2 * Regulator driver for tps65090 power management chip.
4 * Copyright (c) 2012, NVIDIA CORPORATION. All rights reserved.
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms and conditions of the GNU General Public License,
8 * version 2, as published by the Free Software Foundation.
10 * This program is distributed in the hope it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>
19 #include <linux/module.h>
20 #include <linux/init.h>
21 #include <linux/slab.h>
22 #include <linux/err.h>
23 #include <linux/platform_device.h>
24 #include <linux/regulator/driver.h>
25 #include <linux/regulator/machine.h>
26 #include <linux/mfd/tps65090.h>
27 #include <linux/regulator/tps65090-regulator.h>
29 struct tps65090_regulator {
31 /* used by regulator core */
32 struct regulator_desc desc;
38 static struct regulator_ops tps65090_ops = {
39 .enable = regulator_enable_regmap,
40 .disable = regulator_disable_regmap,
41 .is_enabled = regulator_is_enabled_regmap,
44 #define tps65090_REG(_id) \
46 .id = TPS65090_ID_##_id, \
48 .name = tps65090_rails(_id), \
49 .id = TPS65090_ID_##_id, \
50 .ops = &tps65090_ops, \
51 .type = REGULATOR_VOLTAGE, \
52 .owner = THIS_MODULE, \
53 .enable_reg = (TPS65090_ID_##_id) + 12, \
54 .enable_mask = BIT(0), \
58 static struct tps65090_regulator TPS65090_regulator[] = {
71 static inline struct tps65090_regulator *find_regulator_info(int id)
73 struct tps65090_regulator *ri;
76 for (i = 0; i < ARRAY_SIZE(TPS65090_regulator); i++) {
77 ri = &TPS65090_regulator[i];
78 if (ri->desc.id == id)
84 static int __devinit tps65090_regulator_probe(struct platform_device *pdev)
86 struct tps65090 *tps65090_mfd = dev_get_drvdata(pdev->dev.parent);
87 struct tps65090_regulator *ri = NULL;
88 struct regulator_config config = { };
89 struct regulator_dev *rdev;
90 struct tps65090_regulator_platform_data *tps_pdata;
93 dev_dbg(&pdev->dev, "Probing regulator %d\n", id);
95 ri = find_regulator_info(id);
97 dev_err(&pdev->dev, "invalid regulator ID specified\n");
100 tps_pdata = pdev->dev.platform_data;
101 ri->dev = &pdev->dev;
103 config.dev = &pdev->dev;
104 config.init_data = &tps_pdata->regulator;
105 config.driver_data = ri;
106 config.regmap = tps65090_mfd->rmap;
108 rdev = regulator_register(&ri->desc, &config);
110 dev_err(&pdev->dev, "failed to register regulator %s\n",
112 return PTR_ERR(rdev);
115 platform_set_drvdata(pdev, rdev);
119 static int __devexit tps65090_regulator_remove(struct platform_device *pdev)
121 struct regulator_dev *rdev = platform_get_drvdata(pdev);
123 regulator_unregister(rdev);
127 static struct platform_driver tps65090_regulator_driver = {
129 .name = "tps65090-regulator",
130 .owner = THIS_MODULE,
132 .probe = tps65090_regulator_probe,
133 .remove = __devexit_p(tps65090_regulator_remove),
136 static int __init tps65090_regulator_init(void)
138 return platform_driver_register(&tps65090_regulator_driver);
140 subsys_initcall(tps65090_regulator_init);
142 static void __exit tps65090_regulator_exit(void)
144 platform_driver_unregister(&tps65090_regulator_driver);
146 module_exit(tps65090_regulator_exit);
148 MODULE_DESCRIPTION("tps65090 regulator driver");
149 MODULE_AUTHOR("Venu Byravarasu <vbyravarasu@nvidia.com>");
150 MODULE_LICENSE("GPL v2");