1 // SPDX-License-Identifier: GPL-2.0 2 /* 3 * Copyright (C) 2018 Mellanox Technologies. 4 */ 5 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> 12 #include <linux/of.h> 13 #include <linux/platform_device.h> 14 #include <linux/pm_runtime.h> 15 16 #include "dw_mmc.h" 17 #include "dw_mmc-pltfm.h" 18 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 23 24 /* SMC call for RST_N */ 25 #define BLUEFIELD_SMC_SET_EMMC_RST_N 0x82000007 26 27 static void dw_mci_bluefield_set_ios(struct dw_mci *host, struct mmc_ios *ios) 28 { 29 u32 reg; 30 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); 39 } 40 41 static void dw_mci_bluefield_hw_reset(struct dw_mci *host) 42 { 43 struct arm_smccc_res res = { 0 }; 44 45 arm_smccc_smc(BLUEFIELD_SMC_SET_EMMC_RST_N, 0, 0, 0, 0, 0, 0, 0, 46 &res); 47 48 if (res.a0) 49 pr_err("RST_N failed.\n"); 50 } 51 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 55 }; 56 57 static const struct of_device_id dw_mci_bluefield_match[] = { 58 { .compatible = "mellanox,bluefield-dw-mshc", 59 .data = &bluefield_drv_data }, 60 {}, 61 }; 62 MODULE_DEVICE_TABLE(of, dw_mci_bluefield_match); 63 64 static int dw_mci_bluefield_probe(struct platform_device *pdev) 65 { 66 return dw_mci_pltfm_register(pdev, &bluefield_drv_data); 67 } 68 69 static struct platform_driver dw_mci_bluefield_pltfm_driver = { 70 .probe = dw_mci_bluefield_probe, 71 .remove_new = dw_mci_pltfm_remove, 72 .driver = { 73 .name = "dwmmc_bluefield", 74 .probe_type = PROBE_PREFER_ASYNCHRONOUS, 75 .of_match_table = dw_mci_bluefield_match, 76 .pm = &dw_mci_pltfm_pmops, 77 }, 78 }; 79 80 module_platform_driver(dw_mci_bluefield_pltfm_driver); 81 82 MODULE_DESCRIPTION("BlueField DW Multimedia Card driver"); 83 MODULE_AUTHOR("Mellanox Technologies"); 84 MODULE_LICENSE("GPL v2"); 85