Bo Lv | 72d0e90 | 2023-01-02 14:27:34 +0000 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0+ */ |
| 2 | /* |
| 3 | * Copyright 2008,2010 Freescale Semiconductor, Inc |
| 4 | * Andy Fleming |
| 5 | * |
| 6 | * Based (loosely) on the Linux code |
| 7 | */ |
| 8 | |
| 9 | #ifndef _MMC_PRIVATE_H_ |
| 10 | #define _MMC_PRIVATE_H_ |
| 11 | |
| 12 | #include <clk.h> |
| 13 | #include <mmc.h> |
| 14 | #include <asm-generic/gpio.h> |
| 15 | |
| 16 | #define SAMSUNG_MID 0x15 |
| 17 | #define KINGSTON_MID 0x70 |
| 18 | #define BIWIN_MID 0xf4 |
| 19 | #define SAMSUNG_FFU_ADDR 0xc7810000 |
| 20 | #define KINGSTON_FFU_ADDR 0x0000ffff |
| 21 | #define BIWIN_FFU_ADDR 0x0 |
| 22 | #define MAX_TUNING_RETRY (4) |
| 23 | #define CALI_BLK_CNT (1024) |
| 24 | #define REFIX_BLK_CNT (100) |
Bo Lv | 72d0e90 | 2023-01-02 14:27:34 +0000 | [diff] [blame] | 25 | #define TUNING_NUM_PER_POINT 40 |
| 26 | #define MMC_MAX_DESC_NUM 512 |
| 27 | #define MAX_RESPONSE_BYTES 4 |
| 28 | |
| 29 | /* unknown */ |
| 30 | #define CARD_TYPE_UNKNOWN 0 |
| 31 | /* MMC card */ |
| 32 | #define CARD_TYPE_MMC 1 |
| 33 | /* SD card */ |
| 34 | #define CARD_TYPE_SD 2 |
| 35 | /* SDIO card */ |
| 36 | #define CARD_TYPE_SDIO 3 |
| 37 | /* SD combo (IO+mem) card */ |
| 38 | #define CARD_TYPE_SD_COMBO 4 |
| 39 | /* NON sdio device (means SD/MMC card) */ |
| 40 | #define CARD_TYPE_NON_SDIO 5 |
| 41 | |
| 42 | #define aml_card_type_unknown(c) ((c)->card_type == CARD_TYPE_UNKNOWN) |
| 43 | #define aml_card_type_mmc(c) ((c)->card_type == CARD_TYPE_MMC) |
| 44 | #define aml_card_type_sd(c) ((c)->card_type == CARD_TYPE_SD) |
| 45 | #define aml_card_type_sdio(c) ((c)->card_type == CARD_TYPE_SDIO) |
| 46 | #define aml_card_type_non_sdio(c) ((c)->card_type == CARD_TYPE_NON_SDIO) |
| 47 | |
| 48 | struct meson_host { |
| 49 | struct mmc *mmc; |
| 50 | uint is_in; |
| 51 | uint is_sduart; |
| 52 | uint is_tuning; |
| 53 | uint card_type; |
| 54 | uint src_clk; |
| 55 | uint ignore_desc_busy; |
| 56 | uint nwr_cnt; |
| 57 | struct clk core; |
| 58 | struct clk xtal; |
| 59 | struct clk div2; |
| 60 | struct clk mux; |
| 61 | struct clk div; |
| 62 | struct clk gate; |
| 63 | struct gpio_desc gpio_cd; |
| 64 | struct gpio_desc gpio_reset; |
| 65 | char *blk_test; |
| 66 | char* desc_buf; |
| 67 | }; |
| 68 | |
| 69 | struct meson_mmc_platdata { |
| 70 | struct mmc_config cfg; |
| 71 | struct mmc mmc; |
| 72 | void *regbase; |
| 73 | void *w_buf; |
| 74 | }; |
| 75 | |
| 76 | extern int mmc_send_cmd(struct mmc *mmc, struct mmc_cmd *cmd, |
| 77 | struct mmc_data *data); |
| 78 | extern int mmc_send_status(struct mmc *mmc, int timeout); |
| 79 | extern int mmc_set_blocklen(struct mmc *mmc, int len); |
| 80 | #ifdef CONFIG_FSL_ESDHC_ADAPTER_IDENT |
| 81 | void mmc_adapter_card_type_ident(void); |
| 82 | #endif |
| 83 | |
| 84 | #if CONFIG_IS_ENABLED(BLK) |
| 85 | ulong mmc_bread(struct udevice *dev, lbaint_t start, lbaint_t blkcnt, |
| 86 | void *dst); |
| 87 | #else |
| 88 | ulong mmc_bread(struct blk_desc *block_dev, lbaint_t start, lbaint_t blkcnt, |
| 89 | void *dst); |
| 90 | #endif |
| 91 | |
| 92 | #if CONFIG_IS_ENABLED(MMC_WRITE) |
| 93 | |
| 94 | #if CONFIG_IS_ENABLED(BLK) |
| 95 | ulong mmc_bwrite(struct udevice *dev, lbaint_t start, lbaint_t blkcnt, |
| 96 | const void *src); |
| 97 | ulong mmc_berase(struct udevice *dev, lbaint_t start, lbaint_t blkcnt); |
| 98 | #else |
| 99 | ulong mmc_bwrite(struct blk_desc *block_dev, lbaint_t start, lbaint_t blkcnt, |
| 100 | const void *src); |
| 101 | ulong mmc_berase(struct blk_desc *block_dev, lbaint_t start, lbaint_t blkcnt); |
| 102 | #endif |
| 103 | |
| 104 | #else /* CONFIG_SPL_MMC_WRITE is not defined */ |
| 105 | |
| 106 | /* declare dummies to reduce code size. */ |
| 107 | |
| 108 | #if CONFIG_IS_ENABLED(BLK) |
| 109 | static inline unsigned long mmc_berase(struct udevice *dev, |
| 110 | lbaint_t start, lbaint_t blkcnt) |
| 111 | { |
| 112 | return 0; |
| 113 | } |
| 114 | |
| 115 | static inline ulong mmc_bwrite(struct udevice *dev, lbaint_t start, |
| 116 | lbaint_t blkcnt, const void *src) |
| 117 | { |
| 118 | return 0; |
| 119 | } |
| 120 | #else |
| 121 | static inline unsigned long mmc_berase(struct blk_desc *block_dev, |
| 122 | lbaint_t start, lbaint_t blkcnt) |
| 123 | { |
| 124 | return 0; |
| 125 | } |
| 126 | |
| 127 | static inline ulong mmc_bwrite(struct blk_desc *block_dev, lbaint_t start, |
| 128 | lbaint_t blkcnt, const void *src) |
| 129 | { |
| 130 | return 0; |
| 131 | } |
| 132 | #endif |
| 133 | |
| 134 | #endif /* CONFIG_SPL_BUILD */ |
| 135 | |
| 136 | void meson_post_hs400_timming(struct udevice *dev); |
| 137 | void mmc_hs400_timming(struct mmc *mmc); |
| 138 | |
| 139 | #ifdef CONFIG_MMC_TRACE |
| 140 | void mmmc_trace_before_send(struct mmc *mmc, struct mmc_cmd *cmd); |
| 141 | void mmmc_trace_after_send(struct mmc *mmc, struct mmc_cmd *cmd, int ret); |
| 142 | void mmc_trace_state(struct mmc *mmc, struct mmc_cmd *cmd); |
| 143 | #else |
| 144 | static inline void mmmc_trace_before_send(struct mmc *mmc, struct mmc_cmd *cmd) |
| 145 | { |
| 146 | } |
| 147 | |
| 148 | static inline void mmmc_trace_after_send(struct mmc *mmc, struct mmc_cmd *cmd, |
| 149 | int ret) |
| 150 | { |
| 151 | } |
| 152 | |
| 153 | static inline void mmc_trace_state(struct mmc *mmc, struct mmc_cmd *cmd) |
| 154 | { |
| 155 | } |
| 156 | #endif |
| 157 | |
| 158 | /** |
| 159 | * mmc_get_next_devnum() - Get the next available MMC device number |
| 160 | * |
| 161 | * @return next available device number (0 = first), or -ve on error |
| 162 | */ |
| 163 | int mmc_get_next_devnum(void); |
| 164 | |
| 165 | /** |
| 166 | * mmc_do_preinit() - Get an MMC device ready for use |
| 167 | */ |
| 168 | void mmc_do_preinit(void); |
| 169 | |
| 170 | /** |
| 171 | * mmc_list_init() - Set up the list of MMC devices |
| 172 | */ |
| 173 | void mmc_list_init(void); |
| 174 | |
| 175 | /** |
| 176 | * mmc_list_add() - Add a new MMC device to the list of devices |
| 177 | * |
| 178 | * @mmc: Device to add |
| 179 | */ |
| 180 | void mmc_list_add(struct mmc *mmc); |
| 181 | |
| 182 | /** |
| 183 | * mmc_switch_part() - Switch to a new MMC hardware partition |
| 184 | * |
| 185 | * @mmc: MMC device |
| 186 | * @part_num: Hardware partition number |
| 187 | * @return 0 if OK, -ve on error |
| 188 | */ |
| 189 | int mmc_switch_part(struct mmc *mmc, unsigned int part_num); |
| 190 | |
| 191 | /** |
| 192 | * mmc_switch() - Issue and MMC switch mode command |
| 193 | * |
| 194 | * @mmc: MMC device |
| 195 | * @set: Unused |
| 196 | * @index: Cmdarg index |
| 197 | * @value: Cmdarg value |
| 198 | * @return 0 if OK, -ve on error |
| 199 | */ |
| 200 | int mmc_switch(struct mmc *mmc, u8 set, u8 index, u8 value); |
| 201 | |
| 202 | int emmc_boot_chk(struct mmc *mmc); |
| 203 | #endif /* _MMC_PRIVATE_H_ */ |