blob: f6f76ff2f675de86161d1075a7eb74a077624de4 [file] [log] [blame]
San Mehat9d2bd732009-09-22 16:44:22 -07001/*
2 * linux/drivers/mmc/host/msmsdcc.h - QCT MSM7K SDC Controller
3 *
4 * Copyright (C) 2008 Google, All Rights Reserved.
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07005 * Copyright (c) 2009-2011, Code Aurora Forum. All rights reserved.
San Mehat9d2bd732009-09-22 16:44:22 -07006 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 *
11 * - Based on mmci.h
12 */
13
14#ifndef _MSM_SDCC_H
15#define _MSM_SDCC_H
16
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070017#include <linux/types.h>
18
19#include <linux/ioport.h>
20#include <linux/interrupt.h>
21#include <linux/mmc/host.h>
22#include <linux/mmc/card.h>
23#include <linux/mmc/mmc.h>
24#include <linux/mmc/sdio.h>
25#include <linux/scatterlist.h>
26#include <linux/dma-mapping.h>
27#include <linux/wakelock.h>
28#include <linux/earlysuspend.h>
29#include <mach/sps.h>
30
31#include <asm/sizes.h>
32#include <asm/mach/mmc.h>
33#include <mach/dma.h>
San Mehat9d2bd732009-09-22 16:44:22 -070034
35#define MMCIPOWER 0x000
36#define MCI_PWR_OFF 0x00
37#define MCI_PWR_UP 0x02
38#define MCI_PWR_ON 0x03
39#define MCI_OD (1 << 6)
40
41#define MMCICLOCK 0x004
42#define MCI_CLK_ENABLE (1 << 8)
43#define MCI_CLK_PWRSAVE (1 << 9)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070044#define MCI_CLK_WIDEBUS_1 (0 << 10)
45#define MCI_CLK_WIDEBUS_4 (2 << 10)
46#define MCI_CLK_WIDEBUS_8 (3 << 10)
San Mehat9d2bd732009-09-22 16:44:22 -070047#define MCI_CLK_FLOWENA (1 << 12)
48#define MCI_CLK_INVERTOUT (1 << 13)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070049#define MCI_CLK_SELECTIN (1 << 15)
50#define IO_PAD_PWR_SWITCH (1 << 21)
San Mehat9d2bd732009-09-22 16:44:22 -070051
52#define MMCIARGUMENT 0x008
53#define MMCICOMMAND 0x00c
54#define MCI_CPSM_RESPONSE (1 << 6)
55#define MCI_CPSM_LONGRSP (1 << 7)
56#define MCI_CPSM_INTERRUPT (1 << 8)
57#define MCI_CPSM_PENDING (1 << 9)
58#define MCI_CPSM_ENABLE (1 << 10)
59#define MCI_CPSM_PROGENA (1 << 11)
60#define MCI_CSPM_DATCMD (1 << 12)
61#define MCI_CSPM_MCIABORT (1 << 13)
62#define MCI_CSPM_CCSENABLE (1 << 14)
63#define MCI_CSPM_CCSDISABLE (1 << 15)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070064#define MCI_CSPM_AUTO_CMD19 (1 << 16)
San Mehat9d2bd732009-09-22 16:44:22 -070065
66
67#define MMCIRESPCMD 0x010
68#define MMCIRESPONSE0 0x014
69#define MMCIRESPONSE1 0x018
70#define MMCIRESPONSE2 0x01c
71#define MMCIRESPONSE3 0x020
72#define MMCIDATATIMER 0x024
73#define MMCIDATALENGTH 0x028
74
75#define MMCIDATACTRL 0x02c
76#define MCI_DPSM_ENABLE (1 << 0)
77#define MCI_DPSM_DIRECTION (1 << 1)
78#define MCI_DPSM_MODE (1 << 2)
79#define MCI_DPSM_DMAENABLE (1 << 3)
Subhash Jadavani24fb7f82011-07-25 15:54:34 +053080#define MCI_RX_DATA_PEND (1 << 20)
San Mehat9d2bd732009-09-22 16:44:22 -070081
82#define MMCIDATACNT 0x030
83#define MMCISTATUS 0x034
84#define MCI_CMDCRCFAIL (1 << 0)
85#define MCI_DATACRCFAIL (1 << 1)
86#define MCI_CMDTIMEOUT (1 << 2)
87#define MCI_DATATIMEOUT (1 << 3)
88#define MCI_TXUNDERRUN (1 << 4)
89#define MCI_RXOVERRUN (1 << 5)
90#define MCI_CMDRESPEND (1 << 6)
91#define MCI_CMDSENT (1 << 7)
92#define MCI_DATAEND (1 << 8)
93#define MCI_DATABLOCKEND (1 << 10)
94#define MCI_CMDACTIVE (1 << 11)
95#define MCI_TXACTIVE (1 << 12)
96#define MCI_RXACTIVE (1 << 13)
97#define MCI_TXFIFOHALFEMPTY (1 << 14)
98#define MCI_RXFIFOHALFFULL (1 << 15)
99#define MCI_TXFIFOFULL (1 << 16)
100#define MCI_RXFIFOFULL (1 << 17)
101#define MCI_TXFIFOEMPTY (1 << 18)
102#define MCI_RXFIFOEMPTY (1 << 19)
103#define MCI_TXDATAAVLBL (1 << 20)
104#define MCI_RXDATAAVLBL (1 << 21)
105#define MCI_SDIOINTR (1 << 22)
106#define MCI_PROGDONE (1 << 23)
107#define MCI_ATACMDCOMPL (1 << 24)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700108#define MCI_SDIOINTROPE (1 << 25)
San Mehat9d2bd732009-09-22 16:44:22 -0700109#define MCI_CCSTIMEOUT (1 << 26)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700110#define MCI_AUTOCMD19TIMEOUT (1 << 30)
San Mehat9d2bd732009-09-22 16:44:22 -0700111
112#define MMCICLEAR 0x038
113#define MCI_CMDCRCFAILCLR (1 << 0)
114#define MCI_DATACRCFAILCLR (1 << 1)
115#define MCI_CMDTIMEOUTCLR (1 << 2)
116#define MCI_DATATIMEOUTCLR (1 << 3)
117#define MCI_TXUNDERRUNCLR (1 << 4)
118#define MCI_RXOVERRUNCLR (1 << 5)
119#define MCI_CMDRESPENDCLR (1 << 6)
120#define MCI_CMDSENTCLR (1 << 7)
121#define MCI_DATAENDCLR (1 << 8)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700122#define MCI_STARTBITERRCLR (1 << 9)
San Mehat9d2bd732009-09-22 16:44:22 -0700123#define MCI_DATABLOCKENDCLR (1 << 10)
124
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700125#define MCI_SDIOINTRCLR (1 << 22)
126#define MCI_PROGDONECLR (1 << 23)
127#define MCI_ATACMDCOMPLCLR (1 << 24)
128#define MCI_SDIOINTROPECLR (1 << 25)
129#define MCI_CCSTIMEOUTCLR (1 << 26)
130
131#define MCI_CLEAR_STATIC_MASK \
132 (MCI_CMDCRCFAILCLR|MCI_DATACRCFAILCLR|MCI_CMDTIMEOUTCLR|\
133 MCI_DATATIMEOUTCLR|MCI_TXUNDERRUNCLR|MCI_RXOVERRUNCLR| \
134 MCI_CMDRESPENDCLR|MCI_CMDSENTCLR|MCI_DATAENDCLR| \
135 MCI_STARTBITERRCLR|MCI_DATABLOCKENDCLR|MCI_SDIOINTRCLR| \
136 MCI_SDIOINTROPECLR|MCI_PROGDONECLR|MCI_ATACMDCOMPLCLR| \
137 MCI_CCSTIMEOUTCLR)
138
San Mehat9d2bd732009-09-22 16:44:22 -0700139#define MMCIMASK0 0x03c
140#define MCI_CMDCRCFAILMASK (1 << 0)
141#define MCI_DATACRCFAILMASK (1 << 1)
142#define MCI_CMDTIMEOUTMASK (1 << 2)
143#define MCI_DATATIMEOUTMASK (1 << 3)
144#define MCI_TXUNDERRUNMASK (1 << 4)
145#define MCI_RXOVERRUNMASK (1 << 5)
146#define MCI_CMDRESPENDMASK (1 << 6)
147#define MCI_CMDSENTMASK (1 << 7)
148#define MCI_DATAENDMASK (1 << 8)
149#define MCI_DATABLOCKENDMASK (1 << 10)
150#define MCI_CMDACTIVEMASK (1 << 11)
151#define MCI_TXACTIVEMASK (1 << 12)
152#define MCI_RXACTIVEMASK (1 << 13)
153#define MCI_TXFIFOHALFEMPTYMASK (1 << 14)
154#define MCI_RXFIFOHALFFULLMASK (1 << 15)
155#define MCI_TXFIFOFULLMASK (1 << 16)
156#define MCI_RXFIFOFULLMASK (1 << 17)
157#define MCI_TXFIFOEMPTYMASK (1 << 18)
158#define MCI_RXFIFOEMPTYMASK (1 << 19)
159#define MCI_TXDATAAVLBLMASK (1 << 20)
160#define MCI_RXDATAAVLBLMASK (1 << 21)
161#define MCI_SDIOINTMASK (1 << 22)
162#define MCI_PROGDONEMASK (1 << 23)
163#define MCI_ATACMDCOMPLMASK (1 << 24)
164#define MCI_SDIOINTOPERMASK (1 << 25)
165#define MCI_CCSTIMEOUTMASK (1 << 26)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700166#define MCI_AUTOCMD19TIMEOUTMASK (1 << 30)
San Mehat9d2bd732009-09-22 16:44:22 -0700167
168#define MMCIMASK1 0x040
169#define MMCIFIFOCNT 0x044
170#define MCICCSTIMER 0x058
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700171#define MCI_DLL_CONFIG 0x060
172#define MCI_DLL_EN (1 << 16)
173#define MCI_CDR_EN (1 << 17)
174#define MCI_CK_OUT_EN (1 << 18)
175#define MCI_CDR_EXT_EN (1 << 19)
176#define MCI_DLL_PDN (1 << 29)
177#define MCI_DLL_RST (1 << 30)
178
179#define MCI_DLL_STATUS 0x068
180#define MCI_DLL_LOCK (1 << 7)
San Mehat9d2bd732009-09-22 16:44:22 -0700181
Subhash Jadavani8f13e5b2011-08-04 21:15:11 +0530182#define MCI_STATUS2 0x06C
183#define MCI_MCLK_REG_WR_ACTIVE (1 << 0)
184
San Mehat9d2bd732009-09-22 16:44:22 -0700185#define MMCIFIFO 0x080 /* to 0x0bc */
186
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700187#define MCI_TEST_INPUT 0x0D4
188
San Mehat9d2bd732009-09-22 16:44:22 -0700189#define MCI_IRQENABLE \
190 (MCI_CMDCRCFAILMASK|MCI_DATACRCFAILMASK|MCI_CMDTIMEOUTMASK| \
191 MCI_DATATIMEOUTMASK|MCI_TXUNDERRUNMASK|MCI_RXOVERRUNMASK| \
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700192 MCI_CMDRESPENDMASK|MCI_CMDSENTMASK|MCI_DATAENDMASK| \
193 MCI_PROGDONEMASK|MCI_AUTOCMD19TIMEOUTMASK)
194
195#define MCI_IRQ_PIO \
196 (MCI_RXDATAAVLBLMASK | MCI_TXDATAAVLBLMASK | \
197 MCI_RXFIFOEMPTYMASK | MCI_TXFIFOEMPTYMASK | MCI_RXFIFOFULLMASK |\
198 MCI_TXFIFOFULLMASK | MCI_RXFIFOHALFFULLMASK | \
199 MCI_TXFIFOHALFEMPTYMASK | MCI_RXACTIVEMASK | MCI_TXACTIVEMASK)
San Mehat9d2bd732009-09-22 16:44:22 -0700200
201/*
202 * The size of the FIFO in bytes.
203 */
204#define MCI_FIFOSIZE (16*4)
205
206#define MCI_FIFOHALFSIZE (MCI_FIFOSIZE / 2)
207
208#define NR_SG 32
209
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700210#define MSM_MMC_IDLE_TIMEOUT 10000 /* msecs */
211
212/*
213 * Set the request timeout to 10secs to allow
214 * bad cards/controller to respond.
215 */
216#define MSM_MMC_REQ_TIMEOUT 10000 /* msecs */
217
San Mehat9d2bd732009-09-22 16:44:22 -0700218struct clk;
219
220struct msmsdcc_nc_dmadata {
221 dmov_box cmd[NR_SG];
222 uint32_t cmdptr;
223};
224
225struct msmsdcc_dma_data {
226 struct msmsdcc_nc_dmadata *nc;
227 dma_addr_t nc_busaddr;
228 dma_addr_t cmd_busaddr;
229 dma_addr_t cmdptr_busaddr;
230
231 struct msm_dmov_cmd hdr;
232 enum dma_data_direction dir;
233
234 struct scatterlist *sg;
235 int num_ents;
236
237 int channel;
Krishna Konda25786ec2011-07-25 16:21:36 -0700238 int crci;
San Mehat9d2bd732009-09-22 16:44:22 -0700239 struct msmsdcc_host *host;
240 int busy; /* Set if DM is busy */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700241 unsigned int result;
Sahitya Tummala62612cf2010-12-08 15:03:03 +0530242 struct msm_dmov_errdata err;
San Mehat9d2bd732009-09-22 16:44:22 -0700243};
244
245struct msmsdcc_pio_data {
246 struct scatterlist *sg;
247 unsigned int sg_len;
248 unsigned int sg_off;
249};
250
251struct msmsdcc_curr_req {
252 struct mmc_request *mrq;
253 struct mmc_command *cmd;
254 struct mmc_data *data;
255 unsigned int xfer_size; /* Total data size */
256 unsigned int xfer_remain; /* Bytes remaining to send */
257 unsigned int data_xfered; /* Bytes acked by BLKEND irq */
258 int got_dataend;
San Mehat9d2bd732009-09-22 16:44:22 -0700259 int user_pages;
260};
261
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700262struct msmsdcc_sps_ep_conn_data {
263 struct sps_pipe *pipe_handle;
264 struct sps_connect config;
265 struct sps_register_event event;
266};
267
268struct msmsdcc_sps_data {
269 struct msmsdcc_sps_ep_conn_data prod;
270 struct msmsdcc_sps_ep_conn_data cons;
271 struct sps_event_notify notify;
272 enum dma_data_direction dir;
273 struct scatterlist *sg;
274 int num_ents;
275 u32 bam_handle;
276 unsigned int src_pipe_index;
277 unsigned int dest_pipe_index;
278 unsigned int busy;
279 unsigned int xfer_req_cnt;
280 struct tasklet_struct tlet;
281
San Mehat9d2bd732009-09-22 16:44:22 -0700282};
283
284struct msmsdcc_host {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700285 struct resource *core_irqres;
286 struct resource *bam_irqres;
287 struct resource *core_memres;
288 struct resource *bam_memres;
289 struct resource *dml_memres;
San Mehat9d2bd732009-09-22 16:44:22 -0700290 struct resource *dmares;
Krishna Konda25786ec2011-07-25 16:21:36 -0700291 struct resource *dma_crci_res;
San Mehat9d2bd732009-09-22 16:44:22 -0700292 void __iomem *base;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700293 void __iomem *dml_base;
294 void __iomem *bam_base;
295
San Mehat9d2bd732009-09-22 16:44:22 -0700296 int pdev_id;
San Mehat9d2bd732009-09-22 16:44:22 -0700297
298 struct msmsdcc_curr_req curr;
299
300 struct mmc_host *mmc;
301 struct clk *clk; /* main MMC bus clock */
302 struct clk *pclk; /* SDCC peripheral bus clock */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700303 struct clk *dfab_pclk; /* Daytona Fabric SDCC clock */
San Mehat9d2bd732009-09-22 16:44:22 -0700304 unsigned int clks_on; /* set if clocks are enabled */
San Mehat9d2bd732009-09-22 16:44:22 -0700305
306 unsigned int eject; /* eject state */
307
308 spinlock_t lock;
309
310 unsigned int clk_rate; /* Current clock rate */
311 unsigned int pclk_rate;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700312 unsigned int ddr_doubled_clk_rate;
San Mehat9d2bd732009-09-22 16:44:22 -0700313
314 u32 pwr;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700315 struct mmc_platform_data *plat;
San Mehat9d2bd732009-09-22 16:44:22 -0700316
San Mehat9d2bd732009-09-22 16:44:22 -0700317 unsigned int oldstat;
318
319 struct msmsdcc_dma_data dma;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700320 struct msmsdcc_sps_data sps;
321 bool is_dma_mode;
322 bool is_sps_mode;
San Mehat9d2bd732009-09-22 16:44:22 -0700323 struct msmsdcc_pio_data pio;
San Mehat56a8b5b2009-11-21 12:29:46 -0800324
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700325#ifdef CONFIG_HAS_EARLYSUSPEND
326 struct early_suspend early_suspend;
327 int polling_enabled;
328#endif
329
330 struct tasklet_struct dma_tlet;
331
332 unsigned int prog_scan;
333 unsigned int prog_enable;
334
San Mehat56a8b5b2009-11-21 12:29:46 -0800335 /* Command parameters */
336 unsigned int cmd_timeout;
337 unsigned int cmd_pio_irqmask;
338 unsigned int cmd_datactrl;
339 struct mmc_command *cmd_cmd;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700340 u32 cmd_c;
San Mehat56a8b5b2009-11-21 12:29:46 -0800341
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700342 unsigned int mci_irqenable;
343 unsigned int dummy_52_needed;
Oluwafemi Adeyemicb791442011-07-11 22:51:25 -0700344 unsigned int dummy_52_sent;
345
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700346 unsigned int sdio_irq_disabled;
347 struct wake_lock sdio_wlock;
348 struct wake_lock sdio_suspend_wlock;
349 unsigned int sdcc_suspending;
350
351 unsigned int sdcc_irq_disabled;
352 struct timer_list req_tout_timer;
353 bool io_pad_pwr_switch;
354 bool cmd19_tuning_in_progress;
355 bool tuning_needed;
356 bool sdio_gpio_lpm;
357 bool irq_wake_enabled;
San Mehat9d2bd732009-09-22 16:44:22 -0700358};
359
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700360int msmsdcc_set_pwrsave(struct mmc_host *mmc, int pwrsave);
361int msmsdcc_sdio_al_lpm(struct mmc_host *mmc, bool enable);
362
363#ifdef CONFIG_MSM_SDIO_AL
364
365static inline int msmsdcc_lpm_enable(struct mmc_host *mmc)
366{
367 return msmsdcc_sdio_al_lpm(mmc, true);
368}
369
370static inline int msmsdcc_lpm_disable(struct mmc_host *mmc)
371{
372 return msmsdcc_sdio_al_lpm(mmc, false);
373}
374#endif
375
San Mehat9d2bd732009-09-22 16:44:22 -0700376#endif