blob: ad089432bded6a12ee4211a3b5a5cbd549f3cd12 [file] [log] [blame]
Bo Lv72d0e902023-01-02 14:27:34 +00001/* SPDX-License-Identifier: GPL-2.0+ */
2/*
3 * Copyright 2008,2010 Freescale Semiconductor, Inc
4 * Andy Fleming
5 *
6 * Based (loosely) on the Linux code
7 */
8
9#ifndef _MMC_PRIVATE_H_
10#define _MMC_PRIVATE_H_
11
12#include <clk.h>
13#include <mmc.h>
14#include <asm-generic/gpio.h>
15
16#define SAMSUNG_MID 0x15
17#define KINGSTON_MID 0x70
18#define BIWIN_MID 0xf4
19#define SAMSUNG_FFU_ADDR 0xc7810000
20#define KINGSTON_FFU_ADDR 0x0000ffff
21#define BIWIN_FFU_ADDR 0x0
22#define MAX_TUNING_RETRY (4)
23#define CALI_BLK_CNT (1024)
24#define REFIX_BLK_CNT (100)
25#define CALI_PATTERN_ADDR (0x13800)
26#define TUNING_NUM_PER_POINT 40
27#define MMC_MAX_DESC_NUM 512
28#define MAX_RESPONSE_BYTES 4
29
30/* unknown */
31#define CARD_TYPE_UNKNOWN 0
32/* MMC card */
33#define CARD_TYPE_MMC 1
34/* SD card */
35#define CARD_TYPE_SD 2
36/* SDIO card */
37#define CARD_TYPE_SDIO 3
38/* SD combo (IO+mem) card */
39#define CARD_TYPE_SD_COMBO 4
40/* NON sdio device (means SD/MMC card) */
41#define CARD_TYPE_NON_SDIO 5
42
43#define aml_card_type_unknown(c) ((c)->card_type == CARD_TYPE_UNKNOWN)
44#define aml_card_type_mmc(c) ((c)->card_type == CARD_TYPE_MMC)
45#define aml_card_type_sd(c) ((c)->card_type == CARD_TYPE_SD)
46#define aml_card_type_sdio(c) ((c)->card_type == CARD_TYPE_SDIO)
47#define aml_card_type_non_sdio(c) ((c)->card_type == CARD_TYPE_NON_SDIO)
48
49struct meson_host {
50 struct mmc *mmc;
51 uint is_in;
52 uint is_sduart;
53 uint is_tuning;
54 uint card_type;
55 uint src_clk;
56 uint ignore_desc_busy;
57 uint nwr_cnt;
58 struct clk core;
59 struct clk xtal;
60 struct clk div2;
61 struct clk mux;
62 struct clk div;
63 struct clk gate;
64 struct gpio_desc gpio_cd;
65 struct gpio_desc gpio_reset;
66 char *blk_test;
67 char* desc_buf;
68};
69
70struct meson_mmc_platdata {
71 struct mmc_config cfg;
72 struct mmc mmc;
73 void *regbase;
74 void *w_buf;
75};
76
77extern int mmc_send_cmd(struct mmc *mmc, struct mmc_cmd *cmd,
78 struct mmc_data *data);
79extern int mmc_send_status(struct mmc *mmc, int timeout);
80extern int mmc_set_blocklen(struct mmc *mmc, int len);
81#ifdef CONFIG_FSL_ESDHC_ADAPTER_IDENT
82void mmc_adapter_card_type_ident(void);
83#endif
84
85#if CONFIG_IS_ENABLED(BLK)
86ulong mmc_bread(struct udevice *dev, lbaint_t start, lbaint_t blkcnt,
87 void *dst);
88#else
89ulong mmc_bread(struct blk_desc *block_dev, lbaint_t start, lbaint_t blkcnt,
90 void *dst);
91#endif
92
93#if CONFIG_IS_ENABLED(MMC_WRITE)
94
95#if CONFIG_IS_ENABLED(BLK)
96ulong mmc_bwrite(struct udevice *dev, lbaint_t start, lbaint_t blkcnt,
97 const void *src);
98ulong mmc_berase(struct udevice *dev, lbaint_t start, lbaint_t blkcnt);
99#else
100ulong mmc_bwrite(struct blk_desc *block_dev, lbaint_t start, lbaint_t blkcnt,
101 const void *src);
102ulong mmc_berase(struct blk_desc *block_dev, lbaint_t start, lbaint_t blkcnt);
103#endif
104
105#else /* CONFIG_SPL_MMC_WRITE is not defined */
106
107/* declare dummies to reduce code size. */
108
109#if CONFIG_IS_ENABLED(BLK)
110static inline unsigned long mmc_berase(struct udevice *dev,
111 lbaint_t start, lbaint_t blkcnt)
112{
113 return 0;
114}
115
116static inline ulong mmc_bwrite(struct udevice *dev, lbaint_t start,
117 lbaint_t blkcnt, const void *src)
118{
119 return 0;
120}
121#else
122static inline unsigned long mmc_berase(struct blk_desc *block_dev,
123 lbaint_t start, lbaint_t blkcnt)
124{
125 return 0;
126}
127
128static inline ulong mmc_bwrite(struct blk_desc *block_dev, lbaint_t start,
129 lbaint_t blkcnt, const void *src)
130{
131 return 0;
132}
133#endif
134
135#endif /* CONFIG_SPL_BUILD */
136
137void meson_post_hs400_timming(struct udevice *dev);
138void mmc_hs400_timming(struct mmc *mmc);
139
140#ifdef CONFIG_MMC_TRACE
141void mmmc_trace_before_send(struct mmc *mmc, struct mmc_cmd *cmd);
142void mmmc_trace_after_send(struct mmc *mmc, struct mmc_cmd *cmd, int ret);
143void mmc_trace_state(struct mmc *mmc, struct mmc_cmd *cmd);
144#else
145static inline void mmmc_trace_before_send(struct mmc *mmc, struct mmc_cmd *cmd)
146{
147}
148
149static inline void mmmc_trace_after_send(struct mmc *mmc, struct mmc_cmd *cmd,
150 int ret)
151{
152}
153
154static inline void mmc_trace_state(struct mmc *mmc, struct mmc_cmd *cmd)
155{
156}
157#endif
158
159/**
160 * mmc_get_next_devnum() - Get the next available MMC device number
161 *
162 * @return next available device number (0 = first), or -ve on error
163 */
164int mmc_get_next_devnum(void);
165
166/**
167 * mmc_do_preinit() - Get an MMC device ready for use
168 */
169void mmc_do_preinit(void);
170
171/**
172 * mmc_list_init() - Set up the list of MMC devices
173 */
174void mmc_list_init(void);
175
176/**
177 * mmc_list_add() - Add a new MMC device to the list of devices
178 *
179 * @mmc: Device to add
180 */
181void mmc_list_add(struct mmc *mmc);
182
183/**
184 * mmc_switch_part() - Switch to a new MMC hardware partition
185 *
186 * @mmc: MMC device
187 * @part_num: Hardware partition number
188 * @return 0 if OK, -ve on error
189 */
190int mmc_switch_part(struct mmc *mmc, unsigned int part_num);
191
192/**
193 * mmc_switch() - Issue and MMC switch mode command
194 *
195 * @mmc: MMC device
196 * @set: Unused
197 * @index: Cmdarg index
198 * @value: Cmdarg value
199 * @return 0 if OK, -ve on error
200 */
201int mmc_switch(struct mmc *mmc, u8 set, u8 index, u8 value);
202
203int emmc_boot_chk(struct mmc *mmc);
204#endif /* _MMC_PRIVATE_H_ */