Blame view

drivers/regulator/bd718x7-regulator.c 46.7 KB
ba08799e9   Matti Vaittinen   regulator: bd7183...
1
2
  // SPDX-License-Identifier: GPL-2.0
  // Copyright (C) 2018 ROHM Semiconductors
dd2be639f   Matti Vaittinen   regulator/mfd: bd...
3
  // bd71837-regulator.c ROHM BD71837MWV/BD71847MWV regulator driver
ba08799e9   Matti Vaittinen   regulator: bd7183...
4

c9dc4cfa1   Matti Vaittinen   regulator: bd7183...
5
  #include <linux/delay.h>
ba08799e9   Matti Vaittinen   regulator: bd7183...
6
7
  #include <linux/err.h>
  #include <linux/interrupt.h>
c9dc4cfa1   Matti Vaittinen   regulator: bd7183...
8
  #include <linux/kernel.h>
410e8b4f5   Matti Vaittinen   regulator: bd7183...
9
  #include <linux/mfd/rohm-bd718x7.h>
c9dc4cfa1   Matti Vaittinen   regulator: bd7183...
10
  #include <linux/module.h>
9cce72448   Matti Vaittinen   regulator: bd718x...
11
  #include <linux/of.h>
ba08799e9   Matti Vaittinen   regulator: bd7183...
12
13
14
  #include <linux/platform_device.h>
  #include <linux/regulator/driver.h>
  #include <linux/regulator/machine.h>
ba08799e9   Matti Vaittinen   regulator: bd7183...
15
  #include <linux/regulator/of_regulator.h>
c9dc4cfa1   Matti Vaittinen   regulator: bd7183...
16
  #include <linux/slab.h>
ba08799e9   Matti Vaittinen   regulator: bd7183...
17

36afeaad7   Guido Günther   regulator: bd718x...
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
  /* Typical regulator startup times as per data sheet in uS */
  #define BD71847_BUCK1_STARTUP_TIME 144
  #define BD71847_BUCK2_STARTUP_TIME 162
  #define BD71847_BUCK3_STARTUP_TIME 162
  #define BD71847_BUCK4_STARTUP_TIME 240
  #define BD71847_BUCK5_STARTUP_TIME 270
  #define BD71847_BUCK6_STARTUP_TIME 200
  #define BD71847_LDO1_STARTUP_TIME  440
  #define BD71847_LDO2_STARTUP_TIME  370
  #define BD71847_LDO3_STARTUP_TIME  310
  #define BD71847_LDO4_STARTUP_TIME  400
  #define BD71847_LDO5_STARTUP_TIME  530
  #define BD71847_LDO6_STARTUP_TIME  400
  
  #define BD71837_BUCK1_STARTUP_TIME 160
  #define BD71837_BUCK2_STARTUP_TIME 180
  #define BD71837_BUCK3_STARTUP_TIME 180
  #define BD71837_BUCK4_STARTUP_TIME 180
  #define BD71837_BUCK5_STARTUP_TIME 160
  #define BD71837_BUCK6_STARTUP_TIME 240
  #define BD71837_BUCK7_STARTUP_TIME 220
  #define BD71837_BUCK8_STARTUP_TIME 200
  #define BD71837_LDO1_STARTUP_TIME  440
  #define BD71837_LDO2_STARTUP_TIME  370
  #define BD71837_LDO3_STARTUP_TIME  310
  #define BD71837_LDO4_STARTUP_TIME  400
  #define BD71837_LDO5_STARTUP_TIME  310
  #define BD71837_LDO6_STARTUP_TIME  400
  #define BD71837_LDO7_STARTUP_TIME  530
ba08799e9   Matti Vaittinen   regulator: bd7183...
47
  /*
1d848d681   Matti Vaittinen   regulator: bd718x...
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
   * BD718(37/47/50) have two "enable control modes". ON/OFF can either be
   * controlled by software - or by PMIC internal HW state machine. Whether
   * regulator should be under SW or HW control can be defined from device-tree.
   * Let's provide separate ops for regulators to use depending on the "enable
   * control mode".
   */
  #define BD718XX_HWOPNAME(swopname) swopname##_hwcontrol
  
  #define BD718XX_OPS(name, _list_voltage, _map_voltage, _set_voltage_sel, \
  		   _get_voltage_sel, _set_voltage_time_sel, _set_ramp_delay) \
  static const struct regulator_ops name = {			\
  	.enable = regulator_enable_regmap,			\
  	.disable = regulator_disable_regmap,			\
  	.is_enabled = regulator_is_enabled_regmap,		\
  	.list_voltage = (_list_voltage),			\
  	.map_voltage = (_map_voltage),				\
  	.set_voltage_sel = (_set_voltage_sel),			\
  	.get_voltage_sel = (_get_voltage_sel),			\
  	.set_voltage_time_sel = (_set_voltage_time_sel),	\
  	.set_ramp_delay = (_set_ramp_delay),			\
  };								\
  								\
  static const struct regulator_ops BD718XX_HWOPNAME(name) = {	\
  	.is_enabled = always_enabled_by_hwstate,		\
  	.list_voltage = (_list_voltage),			\
  	.map_voltage = (_map_voltage),				\
  	.set_voltage_sel = (_set_voltage_sel),			\
  	.get_voltage_sel = (_get_voltage_sel),			\
  	.set_voltage_time_sel = (_set_voltage_time_sel),	\
  	.set_ramp_delay = (_set_ramp_delay),			\
  }								\
  
  /*
ba08799e9   Matti Vaittinen   regulator: bd7183...
81
82
83
84
85
86
87
   * BUCK1/2/3/4
   * BUCK1RAMPRATE[1:0] BUCK1 DVS ramp rate setting
   * 00: 10.00mV/usec 10mV 1uS
   * 01: 5.00mV/usec	10mV 2uS
   * 10: 2.50mV/usec	10mV 4uS
   * 11: 1.25mV/usec	10mV 8uS
   */
dd2be639f   Matti Vaittinen   regulator/mfd: bd...
88
  static int bd718xx_buck1234_set_ramp_delay(struct regulator_dev *rdev,
ba08799e9   Matti Vaittinen   regulator: bd7183...
89
90
  					   int ramp_delay)
  {
0a245f0ef   Axel Lin   regulator: bd718x...
91
92
  	int id = rdev_get_id(rdev);
  	unsigned int ramp_value;
ba08799e9   Matti Vaittinen   regulator: bd7183...
93

bcb047ebf   Axel Lin   regulator: bd718x...
94
95
  	dev_dbg(&rdev->dev, "Buck[%d] Set Ramp = %d
  ", id + 1,
ba08799e9   Matti Vaittinen   regulator: bd7183...
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
  		ramp_delay);
  	switch (ramp_delay) {
  	case 1 ... 1250:
  		ramp_value = BUCK_RAMPRATE_1P25MV;
  		break;
  	case 1251 ... 2500:
  		ramp_value = BUCK_RAMPRATE_2P50MV;
  		break;
  	case 2501 ... 5000:
  		ramp_value = BUCK_RAMPRATE_5P00MV;
  		break;
  	case 5001 ... 10000:
  		ramp_value = BUCK_RAMPRATE_10P00MV;
  		break;
  	default:
  		ramp_value = BUCK_RAMPRATE_10P00MV;
bcb047ebf   Axel Lin   regulator: bd718x...
112
  		dev_err(&rdev->dev,
ba08799e9   Matti Vaittinen   regulator: bd7183...
113
114
115
116
  			"%s: ramp_delay: %d not supported, setting 10000mV//us
  ",
  			rdev->desc->name, ramp_delay);
  	}
bcb047ebf   Axel Lin   regulator: bd718x...
117
  	return regmap_update_bits(rdev->regmap, BD718XX_REG_BUCK1_CTRL + id,
ba08799e9   Matti Vaittinen   regulator: bd7183...
118
119
  				  BUCK_RAMPRATE_MASK, ramp_value << 6);
  }
1d848d681   Matti Vaittinen   regulator: bd718x...
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
  /* These functions are used when regulators are under HW state machine control.
   * We assume PMIC is in RUN state because SW running and able to query the
   * status. Most of the regulators have fixed ON or OFF state at RUN/IDLE so for
   * them we just return a constant. BD71837 BUCK3 and BUCK4 are exceptions as
   * they support configuring the ON/OFF state for RUN.
   *
   * Note for next hacker - these PMICs have a register where the HW state can be
   * read. If assuming RUN appears to be false in your use-case - you can
   * implement state reading (although that is not going to be atomic) before
   * returning the enable state.
   */
  static int always_enabled_by_hwstate(struct regulator_dev *rdev)
  {
  	return 1;
  }
  
  static int never_enabled_by_hwstate(struct regulator_dev *rdev)
  {
  	return 0;
  }
  
  static int bd71837_get_buck34_enable_hwctrl(struct regulator_dev *rdev)
  {
  	int ret;
  	unsigned int val;
  
  	ret = regmap_read(rdev->regmap, rdev->desc->enable_reg, &val);
  	if (ret)
  		return ret;
  
  	return !!(BD718XX_BUCK_RUN_ON & val);
  }
f0ca7b249   Matti Vaittinen   regulator: bd718x...
152
153
154
  /*
   * On BD71837 (not on BD71847, BD71850, ...)
   * Bucks 1 to 4 support DVS. PWM mode is used when voltage is changed.
ba08799e9   Matti Vaittinen   regulator: bd7183...
155
156
157
   * Bucks 5 to 8 and LDOs can use PFM and must be disabled when voltage
   * is changed. Hence we return -EBUSY for these if voltage is changed
   * when BUCK/LDO is enabled.
f0ca7b249   Matti Vaittinen   regulator: bd718x...
158
   *
9bcbabafa   Matti Vaittinen   regulator: bd718x...
159
160
161
162
163
   * On BD71847, BD71850, ... The LDO voltage can be changed when LDO is
   * enabled. But if voltage is increased the LDO power-good monitoring
   * must be disabled for the duration of changing + 1mS to ensure voltage
   * has reached the higher level before HW does next under voltage detection
   * cycle.
ba08799e9   Matti Vaittinen   regulator: bd7183...
164
   */
9bcbabafa   Matti Vaittinen   regulator: bd718x...
165
  static int bd71837_set_voltage_sel_restricted(struct regulator_dev *rdev,
ba08799e9   Matti Vaittinen   regulator: bd7183...
166
167
  						    unsigned int sel)
  {
1d848d681   Matti Vaittinen   regulator: bd718x...
168
  	if (rdev->desc->ops->is_enabled(rdev))
ffdc49841   Axel Lin   regulator: bd7183...
169
  		return -EBUSY;
ba08799e9   Matti Vaittinen   regulator: bd7183...
170

ffdc49841   Axel Lin   regulator: bd7183...
171
  	return regulator_set_voltage_sel_regmap(rdev, sel);
ba08799e9   Matti Vaittinen   regulator: bd7183...
172
  }
