15 #include <linux/device.h>
19 #include <linux/export.h>
21 #include <linux/slab.h>
30 #define cls_dev_to_mmc_host(d) container_of(d, struct mmc_host, class_dev)
32 static void mmc_host_classdev_release(
struct device *
dev)
39 static struct class mmc_host_class = {
41 .dev_release = mmc_host_classdev_release,
57 #ifdef CONFIG_MMC_CLKGATE
71 if (kstrtoul(buf, 0, &value))
75 host->clkgate_delay =
value;
76 spin_unlock_irqrestore(&host->clk_lock, flags);
87 static void mmc_host_clk_gate_delayed(
struct mmc_host *host)
89 unsigned long tick_ns;
90 unsigned long freq = host->
ios.clock;
94 pr_debug(
"%s: frequency set to 0 in disable function, "
95 "this means the clock is already disabled.\n",
111 if (!host->clk_requests) {
112 spin_unlock_irqrestore(&host->clk_lock, flags);
114 ndelay(host->clk_delay * tick_ns);
117 spin_unlock_irqrestore(&host->clk_lock, flags);
122 if (!host->clk_requests) {
123 spin_unlock_irqrestore(&host->clk_lock, flags);
129 spin_unlock_irqrestore(&host->clk_lock, flags);
141 mmc_host_clk_gate_delayed(host);
152 void mmc_host_clk_hold(
struct mmc_host *host)
160 if (host->clk_gated) {
161 spin_unlock_irqrestore(&host->clk_lock, flags);
166 host->clk_requests++;
167 spin_unlock_irqrestore(&host->clk_lock, flags);
175 static bool mmc_host_may_gate_card(
struct mmc_card *
card)
199 void mmc_host_clk_release(
struct mmc_host *host)
204 host->clk_requests--;
205 if (mmc_host_may_gate_card(host->
card) &&
209 spin_unlock_irqrestore(&host->clk_lock, flags);
218 unsigned int mmc_host_clk_rate(
struct mmc_host *host)
225 freq = host->clk_old;
227 freq = host->
ios.clock;
228 spin_unlock_irqrestore(&host->clk_lock, flags);
236 static inline void mmc_host_clk_init(
struct mmc_host *host)
238 host->clk_requests = 0;
245 host->clkgate_delay = 0;
246 host->clk_gated =
false;
256 static inline void mmc_host_clk_exit(
struct mmc_host *host)
263 mmc_host_clk_gate_delayed(host);
265 mmc_host_clk_hold(host);
267 WARN_ON(host->clk_requests > 1);
270 static inline void mmc_host_clk_sysfs_init(
struct mmc_host *host)
272 host->clkgate_delay_attr.show = clkgate_delay_show;
273 host->clkgate_delay_attr.store = clkgate_delay_store;
275 host->clkgate_delay_attr.attr.name =
"clkgate_delay";
278 pr_err(
"%s: Failed to create clkgate_delay sysfs entry\n",
283 static inline void mmc_host_clk_init(
struct mmc_host *host)
287 static inline void mmc_host_clk_exit(
struct mmc_host *host)
291 static inline void mmc_host_clk_sysfs_init(
struct mmc_host *host)
318 spin_lock(&mmc_host_lock);
320 spin_unlock(&mmc_host_lock);
331 mmc_host_clk_init(host);
376 !host->
ops->enable_sdio_irq);
384 #ifdef CONFIG_DEBUG_FS
387 mmc_host_clk_sysfs_init(host);
407 unregister_pm_notifier(&host->
pm_notify);
410 #ifdef CONFIG_DEBUG_FS
418 mmc_host_clk_exit(host);
431 spin_lock(&mmc_host_lock);
433 spin_unlock(&mmc_host_lock);