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