Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1 | /* |
| 2 | * linux/drivers/mmc/host/msm_sdcc_dml.c - Qualcomm MSM SDCC DML Driver |
| 3 | * |
Duy Truong | 790f06d | 2013-02-13 16:38:12 -0800 | [diff] [blame^] | 4 | * Copyright (c) 2011, The Linux Foundation. All rights reserved. |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License version 2 and |
| 8 | * only version 2 as published by the Free Software Foundation. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
| 15 | */ |
| 16 | |
| 17 | #include <linux/io.h> |
| 18 | #include <asm/sizes.h> |
| 19 | #include <mach/msm_iomap.h> |
| 20 | |
| 21 | #include "msm_sdcc_dml.h" |
| 22 | |
| 23 | /* |
| 24 | * DML registers definations |
| 25 | */ |
| 26 | |
| 27 | /* DML config register defination */ |
| 28 | #define DML_CONFIG 0x0000 |
| 29 | #define PRODUCER_CRCI_DIS 0x00 |
| 30 | #define PRODUCER_CRCI_X_SEL 0x01 |
| 31 | #define PRODUCER_CRCI_Y_SEL 0x02 |
| 32 | #define PRODUCER_CRCI_MSK 0x3 |
| 33 | #define CONSUMER_CRCI_DIS (0x00 << 2) |
| 34 | #define CONSUMER_CRCI_X_SEL (0x01 << 2) |
| 35 | #define CONSUMER_CRCI_Y_SEL (0x02 << 2) |
| 36 | #define CONSUMER_CRCI_MSK (0x3 << 2) |
| 37 | #define PRODUCER_TRANS_END_EN (1 << 4) |
| 38 | #define BYPASS (1 << 16) |
| 39 | #define DIRECT_MODE (1 << 17) |
| 40 | #define INFINITE_CONS_TRANS (1 << 18) |
| 41 | |
| 42 | /* DML status register defination */ |
| 43 | #define DML_STATUS 0x0004 |
| 44 | #define PRODUCER_IDLE (1 << 0) |
| 45 | #define CONSUMER_IDLE (1 << 16) |
| 46 | |
| 47 | /* |
| 48 | * DML SW RESET register defination |
| 49 | * NOTE: write to this register resets the DML core. |
| 50 | * All internal state information will be lost and all |
| 51 | * register values will be reset as well |
| 52 | */ |
| 53 | #define DML_SW_RESET 0x0008 |
| 54 | |
| 55 | /* |
| 56 | * DML PRODUCER START register defination |
| 57 | * NOTE: A write to this register triggers the DML |
| 58 | * Producer state machine. No SW register values will be |
| 59 | * altered. |
| 60 | */ |
| 61 | #define DML_PRODUCER_START 0x000C |
| 62 | |
| 63 | /* |
| 64 | * DML CONSUMER START register defination |
| 65 | * NOTE: A write to this register triggers the DML |
| 66 | * Consumer state machine. No SW register values will be |
| 67 | * altered. |
| 68 | */ |
| 69 | #define DML_CONSUMER_START 0x0010 |
| 70 | |
| 71 | /* |
| 72 | * DML producer pipe logical size register defination |
| 73 | * NOTE: This register holds the size of the producer pipe |
| 74 | * (in units of bytes) _to_ which the peripheral can |
| 75 | * keep writing data to when its the PRODUCER. |
| 76 | */ |
| 77 | #define DML_PRODUCER_PIPE_LOGICAL_SIZE 0x0014 |
| 78 | |
| 79 | /* |
| 80 | * DML producer pipe logical size register defination |
| 81 | * NOTE: This register holds the size of the consumer pipe |
| 82 | * (in units of bytes) _from_ which the peripheral |
| 83 | * can keep _reading_ data from when its the CONSUMER. |
| 84 | */ |
| 85 | #define DML_CONSUMER_PIPE_LOGICAL_SIZE 0x00018 |
| 86 | |
| 87 | /* |
| 88 | * DML PIPE ID register |
| 89 | * This register holds pipe IDs that services |
| 90 | * the producer and consumer side of the peripheral |
| 91 | */ |
| 92 | #define DML_PIPE_ID 0x0001C |
| 93 | #define PRODUCER_PIPE_ID_SHFT 0 |
| 94 | #define PRODUCER_PIPE_ID_MSK 0x1f |
| 95 | #define CONSUMER_PIPE_ID_SHFT 16 |
| 96 | #define CONSUMER_PIPE_ID_MSK (0x1f << 16) |
| 97 | |
| 98 | /* |
| 99 | * DML Producer trackers register defination. |
| 100 | * This register is for debug purposes only. They reflect |
| 101 | * the value of the producer block and transaction counters |
| 102 | * when read. The values may be dynamically changing when |
| 103 | * a transaction is in progress. |
| 104 | */ |
| 105 | #define DML_PRODUCER_TRACKERS 0x00020 |
| 106 | #define PROD_BLOCK_CNT_SHFT 0 |
| 107 | #define PROD_BLOCK_CNT_MSK 0xffff |
| 108 | #define PROD_TRANS_CNT_SHFT 16 |
| 109 | #define PROD_TRANS_CNT_MSK (0xffff << 16) |
| 110 | |
| 111 | /* |
| 112 | * DML Producer BAM block size register defination. |
| 113 | * This regsiter holds the block size, in units of bytes, |
| 114 | * associated with the Producer BAM. The DML asserts the |
| 115 | * block_end side band signal to the BAM whenever the producer |
| 116 | * side of the peripheral has generated the said amount of data. |
| 117 | * This register value should be an integral multiple of the |
| 118 | * Producer CRCI Block Size. |
| 119 | */ |
| 120 | #define DML_PRODUCER_BAM_BLOCK_SIZE 0x00024 |
| 121 | |
| 122 | /* |
| 123 | * DML Producer BAM Transaction size defination. |
| 124 | * This regsiter holds the transaction size, in units of bytes, |
| 125 | * associated with the Producer BAM. The DML asserts the transaction_end |
| 126 | * side band signal to the BAM whenever the producer side of the peripheral |
| 127 | * has generated the said amount of data. |
| 128 | */ |
| 129 | #define DML_PRODUCER_BAM_TRANS_SIZE 0x00028 |
| 130 | |
| 131 | /* |
| 132 | * DML Direct mode base address defination |
| 133 | * This register is used whenever the DIRECT_MODE bit |
| 134 | * in config register is set. |
| 135 | */ |
| 136 | #define DML_DIRECT_MODE_BASE_ADDR 0x002C |
| 137 | #define PRODUCER_BASE_ADDR_BSHFT 0 |
| 138 | #define PRODUCER_BASE_ADDR_BMSK 0xffff |
| 139 | #define CONSUMER_BASE_ADDR_BSHFT 16 |
| 140 | #define CONSUMER_BASE_ADDR_BMSK (0xffff << 16) |
| 141 | |
| 142 | /* |
| 143 | * DMA Debug and status register defination. |
| 144 | * These are the read-only registers useful debugging. |
| 145 | */ |
| 146 | #define DML_DEBUG 0x0030 |
| 147 | #define DML_BAM_SIDE_STATUS_1 0x0034 |
| 148 | #define DML_BAM_SIDE_STATUS_2 0x0038 |
| 149 | |
| 150 | /* other definations */ |
| 151 | #define PRODUCER_PIPE_LOGICAL_SIZE 4096 |
| 152 | #define CONSUMER_PIPE_LOGICAL_SIZE 4096 |
| 153 | |
| 154 | #ifdef CONFIG_MMC_MSM_SPS_SUPPORT |
| 155 | /** |
| 156 | * Initialize DML HW connected with SDCC core |
| 157 | * |
| 158 | */ |
| 159 | int msmsdcc_dml_init(struct msmsdcc_host *host) |
| 160 | { |
| 161 | int rc = 0; |
| 162 | u32 config = 0; |
| 163 | void __iomem *dml_base; |
| 164 | |
| 165 | if (!host->dml_base) { |
| 166 | host->dml_base = ioremap(host->dml_memres->start, |
| 167 | resource_size(host->dml_memres)); |
| 168 | if (!host->dml_base) { |
| 169 | pr_err("%s: DML ioremap() failed!!! phys_addr=0x%x," |
| 170 | " size=0x%x", mmc_hostname(host->mmc), |
| 171 | host->dml_memres->start, |
| 172 | (host->dml_memres->end - |
| 173 | host->dml_memres->start)); |
| 174 | rc = -ENOMEM; |
| 175 | goto out; |
| 176 | } |
| 177 | pr_info("%s: Qualcomm MSM SDCC-DML at 0x%016llx\n", |
| 178 | mmc_hostname(host->mmc), |
| 179 | (unsigned long long)host->dml_memres->start); |
| 180 | } |
| 181 | |
| 182 | dml_base = host->dml_base; |
| 183 | /* Reset the DML block */ |
| 184 | writel_relaxed(1, (dml_base + DML_SW_RESET)); |
| 185 | |
| 186 | /* Disable the producer and consumer CRCI */ |
| 187 | config = (PRODUCER_CRCI_DIS | CONSUMER_CRCI_DIS); |
| 188 | /* |
| 189 | * Disable the bypass mode. Bypass mode will only be used |
| 190 | * if data transfer is to happen in PIO mode and don't |
| 191 | * want the BAM interface to connect with SDCC-DML. |
| 192 | */ |
| 193 | config &= ~BYPASS; |
| 194 | /* |
| 195 | * Disable direct mode as we don't DML to MASTER the AHB bus. |
| 196 | * BAM connected with DML should MASTER the AHB bus. |
| 197 | */ |
| 198 | config &= ~DIRECT_MODE; |
| 199 | /* |
| 200 | * Disable infinite mode transfer as we won't be doing any |
| 201 | * infinite size data transfers. All data transfer will be |
| 202 | * of finite data size. |
| 203 | */ |
| 204 | config &= ~INFINITE_CONS_TRANS; |
| 205 | writel_relaxed(config, (dml_base + DML_CONFIG)); |
| 206 | |
| 207 | /* |
| 208 | * Initialize the logical BAM pipe size for producer |
| 209 | * and consumer. |
| 210 | */ |
| 211 | writel_relaxed(PRODUCER_PIPE_LOGICAL_SIZE, |
| 212 | (dml_base + DML_PRODUCER_PIPE_LOGICAL_SIZE)); |
| 213 | writel_relaxed(CONSUMER_PIPE_LOGICAL_SIZE, |
| 214 | (dml_base + DML_CONSUMER_PIPE_LOGICAL_SIZE)); |
| 215 | |
| 216 | /* Initialize Producer/consumer pipe id */ |
| 217 | writel_relaxed(host->sps.src_pipe_index | |
| 218 | (host->sps.dest_pipe_index << CONSUMER_PIPE_ID_SHFT), |
| 219 | (dml_base + DML_PIPE_ID)); |
| 220 | mb(); |
| 221 | out: |
| 222 | return rc; |
| 223 | } |
| 224 | |
| 225 | /** |
| 226 | * Soft reset DML HW |
| 227 | * |
| 228 | */ |
| 229 | void msmsdcc_dml_reset(struct msmsdcc_host *host) |
| 230 | { |
| 231 | /* Reset the DML block */ |
| 232 | writel_relaxed(1, (host->dml_base + DML_SW_RESET)); |
| 233 | mb(); |
| 234 | } |
| 235 | |
| 236 | /** |
| 237 | * Checks if DML HW is busy or not? |
| 238 | * |
| 239 | */ |
| 240 | bool msmsdcc_is_dml_busy(struct msmsdcc_host *host) |
| 241 | { |
| 242 | return !(readl_relaxed(host->dml_base + DML_STATUS) & PRODUCER_IDLE) || |
| 243 | !(readl_relaxed(host->dml_base + DML_STATUS) & CONSUMER_IDLE); |
| 244 | } |
| 245 | |
| 246 | /** |
| 247 | * Start data transfer. |
| 248 | * |
| 249 | */ |
| 250 | void msmsdcc_dml_start_xfer(struct msmsdcc_host *host, struct mmc_data *data) |
| 251 | { |
| 252 | u32 config; |
| 253 | void __iomem *dml_base = host->dml_base; |
| 254 | |
| 255 | if (data->flags & MMC_DATA_READ) { |
| 256 | /* Read operation: configure DML for producer operation */ |
| 257 | /* Set producer CRCI-x and disable consumer CRCI */ |
| 258 | config = readl_relaxed(dml_base + DML_CONFIG); |
| 259 | config = (config & ~PRODUCER_CRCI_MSK) | PRODUCER_CRCI_X_SEL; |
| 260 | config = (config & ~CONSUMER_CRCI_MSK) | CONSUMER_CRCI_DIS; |
| 261 | writel_relaxed(config, (dml_base + DML_CONFIG)); |
| 262 | |
| 263 | /* Set the Producer BAM block size */ |
| 264 | writel_relaxed(data->blksz, (dml_base + |
| 265 | DML_PRODUCER_BAM_BLOCK_SIZE)); |
| 266 | |
| 267 | /* Set Producer BAM Transaction size */ |
| 268 | writel_relaxed(host->curr.xfer_size, |
| 269 | (dml_base + DML_PRODUCER_BAM_TRANS_SIZE)); |
| 270 | /* Set Producer Transaction End bit */ |
| 271 | writel_relaxed((readl_relaxed(dml_base + DML_CONFIG) |
| 272 | | PRODUCER_TRANS_END_EN), |
| 273 | (dml_base + DML_CONFIG)); |
| 274 | /* Trigger producer */ |
| 275 | writel_relaxed(1, (dml_base + DML_PRODUCER_START)); |
| 276 | } else { |
| 277 | /* Write operation: configure DML for consumer operation */ |
| 278 | /* Set consumer CRCI-x and disable producer CRCI*/ |
| 279 | config = readl_relaxed(dml_base + DML_CONFIG); |
| 280 | config = (config & ~CONSUMER_CRCI_MSK) | CONSUMER_CRCI_X_SEL; |
| 281 | config = (config & ~PRODUCER_CRCI_MSK) | PRODUCER_CRCI_DIS; |
| 282 | writel_relaxed(config, (dml_base + DML_CONFIG)); |
| 283 | /* Clear Producer Transaction End bit */ |
| 284 | writel_relaxed((readl_relaxed(dml_base + DML_CONFIG) |
| 285 | & ~PRODUCER_TRANS_END_EN), |
| 286 | (dml_base + DML_CONFIG)); |
| 287 | /* Trigger consumer */ |
| 288 | writel_relaxed(1, (dml_base + DML_CONSUMER_START)); |
| 289 | } |
| 290 | mb(); |
| 291 | } |
| 292 | |
| 293 | /** |
| 294 | * Deinitialize DML HW connected with SDCC core |
| 295 | * |
| 296 | */ |
| 297 | void msmsdcc_dml_exit(struct msmsdcc_host *host) |
| 298 | { |
| 299 | /* Put DML block in reset state before exiting */ |
| 300 | msmsdcc_dml_reset(host); |
| 301 | iounmap(host->dml_base); |
| 302 | } |
| 303 | #endif /* CONFIG_MMC_MSM_SPS_SUPPORT */ |