ipq40xx: 5.10: copy patches
[openwrt/staging/chunkeey.git] / target / linux / ipq40xx / patches-5.10 / 0002-01-v5.6-regulator-add-IPQ4019-SDHCI-VQMMC-LDO-driver.patch
1 From 97043d292365ae39d62b54a6d79dff98d048b501 Mon Sep 17 00:00:00 2001
2 From: Robert Marko <robert.marko@sartura.hr>
3 Date: Wed, 22 Jan 2020 12:44:14 +0100
4 Subject: [PATCH] From ebf652b408200504194be32ad0a3f5bb49d6000a Mon Sep 17
5 00:00:00 2001 From: Robert Marko <robert.marko@sartura.hr> Date: Sun, 12 Jan
6 2020 12:30:01 +0100 Subject: [PATCH] regulator: add IPQ4019 SDHCI VQMMC LDO
7 driver
8
9 This introduces the IPQ4019 VQMMC LDO driver needed for
10 the SD/EMMC driver I/O level operation.
11 This will enable introducing SD/EMMC support for the built-in controller.
12
13 Signed-off-by: Mantas Pucka <mantas@8devices.com>
14 Signed-off-by: Robert Marko <robert.marko@sartura.hr>
15 Link: https://lore.kernel.org/r/20200112113003.11110-1-robert.marko@sartura.hr
16 Signed-off-by: Mark Brown <broonie@kernel.org>
17 ---
18 drivers/regulator/Kconfig | 7 ++
19 drivers/regulator/Makefile | 1 +
20 drivers/regulator/vqmmc-ipq4019-regulator.c | 101 ++++++++++++++++++++
21 3 files changed, 109 insertions(+)
22 create mode 100644 drivers/regulator/vqmmc-ipq4019-regulator.c
23
24 --- a/drivers/regulator/Kconfig
25 +++ b/drivers/regulator/Kconfig
26 @@ -1077,6 +1077,13 @@ config REGULATOR_VEXPRESS
27 This driver provides support for voltage regulators available
28 on the ARM Ltd's Versatile Express platform.
29
30 +config REGULATOR_VQMMC_IPQ4019
31 + tristate "IPQ4019 VQMMC SD LDO regulator support"
32 + depends on ARCH_QCOM
33 + help
34 + This driver provides support for the VQMMC LDO I/0
35 + voltage regulator of the IPQ4019 SD/EMMC controller.
36 +
37 config REGULATOR_WM831X
38 tristate "Wolfson Microelectronics WM831x PMIC regulators"
39 depends on MFD_WM831X
40 --- a/drivers/regulator/Makefile
41 +++ b/drivers/regulator/Makefile
42 @@ -132,6 +132,7 @@ obj-$(CONFIG_REGULATOR_TWL4030) += twl-r
43 obj-$(CONFIG_REGULATOR_UNIPHIER) += uniphier-regulator.o
44 obj-$(CONFIG_REGULATOR_VCTRL) += vctrl-regulator.o
45 obj-$(CONFIG_REGULATOR_VEXPRESS) += vexpress-regulator.o
46 +obj-$(CONFIG_REGULATOR_VQMMC_IPQ4019) += vqmmc-ipq4019-regulator.o
47 obj-$(CONFIG_REGULATOR_WM831X) += wm831x-dcdc.o
48 obj-$(CONFIG_REGULATOR_WM831X) += wm831x-isink.o
49 obj-$(CONFIG_REGULATOR_WM831X) += wm831x-ldo.o
50 --- /dev/null
51 +++ b/drivers/regulator/vqmmc-ipq4019-regulator.c
52 @@ -0,0 +1,101 @@
53 +// SPDX-License-Identifier: GPL-2.0+
54 +//
55 +// Copyright (c) 2019 Mantas Pucka <mantas@8devices.com>
56 +// Copyright (c) 2019 Robert Marko <robert.marko@sartura.hr>
57 +//
58 +// Driver for IPQ4019 SD/MMC controller's I/O LDO voltage regulator
59 +
60 +#include <linux/io.h>
61 +#include <linux/module.h>
62 +#include <linux/of.h>
63 +#include <linux/platform_device.h>
64 +#include <linux/regmap.h>
65 +#include <linux/regulator/driver.h>
66 +#include <linux/regulator/machine.h>
67 +#include <linux/regulator/of_regulator.h>
68 +
69 +static const unsigned int ipq4019_vmmc_voltages[] = {
70 + 1500000, 1800000, 2500000, 3000000,
71 +};
72 +
73 +static const struct regulator_ops ipq4019_regulator_voltage_ops = {
74 + .list_voltage = regulator_list_voltage_table,
75 + .map_voltage = regulator_map_voltage_ascend,
76 + .get_voltage_sel = regulator_get_voltage_sel_regmap,
77 + .set_voltage_sel = regulator_set_voltage_sel_regmap,
78 +};
79 +
80 +static const struct regulator_desc vmmc_regulator = {
81 + .name = "vmmcq",
82 + .ops = &ipq4019_regulator_voltage_ops,
83 + .type = REGULATOR_VOLTAGE,
84 + .owner = THIS_MODULE,
85 + .volt_table = ipq4019_vmmc_voltages,
86 + .n_voltages = ARRAY_SIZE(ipq4019_vmmc_voltages),
87 + .vsel_reg = 0,
88 + .vsel_mask = 0x3,
89 +};
90 +
91 +static const struct regmap_config ipq4019_vmmcq_regmap_config = {
92 + .reg_bits = 32,
93 + .reg_stride = 4,
94 + .val_bits = 32,
95 +};
96 +
97 +static int ipq4019_regulator_probe(struct platform_device *pdev)
98 +{
99 + struct device *dev = &pdev->dev;
100 + struct regulator_init_data *init_data;
101 + struct regulator_config cfg = {};
102 + struct regulator_dev *rdev;
103 + struct resource *res;
104 + struct regmap *rmap;
105 + void __iomem *base;
106 +
107 + init_data = of_get_regulator_init_data(dev, dev->of_node,
108 + &vmmc_regulator);
109 + if (!init_data)
110 + return -EINVAL;
111 +
112 + res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
113 + base = devm_ioremap_resource(dev, res);
114 + if (IS_ERR(base))
115 + return PTR_ERR(base);
116 +
117 + rmap = devm_regmap_init_mmio(dev, base, &ipq4019_vmmcq_regmap_config);
118 + if (IS_ERR(rmap))
119 + return PTR_ERR(rmap);
120 +
121 + cfg.dev = dev;
122 + cfg.init_data = init_data;
123 + cfg.of_node = dev->of_node;
124 + cfg.regmap = rmap;
125 +
126 + rdev = devm_regulator_register(dev, &vmmc_regulator, &cfg);
127 + if (IS_ERR(rdev)) {
128 + dev_err(dev, "Failed to register regulator: %ld\n",
129 + PTR_ERR(rdev));
130 + return PTR_ERR(rdev);
131 + }
132 + platform_set_drvdata(pdev, rdev);
133 +
134 + return 0;
135 +}
136 +
137 +static const struct of_device_id regulator_ipq4019_of_match[] = {
138 + { .compatible = "qcom,vqmmc-ipq4019-regulator", },
139 + {},
140 +};
141 +
142 +static struct platform_driver ipq4019_regulator_driver = {
143 + .probe = ipq4019_regulator_probe,
144 + .driver = {
145 + .name = "vqmmc-ipq4019-regulator",
146 + .of_match_table = of_match_ptr(regulator_ipq4019_of_match),
147 + },
148 +};
149 +module_platform_driver(ipq4019_regulator_driver);
150 +
151 +MODULE_LICENSE("GPL");
152 +MODULE_AUTHOR("Mantas Pucka <mantas@8devices.com>");
153 +MODULE_DESCRIPTION("IPQ4019 VQMMC voltage regulator");