1 // SPDX-License-Identifier: GPL-2.0 2 /* 3 * Copyright (C) 2018 Mellanox Technologies. 4 * 5 * This program is free software; you can redistribute it and/or modify 6 * it under the terms of the GNU General Public License as published by 7 * the Free Software Foundation; either version 2 of the License, or 8 * (at your option) any later version. 9 */ 10 11 #include <linux/bitfield.h> 12 #include <linux/bitops.h> 13 #include <linux/mmc/host.h> 14 #include <linux/mmc/mmc.h> 15 #include <linux/module.h> 16 #include <linux/of.h> 17 #include <linux/platform_device.h> 18 #include <linux/pm_runtime.h> 19 20 #include "dw_mmc.h" 21 #include "dw_mmc-pltfm.h" 22 23 #define UHS_REG_EXT_SAMPLE_MASK GENMASK(22, 16) 24 #define UHS_REG_EXT_DRIVE_MASK GENMASK(29, 23) 25 #define BLUEFIELD_UHS_REG_EXT_SAMPLE 2 26 #define BLUEFIELD_UHS_REG_EXT_DRIVE 4 27 28 static void dw_mci_bluefield_set_ios(struct dw_mci *host, struct mmc_ios *ios) 29 { 30 u32 reg; 31 32 /* Update the Drive and Sample fields in register UHS_REG_EXT. */ 33 reg = mci_readl(host, UHS_REG_EXT); 34 reg &= ~UHS_REG_EXT_SAMPLE_MASK; 35 reg |= FIELD_PREP(UHS_REG_EXT_SAMPLE_MASK, 36 BLUEFIELD_UHS_REG_EXT_SAMPLE); 37 reg &= ~UHS_REG_EXT_DRIVE_MASK; 38 reg |= FIELD_PREP(UHS_REG_EXT_DRIVE_MASK, BLUEFIELD_UHS_REG_EXT_DRIVE); 39 mci_writel(host, UHS_REG_EXT, reg); 40 } 41 42 static const struct dw_mci_drv_data bluefield_drv_data = { 43 .set_ios = dw_mci_bluefield_set_ios 44 }; 45 46 static const struct of_device_id dw_mci_bluefield_match[] = { 47 { .compatible = "mellanox,bluefield-dw-mshc", 48 .data = &bluefield_drv_data }, 49 {}, 50 }; 51 MODULE_DEVICE_TABLE(of, dw_mci_bluefield_match); 52 53 static int dw_mci_bluefield_probe(struct platform_device *pdev) 54 { 55 const struct dw_mci_drv_data *drv_data = NULL; 56 const struct of_device_id *match; 57 58 if (pdev->dev.of_node) { 59 match = of_match_node(dw_mci_bluefield_match, 60 pdev->dev.of_node); 61 drv_data = match->data; 62 } 63 64 return dw_mci_pltfm_register(pdev, drv_data); 65 } 66 67 static struct platform_driver dw_mci_bluefield_pltfm_driver = { 68 .probe = dw_mci_bluefield_probe, 69 .remove = dw_mci_pltfm_remove, 70 .driver = { 71 .name = "dwmmc_bluefield", 72 .of_match_table = dw_mci_bluefield_match, 73 .pm = &dw_mci_pltfm_pmops, 74 }, 75 }; 76 77 module_platform_driver(dw_mci_bluefield_pltfm_driver); 78 79 MODULE_DESCRIPTION("BlueField DW Multimedia Card driver"); 80 MODULE_AUTHOR("Mellanox Technologies"); 81 MODULE_LICENSE("GPL v2"); 82