Linux Audio

Check our new training course

Loading...
v5.9
  1// SPDX-License-Identifier: GPL-2.0-only
  2// Copyright (C) 2019 ROHM Semiconductors
  3// bd71828-regulator.c ROHM BD71828GW-DS1 regulator driver
  4//
  5
  6#include <linux/delay.h>
  7#include <linux/err.h>
  8#include <linux/gpio.h>
  9#include <linux/interrupt.h>
 10#include <linux/kernel.h>
 11#include <linux/mfd/rohm-bd71828.h>
 12#include <linux/module.h>
 13#include <linux/of.h>
 14#include <linux/platform_device.h>
 15#include <linux/regmap.h>
 16#include <linux/regulator/driver.h>
 17#include <linux/regulator/machine.h>
 18#include <linux/regulator/of_regulator.h>
 19
 20struct reg_init {
 21	unsigned int reg;
 22	unsigned int mask;
 23	unsigned int val;
 24};
 25struct bd71828_regulator_data {
 26	struct regulator_desc desc;
 27	const struct rohm_dvs_config dvs;
 28	const struct reg_init *reg_inits;
 29	int reg_init_amnt;
 30};
 31
 32static const struct reg_init buck1_inits[] = {
 33	/*
 34	 * DVS Buck voltages can be changed by register values or via GPIO.
 35	 * Use register accesses by default.
 36	 */
 37	{
 38		.reg = BD71828_REG_PS_CTRL_1,
 39		.mask = BD71828_MASK_DVS_BUCK1_CTRL,
 40		.val = BD71828_DVS_BUCK1_CTRL_I2C,
 41	},
 42};
 43
 44static const struct reg_init buck2_inits[] = {
 45	{
 46		.reg = BD71828_REG_PS_CTRL_1,
 47		.mask = BD71828_MASK_DVS_BUCK2_CTRL,
 48		.val = BD71828_DVS_BUCK2_CTRL_I2C,
 49	},
 50};
 51
 52static const struct reg_init buck6_inits[] = {
 53	{
 54		.reg = BD71828_REG_PS_CTRL_1,
 55		.mask = BD71828_MASK_DVS_BUCK6_CTRL,
 56		.val = BD71828_DVS_BUCK6_CTRL_I2C,
 57	},
 58};
 59
 60static const struct reg_init buck7_inits[] = {
 61	{
 62		.reg = BD71828_REG_PS_CTRL_1,
 63		.mask = BD71828_MASK_DVS_BUCK7_CTRL,
 64		.val = BD71828_DVS_BUCK7_CTRL_I2C,
 65	},
 66};
 67
 68static const struct linear_range bd71828_buck1267_volts[] = {
 69	REGULATOR_LINEAR_RANGE(500000, 0x00, 0xef, 6250),
 70	REGULATOR_LINEAR_RANGE(2000000, 0xf0, 0xff, 0),
 71};
 72
 73static const struct linear_range bd71828_buck3_volts[] = {
 74	REGULATOR_LINEAR_RANGE(1200000, 0x00, 0x0f, 50000),
 75	REGULATOR_LINEAR_RANGE(2000000, 0x10, 0x1f, 0),
 76};
 77
 78static const struct linear_range bd71828_buck4_volts[] = {
 79	REGULATOR_LINEAR_RANGE(1000000, 0x00, 0x1f, 25000),
 80	REGULATOR_LINEAR_RANGE(1800000, 0x20, 0x3f, 0),
 81};
 82
 83static const struct linear_range bd71828_buck5_volts[] = {
 84	REGULATOR_LINEAR_RANGE(2500000, 0x00, 0x0f, 50000),
 85	REGULATOR_LINEAR_RANGE(3300000, 0x10, 0x1f, 0),
 86};
 87
 88static const struct linear_range bd71828_ldo_volts[] = {
 89	REGULATOR_LINEAR_RANGE(800000, 0x00, 0x31, 50000),
 90	REGULATOR_LINEAR_RANGE(3300000, 0x32, 0x3f, 0),
 91};
 92
 93static int bd71828_set_ramp_delay(struct regulator_dev *rdev, int ramp_delay)
 94{
 95	unsigned int val;
 96
 97	switch (ramp_delay) {
 98	case 1 ... 2500:
 99		val = 0;
100		break;
101	case 2501 ... 5000:
102		val = 1;
103		break;
104	case 5001 ... 10000:
105		val = 2;
106		break;
107	case 10001 ... 20000:
108		val = 3;
109		break;
110	default:
111		val = 3;
112		dev_err(&rdev->dev,
113			"ramp_delay: %d not supported, setting 20mV/uS",
114			 ramp_delay);
115	}
116
117	/*
118	 * On BD71828 the ramp delay level control reg is at offset +2 to
119	 * enable reg
120	 */
121	return regmap_update_bits(rdev->regmap, rdev->desc->enable_reg + 2,
122				  BD71828_MASK_RAMP_DELAY,
123				  val << (ffs(BD71828_MASK_RAMP_DELAY) - 1));
124}
125
126static int buck_set_hw_dvs_levels(struct device_node *np,
127				  const struct regulator_desc *desc,
128				  struct regulator_config *cfg)
129{
130	struct bd71828_regulator_data *data;
131
132	data = container_of(desc, struct bd71828_regulator_data, desc);
133
134	return rohm_regulator_set_dvs_levels(&data->dvs, np, desc, cfg->regmap);
135}
136
137static int ldo6_parse_dt(struct device_node *np,
138			 const struct regulator_desc *desc,
139			 struct regulator_config *cfg)
140{
141	int ret, i;
142	uint32_t uv = 0;
143	unsigned int en;
144	struct regmap *regmap = cfg->regmap;
145	static const char * const props[] = { "rohm,dvs-run-voltage",
146					      "rohm,dvs-idle-voltage",
147					      "rohm,dvs-suspend-voltage",
148					      "rohm,dvs-lpsr-voltage" };
149	unsigned int mask[] = { BD71828_MASK_RUN_EN, BD71828_MASK_IDLE_EN,
150			       BD71828_MASK_SUSP_EN, BD71828_MASK_LPSR_EN };
151
152	for (i = 0; i < ARRAY_SIZE(props); i++) {
153		ret = of_property_read_u32(np, props[i], &uv);
154		if (ret) {
155			if (ret != -EINVAL)
156				return ret;
157			continue;
158		}
159		if (uv)
160			en = 0xffffffff;
161		else
162			en = 0;
163
164		ret = regmap_update_bits(regmap, desc->enable_reg, mask[i], en);
165		if (ret)
166			return ret;
167	}
168	return 0;
169}
170
171static const struct regulator_ops bd71828_buck_ops = {
172	.enable = regulator_enable_regmap,
173	.disable = regulator_disable_regmap,
174	.is_enabled = regulator_is_enabled_regmap,
175	.list_voltage = regulator_list_voltage_linear_range,
176	.set_voltage_sel = regulator_set_voltage_sel_regmap,
177	.get_voltage_sel = regulator_get_voltage_sel_regmap,
178};
179
180static const struct regulator_ops bd71828_dvs_buck_ops = {
181	.enable = regulator_enable_regmap,
182	.disable = regulator_disable_regmap,
183	.is_enabled = regulator_is_enabled_regmap,
184	.list_voltage = regulator_list_voltage_linear_range,
185	.set_voltage_sel = regulator_set_voltage_sel_regmap,
186	.get_voltage_sel = regulator_get_voltage_sel_regmap,
187	.set_voltage_time_sel = regulator_set_voltage_time_sel,
188	.set_ramp_delay = bd71828_set_ramp_delay,
189};
190
191static const struct regulator_ops bd71828_ldo_ops = {
192	.enable = regulator_enable_regmap,
193	.disable = regulator_disable_regmap,
194	.is_enabled = regulator_is_enabled_regmap,
195	.list_voltage = regulator_list_voltage_linear_range,
196	.set_voltage_sel = regulator_set_voltage_sel_regmap,
197	.get_voltage_sel = regulator_get_voltage_sel_regmap,
198};
199
200static const struct regulator_ops bd71828_ldo6_ops = {
201	.enable = regulator_enable_regmap,
202	.disable = regulator_disable_regmap,
203	.is_enabled = regulator_is_enabled_regmap,
204};
205
206static const struct bd71828_regulator_data bd71828_rdata[] = {
207	{
208		.desc = {
209			.name = "buck1",
210			.of_match = of_match_ptr("BUCK1"),
211			.regulators_node = of_match_ptr("regulators"),
212			.id = BD71828_BUCK1,
213			.ops = &bd71828_dvs_buck_ops,
214			.type = REGULATOR_VOLTAGE,
215			.linear_ranges = bd71828_buck1267_volts,
216			.n_linear_ranges = ARRAY_SIZE(bd71828_buck1267_volts),
217			.n_voltages = BD71828_BUCK1267_VOLTS,
218			.enable_reg = BD71828_REG_BUCK1_EN,
219			.enable_mask = BD71828_MASK_RUN_EN,
220			.vsel_reg = BD71828_REG_BUCK1_VOLT,
221			.vsel_mask = BD71828_MASK_BUCK1267_VOLT,
 
 
 
 
222			.owner = THIS_MODULE,
223			.of_parse_cb = buck_set_hw_dvs_levels,
224		},
225		.dvs = {
226			.level_map = ROHM_DVS_LEVEL_RUN | ROHM_DVS_LEVEL_IDLE |
227				     ROHM_DVS_LEVEL_SUSPEND |
228				     ROHM_DVS_LEVEL_LPSR,
229			.run_reg = BD71828_REG_BUCK1_VOLT,
230			.run_mask = BD71828_MASK_BUCK1267_VOLT,
231			.idle_reg = BD71828_REG_BUCK1_IDLE_VOLT,
232			.idle_mask = BD71828_MASK_BUCK1267_VOLT,
233			.idle_on_mask = BD71828_MASK_IDLE_EN,
234			.suspend_reg = BD71828_REG_BUCK1_SUSP_VOLT,
235			.suspend_mask = BD71828_MASK_BUCK1267_VOLT,
236			.suspend_on_mask = BD71828_MASK_SUSP_EN,
237			.lpsr_on_mask = BD71828_MASK_LPSR_EN,
238			/*
239			 * LPSR voltage is same as SUSPEND voltage. Allow
240			 * setting it so that regulator can be set enabled at
241			 * LPSR state
242			 */
243			.lpsr_reg = BD71828_REG_BUCK1_SUSP_VOLT,
244			.lpsr_mask = BD71828_MASK_BUCK1267_VOLT,
245		},
246		.reg_inits = buck1_inits,
247		.reg_init_amnt = ARRAY_SIZE(buck1_inits),
248	},
249	{
250		.desc = {
251			.name = "buck2",
252			.of_match = of_match_ptr("BUCK2"),
253			.regulators_node = of_match_ptr("regulators"),
254			.id = BD71828_BUCK2,
255			.ops = &bd71828_dvs_buck_ops,
256			.type = REGULATOR_VOLTAGE,
257			.linear_ranges = bd71828_buck1267_volts,
258			.n_linear_ranges = ARRAY_SIZE(bd71828_buck1267_volts),
259			.n_voltages = BD71828_BUCK1267_VOLTS,
260			.enable_reg = BD71828_REG_BUCK2_EN,
261			.enable_mask = BD71828_MASK_RUN_EN,
262			.vsel_reg = BD71828_REG_BUCK2_VOLT,
263			.vsel_mask = BD71828_MASK_BUCK1267_VOLT,
 
 
 
 
264			.owner = THIS_MODULE,
265			.of_parse_cb = buck_set_hw_dvs_levels,
266		},
267		.dvs = {
268			.level_map = ROHM_DVS_LEVEL_RUN | ROHM_DVS_LEVEL_IDLE |
269				     ROHM_DVS_LEVEL_SUSPEND |
270				     ROHM_DVS_LEVEL_LPSR,
271			.run_reg = BD71828_REG_BUCK2_VOLT,
272			.run_mask = BD71828_MASK_BUCK1267_VOLT,
273			.idle_reg = BD71828_REG_BUCK2_IDLE_VOLT,
274			.idle_mask = BD71828_MASK_BUCK1267_VOLT,
275			.idle_on_mask = BD71828_MASK_IDLE_EN,
276			.suspend_reg = BD71828_REG_BUCK2_SUSP_VOLT,
277			.suspend_mask = BD71828_MASK_BUCK1267_VOLT,
278			.suspend_on_mask = BD71828_MASK_SUSP_EN,
279			.lpsr_on_mask = BD71828_MASK_LPSR_EN,
280			.lpsr_reg = BD71828_REG_BUCK2_SUSP_VOLT,
281			.lpsr_mask = BD71828_MASK_BUCK1267_VOLT,
282		},
283		.reg_inits = buck2_inits,
284		.reg_init_amnt = ARRAY_SIZE(buck2_inits),
285	},
286	{
287		.desc = {
288			.name = "buck3",
289			.of_match = of_match_ptr("BUCK3"),
290			.regulators_node = of_match_ptr("regulators"),
291			.id = BD71828_BUCK3,
292			.ops = &bd71828_buck_ops,
293			.type = REGULATOR_VOLTAGE,
294			.linear_ranges = bd71828_buck3_volts,
295			.n_linear_ranges = ARRAY_SIZE(bd71828_buck3_volts),
296			.n_voltages = BD71828_BUCK3_VOLTS,
297			.enable_reg = BD71828_REG_BUCK3_EN,
298			.enable_mask = BD71828_MASK_RUN_EN,
299			.vsel_reg = BD71828_REG_BUCK3_VOLT,
300			.vsel_mask = BD71828_MASK_BUCK3_VOLT,
301			.owner = THIS_MODULE,
302			.of_parse_cb = buck_set_hw_dvs_levels,
303		},
304		.dvs = {
305			/*
306			 * BUCK3 only supports single voltage for all states.
307			 * voltage can be individually enabled for each state
308			 * though => allow setting all states to support
309			 * enabling power rail on different states.
310			 */
311			.level_map = ROHM_DVS_LEVEL_RUN | ROHM_DVS_LEVEL_IDLE |
312				     ROHM_DVS_LEVEL_SUSPEND |
313				     ROHM_DVS_LEVEL_LPSR,
314			.run_reg = BD71828_REG_BUCK3_VOLT,
315			.idle_reg = BD71828_REG_BUCK3_VOLT,
316			.suspend_reg = BD71828_REG_BUCK3_VOLT,
317			.lpsr_reg = BD71828_REG_BUCK3_VOLT,
318			.run_mask = BD71828_MASK_BUCK3_VOLT,
319			.idle_mask = BD71828_MASK_BUCK3_VOLT,
320			.suspend_mask = BD71828_MASK_BUCK3_VOLT,
321			.lpsr_mask = BD71828_MASK_BUCK3_VOLT,
322			.idle_on_mask = BD71828_MASK_IDLE_EN,
323			.suspend_on_mask = BD71828_MASK_SUSP_EN,
324			.lpsr_on_mask = BD71828_MASK_LPSR_EN,
325		},
326	},
327	{
328		.desc = {
329			.name = "buck4",
330			.of_match = of_match_ptr("BUCK4"),
331			.regulators_node = of_match_ptr("regulators"),
332			.id = BD71828_BUCK4,
333			.ops = &bd71828_buck_ops,
334			.type = REGULATOR_VOLTAGE,
335			.linear_ranges = bd71828_buck4_volts,
336			.n_linear_ranges = ARRAY_SIZE(bd71828_buck4_volts),
337			.n_voltages = BD71828_BUCK4_VOLTS,
338			.enable_reg = BD71828_REG_BUCK4_EN,
339			.enable_mask = BD71828_MASK_RUN_EN,
340			.vsel_reg = BD71828_REG_BUCK4_VOLT,
341			.vsel_mask = BD71828_MASK_BUCK4_VOLT,
342			.owner = THIS_MODULE,
343			.of_parse_cb = buck_set_hw_dvs_levels,
344		},
345		.dvs = {
346			/*
347			 * BUCK4 only supports single voltage for all states.
348			 * voltage can be individually enabled for each state
349			 * though => allow setting all states to support
350			 * enabling power rail on different states.
351			 */
352			.level_map = ROHM_DVS_LEVEL_RUN | ROHM_DVS_LEVEL_IDLE |
353				     ROHM_DVS_LEVEL_SUSPEND |
354				     ROHM_DVS_LEVEL_LPSR,
355			.run_reg = BD71828_REG_BUCK4_VOLT,
356			.idle_reg = BD71828_REG_BUCK4_VOLT,
357			.suspend_reg = BD71828_REG_BUCK4_VOLT,
358			.lpsr_reg = BD71828_REG_BUCK4_VOLT,
359			.run_mask = BD71828_MASK_BUCK4_VOLT,
360			.idle_mask = BD71828_MASK_BUCK4_VOLT,
361			.suspend_mask = BD71828_MASK_BUCK4_VOLT,
362			.lpsr_mask = BD71828_MASK_BUCK4_VOLT,
363			.idle_on_mask = BD71828_MASK_IDLE_EN,
364			.suspend_on_mask = BD71828_MASK_SUSP_EN,
365			.lpsr_on_mask = BD71828_MASK_LPSR_EN,
366		},
367	},
368	{
369		.desc = {
370			.name = "buck5",
371			.of_match = of_match_ptr("BUCK5"),
372			.regulators_node = of_match_ptr("regulators"),
373			.id = BD71828_BUCK5,
374			.ops = &bd71828_buck_ops,
375			.type = REGULATOR_VOLTAGE,
376			.linear_ranges = bd71828_buck5_volts,
377			.n_linear_ranges = ARRAY_SIZE(bd71828_buck5_volts),
378			.n_voltages = BD71828_BUCK5_VOLTS,
379			.enable_reg = BD71828_REG_BUCK5_EN,
380			.enable_mask = BD71828_MASK_RUN_EN,
381			.vsel_reg = BD71828_REG_BUCK5_VOLT,
382			.vsel_mask = BD71828_MASK_BUCK5_VOLT,
383			.owner = THIS_MODULE,
384			.of_parse_cb = buck_set_hw_dvs_levels,
385		},
386		.dvs = {
387			/*
388			 * BUCK5 only supports single voltage for all states.
389			 * voltage can be individually enabled for each state
390			 * though => allow setting all states to support
391			 * enabling power rail on different states.
392			 */
393			.level_map = ROHM_DVS_LEVEL_RUN | ROHM_DVS_LEVEL_IDLE |
394				     ROHM_DVS_LEVEL_SUSPEND |
395				     ROHM_DVS_LEVEL_LPSR,
396			.run_reg = BD71828_REG_BUCK5_VOLT,
397			.idle_reg = BD71828_REG_BUCK5_VOLT,
398			.suspend_reg = BD71828_REG_BUCK5_VOLT,
399			.lpsr_reg = BD71828_REG_BUCK5_VOLT,
400			.run_mask = BD71828_MASK_BUCK5_VOLT,
401			.idle_mask = BD71828_MASK_BUCK5_VOLT,
402			.suspend_mask = BD71828_MASK_BUCK5_VOLT,
403			.lpsr_mask = BD71828_MASK_BUCK5_VOLT,
404			.idle_on_mask = BD71828_MASK_IDLE_EN,
405			.suspend_on_mask = BD71828_MASK_SUSP_EN,
406			.lpsr_on_mask = BD71828_MASK_LPSR_EN,
407		},
408	},
409	{
410		.desc = {
411			.name = "buck6",
412			.of_match = of_match_ptr("BUCK6"),
413			.regulators_node = of_match_ptr("regulators"),
414			.id = BD71828_BUCK6,
415			.ops = &bd71828_dvs_buck_ops,
416			.type = REGULATOR_VOLTAGE,
417			.linear_ranges = bd71828_buck1267_volts,
418			.n_linear_ranges = ARRAY_SIZE(bd71828_buck1267_volts),
419			.n_voltages = BD71828_BUCK1267_VOLTS,
420			.enable_reg = BD71828_REG_BUCK6_EN,
421			.enable_mask = BD71828_MASK_RUN_EN,
422			.vsel_reg = BD71828_REG_BUCK6_VOLT,
423			.vsel_mask = BD71828_MASK_BUCK1267_VOLT,
 
 
 
 
424			.owner = THIS_MODULE,
425			.of_parse_cb = buck_set_hw_dvs_levels,
426		},
427		.dvs = {
428			.level_map = ROHM_DVS_LEVEL_RUN | ROHM_DVS_LEVEL_IDLE |
429				     ROHM_DVS_LEVEL_SUSPEND |
430				     ROHM_DVS_LEVEL_LPSR,
431			.run_reg = BD71828_REG_BUCK6_VOLT,
432			.run_mask = BD71828_MASK_BUCK1267_VOLT,
433			.idle_reg = BD71828_REG_BUCK6_IDLE_VOLT,
434			.idle_mask = BD71828_MASK_BUCK1267_VOLT,
435			.idle_on_mask = BD71828_MASK_IDLE_EN,
436			.suspend_reg = BD71828_REG_BUCK6_SUSP_VOLT,
437			.suspend_mask = BD71828_MASK_BUCK1267_VOLT,
438			.suspend_on_mask = BD71828_MASK_SUSP_EN,
439			.lpsr_on_mask = BD71828_MASK_LPSR_EN,
440			.lpsr_reg = BD71828_REG_BUCK6_SUSP_VOLT,
441			.lpsr_mask = BD71828_MASK_BUCK1267_VOLT,
442		},
443		.reg_inits = buck6_inits,
444		.reg_init_amnt = ARRAY_SIZE(buck6_inits),
445	},
446	{
447		.desc = {
448			.name = "buck7",
449			.of_match = of_match_ptr("BUCK7"),
450			.regulators_node = of_match_ptr("regulators"),
451			.id = BD71828_BUCK7,
452			.ops = &bd71828_dvs_buck_ops,
453			.type = REGULATOR_VOLTAGE,
454			.linear_ranges = bd71828_buck1267_volts,
455			.n_linear_ranges = ARRAY_SIZE(bd71828_buck1267_volts),
456			.n_voltages = BD71828_BUCK1267_VOLTS,
457			.enable_reg = BD71828_REG_BUCK7_EN,
458			.enable_mask = BD71828_MASK_RUN_EN,
459			.vsel_reg = BD71828_REG_BUCK7_VOLT,
460			.vsel_mask = BD71828_MASK_BUCK1267_VOLT,
 
 
 
 
461			.owner = THIS_MODULE,
462			.of_parse_cb = buck_set_hw_dvs_levels,
463		},
464		.dvs = {
465			.level_map = ROHM_DVS_LEVEL_RUN | ROHM_DVS_LEVEL_IDLE |
466				     ROHM_DVS_LEVEL_SUSPEND |
467				     ROHM_DVS_LEVEL_LPSR,
468			.run_reg = BD71828_REG_BUCK7_VOLT,
469			.run_mask = BD71828_MASK_BUCK1267_VOLT,
470			.idle_reg = BD71828_REG_BUCK7_IDLE_VOLT,
471			.idle_mask = BD71828_MASK_BUCK1267_VOLT,
472			.idle_on_mask = BD71828_MASK_IDLE_EN,
473			.suspend_reg = BD71828_REG_BUCK7_SUSP_VOLT,
474			.suspend_mask = BD71828_MASK_BUCK1267_VOLT,
475			.suspend_on_mask = BD71828_MASK_SUSP_EN,
476			.lpsr_on_mask = BD71828_MASK_LPSR_EN,
477			.lpsr_reg = BD71828_REG_BUCK7_SUSP_VOLT,
478			.lpsr_mask = BD71828_MASK_BUCK1267_VOLT,
479		},
480		.reg_inits = buck7_inits,
481		.reg_init_amnt = ARRAY_SIZE(buck7_inits),
482	},
483	{
484		.desc = {
485			.name = "ldo1",
486			.of_match = of_match_ptr("LDO1"),
487			.regulators_node = of_match_ptr("regulators"),
488			.id = BD71828_LDO1,
489			.ops = &bd71828_ldo_ops,
490			.type = REGULATOR_VOLTAGE,
491			.linear_ranges = bd71828_ldo_volts,
492			.n_linear_ranges = ARRAY_SIZE(bd71828_ldo_volts),
493			.n_voltages = BD71828_LDO_VOLTS,
494			.enable_reg = BD71828_REG_LDO1_EN,
495			.enable_mask = BD71828_MASK_RUN_EN,
496			.vsel_reg = BD71828_REG_LDO1_VOLT,
497			.vsel_mask = BD71828_MASK_LDO_VOLT,
498			.owner = THIS_MODULE,
499			.of_parse_cb = buck_set_hw_dvs_levels,
500		},
501		.dvs = {
502			/*
503			 * LDO1 only supports single voltage for all states.
504			 * voltage can be individually enabled for each state
505			 * though => allow setting all states to support
506			 * enabling power rail on different states.
507			 */
508			.level_map = ROHM_DVS_LEVEL_RUN | ROHM_DVS_LEVEL_IDLE |
509				     ROHM_DVS_LEVEL_SUSPEND |
510				     ROHM_DVS_LEVEL_LPSR,
511			.run_reg = BD71828_REG_LDO1_VOLT,
512			.idle_reg = BD71828_REG_LDO1_VOLT,
513			.suspend_reg = BD71828_REG_LDO1_VOLT,
514			.lpsr_reg = BD71828_REG_LDO1_VOLT,
515			.run_mask = BD71828_MASK_LDO_VOLT,
516			.idle_mask = BD71828_MASK_LDO_VOLT,
517			.suspend_mask = BD71828_MASK_LDO_VOLT,
518			.lpsr_mask = BD71828_MASK_LDO_VOLT,
519			.idle_on_mask = BD71828_MASK_IDLE_EN,
520			.suspend_on_mask = BD71828_MASK_SUSP_EN,
521			.lpsr_on_mask = BD71828_MASK_LPSR_EN,
522		},
523	}, {
524		.desc = {
525			.name = "ldo2",
526			.of_match = of_match_ptr("LDO2"),
527			.regulators_node = of_match_ptr("regulators"),
528			.id = BD71828_LDO2,
529			.ops = &bd71828_ldo_ops,
530			.type = REGULATOR_VOLTAGE,
531			.linear_ranges = bd71828_ldo_volts,
532			.n_linear_ranges = ARRAY_SIZE(bd71828_ldo_volts),
533			.n_voltages = BD71828_LDO_VOLTS,
534			.enable_reg = BD71828_REG_LDO2_EN,
535			.enable_mask = BD71828_MASK_RUN_EN,
536			.vsel_reg = BD71828_REG_LDO2_VOLT,
537			.vsel_mask = BD71828_MASK_LDO_VOLT,
538			.owner = THIS_MODULE,
539			.of_parse_cb = buck_set_hw_dvs_levels,
540		},
541		.dvs = {
542			/*
543			 * LDO2 only supports single voltage for all states.
544			 * voltage can be individually enabled for each state
545			 * though => allow setting all states to support
546			 * enabling power rail on different states.
547			 */
548			.level_map = ROHM_DVS_LEVEL_RUN | ROHM_DVS_LEVEL_IDLE |
549				     ROHM_DVS_LEVEL_SUSPEND |
550				     ROHM_DVS_LEVEL_LPSR,
551			.run_reg = BD71828_REG_LDO2_VOLT,
552			.idle_reg = BD71828_REG_LDO2_VOLT,
553			.suspend_reg = BD71828_REG_LDO2_VOLT,
554			.lpsr_reg = BD71828_REG_LDO2_VOLT,
555			.run_mask = BD71828_MASK_LDO_VOLT,
556			.idle_mask = BD71828_MASK_LDO_VOLT,
557			.suspend_mask = BD71828_MASK_LDO_VOLT,
558			.lpsr_mask = BD71828_MASK_LDO_VOLT,
559			.idle_on_mask = BD71828_MASK_IDLE_EN,
560			.suspend_on_mask = BD71828_MASK_SUSP_EN,
561			.lpsr_on_mask = BD71828_MASK_LPSR_EN,
562		},
563	}, {
564		.desc = {
565			.name = "ldo3",
566			.of_match = of_match_ptr("LDO3"),
567			.regulators_node = of_match_ptr("regulators"),
568			.id = BD71828_LDO3,
569			.ops = &bd71828_ldo_ops,
570			.type = REGULATOR_VOLTAGE,
571			.linear_ranges = bd71828_ldo_volts,
572			.n_linear_ranges = ARRAY_SIZE(bd71828_ldo_volts),
573			.n_voltages = BD71828_LDO_VOLTS,
574			.enable_reg = BD71828_REG_LDO3_EN,
575			.enable_mask = BD71828_MASK_RUN_EN,
576			.vsel_reg = BD71828_REG_LDO3_VOLT,
577			.vsel_mask = BD71828_MASK_LDO_VOLT,
578			.owner = THIS_MODULE,
579			.of_parse_cb = buck_set_hw_dvs_levels,
580		},
581		.dvs = {
582			/*
583			 * LDO3 only supports single voltage for all states.
584			 * voltage can be individually enabled for each state
585			 * though => allow setting all states to support
586			 * enabling power rail on different states.
587			 */
588			.level_map = ROHM_DVS_LEVEL_RUN | ROHM_DVS_LEVEL_IDLE |
589				     ROHM_DVS_LEVEL_SUSPEND |
590				     ROHM_DVS_LEVEL_LPSR,
591			.run_reg = BD71828_REG_LDO3_VOLT,
592			.idle_reg = BD71828_REG_LDO3_VOLT,
593			.suspend_reg = BD71828_REG_LDO3_VOLT,
594			.lpsr_reg = BD71828_REG_LDO3_VOLT,
595			.run_mask = BD71828_MASK_LDO_VOLT,
596			.idle_mask = BD71828_MASK_LDO_VOLT,
597			.suspend_mask = BD71828_MASK_LDO_VOLT,
598			.lpsr_mask = BD71828_MASK_LDO_VOLT,
599			.idle_on_mask = BD71828_MASK_IDLE_EN,
600			.suspend_on_mask = BD71828_MASK_SUSP_EN,
601			.lpsr_on_mask = BD71828_MASK_LPSR_EN,
602		},
603
604	}, {
605		.desc = {
606			.name = "ldo4",
607			.of_match = of_match_ptr("LDO4"),
608			.regulators_node = of_match_ptr("regulators"),
609			.id = BD71828_LDO4,
610			.ops = &bd71828_ldo_ops,
611			.type = REGULATOR_VOLTAGE,
612			.linear_ranges = bd71828_ldo_volts,
613			.n_linear_ranges = ARRAY_SIZE(bd71828_ldo_volts),
614			.n_voltages = BD71828_LDO_VOLTS,
615			.enable_reg = BD71828_REG_LDO4_EN,
616			.enable_mask = BD71828_MASK_RUN_EN,
617			.vsel_reg = BD71828_REG_LDO4_VOLT,
618			.vsel_mask = BD71828_MASK_LDO_VOLT,
619			.owner = THIS_MODULE,
620			.of_parse_cb = buck_set_hw_dvs_levels,
621		},
622		.dvs = {
623			/*
624			 * LDO1 only supports single voltage for all states.
625			 * voltage can be individually enabled for each state
626			 * though => allow setting all states to support
627			 * enabling power rail on different states.
628			 */
629			.level_map = ROHM_DVS_LEVEL_RUN | ROHM_DVS_LEVEL_IDLE |
630				     ROHM_DVS_LEVEL_SUSPEND |
631				     ROHM_DVS_LEVEL_LPSR,
632			.run_reg = BD71828_REG_LDO4_VOLT,
633			.idle_reg = BD71828_REG_LDO4_VOLT,
634			.suspend_reg = BD71828_REG_LDO4_VOLT,
635			.lpsr_reg = BD71828_REG_LDO4_VOLT,
636			.run_mask = BD71828_MASK_LDO_VOLT,
637			.idle_mask = BD71828_MASK_LDO_VOLT,
638			.suspend_mask = BD71828_MASK_LDO_VOLT,
639			.lpsr_mask = BD71828_MASK_LDO_VOLT,
640			.idle_on_mask = BD71828_MASK_IDLE_EN,
641			.suspend_on_mask = BD71828_MASK_SUSP_EN,
642			.lpsr_on_mask = BD71828_MASK_LPSR_EN,
643		},
644	}, {
645		.desc = {
646			.name = "ldo5",
647			.of_match = of_match_ptr("LDO5"),
648			.regulators_node = of_match_ptr("regulators"),
649			.id = BD71828_LDO5,
650			.ops = &bd71828_ldo_ops,
651			.type = REGULATOR_VOLTAGE,
652			.linear_ranges = bd71828_ldo_volts,
653			.n_linear_ranges = ARRAY_SIZE(bd71828_ldo_volts),
654			.n_voltages = BD71828_LDO_VOLTS,
655			.enable_reg = BD71828_REG_LDO5_EN,
656			.enable_mask = BD71828_MASK_RUN_EN,
657			.vsel_reg = BD71828_REG_LDO5_VOLT,
658			.vsel_mask = BD71828_MASK_LDO_VOLT,
659			.of_parse_cb = buck_set_hw_dvs_levels,
660			.owner = THIS_MODULE,
661		},
662		/*
663		 * LDO5 is special. It can choose vsel settings to be configured
664		 * from 2 different registers (by GPIO).
665		 *
666		 * This driver supports only configuration where
667		 * BD71828_REG_LDO5_VOLT_L is used.
668		 */
669		.dvs = {
670			.level_map = ROHM_DVS_LEVEL_RUN | ROHM_DVS_LEVEL_IDLE |
671				     ROHM_DVS_LEVEL_SUSPEND |
672				     ROHM_DVS_LEVEL_LPSR,
673			.run_reg = BD71828_REG_LDO5_VOLT,
674			.idle_reg = BD71828_REG_LDO5_VOLT,
675			.suspend_reg = BD71828_REG_LDO5_VOLT,
676			.lpsr_reg = BD71828_REG_LDO5_VOLT,
677			.run_mask = BD71828_MASK_LDO_VOLT,
678			.idle_mask = BD71828_MASK_LDO_VOLT,
679			.suspend_mask = BD71828_MASK_LDO_VOLT,
680			.lpsr_mask = BD71828_MASK_LDO_VOLT,
681			.idle_on_mask = BD71828_MASK_IDLE_EN,
682			.suspend_on_mask = BD71828_MASK_SUSP_EN,
683			.lpsr_on_mask = BD71828_MASK_LPSR_EN,
684		},
685
686	}, {
687		.desc = {
688			.name = "ldo6",
689			.of_match = of_match_ptr("LDO6"),
690			.regulators_node = of_match_ptr("regulators"),
691			.id = BD71828_LDO6,
692			.ops = &bd71828_ldo6_ops,
693			.type = REGULATOR_VOLTAGE,
694			.fixed_uV = BD71828_LDO_6_VOLTAGE,
695			.n_voltages = 1,
696			.enable_reg = BD71828_REG_LDO6_EN,
697			.enable_mask = BD71828_MASK_RUN_EN,
698			.owner = THIS_MODULE,
699			/*
700			 * LDO6 only supports enable/disable for all states.
701			 * Voltage for LDO6 is fixed.
702			 */
703			.of_parse_cb = ldo6_parse_dt,
704		},
705	}, {
706		.desc = {
707			/* SNVS LDO in data-sheet */
708			.name = "ldo7",
709			.of_match = of_match_ptr("LDO7"),
710			.regulators_node = of_match_ptr("regulators"),
711			.id = BD71828_LDO_SNVS,
712			.ops = &bd71828_ldo_ops,
713			.type = REGULATOR_VOLTAGE,
714			.linear_ranges = bd71828_ldo_volts,
715			.n_linear_ranges = ARRAY_SIZE(bd71828_ldo_volts),
716			.n_voltages = BD71828_LDO_VOLTS,
717			.enable_reg = BD71828_REG_LDO7_EN,
718			.enable_mask = BD71828_MASK_RUN_EN,
719			.vsel_reg = BD71828_REG_LDO7_VOLT,
720			.vsel_mask = BD71828_MASK_LDO_VOLT,
721			.owner = THIS_MODULE,
722			.of_parse_cb = buck_set_hw_dvs_levels,
723		},
724		.dvs = {
725			/*
726			 * LDO7 only supports single voltage for all states.
727			 * voltage can be individually enabled for each state
728			 * though => allow setting all states to support
729			 * enabling power rail on different states.
730			 */
731			.level_map = ROHM_DVS_LEVEL_RUN | ROHM_DVS_LEVEL_IDLE |
732				     ROHM_DVS_LEVEL_SUSPEND |
733				     ROHM_DVS_LEVEL_LPSR,
734			.run_reg = BD71828_REG_LDO7_VOLT,
735			.idle_reg = BD71828_REG_LDO7_VOLT,
736			.suspend_reg = BD71828_REG_LDO7_VOLT,
737			.lpsr_reg = BD71828_REG_LDO7_VOLT,
738			.run_mask = BD71828_MASK_LDO_VOLT,
739			.idle_mask = BD71828_MASK_LDO_VOLT,
740			.suspend_mask = BD71828_MASK_LDO_VOLT,
741			.lpsr_mask = BD71828_MASK_LDO_VOLT,
742			.idle_on_mask = BD71828_MASK_IDLE_EN,
743			.suspend_on_mask = BD71828_MASK_SUSP_EN,
744			.lpsr_on_mask = BD71828_MASK_LPSR_EN,
745		},
746
747	},
748};
749
750static int bd71828_probe(struct platform_device *pdev)
751{
752	struct rohm_regmap_dev *bd71828;
753	int i, j, ret;
754	struct regulator_config config = {
755		.dev = pdev->dev.parent,
756	};
757
758	bd71828 = dev_get_drvdata(pdev->dev.parent);
759	if (!bd71828) {
760		dev_err(&pdev->dev, "No MFD driver data\n");
761		return -EINVAL;
762	}
763
764	config.regmap = bd71828->regmap;
765
766	for (i = 0; i < ARRAY_SIZE(bd71828_rdata); i++) {
767		struct regulator_dev *rdev;
768		const struct bd71828_regulator_data *rd;
769
770		rd = &bd71828_rdata[i];
771		rdev = devm_regulator_register(&pdev->dev,
772					       &rd->desc, &config);
773		if (IS_ERR(rdev)) {
774			dev_err(&pdev->dev,
775				"failed to register %s regulator\n",
776				rd->desc.name);
777			return PTR_ERR(rdev);
778		}
779		for (j = 0; j < rd->reg_init_amnt; j++) {
780			ret = regmap_update_bits(bd71828->regmap,
781						 rd->reg_inits[j].reg,
782						 rd->reg_inits[j].mask,
783						 rd->reg_inits[j].val);
784			if (ret) {
785				dev_err(&pdev->dev,
786					"regulator %s init failed\n",
787					rd->desc.name);
788				return ret;
789			}
790		}
791	}
792	return 0;
793}
794
795static struct platform_driver bd71828_regulator = {
796	.driver = {
797		.name = "bd71828-pmic"
798	},
799	.probe = bd71828_probe,
800};
801
802module_platform_driver(bd71828_regulator);
803
804MODULE_AUTHOR("Matti Vaittinen <matti.vaittinen@fi.rohmeurope.com>");
805MODULE_DESCRIPTION("BD71828 voltage regulator driver");
806MODULE_LICENSE("GPL");
807MODULE_ALIAS("platform:bd71828-pmic");
v6.2
  1// SPDX-License-Identifier: GPL-2.0-only
  2// Copyright (C) 2019 ROHM Semiconductors
  3// bd71828-regulator.c ROHM BD71828GW-DS1 regulator driver
  4//
  5
  6#include <linux/delay.h>
  7#include <linux/err.h>
  8#include <linux/gpio.h>
  9#include <linux/interrupt.h>
 10#include <linux/kernel.h>
 11#include <linux/mfd/rohm-bd71828.h>
 12#include <linux/module.h>
 13#include <linux/of.h>
 14#include <linux/platform_device.h>
 15#include <linux/regmap.h>
 16#include <linux/regulator/driver.h>
 17#include <linux/regulator/machine.h>
 18#include <linux/regulator/of_regulator.h>
 19
 20struct reg_init {
 21	unsigned int reg;
 22	unsigned int mask;
 23	unsigned int val;
 24};
 25struct bd71828_regulator_data {
 26	struct regulator_desc desc;
 27	const struct rohm_dvs_config dvs;
 28	const struct reg_init *reg_inits;
 29	int reg_init_amnt;
 30};
 31
 32static const struct reg_init buck1_inits[] = {
 33	/*
 34	 * DVS Buck voltages can be changed by register values or via GPIO.
 35	 * Use register accesses by default.
 36	 */
 37	{
 38		.reg = BD71828_REG_PS_CTRL_1,
 39		.mask = BD71828_MASK_DVS_BUCK1_CTRL,
 40		.val = BD71828_DVS_BUCK1_CTRL_I2C,
 41	},
 42};
 43
 44static const struct reg_init buck2_inits[] = {
 45	{
 46		.reg = BD71828_REG_PS_CTRL_1,
 47		.mask = BD71828_MASK_DVS_BUCK2_CTRL,
 48		.val = BD71828_DVS_BUCK2_CTRL_I2C,
 49	},
 50};
 51
 52static const struct reg_init buck6_inits[] = {
 53	{
 54		.reg = BD71828_REG_PS_CTRL_1,
 55		.mask = BD71828_MASK_DVS_BUCK6_CTRL,
 56		.val = BD71828_DVS_BUCK6_CTRL_I2C,
 57	},
 58};
 59
 60static const struct reg_init buck7_inits[] = {
 61	{
 62		.reg = BD71828_REG_PS_CTRL_1,
 63		.mask = BD71828_MASK_DVS_BUCK7_CTRL,
 64		.val = BD71828_DVS_BUCK7_CTRL_I2C,
 65	},
 66};
 67
 68static const struct linear_range bd71828_buck1267_volts[] = {
 69	REGULATOR_LINEAR_RANGE(500000, 0x00, 0xef, 6250),
 70	REGULATOR_LINEAR_RANGE(2000000, 0xf0, 0xff, 0),
 71};
 72
 73static const struct linear_range bd71828_buck3_volts[] = {
 74	REGULATOR_LINEAR_RANGE(1200000, 0x00, 0x0f, 50000),
 75	REGULATOR_LINEAR_RANGE(2000000, 0x10, 0x1f, 0),
 76};
 77
 78static const struct linear_range bd71828_buck4_volts[] = {
 79	REGULATOR_LINEAR_RANGE(1000000, 0x00, 0x1f, 25000),
 80	REGULATOR_LINEAR_RANGE(1800000, 0x20, 0x3f, 0),
 81};
 82
 83static const struct linear_range bd71828_buck5_volts[] = {
 84	REGULATOR_LINEAR_RANGE(2500000, 0x00, 0x0f, 50000),
 85	REGULATOR_LINEAR_RANGE(3300000, 0x10, 0x1f, 0),
 86};
 87
 88static const struct linear_range bd71828_ldo_volts[] = {
 89	REGULATOR_LINEAR_RANGE(800000, 0x00, 0x31, 50000),
 90	REGULATOR_LINEAR_RANGE(3300000, 0x32, 0x3f, 0),
 91};
 92
 93static const unsigned int bd71828_ramp_delay[] = { 2500, 5000, 10000, 20000 };
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 94
 95static int buck_set_hw_dvs_levels(struct device_node *np,
 96				  const struct regulator_desc *desc,
 97				  struct regulator_config *cfg)
 98{
 99	struct bd71828_regulator_data *data;
100
101	data = container_of(desc, struct bd71828_regulator_data, desc);
102
103	return rohm_regulator_set_dvs_levels(&data->dvs, np, desc, cfg->regmap);
104}
105
106static int ldo6_parse_dt(struct device_node *np,
107			 const struct regulator_desc *desc,
108			 struct regulator_config *cfg)
109{
110	int ret, i;
111	uint32_t uv = 0;
112	unsigned int en;
113	struct regmap *regmap = cfg->regmap;
114	static const char * const props[] = { "rohm,dvs-run-voltage",
115					      "rohm,dvs-idle-voltage",
116					      "rohm,dvs-suspend-voltage",
117					      "rohm,dvs-lpsr-voltage" };
118	unsigned int mask[] = { BD71828_MASK_RUN_EN, BD71828_MASK_IDLE_EN,
119			       BD71828_MASK_SUSP_EN, BD71828_MASK_LPSR_EN };
120
121	for (i = 0; i < ARRAY_SIZE(props); i++) {
122		ret = of_property_read_u32(np, props[i], &uv);
123		if (ret) {
124			if (ret != -EINVAL)
125				return ret;
126			continue;
127		}
128		if (uv)
129			en = 0xffffffff;
130		else
131			en = 0;
132
133		ret = regmap_update_bits(regmap, desc->enable_reg, mask[i], en);
134		if (ret)
135			return ret;
136	}
137	return 0;
138}
139
140static const struct regulator_ops bd71828_buck_ops = {
141	.enable = regulator_enable_regmap,
142	.disable = regulator_disable_regmap,
143	.is_enabled = regulator_is_enabled_regmap,
144	.list_voltage = regulator_list_voltage_linear_range,
145	.set_voltage_sel = regulator_set_voltage_sel_regmap,
146	.get_voltage_sel = regulator_get_voltage_sel_regmap,
147};
148
149static const struct regulator_ops bd71828_dvs_buck_ops = {
150	.enable = regulator_enable_regmap,
151	.disable = regulator_disable_regmap,
152	.is_enabled = regulator_is_enabled_regmap,
153	.list_voltage = regulator_list_voltage_linear_range,
154	.set_voltage_sel = regulator_set_voltage_sel_regmap,
155	.get_voltage_sel = regulator_get_voltage_sel_regmap,
156	.set_voltage_time_sel = regulator_set_voltage_time_sel,
157	.set_ramp_delay = regulator_set_ramp_delay_regmap,
158};
159
160static const struct regulator_ops bd71828_ldo_ops = {
161	.enable = regulator_enable_regmap,
162	.disable = regulator_disable_regmap,
163	.is_enabled = regulator_is_enabled_regmap,
164	.list_voltage = regulator_list_voltage_linear_range,
165	.set_voltage_sel = regulator_set_voltage_sel_regmap,
166	.get_voltage_sel = regulator_get_voltage_sel_regmap,
167};
168
169static const struct regulator_ops bd71828_ldo6_ops = {
170	.enable = regulator_enable_regmap,
171	.disable = regulator_disable_regmap,
172	.is_enabled = regulator_is_enabled_regmap,
173};
174
175static const struct bd71828_regulator_data bd71828_rdata[] = {
176	{
177		.desc = {
178			.name = "buck1",
179			.of_match = of_match_ptr("BUCK1"),
180			.regulators_node = of_match_ptr("regulators"),
181			.id = BD71828_BUCK1,
182			.ops = &bd71828_dvs_buck_ops,
183			.type = REGULATOR_VOLTAGE,
184			.linear_ranges = bd71828_buck1267_volts,
185			.n_linear_ranges = ARRAY_SIZE(bd71828_buck1267_volts),
186			.n_voltages = BD71828_BUCK1267_VOLTS,
187			.enable_reg = BD71828_REG_BUCK1_EN,
188			.enable_mask = BD71828_MASK_RUN_EN,
189			.vsel_reg = BD71828_REG_BUCK1_VOLT,
190			.vsel_mask = BD71828_MASK_BUCK1267_VOLT,
191			.ramp_delay_table = bd71828_ramp_delay,
192			.n_ramp_values = ARRAY_SIZE(bd71828_ramp_delay),
193			.ramp_reg = BD71828_REG_BUCK1_MODE,
194			.ramp_mask = BD71828_MASK_RAMP_DELAY,
195			.owner = THIS_MODULE,
196			.of_parse_cb = buck_set_hw_dvs_levels,
197		},
198		.dvs = {
199			.level_map = ROHM_DVS_LEVEL_RUN | ROHM_DVS_LEVEL_IDLE |
200				     ROHM_DVS_LEVEL_SUSPEND |
201				     ROHM_DVS_LEVEL_LPSR,
202			.run_reg = BD71828_REG_BUCK1_VOLT,
203			.run_mask = BD71828_MASK_BUCK1267_VOLT,
204			.idle_reg = BD71828_REG_BUCK1_IDLE_VOLT,
205			.idle_mask = BD71828_MASK_BUCK1267_VOLT,
206			.idle_on_mask = BD71828_MASK_IDLE_EN,
207			.suspend_reg = BD71828_REG_BUCK1_SUSP_VOLT,
208			.suspend_mask = BD71828_MASK_BUCK1267_VOLT,
209			.suspend_on_mask = BD71828_MASK_SUSP_EN,
210			.lpsr_on_mask = BD71828_MASK_LPSR_EN,
211			/*
212			 * LPSR voltage is same as SUSPEND voltage. Allow
213			 * setting it so that regulator can be set enabled at
214			 * LPSR state
215			 */
216			.lpsr_reg = BD71828_REG_BUCK1_SUSP_VOLT,
217			.lpsr_mask = BD71828_MASK_BUCK1267_VOLT,
218		},
219		.reg_inits = buck1_inits,
220		.reg_init_amnt = ARRAY_SIZE(buck1_inits),
221	},
222	{
223		.desc = {
224			.name = "buck2",
225			.of_match = of_match_ptr("BUCK2"),
226			.regulators_node = of_match_ptr("regulators"),
227			.id = BD71828_BUCK2,
228			.ops = &bd71828_dvs_buck_ops,
229			.type = REGULATOR_VOLTAGE,
230			.linear_ranges = bd71828_buck1267_volts,
231			.n_linear_ranges = ARRAY_SIZE(bd71828_buck1267_volts),
232			.n_voltages = BD71828_BUCK1267_VOLTS,
233			.enable_reg = BD71828_REG_BUCK2_EN,
234			.enable_mask = BD71828_MASK_RUN_EN,
235			.vsel_reg = BD71828_REG_BUCK2_VOLT,
236			.vsel_mask = BD71828_MASK_BUCK1267_VOLT,
237			.ramp_delay_table = bd71828_ramp_delay,
238			.n_ramp_values = ARRAY_SIZE(bd71828_ramp_delay),
239			.ramp_reg = BD71828_REG_BUCK2_MODE,
240			.ramp_mask = BD71828_MASK_RAMP_DELAY,
241			.owner = THIS_MODULE,
242			.of_parse_cb = buck_set_hw_dvs_levels,
243		},
244		.dvs = {
245			.level_map = ROHM_DVS_LEVEL_RUN | ROHM_DVS_LEVEL_IDLE |
246				     ROHM_DVS_LEVEL_SUSPEND |
247				     ROHM_DVS_LEVEL_LPSR,
248			.run_reg = BD71828_REG_BUCK2_VOLT,
249			.run_mask = BD71828_MASK_BUCK1267_VOLT,
250			.idle_reg = BD71828_REG_BUCK2_IDLE_VOLT,
251			.idle_mask = BD71828_MASK_BUCK1267_VOLT,
252			.idle_on_mask = BD71828_MASK_IDLE_EN,
253			.suspend_reg = BD71828_REG_BUCK2_SUSP_VOLT,
254			.suspend_mask = BD71828_MASK_BUCK1267_VOLT,
255			.suspend_on_mask = BD71828_MASK_SUSP_EN,
256			.lpsr_on_mask = BD71828_MASK_LPSR_EN,
257			.lpsr_reg = BD71828_REG_BUCK2_SUSP_VOLT,
258			.lpsr_mask = BD71828_MASK_BUCK1267_VOLT,
259		},
260		.reg_inits = buck2_inits,
261		.reg_init_amnt = ARRAY_SIZE(buck2_inits),
262	},
263	{
264		.desc = {
265			.name = "buck3",
266			.of_match = of_match_ptr("BUCK3"),
267			.regulators_node = of_match_ptr("regulators"),
268			.id = BD71828_BUCK3,
269			.ops = &bd71828_buck_ops,
270			.type = REGULATOR_VOLTAGE,
271			.linear_ranges = bd71828_buck3_volts,
272			.n_linear_ranges = ARRAY_SIZE(bd71828_buck3_volts),
273			.n_voltages = BD71828_BUCK3_VOLTS,
274			.enable_reg = BD71828_REG_BUCK3_EN,
275			.enable_mask = BD71828_MASK_RUN_EN,
276			.vsel_reg = BD71828_REG_BUCK3_VOLT,
277			.vsel_mask = BD71828_MASK_BUCK3_VOLT,
278			.owner = THIS_MODULE,
279			.of_parse_cb = buck_set_hw_dvs_levels,
280		},
281		.dvs = {
282			/*
283			 * BUCK3 only supports single voltage for all states.
284			 * voltage can be individually enabled for each state
285			 * though => allow setting all states to support
286			 * enabling power rail on different states.
287			 */
288			.level_map = ROHM_DVS_LEVEL_RUN | ROHM_DVS_LEVEL_IDLE |
289				     ROHM_DVS_LEVEL_SUSPEND |
290				     ROHM_DVS_LEVEL_LPSR,
291			.run_reg = BD71828_REG_BUCK3_VOLT,
292			.idle_reg = BD71828_REG_BUCK3_VOLT,
293			.suspend_reg = BD71828_REG_BUCK3_VOLT,
294			.lpsr_reg = BD71828_REG_BUCK3_VOLT,
295			.run_mask = BD71828_MASK_BUCK3_VOLT,
296			.idle_mask = BD71828_MASK_BUCK3_VOLT,
297			.suspend_mask = BD71828_MASK_BUCK3_VOLT,
298			.lpsr_mask = BD71828_MASK_BUCK3_VOLT,
299			.idle_on_mask = BD71828_MASK_IDLE_EN,
300			.suspend_on_mask = BD71828_MASK_SUSP_EN,
301			.lpsr_on_mask = BD71828_MASK_LPSR_EN,
302		},
303	},
304	{
305		.desc = {
306			.name = "buck4",
307			.of_match = of_match_ptr("BUCK4"),
308			.regulators_node = of_match_ptr("regulators"),
309			.id = BD71828_BUCK4,
310			.ops = &bd71828_buck_ops,
311			.type = REGULATOR_VOLTAGE,
312			.linear_ranges = bd71828_buck4_volts,
313			.n_linear_ranges = ARRAY_SIZE(bd71828_buck4_volts),
314			.n_voltages = BD71828_BUCK4_VOLTS,
315			.enable_reg = BD71828_REG_BUCK4_EN,
316			.enable_mask = BD71828_MASK_RUN_EN,
317			.vsel_reg = BD71828_REG_BUCK4_VOLT,
318			.vsel_mask = BD71828_MASK_BUCK4_VOLT,
319			.owner = THIS_MODULE,
320			.of_parse_cb = buck_set_hw_dvs_levels,
321		},
322		.dvs = {
323			/*
324			 * BUCK4 only supports single voltage for all states.
325			 * voltage can be individually enabled for each state
326			 * though => allow setting all states to support
327			 * enabling power rail on different states.
328			 */
329			.level_map = ROHM_DVS_LEVEL_RUN | ROHM_DVS_LEVEL_IDLE |
330				     ROHM_DVS_LEVEL_SUSPEND |
331				     ROHM_DVS_LEVEL_LPSR,
332			.run_reg = BD71828_REG_BUCK4_VOLT,
333			.idle_reg = BD71828_REG_BUCK4_VOLT,
334			.suspend_reg = BD71828_REG_BUCK4_VOLT,
335			.lpsr_reg = BD71828_REG_BUCK4_VOLT,
336			.run_mask = BD71828_MASK_BUCK4_VOLT,
337			.idle_mask = BD71828_MASK_BUCK4_VOLT,
338			.suspend_mask = BD71828_MASK_BUCK4_VOLT,
339			.lpsr_mask = BD71828_MASK_BUCK4_VOLT,
340			.idle_on_mask = BD71828_MASK_IDLE_EN,
341			.suspend_on_mask = BD71828_MASK_SUSP_EN,
342			.lpsr_on_mask = BD71828_MASK_LPSR_EN,
343		},
344	},
345	{
346		.desc = {
347			.name = "buck5",
348			.of_match = of_match_ptr("BUCK5"),
349			.regulators_node = of_match_ptr("regulators"),
350			.id = BD71828_BUCK5,
351			.ops = &bd71828_buck_ops,
352			.type = REGULATOR_VOLTAGE,
353			.linear_ranges = bd71828_buck5_volts,
354			.n_linear_ranges = ARRAY_SIZE(bd71828_buck5_volts),
355			.n_voltages = BD71828_BUCK5_VOLTS,
356			.enable_reg = BD71828_REG_BUCK5_EN,
357			.enable_mask = BD71828_MASK_RUN_EN,
358			.vsel_reg = BD71828_REG_BUCK5_VOLT,
359			.vsel_mask = BD71828_MASK_BUCK5_VOLT,
360			.owner = THIS_MODULE,
361			.of_parse_cb = buck_set_hw_dvs_levels,
362		},
363		.dvs = {
364			/*
365			 * BUCK5 only supports single voltage for all states.
366			 * voltage can be individually enabled for each state
367			 * though => allow setting all states to support
368			 * enabling power rail on different states.
369			 */
370			.level_map = ROHM_DVS_LEVEL_RUN | ROHM_DVS_LEVEL_IDLE |
371				     ROHM_DVS_LEVEL_SUSPEND |
372				     ROHM_DVS_LEVEL_LPSR,
373			.run_reg = BD71828_REG_BUCK5_VOLT,
374			.idle_reg = BD71828_REG_BUCK5_VOLT,
375			.suspend_reg = BD71828_REG_BUCK5_VOLT,
376			.lpsr_reg = BD71828_REG_BUCK5_VOLT,
377			.run_mask = BD71828_MASK_BUCK5_VOLT,
378			.idle_mask = BD71828_MASK_BUCK5_VOLT,
379			.suspend_mask = BD71828_MASK_BUCK5_VOLT,
380			.lpsr_mask = BD71828_MASK_BUCK5_VOLT,
381			.idle_on_mask = BD71828_MASK_IDLE_EN,
382			.suspend_on_mask = BD71828_MASK_SUSP_EN,
383			.lpsr_on_mask = BD71828_MASK_LPSR_EN,
384		},
385	},
386	{
387		.desc = {
388			.name = "buck6",
389			.of_match = of_match_ptr("BUCK6"),
390			.regulators_node = of_match_ptr("regulators"),
391			.id = BD71828_BUCK6,
392			.ops = &bd71828_dvs_buck_ops,
393			.type = REGULATOR_VOLTAGE,
394			.linear_ranges = bd71828_buck1267_volts,
395			.n_linear_ranges = ARRAY_SIZE(bd71828_buck1267_volts),
396			.n_voltages = BD71828_BUCK1267_VOLTS,
397			.enable_reg = BD71828_REG_BUCK6_EN,
398			.enable_mask = BD71828_MASK_RUN_EN,
399			.vsel_reg = BD71828_REG_BUCK6_VOLT,
400			.vsel_mask = BD71828_MASK_BUCK1267_VOLT,
401			.ramp_delay_table = bd71828_ramp_delay,
402			.n_ramp_values = ARRAY_SIZE(bd71828_ramp_delay),
403			.ramp_reg = BD71828_REG_BUCK6_MODE,
404			.ramp_mask = BD71828_MASK_RAMP_DELAY,
405			.owner = THIS_MODULE,
406			.of_parse_cb = buck_set_hw_dvs_levels,
407		},
408		.dvs = {
409			.level_map = ROHM_DVS_LEVEL_RUN | ROHM_DVS_LEVEL_IDLE |
410				     ROHM_DVS_LEVEL_SUSPEND |
411				     ROHM_DVS_LEVEL_LPSR,
412			.run_reg = BD71828_REG_BUCK6_VOLT,
413			.run_mask = BD71828_MASK_BUCK1267_VOLT,
414			.idle_reg = BD71828_REG_BUCK6_IDLE_VOLT,
415			.idle_mask = BD71828_MASK_BUCK1267_VOLT,
416			.idle_on_mask = BD71828_MASK_IDLE_EN,
417			.suspend_reg = BD71828_REG_BUCK6_SUSP_VOLT,
418			.suspend_mask = BD71828_MASK_BUCK1267_VOLT,
419			.suspend_on_mask = BD71828_MASK_SUSP_EN,
420			.lpsr_on_mask = BD71828_MASK_LPSR_EN,
421			.lpsr_reg = BD71828_REG_BUCK6_SUSP_VOLT,
422			.lpsr_mask = BD71828_MASK_BUCK1267_VOLT,
423		},
424		.reg_inits = buck6_inits,
425		.reg_init_amnt = ARRAY_SIZE(buck6_inits),
426	},
427	{
428		.desc = {
429			.name = "buck7",
430			.of_match = of_match_ptr("BUCK7"),
431			.regulators_node = of_match_ptr("regulators"),
432			.id = BD71828_BUCK7,
433			.ops = &bd71828_dvs_buck_ops,
434			.type = REGULATOR_VOLTAGE,
435			.linear_ranges = bd71828_buck1267_volts,
436			.n_linear_ranges = ARRAY_SIZE(bd71828_buck1267_volts),
437			.n_voltages = BD71828_BUCK1267_VOLTS,
438			.enable_reg = BD71828_REG_BUCK7_EN,
439			.enable_mask = BD71828_MASK_RUN_EN,
440			.vsel_reg = BD71828_REG_BUCK7_VOLT,
441			.vsel_mask = BD71828_MASK_BUCK1267_VOLT,
442			.ramp_delay_table = bd71828_ramp_delay,
443			.n_ramp_values = ARRAY_SIZE(bd71828_ramp_delay),
444			.ramp_reg = BD71828_REG_BUCK7_MODE,
445			.ramp_mask = BD71828_MASK_RAMP_DELAY,
446			.owner = THIS_MODULE,
447			.of_parse_cb = buck_set_hw_dvs_levels,
448		},
449		.dvs = {
450			.level_map = ROHM_DVS_LEVEL_RUN | ROHM_DVS_LEVEL_IDLE |
451				     ROHM_DVS_LEVEL_SUSPEND |
452				     ROHM_DVS_LEVEL_LPSR,
453			.run_reg = BD71828_REG_BUCK7_VOLT,
454			.run_mask = BD71828_MASK_BUCK1267_VOLT,
455			.idle_reg = BD71828_REG_BUCK7_IDLE_VOLT,
456			.idle_mask = BD71828_MASK_BUCK1267_VOLT,
457			.idle_on_mask = BD71828_MASK_IDLE_EN,
458			.suspend_reg = BD71828_REG_BUCK7_SUSP_VOLT,
459			.suspend_mask = BD71828_MASK_BUCK1267_VOLT,
460			.suspend_on_mask = BD71828_MASK_SUSP_EN,
461			.lpsr_on_mask = BD71828_MASK_LPSR_EN,
462			.lpsr_reg = BD71828_REG_BUCK7_SUSP_VOLT,
463			.lpsr_mask = BD71828_MASK_BUCK1267_VOLT,
464		},
465		.reg_inits = buck7_inits,
466		.reg_init_amnt = ARRAY_SIZE(buck7_inits),
467	},
468	{
469		.desc = {
470			.name = "ldo1",
471			.of_match = of_match_ptr("LDO1"),
472			.regulators_node = of_match_ptr("regulators"),
473			.id = BD71828_LDO1,
474			.ops = &bd71828_ldo_ops,
475			.type = REGULATOR_VOLTAGE,
476			.linear_ranges = bd71828_ldo_volts,
477			.n_linear_ranges = ARRAY_SIZE(bd71828_ldo_volts),
478			.n_voltages = BD71828_LDO_VOLTS,
479			.enable_reg = BD71828_REG_LDO1_EN,
480			.enable_mask = BD71828_MASK_RUN_EN,
481			.vsel_reg = BD71828_REG_LDO1_VOLT,
482			.vsel_mask = BD71828_MASK_LDO_VOLT,
483			.owner = THIS_MODULE,
484			.of_parse_cb = buck_set_hw_dvs_levels,
485		},
486		.dvs = {
487			/*
488			 * LDO1 only supports single voltage for all states.
489			 * voltage can be individually enabled for each state
490			 * though => allow setting all states to support
491			 * enabling power rail on different states.
492			 */
493			.level_map = ROHM_DVS_LEVEL_RUN | ROHM_DVS_LEVEL_IDLE |
494				     ROHM_DVS_LEVEL_SUSPEND |
495				     ROHM_DVS_LEVEL_LPSR,
496			.run_reg = BD71828_REG_LDO1_VOLT,
497			.idle_reg = BD71828_REG_LDO1_VOLT,
498			.suspend_reg = BD71828_REG_LDO1_VOLT,
499			.lpsr_reg = BD71828_REG_LDO1_VOLT,
500			.run_mask = BD71828_MASK_LDO_VOLT,
501			.idle_mask = BD71828_MASK_LDO_VOLT,
502			.suspend_mask = BD71828_MASK_LDO_VOLT,
503			.lpsr_mask = BD71828_MASK_LDO_VOLT,
504			.idle_on_mask = BD71828_MASK_IDLE_EN,
505			.suspend_on_mask = BD71828_MASK_SUSP_EN,
506			.lpsr_on_mask = BD71828_MASK_LPSR_EN,
507		},
508	}, {
509		.desc = {
510			.name = "ldo2",
511			.of_match = of_match_ptr("LDO2"),
512			.regulators_node = of_match_ptr("regulators"),
513			.id = BD71828_LDO2,
514			.ops = &bd71828_ldo_ops,
515			.type = REGULATOR_VOLTAGE,
516			.linear_ranges = bd71828_ldo_volts,
517			.n_linear_ranges = ARRAY_SIZE(bd71828_ldo_volts),
518			.n_voltages = BD71828_LDO_VOLTS,
519			.enable_reg = BD71828_REG_LDO2_EN,
520			.enable_mask = BD71828_MASK_RUN_EN,
521			.vsel_reg = BD71828_REG_LDO2_VOLT,
522			.vsel_mask = BD71828_MASK_LDO_VOLT,
523			.owner = THIS_MODULE,
524			.of_parse_cb = buck_set_hw_dvs_levels,
525		},
526		.dvs = {
527			/*
528			 * LDO2 only supports single voltage for all states.
529			 * voltage can be individually enabled for each state
530			 * though => allow setting all states to support
531			 * enabling power rail on different states.
532			 */
533			.level_map = ROHM_DVS_LEVEL_RUN | ROHM_DVS_LEVEL_IDLE |
534				     ROHM_DVS_LEVEL_SUSPEND |
535				     ROHM_DVS_LEVEL_LPSR,
536			.run_reg = BD71828_REG_LDO2_VOLT,
537			.idle_reg = BD71828_REG_LDO2_VOLT,
538			.suspend_reg = BD71828_REG_LDO2_VOLT,
539			.lpsr_reg = BD71828_REG_LDO2_VOLT,
540			.run_mask = BD71828_MASK_LDO_VOLT,
541			.idle_mask = BD71828_MASK_LDO_VOLT,
542			.suspend_mask = BD71828_MASK_LDO_VOLT,
543			.lpsr_mask = BD71828_MASK_LDO_VOLT,
544			.idle_on_mask = BD71828_MASK_IDLE_EN,
545			.suspend_on_mask = BD71828_MASK_SUSP_EN,
546			.lpsr_on_mask = BD71828_MASK_LPSR_EN,
547		},
548	}, {
549		.desc = {
550			.name = "ldo3",
551			.of_match = of_match_ptr("LDO3"),
552			.regulators_node = of_match_ptr("regulators"),
553			.id = BD71828_LDO3,
554			.ops = &bd71828_ldo_ops,
555			.type = REGULATOR_VOLTAGE,
556			.linear_ranges = bd71828_ldo_volts,
557			.n_linear_ranges = ARRAY_SIZE(bd71828_ldo_volts),
558			.n_voltages = BD71828_LDO_VOLTS,
559			.enable_reg = BD71828_REG_LDO3_EN,
560			.enable_mask = BD71828_MASK_RUN_EN,
561			.vsel_reg = BD71828_REG_LDO3_VOLT,
562			.vsel_mask = BD71828_MASK_LDO_VOLT,
563			.owner = THIS_MODULE,
564			.of_parse_cb = buck_set_hw_dvs_levels,
565		},
566		.dvs = {
567			/*
568			 * LDO3 only supports single voltage for all states.
569			 * voltage can be individually enabled for each state
570			 * though => allow setting all states to support
571			 * enabling power rail on different states.
572			 */
573			.level_map = ROHM_DVS_LEVEL_RUN | ROHM_DVS_LEVEL_IDLE |
574				     ROHM_DVS_LEVEL_SUSPEND |
575				     ROHM_DVS_LEVEL_LPSR,
576			.run_reg = BD71828_REG_LDO3_VOLT,
577			.idle_reg = BD71828_REG_LDO3_VOLT,
578			.suspend_reg = BD71828_REG_LDO3_VOLT,
579			.lpsr_reg = BD71828_REG_LDO3_VOLT,
580			.run_mask = BD71828_MASK_LDO_VOLT,
581			.idle_mask = BD71828_MASK_LDO_VOLT,
582			.suspend_mask = BD71828_MASK_LDO_VOLT,
583			.lpsr_mask = BD71828_MASK_LDO_VOLT,
584			.idle_on_mask = BD71828_MASK_IDLE_EN,
585			.suspend_on_mask = BD71828_MASK_SUSP_EN,
586			.lpsr_on_mask = BD71828_MASK_LPSR_EN,
587		},
588
589	}, {
590		.desc = {
591			.name = "ldo4",
592			.of_match = of_match_ptr("LDO4"),
593			.regulators_node = of_match_ptr("regulators"),
594			.id = BD71828_LDO4,
595			.ops = &bd71828_ldo_ops,
596			.type = REGULATOR_VOLTAGE,
597			.linear_ranges = bd71828_ldo_volts,
598			.n_linear_ranges = ARRAY_SIZE(bd71828_ldo_volts),
599			.n_voltages = BD71828_LDO_VOLTS,
600			.enable_reg = BD71828_REG_LDO4_EN,
601			.enable_mask = BD71828_MASK_RUN_EN,
602			.vsel_reg = BD71828_REG_LDO4_VOLT,
603			.vsel_mask = BD71828_MASK_LDO_VOLT,
604			.owner = THIS_MODULE,
605			.of_parse_cb = buck_set_hw_dvs_levels,
606		},
607		.dvs = {
608			/*
609			 * LDO1 only supports single voltage for all states.
610			 * voltage can be individually enabled for each state
611			 * though => allow setting all states to support
612			 * enabling power rail on different states.
613			 */
614			.level_map = ROHM_DVS_LEVEL_RUN | ROHM_DVS_LEVEL_IDLE |
615				     ROHM_DVS_LEVEL_SUSPEND |
616				     ROHM_DVS_LEVEL_LPSR,
617			.run_reg = BD71828_REG_LDO4_VOLT,
618			.idle_reg = BD71828_REG_LDO4_VOLT,
619			.suspend_reg = BD71828_REG_LDO4_VOLT,
620			.lpsr_reg = BD71828_REG_LDO4_VOLT,
621			.run_mask = BD71828_MASK_LDO_VOLT,
622			.idle_mask = BD71828_MASK_LDO_VOLT,
623			.suspend_mask = BD71828_MASK_LDO_VOLT,
624			.lpsr_mask = BD71828_MASK_LDO_VOLT,
625			.idle_on_mask = BD71828_MASK_IDLE_EN,
626			.suspend_on_mask = BD71828_MASK_SUSP_EN,
627			.lpsr_on_mask = BD71828_MASK_LPSR_EN,
628		},
629	}, {
630		.desc = {
631			.name = "ldo5",
632			.of_match = of_match_ptr("LDO5"),
633			.regulators_node = of_match_ptr("regulators"),
634			.id = BD71828_LDO5,
635			.ops = &bd71828_ldo_ops,
636			.type = REGULATOR_VOLTAGE,
637			.linear_ranges = bd71828_ldo_volts,
638			.n_linear_ranges = ARRAY_SIZE(bd71828_ldo_volts),
639			.n_voltages = BD71828_LDO_VOLTS,
640			.enable_reg = BD71828_REG_LDO5_EN,
641			.enable_mask = BD71828_MASK_RUN_EN,
642			.vsel_reg = BD71828_REG_LDO5_VOLT,
643			.vsel_mask = BD71828_MASK_LDO_VOLT,
644			.of_parse_cb = buck_set_hw_dvs_levels,
645			.owner = THIS_MODULE,
646		},
647		/*
648		 * LDO5 is special. It can choose vsel settings to be configured
649		 * from 2 different registers (by GPIO).
650		 *
651		 * This driver supports only configuration where
652		 * BD71828_REG_LDO5_VOLT_L is used.
653		 */
654		.dvs = {
655			.level_map = ROHM_DVS_LEVEL_RUN | ROHM_DVS_LEVEL_IDLE |
656				     ROHM_DVS_LEVEL_SUSPEND |
657				     ROHM_DVS_LEVEL_LPSR,
658			.run_reg = BD71828_REG_LDO5_VOLT,
659			.idle_reg = BD71828_REG_LDO5_VOLT,
660			.suspend_reg = BD71828_REG_LDO5_VOLT,
661			.lpsr_reg = BD71828_REG_LDO5_VOLT,
662			.run_mask = BD71828_MASK_LDO_VOLT,
663			.idle_mask = BD71828_MASK_LDO_VOLT,
664			.suspend_mask = BD71828_MASK_LDO_VOLT,
665			.lpsr_mask = BD71828_MASK_LDO_VOLT,
666			.idle_on_mask = BD71828_MASK_IDLE_EN,
667			.suspend_on_mask = BD71828_MASK_SUSP_EN,
668			.lpsr_on_mask = BD71828_MASK_LPSR_EN,
669		},
670
671	}, {
672		.desc = {
673			.name = "ldo6",
674			.of_match = of_match_ptr("LDO6"),
675			.regulators_node = of_match_ptr("regulators"),
676			.id = BD71828_LDO6,
677			.ops = &bd71828_ldo6_ops,
678			.type = REGULATOR_VOLTAGE,
679			.fixed_uV = BD71828_LDO_6_VOLTAGE,
680			.n_voltages = 1,
681			.enable_reg = BD71828_REG_LDO6_EN,
682			.enable_mask = BD71828_MASK_RUN_EN,
683			.owner = THIS_MODULE,
684			/*
685			 * LDO6 only supports enable/disable for all states.
686			 * Voltage for LDO6 is fixed.
687			 */
688			.of_parse_cb = ldo6_parse_dt,
689		},
690	}, {
691		.desc = {
692			/* SNVS LDO in data-sheet */
693			.name = "ldo7",
694			.of_match = of_match_ptr("LDO7"),
695			.regulators_node = of_match_ptr("regulators"),
696			.id = BD71828_LDO_SNVS,
697			.ops = &bd71828_ldo_ops,
698			.type = REGULATOR_VOLTAGE,
699			.linear_ranges = bd71828_ldo_volts,
700			.n_linear_ranges = ARRAY_SIZE(bd71828_ldo_volts),
701			.n_voltages = BD71828_LDO_VOLTS,
702			.enable_reg = BD71828_REG_LDO7_EN,
703			.enable_mask = BD71828_MASK_RUN_EN,
704			.vsel_reg = BD71828_REG_LDO7_VOLT,
705			.vsel_mask = BD71828_MASK_LDO_VOLT,
706			.owner = THIS_MODULE,
707			.of_parse_cb = buck_set_hw_dvs_levels,
708		},
709		.dvs = {
710			/*
711			 * LDO7 only supports single voltage for all states.
712			 * voltage can be individually enabled for each state
713			 * though => allow setting all states to support
714			 * enabling power rail on different states.
715			 */
716			.level_map = ROHM_DVS_LEVEL_RUN | ROHM_DVS_LEVEL_IDLE |
717				     ROHM_DVS_LEVEL_SUSPEND |
718				     ROHM_DVS_LEVEL_LPSR,
719			.run_reg = BD71828_REG_LDO7_VOLT,
720			.idle_reg = BD71828_REG_LDO7_VOLT,
721			.suspend_reg = BD71828_REG_LDO7_VOLT,
722			.lpsr_reg = BD71828_REG_LDO7_VOLT,
723			.run_mask = BD71828_MASK_LDO_VOLT,
724			.idle_mask = BD71828_MASK_LDO_VOLT,
725			.suspend_mask = BD71828_MASK_LDO_VOLT,
726			.lpsr_mask = BD71828_MASK_LDO_VOLT,
727			.idle_on_mask = BD71828_MASK_IDLE_EN,
728			.suspend_on_mask = BD71828_MASK_SUSP_EN,
729			.lpsr_on_mask = BD71828_MASK_LPSR_EN,
730		},
731
732	},
733};
734
735static int bd71828_probe(struct platform_device *pdev)
736{
 
737	int i, j, ret;
738	struct regulator_config config = {
739		.dev = pdev->dev.parent,
740	};
741
742	config.regmap = dev_get_regmap(pdev->dev.parent, NULL);
743	if (!config.regmap)
744		return -ENODEV;
 
 
 
 
745
746	for (i = 0; i < ARRAY_SIZE(bd71828_rdata); i++) {
747		struct regulator_dev *rdev;
748		const struct bd71828_regulator_data *rd;
749
750		rd = &bd71828_rdata[i];
751		rdev = devm_regulator_register(&pdev->dev,
752					       &rd->desc, &config);
753		if (IS_ERR(rdev))
754			return dev_err_probe(&pdev->dev, PTR_ERR(rdev),
755					     "failed to register %s regulator\n",
756					     rd->desc.name);
757
 
758		for (j = 0; j < rd->reg_init_amnt; j++) {
759			ret = regmap_update_bits(config.regmap,
760						 rd->reg_inits[j].reg,
761						 rd->reg_inits[j].mask,
762						 rd->reg_inits[j].val);
763			if (ret)
764				return dev_err_probe(&pdev->dev, ret,
765						     "regulator %s init failed\n",
766						     rd->desc.name);
 
 
767		}
768	}
769	return 0;
770}
771
772static struct platform_driver bd71828_regulator = {
773	.driver = {
774		.name = "bd71828-pmic"
775	},
776	.probe = bd71828_probe,
777};
778
779module_platform_driver(bd71828_regulator);
780
781MODULE_AUTHOR("Matti Vaittinen <matti.vaittinen@fi.rohmeurope.com>");
782MODULE_DESCRIPTION("BD71828 voltage regulator driver");
783MODULE_LICENSE("GPL");
784MODULE_ALIAS("platform:bd71828-pmic");