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 int mmc_set_blockcount(struct mmc *mmc, unsigned int blkcnt, bool is_rel_write); 24 #ifdef CONFIG_FSL_ESDHC_ADAPTER_IDENT 25 void mmc_adapter_card_type_ident(void); 26 #endif 27 28 #if CONFIG_IS_ENABLED(BLK) 29 ulong mmc_bread(struct udevice *dev, lbaint_t start, lbaint_t blkcnt, 30 void *dst); 31 #ifdef CONFIG_SPL_BLK_READ_PREPARE 32 ulong mmc_bread_prepare(struct udevice *dev, lbaint_t start, lbaint_t blkcnt, 33 void *dst); 34 #endif 35 #else 36 ulong mmc_bread(struct blk_desc *block_dev, lbaint_t start, lbaint_t blkcnt, 37 void *dst); 38 #ifdef CONFIG_SPL_BLK_READ_PREPARE 39 ulong mmc_bread_prepare(struct blk_desc *block_dev, lbaint_t start, lbaint_t blkcnt, 40 void *dst); 41 #endif 42 #endif 43 44 #if CONFIG_IS_ENABLED(MMC_WRITE) 45 46 #if CONFIG_IS_ENABLED(BLK) 47 ulong mmc_bwrite(struct udevice *dev, lbaint_t start, lbaint_t blkcnt, 48 const void *src); 49 ulong mmc_berase(struct udevice *dev, lbaint_t start, lbaint_t blkcnt); 50 #else 51 ulong mmc_bwrite(struct blk_desc *block_dev, lbaint_t start, lbaint_t blkcnt, 52 const void *src); 53 ulong mmc_berase(struct blk_desc *block_dev, lbaint_t start, lbaint_t blkcnt); 54 #endif 55 56 #else /* CONFIG_SPL_MMC_WRITE is not defined */ 57 58 /* declare dummies to reduce code size. */ 59 60 #if CONFIG_IS_ENABLED(BLK) 61 static inline unsigned long mmc_berase(struct udevice *dev, 62 lbaint_t start, lbaint_t blkcnt) 63 { 64 return 0; 65 } 66 67 static inline ulong mmc_bwrite(struct udevice *dev, lbaint_t start, 68 lbaint_t blkcnt, const void *src) 69 { 70 return 0; 71 } 72 #else 73 static inline unsigned long mmc_berase(struct blk_desc *block_dev, 74 lbaint_t start, lbaint_t blkcnt) 75 { 76 return 0; 77 } 78 79 static inline ulong mmc_bwrite(struct blk_desc *block_dev, lbaint_t start, 80 lbaint_t blkcnt, const void *src) 81 { 82 return 0; 83 } 84 #endif 85 86 #endif /* CONFIG_SPL_BUILD */ 87 88 #ifdef CONFIG_MMC_TRACE 89 void mmmc_trace_before_send(struct mmc *mmc, struct mmc_cmd *cmd); 90 void mmmc_trace_after_send(struct mmc *mmc, struct mmc_cmd *cmd, int ret); 91 void mmc_trace_state(struct mmc *mmc, struct mmc_cmd *cmd); 92 #else 93 static inline void mmmc_trace_before_send(struct mmc *mmc, struct mmc_cmd *cmd) 94 { 95 } 96 97 static inline void mmmc_trace_after_send(struct mmc *mmc, struct mmc_cmd *cmd, 98 int ret) 99 { 100 } 101 102 static inline void mmc_trace_state(struct mmc *mmc, struct mmc_cmd *cmd) 103 { 104 } 105 #endif 106 107 /** 108 * mmc_get_next_devnum() - Get the next available MMC device number 109 * 110 * @return next available device number (0 = first), or -ve on error 111 */ 112 int mmc_get_next_devnum(void); 113 114 /** 115 * mmc_do_preinit() - Get an MMC device ready for use 116 */ 117 void mmc_do_preinit(void); 118 119 /** 120 * mmc_list_init() - Set up the list of MMC devices 121 */ 122 void mmc_list_init(void); 123 124 /** 125 * mmc_list_add() - Add a new MMC device to the list of devices 126 * 127 * @mmc: Device to add 128 */ 129 void mmc_list_add(struct mmc *mmc); 130 131 /** 132 * mmc_switch_part() - Switch to a new MMC hardware partition 133 * 134 * @mmc: MMC device 135 * @part_num: Hardware partition number 136 * @return 0 if OK, -ve on error 137 */ 138 int mmc_switch_part(struct mmc *mmc, unsigned int part_num); 139 140 /** 141 * mmc_switch() - Issue and MMC switch mode command 142 * 143 * @mmc: MMC device 144 * @set: Unused 145 * @index: Cmdarg index 146 * @value: Cmdarg value 147 * @return 0 if OK, -ve on error 148 */ 149 int mmc_switch(struct mmc *mmc, u8 set, u8 index, u8 value); 150 151 #endif /* _MMC_PRIVATE_H_ */ 152