blob: 661fcecd1cec5bbd089658486a270f24d0a746b0 [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>
20#include <linux/delay.h>
21#include <linux/init.h>
22#include <linux/slab.h>
23#include <linux/err.h>
24#include <linux/platform_device.h>
25#include <linux/regulator/driver.h>
26#include <linux/regulator/machine.h>
27#include <linux/mfd/tps65090.h>
28#include <linux/regulator/tps65090-regulator.h>
29
30struct tps65090_regulator {
31 int id;
Venu Byravarasu452534e2012-03-22 18:34:09 +053032 /* used by regulator core */
33 struct regulator_desc desc;
34
35 /* Device */
36 struct device *dev;
37};
38
Venu Byravarasu452534e2012-03-22 18:34:09 +053039static struct regulator_ops tps65090_ops = {
Axel Lin06c49982012-04-17 17:08:56 +080040 .enable = regulator_enable_regmap,
41 .disable = regulator_disable_regmap,
42 .is_enabled = regulator_is_enabled_regmap,
Venu Byravarasu452534e2012-03-22 18:34:09 +053043};
44
Axel Lin4b3bd552012-03-24 10:57:53 +080045#define tps65090_REG(_id) \
Venu Byravarasu452534e2012-03-22 18:34:09 +053046{ \
Venu Byravarasu452534e2012-03-22 18:34:09 +053047 .id = TPS65090_ID_##_id, \
48 .desc = { \
49 .name = tps65090_rails(_id), \
50 .id = TPS65090_ID_##_id, \
Axel Lin4b3bd552012-03-24 10:57:53 +080051 .ops = &tps65090_ops, \
Venu Byravarasu452534e2012-03-22 18:34:09 +053052 .type = REGULATOR_VOLTAGE, \
53 .owner = THIS_MODULE, \
Axel Lin06c49982012-04-17 17:08:56 +080054 .enable_reg = (TPS65090_ID_##_id) + 12, \
55 .enable_mask = BIT(0), \
Venu Byravarasu452534e2012-03-22 18:34:09 +053056 }, \
57}
58
59static struct tps65090_regulator TPS65090_regulator[] = {
Axel Lin4b3bd552012-03-24 10:57:53 +080060 tps65090_REG(DCDC1),
61 tps65090_REG(DCDC2),
62 tps65090_REG(DCDC3),
63 tps65090_REG(FET1),
64 tps65090_REG(FET2),
65 tps65090_REG(FET3),
66 tps65090_REG(FET4),
67 tps65090_REG(FET5),
68 tps65090_REG(FET6),
69 tps65090_REG(FET7),
Venu Byravarasu452534e2012-03-22 18:34:09 +053070};
71
72static inline struct tps65090_regulator *find_regulator_info(int id)
73{
74 struct tps65090_regulator *ri;
75 int i;
76
77 for (i = 0; i < ARRAY_SIZE(TPS65090_regulator); i++) {
78 ri = &TPS65090_regulator[i];
79 if (ri->desc.id == id)
80 return ri;
81 }
82 return NULL;
83}
84
85static int __devinit tps65090_regulator_probe(struct platform_device *pdev)
86{
Axel Lin06c49982012-04-17 17:08:56 +080087 struct tps65090 *tps65090_mfd = dev_get_drvdata(pdev->dev.parent);
Venu Byravarasu452534e2012-03-22 18:34:09 +053088 struct tps65090_regulator *ri = NULL;
Mark Brownc1727082012-04-04 00:50:22 +010089 struct regulator_config config = { };
Venu Byravarasu452534e2012-03-22 18:34:09 +053090 struct regulator_dev *rdev;
91 struct tps65090_regulator_platform_data *tps_pdata;
92 int id = pdev->id;
93
94 dev_dbg(&pdev->dev, "Probing regulator %d\n", id);
95
96 ri = find_regulator_info(id);
97 if (ri == NULL) {
98 dev_err(&pdev->dev, "invalid regulator ID specified\n");
99 return -EINVAL;
100 }
101 tps_pdata = pdev->dev.platform_data;
102 ri->dev = &pdev->dev;
103
Mark Brownc1727082012-04-04 00:50:22 +0100104 config.dev = &pdev->dev;
105 config.init_data = &tps_pdata->regulator;
106 config.driver_data = ri;
Axel Lin06c49982012-04-17 17:08:56 +0800107 config.regmap = tps65090_mfd->rmap;
Mark Brownc1727082012-04-04 00:50:22 +0100108
109 rdev = regulator_register(&ri->desc, &config);
Axel Lin0ca2d6e2012-03-24 10:56:00 +0800110 if (IS_ERR(rdev)) {
Venu Byravarasu452534e2012-03-22 18:34:09 +0530111 dev_err(&pdev->dev, "failed to register regulator %s\n",
112 ri->desc.name);
113 return PTR_ERR(rdev);
114 }
115
116 platform_set_drvdata(pdev, rdev);
117 return 0;
118}
119
120static int __devexit tps65090_regulator_remove(struct platform_device *pdev)
121{
122 struct regulator_dev *rdev = platform_get_drvdata(pdev);
123
124 regulator_unregister(rdev);
125 return 0;
126}
127
128static struct platform_driver tps65090_regulator_driver = {
129 .driver = {
130 .name = "tps65090-regulator",
131 .owner = THIS_MODULE,
132 },
133 .probe = tps65090_regulator_probe,
134 .remove = __devexit_p(tps65090_regulator_remove),
135};
136
137static int __init tps65090_regulator_init(void)
138{
139 return platform_driver_register(&tps65090_regulator_driver);
140}
141subsys_initcall(tps65090_regulator_init);
142
143static void __exit tps65090_regulator_exit(void)
144{
145 platform_driver_unregister(&tps65090_regulator_driver);
146}
147module_exit(tps65090_regulator_exit);
148
149MODULE_DESCRIPTION("tps65090 regulator driver");
150MODULE_AUTHOR("Venu Byravarasu <vbyravarasu@nvidia.com>");
151MODULE_LICENSE("GPL v2");