Linux Audio

Check our new training course

Loading...
v3.15
 
  1/*
  2 * tps65218-regulator.c
  3 *
  4 * Regulator driver for TPS65218 PMIC
  5 *
  6 * Copyright (C) 2014 Texas Instruments Incorporated - http://www.ti.com/
  7 *
  8 * This program is free software; you can redistribute it and/or
  9 * modify it under the terms of the GNU General Public License version 2 as
 10 * published by the Free Software Foundation.
 11 *
 12 * This program is distributed "as is" WITHOUT ANY WARRANTY of any
 13 * kind, whether expressed or implied; without even the implied warranty
 14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 15 * GNU General Public License version 2 for more details.
 16 */
 17
 18#include <linux/kernel.h>
 
 19#include <linux/module.h>
 20#include <linux/device.h>
 21#include <linux/init.h>
 22#include <linux/err.h>
 23#include <linux/platform_device.h>
 24#include <linux/of_device.h>
 25#include <linux/regulator/of_regulator.h>
 26#include <linux/regulator/driver.h>
 27#include <linux/regulator/machine.h>
 28#include <linux/mfd/tps65218.h>
 29
 30static unsigned int tps65218_ramp_delay = 4000;
 31
 32enum tps65218_regulators { DCDC1, DCDC2, DCDC3, DCDC4, DCDC5, DCDC6, LDO1 };
 33
 34#define TPS65218_REGULATOR(_name, _id, _ops, _n, _vr, _vm, _er, _em, _t, \
 35			    _lr, _nlr)				\
 36	{							\
 37		.name			= _name,		\
 
 38		.id			= _id,			\
 39		.ops			= &_ops,		\
 40		.n_voltages		= _n,			\
 41		.type			= REGULATOR_VOLTAGE,	\
 42		.owner			= THIS_MODULE,		\
 43		.vsel_reg		= _vr,			\
 44		.vsel_mask		= _vm,			\
 
 
 
 
 45		.enable_reg		= _er,			\
 46		.enable_mask		= _em,			\
 47		.volt_table		= _t,			\
 48		.linear_ranges		= _lr,			\
 49		.n_linear_ranges	= _nlr,			\
 
 
 
 
 50	}							\
 51
 52#define TPS65218_INFO(_id, _nm, _min, _max)	\
 53	{						\
 54		.id		= _id,			\
 55		.name		= _nm,			\
 56		.min_uV		= _min,			\
 57		.max_uV		= _max,			\
 58	}
 59
 60static const struct regulator_linear_range dcdc1_dcdc2_ranges[] = {
 61	REGULATOR_LINEAR_RANGE(850000, 0x0, 0x32, 10000),
 62	REGULATOR_LINEAR_RANGE(1375000, 0x33, 0x3f, 25000),
 63};
 64
 65static const struct regulator_linear_range ldo1_dcdc3_ranges[] = {
 66	REGULATOR_LINEAR_RANGE(900000, 0x0, 0x1a, 25000),
 67	REGULATOR_LINEAR_RANGE(1600000, 0x1b, 0x3f, 50000),
 68};
 69
 70static const struct regulator_linear_range dcdc4_ranges[] = {
 71	REGULATOR_LINEAR_RANGE(1175000, 0x0, 0xf, 25000),
 72	REGULATOR_LINEAR_RANGE(1550000, 0x10, 0x34, 50000),
 73};
 74
 75static struct tps_info tps65218_pmic_regs[] = {
 76	TPS65218_INFO(0, "DCDC1", 850000, 167500),
 77	TPS65218_INFO(1, "DCDC2", 850000, 1675000),
 78	TPS65218_INFO(2, "DCDC3", 900000, 3400000),
 79	TPS65218_INFO(3, "DCDC4", 1175000, 3400000),
 80	TPS65218_INFO(4, "DCDC5", 1000000, 1000000),
 81	TPS65218_INFO(5, "DCDC6", 1800000, 1800000),
 82	TPS65218_INFO(6, "LDO1", 900000, 3400000),
 83};
 84
 85#define TPS65218_OF_MATCH(comp, label) \
 86	{ \
 87		.compatible = comp, \
 88		.data = &label, \
 89	}
 90
 91static const struct of_device_id tps65218_of_match[] = {
 92	TPS65218_OF_MATCH("ti,tps65218-dcdc1", tps65218_pmic_regs[DCDC1]),
 93	TPS65218_OF_MATCH("ti,tps65218-dcdc2", tps65218_pmic_regs[DCDC2]),
 94	TPS65218_OF_MATCH("ti,tps65218-dcdc3", tps65218_pmic_regs[DCDC3]),
 95	TPS65218_OF_MATCH("ti,tps65218-dcdc4", tps65218_pmic_regs[DCDC4]),
 96	TPS65218_OF_MATCH("ti,tps65218-dcdc5", tps65218_pmic_regs[DCDC5]),
 97	TPS65218_OF_MATCH("ti,tps65218-dcdc6", tps65218_pmic_regs[DCDC6]),
 98	TPS65218_OF_MATCH("ti,tps65218-ldo1", tps65218_pmic_regs[LDO1]),
 99	{ }
100};
101MODULE_DEVICE_TABLE(of, tps65218_of_match);
102
103static int tps65218_pmic_set_voltage_sel(struct regulator_dev *dev,
104					 unsigned selector)
105{
106	int ret;
107	struct tps65218 *tps = rdev_get_drvdata(dev);
108	unsigned int rid = rdev_get_id(dev);
109
110	/* Set the voltage based on vsel value and write protect level is 2 */
111	ret = tps65218_set_bits(tps, dev->desc->vsel_reg, dev->desc->vsel_mask,
112				selector, TPS65218_PROTECT_L1);
113
114	/* Set GO bit for DCDC1/2 to initiate voltage transistion */
115	switch (rid) {
116	case TPS65218_DCDC_1:
117	case TPS65218_DCDC_2:
118		ret = tps65218_set_bits(tps, TPS65218_REG_CONTRL_SLEW_RATE,
119					TPS65218_SLEW_RATE_GO,
120					TPS65218_SLEW_RATE_GO,
121					TPS65218_PROTECT_L1);
122		break;
123	}
124
125	return ret;
126}
127
128static int tps65218_pmic_enable(struct regulator_dev *dev)
129{
130	struct tps65218 *tps = rdev_get_drvdata(dev);
131	unsigned int rid = rdev_get_id(dev);
132
133	if (rid < TPS65218_DCDC_1 || rid > TPS65218_LDO_1)
134		return -EINVAL;
135
136	/* Enable the regulator and password protection is level 1 */
137	return tps65218_set_bits(tps, dev->desc->enable_reg,
138				 dev->desc->enable_mask, dev->desc->enable_mask,
139				 TPS65218_PROTECT_L1);
140}
141
142static int tps65218_pmic_disable(struct regulator_dev *dev)
143{
144	struct tps65218 *tps = rdev_get_drvdata(dev);
145	unsigned int rid = rdev_get_id(dev);
146
147	if (rid < TPS65218_DCDC_1 || rid > TPS65218_LDO_1)
148		return -EINVAL;
149
150	/* Disable the regulator and password protection is level 1 */
151	return tps65218_clear_bits(tps, dev->desc->enable_reg,
152				   dev->desc->enable_mask, TPS65218_PROTECT_L1);
153}
154
155static int tps65218_set_voltage_time_sel(struct regulator_dev *rdev,
156	unsigned int old_selector, unsigned int new_selector)
157{
158	int old_uv, new_uv;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
159
160	old_uv = regulator_list_voltage_linear_range(rdev, old_selector);
161	if (old_uv < 0)
162		return old_uv;
163
164	new_uv = regulator_list_voltage_linear_range(rdev, new_selector);
165	if (new_uv < 0)
166		return new_uv;
 
 
 
 
 
 
 
 
 
 
 
167
168	return DIV_ROUND_UP(abs(old_uv - new_uv), tps65218_ramp_delay);
 
 
169}
170
171/* Operations permitted on DCDC1, DCDC2 */
172static struct regulator_ops tps65218_dcdc12_ops = {
173	.is_enabled		= regulator_is_enabled_regmap,
174	.enable			= tps65218_pmic_enable,
175	.disable		= tps65218_pmic_disable,
176	.get_voltage_sel	= regulator_get_voltage_sel_regmap,
177	.set_voltage_sel	= tps65218_pmic_set_voltage_sel,
178	.list_voltage		= regulator_list_voltage_linear_range,
179	.map_voltage		= regulator_map_voltage_linear_range,
180	.set_voltage_time_sel	= tps65218_set_voltage_time_sel,
 
 
181};
182
183/* Operations permitted on DCDC3, DCDC4 and LDO1 */
184static struct regulator_ops tps65218_ldo1_dcdc34_ops = {
185	.is_enabled		= regulator_is_enabled_regmap,
186	.enable			= tps65218_pmic_enable,
187	.disable		= tps65218_pmic_disable,
188	.get_voltage_sel	= regulator_get_voltage_sel_regmap,
189	.set_voltage_sel	= tps65218_pmic_set_voltage_sel,
190	.list_voltage		= regulator_list_voltage_linear_range,
191	.map_voltage		= regulator_map_voltage_linear_range,
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
192};
193
194/* Operations permitted on DCDC5, DCDC6 */
195static struct regulator_ops tps65218_dcdc56_pmic_ops = {
196	.is_enabled		= regulator_is_enabled_regmap,
197	.enable			= tps65218_pmic_enable,
198	.disable		= tps65218_pmic_disable,
 
 
199};
200
201static const struct regulator_desc regulators[] = {
202	TPS65218_REGULATOR("DCDC1", TPS65218_DCDC_1, tps65218_dcdc12_ops, 64,
 
203			   TPS65218_REG_CONTROL_DCDC1,
204			   TPS65218_CONTROL_DCDC1_MASK,
205			   TPS65218_REG_ENABLE1, TPS65218_ENABLE1_DC1_EN, NULL,
206			   dcdc1_dcdc2_ranges, 2),
207	TPS65218_REGULATOR("DCDC2", TPS65218_DCDC_2, tps65218_dcdc12_ops, 64,
 
 
208			   TPS65218_REG_CONTROL_DCDC2,
209			   TPS65218_CONTROL_DCDC2_MASK,
210			   TPS65218_REG_ENABLE1, TPS65218_ENABLE1_DC2_EN, NULL,
211			   dcdc1_dcdc2_ranges, 2),
212	TPS65218_REGULATOR("DCDC3", TPS65218_DCDC_3, tps65218_ldo1_dcdc34_ops,
213			   64, TPS65218_REG_CONTROL_DCDC3,
 
 
214			   TPS65218_CONTROL_DCDC3_MASK, TPS65218_REG_ENABLE1,
215			   TPS65218_ENABLE1_DC3_EN, NULL,
216			   ldo1_dcdc3_ranges, 2),
217	TPS65218_REGULATOR("DCDC4", TPS65218_DCDC_4, tps65218_ldo1_dcdc34_ops,
218			   53, TPS65218_REG_CONTROL_DCDC4,
219			   TPS65218_CONTROL_DCDC4_MASK,
220			   TPS65218_REG_ENABLE1, TPS65218_ENABLE1_DC4_EN, NULL,
221			   dcdc4_ranges, 2),
222	TPS65218_REGULATOR("DCDC5", TPS65218_DCDC_5, tps65218_dcdc56_pmic_ops,
223			   1, -1, -1, TPS65218_REG_ENABLE1,
224			   TPS65218_ENABLE1_DC5_EN, NULL, NULL, 0),
225	TPS65218_REGULATOR("DCDC6", TPS65218_DCDC_6, tps65218_dcdc56_pmic_ops,
226			   1, -1, -1, TPS65218_REG_ENABLE1,
227			   TPS65218_ENABLE1_DC6_EN, NULL, NULL, 0),
228	TPS65218_REGULATOR("LDO1", TPS65218_LDO_1, tps65218_ldo1_dcdc34_ops, 64,
229			   TPS65218_REG_CONTROL_DCDC4,
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
230			   TPS65218_CONTROL_LDO1_MASK, TPS65218_REG_ENABLE2,
231			   TPS65218_ENABLE2_LDO1_EN, NULL, ldo1_dcdc3_ranges,
232			   2),
 
 
 
 
 
 
 
 
 
 
 
 
 
233};
234
235static int tps65218_regulator_probe(struct platform_device *pdev)
236{
237	struct tps65218 *tps = dev_get_drvdata(pdev->dev.parent);
238	struct regulator_init_data *init_data;
239	const struct tps_info	*template;
240	struct regulator_dev *rdev;
241	const struct of_device_id	*match;
242	struct regulator_config config = { };
243	int id;
244
245	match = of_match_device(tps65218_of_match, &pdev->dev);
246	if (!match)
247		return -ENODEV;
248
249	template = match->data;
250	id = template->id;
251	init_data = of_get_regulator_init_data(&pdev->dev, pdev->dev.of_node);
252
253	platform_set_drvdata(pdev, tps);
254
255	tps->info[id] = &tps65218_pmic_regs[id];
256	config.dev = &pdev->dev;
257	config.init_data = init_data;
258	config.driver_data = tps;
259	config.regmap = tps->regmap;
260
261	rdev = devm_regulator_register(&pdev->dev, &regulators[id], &config);
262	if (IS_ERR(rdev)) {
263		dev_err(tps->dev, "failed to register %s regulator\n",
264			pdev->name);
265		return PTR_ERR(rdev);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
266	}
267
268	return 0;
269}
270
 
 
 
 
 
 
271static struct platform_driver tps65218_regulator_driver = {
272	.driver = {
273		.name = "tps65218-pmic",
274		.owner = THIS_MODULE,
275		.of_match_table = tps65218_of_match,
276	},
277	.probe = tps65218_regulator_probe,
 
278};
279
280module_platform_driver(tps65218_regulator_driver);
281
282MODULE_AUTHOR("J Keerthy <j-keerthy@ti.com>");
283MODULE_DESCRIPTION("TPS65218 voltage regulator driver");
284MODULE_ALIAS("platform:tps65218-pmic");
285MODULE_LICENSE("GPL v2");
v6.13.7
  1// SPDX-License-Identifier: GPL-2.0-only
  2/*
  3 * tps65218-regulator.c
  4 *
  5 * Regulator driver for TPS65218 PMIC
  6 *
  7 * Copyright (C) 2014 Texas Instruments Incorporated - https://www.ti.com/
 
 
 
 
 
 
 
 
 
  8 */
  9
 10#include <linux/kernel.h>
 11#include <linux/mod_devicetable.h>
 12#include <linux/module.h>
 13#include <linux/device.h>
 14#include <linux/init.h>
 15#include <linux/err.h>
 16#include <linux/platform_device.h>
 17#include <linux/regmap.h>
 18#include <linux/regulator/of_regulator.h>
 19#include <linux/regulator/driver.h>
 20#include <linux/regulator/machine.h>
 21#include <linux/mfd/tps65218.h>
 22
 23#define TPS65218_REGULATOR(_name, _of, _id, _type, _ops, _n, _vr, _vm, _er, \
 24			   _em, _cr, _cm, _lr, _nlr, _delay, _fuv, _sr, _sm, \
 25			   _ct, _ncl) \
 
 
 
 26	{							\
 27		.name			= _name,		\
 28		.of_match		= _of,			\
 29		.id			= _id,			\
 30		.ops			= &_ops,		\
 31		.n_voltages		= _n,			\
 32		.type			= _type,	\
 33		.owner			= THIS_MODULE,		\
 34		.vsel_reg		= _vr,			\
 35		.vsel_mask		= _vm,			\
 36		.csel_reg		= _cr,			\
 37		.csel_mask		= _cm,			\
 38		.curr_table		= _ct,			\
 39		.n_current_limits	= _ncl,			\
 40		.enable_reg		= _er,			\
 41		.enable_mask		= _em,			\
 42		.volt_table		= NULL,			\
 43		.linear_ranges		= _lr,			\
 44		.n_linear_ranges	= _nlr,			\
 45		.ramp_delay		= _delay,		\
 46		.fixed_uV		= _fuv,			\
 47		.bypass_reg	= _sr,				\
 48		.bypass_mask	= _sm,				\
 49	}							\
 50
 51static const struct linear_range dcdc1_dcdc2_ranges[] = {
 
 
 
 
 
 
 
 
 52	REGULATOR_LINEAR_RANGE(850000, 0x0, 0x32, 10000),
 53	REGULATOR_LINEAR_RANGE(1375000, 0x33, 0x3f, 25000),
 54};
 55
 56static const struct linear_range ldo1_dcdc3_ranges[] = {
 57	REGULATOR_LINEAR_RANGE(900000, 0x0, 0x1a, 25000),
 58	REGULATOR_LINEAR_RANGE(1600000, 0x1b, 0x3f, 50000),
 59};
 60
 61static const struct linear_range dcdc4_ranges[] = {
 62	REGULATOR_LINEAR_RANGE(1175000, 0x0, 0xf, 25000),
 63	REGULATOR_LINEAR_RANGE(1600000, 0x10, 0x34, 50000),
 
 
 
 
 
 
 
 
 
 
 64};
 65
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 66static int tps65218_pmic_set_voltage_sel(struct regulator_dev *dev,
 67					 unsigned selector)
 68{
 69	int ret;
 70	struct tps65218 *tps = rdev_get_drvdata(dev);
 71	unsigned int rid = rdev_get_id(dev);
 72
 73	/* Set the voltage based on vsel value and write protect level is 2 */
 74	ret = tps65218_set_bits(tps, dev->desc->vsel_reg, dev->desc->vsel_mask,
 75				selector, TPS65218_PROTECT_L1);
 76
 77	/* Set GO bit for DCDC1/2 to initiate voltage transistion */
 78	switch (rid) {
 79	case TPS65218_DCDC_1:
 80	case TPS65218_DCDC_2:
 81		ret = tps65218_set_bits(tps, TPS65218_REG_CONTRL_SLEW_RATE,
 82					TPS65218_SLEW_RATE_GO,
 83					TPS65218_SLEW_RATE_GO,
 84					TPS65218_PROTECT_L1);
 85		break;
 86	}
 87
 88	return ret;
 89}
 90
 91static int tps65218_pmic_enable(struct regulator_dev *dev)
 92{
 93	struct tps65218 *tps = rdev_get_drvdata(dev);
 94	int rid = rdev_get_id(dev);
 95
 96	if (rid < TPS65218_DCDC_1 || rid > TPS65218_LDO_1)
 97		return -EINVAL;
 98
 99	/* Enable the regulator and password protection is level 1 */
100	return tps65218_set_bits(tps, dev->desc->enable_reg,
101				 dev->desc->enable_mask, dev->desc->enable_mask,
102				 TPS65218_PROTECT_L1);
103}
104
105static int tps65218_pmic_disable(struct regulator_dev *dev)
106{
107	struct tps65218 *tps = rdev_get_drvdata(dev);
108	int rid = rdev_get_id(dev);
109
110	if (rid < TPS65218_DCDC_1 || rid > TPS65218_LDO_1)
111		return -EINVAL;
112
113	/* Disable the regulator and password protection is level 1 */
114	return tps65218_clear_bits(tps, dev->desc->enable_reg,
115				   dev->desc->enable_mask, TPS65218_PROTECT_L1);
116}
117
118static int tps65218_pmic_set_suspend_enable(struct regulator_dev *dev)
 
