Skip to content
Navigation Menu
Toggle navigation
Sign in
In this repository
All GitHub Enterprise
↵
Jump to
↵
No suggested jump to results
In this repository
All GitHub Enterprise
↵
Jump to
↵
In this organization
All GitHub Enterprise
↵
Jump to
↵
In this repository
All GitHub Enterprise
↵
Jump to
↵
Sign in
Reseting focus
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
mariux64
/
linux
Public
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Issues
2
Pull requests
0
Actions
Projects
0
Wiki
Security
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Wiki
Security
Insights
Files
8f3cbcd
Documentation
LICENSES
arch
block
certs
crypto
drivers
accessibility
acpi
amba
android
ata
atm
auxdisplay
base
bcma
block
bluetooth
bus
cdrom
char
clk
clocksource
comedi
connector
counter
cpufreq
cpuidle
crypto
cxl
dax
dca
devfreq
dio
dma-buf
dma
edac
eisa
extcon
firewire
firmware
fpga
fsi
gnss
gpio
gpu
greybus
hid
hsi
hte
hv
hwmon
hwspinlock
hwtracing
i2c
i3c
idle
iio
infiniband
input
interconnect
iommu
ipack
irqchip
isdn
leds
macintosh
mailbox
mcb
md
media
memory
memstick
message
mfd
misc
mmc
most
mtd
mux
net
nfc
ntb
nubus
nvdimm
nvme
nvmem
of
opp
parisc
parport
pci
pcmcia
peci
perf
phy
pinctrl
platform
pnp
power
powercap
pps
ps3
ptp
pwm
rapidio
ras
regulator
88pg86x.c
88pm800-regulator.c
88pm8607.c
Kconfig
Makefile
aat2870-regulator.c
ab8500-ext.c
ab8500.c
act8865-regulator.c
act8945a-regulator.c
ad5398.c
anatop-regulator.c
arizona-ldo1.c
arizona-micsupp.c
as3711-regulator.c
as3722-regulator.c
atc260x-regulator.c
axp20x-regulator.c
bcm590xx-regulator.c
bd71815-regulator.c
bd71828-regulator.c
bd718x7-regulator.c
bd9571mwv-regulator.c
bd9576-regulator.c
core.c
cpcap-regulator.c
cros-ec-regulator.c
da903x-regulator.c
da9052-regulator.c
da9055-regulator.c
da9062-regulator.c
da9063-regulator.c
da9121-regulator.c
da9121-regulator.h
da9210-regulator.c
da9210-regulator.h
da9211-regulator.c
da9211-regulator.h
db8500-prcmu.c
dbx500-prcmu.c
dbx500-prcmu.h
devres.c
dummy.c
dummy.h
fan53555.c
fan53880.c
fixed-helper.c
fixed.c
gpio-regulator.c
helpers.c
hi6421-regulator.c
hi6421v530-regulator.c
hi6421v600-regulator.c
hi655x-regulator.c
internal.h
irq_helpers.c
isl6271a-regulator.c
isl9305.c
lm363x-regulator.c
lochnagar-regulator.c
lp3971.c
lp3972.c
lp872x.c
lp873x-regulator.c
lp8755.c
lp87565-regulator.c
lp8788-buck.c
lp8788-ldo.c
ltc3589.c
ltc3676.c
max14577-regulator.c
max1586.c
max20086-regulator.c
max597x-regulator.c
max77620-regulator.c
max77650-regulator.c
max77686-regulator.c
max77693-regulator.c
max77802-regulator.c
max77826-regulator.c
max8649.c
max8660.c
max8893.c
max8907-regulator.c
max8925-regulator.c
max8952.c
max8973-regulator.c
max8997-regulator.c
max8998.c
mc13783-regulator.c
mc13892-regulator.c
mc13xxx-regulator-core.c
mc13xxx.h
mcp16502.c
mp5416.c
mp8859.c
mp886x.c
mpq7920.c
mpq7920.h
mt6311-regulator.c
mt6311-regulator.h
mt6315-regulator.c
mt6323-regulator.c
mt6331-regulator.c
mt6332-regulator.c
mt6357-regulator.c
mt6358-regulator.c
mt6359-regulator.c
mt6360-regulator.c
mt6370-regulator.c
mt6380-regulator.c
mt6397-regulator.c
mtk-dvfsrc-regulator.c
of_regulator.c
palmas-regulator.c
pbias-regulator.c
pca9450-regulator.c
pcap-regulator.c
pcf50633-regulator.c
pf8x00-regulator.c
pfuze100-regulator.c
pv88060-regulator.c
pv88060-regulator.h
pv88080-regulator.c
pv88080-regulator.h
pv88090-regulator.c
pv88090-regulator.h
pwm-regulator.c
qcom-labibb-regulator.c
qcom-rpmh-regulator.c
qcom_rpm-regulator.c
qcom_smd-regulator.c
qcom_spmi-regulator.c
qcom_usb_vbus-regulator.c
rc5t583-regulator.c
rk808-regulator.c
rn5t618-regulator.c
rohm-regulator.c
rpi-panel-attiny-regulator.c
rt4801-regulator.c
rt4831-regulator.c
rt5033-regulator.c
rt5120-regulator.c
rt5190a-regulator.c
rt5759-regulator.c
rt6160-regulator.c
rt6190-regulator.c
rt6245-regulator.c
rtmv20-regulator.c
rtq2134-regulator.c
rtq6752-regulator.c
s2mpa01.c
s2mps11.c
s5m8767.c
sc2731-regulator.c
scmi-regulator.c
sky81452-regulator.c
slg51000-regulator.c
slg51000-regulator.h
sm5703-regulator.c
stm32-booster.c
stm32-pwr.c
stm32-vrefbuf.c
stpmic1_regulator.c
stw481x-vmmc.c
sy7636a-regulator.c
sy8106a-regulator.c
sy8824x.c
sy8827n.c
ti-abb-regulator.c
tps51632-regulator.c
tps6105x-regulator.c
tps62360-regulator.c
tps6286x-regulator.c
tps65023-regulator.c
tps6507x-regulator.c
tps65086-regulator.c
tps65090-regulator.c
tps65132-regulator.c
tps65217-regulator.c
tps65218-regulator.c
tps65219-regulator.c
tps6524x-regulator.c
tps6586x-regulator.c
tps65910-regulator.c
tps65912-regulator.c
tps68470-regulator.c
twl-regulator.c
twl6030-regulator.c
uniphier-regulator.c
userspace-consumer.c
vctrl-regulator.c
vexpress-regulator.c
virtual.c
vqmmc-ipq4019-regulator.c
wm831x-dcdc.c
wm831x-isink.c
wm831x-ldo.c
wm8350-regulator.c
wm8400-regulator.c
wm8994-regulator.c
remoteproc
reset
rpmsg
rtc
s390
sbus
scsi
sh
siox
slimbus
soc
soundwire
spi
spmi
ssb
staging
target
tc
tee
thermal
thunderbolt
tty
ufs
uio
usb
vdpa
vfio
vhost
video
virt
virtio
vlynq
w1
watchdog
xen
zorro
Kconfig
Makefile
fs
include
init
io_uring
ipc
kernel
lib
mm
net
rust
samples
scripts
security
sound
tools
usr
virt
.clang-format
.cocciconfig
.get_maintainer.ignore
.gitattributes
.gitignore
.mailmap
.rustfmt.toml
COPYING
CREDITS
Kbuild
Kconfig
MAINTAINERS
Makefile
README
Breadcrumbs
linux
/
drivers
/
regulator
/
stm32-vrefbuf.c
Blame
Blame
Latest commit
History
History
297 lines (239 loc) · 7.47 KB
Breadcrumbs
linux
/
drivers
/
regulator
/
stm32-vrefbuf.c
Top
File metadata and controls
Code
Blame
297 lines (239 loc) · 7.47 KB
Raw
// SPDX-License-Identifier: GPL-2.0-only /* * Copyright (C) STMicroelectronics 2017 * * Author: Fabrice Gasnier <fabrice.gasnier@st.com> */ #include <linux/bitfield.h> #include <linux/clk.h> #include <linux/io.h> #include <linux/iopoll.h> #include <linux/module.h> #include <linux/of_device.h> #include <linux/platform_device.h> #include <linux/regulator/driver.h> #include <linux/regulator/of_regulator.h> #include <linux/pm_runtime.h> /* STM32 VREFBUF registers */ #define STM32_VREFBUF_CSR 0x00 /* STM32 VREFBUF CSR bitfields */ #define STM32_VRS GENMASK(6, 4) #define STM32_VRR BIT(3) #define STM32_HIZ BIT(1) #define STM32_ENVR BIT(0) #define STM32_VREFBUF_AUTO_SUSPEND_DELAY_MS 10 struct stm32_vrefbuf { void __iomem *base; struct clk *clk; struct device *dev; }; static const unsigned int stm32_vrefbuf_voltages[] = { /* Matches resp. VRS = 000b, 001b, 010b, 011b */ 2500000, 2048000, 1800000, 1500000, }; static int stm32_vrefbuf_enable(struct regulator_dev *rdev) { struct stm32_vrefbuf *priv = rdev_get_drvdata(rdev); u32 val; int ret; ret = pm_runtime_resume_and_get(priv->dev); if (ret < 0) return ret; val = readl_relaxed(priv->base + STM32_VREFBUF_CSR); val = (val & ~STM32_HIZ) | STM32_ENVR; writel_relaxed(val, priv->base + STM32_VREFBUF_CSR); /* * Vrefbuf startup time depends on external capacitor: wait here for * VRR to be set. That means output has reached expected value. * ~650us sleep should be enough for caps up to 1.5uF. Use 10ms as * arbitrary timeout. */ ret = readl_poll_timeout(priv->base + STM32_VREFBUF_CSR, val, val & STM32_VRR, 650, 10000); if (ret) { dev_err(&rdev->dev, "stm32 vrefbuf timed out!\n"); val = readl_relaxed(priv->base + STM32_VREFBUF_CSR); val = (val & ~STM32_ENVR) | STM32_HIZ; writel_relaxed(val, priv->base + STM32_VREFBUF_CSR); } pm_runtime_mark_last_busy(priv->dev); pm_runtime_put_autosuspend(priv->dev); return ret; } static int stm32_vrefbuf_disable(struct regulator_dev *rdev) { struct stm32_vrefbuf *priv = rdev_get_drvdata(rdev); u32 val; int ret; ret = pm_runtime_resume_and_get(priv->dev); if (ret < 0) return ret; val = readl_relaxed(priv->base + STM32_VREFBUF_CSR); val &= ~STM32_ENVR; writel_relaxed(val, priv->base + STM32_VREFBUF_CSR); pm_runtime_mark_last_busy(priv->dev); pm_runtime_put_autosuspend(priv->dev); return 0; } static int stm32_vrefbuf_is_enabled(struct regulator_dev *rdev) { struct stm32_vrefbuf *priv = rdev_get_drvdata(rdev); int ret; ret = pm_runtime_resume_and_get(priv->dev); if (ret < 0) return ret; ret = readl_relaxed(priv->base + STM32_VREFBUF_CSR) & STM32_ENVR; pm_runtime_mark_last_busy(priv->dev); pm_runtime_put_autosuspend(priv->dev); return ret; } static int stm32_vrefbuf_set_voltage_sel(struct regulator_dev *rdev, unsigned sel) { struct stm32_vrefbuf *priv = rdev_get_drvdata(rdev); u32 val; int ret; ret = pm_runtime_resume_and_get(priv->dev); if (ret < 0) return ret; val = readl_relaxed(priv->base + STM32_VREFBUF_CSR); val = (val & ~STM32_VRS) | FIELD_PREP(STM32_VRS, sel); writel_relaxed(val, priv->base + STM32_VREFBUF_CSR); pm_runtime_mark_last_busy(priv->dev); pm_runtime_put_autosuspend(priv->dev); return 0; } static int stm32_vrefbuf_get_voltage_sel(struct regulator_dev *rdev) { struct stm32_vrefbuf *priv = rdev_get_drvdata(rdev); u32 val; int ret; ret = pm_runtime_resume_and_get(priv->dev); if (ret < 0) return ret; val = readl_relaxed(priv->base + STM32_VREFBUF_CSR); ret = FIELD_GET(STM32_VRS, val); pm_runtime_mark_last_busy(priv->dev); pm_runtime_put_autosuspend(priv->dev); return ret; } static const struct regulator_ops stm32_vrefbuf_volt_ops = { .enable = stm32_vrefbuf_enable, .disable = stm32_vrefbuf_disable, .is_enabled = stm32_vrefbuf_is_enabled, .get_voltage_sel = stm32_vrefbuf_get_voltage_sel, .set_voltage_sel = stm32_vrefbuf_set_voltage_sel, .list_voltage = regulator_list_voltage_table, }; static const struct regulator_desc stm32_vrefbuf_regu = { .name = "vref", .supply_name = "vdda", .volt_table = stm32_vrefbuf_voltages, .n_voltages = ARRAY_SIZE(stm32_vrefbuf_voltages), .ops = &stm32_vrefbuf_volt_ops, .off_on_delay = 1000, .type = REGULATOR_VOLTAGE, .owner = THIS_MODULE, }; static int stm32_vrefbuf_probe(struct platform_device *pdev) { struct stm32_vrefbuf *priv; struct regulator_config config = { }; struct regulator_dev *rdev; int ret; priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); if (!priv) return -ENOMEM; priv->dev = &pdev->dev; priv->base = devm_platform_ioremap_resource(pdev, 0); if (IS_ERR(priv->base)) return PTR_ERR(priv->base); priv->clk = devm_clk_get(&pdev->dev, NULL); if (IS_ERR(priv->clk)) return PTR_ERR(priv->clk); pm_runtime_get_noresume(&pdev->dev); pm_runtime_set_active(&pdev->dev); pm_runtime_set_autosuspend_delay(&pdev->dev, STM32_VREFBUF_AUTO_SUSPEND_DELAY_MS); pm_runtime_use_autosuspend(&pdev->dev); pm_runtime_enable(&pdev->dev); ret = clk_prepare_enable(priv->clk); if (ret) { dev_err(&pdev->dev, "clk prepare failed with error %d\n", ret); goto err_pm_stop; } config.dev = &pdev->dev; config.driver_data = priv; config.of_node = pdev->dev.of_node; config.init_data = of_get_regulator_init_data(&pdev->dev, pdev->dev.of_node, &stm32_vrefbuf_regu); rdev = regulator_register(&pdev->dev, &stm32_vrefbuf_regu, &config); if (IS_ERR(rdev)) { ret = PTR_ERR(rdev); dev_err(&pdev->dev, "register failed with error %d\n", ret); goto err_clk_dis; } platform_set_drvdata(pdev, rdev); pm_runtime_mark_last_busy(&pdev->dev); pm_runtime_put_autosuspend(&pdev->dev); return 0; err_clk_dis: clk_disable_unprepare(priv->clk); err_pm_stop: pm_runtime_disable(&pdev->dev); pm_runtime_set_suspended(&pdev->dev); pm_runtime_put_noidle(&pdev->dev); return ret; } static int stm32_vrefbuf_remove(struct platform_device *pdev) { struct regulator_dev *rdev = platform_get_drvdata(pdev); struct stm32_vrefbuf *priv = rdev_get_drvdata(rdev); pm_runtime_get_sync(&pdev->dev); regulator_unregister(rdev); clk_disable_unprepare(priv->clk); pm_runtime_disable(&pdev->dev); pm_runtime_set_suspended(&pdev->dev); pm_runtime_put_noidle(&pdev->dev); return 0; }; static int __maybe_unused stm32_vrefbuf_runtime_suspend(struct device *dev) { struct regulator_dev *rdev = dev_get_drvdata(dev); struct stm32_vrefbuf *priv = rdev_get_drvdata(rdev); clk_disable_unprepare(priv->clk); return 0; } static int __maybe_unused stm32_vrefbuf_runtime_resume(struct device *dev) { struct regulator_dev *rdev = dev_get_drvdata(dev); struct stm32_vrefbuf *priv = rdev_get_drvdata(rdev); return clk_prepare_enable(priv->clk); } static const struct dev_pm_ops stm32_vrefbuf_pm_ops = { SET_SYSTEM_SLEEP_PM_OPS(pm_runtime_force_suspend, pm_runtime_force_resume) SET_RUNTIME_PM_OPS(stm32_vrefbuf_runtime_suspend, stm32_vrefbuf_runtime_resume, NULL) }; static const struct of_device_id __maybe_unused stm32_vrefbuf_of_match[] = { { .compatible = "st,stm32-vrefbuf", }, {}, }; MODULE_DEVICE_TABLE(of, stm32_vrefbuf_of_match); static struct platform_driver stm32_vrefbuf_driver = { .probe = stm32_vrefbuf_probe, .remove = stm32_vrefbuf_remove, .driver = { .name = "stm32-vrefbuf", .of_match_table = of_match_ptr(stm32_vrefbuf_of_match), .pm = &stm32_vrefbuf_pm_ops, }, }; module_platform_driver(stm32_vrefbuf_driver); MODULE_LICENSE("GPL v2"); MODULE_AUTHOR("Fabrice Gasnier <fabrice.gasnier@st.com>"); MODULE_DESCRIPTION("STMicroelectronics STM32 VREFBUF driver"); MODULE_ALIAS("platform:stm32-vrefbuf");
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
You can’t perform that action at this time.