blob: d54bbc7537ae45e34a195c56b16396c48a4b819b [file] [log] [blame]
Lee Leahyeef40eb2017-03-23 10:54:57 -07001/*
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 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>
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 */
45int sd_mmc_enter_standby(struct storage_media *media);
46uint64_t sd_mmc_extract_uint32_bits(const uint32_t *array, int start,
47 int count);
48int sd_mmc_send_status(struct storage_media *media, ssize_t tries);
49int sd_mmc_set_blocklen(struct sd_mmc_ctrlr *ctrlr, int len);
50
51/* MMC support routines */
Lee Leahy48dbc662017-05-08 16:56:03 -070052int mmc_change_freq(struct storage_media *media);
Lee Leahyeef40eb2017-03-23 10:54:57 -070053int mmc_complete_op_cond(struct storage_media *media);
54const char *mmc_partition_name(struct storage_media *media,
55 unsigned int partition_number);
56int mmc_send_ext_csd(struct sd_mmc_ctrlr *ctrlr, unsigned char *ext_csd);
57int mmc_send_op_cond(struct storage_media *media);
Lee Leahy48dbc662017-05-08 16:56:03 -070058int mmc_set_bus_width(struct storage_media *media);
Lee Leahyeef40eb2017-03-23 10:54:57 -070059int mmc_set_partition(struct storage_media *media,
60 unsigned int partition_number);
61int mmc_update_capacity(struct storage_media *media);
62
63/* SD card support routines */
64int sd_change_freq(struct storage_media *media);
65const char *sd_partition_name(struct storage_media *media,
66 unsigned int partition_number);
67int sd_send_if_cond(struct storage_media *media);
68int sd_send_op_cond(struct storage_media *media);
Lee Leahy48dbc662017-05-08 16:56:03 -070069int sd_set_bus_width(struct storage_media *media);
Lee Leahyeef40eb2017-03-23 10:54:57 -070070int sd_set_partition(struct storage_media *media,
71 unsigned int partition_number);
Lee Leahyeef40eb2017-03-23 10:54:57 -070072
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 Leahy48dbc662017-05-08 16:56:03 -070099#endif /* __COMMONLIB_STORAGE_SD_MMC_H__ */