1 // SPDX-License-Identifier: GPL-2.0-only
3 * SDHCI support for CNS3xxx SoC
5 * Copyright 2008 Cavium Networks
6 * Copyright 2010 MontaVista Software, LLC.
9 * Anton Vorontsov <avorontsov@mvista.com>
12 #include <linux/delay.h>
13 #include <linux/device.h>
14 #include <linux/mmc/host.h>
15 #include <linux/module.h>
16 #include "sdhci-pltfm.h"
18 static unsigned int sdhci_cns3xxx_get_max_clk(struct sdhci_host
*host
)
23 static void sdhci_cns3xxx_set_clock(struct sdhci_host
*host
, unsigned int clock
)
25 struct device
*dev
= mmc_dev(host
->mmc
);
28 unsigned long timeout
;
30 host
->mmc
->actual_clock
= 0;
32 sdhci_writew(host
, 0, SDHCI_CLOCK_CONTROL
);
37 while (host
->max_clk
/ div
> clock
) {
39 * On CNS3xxx divider grows linearly up to 4, and then
40 * exponentially up to 256.
50 dev_dbg(dev
, "desired SD clock: %d, actual: %d\n",
51 clock
, host
->max_clk
/ div
);
53 /* Divide by 3 is special. */
57 clk
= div
<< SDHCI_DIVIDER_SHIFT
;
58 clk
|= SDHCI_CLOCK_INT_EN
;
59 sdhci_writew(host
, clk
, SDHCI_CLOCK_CONTROL
);
62 while (!((clk
= sdhci_readw(host
, SDHCI_CLOCK_CONTROL
))
63 & SDHCI_CLOCK_INT_STABLE
)) {
65 dev_warn(dev
, "clock is unstable");
72 clk
|= SDHCI_CLOCK_CARD_EN
;
73 sdhci_writew(host
, clk
, SDHCI_CLOCK_CONTROL
);
76 static const struct sdhci_ops sdhci_cns3xxx_ops
= {
77 .get_max_clock
= sdhci_cns3xxx_get_max_clk
,
78 .set_clock
= sdhci_cns3xxx_set_clock
,
79 .set_bus_width
= sdhci_set_bus_width
,
81 .set_uhs_signaling
= sdhci_set_uhs_signaling
,
84 static const struct sdhci_pltfm_data sdhci_cns3xxx_pdata
= {
85 .ops
= &sdhci_cns3xxx_ops
,
86 .quirks
= SDHCI_QUIRK_BROKEN_DMA
|
87 SDHCI_QUIRK_DATA_TIMEOUT_USES_SDCLK
|
88 SDHCI_QUIRK_INVERTED_WRITE_PROTECT
|
89 SDHCI_QUIRK_CAP_CLOCK_BASE_BROKEN
|
90 SDHCI_QUIRK_BROKEN_TIMEOUT_VAL
,
93 static int sdhci_cns3xxx_probe(struct platform_device
*pdev
)
95 return sdhci_pltfm_register(pdev
, &sdhci_cns3xxx_pdata
, 0);
98 static struct platform_driver sdhci_cns3xxx_driver
= {
100 .name
= "sdhci-cns3xxx",
101 .pm
= &sdhci_pltfm_pmops
,
103 .probe
= sdhci_cns3xxx_probe
,
104 .remove
= sdhci_pltfm_unregister
,
107 module_platform_driver(sdhci_cns3xxx_driver
);
109 MODULE_DESCRIPTION("SDHCI driver for CNS3xxx");
110 MODULE_AUTHOR("Scott Shu, "
111 "Anton Vorontsov <avorontsov@mvista.com>");
112 MODULE_LICENSE("GPL v2");