blob: b1ae0f3f06fc55ccf13d09a001812582be1345b7 [file] [log] [blame]
Lee Leahyeef40eb2017-03-23 10:54:57 -07001/*
Martin Roth0443ac22019-08-30 21:29:41 -06002 * This file is part of the coreboot project.
Lee Leahyeef40eb2017-03-23 10:54:57 -07003 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License as
6 * published by the Free Software Foundation; either version 2 of
7 * the License, or (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 */
14
Lee Leahy48dbc662017-05-08 16:56:03 -070015#ifndef __COMMONLIB_STORAGE_SD_MMC_H__
16#define __COMMONLIB_STORAGE_SD_MMC_H__
Lee Leahyeef40eb2017-03-23 10:54:57 -070017
Lee Leahy48dbc662017-05-08 16:56:03 -070018#include <commonlib/sd_mmc_ctrlr.h>
19#include <commonlib/storage.h>
Lee Leahyeef40eb2017-03-23 10:54:57 -070020#include <stddef.h>
Elyes HAOUAS6ec87da2018-06-01 14:54:11 +020021#include <console/console.h>
Lee Leahyeef40eb2017-03-23 10:54:57 -070022
23#define SD_MMC_IO_RETRIES 1000
24
25#define IS_SD(x) (x->version & SD_VERSION_SD)
26
27#define SET_BUS_WIDTH(ctrlr, width) \
28 do { \
29 ctrlr->bus_width = width; \
30 ctrlr->set_ios(ctrlr); \
31 } while (0)
32
33#define SET_CLOCK(ctrlr, clock_hz) \
34 do { \
35 ctrlr->request_hz = clock_hz; \
36 ctrlr->set_ios(ctrlr); \
37 } while (0)
38
39#define SET_TIMING(ctrlr, timing_value) \
40 do { \
41 ctrlr->timing = timing_value; \
42 ctrlr->set_ios(ctrlr); \
43 } while (0)
44
45/* Common support routines */
46int sd_mmc_enter_standby(struct storage_media *media);
47uint64_t sd_mmc_extract_uint32_bits(const uint32_t *array, int start,
48 int count);
Bora Guvendike1416fd2018-03-08 16:18:54 -080049int sd_mmc_go_idle(struct storage_media *media);
Lee Leahyeef40eb2017-03-23 10:54:57 -070050int sd_mmc_send_status(struct storage_media *media, ssize_t tries);
51int sd_mmc_set_blocklen(struct sd_mmc_ctrlr *ctrlr, int len);
52
53/* MMC support routines */
Lee Leahy48dbc662017-05-08 16:56:03 -070054int mmc_change_freq(struct storage_media *media);
Lee Leahyeef40eb2017-03-23 10:54:57 -070055int mmc_complete_op_cond(struct storage_media *media);
56const char *mmc_partition_name(struct storage_media *media,
57 unsigned int partition_number);
58int mmc_send_ext_csd(struct sd_mmc_ctrlr *ctrlr, unsigned char *ext_csd);
59int mmc_send_op_cond(struct storage_media *media);
Lee Leahy48dbc662017-05-08 16:56:03 -070060int mmc_set_bus_width(struct storage_media *media);
Lee Leahyeef40eb2017-03-23 10:54:57 -070061int mmc_set_partition(struct storage_media *media,
62 unsigned int partition_number);
63int mmc_update_capacity(struct storage_media *media);
64
65/* SD card support routines */
66int sd_change_freq(struct storage_media *media);
67const char *sd_partition_name(struct storage_media *media,
68 unsigned int partition_number);
69int sd_send_if_cond(struct storage_media *media);
70int sd_send_op_cond(struct storage_media *media);
Lee Leahy48dbc662017-05-08 16:56:03 -070071int sd_set_bus_width(struct storage_media *media);
Lee Leahyeef40eb2017-03-23 10:54:57 -070072int sd_set_partition(struct storage_media *media,
73 unsigned int partition_number);
Lee Leahyeef40eb2017-03-23 10:54:57 -070074
75/* Controller debug functions */
76#define sdhc_debug(format...) \
77 do { \
Julius Wernercd49cce2019-03-05 16:53:33 -080078 if (CONFIG(SDHC_DEBUG)) \
Lee Leahyeef40eb2017-03-23 10:54:57 -070079 printk(BIOS_DEBUG, format); \
80 } while (0)
81#define sdhc_trace(format...) \
82 do { \
Julius Wernercd49cce2019-03-05 16:53:33 -080083 if (CONFIG(SDHC_TRACE)) \
Lee Leahyeef40eb2017-03-23 10:54:57 -070084 printk(BIOS_DEBUG, format); \
85 } while (0)
86#define sdhc_error(format...) printk(BIOS_ERR, "ERROR: " format)
87
88/* Card/device debug functions */
89#define sd_mmc_debug(format...) \
90 do { \
Julius Wernercd49cce2019-03-05 16:53:33 -080091 if (CONFIG(SD_MMC_DEBUG)) \
Lee Leahyeef40eb2017-03-23 10:54:57 -070092 printk(BIOS_DEBUG, format); \
93 } while (0)
94#define sd_mmc_trace(format...) \
95 do { \
Julius Wernercd49cce2019-03-05 16:53:33 -080096 if (CONFIG(SD_MMC_TRACE)) \
Lee Leahyeef40eb2017-03-23 10:54:57 -070097 printk(BIOS_DEBUG, format); \
98 } while (0)
99#define sd_mmc_error(format...) printk(BIOS_ERR, "ERROR: " format)
100
Lee Leahy48dbc662017-05-08 16:56:03 -0700101#endif /* __COMMONLIB_STORAGE_SD_MMC_H__ */