xref: /openbmc/linux/drivers/mmc/host/sdhci-brcmstb.c (revision be709d48)
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 static const struct sdhci_ops sdhci_brcmstb_ops = {
25 	.set_clock = sdhci_set_clock,
26 	.set_bus_width = sdhci_set_bus_width,
27 	.reset = sdhci_reset,
28 	.set_uhs_signaling = sdhci_set_uhs_signaling,
29 };
30 
31 static const struct sdhci_pltfm_data sdhci_brcmstb_pdata = {
32 	.ops = &sdhci_brcmstb_ops,
33 };
34 
35 static int sdhci_brcmstb_probe(struct platform_device *pdev)
36 {
37 	struct sdhci_host *host;
38 	struct sdhci_pltfm_host *pltfm_host;
39 	struct clk *clk;
40 	int res;
41 
42 	clk = devm_clk_get(&pdev->dev, NULL);
43 	if (IS_ERR(clk)) {
44 		dev_err(&pdev->dev, "Clock not found in Device Tree\n");
45 		clk = NULL;
46 	}
47 	res = clk_prepare_enable(clk);
48 	if (res)
49 		return res;
50 
51 	host = sdhci_pltfm_init(pdev, &sdhci_brcmstb_pdata, 0);
52 	if (IS_ERR(host)) {
53 		res = PTR_ERR(host);
54 		goto err_clk;
55 	}
56 
57 	sdhci_get_of_property(pdev);
58 	res = mmc_of_parse(host->mmc);
59 	if (res)
60 		goto err;
61 
62 	/*
63 	 * Supply the existing CAPS, but clear the UHS modes. This
64 	 * will allow these modes to be specified by device tree
65 	 * properties through mmc_of_parse().
66 	 */
67 	host->caps = sdhci_readl(host, SDHCI_CAPABILITIES);
68 	if (of_device_is_compatible(pdev->dev.of_node, "brcm,bcm7425-sdhci"))
69 		host->caps &= ~SDHCI_CAN_64BIT;
70 	host->caps1 = sdhci_readl(host, SDHCI_CAPABILITIES_1);
71 	host->caps1 &= ~(SDHCI_SUPPORT_SDR50 | SDHCI_SUPPORT_SDR104 |
72 			SDHCI_SUPPORT_DDR50);
73 	host->quirks |= SDHCI_QUIRK_MISSING_CAPS |
74 		SDHCI_QUIRK_BROKEN_TIMEOUT_VAL;
75 
76 	res = sdhci_add_host(host);
77 	if (res)
78 		goto err;
79 
80 	pltfm_host = sdhci_priv(host);
81 	pltfm_host->clk = clk;
82 	return res;
83 
84 err:
85 	sdhci_pltfm_free(pdev);
86 err_clk:
87 	clk_disable_unprepare(clk);
88 	return res;
89 }
90 
91 static const struct of_device_id sdhci_brcm_of_match[] = {
92 	{ .compatible = "brcm,bcm7425-sdhci" },
93 	{ .compatible = "brcm,bcm7445-sdhci" },
94 	{},
95 };
96 MODULE_DEVICE_TABLE(of, sdhci_brcm_of_match);
97 
98 static struct platform_driver sdhci_brcmstb_driver = {
99 	.driver		= {
100 		.name	= "sdhci-brcmstb",
101 		.pm	= &sdhci_pltfm_pmops,
102 		.of_match_table = of_match_ptr(sdhci_brcm_of_match),
103 	},
104 	.probe		= sdhci_brcmstb_probe,
105 	.remove		= sdhci_pltfm_unregister,
106 };
107 
108 module_platform_driver(sdhci_brcmstb_driver);
109 
110 MODULE_DESCRIPTION("SDHCI driver for Broadcom BRCMSTB SoCs");
111 MODULE_AUTHOR("Broadcom");
112 MODULE_LICENSE("GPL v2");
113