Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-only */
0002 /*
0003  *  linux/drivers/mmc/core/core.h
0004  *
0005  *  Copyright (C) 2003 Russell King, All Rights Reserved.
0006  *  Copyright 2007 Pierre Ossman
0007  */
0008 #ifndef _MMC_CORE_CORE_H
0009 #define _MMC_CORE_CORE_H
0010 
0011 #include <linux/delay.h>
0012 #include <linux/sched.h>
0013 
0014 struct mmc_host;
0015 struct mmc_card;
0016 struct mmc_request;
0017 
0018 #define MMC_CMD_RETRIES        3
0019 
0020 struct mmc_bus_ops {
0021     void (*remove)(struct mmc_host *);
0022     void (*detect)(struct mmc_host *);
0023     int (*pre_suspend)(struct mmc_host *);
0024     int (*suspend)(struct mmc_host *);
0025     int (*resume)(struct mmc_host *);
0026     int (*runtime_suspend)(struct mmc_host *);
0027     int (*runtime_resume)(struct mmc_host *);
0028     int (*alive)(struct mmc_host *);
0029     int (*shutdown)(struct mmc_host *);
0030     int (*hw_reset)(struct mmc_host *);
0031     int (*sw_reset)(struct mmc_host *);
0032     bool (*cache_enabled)(struct mmc_host *);
0033     int (*flush_cache)(struct mmc_host *);
0034 };
0035 
0036 void mmc_attach_bus(struct mmc_host *host, const struct mmc_bus_ops *ops);
0037 void mmc_detach_bus(struct mmc_host *host);
0038 
0039 struct device_node *mmc_of_find_child_device(struct mmc_host *host,
0040         unsigned func_num);
0041 
0042 void mmc_init_erase(struct mmc_card *card);
0043 
0044 void mmc_set_chip_select(struct mmc_host *host, int mode);
0045 void mmc_set_clock(struct mmc_host *host, unsigned int hz);
0046 void mmc_set_bus_mode(struct mmc_host *host, unsigned int mode);
0047 void mmc_set_bus_width(struct mmc_host *host, unsigned int width);
0048 u32 mmc_select_voltage(struct mmc_host *host, u32 ocr);
0049 int mmc_set_uhs_voltage(struct mmc_host *host, u32 ocr);
0050 int mmc_host_set_uhs_voltage(struct mmc_host *host);
0051 int mmc_set_signal_voltage(struct mmc_host *host, int signal_voltage);
0052 void mmc_set_initial_signal_voltage(struct mmc_host *host);
0053 void mmc_set_timing(struct mmc_host *host, unsigned int timing);
0054 void mmc_set_driver_type(struct mmc_host *host, unsigned int drv_type);
0055 int mmc_select_drive_strength(struct mmc_card *card, unsigned int max_dtr,
0056                   int card_drv_type, int *drv_type);
0057 void mmc_power_up(struct mmc_host *host, u32 ocr);
0058 void mmc_power_off(struct mmc_host *host);
0059 void mmc_power_cycle(struct mmc_host *host, u32 ocr);
0060 void mmc_set_initial_state(struct mmc_host *host);
0061 u32 mmc_vddrange_to_ocrmask(int vdd_min, int vdd_max);
0062 
0063 static inline void mmc_delay(unsigned int ms)
0064 {
0065     if (ms <= 20)
0066         usleep_range(ms * 1000, ms * 1250);
0067     else
0068         msleep(ms);
0069 }
0070 
0071 void mmc_rescan(struct work_struct *work);
0072 void mmc_start_host(struct mmc_host *host);
0073 void __mmc_stop_host(struct mmc_host *host);
0074 void mmc_stop_host(struct mmc_host *host);
0075 
0076 void _mmc_detect_change(struct mmc_host *host, unsigned long delay,
0077             bool cd_irq);
0078 int _mmc_detect_card_removed(struct mmc_host *host);
0079 int mmc_detect_card_removed(struct mmc_host *host);
0080 
0081 int mmc_attach_mmc(struct mmc_host *host);
0082 int mmc_attach_sd(struct mmc_host *host);
0083 int mmc_attach_sdio(struct mmc_host *host);
0084 
0085 /* Module parameters */
0086 extern bool use_spi_crc;
0087 
0088 /* Debugfs information for hosts and cards */
0089 void mmc_add_host_debugfs(struct mmc_host *host);
0090 void mmc_remove_host_debugfs(struct mmc_host *host);
0091 
0092 void mmc_add_card_debugfs(struct mmc_card *card);
0093 void mmc_remove_card_debugfs(struct mmc_card *card);
0094 
0095 int mmc_execute_tuning(struct mmc_card *card);
0096 int mmc_hs200_to_hs400(struct mmc_card *card);
0097 int mmc_hs400_to_hs200(struct mmc_card *card);
0098 
0099 void mmc_wait_for_req_done(struct mmc_host *host, struct mmc_request *mrq);
0100 bool mmc_is_req_done(struct mmc_host *host, struct mmc_request *mrq);
0101 
0102 int mmc_start_request(struct mmc_host *host, struct mmc_request *mrq);
0103 
0104 int mmc_erase(struct mmc_card *card, unsigned int from, unsigned int nr,
0105         unsigned int arg);
0106 int mmc_can_erase(struct mmc_card *card);
0107 int mmc_can_trim(struct mmc_card *card);
0108 int mmc_can_discard(struct mmc_card *card);
0109 int mmc_can_sanitize(struct mmc_card *card);
0110 int mmc_can_secure_erase_trim(struct mmc_card *card);
0111 int mmc_erase_group_aligned(struct mmc_card *card, unsigned int from,
0112             unsigned int nr);
0113 unsigned int mmc_calc_max_discard(struct mmc_card *card);
0114 
0115 int mmc_set_blocklen(struct mmc_card *card, unsigned int blocklen);
0116 
0117 int __mmc_claim_host(struct mmc_host *host, struct mmc_ctx *ctx,
0118              atomic_t *abort);
0119 void mmc_release_host(struct mmc_host *host);
0120 void mmc_get_card(struct mmc_card *card, struct mmc_ctx *ctx);
0121 void mmc_put_card(struct mmc_card *card, struct mmc_ctx *ctx);
0122 
0123 int mmc_card_alternative_gpt_sector(struct mmc_card *card, sector_t *sector);
0124 
0125 /**
0126  *  mmc_claim_host - exclusively claim a host
0127  *  @host: mmc host to claim
0128  *
0129  *  Claim a host for a set of operations.
0130  */
0131 static inline void mmc_claim_host(struct mmc_host *host)
0132 {
0133     __mmc_claim_host(host, NULL, NULL);
0134 }
0135 
0136 int mmc_cqe_start_req(struct mmc_host *host, struct mmc_request *mrq);
0137 void mmc_cqe_post_req(struct mmc_host *host, struct mmc_request *mrq);
0138 int mmc_cqe_recovery(struct mmc_host *host);
0139 
0140 /**
0141  *  mmc_pre_req - Prepare for a new request
0142  *  @host: MMC host to prepare command
0143  *  @mrq: MMC request to prepare for
0144  *
0145  *  mmc_pre_req() is called in prior to mmc_start_req() to let
0146  *  host prepare for the new request. Preparation of a request may be
0147  *  performed while another request is running on the host.
0148  */
0149 static inline void mmc_pre_req(struct mmc_host *host, struct mmc_request *mrq)
0150 {
0151     if (host->ops->pre_req)
0152         host->ops->pre_req(host, mrq);
0153 }
0154 
0155 /**
0156  *  mmc_post_req - Post process a completed request
0157  *  @host: MMC host to post process command
0158  *  @mrq: MMC request to post process for
0159  *  @err: Error, if non zero, clean up any resources made in pre_req
0160  *
0161  *  Let the host post process a completed request. Post processing of
0162  *  a request may be performed while another request is running.
0163  */
0164 static inline void mmc_post_req(struct mmc_host *host, struct mmc_request *mrq,
0165                 int err)
0166 {
0167     if (host->ops->post_req)
0168         host->ops->post_req(host, mrq, err);
0169 }
0170 
0171 static inline bool mmc_cache_enabled(struct mmc_host *host)
0172 {
0173     if (host->bus_ops->cache_enabled)
0174         return host->bus_ops->cache_enabled(host);
0175 
0176     return false;
0177 }
0178 
0179 static inline int mmc_flush_cache(struct mmc_host *host)
0180 {
0181     if (host->bus_ops->flush_cache)
0182         return host->bus_ops->flush_cache(host);
0183 
0184     return 0;
0185 }
0186 
0187 #endif