core.h 5.9 KB
Newer Older
L
Linus Torvalds 已提交
1
/*
2
 *  linux/include/linux/mmc/core.h
L
Linus Torvalds 已提交
3 4 5 6 7
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 as
 * published by the Free Software Foundation.
 */
8 9
#ifndef LINUX_MMC_CORE_H
#define LINUX_MMC_CORE_H
L
Linus Torvalds 已提交
10 11 12 13 14 15 16 17 18 19 20 21 22

#include <linux/interrupt.h>
#include <linux/device.h>

struct request;
struct mmc_data;
struct mmc_request;

struct mmc_command {
	u32			opcode;
	u32			arg;
	u32			resp[4];
	unsigned int		flags;		/* expected response type */
R
Russell King 已提交
23 24 25 26 27
#define MMC_RSP_PRESENT	(1 << 0)
#define MMC_RSP_136	(1 << 1)		/* 136 bit response */
#define MMC_RSP_CRC	(1 << 2)		/* expect valid crc */
#define MMC_RSP_BUSY	(1 << 3)		/* card may send busy */
#define MMC_RSP_OPCODE	(1 << 4)		/* response contains opcode */
D
David Brownell 已提交
28 29

#define MMC_CMD_MASK	(3 << 5)		/* non-SPI command type */
R
Russell King 已提交
30 31 32 33
#define MMC_CMD_AC	(0 << 5)
#define MMC_CMD_ADTC	(1 << 5)
#define MMC_CMD_BC	(2 << 5)
#define MMC_CMD_BCR	(3 << 5)
L
Linus Torvalds 已提交
34

D
David Brownell 已提交
35 36 37 38 39
#define MMC_RSP_SPI_S1	(1 << 7)		/* one status byte */
#define MMC_RSP_SPI_S2	(1 << 8)		/* second byte */
#define MMC_RSP_SPI_B4	(1 << 9)		/* four data bytes */
#define MMC_RSP_SPI_BUSY (1 << 10)		/* card may send busy */

L
Linus Torvalds 已提交
40
/*
D
David Brownell 已提交
41
 * These are the native response types, and correspond to valid bit
L
Linus Torvalds 已提交
42 43 44
 * patterns of the above flags.  One additional valid pattern
 * is all zeros, which means we don't expect a response.
 */
R
Russell King 已提交
45 46 47 48 49
#define MMC_RSP_NONE	(0)
#define MMC_RSP_R1	(MMC_RSP_PRESENT|MMC_RSP_CRC|MMC_RSP_OPCODE)
#define MMC_RSP_R1B	(MMC_RSP_PRESENT|MMC_RSP_CRC|MMC_RSP_OPCODE|MMC_RSP_BUSY)
#define MMC_RSP_R2	(MMC_RSP_PRESENT|MMC_RSP_136|MMC_RSP_CRC)
#define MMC_RSP_R3	(MMC_RSP_PRESENT)
P
Pierre Ossman 已提交
50
#define MMC_RSP_R4	(MMC_RSP_PRESENT)
51
#define MMC_RSP_R5	(MMC_RSP_PRESENT|MMC_RSP_CRC|MMC_RSP_OPCODE)
P
Philip Langdale 已提交
52
#define MMC_RSP_R6	(MMC_RSP_PRESENT|MMC_RSP_CRC|MMC_RSP_OPCODE)
53
#define MMC_RSP_R7	(MMC_RSP_PRESENT|MMC_RSP_CRC|MMC_RSP_OPCODE)
R
Russell King 已提交
54 55 56

#define mmc_resp_type(cmd)	((cmd)->flags & (MMC_RSP_PRESENT|MMC_RSP_136|MMC_RSP_CRC|MMC_RSP_BUSY|MMC_RSP_OPCODE))

D
David Brownell 已提交
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
/*
 * These are the SPI response types for MMC, SD, and SDIO cards.
 * Commands return R1, with maybe more info.  Zero is an error type;
 * callers must always provide the appropriate MMC_RSP_SPI_Rx flags.
 */
#define MMC_RSP_SPI_R1	(MMC_RSP_SPI_S1)
#define MMC_RSP_SPI_R1B	(MMC_RSP_SPI_S1|MMC_RSP_SPI_BUSY)
#define MMC_RSP_SPI_R2	(MMC_RSP_SPI_S1|MMC_RSP_SPI_S2)
#define MMC_RSP_SPI_R3	(MMC_RSP_SPI_S1|MMC_RSP_SPI_B4)
#define MMC_RSP_SPI_R4	(MMC_RSP_SPI_S1|MMC_RSP_SPI_B4)
#define MMC_RSP_SPI_R5	(MMC_RSP_SPI_S1|MMC_RSP_SPI_S2)
#define MMC_RSP_SPI_R7	(MMC_RSP_SPI_S1|MMC_RSP_SPI_B4)

#define mmc_spi_resp_type(cmd)	((cmd)->flags & \
		(MMC_RSP_SPI_S1|MMC_RSP_SPI_BUSY|MMC_RSP_SPI_S2|MMC_RSP_SPI_B4))

