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
3bc7cb9
Documentation
LICENSES
arch
block
certs
crypto
drivers
accessibility
acpi
amba
android
ata
atm
auxdisplay
base
bcma
block
bluetooth
bus
cdrom
char
clk
clocksource
connector
counter
cpufreq
cpuidle
crypto
dax
dca
devfreq
dio
dma-buf
dma
edac
eisa
extcon
firewire
firmware
fpga
fsi
gnss
gpio
gpu
greybus
hid
hsi
hv
hwmon
hwspinlock
hwtracing
i2c
i3c
ide
idle
iio
infiniband
input
interconnect
iommu
ipack
irqchip
isdn
leds
lightnvm
macintosh
mailbox
mcb
md
media
memory
memstick
message
mfd
misc
mmc
most
mtd
mux
net
nfc
ntb
nubus
nvdimm
nvme
nvmem
of
opp
oprofile
parisc
parport
pci
pcmcia
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
ab3100.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
bd70528-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
hi655x-regulator.c
internal.h
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
max77620-regulator.c
max77650-regulator.c
max77686-regulator.c
max77693-regulator.c
max77802-regulator.c
max77826-regulator.c
max8649.c
max8660.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
mt6323-regulator.c
mt6358-regulator.c
mt6360-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
rtmv20-regulator.c
s2mpa01.c
s2mps11.c
s5m8767.c
sc2731-regulator.c
scmi-regulator.c
sky81452-regulator.c
slg51000-regulator.c
slg51000-regulator.h
stm32-booster.c
stm32-pwr.c
stm32-vrefbuf.c
stpmic1_regulator.c
stw481x-vmmc.c
sy8106a-regulator.c
sy8824x.c
sy8827n.c
ti-abb-regulator.c
tps51632-regulator.c
tps6105x-regulator.c
tps62360-regulator.c
tps65023-regulator.c
tps6507x-regulator.c
tps65086-regulator.c
tps65090-regulator.c
tps65132-regulator.c
tps65217-regulator.c
tps65218-regulator.c
tps6524x-regulator.c
tps6586x-regulator.c
tps65910-regulator.c
tps65912-regulator.c
tps80031-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
sfi
sh
siox
slimbus
soc
soundwire
spi
spmi
ssb
staging
target
tc
tee
thermal
thunderbolt
tty
uio
usb
vdpa
vfio
vhost
video
virt
virtio
visorbus
vlynq
vme
w1
watchdog
xen
zorro
Kconfig
Makefile
fs
include
init
ipc
kernel
lib
mm
net
samples
scripts
security
sound
tools
usr
virt
.clang-format
.cocciconfig
.get_maintainer.ignore
.gitattributes
.gitignore
.mailmap
COPYING
CREDITS
Kbuild
Kconfig
MAINTAINERS
Makefile
README
Breadcrumbs
linux
/
drivers
/
regulator
/
qcom-labibb-regulator.c
Blame
Blame
Latest commit
History
History
385 lines (324 loc) · 10.8 KB
Breadcrumbs
linux
/
drivers
/
regulator
/
qcom-labibb-regulator.c
Top
File metadata and controls
Code
Blame
385 lines (324 loc) · 10.8 KB
Raw
// SPDX-License-Identifier: GPL-2.0-only // Copyright (c) 2020, The Linux Foundation. All rights reserved. #include <linux/module.h> #include <linux/of_irq.h> #include <linux/of.h> #include <linux/of_device.h> #include <linux/platform_device.h> #include <linux/regmap.h> #include <linux/regulator/driver.h> #include <linux/regulator/of_regulator.h> #define REG_PERPH_TYPE 0x04 #define QCOM_LAB_TYPE 0x24 #define QCOM_IBB_TYPE 0x20 #define PMI8998_LAB_REG_BASE 0xde00 #define PMI8998_IBB_REG_BASE 0xdc00 #define REG_LABIBB_STATUS1 0x08 #define REG_LABIBB_VOLTAGE 0x41 #define LABIBB_VOLTAGE_OVERRIDE_EN BIT(7) #define LAB_VOLTAGE_SET_MASK GENMASK(3, 0) #define IBB_VOLTAGE_SET_MASK GENMASK(5, 0) #define REG_LABIBB_ENABLE_CTL 0x46 #define LABIBB_STATUS1_VREG_OK_BIT BIT(7) #define LABIBB_CONTROL_ENABLE BIT(7) #define REG_LABIBB_PD_CTL 0x47 #define LAB_PD_CTL_MASK GENMASK(1, 0) #define IBB_PD_CTL_MASK (BIT(0) | BIT(7)) #define LAB_PD_CTL_STRONG_PULL BIT(0) #define IBB_PD_CTL_HALF_STRENGTH BIT(0) #define IBB_PD_CTL_EN BIT(7) #define REG_LABIBB_CURRENT_LIMIT 0x4b #define LAB_CURRENT_LIMIT_MASK GENMASK(2, 0) #define IBB_CURRENT_LIMIT_MASK GENMASK(4, 0) #define LAB_CURRENT_LIMIT_OVERRIDE_EN BIT(3) #define LABIBB_CURRENT_LIMIT_EN BIT(7) #define REG_IBB_PWRUP_PWRDN_CTL_1 0x58 #define IBB_CTL_1_DISCHARGE_EN BIT(2) #define REG_LABIBB_SOFT_START_CTL 0x5f #define REG_LABIBB_SEC_ACCESS 0xd0 #define LABIBB_SEC_UNLOCK_CODE 0xa5 #define LAB_ENABLE_CTL_MASK BIT(7) #define IBB_ENABLE_CTL_MASK (BIT(7) | BIT(6)) #define LABIBB_OFF_ON_DELAY 1000 #define LAB_ENABLE_TIME (LABIBB_OFF_ON_DELAY * 2) #define IBB_ENABLE_TIME (LABIBB_OFF_ON_DELAY * 10) #define LABIBB_POLL_ENABLED_TIME 1000 struct labibb_current_limits { u32 uA_min; u32 uA_step; u8 ovr_val; }; struct labibb_regulator { struct regulator_desc desc; struct device *dev; struct regmap *regmap; struct regulator_dev *rdev; struct labibb_current_limits uA_limits; u16 base; u8 type; u8 dischg_sel; u8 soft_start_sel; }; struct labibb_regulator_data { const char *name; u8 type; u16 base; const struct regulator_desc *desc; }; static int qcom_labibb_set_current_limit(struct regulator_dev *rdev, int min_uA, int max_uA) { struct labibb_regulator *vreg = rdev_get_drvdata(rdev); struct regulator_desc *desc = &vreg->desc; struct labibb_current_limits *lim = &vreg->uA_limits; u32 mask, val; int i, ret, sel = -1; if (min_uA < lim->uA_min || max_uA < lim->uA_min) return -EINVAL; for (i = 0; i < desc->n_current_limits; i++) { int uA_limit = (lim->uA_step * i) + lim->uA_min; if (max_uA >= uA_limit && min_uA <= uA_limit) sel = i; } if (sel < 0) return -EINVAL; /* Current limit setting needs secure access */ ret = regmap_write(vreg->regmap, vreg->base + REG_LABIBB_SEC_ACCESS, LABIBB_SEC_UNLOCK_CODE); if (ret) return ret; mask = desc->csel_mask | lim->ovr_val; mask |= LABIBB_CURRENT_LIMIT_EN; val = (u32)sel | lim->ovr_val; val |= LABIBB_CURRENT_LIMIT_EN; return regmap_update_bits(vreg->regmap, desc->csel_reg, mask, val); } static int qcom_labibb_get_current_limit(struct regulator_dev *rdev) { struct labibb_regulator *vreg = rdev_get_drvdata(rdev); struct regulator_desc *desc = &vreg->desc; struct labibb_current_limits *lim = &vreg->uA_limits; unsigned int cur_step; int ret; ret = regmap_read(vreg->regmap, desc->csel_reg, &cur_step); if (ret) return ret; cur_step &= desc->csel_mask; return (cur_step * lim->uA_step) + lim->uA_min; } static int qcom_labibb_set_soft_start(struct regulator_dev *rdev) { struct labibb_regulator *vreg = rdev_get_drvdata(rdev); u32 val = 0; if (vreg->type == QCOM_IBB_TYPE) val = vreg->dischg_sel; else val = vreg->soft_start_sel; return regmap_write(rdev->regmap, rdev->desc->soft_start_reg, val); } static int qcom_labibb_get_table_sel(const int *table, int sz, u32 value) { int i; for (i = 0; i < sz; i++) if (table[i] == value) return i; return -EINVAL; } /* IBB discharge resistor values in KOhms */ static const int dischg_resistor_values[] = { 300, 64, 32, 16 }; /* Soft start time in microseconds */ static const int soft_start_values[] = { 200, 400, 600, 800 }; static int qcom_labibb_of_parse_cb(struct device_node *np, const struct regulator_desc *desc, struct regulator_config *config) { struct labibb_regulator *vreg = config->driver_data; u32 dischg_kohms, soft_start_time; int ret; ret = of_property_read_u32(np, "qcom,discharge-resistor-kohms", &dischg_kohms); if (ret) dischg_kohms = 300; ret = qcom_labibb_get_table_sel(dischg_resistor_values, ARRAY_SIZE(dischg_resistor_values), dischg_kohms); if (ret < 0) return ret; vreg->dischg_sel = (u8)ret; ret = of_property_read_u32(np, "qcom,soft-start-us", &soft_start_time); if (ret) soft_start_time = 200; ret = qcom_labibb_get_table_sel(soft_start_values, ARRAY_SIZE(soft_start_values), soft_start_time); if (ret < 0) return ret; vreg->soft_start_sel = (u8)ret; return 0; } static const struct regulator_ops qcom_labibb_ops = { .enable = regulator_enable_regmap, .disable = regulator_disable_regmap, .is_enabled = regulator_is_enabled_regmap, .set_voltage_sel = regulator_set_voltage_sel_regmap, .get_voltage_sel = regulator_get_voltage_sel_regmap, .list_voltage = regulator_list_voltage_linear, .map_voltage = regulator_map_voltage_linear, .set_active_discharge = regulator_set_active_discharge_regmap, .set_pull_down = regulator_set_pull_down_regmap, .set_current_limit = qcom_labibb_set_current_limit, .get_current_limit = qcom_labibb_get_current_limit, .set_soft_start = qcom_labibb_set_soft_start, }; static const struct regulator_desc pmi8998_lab_desc = { .enable_mask = LAB_ENABLE_CTL_MASK, .enable_reg = (PMI8998_LAB_REG_BASE + REG_LABIBB_ENABLE_CTL), .enable_val = LABIBB_CONTROL_ENABLE, .enable_time = LAB_ENABLE_TIME, .poll_enabled_time = LABIBB_POLL_ENABLED_TIME, .soft_start_reg = (PMI8998_LAB_REG_BASE + REG_LABIBB_SOFT_START_CTL), .pull_down_reg = (PMI8998_LAB_REG_BASE + REG_LABIBB_PD_CTL), .pull_down_mask = LAB_PD_CTL_MASK, .pull_down_val_on = LAB_PD_CTL_STRONG_PULL, .vsel_reg = (PMI8998_LAB_REG_BASE + REG_LABIBB_VOLTAGE), .vsel_mask = LAB_VOLTAGE_SET_MASK, .apply_reg = (PMI8998_LAB_REG_BASE + REG_LABIBB_VOLTAGE), .apply_bit = LABIBB_VOLTAGE_OVERRIDE_EN, .csel_reg = (PMI8998_LAB_REG_BASE + REG_LABIBB_CURRENT_LIMIT), .csel_mask = LAB_CURRENT_LIMIT_MASK, .n_current_limits = 8, .off_on_delay = LABIBB_OFF_ON_DELAY, .owner = THIS_MODULE, .type = REGULATOR_VOLTAGE, .min_uV = 4600000, .uV_step = 100000, .n_voltages = 16, .ops = &qcom_labibb_ops, .of_parse_cb = qcom_labibb_of_parse_cb, }; static const struct regulator_desc pmi8998_ibb_desc = { .enable_mask = IBB_ENABLE_CTL_MASK, .enable_reg = (PMI8998_IBB_REG_BASE + REG_LABIBB_ENABLE_CTL), .enable_val = LABIBB_CONTROL_ENABLE, .enable_time = IBB_ENABLE_TIME, .poll_enabled_time = LABIBB_POLL_ENABLED_TIME, .soft_start_reg = (PMI8998_IBB_REG_BASE + REG_LABIBB_SOFT_START_CTL), .active_discharge_off = 0, .active_discharge_on = IBB_CTL_1_DISCHARGE_EN, .active_discharge_mask = IBB_CTL_1_DISCHARGE_EN, .active_discharge_reg = (PMI8998_IBB_REG_BASE + REG_IBB_PWRUP_PWRDN_CTL_1), .pull_down_reg = (PMI8998_IBB_REG_BASE + REG_LABIBB_PD_CTL), .pull_down_mask = IBB_PD_CTL_MASK, .pull_down_val_on = IBB_PD_CTL_HALF_STRENGTH | IBB_PD_CTL_EN, .vsel_reg = (PMI8998_IBB_REG_BASE + REG_LABIBB_VOLTAGE), .vsel_mask = IBB_VOLTAGE_SET_MASK, .apply_reg = (PMI8998_IBB_REG_BASE + REG_LABIBB_VOLTAGE), .apply_bit = LABIBB_VOLTAGE_OVERRIDE_EN, .csel_reg = (PMI8998_IBB_REG_BASE + REG_LABIBB_CURRENT_LIMIT), .csel_mask = IBB_CURRENT_LIMIT_MASK, .n_current_limits = 32, .off_on_delay = LABIBB_OFF_ON_DELAY, .owner = THIS_MODULE, .type = REGULATOR_VOLTAGE, .min_uV = 1400000, .uV_step = 100000, .n_voltages = 64, .ops = &qcom_labibb_ops, .of_parse_cb = qcom_labibb_of_parse_cb, }; static const struct labibb_regulator_data pmi8998_labibb_data[] = { {"lab", QCOM_LAB_TYPE, PMI8998_LAB_REG_BASE, &pmi8998_lab_desc}, {"ibb", QCOM_IBB_TYPE, PMI8998_IBB_REG_BASE, &pmi8998_ibb_desc}, { }, }; static const struct of_device_id qcom_labibb_match[] = { { .compatible = "qcom,pmi8998-lab-ibb", .data = &pmi8998_labibb_data}, { }, }; MODULE_DEVICE_TABLE(of, qcom_labibb_match); static int qcom_labibb_regulator_probe(struct platform_device *pdev) { struct labibb_regulator *vreg; struct device *dev = &pdev->dev; struct regulator_config cfg = {}; const struct of_device_id *match; const struct labibb_regulator_data *reg_data; struct regmap *reg_regmap; unsigned int type; int ret; reg_regmap = dev_get_regmap(pdev->dev.parent, NULL); if (!reg_regmap) { dev_err(&pdev->dev, "Couldn't get parent's regmap\n"); return -ENODEV; } match = of_match_device(qcom_labibb_match, &pdev->dev); if (!match) return -ENODEV; for (reg_data = match->data; reg_data->name; reg_data++) { /* Validate if the type of regulator is indeed * what's mentioned in DT. */ ret = regmap_read(reg_regmap, reg_data->base + REG_PERPH_TYPE, &type); if (ret < 0) { dev_err(dev, "Peripheral type read failed ret=%d\n", ret); return -EINVAL; } if (WARN_ON((type != QCOM_LAB_TYPE) && (type != QCOM_IBB_TYPE)) || WARN_ON(type != reg_data->type)) return -EINVAL; vreg = devm_kzalloc(&pdev->dev, sizeof(*vreg), GFP_KERNEL); if (!vreg) return -ENOMEM; vreg->regmap = reg_regmap; vreg->dev = dev; vreg->base = reg_data->base; vreg->type = reg_data->type; switch (vreg->type) { case QCOM_LAB_TYPE: /* LAB Limits: 200-1600mA */ vreg->uA_limits.uA_min = 200000; vreg->uA_limits.uA_step = 200000; vreg->uA_limits.ovr_val = LAB_CURRENT_LIMIT_OVERRIDE_EN; break; case QCOM_IBB_TYPE: /* IBB Limits: 0-1550mA */ vreg->uA_limits.uA_min = 0; vreg->uA_limits.uA_step = 50000; vreg->uA_limits.ovr_val = 0; /* No override bit */ break; default: return -EINVAL; } memcpy(&vreg->desc, reg_data->desc, sizeof(vreg->desc)); vreg->desc.of_match = reg_data->name; vreg->desc.name = reg_data->name; cfg.dev = vreg->dev; cfg.driver_data = vreg; cfg.regmap = vreg->regmap; vreg->rdev = devm_regulator_register(vreg->dev, &vreg->desc, &cfg); if (IS_ERR(vreg->rdev)) { dev_err(dev, "qcom_labibb: error registering %s : %d\n", reg_data->name, ret); return PTR_ERR(vreg->rdev); } } return 0; } static struct platform_driver qcom_labibb_regulator_driver = { .driver = { .name = "qcom-lab-ibb-regulator", .of_match_table = qcom_labibb_match, }, .probe = qcom_labibb_regulator_probe, }; module_platform_driver(qcom_labibb_regulator_driver); MODULE_DESCRIPTION("Qualcomm labibb driver"); MODULE_AUTHOR("Nisha Kumari <nishakumari@codeaurora.org>"); MODULE_AUTHOR("Sumit Semwal <sumit.semwal@linaro.org>"); MODULE_LICENSE("GPL v2");
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
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
You can’t perform that action at this time.