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