162306a36Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-only
262306a36Sopenharmony_ci/*
362306a36Sopenharmony_ci * tps65218-regulator.c
462306a36Sopenharmony_ci *
562306a36Sopenharmony_ci * Regulator driver for TPS65218 PMIC
662306a36Sopenharmony_ci *
762306a36Sopenharmony_ci * Copyright (C) 2014 Texas Instruments Incorporated - https://www.ti.com/
862306a36Sopenharmony_ci */
962306a36Sopenharmony_ci
1062306a36Sopenharmony_ci#include <linux/kernel.h>
1162306a36Sopenharmony_ci#include <linux/mod_devicetable.h>
1262306a36Sopenharmony_ci#include <linux/module.h>
1362306a36Sopenharmony_ci#include <linux/device.h>
1462306a36Sopenharmony_ci#include <linux/init.h>
1562306a36Sopenharmony_ci#include <linux/err.h>
1662306a36Sopenharmony_ci#include <linux/platform_device.h>
1762306a36Sopenharmony_ci#include <linux/regmap.h>
1862306a36Sopenharmony_ci#include <linux/regulator/of_regulator.h>
1962306a36Sopenharmony_ci#include <linux/regulator/driver.h>
2062306a36Sopenharmony_ci#include <linux/regulator/machine.h>
2162306a36Sopenharmony_ci#include <linux/mfd/tps65218.h>
2262306a36Sopenharmony_ci
2362306a36Sopenharmony_ci#define TPS65218_REGULATOR(_name, _of, _id, _type, _ops, _n, _vr, _vm, _er, \
2462306a36Sopenharmony_ci			   _em, _cr, _cm, _lr, _nlr, _delay, _fuv, _sr, _sm, \
2562306a36Sopenharmony_ci			   _ct, _ncl) \
2662306a36Sopenharmony_ci	{							\
2762306a36Sopenharmony_ci		.name			= _name,		\
2862306a36Sopenharmony_ci		.of_match		= _of,			\
2962306a36Sopenharmony_ci		.id			= _id,			\
3062306a36Sopenharmony_ci		.ops			= &_ops,		\
3162306a36Sopenharmony_ci		.n_voltages		= _n,			\
3262306a36Sopenharmony_ci		.type			= _type,	\
3362306a36Sopenharmony_ci		.owner			= THIS_MODULE,		\
3462306a36Sopenharmony_ci		.vsel_reg		= _vr,			\
3562306a36Sopenharmony_ci		.vsel_mask		= _vm,			\
3662306a36Sopenharmony_ci		.csel_reg		= _cr,			\
3762306a36Sopenharmony_ci		.csel_mask		= _cm,			\
3862306a36Sopenharmony_ci		.curr_table		= _ct,			\
3962306a36Sopenharmony_ci		.n_current_limits	= _ncl,			\
4062306a36Sopenharmony_ci		.enable_reg		= _er,			\
4162306a36Sopenharmony_ci		.enable_mask		= _em,			\
4262306a36Sopenharmony_ci		.volt_table		= NULL,			\
4362306a36Sopenharmony_ci		.linear_ranges		= _lr,			\
4462306a36Sopenharmony_ci		.n_linear_ranges	= _nlr,			\
4562306a36Sopenharmony_ci		.ramp_delay		= _delay,		\
4662306a36Sopenharmony_ci		.fixed_uV		= _fuv,			\
4762306a36Sopenharmony_ci		.bypass_reg	= _sr,				\
4862306a36Sopenharmony_ci		.bypass_mask	= _sm,				\
4962306a36Sopenharmony_ci	}							\
5062306a36Sopenharmony_ci
5162306a36Sopenharmony_cistatic const struct linear_range dcdc1_dcdc2_ranges[] = {
5262306a36Sopenharmony_ci	REGULATOR_LINEAR_RANGE(850000, 0x0, 0x32, 10000),
5362306a36Sopenharmony_ci	REGULATOR_LINEAR_RANGE(1375000, 0x33, 0x3f, 25000),
5462306a36Sopenharmony_ci};
5562306a36Sopenharmony_ci
5662306a36Sopenharmony_cistatic const struct linear_range ldo1_dcdc3_ranges[] = {
5762306a36Sopenharmony_ci	REGULATOR_LINEAR_RANGE(900000, 0x0, 0x1a, 25000),
5862306a36Sopenharmony_ci	REGULATOR_LINEAR_RANGE(1600000, 0x1b, 0x3f, 50000),
5962306a36Sopenharmony_ci};
6062306a36Sopenharmony_ci
6162306a36Sopenharmony_cistatic const struct linear_range dcdc4_ranges[] = {
6262306a36Sopenharmony_ci	REGULATOR_LINEAR_RANGE(1175000, 0x0, 0xf, 25000),
6362306a36Sopenharmony_ci	REGULATOR_LINEAR_RANGE(1600000, 0x10, 0x34, 50000),
6462306a36Sopenharmony_ci};
6562306a36Sopenharmony_ci
6662306a36Sopenharmony_cistatic int tps65218_pmic_set_voltage_sel(struct regulator_dev *dev,
6762306a36Sopenharmony_ci					 unsigned selector)
6862306a36Sopenharmony_ci{
6962306a36Sopenharmony_ci	int ret;
7062306a36Sopenharmony_ci	struct tps65218 *tps = rdev_get_drvdata(dev);
7162306a36Sopenharmony_ci	unsigned int rid = rdev_get_id(dev);
7262306a36Sopenharmony_ci
7362306a36Sopenharmony_ci	/* Set the voltage based on vsel value and write protect level is 2 */
7462306a36Sopenharmony_ci	ret = tps65218_set_bits(tps, dev->desc->vsel_reg, dev->desc->vsel_mask,
7562306a36Sopenharmony_ci				selector, TPS65218_PROTECT_L1);
7662306a36Sopenharmony_ci
7762306a36Sopenharmony_ci	/* Set GO bit for DCDC1/2 to initiate voltage transistion */
7862306a36Sopenharmony_ci	switch (rid) {
7962306a36Sopenharmony_ci	case TPS65218_DCDC_1:
8062306a36Sopenharmony_ci	case TPS65218_DCDC_2:
8162306a36Sopenharmony_ci		ret = tps65218_set_bits(tps, TPS65218_REG_CONTRL_SLEW_RATE,
8262306a36Sopenharmony_ci					TPS65218_SLEW_RATE_GO,
8362306a36Sopenharmony_ci					TPS65218_SLEW_RATE_GO,
8462306a36Sopenharmony_ci					TPS65218_PROTECT_L1);
8562306a36Sopenharmony_ci		break;
8662306a36Sopenharmony_ci	}
8762306a36Sopenharmony_ci
8862306a36Sopenharmony_ci	return ret;
8962306a36Sopenharmony_ci}
9062306a36Sopenharmony_ci
9162306a36Sopenharmony_cistatic int tps65218_pmic_enable(struct regulator_dev *dev)
9262306a36Sopenharmony_ci{
9362306a36Sopenharmony_ci	struct tps65218 *tps = rdev_get_drvdata(dev);
9462306a36Sopenharmony_ci	int rid = rdev_get_id(dev);
9562306a36Sopenharmony_ci
9662306a36Sopenharmony_ci	if (rid < TPS65218_DCDC_1 || rid > TPS65218_LDO_1)
9762306a36Sopenharmony_ci		return -EINVAL;
9862306a36Sopenharmony_ci
9962306a36Sopenharmony_ci	/* Enable the regulator and password protection is level 1 */
10062306a36Sopenharmony_ci	return tps65218_set_bits(tps, dev->desc->enable_reg,
10162306a36Sopenharmony_ci				 dev->desc->enable_mask, dev->desc->enable_mask,
10262306a36Sopenharmony_ci				 TPS65218_PROTECT_L1);
10362306a36Sopenharmony_ci}
10462306a36Sopenharmony_ci
10562306a36Sopenharmony_cistatic int tps65218_pmic_disable(struct regulator_dev *dev)
10662306a36Sopenharmony_ci{
10762306a36Sopenharmony_ci	struct tps65218 *tps = rdev_get_drvdata(dev);
10862306a36Sopenharmony_ci	int rid = rdev_get_id(dev);
10962306a36Sopenharmony_ci
11062306a36Sopenharmony_ci	if (rid < TPS65218_DCDC_1 || rid > TPS65218_LDO_1)
11162306a36Sopenharmony_ci		return -EINVAL;
11262306a36Sopenharmony_ci
11362306a36Sopenharmony_ci	/* Disable the regulator and password protection is level 1 */
11462306a36Sopenharmony_ci	return tps65218_clear_bits(tps, dev->desc->enable_reg,
11562306a36Sopenharmony_ci				   dev->desc->enable_mask, TPS65218_PROTECT_L1);
11662306a36Sopenharmony_ci}
11762306a36Sopenharmony_ci
11862306a36Sopenharmony_cistatic int tps65218_pmic_set_suspend_enable(struct regulator_dev *dev)
11962306a36Sopenharmony_ci{
12062306a36Sopenharmony_ci	struct tps65218 *tps = rdev_get_drvdata(dev);
12162306a36Sopenharmony_ci	unsigned int rid = rdev_get_id(dev);
12262306a36Sopenharmony_ci
12362306a36Sopenharmony_ci	if (rid > TPS65218_LDO_1)
12462306a36Sopenharmony_ci		return -EINVAL;
12562306a36Sopenharmony_ci
12662306a36Sopenharmony_ci	return tps65218_clear_bits(tps, dev->desc->bypass_reg,
12762306a36Sopenharmony_ci				   dev->desc->bypass_mask,
12862306a36Sopenharmony_ci				   TPS65218_PROTECT_L1);
12962306a36Sopenharmony_ci}
13062306a36Sopenharmony_ci
13162306a36Sopenharmony_cistatic int tps65218_pmic_set_suspend_disable(struct regulator_dev *dev)
13262306a36Sopenharmony_ci{
13362306a36Sopenharmony_ci	struct tps65218 *tps = rdev_get_drvdata(dev);
13462306a36Sopenharmony_ci	unsigned int rid = rdev_get_id(dev);
13562306a36Sopenharmony_ci
13662306a36Sopenharmony_ci	if (rid > TPS65218_LDO_1)
13762306a36Sopenharmony_ci		return -EINVAL;
13862306a36Sopenharmony_ci
13962306a36Sopenharmony_ci	/*
14062306a36Sopenharmony_ci	 * Certain revisions of TPS65218 will need to have DCDC3 regulator
14162306a36Sopenharmony_ci	 * enabled always, otherwise an immediate system reboot will occur
14262306a36Sopenharmony_ci	 * during poweroff.
14362306a36Sopenharmony_ci	 */
14462306a36Sopenharmony_ci	if (rid == TPS65218_DCDC_3 && tps->rev == TPS65218_REV_2_1)
14562306a36Sopenharmony_ci		return 0;
14662306a36Sopenharmony_ci
14762306a36Sopenharmony_ci	if (!tps->strobes[rid]) {
14862306a36Sopenharmony_ci		if (rid == TPS65218_DCDC_3)
14962306a36Sopenharmony_ci			tps->strobes[rid] = 3;
15062306a36Sopenharmony_ci		else
15162306a36Sopenharmony_ci			return -EINVAL;
15262306a36Sopenharmony_ci	}
15362306a36Sopenharmony_ci
15462306a36Sopenharmony_ci	return tps65218_set_bits(tps, dev->desc->bypass_reg,
15562306a36Sopenharmony_ci				 dev->desc->bypass_mask,
15662306a36Sopenharmony_ci				 tps->strobes[rid], TPS65218_PROTECT_L1);
15762306a36Sopenharmony_ci}
15862306a36Sopenharmony_ci
15962306a36Sopenharmony_ci/* Operations permitted on DCDC1, DCDC2 */
16062306a36Sopenharmony_cistatic const struct regulator_ops tps65218_dcdc12_ops = {
16162306a36Sopenharmony_ci	.is_enabled		= regulator_is_enabled_regmap,
16262306a36Sopenharmony_ci	.enable			= tps65218_pmic_enable,
16362306a36Sopenharmony_ci	.disable		= tps65218_pmic_disable,
16462306a36Sopenharmony_ci	.get_voltage_sel	= regulator_get_voltage_sel_regmap,
16562306a36Sopenharmony_ci	.set_voltage_sel	= tps65218_pmic_set_voltage_sel,
16662306a36Sopenharmony_ci	.list_voltage		= regulator_list_voltage_linear_range,
16762306a36Sopenharmony_ci	.map_voltage		= regulator_map_voltage_linear_range,
16862306a36Sopenharmony_ci	.set_voltage_time_sel	= regulator_set_voltage_time_sel,
16962306a36Sopenharmony_ci	.set_suspend_enable	= tps65218_pmic_set_suspend_enable,
17062306a36Sopenharmony_ci	.set_suspend_disable	= tps65218_pmic_set_suspend_disable,
17162306a36Sopenharmony_ci};
17262306a36Sopenharmony_ci
17362306a36Sopenharmony_ci/* Operations permitted on DCDC3, DCDC4 and LDO1 */
17462306a36Sopenharmony_cistatic const struct regulator_ops tps65218_ldo1_dcdc34_ops = {
17562306a36Sopenharmony_ci	.is_enabled		= regulator_is_enabled_regmap,
17662306a36Sopenharmony_ci	.enable			= tps65218_pmic_enable,
17762306a36Sopenharmony_ci	.disable		= tps65218_pmic_disable,
17862306a36Sopenharmony_ci	.get_voltage_sel	= regulator_get_voltage_sel_regmap,
17962306a36Sopenharmony_ci	.set_voltage_sel	= tps65218_pmic_set_voltage_sel,
18062306a36Sopenharmony_ci	.list_voltage		= regulator_list_voltage_linear_range,
18162306a36Sopenharmony_ci	.map_voltage		= regulator_map_voltage_linear_range,
18262306a36Sopenharmony_ci	.set_suspend_enable	= tps65218_pmic_set_suspend_enable,
18362306a36Sopenharmony_ci	.set_suspend_disable	= tps65218_pmic_set_suspend_disable,
18462306a36Sopenharmony_ci};
18562306a36Sopenharmony_ci
18662306a36Sopenharmony_cistatic const unsigned int ls3_currents[] = { 100000, 200000, 500000, 1000000 };
18762306a36Sopenharmony_ci
18862306a36Sopenharmony_cistatic int tps65218_pmic_set_input_current_lim(struct regulator_dev *dev,
18962306a36Sopenharmony_ci					       int lim_uA)
19062306a36Sopenharmony_ci{
19162306a36Sopenharmony_ci	unsigned int index = 0;
19262306a36Sopenharmony_ci	unsigned int num_currents = ARRAY_SIZE(ls3_currents);
19362306a36Sopenharmony_ci	struct tps65218 *tps = rdev_get_drvdata(dev);
19462306a36Sopenharmony_ci
19562306a36Sopenharmony_ci	while (index < num_currents && ls3_currents[index] != lim_uA)
19662306a36Sopenharmony_ci		index++;
19762306a36Sopenharmony_ci
19862306a36Sopenharmony_ci	if (index == num_currents)
19962306a36Sopenharmony_ci		return -EINVAL;
20062306a36Sopenharmony_ci
20162306a36Sopenharmony_ci	return tps65218_set_bits(tps, dev->desc->csel_reg, dev->desc->csel_mask,
20262306a36Sopenharmony_ci				 index << __builtin_ctz(dev->desc->csel_mask),
20362306a36Sopenharmony_ci				 TPS65218_PROTECT_L1);
20462306a36Sopenharmony_ci}
20562306a36Sopenharmony_ci
20662306a36Sopenharmony_cistatic int tps65218_pmic_set_current_limit(struct regulator_dev *dev,
20762306a36Sopenharmony_ci					   int min_uA, int max_uA)
20862306a36Sopenharmony_ci{
20962306a36Sopenharmony_ci	int index = 0;
21062306a36Sopenharmony_ci	unsigned int num_currents = ARRAY_SIZE(ls3_currents);
21162306a36Sopenharmony_ci	struct tps65218 *tps = rdev_get_drvdata(dev);
21262306a36Sopenharmony_ci
21362306a36Sopenharmony_ci	while (index < num_currents && ls3_currents[index] <= max_uA)
21462306a36Sopenharmony_ci		index++;
21562306a36Sopenharmony_ci
21662306a36Sopenharmony_ci	index--;
21762306a36Sopenharmony_ci
21862306a36Sopenharmony_ci	if (index < 0 || ls3_currents[index] < min_uA)
21962306a36Sopenharmony_ci		return -EINVAL;
22062306a36Sopenharmony_ci
22162306a36Sopenharmony_ci	return tps65218_set_bits(tps, dev->desc->csel_reg, dev->desc->csel_mask,
22262306a36Sopenharmony_ci				 index << __builtin_ctz(dev->desc->csel_mask),
22362306a36Sopenharmony_ci				 TPS65218_PROTECT_L1);
22462306a36Sopenharmony_ci}
22562306a36Sopenharmony_ci
22662306a36Sopenharmony_cistatic const struct regulator_ops tps65218_ls23_ops = {
22762306a36Sopenharmony_ci	.is_enabled		= regulator_is_enabled_regmap,
22862306a36Sopenharmony_ci	.enable			= tps65218_pmic_enable,
22962306a36Sopenharmony_ci	.disable		= tps65218_pmic_disable,
23062306a36Sopenharmony_ci	.set_input_current_limit = tps65218_pmic_set_input_current_lim,
23162306a36Sopenharmony_ci	.set_current_limit	= tps65218_pmic_set_current_limit,
23262306a36Sopenharmony_ci	.get_current_limit	= regulator_get_current_limit_regmap,
23362306a36Sopenharmony_ci};
23462306a36Sopenharmony_ci
23562306a36Sopenharmony_ci/* Operations permitted on DCDC5, DCDC6 */
23662306a36Sopenharmony_cistatic const struct regulator_ops tps65218_dcdc56_pmic_ops = {
23762306a36Sopenharmony_ci	.is_enabled		= regulator_is_enabled_regmap,
23862306a36Sopenharmony_ci	.enable			= tps65218_pmic_enable,
23962306a36Sopenharmony_ci	.disable		= tps65218_pmic_disable,
24062306a36Sopenharmony_ci	.set_suspend_enable	= tps65218_pmic_set_suspend_enable,
24162306a36Sopenharmony_ci	.set_suspend_disable	= tps65218_pmic_set_suspend_disable,
24262306a36Sopenharmony_ci};
24362306a36Sopenharmony_ci
24462306a36Sopenharmony_cistatic const struct regulator_desc regulators[] = {
24562306a36Sopenharmony_ci	TPS65218_REGULATOR("DCDC1", "regulator-dcdc1", TPS65218_DCDC_1,
24662306a36Sopenharmony_ci			   REGULATOR_VOLTAGE, tps65218_dcdc12_ops, 64,
24762306a36Sopenharmony_ci			   TPS65218_REG_CONTROL_DCDC1,
24862306a36Sopenharmony_ci			   TPS65218_CONTROL_DCDC1_MASK, TPS65218_REG_ENABLE1,
24962306a36Sopenharmony_ci			   TPS65218_ENABLE1_DC1_EN, 0, 0, dcdc1_dcdc2_ranges,
25062306a36Sopenharmony_ci			   2, 4000, 0, TPS65218_REG_SEQ3,
25162306a36Sopenharmony_ci			   TPS65218_SEQ3_DC1_SEQ_MASK, NULL, 0),
25262306a36Sopenharmony_ci	TPS65218_REGULATOR("DCDC2", "regulator-dcdc2", TPS65218_DCDC_2,
25362306a36Sopenharmony_ci			   REGULATOR_VOLTAGE, tps65218_dcdc12_ops, 64,
25462306a36Sopenharmony_ci			   TPS65218_REG_CONTROL_DCDC2,
25562306a36Sopenharmony_ci			   TPS65218_CONTROL_DCDC2_MASK, TPS65218_REG_ENABLE1,
25662306a36Sopenharmony_ci			   TPS65218_ENABLE1_DC2_EN, 0, 0, dcdc1_dcdc2_ranges,
25762306a36Sopenharmony_ci			   2, 4000, 0, TPS65218_REG_SEQ3,
25862306a36Sopenharmony_ci			   TPS65218_SEQ3_DC2_SEQ_MASK, NULL, 0),
25962306a36Sopenharmony_ci	TPS65218_REGULATOR("DCDC3", "regulator-dcdc3", TPS65218_DCDC_3,
26062306a36Sopenharmony_ci			   REGULATOR_VOLTAGE, tps65218_ldo1_dcdc34_ops, 64,
26162306a36Sopenharmony_ci			   TPS65218_REG_CONTROL_DCDC3,
26262306a36Sopenharmony_ci			   TPS65218_CONTROL_DCDC3_MASK, TPS65218_REG_ENABLE1,
26362306a36Sopenharmony_ci			   TPS65218_ENABLE1_DC3_EN, 0, 0, ldo1_dcdc3_ranges, 2,
26462306a36Sopenharmony_ci			   0, 0, TPS65218_REG_SEQ4, TPS65218_SEQ4_DC3_SEQ_MASK,
26562306a36Sopenharmony_ci			   NULL, 0),
26662306a36Sopenharmony_ci	TPS65218_REGULATOR("DCDC4", "regulator-dcdc4", TPS65218_DCDC_4,
26762306a36Sopenharmony_ci			   REGULATOR_VOLTAGE, tps65218_ldo1_dcdc34_ops, 53,
26862306a36Sopenharmony_ci			   TPS65218_REG_CONTROL_DCDC4,
26962306a36Sopenharmony_ci			   TPS65218_CONTROL_DCDC4_MASK, TPS65218_REG_ENABLE1,
27062306a36Sopenharmony_ci			   TPS65218_ENABLE1_DC4_EN, 0, 0, dcdc4_ranges, 2,
27162306a36Sopenharmony_ci			   0, 0, TPS65218_REG_SEQ4, TPS65218_SEQ4_DC4_SEQ_MASK,
27262306a36Sopenharmony_ci			   NULL, 0),
27362306a36Sopenharmony_ci	TPS65218_REGULATOR("DCDC5", "regulator-dcdc5", TPS65218_DCDC_5,
27462306a36Sopenharmony_ci			   REGULATOR_VOLTAGE, tps65218_dcdc56_pmic_ops, 1, -1,
27562306a36Sopenharmony_ci			   -1, TPS65218_REG_ENABLE1, TPS65218_ENABLE1_DC5_EN, 0,
27662306a36Sopenharmony_ci			   0, NULL, 0, 0, 1000000, TPS65218_REG_SEQ5,
27762306a36Sopenharmony_ci			   TPS65218_SEQ5_DC5_SEQ_MASK, NULL, 0),
27862306a36Sopenharmony_ci	TPS65218_REGULATOR("DCDC6", "regulator-dcdc6", TPS65218_DCDC_6,
27962306a36Sopenharmony_ci			   REGULATOR_VOLTAGE, tps65218_dcdc56_pmic_ops, 1, -1,
28062306a36Sopenharmony_ci			   -1, TPS65218_REG_ENABLE1, TPS65218_ENABLE1_DC6_EN, 0,
28162306a36Sopenharmony_ci			   0, NULL, 0, 0, 1800000, TPS65218_REG_SEQ5,
28262306a36Sopenharmony_ci			   TPS65218_SEQ5_DC6_SEQ_MASK, NULL, 0),
28362306a36Sopenharmony_ci	TPS65218_REGULATOR("LDO1", "regulator-ldo1", TPS65218_LDO_1,
28462306a36Sopenharmony_ci			   REGULATOR_VOLTAGE, tps65218_ldo1_dcdc34_ops, 64,
28562306a36Sopenharmony_ci			   TPS65218_REG_CONTROL_LDO1,
28662306a36Sopenharmony_ci			   TPS65218_CONTROL_LDO1_MASK, TPS65218_REG_ENABLE2,
28762306a36Sopenharmony_ci			   TPS65218_ENABLE2_LDO1_EN, 0, 0, ldo1_dcdc3_ranges,
28862306a36Sopenharmony_ci			   2, 0, 0, TPS65218_REG_SEQ6,
28962306a36Sopenharmony_ci			   TPS65218_SEQ6_LDO1_SEQ_MASK, NULL, 0),
29062306a36Sopenharmony_ci	TPS65218_REGULATOR("LS2", "regulator-ls2", TPS65218_LS_2,
29162306a36Sopenharmony_ci			   REGULATOR_CURRENT, tps65218_ls23_ops, 0, 0, 0,
29262306a36Sopenharmony_ci			   TPS65218_REG_ENABLE2, TPS65218_ENABLE2_LS2_EN,
29362306a36Sopenharmony_ci			   TPS65218_REG_CONFIG2, TPS65218_CONFIG2_LS2ILIM_MASK,
29462306a36Sopenharmony_ci			   NULL, 0, 0, 0, 0, 0, ls3_currents,
29562306a36Sopenharmony_ci			   ARRAY_SIZE(ls3_currents)),
29662306a36Sopenharmony_ci	TPS65218_REGULATOR("LS3", "regulator-ls3", TPS65218_LS_3,
29762306a36Sopenharmony_ci			   REGULATOR_CURRENT, tps65218_ls23_ops, 0, 0, 0,
29862306a36Sopenharmony_ci			   TPS65218_REG_ENABLE2, TPS65218_ENABLE2_LS3_EN,
29962306a36Sopenharmony_ci			   TPS65218_REG_CONFIG2, TPS65218_CONFIG2_LS3ILIM_MASK,
30062306a36Sopenharmony_ci			   NULL, 0, 0, 0, 0, 0, ls3_currents,
30162306a36Sopenharmony_ci			   ARRAY_SIZE(ls3_currents)),
30262306a36Sopenharmony_ci};
30362306a36Sopenharmony_ci
30462306a36Sopenharmony_cistatic int tps65218_regulator_probe(struct platform_device *pdev)
30562306a36Sopenharmony_ci{
30662306a36Sopenharmony_ci	struct tps65218 *tps = dev_get_drvdata(pdev->dev.parent);
30762306a36Sopenharmony_ci	struct regulator_dev *rdev;
30862306a36Sopenharmony_ci	struct regulator_config config = { };
30962306a36Sopenharmony_ci	int i, ret;
31062306a36Sopenharmony_ci	unsigned int val;
31162306a36Sopenharmony_ci
31262306a36Sopenharmony_ci	config.dev = &pdev->dev;
31362306a36Sopenharmony_ci	config.dev->of_node = tps->dev->of_node;
31462306a36Sopenharmony_ci	config.driver_data = tps;
31562306a36Sopenharmony_ci	config.regmap = tps->regmap;
31662306a36Sopenharmony_ci
31762306a36Sopenharmony_ci	/* Allocate memory for strobes */
31862306a36Sopenharmony_ci	tps->strobes = devm_kcalloc(&pdev->dev,
31962306a36Sopenharmony_ci				    TPS65218_NUM_REGULATOR, sizeof(u8),
32062306a36Sopenharmony_ci				    GFP_KERNEL);
32162306a36Sopenharmony_ci	if (!tps->strobes)
32262306a36Sopenharmony_ci		return -ENOMEM;
32362306a36Sopenharmony_ci
32462306a36Sopenharmony_ci	for (i = 0; i < ARRAY_SIZE(regulators); i++) {
32562306a36Sopenharmony_ci		rdev = devm_regulator_register(&pdev->dev, &regulators[i],
32662306a36Sopenharmony_ci					       &config);
32762306a36Sopenharmony_ci		if (IS_ERR(rdev)) {
32862306a36Sopenharmony_ci			dev_err(tps->dev, "failed to register %s regulator\n",
32962306a36Sopenharmony_ci				pdev->name);
33062306a36Sopenharmony_ci			return PTR_ERR(rdev);
33162306a36Sopenharmony_ci		}
33262306a36Sopenharmony_ci
33362306a36Sopenharmony_ci		ret = regmap_read(tps->regmap, regulators[i].bypass_reg, &val);
33462306a36Sopenharmony_ci		if (ret)
33562306a36Sopenharmony_ci			return ret;
33662306a36Sopenharmony_ci
33762306a36Sopenharmony_ci		tps->strobes[i] = val & regulators[i].bypass_mask;
33862306a36Sopenharmony_ci	}
33962306a36Sopenharmony_ci
34062306a36Sopenharmony_ci	return 0;
34162306a36Sopenharmony_ci}
34262306a36Sopenharmony_ci
34362306a36Sopenharmony_cistatic const struct platform_device_id tps65218_regulator_id_table[] = {
34462306a36Sopenharmony_ci	{ "tps65218-regulator", },
34562306a36Sopenharmony_ci	{ /* sentinel */ }
34662306a36Sopenharmony_ci};
34762306a36Sopenharmony_ciMODULE_DEVICE_TABLE(platform, tps65218_regulator_id_table);
34862306a36Sopenharmony_ci
34962306a36Sopenharmony_cistatic struct platform_driver tps65218_regulator_driver = {
35062306a36Sopenharmony_ci	.driver = {
35162306a36Sopenharmony_ci		.name = "tps65218-pmic",
35262306a36Sopenharmony_ci		.probe_type = PROBE_PREFER_ASYNCHRONOUS,
35362306a36Sopenharmony_ci	},
35462306a36Sopenharmony_ci	.probe = tps65218_regulator_probe,
35562306a36Sopenharmony_ci	.id_table = tps65218_regulator_id_table,
35662306a36Sopenharmony_ci};
35762306a36Sopenharmony_ci
35862306a36Sopenharmony_cimodule_platform_driver(tps65218_regulator_driver);
35962306a36Sopenharmony_ci
36062306a36Sopenharmony_ciMODULE_AUTHOR("J Keerthy <j-keerthy@ti.com>");
36162306a36Sopenharmony_ciMODULE_DESCRIPTION("TPS65218 voltage regulator driver");
36262306a36Sopenharmony_ciMODULE_ALIAS("platform:tps65218-pmic");
36362306a36Sopenharmony_ciMODULE_LICENSE("GPL v2");
364