Patrick Georgi | ac95903 | 2020-05-05 22:49:26 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-or-later */ |
Lee Leahy | eef40eb | 2017-03-23 10:54:57 -0700 | [diff] [blame] | 2 | |
Lee Leahy | 48dbc66 | 2017-05-08 16:56:03 -0700 | [diff] [blame] | 3 | #ifndef __COMMONLIB_STORAGE_SD_MMC_H__ |
| 4 | #define __COMMONLIB_STORAGE_SD_MMC_H__ |
Lee Leahy | eef40eb | 2017-03-23 10:54:57 -0700 | [diff] [blame] | 5 | |
Lee Leahy | 48dbc66 | 2017-05-08 16:56:03 -0700 | [diff] [blame] | 6 | #include <commonlib/sd_mmc_ctrlr.h> |
| 7 | #include <commonlib/storage.h> |
Lee Leahy | eef40eb | 2017-03-23 10:54:57 -0700 | [diff] [blame] | 8 | #include <stddef.h> |
Elyes HAOUAS | 6ec87da | 2018-06-01 14:54:11 +0200 | [diff] [blame] | 9 | #include <console/console.h> |
Lee Leahy | eef40eb | 2017-03-23 10:54:57 -0700 | [diff] [blame] | 10 | |
| 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 */ |
| 34 | int sd_mmc_enter_standby(struct storage_media *media); |
| 35 | uint64_t sd_mmc_extract_uint32_bits(const uint32_t *array, int start, |
| 36 | int count); |
Bora Guvendik | e1416fd | 2018-03-08 16:18:54 -0800 | [diff] [blame] | 37 | int sd_mmc_go_idle(struct storage_media *media); |
Lee Leahy | eef40eb | 2017-03-23 10:54:57 -0700 | [diff] [blame] | 38 | int sd_mmc_send_status(struct storage_media *media, ssize_t tries); |
| 39 | int sd_mmc_set_blocklen(struct sd_mmc_ctrlr *ctrlr, int len); |
| 40 | |
| 41 | /* MMC support routines */ |
Lee Leahy | 48dbc66 | 2017-05-08 16:56:03 -0700 | [diff] [blame] | 42 | int mmc_change_freq(struct storage_media *media); |
Lee Leahy | eef40eb | 2017-03-23 10:54:57 -0700 | [diff] [blame] | 43 | int mmc_complete_op_cond(struct storage_media *media); |
| 44 | const char *mmc_partition_name(struct storage_media *media, |
| 45 | unsigned int partition_number); |
| 46 | int mmc_send_ext_csd(struct sd_mmc_ctrlr *ctrlr, unsigned char *ext_csd); |
| 47 | int mmc_send_op_cond(struct storage_media *media); |
Lee Leahy | 48dbc66 | 2017-05-08 16:56:03 -0700 | [diff] [blame] | 48 | int mmc_set_bus_width(struct storage_media *media); |
Lee Leahy | eef40eb | 2017-03-23 10:54:57 -0700 | [diff] [blame] | 49 | int mmc_set_partition(struct storage_media *media, |
| 50 | unsigned int partition_number); |
| 51 | int mmc_update_capacity(struct storage_media *media); |
Shelley Chen | 419cf93 | 2023-01-11 15:52:20 -0800 | [diff] [blame] | 52 | void mmc_set_early_wake_status(int32_t status); |
| 53 | int mmc_send_cmd1(struct storage_media *media); |
Lee Leahy | eef40eb | 2017-03-23 10:54:57 -0700 | [diff] [blame] | 54 | |
| 55 | /* SD card support routines */ |
| 56 | int sd_change_freq(struct storage_media *media); |
| 57 | const char *sd_partition_name(struct storage_media *media, |
| 58 | unsigned int partition_number); |
| 59 | int sd_send_if_cond(struct storage_media *media); |
| 60 | int sd_send_op_cond(struct storage_media *media); |
Lee Leahy | 48dbc66 | 2017-05-08 16:56:03 -0700 | [diff] [blame] | 61 | int sd_set_bus_width(struct storage_media *media); |
Lee Leahy | eef40eb | 2017-03-23 10:54:57 -0700 | [diff] [blame] | 62 | int sd_set_partition(struct storage_media *media, |
| 63 | unsigned int partition_number); |
Lee Leahy | eef40eb | 2017-03-23 10:54:57 -0700 | [diff] [blame] | 64 | |
| 65 | /* Controller debug functions */ |
| 66 | #define sdhc_debug(format...) \ |
| 67 | do { \ |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 68 | if (CONFIG(SDHC_DEBUG)) \ |
Lee Leahy | eef40eb | 2017-03-23 10:54:57 -0700 | [diff] [blame] | 69 | printk(BIOS_DEBUG, format); \ |
| 70 | } while (0) |
| 71 | #define sdhc_trace(format...) \ |
| 72 | do { \ |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 73 | if (CONFIG(SDHC_TRACE)) \ |
Lee Leahy | eef40eb | 2017-03-23 10:54:57 -0700 | [diff] [blame] | 74 | printk(BIOS_DEBUG, format); \ |
| 75 | } while (0) |
Julius Werner | e966595 | 2022-01-21 17:06:20 -0800 | [diff] [blame] | 76 | #define sdhc_error(format...) printk(BIOS_ERR, format) |
Lee Leahy | eef40eb | 2017-03-23 10:54:57 -0700 | [diff] [blame] | 77 | |
| 78 | /* Card/device debug functions */ |
| 79 | #define sd_mmc_debug(format...) \ |
| 80 | do { \ |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 81 | if (CONFIG(SD_MMC_DEBUG)) \ |
Lee Leahy | eef40eb | 2017-03-23 10:54:57 -0700 | [diff] [blame] | 82 | printk(BIOS_DEBUG, format); \ |
| 83 | } while (0) |
| 84 | #define sd_mmc_trace(format...) \ |
| 85 | do { \ |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 86 | if (CONFIG(SD_MMC_TRACE)) \ |
Lee Leahy | eef40eb | 2017-03-23 10:54:57 -0700 | [diff] [blame] | 87 | printk(BIOS_DEBUG, format); \ |
| 88 | } while (0) |
Julius Werner | e966595 | 2022-01-21 17:06:20 -0800 | [diff] [blame] | 89 | #define sd_mmc_error(format...) printk(BIOS_ERR, format) |
Lee Leahy | eef40eb | 2017-03-23 10:54:57 -0700 | [diff] [blame] | 90 | |
Lee Leahy | 48dbc66 | 2017-05-08 16:56:03 -0700 | [diff] [blame] | 91 | #endif /* __COMMONLIB_STORAGE_SD_MMC_H__ */ |