blob: 57794913aa461ff29d0a59ea317bd68b51c91fa0 [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.
Subhash Jadavani56e0eaa2012-03-13 18:06:04 +05305 * Copyright (c) 2009-2012, 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>
Steve Mucklef132c6c2012-06-06 18:30:57 -070029#include <linux/pm_qos.h>
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070030#include <mach/sps.h>
31
32#include <asm/sizes.h>
33#include <asm/mach/mmc.h>
34#include <mach/dma.h>
San Mehat9d2bd732009-09-22 16:44:22 -070035
36#define MMCIPOWER 0x000
37#define MCI_PWR_OFF 0x00
38#define MCI_PWR_UP 0x02
39#define MCI_PWR_ON 0x03
40#define MCI_OD (1 << 6)
Sujit Reddy Thumma01bc8712012-06-21 12:07:47 +053041#define MCI_SW_RST (1 << 7)
42#define MCI_SW_RST_CFG (1 << 8)
San Mehat9d2bd732009-09-22 16:44:22 -070043
44#define MMCICLOCK 0x004
45#define MCI_CLK_ENABLE (1 << 8)
46#define MCI_CLK_PWRSAVE (1 << 9)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070047#define MCI_CLK_WIDEBUS_1 (0 << 10)
48#define MCI_CLK_WIDEBUS_4 (2 << 10)
49#define MCI_CLK_WIDEBUS_8 (3 << 10)
San Mehat9d2bd732009-09-22 16:44:22 -070050#define MCI_CLK_FLOWENA (1 << 12)
51#define MCI_CLK_INVERTOUT (1 << 13)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070052#define MCI_CLK_SELECTIN (1 << 15)
53#define IO_PAD_PWR_SWITCH (1 << 21)
San Mehat9d2bd732009-09-22 16:44:22 -070054
55#define MMCIARGUMENT 0x008
56#define MMCICOMMAND 0x00c
57#define MCI_CPSM_RESPONSE (1 << 6)
58#define MCI_CPSM_LONGRSP (1 << 7)
59#define MCI_CPSM_INTERRUPT (1 << 8)
60#define MCI_CPSM_PENDING (1 << 9)
61#define MCI_CPSM_ENABLE (1 << 10)
62#define MCI_CPSM_PROGENA (1 << 11)
63#define MCI_CSPM_DATCMD (1 << 12)
64#define MCI_CSPM_MCIABORT (1 << 13)
65#define MCI_CSPM_CCSENABLE (1 << 14)
66#define MCI_CSPM_CCSDISABLE (1 << 15)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070067#define MCI_CSPM_AUTO_CMD19 (1 << 16)
Subhash Jadavani2bb781e2012-08-28 18:33:15 +053068#define MCI_CSPM_AUTO_CMD21 (1 << 21)
San Mehat9d2bd732009-09-22 16:44:22 -070069
70
71#define MMCIRESPCMD 0x010
72#define MMCIRESPONSE0 0x014
73#define MMCIRESPONSE1 0x018
74#define MMCIRESPONSE2 0x01c
75#define MMCIRESPONSE3 0x020
76#define MMCIDATATIMER 0x024
77#define MMCIDATALENGTH 0x028
78
79#define MMCIDATACTRL 0x02c
80#define MCI_DPSM_ENABLE (1 << 0)
81#define MCI_DPSM_DIRECTION (1 << 1)
82#define MCI_DPSM_MODE (1 << 2)
83#define MCI_DPSM_DMAENABLE (1 << 3)
Subhash Jadavanif5277752011-10-12 16:47:52 +053084#define MCI_DATA_PEND (1 << 17)
Subhash Jadavani7a651aa2011-08-03 20:44:58 +053085#define MCI_AUTO_PROG_DONE (1 << 19)
Subhash Jadavani24fb7f82011-07-25 15:54:34 +053086#define MCI_RX_DATA_PEND (1 << 20)
San Mehat9d2bd732009-09-22 16:44:22 -070087
88#define MMCIDATACNT 0x030
89#define MMCISTATUS 0x034
90#define MCI_CMDCRCFAIL (1 << 0)
91#define MCI_DATACRCFAIL (1 << 1)
92#define MCI_CMDTIMEOUT (1 << 2)
93#define MCI_DATATIMEOUT (1 << 3)
94#define MCI_TXUNDERRUN (1 << 4)
95#define MCI_RXOVERRUN (1 << 5)
96#define MCI_CMDRESPEND (1 << 6)
97#define MCI_CMDSENT (1 << 7)
98#define MCI_DATAEND (1 << 8)
99#define MCI_DATABLOCKEND (1 << 10)
100#define MCI_CMDACTIVE (1 << 11)
101#define MCI_TXACTIVE (1 << 12)
102#define MCI_RXACTIVE (1 << 13)
103#define MCI_TXFIFOHALFEMPTY (1 << 14)
104#define MCI_RXFIFOHALFFULL (1 << 15)
105#define MCI_TXFIFOFULL (1 << 16)
106#define MCI_RXFIFOFULL (1 << 17)
107#define MCI_TXFIFOEMPTY (1 << 18)
108#define MCI_RXFIFOEMPTY (1 << 19)
109#define MCI_TXDATAAVLBL (1 << 20)
110#define MCI_RXDATAAVLBL (1 << 21)
111#define MCI_SDIOINTR (1 << 22)
112#define MCI_PROGDONE (1 << 23)
113#define MCI_ATACMDCOMPL (1 << 24)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700114#define MCI_SDIOINTROPE (1 << 25)
San Mehat9d2bd732009-09-22 16:44:22 -0700115#define MCI_CCSTIMEOUT (1 << 26)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700116#define MCI_AUTOCMD19TIMEOUT (1 << 30)
San Mehat9d2bd732009-09-22 16:44:22 -0700117
118#define MMCICLEAR 0x038
119#define MCI_CMDCRCFAILCLR (1 << 0)
120#define MCI_DATACRCFAILCLR (1 << 1)
121#define MCI_CMDTIMEOUTCLR (1 << 2)
122#define MCI_DATATIMEOUTCLR (1 << 3)
123#define MCI_TXUNDERRUNCLR (1 << 4)
124#define MCI_RXOVERRUNCLR (1 << 5)
125#define MCI_CMDRESPENDCLR (1 << 6)
126#define MCI_CMDSENTCLR (1 << 7)
127#define MCI_DATAENDCLR (1 << 8)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700128#define MCI_STARTBITERRCLR (1 << 9)
San Mehat9d2bd732009-09-22 16:44:22 -0700129#define MCI_DATABLOCKENDCLR (1 << 10)
130
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700131#define MCI_SDIOINTRCLR (1 << 22)
132#define MCI_PROGDONECLR (1 << 23)
133#define MCI_ATACMDCOMPLCLR (1 << 24)
134#define MCI_SDIOINTROPECLR (1 << 25)
135#define MCI_CCSTIMEOUTCLR (1 << 26)
136
137#define MCI_CLEAR_STATIC_MASK \
138 (MCI_CMDCRCFAILCLR|MCI_DATACRCFAILCLR|MCI_CMDTIMEOUTCLR|\
139 MCI_DATATIMEOUTCLR|MCI_TXUNDERRUNCLR|MCI_RXOVERRUNCLR| \
140 MCI_CMDRESPENDCLR|MCI_CMDSENTCLR|MCI_DATAENDCLR| \
141 MCI_STARTBITERRCLR|MCI_DATABLOCKENDCLR|MCI_SDIOINTRCLR| \
142 MCI_SDIOINTROPECLR|MCI_PROGDONECLR|MCI_ATACMDCOMPLCLR| \
143 MCI_CCSTIMEOUTCLR)
144
San Mehat9d2bd732009-09-22 16:44:22 -0700145#define MMCIMASK0 0x03c
146#define MCI_CMDCRCFAILMASK (1 << 0)
147#define MCI_DATACRCFAILMASK (1 << 1)
148#define MCI_CMDTIMEOUTMASK (1 << 2)
149#define MCI_DATATIMEOUTMASK (1 << 3)
150#define MCI_TXUNDERRUNMASK (1 << 4)
151#define MCI_RXOVERRUNMASK (1 << 5)
152#define MCI_CMDRESPENDMASK (1 << 6)
153#define MCI_CMDSENTMASK (1 << 7)
154#define MCI_DATAENDMASK (1 << 8)
155#define MCI_DATABLOCKENDMASK (1 << 10)
156#define MCI_CMDACTIVEMASK (1 << 11)
157#define MCI_TXACTIVEMASK (1 << 12)
158#define MCI_RXACTIVEMASK (1 << 13)
159#define MCI_TXFIFOHALFEMPTYMASK (1 << 14)
160#define MCI_RXFIFOHALFFULLMASK (1 << 15)
161#define MCI_TXFIFOFULLMASK (1 << 16)
162#define MCI_RXFIFOFULLMASK (1 << 17)
163#define MCI_TXFIFOEMPTYMASK (1 << 18)
164#define MCI_RXFIFOEMPTYMASK (1 << 19)
165#define MCI_TXDATAAVLBLMASK (1 << 20)
166#define MCI_RXDATAAVLBLMASK (1 << 21)
167#define MCI_SDIOINTMASK (1 << 22)
168#define MCI_PROGDONEMASK (1 << 23)
169#define MCI_ATACMDCOMPLMASK (1 << 24)
170#define MCI_SDIOINTOPERMASK (1 << 25)
171#define MCI_CCSTIMEOUTMASK (1 << 26)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700172#define MCI_AUTOCMD19TIMEOUTMASK (1 << 30)
San Mehat9d2bd732009-09-22 16:44:22 -0700173
174#define MMCIMASK1 0x040
175#define MMCIFIFOCNT 0x044
Pratibhasagar V1c11da62011-11-14 12:36:35 +0530176#define MCI_VERSION 0x050
San Mehat9d2bd732009-09-22 16:44:22 -0700177#define MCICCSTIMER 0x058
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700178#define MCI_DLL_CONFIG 0x060
179#define MCI_DLL_EN (1 << 16)
180#define MCI_CDR_EN (1 << 17)
181#define MCI_CK_OUT_EN (1 << 18)
182#define MCI_CDR_EXT_EN (1 << 19)
183#define MCI_DLL_PDN (1 << 29)
184#define MCI_DLL_RST (1 << 30)
185
186#define MCI_DLL_STATUS 0x068
187#define MCI_DLL_LOCK (1 << 7)
San Mehat9d2bd732009-09-22 16:44:22 -0700188
Subhash Jadavani8f13e5b2011-08-04 21:15:11 +0530189#define MCI_STATUS2 0x06C
190#define MCI_MCLK_REG_WR_ACTIVE (1 << 0)
San Mehat9d2bd732009-09-22 16:44:22 -0700191
192#define MMCIFIFO 0x080 /* to 0x0bc */
193
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700194#define MCI_TEST_INPUT 0x0D4
195
San Mehat9d2bd732009-09-22 16:44:22 -0700196#define MCI_IRQENABLE \
197 (MCI_CMDCRCFAILMASK|MCI_DATACRCFAILMASK|MCI_CMDTIMEOUTMASK| \
198 MCI_DATATIMEOUTMASK|MCI_TXUNDERRUNMASK|MCI_RXOVERRUNMASK| \
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700199 MCI_CMDRESPENDMASK|MCI_CMDSENTMASK|MCI_DATAENDMASK| \
200 MCI_PROGDONEMASK|MCI_AUTOCMD19TIMEOUTMASK)
San Mehat9d2bd732009-09-22 16:44:22 -0700201
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700202#define MCI_IRQ_PIO \
203 (MCI_RXDATAAVLBLMASK | MCI_TXDATAAVLBLMASK | \
204 MCI_RXFIFOEMPTYMASK | MCI_TXFIFOEMPTYMASK | MCI_RXFIFOFULLMASK |\
205 MCI_TXFIFOFULLMASK | MCI_RXFIFOHALFFULLMASK | \
206 MCI_TXFIFOHALFEMPTYMASK | MCI_RXACTIVEMASK | MCI_TXACTIVEMASK)
San Mehat9d2bd732009-09-22 16:44:22 -0700207
208/*
209 * The size of the FIFO in bytes.
210 */
211#define MCI_FIFOSIZE (16*4)
212
213#define MCI_FIFOHALFSIZE (MCI_FIFOSIZE / 2)
214
Sujit Reddy Thummacf6c4ed2011-11-14 17:20:36 +0530215#define NR_SG 128
San Mehat9d2bd732009-09-22 16:44:22 -0700216
Pratibhasagar V13d1d032012-07-09 20:12:38 +0530217#define MSM_MMC_DEFAULT_IDLE_TIMEOUT 5000 /* msecs */
Sujit Reddy Thumma0e05f022012-06-11 19:44:18 +0530218#define MSM_MMC_CLK_GATE_DELAY 200 /* msecs */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700219
Pratibhasagar V4ecbe652012-05-07 15:45:07 +0530220/* Set the request timeout to 10secs */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700221#define MSM_MMC_REQ_TIMEOUT 10000 /* msecs */
222
Sujit Reddy Thummacf6c4ed2011-11-14 17:20:36 +0530223/*
224 * Controller HW limitations
225 */
226#define MCI_DATALENGTH_BITS 25
227#define MMC_MAX_REQ_SIZE ((1 << MCI_DATALENGTH_BITS) - 1)
228/* MCI_DATA_CTL BLOCKSIZE up to 4096 */
229#define MMC_MAX_BLK_SIZE 4096
230#define MMC_MIN_BLK_SIZE 512
231#define MMC_MAX_BLK_CNT (MMC_MAX_REQ_SIZE / MMC_MIN_BLK_SIZE)
232
233/* 64KiB */
234#define MAX_SG_SIZE (64 * 1024)
235#define MAX_NR_SG_DMA_PIO (MMC_MAX_REQ_SIZE / MAX_SG_SIZE)
236
237/*
238 * BAM limitations
239 */
240/* upto 16 bits (64K - 1) */
241#define SPS_MAX_DESC_FIFO_SIZE 65535
242/* 16KiB */
243#define SPS_MAX_DESC_SIZE (16 * 1024)
244/* Each descriptor is of length 8 bytes */
245#define SPS_MAX_DESC_LENGTH 8
246#define SPS_MAX_DESCS (SPS_MAX_DESC_FIFO_SIZE / SPS_MAX_DESC_LENGTH)
Sujit Reddy Thummacf6c4ed2011-11-14 17:20:36 +0530247
248/*
249 * DMA limitations
250 */
251/* upto 16 bits (64K - 1) */
252#define MMC_MAX_DMA_ROWS (64 * 1024 - 1)
253#define MMC_MAX_DMA_BOX_LENGTH (MMC_MAX_DMA_ROWS * MCI_FIFOSIZE)
254#define MMC_MAX_DMA_CMDS (MAX_NR_SG_DMA_PIO * (MMC_MAX_REQ_SIZE / \
255 MMC_MAX_DMA_BOX_LENGTH))
San Mehat9d2bd732009-09-22 16:44:22 -0700256
257struct clk;
258
259struct msmsdcc_nc_dmadata {
Sujit Reddy Thummacf6c4ed2011-11-14 17:20:36 +0530260 dmov_box cmd[MMC_MAX_DMA_CMDS];
San Mehat9d2bd732009-09-22 16:44:22 -0700261 uint32_t cmdptr;
262};
263
264struct msmsdcc_dma_data {
265 struct msmsdcc_nc_dmadata *nc;
266 dma_addr_t nc_busaddr;
267 dma_addr_t cmd_busaddr;
268 dma_addr_t cmdptr_busaddr;
269
270 struct msm_dmov_cmd hdr;
271 enum dma_data_direction dir;
272
273 struct scatterlist *sg;
274 int num_ents;
275
276 int channel;
Krishna Konda25786ec2011-07-25 16:21:36 -0700277 int crci;
San Mehat9d2bd732009-09-22 16:44:22 -0700278 struct msmsdcc_host *host;
279 int busy; /* Set if DM is busy */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700280 unsigned int result;
Sahitya Tummala62612cf2010-12-08 15:03:03 +0530281 struct msm_dmov_errdata err;
San Mehat9d2bd732009-09-22 16:44:22 -0700282};
283
284struct msmsdcc_pio_data {
Oluwafemi Adeyemiecfa3df2012-02-28 18:08:54 -0800285 struct sg_mapping_iter sg_miter;
286 char bounce_buf[4];
287 /* valid bytes in bounce_buf */
288 int bounce_buf_len;
San Mehat9d2bd732009-09-22 16:44:22 -0700289};
290
291struct msmsdcc_curr_req {
292 struct mmc_request *mrq;
293 struct mmc_command *cmd;
294 struct mmc_data *data;
295 unsigned int xfer_size; /* Total data size */
296 unsigned int xfer_remain; /* Bytes remaining to send */
297 unsigned int data_xfered; /* Bytes acked by BLKEND irq */
298 int got_dataend;
Subhash Jadavanid5d59dc2012-05-22 19:38:33 +0530299 bool wait_for_auto_prog_done;
300 bool got_auto_prog_done;
Subhash Jadavanif5277752011-10-12 16:47:52 +0530301 bool use_wr_data_pend;
San Mehat9d2bd732009-09-22 16:44:22 -0700302 int user_pages;
Subhash Jadavani8706ced2012-05-25 16:09:21 +0530303 u32 req_tout_ms;
San Mehat9d2bd732009-09-22 16:44:22 -0700304};
305
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700306struct msmsdcc_sps_ep_conn_data {
307 struct sps_pipe *pipe_handle;
308 struct sps_connect config;
309 struct sps_register_event event;
310};
311
312struct msmsdcc_sps_data {
313 struct msmsdcc_sps_ep_conn_data prod;
314 struct msmsdcc_sps_ep_conn_data cons;
315 struct sps_event_notify notify;
316 enum dma_data_direction dir;
317 struct scatterlist *sg;
318 int num_ents;
319 u32 bam_handle;
320 unsigned int src_pipe_index;
321 unsigned int dest_pipe_index;
322 unsigned int busy;
323 unsigned int xfer_req_cnt;
Subhash Jadavanib5b07742011-08-29 17:48:07 +0530324 bool pipe_reset_pending;
Krishna Konda5af8f972012-05-14 16:15:24 -0700325 bool reset_device;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700326 struct tasklet_struct tlet;
San Mehat9d2bd732009-09-22 16:44:22 -0700327};
328
Subhash Jadavanibcd435f2012-04-24 18:26:49 +0530329struct msmsdcc_msm_bus_vote {
330 uint32_t client_handle;
331 uint32_t curr_vote;
332 int min_bw_vote;
333 int max_bw_vote;
334 bool is_max_bw_needed;
335 struct delayed_work vote_work;
San Mehat9d2bd732009-09-22 16:44:22 -0700336};
337
338struct msmsdcc_host {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700339 struct resource *core_irqres;
340 struct resource *bam_irqres;
341 struct resource *core_memres;
342 struct resource *bam_memres;
343 struct resource *dml_memres;
San Mehat9d2bd732009-09-22 16:44:22 -0700344 struct resource *dmares;
Krishna Konda25786ec2011-07-25 16:21:36 -0700345 struct resource *dma_crci_res;
San Mehat9d2bd732009-09-22 16:44:22 -0700346 void __iomem *base;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700347 void __iomem *dml_base;
348 void __iomem *bam_base;
349
San Mehat9d2bd732009-09-22 16:44:22 -0700350 int pdev_id;
San Mehat9d2bd732009-09-22 16:44:22 -0700351
352 struct msmsdcc_curr_req curr;
353
354 struct mmc_host *mmc;
355 struct clk *clk; /* main MMC bus clock */
356 struct clk *pclk; /* SDCC peripheral bus clock */
Sujit Reddy Thumma8d08c142012-06-12 22:52:29 +0530357 struct clk *bus_clk; /* SDCC bus voter clock */
Pratibhasagar V89cfcd72012-06-14 18:13:26 +0530358 atomic_t clks_on; /* set if clocks are enabled */
San Mehat9d2bd732009-09-22 16:44:22 -0700359
360 unsigned int eject; /* eject state */
361
362 spinlock_t lock;
363
364 unsigned int clk_rate; /* Current clock rate */
365 unsigned int pclk_rate;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700366 unsigned int ddr_doubled_clk_rate;
San Mehat9d2bd732009-09-22 16:44:22 -0700367
368 u32 pwr;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700369 struct mmc_platform_data *plat;
Sujit Reddy Thumma01bc8712012-06-21 12:07:47 +0530370 unsigned int hw_caps;
San Mehat9d2bd732009-09-22 16:44:22 -0700371
San Mehat9d2bd732009-09-22 16:44:22 -0700372 unsigned int oldstat;
373
374 struct msmsdcc_dma_data dma;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700375 struct msmsdcc_sps_data sps;
San Mehat9d2bd732009-09-22 16:44:22 -0700376 struct msmsdcc_pio_data pio;
San Mehat56a8b5b2009-11-21 12:29:46 -0800377
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700378#ifdef CONFIG_HAS_EARLYSUSPEND
379 struct early_suspend early_suspend;
380 int polling_enabled;
381#endif
382
383 struct tasklet_struct dma_tlet;
384
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700385 unsigned int prog_enable;
386
San Mehat56a8b5b2009-11-21 12:29:46 -0800387 /* Command parameters */
388 unsigned int cmd_timeout;
389 unsigned int cmd_pio_irqmask;
390 unsigned int cmd_datactrl;
391 struct mmc_command *cmd_cmd;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700392 u32 cmd_c;
San Mehat56a8b5b2009-11-21 12:29:46 -0800393
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700394 unsigned int mci_irqenable;
395 unsigned int dummy_52_needed;
Oluwafemi Adeyemicb791442011-07-11 22:51:25 -0700396 unsigned int dummy_52_sent;
397
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700398 struct wake_lock sdio_wlock;
399 struct wake_lock sdio_suspend_wlock;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700400 struct timer_list req_tout_timer;
Sujith Reddy Thummac1824d52011-09-28 10:05:44 +0530401 unsigned long reg_write_delay;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700402 bool io_pad_pwr_switch;
Subhash Jadavani56e0eaa2012-03-13 18:06:04 +0530403 bool tuning_in_progress;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700404 bool tuning_needed;
Subhash Jadavanie5c2e712012-08-28 16:31:48 +0530405 bool en_auto_cmd19;
Subhash Jadavani2bb781e2012-08-28 18:33:15 +0530406 bool en_auto_cmd21;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700407 bool sdio_gpio_lpm;
408 bool irq_wake_enabled;
Steve Mucklef132c6c2012-06-06 18:30:57 -0700409 struct pm_qos_request pm_qos_req_dma;
Oluwafemi Adeyemi784b4392012-04-10 13:49:38 -0700410 u32 cpu_dma_latency;
Sujit Reddy Thummaf4a999c2012-02-09 23:14:45 +0530411 bool sdcc_suspending;
412 bool sdcc_irq_disabled;
413 bool sdcc_suspended;
414 bool sdio_wakeupirq_disabled;
Asutosh Dasf5298c32012-04-03 14:51:47 +0530415 struct mutex clk_mutex;
Oluwafemi Adeyemi9acea6b2012-04-27 00:12:07 -0700416 bool pending_resume;
Pratibhasagar V13d1d032012-07-09 20:12:38 +0530417 unsigned int idle_tout_ms; /* Timeout in msecs */
Sujit Reddy Thumma02868752012-06-25 17:22:56 +0530418 bool pending_dpsm_reset;
Subhash Jadavanibcd435f2012-04-24 18:26:49 +0530419 struct msmsdcc_msm_bus_vote msm_bus_vote;
Subhash Jadavanie363cc42012-06-05 18:01:08 +0530420 struct device_attribute max_bus_bw;
421 struct device_attribute polling;
Pratibhasagar V13d1d032012-07-09 20:12:38 +0530422 struct device_attribute idle_timeout;
Subhash Jadavanie5c2e712012-08-28 16:31:48 +0530423 struct device_attribute auto_cmd19_attr;
Subhash Jadavani2bb781e2012-08-28 18:33:15 +0530424 struct device_attribute auto_cmd21_attr;
San Mehat9d2bd732009-09-22 16:44:22 -0700425};
426
Subhash Jadavani2bb781e2012-08-28 18:33:15 +0530427#define MSMSDCC_VERSION_STEP_MASK 0x0000FFFF
428#define MSMSDCC_VERSION_MINOR_MASK 0x0FFF0000
429#define MSMSDCC_VERSION_MINOR_SHIFT 16
430#define MSMSDCC_VERSION_MAJOR_MASK 0xF0000000
431#define MSMSDCC_VERSION_MAJOR_SHIFT 28
Sujit Reddy Thumma01bc8712012-06-21 12:07:47 +0530432#define MSMSDCC_DMA_SUP (1 << 0)
433#define MSMSDCC_SPS_BAM_SUP (1 << 1)
434#define MSMSDCC_SOFT_RESET (1 << 2)
435#define MSMSDCC_AUTO_PROG_DONE (1 << 3)
436#define MSMSDCC_REG_WR_ACTIVE (1 << 4)
437#define MSMSDCC_SW_RST (1 << 5)
438#define MSMSDCC_SW_RST_CFG (1 << 6)
Sujit Reddy Thumma02868752012-06-25 17:22:56 +0530439#define MSMSDCC_WAIT_FOR_TX_RX (1 << 7)
Subhash Jadavani341b9e72012-08-11 18:11:57 +0530440#define MSMSDCC_IO_PAD_PWR_SWITCH (1 << 8)
Subhash Jadavanie5c2e712012-08-28 16:31:48 +0530441#define MSMSDCC_AUTO_CMD19 (1 << 9)
Subhash Jadavani2bb781e2012-08-28 18:33:15 +0530442#define MSMSDCC_AUTO_CMD21 (1 << 10)
Sujit Reddy Thumma01bc8712012-06-21 12:07:47 +0530443
444#define set_hw_caps(h, val) ((h)->hw_caps |= val)
445#define is_sps_mode(h) ((h)->hw_caps & MSMSDCC_SPS_BAM_SUP)
446#define is_dma_mode(h) ((h)->hw_caps & MSMSDCC_DMA_SUP)
447#define is_soft_reset(h) ((h)->hw_caps & MSMSDCC_SOFT_RESET)
448#define is_auto_prog_done(h) ((h)->hw_caps & MSMSDCC_AUTO_PROG_DONE)
449#define is_wait_for_reg_write(h) ((h)->hw_caps & MSMSDCC_REG_WR_ACTIVE)
450#define is_sw_hard_reset(h) ((h)->hw_caps & MSMSDCC_SW_RST)
451#define is_sw_reset_save_config(h) ((h)->hw_caps & MSMSDCC_SW_RST_CFG)
Sujit Reddy Thumma02868752012-06-25 17:22:56 +0530452#define is_wait_for_tx_rx_active(h) ((h)->hw_caps & MSMSDCC_WAIT_FOR_TX_RX)
Subhash Jadavani341b9e72012-08-11 18:11:57 +0530453#define is_io_pad_pwr_switch(h) ((h)->hw_caps & MSMSDCC_IO_PAD_PWR_SWITCH)
Subhash Jadavanie5c2e712012-08-28 16:31:48 +0530454#define is_auto_cmd19(h) ((h)->hw_caps & MSMSDCC_AUTO_CMD19)
Subhash Jadavani2bb781e2012-08-28 18:33:15 +0530455#define is_auto_cmd21(h) ((h)->hw_caps & MSMSDCC_AUTO_CMD21)
Sujit Reddy Thumma01bc8712012-06-21 12:07:47 +0530456
457/* Set controller capabilities based on version */
458static inline void set_default_hw_caps(struct msmsdcc_host *host)
459{
460 u32 version;
Subhash Jadavani2bb781e2012-08-28 18:33:15 +0530461 u16 step, minor;
462
Sujit Reddy Thumma01bc8712012-06-21 12:07:47 +0530463 /*
464 * Lookup the Controller Version, to identify the supported features
465 * Version number read as 0 would indicate SDCC3 or earlier versions.
466 */
467 version = readl_relaxed(host->base + MCI_VERSION);
468 pr_info("%s: SDCC Version: 0x%.8x\n", mmc_hostname(host->mmc), version);
469
470 if (!version)
471 return;
472
Subhash Jadavani2bb781e2012-08-28 18:33:15 +0530473 step = version & MSMSDCC_VERSION_STEP_MASK;
474 minor = (version & MSMSDCC_VERSION_MINOR_MASK) >>
475 MSMSDCC_VERSION_MINOR_SHIFT;
476
Sujit Reddy Thumma01bc8712012-06-21 12:07:47 +0530477 if (version) /* SDCC v4 and greater */
478 host->hw_caps |= MSMSDCC_AUTO_PROG_DONE |
Sujit Reddy Thumma02868752012-06-25 17:22:56 +0530479 MSMSDCC_SOFT_RESET | MSMSDCC_REG_WR_ACTIVE
Subhash Jadavanie5c2e712012-08-28 16:31:48 +0530480 | MSMSDCC_WAIT_FOR_TX_RX | MSMSDCC_IO_PAD_PWR_SWITCH
481 | MSMSDCC_AUTO_CMD19;
Sujit Reddy Thumma01bc8712012-06-21 12:07:47 +0530482
Subhash Jadavani2bb781e2012-08-28 18:33:15 +0530483 if ((step == 0x18) && (minor >= 3))
484 host->hw_caps |= MSMSDCC_AUTO_CMD21;
485
Krishna Kondaf6486f12012-09-10 13:12:10 -0700486 if (version >= 0x2b) /* SDCC v4 2.1.0 and greater */
Subhash Jadavani2bb781e2012-08-28 18:33:15 +0530487 host->hw_caps |= MSMSDCC_SW_RST | MSMSDCC_AUTO_CMD21;
Sujit Reddy Thumma01bc8712012-06-21 12:07:47 +0530488}
489
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700490int msmsdcc_set_pwrsave(struct mmc_host *mmc, int pwrsave);
491int msmsdcc_sdio_al_lpm(struct mmc_host *mmc, bool enable);
492
493#ifdef CONFIG_MSM_SDIO_AL
494
495static inline int msmsdcc_lpm_enable(struct mmc_host *mmc)
496{
497 return msmsdcc_sdio_al_lpm(mmc, true);
498}
499
500static inline int msmsdcc_lpm_disable(struct mmc_host *mmc)
501{
Venkat Gopalakrishnanf3170582011-11-04 14:02:48 -0700502 struct msmsdcc_host *host = mmc_priv(mmc);
503 int ret;
504
505 ret = msmsdcc_sdio_al_lpm(mmc, false);
506 wake_unlock(&host->sdio_wlock);
507 return ret;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700508}
509#endif
510
San Mehat9d2bd732009-09-22 16:44:22 -0700511#endif