San Mehat | 9d2bd73 | 2009-09-22 16:44:22 -0700 | [diff] [blame] | 1 | /* |
| 2 | * linux/drivers/mmc/host/msm_sdcc.c - Qualcomm MSM 7X00A SDCC Driver |
| 3 | * |
| 4 | * Copyright (C) 2007 Google Inc, |
| 5 | * Copyright (C) 2003 Deep Blue Solutions, Ltd, All Rights Reserved. |
Krishna Konda | 941604a | 2012-01-10 17:46:34 -0800 | [diff] [blame] | 6 | * Copyright (c) 2009-2012, Code Aurora Forum. All rights reserved. |
San Mehat | 9d2bd73 | 2009-09-22 16:44:22 -0700 | [diff] [blame] | 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU General Public License version 2 as |
| 10 | * published by the Free Software Foundation. |
| 11 | * |
| 12 | * Based on mmci.c |
| 13 | * |
| 14 | * Author: San Mehat (san@android.com) |
| 15 | * |
| 16 | */ |
| 17 | |
| 18 | #include <linux/module.h> |
| 19 | #include <linux/moduleparam.h> |
| 20 | #include <linux/init.h> |
| 21 | #include <linux/ioport.h> |
Sujit Reddy Thumma | 7285c2e | 2011-11-04 10:18:15 +0530 | [diff] [blame] | 22 | #include <linux/of.h> |
San Mehat | 9d2bd73 | 2009-09-22 16:44:22 -0700 | [diff] [blame] | 23 | #include <linux/device.h> |
| 24 | #include <linux/interrupt.h> |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 25 | #include <linux/irq.h> |
San Mehat | 9d2bd73 | 2009-09-22 16:44:22 -0700 | [diff] [blame] | 26 | #include <linux/delay.h> |
| 27 | #include <linux/err.h> |
| 28 | #include <linux/highmem.h> |
| 29 | #include <linux/log2.h> |
| 30 | #include <linux/mmc/host.h> |
| 31 | #include <linux/mmc/card.h> |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 32 | #include <linux/mmc/mmc.h> |
San Mehat | b3fa579 | 2009-11-02 18:46:09 -0800 | [diff] [blame] | 33 | #include <linux/mmc/sdio.h> |
San Mehat | 9d2bd73 | 2009-09-22 16:44:22 -0700 | [diff] [blame] | 34 | #include <linux/clk.h> |
| 35 | #include <linux/scatterlist.h> |
| 36 | #include <linux/platform_device.h> |
| 37 | #include <linux/dma-mapping.h> |
| 38 | #include <linux/debugfs.h> |
| 39 | #include <linux/io.h> |
| 40 | #include <linux/memory.h> |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 41 | #include <linux/pm_runtime.h> |
| 42 | #include <linux/wakelock.h> |
Sahitya Tummala | 7a89248 | 2011-01-18 11:22:49 +0530 | [diff] [blame] | 43 | #include <linux/gpio.h> |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 44 | #include <linux/regulator/consumer.h> |
| 45 | #include <linux/slab.h> |
Subhash Jadavani | 933e6a6 | 2011-12-26 18:05:04 +0530 | [diff] [blame] | 46 | #include <linux/pm_qos_params.h> |
San Mehat | 9d2bd73 | 2009-09-22 16:44:22 -0700 | [diff] [blame] | 47 | |
| 48 | #include <asm/cacheflush.h> |
| 49 | #include <asm/div64.h> |
| 50 | #include <asm/sizes.h> |
| 51 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 52 | #include <asm/mach/mmc.h> |
San Mehat | 9d2bd73 | 2009-09-22 16:44:22 -0700 | [diff] [blame] | 53 | #include <mach/msm_iomap.h> |
Sahitya Tummala | b08bb35 | 2010-12-08 15:03:05 +0530 | [diff] [blame] | 54 | #include <mach/clk.h> |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 55 | #include <mach/dma.h> |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 56 | #include <mach/sdio_al.h> |
Subhash Jadavani | c9b8575 | 2012-04-13 11:16:49 +0530 | [diff] [blame^] | 57 | #include <mach/mpm.h> |
San Mehat | 9d2bd73 | 2009-09-22 16:44:22 -0700 | [diff] [blame] | 58 | |
San Mehat | 9d2bd73 | 2009-09-22 16:44:22 -0700 | [diff] [blame] | 59 | #include "msm_sdcc.h" |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 60 | #include "msm_sdcc_dml.h" |
San Mehat | 9d2bd73 | 2009-09-22 16:44:22 -0700 | [diff] [blame] | 61 | |
| 62 | #define DRIVER_NAME "msm-sdcc" |
| 63 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 64 | #define DBG(host, fmt, args...) \ |
| 65 | pr_debug("%s: %s: " fmt "\n", mmc_hostname(host->mmc), __func__ , args) |
| 66 | |
| 67 | #define IRQ_DEBUG 0 |
| 68 | #define SPS_SDCC_PRODUCER_PIPE_INDEX 1 |
| 69 | #define SPS_SDCC_CONSUMER_PIPE_INDEX 2 |
| 70 | #define SPS_CONS_PERIPHERAL 0 |
| 71 | #define SPS_PROD_PERIPHERAL 1 |
Subhash Jadavani | e6e1b82 | 2012-03-12 18:17:58 +0530 | [diff] [blame] | 72 | /* Use SPS only if transfer size is more than this macro */ |
| 73 | #define SPS_MIN_XFER_SIZE MCI_FIFOSIZE |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 74 | |
| 75 | #if defined(CONFIG_DEBUG_FS) |
| 76 | static void msmsdcc_dbg_createhost(struct msmsdcc_host *); |
| 77 | static struct dentry *debugfs_dir; |
| 78 | static struct dentry *debugfs_file; |
| 79 | static int msmsdcc_dbg_init(void); |
| 80 | #endif |
| 81 | |
Subhash Jadavani | 8766e35 | 2011-11-30 11:30:32 +0530 | [diff] [blame] | 82 | static u64 dma_mask = DMA_BIT_MASK(32); |
San Mehat | 9d2bd73 | 2009-09-22 16:44:22 -0700 | [diff] [blame] | 83 | static unsigned int msmsdcc_pwrsave = 1; |
San Mehat | 9d2bd73 | 2009-09-22 16:44:22 -0700 | [diff] [blame] | 84 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 85 | static struct mmc_command dummy52cmd; |
| 86 | static struct mmc_request dummy52mrq = { |
| 87 | .cmd = &dummy52cmd, |
| 88 | .data = NULL, |
| 89 | .stop = NULL, |
| 90 | }; |
| 91 | static struct mmc_command dummy52cmd = { |
| 92 | .opcode = SD_IO_RW_DIRECT, |
| 93 | .flags = MMC_RSP_PRESENT, |
| 94 | .data = NULL, |
| 95 | .mrq = &dummy52mrq, |
| 96 | }; |
| 97 | /* |
| 98 | * An array holding the Tuning pattern to compare with when |
| 99 | * executing a tuning cycle. |
| 100 | */ |
Subhash Jadavani | 56e0eaa | 2012-03-13 18:06:04 +0530 | [diff] [blame] | 101 | static const u32 tuning_block_64[] = { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 102 | 0x00FF0FFF, 0xCCC3CCFF, 0xFFCC3CC3, 0xEFFEFFFE, |
| 103 | 0xDDFFDFFF, 0xFBFFFBFF, 0xFF7FFFBF, 0xEFBDF777, |
| 104 | 0xF0FFF0FF, 0x3CCCFC0F, 0xCFCC33CC, 0xEEFFEFFF, |
| 105 | 0xFDFFFDFF, 0xFFBFFFDF, 0xFFF7FFBB, 0xDE7B7FF7 |
| 106 | }; |
San Mehat | 865c806 | 2009-11-13 13:42:06 -0800 | [diff] [blame] | 107 | |
Subhash Jadavani | 56e0eaa | 2012-03-13 18:06:04 +0530 | [diff] [blame] | 108 | static const u32 tuning_block_128[] = { |
| 109 | 0xFF00FFFF, 0x0000FFFF, 0xCCCCFFFF, 0xCCCC33CC, |
| 110 | 0xCC3333CC, 0xFFFFCCCC, 0xFFFFEEFF, 0xFFEEEEFF, |
| 111 | 0xFFDDFFFF, 0xDDDDFFFF, 0xBBFFFFFF, 0xBBFFFFFF, |
| 112 | 0xFFFFFFBB, 0xFFFFFF77, 0x77FF7777, 0xFFEEDDBB, |
| 113 | 0x00FFFFFF, 0x00FFFFFF, 0xCCFFFF00, 0xCC33CCCC, |
| 114 | 0x3333CCCC, 0xFFCCCCCC, 0xFFEEFFFF, 0xEEEEFFFF, |
| 115 | 0xDDFFFFFF, 0xDDFFFFFF, 0xFFFFFFDD, 0xFFFFFFBB, |
| 116 | 0xFFFFBBBB, 0xFFFF77FF, 0xFF7777FF, 0xEEDDBB77 |
| 117 | }; |
| 118 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 119 | #if IRQ_DEBUG == 1 |
| 120 | static char *irq_status_bits[] = { "cmdcrcfail", "datcrcfail", "cmdtimeout", |
| 121 | "dattimeout", "txunderrun", "rxoverrun", |
| 122 | "cmdrespend", "cmdsent", "dataend", NULL, |
| 123 | "datablkend", "cmdactive", "txactive", |
| 124 | "rxactive", "txhalfempty", "rxhalffull", |
| 125 | "txfifofull", "rxfifofull", "txfifoempty", |
| 126 | "rxfifoempty", "txdataavlbl", "rxdataavlbl", |
| 127 | "sdiointr", "progdone", "atacmdcompl", |
| 128 | "sdiointrope", "ccstimeout", NULL, NULL, |
| 129 | NULL, NULL, NULL }; |
| 130 | |
| 131 | static void |
| 132 | msmsdcc_print_status(struct msmsdcc_host *host, char *hdr, uint32_t status) |
San Mehat | 865c806 | 2009-11-13 13:42:06 -0800 | [diff] [blame] | 133 | { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 134 | int i; |
San Mehat | 8b1c2ba | 2009-11-16 10:17:30 -0800 | [diff] [blame] | 135 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 136 | pr_debug("%s-%s ", mmc_hostname(host->mmc), hdr); |
| 137 | for (i = 0; i < 32; i++) { |
| 138 | if (status & (1 << i)) |
| 139 | pr_debug("%s ", irq_status_bits[i]); |
San Mehat | 865c806 | 2009-11-13 13:42:06 -0800 | [diff] [blame] | 140 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 141 | pr_debug("\n"); |
San Mehat | c7fc937 | 2009-11-22 17:19:07 -0800 | [diff] [blame] | 142 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 143 | #endif |
San Mehat | 865c806 | 2009-11-13 13:42:06 -0800 | [diff] [blame] | 144 | |
San Mehat | 9d2bd73 | 2009-09-22 16:44:22 -0700 | [diff] [blame] | 145 | static void |
| 146 | msmsdcc_start_command(struct msmsdcc_host *host, struct mmc_command *cmd, |
| 147 | u32 c); |
Subhash Jadavani | dd43295 | 2012-03-28 11:25:56 +0530 | [diff] [blame] | 148 | static inline void msmsdcc_sync_reg_wr(struct msmsdcc_host *host); |
Subhash Jadavani | 15f29db | 2011-10-13 09:57:13 +0530 | [diff] [blame] | 149 | static inline void msmsdcc_delay(struct msmsdcc_host *host); |
Subhash Jadavani | b52b4d7 | 2011-12-05 19:16:28 +0530 | [diff] [blame] | 150 | static void msmsdcc_dump_sdcc_state(struct msmsdcc_host *host); |
Oluwafemi Adeyemi | ecfa3df | 2012-02-28 18:08:54 -0800 | [diff] [blame] | 151 | static void msmsdcc_sg_start(struct msmsdcc_host *host); |
Oluwafemi Adeyemi | 4ea731c | 2012-03-07 14:47:36 -0800 | [diff] [blame] | 152 | static int msmsdcc_vreg_reset(struct msmsdcc_host *host); |
Subhash Jadavani | 15f29db | 2011-10-13 09:57:13 +0530 | [diff] [blame] | 153 | |
Sujit Reddy Thumma | cf6c4ed | 2011-11-14 17:20:36 +0530 | [diff] [blame] | 154 | static inline unsigned short msmsdcc_get_nr_sg(struct msmsdcc_host *host) |
| 155 | { |
| 156 | unsigned short ret = NR_SG; |
| 157 | |
| 158 | if (host->is_sps_mode) { |
Subhash Jadavani | d4aff7f | 2011-12-08 18:08:19 +0530 | [diff] [blame] | 159 | ret = SPS_MAX_DESCS; |
Sujit Reddy Thumma | cf6c4ed | 2011-11-14 17:20:36 +0530 | [diff] [blame] | 160 | } else { /* DMA or PIO mode */ |
| 161 | if (NR_SG > MAX_NR_SG_DMA_PIO) |
| 162 | ret = MAX_NR_SG_DMA_PIO; |
| 163 | } |
| 164 | |
| 165 | return ret; |
| 166 | } |
| 167 | |
Subhash Jadavani | 933e6a6 | 2011-12-26 18:05:04 +0530 | [diff] [blame] | 168 | /* Prevent idle power collapse(pc) while operating in peripheral mode */ |
| 169 | static void msmsdcc_pm_qos_update_latency(struct msmsdcc_host *host, int vote) |
| 170 | { |
| 171 | u32 swfi_latency = 0; |
| 172 | |
| 173 | if (!host->plat->swfi_latency) |
| 174 | return; |
| 175 | |
| 176 | swfi_latency = host->plat->swfi_latency + 1; |
| 177 | |
| 178 | if (vote) |
| 179 | pm_qos_update_request(&host->pm_qos_req_dma, |
| 180 | swfi_latency); |
| 181 | else |
| 182 | pm_qos_update_request(&host->pm_qos_req_dma, |
| 183 | PM_QOS_DEFAULT_VALUE); |
| 184 | } |
| 185 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 186 | #ifdef CONFIG_MMC_MSM_SPS_SUPPORT |
| 187 | static int msmsdcc_sps_reset_ep(struct msmsdcc_host *host, |
| 188 | struct msmsdcc_sps_ep_conn_data *ep); |
| 189 | static int msmsdcc_sps_restore_ep(struct msmsdcc_host *host, |
| 190 | struct msmsdcc_sps_ep_conn_data *ep); |
| 191 | #else |
| 192 | static inline int msmsdcc_sps_init_ep_conn(struct msmsdcc_host *host, |
| 193 | struct msmsdcc_sps_ep_conn_data *ep, |
| 194 | bool is_producer) { return 0; } |
| 195 | static inline void msmsdcc_sps_exit_ep_conn(struct msmsdcc_host *host, |
| 196 | struct msmsdcc_sps_ep_conn_data *ep) { } |
| 197 | static inline int msmsdcc_sps_reset_ep(struct msmsdcc_host *host, |
| 198 | struct msmsdcc_sps_ep_conn_data *ep) |
Sahitya Tummala | b08bb35 | 2010-12-08 15:03:05 +0530 | [diff] [blame] | 199 | { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 200 | return 0; |
| 201 | } |
| 202 | static inline int msmsdcc_sps_restore_ep(struct msmsdcc_host *host, |
| 203 | struct msmsdcc_sps_ep_conn_data *ep) |
| 204 | { |
| 205 | return 0; |
| 206 | } |
| 207 | static inline int msmsdcc_sps_init(struct msmsdcc_host *host) { return 0; } |
| 208 | static inline void msmsdcc_sps_exit(struct msmsdcc_host *host) {} |
| 209 | #endif /* CONFIG_MMC_MSM_SPS_SUPPORT */ |
Sahitya Tummala | b08bb35 | 2010-12-08 15:03:05 +0530 | [diff] [blame] | 210 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 211 | /** |
Subhash Jadavani | b5b0774 | 2011-08-29 17:48:07 +0530 | [diff] [blame] | 212 | * Apply soft reset to all SDCC BAM pipes |
| 213 | * |
| 214 | * This function applies soft reset to SDCC BAM pipe. |
| 215 | * |
| 216 | * This function should be called to recover from error |
| 217 | * conditions encountered during CMD/DATA tranfsers with card. |
| 218 | * |
| 219 | * @host - Pointer to driver's host structure |
| 220 | * |
| 221 | */ |
| 222 | static void msmsdcc_sps_pipes_reset_and_restore(struct msmsdcc_host *host) |
| 223 | { |
| 224 | int rc; |
| 225 | |
| 226 | /* Reset all SDCC BAM pipes */ |
| 227 | rc = msmsdcc_sps_reset_ep(host, &host->sps.prod); |
| 228 | if (rc) |
| 229 | pr_err("%s:msmsdcc_sps_reset_ep(prod) error=%d\n", |
| 230 | mmc_hostname(host->mmc), rc); |
| 231 | rc = msmsdcc_sps_reset_ep(host, &host->sps.cons); |
| 232 | if (rc) |
| 233 | pr_err("%s:msmsdcc_sps_reset_ep(cons) error=%d\n", |
| 234 | mmc_hostname(host->mmc), rc); |
| 235 | |
| 236 | /* Restore all BAM pipes connections */ |
| 237 | rc = msmsdcc_sps_restore_ep(host, &host->sps.prod); |
| 238 | if (rc) |
| 239 | pr_err("%s:msmsdcc_sps_restore_ep(prod) error=%d\n", |
| 240 | mmc_hostname(host->mmc), rc); |
| 241 | rc = msmsdcc_sps_restore_ep(host, &host->sps.cons); |
| 242 | if (rc) |
| 243 | pr_err("%s:msmsdcc_sps_restore_ep(cons) error=%d\n", |
| 244 | mmc_hostname(host->mmc), rc); |
| 245 | } |
| 246 | |
| 247 | /** |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 248 | * Apply soft reset |
| 249 | * |
Subhash Jadavani | b5b0774 | 2011-08-29 17:48:07 +0530 | [diff] [blame] | 250 | * This function applies soft reset to SDCC core and DML core. |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 251 | * |
| 252 | * This function should be called to recover from error |
| 253 | * conditions encountered with CMD/DATA tranfsers with card. |
| 254 | * |
| 255 | * Soft reset should only be used with SDCC controller v4. |
| 256 | * |
| 257 | * @host - Pointer to driver's host structure |
| 258 | * |
| 259 | */ |
Subhash Jadavani | 15f29db | 2011-10-13 09:57:13 +0530 | [diff] [blame] | 260 | static void msmsdcc_soft_reset(struct msmsdcc_host *host) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 261 | { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 262 | /* |
| 263 | * Reset SDCC controller's DPSM (data path state machine |
| 264 | * and CPSM (command path state machine). |
| 265 | */ |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 266 | writel_relaxed(0, host->base + MMCICOMMAND); |
Subhash Jadavani | dd43295 | 2012-03-28 11:25:56 +0530 | [diff] [blame] | 267 | msmsdcc_sync_reg_wr(host); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 268 | writel_relaxed(0, host->base + MMCIDATACTRL); |
Subhash Jadavani | dd43295 | 2012-03-28 11:25:56 +0530 | [diff] [blame] | 269 | msmsdcc_sync_reg_wr(host); |
Subhash Jadavani | 15f29db | 2011-10-13 09:57:13 +0530 | [diff] [blame] | 270 | } |
Sahitya Tummala | b08bb35 | 2010-12-08 15:03:05 +0530 | [diff] [blame] | 271 | |
Subhash Jadavani | 15f29db | 2011-10-13 09:57:13 +0530 | [diff] [blame] | 272 | static void msmsdcc_hard_reset(struct msmsdcc_host *host) |
| 273 | { |
| 274 | int ret; |
Sahitya Tummala | b08bb35 | 2010-12-08 15:03:05 +0530 | [diff] [blame] | 275 | |
Subhash Jadavani | 15f29db | 2011-10-13 09:57:13 +0530 | [diff] [blame] | 276 | /* Reset the controller */ |
| 277 | ret = clk_reset(host->clk, CLK_RESET_ASSERT); |
| 278 | if (ret) |
| 279 | pr_err("%s: Clock assert failed at %u Hz" |
| 280 | " with err %d\n", mmc_hostname(host->mmc), |
| 281 | host->clk_rate, ret); |
| 282 | |
| 283 | ret = clk_reset(host->clk, CLK_RESET_DEASSERT); |
| 284 | if (ret) |
| 285 | pr_err("%s: Clock deassert failed at %u Hz" |
| 286 | " with err %d\n", mmc_hostname(host->mmc), |
| 287 | host->clk_rate, ret); |
| 288 | |
Subhash Jadavani | dd43295 | 2012-03-28 11:25:56 +0530 | [diff] [blame] | 289 | mb(); |
Subhash Jadavani | 15f29db | 2011-10-13 09:57:13 +0530 | [diff] [blame] | 290 | /* Give some delay for clock reset to propogate to controller */ |
| 291 | msmsdcc_delay(host); |
Sahitya Tummala | b08bb35 | 2010-12-08 15:03:05 +0530 | [diff] [blame] | 292 | } |
| 293 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 294 | static void msmsdcc_reset_and_restore(struct msmsdcc_host *host) |
| 295 | { |
Pratibhasagar V | 1c11da6 | 2011-11-14 12:36:35 +0530 | [diff] [blame] | 296 | if (host->sdcc_version) { |
Subhash Jadavani | 15f29db | 2011-10-13 09:57:13 +0530 | [diff] [blame] | 297 | if (host->is_sps_mode) { |
| 298 | /* Reset DML first */ |
| 299 | msmsdcc_dml_reset(host); |
| 300 | /* |
| 301 | * delay the SPS pipe reset in thread context as |
| 302 | * sps_connect/sps_disconnect APIs can be called |
| 303 | * only from non-atomic context. |
| 304 | */ |
| 305 | host->sps.pipe_reset_pending = true; |
| 306 | } |
| 307 | mb(); |
| 308 | msmsdcc_soft_reset(host); |
| 309 | |
| 310 | pr_debug("%s: Applied soft reset to Controller\n", |
| 311 | mmc_hostname(host->mmc)); |
| 312 | |
| 313 | if (host->is_sps_mode) |
| 314 | msmsdcc_dml_init(host); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 315 | } else { |
| 316 | /* Give Clock reset (hard reset) to controller */ |
| 317 | u32 mci_clk = 0; |
| 318 | u32 mci_mask0 = 0; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 319 | |
| 320 | /* Save the controller state */ |
| 321 | mci_clk = readl_relaxed(host->base + MMCICLOCK); |
| 322 | mci_mask0 = readl_relaxed(host->base + MMCIMASK0); |
Sujit Reddy Thumma | f4a999c | 2012-02-09 23:14:45 +0530 | [diff] [blame] | 323 | host->pwr = readl_relaxed(host->base + MMCIPOWER); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 324 | mb(); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 325 | |
Subhash Jadavani | 15f29db | 2011-10-13 09:57:13 +0530 | [diff] [blame] | 326 | msmsdcc_hard_reset(host); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 327 | pr_debug("%s: Controller has been reinitialized\n", |
| 328 | mmc_hostname(host->mmc)); |
| 329 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 330 | /* Restore the contoller state */ |
| 331 | writel_relaxed(host->pwr, host->base + MMCIPOWER); |
Subhash Jadavani | dd43295 | 2012-03-28 11:25:56 +0530 | [diff] [blame] | 332 | msmsdcc_sync_reg_wr(host); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 333 | writel_relaxed(mci_clk, host->base + MMCICLOCK); |
Subhash Jadavani | dd43295 | 2012-03-28 11:25:56 +0530 | [diff] [blame] | 334 | msmsdcc_sync_reg_wr(host); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 335 | writel_relaxed(mci_mask0, host->base + MMCIMASK0); |
Subhash Jadavani | 15f29db | 2011-10-13 09:57:13 +0530 | [diff] [blame] | 336 | mb(); /* no delay required after writing to MASK0 register */ |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 337 | } |
Subhash Jadavani | 15f29db | 2011-10-13 09:57:13 +0530 | [diff] [blame] | 338 | |
Oluwafemi Adeyemi | cb79144 | 2011-07-11 22:51:25 -0700 | [diff] [blame] | 339 | if (host->dummy_52_needed) |
| 340 | host->dummy_52_needed = 0; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 341 | } |
| 342 | |
| 343 | static int |
San Mehat | 9d2bd73 | 2009-09-22 16:44:22 -0700 | [diff] [blame] | 344 | msmsdcc_request_end(struct msmsdcc_host *host, struct mmc_request *mrq) |
| 345 | { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 346 | int retval = 0; |
| 347 | |
San Mehat | 9d2bd73 | 2009-09-22 16:44:22 -0700 | [diff] [blame] | 348 | BUG_ON(host->curr.data); |
| 349 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 350 | del_timer(&host->req_tout_timer); |
| 351 | |
San Mehat | 9d2bd73 | 2009-09-22 16:44:22 -0700 | [diff] [blame] | 352 | if (mrq->data) |
| 353 | mrq->data->bytes_xfered = host->curr.data_xfered; |
| 354 | if (mrq->cmd->error == -ETIMEDOUT) |
| 355 | mdelay(5); |
| 356 | |
Subhash Jadavani | ed6b0e4 | 2012-03-07 16:36:27 +0530 | [diff] [blame] | 357 | /* Clear current request information as current request has ended */ |
| 358 | memset(&host->curr, 0, sizeof(struct msmsdcc_curr_req)); |
| 359 | |
San Mehat | 9d2bd73 | 2009-09-22 16:44:22 -0700 | [diff] [blame] | 360 | /* |
| 361 | * Need to drop the host lock here; mmc_request_done may call |
| 362 | * back into the driver... |
| 363 | */ |
| 364 | spin_unlock(&host->lock); |
| 365 | mmc_request_done(host->mmc, mrq); |
| 366 | spin_lock(&host->lock); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 367 | |
| 368 | return retval; |
San Mehat | 9d2bd73 | 2009-09-22 16:44:22 -0700 | [diff] [blame] | 369 | } |
| 370 | |
| 371 | static void |
| 372 | msmsdcc_stop_data(struct msmsdcc_host *host) |
| 373 | { |
San Mehat | 9d2bd73 | 2009-09-22 16:44:22 -0700 | [diff] [blame] | 374 | host->curr.data = NULL; |
Sahitya Tummala | 0c521cc | 2010-12-08 15:03:07 +0530 | [diff] [blame] | 375 | host->curr.got_dataend = 0; |
Subhash Jadavani | 7a651aa | 2011-08-03 20:44:58 +0530 | [diff] [blame] | 376 | host->curr.wait_for_auto_prog_done = 0; |
| 377 | host->curr.got_auto_prog_done = 0; |
Krishna Konda | 3f5d48f | 2011-07-27 10:47:31 -0700 | [diff] [blame] | 378 | writel_relaxed(readl_relaxed(host->base + MMCIDATACTRL) & |
| 379 | (~(MCI_DPSM_ENABLE)), host->base + MMCIDATACTRL); |
Subhash Jadavani | dd43295 | 2012-03-28 11:25:56 +0530 | [diff] [blame] | 380 | msmsdcc_sync_reg_wr(host); /* Allow the DPSM to be reset */ |
San Mehat | 9d2bd73 | 2009-09-22 16:44:22 -0700 | [diff] [blame] | 381 | } |
| 382 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 383 | static inline uint32_t msmsdcc_fifo_addr(struct msmsdcc_host *host) |
San Mehat | 9d2bd73 | 2009-09-22 16:44:22 -0700 | [diff] [blame] | 384 | { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 385 | return host->core_memres->start + MMCIFIFO; |
| 386 | } |
| 387 | |
| 388 | static inline unsigned int msmsdcc_get_min_sup_clk_rate( |
| 389 | struct msmsdcc_host *host); |
Subhash Jadavani | 8f13e5b | 2011-08-04 21:15:11 +0530 | [diff] [blame] | 390 | |
Subhash Jadavani | dd43295 | 2012-03-28 11:25:56 +0530 | [diff] [blame] | 391 | static inline void msmsdcc_sync_reg_wr(struct msmsdcc_host *host) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 392 | { |
| 393 | mb(); |
Subhash Jadavani | dd43295 | 2012-03-28 11:25:56 +0530 | [diff] [blame] | 394 | if (!host->sdcc_version) |
| 395 | udelay(host->reg_write_delay); |
| 396 | else if (readl_relaxed(host->base + MCI_STATUS2) & |
| 397 | MCI_MCLK_REG_WR_ACTIVE) { |
| 398 | ktime_t start, diff; |
Subhash Jadavani | 8f13e5b | 2011-08-04 21:15:11 +0530 | [diff] [blame] | 399 | |
Subhash Jadavani | 8f13e5b | 2011-08-04 21:15:11 +0530 | [diff] [blame] | 400 | start = ktime_get(); |
| 401 | while (readl_relaxed(host->base + MCI_STATUS2) & |
| 402 | MCI_MCLK_REG_WR_ACTIVE) { |
| 403 | diff = ktime_sub(ktime_get(), start); |
| 404 | /* poll for max. 1 ms */ |
| 405 | if (ktime_to_us(diff) > 1000) { |
| 406 | pr_warning("%s: previous reg. write is" |
| 407 | " still active\n", |
| 408 | mmc_hostname(host->mmc)); |
| 409 | break; |
| 410 | } |
| 411 | } |
| 412 | } |
San Mehat | 9d2bd73 | 2009-09-22 16:44:22 -0700 | [diff] [blame] | 413 | } |
| 414 | |
Subhash Jadavani | dd43295 | 2012-03-28 11:25:56 +0530 | [diff] [blame] | 415 | static inline void msmsdcc_delay(struct msmsdcc_host *host) |
| 416 | { |
| 417 | udelay(host->reg_write_delay); |
| 418 | |
| 419 | } |
| 420 | |
San Mehat | 56a8b5b | 2009-11-21 12:29:46 -0800 | [diff] [blame] | 421 | static inline void |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 422 | msmsdcc_start_command_exec(struct msmsdcc_host *host, u32 arg, u32 c) |
| 423 | { |
| 424 | writel_relaxed(arg, host->base + MMCIARGUMENT); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 425 | writel_relaxed(c, host->base + MMCICOMMAND); |
Subhash Jadavani | 15f29db | 2011-10-13 09:57:13 +0530 | [diff] [blame] | 426 | /* |
| 427 | * As after sending the command, we don't write any of the |
| 428 | * controller registers and just wait for the |
| 429 | * CMD_RESPOND_END/CMD_SENT/Command failure notication |
| 430 | * from Controller. |
| 431 | */ |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 432 | mb(); |
San Mehat | 56a8b5b | 2009-11-21 12:29:46 -0800 | [diff] [blame] | 433 | } |
| 434 | |
| 435 | static void |
| 436 | msmsdcc_dma_exec_func(struct msm_dmov_cmd *cmd) |
| 437 | { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 438 | struct msmsdcc_host *host = (struct msmsdcc_host *)cmd->user; |
San Mehat | 56a8b5b | 2009-11-21 12:29:46 -0800 | [diff] [blame] | 439 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 440 | writel_relaxed(host->cmd_timeout, host->base + MMCIDATATIMER); |
| 441 | writel_relaxed((unsigned int)host->curr.xfer_size, |
| 442 | host->base + MMCIDATALENGTH); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 443 | writel_relaxed(host->cmd_datactrl, host->base + MMCIDATACTRL); |
Subhash Jadavani | dd43295 | 2012-03-28 11:25:56 +0530 | [diff] [blame] | 444 | msmsdcc_sync_reg_wr(host); /* Force delay prior to ADM or command */ |
San Mehat | 56a8b5b | 2009-11-21 12:29:46 -0800 | [diff] [blame] | 445 | |
San Mehat | 6ac9ea6 | 2009-12-02 17:24:58 -0800 | [diff] [blame] | 446 | if (host->cmd_cmd) { |
| 447 | msmsdcc_start_command_exec(host, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 448 | (u32)host->cmd_cmd->arg, (u32)host->cmd_c); |
San Mehat | 6ac9ea6 | 2009-12-02 17:24:58 -0800 | [diff] [blame] | 449 | } |
San Mehat | 56a8b5b | 2009-11-21 12:29:46 -0800 | [diff] [blame] | 450 | } |
| 451 | |
San Mehat | 9d2bd73 | 2009-09-22 16:44:22 -0700 | [diff] [blame] | 452 | static void |
Sahitya Tummala | 62612cf | 2010-12-08 15:03:03 +0530 | [diff] [blame] | 453 | msmsdcc_dma_complete_tlet(unsigned long data) |
San Mehat | 9d2bd73 | 2009-09-22 16:44:22 -0700 | [diff] [blame] | 454 | { |
Sahitya Tummala | 62612cf | 2010-12-08 15:03:03 +0530 | [diff] [blame] | 455 | struct msmsdcc_host *host = (struct msmsdcc_host *)data; |
San Mehat | 9d2bd73 | 2009-09-22 16:44:22 -0700 | [diff] [blame] | 456 | unsigned long flags; |
| 457 | struct mmc_request *mrq; |
| 458 | |
| 459 | spin_lock_irqsave(&host->lock, flags); |
| 460 | mrq = host->curr.mrq; |
| 461 | BUG_ON(!mrq); |
| 462 | |
Sahitya Tummala | 62612cf | 2010-12-08 15:03:03 +0530 | [diff] [blame] | 463 | if (!(host->dma.result & DMOV_RSLT_VALID)) { |
Joe Perches | 0a7ff7c | 2009-09-22 16:44:23 -0700 | [diff] [blame] | 464 | pr_err("msmsdcc: Invalid DataMover result\n"); |
San Mehat | 9d2bd73 | 2009-09-22 16:44:22 -0700 | [diff] [blame] | 465 | goto out; |
| 466 | } |
| 467 | |
Sahitya Tummala | 62612cf | 2010-12-08 15:03:03 +0530 | [diff] [blame] | 468 | if (host->dma.result & DMOV_RSLT_DONE) { |
San Mehat | 9d2bd73 | 2009-09-22 16:44:22 -0700 | [diff] [blame] | 469 | host->curr.data_xfered = host->curr.xfer_size; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 470 | host->curr.xfer_remain -= host->curr.xfer_size; |
San Mehat | 9d2bd73 | 2009-09-22 16:44:22 -0700 | [diff] [blame] | 471 | } else { |
| 472 | /* Error or flush */ |
Sahitya Tummala | 62612cf | 2010-12-08 15:03:03 +0530 | [diff] [blame] | 473 | if (host->dma.result & DMOV_RSLT_ERROR) |
Joe Perches | 0a7ff7c | 2009-09-22 16:44:23 -0700 | [diff] [blame] | 474 | pr_err("%s: DMA error (0x%.8x)\n", |
Sahitya Tummala | 62612cf | 2010-12-08 15:03:03 +0530 | [diff] [blame] | 475 | mmc_hostname(host->mmc), host->dma.result); |
| 476 | if (host->dma.result & DMOV_RSLT_FLUSH) |
Joe Perches | 0a7ff7c | 2009-09-22 16:44:23 -0700 | [diff] [blame] | 477 | pr_err("%s: DMA channel flushed (0x%.8x)\n", |
Sahitya Tummala | 62612cf | 2010-12-08 15:03:03 +0530 | [diff] [blame] | 478 | mmc_hostname(host->mmc), host->dma.result); |
Sahitya Tummala | 62612cf | 2010-12-08 15:03:03 +0530 | [diff] [blame] | 479 | pr_err("Flush data: %.8x %.8x %.8x %.8x %.8x %.8x\n", |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 480 | host->dma.err.flush[0], host->dma.err.flush[1], |
| 481 | host->dma.err.flush[2], host->dma.err.flush[3], |
| 482 | host->dma.err.flush[4], |
| 483 | host->dma.err.flush[5]); |
Sahitya Tummala | b08bb35 | 2010-12-08 15:03:05 +0530 | [diff] [blame] | 484 | msmsdcc_reset_and_restore(host); |
San Mehat | 9d2bd73 | 2009-09-22 16:44:22 -0700 | [diff] [blame] | 485 | if (!mrq->data->error) |
| 486 | mrq->data->error = -EIO; |
| 487 | } |
San Mehat | 9d2bd73 | 2009-09-22 16:44:22 -0700 | [diff] [blame] | 488 | dma_unmap_sg(mmc_dev(host->mmc), host->dma.sg, host->dma.num_ents, |
| 489 | host->dma.dir); |
| 490 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 491 | if (host->curr.user_pages) { |
| 492 | struct scatterlist *sg = host->dma.sg; |
| 493 | int i; |
| 494 | |
| 495 | for (i = 0; i < host->dma.num_ents; i++, sg++) |
| 496 | flush_dcache_page(sg_page(sg)); |
| 497 | } |
| 498 | |
San Mehat | 9d2bd73 | 2009-09-22 16:44:22 -0700 | [diff] [blame] | 499 | host->dma.sg = NULL; |
San Mehat | 56a8b5b | 2009-11-21 12:29:46 -0800 | [diff] [blame] | 500 | host->dma.busy = 0; |
San Mehat | 9d2bd73 | 2009-09-22 16:44:22 -0700 | [diff] [blame] | 501 | |
Subhash Jadavani | 7a651aa | 2011-08-03 20:44:58 +0530 | [diff] [blame] | 502 | if ((host->curr.got_dataend && (!host->curr.wait_for_auto_prog_done || |
| 503 | (host->curr.wait_for_auto_prog_done && |
| 504 | host->curr.got_auto_prog_done))) || mrq->data->error) { |
San Mehat | 9d2bd73 | 2009-09-22 16:44:22 -0700 | [diff] [blame] | 505 | /* |
| 506 | * If we've already gotten our DATAEND / DATABLKEND |
| 507 | * for this request, then complete it through here. |
| 508 | */ |
San Mehat | 9d2bd73 | 2009-09-22 16:44:22 -0700 | [diff] [blame] | 509 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 510 | if (!mrq->data->error) { |
San Mehat | 9d2bd73 | 2009-09-22 16:44:22 -0700 | [diff] [blame] | 511 | host->curr.data_xfered = host->curr.xfer_size; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 512 | host->curr.xfer_remain -= host->curr.xfer_size; |
| 513 | } |
Oluwafemi Adeyemi | cb79144 | 2011-07-11 22:51:25 -0700 | [diff] [blame] | 514 | if (host->dummy_52_needed) { |
| 515 | mrq->data->bytes_xfered = host->curr.data_xfered; |
| 516 | host->dummy_52_sent = 1; |
| 517 | msmsdcc_start_command(host, &dummy52cmd, |
| 518 | MCI_CPSM_PROGENA); |
| 519 | goto out; |
| 520 | } |
| 521 | msmsdcc_stop_data(host); |
Sujit Reddy Thumma | 055106d | 2012-01-16 15:16:26 +0530 | [diff] [blame] | 522 | if (!mrq->data->stop || mrq->cmd->error || |
Subhash Jadavani | a8e5ecb | 2011-08-25 19:19:58 +0530 | [diff] [blame] | 523 | (mrq->sbc && !mrq->data->error)) { |
San Mehat | 9d2bd73 | 2009-09-22 16:44:22 -0700 | [diff] [blame] | 524 | mrq->data->bytes_xfered = host->curr.data_xfered; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 525 | del_timer(&host->req_tout_timer); |
Subhash Jadavani | ed6b0e4 | 2012-03-07 16:36:27 +0530 | [diff] [blame] | 526 | /* |
| 527 | * Clear current request information as current |
| 528 | * request has ended |
| 529 | */ |
| 530 | memset(&host->curr, 0, sizeof(struct msmsdcc_curr_req)); |
San Mehat | 9d2bd73 | 2009-09-22 16:44:22 -0700 | [diff] [blame] | 531 | spin_unlock_irqrestore(&host->lock, flags); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 532 | |
San Mehat | 9d2bd73 | 2009-09-22 16:44:22 -0700 | [diff] [blame] | 533 | mmc_request_done(host->mmc, mrq); |
| 534 | return; |
Sujit Reddy Thumma | 055106d | 2012-01-16 15:16:26 +0530 | [diff] [blame] | 535 | } else if (mrq->data->stop && ((mrq->sbc && mrq->data->error) |
| 536 | || !mrq->sbc)) { |
| 537 | msmsdcc_start_command(host, mrq->data->stop, 0); |
Subhash Jadavani | a8e5ecb | 2011-08-25 19:19:58 +0530 | [diff] [blame] | 538 | } |
San Mehat | 9d2bd73 | 2009-09-22 16:44:22 -0700 | [diff] [blame] | 539 | } |
| 540 | |
| 541 | out: |
| 542 | spin_unlock_irqrestore(&host->lock, flags); |
| 543 | return; |
| 544 | } |
| 545 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 546 | #ifdef CONFIG_MMC_MSM_SPS_SUPPORT |
| 547 | /** |
| 548 | * Callback notification from SPS driver |
| 549 | * |
| 550 | * This callback function gets triggered called from |
| 551 | * SPS driver when requested SPS data transfer is |
| 552 | * completed. |
| 553 | * |
| 554 | * SPS driver invokes this callback in BAM irq context so |
| 555 | * SDCC driver schedule a tasklet for further processing |
| 556 | * this callback notification at later point of time in |
| 557 | * tasklet context and immediately returns control back |
| 558 | * to SPS driver. |
| 559 | * |
| 560 | * @nofity - Pointer to sps event notify sturcture |
| 561 | * |
| 562 | */ |
| 563 | static void |
| 564 | msmsdcc_sps_complete_cb(struct sps_event_notify *notify) |
| 565 | { |
| 566 | struct msmsdcc_host *host = |
| 567 | (struct msmsdcc_host *) |
| 568 | ((struct sps_event_notify *)notify)->user; |
| 569 | |
| 570 | host->sps.notify = *notify; |
| 571 | pr_debug("%s: %s: sps ev_id=%d, addr=0x%x, size=0x%x, flags=0x%x\n", |
| 572 | mmc_hostname(host->mmc), __func__, notify->event_id, |
| 573 | notify->data.transfer.iovec.addr, |
| 574 | notify->data.transfer.iovec.size, |
| 575 | notify->data.transfer.iovec.flags); |
| 576 | /* Schedule a tasklet for completing data transfer */ |
| 577 | tasklet_schedule(&host->sps.tlet); |
| 578 | } |
| 579 | |
| 580 | /** |
| 581 | * Tasklet handler for processing SPS callback event |
| 582 | * |
| 583 | * This function processing SPS event notification and |
| 584 | * checks if the SPS transfer is completed or not and |
| 585 | * then accordingly notifies status to MMC core layer. |
| 586 | * |
| 587 | * This function is called in tasklet context. |
| 588 | * |
| 589 | * @data - Pointer to sdcc driver data |
| 590 | * |
| 591 | */ |
| 592 | static void msmsdcc_sps_complete_tlet(unsigned long data) |
| 593 | { |
| 594 | unsigned long flags; |
| 595 | int i, rc; |
| 596 | u32 data_xfered = 0; |
| 597 | struct mmc_request *mrq; |
| 598 | struct sps_iovec iovec; |
| 599 | struct sps_pipe *sps_pipe_handle; |
| 600 | struct msmsdcc_host *host = (struct msmsdcc_host *)data; |
| 601 | struct sps_event_notify *notify = &host->sps.notify; |
| 602 | |
| 603 | spin_lock_irqsave(&host->lock, flags); |
| 604 | if (host->sps.dir == DMA_FROM_DEVICE) |
| 605 | sps_pipe_handle = host->sps.prod.pipe_handle; |
| 606 | else |
| 607 | sps_pipe_handle = host->sps.cons.pipe_handle; |
| 608 | mrq = host->curr.mrq; |
| 609 | |
| 610 | if (!mrq) { |
| 611 | spin_unlock_irqrestore(&host->lock, flags); |
| 612 | return; |
| 613 | } |
| 614 | |
| 615 | pr_debug("%s: %s: sps event_id=%d\n", |
| 616 | mmc_hostname(host->mmc), __func__, |
| 617 | notify->event_id); |
| 618 | |
| 619 | if (msmsdcc_is_dml_busy(host)) { |
| 620 | /* oops !!! this should never happen. */ |
| 621 | pr_err("%s: %s: Received SPS EOT event" |
| 622 | " but DML HW is still busy !!!\n", |
| 623 | mmc_hostname(host->mmc), __func__); |
| 624 | } |
| 625 | /* |
| 626 | * Got End of transfer event!!! Check if all of the data |
| 627 | * has been transferred? |
| 628 | */ |
| 629 | for (i = 0; i < host->sps.xfer_req_cnt; i++) { |
| 630 | rc = sps_get_iovec(sps_pipe_handle, &iovec); |
| 631 | if (rc) { |
| 632 | pr_err("%s: %s: sps_get_iovec() failed rc=%d, i=%d", |
| 633 | mmc_hostname(host->mmc), __func__, rc, i); |
| 634 | break; |
| 635 | } |
| 636 | data_xfered += iovec.size; |
| 637 | } |
| 638 | |
| 639 | if (data_xfered == host->curr.xfer_size) { |
| 640 | host->curr.data_xfered = host->curr.xfer_size; |
| 641 | host->curr.xfer_remain -= host->curr.xfer_size; |
| 642 | pr_debug("%s: Data xfer success. data_xfered=0x%x", |
| 643 | mmc_hostname(host->mmc), |
| 644 | host->curr.xfer_size); |
| 645 | } else { |
| 646 | pr_err("%s: Data xfer failed. data_xfered=0x%x," |
| 647 | " xfer_size=%d", mmc_hostname(host->mmc), |
| 648 | data_xfered, host->curr.xfer_size); |
| 649 | msmsdcc_reset_and_restore(host); |
| 650 | if (!mrq->data->error) |
| 651 | mrq->data->error = -EIO; |
| 652 | } |
| 653 | |
| 654 | /* Unmap sg buffers */ |
| 655 | dma_unmap_sg(mmc_dev(host->mmc), host->sps.sg, host->sps.num_ents, |
| 656 | host->sps.dir); |
| 657 | |
| 658 | host->sps.sg = NULL; |
| 659 | host->sps.busy = 0; |
| 660 | |
Subhash Jadavani | 7a651aa | 2011-08-03 20:44:58 +0530 | [diff] [blame] | 661 | if ((host->curr.got_dataend && (!host->curr.wait_for_auto_prog_done || |
| 662 | (host->curr.wait_for_auto_prog_done && |
| 663 | host->curr.got_auto_prog_done))) || mrq->data->error) { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 664 | /* |
| 665 | * If we've already gotten our DATAEND / DATABLKEND |
| 666 | * for this request, then complete it through here. |
| 667 | */ |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 668 | |
| 669 | if (!mrq->data->error) { |
| 670 | host->curr.data_xfered = host->curr.xfer_size; |
| 671 | host->curr.xfer_remain -= host->curr.xfer_size; |
| 672 | } |
Oluwafemi Adeyemi | cb79144 | 2011-07-11 22:51:25 -0700 | [diff] [blame] | 673 | if (host->dummy_52_needed) { |
| 674 | mrq->data->bytes_xfered = host->curr.data_xfered; |
| 675 | host->dummy_52_sent = 1; |
| 676 | msmsdcc_start_command(host, &dummy52cmd, |
| 677 | MCI_CPSM_PROGENA); |
Jeff Ohlstein | 5e48f24 | 2011-11-01 14:59:48 -0700 | [diff] [blame] | 678 | spin_unlock_irqrestore(&host->lock, flags); |
Oluwafemi Adeyemi | cb79144 | 2011-07-11 22:51:25 -0700 | [diff] [blame] | 679 | return; |
| 680 | } |
| 681 | msmsdcc_stop_data(host); |
Sujit Reddy Thumma | 055106d | 2012-01-16 15:16:26 +0530 | [diff] [blame] | 682 | if (!mrq->data->stop || mrq->cmd->error || |
Subhash Jadavani | a8e5ecb | 2011-08-25 19:19:58 +0530 | [diff] [blame] | 683 | (mrq->sbc && !mrq->data->error)) { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 684 | mrq->data->bytes_xfered = host->curr.data_xfered; |
| 685 | del_timer(&host->req_tout_timer); |
Subhash Jadavani | ed6b0e4 | 2012-03-07 16:36:27 +0530 | [diff] [blame] | 686 | /* |
| 687 | * Clear current request information as current |
| 688 | * request has ended |
| 689 | */ |
| 690 | memset(&host->curr, 0, sizeof(struct msmsdcc_curr_req)); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 691 | spin_unlock_irqrestore(&host->lock, flags); |
| 692 | |
| 693 | mmc_request_done(host->mmc, mrq); |
| 694 | return; |
Sujit Reddy Thumma | 055106d | 2012-01-16 15:16:26 +0530 | [diff] [blame] | 695 | } else if (mrq->data->stop && ((mrq->sbc && mrq->data->error) |
| 696 | || !mrq->sbc)) { |
| 697 | msmsdcc_start_command(host, mrq->data->stop, 0); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 698 | } |
| 699 | } |
| 700 | spin_unlock_irqrestore(&host->lock, flags); |
| 701 | } |
| 702 | |
| 703 | /** |
| 704 | * Exit from current SPS data transfer |
| 705 | * |
| 706 | * This function exits from current SPS data transfer. |
| 707 | * |
| 708 | * This function should be called when error condition |
| 709 | * is encountered during data transfer. |
| 710 | * |
| 711 | * @host - Pointer to sdcc host structure |
| 712 | * |
| 713 | */ |
| 714 | static void msmsdcc_sps_exit_curr_xfer(struct msmsdcc_host *host) |
| 715 | { |
| 716 | struct mmc_request *mrq; |
| 717 | |
| 718 | mrq = host->curr.mrq; |
| 719 | BUG_ON(!mrq); |
| 720 | |
| 721 | msmsdcc_reset_and_restore(host); |
| 722 | if (!mrq->data->error) |
| 723 | mrq->data->error = -EIO; |
| 724 | |
| 725 | /* Unmap sg buffers */ |
| 726 | dma_unmap_sg(mmc_dev(host->mmc), host->sps.sg, host->sps.num_ents, |
| 727 | host->sps.dir); |
| 728 | |
| 729 | host->sps.sg = NULL; |
| 730 | host->sps.busy = 0; |
| 731 | if (host->curr.data) |
| 732 | msmsdcc_stop_data(host); |
| 733 | |
Subhash Jadavani | a8e5ecb | 2011-08-25 19:19:58 +0530 | [diff] [blame] | 734 | if (!mrq->data->stop || mrq->cmd->error || |
| 735 | (mrq->sbc && !mrq->data->error)) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 736 | msmsdcc_request_end(host, mrq); |
Subhash Jadavani | a8e5ecb | 2011-08-25 19:19:58 +0530 | [diff] [blame] | 737 | else if (mrq->data->stop && ((mrq->sbc && mrq->data->error) |
| 738 | || !mrq->sbc)) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 739 | msmsdcc_start_command(host, mrq->data->stop, 0); |
| 740 | |
| 741 | } |
| 742 | #else |
| 743 | static inline void msmsdcc_sps_complete_cb(struct sps_event_notify *notify) { } |
| 744 | static inline void msmsdcc_sps_complete_tlet(unsigned long data) { } |
| 745 | static inline void msmsdcc_sps_exit_curr_xfer(struct msmsdcc_host *host) { } |
| 746 | #endif /* CONFIG_MMC_MSM_SPS_SUPPORT */ |
| 747 | |
Subhash Jadavani | b52b4d7 | 2011-12-05 19:16:28 +0530 | [diff] [blame] | 748 | static int msmsdcc_enable_cdr_cm_sdc4_dll(struct msmsdcc_host *host); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 749 | |
Sahitya Tummala | 62612cf | 2010-12-08 15:03:03 +0530 | [diff] [blame] | 750 | static void |
| 751 | msmsdcc_dma_complete_func(struct msm_dmov_cmd *cmd, |
| 752 | unsigned int result, |
| 753 | struct msm_dmov_errdata *err) |
| 754 | { |
| 755 | struct msmsdcc_dma_data *dma_data = |
| 756 | container_of(cmd, struct msmsdcc_dma_data, hdr); |
| 757 | struct msmsdcc_host *host = dma_data->host; |
| 758 | |
| 759 | dma_data->result = result; |
| 760 | if (err) |
| 761 | memcpy(&dma_data->err, err, sizeof(struct msm_dmov_errdata)); |
| 762 | |
| 763 | tasklet_schedule(&host->dma_tlet); |
| 764 | } |
| 765 | |
Subhash Jadavani | e6e1b82 | 2012-03-12 18:17:58 +0530 | [diff] [blame] | 766 | static bool msmsdcc_is_dma_possible(struct msmsdcc_host *host, |
| 767 | struct mmc_data *data) |
San Mehat | 9d2bd73 | 2009-09-22 16:44:22 -0700 | [diff] [blame] | 768 | { |
Subhash Jadavani | e6e1b82 | 2012-03-12 18:17:58 +0530 | [diff] [blame] | 769 | bool ret = true; |
| 770 | u32 xfer_size = data->blksz * data->blocks; |
| 771 | |
| 772 | if (host->is_sps_mode) { |
| 773 | /* |
| 774 | * BAM Mode: Fall back on PIO if size is less |
| 775 | * than or equal to SPS_MIN_XFER_SIZE bytes. |
| 776 | */ |
| 777 | if (xfer_size <= SPS_MIN_XFER_SIZE) |
| 778 | ret = false; |
| 779 | } else if (host->is_dma_mode) { |
| 780 | /* |
| 781 | * ADM Mode: Fall back on PIO if size is less than FIFO size |
| 782 | * or not integer multiple of FIFO size |
| 783 | */ |
| 784 | if (xfer_size % MCI_FIFOSIZE) |
| 785 | ret = false; |
| 786 | } else { |
| 787 | /* PIO Mode */ |
| 788 | ret = false; |
| 789 | } |
| 790 | |
| 791 | return ret; |
San Mehat | 9d2bd73 | 2009-09-22 16:44:22 -0700 | [diff] [blame] | 792 | } |
| 793 | |
| 794 | static int msmsdcc_config_dma(struct msmsdcc_host *host, struct mmc_data *data) |
| 795 | { |
| 796 | struct msmsdcc_nc_dmadata *nc; |
| 797 | dmov_box *box; |
| 798 | uint32_t rows; |
San Mehat | 9d2bd73 | 2009-09-22 16:44:22 -0700 | [diff] [blame] | 799 | unsigned int n; |
Sujit Reddy Thumma | cf6c4ed | 2011-11-14 17:20:36 +0530 | [diff] [blame] | 800 | int i, err = 0, box_cmd_cnt = 0; |
San Mehat | 9d2bd73 | 2009-09-22 16:44:22 -0700 | [diff] [blame] | 801 | struct scatterlist *sg = data->sg; |
Sujit Reddy Thumma | cf6c4ed | 2011-11-14 17:20:36 +0530 | [diff] [blame] | 802 | unsigned int len, offset; |
San Mehat | 9d2bd73 | 2009-09-22 16:44:22 -0700 | [diff] [blame] | 803 | |
Krishna Konda | 25786ec | 2011-07-25 16:21:36 -0700 | [diff] [blame] | 804 | if ((host->dma.channel == -1) || (host->dma.crci == -1)) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 805 | return -ENOENT; |
San Mehat | 9d2bd73 | 2009-09-22 16:44:22 -0700 | [diff] [blame] | 806 | |
Krishna Konda | 25786ec | 2011-07-25 16:21:36 -0700 | [diff] [blame] | 807 | BUG_ON((host->pdev_id < 1) || (host->pdev_id > 5)); |
| 808 | |
San Mehat | 9d2bd73 | 2009-09-22 16:44:22 -0700 | [diff] [blame] | 809 | host->dma.sg = data->sg; |
| 810 | host->dma.num_ents = data->sg_len; |
| 811 | |
Sujit Reddy Thumma | cf6c4ed | 2011-11-14 17:20:36 +0530 | [diff] [blame] | 812 | /* Prevent memory corruption */ |
| 813 | BUG_ON(host->dma.num_ents > msmsdcc_get_nr_sg(host)); |
San Mehat | 56a8b5b | 2009-11-21 12:29:46 -0800 | [diff] [blame] | 814 | |
San Mehat | 9d2bd73 | 2009-09-22 16:44:22 -0700 | [diff] [blame] | 815 | nc = host->dma.nc; |
| 816 | |
San Mehat | 9d2bd73 | 2009-09-22 16:44:22 -0700 | [diff] [blame] | 817 | if (data->flags & MMC_DATA_READ) |
| 818 | host->dma.dir = DMA_FROM_DEVICE; |
| 819 | else |
| 820 | host->dma.dir = DMA_TO_DEVICE; |
| 821 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 822 | n = dma_map_sg(mmc_dev(host->mmc), host->dma.sg, |
| 823 | host->dma.num_ents, host->dma.dir); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 824 | |
| 825 | if (n != host->dma.num_ents) { |
| 826 | pr_err("%s: Unable to map in all sg elements\n", |
| 827 | mmc_hostname(host->mmc)); |
| 828 | host->dma.sg = NULL; |
| 829 | host->dma.num_ents = 0; |
| 830 | return -ENOMEM; |
San Mehat | 56a8b5b | 2009-11-21 12:29:46 -0800 | [diff] [blame] | 831 | } |
San Mehat | 9d2bd73 | 2009-09-22 16:44:22 -0700 | [diff] [blame] | 832 | |
Sujit Reddy Thumma | cf6c4ed | 2011-11-14 17:20:36 +0530 | [diff] [blame] | 833 | /* host->curr.user_pages = (data->flags & MMC_DATA_USERPAGE); */ |
| 834 | host->curr.user_pages = 0; |
| 835 | box = &nc->cmd[0]; |
| 836 | for (i = 0; i < host->dma.num_ents; i++) { |
| 837 | len = sg_dma_len(sg); |
| 838 | offset = 0; |
| 839 | |
| 840 | do { |
| 841 | /* Check if we can do DMA */ |
| 842 | if (!len || (box_cmd_cnt >= MMC_MAX_DMA_CMDS)) { |
| 843 | err = -ENOTSUPP; |
| 844 | goto unmap; |
| 845 | } |
| 846 | |
| 847 | box->cmd = CMD_MODE_BOX; |
| 848 | |
| 849 | if (len >= MMC_MAX_DMA_BOX_LENGTH) { |
| 850 | len = MMC_MAX_DMA_BOX_LENGTH; |
| 851 | len -= len % data->blksz; |
| 852 | } |
| 853 | rows = (len % MCI_FIFOSIZE) ? |
| 854 | (len / MCI_FIFOSIZE) + 1 : |
| 855 | (len / MCI_FIFOSIZE); |
| 856 | |
| 857 | if (data->flags & MMC_DATA_READ) { |
| 858 | box->src_row_addr = msmsdcc_fifo_addr(host); |
| 859 | box->dst_row_addr = sg_dma_address(sg) + offset; |
| 860 | box->src_dst_len = (MCI_FIFOSIZE << 16) | |
| 861 | (MCI_FIFOSIZE); |
| 862 | box->row_offset = MCI_FIFOSIZE; |
| 863 | box->num_rows = rows * ((1 << 16) + 1); |
| 864 | box->cmd |= CMD_SRC_CRCI(host->dma.crci); |
| 865 | } else { |
| 866 | box->src_row_addr = sg_dma_address(sg) + offset; |
| 867 | box->dst_row_addr = msmsdcc_fifo_addr(host); |
| 868 | box->src_dst_len = (MCI_FIFOSIZE << 16) | |
| 869 | (MCI_FIFOSIZE); |
| 870 | box->row_offset = (MCI_FIFOSIZE << 16); |
| 871 | box->num_rows = rows * ((1 << 16) + 1); |
| 872 | box->cmd |= CMD_DST_CRCI(host->dma.crci); |
| 873 | } |
| 874 | |
| 875 | offset += len; |
| 876 | len = sg_dma_len(sg) - offset; |
| 877 | box++; |
| 878 | box_cmd_cnt++; |
| 879 | } while (len); |
| 880 | sg++; |
| 881 | } |
| 882 | /* Mark last command */ |
| 883 | box--; |
| 884 | box->cmd |= CMD_LC; |
| 885 | |
| 886 | /* location of command block must be 64 bit aligned */ |
| 887 | BUG_ON(host->dma.cmd_busaddr & 0x07); |
| 888 | |
| 889 | nc->cmdptr = (host->dma.cmd_busaddr >> 3) | CMD_PTR_LP; |
| 890 | host->dma.hdr.cmdptr = DMOV_CMD_PTR_LIST | |
| 891 | DMOV_CMD_ADDR(host->dma.cmdptr_busaddr); |
| 892 | host->dma.hdr.complete_func = msmsdcc_dma_complete_func; |
| 893 | |
| 894 | /* Flush all data to memory before starting dma */ |
| 895 | mb(); |
| 896 | |
| 897 | unmap: |
| 898 | if (err) { |
| 899 | dma_unmap_sg(mmc_dev(host->mmc), host->dma.sg, |
| 900 | host->dma.num_ents, host->dma.dir); |
| 901 | pr_err("%s: cannot do DMA, fall back to PIO mode err=%d\n", |
| 902 | mmc_hostname(host->mmc), err); |
| 903 | } |
| 904 | |
| 905 | return err; |
San Mehat | 9d2bd73 | 2009-09-22 16:44:22 -0700 | [diff] [blame] | 906 | } |
| 907 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 908 | #ifdef CONFIG_MMC_MSM_SPS_SUPPORT |
| 909 | /** |
| 910 | * Submits data transfer request to SPS driver |
| 911 | * |
| 912 | * This function make sg (scatter gather) data buffers |
| 913 | * DMA ready and then submits them to SPS driver for |
| 914 | * transfer. |
| 915 | * |
| 916 | * @host - Pointer to sdcc host structure |
| 917 | * @data - Pointer to mmc_data structure |
| 918 | * |
| 919 | * @return 0 if success else negative value |
| 920 | */ |
| 921 | static int msmsdcc_sps_start_xfer(struct msmsdcc_host *host, |
| 922 | struct mmc_data *data) |
San Mehat | 56a8b5b | 2009-11-21 12:29:46 -0800 | [diff] [blame] | 923 | { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 924 | int rc = 0; |
| 925 | u32 flags; |
| 926 | int i; |
| 927 | u32 addr, len, data_cnt; |
| 928 | struct scatterlist *sg = data->sg; |
| 929 | struct sps_pipe *sps_pipe_handle; |
| 930 | |
Sujit Reddy Thumma | cf6c4ed | 2011-11-14 17:20:36 +0530 | [diff] [blame] | 931 | /* Prevent memory corruption */ |
| 932 | BUG_ON(data->sg_len > msmsdcc_get_nr_sg(host)); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 933 | |
| 934 | host->sps.sg = data->sg; |
| 935 | host->sps.num_ents = data->sg_len; |
| 936 | host->sps.xfer_req_cnt = 0; |
| 937 | if (data->flags & MMC_DATA_READ) { |
| 938 | host->sps.dir = DMA_FROM_DEVICE; |
| 939 | sps_pipe_handle = host->sps.prod.pipe_handle; |
| 940 | } else { |
| 941 | host->sps.dir = DMA_TO_DEVICE; |
| 942 | sps_pipe_handle = host->sps.cons.pipe_handle; |
| 943 | } |
| 944 | |
| 945 | /* Make sg buffers DMA ready */ |
| 946 | rc = dma_map_sg(mmc_dev(host->mmc), data->sg, data->sg_len, |
| 947 | host->sps.dir); |
| 948 | |
| 949 | if (rc != data->sg_len) { |
| 950 | pr_err("%s: Unable to map in all sg elements, rc=%d\n", |
| 951 | mmc_hostname(host->mmc), rc); |
| 952 | host->sps.sg = NULL; |
| 953 | host->sps.num_ents = 0; |
| 954 | rc = -ENOMEM; |
| 955 | goto dma_map_err; |
| 956 | } |
| 957 | |
| 958 | pr_debug("%s: %s: %s: pipe=0x%x, total_xfer=0x%x, sg_len=%d\n", |
| 959 | mmc_hostname(host->mmc), __func__, |
| 960 | host->sps.dir == DMA_FROM_DEVICE ? "READ" : "WRITE", |
| 961 | (u32)sps_pipe_handle, host->curr.xfer_size, data->sg_len); |
| 962 | |
| 963 | for (i = 0; i < data->sg_len; i++) { |
| 964 | /* |
| 965 | * Check if this is the last buffer to transfer? |
| 966 | * If yes then set the INT and EOT flags. |
| 967 | */ |
| 968 | len = sg_dma_len(sg); |
| 969 | addr = sg_dma_address(sg); |
| 970 | flags = 0; |
| 971 | while (len > 0) { |
| 972 | if (len > SPS_MAX_DESC_SIZE) { |
| 973 | data_cnt = SPS_MAX_DESC_SIZE; |
| 974 | } else { |
| 975 | data_cnt = len; |
| 976 | if (i == data->sg_len - 1) |
| 977 | flags = SPS_IOVEC_FLAG_INT | |
| 978 | SPS_IOVEC_FLAG_EOT; |
| 979 | } |
| 980 | rc = sps_transfer_one(sps_pipe_handle, addr, |
| 981 | data_cnt, host, flags); |
| 982 | if (rc) { |
| 983 | pr_err("%s: sps_transfer_one() error! rc=%d," |
| 984 | " pipe=0x%x, sg=0x%x, sg_buf_no=%d\n", |
| 985 | mmc_hostname(host->mmc), rc, |
| 986 | (u32)sps_pipe_handle, (u32)sg, i); |
| 987 | goto dma_map_err; |
| 988 | } |
| 989 | addr += data_cnt; |
| 990 | len -= data_cnt; |
| 991 | host->sps.xfer_req_cnt++; |
| 992 | } |
| 993 | sg++; |
| 994 | } |
| 995 | goto out; |
| 996 | |
| 997 | dma_map_err: |
| 998 | /* unmap sg buffers */ |
| 999 | dma_unmap_sg(mmc_dev(host->mmc), host->sps.sg, host->sps.num_ents, |
| 1000 | host->sps.dir); |
| 1001 | out: |
| 1002 | return rc; |
San Mehat | 9d2bd73 | 2009-09-22 16:44:22 -0700 | [diff] [blame] | 1003 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1004 | #else |
| 1005 | static int msmsdcc_sps_start_xfer(struct msmsdcc_host *host, |
| 1006 | struct mmc_data *data) { return 0; } |
| 1007 | #endif /* CONFIG_MMC_MSM_SPS_SUPPORT */ |
San Mehat | 9d2bd73 | 2009-09-22 16:44:22 -0700 | [diff] [blame] | 1008 | |
| 1009 | static void |
San Mehat | 56a8b5b | 2009-11-21 12:29:46 -0800 | [diff] [blame] | 1010 | msmsdcc_start_command_deferred(struct msmsdcc_host *host, |
| 1011 | struct mmc_command *cmd, u32 *c) |
| 1012 | { |
Sujit Reddy Thumma | 055106d | 2012-01-16 15:16:26 +0530 | [diff] [blame] | 1013 | DBG(host, "op %02x arg %08x flags %08x\n", |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1014 | cmd->opcode, cmd->arg, cmd->flags); |
| 1015 | |
San Mehat | 56a8b5b | 2009-11-21 12:29:46 -0800 | [diff] [blame] | 1016 | *c |= (cmd->opcode | MCI_CPSM_ENABLE); |
| 1017 | |
| 1018 | if (cmd->flags & MMC_RSP_PRESENT) { |
| 1019 | if (cmd->flags & MMC_RSP_136) |
| 1020 | *c |= MCI_CPSM_LONGRSP; |
| 1021 | *c |= MCI_CPSM_RESPONSE; |
| 1022 | } |
| 1023 | |
| 1024 | if (/*interrupt*/0) |
| 1025 | *c |= MCI_CPSM_INTERRUPT; |
| 1026 | |
Subhash Jadavani | de0fc77 | 2011-11-13 12:27:52 +0530 | [diff] [blame] | 1027 | if (cmd->opcode == MMC_READ_SINGLE_BLOCK || |
| 1028 | cmd->opcode == MMC_READ_MULTIPLE_BLOCK || |
| 1029 | cmd->opcode == MMC_WRITE_BLOCK || |
| 1030 | cmd->opcode == MMC_WRITE_MULTIPLE_BLOCK || |
| 1031 | cmd->opcode == SD_IO_RW_EXTENDED) |
San Mehat | 56a8b5b | 2009-11-21 12:29:46 -0800 | [diff] [blame] | 1032 | *c |= MCI_CSPM_DATCMD; |
| 1033 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1034 | /* Check if AUTO CMD19 is required or not? */ |
Subhash Jadavani | 56e0eaa | 2012-03-13 18:06:04 +0530 | [diff] [blame] | 1035 | if (host->tuning_needed && |
| 1036 | !(host->mmc->ios.timing == MMC_TIMING_MMC_HS200)) { |
| 1037 | |
Subhash Jadavani | 1d6ba60 | 2011-09-21 18:10:54 +0530 | [diff] [blame] | 1038 | /* |
| 1039 | * For open ended block read operation (without CMD23), |
| 1040 | * AUTO_CMD19 bit should be set while sending the READ command. |
| 1041 | * For close ended block read operation (with CMD23), |
| 1042 | * AUTO_CMD19 bit should be set while sending CMD23. |
| 1043 | */ |
Subhash Jadavani | de0fc77 | 2011-11-13 12:27:52 +0530 | [diff] [blame] | 1044 | if ((cmd->opcode == MMC_SET_BLOCK_COUNT && |
| 1045 | host->curr.mrq->cmd->opcode == |
| 1046 | MMC_READ_MULTIPLE_BLOCK) || |
Subhash Jadavani | 1d6ba60 | 2011-09-21 18:10:54 +0530 | [diff] [blame] | 1047 | (!host->curr.mrq->sbc && |
Subhash Jadavani | de0fc77 | 2011-11-13 12:27:52 +0530 | [diff] [blame] | 1048 | (cmd->opcode == MMC_READ_SINGLE_BLOCK || |
| 1049 | cmd->opcode == MMC_READ_MULTIPLE_BLOCK))) { |
Subhash Jadavani | 1d6ba60 | 2011-09-21 18:10:54 +0530 | [diff] [blame] | 1050 | msmsdcc_enable_cdr_cm_sdc4_dll(host); |
| 1051 | *c |= MCI_CSPM_AUTO_CMD19; |
| 1052 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1053 | } |
| 1054 | |
Subhash Jadavani | 8b6ee57 | 2012-02-02 18:24:45 +0530 | [diff] [blame] | 1055 | /* Clear CDR_EN bit for write operations */ |
| 1056 | if (host->tuning_needed && cmd->mrq->data && |
| 1057 | (cmd->mrq->data->flags & MMC_DATA_WRITE)) |
| 1058 | writel_relaxed((readl_relaxed(host->base + MCI_DLL_CONFIG) & |
| 1059 | ~MCI_CDR_EN), host->base + MCI_DLL_CONFIG); |
| 1060 | |
Subhash Jadavani | 7d8c94d | 2011-10-18 18:00:07 +0530 | [diff] [blame] | 1061 | if ((cmd->flags & MMC_RSP_R1B) == MMC_RSP_R1B) { |
Sahitya Tummala | d5137bd | 2010-12-08 15:03:04 +0530 | [diff] [blame] | 1062 | *c |= MCI_CPSM_PROGENA; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1063 | host->prog_enable = 1; |
Sahitya Tummala | d5137bd | 2010-12-08 15:03:04 +0530 | [diff] [blame] | 1064 | } |
| 1065 | |
San Mehat | 56a8b5b | 2009-11-21 12:29:46 -0800 | [diff] [blame] | 1066 | if (cmd == cmd->mrq->stop) |
| 1067 | *c |= MCI_CSPM_MCIABORT; |
| 1068 | |
San Mehat | 56a8b5b | 2009-11-21 12:29:46 -0800 | [diff] [blame] | 1069 | if (host->curr.cmd != NULL) { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1070 | pr_err("%s: Overlapping command requests\n", |
| 1071 | mmc_hostname(host->mmc)); |
San Mehat | 56a8b5b | 2009-11-21 12:29:46 -0800 | [diff] [blame] | 1072 | } |
| 1073 | host->curr.cmd = cmd; |
| 1074 | } |
| 1075 | |
| 1076 | static void |
| 1077 | msmsdcc_start_data(struct msmsdcc_host *host, struct mmc_data *data, |
| 1078 | struct mmc_command *cmd, u32 c) |
San Mehat | 9d2bd73 | 2009-09-22 16:44:22 -0700 | [diff] [blame] | 1079 | { |
Subhash Jadavani | 24fb7f8 | 2011-07-25 15:54:34 +0530 | [diff] [blame] | 1080 | unsigned int datactrl = 0, timeout; |
San Mehat | 9d2bd73 | 2009-09-22 16:44:22 -0700 | [diff] [blame] | 1081 | unsigned long long clks; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1082 | void __iomem *base = host->base; |
San Mehat | 9d2bd73 | 2009-09-22 16:44:22 -0700 | [diff] [blame] | 1083 | unsigned int pio_irqmask = 0; |
| 1084 | |
Subhash Jadavani | 7d572f1 | 2011-11-13 13:09:36 +0530 | [diff] [blame] | 1085 | BUG_ON(!data->sg); |
| 1086 | BUG_ON(!data->sg_len); |
| 1087 | |
San Mehat | 9d2bd73 | 2009-09-22 16:44:22 -0700 | [diff] [blame] | 1088 | host->curr.data = data; |
| 1089 | host->curr.xfer_size = data->blksz * data->blocks; |
| 1090 | host->curr.xfer_remain = host->curr.xfer_size; |
| 1091 | host->curr.data_xfered = 0; |
| 1092 | host->curr.got_dataend = 0; |
Subhash Jadavani | 7a651aa | 2011-08-03 20:44:58 +0530 | [diff] [blame] | 1093 | host->curr.got_auto_prog_done = 0; |
San Mehat | 9d2bd73 | 2009-09-22 16:44:22 -0700 | [diff] [blame] | 1094 | |
San Mehat | 9d2bd73 | 2009-09-22 16:44:22 -0700 | [diff] [blame] | 1095 | datactrl = MCI_DPSM_ENABLE | (data->blksz << 4); |
| 1096 | |
Subhash Jadavani | 7a651aa | 2011-08-03 20:44:58 +0530 | [diff] [blame] | 1097 | if (host->curr.wait_for_auto_prog_done) |
| 1098 | datactrl |= MCI_AUTO_PROG_DONE; |
| 1099 | |
Subhash Jadavani | e6e1b82 | 2012-03-12 18:17:58 +0530 | [diff] [blame] | 1100 | if (msmsdcc_is_dma_possible(host, data)) { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1101 | if (host->is_dma_mode && !msmsdcc_config_dma(host, data)) { |
| 1102 | datactrl |= MCI_DPSM_DMAENABLE; |
| 1103 | } else if (host->is_sps_mode) { |
| 1104 | if (!msmsdcc_is_dml_busy(host)) { |
| 1105 | if (!msmsdcc_sps_start_xfer(host, data)) { |
| 1106 | /* Now kick start DML transfer */ |
| 1107 | mb(); |
| 1108 | msmsdcc_dml_start_xfer(host, data); |
| 1109 | datactrl |= MCI_DPSM_DMAENABLE; |
| 1110 | host->sps.busy = 1; |
| 1111 | } |
| 1112 | } else { |
| 1113 | /* |
| 1114 | * Can't proceed with new transfer as |
| 1115 | * previous trasnfer is already in progress. |
| 1116 | * There is no point of going into PIO mode |
| 1117 | * as well. Is this a time to do kernel panic? |
| 1118 | */ |
| 1119 | pr_err("%s: %s: DML HW is busy!!!" |
| 1120 | " Can't perform new SPS transfers" |
| 1121 | " now\n", mmc_hostname(host->mmc), |
| 1122 | __func__); |
| 1123 | } |
| 1124 | } |
| 1125 | } |
| 1126 | |
| 1127 | /* Is data transfer in PIO mode required? */ |
| 1128 | if (!(datactrl & MCI_DPSM_DMAENABLE)) { |
San Mehat | 9d2bd73 | 2009-09-22 16:44:22 -0700 | [diff] [blame] | 1129 | if (data->flags & MMC_DATA_READ) { |
| 1130 | pio_irqmask = MCI_RXFIFOHALFFULLMASK; |
| 1131 | if (host->curr.xfer_remain < MCI_FIFOSIZE) |
| 1132 | pio_irqmask |= MCI_RXDATAAVLBLMASK; |
Oluwafemi Adeyemi | ecfa3df | 2012-02-28 18:08:54 -0800 | [diff] [blame] | 1133 | } else |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1134 | pio_irqmask = MCI_TXFIFOHALFEMPTYMASK | |
| 1135 | MCI_TXFIFOEMPTYMASK; |
Oluwafemi Adeyemi | a981c5c | 2012-02-09 20:02:00 -0800 | [diff] [blame] | 1136 | |
Oluwafemi Adeyemi | ecfa3df | 2012-02-28 18:08:54 -0800 | [diff] [blame] | 1137 | msmsdcc_sg_start(host); |
San Mehat | 9d2bd73 | 2009-09-22 16:44:22 -0700 | [diff] [blame] | 1138 | } |
| 1139 | |
| 1140 | if (data->flags & MMC_DATA_READ) |
Subhash Jadavani | 24fb7f8 | 2011-07-25 15:54:34 +0530 | [diff] [blame] | 1141 | datactrl |= (MCI_DPSM_DIRECTION | MCI_RX_DATA_PEND); |
San Mehat | 9d2bd73 | 2009-09-22 16:44:22 -0700 | [diff] [blame] | 1142 | |
San Mehat | 56a8b5b | 2009-11-21 12:29:46 -0800 | [diff] [blame] | 1143 | clks = (unsigned long long)data->timeout_ns * host->clk_rate; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1144 | do_div(clks, 1000000000UL); |
San Mehat | 56a8b5b | 2009-11-21 12:29:46 -0800 | [diff] [blame] | 1145 | timeout = data->timeout_clks + (unsigned int)clks*2 ; |
San Mehat | 9d2bd73 | 2009-09-22 16:44:22 -0700 | [diff] [blame] | 1146 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1147 | if (host->is_dma_mode && (datactrl & MCI_DPSM_DMAENABLE)) { |
| 1148 | /* Use ADM (Application Data Mover) HW for Data transfer */ |
| 1149 | /* Save parameters for the dma exec function */ |
San Mehat | 56a8b5b | 2009-11-21 12:29:46 -0800 | [diff] [blame] | 1150 | host->cmd_timeout = timeout; |
| 1151 | host->cmd_pio_irqmask = pio_irqmask; |
| 1152 | host->cmd_datactrl = datactrl; |
| 1153 | host->cmd_cmd = cmd; |
San Mehat | 9d2bd73 | 2009-09-22 16:44:22 -0700 | [diff] [blame] | 1154 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1155 | host->dma.hdr.exec_func = msmsdcc_dma_exec_func; |
| 1156 | host->dma.hdr.user = (void *)host; |
San Mehat | 9d2bd73 | 2009-09-22 16:44:22 -0700 | [diff] [blame] | 1157 | host->dma.busy = 1; |
San Mehat | 56a8b5b | 2009-11-21 12:29:46 -0800 | [diff] [blame] | 1158 | |
| 1159 | if (cmd) { |
| 1160 | msmsdcc_start_command_deferred(host, cmd, &c); |
| 1161 | host->cmd_c = c; |
| 1162 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1163 | writel_relaxed((readl_relaxed(host->base + MMCIMASK0) & |
| 1164 | (~(MCI_IRQ_PIO))) | host->cmd_pio_irqmask, |
| 1165 | host->base + MMCIMASK0); |
| 1166 | mb(); |
| 1167 | msm_dmov_enqueue_cmd_ext(host->dma.channel, &host->dma.hdr); |
San Mehat | 56a8b5b | 2009-11-21 12:29:46 -0800 | [diff] [blame] | 1168 | } else { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1169 | /* SPS-BAM mode or PIO mode */ |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1170 | writel_relaxed(timeout, base + MMCIDATATIMER); |
San Mehat | 56a8b5b | 2009-11-21 12:29:46 -0800 | [diff] [blame] | 1171 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1172 | writel_relaxed(host->curr.xfer_size, base + MMCIDATALENGTH); |
San Mehat | 56a8b5b | 2009-11-21 12:29:46 -0800 | [diff] [blame] | 1173 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1174 | writel_relaxed((readl_relaxed(host->base + MMCIMASK0) & |
| 1175 | (~(MCI_IRQ_PIO))) | pio_irqmask, |
| 1176 | host->base + MMCIMASK0); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1177 | writel_relaxed(datactrl, base + MMCIDATACTRL); |
San Mehat | 56a8b5b | 2009-11-21 12:29:46 -0800 | [diff] [blame] | 1178 | |
| 1179 | if (cmd) { |
Subhash Jadavani | dd43295 | 2012-03-28 11:25:56 +0530 | [diff] [blame] | 1180 | /* Delay between data/command */ |
| 1181 | msmsdcc_sync_reg_wr(host); |
San Mehat | 56a8b5b | 2009-11-21 12:29:46 -0800 | [diff] [blame] | 1182 | /* Daisy-chain the command if requested */ |
| 1183 | msmsdcc_start_command(host, cmd, c); |
Subhash Jadavani | dd43295 | 2012-03-28 11:25:56 +0530 | [diff] [blame] | 1184 | } else { |
| 1185 | /* |
| 1186 | * We don't need delay after writing to DATA_CTRL |
| 1187 | * register if we are not writing to CMD register |
| 1188 | * immediately after this. As we already have delay |
| 1189 | * before sending the command, we just need mb() here. |
| 1190 | */ |
| 1191 | mb(); |
San Mehat | 56a8b5b | 2009-11-21 12:29:46 -0800 | [diff] [blame] | 1192 | } |
San Mehat | 9d2bd73 | 2009-09-22 16:44:22 -0700 | [diff] [blame] | 1193 | } |
| 1194 | } |
| 1195 | |
| 1196 | static void |
| 1197 | msmsdcc_start_command(struct msmsdcc_host *host, struct mmc_command *cmd, u32 c) |
| 1198 | { |
San Mehat | 56a8b5b | 2009-11-21 12:29:46 -0800 | [diff] [blame] | 1199 | msmsdcc_start_command_deferred(host, cmd, &c); |
| 1200 | msmsdcc_start_command_exec(host, cmd->arg, c); |
San Mehat | 9d2bd73 | 2009-09-22 16:44:22 -0700 | [diff] [blame] | 1201 | } |
| 1202 | |
| 1203 | static void |
| 1204 | msmsdcc_data_err(struct msmsdcc_host *host, struct mmc_data *data, |
| 1205 | unsigned int status) |
| 1206 | { |
| 1207 | if (status & MCI_DATACRCFAIL) { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1208 | if (!(data->mrq->cmd->opcode == MMC_BUS_TEST_W |
Subhash Jadavani | b30c982 | 2012-03-27 18:03:16 +0530 | [diff] [blame] | 1209 | || data->mrq->cmd->opcode == MMC_BUS_TEST_R |
| 1210 | || data->mrq->cmd->opcode == |
| 1211 | MMC_SEND_TUNING_BLOCK_HS200)) { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1212 | pr_err("%s: Data CRC error\n", |
| 1213 | mmc_hostname(host->mmc)); |
| 1214 | pr_err("%s: opcode 0x%.8x\n", __func__, |
| 1215 | data->mrq->cmd->opcode); |
| 1216 | pr_err("%s: blksz %d, blocks %d\n", __func__, |
| 1217 | data->blksz, data->blocks); |
| 1218 | data->error = -EILSEQ; |
| 1219 | } |
San Mehat | 9d2bd73 | 2009-09-22 16:44:22 -0700 | [diff] [blame] | 1220 | } else if (status & MCI_DATATIMEOUT) { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1221 | /* CRC is optional for the bus test commands, not all |
| 1222 | * cards respond back with CRC. However controller |
| 1223 | * waits for the CRC and times out. Hence ignore the |
| 1224 | * data timeouts during the Bustest. |
| 1225 | */ |
| 1226 | if (!(data->mrq->cmd->opcode == MMC_BUS_TEST_W |
| 1227 | || data->mrq->cmd->opcode == MMC_BUS_TEST_R)) { |
Subhash Jadavani | b52b4d7 | 2011-12-05 19:16:28 +0530 | [diff] [blame] | 1228 | pr_err("%s: CMD%d: Data timeout\n", |
| 1229 | mmc_hostname(host->mmc), |
| 1230 | data->mrq->cmd->opcode); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1231 | data->error = -ETIMEDOUT; |
Subhash Jadavani | b52b4d7 | 2011-12-05 19:16:28 +0530 | [diff] [blame] | 1232 | msmsdcc_dump_sdcc_state(host); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1233 | } |
San Mehat | 9d2bd73 | 2009-09-22 16:44:22 -0700 | [diff] [blame] | 1234 | } else if (status & MCI_RXOVERRUN) { |
Joe Perches | 0a7ff7c | 2009-09-22 16:44:23 -0700 | [diff] [blame] | 1235 | pr_err("%s: RX overrun\n", mmc_hostname(host->mmc)); |
San Mehat | 9d2bd73 | 2009-09-22 16:44:22 -0700 | [diff] [blame] | 1236 | data->error = -EIO; |
| 1237 | } else if (status & MCI_TXUNDERRUN) { |
Joe Perches | 0a7ff7c | 2009-09-22 16:44:23 -0700 | [diff] [blame] | 1238 | pr_err("%s: TX underrun\n", mmc_hostname(host->mmc)); |
San Mehat | 9d2bd73 | 2009-09-22 16:44:22 -0700 | [diff] [blame] | 1239 | data->error = -EIO; |
| 1240 | } else { |
Joe Perches | 0a7ff7c | 2009-09-22 16:44:23 -0700 | [diff] [blame] | 1241 | pr_err("%s: Unknown error (0x%.8x)\n", |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1242 | mmc_hostname(host->mmc), status); |
San Mehat | 9d2bd73 | 2009-09-22 16:44:22 -0700 | [diff] [blame] | 1243 | data->error = -EIO; |
| 1244 | } |
San Mehat | 9d2bd73 | 2009-09-22 16:44:22 -0700 | [diff] [blame] | 1245 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1246 | /* Dummy CMD52 is not needed when CMD53 has errors */ |
Oluwafemi Adeyemi | cb79144 | 2011-07-11 22:51:25 -0700 | [diff] [blame] | 1247 | if (host->dummy_52_needed) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1248 | host->dummy_52_needed = 0; |
| 1249 | } |
San Mehat | 9d2bd73 | 2009-09-22 16:44:22 -0700 | [diff] [blame] | 1250 | |
| 1251 | static int |
| 1252 | msmsdcc_pio_read(struct msmsdcc_host *host, char *buffer, unsigned int remain) |
| 1253 | { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1254 | void __iomem *base = host->base; |
San Mehat | 9d2bd73 | 2009-09-22 16:44:22 -0700 | [diff] [blame] | 1255 | uint32_t *ptr = (uint32_t *) buffer; |
| 1256 | int count = 0; |
| 1257 | |
Sahitya Tummala | 71dd910 | 2010-12-08 15:03:06 +0530 | [diff] [blame] | 1258 | if (remain % 4) |
| 1259 | remain = ((remain >> 2) + 1) << 2; |
| 1260 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1261 | while (readl_relaxed(base + MMCISTATUS) & MCI_RXDATAAVLBL) { |
| 1262 | |
| 1263 | *ptr = readl_relaxed(base + MMCIFIFO + (count % MCI_FIFOSIZE)); |
San Mehat | 9d2bd73 | 2009-09-22 16:44:22 -0700 | [diff] [blame] | 1264 | ptr++; |
| 1265 | count += sizeof(uint32_t); |
| 1266 | |
| 1267 | remain -= sizeof(uint32_t); |
| 1268 | if (remain == 0) |
| 1269 | break; |
| 1270 | } |
| 1271 | return count; |
| 1272 | } |
| 1273 | |
| 1274 | static int |
| 1275 | msmsdcc_pio_write(struct msmsdcc_host *host, char *buffer, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1276 | unsigned int remain) |
San Mehat | 9d2bd73 | 2009-09-22 16:44:22 -0700 | [diff] [blame] | 1277 | { |
| 1278 | void __iomem *base = host->base; |
| 1279 | char *ptr = buffer; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1280 | unsigned int maxcnt = MCI_FIFOHALFSIZE; |
San Mehat | 9d2bd73 | 2009-09-22 16:44:22 -0700 | [diff] [blame] | 1281 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1282 | while (readl_relaxed(base + MMCISTATUS) & |
| 1283 | (MCI_TXFIFOEMPTY | MCI_TXFIFOHALFEMPTY)) { |
| 1284 | unsigned int count, sz; |
San Mehat | 9d2bd73 | 2009-09-22 16:44:22 -0700 | [diff] [blame] | 1285 | |
San Mehat | 9d2bd73 | 2009-09-22 16:44:22 -0700 | [diff] [blame] | 1286 | count = min(remain, maxcnt); |
| 1287 | |
Sahitya Tummala | 71dd910 | 2010-12-08 15:03:06 +0530 | [diff] [blame] | 1288 | sz = count % 4 ? (count >> 2) + 1 : (count >> 2); |
| 1289 | writesl(base + MMCIFIFO, ptr, sz); |
San Mehat | 9d2bd73 | 2009-09-22 16:44:22 -0700 | [diff] [blame] | 1290 | ptr += count; |
| 1291 | remain -= count; |
| 1292 | |
| 1293 | if (remain == 0) |
| 1294 | break; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1295 | } |
| 1296 | mb(); |
San Mehat | 9d2bd73 | 2009-09-22 16:44:22 -0700 | [diff] [blame] | 1297 | |
| 1298 | return ptr - buffer; |
| 1299 | } |
| 1300 | |
Oluwafemi Adeyemi | ecfa3df | 2012-02-28 18:08:54 -0800 | [diff] [blame] | 1301 | /* |
| 1302 | * Copy up to a word (4 bytes) between a scatterlist |
| 1303 | * and a temporary bounce buffer when the word lies across |
| 1304 | * two pages. The temporary buffer can then be read to/ |
| 1305 | * written from the FIFO once. |
| 1306 | */ |
| 1307 | static void _msmsdcc_sg_consume_word(struct msmsdcc_host *host) |
| 1308 | { |
| 1309 | struct msmsdcc_pio_data *pio = &host->pio; |
| 1310 | unsigned int bytes_avail; |
| 1311 | |
| 1312 | if (host->curr.data->flags & MMC_DATA_READ) |
| 1313 | memcpy(pio->sg_miter.addr, pio->bounce_buf, |
| 1314 | pio->bounce_buf_len); |
| 1315 | else |
| 1316 | memcpy(pio->bounce_buf, pio->sg_miter.addr, |
| 1317 | pio->bounce_buf_len); |
| 1318 | |
| 1319 | while (pio->bounce_buf_len != 4) { |
| 1320 | if (!sg_miter_next(&pio->sg_miter)) |
| 1321 | break; |
| 1322 | bytes_avail = min_t(unsigned int, pio->sg_miter.length, |
| 1323 | 4 - pio->bounce_buf_len); |
| 1324 | if (host->curr.data->flags & MMC_DATA_READ) |
| 1325 | memcpy(pio->sg_miter.addr, |
| 1326 | &pio->bounce_buf[pio->bounce_buf_len], |
| 1327 | bytes_avail); |
| 1328 | else |
| 1329 | memcpy(&pio->bounce_buf[pio->bounce_buf_len], |
| 1330 | pio->sg_miter.addr, bytes_avail); |
| 1331 | |
| 1332 | pio->sg_miter.consumed = bytes_avail; |
| 1333 | pio->bounce_buf_len += bytes_avail; |
| 1334 | } |
| 1335 | } |
| 1336 | |
| 1337 | /* |
| 1338 | * Use sg_miter_next to return as many 4-byte aligned |
| 1339 | * chunks as possible, using a temporary 4 byte buffer |
| 1340 | * for alignment if necessary |
| 1341 | */ |
| 1342 | static int msmsdcc_sg_next(struct msmsdcc_host *host, char **buf, int *len) |
| 1343 | { |
| 1344 | struct msmsdcc_pio_data *pio = &host->pio; |
| 1345 | unsigned int length, rlength; |
| 1346 | char *buffer; |
| 1347 | |
| 1348 | if (!sg_miter_next(&pio->sg_miter)) |
| 1349 | return 0; |
| 1350 | |
| 1351 | buffer = pio->sg_miter.addr; |
| 1352 | length = pio->sg_miter.length; |
| 1353 | |
| 1354 | if (length < host->curr.xfer_remain) { |
| 1355 | rlength = round_down(length, 4); |
| 1356 | if (rlength) { |
| 1357 | /* |
| 1358 | * We have a 4-byte aligned chunk. |
| 1359 | * The rounding will be reflected by |
| 1360 | * a call to msmsdcc_sg_consumed |
| 1361 | */ |
| 1362 | length = rlength; |
| 1363 | goto sg_next_end; |
| 1364 | } |
| 1365 | /* |
| 1366 | * We have a length less than 4 bytes. Check to |
| 1367 | * see if more buffer is available, and combine |
| 1368 | * to make 4 bytes if possible. |
| 1369 | */ |
| 1370 | pio->bounce_buf_len = length; |
| 1371 | memset(pio->bounce_buf, 0, 4); |
| 1372 | |
| 1373 | /* |
| 1374 | * On a read, get 4 bytes from FIFO, and distribute |
| 1375 | * (4-bouce_buf_len) bytes into consecutive |
| 1376 | * sgl buffers when msmsdcc_sg_consumed is called |
| 1377 | */ |
| 1378 | if (host->curr.data->flags & MMC_DATA_READ) { |
| 1379 | buffer = pio->bounce_buf; |
| 1380 | length = 4; |
| 1381 | goto sg_next_end; |
| 1382 | } else { |
| 1383 | _msmsdcc_sg_consume_word(host); |
| 1384 | buffer = pio->bounce_buf; |
| 1385 | length = pio->bounce_buf_len; |
| 1386 | } |
| 1387 | } |
| 1388 | |
| 1389 | sg_next_end: |
| 1390 | *buf = buffer; |
| 1391 | *len = length; |
| 1392 | return 1; |
| 1393 | } |
| 1394 | |
| 1395 | /* |
| 1396 | * Update sg_miter.consumed based on how many bytes were |
| 1397 | * consumed. If the bounce buffer was used to read from FIFO, |
| 1398 | * redistribute into sgls. |
| 1399 | */ |
| 1400 | static void msmsdcc_sg_consumed(struct msmsdcc_host *host, |
| 1401 | unsigned int length) |
| 1402 | { |
| 1403 | struct msmsdcc_pio_data *pio = &host->pio; |
| 1404 | |
| 1405 | if (host->curr.data->flags & MMC_DATA_READ) { |
| 1406 | if (length > pio->sg_miter.consumed) |
| 1407 | /* |
| 1408 | * consumed 4 bytes, but sgl |
| 1409 | * describes < 4 bytes |
| 1410 | */ |
| 1411 | _msmsdcc_sg_consume_word(host); |
| 1412 | else |
| 1413 | pio->sg_miter.consumed = length; |
| 1414 | } else |
| 1415 | if (length < pio->sg_miter.consumed) |
| 1416 | pio->sg_miter.consumed = length; |
| 1417 | } |
| 1418 | |
| 1419 | static void msmsdcc_sg_start(struct msmsdcc_host *host) |
| 1420 | { |
| 1421 | unsigned int sg_miter_flags = SG_MITER_ATOMIC; |
| 1422 | |
| 1423 | host->pio.bounce_buf_len = 0; |
| 1424 | |
| 1425 | if (host->curr.data->flags & MMC_DATA_READ) |
| 1426 | sg_miter_flags |= SG_MITER_TO_SG; |
| 1427 | else |
| 1428 | sg_miter_flags |= SG_MITER_FROM_SG; |
| 1429 | |
| 1430 | sg_miter_start(&host->pio.sg_miter, host->curr.data->sg, |
| 1431 | host->curr.data->sg_len, sg_miter_flags); |
| 1432 | } |
| 1433 | |
| 1434 | static void msmsdcc_sg_stop(struct msmsdcc_host *host) |
| 1435 | { |
| 1436 | sg_miter_stop(&host->pio.sg_miter); |
| 1437 | } |
| 1438 | |
San Mehat | 1cd2296 | 2010-02-03 12:59:29 -0800 | [diff] [blame] | 1439 | static irqreturn_t |
San Mehat | 9d2bd73 | 2009-09-22 16:44:22 -0700 | [diff] [blame] | 1440 | msmsdcc_pio_irq(int irq, void *dev_id) |
| 1441 | { |
| 1442 | struct msmsdcc_host *host = dev_id; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1443 | void __iomem *base = host->base; |
San Mehat | 9d2bd73 | 2009-09-22 16:44:22 -0700 | [diff] [blame] | 1444 | uint32_t status; |
Oluwafemi Adeyemi | a981c5c | 2012-02-09 20:02:00 -0800 | [diff] [blame] | 1445 | unsigned long flags; |
Oluwafemi Adeyemi | ecfa3df | 2012-02-28 18:08:54 -0800 | [diff] [blame] | 1446 | unsigned int remain; |
| 1447 | char *buffer; |
San Mehat | 9d2bd73 | 2009-09-22 16:44:22 -0700 | [diff] [blame] | 1448 | |
Murali Palnati | 36448a4 | 2011-09-02 15:06:18 +0530 | [diff] [blame] | 1449 | spin_lock(&host->lock); |
| 1450 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1451 | status = readl_relaxed(base + MMCISTATUS); |
Oluwafemi Adeyemi | cb79144 | 2011-07-11 22:51:25 -0700 | [diff] [blame] | 1452 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1453 | if (((readl_relaxed(host->base + MMCIMASK0) & status) & |
Murali Palnati | 36448a4 | 2011-09-02 15:06:18 +0530 | [diff] [blame] | 1454 | (MCI_IRQ_PIO)) == 0) { |
| 1455 | spin_unlock(&host->lock); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1456 | return IRQ_NONE; |
Murali Palnati | 36448a4 | 2011-09-02 15:06:18 +0530 | [diff] [blame] | 1457 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1458 | #if IRQ_DEBUG |
| 1459 | msmsdcc_print_status(host, "irq1-r", status); |
| 1460 | #endif |
Oluwafemi Adeyemi | a981c5c | 2012-02-09 20:02:00 -0800 | [diff] [blame] | 1461 | local_irq_save(flags); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1462 | |
Oluwafemi Adeyemi | ecfa3df | 2012-02-28 18:08:54 -0800 | [diff] [blame] | 1463 | do { |
| 1464 | unsigned int len; |
San Mehat | 9d2bd73 | 2009-09-22 16:44:22 -0700 | [diff] [blame] | 1465 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1466 | if (!(status & (MCI_TXFIFOHALFEMPTY | MCI_TXFIFOEMPTY |
| 1467 | | MCI_RXDATAAVLBL))) |
| 1468 | break; |
San Mehat | 9d2bd73 | 2009-09-22 16:44:22 -0700 | [diff] [blame] | 1469 | |
Oluwafemi Adeyemi | ecfa3df | 2012-02-28 18:08:54 -0800 | [diff] [blame] | 1470 | if (!msmsdcc_sg_next(host, &buffer, &remain)) |
| 1471 | break; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1472 | |
San Mehat | 9d2bd73 | 2009-09-22 16:44:22 -0700 | [diff] [blame] | 1473 | len = 0; |
| 1474 | if (status & MCI_RXACTIVE) |
| 1475 | len = msmsdcc_pio_read(host, buffer, remain); |
| 1476 | if (status & MCI_TXACTIVE) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1477 | len = msmsdcc_pio_write(host, buffer, remain); |
Oluwafemi Adeyemi | ecfa3df | 2012-02-28 18:08:54 -0800 | [diff] [blame] | 1478 | |
Sujit Reddy Thumma | 18e41a1 | 2011-12-14 21:46:54 +0530 | [diff] [blame] | 1479 | /* len might have aligned to 32bits above */ |
| 1480 | if (len > remain) |
| 1481 | len = remain; |
San Mehat | 9d2bd73 | 2009-09-22 16:44:22 -0700 | [diff] [blame] | 1482 | |
San Mehat | 9d2bd73 | 2009-09-22 16:44:22 -0700 | [diff] [blame] | 1483 | host->curr.xfer_remain -= len; |
| 1484 | host->curr.data_xfered += len; |
| 1485 | remain -= len; |
Oluwafemi Adeyemi | ecfa3df | 2012-02-28 18:08:54 -0800 | [diff] [blame] | 1486 | msmsdcc_sg_consumed(host, len); |
San Mehat | 9d2bd73 | 2009-09-22 16:44:22 -0700 | [diff] [blame] | 1487 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1488 | if (remain) /* Done with this page? */ |
| 1489 | break; /* Nope */ |
San Mehat | 9d2bd73 | 2009-09-22 16:44:22 -0700 | [diff] [blame] | 1490 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1491 | status = readl_relaxed(base + MMCISTATUS); |
Oluwafemi Adeyemi | ecfa3df | 2012-02-28 18:08:54 -0800 | [diff] [blame] | 1492 | } while (1); |
Oluwafemi Adeyemi | a981c5c | 2012-02-09 20:02:00 -0800 | [diff] [blame] | 1493 | |
Oluwafemi Adeyemi | ecfa3df | 2012-02-28 18:08:54 -0800 | [diff] [blame] | 1494 | msmsdcc_sg_stop(host); |
Oluwafemi Adeyemi | a981c5c | 2012-02-09 20:02:00 -0800 | [diff] [blame] | 1495 | local_irq_restore(flags); |
San Mehat | 9d2bd73 | 2009-09-22 16:44:22 -0700 | [diff] [blame] | 1496 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1497 | if (status & MCI_RXACTIVE && host->curr.xfer_remain < MCI_FIFOSIZE) { |
| 1498 | writel_relaxed((readl_relaxed(host->base + MMCIMASK0) & |
| 1499 | (~(MCI_IRQ_PIO))) | MCI_RXDATAAVLBLMASK, |
| 1500 | host->base + MMCIMASK0); |
| 1501 | if (!host->curr.xfer_remain) { |
Subhash Jadavani | 15f29db | 2011-10-13 09:57:13 +0530 | [diff] [blame] | 1502 | /* |
| 1503 | * back to back write to MASK0 register don't need |
| 1504 | * synchronization delay. |
| 1505 | */ |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1506 | writel_relaxed((readl_relaxed(host->base + MMCIMASK0) & |
| 1507 | (~(MCI_IRQ_PIO))) | 0, host->base + MMCIMASK0); |
| 1508 | } |
| 1509 | mb(); |
| 1510 | } else if (!host->curr.xfer_remain) { |
| 1511 | writel_relaxed((readl_relaxed(host->base + MMCIMASK0) & |
| 1512 | (~(MCI_IRQ_PIO))) | 0, host->base + MMCIMASK0); |
| 1513 | mb(); |
| 1514 | } |
San Mehat | 9d2bd73 | 2009-09-22 16:44:22 -0700 | [diff] [blame] | 1515 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1516 | spin_unlock(&host->lock); |
San Mehat | 9d2bd73 | 2009-09-22 16:44:22 -0700 | [diff] [blame] | 1517 | |
| 1518 | return IRQ_HANDLED; |
| 1519 | } |
| 1520 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1521 | static void |
| 1522 | msmsdcc_request_start(struct msmsdcc_host *host, struct mmc_request *mrq); |
| 1523 | |
| 1524 | static void msmsdcc_wait_for_rxdata(struct msmsdcc_host *host, |
| 1525 | struct mmc_data *data) |
| 1526 | { |
| 1527 | u32 loop_cnt = 0; |
| 1528 | |
| 1529 | /* |
| 1530 | * For read commands with data less than fifo size, it is possible to |
| 1531 | * get DATAEND first and RXDATA_AVAIL might be set later because of |
| 1532 | * synchronization delay through the asynchronous RX FIFO. Thus, for |
| 1533 | * such cases, even after DATAEND interrupt is received software |
| 1534 | * should poll for RXDATA_AVAIL until the requested data is read out |
| 1535 | * of FIFO. This change is needed to get around this abnormal but |
| 1536 | * sometimes expected behavior of SDCC3 controller. |
| 1537 | * |
| 1538 | * We can expect RXDATAAVAIL bit to be set after 6HCLK clock cycles |
| 1539 | * after the data is loaded into RX FIFO. This would amount to less |
| 1540 | * than a microsecond and thus looping for 1000 times is good enough |
| 1541 | * for that delay. |
| 1542 | */ |
| 1543 | while (((int)host->curr.xfer_remain > 0) && (++loop_cnt < 1000)) { |
| 1544 | if (readl_relaxed(host->base + MMCISTATUS) & MCI_RXDATAAVLBL) { |
| 1545 | spin_unlock(&host->lock); |
| 1546 | msmsdcc_pio_irq(1, host); |
| 1547 | spin_lock(&host->lock); |
| 1548 | } |
| 1549 | } |
| 1550 | if (loop_cnt == 1000) { |
| 1551 | pr_info("%s: Timed out while polling for Rx Data\n", |
| 1552 | mmc_hostname(host->mmc)); |
| 1553 | data->error = -ETIMEDOUT; |
| 1554 | msmsdcc_reset_and_restore(host); |
| 1555 | } |
| 1556 | } |
| 1557 | |
San Mehat | 9d2bd73 | 2009-09-22 16:44:22 -0700 | [diff] [blame] | 1558 | static void msmsdcc_do_cmdirq(struct msmsdcc_host *host, uint32_t status) |
| 1559 | { |
| 1560 | struct mmc_command *cmd = host->curr.cmd; |
San Mehat | 9d2bd73 | 2009-09-22 16:44:22 -0700 | [diff] [blame] | 1561 | |
| 1562 | host->curr.cmd = NULL; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1563 | cmd->resp[0] = readl_relaxed(host->base + MMCIRESPONSE0); |
| 1564 | cmd->resp[1] = readl_relaxed(host->base + MMCIRESPONSE1); |
| 1565 | cmd->resp[2] = readl_relaxed(host->base + MMCIRESPONSE2); |
| 1566 | cmd->resp[3] = readl_relaxed(host->base + MMCIRESPONSE3); |
San Mehat | 9d2bd73 | 2009-09-22 16:44:22 -0700 | [diff] [blame] | 1567 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1568 | if (status & (MCI_CMDTIMEOUT | MCI_AUTOCMD19TIMEOUT)) { |
Subhash Jadavani | b52b4d7 | 2011-12-05 19:16:28 +0530 | [diff] [blame] | 1569 | pr_debug("%s: CMD%d: Command timeout\n", |
| 1570 | mmc_hostname(host->mmc), cmd->opcode); |
San Mehat | 9d2bd73 | 2009-09-22 16:44:22 -0700 | [diff] [blame] | 1571 | cmd->error = -ETIMEDOUT; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1572 | } else if ((status & MCI_CMDCRCFAIL && cmd->flags & MMC_RSP_CRC) && |
Subhash Jadavani | 56e0eaa | 2012-03-13 18:06:04 +0530 | [diff] [blame] | 1573 | !host->tuning_in_progress) { |
Subhash Jadavani | b52b4d7 | 2011-12-05 19:16:28 +0530 | [diff] [blame] | 1574 | pr_err("%s: CMD%d: Command CRC error\n", |
| 1575 | mmc_hostname(host->mmc), cmd->opcode); |
| 1576 | msmsdcc_dump_sdcc_state(host); |
San Mehat | 9d2bd73 | 2009-09-22 16:44:22 -0700 | [diff] [blame] | 1577 | cmd->error = -EILSEQ; |
| 1578 | } |
| 1579 | |
| 1580 | if (!cmd->data || cmd->error) { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1581 | if (host->curr.data && host->dma.sg && |
| 1582 | host->is_dma_mode) |
San Mehat | 9d2bd73 | 2009-09-22 16:44:22 -0700 | [diff] [blame] | 1583 | msm_dmov_stop_cmd(host->dma.channel, |
| 1584 | &host->dma.hdr, 0); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1585 | else if (host->curr.data && host->sps.sg && |
| 1586 | host->is_sps_mode){ |
| 1587 | /* Stop current SPS transfer */ |
| 1588 | msmsdcc_sps_exit_curr_xfer(host); |
| 1589 | } |
San Mehat | 9d2bd73 | 2009-09-22 16:44:22 -0700 | [diff] [blame] | 1590 | else if (host->curr.data) { /* Non DMA */ |
Sahitya Tummala | b08bb35 | 2010-12-08 15:03:05 +0530 | [diff] [blame] | 1591 | msmsdcc_reset_and_restore(host); |
San Mehat | 9d2bd73 | 2009-09-22 16:44:22 -0700 | [diff] [blame] | 1592 | msmsdcc_stop_data(host); |
Sujit Reddy Thumma | 055106d | 2012-01-16 15:16:26 +0530 | [diff] [blame] | 1593 | msmsdcc_request_end(host, cmd->mrq); |
Sahitya Tummala | d5137bd | 2010-12-08 15:03:04 +0530 | [diff] [blame] | 1594 | } else { /* host->data == NULL */ |
Sujit Reddy Thumma | 055106d | 2012-01-16 15:16:26 +0530 | [diff] [blame] | 1595 | if (!cmd->error && host->prog_enable) { |
Sahitya Tummala | d5137bd | 2010-12-08 15:03:04 +0530 | [diff] [blame] | 1596 | if (status & MCI_PROGDONE) { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1597 | host->prog_enable = 0; |
Subhash Jadavani | 7d8c94d | 2011-10-18 18:00:07 +0530 | [diff] [blame] | 1598 | msmsdcc_request_end(host, cmd->mrq); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1599 | } else |
Sahitya Tummala | d5137bd | 2010-12-08 15:03:04 +0530 | [diff] [blame] | 1600 | host->curr.cmd = cmd; |
Sahitya Tummala | d5137bd | 2010-12-08 15:03:04 +0530 | [diff] [blame] | 1601 | } else { |
Subhash Jadavani | 7d8c94d | 2011-10-18 18:00:07 +0530 | [diff] [blame] | 1602 | host->prog_enable = 0; |
Subhash Jadavani | ed6b0e4 | 2012-03-07 16:36:27 +0530 | [diff] [blame] | 1603 | host->curr.wait_for_auto_prog_done = 0; |
Oluwafemi Adeyemi | cb79144 | 2011-07-11 22:51:25 -0700 | [diff] [blame] | 1604 | if (host->dummy_52_needed) |
| 1605 | host->dummy_52_needed = 0; |
| 1606 | if (cmd->data && cmd->error) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1607 | msmsdcc_reset_and_restore(host); |
Sahitya Tummala | d5137bd | 2010-12-08 15:03:04 +0530 | [diff] [blame] | 1608 | msmsdcc_request_end(host, cmd->mrq); |
| 1609 | } |
| 1610 | } |
Subhash Jadavani | 1d6ba60 | 2011-09-21 18:10:54 +0530 | [diff] [blame] | 1611 | } else if ((cmd == host->curr.mrq->sbc) && cmd->data) { |
| 1612 | if (cmd->data->flags & MMC_DATA_READ) |
| 1613 | msmsdcc_start_command(host, host->curr.mrq->cmd, 0); |
| 1614 | else |
| 1615 | msmsdcc_request_start(host, host->curr.mrq); |
Sujit Reddy Thumma | df8e9b2 | 2011-11-04 16:22:06 +0530 | [diff] [blame] | 1616 | } else if (cmd->data) { |
| 1617 | if (!(cmd->data->flags & MMC_DATA_READ)) |
| 1618 | msmsdcc_start_data(host, cmd->data, NULL, 0); |
Joe Perches | b5a74d6 | 2009-09-22 16:44:25 -0700 | [diff] [blame] | 1619 | } |
| 1620 | } |
| 1621 | |
San Mehat | 9d2bd73 | 2009-09-22 16:44:22 -0700 | [diff] [blame] | 1622 | static irqreturn_t |
| 1623 | msmsdcc_irq(int irq, void *dev_id) |
| 1624 | { |
| 1625 | struct msmsdcc_host *host = dev_id; |
San Mehat | 9d2bd73 | 2009-09-22 16:44:22 -0700 | [diff] [blame] | 1626 | u32 status; |
| 1627 | int ret = 0; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1628 | int timer = 0; |
San Mehat | 9d2bd73 | 2009-09-22 16:44:22 -0700 | [diff] [blame] | 1629 | |
| 1630 | spin_lock(&host->lock); |
| 1631 | |
| 1632 | do { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1633 | struct mmc_command *cmd; |
| 1634 | struct mmc_data *data; |
San Mehat | 9d2bd73 | 2009-09-22 16:44:22 -0700 | [diff] [blame] | 1635 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1636 | if (timer) { |
| 1637 | timer = 0; |
| 1638 | msmsdcc_delay(host); |
| 1639 | } |
San Mehat | 865c806 | 2009-11-13 13:42:06 -0800 | [diff] [blame] | 1640 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1641 | if (!host->clks_on) { |
| 1642 | pr_debug("%s: %s: SDIO async irq received\n", |
| 1643 | mmc_hostname(host->mmc), __func__); |
Sujit Reddy Thumma | f4a999c | 2012-02-09 23:14:45 +0530 | [diff] [blame] | 1644 | |
| 1645 | /* |
| 1646 | * Only async interrupt can come when clocks are off, |
| 1647 | * disable further interrupts and enable them when |
| 1648 | * clocks are on. |
| 1649 | */ |
| 1650 | if (!host->sdcc_irq_disabled) { |
| 1651 | disable_irq_nosync(irq); |
| 1652 | host->sdcc_irq_disabled = 1; |
| 1653 | } |
| 1654 | |
| 1655 | /* |
| 1656 | * If mmc_card_wake_sdio_irq() is set, mmc core layer |
| 1657 | * will take care of signaling sdio irq during |
| 1658 | * mmc_sdio_resume(). |
| 1659 | */ |
| 1660 | if (host->sdcc_suspended) |
| 1661 | /* |
| 1662 | * This is a wakeup interrupt so hold wakelock |
| 1663 | * until SDCC resume is handled. |
| 1664 | */ |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1665 | wake_lock(&host->sdio_wlock); |
Sujit Reddy Thumma | f4a999c | 2012-02-09 23:14:45 +0530 | [diff] [blame] | 1666 | else |
| 1667 | mmc_signal_sdio_irq(host->mmc); |
| 1668 | ret = 1; |
| 1669 | break; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1670 | } |
| 1671 | |
| 1672 | status = readl_relaxed(host->base + MMCISTATUS); |
| 1673 | |
| 1674 | if (((readl_relaxed(host->base + MMCIMASK0) & status) & |
| 1675 | (~(MCI_IRQ_PIO))) == 0) |
San Mehat | 865c806 | 2009-11-13 13:42:06 -0800 | [diff] [blame] | 1676 | break; |
San Mehat | 9d2bd73 | 2009-09-22 16:44:22 -0700 | [diff] [blame] | 1677 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1678 | #if IRQ_DEBUG |
| 1679 | msmsdcc_print_status(host, "irq0-r", status); |
| 1680 | #endif |
| 1681 | status &= readl_relaxed(host->base + MMCIMASK0); |
| 1682 | writel_relaxed(status, host->base + MMCICLEAR); |
Sujith Reddy Thumma | c1824d5 | 2011-09-28 10:05:44 +0530 | [diff] [blame] | 1683 | /* Allow clear to take effect*/ |
Sujith Reddy Thumma | 32fae1a | 2011-10-03 11:16:51 +0530 | [diff] [blame] | 1684 | if (host->clk_rate <= |
| 1685 | msmsdcc_get_min_sup_clk_rate(host)) |
Subhash Jadavani | dd43295 | 2012-03-28 11:25:56 +0530 | [diff] [blame] | 1686 | msmsdcc_sync_reg_wr(host); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1687 | #if IRQ_DEBUG |
| 1688 | msmsdcc_print_status(host, "irq0-p", status); |
| 1689 | #endif |
Oluwafemi Adeyemi | cb79144 | 2011-07-11 22:51:25 -0700 | [diff] [blame] | 1690 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1691 | if (status & MCI_SDIOINTROPE) { |
| 1692 | if (host->sdcc_suspending) |
| 1693 | wake_lock(&host->sdio_suspend_wlock); |
| 1694 | mmc_signal_sdio_irq(host->mmc); |
San Mehat | 9d2bd73 | 2009-09-22 16:44:22 -0700 | [diff] [blame] | 1695 | } |
Oluwafemi Adeyemi | cb79144 | 2011-07-11 22:51:25 -0700 | [diff] [blame] | 1696 | data = host->curr.data; |
| 1697 | |
| 1698 | if (host->dummy_52_sent) { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1699 | if (status & (MCI_PROGDONE | MCI_CMDCRCFAIL | |
| 1700 | MCI_CMDTIMEOUT)) { |
| 1701 | if (status & MCI_CMDTIMEOUT) |
| 1702 | pr_debug("%s: dummy CMD52 timeout\n", |
| 1703 | mmc_hostname(host->mmc)); |
| 1704 | if (status & MCI_CMDCRCFAIL) |
| 1705 | pr_debug("%s: dummy CMD52 CRC failed\n", |
| 1706 | mmc_hostname(host->mmc)); |
Oluwafemi Adeyemi | cb79144 | 2011-07-11 22:51:25 -0700 | [diff] [blame] | 1707 | host->dummy_52_sent = 0; |
| 1708 | host->dummy_52_needed = 0; |
| 1709 | if (data) { |
| 1710 | msmsdcc_stop_data(host); |
| 1711 | msmsdcc_request_end(host, data->mrq); |
| 1712 | } |
| 1713 | WARN(!data, "No data cmd for dummy CMD52\n"); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1714 | spin_unlock(&host->lock); |
| 1715 | return IRQ_HANDLED; |
| 1716 | } |
| 1717 | break; |
| 1718 | } |
| 1719 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1720 | /* |
| 1721 | * Check for proper command response |
| 1722 | */ |
| 1723 | cmd = host->curr.cmd; |
| 1724 | if ((status & (MCI_CMDSENT | MCI_CMDRESPEND | MCI_CMDCRCFAIL | |
| 1725 | MCI_CMDTIMEOUT | MCI_PROGDONE | |
| 1726 | MCI_AUTOCMD19TIMEOUT)) && host->curr.cmd) { |
| 1727 | msmsdcc_do_cmdirq(host, status); |
| 1728 | } |
| 1729 | |
Sathish Ambley | 081d784 | 2011-11-29 11:19:41 -0800 | [diff] [blame] | 1730 | if (host->curr.data) { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1731 | /* Check for data errors */ |
| 1732 | if (status & (MCI_DATACRCFAIL|MCI_DATATIMEOUT| |
| 1733 | MCI_TXUNDERRUN|MCI_RXOVERRUN)) { |
| 1734 | msmsdcc_data_err(host, data, status); |
| 1735 | host->curr.data_xfered = 0; |
| 1736 | if (host->dma.sg && host->is_dma_mode) |
| 1737 | msm_dmov_stop_cmd(host->dma.channel, |
| 1738 | &host->dma.hdr, 0); |
| 1739 | else if (host->sps.sg && host->is_sps_mode) { |
| 1740 | /* Stop current SPS transfer */ |
| 1741 | msmsdcc_sps_exit_curr_xfer(host); |
Subhash Jadavani | a8e5ecb | 2011-08-25 19:19:58 +0530 | [diff] [blame] | 1742 | } else { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1743 | msmsdcc_reset_and_restore(host); |
| 1744 | if (host->curr.data) |
| 1745 | msmsdcc_stop_data(host); |
Subhash Jadavani | a8e5ecb | 2011-08-25 19:19:58 +0530 | [diff] [blame] | 1746 | if (!data->stop || (host->curr.mrq->sbc |
| 1747 | && !data->error)) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1748 | timer |= |
| 1749 | msmsdcc_request_end(host, |
| 1750 | data->mrq); |
Subhash Jadavani | a8e5ecb | 2011-08-25 19:19:58 +0530 | [diff] [blame] | 1751 | else if ((host->curr.mrq->sbc |
| 1752 | && data->error) || |
| 1753 | !host->curr.mrq->sbc) { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1754 | msmsdcc_start_command(host, |
| 1755 | data->stop, |
| 1756 | 0); |
| 1757 | timer = 1; |
| 1758 | } |
| 1759 | } |
| 1760 | } |
| 1761 | |
Subhash Jadavani | 7a651aa | 2011-08-03 20:44:58 +0530 | [diff] [blame] | 1762 | /* Check for prog done */ |
| 1763 | if (host->curr.wait_for_auto_prog_done && |
| 1764 | (status & MCI_PROGDONE)) |
| 1765 | host->curr.got_auto_prog_done = 1; |
| 1766 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1767 | /* Check for data done */ |
| 1768 | if (!host->curr.got_dataend && (status & MCI_DATAEND)) |
| 1769 | host->curr.got_dataend = 1; |
| 1770 | |
Subhash Jadavani | 7a651aa | 2011-08-03 20:44:58 +0530 | [diff] [blame] | 1771 | if (host->curr.got_dataend && |
| 1772 | (!host->curr.wait_for_auto_prog_done || |
| 1773 | (host->curr.wait_for_auto_prog_done && |
| 1774 | host->curr.got_auto_prog_done))) { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1775 | /* |
| 1776 | * If DMA is still in progress, we complete |
| 1777 | * via the completion handler |
| 1778 | */ |
| 1779 | if (!host->dma.busy && !host->sps.busy) { |
| 1780 | /* |
| 1781 | * There appears to be an issue in the |
| 1782 | * controller where if you request a |
| 1783 | * small block transfer (< fifo size), |
| 1784 | * you may get your DATAEND/DATABLKEND |
| 1785 | * irq without the PIO data irq. |
| 1786 | * |
| 1787 | * Check to see if theres still data |
| 1788 | * to be read, and simulate a PIO irq. |
| 1789 | */ |
| 1790 | if (data->flags & MMC_DATA_READ) |
| 1791 | msmsdcc_wait_for_rxdata(host, |
| 1792 | data); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1793 | if (!data->error) { |
| 1794 | host->curr.data_xfered = |
| 1795 | host->curr.xfer_size; |
| 1796 | host->curr.xfer_remain -= |
| 1797 | host->curr.xfer_size; |
| 1798 | } |
| 1799 | |
Oluwafemi Adeyemi | cb79144 | 2011-07-11 22:51:25 -0700 | [diff] [blame] | 1800 | if (!host->dummy_52_needed) { |
| 1801 | msmsdcc_stop_data(host); |
Subhash Jadavani | a8e5ecb | 2011-08-25 19:19:58 +0530 | [diff] [blame] | 1802 | if (!data->stop || |
| 1803 | (host->curr.mrq->sbc |
| 1804 | && !data->error)) |
Oluwafemi Adeyemi | cb79144 | 2011-07-11 22:51:25 -0700 | [diff] [blame] | 1805 | msmsdcc_request_end( |
| 1806 | host, |
| 1807 | data->mrq); |
Subhash Jadavani | a8e5ecb | 2011-08-25 19:19:58 +0530 | [diff] [blame] | 1808 | else if ((host->curr.mrq->sbc |
| 1809 | && data->error) || |
| 1810 | !host->curr.mrq->sbc) { |
Oluwafemi Adeyemi | cb79144 | 2011-07-11 22:51:25 -0700 | [diff] [blame] | 1811 | msmsdcc_start_command( |
| 1812 | host, |
| 1813 | data->stop, 0); |
| 1814 | timer = 1; |
| 1815 | } |
| 1816 | } else { |
| 1817 | host->dummy_52_sent = 1; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1818 | msmsdcc_start_command(host, |
Oluwafemi Adeyemi | cb79144 | 2011-07-11 22:51:25 -0700 | [diff] [blame] | 1819 | &dummy52cmd, |
| 1820 | MCI_CPSM_PROGENA); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1821 | } |
| 1822 | } |
| 1823 | } |
| 1824 | } |
| 1825 | |
San Mehat | 9d2bd73 | 2009-09-22 16:44:22 -0700 | [diff] [blame] | 1826 | ret = 1; |
| 1827 | } while (status); |
| 1828 | |
| 1829 | spin_unlock(&host->lock); |
| 1830 | |
San Mehat | 9d2bd73 | 2009-09-22 16:44:22 -0700 | [diff] [blame] | 1831 | return IRQ_RETVAL(ret); |
| 1832 | } |
| 1833 | |
| 1834 | static void |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1835 | msmsdcc_request_start(struct msmsdcc_host *host, struct mmc_request *mrq) |
| 1836 | { |
Sujit Reddy Thumma | df8e9b2 | 2011-11-04 16:22:06 +0530 | [diff] [blame] | 1837 | if (mrq->data && mrq->data->flags & MMC_DATA_READ) { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1838 | /* Queue/read data, daisy-chain command when data starts */ |
Sujit Reddy Thumma | df8e9b2 | 2011-11-04 16:22:06 +0530 | [diff] [blame] | 1839 | if (mrq->sbc) |
Subhash Jadavani | 1d6ba60 | 2011-09-21 18:10:54 +0530 | [diff] [blame] | 1840 | msmsdcc_start_data(host, mrq->data, mrq->sbc, 0); |
| 1841 | else |
| 1842 | msmsdcc_start_data(host, mrq->data, mrq->cmd, 0); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1843 | } else { |
| 1844 | msmsdcc_start_command(host, mrq->cmd, 0); |
| 1845 | } |
| 1846 | } |
| 1847 | |
| 1848 | static void |
San Mehat | 9d2bd73 | 2009-09-22 16:44:22 -0700 | [diff] [blame] | 1849 | msmsdcc_request(struct mmc_host *mmc, struct mmc_request *mrq) |
| 1850 | { |
| 1851 | struct msmsdcc_host *host = mmc_priv(mmc); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1852 | unsigned long flags; |
San Mehat | 9d2bd73 | 2009-09-22 16:44:22 -0700 | [diff] [blame] | 1853 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1854 | /* |
| 1855 | * Get the SDIO AL client out of LPM. |
| 1856 | */ |
Oluwafemi Adeyemi | cb79144 | 2011-07-11 22:51:25 -0700 | [diff] [blame] | 1857 | WARN(host->dummy_52_sent, "Dummy CMD52 in progress\n"); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1858 | if (host->plat->is_sdio_al_client) |
| 1859 | msmsdcc_sdio_al_lpm(mmc, false); |
San Mehat | 9d2bd73 | 2009-09-22 16:44:22 -0700 | [diff] [blame] | 1860 | |
Subhash Jadavani | b5b0774 | 2011-08-29 17:48:07 +0530 | [diff] [blame] | 1861 | /* check if sps pipe reset is pending? */ |
| 1862 | if (host->is_sps_mode && host->sps.pipe_reset_pending) { |
| 1863 | msmsdcc_sps_pipes_reset_and_restore(host); |
| 1864 | host->sps.pipe_reset_pending = false; |
| 1865 | } |
| 1866 | |
San Mehat | 9d2bd73 | 2009-09-22 16:44:22 -0700 | [diff] [blame] | 1867 | spin_lock_irqsave(&host->lock, flags); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1868 | WARN(host->curr.mrq, "Request in progress\n"); |
| 1869 | WARN(!host->pwr, "SDCC power is turned off\n"); |
| 1870 | WARN(!host->clks_on, "SDCC clocks are turned off\n"); |
| 1871 | WARN(host->sdcc_irq_disabled, "SDCC IRQ is disabled\n"); |
San Mehat | 9d2bd73 | 2009-09-22 16:44:22 -0700 | [diff] [blame] | 1872 | |
| 1873 | if (host->eject) { |
| 1874 | if (mrq->data && !(mrq->data->flags & MMC_DATA_READ)) { |
| 1875 | mrq->cmd->error = 0; |
| 1876 | mrq->data->bytes_xfered = mrq->data->blksz * |
| 1877 | mrq->data->blocks; |
| 1878 | } else |
| 1879 | mrq->cmd->error = -ENOMEDIUM; |
| 1880 | |
| 1881 | spin_unlock_irqrestore(&host->lock, flags); |
| 1882 | mmc_request_done(mmc, mrq); |
| 1883 | return; |
| 1884 | } |
| 1885 | |
Subhash Jadavani | a8e5ecb | 2011-08-25 19:19:58 +0530 | [diff] [blame] | 1886 | /* |
| 1887 | * Kick the software command timeout timer here. |
| 1888 | * Timer expires in 10 secs. |
| 1889 | */ |
| 1890 | mod_timer(&host->req_tout_timer, |
| 1891 | (jiffies + msecs_to_jiffies(MSM_MMC_REQ_TIMEOUT))); |
San Mehat | 9d2bd73 | 2009-09-22 16:44:22 -0700 | [diff] [blame] | 1892 | |
Subhash Jadavani | a8e5ecb | 2011-08-25 19:19:58 +0530 | [diff] [blame] | 1893 | host->curr.mrq = mrq; |
Subhash Jadavani | 1d6ba60 | 2011-09-21 18:10:54 +0530 | [diff] [blame] | 1894 | if (mrq->data && (mrq->data->flags & MMC_DATA_WRITE)) { |
Subhash Jadavani | 7a651aa | 2011-08-03 20:44:58 +0530 | [diff] [blame] | 1895 | if (mrq->cmd->opcode == SD_IO_RW_EXTENDED || |
| 1896 | mrq->cmd->opcode == 54) { |
Pratibhasagar V | 1c11da6 | 2011-11-14 12:36:35 +0530 | [diff] [blame] | 1897 | if (!host->sdcc_version) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1898 | host->dummy_52_needed = 1; |
Subhash Jadavani | 7a651aa | 2011-08-03 20:44:58 +0530 | [diff] [blame] | 1899 | else |
| 1900 | /* |
| 1901 | * SDCCv4 supports AUTO_PROG_DONE bit for SDIO |
| 1902 | * write operations using CMD53 and CMD54. |
| 1903 | * Setting this bit with CMD53 would |
| 1904 | * automatically triggers PROG_DONE interrupt |
| 1905 | * without the need of sending dummy CMD52. |
| 1906 | */ |
| 1907 | host->curr.wait_for_auto_prog_done = 1; |
Subhash Jadavani | 758cf8c | 2011-11-13 11:59:55 +0530 | [diff] [blame] | 1908 | } else if (mrq->cmd->opcode == MMC_WRITE_BLOCK && |
| 1909 | host->sdcc_version) { |
| 1910 | host->curr.wait_for_auto_prog_done = 1; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1911 | } |
San Mehat | 9d2bd73 | 2009-09-22 16:44:22 -0700 | [diff] [blame] | 1912 | } |
Subhash Jadavani | 7a651aa | 2011-08-03 20:44:58 +0530 | [diff] [blame] | 1913 | |
Pratibhasagar V | 00b9433 | 2011-10-18 14:57:27 +0530 | [diff] [blame] | 1914 | if (mrq->data && mrq->sbc) { |
Subhash Jadavani | a8e5ecb | 2011-08-25 19:19:58 +0530 | [diff] [blame] | 1915 | mrq->sbc->mrq = mrq; |
| 1916 | mrq->sbc->data = mrq->data; |
Subhash Jadavani | 1d6ba60 | 2011-09-21 18:10:54 +0530 | [diff] [blame] | 1917 | if (mrq->data->flags & MMC_DATA_WRITE) { |
Subhash Jadavani | a8e5ecb | 2011-08-25 19:19:58 +0530 | [diff] [blame] | 1918 | host->curr.wait_for_auto_prog_done = 1; |
Subhash Jadavani | 1d6ba60 | 2011-09-21 18:10:54 +0530 | [diff] [blame] | 1919 | msmsdcc_start_command(host, mrq->sbc, 0); |
| 1920 | } else { |
| 1921 | msmsdcc_request_start(host, mrq); |
| 1922 | } |
Subhash Jadavani | a8e5ecb | 2011-08-25 19:19:58 +0530 | [diff] [blame] | 1923 | } else { |
| 1924 | msmsdcc_request_start(host, mrq); |
| 1925 | } |
| 1926 | |
San Mehat | 9d2bd73 | 2009-09-22 16:44:22 -0700 | [diff] [blame] | 1927 | spin_unlock_irqrestore(&host->lock, flags); |
| 1928 | } |
| 1929 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1930 | static inline int msmsdcc_vreg_set_voltage(struct msm_mmc_reg_data *vreg, |
| 1931 | int min_uV, int max_uV) |
| 1932 | { |
| 1933 | int rc = 0; |
| 1934 | |
| 1935 | if (vreg->set_voltage_sup) { |
| 1936 | rc = regulator_set_voltage(vreg->reg, min_uV, max_uV); |
| 1937 | if (rc) { |
| 1938 | pr_err("%s: regulator_set_voltage(%s) failed." |
| 1939 | " min_uV=%d, max_uV=%d, rc=%d\n", |
| 1940 | __func__, vreg->name, min_uV, max_uV, rc); |
| 1941 | } |
| 1942 | } |
| 1943 | |
| 1944 | return rc; |
| 1945 | } |
| 1946 | |
| 1947 | static inline int msmsdcc_vreg_set_optimum_mode(struct msm_mmc_reg_data *vreg, |
| 1948 | int uA_load) |
| 1949 | { |
| 1950 | int rc = 0; |
| 1951 | |
Krishna Konda | fea6018 | 2011-11-01 16:01:34 -0700 | [diff] [blame] | 1952 | /* regulators that do not support regulator_set_voltage also |
| 1953 | do not support regulator_set_optimum_mode */ |
| 1954 | if (vreg->set_voltage_sup) { |
| 1955 | rc = regulator_set_optimum_mode(vreg->reg, uA_load); |
| 1956 | if (rc < 0) |
| 1957 | pr_err("%s: regulator_set_optimum_mode(reg=%s, " |
| 1958 | "uA_load=%d) failed. rc=%d\n", __func__, |
| 1959 | vreg->name, uA_load, rc); |
| 1960 | else |
| 1961 | /* regulator_set_optimum_mode() can return non zero |
| 1962 | * value even for success case. |
| 1963 | */ |
| 1964 | rc = 0; |
| 1965 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1966 | |
| 1967 | return rc; |
| 1968 | } |
| 1969 | |
| 1970 | static inline int msmsdcc_vreg_init_reg(struct msm_mmc_reg_data *vreg, |
| 1971 | struct device *dev) |
| 1972 | { |
| 1973 | int rc = 0; |
| 1974 | |
| 1975 | /* check if regulator is already initialized? */ |
| 1976 | if (vreg->reg) |
| 1977 | goto out; |
| 1978 | |
| 1979 | /* Get the regulator handle */ |
| 1980 | vreg->reg = regulator_get(dev, vreg->name); |
| 1981 | if (IS_ERR(vreg->reg)) { |
| 1982 | rc = PTR_ERR(vreg->reg); |
| 1983 | pr_err("%s: regulator_get(%s) failed. rc=%d\n", |
| 1984 | __func__, vreg->name, rc); |
Krishna Konda | 9f7d67e | 2011-11-07 23:40:13 -0800 | [diff] [blame] | 1985 | goto out; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1986 | } |
Krishna Konda | 9f7d67e | 2011-11-07 23:40:13 -0800 | [diff] [blame] | 1987 | |
| 1988 | if (regulator_count_voltages(vreg->reg) > 0) |
| 1989 | vreg->set_voltage_sup = 1; |
| 1990 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1991 | out: |
| 1992 | return rc; |
| 1993 | } |
| 1994 | |
| 1995 | static inline void msmsdcc_vreg_deinit_reg(struct msm_mmc_reg_data *vreg) |
| 1996 | { |
| 1997 | if (vreg->reg) |
| 1998 | regulator_put(vreg->reg); |
| 1999 | } |
| 2000 | |
| 2001 | /* This init function should be called only once for each SDCC slot */ |
| 2002 | static int msmsdcc_vreg_init(struct msmsdcc_host *host, bool is_init) |
| 2003 | { |
| 2004 | int rc = 0; |
| 2005 | struct msm_mmc_slot_reg_data *curr_slot; |
| 2006 | struct msm_mmc_reg_data *curr_vdd_reg, *curr_vccq_reg, *curr_vddp_reg; |
| 2007 | struct device *dev = mmc_dev(host->mmc); |
| 2008 | |
| 2009 | curr_slot = host->plat->vreg_data; |
| 2010 | if (!curr_slot) |
| 2011 | goto out; |
| 2012 | |
| 2013 | curr_vdd_reg = curr_slot->vdd_data; |
| 2014 | curr_vccq_reg = curr_slot->vccq_data; |
| 2015 | curr_vddp_reg = curr_slot->vddp_data; |
| 2016 | |
| 2017 | if (is_init) { |
| 2018 | /* |
| 2019 | * Get the regulator handle from voltage regulator framework |
| 2020 | * and then try to set the voltage level for the regulator |
| 2021 | */ |
| 2022 | if (curr_vdd_reg) { |
| 2023 | rc = msmsdcc_vreg_init_reg(curr_vdd_reg, dev); |
| 2024 | if (rc) |
| 2025 | goto out; |
| 2026 | } |
| 2027 | if (curr_vccq_reg) { |
| 2028 | rc = msmsdcc_vreg_init_reg(curr_vccq_reg, dev); |
| 2029 | if (rc) |
| 2030 | goto vdd_reg_deinit; |
| 2031 | } |
| 2032 | if (curr_vddp_reg) { |
| 2033 | rc = msmsdcc_vreg_init_reg(curr_vddp_reg, dev); |
| 2034 | if (rc) |
| 2035 | goto vccq_reg_deinit; |
| 2036 | } |
Oluwafemi Adeyemi | 4ea731c | 2012-03-07 14:47:36 -0800 | [diff] [blame] | 2037 | rc = msmsdcc_vreg_reset(host); |
| 2038 | if (rc) |
| 2039 | pr_err("msmsdcc.%d vreg reset failed (%d)\n", |
| 2040 | host->pdev_id, rc); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2041 | goto out; |
| 2042 | } else { |
| 2043 | /* Deregister all regulators from regulator framework */ |
| 2044 | goto vddp_reg_deinit; |
| 2045 | } |
| 2046 | vddp_reg_deinit: |
| 2047 | if (curr_vddp_reg) |
| 2048 | msmsdcc_vreg_deinit_reg(curr_vddp_reg); |
| 2049 | vccq_reg_deinit: |
| 2050 | if (curr_vccq_reg) |
| 2051 | msmsdcc_vreg_deinit_reg(curr_vccq_reg); |
| 2052 | vdd_reg_deinit: |
| 2053 | if (curr_vdd_reg) |
| 2054 | msmsdcc_vreg_deinit_reg(curr_vdd_reg); |
| 2055 | out: |
| 2056 | return rc; |
| 2057 | } |
| 2058 | |
| 2059 | static int msmsdcc_vreg_enable(struct msm_mmc_reg_data *vreg) |
| 2060 | { |
| 2061 | int rc = 0; |
| 2062 | |
Subhash Jadavani | cc92269 | 2011-08-01 23:05:01 +0530 | [diff] [blame] | 2063 | /* Put regulator in HPM (high power mode) */ |
| 2064 | rc = msmsdcc_vreg_set_optimum_mode(vreg, vreg->hpm_uA); |
| 2065 | if (rc < 0) |
| 2066 | goto out; |
| 2067 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2068 | if (!vreg->is_enabled) { |
| 2069 | /* Set voltage level */ |
Subhash Jadavani | 99ba53a | 2011-08-01 16:04:18 +0530 | [diff] [blame] | 2070 | rc = msmsdcc_vreg_set_voltage(vreg, vreg->high_vol_level, |
| 2071 | vreg->high_vol_level); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2072 | if (rc) |
| 2073 | goto out; |
| 2074 | |
| 2075 | rc = regulator_enable(vreg->reg); |
| 2076 | if (rc) { |
| 2077 | pr_err("%s: regulator_enable(%s) failed. rc=%d\n", |
| 2078 | __func__, vreg->name, rc); |
| 2079 | goto out; |
| 2080 | } |
| 2081 | vreg->is_enabled = true; |
| 2082 | } |
| 2083 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2084 | out: |
| 2085 | return rc; |
| 2086 | } |
| 2087 | |
| 2088 | static int msmsdcc_vreg_disable(struct msm_mmc_reg_data *vreg) |
| 2089 | { |
| 2090 | int rc = 0; |
| 2091 | |
| 2092 | /* Never disable regulator marked as always_on */ |
| 2093 | if (vreg->is_enabled && !vreg->always_on) { |
| 2094 | rc = regulator_disable(vreg->reg); |
| 2095 | if (rc) { |
| 2096 | pr_err("%s: regulator_disable(%s) failed. rc=%d\n", |
| 2097 | __func__, vreg->name, rc); |
| 2098 | goto out; |
| 2099 | } |
| 2100 | vreg->is_enabled = false; |
| 2101 | |
| 2102 | rc = msmsdcc_vreg_set_optimum_mode(vreg, 0); |
| 2103 | if (rc < 0) |
| 2104 | goto out; |
| 2105 | |
| 2106 | /* Set min. voltage level to 0 */ |
Subhash Jadavani | 99ba53a | 2011-08-01 16:04:18 +0530 | [diff] [blame] | 2107 | rc = msmsdcc_vreg_set_voltage(vreg, 0, vreg->high_vol_level); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2108 | if (rc) |
| 2109 | goto out; |
| 2110 | } else if (vreg->is_enabled && vreg->always_on && vreg->lpm_sup) { |
| 2111 | /* Put always_on regulator in LPM (low power mode) */ |
| 2112 | rc = msmsdcc_vreg_set_optimum_mode(vreg, vreg->lpm_uA); |
| 2113 | if (rc < 0) |
| 2114 | goto out; |
| 2115 | } |
| 2116 | out: |
| 2117 | return rc; |
| 2118 | } |
| 2119 | |
| 2120 | static int msmsdcc_setup_vreg(struct msmsdcc_host *host, bool enable) |
| 2121 | { |
| 2122 | int rc = 0, i; |
| 2123 | struct msm_mmc_slot_reg_data *curr_slot; |
| 2124 | struct msm_mmc_reg_data *curr_vdd_reg, *curr_vccq_reg, *curr_vddp_reg; |
| 2125 | struct msm_mmc_reg_data *vreg_table[3]; |
| 2126 | |
| 2127 | curr_slot = host->plat->vreg_data; |
| 2128 | if (!curr_slot) |
| 2129 | goto out; |
| 2130 | |
| 2131 | curr_vdd_reg = vreg_table[0] = curr_slot->vdd_data; |
| 2132 | curr_vccq_reg = vreg_table[1] = curr_slot->vccq_data; |
| 2133 | curr_vddp_reg = vreg_table[2] = curr_slot->vddp_data; |
| 2134 | |
| 2135 | for (i = 0; i < ARRAY_SIZE(vreg_table); i++) { |
| 2136 | if (vreg_table[i]) { |
| 2137 | if (enable) |
| 2138 | rc = msmsdcc_vreg_enable(vreg_table[i]); |
| 2139 | else |
| 2140 | rc = msmsdcc_vreg_disable(vreg_table[i]); |
| 2141 | if (rc) |
| 2142 | goto out; |
| 2143 | } |
| 2144 | } |
| 2145 | out: |
| 2146 | return rc; |
| 2147 | } |
| 2148 | |
Oluwafemi Adeyemi | 4ea731c | 2012-03-07 14:47:36 -0800 | [diff] [blame] | 2149 | /* |
| 2150 | * Reset vreg by ensuring it is off during probe. A call |
| 2151 | * to enable vreg is needed to balance disable vreg |
| 2152 | */ |
| 2153 | static int msmsdcc_vreg_reset(struct msmsdcc_host *host) |
| 2154 | { |
| 2155 | int rc; |
| 2156 | |
| 2157 | rc = msmsdcc_setup_vreg(host, 1); |
| 2158 | if (rc) |
| 2159 | return rc; |
| 2160 | rc = msmsdcc_setup_vreg(host, 0); |
| 2161 | return rc; |
| 2162 | } |
| 2163 | |
Subhash Jadavani | 99ba53a | 2011-08-01 16:04:18 +0530 | [diff] [blame] | 2164 | static int msmsdcc_set_vddp_level(struct msmsdcc_host *host, int level) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2165 | { |
| 2166 | int rc = 0; |
| 2167 | |
| 2168 | if (host->plat->vreg_data) { |
| 2169 | struct msm_mmc_reg_data *vddp_reg = |
| 2170 | host->plat->vreg_data->vddp_data; |
| 2171 | |
| 2172 | if (vddp_reg && vddp_reg->is_enabled) |
| 2173 | rc = msmsdcc_vreg_set_voltage(vddp_reg, level, level); |
| 2174 | } |
| 2175 | |
| 2176 | return rc; |
| 2177 | } |
| 2178 | |
Subhash Jadavani | 99ba53a | 2011-08-01 16:04:18 +0530 | [diff] [blame] | 2179 | static inline int msmsdcc_set_vddp_low_vol(struct msmsdcc_host *host) |
| 2180 | { |
| 2181 | struct msm_mmc_slot_reg_data *curr_slot = host->plat->vreg_data; |
| 2182 | int rc = 0; |
| 2183 | |
| 2184 | if (curr_slot && curr_slot->vddp_data) { |
| 2185 | rc = msmsdcc_set_vddp_level(host, |
| 2186 | curr_slot->vddp_data->low_vol_level); |
| 2187 | |
| 2188 | if (rc) |
| 2189 | pr_err("%s: %s: failed to change vddp level to %d", |
| 2190 | mmc_hostname(host->mmc), __func__, |
| 2191 | curr_slot->vddp_data->low_vol_level); |
| 2192 | } |
| 2193 | |
| 2194 | return rc; |
| 2195 | } |
| 2196 | |
| 2197 | static inline int msmsdcc_set_vddp_high_vol(struct msmsdcc_host *host) |
| 2198 | { |
| 2199 | struct msm_mmc_slot_reg_data *curr_slot = host->plat->vreg_data; |
| 2200 | int rc = 0; |
| 2201 | |
| 2202 | if (curr_slot && curr_slot->vddp_data) { |
| 2203 | rc = msmsdcc_set_vddp_level(host, |
| 2204 | curr_slot->vddp_data->high_vol_level); |
| 2205 | |
| 2206 | if (rc) |
| 2207 | pr_err("%s: %s: failed to change vddp level to %d", |
| 2208 | mmc_hostname(host->mmc), __func__, |
| 2209 | curr_slot->vddp_data->high_vol_level); |
| 2210 | } |
| 2211 | |
| 2212 | return rc; |
| 2213 | } |
| 2214 | |
Subhash Jadavani | 56e0eaa | 2012-03-13 18:06:04 +0530 | [diff] [blame] | 2215 | static inline int msmsdcc_set_vccq_vol(struct msmsdcc_host *host, int level) |
| 2216 | { |
| 2217 | struct msm_mmc_slot_reg_data *curr_slot = host->plat->vreg_data; |
| 2218 | int rc = 0; |
| 2219 | |
| 2220 | if (curr_slot && curr_slot->vccq_data) { |
| 2221 | rc = msmsdcc_vreg_set_voltage(curr_slot->vccq_data, |
| 2222 | level, level); |
| 2223 | if (rc) |
| 2224 | pr_err("%s: %s: failed to change vccq level to %d", |
| 2225 | mmc_hostname(host->mmc), __func__, level); |
| 2226 | } |
| 2227 | |
| 2228 | return rc; |
| 2229 | } |
| 2230 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2231 | static inline int msmsdcc_is_pwrsave(struct msmsdcc_host *host) |
| 2232 | { |
| 2233 | if (host->clk_rate > 400000 && msmsdcc_pwrsave) |
| 2234 | return 1; |
| 2235 | return 0; |
| 2236 | } |
| 2237 | |
Asutosh Das | f5298c3 | 2012-04-03 14:51:47 +0530 | [diff] [blame] | 2238 | /* |
| 2239 | * Any function calling msmsdcc_setup_clocks must |
| 2240 | * acquire clk_mutex. May sleep. |
| 2241 | */ |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2242 | static inline void msmsdcc_setup_clocks(struct msmsdcc_host *host, bool enable) |
| 2243 | { |
| 2244 | if (enable) { |
| 2245 | if (!IS_ERR_OR_NULL(host->dfab_pclk)) |
Asutosh Das | f5298c3 | 2012-04-03 14:51:47 +0530 | [diff] [blame] | 2246 | clk_prepare_enable(host->dfab_pclk); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2247 | if (!IS_ERR(host->pclk)) |
Asutosh Das | f5298c3 | 2012-04-03 14:51:47 +0530 | [diff] [blame] | 2248 | clk_prepare_enable(host->pclk); |
| 2249 | clk_prepare_enable(host->clk); |
Subhash Jadavani | dd43295 | 2012-03-28 11:25:56 +0530 | [diff] [blame] | 2250 | mb(); |
Subhash Jadavani | 15f29db | 2011-10-13 09:57:13 +0530 | [diff] [blame] | 2251 | msmsdcc_delay(host); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2252 | } else { |
Subhash Jadavani | dd43295 | 2012-03-28 11:25:56 +0530 | [diff] [blame] | 2253 | mb(); |
Subhash Jadavani | 15f29db | 2011-10-13 09:57:13 +0530 | [diff] [blame] | 2254 | msmsdcc_delay(host); |
Asutosh Das | f5298c3 | 2012-04-03 14:51:47 +0530 | [diff] [blame] | 2255 | clk_disable_unprepare(host->clk); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2256 | if (!IS_ERR(host->pclk)) |
Asutosh Das | f5298c3 | 2012-04-03 14:51:47 +0530 | [diff] [blame] | 2257 | clk_disable_unprepare(host->pclk); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2258 | if (!IS_ERR_OR_NULL(host->dfab_pclk)) |
Asutosh Das | f5298c3 | 2012-04-03 14:51:47 +0530 | [diff] [blame] | 2259 | clk_disable_unprepare(host->dfab_pclk); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2260 | } |
| 2261 | } |
| 2262 | |
| 2263 | static inline unsigned int msmsdcc_get_sup_clk_rate(struct msmsdcc_host *host, |
| 2264 | unsigned int req_clk) |
| 2265 | { |
| 2266 | unsigned int sel_clk = -1; |
| 2267 | |
Subhash Jadavani | 327f4be | 2012-03-25 00:44:29 +0530 | [diff] [blame] | 2268 | if (req_clk < msmsdcc_get_min_sup_clk_rate(host)) { |
| 2269 | sel_clk = msmsdcc_get_min_sup_clk_rate(host); |
| 2270 | goto out; |
| 2271 | } |
| 2272 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2273 | if (host->plat->sup_clk_table && host->plat->sup_clk_cnt) { |
| 2274 | unsigned char cnt; |
| 2275 | |
| 2276 | for (cnt = 0; cnt < host->plat->sup_clk_cnt; cnt++) { |
| 2277 | if (host->plat->sup_clk_table[cnt] > req_clk) |
| 2278 | break; |
| 2279 | else if (host->plat->sup_clk_table[cnt] == req_clk) { |
| 2280 | sel_clk = host->plat->sup_clk_table[cnt]; |
| 2281 | break; |
| 2282 | } else |
| 2283 | sel_clk = host->plat->sup_clk_table[cnt]; |
| 2284 | } |
| 2285 | } else { |
| 2286 | if ((req_clk < host->plat->msmsdcc_fmax) && |
| 2287 | (req_clk > host->plat->msmsdcc_fmid)) |
| 2288 | sel_clk = host->plat->msmsdcc_fmid; |
| 2289 | else |
| 2290 | sel_clk = req_clk; |
| 2291 | } |
| 2292 | |
Subhash Jadavani | 327f4be | 2012-03-25 00:44:29 +0530 | [diff] [blame] | 2293 | out: |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2294 | return sel_clk; |
| 2295 | } |
| 2296 | |
| 2297 | static inline unsigned int msmsdcc_get_min_sup_clk_rate( |
| 2298 | struct msmsdcc_host *host) |
| 2299 | { |
| 2300 | if (host->plat->sup_clk_table && host->plat->sup_clk_cnt) |
| 2301 | return host->plat->sup_clk_table[0]; |
| 2302 | else |
| 2303 | return host->plat->msmsdcc_fmin; |
| 2304 | } |
| 2305 | |
| 2306 | static inline unsigned int msmsdcc_get_max_sup_clk_rate( |
| 2307 | struct msmsdcc_host *host) |
| 2308 | { |
| 2309 | if (host->plat->sup_clk_table && host->plat->sup_clk_cnt) |
| 2310 | return host->plat->sup_clk_table[host->plat->sup_clk_cnt - 1]; |
| 2311 | else |
| 2312 | return host->plat->msmsdcc_fmax; |
| 2313 | } |
| 2314 | |
| 2315 | static int msmsdcc_setup_gpio(struct msmsdcc_host *host, bool enable) |
Sahitya Tummala | 7a89248 | 2011-01-18 11:22:49 +0530 | [diff] [blame] | 2316 | { |
| 2317 | struct msm_mmc_gpio_data *curr; |
| 2318 | int i, rc = 0; |
| 2319 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2320 | curr = host->plat->pin_data->gpio_data; |
Sahitya Tummala | 7a89248 | 2011-01-18 11:22:49 +0530 | [diff] [blame] | 2321 | for (i = 0; i < curr->size; i++) { |
| 2322 | if (enable) { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2323 | if (curr->gpio[i].is_always_on && |
| 2324 | curr->gpio[i].is_enabled) |
| 2325 | continue; |
Sahitya Tummala | 7a89248 | 2011-01-18 11:22:49 +0530 | [diff] [blame] | 2326 | rc = gpio_request(curr->gpio[i].no, |
| 2327 | curr->gpio[i].name); |
| 2328 | if (rc) { |
| 2329 | pr_err("%s: gpio_request(%d, %s) failed %d\n", |
| 2330 | mmc_hostname(host->mmc), |
| 2331 | curr->gpio[i].no, |
| 2332 | curr->gpio[i].name, rc); |
| 2333 | goto free_gpios; |
| 2334 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2335 | curr->gpio[i].is_enabled = true; |
Sahitya Tummala | 7a89248 | 2011-01-18 11:22:49 +0530 | [diff] [blame] | 2336 | } else { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2337 | if (curr->gpio[i].is_always_on) |
| 2338 | continue; |
Sahitya Tummala | 7a89248 | 2011-01-18 11:22:49 +0530 | [diff] [blame] | 2339 | gpio_free(curr->gpio[i].no); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2340 | curr->gpio[i].is_enabled = false; |
Sahitya Tummala | 7a89248 | 2011-01-18 11:22:49 +0530 | [diff] [blame] | 2341 | } |
| 2342 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2343 | goto out; |
Sahitya Tummala | 7a89248 | 2011-01-18 11:22:49 +0530 | [diff] [blame] | 2344 | |
| 2345 | free_gpios: |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2346 | for (; i >= 0; i--) { |
Sahitya Tummala | 7a89248 | 2011-01-18 11:22:49 +0530 | [diff] [blame] | 2347 | gpio_free(curr->gpio[i].no); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2348 | curr->gpio[i].is_enabled = false; |
| 2349 | } |
| 2350 | out: |
| 2351 | return rc; |
| 2352 | } |
| 2353 | |
| 2354 | static int msmsdcc_setup_pad(struct msmsdcc_host *host, bool enable) |
| 2355 | { |
| 2356 | struct msm_mmc_pad_data *curr; |
| 2357 | int i; |
| 2358 | |
| 2359 | curr = host->plat->pin_data->pad_data; |
| 2360 | for (i = 0; i < curr->drv->size; i++) { |
| 2361 | if (enable) |
| 2362 | msm_tlmm_set_hdrive(curr->drv->on[i].no, |
| 2363 | curr->drv->on[i].val); |
| 2364 | else |
| 2365 | msm_tlmm_set_hdrive(curr->drv->off[i].no, |
| 2366 | curr->drv->off[i].val); |
| 2367 | } |
| 2368 | |
| 2369 | for (i = 0; i < curr->pull->size; i++) { |
| 2370 | if (enable) |
Krishna Konda | 6ad526f | 2011-09-22 22:07:27 -0700 | [diff] [blame] | 2371 | msm_tlmm_set_pull(curr->pull->on[i].no, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2372 | curr->pull->on[i].val); |
| 2373 | else |
Krishna Konda | 6ad526f | 2011-09-22 22:07:27 -0700 | [diff] [blame] | 2374 | msm_tlmm_set_pull(curr->pull->off[i].no, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2375 | curr->pull->off[i].val); |
| 2376 | } |
| 2377 | |
| 2378 | return 0; |
| 2379 | } |
| 2380 | |
| 2381 | static u32 msmsdcc_setup_pins(struct msmsdcc_host *host, bool enable) |
| 2382 | { |
| 2383 | int rc = 0; |
| 2384 | |
| 2385 | if (!host->plat->pin_data || host->plat->pin_data->cfg_sts == enable) |
| 2386 | return 0; |
| 2387 | |
| 2388 | if (host->plat->pin_data->is_gpio) |
| 2389 | rc = msmsdcc_setup_gpio(host, enable); |
| 2390 | else |
| 2391 | rc = msmsdcc_setup_pad(host, enable); |
| 2392 | |
| 2393 | if (!rc) |
| 2394 | host->plat->pin_data->cfg_sts = enable; |
| 2395 | |
| 2396 | return rc; |
| 2397 | } |
| 2398 | |
Subhash Jadavani | c9b8575 | 2012-04-13 11:16:49 +0530 | [diff] [blame^] | 2399 | static int msmsdcc_cfg_mpm_sdiowakeup(struct msmsdcc_host *host, |
| 2400 | unsigned mode) |
| 2401 | { |
| 2402 | int ret = 0; |
| 2403 | unsigned int pin = host->plat->mpm_sdiowakeup_int; |
| 2404 | |
| 2405 | if (!pin) |
| 2406 | return 0; |
| 2407 | |
| 2408 | switch (mode) { |
| 2409 | case SDC_DAT1_DISABLE: |
| 2410 | ret = msm_mpm_enable_pin(pin, 0); |
| 2411 | break; |
| 2412 | case SDC_DAT1_ENABLE: |
| 2413 | ret = msm_mpm_set_pin_type(pin, IRQ_TYPE_LEVEL_LOW); |
| 2414 | ret = msm_mpm_enable_pin(pin, 1); |
| 2415 | break; |
| 2416 | case SDC_DAT1_ENWAKE: |
| 2417 | ret = msm_mpm_set_pin_wake(pin, 1); |
| 2418 | break; |
| 2419 | case SDC_DAT1_DISWAKE: |
| 2420 | ret = msm_mpm_set_pin_wake(pin, 0); |
| 2421 | break; |
| 2422 | default: |
| 2423 | ret = -EINVAL; |
| 2424 | break; |
| 2425 | } |
| 2426 | |
| 2427 | return ret; |
| 2428 | } |
| 2429 | |
Sujit Reddy Thumma | f4a999c | 2012-02-09 23:14:45 +0530 | [diff] [blame] | 2430 | static u32 msmsdcc_setup_pwr(struct msmsdcc_host *host, struct mmc_ios *ios) |
| 2431 | { |
| 2432 | u32 pwr = 0; |
| 2433 | int ret = 0; |
| 2434 | struct mmc_host *mmc = host->mmc; |
| 2435 | |
| 2436 | if (host->plat->translate_vdd && !host->sdio_gpio_lpm) |
| 2437 | ret = host->plat->translate_vdd(mmc_dev(mmc), ios->vdd); |
| 2438 | else if (!host->plat->translate_vdd && !host->sdio_gpio_lpm) |
| 2439 | ret = msmsdcc_setup_vreg(host, !!ios->vdd); |
| 2440 | |
| 2441 | if (ret) { |
| 2442 | pr_err("%s: Failed to setup voltage regulators\n", |
| 2443 | mmc_hostname(host->mmc)); |
| 2444 | goto out; |
| 2445 | } |
| 2446 | |
| 2447 | switch (ios->power_mode) { |
| 2448 | case MMC_POWER_OFF: |
| 2449 | pwr = MCI_PWR_OFF; |
Subhash Jadavani | c9b8575 | 2012-04-13 11:16:49 +0530 | [diff] [blame^] | 2450 | msmsdcc_cfg_mpm_sdiowakeup(host, SDC_DAT1_DISABLE); |
Sujit Reddy Thumma | f4a999c | 2012-02-09 23:14:45 +0530 | [diff] [blame] | 2451 | /* |
| 2452 | * As VDD pad rail is always on, set low voltage for VDD |
| 2453 | * pad rail when slot is unused (when card is not present |
| 2454 | * or during system suspend). |
| 2455 | */ |
| 2456 | msmsdcc_set_vddp_low_vol(host); |
| 2457 | msmsdcc_setup_pins(host, false); |
| 2458 | break; |
| 2459 | case MMC_POWER_UP: |
| 2460 | /* writing PWR_UP bit is redundant */ |
| 2461 | pwr = MCI_PWR_UP; |
Subhash Jadavani | c9b8575 | 2012-04-13 11:16:49 +0530 | [diff] [blame^] | 2462 | msmsdcc_cfg_mpm_sdiowakeup(host, SDC_DAT1_ENABLE); |
Sujit Reddy Thumma | f4a999c | 2012-02-09 23:14:45 +0530 | [diff] [blame] | 2463 | |
| 2464 | msmsdcc_set_vddp_high_vol(host); |
| 2465 | msmsdcc_setup_pins(host, true); |
| 2466 | break; |
| 2467 | case MMC_POWER_ON: |
| 2468 | pwr = MCI_PWR_ON; |
| 2469 | break; |
| 2470 | } |
| 2471 | |
| 2472 | out: |
| 2473 | return pwr; |
| 2474 | } |
| 2475 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2476 | static void msmsdcc_enable_irq_wake(struct msmsdcc_host *host) |
| 2477 | { |
| 2478 | unsigned int wakeup_irq; |
| 2479 | |
| 2480 | wakeup_irq = (host->plat->sdiowakeup_irq) ? |
| 2481 | host->plat->sdiowakeup_irq : |
| 2482 | host->core_irqres->start; |
| 2483 | |
| 2484 | if (!host->irq_wake_enabled) { |
| 2485 | enable_irq_wake(wakeup_irq); |
| 2486 | host->irq_wake_enabled = true; |
| 2487 | } |
| 2488 | } |
| 2489 | |
| 2490 | static void msmsdcc_disable_irq_wake(struct msmsdcc_host *host) |
| 2491 | { |
| 2492 | unsigned int wakeup_irq; |
| 2493 | |
| 2494 | wakeup_irq = (host->plat->sdiowakeup_irq) ? |
| 2495 | host->plat->sdiowakeup_irq : |
| 2496 | host->core_irqres->start; |
| 2497 | |
| 2498 | if (host->irq_wake_enabled) { |
| 2499 | disable_irq_wake(wakeup_irq); |
| 2500 | host->irq_wake_enabled = false; |
| 2501 | } |
Sahitya Tummala | 7a89248 | 2011-01-18 11:22:49 +0530 | [diff] [blame] | 2502 | } |
| 2503 | |
San Mehat | 9d2bd73 | 2009-09-22 16:44:22 -0700 | [diff] [blame] | 2504 | static void |
Sujit Reddy Thumma | f4a999c | 2012-02-09 23:14:45 +0530 | [diff] [blame] | 2505 | msmsdcc_cfg_sdio_wakeup(struct msmsdcc_host *host, bool enable_wakeup_irq) |
| 2506 | { |
| 2507 | struct mmc_host *mmc = host->mmc; |
| 2508 | |
| 2509 | /* |
| 2510 | * SDIO_AL clients has different mechanism of handling LPM through |
| 2511 | * sdio_al driver itself. The sdio wakeup interrupt is configured as |
| 2512 | * part of that. Here, we are interested only in clients like WLAN. |
| 2513 | */ |
| 2514 | if (!(mmc->card && mmc_card_sdio(mmc->card)) |
| 2515 | || host->plat->is_sdio_al_client) |
| 2516 | goto out; |
| 2517 | |
| 2518 | if (!host->sdcc_suspended) { |
| 2519 | /* |
| 2520 | * When MSM is not in power collapse and we |
| 2521 | * are disabling clocks, enable bit 22 in MASK0 |
| 2522 | * to handle asynchronous SDIO interrupts. |
| 2523 | */ |
Subhash Jadavani | dd43295 | 2012-03-28 11:25:56 +0530 | [diff] [blame] | 2524 | if (enable_wakeup_irq) { |
Sujit Reddy Thumma | f4a999c | 2012-02-09 23:14:45 +0530 | [diff] [blame] | 2525 | writel_relaxed(MCI_SDIOINTMASK, host->base + MMCIMASK0); |
Subhash Jadavani | dd43295 | 2012-03-28 11:25:56 +0530 | [diff] [blame] | 2526 | mb(); |
| 2527 | } else { |
Sujit Reddy Thumma | f4a999c | 2012-02-09 23:14:45 +0530 | [diff] [blame] | 2528 | writel_relaxed(MCI_SDIOINTMASK, host->base + MMCICLEAR); |
Subhash Jadavani | dd43295 | 2012-03-28 11:25:56 +0530 | [diff] [blame] | 2529 | msmsdcc_sync_reg_wr(host); |
| 2530 | } |
Sujit Reddy Thumma | f4a999c | 2012-02-09 23:14:45 +0530 | [diff] [blame] | 2531 | goto out; |
| 2532 | } else if (!mmc_card_wake_sdio_irq(mmc)) { |
| 2533 | /* |
| 2534 | * Wakeup MSM only if SDIO function drivers set |
| 2535 | * MMC_PM_WAKE_SDIO_IRQ flag in their suspend call. |
| 2536 | */ |
| 2537 | goto out; |
| 2538 | } |
| 2539 | |
| 2540 | if (enable_wakeup_irq) { |
| 2541 | if (!host->plat->sdiowakeup_irq) { |
| 2542 | /* |
| 2543 | * When there is no gpio line that can be configured |
| 2544 | * as wakeup interrupt handle it by configuring |
| 2545 | * asynchronous sdio interrupts and DAT1 line. |
| 2546 | */ |
| 2547 | writel_relaxed(MCI_SDIOINTMASK, |
| 2548 | host->base + MMCIMASK0); |
| 2549 | mb(); |
Subhash Jadavani | c9b8575 | 2012-04-13 11:16:49 +0530 | [diff] [blame^] | 2550 | msmsdcc_cfg_mpm_sdiowakeup(host, SDC_DAT1_ENWAKE); |
Sujit Reddy Thumma | f4a999c | 2012-02-09 23:14:45 +0530 | [diff] [blame] | 2551 | /* configure sdcc core interrupt as wakeup interrupt */ |
| 2552 | msmsdcc_enable_irq_wake(host); |
| 2553 | } else { |
| 2554 | /* Let gpio line handle wakeup interrupt */ |
| 2555 | writel_relaxed(0, host->base + MMCIMASK0); |
| 2556 | mb(); |
| 2557 | if (host->sdio_wakeupirq_disabled) { |
| 2558 | host->sdio_wakeupirq_disabled = 0; |
| 2559 | /* configure gpio line as wakeup interrupt */ |
| 2560 | msmsdcc_enable_irq_wake(host); |
| 2561 | enable_irq(host->plat->sdiowakeup_irq); |
| 2562 | } |
| 2563 | } |
| 2564 | } else { |
| 2565 | if (!host->plat->sdiowakeup_irq) { |
| 2566 | /* |
| 2567 | * We may not have cleared bit 22 in the interrupt |
| 2568 | * handler as the clocks might be off at that time. |
| 2569 | */ |
| 2570 | writel_relaxed(MCI_SDIOINTMASK, host->base + MMCICLEAR); |
Subhash Jadavani | dd43295 | 2012-03-28 11:25:56 +0530 | [diff] [blame] | 2571 | msmsdcc_sync_reg_wr(host); |
Subhash Jadavani | c9b8575 | 2012-04-13 11:16:49 +0530 | [diff] [blame^] | 2572 | msmsdcc_cfg_mpm_sdiowakeup(host, SDC_DAT1_DISWAKE); |
Sujit Reddy Thumma | f4a999c | 2012-02-09 23:14:45 +0530 | [diff] [blame] | 2573 | msmsdcc_disable_irq_wake(host); |
| 2574 | } else if (!host->sdio_wakeupirq_disabled) { |
| 2575 | disable_irq_nosync(host->plat->sdiowakeup_irq); |
| 2576 | msmsdcc_disable_irq_wake(host); |
| 2577 | host->sdio_wakeupirq_disabled = 1; |
| 2578 | } |
| 2579 | } |
| 2580 | out: |
| 2581 | return; |
| 2582 | } |
| 2583 | |
| 2584 | static void |
San Mehat | 9d2bd73 | 2009-09-22 16:44:22 -0700 | [diff] [blame] | 2585 | msmsdcc_set_ios(struct mmc_host *mmc, struct mmc_ios *ios) |
| 2586 | { |
| 2587 | struct msmsdcc_host *host = mmc_priv(mmc); |
| 2588 | u32 clk = 0, pwr = 0; |
| 2589 | int rc; |
San Mehat | 4adbbcc | 2009-11-08 13:00:37 -0800 | [diff] [blame] | 2590 | unsigned long flags; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2591 | unsigned int clock; |
San Mehat | 9d2bd73 | 2009-09-22 16:44:22 -0700 | [diff] [blame] | 2592 | |
Sahitya Tummala | 7a89248 | 2011-01-18 11:22:49 +0530 | [diff] [blame] | 2593 | |
Sujit Reddy Thumma | f4a999c | 2012-02-09 23:14:45 +0530 | [diff] [blame] | 2594 | /* |
| 2595 | * Disable SDCC core interrupt until set_ios is completed. |
| 2596 | * This avoids any race conditions with interrupt raised |
| 2597 | * when turning on/off the clocks. One possible |
| 2598 | * scenario is SDIO operational interrupt while the clock |
| 2599 | * is turned off. |
Asutosh Das | f5298c3 | 2012-04-03 14:51:47 +0530 | [diff] [blame] | 2600 | * host->lock is being released intermittently below. |
| 2601 | * Thus, prevent concurrent access to host. |
Sujit Reddy Thumma | f4a999c | 2012-02-09 23:14:45 +0530 | [diff] [blame] | 2602 | */ |
| 2603 | |
Asutosh Das | f5298c3 | 2012-04-03 14:51:47 +0530 | [diff] [blame] | 2604 | mutex_lock(&host->clk_mutex); |
| 2605 | DBG(host, "ios->clock = %u\n", ios->clock); |
Sujit Reddy Thumma | f4a999c | 2012-02-09 23:14:45 +0530 | [diff] [blame] | 2606 | spin_lock_irqsave(&host->lock, flags); |
| 2607 | if (!host->sdcc_irq_disabled) { |
| 2608 | spin_unlock_irqrestore(&host->lock, flags); |
| 2609 | disable_irq(host->core_irqres->start); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2610 | spin_lock_irqsave(&host->lock, flags); |
Sujit Reddy Thumma | f4a999c | 2012-02-09 23:14:45 +0530 | [diff] [blame] | 2611 | host->sdcc_irq_disabled = 1; |
| 2612 | } |
| 2613 | spin_unlock_irqrestore(&host->lock, flags); |
| 2614 | |
| 2615 | pwr = msmsdcc_setup_pwr(host, ios); |
| 2616 | |
| 2617 | spin_lock_irqsave(&host->lock, flags); |
| 2618 | if (ios->clock) { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2619 | if (!host->clks_on) { |
Asutosh Das | f5298c3 | 2012-04-03 14:51:47 +0530 | [diff] [blame] | 2620 | spin_unlock_irqrestore(&host->lock, flags); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2621 | msmsdcc_setup_clocks(host, true); |
Asutosh Das | f5298c3 | 2012-04-03 14:51:47 +0530 | [diff] [blame] | 2622 | spin_lock_irqsave(&host->lock, flags); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2623 | host->clks_on = 1; |
Sujit Reddy Thumma | f4a999c | 2012-02-09 23:14:45 +0530 | [diff] [blame] | 2624 | writel_relaxed(host->mci_irqenable, |
| 2625 | host->base + MMCIMASK0); |
| 2626 | mb(); |
| 2627 | msmsdcc_cfg_sdio_wakeup(host, false); |
San Mehat | 9d2bd73 | 2009-09-22 16:44:22 -0700 | [diff] [blame] | 2628 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2629 | |
| 2630 | clock = msmsdcc_get_sup_clk_rate(host, ios->clock); |
| 2631 | /* |
| 2632 | * For DDR50 mode, controller needs clock rate to be |
| 2633 | * double than what is required on the SD card CLK pin. |
| 2634 | */ |
Subhash Jadavani | 0e027b7 | 2011-08-30 17:40:55 +0530 | [diff] [blame] | 2635 | if (ios->timing == MMC_TIMING_UHS_DDR50) { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2636 | /* |
| 2637 | * Make sure that we don't double the clock if |
| 2638 | * doubled clock rate is already set |
| 2639 | */ |
| 2640 | if (!host->ddr_doubled_clk_rate || |
| 2641 | (host->ddr_doubled_clk_rate && |
| 2642 | (host->ddr_doubled_clk_rate != ios->clock))) { |
| 2643 | host->ddr_doubled_clk_rate = |
| 2644 | msmsdcc_get_sup_clk_rate( |
| 2645 | host, (ios->clock * 2)); |
| 2646 | clock = host->ddr_doubled_clk_rate; |
| 2647 | } |
| 2648 | } else { |
| 2649 | host->ddr_doubled_clk_rate = 0; |
| 2650 | } |
| 2651 | |
| 2652 | if (clock != host->clk_rate) { |
Asutosh Das | f5298c3 | 2012-04-03 14:51:47 +0530 | [diff] [blame] | 2653 | spin_unlock_irqrestore(&host->lock, flags); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2654 | rc = clk_set_rate(host->clk, clock); |
Asutosh Das | f5298c3 | 2012-04-03 14:51:47 +0530 | [diff] [blame] | 2655 | spin_lock_irqsave(&host->lock, flags); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2656 | if (rc < 0) |
Subhash Jadavani | b52b4d7 | 2011-12-05 19:16:28 +0530 | [diff] [blame] | 2657 | pr_err("%s: failed to set clk rate %u\n", |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2658 | mmc_hostname(mmc), clock); |
| 2659 | host->clk_rate = clock; |
Sujith Reddy Thumma | c1824d5 | 2011-09-28 10:05:44 +0530 | [diff] [blame] | 2660 | host->reg_write_delay = |
| 2661 | (1 + ((3 * USEC_PER_SEC) / |
| 2662 | (host->clk_rate ? host->clk_rate : |
| 2663 | msmsdcc_get_min_sup_clk_rate(host)))); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2664 | } |
| 2665 | /* |
| 2666 | * give atleast 2 MCLK cycles delay for clocks |
| 2667 | * and SDCC core to stabilize |
| 2668 | */ |
Subhash Jadavani | dd43295 | 2012-03-28 11:25:56 +0530 | [diff] [blame] | 2669 | mb(); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2670 | msmsdcc_delay(host); |
San Mehat | 9d2bd73 | 2009-09-22 16:44:22 -0700 | [diff] [blame] | 2671 | clk |= MCI_CLK_ENABLE; |
| 2672 | } |
| 2673 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2674 | if (ios->bus_width == MMC_BUS_WIDTH_8) |
| 2675 | clk |= MCI_CLK_WIDEBUS_8; |
| 2676 | else if (ios->bus_width == MMC_BUS_WIDTH_4) |
| 2677 | clk |= MCI_CLK_WIDEBUS_4; |
| 2678 | else |
| 2679 | clk |= MCI_CLK_WIDEBUS_1; |
San Mehat | 9d2bd73 | 2009-09-22 16:44:22 -0700 | [diff] [blame] | 2680 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2681 | if (msmsdcc_is_pwrsave(host)) |
| 2682 | clk |= MCI_CLK_PWRSAVE; |
San Mehat | 9d2bd73 | 2009-09-22 16:44:22 -0700 | [diff] [blame] | 2683 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2684 | clk |= MCI_CLK_FLOWENA; |
San Mehat | 9d2bd73 | 2009-09-22 16:44:22 -0700 | [diff] [blame] | 2685 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2686 | host->tuning_needed = 0; |
| 2687 | /* |
| 2688 | * Select the controller timing mode according |
| 2689 | * to current bus speed mode |
| 2690 | */ |
Subhash Jadavani | 56e0eaa | 2012-03-13 18:06:04 +0530 | [diff] [blame] | 2691 | if ((ios->timing == MMC_TIMING_UHS_SDR104) || |
| 2692 | (ios->timing == MMC_TIMING_MMC_HS200)) { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2693 | clk |= (4 << 14); |
| 2694 | host->tuning_needed = 1; |
Subhash Jadavani | 0e027b7 | 2011-08-30 17:40:55 +0530 | [diff] [blame] | 2695 | } else if (ios->timing == MMC_TIMING_UHS_DDR50) { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2696 | clk |= (3 << 14); |
| 2697 | } else { |
| 2698 | clk |= (2 << 14); /* feedback clock */ |
| 2699 | } |
| 2700 | |
| 2701 | /* Select free running MCLK as input clock of cm_dll_sdc4 */ |
| 2702 | clk |= (2 << 23); |
| 2703 | |
Subhash Jadavani | 0008357 | 2012-02-15 16:18:01 +0530 | [diff] [blame] | 2704 | /* Clear IO_PAD_PWR_SWITCH while powering off the card */ |
| 2705 | if (!ios->vdd) |
| 2706 | host->io_pad_pwr_switch = 0; |
| 2707 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2708 | if (host->io_pad_pwr_switch) |
| 2709 | clk |= IO_PAD_PWR_SWITCH; |
| 2710 | |
Sujit Reddy Thumma | f4a999c | 2012-02-09 23:14:45 +0530 | [diff] [blame] | 2711 | /* Don't write into registers if clocks are disabled */ |
| 2712 | if (host->clks_on) { |
| 2713 | if (readl_relaxed(host->base + MMCICLOCK) != clk) { |
| 2714 | writel_relaxed(clk, host->base + MMCICLOCK); |
Subhash Jadavani | dd43295 | 2012-03-28 11:25:56 +0530 | [diff] [blame] | 2715 | msmsdcc_sync_reg_wr(host); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2716 | } |
Sujit Reddy Thumma | f4a999c | 2012-02-09 23:14:45 +0530 | [diff] [blame] | 2717 | if (readl_relaxed(host->base + MMCIPOWER) != pwr) { |
| 2718 | host->pwr = pwr; |
| 2719 | writel_relaxed(pwr, host->base + MMCIPOWER); |
Subhash Jadavani | dd43295 | 2012-03-28 11:25:56 +0530 | [diff] [blame] | 2720 | msmsdcc_sync_reg_wr(host); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2721 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2722 | } |
| 2723 | |
| 2724 | if (!(clk & MCI_CLK_ENABLE) && host->clks_on) { |
Sujit Reddy Thumma | f4a999c | 2012-02-09 23:14:45 +0530 | [diff] [blame] | 2725 | msmsdcc_cfg_sdio_wakeup(host, true); |
Asutosh Das | f5298c3 | 2012-04-03 14:51:47 +0530 | [diff] [blame] | 2726 | spin_unlock_irqrestore(&host->lock, flags); |
| 2727 | /* |
| 2728 | * May get a wake-up interrupt the instant we disable the |
| 2729 | * clocks. This would disable the wake-up interrupt. |
| 2730 | */ |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2731 | msmsdcc_setup_clocks(host, false); |
Asutosh Das | f5298c3 | 2012-04-03 14:51:47 +0530 | [diff] [blame] | 2732 | spin_lock_irqsave(&host->lock, flags); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2733 | host->clks_on = 0; |
| 2734 | } |
Subhash Jadavani | b52b4d7 | 2011-12-05 19:16:28 +0530 | [diff] [blame] | 2735 | |
Subhash Jadavani | 56e0eaa | 2012-03-13 18:06:04 +0530 | [diff] [blame] | 2736 | if (host->tuning_in_progress) |
Subhash Jadavani | b52b4d7 | 2011-12-05 19:16:28 +0530 | [diff] [blame] | 2737 | WARN(!host->clks_on, |
Subhash Jadavani | 56e0eaa | 2012-03-13 18:06:04 +0530 | [diff] [blame] | 2738 | "tuning_in_progress but SDCC clocks are OFF\n"); |
Subhash Jadavani | b52b4d7 | 2011-12-05 19:16:28 +0530 | [diff] [blame] | 2739 | |
Sujit Reddy Thumma | f4a999c | 2012-02-09 23:14:45 +0530 | [diff] [blame] | 2740 | /* Let interrupts be disabled if the host is powered off */ |
| 2741 | if (ios->power_mode != MMC_POWER_OFF && host->sdcc_irq_disabled) { |
| 2742 | enable_irq(host->core_irqres->start); |
| 2743 | host->sdcc_irq_disabled = 0; |
| 2744 | } |
| 2745 | |
San Mehat | 4adbbcc | 2009-11-08 13:00:37 -0800 | [diff] [blame] | 2746 | spin_unlock_irqrestore(&host->lock, flags); |
Asutosh Das | f5298c3 | 2012-04-03 14:51:47 +0530 | [diff] [blame] | 2747 | mutex_unlock(&host->clk_mutex); |
San Mehat | 9d2bd73 | 2009-09-22 16:44:22 -0700 | [diff] [blame] | 2748 | } |
| 2749 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2750 | int msmsdcc_set_pwrsave(struct mmc_host *mmc, int pwrsave) |
| 2751 | { |
| 2752 | struct msmsdcc_host *host = mmc_priv(mmc); |
| 2753 | u32 clk; |
| 2754 | |
| 2755 | clk = readl_relaxed(host->base + MMCICLOCK); |
| 2756 | pr_debug("Changing to pwr_save=%d", pwrsave); |
| 2757 | if (pwrsave && msmsdcc_is_pwrsave(host)) |
| 2758 | clk |= MCI_CLK_PWRSAVE; |
| 2759 | else |
| 2760 | clk &= ~MCI_CLK_PWRSAVE; |
| 2761 | writel_relaxed(clk, host->base + MMCICLOCK); |
Subhash Jadavani | dd43295 | 2012-03-28 11:25:56 +0530 | [diff] [blame] | 2762 | msmsdcc_sync_reg_wr(host); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2763 | |
| 2764 | return 0; |
| 2765 | } |
| 2766 | |
| 2767 | static int msmsdcc_get_ro(struct mmc_host *mmc) |
| 2768 | { |
| 2769 | int status = -ENOSYS; |
| 2770 | struct msmsdcc_host *host = mmc_priv(mmc); |
| 2771 | |
| 2772 | if (host->plat->wpswitch) { |
| 2773 | status = host->plat->wpswitch(mmc_dev(mmc)); |
| 2774 | } else if (host->plat->wpswitch_gpio) { |
| 2775 | status = gpio_request(host->plat->wpswitch_gpio, |
| 2776 | "SD_WP_Switch"); |
| 2777 | if (status) { |
| 2778 | pr_err("%s: %s: Failed to request GPIO %d\n", |
| 2779 | mmc_hostname(mmc), __func__, |
| 2780 | host->plat->wpswitch_gpio); |
| 2781 | } else { |
| 2782 | status = gpio_direction_input( |
| 2783 | host->plat->wpswitch_gpio); |
| 2784 | if (!status) { |
| 2785 | /* |
| 2786 | * Wait for atleast 300ms as debounce |
| 2787 | * time for GPIO input to stabilize. |
| 2788 | */ |
| 2789 | msleep(300); |
| 2790 | status = gpio_get_value_cansleep( |
| 2791 | host->plat->wpswitch_gpio); |
| 2792 | status ^= !host->plat->wpswitch_polarity; |
| 2793 | } |
| 2794 | gpio_free(host->plat->wpswitch_gpio); |
| 2795 | } |
| 2796 | } |
| 2797 | |
| 2798 | if (status < 0) |
| 2799 | status = -ENOSYS; |
| 2800 | pr_debug("%s: Card read-only status %d\n", __func__, status); |
| 2801 | |
| 2802 | return status; |
| 2803 | } |
| 2804 | |
San Mehat | 9d2bd73 | 2009-09-22 16:44:22 -0700 | [diff] [blame] | 2805 | static void msmsdcc_enable_sdio_irq(struct mmc_host *mmc, int enable) |
| 2806 | { |
| 2807 | struct msmsdcc_host *host = mmc_priv(mmc); |
| 2808 | unsigned long flags; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2809 | |
Sujit Reddy Thumma | f4a999c | 2012-02-09 23:14:45 +0530 | [diff] [blame] | 2810 | /* |
| 2811 | * We may come here with clocks turned off in that case don't |
| 2812 | * attempt to write into MASK0 register. While turning on the |
| 2813 | * clocks mci_irqenable will be written to MASK0 register. |
| 2814 | */ |
| 2815 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2816 | if (enable) { |
| 2817 | spin_lock_irqsave(&host->lock, flags); |
| 2818 | host->mci_irqenable |= MCI_SDIOINTOPERMASK; |
Sujit Reddy Thumma | f4a999c | 2012-02-09 23:14:45 +0530 | [diff] [blame] | 2819 | if (host->clks_on) { |
| 2820 | writel_relaxed(readl_relaxed(host->base + MMCIMASK0) | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2821 | MCI_SDIOINTOPERMASK, host->base + MMCIMASK0); |
Sujit Reddy Thumma | f4a999c | 2012-02-09 23:14:45 +0530 | [diff] [blame] | 2822 | mb(); |
| 2823 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2824 | spin_unlock_irqrestore(&host->lock, flags); |
| 2825 | } else { |
| 2826 | host->mci_irqenable &= ~MCI_SDIOINTOPERMASK; |
Sujit Reddy Thumma | f4a999c | 2012-02-09 23:14:45 +0530 | [diff] [blame] | 2827 | if (host->clks_on) { |
| 2828 | writel_relaxed(readl_relaxed(host->base + MMCIMASK0) & |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2829 | ~MCI_SDIOINTOPERMASK, host->base + MMCIMASK0); |
Sujit Reddy Thumma | f4a999c | 2012-02-09 23:14:45 +0530 | [diff] [blame] | 2830 | mb(); |
| 2831 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2832 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2833 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2834 | |
| 2835 | #ifdef CONFIG_PM_RUNTIME |
| 2836 | static int msmsdcc_enable(struct mmc_host *mmc) |
| 2837 | { |
Sahitya Tummala | efa6af8 | 2011-09-07 14:46:30 +0530 | [diff] [blame] | 2838 | int rc; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2839 | struct device *dev = mmc->parent; |
Subhash Jadavani | 933e6a6 | 2011-12-26 18:05:04 +0530 | [diff] [blame] | 2840 | struct msmsdcc_host *host = mmc_priv(mmc); |
| 2841 | |
| 2842 | msmsdcc_pm_qos_update_latency(host, 1); |
| 2843 | |
| 2844 | if (mmc->card && mmc_card_sdio(mmc->card) && host->is_resumed) |
| 2845 | return 0; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2846 | |
Sahitya Tummala | efa6af8 | 2011-09-07 14:46:30 +0530 | [diff] [blame] | 2847 | if (dev->power.runtime_status == RPM_SUSPENDING) { |
| 2848 | if (mmc->suspend_task == current) { |
| 2849 | pm_runtime_get_noresume(dev); |
| 2850 | goto out; |
| 2851 | } |
| 2852 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2853 | |
Sahitya Tummala | efa6af8 | 2011-09-07 14:46:30 +0530 | [diff] [blame] | 2854 | rc = pm_runtime_get_sync(dev); |
| 2855 | |
| 2856 | if (rc < 0) { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2857 | pr_info("%s: %s: failed with error %d", mmc_hostname(mmc), |
| 2858 | __func__, rc); |
Sahitya Tummala | efa6af8 | 2011-09-07 14:46:30 +0530 | [diff] [blame] | 2859 | return rc; |
| 2860 | } |
Subhash Jadavani | 933e6a6 | 2011-12-26 18:05:04 +0530 | [diff] [blame] | 2861 | |
| 2862 | host->is_resumed = true; |
Sahitya Tummala | efa6af8 | 2011-09-07 14:46:30 +0530 | [diff] [blame] | 2863 | out: |
| 2864 | return 0; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2865 | } |
| 2866 | |
| 2867 | static int msmsdcc_disable(struct mmc_host *mmc, int lazy) |
| 2868 | { |
| 2869 | int rc; |
Sahitya Tummala | b07e1ae | 2011-09-02 11:58:42 +0530 | [diff] [blame] | 2870 | struct msmsdcc_host *host = mmc_priv(mmc); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2871 | |
Subhash Jadavani | 933e6a6 | 2011-12-26 18:05:04 +0530 | [diff] [blame] | 2872 | msmsdcc_pm_qos_update_latency(host, 0); |
| 2873 | |
| 2874 | if (mmc->card && mmc_card_sdio(mmc->card)) |
| 2875 | return 0; |
| 2876 | |
Sahitya Tummala | b07e1ae | 2011-09-02 11:58:42 +0530 | [diff] [blame] | 2877 | if (host->plat->disable_runtime_pm) |
| 2878 | return -ENOTSUPP; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2879 | |
| 2880 | rc = pm_runtime_put_sync(mmc->parent); |
| 2881 | |
| 2882 | if (rc < 0) |
| 2883 | pr_info("%s: %s: failed with error %d", mmc_hostname(mmc), |
| 2884 | __func__, rc); |
Subhash Jadavani | 933e6a6 | 2011-12-26 18:05:04 +0530 | [diff] [blame] | 2885 | else |
| 2886 | host->is_resumed = false; |
| 2887 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2888 | return rc; |
| 2889 | } |
| 2890 | #else |
Sujit Reddy Thumma | 5000d2a | 2011-11-17 12:09:04 +0530 | [diff] [blame] | 2891 | static int msmsdcc_enable(struct mmc_host *mmc) |
| 2892 | { |
| 2893 | struct msmsdcc_host *host = mmc_priv(mmc); |
| 2894 | unsigned long flags; |
| 2895 | |
Subhash Jadavani | 933e6a6 | 2011-12-26 18:05:04 +0530 | [diff] [blame] | 2896 | msmsdcc_pm_qos_update_latency(host, 1); |
| 2897 | |
Asutosh Das | f5298c3 | 2012-04-03 14:51:47 +0530 | [diff] [blame] | 2898 | mutex_lock(&host->clk_mutex); |
Sujit Reddy Thumma | 5000d2a | 2011-11-17 12:09:04 +0530 | [diff] [blame] | 2899 | spin_lock_irqsave(&host->lock, flags); |
| 2900 | if (!host->clks_on) { |
Asutosh Das | f5298c3 | 2012-04-03 14:51:47 +0530 | [diff] [blame] | 2901 | spin_unlock_irqrestore(&host->lock, flags); |
Sujit Reddy Thumma | 5000d2a | 2011-11-17 12:09:04 +0530 | [diff] [blame] | 2902 | msmsdcc_setup_clocks(host, true); |
Asutosh Das | f5298c3 | 2012-04-03 14:51:47 +0530 | [diff] [blame] | 2903 | spin_lock_irqsave(&host->lock, flags); |
Sujit Reddy Thumma | 5000d2a | 2011-11-17 12:09:04 +0530 | [diff] [blame] | 2904 | host->clks_on = 1; |
| 2905 | } |
| 2906 | spin_unlock_irqrestore(&host->lock, flags); |
Asutosh Das | f5298c3 | 2012-04-03 14:51:47 +0530 | [diff] [blame] | 2907 | mutex_unlock(&host->clk_mutex); |
Sujit Reddy Thumma | 5000d2a | 2011-11-17 12:09:04 +0530 | [diff] [blame] | 2908 | |
| 2909 | return 0; |
| 2910 | } |
| 2911 | |
| 2912 | static int msmsdcc_disable(struct mmc_host *mmc, int lazy) |
| 2913 | { |
| 2914 | struct msmsdcc_host *host = mmc_priv(mmc); |
| 2915 | unsigned long flags; |
| 2916 | |
Subhash Jadavani | 933e6a6 | 2011-12-26 18:05:04 +0530 | [diff] [blame] | 2917 | msmsdcc_pm_qos_update_latency(host, 0); |
| 2918 | |
Sujit Reddy Thumma | 5000d2a | 2011-11-17 12:09:04 +0530 | [diff] [blame] | 2919 | if (mmc->card && mmc_card_sdio(mmc->card)) |
Subhash Jadavani | 933e6a6 | 2011-12-26 18:05:04 +0530 | [diff] [blame] | 2920 | return 0; |
Sujit Reddy Thumma | 5000d2a | 2011-11-17 12:09:04 +0530 | [diff] [blame] | 2921 | |
Asutosh Das | f5298c3 | 2012-04-03 14:51:47 +0530 | [diff] [blame] | 2922 | mutex_lock(&host->clk_mutex); |
Sujit Reddy Thumma | 5000d2a | 2011-11-17 12:09:04 +0530 | [diff] [blame] | 2923 | spin_lock_irqsave(&host->lock, flags); |
| 2924 | if (host->clks_on) { |
Asutosh Das | f5298c3 | 2012-04-03 14:51:47 +0530 | [diff] [blame] | 2925 | spin_unlock_irqrestore(&host->lock, flags); |
Sujit Reddy Thumma | 5000d2a | 2011-11-17 12:09:04 +0530 | [diff] [blame] | 2926 | msmsdcc_setup_clocks(host, false); |
Asutosh Das | f5298c3 | 2012-04-03 14:51:47 +0530 | [diff] [blame] | 2927 | spin_lock_irqsave(&host->lock, flags); |
Sujit Reddy Thumma | 5000d2a | 2011-11-17 12:09:04 +0530 | [diff] [blame] | 2928 | host->clks_on = 0; |
| 2929 | } |
| 2930 | spin_unlock_irqrestore(&host->lock, flags); |
Asutosh Das | f5298c3 | 2012-04-03 14:51:47 +0530 | [diff] [blame] | 2931 | mutex_unlock(&host->clk_mutex); |
Sujit Reddy Thumma | 5000d2a | 2011-11-17 12:09:04 +0530 | [diff] [blame] | 2932 | |
| 2933 | return 0; |
| 2934 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2935 | #endif |
| 2936 | |
| 2937 | static int msmsdcc_start_signal_voltage_switch(struct mmc_host *mmc, |
| 2938 | struct mmc_ios *ios) |
| 2939 | { |
| 2940 | struct msmsdcc_host *host = mmc_priv(mmc); |
| 2941 | unsigned long flags; |
Subhash Jadavani | 99ba53a | 2011-08-01 16:04:18 +0530 | [diff] [blame] | 2942 | int rc = 0; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2943 | |
Subhash Jadavani | 0008357 | 2012-02-15 16:18:01 +0530 | [diff] [blame] | 2944 | spin_lock_irqsave(&host->lock, flags); |
| 2945 | host->io_pad_pwr_switch = 0; |
| 2946 | spin_unlock_irqrestore(&host->lock, flags); |
| 2947 | |
Subhash Jadavani | 56e0eaa | 2012-03-13 18:06:04 +0530 | [diff] [blame] | 2948 | /* |
| 2949 | * For eMMC cards, VccQ voltage range must be changed |
| 2950 | * only if it operates in HS200 SDR 1.2V mode or in |
| 2951 | * DDR 1.2V mode. |
| 2952 | */ |
| 2953 | if (ios->signal_voltage == MMC_SIGNAL_VOLTAGE_120) { |
| 2954 | rc = msmsdcc_set_vccq_vol(host, 1200000); |
| 2955 | goto out; |
| 2956 | } |
| 2957 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2958 | if (ios->signal_voltage == MMC_SIGNAL_VOLTAGE_330) { |
| 2959 | /* Change voltage level of VDDPX to high voltage */ |
Subhash Jadavani | 99ba53a | 2011-08-01 16:04:18 +0530 | [diff] [blame] | 2960 | rc = msmsdcc_set_vddp_high_vol(host); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2961 | goto out; |
| 2962 | } else if (ios->signal_voltage != MMC_SIGNAL_VOLTAGE_180) { |
| 2963 | /* invalid selection. don't do anything */ |
Subhash Jadavani | 99ba53a | 2011-08-01 16:04:18 +0530 | [diff] [blame] | 2964 | rc = -EINVAL; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2965 | goto out; |
| 2966 | } |
San Mehat | 9d2bd73 | 2009-09-22 16:44:22 -0700 | [diff] [blame] | 2967 | |
| 2968 | spin_lock_irqsave(&host->lock, flags); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2969 | /* |
| 2970 | * If we are here means voltage switch from high voltage to |
| 2971 | * low voltage is required |
| 2972 | */ |
| 2973 | |
| 2974 | /* |
| 2975 | * Poll on MCIDATIN_3_0 and MCICMDIN bits of MCI_TEST_INPUT |
| 2976 | * register until they become all zeros. |
| 2977 | */ |
| 2978 | if (readl_relaxed(host->base + MCI_TEST_INPUT) & (0xF << 1)) { |
Subhash Jadavani | 99ba53a | 2011-08-01 16:04:18 +0530 | [diff] [blame] | 2979 | rc = -EAGAIN; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2980 | pr_err("%s: %s: MCIDATIN_3_0 is still not all zeros", |
| 2981 | mmc_hostname(mmc), __func__); |
| 2982 | goto out_unlock; |
San Mehat | 9d2bd73 | 2009-09-22 16:44:22 -0700 | [diff] [blame] | 2983 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2984 | |
| 2985 | /* Stop SD CLK output. */ |
| 2986 | writel_relaxed((readl_relaxed(host->base + MMCICLOCK) | |
| 2987 | MCI_CLK_PWRSAVE), host->base + MMCICLOCK); |
Subhash Jadavani | dd43295 | 2012-03-28 11:25:56 +0530 | [diff] [blame] | 2988 | msmsdcc_sync_reg_wr(host); |
San Mehat | 9d2bd73 | 2009-09-22 16:44:22 -0700 | [diff] [blame] | 2989 | spin_unlock_irqrestore(&host->lock, flags); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2990 | |
| 2991 | /* |
| 2992 | * Switch VDDPX from high voltage to low voltage |
| 2993 | * to change the VDD of the SD IO pads. |
| 2994 | */ |
Subhash Jadavani | 99ba53a | 2011-08-01 16:04:18 +0530 | [diff] [blame] | 2995 | rc = msmsdcc_set_vddp_low_vol(host); |
| 2996 | if (rc) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2997 | goto out; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2998 | |
| 2999 | spin_lock_irqsave(&host->lock, flags); |
| 3000 | writel_relaxed((readl_relaxed(host->base + MMCICLOCK) | |
| 3001 | IO_PAD_PWR_SWITCH), host->base + MMCICLOCK); |
Subhash Jadavani | dd43295 | 2012-03-28 11:25:56 +0530 | [diff] [blame] | 3002 | msmsdcc_sync_reg_wr(host); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3003 | host->io_pad_pwr_switch = 1; |
| 3004 | spin_unlock_irqrestore(&host->lock, flags); |
| 3005 | |
| 3006 | /* Wait 5 ms for the voltage regulater in the card to become stable. */ |
| 3007 | usleep_range(5000, 5500); |
| 3008 | |
| 3009 | spin_lock_irqsave(&host->lock, flags); |
Subhash Jadavani | 0c0b818 | 2011-11-03 10:51:20 +0530 | [diff] [blame] | 3010 | /* Disable PWRSAVE would make sure that SD CLK is always running */ |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3011 | writel_relaxed((readl_relaxed(host->base + MMCICLOCK) |
| 3012 | & ~MCI_CLK_PWRSAVE), host->base + MMCICLOCK); |
Subhash Jadavani | dd43295 | 2012-03-28 11:25:56 +0530 | [diff] [blame] | 3013 | msmsdcc_sync_reg_wr(host); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3014 | spin_unlock_irqrestore(&host->lock, flags); |
| 3015 | |
| 3016 | /* |
| 3017 | * If MCIDATIN_3_0 and MCICMDIN bits of MCI_TEST_INPUT register |
| 3018 | * don't become all ones within 1 ms then a Voltage Switch |
| 3019 | * sequence has failed and a power cycle to the card is required. |
| 3020 | * Otherwise Voltage Switch sequence is completed successfully. |
| 3021 | */ |
| 3022 | usleep_range(1000, 1500); |
| 3023 | |
| 3024 | spin_lock_irqsave(&host->lock, flags); |
| 3025 | if ((readl_relaxed(host->base + MCI_TEST_INPUT) & (0xF << 1)) |
| 3026 | != (0xF << 1)) { |
| 3027 | pr_err("%s: %s: MCIDATIN_3_0 are still not all ones", |
| 3028 | mmc_hostname(mmc), __func__); |
Subhash Jadavani | 99ba53a | 2011-08-01 16:04:18 +0530 | [diff] [blame] | 3029 | rc = -EAGAIN; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3030 | goto out_unlock; |
| 3031 | } |
| 3032 | |
| 3033 | out_unlock: |
Subhash Jadavani | 0c0b818 | 2011-11-03 10:51:20 +0530 | [diff] [blame] | 3034 | /* Enable PWRSAVE */ |
| 3035 | writel_relaxed((readl_relaxed(host->base + MMCICLOCK) | |
| 3036 | MCI_CLK_PWRSAVE), host->base + MMCICLOCK); |
Subhash Jadavani | dd43295 | 2012-03-28 11:25:56 +0530 | [diff] [blame] | 3037 | msmsdcc_sync_reg_wr(host); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3038 | spin_unlock_irqrestore(&host->lock, flags); |
| 3039 | out: |
Subhash Jadavani | 99ba53a | 2011-08-01 16:04:18 +0530 | [diff] [blame] | 3040 | return rc; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3041 | } |
| 3042 | |
Subhash Jadavani | b52b4d7 | 2011-12-05 19:16:28 +0530 | [diff] [blame] | 3043 | static inline void msmsdcc_cm_sdc4_dll_set_freq(struct msmsdcc_host *host) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3044 | { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3045 | u32 mclk_freq = 0; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3046 | |
| 3047 | /* Program the MCLK value to MCLK_FREQ bit field */ |
| 3048 | if (host->clk_rate <= 112000000) |
| 3049 | mclk_freq = 0; |
| 3050 | else if (host->clk_rate <= 125000000) |
| 3051 | mclk_freq = 1; |
| 3052 | else if (host->clk_rate <= 137000000) |
| 3053 | mclk_freq = 2; |
| 3054 | else if (host->clk_rate <= 150000000) |
| 3055 | mclk_freq = 3; |
| 3056 | else if (host->clk_rate <= 162000000) |
| 3057 | mclk_freq = 4; |
| 3058 | else if (host->clk_rate <= 175000000) |
| 3059 | mclk_freq = 5; |
| 3060 | else if (host->clk_rate <= 187000000) |
| 3061 | mclk_freq = 6; |
| 3062 | else if (host->clk_rate <= 200000000) |
| 3063 | mclk_freq = 7; |
| 3064 | |
| 3065 | writel_relaxed(((readl_relaxed(host->base + MCI_DLL_CONFIG) |
| 3066 | & ~(7 << 24)) | (mclk_freq << 24)), |
| 3067 | host->base + MCI_DLL_CONFIG); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3068 | } |
| 3069 | |
Subhash Jadavani | b52b4d7 | 2011-12-05 19:16:28 +0530 | [diff] [blame] | 3070 | /* Initialize the DLL (Programmable Delay Line ) */ |
| 3071 | static int msmsdcc_init_cm_sdc4_dll(struct msmsdcc_host *host) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3072 | { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3073 | int rc = 0; |
Subhash Jadavani | b52b4d7 | 2011-12-05 19:16:28 +0530 | [diff] [blame] | 3074 | unsigned long flags; |
| 3075 | u32 wait_cnt; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3076 | |
Subhash Jadavani | b52b4d7 | 2011-12-05 19:16:28 +0530 | [diff] [blame] | 3077 | spin_lock_irqsave(&host->lock, flags); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3078 | /* |
| 3079 | * Make sure that clock is always enabled when DLL |
| 3080 | * tuning is in progress. Keeping PWRSAVE ON may |
| 3081 | * turn off the clock. So let's disable the PWRSAVE |
| 3082 | * here and re-enable it once tuning is completed. |
| 3083 | */ |
| 3084 | writel_relaxed((readl_relaxed(host->base + MMCICLOCK) |
| 3085 | & ~MCI_CLK_PWRSAVE), host->base + MMCICLOCK); |
Subhash Jadavani | dd43295 | 2012-03-28 11:25:56 +0530 | [diff] [blame] | 3086 | msmsdcc_sync_reg_wr(host); |
Subhash Jadavani | b52b4d7 | 2011-12-05 19:16:28 +0530 | [diff] [blame] | 3087 | |
| 3088 | /* Write 1 to DLL_RST bit of MCI_DLL_CONFIG register */ |
| 3089 | writel_relaxed((readl_relaxed(host->base + MCI_DLL_CONFIG) |
| 3090 | | MCI_DLL_RST), host->base + MCI_DLL_CONFIG); |
| 3091 | |
| 3092 | /* Write 1 to DLL_PDN bit of MCI_DLL_CONFIG register */ |
| 3093 | writel_relaxed((readl_relaxed(host->base + MCI_DLL_CONFIG) |
| 3094 | | MCI_DLL_PDN), host->base + MCI_DLL_CONFIG); |
| 3095 | |
| 3096 | msmsdcc_cm_sdc4_dll_set_freq(host); |
| 3097 | |
| 3098 | /* Write 0 to DLL_RST bit of MCI_DLL_CONFIG register */ |
| 3099 | writel_relaxed((readl_relaxed(host->base + MCI_DLL_CONFIG) |
| 3100 | & ~MCI_DLL_RST), host->base + MCI_DLL_CONFIG); |
| 3101 | |
| 3102 | /* Write 0 to DLL_PDN bit of MCI_DLL_CONFIG register */ |
| 3103 | writel_relaxed((readl_relaxed(host->base + MCI_DLL_CONFIG) |
| 3104 | & ~MCI_DLL_PDN), host->base + MCI_DLL_CONFIG); |
| 3105 | |
| 3106 | /* Set DLL_EN bit to 1. */ |
| 3107 | writel_relaxed((readl_relaxed(host->base + MCI_DLL_CONFIG) |
| 3108 | | MCI_DLL_EN), host->base + MCI_DLL_CONFIG); |
| 3109 | |
| 3110 | /* Set CK_OUT_EN bit to 1. */ |
| 3111 | writel_relaxed((readl_relaxed(host->base + MCI_DLL_CONFIG) |
| 3112 | | MCI_CK_OUT_EN), host->base + MCI_DLL_CONFIG); |
| 3113 | |
| 3114 | wait_cnt = 50; |
| 3115 | /* Wait until DLL_LOCK bit of MCI_DLL_STATUS register becomes '1' */ |
| 3116 | while (!(readl_relaxed(host->base + MCI_DLL_STATUS) & MCI_DLL_LOCK)) { |
| 3117 | /* max. wait for 50us sec for LOCK bit to be set */ |
| 3118 | if (--wait_cnt == 0) { |
| 3119 | pr_err("%s: %s: DLL failed to LOCK\n", |
| 3120 | mmc_hostname(host->mmc), __func__); |
| 3121 | rc = -ETIMEDOUT; |
| 3122 | goto out; |
| 3123 | } |
| 3124 | /* wait for 1us before polling again */ |
| 3125 | udelay(1); |
| 3126 | } |
| 3127 | |
| 3128 | out: |
| 3129 | /* re-enable PWRSAVE */ |
| 3130 | writel_relaxed((readl_relaxed(host->base + MMCICLOCK) | |
| 3131 | MCI_CLK_PWRSAVE), host->base + MMCICLOCK); |
Subhash Jadavani | dd43295 | 2012-03-28 11:25:56 +0530 | [diff] [blame] | 3132 | msmsdcc_sync_reg_wr(host); |
Subhash Jadavani | b52b4d7 | 2011-12-05 19:16:28 +0530 | [diff] [blame] | 3133 | spin_unlock_irqrestore(&host->lock, flags); |
| 3134 | |
| 3135 | return rc; |
| 3136 | } |
| 3137 | |
| 3138 | static inline int msmsdcc_dll_poll_ck_out_en(struct msmsdcc_host *host, |
| 3139 | u8 poll) |
| 3140 | { |
| 3141 | int rc = 0; |
| 3142 | u32 wait_cnt = 50; |
| 3143 | u8 ck_out_en = 0; |
| 3144 | |
| 3145 | /* poll for MCI_CK_OUT_EN bit. max. poll time = 50us */ |
| 3146 | ck_out_en = !!(readl_relaxed(host->base + MCI_DLL_CONFIG) & |
| 3147 | MCI_CK_OUT_EN); |
| 3148 | |
| 3149 | while (ck_out_en != poll) { |
| 3150 | if (--wait_cnt == 0) { |
| 3151 | pr_err("%s: %s: CK_OUT_EN bit is not %d\n", |
| 3152 | mmc_hostname(host->mmc), __func__, poll); |
| 3153 | rc = -ETIMEDOUT; |
| 3154 | goto out; |
| 3155 | } |
| 3156 | udelay(1); |
| 3157 | |
| 3158 | ck_out_en = !!(readl_relaxed(host->base + MCI_DLL_CONFIG) & |
| 3159 | MCI_CK_OUT_EN); |
| 3160 | } |
| 3161 | out: |
| 3162 | return rc; |
| 3163 | } |
| 3164 | |
| 3165 | /* |
| 3166 | * Enable a CDR circuit in CM_SDC4_DLL block to enable automatic |
| 3167 | * calibration sequence. This function should be called before |
| 3168 | * enabling AUTO_CMD19 bit in MCI_CMD register for block read |
| 3169 | * commands (CMD17/CMD18). |
| 3170 | * |
| 3171 | * This function gets called when host spinlock acquired. |
| 3172 | */ |
| 3173 | static int msmsdcc_enable_cdr_cm_sdc4_dll(struct msmsdcc_host *host) |
| 3174 | { |
| 3175 | int rc = 0; |
| 3176 | u32 config; |
| 3177 | |
| 3178 | config = readl_relaxed(host->base + MCI_DLL_CONFIG); |
| 3179 | config |= MCI_CDR_EN; |
| 3180 | config &= ~(MCI_CDR_EXT_EN | MCI_CK_OUT_EN); |
| 3181 | writel_relaxed(config, host->base + MCI_DLL_CONFIG); |
| 3182 | |
| 3183 | /* Wait until CK_OUT_EN bit of MCI_DLL_CONFIG register becomes '0' */ |
| 3184 | rc = msmsdcc_dll_poll_ck_out_en(host, 0); |
| 3185 | if (rc) |
| 3186 | goto err_out; |
| 3187 | |
| 3188 | /* Set CK_OUT_EN bit of MCI_DLL_CONFIG register to 1. */ |
| 3189 | writel_relaxed((readl_relaxed(host->base + MCI_DLL_CONFIG) |
| 3190 | | MCI_CK_OUT_EN), host->base + MCI_DLL_CONFIG); |
| 3191 | |
| 3192 | /* Wait until CK_OUT_EN bit of MCI_DLL_CONFIG register becomes '1' */ |
| 3193 | rc = msmsdcc_dll_poll_ck_out_en(host, 1); |
| 3194 | if (rc) |
| 3195 | goto err_out; |
| 3196 | |
| 3197 | goto out; |
| 3198 | |
| 3199 | err_out: |
| 3200 | pr_err("%s: %s: Failed\n", mmc_hostname(host->mmc), __func__); |
| 3201 | out: |
| 3202 | return rc; |
| 3203 | } |
| 3204 | |
| 3205 | static int msmsdcc_config_cm_sdc4_dll_phase(struct msmsdcc_host *host, |
| 3206 | u8 phase) |
| 3207 | { |
| 3208 | int rc = 0; |
Subhash Jadavani | fac0a09 | 2012-02-01 20:01:04 +0530 | [diff] [blame] | 3209 | u8 grey_coded_phase_table[] = {0x0, 0x1, 0x3, 0x2, 0x6, 0x7, 0x5, 0x4, |
| 3210 | 0xC, 0xD, 0xF, 0xE, 0xA, 0xB, 0x9, |
| 3211 | 0x8}; |
Subhash Jadavani | b52b4d7 | 2011-12-05 19:16:28 +0530 | [diff] [blame] | 3212 | unsigned long flags; |
| 3213 | u32 config; |
| 3214 | |
| 3215 | spin_lock_irqsave(&host->lock, flags); |
| 3216 | |
| 3217 | config = readl_relaxed(host->base + MCI_DLL_CONFIG); |
| 3218 | config &= ~(MCI_CDR_EN | MCI_CK_OUT_EN); |
| 3219 | config |= (MCI_CDR_EXT_EN | MCI_DLL_EN); |
| 3220 | writel_relaxed(config, host->base + MCI_DLL_CONFIG); |
| 3221 | |
| 3222 | /* Wait until CK_OUT_EN bit of MCI_DLL_CONFIG register becomes '0' */ |
| 3223 | rc = msmsdcc_dll_poll_ck_out_en(host, 0); |
| 3224 | if (rc) |
| 3225 | goto err_out; |
| 3226 | |
| 3227 | /* |
| 3228 | * Write the selected DLL clock output phase (0 ... 15) |
| 3229 | * to CDR_SELEXT bit field of MCI_DLL_CONFIG register. |
| 3230 | */ |
| 3231 | writel_relaxed(((readl_relaxed(host->base + MCI_DLL_CONFIG) |
| 3232 | & ~(0xF << 20)) |
| 3233 | | (grey_coded_phase_table[phase] << 20)), |
| 3234 | host->base + MCI_DLL_CONFIG); |
| 3235 | |
| 3236 | /* Set CK_OUT_EN bit of MCI_DLL_CONFIG register to 1. */ |
| 3237 | writel_relaxed((readl_relaxed(host->base + MCI_DLL_CONFIG) |
| 3238 | | MCI_CK_OUT_EN), host->base + MCI_DLL_CONFIG); |
| 3239 | |
| 3240 | /* Wait until CK_OUT_EN bit of MCI_DLL_CONFIG register becomes '1' */ |
| 3241 | rc = msmsdcc_dll_poll_ck_out_en(host, 1); |
| 3242 | if (rc) |
| 3243 | goto err_out; |
| 3244 | |
| 3245 | config = readl_relaxed(host->base + MCI_DLL_CONFIG); |
| 3246 | config |= MCI_CDR_EN; |
| 3247 | config &= ~MCI_CDR_EXT_EN; |
| 3248 | writel_relaxed(config, host->base + MCI_DLL_CONFIG); |
| 3249 | goto out; |
| 3250 | |
| 3251 | err_out: |
| 3252 | pr_err("%s: %s: Failed to set DLL phase: %d\n", |
| 3253 | mmc_hostname(host->mmc), __func__, phase); |
| 3254 | out: |
| 3255 | spin_unlock_irqrestore(&host->lock, flags); |
| 3256 | return rc; |
| 3257 | } |
| 3258 | |
| 3259 | /* |
| 3260 | * Find out the greatest range of consecuitive selected |
| 3261 | * DLL clock output phases that can be used as sampling |
| 3262 | * setting for SD3.0 UHS-I card read operation (in SDR104 |
| 3263 | * timing mode) or for eMMC4.5 card read operation (in HS200 |
| 3264 | * timing mode). |
| 3265 | * Select the 3/4 of the range and configure the DLL with the |
| 3266 | * selected DLL clock output phase. |
| 3267 | */ |
Subhash Jadavani | 3418704 | 2012-03-02 10:59:49 +0530 | [diff] [blame] | 3268 | static int find_most_appropriate_phase(struct msmsdcc_host *host, |
Subhash Jadavani | b52b4d7 | 2011-12-05 19:16:28 +0530 | [diff] [blame] | 3269 | u8 *phase_table, u8 total_phases) |
| 3270 | { |
Subhash Jadavani | 6159c62 | 2012-03-15 19:05:55 +0530 | [diff] [blame] | 3271 | #define MAX_PHASES 16 |
Subhash Jadavani | 3418704 | 2012-03-02 10:59:49 +0530 | [diff] [blame] | 3272 | int ret; |
Subhash Jadavani | 6159c62 | 2012-03-15 19:05:55 +0530 | [diff] [blame] | 3273 | u8 ranges[MAX_PHASES][MAX_PHASES] = { {0}, {0} }; |
| 3274 | u8 phases_per_row[MAX_PHASES] = {0}; |
Subhash Jadavani | b52b4d7 | 2011-12-05 19:16:28 +0530 | [diff] [blame] | 3275 | int row_index = 0, col_index = 0, selected_row_index = 0, curr_max = 0; |
Subhash Jadavani | 8b6ee57 | 2012-02-02 18:24:45 +0530 | [diff] [blame] | 3276 | int i, cnt, phase_0_raw_index = 0, phase_15_raw_index = 0; |
| 3277 | bool phase_0_found = false, phase_15_found = false; |
Subhash Jadavani | b52b4d7 | 2011-12-05 19:16:28 +0530 | [diff] [blame] | 3278 | |
Subhash Jadavani | 6159c62 | 2012-03-15 19:05:55 +0530 | [diff] [blame] | 3279 | if (!total_phases || (total_phases > MAX_PHASES)) { |
Subhash Jadavani | 3418704 | 2012-03-02 10:59:49 +0530 | [diff] [blame] | 3280 | pr_err("%s: %s: invalid argument: total_phases=%d\n", |
| 3281 | mmc_hostname(host->mmc), __func__, total_phases); |
| 3282 | return -EINVAL; |
| 3283 | } |
| 3284 | |
Subhash Jadavani | 8b6ee57 | 2012-02-02 18:24:45 +0530 | [diff] [blame] | 3285 | for (cnt = 0; cnt < total_phases; cnt++) { |
Subhash Jadavani | b52b4d7 | 2011-12-05 19:16:28 +0530 | [diff] [blame] | 3286 | ranges[row_index][col_index] = phase_table[cnt]; |
| 3287 | phases_per_row[row_index] += 1; |
| 3288 | col_index++; |
| 3289 | |
Subhash Jadavani | 8b6ee57 | 2012-02-02 18:24:45 +0530 | [diff] [blame] | 3290 | if ((cnt + 1) == total_phases) { |
Subhash Jadavani | b52b4d7 | 2011-12-05 19:16:28 +0530 | [diff] [blame] | 3291 | continue; |
| 3292 | /* check if next phase in phase_table is consecutive or not */ |
| 3293 | } else if ((phase_table[cnt] + 1) != phase_table[cnt + 1]) { |
| 3294 | row_index++; |
| 3295 | col_index = 0; |
| 3296 | } |
| 3297 | } |
| 3298 | |
Subhash Jadavani | 6159c62 | 2012-03-15 19:05:55 +0530 | [diff] [blame] | 3299 | if (row_index >= MAX_PHASES) |
| 3300 | return -EINVAL; |
| 3301 | |
Subhash Jadavani | 8b6ee57 | 2012-02-02 18:24:45 +0530 | [diff] [blame] | 3302 | /* Check if phase-0 is present in first valid window? */ |
| 3303 | if (!ranges[0][0]) { |
| 3304 | phase_0_found = true; |
| 3305 | phase_0_raw_index = 0; |
| 3306 | /* Check if cycle exist between 2 valid windows */ |
| 3307 | for (cnt = 1; cnt <= row_index; cnt++) { |
| 3308 | if (phases_per_row[cnt]) { |
Subhash Jadavani | 6159c62 | 2012-03-15 19:05:55 +0530 | [diff] [blame] | 3309 | for (i = 0; i < phases_per_row[cnt]; i++) { |
Subhash Jadavani | 8b6ee57 | 2012-02-02 18:24:45 +0530 | [diff] [blame] | 3310 | if (ranges[cnt][i] == 15) { |
| 3311 | phase_15_found = true; |
| 3312 | phase_15_raw_index = cnt; |
| 3313 | break; |
| 3314 | } |
| 3315 | } |
| 3316 | } |
| 3317 | } |
| 3318 | } |
| 3319 | |
| 3320 | /* If 2 valid windows form cycle then merge them as single window */ |
| 3321 | if (phase_0_found && phase_15_found) { |
| 3322 | /* number of phases in raw where phase 0 is present */ |
| 3323 | u8 phases_0 = phases_per_row[phase_0_raw_index]; |
| 3324 | /* number of phases in raw where phase 15 is present */ |
| 3325 | u8 phases_15 = phases_per_row[phase_15_raw_index]; |
| 3326 | |
Subhash Jadavani | 6159c62 | 2012-03-15 19:05:55 +0530 | [diff] [blame] | 3327 | if (phases_0 + phases_15 >= MAX_PHASES) |
| 3328 | /* |
| 3329 | * If there are more than 1 phase windows then total |
| 3330 | * number of phases in both the windows should not be |
| 3331 | * more than or equal to MAX_PHASES. |
| 3332 | */ |
| 3333 | return -EINVAL; |
| 3334 | |
| 3335 | /* Merge 2 cyclic windows */ |
| 3336 | i = phases_15; |
| 3337 | for (cnt = 0; cnt < phases_0; cnt++) { |
Subhash Jadavani | 8b6ee57 | 2012-02-02 18:24:45 +0530 | [diff] [blame] | 3338 | ranges[phase_15_raw_index][i] = |
| 3339 | ranges[phase_0_raw_index][cnt]; |
Subhash Jadavani | 6159c62 | 2012-03-15 19:05:55 +0530 | [diff] [blame] | 3340 | if (++i >= MAX_PHASES) |
| 3341 | break; |
Subhash Jadavani | 8b6ee57 | 2012-02-02 18:24:45 +0530 | [diff] [blame] | 3342 | } |
Subhash Jadavani | 6159c62 | 2012-03-15 19:05:55 +0530 | [diff] [blame] | 3343 | |
Subhash Jadavani | 8b6ee57 | 2012-02-02 18:24:45 +0530 | [diff] [blame] | 3344 | phases_per_row[phase_0_raw_index] = 0; |
| 3345 | phases_per_row[phase_15_raw_index] = phases_15 + phases_0; |
| 3346 | } |
| 3347 | |
| 3348 | for (cnt = 0; cnt <= row_index; cnt++) { |
Subhash Jadavani | b52b4d7 | 2011-12-05 19:16:28 +0530 | [diff] [blame] | 3349 | if (phases_per_row[cnt] > curr_max) { |
| 3350 | curr_max = phases_per_row[cnt]; |
| 3351 | selected_row_index = cnt; |
| 3352 | } |
| 3353 | } |
| 3354 | |
Subhash Jadavani | 6159c62 | 2012-03-15 19:05:55 +0530 | [diff] [blame] | 3355 | i = ((curr_max * 3) / 4); |
| 3356 | if (i) |
| 3357 | i--; |
| 3358 | |
Subhash Jadavani | 3418704 | 2012-03-02 10:59:49 +0530 | [diff] [blame] | 3359 | ret = (int)ranges[selected_row_index][i]; |
Subhash Jadavani | b52b4d7 | 2011-12-05 19:16:28 +0530 | [diff] [blame] | 3360 | |
Subhash Jadavani | 6159c62 | 2012-03-15 19:05:55 +0530 | [diff] [blame] | 3361 | if (ret >= MAX_PHASES) { |
| 3362 | ret = -EINVAL; |
| 3363 | pr_err("%s: %s: invalid phase selected=%d\n", |
| 3364 | mmc_hostname(host->mmc), __func__, ret); |
| 3365 | } |
| 3366 | |
Subhash Jadavani | b52b4d7 | 2011-12-05 19:16:28 +0530 | [diff] [blame] | 3367 | return ret; |
| 3368 | } |
| 3369 | |
Girish K S | a3f4169 | 2012-02-29 12:00:09 +0530 | [diff] [blame] | 3370 | static int msmsdcc_execute_tuning(struct mmc_host *mmc, u32 opcode) |
Subhash Jadavani | b52b4d7 | 2011-12-05 19:16:28 +0530 | [diff] [blame] | 3371 | { |
| 3372 | int rc = 0; |
| 3373 | struct msmsdcc_host *host = mmc_priv(mmc); |
| 3374 | unsigned long flags; |
| 3375 | u8 phase, *data_buf, tuned_phases[16], tuned_phase_cnt = 0; |
Subhash Jadavani | 56e0eaa | 2012-03-13 18:06:04 +0530 | [diff] [blame] | 3376 | const u32 *tuning_block_pattern = tuning_block_64; |
| 3377 | int size = sizeof(tuning_block_64); /* Tuning pattern size in bytes */ |
Subhash Jadavani | b52b4d7 | 2011-12-05 19:16:28 +0530 | [diff] [blame] | 3378 | |
| 3379 | pr_debug("%s: Enter %s\n", mmc_hostname(mmc), __func__); |
| 3380 | |
| 3381 | /* Tuning is only required for SDR104 modes */ |
| 3382 | if (!host->tuning_needed) { |
| 3383 | rc = 0; |
| 3384 | goto exit; |
| 3385 | } |
| 3386 | |
| 3387 | spin_lock_irqsave(&host->lock, flags); |
| 3388 | WARN(!host->pwr, "SDCC power is turned off\n"); |
| 3389 | WARN(!host->clks_on, "SDCC clocks are turned off\n"); |
| 3390 | WARN(host->sdcc_irq_disabled, "SDCC IRQ is disabled\n"); |
| 3391 | |
Subhash Jadavani | 56e0eaa | 2012-03-13 18:06:04 +0530 | [diff] [blame] | 3392 | host->tuning_in_progress = 1; |
Subhash Jadavani | 56e0eaa | 2012-03-13 18:06:04 +0530 | [diff] [blame] | 3393 | if ((opcode == MMC_SEND_TUNING_BLOCK_HS200) && |
| 3394 | (mmc->ios.bus_width == MMC_BUS_WIDTH_8)) { |
| 3395 | tuning_block_pattern = tuning_block_128; |
| 3396 | size = sizeof(tuning_block_128); |
| 3397 | } |
Subhash Jadavani | b52b4d7 | 2011-12-05 19:16:28 +0530 | [diff] [blame] | 3398 | spin_unlock_irqrestore(&host->lock, flags); |
| 3399 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3400 | /* first of all reset the tuning block */ |
| 3401 | rc = msmsdcc_init_cm_sdc4_dll(host); |
| 3402 | if (rc) |
| 3403 | goto out; |
| 3404 | |
Subhash Jadavani | 56e0eaa | 2012-03-13 18:06:04 +0530 | [diff] [blame] | 3405 | data_buf = kmalloc(size, GFP_KERNEL); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3406 | if (!data_buf) { |
| 3407 | rc = -ENOMEM; |
| 3408 | goto out; |
| 3409 | } |
| 3410 | |
| 3411 | phase = 0; |
| 3412 | do { |
| 3413 | struct mmc_command cmd = {0}; |
| 3414 | struct mmc_data data = {0}; |
| 3415 | struct mmc_request mrq = { |
| 3416 | .cmd = &cmd, |
| 3417 | .data = &data |
| 3418 | }; |
| 3419 | struct scatterlist sg; |
| 3420 | |
| 3421 | /* set the phase in delay line hw block */ |
| 3422 | rc = msmsdcc_config_cm_sdc4_dll_phase(host, phase); |
| 3423 | if (rc) |
| 3424 | goto kfree; |
| 3425 | |
Subhash Jadavani | 56e0eaa | 2012-03-13 18:06:04 +0530 | [diff] [blame] | 3426 | cmd.opcode = opcode; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3427 | cmd.flags = MMC_RSP_R1 | MMC_CMD_ADTC; |
| 3428 | |
Subhash Jadavani | 56e0eaa | 2012-03-13 18:06:04 +0530 | [diff] [blame] | 3429 | data.blksz = size; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3430 | data.blocks = 1; |
| 3431 | data.flags = MMC_DATA_READ; |
| 3432 | data.timeout_ns = 1000 * 1000 * 1000; /* 1 sec */ |
| 3433 | |
| 3434 | data.sg = &sg; |
| 3435 | data.sg_len = 1; |
Subhash Jadavani | 56e0eaa | 2012-03-13 18:06:04 +0530 | [diff] [blame] | 3436 | sg_init_one(&sg, data_buf, size); |
| 3437 | memset(data_buf, 0, size); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3438 | mmc_wait_for_req(mmc, &mrq); |
| 3439 | |
| 3440 | if (!cmd.error && !data.error && |
Subhash Jadavani | 56e0eaa | 2012-03-13 18:06:04 +0530 | [diff] [blame] | 3441 | !memcmp(data_buf, tuning_block_pattern, size)) { |
| 3442 | /* tuning is successful at this tuning point */ |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3443 | tuned_phases[tuned_phase_cnt++] = phase; |
Subhash Jadavani | 8b6ee57 | 2012-02-02 18:24:45 +0530 | [diff] [blame] | 3444 | pr_debug("%s: %s: found good phase = %d\n", |
| 3445 | mmc_hostname(mmc), __func__, phase); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3446 | } |
| 3447 | } while (++phase < 16); |
| 3448 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3449 | if (tuned_phase_cnt) { |
Subhash Jadavani | 3418704 | 2012-03-02 10:59:49 +0530 | [diff] [blame] | 3450 | rc = find_most_appropriate_phase(host, tuned_phases, |
Subhash Jadavani | b52b4d7 | 2011-12-05 19:16:28 +0530 | [diff] [blame] | 3451 | tuned_phase_cnt); |
Subhash Jadavani | 3418704 | 2012-03-02 10:59:49 +0530 | [diff] [blame] | 3452 | if (rc < 0) |
| 3453 | goto kfree; |
| 3454 | else |
| 3455 | phase = (u8)rc; |
| 3456 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3457 | /* |
| 3458 | * Finally set the selected phase in delay |
| 3459 | * line hw block. |
| 3460 | */ |
| 3461 | rc = msmsdcc_config_cm_sdc4_dll_phase(host, phase); |
| 3462 | if (rc) |
Subhash Jadavani | b52b4d7 | 2011-12-05 19:16:28 +0530 | [diff] [blame] | 3463 | goto kfree; |
| 3464 | pr_debug("%s: %s: finally setting the tuning phase to %d\n", |
| 3465 | mmc_hostname(mmc), __func__, phase); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3466 | } else { |
| 3467 | /* tuning failed */ |
Subhash Jadavani | b52b4d7 | 2011-12-05 19:16:28 +0530 | [diff] [blame] | 3468 | pr_err("%s: %s: no tuning point found\n", |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3469 | mmc_hostname(mmc), __func__); |
Subhash Jadavani | b52b4d7 | 2011-12-05 19:16:28 +0530 | [diff] [blame] | 3470 | msmsdcc_dump_sdcc_state(host); |
| 3471 | rc = -EAGAIN; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3472 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3473 | |
| 3474 | kfree: |
| 3475 | kfree(data_buf); |
| 3476 | out: |
Subhash Jadavani | b52b4d7 | 2011-12-05 19:16:28 +0530 | [diff] [blame] | 3477 | spin_lock_irqsave(&host->lock, flags); |
Subhash Jadavani | 56e0eaa | 2012-03-13 18:06:04 +0530 | [diff] [blame] | 3478 | host->tuning_in_progress = 0; |
Subhash Jadavani | b52b4d7 | 2011-12-05 19:16:28 +0530 | [diff] [blame] | 3479 | spin_unlock_irqrestore(&host->lock, flags); |
| 3480 | exit: |
| 3481 | pr_debug("%s: Exit %s\n", mmc_hostname(mmc), __func__); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3482 | return rc; |
San Mehat | 9d2bd73 | 2009-09-22 16:44:22 -0700 | [diff] [blame] | 3483 | } |
| 3484 | |
| 3485 | static const struct mmc_host_ops msmsdcc_ops = { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3486 | .enable = msmsdcc_enable, |
| 3487 | .disable = msmsdcc_disable, |
San Mehat | 9d2bd73 | 2009-09-22 16:44:22 -0700 | [diff] [blame] | 3488 | .request = msmsdcc_request, |
| 3489 | .set_ios = msmsdcc_set_ios, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3490 | .get_ro = msmsdcc_get_ro, |
San Mehat | 9d2bd73 | 2009-09-22 16:44:22 -0700 | [diff] [blame] | 3491 | .enable_sdio_irq = msmsdcc_enable_sdio_irq, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3492 | .start_signal_voltage_switch = msmsdcc_start_signal_voltage_switch, |
| 3493 | .execute_tuning = msmsdcc_execute_tuning |
San Mehat | 9d2bd73 | 2009-09-22 16:44:22 -0700 | [diff] [blame] | 3494 | }; |
| 3495 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3496 | static unsigned int |
| 3497 | msmsdcc_slot_status(struct msmsdcc_host *host) |
| 3498 | { |
| 3499 | int status; |
| 3500 | unsigned int gpio_no = host->plat->status_gpio; |
| 3501 | |
| 3502 | status = gpio_request(gpio_no, "SD_HW_Detect"); |
| 3503 | if (status) { |
| 3504 | pr_err("%s: %s: Failed to request GPIO %d\n", |
| 3505 | mmc_hostname(host->mmc), __func__, gpio_no); |
| 3506 | } else { |
| 3507 | status = gpio_direction_input(gpio_no); |
Krishna Konda | 941604a | 2012-01-10 17:46:34 -0800 | [diff] [blame] | 3508 | if (!status) { |
Krishna Konda | 360aa42 | 2011-12-06 18:27:41 -0800 | [diff] [blame] | 3509 | status = gpio_get_value_cansleep(gpio_no); |
Krishna Konda | 941604a | 2012-01-10 17:46:34 -0800 | [diff] [blame] | 3510 | if (host->plat->is_status_gpio_active_low) |
| 3511 | status = !status; |
| 3512 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3513 | gpio_free(gpio_no); |
| 3514 | } |
| 3515 | return status; |
| 3516 | } |
| 3517 | |
San Mehat | 9d2bd73 | 2009-09-22 16:44:22 -0700 | [diff] [blame] | 3518 | static void |
| 3519 | msmsdcc_check_status(unsigned long data) |
| 3520 | { |
| 3521 | struct msmsdcc_host *host = (struct msmsdcc_host *)data; |
| 3522 | unsigned int status; |
| 3523 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3524 | if (host->plat->status || host->plat->status_gpio) { |
Krishna Konda | 941604a | 2012-01-10 17:46:34 -0800 | [diff] [blame] | 3525 | if (host->plat->status) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3526 | status = host->plat->status(mmc_dev(host->mmc)); |
Krishna Konda | 941604a | 2012-01-10 17:46:34 -0800 | [diff] [blame] | 3527 | else |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3528 | status = msmsdcc_slot_status(host); |
| 3529 | |
Krishna Konda | 941604a | 2012-01-10 17:46:34 -0800 | [diff] [blame] | 3530 | host->eject = !status; |
Krishna Konda | 360aa42 | 2011-12-06 18:27:41 -0800 | [diff] [blame] | 3531 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3532 | if (status ^ host->oldstat) { |
Krishna Konda | 360aa42 | 2011-12-06 18:27:41 -0800 | [diff] [blame] | 3533 | if (host->plat->status) |
| 3534 | pr_info("%s: Slot status change detected " |
| 3535 | "(%d -> %d)\n", |
| 3536 | mmc_hostname(host->mmc), |
| 3537 | host->oldstat, status); |
| 3538 | else if (host->plat->is_status_gpio_active_low) |
| 3539 | pr_info("%s: Slot status change detected " |
| 3540 | "(%d -> %d) and the card detect GPIO" |
| 3541 | " is ACTIVE_LOW\n", |
| 3542 | mmc_hostname(host->mmc), |
| 3543 | host->oldstat, status); |
| 3544 | else |
| 3545 | pr_info("%s: Slot status change detected " |
| 3546 | "(%d -> %d) and the card detect GPIO" |
| 3547 | " is ACTIVE_HIGH\n", |
| 3548 | mmc_hostname(host->mmc), |
| 3549 | host->oldstat, status); |
San Mehat | 9d2bd73 | 2009-09-22 16:44:22 -0700 | [diff] [blame] | 3550 | mmc_detect_change(host->mmc, 0); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3551 | } |
| 3552 | host->oldstat = status; |
| 3553 | } else { |
| 3554 | mmc_detect_change(host->mmc, 0); |
San Mehat | 9d2bd73 | 2009-09-22 16:44:22 -0700 | [diff] [blame] | 3555 | } |
San Mehat | 9d2bd73 | 2009-09-22 16:44:22 -0700 | [diff] [blame] | 3556 | } |
| 3557 | |
| 3558 | static irqreturn_t |
| 3559 | msmsdcc_platform_status_irq(int irq, void *dev_id) |
| 3560 | { |
| 3561 | struct msmsdcc_host *host = dev_id; |
| 3562 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3563 | pr_debug("%s: %d\n", __func__, irq); |
San Mehat | 9d2bd73 | 2009-09-22 16:44:22 -0700 | [diff] [blame] | 3564 | msmsdcc_check_status((unsigned long) host); |
| 3565 | return IRQ_HANDLED; |
| 3566 | } |
| 3567 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3568 | static irqreturn_t |
| 3569 | msmsdcc_platform_sdiowakeup_irq(int irq, void *dev_id) |
| 3570 | { |
| 3571 | struct msmsdcc_host *host = dev_id; |
| 3572 | |
| 3573 | pr_debug("%s: SDIO Wake up IRQ : %d\n", mmc_hostname(host->mmc), irq); |
| 3574 | spin_lock(&host->lock); |
Sujit Reddy Thumma | f4a999c | 2012-02-09 23:14:45 +0530 | [diff] [blame] | 3575 | if (!host->sdio_wakeupirq_disabled) { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3576 | disable_irq_nosync(irq); |
Sujit Reddy Thumma | f4a999c | 2012-02-09 23:14:45 +0530 | [diff] [blame] | 3577 | if (host->sdcc_suspended) { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3578 | wake_lock(&host->sdio_wlock); |
| 3579 | msmsdcc_disable_irq_wake(host); |
| 3580 | } |
Sujit Reddy Thumma | f4a999c | 2012-02-09 23:14:45 +0530 | [diff] [blame] | 3581 | host->sdio_wakeupirq_disabled = 1; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3582 | } |
| 3583 | if (host->plat->is_sdio_al_client) { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3584 | wake_lock(&host->sdio_wlock); |
Asutosh Das | f5298c3 | 2012-04-03 14:51:47 +0530 | [diff] [blame] | 3585 | mmc_signal_sdio_irq(host->mmc); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3586 | } |
| 3587 | spin_unlock(&host->lock); |
| 3588 | |
| 3589 | return IRQ_HANDLED; |
| 3590 | } |
| 3591 | |
San Mehat | 9d2bd73 | 2009-09-22 16:44:22 -0700 | [diff] [blame] | 3592 | static void |
| 3593 | msmsdcc_status_notify_cb(int card_present, void *dev_id) |
| 3594 | { |
| 3595 | struct msmsdcc_host *host = dev_id; |
| 3596 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3597 | pr_debug("%s: card_present %d\n", mmc_hostname(host->mmc), |
San Mehat | 9d2bd73 | 2009-09-22 16:44:22 -0700 | [diff] [blame] | 3598 | card_present); |
| 3599 | msmsdcc_check_status((unsigned long) host); |
| 3600 | } |
| 3601 | |
San Mehat | 9d2bd73 | 2009-09-22 16:44:22 -0700 | [diff] [blame] | 3602 | static int |
| 3603 | msmsdcc_init_dma(struct msmsdcc_host *host) |
| 3604 | { |
| 3605 | memset(&host->dma, 0, sizeof(struct msmsdcc_dma_data)); |
| 3606 | host->dma.host = host; |
| 3607 | host->dma.channel = -1; |
Krishna Konda | 25786ec | 2011-07-25 16:21:36 -0700 | [diff] [blame] | 3608 | host->dma.crci = -1; |
San Mehat | 9d2bd73 | 2009-09-22 16:44:22 -0700 | [diff] [blame] | 3609 | |
| 3610 | if (!host->dmares) |
| 3611 | return -ENODEV; |
| 3612 | |
| 3613 | host->dma.nc = dma_alloc_coherent(NULL, |
| 3614 | sizeof(struct msmsdcc_nc_dmadata), |
| 3615 | &host->dma.nc_busaddr, |
| 3616 | GFP_KERNEL); |
| 3617 | if (host->dma.nc == NULL) { |
Joe Perches | 0a7ff7c | 2009-09-22 16:44:23 -0700 | [diff] [blame] | 3618 | pr_err("Unable to allocate DMA buffer\n"); |
San Mehat | 9d2bd73 | 2009-09-22 16:44:22 -0700 | [diff] [blame] | 3619 | return -ENOMEM; |
| 3620 | } |
| 3621 | memset(host->dma.nc, 0x00, sizeof(struct msmsdcc_nc_dmadata)); |
| 3622 | host->dma.cmd_busaddr = host->dma.nc_busaddr; |
| 3623 | host->dma.cmdptr_busaddr = host->dma.nc_busaddr + |
| 3624 | offsetof(struct msmsdcc_nc_dmadata, cmdptr); |
| 3625 | host->dma.channel = host->dmares->start; |
Krishna Konda | 25786ec | 2011-07-25 16:21:36 -0700 | [diff] [blame] | 3626 | host->dma.crci = host->dma_crci_res->start; |
San Mehat | 9d2bd73 | 2009-09-22 16:44:22 -0700 | [diff] [blame] | 3627 | |
| 3628 | return 0; |
| 3629 | } |
| 3630 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3631 | #ifdef CONFIG_MMC_MSM_SPS_SUPPORT |
| 3632 | /** |
| 3633 | * Allocate and Connect a SDCC peripheral's SPS endpoint |
| 3634 | * |
| 3635 | * This function allocates endpoint context and |
| 3636 | * connect it with memory endpoint by calling |
| 3637 | * appropriate SPS driver APIs. |
| 3638 | * |
| 3639 | * Also registers a SPS callback function with |
| 3640 | * SPS driver |
| 3641 | * |
| 3642 | * This function should only be called once typically |
| 3643 | * during driver probe. |
| 3644 | * |
| 3645 | * @host - Pointer to sdcc host structure |
| 3646 | * @ep - Pointer to sps endpoint data structure |
| 3647 | * @is_produce - 1 means Producer endpoint |
| 3648 | * 0 means Consumer endpoint |
| 3649 | * |
| 3650 | * @return - 0 if successful else negative value. |
| 3651 | * |
| 3652 | */ |
| 3653 | static int msmsdcc_sps_init_ep_conn(struct msmsdcc_host *host, |
| 3654 | struct msmsdcc_sps_ep_conn_data *ep, |
| 3655 | bool is_producer) |
| 3656 | { |
| 3657 | int rc = 0; |
| 3658 | struct sps_pipe *sps_pipe_handle; |
| 3659 | struct sps_connect *sps_config = &ep->config; |
| 3660 | struct sps_register_event *sps_event = &ep->event; |
| 3661 | |
| 3662 | /* Allocate endpoint context */ |
| 3663 | sps_pipe_handle = sps_alloc_endpoint(); |
| 3664 | if (!sps_pipe_handle) { |
| 3665 | pr_err("%s: sps_alloc_endpoint() failed!!! is_producer=%d", |
| 3666 | mmc_hostname(host->mmc), is_producer); |
| 3667 | rc = -ENOMEM; |
| 3668 | goto out; |
| 3669 | } |
| 3670 | |
| 3671 | /* Get default connection configuration for an endpoint */ |
| 3672 | rc = sps_get_config(sps_pipe_handle, sps_config); |
| 3673 | if (rc) { |
| 3674 | pr_err("%s: sps_get_config() failed!!! pipe_handle=0x%x," |
| 3675 | " rc=%d", mmc_hostname(host->mmc), |
| 3676 | (u32)sps_pipe_handle, rc); |
| 3677 | goto get_config_err; |
| 3678 | } |
| 3679 | |
| 3680 | /* Modify the default connection configuration */ |
| 3681 | if (is_producer) { |
| 3682 | /* |
| 3683 | * For SDCC producer transfer, source should be |
| 3684 | * SDCC peripheral where as destination should |
| 3685 | * be system memory. |
| 3686 | */ |
| 3687 | sps_config->source = host->sps.bam_handle; |
| 3688 | sps_config->destination = SPS_DEV_HANDLE_MEM; |
| 3689 | /* Producer pipe will handle this connection */ |
| 3690 | sps_config->mode = SPS_MODE_SRC; |
| 3691 | sps_config->options = |
| 3692 | SPS_O_AUTO_ENABLE | SPS_O_EOT | SPS_O_ACK_TRANSFERS; |
| 3693 | } else { |
| 3694 | /* |
| 3695 | * For SDCC consumer transfer, source should be |
| 3696 | * system memory where as destination should |
| 3697 | * SDCC peripheral |
| 3698 | */ |
| 3699 | sps_config->source = SPS_DEV_HANDLE_MEM; |
| 3700 | sps_config->destination = host->sps.bam_handle; |
| 3701 | sps_config->mode = SPS_MODE_DEST; |
| 3702 | sps_config->options = |
| 3703 | SPS_O_AUTO_ENABLE | SPS_O_EOT | SPS_O_ACK_TRANSFERS; |
| 3704 | } |
| 3705 | |
| 3706 | /* Producer pipe index */ |
| 3707 | sps_config->src_pipe_index = host->sps.src_pipe_index; |
| 3708 | /* Consumer pipe index */ |
| 3709 | sps_config->dest_pipe_index = host->sps.dest_pipe_index; |
| 3710 | /* |
| 3711 | * This event thresold value is only significant for BAM-to-BAM |
| 3712 | * transfer. It's ignored for BAM-to-System mode transfer. |
| 3713 | */ |
| 3714 | sps_config->event_thresh = 0x10; |
Sujit Reddy Thumma | cf6c4ed | 2011-11-14 17:20:36 +0530 | [diff] [blame] | 3715 | |
| 3716 | /* Allocate maximum descriptor fifo size */ |
| 3717 | sps_config->desc.size = SPS_MAX_DESC_FIFO_SIZE - |
| 3718 | (SPS_MAX_DESC_FIFO_SIZE % SPS_MAX_DESC_LENGTH); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3719 | sps_config->desc.base = dma_alloc_coherent(mmc_dev(host->mmc), |
| 3720 | sps_config->desc.size, |
| 3721 | &sps_config->desc.phys_base, |
| 3722 | GFP_KERNEL); |
| 3723 | |
Pratibhasagar V | 00b9433 | 2011-10-18 14:57:27 +0530 | [diff] [blame] | 3724 | if (!sps_config->desc.base) { |
| 3725 | rc = -ENOMEM; |
| 3726 | pr_err("%s: dma_alloc_coherent() failed!!! Can't allocate buffer\n" |
| 3727 | , mmc_hostname(host->mmc)); |
| 3728 | goto get_config_err; |
| 3729 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3730 | memset(sps_config->desc.base, 0x00, sps_config->desc.size); |
| 3731 | |
| 3732 | /* Establish connection between peripheral and memory endpoint */ |
| 3733 | rc = sps_connect(sps_pipe_handle, sps_config); |
| 3734 | if (rc) { |
| 3735 | pr_err("%s: sps_connect() failed!!! pipe_handle=0x%x," |
| 3736 | " rc=%d", mmc_hostname(host->mmc), |
| 3737 | (u32)sps_pipe_handle, rc); |
| 3738 | goto sps_connect_err; |
| 3739 | } |
| 3740 | |
| 3741 | sps_event->mode = SPS_TRIGGER_CALLBACK; |
| 3742 | sps_event->options = SPS_O_EOT; |
| 3743 | sps_event->callback = msmsdcc_sps_complete_cb; |
| 3744 | sps_event->xfer_done = NULL; |
| 3745 | sps_event->user = (void *)host; |
| 3746 | |
| 3747 | /* Register callback event for EOT (End of transfer) event. */ |
| 3748 | rc = sps_register_event(sps_pipe_handle, sps_event); |
| 3749 | if (rc) { |
| 3750 | pr_err("%s: sps_connect() failed!!! pipe_handle=0x%x," |
| 3751 | " rc=%d", mmc_hostname(host->mmc), |
| 3752 | (u32)sps_pipe_handle, rc); |
| 3753 | goto reg_event_err; |
| 3754 | } |
| 3755 | /* Now save the sps pipe handle */ |
| 3756 | ep->pipe_handle = sps_pipe_handle; |
| 3757 | pr_debug("%s: %s, success !!! %s: pipe_handle=0x%x," |
| 3758 | " desc_fifo.phys_base=0x%x\n", mmc_hostname(host->mmc), |
| 3759 | __func__, is_producer ? "READ" : "WRITE", |
| 3760 | (u32)sps_pipe_handle, sps_config->desc.phys_base); |
| 3761 | goto out; |
| 3762 | |
| 3763 | reg_event_err: |
| 3764 | sps_disconnect(sps_pipe_handle); |
| 3765 | sps_connect_err: |
| 3766 | dma_free_coherent(mmc_dev(host->mmc), |
| 3767 | sps_config->desc.size, |
| 3768 | sps_config->desc.base, |
| 3769 | sps_config->desc.phys_base); |
| 3770 | get_config_err: |
| 3771 | sps_free_endpoint(sps_pipe_handle); |
| 3772 | out: |
| 3773 | return rc; |
| 3774 | } |
| 3775 | |
| 3776 | /** |
| 3777 | * Disconnect and Deallocate a SDCC peripheral's SPS endpoint |
| 3778 | * |
| 3779 | * This function disconnect endpoint and deallocates |
| 3780 | * endpoint context. |
| 3781 | * |
| 3782 | * This function should only be called once typically |
| 3783 | * during driver remove. |
| 3784 | * |
| 3785 | * @host - Pointer to sdcc host structure |
| 3786 | * @ep - Pointer to sps endpoint data structure |
| 3787 | * |
| 3788 | */ |
| 3789 | static void msmsdcc_sps_exit_ep_conn(struct msmsdcc_host *host, |
| 3790 | struct msmsdcc_sps_ep_conn_data *ep) |
| 3791 | { |
| 3792 | struct sps_pipe *sps_pipe_handle = ep->pipe_handle; |
| 3793 | struct sps_connect *sps_config = &ep->config; |
| 3794 | struct sps_register_event *sps_event = &ep->event; |
| 3795 | |
| 3796 | sps_event->xfer_done = NULL; |
| 3797 | sps_event->callback = NULL; |
| 3798 | sps_register_event(sps_pipe_handle, sps_event); |
| 3799 | sps_disconnect(sps_pipe_handle); |
| 3800 | dma_free_coherent(mmc_dev(host->mmc), |
| 3801 | sps_config->desc.size, |
| 3802 | sps_config->desc.base, |
| 3803 | sps_config->desc.phys_base); |
| 3804 | sps_free_endpoint(sps_pipe_handle); |
| 3805 | } |
| 3806 | |
| 3807 | /** |
| 3808 | * Reset SDCC peripheral's SPS endpoint |
| 3809 | * |
| 3810 | * This function disconnects an endpoint. |
| 3811 | * |
| 3812 | * This function should be called for reseting |
| 3813 | * SPS endpoint when data transfer error is |
| 3814 | * encountered during data transfer. This |
| 3815 | * can be considered as soft reset to endpoint. |
| 3816 | * |
| 3817 | * This function should only be called if |
| 3818 | * msmsdcc_sps_init() is already called. |
| 3819 | * |
| 3820 | * @host - Pointer to sdcc host structure |
| 3821 | * @ep - Pointer to sps endpoint data structure |
| 3822 | * |
| 3823 | * @return - 0 if successful else negative value. |
| 3824 | */ |
| 3825 | static int msmsdcc_sps_reset_ep(struct msmsdcc_host *host, |
| 3826 | struct msmsdcc_sps_ep_conn_data *ep) |
| 3827 | { |
| 3828 | int rc = 0; |
| 3829 | struct sps_pipe *sps_pipe_handle = ep->pipe_handle; |
| 3830 | |
| 3831 | rc = sps_disconnect(sps_pipe_handle); |
| 3832 | if (rc) { |
| 3833 | pr_err("%s: %s: sps_disconnect() failed!!! pipe_handle=0x%x," |
| 3834 | " rc=%d", mmc_hostname(host->mmc), __func__, |
| 3835 | (u32)sps_pipe_handle, rc); |
| 3836 | goto out; |
| 3837 | } |
| 3838 | out: |
| 3839 | return rc; |
| 3840 | } |
| 3841 | |
| 3842 | /** |
| 3843 | * Restore SDCC peripheral's SPS endpoint |
| 3844 | * |
| 3845 | * This function connects an endpoint. |
| 3846 | * |
| 3847 | * This function should be called for restoring |
| 3848 | * SPS endpoint after data transfer error is |
| 3849 | * encountered during data transfer. This |
| 3850 | * can be considered as soft reset to endpoint. |
| 3851 | * |
| 3852 | * This function should only be called if |
| 3853 | * msmsdcc_sps_reset_ep() is called before. |
| 3854 | * |
| 3855 | * @host - Pointer to sdcc host structure |
| 3856 | * @ep - Pointer to sps endpoint data structure |
| 3857 | * |
| 3858 | * @return - 0 if successful else negative value. |
| 3859 | */ |
| 3860 | static int msmsdcc_sps_restore_ep(struct msmsdcc_host *host, |
| 3861 | struct msmsdcc_sps_ep_conn_data *ep) |
| 3862 | { |
| 3863 | int rc = 0; |
| 3864 | struct sps_pipe *sps_pipe_handle = ep->pipe_handle; |
| 3865 | struct sps_connect *sps_config = &ep->config; |
| 3866 | struct sps_register_event *sps_event = &ep->event; |
| 3867 | |
| 3868 | /* Establish connection between peripheral and memory endpoint */ |
| 3869 | rc = sps_connect(sps_pipe_handle, sps_config); |
| 3870 | if (rc) { |
| 3871 | pr_err("%s: %s: sps_connect() failed!!! pipe_handle=0x%x," |
| 3872 | " rc=%d", mmc_hostname(host->mmc), __func__, |
| 3873 | (u32)sps_pipe_handle, rc); |
| 3874 | goto out; |
| 3875 | } |
| 3876 | |
| 3877 | /* Register callback event for EOT (End of transfer) event. */ |
| 3878 | rc = sps_register_event(sps_pipe_handle, sps_event); |
| 3879 | if (rc) { |
| 3880 | pr_err("%s: %s: sps_register_event() failed!!!" |
| 3881 | " pipe_handle=0x%x, rc=%d", |
| 3882 | mmc_hostname(host->mmc), __func__, |
| 3883 | (u32)sps_pipe_handle, rc); |
| 3884 | goto reg_event_err; |
| 3885 | } |
| 3886 | goto out; |
| 3887 | |
| 3888 | reg_event_err: |
| 3889 | sps_disconnect(sps_pipe_handle); |
| 3890 | out: |
| 3891 | return rc; |
| 3892 | } |
| 3893 | |
| 3894 | /** |
| 3895 | * Initialize SPS HW connected with SDCC core |
| 3896 | * |
| 3897 | * This function register BAM HW resources with |
| 3898 | * SPS driver and then initialize 2 SPS endpoints |
| 3899 | * |
| 3900 | * This function should only be called once typically |
| 3901 | * during driver probe. |
| 3902 | * |
| 3903 | * @host - Pointer to sdcc host structure |
| 3904 | * |
| 3905 | * @return - 0 if successful else negative value. |
| 3906 | * |
| 3907 | */ |
| 3908 | static int msmsdcc_sps_init(struct msmsdcc_host *host) |
| 3909 | { |
| 3910 | int rc = 0; |
| 3911 | struct sps_bam_props bam = {0}; |
| 3912 | |
| 3913 | host->bam_base = ioremap(host->bam_memres->start, |
| 3914 | resource_size(host->bam_memres)); |
| 3915 | if (!host->bam_base) { |
| 3916 | pr_err("%s: BAM ioremap() failed!!! phys_addr=0x%x," |
| 3917 | " size=0x%x", mmc_hostname(host->mmc), |
| 3918 | host->bam_memres->start, |
| 3919 | (host->bam_memres->end - |
| 3920 | host->bam_memres->start)); |
| 3921 | rc = -ENOMEM; |
| 3922 | goto out; |
| 3923 | } |
| 3924 | |
| 3925 | bam.phys_addr = host->bam_memres->start; |
| 3926 | bam.virt_addr = host->bam_base; |
| 3927 | /* |
| 3928 | * This event thresold value is only significant for BAM-to-BAM |
| 3929 | * transfer. It's ignored for BAM-to-System mode transfer. |
| 3930 | */ |
| 3931 | bam.event_threshold = 0x10; /* Pipe event threshold */ |
| 3932 | /* |
| 3933 | * This threshold controls when the BAM publish |
| 3934 | * the descriptor size on the sideband interface. |
Subhash Jadavani | e6e1b82 | 2012-03-12 18:17:58 +0530 | [diff] [blame] | 3935 | * SPS HW will be used for data transfer size even |
| 3936 | * less than SDCC FIFO size. So let's set BAM summing |
| 3937 | * thresold to SPS_MIN_XFER_SIZE bytes. |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3938 | */ |
Subhash Jadavani | e6e1b82 | 2012-03-12 18:17:58 +0530 | [diff] [blame] | 3939 | bam.summing_threshold = SPS_MIN_XFER_SIZE; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3940 | /* SPS driver wll handle the SDCC BAM IRQ */ |
| 3941 | bam.irq = (u32)host->bam_irqres->start; |
| 3942 | bam.manage = SPS_BAM_MGR_LOCAL; |
| 3943 | |
| 3944 | pr_info("%s: bam physical base=0x%x\n", mmc_hostname(host->mmc), |
| 3945 | (u32)bam.phys_addr); |
| 3946 | pr_info("%s: bam virtual base=0x%x\n", mmc_hostname(host->mmc), |
| 3947 | (u32)bam.virt_addr); |
| 3948 | |
| 3949 | /* Register SDCC Peripheral BAM device to SPS driver */ |
| 3950 | rc = sps_register_bam_device(&bam, &host->sps.bam_handle); |
| 3951 | if (rc) { |
| 3952 | pr_err("%s: sps_register_bam_device() failed!!! err=%d", |
| 3953 | mmc_hostname(host->mmc), rc); |
| 3954 | goto reg_bam_err; |
| 3955 | } |
| 3956 | pr_info("%s: BAM device registered. bam_handle=0x%x", |
| 3957 | mmc_hostname(host->mmc), host->sps.bam_handle); |
| 3958 | |
| 3959 | host->sps.src_pipe_index = SPS_SDCC_PRODUCER_PIPE_INDEX; |
| 3960 | host->sps.dest_pipe_index = SPS_SDCC_CONSUMER_PIPE_INDEX; |
| 3961 | |
| 3962 | rc = msmsdcc_sps_init_ep_conn(host, &host->sps.prod, |
| 3963 | SPS_PROD_PERIPHERAL); |
| 3964 | if (rc) |
| 3965 | goto sps_reset_err; |
| 3966 | rc = msmsdcc_sps_init_ep_conn(host, &host->sps.cons, |
| 3967 | SPS_CONS_PERIPHERAL); |
| 3968 | if (rc) |
| 3969 | goto cons_conn_err; |
| 3970 | |
| 3971 | pr_info("%s: Qualcomm MSM SDCC-BAM at 0x%016llx irq %d\n", |
| 3972 | mmc_hostname(host->mmc), |
| 3973 | (unsigned long long)host->bam_memres->start, |
| 3974 | (unsigned int)host->bam_irqres->start); |
| 3975 | goto out; |
| 3976 | |
| 3977 | cons_conn_err: |
| 3978 | msmsdcc_sps_exit_ep_conn(host, &host->sps.prod); |
| 3979 | sps_reset_err: |
| 3980 | sps_deregister_bam_device(host->sps.bam_handle); |
| 3981 | reg_bam_err: |
| 3982 | iounmap(host->bam_base); |
| 3983 | out: |
| 3984 | return rc; |
| 3985 | } |
| 3986 | |
| 3987 | /** |
| 3988 | * De-initialize SPS HW connected with SDCC core |
| 3989 | * |
| 3990 | * This function deinitialize SPS endpoints and then |
| 3991 | * deregisters BAM resources from SPS driver. |
| 3992 | * |
| 3993 | * This function should only be called once typically |
| 3994 | * during driver remove. |
| 3995 | * |
| 3996 | * @host - Pointer to sdcc host structure |
| 3997 | * |
| 3998 | */ |
| 3999 | static void msmsdcc_sps_exit(struct msmsdcc_host *host) |
| 4000 | { |
| 4001 | msmsdcc_sps_exit_ep_conn(host, &host->sps.cons); |
| 4002 | msmsdcc_sps_exit_ep_conn(host, &host->sps.prod); |
| 4003 | sps_deregister_bam_device(host->sps.bam_handle); |
| 4004 | iounmap(host->bam_base); |
| 4005 | } |
| 4006 | #endif /* CONFIG_MMC_MSM_SPS_SUPPORT */ |
| 4007 | |
| 4008 | static ssize_t |
| 4009 | show_polling(struct device *dev, struct device_attribute *attr, char *buf) |
| 4010 | { |
| 4011 | struct mmc_host *mmc = dev_get_drvdata(dev); |
| 4012 | struct msmsdcc_host *host = mmc_priv(mmc); |
| 4013 | int poll; |
| 4014 | unsigned long flags; |
| 4015 | |
| 4016 | spin_lock_irqsave(&host->lock, flags); |
| 4017 | poll = !!(mmc->caps & MMC_CAP_NEEDS_POLL); |
| 4018 | spin_unlock_irqrestore(&host->lock, flags); |
| 4019 | |
| 4020 | return snprintf(buf, PAGE_SIZE, "%d\n", poll); |
| 4021 | } |
| 4022 | |
| 4023 | static ssize_t |
| 4024 | set_polling(struct device *dev, struct device_attribute *attr, |
| 4025 | const char *buf, size_t count) |
| 4026 | { |
| 4027 | struct mmc_host *mmc = dev_get_drvdata(dev); |
| 4028 | struct msmsdcc_host *host = mmc_priv(mmc); |
| 4029 | int value; |
| 4030 | unsigned long flags; |
| 4031 | |
| 4032 | sscanf(buf, "%d", &value); |
| 4033 | |
| 4034 | spin_lock_irqsave(&host->lock, flags); |
| 4035 | if (value) { |
| 4036 | mmc->caps |= MMC_CAP_NEEDS_POLL; |
| 4037 | mmc_detect_change(host->mmc, 0); |
| 4038 | } else { |
| 4039 | mmc->caps &= ~MMC_CAP_NEEDS_POLL; |
| 4040 | } |
| 4041 | #ifdef CONFIG_HAS_EARLYSUSPEND |
| 4042 | host->polling_enabled = mmc->caps & MMC_CAP_NEEDS_POLL; |
| 4043 | #endif |
| 4044 | spin_unlock_irqrestore(&host->lock, flags); |
| 4045 | return count; |
| 4046 | } |
| 4047 | |
| 4048 | static DEVICE_ATTR(polling, S_IRUGO | S_IWUSR, |
| 4049 | show_polling, set_polling); |
| 4050 | static struct attribute *dev_attrs[] = { |
| 4051 | &dev_attr_polling.attr, |
| 4052 | NULL, |
| 4053 | }; |
| 4054 | static struct attribute_group dev_attr_grp = { |
| 4055 | .attrs = dev_attrs, |
| 4056 | }; |
| 4057 | |
| 4058 | #ifdef CONFIG_HAS_EARLYSUSPEND |
| 4059 | static void msmsdcc_early_suspend(struct early_suspend *h) |
| 4060 | { |
| 4061 | struct msmsdcc_host *host = |
| 4062 | container_of(h, struct msmsdcc_host, early_suspend); |
| 4063 | unsigned long flags; |
| 4064 | |
| 4065 | spin_lock_irqsave(&host->lock, flags); |
| 4066 | host->polling_enabled = host->mmc->caps & MMC_CAP_NEEDS_POLL; |
| 4067 | host->mmc->caps &= ~MMC_CAP_NEEDS_POLL; |
| 4068 | spin_unlock_irqrestore(&host->lock, flags); |
| 4069 | }; |
| 4070 | static void msmsdcc_late_resume(struct early_suspend *h) |
| 4071 | { |
| 4072 | struct msmsdcc_host *host = |
| 4073 | container_of(h, struct msmsdcc_host, early_suspend); |
| 4074 | unsigned long flags; |
| 4075 | |
| 4076 | if (host->polling_enabled) { |
| 4077 | spin_lock_irqsave(&host->lock, flags); |
| 4078 | host->mmc->caps |= MMC_CAP_NEEDS_POLL; |
| 4079 | mmc_detect_change(host->mmc, 0); |
| 4080 | spin_unlock_irqrestore(&host->lock, flags); |
| 4081 | } |
| 4082 | }; |
| 4083 | #endif |
| 4084 | |
Subhash Jadavani | c0dd4a8 | 2011-09-07 18:41:36 +0530 | [diff] [blame] | 4085 | void msmsdcc_print_regs(const char *name, void __iomem *base, |
| 4086 | unsigned int no_of_regs) |
| 4087 | { |
| 4088 | unsigned int i; |
| 4089 | |
| 4090 | if (!base) |
| 4091 | return; |
| 4092 | pr_info("===== %s: Register Dumps @base=0x%x =====\n", |
| 4093 | name, (u32)base); |
| 4094 | for (i = 0; i < no_of_regs; i = i + 4) { |
| 4095 | pr_info("Reg=0x%.2x: 0x%.8x, 0x%.8x, 0x%.8x, 0x%.8x.\n", i*4, |
| 4096 | (u32)readl_relaxed(base + i*4), |
| 4097 | (u32)readl_relaxed(base + ((i+1)*4)), |
| 4098 | (u32)readl_relaxed(base + ((i+2)*4)), |
| 4099 | (u32)readl_relaxed(base + ((i+3)*4))); |
| 4100 | } |
| 4101 | } |
| 4102 | |
| 4103 | static void msmsdcc_dump_sdcc_state(struct msmsdcc_host *host) |
| 4104 | { |
| 4105 | /* Dump current state of SDCC clocks, power and irq */ |
| 4106 | pr_info("%s: SDCC PWR is %s\n", mmc_hostname(host->mmc), |
| 4107 | (host->pwr ? "ON" : "OFF")); |
| 4108 | pr_info("%s: SDCC clks are %s, MCLK rate=%d\n", |
| 4109 | mmc_hostname(host->mmc), |
| 4110 | (host->clks_on ? "ON" : "OFF"), |
| 4111 | (u32)clk_get_rate(host->clk)); |
| 4112 | pr_info("%s: SDCC irq is %s\n", mmc_hostname(host->mmc), |
| 4113 | (host->sdcc_irq_disabled ? "disabled" : "enabled")); |
| 4114 | |
| 4115 | /* Now dump SDCC registers. Don't print FIFO registers */ |
| 4116 | if (host->clks_on) |
| 4117 | msmsdcc_print_regs("SDCC-CORE", host->base, 28); |
| 4118 | |
| 4119 | if (host->curr.data) { |
Subhash Jadavani | e6e1b82 | 2012-03-12 18:17:58 +0530 | [diff] [blame] | 4120 | if (!msmsdcc_is_dma_possible(host, host->curr.data)) |
Subhash Jadavani | c0dd4a8 | 2011-09-07 18:41:36 +0530 | [diff] [blame] | 4121 | pr_info("%s: PIO mode\n", mmc_hostname(host->mmc)); |
| 4122 | else if (host->is_dma_mode) |
| 4123 | pr_info("%s: ADM mode: busy=%d, chnl=%d, crci=%d\n", |
| 4124 | mmc_hostname(host->mmc), host->dma.busy, |
| 4125 | host->dma.channel, host->dma.crci); |
| 4126 | else if (host->is_sps_mode) |
| 4127 | pr_info("%s: SPS mode: busy=%d\n", |
| 4128 | mmc_hostname(host->mmc), host->sps.busy); |
| 4129 | |
| 4130 | pr_info("%s: xfer_size=%d, data_xfered=%d, xfer_remain=%d\n", |
| 4131 | mmc_hostname(host->mmc), host->curr.xfer_size, |
| 4132 | host->curr.data_xfered, host->curr.xfer_remain); |
| 4133 | pr_info("%s: got_dataend=%d, prog_enable=%d," |
| 4134 | " wait_for_auto_prog_done=%d," |
| 4135 | " got_auto_prog_done=%d\n", |
| 4136 | mmc_hostname(host->mmc), host->curr.got_dataend, |
| 4137 | host->prog_enable, host->curr.wait_for_auto_prog_done, |
| 4138 | host->curr.got_auto_prog_done); |
| 4139 | } |
| 4140 | |
| 4141 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4142 | static void msmsdcc_req_tout_timer_hdlr(unsigned long data) |
| 4143 | { |
| 4144 | struct msmsdcc_host *host = (struct msmsdcc_host *)data; |
| 4145 | struct mmc_request *mrq; |
| 4146 | unsigned long flags; |
| 4147 | |
| 4148 | spin_lock_irqsave(&host->lock, flags); |
Oluwafemi Adeyemi | cb79144 | 2011-07-11 22:51:25 -0700 | [diff] [blame] | 4149 | if (host->dummy_52_sent) { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4150 | pr_info("%s: %s: dummy CMD52 timeout\n", |
| 4151 | mmc_hostname(host->mmc), __func__); |
Oluwafemi Adeyemi | cb79144 | 2011-07-11 22:51:25 -0700 | [diff] [blame] | 4152 | host->dummy_52_sent = 0; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4153 | } |
| 4154 | |
| 4155 | mrq = host->curr.mrq; |
| 4156 | |
| 4157 | if (mrq && mrq->cmd) { |
Subhash Jadavani | c0dd4a8 | 2011-09-07 18:41:36 +0530 | [diff] [blame] | 4158 | pr_info("%s: CMD%d: Request timeout\n", mmc_hostname(host->mmc), |
| 4159 | mrq->cmd->opcode); |
| 4160 | msmsdcc_dump_sdcc_state(host); |
| 4161 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4162 | if (!mrq->cmd->error) |
| 4163 | mrq->cmd->error = -ETIMEDOUT; |
Subhash Jadavani | c0dd4a8 | 2011-09-07 18:41:36 +0530 | [diff] [blame] | 4164 | host->dummy_52_needed = 0; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4165 | if (host->curr.data) { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4166 | if (mrq->data && !mrq->data->error) |
| 4167 | mrq->data->error = -ETIMEDOUT; |
| 4168 | host->curr.data_xfered = 0; |
| 4169 | if (host->dma.sg && host->is_dma_mode) { |
| 4170 | msm_dmov_stop_cmd(host->dma.channel, |
| 4171 | &host->dma.hdr, 0); |
| 4172 | } else if (host->sps.sg && host->is_sps_mode) { |
| 4173 | /* Stop current SPS transfer */ |
| 4174 | msmsdcc_sps_exit_curr_xfer(host); |
| 4175 | } else { |
| 4176 | msmsdcc_reset_and_restore(host); |
| 4177 | msmsdcc_stop_data(host); |
| 4178 | if (mrq->data && mrq->data->stop) |
| 4179 | msmsdcc_start_command(host, |
| 4180 | mrq->data->stop, 0); |
| 4181 | else |
| 4182 | msmsdcc_request_end(host, mrq); |
| 4183 | } |
| 4184 | } else { |
Subhash Jadavani | 7d8c94d | 2011-10-18 18:00:07 +0530 | [diff] [blame] | 4185 | host->prog_enable = 0; |
Subhash Jadavani | ed6b0e4 | 2012-03-07 16:36:27 +0530 | [diff] [blame] | 4186 | host->curr.wait_for_auto_prog_done = 0; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4187 | msmsdcc_reset_and_restore(host); |
| 4188 | msmsdcc_request_end(host, mrq); |
| 4189 | } |
| 4190 | } |
| 4191 | spin_unlock_irqrestore(&host->lock, flags); |
| 4192 | } |
| 4193 | |
Sujit Reddy Thumma | 7285c2e | 2011-11-04 10:18:15 +0530 | [diff] [blame] | 4194 | static struct mmc_platform_data *msmsdcc_populate_pdata(struct device *dev) |
| 4195 | { |
| 4196 | int i, ret; |
| 4197 | struct mmc_platform_data *pdata; |
| 4198 | struct device_node *np = dev->of_node; |
| 4199 | u32 bus_width = 0; |
| 4200 | u32 *clk_table; |
| 4201 | int clk_table_len; |
| 4202 | u32 *sup_voltages; |
| 4203 | int sup_volt_len; |
| 4204 | |
| 4205 | pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL); |
| 4206 | if (!pdata) { |
| 4207 | dev_err(dev, "could not allocate memory for platform data\n"); |
| 4208 | goto err; |
| 4209 | } |
| 4210 | |
| 4211 | of_property_read_u32(np, "qcom,sdcc-bus-width", &bus_width); |
| 4212 | if (bus_width == 8) { |
| 4213 | pdata->mmc_bus_width = MMC_CAP_8_BIT_DATA; |
| 4214 | } else if (bus_width == 4) { |
| 4215 | pdata->mmc_bus_width = MMC_CAP_4_BIT_DATA; |
| 4216 | } else { |
| 4217 | dev_notice(dev, "Invalid bus width, default to 1 bit mode\n"); |
| 4218 | pdata->mmc_bus_width = 0; |
| 4219 | } |
| 4220 | |
| 4221 | if (of_get_property(np, "qcom,sdcc-sup-voltages", &sup_volt_len)) { |
| 4222 | size_t sz; |
| 4223 | sz = sup_volt_len / sizeof(*sup_voltages); |
| 4224 | if (sz > 0) { |
| 4225 | sup_voltages = devm_kzalloc(dev, |
| 4226 | sz * sizeof(*sup_voltages), GFP_KERNEL); |
| 4227 | if (!sup_voltages) { |
| 4228 | dev_err(dev, "No memory for supported voltage\n"); |
| 4229 | goto err; |
| 4230 | } |
| 4231 | |
| 4232 | ret = of_property_read_u32_array(np, |
| 4233 | "qcom,sdcc-sup-voltages", sup_voltages, sz); |
| 4234 | if (ret < 0) { |
| 4235 | dev_err(dev, "error while reading voltage" |
| 4236 | "ranges %d\n", ret); |
| 4237 | goto err; |
| 4238 | } |
| 4239 | } else { |
| 4240 | dev_err(dev, "No supported voltages\n"); |
| 4241 | goto err; |
| 4242 | } |
| 4243 | for (i = 0; i < sz; i += 2) { |
| 4244 | u32 mask; |
| 4245 | |
| 4246 | mask = mmc_vddrange_to_ocrmask(sup_voltages[i], |
| 4247 | sup_voltages[i + 1]); |
| 4248 | if (!mask) |
| 4249 | dev_err(dev, "Invalide voltage range %d\n", i); |
| 4250 | pdata->ocr_mask |= mask; |
| 4251 | } |
| 4252 | dev_dbg(dev, "OCR mask=0x%x\n", pdata->ocr_mask); |
| 4253 | } else { |
| 4254 | dev_err(dev, "Supported voltage range not specified\n"); |
| 4255 | } |
| 4256 | |
| 4257 | if (of_get_property(np, "qcom,sdcc-clk-rates", &clk_table_len)) { |
| 4258 | size_t sz; |
| 4259 | sz = clk_table_len / sizeof(*clk_table); |
| 4260 | |
| 4261 | if (sz > 0) { |
| 4262 | clk_table = devm_kzalloc(dev, sz * sizeof(*clk_table), |
| 4263 | GFP_KERNEL); |
| 4264 | if (!clk_table) { |
| 4265 | dev_err(dev, "No memory for clock table\n"); |
| 4266 | goto err; |
| 4267 | } |
| 4268 | |
| 4269 | ret = of_property_read_u32_array(np, |
| 4270 | "qcom,sdcc-clk-rates", clk_table, sz); |
| 4271 | if (ret < 0) { |
| 4272 | dev_err(dev, "error while reading clk" |
| 4273 | "table %d\n", ret); |
| 4274 | goto err; |
| 4275 | } |
| 4276 | } else { |
| 4277 | dev_err(dev, "clk_table not specified\n"); |
| 4278 | goto err; |
| 4279 | } |
| 4280 | pdata->sup_clk_table = clk_table; |
| 4281 | pdata->sup_clk_cnt = sz; |
| 4282 | } else { |
| 4283 | dev_err(dev, "Supported clock rates not specified\n"); |
| 4284 | } |
| 4285 | |
| 4286 | if (of_get_property(np, "qcom,sdcc-nonremovable", NULL)) |
| 4287 | pdata->nonremovable = true; |
| 4288 | if (of_get_property(np, "qcom,sdcc-disable_cmd23", NULL)) |
| 4289 | pdata->disable_cmd23 = true; |
| 4290 | |
| 4291 | return pdata; |
| 4292 | err: |
| 4293 | return NULL; |
| 4294 | } |
| 4295 | |
San Mehat | 9d2bd73 | 2009-09-22 16:44:22 -0700 | [diff] [blame] | 4296 | static int |
| 4297 | msmsdcc_probe(struct platform_device *pdev) |
| 4298 | { |
Sujit Reddy Thumma | 7285c2e | 2011-11-04 10:18:15 +0530 | [diff] [blame] | 4299 | struct mmc_platform_data *plat; |
San Mehat | 9d2bd73 | 2009-09-22 16:44:22 -0700 | [diff] [blame] | 4300 | struct msmsdcc_host *host; |
| 4301 | struct mmc_host *mmc; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4302 | unsigned long flags; |
| 4303 | struct resource *core_irqres = NULL; |
| 4304 | struct resource *bam_irqres = NULL; |
| 4305 | struct resource *core_memres = NULL; |
| 4306 | struct resource *dml_memres = NULL; |
| 4307 | struct resource *bam_memres = NULL; |
San Mehat | 9d2bd73 | 2009-09-22 16:44:22 -0700 | [diff] [blame] | 4308 | struct resource *dmares = NULL; |
Krishna Konda | 25786ec | 2011-07-25 16:21:36 -0700 | [diff] [blame] | 4309 | struct resource *dma_crci_res = NULL; |
Pratibhasagar V | 00b9433 | 2011-10-18 14:57:27 +0530 | [diff] [blame] | 4310 | int ret = 0; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4311 | int i; |
San Mehat | 9d2bd73 | 2009-09-22 16:44:22 -0700 | [diff] [blame] | 4312 | |
Sujit Reddy Thumma | 7285c2e | 2011-11-04 10:18:15 +0530 | [diff] [blame] | 4313 | if (pdev->dev.of_node) { |
| 4314 | plat = msmsdcc_populate_pdata(&pdev->dev); |
| 4315 | of_property_read_u32((&pdev->dev)->of_node, |
| 4316 | "cell-index", &pdev->id); |
| 4317 | } else { |
| 4318 | plat = pdev->dev.platform_data; |
| 4319 | } |
| 4320 | |
San Mehat | 9d2bd73 | 2009-09-22 16:44:22 -0700 | [diff] [blame] | 4321 | /* must have platform data */ |
| 4322 | if (!plat) { |
Joe Perches | 0a7ff7c | 2009-09-22 16:44:23 -0700 | [diff] [blame] | 4323 | pr_err("%s: Platform data not available\n", __func__); |
San Mehat | 9d2bd73 | 2009-09-22 16:44:22 -0700 | [diff] [blame] | 4324 | ret = -EINVAL; |
| 4325 | goto out; |
| 4326 | } |
| 4327 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4328 | if (pdev->id < 1 || pdev->id > 5) |
San Mehat | 9d2bd73 | 2009-09-22 16:44:22 -0700 | [diff] [blame] | 4329 | return -EINVAL; |
| 4330 | |
Sujith Reddy Thumma | 84a0f51 | 2011-08-29 09:57:03 +0530 | [diff] [blame] | 4331 | if (plat->is_sdio_al_client && !plat->sdiowakeup_irq) { |
| 4332 | pr_err("%s: No wakeup IRQ for sdio_al client\n", __func__); |
| 4333 | return -EINVAL; |
| 4334 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4335 | |
San Mehat | 9d2bd73 | 2009-09-22 16:44:22 -0700 | [diff] [blame] | 4336 | if (pdev->resource == NULL || pdev->num_resources < 2) { |
Joe Perches | 0a7ff7c | 2009-09-22 16:44:23 -0700 | [diff] [blame] | 4337 | pr_err("%s: Invalid resource\n", __func__); |
San Mehat | 9d2bd73 | 2009-09-22 16:44:22 -0700 | [diff] [blame] | 4338 | return -ENXIO; |
| 4339 | } |
Sujit Reddy Thumma | 7285c2e | 2011-11-04 10:18:15 +0530 | [diff] [blame] | 4340 | if (pdev->dev.of_node) { |
| 4341 | /* |
| 4342 | * Device tree iomem resources are only accessible by index. |
| 4343 | * index = 0 -> SDCC register interface |
| 4344 | * index = 1 -> DML register interface |
| 4345 | * index = 2 -> BAM register interface |
| 4346 | * IRQ resources: |
| 4347 | * index = 0 -> SDCC IRQ |
| 4348 | * index = 1 -> BAM IRQ |
| 4349 | */ |
| 4350 | core_memres = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 4351 | dml_memres = platform_get_resource(pdev, IORESOURCE_MEM, 1); |
| 4352 | bam_memres = platform_get_resource(pdev, IORESOURCE_MEM, 2); |
| 4353 | core_irqres = platform_get_resource(pdev, IORESOURCE_IRQ, 0); |
| 4354 | bam_irqres = platform_get_resource(pdev, IORESOURCE_IRQ, 1); |
| 4355 | } else { |
| 4356 | for (i = 0; i < pdev->num_resources; i++) { |
| 4357 | if (pdev->resource[i].flags & IORESOURCE_MEM) { |
| 4358 | if (!strncmp(pdev->resource[i].name, |
| 4359 | "sdcc_dml_addr", |
| 4360 | sizeof("sdcc_dml_addr"))) |
| 4361 | dml_memres = &pdev->resource[i]; |
| 4362 | else if (!strncmp(pdev->resource[i].name, |
| 4363 | "sdcc_bam_addr", |
| 4364 | sizeof("sdcc_bam_addr"))) |
| 4365 | bam_memres = &pdev->resource[i]; |
| 4366 | else |
| 4367 | core_memres = &pdev->resource[i]; |
San Mehat | 9d2bd73 | 2009-09-22 16:44:22 -0700 | [diff] [blame] | 4368 | |
Sujit Reddy Thumma | 7285c2e | 2011-11-04 10:18:15 +0530 | [diff] [blame] | 4369 | } |
| 4370 | if (pdev->resource[i].flags & IORESOURCE_IRQ) { |
| 4371 | if (!strncmp(pdev->resource[i].name, |
| 4372 | "sdcc_bam_irq", |
| 4373 | sizeof("sdcc_bam_irq"))) |
| 4374 | bam_irqres = &pdev->resource[i]; |
| 4375 | else |
| 4376 | core_irqres = &pdev->resource[i]; |
| 4377 | } |
| 4378 | if (pdev->resource[i].flags & IORESOURCE_DMA) { |
| 4379 | if (!strncmp(pdev->resource[i].name, |
| 4380 | "sdcc_dma_chnl", |
| 4381 | sizeof("sdcc_dma_chnl"))) |
| 4382 | dmares = &pdev->resource[i]; |
| 4383 | else if (!strncmp(pdev->resource[i].name, |
| 4384 | "sdcc_dma_crci", |
| 4385 | sizeof("sdcc_dma_crci"))) |
| 4386 | dma_crci_res = &pdev->resource[i]; |
| 4387 | } |
Krishna Konda | 25786ec | 2011-07-25 16:21:36 -0700 | [diff] [blame] | 4388 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4389 | } |
| 4390 | |
| 4391 | if (!core_irqres || !core_memres) { |
| 4392 | pr_err("%s: Invalid sdcc core resource\n", __func__); |
| 4393 | return -ENXIO; |
| 4394 | } |
| 4395 | |
| 4396 | /* |
| 4397 | * Both BAM and DML memory resource should be preset. |
| 4398 | * BAM IRQ resource should also be present. |
| 4399 | */ |
| 4400 | if ((bam_memres && !dml_memres) || |
| 4401 | (!bam_memres && dml_memres) || |
| 4402 | ((bam_memres && dml_memres) && !bam_irqres)) { |
| 4403 | pr_err("%s: Invalid sdcc BAM/DML resource\n", __func__); |
San Mehat | 9d2bd73 | 2009-09-22 16:44:22 -0700 | [diff] [blame] | 4404 | return -ENXIO; |
| 4405 | } |
| 4406 | |
| 4407 | /* |
| 4408 | * Setup our host structure |
| 4409 | */ |
San Mehat | 9d2bd73 | 2009-09-22 16:44:22 -0700 | [diff] [blame] | 4410 | mmc = mmc_alloc_host(sizeof(struct msmsdcc_host), &pdev->dev); |
| 4411 | if (!mmc) { |
| 4412 | ret = -ENOMEM; |
| 4413 | goto out; |
| 4414 | } |
| 4415 | |
| 4416 | host = mmc_priv(mmc); |
| 4417 | host->pdev_id = pdev->id; |
| 4418 | host->plat = plat; |
| 4419 | host->mmc = mmc; |
San Mehat | 56a8b5b | 2009-11-21 12:29:46 -0800 | [diff] [blame] | 4420 | host->curr.cmd = NULL; |
Sahitya Tummala | d9df327 | 2011-08-19 16:50:46 +0530 | [diff] [blame] | 4421 | |
| 4422 | if (!plat->disable_bam && bam_memres && dml_memres && bam_irqres) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4423 | host->is_sps_mode = 1; |
| 4424 | else if (dmares) |
| 4425 | host->is_dma_mode = 1; |
San Mehat | 9d2bd73 | 2009-09-22 16:44:22 -0700 | [diff] [blame] | 4426 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4427 | host->base = ioremap(core_memres->start, |
| 4428 | resource_size(core_memres)); |
San Mehat | 9d2bd73 | 2009-09-22 16:44:22 -0700 | [diff] [blame] | 4429 | if (!host->base) { |
| 4430 | ret = -ENOMEM; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4431 | goto host_free; |
San Mehat | 9d2bd73 | 2009-09-22 16:44:22 -0700 | [diff] [blame] | 4432 | } |
| 4433 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4434 | host->core_irqres = core_irqres; |
| 4435 | host->bam_irqres = bam_irqres; |
| 4436 | host->core_memres = core_memres; |
| 4437 | host->dml_memres = dml_memres; |
| 4438 | host->bam_memres = bam_memres; |
San Mehat | 9d2bd73 | 2009-09-22 16:44:22 -0700 | [diff] [blame] | 4439 | host->dmares = dmares; |
Krishna Konda | 25786ec | 2011-07-25 16:21:36 -0700 | [diff] [blame] | 4440 | host->dma_crci_res = dma_crci_res; |
San Mehat | 9d2bd73 | 2009-09-22 16:44:22 -0700 | [diff] [blame] | 4441 | spin_lock_init(&host->lock); |
Asutosh Das | f5298c3 | 2012-04-03 14:51:47 +0530 | [diff] [blame] | 4442 | mutex_init(&host->clk_mutex); |
San Mehat | 9d2bd73 | 2009-09-22 16:44:22 -0700 | [diff] [blame] | 4443 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4444 | #ifdef CONFIG_MMC_EMBEDDED_SDIO |
| 4445 | if (plat->embedded_sdio) |
| 4446 | mmc_set_embedded_sdio_data(mmc, |
| 4447 | &plat->embedded_sdio->cis, |
| 4448 | &plat->embedded_sdio->cccr, |
| 4449 | plat->embedded_sdio->funcs, |
| 4450 | plat->embedded_sdio->num_funcs); |
| 4451 | #endif |
| 4452 | |
Sahitya Tummala | 62612cf | 2010-12-08 15:03:03 +0530 | [diff] [blame] | 4453 | tasklet_init(&host->dma_tlet, msmsdcc_dma_complete_tlet, |
| 4454 | (unsigned long)host); |
| 4455 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4456 | tasklet_init(&host->sps.tlet, msmsdcc_sps_complete_tlet, |
| 4457 | (unsigned long)host); |
| 4458 | if (host->is_dma_mode) { |
| 4459 | /* Setup DMA */ |
| 4460 | ret = msmsdcc_init_dma(host); |
| 4461 | if (ret) |
| 4462 | goto ioremap_free; |
| 4463 | } else { |
| 4464 | host->dma.channel = -1; |
Krishna Konda | 25786ec | 2011-07-25 16:21:36 -0700 | [diff] [blame] | 4465 | host->dma.crci = -1; |
San Mehat | 9d2bd73 | 2009-09-22 16:44:22 -0700 | [diff] [blame] | 4466 | } |
| 4467 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4468 | /* |
| 4469 | * Setup SDCC clock if derived from Dayatona |
| 4470 | * fabric core clock. |
| 4471 | */ |
| 4472 | if (plat->pclk_src_dfab) { |
Matt Wagantall | 37ce384 | 2011-08-17 16:00:36 -0700 | [diff] [blame] | 4473 | host->dfab_pclk = clk_get(&pdev->dev, "bus_clk"); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4474 | if (!IS_ERR(host->dfab_pclk)) { |
| 4475 | /* Set the clock rate to 64MHz for max. performance */ |
| 4476 | ret = clk_set_rate(host->dfab_pclk, 64000000); |
| 4477 | if (ret) |
| 4478 | goto dfab_pclk_put; |
Asutosh Das | f5298c3 | 2012-04-03 14:51:47 +0530 | [diff] [blame] | 4479 | ret = clk_prepare_enable(host->dfab_pclk); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4480 | if (ret) |
| 4481 | goto dfab_pclk_put; |
| 4482 | } else |
| 4483 | goto dma_free; |
| 4484 | } |
| 4485 | |
| 4486 | /* |
| 4487 | * Setup main peripheral bus clock |
| 4488 | */ |
Matt Wagantall | 37ce384 | 2011-08-17 16:00:36 -0700 | [diff] [blame] | 4489 | host->pclk = clk_get(&pdev->dev, "iface_clk"); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4490 | if (!IS_ERR(host->pclk)) { |
Asutosh Das | f5298c3 | 2012-04-03 14:51:47 +0530 | [diff] [blame] | 4491 | ret = clk_prepare_enable(host->pclk); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4492 | if (ret) |
| 4493 | goto pclk_put; |
| 4494 | |
| 4495 | host->pclk_rate = clk_get_rate(host->pclk); |
| 4496 | } |
| 4497 | |
| 4498 | /* |
| 4499 | * Setup SDC MMC clock |
| 4500 | */ |
Matt Wagantall | 37ce384 | 2011-08-17 16:00:36 -0700 | [diff] [blame] | 4501 | host->clk = clk_get(&pdev->dev, "core_clk"); |
San Mehat | 9d2bd73 | 2009-09-22 16:44:22 -0700 | [diff] [blame] | 4502 | if (IS_ERR(host->clk)) { |
| 4503 | ret = PTR_ERR(host->clk); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4504 | goto pclk_disable; |
San Mehat | 9d2bd73 | 2009-09-22 16:44:22 -0700 | [diff] [blame] | 4505 | } |
| 4506 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4507 | ret = clk_set_rate(host->clk, msmsdcc_get_min_sup_clk_rate(host)); |
| 4508 | if (ret) { |
| 4509 | pr_err("%s: Clock rate set failed (%d)\n", __func__, ret); |
| 4510 | goto clk_put; |
| 4511 | } |
| 4512 | |
Asutosh Das | f5298c3 | 2012-04-03 14:51:47 +0530 | [diff] [blame] | 4513 | ret = clk_prepare_enable(host->clk); |
San Mehat | 9d2bd73 | 2009-09-22 16:44:22 -0700 | [diff] [blame] | 4514 | if (ret) |
| 4515 | goto clk_put; |
| 4516 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4517 | host->clk_rate = clk_get_rate(host->clk); |
Sujith Reddy Thumma | c1824d5 | 2011-09-28 10:05:44 +0530 | [diff] [blame] | 4518 | if (!host->clk_rate) |
| 4519 | dev_err(&pdev->dev, "Failed to read MCLK\n"); |
Pratibhasagar V | 1c11da6 | 2011-11-14 12:36:35 +0530 | [diff] [blame] | 4520 | |
| 4521 | /* |
| 4522 | * Lookup the Controller Version, to identify the supported features |
| 4523 | * Version number read as 0 would indicate SDCC3 or earlier versions |
| 4524 | */ |
| 4525 | host->sdcc_version = readl_relaxed(host->base + MCI_VERSION); |
| 4526 | pr_info("%s: mci-version: %x\n", mmc_hostname(host->mmc), |
| 4527 | host->sdcc_version); |
Sujith Reddy Thumma | c1824d5 | 2011-09-28 10:05:44 +0530 | [diff] [blame] | 4528 | /* |
| 4529 | * Set the register write delay according to min. clock frequency |
| 4530 | * supported and update later when the host->clk_rate changes. |
| 4531 | */ |
| 4532 | host->reg_write_delay = |
| 4533 | (1 + ((3 * USEC_PER_SEC) / |
| 4534 | msmsdcc_get_min_sup_clk_rate(host))); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4535 | |
| 4536 | host->clks_on = 1; |
Subhash Jadavani | 15f29db | 2011-10-13 09:57:13 +0530 | [diff] [blame] | 4537 | /* Apply Hard reset to SDCC to put it in power on default state */ |
| 4538 | msmsdcc_hard_reset(host); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4539 | |
Subhash Jadavani | 933e6a6 | 2011-12-26 18:05:04 +0530 | [diff] [blame] | 4540 | /* pm qos request to prevent apps idle power collapse */ |
| 4541 | if (host->plat->swfi_latency) |
| 4542 | pm_qos_add_request(&host->pm_qos_req_dma, |
| 4543 | PM_QOS_CPU_DMA_LATENCY, PM_QOS_DEFAULT_VALUE); |
| 4544 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4545 | ret = msmsdcc_vreg_init(host, true); |
San Mehat | 9d2bd73 | 2009-09-22 16:44:22 -0700 | [diff] [blame] | 4546 | if (ret) { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4547 | pr_err("%s: msmsdcc_vreg_init() failed (%d)\n", __func__, ret); |
San Mehat | 9d2bd73 | 2009-09-22 16:44:22 -0700 | [diff] [blame] | 4548 | goto clk_disable; |
| 4549 | } |
| 4550 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4551 | |
| 4552 | /* Clocks has to be running before accessing SPS/DML HW blocks */ |
| 4553 | if (host->is_sps_mode) { |
| 4554 | /* Initialize SPS */ |
| 4555 | ret = msmsdcc_sps_init(host); |
| 4556 | if (ret) |
| 4557 | goto vreg_deinit; |
| 4558 | /* Initialize DML */ |
| 4559 | ret = msmsdcc_dml_init(host); |
| 4560 | if (ret) |
| 4561 | goto sps_exit; |
| 4562 | } |
Subhash Jadavani | 8766e35 | 2011-11-30 11:30:32 +0530 | [diff] [blame] | 4563 | mmc_dev(mmc)->dma_mask = &dma_mask; |
San Mehat | 9d2bd73 | 2009-09-22 16:44:22 -0700 | [diff] [blame] | 4564 | |
San Mehat | 9d2bd73 | 2009-09-22 16:44:22 -0700 | [diff] [blame] | 4565 | /* |
| 4566 | * Setup MMC host structure |
| 4567 | */ |
| 4568 | mmc->ops = &msmsdcc_ops; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4569 | mmc->f_min = msmsdcc_get_min_sup_clk_rate(host); |
| 4570 | mmc->f_max = msmsdcc_get_max_sup_clk_rate(host); |
San Mehat | 9d2bd73 | 2009-09-22 16:44:22 -0700 | [diff] [blame] | 4571 | mmc->ocr_avail = plat->ocr_mask; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4572 | mmc->pm_caps |= MMC_PM_KEEP_POWER | MMC_PM_WAKE_SDIO_IRQ; |
| 4573 | mmc->caps |= plat->mmc_bus_width; |
San Mehat | 9d2bd73 | 2009-09-22 16:44:22 -0700 | [diff] [blame] | 4574 | |
San Mehat | 9d2bd73 | 2009-09-22 16:44:22 -0700 | [diff] [blame] | 4575 | mmc->caps |= MMC_CAP_MMC_HIGHSPEED | MMC_CAP_SD_HIGHSPEED; |
Sujit Reddy Thumma | 31a45ce | 2012-03-07 09:43:59 +0530 | [diff] [blame] | 4576 | mmc->caps |= MMC_CAP_WAIT_WHILE_BUSY | MMC_CAP_ERASE; |
Subhash Jadavani | a8e5ecb | 2011-08-25 19:19:58 +0530 | [diff] [blame] | 4577 | |
| 4578 | /* |
| 4579 | * If we send the CMD23 before multi block write/read command |
| 4580 | * then we need not to send CMD12 at the end of the transfer. |
| 4581 | * If we don't send the CMD12 then only way to detect the PROG_DONE |
| 4582 | * status is to use the AUTO_PROG_DONE status provided by SDCC4 |
| 4583 | * controller. So let's enable the CMD23 for SDCC4 only. |
| 4584 | */ |
Pratibhasagar V | 1c11da6 | 2011-11-14 12:36:35 +0530 | [diff] [blame] | 4585 | if (!plat->disable_cmd23 && host->sdcc_version) |
Subhash Jadavani | a8e5ecb | 2011-08-25 19:19:58 +0530 | [diff] [blame] | 4586 | mmc->caps |= MMC_CAP_CMD23; |
| 4587 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4588 | mmc->caps |= plat->uhs_caps; |
| 4589 | /* |
| 4590 | * XPC controls the maximum current in the default speed mode of SDXC |
| 4591 | * card. XPC=0 means 100mA (max.) but speed class is not supported. |
| 4592 | * XPC=1 means 150mA (max.) and speed class is supported. |
| 4593 | */ |
| 4594 | if (plat->xpc_cap) |
| 4595 | mmc->caps |= (MMC_CAP_SET_XPC_330 | MMC_CAP_SET_XPC_300 | |
| 4596 | MMC_CAP_SET_XPC_180); |
| 4597 | |
Subhash Jadavani | 6bb34a8 | 2012-04-18 13:18:40 +0530 | [diff] [blame] | 4598 | mmc->caps2 |= (MMC_CAP2_BOOTPART_NOACC | MMC_CAP2_DETECT_ON_ERR); |
Subhash Jadavani | 56e0eaa | 2012-03-13 18:06:04 +0530 | [diff] [blame] | 4599 | if (pdev->dev.of_node) { |
| 4600 | if (of_get_property((&pdev->dev)->of_node, |
| 4601 | "qcom,sdcc-hs200", NULL)) |
| 4602 | mmc->caps2 |= MMC_CAP2_HS200_1_8V_SDR; |
| 4603 | } |
| 4604 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4605 | if (plat->nonremovable) |
| 4606 | mmc->caps |= MMC_CAP_NONREMOVABLE; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4607 | mmc->caps |= MMC_CAP_SDIO_IRQ; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4608 | |
| 4609 | if (plat->is_sdio_al_client) |
| 4610 | mmc->pm_flags |= MMC_PM_IGNORE_PM_NOTIFY; |
San Mehat | 9d2bd73 | 2009-09-22 16:44:22 -0700 | [diff] [blame] | 4611 | |
Sujit Reddy Thumma | cf6c4ed | 2011-11-14 17:20:36 +0530 | [diff] [blame] | 4612 | mmc->max_segs = msmsdcc_get_nr_sg(host); |
| 4613 | mmc->max_blk_size = MMC_MAX_BLK_SIZE; |
| 4614 | mmc->max_blk_count = MMC_MAX_BLK_CNT; |
San Mehat | 9d2bd73 | 2009-09-22 16:44:22 -0700 | [diff] [blame] | 4615 | |
Sujit Reddy Thumma | cf6c4ed | 2011-11-14 17:20:36 +0530 | [diff] [blame] | 4616 | mmc->max_req_size = MMC_MAX_REQ_SIZE; |
Subhash Jadavani | d4aff7f | 2011-12-08 18:08:19 +0530 | [diff] [blame] | 4617 | mmc->max_seg_size = mmc->max_req_size; |
San Mehat | 9d2bd73 | 2009-09-22 16:44:22 -0700 | [diff] [blame] | 4618 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4619 | writel_relaxed(0, host->base + MMCIMASK0); |
| 4620 | writel_relaxed(MCI_CLEAR_STATIC_MASK, host->base + MMCICLEAR); |
Subhash Jadavani | dd43295 | 2012-03-28 11:25:56 +0530 | [diff] [blame] | 4621 | msmsdcc_sync_reg_wr(host); |
San Mehat | 9d2bd73 | 2009-09-22 16:44:22 -0700 | [diff] [blame] | 4622 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4623 | writel_relaxed(MCI_IRQENABLE, host->base + MMCIMASK0); |
| 4624 | mb(); |
| 4625 | host->mci_irqenable = MCI_IRQENABLE; |
San Mehat | 9d2bd73 | 2009-09-22 16:44:22 -0700 | [diff] [blame] | 4626 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4627 | ret = request_irq(core_irqres->start, msmsdcc_irq, IRQF_SHARED, |
| 4628 | DRIVER_NAME " (cmd)", host); |
| 4629 | if (ret) |
| 4630 | goto dml_exit; |
| 4631 | |
| 4632 | ret = request_irq(core_irqres->start, msmsdcc_pio_irq, IRQF_SHARED, |
| 4633 | DRIVER_NAME " (pio)", host); |
| 4634 | if (ret) |
| 4635 | goto irq_free; |
| 4636 | |
| 4637 | /* |
| 4638 | * Enable SDCC IRQ only when host is powered on. Otherwise, this |
| 4639 | * IRQ is un-necessarily being monitored by MPM (Modem power |
| 4640 | * management block) during idle-power collapse. The MPM will be |
| 4641 | * configured to monitor the DATA1 GPIO line with level-low trigger |
| 4642 | * and thus depending on the GPIO status, it prevents TCXO shutdown |
| 4643 | * during idle-power collapse. |
| 4644 | */ |
| 4645 | disable_irq(core_irqres->start); |
| 4646 | host->sdcc_irq_disabled = 1; |
| 4647 | |
| 4648 | if (plat->sdiowakeup_irq) { |
| 4649 | wake_lock_init(&host->sdio_wlock, WAKE_LOCK_SUSPEND, |
| 4650 | mmc_hostname(mmc)); |
| 4651 | ret = request_irq(plat->sdiowakeup_irq, |
| 4652 | msmsdcc_platform_sdiowakeup_irq, |
| 4653 | IRQF_SHARED | IRQF_TRIGGER_LOW, |
| 4654 | DRIVER_NAME "sdiowakeup", host); |
| 4655 | if (ret) { |
| 4656 | pr_err("Unable to get sdio wakeup IRQ %d (%d)\n", |
| 4657 | plat->sdiowakeup_irq, ret); |
| 4658 | goto pio_irq_free; |
| 4659 | } else { |
| 4660 | spin_lock_irqsave(&host->lock, flags); |
Sujit Reddy Thumma | f4a999c | 2012-02-09 23:14:45 +0530 | [diff] [blame] | 4661 | if (!host->sdio_wakeupirq_disabled) { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4662 | disable_irq_nosync(plat->sdiowakeup_irq); |
Sujit Reddy Thumma | f4a999c | 2012-02-09 23:14:45 +0530 | [diff] [blame] | 4663 | host->sdio_wakeupirq_disabled = 1; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4664 | } |
| 4665 | spin_unlock_irqrestore(&host->lock, flags); |
| 4666 | } |
| 4667 | } |
| 4668 | |
Subhash Jadavani | c9b8575 | 2012-04-13 11:16:49 +0530 | [diff] [blame^] | 4669 | if (host->plat->mpm_sdiowakeup_int) { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4670 | wake_lock_init(&host->sdio_wlock, WAKE_LOCK_SUSPEND, |
| 4671 | mmc_hostname(mmc)); |
| 4672 | } |
| 4673 | |
| 4674 | wake_lock_init(&host->sdio_suspend_wlock, WAKE_LOCK_SUSPEND, |
| 4675 | mmc_hostname(mmc)); |
San Mehat | 9d2bd73 | 2009-09-22 16:44:22 -0700 | [diff] [blame] | 4676 | /* |
| 4677 | * Setup card detect change |
| 4678 | */ |
| 4679 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4680 | if (plat->status || plat->status_gpio) { |
Krishna Konda | 941604a | 2012-01-10 17:46:34 -0800 | [diff] [blame] | 4681 | if (plat->status) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4682 | host->oldstat = plat->status(mmc_dev(host->mmc)); |
Krishna Konda | 941604a | 2012-01-10 17:46:34 -0800 | [diff] [blame] | 4683 | else |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4684 | host->oldstat = msmsdcc_slot_status(host); |
Krishna Konda | 360aa42 | 2011-12-06 18:27:41 -0800 | [diff] [blame] | 4685 | |
Krishna Konda | 941604a | 2012-01-10 17:46:34 -0800 | [diff] [blame] | 4686 | host->eject = !host->oldstat; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4687 | } |
San Mehat | 9d2bd73 | 2009-09-22 16:44:22 -0700 | [diff] [blame] | 4688 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4689 | if (plat->status_irq) { |
| 4690 | ret = request_threaded_irq(plat->status_irq, NULL, |
San Mehat | 9d2bd73 | 2009-09-22 16:44:22 -0700 | [diff] [blame] | 4691 | msmsdcc_platform_status_irq, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4692 | plat->irq_flags, |
San Mehat | 9d2bd73 | 2009-09-22 16:44:22 -0700 | [diff] [blame] | 4693 | DRIVER_NAME " (slot)", |
| 4694 | host); |
| 4695 | if (ret) { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4696 | pr_err("Unable to get slot IRQ %d (%d)\n", |
| 4697 | plat->status_irq, ret); |
| 4698 | goto sdiowakeup_irq_free; |
San Mehat | 9d2bd73 | 2009-09-22 16:44:22 -0700 | [diff] [blame] | 4699 | } |
| 4700 | } else if (plat->register_status_notify) { |
| 4701 | plat->register_status_notify(msmsdcc_status_notify_cb, host); |
| 4702 | } else if (!plat->status) |
Joe Perches | 0a7ff7c | 2009-09-22 16:44:23 -0700 | [diff] [blame] | 4703 | pr_err("%s: No card detect facilities available\n", |
San Mehat | 9d2bd73 | 2009-09-22 16:44:22 -0700 | [diff] [blame] | 4704 | mmc_hostname(mmc)); |
San Mehat | 9d2bd73 | 2009-09-22 16:44:22 -0700 | [diff] [blame] | 4705 | |
| 4706 | mmc_set_drvdata(pdev, mmc); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4707 | |
| 4708 | ret = pm_runtime_set_active(&(pdev)->dev); |
| 4709 | if (ret < 0) |
| 4710 | pr_info("%s: %s: failed with error %d", mmc_hostname(mmc), |
| 4711 | __func__, ret); |
| 4712 | /* |
| 4713 | * There is no notion of suspend/resume for SD/MMC/SDIO |
| 4714 | * cards. So host can be suspended/resumed with out |
| 4715 | * worrying about its children. |
| 4716 | */ |
| 4717 | pm_suspend_ignore_children(&(pdev)->dev, true); |
| 4718 | |
| 4719 | /* |
| 4720 | * MMC/SD/SDIO bus suspend/resume operations are defined |
| 4721 | * only for the slots that will be used for non-removable |
| 4722 | * media or for all slots when CONFIG_MMC_UNSAFE_RESUME is |
| 4723 | * defined. Otherwise, they simply become card removal and |
| 4724 | * insertion events during suspend and resume respectively. |
| 4725 | * Hence, enable run-time PM only for slots for which bus |
| 4726 | * suspend/resume operations are defined. |
| 4727 | */ |
| 4728 | #ifdef CONFIG_MMC_UNSAFE_RESUME |
| 4729 | /* |
| 4730 | * If this capability is set, MMC core will enable/disable host |
| 4731 | * for every claim/release operation on a host. We use this |
| 4732 | * notification to increment/decrement runtime pm usage count. |
| 4733 | */ |
| 4734 | mmc->caps |= MMC_CAP_DISABLE; |
| 4735 | pm_runtime_enable(&(pdev)->dev); |
| 4736 | #else |
| 4737 | if (mmc->caps & MMC_CAP_NONREMOVABLE) { |
| 4738 | mmc->caps |= MMC_CAP_DISABLE; |
| 4739 | pm_runtime_enable(&(pdev)->dev); |
| 4740 | } |
| 4741 | #endif |
Sujit Reddy Thumma | 5000d2a | 2011-11-17 12:09:04 +0530 | [diff] [blame] | 4742 | #ifndef CONFIG_PM_RUNTIME |
| 4743 | mmc_set_disable_delay(mmc, MSM_MMC_DISABLE_TIMEOUT); |
| 4744 | #endif |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4745 | setup_timer(&host->req_tout_timer, msmsdcc_req_tout_timer_hdlr, |
| 4746 | (unsigned long)host); |
| 4747 | |
San Mehat | 9d2bd73 | 2009-09-22 16:44:22 -0700 | [diff] [blame] | 4748 | mmc_add_host(mmc); |
| 4749 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4750 | #ifdef CONFIG_HAS_EARLYSUSPEND |
| 4751 | host->early_suspend.suspend = msmsdcc_early_suspend; |
| 4752 | host->early_suspend.resume = msmsdcc_late_resume; |
| 4753 | host->early_suspend.level = EARLY_SUSPEND_LEVEL_DISABLE_FB; |
| 4754 | register_early_suspend(&host->early_suspend); |
| 4755 | #endif |
San Mehat | 9d2bd73 | 2009-09-22 16:44:22 -0700 | [diff] [blame] | 4756 | |
Krishna Konda | 25786ec | 2011-07-25 16:21:36 -0700 | [diff] [blame] | 4757 | pr_info("%s: Qualcomm MSM SDCC-core at 0x%016llx irq %d,%d dma %d" |
| 4758 | " dmacrcri %d\n", mmc_hostname(mmc), |
| 4759 | (unsigned long long)core_memres->start, |
| 4760 | (unsigned int) core_irqres->start, |
| 4761 | (unsigned int) plat->status_irq, host->dma.channel, |
| 4762 | host->dma.crci); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4763 | |
| 4764 | pr_info("%s: 8 bit data mode %s\n", mmc_hostname(mmc), |
| 4765 | (mmc->caps & MMC_CAP_8_BIT_DATA ? "enabled" : "disabled")); |
| 4766 | pr_info("%s: 4 bit data mode %s\n", mmc_hostname(mmc), |
| 4767 | (mmc->caps & MMC_CAP_4_BIT_DATA ? "enabled" : "disabled")); |
| 4768 | pr_info("%s: polling status mode %s\n", mmc_hostname(mmc), |
| 4769 | (mmc->caps & MMC_CAP_NEEDS_POLL ? "enabled" : "disabled")); |
| 4770 | pr_info("%s: MMC clock %u -> %u Hz, PCLK %u Hz\n", |
| 4771 | mmc_hostname(mmc), msmsdcc_get_min_sup_clk_rate(host), |
| 4772 | msmsdcc_get_max_sup_clk_rate(host), host->pclk_rate); |
| 4773 | pr_info("%s: Slot eject status = %d\n", mmc_hostname(mmc), |
| 4774 | host->eject); |
| 4775 | pr_info("%s: Power save feature enable = %d\n", |
| 4776 | mmc_hostname(mmc), msmsdcc_pwrsave); |
| 4777 | |
Krishna Konda | 25786ec | 2011-07-25 16:21:36 -0700 | [diff] [blame] | 4778 | if (host->is_dma_mode && host->dma.channel != -1 |
| 4779 | && host->dma.crci != -1) { |
Joe Perches | 0a7ff7c | 2009-09-22 16:44:23 -0700 | [diff] [blame] | 4780 | pr_info("%s: DM non-cached buffer at %p, dma_addr 0x%.8x\n", |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4781 | mmc_hostname(mmc), host->dma.nc, host->dma.nc_busaddr); |
Joe Perches | 0a7ff7c | 2009-09-22 16:44:23 -0700 | [diff] [blame] | 4782 | pr_info("%s: DM cmd busaddr 0x%.8x, cmdptr busaddr 0x%.8x\n", |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4783 | mmc_hostname(mmc), host->dma.cmd_busaddr, |
| 4784 | host->dma.cmdptr_busaddr); |
| 4785 | } else if (host->is_sps_mode) { |
| 4786 | pr_info("%s: SPS-BAM data transfer mode available\n", |
| 4787 | mmc_hostname(mmc)); |
San Mehat | 9d2bd73 | 2009-09-22 16:44:22 -0700 | [diff] [blame] | 4788 | } else |
Joe Perches | 0a7ff7c | 2009-09-22 16:44:23 -0700 | [diff] [blame] | 4789 | pr_info("%s: PIO transfer enabled\n", mmc_hostname(mmc)); |
San Mehat | 9d2bd73 | 2009-09-22 16:44:22 -0700 | [diff] [blame] | 4790 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4791 | #if defined(CONFIG_DEBUG_FS) |
| 4792 | msmsdcc_dbg_createhost(host); |
| 4793 | #endif |
| 4794 | if (!plat->status_irq) { |
| 4795 | ret = sysfs_create_group(&pdev->dev.kobj, &dev_attr_grp); |
| 4796 | if (ret) |
| 4797 | goto platform_irq_free; |
| 4798 | } |
San Mehat | 9d2bd73 | 2009-09-22 16:44:22 -0700 | [diff] [blame] | 4799 | return 0; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4800 | |
| 4801 | platform_irq_free: |
| 4802 | del_timer_sync(&host->req_tout_timer); |
| 4803 | pm_runtime_disable(&(pdev)->dev); |
| 4804 | pm_runtime_set_suspended(&(pdev)->dev); |
| 4805 | |
| 4806 | if (plat->status_irq) |
| 4807 | free_irq(plat->status_irq, host); |
| 4808 | sdiowakeup_irq_free: |
| 4809 | wake_lock_destroy(&host->sdio_suspend_wlock); |
| 4810 | if (plat->sdiowakeup_irq) |
| 4811 | free_irq(plat->sdiowakeup_irq, host); |
| 4812 | pio_irq_free: |
| 4813 | if (plat->sdiowakeup_irq) |
| 4814 | wake_lock_destroy(&host->sdio_wlock); |
| 4815 | free_irq(core_irqres->start, host); |
| 4816 | irq_free: |
| 4817 | free_irq(core_irqres->start, host); |
| 4818 | dml_exit: |
| 4819 | if (host->is_sps_mode) |
| 4820 | msmsdcc_dml_exit(host); |
| 4821 | sps_exit: |
| 4822 | if (host->is_sps_mode) |
| 4823 | msmsdcc_sps_exit(host); |
| 4824 | vreg_deinit: |
| 4825 | msmsdcc_vreg_init(host, false); |
San Mehat | 9d2bd73 | 2009-09-22 16:44:22 -0700 | [diff] [blame] | 4826 | clk_disable: |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4827 | clk_disable(host->clk); |
Subhash Jadavani | 933e6a6 | 2011-12-26 18:05:04 +0530 | [diff] [blame] | 4828 | if (host->plat->swfi_latency) |
| 4829 | pm_qos_remove_request(&host->pm_qos_req_dma); |
San Mehat | 9d2bd73 | 2009-09-22 16:44:22 -0700 | [diff] [blame] | 4830 | clk_put: |
| 4831 | clk_put(host->clk); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4832 | pclk_disable: |
| 4833 | if (!IS_ERR(host->pclk)) |
Asutosh Das | f5298c3 | 2012-04-03 14:51:47 +0530 | [diff] [blame] | 4834 | clk_disable_unprepare(host->pclk); |
San Mehat | 9d2bd73 | 2009-09-22 16:44:22 -0700 | [diff] [blame] | 4835 | pclk_put: |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4836 | if (!IS_ERR(host->pclk)) |
| 4837 | clk_put(host->pclk); |
| 4838 | if (!IS_ERR_OR_NULL(host->dfab_pclk)) |
Asutosh Das | f5298c3 | 2012-04-03 14:51:47 +0530 | [diff] [blame] | 4839 | clk_disable_unprepare(host->dfab_pclk); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4840 | dfab_pclk_put: |
| 4841 | if (!IS_ERR_OR_NULL(host->dfab_pclk)) |
| 4842 | clk_put(host->dfab_pclk); |
| 4843 | dma_free: |
| 4844 | if (host->is_dma_mode) { |
| 4845 | if (host->dmares) |
| 4846 | dma_free_coherent(NULL, |
| 4847 | sizeof(struct msmsdcc_nc_dmadata), |
| 4848 | host->dma.nc, host->dma.nc_busaddr); |
| 4849 | } |
| 4850 | ioremap_free: |
| 4851 | iounmap(host->base); |
San Mehat | 9d2bd73 | 2009-09-22 16:44:22 -0700 | [diff] [blame] | 4852 | host_free: |
| 4853 | mmc_free_host(mmc); |
| 4854 | out: |
| 4855 | return ret; |
| 4856 | } |
| 4857 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4858 | static int msmsdcc_remove(struct platform_device *pdev) |
Daniel Walker | 08ecfde | 2010-06-23 12:32:20 -0700 | [diff] [blame] | 4859 | { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4860 | struct mmc_host *mmc = mmc_get_drvdata(pdev); |
| 4861 | struct mmc_platform_data *plat; |
| 4862 | struct msmsdcc_host *host; |
Daniel Walker | 08ecfde | 2010-06-23 12:32:20 -0700 | [diff] [blame] | 4863 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4864 | if (!mmc) |
| 4865 | return -ENXIO; |
| 4866 | |
| 4867 | if (pm_runtime_suspended(&(pdev)->dev)) |
| 4868 | pm_runtime_resume(&(pdev)->dev); |
| 4869 | |
| 4870 | host = mmc_priv(mmc); |
| 4871 | |
| 4872 | DBG(host, "Removing SDCC device = %d\n", pdev->id); |
| 4873 | plat = host->plat; |
| 4874 | |
| 4875 | if (!plat->status_irq) |
| 4876 | sysfs_remove_group(&pdev->dev.kobj, &dev_attr_grp); |
| 4877 | |
| 4878 | del_timer_sync(&host->req_tout_timer); |
| 4879 | tasklet_kill(&host->dma_tlet); |
| 4880 | tasklet_kill(&host->sps.tlet); |
| 4881 | mmc_remove_host(mmc); |
| 4882 | |
| 4883 | if (plat->status_irq) |
| 4884 | free_irq(plat->status_irq, host); |
| 4885 | |
| 4886 | wake_lock_destroy(&host->sdio_suspend_wlock); |
| 4887 | if (plat->sdiowakeup_irq) { |
| 4888 | wake_lock_destroy(&host->sdio_wlock); |
| 4889 | irq_set_irq_wake(plat->sdiowakeup_irq, 0); |
| 4890 | free_irq(plat->sdiowakeup_irq, host); |
Daniel Walker | 08ecfde | 2010-06-23 12:32:20 -0700 | [diff] [blame] | 4891 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4892 | |
| 4893 | free_irq(host->core_irqres->start, host); |
| 4894 | free_irq(host->core_irqres->start, host); |
| 4895 | |
| 4896 | clk_put(host->clk); |
| 4897 | if (!IS_ERR(host->pclk)) |
| 4898 | clk_put(host->pclk); |
| 4899 | if (!IS_ERR_OR_NULL(host->dfab_pclk)) |
| 4900 | clk_put(host->dfab_pclk); |
| 4901 | |
Subhash Jadavani | 933e6a6 | 2011-12-26 18:05:04 +0530 | [diff] [blame] | 4902 | if (host->plat->swfi_latency) |
| 4903 | pm_qos_remove_request(&host->pm_qos_req_dma); |
| 4904 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4905 | msmsdcc_vreg_init(host, false); |
| 4906 | |
| 4907 | if (host->is_dma_mode) { |
| 4908 | if (host->dmares) |
| 4909 | dma_free_coherent(NULL, |
| 4910 | sizeof(struct msmsdcc_nc_dmadata), |
| 4911 | host->dma.nc, host->dma.nc_busaddr); |
| 4912 | } |
| 4913 | |
| 4914 | if (host->is_sps_mode) { |
| 4915 | msmsdcc_dml_exit(host); |
| 4916 | msmsdcc_sps_exit(host); |
| 4917 | } |
| 4918 | |
| 4919 | iounmap(host->base); |
| 4920 | mmc_free_host(mmc); |
| 4921 | |
| 4922 | #ifdef CONFIG_HAS_EARLYSUSPEND |
| 4923 | unregister_early_suspend(&host->early_suspend); |
| 4924 | #endif |
| 4925 | pm_runtime_disable(&(pdev)->dev); |
| 4926 | pm_runtime_set_suspended(&(pdev)->dev); |
| 4927 | |
| 4928 | return 0; |
| 4929 | } |
| 4930 | |
| 4931 | #ifdef CONFIG_MSM_SDIO_AL |
| 4932 | int msmsdcc_sdio_al_lpm(struct mmc_host *mmc, bool enable) |
| 4933 | { |
| 4934 | struct msmsdcc_host *host = mmc_priv(mmc); |
| 4935 | unsigned long flags; |
| 4936 | |
Asutosh Das | f5298c3 | 2012-04-03 14:51:47 +0530 | [diff] [blame] | 4937 | mutex_lock(&host->clk_mutex); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4938 | spin_lock_irqsave(&host->lock, flags); |
| 4939 | pr_debug("%s: %sabling LPM\n", mmc_hostname(mmc), |
| 4940 | enable ? "En" : "Dis"); |
| 4941 | |
| 4942 | if (enable) { |
| 4943 | if (!host->sdcc_irq_disabled) { |
| 4944 | writel_relaxed(0, host->base + MMCIMASK0); |
Sujith Reddy Thumma | de773b8 | 2011-08-03 19:58:15 +0530 | [diff] [blame] | 4945 | disable_irq_nosync(host->core_irqres->start); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4946 | host->sdcc_irq_disabled = 1; |
| 4947 | } |
| 4948 | |
| 4949 | if (host->clks_on) { |
Asutosh Das | f5298c3 | 2012-04-03 14:51:47 +0530 | [diff] [blame] | 4950 | spin_unlock_irqrestore(&host->lock, flags); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4951 | msmsdcc_setup_clocks(host, false); |
Asutosh Das | f5298c3 | 2012-04-03 14:51:47 +0530 | [diff] [blame] | 4952 | spin_lock_irqsave(&host->lock, flags); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4953 | host->clks_on = 0; |
| 4954 | } |
| 4955 | |
Sujith Reddy Thumma | 84a0f51 | 2011-08-29 09:57:03 +0530 | [diff] [blame] | 4956 | if (host->plat->sdio_lpm_gpio_setup && |
| 4957 | !host->sdio_gpio_lpm) { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4958 | spin_unlock_irqrestore(&host->lock, flags); |
| 4959 | host->plat->sdio_lpm_gpio_setup(mmc_dev(mmc), 0); |
| 4960 | spin_lock_irqsave(&host->lock, flags); |
| 4961 | host->sdio_gpio_lpm = 1; |
| 4962 | } |
| 4963 | |
Sujit Reddy Thumma | f4a999c | 2012-02-09 23:14:45 +0530 | [diff] [blame] | 4964 | if (host->sdio_wakeupirq_disabled) { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4965 | msmsdcc_enable_irq_wake(host); |
| 4966 | enable_irq(host->plat->sdiowakeup_irq); |
Sujit Reddy Thumma | f4a999c | 2012-02-09 23:14:45 +0530 | [diff] [blame] | 4967 | host->sdio_wakeupirq_disabled = 0; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4968 | } |
| 4969 | } else { |
Sujit Reddy Thumma | f4a999c | 2012-02-09 23:14:45 +0530 | [diff] [blame] | 4970 | if (!host->sdio_wakeupirq_disabled) { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4971 | disable_irq_nosync(host->plat->sdiowakeup_irq); |
Sujit Reddy Thumma | f4a999c | 2012-02-09 23:14:45 +0530 | [diff] [blame] | 4972 | host->sdio_wakeupirq_disabled = 1; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4973 | msmsdcc_disable_irq_wake(host); |
| 4974 | } |
| 4975 | |
Sujith Reddy Thumma | 84a0f51 | 2011-08-29 09:57:03 +0530 | [diff] [blame] | 4976 | if (host->plat->sdio_lpm_gpio_setup && |
| 4977 | host->sdio_gpio_lpm) { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4978 | spin_unlock_irqrestore(&host->lock, flags); |
| 4979 | host->plat->sdio_lpm_gpio_setup(mmc_dev(mmc), 1); |
| 4980 | spin_lock_irqsave(&host->lock, flags); |
| 4981 | host->sdio_gpio_lpm = 0; |
| 4982 | } |
| 4983 | |
| 4984 | if (!host->clks_on) { |
Asutosh Das | f5298c3 | 2012-04-03 14:51:47 +0530 | [diff] [blame] | 4985 | spin_unlock_irqrestore(&host->lock, flags); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4986 | msmsdcc_setup_clocks(host, true); |
Asutosh Das | f5298c3 | 2012-04-03 14:51:47 +0530 | [diff] [blame] | 4987 | spin_lock_irqsave(&host->lock, flags); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4988 | host->clks_on = 1; |
| 4989 | } |
| 4990 | |
| 4991 | if (host->sdcc_irq_disabled) { |
| 4992 | writel_relaxed(host->mci_irqenable, |
| 4993 | host->base + MMCIMASK0); |
| 4994 | mb(); |
| 4995 | enable_irq(host->core_irqres->start); |
| 4996 | host->sdcc_irq_disabled = 0; |
| 4997 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4998 | } |
| 4999 | spin_unlock_irqrestore(&host->lock, flags); |
Asutosh Das | f5298c3 | 2012-04-03 14:51:47 +0530 | [diff] [blame] | 5000 | mutex_unlock(&host->clk_mutex); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 5001 | return 0; |
| 5002 | } |
| 5003 | #else |
| 5004 | int msmsdcc_sdio_al_lpm(struct mmc_host *mmc, bool enable) |
| 5005 | { |
| 5006 | return 0; |
Daniel Walker | 08ecfde | 2010-06-23 12:32:20 -0700 | [diff] [blame] | 5007 | } |
| 5008 | #endif |
| 5009 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 5010 | #ifdef CONFIG_PM |
San Mehat | 9d2bd73 | 2009-09-22 16:44:22 -0700 | [diff] [blame] | 5011 | static int |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 5012 | msmsdcc_runtime_suspend(struct device *dev) |
San Mehat | 9d2bd73 | 2009-09-22 16:44:22 -0700 | [diff] [blame] | 5013 | { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 5014 | struct mmc_host *mmc = dev_get_drvdata(dev); |
| 5015 | struct msmsdcc_host *host = mmc_priv(mmc); |
San Mehat | 9d2bd73 | 2009-09-22 16:44:22 -0700 | [diff] [blame] | 5016 | int rc = 0; |
Sujit Reddy Thumma | f4a999c | 2012-02-09 23:14:45 +0530 | [diff] [blame] | 5017 | unsigned long flags; |
| 5018 | |
San Mehat | 9d2bd73 | 2009-09-22 16:44:22 -0700 | [diff] [blame] | 5019 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 5020 | if (host->plat->is_sdio_al_client) |
| 5021 | return 0; |
Sahitya Tummala | 7661a45 | 2011-07-18 13:28:35 +0530 | [diff] [blame] | 5022 | pr_debug("%s: %s: start\n", mmc_hostname(mmc), __func__); |
San Mehat | 9d2bd73 | 2009-09-22 16:44:22 -0700 | [diff] [blame] | 5023 | if (mmc) { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 5024 | host->sdcc_suspending = 1; |
| 5025 | mmc->suspend_task = current; |
San Mehat | 9d2bd73 | 2009-09-22 16:44:22 -0700 | [diff] [blame] | 5026 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 5027 | /* |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 5028 | * MMC core thinks that host is disabled by now since |
| 5029 | * runtime suspend is scheduled after msmsdcc_disable() |
| 5030 | * is called. Thus, MMC core will try to enable the host |
| 5031 | * while suspending it. This results in a synchronous |
| 5032 | * runtime resume request while in runtime suspending |
| 5033 | * context and hence inorder to complete this resume |
| 5034 | * requet, it will wait for suspend to be complete, |
| 5035 | * but runtime suspend also can not proceed further |
| 5036 | * until the host is resumed. Thus, it leads to a hang. |
| 5037 | * Hence, increase the pm usage count before suspending |
| 5038 | * the host so that any resume requests after this will |
| 5039 | * simple become pm usage counter increment operations. |
| 5040 | */ |
| 5041 | pm_runtime_get_noresume(dev); |
Sujit Reddy Thumma | 19859ef | 2011-12-14 21:17:08 +0530 | [diff] [blame] | 5042 | /* If there is pending detect work abort runtime suspend */ |
| 5043 | if (unlikely(work_busy(&mmc->detect.work))) |
| 5044 | rc = -EAGAIN; |
| 5045 | else |
| 5046 | rc = mmc_suspend_host(mmc); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 5047 | pm_runtime_put_noidle(dev); |
| 5048 | |
| 5049 | if (!rc) { |
Sujit Reddy Thumma | f4a999c | 2012-02-09 23:14:45 +0530 | [diff] [blame] | 5050 | spin_lock_irqsave(&host->lock, flags); |
| 5051 | host->sdcc_suspended = true; |
| 5052 | spin_unlock_irqrestore(&host->lock, flags); |
| 5053 | if (mmc->card && mmc_card_sdio(mmc->card) && |
| 5054 | mmc->ios.clock) { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 5055 | /* |
Sujit Reddy Thumma | f4a999c | 2012-02-09 23:14:45 +0530 | [diff] [blame] | 5056 | * If SDIO function driver doesn't want |
| 5057 | * to power off the card, atleast turn off |
| 5058 | * clocks to allow deep sleep (TCXO shutdown). |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 5059 | */ |
Sujit Reddy Thumma | f4a999c | 2012-02-09 23:14:45 +0530 | [diff] [blame] | 5060 | mmc_host_clk_hold(mmc); |
| 5061 | spin_lock_irqsave(&mmc->clk_lock, flags); |
| 5062 | mmc->clk_old = mmc->ios.clock; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 5063 | mmc->ios.clock = 0; |
Sujit Reddy Thumma | f4a999c | 2012-02-09 23:14:45 +0530 | [diff] [blame] | 5064 | mmc->clk_gated = true; |
| 5065 | spin_unlock_irqrestore(&mmc->clk_lock, flags); |
| 5066 | mmc_set_ios(mmc); |
| 5067 | mmc_host_clk_release(mmc); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 5068 | } |
| 5069 | } |
| 5070 | host->sdcc_suspending = 0; |
| 5071 | mmc->suspend_task = NULL; |
| 5072 | if (rc && wake_lock_active(&host->sdio_suspend_wlock)) |
| 5073 | wake_unlock(&host->sdio_suspend_wlock); |
San Mehat | 9d2bd73 | 2009-09-22 16:44:22 -0700 | [diff] [blame] | 5074 | } |
Sujit Reddy Thumma | 19859ef | 2011-12-14 21:17:08 +0530 | [diff] [blame] | 5075 | pr_debug("%s: %s: ends with err=%d\n", mmc_hostname(mmc), __func__, rc); |
San Mehat | 9d2bd73 | 2009-09-22 16:44:22 -0700 | [diff] [blame] | 5076 | return rc; |
| 5077 | } |
| 5078 | |
| 5079 | static int |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 5080 | msmsdcc_runtime_resume(struct device *dev) |
San Mehat | 9d2bd73 | 2009-09-22 16:44:22 -0700 | [diff] [blame] | 5081 | { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 5082 | struct mmc_host *mmc = dev_get_drvdata(dev); |
| 5083 | struct msmsdcc_host *host = mmc_priv(mmc); |
| 5084 | unsigned long flags; |
| 5085 | |
| 5086 | if (host->plat->is_sdio_al_client) |
| 5087 | return 0; |
San Mehat | 9d2bd73 | 2009-09-22 16:44:22 -0700 | [diff] [blame] | 5088 | |
Sahitya Tummala | 7661a45 | 2011-07-18 13:28:35 +0530 | [diff] [blame] | 5089 | pr_debug("%s: %s: start\n", mmc_hostname(mmc), __func__); |
San Mehat | 9d2bd73 | 2009-09-22 16:44:22 -0700 | [diff] [blame] | 5090 | if (mmc) { |
Sujit Reddy Thumma | f4a999c | 2012-02-09 23:14:45 +0530 | [diff] [blame] | 5091 | if (mmc->card && mmc_card_sdio(mmc->card) && |
| 5092 | mmc_card_keep_power(mmc)) { |
| 5093 | mmc_host_clk_hold(mmc); |
Sujit Reddy Thumma | d16214c | 2011-10-19 11:06:50 +0530 | [diff] [blame] | 5094 | mmc->ios.clock = host->clk_rate; |
Sujit Reddy Thumma | f4a999c | 2012-02-09 23:14:45 +0530 | [diff] [blame] | 5095 | mmc_set_ios(mmc); |
| 5096 | mmc_host_clk_release(mmc); |
Sujit Reddy Thumma | d16214c | 2011-10-19 11:06:50 +0530 | [diff] [blame] | 5097 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 5098 | |
| 5099 | mmc_resume_host(mmc); |
| 5100 | |
| 5101 | /* |
| 5102 | * FIXME: Clearing of flags must be handled in clients |
| 5103 | * resume handler. |
| 5104 | */ |
| 5105 | spin_lock_irqsave(&host->lock, flags); |
| 5106 | mmc->pm_flags = 0; |
Sujit Reddy Thumma | f4a999c | 2012-02-09 23:14:45 +0530 | [diff] [blame] | 5107 | host->sdcc_suspended = false; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 5108 | spin_unlock_irqrestore(&host->lock, flags); |
| 5109 | |
| 5110 | /* |
| 5111 | * After resuming the host wait for sometime so that |
| 5112 | * the SDIO work will be processed. |
| 5113 | */ |
Sujit Reddy Thumma | f4a999c | 2012-02-09 23:14:45 +0530 | [diff] [blame] | 5114 | if (mmc->card && mmc_card_sdio(mmc->card)) { |
Subhash Jadavani | c9b8575 | 2012-04-13 11:16:49 +0530 | [diff] [blame^] | 5115 | if ((host->plat->mpm_sdiowakeup_int || |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 5116 | host->plat->sdiowakeup_irq) && |
| 5117 | wake_lock_active(&host->sdio_wlock)) |
| 5118 | wake_lock_timeout(&host->sdio_wlock, 1); |
| 5119 | } |
| 5120 | |
| 5121 | wake_unlock(&host->sdio_suspend_wlock); |
San Mehat | 9d2bd73 | 2009-09-22 16:44:22 -0700 | [diff] [blame] | 5122 | } |
Sahitya Tummala | 7661a45 | 2011-07-18 13:28:35 +0530 | [diff] [blame] | 5123 | pr_debug("%s: %s: end\n", mmc_hostname(mmc), __func__); |
San Mehat | 9d2bd73 | 2009-09-22 16:44:22 -0700 | [diff] [blame] | 5124 | return 0; |
| 5125 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 5126 | |
| 5127 | static int msmsdcc_runtime_idle(struct device *dev) |
| 5128 | { |
| 5129 | struct mmc_host *mmc = dev_get_drvdata(dev); |
| 5130 | struct msmsdcc_host *host = mmc_priv(mmc); |
| 5131 | |
| 5132 | if (host->plat->is_sdio_al_client) |
| 5133 | return 0; |
| 5134 | |
| 5135 | /* Idle timeout is not configurable for now */ |
| 5136 | pm_schedule_suspend(dev, MSM_MMC_IDLE_TIMEOUT); |
| 5137 | |
| 5138 | return -EAGAIN; |
| 5139 | } |
| 5140 | |
| 5141 | static int msmsdcc_pm_suspend(struct device *dev) |
| 5142 | { |
| 5143 | struct mmc_host *mmc = dev_get_drvdata(dev); |
| 5144 | struct msmsdcc_host *host = mmc_priv(mmc); |
| 5145 | int rc = 0; |
| 5146 | |
| 5147 | if (host->plat->is_sdio_al_client) |
| 5148 | return 0; |
| 5149 | |
| 5150 | |
| 5151 | if (host->plat->status_irq) |
| 5152 | disable_irq(host->plat->status_irq); |
| 5153 | |
Subhash Jadavani | 1870221 | 2012-03-19 18:50:18 +0530 | [diff] [blame] | 5154 | if (!pm_runtime_suspended(dev)) { |
| 5155 | if (!(mmc->card && mmc_card_sdio(mmc->card))) { |
| 5156 | /* |
| 5157 | * decrement power.usage_counter if it's |
| 5158 | * not zero earlier |
| 5159 | */ |
| 5160 | pm_runtime_put_noidle(dev); |
| 5161 | rc = pm_runtime_suspend(dev); |
| 5162 | } |
| 5163 | |
| 5164 | /* |
| 5165 | * if device runtime PM status is still not suspended |
| 5166 | * then perform suspend here. |
| 5167 | */ |
| 5168 | if (!pm_runtime_suspended(dev)) |
| 5169 | rc = msmsdcc_runtime_suspend(dev); |
| 5170 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 5171 | |
| 5172 | return rc; |
| 5173 | } |
| 5174 | |
Sujit Reddy Thumma | f4a999c | 2012-02-09 23:14:45 +0530 | [diff] [blame] | 5175 | static int msmsdcc_suspend_noirq(struct device *dev) |
| 5176 | { |
| 5177 | struct mmc_host *mmc = dev_get_drvdata(dev); |
| 5178 | struct msmsdcc_host *host = mmc_priv(mmc); |
| 5179 | int rc = 0; |
| 5180 | |
| 5181 | /* |
| 5182 | * After platform suspend there may be active request |
| 5183 | * which might have enabled clocks. For example, in SDIO |
| 5184 | * case, ksdioirq thread might have scheduled after sdcc |
| 5185 | * suspend but before system freeze. In that case abort |
| 5186 | * suspend and retry instead of keeping the clocks on |
| 5187 | * during suspend and not allowing TCXO. |
| 5188 | */ |
| 5189 | |
Asutosh Das | f5298c3 | 2012-04-03 14:51:47 +0530 | [diff] [blame] | 5190 | if (host->clks_on && !host->plat->is_sdio_al_client) { |
Sujit Reddy Thumma | f4a999c | 2012-02-09 23:14:45 +0530 | [diff] [blame] | 5191 | pr_warn("%s: clocks are on after suspend, aborting system " |
| 5192 | "suspend\n", mmc_hostname(mmc)); |
| 5193 | rc = -EAGAIN; |
| 5194 | } |
| 5195 | |
| 5196 | return rc; |
| 5197 | } |
| 5198 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 5199 | static int msmsdcc_pm_resume(struct device *dev) |
| 5200 | { |
| 5201 | struct mmc_host *mmc = dev_get_drvdata(dev); |
| 5202 | struct msmsdcc_host *host = mmc_priv(mmc); |
| 5203 | int rc = 0; |
| 5204 | |
| 5205 | if (host->plat->is_sdio_al_client) |
| 5206 | return 0; |
| 5207 | |
Sahitya Tummala | fb48637 | 2011-09-02 19:01:49 +0530 | [diff] [blame] | 5208 | if (!pm_runtime_suspended(dev)) |
| 5209 | rc = msmsdcc_runtime_resume(dev); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 5210 | if (host->plat->status_irq) { |
| 5211 | msmsdcc_check_status((unsigned long)host); |
| 5212 | enable_irq(host->plat->status_irq); |
| 5213 | } |
| 5214 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 5215 | return rc; |
| 5216 | } |
| 5217 | |
Daniel Walker | 08ecfde | 2010-06-23 12:32:20 -0700 | [diff] [blame] | 5218 | #else |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 5219 | #define msmsdcc_runtime_suspend NULL |
| 5220 | #define msmsdcc_runtime_resume NULL |
| 5221 | #define msmsdcc_runtime_idle NULL |
| 5222 | #define msmsdcc_pm_suspend NULL |
| 5223 | #define msmsdcc_pm_resume NULL |
Sujit Reddy Thumma | f4a999c | 2012-02-09 23:14:45 +0530 | [diff] [blame] | 5224 | #define msmsdcc_suspend_noirq NULL |
Daniel Walker | 08ecfde | 2010-06-23 12:32:20 -0700 | [diff] [blame] | 5225 | #endif |
San Mehat | 9d2bd73 | 2009-09-22 16:44:22 -0700 | [diff] [blame] | 5226 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 5227 | static const struct dev_pm_ops msmsdcc_dev_pm_ops = { |
| 5228 | .runtime_suspend = msmsdcc_runtime_suspend, |
| 5229 | .runtime_resume = msmsdcc_runtime_resume, |
| 5230 | .runtime_idle = msmsdcc_runtime_idle, |
| 5231 | .suspend = msmsdcc_pm_suspend, |
| 5232 | .resume = msmsdcc_pm_resume, |
Sujit Reddy Thumma | f4a999c | 2012-02-09 23:14:45 +0530 | [diff] [blame] | 5233 | .suspend_noirq = msmsdcc_suspend_noirq, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 5234 | }; |
| 5235 | |
Sujit Reddy Thumma | 7285c2e | 2011-11-04 10:18:15 +0530 | [diff] [blame] | 5236 | static const struct of_device_id msmsdcc_dt_match[] = { |
| 5237 | {.compatible = "qcom,msm-sdcc"}, |
| 5238 | |
| 5239 | }; |
| 5240 | MODULE_DEVICE_TABLE(of, msmsdcc_dt_match); |
| 5241 | |
San Mehat | 9d2bd73 | 2009-09-22 16:44:22 -0700 | [diff] [blame] | 5242 | static struct platform_driver msmsdcc_driver = { |
| 5243 | .probe = msmsdcc_probe, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 5244 | .remove = msmsdcc_remove, |
San Mehat | 9d2bd73 | 2009-09-22 16:44:22 -0700 | [diff] [blame] | 5245 | .driver = { |
| 5246 | .name = "msm_sdcc", |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 5247 | .pm = &msmsdcc_dev_pm_ops, |
Sujit Reddy Thumma | 7285c2e | 2011-11-04 10:18:15 +0530 | [diff] [blame] | 5248 | .of_match_table = msmsdcc_dt_match, |
San Mehat | 9d2bd73 | 2009-09-22 16:44:22 -0700 | [diff] [blame] | 5249 | }, |
| 5250 | }; |
| 5251 | |
| 5252 | static int __init msmsdcc_init(void) |
| 5253 | { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 5254 | #if defined(CONFIG_DEBUG_FS) |
| 5255 | int ret = 0; |
| 5256 | ret = msmsdcc_dbg_init(); |
| 5257 | if (ret) { |
| 5258 | pr_err("Failed to create debug fs dir \n"); |
| 5259 | return ret; |
| 5260 | } |
| 5261 | #endif |
San Mehat | 9d2bd73 | 2009-09-22 16:44:22 -0700 | [diff] [blame] | 5262 | return platform_driver_register(&msmsdcc_driver); |
| 5263 | } |
| 5264 | |
| 5265 | static void __exit msmsdcc_exit(void) |
| 5266 | { |
| 5267 | platform_driver_unregister(&msmsdcc_driver); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 5268 | |
| 5269 | #if defined(CONFIG_DEBUG_FS) |
| 5270 | debugfs_remove(debugfs_file); |
| 5271 | debugfs_remove(debugfs_dir); |
| 5272 | #endif |
San Mehat | 9d2bd73 | 2009-09-22 16:44:22 -0700 | [diff] [blame] | 5273 | } |
| 5274 | |
| 5275 | module_init(msmsdcc_init); |
| 5276 | module_exit(msmsdcc_exit); |
| 5277 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 5278 | MODULE_DESCRIPTION("Qualcomm Multimedia Card Interface driver"); |
San Mehat | 9d2bd73 | 2009-09-22 16:44:22 -0700 | [diff] [blame] | 5279 | MODULE_LICENSE("GPL"); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 5280 | |
| 5281 | #if defined(CONFIG_DEBUG_FS) |
| 5282 | |
| 5283 | static int |
| 5284 | msmsdcc_dbg_state_open(struct inode *inode, struct file *file) |
| 5285 | { |
| 5286 | file->private_data = inode->i_private; |
| 5287 | return 0; |
| 5288 | } |
| 5289 | |
| 5290 | static ssize_t |
| 5291 | msmsdcc_dbg_state_read(struct file *file, char __user *ubuf, |
| 5292 | size_t count, loff_t *ppos) |
| 5293 | { |
| 5294 | struct msmsdcc_host *host = (struct msmsdcc_host *) file->private_data; |
Stephen Boyd | 0a66585 | 2011-12-15 00:20:53 -0800 | [diff] [blame] | 5295 | char buf[200]; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 5296 | int max, i; |
| 5297 | |
| 5298 | i = 0; |
| 5299 | max = sizeof(buf) - 1; |
| 5300 | |
| 5301 | i += scnprintf(buf + i, max - i, "STAT: %p %p %p\n", host->curr.mrq, |
| 5302 | host->curr.cmd, host->curr.data); |
| 5303 | if (host->curr.cmd) { |
| 5304 | struct mmc_command *cmd = host->curr.cmd; |
| 5305 | |
| 5306 | i += scnprintf(buf + i, max - i, "CMD : %.8x %.8x %.8x\n", |
| 5307 | cmd->opcode, cmd->arg, cmd->flags); |
| 5308 | } |
| 5309 | if (host->curr.data) { |
| 5310 | struct mmc_data *data = host->curr.data; |
| 5311 | i += scnprintf(buf + i, max - i, |
| 5312 | "DAT0: %.8x %.8x %.8x %.8x %.8x %.8x\n", |
| 5313 | data->timeout_ns, data->timeout_clks, |
| 5314 | data->blksz, data->blocks, data->error, |
| 5315 | data->flags); |
| 5316 | i += scnprintf(buf + i, max - i, "DAT1: %.8x %.8x %.8x %p\n", |
| 5317 | host->curr.xfer_size, host->curr.xfer_remain, |
| 5318 | host->curr.data_xfered, host->dma.sg); |
| 5319 | } |
| 5320 | |
| 5321 | return simple_read_from_buffer(ubuf, count, ppos, buf, i); |
| 5322 | } |
| 5323 | |
| 5324 | static const struct file_operations msmsdcc_dbg_state_ops = { |
| 5325 | .read = msmsdcc_dbg_state_read, |
| 5326 | .open = msmsdcc_dbg_state_open, |
| 5327 | }; |
| 5328 | |
| 5329 | static void msmsdcc_dbg_createhost(struct msmsdcc_host *host) |
| 5330 | { |
| 5331 | if (debugfs_dir) { |
| 5332 | debugfs_file = debugfs_create_file(mmc_hostname(host->mmc), |
| 5333 | 0644, debugfs_dir, host, |
| 5334 | &msmsdcc_dbg_state_ops); |
| 5335 | } |
| 5336 | } |
| 5337 | |
| 5338 | static int __init msmsdcc_dbg_init(void) |
| 5339 | { |
| 5340 | int err; |
| 5341 | |
| 5342 | debugfs_dir = debugfs_create_dir("msmsdcc", 0); |
| 5343 | if (IS_ERR(debugfs_dir)) { |
| 5344 | err = PTR_ERR(debugfs_dir); |
| 5345 | debugfs_dir = NULL; |
| 5346 | return err; |
| 5347 | } |
| 5348 | |
| 5349 | return 0; |
| 5350 | } |
| 5351 | #endif |