162306a36Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-only
262306a36Sopenharmony_ci/*
362306a36Sopenharmony_ci * Regulators driver for Marvell 88PM8607
462306a36Sopenharmony_ci *
562306a36Sopenharmony_ci * Copyright (C) 2009 Marvell International Ltd.
662306a36Sopenharmony_ci *	Haojian Zhuang <haojian.zhuang@marvell.com>
762306a36Sopenharmony_ci */
862306a36Sopenharmony_ci#include <linux/kernel.h>
962306a36Sopenharmony_ci#include <linux/init.h>
1062306a36Sopenharmony_ci#include <linux/err.h>
1162306a36Sopenharmony_ci#include <linux/of.h>
1262306a36Sopenharmony_ci#include <linux/regulator/of_regulator.h>
1362306a36Sopenharmony_ci#include <linux/platform_device.h>
1462306a36Sopenharmony_ci#include <linux/regulator/driver.h>
1562306a36Sopenharmony_ci#include <linux/regulator/machine.h>
1662306a36Sopenharmony_ci#include <linux/mfd/88pm860x.h>
1762306a36Sopenharmony_ci#include <linux/module.h>
1862306a36Sopenharmony_ci
1962306a36Sopenharmony_cistruct pm8607_regulator_info {
2062306a36Sopenharmony_ci	struct regulator_desc	desc;
2162306a36Sopenharmony_ci
2262306a36Sopenharmony_ci	unsigned int	*vol_suspend;
2362306a36Sopenharmony_ci
2462306a36Sopenharmony_ci	int	slope_double;
2562306a36Sopenharmony_ci};
2662306a36Sopenharmony_ci
2762306a36Sopenharmony_cistatic const unsigned int BUCK1_table[] = {
2862306a36Sopenharmony_ci	 725000,  750000,  775000,  800000,  825000,  850000,  875000,  900000,
2962306a36Sopenharmony_ci	 925000,  950000,  975000, 1000000, 1025000, 1050000, 1075000, 1100000,
3062306a36Sopenharmony_ci	1125000, 1150000, 1175000, 1200000, 1225000, 1250000, 1275000, 1300000,
3162306a36Sopenharmony_ci	1325000, 1350000, 1375000, 1400000, 1425000, 1450000, 1475000, 1500000,
3262306a36Sopenharmony_ci	      0,   25000,   50000,   75000,  100000,  125000,  150000,  175000,
3362306a36Sopenharmony_ci	 200000,  225000,  250000,  275000,  300000,  325000,  350000,  375000,
3462306a36Sopenharmony_ci	 400000,  425000,  450000,  475000,  500000,  525000,  550000,  575000,
3562306a36Sopenharmony_ci	 600000,  625000,  650000,  675000,  700000,  725000,  750000,  775000,
3662306a36Sopenharmony_ci};
3762306a36Sopenharmony_ci
3862306a36Sopenharmony_cistatic const unsigned int BUCK1_suspend_table[] = {
3962306a36Sopenharmony_ci	      0,   25000,   50000,   75000,  100000,  125000,  150000,  175000,
4062306a36Sopenharmony_ci	 200000,  225000,  250000,  275000,  300000,  325000,  350000,  375000,
4162306a36Sopenharmony_ci	 400000,  425000,  450000,  475000,  500000,  525000,  550000,  575000,
4262306a36Sopenharmony_ci	 600000,  625000,  650000,  675000,  700000,  725000,  750000,  775000,
4362306a36Sopenharmony_ci	 800000,  825000,  850000,  875000,  900000,  925000,  950000,  975000,
4462306a36Sopenharmony_ci	1000000, 1025000, 1050000, 1075000, 1100000, 1125000, 1150000, 1175000,
4562306a36Sopenharmony_ci	1200000, 1225000, 1250000, 1275000, 1300000, 1325000, 1350000, 1375000,
4662306a36Sopenharmony_ci	1400000, 1425000, 1450000, 1475000, 1500000, 1500000, 1500000, 1500000,
4762306a36Sopenharmony_ci};
4862306a36Sopenharmony_ci
4962306a36Sopenharmony_cistatic const unsigned int BUCK2_table[] = {
5062306a36Sopenharmony_ci	      0,   50000,  100000,  150000,  200000,  250000,  300000,  350000,
5162306a36Sopenharmony_ci	 400000,  450000,  500000,  550000,  600000,  650000,  700000,  750000,
5262306a36Sopenharmony_ci	 800000,  850000,  900000,  950000, 1000000, 1050000, 1100000, 1150000,
5362306a36Sopenharmony_ci	1200000, 1250000, 1300000, 1350000, 1400000, 1450000, 1500000, 1550000,
5462306a36Sopenharmony_ci	1600000, 1650000, 1700000, 1750000, 1800000, 1850000, 1900000, 1950000,
5562306a36Sopenharmony_ci	2000000, 2050000, 2100000, 2150000, 2200000, 2250000, 2300000, 2350000,
5662306a36Sopenharmony_ci	2400000, 2450000, 2500000, 2550000, 2600000, 2650000, 2700000, 2750000,
5762306a36Sopenharmony_ci	2800000, 2850000, 2900000, 2950000, 3000000, 3000000, 3000000, 3000000,
5862306a36Sopenharmony_ci};
5962306a36Sopenharmony_ci
6062306a36Sopenharmony_cistatic const unsigned int BUCK2_suspend_table[] = {
6162306a36Sopenharmony_ci	      0,   50000,  100000,  150000,  200000,  250000,  300000,  350000,
6262306a36Sopenharmony_ci	 400000,  450000,  500000,  550000,  600000,  650000,  700000,  750000,
6362306a36Sopenharmony_ci	 800000,  850000,  900000,  950000, 1000000, 1050000, 1100000, 1150000,
6462306a36Sopenharmony_ci	1200000, 1250000, 1300000, 1350000, 1400000, 1450000, 1500000, 1550000,
6562306a36Sopenharmony_ci	1600000, 1650000, 1700000, 1750000, 1800000, 1850000, 1900000, 1950000,
6662306a36Sopenharmony_ci	2000000, 2050000, 2100000, 2150000, 2200000, 2250000, 2300000, 2350000,
6762306a36Sopenharmony_ci	2400000, 2450000, 2500000, 2550000, 2600000, 2650000, 2700000, 2750000,
6862306a36Sopenharmony_ci	2800000, 2850000, 2900000, 2950000, 3000000, 3000000, 3000000, 3000000,
6962306a36Sopenharmony_ci};
7062306a36Sopenharmony_ci
7162306a36Sopenharmony_cistatic const unsigned int BUCK3_table[] = {
7262306a36Sopenharmony_ci	      0,   25000,   50000,   75000,  100000,  125000,  150000,  175000,
7362306a36Sopenharmony_ci	 200000,  225000,  250000,  275000,  300000,  325000,  350000,  375000,
7462306a36Sopenharmony_ci	 400000,  425000,  450000,  475000,  500000,  525000,  550000,  575000,
7562306a36Sopenharmony_ci	 600000,  625000,  650000,  675000,  700000,  725000,  750000,  775000,
7662306a36Sopenharmony_ci	 800000,  825000,  850000,  875000,  900000,  925000,  950000,  975000,
7762306a36Sopenharmony_ci	1000000, 1025000, 1050000, 1075000, 1100000, 1125000, 1150000, 1175000,
7862306a36Sopenharmony_ci	1200000, 1225000, 1250000, 1275000, 1300000, 1325000, 1350000, 1375000,
7962306a36Sopenharmony_ci	1400000, 1425000, 1450000, 1475000, 1500000, 1500000, 1500000, 1500000,
8062306a36Sopenharmony_ci};
8162306a36Sopenharmony_ci
8262306a36Sopenharmony_cistatic const unsigned int BUCK3_suspend_table[] = {
8362306a36Sopenharmony_ci	      0,   25000,   50000,   75000,  100000,  125000,  150000,  175000,
8462306a36Sopenharmony_ci	 200000,  225000,  250000,  275000,  300000,  325000,  350000,  375000,
8562306a36Sopenharmony_ci	 400000,  425000,  450000,  475000,  500000,  525000,  550000,  575000,
8662306a36Sopenharmony_ci	 600000,  625000,  650000,  675000,  700000,  725000,  750000,  775000,
8762306a36Sopenharmony_ci	 800000,  825000,  850000,  875000,  900000,  925000,  950000,  975000,
8862306a36Sopenharmony_ci	1000000, 1025000, 1050000, 1075000, 1100000, 1125000, 1150000, 1175000,
8962306a36Sopenharmony_ci	1200000, 1225000, 1250000, 1275000, 1300000, 1325000, 1350000, 1375000,
9062306a36Sopenharmony_ci	1400000, 1425000, 1450000, 1475000, 1500000, 1500000, 1500000, 1500000,
9162306a36Sopenharmony_ci};
9262306a36Sopenharmony_ci
9362306a36Sopenharmony_cistatic const unsigned int LDO1_table[] = {
9462306a36Sopenharmony_ci	1800000, 1200000, 2800000, 0,
9562306a36Sopenharmony_ci};
9662306a36Sopenharmony_ci
9762306a36Sopenharmony_cistatic const unsigned int LDO1_suspend_table[] = {
9862306a36Sopenharmony_ci	1800000, 1200000, 0, 0,
9962306a36Sopenharmony_ci};
10062306a36Sopenharmony_ci
10162306a36Sopenharmony_cistatic const unsigned int LDO2_table[] = {
10262306a36Sopenharmony_ci	1800000, 1850000, 1900000, 2700000, 2750000, 2800000, 2850000, 3300000,
10362306a36Sopenharmony_ci};
10462306a36Sopenharmony_ci
10562306a36Sopenharmony_cistatic const unsigned int LDO2_suspend_table[] = {
10662306a36Sopenharmony_ci	1800000, 1850000, 1900000, 2700000, 2750000, 2800000, 2850000, 2900000,
10762306a36Sopenharmony_ci};
10862306a36Sopenharmony_ci
10962306a36Sopenharmony_cistatic const unsigned int LDO3_table[] = {
11062306a36Sopenharmony_ci	1800000, 1850000, 1900000, 2700000, 2750000, 2800000, 2850000, 3300000,
11162306a36Sopenharmony_ci};
11262306a36Sopenharmony_ci
11362306a36Sopenharmony_cistatic const unsigned int LDO3_suspend_table[] = {
11462306a36Sopenharmony_ci	1800000, 1850000, 1900000, 2700000, 2750000, 2800000, 2850000, 2900000,
11562306a36Sopenharmony_ci};
11662306a36Sopenharmony_ci
11762306a36Sopenharmony_cistatic const unsigned int LDO4_table[] = {
11862306a36Sopenharmony_ci	1800000, 1850000, 1900000, 2700000, 2750000, 2800000, 2900000, 3300000,
11962306a36Sopenharmony_ci};
12062306a36Sopenharmony_ci
12162306a36Sopenharmony_cistatic const unsigned int LDO4_suspend_table[] = {
12262306a36Sopenharmony_ci	1800000, 1850000, 1900000, 2700000, 2750000, 2800000, 2900000, 2900000,
12362306a36Sopenharmony_ci};
12462306a36Sopenharmony_ci
12562306a36Sopenharmony_cistatic const unsigned int LDO5_table[] = {
12662306a36Sopenharmony_ci	2900000, 3000000, 3100000, 3300000,
12762306a36Sopenharmony_ci};
12862306a36Sopenharmony_ci
12962306a36Sopenharmony_cistatic const unsigned int LDO5_suspend_table[] = {
13062306a36Sopenharmony_ci	2900000, 0, 0, 0,
13162306a36Sopenharmony_ci};
13262306a36Sopenharmony_ci
13362306a36Sopenharmony_cistatic const unsigned int LDO6_table[] = {
13462306a36Sopenharmony_ci	1800000, 1850000, 2600000, 2650000, 2700000, 2750000, 2800000, 3300000,
13562306a36Sopenharmony_ci};
13662306a36Sopenharmony_ci
13762306a36Sopenharmony_cistatic const unsigned int LDO6_suspend_table[] = {
13862306a36Sopenharmony_ci	1800000, 1850000, 2600000, 2650000, 2700000, 2750000, 2800000, 2900000,
13962306a36Sopenharmony_ci};
14062306a36Sopenharmony_ci
14162306a36Sopenharmony_cistatic const unsigned int LDO7_table[] = {
14262306a36Sopenharmony_ci	1800000, 1850000, 1900000, 2700000, 2750000, 2800000, 2850000, 2900000,
14362306a36Sopenharmony_ci};
14462306a36Sopenharmony_ci
14562306a36Sopenharmony_cistatic const unsigned int LDO7_suspend_table[] = {
14662306a36Sopenharmony_ci	1800000, 1850000, 1900000, 2700000, 2750000, 2800000, 2850000, 2900000,
14762306a36Sopenharmony_ci};
14862306a36Sopenharmony_ci
14962306a36Sopenharmony_cistatic const unsigned int LDO8_table[] = {
15062306a36Sopenharmony_ci	1800000, 1850000, 1900000, 2700000, 2750000, 2800000, 2850000, 2900000,
15162306a36Sopenharmony_ci};
15262306a36Sopenharmony_ci
15362306a36Sopenharmony_cistatic const unsigned int LDO8_suspend_table[] = {
15462306a36Sopenharmony_ci	1800000, 1850000, 1900000, 2700000, 2750000, 2800000, 2850000, 2900000,
15562306a36Sopenharmony_ci};
15662306a36Sopenharmony_ci
15762306a36Sopenharmony_cistatic const unsigned int LDO9_table[] = {
15862306a36Sopenharmony_ci	1800000, 1850000, 1900000, 2700000, 2750000, 2800000, 2850000, 3300000,
15962306a36Sopenharmony_ci};
16062306a36Sopenharmony_ci
16162306a36Sopenharmony_cistatic const unsigned int LDO9_suspend_table[] = {
16262306a36Sopenharmony_ci	1800000, 1850000, 1900000, 2700000, 2750000, 2800000, 2850000, 2900000,
16362306a36Sopenharmony_ci};
16462306a36Sopenharmony_ci
16562306a36Sopenharmony_cistatic const unsigned int LDO10_table[] = {
16662306a36Sopenharmony_ci	1800000, 1850000, 1900000, 2700000, 2750000, 2800000, 2850000, 3300000,
16762306a36Sopenharmony_ci	1200000, 1200000, 1200000, 1200000, 1200000, 1200000, 1200000, 1200000,
16862306a36Sopenharmony_ci};
16962306a36Sopenharmony_ci
17062306a36Sopenharmony_cistatic const unsigned int LDO10_suspend_table[] = {
17162306a36Sopenharmony_ci	1800000, 1850000, 1900000, 2700000, 2750000, 2800000, 2850000, 2900000,
17262306a36Sopenharmony_ci	1200000, 1200000, 1200000, 1200000, 1200000, 1200000, 1200000, 1200000,
17362306a36Sopenharmony_ci};
17462306a36Sopenharmony_ci
17562306a36Sopenharmony_cistatic const unsigned int LDO12_table[] = {
17662306a36Sopenharmony_ci	1800000, 1900000, 2700000, 2800000, 2900000, 3000000, 3100000, 3300000,
17762306a36Sopenharmony_ci	1200000, 1200000, 1200000, 1200000, 1200000, 1200000, 1200000, 1200000,
17862306a36Sopenharmony_ci};
17962306a36Sopenharmony_ci
18062306a36Sopenharmony_cistatic const unsigned int LDO12_suspend_table[] = {
18162306a36Sopenharmony_ci	1800000, 1900000, 2700000, 2800000, 2900000, 2900000, 2900000, 2900000,
18262306a36Sopenharmony_ci	1200000, 1200000, 1200000, 1200000, 1200000, 1200000, 1200000, 1200000,
18362306a36Sopenharmony_ci};
18462306a36Sopenharmony_ci
18562306a36Sopenharmony_cistatic const unsigned int LDO13_table[] = {
18662306a36Sopenharmony_ci	1200000, 1300000, 1800000, 2000000, 2500000, 2800000, 3000000, 0,
18762306a36Sopenharmony_ci};
18862306a36Sopenharmony_ci
18962306a36Sopenharmony_cistatic const unsigned int LDO13_suspend_table[] = {
19062306a36Sopenharmony_ci	0,
19162306a36Sopenharmony_ci};
19262306a36Sopenharmony_ci
19362306a36Sopenharmony_cistatic const unsigned int LDO14_table[] = {
19462306a36Sopenharmony_ci	1800000, 1850000, 2700000, 2750000, 2800000, 2850000, 2900000, 3300000,
19562306a36Sopenharmony_ci};
19662306a36Sopenharmony_ci
19762306a36Sopenharmony_cistatic const unsigned int LDO14_suspend_table[] = {
19862306a36Sopenharmony_ci	1800000, 1850000, 2700000, 2750000, 2800000, 2850000, 2900000, 2900000,
19962306a36Sopenharmony_ci};
20062306a36Sopenharmony_ci
20162306a36Sopenharmony_cistatic int pm8607_list_voltage(struct regulator_dev *rdev, unsigned index)
20262306a36Sopenharmony_ci{
20362306a36Sopenharmony_ci	struct pm8607_regulator_info *info = rdev_get_drvdata(rdev);
20462306a36Sopenharmony_ci	int ret;
20562306a36Sopenharmony_ci
20662306a36Sopenharmony_ci	ret = regulator_list_voltage_table(rdev, index);
20762306a36Sopenharmony_ci	if (ret < 0)
20862306a36Sopenharmony_ci		return ret;
20962306a36Sopenharmony_ci
21062306a36Sopenharmony_ci	if (info->slope_double)
21162306a36Sopenharmony_ci		ret <<= 1;
21262306a36Sopenharmony_ci
21362306a36Sopenharmony_ci	return ret;
21462306a36Sopenharmony_ci}
21562306a36Sopenharmony_ci
21662306a36Sopenharmony_cistatic const struct regulator_ops pm8607_regulator_ops = {
21762306a36Sopenharmony_ci	.list_voltage	= pm8607_list_voltage,
21862306a36Sopenharmony_ci	.set_voltage_sel = regulator_set_voltage_sel_regmap,
21962306a36Sopenharmony_ci	.get_voltage_sel = regulator_get_voltage_sel_regmap,
22062306a36Sopenharmony_ci	.enable = regulator_enable_regmap,
22162306a36Sopenharmony_ci	.disable = regulator_disable_regmap,
22262306a36Sopenharmony_ci	.is_enabled = regulator_is_enabled_regmap,
22362306a36Sopenharmony_ci};
22462306a36Sopenharmony_ci
22562306a36Sopenharmony_cistatic const struct regulator_ops pm8606_preg_ops = {
22662306a36Sopenharmony_ci	.enable		= regulator_enable_regmap,
22762306a36Sopenharmony_ci	.disable	= regulator_disable_regmap,
22862306a36Sopenharmony_ci	.is_enabled	= regulator_is_enabled_regmap,
22962306a36Sopenharmony_ci};
23062306a36Sopenharmony_ci
23162306a36Sopenharmony_ci#define PM8606_PREG(ereg, ebit)						\
23262306a36Sopenharmony_ci{									\
23362306a36Sopenharmony_ci	.desc	= {							\
23462306a36Sopenharmony_ci		.name	= "PREG",					\
23562306a36Sopenharmony_ci		.of_match = of_match_ptr("PREG"),			\
23662306a36Sopenharmony_ci		.regulators_node = of_match_ptr("regulators"),		\
23762306a36Sopenharmony_ci		.ops	= &pm8606_preg_ops,				\
23862306a36Sopenharmony_ci		.type	= REGULATOR_CURRENT,				\
23962306a36Sopenharmony_ci		.id	= PM8606_ID_PREG,				\
24062306a36Sopenharmony_ci		.owner	= THIS_MODULE,					\
24162306a36Sopenharmony_ci		.enable_reg = PM8606_##ereg,				\
24262306a36Sopenharmony_ci		.enable_mask = (ebit),					\
24362306a36Sopenharmony_ci		.enable_is_inverted = true,				\
24462306a36Sopenharmony_ci	},								\
24562306a36Sopenharmony_ci}
24662306a36Sopenharmony_ci
24762306a36Sopenharmony_ci#define PM8607_DVC(vreg, ureg, ubit, ereg, ebit)			\
24862306a36Sopenharmony_ci{									\
24962306a36Sopenharmony_ci	.desc	= {							\
25062306a36Sopenharmony_ci		.name	= #vreg,					\
25162306a36Sopenharmony_ci		.of_match = of_match_ptr(#vreg),			\
25262306a36Sopenharmony_ci		.regulators_node = of_match_ptr("regulators"),		\
25362306a36Sopenharmony_ci		.ops	= &pm8607_regulator_ops,			\
25462306a36Sopenharmony_ci		.type	= REGULATOR_VOLTAGE,				\
25562306a36Sopenharmony_ci		.id	= PM8607_ID_##vreg,				\
25662306a36Sopenharmony_ci		.owner	= THIS_MODULE,					\
25762306a36Sopenharmony_ci		.volt_table = vreg##_table,				\
25862306a36Sopenharmony_ci		.n_voltages = ARRAY_SIZE(vreg##_table),			\
25962306a36Sopenharmony_ci		.vsel_reg = PM8607_##vreg,				\
26062306a36Sopenharmony_ci		.vsel_mask = ARRAY_SIZE(vreg##_table) - 1,		\
26162306a36Sopenharmony_ci		.apply_reg = PM8607_##ureg,				\
26262306a36Sopenharmony_ci		.apply_bit = (ubit),					\
26362306a36Sopenharmony_ci		.enable_reg = PM8607_##ereg,				\
26462306a36Sopenharmony_ci		.enable_mask = 1 << (ebit),				\
26562306a36Sopenharmony_ci	},								\
26662306a36Sopenharmony_ci	.slope_double	= (0),						\
26762306a36Sopenharmony_ci	.vol_suspend	= (unsigned int *)&vreg##_suspend_table,	\
26862306a36Sopenharmony_ci}
26962306a36Sopenharmony_ci
27062306a36Sopenharmony_ci#define PM8607_LDO(_id, vreg, shift, ereg, ebit)			\
27162306a36Sopenharmony_ci{									\
27262306a36Sopenharmony_ci	.desc	= {							\
27362306a36Sopenharmony_ci		.name	= "LDO" #_id,					\
27462306a36Sopenharmony_ci		.of_match = of_match_ptr("LDO" #_id),			\
27562306a36Sopenharmony_ci		.regulators_node = of_match_ptr("regulators"),		\
27662306a36Sopenharmony_ci		.ops	= &pm8607_regulator_ops,			\
27762306a36Sopenharmony_ci		.type	= REGULATOR_VOLTAGE,				\
27862306a36Sopenharmony_ci		.id	= PM8607_ID_LDO##_id,				\
27962306a36Sopenharmony_ci		.owner	= THIS_MODULE,					\
28062306a36Sopenharmony_ci		.volt_table = LDO##_id##_table,				\
28162306a36Sopenharmony_ci		.n_voltages = ARRAY_SIZE(LDO##_id##_table),		\
28262306a36Sopenharmony_ci		.vsel_reg = PM8607_##vreg,				\
28362306a36Sopenharmony_ci		.vsel_mask = (ARRAY_SIZE(LDO##_id##_table) - 1) << (shift), \
28462306a36Sopenharmony_ci		.enable_reg = PM8607_##ereg,				\
28562306a36Sopenharmony_ci		.enable_mask = 1 << (ebit),				\
28662306a36Sopenharmony_ci	},								\
28762306a36Sopenharmony_ci	.slope_double	= (0),						\
28862306a36Sopenharmony_ci	.vol_suspend	= (unsigned int *)&LDO##_id##_suspend_table,	\
28962306a36Sopenharmony_ci}
29062306a36Sopenharmony_ci
29162306a36Sopenharmony_cistatic struct pm8607_regulator_info pm8607_regulator_info[] = {
29262306a36Sopenharmony_ci	PM8607_DVC(BUCK1, GO, BIT(0), SUPPLIES_EN11, 0),
29362306a36Sopenharmony_ci	PM8607_DVC(BUCK2, GO, BIT(1), SUPPLIES_EN11, 1),
29462306a36Sopenharmony_ci	PM8607_DVC(BUCK3, GO, BIT(2), SUPPLIES_EN11, 2),
29562306a36Sopenharmony_ci
29662306a36Sopenharmony_ci	PM8607_LDO(1,         LDO1, 0, SUPPLIES_EN11, 3),
29762306a36Sopenharmony_ci	PM8607_LDO(2,         LDO2, 0, SUPPLIES_EN11, 4),
29862306a36Sopenharmony_ci	PM8607_LDO(3,         LDO3, 0, SUPPLIES_EN11, 5),
29962306a36Sopenharmony_ci	PM8607_LDO(4,         LDO4, 0, SUPPLIES_EN11, 6),
30062306a36Sopenharmony_ci	PM8607_LDO(5,         LDO5, 0, SUPPLIES_EN11, 7),
30162306a36Sopenharmony_ci	PM8607_LDO(6,         LDO6, 0, SUPPLIES_EN12, 0),
30262306a36Sopenharmony_ci	PM8607_LDO(7,         LDO7, 0, SUPPLIES_EN12, 1),
30362306a36Sopenharmony_ci	PM8607_LDO(8,         LDO8, 0, SUPPLIES_EN12, 2),
30462306a36Sopenharmony_ci	PM8607_LDO(9,         LDO9, 0, SUPPLIES_EN12, 3),
30562306a36Sopenharmony_ci	PM8607_LDO(10,        LDO10, 0, SUPPLIES_EN12, 4),
30662306a36Sopenharmony_ci	PM8607_LDO(12,        LDO12, 0, SUPPLIES_EN12, 5),
30762306a36Sopenharmony_ci	PM8607_LDO(13, VIBRATOR_SET, 1, VIBRATOR_SET, 0),
30862306a36Sopenharmony_ci	PM8607_LDO(14,        LDO14, 0, SUPPLIES_EN12, 6),
30962306a36Sopenharmony_ci};
31062306a36Sopenharmony_ci
31162306a36Sopenharmony_cistatic struct pm8607_regulator_info pm8606_regulator_info[] = {
31262306a36Sopenharmony_ci	PM8606_PREG(PREREGULATORB, 5),
31362306a36Sopenharmony_ci};
31462306a36Sopenharmony_ci
31562306a36Sopenharmony_cistatic int pm8607_regulator_probe(struct platform_device *pdev)
31662306a36Sopenharmony_ci{
31762306a36Sopenharmony_ci	struct pm860x_chip *chip = dev_get_drvdata(pdev->dev.parent);
31862306a36Sopenharmony_ci	struct pm8607_regulator_info *info = NULL;
31962306a36Sopenharmony_ci	struct regulator_init_data *pdata = dev_get_platdata(&pdev->dev);
32062306a36Sopenharmony_ci	struct regulator_config config = { };
32162306a36Sopenharmony_ci	struct regulator_dev *rdev;
32262306a36Sopenharmony_ci	struct resource *res;
32362306a36Sopenharmony_ci	int i;
32462306a36Sopenharmony_ci
32562306a36Sopenharmony_ci	res = platform_get_resource(pdev, IORESOURCE_REG, 0);
32662306a36Sopenharmony_ci	if (res) {
32762306a36Sopenharmony_ci		/* There're resources in 88PM8607 regulator driver */
32862306a36Sopenharmony_ci		for (i = 0; i < ARRAY_SIZE(pm8607_regulator_info); i++) {
32962306a36Sopenharmony_ci			info = &pm8607_regulator_info[i];
33062306a36Sopenharmony_ci			if (info->desc.vsel_reg == res->start)
33162306a36Sopenharmony_ci				break;
33262306a36Sopenharmony_ci		}
33362306a36Sopenharmony_ci		if (i == ARRAY_SIZE(pm8607_regulator_info)) {
33462306a36Sopenharmony_ci			dev_err(&pdev->dev, "Failed to find regulator %llu\n",
33562306a36Sopenharmony_ci				(unsigned long long)res->start);
33662306a36Sopenharmony_ci			return -EINVAL;
33762306a36Sopenharmony_ci		}
33862306a36Sopenharmony_ci	} else {
33962306a36Sopenharmony_ci		/* There's no resource in 88PM8606 PREG regulator driver */
34062306a36Sopenharmony_ci		info = &pm8606_regulator_info[0];
34162306a36Sopenharmony_ci		/* i is used to check regulator ID */
34262306a36Sopenharmony_ci		i = -1;
34362306a36Sopenharmony_ci	}
34462306a36Sopenharmony_ci
34562306a36Sopenharmony_ci	/* check DVC ramp slope double */
34662306a36Sopenharmony_ci	if ((i == PM8607_ID_BUCK3) && chip->buck3_double)
34762306a36Sopenharmony_ci		info->slope_double = 1;
34862306a36Sopenharmony_ci
34962306a36Sopenharmony_ci	config.dev = chip->dev;
35062306a36Sopenharmony_ci	config.driver_data = info;
35162306a36Sopenharmony_ci
35262306a36Sopenharmony_ci	if (pdata)
35362306a36Sopenharmony_ci		config.init_data = pdata;
35462306a36Sopenharmony_ci
35562306a36Sopenharmony_ci	if (chip->id == CHIP_PM8607)
35662306a36Sopenharmony_ci		config.regmap = chip->regmap;
35762306a36Sopenharmony_ci	else
35862306a36Sopenharmony_ci		config.regmap = chip->regmap_companion;
35962306a36Sopenharmony_ci
36062306a36Sopenharmony_ci	rdev = devm_regulator_register(&pdev->dev, &info->desc, &config);
36162306a36Sopenharmony_ci	if (IS_ERR(rdev)) {
36262306a36Sopenharmony_ci		dev_err(&pdev->dev, "failed to register regulator %s\n",
36362306a36Sopenharmony_ci			info->desc.name);
36462306a36Sopenharmony_ci		return PTR_ERR(rdev);
36562306a36Sopenharmony_ci	}
36662306a36Sopenharmony_ci
36762306a36Sopenharmony_ci	platform_set_drvdata(pdev, info);
36862306a36Sopenharmony_ci	return 0;
36962306a36Sopenharmony_ci}
37062306a36Sopenharmony_ci
37162306a36Sopenharmony_cistatic const struct platform_device_id pm8607_regulator_driver_ids[] = {
37262306a36Sopenharmony_ci	{
37362306a36Sopenharmony_ci		.name	= "88pm860x-regulator",
37462306a36Sopenharmony_ci		.driver_data	= 0,
37562306a36Sopenharmony_ci	}, {
37662306a36Sopenharmony_ci		.name	= "88pm860x-preg",
37762306a36Sopenharmony_ci		.driver_data	= 0,
37862306a36Sopenharmony_ci	},
37962306a36Sopenharmony_ci	{ },
38062306a36Sopenharmony_ci};
38162306a36Sopenharmony_ciMODULE_DEVICE_TABLE(platform, pm8607_regulator_driver_ids);
38262306a36Sopenharmony_ci
38362306a36Sopenharmony_cistatic struct platform_driver pm8607_regulator_driver = {
38462306a36Sopenharmony_ci	.driver		= {
38562306a36Sopenharmony_ci		.name	= "88pm860x-regulator",
38662306a36Sopenharmony_ci		.probe_type = PROBE_PREFER_ASYNCHRONOUS,
38762306a36Sopenharmony_ci	},
38862306a36Sopenharmony_ci	.probe		= pm8607_regulator_probe,
38962306a36Sopenharmony_ci	.id_table	= pm8607_regulator_driver_ids,
39062306a36Sopenharmony_ci};
39162306a36Sopenharmony_ci
39262306a36Sopenharmony_cistatic int __init pm8607_regulator_init(void)
39362306a36Sopenharmony_ci{
39462306a36Sopenharmony_ci	return platform_driver_register(&pm8607_regulator_driver);
39562306a36Sopenharmony_ci}
39662306a36Sopenharmony_cisubsys_initcall(pm8607_regulator_init);
39762306a36Sopenharmony_ci
39862306a36Sopenharmony_cistatic void __exit pm8607_regulator_exit(void)
39962306a36Sopenharmony_ci{
40062306a36Sopenharmony_ci	platform_driver_unregister(&pm8607_regulator_driver);
40162306a36Sopenharmony_ci}
40262306a36Sopenharmony_cimodule_exit(pm8607_regulator_exit);
40362306a36Sopenharmony_ci
40462306a36Sopenharmony_ciMODULE_LICENSE("GPL");
40562306a36Sopenharmony_ciMODULE_AUTHOR("Haojian Zhuang <haojian.zhuang@marvell.com>");
40662306a36Sopenharmony_ciMODULE_DESCRIPTION("Regulator Driver for Marvell 88PM8607 PMIC");
40762306a36Sopenharmony_ciMODULE_ALIAS("platform:88pm8607-regulator");
408