2 * ROHM BD9571MWV-M regulator driver
4 * Copyright (C) 2017 Marek Vasut <marek.vasut+renesas@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 version 2 as
8 * published by the Free Software Foundation.
10 * This program is distributed "as is" WITHOUT ANY WARRANTY of any
11 * kind, whether expressed or implied; without even the implied warranty
12 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License version 2 for more details.
15 * Based on the TPS65086 driver
17 * NOTE: VD09 is missing
20 #include <linux/module.h>
22 #include <linux/platform_device.h>
23 #include <linux/regulator/driver.h>
25 #include <linux/mfd/bd9571mwv.h>
27 enum bd9571mwv_regulators
{ VD09
, VD18
, VD25
, VD33
, DVFS
};
29 #define BD9571MWV_REG(_name, _of, _id, _ops, _vr, _vm, _nv, _min, _step, _lmin)\
32 .of_match = of_match_ptr(_of), \
33 .regulators_node = "regulators", \
37 .type = REGULATOR_VOLTAGE, \
38 .owner = THIS_MODULE, \
43 .linear_min_sel = _lmin, \
46 static int bd9571mwv_avs_get_moni_state(struct regulator_dev
*rdev
)
51 ret
= regmap_read(rdev
->regmap
, BD9571MWV_AVS_SET_MONI
, &val
);
55 return val
& BD9571MWV_AVS_SET_MONI_MASK
;
58 static int bd9571mwv_avs_set_voltage_sel_regmap(struct regulator_dev
*rdev
,
63 ret
= bd9571mwv_avs_get_moni_state(rdev
);
67 return regmap_write_bits(rdev
->regmap
, BD9571MWV_AVS_VD09_VID(ret
),
68 rdev
->desc
->vsel_mask
, sel
);
71 static int bd9571mwv_avs_get_voltage_sel_regmap(struct regulator_dev
*rdev
)
76 ret
= bd9571mwv_avs_get_moni_state(rdev
);
80 ret
= regmap_read(rdev
->regmap
, BD9571MWV_AVS_VD09_VID(ret
), &val
);
84 val
&= rdev
->desc
->vsel_mask
;
85 val
>>= ffs(rdev
->desc
->vsel_mask
) - 1;
90 static int bd9571mwv_reg_set_voltage_sel_regmap(struct regulator_dev
*rdev
,
93 return regmap_write_bits(rdev
->regmap
, BD9571MWV_DVFS_SETVID
,
94 rdev
->desc
->vsel_mask
, sel
);
97 /* Operations permitted on AVS voltage regulator */
98 static struct regulator_ops avs_ops
= {
99 .set_voltage_sel
= bd9571mwv_avs_set_voltage_sel_regmap
,
100 .map_voltage
= regulator_map_voltage_linear
,
101 .get_voltage_sel
= bd9571mwv_avs_get_voltage_sel_regmap
,
102 .list_voltage
= regulator_list_voltage_linear
,
105 /* Operations permitted on voltage regulators */
106 static struct regulator_ops reg_ops
= {
107 .set_voltage_sel
= bd9571mwv_reg_set_voltage_sel_regmap
,
108 .map_voltage
= regulator_map_voltage_linear
,
109 .get_voltage_sel
= regulator_get_voltage_sel_regmap
,
110 .list_voltage
= regulator_list_voltage_linear
,
113 /* Operations permitted on voltage monitors */
114 static struct regulator_ops vid_ops
= {
115 .map_voltage
= regulator_map_voltage_linear
,
116 .get_voltage_sel
= regulator_get_voltage_sel_regmap
,
117 .list_voltage
= regulator_list_voltage_linear
,
120 static struct regulator_desc regulators
[] = {
121 BD9571MWV_REG("VD09", "vd09", VD09
, avs_ops
, 0, 0x7f,
122 0x80, 600000, 10000, 0x3c),
123 BD9571MWV_REG("VD18", "vd18", VD18
, vid_ops
, BD9571MWV_VD18_VID
, 0xf,
124 16, 1625000, 25000, 0),
125 BD9571MWV_REG("VD25", "vd25", VD25
, vid_ops
, BD9571MWV_VD25_VID
, 0xf,
126 16, 2150000, 50000, 0),
127 BD9571MWV_REG("VD33", "vd33", VD33
, vid_ops
, BD9571MWV_VD33_VID
, 0xf,
128 11, 2800000, 100000, 0),
129 BD9571MWV_REG("DVFS", "dvfs", DVFS
, reg_ops
,
130 BD9571MWV_DVFS_MONIVDAC
, 0x7f,
131 0x80, 600000, 10000, 0x3c),
134 static int bd9571mwv_regulator_probe(struct platform_device
*pdev
)
136 struct bd9571mwv
*bd
= dev_get_drvdata(pdev
->dev
.parent
);
137 struct regulator_config config
= { };
138 struct regulator_dev
*rdev
;
141 platform_set_drvdata(pdev
, bd
);
143 config
.dev
= &pdev
->dev
;
144 config
.dev
->of_node
= bd
->dev
->of_node
;
145 config
.driver_data
= bd
;
146 config
.regmap
= bd
->regmap
;
148 for (i
= 0; i
< ARRAY_SIZE(regulators
); i
++) {
149 rdev
= devm_regulator_register(&pdev
->dev
, ®ulators
[i
],
152 dev_err(bd
->dev
, "failed to register %s regulator\n",
154 return PTR_ERR(rdev
);
161 static const struct platform_device_id bd9571mwv_regulator_id_table
[] = {
162 { "bd9571mwv-regulator", },
165 MODULE_DEVICE_TABLE(platform
, bd9571mwv_regulator_id_table
);
167 static struct platform_driver bd9571mwv_regulator_driver
= {
169 .name
= "bd9571mwv-regulator",
171 .probe
= bd9571mwv_regulator_probe
,
172 .id_table
= bd9571mwv_regulator_id_table
,
174 module_platform_driver(bd9571mwv_regulator_driver
);
176 MODULE_AUTHOR("Marek Vasut <marek.vasut+renesas@gmail.com>");
177 MODULE_DESCRIPTION("BD9571MWV Regulator driver");
178 MODULE_LICENSE("GPL v2");