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