Wolfram Sang | 95f25ef | 2010-10-15 12:21:04 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Freescale eSDHC i.MX controller driver for the platform bus. |
| 3 | * |
| 4 | * derived from the OF-version. |
| 5 | * |
| 6 | * Copyright (c) 2010 Pengutronix e.K. |
| 7 | * Author: Wolfram Sang <w.sang@pengutronix.de> |
| 8 | * |
| 9 | * This program is free software; you can redistribute it and/or modify |
| 10 | * it under the terms of the GNU General Public License as published by |
| 11 | * the Free Software Foundation; either version 2 of the License. |
| 12 | */ |
| 13 | |
| 14 | #include <linux/io.h> |
| 15 | #include <linux/delay.h> |
| 16 | #include <linux/err.h> |
| 17 | #include <linux/clk.h> |
Wolfram Sang | 0c6d49c | 2011-02-26 14:44:39 +0100 | [diff] [blame] | 18 | #include <linux/gpio.h> |
Shawn Guo | 66506f7 | 2011-08-15 10:28:18 +0800 | [diff] [blame] | 19 | #include <linux/module.h> |
Richard Zhu | e149860 | 2011-03-25 09:18:27 -0400 | [diff] [blame] | 20 | #include <linux/slab.h> |
Wolfram Sang | 95f25ef | 2010-10-15 12:21:04 +0200 | [diff] [blame] | 21 | #include <linux/mmc/host.h> |
Richard Zhu | 58ac817 | 2011-03-21 13:22:16 +0800 | [diff] [blame] | 22 | #include <linux/mmc/mmc.h> |
| 23 | #include <linux/mmc/sdio.h> |
Shawn Guo | fbe5fdd | 2012-12-11 22:32:20 +0800 | [diff] [blame] | 24 | #include <linux/mmc/slot-gpio.h> |
Shawn Guo | abfafc2 | 2011-06-30 15:44:44 +0800 | [diff] [blame] | 25 | #include <linux/of.h> |
| 26 | #include <linux/of_device.h> |
| 27 | #include <linux/of_gpio.h> |
Dong Aisheng | e62d8b8 | 2012-05-11 14:56:01 +0800 | [diff] [blame] | 28 | #include <linux/pinctrl/consumer.h> |
Arnd Bergmann | 82906b1 | 2012-08-24 15:14:29 +0200 | [diff] [blame] | 29 | #include <linux/platform_data/mmc-esdhc-imx.h> |
Wolfram Sang | 95f25ef | 2010-10-15 12:21:04 +0200 | [diff] [blame] | 30 | #include "sdhci-pltfm.h" |
| 31 | #include "sdhci-esdhc.h" |
| 32 | |
Shawn Guo | 60bf639 | 2013-01-15 23:36:53 +0800 | [diff] [blame] | 33 | #define ESDHC_CTRL_D3CD 0x08 |
Richard Zhu | 58ac817 | 2011-03-21 13:22:16 +0800 | [diff] [blame] | 34 | /* VENDOR SPEC register */ |
Shawn Guo | 60bf639 | 2013-01-15 23:36:53 +0800 | [diff] [blame] | 35 | #define ESDHC_VENDOR_SPEC 0xc0 |
| 36 | #define ESDHC_VENDOR_SPEC_SDIO_QUIRK (1 << 1) |
| 37 | #define ESDHC_WTMK_LVL 0x44 |
| 38 | #define ESDHC_MIX_CTRL 0x48 |
Shawn Guo | 2a15f98 | 2013-01-21 19:02:26 +0800 | [diff] [blame] | 39 | #define ESDHC_MIX_CTRL_AC23EN (1 << 7) |
| 40 | /* Bits 3 and 6 are not SDHCI standard definitions */ |
| 41 | #define ESDHC_MIX_CTRL_SDHCI_MASK 0xb7 |
Richard Zhu | 58ac817 | 2011-03-21 13:22:16 +0800 | [diff] [blame] | 42 | |
Richard Zhu | 58ac817 | 2011-03-21 13:22:16 +0800 | [diff] [blame] | 43 | /* |
Sascha Hauer | af51079 | 2013-01-21 19:02:28 +0800 | [diff] [blame] | 44 | * Our interpretation of the SDHCI_HOST_CONTROL register |
| 45 | */ |
| 46 | #define ESDHC_CTRL_4BITBUS (0x1 << 1) |
| 47 | #define ESDHC_CTRL_8BITBUS (0x2 << 1) |
| 48 | #define ESDHC_CTRL_BUSWIDTH_MASK (0x3 << 1) |
| 49 | |
| 50 | /* |
Richard Zhu | 97e4ba6 | 2011-08-11 16:51:46 -0400 | [diff] [blame] | 51 | * There is an INT DMA ERR mis-match between eSDHC and STD SDHC SPEC: |
| 52 | * Bit25 is used in STD SPEC, and is reserved in fsl eSDHC design, |
| 53 | * but bit28 is used as the INT DMA ERR in fsl eSDHC design. |
| 54 | * Define this macro DMA error INT for fsl eSDHC |
| 55 | */ |
Shawn Guo | 60bf639 | 2013-01-15 23:36:53 +0800 | [diff] [blame] | 56 | #define ESDHC_INT_VENDOR_SPEC_DMA_ERR (1 << 28) |
Richard Zhu | 97e4ba6 | 2011-08-11 16:51:46 -0400 | [diff] [blame] | 57 | |
| 58 | /* |
Richard Zhu | 58ac817 | 2011-03-21 13:22:16 +0800 | [diff] [blame] | 59 | * The CMDTYPE of the CMD register (offset 0xE) should be set to |
| 60 | * "11" when the STOP CMD12 is issued on imx53 to abort one |
| 61 | * open ended multi-blk IO. Otherwise the TC INT wouldn't |
| 62 | * be generated. |
| 63 | * In exact block transfer, the controller doesn't complete the |
| 64 | * operations automatically as required at the end of the |
| 65 | * transfer and remains on hold if the abort command is not sent. |
| 66 | * As a result, the TC flag is not asserted and SW received timeout |
| 67 | * exeception. Bit1 of Vendor Spec registor is used to fix it. |
| 68 | */ |
| 69 | #define ESDHC_FLAG_MULTIBLK_NO_INT (1 << 1) |
Richard Zhu | e149860 | 2011-03-25 09:18:27 -0400 | [diff] [blame] | 70 | |
Shawn Guo | 57ed331 | 2011-06-30 09:24:26 +0800 | [diff] [blame] | 71 | enum imx_esdhc_type { |
| 72 | IMX25_ESDHC, |
| 73 | IMX35_ESDHC, |
| 74 | IMX51_ESDHC, |
| 75 | IMX53_ESDHC, |
Shawn Guo | 95a2482 | 2011-09-19 17:32:21 +0800 | [diff] [blame] | 76 | IMX6Q_USDHC, |
Shawn Guo | 57ed331 | 2011-06-30 09:24:26 +0800 | [diff] [blame] | 77 | }; |
| 78 | |
Richard Zhu | e149860 | 2011-03-25 09:18:27 -0400 | [diff] [blame] | 79 | struct pltfm_imx_data { |
| 80 | int flags; |
| 81 | u32 scratchpad; |
Shawn Guo | 57ed331 | 2011-06-30 09:24:26 +0800 | [diff] [blame] | 82 | enum imx_esdhc_type devtype; |
Dong Aisheng | e62d8b8 | 2012-05-11 14:56:01 +0800 | [diff] [blame] | 83 | struct pinctrl *pinctrl; |
Shawn Guo | 842afc0 | 2011-07-06 22:57:48 +0800 | [diff] [blame] | 84 | struct esdhc_platform_data boarddata; |
Sascha Hauer | 52dac61 | 2012-03-07 09:31:34 +0100 | [diff] [blame] | 85 | struct clk *clk_ipg; |
| 86 | struct clk *clk_ahb; |
| 87 | struct clk *clk_per; |
Lucas Stach | 361b848 | 2013-03-15 09:49:26 +0100 | [diff] [blame] | 88 | enum { |
| 89 | NO_CMD_PENDING, /* no multiblock command pending*/ |
| 90 | MULTIBLK_IN_PROCESS, /* exact multiblock cmd in process */ |
| 91 | WAIT_FOR_INT, /* sent CMD12, waiting for response INT */ |
| 92 | } multiblock_status; |
| 93 | |
Richard Zhu | e149860 | 2011-03-25 09:18:27 -0400 | [diff] [blame] | 94 | }; |
| 95 | |
Shawn Guo | 57ed331 | 2011-06-30 09:24:26 +0800 | [diff] [blame] | 96 | static struct platform_device_id imx_esdhc_devtype[] = { |
| 97 | { |
| 98 | .name = "sdhci-esdhc-imx25", |
| 99 | .driver_data = IMX25_ESDHC, |
| 100 | }, { |
| 101 | .name = "sdhci-esdhc-imx35", |
| 102 | .driver_data = IMX35_ESDHC, |
| 103 | }, { |
| 104 | .name = "sdhci-esdhc-imx51", |
| 105 | .driver_data = IMX51_ESDHC, |
| 106 | }, { |
| 107 | .name = "sdhci-esdhc-imx53", |
| 108 | .driver_data = IMX53_ESDHC, |
| 109 | }, { |
Shawn Guo | 95a2482 | 2011-09-19 17:32:21 +0800 | [diff] [blame] | 110 | .name = "sdhci-usdhc-imx6q", |
| 111 | .driver_data = IMX6Q_USDHC, |
| 112 | }, { |
Shawn Guo | 57ed331 | 2011-06-30 09:24:26 +0800 | [diff] [blame] | 113 | /* sentinel */ |
| 114 | } |
| 115 | }; |
| 116 | MODULE_DEVICE_TABLE(platform, imx_esdhc_devtype); |
| 117 | |
Shawn Guo | abfafc2 | 2011-06-30 15:44:44 +0800 | [diff] [blame] | 118 | static const struct of_device_id imx_esdhc_dt_ids[] = { |
| 119 | { .compatible = "fsl,imx25-esdhc", .data = &imx_esdhc_devtype[IMX25_ESDHC], }, |
| 120 | { .compatible = "fsl,imx35-esdhc", .data = &imx_esdhc_devtype[IMX35_ESDHC], }, |
| 121 | { .compatible = "fsl,imx51-esdhc", .data = &imx_esdhc_devtype[IMX51_ESDHC], }, |
| 122 | { .compatible = "fsl,imx53-esdhc", .data = &imx_esdhc_devtype[IMX53_ESDHC], }, |
Shawn Guo | 95a2482 | 2011-09-19 17:32:21 +0800 | [diff] [blame] | 123 | { .compatible = "fsl,imx6q-usdhc", .data = &imx_esdhc_devtype[IMX6Q_USDHC], }, |
Shawn Guo | abfafc2 | 2011-06-30 15:44:44 +0800 | [diff] [blame] | 124 | { /* sentinel */ } |
| 125 | }; |
| 126 | MODULE_DEVICE_TABLE(of, imx_esdhc_dt_ids); |
| 127 | |
Shawn Guo | 57ed331 | 2011-06-30 09:24:26 +0800 | [diff] [blame] | 128 | static inline int is_imx25_esdhc(struct pltfm_imx_data *data) |
| 129 | { |
| 130 | return data->devtype == IMX25_ESDHC; |
| 131 | } |
| 132 | |
| 133 | static inline int is_imx35_esdhc(struct pltfm_imx_data *data) |
| 134 | { |
| 135 | return data->devtype == IMX35_ESDHC; |
| 136 | } |
| 137 | |
| 138 | static inline int is_imx51_esdhc(struct pltfm_imx_data *data) |
| 139 | { |
| 140 | return data->devtype == IMX51_ESDHC; |
| 141 | } |
| 142 | |
| 143 | static inline int is_imx53_esdhc(struct pltfm_imx_data *data) |
| 144 | { |
| 145 | return data->devtype == IMX53_ESDHC; |
| 146 | } |
| 147 | |
Shawn Guo | 95a2482 | 2011-09-19 17:32:21 +0800 | [diff] [blame] | 148 | static inline int is_imx6q_usdhc(struct pltfm_imx_data *data) |
| 149 | { |
| 150 | return data->devtype == IMX6Q_USDHC; |
| 151 | } |
| 152 | |
Wolfram Sang | 95f25ef | 2010-10-15 12:21:04 +0200 | [diff] [blame] | 153 | static inline void esdhc_clrset_le(struct sdhci_host *host, u32 mask, u32 val, int reg) |
| 154 | { |
| 155 | void __iomem *base = host->ioaddr + (reg & ~0x3); |
| 156 | u32 shift = (reg & 0x3) * 8; |
| 157 | |
| 158 | writel(((readl(base) & ~(mask << shift)) | (val << shift)), base); |
| 159 | } |
| 160 | |
Wolfram Sang | 7e29c30 | 2011-02-26 14:44:41 +0100 | [diff] [blame] | 161 | static u32 esdhc_readl_le(struct sdhci_host *host, int reg) |
| 162 | { |
Lucas Stach | 361b848 | 2013-03-15 09:49:26 +0100 | [diff] [blame] | 163 | struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host); |
| 164 | struct pltfm_imx_data *imx_data = pltfm_host->priv; |
Wolfram Sang | 7e29c30 | 2011-02-26 14:44:41 +0100 | [diff] [blame] | 165 | u32 val = readl(host->ioaddr + reg); |
| 166 | |
Richard Zhu | 97e4ba6 | 2011-08-11 16:51:46 -0400 | [diff] [blame] | 167 | if (unlikely(reg == SDHCI_CAPABILITIES)) { |
| 168 | /* In FSL esdhc IC module, only bit20 is used to indicate the |
| 169 | * ADMA2 capability of esdhc, but this bit is messed up on |
| 170 | * some SOCs (e.g. on MX25, MX35 this bit is set, but they |
| 171 | * don't actually support ADMA2). So set the BROKEN_ADMA |
| 172 | * uirk on MX25/35 platforms. |
| 173 | */ |
| 174 | |
| 175 | if (val & SDHCI_CAN_DO_ADMA1) { |
| 176 | val &= ~SDHCI_CAN_DO_ADMA1; |
| 177 | val |= SDHCI_CAN_DO_ADMA2; |
| 178 | } |
| 179 | } |
| 180 | |
| 181 | if (unlikely(reg == SDHCI_INT_STATUS)) { |
Shawn Guo | 60bf639 | 2013-01-15 23:36:53 +0800 | [diff] [blame] | 182 | if (val & ESDHC_INT_VENDOR_SPEC_DMA_ERR) { |
| 183 | val &= ~ESDHC_INT_VENDOR_SPEC_DMA_ERR; |
Richard Zhu | 97e4ba6 | 2011-08-11 16:51:46 -0400 | [diff] [blame] | 184 | val |= SDHCI_INT_ADMA_ERROR; |
| 185 | } |
Lucas Stach | 361b848 | 2013-03-15 09:49:26 +0100 | [diff] [blame] | 186 | |
| 187 | /* |
| 188 | * mask off the interrupt we get in response to the manually |
| 189 | * sent CMD12 |
| 190 | */ |
| 191 | if ((imx_data->multiblock_status == WAIT_FOR_INT) && |
| 192 | ((val & SDHCI_INT_RESPONSE) == SDHCI_INT_RESPONSE)) { |
| 193 | val &= ~SDHCI_INT_RESPONSE; |
| 194 | writel(SDHCI_INT_RESPONSE, host->ioaddr + |
| 195 | SDHCI_INT_STATUS); |
| 196 | imx_data->multiblock_status = NO_CMD_PENDING; |
| 197 | } |
Richard Zhu | 97e4ba6 | 2011-08-11 16:51:46 -0400 | [diff] [blame] | 198 | } |
| 199 | |
Wolfram Sang | 7e29c30 | 2011-02-26 14:44:41 +0100 | [diff] [blame] | 200 | return val; |
| 201 | } |
| 202 | |
| 203 | static void esdhc_writel_le(struct sdhci_host *host, u32 val, int reg) |
| 204 | { |
Richard Zhu | e149860 | 2011-03-25 09:18:27 -0400 | [diff] [blame] | 205 | struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host); |
| 206 | struct pltfm_imx_data *imx_data = pltfm_host->priv; |
Tony Lin | 0d58864 | 2011-08-11 16:45:59 -0400 | [diff] [blame] | 207 | u32 data; |
Richard Zhu | e149860 | 2011-03-25 09:18:27 -0400 | [diff] [blame] | 208 | |
Tony Lin | 0d58864 | 2011-08-11 16:45:59 -0400 | [diff] [blame] | 209 | if (unlikely(reg == SDHCI_INT_ENABLE || reg == SDHCI_SIGNAL_ENABLE)) { |
Tony Lin | 0d58864 | 2011-08-11 16:45:59 -0400 | [diff] [blame] | 210 | if (val & SDHCI_INT_CARD_INT) { |
| 211 | /* |
| 212 | * Clear and then set D3CD bit to avoid missing the |
| 213 | * card interrupt. This is a eSDHC controller problem |
| 214 | * so we need to apply the following workaround: clear |
| 215 | * and set D3CD bit will make eSDHC re-sample the card |
| 216 | * interrupt. In case a card interrupt was lost, |
| 217 | * re-sample it by the following steps. |
| 218 | */ |
| 219 | data = readl(host->ioaddr + SDHCI_HOST_CONTROL); |
Shawn Guo | 60bf639 | 2013-01-15 23:36:53 +0800 | [diff] [blame] | 220 | data &= ~ESDHC_CTRL_D3CD; |
Tony Lin | 0d58864 | 2011-08-11 16:45:59 -0400 | [diff] [blame] | 221 | writel(data, host->ioaddr + SDHCI_HOST_CONTROL); |
Shawn Guo | 60bf639 | 2013-01-15 23:36:53 +0800 | [diff] [blame] | 222 | data |= ESDHC_CTRL_D3CD; |
Tony Lin | 0d58864 | 2011-08-11 16:45:59 -0400 | [diff] [blame] | 223 | writel(data, host->ioaddr + SDHCI_HOST_CONTROL); |
| 224 | } |
| 225 | } |
Wolfram Sang | 7e29c30 | 2011-02-26 14:44:41 +0100 | [diff] [blame] | 226 | |
Richard Zhu | 58ac817 | 2011-03-21 13:22:16 +0800 | [diff] [blame] | 227 | if (unlikely((imx_data->flags & ESDHC_FLAG_MULTIBLK_NO_INT) |
| 228 | && (reg == SDHCI_INT_STATUS) |
| 229 | && (val & SDHCI_INT_DATA_END))) { |
| 230 | u32 v; |
Shawn Guo | 60bf639 | 2013-01-15 23:36:53 +0800 | [diff] [blame] | 231 | v = readl(host->ioaddr + ESDHC_VENDOR_SPEC); |
| 232 | v &= ~ESDHC_VENDOR_SPEC_SDIO_QUIRK; |
| 233 | writel(v, host->ioaddr + ESDHC_VENDOR_SPEC); |
Lucas Stach | 361b848 | 2013-03-15 09:49:26 +0100 | [diff] [blame] | 234 | |
| 235 | if (imx_data->multiblock_status == MULTIBLK_IN_PROCESS) |
| 236 | { |
| 237 | /* send a manual CMD12 with RESPTYP=none */ |
| 238 | data = MMC_STOP_TRANSMISSION << 24 | |
| 239 | SDHCI_CMD_ABORTCMD << 16; |
| 240 | writel(data, host->ioaddr + SDHCI_TRANSFER_MODE); |
| 241 | imx_data->multiblock_status = WAIT_FOR_INT; |
| 242 | } |
Richard Zhu | 58ac817 | 2011-03-21 13:22:16 +0800 | [diff] [blame] | 243 | } |
| 244 | |
Richard Zhu | 97e4ba6 | 2011-08-11 16:51:46 -0400 | [diff] [blame] | 245 | if (unlikely(reg == SDHCI_INT_ENABLE || reg == SDHCI_SIGNAL_ENABLE)) { |
| 246 | if (val & SDHCI_INT_ADMA_ERROR) { |
| 247 | val &= ~SDHCI_INT_ADMA_ERROR; |
Shawn Guo | 60bf639 | 2013-01-15 23:36:53 +0800 | [diff] [blame] | 248 | val |= ESDHC_INT_VENDOR_SPEC_DMA_ERR; |
Richard Zhu | 97e4ba6 | 2011-08-11 16:51:46 -0400 | [diff] [blame] | 249 | } |
| 250 | } |
| 251 | |
Wolfram Sang | 7e29c30 | 2011-02-26 14:44:41 +0100 | [diff] [blame] | 252 | writel(val, host->ioaddr + reg); |
| 253 | } |
| 254 | |
Wolfram Sang | 95f25ef | 2010-10-15 12:21:04 +0200 | [diff] [blame] | 255 | static u16 esdhc_readw_le(struct sdhci_host *host, int reg) |
| 256 | { |
Shawn Guo | ef4d088 | 2013-01-15 23:30:27 +0800 | [diff] [blame] | 257 | struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host); |
| 258 | struct pltfm_imx_data *imx_data = pltfm_host->priv; |
| 259 | |
Shawn Guo | 95a2482 | 2011-09-19 17:32:21 +0800 | [diff] [blame] | 260 | if (unlikely(reg == SDHCI_HOST_VERSION)) { |
Shawn Guo | ef4d088 | 2013-01-15 23:30:27 +0800 | [diff] [blame] | 261 | reg ^= 2; |
| 262 | if (is_imx6q_usdhc(imx_data)) { |
| 263 | /* |
| 264 | * The usdhc register returns a wrong host version. |
| 265 | * Correct it here. |
| 266 | */ |
| 267 | return SDHCI_SPEC_300; |
| 268 | } |
Shawn Guo | 95a2482 | 2011-09-19 17:32:21 +0800 | [diff] [blame] | 269 | } |
Wolfram Sang | 95f25ef | 2010-10-15 12:21:04 +0200 | [diff] [blame] | 270 | |
| 271 | return readw(host->ioaddr + reg); |
| 272 | } |
| 273 | |
| 274 | static void esdhc_writew_le(struct sdhci_host *host, u16 val, int reg) |
| 275 | { |
| 276 | struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host); |
Richard Zhu | e149860 | 2011-03-25 09:18:27 -0400 | [diff] [blame] | 277 | struct pltfm_imx_data *imx_data = pltfm_host->priv; |
Wolfram Sang | 95f25ef | 2010-10-15 12:21:04 +0200 | [diff] [blame] | 278 | |
| 279 | switch (reg) { |
| 280 | case SDHCI_TRANSFER_MODE: |
Richard Zhu | 58ac817 | 2011-03-21 13:22:16 +0800 | [diff] [blame] | 281 | if ((imx_data->flags & ESDHC_FLAG_MULTIBLK_NO_INT) |
| 282 | && (host->cmd->opcode == SD_IO_RW_EXTENDED) |
| 283 | && (host->cmd->data->blocks > 1) |
| 284 | && (host->cmd->data->flags & MMC_DATA_READ)) { |
| 285 | u32 v; |
Shawn Guo | 60bf639 | 2013-01-15 23:36:53 +0800 | [diff] [blame] | 286 | v = readl(host->ioaddr + ESDHC_VENDOR_SPEC); |
| 287 | v |= ESDHC_VENDOR_SPEC_SDIO_QUIRK; |
| 288 | writel(v, host->ioaddr + ESDHC_VENDOR_SPEC); |
Richard Zhu | 58ac817 | 2011-03-21 13:22:16 +0800 | [diff] [blame] | 289 | } |
Shawn Guo | 69f5469 | 2013-01-21 19:02:24 +0800 | [diff] [blame] | 290 | |
| 291 | if (is_imx6q_usdhc(imx_data)) { |
| 292 | u32 m = readl(host->ioaddr + ESDHC_MIX_CTRL); |
Shawn Guo | 2a15f98 | 2013-01-21 19:02:26 +0800 | [diff] [blame] | 293 | /* Swap AC23 bit */ |
| 294 | if (val & SDHCI_TRNS_AUTO_CMD23) { |
| 295 | val &= ~SDHCI_TRNS_AUTO_CMD23; |
| 296 | val |= ESDHC_MIX_CTRL_AC23EN; |
| 297 | } |
| 298 | m = val | (m & ~ESDHC_MIX_CTRL_SDHCI_MASK); |
Shawn Guo | 69f5469 | 2013-01-21 19:02:24 +0800 | [diff] [blame] | 299 | writel(m, host->ioaddr + ESDHC_MIX_CTRL); |
| 300 | } else { |
| 301 | /* |
| 302 | * Postpone this write, we must do it together with a |
| 303 | * command write that is down below. |
| 304 | */ |
| 305 | imx_data->scratchpad = val; |
| 306 | } |
Wolfram Sang | 95f25ef | 2010-10-15 12:21:04 +0200 | [diff] [blame] | 307 | return; |
| 308 | case SDHCI_COMMAND: |
Lucas Stach | 361b848 | 2013-03-15 09:49:26 +0100 | [diff] [blame] | 309 | if (host->cmd->opcode == MMC_STOP_TRANSMISSION) |
Richard Zhu | 58ac817 | 2011-03-21 13:22:16 +0800 | [diff] [blame] | 310 | val |= SDHCI_CMD_ABORTCMD; |
Shawn Guo | 95a2482 | 2011-09-19 17:32:21 +0800 | [diff] [blame] | 311 | |
Lucas Stach | 361b848 | 2013-03-15 09:49:26 +0100 | [diff] [blame] | 312 | if ((host->cmd->opcode == MMC_SET_BLOCK_COUNT) && |
| 313 | (imx_data->flags & ESDHC_FLAG_MULTIBLK_NO_INT)) |
| 314 | imx_data->multiblock_status = MULTIBLK_IN_PROCESS; |
| 315 | |
Shawn Guo | 69f5469 | 2013-01-21 19:02:24 +0800 | [diff] [blame] | 316 | if (is_imx6q_usdhc(imx_data)) |
Shawn Guo | 95a2482 | 2011-09-19 17:32:21 +0800 | [diff] [blame] | 317 | writel(val << 16, |
| 318 | host->ioaddr + SDHCI_TRANSFER_MODE); |
Shawn Guo | 69f5469 | 2013-01-21 19:02:24 +0800 | [diff] [blame] | 319 | else |
Shawn Guo | 95a2482 | 2011-09-19 17:32:21 +0800 | [diff] [blame] | 320 | writel(val << 16 | imx_data->scratchpad, |
| 321 | host->ioaddr + SDHCI_TRANSFER_MODE); |
Wolfram Sang | 95f25ef | 2010-10-15 12:21:04 +0200 | [diff] [blame] | 322 | return; |
| 323 | case SDHCI_BLOCK_SIZE: |
| 324 | val &= ~SDHCI_MAKE_BLKSZ(0x7, 0); |
| 325 | break; |
| 326 | } |
| 327 | esdhc_clrset_le(host, 0xffff, val, reg); |
| 328 | } |
| 329 | |
| 330 | static void esdhc_writeb_le(struct sdhci_host *host, u8 val, int reg) |
| 331 | { |
Wilson Callan | 9a0985b | 2012-07-19 02:49:16 -0400 | [diff] [blame] | 332 | struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host); |
| 333 | struct pltfm_imx_data *imx_data = pltfm_host->priv; |
Wolfram Sang | 95f25ef | 2010-10-15 12:21:04 +0200 | [diff] [blame] | 334 | u32 new_val; |
Sascha Hauer | af51079 | 2013-01-21 19:02:28 +0800 | [diff] [blame] | 335 | u32 mask; |
Wolfram Sang | 95f25ef | 2010-10-15 12:21:04 +0200 | [diff] [blame] | 336 | |
| 337 | switch (reg) { |
| 338 | case SDHCI_POWER_CONTROL: |
| 339 | /* |
| 340 | * FSL put some DMA bits here |
| 341 | * If your board has a regulator, code should be here |
| 342 | */ |
| 343 | return; |
| 344 | case SDHCI_HOST_CONTROL: |
Shawn Guo | 6b40d18 | 2013-01-15 23:36:52 +0800 | [diff] [blame] | 345 | /* FSL messed up here, so we need to manually compose it. */ |
Sascha Hauer | af51079 | 2013-01-21 19:02:28 +0800 | [diff] [blame] | 346 | new_val = val & SDHCI_CTRL_LED; |
Masanari Iida | 7122bbb | 2012-08-05 23:25:40 +0900 | [diff] [blame] | 347 | /* ensure the endianness */ |
Wolfram Sang | 95f25ef | 2010-10-15 12:21:04 +0200 | [diff] [blame] | 348 | new_val |= ESDHC_HOST_CONTROL_LE; |
Wilson Callan | 9a0985b | 2012-07-19 02:49:16 -0400 | [diff] [blame] | 349 | /* bits 8&9 are reserved on mx25 */ |
| 350 | if (!is_imx25_esdhc(imx_data)) { |
| 351 | /* DMA mode bits are shifted */ |
| 352 | new_val |= (val & SDHCI_CTRL_DMA_MASK) << 5; |
| 353 | } |
Wolfram Sang | 95f25ef | 2010-10-15 12:21:04 +0200 | [diff] [blame] | 354 | |
Sascha Hauer | af51079 | 2013-01-21 19:02:28 +0800 | [diff] [blame] | 355 | /* |
| 356 | * Do not touch buswidth bits here. This is done in |
| 357 | * esdhc_pltfm_bus_width. |
Martin Fuzzey | f682574 | 2013-04-15 17:08:35 +0200 | [diff] [blame] | 358 | * Do not touch the D3CD bit either which is used for the |
| 359 | * SDIO interrupt errata workaround. |
Sascha Hauer | af51079 | 2013-01-21 19:02:28 +0800 | [diff] [blame] | 360 | */ |
Martin Fuzzey | f682574 | 2013-04-15 17:08:35 +0200 | [diff] [blame] | 361 | mask = 0xffff & ~(ESDHC_CTRL_BUSWIDTH_MASK | ESDHC_CTRL_D3CD); |
Sascha Hauer | af51079 | 2013-01-21 19:02:28 +0800 | [diff] [blame] | 362 | |
| 363 | esdhc_clrset_le(host, mask, new_val, reg); |
Wolfram Sang | 95f25ef | 2010-10-15 12:21:04 +0200 | [diff] [blame] | 364 | return; |
| 365 | } |
| 366 | esdhc_clrset_le(host, 0xff, val, reg); |
Shawn Guo | 913413c | 2011-06-21 22:41:51 +0800 | [diff] [blame] | 367 | |
| 368 | /* |
| 369 | * The esdhc has a design violation to SDHC spec which tells |
| 370 | * that software reset should not affect card detection circuit. |
| 371 | * But esdhc clears its SYSCTL register bits [0..2] during the |
| 372 | * software reset. This will stop those clocks that card detection |
| 373 | * circuit relies on. To work around it, we turn the clocks on back |
| 374 | * to keep card detection circuit functional. |
| 375 | */ |
Shawn Guo | 58c8c4f | 2013-01-21 19:02:25 +0800 | [diff] [blame] | 376 | if ((reg == SDHCI_SOFTWARE_RESET) && (val & 1)) { |
Shawn Guo | 913413c | 2011-06-21 22:41:51 +0800 | [diff] [blame] | 377 | esdhc_clrset_le(host, 0x7, 0x7, ESDHC_SYSTEM_CONTROL); |
Shawn Guo | 58c8c4f | 2013-01-21 19:02:25 +0800 | [diff] [blame] | 378 | /* |
| 379 | * The reset on usdhc fails to clear MIX_CTRL register. |
| 380 | * Do it manually here. |
| 381 | */ |
| 382 | if (is_imx6q_usdhc(imx_data)) |
| 383 | writel(0, host->ioaddr + ESDHC_MIX_CTRL); |
| 384 | } |
Wolfram Sang | 95f25ef | 2010-10-15 12:21:04 +0200 | [diff] [blame] | 385 | } |
| 386 | |
Lucas Stach | 0ddf03c | 2013-06-05 15:13:26 +0200 | [diff] [blame] | 387 | static unsigned int esdhc_pltfm_get_max_clock(struct sdhci_host *host) |
| 388 | { |
| 389 | struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host); |
| 390 | struct pltfm_imx_data *imx_data = pltfm_host->priv; |
| 391 | struct esdhc_platform_data *boarddata = &imx_data->boarddata; |
| 392 | |
| 393 | u32 f_host = clk_get_rate(pltfm_host->clk); |
| 394 | |
| 395 | if (boarddata->f_max && (boarddata->f_max < f_host)) |
| 396 | return boarddata->f_max; |
| 397 | else |
| 398 | return f_host; |
| 399 | } |
| 400 | |
Wolfram Sang | 95f25ef | 2010-10-15 12:21:04 +0200 | [diff] [blame] | 401 | static unsigned int esdhc_pltfm_get_min_clock(struct sdhci_host *host) |
| 402 | { |
| 403 | struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host); |
| 404 | |
| 405 | return clk_get_rate(pltfm_host->clk) / 256 / 16; |
| 406 | } |
| 407 | |
Lucas Stach | 8ba9580 | 2013-06-05 15:13:25 +0200 | [diff] [blame] | 408 | static inline void esdhc_pltfm_set_clock(struct sdhci_host *host, |
| 409 | unsigned int clock) |
| 410 | { |
| 411 | struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host); |
Dong Aisheng | d31fc00 | 2013-09-13 19:11:32 +0800 | [diff] [blame^] | 412 | unsigned int host_clock = clk_get_rate(pltfm_host->clk); |
| 413 | int pre_div = 2; |
| 414 | int div = 1; |
| 415 | u32 temp; |
Lucas Stach | 8ba9580 | 2013-06-05 15:13:25 +0200 | [diff] [blame] | 416 | |
Dong Aisheng | d31fc00 | 2013-09-13 19:11:32 +0800 | [diff] [blame^] | 417 | if (clock == 0) |
| 418 | goto out; |
| 419 | |
| 420 | temp = sdhci_readl(host, ESDHC_SYSTEM_CONTROL); |
| 421 | temp &= ~(ESDHC_CLOCK_IPGEN | ESDHC_CLOCK_HCKEN | ESDHC_CLOCK_PEREN |
| 422 | | ESDHC_CLOCK_MASK); |
| 423 | sdhci_writel(host, temp, ESDHC_SYSTEM_CONTROL); |
| 424 | |
| 425 | while (host_clock / pre_div / 16 > clock && pre_div < 256) |
| 426 | pre_div *= 2; |
| 427 | |
| 428 | while (host_clock / pre_div / div > clock && div < 16) |
| 429 | div++; |
| 430 | |
| 431 | dev_dbg(mmc_dev(host->mmc), "desired SD clock: %d, actual: %d\n", |
| 432 | clock, host_clock / pre_div / div); |
| 433 | |
| 434 | pre_div >>= 1; |
| 435 | div--; |
| 436 | |
| 437 | temp = sdhci_readl(host, ESDHC_SYSTEM_CONTROL); |
| 438 | temp |= (ESDHC_CLOCK_IPGEN | ESDHC_CLOCK_HCKEN | ESDHC_CLOCK_PEREN |
| 439 | | (div << ESDHC_DIVIDER_SHIFT) |
| 440 | | (pre_div << ESDHC_PREDIV_SHIFT)); |
| 441 | sdhci_writel(host, temp, ESDHC_SYSTEM_CONTROL); |
| 442 | mdelay(1); |
| 443 | out: |
| 444 | host->clock = clock; |
Lucas Stach | 8ba9580 | 2013-06-05 15:13:25 +0200 | [diff] [blame] | 445 | } |
| 446 | |
Shawn Guo | 913413c | 2011-06-21 22:41:51 +0800 | [diff] [blame] | 447 | static unsigned int esdhc_pltfm_get_ro(struct sdhci_host *host) |
| 448 | { |
Shawn Guo | 842afc0 | 2011-07-06 22:57:48 +0800 | [diff] [blame] | 449 | struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host); |
| 450 | struct pltfm_imx_data *imx_data = pltfm_host->priv; |
| 451 | struct esdhc_platform_data *boarddata = &imx_data->boarddata; |
Shawn Guo | 913413c | 2011-06-21 22:41:51 +0800 | [diff] [blame] | 452 | |
| 453 | switch (boarddata->wp_type) { |
| 454 | case ESDHC_WP_GPIO: |
Shawn Guo | fbe5fdd | 2012-12-11 22:32:20 +0800 | [diff] [blame] | 455 | return mmc_gpio_get_ro(host->mmc); |
Shawn Guo | 913413c | 2011-06-21 22:41:51 +0800 | [diff] [blame] | 456 | case ESDHC_WP_CONTROLLER: |
| 457 | return !(readl(host->ioaddr + SDHCI_PRESENT_STATE) & |
| 458 | SDHCI_WRITE_PROTECT); |
| 459 | case ESDHC_WP_NONE: |
| 460 | break; |
| 461 | } |
| 462 | |
| 463 | return -ENOSYS; |
| 464 | } |
| 465 | |
Sascha Hauer | af51079 | 2013-01-21 19:02:28 +0800 | [diff] [blame] | 466 | static int esdhc_pltfm_bus_width(struct sdhci_host *host, int width) |
| 467 | { |
| 468 | u32 ctrl; |
| 469 | |
| 470 | switch (width) { |
| 471 | case MMC_BUS_WIDTH_8: |
| 472 | ctrl = ESDHC_CTRL_8BITBUS; |
| 473 | break; |
| 474 | case MMC_BUS_WIDTH_4: |
| 475 | ctrl = ESDHC_CTRL_4BITBUS; |
| 476 | break; |
| 477 | default: |
| 478 | ctrl = 0; |
| 479 | break; |
| 480 | } |
| 481 | |
| 482 | esdhc_clrset_le(host, ESDHC_CTRL_BUSWIDTH_MASK, ctrl, |
| 483 | SDHCI_HOST_CONTROL); |
| 484 | |
| 485 | return 0; |
| 486 | } |
| 487 | |
Lars-Peter Clausen | c915568 | 2013-03-13 19:26:05 +0100 | [diff] [blame] | 488 | static const struct sdhci_ops sdhci_esdhc_ops = { |
Richard Zhu | e149860 | 2011-03-25 09:18:27 -0400 | [diff] [blame] | 489 | .read_l = esdhc_readl_le, |
Wolfram Sang | 0c6d49c | 2011-02-26 14:44:39 +0100 | [diff] [blame] | 490 | .read_w = esdhc_readw_le, |
Richard Zhu | e149860 | 2011-03-25 09:18:27 -0400 | [diff] [blame] | 491 | .write_l = esdhc_writel_le, |
Wolfram Sang | 0c6d49c | 2011-02-26 14:44:39 +0100 | [diff] [blame] | 492 | .write_w = esdhc_writew_le, |
| 493 | .write_b = esdhc_writeb_le, |
Lucas Stach | 8ba9580 | 2013-06-05 15:13:25 +0200 | [diff] [blame] | 494 | .set_clock = esdhc_pltfm_set_clock, |
Lucas Stach | 0ddf03c | 2013-06-05 15:13:26 +0200 | [diff] [blame] | 495 | .get_max_clock = esdhc_pltfm_get_max_clock, |
Wolfram Sang | 0c6d49c | 2011-02-26 14:44:39 +0100 | [diff] [blame] | 496 | .get_min_clock = esdhc_pltfm_get_min_clock, |
Shawn Guo | 913413c | 2011-06-21 22:41:51 +0800 | [diff] [blame] | 497 | .get_ro = esdhc_pltfm_get_ro, |
Sascha Hauer | af51079 | 2013-01-21 19:02:28 +0800 | [diff] [blame] | 498 | .platform_bus_width = esdhc_pltfm_bus_width, |
Wolfram Sang | 0c6d49c | 2011-02-26 14:44:39 +0100 | [diff] [blame] | 499 | }; |
| 500 | |
Lars-Peter Clausen | 1db5eeb | 2013-03-13 19:26:03 +0100 | [diff] [blame] | 501 | static const struct sdhci_pltfm_data sdhci_esdhc_imx_pdata = { |
Richard Zhu | 97e4ba6 | 2011-08-11 16:51:46 -0400 | [diff] [blame] | 502 | .quirks = ESDHC_DEFAULT_QUIRKS | SDHCI_QUIRK_NO_HISPD_BIT |
| 503 | | SDHCI_QUIRK_NO_ENDATTR_IN_NOPDESC |
| 504 | | SDHCI_QUIRK_BROKEN_ADMA_ZEROLEN_DESC |
Shawn Guo | 85d6509 | 2011-05-27 23:48:12 +0800 | [diff] [blame] | 505 | | SDHCI_QUIRK_BROKEN_CARD_DETECTION, |
Shawn Guo | 85d6509 | 2011-05-27 23:48:12 +0800 | [diff] [blame] | 506 | .ops = &sdhci_esdhc_ops, |
| 507 | }; |
| 508 | |
Shawn Guo | abfafc2 | 2011-06-30 15:44:44 +0800 | [diff] [blame] | 509 | #ifdef CONFIG_OF |
Bill Pemberton | c3be1ef | 2012-11-19 13:23:06 -0500 | [diff] [blame] | 510 | static int |
Shawn Guo | abfafc2 | 2011-06-30 15:44:44 +0800 | [diff] [blame] | 511 | sdhci_esdhc_imx_probe_dt(struct platform_device *pdev, |
| 512 | struct esdhc_platform_data *boarddata) |
| 513 | { |
| 514 | struct device_node *np = pdev->dev.of_node; |
| 515 | |
| 516 | if (!np) |
| 517 | return -ENODEV; |
| 518 | |
Arnd Bergmann | 7f21779 | 2012-05-13 00:14:24 -0400 | [diff] [blame] | 519 | if (of_get_property(np, "non-removable", NULL)) |
Shawn Guo | abfafc2 | 2011-06-30 15:44:44 +0800 | [diff] [blame] | 520 | boarddata->cd_type = ESDHC_CD_PERMANENT; |
| 521 | |
| 522 | if (of_get_property(np, "fsl,cd-controller", NULL)) |
| 523 | boarddata->cd_type = ESDHC_CD_CONTROLLER; |
| 524 | |
| 525 | if (of_get_property(np, "fsl,wp-controller", NULL)) |
| 526 | boarddata->wp_type = ESDHC_WP_CONTROLLER; |
| 527 | |
| 528 | boarddata->cd_gpio = of_get_named_gpio(np, "cd-gpios", 0); |
| 529 | if (gpio_is_valid(boarddata->cd_gpio)) |
| 530 | boarddata->cd_type = ESDHC_CD_GPIO; |
| 531 | |
| 532 | boarddata->wp_gpio = of_get_named_gpio(np, "wp-gpios", 0); |
| 533 | if (gpio_is_valid(boarddata->wp_gpio)) |
| 534 | boarddata->wp_type = ESDHC_WP_GPIO; |
| 535 | |
Sascha Hauer | af51079 | 2013-01-21 19:02:28 +0800 | [diff] [blame] | 536 | of_property_read_u32(np, "bus-width", &boarddata->max_bus_width); |
| 537 | |
Lucas Stach | 0ddf03c | 2013-06-05 15:13:26 +0200 | [diff] [blame] | 538 | of_property_read_u32(np, "max-frequency", &boarddata->f_max); |
| 539 | |
Shawn Guo | abfafc2 | 2011-06-30 15:44:44 +0800 | [diff] [blame] | 540 | return 0; |
| 541 | } |
| 542 | #else |
| 543 | static inline int |
| 544 | sdhci_esdhc_imx_probe_dt(struct platform_device *pdev, |
| 545 | struct esdhc_platform_data *boarddata) |
| 546 | { |
| 547 | return -ENODEV; |
| 548 | } |
| 549 | #endif |
| 550 | |
Bill Pemberton | c3be1ef | 2012-11-19 13:23:06 -0500 | [diff] [blame] | 551 | static int sdhci_esdhc_imx_probe(struct platform_device *pdev) |
Wolfram Sang | 95f25ef | 2010-10-15 12:21:04 +0200 | [diff] [blame] | 552 | { |
Shawn Guo | abfafc2 | 2011-06-30 15:44:44 +0800 | [diff] [blame] | 553 | const struct of_device_id *of_id = |
| 554 | of_match_device(imx_esdhc_dt_ids, &pdev->dev); |
Shawn Guo | 85d6509 | 2011-05-27 23:48:12 +0800 | [diff] [blame] | 555 | struct sdhci_pltfm_host *pltfm_host; |
| 556 | struct sdhci_host *host; |
| 557 | struct esdhc_platform_data *boarddata; |
Wolfram Sang | 0c6d49c | 2011-02-26 14:44:39 +0100 | [diff] [blame] | 558 | int err; |
Richard Zhu | e149860 | 2011-03-25 09:18:27 -0400 | [diff] [blame] | 559 | struct pltfm_imx_data *imx_data; |
Wolfram Sang | 95f25ef | 2010-10-15 12:21:04 +0200 | [diff] [blame] | 560 | |
Christian Daudt | 0e74823 | 2013-05-29 13:50:05 -0700 | [diff] [blame] | 561 | host = sdhci_pltfm_init(pdev, &sdhci_esdhc_imx_pdata, 0); |
Shawn Guo | 85d6509 | 2011-05-27 23:48:12 +0800 | [diff] [blame] | 562 | if (IS_ERR(host)) |
| 563 | return PTR_ERR(host); |
| 564 | |
| 565 | pltfm_host = sdhci_priv(host); |
| 566 | |
Shawn Guo | e3af31c | 2012-11-26 14:39:43 +0800 | [diff] [blame] | 567 | imx_data = devm_kzalloc(&pdev->dev, sizeof(*imx_data), GFP_KERNEL); |
Shawn Guo | abfafc2 | 2011-06-30 15:44:44 +0800 | [diff] [blame] | 568 | if (!imx_data) { |
| 569 | err = -ENOMEM; |
Shawn Guo | e3af31c | 2012-11-26 14:39:43 +0800 | [diff] [blame] | 570 | goto free_sdhci; |
Shawn Guo | abfafc2 | 2011-06-30 15:44:44 +0800 | [diff] [blame] | 571 | } |
Shawn Guo | 57ed331 | 2011-06-30 09:24:26 +0800 | [diff] [blame] | 572 | |
Shawn Guo | abfafc2 | 2011-06-30 15:44:44 +0800 | [diff] [blame] | 573 | if (of_id) |
| 574 | pdev->id_entry = of_id->data; |
Shawn Guo | 57ed331 | 2011-06-30 09:24:26 +0800 | [diff] [blame] | 575 | imx_data->devtype = pdev->id_entry->driver_data; |
Shawn Guo | 85d6509 | 2011-05-27 23:48:12 +0800 | [diff] [blame] | 576 | pltfm_host->priv = imx_data; |
| 577 | |
Sascha Hauer | 52dac61 | 2012-03-07 09:31:34 +0100 | [diff] [blame] | 578 | imx_data->clk_ipg = devm_clk_get(&pdev->dev, "ipg"); |
| 579 | if (IS_ERR(imx_data->clk_ipg)) { |
| 580 | err = PTR_ERR(imx_data->clk_ipg); |
Shawn Guo | e3af31c | 2012-11-26 14:39:43 +0800 | [diff] [blame] | 581 | goto free_sdhci; |
Wolfram Sang | 95f25ef | 2010-10-15 12:21:04 +0200 | [diff] [blame] | 582 | } |
Sascha Hauer | 52dac61 | 2012-03-07 09:31:34 +0100 | [diff] [blame] | 583 | |
| 584 | imx_data->clk_ahb = devm_clk_get(&pdev->dev, "ahb"); |
| 585 | if (IS_ERR(imx_data->clk_ahb)) { |
| 586 | err = PTR_ERR(imx_data->clk_ahb); |
Shawn Guo | e3af31c | 2012-11-26 14:39:43 +0800 | [diff] [blame] | 587 | goto free_sdhci; |
Sascha Hauer | 52dac61 | 2012-03-07 09:31:34 +0100 | [diff] [blame] | 588 | } |
| 589 | |
| 590 | imx_data->clk_per = devm_clk_get(&pdev->dev, "per"); |
| 591 | if (IS_ERR(imx_data->clk_per)) { |
| 592 | err = PTR_ERR(imx_data->clk_per); |
Shawn Guo | e3af31c | 2012-11-26 14:39:43 +0800 | [diff] [blame] | 593 | goto free_sdhci; |
Sascha Hauer | 52dac61 | 2012-03-07 09:31:34 +0100 | [diff] [blame] | 594 | } |
| 595 | |
| 596 | pltfm_host->clk = imx_data->clk_per; |
| 597 | |
| 598 | clk_prepare_enable(imx_data->clk_per); |
| 599 | clk_prepare_enable(imx_data->clk_ipg); |
| 600 | clk_prepare_enable(imx_data->clk_ahb); |
Wolfram Sang | 95f25ef | 2010-10-15 12:21:04 +0200 | [diff] [blame] | 601 | |
Dong Aisheng | e62d8b8 | 2012-05-11 14:56:01 +0800 | [diff] [blame] | 602 | imx_data->pinctrl = devm_pinctrl_get_select_default(&pdev->dev); |
| 603 | if (IS_ERR(imx_data->pinctrl)) { |
| 604 | err = PTR_ERR(imx_data->pinctrl); |
Shawn Guo | e3af31c | 2012-11-26 14:39:43 +0800 | [diff] [blame] | 605 | goto disable_clk; |
Dong Aisheng | e62d8b8 | 2012-05-11 14:56:01 +0800 | [diff] [blame] | 606 | } |
| 607 | |
Eric BĂ©nard | b8915282 | 2012-04-18 02:30:20 +0200 | [diff] [blame] | 608 | host->quirks |= SDHCI_QUIRK_BROKEN_TIMEOUT_VAL; |
Eric BĂ©nard | 37865fe | 2010-10-23 01:57:21 +0200 | [diff] [blame] | 609 | |
Shawn Guo | 57ed331 | 2011-06-30 09:24:26 +0800 | [diff] [blame] | 610 | if (is_imx25_esdhc(imx_data) || is_imx35_esdhc(imx_data)) |
Wolfram Sang | 0c6d49c | 2011-02-26 14:44:39 +0100 | [diff] [blame] | 611 | /* Fix errata ENGcm07207 present on i.MX25 and i.MX35 */ |
Richard Zhu | 97e4ba6 | 2011-08-11 16:51:46 -0400 | [diff] [blame] | 612 | host->quirks |= SDHCI_QUIRK_NO_MULTIBLOCK |
| 613 | | SDHCI_QUIRK_BROKEN_ADMA; |
Wolfram Sang | 0c6d49c | 2011-02-26 14:44:39 +0100 | [diff] [blame] | 614 | |
Shawn Guo | 57ed331 | 2011-06-30 09:24:26 +0800 | [diff] [blame] | 615 | if (is_imx53_esdhc(imx_data)) |
Richard Zhu | 58ac817 | 2011-03-21 13:22:16 +0800 | [diff] [blame] | 616 | imx_data->flags |= ESDHC_FLAG_MULTIBLK_NO_INT; |
| 617 | |
Shawn Guo | f750ba9 | 2011-11-10 16:39:32 +0800 | [diff] [blame] | 618 | /* |
| 619 | * The imx6q ROM code will change the default watermark level setting |
| 620 | * to something insane. Change it back here. |
| 621 | */ |
| 622 | if (is_imx6q_usdhc(imx_data)) |
Shawn Guo | 60bf639 | 2013-01-15 23:36:53 +0800 | [diff] [blame] | 623 | writel(0x08100810, host->ioaddr + ESDHC_WTMK_LVL); |
Shawn Guo | f750ba9 | 2011-11-10 16:39:32 +0800 | [diff] [blame] | 624 | |
Shawn Guo | 842afc0 | 2011-07-06 22:57:48 +0800 | [diff] [blame] | 625 | boarddata = &imx_data->boarddata; |
Shawn Guo | abfafc2 | 2011-06-30 15:44:44 +0800 | [diff] [blame] | 626 | if (sdhci_esdhc_imx_probe_dt(pdev, boarddata) < 0) { |
| 627 | if (!host->mmc->parent->platform_data) { |
| 628 | dev_err(mmc_dev(host->mmc), "no board data!\n"); |
| 629 | err = -EINVAL; |
Shawn Guo | e3af31c | 2012-11-26 14:39:43 +0800 | [diff] [blame] | 630 | goto disable_clk; |
Shawn Guo | abfafc2 | 2011-06-30 15:44:44 +0800 | [diff] [blame] | 631 | } |
| 632 | imx_data->boarddata = *((struct esdhc_platform_data *) |
| 633 | host->mmc->parent->platform_data); |
| 634 | } |
Shawn Guo | 913413c | 2011-06-21 22:41:51 +0800 | [diff] [blame] | 635 | |
| 636 | /* write_protect */ |
| 637 | if (boarddata->wp_type == ESDHC_WP_GPIO) { |
Shawn Guo | fbe5fdd | 2012-12-11 22:32:20 +0800 | [diff] [blame] | 638 | err = mmc_gpio_request_ro(host->mmc, boarddata->wp_gpio); |
Wolfram Sang | 0c6d49c | 2011-02-26 14:44:39 +0100 | [diff] [blame] | 639 | if (err) { |
Shawn Guo | fbe5fdd | 2012-12-11 22:32:20 +0800 | [diff] [blame] | 640 | dev_err(mmc_dev(host->mmc), |
| 641 | "failed to request write-protect gpio!\n"); |
| 642 | goto disable_clk; |
Wolfram Sang | 0c6d49c | 2011-02-26 14:44:39 +0100 | [diff] [blame] | 643 | } |
Shawn Guo | fbe5fdd | 2012-12-11 22:32:20 +0800 | [diff] [blame] | 644 | host->mmc->caps2 |= MMC_CAP2_RO_ACTIVE_HIGH; |
Shawn Guo | 913413c | 2011-06-21 22:41:51 +0800 | [diff] [blame] | 645 | } |
Wolfram Sang | 7e29c30 | 2011-02-26 14:44:41 +0100 | [diff] [blame] | 646 | |
Shawn Guo | 913413c | 2011-06-21 22:41:51 +0800 | [diff] [blame] | 647 | /* card_detect */ |
Shawn Guo | 913413c | 2011-06-21 22:41:51 +0800 | [diff] [blame] | 648 | switch (boarddata->cd_type) { |
| 649 | case ESDHC_CD_GPIO: |
Laurent Pinchart | 214fc30 | 2013-08-08 12:38:31 +0200 | [diff] [blame] | 650 | err = mmc_gpio_request_cd(host->mmc, boarddata->cd_gpio, 0); |
Wolfram Sang | 7e29c30 | 2011-02-26 14:44:41 +0100 | [diff] [blame] | 651 | if (err) { |
Shawn Guo | 913413c | 2011-06-21 22:41:51 +0800 | [diff] [blame] | 652 | dev_err(mmc_dev(host->mmc), |
Shawn Guo | fbe5fdd | 2012-12-11 22:32:20 +0800 | [diff] [blame] | 653 | "failed to request card-detect gpio!\n"); |
Shawn Guo | e3af31c | 2012-11-26 14:39:43 +0800 | [diff] [blame] | 654 | goto disable_clk; |
Wolfram Sang | 7e29c30 | 2011-02-26 14:44:41 +0100 | [diff] [blame] | 655 | } |
Shawn Guo | 913413c | 2011-06-21 22:41:51 +0800 | [diff] [blame] | 656 | /* fall through */ |
Wolfram Sang | 7e29c30 | 2011-02-26 14:44:41 +0100 | [diff] [blame] | 657 | |
Shawn Guo | 913413c | 2011-06-21 22:41:51 +0800 | [diff] [blame] | 658 | case ESDHC_CD_CONTROLLER: |
| 659 | /* we have a working card_detect back */ |
Wolfram Sang | 7e29c30 | 2011-02-26 14:44:41 +0100 | [diff] [blame] | 660 | host->quirks &= ~SDHCI_QUIRK_BROKEN_CARD_DETECTION; |
Shawn Guo | 913413c | 2011-06-21 22:41:51 +0800 | [diff] [blame] | 661 | break; |
| 662 | |
| 663 | case ESDHC_CD_PERMANENT: |
| 664 | host->mmc->caps = MMC_CAP_NONREMOVABLE; |
| 665 | break; |
| 666 | |
| 667 | case ESDHC_CD_NONE: |
| 668 | break; |
Wolfram Sang | 0c6d49c | 2011-02-26 14:44:39 +0100 | [diff] [blame] | 669 | } |
Eric BĂ©nard | 16a790b | 2010-10-23 01:57:22 +0200 | [diff] [blame] | 670 | |
Sascha Hauer | af51079 | 2013-01-21 19:02:28 +0800 | [diff] [blame] | 671 | switch (boarddata->max_bus_width) { |
| 672 | case 8: |
| 673 | host->mmc->caps |= MMC_CAP_8_BIT_DATA | MMC_CAP_4_BIT_DATA; |
| 674 | break; |
| 675 | case 4: |
| 676 | host->mmc->caps |= MMC_CAP_4_BIT_DATA; |
| 677 | break; |
| 678 | case 1: |
| 679 | default: |
| 680 | host->quirks |= SDHCI_QUIRK_FORCE_1_BIT_DATA; |
| 681 | break; |
| 682 | } |
| 683 | |
Shawn Guo | 85d6509 | 2011-05-27 23:48:12 +0800 | [diff] [blame] | 684 | err = sdhci_add_host(host); |
| 685 | if (err) |
Shawn Guo | e3af31c | 2012-11-26 14:39:43 +0800 | [diff] [blame] | 686 | goto disable_clk; |
Shawn Guo | 85d6509 | 2011-05-27 23:48:12 +0800 | [diff] [blame] | 687 | |
Wolfram Sang | 95f25ef | 2010-10-15 12:21:04 +0200 | [diff] [blame] | 688 | return 0; |
Wolfram Sang | 7e29c30 | 2011-02-26 14:44:41 +0100 | [diff] [blame] | 689 | |
Shawn Guo | e3af31c | 2012-11-26 14:39:43 +0800 | [diff] [blame] | 690 | disable_clk: |
Sascha Hauer | 52dac61 | 2012-03-07 09:31:34 +0100 | [diff] [blame] | 691 | clk_disable_unprepare(imx_data->clk_per); |
| 692 | clk_disable_unprepare(imx_data->clk_ipg); |
| 693 | clk_disable_unprepare(imx_data->clk_ahb); |
Shawn Guo | e3af31c | 2012-11-26 14:39:43 +0800 | [diff] [blame] | 694 | free_sdhci: |
Shawn Guo | 85d6509 | 2011-05-27 23:48:12 +0800 | [diff] [blame] | 695 | sdhci_pltfm_free(pdev); |
| 696 | return err; |
Wolfram Sang | 95f25ef | 2010-10-15 12:21:04 +0200 | [diff] [blame] | 697 | } |
| 698 | |
Bill Pemberton | 6e0ee71 | 2012-11-19 13:26:03 -0500 | [diff] [blame] | 699 | static int sdhci_esdhc_imx_remove(struct platform_device *pdev) |
Wolfram Sang | 95f25ef | 2010-10-15 12:21:04 +0200 | [diff] [blame] | 700 | { |
Shawn Guo | 85d6509 | 2011-05-27 23:48:12 +0800 | [diff] [blame] | 701 | struct sdhci_host *host = platform_get_drvdata(pdev); |
Wolfram Sang | 95f25ef | 2010-10-15 12:21:04 +0200 | [diff] [blame] | 702 | struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host); |
Richard Zhu | e149860 | 2011-03-25 09:18:27 -0400 | [diff] [blame] | 703 | struct pltfm_imx_data *imx_data = pltfm_host->priv; |
Shawn Guo | 85d6509 | 2011-05-27 23:48:12 +0800 | [diff] [blame] | 704 | int dead = (readl(host->ioaddr + SDHCI_INT_STATUS) == 0xffffffff); |
| 705 | |
| 706 | sdhci_remove_host(host, dead); |
Wolfram Sang | 0c6d49c | 2011-02-26 14:44:39 +0100 | [diff] [blame] | 707 | |
Sascha Hauer | 52dac61 | 2012-03-07 09:31:34 +0100 | [diff] [blame] | 708 | clk_disable_unprepare(imx_data->clk_per); |
| 709 | clk_disable_unprepare(imx_data->clk_ipg); |
| 710 | clk_disable_unprepare(imx_data->clk_ahb); |
| 711 | |
Shawn Guo | 85d6509 | 2011-05-27 23:48:12 +0800 | [diff] [blame] | 712 | sdhci_pltfm_free(pdev); |
| 713 | |
| 714 | return 0; |
Wolfram Sang | 95f25ef | 2010-10-15 12:21:04 +0200 | [diff] [blame] | 715 | } |
| 716 | |
Shawn Guo | 85d6509 | 2011-05-27 23:48:12 +0800 | [diff] [blame] | 717 | static struct platform_driver sdhci_esdhc_imx_driver = { |
| 718 | .driver = { |
| 719 | .name = "sdhci-esdhc-imx", |
| 720 | .owner = THIS_MODULE, |
Shawn Guo | abfafc2 | 2011-06-30 15:44:44 +0800 | [diff] [blame] | 721 | .of_match_table = imx_esdhc_dt_ids, |
Manuel Lauss | 29495aa | 2011-11-03 11:09:45 +0100 | [diff] [blame] | 722 | .pm = SDHCI_PLTFM_PMOPS, |
Shawn Guo | 85d6509 | 2011-05-27 23:48:12 +0800 | [diff] [blame] | 723 | }, |
Shawn Guo | 57ed331 | 2011-06-30 09:24:26 +0800 | [diff] [blame] | 724 | .id_table = imx_esdhc_devtype, |
Shawn Guo | 85d6509 | 2011-05-27 23:48:12 +0800 | [diff] [blame] | 725 | .probe = sdhci_esdhc_imx_probe, |
Bill Pemberton | 0433c14 | 2012-11-19 13:20:26 -0500 | [diff] [blame] | 726 | .remove = sdhci_esdhc_imx_remove, |
Wolfram Sang | 95f25ef | 2010-10-15 12:21:04 +0200 | [diff] [blame] | 727 | }; |
Shawn Guo | 85d6509 | 2011-05-27 23:48:12 +0800 | [diff] [blame] | 728 | |
Axel Lin | d1f81a6 | 2011-11-26 12:55:43 +0800 | [diff] [blame] | 729 | module_platform_driver(sdhci_esdhc_imx_driver); |
Shawn Guo | 85d6509 | 2011-05-27 23:48:12 +0800 | [diff] [blame] | 730 | |
| 731 | MODULE_DESCRIPTION("SDHCI driver for Freescale i.MX eSDHC"); |
| 732 | MODULE_AUTHOR("Wolfram Sang <w.sang@pengutronix.de>"); |
| 733 | MODULE_LICENSE("GPL v2"); |