#include <linux/err.h>
#include <linux/platform_device.h>
#include <linux/regulator/driver.h>
+#include <linux/regulator/of_regulator.h>
#include <linux/regulator/machine.h>
#include <linux/mfd/tps65090.h>
-#include <linux/regulator/tps65090-regulator.h>
+#include <linux/of.h>
+
+/* TPS65090 has 3 DCDC-regulators and 7 FETs. */
+
+#define MAX_REGULATORS 10
struct tps65090_regulator {
- int id;
/* Regulator register address.*/
- u8 reg_en_reg;
- u8 en_bit;
+ u32 reg_en_reg;
+ u32 en_bit;
/* used by regulator core */
struct regulator_desc desc;
- /* Device */
- struct device *dev;
+ struct regulator_dev *rdev;
+};
+
+struct tps65090_regulator_drvdata {
+ struct tps65090_regulator *regulators[MAX_REGULATORS];
};
static inline struct device *to_tps65090_dev(struct regulator_dev *rdev)
return ret;
}
+static int tps65090_set_voltage(struct regulator_dev *rdev, int min,
+ int max, unsigned *sel)
+{
+ /*
+ * Only needed for the core code to set constraints; the voltage
+ * isn't actually adjustable on tps65090.
+ */
+ return 0;
+}
+
static struct regulator_ops tps65090_ops = {
.enable = tps65090_reg_enable,
.disable = tps65090_reg_disable,
+ .set_voltage = tps65090_set_voltage,
.is_enabled = tps65090_reg_is_enabled,
};
-#define tps65090_REG(_id) \
-{ \
- .reg_en_reg = (TPS65090_ID_##_id) + 12, \
- .en_bit = 0, \
- .id = TPS65090_ID_##_id, \
- .desc = { \
- .name = tps65090_rails(_id), \
- .id = TPS65090_ID_##_id, \
- .ops = &tps65090_ops, \
- .type = REGULATOR_VOLTAGE, \
- .owner = THIS_MODULE, \
- }, \
-}
-
-static struct tps65090_regulator TPS65090_regulator[] = {
- tps65090_REG(DCDC1),
- tps65090_REG(DCDC2),
- tps65090_REG(DCDC3),
- tps65090_REG(FET1),
- tps65090_REG(FET2),
- tps65090_REG(FET3),
- tps65090_REG(FET4),
- tps65090_REG(FET5),
- tps65090_REG(FET6),
- tps65090_REG(FET7),
-};
-
-static inline struct tps65090_regulator *find_regulator_info(int id)
+static void tps65090_unregister_regulators(struct tps65090_regulator *regs[])
{
- struct tps65090_regulator *ri;
int i;
- for (i = 0; i < ARRAY_SIZE(TPS65090_regulator); i++) {
- ri = &TPS65090_regulator[i];
- if (ri->desc.id == id)
- return ri;
- }
- return NULL;
+ for (i = 0; i < MAX_REGULATORS; i++)
+ if (regs[i]) {
+ regulator_unregister(regs[i]->rdev);
+ kfree(regs[i]->rdev->desc->name);
+ kfree(regs[i]->rdev);
+ }
}
+
static int __devinit tps65090_regulator_probe(struct platform_device *pdev)
{
- struct tps65090_regulator *ri = NULL;
- struct regulator_dev *rdev;
- struct tps65090_regulator_platform_data *tps_pdata;
- int id = pdev->id;
+ struct tps65090_regulator_drvdata *drvdata;
+ struct tps65090_regulator *reg;
+ struct device_node *mfdnp, *regnp, *np;
+ struct regulator_init_data *ri;
+ u32 id;
+
+ mfdnp = pdev->dev.parent->of_node;
- dev_dbg(&pdev->dev, "Probing regulator %d\n", id);
+ if (!mfdnp) {
+ dev_err(&pdev->dev, "no device tree data available\n");
+ return -EINVAL;
+ }
- ri = find_regulator_info(id);
- if (ri == NULL) {
- dev_err(&pdev->dev, "invalid regulator ID specified\n");
+ regnp = of_find_node_by_name(mfdnp, "voltage-regulators");
+ if (!regnp) {
+ dev_err(&pdev->dev, "no OF regulator data found at %s\n",
+ mfdnp->full_name);
return -EINVAL;
}
- tps_pdata = pdev->dev.platform_data;
- ri->dev = &pdev->dev;
-
- rdev = regulator_register(&ri->desc, &pdev->dev,
- &tps_pdata->regulator, ri, NULL);
- if (IS_ERR(rdev)) {
- dev_err(&pdev->dev, "failed to register regulator %s\n",
- ri->desc.name);
- return PTR_ERR(rdev);
+
+ drvdata = devm_kzalloc(&pdev->dev, sizeof(*drvdata), GFP_KERNEL);
+ if (!drvdata) {
+ of_node_put(regnp);
+ return -ENOMEM;
}
- platform_set_drvdata(pdev, rdev);
+ id = 0;
+ for_each_child_of_node(regnp, np) {
+ ri = of_get_regulator_init_data(&pdev->dev, np);
+ if (!ri) {
+ dev_err(&pdev->dev, "regulator_init_data failed for %s\n",
+ np->full_name);
+ goto out;
+ }
+
+ reg = devm_kzalloc(&pdev->dev,
+ sizeof(struct tps65090_regulator),
+ GFP_KERNEL);
+ reg->desc.name = kstrdup(of_get_property(np, "regulator-name",
+ NULL), GFP_KERNEL);
+ if (!reg->desc.name) {
+ dev_err(&pdev->dev,
+ "no regulator-name specified at %s\n", np->full_name);
+ goto out;
+ }
+
+ if (of_property_read_u32(np, "tps65090-control-reg-offset",
+ ®->reg_en_reg)) {
+ dev_err(&pdev->dev,
+ "no control-reg-offset property at %s\n",
+ np->full_name);
+ kfree(reg->desc.name);
+ goto out;
+ }
+
+ reg->desc.id = id;
+ reg->desc.ops = &tps65090_ops;
+ reg->desc.type = REGULATOR_VOLTAGE;
+ reg->desc.owner = THIS_MODULE;
+ reg->rdev = regulator_register(®->desc, &pdev->dev,
+ ri, reg, np);
+ drvdata->regulators[id] = reg;
+ id++;
+ }
+
+ platform_set_drvdata(pdev, drvdata);
+ of_node_put(regnp);
+
return 0;
+
+out:
+ dev_err(&pdev->dev, "bad OF regulator data in %s\n", regnp->full_name);
+ tps65090_unregister_regulators(drvdata->regulators);
+ of_node_put(regnp);
+ return -EINVAL;
}
static int __devexit tps65090_regulator_remove(struct platform_device *pdev)
{
- struct regulator_dev *rdev = platform_get_drvdata(pdev);
+ struct tps65090_regulator_drvdata *drvdata = platform_get_drvdata(pdev);
+
+ tps65090_unregister_regulators(drvdata->regulators);
- regulator_unregister(rdev);
return 0;
}
+++ /dev/null
-/*
- * Regulator driver interface for TI TPS65090 PMIC family
- *
- * Copyright (c) 2012, NVIDIA CORPORATION. All rights reserved.
-
- * This program is free software; you can redistribute it and/or modify it
- * under the terms and conditions of the GNU General Public License,
- * version 2, as published by the Free Software Foundation.
-
- * This program is distributed in the hope 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.
-
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef __REGULATOR_TPS65090_H
-#define __REGULATOR_TPS65090_H
-
-#include <linux/regulator/machine.h>
-
-#define tps65090_rails(_name) "tps65090_"#_name
-
-enum {
- TPS65090_ID_DCDC1,
- TPS65090_ID_DCDC2,
- TPS65090_ID_DCDC3,
- TPS65090_ID_FET1,
- TPS65090_ID_FET2,
- TPS65090_ID_FET3,
- TPS65090_ID_FET4,
- TPS65090_ID_FET5,
- TPS65090_ID_FET6,
- TPS65090_ID_FET7,
-};
-
-/*
- * struct tps65090_regulator_platform_data
- *
- * @regulator: The regulator init data.
- * @slew_rate_uV_per_us: Slew rate microvolt per microsec.
- */
-
-struct tps65090_regulator_platform_data {
- struct regulator_init_data regulator;
-};
-
-#endif /* __REGULATOR_TPS65090_H */