1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (C) 2018 Mellanox Technologies.
6 #include <linux/arm-smccc.h>
7 #include <linux/bitfield.h>
8 #include <linux/bitops.h>
9 #include <linux/mmc/host.h>
10 #include <linux/mmc/mmc.h>
11 #include <linux/module.h>
13 #include <linux/platform_device.h>
14 #include <linux/pm_runtime.h>
17 #include "dw_mmc-pltfm.h"
19 #define UHS_REG_EXT_SAMPLE_MASK GENMASK(22, 16)
20 #define UHS_REG_EXT_DRIVE_MASK GENMASK(29, 23)
21 #define BLUEFIELD_UHS_REG_EXT_SAMPLE 2
22 #define BLUEFIELD_UHS_REG_EXT_DRIVE 4
24 /* SMC call for RST_N */
25 #define BLUEFIELD_SMC_SET_EMMC_RST_N 0x82000007
27 static void dw_mci_bluefield_set_ios(struct dw_mci
*host
, struct mmc_ios
*ios
)
31 /* Update the Drive and Sample fields in register UHS_REG_EXT. */
32 reg
= mci_readl(host
, UHS_REG_EXT
);
33 reg
&= ~UHS_REG_EXT_SAMPLE_MASK
;
34 reg
|= FIELD_PREP(UHS_REG_EXT_SAMPLE_MASK
,
35 BLUEFIELD_UHS_REG_EXT_SAMPLE
);
36 reg
&= ~UHS_REG_EXT_DRIVE_MASK
;
37 reg
|= FIELD_PREP(UHS_REG_EXT_DRIVE_MASK
, BLUEFIELD_UHS_REG_EXT_DRIVE
);
38 mci_writel(host
, UHS_REG_EXT
, reg
);
41 static void dw_mci_bluefield_hw_reset(struct dw_mci
*host
)
43 struct arm_smccc_res res
= { 0 };
45 arm_smccc_smc(BLUEFIELD_SMC_SET_EMMC_RST_N
, 0, 0, 0, 0, 0, 0, 0,
49 pr_err("RST_N failed.\n");
52 static const struct dw_mci_drv_data bluefield_drv_data
= {
53 .set_ios
= dw_mci_bluefield_set_ios
,
54 .hw_reset
= dw_mci_bluefield_hw_reset
57 static const struct of_device_id dw_mci_bluefield_match
[] = {
58 { .compatible
= "mellanox,bluefield-dw-mshc",
59 .data
= &bluefield_drv_data
},
62 MODULE_DEVICE_TABLE(of
, dw_mci_bluefield_match
);
64 static int dw_mci_bluefield_probe(struct platform_device
*pdev
)
66 return dw_mci_pltfm_register(pdev
, &bluefield_drv_data
);
69 static struct platform_driver dw_mci_bluefield_pltfm_driver
= {
70 .probe
= dw_mci_bluefield_probe
,
71 .remove
= dw_mci_pltfm_remove
,
73 .name
= "dwmmc_bluefield",
74 .probe_type
= PROBE_PREFER_ASYNCHRONOUS
,
75 .of_match_table
= dw_mci_bluefield_match
,
76 .pm
= &dw_mci_pltfm_pmops
,
80 module_platform_driver(dw_mci_bluefield_pltfm_driver
);
82 MODULE_DESCRIPTION("BlueField DW Multimedia Card driver");
83 MODULE_AUTHOR("Mellanox Technologies");
84 MODULE_LICENSE("GPL v2");