blob: eb807a059479a6e744a767eabb3d880df3f2f80a [file] [log] [blame]
Thomas Gleixner3c910ec2019-06-01 10:09:00 +02001// SPDX-License-Identifier: GPL-2.0-only
Beniamino Galvani811b7002014-08-30 14:50:24 +02002/*
3 * Regulator driver for Ricoh RN5T618 PMIC
4 *
5 * Copyright (C) 2014 Beniamino Galvani <b.galvani@gmail.com>
Beniamino Galvani811b7002014-08-30 14:50:24 +02006 */
7
8#include <linux/mfd/rn5t618.h>
9#include <linux/module.h>
10#include <linux/of.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>
15
Bhumika Goyal243842b2017-01-28 20:52:23 +053016static const struct regulator_ops rn5t618_reg_ops = {
Beniamino Galvani811b7002014-08-30 14:50:24 +020017 .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,
23};
24
25#define REG(rid, ereg, emask, vreg, vmask, min, max, step) \
Leonard Crestezd824c7a2017-10-13 19:37:31 +030026 { \
Beniamino Galvani811b7002014-08-30 14:50:24 +020027 .name = #rid, \
Beniamino Galvani9075cce2014-10-08 23:19:08 +020028 .of_match = of_match_ptr(#rid), \
29 .regulators_node = of_match_ptr("regulators"), \
Beniamino Galvani811b7002014-08-30 14:50:24 +020030 .id = RN5T618_##rid, \
31 .type = REGULATOR_VOLTAGE, \
32 .owner = THIS_MODULE, \
33 .ops = &rn5t618_reg_ops, \
34 .n_voltages = ((max) - (min)) / (step) + 1, \
35 .min_uV = (min), \
36 .uV_step = (step), \
37 .enable_reg = RN5T618_##ereg, \
38 .enable_mask = (emask), \
39 .vsel_reg = RN5T618_##vreg, \
40 .vsel_mask = (vmask), \
41 }
42
Axel Linc2293852019-03-20 20:10:57 +080043static const struct regulator_desc rn5t567_regulators[] = {
Stefan Agnered6d3622016-06-28 22:53:20 -070044 /* DCDC */
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),
49 /* LDO */
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),
55 /* LDO RTC */
56 REG(LDORTC1, LDOEN2, BIT(4), LDORTCDAC, 0x7f, 1200000, 3500000, 25000),
57 REG(LDORTC2, LDOEN2, BIT(5), LDORTC2DAC, 0x7f, 900000, 3500000, 25000),
58};
59
Axel Linc2293852019-03-20 20:10:57 +080060static const struct regulator_desc rn5t618_regulators[] = {
Beniamino Galvani811b7002014-08-30 14:50:24 +020061 /* DCDC */
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),
65 /* LDO */
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),
71 /* LDO RTC */
72 REG(LDORTC1, LDOEN2, BIT(4), LDORTCDAC, 0x7f, 1700000, 3500000, 25000),
73 REG(LDORTC2, LDOEN2, BIT(5), LDORTC2DAC, 0x7f, 900000, 3500000, 25000),
74};
75
Axel Linc2293852019-03-20 20:10:57 +080076static const struct regulator_desc rc5t619_regulators[] = {
Pierre-Hugues Husson83b2a3c2017-08-27 15:58:31 +020077 /* DCDC */
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),
83 /* LDO */
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(0), LDO10DAC, 0x7f, 900000, 3500000, 25000),
94 /* LDO RTC */
95 REG(LDORTC1, LDOEN2, BIT(4), LDORTCDAC, 0x7f, 1700000, 3500000, 25000),
96 REG(LDORTC2, LDOEN2, BIT(5), LDORTC2DAC, 0x7f, 900000, 3500000, 25000),
97};
98
Beniamino Galvani811b7002014-08-30 14:50:24 +020099static int rn5t618_regulator_probe(struct platform_device *pdev)
100{
101 struct rn5t618 *rn5t618 = dev_get_drvdata(pdev->dev.parent);
102 struct regulator_config config = { };
103 struct regulator_dev *rdev;
Axel Linc2293852019-03-20 20:10:57 +0800104 const struct regulator_desc *regulators;
Beniamino Galvani9075cce2014-10-08 23:19:08 +0200105 int i;
Pierre-Hugues Husson83b2a3c2017-08-27 15:58:31 +0200106 int num_regulators = 0;
Beniamino Galvani811b7002014-08-30 14:50:24 +0200107
Stefan Agnered6d3622016-06-28 22:53:20 -0700108 switch (rn5t618->variant) {
109 case RN5T567:
110 regulators = rn5t567_regulators;
Pierre-Hugues Husson83b2a3c2017-08-27 15:58:31 +0200111 num_regulators = ARRAY_SIZE(rn5t567_regulators);
Stefan Agnered6d3622016-06-28 22:53:20 -0700112 break;
113 case RN5T618:
114 regulators = rn5t618_regulators;
Pierre-Hugues Husson83b2a3c2017-08-27 15:58:31 +0200115 num_regulators = ARRAY_SIZE(rn5t618_regulators);
116 break;
117 case RC5T619:
118 regulators = rc5t619_regulators;
119 num_regulators = ARRAY_SIZE(rc5t619_regulators);
Stefan Agnered6d3622016-06-28 22:53:20 -0700120 break;
121 default:
122 return -EINVAL;
123 }
124
125 config.dev = pdev->dev.parent;
126 config.regmap = rn5t618->regmap;
127
Pierre-Hugues Husson83b2a3c2017-08-27 15:58:31 +0200128 for (i = 0; i < num_regulators; i++) {
Beniamino Galvani811b7002014-08-30 14:50:24 +0200129 rdev = devm_regulator_register(&pdev->dev,
Stefan Agnered6d3622016-06-28 22:53:20 -0700130 &regulators[i],
Beniamino Galvani811b7002014-08-30 14:50:24 +0200131 &config);
132 if (IS_ERR(rdev)) {
133 dev_err(&pdev->dev, "failed to register %s regulator\n",
Stefan Agnered6d3622016-06-28 22:53:20 -0700134 regulators[i].name);
Beniamino Galvani811b7002014-08-30 14:50:24 +0200135 return PTR_ERR(rdev);
136 }
137 }
138
139 return 0;
140}
141
142static struct platform_driver rn5t618_regulator_driver = {
143 .probe = rn5t618_regulator_probe,
144 .driver = {
145 .name = "rn5t618-regulator",
146 },
147};
148
149module_platform_driver(rn5t618_regulator_driver);
150
151MODULE_AUTHOR("Beniamino Galvani <b.galvani@gmail.com>");
152MODULE_DESCRIPTION("RN5T618 regulator driver");
153MODULE_LICENSE("GPL v2");