R
Russell King 已提交
73 74 75
/*
 * These are the command types.
 */
R
Russell King 已提交
76
#define mmc_cmd_type(cmd)	((cmd)->flags & MMC_CMD_MASK)
L
Linus Torvalds 已提交
77 78 79 80

	unsigned int		retries;	/* max number of retries */
	unsigned int		error;		/* command error */

P
Pierre Ossman 已提交
81 82 83 84 85 86 87 88 89 90 91 92 93
/*
 * Standard errno values are used for errors, but some have specific
 * meaning in the MMC layer:
 *
 * ETIMEDOUT    Card took too long to respond
 * EILSEQ       Basic format problem with the received or sent data
 *              (e.g. CRC check failed, incorrect opcode in response
 *              or bad end bit)
 * EINVAL       Request cannot be performed because of restrictions
 *              in hardware and/or the driver
 * ENOMEDIUM    Host can determine that the slot is empty and is
 *              actively failing requests
 */
L
Linus Torvalds 已提交
94

95 96
	unsigned int		erase_timeout;	/* in milliseconds */

L
Linus Torvalds 已提交
97
	struct mmc_data		*data;		/* data segment associated with cmd */
98
	struct mmc_request	*mrq;		/* associated request */
L
Linus Torvalds 已提交
99 100 101 102 103
};

struct mmc_data {
	unsigned int		timeout_ns;	/* data timeout (in ns, max 80ms) */
	unsigned int		timeout_clks;	/* data timeout (in clocks) */
104
	unsigned int		blksz;		/* data block size */
L
Linus Torvalds 已提交
105 106 107 108 109 110 111 112 113 114 115
	unsigned int		blocks;		/* number of blocks */
	unsigned int		error;		/* data error */
	unsigned int		flags;

#define MMC_DATA_WRITE	(1 << 8)
#define MMC_DATA_READ	(1 << 9)
#define MMC_DATA_STREAM	(1 << 10)

	unsigned int		bytes_xfered;

	struct mmc_command	*stop;		/* stop command */
116
	struct mmc_request	*mrq;		/* associated request */
L
Linus Torvalds 已提交
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133

	unsigned int		sg_len;		/* size of scatter list */
	struct scatterlist	*sg;		/* I/O scatter list */
};

struct mmc_request {
	struct mmc_command	*cmd;
	struct mmc_data		*data;
	struct mmc_command	*stop;

	void			*done_data;	/* completion data */
	void			(*done)(struct mmc_request *);/* completion function */
};

struct mmc_host;
struct mmc_card;

P
Pierre Ossman 已提交
134
extern void mmc_wait_for_req(struct mmc_host *, struct mmc_request *);
L
Linus Torvalds 已提交
135
extern int mmc_wait_for_cmd(struct mmc_host *, struct mmc_command *, int);
P
Pierre Ossman 已提交
136
extern int mmc_wait_for_app_cmd(struct mmc_host *, struct mmc_card *,
P
Pierre Ossman 已提交
137
	struct mmc_command *, int);
L
Linus Torvalds 已提交
138

139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155
#define MMC_ERASE_ARG		0x00000000
#define MMC_SECURE_ERASE_ARG	0x80000000
#define MMC_TRIM_ARG		0x00000001
#define MMC_SECURE_TRIM1_ARG	0x80000001
#define MMC_SECURE_TRIM2_ARG	0x80008000

#define MMC_SECURE_ARGS		0x80000000
#define MMC_TRIM_ARGS		0x00008001

extern int mmc_erase(struct mmc_card *card, unsigned int from, unsigned int nr,
		     unsigned int arg);
extern int mmc_can_erase(struct mmc_card *card);
extern int mmc_can_trim(struct mmc_card *card);
extern int mmc_can_secure_erase_trim(struct mmc_card *card);
extern int mmc_erase_group_aligned(struct mmc_card *card, unsigned int from,
				   unsigned int nr);

156 157
extern int mmc_set_blocklen(struct mmc_card *card, unsigned int blocklen);

158
extern void mmc_set_data_timeout(struct mmc_data *, const struct mmc_card *);
159
extern unsigned int mmc_align_data_size(struct mmc_card *, unsigned int);
160

161
extern int __mmc_claim_host(struct mmc_host *host, atomic_t *abort);
L
Linus Torvalds 已提交
162
extern void mmc_release_host(struct mmc_host *host);
163
extern int mmc_try_claim_host(struct mmc_host *host);
L
Linus Torvalds 已提交
164

165 166 167 168 169 170 171 172 173 174 175
/**
 *	mmc_claim_host - exclusively claim a host
 *	@host: mmc host to claim
 *
 *	Claim a host for a set of operations.
 */
static inline void mmc_claim_host(struct mmc_host *host)
{
	__mmc_claim_host(host, NULL);
}

176 177
extern u32 mmc_vddrange_to_ocrmask(int vdd_min, int vdd_max);

L
Linus Torvalds 已提交
178
#endif