119{
120	struct tps65218 *tps = rdev_get_drvdata(dev);
121	unsigned int rid = rdev_get_id(dev);
122
123	if (rid > TPS65218_LDO_1)
124		return -EINVAL;
125
126	return tps65218_clear_bits(tps, dev->desc->bypass_reg,
127				   dev->desc->bypass_mask,
128				   TPS65218_PROTECT_L1);
129}
130
131static int tps65218_pmic_set_suspend_disable(struct regulator_dev *dev)
132{
133	struct tps65218 *tps = rdev_get_drvdata(dev);
134	unsigned int rid = rdev_get_id(dev);
135
136	if (rid > TPS65218_LDO_1)
137		return -EINVAL;
 
138
139	/*
140	 * Certain revisions of TPS65218 will need to have DCDC3 regulator
141	 * enabled always, otherwise an immediate system reboot will occur
142	 * during poweroff.
143	 */
144	if (rid == TPS65218_DCDC_3 && tps->rev == TPS65218_REV_2_1)
145		return 0;
146
147	if (!tps->strobes[rid]) {
148		if (rid == TPS65218_DCDC_3)
149			tps->strobes[rid] = 3;
150		else
151			return -EINVAL;
152	}
153
154	return tps65218_set_bits(tps, dev->desc->bypass_reg,
155				 dev->desc->bypass_mask,
156				 tps->strobes[rid], TPS65218_PROTECT_L1);
157}
158
159/* Operations permitted on DCDC1, DCDC2 */
160static const struct regulator_ops tps65218_dcdc12_ops = {
161	.is_enabled		= regulator_is_enabled_regmap,
162	.enable			= tps65218_pmic_enable,
163	.disable		= tps65218_pmic_disable,
164	.get_voltage_sel	= regulator_get_voltage_sel_regmap,
165	.set_voltage_sel	= tps65218_pmic_set_voltage_sel,
166	.list_voltage		= regulator_list_voltage_linear_range,
167	.map_voltage		= regulator_map_voltage_linear_range,
168	.set_voltage_time_sel	= regulator_set_voltage_time_sel,
169	.set_suspend_enable	= tps65218_pmic_set_suspend_enable,
170	.set_suspend_disable	= tps65218_pmic_set_suspend_disable,
171};
172
173/* Operations permitted on DCDC3, DCDC4 and LDO1 */
174static const struct regulator_ops tps65218_ldo1_dcdc34_ops = {
175	.is_enabled		= regulator_is_enabled_regmap,
176	.enable			= tps65218_pmic_enable,
177	.disable		= tps65218_pmic_disable,
178	.get_voltage_sel	= regulator_get_voltage_sel_regmap,
179	.set_voltage_sel	= tps65218_pmic_set_voltage_sel,
180	.list_voltage		= regulator_list_voltage_linear_range,
181	.map_voltage		= regulator_map_voltage_linear_range,
182	.set_suspend_enable	= tps65218_pmic_set_suspend_enable,
183	.set_suspend_disable	= tps65218_pmic_set_suspend_disable,
184};
185
186static const unsigned int ls3_currents[] = { 100000, 200000, 500000, 1000000 };
187
188static int tps65218_pmic_set_input_current_lim(struct regulator_dev *dev,
189					       int lim_uA)
190{
191	unsigned int index = 0;
192	unsigned int num_currents = ARRAY_SIZE(ls3_currents);
193	struct tps65218 *tps = rdev_get_drvdata(dev);
194
195	while (index < num_currents && ls3_currents[index] != lim_uA)
196		index++;
197
198	if (index == num_currents)
199		return -EINVAL;
200
201	return tps65218_set_bits(tps, dev->desc->csel_reg, dev->desc->csel_mask,
202				 index << __builtin_ctz(dev->desc->csel_mask),
203				 TPS65218_PROTECT_L1);
204}
205
206static int tps65218_pmic_set_current_limit(struct regulator_dev *dev,
207					   int min_uA, int max_uA)
208{
209	int index = 0;
210	unsigned int num_currents = ARRAY_SIZE(ls3_currents);
211	struct tps65218 *tps = rdev_get_drvdata(dev);
212
213	while (index < num_currents && ls3_currents[index] <= max_uA)
214		index++;
215
216	index--;
217
218	if (index < 0 || ls3_currents[index] < min_uA)
219		return -EINVAL;
220
221	return tps65218_set_bits(tps, dev->desc->csel_reg, dev->desc->csel_mask,
222				 index << __builtin_ctz(dev->desc->csel_mask),
223				 TPS65218_PROTECT_L1);
224}
225
226static const struct regulator_ops tps65218_ls23_ops = {
227	.is_enabled		= regulator_is_enabled_regmap,
228	.enable			= tps65218_pmic_enable,
229	.disable		= tps65218_pmic_disable,
230	.set_input_current_limit = tps65218_pmic_set_input_current_lim,
231	.set_current_limit	= tps65218_pmic_set_current_limit,
232	.get_current_limit	= regulator_get_current_limit_regmap,
233};
234
235/* Operations permitted on DCDC5, DCDC6 */
236static const struct regulator_ops tps65218_dcdc56_pmic_ops = {
237	.is_enabled		= regulator_is_enabled_regmap,
238	.enable			= tps65218_pmic_enable,
239	.disable		= tps65218_pmic_disable,
240	.set_suspend_enable	= tps65218_pmic_set_suspend_enable,
241	.set_suspend_disable	= tps65218_pmic_set_suspend_disable,
242};
243
244static const struct regulator_desc regulators[] = {
245	TPS65218_REGULATOR("DCDC1", "regulator-dcdc1", TPS65218_DCDC_1,
246			   REGULATOR_VOLTAGE, tps65218_dcdc12_ops, 64,
247			   TPS65218_REG_CONTROL_DCDC1,
248			   TPS65218_CONTROL_DCDC1_MASK, TPS65218_REG_ENABLE1,
249			   TPS65218_ENABLE1_DC1_EN, 0, 0, dcdc1_dcdc2_ranges,
250			   2, 4000, 0, TPS65218_REG_SEQ3,
251			   TPS65218_SEQ3_DC1_SEQ_MASK, NULL, 0),
252	TPS65218_REGULATOR("DCDC2", "regulator-dcdc2", TPS65218_DCDC_2,
253			   REGULATOR_VOLTAGE, tps65218_dcdc12_ops, 64,
254			   TPS65218_REG_CONTROL_DCDC2,
255			   TPS65218_CONTROL_DCDC2_MASK, TPS65218_REG_ENABLE1,
256			   TPS65218_ENABLE1_DC2_EN, 0, 0, dcdc1_dcdc2_ranges,
257			   2, 4000, 0, TPS65218_REG_SEQ3,
258			   TPS65218_SEQ3_DC2_SEQ_MASK, NULL, 0),
259	TPS65218_REGULATOR("DCDC3", "regulator-dcdc3", TPS65218_DCDC_3,
260			   REGULATOR_VOLTAGE, tps65218_ldo1_dcdc34_ops, 64,
261			   TPS65218_REG_CONTROL_DCDC3,
262			   TPS65218_CONTROL_DCDC3_MASK, TPS65218_REG_ENABLE1,
263			   TPS65218_ENABLE1_DC3_EN, 0, 0, ldo1_dcdc3_ranges, 2,
264			   0, 0, TPS65218_REG_SEQ4, TPS65218_SEQ4_DC3_SEQ_MASK,
265			   NULL, 0),
266	TPS65218_REGULATOR("DCDC4", "regulator-dcdc4", TPS65218_DCDC_4,
267			   REGULATOR_VOLTAGE, tps65218_ldo1_dcdc34_ops, 53,
 
 
 
 
 
 
 
 
 
268			   TPS65218_REG_CONTROL_DCDC4,
269			   TPS65218_CONTROL_DCDC4_MASK, TPS65218_REG_ENABLE1,
270			   TPS65218_ENABLE1_DC4_EN, 0, 0, dcdc4_ranges, 2,
271			   0, 0, TPS65218_REG_SEQ4, TPS65218_SEQ4_DC4_SEQ_MASK,
272			   NULL, 0),
273	TPS65218_REGULATOR("DCDC5", "regulator-dcdc5", TPS65218_DCDC_5,
274			   REGULATOR_VOLTAGE, tps65218_dcdc56_pmic_ops, 1, -1,
275			   -1, TPS65218_REG_ENABLE1, TPS65218_ENABLE1_DC5_EN, 0,
276			   0, NULL, 0, 0, 1000000, TPS65218_REG_SEQ5,
277			   TPS65218_SEQ5_DC5_SEQ_MASK, NULL, 0),
278	TPS65218_REGULATOR("DCDC6", "regulator-dcdc6", TPS65218_DCDC_6,
279			   REGULATOR_VOLTAGE, tps65218_dcdc56_pmic_ops, 1, -1,
280			   -1, TPS65218_REG_ENABLE1, TPS65218_ENABLE1_DC6_EN, 0,
281			   0, NULL, 0, 0, 1800000, TPS65218_REG_SEQ5,
282			   TPS65218_SEQ5_DC6_SEQ_MASK, NULL, 0),
283	TPS65218_REGULATOR("LDO1", "regulator-ldo1", TPS65218_LDO_1,
284			   REGULATOR_VOLTAGE, tps65218_ldo1_dcdc34_ops, 64,
285			   TPS65218_REG_CONTROL_LDO1,
286			   TPS65218_CONTROL_LDO1_MASK, TPS65218_REG_ENABLE2,
287			   TPS65218_ENABLE2_LDO1_EN, 0, 0, ldo1_dcdc3_ranges,
288			   2, 0, 0, TPS65218_REG_SEQ6,
289			   TPS65218_SEQ6_LDO1_SEQ_MASK, NULL, 0),
290	TPS65218_REGULATOR("LS2", "regulator-ls2", TPS65218_LS_2,
291			   REGULATOR_CURRENT, tps65218_ls23_ops, 0, 0, 0,
292			   TPS65218_REG_ENABLE2, TPS65218_ENABLE2_LS2_EN,
293			   TPS65218_REG_CONFIG2, TPS65218_CONFIG2_LS2ILIM_MASK,
294			   NULL, 0, 0, 0, 0, 0, ls3_currents,
295			   ARRAY_SIZE(ls3_currents)),
296	TPS65218_REGULATOR("LS3", "regulator-ls3", TPS65218_LS_3,
297			   REGULATOR_CURRENT, tps65218_ls23_ops, 0, 0, 0,
298			   TPS65218_REG_ENABLE2, TPS65218_ENABLE2_LS3_EN,
299			   TPS65218_REG_CONFIG2, TPS65218_CONFIG2_LS3ILIM_MASK,
300			   NULL, 0, 0, 0, 0, 0, ls3_currents,
301			   ARRAY_SIZE(ls3_currents)),
302};
303
304static int tps65218_regulator_probe(struct platform_device *pdev)
305{
306	struct tps65218 *tps = dev_get_drvdata(pdev->dev.parent);
 
 
307	struct regulator_dev *rdev;
 
308	struct regulator_config config = { };
309	int i, ret;
310	unsigned int val;
 
 
 
 
 
 
 
 
 
311
 
312	config.dev = &pdev->dev;
313	config.dev->of_node = tps->dev->of_node;
314	config.driver_data = tps;
315	config.regmap = tps->regmap;
316
317	/* Allocate memory for strobes */
318	tps->strobes = devm_kcalloc(&pdev->dev,
319				    TPS65218_NUM_REGULATOR, sizeof(u8),
320				    GFP_KERNEL);
321	if (!tps->strobes)
322		return -ENOMEM;
323
324	for (i = 0; i < ARRAY_SIZE(regulators); i++) {
325		rdev = devm_regulator_register(&pdev->dev, &regulators[i],
326					       &config);
327		if (IS_ERR(rdev)) {
328			dev_err(tps->dev, "failed to register %s regulator\n",
329				pdev->name);
330			return PTR_ERR(rdev);
331		}
332
333		ret = regmap_read(tps->regmap, regulators[i].bypass_reg, &val);
334		if (ret)
335			return ret;
336
337		tps->strobes[i] = val & regulators[i].bypass_mask;
338	}
339
340	return 0;
341}
342
343static const struct platform_device_id tps65218_regulator_id_table[] = {
344	{ "tps65218-regulator", },
345	{ /* sentinel */ }
346};
347MODULE_DEVICE_TABLE(platform, tps65218_regulator_id_table);
348
349static struct platform_driver tps65218_regulator_driver = {
350	.driver = {
351		.name = "tps65218-pmic",
352		.probe_type = PROBE_PREFER_ASYNCHRONOUS,
 
353	},
354	.probe = tps65218_regulator_probe,
355	.id_table = tps65218_regulator_id_table,
356};
357
358module_platform_driver(tps65218_regulator_driver);
359
360MODULE_AUTHOR("J Keerthy <j-keerthy@ti.com>");
361MODULE_DESCRIPTION("TPS65218 voltage regulator driver");
362MODULE_ALIAS("platform:tps65218-pmic");
363MODULE_LICENSE("GPL v2");