1 // SPDX-License-Identifier: GPL-2.0-only
3 * Regulator driver for Ricoh RN5T618 PMIC
5 * Copyright (C) 2014 Beniamino Galvani <b.galvani@gmail.com>
8 #include <linux/mfd/rn5t618.h>
9 #include <linux/module.h>
11 #include <linux/platform_device.h>
12 #include <linux/regmap.h>
13 #include <linux/regulator/driver.h>
14 #include <linux/regulator/of_regulator.h>
16 static const struct regulator_ops rn5t618_reg_ops = {
17 .enable = regulator_enable_regmap,
18 .disable = regulator_disable_regmap,
19 .is_enabled = regulator_is_enabled_regmap,
20 .set_voltage_sel = regulator_set_voltage_sel_regmap,
21 .get_voltage_sel = regulator_get_voltage_sel_regmap,
22 .list_voltage = regulator_list_voltage_linear,
25 #define REG(rid, ereg, emask, vreg, vmask, min, max, step) \
28 .of_match = of_match_ptr(#rid), \
29 .regulators_node = of_match_ptr("regulators"), \
30 .id = RN5T618_##rid, \
31 .type = REGULATOR_VOLTAGE, \
32 .owner = THIS_MODULE, \
33 .ops = &rn5t618_reg_ops, \
34 .n_voltages = ((max) - (min)) / (step) + 1, \
37 .enable_reg = RN5T618_##ereg, \
38 .enable_mask = (emask), \
39 .vsel_reg = RN5T618_##vreg, \
40 .vsel_mask = (vmask), \
43 static const struct regulator_desc rn5t567_regulators[] = {
45 REG(DCDC1, DC1CTL, BIT(0), DC1DAC, 0xff, 600000, 3500000, 12500),
46 REG(DCDC2, DC2CTL, BIT(0), DC2DAC, 0xff, 600000, 3500000, 12500),
47 REG(DCDC3, DC3CTL, BIT(0), DC3DAC, 0xff, 600000, 3500000, 12500),
48 REG(DCDC4, DC4CTL, BIT(0), DC4DAC, 0xff, 600000, 3500000, 12500),
50 REG(LDO1, LDOEN1, BIT(0), LDO1DAC, 0x7f, 900000, 3500000, 25000),
51 REG(LDO2, LDOEN1, BIT(1), LDO2DAC, 0x7f, 900000, 3500000, 25000),
52 REG(LDO3, LDOEN1, BIT(2), LDO3DAC, 0x7f, 600000, 3500000, 25000),
53 REG(LDO4, LDOEN1, BIT(3), LDO4DAC, 0x7f, 900000, 3500000, 25000),
54 REG(LDO5, LDOEN1, BIT(4), LDO5DAC, 0x7f, 900000, 3500000, 25000),
56 REG(LDORTC1, LDOEN2, BIT(4), LDORTCDAC, 0x7f, 1200000, 3500000, 25000),
57 REG(LDORTC2, LDOEN2, BIT(5), LDORTC2DAC, 0x7f, 900000, 3500000, 25000),
60 static const struct regulator_desc rn5t618_regulators[] = {
62 REG(DCDC1, DC1CTL, BIT(0), DC1DAC, 0xff, 600000, 3500000, 12500),
63 REG(DCDC2, DC2CTL, BIT(0), DC2DAC, 0xff, 600000, 3500000, 12500),
64 REG(DCDC3, DC3CTL, BIT(0), DC3DAC, 0xff, 600000, 3500000, 12500),
66 REG(LDO1, LDOEN1, BIT(0), LDO1DAC, 0x7f, 900000, 3500000, 25000),
67 REG(LDO2, LDOEN1, BIT(1), LDO2DAC, 0x7f, 900000, 3500000, 25000),
68 REG(LDO3, LDOEN1, BIT(2), LDO3DAC, 0x7f, 600000, 3500000, 25000),
69 REG(LDO4, LDOEN1, BIT(3), LDO4DAC, 0x7f, 900000, 3500000, 25000),
70 REG(LDO5, LDOEN1, BIT(4), LDO5DAC, 0x7f, 900000, 3500000, 25000),
72 REG(LDORTC1, LDOEN2, BIT(4), LDORTCDAC, 0x7f, 1700000, 3500000, 25000),
73 REG(LDORTC2, LDOEN2, BIT(5), LDORTC2DAC, 0x7f, 900000, 3500000, 25000),
76 static const struct regulator_desc rc5t619_regulators[] = {
78 REG(DCDC1, DC1CTL, BIT(0), DC1DAC, 0xff, 600000, 3500000, 12500),
79 REG(DCDC2, DC2CTL, BIT(0), DC2DAC, 0xff, 600000, 3500000, 12500),
80 REG(DCDC3, DC3CTL, BIT(0), DC3DAC, 0xff, 600000, 3500000, 12500),
81 REG(DCDC4, DC4CTL, BIT(0), DC4DAC, 0xff, 600000, 3500000, 12500),
82 REG(DCDC5, DC5CTL, BIT(0), DC5DAC, 0xff, 600000, 3500000, 12500),
84 REG(LDO1, LDOEN1, BIT(0), LDO1DAC, 0x7f, 900000, 3500000, 25000),
85 REG(LDO2, LDOEN1, BIT(1), LDO2DAC, 0x7f, 900000, 3500000, 25000),
86 REG(LDO3, LDOEN1, BIT(2), LDO3DAC, 0x7f, 900000, 3500000, 25000),
87 REG(LDO4, LDOEN1, BIT(3), LDO4DAC, 0x7f, 900000, 3500000, 25000),
88 REG(LDO5, LDOEN1, BIT(4), LDO5DAC, 0x7f, 600000, 3500000, 25000),
89 REG(LDO6, LDOEN1, BIT(5), LDO6DAC, 0x7f, 600000, 3500000, 25000),
90 REG(LDO7, LDOEN1, BIT(6), LDO7DAC, 0x7f, 900000, 3500000, 25000),
91 REG(LDO8, LDOEN1, BIT(7), LDO8DAC, 0x7f, 900000, 3500000, 25000),
92 REG(LDO9, LDOEN2, BIT(0), LDO9DAC, 0x7f, 900000, 3500000, 25000),
93 REG(LDO10, LDOEN2, BIT(1), LDO10DAC, 0x7f, 900000, 3500000, 25000),
95 REG(LDORTC1, LDOEN2, BIT(4), LDORTCDAC, 0x7f, 1700000, 3500000, 25000),
96 REG(LDORTC2, LDOEN2, BIT(5), LDORTC2DAC, 0x7f, 900000, 3500000, 25000),
99 static int rn5t618_regulator_probe(struct platform_device *pdev)
101 struct rn5t618 *rn5t618 = dev_get_drvdata(pdev->dev.parent);
102 struct regulator_config config = { };
103 struct regulator_dev *rdev;
104 const struct regulator_desc *regulators;
106 int num_regulators = 0;
108 switch (rn5t618->variant) {
110 regulators = rn5t567_regulators;
111 num_regulators = ARRAY_SIZE(rn5t567_regulators);
114 regulators = rn5t618_regulators;
115 num_regulators = ARRAY_SIZE(rn5t618_regulators);
118 regulators = rc5t619_regulators;
119 num_regulators = ARRAY_SIZE(rc5t619_regulators);
125 config.dev = pdev->dev.parent;
126 config.regmap = rn5t618->regmap;
128 for (i = 0; i < num_regulators; i++) {
129 rdev = devm_regulator_register(&pdev->dev,
133 dev_err(&pdev->dev, "failed to register %s regulator\n",
135 return PTR_ERR(rdev);
142 static struct platform_driver rn5t618_regulator_driver = {
143 .probe = rn5t618_regulator_probe,
145 .name = "rn5t618-regulator",
146 .probe_type = PROBE_PREFER_ASYNCHRONOUS,
150 module_platform_driver(rn5t618_regulator_driver);
152 MODULE_ALIAS("platform:rn5t618-regulator");
153 MODULE_AUTHOR("Beniamino Galvani <b.galvani@gmail.com>");
154 MODULE_DESCRIPTION("RN5T618 regulator driver");
155 MODULE_LICENSE("GPL v2");