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.h>
24 #include <linux/gpio/consumer.h>
25 #include <linux/of_gpio.h>
26 #include <linux/i2c.h>
27 #include <linux/slab.h>
28 #include <linux/regmap.h>
29 #include <linux/thermal.h>
30 #include <linux/irq.h>
31 #include <linux/interrupt.h>
33 /* Register definitions */
34 #define MAX8973_VOUT 0x0
35 #define MAX8973_VOUT_DVS 0x1
36 #define MAX8973_CONTROL1 0x2
37 #define MAX8973_CONTROL2 0x3
38 #define MAX8973_CHIPID1 0x4
39 #define MAX8973_CHIPID2 0x5
41 #define MAX8973_MAX_VOUT_REG 2
44 #define MAX8973_VOUT_ENABLE BIT(7)
45 #define MAX8973_VOUT_MASK 0x7F
47 /* MAX8973_VOUT_DVS */
48 #define MAX8973_DVS_VOUT_MASK 0x7F
50 /* MAX8973_CONTROL1 */
51 #define MAX8973_SNS_ENABLE BIT(7)
52 #define MAX8973_FPWM_EN_M BIT(6)
53 #define MAX8973_NFSR_ENABLE BIT(5)
54 #define MAX8973_AD_ENABLE BIT(4)
55 #define MAX8973_BIAS_ENABLE BIT(3)
56 #define MAX8973_FREQSHIFT_9PER BIT(2)
58 #define MAX8973_RAMP_12mV_PER_US 0x0
59 #define MAX8973_RAMP_25mV_PER_US 0x1
60 #define MAX8973_RAMP_50mV_PER_US 0x2
61 #define MAX8973_RAMP_200mV_PER_US 0x3
62 #define MAX8973_RAMP_MASK 0x3
64 /* MAX8973_CONTROL2 */
65 #define MAX8973_WDTMR_ENABLE BIT(6)
66 #define MAX8973_DISCH_ENBABLE BIT(5)
67 #define MAX8973_FT_ENABLE BIT(4)
68 #define MAX77621_T_JUNCTION_120 BIT(7)
70 #define MAX8973_CKKADV_TRIP_MASK 0xC
71 #define MAX8973_CKKADV_TRIP_DISABLE 0xC
72 #define MAX8973_CKKADV_TRIP_75mV_PER_US 0x0
73 #define MAX8973_CKKADV_TRIP_150mV_PER_US 0x4
74 #define MAX8973_CKKADV_TRIP_75mV_PER_US_HIST_DIS 0x8
75 #define MAX8973_CONTROL_CLKADV_TRIP_MASK 0x00030000
77 #define MAX8973_INDUCTOR_MIN_30_PER 0x0
78 #define MAX8973_INDUCTOR_NOMINAL 0x1
79 #define MAX8973_INDUCTOR_PLUS_30_PER 0x2
80 #define MAX8973_INDUCTOR_PLUS_60_PER 0x3
81 #define MAX8973_CONTROL_INDUCTOR_VALUE_MASK 0x00300000
83 #define MAX8973_MIN_VOLATGE 606250
84 #define MAX8973_MAX_VOLATGE 1400000
85 #define MAX8973_VOLATGE_STEP 6250
86 #define MAX8973_BUCK_N_VOLTAGE 0x80
88 #define MAX77621_CHIPID_TJINT_S BIT(0)
90 #define MAX77621_NORMAL_OPERATING_TEMP 100000
91 #define MAX77621_TJINT_WARNING_TEMP_120 120000
92 #define MAX77621_TJINT_WARNING_TEMP_140 140000
99 /* Maxim 8973 chip information */
100 struct max8973_chip {
102 struct regulator_desc desc;
103 struct regmap *regmap;
104 bool enable_external_control;
106 int lru_index[MAX8973_MAX_VOUT_REG];
107 int curr_vout_val[MAX8973_MAX_VOUT_REG];
110 struct regulator_ops ops;
112 int junction_temp_warning;
114 struct thermal_zone_device *tz_device;
118 * find_voltage_set_register: Find new voltage configuration register (VOUT).
119 * The finding of the new VOUT register will be based on the LRU mechanism.
120 * Each VOUT register will have different voltage configured . This
121 * Function will look if any of the VOUT register have requested voltage set
123 * - If it is already there then it will make that register as most
124 * recently used and return as found so that caller need not to set
125 * the VOUT register but need to set the proper gpios to select this
127 * - If requested voltage is not found then it will use the least
128 * recently mechanism to get new VOUT register for new configuration
129 * and will return not_found so that caller need to set new VOUT
130 * register and then gpios (both).
132 static bool find_voltage_set_register(struct max8973_chip *tps,
133 int req_vsel, int *vout_reg, int *gpio_val)
137 int new_vout_reg = tps->lru_index[MAX8973_MAX_VOUT_REG - 1];
138 int found_index = MAX8973_MAX_VOUT_REG - 1;
140 for (i = 0; i < MAX8973_MAX_VOUT_REG; ++i) {
141 if (tps->curr_vout_val[tps->lru_index[i]] == req_vsel) {
142 new_vout_reg = tps->lru_index[i];
145 goto update_lru_index;
150 for (i = found_index; i > 0; i--)
151 tps->lru_index[i] = tps->lru_index[i - 1];
153 tps->lru_index[0] = new_vout_reg;
154 *gpio_val = new_vout_reg;
155 *vout_reg = MAX8973_VOUT + new_vout_reg;
159 static int max8973_dcdc_get_voltage_sel(struct regulator_dev *rdev)
161 struct max8973_chip *max = rdev_get_drvdata(rdev);
165 ret = regmap_read(max->regmap, max->curr_vout_reg, &data);
167 dev_err(max->dev, "register %d read failed, err = %d\n",
168 max->curr_vout_reg, ret);
171 return data & MAX8973_VOUT_MASK;
174 static int max8973_dcdc_set_voltage_sel(struct regulator_dev *rdev,
177 struct max8973_chip *max = rdev_get_drvdata(rdev);
180 int vout_reg = max->curr_vout_reg;
181 int gpio_val = max->curr_gpio_val;
184 * If gpios are available to select the VOUT register then least
185 * recently used register for new configuration.
187 if (gpio_is_valid(max->dvs_gpio))
188 found = find_voltage_set_register(max, vsel,
189 &vout_reg, &gpio_val);
192 ret = regmap_update_bits(max->regmap, vout_reg,
193 MAX8973_VOUT_MASK, vsel);
195 dev_err(max->dev, "register %d update failed, err %d\n",
199 max->curr_vout_reg = vout_reg;
200 max->curr_vout_val[gpio_val] = vsel;
203 /* Select proper VOUT register vio gpios */
204 if (gpio_is_valid(max->dvs_gpio)) {
205 gpio_set_value_cansleep(max->dvs_gpio, gpio_val & 0x1);
206 max->curr_gpio_val = gpio_val;
211 static int max8973_dcdc_set_mode(struct regulator_dev *rdev, unsigned int mode)
213 struct max8973_chip *max = rdev_get_drvdata(rdev);
217 /* Enable force PWM mode in FAST mode only. */
219 case REGULATOR_MODE_FAST:
220 pwm = MAX8973_FPWM_EN_M;
223 case REGULATOR_MODE_NORMAL:
231 ret = regmap_update_bits(max->regmap, MAX8973_CONTROL1,
232 MAX8973_FPWM_EN_M, pwm);
234 dev_err(max->dev, "register %d update failed, err %d\n",
235 MAX8973_CONTROL1, ret);
239 static unsigned int max8973_dcdc_get_mode(struct regulator_dev *rdev)
241 struct max8973_chip *max = rdev_get_drvdata(rdev);
245 ret = regmap_read(max->regmap, MAX8973_CONTROL1, &data);
247 dev_err(max->dev, "register %d read failed, err %d\n",
248 MAX8973_CONTROL1, ret);
251 return (data & MAX8973_FPWM_EN_M) ?
252 REGULATOR_MODE_FAST : REGULATOR_MODE_NORMAL;
255 static int max8973_set_current_limit(struct regulator_dev *rdev,
256 int min_ua, int max_ua)
258 struct max8973_chip *max = rdev_get_drvdata(rdev);
262 if (max_ua <= 9000000)
263 val = MAX8973_CKKADV_TRIP_75mV_PER_US;
264 else if (max_ua <= 12000000)
265 val = MAX8973_CKKADV_TRIP_150mV_PER_US;
267 val = MAX8973_CKKADV_TRIP_DISABLE;
269 ret = regmap_update_bits(max->regmap, MAX8973_CONTROL2,
270 MAX8973_CKKADV_TRIP_MASK, val);
272 dev_err(max->dev, "register %d update failed: %d\n",
273 MAX8973_CONTROL2, ret);
279 static int max8973_get_current_limit(struct regulator_dev *rdev)
281 struct max8973_chip *max = rdev_get_drvdata(rdev);
282 unsigned int control2;
285 ret = regmap_read(max->regmap, MAX8973_CONTROL2, &control2);
287 dev_err(max->dev, "register %d read failed: %d\n",
288 MAX8973_CONTROL2, ret);
291 switch (control2 & MAX8973_CKKADV_TRIP_MASK) {
292 case MAX8973_CKKADV_TRIP_DISABLE:
294 case MAX8973_CKKADV_TRIP_150mV_PER_US:
296 case MAX8973_CKKADV_TRIP_75mV_PER_US:
304 static const unsigned int max8973_buck_ramp_table[] = {
305 12000, 25000, 50000, 200000
308 static const struct regulator_ops max8973_dcdc_ops = {
309 .get_voltage_sel = max8973_dcdc_get_voltage_sel,
310 .set_voltage_sel = max8973_dcdc_set_voltage_sel,
311 .list_voltage = regulator_list_voltage_linear,
312 .set_mode = max8973_dcdc_set_mode,
313 .get_mode = max8973_dcdc_get_mode,
314 .set_voltage_time_sel = regulator_set_voltage_time_sel,
315 .set_ramp_delay = regulator_set_ramp_delay_regmap,
318 static int max8973_init_dcdc(struct max8973_chip *max,
319 struct max8973_regulator_platform_data *pdata)
322 uint8_t control1 = 0;
323 uint8_t control2 = 0;
326 ret = regmap_read(max->regmap, MAX8973_CONTROL1, &data);
328 dev_err(max->dev, "register %d read failed, err = %d",
329 MAX8973_CONTROL1, ret);
332 control1 = data & MAX8973_RAMP_MASK;
334 case MAX8973_RAMP_12mV_PER_US:
335 max->desc.ramp_delay = 12000;
337 case MAX8973_RAMP_25mV_PER_US:
338 max->desc.ramp_delay = 25000;
340 case MAX8973_RAMP_50mV_PER_US:
341 max->desc.ramp_delay = 50000;
343 case MAX8973_RAMP_200mV_PER_US:
344 max->desc.ramp_delay = 200000;
348 if (pdata->control_flags & MAX8973_CONTROL_REMOTE_SENSE_ENABLE)
349 control1 |= MAX8973_SNS_ENABLE;
351 if (!(pdata->control_flags & MAX8973_CONTROL_FALLING_SLEW_RATE_ENABLE))
352 control1 |= MAX8973_NFSR_ENABLE;
354 if (pdata->control_flags & MAX8973_CONTROL_OUTPUT_ACTIVE_DISCH_ENABLE)
355 control1 |= MAX8973_AD_ENABLE;
357 if (pdata->control_flags & MAX8973_CONTROL_BIAS_ENABLE) {
358 control1 |= MAX8973_BIAS_ENABLE;
359 max->desc.enable_time = 20;
361 max->desc.enable_time = 240;
364 if (pdata->control_flags & MAX8973_CONTROL_FREQ_SHIFT_9PER_ENABLE)
365 control1 |= MAX8973_FREQSHIFT_9PER;
367 if ((pdata->junction_temp_warning == MAX77621_TJINT_WARNING_TEMP_120) &&
368 (max->id == MAX77621))
369 control2 |= MAX77621_T_JUNCTION_120;
371 if (!(pdata->control_flags & MAX8973_CONTROL_PULL_DOWN_ENABLE))
372 control2 |= MAX8973_DISCH_ENBABLE;
374 /* Clock advance trip configuration */
375 switch (pdata->control_flags & MAX8973_CONTROL_CLKADV_TRIP_MASK) {
376 case MAX8973_CONTROL_CLKADV_TRIP_DISABLED:
377 control2 |= MAX8973_CKKADV_TRIP_DISABLE;
380 case MAX8973_CONTROL_CLKADV_TRIP_75mV_PER_US:
381 control2 |= MAX8973_CKKADV_TRIP_75mV_PER_US;
384 case MAX8973_CONTROL_CLKADV_TRIP_150mV_PER_US:
385 control2 |= MAX8973_CKKADV_TRIP_150mV_PER_US;
388 case MAX8973_CONTROL_CLKADV_TRIP_75mV_PER_US_HIST_DIS:
389 control2 |= MAX8973_CKKADV_TRIP_75mV_PER_US_HIST_DIS;
393 /* Configure inductor value */
394 switch (pdata->control_flags & MAX8973_CONTROL_INDUCTOR_VALUE_MASK) {
395 case MAX8973_CONTROL_INDUCTOR_VALUE_NOMINAL:
396 control2 |= MAX8973_INDUCTOR_NOMINAL;
399 case MAX8973_CONTROL_INDUCTOR_VALUE_MINUS_30_PER:
400 control2 |= MAX8973_INDUCTOR_MIN_30_PER;
403 case MAX8973_CONTROL_INDUCTOR_VALUE_PLUS_30_PER:
404 control2 |= MAX8973_INDUCTOR_PLUS_30_PER;
407 case MAX8973_CONTROL_INDUCTOR_VALUE_PLUS_60_PER:
408 control2 |= MAX8973_INDUCTOR_PLUS_60_PER;
412 ret = regmap_write(max->regmap, MAX8973_CONTROL1, control1);
414 dev_err(max->dev, "register %d write failed, err = %d",
415 MAX8973_CONTROL1, ret);
419 ret = regmap_write(max->regmap, MAX8973_CONTROL2, control2);
421 dev_err(max->dev, "register %d write failed, err = %d",
422 MAX8973_CONTROL2, ret);
426 /* If external control is enabled then disable EN bit */
427 if (max->enable_external_control && (max->id == MAX8973)) {
428 ret = regmap_update_bits(max->regmap, MAX8973_VOUT,
429 MAX8973_VOUT_ENABLE, 0);
431 dev_err(max->dev, "register %d update failed, err = %d",
437 static int max8973_thermal_read_temp(struct thermal_zone_device *tz, int *temp)
439 struct max8973_chip *mchip = thermal_zone_device_priv(tz);
443 ret = regmap_read(mchip->regmap, MAX8973_CHIPID1, &val);
445 dev_err(mchip->dev, "Failed to read register CHIPID1, %d", ret);
449 /* +1 degC to trigger cool device */
450 if (val & MAX77621_CHIPID_TJINT_S)
451 *temp = mchip->junction_temp_warning + 1000;
453 *temp = MAX77621_NORMAL_OPERATING_TEMP;
458 static irqreturn_t max8973_thermal_irq(int irq, void *data)
460 struct max8973_chip *mchip = data;
462 thermal_zone_device_update(mchip->tz_device,
463 THERMAL_EVENT_UNSPECIFIED);
468 static const struct thermal_zone_device_ops max77621_tz_ops = {
469 .get_temp = max8973_thermal_read_temp,
472 static int max8973_thermal_init(struct max8973_chip *mchip)
474 struct thermal_zone_device *tzd;
475 struct irq_data *irq_data;
476 unsigned long irq_flags = 0;
479 if (mchip->id != MAX77621)
482 tzd = devm_thermal_of_zone_register(mchip->dev, 0, mchip,
486 dev_err(mchip->dev, "Failed to register thermal sensor: %d\n",
494 irq_data = irq_get_irq_data(mchip->irq);
496 irq_flags = irqd_get_trigger_type(irq_data);
498 ret = devm_request_threaded_irq(mchip->dev, mchip->irq, NULL,
500 IRQF_ONESHOT | IRQF_SHARED | irq_flags,
501 dev_name(mchip->dev), mchip);
503 dev_err(mchip->dev, "Failed to request irq %d, %d\n",
511 static const struct regmap_config max8973_regmap_config = {
514 .max_register = MAX8973_CHIPID2,
515 .cache_type = REGCACHE_RBTREE,
518 static struct max8973_regulator_platform_data *max8973_parse_dt(
521 struct max8973_regulator_platform_data *pdata;
522 struct device_node *np = dev->of_node;
526 bool etr_sensitivity_high;
528 pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL);
532 pdata->enable_ext_control = of_property_read_bool(np,
533 "maxim,externally-enable");
534 pdata->dvs_gpio = of_get_named_gpio(np, "maxim,dvs-gpio", 0);
536 ret = of_property_read_u32(np, "maxim,dvs-default-state", &pval);
538 pdata->dvs_def_state = pval;
540 if (of_property_read_bool(np, "maxim,enable-remote-sense"))
541 pdata->control_flags |= MAX8973_CONTROL_REMOTE_SENSE_ENABLE;
543 if (of_property_read_bool(np, "maxim,enable-falling-slew-rate"))
544 pdata->control_flags |=
545 MAX8973_CONTROL_FALLING_SLEW_RATE_ENABLE;
547 if (of_property_read_bool(np, "maxim,enable-active-discharge"))
548 pdata->control_flags |=
549 MAX8973_CONTROL_OUTPUT_ACTIVE_DISCH_ENABLE;
551 if (of_property_read_bool(np, "maxim,enable-frequency-shift"))
552 pdata->control_flags |= MAX8973_CONTROL_FREQ_SHIFT_9PER_ENABLE;
554 if (of_property_read_bool(np, "maxim,enable-bias-control"))
555 pdata->control_flags |= MAX8973_CONTROL_BIAS_ENABLE;
557 etr_enable = of_property_read_bool(np, "maxim,enable-etr");
558 etr_sensitivity_high = of_property_read_bool(np,
559 "maxim,enable-high-etr-sensitivity");
560 if (etr_sensitivity_high)
564 if (etr_sensitivity_high)
565 pdata->control_flags |=
566 MAX8973_CONTROL_CLKADV_TRIP_75mV_PER_US;
568 pdata->control_flags |=
569 MAX8973_CONTROL_CLKADV_TRIP_150mV_PER_US;
571 pdata->control_flags |= MAX8973_CONTROL_CLKADV_TRIP_DISABLED;
574 pdata->junction_temp_warning = MAX77621_TJINT_WARNING_TEMP_140;
575 ret = of_property_read_u32(np, "junction-warn-millicelsius", &pval);
576 if (!ret && (pval <= MAX77621_TJINT_WARNING_TEMP_120))
577 pdata->junction_temp_warning = MAX77621_TJINT_WARNING_TEMP_120;
582 static const struct of_device_id of_max8973_match_tbl[] = {
583 { .compatible = "maxim,max8973", .data = (void *)MAX8973, },
584 { .compatible = "maxim,max77621", .data = (void *)MAX77621, },
587 MODULE_DEVICE_TABLE(of, of_max8973_match_tbl);
589 static int max8973_probe(struct i2c_client *client)
591 const struct i2c_device_id *id = i2c_client_get_device_id(client);
592 struct max8973_regulator_platform_data *pdata;
593 struct regulator_init_data *ridata;
594 struct regulator_config config = { };
595 struct regulator_dev *rdev;
596 struct max8973_chip *max;
597 bool pdata_from_dt = false;
598 unsigned int chip_id;
599 struct gpio_desc *gpiod;
600 enum gpiod_flags gflags;
603 pdata = dev_get_platdata(&client->dev);
605 if (!pdata && client->dev.of_node) {
606 pdata = max8973_parse_dt(&client->dev);
607 pdata_from_dt = true;
611 dev_err(&client->dev, "No Platform data");
615 if (pdata->dvs_gpio == -EPROBE_DEFER)
616 return -EPROBE_DEFER;
618 max = devm_kzalloc(&client->dev, sizeof(*max), GFP_KERNEL);
622 max->regmap = devm_regmap_init_i2c(client, &max8973_regmap_config);
623 if (IS_ERR(max->regmap)) {
624 ret = PTR_ERR(max->regmap);
625 dev_err(&client->dev, "regmap init failed, err %d\n", ret);
629 if (client->dev.of_node) {
630 const struct of_device_id *match;
632 match = of_match_device(of_match_ptr(of_max8973_match_tbl),
636 max->id = (u32)((uintptr_t)match->data);
638 max->id = id->driver_data;
641 ret = regmap_read(max->regmap, MAX8973_CHIPID1, &chip_id);
643 dev_err(&client->dev, "register CHIPID1 read failed, %d", ret);
647 dev_info(&client->dev, "CHIP-ID OTP: 0x%02x ID_M: 0x%02x\n",
648 (chip_id >> 4) & 0xF, (chip_id >> 1) & 0x7);
650 i2c_set_clientdata(client, max);
651 max->ops = max8973_dcdc_ops;
652 max->dev = &client->dev;
653 max->desc.name = id->name;
655 max->desc.ops = &max->ops;
656 max->desc.type = REGULATOR_VOLTAGE;
657 max->desc.owner = THIS_MODULE;
658 max->desc.min_uV = MAX8973_MIN_VOLATGE;
659 max->desc.uV_step = MAX8973_VOLATGE_STEP;
660 max->desc.n_voltages = MAX8973_BUCK_N_VOLTAGE;
661 max->desc.ramp_reg = MAX8973_CONTROL1;
662 max->desc.ramp_mask = MAX8973_RAMP_MASK;
663 max->desc.ramp_delay_table = max8973_buck_ramp_table;
664 max->desc.n_ramp_values = ARRAY_SIZE(max8973_buck_ramp_table);
666 max->dvs_gpio = (pdata->dvs_gpio) ? pdata->dvs_gpio : -EINVAL;
667 max->enable_external_control = pdata->enable_ext_control;
668 max->curr_gpio_val = pdata->dvs_def_state;
669 max->curr_vout_reg = MAX8973_VOUT + pdata->dvs_def_state;
670 max->junction_temp_warning = pdata->junction_temp_warning;
672 max->lru_index[0] = max->curr_vout_reg;
674 if (gpio_is_valid(max->dvs_gpio)) {
678 gpio_flags = (pdata->dvs_def_state) ?
679 GPIOF_OUT_INIT_HIGH : GPIOF_OUT_INIT_LOW;
680 ret = devm_gpio_request_one(&client->dev, max->dvs_gpio,
681 gpio_flags, "max8973-dvs");
683 dev_err(&client->dev,
684 "gpio_request for gpio %d failed, err = %d\n",
690 * Initialize the lru index with vout_reg id
691 * The index 0 will be most recently used and
692 * set with the max->curr_vout_reg */
693 for (i = 0; i < MAX8973_MAX_VOUT_REG; ++i)
694 max->lru_index[i] = i;
695 max->lru_index[0] = max->curr_vout_reg;
696 max->lru_index[max->curr_vout_reg] = 0;
699 * If there is no DVS GPIO, the VOUT register
702 max->ops.set_voltage_sel = regulator_set_voltage_sel_regmap;
703 max->ops.get_voltage_sel = regulator_get_voltage_sel_regmap;
704 max->desc.vsel_reg = max->curr_vout_reg;
705 max->desc.vsel_mask = MAX8973_VOUT_MASK;
709 pdata->reg_init_data = of_get_regulator_init_data(&client->dev,
710 client->dev.of_node, &max->desc);
712 ridata = pdata->reg_init_data;
715 if (!pdata->enable_ext_control) {
716 max->desc.enable_reg = MAX8973_VOUT;
717 max->desc.enable_mask = MAX8973_VOUT_ENABLE;
718 max->ops.enable = regulator_enable_regmap;
719 max->ops.disable = regulator_disable_regmap;
720 max->ops.is_enabled = regulator_is_enabled_regmap;
724 if (ridata && (ridata->constraints.always_on ||
725 ridata->constraints.boot_on))
726 gflags = GPIOD_OUT_HIGH;
728 gflags = GPIOD_OUT_LOW;
729 gflags |= GPIOD_FLAGS_BIT_NONEXCLUSIVE;
730 gpiod = devm_gpiod_get_optional(&client->dev,
734 return PTR_ERR(gpiod);
736 config.ena_gpiod = gpiod;
737 max->enable_external_control = true;
744 * We do not let the core switch this regulator on/off,
745 * we just leave it on.
747 gpiod = devm_gpiod_get_optional(&client->dev,
751 return PTR_ERR(gpiod);
753 max->enable_external_control = true;
755 max->desc.enable_reg = MAX8973_VOUT;
756 max->desc.enable_mask = MAX8973_VOUT_ENABLE;
757 max->ops.enable = regulator_enable_regmap;
758 max->ops.disable = regulator_disable_regmap;
759 max->ops.is_enabled = regulator_is_enabled_regmap;
760 max->ops.set_current_limit = max8973_set_current_limit;
761 max->ops.get_current_limit = max8973_get_current_limit;
767 ret = max8973_init_dcdc(max, pdata);
769 dev_err(max->dev, "Max8973 Init failed, err = %d\n", ret);
773 config.dev = &client->dev;
774 config.init_data = pdata->reg_init_data;
775 config.driver_data = max;
776 config.of_node = client->dev.of_node;
777 config.regmap = max->regmap;
780 * Register the regulators
781 * Turn the GPIO descriptor over to the regulator core for
782 * lifecycle management if we pass an ena_gpiod.
784 if (config.ena_gpiod)
785 devm_gpiod_unhinge(&client->dev, config.ena_gpiod);
786 rdev = devm_regulator_register(&client->dev, &max->desc, &config);
789 dev_err(max->dev, "regulator register failed, err %d\n", ret);
793 max8973_thermal_init(max);
797 static const struct i2c_device_id max8973_id[] = {
798 {.name = "max8973", .driver_data = MAX8973},
799 {.name = "max77621", .driver_data = MAX77621},
802 MODULE_DEVICE_TABLE(i2c, max8973_id);
804 static struct i2c_driver max8973_i2c_driver = {
807 .probe_type = PROBE_PREFER_ASYNCHRONOUS,
808 .of_match_table = of_max8973_match_tbl,
810 .probe = max8973_probe,
811 .id_table = max8973_id,
814 static int __init max8973_init(void)
816 return i2c_add_driver(&max8973_i2c_driver);
818 subsys_initcall(max8973_init);
820 static void __exit max8973_cleanup(void)
822 i2c_del_driver(&max8973_i2c_driver);
824 module_exit(max8973_cleanup);
826 MODULE_AUTHOR("Laxman Dewangan <ldewangan@nvidia.com>");
827 MODULE_DESCRIPTION("MAX8973 voltage regulator driver");
828 MODULE_LICENSE("GPL v2");