Merge tag 'thermal-v5.15-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/therma...
[linux-2.6-microblaze.git] / drivers / mmc / host / dw_mmc-bluefield.c
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  * Copyright (C) 2018 Mellanox Technologies.
4  */
5
6 #include <linux/bitfield.h>
7 #include <linux/bitops.h>
8 #include <linux/mmc/host.h>
9 #include <linux/mmc/mmc.h>
10 #include <linux/module.h>
11 #include <linux/of.h>
12 #include <linux/platform_device.h>
13 #include <linux/pm_runtime.h>
14
15 #include "dw_mmc.h"
16 #include "dw_mmc-pltfm.h"
17
18 #define UHS_REG_EXT_SAMPLE_MASK         GENMASK(22, 16)
19 #define UHS_REG_EXT_DRIVE_MASK          GENMASK(29, 23)
20 #define BLUEFIELD_UHS_REG_EXT_SAMPLE    2
21 #define BLUEFIELD_UHS_REG_EXT_DRIVE     4
22
23 static void dw_mci_bluefield_set_ios(struct dw_mci *host, struct mmc_ios *ios)
24 {
25         u32 reg;
26
27         /* Update the Drive and Sample fields in register UHS_REG_EXT. */
28         reg = mci_readl(host, UHS_REG_EXT);
29         reg &= ~UHS_REG_EXT_SAMPLE_MASK;
30         reg |= FIELD_PREP(UHS_REG_EXT_SAMPLE_MASK,
31                           BLUEFIELD_UHS_REG_EXT_SAMPLE);
32         reg &= ~UHS_REG_EXT_DRIVE_MASK;
33         reg |= FIELD_PREP(UHS_REG_EXT_DRIVE_MASK, BLUEFIELD_UHS_REG_EXT_DRIVE);
34         mci_writel(host, UHS_REG_EXT, reg);
35 }
36
37 static const struct dw_mci_drv_data bluefield_drv_data = {
38         .set_ios                = dw_mci_bluefield_set_ios
39 };
40
41 static const struct of_device_id dw_mci_bluefield_match[] = {
42         { .compatible = "mellanox,bluefield-dw-mshc",
43           .data = &bluefield_drv_data },
44         {},
45 };
46 MODULE_DEVICE_TABLE(of, dw_mci_bluefield_match);
47
48 static int dw_mci_bluefield_probe(struct platform_device *pdev)
49 {
50         return dw_mci_pltfm_register(pdev, &bluefield_drv_data);
51 }
52
53 static struct platform_driver dw_mci_bluefield_pltfm_driver = {
54         .probe          = dw_mci_bluefield_probe,
55         .remove         = dw_mci_pltfm_remove,
56         .driver         = {
57                 .name           = "dwmmc_bluefield",
58                 .probe_type     = PROBE_PREFER_ASYNCHRONOUS,
59                 .of_match_table = dw_mci_bluefield_match,
60                 .pm             = &dw_mci_pltfm_pmops,
61         },
62 };
63
64 module_platform_driver(dw_mci_bluefield_pltfm_driver);
65
66 MODULE_DESCRIPTION("BlueField DW Multimedia Card driver");
67 MODULE_AUTHOR("Mellanox Technologies");
68 MODULE_LICENSE("GPL v2");