blob: 25624369e98d3b6e8ad1fbaf5fb504775cb48933 [file] [log] [blame]
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001/*
2 * linux/drivers/mmc/host/msm_sdcc_dml.c - Qualcomm MSM SDCC DML Driver
3 *
Duy Truong790f06d2013-02-13 16:38:12 -08004 * Copyright (c) 2011, The Linux Foundation. All rights reserved.
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07005 *
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 */
159int 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) {
Venkat Gopalakrishnan28ded7f2013-03-29 19:50:14 -0700169 pr_err("%s: DML ioremap() failed!!! %pr\n",
170 mmc_hostname(host->mmc), host->dml_memres);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700171 rc = -ENOMEM;
172 goto out;
173 }
Venkat Gopalakrishnan28ded7f2013-03-29 19:50:14 -0700174 pr_info("%s: Qualcomm MSM SDCC-DML %pr\n",
175 mmc_hostname(host->mmc), host->dml_memres);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700176 }
177
178 dml_base = host->dml_base;
179 /* Reset the DML block */
180 writel_relaxed(1, (dml_base + DML_SW_RESET));
181
182 /* Disable the producer and consumer CRCI */
183 config = (PRODUCER_CRCI_DIS | CONSUMER_CRCI_DIS);
184 /*
185 * Disable the bypass mode. Bypass mode will only be used
186 * if data transfer is to happen in PIO mode and don't
187 * want the BAM interface to connect with SDCC-DML.
188 */
189 config &= ~BYPASS;
190 /*
191 * Disable direct mode as we don't DML to MASTER the AHB bus.
192 * BAM connected with DML should MASTER the AHB bus.
193 */
194 config &= ~DIRECT_MODE;
195 /*
196 * Disable infinite mode transfer as we won't be doing any
197 * infinite size data transfers. All data transfer will be
198 * of finite data size.
199 */
200 config &= ~INFINITE_CONS_TRANS;
201 writel_relaxed(config, (dml_base + DML_CONFIG));
202
203 /*
204 * Initialize the logical BAM pipe size for producer
205 * and consumer.
206 */
207 writel_relaxed(PRODUCER_PIPE_LOGICAL_SIZE,
208 (dml_base + DML_PRODUCER_PIPE_LOGICAL_SIZE));
209 writel_relaxed(CONSUMER_PIPE_LOGICAL_SIZE,
210 (dml_base + DML_CONSUMER_PIPE_LOGICAL_SIZE));
211
212 /* Initialize Producer/consumer pipe id */
213 writel_relaxed(host->sps.src_pipe_index |
214 (host->sps.dest_pipe_index << CONSUMER_PIPE_ID_SHFT),
215 (dml_base + DML_PIPE_ID));
216 mb();
217out:
218 return rc;
219}
220
221/**
222 * Soft reset DML HW
223 *
224 */
225void msmsdcc_dml_reset(struct msmsdcc_host *host)
226{
227 /* Reset the DML block */
228 writel_relaxed(1, (host->dml_base + DML_SW_RESET));
229 mb();
230}
231
232/**
233 * Checks if DML HW is busy or not?
234 *
235 */
236bool msmsdcc_is_dml_busy(struct msmsdcc_host *host)
237{
238 return !(readl_relaxed(host->dml_base + DML_STATUS) & PRODUCER_IDLE) ||
239 !(readl_relaxed(host->dml_base + DML_STATUS) & CONSUMER_IDLE);
240}
241
242/**
243 * Start data transfer.
244 *
245 */
246void msmsdcc_dml_start_xfer(struct msmsdcc_host *host, struct mmc_data *data)
247{
248 u32 config;
249 void __iomem *dml_base = host->dml_base;
250
251 if (data->flags & MMC_DATA_READ) {
252 /* Read operation: configure DML for producer operation */
253 /* Set producer CRCI-x and disable consumer CRCI */
254 config = readl_relaxed(dml_base + DML_CONFIG);
255 config = (config & ~PRODUCER_CRCI_MSK) | PRODUCER_CRCI_X_SEL;
256 config = (config & ~CONSUMER_CRCI_MSK) | CONSUMER_CRCI_DIS;
257 writel_relaxed(config, (dml_base + DML_CONFIG));
258
259 /* Set the Producer BAM block size */
260 writel_relaxed(data->blksz, (dml_base +
261 DML_PRODUCER_BAM_BLOCK_SIZE));
262
263 /* Set Producer BAM Transaction size */
264 writel_relaxed(host->curr.xfer_size,
265 (dml_base + DML_PRODUCER_BAM_TRANS_SIZE));
266 /* Set Producer Transaction End bit */
267 writel_relaxed((readl_relaxed(dml_base + DML_CONFIG)
268 | PRODUCER_TRANS_END_EN),
269 (dml_base + DML_CONFIG));
270 /* Trigger producer */
271 writel_relaxed(1, (dml_base + DML_PRODUCER_START));
272 } else {
273 /* Write operation: configure DML for consumer operation */
274 /* Set consumer CRCI-x and disable producer CRCI*/
275 config = readl_relaxed(dml_base + DML_CONFIG);
276 config = (config & ~CONSUMER_CRCI_MSK) | CONSUMER_CRCI_X_SEL;
277 config = (config & ~PRODUCER_CRCI_MSK) | PRODUCER_CRCI_DIS;
278 writel_relaxed(config, (dml_base + DML_CONFIG));
279 /* Clear Producer Transaction End bit */
280 writel_relaxed((readl_relaxed(dml_base + DML_CONFIG)
281 & ~PRODUCER_TRANS_END_EN),
282 (dml_base + DML_CONFIG));
283 /* Trigger consumer */
284 writel_relaxed(1, (dml_base + DML_CONSUMER_START));
285 }
286 mb();
287}
288
289/**
290 * Deinitialize DML HW connected with SDCC core
291 *
292 */
293void msmsdcc_dml_exit(struct msmsdcc_host *host)
294{
295 /* Put DML block in reset state before exiting */
296 msmsdcc_dml_reset(host);
297 iounmap(host->dml_base);
298}
299#endif /* CONFIG_MMC_MSM_SPS_SUPPORT */