blob: 001ad554ac62634c6a77897ffc9a92cf641c2abf [file] [log] [blame]
Venu Byravarasu452534e2012-03-22 18:34:09 +05301/*
2 * Regulator driver for tps65090 power management chip.
3 *
4 * Copyright (c) 2012, NVIDIA CORPORATION. All rights reserved.
5
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.
9
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
13 * more details.
14
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/>
17 */
18
19#include <linux/module.h>
Venu Byravarasu452534e2012-03-22 18:34:09 +053020#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>
28
29struct tps65090_regulator {
30 int id;
Venu Byravarasu452534e2012-03-22 18:34:09 +053031 /* used by regulator core */
32 struct regulator_desc desc;
33
34 /* Device */
35 struct device *dev;
36};
37
Venu Byravarasu452534e2012-03-22 18:34:09 +053038static struct regulator_ops tps65090_ops = {
Axel Lin06c49982012-04-17 17:08:56 +080039 .enable = regulator_enable_regmap,
40 .disable = regulator_disable_regmap,
41 .is_enabled = regulator_is_enabled_regmap,
Venu Byravarasu452534e2012-03-22 18:34:09 +053042};
43
Axel Lin4b3bd552012-03-24 10:57:53 +080044#define tps65090_REG(_id) \
Venu Byravarasu452534e2012-03-22 18:34:09 +053045{ \
Venu Byravarasu452534e2012-03-22 18:34:09 +053046 .id = TPS65090_ID_##_id, \
47 .desc = { \
48 .name = tps65090_rails(_id), \
49 .id = TPS65090_ID_##_id, \
Axel Lin4b3bd552012-03-24 10:57:53 +080050 .ops = &tps65090_ops, \
Venu Byravarasu452534e2012-03-22 18:34:09 +053051 .type = REGULATOR_VOLTAGE, \
52 .owner = THIS_MODULE, \
Axel Lin06c49982012-04-17 17:08:56 +080053 .enable_reg = (TPS65090_ID_##_id) + 12, \
54 .enable_mask = BIT(0), \
Venu Byravarasu452534e2012-03-22 18:34:09 +053055 }, \
56}
57
58static struct tps65090_regulator TPS65090_regulator[] = {
Axel Lin4b3bd552012-03-24 10:57:53 +080059 tps65090_REG(DCDC1),
60 tps65090_REG(DCDC2),
61 tps65090_REG(DCDC3),
62 tps65090_REG(FET1),
63 tps65090_REG(FET2),
64 tps65090_REG(FET3),
65 tps65090_REG(FET4),
66 tps65090_REG(FET5),
67 tps65090_REG(FET6),
68 tps65090_REG(FET7),
Venu Byravarasu452534e2012-03-22 18:34:09 +053069};
70
71static inline struct tps65090_regulator *find_regulator_info(int id)
72{
73 struct tps65090_regulator *ri;
74 int i;
75
76 for (i = 0; i < ARRAY_SIZE(TPS65090_regulator); i++) {
77 ri = &TPS65090_regulator[i];
78 if (ri->desc.id == id)
79 return ri;
80 }
81 return NULL;
82}
83
84static int __devinit tps65090_regulator_probe(struct platform_device *pdev)
85{
Axel Lin06c49982012-04-17 17:08:56 +080086 struct tps65090 *tps65090_mfd = dev_get_drvdata(pdev->dev.parent);
Venu Byravarasu452534e2012-03-22 18:34:09 +053087 struct tps65090_regulator *ri = NULL;
Mark Brownc1727082012-04-04 00:50:22 +010088 struct regulator_config config = { };
Venu Byravarasu452534e2012-03-22 18:34:09 +053089 struct regulator_dev *rdev;
90 struct tps65090_regulator_platform_data *tps_pdata;
91 int id = pdev->id;
92
93 dev_dbg(&pdev->dev, "Probing regulator %d\n", id);
94
95 ri = find_regulator_info(id);
96 if (ri == NULL) {
97 dev_err(&pdev->dev, "invalid regulator ID specified\n");
98 return -EINVAL;
99 }
100 tps_pdata = pdev->dev.platform_data;
101 ri->dev = &pdev->dev;
102
Mark Brownc1727082012-04-04 00:50:22 +0100103 config.dev = &pdev->dev;
104 config.init_data = &tps_pdata->regulator;
105 config.driver_data = ri;
Axel Lin06c49982012-04-17 17:08:56 +0800106 config.regmap = tps65090_mfd->rmap;
Mark Brownc1727082012-04-04 00:50:22 +0100107
108 rdev = regulator_register(&ri->desc, &config);
Axel Lin0ca2d6e2012-03-24 10:56:00 +0800109 if (IS_ERR(rdev)) {
Venu Byravarasu452534e2012-03-22 18:34:09 +0530110 dev_err(&pdev->dev, "failed to register regulator %s\n",
111 ri->desc.name);
112 return PTR_ERR(rdev);
113 }
114
115 platform_set_drvdata(pdev, rdev);
116 return 0;
117}
118
119static int __devexit tps65090_regulator_remove(struct platform_device *pdev)
120{
121 struct regulator_dev *rdev = platform_get_drvdata(pdev);
122
123 regulator_unregister(rdev);
124 return 0;
125}
126
127static struct platform_driver tps65090_regulator_driver = {
128 .driver = {
129 .name = "tps65090-regulator",
130 .owner = THIS_MODULE,
131 },
132 .probe = tps65090_regulator_probe,
133 .remove = __devexit_p(tps65090_regulator_remove),
134};
135
136static int __init tps65090_regulator_init(void)
137{
138 return platform_driver_register(&tps65090_regulator_driver);
139}
140subsys_initcall(tps65090_regulator_init);
141
142static void __exit tps65090_regulator_exit(void)
143{
144 platform_driver_unregister(&tps65090_regulator_driver);
145}
146module_exit(tps65090_regulator_exit);
147
148MODULE_DESCRIPTION("tps65090 regulator driver");
149MODULE_AUTHOR("Venu Byravarasu <vbyravarasu@nvidia.com>");
150MODULE_LICENSE("GPL v2");