2 * Regulator driver for Ricoh RN5T618 PMIC
4 * Copyright (C) 2014 Beniamino Galvani <b.galvani@gmail.com>
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * version 2 as published by the Free Software Foundation.
10 * You should have received a copy of the GNU General Public License
11 * along with this program. If not, see <http://www.gnu.org/licenses/>.
14 #include <linux/mfd/rn5t618.h>
15 #include <linux/module.h>
17 #include <linux/platform_device.h>
18 #include <linux/regmap.h>
19 #include <linux/regulator/driver.h>
20 #include <linux/regulator/of_regulator.h>
22 static struct regulator_ops rn5t618_reg_ops = {
23 .enable = regulator_enable_regmap,
24 .disable = regulator_disable_regmap,
25 .is_enabled = regulator_is_enabled_regmap,
26 .set_voltage_sel = regulator_set_voltage_sel_regmap,
27 .get_voltage_sel = regulator_get_voltage_sel_regmap,
28 .list_voltage = regulator_list_voltage_linear,
31 #define REG(rid, ereg, emask, vreg, vmask, min, max, step) \
34 .of_match = of_match_ptr(#rid), \
35 .regulators_node = of_match_ptr("regulators"), \
36 .id = RN5T618_##rid, \
37 .type = REGULATOR_VOLTAGE, \
38 .owner = THIS_MODULE, \
39 .ops = &rn5t618_reg_ops, \
40 .n_voltages = ((max) - (min)) / (step) + 1, \
43 .enable_reg = RN5T618_##ereg, \
44 .enable_mask = (emask), \
45 .vsel_reg = RN5T618_##vreg, \
46 .vsel_mask = (vmask), \
49 static struct regulator_desc rn5t567_regulators[] = {
51 REG(DCDC1, DC1CTL, BIT(0), DC1DAC, 0xff, 600000, 3500000, 12500),
52 REG(DCDC2, DC2CTL, BIT(0), DC2DAC, 0xff, 600000, 3500000, 12500),
53 REG(DCDC3, DC3CTL, BIT(0), DC3DAC, 0xff, 600000, 3500000, 12500),
54 REG(DCDC4, DC4CTL, BIT(0), DC4DAC, 0xff, 600000, 3500000, 12500),
56 REG(LDO1, LDOEN1, BIT(0), LDO1DAC, 0x7f, 900000, 3500000, 25000),
57 REG(LDO2, LDOEN1, BIT(1), LDO2DAC, 0x7f, 900000, 3500000, 25000),
58 REG(LDO3, LDOEN1, BIT(2), LDO3DAC, 0x7f, 600000, 3500000, 25000),
59 REG(LDO4, LDOEN1, BIT(3), LDO4DAC, 0x7f, 900000, 3500000, 25000),
60 REG(LDO5, LDOEN1, BIT(4), LDO5DAC, 0x7f, 900000, 3500000, 25000),
62 REG(LDORTC1, LDOEN2, BIT(4), LDORTCDAC, 0x7f, 1200000, 3500000, 25000),
63 REG(LDORTC2, LDOEN2, BIT(5), LDORTC2DAC, 0x7f, 900000, 3500000, 25000),
66 static struct regulator_desc rn5t618_regulators[] = {
68 REG(DCDC1, DC1CTL, BIT(0), DC1DAC, 0xff, 600000, 3500000, 12500),
69 REG(DCDC2, DC2CTL, BIT(0), DC2DAC, 0xff, 600000, 3500000, 12500),
70 REG(DCDC3, DC3CTL, BIT(0), DC3DAC, 0xff, 600000, 3500000, 12500),
72 REG(LDO1, LDOEN1, BIT(0), LDO1DAC, 0x7f, 900000, 3500000, 25000),
73 REG(LDO2, LDOEN1, BIT(1), LDO2DAC, 0x7f, 900000, 3500000, 25000),
74 REG(LDO3, LDOEN1, BIT(2), LDO3DAC, 0x7f, 600000, 3500000, 25000),
75 REG(LDO4, LDOEN1, BIT(3), LDO4DAC, 0x7f, 900000, 3500000, 25000),
76 REG(LDO5, LDOEN1, BIT(4), LDO5DAC, 0x7f, 900000, 3500000, 25000),
78 REG(LDORTC1, LDOEN2, BIT(4), LDORTCDAC, 0x7f, 1700000, 3500000, 25000),
79 REG(LDORTC2, LDOEN2, BIT(5), LDORTC2DAC, 0x7f, 900000, 3500000, 25000),
82 static int rn5t618_regulator_probe(struct platform_device *pdev)
84 struct rn5t618 *rn5t618 = dev_get_drvdata(pdev->dev.parent);
85 struct regulator_config config = { };
86 struct regulator_dev *rdev;
87 struct regulator_desc *regulators;
90 switch (rn5t618->variant) {
92 regulators = rn5t567_regulators;
95 regulators = rn5t618_regulators;
101 config.dev = pdev->dev.parent;
102 config.regmap = rn5t618->regmap;
104 for (i = 0; i < RN5T618_REG_NUM; i++) {
105 if (!regulators[i].name)
108 rdev = devm_regulator_register(&pdev->dev,
112 dev_err(&pdev->dev, "failed to register %s regulator\n",
114 return PTR_ERR(rdev);
121 static struct platform_driver rn5t618_regulator_driver = {
122 .probe = rn5t618_regulator_probe,
124 .name = "rn5t618-regulator",
128 module_platform_driver(rn5t618_regulator_driver);
130 MODULE_AUTHOR("Beniamino Galvani <b.galvani@gmail.com>");
131 MODULE_DESCRIPTION("RN5T618 regulator driver");
132 MODULE_LICENSE("GPL v2");