[mcs814x] nuport-mac: various fixes
[openwrt/svn-archive/archive.git] / package / uboot-xburst / files / cpu / mips / jz_mmc.h
1 /*
2 * linux/drivers/mmc/jz_mmc.h
3 *
4 * Author: Vladimir Shebordaev, Igor Oblakov
5 * Copyright: MontaVista Software Inc.
6 *
7 * $Id: jz_mmc.h,v 1.3 2007-06-15 08:04:20 jlwei Exp $
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation.
12 */
13 #ifndef __MMC_JZMMC_H__
14 #define __MMC_JZMMC_H__
15
16 #include "mmc_protocol.h"
17
18 #define MMC_DEBUG_LEVEL 0 /* Enable Debug: 0 - no debug */
19
20 #define MMC_BLOCK_SIZE 512 /* MMC/SD Block Size */
21
22 #define ID_TO_RCA(x) ((x)+1)
23
24 #define MMC_OCR_ARG 0x00ff8000 /* Argument of OCR */
25
26 enum mmc_result_t {
27 MMC_NO_RESPONSE = -1,
28 MMC_NO_ERROR = 0,
29 MMC_ERROR_OUT_OF_RANGE,
30 MMC_ERROR_ADDRESS,
31 MMC_ERROR_BLOCK_LEN,
32 MMC_ERROR_ERASE_SEQ,
33 MMC_ERROR_ERASE_PARAM,
34 MMC_ERROR_WP_VIOLATION,
35 MMC_ERROR_CARD_IS_LOCKED,
36 MMC_ERROR_LOCK_UNLOCK_FAILED,
37 MMC_ERROR_COM_CRC,
38 MMC_ERROR_ILLEGAL_COMMAND,
39 MMC_ERROR_CARD_ECC_FAILED,
40 MMC_ERROR_CC,
41 MMC_ERROR_GENERAL,
42 MMC_ERROR_UNDERRUN,
43 MMC_ERROR_OVERRUN,
44 MMC_ERROR_CID_CSD_OVERWRITE,
45 MMC_ERROR_STATE_MISMATCH,
46 MMC_ERROR_HEADER_MISMATCH,
47 MMC_ERROR_TIMEOUT,
48 MMC_ERROR_CRC,
49 MMC_ERROR_DRIVER_FAILURE,
50 };
51
52 /* the information structure of MMC/SD Card */
53 typedef struct MMC_INFO
54 {
55 int id; /* Card index */
56 int sd; /* MMC or SD card */
57 int rca; /* RCA */
58 u32 scr; /* SCR 63:32*/
59 int flags; /* Ejected, inserted */
60 enum card_state state; /* empty, ident, ready, whatever */
61
62 /* Card specific information */
63 struct mmc_cid cid;
64 struct mmc_csd csd;
65 u32 block_num;
66 u32 block_len;
67 u32 erase_unit;
68 } mmc_info;
69
70 mmc_info mmcinfo;
71
72 struct mmc_request {
73 int index; /* Slot index - used for CS lines */
74 int cmd; /* Command to send */
75 u32 arg; /* Argument to send */
76 enum mmc_rsp_t rtype; /* Response type expected */
77
78 /* Data transfer (these may be modified at the low level) */
79 u16 nob; /* Number of blocks to transfer*/
80 u16 block_len; /* Block length */
81 u8 *buffer; /* Data buffer */
82 u32 cnt; /* Data length, for PIO */
83
84 /* Results */
85 u8 response[18]; /* Buffer to store response - CRC is optional */
86 enum mmc_result_t result;
87 };
88
89 char * mmc_result_to_string(int);
90 int mmc_unpack_csd(struct mmc_request *request, struct mmc_csd *csd);
91 int mmc_unpack_r1(struct mmc_request *request, struct mmc_response_r1 *r1, enum card_state state);
92 int mmc_unpack_r6(struct mmc_request *request, struct mmc_response_r1 *r1, enum card_state state, int *rca);
93 int mmc_unpack_scr(struct mmc_request *request, struct mmc_response_r1 *r1, enum card_state state, u32 *scr);
94 int mmc_unpack_cid(struct mmc_request *request, struct mmc_cid *cid);
95 int mmc_unpack_r3(struct mmc_request *request, struct mmc_response_r3 *r3);
96
97 void mmc_send_cmd(struct mmc_request *request, int cmd, u32 arg,
98 u16 nob, u16 block_len, enum mmc_rsp_t rtype, u8 *buffer);
99 u32 mmc_tran_speed(u8 ts);
100 void jz_mmc_set_clock(int sd, u32 rate);
101 void jz_mmc_hardware_init(void);
102
103 static inline void mmc_simple_cmd(struct mmc_request *request, int cmd, u32 arg, enum mmc_rsp_t rtype)
104 {
105 mmc_send_cmd( request, cmd, arg, 0, 0, rtype, 0);
106 }
107
108 int mmc_legacy_init(int verbose);
109 int mmc_read(ulong src, uchar *dst, int size);
110 int mmc_write(uchar *src, ulong dst, int size);
111 int mmc2info(ulong addr);
112
113 #endif /* __MMC_JZMMC_H__ */