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