From c6a21f246263dfe1689d827af4200c64679dcc77 Mon Sep 17 00:00:00 2001 From: Jingoo Han Date: Mon, 14 Oct 2013 17:51:19 +0900 Subject: [PATCH 01/13] regulator: mc13892: Fix checkpatch issue Fix the following checkpatch warnings. WARNING: Avoid unnecessary line continuations WARNING: line over 80 characters Signed-off-by: Jingoo Han Signed-off-by: Mark Brown --- drivers/regulator/mc13892-regulator.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/drivers/regulator/mc13892-regulator.c b/drivers/regulator/mc13892-regulator.c index 1037e07937cf..35bd53ba4a48 100644 --- a/drivers/regulator/mc13892-regulator.c +++ b/drivers/regulator/mc13892-regulator.c @@ -274,25 +274,25 @@ static struct mc13xxx_regulator mc13892_regulators[] = { MC13892_SW_DEFINE(SW4, SWITCHERS3, SWITCHERS3, mc13892_sw), MC13892_FIXED_DEFINE(SWBST, SWITCHERS5, mc13892_swbst), MC13892_FIXED_DEFINE(VIOHI, REGULATORMODE0, mc13892_viohi), - MC13892_DEFINE_REGU(VPLL, REGULATORMODE0, REGULATORSETTING0, \ + MC13892_DEFINE_REGU(VPLL, REGULATORMODE0, REGULATORSETTING0, mc13892_vpll), - MC13892_DEFINE_REGU(VDIG, REGULATORMODE0, REGULATORSETTING0, \ + MC13892_DEFINE_REGU(VDIG, REGULATORMODE0, REGULATORSETTING0, mc13892_vdig), - MC13892_DEFINE_REGU(VSD, REGULATORMODE1, REGULATORSETTING1, \ + MC13892_DEFINE_REGU(VSD, REGULATORMODE1, REGULATORSETTING1, mc13892_vsd), - MC13892_DEFINE_REGU(VUSB2, REGULATORMODE0, REGULATORSETTING0, \ + MC13892_DEFINE_REGU(VUSB2, REGULATORMODE0, REGULATORSETTING0, mc13892_vusb2), - MC13892_DEFINE_REGU(VVIDEO, REGULATORMODE1, REGULATORSETTING1, \ + MC13892_DEFINE_REGU(VVIDEO, REGULATORMODE1, REGULATORSETTING1, mc13892_vvideo), - MC13892_DEFINE_REGU(VAUDIO, REGULATORMODE1, REGULATORSETTING1, \ + MC13892_DEFINE_REGU(VAUDIO, REGULATORMODE1, REGULATORSETTING1, mc13892_vaudio), - MC13892_DEFINE_REGU(VCAM, REGULATORMODE1, REGULATORSETTING0, \ + MC13892_DEFINE_REGU(VCAM, REGULATORMODE1, REGULATORSETTING0, mc13892_vcam), - MC13892_DEFINE_REGU(VGEN1, REGULATORMODE0, REGULATORSETTING0, \ + MC13892_DEFINE_REGU(VGEN1, REGULATORMODE0, REGULATORSETTING0, mc13892_vgen1), - MC13892_DEFINE_REGU(VGEN2, REGULATORMODE0, REGULATORSETTING0, \ + MC13892_DEFINE_REGU(VGEN2, REGULATORMODE0, REGULATORSETTING0, mc13892_vgen2), - MC13892_DEFINE_REGU(VGEN3, REGULATORMODE1, REGULATORSETTING0, \ + MC13892_DEFINE_REGU(VGEN3, REGULATORMODE1, REGULATORSETTING0, mc13892_vgen3), MC13892_FIXED_DEFINE(VUSB, USB1, mc13892_vusb), MC13892_GPO_DEFINE(GPO1, POWERMISC, mc13892_gpo), @@ -476,8 +476,8 @@ static int mc13892_sw_regulator_set_voltage_sel(struct regulator_dev *rdev, } mc13xxx_lock(priv->mc13xxx); - ret = mc13xxx_reg_rmw(priv->mc13xxx, mc13892_regulators[id].vsel_reg, mask, - reg_value); + ret = mc13xxx_reg_rmw(priv->mc13xxx, mc13892_regulators[id].vsel_reg, + mask, reg_value); mc13xxx_unlock(priv->mc13xxx); return ret; From 56dde80a1a62b1f84f9ba7d2aee267dc9476ee58 Mon Sep 17 00:00:00 2001 From: Axel Lin Date: Wed, 13 Nov 2013 14:52:26 +0800 Subject: [PATCH 02/13] regulator: lp3971: Convert to devm_regulator_register Both num_regulators and **rdev are no longer required after this conversion, thus remove them from struct lp3971. Signed-off-by: Axel Lin Signed-off-by: Mark Brown --- drivers/regulator/lp3971.c | 43 ++++++-------------------------------- 1 file changed, 6 insertions(+), 37 deletions(-) diff --git a/drivers/regulator/lp3971.c b/drivers/regulator/lp3971.c index 947c05ffe0ab..3b1102b75071 100644 --- a/drivers/regulator/lp3971.c +++ b/drivers/regulator/lp3971.c @@ -25,8 +25,6 @@ struct lp3971 { struct device *dev; struct mutex io_lock; struct i2c_client *i2c; - int num_regulators; - struct regulator_dev **rdev; }; static u8 lp3971_reg_read(struct lp3971 *lp3971, u8 reg); @@ -383,42 +381,27 @@ static int setup_regulators(struct lp3971 *lp3971, { int i, err; - lp3971->num_regulators = pdata->num_regulators; - lp3971->rdev = kcalloc(pdata->num_regulators, - sizeof(struct regulator_dev *), GFP_KERNEL); - if (!lp3971->rdev) { - err = -ENOMEM; - goto err_nomem; - } - /* Instantiate the regulators */ for (i = 0; i < pdata->num_regulators; i++) { struct regulator_config config = { }; struct lp3971_regulator_subdev *reg = &pdata->regulators[i]; + struct regulator_dev *rdev; config.dev = lp3971->dev; config.init_data = reg->initdata; config.driver_data = lp3971; - lp3971->rdev[i] = regulator_register(®ulators[reg->id], - &config); - if (IS_ERR(lp3971->rdev[i])) { - err = PTR_ERR(lp3971->rdev[i]); + rdev = devm_regulator_register(lp3971->dev, + ®ulators[reg->id], &config); + if (IS_ERR(rdev)) { + err = PTR_ERR(rdev); dev_err(lp3971->dev, "regulator init failed: %d\n", err); - goto error; + return err; } } return 0; - -error: - while (--i >= 0) - regulator_unregister(lp3971->rdev[i]); - kfree(lp3971->rdev); - lp3971->rdev = NULL; -err_nomem: - return err; } static int lp3971_i2c_probe(struct i2c_client *i2c, @@ -460,19 +443,6 @@ static int lp3971_i2c_probe(struct i2c_client *i2c, return 0; } -static int lp3971_i2c_remove(struct i2c_client *i2c) -{ - struct lp3971 *lp3971 = i2c_get_clientdata(i2c); - int i; - - for (i = 0; i < lp3971->num_regulators; i++) - regulator_unregister(lp3971->rdev[i]); - - kfree(lp3971->rdev); - - return 0; -} - static const struct i2c_device_id lp3971_i2c_id[] = { { "lp3971", 0 }, { } @@ -485,7 +455,6 @@ static struct i2c_driver lp3971_i2c_driver = { .owner = THIS_MODULE, }, .probe = lp3971_i2c_probe, - .remove = lp3971_i2c_remove, .id_table = lp3971_i2c_id, }; From 93227c801372522d6f667aac0de2cacc7995d8b9 Mon Sep 17 00:00:00 2001 From: Axel Lin Date: Wed, 13 Nov 2013 14:55:14 +0800 Subject: [PATCH 03/13] regulator: lp3972: Convert to devm_regulator_register Both num_regulators and **rdev are no longer required after this conversion, thus remove them from struct lp3972. Signed-off-by: Axel Lin Signed-off-by: Mark Brown --- drivers/regulator/lp3972.c | 41 ++++++-------------------------------- 1 file changed, 6 insertions(+), 35 deletions(-) diff --git a/drivers/regulator/lp3972.c b/drivers/regulator/lp3972.c index 093e6f44ff8a..aea485afcc1a 100644 --- a/drivers/regulator/lp3972.c +++ b/drivers/regulator/lp3972.c @@ -22,8 +22,6 @@ struct lp3972 { struct device *dev; struct mutex io_lock; struct i2c_client *i2c; - int num_regulators; - struct regulator_dev **rdev; }; /* LP3972 Control Registers */ @@ -478,41 +476,27 @@ static int setup_regulators(struct lp3972 *lp3972, { int i, err; - lp3972->num_regulators = pdata->num_regulators; - lp3972->rdev = kcalloc(pdata->num_regulators, - sizeof(struct regulator_dev *), GFP_KERNEL); - if (!lp3972->rdev) { - err = -ENOMEM; - goto err_nomem; - } - /* Instantiate the regulators */ for (i = 0; i < pdata->num_regulators; i++) { struct lp3972_regulator_subdev *reg = &pdata->regulators[i]; struct regulator_config config = { }; + struct regulator_dev *rdev; config.dev = lp3972->dev; config.init_data = reg->initdata; config.driver_data = lp3972; - lp3972->rdev[i] = regulator_register(®ulators[reg->id], - &config); - if (IS_ERR(lp3972->rdev[i])) { - err = PTR_ERR(lp3972->rdev[i]); + rdev = devm_regulator_register(lp3972->dev, + ®ulators[reg->id], &config); + if (IS_ERR(rdev)) { + err = PTR_ERR(rdev); dev_err(lp3972->dev, "regulator init failed: %d\n", err); - goto error; + return err; } } return 0; -error: - while (--i >= 0) - regulator_unregister(lp3972->rdev[i]); - kfree(lp3972->rdev); - lp3972->rdev = NULL; -err_nomem: - return err; } static int lp3972_i2c_probe(struct i2c_client *i2c, @@ -557,18 +541,6 @@ static int lp3972_i2c_probe(struct i2c_client *i2c, return 0; } -static int lp3972_i2c_remove(struct i2c_client *i2c) -{ - struct lp3972 *lp3972 = i2c_get_clientdata(i2c); - int i; - - for (i = 0; i < lp3972->num_regulators; i++) - regulator_unregister(lp3972->rdev[i]); - kfree(lp3972->rdev); - - return 0; -} - static const struct i2c_device_id lp3972_i2c_id[] = { { "lp3972", 0 }, { } @@ -581,7 +553,6 @@ static struct i2c_driver lp3972_i2c_driver = { .owner = THIS_MODULE, }, .probe = lp3972_i2c_probe, - .remove = lp3972_i2c_remove, .id_table = lp3972_i2c_id, }; From 561427f5ea106d57a8a84113c89ecf23a5c865bb Mon Sep 17 00:00:00 2001 From: Axel Lin Date: Sat, 30 Nov 2013 12:21:03 +0800 Subject: [PATCH 04/13] mfd: pcf50633: Correct device name for pcf50633 regulator Change the device name of the regulator function to the one chosen for MODULE_ALIAS. This fixes kernel auto-module loading for the regulator function. Signed-off-by: Axel Lin Acked-by: Lee Jones Signed-off-by: Mark Brown --- drivers/mfd/pcf50633-core.c | 2 +- drivers/regulator/pcf50633-regulator.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/mfd/pcf50633-core.c b/drivers/mfd/pcf50633-core.c index 6841d6805fd6..41ab5e34d2ac 100644 --- a/drivers/mfd/pcf50633-core.c +++ b/drivers/mfd/pcf50633-core.c @@ -245,7 +245,7 @@ static int pcf50633_probe(struct i2c_client *client, for (i = 0; i < PCF50633_NUM_REGULATORS; i++) { struct platform_device *pdev; - pdev = platform_device_alloc("pcf50633-regltr", i); + pdev = platform_device_alloc("pcf50633-regulator", i); if (!pdev) { dev_err(pcf->dev, "Cannot create regulator %d\n", i); continue; diff --git a/drivers/regulator/pcf50633-regulator.c b/drivers/regulator/pcf50633-regulator.c index d7da1c15a6da..134f90ec9ca1 100644 --- a/drivers/regulator/pcf50633-regulator.c +++ b/drivers/regulator/pcf50633-regulator.c @@ -105,7 +105,7 @@ static int pcf50633_regulator_probe(struct platform_device *pdev) static struct platform_driver pcf50633_regulator_driver = { .driver = { - .name = "pcf50633-regltr", + .name = "pcf50633-regulator", }, .probe = pcf50633_regulator_probe, }; From 5b1ada83bae7d689cf1fe76eb1bdd058ea84a97c Mon Sep 17 00:00:00 2001 From: Mark Brown Date: Thu, 5 Dec 2013 00:29:57 +0000 Subject: [PATCH 05/13] regulator: gpio: Don't require a regulator-type property Since essentially all GPIO controlled regulators are voltage regulators make the regulator-type property optional, defaulting to voltage. Signed-off-by: Mark Brown --- drivers/regulator/gpio-regulator.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/drivers/regulator/gpio-regulator.c b/drivers/regulator/gpio-regulator.c index bcd827c363dc..cdb9d947d914 100644 --- a/drivers/regulator/gpio-regulator.c +++ b/drivers/regulator/gpio-regulator.c @@ -203,17 +203,15 @@ of_get_gpio_regulator_config(struct device *dev, struct device_node *np) } config->nr_states = i; + config->type = REGULATOR_VOLTAGE; ret = of_property_read_string(np, "regulator-type", ®type); - if (ret < 0) { - dev_err(dev, "Missing 'regulator-type' property\n"); - return ERR_PTR(-EINVAL); + if (ret >= 0) { + if (!strncmp("voltage", regtype, 7)) + config->type = REGULATOR_VOLTAGE; + else if (!strncmp("current", regtype, 7)) + config->type = REGULATOR_CURRENT; } - if (!strncmp("voltage", regtype, 7)) - config->type = REGULATOR_VOLTAGE; - else if (!strncmp("current", regtype, 7)) - config->type = REGULATOR_CURRENT; - return config; } From 9eb9d3150bd941be2f2e370e0081736d9d51e31b Mon Sep 17 00:00:00 2001 From: Mark Brown Date: Thu, 5 Dec 2013 19:09:55 +0000 Subject: [PATCH 06/13] regulator: gpio: Warn if an invalid regulator-type is supplied Reported-by: Laurent Pinchart Acked-by: Laurent Pinchart Signed-off-by: Mark Brown --- drivers/regulator/gpio-regulator.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/regulator/gpio-regulator.c b/drivers/regulator/gpio-regulator.c index cdb9d947d914..49fe20f58d2a 100644 --- a/drivers/regulator/gpio-regulator.c +++ b/drivers/regulator/gpio-regulator.c @@ -210,6 +210,9 @@ of_get_gpio_regulator_config(struct device *dev, struct device_node *np) config->type = REGULATOR_VOLTAGE; else if (!strncmp("current", regtype, 7)) config->type = REGULATOR_CURRENT; + else + dev_warn(dev, "Unknown regulator-type '%s'\n", + regtype); } return config; From 92dfbdbcb504beb1d716e500cd20b4780961afd5 Mon Sep 17 00:00:00 2001 From: Jingoo Han Date: Fri, 6 Dec 2013 16:08:38 +0900 Subject: [PATCH 07/13] regulator: db8500-prcmu: use devm_regulator_register() Use devm_regulator_register() to make cleanup paths simpler. Signed-off-by: Jingoo Han Acked-by: Bengt Jonsson Signed-off-by: Mark Brown --- drivers/regulator/db8500-prcmu.c | 20 +------------------- 1 file changed, 1 insertion(+), 19 deletions(-) diff --git a/drivers/regulator/db8500-prcmu.c b/drivers/regulator/db8500-prcmu.c index a53c11a529d5..846acf240e48 100644 --- a/drivers/regulator/db8500-prcmu.c +++ b/drivers/regulator/db8500-prcmu.c @@ -431,17 +431,11 @@ static int db8500_regulator_register(struct platform_device *pdev, config.of_node = np; /* register with the regulator framework */ - info->rdev = regulator_register(&info->desc, &config); + info->rdev = devm_regulator_register(&pdev->dev, &info->desc, &config); if (IS_ERR(info->rdev)) { err = PTR_ERR(info->rdev); dev_err(&pdev->dev, "failed to register %s: err %i\n", info->desc.name, err); - - /* if failing, unregister all earlier regulators */ - while (--id >= 0) { - info = &dbx500_regulator_info[id]; - regulator_unregister(info->rdev); - } return err; } @@ -530,20 +524,8 @@ static int db8500_regulator_probe(struct platform_device *pdev) static int db8500_regulator_remove(struct platform_device *pdev) { - int i; - ux500_regulator_debug_exit(); - for (i = 0; i < ARRAY_SIZE(dbx500_regulator_info); i++) { - struct dbx500_regulator_info *info; - info = &dbx500_regulator_info[i]; - - dev_vdbg(rdev_get_dev(info->rdev), - "regulator-%s-remove\n", info->desc.name); - - regulator_unregister(info->rdev); - } - return 0; } From f5247b401ccfbbf062ca1f4d3eef433f406c39ae Mon Sep 17 00:00:00 2001 From: Jingoo Han Date: Fri, 6 Dec 2013 16:11:58 +0900 Subject: [PATCH 08/13] regulator: pfuze100: use devm_regulator_register() Use devm_regulator_register() to make cleanup paths simpler, and remove unnecessary remove(). Signed-off-by: Jingoo Han Acked-by: Robin Gong Signed-off-by: Mark Brown --- drivers/regulator/pfuze100-regulator.c | 20 +++----------------- 1 file changed, 3 insertions(+), 17 deletions(-) diff --git a/drivers/regulator/pfuze100-regulator.c b/drivers/regulator/pfuze100-regulator.c index ba67b2c4e2e7..1d5ef37918f9 100644 --- a/drivers/regulator/pfuze100-regulator.c +++ b/drivers/regulator/pfuze100-regulator.c @@ -402,31 +402,18 @@ static int pfuze100_regulator_probe(struct i2c_client *client, config.driver_data = pfuze_chip; config.of_node = match_of_node(i); - pfuze_chip->regulators[i] = regulator_register(desc, &config); + pfuze_chip->regulators[i] = + devm_regulator_register(&client->dev, desc, &config); if (IS_ERR(pfuze_chip->regulators[i])) { dev_err(&client->dev, "register regulator%s failed\n", pfuze100_regulators[i].desc.name); - ret = PTR_ERR(pfuze_chip->regulators[i]); - while (--i >= 0) - regulator_unregister(pfuze_chip->regulators[i]); - return ret; + return PTR_ERR(pfuze_chip->regulators[i]); } } return 0; } -static int pfuze100_regulator_remove(struct i2c_client *client) -{ - int i; - struct pfuze_chip *pfuze_chip = i2c_get_clientdata(client); - - for (i = 0; i < PFUZE100_MAX_REGULATOR; i++) - regulator_unregister(pfuze_chip->regulators[i]); - - return 0; -} - static struct i2c_driver pfuze_driver = { .id_table = pfuze_device_id, .driver = { @@ -435,7 +422,6 @@ static struct i2c_driver pfuze_driver = { .of_match_table = pfuze_dt_ids, }, .probe = pfuze100_regulator_probe, - .remove = pfuze100_regulator_remove, }; module_i2c_driver(pfuze_driver); From b0902bbeb7684f2cf8dd1c54fe2616cc2ab1b91d Mon Sep 17 00:00:00 2001 From: Krzysztof Kozlowski Date: Fri, 6 Dec 2013 12:32:13 +0100 Subject: [PATCH 09/13] regulator: max14577: Add regulator driver for Maxim 14577 MAX14577 chip is a multi-function device which includes MUIC, charger and voltage regulator. The driver is located in drivers/mfd. This patch adds regulator driver for MAX14577 chip. There are two regulators in this chip: 1. Safeout LDO with constant voltage output of 4.9V. It can be only enabled or disabled. 2. Current regulator for the charger. It provides current from 90mA up to 950mA. Driver supports Device Tree. Signed-off-by: Krzysztof Kozlowski Signed-off-by: Kyungmin Park Signed-off-by: Mark Brown --- drivers/regulator/Kconfig | 7 + drivers/regulator/Makefile | 1 + drivers/regulator/max14577.c | 272 +++++++++++++++++++++++++++++++++++ 3 files changed, 280 insertions(+) create mode 100644 drivers/regulator/max14577.c diff --git a/drivers/regulator/Kconfig b/drivers/regulator/Kconfig index ce785f481281..11ee05341926 100644 --- a/drivers/regulator/Kconfig +++ b/drivers/regulator/Kconfig @@ -249,6 +249,13 @@ config REGULATOR_LP8788 help This driver supports LP8788 voltage regulator chip. +config REGULATOR_MAX14577 + tristate "Maxim 14577 regulator" + depends on MFD_MAX14577 + help + This driver controls a Maxim 14577 regulator via I2C bus. + The regulators include safeout LDO and current regulator 'CHARGER'. + config REGULATOR_MAX1586 tristate "Maxim 1586/1587 voltage regulator" depends on I2C diff --git a/drivers/regulator/Makefile b/drivers/regulator/Makefile index 01c597ea1744..654bd43a7426 100644 --- a/drivers/regulator/Makefile +++ b/drivers/regulator/Makefile @@ -35,6 +35,7 @@ obj-$(CONFIG_REGULATOR_LP872X) += lp872x.o obj-$(CONFIG_REGULATOR_LP8788) += lp8788-buck.o obj-$(CONFIG_REGULATOR_LP8788) += lp8788-ldo.o obj-$(CONFIG_REGULATOR_LP8755) += lp8755.o +obj-$(CONFIG_REGULATOR_MAX14577) += max14577.o obj-$(CONFIG_REGULATOR_MAX1586) += max1586.o obj-$(CONFIG_REGULATOR_MAX8649) += max8649.o obj-$(CONFIG_REGULATOR_MAX8660) += max8660.o diff --git a/drivers/regulator/max14577.c b/drivers/regulator/max14577.c new file mode 100644 index 000000000000..516e8af05641 --- /dev/null +++ b/drivers/regulator/max14577.c @@ -0,0 +1,272 @@ +/* + * max14577.c - Regulator driver for the Maxim 14577 + * + * Copyright (C) 2013 Samsung Electronics + * Krzysztof Kozlowski + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#include +#include +#include +#include +#include +#include + +struct max14577_regulator { + struct device *dev; + struct max14577 *max14577; + struct regulator_dev **regulators; +}; + +static int max14577_reg_is_enabled(struct regulator_dev *rdev) +{ + int rid = rdev_get_id(rdev); + struct regmap *rmap = rdev->regmap; + u8 reg_data; + + switch (rid) { + case MAX14577_CHARGER: + max14577_read_reg(rmap, MAX14577_CHG_REG_CHG_CTRL2, ®_data); + if ((reg_data & CHGCTRL2_MBCHOSTEN_MASK) == 0) + return 0; + max14577_read_reg(rmap, MAX14577_CHG_REG_STATUS3, ®_data); + if ((reg_data & STATUS3_CGMBC_MASK) == 0) + return 0; + /* MBCHOSTEN and CGMBC are on */ + return 1; + default: + return -EINVAL; + } +} + +static int max14577_reg_get_current_limit(struct regulator_dev *rdev) +{ + u8 reg_data; + struct regmap *rmap = rdev->regmap; + + if (rdev_get_id(rdev) != MAX14577_CHARGER) + return -EINVAL; + + max14577_read_reg(rmap, MAX14577_CHG_REG_CHG_CTRL4, ®_data); + + if ((reg_data & CHGCTRL4_MBCICHWRCL_MASK) == 0) + return MAX14577_REGULATOR_CURRENT_LIMIT_MIN; + + reg_data = ((reg_data & CHGCTRL4_MBCICHWRCH_MASK) >> + CHGCTRL4_MBCICHWRCH_SHIFT); + return MAX14577_REGULATOR_CURRENT_LIMIT_HIGH_START + + reg_data * MAX14577_REGULATOR_CURRENT_LIMIT_HIGH_STEP; +} + +static int max14577_reg_set_current_limit(struct regulator_dev *rdev, + int min_uA, int max_uA) +{ + int i, current_bits = 0xf; + u8 reg_data; + + if (rdev_get_id(rdev) != MAX14577_CHARGER) + return -EINVAL; + + if (min_uA > MAX14577_REGULATOR_CURRENT_LIMIT_MAX || + max_uA < MAX14577_REGULATOR_CURRENT_LIMIT_MIN) + return -EINVAL; + + if (max_uA < MAX14577_REGULATOR_CURRENT_LIMIT_HIGH_START) { + /* Less than 200 mA, so set 90mA (turn only Low Bit off) */ + u8 reg_data = 0x0 << CHGCTRL4_MBCICHWRCL_SHIFT; + return max14577_update_reg(rdev->regmap, + MAX14577_CHG_REG_CHG_CTRL4, + CHGCTRL4_MBCICHWRCL_MASK, reg_data); + } + + /* max_uA is in range: , so search for + * valid current starting from LIMIT_MAX. */ + for (i = MAX14577_REGULATOR_CURRENT_LIMIT_MAX; + i >= MAX14577_REGULATOR_CURRENT_LIMIT_HIGH_START; + i -= MAX14577_REGULATOR_CURRENT_LIMIT_HIGH_STEP) { + if (i <= max_uA) + break; + current_bits--; + } + BUG_ON(current_bits < 0); /* Cannot happen */ + /* Turn Low Bit on (use range 200mA-950 mA) */ + reg_data = 0x1 << CHGCTRL4_MBCICHWRCL_SHIFT; + /* and set proper High Bits */ + reg_data |= current_bits << CHGCTRL4_MBCICHWRCH_SHIFT; + + return max14577_update_reg(rdev->regmap, MAX14577_CHG_REG_CHG_CTRL4, + CHGCTRL4_MBCICHWRCL_MASK | CHGCTRL4_MBCICHWRCH_MASK, + reg_data); +} + +static struct regulator_ops max14577_safeout_ops = { + .is_enabled = regulator_is_enabled_regmap, + .enable = regulator_enable_regmap, + .disable = regulator_disable_regmap, + .list_voltage = regulator_list_voltage_linear, +}; + +static struct regulator_ops max14577_charger_ops = { + .is_enabled = max14577_reg_is_enabled, + .enable = regulator_enable_regmap, + .disable = regulator_disable_regmap, + .get_current_limit = max14577_reg_get_current_limit, + .set_current_limit = max14577_reg_set_current_limit, +}; + +static const struct regulator_desc supported_regulators[] = { + [MAX14577_SAFEOUT] = { + .name = "SAFEOUT", + .id = MAX14577_SAFEOUT, + .ops = &max14577_safeout_ops, + .type = REGULATOR_VOLTAGE, + .owner = THIS_MODULE, + .n_voltages = 1, + .min_uV = MAX14577_REGULATOR_SAFEOUT_VOLTAGE, + .enable_reg = MAX14577_REG_CONTROL2, + .enable_mask = CTRL2_SFOUTORD_MASK, + }, + [MAX14577_CHARGER] = { + .name = "CHARGER", + .id = MAX14577_CHARGER, + .ops = &max14577_charger_ops, + .type = REGULATOR_CURRENT, + .owner = THIS_MODULE, + .enable_reg = MAX14577_CHG_REG_CHG_CTRL2, + .enable_mask = CHGCTRL2_MBCHOSTEN_MASK, + }, +}; + +#ifdef CONFIG_OF +static struct of_regulator_match max14577_regulator_matches[] = { + { .name = "SAFEOUT", }, + { .name = "CHARGER", }, +}; + +static int max14577_regulator_dt_parse_pdata(struct platform_device *pdev) +{ + int ret; + struct device_node *np; + + np = of_get_child_by_name(pdev->dev.parent->of_node, "regulators"); + if (!np) { + dev_err(&pdev->dev, "Failed to get child OF node for regulators\n"); + return -EINVAL; + } + + ret = of_regulator_match(&pdev->dev, np, max14577_regulator_matches, + MAX14577_REG_MAX); + if (ret < 0) { + dev_err(&pdev->dev, "Error parsing regulator init data: %d\n", ret); + return ret; + } + + return 0; +} + +static inline struct regulator_init_data *match_init_data(int index) +{ + return max14577_regulator_matches[index].init_data; +} + +static inline struct device_node *match_of_node(int index) +{ + return max14577_regulator_matches[index].of_node; +} +#else /* CONFIG_OF */ +static int max14577_regulator_dt_parse_pdata(struct platform_device *pdev) +{ + return 0; +} +static inline struct regulator_init_data *match_init_data(int index) +{ + return NULL; +} + +static inline struct device_node *match_of_node(int index) +{ + return NULL; +} +#endif /* CONFIG_OF */ + + +static int max14577_regulator_probe(struct platform_device *pdev) +{ + struct max14577 *max14577 = dev_get_drvdata(pdev->dev.parent); + struct max14577_platform_data *pdata = dev_get_platdata(max14577->dev); + int i, ret; + struct regulator_config config = {}; + + ret = max14577_regulator_dt_parse_pdata(pdev); + if (ret) + return ret; + + config.dev = &pdev->dev; + config.regmap = max14577->regmap; + + for (i = 0; i < ARRAY_SIZE(supported_regulators); i++) { + struct regulator_dev *regulator; + /* + * Index of supported_regulators[] is also the id and must + * match index of pdata->regulators[]. + */ + if (pdata && pdata->regulators) { + config.init_data = pdata->regulators[i].initdata; + config.of_node = pdata->regulators[i].of_node; + } else { + config.init_data = match_init_data(i); + config.of_node = match_of_node(i); + } + + regulator = devm_regulator_register(&pdev->dev, + &supported_regulators[i], &config); + if (IS_ERR(regulator)) { + ret = PTR_ERR(regulator); + dev_err(&pdev->dev, + "Regulator init failed for ID %d with error: %d\n", + i, ret); + return ret; + } + } + + return ret; +} + +static struct platform_driver max14577_regulator_driver = { + .driver = { + .owner = THIS_MODULE, + .name = "max14577-regulator", + }, + .probe = max14577_regulator_probe, +}; + +static int __init max14577_regulator_init(void) +{ + BUILD_BUG_ON(MAX14577_REGULATOR_CURRENT_LIMIT_HIGH_START + + MAX14577_REGULATOR_CURRENT_LIMIT_HIGH_STEP * 0xf != + MAX14577_REGULATOR_CURRENT_LIMIT_MAX); + BUILD_BUG_ON(ARRAY_SIZE(supported_regulators) != MAX14577_REG_MAX); + + return platform_driver_register(&max14577_regulator_driver); +} +subsys_initcall(max14577_regulator_init); + +static void __exit max14577_regulator_exit(void) +{ + platform_driver_unregister(&max14577_regulator_driver); +} +module_exit(max14577_regulator_exit); + +MODULE_AUTHOR("Krzysztof Kozlowski "); +MODULE_DESCRIPTION("MAXIM 14577 regulator driver"); +MODULE_LICENSE("GPL"); From 9f45a3dd93a7276caaf3735bb3b9adb92f3358a0 Mon Sep 17 00:00:00 2001 From: Axel Lin Date: Mon, 23 Dec 2013 14:50:53 +0800 Subject: [PATCH 10/13] regulator: max14577: Add module alias to support module auto-loading Signed-off-by: Axel Lin Signed-off-by: Mark Brown --- drivers/regulator/max14577.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/regulator/max14577.c b/drivers/regulator/max14577.c index 516e8af05641..b1078ba3f393 100644 --- a/drivers/regulator/max14577.c +++ b/drivers/regulator/max14577.c @@ -270,3 +270,4 @@ module_exit(max14577_regulator_exit); MODULE_AUTHOR("Krzysztof Kozlowski "); MODULE_DESCRIPTION("MAXIM 14577 regulator driver"); MODULE_LICENSE("GPL"); +MODULE_ALIAS("platform:max14577-regulator"); From 1eb72f0b98fe7ea1c4bb2e9e294a865b044b2a82 Mon Sep 17 00:00:00 2001 From: Fabio Estevam Date: Mon, 23 Dec 2013 17:35:35 -0200 Subject: [PATCH 11/13] regulator: pfuze100: Improve PFUZE100 entry text Make PFUZE100 entry consistent with other Freescale PMIC entries, so that now we can have: <*> Freescale MC13783 regulator driver <*> Freescale MC13892 regulator driver <*> Freescale PFUZE100 regulator driver Signed-off-by: Fabio Estevam Acked-by: Robin Gong Signed-off-by: Mark Brown --- drivers/regulator/Kconfig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/regulator/Kconfig b/drivers/regulator/Kconfig index ce785f481281..b4a445e7f78d 100644 --- a/drivers/regulator/Kconfig +++ b/drivers/regulator/Kconfig @@ -384,7 +384,7 @@ config REGULATOR_PCF50633 on PCF50633 config REGULATOR_PFUZE100 - tristate "Support regulators on Freescale PFUZE100 PMIC" + tristate "Freescale PFUZE100 regulator driver" depends on I2C select REGMAP_I2C help From 52f48bf33dff6ac261c77a1da6b9f6ab67509d37 Mon Sep 17 00:00:00 2001 From: Axel Lin Date: Tue, 24 Dec 2013 21:37:50 +0800 Subject: [PATCH 12/13] regulator: max77693: Add missing .owner field in regulator_desc Add missing .owner field in regulator_desc, which is used for refcounting. Signed-off-by: Axel Lin Signed-off-by: Mark Brown --- drivers/regulator/max77693.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/regulator/max77693.c b/drivers/regulator/max77693.c index feb20bf4ccab..5fb899f461d0 100644 --- a/drivers/regulator/max77693.c +++ b/drivers/regulator/max77693.c @@ -138,6 +138,7 @@ static struct regulator_ops max77693_charger_ops = { .n_voltages = 4, \ .ops = &max77693_safeout_ops, \ .type = REGULATOR_VOLTAGE, \ + .owner = THIS_MODULE, \ .volt_table = max77693_safeout_table, \ .vsel_reg = MAX77693_CHG_REG_SAFEOUT_CTRL, \ .vsel_mask = SAFEOUT_CTRL_SAFEOUT##_num##_MASK, \ From 62b389161fea824b6c87614daa6483ef7632f786 Mon Sep 17 00:00:00 2001 From: Fabio Estevam Date: Wed, 15 Jan 2014 00:52:45 -0200 Subject: [PATCH 13/13] regulator: pfuze100-regulator: Fix some checkpatch complaints Fix the following checkpatch error and warning: ERROR: switch and case should be at the same indent #311: FILE: drivers/regulator/pfuze100-regulator.c:311: + switch (value & 0x0f) { [...] + case 0x8: [...] + case 0x0: [...] + default: WARNING: line over 80 characters #312: FILE: drivers/regulator/pfuze100-regulator.c:312: + /* Freescale misprogrammed 1-3% of parts prior to week 8 of 2013 as ID=8 */ Signed-off-by: Fabio Estevam Signed-off-by: Mark Brown --- drivers/regulator/pfuze100-regulator.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/drivers/regulator/pfuze100-regulator.c b/drivers/regulator/pfuze100-regulator.c index 0c511ae52c42..f68e5d5a011e 100644 --- a/drivers/regulator/pfuze100-regulator.c +++ b/drivers/regulator/pfuze100-regulator.c @@ -309,14 +309,17 @@ static int pfuze_identify(struct pfuze_chip *pfuze_chip) return ret; switch (value & 0x0f) { - /* Freescale misprogrammed 1-3% of parts prior to week 8 of 2013 as ID=8 */ - case 0x8: - dev_info(pfuze_chip->dev, "Assuming misprogrammed ID=0x8"); - case 0x0: - break; - default: - dev_warn(pfuze_chip->dev, "Illegal ID: %x\n", value); - return -ENODEV; + /* + * Freescale misprogrammed 1-3% of parts prior to week 8 of 2013 + * as ID=8 + */ + case 0x8: + dev_info(pfuze_chip->dev, "Assuming misprogrammed ID=0x8"); + case 0x0: + break; + default: + dev_warn(pfuze_chip->dev, "Illegal ID: %x\n", value); + return -ENODEV; } ret = regmap_read(pfuze_chip->regmap, PFUZE100_REVID, &value);