blob: 31ece6e05953eb040a9823198af0b0233e5f7144 [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 Jadavani7a651aa2011-08-03 20:44:58 +053080#define MCI_AUTO_PROG_DONE (1 << 19)
Subhash Jadavani24fb7f82011-07-25 15:54:34 +053081#define MCI_RX_DATA_PEND (1 << 20)
San Mehat9d2bd732009-09-22 16:44:22 -070082
83#define MMCIDATACNT 0x030
84#define MMCISTATUS 0x034
85#define MCI_CMDCRCFAIL (1 << 0)
86#define MCI_DATACRCFAIL (1 << 1)
87#define MCI_CMDTIMEOUT (1 << 2)
88#define MCI_DATATIMEOUT (1 << 3)
89#define MCI_TXUNDERRUN (1 << 4)
90#define MCI_RXOVERRUN (1 << 5)
91#define MCI_CMDRESPEND (1 << 6)
92#define MCI_CMDSENT (1 << 7)
93#define MCI_DATAEND (1 << 8)
94#define MCI_DATABLOCKEND (1 << 10)
95#define MCI_CMDACTIVE (1 << 11)
96#define MCI_TXACTIVE (1 << 12)
97#define MCI_RXACTIVE (1 << 13)
98#define MCI_TXFIFOHALFEMPTY (1 << 14)
99#define MCI_RXFIFOHALFFULL (1 << 15)
100#define MCI_TXFIFOFULL (1 << 16)
101#define MCI_RXFIFOFULL (1 << 17)
102#define MCI_TXFIFOEMPTY (1 << 18)
103#define MCI_RXFIFOEMPTY (1 << 19)
104#define MCI_TXDATAAVLBL (1 << 20)
105#define MCI_RXDATAAVLBL (1 << 21)
106#define MCI_SDIOINTR (1 << 22)
107#define MCI_PROGDONE (1 << 23)
108#define MCI_ATACMDCOMPL (1 << 24)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700109#define MCI_SDIOINTROPE (1 << 25)
San Mehat9d2bd732009-09-22 16:44:22 -0700110#define MCI_CCSTIMEOUT (1 << 26)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700111#define MCI_AUTOCMD19TIMEOUT (1 << 30)
San Mehat9d2bd732009-09-22 16:44:22 -0700112
113#define MMCICLEAR 0x038
114#define MCI_CMDCRCFAILCLR (1 << 0)
115#define MCI_DATACRCFAILCLR (1 << 1)
116#define MCI_CMDTIMEOUTCLR (1 << 2)
117#define MCI_DATATIMEOUTCLR (1 << 3)
118#define MCI_TXUNDERRUNCLR (1 << 4)
119#define MCI_RXOVERRUNCLR (1 << 5)
120#define MCI_CMDRESPENDCLR (1 << 6)
121#define MCI_CMDSENTCLR (1 << 7)
122#define MCI_DATAENDCLR (1 << 8)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700123#define MCI_STARTBITERRCLR (1 << 9)
San Mehat9d2bd732009-09-22 16:44:22 -0700124#define MCI_DATABLOCKENDCLR (1 << 10)
125
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700126#define MCI_SDIOINTRCLR (1 << 22)
127#define MCI_PROGDONECLR (1 << 23)
128#define MCI_ATACMDCOMPLCLR (1 << 24)
129#define MCI_SDIOINTROPECLR (1 << 25)
130#define MCI_CCSTIMEOUTCLR (1 << 26)
131
132#define MCI_CLEAR_STATIC_MASK \
133 (MCI_CMDCRCFAILCLR|MCI_DATACRCFAILCLR|MCI_CMDTIMEOUTCLR|\
134 MCI_DATATIMEOUTCLR|MCI_TXUNDERRUNCLR|MCI_RXOVERRUNCLR| \
135 MCI_CMDRESPENDCLR|MCI_CMDSENTCLR|MCI_DATAENDCLR| \
136 MCI_STARTBITERRCLR|MCI_DATABLOCKENDCLR|MCI_SDIOINTRCLR| \
137 MCI_SDIOINTROPECLR|MCI_PROGDONECLR|MCI_ATACMDCOMPLCLR| \
138 MCI_CCSTIMEOUTCLR)
139
San Mehat9d2bd732009-09-22 16:44:22 -0700140#define MMCIMASK0 0x03c
141#define MCI_CMDCRCFAILMASK (1 << 0)
142#define MCI_DATACRCFAILMASK (1 << 1)
143#define MCI_CMDTIMEOUTMASK (1 << 2)
144#define MCI_DATATIMEOUTMASK (1 << 3)
145#define MCI_TXUNDERRUNMASK (1 << 4)
146#define MCI_RXOVERRUNMASK (1 << 5)
147#define MCI_CMDRESPENDMASK (1 << 6)
148#define MCI_CMDSENTMASK (1 << 7)
149#define MCI_DATAENDMASK (1 << 8)
150#define MCI_DATABLOCKENDMASK (1 << 10)
151#define MCI_CMDACTIVEMASK (1 << 11)
152#define MCI_TXACTIVEMASK (1 << 12)
153#define MCI_RXACTIVEMASK (1 << 13)
154#define MCI_TXFIFOHALFEMPTYMASK (1 << 14)
155#define MCI_RXFIFOHALFFULLMASK (1 << 15)
156#define MCI_TXFIFOFULLMASK (1 << 16)
157#define MCI_RXFIFOFULLMASK (1 << 17)
158#define MCI_TXFIFOEMPTYMASK (1 << 18)
159#define MCI_RXFIFOEMPTYMASK (1 << 19)
160#define MCI_TXDATAAVLBLMASK (1 << 20)
161#define MCI_RXDATAAVLBLMASK (1 << 21)
162#define MCI_SDIOINTMASK (1 << 22)
163#define MCI_PROGDONEMASK (1 << 23)
164#define MCI_ATACMDCOMPLMASK (1 << 24)
165#define MCI_SDIOINTOPERMASK (1 << 25)
166#define MCI_CCSTIMEOUTMASK (1 << 26)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700167#define MCI_AUTOCMD19TIMEOUTMASK (1 << 30)
San Mehat9d2bd732009-09-22 16:44:22 -0700168
169#define MMCIMASK1 0x040
170#define MMCIFIFOCNT 0x044
171#define MCICCSTIMER 0x058
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700172#define MCI_DLL_CONFIG 0x060
173#define MCI_DLL_EN (1 << 16)
174#define MCI_CDR_EN (1 << 17)
175#define MCI_CK_OUT_EN (1 << 18)
176#define MCI_CDR_EXT_EN (1 << 19)
177#define MCI_DLL_PDN (1 << 29)
178#define MCI_DLL_RST (1 << 30)
179
180#define MCI_DLL_STATUS 0x068
181#define MCI_DLL_LOCK (1 << 7)
San Mehat9d2bd732009-09-22 16:44:22 -0700182
Subhash Jadavani8f13e5b2011-08-04 21:15:11 +0530183#define MCI_STATUS2 0x06C
184#define MCI_MCLK_REG_WR_ACTIVE (1 << 0)
185
San Mehat9d2bd732009-09-22 16:44:22 -0700186#define MMCIFIFO 0x080 /* to 0x0bc */
187
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700188#define MCI_TEST_INPUT 0x0D4
189
San Mehat9d2bd732009-09-22 16:44:22 -0700190#define MCI_IRQENABLE \
191 (MCI_CMDCRCFAILMASK|MCI_DATACRCFAILMASK|MCI_CMDTIMEOUTMASK| \
192 MCI_DATATIMEOUTMASK|MCI_TXUNDERRUNMASK|MCI_RXOVERRUNMASK| \
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700193 MCI_CMDRESPENDMASK|MCI_CMDSENTMASK|MCI_DATAENDMASK| \
194 MCI_PROGDONEMASK|MCI_AUTOCMD19TIMEOUTMASK)
195
196#define MCI_IRQ_PIO \
197 (MCI_RXDATAAVLBLMASK | MCI_TXDATAAVLBLMASK | \
198 MCI_RXFIFOEMPTYMASK | MCI_TXFIFOEMPTYMASK | MCI_RXFIFOFULLMASK |\
199 MCI_TXFIFOFULLMASK | MCI_RXFIFOHALFFULLMASK | \
200 MCI_TXFIFOHALFEMPTYMASK | MCI_RXACTIVEMASK | MCI_TXACTIVEMASK)
San Mehat9d2bd732009-09-22 16:44:22 -0700201
202/*
203 * The size of the FIFO in bytes.
204 */
205#define MCI_FIFOSIZE (16*4)
206
207#define MCI_FIFOHALFSIZE (MCI_FIFOSIZE / 2)
208
209#define NR_SG 32
210
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700211#define MSM_MMC_IDLE_TIMEOUT 10000 /* msecs */
212
213/*
214 * Set the request timeout to 10secs to allow
215 * bad cards/controller to respond.
216 */
217#define MSM_MMC_REQ_TIMEOUT 10000 /* msecs */
218
San Mehat9d2bd732009-09-22 16:44:22 -0700219struct clk;
220
221struct msmsdcc_nc_dmadata {
222 dmov_box cmd[NR_SG];
223 uint32_t cmdptr;
224};
225
226struct msmsdcc_dma_data {
227 struct msmsdcc_nc_dmadata *nc;
228 dma_addr_t nc_busaddr;
229 dma_addr_t cmd_busaddr;
230 dma_addr_t cmdptr_busaddr;
231
232 struct msm_dmov_cmd hdr;
233 enum dma_data_direction dir;
234
235 struct scatterlist *sg;
236 int num_ents;
237
238 int channel;
Krishna Konda25786ec2011-07-25 16:21:36 -0700239 int crci;
San Mehat9d2bd732009-09-22 16:44:22 -0700240 struct msmsdcc_host *host;
241 int busy; /* Set if DM is busy */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700242 unsigned int result;
Sahitya Tummala62612cf2010-12-08 15:03:03 +0530243 struct msm_dmov_errdata err;
San Mehat9d2bd732009-09-22 16:44:22 -0700244};
245
246struct msmsdcc_pio_data {
247 struct scatterlist *sg;
248 unsigned int sg_len;
249 unsigned int sg_off;
250};
251
252struct msmsdcc_curr_req {
253 struct mmc_request *mrq;
254 struct mmc_command *cmd;
255 struct mmc_data *data;
256 unsigned int xfer_size; /* Total data size */
257 unsigned int xfer_remain; /* Bytes remaining to send */
258 unsigned int data_xfered; /* Bytes acked by BLKEND irq */
259 int got_dataend;
Subhash Jadavani7a651aa2011-08-03 20:44:58 +0530260 int wait_for_auto_prog_done;
261 int got_auto_prog_done;
San Mehat9d2bd732009-09-22 16:44:22 -0700262 int user_pages;
263};
264
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700265struct msmsdcc_sps_ep_conn_data {
266 struct sps_pipe *pipe_handle;
267 struct sps_connect config;
268 struct sps_register_event event;
269};
270
271struct msmsdcc_sps_data {
272 struct msmsdcc_sps_ep_conn_data prod;
273 struct msmsdcc_sps_ep_conn_data cons;
274 struct sps_event_notify notify;
275 enum dma_data_direction dir;
276 struct scatterlist *sg;
277 int num_ents;
278 u32 bam_handle;
279 unsigned int src_pipe_index;
280 unsigned int dest_pipe_index;
281 unsigned int busy;
282 unsigned int xfer_req_cnt;
Subhash Jadavanib5b07742011-08-29 17:48:07 +0530283 bool pipe_reset_pending;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700284 struct tasklet_struct tlet;
San Mehat9d2bd732009-09-22 16:44:22 -0700285};
286
287struct msmsdcc_host {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700288 struct resource *core_irqres;
289 struct resource *bam_irqres;
290 struct resource *core_memres;
291 struct resource *bam_memres;
292 struct resource *dml_memres;
San Mehat9d2bd732009-09-22 16:44:22 -0700293 struct resource *dmares;
Krishna Konda25786ec2011-07-25 16:21:36 -0700294 struct resource *dma_crci_res;
San Mehat9d2bd732009-09-22 16:44:22 -0700295 void __iomem *base;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700296 void __iomem *dml_base;
297 void __iomem *bam_base;
298
San Mehat9d2bd732009-09-22 16:44:22 -0700299 int pdev_id;
San Mehat9d2bd732009-09-22 16:44:22 -0700300
301 struct msmsdcc_curr_req curr;
302
303 struct mmc_host *mmc;
304 struct clk *clk; /* main MMC bus clock */
305 struct clk *pclk; /* SDCC peripheral bus clock */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700306 struct clk *dfab_pclk; /* Daytona Fabric SDCC clock */
San Mehat9d2bd732009-09-22 16:44:22 -0700307 unsigned int clks_on; /* set if clocks are enabled */
San Mehat9d2bd732009-09-22 16:44:22 -0700308
309 unsigned int eject; /* eject state */
310
311 spinlock_t lock;
312
313 unsigned int clk_rate; /* Current clock rate */
314 unsigned int pclk_rate;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700315 unsigned int ddr_doubled_clk_rate;
San Mehat9d2bd732009-09-22 16:44:22 -0700316
317 u32 pwr;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700318 struct mmc_platform_data *plat;
San Mehat9d2bd732009-09-22 16:44:22 -0700319
San Mehat9d2bd732009-09-22 16:44:22 -0700320 unsigned int oldstat;
321
322 struct msmsdcc_dma_data dma;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700323 struct msmsdcc_sps_data sps;
324 bool is_dma_mode;
325 bool is_sps_mode;
San Mehat9d2bd732009-09-22 16:44:22 -0700326 struct msmsdcc_pio_data pio;
San Mehat56a8b5b2009-11-21 12:29:46 -0800327
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700328#ifdef CONFIG_HAS_EARLYSUSPEND
329 struct early_suspend early_suspend;
330 int polling_enabled;
331#endif
332
333 struct tasklet_struct dma_tlet;
334
335 unsigned int prog_scan;
336 unsigned int prog_enable;
337
San Mehat56a8b5b2009-11-21 12:29:46 -0800338 /* Command parameters */
339 unsigned int cmd_timeout;
340 unsigned int cmd_pio_irqmask;
341 unsigned int cmd_datactrl;
342 struct mmc_command *cmd_cmd;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700343 u32 cmd_c;
San Mehat56a8b5b2009-11-21 12:29:46 -0800344
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700345 unsigned int mci_irqenable;
346 unsigned int dummy_52_needed;
Oluwafemi Adeyemicb791442011-07-11 22:51:25 -0700347 unsigned int dummy_52_sent;
348
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700349 unsigned int sdio_irq_disabled;
350 struct wake_lock sdio_wlock;
351 struct wake_lock sdio_suspend_wlock;
352 unsigned int sdcc_suspending;
353
354 unsigned int sdcc_irq_disabled;
355 struct timer_list req_tout_timer;
Sujith Reddy Thummac1824d52011-09-28 10:05:44 +0530356 unsigned long reg_write_delay;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700357 bool io_pad_pwr_switch;
358 bool cmd19_tuning_in_progress;
359 bool tuning_needed;
360 bool sdio_gpio_lpm;
361 bool irq_wake_enabled;
San Mehat9d2bd732009-09-22 16:44:22 -0700362};
363
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700364int msmsdcc_set_pwrsave(struct mmc_host *mmc, int pwrsave);
365int msmsdcc_sdio_al_lpm(struct mmc_host *mmc, bool enable);
366
367#ifdef CONFIG_MSM_SDIO_AL
368
369static inline int msmsdcc_lpm_enable(struct mmc_host *mmc)
370{
371 return msmsdcc_sdio_al_lpm(mmc, true);
372}
373
374static inline int msmsdcc_lpm_disable(struct mmc_host *mmc)
375{
376 return msmsdcc_sdio_al_lpm(mmc, false);
377}
378#endif
379
San Mehat9d2bd732009-09-22 16:44:22 -0700380#endif