1 // SPDX-License-Identifier: GPL-2.0-only
3 * max8973-regulator.c -- Maxim max8973A
5 * Regulator driver for MAXIM 8973A DC-DC step-down switching regulator.
7 * Copyright (c) 2012, NVIDIA Corporation.
9 * Author: Laxman Dewangan <ldewangan@nvidia.com>
12 #include <linux/kernel.h>
13 #include <linux/module.h>
14 #include <linux/init.h>
15 #include <linux/err.h>
17 #include <linux/of_device.h>
18 #include <linux/platform_device.h>
19 #include <linux/regulator/driver.h>
20 #include <linux/regulator/machine.h>
21 #include <linux/regulator/max8973-regulator.h>
22 #include <linux/regulator/of_regulator.h>
23 #include <linux/gpio/consumer.h>
24 #include <linux/i2c.h>
25 #include <linux/slab.h>
26 #include <linux/regmap.h>
27 #include <linux/thermal.h>
28 #include <linux/irq.h>
29 #include <linux/interrupt.h>
31 /* Register definitions */
32 #define MAX8973_VOUT 0x0
33 #define MAX8973_VOUT_DVS 0x1
34 #define MAX8973_CONTROL1 0x2
35 #define MAX8973_CONTROL2 0x3
36 #define MAX8973_CHIPID1 0x4
37 #define MAX8973_CHIPID2 0x5
39 #define MAX8973_MAX_VOUT_REG 2
42 #define MAX8973_VOUT_ENABLE BIT(7)
43 #define MAX8973_VOUT_MASK 0x7F
45 /* MAX8973_VOUT_DVS */
46 #define MAX8973_DVS_VOUT_MASK 0x7F
48 /* MAX8973_CONTROL1 */
49 #define MAX8973_SNS_ENABLE BIT(7)
50 #define MAX8973_FPWM_EN_M BIT(6)
51 #define MAX8973_NFSR_ENABLE BIT(5)
52 #define MAX8973_AD_ENABLE BIT(4)
53 #define MAX8973_BIAS_ENABLE BIT(3)
54 #define MAX8973_FREQSHIFT_9PER BIT(2)
56 #define MAX8973_RAMP_12mV_PER_US 0x0
57 #define MAX8973_RAMP_25mV_PER_US 0x1
58 #define MAX8973_RAMP_50mV_PER_US 0x2
59 #define MAX8973_RAMP_200mV_PER_US 0x3
60 #define MAX8973_RAMP_MASK 0x3
62 /* MAX8973_CONTROL2 */
63 #define MAX8973_WDTMR_ENABLE BIT(6)
64 #define MAX8973_DISCH_ENBABLE BIT(5)
65 #define MAX8973_FT_ENABLE BIT(4)
66 #define MAX77621_T_JUNCTION_120 BIT(7)
68 #define MAX8973_CKKADV_TRIP_MASK 0xC
69 #define MAX8973_CKKADV_TRIP_DISABLE 0xC
70 #define MAX8973_CKKADV_TRIP_75mV_PER_US 0x0
71 #define MAX8973_CKKADV_TRIP_150mV_PER_US 0x4
72 #define MAX8973_CKKADV_TRIP_75mV_PER_US_HIST_DIS 0x8
73 #define MAX8973_CONTROL_CLKADV_TRIP_MASK 0x00030000
75 #define MAX8973_INDUCTOR_MIN_30_PER 0x0
76 #define MAX8973_INDUCTOR_NOMINAL 0x1
77 #define MAX8973_INDUCTOR_PLUS_30_PER 0x2
78 #define MAX8973_INDUCTOR_PLUS_60_PER 0x3
79 #define MAX8973_CONTROL_INDUCTOR_VALUE_MASK 0x00300000
81 #define MAX8973_MIN_VOLATGE 606250
82 #define MAX8973_MAX_VOLATGE 1400000
83 #define MAX8973_VOLATGE_STEP 6250
84 #define MAX8973_BUCK_N_VOLTAGE 0x80
86 #define MAX77621_CHIPID_TJINT_S BIT(0)
88 #define MAX77621_NORMAL_OPERATING_TEMP 100000
89 #define MAX77621_TJINT_WARNING_TEMP_120 120000
90 #define MAX77621_TJINT_WARNING_TEMP_140 140000
97 /* Maxim 8973 chip information */
100 struct regulator_desc desc
;
101 struct regmap
*regmap
;
102 bool enable_external_control
;
103 struct gpio_desc
*dvs_gpiod
;
104 int lru_index
[MAX8973_MAX_VOUT_REG
];
105 int curr_vout_val
[MAX8973_MAX_VOUT_REG
];
108 struct regulator_ops ops
;
110 int junction_temp_warning
;
112 struct thermal_zone_device
*tz_device
;
116 * find_voltage_set_register: Find new voltage configuration register (VOUT).
117 * The finding of the new VOUT register will be based on the LRU mechanism.
118 * Each VOUT register will have different voltage configured . This
119 * Function will look if any of the VOUT register have requested voltage set
121 * - If it is already there then it will make that register as most
122 * recently used and return as found so that caller need not to set
123 * the VOUT register but need to set the proper gpios to select this
125 * - If requested voltage is not found then it will use the least
126 * recently mechanism to get new VOUT register for new configuration
127 * and will return not_found so that caller need to set new VOUT
128 * register and then gpios (both).
130 static bool find_voltage_set_register(struct max8973_chip
*tps
,
131 int req_vsel
, int *vout_reg
, int *gpio_val
)
135 int new_vout_reg
= tps
->lru_index
[MAX8973_MAX_VOUT_REG
- 1];
136 int found_index
= MAX8973_MAX_VOUT_REG
- 1;
138 for (i
= 0; i
< MAX8973_MAX_VOUT_REG
; ++i
) {
139 if (tps
->curr_vout_val
[tps
->lru_index
[i
]] == req_vsel
) {
140 new_vout_reg
= tps
->lru_index
[i
];
143 goto update_lru_index
;
148 for (i
= found_index
; i
> 0; i
--)
149 tps
->lru_index
[i
] = tps
->lru_index
[i
- 1];
151 tps
->lru_index
[0] = new_vout_reg
;
152 *gpio_val
= new_vout_reg
;
153 *vout_reg
= MAX8973_VOUT
+ new_vout_reg
;
157 static int max8973_dcdc_get_voltage_sel(struct regulator_dev
*rdev
)
159 struct max8973_chip
*max
= rdev_get_drvdata(rdev
);
163 ret
= regmap_read(max
->regmap
, max
->curr_vout_reg
, &data
);
165 dev_err(max
->dev
, "register %d read failed, err = %d\n",
166 max
->curr_vout_reg
, ret
);
169 return data
& MAX8973_VOUT_MASK
;
172 static int max8973_dcdc_set_voltage_sel(struct regulator_dev
*rdev
,
175 struct max8973_chip
*max
= rdev_get_drvdata(rdev
);
178 int vout_reg
= max
->curr_vout_reg
;
179 int gpio_val
= max
->curr_gpio_val
;
182 * If gpios are available to select the VOUT register then least
183 * recently used register for new configuration.
186 found
= find_voltage_set_register(max
, vsel
,
187 &vout_reg
, &gpio_val
);
190 ret
= regmap_update_bits(max
->regmap
, vout_reg
,
191 MAX8973_VOUT_MASK
, vsel
);
193 dev_err(max
->dev
, "register %d update failed, err %d\n",
197 max
->curr_vout_reg
= vout_reg
;
198 max
->curr_vout_val
[gpio_val
] = vsel
;
201 /* Select proper VOUT register vio gpios */
202 if (max
->dvs_gpiod
) {
203 gpiod_set_value_cansleep(max
->dvs_gpiod
, gpio_val
& 0x1);
204 max
->curr_gpio_val
= gpio_val
;
209 static int max8973_dcdc_set_mode(struct regulator_dev
*rdev
, unsigned int mode
)
211 struct max8973_chip
*max
= rdev_get_drvdata(rdev
);
215 /* Enable force PWM mode in FAST mode only. */
217 case REGULATOR_MODE_FAST
:
218 pwm
= MAX8973_FPWM_EN_M
;
221 case REGULATOR_MODE_NORMAL
:
229 ret
= regmap_update_bits(max
->regmap
, MAX8973_CONTROL1
,
230 MAX8973_FPWM_EN_M
, pwm
);
232 dev_err(max
->dev
, "register %d update failed, err %d\n",
233 MAX8973_CONTROL1
, ret
);
237 static unsigned int max8973_dcdc_get_mode(struct regulator_dev
*rdev
)
239 struct max8973_chip
*max
= rdev_get_drvdata(rdev
);
243 ret
= regmap_read(max
->regmap
, MAX8973_CONTROL1
, &data
);
245 dev_err(max
->dev
, "register %d read failed, err %d\n",
246 MAX8973_CONTROL1
, ret
);
249 return (data
& MAX8973_FPWM_EN_M
) ?
250 REGULATOR_MODE_FAST
: REGULATOR_MODE_NORMAL
;
253 static int max8973_set_current_limit(struct regulator_dev
*rdev
,
254 int min_ua
, int max_ua
)
256 struct max8973_chip
*max
= rdev_get_drvdata(rdev
);
260 if (max_ua
<= 9000000)
261 val
= MAX8973_CKKADV_TRIP_75mV_PER_US
;
262 else if (max_ua
<= 12000000)
263 val
= MAX8973_CKKADV_TRIP_150mV_PER_US
;
265 val
= MAX8973_CKKADV_TRIP_DISABLE
;
267 ret
= regmap_update_bits(max
->regmap
, MAX8973_CONTROL2
,
268 MAX8973_CKKADV_TRIP_MASK
, val
);
270 dev_err(max
->dev
, "register %d update failed: %d\n",
271 MAX8973_CONTROL2
, ret
);
277 static int max8973_get_current_limit(struct regulator_dev
*rdev
)
279 struct max8973_chip
*max
= rdev_get_drvdata(rdev
);
280 unsigned int control2
;
283 ret
= regmap_read(max
->regmap
, MAX8973_CONTROL2
, &control2
);
285 dev_err(max
->dev
, "register %d read failed: %d\n",
286 MAX8973_CONTROL2
, ret
);
289 switch (control2
& MAX8973_CKKADV_TRIP_MASK
) {
290 case MAX8973_CKKADV_TRIP_DISABLE
:
292 case MAX8973_CKKADV_TRIP_150mV_PER_US
:
294 case MAX8973_CKKADV_TRIP_75mV_PER_US
:
302 static const unsigned int max8973_buck_ramp_table
[] = {
303 12000, 25000, 50000, 200000
306 static const struct regulator_ops max8973_dcdc_ops
= {
307 .get_voltage_sel
= max8973_dcdc_get_voltage_sel
,
308 .set_voltage_sel
= max8973_dcdc_set_voltage_sel
,
309 .list_voltage
= regulator_list_voltage_linear
,
310 .set_mode
= max8973_dcdc_set_mode
,
311 .get_mode
= max8973_dcdc_get_mode
,
312 .set_voltage_time_sel
= regulator_set_voltage_time_sel
,
313 .set_ramp_delay
= regulator_set_ramp_delay_regmap
,
316 static int max8973_init_dcdc(struct max8973_chip
*max
,
317 struct max8973_regulator_platform_data
*pdata
)
320 uint8_t control1
= 0;
321 uint8_t control2
= 0;
324 ret
= regmap_read(max
->regmap
, MAX8973_CONTROL1
, &data
);
326 dev_err(max
->dev
, "register %d read failed, err = %d",
327 MAX8973_CONTROL1
, ret
);
330 control1
= data
& MAX8973_RAMP_MASK
;
332 case MAX8973_RAMP_12mV_PER_US
:
333 max
->desc
.ramp_delay
= 12000;
335 case MAX8973_RAMP_25mV_PER_US
:
336 max
->desc
.ramp_delay
= 25000;
338 case MAX8973_RAMP_50mV_PER_US
:
339 max
->desc
.ramp_delay
= 50000;
341 case MAX8973_RAMP_200mV_PER_US
:
342 max
->desc
.ramp_delay
= 200000;
346 if (pdata
->control_flags
& MAX8973_CONTROL_REMOTE_SENSE_ENABLE
)
347 control1
|= MAX8973_SNS_ENABLE
;
349 if (!(pdata
->control_flags
& MAX8973_CONTROL_FALLING_SLEW_RATE_ENABLE
))
350 control1
|= MAX8973_NFSR_ENABLE
;
352 if (pdata
->control_flags
& MAX8973_CONTROL_OUTPUT_ACTIVE_DISCH_ENABLE
)
353 control1
|= MAX8973_AD_ENABLE
;
355 if (pdata
->control_flags
& MAX8973_CONTROL_BIAS_ENABLE
) {
356 control1
|= MAX8973_BIAS_ENABLE
;
357 max
->desc
.enable_time
= 20;
359 max
->desc
.enable_time
= 240;
362 if (pdata
->control_flags
& MAX8973_CONTROL_FREQ_SHIFT_9PER_ENABLE
)
363 control1
|= MAX8973_FREQSHIFT_9PER
;
365 if ((pdata
->junction_temp_warning
== MAX77621_TJINT_WARNING_TEMP_120
) &&
366 (max
->id
== MAX77621
))
367 control2
|= MAX77621_T_JUNCTION_120
;
369 if (!(pdata
->control_flags
& MAX8973_CONTROL_PULL_DOWN_ENABLE
))
370 control2
|= MAX8973_DISCH_ENBABLE
;
372 /* Clock advance trip configuration */
373 switch (pdata
->control_flags
& MAX8973_CONTROL_CLKADV_TRIP_MASK
) {
374 case MAX8973_CONTROL_CLKADV_TRIP_DISABLED
:
375 control2
|= MAX8973_CKKADV_TRIP_DISABLE
;
378 case MAX8973_CONTROL_CLKADV_TRIP_75mV_PER_US
:
379 control2
|= MAX8973_CKKADV_TRIP_75mV_PER_US
;
382 case MAX8973_CONTROL_CLKADV_TRIP_150mV_PER_US
:
383 control2
|= MAX8973_CKKADV_TRIP_150mV_PER_US
;
386 case MAX8973_CONTROL_CLKADV_TRIP_75mV_PER_US_HIST_DIS
:
387 control2
|= MAX8973_CKKADV_TRIP_75mV_PER_US_HIST_DIS
;
391 /* Configure inductor value */
392 switch (pdata
->control_flags
& MAX8973_CONTROL_INDUCTOR_VALUE_MASK
) {
393 case MAX8973_CONTROL_INDUCTOR_VALUE_NOMINAL
:
394 control2
|= MAX8973_INDUCTOR_NOMINAL
;
397 case MAX8973_CONTROL_INDUCTOR_VALUE_MINUS_30_PER
:
398 control2
|= MAX8973_INDUCTOR_MIN_30_PER
;
401 case MAX8973_CONTROL_INDUCTOR_VALUE_PLUS_30_PER
:
402 control2
|= MAX8973_INDUCTOR_PLUS_30_PER
;
405 case MAX8973_CONTROL_INDUCTOR_VALUE_PLUS_60_PER
:
406 control2
|= MAX8973_INDUCTOR_PLUS_60_PER
;
410 ret
= regmap_write(max
->regmap
, MAX8973_CONTROL1
, control1
);
412 dev_err(max
->dev
, "register %d write failed, err = %d",
413 MAX8973_CONTROL1
, ret
);
417 ret
= regmap_write(max
->regmap
, MAX8973_CONTROL2
, control2
);
419 dev_err(max
->dev
, "register %d write failed, err = %d",
420 MAX8973_CONTROL2
, ret
);
424 /* If external control is enabled then disable EN bit */
425 if (max
->enable_external_control
&& (max
->id
== MAX8973
)) {
426 ret
= regmap_update_bits(max
->regmap
, MAX8973_VOUT
,
427 MAX8973_VOUT_ENABLE
, 0);
429 dev_err(max
->dev
, "register %d update failed, err = %d",
435 static int max8973_thermal_read_temp(struct thermal_zone_device
*tz
, int *temp
)
437 struct max8973_chip
*mchip
= thermal_zone_device_priv(tz
);
441 ret
= regmap_read(mchip
->regmap
, MAX8973_CHIPID1
, &val
);
443 dev_err(mchip
->dev
, "Failed to read register CHIPID1, %d", ret
);
447 /* +1 degC to trigger cool device */
448 if (val
& MAX77621_CHIPID_TJINT_S
)
449 *temp
= mchip
->junction_temp_warning
+ 1000;
451 *temp
= MAX77621_NORMAL_OPERATING_TEMP
;
456 static irqreturn_t
max8973_thermal_irq(int irq
, void *data
)
458 struct max8973_chip
*mchip
= data
;
460 thermal_zone_device_update(mchip
->tz_device
,
461 THERMAL_EVENT_UNSPECIFIED
);
466 static const struct thermal_zone_device_ops max77621_tz_ops
= {
467 .get_temp
= max8973_thermal_read_temp
,
470 static int max8973_thermal_init(struct max8973_chip
*mchip
)
472 struct thermal_zone_device
*tzd
;
473 unsigned long irq_flags
;
476 if (mchip
->id
!= MAX77621
)
479 tzd
= devm_thermal_of_zone_register(mchip
->dev
, 0, mchip
,
483 dev_err(mchip
->dev
, "Failed to register thermal sensor: %d\n",
491 irq_flags
= irq_get_trigger_type(mchip
->irq
);
493 ret
= devm_request_threaded_irq(mchip
->dev
, mchip
->irq
, NULL
,
495 IRQF_ONESHOT
| IRQF_SHARED
| irq_flags
,
496 dev_name(mchip
->dev
), mchip
);
498 dev_err(mchip
->dev
, "Failed to request irq %d, %d\n",
506 static const struct regmap_config max8973_regmap_config
= {
509 .max_register
= MAX8973_CHIPID2
,
510 .cache_type
= REGCACHE_MAPLE
,
513 static struct max8973_regulator_platform_data
*max8973_parse_dt(
516 struct max8973_regulator_platform_data
*pdata
;
517 struct device_node
*np
= dev
->of_node
;
521 bool etr_sensitivity_high
;
523 pdata
= devm_kzalloc(dev
, sizeof(*pdata
), GFP_KERNEL
);
527 pdata
->enable_ext_control
= of_property_read_bool(np
,
528 "maxim,externally-enable");
530 ret
= of_property_read_u32(np
, "maxim,dvs-default-state", &pval
);
532 pdata
->dvs_def_state
= pval
;
534 if (of_property_read_bool(np
, "maxim,enable-remote-sense"))
535 pdata
->control_flags
|= MAX8973_CONTROL_REMOTE_SENSE_ENABLE
;
537 if (of_property_read_bool(np
, "maxim,enable-falling-slew-rate"))
538 pdata
->control_flags
|=
539 MAX8973_CONTROL_FALLING_SLEW_RATE_ENABLE
;
541 if (of_property_read_bool(np
, "maxim,enable-active-discharge"))
542 pdata
->control_flags
|=
543 MAX8973_CONTROL_OUTPUT_ACTIVE_DISCH_ENABLE
;
545 if (of_property_read_bool(np
, "maxim,enable-frequency-shift"))
546 pdata
->control_flags
|= MAX8973_CONTROL_FREQ_SHIFT_9PER_ENABLE
;
548 if (of_property_read_bool(np
, "maxim,enable-bias-control"))
549 pdata
->control_flags
|= MAX8973_CONTROL_BIAS_ENABLE
;
551 etr_enable
= of_property_read_bool(np
, "maxim,enable-etr");
552 etr_sensitivity_high
= of_property_read_bool(np
,
553 "maxim,enable-high-etr-sensitivity");
554 if (etr_sensitivity_high
)
558 if (etr_sensitivity_high
)
559 pdata
->control_flags
|=
560 MAX8973_CONTROL_CLKADV_TRIP_75mV_PER_US
;
562 pdata
->control_flags
|=
563 MAX8973_CONTROL_CLKADV_TRIP_150mV_PER_US
;
565 pdata
->control_flags
|= MAX8973_CONTROL_CLKADV_TRIP_DISABLED
;
568 pdata
->junction_temp_warning
= MAX77621_TJINT_WARNING_TEMP_140
;
569 ret
= of_property_read_u32(np
, "junction-warn-millicelsius", &pval
);
570 if (!ret
&& (pval
<= MAX77621_TJINT_WARNING_TEMP_120
))
571 pdata
->junction_temp_warning
= MAX77621_TJINT_WARNING_TEMP_120
;
576 static const struct of_device_id of_max8973_match_tbl
[] = {
577 { .compatible
= "maxim,max8973", .data
= (void *)MAX8973
, },
578 { .compatible
= "maxim,max77621", .data
= (void *)MAX77621
, },
581 MODULE_DEVICE_TABLE(of
, of_max8973_match_tbl
);
583 static int max8973_probe(struct i2c_client
*client
)
585 const struct i2c_device_id
*id
= i2c_client_get_device_id(client
);
586 struct max8973_regulator_platform_data
*pdata
;
587 struct regulator_init_data
*ridata
;
588 struct regulator_config config
= { };
589 struct regulator_dev
*rdev
;
590 struct max8973_chip
*max
;
591 bool pdata_from_dt
= false;
592 unsigned int chip_id
;
593 struct gpio_desc
*gpiod
;
594 enum gpiod_flags gflags
;
597 pdata
= dev_get_platdata(&client
->dev
);
599 if (!pdata
&& client
->dev
.of_node
) {
600 pdata
= max8973_parse_dt(&client
->dev
);
601 pdata_from_dt
= true;
605 dev_err(&client
->dev
, "No Platform data");
609 max
= devm_kzalloc(&client
->dev
, sizeof(*max
), GFP_KERNEL
);
613 max
->dvs_gpiod
= devm_gpiod_get_optional(&client
->dev
, "maxim,dvs",
614 (pdata
->dvs_def_state
) ? GPIOD_OUT_HIGH
: GPIOD_OUT_LOW
);
615 if (IS_ERR(max
->dvs_gpiod
))
616 return dev_err_probe(&client
->dev
, PTR_ERR(max
->dvs_gpiod
),
617 "failed to obtain dvs gpio\n");
618 gpiod_set_consumer_name(max
->dvs_gpiod
, "max8973-dvs");
620 max
->regmap
= devm_regmap_init_i2c(client
, &max8973_regmap_config
);
621 if (IS_ERR(max
->regmap
)) {
622 ret
= PTR_ERR(max
->regmap
);
623 dev_err(&client
->dev
, "regmap init failed, err %d\n", ret
);
627 if (client
->dev
.of_node
) {
628 const struct of_device_id
*match
;
630 match
= of_match_device(of_match_ptr(of_max8973_match_tbl
),
634 max
->id
= (u32
)((uintptr_t)match
->data
);
636 max
->id
= id
->driver_data
;
639 ret
= regmap_read(max
->regmap
, MAX8973_CHIPID1
, &chip_id
);
641 dev_err(&client
->dev
, "register CHIPID1 read failed, %d", ret
);
645 dev_info(&client
->dev
, "CHIP-ID OTP: 0x%02x ID_M: 0x%02x\n",
646 (chip_id
>> 4) & 0xF, (chip_id
>> 1) & 0x7);
648 i2c_set_clientdata(client
, max
);
649 max
->ops
= max8973_dcdc_ops
;
650 max
->dev
= &client
->dev
;
651 max
->desc
.name
= id
->name
;
653 max
->desc
.ops
= &max
->ops
;
654 max
->desc
.type
= REGULATOR_VOLTAGE
;
655 max
->desc
.owner
= THIS_MODULE
;
656 max
->desc
.min_uV
= MAX8973_MIN_VOLATGE
;
657 max
->desc
.uV_step
= MAX8973_VOLATGE_STEP
;
658 max
->desc
.n_voltages
= MAX8973_BUCK_N_VOLTAGE
;
659 max
->desc
.ramp_reg
= MAX8973_CONTROL1
;
660 max
->desc
.ramp_mask
= MAX8973_RAMP_MASK
;
661 max
->desc
.ramp_delay_table
= max8973_buck_ramp_table
;
662 max
->desc
.n_ramp_values
= ARRAY_SIZE(max8973_buck_ramp_table
);
664 max
->enable_external_control
= pdata
->enable_ext_control
;
665 max
->curr_gpio_val
= pdata
->dvs_def_state
;
666 max
->curr_vout_reg
= MAX8973_VOUT
+ pdata
->dvs_def_state
;
667 max
->junction_temp_warning
= pdata
->junction_temp_warning
;
669 max
->lru_index
[0] = max
->curr_vout_reg
;
671 if (max
->dvs_gpiod
) {
675 * Initialize the lru index with vout_reg id
676 * The index 0 will be most recently used and
677 * set with the max->curr_vout_reg */
678 for (i
= 0; i
< MAX8973_MAX_VOUT_REG
; ++i
)
679 max
->lru_index
[i
] = i
;
680 max
->lru_index
[0] = max
->curr_vout_reg
;
681 max
->lru_index
[max
->curr_vout_reg
] = 0;
684 * If there is no DVS GPIO, the VOUT register
687 max
->ops
.set_voltage_sel
= regulator_set_voltage_sel_regmap
;
688 max
->ops
.get_voltage_sel
= regulator_get_voltage_sel_regmap
;
689 max
->desc
.vsel_reg
= max
->curr_vout_reg
;
690 max
->desc
.vsel_mask
= MAX8973_VOUT_MASK
;
694 pdata
->reg_init_data
= of_get_regulator_init_data(&client
->dev
,
695 client
->dev
.of_node
, &max
->desc
);
697 ridata
= pdata
->reg_init_data
;
700 if (!pdata
->enable_ext_control
) {
701 max
->desc
.enable_reg
= MAX8973_VOUT
;
702 max
->desc
.enable_mask
= MAX8973_VOUT_ENABLE
;
703 max
->ops
.enable
= regulator_enable_regmap
;
704 max
->ops
.disable
= regulator_disable_regmap
;
705 max
->ops
.is_enabled
= regulator_is_enabled_regmap
;
709 if (ridata
&& (ridata
->constraints
.always_on
||
710 ridata
->constraints
.boot_on
))
711 gflags
= GPIOD_OUT_HIGH
;
713 gflags
= GPIOD_OUT_LOW
;
714 gflags
|= GPIOD_FLAGS_BIT_NONEXCLUSIVE
;
715 gpiod
= devm_gpiod_get_optional(&client
->dev
,
719 return PTR_ERR(gpiod
);
721 config
.ena_gpiod
= gpiod
;
722 max
->enable_external_control
= true;
729 * We do not let the core switch this regulator on/off,
730 * we just leave it on.
732 gpiod
= devm_gpiod_get_optional(&client
->dev
,
736 return PTR_ERR(gpiod
);
738 max
->enable_external_control
= true;
740 max
->desc
.enable_reg
= MAX8973_VOUT
;
741 max
->desc
.enable_mask
= MAX8973_VOUT_ENABLE
;
742 max
->ops
.enable
= regulator_enable_regmap
;
743 max
->ops
.disable
= regulator_disable_regmap
;
744 max
->ops
.is_enabled
= regulator_is_enabled_regmap
;
745 max
->ops
.set_current_limit
= max8973_set_current_limit
;
746 max
->ops
.get_current_limit
= max8973_get_current_limit
;
752 ret
= max8973_init_dcdc(max
, pdata
);
754 dev_err(max
->dev
, "Max8973 Init failed, err = %d\n", ret
);
758 config
.dev
= &client
->dev
;
759 config
.init_data
= pdata
->reg_init_data
;
760 config
.driver_data
= max
;
761 config
.of_node
= client
->dev
.of_node
;
762 config
.regmap
= max
->regmap
;
765 * Register the regulators
766 * Turn the GPIO descriptor over to the regulator core for
767 * lifecycle management if we pass an ena_gpiod.
769 if (config
.ena_gpiod
)
770 devm_gpiod_unhinge(&client
->dev
, config
.ena_gpiod
);
771 rdev
= devm_regulator_register(&client
->dev
, &max
->desc
, &config
);
774 dev_err(max
->dev
, "regulator register failed, err %d\n", ret
);
778 max8973_thermal_init(max
);
782 static const struct i2c_device_id max8973_id
[] = {
783 {.name
= "max8973", .driver_data
= MAX8973
},
784 {.name
= "max77621", .driver_data
= MAX77621
},
787 MODULE_DEVICE_TABLE(i2c
, max8973_id
);
789 static struct i2c_driver max8973_i2c_driver
= {
792 .probe_type
= PROBE_PREFER_ASYNCHRONOUS
,
793 .of_match_table
= of_max8973_match_tbl
,
795 .probe
= max8973_probe
,
796 .id_table
= max8973_id
,
799 static int __init
max8973_init(void)
801 return i2c_add_driver(&max8973_i2c_driver
);
803 subsys_initcall(max8973_init
);
805 static void __exit
max8973_cleanup(void)
807 i2c_del_driver(&max8973_i2c_driver
);
809 module_exit(max8973_cleanup
);
811 MODULE_AUTHOR("Laxman Dewangan <ldewangan@nvidia.com>");
812 MODULE_DESCRIPTION("MAX8973 voltage regulator driver");
813 MODULE_LICENSE("GPL v2");