blob: 3ffe65f0f92e67d593cf4067f2eeeb36511204fe [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
182#define MMCIFIFO 0x080 /* to 0x0bc */
183
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700184#define MCI_TEST_INPUT 0x0D4
185
San Mehat9d2bd732009-09-22 16:44:22 -0700186#define MCI_IRQENABLE \
187 (MCI_CMDCRCFAILMASK|MCI_DATACRCFAILMASK|MCI_CMDTIMEOUTMASK| \
188 MCI_DATATIMEOUTMASK|MCI_TXUNDERRUNMASK|MCI_RXOVERRUNMASK| \
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700189 MCI_CMDRESPENDMASK|MCI_CMDSENTMASK|MCI_DATAENDMASK| \
190 MCI_PROGDONEMASK|MCI_AUTOCMD19TIMEOUTMASK)
191
192#define MCI_IRQ_PIO \
193 (MCI_RXDATAAVLBLMASK | MCI_TXDATAAVLBLMASK | \
194 MCI_RXFIFOEMPTYMASK | MCI_TXFIFOEMPTYMASK | MCI_RXFIFOFULLMASK |\
195 MCI_TXFIFOFULLMASK | MCI_RXFIFOHALFFULLMASK | \
196 MCI_TXFIFOHALFEMPTYMASK | MCI_RXACTIVEMASK | MCI_TXACTIVEMASK)
San Mehat9d2bd732009-09-22 16:44:22 -0700197
198/*
199 * The size of the FIFO in bytes.
200 */
201#define MCI_FIFOSIZE (16*4)
202
203#define MCI_FIFOHALFSIZE (MCI_FIFOSIZE / 2)
204
205#define NR_SG 32
206
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700207#define MSM_MMC_IDLE_TIMEOUT 10000 /* msecs */
208
209/*
210 * Set the request timeout to 10secs to allow
211 * bad cards/controller to respond.
212 */
213#define MSM_MMC_REQ_TIMEOUT 10000 /* msecs */
214
San Mehat9d2bd732009-09-22 16:44:22 -0700215struct clk;
216
217struct msmsdcc_nc_dmadata {
218 dmov_box cmd[NR_SG];
219 uint32_t cmdptr;
220};
221
222struct msmsdcc_dma_data {
223 struct msmsdcc_nc_dmadata *nc;
224 dma_addr_t nc_busaddr;
225 dma_addr_t cmd_busaddr;
226 dma_addr_t cmdptr_busaddr;
227
228 struct msm_dmov_cmd hdr;
229 enum dma_data_direction dir;
230
231 struct scatterlist *sg;
232 int num_ents;
233
234 int channel;
235 struct msmsdcc_host *host;
236 int busy; /* Set if DM is busy */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700237 unsigned int result;
Sahitya Tummala62612cf2010-12-08 15:03:03 +0530238 struct msm_dmov_errdata err;
San Mehat9d2bd732009-09-22 16:44:22 -0700239};
240
241struct msmsdcc_pio_data {
242 struct scatterlist *sg;
243 unsigned int sg_len;
244 unsigned int sg_off;
245};
246
247struct msmsdcc_curr_req {
248 struct mmc_request *mrq;
249 struct mmc_command *cmd;
250 struct mmc_data *data;
251 unsigned int xfer_size; /* Total data size */
252 unsigned int xfer_remain; /* Bytes remaining to send */
253 unsigned int data_xfered; /* Bytes acked by BLKEND irq */
254 int got_dataend;
San Mehat9d2bd732009-09-22 16:44:22 -0700255 int user_pages;
256};
257
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700258struct msmsdcc_sps_ep_conn_data {
259 struct sps_pipe *pipe_handle;
260 struct sps_connect config;
261 struct sps_register_event event;
262};
263
264struct msmsdcc_sps_data {
265 struct msmsdcc_sps_ep_conn_data prod;
266 struct msmsdcc_sps_ep_conn_data cons;
267 struct sps_event_notify notify;
268 enum dma_data_direction dir;
269 struct scatterlist *sg;
270 int num_ents;
271 u32 bam_handle;
272 unsigned int src_pipe_index;
273 unsigned int dest_pipe_index;
274 unsigned int busy;
275 unsigned int xfer_req_cnt;
276 struct tasklet_struct tlet;
277
San Mehat9d2bd732009-09-22 16:44:22 -0700278};
279
280struct msmsdcc_host {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700281 struct resource *core_irqres;
282 struct resource *bam_irqres;
283 struct resource *core_memres;
284 struct resource *bam_memres;
285 struct resource *dml_memres;
San Mehat9d2bd732009-09-22 16:44:22 -0700286 struct resource *dmares;
287 void __iomem *base;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700288 void __iomem *dml_base;
289 void __iomem *bam_base;
290
San Mehat9d2bd732009-09-22 16:44:22 -0700291 int pdev_id;
San Mehat9d2bd732009-09-22 16:44:22 -0700292
293 struct msmsdcc_curr_req curr;
294
295 struct mmc_host *mmc;
296 struct clk *clk; /* main MMC bus clock */
297 struct clk *pclk; /* SDCC peripheral bus clock */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700298 struct clk *dfab_pclk; /* Daytona Fabric SDCC clock */
San Mehat9d2bd732009-09-22 16:44:22 -0700299 unsigned int clks_on; /* set if clocks are enabled */
San Mehat9d2bd732009-09-22 16:44:22 -0700300
301 unsigned int eject; /* eject state */
302
303 spinlock_t lock;
304
305 unsigned int clk_rate; /* Current clock rate */
306 unsigned int pclk_rate;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700307 unsigned int ddr_doubled_clk_rate;
San Mehat9d2bd732009-09-22 16:44:22 -0700308
309 u32 pwr;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700310 struct mmc_platform_data *plat;
San Mehat9d2bd732009-09-22 16:44:22 -0700311
San Mehat9d2bd732009-09-22 16:44:22 -0700312 unsigned int oldstat;
313
314 struct msmsdcc_dma_data dma;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700315 struct msmsdcc_sps_data sps;
316 bool is_dma_mode;
317 bool is_sps_mode;
San Mehat9d2bd732009-09-22 16:44:22 -0700318 struct msmsdcc_pio_data pio;
San Mehat56a8b5b2009-11-21 12:29:46 -0800319
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700320#ifdef CONFIG_HAS_EARLYSUSPEND
321 struct early_suspend early_suspend;
322 int polling_enabled;
323#endif
324
325 struct tasklet_struct dma_tlet;
326
327 unsigned int prog_scan;
328 unsigned int prog_enable;
329
San Mehat56a8b5b2009-11-21 12:29:46 -0800330 /* Command parameters */
331 unsigned int cmd_timeout;
332 unsigned int cmd_pio_irqmask;
333 unsigned int cmd_datactrl;
334 struct mmc_command *cmd_cmd;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700335 u32 cmd_c;
San Mehat56a8b5b2009-11-21 12:29:46 -0800336
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700337 unsigned int mci_irqenable;
338 unsigned int dummy_52_needed;
Oluwafemi Adeyemicb791442011-07-11 22:51:25 -0700339 unsigned int dummy_52_sent;
340
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700341 unsigned int sdio_irq_disabled;
342 struct wake_lock sdio_wlock;
343 struct wake_lock sdio_suspend_wlock;
344 unsigned int sdcc_suspending;
345
346 unsigned int sdcc_irq_disabled;
347 struct timer_list req_tout_timer;
348 bool io_pad_pwr_switch;
349 bool cmd19_tuning_in_progress;
350 bool tuning_needed;
351 bool sdio_gpio_lpm;
352 bool irq_wake_enabled;
San Mehat9d2bd732009-09-22 16:44:22 -0700353};
354
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700355int msmsdcc_set_pwrsave(struct mmc_host *mmc, int pwrsave);
356int msmsdcc_sdio_al_lpm(struct mmc_host *mmc, bool enable);
357
358#ifdef CONFIG_MSM_SDIO_AL
359
360static inline int msmsdcc_lpm_enable(struct mmc_host *mmc)
361{
362 return msmsdcc_sdio_al_lpm(mmc, true);
363}
364
365static inline int msmsdcc_lpm_disable(struct mmc_host *mmc)
366{
367 return msmsdcc_sdio_al_lpm(mmc, false);
368}
369#endif
370
San Mehat9d2bd732009-09-22 16:44:22 -0700371#endif