xref: /openbmc/linux/drivers/mmc/host/sdhci-npcm.c (revision 284ab56f)
1284ab56fSTomer Maimon // SPDX-License-Identifier: GPL-2.0+
2284ab56fSTomer Maimon /*
3284ab56fSTomer Maimon  * NPCM SDHC MMC host controller driver.
4284ab56fSTomer Maimon  *
5284ab56fSTomer Maimon  * Copyright (c) 2023 Nuvoton Technology corporation.
6284ab56fSTomer Maimon  */
7284ab56fSTomer Maimon 
8284ab56fSTomer Maimon #include <linux/clk.h>
9284ab56fSTomer Maimon #include <linux/err.h>
10284ab56fSTomer Maimon #include <linux/io.h>
11284ab56fSTomer Maimon #include <linux/mmc/host.h>
12284ab56fSTomer Maimon #include <linux/mmc/mmc.h>
13284ab56fSTomer Maimon #include <linux/mod_devicetable.h>
14284ab56fSTomer Maimon #include <linux/module.h>
15284ab56fSTomer Maimon #include <linux/of.h>
16284ab56fSTomer Maimon 
17284ab56fSTomer Maimon #include "sdhci-pltfm.h"
18284ab56fSTomer Maimon 
19284ab56fSTomer Maimon static const struct sdhci_pltfm_data npcm7xx_sdhci_pdata = {
20284ab56fSTomer Maimon 	.quirks  = SDHCI_QUIRK_DELAY_AFTER_POWER,
21284ab56fSTomer Maimon 	.quirks2 = SDHCI_QUIRK2_STOP_WITH_TC |
22284ab56fSTomer Maimon 		   SDHCI_QUIRK2_NO_1_8_V,
23284ab56fSTomer Maimon };
24284ab56fSTomer Maimon 
25284ab56fSTomer Maimon static const struct sdhci_pltfm_data npcm8xx_sdhci_pdata = {
26284ab56fSTomer Maimon 	.quirks  = SDHCI_QUIRK_DELAY_AFTER_POWER,
27284ab56fSTomer Maimon 	.quirks2 = SDHCI_QUIRK2_STOP_WITH_TC,
28284ab56fSTomer Maimon };
29284ab56fSTomer Maimon 
npcm_sdhci_probe(struct platform_device * pdev)30284ab56fSTomer Maimon static int npcm_sdhci_probe(struct platform_device *pdev)
31284ab56fSTomer Maimon {
32284ab56fSTomer Maimon 	const struct sdhci_pltfm_data *data;
33284ab56fSTomer Maimon 	struct sdhci_pltfm_host *pltfm_host;
34284ab56fSTomer Maimon 	struct device *dev = &pdev->dev;
35284ab56fSTomer Maimon 	struct sdhci_host *host;
36284ab56fSTomer Maimon 	u32 caps;
37284ab56fSTomer Maimon 	int ret;
38284ab56fSTomer Maimon 
39284ab56fSTomer Maimon 	data = of_device_get_match_data(dev);
40284ab56fSTomer Maimon 	if (!data)
41284ab56fSTomer Maimon 		return -EINVAL;
42284ab56fSTomer Maimon 
43284ab56fSTomer Maimon 	host = sdhci_pltfm_init(pdev, data, 0);
44284ab56fSTomer Maimon 	if (IS_ERR(host))
45284ab56fSTomer Maimon 		return PTR_ERR(host);
46284ab56fSTomer Maimon 
47284ab56fSTomer Maimon 	pltfm_host = sdhci_priv(host);
48284ab56fSTomer Maimon 
49284ab56fSTomer Maimon 	pltfm_host->clk = devm_clk_get_optional_enabled(dev, NULL);
50284ab56fSTomer Maimon 	if (IS_ERR(pltfm_host->clk)) {
51284ab56fSTomer Maimon 		ret = PTR_ERR(pltfm_host->clk);
52284ab56fSTomer Maimon 		goto err_sdhci;
53284ab56fSTomer Maimon 	}
54284ab56fSTomer Maimon 
55284ab56fSTomer Maimon 	caps = sdhci_readl(host, SDHCI_CAPABILITIES);
56284ab56fSTomer Maimon 	if (caps & SDHCI_CAN_DO_8BIT)
57284ab56fSTomer Maimon 		host->mmc->caps |= MMC_CAP_8_BIT_DATA;
58284ab56fSTomer Maimon 
59284ab56fSTomer Maimon 	ret = mmc_of_parse(host->mmc);
60284ab56fSTomer Maimon 	if (ret)
61284ab56fSTomer Maimon 		goto err_sdhci;
62284ab56fSTomer Maimon 
63284ab56fSTomer Maimon 	ret = sdhci_add_host(host);
64284ab56fSTomer Maimon 	if (ret)
65284ab56fSTomer Maimon 		goto err_sdhci;
66284ab56fSTomer Maimon 
67284ab56fSTomer Maimon 	return 0;
68284ab56fSTomer Maimon 
69284ab56fSTomer Maimon err_sdhci:
70284ab56fSTomer Maimon 	sdhci_pltfm_free(pdev);
71284ab56fSTomer Maimon 	return ret;
72284ab56fSTomer Maimon }
73284ab56fSTomer Maimon 
74284ab56fSTomer Maimon static const struct of_device_id npcm_sdhci_of_match[] = {
75284ab56fSTomer Maimon 	{ .compatible = "nuvoton,npcm750-sdhci", .data = &npcm7xx_sdhci_pdata },
76284ab56fSTomer Maimon 	{ .compatible = "nuvoton,npcm845-sdhci", .data = &npcm8xx_sdhci_pdata },
77284ab56fSTomer Maimon 	{ }
78284ab56fSTomer Maimon };
79284ab56fSTomer Maimon MODULE_DEVICE_TABLE(of, npcm_sdhci_of_match);
80284ab56fSTomer Maimon 
81284ab56fSTomer Maimon static struct platform_driver npcm_sdhci_driver = {
82284ab56fSTomer Maimon 	.driver = {
83284ab56fSTomer Maimon 		.name	= "npcm-sdhci",
84284ab56fSTomer Maimon 		.of_match_table = npcm_sdhci_of_match,
85284ab56fSTomer Maimon 		.pm	= &sdhci_pltfm_pmops,
86284ab56fSTomer Maimon 	},
87284ab56fSTomer Maimon 	.probe		= npcm_sdhci_probe,
88284ab56fSTomer Maimon 	.remove_new	= sdhci_pltfm_remove,
89284ab56fSTomer Maimon };
90284ab56fSTomer Maimon module_platform_driver(npcm_sdhci_driver);
91284ab56fSTomer Maimon 
92284ab56fSTomer Maimon MODULE_DESCRIPTION("NPCM Secure Digital Host Controller Interface driver");
93284ab56fSTomer Maimon MODULE_AUTHOR("Tomer Maimon <tomer.maimon@nuvoton.com>");
94284ab56fSTomer Maimon MODULE_LICENSE("GPL");
95