1 /* 2 * Copyright 2008,2010 Freescale Semiconductor, Inc 3 * Andy Fleming 4 * 5 * Based (loosely) on the Linux code 6 * 7 * SPDX-License-Identifier: GPL-2.0+ 8 */ 9 10 #ifndef _MMC_PRIVATE_H_ 11 #define _MMC_PRIVATE_H_ 12 13 #include <mmc.h> 14 15 extern int mmc_send_cmd(struct mmc *mmc, struct mmc_cmd *cmd, 16 struct mmc_data *data); 17 #ifdef CONFIG_SPL_BLK_READ_PREPARE 18 int mmc_send_cmd_prepare(struct mmc *mmc, struct mmc_cmd *cmd, 19 struct mmc_data *data); 20 #endif 21 extern int mmc_send_status(struct mmc *mmc, int timeout); 22 extern int mmc_set_blocklen(struct mmc *mmc, int len); 23 #ifdef CONFIG_FSL_ESDHC_ADAPTER_IDENT 24 void mmc_adapter_card_type_ident(void); 25 #endif 26 27 #if CONFIG_IS_ENABLED(BLK) 28 ulong mmc_bread(struct udevice *dev, lbaint_t start, lbaint_t blkcnt, 29 void *dst); 30 #ifdef CONFIG_SPL_BLK_READ_PREPARE 31 ulong mmc_bread_prepare(struct udevice *dev, lbaint_t start, lbaint_t blkcnt, 32 void *dst); 33 #endif 34 #else 35 ulong mmc_bread(struct blk_desc *block_dev, lbaint_t start, lbaint_t blkcnt, 36 void *dst); 37 #ifdef CONFIG_SPL_BLK_READ_PREPARE 38 ulong mmc_bread_prepare(struct blk_desc *block_dev, lbaint_t start, lbaint_t blkcnt, 39 void *dst); 40 #endif 41 #endif 42 43 #if !(defined(CONFIG_SPL_BUILD) && !defined(CONFIG_SPL_SAVEENV)) 44 45 #if CONFIG_IS_ENABLED(BLK) 46 ulong mmc_bwrite(struct udevice *dev, lbaint_t start, lbaint_t blkcnt, 47 const void *src); 48 ulong mmc_berase(struct udevice *dev, lbaint_t start, lbaint_t blkcnt); 49 #else 50 ulong mmc_bwrite(struct blk_desc *block_dev, lbaint_t start, lbaint_t blkcnt, 51 const void *src); 52 ulong mmc_berase(struct blk_desc *block_dev, lbaint_t start, lbaint_t blkcnt); 53 #endif 54 55 #else /* CONFIG_SPL_BUILD and CONFIG_SPL_SAVEENV is not defined */ 56 57 /* declare dummies to reduce code size. */ 58 59 #if CONFIG_IS_ENABLED(BLK) 60 static inline unsigned long mmc_berase(struct udevice *dev, 61 lbaint_t start, lbaint_t blkcnt) 62 { 63 return 0; 64 } 65 66 static inline ulong mmc_bwrite(struct udevice *dev, lbaint_t start, 67 lbaint_t blkcnt, const void *src) 68 { 69 return 0; 70 } 71 #else 72 static inline unsigned long mmc_berase(struct blk_desc *block_dev, 73 lbaint_t start, lbaint_t blkcnt) 74 { 75 return 0; 76 } 77 78 static inline ulong mmc_bwrite(struct blk_desc *block_dev, lbaint_t start, 79 lbaint_t blkcnt, const void *src) 80 { 81 return 0; 82 } 83 #endif 84 85 #endif /* CONFIG_SPL_BUILD */ 86 87 #ifdef CONFIG_MMC_TRACE 88 void mmmc_trace_before_send(struct mmc *mmc, struct mmc_cmd *cmd); 89 void mmmc_trace_after_send(struct mmc *mmc, struct mmc_cmd *cmd, int ret); 90 void mmc_trace_state(struct mmc *mmc, struct mmc_cmd *cmd); 91 #else 92 static inline void mmmc_trace_before_send(struct mmc *mmc, struct mmc_cmd *cmd) 93 { 94 } 95 96 static inline void mmmc_trace_after_send(struct mmc *mmc, struct mmc_cmd *cmd, 97 int ret) 98 { 99 } 100 101 static inline void mmc_trace_state(struct mmc *mmc, struct mmc_cmd *cmd) 102 { 103 } 104 #endif 105 106 /** 107 * mmc_get_next_devnum() - Get the next available MMC device number 108 * 109 * @return next available device number (0 = first), or -ve on error 110 */ 111 int mmc_get_next_devnum(void); 112 113 /** 114 * mmc_do_preinit() - Get an MMC device ready for use 115 */ 116 void mmc_do_preinit(void); 117 118 /** 119 * mmc_list_init() - Set up the list of MMC devices 120 */ 121 void mmc_list_init(void); 122 123 /** 124 * mmc_list_add() - Add a new MMC device to the list of devices 125 * 126 * @mmc: Device to add 127 */ 128 void mmc_list_add(struct mmc *mmc); 129 130 /** 131 * mmc_switch_part() - Switch to a new MMC hardware partition 132 * 133 * @mmc: MMC device 134 * @part_num: Hardware partition number 135 * @return 0 if OK, -ve on error 136 */ 137 int mmc_switch_part(struct mmc *mmc, unsigned int part_num); 138 139 /** 140 * mmc_switch() - Issue and MMC switch mode command 141 * 142 * @mmc: MMC device 143 * @set: Unused 144 * @index: Cmdarg index 145 * @value: Cmdarg value 146 * @return 0 if OK, -ve on error 147 */ 148 int mmc_switch(struct mmc *mmc, u8 set, u8 index, u8 value); 149 150 #endif /* _MMC_PRIVATE_H_ */ 151