Skip to content

Commit f039685

Browse files
committed
Merge remote-tracking branches 'regulator/topic/rc5t619' and 'regulator/topic/stm32-vref' into regulator-next
3 parents a6955d3 + 83b2a3c + 0cdbf48 commit f039685

File tree

6 files changed

+274
-6
lines changed

6 files changed

+274
-6
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
STM32 VREFBUF - Voltage reference buffer
2+
3+
Some STM32 devices embed a voltage reference buffer which can be used as
4+
voltage reference for ADCs, DACs and also as voltage reference for external
5+
components through the dedicated VREF+ pin.
6+
7+
Required properties:
8+
- compatible: Must be "st,stm32-vrefbuf".
9+
- reg: Offset and length of VREFBUF register set.
10+
- clocks: Must contain an entry for peripheral clock.
11+
12+
Example:
13+
vrefbuf: regulator@58003C00 {
14+
compatible = "st,stm32-vrefbuf";
15+
reg = <0x58003C00 0x8>;
16+
clocks = <&rcc VREF_CK>;
17+
regulator-min-microvolt = <1500000>;
18+
regulator-max-microvolt = <2500000>;
19+
vdda-supply = <&vdda>;
20+
};

drivers/regulator/Kconfig

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -709,8 +709,8 @@ config REGULATOR_RN5T618
709709
tristate "Ricoh RN5T567/618 voltage regulators"
710710
depends on MFD_RN5T618
711711
help
712-
Say y here to support the regulators found on Ricoh RN5T567 or
713-
RN5T618 PMIC.
712+
Say y here to support the regulators found on Ricoh RN5T567,
713+
RN5T618 or RC5T619 PMIC.
714714

715715
config REGULATOR_RT5033
716716
tristate "Richtek RT5033 Regulators"
@@ -755,6 +755,18 @@ config REGULATOR_SKY81452
755755
This driver can also be built as a module. If so, the module
756756
will be called sky81452-regulator.
757757

758+
config REGULATOR_STM32_VREFBUF
759+
tristate "STMicroelectronics STM32 VREFBUF"
760+
depends on ARCH_STM32 || COMPILE_TEST
761+
help
762+
This driver supports STMicroelectronics STM32 VREFBUF (voltage
763+
reference buffer) which can be used as voltage reference for
764+
internal ADCs, DACs and also for external components through
765+
dedicated Vref+ pin.
766+
767+
This driver can also be built as a module. If so, the module
768+
will be called stm32-vrefbuf.
769+
758770
config REGULATOR_TI_ABB
759771
tristate "TI Adaptive Body Bias on-chip LDO"
760772
depends on ARCH_OMAP

drivers/regulator/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ obj-$(CONFIG_REGULATOR_S2MPA01) += s2mpa01.o
9595
obj-$(CONFIG_REGULATOR_S2MPS11) += s2mps11.o
9696
obj-$(CONFIG_REGULATOR_S5M8767) += s5m8767.o
9797
obj-$(CONFIG_REGULATOR_SKY81452) += sky81452-regulator.o
98+
obj-$(CONFIG_REGULATOR_STM32_VREFBUF) += stm32-vrefbuf.o
9899
obj-$(CONFIG_REGULATOR_STW481X_VMMC) += stw481x-vmmc.o
99100
obj-$(CONFIG_REGULATOR_TI_ABB) += ti-abb-regulator.o
100101
obj-$(CONFIG_REGULATOR_TPS6105X) += tps6105x-regulator.o

drivers/regulator/rn5t618-regulator.c

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,20 +79,50 @@ static struct regulator_desc rn5t618_regulators[] = {
7979
REG(LDORTC2, LDOEN2, BIT(5), LDORTC2DAC, 0x7f, 900000, 3500000, 25000),
8080
};
8181

