PageRenderTime 28ms CodeModel.GetById 20ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 0ms

/include/linux/mmc/core.h

https://bitbucket.org/cyanogenmod/android_kernel_asus_tf300t
C Header | 195 lines | 122 code | 34 blank | 39 comment | 0 complexity | 0316ab5be99a1a99a0528f240c283508 MD5 | raw file
Possible License(s): LGPL-2.0, AGPL-1.0, GPL-2.0
  1/*
  2 *  linux/include/linux/mmc/core.h
  3 *
  4 * This program is free software; you can redistribute it and/or modify
  5 * it under the terms of the GNU General Public License version 2 as
  6 * published by the Free Software Foundation.
  7 */
  8#ifndef LINUX_MMC_CORE_H
  9#define LINUX_MMC_CORE_H
 10
 11#include <linux/interrupt.h>
 12#include <linux/device.h>
 13
 14#define MMC_SLOW_WRITE_TIME	500000	/* time (us) */
 15#define MMC_REFRESH_INTERVAL	60	/* time (s) */
 16#define MMC_BKOPS_INTERVAL	20	/* time (s) */
 17
 18struct request;
 19struct mmc_data;
 20struct mmc_request;
 21
 22struct mmc_command {
 23	u32			opcode;
 24	u32			arg;
 25	u32			resp[4];
 26	unsigned int		flags;		/* expected response type */
 27#define MMC_RSP_PRESENT	(1 << 0)
 28#define MMC_RSP_136	(1 << 1)		/* 136 bit response */
 29#define MMC_RSP_CRC	(1 << 2)		/* expect valid crc */
 30#define MMC_RSP_BUSY	(1 << 3)		/* card may send busy */
 31#define MMC_RSP_OPCODE	(1 << 4)		/* response contains opcode */
 32
 33#define MMC_CMD_MASK	(3 << 5)		/* non-SPI command type */
 34#define MMC_CMD_AC	(0 << 5)
 35#define MMC_CMD_ADTC	(1 << 5)
 36#define MMC_CMD_BC	(2 << 5)
 37#define MMC_CMD_BCR	(3 << 5)
 38
 39#define MMC_RSP_SPI_S1	(1 << 7)		/* one status byte */
 40#define MMC_RSP_SPI_S2	(1 << 8)		/* second byte */
 41#define MMC_RSP_SPI_B4	(1 << 9)		/* four data bytes */
 42#define MMC_RSP_SPI_BUSY (1 << 10)		/* card may send busy */
 43
 44/*
 45 * These are the native response types, and correspond to valid bit
 46 * patterns of the above flags.  One additional valid pattern
 47 * is all zeros, which means we don't expect a response.
 48 */
 49#define MMC_RSP_NONE	(0)
 50#define MMC_RSP_R1	(MMC_RSP_PRESENT|MMC_RSP_CRC|MMC_RSP_OPCODE)
 51#define MMC_RSP_R1B	(MMC_RSP_PRESENT|MMC_RSP_CRC|MMC_RSP_OPCODE|MMC_RSP_BUSY)
 52#define MMC_RSP_R2	(MMC_RSP_PRESENT|MMC_RSP_136|MMC_RSP_CRC)
 53#define MMC_RSP_R3	(MMC_RSP_PRESENT)
 54#define MMC_RSP_R4	(MMC_RSP_PRESENT)
 55#define MMC_RSP_R5	(MMC_RSP_PRESENT|MMC_RSP_CRC|MMC_RSP_OPCODE)
 56#define MMC_RSP_R6	(MMC_RSP_PRESENT|MMC_RSP_CRC|MMC_RSP_OPCODE)
 57#define MMC_RSP_R7	(MMC_RSP_PRESENT|MMC_RSP_CRC|MMC_RSP_OPCODE)
 58
 59#define mmc_resp_type(cmd)	((cmd)->flags & (MMC_RSP_PRESENT|MMC_RSP_136|MMC_RSP_CRC|MMC_RSP_BUSY|MMC_RSP_OPCODE))
 60
 61/*
 62 * These are the SPI response types for MMC, SD, and SDIO cards.
 63 * Commands return R1, with maybe more info.  Zero is an error type;
 64 * callers must always provide the appropriate MMC_RSP_SPI_Rx flags.
 65 */
 66#define MMC_RSP_SPI_R1	(MMC_RSP_SPI_S1)
 67#define MMC_RSP_SPI_R1B	(MMC_RSP_SPI_S1|MMC_RSP_SPI_BUSY)
 68#define MMC_RSP_SPI_R2	(MMC_RSP_SPI_S1|MMC_RSP_SPI_S2)
 69#define MMC_RSP_SPI_R3	(MMC_RSP_SPI_S1|MMC_RSP_SPI_B4)
 70#define MMC_RSP_SPI_R4	(MMC_RSP_SPI_S1|MMC_RSP_SPI_B4)
 71#define MMC_RSP_SPI_R5	(MMC_RSP_SPI_S1|MMC_RSP_SPI_S2)
 72#define MMC_RSP_SPI_R7	(MMC_RSP_SPI_S1|MMC_RSP_SPI_B4)
 73
 74#define mmc_spi_resp_type(cmd)	((cmd)->flags & \
 75		(MMC_RSP_SPI_S1|MMC_RSP_SPI_BUSY|MMC_RSP_SPI_S2|MMC_RSP_SPI_B4))
 76
 77/*
 78 * These are the command types.
 79 */
 80#define mmc_cmd_type(cmd)	((cmd)->flags & MMC_CMD_MASK)
 81
 82	unsigned int		retries;	/* max number of retries */
 83	unsigned int		error;		/* command error */
 84
 85/*
 86 * Standard errno values are used for errors, but some have specific
 87 * meaning in the MMC layer:
 88 *
 89 * ETIMEDOUT    Card took too long to respond
 90 * EILSEQ       Basic format problem with the received or sent data
 91 *              (e.g. CRC check failed, incorrect opcode in response
 92 *              or bad end bit)
 93 * EINVAL       Request cannot be performed because of restrictions
 94 *              in hardware and/or the driver
 95 * ENOMEDIUM    Host can determine that the slot is empty and is
 96 *              actively failing requests
 97 */
 98
 99	unsigned int		cmd_timeout_ms;	/* in milliseconds */
