hc
2023-12-11 6778948f9de86c3cfaf36725a7c87dcff9ba247f
kernel/drivers/mmc/host/tmio_mmc.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0
12 /*
23 * Driver for the MMC / SD / SDIO cell found in:
34 *
....@@ -7,12 +8,9 @@
78 * Copyright (C) 2017 Horms Solutions, Simon Horman
89 * Copyright (C) 2007 Ian Molton
910 * Copyright (C) 2004 Ian Molton
10
- *
11
- * This program is free software; you can redistribute it and/or modify
12
- * it under the terms of the GNU General Public License version 2 as
13
- * published by the Free Software Foundation.
1411 */
1512
13
+#include <linux/delay.h>
1614 #include <linux/device.h>
1715 #include <linux/mfd/core.h>
1816 #include <linux/mfd/tmio.h>
....@@ -22,6 +20,68 @@
2220 #include <linux/scatterlist.h>
2321
2422 #include "tmio_mmc.h"
23
+
24
+/* Registers specific to this variant */
25
+#define CTL_SDIO_REGS 0x100
26
+#define CTL_CLK_AND_WAIT_CTL 0x138
27
+#define CTL_RESET_SDIO 0x1e0
28
+
29
+static void tmio_mmc_clk_start(struct tmio_mmc_host *host)
30
+{
31
+ sd_ctrl_write16(host, CTL_SD_CARD_CLK_CTL, CLK_CTL_SCLKEN |
32
+ sd_ctrl_read16(host, CTL_SD_CARD_CLK_CTL));
33
+
34
+ usleep_range(10000, 11000);
35
+ sd_ctrl_write16(host, CTL_CLK_AND_WAIT_CTL, 0x0100);
36
+ usleep_range(10000, 11000);
37
+}
38
+
39
+static void tmio_mmc_clk_stop(struct tmio_mmc_host *host)
40
+{
41
+ sd_ctrl_write16(host, CTL_CLK_AND_WAIT_CTL, 0x0000);
42
+ usleep_range(10000, 11000);
43
+
44
+ sd_ctrl_write16(host, CTL_SD_CARD_CLK_CTL, ~CLK_CTL_SCLKEN &
45
+ sd_ctrl_read16(host, CTL_SD_CARD_CLK_CTL));
46
+
47
+ usleep_range(10000, 11000);
48
+}
49
+
50
+static void tmio_mmc_set_clock(struct tmio_mmc_host *host,
51
+ unsigned int new_clock)
52
+{
53
+ unsigned int divisor;
54
+ u32 clk = 0;
55
+ int clk_sel;
56
+
57
+ if (new_clock == 0) {
58
+ tmio_mmc_clk_stop(host);
59
+ return;
60
+ }
61
+
62
+ divisor = host->pdata->hclk / new_clock;
63
+
64
+ /* bit7 set: 1/512, ... bit0 set: 1/4, all bits clear: 1/2 */
65
+ clk_sel = (divisor <= 1);
66
+ clk = clk_sel ? 0 : (roundup_pow_of_two(divisor) >> 2);
67
+
68
+ host->pdata->set_clk_div(host->pdev, clk_sel);
69
+
70
+ sd_ctrl_write16(host, CTL_SD_CARD_CLK_CTL, ~CLK_CTL_SCLKEN &
71
+ sd_ctrl_read16(host, CTL_SD_CARD_CLK_CTL));
72
+ sd_ctrl_write16(host, CTL_SD_CARD_CLK_CTL, clk & CLK_CTL_DIV_MASK);
73
+ usleep_range(10000, 11000);
74
+
75
+ tmio_mmc_clk_start(host);
76
+}
77
+
78
+static void tmio_mmc_reset(struct tmio_mmc_host *host)
79
+{
80
+ sd_ctrl_write16(host, CTL_RESET_SDIO, 0x0000);
81
+ usleep_range(10000, 11000);
82
+ sd_ctrl_write16(host, CTL_RESET_SDIO, 0x0001);
83
+ usleep_range(10000, 11000);
84
+}
2585
2686 #ifdef CONFIG_PM_SLEEP
2787 static int tmio_mmc_suspend(struct device *dev)
....@@ -90,8 +150,6 @@
90150 goto cell_disable;
91151 }
92152
93
- pdata->flags |= TMIO_MMC_HAVE_HIGH_REG;
94
-
95153 host = tmio_mmc_host_alloc(pdev, pdata);
96154 if (IS_ERR(host)) {
97155 ret = PTR_ERR(host);
....@@ -100,6 +158,8 @@
100158
101159 /* SD control register space size is 0x200, 0x400 for bus_shift=1 */
102160 host->bus_shift = resource_size(res) >> 10;
161
+ host->set_clock = tmio_mmc_set_clock;
162
+ host->reset = tmio_mmc_reset;
103163
104164 host->mmc->f_max = pdata->hclk;
105165 host->mmc->f_min = pdata->hclk / 512;
....@@ -153,6 +213,7 @@
153213 static struct platform_driver tmio_mmc_driver = {
154214 .driver = {
155215 .name = "tmio-mmc",
216
+ .probe_type = PROBE_PREFER_ASYNCHRONOUS,
156217 .pm = &tmio_mmc_dev_pm_ops,
157218 },
158219 .probe = tmio_mmc_probe,