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 	return dw_mci_pltfm_register(pdev, &bluefield_drv_data);
56 }
57 
58 static struct platform_driver dw_mci_bluefield_pltfm_driver = {
59 	.probe		= dw_mci_bluefield_probe,
60 	.remove		= dw_mci_pltfm_remove,
61 	.driver		= {
62 		.name		= "dwmmc_bluefield",
63 		.of_match_table	= dw_mci_bluefield_match,
64 		.pm		= &dw_mci_pltfm_pmops,
65 	},
66 };
67 
68 module_platform_driver(dw_mci_bluefield_pltfm_driver);
69 
70 MODULE_DESCRIPTION("BlueField DW Multimedia Card driver");
71 MODULE_AUTHOR("Mellanox Technologies");
72 MODULE_LICENSE("GPL v2");
73