100
101	struct mmc_data		*data;		/* data segment associated with cmd */
102	struct mmc_request	*mrq;		/* associated request */
103};
104
105struct mmc_data {
106	unsigned int		timeout_ns;	/* data timeout (in ns, max 80ms) */
107	unsigned int		timeout_clks;	/* data timeout (in clocks) */
108	unsigned int		blksz;		/* data block size */
109	unsigned int		blocks;		/* number of blocks */
110	unsigned int		error;		/* data error */
111	unsigned int		flags;
112
113#define MMC_DATA_WRITE	(1 << 8)
114#define MMC_DATA_READ	(1 << 9)
115#define MMC_DATA_STREAM	(1 << 10)
116
117	unsigned int		bytes_xfered;
118
119	struct mmc_command	*stop;		/* stop command */
120	struct mmc_request	*mrq;		/* associated request */
121
122	unsigned int		sg_len;		/* size of scatter list */
123	struct scatterlist	*sg;		/* I/O scatter list */
124	s32			host_cookie;	/* host private data */
125};
126
127struct mmc_request {
128	struct mmc_command	*sbc;		/* SET_BLOCK_COUNT for multiblock */
129	struct mmc_command	*cmd;
130	struct mmc_data		*data;
131	struct mmc_command	*stop;
132
133	struct completion	completion;
134	void			(*done)(struct mmc_request *);/* completion function */
135};
136
137struct mmc_host;
138struct mmc_card;
139struct mmc_async_req;
140
141extern struct mmc_async_req *mmc_start_req(struct mmc_host *,
142					   struct mmc_async_req *, int *);
143extern int mmc_interrupt_hpi(struct mmc_card *);
144extern int mmc_bkops_start(struct mmc_card *card, bool is_synchronous);
145extern void mmc_refresh(unsigned long data);
146
147extern void mmc_wait_for_req(struct mmc_host *, struct mmc_request *);
148extern int mmc_wait_for_cmd(struct mmc_host *, struct mmc_command *, int);
149extern int mmc_app_cmd(struct mmc_host *, struct mmc_card *);
150extern int mmc_wait_for_app_cmd(struct mmc_host *, struct mmc_card *,
151	struct mmc_command *, int);
152extern int mmc_switch(struct mmc_card *, u8, u8, u8, unsigned int);
153
154#define MMC_ERASE_ARG		0x00000000
155#define MMC_SECURE_ERASE_ARG	0x80000000
156#define MMC_TRIM_ARG		0x00000001
157#define MMC_SECURE_TRIM1_ARG	0x80000001
158#define MMC_SECURE_TRIM2_ARG	0x80008000
159
160#define MMC_SECURE_ARGS		0x80000000
161#define MMC_TRIM_ARGS		0x00008001
162
163extern int mmc_erase(struct mmc_card *card, unsigned int from, unsigned int nr,
164		     unsigned int arg);
165extern int mmc_can_erase(struct mmc_card *card);
166extern int mmc_can_trim(struct mmc_card *card);
167extern int mmc_can_secure_erase_trim(struct mmc_card *card);
168extern int mmc_erase_group_aligned(struct mmc_card *card, unsigned int from,
169				   unsigned int nr);
170extern unsigned int mmc_calc_max_discard(struct mmc_card *card);
171
172extern int mmc_set_blocklen(struct mmc_card *card, unsigned int blocklen);
173
174extern void mmc_set_data_timeout(struct mmc_data *, const struct mmc_card *);
175extern unsigned int mmc_align_data_size(struct mmc_card *, unsigned int);
176
177extern int __mmc_claim_host(struct mmc_host *host, atomic_t *abort);
178extern void mmc_release_host(struct mmc_host *host);
179extern void mmc_do_release_host(struct mmc_host *host);
180extern int mmc_try_claim_host(struct mmc_host *host);
181
182/**
183 *	mmc_claim_host - exclusively claim a host
184 *	@host: mmc host to claim
185 *
186 *	Claim a host for a set of operations.
187 */
188static inline void mmc_claim_host(struct mmc_host *host)
189{
190	__mmc_claim_host(host, NULL);
191}
192
193extern u32 mmc_vddrange_to_ocrmask(int vdd_min, int vdd_max);
194
195#endif /* LINUX_MMC_CORE_H */