blob: 9446653e7a894cb84da2ed753ac70eed5bd65cef [file] [log] [blame]
Laxman Dewangan6ffc3272012-04-04 12:44:00 +05301/*
2 * Regulator driver for RICOH RC5T583 power management chip.
3 *
4 * Copyright (c) 2011-2012, NVIDIA CORPORATION. All rights reserved.
5 * Author: Laxman dewangan <ldewangan@nvidia.com>
6 *
7 * based on code
8 * Copyright (C) 2011 RICOH COMPANY,LTD
9 *
10 *
11 * This program is free software; you can redistribute it and/or modify it
12 * under the terms and conditions of the GNU General Public License,
13 * version 2, as published by the Free Software Foundation.
14 *
15 * This program is distributed in the hope it will be useful, but WITHOUT
16 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
17 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
18 * more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program. If not, see <http://www.gnu.org/licenses/>.
22 *
23 */
24
25#include <linux/module.h>
Laxman Dewangan6ffc3272012-04-04 12:44:00 +053026#include <linux/init.h>
27#include <linux/slab.h>
28#include <linux/err.h>
29#include <linux/platform_device.h>
30#include <linux/regulator/driver.h>
31#include <linux/regulator/machine.h>
32#include <linux/gpio.h>
33#include <linux/mfd/rc5t583.h>
34
35struct rc5t583_regulator_info {
36 int deepsleep_id;
37
38 /* Regulator register address.*/
Laxman Dewangan6ffc3272012-04-04 12:44:00 +053039 uint8_t reg_disc_reg;
40 uint8_t disc_bit;
Laxman Dewangan6ffc3272012-04-04 12:44:00 +053041 uint8_t deepsleep_reg;
42
Laxman Dewangan6ffc3272012-04-04 12:44:00 +053043 /* Regulator specific turn-on delay and voltage settling time*/
44 int enable_uv_per_us;
Laxman Dewangan6ffc3272012-04-04 12:44:00 +053045
46 /* Used by regulator core */
47 struct regulator_desc desc;
48};
49
Laxman Dewangan6ffc3272012-04-04 12:44:00 +053050static int rc5t583_regulator_enable_time(struct regulator_dev *rdev)
51{
Axel Linc07608f2019-03-27 19:54:13 +080052 struct rc5t583_regulator_info *reg_info = rdev_get_drvdata(rdev);
Axel Lin15b397d72012-04-24 09:56:43 +080053 int vsel = regulator_get_voltage_sel_regmap(rdev);
Axel Lin3209be12012-05-14 10:54:46 +080054 int curr_uV = regulator_list_voltage_linear(rdev, vsel);
Axel Lin15b397d72012-04-24 09:56:43 +080055
Axel Linc07608f2019-03-27 19:54:13 +080056 return DIV_ROUND_UP(curr_uV, reg_info->enable_uv_per_us);
Laxman Dewangan6ffc3272012-04-04 12:44:00 +053057}
58
Bhumika Goyalfb740362017-01-28 20:48:51 +053059static const struct regulator_ops rc5t583_ops = {
Axel Lin5bb69362012-04-17 14:11:31 +080060 .is_enabled = regulator_is_enabled_regmap,
61 .enable = regulator_enable_regmap,
62 .disable = regulator_disable_regmap,
Laxman Dewangan6ffc3272012-04-04 12:44:00 +053063 .enable_time = rc5t583_regulator_enable_time,
Axel Lin15b397d72012-04-24 09:56:43 +080064 .get_voltage_sel = regulator_get_voltage_sel_regmap,
Axel Lin70e5f642012-05-14 10:55:50 +080065 .set_voltage_sel = regulator_set_voltage_sel_regmap,
Axel Lin3209be12012-05-14 10:54:46 +080066 .list_voltage = regulator_list_voltage_linear,
Axel Lin70e5f642012-05-14 10:55:50 +080067 .map_voltage = regulator_map_voltage_linear,
Axel Lin2f6ae6e2012-06-19 09:26:52 +080068 .set_voltage_time_sel = regulator_set_voltage_time_sel,
Laxman Dewangan6ffc3272012-04-04 12:44:00 +053069};
70
Axel Lin95e301b2012-04-06 08:01:36 +080071#define RC5T583_REG(_id, _en_reg, _en_bit, _disc_reg, _disc_bit, \
72 _vout_mask, _min_mv, _max_mv, _step_uV, _enable_mv) \
Laxman Dewangan6ffc3272012-04-04 12:44:00 +053073{ \
Laxman Dewangan6ffc3272012-04-04 12:44:00 +053074 .reg_disc_reg = RC5T583_REG_##_disc_reg, \
75 .disc_bit = _disc_bit, \
Axel Lin95e301b2012-04-06 08:01:36 +080076 .deepsleep_reg = RC5T583_REG_##_id##DAC_DS, \
Laxman Dewangan6ffc3272012-04-04 12:44:00 +053077 .enable_uv_per_us = _enable_mv * 1000, \
Laxman Dewangan6ffc3272012-04-04 12:44:00 +053078 .deepsleep_id = RC5T583_DS_##_id, \
79 .desc = { \
80 .name = "rc5t583-regulator-"#_id, \
81 .id = RC5T583_REGULATOR_##_id, \
Axel Line3a73842012-04-05 14:04:48 +080082 .n_voltages = (_max_mv - _min_mv) * 1000 / _step_uV + 1, \
Laxman Dewangan6ffc3272012-04-04 12:44:00 +053083 .ops = &rc5t583_ops, \
84 .type = REGULATOR_VOLTAGE, \
85 .owner = THIS_MODULE, \
Axel Lin15b397d72012-04-24 09:56:43 +080086 .vsel_reg = RC5T583_REG_##_id##DAC, \
87 .vsel_mask = _vout_mask, \
Axel Lin5bb69362012-04-17 14:11:31 +080088 .enable_reg = RC5T583_REG_##_en_reg, \
89 .enable_mask = BIT(_en_bit), \
Axel Lin3209be12012-05-14 10:54:46 +080090 .min_uV = _min_mv * 1000, \
91 .uV_step = _step_uV, \
Axel Lin2f6ae6e2012-06-19 09:26:52 +080092 .ramp_delay = 40 * 1000, \
Laxman Dewangan6ffc3272012-04-04 12:44:00 +053093 }, \
94}
95
96static struct rc5t583_regulator_info rc5t583_reg_info[RC5T583_REGULATOR_MAX] = {
Axel Lin95e301b2012-04-06 08:01:36 +080097 RC5T583_REG(DC0, DC0CTL, 0, DC0CTL, 1, 0x7F, 700, 1500, 12500, 4),
98 RC5T583_REG(DC1, DC1CTL, 0, DC1CTL, 1, 0x7F, 700, 1500, 12500, 14),
99 RC5T583_REG(DC2, DC2CTL, 0, DC2CTL, 1, 0x7F, 900, 2400, 12500, 14),
100 RC5T583_REG(DC3, DC3CTL, 0, DC3CTL, 1, 0x7F, 900, 2400, 12500, 14),
101 RC5T583_REG(LDO0, LDOEN2, 0, LDODIS2, 0, 0x7F, 900, 3400, 25000, 160),
102 RC5T583_REG(LDO1, LDOEN2, 1, LDODIS2, 1, 0x7F, 900, 3400, 25000, 160),
103 RC5T583_REG(LDO2, LDOEN2, 2, LDODIS2, 2, 0x7F, 900, 3400, 25000, 160),
104 RC5T583_REG(LDO3, LDOEN2, 3, LDODIS2, 3, 0x7F, 900, 3400, 25000, 160),
105 RC5T583_REG(LDO4, LDOEN2, 4, LDODIS2, 4, 0x3F, 750, 1500, 12500, 133),
106 RC5T583_REG(LDO5, LDOEN2, 5, LDODIS2, 5, 0x7F, 900, 3400, 25000, 267),
107 RC5T583_REG(LDO6, LDOEN2, 6, LDODIS2, 6, 0x7F, 900, 3400, 25000, 133),
108 RC5T583_REG(LDO7, LDOEN2, 7, LDODIS2, 7, 0x7F, 900, 3400, 25000, 233),
109 RC5T583_REG(LDO8, LDOEN1, 0, LDODIS1, 0, 0x7F, 900, 3400, 25000, 233),
110 RC5T583_REG(LDO9, LDOEN1, 1, LDODIS1, 1, 0x7F, 900, 3400, 25000, 133),
Laxman Dewangan6ffc3272012-04-04 12:44:00 +0530111};
112
Bill Pembertona5023572012-11-19 13:22:22 -0500113static int rc5t583_regulator_probe(struct platform_device *pdev)
Laxman Dewangan6ffc3272012-04-04 12:44:00 +0530114{
115 struct rc5t583 *rc5t583 = dev_get_drvdata(pdev->dev.parent);
116 struct rc5t583_platform_data *pdata = dev_get_platdata(rc5t583->dev);
Mark Brownc172708d2012-04-04 00:50:22 +0100117 struct regulator_config config = { };
Laxman Dewangan6ffc3272012-04-04 12:44:00 +0530118 struct regulator_dev *rdev;
119 struct rc5t583_regulator_info *ri;
120 int ret;
121 int id;
122
123 if (!pdata) {
124 dev_err(&pdev->dev, "No platform data, exiting...\n");
125 return -ENODEV;
126 }
127
Laxman Dewangan6ffc3272012-04-04 12:44:00 +0530128 for (id = 0; id < RC5T583_REGULATOR_MAX; ++id) {
Laxman Dewangan6ffc3272012-04-04 12:44:00 +0530129 ri = &rc5t583_reg_info[id];
Laxman Dewangan6ffc3272012-04-04 12:44:00 +0530130
131 if (ri->deepsleep_id == RC5T583_DS_NONE)
132 goto skip_ext_pwr_config;
133
134 ret = rc5t583_ext_power_req_config(rc5t583->dev,
135 ri->deepsleep_id,
136 pdata->regulator_ext_pwr_control[id],
137 pdata->regulator_deepsleep_slot[id]);
138 /*
139 * Configuring external control is not a major issue,
140 * just give warning.
141 */
142 if (ret < 0)
143 dev_warn(&pdev->dev,
144 "Failed to configure ext control %d\n", id);
145
146skip_ext_pwr_config:
Mark Brownc172708d2012-04-04 00:50:22 +0100147 config.dev = &pdev->dev;
Axel Lin3f24bf72014-02-06 14:49:11 +0800148 config.init_data = pdata->reg_init_data[id];
Axel Linc07608f2019-03-27 19:54:13 +0800149 config.driver_data = ri;
Axel Lin5bb69362012-04-17 14:11:31 +0800150 config.regmap = rc5t583->regmap;
Mark Brownc172708d2012-04-04 00:50:22 +0100151
Sachin Kamat13775302013-09-04 12:01:02 +0530152 rdev = devm_regulator_register(&pdev->dev, &ri->desc, &config);
Axel Lina69df8a2012-04-04 19:52:35 +0800153 if (IS_ERR(rdev)) {
Laxman Dewangan6ffc3272012-04-04 12:44:00 +0530154 dev_err(&pdev->dev, "Failed to register regulator %s\n",
155 ri->desc.name);
Sachin Kamat13775302013-09-04 12:01:02 +0530156 return PTR_ERR(rdev);
Laxman Dewangan6ffc3272012-04-04 12:44:00 +0530157 }
Laxman Dewangan6ffc3272012-04-04 12:44:00 +0530158 }
Laxman Dewangan6ffc3272012-04-04 12:44:00 +0530159 return 0;
Laxman Dewangan6ffc3272012-04-04 12:44:00 +0530160}
161
162static struct platform_driver rc5t583_regulator_driver = {
163 .driver = {
164 .name = "rc5t583-regulator",
Laxman Dewangan6ffc3272012-04-04 12:44:00 +0530165 },
166 .probe = rc5t583_regulator_probe,
Laxman Dewangan6ffc3272012-04-04 12:44:00 +0530167};
168
169static int __init rc5t583_regulator_init(void)
170{
171 return platform_driver_register(&rc5t583_regulator_driver);
172}
173subsys_initcall(rc5t583_regulator_init);
174
175static void __exit rc5t583_regulator_exit(void)
176{
177 platform_driver_unregister(&rc5t583_regulator_driver);
178}
179module_exit(rc5t583_regulator_exit);
180
181MODULE_AUTHOR("Laxman Dewangan <ldewangan@nvidia.com>");
182MODULE_DESCRIPTION("RC5T583 regulator driver");
183MODULE_ALIAS("platform:rc5t583-regulator");
Laxman Dewangan4eb06452012-04-06 10:58:33 +0530184MODULE_LICENSE("GPL v2");