| 1 |
// SPDX-License-Identifier: GPL-2.0+ |
| 2 |
/* |
| 3 |
* NPCM SDHC MMC host controller driver. |
| 4 |
* |
| 5 |
* Copyright (c) 2023 Nuvoton Technology corporation. |
| 6 |
*/ |
| 7 |
|
| 8 |
#include <linux/clk.h> |
| 9 |
#include <linux/err.h> |
| 10 |
#include <linux/io.h> |
| 11 |
#include <linux/mmc/host.h> |
| 12 |
#include <linux/mmc/mmc.h> |
| 13 |
#include <linux/mod_devicetable.h> |
| 14 |
#include <linux/module.h> |
| 15 |
#include <linux/of.h> |
| 16 |
|
| 17 |
#include "sdhci-pltfm.h" |
| 18 |
|
| 19 |
static const struct sdhci_pltfm_data npcm7xx_sdhci_pdata = { |
| 20 |
.quirks = SDHCI_QUIRK_DELAY_AFTER_POWER, |
| 21 |
.quirks2 = SDHCI_QUIRK2_STOP_WITH_TC | |
| 22 |
SDHCI_QUIRK2_NO_1_8_V, |
| 23 |
}; |
| 24 |
|
| 25 |
static const struct sdhci_pltfm_data npcm8xx_sdhci_pdata = { |
| 26 |
.quirks = SDHCI_QUIRK_DELAY_AFTER_POWER, |
| 27 |
.quirks2 = SDHCI_QUIRK2_STOP_WITH_TC, |
| 28 |
}; |
| 29 |
|
| 30 |
static int npcm_sdhci_probe(struct platform_device *pdev) |
| 31 |
{ |
| 32 |
const struct sdhci_pltfm_data *data; |
| 33 |
struct sdhci_pltfm_host *pltfm_host; |
| 34 |
struct device *dev = &pdev->dev; |
| 35 |
struct sdhci_host *host; |
| 36 |
u32 caps; |
| 37 |
int ret; |
| 38 |
|
| 39 |
data = of_device_get_match_data(dev); |
| 40 |
if (!data) |
| 41 |
return -EINVAL; |
| 42 |
|
| 43 |
host = sdhci_pltfm_init(pdev, data, 0); |
| 44 |
if (IS_ERR(host)) |
| 45 |
return PTR_ERR(host); |
| 46 |
|
| 47 |
pltfm_host = sdhci_priv(host); |
| 48 |
|
| 49 |
pltfm_host->clk = devm_clk_get_optional_enabled(dev, NULL); |
| 50 |
if (IS_ERR(pltfm_host->clk)) { |
| 51 |
return PTR_ERR(pltfm_host->clk); |
| 52 |
} |
| 53 |
|
| 54 |
caps = sdhci_readl(host, SDHCI_CAPABILITIES); |
| 55 |
if (caps & SDHCI_CAN_DO_8BIT) |
| 56 |
host->mmc->caps |= MMC_CAP_8_BIT_DATA; |
| 57 |
|
| 58 |
ret = mmc_of_parse(host->mmc); |
| 59 |
if (ret) |
| 60 |
return ret; |
| 61 |
|
| 62 |
return sdhci_add_host(host); |
| 63 |
} |
| 64 |
|
| 65 |
static const struct of_device_id npcm_sdhci_of_match[] = { |
| 66 |
{ .compatible = "nuvoton,npcm750-sdhci", .data = &npcm7xx_sdhci_pdata }, |
| 67 |
{ .compatible = "nuvoton,npcm845-sdhci", .data = &npcm8xx_sdhci_pdata }, |
| 68 |
{ } |
| 69 |
}; |
| 70 |
MODULE_DEVICE_TABLE(of, npcm_sdhci_of_match); |
| 71 |
|
| 72 |
static struct platform_driver npcm_sdhci_driver = { |
| 73 |
.driver = { |
| 74 |
.name = "npcm-sdhci", |
| 75 |
.of_match_table = npcm_sdhci_of_match, |
| 76 |
.pm = &sdhci_pltfm_pmops, |
| 77 |
}, |
| 78 |
.probe = npcm_sdhci_probe, |
| 79 |
.remove = sdhci_pltfm_remove, |
| 80 |
}; |
| 81 |
module_platform_driver(npcm_sdhci_driver); |
| 82 |
|
| 83 |
MODULE_DESCRIPTION("NPCM Secure Digital Host Controller Interface driver"); |
| 84 |
MODULE_AUTHOR("Tomer Maimon <[email protected]>"); |
| 85 |
MODULE_LICENSE("GPL"); |