1 /*
2  * Copyright (c) 2010 Broadcom Corporation
3  *
4  * Permission to use, copy, modify, and/or distribute this software for any
5  * purpose with or without fee is hereby granted, provided that the above
6  * copyright notice and this permission notice appear in all copies.
7  *
8  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
11  * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
13  * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
14  * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15  */
16 
17 #ifndef __BCMSDH_SDMMC_H__
18 #define __BCMSDH_SDMMC_H__
19 
20 #ifdef BCMDBG
21 #define sd_err(x)	\
22 	do { \
23 		if ((sd_msglevel & SDH_ERROR_VAL) && net_ratelimit()) \
24 			printk x; \
25 	} while (0)
26 #define sd_trace(x)	\
27 	do { \
28 		if ((sd_msglevel & SDH_TRACE_VAL) && net_ratelimit()) \
29 			printk x; \
30 	} while (0)
31 #define sd_info(x)	\
32 	do { \
33 		if ((sd_msglevel & SDH_INFO_VAL) && net_ratelimit()) \
34 			printk x; \
35 	} while (0)
36 #define sd_debug(x)	\
37 	do { \
38 		if ((sd_msglevel & SDH_DEBUG_VAL) && net_ratelimit()) \
39 			printk x; \
40 	} while (0)
41 #define sd_data(x)	\
42 	do { \
43 		if ((sd_msglevel & SDH_DATA_VAL) && net_ratelimit()) \
44 			printk x; \
45 	} while (0)
46 #define sd_ctrl(x)	\
47 	do { \
48 		if ((sd_msglevel & SDH_CTRL_VAL) && net_ratelimit()) \
49 			printk x; \
50 	} while (0)
51 #else
52 #define sd_err(x)
53 #define sd_trace(x)
54 #define sd_info(x)
55 #define sd_debug(x)
56 #define sd_data(x)
57 #define sd_ctrl(x)
58 #endif
59 
60 /* Allocate/init/free per-OS private data */
61 extern int sdioh_sdmmc_osinit(sdioh_info_t *sd);
62 extern void sdioh_sdmmc_osfree(sdioh_info_t *sd);
63 
64 #define BLOCK_SIZE_64 64
65 #define BLOCK_SIZE_512 512
66 #define BLOCK_SIZE_4318 64
67 #define BLOCK_SIZE_4328 512
68 
69 /* internal return code */
70 #define SUCCESS	0
71 #define ERROR	1
72 
73 /* private bus modes */
74 #define SDIOH_MODE_SD4		2
75 #define CLIENT_INTR 		0x100	/* Get rid of this! */
76 
77 struct sdioh_info {
78 	struct osl_info *osh;		/* osh handler */
79 	bool client_intr_enabled;	/* interrupt connnected flag */
80 	bool intr_handler_valid;	/* client driver interrupt handler valid */
81 	sdioh_cb_fn_t intr_handler;	/* registered interrupt handler */
82 	void *intr_handler_arg;	/* argument to call interrupt handler */
83 	u16 intmask;		/* Current active interrupts */
84 	void *sdos_info;	/* Pointer to per-OS private data */
85 
86 	uint irq;		/* Client irq */
87 	int intrcount;		/* Client interrupts */
88 	bool sd_use_dma;	/* DMA on CMD53 */
89 	bool sd_blockmode;	/* sd_blockmode == false => 64 Byte Cmd 53s. */
90 	/*  Must be on for sd_multiblock to be effective */
91 	bool use_client_ints;	/* If this is false, make sure to restore */
92 	int sd_mode;		/* SD1/SD4/SPI */
93 	int client_block_size[SDIOD_MAX_IOFUNCS];	/* Blocksize */
94 	u8 num_funcs;	/* Supported funcs on client */
95 	u32 com_cis_ptr;
96 	u32 func_cis_ptr[SDIOD_MAX_IOFUNCS];
97 	uint max_dma_len;
98 	uint max_dma_descriptors;	/* DMA Descriptors supported by this controller. */
99 	/*	SDDMA_DESCRIPTOR	SGList[32]; *//* Scatter/Gather DMA List */
100 };
101 
102 /************************************************************
103  * Internal interfaces: per-port references into bcmsdh_sdmmc.c
104  */
105 
106 /* Global message bits */
107 extern uint sd_msglevel;
108 
109 /* OS-independent interrupt handler */
110 extern bool check_client_intr(sdioh_info_t *sd);
111 
112 /* Core interrupt enable/disable of device interrupts */
113 extern void sdioh_sdmmc_devintr_on(sdioh_info_t *sd);
114 extern void sdioh_sdmmc_devintr_off(sdioh_info_t *sd);
115 
116 /**************************************************************
117  * Internal interfaces: bcmsdh_sdmmc.c references to per-port code
118  */
119 
120 /* Register mapping routines */
121 extern u32 *sdioh_sdmmc_reg_map(s32 addr, int size);
122 extern void sdioh_sdmmc_reg_unmap(s32 addr, int size);
123 
124 /* Interrupt (de)registration routines */
125 extern int sdioh_sdmmc_register_irq(sdioh_info_t *sd, uint irq);
126 extern void sdioh_sdmmc_free_irq(uint irq, sdioh_info_t *sd);
127 
128 typedef struct _BCMSDH_SDMMC_INSTANCE {
129 	sdioh_info_t *sd;
130 	struct sdio_func *func[SDIOD_MAX_IOFUNCS];
131 	u32 host_claimed;
132 } BCMSDH_SDMMC_INSTANCE, *PBCMSDH_SDMMC_INSTANCE;
133 
134 #endif				/* __BCMSDH_SDMMC_H__ */
135