blob: 411a4a305296c9b7847fa86124f5814fbb9dcf45 [file] [log] [blame]
Patrick Georgiac959032020-05-05 22:49:26 +02001/* SPDX-License-Identifier: GPL-2.0-or-later */
Lee Leahyeef40eb2017-03-23 10:54:57 -07002
Lee Leahy48dbc662017-05-08 16:56:03 -07003#ifndef __COMMONLIB_STORAGE_SD_MMC_H__
4#define __COMMONLIB_STORAGE_SD_MMC_H__
Lee Leahyeef40eb2017-03-23 10:54:57 -07005
Lee Leahy48dbc662017-05-08 16:56:03 -07006#include <commonlib/sd_mmc_ctrlr.h>
7#include <commonlib/storage.h>
Lee Leahyeef40eb2017-03-23 10:54:57 -07008#include <stddef.h>
Elyes HAOUAS6ec87da2018-06-01 14:54:11 +02009#include <console/console.h>
Lee Leahyeef40eb2017-03-23 10:54:57 -070010
11#define SD_MMC_IO_RETRIES 1000
12
13#define IS_SD(x) (x->version & SD_VERSION_SD)
14
15#define SET_BUS_WIDTH(ctrlr, width) \
16 do { \
17 ctrlr->bus_width = width; \
18 ctrlr->set_ios(ctrlr); \
19 } while (0)
20
21#define SET_CLOCK(ctrlr, clock_hz) \
22 do { \
23 ctrlr->request_hz = clock_hz; \
24 ctrlr->set_ios(ctrlr); \
25 } while (0)
26
27#define SET_TIMING(ctrlr, timing_value) \
28 do { \
29 ctrlr->timing = timing_value; \
30 ctrlr->set_ios(ctrlr); \
31 } while (0)
32
33/* Common support routines */
34int sd_mmc_enter_standby(struct storage_media *media);
35uint64_t sd_mmc_extract_uint32_bits(const uint32_t *array, int start,
36 int count);
Bora Guvendike1416fd2018-03-08 16:18:54 -080037int sd_mmc_go_idle(struct storage_media *media);
Lee Leahyeef40eb2017-03-23 10:54:57 -070038int sd_mmc_send_status(struct storage_media *media, ssize_t tries);
39int sd_mmc_set_blocklen(struct sd_mmc_ctrlr *ctrlr, int len);
40
41/* MMC support routines */
Lee Leahy48dbc662017-05-08 16:56:03 -070042int mmc_change_freq(struct storage_media *media);
Lee Leahyeef40eb2017-03-23 10:54:57 -070043int mmc_complete_op_cond(struct storage_media *media);
44const char *mmc_partition_name(struct storage_media *media,
45 unsigned int partition_number);
46int mmc_send_ext_csd(struct sd_mmc_ctrlr *ctrlr, unsigned char *ext_csd);
47int mmc_send_op_cond(struct storage_media *media);
Lee Leahy48dbc662017-05-08 16:56:03 -070048int mmc_set_bus_width(struct storage_media *media);
Lee Leahyeef40eb2017-03-23 10:54:57 -070049int mmc_set_partition(struct storage_media *media,
50 unsigned int partition_number);
51int mmc_update_capacity(struct storage_media *media);
52
53/* SD card support routines */
54int sd_change_freq(struct storage_media *media);
55const char *sd_partition_name(struct storage_media *media,
56 unsigned int partition_number);
57int sd_send_if_cond(struct storage_media *media);
58int sd_send_op_cond(struct storage_media *media);
Lee Leahy48dbc662017-05-08 16:56:03 -070059int sd_set_bus_width(struct storage_media *media);
Lee Leahyeef40eb2017-03-23 10:54:57 -070060int sd_set_partition(struct storage_media *media,
61 unsigned int partition_number);
Lee Leahyeef40eb2017-03-23 10:54:57 -070062
63/* Controller debug functions */
64#define sdhc_debug(format...) \
65 do { \
Julius Wernercd49cce2019-03-05 16:53:33 -080066 if (CONFIG(SDHC_DEBUG)) \
Lee Leahyeef40eb2017-03-23 10:54:57 -070067 printk(BIOS_DEBUG, format); \
68 } while (0)
69#define sdhc_trace(format...) \
70 do { \
Julius Wernercd49cce2019-03-05 16:53:33 -080071 if (CONFIG(SDHC_TRACE)) \
Lee Leahyeef40eb2017-03-23 10:54:57 -070072 printk(BIOS_DEBUG, format); \
73 } while (0)
Julius Wernere9665952022-01-21 17:06:20 -080074#define sdhc_error(format...) printk(BIOS_ERR, format)
Lee Leahyeef40eb2017-03-23 10:54:57 -070075
76/* Card/device debug functions */
77#define sd_mmc_debug(format...) \
78 do { \
Julius Wernercd49cce2019-03-05 16:53:33 -080079 if (CONFIG(SD_MMC_DEBUG)) \
Lee Leahyeef40eb2017-03-23 10:54:57 -070080 printk(BIOS_DEBUG, format); \
81 } while (0)
82#define sd_mmc_trace(format...) \
83 do { \
Julius Wernercd49cce2019-03-05 16:53:33 -080084 if (CONFIG(SD_MMC_TRACE)) \
Lee Leahyeef40eb2017-03-23 10:54:57 -070085 printk(BIOS_DEBUG, format); \
86 } while (0)
Julius Wernere9665952022-01-21 17:06:20 -080087#define sd_mmc_error(format...) printk(BIOS_ERR, format)
Lee Leahyeef40eb2017-03-23 10:54:57 -070088
Lee Leahy48dbc662017-05-08 16:56:03 -070089#endif /* __COMMONLIB_STORAGE_SD_MMC_H__ */