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