xref: /openbmc/linux/drivers/mmc/host/sdhci-brcmstb.c (revision 6d99a79c)
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 	mmc_of_parse(host->mmc);
59 
60 	/*
61 	 * Supply the existing CAPS, but clear the UHS modes. This
62 	 * will allow these modes to be specified by device tree
63 	 * properties through mmc_of_parse().
64 	 */
65 	host->caps = sdhci_readl(host, SDHCI_CAPABILITIES);
66 	if (of_device_is_compatible(pdev->dev.of_node, "brcm,bcm7425-sdhci"))
67 		host->caps &= ~SDHCI_CAN_64BIT;
68 	host->caps1 = sdhci_readl(host, SDHCI_CAPABILITIES_1);
69 	host->caps1 &= ~(SDHCI_SUPPORT_SDR50 | SDHCI_SUPPORT_SDR104 |
70 			SDHCI_SUPPORT_DDR50);
71 	host->quirks |= SDHCI_QUIRK_MISSING_CAPS |
72 		SDHCI_QUIRK_BROKEN_TIMEOUT_VAL;
73 
74 	res = sdhci_add_host(host);
75 	if (res)
76 		goto err;
77 
78 	pltfm_host = sdhci_priv(host);
79 	pltfm_host->clk = clk;
80 	return res;
81 
82 err:
83 	sdhci_pltfm_free(pdev);
84 err_clk:
85 	clk_disable_unprepare(clk);
86 	return res;
87 }
88 
89 static const struct of_device_id sdhci_brcm_of_match[] = {
90 	{ .compatible = "brcm,bcm7425-sdhci" },
91 	{ .compatible = "brcm,bcm7445-sdhci" },
92 	{},
93 };
94 MODULE_DEVICE_TABLE(of, sdhci_brcm_of_match);
95 
96 static struct platform_driver sdhci_brcmstb_driver = {
97 	.driver		= {
98 		.name	= "sdhci-brcmstb",
99 		.pm	= &sdhci_pltfm_pmops,
100 		.of_match_table = of_match_ptr(sdhci_brcm_of_match),
101 	},
102 	.probe		= sdhci_brcmstb_probe,
103 	.remove		= sdhci_pltfm_unregister,
104 };
105 
106 module_platform_driver(sdhci_brcmstb_driver);
107 
108 MODULE_DESCRIPTION("SDHCI driver for Broadcom BRCMSTB SoCs");
109 MODULE_AUTHOR("Broadcom");
110 MODULE_LICENSE("GPL v2");
111