aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLinus Walleij <linus.walleij@linaro.org>2018-05-14 04:06:25 -0400
committerMark Brown <broonie@kernel.org>2018-05-24 11:50:25 -0400
commite7d2be696faa3c8add5b21006ad8fec6b6ed85f1 (patch)
tree13a8e25768aba026af97574d41b5bf41630362f2
parent910adc0e1bf50cc4c9eddf1d8764e6fe4055adf4 (diff)
regulator: max8973: Pass descriptor instead of GPIO number
Instead of passing a global GPIO number, pass a descriptor looked up with the standard devm_gpiod_get_optional() call. Signed-off-by: Linus Walleij <linus.walleij@linaro.org> Signed-off-by: Mark Brown <broonie@kernel.org>
-rw-r--r--drivers/regulator/max8973-regulator.c54
1 files changed, 29 insertions, 25 deletions
diff --git a/drivers/regulator/max8973-regulator.c b/drivers/regulator/max8973-regulator.c
index e0c747aa9f85..7cd493ec6315 100644
--- a/drivers/regulator/max8973-regulator.c
+++ b/drivers/regulator/max8973-regulator.c
@@ -34,6 +34,7 @@
34#include <linux/regulator/max8973-regulator.h> 34#include <linux/regulator/max8973-regulator.h>
35#include <linux/regulator/of_regulator.h> 35#include <linux/regulator/of_regulator.h>
36#include <linux/gpio.h> 36#include <linux/gpio.h>
37#include <linux/gpio/consumer.h>
37#include <linux/of_gpio.h> 38#include <linux/of_gpio.h>
38#include <linux/i2c.h> 39#include <linux/i2c.h>
39#include <linux/slab.h> 40#include <linux/slab.h>
@@ -114,7 +115,6 @@ struct max8973_chip {
114 struct regulator_desc desc; 115 struct regulator_desc desc;
115 struct regmap *regmap; 116 struct regmap *regmap;
116 bool enable_external_control; 117 bool enable_external_control;
117 int enable_gpio;
118 int dvs_gpio; 118 int dvs_gpio;
119 int lru_index[MAX8973_MAX_VOUT_REG]; 119 int lru_index[MAX8973_MAX_VOUT_REG];
120 int curr_vout_val[MAX8973_MAX_VOUT_REG]; 120 int curr_vout_val[MAX8973_MAX_VOUT_REG];
@@ -567,7 +567,6 @@ static struct max8973_regulator_platform_data *max8973_parse_dt(
567 567
568 pdata->enable_ext_control = of_property_read_bool(np, 568 pdata->enable_ext_control = of_property_read_bool(np,
569 "maxim,externally-enable"); 569 "maxim,externally-enable");
570 pdata->enable_gpio = of_get_named_gpio(np, "maxim,enable-gpio", 0);
571 pdata->dvs_gpio = of_get_named_gpio(np, "maxim,dvs-gpio", 0); 570 pdata->dvs_gpio = of_get_named_gpio(np, "maxim,dvs-gpio", 0);
572 571
573 ret = of_property_read_u32(np, "maxim,dvs-default-state", &pval); 572 ret = of_property_read_u32(np, "maxim,dvs-default-state", &pval);
@@ -633,6 +632,8 @@ static int max8973_probe(struct i2c_client *client,
633 struct max8973_chip *max; 632 struct max8973_chip *max;
634 bool pdata_from_dt = false; 633 bool pdata_from_dt = false;
635 unsigned int chip_id; 634 unsigned int chip_id;
635 struct gpio_desc *gpiod;
636 enum gpiod_flags gflags;
636 int ret; 637 int ret;
637 638
638 pdata = dev_get_platdata(&client->dev); 639 pdata = dev_get_platdata(&client->dev);
@@ -647,8 +648,7 @@ static int max8973_probe(struct i2c_client *client,
647 return -EIO; 648 return -EIO;
648 } 649 }
649 650
650 if ((pdata->dvs_gpio == -EPROBE_DEFER) || 651 if (pdata->dvs_gpio == -EPROBE_DEFER)
651 (pdata->enable_gpio == -EPROBE_DEFER))
652 return -EPROBE_DEFER; 652 return -EPROBE_DEFER;
653 653
654 max = devm_kzalloc(&client->dev, sizeof(*max), GFP_KERNEL); 654 max = devm_kzalloc(&client->dev, sizeof(*max), GFP_KERNEL);
@@ -696,15 +696,11 @@ static int max8973_probe(struct i2c_client *client,
696 max->desc.n_voltages = MAX8973_BUCK_N_VOLTAGE; 696 max->desc.n_voltages = MAX8973_BUCK_N_VOLTAGE;
697 697
698 max->dvs_gpio = (pdata->dvs_gpio) ? pdata->dvs_gpio : -EINVAL; 698 max->dvs_gpio = (pdata->dvs_gpio) ? pdata->dvs_gpio : -EINVAL;
699 max->enable_gpio = (pdata->enable_gpio) ? pdata->enable_gpio : -EINVAL;
700 max->enable_external_control = pdata->enable_ext_control; 699 max->enable_external_control = pdata->enable_ext_control;
701 max->curr_gpio_val = pdata->dvs_def_state; 700 max->curr_gpio_val = pdata->dvs_def_state;
702 max->curr_vout_reg = MAX8973_VOUT + pdata->dvs_def_state; 701 max->curr_vout_reg = MAX8973_VOUT + pdata->dvs_def_state;
703 max->junction_temp_warning = pdata->junction_temp_warning; 702 max->junction_temp_warning = pdata->junction_temp_warning;
704 703
705 if (gpio_is_valid(max->enable_gpio))
706 max->enable_external_control = true;
707
708 max->lru_index[0] = max->curr_vout_reg; 704 max->lru_index[0] = max->curr_vout_reg;
709 705
710 if (gpio_is_valid(max->dvs_gpio)) { 706 if (gpio_is_valid(max->dvs_gpio)) {
@@ -757,27 +753,35 @@ static int max8973_probe(struct i2c_client *client,
757 break; 753 break;
758 } 754 }
759 755
760 if (gpio_is_valid(max->enable_gpio)) { 756 if (ridata && (ridata->constraints.always_on ||
761 config.ena_gpio_flags = GPIOF_OUT_INIT_LOW; 757 ridata->constraints.boot_on))
762 if (ridata && (ridata->constraints.always_on || 758 gflags = GPIOD_OUT_HIGH;
763 ridata->constraints.boot_on)) 759 else
764 config.ena_gpio_flags = GPIOF_OUT_INIT_HIGH; 760 gflags = GPIOD_OUT_LOW;
765 config.ena_gpio = max->enable_gpio; 761 gpiod = devm_gpiod_get_optional(&client->dev,
762 "maxim,enable",
763 gflags);
764 if (IS_ERR(gpiod))
765 return PTR_ERR(gpiod);
766 if (gpiod) {
767 config.ena_gpiod = gpiod;
768 max->enable_external_control = true;
766 } 769 }
770
767 break; 771 break;
768 772
769 case MAX77621: 773 case MAX77621:
770 if (gpio_is_valid(max->enable_gpio)) { 774 /*
771 ret = devm_gpio_request_one(&client->dev, 775 * We do not let the core switch this regulator on/off,
772 max->enable_gpio, GPIOF_OUT_INIT_HIGH, 776 * we just leave it on.
773 "max8973-en-gpio"); 777 */
774 if (ret) { 778 gpiod = devm_gpiod_get_optional(&client->dev,
775 dev_err(&client->dev, 779 "maxim,enable",
776 "gpio_request for gpio %d failed: %d\n", 780 GPIOD_OUT_HIGH);
777 max->enable_gpio, ret); 781 if (IS_ERR(gpiod))
778 return ret; 782 return PTR_ERR(gpiod);
779 } 783 if (gpiod)
780 } 784 max->enable_external_control = true;
781 785
782 max->desc.enable_reg = MAX8973_VOUT; 786 max->desc.enable_reg = MAX8973_VOUT;
783 max->desc.enable_mask = MAX8973_VOUT_ENABLE; 787 max->desc.enable_mask = MAX8973_VOUT_ENABLE;