aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Documentation/devicetree/bindings/regulator/max8973-regulator.txt21
-rw-r--r--drivers/regulator/max8973-regulator.c49
2 files changed, 53 insertions, 17 deletions
diff --git a/Documentation/devicetree/bindings/regulator/max8973-regulator.txt b/Documentation/devicetree/bindings/regulator/max8973-regulator.txt
new file mode 100644
index 000000000000..4f15d8a1bfd0
--- /dev/null
+++ b/Documentation/devicetree/bindings/regulator/max8973-regulator.txt
@@ -0,0 +1,21 @@
1* Maxim MAX8973 Voltage Regulator
2
3Required properties:
4
5- compatible: must be "maxim,max8973"
6- reg: the i2c slave address of the regulator. It should be 0x1b.
7
8Any standard regulator properties can be used to configure the single max8973
9DCDC.
10
11Example:
12
13 max8973@1b {
14 compatible = "maxim,max8973";
15 reg = <0x1b>;
16
17 regulator-min-microvolt = <935000>;
18 regulator-max-microvolt = <1200000>;
19 regulator-boot-on;
20 regulator-always-on;
21 };
diff --git a/drivers/regulator/max8973-regulator.c b/drivers/regulator/max8973-regulator.c
index adb1414e5e37..0c5195a842e2 100644
--- a/drivers/regulator/max8973-regulator.c
+++ b/drivers/regulator/max8973-regulator.c
@@ -26,10 +26,12 @@
26#include <linux/module.h> 26#include <linux/module.h>
27#include <linux/init.h> 27#include <linux/init.h>
28#include <linux/err.h> 28#include <linux/err.h>
29#include <linux/of.h>
29#include <linux/platform_device.h> 30#include <linux/platform_device.h>
30#include <linux/regulator/driver.h> 31#include <linux/regulator/driver.h>
31#include <linux/regulator/machine.h> 32#include <linux/regulator/machine.h>
32#include <linux/regulator/max8973-regulator.h> 33#include <linux/regulator/max8973-regulator.h>
34#include <linux/regulator/of_regulator.h>
33#include <linux/gpio.h> 35#include <linux/gpio.h>
34#include <linux/i2c.h> 36#include <linux/i2c.h>
35#include <linux/slab.h> 37#include <linux/slab.h>
@@ -100,6 +102,7 @@ struct max8973_chip {
100 int curr_vout_reg; 102 int curr_vout_reg;
101 int curr_gpio_val; 103 int curr_gpio_val;
102 bool valid_dvs_gpio; 104 bool valid_dvs_gpio;
105 struct regulator_ops ops;
103}; 106};
104 107
105/* 108/*
@@ -240,7 +243,7 @@ static unsigned int max8973_dcdc_get_mode(struct regulator_dev *rdev)
240 REGULATOR_MODE_FAST : REGULATOR_MODE_NORMAL; 243 REGULATOR_MODE_FAST : REGULATOR_MODE_NORMAL;
241} 244}
242 245
243static struct regulator_ops max8973_dcdc_ops = { 246static const struct regulator_ops max8973_dcdc_ops = {
244 .get_voltage_sel = max8973_dcdc_get_voltage_sel, 247 .get_voltage_sel = max8973_dcdc_get_voltage_sel,
245 .set_voltage_sel = max8973_dcdc_set_voltage_sel, 248 .set_voltage_sel = max8973_dcdc_set_voltage_sel,
246 .list_voltage = regulator_list_voltage_linear, 249 .list_voltage = regulator_list_voltage_linear,
@@ -369,7 +372,8 @@ static int max8973_probe(struct i2c_client *client,
369 int ret; 372 int ret;
370 373
371 pdata = client->dev.platform_data; 374 pdata = client->dev.platform_data;
372 if (!pdata) { 375
376 if (!pdata && !client->dev.of_node) {
373 dev_err(&client->dev, "No Platform data"); 377 dev_err(&client->dev, "No Platform data");
374 return -EIO; 378 return -EIO;
375 } 379 }
@@ -388,30 +392,36 @@ static int max8973_probe(struct i2c_client *client,
388 } 392 }
389 393
390 i2c_set_clientdata(client, max); 394 i2c_set_clientdata(client, max);
395 max->ops = max8973_dcdc_ops;
391 max->dev = &client->dev; 396 max->dev = &client->dev;
392 max->desc.name = id->name; 397 max->desc.name = id->name;
393 max->desc.id = 0; 398 max->desc.id = 0;
394 max->desc.ops = &max8973_dcdc_ops; 399 max->desc.ops = &max->ops;
395 max->desc.type = REGULATOR_VOLTAGE; 400 max->desc.type = REGULATOR_VOLTAGE;
396 max->desc.owner = THIS_MODULE; 401 max->desc.owner = THIS_MODULE;
397 max->desc.min_uV = MAX8973_MIN_VOLATGE; 402 max->desc.min_uV = MAX8973_MIN_VOLATGE;
398 max->desc.uV_step = MAX8973_VOLATGE_STEP; 403 max->desc.uV_step = MAX8973_VOLATGE_STEP;
399 max->desc.n_voltages = MAX8973_BUCK_N_VOLTAGE; 404 max->desc.n_voltages = MAX8973_BUCK_N_VOLTAGE;
400 405
401 if (!pdata->enable_ext_control) { 406 if (!pdata || !pdata->enable_ext_control) {
402 max->desc.enable_reg = MAX8973_VOUT; 407 max->desc.enable_reg = MAX8973_VOUT;
403 max->desc.enable_mask = MAX8973_VOUT_ENABLE; 408 max->desc.enable_mask = MAX8973_VOUT_ENABLE;
404 max8973_dcdc_ops.enable = regulator_enable_regmap; 409 max->ops.enable = regulator_enable_regmap;
405 max8973_dcdc_ops.disable = regulator_disable_regmap; 410 max->ops.disable = regulator_disable_regmap;
406 max8973_dcdc_ops.is_enabled = regulator_is_enabled_regmap; 411 max->ops.is_enabled = regulator_is_enabled_regmap;
412 }
413
414 if (pdata) {
415 max->dvs_gpio = pdata->dvs_gpio;
416 max->enable_external_control = pdata->enable_ext_control;
417 max->curr_gpio_val = pdata->dvs_def_state;
418 max->curr_vout_reg = MAX8973_VOUT + pdata->dvs_def_state;
419 } else {
420 max->dvs_gpio = -EINVAL;
421 max->curr_vout_reg = MAX8973_VOUT;
407 } 422 }
408 423
409 max->enable_external_control = pdata->enable_ext_control;
410 max->dvs_gpio = pdata->dvs_gpio;
411 max->curr_gpio_val = pdata->dvs_def_state;
412 max->curr_vout_reg = MAX8973_VOUT + pdata->dvs_def_state;
413 max->lru_index[0] = max->curr_vout_reg; 424 max->lru_index[0] = max->curr_vout_reg;
414 max->valid_dvs_gpio = false;
415 425
416 if (gpio_is_valid(max->dvs_gpio)) { 426 if (gpio_is_valid(max->dvs_gpio)) {
417 int gpio_flags; 427 int gpio_flags;
@@ -437,16 +447,21 @@ static int max8973_probe(struct i2c_client *client,
437 max->lru_index[i] = i; 447 max->lru_index[i] = i;
438 max->lru_index[0] = max->curr_vout_reg; 448 max->lru_index[0] = max->curr_vout_reg;
439 max->lru_index[max->curr_vout_reg] = 0; 449 max->lru_index[max->curr_vout_reg] = 0;
450 } else {
451 max->valid_dvs_gpio = false;
440 } 452 }
441 453
442 ret = max8973_init_dcdc(max, pdata); 454 if (pdata) {
443 if (ret < 0) { 455 ret = max8973_init_dcdc(max, pdata);
444 dev_err(max->dev, "Max8973 Init failed, err = %d\n", ret); 456 if (ret < 0) {
445 return ret; 457 dev_err(max->dev, "Max8973 Init failed, err = %d\n", ret);
458 return ret;
459 }
446 } 460 }
447 461
448 config.dev = &client->dev; 462 config.dev = &client->dev;
449 config.init_data = pdata->reg_init_data; 463 config.init_data = pdata ? pdata->reg_init_data :
464 of_get_regulator_init_data(&client->dev, client->dev.of_node);
450 config.driver_data = max; 465 config.driver_data = max;
451 config.of_node = client->dev.of_node; 466 config.of_node = client->dev.of_node;
452 config.regmap = max->regmap; 467 config.regmap = max->regmap;