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