Lee Leahy | eef40eb | 2017-03-23 10:54:57 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2017 Intel Corporation |
| 3 | * |
| 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 Leahy | 48dbc66 | 2017-05-08 16:56:03 -0700 | [diff] [blame^] | 15 | #ifndef __COMMONLIB_STORAGE_SD_MMC_H__ |
| 16 | #define __COMMONLIB_STORAGE_SD_MMC_H__ |
Lee Leahy | eef40eb | 2017-03-23 10:54:57 -0700 | [diff] [blame] | 17 | |
Lee Leahy | 48dbc66 | 2017-05-08 16:56:03 -0700 | [diff] [blame^] | 18 | #include <commonlib/sd_mmc_ctrlr.h> |
| 19 | #include <commonlib/storage.h> |
Lee Leahy | eef40eb | 2017-03-23 10:54:57 -0700 | [diff] [blame] | 20 | #include <stddef.h> |
| 21 | |
| 22 | #define SD_MMC_IO_RETRIES 1000 |
| 23 | |
| 24 | #define IS_SD(x) (x->version & SD_VERSION_SD) |
| 25 | |
| 26 | #define SET_BUS_WIDTH(ctrlr, width) \ |
| 27 | do { \ |
| 28 | ctrlr->bus_width = width; \ |
| 29 | ctrlr->set_ios(ctrlr); \ |
| 30 | } while (0) |
| 31 | |
| 32 | #define SET_CLOCK(ctrlr, clock_hz) \ |
| 33 | do { \ |
| 34 | ctrlr->request_hz = clock_hz; \ |
| 35 | ctrlr->set_ios(ctrlr); \ |
| 36 | } while (0) |
| 37 | |
| 38 | #define SET_TIMING(ctrlr, timing_value) \ |
| 39 | do { \ |
| 40 | ctrlr->timing = timing_value; \ |
| 41 | ctrlr->set_ios(ctrlr); \ |
| 42 | } while (0) |
| 43 | |
| 44 | /* Common support routines */ |
| 45 | int sd_mmc_enter_standby(struct storage_media *media); |
| 46 | uint64_t sd_mmc_extract_uint32_bits(const uint32_t *array, int start, |
| 47 | int count); |
| 48 | int sd_mmc_send_status(struct storage_media *media, ssize_t tries); |
| 49 | int sd_mmc_set_blocklen(struct sd_mmc_ctrlr *ctrlr, int len); |
| 50 | |
| 51 | /* MMC support routines */ |
Lee Leahy | 48dbc66 | 2017-05-08 16:56:03 -0700 | [diff] [blame^] | 52 | int mmc_change_freq(struct storage_media *media); |
Lee Leahy | eef40eb | 2017-03-23 10:54:57 -0700 | [diff] [blame] | 53 | int mmc_complete_op_cond(struct storage_media *media); |
| 54 | const char *mmc_partition_name(struct storage_media *media, |
| 55 | unsigned int partition_number); |
| 56 | int mmc_send_ext_csd(struct sd_mmc_ctrlr *ctrlr, unsigned char *ext_csd); |
| 57 | int mmc_send_op_cond(struct storage_media *media); |
Lee Leahy | 48dbc66 | 2017-05-08 16:56:03 -0700 | [diff] [blame^] | 58 | int mmc_set_bus_width(struct storage_media *media); |
Lee Leahy | eef40eb | 2017-03-23 10:54:57 -0700 | [diff] [blame] | 59 | int mmc_set_partition(struct storage_media *media, |
| 60 | unsigned int partition_number); |
| 61 | int mmc_update_capacity(struct storage_media *media); |
| 62 | |
| 63 | /* SD card support routines */ |
| 64 | int sd_change_freq(struct storage_media *media); |
| 65 | const char *sd_partition_name(struct storage_media *media, |
| 66 | unsigned int partition_number); |
| 67 | int sd_send_if_cond(struct storage_media *media); |
| 68 | int sd_send_op_cond(struct storage_media *media); |
Lee Leahy | 48dbc66 | 2017-05-08 16:56:03 -0700 | [diff] [blame^] | 69 | int sd_set_bus_width(struct storage_media *media); |
Lee Leahy | eef40eb | 2017-03-23 10:54:57 -0700 | [diff] [blame] | 70 | int sd_set_partition(struct storage_media *media, |
| 71 | unsigned int partition_number); |
Lee Leahy | eef40eb | 2017-03-23 10:54:57 -0700 | [diff] [blame] | 72 | |
| 73 | /* Controller debug functions */ |
| 74 | #define sdhc_debug(format...) \ |
| 75 | do { \ |
| 76 | if (IS_ENABLED(CONFIG_SDHC_DEBUG)) \ |
| 77 | printk(BIOS_DEBUG, format); \ |
| 78 | } while (0) |
| 79 | #define sdhc_trace(format...) \ |
| 80 | do { \ |
| 81 | if (IS_ENABLED(CONFIG_SDHC_TRACE)) \ |
| 82 | printk(BIOS_DEBUG, format); \ |
| 83 | } while (0) |
| 84 | #define sdhc_error(format...) printk(BIOS_ERR, "ERROR: " format) |
| 85 | |
| 86 | /* Card/device debug functions */ |
| 87 | #define sd_mmc_debug(format...) \ |
| 88 | do { \ |
| 89 | if (IS_ENABLED(CONFIG_SD_MMC_DEBUG)) \ |
| 90 | printk(BIOS_DEBUG, format); \ |
| 91 | } while (0) |
| 92 | #define sd_mmc_trace(format...) \ |
| 93 | do { \ |
| 94 | if (IS_ENABLED(CONFIG_SD_MMC_TRACE)) \ |
| 95 | printk(BIOS_DEBUG, format); \ |
| 96 | } while (0) |
| 97 | #define sd_mmc_error(format...) printk(BIOS_ERR, "ERROR: " format) |
| 98 | |
Lee Leahy | 48dbc66 | 2017-05-08 16:56:03 -0700 | [diff] [blame^] | 99 | #endif /* __COMMONLIB_STORAGE_SD_MMC_H__ */ |