Commit | Line | Data |
---|---|---|
476bf3d6 AC |
1 | /* |
2 | * sdhci-brcmstb.c Support for SDHCI on Broadcom BRCMSTB SoC's | |
3 | * | |
4 | * Copyright (C) 2015 Broadcom Corporation | |
5 | * | |
6 | * This program is free software; you can redistribute it and/or modify | |
7 | * it under the terms of the GNU General Public License version 2 as | |
8 | * published by the Free Software Foundation. | |
9 | * | |
10 | * This program is distributed in the hope that it will be useful, | |
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | * GNU General Public License for more details. | |
14 | * | |
15 | */ | |
16 | ||
17 | #include <linux/io.h> | |
18 | #include <linux/mmc/host.h> | |
19 | #include <linux/module.h> | |
20 | #include <linux/of.h> | |
21 | ||
22 | #include "sdhci-pltfm.h" | |
23 | ||
24 | #ifdef CONFIG_PM_SLEEP | |
25 | ||
26 | static int sdhci_brcmstb_suspend(struct device *dev) | |
27 | { | |
28 | struct sdhci_host *host = dev_get_drvdata(dev); | |
29 | struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host); | |
30 | int res; | |
31 | ||
d38dcad4 AH |
32 | if (host->tuning_mode != SDHCI_TUNING_MODE_3) |
33 | mmc_retune_needed(host->mmc); | |
34 | ||
476bf3d6 AC |
35 | res = sdhci_suspend_host(host); |
36 | if (res) | |
37 | return res; | |
38 | clk_disable_unprepare(pltfm_host->clk); | |
39 | return res; | |
40 | } | |
41 | ||
42 | static int sdhci_brcmstb_resume(struct device *dev) | |
43 | { | |
44 | struct sdhci_host *host = dev_get_drvdata(dev); | |
45 | struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host); | |
46 | int err; | |
47 | ||
48 | err = clk_prepare_enable(pltfm_host->clk); | |
49 | if (err) | |
50 | return err; | |
51 | return sdhci_resume_host(host); | |
52 | } | |
53 | ||
54 | #endif /* CONFIG_PM_SLEEP */ | |
55 | ||
56 | static SIMPLE_DEV_PM_OPS(sdhci_brcmstb_pmops, sdhci_brcmstb_suspend, | |
57 | sdhci_brcmstb_resume); | |
58 | ||
59 | static const struct sdhci_ops sdhci_brcmstb_ops = { | |
60 | .set_clock = sdhci_set_clock, | |
61 | .set_bus_width = sdhci_set_bus_width, | |
62 | .reset = sdhci_reset, | |
63 | .set_uhs_signaling = sdhci_set_uhs_signaling, | |
64 | }; | |
65 | ||
66 | static struct sdhci_pltfm_data sdhci_brcmstb_pdata = { | |
67 | .ops = &sdhci_brcmstb_ops, | |
68 | }; | |
69 | ||
70 | static int sdhci_brcmstb_probe(struct platform_device *pdev) | |
71 | { | |
72 | struct sdhci_host *host; | |
73 | struct sdhci_pltfm_host *pltfm_host; | |
74 | struct clk *clk; | |
75 | int res; | |
76 | ||
77 | clk = devm_clk_get(&pdev->dev, NULL); | |
78 | if (IS_ERR(clk)) { | |
79 | dev_err(&pdev->dev, "Clock not found in Device Tree\n"); | |
80 | clk = NULL; | |
81 | } | |
82 | res = clk_prepare_enable(clk); | |
83 | if (res) | |
84 | return res; | |
85 | ||
86 | host = sdhci_pltfm_init(pdev, &sdhci_brcmstb_pdata, 0); | |
87 | if (IS_ERR(host)) { | |
88 | res = PTR_ERR(host); | |
89 | goto err_clk; | |
90 | } | |
91 | ||
92 | /* Enable MMC_CAP2_HC_ERASE_SZ for better max discard calculations */ | |
93 | host->mmc->caps2 |= MMC_CAP2_HC_ERASE_SZ; | |
94 | ||
95 | sdhci_get_of_property(pdev); | |
96 | mmc_of_parse(host->mmc); | |
97 | ||
98 | /* | |
99 | * Supply the existing CAPS, but clear the UHS modes. This | |
100 | * will allow these modes to be specified by device tree | |
101 | * properties through mmc_of_parse(). | |
102 | */ | |
103 | host->caps = sdhci_readl(host, SDHCI_CAPABILITIES); | |
6a3d8ced JS |
104 | if (of_device_is_compatible(pdev->dev.of_node, "brcm,bcm7425-sdhci")) |
105 | host->caps &= ~SDHCI_CAN_64BIT; | |
476bf3d6 AC |
106 | host->caps1 = sdhci_readl(host, SDHCI_CAPABILITIES_1); |
107 | host->caps1 &= ~(SDHCI_SUPPORT_SDR50 | SDHCI_SUPPORT_SDR104 | | |
108 | SDHCI_SUPPORT_DDR50); | |
109 | host->quirks |= SDHCI_QUIRK_MISSING_CAPS | | |
110 | SDHCI_QUIRK_BROKEN_TIMEOUT_VAL; | |
111 | ||
112 | res = sdhci_add_host(host); | |
113 | if (res) | |
114 | goto err; | |
115 | ||
116 | pltfm_host = sdhci_priv(host); | |
117 | pltfm_host->clk = clk; | |
118 | return res; | |
119 | ||
120 | err: | |
121 | sdhci_pltfm_free(pdev); | |
122 | err_clk: | |
123 | clk_disable_unprepare(clk); | |
124 | return res; | |
125 | } | |
126 | ||
127 | static const struct of_device_id sdhci_brcm_of_match[] = { | |
128 | { .compatible = "brcm,bcm7425-sdhci" }, | |
6a3d8ced | 129 | { .compatible = "brcm,bcm7445-sdhci" }, |
476bf3d6 AC |
130 | {}, |
131 | }; | |
132 | MODULE_DEVICE_TABLE(of, sdhci_brcm_of_match); | |
133 | ||
134 | static struct platform_driver sdhci_brcmstb_driver = { | |
135 | .driver = { | |
136 | .name = "sdhci-brcmstb", | |
476bf3d6 AC |
137 | .pm = &sdhci_brcmstb_pmops, |
138 | .of_match_table = of_match_ptr(sdhci_brcm_of_match), | |
139 | }, | |
140 | .probe = sdhci_brcmstb_probe, | |
141 | .remove = sdhci_pltfm_unregister, | |
142 | }; | |
143 | ||
144 | module_platform_driver(sdhci_brcmstb_driver); | |
145 | ||
146 | MODULE_DESCRIPTION("SDHCI driver for Broadcom BRCMSTB SoCs"); | |
147 | MODULE_AUTHOR("Broadcom"); | |
148 | MODULE_LICENSE("GPL v2"); |