82+
static struct regulator_desc rc5t619_regulators[] = {
83+
/* DCDC */
84+
REG(DCDC1, DC1CTL, BIT(0), DC1DAC, 0xff, 600000, 3500000, 12500),
85+
REG(DCDC2, DC2CTL, BIT(0), DC2DAC, 0xff, 600000, 3500000, 12500),
86+
REG(DCDC3, DC3CTL, BIT(0), DC3DAC, 0xff, 600000, 3500000, 12500),
87+
REG(DCDC4, DC4CTL, BIT(0), DC4DAC, 0xff, 600000, 3500000, 12500),
88+
REG(DCDC5, DC5CTL, BIT(0), DC5DAC, 0xff, 600000, 3500000, 12500),
89+
/* LDO */
90+
REG(LDO1, LDOEN1, BIT(0), LDO1DAC, 0x7f, 900000, 3500000, 25000),
91+
REG(LDO2, LDOEN1, BIT(1), LDO2DAC, 0x7f, 900000, 3500000, 25000),
92+
REG(LDO3, LDOEN1, BIT(2), LDO3DAC, 0x7f, 900000, 3500000, 25000),
93+
REG(LDO4, LDOEN1, BIT(3), LDO4DAC, 0x7f, 900000, 3500000, 25000),
94+
REG(LDO5, LDOEN1, BIT(4), LDO5DAC, 0x7f, 600000, 3500000, 25000),
95+
REG(LDO6, LDOEN1, BIT(5), LDO6DAC, 0x7f, 600000, 3500000, 25000),
96+
REG(LDO7, LDOEN1, BIT(6), LDO7DAC, 0x7f, 900000, 3500000, 25000),
97+
REG(LDO8, LDOEN1, BIT(7), LDO8DAC, 0x7f, 900000, 3500000, 25000),
98+
REG(LDO9, LDOEN2, BIT(0), LDO9DAC, 0x7f, 900000, 3500000, 25000),
99+
REG(LDO10, LDOEN2, BIT(0), LDO10DAC, 0x7f, 900000, 3500000, 25000),
100+
/* LDO RTC */
101+
REG(LDORTC1, LDOEN2, BIT(4), LDORTCDAC, 0x7f, 1700000, 3500000, 25000),
102+
REG(LDORTC2, LDOEN2, BIT(5), LDORTC2DAC, 0x7f, 900000, 3500000, 25000),
103+
};
104+
82105
static int rn5t618_regulator_probe(struct platform_device *pdev)
83106
{
84107
struct rn5t618 *rn5t618 = dev_get_drvdata(pdev->dev.parent);
85108
struct regulator_config config = { };
86109
struct regulator_dev *rdev;
87110
struct regulator_desc *regulators;
88111
int i;
112+
int num_regulators = 0;
89113

90114
switch (rn5t618->variant) {
91115
case RN5T567:
92116
regulators = rn5t567_regulators;
117+
num_regulators = ARRAY_SIZE(rn5t567_regulators);
93118
break;
94119
case RN5T618:
95120
regulators = rn5t618_regulators;
121+
num_regulators = ARRAY_SIZE(rn5t618_regulators);
122+
break;
123+
case RC5T619:
124+
regulators = rc5t619_regulators;
125+
num_regulators = ARRAY_SIZE(rc5t619_regulators);
96126
break;
97127
default:
98128
return -EINVAL;
@@ -101,10 +131,7 @@ static int rn5t618_regulator_probe(struct platform_device *pdev)
101131
config.dev = pdev->dev.parent;
102132
config.regmap = rn5t618->regmap;
103133

104-
for (i = 0; i < RN5T618_REG_NUM; i++) {
105-
if (!regulators[i].name)
106-
continue;
107-
134+
for (i = 0; i < num_regulators; i++) {
108135
rdev = devm_regulator_register(&pdev->dev,
109136
&regulators[i],
110137
&config);

drivers/regulator/stm32-vrefbuf.c

Lines changed: 202 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,202 @@
1+
/*
2+
* Copyright (C) STMicroelectronics 2017
3+
*
4+
* Author: Fabrice Gasnier <[email protected]>
5+
*
6+
* License terms: GNU General Public License (GPL), version 2
7+
*/
8+
9+
#include <linux/bitfield.h>
10+
#include <linux/clk.h>
11+
#include <linux/io.h>
12+
#include <linux/iopoll.h>
13+
#include <linux/module.h>
14+
#include <linux/of_device.h>
15+
#include <linux/platform_device.h>
16+
#include <linux/regulator/driver.h>
17+
#include <linux/regulator/of_regulator.h>
18+
19+
/* STM32 VREFBUF registers */
20+
#define STM32_VREFBUF_CSR 0x00
21+
22+
/* STM32 VREFBUF CSR bitfields */
23+
#define STM32_VRS GENMASK(6, 4)
24+
#define STM32_VRR BIT(3)
25+
#define STM32_HIZ BIT(1)
26+
#define STM32_ENVR BIT(0)
27+
28+
struct stm32_vrefbuf {
29+
void __iomem *base;
30+
struct clk *clk;
31+
};
32+
33+
static const unsigned int stm32_vrefbuf_voltages[] = {
34+
/* Matches resp. VRS = 000b, 001b, 010b, 011b */
35+
2500000, 2048000, 1800000, 1500000,
36+
};
37+
38+
static int stm32_vrefbuf_enable(struct regulator_dev *rdev)
39+
{
40+
struct stm32_vrefbuf *priv = rdev_get_drvdata(rdev);
41+
u32 val = readl_relaxed(priv->base + STM32_VREFBUF_CSR);
42+
int ret;
43+
44+
val = (val & ~STM32_HIZ) | STM32_ENVR;
45+
writel_relaxed(val, priv->base + STM32_VREFBUF_CSR);
46+
47+
/*
48+
* Vrefbuf startup time depends on external capacitor: wait here for
49+
* VRR to be set. That means output has reached expected value.
50+
* ~650us sleep should be enough for caps up to 1.5uF. Use 10ms as
51+
* arbitrary timeout.
52+
*/
53+
ret = readl_poll_timeout(priv->base + STM32_VREFBUF_CSR, val,
54+
!(val & STM32_VRR), 650, 10000);
55+
if (ret) {
56+
dev_err(&rdev->dev, "stm32 vrefbuf timed out!\n");
57+
val = readl_relaxed(priv->base + STM32_VREFBUF_CSR);
58+
val = (val & ~STM32_ENVR) | STM32_HIZ;
59+
writel_relaxed(val, priv->base + STM32_VREFBUF_CSR);
60+
}
61+
62+
return ret;
63+
}
64+
65+
static int stm32_vrefbuf_disable(struct regulator_dev *rdev)
66+
{
67+
struct stm32_vrefbuf *priv = rdev_get_drvdata(rdev);
68+
u32 val = readl_relaxed(priv->base + STM32_VREFBUF_CSR);
69+
70+
val = (val & ~STM32_ENVR) | STM32_HIZ;
71+
writel_relaxed(val, priv->base + STM32_VREFBUF_CSR);
72+
73+
return 0;
74+
}
75+
76+
static int stm32_vrefbuf_is_enabled(struct regulator_dev *rdev)
77+
{
78+
struct stm32_vrefbuf *priv = rdev_get_drvdata(rdev);
79+
80+
return readl_relaxed(priv->base + STM32_VREFBUF_CSR) & STM32_ENVR;
81+
}
82+
83+
static int stm32_vrefbuf_set_voltage_sel(struct regulator_dev *rdev,
84+
unsigned sel)
85+
{
86+
struct stm32_vrefbuf *priv = rdev_get_drvdata(rdev);
87+
u32 val = readl_relaxed(priv->base + STM32_VREFBUF_CSR);
88+
89+
val = (val & ~STM32_VRS) | FIELD_PREP(STM32_VRS, sel);
90+
writel_relaxed(val, priv->base + STM32_VREFBUF_CSR);
91+
92+
return 0;
93+
}
94+
95+
static int stm32_vrefbuf_get_voltage_sel(struct regulator_dev *rdev)
96+
{
97+
struct stm32_vrefbuf *priv = rdev_get_drvdata(rdev);
98+
u32 val = readl_relaxed(priv->base + STM32_VREFBUF_CSR);
99+
100+
return FIELD_GET(STM32_VRS, val);
101+
}
102+
103+
static const struct regulator_ops stm32_vrefbuf_volt_ops = {
104+
.enable = stm32_vrefbuf_enable,
105+
.disable = stm32_vrefbuf_disable,
106+
.is_enabled = stm32_vrefbuf_is_enabled,
107+
.get_voltage_sel = stm32_vrefbuf_get_voltage_sel,
108+
.set_voltage_sel = stm32_vrefbuf_set_voltage_sel,
109+
.list_voltage = regulator_list_voltage_table,
110+
};
111+
112+
static const struct regulator_desc stm32_vrefbuf_regu = {
113+
.name = "vref",
114+
.supply_name = "vdda",
115+
.volt_table = stm32_vrefbuf_voltages,
116+
.n_voltages = ARRAY_SIZE(stm32_vrefbuf_voltages),
117+
.ops = &stm32_vrefbuf_volt_ops,
118+
.type = REGULATOR_VOLTAGE,
119+
.owner = THIS_MODULE,
120+
};
121+
122+
static int stm32_vrefbuf_probe(struct platform_device *pdev)
123+
{
124+
struct resource *res;
125+
struct stm32_vrefbuf *priv;
126+
struct regulator_config config = { };
127+
struct regulator_dev *rdev;
128+
int ret;
129+
130+
priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
131+
if (!priv)
132+
return -ENOMEM;
133+
134+
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
135+
priv->base = devm_ioremap_resource(&pdev->dev, res);
136+
if (IS_ERR(priv->base))
137+
return PTR_ERR(priv->base);
138+
139+
priv->clk = devm_clk_get(&pdev->dev, NULL);
140+
if (IS_ERR(priv->clk))
141+
return PTR_ERR(priv->clk);
142+
143+
ret = clk_prepare_enable(priv->clk);
144+
if (ret) {
145+
dev_err(&pdev->dev, "clk prepare failed with error %d\n", ret);
146+
return ret;
147+
}
148+
149+
config.dev = &pdev->dev;
150+
config.driver_data = priv;
151+
config.of_node = pdev->dev.of_node;
152+
config.init_data = of_get_regulator_init_data(&pdev->dev,
153+
pdev->dev.of_node,
154+
&stm32_vrefbuf_regu);
155+
156+
rdev = regulator_register(&stm32_vrefbuf_regu, &config);
157+
if (IS_ERR(rdev)) {
158+
ret = PTR_ERR(rdev);
159+
dev_err(&pdev->dev, "register failed with error %d\n", ret);
160+
goto err_clk_dis;
161+
}
162+
platform_set_drvdata(pdev, rdev);
163+
164+
return 0;
165+
166+
err_clk_dis:
167+
clk_disable_unprepare(priv->clk);
168+
169+
return ret;
170+
}
171+
172+
static int stm32_vrefbuf_remove(struct platform_device *pdev)
173+
{
174+
struct regulator_dev *rdev = platform_get_drvdata(pdev);
175+
struct stm32_vrefbuf *priv = rdev_get_drvdata(rdev);
176+
177+
regulator_unregister(rdev);
178+
clk_disable_unprepare(priv->clk);
179+
180+
return 0;
181+
};
182+
183+
static const struct of_device_id stm32_vrefbuf_of_match[] = {
184+
{ .compatible = "st,stm32-vrefbuf", },
185+
{},
186+
};
187+
MODULE_DEVICE_TABLE(of, stm32_vrefbuf_of_match);
188+
189+
static struct platform_driver stm32_vrefbuf_driver = {
190+
.probe = stm32_vrefbuf_probe,
191+
.remove = stm32_vrefbuf_remove,
192+
.driver = {
193+
.name = "stm32-vrefbuf",
194+
.of_match_table = of_match_ptr(stm32_vrefbuf_of_match),
195+
},
196+
};
197+
module_platform_driver(stm32_vrefbuf_driver);
198+
199+
MODULE_LICENSE("GPL v2");
200+
MODULE_AUTHOR("Fabrice Gasnier <[email protected]>");
201+
MODULE_DESCRIPTION("STMicroelectronics STM32 VREFBUF driver");
202+
MODULE_ALIAS("platform:stm32-vrefbuf");

include/linux/mfd/rn5t618.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,11 +226,17 @@ enum {
226226
RN5T618_DCDC2,
227227
RN5T618_DCDC3,
228228
RN5T618_DCDC4,
229+
RN5T618_DCDC5,
229230
RN5T618_LDO1,
230231
RN5T618_LDO2,
231232
RN5T618_LDO3,
232233
RN5T618_LDO4,
233234
RN5T618_LDO5,
235+
RN5T618_LDO6,
236+
RN5T618_LDO7,
237+
RN5T618_LDO8,
238+
RN5T618_LDO9,
239+
RN5T618_LDO10,
234240
RN5T618_LDORTC1,
235241
RN5T618_LDORTC2,
236242
RN5T618_REG_NUM,

0 commit comments

Comments
 (0)