blob: c6acea9fcc7a5ccfc0f6c8d3183c606f4f342bef [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)
80
81#define MMCIDATACNT 0x030
82#define MMCISTATUS 0x034
83#define MCI_CMDCRCFAIL (1 << 0)
84#define MCI_DATACRCFAIL (1 << 1)
85#define MCI_CMDTIMEOUT (1 << 2)
86#define MCI_DATATIMEOUT (1 << 3)
87#define MCI_TXUNDERRUN (1 << 4)
88#define MCI_RXOVERRUN (1 << 5)
89#define MCI_CMDRESPEND (1 << 6)
90#define MCI_CMDSENT (1 << 7)
91#define MCI_DATAEND (1 << 8)
92#define MCI_DATABLOCKEND (1 << 10)
93#define MCI_CMDACTIVE (1 << 11)
94#define MCI_TXACTIVE (1 << 12)
95#define MCI_RXACTIVE (1 << 13)
96#define MCI_TXFIFOHALFEMPTY (1 << 14)
97#define MCI_RXFIFOHALFFULL (1 << 15)
98#define MCI_TXFIFOFULL (1 << 16)
99#define MCI_RXFIFOFULL (1 << 17)
100#define MCI_TXFIFOEMPTY (1 << 18)
101#define MCI_RXFIFOEMPTY (1 << 19)
102#define MCI_TXDATAAVLBL (1 << 20)
103#define MCI_RXDATAAVLBL (1 << 21)
104#define MCI_SDIOINTR (1 << 22)
105#define MCI_PROGDONE (1 << 23)
106#define MCI_ATACMDCOMPL (1 << 24)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700107#define MCI_SDIOINTROPE (1 << 25)
San Mehat9d2bd732009-09-22 16:44:22 -0700108#define MCI_CCSTIMEOUT (1 << 26)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700109#define MCI_AUTOCMD19TIMEOUT (1 << 30)
San Mehat9d2bd732009-09-22 16:44:22 -0700110
111#define MMCICLEAR 0x038
112#define MCI_CMDCRCFAILCLR (1 << 0)
113#define MCI_DATACRCFAILCLR (1 << 1)
114#define MCI_CMDTIMEOUTCLR (1 << 2)
115#define MCI_DATATIMEOUTCLR (1 << 3)
116#define MCI_TXUNDERRUNCLR (1 << 4)
117#define MCI_RXOVERRUNCLR (1 << 5)
118#define MCI_CMDRESPENDCLR (1 << 6)
119#define MCI_CMDSENTCLR (1 << 7)
120#define MCI_DATAENDCLR (1 << 8)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700121#define MCI_STARTBITERRCLR (1 << 9)
San Mehat9d2bd732009-09-22 16:44:22 -0700122#define MCI_DATABLOCKENDCLR (1 << 10)
123
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700124#define MCI_SDIOINTRCLR (1 << 22)
125#define MCI_PROGDONECLR (1 << 23)
126#define MCI_ATACMDCOMPLCLR (1 << 24)
127#define MCI_SDIOINTROPECLR (1 << 25)
128#define MCI_CCSTIMEOUTCLR (1 << 26)
129
130#define MCI_CLEAR_STATIC_MASK \
131 (MCI_CMDCRCFAILCLR|MCI_DATACRCFAILCLR|MCI_CMDTIMEOUTCLR|\
132 MCI_DATATIMEOUTCLR|MCI_TXUNDERRUNCLR|MCI_RXOVERRUNCLR| \
133 MCI_CMDRESPENDCLR|MCI_CMDSENTCLR|MCI_DATAENDCLR| \
134 MCI_STARTBITERRCLR|MCI_DATABLOCKENDCLR|MCI_SDIOINTRCLR| \
135 MCI_SDIOINTROPECLR|MCI_PROGDONECLR|MCI_ATACMDCOMPLCLR| \
136 MCI_CCSTIMEOUTCLR)
137
San Mehat9d2bd732009-09-22 16:44:22 -0700138#define MMCIMASK0 0x03c
139#define MCI_CMDCRCFAILMASK (1 << 0)
140#define MCI_DATACRCFAILMASK (1 << 1)
141#define MCI_CMDTIMEOUTMASK (1 << 2)
142#define MCI_DATATIMEOUTMASK (1 << 3)
143#define MCI_TXUNDERRUNMASK (1 << 4)
144#define MCI_RXOVERRUNMASK (1 << 5)
145#define MCI_CMDRESPENDMASK (1 << 6)
146#define MCI_CMDSENTMASK (1 << 7)
147#define MCI_DATAENDMASK (1 << 8)
148#define MCI_DATABLOCKENDMASK (1 << 10)
149#define MCI_CMDACTIVEMASK (1 << 11)
150#define MCI_TXACTIVEMASK (1 << 12)
151#define MCI_RXACTIVEMASK (1 << 13)
152#define MCI_TXFIFOHALFEMPTYMASK (1 << 14)
153#define MCI_RXFIFOHALFFULLMASK (1 << 15)
154#define MCI_TXFIFOFULLMASK (1 << 16)
155#define MCI_RXFIFOFULLMASK (1 << 17)
156#define MCI_TXFIFOEMPTYMASK (1 << 18)
157#define MCI_RXFIFOEMPTYMASK (1 << 19)
158#define MCI_TXDATAAVLBLMASK (1 << 20)
159#define MCI_RXDATAAVLBLMASK (1 << 21)
160#define MCI_SDIOINTMASK (1 << 22)
161#define MCI_PROGDONEMASK (1 << 23)
162#define MCI_ATACMDCOMPLMASK (1 << 24)
163#define MCI_SDIOINTOPERMASK (1 << 25)
164#define MCI_CCSTIMEOUTMASK (1 << 26)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700165#define MCI_AUTOCMD19TIMEOUTMASK (1 << 30)
San Mehat9d2bd732009-09-22 16:44:22 -0700166
167#define MMCIMASK1 0x040
168#define MMCIFIFOCNT 0x044
169#define MCICCSTIMER 0x058
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700170#define MCI_DLL_CONFIG 0x060
171#define MCI_DLL_EN (1 << 16)
172#define MCI_CDR_EN (1 << 17)
173#define MCI_CK_OUT_EN (1 << 18)
174#define MCI_CDR_EXT_EN (1 << 19)
175#define MCI_DLL_PDN (1 << 29)
176#define MCI_DLL_RST (1 << 30)
177
178#define MCI_DLL_STATUS 0x068
179#define MCI_DLL_LOCK (1 << 7)
San Mehat9d2bd732009-09-22 16:44:22 -0700180
181#define MMCIFIFO 0x080 /* to 0x0bc */
182
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700183#define MCI_TEST_INPUT 0x0D4
184
San Mehat9d2bd732009-09-22 16:44:22 -0700185#define MCI_IRQENABLE \
186 (MCI_CMDCRCFAILMASK|MCI_DATACRCFAILMASK|MCI_CMDTIMEOUTMASK| \
187 MCI_DATATIMEOUTMASK|MCI_TXUNDERRUNMASK|MCI_RXOVERRUNMASK| \
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700188 MCI_CMDRESPENDMASK|MCI_CMDSENTMASK|MCI_DATAENDMASK| \
189 MCI_PROGDONEMASK|MCI_AUTOCMD19TIMEOUTMASK)
190
191#define MCI_IRQ_PIO \
192 (MCI_RXDATAAVLBLMASK | MCI_TXDATAAVLBLMASK | \
193 MCI_RXFIFOEMPTYMASK | MCI_TXFIFOEMPTYMASK | MCI_RXFIFOFULLMASK |\
194 MCI_TXFIFOFULLMASK | MCI_RXFIFOHALFFULLMASK | \
195 MCI_TXFIFOHALFEMPTYMASK | MCI_RXACTIVEMASK | MCI_TXACTIVEMASK)
San Mehat9d2bd732009-09-22 16:44:22 -0700196
197/*
198 * The size of the FIFO in bytes.
199 */
200#define MCI_FIFOSIZE (16*4)
201
202#define MCI_FIFOHALFSIZE (MCI_FIFOSIZE / 2)
203
204#define NR_SG 32
205
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700206#define MSM_MMC_IDLE_TIMEOUT 10000 /* msecs */
207
208/*
209 * Set the request timeout to 10secs to allow
210 * bad cards/controller to respond.
211 */
212#define MSM_MMC_REQ_TIMEOUT 10000 /* msecs */
213
San Mehat9d2bd732009-09-22 16:44:22 -0700214struct clk;
215
216struct msmsdcc_nc_dmadata {
217 dmov_box cmd[NR_SG];
218 uint32_t cmdptr;
219};
220
221struct msmsdcc_dma_data {
222 struct msmsdcc_nc_dmadata *nc;
223 dma_addr_t nc_busaddr;
224 dma_addr_t cmd_busaddr;
225 dma_addr_t cmdptr_busaddr;
226
227 struct msm_dmov_cmd hdr;
228 enum dma_data_direction dir;
229
230 struct scatterlist *sg;
231 int num_ents;
232
233 int channel;
234 struct msmsdcc_host *host;
235 int busy; /* Set if DM is busy */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700236 unsigned int result;
Sahitya Tummala62612cf2010-12-08 15:03:03 +0530237 struct msm_dmov_errdata err;
San Mehat9d2bd732009-09-22 16:44:22 -0700238};
239
240struct msmsdcc_pio_data {
241 struct scatterlist *sg;
242 unsigned int sg_len;
243 unsigned int sg_off;
244};
245
246struct msmsdcc_curr_req {
247 struct mmc_request *mrq;
248 struct mmc_command *cmd;
249 struct mmc_data *data;
250 unsigned int xfer_size; /* Total data size */
251 unsigned int xfer_remain; /* Bytes remaining to send */
252 unsigned int data_xfered; /* Bytes acked by BLKEND irq */
253 int got_dataend;
San Mehat9d2bd732009-09-22 16:44:22 -0700254 int user_pages;
255};
256
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700257struct msmsdcc_sps_ep_conn_data {
258 struct sps_pipe *pipe_handle;
259 struct sps_connect config;
260 struct sps_register_event event;
261};
262
263struct msmsdcc_sps_data {
264 struct msmsdcc_sps_ep_conn_data prod;
265 struct msmsdcc_sps_ep_conn_data cons;
266 struct sps_event_notify notify;
267 enum dma_data_direction dir;
268 struct scatterlist *sg;
269 int num_ents;
270 u32 bam_handle;
271 unsigned int src_pipe_index;
272 unsigned int dest_pipe_index;
273 unsigned int busy;
274 unsigned int xfer_req_cnt;
275 struct tasklet_struct tlet;
276
San Mehat9d2bd732009-09-22 16:44:22 -0700277};
278
279struct msmsdcc_host {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700280 struct resource *core_irqres;
281 struct resource *bam_irqres;
282 struct resource *core_memres;
283 struct resource *bam_memres;
284 struct resource *dml_memres;
San Mehat9d2bd732009-09-22 16:44:22 -0700285 struct resource *dmares;
286 void __iomem *base;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700287 void __iomem *dml_base;
288 void __iomem *bam_base;
289
San Mehat9d2bd732009-09-22 16:44:22 -0700290 int pdev_id;
San Mehat9d2bd732009-09-22 16:44:22 -0700291
292 struct msmsdcc_curr_req curr;
293
294 struct mmc_host *mmc;
295 struct clk *clk; /* main MMC bus clock */
296 struct clk *pclk; /* SDCC peripheral bus clock */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700297 struct clk *dfab_pclk; /* Daytona Fabric SDCC clock */
San Mehat9d2bd732009-09-22 16:44:22 -0700298 unsigned int clks_on; /* set if clocks are enabled */
San Mehat9d2bd732009-09-22 16:44:22 -0700299
300 unsigned int eject; /* eject state */
301
302 spinlock_t lock;
303
304 unsigned int clk_rate; /* Current clock rate */
305 unsigned int pclk_rate;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700306 unsigned int ddr_doubled_clk_rate;
San Mehat9d2bd732009-09-22 16:44:22 -0700307
308 u32 pwr;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700309 struct mmc_platform_data *plat;
San Mehat9d2bd732009-09-22 16:44:22 -0700310
San Mehat9d2bd732009-09-22 16:44:22 -0700311 unsigned int oldstat;
312
313 struct msmsdcc_dma_data dma;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700314 struct msmsdcc_sps_data sps;
315 bool is_dma_mode;
316 bool is_sps_mode;
San Mehat9d2bd732009-09-22 16:44:22 -0700317 struct msmsdcc_pio_data pio;
San Mehat56a8b5b2009-11-21 12:29:46 -0800318
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700319#ifdef CONFIG_HAS_EARLYSUSPEND
320 struct early_suspend early_suspend;
321 int polling_enabled;
322#endif
323
324 struct tasklet_struct dma_tlet;
325
326 unsigned int prog_scan;
327 unsigned int prog_enable;
328
San Mehat56a8b5b2009-11-21 12:29:46 -0800329 /* Command parameters */
330 unsigned int cmd_timeout;
331 unsigned int cmd_pio_irqmask;
332 unsigned int cmd_datactrl;
333 struct mmc_command *cmd_cmd;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700334 u32 cmd_c;
San Mehat56a8b5b2009-11-21 12:29:46 -0800335
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700336 unsigned int mci_irqenable;
337 unsigned int dummy_52_needed;
338 unsigned int dummy_52_state;
339 unsigned int sdio_irq_disabled;
340 struct wake_lock sdio_wlock;
341 struct wake_lock sdio_suspend_wlock;
342 unsigned int sdcc_suspending;
343
344 unsigned int sdcc_irq_disabled;
345 struct timer_list req_tout_timer;
346 bool io_pad_pwr_switch;
347 bool cmd19_tuning_in_progress;
348 bool tuning_needed;
349 bool sdio_gpio_lpm;
350 bool irq_wake_enabled;
San Mehat9d2bd732009-09-22 16:44:22 -0700351};
352
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700353int msmsdcc_set_pwrsave(struct mmc_host *mmc, int pwrsave);
354int msmsdcc_sdio_al_lpm(struct mmc_host *mmc, bool enable);
355
356#ifdef CONFIG_MSM_SDIO_AL
357
358static inline int msmsdcc_lpm_enable(struct mmc_host *mmc)
359{
360 return msmsdcc_sdio_al_lpm(mmc, true);
361}
362
363static inline int msmsdcc_lpm_disable(struct mmc_host *mmc)
364{
365 return msmsdcc_sdio_al_lpm(mmc, false);
366}
367#endif
368
San Mehat9d2bd732009-09-22 16:44:22 -0700369#endif