Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 1 | /* |
| 2 | * drivers/mmc/host/omap_hsmmc.c |
| 3 | * |
| 4 | * Driver for OMAP2430/3430 MMC controller. |
| 5 | * |
| 6 | * Copyright (C) 2007 Texas Instruments. |
| 7 | * |
| 8 | * Authors: |
| 9 | * Syed Mohammed Khasim <x0khasim@ti.com> |
| 10 | * Madhusudhan <madhu.cr@ti.com> |
| 11 | * Mohit Jalori <mjalori@ti.com> |
| 12 | * |
| 13 | * This file is licensed under the terms of the GNU General Public License |
| 14 | * version 2. This program is licensed "as is" without any warranty of any |
| 15 | * kind, whether express or implied. |
| 16 | */ |
| 17 | |
| 18 | #include <linux/module.h> |
| 19 | #include <linux/init.h> |
Andy Shevchenko | ac330f4 | 2011-05-10 15:51:54 +0300 | [diff] [blame] | 20 | #include <linux/kernel.h> |
Denis Karpov | d900f71 | 2009-09-22 16:44:38 -0700 | [diff] [blame] | 21 | #include <linux/debugfs.h> |
Russell King | c5c9892 | 2012-04-13 12:14:39 +0100 | [diff] [blame] | 22 | #include <linux/dmaengine.h> |
Denis Karpov | d900f71 | 2009-09-22 16:44:38 -0700 | [diff] [blame] | 23 | #include <linux/seq_file.h> |
Felipe Balbi | 031cd03 | 2013-07-11 16:09:05 +0300 | [diff] [blame] | 24 | #include <linux/sizes.h> |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 25 | #include <linux/interrupt.h> |
| 26 | #include <linux/delay.h> |
| 27 | #include <linux/dma-mapping.h> |
| 28 | #include <linux/platform_device.h> |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 29 | #include <linux/timer.h> |
| 30 | #include <linux/clk.h> |
Rajendra Nayak | 46856a6 | 2012-03-12 20:32:37 +0530 | [diff] [blame] | 31 | #include <linux/of.h> |
Andreas Fenkart | 2cd3a2a | 2014-05-29 10:28:00 +0200 | [diff] [blame] | 32 | #include <linux/of_irq.h> |
Rajendra Nayak | 46856a6 | 2012-03-12 20:32:37 +0530 | [diff] [blame] | 33 | #include <linux/of_gpio.h> |
| 34 | #include <linux/of_device.h> |
Balaji T K | ee526d5 | 2014-05-09 22:16:53 +0530 | [diff] [blame] | 35 | #include <linux/omap-dmaengine.h> |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 36 | #include <linux/mmc/host.h> |
Jarkko Lavinen | 13189e7 | 2009-09-22 16:44:53 -0700 | [diff] [blame] | 37 | #include <linux/mmc/core.h> |
Adrian Hunter | 93caf8e69 | 2010-08-11 14:17:48 -0700 | [diff] [blame] | 38 | #include <linux/mmc/mmc.h> |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 39 | #include <linux/io.h> |
Andreas Fenkart | 2cd3a2a | 2014-05-29 10:28:00 +0200 | [diff] [blame] | 40 | #include <linux/irq.h> |
Adrian Hunter | db0fefc | 2010-02-15 10:03:34 -0800 | [diff] [blame] | 41 | #include <linux/gpio.h> |
| 42 | #include <linux/regulator/consumer.h> |
Daniel Mack | 46b7603 | 2012-10-15 21:35:05 +0530 | [diff] [blame] | 43 | #include <linux/pinctrl/consumer.h> |
Balaji T K | fa4aa2d | 2011-07-01 22:09:35 +0530 | [diff] [blame] | 44 | #include <linux/pm_runtime.h> |
Tony Lindgren | 68f39e7 | 2012-10-15 12:09:43 -0700 | [diff] [blame] | 45 | #include <linux/platform_data/mmc-omap.h> |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 46 | |
| 47 | /* OMAP HSMMC Host Controller Registers */ |
Denis Karpov | 11dd62a | 2009-09-22 16:44:43 -0700 | [diff] [blame] | 48 | #define OMAP_HSMMC_SYSSTATUS 0x0014 |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 49 | #define OMAP_HSMMC_CON 0x002C |
Balaji T K | a2e7715 | 2014-01-21 19:54:42 +0530 | [diff] [blame] | 50 | #define OMAP_HSMMC_SDMASA 0x0100 |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 51 | #define OMAP_HSMMC_BLK 0x0104 |
| 52 | #define OMAP_HSMMC_ARG 0x0108 |
| 53 | #define OMAP_HSMMC_CMD 0x010C |
| 54 | #define OMAP_HSMMC_RSP10 0x0110 |
| 55 | #define OMAP_HSMMC_RSP32 0x0114 |
| 56 | #define OMAP_HSMMC_RSP54 0x0118 |
| 57 | #define OMAP_HSMMC_RSP76 0x011C |
| 58 | #define OMAP_HSMMC_DATA 0x0120 |
Andreas Fenkart | bb0635f | 2014-05-29 10:28:01 +0200 | [diff] [blame] | 59 | #define OMAP_HSMMC_PSTATE 0x0124 |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 60 | #define OMAP_HSMMC_HCTL 0x0128 |
| 61 | #define OMAP_HSMMC_SYSCTL 0x012C |
| 62 | #define OMAP_HSMMC_STAT 0x0130 |
| 63 | #define OMAP_HSMMC_IE 0x0134 |
| 64 | #define OMAP_HSMMC_ISE 0x0138 |
Balaji T K | a2e7715 | 2014-01-21 19:54:42 +0530 | [diff] [blame] | 65 | #define OMAP_HSMMC_AC12 0x013C |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 66 | #define OMAP_HSMMC_CAPA 0x0140 |
| 67 | |
| 68 | #define VS18 (1 << 26) |
| 69 | #define VS30 (1 << 25) |
Hebbar, Gururaja | cd58709 | 2012-11-19 21:59:58 +0530 | [diff] [blame] | 70 | #define HSS (1 << 21) |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 71 | #define SDVS18 (0x5 << 9) |
| 72 | #define SDVS30 (0x6 << 9) |
David Brownell | eb25082 | 2009-02-17 14:49:01 -0800 | [diff] [blame] | 73 | #define SDVS33 (0x7 << 9) |
Kim Kyuwon | 1b331e6 | 2009-02-20 13:10:08 +0100 | [diff] [blame] | 74 | #define SDVS_MASK 0x00000E00 |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 75 | #define SDVSCLR 0xFFFFF1FF |
| 76 | #define SDVSDET 0x00000400 |
| 77 | #define AUTOIDLE 0x1 |
| 78 | #define SDBP (1 << 8) |
| 79 | #define DTO 0xe |
| 80 | #define ICE 0x1 |
| 81 | #define ICS 0x2 |
| 82 | #define CEN (1 << 2) |
Balaji T K | ed16418 | 2013-10-21 00:25:21 +0530 | [diff] [blame] | 83 | #define CLKD_MAX 0x3FF /* max clock divisor: 1023 */ |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 84 | #define CLKD_MASK 0x0000FFC0 |
| 85 | #define CLKD_SHIFT 6 |
| 86 | #define DTO_MASK 0x000F0000 |
| 87 | #define DTO_SHIFT 16 |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 88 | #define INIT_STREAM (1 << 1) |
Balaji T K | a2e7715 | 2014-01-21 19:54:42 +0530 | [diff] [blame] | 89 | #define ACEN_ACMD23 (2 << 2) |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 90 | #define DP_SELECT (1 << 21) |
| 91 | #define DDIR (1 << 4) |
Venkatraman S | a7e9687 | 2012-11-19 22:00:01 +0530 | [diff] [blame] | 92 | #define DMAE 0x1 |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 93 | #define MSBS (1 << 5) |
| 94 | #define BCE (1 << 1) |
| 95 | #define FOUR_BIT (1 << 1) |
Hebbar, Gururaja | cd58709 | 2012-11-19 21:59:58 +0530 | [diff] [blame] | 96 | #define HSPE (1 << 2) |
Balaji T K | 5a52b08 | 2014-05-29 10:28:02 +0200 | [diff] [blame] | 97 | #define IWE (1 << 24) |
Balaji T K | 03b5d92 | 2012-04-09 12:08:33 +0530 | [diff] [blame] | 98 | #define DDR (1 << 19) |
Balaji T K | 5a52b08 | 2014-05-29 10:28:02 +0200 | [diff] [blame] | 99 | #define CLKEXTFREE (1 << 16) |
| 100 | #define CTPL (1 << 11) |
Jarkko Lavinen | 7315301 | 2008-11-21 16:49:54 +0200 | [diff] [blame] | 101 | #define DW8 (1 << 5) |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 102 | #define OD 0x1 |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 103 | #define STAT_CLEAR 0xFFFFFFFF |
| 104 | #define INIT_STREAM_CMD 0x00000000 |
| 105 | #define DUAL_VOLT_OCR_BIT 7 |
| 106 | #define SRC (1 << 25) |
| 107 | #define SRD (1 << 26) |
Denis Karpov | 11dd62a | 2009-09-22 16:44:43 -0700 | [diff] [blame] | 108 | #define SOFTRESET (1 << 1) |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 109 | |
Andreas Fenkart | f945901 | 2014-05-29 10:28:03 +0200 | [diff] [blame^] | 110 | /* PSTATE */ |
| 111 | #define DLEV_DAT(x) (1 << (20 + (x))) |
| 112 | |
Venkatraman S | a7e9687 | 2012-11-19 22:00:01 +0530 | [diff] [blame] | 113 | /* Interrupt masks for IE and ISE register */ |
| 114 | #define CC_EN (1 << 0) |
| 115 | #define TC_EN (1 << 1) |
| 116 | #define BWR_EN (1 << 4) |
| 117 | #define BRR_EN (1 << 5) |
Andreas Fenkart | 2cd3a2a | 2014-05-29 10:28:00 +0200 | [diff] [blame] | 118 | #define CIRQ_EN (1 << 8) |
Venkatraman S | a7e9687 | 2012-11-19 22:00:01 +0530 | [diff] [blame] | 119 | #define ERR_EN (1 << 15) |
| 120 | #define CTO_EN (1 << 16) |
| 121 | #define CCRC_EN (1 << 17) |
| 122 | #define CEB_EN (1 << 18) |
| 123 | #define CIE_EN (1 << 19) |
| 124 | #define DTO_EN (1 << 20) |
| 125 | #define DCRC_EN (1 << 21) |
| 126 | #define DEB_EN (1 << 22) |
Balaji T K | a2e7715 | 2014-01-21 19:54:42 +0530 | [diff] [blame] | 127 | #define ACE_EN (1 << 24) |
Venkatraman S | a7e9687 | 2012-11-19 22:00:01 +0530 | [diff] [blame] | 128 | #define CERR_EN (1 << 28) |
| 129 | #define BADA_EN (1 << 29) |
| 130 | |
Balaji T K | a2e7715 | 2014-01-21 19:54:42 +0530 | [diff] [blame] | 131 | #define INT_EN_MASK (BADA_EN | CERR_EN | ACE_EN | DEB_EN | DCRC_EN |\ |
Venkatraman S | a7e9687 | 2012-11-19 22:00:01 +0530 | [diff] [blame] | 132 | DTO_EN | CIE_EN | CEB_EN | CCRC_EN | CTO_EN | \ |
| 133 | BRR_EN | BWR_EN | TC_EN | CC_EN) |
| 134 | |
Balaji T K | a2e7715 | 2014-01-21 19:54:42 +0530 | [diff] [blame] | 135 | #define CNI (1 << 7) |
| 136 | #define ACIE (1 << 4) |
| 137 | #define ACEB (1 << 3) |
| 138 | #define ACCE (1 << 2) |
| 139 | #define ACTO (1 << 1) |
| 140 | #define ACNE (1 << 0) |
| 141 | |
Balaji T K | fa4aa2d | 2011-07-01 22:09:35 +0530 | [diff] [blame] | 142 | #define MMC_AUTOSUSPEND_DELAY 100 |
Jianpeng Ma | 1e88178 | 2013-10-21 00:25:20 +0530 | [diff] [blame] | 143 | #define MMC_TIMEOUT_MS 20 /* 20 mSec */ |
| 144 | #define MMC_TIMEOUT_US 20000 /* 20000 micro Sec */ |
Andy Shevchenko | 6b206ef | 2011-07-13 11:16:29 -0400 | [diff] [blame] | 145 | #define OMAP_MMC_MIN_CLOCK 400000 |
| 146 | #define OMAP_MMC_MAX_CLOCK 52000000 |
Kishore Kadiyala | 0005ae7 | 2011-02-28 20:48:05 +0530 | [diff] [blame] | 147 | #define DRIVER_NAME "omap_hsmmc" |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 148 | |
Balaji T K | e99448f | 2014-02-19 20:26:40 +0530 | [diff] [blame] | 149 | #define VDD_1V8 1800000 /* 180000 uV */ |
| 150 | #define VDD_3V0 3000000 /* 300000 uV */ |
| 151 | #define VDD_165_195 (ffs(MMC_VDD_165_195) - 1) |
| 152 | |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 153 | /* |
| 154 | * One controller can have multiple slots, like on some omap boards using |
| 155 | * omap.c controller driver. Luckily this is not currently done on any known |
| 156 | * omap_hsmmc.c device. |
| 157 | */ |
| 158 | #define mmc_slot(host) (host->pdata->slots[host->slot_id]) |
| 159 | |
| 160 | /* |
| 161 | * MMC Host controller read/write API's |
| 162 | */ |
| 163 | #define OMAP_HSMMC_READ(base, reg) \ |
| 164 | __raw_readl((base) + OMAP_HSMMC_##reg) |
| 165 | |
| 166 | #define OMAP_HSMMC_WRITE(base, reg, val) \ |
| 167 | __raw_writel((val), (base) + OMAP_HSMMC_##reg) |
| 168 | |
Per Forlin | 9782aff | 2011-07-01 18:55:23 +0200 | [diff] [blame] | 169 | struct omap_hsmmc_next { |
| 170 | unsigned int dma_len; |
| 171 | s32 cookie; |
| 172 | }; |
| 173 | |
Denis Karpov | 70a3341 | 2009-09-22 16:44:59 -0700 | [diff] [blame] | 174 | struct omap_hsmmc_host { |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 175 | struct device *dev; |
| 176 | struct mmc_host *mmc; |
| 177 | struct mmc_request *mrq; |
| 178 | struct mmc_command *cmd; |
| 179 | struct mmc_data *data; |
| 180 | struct clk *fclk; |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 181 | struct clk *dbclk; |
Adrian Hunter | db0fefc | 2010-02-15 10:03:34 -0800 | [diff] [blame] | 182 | /* |
| 183 | * vcc == configured supply |
| 184 | * vcc_aux == optional |
| 185 | * - MMC1, supply for DAT4..DAT7 |
| 186 | * - MMC2/MMC2, external level shifter voltage supply, for |
| 187 | * chip (SDIO, eMMC, etc) or transceiver (MMC2 only) |
| 188 | */ |
| 189 | struct regulator *vcc; |
| 190 | struct regulator *vcc_aux; |
Balaji T K | e99448f | 2014-02-19 20:26:40 +0530 | [diff] [blame] | 191 | struct regulator *pbias; |
| 192 | bool pbias_enabled; |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 193 | void __iomem *base; |
| 194 | resource_size_t mapbase; |
Adrian Hunter | 4dffd7a | 2009-09-22 16:44:58 -0700 | [diff] [blame] | 195 | spinlock_t irq_lock; /* Prevent races with irq handler */ |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 196 | unsigned int dma_len; |
Juha Yrjola | 0ccd76d | 2008-11-14 15:22:00 +0200 | [diff] [blame] | 197 | unsigned int dma_sg_idx; |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 198 | unsigned char bus_mode; |
Adrian Hunter | a362146 | 2009-09-22 16:44:42 -0700 | [diff] [blame] | 199 | unsigned char power_mode; |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 200 | int suspended; |
Tony Lindgren | 0a82e06 | 2013-10-21 00:25:19 +0530 | [diff] [blame] | 201 | u32 con; |
| 202 | u32 hctl; |
| 203 | u32 sysctl; |
| 204 | u32 capa; |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 205 | int irq; |
Andreas Fenkart | 2cd3a2a | 2014-05-29 10:28:00 +0200 | [diff] [blame] | 206 | int wake_irq; |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 207 | int use_dma, dma_ch; |
Russell King | c5c9892 | 2012-04-13 12:14:39 +0100 | [diff] [blame] | 208 | struct dma_chan *tx_chan; |
| 209 | struct dma_chan *rx_chan; |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 210 | int slot_id; |
Adrian Hunter | 4a694dc | 2009-01-12 16:13:08 +0200 | [diff] [blame] | 211 | int response_busy; |
Denis Karpov | 11dd62a | 2009-09-22 16:44:43 -0700 | [diff] [blame] | 212 | int context_loss; |
Adrian Hunter | b62f622 | 2009-09-22 16:45:01 -0700 | [diff] [blame] | 213 | int protect_card; |
| 214 | int reqs_blocked; |
Adrian Hunter | db0fefc | 2010-02-15 10:03:34 -0800 | [diff] [blame] | 215 | int use_reg; |
Adrian Hunter | b417577 | 2010-05-26 14:42:06 -0700 | [diff] [blame] | 216 | int req_in_progress; |
Balaji T K | 6e3076c | 2014-01-21 19:54:42 +0530 | [diff] [blame] | 217 | unsigned long clk_rate; |
Balaji T K | a2e7715 | 2014-01-21 19:54:42 +0530 | [diff] [blame] | 218 | unsigned int flags; |
Andreas Fenkart | 2cd3a2a | 2014-05-29 10:28:00 +0200 | [diff] [blame] | 219 | #define AUTO_CMD23 (1 << 0) /* Auto CMD23 support */ |
| 220 | #define HSMMC_SDIO_IRQ_ENABLED (1 << 1) /* SDIO irq enabled */ |
| 221 | #define HSMMC_WAKE_IRQ_ENABLED (1 << 2) |
Per Forlin | 9782aff | 2011-07-01 18:55:23 +0200 | [diff] [blame] | 222 | struct omap_hsmmc_next next_data; |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 223 | struct omap_mmc_platform_data *pdata; |
| 224 | }; |
| 225 | |
Nishanth Menon | 59445b1 | 2014-02-13 23:45:48 -0600 | [diff] [blame] | 226 | struct omap_mmc_of_data { |
| 227 | u32 reg_offset; |
| 228 | u8 controller_flags; |
| 229 | }; |
| 230 | |
Balaji T K | bf129e1 | 2014-01-21 19:54:42 +0530 | [diff] [blame] | 231 | static void omap_hsmmc_start_dma_transfer(struct omap_hsmmc_host *host); |
| 232 | |
Adrian Hunter | db0fefc | 2010-02-15 10:03:34 -0800 | [diff] [blame] | 233 | static int omap_hsmmc_card_detect(struct device *dev, int slot) |
| 234 | { |
Balaji T K | 9ea28ec | 2012-10-15 21:35:08 +0530 | [diff] [blame] | 235 | struct omap_hsmmc_host *host = dev_get_drvdata(dev); |
| 236 | struct omap_mmc_platform_data *mmc = host->pdata; |
Adrian Hunter | db0fefc | 2010-02-15 10:03:34 -0800 | [diff] [blame] | 237 | |
| 238 | /* NOTE: assumes card detect signal is active-low */ |
| 239 | return !gpio_get_value_cansleep(mmc->slots[0].switch_pin); |
| 240 | } |
| 241 | |
| 242 | static int omap_hsmmc_get_wp(struct device *dev, int slot) |
| 243 | { |
Balaji T K | 9ea28ec | 2012-10-15 21:35:08 +0530 | [diff] [blame] | 244 | struct omap_hsmmc_host *host = dev_get_drvdata(dev); |
| 245 | struct omap_mmc_platform_data *mmc = host->pdata; |
Adrian Hunter | db0fefc | 2010-02-15 10:03:34 -0800 | [diff] [blame] | 246 | |
| 247 | /* NOTE: assumes write protect signal is active-high */ |
| 248 | return gpio_get_value_cansleep(mmc->slots[0].gpio_wp); |
| 249 | } |
| 250 | |
| 251 | static int omap_hsmmc_get_cover_state(struct device *dev, int slot) |
| 252 | { |
Balaji T K | 9ea28ec | 2012-10-15 21:35:08 +0530 | [diff] [blame] | 253 | struct omap_hsmmc_host *host = dev_get_drvdata(dev); |
| 254 | struct omap_mmc_platform_data *mmc = host->pdata; |
Adrian Hunter | db0fefc | 2010-02-15 10:03:34 -0800 | [diff] [blame] | 255 | |
| 256 | /* NOTE: assumes card detect signal is active-low */ |
| 257 | return !gpio_get_value_cansleep(mmc->slots[0].switch_pin); |
| 258 | } |
| 259 | |
| 260 | #ifdef CONFIG_PM |
| 261 | |
| 262 | static int omap_hsmmc_suspend_cdirq(struct device *dev, int slot) |
| 263 | { |
Balaji T K | 9ea28ec | 2012-10-15 21:35:08 +0530 | [diff] [blame] | 264 | struct omap_hsmmc_host *host = dev_get_drvdata(dev); |
| 265 | struct omap_mmc_platform_data *mmc = host->pdata; |
Adrian Hunter | db0fefc | 2010-02-15 10:03:34 -0800 | [diff] [blame] | 266 | |
| 267 | disable_irq(mmc->slots[0].card_detect_irq); |
| 268 | return 0; |
| 269 | } |
| 270 | |
| 271 | static int omap_hsmmc_resume_cdirq(struct device *dev, int slot) |
| 272 | { |
Balaji T K | 9ea28ec | 2012-10-15 21:35:08 +0530 | [diff] [blame] | 273 | struct omap_hsmmc_host *host = dev_get_drvdata(dev); |
| 274 | struct omap_mmc_platform_data *mmc = host->pdata; |
Adrian Hunter | db0fefc | 2010-02-15 10:03:34 -0800 | [diff] [blame] | 275 | |
| 276 | enable_irq(mmc->slots[0].card_detect_irq); |
| 277 | return 0; |
| 278 | } |
| 279 | |
| 280 | #else |
| 281 | |
| 282 | #define omap_hsmmc_suspend_cdirq NULL |
| 283 | #define omap_hsmmc_resume_cdirq NULL |
| 284 | |
| 285 | #endif |
| 286 | |
Adrian Hunter | b702b10 | 2010-02-15 10:03:35 -0800 | [diff] [blame] | 287 | #ifdef CONFIG_REGULATOR |
| 288 | |
Rajendra Nayak | 69b07ec | 2012-03-07 09:55:30 -0500 | [diff] [blame] | 289 | static int omap_hsmmc_set_power(struct device *dev, int slot, int power_on, |
Adrian Hunter | db0fefc | 2010-02-15 10:03:34 -0800 | [diff] [blame] | 290 | int vdd) |
| 291 | { |
| 292 | struct omap_hsmmc_host *host = |
| 293 | platform_get_drvdata(to_platform_device(dev)); |
| 294 | int ret = 0; |
| 295 | |
| 296 | /* |
| 297 | * If we don't see a Vcc regulator, assume it's a fixed |
| 298 | * voltage always-on regulator. |
| 299 | */ |
| 300 | if (!host->vcc) |
| 301 | return 0; |
| 302 | |
| 303 | if (mmc_slot(host).before_set_reg) |
| 304 | mmc_slot(host).before_set_reg(dev, slot, power_on, vdd); |
| 305 | |
Balaji T K | e99448f | 2014-02-19 20:26:40 +0530 | [diff] [blame] | 306 | if (host->pbias) { |
| 307 | if (host->pbias_enabled == 1) { |
| 308 | ret = regulator_disable(host->pbias); |
| 309 | if (!ret) |
| 310 | host->pbias_enabled = 0; |
| 311 | } |
| 312 | regulator_set_voltage(host->pbias, VDD_3V0, VDD_3V0); |
| 313 | } |
| 314 | |
Adrian Hunter | db0fefc | 2010-02-15 10:03:34 -0800 | [diff] [blame] | 315 | /* |
| 316 | * Assume Vcc regulator is used only to power the card ... OMAP |
| 317 | * VDDS is used to power the pins, optionally with a transceiver to |
| 318 | * support cards using voltages other than VDDS (1.8V nominal). When a |
| 319 | * transceiver is used, DAT3..7 are muxed as transceiver control pins. |
| 320 | * |
| 321 | * In some cases this regulator won't support enable/disable; |
| 322 | * e.g. it's a fixed rail for a WLAN chip. |
| 323 | * |
| 324 | * In other cases vcc_aux switches interface power. Example, for |
| 325 | * eMMC cards it represents VccQ. Sometimes transceivers or SDIO |
| 326 | * chips/cards need an interface voltage rail too. |
| 327 | */ |
| 328 | if (power_on) { |
Balaji T K | 987fd49 | 2014-02-19 20:26:40 +0530 | [diff] [blame] | 329 | if (host->vcc) |
| 330 | ret = mmc_regulator_set_ocr(host->mmc, host->vcc, vdd); |
Adrian Hunter | db0fefc | 2010-02-15 10:03:34 -0800 | [diff] [blame] | 331 | /* Enable interface voltage rail, if needed */ |
| 332 | if (ret == 0 && host->vcc_aux) { |
| 333 | ret = regulator_enable(host->vcc_aux); |
Balaji T K | 987fd49 | 2014-02-19 20:26:40 +0530 | [diff] [blame] | 334 | if (ret < 0 && host->vcc) |
Linus Walleij | 99fc513 | 2010-09-29 01:08:27 -0400 | [diff] [blame] | 335 | ret = mmc_regulator_set_ocr(host->mmc, |
| 336 | host->vcc, 0); |
Adrian Hunter | db0fefc | 2010-02-15 10:03:34 -0800 | [diff] [blame] | 337 | } |
| 338 | } else { |
Linus Walleij | 99fc513 | 2010-09-29 01:08:27 -0400 | [diff] [blame] | 339 | /* Shut down the rail */ |
Adrian Hunter | 6da20c8 | 2010-02-15 10:03:34 -0800 | [diff] [blame] | 340 | if (host->vcc_aux) |
| 341 | ret = regulator_disable(host->vcc_aux); |
Balaji T K | 987fd49 | 2014-02-19 20:26:40 +0530 | [diff] [blame] | 342 | if (host->vcc) { |
Linus Walleij | 99fc513 | 2010-09-29 01:08:27 -0400 | [diff] [blame] | 343 | /* Then proceed to shut down the local regulator */ |
| 344 | ret = mmc_regulator_set_ocr(host->mmc, |
| 345 | host->vcc, 0); |
| 346 | } |
Adrian Hunter | db0fefc | 2010-02-15 10:03:34 -0800 | [diff] [blame] | 347 | } |
| 348 | |
Balaji T K | e99448f | 2014-02-19 20:26:40 +0530 | [diff] [blame] | 349 | if (host->pbias) { |
| 350 | if (vdd <= VDD_165_195) |
| 351 | ret = regulator_set_voltage(host->pbias, VDD_1V8, |
| 352 | VDD_1V8); |
| 353 | else |
| 354 | ret = regulator_set_voltage(host->pbias, VDD_3V0, |
| 355 | VDD_3V0); |
| 356 | if (ret < 0) |
| 357 | goto error_set_power; |
| 358 | |
| 359 | if (host->pbias_enabled == 0) { |
| 360 | ret = regulator_enable(host->pbias); |
| 361 | if (!ret) |
| 362 | host->pbias_enabled = 1; |
| 363 | } |
| 364 | } |
| 365 | |
Adrian Hunter | db0fefc | 2010-02-15 10:03:34 -0800 | [diff] [blame] | 366 | if (mmc_slot(host).after_set_reg) |
| 367 | mmc_slot(host).after_set_reg(dev, slot, power_on, vdd); |
| 368 | |
Balaji T K | e99448f | 2014-02-19 20:26:40 +0530 | [diff] [blame] | 369 | error_set_power: |
Adrian Hunter | db0fefc | 2010-02-15 10:03:34 -0800 | [diff] [blame] | 370 | return ret; |
| 371 | } |
| 372 | |
Adrian Hunter | db0fefc | 2010-02-15 10:03:34 -0800 | [diff] [blame] | 373 | static int omap_hsmmc_reg_get(struct omap_hsmmc_host *host) |
| 374 | { |
| 375 | struct regulator *reg; |
kishore kadiyala | 64be978 | 2010-10-01 16:35:28 -0700 | [diff] [blame] | 376 | int ocr_value = 0; |
Adrian Hunter | db0fefc | 2010-02-15 10:03:34 -0800 | [diff] [blame] | 377 | |
Balaji T K | f2ddc1d | 2014-02-19 20:26:40 +0530 | [diff] [blame] | 378 | reg = devm_regulator_get(host->dev, "vmmc"); |
Adrian Hunter | db0fefc | 2010-02-15 10:03:34 -0800 | [diff] [blame] | 379 | if (IS_ERR(reg)) { |
Balaji T K | 987fd49 | 2014-02-19 20:26:40 +0530 | [diff] [blame] | 380 | dev_err(host->dev, "unable to get vmmc regulator %ld\n", |
| 381 | PTR_ERR(reg)); |
NeilBrown | 1fdc90f | 2012-08-08 00:06:00 -0400 | [diff] [blame] | 382 | return PTR_ERR(reg); |
Adrian Hunter | db0fefc | 2010-02-15 10:03:34 -0800 | [diff] [blame] | 383 | } else { |
| 384 | host->vcc = reg; |
kishore kadiyala | 64be978 | 2010-10-01 16:35:28 -0700 | [diff] [blame] | 385 | ocr_value = mmc_regulator_get_ocrmask(reg); |
| 386 | if (!mmc_slot(host).ocr_mask) { |
| 387 | mmc_slot(host).ocr_mask = ocr_value; |
| 388 | } else { |
| 389 | if (!(mmc_slot(host).ocr_mask & ocr_value)) { |
Rajendra Nayak | 2cecdf0 | 2012-02-23 17:02:20 +0530 | [diff] [blame] | 390 | dev_err(host->dev, "ocrmask %x is not supported\n", |
Rajendra Nayak | e3f1adb | 2012-03-07 09:55:31 -0500 | [diff] [blame] | 391 | mmc_slot(host).ocr_mask); |
kishore kadiyala | 64be978 | 2010-10-01 16:35:28 -0700 | [diff] [blame] | 392 | mmc_slot(host).ocr_mask = 0; |
| 393 | return -EINVAL; |
| 394 | } |
| 395 | } |
Balaji T K | 987fd49 | 2014-02-19 20:26:40 +0530 | [diff] [blame] | 396 | } |
| 397 | mmc_slot(host).set_power = omap_hsmmc_set_power; |
Adrian Hunter | db0fefc | 2010-02-15 10:03:34 -0800 | [diff] [blame] | 398 | |
Balaji T K | 987fd49 | 2014-02-19 20:26:40 +0530 | [diff] [blame] | 399 | /* Allow an aux regulator */ |
| 400 | reg = devm_regulator_get_optional(host->dev, "vmmc_aux"); |
| 401 | host->vcc_aux = IS_ERR(reg) ? NULL : reg; |
Adrian Hunter | db0fefc | 2010-02-15 10:03:34 -0800 | [diff] [blame] | 402 | |
Balaji T K | e99448f | 2014-02-19 20:26:40 +0530 | [diff] [blame] | 403 | reg = devm_regulator_get_optional(host->dev, "pbias"); |
| 404 | host->pbias = IS_ERR(reg) ? NULL : reg; |
| 405 | |
Balaji T K | 987fd49 | 2014-02-19 20:26:40 +0530 | [diff] [blame] | 406 | /* For eMMC do not power off when not in sleep state */ |
| 407 | if (mmc_slot(host).no_regulator_off_init) |
| 408 | return 0; |
| 409 | /* |
| 410 | * To disable boot_on regulator, enable regulator |
| 411 | * to increase usecount and then disable it. |
| 412 | */ |
| 413 | if ((host->vcc && regulator_is_enabled(host->vcc) > 0) || |
| 414 | (host->vcc_aux && regulator_is_enabled(host->vcc_aux))) { |
| 415 | int vdd = ffs(mmc_slot(host).ocr_mask) - 1; |
Adrian Hunter | e840ce1 | 2011-05-06 12:14:10 +0300 | [diff] [blame] | 416 | |
Balaji T K | 987fd49 | 2014-02-19 20:26:40 +0530 | [diff] [blame] | 417 | mmc_slot(host).set_power(host->dev, host->slot_id, 1, vdd); |
| 418 | mmc_slot(host).set_power(host->dev, host->slot_id, 0, 0); |
Adrian Hunter | db0fefc | 2010-02-15 10:03:34 -0800 | [diff] [blame] | 419 | } |
| 420 | |
| 421 | return 0; |
Adrian Hunter | db0fefc | 2010-02-15 10:03:34 -0800 | [diff] [blame] | 422 | } |
| 423 | |
| 424 | static void omap_hsmmc_reg_put(struct omap_hsmmc_host *host) |
| 425 | { |
Adrian Hunter | db0fefc | 2010-02-15 10:03:34 -0800 | [diff] [blame] | 426 | mmc_slot(host).set_power = NULL; |
Adrian Hunter | db0fefc | 2010-02-15 10:03:34 -0800 | [diff] [blame] | 427 | } |
| 428 | |
Adrian Hunter | b702b10 | 2010-02-15 10:03:35 -0800 | [diff] [blame] | 429 | static inline int omap_hsmmc_have_reg(void) |
| 430 | { |
| 431 | return 1; |
| 432 | } |
| 433 | |
| 434 | #else |
| 435 | |
| 436 | static inline int omap_hsmmc_reg_get(struct omap_hsmmc_host *host) |
| 437 | { |
| 438 | return -EINVAL; |
| 439 | } |
| 440 | |
| 441 | static inline void omap_hsmmc_reg_put(struct omap_hsmmc_host *host) |
| 442 | { |
| 443 | } |
| 444 | |
| 445 | static inline int omap_hsmmc_have_reg(void) |
| 446 | { |
| 447 | return 0; |
| 448 | } |
| 449 | |
| 450 | #endif |
| 451 | |
| 452 | static int omap_hsmmc_gpio_init(struct omap_mmc_platform_data *pdata) |
| 453 | { |
| 454 | int ret; |
| 455 | |
| 456 | if (gpio_is_valid(pdata->slots[0].switch_pin)) { |
Adrian Hunter | b702b10 | 2010-02-15 10:03:35 -0800 | [diff] [blame] | 457 | if (pdata->slots[0].cover) |
| 458 | pdata->slots[0].get_cover_state = |
| 459 | omap_hsmmc_get_cover_state; |
| 460 | else |
| 461 | pdata->slots[0].card_detect = omap_hsmmc_card_detect; |
| 462 | pdata->slots[0].card_detect_irq = |
| 463 | gpio_to_irq(pdata->slots[0].switch_pin); |
| 464 | ret = gpio_request(pdata->slots[0].switch_pin, "mmc_cd"); |
| 465 | if (ret) |
| 466 | return ret; |
| 467 | ret = gpio_direction_input(pdata->slots[0].switch_pin); |
| 468 | if (ret) |
| 469 | goto err_free_sp; |
| 470 | } else |
| 471 | pdata->slots[0].switch_pin = -EINVAL; |
| 472 | |
| 473 | if (gpio_is_valid(pdata->slots[0].gpio_wp)) { |
| 474 | pdata->slots[0].get_ro = omap_hsmmc_get_wp; |
| 475 | ret = gpio_request(pdata->slots[0].gpio_wp, "mmc_wp"); |
| 476 | if (ret) |
| 477 | goto err_free_cd; |
| 478 | ret = gpio_direction_input(pdata->slots[0].gpio_wp); |
| 479 | if (ret) |
| 480 | goto err_free_wp; |
| 481 | } else |
| 482 | pdata->slots[0].gpio_wp = -EINVAL; |
| 483 | |
| 484 | return 0; |
| 485 | |
| 486 | err_free_wp: |
| 487 | gpio_free(pdata->slots[0].gpio_wp); |
| 488 | err_free_cd: |
| 489 | if (gpio_is_valid(pdata->slots[0].switch_pin)) |
| 490 | err_free_sp: |
| 491 | gpio_free(pdata->slots[0].switch_pin); |
| 492 | return ret; |
| 493 | } |
| 494 | |
| 495 | static void omap_hsmmc_gpio_free(struct omap_mmc_platform_data *pdata) |
| 496 | { |
| 497 | if (gpio_is_valid(pdata->slots[0].gpio_wp)) |
| 498 | gpio_free(pdata->slots[0].gpio_wp); |
| 499 | if (gpio_is_valid(pdata->slots[0].switch_pin)) |
| 500 | gpio_free(pdata->slots[0].switch_pin); |
| 501 | } |
| 502 | |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 503 | /* |
Andy Shevchenko | e0c7f99 | 2011-05-06 12:14:05 +0300 | [diff] [blame] | 504 | * Start clock to the card |
| 505 | */ |
| 506 | static void omap_hsmmc_start_clock(struct omap_hsmmc_host *host) |
| 507 | { |
| 508 | OMAP_HSMMC_WRITE(host->base, SYSCTL, |
| 509 | OMAP_HSMMC_READ(host->base, SYSCTL) | CEN); |
| 510 | } |
| 511 | |
| 512 | /* |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 513 | * Stop clock to the card |
| 514 | */ |
Denis Karpov | 70a3341 | 2009-09-22 16:44:59 -0700 | [diff] [blame] | 515 | static void omap_hsmmc_stop_clock(struct omap_hsmmc_host *host) |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 516 | { |
| 517 | OMAP_HSMMC_WRITE(host->base, SYSCTL, |
| 518 | OMAP_HSMMC_READ(host->base, SYSCTL) & ~CEN); |
| 519 | if ((OMAP_HSMMC_READ(host->base, SYSCTL) & CEN) != 0x0) |
Masanari Iida | 7122bbb | 2012-08-05 23:25:40 +0900 | [diff] [blame] | 520 | dev_dbg(mmc_dev(host->mmc), "MMC Clock is not stopped\n"); |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 521 | } |
| 522 | |
Adrian Hunter | 93caf8e69 | 2010-08-11 14:17:48 -0700 | [diff] [blame] | 523 | static void omap_hsmmc_enable_irq(struct omap_hsmmc_host *host, |
| 524 | struct mmc_command *cmd) |
Adrian Hunter | b417577 | 2010-05-26 14:42:06 -0700 | [diff] [blame] | 525 | { |
Andreas Fenkart | 2cd3a2a | 2014-05-29 10:28:00 +0200 | [diff] [blame] | 526 | u32 irq_mask = INT_EN_MASK; |
| 527 | unsigned long flags; |
Adrian Hunter | b417577 | 2010-05-26 14:42:06 -0700 | [diff] [blame] | 528 | |
| 529 | if (host->use_dma) |
Andreas Fenkart | 2cd3a2a | 2014-05-29 10:28:00 +0200 | [diff] [blame] | 530 | irq_mask &= ~(BRR_EN | BWR_EN); |
Adrian Hunter | b417577 | 2010-05-26 14:42:06 -0700 | [diff] [blame] | 531 | |
Adrian Hunter | 93caf8e69 | 2010-08-11 14:17:48 -0700 | [diff] [blame] | 532 | /* Disable timeout for erases */ |
| 533 | if (cmd->opcode == MMC_ERASE) |
Venkatraman S | a7e9687 | 2012-11-19 22:00:01 +0530 | [diff] [blame] | 534 | irq_mask &= ~DTO_EN; |
Adrian Hunter | 93caf8e69 | 2010-08-11 14:17:48 -0700 | [diff] [blame] | 535 | |
Andreas Fenkart | 2cd3a2a | 2014-05-29 10:28:00 +0200 | [diff] [blame] | 536 | spin_lock_irqsave(&host->irq_lock, flags); |
Adrian Hunter | b417577 | 2010-05-26 14:42:06 -0700 | [diff] [blame] | 537 | OMAP_HSMMC_WRITE(host->base, STAT, STAT_CLEAR); |
| 538 | OMAP_HSMMC_WRITE(host->base, ISE, irq_mask); |
Andreas Fenkart | 2cd3a2a | 2014-05-29 10:28:00 +0200 | [diff] [blame] | 539 | |
| 540 | /* latch pending CIRQ, but don't signal MMC core */ |
| 541 | if (host->flags & HSMMC_SDIO_IRQ_ENABLED) |
| 542 | irq_mask |= CIRQ_EN; |
Adrian Hunter | b417577 | 2010-05-26 14:42:06 -0700 | [diff] [blame] | 543 | OMAP_HSMMC_WRITE(host->base, IE, irq_mask); |
Andreas Fenkart | 2cd3a2a | 2014-05-29 10:28:00 +0200 | [diff] [blame] | 544 | spin_unlock_irqrestore(&host->irq_lock, flags); |
Adrian Hunter | b417577 | 2010-05-26 14:42:06 -0700 | [diff] [blame] | 545 | } |
| 546 | |
| 547 | static void omap_hsmmc_disable_irq(struct omap_hsmmc_host *host) |
| 548 | { |
Andreas Fenkart | 2cd3a2a | 2014-05-29 10:28:00 +0200 | [diff] [blame] | 549 | u32 irq_mask = 0; |
| 550 | unsigned long flags; |
| 551 | |
| 552 | spin_lock_irqsave(&host->irq_lock, flags); |
| 553 | /* no transfer running but need to keep cirq if enabled */ |
| 554 | if (host->flags & HSMMC_SDIO_IRQ_ENABLED) |
| 555 | irq_mask |= CIRQ_EN; |
| 556 | OMAP_HSMMC_WRITE(host->base, ISE, irq_mask); |
| 557 | OMAP_HSMMC_WRITE(host->base, IE, irq_mask); |
Adrian Hunter | b417577 | 2010-05-26 14:42:06 -0700 | [diff] [blame] | 558 | OMAP_HSMMC_WRITE(host->base, STAT, STAT_CLEAR); |
Andreas Fenkart | 2cd3a2a | 2014-05-29 10:28:00 +0200 | [diff] [blame] | 559 | spin_unlock_irqrestore(&host->irq_lock, flags); |
Adrian Hunter | b417577 | 2010-05-26 14:42:06 -0700 | [diff] [blame] | 560 | } |
| 561 | |
Andy Shevchenko | ac330f4 | 2011-05-10 15:51:54 +0300 | [diff] [blame] | 562 | /* Calculate divisor for the given clock frequency */ |
Balaji TK | d83b6e0 | 2011-12-20 15:12:00 +0530 | [diff] [blame] | 563 | static u16 calc_divisor(struct omap_hsmmc_host *host, struct mmc_ios *ios) |
Andy Shevchenko | ac330f4 | 2011-05-10 15:51:54 +0300 | [diff] [blame] | 564 | { |
| 565 | u16 dsor = 0; |
| 566 | |
| 567 | if (ios->clock) { |
Balaji TK | d83b6e0 | 2011-12-20 15:12:00 +0530 | [diff] [blame] | 568 | dsor = DIV_ROUND_UP(clk_get_rate(host->fclk), ios->clock); |
Balaji T K | ed16418 | 2013-10-21 00:25:21 +0530 | [diff] [blame] | 569 | if (dsor > CLKD_MAX) |
| 570 | dsor = CLKD_MAX; |
Andy Shevchenko | ac330f4 | 2011-05-10 15:51:54 +0300 | [diff] [blame] | 571 | } |
| 572 | |
| 573 | return dsor; |
| 574 | } |
| 575 | |
Andy Shevchenko | 5934df2 | 2011-05-06 12:14:06 +0300 | [diff] [blame] | 576 | static void omap_hsmmc_set_clock(struct omap_hsmmc_host *host) |
| 577 | { |
| 578 | struct mmc_ios *ios = &host->mmc->ios; |
| 579 | unsigned long regval; |
| 580 | unsigned long timeout; |
Hebbar, Gururaja | cd58709 | 2012-11-19 21:59:58 +0530 | [diff] [blame] | 581 | unsigned long clkdiv; |
Andy Shevchenko | 5934df2 | 2011-05-06 12:14:06 +0300 | [diff] [blame] | 582 | |
Venkatraman S | 8986d31 | 2012-08-07 19:10:38 +0530 | [diff] [blame] | 583 | dev_vdbg(mmc_dev(host->mmc), "Set clock to %uHz\n", ios->clock); |
Andy Shevchenko | 5934df2 | 2011-05-06 12:14:06 +0300 | [diff] [blame] | 584 | |
| 585 | omap_hsmmc_stop_clock(host); |
| 586 | |
| 587 | regval = OMAP_HSMMC_READ(host->base, SYSCTL); |
| 588 | regval = regval & ~(CLKD_MASK | DTO_MASK); |
Hebbar, Gururaja | cd58709 | 2012-11-19 21:59:58 +0530 | [diff] [blame] | 589 | clkdiv = calc_divisor(host, ios); |
| 590 | regval = regval | (clkdiv << 6) | (DTO << 16); |
Andy Shevchenko | 5934df2 | 2011-05-06 12:14:06 +0300 | [diff] [blame] | 591 | OMAP_HSMMC_WRITE(host->base, SYSCTL, regval); |
| 592 | OMAP_HSMMC_WRITE(host->base, SYSCTL, |
| 593 | OMAP_HSMMC_READ(host->base, SYSCTL) | ICE); |
| 594 | |
| 595 | /* Wait till the ICS bit is set */ |
| 596 | timeout = jiffies + msecs_to_jiffies(MMC_TIMEOUT_MS); |
| 597 | while ((OMAP_HSMMC_READ(host->base, SYSCTL) & ICS) != ICS |
| 598 | && time_before(jiffies, timeout)) |
| 599 | cpu_relax(); |
| 600 | |
Hebbar, Gururaja | cd58709 | 2012-11-19 21:59:58 +0530 | [diff] [blame] | 601 | /* |
| 602 | * Enable High-Speed Support |
| 603 | * Pre-Requisites |
| 604 | * - Controller should support High-Speed-Enable Bit |
| 605 | * - Controller should not be using DDR Mode |
| 606 | * - Controller should advertise that it supports High Speed |
| 607 | * in capabilities register |
| 608 | * - MMC/SD clock coming out of controller > 25MHz |
| 609 | */ |
| 610 | if ((mmc_slot(host).features & HSMMC_HAS_HSPE_SUPPORT) && |
Seungwon Jeon | 5438ad9 | 2014-03-14 21:12:27 +0900 | [diff] [blame] | 611 | (ios->timing != MMC_TIMING_MMC_DDR52) && |
Hebbar, Gururaja | cd58709 | 2012-11-19 21:59:58 +0530 | [diff] [blame] | 612 | ((OMAP_HSMMC_READ(host->base, CAPA) & HSS) == HSS)) { |
| 613 | regval = OMAP_HSMMC_READ(host->base, HCTL); |
| 614 | if (clkdiv && (clk_get_rate(host->fclk)/clkdiv) > 25000000) |
| 615 | regval |= HSPE; |
| 616 | else |
| 617 | regval &= ~HSPE; |
| 618 | |
| 619 | OMAP_HSMMC_WRITE(host->base, HCTL, regval); |
| 620 | } |
| 621 | |
Andy Shevchenko | 5934df2 | 2011-05-06 12:14:06 +0300 | [diff] [blame] | 622 | omap_hsmmc_start_clock(host); |
| 623 | } |
| 624 | |
Andy Shevchenko | 3796fb8a | 2011-07-13 11:31:15 -0400 | [diff] [blame] | 625 | static void omap_hsmmc_set_bus_width(struct omap_hsmmc_host *host) |
| 626 | { |
| 627 | struct mmc_ios *ios = &host->mmc->ios; |
| 628 | u32 con; |
| 629 | |
| 630 | con = OMAP_HSMMC_READ(host->base, CON); |
Seungwon Jeon | 5438ad9 | 2014-03-14 21:12:27 +0900 | [diff] [blame] | 631 | if (ios->timing == MMC_TIMING_MMC_DDR52) |
Balaji T K | 03b5d92 | 2012-04-09 12:08:33 +0530 | [diff] [blame] | 632 | con |= DDR; /* configure in DDR mode */ |
| 633 | else |
| 634 | con &= ~DDR; |
Andy Shevchenko | 3796fb8a | 2011-07-13 11:31:15 -0400 | [diff] [blame] | 635 | switch (ios->bus_width) { |
| 636 | case MMC_BUS_WIDTH_8: |
| 637 | OMAP_HSMMC_WRITE(host->base, CON, con | DW8); |
| 638 | break; |
| 639 | case MMC_BUS_WIDTH_4: |
| 640 | OMAP_HSMMC_WRITE(host->base, CON, con & ~DW8); |
| 641 | OMAP_HSMMC_WRITE(host->base, HCTL, |
| 642 | OMAP_HSMMC_READ(host->base, HCTL) | FOUR_BIT); |
| 643 | break; |
| 644 | case MMC_BUS_WIDTH_1: |
| 645 | OMAP_HSMMC_WRITE(host->base, CON, con & ~DW8); |
| 646 | OMAP_HSMMC_WRITE(host->base, HCTL, |
| 647 | OMAP_HSMMC_READ(host->base, HCTL) & ~FOUR_BIT); |
| 648 | break; |
| 649 | } |
| 650 | } |
| 651 | |
| 652 | static void omap_hsmmc_set_bus_mode(struct omap_hsmmc_host *host) |
| 653 | { |
| 654 | struct mmc_ios *ios = &host->mmc->ios; |
| 655 | u32 con; |
| 656 | |
| 657 | con = OMAP_HSMMC_READ(host->base, CON); |
| 658 | if (ios->bus_mode == MMC_BUSMODE_OPENDRAIN) |
| 659 | OMAP_HSMMC_WRITE(host->base, CON, con | OD); |
| 660 | else |
| 661 | OMAP_HSMMC_WRITE(host->base, CON, con & ~OD); |
| 662 | } |
| 663 | |
Denis Karpov | 11dd62a | 2009-09-22 16:44:43 -0700 | [diff] [blame] | 664 | #ifdef CONFIG_PM |
| 665 | |
| 666 | /* |
| 667 | * Restore the MMC host context, if it was lost as result of a |
| 668 | * power state change. |
| 669 | */ |
Denis Karpov | 70a3341 | 2009-09-22 16:44:59 -0700 | [diff] [blame] | 670 | static int omap_hsmmc_context_restore(struct omap_hsmmc_host *host) |
Denis Karpov | 11dd62a | 2009-09-22 16:44:43 -0700 | [diff] [blame] | 671 | { |
| 672 | struct mmc_ios *ios = &host->mmc->ios; |
Andy Shevchenko | 3796fb8a | 2011-07-13 11:31:15 -0400 | [diff] [blame] | 673 | u32 hctl, capa; |
Denis Karpov | 11dd62a | 2009-09-22 16:44:43 -0700 | [diff] [blame] | 674 | unsigned long timeout; |
| 675 | |
Tony Lindgren | 0a82e06 | 2013-10-21 00:25:19 +0530 | [diff] [blame] | 676 | if (host->con == OMAP_HSMMC_READ(host->base, CON) && |
| 677 | host->hctl == OMAP_HSMMC_READ(host->base, HCTL) && |
| 678 | host->sysctl == OMAP_HSMMC_READ(host->base, SYSCTL) && |
| 679 | host->capa == OMAP_HSMMC_READ(host->base, CAPA)) |
| 680 | return 0; |
| 681 | |
| 682 | host->context_loss++; |
| 683 | |
Balaji T K | c2200ef | 2012-03-07 09:55:30 -0500 | [diff] [blame] | 684 | if (host->pdata->controller_flags & OMAP_HSMMC_SUPPORTS_DUAL_VOLT) { |
Denis Karpov | 11dd62a | 2009-09-22 16:44:43 -0700 | [diff] [blame] | 685 | if (host->power_mode != MMC_POWER_OFF && |
| 686 | (1 << ios->vdd) <= MMC_VDD_23_24) |
| 687 | hctl = SDVS18; |
| 688 | else |
| 689 | hctl = SDVS30; |
| 690 | capa = VS30 | VS18; |
| 691 | } else { |
| 692 | hctl = SDVS18; |
| 693 | capa = VS18; |
| 694 | } |
| 695 | |
Balaji T K | 5a52b08 | 2014-05-29 10:28:02 +0200 | [diff] [blame] | 696 | if (host->mmc->caps & MMC_CAP_SDIO_IRQ) |
| 697 | hctl |= IWE; |
| 698 | |
Denis Karpov | 11dd62a | 2009-09-22 16:44:43 -0700 | [diff] [blame] | 699 | OMAP_HSMMC_WRITE(host->base, HCTL, |
| 700 | OMAP_HSMMC_READ(host->base, HCTL) | hctl); |
| 701 | |
| 702 | OMAP_HSMMC_WRITE(host->base, CAPA, |
| 703 | OMAP_HSMMC_READ(host->base, CAPA) | capa); |
| 704 | |
| 705 | OMAP_HSMMC_WRITE(host->base, HCTL, |
| 706 | OMAP_HSMMC_READ(host->base, HCTL) | SDBP); |
| 707 | |
| 708 | timeout = jiffies + msecs_to_jiffies(MMC_TIMEOUT_MS); |
| 709 | while ((OMAP_HSMMC_READ(host->base, HCTL) & SDBP) != SDBP |
| 710 | && time_before(jiffies, timeout)) |
| 711 | ; |
| 712 | |
Andreas Fenkart | 2cd3a2a | 2014-05-29 10:28:00 +0200 | [diff] [blame] | 713 | OMAP_HSMMC_WRITE(host->base, ISE, 0); |
| 714 | OMAP_HSMMC_WRITE(host->base, IE, 0); |
| 715 | OMAP_HSMMC_WRITE(host->base, STAT, STAT_CLEAR); |
Denis Karpov | 11dd62a | 2009-09-22 16:44:43 -0700 | [diff] [blame] | 716 | |
| 717 | /* Do not initialize card-specific things if the power is off */ |
| 718 | if (host->power_mode == MMC_POWER_OFF) |
| 719 | goto out; |
| 720 | |
Andy Shevchenko | 3796fb8a | 2011-07-13 11:31:15 -0400 | [diff] [blame] | 721 | omap_hsmmc_set_bus_width(host); |
Denis Karpov | 11dd62a | 2009-09-22 16:44:43 -0700 | [diff] [blame] | 722 | |
Andy Shevchenko | 5934df2 | 2011-05-06 12:14:06 +0300 | [diff] [blame] | 723 | omap_hsmmc_set_clock(host); |
Denis Karpov | 11dd62a | 2009-09-22 16:44:43 -0700 | [diff] [blame] | 724 | |
Andy Shevchenko | 3796fb8a | 2011-07-13 11:31:15 -0400 | [diff] [blame] | 725 | omap_hsmmc_set_bus_mode(host); |
| 726 | |
Denis Karpov | 11dd62a | 2009-09-22 16:44:43 -0700 | [diff] [blame] | 727 | out: |
Tony Lindgren | 0a82e06 | 2013-10-21 00:25:19 +0530 | [diff] [blame] | 728 | dev_dbg(mmc_dev(host->mmc), "context is restored: restore count %d\n", |
| 729 | host->context_loss); |
Denis Karpov | 11dd62a | 2009-09-22 16:44:43 -0700 | [diff] [blame] | 730 | return 0; |
| 731 | } |
| 732 | |
| 733 | /* |
| 734 | * Save the MMC host context (store the number of power state changes so far). |
| 735 | */ |
Denis Karpov | 70a3341 | 2009-09-22 16:44:59 -0700 | [diff] [blame] | 736 | static void omap_hsmmc_context_save(struct omap_hsmmc_host *host) |
Denis Karpov | 11dd62a | 2009-09-22 16:44:43 -0700 | [diff] [blame] | 737 | { |
Tony Lindgren | 0a82e06 | 2013-10-21 00:25:19 +0530 | [diff] [blame] | 738 | host->con = OMAP_HSMMC_READ(host->base, CON); |
| 739 | host->hctl = OMAP_HSMMC_READ(host->base, HCTL); |
| 740 | host->sysctl = OMAP_HSMMC_READ(host->base, SYSCTL); |
| 741 | host->capa = OMAP_HSMMC_READ(host->base, CAPA); |
Denis Karpov | 11dd62a | 2009-09-22 16:44:43 -0700 | [diff] [blame] | 742 | } |
| 743 | |
| 744 | #else |
| 745 | |
Denis Karpov | 70a3341 | 2009-09-22 16:44:59 -0700 | [diff] [blame] | 746 | static int omap_hsmmc_context_restore(struct omap_hsmmc_host *host) |
Denis Karpov | 11dd62a | 2009-09-22 16:44:43 -0700 | [diff] [blame] | 747 | { |
| 748 | return 0; |
| 749 | } |
| 750 | |
Denis Karpov | 70a3341 | 2009-09-22 16:44:59 -0700 | [diff] [blame] | 751 | static void omap_hsmmc_context_save(struct omap_hsmmc_host *host) |
Denis Karpov | 11dd62a | 2009-09-22 16:44:43 -0700 | [diff] [blame] | 752 | { |
| 753 | } |
| 754 | |
| 755 | #endif |
| 756 | |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 757 | /* |
| 758 | * Send init stream sequence to card |
| 759 | * before sending IDLE command |
| 760 | */ |
Denis Karpov | 70a3341 | 2009-09-22 16:44:59 -0700 | [diff] [blame] | 761 | static void send_init_stream(struct omap_hsmmc_host *host) |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 762 | { |
| 763 | int reg = 0; |
| 764 | unsigned long timeout; |
| 765 | |
Adrian Hunter | b62f622 | 2009-09-22 16:45:01 -0700 | [diff] [blame] | 766 | if (host->protect_card) |
| 767 | return; |
| 768 | |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 769 | disable_irq(host->irq); |
Adrian Hunter | b417577 | 2010-05-26 14:42:06 -0700 | [diff] [blame] | 770 | |
| 771 | OMAP_HSMMC_WRITE(host->base, IE, INT_EN_MASK); |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 772 | OMAP_HSMMC_WRITE(host->base, CON, |
| 773 | OMAP_HSMMC_READ(host->base, CON) | INIT_STREAM); |
| 774 | OMAP_HSMMC_WRITE(host->base, CMD, INIT_STREAM_CMD); |
| 775 | |
| 776 | timeout = jiffies + msecs_to_jiffies(MMC_TIMEOUT_MS); |
Venkatraman S | a7e9687 | 2012-11-19 22:00:01 +0530 | [diff] [blame] | 777 | while ((reg != CC_EN) && time_before(jiffies, timeout)) |
| 778 | reg = OMAP_HSMMC_READ(host->base, STAT) & CC_EN; |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 779 | |
| 780 | OMAP_HSMMC_WRITE(host->base, CON, |
| 781 | OMAP_HSMMC_READ(host->base, CON) & ~INIT_STREAM); |
Adrian Hunter | c653a6d | 2009-09-22 16:44:56 -0700 | [diff] [blame] | 782 | |
| 783 | OMAP_HSMMC_WRITE(host->base, STAT, STAT_CLEAR); |
| 784 | OMAP_HSMMC_READ(host->base, STAT); |
| 785 | |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 786 | enable_irq(host->irq); |
| 787 | } |
| 788 | |
| 789 | static inline |
Denis Karpov | 70a3341 | 2009-09-22 16:44:59 -0700 | [diff] [blame] | 790 | int omap_hsmmc_cover_is_closed(struct omap_hsmmc_host *host) |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 791 | { |
| 792 | int r = 1; |
| 793 | |
Denis Karpov | 191d1f1 | 2009-09-22 16:44:55 -0700 | [diff] [blame] | 794 | if (mmc_slot(host).get_cover_state) |
| 795 | r = mmc_slot(host).get_cover_state(host->dev, host->slot_id); |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 796 | return r; |
| 797 | } |
| 798 | |
| 799 | static ssize_t |
Denis Karpov | 70a3341 | 2009-09-22 16:44:59 -0700 | [diff] [blame] | 800 | omap_hsmmc_show_cover_switch(struct device *dev, struct device_attribute *attr, |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 801 | char *buf) |
| 802 | { |
| 803 | struct mmc_host *mmc = container_of(dev, struct mmc_host, class_dev); |
Denis Karpov | 70a3341 | 2009-09-22 16:44:59 -0700 | [diff] [blame] | 804 | struct omap_hsmmc_host *host = mmc_priv(mmc); |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 805 | |
Denis Karpov | 70a3341 | 2009-09-22 16:44:59 -0700 | [diff] [blame] | 806 | return sprintf(buf, "%s\n", |
| 807 | omap_hsmmc_cover_is_closed(host) ? "closed" : "open"); |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 808 | } |
| 809 | |
Denis Karpov | 70a3341 | 2009-09-22 16:44:59 -0700 | [diff] [blame] | 810 | static DEVICE_ATTR(cover_switch, S_IRUGO, omap_hsmmc_show_cover_switch, NULL); |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 811 | |
| 812 | static ssize_t |
Denis Karpov | 70a3341 | 2009-09-22 16:44:59 -0700 | [diff] [blame] | 813 | omap_hsmmc_show_slot_name(struct device *dev, struct device_attribute *attr, |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 814 | char *buf) |
| 815 | { |
| 816 | struct mmc_host *mmc = container_of(dev, struct mmc_host, class_dev); |
Denis Karpov | 70a3341 | 2009-09-22 16:44:59 -0700 | [diff] [blame] | 817 | struct omap_hsmmc_host *host = mmc_priv(mmc); |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 818 | |
Denis Karpov | 191d1f1 | 2009-09-22 16:44:55 -0700 | [diff] [blame] | 819 | return sprintf(buf, "%s\n", mmc_slot(host).name); |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 820 | } |
| 821 | |
Denis Karpov | 70a3341 | 2009-09-22 16:44:59 -0700 | [diff] [blame] | 822 | static DEVICE_ATTR(slot_name, S_IRUGO, omap_hsmmc_show_slot_name, NULL); |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 823 | |
| 824 | /* |
| 825 | * Configure the response type and send the cmd. |
| 826 | */ |
| 827 | static void |
Denis Karpov | 70a3341 | 2009-09-22 16:44:59 -0700 | [diff] [blame] | 828 | omap_hsmmc_start_command(struct omap_hsmmc_host *host, struct mmc_command *cmd, |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 829 | struct mmc_data *data) |
| 830 | { |
| 831 | int cmdreg = 0, resptype = 0, cmdtype = 0; |
| 832 | |
Venkatraman S | 8986d31 | 2012-08-07 19:10:38 +0530 | [diff] [blame] | 833 | dev_vdbg(mmc_dev(host->mmc), "%s: CMD%d, argument 0x%08x\n", |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 834 | mmc_hostname(host->mmc), cmd->opcode, cmd->arg); |
| 835 | host->cmd = cmd; |
| 836 | |
Adrian Hunter | 93caf8e69 | 2010-08-11 14:17:48 -0700 | [diff] [blame] | 837 | omap_hsmmc_enable_irq(host, cmd); |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 838 | |
Adrian Hunter | 4a694dc | 2009-01-12 16:13:08 +0200 | [diff] [blame] | 839 | host->response_busy = 0; |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 840 | if (cmd->flags & MMC_RSP_PRESENT) { |
| 841 | if (cmd->flags & MMC_RSP_136) |
| 842 | resptype = 1; |
Adrian Hunter | 4a694dc | 2009-01-12 16:13:08 +0200 | [diff] [blame] | 843 | else if (cmd->flags & MMC_RSP_BUSY) { |
| 844 | resptype = 3; |
| 845 | host->response_busy = 1; |
| 846 | } else |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 847 | resptype = 2; |
| 848 | } |
| 849 | |
| 850 | /* |
| 851 | * Unlike OMAP1 controller, the cmdtype does not seem to be based on |
| 852 | * ac, bc, adtc, bcr. Only commands ending an open ended transfer need |
| 853 | * a val of 0x3, rest 0x0. |
| 854 | */ |
| 855 | if (cmd == host->mrq->stop) |
| 856 | cmdtype = 0x3; |
| 857 | |
| 858 | cmdreg = (cmd->opcode << 24) | (resptype << 16) | (cmdtype << 22); |
| 859 | |
Balaji T K | a2e7715 | 2014-01-21 19:54:42 +0530 | [diff] [blame] | 860 | if ((host->flags & AUTO_CMD23) && mmc_op_multi(cmd->opcode) && |
| 861 | host->mrq->sbc) { |
| 862 | cmdreg |= ACEN_ACMD23; |
| 863 | OMAP_HSMMC_WRITE(host->base, SDMASA, host->mrq->sbc->arg); |
| 864 | } |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 865 | if (data) { |
| 866 | cmdreg |= DP_SELECT | MSBS | BCE; |
| 867 | if (data->flags & MMC_DATA_READ) |
| 868 | cmdreg |= DDIR; |
| 869 | else |
| 870 | cmdreg &= ~(DDIR); |
| 871 | } |
| 872 | |
| 873 | if (host->use_dma) |
Venkatraman S | a7e9687 | 2012-11-19 22:00:01 +0530 | [diff] [blame] | 874 | cmdreg |= DMAE; |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 875 | |
Adrian Hunter | b417577 | 2010-05-26 14:42:06 -0700 | [diff] [blame] | 876 | host->req_in_progress = 1; |
Adrian Hunter | 4dffd7a | 2009-09-22 16:44:58 -0700 | [diff] [blame] | 877 | |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 878 | OMAP_HSMMC_WRITE(host->base, ARG, cmd->arg); |
| 879 | OMAP_HSMMC_WRITE(host->base, CMD, cmdreg); |
| 880 | } |
| 881 | |
Juha Yrjola | 0ccd76d | 2008-11-14 15:22:00 +0200 | [diff] [blame] | 882 | static int |
Denis Karpov | 70a3341 | 2009-09-22 16:44:59 -0700 | [diff] [blame] | 883 | omap_hsmmc_get_dma_dir(struct omap_hsmmc_host *host, struct mmc_data *data) |
Juha Yrjola | 0ccd76d | 2008-11-14 15:22:00 +0200 | [diff] [blame] | 884 | { |
| 885 | if (data->flags & MMC_DATA_WRITE) |
| 886 | return DMA_TO_DEVICE; |
| 887 | else |
| 888 | return DMA_FROM_DEVICE; |
| 889 | } |
| 890 | |
Russell King | c5c9892 | 2012-04-13 12:14:39 +0100 | [diff] [blame] | 891 | static struct dma_chan *omap_hsmmc_get_dma_chan(struct omap_hsmmc_host *host, |
| 892 | struct mmc_data *data) |
| 893 | { |
| 894 | return data->flags & MMC_DATA_WRITE ? host->tx_chan : host->rx_chan; |
| 895 | } |
| 896 | |
Adrian Hunter | b417577 | 2010-05-26 14:42:06 -0700 | [diff] [blame] | 897 | static void omap_hsmmc_request_done(struct omap_hsmmc_host *host, struct mmc_request *mrq) |
| 898 | { |
| 899 | int dma_ch; |
Venkatraman S | 31463b1 | 2012-04-09 12:08:34 +0530 | [diff] [blame] | 900 | unsigned long flags; |
Adrian Hunter | b417577 | 2010-05-26 14:42:06 -0700 | [diff] [blame] | 901 | |
Venkatraman S | 31463b1 | 2012-04-09 12:08:34 +0530 | [diff] [blame] | 902 | spin_lock_irqsave(&host->irq_lock, flags); |
Adrian Hunter | b417577 | 2010-05-26 14:42:06 -0700 | [diff] [blame] | 903 | host->req_in_progress = 0; |
| 904 | dma_ch = host->dma_ch; |
Venkatraman S | 31463b1 | 2012-04-09 12:08:34 +0530 | [diff] [blame] | 905 | spin_unlock_irqrestore(&host->irq_lock, flags); |
Adrian Hunter | b417577 | 2010-05-26 14:42:06 -0700 | [diff] [blame] | 906 | |
| 907 | omap_hsmmc_disable_irq(host); |
| 908 | /* Do not complete the request if DMA is still in progress */ |
| 909 | if (mrq->data && host->use_dma && dma_ch != -1) |
| 910 | return; |
| 911 | host->mrq = NULL; |
| 912 | mmc_request_done(host->mmc, mrq); |
| 913 | } |
| 914 | |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 915 | /* |
| 916 | * Notify the transfer complete to MMC core |
| 917 | */ |
| 918 | static void |
Denis Karpov | 70a3341 | 2009-09-22 16:44:59 -0700 | [diff] [blame] | 919 | omap_hsmmc_xfer_done(struct omap_hsmmc_host *host, struct mmc_data *data) |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 920 | { |
Adrian Hunter | 4a694dc | 2009-01-12 16:13:08 +0200 | [diff] [blame] | 921 | if (!data) { |
| 922 | struct mmc_request *mrq = host->mrq; |
| 923 | |
Adrian Hunter | 2305010 | 2009-09-22 16:44:57 -0700 | [diff] [blame] | 924 | /* TC before CC from CMD6 - don't know why, but it happens */ |
| 925 | if (host->cmd && host->cmd->opcode == 6 && |
| 926 | host->response_busy) { |
| 927 | host->response_busy = 0; |
| 928 | return; |
| 929 | } |
| 930 | |
Adrian Hunter | b417577 | 2010-05-26 14:42:06 -0700 | [diff] [blame] | 931 | omap_hsmmc_request_done(host, mrq); |
Adrian Hunter | 4a694dc | 2009-01-12 16:13:08 +0200 | [diff] [blame] | 932 | return; |
| 933 | } |
| 934 | |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 935 | host->data = NULL; |
| 936 | |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 937 | if (!data->error) |
| 938 | data->bytes_xfered += data->blocks * (data->blksz); |
| 939 | else |
| 940 | data->bytes_xfered = 0; |
| 941 | |
Balaji T K | bf129e1 | 2014-01-21 19:54:42 +0530 | [diff] [blame] | 942 | if (data->stop && (data->error || !host->mrq->sbc)) |
| 943 | omap_hsmmc_start_command(host, data->stop, NULL); |
| 944 | else |
Adrian Hunter | b417577 | 2010-05-26 14:42:06 -0700 | [diff] [blame] | 945 | omap_hsmmc_request_done(host, data->mrq); |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 946 | } |
| 947 | |
| 948 | /* |
| 949 | * Notify the core about command completion |
| 950 | */ |
| 951 | static void |
Denis Karpov | 70a3341 | 2009-09-22 16:44:59 -0700 | [diff] [blame] | 952 | omap_hsmmc_cmd_done(struct omap_hsmmc_host *host, struct mmc_command *cmd) |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 953 | { |
Balaji T K | bf129e1 | 2014-01-21 19:54:42 +0530 | [diff] [blame] | 954 | if (host->mrq->sbc && (host->cmd == host->mrq->sbc) && |
Balaji T K | a2e7715 | 2014-01-21 19:54:42 +0530 | [diff] [blame] | 955 | !host->mrq->sbc->error && !(host->flags & AUTO_CMD23)) { |
Balaji T K | 2177fa9 | 2014-05-09 22:16:52 +0530 | [diff] [blame] | 956 | host->cmd = NULL; |
Balaji T K | bf129e1 | 2014-01-21 19:54:42 +0530 | [diff] [blame] | 957 | omap_hsmmc_start_dma_transfer(host); |
| 958 | omap_hsmmc_start_command(host, host->mrq->cmd, |
| 959 | host->mrq->data); |
| 960 | return; |
| 961 | } |
| 962 | |
Balaji T K | 2177fa9 | 2014-05-09 22:16:52 +0530 | [diff] [blame] | 963 | host->cmd = NULL; |
| 964 | |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 965 | if (cmd->flags & MMC_RSP_PRESENT) { |
| 966 | if (cmd->flags & MMC_RSP_136) { |
| 967 | /* response type 2 */ |
| 968 | cmd->resp[3] = OMAP_HSMMC_READ(host->base, RSP10); |
| 969 | cmd->resp[2] = OMAP_HSMMC_READ(host->base, RSP32); |
| 970 | cmd->resp[1] = OMAP_HSMMC_READ(host->base, RSP54); |
| 971 | cmd->resp[0] = OMAP_HSMMC_READ(host->base, RSP76); |
| 972 | } else { |
| 973 | /* response types 1, 1b, 3, 4, 5, 6 */ |
| 974 | cmd->resp[0] = OMAP_HSMMC_READ(host->base, RSP10); |
| 975 | } |
| 976 | } |
Adrian Hunter | b417577 | 2010-05-26 14:42:06 -0700 | [diff] [blame] | 977 | if ((host->data == NULL && !host->response_busy) || cmd->error) |
Balaji T K | d4b2c37 | 2014-01-21 19:54:42 +0530 | [diff] [blame] | 978 | omap_hsmmc_request_done(host, host->mrq); |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 979 | } |
| 980 | |
| 981 | /* |
| 982 | * DMA clean up for command errors |
| 983 | */ |
Denis Karpov | 70a3341 | 2009-09-22 16:44:59 -0700 | [diff] [blame] | 984 | static void omap_hsmmc_dma_cleanup(struct omap_hsmmc_host *host, int errno) |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 985 | { |
Adrian Hunter | b417577 | 2010-05-26 14:42:06 -0700 | [diff] [blame] | 986 | int dma_ch; |
Venkatraman S | 31463b1 | 2012-04-09 12:08:34 +0530 | [diff] [blame] | 987 | unsigned long flags; |
Adrian Hunter | b417577 | 2010-05-26 14:42:06 -0700 | [diff] [blame] | 988 | |
Jarkko Lavinen | 82788ff | 2008-12-05 12:31:46 +0200 | [diff] [blame] | 989 | host->data->error = errno; |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 990 | |
Venkatraman S | 31463b1 | 2012-04-09 12:08:34 +0530 | [diff] [blame] | 991 | spin_lock_irqsave(&host->irq_lock, flags); |
Adrian Hunter | b417577 | 2010-05-26 14:42:06 -0700 | [diff] [blame] | 992 | dma_ch = host->dma_ch; |
| 993 | host->dma_ch = -1; |
Venkatraman S | 31463b1 | 2012-04-09 12:08:34 +0530 | [diff] [blame] | 994 | spin_unlock_irqrestore(&host->irq_lock, flags); |
Adrian Hunter | b417577 | 2010-05-26 14:42:06 -0700 | [diff] [blame] | 995 | |
| 996 | if (host->use_dma && dma_ch != -1) { |
Russell King | c5c9892 | 2012-04-13 12:14:39 +0100 | [diff] [blame] | 997 | struct dma_chan *chan = omap_hsmmc_get_dma_chan(host, host->data); |
| 998 | |
| 999 | dmaengine_terminate_all(chan); |
| 1000 | dma_unmap_sg(chan->device->dev, |
| 1001 | host->data->sg, host->data->sg_len, |
Denis Karpov | 70a3341 | 2009-09-22 16:44:59 -0700 | [diff] [blame] | 1002 | omap_hsmmc_get_dma_dir(host, host->data)); |
Russell King | c5c9892 | 2012-04-13 12:14:39 +0100 | [diff] [blame] | 1003 | |
Per Forlin | 053bf34 | 2011-11-07 21:55:11 +0530 | [diff] [blame] | 1004 | host->data->host_cookie = 0; |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 1005 | } |
| 1006 | host->data = NULL; |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 1007 | } |
| 1008 | |
| 1009 | /* |
| 1010 | * Readable error output |
| 1011 | */ |
| 1012 | #ifdef CONFIG_MMC_DEBUG |
Adrian Hunter | 699b958 | 2011-05-06 12:14:01 +0300 | [diff] [blame] | 1013 | static void omap_hsmmc_dbg_report_irq(struct omap_hsmmc_host *host, u32 status) |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 1014 | { |
| 1015 | /* --- means reserved bit without definition at documentation */ |
Denis Karpov | 70a3341 | 2009-09-22 16:44:59 -0700 | [diff] [blame] | 1016 | static const char *omap_hsmmc_status_bits[] = { |
Adrian Hunter | 699b958 | 2011-05-06 12:14:01 +0300 | [diff] [blame] | 1017 | "CC" , "TC" , "BGE", "---", "BWR" , "BRR" , "---" , "---" , |
| 1018 | "CIRQ", "OBI" , "---", "---", "---" , "---" , "---" , "ERRI", |
| 1019 | "CTO" , "CCRC", "CEB", "CIE", "DTO" , "DCRC", "DEB" , "---" , |
| 1020 | "ACE" , "---" , "---", "---", "CERR", "BADA", "---" , "---" |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 1021 | }; |
| 1022 | char res[256]; |
| 1023 | char *buf = res; |
| 1024 | int len, i; |
| 1025 | |
| 1026 | len = sprintf(buf, "MMC IRQ 0x%x :", status); |
| 1027 | buf += len; |
| 1028 | |
Denis Karpov | 70a3341 | 2009-09-22 16:44:59 -0700 | [diff] [blame] | 1029 | for (i = 0; i < ARRAY_SIZE(omap_hsmmc_status_bits); i++) |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 1030 | if (status & (1 << i)) { |
Denis Karpov | 70a3341 | 2009-09-22 16:44:59 -0700 | [diff] [blame] | 1031 | len = sprintf(buf, " %s", omap_hsmmc_status_bits[i]); |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 1032 | buf += len; |
| 1033 | } |
| 1034 | |
Venkatraman S | 8986d31 | 2012-08-07 19:10:38 +0530 | [diff] [blame] | 1035 | dev_vdbg(mmc_dev(host->mmc), "%s\n", res); |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 1036 | } |
Adrian Hunter | 699b958 | 2011-05-06 12:14:01 +0300 | [diff] [blame] | 1037 | #else |
| 1038 | static inline void omap_hsmmc_dbg_report_irq(struct omap_hsmmc_host *host, |
| 1039 | u32 status) |
| 1040 | { |
| 1041 | } |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 1042 | #endif /* CONFIG_MMC_DEBUG */ |
| 1043 | |
Jean Pihet | 3ebf74b | 2009-02-06 16:42:51 +0100 | [diff] [blame] | 1044 | /* |
| 1045 | * MMC controller internal state machines reset |
| 1046 | * |
| 1047 | * Used to reset command or data internal state machines, using respectively |
| 1048 | * SRC or SRD bit of SYSCTL register |
| 1049 | * Can be called from interrupt context |
| 1050 | */ |
Denis Karpov | 70a3341 | 2009-09-22 16:44:59 -0700 | [diff] [blame] | 1051 | static inline void omap_hsmmc_reset_controller_fsm(struct omap_hsmmc_host *host, |
| 1052 | unsigned long bit) |
Jean Pihet | 3ebf74b | 2009-02-06 16:42:51 +0100 | [diff] [blame] | 1053 | { |
| 1054 | unsigned long i = 0; |
Jianpeng Ma | 1e88178 | 2013-10-21 00:25:20 +0530 | [diff] [blame] | 1055 | unsigned long limit = MMC_TIMEOUT_US; |
Jean Pihet | 3ebf74b | 2009-02-06 16:42:51 +0100 | [diff] [blame] | 1056 | |
| 1057 | OMAP_HSMMC_WRITE(host->base, SYSCTL, |
| 1058 | OMAP_HSMMC_READ(host->base, SYSCTL) | bit); |
| 1059 | |
Madhusudhan Chikkature | 07ad64b | 2010-10-01 16:35:25 -0700 | [diff] [blame] | 1060 | /* |
| 1061 | * OMAP4 ES2 and greater has an updated reset logic. |
| 1062 | * Monitor a 0->1 transition first |
| 1063 | */ |
| 1064 | if (mmc_slot(host).features & HSMMC_HAS_UPDATED_RESET) { |
kishore kadiyala | b432b4b | 2010-11-17 22:35:32 -0500 | [diff] [blame] | 1065 | while ((!(OMAP_HSMMC_READ(host->base, SYSCTL) & bit)) |
Madhusudhan Chikkature | 07ad64b | 2010-10-01 16:35:25 -0700 | [diff] [blame] | 1066 | && (i++ < limit)) |
Jianpeng Ma | 1e88178 | 2013-10-21 00:25:20 +0530 | [diff] [blame] | 1067 | udelay(1); |
Madhusudhan Chikkature | 07ad64b | 2010-10-01 16:35:25 -0700 | [diff] [blame] | 1068 | } |
| 1069 | i = 0; |
| 1070 | |
Jean Pihet | 3ebf74b | 2009-02-06 16:42:51 +0100 | [diff] [blame] | 1071 | while ((OMAP_HSMMC_READ(host->base, SYSCTL) & bit) && |
| 1072 | (i++ < limit)) |
Jianpeng Ma | 1e88178 | 2013-10-21 00:25:20 +0530 | [diff] [blame] | 1073 | udelay(1); |
Jean Pihet | 3ebf74b | 2009-02-06 16:42:51 +0100 | [diff] [blame] | 1074 | |
| 1075 | if (OMAP_HSMMC_READ(host->base, SYSCTL) & bit) |
| 1076 | dev_err(mmc_dev(host->mmc), |
| 1077 | "Timeout waiting on controller reset in %s\n", |
| 1078 | __func__); |
| 1079 | } |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 1080 | |
Balaji T K | 25e1897 | 2012-11-19 21:59:55 +0530 | [diff] [blame] | 1081 | static void hsmmc_command_incomplete(struct omap_hsmmc_host *host, |
| 1082 | int err, int end_cmd) |
Venkatraman S | ae4bf78 | 2012-08-09 20:36:07 +0530 | [diff] [blame] | 1083 | { |
Balaji T K | 25e1897 | 2012-11-19 21:59:55 +0530 | [diff] [blame] | 1084 | if (end_cmd) { |
Balaji T K | 94d4f27 | 2012-11-19 21:59:56 +0530 | [diff] [blame] | 1085 | omap_hsmmc_reset_controller_fsm(host, SRC); |
Balaji T K | 25e1897 | 2012-11-19 21:59:55 +0530 | [diff] [blame] | 1086 | if (host->cmd) |
| 1087 | host->cmd->error = err; |
| 1088 | } |
Venkatraman S | ae4bf78 | 2012-08-09 20:36:07 +0530 | [diff] [blame] | 1089 | |
| 1090 | if (host->data) { |
| 1091 | omap_hsmmc_reset_controller_fsm(host, SRD); |
| 1092 | omap_hsmmc_dma_cleanup(host, err); |
Balaji T K | dc7745b | 2012-11-19 21:59:57 +0530 | [diff] [blame] | 1093 | } else if (host->mrq && host->mrq->cmd) |
| 1094 | host->mrq->cmd->error = err; |
Venkatraman S | ae4bf78 | 2012-08-09 20:36:07 +0530 | [diff] [blame] | 1095 | } |
| 1096 | |
Adrian Hunter | b417577 | 2010-05-26 14:42:06 -0700 | [diff] [blame] | 1097 | static void omap_hsmmc_do_irq(struct omap_hsmmc_host *host, int status) |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 1098 | { |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 1099 | struct mmc_data *data; |
Adrian Hunter | b417577 | 2010-05-26 14:42:06 -0700 | [diff] [blame] | 1100 | int end_cmd = 0, end_trans = 0; |
Balaji T K | a2e7715 | 2014-01-21 19:54:42 +0530 | [diff] [blame] | 1101 | int error = 0; |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 1102 | |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 1103 | data = host->data; |
Venkatraman S | 8986d31 | 2012-08-07 19:10:38 +0530 | [diff] [blame] | 1104 | dev_vdbg(mmc_dev(host->mmc), "IRQ Status is %x\n", status); |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 1105 | |
Venkatraman S | a7e9687 | 2012-11-19 22:00:01 +0530 | [diff] [blame] | 1106 | if (status & ERR_EN) { |
Adrian Hunter | 699b958 | 2011-05-06 12:14:01 +0300 | [diff] [blame] | 1107 | omap_hsmmc_dbg_report_irq(host, status); |
Adrian Hunter | 4a694dc | 2009-01-12 16:13:08 +0200 | [diff] [blame] | 1108 | |
Venkatraman S | a7e9687 | 2012-11-19 22:00:01 +0530 | [diff] [blame] | 1109 | if (status & (CTO_EN | CCRC_EN)) |
Balaji T K | 25e1897 | 2012-11-19 21:59:55 +0530 | [diff] [blame] | 1110 | end_cmd = 1; |
Venkatraman S | a7e9687 | 2012-11-19 22:00:01 +0530 | [diff] [blame] | 1111 | if (status & (CTO_EN | DTO_EN)) |
Balaji T K | 25e1897 | 2012-11-19 21:59:55 +0530 | [diff] [blame] | 1112 | hsmmc_command_incomplete(host, -ETIMEDOUT, end_cmd); |
Venkatraman S | a7e9687 | 2012-11-19 22:00:01 +0530 | [diff] [blame] | 1113 | else if (status & (CCRC_EN | DCRC_EN)) |
Balaji T K | 25e1897 | 2012-11-19 21:59:55 +0530 | [diff] [blame] | 1114 | hsmmc_command_incomplete(host, -EILSEQ, end_cmd); |
| 1115 | |
Balaji T K | a2e7715 | 2014-01-21 19:54:42 +0530 | [diff] [blame] | 1116 | if (status & ACE_EN) { |
| 1117 | u32 ac12; |
| 1118 | ac12 = OMAP_HSMMC_READ(host->base, AC12); |
| 1119 | if (!(ac12 & ACNE) && host->mrq->sbc) { |
| 1120 | end_cmd = 1; |
| 1121 | if (ac12 & ACTO) |
| 1122 | error = -ETIMEDOUT; |
| 1123 | else if (ac12 & (ACCE | ACEB | ACIE)) |
| 1124 | error = -EILSEQ; |
| 1125 | host->mrq->sbc->error = error; |
| 1126 | hsmmc_command_incomplete(host, error, end_cmd); |
| 1127 | } |
| 1128 | dev_dbg(mmc_dev(host->mmc), "AC12 err: 0x%x\n", ac12); |
| 1129 | } |
Venkatraman S | ae4bf78 | 2012-08-09 20:36:07 +0530 | [diff] [blame] | 1130 | if (host->data || host->response_busy) { |
Balaji T K | 25e1897 | 2012-11-19 21:59:55 +0530 | [diff] [blame] | 1131 | end_trans = !end_cmd; |
Venkatraman S | ae4bf78 | 2012-08-09 20:36:07 +0530 | [diff] [blame] | 1132 | host->response_busy = 0; |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 1133 | } |
| 1134 | } |
| 1135 | |
Francesco Lavra | 7472bab | 2013-06-29 08:25:12 +0200 | [diff] [blame] | 1136 | OMAP_HSMMC_WRITE(host->base, STAT, status); |
Venkatraman S | a7e9687 | 2012-11-19 22:00:01 +0530 | [diff] [blame] | 1137 | if (end_cmd || ((status & CC_EN) && host->cmd)) |
Denis Karpov | 70a3341 | 2009-09-22 16:44:59 -0700 | [diff] [blame] | 1138 | omap_hsmmc_cmd_done(host, host->cmd); |
Venkatraman S | a7e9687 | 2012-11-19 22:00:01 +0530 | [diff] [blame] | 1139 | if ((end_trans || (status & TC_EN)) && host->mrq) |
Denis Karpov | 70a3341 | 2009-09-22 16:44:59 -0700 | [diff] [blame] | 1140 | omap_hsmmc_xfer_done(host, data); |
Adrian Hunter | b417577 | 2010-05-26 14:42:06 -0700 | [diff] [blame] | 1141 | } |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 1142 | |
Adrian Hunter | b417577 | 2010-05-26 14:42:06 -0700 | [diff] [blame] | 1143 | /* |
| 1144 | * MMC controller IRQ handler |
| 1145 | */ |
| 1146 | static irqreturn_t omap_hsmmc_irq(int irq, void *dev_id) |
| 1147 | { |
| 1148 | struct omap_hsmmc_host *host = dev_id; |
| 1149 | int status; |
| 1150 | |
| 1151 | status = OMAP_HSMMC_READ(host->base, STAT); |
Andreas Fenkart | 2cd3a2a | 2014-05-29 10:28:00 +0200 | [diff] [blame] | 1152 | while (status & (INT_EN_MASK | CIRQ_EN)) { |
| 1153 | if (host->req_in_progress) |
| 1154 | omap_hsmmc_do_irq(host, status); |
| 1155 | |
| 1156 | if (status & CIRQ_EN) |
| 1157 | mmc_signal_sdio_irq(host->mmc); |
Venkatraman S | 1f6b9fa | 2012-08-08 15:44:29 +0530 | [diff] [blame] | 1158 | |
Adrian Hunter | b417577 | 2010-05-26 14:42:06 -0700 | [diff] [blame] | 1159 | /* Flush posted write */ |
| 1160 | status = OMAP_HSMMC_READ(host->base, STAT); |
Venkatraman S | 1f6b9fa | 2012-08-08 15:44:29 +0530 | [diff] [blame] | 1161 | } |
Adrian Hunter | 4dffd7a | 2009-09-22 16:44:58 -0700 | [diff] [blame] | 1162 | |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 1163 | return IRQ_HANDLED; |
| 1164 | } |
| 1165 | |
Andreas Fenkart | 2cd3a2a | 2014-05-29 10:28:00 +0200 | [diff] [blame] | 1166 | static irqreturn_t omap_hsmmc_wake_irq(int irq, void *dev_id) |
| 1167 | { |
| 1168 | struct omap_hsmmc_host *host = dev_id; |
| 1169 | |
| 1170 | /* cirq is level triggered, disable to avoid infinite loop */ |
| 1171 | spin_lock(&host->irq_lock); |
| 1172 | if (host->flags & HSMMC_WAKE_IRQ_ENABLED) { |
| 1173 | disable_irq_nosync(host->wake_irq); |
| 1174 | host->flags &= ~HSMMC_WAKE_IRQ_ENABLED; |
| 1175 | } |
| 1176 | spin_unlock(&host->irq_lock); |
| 1177 | pm_request_resume(host->dev); /* no use counter */ |
| 1178 | |
| 1179 | return IRQ_HANDLED; |
| 1180 | } |
| 1181 | |
Denis Karpov | 70a3341 | 2009-09-22 16:44:59 -0700 | [diff] [blame] | 1182 | static void set_sd_bus_power(struct omap_hsmmc_host *host) |
Adrian Hunter | e13bb30 | 2009-03-12 17:08:26 +0200 | [diff] [blame] | 1183 | { |
| 1184 | unsigned long i; |
| 1185 | |
| 1186 | OMAP_HSMMC_WRITE(host->base, HCTL, |
| 1187 | OMAP_HSMMC_READ(host->base, HCTL) | SDBP); |
| 1188 | for (i = 0; i < loops_per_jiffy; i++) { |
| 1189 | if (OMAP_HSMMC_READ(host->base, HCTL) & SDBP) |
| 1190 | break; |
| 1191 | cpu_relax(); |
| 1192 | } |
| 1193 | } |
| 1194 | |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 1195 | /* |
David Brownell | eb25082 | 2009-02-17 14:49:01 -0800 | [diff] [blame] | 1196 | * Switch MMC interface voltage ... only relevant for MMC1. |
| 1197 | * |
| 1198 | * MMC2 and MMC3 use fixed 1.8V levels, and maybe a transceiver. |
| 1199 | * The MMC2 transceiver controls are used instead of DAT4..DAT7. |
| 1200 | * Some chips, like eMMC ones, use internal transceivers. |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 1201 | */ |
Denis Karpov | 70a3341 | 2009-09-22 16:44:59 -0700 | [diff] [blame] | 1202 | static int omap_hsmmc_switch_opcond(struct omap_hsmmc_host *host, int vdd) |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 1203 | { |
| 1204 | u32 reg_val = 0; |
| 1205 | int ret; |
| 1206 | |
| 1207 | /* Disable the clocks */ |
Balaji T K | fa4aa2d | 2011-07-01 22:09:35 +0530 | [diff] [blame] | 1208 | pm_runtime_put_sync(host->dev); |
Rajendra Nayak | cd03d9a | 2012-04-09 12:08:35 +0530 | [diff] [blame] | 1209 | if (host->dbclk) |
Rajendra Nayak | 94c1814 | 2012-06-27 14:19:54 +0530 | [diff] [blame] | 1210 | clk_disable_unprepare(host->dbclk); |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 1211 | |
| 1212 | /* Turn the power off */ |
| 1213 | ret = mmc_slot(host).set_power(host->dev, host->slot_id, 0, 0); |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 1214 | |
| 1215 | /* Turn the power ON with given VDD 1.8 or 3.0v */ |
Adrian Hunter | 2bec089 | 2009-09-22 16:45:02 -0700 | [diff] [blame] | 1216 | if (!ret) |
| 1217 | ret = mmc_slot(host).set_power(host->dev, host->slot_id, 1, |
| 1218 | vdd); |
Balaji T K | fa4aa2d | 2011-07-01 22:09:35 +0530 | [diff] [blame] | 1219 | pm_runtime_get_sync(host->dev); |
Rajendra Nayak | cd03d9a | 2012-04-09 12:08:35 +0530 | [diff] [blame] | 1220 | if (host->dbclk) |
Rajendra Nayak | 94c1814 | 2012-06-27 14:19:54 +0530 | [diff] [blame] | 1221 | clk_prepare_enable(host->dbclk); |
Adrian Hunter | 2bec089 | 2009-09-22 16:45:02 -0700 | [diff] [blame] | 1222 | |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 1223 | if (ret != 0) |
| 1224 | goto err; |
| 1225 | |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 1226 | OMAP_HSMMC_WRITE(host->base, HCTL, |
| 1227 | OMAP_HSMMC_READ(host->base, HCTL) & SDVSCLR); |
| 1228 | reg_val = OMAP_HSMMC_READ(host->base, HCTL); |
David Brownell | eb25082 | 2009-02-17 14:49:01 -0800 | [diff] [blame] | 1229 | |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 1230 | /* |
| 1231 | * If a MMC dual voltage card is detected, the set_ios fn calls |
| 1232 | * this fn with VDD bit set for 1.8V. Upon card removal from the |
Denis Karpov | 70a3341 | 2009-09-22 16:44:59 -0700 | [diff] [blame] | 1233 | * slot, omap_hsmmc_set_ios sets the VDD back to 3V on MMC_POWER_OFF. |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 1234 | * |
David Brownell | eb25082 | 2009-02-17 14:49:01 -0800 | [diff] [blame] | 1235 | * Cope with a bit of slop in the range ... per data sheets: |
| 1236 | * - "1.8V" for vdds_mmc1/vdds_mmc1a can be up to 2.45V max, |
| 1237 | * but recommended values are 1.71V to 1.89V |
| 1238 | * - "3.0V" for vdds_mmc1/vdds_mmc1a can be up to 3.5V max, |
| 1239 | * but recommended values are 2.7V to 3.3V |
| 1240 | * |
| 1241 | * Board setup code shouldn't permit anything very out-of-range. |
| 1242 | * TWL4030-family VMMC1 and VSIM regulators are fine (avoiding the |
| 1243 | * middle range) but VSIM can't power DAT4..DAT7 at more than 3V. |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 1244 | */ |
David Brownell | eb25082 | 2009-02-17 14:49:01 -0800 | [diff] [blame] | 1245 | if ((1 << vdd) <= MMC_VDD_23_24) |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 1246 | reg_val |= SDVS18; |
David Brownell | eb25082 | 2009-02-17 14:49:01 -0800 | [diff] [blame] | 1247 | else |
| 1248 | reg_val |= SDVS30; |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 1249 | |
| 1250 | OMAP_HSMMC_WRITE(host->base, HCTL, reg_val); |
Adrian Hunter | e13bb30 | 2009-03-12 17:08:26 +0200 | [diff] [blame] | 1251 | set_sd_bus_power(host); |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 1252 | |
| 1253 | return 0; |
| 1254 | err: |
Venkatraman S | b1e056a | 2012-11-19 22:00:00 +0530 | [diff] [blame] | 1255 | dev_err(mmc_dev(host->mmc), "Unable to switch operating voltage\n"); |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 1256 | return ret; |
| 1257 | } |
| 1258 | |
Adrian Hunter | b62f622 | 2009-09-22 16:45:01 -0700 | [diff] [blame] | 1259 | /* Protect the card while the cover is open */ |
| 1260 | static void omap_hsmmc_protect_card(struct omap_hsmmc_host *host) |
| 1261 | { |
| 1262 | if (!mmc_slot(host).get_cover_state) |
| 1263 | return; |
| 1264 | |
| 1265 | host->reqs_blocked = 0; |
| 1266 | if (mmc_slot(host).get_cover_state(host->dev, host->slot_id)) { |
| 1267 | if (host->protect_card) { |
Rajendra Nayak | 2cecdf0 | 2012-02-23 17:02:20 +0530 | [diff] [blame] | 1268 | dev_info(host->dev, "%s: cover is closed, " |
Adrian Hunter | b62f622 | 2009-09-22 16:45:01 -0700 | [diff] [blame] | 1269 | "card is now accessible\n", |
| 1270 | mmc_hostname(host->mmc)); |
| 1271 | host->protect_card = 0; |
| 1272 | } |
| 1273 | } else { |
| 1274 | if (!host->protect_card) { |
Rajendra Nayak | 2cecdf0 | 2012-02-23 17:02:20 +0530 | [diff] [blame] | 1275 | dev_info(host->dev, "%s: cover is open, " |
Adrian Hunter | b62f622 | 2009-09-22 16:45:01 -0700 | [diff] [blame] | 1276 | "card is now inaccessible\n", |
| 1277 | mmc_hostname(host->mmc)); |
| 1278 | host->protect_card = 1; |
| 1279 | } |
| 1280 | } |
| 1281 | } |
| 1282 | |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 1283 | /* |
NeilBrown | 7efab4f | 2011-12-30 12:35:13 +1100 | [diff] [blame] | 1284 | * irq handler to notify the core about card insertion/removal |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 1285 | */ |
NeilBrown | 7efab4f | 2011-12-30 12:35:13 +1100 | [diff] [blame] | 1286 | static irqreturn_t omap_hsmmc_detect(int irq, void *dev_id) |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 1287 | { |
NeilBrown | 7efab4f | 2011-12-30 12:35:13 +1100 | [diff] [blame] | 1288 | struct omap_hsmmc_host *host = dev_id; |
David Brownell | 249d0fa | 2009-02-04 14:42:03 -0800 | [diff] [blame] | 1289 | struct omap_mmc_slot_data *slot = &mmc_slot(host); |
Adrian Hunter | a6b2240 | 2009-09-22 16:44:45 -0700 | [diff] [blame] | 1290 | int carddetect; |
David Brownell | 249d0fa | 2009-02-04 14:42:03 -0800 | [diff] [blame] | 1291 | |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 1292 | sysfs_notify(&host->mmc->class_dev.kobj, NULL, "cover_switch"); |
Adrian Hunter | a6b2240 | 2009-09-22 16:44:45 -0700 | [diff] [blame] | 1293 | |
Denis Karpov | 191d1f1 | 2009-09-22 16:44:55 -0700 | [diff] [blame] | 1294 | if (slot->card_detect) |
Adrian Hunter | db0fefc | 2010-02-15 10:03:34 -0800 | [diff] [blame] | 1295 | carddetect = slot->card_detect(host->dev, host->slot_id); |
Adrian Hunter | b62f622 | 2009-09-22 16:45:01 -0700 | [diff] [blame] | 1296 | else { |
| 1297 | omap_hsmmc_protect_card(host); |
Adrian Hunter | a6b2240 | 2009-09-22 16:44:45 -0700 | [diff] [blame] | 1298 | carddetect = -ENOSYS; |
Adrian Hunter | b62f622 | 2009-09-22 16:45:01 -0700 | [diff] [blame] | 1299 | } |
Adrian Hunter | a6b2240 | 2009-09-22 16:44:45 -0700 | [diff] [blame] | 1300 | |
Madhusudhan Chikkature | cdeebad | 2010-04-06 14:34:49 -0700 | [diff] [blame] | 1301 | if (carddetect) |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 1302 | mmc_detect_change(host->mmc, (HZ * 200) / 1000); |
Madhusudhan Chikkature | cdeebad | 2010-04-06 14:34:49 -0700 | [diff] [blame] | 1303 | else |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 1304 | mmc_detect_change(host->mmc, (HZ * 50) / 1000); |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 1305 | return IRQ_HANDLED; |
| 1306 | } |
| 1307 | |
Russell King | c5c9892 | 2012-04-13 12:14:39 +0100 | [diff] [blame] | 1308 | static void omap_hsmmc_dma_callback(void *param) |
Juha Yrjola | 0ccd76d | 2008-11-14 15:22:00 +0200 | [diff] [blame] | 1309 | { |
Russell King | c5c9892 | 2012-04-13 12:14:39 +0100 | [diff] [blame] | 1310 | struct omap_hsmmc_host *host = param; |
| 1311 | struct dma_chan *chan; |
Adrian Hunter | 770d743 | 2011-05-06 12:14:11 +0300 | [diff] [blame] | 1312 | struct mmc_data *data; |
Russell King | c5c9892 | 2012-04-13 12:14:39 +0100 | [diff] [blame] | 1313 | int req_in_progress; |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 1314 | |
Russell King | c5c9892 | 2012-04-13 12:14:39 +0100 | [diff] [blame] | 1315 | spin_lock_irq(&host->irq_lock); |
Adrian Hunter | b417577 | 2010-05-26 14:42:06 -0700 | [diff] [blame] | 1316 | if (host->dma_ch < 0) { |
Russell King | c5c9892 | 2012-04-13 12:14:39 +0100 | [diff] [blame] | 1317 | spin_unlock_irq(&host->irq_lock); |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 1318 | return; |
Adrian Hunter | b417577 | 2010-05-26 14:42:06 -0700 | [diff] [blame] | 1319 | } |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 1320 | |
Adrian Hunter | 770d743 | 2011-05-06 12:14:11 +0300 | [diff] [blame] | 1321 | data = host->mrq->data; |
Russell King | c5c9892 | 2012-04-13 12:14:39 +0100 | [diff] [blame] | 1322 | chan = omap_hsmmc_get_dma_chan(host, data); |
Per Forlin | 9782aff | 2011-07-01 18:55:23 +0200 | [diff] [blame] | 1323 | if (!data->host_cookie) |
Russell King | c5c9892 | 2012-04-13 12:14:39 +0100 | [diff] [blame] | 1324 | dma_unmap_sg(chan->device->dev, |
| 1325 | data->sg, data->sg_len, |
Per Forlin | 9782aff | 2011-07-01 18:55:23 +0200 | [diff] [blame] | 1326 | omap_hsmmc_get_dma_dir(host, data)); |
Adrian Hunter | b417577 | 2010-05-26 14:42:06 -0700 | [diff] [blame] | 1327 | |
| 1328 | req_in_progress = host->req_in_progress; |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 1329 | host->dma_ch = -1; |
Russell King | c5c9892 | 2012-04-13 12:14:39 +0100 | [diff] [blame] | 1330 | spin_unlock_irq(&host->irq_lock); |
Adrian Hunter | b417577 | 2010-05-26 14:42:06 -0700 | [diff] [blame] | 1331 | |
| 1332 | /* If DMA has finished after TC, complete the request */ |
| 1333 | if (!req_in_progress) { |
| 1334 | struct mmc_request *mrq = host->mrq; |
| 1335 | |
| 1336 | host->mrq = NULL; |
| 1337 | mmc_request_done(host->mmc, mrq); |
| 1338 | } |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 1339 | } |
| 1340 | |
Per Forlin | 9782aff | 2011-07-01 18:55:23 +0200 | [diff] [blame] | 1341 | static int omap_hsmmc_pre_dma_transfer(struct omap_hsmmc_host *host, |
| 1342 | struct mmc_data *data, |
Russell King | c5c9892 | 2012-04-13 12:14:39 +0100 | [diff] [blame] | 1343 | struct omap_hsmmc_next *next, |
Russell King | 26b8852 | 2012-04-13 12:27:37 +0100 | [diff] [blame] | 1344 | struct dma_chan *chan) |
Per Forlin | 9782aff | 2011-07-01 18:55:23 +0200 | [diff] [blame] | 1345 | { |
| 1346 | int dma_len; |
| 1347 | |
| 1348 | if (!next && data->host_cookie && |
| 1349 | data->host_cookie != host->next_data.cookie) { |
Rajendra Nayak | 2cecdf0 | 2012-02-23 17:02:20 +0530 | [diff] [blame] | 1350 | dev_warn(host->dev, "[%s] invalid cookie: data->host_cookie %d" |
Per Forlin | 9782aff | 2011-07-01 18:55:23 +0200 | [diff] [blame] | 1351 | " host->next_data.cookie %d\n", |
| 1352 | __func__, data->host_cookie, host->next_data.cookie); |
| 1353 | data->host_cookie = 0; |
| 1354 | } |
| 1355 | |
| 1356 | /* Check if next job is already prepared */ |
Dan Carpenter | b38313d | 2014-01-30 15:15:18 +0300 | [diff] [blame] | 1357 | if (next || data->host_cookie != host->next_data.cookie) { |
Russell King | 26b8852 | 2012-04-13 12:27:37 +0100 | [diff] [blame] | 1358 | dma_len = dma_map_sg(chan->device->dev, data->sg, data->sg_len, |
Per Forlin | 9782aff | 2011-07-01 18:55:23 +0200 | [diff] [blame] | 1359 | omap_hsmmc_get_dma_dir(host, data)); |
| 1360 | |
| 1361 | } else { |
| 1362 | dma_len = host->next_data.dma_len; |
| 1363 | host->next_data.dma_len = 0; |
| 1364 | } |
| 1365 | |
| 1366 | |
| 1367 | if (dma_len == 0) |
| 1368 | return -EINVAL; |
| 1369 | |
| 1370 | if (next) { |
| 1371 | next->dma_len = dma_len; |
| 1372 | data->host_cookie = ++next->cookie < 0 ? 1 : next->cookie; |
| 1373 | } else |
| 1374 | host->dma_len = dma_len; |
| 1375 | |
| 1376 | return 0; |
| 1377 | } |
| 1378 | |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 1379 | /* |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 1380 | * Routine to configure and start DMA for the MMC card |
| 1381 | */ |
Balaji T K | 9d02533 | 2014-01-21 19:54:42 +0530 | [diff] [blame] | 1382 | static int omap_hsmmc_setup_dma_transfer(struct omap_hsmmc_host *host, |
Denis Karpov | 70a3341 | 2009-09-22 16:44:59 -0700 | [diff] [blame] | 1383 | struct mmc_request *req) |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 1384 | { |
Russell King | 26b8852 | 2012-04-13 12:27:37 +0100 | [diff] [blame] | 1385 | struct dma_slave_config cfg; |
| 1386 | struct dma_async_tx_descriptor *tx; |
| 1387 | int ret = 0, i; |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 1388 | struct mmc_data *data = req->data; |
Russell King | c5c9892 | 2012-04-13 12:14:39 +0100 | [diff] [blame] | 1389 | struct dma_chan *chan; |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 1390 | |
Juha Yrjola | 0ccd76d | 2008-11-14 15:22:00 +0200 | [diff] [blame] | 1391 | /* Sanity check: all the SG entries must be aligned by block size. */ |
Jarkko Lavinen | a3f406f | 2009-09-22 16:44:46 -0700 | [diff] [blame] | 1392 | for (i = 0; i < data->sg_len; i++) { |
Juha Yrjola | 0ccd76d | 2008-11-14 15:22:00 +0200 | [diff] [blame] | 1393 | struct scatterlist *sgl; |
| 1394 | |
| 1395 | sgl = data->sg + i; |
| 1396 | if (sgl->length % data->blksz) |
| 1397 | return -EINVAL; |
| 1398 | } |
| 1399 | if ((data->blksz % 4) != 0) |
| 1400 | /* REVISIT: The MMC buffer increments only when MSB is written. |
| 1401 | * Return error for blksz which is non multiple of four. |
| 1402 | */ |
| 1403 | return -EINVAL; |
| 1404 | |
Adrian Hunter | b417577 | 2010-05-26 14:42:06 -0700 | [diff] [blame] | 1405 | BUG_ON(host->dma_ch != -1); |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 1406 | |
Russell King | c5c9892 | 2012-04-13 12:14:39 +0100 | [diff] [blame] | 1407 | chan = omap_hsmmc_get_dma_chan(host, data); |
Russell King | c5c9892 | 2012-04-13 12:14:39 +0100 | [diff] [blame] | 1408 | |
Russell King | 26b8852 | 2012-04-13 12:27:37 +0100 | [diff] [blame] | 1409 | cfg.src_addr = host->mapbase + OMAP_HSMMC_DATA; |
| 1410 | cfg.dst_addr = host->mapbase + OMAP_HSMMC_DATA; |
| 1411 | cfg.src_addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES; |
| 1412 | cfg.dst_addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES; |
| 1413 | cfg.src_maxburst = data->blksz / 4; |
| 1414 | cfg.dst_maxburst = data->blksz / 4; |
Russell King | c5c9892 | 2012-04-13 12:14:39 +0100 | [diff] [blame] | 1415 | |
Russell King | 26b8852 | 2012-04-13 12:27:37 +0100 | [diff] [blame] | 1416 | ret = dmaengine_slave_config(chan, &cfg); |
Per Forlin | 9782aff | 2011-07-01 18:55:23 +0200 | [diff] [blame] | 1417 | if (ret) |
| 1418 | return ret; |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 1419 | |
Russell King | 26b8852 | 2012-04-13 12:27:37 +0100 | [diff] [blame] | 1420 | ret = omap_hsmmc_pre_dma_transfer(host, data, NULL, chan); |
| 1421 | if (ret) |
| 1422 | return ret; |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 1423 | |
Russell King | 26b8852 | 2012-04-13 12:27:37 +0100 | [diff] [blame] | 1424 | tx = dmaengine_prep_slave_sg(chan, data->sg, data->sg_len, |
| 1425 | data->flags & MMC_DATA_WRITE ? DMA_MEM_TO_DEV : DMA_DEV_TO_MEM, |
| 1426 | DMA_PREP_INTERRUPT | DMA_CTRL_ACK); |
| 1427 | if (!tx) { |
| 1428 | dev_err(mmc_dev(host->mmc), "prep_slave_sg() failed\n"); |
| 1429 | /* FIXME: cleanup */ |
| 1430 | return -1; |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 1431 | } |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 1432 | |
Russell King | 26b8852 | 2012-04-13 12:27:37 +0100 | [diff] [blame] | 1433 | tx->callback = omap_hsmmc_dma_callback; |
| 1434 | tx->callback_param = host; |
| 1435 | |
| 1436 | /* Does not fail */ |
| 1437 | dmaengine_submit(tx); |
| 1438 | |
| 1439 | host->dma_ch = 1; |
| 1440 | |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 1441 | return 0; |
| 1442 | } |
| 1443 | |
Denis Karpov | 70a3341 | 2009-09-22 16:44:59 -0700 | [diff] [blame] | 1444 | static void set_data_timeout(struct omap_hsmmc_host *host, |
Adrian Hunter | e2bf08d | 2009-09-22 16:45:03 -0700 | [diff] [blame] | 1445 | unsigned int timeout_ns, |
| 1446 | unsigned int timeout_clks) |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 1447 | { |
| 1448 | unsigned int timeout, cycle_ns; |
| 1449 | uint32_t reg, clkd, dto = 0; |
| 1450 | |
| 1451 | reg = OMAP_HSMMC_READ(host->base, SYSCTL); |
| 1452 | clkd = (reg & CLKD_MASK) >> CLKD_SHIFT; |
| 1453 | if (clkd == 0) |
| 1454 | clkd = 1; |
| 1455 | |
Balaji T K | 6e3076c | 2014-01-21 19:54:42 +0530 | [diff] [blame] | 1456 | cycle_ns = 1000000000 / (host->clk_rate / clkd); |
Adrian Hunter | e2bf08d | 2009-09-22 16:45:03 -0700 | [diff] [blame] | 1457 | timeout = timeout_ns / cycle_ns; |
| 1458 | timeout += timeout_clks; |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 1459 | if (timeout) { |
| 1460 | while ((timeout & 0x80000000) == 0) { |
| 1461 | dto += 1; |
| 1462 | timeout <<= 1; |
| 1463 | } |
| 1464 | dto = 31 - dto; |
| 1465 | timeout <<= 1; |
| 1466 | if (timeout && dto) |
| 1467 | dto += 1; |
| 1468 | if (dto >= 13) |
| 1469 | dto -= 13; |
| 1470 | else |
| 1471 | dto = 0; |
| 1472 | if (dto > 14) |
| 1473 | dto = 14; |
| 1474 | } |
| 1475 | |
| 1476 | reg &= ~DTO_MASK; |
| 1477 | reg |= dto << DTO_SHIFT; |
| 1478 | OMAP_HSMMC_WRITE(host->base, SYSCTL, reg); |
| 1479 | } |
| 1480 | |
Balaji T K | 9d02533 | 2014-01-21 19:54:42 +0530 | [diff] [blame] | 1481 | static void omap_hsmmc_start_dma_transfer(struct omap_hsmmc_host *host) |
| 1482 | { |
| 1483 | struct mmc_request *req = host->mrq; |
| 1484 | struct dma_chan *chan; |
| 1485 | |
| 1486 | if (!req->data) |
| 1487 | return; |
| 1488 | OMAP_HSMMC_WRITE(host->base, BLK, (req->data->blksz) |
| 1489 | | (req->data->blocks << 16)); |
| 1490 | set_data_timeout(host, req->data->timeout_ns, |
| 1491 | req->data->timeout_clks); |
| 1492 | chan = omap_hsmmc_get_dma_chan(host, req->data); |
| 1493 | dma_async_issue_pending(chan); |
| 1494 | } |
| 1495 | |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 1496 | /* |
| 1497 | * Configure block length for MMC/SD cards and initiate the transfer. |
| 1498 | */ |
| 1499 | static int |
Denis Karpov | 70a3341 | 2009-09-22 16:44:59 -0700 | [diff] [blame] | 1500 | omap_hsmmc_prepare_data(struct omap_hsmmc_host *host, struct mmc_request *req) |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 1501 | { |
| 1502 | int ret; |
| 1503 | host->data = req->data; |
| 1504 | |
| 1505 | if (req->data == NULL) { |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 1506 | OMAP_HSMMC_WRITE(host->base, BLK, 0); |
Adrian Hunter | e2bf08d | 2009-09-22 16:45:03 -0700 | [diff] [blame] | 1507 | /* |
| 1508 | * Set an arbitrary 100ms data timeout for commands with |
| 1509 | * busy signal. |
| 1510 | */ |
| 1511 | if (req->cmd->flags & MMC_RSP_BUSY) |
| 1512 | set_data_timeout(host, 100000000U, 0); |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 1513 | return 0; |
| 1514 | } |
| 1515 | |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 1516 | if (host->use_dma) { |
Balaji T K | 9d02533 | 2014-01-21 19:54:42 +0530 | [diff] [blame] | 1517 | ret = omap_hsmmc_setup_dma_transfer(host, req); |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 1518 | if (ret != 0) { |
Venkatraman S | b1e056a | 2012-11-19 22:00:00 +0530 | [diff] [blame] | 1519 | dev_err(mmc_dev(host->mmc), "MMC start dma failure\n"); |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 1520 | return ret; |
| 1521 | } |
| 1522 | } |
| 1523 | return 0; |
| 1524 | } |
| 1525 | |
Per Forlin | 9782aff | 2011-07-01 18:55:23 +0200 | [diff] [blame] | 1526 | static void omap_hsmmc_post_req(struct mmc_host *mmc, struct mmc_request *mrq, |
| 1527 | int err) |
| 1528 | { |
| 1529 | struct omap_hsmmc_host *host = mmc_priv(mmc); |
| 1530 | struct mmc_data *data = mrq->data; |
| 1531 | |
Russell King | 26b8852 | 2012-04-13 12:27:37 +0100 | [diff] [blame] | 1532 | if (host->use_dma && data->host_cookie) { |
Russell King | c5c9892 | 2012-04-13 12:14:39 +0100 | [diff] [blame] | 1533 | struct dma_chan *c = omap_hsmmc_get_dma_chan(host, data); |
Russell King | c5c9892 | 2012-04-13 12:14:39 +0100 | [diff] [blame] | 1534 | |
Russell King | 26b8852 | 2012-04-13 12:27:37 +0100 | [diff] [blame] | 1535 | dma_unmap_sg(c->device->dev, data->sg, data->sg_len, |
| 1536 | omap_hsmmc_get_dma_dir(host, data)); |
Per Forlin | 9782aff | 2011-07-01 18:55:23 +0200 | [diff] [blame] | 1537 | data->host_cookie = 0; |
| 1538 | } |
| 1539 | } |
| 1540 | |
| 1541 | static void omap_hsmmc_pre_req(struct mmc_host *mmc, struct mmc_request *mrq, |
| 1542 | bool is_first_req) |
| 1543 | { |
| 1544 | struct omap_hsmmc_host *host = mmc_priv(mmc); |
| 1545 | |
| 1546 | if (mrq->data->host_cookie) { |
| 1547 | mrq->data->host_cookie = 0; |
| 1548 | return ; |
| 1549 | } |
| 1550 | |
Russell King | c5c9892 | 2012-04-13 12:14:39 +0100 | [diff] [blame] | 1551 | if (host->use_dma) { |
| 1552 | struct dma_chan *c = omap_hsmmc_get_dma_chan(host, mrq->data); |
Russell King | c5c9892 | 2012-04-13 12:14:39 +0100 | [diff] [blame] | 1553 | |
Per Forlin | 9782aff | 2011-07-01 18:55:23 +0200 | [diff] [blame] | 1554 | if (omap_hsmmc_pre_dma_transfer(host, mrq->data, |
Russell King | 26b8852 | 2012-04-13 12:27:37 +0100 | [diff] [blame] | 1555 | &host->next_data, c)) |
Per Forlin | 9782aff | 2011-07-01 18:55:23 +0200 | [diff] [blame] | 1556 | mrq->data->host_cookie = 0; |
Russell King | c5c9892 | 2012-04-13 12:14:39 +0100 | [diff] [blame] | 1557 | } |
Per Forlin | 9782aff | 2011-07-01 18:55:23 +0200 | [diff] [blame] | 1558 | } |
| 1559 | |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 1560 | /* |
| 1561 | * Request function. for read/write operation |
| 1562 | */ |
Denis Karpov | 70a3341 | 2009-09-22 16:44:59 -0700 | [diff] [blame] | 1563 | static void omap_hsmmc_request(struct mmc_host *mmc, struct mmc_request *req) |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 1564 | { |
Denis Karpov | 70a3341 | 2009-09-22 16:44:59 -0700 | [diff] [blame] | 1565 | struct omap_hsmmc_host *host = mmc_priv(mmc); |
Jarkko Lavinen | a3f406f | 2009-09-22 16:44:46 -0700 | [diff] [blame] | 1566 | int err; |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 1567 | |
Adrian Hunter | b417577 | 2010-05-26 14:42:06 -0700 | [diff] [blame] | 1568 | BUG_ON(host->req_in_progress); |
| 1569 | BUG_ON(host->dma_ch != -1); |
| 1570 | if (host->protect_card) { |
| 1571 | if (host->reqs_blocked < 3) { |
| 1572 | /* |
| 1573 | * Ensure the controller is left in a consistent |
| 1574 | * state by resetting the command and data state |
| 1575 | * machines. |
| 1576 | */ |
| 1577 | omap_hsmmc_reset_controller_fsm(host, SRD); |
| 1578 | omap_hsmmc_reset_controller_fsm(host, SRC); |
| 1579 | host->reqs_blocked += 1; |
| 1580 | } |
| 1581 | req->cmd->error = -EBADF; |
| 1582 | if (req->data) |
| 1583 | req->data->error = -EBADF; |
| 1584 | req->cmd->retries = 0; |
| 1585 | mmc_request_done(mmc, req); |
| 1586 | return; |
| 1587 | } else if (host->reqs_blocked) |
| 1588 | host->reqs_blocked = 0; |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 1589 | WARN_ON(host->mrq != NULL); |
| 1590 | host->mrq = req; |
Balaji T K | 6e3076c | 2014-01-21 19:54:42 +0530 | [diff] [blame] | 1591 | host->clk_rate = clk_get_rate(host->fclk); |
Denis Karpov | 70a3341 | 2009-09-22 16:44:59 -0700 | [diff] [blame] | 1592 | err = omap_hsmmc_prepare_data(host, req); |
Jarkko Lavinen | a3f406f | 2009-09-22 16:44:46 -0700 | [diff] [blame] | 1593 | if (err) { |
| 1594 | req->cmd->error = err; |
| 1595 | if (req->data) |
| 1596 | req->data->error = err; |
| 1597 | host->mrq = NULL; |
| 1598 | mmc_request_done(mmc, req); |
| 1599 | return; |
| 1600 | } |
Balaji T K | a2e7715 | 2014-01-21 19:54:42 +0530 | [diff] [blame] | 1601 | if (req->sbc && !(host->flags & AUTO_CMD23)) { |
Balaji T K | bf129e1 | 2014-01-21 19:54:42 +0530 | [diff] [blame] | 1602 | omap_hsmmc_start_command(host, req->sbc, NULL); |
| 1603 | return; |
| 1604 | } |
Jarkko Lavinen | a3f406f | 2009-09-22 16:44:46 -0700 | [diff] [blame] | 1605 | |
Balaji T K | 9d02533 | 2014-01-21 19:54:42 +0530 | [diff] [blame] | 1606 | omap_hsmmc_start_dma_transfer(host); |
Denis Karpov | 70a3341 | 2009-09-22 16:44:59 -0700 | [diff] [blame] | 1607 | omap_hsmmc_start_command(host, req->cmd, req->data); |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 1608 | } |
| 1609 | |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 1610 | /* Routine to configure clock values. Exposed API to core */ |
Denis Karpov | 70a3341 | 2009-09-22 16:44:59 -0700 | [diff] [blame] | 1611 | static void omap_hsmmc_set_ios(struct mmc_host *mmc, struct mmc_ios *ios) |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 1612 | { |
Denis Karpov | 70a3341 | 2009-09-22 16:44:59 -0700 | [diff] [blame] | 1613 | struct omap_hsmmc_host *host = mmc_priv(mmc); |
Adrian Hunter | a362146 | 2009-09-22 16:44:42 -0700 | [diff] [blame] | 1614 | int do_send_init_stream = 0; |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 1615 | |
Balaji T K | fa4aa2d | 2011-07-01 22:09:35 +0530 | [diff] [blame] | 1616 | pm_runtime_get_sync(host->dev); |
Adrian Hunter | 5e2ea61 | 2009-09-22 16:44:39 -0700 | [diff] [blame] | 1617 | |
Adrian Hunter | a362146 | 2009-09-22 16:44:42 -0700 | [diff] [blame] | 1618 | if (ios->power_mode != host->power_mode) { |
| 1619 | switch (ios->power_mode) { |
| 1620 | case MMC_POWER_OFF: |
| 1621 | mmc_slot(host).set_power(host->dev, host->slot_id, |
| 1622 | 0, 0); |
| 1623 | break; |
| 1624 | case MMC_POWER_UP: |
| 1625 | mmc_slot(host).set_power(host->dev, host->slot_id, |
| 1626 | 1, ios->vdd); |
| 1627 | break; |
| 1628 | case MMC_POWER_ON: |
| 1629 | do_send_init_stream = 1; |
| 1630 | break; |
| 1631 | } |
| 1632 | host->power_mode = ios->power_mode; |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 1633 | } |
| 1634 | |
Denis Karpov | dd498ef | 2009-09-22 16:44:49 -0700 | [diff] [blame] | 1635 | /* FIXME: set registers based only on changes to ios */ |
| 1636 | |
Andy Shevchenko | 3796fb8a | 2011-07-13 11:31:15 -0400 | [diff] [blame] | 1637 | omap_hsmmc_set_bus_width(host); |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 1638 | |
Kishore Kadiyala | 4621d5f | 2011-02-28 20:48:04 +0530 | [diff] [blame] | 1639 | if (host->pdata->controller_flags & OMAP_HSMMC_SUPPORTS_DUAL_VOLT) { |
David Brownell | eb25082 | 2009-02-17 14:49:01 -0800 | [diff] [blame] | 1640 | /* Only MMC1 can interface at 3V without some flavor |
| 1641 | * of external transceiver; but they all handle 1.8V. |
| 1642 | */ |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 1643 | if ((OMAP_HSMMC_READ(host->base, HCTL) & SDVSDET) && |
Balaji T K | 2cf171c | 2014-02-19 20:26:40 +0530 | [diff] [blame] | 1644 | (ios->vdd == DUAL_VOLT_OCR_BIT)) { |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 1645 | /* |
| 1646 | * The mmc_select_voltage fn of the core does |
| 1647 | * not seem to set the power_mode to |
| 1648 | * MMC_POWER_UP upon recalculating the voltage. |
| 1649 | * vdd 1.8v. |
| 1650 | */ |
Denis Karpov | 70a3341 | 2009-09-22 16:44:59 -0700 | [diff] [blame] | 1651 | if (omap_hsmmc_switch_opcond(host, ios->vdd) != 0) |
| 1652 | dev_dbg(mmc_dev(host->mmc), |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 1653 | "Switch operation failed\n"); |
| 1654 | } |
| 1655 | } |
| 1656 | |
Andy Shevchenko | 5934df2 | 2011-05-06 12:14:06 +0300 | [diff] [blame] | 1657 | omap_hsmmc_set_clock(host); |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 1658 | |
Adrian Hunter | a362146 | 2009-09-22 16:44:42 -0700 | [diff] [blame] | 1659 | if (do_send_init_stream) |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 1660 | send_init_stream(host); |
| 1661 | |
Andy Shevchenko | 3796fb8a | 2011-07-13 11:31:15 -0400 | [diff] [blame] | 1662 | omap_hsmmc_set_bus_mode(host); |
Adrian Hunter | 5e2ea61 | 2009-09-22 16:44:39 -0700 | [diff] [blame] | 1663 | |
Balaji T K | fa4aa2d | 2011-07-01 22:09:35 +0530 | [diff] [blame] | 1664 | pm_runtime_put_autosuspend(host->dev); |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 1665 | } |
| 1666 | |
| 1667 | static int omap_hsmmc_get_cd(struct mmc_host *mmc) |
| 1668 | { |
Denis Karpov | 70a3341 | 2009-09-22 16:44:59 -0700 | [diff] [blame] | 1669 | struct omap_hsmmc_host *host = mmc_priv(mmc); |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 1670 | |
Denis Karpov | 191d1f1 | 2009-09-22 16:44:55 -0700 | [diff] [blame] | 1671 | if (!mmc_slot(host).card_detect) |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 1672 | return -ENOSYS; |
Adrian Hunter | db0fefc | 2010-02-15 10:03:34 -0800 | [diff] [blame] | 1673 | return mmc_slot(host).card_detect(host->dev, host->slot_id); |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 1674 | } |
| 1675 | |
| 1676 | static int omap_hsmmc_get_ro(struct mmc_host *mmc) |
| 1677 | { |
Denis Karpov | 70a3341 | 2009-09-22 16:44:59 -0700 | [diff] [blame] | 1678 | struct omap_hsmmc_host *host = mmc_priv(mmc); |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 1679 | |
Denis Karpov | 191d1f1 | 2009-09-22 16:44:55 -0700 | [diff] [blame] | 1680 | if (!mmc_slot(host).get_ro) |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 1681 | return -ENOSYS; |
Denis Karpov | 191d1f1 | 2009-09-22 16:44:55 -0700 | [diff] [blame] | 1682 | return mmc_slot(host).get_ro(host->dev, 0); |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 1683 | } |
| 1684 | |
Grazvydas Ignotas | 4816858 | 2010-08-10 18:01:52 -0700 | [diff] [blame] | 1685 | static void omap_hsmmc_init_card(struct mmc_host *mmc, struct mmc_card *card) |
| 1686 | { |
| 1687 | struct omap_hsmmc_host *host = mmc_priv(mmc); |
| 1688 | |
| 1689 | if (mmc_slot(host).init_card) |
| 1690 | mmc_slot(host).init_card(card); |
| 1691 | } |
| 1692 | |
Andreas Fenkart | 2cd3a2a | 2014-05-29 10:28:00 +0200 | [diff] [blame] | 1693 | static void omap_hsmmc_enable_sdio_irq(struct mmc_host *mmc, int enable) |
| 1694 | { |
| 1695 | struct omap_hsmmc_host *host = mmc_priv(mmc); |
Balaji T K | 5a52b08 | 2014-05-29 10:28:02 +0200 | [diff] [blame] | 1696 | u32 irq_mask, con; |
Andreas Fenkart | 2cd3a2a | 2014-05-29 10:28:00 +0200 | [diff] [blame] | 1697 | unsigned long flags; |
| 1698 | |
| 1699 | spin_lock_irqsave(&host->irq_lock, flags); |
| 1700 | |
Balaji T K | 5a52b08 | 2014-05-29 10:28:02 +0200 | [diff] [blame] | 1701 | con = OMAP_HSMMC_READ(host->base, CON); |
Andreas Fenkart | 2cd3a2a | 2014-05-29 10:28:00 +0200 | [diff] [blame] | 1702 | irq_mask = OMAP_HSMMC_READ(host->base, ISE); |
| 1703 | if (enable) { |
| 1704 | host->flags |= HSMMC_SDIO_IRQ_ENABLED; |
| 1705 | irq_mask |= CIRQ_EN; |
Balaji T K | 5a52b08 | 2014-05-29 10:28:02 +0200 | [diff] [blame] | 1706 | con |= CTPL | CLKEXTFREE; |
Andreas Fenkart | 2cd3a2a | 2014-05-29 10:28:00 +0200 | [diff] [blame] | 1707 | } else { |
| 1708 | host->flags &= ~HSMMC_SDIO_IRQ_ENABLED; |
| 1709 | irq_mask &= ~CIRQ_EN; |
Balaji T K | 5a52b08 | 2014-05-29 10:28:02 +0200 | [diff] [blame] | 1710 | con &= ~(CTPL | CLKEXTFREE); |
Andreas Fenkart | 2cd3a2a | 2014-05-29 10:28:00 +0200 | [diff] [blame] | 1711 | } |
Balaji T K | 5a52b08 | 2014-05-29 10:28:02 +0200 | [diff] [blame] | 1712 | OMAP_HSMMC_WRITE(host->base, CON, con); |
Andreas Fenkart | 2cd3a2a | 2014-05-29 10:28:00 +0200 | [diff] [blame] | 1713 | OMAP_HSMMC_WRITE(host->base, IE, irq_mask); |
| 1714 | |
| 1715 | /* |
| 1716 | * if enable, piggy back detection on current request |
| 1717 | * but always disable immediately |
| 1718 | */ |
| 1719 | if (!host->req_in_progress || !enable) |
| 1720 | OMAP_HSMMC_WRITE(host->base, ISE, irq_mask); |
| 1721 | |
| 1722 | /* flush posted write */ |
| 1723 | OMAP_HSMMC_READ(host->base, IE); |
| 1724 | |
| 1725 | spin_unlock_irqrestore(&host->irq_lock, flags); |
| 1726 | } |
| 1727 | |
| 1728 | static int omap_hsmmc_configure_wake_irq(struct omap_hsmmc_host *host) |
| 1729 | { |
| 1730 | struct mmc_host *mmc = host->mmc; |
| 1731 | int ret; |
| 1732 | |
| 1733 | /* |
| 1734 | * For omaps with wake-up path, wakeirq will be irq from pinctrl and |
| 1735 | * for other omaps, wakeirq will be from GPIO (dat line remuxed to |
| 1736 | * gpio). wakeirq is needed to detect sdio irq in runtime suspend state |
| 1737 | * with functional clock disabled. |
| 1738 | */ |
| 1739 | if (!host->dev->of_node || !host->wake_irq) |
| 1740 | return -ENODEV; |
| 1741 | |
| 1742 | /* Prevent auto-enabling of IRQ */ |
| 1743 | irq_set_status_flags(host->wake_irq, IRQ_NOAUTOEN); |
| 1744 | ret = devm_request_irq(host->dev, host->wake_irq, omap_hsmmc_wake_irq, |
| 1745 | IRQF_TRIGGER_LOW | IRQF_ONESHOT, |
| 1746 | mmc_hostname(mmc), host); |
| 1747 | if (ret) { |
| 1748 | dev_err(mmc_dev(host->mmc), "Unable to request wake IRQ\n"); |
| 1749 | goto err; |
| 1750 | } |
| 1751 | |
| 1752 | /* |
| 1753 | * Some omaps don't have wake-up path from deeper idle states |
| 1754 | * and need to remux SDIO DAT1 to GPIO for wake-up from idle. |
| 1755 | */ |
| 1756 | if (host->pdata->controller_flags & OMAP_HSMMC_SWAKEUP_MISSING) { |
| 1757 | ret = -ENODEV; |
| 1758 | devm_free_irq(host->dev, host->wake_irq, host); |
| 1759 | goto err; |
| 1760 | } |
| 1761 | |
Balaji T K | 5a52b08 | 2014-05-29 10:28:02 +0200 | [diff] [blame] | 1762 | OMAP_HSMMC_WRITE(host->base, HCTL, |
| 1763 | OMAP_HSMMC_READ(host->base, HCTL) | IWE); |
Andreas Fenkart | 2cd3a2a | 2014-05-29 10:28:00 +0200 | [diff] [blame] | 1764 | return 0; |
| 1765 | |
| 1766 | err: |
| 1767 | dev_warn(host->dev, "no SDIO IRQ support, falling back to polling\n"); |
| 1768 | host->wake_irq = 0; |
| 1769 | return ret; |
| 1770 | } |
| 1771 | |
Denis Karpov | 70a3341 | 2009-09-22 16:44:59 -0700 | [diff] [blame] | 1772 | static void omap_hsmmc_conf_bus_power(struct omap_hsmmc_host *host) |
Kim Kyuwon | 1b331e6 | 2009-02-20 13:10:08 +0100 | [diff] [blame] | 1773 | { |
| 1774 | u32 hctl, capa, value; |
| 1775 | |
| 1776 | /* Only MMC1 supports 3.0V */ |
Kishore Kadiyala | 4621d5f | 2011-02-28 20:48:04 +0530 | [diff] [blame] | 1777 | if (host->pdata->controller_flags & OMAP_HSMMC_SUPPORTS_DUAL_VOLT) { |
Kim Kyuwon | 1b331e6 | 2009-02-20 13:10:08 +0100 | [diff] [blame] | 1778 | hctl = SDVS30; |
| 1779 | capa = VS30 | VS18; |
| 1780 | } else { |
| 1781 | hctl = SDVS18; |
| 1782 | capa = VS18; |
| 1783 | } |
| 1784 | |
| 1785 | value = OMAP_HSMMC_READ(host->base, HCTL) & ~SDVS_MASK; |
| 1786 | OMAP_HSMMC_WRITE(host->base, HCTL, value | hctl); |
| 1787 | |
| 1788 | value = OMAP_HSMMC_READ(host->base, CAPA); |
| 1789 | OMAP_HSMMC_WRITE(host->base, CAPA, value | capa); |
| 1790 | |
Kim Kyuwon | 1b331e6 | 2009-02-20 13:10:08 +0100 | [diff] [blame] | 1791 | /* Set SD bus power bit */ |
Adrian Hunter | e13bb30 | 2009-03-12 17:08:26 +0200 | [diff] [blame] | 1792 | set_sd_bus_power(host); |
Kim Kyuwon | 1b331e6 | 2009-02-20 13:10:08 +0100 | [diff] [blame] | 1793 | } |
| 1794 | |
Denis Karpov | 70a3341 | 2009-09-22 16:44:59 -0700 | [diff] [blame] | 1795 | static int omap_hsmmc_enable_fclk(struct mmc_host *mmc) |
Denis Karpov | dd498ef | 2009-09-22 16:44:49 -0700 | [diff] [blame] | 1796 | { |
Denis Karpov | 70a3341 | 2009-09-22 16:44:59 -0700 | [diff] [blame] | 1797 | struct omap_hsmmc_host *host = mmc_priv(mmc); |
Denis Karpov | dd498ef | 2009-09-22 16:44:49 -0700 | [diff] [blame] | 1798 | |
Balaji T K | fa4aa2d | 2011-07-01 22:09:35 +0530 | [diff] [blame] | 1799 | pm_runtime_get_sync(host->dev); |
| 1800 | |
Denis Karpov | dd498ef | 2009-09-22 16:44:49 -0700 | [diff] [blame] | 1801 | return 0; |
| 1802 | } |
| 1803 | |
Adrian Hunter | 907d2e7 | 2012-02-29 09:17:21 +0200 | [diff] [blame] | 1804 | static int omap_hsmmc_disable_fclk(struct mmc_host *mmc) |
Denis Karpov | dd498ef | 2009-09-22 16:44:49 -0700 | [diff] [blame] | 1805 | { |
Denis Karpov | 70a3341 | 2009-09-22 16:44:59 -0700 | [diff] [blame] | 1806 | struct omap_hsmmc_host *host = mmc_priv(mmc); |
Denis Karpov | dd498ef | 2009-09-22 16:44:49 -0700 | [diff] [blame] | 1807 | |
Balaji T K | fa4aa2d | 2011-07-01 22:09:35 +0530 | [diff] [blame] | 1808 | pm_runtime_mark_last_busy(host->dev); |
| 1809 | pm_runtime_put_autosuspend(host->dev); |
| 1810 | |
Denis Karpov | dd498ef | 2009-09-22 16:44:49 -0700 | [diff] [blame] | 1811 | return 0; |
| 1812 | } |
| 1813 | |
Denis Karpov | 70a3341 | 2009-09-22 16:44:59 -0700 | [diff] [blame] | 1814 | static const struct mmc_host_ops omap_hsmmc_ops = { |
| 1815 | .enable = omap_hsmmc_enable_fclk, |
| 1816 | .disable = omap_hsmmc_disable_fclk, |
Per Forlin | 9782aff | 2011-07-01 18:55:23 +0200 | [diff] [blame] | 1817 | .post_req = omap_hsmmc_post_req, |
| 1818 | .pre_req = omap_hsmmc_pre_req, |
Denis Karpov | 70a3341 | 2009-09-22 16:44:59 -0700 | [diff] [blame] | 1819 | .request = omap_hsmmc_request, |
| 1820 | .set_ios = omap_hsmmc_set_ios, |
Denis Karpov | dd498ef | 2009-09-22 16:44:49 -0700 | [diff] [blame] | 1821 | .get_cd = omap_hsmmc_get_cd, |
| 1822 | .get_ro = omap_hsmmc_get_ro, |
Grazvydas Ignotas | 4816858 | 2010-08-10 18:01:52 -0700 | [diff] [blame] | 1823 | .init_card = omap_hsmmc_init_card, |
Andreas Fenkart | 2cd3a2a | 2014-05-29 10:28:00 +0200 | [diff] [blame] | 1824 | .enable_sdio_irq = omap_hsmmc_enable_sdio_irq, |
Denis Karpov | dd498ef | 2009-09-22 16:44:49 -0700 | [diff] [blame] | 1825 | }; |
| 1826 | |
Denis Karpov | d900f71 | 2009-09-22 16:44:38 -0700 | [diff] [blame] | 1827 | #ifdef CONFIG_DEBUG_FS |
| 1828 | |
Denis Karpov | 70a3341 | 2009-09-22 16:44:59 -0700 | [diff] [blame] | 1829 | static int omap_hsmmc_regs_show(struct seq_file *s, void *data) |
Denis Karpov | d900f71 | 2009-09-22 16:44:38 -0700 | [diff] [blame] | 1830 | { |
| 1831 | struct mmc_host *mmc = s->private; |
Denis Karpov | 70a3341 | 2009-09-22 16:44:59 -0700 | [diff] [blame] | 1832 | struct omap_hsmmc_host *host = mmc_priv(mmc); |
Denis Karpov | 11dd62a | 2009-09-22 16:44:43 -0700 | [diff] [blame] | 1833 | |
Andreas Fenkart | bb0635f | 2014-05-29 10:28:01 +0200 | [diff] [blame] | 1834 | seq_printf(s, "mmc%d:\n", mmc->index); |
| 1835 | seq_printf(s, "sdio irq mode\t%s\n", |
| 1836 | (mmc->caps & MMC_CAP_SDIO_IRQ) ? "interrupt" : "polling"); |
| 1837 | |
| 1838 | if (mmc->caps & MMC_CAP_SDIO_IRQ) { |
| 1839 | seq_printf(s, "sdio irq \t%s\n", |
| 1840 | (host->flags & HSMMC_SDIO_IRQ_ENABLED) ? "enabled" |
| 1841 | : "disabled"); |
| 1842 | } |
| 1843 | seq_printf(s, "ctx_loss:\t%d\n", host->context_loss); |
Adrian Hunter | 5e2ea61 | 2009-09-22 16:44:39 -0700 | [diff] [blame] | 1844 | |
Balaji T K | fa4aa2d | 2011-07-01 22:09:35 +0530 | [diff] [blame] | 1845 | pm_runtime_get_sync(host->dev); |
Andreas Fenkart | bb0635f | 2014-05-29 10:28:01 +0200 | [diff] [blame] | 1846 | seq_puts(s, "\nregs:\n"); |
Denis Karpov | d900f71 | 2009-09-22 16:44:38 -0700 | [diff] [blame] | 1847 | seq_printf(s, "CON:\t\t0x%08x\n", |
| 1848 | OMAP_HSMMC_READ(host->base, CON)); |
Andreas Fenkart | bb0635f | 2014-05-29 10:28:01 +0200 | [diff] [blame] | 1849 | seq_printf(s, "PSTATE:\t\t0x%08x\n", |
| 1850 | OMAP_HSMMC_READ(host->base, PSTATE)); |
Denis Karpov | d900f71 | 2009-09-22 16:44:38 -0700 | [diff] [blame] | 1851 | seq_printf(s, "HCTL:\t\t0x%08x\n", |
| 1852 | OMAP_HSMMC_READ(host->base, HCTL)); |
| 1853 | seq_printf(s, "SYSCTL:\t\t0x%08x\n", |
| 1854 | OMAP_HSMMC_READ(host->base, SYSCTL)); |
| 1855 | seq_printf(s, "IE:\t\t0x%08x\n", |
| 1856 | OMAP_HSMMC_READ(host->base, IE)); |
| 1857 | seq_printf(s, "ISE:\t\t0x%08x\n", |
| 1858 | OMAP_HSMMC_READ(host->base, ISE)); |
| 1859 | seq_printf(s, "CAPA:\t\t0x%08x\n", |
| 1860 | OMAP_HSMMC_READ(host->base, CAPA)); |
Adrian Hunter | 5e2ea61 | 2009-09-22 16:44:39 -0700 | [diff] [blame] | 1861 | |
Balaji T K | fa4aa2d | 2011-07-01 22:09:35 +0530 | [diff] [blame] | 1862 | pm_runtime_mark_last_busy(host->dev); |
| 1863 | pm_runtime_put_autosuspend(host->dev); |
Denis Karpov | dd498ef | 2009-09-22 16:44:49 -0700 | [diff] [blame] | 1864 | |
Denis Karpov | d900f71 | 2009-09-22 16:44:38 -0700 | [diff] [blame] | 1865 | return 0; |
| 1866 | } |
| 1867 | |
Denis Karpov | 70a3341 | 2009-09-22 16:44:59 -0700 | [diff] [blame] | 1868 | static int omap_hsmmc_regs_open(struct inode *inode, struct file *file) |
Denis Karpov | d900f71 | 2009-09-22 16:44:38 -0700 | [diff] [blame] | 1869 | { |
Denis Karpov | 70a3341 | 2009-09-22 16:44:59 -0700 | [diff] [blame] | 1870 | return single_open(file, omap_hsmmc_regs_show, inode->i_private); |
Denis Karpov | d900f71 | 2009-09-22 16:44:38 -0700 | [diff] [blame] | 1871 | } |
| 1872 | |
| 1873 | static const struct file_operations mmc_regs_fops = { |
Denis Karpov | 70a3341 | 2009-09-22 16:44:59 -0700 | [diff] [blame] | 1874 | .open = omap_hsmmc_regs_open, |
Denis Karpov | d900f71 | 2009-09-22 16:44:38 -0700 | [diff] [blame] | 1875 | .read = seq_read, |
| 1876 | .llseek = seq_lseek, |
| 1877 | .release = single_release, |
| 1878 | }; |
| 1879 | |
Denis Karpov | 70a3341 | 2009-09-22 16:44:59 -0700 | [diff] [blame] | 1880 | static void omap_hsmmc_debugfs(struct mmc_host *mmc) |
Denis Karpov | d900f71 | 2009-09-22 16:44:38 -0700 | [diff] [blame] | 1881 | { |
| 1882 | if (mmc->debugfs_root) |
| 1883 | debugfs_create_file("regs", S_IRUSR, mmc->debugfs_root, |
| 1884 | mmc, &mmc_regs_fops); |
| 1885 | } |
| 1886 | |
| 1887 | #else |
| 1888 | |
Denis Karpov | 70a3341 | 2009-09-22 16:44:59 -0700 | [diff] [blame] | 1889 | static void omap_hsmmc_debugfs(struct mmc_host *mmc) |
Denis Karpov | d900f71 | 2009-09-22 16:44:38 -0700 | [diff] [blame] | 1890 | { |
| 1891 | } |
| 1892 | |
| 1893 | #endif |
| 1894 | |
Rajendra Nayak | 46856a6 | 2012-03-12 20:32:37 +0530 | [diff] [blame] | 1895 | #ifdef CONFIG_OF |
Nishanth Menon | 59445b1 | 2014-02-13 23:45:48 -0600 | [diff] [blame] | 1896 | static const struct omap_mmc_of_data omap3_pre_es3_mmc_of_data = { |
| 1897 | /* See 35xx errata 2.1.1.128 in SPRZ278F */ |
| 1898 | .controller_flags = OMAP_HSMMC_BROKEN_MULTIBLOCK_READ, |
| 1899 | }; |
| 1900 | |
| 1901 | static const struct omap_mmc_of_data omap4_mmc_of_data = { |
| 1902 | .reg_offset = 0x100, |
| 1903 | }; |
Andreas Fenkart | 2cd3a2a | 2014-05-29 10:28:00 +0200 | [diff] [blame] | 1904 | static const struct omap_mmc_of_data am33xx_mmc_of_data = { |
| 1905 | .reg_offset = 0x100, |
| 1906 | .controller_flags = OMAP_HSMMC_SWAKEUP_MISSING, |
| 1907 | }; |
Rajendra Nayak | 46856a6 | 2012-03-12 20:32:37 +0530 | [diff] [blame] | 1908 | |
| 1909 | static const struct of_device_id omap_mmc_of_match[] = { |
| 1910 | { |
| 1911 | .compatible = "ti,omap2-hsmmc", |
| 1912 | }, |
| 1913 | { |
Nishanth Menon | 59445b1 | 2014-02-13 23:45:48 -0600 | [diff] [blame] | 1914 | .compatible = "ti,omap3-pre-es3-hsmmc", |
| 1915 | .data = &omap3_pre_es3_mmc_of_data, |
| 1916 | }, |
| 1917 | { |
Rajendra Nayak | 46856a6 | 2012-03-12 20:32:37 +0530 | [diff] [blame] | 1918 | .compatible = "ti,omap3-hsmmc", |
| 1919 | }, |
| 1920 | { |
| 1921 | .compatible = "ti,omap4-hsmmc", |
Nishanth Menon | 59445b1 | 2014-02-13 23:45:48 -0600 | [diff] [blame] | 1922 | .data = &omap4_mmc_of_data, |
Rajendra Nayak | 46856a6 | 2012-03-12 20:32:37 +0530 | [diff] [blame] | 1923 | }, |
Andreas Fenkart | 2cd3a2a | 2014-05-29 10:28:00 +0200 | [diff] [blame] | 1924 | { |
| 1925 | .compatible = "ti,am33xx-hsmmc", |
| 1926 | .data = &am33xx_mmc_of_data, |
| 1927 | }, |
Rajendra Nayak | 46856a6 | 2012-03-12 20:32:37 +0530 | [diff] [blame] | 1928 | {}, |
Chris Ball | b6d085f | 2012-04-10 09:57:36 -0400 | [diff] [blame] | 1929 | }; |
Rajendra Nayak | 46856a6 | 2012-03-12 20:32:37 +0530 | [diff] [blame] | 1930 | MODULE_DEVICE_TABLE(of, omap_mmc_of_match); |
| 1931 | |
| 1932 | static struct omap_mmc_platform_data *of_get_hsmmc_pdata(struct device *dev) |
| 1933 | { |
| 1934 | struct omap_mmc_platform_data *pdata; |
| 1935 | struct device_node *np = dev->of_node; |
Daniel Mack | d8714e8 | 2012-10-15 21:35:06 +0530 | [diff] [blame] | 1936 | u32 bus_width, max_freq; |
Jan Luebbe | dc642c2 | 2013-01-30 10:07:17 +0100 | [diff] [blame] | 1937 | int cd_gpio, wp_gpio; |
| 1938 | |
| 1939 | cd_gpio = of_get_named_gpio(np, "cd-gpios", 0); |
| 1940 | wp_gpio = of_get_named_gpio(np, "wp-gpios", 0); |
| 1941 | if (cd_gpio == -EPROBE_DEFER || wp_gpio == -EPROBE_DEFER) |
| 1942 | return ERR_PTR(-EPROBE_DEFER); |
Rajendra Nayak | 46856a6 | 2012-03-12 20:32:37 +0530 | [diff] [blame] | 1943 | |
| 1944 | pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL); |
| 1945 | if (!pdata) |
Balaji T K | 19df45b | 2014-02-28 19:08:18 +0530 | [diff] [blame] | 1946 | return ERR_PTR(-ENOMEM); /* out of memory */ |
Rajendra Nayak | 46856a6 | 2012-03-12 20:32:37 +0530 | [diff] [blame] | 1947 | |
| 1948 | if (of_find_property(np, "ti,dual-volt", NULL)) |
| 1949 | pdata->controller_flags |= OMAP_HSMMC_SUPPORTS_DUAL_VOLT; |
| 1950 | |
| 1951 | /* This driver only supports 1 slot */ |
| 1952 | pdata->nr_slots = 1; |
Jan Luebbe | dc642c2 | 2013-01-30 10:07:17 +0100 | [diff] [blame] | 1953 | pdata->slots[0].switch_pin = cd_gpio; |
| 1954 | pdata->slots[0].gpio_wp = wp_gpio; |
Rajendra Nayak | 46856a6 | 2012-03-12 20:32:37 +0530 | [diff] [blame] | 1955 | |
| 1956 | if (of_find_property(np, "ti,non-removable", NULL)) { |
| 1957 | pdata->slots[0].nonremovable = true; |
| 1958 | pdata->slots[0].no_regulator_off_init = true; |
| 1959 | } |
Arnd Bergmann | 7f21779 | 2012-05-13 00:14:24 -0400 | [diff] [blame] | 1960 | of_property_read_u32(np, "bus-width", &bus_width); |
Rajendra Nayak | 46856a6 | 2012-03-12 20:32:37 +0530 | [diff] [blame] | 1961 | if (bus_width == 4) |
| 1962 | pdata->slots[0].caps |= MMC_CAP_4_BIT_DATA; |
| 1963 | else if (bus_width == 8) |
| 1964 | pdata->slots[0].caps |= MMC_CAP_8_BIT_DATA; |
| 1965 | |
| 1966 | if (of_find_property(np, "ti,needs-special-reset", NULL)) |
| 1967 | pdata->slots[0].features |= HSMMC_HAS_UPDATED_RESET; |
| 1968 | |
Daniel Mack | d8714e8 | 2012-10-15 21:35:06 +0530 | [diff] [blame] | 1969 | if (!of_property_read_u32(np, "max-frequency", &max_freq)) |
| 1970 | pdata->max_freq = max_freq; |
| 1971 | |
Hebbar, Gururaja | cd58709 | 2012-11-19 21:59:58 +0530 | [diff] [blame] | 1972 | if (of_find_property(np, "ti,needs-special-hs-handling", NULL)) |
| 1973 | pdata->slots[0].features |= HSMMC_HAS_HSPE_SUPPORT; |
| 1974 | |
Daniel Mack | c9ae64d | 2014-02-17 12:36:33 +0100 | [diff] [blame] | 1975 | if (of_find_property(np, "keep-power-in-suspend", NULL)) |
| 1976 | pdata->slots[0].pm_caps |= MMC_PM_KEEP_POWER; |
| 1977 | |
| 1978 | if (of_find_property(np, "enable-sdio-wakeup", NULL)) |
| 1979 | pdata->slots[0].pm_caps |= MMC_PM_WAKE_SDIO_IRQ; |
| 1980 | |
Rajendra Nayak | 46856a6 | 2012-03-12 20:32:37 +0530 | [diff] [blame] | 1981 | return pdata; |
| 1982 | } |
| 1983 | #else |
| 1984 | static inline struct omap_mmc_platform_data |
| 1985 | *of_get_hsmmc_pdata(struct device *dev) |
| 1986 | { |
Balaji T K | 19df45b | 2014-02-28 19:08:18 +0530 | [diff] [blame] | 1987 | return ERR_PTR(-EINVAL); |
Rajendra Nayak | 46856a6 | 2012-03-12 20:32:37 +0530 | [diff] [blame] | 1988 | } |
| 1989 | #endif |
| 1990 | |
Bill Pemberton | c3be1ef | 2012-11-19 13:23:06 -0500 | [diff] [blame] | 1991 | static int omap_hsmmc_probe(struct platform_device *pdev) |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 1992 | { |
| 1993 | struct omap_mmc_platform_data *pdata = pdev->dev.platform_data; |
| 1994 | struct mmc_host *mmc; |
Denis Karpov | 70a3341 | 2009-09-22 16:44:59 -0700 | [diff] [blame] | 1995 | struct omap_hsmmc_host *host = NULL; |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 1996 | struct resource *res; |
Adrian Hunter | db0fefc | 2010-02-15 10:03:34 -0800 | [diff] [blame] | 1997 | int ret, irq; |
Rajendra Nayak | 46856a6 | 2012-03-12 20:32:37 +0530 | [diff] [blame] | 1998 | const struct of_device_id *match; |
Russell King | 26b8852 | 2012-04-13 12:27:37 +0100 | [diff] [blame] | 1999 | dma_cap_mask_t mask; |
| 2000 | unsigned tx_req, rx_req; |
Daniel Mack | 46b7603 | 2012-10-15 21:35:05 +0530 | [diff] [blame] | 2001 | struct pinctrl *pinctrl; |
Nishanth Menon | 59445b1 | 2014-02-13 23:45:48 -0600 | [diff] [blame] | 2002 | const struct omap_mmc_of_data *data; |
Balaji T K | 77fae21 | 2014-05-09 22:16:51 +0530 | [diff] [blame] | 2003 | void __iomem *base; |
Rajendra Nayak | 46856a6 | 2012-03-12 20:32:37 +0530 | [diff] [blame] | 2004 | |
| 2005 | match = of_match_device(of_match_ptr(omap_mmc_of_match), &pdev->dev); |
| 2006 | if (match) { |
| 2007 | pdata = of_get_hsmmc_pdata(&pdev->dev); |
Jan Luebbe | dc642c2 | 2013-01-30 10:07:17 +0100 | [diff] [blame] | 2008 | |
| 2009 | if (IS_ERR(pdata)) |
| 2010 | return PTR_ERR(pdata); |
| 2011 | |
Rajendra Nayak | 46856a6 | 2012-03-12 20:32:37 +0530 | [diff] [blame] | 2012 | if (match->data) { |
Nishanth Menon | 59445b1 | 2014-02-13 23:45:48 -0600 | [diff] [blame] | 2013 | data = match->data; |
| 2014 | pdata->reg_offset = data->reg_offset; |
| 2015 | pdata->controller_flags |= data->controller_flags; |
Rajendra Nayak | 46856a6 | 2012-03-12 20:32:37 +0530 | [diff] [blame] | 2016 | } |
| 2017 | } |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 2018 | |
| 2019 | if (pdata == NULL) { |
| 2020 | dev_err(&pdev->dev, "Platform Data is missing\n"); |
| 2021 | return -ENXIO; |
| 2022 | } |
| 2023 | |
| 2024 | if (pdata->nr_slots == 0) { |
| 2025 | dev_err(&pdev->dev, "No Slots\n"); |
| 2026 | return -ENXIO; |
| 2027 | } |
| 2028 | |
| 2029 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 2030 | irq = platform_get_irq(pdev, 0); |
| 2031 | if (res == NULL || irq < 0) |
| 2032 | return -ENXIO; |
| 2033 | |
Balaji T K | 77fae21 | 2014-05-09 22:16:51 +0530 | [diff] [blame] | 2034 | base = devm_ioremap_resource(&pdev->dev, res); |
| 2035 | if (IS_ERR(base)) |
| 2036 | return PTR_ERR(base); |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 2037 | |
Adrian Hunter | db0fefc | 2010-02-15 10:03:34 -0800 | [diff] [blame] | 2038 | ret = omap_hsmmc_gpio_init(pdata); |
| 2039 | if (ret) |
| 2040 | goto err; |
| 2041 | |
Denis Karpov | 70a3341 | 2009-09-22 16:44:59 -0700 | [diff] [blame] | 2042 | mmc = mmc_alloc_host(sizeof(struct omap_hsmmc_host), &pdev->dev); |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 2043 | if (!mmc) { |
| 2044 | ret = -ENOMEM; |
Adrian Hunter | db0fefc | 2010-02-15 10:03:34 -0800 | [diff] [blame] | 2045 | goto err_alloc; |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 2046 | } |
| 2047 | |
| 2048 | host = mmc_priv(mmc); |
| 2049 | host->mmc = mmc; |
| 2050 | host->pdata = pdata; |
| 2051 | host->dev = &pdev->dev; |
| 2052 | host->use_dma = 1; |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 2053 | host->dma_ch = -1; |
| 2054 | host->irq = irq; |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 2055 | host->slot_id = 0; |
Balaji T K | fc307df | 2012-04-02 12:26:47 +0530 | [diff] [blame] | 2056 | host->mapbase = res->start + pdata->reg_offset; |
Balaji T K | 77fae21 | 2014-05-09 22:16:51 +0530 | [diff] [blame] | 2057 | host->base = base + pdata->reg_offset; |
Adrian Hunter | 6da20c8 | 2010-02-15 10:03:34 -0800 | [diff] [blame] | 2058 | host->power_mode = MMC_POWER_OFF; |
Per Forlin | 9782aff | 2011-07-01 18:55:23 +0200 | [diff] [blame] | 2059 | host->next_data.cookie = 1; |
Balaji T K | e99448f | 2014-02-19 20:26:40 +0530 | [diff] [blame] | 2060 | host->pbias_enabled = 0; |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 2061 | |
| 2062 | platform_set_drvdata(pdev, host); |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 2063 | |
Andreas Fenkart | 2cd3a2a | 2014-05-29 10:28:00 +0200 | [diff] [blame] | 2064 | if (pdev->dev.of_node) |
| 2065 | host->wake_irq = irq_of_parse_and_map(pdev->dev.of_node, 1); |
| 2066 | |
Balaji T K | 7a8c2ce | 2011-07-01 22:09:34 +0530 | [diff] [blame] | 2067 | mmc->ops = &omap_hsmmc_ops; |
Denis Karpov | dd498ef | 2009-09-22 16:44:49 -0700 | [diff] [blame] | 2068 | |
Daniel Mack | d418ed8 | 2012-02-19 13:20:33 +0100 | [diff] [blame] | 2069 | mmc->f_min = OMAP_MMC_MIN_CLOCK; |
| 2070 | |
| 2071 | if (pdata->max_freq > 0) |
| 2072 | mmc->f_max = pdata->max_freq; |
| 2073 | else |
| 2074 | mmc->f_max = OMAP_MMC_MAX_CLOCK; |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 2075 | |
Adrian Hunter | 4dffd7a | 2009-09-22 16:44:58 -0700 | [diff] [blame] | 2076 | spin_lock_init(&host->irq_lock); |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 2077 | |
Balaji T K | 9618195 | 2014-05-09 22:16:48 +0530 | [diff] [blame] | 2078 | host->fclk = devm_clk_get(&pdev->dev, "fck"); |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 2079 | if (IS_ERR(host->fclk)) { |
| 2080 | ret = PTR_ERR(host->fclk); |
| 2081 | host->fclk = NULL; |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 2082 | goto err1; |
| 2083 | } |
| 2084 | |
Paul Walmsley | 9b68256 | 2011-10-06 14:50:35 -0600 | [diff] [blame] | 2085 | if (host->pdata->controller_flags & OMAP_HSMMC_BROKEN_MULTIBLOCK_READ) { |
| 2086 | dev_info(&pdev->dev, "multiblock reads disabled due to 35xx erratum 2.1.1.128; MMC read performance may suffer\n"); |
| 2087 | mmc->caps2 |= MMC_CAP2_NO_MULTI_READ; |
| 2088 | } |
Denis Karpov | dd498ef | 2009-09-22 16:44:49 -0700 | [diff] [blame] | 2089 | |
Balaji T K | fa4aa2d | 2011-07-01 22:09:35 +0530 | [diff] [blame] | 2090 | pm_runtime_enable(host->dev); |
| 2091 | pm_runtime_get_sync(host->dev); |
| 2092 | pm_runtime_set_autosuspend_delay(host->dev, MMC_AUTOSUSPEND_DELAY); |
| 2093 | pm_runtime_use_autosuspend(host->dev); |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 2094 | |
Balaji T K | 92a3aeb | 2012-02-24 21:14:34 +0530 | [diff] [blame] | 2095 | omap_hsmmc_context_save(host); |
| 2096 | |
Balaji T K | 9618195 | 2014-05-09 22:16:48 +0530 | [diff] [blame] | 2097 | host->dbclk = devm_clk_get(&pdev->dev, "mmchsdb_fck"); |
Rajendra Nayak | cd03d9a | 2012-04-09 12:08:35 +0530 | [diff] [blame] | 2098 | /* |
| 2099 | * MMC can still work without debounce clock. |
| 2100 | */ |
| 2101 | if (IS_ERR(host->dbclk)) { |
Rajendra Nayak | cd03d9a | 2012-04-09 12:08:35 +0530 | [diff] [blame] | 2102 | host->dbclk = NULL; |
Rajendra Nayak | 94c1814 | 2012-06-27 14:19:54 +0530 | [diff] [blame] | 2103 | } else if (clk_prepare_enable(host->dbclk) != 0) { |
Rajendra Nayak | cd03d9a | 2012-04-09 12:08:35 +0530 | [diff] [blame] | 2104 | dev_warn(mmc_dev(host->mmc), "Failed to enable debounce clk\n"); |
Rajendra Nayak | cd03d9a | 2012-04-09 12:08:35 +0530 | [diff] [blame] | 2105 | host->dbclk = NULL; |
Adrian Hunter | 2bec089 | 2009-09-22 16:45:02 -0700 | [diff] [blame] | 2106 | } |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 2107 | |
Juha Yrjola | 0ccd76d | 2008-11-14 15:22:00 +0200 | [diff] [blame] | 2108 | /* Since we do only SG emulation, we can have as many segs |
| 2109 | * as we want. */ |
Martin K. Petersen | a36274e | 2010-09-10 01:33:59 -0400 | [diff] [blame] | 2110 | mmc->max_segs = 1024; |
Juha Yrjola | 0ccd76d | 2008-11-14 15:22:00 +0200 | [diff] [blame] | 2111 | |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 2112 | mmc->max_blk_size = 512; /* Block Length at max can be 1024 */ |
| 2113 | mmc->max_blk_count = 0xFFFF; /* No. of Blocks is 16 bits */ |
| 2114 | mmc->max_req_size = mmc->max_blk_size * mmc->max_blk_count; |
| 2115 | mmc->max_seg_size = mmc->max_req_size; |
| 2116 | |
Jarkko Lavinen | 13189e7 | 2009-09-22 16:44:53 -0700 | [diff] [blame] | 2117 | mmc->caps |= MMC_CAP_MMC_HIGHSPEED | MMC_CAP_SD_HIGHSPEED | |
Adrian Hunter | 93caf8e69 | 2010-08-11 14:17:48 -0700 | [diff] [blame] | 2118 | MMC_CAP_WAIT_WHILE_BUSY | MMC_CAP_ERASE; |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 2119 | |
Sukumar Ghorai | 3a63833 | 2010-09-15 14:49:23 +0000 | [diff] [blame] | 2120 | mmc->caps |= mmc_slot(host).caps; |
| 2121 | if (mmc->caps & MMC_CAP_8_BIT_DATA) |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 2122 | mmc->caps |= MMC_CAP_4_BIT_DATA; |
| 2123 | |
Denis Karpov | 191d1f1 | 2009-09-22 16:44:55 -0700 | [diff] [blame] | 2124 | if (mmc_slot(host).nonremovable) |
Adrian Hunter | 23d99bb | 2009-09-22 16:44:48 -0700 | [diff] [blame] | 2125 | mmc->caps |= MMC_CAP_NONREMOVABLE; |
| 2126 | |
Eliad Peller | 6fdc75d | 2011-11-22 16:02:18 +0200 | [diff] [blame] | 2127 | mmc->pm_caps = mmc_slot(host).pm_caps; |
| 2128 | |
Denis Karpov | 70a3341 | 2009-09-22 16:44:59 -0700 | [diff] [blame] | 2129 | omap_hsmmc_conf_bus_power(host); |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 2130 | |
Santosh Shilimkar | 4a29b55 | 2013-05-10 17:42:35 +0530 | [diff] [blame] | 2131 | if (!pdev->dev.of_node) { |
| 2132 | res = platform_get_resource_byname(pdev, IORESOURCE_DMA, "tx"); |
| 2133 | if (!res) { |
| 2134 | dev_err(mmc_dev(host->mmc), "cannot get DMA TX channel\n"); |
| 2135 | ret = -ENXIO; |
| 2136 | goto err_irq; |
| 2137 | } |
| 2138 | tx_req = res->start; |
Balaji T K | b7bf773 | 2012-03-07 09:55:30 -0500 | [diff] [blame] | 2139 | |
Santosh Shilimkar | 4a29b55 | 2013-05-10 17:42:35 +0530 | [diff] [blame] | 2140 | res = platform_get_resource_byname(pdev, IORESOURCE_DMA, "rx"); |
| 2141 | if (!res) { |
| 2142 | dev_err(mmc_dev(host->mmc), "cannot get DMA RX channel\n"); |
| 2143 | ret = -ENXIO; |
| 2144 | goto err_irq; |
| 2145 | } |
| 2146 | rx_req = res->start; |
Balaji T K | b7bf773 | 2012-03-07 09:55:30 -0500 | [diff] [blame] | 2147 | } |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 2148 | |
Russell King | 26b8852 | 2012-04-13 12:27:37 +0100 | [diff] [blame] | 2149 | dma_cap_zero(mask); |
| 2150 | dma_cap_set(DMA_SLAVE, mask); |
Russell King | c5c9892 | 2012-04-13 12:14:39 +0100 | [diff] [blame] | 2151 | |
Matt Porter | d272fbf | 2013-05-10 17:42:34 +0530 | [diff] [blame] | 2152 | host->rx_chan = |
| 2153 | dma_request_slave_channel_compat(mask, omap_dma_filter_fn, |
| 2154 | &rx_req, &pdev->dev, "rx"); |
| 2155 | |
Russell King | 26b8852 | 2012-04-13 12:27:37 +0100 | [diff] [blame] | 2156 | if (!host->rx_chan) { |
| 2157 | dev_err(mmc_dev(host->mmc), "unable to obtain RX DMA engine channel %u\n", rx_req); |
Kevin Hilman | 04e8c7b | 2012-07-11 17:51:40 +0100 | [diff] [blame] | 2158 | ret = -ENXIO; |
Russell King | 26b8852 | 2012-04-13 12:27:37 +0100 | [diff] [blame] | 2159 | goto err_irq; |
| 2160 | } |
| 2161 | |
Matt Porter | d272fbf | 2013-05-10 17:42:34 +0530 | [diff] [blame] | 2162 | host->tx_chan = |
| 2163 | dma_request_slave_channel_compat(mask, omap_dma_filter_fn, |
| 2164 | &tx_req, &pdev->dev, "tx"); |
| 2165 | |
Russell King | 26b8852 | 2012-04-13 12:27:37 +0100 | [diff] [blame] | 2166 | if (!host->tx_chan) { |
| 2167 | dev_err(mmc_dev(host->mmc), "unable to obtain TX DMA engine channel %u\n", tx_req); |
Kevin Hilman | 04e8c7b | 2012-07-11 17:51:40 +0100 | [diff] [blame] | 2168 | ret = -ENXIO; |
Russell King | 26b8852 | 2012-04-13 12:27:37 +0100 | [diff] [blame] | 2169 | goto err_irq; |
Russell King | c5c9892 | 2012-04-13 12:14:39 +0100 | [diff] [blame] | 2170 | } |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 2171 | |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 2172 | /* Request IRQ for MMC operations */ |
Balaji T K | e1538ed | 2014-05-09 22:16:49 +0530 | [diff] [blame] | 2173 | ret = devm_request_irq(&pdev->dev, host->irq, omap_hsmmc_irq, 0, |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 2174 | mmc_hostname(mmc), host); |
| 2175 | if (ret) { |
Venkatraman S | b1e056a | 2012-11-19 22:00:00 +0530 | [diff] [blame] | 2176 | dev_err(mmc_dev(host->mmc), "Unable to grab HSMMC IRQ\n"); |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 2177 | goto err_irq; |
| 2178 | } |
| 2179 | |
| 2180 | if (pdata->init != NULL) { |
| 2181 | if (pdata->init(&pdev->dev) != 0) { |
Venkatraman S | b1e056a | 2012-11-19 22:00:00 +0530 | [diff] [blame] | 2182 | dev_err(mmc_dev(host->mmc), |
Denis Karpov | 70a3341 | 2009-09-22 16:44:59 -0700 | [diff] [blame] | 2183 | "Unable to configure MMC IRQs\n"); |
Balaji T K | e1538ed | 2014-05-09 22:16:49 +0530 | [diff] [blame] | 2184 | goto err_irq; |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 2185 | } |
| 2186 | } |
Adrian Hunter | db0fefc | 2010-02-15 10:03:34 -0800 | [diff] [blame] | 2187 | |
Adrian Hunter | b702b10 | 2010-02-15 10:03:35 -0800 | [diff] [blame] | 2188 | if (omap_hsmmc_have_reg() && !mmc_slot(host).set_power) { |
Adrian Hunter | db0fefc | 2010-02-15 10:03:34 -0800 | [diff] [blame] | 2189 | ret = omap_hsmmc_reg_get(host); |
| 2190 | if (ret) |
| 2191 | goto err_reg; |
| 2192 | host->use_reg = 1; |
| 2193 | } |
| 2194 | |
David Brownell | b583f26 | 2009-05-28 14:04:03 -0700 | [diff] [blame] | 2195 | mmc->ocr_avail = mmc_slot(host).ocr_mask; |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 2196 | |
| 2197 | /* Request IRQ for card detect */ |
Adrian Hunter | e1a55f5 | 2009-01-26 13:17:25 +0200 | [diff] [blame] | 2198 | if ((mmc_slot(host).card_detect_irq)) { |
Balaji T K | 9fa0e05 | 2014-05-09 22:16:50 +0530 | [diff] [blame] | 2199 | ret = devm_request_threaded_irq(&pdev->dev, |
| 2200 | mmc_slot(host).card_detect_irq, |
| 2201 | NULL, omap_hsmmc_detect, |
Ming Lei | db35f83 | 2012-05-17 10:27:12 +0800 | [diff] [blame] | 2202 | IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING | IRQF_ONESHOT, |
NeilBrown | 7efab4f | 2011-12-30 12:35:13 +1100 | [diff] [blame] | 2203 | mmc_hostname(mmc), host); |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 2204 | if (ret) { |
Venkatraman S | b1e056a | 2012-11-19 22:00:00 +0530 | [diff] [blame] | 2205 | dev_err(mmc_dev(host->mmc), |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 2206 | "Unable to grab MMC CD IRQ\n"); |
| 2207 | goto err_irq_cd; |
| 2208 | } |
kishore kadiyala | 72f2e2c | 2010-09-24 17:13:20 +0000 | [diff] [blame] | 2209 | pdata->suspend = omap_hsmmc_suspend_cdirq; |
| 2210 | pdata->resume = omap_hsmmc_resume_cdirq; |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 2211 | } |
| 2212 | |
Adrian Hunter | b417577 | 2010-05-26 14:42:06 -0700 | [diff] [blame] | 2213 | omap_hsmmc_disable_irq(host); |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 2214 | |
Daniel Mack | 46b7603 | 2012-10-15 21:35:05 +0530 | [diff] [blame] | 2215 | pinctrl = devm_pinctrl_get_select_default(&pdev->dev); |
| 2216 | if (IS_ERR(pinctrl)) |
| 2217 | dev_warn(&pdev->dev, |
| 2218 | "pins are not configured from the driver\n"); |
| 2219 | |
Andreas Fenkart | 2cd3a2a | 2014-05-29 10:28:00 +0200 | [diff] [blame] | 2220 | /* |
| 2221 | * For now, only support SDIO interrupt if we have a separate |
| 2222 | * wake-up interrupt configured from device tree. This is because |
| 2223 | * the wake-up interrupt is needed for idle state and some |
| 2224 | * platforms need special quirks. And we don't want to add new |
| 2225 | * legacy mux platform init code callbacks any longer as we |
| 2226 | * are moving to DT based booting anyways. |
| 2227 | */ |
| 2228 | ret = omap_hsmmc_configure_wake_irq(host); |
| 2229 | if (!ret) |
| 2230 | mmc->caps |= MMC_CAP_SDIO_IRQ; |
| 2231 | |
Adrian Hunter | b62f622 | 2009-09-22 16:45:01 -0700 | [diff] [blame] | 2232 | omap_hsmmc_protect_card(host); |
| 2233 | |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 2234 | mmc_add_host(mmc); |
| 2235 | |
Denis Karpov | 191d1f1 | 2009-09-22 16:44:55 -0700 | [diff] [blame] | 2236 | if (mmc_slot(host).name != NULL) { |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 2237 | ret = device_create_file(&mmc->class_dev, &dev_attr_slot_name); |
| 2238 | if (ret < 0) |
| 2239 | goto err_slot_name; |
| 2240 | } |
Denis Karpov | 191d1f1 | 2009-09-22 16:44:55 -0700 | [diff] [blame] | 2241 | if (mmc_slot(host).card_detect_irq && mmc_slot(host).get_cover_state) { |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 2242 | ret = device_create_file(&mmc->class_dev, |
| 2243 | &dev_attr_cover_switch); |
| 2244 | if (ret < 0) |
Adrian Hunter | db0fefc | 2010-02-15 10:03:34 -0800 | [diff] [blame] | 2245 | goto err_slot_name; |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 2246 | } |
| 2247 | |
Denis Karpov | 70a3341 | 2009-09-22 16:44:59 -0700 | [diff] [blame] | 2248 | omap_hsmmc_debugfs(mmc); |
Balaji T K | fa4aa2d | 2011-07-01 22:09:35 +0530 | [diff] [blame] | 2249 | pm_runtime_mark_last_busy(host->dev); |
| 2250 | pm_runtime_put_autosuspend(host->dev); |
Denis Karpov | d900f71 | 2009-09-22 16:44:38 -0700 | [diff] [blame] | 2251 | |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 2252 | return 0; |
| 2253 | |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 2254 | err_slot_name: |
| 2255 | mmc_remove_host(mmc); |
Adrian Hunter | db0fefc | 2010-02-15 10:03:34 -0800 | [diff] [blame] | 2256 | err_irq_cd: |
| 2257 | if (host->use_reg) |
| 2258 | omap_hsmmc_reg_put(host); |
| 2259 | err_reg: |
| 2260 | if (host->pdata->cleanup) |
| 2261 | host->pdata->cleanup(&pdev->dev); |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 2262 | err_irq: |
Russell King | c5c9892 | 2012-04-13 12:14:39 +0100 | [diff] [blame] | 2263 | if (host->tx_chan) |
| 2264 | dma_release_channel(host->tx_chan); |
| 2265 | if (host->rx_chan) |
| 2266 | dma_release_channel(host->rx_chan); |
Balaji T K | d59d77e | 2012-02-24 21:14:33 +0530 | [diff] [blame] | 2267 | pm_runtime_put_sync(host->dev); |
Tony Lindgren | 37f6190 | 2012-03-08 23:41:35 -0500 | [diff] [blame] | 2268 | pm_runtime_disable(host->dev); |
Balaji T K | 9618195 | 2014-05-09 22:16:48 +0530 | [diff] [blame] | 2269 | if (host->dbclk) |
Rajendra Nayak | 94c1814 | 2012-06-27 14:19:54 +0530 | [diff] [blame] | 2270 | clk_disable_unprepare(host->dbclk); |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 2271 | err1: |
Adrian Hunter | db0fefc | 2010-02-15 10:03:34 -0800 | [diff] [blame] | 2272 | mmc_free_host(mmc); |
| 2273 | err_alloc: |
| 2274 | omap_hsmmc_gpio_free(pdata); |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 2275 | err: |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 2276 | return ret; |
| 2277 | } |
| 2278 | |
Bill Pemberton | 6e0ee71 | 2012-11-19 13:26:03 -0500 | [diff] [blame] | 2279 | static int omap_hsmmc_remove(struct platform_device *pdev) |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 2280 | { |
Denis Karpov | 70a3341 | 2009-09-22 16:44:59 -0700 | [diff] [blame] | 2281 | struct omap_hsmmc_host *host = platform_get_drvdata(pdev); |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 2282 | |
Felipe Balbi | 927ce94 | 2012-03-14 11:18:27 +0200 | [diff] [blame] | 2283 | pm_runtime_get_sync(host->dev); |
| 2284 | mmc_remove_host(host->mmc); |
| 2285 | if (host->use_reg) |
| 2286 | omap_hsmmc_reg_put(host); |
| 2287 | if (host->pdata->cleanup) |
| 2288 | host->pdata->cleanup(&pdev->dev); |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 2289 | |
Russell King | c5c9892 | 2012-04-13 12:14:39 +0100 | [diff] [blame] | 2290 | if (host->tx_chan) |
| 2291 | dma_release_channel(host->tx_chan); |
| 2292 | if (host->rx_chan) |
| 2293 | dma_release_channel(host->rx_chan); |
| 2294 | |
Felipe Balbi | 927ce94 | 2012-03-14 11:18:27 +0200 | [diff] [blame] | 2295 | pm_runtime_put_sync(host->dev); |
| 2296 | pm_runtime_disable(host->dev); |
Balaji T K | 9618195 | 2014-05-09 22:16:48 +0530 | [diff] [blame] | 2297 | if (host->dbclk) |
Rajendra Nayak | 94c1814 | 2012-06-27 14:19:54 +0530 | [diff] [blame] | 2298 | clk_disable_unprepare(host->dbclk); |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 2299 | |
Balaji T K | 9ea28ec | 2012-10-15 21:35:08 +0530 | [diff] [blame] | 2300 | omap_hsmmc_gpio_free(host->pdata); |
Balaji T K | 9d1f028 | 2012-10-15 21:35:07 +0530 | [diff] [blame] | 2301 | mmc_free_host(host->mmc); |
Felipe Balbi | 927ce94 | 2012-03-14 11:18:27 +0200 | [diff] [blame] | 2302 | |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 2303 | return 0; |
| 2304 | } |
| 2305 | |
| 2306 | #ifdef CONFIG_PM |
Felipe Balbi | a48ce88 | 2012-11-19 21:59:59 +0530 | [diff] [blame] | 2307 | static int omap_hsmmc_prepare(struct device *dev) |
| 2308 | { |
| 2309 | struct omap_hsmmc_host *host = dev_get_drvdata(dev); |
| 2310 | |
| 2311 | if (host->pdata->suspend) |
| 2312 | return host->pdata->suspend(dev, host->slot_id); |
| 2313 | |
| 2314 | return 0; |
| 2315 | } |
| 2316 | |
| 2317 | static void omap_hsmmc_complete(struct device *dev) |
| 2318 | { |
| 2319 | struct omap_hsmmc_host *host = dev_get_drvdata(dev); |
| 2320 | |
| 2321 | if (host->pdata->resume) |
| 2322 | host->pdata->resume(dev, host->slot_id); |
| 2323 | |
| 2324 | } |
| 2325 | |
Kevin Hilman | a791daa | 2010-05-26 14:42:07 -0700 | [diff] [blame] | 2326 | static int omap_hsmmc_suspend(struct device *dev) |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 2327 | { |
Felipe Balbi | 927ce94 | 2012-03-14 11:18:27 +0200 | [diff] [blame] | 2328 | struct omap_hsmmc_host *host = dev_get_drvdata(dev); |
| 2329 | |
| 2330 | if (!host) |
| 2331 | return 0; |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 2332 | |
Felipe Balbi | 927ce94 | 2012-03-14 11:18:27 +0200 | [diff] [blame] | 2333 | pm_runtime_get_sync(host->dev); |
Felipe Balbi | 927ce94 | 2012-03-14 11:18:27 +0200 | [diff] [blame] | 2334 | |
| 2335 | if (!(host->mmc->pm_flags & MMC_PM_KEEP_POWER)) { |
Andreas Fenkart | 2cd3a2a | 2014-05-29 10:28:00 +0200 | [diff] [blame] | 2336 | OMAP_HSMMC_WRITE(host->base, ISE, 0); |
| 2337 | OMAP_HSMMC_WRITE(host->base, IE, 0); |
| 2338 | OMAP_HSMMC_WRITE(host->base, STAT, STAT_CLEAR); |
Felipe Balbi | 927ce94 | 2012-03-14 11:18:27 +0200 | [diff] [blame] | 2339 | OMAP_HSMMC_WRITE(host->base, HCTL, |
| 2340 | OMAP_HSMMC_READ(host->base, HCTL) & ~SDBP); |
| 2341 | } |
| 2342 | |
Andreas Fenkart | 2cd3a2a | 2014-05-29 10:28:00 +0200 | [diff] [blame] | 2343 | /* do not wake up due to sdio irq */ |
| 2344 | if ((host->mmc->caps & MMC_CAP_SDIO_IRQ) && |
| 2345 | !(host->mmc->pm_flags & MMC_PM_WAKE_SDIO_IRQ)) |
| 2346 | disable_irq(host->wake_irq); |
| 2347 | |
Rajendra Nayak | cd03d9a | 2012-04-09 12:08:35 +0530 | [diff] [blame] | 2348 | if (host->dbclk) |
Rajendra Nayak | 94c1814 | 2012-06-27 14:19:54 +0530 | [diff] [blame] | 2349 | clk_disable_unprepare(host->dbclk); |
Ulf Hansson | 3932afd | 2013-09-25 14:47:06 +0200 | [diff] [blame] | 2350 | |
Eliad Peller | 31f9d46 | 2011-11-22 16:02:17 +0200 | [diff] [blame] | 2351 | pm_runtime_put_sync(host->dev); |
Ulf Hansson | 3932afd | 2013-09-25 14:47:06 +0200 | [diff] [blame] | 2352 | return 0; |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 2353 | } |
| 2354 | |
| 2355 | /* Routine to resume the MMC device */ |
Kevin Hilman | a791daa | 2010-05-26 14:42:07 -0700 | [diff] [blame] | 2356 | static int omap_hsmmc_resume(struct device *dev) |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 2357 | { |
Felipe Balbi | 927ce94 | 2012-03-14 11:18:27 +0200 | [diff] [blame] | 2358 | struct omap_hsmmc_host *host = dev_get_drvdata(dev); |
| 2359 | |
| 2360 | if (!host) |
| 2361 | return 0; |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 2362 | |
Felipe Balbi | 927ce94 | 2012-03-14 11:18:27 +0200 | [diff] [blame] | 2363 | pm_runtime_get_sync(host->dev); |
Denis Karpov | 11dd62a | 2009-09-22 16:44:43 -0700 | [diff] [blame] | 2364 | |
Rajendra Nayak | cd03d9a | 2012-04-09 12:08:35 +0530 | [diff] [blame] | 2365 | if (host->dbclk) |
Rajendra Nayak | 94c1814 | 2012-06-27 14:19:54 +0530 | [diff] [blame] | 2366 | clk_prepare_enable(host->dbclk); |
Adrian Hunter | 2bec089 | 2009-09-22 16:45:02 -0700 | [diff] [blame] | 2367 | |
Felipe Balbi | 927ce94 | 2012-03-14 11:18:27 +0200 | [diff] [blame] | 2368 | if (!(host->mmc->pm_flags & MMC_PM_KEEP_POWER)) |
| 2369 | omap_hsmmc_conf_bus_power(host); |
Kim Kyuwon | 1b331e6 | 2009-02-20 13:10:08 +0100 | [diff] [blame] | 2370 | |
Felipe Balbi | 927ce94 | 2012-03-14 11:18:27 +0200 | [diff] [blame] | 2371 | omap_hsmmc_protect_card(host); |
| 2372 | |
Andreas Fenkart | 2cd3a2a | 2014-05-29 10:28:00 +0200 | [diff] [blame] | 2373 | if ((host->mmc->caps & MMC_CAP_SDIO_IRQ) && |
| 2374 | !(host->mmc->pm_flags & MMC_PM_WAKE_SDIO_IRQ)) |
| 2375 | enable_irq(host->wake_irq); |
| 2376 | |
Felipe Balbi | 927ce94 | 2012-03-14 11:18:27 +0200 | [diff] [blame] | 2377 | pm_runtime_mark_last_busy(host->dev); |
| 2378 | pm_runtime_put_autosuspend(host->dev); |
Ulf Hansson | 3932afd | 2013-09-25 14:47:06 +0200 | [diff] [blame] | 2379 | return 0; |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 2380 | } |
| 2381 | |
| 2382 | #else |
Felipe Balbi | a48ce88 | 2012-11-19 21:59:59 +0530 | [diff] [blame] | 2383 | #define omap_hsmmc_prepare NULL |
| 2384 | #define omap_hsmmc_complete NULL |
Denis Karpov | 70a3341 | 2009-09-22 16:44:59 -0700 | [diff] [blame] | 2385 | #define omap_hsmmc_suspend NULL |
Felipe Balbi | a48ce88 | 2012-11-19 21:59:59 +0530 | [diff] [blame] | 2386 | #define omap_hsmmc_resume NULL |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 2387 | #endif |
| 2388 | |
Balaji T K | fa4aa2d | 2011-07-01 22:09:35 +0530 | [diff] [blame] | 2389 | static int omap_hsmmc_runtime_suspend(struct device *dev) |
| 2390 | { |
| 2391 | struct omap_hsmmc_host *host; |
Andreas Fenkart | 2cd3a2a | 2014-05-29 10:28:00 +0200 | [diff] [blame] | 2392 | unsigned long flags; |
Andreas Fenkart | f945901 | 2014-05-29 10:28:03 +0200 | [diff] [blame^] | 2393 | int ret = 0; |
Balaji T K | fa4aa2d | 2011-07-01 22:09:35 +0530 | [diff] [blame] | 2394 | |
| 2395 | host = platform_get_drvdata(to_platform_device(dev)); |
| 2396 | omap_hsmmc_context_save(host); |
Felipe Balbi | 927ce94 | 2012-03-14 11:18:27 +0200 | [diff] [blame] | 2397 | dev_dbg(dev, "disabled\n"); |
Balaji T K | fa4aa2d | 2011-07-01 22:09:35 +0530 | [diff] [blame] | 2398 | |
Andreas Fenkart | 2cd3a2a | 2014-05-29 10:28:00 +0200 | [diff] [blame] | 2399 | spin_lock_irqsave(&host->irq_lock, flags); |
| 2400 | if ((host->mmc->caps & MMC_CAP_SDIO_IRQ) && |
| 2401 | (host->flags & HSMMC_SDIO_IRQ_ENABLED)) { |
| 2402 | /* disable sdio irq handling to prevent race */ |
| 2403 | OMAP_HSMMC_WRITE(host->base, ISE, 0); |
| 2404 | OMAP_HSMMC_WRITE(host->base, IE, 0); |
Andreas Fenkart | f945901 | 2014-05-29 10:28:03 +0200 | [diff] [blame^] | 2405 | |
| 2406 | if (!(OMAP_HSMMC_READ(host->base, PSTATE) & DLEV_DAT(1))) { |
| 2407 | /* |
| 2408 | * dat1 line low, pending sdio irq |
| 2409 | * race condition: possible irq handler running on |
| 2410 | * multi-core, abort |
| 2411 | */ |
| 2412 | dev_dbg(dev, "pending sdio irq, abort suspend\n"); |
| 2413 | OMAP_HSMMC_WRITE(host->base, STAT, STAT_CLEAR); |
| 2414 | OMAP_HSMMC_WRITE(host->base, ISE, CIRQ_EN); |
| 2415 | OMAP_HSMMC_WRITE(host->base, IE, CIRQ_EN); |
| 2416 | pm_runtime_mark_last_busy(dev); |
| 2417 | ret = -EBUSY; |
| 2418 | goto abort; |
| 2419 | } |
Andreas Fenkart | 2cd3a2a | 2014-05-29 10:28:00 +0200 | [diff] [blame] | 2420 | |
| 2421 | WARN_ON(host->flags & HSMMC_WAKE_IRQ_ENABLED); |
| 2422 | enable_irq(host->wake_irq); |
| 2423 | host->flags |= HSMMC_WAKE_IRQ_ENABLED; |
| 2424 | } |
Andreas Fenkart | f945901 | 2014-05-29 10:28:03 +0200 | [diff] [blame^] | 2425 | abort: |
Andreas Fenkart | 2cd3a2a | 2014-05-29 10:28:00 +0200 | [diff] [blame] | 2426 | spin_unlock_irqrestore(&host->irq_lock, flags); |
Andreas Fenkart | f945901 | 2014-05-29 10:28:03 +0200 | [diff] [blame^] | 2427 | return ret; |
Balaji T K | fa4aa2d | 2011-07-01 22:09:35 +0530 | [diff] [blame] | 2428 | } |
| 2429 | |
| 2430 | static int omap_hsmmc_runtime_resume(struct device *dev) |
| 2431 | { |
| 2432 | struct omap_hsmmc_host *host; |
Andreas Fenkart | 2cd3a2a | 2014-05-29 10:28:00 +0200 | [diff] [blame] | 2433 | unsigned long flags; |
Balaji T K | fa4aa2d | 2011-07-01 22:09:35 +0530 | [diff] [blame] | 2434 | |
| 2435 | host = platform_get_drvdata(to_platform_device(dev)); |
| 2436 | omap_hsmmc_context_restore(host); |
Felipe Balbi | 927ce94 | 2012-03-14 11:18:27 +0200 | [diff] [blame] | 2437 | dev_dbg(dev, "enabled\n"); |
Balaji T K | fa4aa2d | 2011-07-01 22:09:35 +0530 | [diff] [blame] | 2438 | |
Andreas Fenkart | 2cd3a2a | 2014-05-29 10:28:00 +0200 | [diff] [blame] | 2439 | spin_lock_irqsave(&host->irq_lock, flags); |
| 2440 | if ((host->mmc->caps & MMC_CAP_SDIO_IRQ) && |
| 2441 | (host->flags & HSMMC_SDIO_IRQ_ENABLED)) { |
| 2442 | /* sdio irq flag can't change while in runtime suspend */ |
| 2443 | if (host->flags & HSMMC_WAKE_IRQ_ENABLED) { |
| 2444 | disable_irq_nosync(host->wake_irq); |
| 2445 | host->flags &= ~HSMMC_WAKE_IRQ_ENABLED; |
| 2446 | } |
| 2447 | |
| 2448 | OMAP_HSMMC_WRITE(host->base, STAT, STAT_CLEAR); |
| 2449 | OMAP_HSMMC_WRITE(host->base, ISE, CIRQ_EN); |
| 2450 | OMAP_HSMMC_WRITE(host->base, IE, CIRQ_EN); |
| 2451 | } |
| 2452 | spin_unlock_irqrestore(&host->irq_lock, flags); |
Balaji T K | fa4aa2d | 2011-07-01 22:09:35 +0530 | [diff] [blame] | 2453 | return 0; |
| 2454 | } |
| 2455 | |
Kevin Hilman | a791daa | 2010-05-26 14:42:07 -0700 | [diff] [blame] | 2456 | static struct dev_pm_ops omap_hsmmc_dev_pm_ops = { |
Denis Karpov | 70a3341 | 2009-09-22 16:44:59 -0700 | [diff] [blame] | 2457 | .suspend = omap_hsmmc_suspend, |
| 2458 | .resume = omap_hsmmc_resume, |
Felipe Balbi | a48ce88 | 2012-11-19 21:59:59 +0530 | [diff] [blame] | 2459 | .prepare = omap_hsmmc_prepare, |
| 2460 | .complete = omap_hsmmc_complete, |
Balaji T K | fa4aa2d | 2011-07-01 22:09:35 +0530 | [diff] [blame] | 2461 | .runtime_suspend = omap_hsmmc_runtime_suspend, |
| 2462 | .runtime_resume = omap_hsmmc_runtime_resume, |
Kevin Hilman | a791daa | 2010-05-26 14:42:07 -0700 | [diff] [blame] | 2463 | }; |
| 2464 | |
| 2465 | static struct platform_driver omap_hsmmc_driver = { |
Felipe Balbi | efa25fd | 2012-03-14 11:18:28 +0200 | [diff] [blame] | 2466 | .probe = omap_hsmmc_probe, |
Bill Pemberton | 0433c14 | 2012-11-19 13:20:26 -0500 | [diff] [blame] | 2467 | .remove = omap_hsmmc_remove, |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 2468 | .driver = { |
| 2469 | .name = DRIVER_NAME, |
| 2470 | .owner = THIS_MODULE, |
Kevin Hilman | a791daa | 2010-05-26 14:42:07 -0700 | [diff] [blame] | 2471 | .pm = &omap_hsmmc_dev_pm_ops, |
Rajendra Nayak | 46856a6 | 2012-03-12 20:32:37 +0530 | [diff] [blame] | 2472 | .of_match_table = of_match_ptr(omap_mmc_of_match), |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 2473 | }, |
| 2474 | }; |
| 2475 | |
Felipe Balbi | b796450 | 2012-03-14 11:18:32 +0200 | [diff] [blame] | 2476 | module_platform_driver(omap_hsmmc_driver); |
Madhusudhan Chikkature | a45c6cb | 2009-01-23 01:05:23 +0100 | [diff] [blame] | 2477 | MODULE_DESCRIPTION("OMAP High Speed Multimedia Card driver"); |
| 2478 | MODULE_LICENSE("GPL"); |
| 2479 | MODULE_ALIAS("platform:" DRIVER_NAME); |
| 2480 | MODULE_AUTHOR("Texas Instruments Inc"); |