9bcbabafa   Matti Vaittinen   regulator: bd718x...
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
  static void voltage_change_done(struct regulator_dev *rdev, unsigned int sel,
  				unsigned int *mask)
  {
  	int ret;
  
  	if (*mask) {
  		/*
  		 * Let's allow scheduling as we use I2C anyways. We just need to
  		 * guarantee minimum of 1ms sleep - it shouldn't matter if we
  		 * exceed it due to the scheduling.
  		 */
  		msleep(1);
  		/*
  		 * Note for next hacker. The PWRGOOD should not be masked on
  		 * BD71847 so we will just unconditionally enable detection
  		 * when voltage is set.
  		 * If someone want's to disable PWRGOOD he must implement
  		 * caching and restoring the old value here. I am not
  		 * aware of such use-cases so for the sake of the simplicity
  		 * we just always enable PWRGOOD here.
  		 */
  		ret = regmap_update_bits(rdev->regmap, BD718XX_REG_MVRFLTMASK2,
  					 *mask, 0);
  		if (ret)
  			dev_err(&rdev->dev,
  				"Failed to re-enable voltage monitoring (%d)
  ",
  				ret);
  	}
  }
  
  static int voltage_change_prepare(struct regulator_dev *rdev, unsigned int sel,
  				  unsigned int *mask)
  {
  	int ret;
  
  	*mask = 0;
1d848d681   Matti Vaittinen   regulator: bd718x...
210
  	if (rdev->desc->ops->is_enabled(rdev)) {
9bcbabafa   Matti Vaittinen   regulator: bd718x...
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
  		int now, new;
  
  		now = rdev->desc->ops->get_voltage_sel(rdev);
  		if (now < 0)
  			return now;
  
  		now = rdev->desc->ops->list_voltage(rdev, now);
  		if (now < 0)
  			return now;
  
  		new = rdev->desc->ops->list_voltage(rdev, sel);
  		if (new < 0)
  			return new;
  
  		/*
  		 * If we increase LDO voltage when LDO is enabled we need to
  		 * disable the power-good detection until voltage has reached
  		 * the new level. According to HW colleagues the maximum time
  		 * it takes is 1000us. I assume that on systems with light load
  		 * this might be less - and we could probably use DT to give
  		 * system specific delay value if performance matters.
  		 *
  		 * Well, knowing we use I2C here and can add scheduling delays
  		 * I don't think it is worth the hassle and I just add fixed
  		 * 1ms sleep here (and allow scheduling). If this turns out to
  		 * be a problem we can change it to delay and make the delay
  		 * time configurable.
  		 */
  		if (new > now) {
  			int ldo_offset = rdev->desc->id - BD718XX_LDO1;
  
  			*mask = BD718XX_LDO1_VRMON80 << ldo_offset;
  			ret = regmap_update_bits(rdev->regmap,
  						 BD718XX_REG_MVRFLTMASK2,
  						 *mask, *mask);
  			if (ret) {
  				dev_err(&rdev->dev,
  					"Failed to stop voltage monitoring
  ");
  				return ret;
  			}
  		}
  	}
  
  	return 0;
  }
  
  static int bd718xx_set_voltage_sel_restricted(struct regulator_dev *rdev,
  						    unsigned int sel)
  {
  	int ret;
  	int mask;
  
  	ret = voltage_change_prepare(rdev, sel, &mask);
  	if (ret)
  		return ret;
  
  	ret = regulator_set_voltage_sel_regmap(rdev, sel);
  	voltage_change_done(rdev, sel, &mask);
  
  	return ret;
  }
a4bfc2c28   Matti Vaittinen   regulator: bd718X...
273
274
275
  static int bd718xx_set_voltage_sel_pickable_restricted(
  		struct regulator_dev *rdev, unsigned int sel)
  {
9bcbabafa   Matti Vaittinen   regulator: bd718x...
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
  	int ret;
  	int mask;
  
  	ret = voltage_change_prepare(rdev, sel, &mask);
  	if (ret)
  		return ret;
  
  	ret = regulator_set_voltage_sel_pickable_regmap(rdev, sel);
  	voltage_change_done(rdev, sel, &mask);
  
  	return ret;
  }
  
  static int bd71837_set_voltage_sel_pickable_restricted(
  		struct regulator_dev *rdev, unsigned int sel)
  {
1d848d681   Matti Vaittinen   regulator: bd718x...
292
  	if (rdev->desc->ops->is_enabled(rdev))
a4bfc2c28   Matti Vaittinen   regulator: bd718X...
293
294
295
296
  		return -EBUSY;
  
  	return regulator_set_voltage_sel_pickable_regmap(rdev, sel);
  }
1d848d681   Matti Vaittinen   regulator: bd718x...
297
298
299
300
301
302
303
304
305
306
307
  /*
   * OPS common for BD71847 and BD71850
   */
  BD718XX_OPS(bd718xx_pickable_range_ldo_ops,
  	    regulator_list_voltage_pickable_linear_range, NULL,
  	    bd718xx_set_voltage_sel_pickable_restricted,
  	    regulator_get_voltage_sel_pickable_regmap, NULL, NULL);
  
  /* BD71847 and BD71850 LDO 5 is by default OFF at RUN state */
  static const struct regulator_ops bd718xx_ldo5_ops_hwstate = {
  	.is_enabled = never_enabled_by_hwstate,
a4bfc2c28   Matti Vaittinen   regulator: bd718X...
308
309
310
  	.list_voltage = regulator_list_voltage_pickable_linear_range,
  	.set_voltage_sel = bd718xx_set_voltage_sel_pickable_restricted,
  	.get_voltage_sel = regulator_get_voltage_sel_pickable_regmap,
9bcbabafa   Matti Vaittinen   regulator: bd718x...
311
  };
1d848d681   Matti Vaittinen   regulator: bd718x...
312
313
314
315
316
  BD718XX_OPS(bd718xx_pickable_range_buck_ops,
  	    regulator_list_voltage_pickable_linear_range, NULL,
  	    regulator_set_voltage_sel_pickable_regmap,
  	    regulator_get_voltage_sel_pickable_regmap,
  	    regulator_set_voltage_time_sel, NULL);
f0ca7b249   Matti Vaittinen   regulator: bd718x...
317

1d848d681   Matti Vaittinen   regulator: bd718x...
318
319
320
  BD718XX_OPS(bd718xx_ldo_regulator_ops, regulator_list_voltage_linear_range,
  	    NULL, bd718xx_set_voltage_sel_restricted,
  	    regulator_get_voltage_sel_regmap, NULL, NULL);
9bcbabafa   Matti Vaittinen   regulator: bd718x...
321

1d848d681   Matti Vaittinen   regulator: bd718x...
322
323
324
  BD718XX_OPS(bd718xx_ldo_regulator_nolinear_ops, regulator_list_voltage_table,
  	    NULL, bd718xx_set_voltage_sel_restricted,
  	    regulator_get_voltage_sel_regmap, NULL, NULL);
ba08799e9   Matti Vaittinen   regulator: bd7183...
325

1d848d681   Matti Vaittinen   regulator: bd718x...
326
327
328
329
  BD718XX_OPS(bd718xx_buck_regulator_ops, regulator_list_voltage_linear_range,
  	    NULL, regulator_set_voltage_sel_regmap,
  	    regulator_get_voltage_sel_regmap, regulator_set_voltage_time_sel,
  	    NULL);
9bcbabafa   Matti Vaittinen   regulator: bd718x...
330

1d848d681   Matti Vaittinen   regulator: bd718x...
331
332
333
334
  BD718XX_OPS(bd718xx_buck_regulator_nolinear_ops, regulator_list_voltage_table,
  	    regulator_map_voltage_ascend, regulator_set_voltage_sel_regmap,
  	    regulator_get_voltage_sel_regmap, regulator_set_voltage_time_sel,
  	    NULL);
ba08799e9   Matti Vaittinen   regulator: bd7183...
335

1d848d681   Matti Vaittinen   regulator: bd718x...
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
  /*
   * OPS for BD71837
   */
  BD718XX_OPS(bd71837_pickable_range_ldo_ops,
  	    regulator_list_voltage_pickable_linear_range, NULL,
  	    bd71837_set_voltage_sel_pickable_restricted,
  	    regulator_get_voltage_sel_pickable_regmap, NULL, NULL);
  
  BD718XX_OPS(bd71837_pickable_range_buck_ops,
  	    regulator_list_voltage_pickable_linear_range, NULL,
  	    bd71837_set_voltage_sel_pickable_restricted,
  	    regulator_get_voltage_sel_pickable_regmap,
  	    regulator_set_voltage_time_sel, NULL);
  
  BD718XX_OPS(bd71837_ldo_regulator_ops, regulator_list_voltage_linear_range,
  	    NULL, bd71837_set_voltage_sel_restricted,
  	    regulator_get_voltage_sel_regmap, NULL, NULL);
  
  BD718XX_OPS(bd71837_ldo_regulator_nolinear_ops, regulator_list_voltage_table,
  	    NULL, bd71837_set_voltage_sel_restricted,
  	    regulator_get_voltage_sel_regmap, NULL, NULL);
  
  BD718XX_OPS(bd71837_buck_regulator_ops, regulator_list_voltage_linear_range,
  	    NULL, bd71837_set_voltage_sel_restricted,
  	    regulator_get_voltage_sel_regmap, regulator_set_voltage_time_sel,
  	    NULL);
  
  BD718XX_OPS(bd71837_buck_regulator_nolinear_ops, regulator_list_voltage_table,
  	    regulator_map_voltage_ascend, bd718xx_set_voltage_sel_restricted,
  	    regulator_get_voltage_sel_regmap, regulator_set_voltage_time_sel,
  	    NULL);
  /*
   * BD71837 bucks 3 and 4 support defining their enable/disable state also
   * when buck enable state is under HW state machine control. In that case the
   * bit [2] in CTRL register is used to indicate if regulator should be ON.
   */
  static const struct regulator_ops bd71837_buck34_ops_hwctrl = {
  	.is_enabled = bd71837_get_buck34_enable_hwctrl,
ba08799e9   Matti Vaittinen   regulator: bd7183...
374
375
376
377
  	.list_voltage = regulator_list_voltage_linear_range,
  	.set_voltage_sel = regulator_set_voltage_sel_regmap,
  	.get_voltage_sel = regulator_get_voltage_sel_regmap,
  	.set_voltage_time_sel = regulator_set_voltage_time_sel,
dd2be639f   Matti Vaittinen   regulator/mfd: bd...
378
  	.set_ramp_delay = bd718xx_buck1234_set_ramp_delay,
ba08799e9   Matti Vaittinen   regulator: bd7183...
379
380
381
  };
  
  /*
1d848d681   Matti Vaittinen   regulator: bd718x...
382
383
384
385
386
387
388
389
   * OPS for all of the ICs - BD718(37/47/50)
   */
  BD718XX_OPS(bd718xx_dvs_buck_regulator_ops, regulator_list_voltage_linear_range,
  	    NULL, regulator_set_voltage_sel_regmap,
  	    regulator_get_voltage_sel_regmap, regulator_set_voltage_time_sel,
  	    bd718xx_buck1234_set_ramp_delay);
  
  /*
494edd266   Matti Vaittinen   regulator/mfd: Su...
390
391
   * BD71837 BUCK1/2/3/4
   * BD71847 BUCK1/2
ba08799e9   Matti Vaittinen   regulator: bd7183...
392
393
   * 0.70 to 1.30V (10mV step)
   */
60ab7f415   Matti Vaittinen   regulator: use li...
394
  static const struct linear_range bd718xx_dvs_buck_volts[] = {
ba08799e9   Matti Vaittinen   regulator: bd7183...
395
396
397
398
399
  	REGULATOR_LINEAR_RANGE(700000, 0x00, 0x3C, 10000),
  	REGULATOR_LINEAR_RANGE(1300000, 0x3D, 0x3F, 0),
  };
  
  /*
494edd266   Matti Vaittinen   regulator/mfd: Su...
400
   * BD71837 BUCK5
a4bfc2c28   Matti Vaittinen   regulator: bd718X...
401
402
403
404
   * 0.7V to 1.35V  (range 0)
   * and
   * 0.675 to 1.325 (range 1)
   */
60ab7f415   Matti Vaittinen   regulator: use li...
405
  static const struct linear_range bd71837_buck5_volts[] = {
a4bfc2c28   Matti Vaittinen   regulator: bd718X...
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
  	/* Ranges when VOLT_SEL bit is 0 */
  	REGULATOR_LINEAR_RANGE(700000, 0x00, 0x03, 100000),
  	REGULATOR_LINEAR_RANGE(1050000, 0x04, 0x05, 50000),
  	REGULATOR_LINEAR_RANGE(1200000, 0x06, 0x07, 150000),
  	/* Ranges when VOLT_SEL bit is 1  */
  	REGULATOR_LINEAR_RANGE(675000, 0x0, 0x3, 100000),
  	REGULATOR_LINEAR_RANGE(1025000, 0x4, 0x5, 50000),
  	REGULATOR_LINEAR_RANGE(1175000, 0x6, 0x7, 150000),
  };
  
  /*
   * Range selector for first 3 linear ranges is 0x0
   * and 0x1 for last 3 ranges.
   */
  static const unsigned int bd71837_buck5_volt_range_sel[] = {
  	0x0, 0x0, 0x0, 0x80, 0x80, 0x80
  };
  
  /*
494edd266   Matti Vaittinen   regulator/mfd: Su...
425
   * BD71847 BUCK3
ba08799e9   Matti Vaittinen   regulator: bd7183...
426
   */
60ab7f415   Matti Vaittinen   regulator: use li...
427
  static const struct linear_range bd71847_buck3_volts[] = {
a4bfc2c28   Matti Vaittinen   regulator: bd718X...
428
  	/* Ranges when VOLT_SEL bits are 00 */
ba08799e9   Matti Vaittinen   regulator: bd7183...
429
430
431
  	REGULATOR_LINEAR_RANGE(700000, 0x00, 0x03, 100000),
  	REGULATOR_LINEAR_RANGE(1050000, 0x04, 0x05, 50000),
  	REGULATOR_LINEAR_RANGE(1200000, 0x06, 0x07, 150000),
a4bfc2c28   Matti Vaittinen   regulator: bd718X...
432
433
434
435
436
437
438
439
440
441
  	/* Ranges when VOLT_SEL bits are 01 */
  	REGULATOR_LINEAR_RANGE(550000, 0x0, 0x7, 50000),
  	/* Ranges when VOLT_SEL bits are 11 */
  	REGULATOR_LINEAR_RANGE(675000, 0x0, 0x3, 100000),
  	REGULATOR_LINEAR_RANGE(1025000, 0x4, 0x5, 50000),
  	REGULATOR_LINEAR_RANGE(1175000, 0x6, 0x7, 150000),
  };
  
  static const unsigned int bd71847_buck3_volt_range_sel[] = {
  	0x0, 0x0, 0x0, 0x40, 0x80, 0x80, 0x80
ba08799e9   Matti Vaittinen   regulator: bd7183...
442
  };
60ab7f415   Matti Vaittinen   regulator: use li...
443
  static const struct linear_range bd71847_buck4_volts[] = {
494edd266   Matti Vaittinen   regulator/mfd: Su...
444
  	REGULATOR_LINEAR_RANGE(3000000, 0x00, 0x03, 100000),
a4bfc2c28   Matti Vaittinen   regulator: bd718X...
445
  	REGULATOR_LINEAR_RANGE(2600000, 0x00, 0x03, 100000),
494edd266   Matti Vaittinen   regulator/mfd: Su...
446
  };
a4bfc2c28   Matti Vaittinen   regulator: bd718X...
447
  static const unsigned int bd71847_buck4_volt_range_sel[] = { 0x0, 0x40 };
ba08799e9   Matti Vaittinen   regulator: bd7183...
448
449
450
451
  /*
   * BUCK6
   * 3.0V to 3.3V (step 100mV)
   */
60ab7f415   Matti Vaittinen   regulator: use li...
452
  static const struct linear_range bd71837_buck6_volts[] = {
ba08799e9   Matti Vaittinen   regulator: bd7183...
453
454
455
456
  	REGULATOR_LINEAR_RANGE(3000000, 0x00, 0x03, 100000),
  };
  
  /*
494edd266   Matti Vaittinen   regulator/mfd: Su...
457
458
   * BD71837 BUCK7
   * BD71847 BUCK5
ba08799e9   Matti Vaittinen   regulator: bd7183...
459
460
461
462
463
464
465
466
467
   * 000 = 1.605V
   * 001 = 1.695V
   * 010 = 1.755V
   * 011 = 1.8V (Initial)
   * 100 = 1.845V
   * 101 = 1.905V
   * 110 = 1.95V
   * 111 = 1.995V
   */
494edd266   Matti Vaittinen   regulator/mfd: Su...
468
  static const unsigned int bd718xx_3rd_nodvs_buck_volts[] = {
ba08799e9   Matti Vaittinen   regulator: bd7183...
469
470
471
472
473
474
475
  	1605000, 1695000, 1755000, 1800000, 1845000, 1905000, 1950000, 1995000
  };
  
  /*
   * BUCK8
   * 0.8V to 1.40V (step 10mV)
   */
60ab7f415   Matti Vaittinen   regulator: use li...
476
  static const struct linear_range bd718xx_4th_nodvs_buck_volts[] = {
ba08799e9   Matti Vaittinen   regulator: bd7183...
477
  	REGULATOR_LINEAR_RANGE(800000, 0x00, 0x3C, 10000),
ba08799e9   Matti Vaittinen   regulator: bd7183...
478
479
480
481
482
483
  };
  
  /*
   * LDO1
   * 3.0 to 3.3V (100mV step)
   */
60ab7f415   Matti Vaittinen   regulator: use li...
484
  static const struct linear_range bd718xx_ldo1_volts[] = {
ba08799e9   Matti Vaittinen   regulator: bd7183...
485
  	REGULATOR_LINEAR_RANGE(3000000, 0x00, 0x03, 100000),
a4bfc2c28   Matti Vaittinen   regulator: bd718X...
486
  	REGULATOR_LINEAR_RANGE(1600000, 0x00, 0x03, 100000),
ba08799e9   Matti Vaittinen   regulator: bd7183...
487
  };
a4bfc2c28   Matti Vaittinen   regulator: bd718X...
488
  static const unsigned int bd718xx_ldo1_volt_range_sel[] = { 0x0, 0x20 };
ba08799e9   Matti Vaittinen   regulator: bd7183...
489
490
491
492
  /*
   * LDO2
   * 0.8 or 0.9V
   */
adb78a8e2   Axel Lin   regulator: bd7183...
493
  static const unsigned int ldo_2_volts[] = {
ba08799e9   Matti Vaittinen   regulator: bd7183...
494
495
496
497
498
499
500
  	900000, 800000
  };
  
  /*
   * LDO3
   * 1.8 to 3.3V (100mV step)
   */
60ab7f415   Matti Vaittinen   regulator: use li...
501
  static const struct linear_range bd718xx_ldo3_volts[] = {
ba08799e9   Matti Vaittinen   regulator: bd7183...
502
503
504
505
506
507
508
  	REGULATOR_LINEAR_RANGE(1800000, 0x00, 0x0F, 100000),
  };
  
  /*
   * LDO4
   * 0.9 to 1.8V (100mV step)
   */
60ab7f415   Matti Vaittinen   regulator: use li...
509
  static const struct linear_range bd718xx_ldo4_volts[] = {
ba08799e9   Matti Vaittinen   regulator: bd7183...
510
  	REGULATOR_LINEAR_RANGE(900000, 0x00, 0x09, 100000),
ba08799e9   Matti Vaittinen   regulator: bd7183...
511
512
513
  };
  
  /*
494edd266   Matti Vaittinen   regulator/mfd: Su...
514
   * LDO5 for BD71837
ba08799e9   Matti Vaittinen   regulator: bd7183...
515
516
   * 1.8 to 3.3V (100mV step)
   */
60ab7f415   Matti Vaittinen   regulator: use li...
517
  static const struct linear_range bd71837_ldo5_volts[] = {
ba08799e9   Matti Vaittinen   regulator: bd7183...
518
519
520
521
  	REGULATOR_LINEAR_RANGE(1800000, 0x00, 0x0F, 100000),
  };
  
  /*
a4bfc2c28   Matti Vaittinen   regulator: bd718X...
522
523
524
   * LDO5 for BD71837
   * 1.8 to 3.3V (100mV step)
   */
60ab7f415   Matti Vaittinen   regulator: use li...
525
  static const struct linear_range bd71847_ldo5_volts[] = {
a4bfc2c28   Matti Vaittinen   regulator: bd718X...
526
527
528
529
530
531
532
  	REGULATOR_LINEAR_RANGE(1800000, 0x00, 0x0F, 100000),
  	REGULATOR_LINEAR_RANGE(800000, 0x00, 0x0F, 100000),
  };
  
  static const unsigned int bd71847_ldo5_volt_range_sel[] = { 0x0, 0x20 };
  
  /*
ba08799e9   Matti Vaittinen   regulator: bd7183...
533
534
535
   * LDO6
   * 0.9 to 1.8V (100mV step)
   */
60ab7f415   Matti Vaittinen   regulator: use li...
536
  static const struct linear_range bd718xx_ldo6_volts[] = {
ba08799e9   Matti Vaittinen   regulator: bd7183...
537
  	REGULATOR_LINEAR_RANGE(900000, 0x00, 0x09, 100000),
ba08799e9   Matti Vaittinen   regulator: bd7183...
538
539
540
541
542
543
  };
  
  /*
   * LDO7
   * 1.8 to 3.3V (100mV step)
   */
60ab7f415   Matti Vaittinen   regulator: use li...
544
  static const struct linear_range bd71837_ldo7_volts[] = {
ba08799e9   Matti Vaittinen   regulator: bd7183...
545
546
  	REGULATOR_LINEAR_RANGE(1800000, 0x00, 0x0F, 100000),
  };
494edd266   Matti Vaittinen   regulator/mfd: Su...
547
548
549
550
551
552
553
  struct reg_init {
  	unsigned int reg;
  	unsigned int mask;
  	unsigned int val;
  };
  struct bd718xx_regulator_data {
  	struct regulator_desc desc;
21b72156e   Matti Vaittinen   regulator: bd718x...
554
  	const struct rohm_dvs_config dvs;
494edd266   Matti Vaittinen   regulator/mfd: Su...
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
  	const struct reg_init init;
  	const struct reg_init *additional_inits;
  	int additional_init_amnt;
  };
  
  /*
   * There is a HW quirk in BD71837. The shutdown sequence timings for
   * bucks/LDOs which are controlled via register interface are changed.
   * At PMIC poweroff the voltage for BUCK6/7 is cut immediately at the
   * beginning of shut-down sequence. As bucks 6 and 7 are parent
   * supplies for LDO5 and LDO6 - this causes LDO5/6 voltage
   * monitoring to errorneously detect under voltage and force PMIC to
   * emergency state instead of poweroff. In order to avoid this we
   * disable voltage monitoring for LDO5 and LDO6
   */
  static const struct reg_init bd71837_ldo5_inits[] = {
  	{
  		.reg = BD718XX_REG_MVRFLTMASK2,
  		.mask = BD718XX_LDO5_VRMON80,
  		.val = BD718XX_LDO5_VRMON80,
  	},
  };
  
  static const struct reg_init bd71837_ldo6_inits[] = {
  	{
  		.reg = BD718XX_REG_MVRFLTMASK2,
  		.mask = BD718XX_LDO6_VRMON80,
  		.val = BD718XX_LDO6_VRMON80,
  	},
  };
21b72156e   Matti Vaittinen   regulator: bd718x...
585
  static int buck_set_hw_dvs_levels(struct device_node *np,
049369d46   Matti Vaittinen   regulator: bd718x...
586
587
588
  			    const struct regulator_desc *desc,
  			    struct regulator_config *cfg)
  {
21b72156e   Matti Vaittinen   regulator: bd718x...
589
  	struct bd718xx_regulator_data *data;
049369d46   Matti Vaittinen   regulator: bd718x...
590

21b72156e   Matti Vaittinen   regulator: bd718x...
591
  	data = container_of(desc, struct bd718xx_regulator_data, desc);
049369d46   Matti Vaittinen   regulator: bd718x...
592

21b72156e   Matti Vaittinen   regulator: bd718x...
593
  	return rohm_regulator_set_dvs_levels(&data->dvs, np, desc, cfg->regmap);
049369d46   Matti Vaittinen   regulator: bd718x...
594
  }
02f8eaab0   YueHaibing   regulator: bd718x...
595
  static const struct regulator_ops *bd71847_swcontrol_ops[] = {
1d848d681   Matti Vaittinen   regulator: bd718x...
596
597
598
599
600
601
602
  	&bd718xx_dvs_buck_regulator_ops, &bd718xx_dvs_buck_regulator_ops,
  	&bd718xx_pickable_range_buck_ops, &bd718xx_pickable_range_buck_ops,
  	&bd718xx_buck_regulator_nolinear_ops, &bd718xx_buck_regulator_ops,
  	&bd718xx_pickable_range_ldo_ops, &bd718xx_ldo_regulator_nolinear_ops,
  	&bd718xx_ldo_regulator_ops, &bd718xx_ldo_regulator_ops,
  	&bd718xx_pickable_range_ldo_ops, &bd718xx_ldo_regulator_ops,
  };
02f8eaab0   YueHaibing   regulator: bd718x...
603
  static const struct regulator_ops *bd71847_hwcontrol_ops[] = {
1d848d681   Matti Vaittinen   regulator: bd718x...
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
  	&BD718XX_HWOPNAME(bd718xx_dvs_buck_regulator_ops),
  	&BD718XX_HWOPNAME(bd718xx_dvs_buck_regulator_ops),
  	&BD718XX_HWOPNAME(bd718xx_pickable_range_buck_ops),
  	&BD718XX_HWOPNAME(bd718xx_pickable_range_buck_ops),
  	&BD718XX_HWOPNAME(bd718xx_buck_regulator_nolinear_ops),
  	&BD718XX_HWOPNAME(bd718xx_buck_regulator_ops),
  	&BD718XX_HWOPNAME(bd718xx_pickable_range_ldo_ops),
  	&BD718XX_HWOPNAME(bd718xx_ldo_regulator_nolinear_ops),
  	&BD718XX_HWOPNAME(bd718xx_ldo_regulator_ops),
  	&BD718XX_HWOPNAME(bd718xx_ldo_regulator_ops),
  	&bd718xx_ldo5_ops_hwstate,
  	&BD718XX_HWOPNAME(bd718xx_ldo_regulator_ops),
  };
  
  static struct bd718xx_regulator_data bd71847_regulators[] = {
494edd266   Matti Vaittinen   regulator/mfd: Su...
619
620
621
622
623
624
  	{
  		.desc = {
  			.name = "buck1",
  			.of_match = of_match_ptr("BUCK1"),
  			.regulators_node = of_match_ptr("regulators"),
  			.id = BD718XX_BUCK1,
494edd266   Matti Vaittinen   regulator/mfd: Su...
625
626
627
628
629
630
631
632
633
  			.type = REGULATOR_VOLTAGE,
  			.n_voltages = BD718XX_DVS_BUCK_VOLTAGE_NUM,
  			.linear_ranges = bd718xx_dvs_buck_volts,
  			.n_linear_ranges =
  				ARRAY_SIZE(bd718xx_dvs_buck_volts),
  			.vsel_reg = BD718XX_REG_BUCK1_VOLT_RUN,
  			.vsel_mask = DVS_BUCK_RUN_MASK,
  			.enable_reg = BD718XX_REG_BUCK1_CTRL,
  			.enable_mask = BD718XX_BUCK_EN,
36afeaad7   Guido Günther   regulator: bd718x...
634
  			.enable_time = BD71847_BUCK1_STARTUP_TIME,
494edd266   Matti Vaittinen   regulator/mfd: Su...
635
  			.owner = THIS_MODULE,
21b72156e   Matti Vaittinen   regulator: bd718x...
636
637
638
639
640
641
642
643
644
645
646
  			.of_parse_cb = buck_set_hw_dvs_levels,
  		},
  		.dvs = {
  			.level_map = ROHM_DVS_LEVEL_RUN | ROHM_DVS_LEVEL_IDLE |
  				     ROHM_DVS_LEVEL_SUSPEND,
  			.run_reg = BD718XX_REG_BUCK1_VOLT_RUN,
  			.run_mask = DVS_BUCK_RUN_MASK,
  			.idle_reg = BD718XX_REG_BUCK1_VOLT_IDLE,
  			.idle_mask = DVS_BUCK_RUN_MASK,
  			.suspend_reg = BD718XX_REG_BUCK1_VOLT_SUSP,
  			.suspend_mask = DVS_BUCK_RUN_MASK,
494edd266   Matti Vaittinen   regulator/mfd: Su...
647
648
649
650
651
652
653
  		},
  		.init = {
  			.reg = BD718XX_REG_BUCK1_CTRL,
  			.mask = BD718XX_BUCK_SEL,
  			.val = BD718XX_BUCK_SEL,
  		},
  	},
ba08799e9   Matti Vaittinen   regulator: bd7183...
654
  	{
494edd266   Matti Vaittinen   regulator/mfd: Su...
655
656
657
658
659
  		.desc = {
  			.name = "buck2",
  			.of_match = of_match_ptr("BUCK2"),
  			.regulators_node = of_match_ptr("regulators"),
  			.id = BD718XX_BUCK2,
494edd266   Matti Vaittinen   regulator/mfd: Su...
660
661
662
663
664
665
666
667
  			.type = REGULATOR_VOLTAGE,
  			.n_voltages = BD718XX_DVS_BUCK_VOLTAGE_NUM,
  			.linear_ranges = bd718xx_dvs_buck_volts,
  			.n_linear_ranges = ARRAY_SIZE(bd718xx_dvs_buck_volts),
  			.vsel_reg = BD718XX_REG_BUCK2_VOLT_RUN,
  			.vsel_mask = DVS_BUCK_RUN_MASK,
  			.enable_reg = BD718XX_REG_BUCK2_CTRL,
  			.enable_mask = BD718XX_BUCK_EN,
36afeaad7   Guido Günther   regulator: bd718x...
668
  			.enable_time = BD71847_BUCK2_STARTUP_TIME,
494edd266   Matti Vaittinen   regulator/mfd: Su...
669
  			.owner = THIS_MODULE,
21b72156e   Matti Vaittinen   regulator: bd718x...
670
671
672
673
674
675
676
677
  			.of_parse_cb = buck_set_hw_dvs_levels,
  		},
  		.dvs = {
  			.level_map = ROHM_DVS_LEVEL_RUN | ROHM_DVS_LEVEL_IDLE,
  			.run_reg = BD718XX_REG_BUCK2_VOLT_RUN,
  			.run_mask = DVS_BUCK_RUN_MASK,
  			.idle_reg = BD718XX_REG_BUCK2_VOLT_IDLE,
  			.idle_mask = DVS_BUCK_RUN_MASK,
494edd266   Matti Vaittinen   regulator/mfd: Su...
678
679
680
681
682
683
  		},
  		.init = {
  			.reg = BD718XX_REG_BUCK2_CTRL,
  			.mask = BD718XX_BUCK_SEL,
  			.val = BD718XX_BUCK_SEL,
  		},
ba08799e9   Matti Vaittinen   regulator: bd7183...
684
685
  	},
  	{
494edd266   Matti Vaittinen   regulator/mfd: Su...
686
687
688
689
690
  		.desc = {
  			.name = "buck3",
  			.of_match = of_match_ptr("BUCK3"),
  			.regulators_node = of_match_ptr("regulators"),
  			.id = BD718XX_BUCK3,
494edd266   Matti Vaittinen   regulator/mfd: Su...
691
  			.type = REGULATOR_VOLTAGE,
a4bfc2c28   Matti Vaittinen   regulator: bd718X...
692
693
  			.n_voltages = BD71847_BUCK3_VOLTAGE_NUM,
  			.linear_ranges = bd71847_buck3_volts,
494edd266   Matti Vaittinen   regulator/mfd: Su...
694
  			.n_linear_ranges =
a4bfc2c28   Matti Vaittinen   regulator: bd718X...
695
  				ARRAY_SIZE(bd71847_buck3_volts),
494edd266   Matti Vaittinen   regulator/mfd: Su...
696
697
  			.vsel_reg = BD718XX_REG_1ST_NODVS_BUCK_VOLT,
  			.vsel_mask = BD718XX_1ST_NODVS_BUCK_MASK,
a4bfc2c28   Matti Vaittinen   regulator: bd718X...
698
699
700
  			.vsel_range_reg = BD718XX_REG_1ST_NODVS_BUCK_VOLT,
  			.vsel_range_mask = BD71847_BUCK3_RANGE_MASK,
  			.linear_range_selectors = bd71847_buck3_volt_range_sel,
494edd266   Matti Vaittinen   regulator/mfd: Su...
701
702
  			.enable_reg = BD718XX_REG_1ST_NODVS_BUCK_CTRL,
  			.enable_mask = BD718XX_BUCK_EN,
36afeaad7   Guido Günther   regulator: bd718x...
703
  			.enable_time = BD71847_BUCK3_STARTUP_TIME,
494edd266   Matti Vaittinen   regulator/mfd: Su...
704
705
706
707
708
709
710
  			.owner = THIS_MODULE,
  		},
  		.init = {
  			.reg = BD718XX_REG_1ST_NODVS_BUCK_CTRL,
  			.mask = BD718XX_BUCK_SEL,
  			.val = BD718XX_BUCK_SEL,
  		},
ba08799e9   Matti Vaittinen   regulator: bd7183...
711
712
  	},
  	{
494edd266   Matti Vaittinen   regulator/mfd: Su...
713
714
715
716
717
  		.desc = {
  			.name = "buck4",
  			.of_match = of_match_ptr("BUCK4"),
  			.regulators_node = of_match_ptr("regulators"),
  			.id = BD718XX_BUCK4,
494edd266   Matti Vaittinen   regulator/mfd: Su...
718
719
  			.type = REGULATOR_VOLTAGE,
  			.n_voltages = BD71847_BUCK4_VOLTAGE_NUM,
a4bfc2c28   Matti Vaittinen   regulator: bd718X...
720
  			.linear_ranges = bd71847_buck4_volts,
494edd266   Matti Vaittinen   regulator/mfd: Su...
721
  			.n_linear_ranges =
a4bfc2c28   Matti Vaittinen   regulator: bd718X...
722
  				ARRAY_SIZE(bd71847_buck4_volts),
494edd266   Matti Vaittinen   regulator/mfd: Su...
723
724
725
  			.enable_reg = BD718XX_REG_2ND_NODVS_BUCK_CTRL,
  			.vsel_reg = BD718XX_REG_2ND_NODVS_BUCK_VOLT,
  			.vsel_mask = BD71847_BUCK4_MASK,
a4bfc2c28   Matti Vaittinen   regulator: bd718X...
726
727
728
  			.vsel_range_reg = BD718XX_REG_2ND_NODVS_BUCK_VOLT,
  			.vsel_range_mask = BD71847_BUCK4_RANGE_MASK,
  			.linear_range_selectors = bd71847_buck4_volt_range_sel,
494edd266   Matti Vaittinen   regulator/mfd: Su...
729
  			.enable_mask = BD718XX_BUCK_EN,
36afeaad7   Guido Günther   regulator: bd718x...
730
  			.enable_time = BD71847_BUCK4_STARTUP_TIME,
494edd266   Matti Vaittinen   regulator/mfd: Su...
731
732
733
734
735
736
737
  			.owner = THIS_MODULE,
  		},
  		.init = {
  			.reg = BD718XX_REG_2ND_NODVS_BUCK_CTRL,
  			.mask = BD718XX_BUCK_SEL,
  			.val = BD718XX_BUCK_SEL,
  		},
ba08799e9   Matti Vaittinen   regulator: bd7183...
738
739
  	},
  	{
494edd266   Matti Vaittinen   regulator/mfd: Su...
740
741
742
  		.desc = {
  			.name = "buck5",
  			.of_match = of_match_ptr("BUCK5"),
dd2be639f   Matti Vaittinen   regulator/mfd: bd...
743
  			.regulators_node = of_match_ptr("regulators"),
494edd266   Matti Vaittinen   regulator/mfd: Su...
744
  			.id = BD718XX_BUCK5,
494edd266   Matti Vaittinen   regulator/mfd: Su...
745
746
747
748
749
750
751
  			.type = REGULATOR_VOLTAGE,
  			.volt_table = &bd718xx_3rd_nodvs_buck_volts[0],
  			.n_voltages = ARRAY_SIZE(bd718xx_3rd_nodvs_buck_volts),
  			.vsel_reg = BD718XX_REG_3RD_NODVS_BUCK_VOLT,
  			.vsel_mask = BD718XX_3RD_NODVS_BUCK_MASK,
  			.enable_reg = BD718XX_REG_3RD_NODVS_BUCK_CTRL,
  			.enable_mask = BD718XX_BUCK_EN,
36afeaad7   Guido Günther   regulator: bd718x...
752
  			.enable_time = BD71847_BUCK5_STARTUP_TIME,
494edd266   Matti Vaittinen   regulator/mfd: Su...
753
754
755
756
757
758
759
  			.owner = THIS_MODULE,
  		},
  		.init = {
  			.reg = BD718XX_REG_3RD_NODVS_BUCK_CTRL,
  			.mask = BD718XX_BUCK_SEL,
  			.val = BD718XX_BUCK_SEL,
  		},
ba08799e9   Matti Vaittinen   regulator: bd7183...
760
761
  	},
  	{
494edd266   Matti Vaittinen   regulator/mfd: Su...
762
763
764
765
766
  		.desc = {
  			.name = "buck6",
  			.of_match = of_match_ptr("BUCK6"),
  			.regulators_node = of_match_ptr("regulators"),
  			.id = BD718XX_BUCK6,
494edd266   Matti Vaittinen   regulator/mfd: Su...
767
  			.type = REGULATOR_VOLTAGE,
dd2be639f   Matti Vaittinen   regulator/mfd: bd...
768
  			.n_voltages = BD718XX_4TH_NODVS_BUCK_VOLTAGE_NUM,
494edd266   Matti Vaittinen   regulator/mfd: Su...
769
770
771
772
773
774
775
  			.linear_ranges = bd718xx_4th_nodvs_buck_volts,
  			.n_linear_ranges =
  				ARRAY_SIZE(bd718xx_4th_nodvs_buck_volts),
  			.vsel_reg = BD718XX_REG_4TH_NODVS_BUCK_VOLT,
  			.vsel_mask = BD718XX_4TH_NODVS_BUCK_MASK,
  			.enable_reg = BD718XX_REG_4TH_NODVS_BUCK_CTRL,
  			.enable_mask = BD718XX_BUCK_EN,
36afeaad7   Guido Günther   regulator: bd718x...
776
  			.enable_time = BD71847_BUCK6_STARTUP_TIME,
494edd266   Matti Vaittinen   regulator/mfd: Su...
777
778
779
780
781
782
783
  			.owner = THIS_MODULE,
  		},
  		.init = {
  			.reg = BD718XX_REG_4TH_NODVS_BUCK_CTRL,
  			.mask = BD718XX_BUCK_SEL,
  			.val = BD718XX_BUCK_SEL,
  		},
ba08799e9   Matti Vaittinen   regulator: bd7183...
784
785
  	},
  	{
494edd266   Matti Vaittinen   regulator/mfd: Su...
786
787
788
789
790
  		.desc = {
  			.name = "ldo1",
  			.of_match = of_match_ptr("LDO1"),
  			.regulators_node = of_match_ptr("regulators"),
  			.id = BD718XX_LDO1,
494edd266   Matti Vaittinen   regulator/mfd: Su...
791
792
793
794
795
796
  			.type = REGULATOR_VOLTAGE,
  			.n_voltages = BD718XX_LDO1_VOLTAGE_NUM,
  			.linear_ranges = bd718xx_ldo1_volts,
  			.n_linear_ranges = ARRAY_SIZE(bd718xx_ldo1_volts),
  			.vsel_reg = BD718XX_REG_LDO1_VOLT,
  			.vsel_mask = BD718XX_LDO1_MASK,
a4bfc2c28   Matti Vaittinen   regulator: bd718X...
797
798
799
  			.vsel_range_reg = BD718XX_REG_LDO1_VOLT,
  			.vsel_range_mask = BD718XX_LDO1_RANGE_MASK,
  			.linear_range_selectors = bd718xx_ldo1_volt_range_sel,
494edd266   Matti Vaittinen   regulator/mfd: Su...
800
801
  			.enable_reg = BD718XX_REG_LDO1_VOLT,
  			.enable_mask = BD718XX_LDO_EN,
36afeaad7   Guido Günther   regulator: bd718x...
802
  			.enable_time = BD71847_LDO1_STARTUP_TIME,
494edd266   Matti Vaittinen   regulator/mfd: Su...
803
804
805
806
807
808
809
  			.owner = THIS_MODULE,
  		},
  		.init = {
  			.reg = BD718XX_REG_LDO1_VOLT,
  			.mask = BD718XX_LDO_SEL,
  			.val = BD718XX_LDO_SEL,
  		},
ba08799e9   Matti Vaittinen   regulator: bd7183...
810
811
  	},
  	{
494edd266   Matti Vaittinen   regulator/mfd: Su...
812
813
814
815
816
  		.desc = {
  			.name = "ldo2",
  			.of_match = of_match_ptr("LDO2"),
  			.regulators_node = of_match_ptr("regulators"),
  			.id = BD718XX_LDO2,
494edd266   Matti Vaittinen   regulator/mfd: Su...
817
818
819
820
821
822
823
  			.type = REGULATOR_VOLTAGE,
  			.volt_table = &ldo_2_volts[0],
  			.vsel_reg = BD718XX_REG_LDO2_VOLT,
  			.vsel_mask = BD718XX_LDO2_MASK,
  			.n_voltages = ARRAY_SIZE(ldo_2_volts),
  			.enable_reg = BD718XX_REG_LDO2_VOLT,
  			.enable_mask = BD718XX_LDO_EN,
36afeaad7   Guido Günther   regulator: bd718x...
824
  			.enable_time = BD71847_LDO2_STARTUP_TIME,
494edd266   Matti Vaittinen   regulator/mfd: Su...
825
826
827
828
829
830
831
  			.owner = THIS_MODULE,
  		},
  		.init = {
  			.reg = BD718XX_REG_LDO2_VOLT,
  			.mask = BD718XX_LDO_SEL,
  			.val = BD718XX_LDO_SEL,
  		},
ba08799e9   Matti Vaittinen   regulator: bd7183...
832
833
  	},
  	{
494edd266   Matti Vaittinen   regulator/mfd: Su...
834
835
836
837
838
  		.desc = {
  			.name = "ldo3",
  			.of_match = of_match_ptr("LDO3"),
  			.regulators_node = of_match_ptr("regulators"),
  			.id = BD718XX_LDO3,
494edd266   Matti Vaittinen   regulator/mfd: Su...
839
840
841
842
843
844
845
846
  			.type = REGULATOR_VOLTAGE,
  			.n_voltages = BD718XX_LDO3_VOLTAGE_NUM,
  			.linear_ranges = bd718xx_ldo3_volts,
  			.n_linear_ranges = ARRAY_SIZE(bd718xx_ldo3_volts),
  			.vsel_reg = BD718XX_REG_LDO3_VOLT,
  			.vsel_mask = BD718XX_LDO3_MASK,
  			.enable_reg = BD718XX_REG_LDO3_VOLT,
  			.enable_mask = BD718XX_LDO_EN,
36afeaad7   Guido Günther   regulator: bd718x...
847
  			.enable_time = BD71847_LDO3_STARTUP_TIME,
494edd266   Matti Vaittinen   regulator/mfd: Su...
848
849
850
851
852
853
854
  			.owner = THIS_MODULE,
  		},
  		.init = {
  			.reg = BD718XX_REG_LDO3_VOLT,
  			.mask = BD718XX_LDO_SEL,
  			.val = BD718XX_LDO_SEL,
  		},
ba08799e9   Matti Vaittinen   regulator: bd7183...
855
856
  	},
  	{
494edd266   Matti Vaittinen   regulator/mfd: Su...
857
858
859
860
861
  		.desc = {
  			.name = "ldo4",
  			.of_match = of_match_ptr("LDO4"),
  			.regulators_node = of_match_ptr("regulators"),
  			.id = BD718XX_LDO4,
494edd266   Matti Vaittinen   regulator/mfd: Su...
862
863
864
865
866
867
868
869
  			.type = REGULATOR_VOLTAGE,
  			.n_voltages = BD718XX_LDO4_VOLTAGE_NUM,
  			.linear_ranges = bd718xx_ldo4_volts,
  			.n_linear_ranges = ARRAY_SIZE(bd718xx_ldo4_volts),
  			.vsel_reg = BD718XX_REG_LDO4_VOLT,
  			.vsel_mask = BD718XX_LDO4_MASK,
  			.enable_reg = BD718XX_REG_LDO4_VOLT,
  			.enable_mask = BD718XX_LDO_EN,
36afeaad7   Guido Günther   regulator: bd718x...
870
  			.enable_time = BD71847_LDO4_STARTUP_TIME,
494edd266   Matti Vaittinen   regulator/mfd: Su...
871
872
873
874
875
876
877
  			.owner = THIS_MODULE,
  		},
  		.init = {
  			.reg = BD718XX_REG_LDO4_VOLT,
  			.mask = BD718XX_LDO_SEL,
  			.val = BD718XX_LDO_SEL,
  		},
ba08799e9   Matti Vaittinen   regulator: bd7183...
878
879
  	},
  	{
494edd266   Matti Vaittinen   regulator/mfd: Su...
880
881
882
883
884
  		.desc = {
  			.name = "ldo5",
  			.of_match = of_match_ptr("LDO5"),
  			.regulators_node = of_match_ptr("regulators"),
  			.id = BD718XX_LDO5,
494edd266   Matti Vaittinen   regulator/mfd: Su...
885
  			.type = REGULATOR_VOLTAGE,
a4bfc2c28   Matti Vaittinen   regulator: bd718X...
886
887
888
  			.n_voltages = BD71847_LDO5_VOLTAGE_NUM,
  			.linear_ranges = bd71847_ldo5_volts,
  			.n_linear_ranges = ARRAY_SIZE(bd71847_ldo5_volts),
494edd266   Matti Vaittinen   regulator/mfd: Su...
889
890
  			.vsel_reg = BD718XX_REG_LDO5_VOLT,
  			.vsel_mask = BD71847_LDO5_MASK,
a4bfc2c28   Matti Vaittinen   regulator: bd718X...
891
892
893
  			.vsel_range_reg = BD718XX_REG_LDO5_VOLT,
  			.vsel_range_mask = BD71847_LDO5_RANGE_MASK,
  			.linear_range_selectors = bd71847_ldo5_volt_range_sel,
494edd266   Matti Vaittinen   regulator/mfd: Su...
894
895
  			.enable_reg = BD718XX_REG_LDO5_VOLT,
  			.enable_mask = BD718XX_LDO_EN,
36afeaad7   Guido Günther   regulator: bd718x...
896
  			.enable_time = BD71847_LDO5_STARTUP_TIME,
494edd266   Matti Vaittinen   regulator/mfd: Su...
897
898
899
900
901
902
903
  			.owner = THIS_MODULE,
  		},
  		.init = {
  			.reg = BD718XX_REG_LDO5_VOLT,
  			.mask = BD718XX_LDO_SEL,
  			.val = BD718XX_LDO_SEL,
  		},
ba08799e9   Matti Vaittinen   regulator: bd7183...
904
905
  	},
  	{
494edd266   Matti Vaittinen   regulator/mfd: Su...
906
907
908
909
910
  		.desc = {
  			.name = "ldo6",
  			.of_match = of_match_ptr("LDO6"),
  			.regulators_node = of_match_ptr("regulators"),
  			.id = BD718XX_LDO6,
494edd266   Matti Vaittinen   regulator/mfd: Su...
911
912
913
914
915
916
917
918
919
920
  			.type = REGULATOR_VOLTAGE,
  			.n_voltages = BD718XX_LDO6_VOLTAGE_NUM,
  			.linear_ranges = bd718xx_ldo6_volts,
  			.n_linear_ranges = ARRAY_SIZE(bd718xx_ldo6_volts),
  			/* LDO6 is supplied by buck5 */
  			.supply_name = "buck5",
  			.vsel_reg = BD718XX_REG_LDO6_VOLT,
  			.vsel_mask = BD718XX_LDO6_MASK,
  			.enable_reg = BD718XX_REG_LDO6_VOLT,
  			.enable_mask = BD718XX_LDO_EN,
36afeaad7   Guido Günther   regulator: bd718x...
921
  			.enable_time = BD71847_LDO6_STARTUP_TIME,
494edd266   Matti Vaittinen   regulator/mfd: Su...
922
923
924
925
926
927
928
929
930
  			.owner = THIS_MODULE,
  		},
  		.init = {
  			.reg = BD718XX_REG_LDO6_VOLT,
  			.mask = BD718XX_LDO_SEL,
  			.val = BD718XX_LDO_SEL,
  		},
  	},
  };
02f8eaab0   YueHaibing   regulator: bd718x...
931
  static const struct regulator_ops *bd71837_swcontrol_ops[] = {
1d848d681   Matti Vaittinen   regulator: bd718x...
932
933
934
935
936
937
938
939
940
  	&bd718xx_dvs_buck_regulator_ops, &bd718xx_dvs_buck_regulator_ops,
  	&bd718xx_dvs_buck_regulator_ops, &bd718xx_dvs_buck_regulator_ops,
  	&bd71837_pickable_range_buck_ops, &bd71837_buck_regulator_ops,
  	&bd71837_buck_regulator_nolinear_ops, &bd71837_buck_regulator_ops,
  	&bd71837_pickable_range_ldo_ops, &bd71837_ldo_regulator_nolinear_ops,
  	&bd71837_ldo_regulator_ops, &bd71837_ldo_regulator_ops,
  	&bd71837_ldo_regulator_ops, &bd71837_ldo_regulator_ops,
  	&bd71837_ldo_regulator_ops,
  };
02f8eaab0   YueHaibing   regulator: bd718x...
941
  static const struct regulator_ops *bd71837_hwcontrol_ops[] = {
1d848d681   Matti Vaittinen   regulator: bd718x...
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
  	&BD718XX_HWOPNAME(bd718xx_dvs_buck_regulator_ops),
  	&BD718XX_HWOPNAME(bd718xx_dvs_buck_regulator_ops),
  	&bd71837_buck34_ops_hwctrl, &bd71837_buck34_ops_hwctrl,
  	&BD718XX_HWOPNAME(bd71837_pickable_range_buck_ops),
  	&BD718XX_HWOPNAME(bd71837_buck_regulator_ops),
  	&BD718XX_HWOPNAME(bd71837_buck_regulator_nolinear_ops),
  	&BD718XX_HWOPNAME(bd71837_buck_regulator_ops),
  	&BD718XX_HWOPNAME(bd71837_pickable_range_ldo_ops),
  	&BD718XX_HWOPNAME(bd71837_ldo_regulator_nolinear_ops),
  	&BD718XX_HWOPNAME(bd71837_ldo_regulator_ops),
  	&BD718XX_HWOPNAME(bd71837_ldo_regulator_ops),
  	&BD718XX_HWOPNAME(bd71837_ldo_regulator_ops),
  	&BD718XX_HWOPNAME(bd71837_ldo_regulator_ops),
  	&BD718XX_HWOPNAME(bd71837_ldo_regulator_ops),
  };
  
  static struct bd718xx_regulator_data bd71837_regulators[] = {
494edd266   Matti Vaittinen   regulator/mfd: Su...
959
960
961
962
963
964
  	{
  		.desc = {
  			.name = "buck1",
  			.of_match = of_match_ptr("BUCK1"),
  			.regulators_node = of_match_ptr("regulators"),
  			.id = BD718XX_BUCK1,
494edd266   Matti Vaittinen   regulator/mfd: Su...
965
966
967
968
969
970
971
972
  			.type = REGULATOR_VOLTAGE,
  			.n_voltages = BD718XX_DVS_BUCK_VOLTAGE_NUM,
  			.linear_ranges = bd718xx_dvs_buck_volts,
  			.n_linear_ranges = ARRAY_SIZE(bd718xx_dvs_buck_volts),
  			.vsel_reg = BD718XX_REG_BUCK1_VOLT_RUN,
  			.vsel_mask = DVS_BUCK_RUN_MASK,
  			.enable_reg = BD718XX_REG_BUCK1_CTRL,
  			.enable_mask = BD718XX_BUCK_EN,
36afeaad7   Guido Günther   regulator: bd718x...
973
  			.enable_time = BD71837_BUCK1_STARTUP_TIME,
494edd266   Matti Vaittinen   regulator/mfd: Su...
974
  			.owner = THIS_MODULE,
21b72156e   Matti Vaittinen   regulator: bd718x...
975
976
977
978
979
980
981
982
983
984
985
  			.of_parse_cb = buck_set_hw_dvs_levels,
  		},
  		.dvs = {
  			.level_map = ROHM_DVS_LEVEL_RUN | ROHM_DVS_LEVEL_IDLE |
  				     ROHM_DVS_LEVEL_SUSPEND,
  			.run_reg = BD718XX_REG_BUCK1_VOLT_RUN,
  			.run_mask = DVS_BUCK_RUN_MASK,
  			.idle_reg = BD718XX_REG_BUCK1_VOLT_IDLE,
  			.idle_mask = DVS_BUCK_RUN_MASK,
  			.suspend_reg = BD718XX_REG_BUCK1_VOLT_SUSP,
  			.suspend_mask = DVS_BUCK_RUN_MASK,
494edd266   Matti Vaittinen   regulator/mfd: Su...
986
987
988
989
990
991
992
993
994
995
996
997
998
  		},
  		.init = {
  			.reg = BD718XX_REG_BUCK1_CTRL,
  			.mask = BD718XX_BUCK_SEL,
  			.val = BD718XX_BUCK_SEL,
  		},
  	},
  	{
  		.desc = {
  			.name = "buck2",
  			.of_match = of_match_ptr("BUCK2"),
  			.regulators_node = of_match_ptr("regulators"),
  			.id = BD718XX_BUCK2,
494edd266   Matti Vaittinen   regulator/mfd: Su...
999
1000
1001
1002
1003
1004
1005
1006
  			.type = REGULATOR_VOLTAGE,
  			.n_voltages = BD718XX_DVS_BUCK_VOLTAGE_NUM,
  			.linear_ranges = bd718xx_dvs_buck_volts,
  			.n_linear_ranges = ARRAY_SIZE(bd718xx_dvs_buck_volts),
  			.vsel_reg = BD718XX_REG_BUCK2_VOLT_RUN,
  			.vsel_mask = DVS_BUCK_RUN_MASK,
  			.enable_reg = BD718XX_REG_BUCK2_CTRL,
  			.enable_mask = BD718XX_BUCK_EN,
36afeaad7   Guido Günther   regulator: bd718x...
1007
  			.enable_time = BD71837_BUCK2_STARTUP_TIME,
494edd266   Matti Vaittinen   regulator/mfd: Su...
1008
  			.owner = THIS_MODULE,
21b72156e   Matti Vaittinen   regulator: bd718x...
1009
1010
1011
1012
1013
1014
1015
1016
  			.of_parse_cb = buck_set_hw_dvs_levels,
  		},
  		.dvs = {
  			.level_map = ROHM_DVS_LEVEL_RUN | ROHM_DVS_LEVEL_IDLE,
  			.run_reg = BD718XX_REG_BUCK2_VOLT_RUN,
  			.run_mask = DVS_BUCK_RUN_MASK,
  			.idle_reg = BD718XX_REG_BUCK2_VOLT_IDLE,
  			.idle_mask = DVS_BUCK_RUN_MASK,
494edd266   Matti Vaittinen   regulator/mfd: Su...
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
  		},
  		.init = {
  			.reg = BD718XX_REG_BUCK2_CTRL,
  			.mask = BD718XX_BUCK_SEL,
  			.val = BD718XX_BUCK_SEL,
  		},
  	},
  	{
  		.desc = {
  			.name = "buck3",
  			.of_match = of_match_ptr("BUCK3"),
  			.regulators_node = of_match_ptr("regulators"),
  			.id = BD718XX_BUCK3,
494edd266   Matti Vaittinen   regulator/mfd: Su...
1030
1031
1032
1033
1034
1035
1036
1037
  			.type = REGULATOR_VOLTAGE,
  			.n_voltages = BD718XX_DVS_BUCK_VOLTAGE_NUM,
  			.linear_ranges = bd718xx_dvs_buck_volts,
  			.n_linear_ranges = ARRAY_SIZE(bd718xx_dvs_buck_volts),
  			.vsel_reg = BD71837_REG_BUCK3_VOLT_RUN,
  			.vsel_mask = DVS_BUCK_RUN_MASK,
  			.enable_reg = BD71837_REG_BUCK3_CTRL,
  			.enable_mask = BD718XX_BUCK_EN,
36afeaad7   Guido Günther   regulator: bd718x...
1038
  			.enable_time = BD71837_BUCK3_STARTUP_TIME,
494edd266   Matti Vaittinen   regulator/mfd: Su...
1039
  			.owner = THIS_MODULE,
21b72156e   Matti Vaittinen   regulator: bd718x...
1040
1041
1042
1043
1044
1045
  			.of_parse_cb = buck_set_hw_dvs_levels,
  		},
  		.dvs = {
  			.level_map = ROHM_DVS_LEVEL_RUN,
  			.run_reg = BD71837_REG_BUCK3_VOLT_RUN,
  			.run_mask = DVS_BUCK_RUN_MASK,
494edd266   Matti Vaittinen   regulator/mfd: Su...
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
  		},
  		.init = {
  			.reg = BD71837_REG_BUCK3_CTRL,
  			.mask = BD718XX_BUCK_SEL,
  			.val = BD718XX_BUCK_SEL,
  		},
  	},
  	{
  		.desc = {
  			.name = "buck4",
  			.of_match = of_match_ptr("BUCK4"),
  			.regulators_node = of_match_ptr("regulators"),
  			.id = BD718XX_BUCK4,
494edd266   Matti Vaittinen   regulator/mfd: Su...
1059
1060
1061
1062
1063
1064
1065
1066
  			.type = REGULATOR_VOLTAGE,
  			.n_voltages = BD718XX_DVS_BUCK_VOLTAGE_NUM,
  			.linear_ranges = bd718xx_dvs_buck_volts,
  			.n_linear_ranges = ARRAY_SIZE(bd718xx_dvs_buck_volts),
  			.vsel_reg = BD71837_REG_BUCK4_VOLT_RUN,
  			.vsel_mask = DVS_BUCK_RUN_MASK,
  			.enable_reg = BD71837_REG_BUCK4_CTRL,
  			.enable_mask = BD718XX_BUCK_EN,
36afeaad7   Guido Günther   regulator: bd718x...
1067
  			.enable_time = BD71837_BUCK4_STARTUP_TIME,
494edd266   Matti Vaittinen   regulator/mfd: Su...
1068
  			.owner = THIS_MODULE,
21b72156e   Matti Vaittinen   regulator: bd718x...
1069
1070
1071
1072
1073
1074
  			.of_parse_cb = buck_set_hw_dvs_levels,
  		},
  		.dvs = {
  			.level_map = ROHM_DVS_LEVEL_RUN,
  			.run_reg = BD71837_REG_BUCK4_VOLT_RUN,
  			.run_mask = DVS_BUCK_RUN_MASK,
494edd266   Matti Vaittinen   regulator/mfd: Su...
1075
1076
1077
1078
1079
1080
  		},
  		.init = {
  			.reg = BD71837_REG_BUCK4_CTRL,
  			.mask = BD718XX_BUCK_SEL,
  			.val = BD718XX_BUCK_SEL,
  		},
ba08799e9   Matti Vaittinen   regulator: bd7183...
1081
1082
  	},
  	{
494edd266   Matti Vaittinen   regulator/mfd: Su...
1083
1084
1085
1086
1087
  		.desc = {
  			.name = "buck5",
  			.of_match = of_match_ptr("BUCK5"),
  			.regulators_node = of_match_ptr("regulators"),
  			.id = BD718XX_BUCK5,
494edd266   Matti Vaittinen   regulator/mfd: Su...
1088
  			.type = REGULATOR_VOLTAGE,
a4bfc2c28   Matti Vaittinen   regulator: bd718X...
1089
1090
  			.n_voltages = BD71837_BUCK5_VOLTAGE_NUM,
  			.linear_ranges = bd71837_buck5_volts,
494edd266   Matti Vaittinen   regulator/mfd: Su...
1091
  			.n_linear_ranges =
a4bfc2c28   Matti Vaittinen   regulator: bd718X...
1092
  				ARRAY_SIZE(bd71837_buck5_volts),
494edd266   Matti Vaittinen   regulator/mfd: Su...
1093
  			.vsel_reg = BD718XX_REG_1ST_NODVS_BUCK_VOLT,
a4bfc2c28   Matti Vaittinen   regulator: bd718X...
1094
1095
1096
1097
  			.vsel_mask = BD71837_BUCK5_MASK,
  			.vsel_range_reg = BD718XX_REG_1ST_NODVS_BUCK_VOLT,
  			.vsel_range_mask = BD71837_BUCK5_RANGE_MASK,
  			.linear_range_selectors = bd71837_buck5_volt_range_sel,
494edd266   Matti Vaittinen   regulator/mfd: Su...
1098
1099
  			.enable_reg = BD718XX_REG_1ST_NODVS_BUCK_CTRL,
  			.enable_mask = BD718XX_BUCK_EN,
36afeaad7   Guido Günther   regulator: bd718x...
1100
  			.enable_time = BD71837_BUCK5_STARTUP_TIME,
494edd266   Matti Vaittinen   regulator/mfd: Su...
1101
1102
1103
1104
1105
1106
1107
  			.owner = THIS_MODULE,
  		},
  		.init = {
  			.reg = BD718XX_REG_1ST_NODVS_BUCK_CTRL,
  			.mask = BD718XX_BUCK_SEL,
  			.val = BD718XX_BUCK_SEL,
  		},
ba08799e9   Matti Vaittinen   regulator: bd7183...
1108
1109
  	},
  	{
494edd266   Matti Vaittinen   regulator/mfd: Su...
1110
1111
1112
1113
1114
  		.desc = {
  			.name = "buck6",
  			.of_match = of_match_ptr("BUCK6"),
  			.regulators_node = of_match_ptr("regulators"),
  			.id = BD718XX_BUCK6,
494edd266   Matti Vaittinen   regulator/mfd: Su...
1115
1116
  			.type = REGULATOR_VOLTAGE,
  			.n_voltages = BD71837_BUCK6_VOLTAGE_NUM,
a4bfc2c28   Matti Vaittinen   regulator: bd718X...
1117
  			.linear_ranges = bd71837_buck6_volts,
494edd266   Matti Vaittinen   regulator/mfd: Su...
1118
  			.n_linear_ranges =
a4bfc2c28   Matti Vaittinen   regulator: bd718X...
1119
  				ARRAY_SIZE(bd71837_buck6_volts),
494edd266   Matti Vaittinen   regulator/mfd: Su...
1120
1121
1122
1123
  			.vsel_reg = BD718XX_REG_2ND_NODVS_BUCK_VOLT,
  			.vsel_mask = BD71837_BUCK6_MASK,
  			.enable_reg = BD718XX_REG_2ND_NODVS_BUCK_CTRL,
  			.enable_mask = BD718XX_BUCK_EN,
36afeaad7   Guido Günther   regulator: bd718x...
1124
  			.enable_time = BD71837_BUCK6_STARTUP_TIME,
494edd266   Matti Vaittinen   regulator/mfd: Su...
1125
1126
1127
1128
1129
1130
1131
  			.owner = THIS_MODULE,
  		},
  		.init = {
  			.reg = BD718XX_REG_2ND_NODVS_BUCK_CTRL,
  			.mask = BD718XX_BUCK_SEL,
  			.val = BD718XX_BUCK_SEL,
  		},
ba08799e9   Matti Vaittinen   regulator: bd7183...
1132
1133
  	},
  	{
494edd266   Matti Vaittinen   regulator/mfd: Su...
1134
1135
1136
1137
1138
  		.desc = {
  			.name = "buck7",
  			.of_match = of_match_ptr("BUCK7"),
  			.regulators_node = of_match_ptr("regulators"),
  			.id = BD718XX_BUCK7,
494edd266   Matti Vaittinen   regulator/mfd: Su...
1139
1140
1141
1142
1143
1144
1145
  			.type = REGULATOR_VOLTAGE,
  			.volt_table = &bd718xx_3rd_nodvs_buck_volts[0],
  			.n_voltages = ARRAY_SIZE(bd718xx_3rd_nodvs_buck_volts),
  			.vsel_reg = BD718XX_REG_3RD_NODVS_BUCK_VOLT,
  			.vsel_mask = BD718XX_3RD_NODVS_BUCK_MASK,
  			.enable_reg = BD718XX_REG_3RD_NODVS_BUCK_CTRL,
  			.enable_mask = BD718XX_BUCK_EN,
36afeaad7   Guido Günther   regulator: bd718x...
1146
  			.enable_time = BD71837_BUCK7_STARTUP_TIME,
494edd266   Matti Vaittinen   regulator/mfd: Su...
1147
1148
1149
1150
1151
1152
1153
  			.owner = THIS_MODULE,
  		},
  		.init = {
  			.reg = BD718XX_REG_3RD_NODVS_BUCK_CTRL,
  			.mask = BD718XX_BUCK_SEL,
  			.val = BD718XX_BUCK_SEL,
  		},
ba08799e9   Matti Vaittinen   regulator: bd7183...
1154
1155
  	},
  	{
494edd266   Matti Vaittinen   regulator/mfd: Su...
1156
1157
1158
1159
1160
  		.desc = {
  			.name = "buck8",
  			.of_match = of_match_ptr("BUCK8"),
  			.regulators_node = of_match_ptr("regulators"),
  			.id = BD718XX_BUCK8,
494edd266   Matti Vaittinen   regulator/mfd: Su...
1161
  			.type = REGULATOR_VOLTAGE,
dd2be639f   Matti Vaittinen   regulator/mfd: bd...
1162
  			.n_voltages = BD718XX_4TH_NODVS_BUCK_VOLTAGE_NUM,
494edd266   Matti Vaittinen   regulator/mfd: Su...
1163
1164
1165
1166
1167
1168
1169
  			.linear_ranges = bd718xx_4th_nodvs_buck_volts,
  			.n_linear_ranges =
  				ARRAY_SIZE(bd718xx_4th_nodvs_buck_volts),
  			.vsel_reg = BD718XX_REG_4TH_NODVS_BUCK_VOLT,
  			.vsel_mask = BD718XX_4TH_NODVS_BUCK_MASK,
  			.enable_reg = BD718XX_REG_4TH_NODVS_BUCK_CTRL,
  			.enable_mask = BD718XX_BUCK_EN,
36afeaad7   Guido Günther   regulator: bd718x...
1170
  			.enable_time = BD71837_BUCK8_STARTUP_TIME,
494edd266   Matti Vaittinen   regulator/mfd: Su...
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
  			.owner = THIS_MODULE,
  		},
  		.init = {
  			.reg = BD718XX_REG_4TH_NODVS_BUCK_CTRL,
  			.mask = BD718XX_BUCK_SEL,
  			.val = BD718XX_BUCK_SEL,
  		},
  	},
  	{
  		.desc = {
  			.name = "ldo1",
  			.of_match = of_match_ptr("LDO1"),
  			.regulators_node = of_match_ptr("regulators"),
  			.id = BD718XX_LDO1,
494edd266   Matti Vaittinen   regulator/mfd: Su...
1185
1186
1187
1188
1189
1190
  			.type = REGULATOR_VOLTAGE,
  			.n_voltages = BD718XX_LDO1_VOLTAGE_NUM,
  			.linear_ranges = bd718xx_ldo1_volts,
  			.n_linear_ranges = ARRAY_SIZE(bd718xx_ldo1_volts),
  			.vsel_reg = BD718XX_REG_LDO1_VOLT,
  			.vsel_mask = BD718XX_LDO1_MASK,
a4bfc2c28   Matti Vaittinen   regulator: bd718X...
1191
1192
1193
  			.vsel_range_reg = BD718XX_REG_LDO1_VOLT,
  			.vsel_range_mask = BD718XX_LDO1_RANGE_MASK,
  			.linear_range_selectors = bd718xx_ldo1_volt_range_sel,
494edd266   Matti Vaittinen   regulator/mfd: Su...
1194
1195
  			.enable_reg = BD718XX_REG_LDO1_VOLT,
  			.enable_mask = BD718XX_LDO_EN,
36afeaad7   Guido Günther   regulator: bd718x...
1196
  			.enable_time = BD71837_LDO1_STARTUP_TIME,
494edd266   Matti Vaittinen   regulator/mfd: Su...
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
  			.owner = THIS_MODULE,
  		},
  		.init = {
  			.reg = BD718XX_REG_LDO1_VOLT,
  			.mask = BD718XX_LDO_SEL,
  			.val = BD718XX_LDO_SEL,
  		},
  	},
  	{
  		.desc = {
  			.name = "ldo2",
  			.of_match = of_match_ptr("LDO2"),
  			.regulators_node = of_match_ptr("regulators"),
  			.id = BD718XX_LDO2,
494edd266   Matti Vaittinen   regulator/mfd: Su...
1211
1212
1213
1214
1215
1216
1217
  			.type = REGULATOR_VOLTAGE,
  			.volt_table = &ldo_2_volts[0],
  			.vsel_reg = BD718XX_REG_LDO2_VOLT,
  			.vsel_mask = BD718XX_LDO2_MASK,
  			.n_voltages = ARRAY_SIZE(ldo_2_volts),
  			.enable_reg = BD718XX_REG_LDO2_VOLT,
  			.enable_mask = BD718XX_LDO_EN,
36afeaad7   Guido Günther   regulator: bd718x...
1218
  			.enable_time = BD71837_LDO2_STARTUP_TIME,
494edd266   Matti Vaittinen   regulator/mfd: Su...
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
  			.owner = THIS_MODULE,
  		},
  		.init = {
  			.reg = BD718XX_REG_LDO2_VOLT,
  			.mask = BD718XX_LDO_SEL,
  			.val = BD718XX_LDO_SEL,
  		},
  	},
  	{
  		.desc = {
  			.name = "ldo3",
  			.of_match = of_match_ptr("LDO3"),
  			.regulators_node = of_match_ptr("regulators"),
  			.id = BD718XX_LDO3,
494edd266   Matti Vaittinen   regulator/mfd: Su...
1233
1234
1235
1236
1237
1238
1239
1240
  			.type = REGULATOR_VOLTAGE,
  			.n_voltages = BD718XX_LDO3_VOLTAGE_NUM,
  			.linear_ranges = bd718xx_ldo3_volts,
  			.n_linear_ranges = ARRAY_SIZE(bd718xx_ldo3_volts),
  			.vsel_reg = BD718XX_REG_LDO3_VOLT,
  			.vsel_mask = BD718XX_LDO3_MASK,
  			.enable_reg = BD718XX_REG_LDO3_VOLT,
  			.enable_mask = BD718XX_LDO_EN,
36afeaad7   Guido Günther   regulator: bd718x...
1241
  			.enable_time = BD71837_LDO3_STARTUP_TIME,
494edd266   Matti Vaittinen   regulator/mfd: Su...
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
  			.owner = THIS_MODULE,
  		},
  		.init = {
  			.reg = BD718XX_REG_LDO3_VOLT,
  			.mask = BD718XX_LDO_SEL,
  			.val = BD718XX_LDO_SEL,
  		},
  	},
  	{
  		.desc = {
  			.name = "ldo4",
  			.of_match = of_match_ptr("LDO4"),
  			.regulators_node = of_match_ptr("regulators"),
  			.id = BD718XX_LDO4,
494edd266   Matti Vaittinen   regulator/mfd: Su...
1256
1257
1258
1259
1260
1261
1262
1263
  			.type = REGULATOR_VOLTAGE,
  			.n_voltages = BD718XX_LDO4_VOLTAGE_NUM,
  			.linear_ranges = bd718xx_ldo4_volts,
  			.n_linear_ranges = ARRAY_SIZE(bd718xx_ldo4_volts),
  			.vsel_reg = BD718XX_REG_LDO4_VOLT,
  			.vsel_mask = BD718XX_LDO4_MASK,
  			.enable_reg = BD718XX_REG_LDO4_VOLT,
  			.enable_mask = BD718XX_LDO_EN,
36afeaad7   Guido Günther   regulator: bd718x...
1264
  			.enable_time = BD71837_LDO4_STARTUP_TIME,
494edd266   Matti Vaittinen   regulator/mfd: Su...
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
  			.owner = THIS_MODULE,
  		},
  		.init = {
  			.reg = BD718XX_REG_LDO4_VOLT,
  			.mask = BD718XX_LDO_SEL,
  			.val = BD718XX_LDO_SEL,
  		},
  	},
  	{
  		.desc = {
  			.name = "ldo5",
  			.of_match = of_match_ptr("LDO5"),
  			.regulators_node = of_match_ptr("regulators"),
  			.id = BD718XX_LDO5,
494edd266   Matti Vaittinen   regulator/mfd: Su...
1279
  			.type = REGULATOR_VOLTAGE,
a4bfc2c28   Matti Vaittinen   regulator: bd718X...
1280
1281
1282
  			.n_voltages = BD71837_LDO5_VOLTAGE_NUM,
  			.linear_ranges = bd71837_ldo5_volts,
  			.n_linear_ranges = ARRAY_SIZE(bd71837_ldo5_volts),
494edd266   Matti Vaittinen   regulator/mfd: Su...
1283
1284
1285
1286
1287
1288
  			/* LDO5 is supplied by buck6 */
  			.supply_name = "buck6",
  			.vsel_reg = BD718XX_REG_LDO5_VOLT,
  			.vsel_mask = BD71837_LDO5_MASK,
  			.enable_reg = BD718XX_REG_LDO5_VOLT,
  			.enable_mask = BD718XX_LDO_EN,
36afeaad7   Guido Günther   regulator: bd718x...
1289
  			.enable_time = BD71837_LDO5_STARTUP_TIME,
494edd266   Matti Vaittinen   regulator/mfd: Su...
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
  			.owner = THIS_MODULE,
  		},
  		.init = {
  			.reg = BD718XX_REG_LDO5_VOLT,
  			.mask = BD718XX_LDO_SEL,
  			.val = BD718XX_LDO_SEL,
  		},
  		.additional_inits = bd71837_ldo5_inits,
  		.additional_init_amnt = ARRAY_SIZE(bd71837_ldo5_inits),
  	},
  	{
  		.desc = {
  			.name = "ldo6",
  			.of_match = of_match_ptr("LDO6"),
  			.regulators_node = of_match_ptr("regulators"),
  			.id = BD718XX_LDO6,
494edd266   Matti Vaittinen   regulator/mfd: Su...
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
  			.type = REGULATOR_VOLTAGE,
  			.n_voltages = BD718XX_LDO6_VOLTAGE_NUM,
  			.linear_ranges = bd718xx_ldo6_volts,
  			.n_linear_ranges = ARRAY_SIZE(bd718xx_ldo6_volts),
  			/* LDO6 is supplied by buck7 */
  			.supply_name = "buck7",
  			.vsel_reg = BD718XX_REG_LDO6_VOLT,
  			.vsel_mask = BD718XX_LDO6_MASK,
  			.enable_reg = BD718XX_REG_LDO6_VOLT,
  			.enable_mask = BD718XX_LDO_EN,
36afeaad7   Guido Günther   regulator: bd718x...
1316
  			.enable_time = BD71837_LDO6_STARTUP_TIME,
494edd266   Matti Vaittinen   regulator/mfd: Su...
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
  			.owner = THIS_MODULE,
  		},
  		.init = {
  			.reg = BD718XX_REG_LDO6_VOLT,
  			.mask = BD718XX_LDO_SEL,
  			.val = BD718XX_LDO_SEL,
  		},
  		.additional_inits = bd71837_ldo6_inits,
  		.additional_init_amnt = ARRAY_SIZE(bd71837_ldo6_inits),
  	},
  	{
  		.desc = {
  			.name = "ldo7",
  			.of_match = of_match_ptr("LDO7"),
  			.regulators_node = of_match_ptr("regulators"),
  			.id = BD718XX_LDO7,
494edd266   Matti Vaittinen   regulator/mfd: Su...
1333
1334
1335
1336
1337
1338
1339
1340
  			.type = REGULATOR_VOLTAGE,
  			.n_voltages = BD71837_LDO7_VOLTAGE_NUM,
  			.linear_ranges = bd71837_ldo7_volts,
  			.n_linear_ranges = ARRAY_SIZE(bd71837_ldo7_volts),
  			.vsel_reg = BD71837_REG_LDO7_VOLT,
  			.vsel_mask = BD71837_LDO7_MASK,
  			.enable_reg = BD71837_REG_LDO7_VOLT,
  			.enable_mask = BD718XX_LDO_EN,
36afeaad7   Guido Günther   regulator: bd718x...
1341
  			.enable_time = BD71837_LDO7_STARTUP_TIME,
494edd266   Matti Vaittinen   regulator/mfd: Su...
1342
1343
1344
1345
1346
1347
1348
  			.owner = THIS_MODULE,
  		},
  		.init = {
  			.reg = BD71837_REG_LDO7_VOLT,
  			.mask = BD718XX_LDO_SEL,
  			.val = BD718XX_LDO_SEL,
  		},
ba08799e9   Matti Vaittinen   regulator: bd7183...
1349
1350
  	},
  };
1d848d681   Matti Vaittinen   regulator: bd718x...
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
  static void mark_hw_controlled(struct device *dev, struct device_node *np,
  			       struct bd718xx_regulator_data *reg_data,
  			       unsigned int num_reg_data, int *info)
  {
  	int i;
  
  	for (i = 1; i <= num_reg_data; i++) {
  		if (!of_node_name_eq(np, reg_data[i-1].desc.of_match))
  			continue;
  
  		*info |= 1 << (i - 1);
  		dev_dbg(dev, "regulator %d runlevel controlled
  ", i);
  		return;
  	}
  	dev_warn(dev, "Bad regulator node
  ");
  }
  
  static int get_hw_controlled_regulators(struct device *dev,
  					struct bd718xx_regulator_data *reg_data,
  					unsigned int num_reg_data, int *info)
  {
  	struct device_node *np;
  	struct device_node *nproot = dev->of_node;
  	const char *prop = "rohm,no-regulator-enable-control";
  
  	*info = 0;
  
  	nproot = of_get_child_by_name(nproot, "regulators");
  	if (!nproot) {
  		dev_err(dev, "failed to find regulators node
  ");
  		return -ENODEV;
  	}
  	for_each_child_of_node(nproot, np)
  		if (of_property_read_bool(np, prop))
  			mark_hw_controlled(dev, np, reg_data, num_reg_data,
  					   info);
  
  	of_node_put(nproot);
  	return 0;
  }
dd2be639f   Matti Vaittinen   regulator/mfd: bd...
1394
  static int bd718xx_probe(struct platform_device *pdev)
ba08799e9   Matti Vaittinen   regulator: bd7183...
1395
  {
bcb047ebf   Axel Lin   regulator: bd718x...
1396
  	struct bd718xx *mfd;
ba08799e9   Matti Vaittinen   regulator: bd7183...
1397
  	struct regulator_config config = { 0 };
1d848d681   Matti Vaittinen   regulator: bd718x...
1398
  	int i, j, err, omit_enable;
049369d46   Matti Vaittinen   regulator: bd718x...
1399
  	bool use_snvs;
1d848d681   Matti Vaittinen   regulator: bd718x...
1400
  	struct bd718xx_regulator_data *reg_data;
b389ceae4   Axel Lin   regulator: bd718x...
1401
  	unsigned int num_reg_data;
1b1c26b24   Matti Vaittinen   mfd: Rohm PMICs: ...
1402
  	enum rohm_chip_type chip = platform_get_device_id(pdev)->driver_data;
1d848d681   Matti Vaittinen   regulator: bd718x...
1403
  	const struct regulator_ops **swops, **hwops;
ba08799e9   Matti Vaittinen   regulator: bd7183...
1404

bcb047ebf   Axel Lin   regulator: bd718x...
1405
1406
  	mfd = dev_get_drvdata(pdev->dev.parent);
  	if (!mfd) {
ba08799e9   Matti Vaittinen   regulator: bd7183...
1407
1408
1409
1410
1411
  		dev_err(&pdev->dev, "No MFD driver data
  ");
  		err = -EINVAL;
  		goto err;
  	}
bcb047ebf   Axel Lin   regulator: bd718x...
1412

af32f3a41   Linus Torvalds   Merge tag 'mfd-ne...
1413
  	switch (chip) {
b389ceae4   Axel Lin   regulator: bd718x...
1414
1415
1416
  	case ROHM_CHIP_TYPE_BD71837:
  		reg_data = bd71837_regulators;
  		num_reg_data = ARRAY_SIZE(bd71837_regulators);
1d848d681   Matti Vaittinen   regulator: bd718x...
1417
1418
  		swops = &bd71837_swcontrol_ops[0];
  		hwops = &bd71837_hwcontrol_ops[0];
b389ceae4   Axel Lin   regulator: bd718x...
1419
1420
1421
1422
  		break;
  	case ROHM_CHIP_TYPE_BD71847:
  		reg_data = bd71847_regulators;
  		num_reg_data = ARRAY_SIZE(bd71847_regulators);
1d848d681   Matti Vaittinen   regulator: bd718x...
1423
1424
  		swops = &bd71847_swcontrol_ops[0];
  		hwops = &bd71847_hwcontrol_ops[0];
b389ceae4   Axel Lin   regulator: bd718x...
1425
1426
  		break;
  	default:
494edd266   Matti Vaittinen   regulator/mfd: Su...
1427
1428
1429
1430
1431
  		dev_err(&pdev->dev, "Unsupported chip type
  ");
  		err = -EINVAL;
  		goto err;
  	}
ba08799e9   Matti Vaittinen   regulator: bd7183...
1432
  	/* Register LOCK release */
2a6a7aacd   Matti Vaittinen   mfd: regulator: c...
1433
  	err = regmap_update_bits(mfd->chip.regmap, BD718XX_REG_REGLOCK,
ba08799e9   Matti Vaittinen   regulator: bd7183...
1434
1435
  				 (REGLOCK_PWRSEQ | REGLOCK_VREG), 0);
  	if (err) {
bcb047ebf   Axel Lin   regulator: bd718x...
1436
1437
  		dev_err(&pdev->dev, "Failed to unlock PMIC (%d)
  ", err);
ba08799e9   Matti Vaittinen   regulator: bd7183...
1438
1439
  		goto err;
  	} else {
bcb047ebf   Axel Lin   regulator: bd718x...
1440
1441
  		dev_dbg(&pdev->dev, "Unlocked lock register 0x%x
  ",
494edd266   Matti Vaittinen   regulator/mfd: Su...
1442
  			BD718XX_REG_REGLOCK);
823f18f8b   Matti Vaittinen   regulator: bd7183...
1443
  	}
049369d46   Matti Vaittinen   regulator: bd718x...
1444
1445
1446
1447
  	use_snvs = of_property_read_bool(pdev->dev.parent->of_node,
  					 "rohm,reset-snvs-powered");
  
  	/*
e770b18bb   Matti Vaittinen   regulator: bd718x...
1448
1449
1450
1451
  	 * Change the next stage from poweroff to be READY instead of SNVS
  	 * for all reset types because OTP loading at READY will clear SEL
  	 * bit allowing HW defaults for power rails to be used
  	 */
049369d46   Matti Vaittinen   regulator: bd718x...
1452
  	if (!use_snvs) {
2a6a7aacd   Matti Vaittinen   mfd: regulator: c...
1453
1454
  		err = regmap_update_bits(mfd->chip.regmap,
  					 BD718XX_REG_TRANS_COND1,
049369d46   Matti Vaittinen   regulator: bd718x...
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
  					 BD718XX_ON_REQ_POWEROFF_MASK |
  					 BD718XX_SWRESET_POWEROFF_MASK |
  					 BD718XX_WDOG_POWEROFF_MASK |
  					 BD718XX_KEY_L_POWEROFF_MASK,
  					 BD718XX_POWOFF_TO_RDY);
  		if (err) {
  			dev_err(&pdev->dev, "Failed to change reset target
  ");
  			goto err;
  		} else {
  			dev_dbg(&pdev->dev,
  				"Changed all resets from SVNS to READY
  ");
  		}
e770b18bb   Matti Vaittinen   regulator: bd718x...
1469
  	}
df9db2541   Matti Vaittinen   regulator: bd718x...
1470
1471
  	config.dev = pdev->dev.parent;
  	config.regmap = mfd->chip.regmap;
1d848d681   Matti Vaittinen   regulator: bd718x...
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
  	/*
  	 * There are cases when we want to leave the enable-control for
  	 * the HW state machine and use this driver only for voltage control.
  	 * One special case is when we use PMIC_STBY_REQ line from SoC to PMIC
  	 * in order to set the system to SUSPEND state.
  	 *
  	 * If regulator is taken under SW control the regulator state will not
  	 * be affected by PMIC state machine - Eg. regulator is likely to stay
  	 * on even in SUSPEND
  	 */
  	get_hw_controlled_regulators(pdev->dev.parent, reg_data, num_reg_data,
  				     &omit_enable);
df9db2541   Matti Vaittinen   regulator: bd718x...
1484

b389ceae4   Axel Lin   regulator: bd718x...
1485
  	for (i = 0; i < num_reg_data; i++) {
ba08799e9   Matti Vaittinen   regulator: bd7183...
1486

1d848d681   Matti Vaittinen   regulator: bd718x...
1487
  		struct regulator_desc *desc;
ba08799e9   Matti Vaittinen   regulator: bd7183...
1488
  		struct regulator_dev *rdev;
1d848d681   Matti Vaittinen   regulator: bd718x...
1489
1490
  		struct bd718xx_regulator_data *r;
  		int no_enable_control = omit_enable & (1 << i);
ba08799e9   Matti Vaittinen   regulator: bd7183...
1491

b389ceae4   Axel Lin   regulator: bd718x...
1492
  		r = &reg_data[i];
494edd266   Matti Vaittinen   regulator/mfd: Su...
1493
  		desc = &r->desc;
ba08799e9   Matti Vaittinen   regulator: bd7183...
1494

1d848d681   Matti Vaittinen   regulator: bd718x...
1495
1496
1497
1498
  		if (no_enable_control)
  			desc->ops = hwops[i];
  		else
  			desc->ops = swops[i];
ba08799e9   Matti Vaittinen   regulator: bd7183...
1499
1500
1501
  
  		rdev = devm_regulator_register(&pdev->dev, desc, &config);
  		if (IS_ERR(rdev)) {
bcb047ebf   Axel Lin   regulator: bd718x...
1502
  			dev_err(&pdev->dev,
ba08799e9   Matti Vaittinen   regulator: bd7183...
1503
1504
1505
1506
1507
1508
  				"failed to register %s regulator
  ",
  				desc->name);
  			err = PTR_ERR(rdev);
  			goto err;
  		}
049369d46   Matti Vaittinen   regulator: bd718x...
1509
1510
1511
  
  		/*
  		 * Regulator register gets the regulator constraints and
ba08799e9   Matti Vaittinen   regulator: bd7183...
1512
1513
1514
1515
  		 * applies them (set_machine_constraints). This should have
  		 * turned the control register(s) to correct values and we
  		 * can now switch the control from PMIC state machine to the
  		 * register interface
049369d46   Matti Vaittinen   regulator: bd718x...
1516
1517
1518
1519
1520
1521
1522
1523
1524
  		 *
  		 * At poweroff transition PMIC HW disables EN bit for
  		 * regulators but leaves SEL bit untouched. So if state
  		 * transition from POWEROFF is done to SNVS - then all power
  		 * rails controlled by SW (having SEL bit set) stay disabled
  		 * as EN is cleared. This will result boot failure if any
  		 * crucial systems are powered by these rails. We don't
  		 * enable SW control for crucial regulators if snvs state is
  		 * used
ba08799e9   Matti Vaittinen   regulator: bd7183...
1525
  		 */
1d848d681   Matti Vaittinen   regulator: bd718x...
1526
1527
1528
  		if (!no_enable_control && (!use_snvs ||
  		    !rdev->constraints->always_on ||
  		    !rdev->constraints->boot_on)) {
2a6a7aacd   Matti Vaittinen   mfd: regulator: c...
1529
  			err = regmap_update_bits(mfd->chip.regmap, r->init.reg,
049369d46   Matti Vaittinen   regulator: bd718x...
1530
1531
1532
1533
1534
1535
1536
1537
  						 r->init.mask, r->init.val);
  			if (err) {
  				dev_err(&pdev->dev,
  					"Failed to take control for (%s)
  ",
  					desc->name);
  				goto err;
  			}
ba08799e9   Matti Vaittinen   regulator: bd7183...
1538
  		}
494edd266   Matti Vaittinen   regulator/mfd: Su...
1539
  		for (j = 0; j < r->additional_init_amnt; j++) {
2a6a7aacd   Matti Vaittinen   mfd: regulator: c...
1540
  			err = regmap_update_bits(mfd->chip.regmap,
494edd266   Matti Vaittinen   regulator/mfd: Su...
1541
1542
1543
1544
  						 r->additional_inits[j].reg,
  						 r->additional_inits[j].mask,
  						 r->additional_inits[j].val);
  			if (err) {
bcb047ebf   Axel Lin   regulator: bd718x...
1545
  				dev_err(&pdev->dev,
494edd266   Matti Vaittinen   regulator/mfd: Su...
1546
1547
1548
1549
1550
1551
  					"Buck (%s) initialization failed
  ",
  					desc->name);
  				goto err;
  			}
  		}
ba08799e9   Matti Vaittinen   regulator: bd7183...
1552
  	}
ba08799e9   Matti Vaittinen   regulator: bd7183...
1553
1554
1555
  err:
  	return err;
  }
1b1c26b24   Matti Vaittinen   mfd: Rohm PMICs: ...
1556
1557
1558
1559
1560
1561
  static const struct platform_device_id bd718x7_pmic_id[] = {
  	{ "bd71837-pmic", ROHM_CHIP_TYPE_BD71837 },
  	{ "bd71847-pmic", ROHM_CHIP_TYPE_BD71847 },
  	{ },
  };
  MODULE_DEVICE_TABLE(platform, bd718x7_pmic_id);
dd2be639f   Matti Vaittinen   regulator/mfd: bd...
1562
  static struct platform_driver bd718xx_regulator = {
ba08799e9   Matti Vaittinen   regulator: bd7183...
1563
  	.driver = {
494edd266   Matti Vaittinen   regulator/mfd: Su...
1564
  		.name = "bd718xx-pmic",
ba08799e9   Matti Vaittinen   regulator: bd7183...
1565
  	},
dd2be639f   Matti Vaittinen   regulator/mfd: bd...
1566
  	.probe = bd718xx_probe,
1b1c26b24   Matti Vaittinen   mfd: Rohm PMICs: ...
1567
  	.id_table = bd718x7_pmic_id,
ba08799e9   Matti Vaittinen   regulator: bd7183...
1568
  };
dd2be639f   Matti Vaittinen   regulator/mfd: bd...
1569
  module_platform_driver(bd718xx_regulator);
ba08799e9   Matti Vaittinen   regulator: bd7183...
1570
1571
  
  MODULE_AUTHOR("Matti Vaittinen <matti.vaittinen@fi.rohmeurope.com>");
dd2be639f   Matti Vaittinen   regulator/mfd: bd...
1572
  MODULE_DESCRIPTION("BD71837/BD71847 voltage regulator driver");
ba08799e9   Matti Vaittinen   regulator: bd7183...
1573
  MODULE_LICENSE("GPL");
95bddd8bb   Guido Günther   regulator: bd718x...
1574
  MODULE_ALIAS("platform:bd718xx-pmic");