xref: /OK3568_Linux_fs/kernel/drivers/mmc/core/core.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3  *  linux/drivers/mmc/core/core.h
4  *
5  *  Copyright (C) 2003 Russell King, All Rights Reserved.
6  *  Copyright 2007 Pierre Ossman
7  */
8 #ifndef _MMC_CORE_CORE_H
9 #define _MMC_CORE_CORE_H
10 
11 #include <linux/delay.h>
12 #include <linux/sched.h>
13 
14 struct mmc_host;
15 struct mmc_card;
16 struct mmc_request;
17 
18 #define MMC_CMD_RETRIES        3
19 
20 static const unsigned int freqs[] = { 400000, 300000, 200000, 100000 };
21 
22 struct mmc_bus_ops {
23 	void (*remove)(struct mmc_host *);
24 	void (*detect)(struct mmc_host *);
25 	int (*pre_suspend)(struct mmc_host *);
26 	int (*suspend)(struct mmc_host *);
27 	int (*resume)(struct mmc_host *);
28 	int (*runtime_suspend)(struct mmc_host *);
29 	int (*runtime_resume)(struct mmc_host *);
30 	int (*alive)(struct mmc_host *);
31 	int (*shutdown)(struct mmc_host *);
32 	int (*hw_reset)(struct mmc_host *);
33 	int (*sw_reset)(struct mmc_host *);
34 	bool (*cache_enabled)(struct mmc_host *);
35 
36 	ANDROID_VENDOR_DATA_ARRAY(1, 2);
37 };
38 
39 void mmc_attach_bus(struct mmc_host *host, const struct mmc_bus_ops *ops);
40 void mmc_detach_bus(struct mmc_host *host);
41 
42 struct device_node *mmc_of_find_child_device(struct mmc_host *host,
43 		unsigned func_num);
44 
45 void mmc_init_erase(struct mmc_card *card);
46 
47 void mmc_set_chip_select(struct mmc_host *host, int mode);
48 extern void mmc_set_clock(struct mmc_host *host, unsigned int hz);
49 void mmc_set_bus_mode(struct mmc_host *host, unsigned int mode);
50 void mmc_set_bus_width(struct mmc_host *host, unsigned int width);
51 u32 mmc_select_voltage(struct mmc_host *host, u32 ocr);
52 int mmc_set_uhs_voltage(struct mmc_host *host, u32 ocr);
53 int mmc_host_set_uhs_voltage(struct mmc_host *host);
54 int mmc_set_signal_voltage(struct mmc_host *host, int signal_voltage);
55 void mmc_set_initial_signal_voltage(struct mmc_host *host);
56 void mmc_set_timing(struct mmc_host *host, unsigned int timing);
57 void mmc_set_driver_type(struct mmc_host *host, unsigned int drv_type);
58 int mmc_select_drive_strength(struct mmc_card *card, unsigned int max_dtr,
59 			      int card_drv_type, int *drv_type);
60 void mmc_power_up(struct mmc_host *host, u32 ocr);
61 void mmc_power_off(struct mmc_host *host);
62 void mmc_power_cycle(struct mmc_host *host, u32 ocr);
63 void mmc_set_initial_state(struct mmc_host *host);
64 u32 mmc_vddrange_to_ocrmask(int vdd_min, int vdd_max);
65 
mmc_delay(unsigned int ms)66 static inline void mmc_delay(unsigned int ms)
67 {
68 	if (ms <= 20)
69 		usleep_range(ms * 1000, ms * 1250);
70 	else
71 		msleep(ms);
72 }
73 
74 void mmc_rescan(struct work_struct *work);
75 void mmc_start_host(struct mmc_host *host);
76 void __mmc_stop_host(struct mmc_host *host);
77 void mmc_stop_host(struct mmc_host *host);
78 
79 void _mmc_detect_change(struct mmc_host *host, unsigned long delay,
80 			bool cd_irq);
81 int _mmc_detect_card_removed(struct mmc_host *host);
82 int mmc_detect_card_removed(struct mmc_host *host);
83 
84 int mmc_attach_mmc(struct mmc_host *host);
85 int mmc_attach_sd(struct mmc_host *host);
86 int mmc_attach_sdio(struct mmc_host *host);
87 
88 /* Module parameters */
89 extern bool use_spi_crc;
90 
91 /* Debugfs information for hosts and cards */
92 void mmc_add_host_debugfs(struct mmc_host *host);
93 void mmc_remove_host_debugfs(struct mmc_host *host);
94 
95 void mmc_add_card_debugfs(struct mmc_card *card);
96 void mmc_remove_card_debugfs(struct mmc_card *card);
97 
98 int mmc_execute_tuning(struct mmc_card *card);
99 int mmc_hs200_to_hs400(struct mmc_card *card);
100 int mmc_hs400_to_hs200(struct mmc_card *card);
101 
102 void mmc_wait_for_req_done(struct mmc_host *host, struct mmc_request *mrq);
103 bool mmc_is_req_done(struct mmc_host *host, struct mmc_request *mrq);
104 
105 int mmc_start_request(struct mmc_host *host, struct mmc_request *mrq);
106 
107 int mmc_erase(struct mmc_card *card, unsigned int from, unsigned int nr,
108 		unsigned int arg);
109 int mmc_can_erase(struct mmc_card *card);
110 int mmc_can_trim(struct mmc_card *card);
111 int mmc_can_discard(struct mmc_card *card);
112 int mmc_can_sanitize(struct mmc_card *card);
113 int mmc_can_secure_erase_trim(struct mmc_card *card);
114 int mmc_erase_group_aligned(struct mmc_card *card, unsigned int from,
115 			unsigned int nr);
116 unsigned int mmc_calc_max_discard(struct mmc_card *card);
117 
118 int mmc_set_blocklen(struct mmc_card *card, unsigned int blocklen);
119 
120 int __mmc_claim_host(struct mmc_host *host, struct mmc_ctx *ctx,
121 		     atomic_t *abort);
122 void mmc_release_host(struct mmc_host *host);
123 void mmc_get_card(struct mmc_card *card, struct mmc_ctx *ctx);
124 void mmc_put_card(struct mmc_card *card, struct mmc_ctx *ctx);
125 
126 /**
127  *	mmc_claim_host - exclusively claim a host
128  *	@host: mmc host to claim
129  *
130  *	Claim a host for a set of operations.
131  */
mmc_claim_host(struct mmc_host * host)132 static inline void mmc_claim_host(struct mmc_host *host)
133 {
134 	__mmc_claim_host(host, NULL, NULL);
135 }
136 
137 int mmc_cqe_start_req(struct mmc_host *host, struct mmc_request *mrq);
138 void mmc_cqe_post_req(struct mmc_host *host, struct mmc_request *mrq);
139 int mmc_cqe_recovery(struct mmc_host *host);
140 
141 /**
142  *	mmc_pre_req - Prepare for a new request
143  *	@host: MMC host to prepare command
144  *	@mrq: MMC request to prepare for
145  *
146  *	mmc_pre_req() is called in prior to mmc_start_req() to let
147  *	host prepare for the new request. Preparation of a request may be
148  *	performed while another request is running on the host.
149  */
mmc_pre_req(struct mmc_host * host,struct mmc_request * mrq)150 static inline void mmc_pre_req(struct mmc_host *host, struct mmc_request *mrq)
151 {
152 	if (host->ops->pre_req)
153 		host->ops->pre_req(host, mrq);
154 }
155 
156 /**
157  *	mmc_post_req - Post process a completed request
158  *	@host: MMC host to post process command
159  *	@mrq: MMC request to post process for
160  *	@err: Error, if non zero, clean up any resources made in pre_req
161  *
162  *	Let the host post process a completed request. Post processing of
163  *	a request may be performed while another request is running.
164  */
mmc_post_req(struct mmc_host * host,struct mmc_request * mrq,int err)165 static inline void mmc_post_req(struct mmc_host *host, struct mmc_request *mrq,
166 				int err)
167 {
168 	if (host->ops->post_req)
169 		host->ops->post_req(host, mrq, err);
170 }
171 
mmc_cache_enabled(struct mmc_host * host)172 static inline bool mmc_cache_enabled(struct mmc_host *host)
173 {
174 	if (host->bus_ops->cache_enabled)
175 		return host->bus_ops->cache_enabled(host);
176 
177 	return false;
178 }
179 
180 #endif
181