From db892ff6c0f49708f13d9dff3957034f2f90e1c1 Mon Sep 17 00:00:00 2001 From: Guennadi Liakhovetski Date: Fri, 21 Jun 2013 08:30:22 +0200 Subject: regulators: max8973: fix multiple instance support Currently the max8973 regulator driver uses a single static struct of regulator operations for all chip instances, but can overwrite some of its members depending on configuration. This will affect all other MAX8973 instances on the system. This patch fixes this bug by allocating a separate copy of the struct for each chip instance. Signed-off-by: Guennadi Liakhovetski Signed-off-by: Mark Brown --- drivers/regulator/max8973-regulator.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/drivers/regulator/max8973-regulator.c b/drivers/regulator/max8973-regulator.c index adb1414e5e37..b2dbdd70cab1 100644 --- a/drivers/regulator/max8973-regulator.c +++ b/drivers/regulator/max8973-regulator.c @@ -100,6 +100,7 @@ struct max8973_chip { int curr_vout_reg; int curr_gpio_val; bool valid_dvs_gpio; + struct regulator_ops ops; }; /* @@ -240,7 +241,7 @@ static unsigned int max8973_dcdc_get_mode(struct regulator_dev *rdev) REGULATOR_MODE_FAST : REGULATOR_MODE_NORMAL; } -static struct regulator_ops max8973_dcdc_ops = { +static const struct regulator_ops max8973_dcdc_ops = { .get_voltage_sel = max8973_dcdc_get_voltage_sel, .set_voltage_sel = max8973_dcdc_set_voltage_sel, .list_voltage = regulator_list_voltage_linear, @@ -388,10 +389,11 @@ static int max8973_probe(struct i2c_client *client, } i2c_set_clientdata(client, max); + max->ops = max8973_dcdc_ops; max->dev = &client->dev; max->desc.name = id->name; max->desc.id = 0; - max->desc.ops = &max8973_dcdc_ops; + max->desc.ops = &max->ops; max->desc.type = REGULATOR_VOLTAGE; max->desc.owner = THIS_MODULE; max->desc.min_uV = MAX8973_MIN_VOLATGE; @@ -401,9 +403,9 @@ static int max8973_probe(struct i2c_client *client, if (!pdata->enable_ext_control) { max->desc.enable_reg = MAX8973_VOUT; max->desc.enable_mask = MAX8973_VOUT_ENABLE; - max8973_dcdc_ops.enable = regulator_enable_regmap; - max8973_dcdc_ops.disable = regulator_disable_regmap; - max8973_dcdc_ops.is_enabled = regulator_is_enabled_regmap; + max->ops.enable = regulator_enable_regmap; + max->ops.disable = regulator_disable_regmap; + max->ops.is_enabled = regulator_is_enabled_regmap; } max->enable_external_control = pdata->enable_ext_control; -- cgit v1.2.3 From 42dc30231ba35939213c33378c17cb81c31b0a37 Mon Sep 17 00:00:00 2001 From: Guennadi Liakhovetski Date: Mon, 24 Jun 2013 12:50:16 +0200 Subject: regulator: max8973: initial DT support This patch adds primitive DT support to the max8973 regulator driver. None of the configuration parameters, supported in the platform data are yet available in DT, therefore no configuration is performed if booting with no platform data. This means, that DT instantiation can only be used on boards, where no run-time configuration of the chip is required. In such cases the driver can be used to scale its output voltage. In the future support for configuration parameters should be added. Signed-off-by: Guennadi Liakhovetski Signed-off-by: Mark Brown --- .../bindings/regulator/max8973-regulator.txt | 21 ++++++++++++ drivers/regulator/max8973-regulator.c | 37 +++++++++++++++------- 2 files changed, 46 insertions(+), 12 deletions(-) create mode 100644 Documentation/devicetree/bindings/regulator/max8973-regulator.txt diff --git a/Documentation/devicetree/bindings/regulator/max8973-regulator.txt b/Documentation/devicetree/bindings/regulator/max8973-regulator.txt new file mode 100644 index 000000000000..8d38ab2acac5 --- /dev/null +++ b/Documentation/devicetree/bindings/regulator/max8973-regulator.txt @@ -0,0 +1,21 @@ +* Maxim MAX8973 Voltage Regulator + +Required properties: + +- compatible: must be "maxium,max8973" +- reg: the i2c slave address of the regulator. It should be 0x1b. + +Any standard regulator properties can be used to configure the single max8973 +DCDC. + +Example: + + max8973@1b { + compatible = "maxium,max8973"; + reg = <0x1b>; + + regulator-min-microvolt = <935000>; + regulator-max-microvolt = <1200000>; + regulator-boot-on; + regulator-always-on; + }; diff --git a/drivers/regulator/max8973-regulator.c b/drivers/regulator/max8973-regulator.c index b2dbdd70cab1..0c5195a842e2 100644 --- a/drivers/regulator/max8973-regulator.c +++ b/drivers/regulator/max8973-regulator.c @@ -26,10 +26,12 @@ #include #include #include +#include #include #include #include #include +#include #include #include #include @@ -370,7 +372,8 @@ static int max8973_probe(struct i2c_client *client, int ret; pdata = client->dev.platform_data; - if (!pdata) { + + if (!pdata && !client->dev.of_node) { dev_err(&client->dev, "No Platform data"); return -EIO; } @@ -400,7 +403,7 @@ static int max8973_probe(struct i2c_client *client, max->desc.uV_step = MAX8973_VOLATGE_STEP; max->desc.n_voltages = MAX8973_BUCK_N_VOLTAGE; - if (!pdata->enable_ext_control) { + if (!pdata || !pdata->enable_ext_control) { max->desc.enable_reg = MAX8973_VOUT; max->desc.enable_mask = MAX8973_VOUT_ENABLE; max->ops.enable = regulator_enable_regmap; @@ -408,12 +411,17 @@ static int max8973_probe(struct i2c_client *client, max->ops.is_enabled = regulator_is_enabled_regmap; } - max->enable_external_control = pdata->enable_ext_control; - max->dvs_gpio = pdata->dvs_gpio; - max->curr_gpio_val = pdata->dvs_def_state; - max->curr_vout_reg = MAX8973_VOUT + pdata->dvs_def_state; + if (pdata) { + max->dvs_gpio = pdata->dvs_gpio; + max->enable_external_control = pdata->enable_ext_control; + max->curr_gpio_val = pdata->dvs_def_state; + max->curr_vout_reg = MAX8973_VOUT + pdata->dvs_def_state; + } else { + max->dvs_gpio = -EINVAL; + max->curr_vout_reg = MAX8973_VOUT; + } + max->lru_index[0] = max->curr_vout_reg; - max->valid_dvs_gpio = false; if (gpio_is_valid(max->dvs_gpio)) { int gpio_flags; @@ -439,16 +447,21 @@ static int max8973_probe(struct i2c_client *client, max->lru_index[i] = i; max->lru_index[0] = max->curr_vout_reg; max->lru_index[max->curr_vout_reg] = 0; + } else { + max->valid_dvs_gpio = false; } - ret = max8973_init_dcdc(max, pdata); - if (ret < 0) { - dev_err(max->dev, "Max8973 Init failed, err = %d\n", ret); - return ret; + if (pdata) { + ret = max8973_init_dcdc(max, pdata); + if (ret < 0) { + dev_err(max->dev, "Max8973 Init failed, err = %d\n", ret); + return ret; + } } config.dev = &client->dev; - config.init_data = pdata->reg_init_data; + config.init_data = pdata ? pdata->reg_init_data : + of_get_regulator_init_data(&client->dev, client->dev.of_node); config.driver_data = max; config.of_node = client->dev.of_node; config.regmap = max->regmap; -- cgit v1.2.3 From f986c35689996caddfddb096ead8095c91f7f155 Mon Sep 17 00:00:00 2001 From: Guennadi Liakhovetski Date: Tue, 25 Jun 2013 09:07:06 +0200 Subject: regulator: max8973: fix a typo in documentation Fix a s/maxium/maxim/ typo in DT binding documentation. Reported-by: Sergei Shtylyov Signed-off-by: Guennadi Liakhovetski Signed-off-by: Mark Brown --- Documentation/devicetree/bindings/regulator/max8973-regulator.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Documentation/devicetree/bindings/regulator/max8973-regulator.txt b/Documentation/devicetree/bindings/regulator/max8973-regulator.txt index 8d38ab2acac5..4f15d8a1bfd0 100644 --- a/Documentation/devicetree/bindings/regulator/max8973-regulator.txt +++ b/Documentation/devicetree/bindings/regulator/max8973-regulator.txt @@ -2,7 +2,7 @@ Required properties: -- compatible: must be "maxium,max8973" +- compatible: must be "maxim,max8973" - reg: the i2c slave address of the regulator. It should be 0x1b. Any standard regulator properties can be used to configure the single max8973 @@ -11,7 +11,7 @@ DCDC. Example: max8973@1b { - compatible = "maxium,max8973"; + compatible = "maxim,max8973"; reg = <0x1b>; regulator-min-microvolt = <935000>; -- cgit v1.2.3