186958dccSLiming Sun // SPDX-License-Identifier: GPL-2.0
286958dccSLiming Sun /*
386958dccSLiming Sun * Copyright (C) 2018 Mellanox Technologies.
486958dccSLiming Sun */
586958dccSLiming Sun
6*c17aecf8SLiming Sun #include <linux/arm-smccc.h>
786958dccSLiming Sun #include <linux/bitfield.h>
886958dccSLiming Sun #include <linux/bitops.h>
986958dccSLiming Sun #include <linux/mmc/host.h>
1086958dccSLiming Sun #include <linux/mmc/mmc.h>
1186958dccSLiming Sun #include <linux/module.h>
1286958dccSLiming Sun #include <linux/of.h>
1386958dccSLiming Sun #include <linux/platform_device.h>
1486958dccSLiming Sun #include <linux/pm_runtime.h>
1586958dccSLiming Sun
1686958dccSLiming Sun #include "dw_mmc.h"
1786958dccSLiming Sun #include "dw_mmc-pltfm.h"
1886958dccSLiming Sun
1986958dccSLiming Sun #define UHS_REG_EXT_SAMPLE_MASK GENMASK(22, 16)
2086958dccSLiming Sun #define UHS_REG_EXT_DRIVE_MASK GENMASK(29, 23)
2186958dccSLiming Sun #define BLUEFIELD_UHS_REG_EXT_SAMPLE 2
2286958dccSLiming Sun #define BLUEFIELD_UHS_REG_EXT_DRIVE 4
2386958dccSLiming Sun
24*c17aecf8SLiming Sun /* SMC call for RST_N */
25*c17aecf8SLiming Sun #define BLUEFIELD_SMC_SET_EMMC_RST_N 0x82000007
26*c17aecf8SLiming Sun
dw_mci_bluefield_set_ios(struct dw_mci * host,struct mmc_ios * ios)2786958dccSLiming Sun static void dw_mci_bluefield_set_ios(struct dw_mci *host, struct mmc_ios *ios)
2886958dccSLiming Sun {
2986958dccSLiming Sun u32 reg;
3086958dccSLiming Sun
3186958dccSLiming Sun /* Update the Drive and Sample fields in register UHS_REG_EXT. */
3286958dccSLiming Sun reg = mci_readl(host, UHS_REG_EXT);
3386958dccSLiming Sun reg &= ~UHS_REG_EXT_SAMPLE_MASK;
3486958dccSLiming Sun reg |= FIELD_PREP(UHS_REG_EXT_SAMPLE_MASK,
3586958dccSLiming Sun BLUEFIELD_UHS_REG_EXT_SAMPLE);
3686958dccSLiming Sun reg &= ~UHS_REG_EXT_DRIVE_MASK;
3786958dccSLiming Sun reg |= FIELD_PREP(UHS_REG_EXT_DRIVE_MASK, BLUEFIELD_UHS_REG_EXT_DRIVE);
3886958dccSLiming Sun mci_writel(host, UHS_REG_EXT, reg);
3986958dccSLiming Sun }
4086958dccSLiming Sun
dw_mci_bluefield_hw_reset(struct dw_mci * host)41*c17aecf8SLiming Sun static void dw_mci_bluefield_hw_reset(struct dw_mci *host)
42*c17aecf8SLiming Sun {
43*c17aecf8SLiming Sun struct arm_smccc_res res = { 0 };
44*c17aecf8SLiming Sun
45*c17aecf8SLiming Sun arm_smccc_smc(BLUEFIELD_SMC_SET_EMMC_RST_N, 0, 0, 0, 0, 0, 0, 0,
46*c17aecf8SLiming Sun &res);
47*c17aecf8SLiming Sun
48*c17aecf8SLiming Sun if (res.a0)
49*c17aecf8SLiming Sun pr_err("RST_N failed.\n");
50*c17aecf8SLiming Sun }
51*c17aecf8SLiming Sun
5286958dccSLiming Sun static const struct dw_mci_drv_data bluefield_drv_data = {
53*c17aecf8SLiming Sun .set_ios = dw_mci_bluefield_set_ios,
54*c17aecf8SLiming Sun .hw_reset = dw_mci_bluefield_hw_reset
5586958dccSLiming Sun };
5686958dccSLiming Sun
5786958dccSLiming Sun static const struct of_device_id dw_mci_bluefield_match[] = {
5886958dccSLiming Sun { .compatible = "mellanox,bluefield-dw-mshc",
5986958dccSLiming Sun .data = &bluefield_drv_data },
6086958dccSLiming Sun {},
6186958dccSLiming Sun };
6286958dccSLiming Sun MODULE_DEVICE_TABLE(of, dw_mci_bluefield_match);
6386958dccSLiming Sun
dw_mci_bluefield_probe(struct platform_device * pdev)6486958dccSLiming Sun static int dw_mci_bluefield_probe(struct platform_device *pdev)
6586958dccSLiming Sun {
663df407b2SLiming Sun return dw_mci_pltfm_register(pdev, &bluefield_drv_data);
6786958dccSLiming Sun }
6886958dccSLiming Sun
6986958dccSLiming Sun static struct platform_driver dw_mci_bluefield_pltfm_driver = {
7086958dccSLiming Sun .probe = dw_mci_bluefield_probe,
71982fe2e0SUwe Kleine-König .remove_new = dw_mci_pltfm_remove,
7286958dccSLiming Sun .driver = {
7386958dccSLiming Sun .name = "dwmmc_bluefield",
74a1a48919SDouglas Anderson .probe_type = PROBE_PREFER_ASYNCHRONOUS,
7586958dccSLiming Sun .of_match_table = dw_mci_bluefield_match,
7686958dccSLiming Sun .pm = &dw_mci_pltfm_pmops,
7786958dccSLiming Sun },
7886958dccSLiming Sun };
7986958dccSLiming Sun
8086958dccSLiming Sun module_platform_driver(dw_mci_bluefield_pltfm_driver);
8186958dccSLiming Sun
8286958dccSLiming Sun MODULE_DESCRIPTION("BlueField DW Multimedia Card driver");
8386958dccSLiming Sun MODULE_AUTHOR("Mellanox Technologies");
8486958dccSLiming Sun MODULE_LICENSE("GPL v2");
85