|
| 1 | +/* |
| 2 | + * Copyright 2022 NXP |
| 3 | + * |
| 4 | + * SPDX-License-Identifier: Apache-2.0 |
| 5 | + */ |
| 6 | + |
| 7 | +/** |
| 8 | + * @file |
| 9 | + * @brief Public API for SD subsystem |
| 10 | + */ |
| 11 | + |
| 12 | +#ifndef ZEPHYR_INCLUDE_SD_SD_H_ |
| 13 | +#define ZEPHYR_INCLUDE_SD_SD_H_ |
| 14 | + |
| 15 | +#include <zephyr/device.h> |
| 16 | +#include <zephyr/drivers/sdhc.h> |
| 17 | + |
| 18 | +#ifdef __cplusplus |
| 19 | +extern "C" { |
| 20 | +#endif |
| 21 | + |
| 22 | +/** |
| 23 | + * @brief card status. Used interally by subsystem. |
| 24 | + */ |
| 25 | +enum card_status { |
| 26 | + CARD_UNINITIALIZED = 0, /*!< card has not been initialized */ |
| 27 | + CARD_ERROR = 1, /*!< card state is error */ |
| 28 | + CARD_INITIALIZED = 2, /*!< card is in valid state */ |
| 29 | +}; |
| 30 | + |
| 31 | +/** |
| 32 | + * @brief card type. Used interally by subsystem. |
| 33 | + */ |
| 34 | +enum card_type { |
| 35 | + CARD_SDMMC = 0, /*!< SD memory card */ |
| 36 | + CARD_SDIO = 1, /*!< SD I/O card */ |
| 37 | + CARD_COMBO = 2, /*!< SD memory and I/O card */ |
| 38 | +}; |
| 39 | + |
| 40 | + |
| 41 | +/** |
| 42 | + * @brief SD card structure |
| 43 | + * |
| 44 | + * This structure is used by the subsystem to track an individual SD |
| 45 | + * device connected to the system. The application may access these |
| 46 | + * fields, but use caution when changing values. |
| 47 | + */ |
| 48 | +struct sd_card { |
| 49 | + const struct device *sdhc; /*!< SD host controller for card */ |
| 50 | + struct sdhc_io bus_io; /*!< Current bus I/O props for SDHC */ |
| 51 | + enum sd_voltage card_voltage; /*!< Card signal voltage */ |
| 52 | + struct k_mutex lock; /*!< card mutex */ |
| 53 | + struct sdhc_host_props host_props; /*!< SDHC host properties */ |
| 54 | + uint32_t ocr; /*!< Raw card OCR content */ |
| 55 | + struct sd_switch_caps switch_caps; /*!< SD switch capabilities */ |
| 56 | + uint32_t num_io; /*!< I/O function count. 0 for SD cards */ |
| 57 | + uint32_t relative_addr; /*!< Card relative address */ |
| 58 | + uint32_t block_count; /*!< Number of blocks in SD card */ |
| 59 | + uint32_t block_size; /*!< SD block size */ |
| 60 | + uint32_t sd_version; /*!< SD specification version */ |
| 61 | + enum sd_timing_mode card_speed; /*!< Card timing mode */ |
| 62 | + enum card_status status; /*!< Card status */ |
| 63 | + enum card_type type; /*!< Card type */ |
| 64 | + uint32_t flags; /*!< Card flags */ |
| 65 | + uint8_t card_buffer[CONFIG_SD_BUFFER_SIZE] |
| 66 | + __aligned(CONFIG_SDHC_BUFFER_ALIGNMENT); /* Card internal buffer */ |
| 67 | +}; |
| 68 | + |
| 69 | +/** |
| 70 | + * @brief Initialize an SD device |
| 71 | + * |
| 72 | + * Initializes an SD device to use with the subsystem. After this call, |
| 73 | + * only the SD card structure is required to access the card. |
| 74 | + * @param sdhc_dev SD host controller device for this card |
| 75 | + * @param card SD card structure for this card |
| 76 | + * @retval 0 card was initialized |
| 77 | + * @retval -ETIMEDOUT: card initialization timed out |
| 78 | + * @retval -EBUSY: card is busy |
| 79 | + * @retval -EIO: IO error while starting card |
| 80 | + */ |
| 81 | +int sd_init(const struct device *sdhc_dev, struct sd_card *card); |
| 82 | + |
| 83 | +/** |
| 84 | + * @brief checks to see if card is present in the SD slot |
| 85 | + * |
| 86 | + * @param sdhc_dev SD host controller to check for card presence on |
| 87 | + * @retval true card is present |
| 88 | + * @retval false card is not present |
| 89 | + */ |
| 90 | +bool sd_is_card_present(const struct device *sdhc_dev); |
| 91 | + |
| 92 | + |
| 93 | +#ifdef __cplusplus |
| 94 | +} |
| 95 | +#endif |
| 96 | + |
| 97 | +#endif /* ZEPHYR_INCLUDE_SD_SD_H_ */ |
0 commit comments