Pete Popov | ba264b3 | 2005-09-21 06:18:27 +0000 | [diff] [blame] | 1 | /* |
Pierre Ossman | 70f1048 | 2007-07-11 20:04:50 +0200 | [diff] [blame] | 2 | * linux/drivers/mmc/host/au1xmmc.c - AU1XX0 MMC driver |
Pete Popov | ba264b3 | 2005-09-21 06:18:27 +0000 | [diff] [blame] | 3 | * |
| 4 | * Copyright (c) 2005, Advanced Micro Devices, Inc. |
| 5 | * |
| 6 | * Developed with help from the 2.4.30 MMC AU1XXX controller including |
| 7 | * the following copyright notices: |
| 8 | * Copyright (c) 2003-2004 Embedded Edge, LLC. |
| 9 | * Portions Copyright (C) 2002 Embedix, Inc |
| 10 | * Copyright 2002 Hewlett-Packard Company |
| 11 | |
| 12 | * 2.6 version of this driver inspired by: |
| 13 | * (drivers/mmc/wbsd.c) Copyright (C) 2004-2005 Pierre Ossman, |
| 14 | * All Rights Reserved. |
| 15 | * (drivers/mmc/pxa.c) Copyright (C) 2003 Russell King, |
| 16 | * All Rights Reserved. |
| 17 | * |
| 18 | |
| 19 | * This program is free software; you can redistribute it and/or modify |
| 20 | * it under the terms of the GNU General Public License version 2 as |
| 21 | * published by the Free Software Foundation. |
| 22 | */ |
| 23 | |
Manuel Lauss | e2d2647 | 2008-06-27 18:25:18 +0200 | [diff] [blame] | 24 | /* Why don't we use the SD controllers' carddetect feature? |
Pete Popov | ba264b3 | 2005-09-21 06:18:27 +0000 | [diff] [blame] | 25 | * |
| 26 | * From the AU1100 MMC application guide: |
| 27 | * If the Au1100-based design is intended to support both MultiMediaCards |
| 28 | * and 1- or 4-data bit SecureDigital cards, then the solution is to |
| 29 | * connect a weak (560KOhm) pull-up resistor to connector pin 1. |
| 30 | * In doing so, a MMC card never enters SPI-mode communications, |
| 31 | * but now the SecureDigital card-detect feature of CD/DAT3 is ineffective |
| 32 | * (the low to high transition will not occur). |
Pete Popov | ba264b3 | 2005-09-21 06:18:27 +0000 | [diff] [blame] | 33 | */ |
| 34 | |
Manuel Lauss | b650759 | 2014-07-23 16:36:56 +0200 | [diff] [blame] | 35 | #include <linux/clk.h> |
Pete Popov | ba264b3 | 2005-09-21 06:18:27 +0000 | [diff] [blame] | 36 | #include <linux/module.h> |
| 37 | #include <linux/init.h> |
Martin Michlmayr | b256f9d | 2006-03-04 23:01:13 +0000 | [diff] [blame] | 38 | #include <linux/platform_device.h> |
Pete Popov | ba264b3 | 2005-09-21 06:18:27 +0000 | [diff] [blame] | 39 | #include <linux/mm.h> |
| 40 | #include <linux/interrupt.h> |
| 41 | #include <linux/dma-mapping.h> |
Al Viro | 0ada7a0 | 2007-10-27 19:40:46 +0100 | [diff] [blame] | 42 | #include <linux/scatterlist.h> |
Manuel Lauss | c4223c2 | 2008-06-09 08:36:13 +0200 | [diff] [blame] | 43 | #include <linux/leds.h> |
Pete Popov | ba264b3 | 2005-09-21 06:18:27 +0000 | [diff] [blame] | 44 | #include <linux/mmc/host.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 45 | #include <linux/slab.h> |
Manuel Lauss | c4223c2 | 2008-06-09 08:36:13 +0200 | [diff] [blame] | 46 | |
Pete Popov | ba264b3 | 2005-09-21 06:18:27 +0000 | [diff] [blame] | 47 | #include <asm/io.h> |
| 48 | #include <asm/mach-au1x00/au1000.h> |
| 49 | #include <asm/mach-au1x00/au1xxx_dbdma.h> |
| 50 | #include <asm/mach-au1x00/au1100_mmc.h> |
Pete Popov | ba264b3 | 2005-09-21 06:18:27 +0000 | [diff] [blame] | 51 | |
Pete Popov | ba264b3 | 2005-09-21 06:18:27 +0000 | [diff] [blame] | 52 | #define DRIVER_NAME "au1xxx-mmc" |
| 53 | |
| 54 | /* Set this to enable special debugging macros */ |
Manuel Lauss | c4223c2 | 2008-06-09 08:36:13 +0200 | [diff] [blame] | 55 | /* #define DEBUG */ |
Pete Popov | ba264b3 | 2005-09-21 06:18:27 +0000 | [diff] [blame] | 56 | |
Russell King | c656317 | 2006-03-29 09:30:20 +0100 | [diff] [blame] | 57 | #ifdef DEBUG |
Manuel Lauss | 5c0a889 | 2008-06-09 08:38:35 +0200 | [diff] [blame] | 58 | #define DBG(fmt, idx, args...) \ |
Girish K S | a3c76eb | 2011-10-11 11:44:09 +0530 | [diff] [blame] | 59 | pr_debug("au1xmmc(%d): DEBUG: " fmt, idx, ##args) |
Pete Popov | ba264b3 | 2005-09-21 06:18:27 +0000 | [diff] [blame] | 60 | #else |
Manuel Lauss | 5c0a889 | 2008-06-09 08:38:35 +0200 | [diff] [blame] | 61 | #define DBG(fmt, idx, args...) do {} while (0) |
Pete Popov | ba264b3 | 2005-09-21 06:18:27 +0000 | [diff] [blame] | 62 | #endif |
| 63 | |
Manuel Lauss | 5c0a889 | 2008-06-09 08:38:35 +0200 | [diff] [blame] | 64 | /* Hardware definitions */ |
| 65 | #define AU1XMMC_DESCRIPTOR_COUNT 1 |
Manuel Lauss | e491d23 | 2008-07-29 10:10:49 +0200 | [diff] [blame] | 66 | |
| 67 | /* max DMA seg size: 64KB on Au1100, 4MB on Au1200 */ |
Manuel Lauss | 1177d99 | 2011-08-02 19:51:07 +0200 | [diff] [blame] | 68 | #define AU1100_MMC_DESCRIPTOR_SIZE 0x0000ffff |
| 69 | #define AU1200_MMC_DESCRIPTOR_SIZE 0x003fffff |
Manuel Lauss | 5c0a889 | 2008-06-09 08:38:35 +0200 | [diff] [blame] | 70 | |
| 71 | #define AU1XMMC_OCR (MMC_VDD_27_28 | MMC_VDD_28_29 | MMC_VDD_29_30 | \ |
| 72 | MMC_VDD_30_31 | MMC_VDD_31_32 | MMC_VDD_32_33 | \ |
| 73 | MMC_VDD_33_34 | MMC_VDD_34_35 | MMC_VDD_35_36) |
| 74 | |
| 75 | /* This gives us a hard value for the stop command that we can write directly |
| 76 | * to the command register. |
| 77 | */ |
| 78 | #define STOP_CMD \ |
| 79 | (SD_CMD_RT_1B | SD_CMD_CT_7 | (0xC << SD_CMD_CI_SHIFT) | SD_CMD_GO) |
| 80 | |
| 81 | /* This is the set of interrupts that we configure by default. */ |
| 82 | #define AU1XMMC_INTERRUPTS \ |
| 83 | (SD_CONFIG_SC | SD_CONFIG_DT | SD_CONFIG_RAT | \ |
| 84 | SD_CONFIG_CR | SD_CONFIG_I) |
| 85 | |
| 86 | /* The poll event (looking for insert/remove events runs twice a second. */ |
| 87 | #define AU1XMMC_DETECT_TIMEOUT (HZ/2) |
| 88 | |
| 89 | struct au1xmmc_host { |
| 90 | struct mmc_host *mmc; |
| 91 | struct mmc_request *mrq; |
| 92 | |
| 93 | u32 flags; |
Manuel Lauss | 2f73bfb | 2014-07-23 16:36:26 +0200 | [diff] [blame] | 94 | void __iomem *iobase; |
Manuel Lauss | 5c0a889 | 2008-06-09 08:38:35 +0200 | [diff] [blame] | 95 | u32 clock; |
| 96 | u32 bus_width; |
| 97 | u32 power_mode; |
| 98 | |
| 99 | int status; |
| 100 | |
| 101 | struct { |
| 102 | int len; |
| 103 | int dir; |
| 104 | } dma; |
| 105 | |
| 106 | struct { |
| 107 | int index; |
| 108 | int offset; |
| 109 | int len; |
| 110 | } pio; |
| 111 | |
| 112 | u32 tx_chan; |
| 113 | u32 rx_chan; |
| 114 | |
| 115 | int irq; |
| 116 | |
Manuel Lauss | 5c0a889 | 2008-06-09 08:38:35 +0200 | [diff] [blame] | 117 | struct tasklet_struct finish_task; |
| 118 | struct tasklet_struct data_task; |
| 119 | struct au1xmmc_platform_data *platdata; |
| 120 | struct platform_device *pdev; |
| 121 | struct resource *ioarea; |
Manuel Lauss | b650759 | 2014-07-23 16:36:56 +0200 | [diff] [blame] | 122 | struct clk *clk; |
Manuel Lauss | 5c0a889 | 2008-06-09 08:38:35 +0200 | [diff] [blame] | 123 | }; |
| 124 | |
| 125 | /* Status flags used by the host structure */ |
| 126 | #define HOST_F_XMIT 0x0001 |
| 127 | #define HOST_F_RECV 0x0002 |
| 128 | #define HOST_F_DMA 0x0010 |
Manuel Lauss | 1177d99 | 2011-08-02 19:51:07 +0200 | [diff] [blame] | 129 | #define HOST_F_DBDMA 0x0020 |
Manuel Lauss | 5c0a889 | 2008-06-09 08:38:35 +0200 | [diff] [blame] | 130 | #define HOST_F_ACTIVE 0x0100 |
| 131 | #define HOST_F_STOP 0x1000 |
| 132 | |
| 133 | #define HOST_S_IDLE 0x0001 |
| 134 | #define HOST_S_CMD 0x0002 |
| 135 | #define HOST_S_DATA 0x0003 |
| 136 | #define HOST_S_STOP 0x0004 |
| 137 | |
| 138 | /* Easy access macros */ |
| 139 | #define HOST_STATUS(h) ((h)->iobase + SD_STATUS) |
| 140 | #define HOST_CONFIG(h) ((h)->iobase + SD_CONFIG) |
| 141 | #define HOST_ENABLE(h) ((h)->iobase + SD_ENABLE) |
| 142 | #define HOST_TXPORT(h) ((h)->iobase + SD_TXPORT) |
| 143 | #define HOST_RXPORT(h) ((h)->iobase + SD_RXPORT) |
| 144 | #define HOST_CMDARG(h) ((h)->iobase + SD_CMDARG) |
| 145 | #define HOST_BLKSIZE(h) ((h)->iobase + SD_BLKSIZE) |
| 146 | #define HOST_CMD(h) ((h)->iobase + SD_CMD) |
| 147 | #define HOST_CONFIG2(h) ((h)->iobase + SD_CONFIG2) |
| 148 | #define HOST_TIMEOUT(h) ((h)->iobase + SD_TIMEOUT) |
| 149 | #define HOST_DEBUG(h) ((h)->iobase + SD_DEBUG) |
| 150 | |
| 151 | #define DMA_CHANNEL(h) \ |
| 152 | (((h)->flags & HOST_F_XMIT) ? (h)->tx_chan : (h)->rx_chan) |
| 153 | |
Manuel Lauss | 1177d99 | 2011-08-02 19:51:07 +0200 | [diff] [blame] | 154 | static inline int has_dbdma(void) |
| 155 | { |
| 156 | switch (alchemy_get_cputype()) { |
| 157 | case ALCHEMY_CPU_AU1200: |
Manuel Lauss | 809f36c | 2011-11-01 20:03:30 +0100 | [diff] [blame] | 158 | case ALCHEMY_CPU_AU1300: |
Manuel Lauss | 1177d99 | 2011-08-02 19:51:07 +0200 | [diff] [blame] | 159 | return 1; |
| 160 | default: |
| 161 | return 0; |
| 162 | } |
| 163 | } |
| 164 | |
Pete Popov | ba264b3 | 2005-09-21 06:18:27 +0000 | [diff] [blame] | 165 | static inline void IRQ_ON(struct au1xmmc_host *host, u32 mask) |
| 166 | { |
Manuel Lauss | 2f73bfb | 2014-07-23 16:36:26 +0200 | [diff] [blame] | 167 | u32 val = __raw_readl(HOST_CONFIG(host)); |
Pete Popov | ba264b3 | 2005-09-21 06:18:27 +0000 | [diff] [blame] | 168 | val |= mask; |
Manuel Lauss | 2f73bfb | 2014-07-23 16:36:26 +0200 | [diff] [blame] | 169 | __raw_writel(val, HOST_CONFIG(host)); |
| 170 | wmb(); /* drain writebuffer */ |
Pete Popov | ba264b3 | 2005-09-21 06:18:27 +0000 | [diff] [blame] | 171 | } |
| 172 | |
| 173 | static inline void FLUSH_FIFO(struct au1xmmc_host *host) |
| 174 | { |
Manuel Lauss | 2f73bfb | 2014-07-23 16:36:26 +0200 | [diff] [blame] | 175 | u32 val = __raw_readl(HOST_CONFIG2(host)); |
Pete Popov | ba264b3 | 2005-09-21 06:18:27 +0000 | [diff] [blame] | 176 | |
Manuel Lauss | 2f73bfb | 2014-07-23 16:36:26 +0200 | [diff] [blame] | 177 | __raw_writel(val | SD_CONFIG2_FF, HOST_CONFIG2(host)); |
| 178 | wmb(); /* drain writebuffer */ |
| 179 | mdelay(1); |
Pete Popov | ba264b3 | 2005-09-21 06:18:27 +0000 | [diff] [blame] | 180 | |
| 181 | /* SEND_STOP will turn off clock control - this re-enables it */ |
| 182 | val &= ~SD_CONFIG2_DF; |
| 183 | |
Manuel Lauss | 2f73bfb | 2014-07-23 16:36:26 +0200 | [diff] [blame] | 184 | __raw_writel(val, HOST_CONFIG2(host)); |
| 185 | wmb(); /* drain writebuffer */ |
Pete Popov | ba264b3 | 2005-09-21 06:18:27 +0000 | [diff] [blame] | 186 | } |
| 187 | |
| 188 | static inline void IRQ_OFF(struct au1xmmc_host *host, u32 mask) |
| 189 | { |
Manuel Lauss | 2f73bfb | 2014-07-23 16:36:26 +0200 | [diff] [blame] | 190 | u32 val = __raw_readl(HOST_CONFIG(host)); |
Pete Popov | ba264b3 | 2005-09-21 06:18:27 +0000 | [diff] [blame] | 191 | val &= ~mask; |
Manuel Lauss | 2f73bfb | 2014-07-23 16:36:26 +0200 | [diff] [blame] | 192 | __raw_writel(val, HOST_CONFIG(host)); |
| 193 | wmb(); /* drain writebuffer */ |
Pete Popov | ba264b3 | 2005-09-21 06:18:27 +0000 | [diff] [blame] | 194 | } |
| 195 | |
| 196 | static inline void SEND_STOP(struct au1xmmc_host *host) |
| 197 | { |
Manuel Lauss | 281dd23 | 2008-06-09 08:37:33 +0200 | [diff] [blame] | 198 | u32 config2; |
Pete Popov | ba264b3 | 2005-09-21 06:18:27 +0000 | [diff] [blame] | 199 | |
| 200 | WARN_ON(host->status != HOST_S_DATA); |
| 201 | host->status = HOST_S_STOP; |
| 202 | |
Manuel Lauss | 2f73bfb | 2014-07-23 16:36:26 +0200 | [diff] [blame] | 203 | config2 = __raw_readl(HOST_CONFIG2(host)); |
| 204 | __raw_writel(config2 | SD_CONFIG2_DF, HOST_CONFIG2(host)); |
| 205 | wmb(); /* drain writebuffer */ |
Pete Popov | ba264b3 | 2005-09-21 06:18:27 +0000 | [diff] [blame] | 206 | |
Uwe Kleine-König | b595076 | 2010-11-01 15:38:34 -0400 | [diff] [blame] | 207 | /* Send the stop command */ |
Manuel Lauss | 2f73bfb | 2014-07-23 16:36:26 +0200 | [diff] [blame] | 208 | __raw_writel(STOP_CMD, HOST_CMD(host)); |
| 209 | wmb(); /* drain writebuffer */ |
Pete Popov | ba264b3 | 2005-09-21 06:18:27 +0000 | [diff] [blame] | 210 | } |
| 211 | |
| 212 | static void au1xmmc_set_power(struct au1xmmc_host *host, int state) |
| 213 | { |
Manuel Lauss | c4223c2 | 2008-06-09 08:36:13 +0200 | [diff] [blame] | 214 | if (host->platdata && host->platdata->set_power) |
| 215 | host->platdata->set_power(host->mmc, state); |
Pete Popov | ba264b3 | 2005-09-21 06:18:27 +0000 | [diff] [blame] | 216 | } |
| 217 | |
Manuel Lauss | e2d2647 | 2008-06-27 18:25:18 +0200 | [diff] [blame] | 218 | static int au1xmmc_card_inserted(struct mmc_host *mmc) |
Pete Popov | ba264b3 | 2005-09-21 06:18:27 +0000 | [diff] [blame] | 219 | { |
Manuel Lauss | e2d2647 | 2008-06-27 18:25:18 +0200 | [diff] [blame] | 220 | struct au1xmmc_host *host = mmc_priv(mmc); |
Manuel Lauss | c4223c2 | 2008-06-09 08:36:13 +0200 | [diff] [blame] | 221 | |
| 222 | if (host->platdata && host->platdata->card_inserted) |
Manuel Lauss | e2d2647 | 2008-06-27 18:25:18 +0200 | [diff] [blame] | 223 | return !!host->platdata->card_inserted(host->mmc); |
Manuel Lauss | c4223c2 | 2008-06-09 08:36:13 +0200 | [diff] [blame] | 224 | |
Manuel Lauss | e2d2647 | 2008-06-27 18:25:18 +0200 | [diff] [blame] | 225 | return -ENOSYS; |
Pete Popov | ba264b3 | 2005-09-21 06:18:27 +0000 | [diff] [blame] | 226 | } |
| 227 | |
Manuel Lauss | 8299977 | 2007-01-25 10:29:24 +0100 | [diff] [blame] | 228 | static int au1xmmc_card_readonly(struct mmc_host *mmc) |
Pete Popov | ba264b3 | 2005-09-21 06:18:27 +0000 | [diff] [blame] | 229 | { |
Manuel Lauss | 8299977 | 2007-01-25 10:29:24 +0100 | [diff] [blame] | 230 | struct au1xmmc_host *host = mmc_priv(mmc); |
Manuel Lauss | c4223c2 | 2008-06-09 08:36:13 +0200 | [diff] [blame] | 231 | |
| 232 | if (host->platdata && host->platdata->card_readonly) |
Manuel Lauss | e2d2647 | 2008-06-27 18:25:18 +0200 | [diff] [blame] | 233 | return !!host->platdata->card_readonly(mmc); |
Manuel Lauss | c4223c2 | 2008-06-09 08:36:13 +0200 | [diff] [blame] | 234 | |
Manuel Lauss | e2d2647 | 2008-06-27 18:25:18 +0200 | [diff] [blame] | 235 | return -ENOSYS; |
Pete Popov | ba264b3 | 2005-09-21 06:18:27 +0000 | [diff] [blame] | 236 | } |
| 237 | |
| 238 | static void au1xmmc_finish_request(struct au1xmmc_host *host) |
| 239 | { |
Pete Popov | ba264b3 | 2005-09-21 06:18:27 +0000 | [diff] [blame] | 240 | struct mmc_request *mrq = host->mrq; |
| 241 | |
| 242 | host->mrq = NULL; |
Manuel Lauss | c4223c2 | 2008-06-09 08:36:13 +0200 | [diff] [blame] | 243 | host->flags &= HOST_F_ACTIVE | HOST_F_DMA; |
Pete Popov | ba264b3 | 2005-09-21 06:18:27 +0000 | [diff] [blame] | 244 | |
| 245 | host->dma.len = 0; |
| 246 | host->dma.dir = 0; |
| 247 | |
| 248 | host->pio.index = 0; |
| 249 | host->pio.offset = 0; |
| 250 | host->pio.len = 0; |
| 251 | |
| 252 | host->status = HOST_S_IDLE; |
| 253 | |
Pete Popov | ba264b3 | 2005-09-21 06:18:27 +0000 | [diff] [blame] | 254 | mmc_request_done(host->mmc, mrq); |
| 255 | } |
| 256 | |
| 257 | static void au1xmmc_tasklet_finish(unsigned long param) |
| 258 | { |
| 259 | struct au1xmmc_host *host = (struct au1xmmc_host *) param; |
| 260 | au1xmmc_finish_request(host); |
| 261 | } |
| 262 | |
| 263 | static int au1xmmc_send_command(struct au1xmmc_host *host, int wait, |
Pierre Ossman | be0192a | 2007-07-24 21:11:47 +0200 | [diff] [blame] | 264 | struct mmc_command *cmd, struct mmc_data *data) |
Pete Popov | ba264b3 | 2005-09-21 06:18:27 +0000 | [diff] [blame] | 265 | { |
Pete Popov | ba264b3 | 2005-09-21 06:18:27 +0000 | [diff] [blame] | 266 | u32 mmccmd = (cmd->opcode << SD_CMD_CI_SHIFT); |
| 267 | |
Martin Michlmayr | e142c24 | 2006-03-04 23:01:39 +0000 | [diff] [blame] | 268 | switch (mmc_resp_type(cmd)) { |
Manuel Lauss | 279bc44 | 2007-01-25 10:27:41 +0100 | [diff] [blame] | 269 | case MMC_RSP_NONE: |
| 270 | break; |
Pete Popov | ba264b3 | 2005-09-21 06:18:27 +0000 | [diff] [blame] | 271 | case MMC_RSP_R1: |
| 272 | mmccmd |= SD_CMD_RT_1; |
| 273 | break; |
| 274 | case MMC_RSP_R1B: |
| 275 | mmccmd |= SD_CMD_RT_1B; |
| 276 | break; |
| 277 | case MMC_RSP_R2: |
| 278 | mmccmd |= SD_CMD_RT_2; |
| 279 | break; |
| 280 | case MMC_RSP_R3: |
| 281 | mmccmd |= SD_CMD_RT_3; |
| 282 | break; |
Manuel Lauss | 279bc44 | 2007-01-25 10:27:41 +0100 | [diff] [blame] | 283 | default: |
Girish K S | a3c76eb | 2011-10-11 11:44:09 +0530 | [diff] [blame] | 284 | pr_info("au1xmmc: unhandled response type %02x\n", |
Manuel Lauss | 279bc44 | 2007-01-25 10:27:41 +0100 | [diff] [blame] | 285 | mmc_resp_type(cmd)); |
Pierre Ossman | 17b0429 | 2007-07-22 22:18:46 +0200 | [diff] [blame] | 286 | return -EINVAL; |
Pete Popov | ba264b3 | 2005-09-21 06:18:27 +0000 | [diff] [blame] | 287 | } |
| 288 | |
Pierre Ossman | be0192a | 2007-07-24 21:11:47 +0200 | [diff] [blame] | 289 | if (data) { |
Pierre Ossman | 6356a9d | 2007-10-22 18:16:16 +0200 | [diff] [blame] | 290 | if (data->flags & MMC_DATA_READ) { |
Pierre Ossman | be0192a | 2007-07-24 21:11:47 +0200 | [diff] [blame] | 291 | if (data->blocks > 1) |
| 292 | mmccmd |= SD_CMD_CT_4; |
| 293 | else |
| 294 | mmccmd |= SD_CMD_CT_2; |
Pierre Ossman | 6356a9d | 2007-10-22 18:16:16 +0200 | [diff] [blame] | 295 | } else if (data->flags & MMC_DATA_WRITE) { |
Pierre Ossman | be0192a | 2007-07-24 21:11:47 +0200 | [diff] [blame] | 296 | if (data->blocks > 1) |
| 297 | mmccmd |= SD_CMD_CT_3; |
| 298 | else |
| 299 | mmccmd |= SD_CMD_CT_1; |
| 300 | } |
Pete Popov | ba264b3 | 2005-09-21 06:18:27 +0000 | [diff] [blame] | 301 | } |
| 302 | |
Manuel Lauss | 2f73bfb | 2014-07-23 16:36:26 +0200 | [diff] [blame] | 303 | __raw_writel(cmd->arg, HOST_CMDARG(host)); |
| 304 | wmb(); /* drain writebuffer */ |
Pete Popov | ba264b3 | 2005-09-21 06:18:27 +0000 | [diff] [blame] | 305 | |
| 306 | if (wait) |
| 307 | IRQ_OFF(host, SD_CONFIG_CR); |
| 308 | |
Manuel Lauss | 2f73bfb | 2014-07-23 16:36:26 +0200 | [diff] [blame] | 309 | __raw_writel((mmccmd | SD_CMD_GO), HOST_CMD(host)); |
| 310 | wmb(); /* drain writebuffer */ |
Pete Popov | ba264b3 | 2005-09-21 06:18:27 +0000 | [diff] [blame] | 311 | |
| 312 | /* Wait for the command to go on the line */ |
Manuel Lauss | 2f73bfb | 2014-07-23 16:36:26 +0200 | [diff] [blame] | 313 | while (__raw_readl(HOST_CMD(host)) & SD_CMD_GO) |
Manuel Lauss | 5c0a889 | 2008-06-09 08:38:35 +0200 | [diff] [blame] | 314 | /* nop */; |
Pete Popov | ba264b3 | 2005-09-21 06:18:27 +0000 | [diff] [blame] | 315 | |
| 316 | /* Wait for the command to come back */ |
Pete Popov | ba264b3 | 2005-09-21 06:18:27 +0000 | [diff] [blame] | 317 | if (wait) { |
Manuel Lauss | 2f73bfb | 2014-07-23 16:36:26 +0200 | [diff] [blame] | 318 | u32 status = __raw_readl(HOST_STATUS(host)); |
Pete Popov | ba264b3 | 2005-09-21 06:18:27 +0000 | [diff] [blame] | 319 | |
Manuel Lauss | 5c0a889 | 2008-06-09 08:38:35 +0200 | [diff] [blame] | 320 | while (!(status & SD_STATUS_CR)) |
Manuel Lauss | 2f73bfb | 2014-07-23 16:36:26 +0200 | [diff] [blame] | 321 | status = __raw_readl(HOST_STATUS(host)); |
Pete Popov | ba264b3 | 2005-09-21 06:18:27 +0000 | [diff] [blame] | 322 | |
| 323 | /* Clear the CR status */ |
Manuel Lauss | 2f73bfb | 2014-07-23 16:36:26 +0200 | [diff] [blame] | 324 | __raw_writel(SD_STATUS_CR, HOST_STATUS(host)); |
Pete Popov | ba264b3 | 2005-09-21 06:18:27 +0000 | [diff] [blame] | 325 | |
| 326 | IRQ_ON(host, SD_CONFIG_CR); |
| 327 | } |
| 328 | |
Pierre Ossman | 17b0429 | 2007-07-22 22:18:46 +0200 | [diff] [blame] | 329 | return 0; |
Pete Popov | ba264b3 | 2005-09-21 06:18:27 +0000 | [diff] [blame] | 330 | } |
| 331 | |
| 332 | static void au1xmmc_data_complete(struct au1xmmc_host *host, u32 status) |
| 333 | { |
Pete Popov | ba264b3 | 2005-09-21 06:18:27 +0000 | [diff] [blame] | 334 | struct mmc_request *mrq = host->mrq; |
| 335 | struct mmc_data *data; |
| 336 | u32 crc; |
| 337 | |
Manuel Lauss | 5c0a889 | 2008-06-09 08:38:35 +0200 | [diff] [blame] | 338 | WARN_ON((host->status != HOST_S_DATA) && (host->status != HOST_S_STOP)); |
Pete Popov | ba264b3 | 2005-09-21 06:18:27 +0000 | [diff] [blame] | 339 | |
| 340 | if (host->mrq == NULL) |
| 341 | return; |
| 342 | |
| 343 | data = mrq->cmd->data; |
| 344 | |
| 345 | if (status == 0) |
Manuel Lauss | 2f73bfb | 2014-07-23 16:36:26 +0200 | [diff] [blame] | 346 | status = __raw_readl(HOST_STATUS(host)); |
Pete Popov | ba264b3 | 2005-09-21 06:18:27 +0000 | [diff] [blame] | 347 | |
| 348 | /* The transaction is really over when the SD_STATUS_DB bit is clear */ |
Manuel Lauss | 5c0a889 | 2008-06-09 08:38:35 +0200 | [diff] [blame] | 349 | while ((host->flags & HOST_F_XMIT) && (status & SD_STATUS_DB)) |
Manuel Lauss | 2f73bfb | 2014-07-23 16:36:26 +0200 | [diff] [blame] | 350 | status = __raw_readl(HOST_STATUS(host)); |
Pete Popov | ba264b3 | 2005-09-21 06:18:27 +0000 | [diff] [blame] | 351 | |
Pierre Ossman | 17b0429 | 2007-07-22 22:18:46 +0200 | [diff] [blame] | 352 | data->error = 0; |
Pete Popov | ba264b3 | 2005-09-21 06:18:27 +0000 | [diff] [blame] | 353 | dma_unmap_sg(mmc_dev(host->mmc), data->sg, data->sg_len, host->dma.dir); |
| 354 | |
| 355 | /* Process any errors */ |
Pete Popov | ba264b3 | 2005-09-21 06:18:27 +0000 | [diff] [blame] | 356 | crc = (status & (SD_STATUS_WC | SD_STATUS_RC)); |
| 357 | if (host->flags & HOST_F_XMIT) |
| 358 | crc |= ((status & 0x07) == 0x02) ? 0 : 1; |
| 359 | |
| 360 | if (crc) |
Pierre Ossman | 17b0429 | 2007-07-22 22:18:46 +0200 | [diff] [blame] | 361 | data->error = -EILSEQ; |
Pete Popov | ba264b3 | 2005-09-21 06:18:27 +0000 | [diff] [blame] | 362 | |
| 363 | /* Clear the CRC bits */ |
Manuel Lauss | 2f73bfb | 2014-07-23 16:36:26 +0200 | [diff] [blame] | 364 | __raw_writel(SD_STATUS_WC | SD_STATUS_RC, HOST_STATUS(host)); |
Pete Popov | ba264b3 | 2005-09-21 06:18:27 +0000 | [diff] [blame] | 365 | |
| 366 | data->bytes_xfered = 0; |
| 367 | |
Pierre Ossman | 17b0429 | 2007-07-22 22:18:46 +0200 | [diff] [blame] | 368 | if (!data->error) { |
Manuel Lauss | 1177d99 | 2011-08-02 19:51:07 +0200 | [diff] [blame] | 369 | if (host->flags & (HOST_F_DMA | HOST_F_DBDMA)) { |
Pete Popov | ba264b3 | 2005-09-21 06:18:27 +0000 | [diff] [blame] | 370 | u32 chan = DMA_CHANNEL(host); |
| 371 | |
Manuel Lauss | 5c0a889 | 2008-06-09 08:38:35 +0200 | [diff] [blame] | 372 | chan_tab_t *c = *((chan_tab_t **)chan); |
Pete Popov | ba264b3 | 2005-09-21 06:18:27 +0000 | [diff] [blame] | 373 | au1x_dma_chan_t *cp = c->chan_ptr; |
| 374 | data->bytes_xfered = cp->ddma_bytecnt; |
Manuel Lauss | 5c0a889 | 2008-06-09 08:38:35 +0200 | [diff] [blame] | 375 | } else |
Pete Popov | ba264b3 | 2005-09-21 06:18:27 +0000 | [diff] [blame] | 376 | data->bytes_xfered = |
Manuel Lauss | 5c0a889 | 2008-06-09 08:38:35 +0200 | [diff] [blame] | 377 | (data->blocks * data->blksz) - host->pio.len; |
Pete Popov | ba264b3 | 2005-09-21 06:18:27 +0000 | [diff] [blame] | 378 | } |
| 379 | |
| 380 | au1xmmc_finish_request(host); |
| 381 | } |
| 382 | |
| 383 | static void au1xmmc_tasklet_data(unsigned long param) |
| 384 | { |
Manuel Lauss | 5c0a889 | 2008-06-09 08:38:35 +0200 | [diff] [blame] | 385 | struct au1xmmc_host *host = (struct au1xmmc_host *)param; |
Pete Popov | ba264b3 | 2005-09-21 06:18:27 +0000 | [diff] [blame] | 386 | |
Manuel Lauss | 2f73bfb | 2014-07-23 16:36:26 +0200 | [diff] [blame] | 387 | u32 status = __raw_readl(HOST_STATUS(host)); |
Pete Popov | ba264b3 | 2005-09-21 06:18:27 +0000 | [diff] [blame] | 388 | au1xmmc_data_complete(host, status); |
| 389 | } |
| 390 | |
| 391 | #define AU1XMMC_MAX_TRANSFER 8 |
| 392 | |
| 393 | static void au1xmmc_send_pio(struct au1xmmc_host *host) |
| 394 | { |
Manuel Lauss | 5c0a889 | 2008-06-09 08:38:35 +0200 | [diff] [blame] | 395 | struct mmc_data *data; |
| 396 | int sg_len, max, count; |
| 397 | unsigned char *sg_ptr, val; |
| 398 | u32 status; |
Pete Popov | ba264b3 | 2005-09-21 06:18:27 +0000 | [diff] [blame] | 399 | struct scatterlist *sg; |
| 400 | |
| 401 | data = host->mrq->data; |
| 402 | |
| 403 | if (!(host->flags & HOST_F_XMIT)) |
| 404 | return; |
| 405 | |
| 406 | /* This is the pointer to the data buffer */ |
| 407 | sg = &data->sg[host->pio.index]; |
Jens Axboe | 45711f1 | 2007-10-22 21:19:53 +0200 | [diff] [blame] | 408 | sg_ptr = sg_virt(sg) + host->pio.offset; |
Pete Popov | ba264b3 | 2005-09-21 06:18:27 +0000 | [diff] [blame] | 409 | |
| 410 | /* This is the space left inside the buffer */ |
| 411 | sg_len = data->sg[host->pio.index].length - host->pio.offset; |
| 412 | |
Manuel Lauss | 5c0a889 | 2008-06-09 08:38:35 +0200 | [diff] [blame] | 413 | /* Check if we need less than the size of the sg_buffer */ |
Pete Popov | ba264b3 | 2005-09-21 06:18:27 +0000 | [diff] [blame] | 414 | max = (sg_len > host->pio.len) ? host->pio.len : sg_len; |
Manuel Lauss | 5c0a889 | 2008-06-09 08:38:35 +0200 | [diff] [blame] | 415 | if (max > AU1XMMC_MAX_TRANSFER) |
| 416 | max = AU1XMMC_MAX_TRANSFER; |
Pete Popov | ba264b3 | 2005-09-21 06:18:27 +0000 | [diff] [blame] | 417 | |
Manuel Lauss | 5c0a889 | 2008-06-09 08:38:35 +0200 | [diff] [blame] | 418 | for (count = 0; count < max; count++) { |
Manuel Lauss | 2f73bfb | 2014-07-23 16:36:26 +0200 | [diff] [blame] | 419 | status = __raw_readl(HOST_STATUS(host)); |
Pete Popov | ba264b3 | 2005-09-21 06:18:27 +0000 | [diff] [blame] | 420 | |
| 421 | if (!(status & SD_STATUS_TH)) |
| 422 | break; |
| 423 | |
| 424 | val = *sg_ptr++; |
| 425 | |
Manuel Lauss | 2f73bfb | 2014-07-23 16:36:26 +0200 | [diff] [blame] | 426 | __raw_writel((unsigned long)val, HOST_TXPORT(host)); |
| 427 | wmb(); /* drain writebuffer */ |
Pete Popov | ba264b3 | 2005-09-21 06:18:27 +0000 | [diff] [blame] | 428 | } |
| 429 | |
| 430 | host->pio.len -= count; |
| 431 | host->pio.offset += count; |
| 432 | |
| 433 | if (count == sg_len) { |
| 434 | host->pio.index++; |
| 435 | host->pio.offset = 0; |
| 436 | } |
| 437 | |
| 438 | if (host->pio.len == 0) { |
| 439 | IRQ_OFF(host, SD_CONFIG_TH); |
| 440 | |
| 441 | if (host->flags & HOST_F_STOP) |
| 442 | SEND_STOP(host); |
| 443 | |
| 444 | tasklet_schedule(&host->data_task); |
| 445 | } |
| 446 | } |
| 447 | |
| 448 | static void au1xmmc_receive_pio(struct au1xmmc_host *host) |
| 449 | { |
Manuel Lauss | 5c0a889 | 2008-06-09 08:38:35 +0200 | [diff] [blame] | 450 | struct mmc_data *data; |
| 451 | int max, count, sg_len = 0; |
| 452 | unsigned char *sg_ptr = NULL; |
| 453 | u32 status, val; |
Pete Popov | ba264b3 | 2005-09-21 06:18:27 +0000 | [diff] [blame] | 454 | struct scatterlist *sg; |
| 455 | |
| 456 | data = host->mrq->data; |
| 457 | |
| 458 | if (!(host->flags & HOST_F_RECV)) |
| 459 | return; |
| 460 | |
| 461 | max = host->pio.len; |
| 462 | |
| 463 | if (host->pio.index < host->dma.len) { |
| 464 | sg = &data->sg[host->pio.index]; |
Jens Axboe | 45711f1 | 2007-10-22 21:19:53 +0200 | [diff] [blame] | 465 | sg_ptr = sg_virt(sg) + host->pio.offset; |
Pete Popov | ba264b3 | 2005-09-21 06:18:27 +0000 | [diff] [blame] | 466 | |
| 467 | /* This is the space left inside the buffer */ |
| 468 | sg_len = sg_dma_len(&data->sg[host->pio.index]) - host->pio.offset; |
| 469 | |
Manuel Lauss | 5c0a889 | 2008-06-09 08:38:35 +0200 | [diff] [blame] | 470 | /* Check if we need less than the size of the sg_buffer */ |
| 471 | if (sg_len < max) |
| 472 | max = sg_len; |
Pete Popov | ba264b3 | 2005-09-21 06:18:27 +0000 | [diff] [blame] | 473 | } |
| 474 | |
| 475 | if (max > AU1XMMC_MAX_TRANSFER) |
| 476 | max = AU1XMMC_MAX_TRANSFER; |
| 477 | |
Manuel Lauss | 5c0a889 | 2008-06-09 08:38:35 +0200 | [diff] [blame] | 478 | for (count = 0; count < max; count++) { |
Manuel Lauss | 2f73bfb | 2014-07-23 16:36:26 +0200 | [diff] [blame] | 479 | status = __raw_readl(HOST_STATUS(host)); |
Pete Popov | ba264b3 | 2005-09-21 06:18:27 +0000 | [diff] [blame] | 480 | |
| 481 | if (!(status & SD_STATUS_NE)) |
| 482 | break; |
| 483 | |
| 484 | if (status & SD_STATUS_RC) { |
Manuel Lauss | c4223c2 | 2008-06-09 08:36:13 +0200 | [diff] [blame] | 485 | DBG("RX CRC Error [%d + %d].\n", host->pdev->id, |
Pete Popov | ba264b3 | 2005-09-21 06:18:27 +0000 | [diff] [blame] | 486 | host->pio.len, count); |
| 487 | break; |
| 488 | } |
| 489 | |
| 490 | if (status & SD_STATUS_RO) { |
Manuel Lauss | c4223c2 | 2008-06-09 08:36:13 +0200 | [diff] [blame] | 491 | DBG("RX Overrun [%d + %d]\n", host->pdev->id, |
Pete Popov | ba264b3 | 2005-09-21 06:18:27 +0000 | [diff] [blame] | 492 | host->pio.len, count); |
| 493 | break; |
| 494 | } |
| 495 | else if (status & SD_STATUS_RU) { |
Manuel Lauss | c4223c2 | 2008-06-09 08:36:13 +0200 | [diff] [blame] | 496 | DBG("RX Underrun [%d + %d]\n", host->pdev->id, |
Pete Popov | ba264b3 | 2005-09-21 06:18:27 +0000 | [diff] [blame] | 497 | host->pio.len, count); |
| 498 | break; |
| 499 | } |
| 500 | |
Manuel Lauss | 2f73bfb | 2014-07-23 16:36:26 +0200 | [diff] [blame] | 501 | val = __raw_readl(HOST_RXPORT(host)); |
Pete Popov | ba264b3 | 2005-09-21 06:18:27 +0000 | [diff] [blame] | 502 | |
| 503 | if (sg_ptr) |
Manuel Lauss | 5c0a889 | 2008-06-09 08:38:35 +0200 | [diff] [blame] | 504 | *sg_ptr++ = (unsigned char)(val & 0xFF); |
Pete Popov | ba264b3 | 2005-09-21 06:18:27 +0000 | [diff] [blame] | 505 | } |
| 506 | |
| 507 | host->pio.len -= count; |
| 508 | host->pio.offset += count; |
| 509 | |
| 510 | if (sg_len && count == sg_len) { |
| 511 | host->pio.index++; |
| 512 | host->pio.offset = 0; |
| 513 | } |
| 514 | |
| 515 | if (host->pio.len == 0) { |
Manuel Lauss | 5c0a889 | 2008-06-09 08:38:35 +0200 | [diff] [blame] | 516 | /* IRQ_OFF(host, SD_CONFIG_RA | SD_CONFIG_RF); */ |
Pete Popov | ba264b3 | 2005-09-21 06:18:27 +0000 | [diff] [blame] | 517 | IRQ_OFF(host, SD_CONFIG_NE); |
| 518 | |
| 519 | if (host->flags & HOST_F_STOP) |
| 520 | SEND_STOP(host); |
| 521 | |
| 522 | tasklet_schedule(&host->data_task); |
| 523 | } |
| 524 | } |
| 525 | |
Manuel Lauss | 5c0a889 | 2008-06-09 08:38:35 +0200 | [diff] [blame] | 526 | /* This is called when a command has been completed - grab the response |
| 527 | * and check for errors. Then start the data transfer if it is indicated. |
| 528 | */ |
Pete Popov | ba264b3 | 2005-09-21 06:18:27 +0000 | [diff] [blame] | 529 | static void au1xmmc_cmd_complete(struct au1xmmc_host *host, u32 status) |
| 530 | { |
Pete Popov | ba264b3 | 2005-09-21 06:18:27 +0000 | [diff] [blame] | 531 | struct mmc_request *mrq = host->mrq; |
| 532 | struct mmc_command *cmd; |
Manuel Lauss | 5c0a889 | 2008-06-09 08:38:35 +0200 | [diff] [blame] | 533 | u32 r[4]; |
| 534 | int i, trans; |
Pete Popov | ba264b3 | 2005-09-21 06:18:27 +0000 | [diff] [blame] | 535 | |
| 536 | if (!host->mrq) |
| 537 | return; |
| 538 | |
| 539 | cmd = mrq->cmd; |
Pierre Ossman | 17b0429 | 2007-07-22 22:18:46 +0200 | [diff] [blame] | 540 | cmd->error = 0; |
Pete Popov | ba264b3 | 2005-09-21 06:18:27 +0000 | [diff] [blame] | 541 | |
Russell King | e922517 | 2006-02-02 12:23:12 +0000 | [diff] [blame] | 542 | if (cmd->flags & MMC_RSP_PRESENT) { |
| 543 | if (cmd->flags & MMC_RSP_136) { |
Manuel Lauss | 2f73bfb | 2014-07-23 16:36:26 +0200 | [diff] [blame] | 544 | r[0] = __raw_readl(host->iobase + SD_RESP3); |
| 545 | r[1] = __raw_readl(host->iobase + SD_RESP2); |
| 546 | r[2] = __raw_readl(host->iobase + SD_RESP1); |
| 547 | r[3] = __raw_readl(host->iobase + SD_RESP0); |
Pete Popov | ba264b3 | 2005-09-21 06:18:27 +0000 | [diff] [blame] | 548 | |
Russell King | e922517 | 2006-02-02 12:23:12 +0000 | [diff] [blame] | 549 | /* The CRC is omitted from the response, so really |
| 550 | * we only got 120 bytes, but the engine expects |
Manuel Lauss | 5c0a889 | 2008-06-09 08:38:35 +0200 | [diff] [blame] | 551 | * 128 bits, so we have to shift things up. |
Russell King | e922517 | 2006-02-02 12:23:12 +0000 | [diff] [blame] | 552 | */ |
Manuel Lauss | 5c0a889 | 2008-06-09 08:38:35 +0200 | [diff] [blame] | 553 | for (i = 0; i < 4; i++) { |
Russell King | e922517 | 2006-02-02 12:23:12 +0000 | [diff] [blame] | 554 | cmd->resp[i] = (r[i] & 0x00FFFFFF) << 8; |
| 555 | if (i != 3) |
| 556 | cmd->resp[i] |= (r[i + 1] & 0xFF000000) >> 24; |
| 557 | } |
| 558 | } else { |
| 559 | /* Techincally, we should be getting all 48 bits of |
| 560 | * the response (SD_RESP1 + SD_RESP2), but because |
| 561 | * our response omits the CRC, our data ends up |
| 562 | * being shifted 8 bits to the right. In this case, |
| 563 | * that means that the OSR data starts at bit 31, |
Manuel Lauss | 5c0a889 | 2008-06-09 08:38:35 +0200 | [diff] [blame] | 564 | * so we can just read RESP0 and return that. |
Russell King | e922517 | 2006-02-02 12:23:12 +0000 | [diff] [blame] | 565 | */ |
Manuel Lauss | 2f73bfb | 2014-07-23 16:36:26 +0200 | [diff] [blame] | 566 | cmd->resp[0] = __raw_readl(host->iobase + SD_RESP0); |
Pete Popov | ba264b3 | 2005-09-21 06:18:27 +0000 | [diff] [blame] | 567 | } |
| 568 | } |
| 569 | |
| 570 | /* Figure out errors */ |
Pete Popov | ba264b3 | 2005-09-21 06:18:27 +0000 | [diff] [blame] | 571 | if (status & (SD_STATUS_SC | SD_STATUS_WC | SD_STATUS_RC)) |
Pierre Ossman | 17b0429 | 2007-07-22 22:18:46 +0200 | [diff] [blame] | 572 | cmd->error = -EILSEQ; |
Pete Popov | ba264b3 | 2005-09-21 06:18:27 +0000 | [diff] [blame] | 573 | |
| 574 | trans = host->flags & (HOST_F_XMIT | HOST_F_RECV); |
| 575 | |
Pierre Ossman | 17b0429 | 2007-07-22 22:18:46 +0200 | [diff] [blame] | 576 | if (!trans || cmd->error) { |
Manuel Lauss | 5c0a889 | 2008-06-09 08:38:35 +0200 | [diff] [blame] | 577 | IRQ_OFF(host, SD_CONFIG_TH | SD_CONFIG_RA | SD_CONFIG_RF); |
Pete Popov | ba264b3 | 2005-09-21 06:18:27 +0000 | [diff] [blame] | 578 | tasklet_schedule(&host->finish_task); |
| 579 | return; |
| 580 | } |
| 581 | |
| 582 | host->status = HOST_S_DATA; |
| 583 | |
Manuel Lauss | 1177d99 | 2011-08-02 19:51:07 +0200 | [diff] [blame] | 584 | if ((host->flags & (HOST_F_DMA | HOST_F_DBDMA))) { |
Pete Popov | ba264b3 | 2005-09-21 06:18:27 +0000 | [diff] [blame] | 585 | u32 channel = DMA_CHANNEL(host); |
| 586 | |
Manuel Lauss | 1177d99 | 2011-08-02 19:51:07 +0200 | [diff] [blame] | 587 | /* Start the DBDMA as soon as the buffer gets something in it */ |
Pete Popov | ba264b3 | 2005-09-21 06:18:27 +0000 | [diff] [blame] | 588 | |
| 589 | if (host->flags & HOST_F_RECV) { |
| 590 | u32 mask = SD_STATUS_DB | SD_STATUS_NE; |
| 591 | |
| 592 | while((status & mask) != mask) |
Manuel Lauss | 2f73bfb | 2014-07-23 16:36:26 +0200 | [diff] [blame] | 593 | status = __raw_readl(HOST_STATUS(host)); |
Pete Popov | ba264b3 | 2005-09-21 06:18:27 +0000 | [diff] [blame] | 594 | } |
| 595 | |
| 596 | au1xxx_dbdma_start(channel); |
| 597 | } |
| 598 | } |
| 599 | |
| 600 | static void au1xmmc_set_clock(struct au1xmmc_host *host, int rate) |
| 601 | { |
Manuel Lauss | b650759 | 2014-07-23 16:36:56 +0200 | [diff] [blame] | 602 | unsigned int pbus = clk_get_rate(host->clk); |
| 603 | unsigned int divisor = ((pbus / rate) / 2) - 1; |
Pete Popov | ba264b3 | 2005-09-21 06:18:27 +0000 | [diff] [blame] | 604 | u32 config; |
| 605 | |
Manuel Lauss | 2f73bfb | 2014-07-23 16:36:26 +0200 | [diff] [blame] | 606 | config = __raw_readl(HOST_CONFIG(host)); |
Pete Popov | ba264b3 | 2005-09-21 06:18:27 +0000 | [diff] [blame] | 607 | |
| 608 | config &= ~(SD_CONFIG_DIV); |
| 609 | config |= (divisor & SD_CONFIG_DIV) | SD_CONFIG_DE; |
| 610 | |
Manuel Lauss | 2f73bfb | 2014-07-23 16:36:26 +0200 | [diff] [blame] | 611 | __raw_writel(config, HOST_CONFIG(host)); |
| 612 | wmb(); /* drain writebuffer */ |
Pete Popov | ba264b3 | 2005-09-21 06:18:27 +0000 | [diff] [blame] | 613 | } |
| 614 | |
Manuel Lauss | 5c0a889 | 2008-06-09 08:38:35 +0200 | [diff] [blame] | 615 | static int au1xmmc_prepare_data(struct au1xmmc_host *host, |
| 616 | struct mmc_data *data) |
Pete Popov | ba264b3 | 2005-09-21 06:18:27 +0000 | [diff] [blame] | 617 | { |
Pavel Pisa | 2c171bf | 2006-05-19 21:48:03 +0100 | [diff] [blame] | 618 | int datalen = data->blocks * data->blksz; |
Pete Popov | ba264b3 | 2005-09-21 06:18:27 +0000 | [diff] [blame] | 619 | |
Pete Popov | ba264b3 | 2005-09-21 06:18:27 +0000 | [diff] [blame] | 620 | if (data->flags & MMC_DATA_READ) |
| 621 | host->flags |= HOST_F_RECV; |
| 622 | else |
| 623 | host->flags |= HOST_F_XMIT; |
| 624 | |
| 625 | if (host->mrq->stop) |
| 626 | host->flags |= HOST_F_STOP; |
| 627 | |
| 628 | host->dma.dir = DMA_BIDIRECTIONAL; |
| 629 | |
| 630 | host->dma.len = dma_map_sg(mmc_dev(host->mmc), data->sg, |
| 631 | data->sg_len, host->dma.dir); |
| 632 | |
| 633 | if (host->dma.len == 0) |
Pierre Ossman | 17b0429 | 2007-07-22 22:18:46 +0200 | [diff] [blame] | 634 | return -ETIMEDOUT; |
Pete Popov | ba264b3 | 2005-09-21 06:18:27 +0000 | [diff] [blame] | 635 | |
Manuel Lauss | 2f73bfb | 2014-07-23 16:36:26 +0200 | [diff] [blame] | 636 | __raw_writel(data->blksz - 1, HOST_BLKSIZE(host)); |
Pete Popov | ba264b3 | 2005-09-21 06:18:27 +0000 | [diff] [blame] | 637 | |
Manuel Lauss | 1177d99 | 2011-08-02 19:51:07 +0200 | [diff] [blame] | 638 | if (host->flags & (HOST_F_DMA | HOST_F_DBDMA)) { |
Pete Popov | ba264b3 | 2005-09-21 06:18:27 +0000 | [diff] [blame] | 639 | int i; |
| 640 | u32 channel = DMA_CHANNEL(host); |
| 641 | |
| 642 | au1xxx_dbdma_stop(channel); |
| 643 | |
Manuel Lauss | 5c0a889 | 2008-06-09 08:38:35 +0200 | [diff] [blame] | 644 | for (i = 0; i < host->dma.len; i++) { |
Pete Popov | ba264b3 | 2005-09-21 06:18:27 +0000 | [diff] [blame] | 645 | u32 ret = 0, flags = DDMA_FLAGS_NOIE; |
| 646 | struct scatterlist *sg = &data->sg[i]; |
| 647 | int sg_len = sg->length; |
| 648 | |
| 649 | int len = (datalen > sg_len) ? sg_len : datalen; |
| 650 | |
| 651 | if (i == host->dma.len - 1) |
| 652 | flags = DDMA_FLAGS_IE; |
| 653 | |
Manuel Lauss | 5c0a889 | 2008-06-09 08:38:35 +0200 | [diff] [blame] | 654 | if (host->flags & HOST_F_XMIT) { |
Manuel Lauss | ea071cc | 2009-10-13 20:22:34 +0200 | [diff] [blame] | 655 | ret = au1xxx_dbdma_put_source(channel, |
Manuel Lauss | 963accb | 2009-10-13 20:22:35 +0200 | [diff] [blame] | 656 | sg_phys(sg), len, flags); |
Manuel Lauss | 5c0a889 | 2008-06-09 08:38:35 +0200 | [diff] [blame] | 657 | } else { |
Manuel Lauss | ea071cc | 2009-10-13 20:22:34 +0200 | [diff] [blame] | 658 | ret = au1xxx_dbdma_put_dest(channel, |
Manuel Lauss | 963accb | 2009-10-13 20:22:35 +0200 | [diff] [blame] | 659 | sg_phys(sg), len, flags); |
Pete Popov | ba264b3 | 2005-09-21 06:18:27 +0000 | [diff] [blame] | 660 | } |
| 661 | |
Manuel Lauss | c4223c2 | 2008-06-09 08:36:13 +0200 | [diff] [blame] | 662 | if (!ret) |
Pete Popov | ba264b3 | 2005-09-21 06:18:27 +0000 | [diff] [blame] | 663 | goto dataerr; |
| 664 | |
| 665 | datalen -= len; |
| 666 | } |
Manuel Lauss | 5c0a889 | 2008-06-09 08:38:35 +0200 | [diff] [blame] | 667 | } else { |
Pete Popov | ba264b3 | 2005-09-21 06:18:27 +0000 | [diff] [blame] | 668 | host->pio.index = 0; |
| 669 | host->pio.offset = 0; |
| 670 | host->pio.len = datalen; |
| 671 | |
| 672 | if (host->flags & HOST_F_XMIT) |
| 673 | IRQ_ON(host, SD_CONFIG_TH); |
| 674 | else |
| 675 | IRQ_ON(host, SD_CONFIG_NE); |
Manuel Lauss | 5c0a889 | 2008-06-09 08:38:35 +0200 | [diff] [blame] | 676 | /* IRQ_ON(host, SD_CONFIG_RA | SD_CONFIG_RF); */ |
Pete Popov | ba264b3 | 2005-09-21 06:18:27 +0000 | [diff] [blame] | 677 | } |
| 678 | |
Pierre Ossman | 17b0429 | 2007-07-22 22:18:46 +0200 | [diff] [blame] | 679 | return 0; |
Pete Popov | ba264b3 | 2005-09-21 06:18:27 +0000 | [diff] [blame] | 680 | |
Manuel Lauss | c4223c2 | 2008-06-09 08:36:13 +0200 | [diff] [blame] | 681 | dataerr: |
| 682 | dma_unmap_sg(mmc_dev(host->mmc), data->sg, data->sg_len, |
| 683 | host->dma.dir); |
Pierre Ossman | 17b0429 | 2007-07-22 22:18:46 +0200 | [diff] [blame] | 684 | return -ETIMEDOUT; |
Pete Popov | ba264b3 | 2005-09-21 06:18:27 +0000 | [diff] [blame] | 685 | } |
| 686 | |
Manuel Lauss | 5c0a889 | 2008-06-09 08:38:35 +0200 | [diff] [blame] | 687 | /* This actually starts a command or data transaction */ |
Pete Popov | ba264b3 | 2005-09-21 06:18:27 +0000 | [diff] [blame] | 688 | static void au1xmmc_request(struct mmc_host* mmc, struct mmc_request* mrq) |
| 689 | { |
Pete Popov | ba264b3 | 2005-09-21 06:18:27 +0000 | [diff] [blame] | 690 | struct au1xmmc_host *host = mmc_priv(mmc); |
Pierre Ossman | 17b0429 | 2007-07-22 22:18:46 +0200 | [diff] [blame] | 691 | int ret = 0; |
Pete Popov | ba264b3 | 2005-09-21 06:18:27 +0000 | [diff] [blame] | 692 | |
| 693 | WARN_ON(irqs_disabled()); |
| 694 | WARN_ON(host->status != HOST_S_IDLE); |
| 695 | |
| 696 | host->mrq = mrq; |
| 697 | host->status = HOST_S_CMD; |
| 698 | |
Manuel Lauss | 88b8d9a | 2008-06-09 08:39:11 +0200 | [diff] [blame] | 699 | /* fail request immediately if no card is present */ |
Manuel Lauss | e2d2647 | 2008-06-27 18:25:18 +0200 | [diff] [blame] | 700 | if (0 == au1xmmc_card_inserted(mmc)) { |
Manuel Lauss | 88b8d9a | 2008-06-09 08:39:11 +0200 | [diff] [blame] | 701 | mrq->cmd->error = -ENOMEDIUM; |
| 702 | au1xmmc_finish_request(host); |
| 703 | return; |
| 704 | } |
| 705 | |
Pete Popov | ba264b3 | 2005-09-21 06:18:27 +0000 | [diff] [blame] | 706 | if (mrq->data) { |
| 707 | FLUSH_FIFO(host); |
| 708 | ret = au1xmmc_prepare_data(host, mrq->data); |
| 709 | } |
| 710 | |
Pierre Ossman | 17b0429 | 2007-07-22 22:18:46 +0200 | [diff] [blame] | 711 | if (!ret) |
Pierre Ossman | be0192a | 2007-07-24 21:11:47 +0200 | [diff] [blame] | 712 | ret = au1xmmc_send_command(host, 0, mrq->cmd, mrq->data); |
Pete Popov | ba264b3 | 2005-09-21 06:18:27 +0000 | [diff] [blame] | 713 | |
Pierre Ossman | 17b0429 | 2007-07-22 22:18:46 +0200 | [diff] [blame] | 714 | if (ret) { |
Pete Popov | ba264b3 | 2005-09-21 06:18:27 +0000 | [diff] [blame] | 715 | mrq->cmd->error = ret; |
| 716 | au1xmmc_finish_request(host); |
| 717 | } |
| 718 | } |
| 719 | |
| 720 | static void au1xmmc_reset_controller(struct au1xmmc_host *host) |
| 721 | { |
Pete Popov | ba264b3 | 2005-09-21 06:18:27 +0000 | [diff] [blame] | 722 | /* Apply the clock */ |
Manuel Lauss | 2f73bfb | 2014-07-23 16:36:26 +0200 | [diff] [blame] | 723 | __raw_writel(SD_ENABLE_CE, HOST_ENABLE(host)); |
| 724 | wmb(); /* drain writebuffer */ |
| 725 | mdelay(1); |
Pete Popov | ba264b3 | 2005-09-21 06:18:27 +0000 | [diff] [blame] | 726 | |
Manuel Lauss | 2f73bfb | 2014-07-23 16:36:26 +0200 | [diff] [blame] | 727 | __raw_writel(SD_ENABLE_R | SD_ENABLE_CE, HOST_ENABLE(host)); |
| 728 | wmb(); /* drain writebuffer */ |
| 729 | mdelay(5); |
Pete Popov | ba264b3 | 2005-09-21 06:18:27 +0000 | [diff] [blame] | 730 | |
Manuel Lauss | 2f73bfb | 2014-07-23 16:36:26 +0200 | [diff] [blame] | 731 | __raw_writel(~0, HOST_STATUS(host)); |
| 732 | wmb(); /* drain writebuffer */ |
Pete Popov | ba264b3 | 2005-09-21 06:18:27 +0000 | [diff] [blame] | 733 | |
Manuel Lauss | 2f73bfb | 2014-07-23 16:36:26 +0200 | [diff] [blame] | 734 | __raw_writel(0, HOST_BLKSIZE(host)); |
| 735 | __raw_writel(0x001fffff, HOST_TIMEOUT(host)); |
| 736 | wmb(); /* drain writebuffer */ |
Pete Popov | ba264b3 | 2005-09-21 06:18:27 +0000 | [diff] [blame] | 737 | |
Manuel Lauss | 2f73bfb | 2014-07-23 16:36:26 +0200 | [diff] [blame] | 738 | __raw_writel(SD_CONFIG2_EN, HOST_CONFIG2(host)); |
| 739 | wmb(); /* drain writebuffer */ |
Pete Popov | ba264b3 | 2005-09-21 06:18:27 +0000 | [diff] [blame] | 740 | |
Manuel Lauss | 2f73bfb | 2014-07-23 16:36:26 +0200 | [diff] [blame] | 741 | __raw_writel(SD_CONFIG2_EN | SD_CONFIG2_FF, HOST_CONFIG2(host)); |
| 742 | wmb(); /* drain writebuffer */ |
| 743 | mdelay(1); |
Pete Popov | ba264b3 | 2005-09-21 06:18:27 +0000 | [diff] [blame] | 744 | |
Manuel Lauss | 2f73bfb | 2014-07-23 16:36:26 +0200 | [diff] [blame] | 745 | __raw_writel(SD_CONFIG2_EN, HOST_CONFIG2(host)); |
| 746 | wmb(); /* drain writebuffer */ |
Pete Popov | ba264b3 | 2005-09-21 06:18:27 +0000 | [diff] [blame] | 747 | |
| 748 | /* Configure interrupts */ |
Manuel Lauss | 2f73bfb | 2014-07-23 16:36:26 +0200 | [diff] [blame] | 749 | __raw_writel(AU1XMMC_INTERRUPTS, HOST_CONFIG(host)); |
| 750 | wmb(); /* drain writebuffer */ |
Pete Popov | ba264b3 | 2005-09-21 06:18:27 +0000 | [diff] [blame] | 751 | } |
| 752 | |
| 753 | |
Manuel Lauss | 5c0a889 | 2008-06-09 08:38:35 +0200 | [diff] [blame] | 754 | static void au1xmmc_set_ios(struct mmc_host *mmc, struct mmc_ios *ios) |
Pete Popov | ba264b3 | 2005-09-21 06:18:27 +0000 | [diff] [blame] | 755 | { |
| 756 | struct au1xmmc_host *host = mmc_priv(mmc); |
Manuel Lauss | 281dd23 | 2008-06-09 08:37:33 +0200 | [diff] [blame] | 757 | u32 config2; |
Pete Popov | ba264b3 | 2005-09-21 06:18:27 +0000 | [diff] [blame] | 758 | |
Pete Popov | ba264b3 | 2005-09-21 06:18:27 +0000 | [diff] [blame] | 759 | if (ios->power_mode == MMC_POWER_OFF) |
| 760 | au1xmmc_set_power(host, 0); |
| 761 | else if (ios->power_mode == MMC_POWER_ON) { |
| 762 | au1xmmc_set_power(host, 1); |
| 763 | } |
| 764 | |
| 765 | if (ios->clock && ios->clock != host->clock) { |
| 766 | au1xmmc_set_clock(host, ios->clock); |
| 767 | host->clock = ios->clock; |
| 768 | } |
Manuel Lauss | 281dd23 | 2008-06-09 08:37:33 +0200 | [diff] [blame] | 769 | |
Manuel Lauss | 2f73bfb | 2014-07-23 16:36:26 +0200 | [diff] [blame] | 770 | config2 = __raw_readl(HOST_CONFIG2(host)); |
Manuel Lauss | 281dd23 | 2008-06-09 08:37:33 +0200 | [diff] [blame] | 771 | switch (ios->bus_width) { |
Manuel Lauss | 809f36c | 2011-11-01 20:03:30 +0100 | [diff] [blame] | 772 | case MMC_BUS_WIDTH_8: |
| 773 | config2 |= SD_CONFIG2_BB; |
| 774 | break; |
Manuel Lauss | 281dd23 | 2008-06-09 08:37:33 +0200 | [diff] [blame] | 775 | case MMC_BUS_WIDTH_4: |
Manuel Lauss | 809f36c | 2011-11-01 20:03:30 +0100 | [diff] [blame] | 776 | config2 &= ~SD_CONFIG2_BB; |
Manuel Lauss | 281dd23 | 2008-06-09 08:37:33 +0200 | [diff] [blame] | 777 | config2 |= SD_CONFIG2_WB; |
| 778 | break; |
| 779 | case MMC_BUS_WIDTH_1: |
Manuel Lauss | 809f36c | 2011-11-01 20:03:30 +0100 | [diff] [blame] | 780 | config2 &= ~(SD_CONFIG2_WB | SD_CONFIG2_BB); |
Manuel Lauss | 281dd23 | 2008-06-09 08:37:33 +0200 | [diff] [blame] | 781 | break; |
| 782 | } |
Manuel Lauss | 2f73bfb | 2014-07-23 16:36:26 +0200 | [diff] [blame] | 783 | __raw_writel(config2, HOST_CONFIG2(host)); |
| 784 | wmb(); /* drain writebuffer */ |
Pete Popov | ba264b3 | 2005-09-21 06:18:27 +0000 | [diff] [blame] | 785 | } |
| 786 | |
Manuel Lauss | c4223c2 | 2008-06-09 08:36:13 +0200 | [diff] [blame] | 787 | #define STATUS_TIMEOUT (SD_STATUS_RAT | SD_STATUS_DT) |
| 788 | #define STATUS_DATA_IN (SD_STATUS_NE) |
| 789 | #define STATUS_DATA_OUT (SD_STATUS_TH) |
| 790 | |
| 791 | static irqreturn_t au1xmmc_irq(int irq, void *dev_id) |
Pete Popov | ba264b3 | 2005-09-21 06:18:27 +0000 | [diff] [blame] | 792 | { |
Manuel Lauss | c4223c2 | 2008-06-09 08:36:13 +0200 | [diff] [blame] | 793 | struct au1xmmc_host *host = dev_id; |
| 794 | u32 status; |
| 795 | |
Manuel Lauss | 2f73bfb | 2014-07-23 16:36:26 +0200 | [diff] [blame] | 796 | status = __raw_readl(HOST_STATUS(host)); |
Manuel Lauss | c4223c2 | 2008-06-09 08:36:13 +0200 | [diff] [blame] | 797 | |
| 798 | if (!(status & SD_STATUS_I)) |
| 799 | return IRQ_NONE; /* not ours */ |
| 800 | |
Manuel Lauss | 20f522f | 2008-06-09 08:38:03 +0200 | [diff] [blame] | 801 | if (status & SD_STATUS_SI) /* SDIO */ |
| 802 | mmc_signal_sdio_irq(host->mmc); |
| 803 | |
Manuel Lauss | c4223c2 | 2008-06-09 08:36:13 +0200 | [diff] [blame] | 804 | if (host->mrq && (status & STATUS_TIMEOUT)) { |
| 805 | if (status & SD_STATUS_RAT) |
| 806 | host->mrq->cmd->error = -ETIMEDOUT; |
| 807 | else if (status & SD_STATUS_DT) |
| 808 | host->mrq->data->error = -ETIMEDOUT; |
| 809 | |
| 810 | /* In PIO mode, interrupts might still be enabled */ |
| 811 | IRQ_OFF(host, SD_CONFIG_NE | SD_CONFIG_TH); |
| 812 | |
| 813 | /* IRQ_OFF(host, SD_CONFIG_TH | SD_CONFIG_RA | SD_CONFIG_RF); */ |
| 814 | tasklet_schedule(&host->finish_task); |
| 815 | } |
| 816 | #if 0 |
| 817 | else if (status & SD_STATUS_DD) { |
| 818 | /* Sometimes we get a DD before a NE in PIO mode */ |
| 819 | if (!(host->flags & HOST_F_DMA) && (status & SD_STATUS_NE)) |
| 820 | au1xmmc_receive_pio(host); |
| 821 | else { |
| 822 | au1xmmc_data_complete(host, status); |
| 823 | /* tasklet_schedule(&host->data_task); */ |
| 824 | } |
| 825 | } |
| 826 | #endif |
| 827 | else if (status & SD_STATUS_CR) { |
| 828 | if (host->status == HOST_S_CMD) |
| 829 | au1xmmc_cmd_complete(host, status); |
| 830 | |
| 831 | } else if (!(host->flags & HOST_F_DMA)) { |
| 832 | if ((host->flags & HOST_F_XMIT) && (status & STATUS_DATA_OUT)) |
| 833 | au1xmmc_send_pio(host); |
| 834 | else if ((host->flags & HOST_F_RECV) && (status & STATUS_DATA_IN)) |
| 835 | au1xmmc_receive_pio(host); |
| 836 | |
| 837 | } else if (status & 0x203F3C70) { |
| 838 | DBG("Unhandled status %8.8x\n", host->pdev->id, |
| 839 | status); |
| 840 | } |
| 841 | |
Manuel Lauss | 2f73bfb | 2014-07-23 16:36:26 +0200 | [diff] [blame] | 842 | __raw_writel(status, HOST_STATUS(host)); |
| 843 | wmb(); /* drain writebuffer */ |
Manuel Lauss | c4223c2 | 2008-06-09 08:36:13 +0200 | [diff] [blame] | 844 | |
| 845 | return IRQ_HANDLED; |
| 846 | } |
| 847 | |
Manuel Lauss | c4223c2 | 2008-06-09 08:36:13 +0200 | [diff] [blame] | 848 | /* 8bit memory DMA device */ |
| 849 | static dbdev_tab_t au1xmmc_mem_dbdev = { |
| 850 | .dev_id = DSCR_CMD0_ALWAYS, |
| 851 | .dev_flags = DEV_FLAGS_ANYUSE, |
| 852 | .dev_tsize = 0, |
| 853 | .dev_devwidth = 8, |
| 854 | .dev_physaddr = 0x00000000, |
| 855 | .dev_intlevel = 0, |
| 856 | .dev_intpolarity = 0, |
| 857 | }; |
| 858 | static int memid; |
| 859 | |
| 860 | static void au1xmmc_dbdma_callback(int irq, void *dev_id) |
| 861 | { |
| 862 | struct au1xmmc_host *host = (struct au1xmmc_host *)dev_id; |
Pete Popov | ba264b3 | 2005-09-21 06:18:27 +0000 | [diff] [blame] | 863 | |
| 864 | /* Avoid spurious interrupts */ |
Pete Popov | ba264b3 | 2005-09-21 06:18:27 +0000 | [diff] [blame] | 865 | if (!host->mrq) |
| 866 | return; |
| 867 | |
| 868 | if (host->flags & HOST_F_STOP) |
| 869 | SEND_STOP(host); |
| 870 | |
| 871 | tasklet_schedule(&host->data_task); |
| 872 | } |
| 873 | |
Manuel Lauss | c4223c2 | 2008-06-09 08:36:13 +0200 | [diff] [blame] | 874 | static int au1xmmc_dbdma_init(struct au1xmmc_host *host) |
Pete Popov | ba264b3 | 2005-09-21 06:18:27 +0000 | [diff] [blame] | 875 | { |
Manuel Lauss | c4223c2 | 2008-06-09 08:36:13 +0200 | [diff] [blame] | 876 | struct resource *res; |
| 877 | int txid, rxid; |
Pete Popov | ba264b3 | 2005-09-21 06:18:27 +0000 | [diff] [blame] | 878 | |
Manuel Lauss | c4223c2 | 2008-06-09 08:36:13 +0200 | [diff] [blame] | 879 | res = platform_get_resource(host->pdev, IORESOURCE_DMA, 0); |
| 880 | if (!res) |
| 881 | return -ENODEV; |
| 882 | txid = res->start; |
Pete Popov | ba264b3 | 2005-09-21 06:18:27 +0000 | [diff] [blame] | 883 | |
Manuel Lauss | c4223c2 | 2008-06-09 08:36:13 +0200 | [diff] [blame] | 884 | res = platform_get_resource(host->pdev, IORESOURCE_DMA, 1); |
| 885 | if (!res) |
| 886 | return -ENODEV; |
| 887 | rxid = res->start; |
Pete Popov | ba264b3 | 2005-09-21 06:18:27 +0000 | [diff] [blame] | 888 | |
Manuel Lauss | c4223c2 | 2008-06-09 08:36:13 +0200 | [diff] [blame] | 889 | if (!memid) |
| 890 | return -ENODEV; |
Pete Popov | ba264b3 | 2005-09-21 06:18:27 +0000 | [diff] [blame] | 891 | |
Manuel Lauss | c4223c2 | 2008-06-09 08:36:13 +0200 | [diff] [blame] | 892 | host->tx_chan = au1xxx_dbdma_chan_alloc(memid, txid, |
| 893 | au1xmmc_dbdma_callback, (void *)host); |
| 894 | if (!host->tx_chan) { |
| 895 | dev_err(&host->pdev->dev, "cannot allocate TX DMA\n"); |
| 896 | return -ENODEV; |
| 897 | } |
Pete Popov | ba264b3 | 2005-09-21 06:18:27 +0000 | [diff] [blame] | 898 | |
Manuel Lauss | c4223c2 | 2008-06-09 08:36:13 +0200 | [diff] [blame] | 899 | host->rx_chan = au1xxx_dbdma_chan_alloc(rxid, memid, |
| 900 | au1xmmc_dbdma_callback, (void *)host); |
| 901 | if (!host->rx_chan) { |
| 902 | dev_err(&host->pdev->dev, "cannot allocate RX DMA\n"); |
| 903 | au1xxx_dbdma_chan_free(host->tx_chan); |
| 904 | return -ENODEV; |
| 905 | } |
Pete Popov | ba264b3 | 2005-09-21 06:18:27 +0000 | [diff] [blame] | 906 | |
Manuel Lauss | c4223c2 | 2008-06-09 08:36:13 +0200 | [diff] [blame] | 907 | au1xxx_dbdma_set_devwidth(host->tx_chan, 8); |
| 908 | au1xxx_dbdma_set_devwidth(host->rx_chan, 8); |
Pete Popov | ba264b3 | 2005-09-21 06:18:27 +0000 | [diff] [blame] | 909 | |
Manuel Lauss | c4223c2 | 2008-06-09 08:36:13 +0200 | [diff] [blame] | 910 | au1xxx_dbdma_ring_alloc(host->tx_chan, AU1XMMC_DESCRIPTOR_COUNT); |
| 911 | au1xxx_dbdma_ring_alloc(host->rx_chan, AU1XMMC_DESCRIPTOR_COUNT); |
Pete Popov | ba264b3 | 2005-09-21 06:18:27 +0000 | [diff] [blame] | 912 | |
Manuel Lauss | c4223c2 | 2008-06-09 08:36:13 +0200 | [diff] [blame] | 913 | /* DBDMA is good to go */ |
Manuel Lauss | 1177d99 | 2011-08-02 19:51:07 +0200 | [diff] [blame] | 914 | host->flags |= HOST_F_DMA | HOST_F_DBDMA; |
Pete Popov | ba264b3 | 2005-09-21 06:18:27 +0000 | [diff] [blame] | 915 | |
Manuel Lauss | c4223c2 | 2008-06-09 08:36:13 +0200 | [diff] [blame] | 916 | return 0; |
| 917 | } |
Pete Popov | ba264b3 | 2005-09-21 06:18:27 +0000 | [diff] [blame] | 918 | |
Manuel Lauss | c4223c2 | 2008-06-09 08:36:13 +0200 | [diff] [blame] | 919 | static void au1xmmc_dbdma_shutdown(struct au1xmmc_host *host) |
| 920 | { |
| 921 | if (host->flags & HOST_F_DMA) { |
| 922 | host->flags &= ~HOST_F_DMA; |
| 923 | au1xxx_dbdma_chan_free(host->tx_chan); |
| 924 | au1xxx_dbdma_chan_free(host->rx_chan); |
| 925 | } |
| 926 | } |
Pete Popov | ba264b3 | 2005-09-21 06:18:27 +0000 | [diff] [blame] | 927 | |
Manuel Lauss | 20f522f | 2008-06-09 08:38:03 +0200 | [diff] [blame] | 928 | static void au1xmmc_enable_sdio_irq(struct mmc_host *mmc, int en) |
| 929 | { |
| 930 | struct au1xmmc_host *host = mmc_priv(mmc); |
| 931 | |
| 932 | if (en) |
| 933 | IRQ_ON(host, SD_CONFIG_SI); |
| 934 | else |
| 935 | IRQ_OFF(host, SD_CONFIG_SI); |
| 936 | } |
| 937 | |
Yoichi Yuasa | bf8c80a | 2006-12-05 07:43:38 +0100 | [diff] [blame] | 938 | static const struct mmc_host_ops au1xmmc_ops = { |
Pete Popov | ba264b3 | 2005-09-21 06:18:27 +0000 | [diff] [blame] | 939 | .request = au1xmmc_request, |
| 940 | .set_ios = au1xmmc_set_ios, |
Manuel Lauss | 8299977 | 2007-01-25 10:29:24 +0100 | [diff] [blame] | 941 | .get_ro = au1xmmc_card_readonly, |
Manuel Lauss | e2d2647 | 2008-06-27 18:25:18 +0200 | [diff] [blame] | 942 | .get_cd = au1xmmc_card_inserted, |
Manuel Lauss | 20f522f | 2008-06-09 08:38:03 +0200 | [diff] [blame] | 943 | .enable_sdio_irq = au1xmmc_enable_sdio_irq, |
Pete Popov | ba264b3 | 2005-09-21 06:18:27 +0000 | [diff] [blame] | 944 | }; |
| 945 | |
Bill Pemberton | c3be1ef | 2012-11-19 13:23:06 -0500 | [diff] [blame] | 946 | static int au1xmmc_probe(struct platform_device *pdev) |
Pete Popov | ba264b3 | 2005-09-21 06:18:27 +0000 | [diff] [blame] | 947 | { |
Manuel Lauss | c4223c2 | 2008-06-09 08:36:13 +0200 | [diff] [blame] | 948 | struct mmc_host *mmc; |
| 949 | struct au1xmmc_host *host; |
| 950 | struct resource *r; |
Manuel Lauss | 809f36c | 2011-11-01 20:03:30 +0100 | [diff] [blame] | 951 | int ret, iflag; |
Pete Popov | ba264b3 | 2005-09-21 06:18:27 +0000 | [diff] [blame] | 952 | |
Manuel Lauss | c4223c2 | 2008-06-09 08:36:13 +0200 | [diff] [blame] | 953 | mmc = mmc_alloc_host(sizeof(struct au1xmmc_host), &pdev->dev); |
| 954 | if (!mmc) { |
| 955 | dev_err(&pdev->dev, "no memory for mmc_host\n"); |
| 956 | ret = -ENOMEM; |
| 957 | goto out0; |
Pete Popov | ba264b3 | 2005-09-21 06:18:27 +0000 | [diff] [blame] | 958 | } |
| 959 | |
Manuel Lauss | c4223c2 | 2008-06-09 08:36:13 +0200 | [diff] [blame] | 960 | host = mmc_priv(mmc); |
| 961 | host->mmc = mmc; |
| 962 | host->platdata = pdev->dev.platform_data; |
| 963 | host->pdev = pdev; |
Pete Popov | ba264b3 | 2005-09-21 06:18:27 +0000 | [diff] [blame] | 964 | |
Manuel Lauss | c4223c2 | 2008-06-09 08:36:13 +0200 | [diff] [blame] | 965 | ret = -ENODEV; |
| 966 | r = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 967 | if (!r) { |
| 968 | dev_err(&pdev->dev, "no mmio defined\n"); |
| 969 | goto out1; |
| 970 | } |
Pete Popov | ba264b3 | 2005-09-21 06:18:27 +0000 | [diff] [blame] | 971 | |
H Hartley Sweeten | 7a5ea56a | 2009-12-14 14:28:06 -0500 | [diff] [blame] | 972 | host->ioarea = request_mem_region(r->start, resource_size(r), |
Manuel Lauss | c4223c2 | 2008-06-09 08:36:13 +0200 | [diff] [blame] | 973 | pdev->name); |
| 974 | if (!host->ioarea) { |
| 975 | dev_err(&pdev->dev, "mmio already in use\n"); |
| 976 | goto out1; |
| 977 | } |
| 978 | |
Manuel Lauss | 2f73bfb | 2014-07-23 16:36:26 +0200 | [diff] [blame] | 979 | host->iobase = ioremap(r->start, 0x3c); |
Manuel Lauss | c4223c2 | 2008-06-09 08:36:13 +0200 | [diff] [blame] | 980 | if (!host->iobase) { |
| 981 | dev_err(&pdev->dev, "cannot remap mmio\n"); |
| 982 | goto out2; |
| 983 | } |
| 984 | |
| 985 | r = platform_get_resource(pdev, IORESOURCE_IRQ, 0); |
| 986 | if (!r) { |
| 987 | dev_err(&pdev->dev, "no IRQ defined\n"); |
| 988 | goto out3; |
| 989 | } |
Manuel Lauss | c4223c2 | 2008-06-09 08:36:13 +0200 | [diff] [blame] | 990 | host->irq = r->start; |
Manuel Lauss | c4223c2 | 2008-06-09 08:36:13 +0200 | [diff] [blame] | 991 | |
| 992 | mmc->ops = &au1xmmc_ops; |
| 993 | |
| 994 | mmc->f_min = 450000; |
| 995 | mmc->f_max = 24000000; |
| 996 | |
Manuel Lauss | c4223c2 | 2008-06-09 08:36:13 +0200 | [diff] [blame] | 997 | mmc->max_blk_size = 2048; |
| 998 | mmc->max_blk_count = 512; |
| 999 | |
| 1000 | mmc->ocr_avail = AU1XMMC_OCR; |
Manuel Lauss | 20f522f | 2008-06-09 08:38:03 +0200 | [diff] [blame] | 1001 | mmc->caps = MMC_CAP_4_BIT_DATA | MMC_CAP_SDIO_IRQ; |
Manuel Lauss | 809f36c | 2011-11-01 20:03:30 +0100 | [diff] [blame] | 1002 | mmc->max_segs = AU1XMMC_DESCRIPTOR_COUNT; |
| 1003 | |
| 1004 | iflag = IRQF_SHARED; /* Au1100/Au1200: one int for both ctrls */ |
| 1005 | |
| 1006 | switch (alchemy_get_cputype()) { |
| 1007 | case ALCHEMY_CPU_AU1100: |
| 1008 | mmc->max_seg_size = AU1100_MMC_DESCRIPTOR_SIZE; |
| 1009 | break; |
| 1010 | case ALCHEMY_CPU_AU1200: |
| 1011 | mmc->max_seg_size = AU1200_MMC_DESCRIPTOR_SIZE; |
| 1012 | break; |
| 1013 | case ALCHEMY_CPU_AU1300: |
| 1014 | iflag = 0; /* nothing is shared */ |
| 1015 | mmc->max_seg_size = AU1200_MMC_DESCRIPTOR_SIZE; |
| 1016 | mmc->f_max = 52000000; |
| 1017 | if (host->ioarea->start == AU1100_SD0_PHYS_ADDR) |
| 1018 | mmc->caps |= MMC_CAP_8_BIT_DATA; |
| 1019 | break; |
| 1020 | } |
| 1021 | |
| 1022 | ret = request_irq(host->irq, au1xmmc_irq, iflag, DRIVER_NAME, host); |
| 1023 | if (ret) { |
| 1024 | dev_err(&pdev->dev, "cannot grab IRQ\n"); |
| 1025 | goto out3; |
| 1026 | } |
Manuel Lauss | c4223c2 | 2008-06-09 08:36:13 +0200 | [diff] [blame] | 1027 | |
Manuel Lauss | b650759 | 2014-07-23 16:36:56 +0200 | [diff] [blame] | 1028 | host->clk = clk_get(&pdev->dev, ALCHEMY_PERIPH_CLK); |
| 1029 | if (IS_ERR(host->clk)) { |
| 1030 | dev_err(&pdev->dev, "cannot find clock\n"); |
Wei Yongjun | ee9d19d | 2014-08-14 09:00:19 +0800 | [diff] [blame] | 1031 | ret = PTR_ERR(host->clk); |
Manuel Lauss | b650759 | 2014-07-23 16:36:56 +0200 | [diff] [blame] | 1032 | goto out_irq; |
| 1033 | } |
Wei Yongjun | ee9d19d | 2014-08-14 09:00:19 +0800 | [diff] [blame] | 1034 | |
| 1035 | ret = clk_prepare_enable(host->clk); |
| 1036 | if (ret) { |
Manuel Lauss | b650759 | 2014-07-23 16:36:56 +0200 | [diff] [blame] | 1037 | dev_err(&pdev->dev, "cannot enable clock\n"); |
| 1038 | goto out_clk; |
| 1039 | } |
| 1040 | |
Manuel Lauss | c4223c2 | 2008-06-09 08:36:13 +0200 | [diff] [blame] | 1041 | host->status = HOST_S_IDLE; |
| 1042 | |
| 1043 | /* board-specific carddetect setup, if any */ |
| 1044 | if (host->platdata && host->platdata->cd_setup) { |
| 1045 | ret = host->platdata->cd_setup(mmc, 1); |
| 1046 | if (ret) { |
Manuel Lauss | e2d2647 | 2008-06-27 18:25:18 +0200 | [diff] [blame] | 1047 | dev_warn(&pdev->dev, "board CD setup failed\n"); |
| 1048 | mmc->caps |= MMC_CAP_NEEDS_POLL; |
Pete Popov | ba264b3 | 2005-09-21 06:18:27 +0000 | [diff] [blame] | 1049 | } |
Manuel Lauss | e2d2647 | 2008-06-27 18:25:18 +0200 | [diff] [blame] | 1050 | } else |
| 1051 | mmc->caps |= MMC_CAP_NEEDS_POLL; |
Pete Popov | ba264b3 | 2005-09-21 06:18:27 +0000 | [diff] [blame] | 1052 | |
Manuel Lauss | 3b83907 | 2009-10-14 09:38:06 +0200 | [diff] [blame] | 1053 | /* platform may not be able to use all advertised caps */ |
| 1054 | if (host->platdata) |
| 1055 | mmc->caps &= ~(host->platdata->mask_host_caps); |
| 1056 | |
Manuel Lauss | c4223c2 | 2008-06-09 08:36:13 +0200 | [diff] [blame] | 1057 | tasklet_init(&host->data_task, au1xmmc_tasklet_data, |
| 1058 | (unsigned long)host); |
Pete Popov | ba264b3 | 2005-09-21 06:18:27 +0000 | [diff] [blame] | 1059 | |
Manuel Lauss | c4223c2 | 2008-06-09 08:36:13 +0200 | [diff] [blame] | 1060 | tasklet_init(&host->finish_task, au1xmmc_tasklet_finish, |
| 1061 | (unsigned long)host); |
Pete Popov | ba264b3 | 2005-09-21 06:18:27 +0000 | [diff] [blame] | 1062 | |
Manuel Lauss | 1177d99 | 2011-08-02 19:51:07 +0200 | [diff] [blame] | 1063 | if (has_dbdma()) { |
| 1064 | ret = au1xmmc_dbdma_init(host); |
| 1065 | if (ret) |
Linus Torvalds | d674806 | 2011-11-03 13:28:14 -0700 | [diff] [blame] | 1066 | pr_info(DRIVER_NAME ": DBDMA init failed; using PIO\n"); |
Manuel Lauss | 1177d99 | 2011-08-02 19:51:07 +0200 | [diff] [blame] | 1067 | } |
Pete Popov | ba264b3 | 2005-09-21 06:18:27 +0000 | [diff] [blame] | 1068 | |
Manuel Lauss | c4223c2 | 2008-06-09 08:36:13 +0200 | [diff] [blame] | 1069 | #ifdef CONFIG_LEDS_CLASS |
| 1070 | if (host->platdata && host->platdata->led) { |
| 1071 | struct led_classdev *led = host->platdata->led; |
| 1072 | led->name = mmc_hostname(mmc); |
| 1073 | led->brightness = LED_OFF; |
| 1074 | led->default_trigger = mmc_hostname(mmc); |
| 1075 | ret = led_classdev_register(mmc_dev(mmc), led); |
| 1076 | if (ret) |
| 1077 | goto out5; |
| 1078 | } |
| 1079 | #endif |
Pierre Ossman | fe4a3c7 | 2006-11-21 17:54:23 +0100 | [diff] [blame] | 1080 | |
Manuel Lauss | c4223c2 | 2008-06-09 08:36:13 +0200 | [diff] [blame] | 1081 | au1xmmc_reset_controller(host); |
Pete Popov | ba264b3 | 2005-09-21 06:18:27 +0000 | [diff] [blame] | 1082 | |
Manuel Lauss | c4223c2 | 2008-06-09 08:36:13 +0200 | [diff] [blame] | 1083 | ret = mmc_add_host(mmc); |
| 1084 | if (ret) { |
| 1085 | dev_err(&pdev->dev, "cannot add mmc host\n"); |
| 1086 | goto out6; |
| 1087 | } |
Pete Popov | ba264b3 | 2005-09-21 06:18:27 +0000 | [diff] [blame] | 1088 | |
Manuel Lauss | dd8572a | 2008-07-17 13:07:28 +0200 | [diff] [blame] | 1089 | platform_set_drvdata(pdev, host); |
Pete Popov | ba264b3 | 2005-09-21 06:18:27 +0000 | [diff] [blame] | 1090 | |
Manuel Lauss | 2f73bfb | 2014-07-23 16:36:26 +0200 | [diff] [blame] | 1091 | pr_info(DRIVER_NAME ": MMC Controller %d set up at %p" |
Manuel Lauss | c4223c2 | 2008-06-09 08:36:13 +0200 | [diff] [blame] | 1092 | " (mode=%s)\n", pdev->id, host->iobase, |
| 1093 | host->flags & HOST_F_DMA ? "dma" : "pio"); |
Pete Popov | ba264b3 | 2005-09-21 06:18:27 +0000 | [diff] [blame] | 1094 | |
Manuel Lauss | c4223c2 | 2008-06-09 08:36:13 +0200 | [diff] [blame] | 1095 | return 0; /* all ok */ |
Pete Popov | ba264b3 | 2005-09-21 06:18:27 +0000 | [diff] [blame] | 1096 | |
Manuel Lauss | c4223c2 | 2008-06-09 08:36:13 +0200 | [diff] [blame] | 1097 | out6: |
| 1098 | #ifdef CONFIG_LEDS_CLASS |
| 1099 | if (host->platdata && host->platdata->led) |
| 1100 | led_classdev_unregister(host->platdata->led); |
| 1101 | out5: |
| 1102 | #endif |
Manuel Lauss | 2f73bfb | 2014-07-23 16:36:26 +0200 | [diff] [blame] | 1103 | __raw_writel(0, HOST_ENABLE(host)); |
| 1104 | __raw_writel(0, HOST_CONFIG(host)); |
| 1105 | __raw_writel(0, HOST_CONFIG2(host)); |
| 1106 | wmb(); /* drain writebuffer */ |
Manuel Lauss | c4223c2 | 2008-06-09 08:36:13 +0200 | [diff] [blame] | 1107 | |
Manuel Lauss | 1177d99 | 2011-08-02 19:51:07 +0200 | [diff] [blame] | 1108 | if (host->flags & HOST_F_DBDMA) |
| 1109 | au1xmmc_dbdma_shutdown(host); |
Manuel Lauss | c4223c2 | 2008-06-09 08:36:13 +0200 | [diff] [blame] | 1110 | |
| 1111 | tasklet_kill(&host->data_task); |
| 1112 | tasklet_kill(&host->finish_task); |
| 1113 | |
Manuel Lauss | e2d2647 | 2008-06-27 18:25:18 +0200 | [diff] [blame] | 1114 | if (host->platdata && host->platdata->cd_setup && |
| 1115 | !(mmc->caps & MMC_CAP_NEEDS_POLL)) |
Manuel Lauss | c4223c2 | 2008-06-09 08:36:13 +0200 | [diff] [blame] | 1116 | host->platdata->cd_setup(mmc, 0); |
Manuel Lauss | b650759 | 2014-07-23 16:36:56 +0200 | [diff] [blame] | 1117 | out_clk: |
| 1118 | clk_disable_unprepare(host->clk); |
| 1119 | clk_put(host->clk); |
| 1120 | out_irq: |
Manuel Lauss | c4223c2 | 2008-06-09 08:36:13 +0200 | [diff] [blame] | 1121 | free_irq(host->irq, host); |
| 1122 | out3: |
| 1123 | iounmap((void *)host->iobase); |
| 1124 | out2: |
| 1125 | release_resource(host->ioarea); |
| 1126 | kfree(host->ioarea); |
| 1127 | out1: |
| 1128 | mmc_free_host(mmc); |
| 1129 | out0: |
| 1130 | return ret; |
Pete Popov | ba264b3 | 2005-09-21 06:18:27 +0000 | [diff] [blame] | 1131 | } |
| 1132 | |
Bill Pemberton | 6e0ee71 | 2012-11-19 13:26:03 -0500 | [diff] [blame] | 1133 | static int au1xmmc_remove(struct platform_device *pdev) |
Pete Popov | ba264b3 | 2005-09-21 06:18:27 +0000 | [diff] [blame] | 1134 | { |
Manuel Lauss | dd8572a | 2008-07-17 13:07:28 +0200 | [diff] [blame] | 1135 | struct au1xmmc_host *host = platform_get_drvdata(pdev); |
Pete Popov | ba264b3 | 2005-09-21 06:18:27 +0000 | [diff] [blame] | 1136 | |
Manuel Lauss | dd8572a | 2008-07-17 13:07:28 +0200 | [diff] [blame] | 1137 | if (host) { |
| 1138 | mmc_remove_host(host->mmc); |
Pete Popov | ba264b3 | 2005-09-21 06:18:27 +0000 | [diff] [blame] | 1139 | |
Manuel Lauss | c4223c2 | 2008-06-09 08:36:13 +0200 | [diff] [blame] | 1140 | #ifdef CONFIG_LEDS_CLASS |
| 1141 | if (host->platdata && host->platdata->led) |
| 1142 | led_classdev_unregister(host->platdata->led); |
| 1143 | #endif |
| 1144 | |
Manuel Lauss | e2d2647 | 2008-06-27 18:25:18 +0200 | [diff] [blame] | 1145 | if (host->platdata && host->platdata->cd_setup && |
Manuel Lauss | dd8572a | 2008-07-17 13:07:28 +0200 | [diff] [blame] | 1146 | !(host->mmc->caps & MMC_CAP_NEEDS_POLL)) |
| 1147 | host->platdata->cd_setup(host->mmc, 0); |
Manuel Lauss | c4223c2 | 2008-06-09 08:36:13 +0200 | [diff] [blame] | 1148 | |
Manuel Lauss | 2f73bfb | 2014-07-23 16:36:26 +0200 | [diff] [blame] | 1149 | __raw_writel(0, HOST_ENABLE(host)); |
| 1150 | __raw_writel(0, HOST_CONFIG(host)); |
| 1151 | __raw_writel(0, HOST_CONFIG2(host)); |
| 1152 | wmb(); /* drain writebuffer */ |
Pete Popov | ba264b3 | 2005-09-21 06:18:27 +0000 | [diff] [blame] | 1153 | |
| 1154 | tasklet_kill(&host->data_task); |
| 1155 | tasklet_kill(&host->finish_task); |
| 1156 | |
Manuel Lauss | 1177d99 | 2011-08-02 19:51:07 +0200 | [diff] [blame] | 1157 | if (host->flags & HOST_F_DBDMA) |
| 1158 | au1xmmc_dbdma_shutdown(host); |
| 1159 | |
Pete Popov | ba264b3 | 2005-09-21 06:18:27 +0000 | [diff] [blame] | 1160 | au1xmmc_set_power(host, 0); |
| 1161 | |
Manuel Lauss | b650759 | 2014-07-23 16:36:56 +0200 | [diff] [blame] | 1162 | clk_disable_unprepare(host->clk); |
| 1163 | clk_put(host->clk); |
| 1164 | |
Manuel Lauss | c4223c2 | 2008-06-09 08:36:13 +0200 | [diff] [blame] | 1165 | free_irq(host->irq, host); |
| 1166 | iounmap((void *)host->iobase); |
| 1167 | release_resource(host->ioarea); |
| 1168 | kfree(host->ioarea); |
Pete Popov | ba264b3 | 2005-09-21 06:18:27 +0000 | [diff] [blame] | 1169 | |
Manuel Lauss | dd8572a | 2008-07-17 13:07:28 +0200 | [diff] [blame] | 1170 | mmc_free_host(host->mmc); |
Pete Popov | ba264b3 | 2005-09-21 06:18:27 +0000 | [diff] [blame] | 1171 | } |
Pete Popov | ba264b3 | 2005-09-21 06:18:27 +0000 | [diff] [blame] | 1172 | return 0; |
| 1173 | } |
| 1174 | |
Manuel Lauss | dd8572a | 2008-07-17 13:07:28 +0200 | [diff] [blame] | 1175 | #ifdef CONFIG_PM |
| 1176 | static int au1xmmc_suspend(struct platform_device *pdev, pm_message_t state) |
| 1177 | { |
| 1178 | struct au1xmmc_host *host = platform_get_drvdata(pdev); |
Manuel Lauss | dd8572a | 2008-07-17 13:07:28 +0200 | [diff] [blame] | 1179 | |
Manuel Lauss | 2f73bfb | 2014-07-23 16:36:26 +0200 | [diff] [blame] | 1180 | __raw_writel(0, HOST_CONFIG2(host)); |
| 1181 | __raw_writel(0, HOST_CONFIG(host)); |
| 1182 | __raw_writel(0xffffffff, HOST_STATUS(host)); |
| 1183 | __raw_writel(0, HOST_ENABLE(host)); |
| 1184 | wmb(); /* drain writebuffer */ |
Manuel Lauss | dd8572a | 2008-07-17 13:07:28 +0200 | [diff] [blame] | 1185 | |
| 1186 | return 0; |
| 1187 | } |
| 1188 | |
| 1189 | static int au1xmmc_resume(struct platform_device *pdev) |
| 1190 | { |
| 1191 | struct au1xmmc_host *host = platform_get_drvdata(pdev); |
| 1192 | |
| 1193 | au1xmmc_reset_controller(host); |
| 1194 | |
Ulf Hansson | 1e63d48 | 2013-09-25 10:55:23 +0200 | [diff] [blame] | 1195 | return 0; |
Manuel Lauss | dd8572a | 2008-07-17 13:07:28 +0200 | [diff] [blame] | 1196 | } |
| 1197 | #else |
| 1198 | #define au1xmmc_suspend NULL |
| 1199 | #define au1xmmc_resume NULL |
| 1200 | #endif |
| 1201 | |
Martin Michlmayr | b256f9d | 2006-03-04 23:01:13 +0000 | [diff] [blame] | 1202 | static struct platform_driver au1xmmc_driver = { |
Pete Popov | ba264b3 | 2005-09-21 06:18:27 +0000 | [diff] [blame] | 1203 | .probe = au1xmmc_probe, |
| 1204 | .remove = au1xmmc_remove, |
Manuel Lauss | dd8572a | 2008-07-17 13:07:28 +0200 | [diff] [blame] | 1205 | .suspend = au1xmmc_suspend, |
| 1206 | .resume = au1xmmc_resume, |
Martin Michlmayr | b256f9d | 2006-03-04 23:01:13 +0000 | [diff] [blame] | 1207 | .driver = { |
| 1208 | .name = DRIVER_NAME, |
| 1209 | }, |
Pete Popov | ba264b3 | 2005-09-21 06:18:27 +0000 | [diff] [blame] | 1210 | }; |
| 1211 | |
| 1212 | static int __init au1xmmc_init(void) |
| 1213 | { |
Manuel Lauss | 1177d99 | 2011-08-02 19:51:07 +0200 | [diff] [blame] | 1214 | if (has_dbdma()) { |
| 1215 | /* DSCR_CMD0_ALWAYS has a stride of 32 bits, we need a stride |
| 1216 | * of 8 bits. And since devices are shared, we need to create |
| 1217 | * our own to avoid freaking out other devices. |
| 1218 | */ |
| 1219 | memid = au1xxx_ddma_add_device(&au1xmmc_mem_dbdev); |
| 1220 | if (!memid) |
Linus Torvalds | d674806 | 2011-11-03 13:28:14 -0700 | [diff] [blame] | 1221 | pr_err("au1xmmc: cannot add memory dbdma\n"); |
Manuel Lauss | 1177d99 | 2011-08-02 19:51:07 +0200 | [diff] [blame] | 1222 | } |
Martin Michlmayr | b256f9d | 2006-03-04 23:01:13 +0000 | [diff] [blame] | 1223 | return platform_driver_register(&au1xmmc_driver); |
Pete Popov | ba264b3 | 2005-09-21 06:18:27 +0000 | [diff] [blame] | 1224 | } |
| 1225 | |
| 1226 | static void __exit au1xmmc_exit(void) |
| 1227 | { |
Manuel Lauss | 1177d99 | 2011-08-02 19:51:07 +0200 | [diff] [blame] | 1228 | if (has_dbdma() && memid) |
Manuel Lauss | c4223c2 | 2008-06-09 08:36:13 +0200 | [diff] [blame] | 1229 | au1xxx_ddma_del_device(memid); |
Manuel Lauss | 1177d99 | 2011-08-02 19:51:07 +0200 | [diff] [blame] | 1230 | |
Martin Michlmayr | b256f9d | 2006-03-04 23:01:13 +0000 | [diff] [blame] | 1231 | platform_driver_unregister(&au1xmmc_driver); |
Pete Popov | ba264b3 | 2005-09-21 06:18:27 +0000 | [diff] [blame] | 1232 | } |
| 1233 | |
| 1234 | module_init(au1xmmc_init); |
| 1235 | module_exit(au1xmmc_exit); |
| 1236 | |
Pete Popov | ba264b3 | 2005-09-21 06:18:27 +0000 | [diff] [blame] | 1237 | MODULE_AUTHOR("Advanced Micro Devices, Inc"); |
| 1238 | MODULE_DESCRIPTION("MMC/SD driver for the Alchemy Au1XXX"); |
| 1239 | MODULE_LICENSE("GPL"); |
Kay Sievers | bc65c72 | 2008-04-15 14:34:28 -0700 | [diff] [blame] | 1240 | MODULE_ALIAS("platform:au1xxx-mmc"); |