xref: /linux/drivers/regulator/qcom_spmi-regulator.c (revision 3a39d672e7f48b8d6b91a09afa4b55352773b4b5)
197fb5e8dSThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only
2e92a4047SStephen Boyd /*
3e92a4047SStephen Boyd  * Copyright (c) 2012-2015, The Linux Foundation. All rights reserved.
4e92a4047SStephen Boyd  */
5e92a4047SStephen Boyd 
6e92a4047SStephen Boyd #include <linux/module.h>
7e92a4047SStephen Boyd #include <linux/delay.h>
8b6688015SMatti Vaittinen #include <linux/devm-helpers.h>
9e92a4047SStephen Boyd #include <linux/err.h>
10e92a4047SStephen Boyd #include <linux/kernel.h>
11e92a4047SStephen Boyd #include <linux/interrupt.h>
12e92a4047SStephen Boyd #include <linux/bitops.h>
13e92a4047SStephen Boyd #include <linux/slab.h>
14e92a4047SStephen Boyd #include <linux/of.h>
15e92a4047SStephen Boyd #include <linux/of_device.h>
16e92a4047SStephen Boyd #include <linux/platform_device.h>
17e92a4047SStephen Boyd #include <linux/ktime.h>
18e92a4047SStephen Boyd #include <linux/regulator/driver.h>
19e92a4047SStephen Boyd #include <linux/regmap.h>
20e92a4047SStephen Boyd #include <linux/list.h>
210caecaa8SIlia Lin #include <linux/mfd/syscon.h>
220caecaa8SIlia Lin #include <linux/io.h>
23e92a4047SStephen Boyd 
24e2adfacdSStephen Boyd /* Pin control enable input pins. */
25e2adfacdSStephen Boyd #define SPMI_REGULATOR_PIN_CTRL_ENABLE_NONE		0x00
26e2adfacdSStephen Boyd #define SPMI_REGULATOR_PIN_CTRL_ENABLE_EN0		0x01
27e2adfacdSStephen Boyd #define SPMI_REGULATOR_PIN_CTRL_ENABLE_EN1		0x02
28e2adfacdSStephen Boyd #define SPMI_REGULATOR_PIN_CTRL_ENABLE_EN2		0x04
29e2adfacdSStephen Boyd #define SPMI_REGULATOR_PIN_CTRL_ENABLE_EN3		0x08
30e2adfacdSStephen Boyd #define SPMI_REGULATOR_PIN_CTRL_ENABLE_HW_DEFAULT	0x10
31e2adfacdSStephen Boyd 
32e2adfacdSStephen Boyd /* Pin control high power mode input pins. */
33e2adfacdSStephen Boyd #define SPMI_REGULATOR_PIN_CTRL_HPM_NONE		0x00
34e2adfacdSStephen Boyd #define SPMI_REGULATOR_PIN_CTRL_HPM_EN0			0x01
35e2adfacdSStephen Boyd #define SPMI_REGULATOR_PIN_CTRL_HPM_EN1			0x02
36e2adfacdSStephen Boyd #define SPMI_REGULATOR_PIN_CTRL_HPM_EN2			0x04
37e2adfacdSStephen Boyd #define SPMI_REGULATOR_PIN_CTRL_HPM_EN3			0x08
38e2adfacdSStephen Boyd #define SPMI_REGULATOR_PIN_CTRL_HPM_SLEEP_B		0x10
39e2adfacdSStephen Boyd #define SPMI_REGULATOR_PIN_CTRL_HPM_HW_DEFAULT		0x20
40e2adfacdSStephen Boyd 
41e2adfacdSStephen Boyd /*
42e2adfacdSStephen Boyd  * Used with enable parameters to specify that hardware default register values
43e2adfacdSStephen Boyd  * should be left unaltered.
44e2adfacdSStephen Boyd  */
45e2adfacdSStephen Boyd #define SPMI_REGULATOR_USE_HW_DEFAULT			2
46e2adfacdSStephen Boyd 
47e2adfacdSStephen Boyd /* Soft start strength of a voltage switch type regulator */
48e2adfacdSStephen Boyd enum spmi_vs_soft_start_str {
49e2adfacdSStephen Boyd 	SPMI_VS_SOFT_START_STR_0P05_UA = 0,
50e2adfacdSStephen Boyd 	SPMI_VS_SOFT_START_STR_0P25_UA,
51e2adfacdSStephen Boyd 	SPMI_VS_SOFT_START_STR_0P55_UA,
52e2adfacdSStephen Boyd 	SPMI_VS_SOFT_START_STR_0P75_UA,
53e2adfacdSStephen Boyd 	SPMI_VS_SOFT_START_STR_HW_DEFAULT,
54e2adfacdSStephen Boyd };
55e2adfacdSStephen Boyd 
56e2adfacdSStephen Boyd /**
57e2adfacdSStephen Boyd  * struct spmi_regulator_init_data - spmi-regulator initialization data
58e2adfacdSStephen Boyd  * @pin_ctrl_enable:        Bit mask specifying which hardware pins should be
59e2adfacdSStephen Boyd  *				used to enable the regulator, if any
60e2adfacdSStephen Boyd  *			    Value should be an ORing of
61e2adfacdSStephen Boyd  *				SPMI_REGULATOR_PIN_CTRL_ENABLE_* constants.  If
62e2adfacdSStephen Boyd  *				the bit specified by
63e2adfacdSStephen Boyd  *				SPMI_REGULATOR_PIN_CTRL_ENABLE_HW_DEFAULT is
64e2adfacdSStephen Boyd  *				set, then pin control enable hardware registers
65e2adfacdSStephen Boyd  *				will not be modified.
66e2adfacdSStephen Boyd  * @pin_ctrl_hpm:           Bit mask specifying which hardware pins should be
67e2adfacdSStephen Boyd  *				used to force the regulator into high power
68e2adfacdSStephen Boyd  *				mode, if any
69e2adfacdSStephen Boyd  *			    Value should be an ORing of
70e2adfacdSStephen Boyd  *				SPMI_REGULATOR_PIN_CTRL_HPM_* constants.  If
71e2adfacdSStephen Boyd  *				the bit specified by
72e2adfacdSStephen Boyd  *				SPMI_REGULATOR_PIN_CTRL_HPM_HW_DEFAULT is
73e2adfacdSStephen Boyd  *				set, then pin control mode hardware registers
74e2adfacdSStephen Boyd  *				will not be modified.
75e2adfacdSStephen Boyd  * @vs_soft_start_strength: This parameter sets the soft start strength for
76e2adfacdSStephen Boyd  *				voltage switch type regulators.  Its value
77e2adfacdSStephen Boyd  *				should be one of SPMI_VS_SOFT_START_STR_*.  If
78e2adfacdSStephen Boyd  *				its value is SPMI_VS_SOFT_START_STR_HW_DEFAULT,
79e2adfacdSStephen Boyd  *				then the soft start strength will be left at its
80e2adfacdSStephen Boyd  *				default hardware value.
81e2adfacdSStephen Boyd  */
82e2adfacdSStephen Boyd struct spmi_regulator_init_data {
83e2adfacdSStephen Boyd 	unsigned				pin_ctrl_enable;
84e2adfacdSStephen Boyd 	unsigned				pin_ctrl_hpm;
85e2adfacdSStephen Boyd 	enum spmi_vs_soft_start_str		vs_soft_start_strength;
86e2adfacdSStephen Boyd };
87e2adfacdSStephen Boyd 
88e92a4047SStephen Boyd /* These types correspond to unique register layouts. */
89e92a4047SStephen Boyd enum spmi_regulator_logical_type {
90e92a4047SStephen Boyd 	SPMI_REGULATOR_LOGICAL_TYPE_SMPS,
91e92a4047SStephen Boyd 	SPMI_REGULATOR_LOGICAL_TYPE_LDO,
92e92a4047SStephen Boyd 	SPMI_REGULATOR_LOGICAL_TYPE_VS,
93e92a4047SStephen Boyd 	SPMI_REGULATOR_LOGICAL_TYPE_BOOST,
94e92a4047SStephen Boyd 	SPMI_REGULATOR_LOGICAL_TYPE_FTSMPS,
95e92a4047SStephen Boyd 	SPMI_REGULATOR_LOGICAL_TYPE_BOOST_BYP,
96e92a4047SStephen Boyd 	SPMI_REGULATOR_LOGICAL_TYPE_LN_LDO,
97e92a4047SStephen Boyd 	SPMI_REGULATOR_LOGICAL_TYPE_ULT_LO_SMPS,
98e92a4047SStephen Boyd 	SPMI_REGULATOR_LOGICAL_TYPE_ULT_HO_SMPS,
99e92a4047SStephen Boyd 	SPMI_REGULATOR_LOGICAL_TYPE_ULT_LDO,
10042ba89c8SJeffrey Hugo 	SPMI_REGULATOR_LOGICAL_TYPE_FTSMPS426,
1010211f68eSJorge Ramirez 	SPMI_REGULATOR_LOGICAL_TYPE_HFS430,
1020d1cf568SIskren Chernev 	SPMI_REGULATOR_LOGICAL_TYPE_FTSMPS3,
1030d1cf568SIskren Chernev 	SPMI_REGULATOR_LOGICAL_TYPE_LDO_510,
10427850254SIskren Chernev 	SPMI_REGULATOR_LOGICAL_TYPE_HFSMPS,
105e92a4047SStephen Boyd };
106e92a4047SStephen Boyd 
107e92a4047SStephen Boyd enum spmi_regulator_type {
108e92a4047SStephen Boyd 	SPMI_REGULATOR_TYPE_BUCK		= 0x03,
109e92a4047SStephen Boyd 	SPMI_REGULATOR_TYPE_LDO			= 0x04,
110e92a4047SStephen Boyd 	SPMI_REGULATOR_TYPE_VS			= 0x05,
111e92a4047SStephen Boyd 	SPMI_REGULATOR_TYPE_BOOST		= 0x1b,
112e92a4047SStephen Boyd 	SPMI_REGULATOR_TYPE_FTS			= 0x1c,
113e92a4047SStephen Boyd 	SPMI_REGULATOR_TYPE_BOOST_BYP		= 0x1f,
114e92a4047SStephen Boyd 	SPMI_REGULATOR_TYPE_ULT_LDO		= 0x21,
115e92a4047SStephen Boyd 	SPMI_REGULATOR_TYPE_ULT_BUCK		= 0x22,
116e92a4047SStephen Boyd };
117e92a4047SStephen Boyd 
118e92a4047SStephen Boyd enum spmi_regulator_subtype {
119e92a4047SStephen Boyd 	SPMI_REGULATOR_SUBTYPE_GP_CTL		= 0x08,
120e92a4047SStephen Boyd 	SPMI_REGULATOR_SUBTYPE_RF_CTL		= 0x09,
121e92a4047SStephen Boyd 	SPMI_REGULATOR_SUBTYPE_N50		= 0x01,
122e92a4047SStephen Boyd 	SPMI_REGULATOR_SUBTYPE_N150		= 0x02,
123e92a4047SStephen Boyd 	SPMI_REGULATOR_SUBTYPE_N300		= 0x03,
124e92a4047SStephen Boyd 	SPMI_REGULATOR_SUBTYPE_N600		= 0x04,
125e92a4047SStephen Boyd 	SPMI_REGULATOR_SUBTYPE_N1200		= 0x05,
126e92a4047SStephen Boyd 	SPMI_REGULATOR_SUBTYPE_N600_ST		= 0x06,
127e92a4047SStephen Boyd 	SPMI_REGULATOR_SUBTYPE_N1200_ST		= 0x07,
128e92a4047SStephen Boyd 	SPMI_REGULATOR_SUBTYPE_N900_ST		= 0x14,
129e92a4047SStephen Boyd 	SPMI_REGULATOR_SUBTYPE_N300_ST		= 0x15,
130e92a4047SStephen Boyd 	SPMI_REGULATOR_SUBTYPE_P50		= 0x08,
131e92a4047SStephen Boyd 	SPMI_REGULATOR_SUBTYPE_P150		= 0x09,
132e92a4047SStephen Boyd 	SPMI_REGULATOR_SUBTYPE_P300		= 0x0a,
133e92a4047SStephen Boyd 	SPMI_REGULATOR_SUBTYPE_P600		= 0x0b,
134e92a4047SStephen Boyd 	SPMI_REGULATOR_SUBTYPE_P1200		= 0x0c,
135e92a4047SStephen Boyd 	SPMI_REGULATOR_SUBTYPE_LN		= 0x10,
136e92a4047SStephen Boyd 	SPMI_REGULATOR_SUBTYPE_LV_P50		= 0x28,
137e92a4047SStephen Boyd 	SPMI_REGULATOR_SUBTYPE_LV_P150		= 0x29,
138e92a4047SStephen Boyd 	SPMI_REGULATOR_SUBTYPE_LV_P300		= 0x2a,
139e92a4047SStephen Boyd 	SPMI_REGULATOR_SUBTYPE_LV_P600		= 0x2b,
140e92a4047SStephen Boyd 	SPMI_REGULATOR_SUBTYPE_LV_P1200		= 0x2c,
141e92a4047SStephen Boyd 	SPMI_REGULATOR_SUBTYPE_LV_P450		= 0x2d,
142328816c2SAngeloGioacchino Del Regno 	SPMI_REGULATOR_SUBTYPE_HT_N300_ST	= 0x30,
143328816c2SAngeloGioacchino Del Regno 	SPMI_REGULATOR_SUBTYPE_HT_N600_ST	= 0x31,
144328816c2SAngeloGioacchino Del Regno 	SPMI_REGULATOR_SUBTYPE_HT_N1200_ST	= 0x32,
145328816c2SAngeloGioacchino Del Regno 	SPMI_REGULATOR_SUBTYPE_HT_LVP150	= 0x3b,
146328816c2SAngeloGioacchino Del Regno 	SPMI_REGULATOR_SUBTYPE_HT_LVP300	= 0x3c,
147328816c2SAngeloGioacchino Del Regno 	SPMI_REGULATOR_SUBTYPE_L660_N300_ST	= 0x42,
148328816c2SAngeloGioacchino Del Regno 	SPMI_REGULATOR_SUBTYPE_L660_N600_ST	= 0x43,
149328816c2SAngeloGioacchino Del Regno 	SPMI_REGULATOR_SUBTYPE_L660_P50		= 0x46,
150328816c2SAngeloGioacchino Del Regno 	SPMI_REGULATOR_SUBTYPE_L660_P150	= 0x47,
151328816c2SAngeloGioacchino Del Regno 	SPMI_REGULATOR_SUBTYPE_L660_P600	= 0x49,
152328816c2SAngeloGioacchino Del Regno 	SPMI_REGULATOR_SUBTYPE_L660_LVP150	= 0x4d,
153328816c2SAngeloGioacchino Del Regno 	SPMI_REGULATOR_SUBTYPE_L660_LVP600	= 0x4f,
154e92a4047SStephen Boyd 	SPMI_REGULATOR_SUBTYPE_LV100		= 0x01,
155e92a4047SStephen Boyd 	SPMI_REGULATOR_SUBTYPE_LV300		= 0x02,
156e92a4047SStephen Boyd 	SPMI_REGULATOR_SUBTYPE_MV300		= 0x08,
157e92a4047SStephen Boyd 	SPMI_REGULATOR_SUBTYPE_MV500		= 0x09,
158e92a4047SStephen Boyd 	SPMI_REGULATOR_SUBTYPE_HDMI		= 0x10,
159e92a4047SStephen Boyd 	SPMI_REGULATOR_SUBTYPE_OTG		= 0x11,
160e92a4047SStephen Boyd 	SPMI_REGULATOR_SUBTYPE_5V_BOOST		= 0x01,
161e92a4047SStephen Boyd 	SPMI_REGULATOR_SUBTYPE_FTS_CTL		= 0x08,
162e92a4047SStephen Boyd 	SPMI_REGULATOR_SUBTYPE_FTS2p5_CTL	= 0x09,
16342ba89c8SJeffrey Hugo 	SPMI_REGULATOR_SUBTYPE_FTS426_CTL	= 0x0a,
164e92a4047SStephen Boyd 	SPMI_REGULATOR_SUBTYPE_BB_2A		= 0x01,
165e92a4047SStephen Boyd 	SPMI_REGULATOR_SUBTYPE_ULT_HF_CTL1	= 0x0d,
166e92a4047SStephen Boyd 	SPMI_REGULATOR_SUBTYPE_ULT_HF_CTL2	= 0x0e,
167e92a4047SStephen Boyd 	SPMI_REGULATOR_SUBTYPE_ULT_HF_CTL3	= 0x0f,
168e92a4047SStephen Boyd 	SPMI_REGULATOR_SUBTYPE_ULT_HF_CTL4	= 0x10,
1690211f68eSJorge Ramirez 	SPMI_REGULATOR_SUBTYPE_HFS430		= 0x0a,
17000f6ebbdSRobert Marko 	SPMI_REGULATOR_SUBTYPE_HT_P150		= 0x35,
1713d04ae8eSRobert Marko 	SPMI_REGULATOR_SUBTYPE_HT_P600		= 0x3d,
17227850254SIskren Chernev 	SPMI_REGULATOR_SUBTYPE_HFSMPS_510	= 0x0a,
1730d1cf568SIskren Chernev 	SPMI_REGULATOR_SUBTYPE_FTSMPS_510	= 0x0b,
1740d1cf568SIskren Chernev 	SPMI_REGULATOR_SUBTYPE_LV_P150_510	= 0x71,
1750d1cf568SIskren Chernev 	SPMI_REGULATOR_SUBTYPE_LV_P300_510	= 0x72,
1760d1cf568SIskren Chernev 	SPMI_REGULATOR_SUBTYPE_LV_P600_510	= 0x73,
1770d1cf568SIskren Chernev 	SPMI_REGULATOR_SUBTYPE_N300_510		= 0x6a,
1780d1cf568SIskren Chernev 	SPMI_REGULATOR_SUBTYPE_N600_510		= 0x6b,
1790d1cf568SIskren Chernev 	SPMI_REGULATOR_SUBTYPE_N1200_510	= 0x6c,
1800d1cf568SIskren Chernev 	SPMI_REGULATOR_SUBTYPE_MV_P50_510	= 0x7a,
1810d1cf568SIskren Chernev 	SPMI_REGULATOR_SUBTYPE_MV_P150_510	= 0x7b,
1820d1cf568SIskren Chernev 	SPMI_REGULATOR_SUBTYPE_MV_P600_510	= 0x7d,
183e92a4047SStephen Boyd };
184e92a4047SStephen Boyd 
185e92a4047SStephen Boyd enum spmi_common_regulator_registers {
186e92a4047SStephen Boyd 	SPMI_COMMON_REG_DIG_MAJOR_REV		= 0x01,
187e92a4047SStephen Boyd 	SPMI_COMMON_REG_TYPE			= 0x04,
188e92a4047SStephen Boyd 	SPMI_COMMON_REG_SUBTYPE			= 0x05,
189e92a4047SStephen Boyd 	SPMI_COMMON_REG_VOLTAGE_RANGE		= 0x40,
190e92a4047SStephen Boyd 	SPMI_COMMON_REG_VOLTAGE_SET		= 0x41,
191e92a4047SStephen Boyd 	SPMI_COMMON_REG_MODE			= 0x45,
192e92a4047SStephen Boyd 	SPMI_COMMON_REG_ENABLE			= 0x46,
193e92a4047SStephen Boyd 	SPMI_COMMON_REG_PULL_DOWN		= 0x48,
194e92a4047SStephen Boyd 	SPMI_COMMON_REG_SOFT_START		= 0x4c,
195e92a4047SStephen Boyd 	SPMI_COMMON_REG_STEP_CTRL		= 0x61,
196e92a4047SStephen Boyd };
197e92a4047SStephen Boyd 
19842ba89c8SJeffrey Hugo /*
19942ba89c8SJeffrey Hugo  * Second common register layout used by newer devices starting with ftsmps426
20042ba89c8SJeffrey Hugo  * Note that some of the registers from the first common layout remain
20142ba89c8SJeffrey Hugo  * unchanged and their definition is not duplicated.
20242ba89c8SJeffrey Hugo  */
20342ba89c8SJeffrey Hugo enum spmi_ftsmps426_regulator_registers {
20442ba89c8SJeffrey Hugo 	SPMI_FTSMPS426_REG_VOLTAGE_LSB		= 0x40,
20542ba89c8SJeffrey Hugo 	SPMI_FTSMPS426_REG_VOLTAGE_MSB		= 0x41,
20642ba89c8SJeffrey Hugo 	SPMI_FTSMPS426_REG_VOLTAGE_ULS_LSB	= 0x68,
20742ba89c8SJeffrey Hugo 	SPMI_FTSMPS426_REG_VOLTAGE_ULS_MSB	= 0x69,
20842ba89c8SJeffrey Hugo };
20942ba89c8SJeffrey Hugo 
21027850254SIskren Chernev /*
21127850254SIskren Chernev  * Third common register layout
21227850254SIskren Chernev  */
21327850254SIskren Chernev enum spmi_hfsmps_regulator_registers {
21427850254SIskren Chernev 	SPMI_HFSMPS_REG_STEP_CTRL		= 0x3c,
21527850254SIskren Chernev 	SPMI_HFSMPS_REG_PULL_DOWN		= 0xa0,
21627850254SIskren Chernev };
21727850254SIskren Chernev 
218e92a4047SStephen Boyd enum spmi_vs_registers {
219e92a4047SStephen Boyd 	SPMI_VS_REG_OCP				= 0x4a,
220e92a4047SStephen Boyd 	SPMI_VS_REG_SOFT_START			= 0x4c,
221e92a4047SStephen Boyd };
222e92a4047SStephen Boyd 
223e92a4047SStephen Boyd enum spmi_boost_registers {
224e92a4047SStephen Boyd 	SPMI_BOOST_REG_CURRENT_LIMIT		= 0x4a,
225e92a4047SStephen Boyd };
226e92a4047SStephen Boyd 
227e92a4047SStephen Boyd enum spmi_boost_byp_registers {
228e92a4047SStephen Boyd 	SPMI_BOOST_BYP_REG_CURRENT_LIMIT	= 0x4b,
229e92a4047SStephen Boyd };
230e92a4047SStephen Boyd 
2310caecaa8SIlia Lin enum spmi_saw3_registers {
2320caecaa8SIlia Lin 	SAW3_SECURE				= 0x00,
2330caecaa8SIlia Lin 	SAW3_ID					= 0x04,
2340caecaa8SIlia Lin 	SAW3_SPM_STS				= 0x0C,
2350caecaa8SIlia Lin 	SAW3_AVS_STS				= 0x10,
2360caecaa8SIlia Lin 	SAW3_PMIC_STS				= 0x14,
2370caecaa8SIlia Lin 	SAW3_RST				= 0x18,
2380caecaa8SIlia Lin 	SAW3_VCTL				= 0x1C,
2390caecaa8SIlia Lin 	SAW3_AVS_CTL				= 0x20,
2400caecaa8SIlia Lin 	SAW3_AVS_LIMIT				= 0x24,
2410caecaa8SIlia Lin 	SAW3_AVS_DLY				= 0x28,
2420caecaa8SIlia Lin 	SAW3_AVS_HYSTERESIS			= 0x2C,
2430caecaa8SIlia Lin 	SAW3_SPM_STS2				= 0x38,
2440caecaa8SIlia Lin 	SAW3_SPM_PMIC_DATA_3			= 0x4C,
2450caecaa8SIlia Lin 	SAW3_VERSION				= 0xFD0,
2460caecaa8SIlia Lin };
2470caecaa8SIlia Lin 
248*886fee35SYu Jiaoliang /* Used for indexing into ctrl_reg.  These are offsets from 0x40 */
249e92a4047SStephen Boyd enum spmi_common_control_register_index {
250e92a4047SStephen Boyd 	SPMI_COMMON_IDX_VOLTAGE_RANGE		= 0,
251e92a4047SStephen Boyd 	SPMI_COMMON_IDX_VOLTAGE_SET		= 1,
252e92a4047SStephen Boyd 	SPMI_COMMON_IDX_MODE			= 5,
253e92a4047SStephen Boyd 	SPMI_COMMON_IDX_ENABLE			= 6,
254e92a4047SStephen Boyd };
255e92a4047SStephen Boyd 
256e92a4047SStephen Boyd /* Common regulator control register layout */
257e92a4047SStephen Boyd #define SPMI_COMMON_ENABLE_MASK			0x80
258e92a4047SStephen Boyd #define SPMI_COMMON_ENABLE			0x80
259e92a4047SStephen Boyd #define SPMI_COMMON_DISABLE			0x00
260e92a4047SStephen Boyd #define SPMI_COMMON_ENABLE_FOLLOW_HW_EN3_MASK	0x08
261e92a4047SStephen Boyd #define SPMI_COMMON_ENABLE_FOLLOW_HW_EN2_MASK	0x04
262e92a4047SStephen Boyd #define SPMI_COMMON_ENABLE_FOLLOW_HW_EN1_MASK	0x02
263e92a4047SStephen Boyd #define SPMI_COMMON_ENABLE_FOLLOW_HW_EN0_MASK	0x01
264e92a4047SStephen Boyd #define SPMI_COMMON_ENABLE_FOLLOW_ALL_MASK	0x0f
265e92a4047SStephen Boyd 
266e92a4047SStephen Boyd /* Common regulator mode register layout */
267e92a4047SStephen Boyd #define SPMI_COMMON_MODE_HPM_MASK		0x80
268e92a4047SStephen Boyd #define SPMI_COMMON_MODE_AUTO_MASK		0x40
269e92a4047SStephen Boyd #define SPMI_COMMON_MODE_BYPASS_MASK		0x20
270e92a4047SStephen Boyd #define SPMI_COMMON_MODE_FOLLOW_AWAKE_MASK	0x10
271e92a4047SStephen Boyd #define SPMI_COMMON_MODE_FOLLOW_HW_EN3_MASK	0x08
272e92a4047SStephen Boyd #define SPMI_COMMON_MODE_FOLLOW_HW_EN2_MASK	0x04
273e92a4047SStephen Boyd #define SPMI_COMMON_MODE_FOLLOW_HW_EN1_MASK	0x02
274e92a4047SStephen Boyd #define SPMI_COMMON_MODE_FOLLOW_HW_EN0_MASK	0x01
275e92a4047SStephen Boyd #define SPMI_COMMON_MODE_FOLLOW_ALL_MASK	0x1f
276e92a4047SStephen Boyd 
27742ba89c8SJeffrey Hugo #define SPMI_FTSMPS426_MODE_BYPASS_MASK		3
27842ba89c8SJeffrey Hugo #define SPMI_FTSMPS426_MODE_RETENTION_MASK	4
27942ba89c8SJeffrey Hugo #define SPMI_FTSMPS426_MODE_LPM_MASK		5
28042ba89c8SJeffrey Hugo #define SPMI_FTSMPS426_MODE_AUTO_MASK		6
28142ba89c8SJeffrey Hugo #define SPMI_FTSMPS426_MODE_HPM_MASK		7
28242ba89c8SJeffrey Hugo 
28342ba89c8SJeffrey Hugo #define SPMI_FTSMPS426_MODE_MASK		0x07
28442ba89c8SJeffrey Hugo 
28527850254SIskren Chernev /* Third common regulator mode register values */
28627850254SIskren Chernev #define SPMI_HFSMPS_MODE_BYPASS_MASK		2
28727850254SIskren Chernev #define SPMI_HFSMPS_MODE_RETENTION_MASK		3
28827850254SIskren Chernev #define SPMI_HFSMPS_MODE_LPM_MASK		4
28927850254SIskren Chernev #define SPMI_HFSMPS_MODE_AUTO_MASK		6
29027850254SIskren Chernev #define SPMI_HFSMPS_MODE_HPM_MASK		7
29127850254SIskren Chernev 
29227850254SIskren Chernev #define SPMI_HFSMPS_MODE_MASK			0x07
29327850254SIskren Chernev 
294e92a4047SStephen Boyd /* Common regulator pull down control register layout */
295e92a4047SStephen Boyd #define SPMI_COMMON_PULL_DOWN_ENABLE_MASK	0x80
296e92a4047SStephen Boyd 
297e92a4047SStephen Boyd /* LDO regulator current limit control register layout */
298e92a4047SStephen Boyd #define SPMI_LDO_CURRENT_LIMIT_ENABLE_MASK	0x80
299e92a4047SStephen Boyd 
300e92a4047SStephen Boyd /* LDO regulator soft start control register layout */
301e92a4047SStephen Boyd #define SPMI_LDO_SOFT_START_ENABLE_MASK		0x80
302e92a4047SStephen Boyd 
303e92a4047SStephen Boyd /* VS regulator over current protection control register layout */
304e92a4047SStephen Boyd #define SPMI_VS_OCP_OVERRIDE			0x01
305e92a4047SStephen Boyd #define SPMI_VS_OCP_NO_OVERRIDE			0x00
306e92a4047SStephen Boyd 
307e92a4047SStephen Boyd /* VS regulator soft start control register layout */
308e92a4047SStephen Boyd #define SPMI_VS_SOFT_START_ENABLE_MASK		0x80
309e92a4047SStephen Boyd #define SPMI_VS_SOFT_START_SEL_MASK		0x03
310e92a4047SStephen Boyd 
311e92a4047SStephen Boyd /* Boost regulator current limit control register layout */
312e92a4047SStephen Boyd #define SPMI_BOOST_CURRENT_LIMIT_ENABLE_MASK	0x80
313e92a4047SStephen Boyd #define SPMI_BOOST_CURRENT_LIMIT_MASK		0x07
314e92a4047SStephen Boyd 
315e92a4047SStephen Boyd #define SPMI_VS_OCP_DEFAULT_MAX_RETRIES		10
316e92a4047SStephen Boyd #define SPMI_VS_OCP_DEFAULT_RETRY_DELAY_MS	30
317e92a4047SStephen Boyd #define SPMI_VS_OCP_FALL_DELAY_US		90
318e92a4047SStephen Boyd #define SPMI_VS_OCP_FAULT_DELAY_US		20000
319e92a4047SStephen Boyd 
320e92a4047SStephen Boyd #define SPMI_FTSMPS_STEP_CTRL_STEP_MASK		0x18
321e92a4047SStephen Boyd #define SPMI_FTSMPS_STEP_CTRL_STEP_SHIFT	3
322e92a4047SStephen Boyd #define SPMI_FTSMPS_STEP_CTRL_DELAY_MASK	0x07
323e92a4047SStephen Boyd #define SPMI_FTSMPS_STEP_CTRL_DELAY_SHIFT	0
324e92a4047SStephen Boyd 
325e92a4047SStephen Boyd /* Clock rate in kHz of the FTSMPS regulator reference clock. */
326e92a4047SStephen Boyd #define SPMI_FTSMPS_CLOCK_RATE		19200
327e92a4047SStephen Boyd 
328e92a4047SStephen Boyd /* Minimum voltage stepper delay for each step. */
329e92a4047SStephen Boyd #define SPMI_FTSMPS_STEP_DELAY		8
3302cf7b99cSStephen Boyd #define SPMI_DEFAULT_STEP_DELAY		20
331e92a4047SStephen Boyd 
332e92a4047SStephen Boyd /*
333e92a4047SStephen Boyd  * The ratio SPMI_FTSMPS_STEP_MARGIN_NUM/SPMI_FTSMPS_STEP_MARGIN_DEN is used to
334e92a4047SStephen Boyd  * adjust the step rate in order to account for oscillator variance.
335e92a4047SStephen Boyd  */
336e92a4047SStephen Boyd #define SPMI_FTSMPS_STEP_MARGIN_NUM	4
337e92a4047SStephen Boyd #define SPMI_FTSMPS_STEP_MARGIN_DEN	5
338e92a4047SStephen Boyd 
33927850254SIskren Chernev /* slew_rate has units of uV/us. */
34027850254SIskren Chernev #define SPMI_HFSMPS_SLEW_RATE_38p4 38400
34127850254SIskren Chernev 
34242ba89c8SJeffrey Hugo #define SPMI_FTSMPS426_STEP_CTRL_DELAY_MASK	0x03
34342ba89c8SJeffrey Hugo #define SPMI_FTSMPS426_STEP_CTRL_DELAY_SHIFT	0
34442ba89c8SJeffrey Hugo 
34542ba89c8SJeffrey Hugo /* Clock rate in kHz of the FTSMPS426 regulator reference clock. */
34642ba89c8SJeffrey Hugo #define SPMI_FTSMPS426_CLOCK_RATE		4800
34742ba89c8SJeffrey Hugo 
3480211f68eSJorge Ramirez #define SPMI_HFS430_CLOCK_RATE			1600
3490211f68eSJorge Ramirez 
35042ba89c8SJeffrey Hugo /* Minimum voltage stepper delay for each step. */
35142ba89c8SJeffrey Hugo #define SPMI_FTSMPS426_STEP_DELAY		2
35242ba89c8SJeffrey Hugo 
35342ba89c8SJeffrey Hugo /*
35442ba89c8SJeffrey Hugo  * The ratio SPMI_FTSMPS426_STEP_MARGIN_NUM/SPMI_FTSMPS426_STEP_MARGIN_DEN is
35542ba89c8SJeffrey Hugo  * used to adjust the step rate in order to account for oscillator variance.
35642ba89c8SJeffrey Hugo  */
35742ba89c8SJeffrey Hugo #define SPMI_FTSMPS426_STEP_MARGIN_NUM	10
35842ba89c8SJeffrey Hugo #define SPMI_FTSMPS426_STEP_MARGIN_DEN	11
35942ba89c8SJeffrey Hugo 
36042ba89c8SJeffrey Hugo 
361e92a4047SStephen Boyd /* VSET value to decide the range of ULT SMPS */
362e92a4047SStephen Boyd #define ULT_SMPS_RANGE_SPLIT 0x60
363e92a4047SStephen Boyd 
364e92a4047SStephen Boyd /**
365e92a4047SStephen Boyd  * struct spmi_voltage_range - regulator set point voltage mapping description
366e92a4047SStephen Boyd  * @min_uV:		Minimum programmable output voltage resulting from
367e92a4047SStephen Boyd  *			set point register value 0x00
368e92a4047SStephen Boyd  * @max_uV:		Maximum programmable output voltage
369e92a4047SStephen Boyd  * @step_uV:		Output voltage increase resulting from the set point
370e92a4047SStephen Boyd  *			register value increasing by 1
371e92a4047SStephen Boyd  * @set_point_min_uV:	Minimum allowed voltage
372e92a4047SStephen Boyd  * @set_point_max_uV:	Maximum allowed voltage.  This may be tweaked in order
373e92a4047SStephen Boyd  *			to pick which range should be used in the case of
374e92a4047SStephen Boyd  *			overlapping set points.
375e92a4047SStephen Boyd  * @n_voltages:		Number of preferred voltage set points present in this
376e92a4047SStephen Boyd  *			range
377e92a4047SStephen Boyd  * @range_sel:		Voltage range register value corresponding to this range
378e92a4047SStephen Boyd  *
379e92a4047SStephen Boyd  * The following relationships must be true for the values used in this struct:
380e92a4047SStephen Boyd  * (max_uV - min_uV) % step_uV == 0
381e92a4047SStephen Boyd  * (set_point_min_uV - min_uV) % step_uV == 0*
382e92a4047SStephen Boyd  * (set_point_max_uV - min_uV) % step_uV == 0*
383e92a4047SStephen Boyd  * n_voltages = (set_point_max_uV - set_point_min_uV) / step_uV + 1
384e92a4047SStephen Boyd  *
385e92a4047SStephen Boyd  * *Note, set_point_min_uV == set_point_max_uV == 0 is allowed in order to
386e92a4047SStephen Boyd  * specify that the voltage range has meaning, but is not preferred.
387e92a4047SStephen Boyd  */
388e92a4047SStephen Boyd struct spmi_voltage_range {
389e92a4047SStephen Boyd 	int					min_uV;
390e92a4047SStephen Boyd 	int					max_uV;
391e92a4047SStephen Boyd 	int					step_uV;
392e92a4047SStephen Boyd 	int					set_point_min_uV;
393e92a4047SStephen Boyd 	int					set_point_max_uV;
394e92a4047SStephen Boyd 	unsigned				n_voltages;
395e92a4047SStephen Boyd 	u8					range_sel;
396e92a4047SStephen Boyd };
397e92a4047SStephen Boyd 
398e92a4047SStephen Boyd /*
399e92a4047SStephen Boyd  * The ranges specified in the spmi_voltage_set_points struct must be listed
400e92a4047SStephen Boyd  * so that range[i].set_point_max_uV < range[i+1].set_point_min_uV.
401e92a4047SStephen Boyd  */
402e92a4047SStephen Boyd struct spmi_voltage_set_points {
403e92a4047SStephen Boyd 	struct spmi_voltage_range		*range;
404e92a4047SStephen Boyd 	int					count;
405e92a4047SStephen Boyd 	unsigned				n_voltages;
406e92a4047SStephen Boyd };
407e92a4047SStephen Boyd 
408e92a4047SStephen Boyd struct spmi_regulator {
409e92a4047SStephen Boyd 	struct regulator_desc			desc;
410e92a4047SStephen Boyd 	struct device				*dev;
411e92a4047SStephen Boyd 	struct delayed_work			ocp_work;
412e92a4047SStephen Boyd 	struct regmap				*regmap;
413e92a4047SStephen Boyd 	struct spmi_voltage_set_points		*set_points;
414e92a4047SStephen Boyd 	enum spmi_regulator_logical_type	logical_type;
415e92a4047SStephen Boyd 	int					ocp_irq;
416e92a4047SStephen Boyd 	int					ocp_count;
417e92a4047SStephen Boyd 	int					ocp_max_retries;
418e92a4047SStephen Boyd 	int					ocp_retry_delay_ms;
419e92a4047SStephen Boyd 	int					hpm_min_load;
420e92a4047SStephen Boyd 	int					slew_rate;
421e92a4047SStephen Boyd 	ktime_t					vs_enable_time;
422e92a4047SStephen Boyd 	u16					base;
423e92a4047SStephen Boyd 	struct list_head			node;
424e92a4047SStephen Boyd };
425e92a4047SStephen Boyd 
426e92a4047SStephen Boyd struct spmi_regulator_mapping {
427e92a4047SStephen Boyd 	enum spmi_regulator_type		type;
428e92a4047SStephen Boyd 	enum spmi_regulator_subtype		subtype;
429e92a4047SStephen Boyd 	enum spmi_regulator_logical_type	logical_type;
430e92a4047SStephen Boyd 	u32					revision_min;
431e92a4047SStephen Boyd 	u32					revision_max;
4323b619e3eSRikard Falkeborn 	const struct regulator_ops		*ops;
433e92a4047SStephen Boyd 	struct spmi_voltage_set_points		*set_points;
434e92a4047SStephen Boyd 	int					hpm_min_load;
435e92a4047SStephen Boyd };
436e92a4047SStephen Boyd 
437e92a4047SStephen Boyd struct spmi_regulator_data {
438e92a4047SStephen Boyd 	const char			*name;
439e92a4047SStephen Boyd 	u16				base;
440e92a4047SStephen Boyd 	const char			*supply;
441e92a4047SStephen Boyd 	const char			*ocp;
442e92a4047SStephen Boyd 	u16				force_type;
443e92a4047SStephen Boyd };
444e92a4047SStephen Boyd 
445e92a4047SStephen Boyd #define SPMI_VREG(_type, _subtype, _dig_major_min, _dig_major_max, \
446e92a4047SStephen Boyd 		      _logical_type, _ops_val, _set_points_val, _hpm_min_load) \
447e92a4047SStephen Boyd 	{ \
448e92a4047SStephen Boyd 		.type		= SPMI_REGULATOR_TYPE_##_type, \
449e92a4047SStephen Boyd 		.subtype	= SPMI_REGULATOR_SUBTYPE_##_subtype, \
450e92a4047SStephen Boyd 		.revision_min	= _dig_major_min, \
451e92a4047SStephen Boyd 		.revision_max	= _dig_major_max, \
452e92a4047SStephen Boyd 		.logical_type	= SPMI_REGULATOR_LOGICAL_TYPE_##_logical_type, \
453e92a4047SStephen Boyd 		.ops		= &spmi_##_ops_val##_ops, \
454e92a4047SStephen Boyd 		.set_points	= &_set_points_val##_set_points, \
455e92a4047SStephen Boyd 		.hpm_min_load	= _hpm_min_load, \
456e92a4047SStephen Boyd 	}
457e92a4047SStephen Boyd 
458e92a4047SStephen Boyd #define SPMI_VREG_VS(_subtype, _dig_major_min, _dig_major_max) \
459e92a4047SStephen Boyd 	{ \
460e92a4047SStephen Boyd 		.type		= SPMI_REGULATOR_TYPE_VS, \
461e92a4047SStephen Boyd 		.subtype	= SPMI_REGULATOR_SUBTYPE_##_subtype, \
462e92a4047SStephen Boyd 		.revision_min	= _dig_major_min, \
463e92a4047SStephen Boyd 		.revision_max	= _dig_major_max, \
464e92a4047SStephen Boyd 		.logical_type	= SPMI_REGULATOR_LOGICAL_TYPE_VS, \
465e92a4047SStephen Boyd 		.ops		= &spmi_vs_ops, \
466e92a4047SStephen Boyd 	}
467e92a4047SStephen Boyd 
468e92a4047SStephen Boyd #define SPMI_VOLTAGE_RANGE(_range_sel, _min_uV, _set_point_min_uV, \
469e92a4047SStephen Boyd 			_set_point_max_uV, _max_uV, _step_uV) \
470e92a4047SStephen Boyd 	{ \
471e92a4047SStephen Boyd 		.min_uV			= _min_uV, \
472e92a4047SStephen Boyd 		.max_uV			= _max_uV, \
473e92a4047SStephen Boyd 		.set_point_min_uV	= _set_point_min_uV, \
474e92a4047SStephen Boyd 		.set_point_max_uV	= _set_point_max_uV, \
475e92a4047SStephen Boyd 		.step_uV		= _step_uV, \
476e92a4047SStephen Boyd 		.range_sel		= _range_sel, \
477e92a4047SStephen Boyd 	}
478e92a4047SStephen Boyd 
479e92a4047SStephen Boyd #define DEFINE_SPMI_SET_POINTS(name) \
480e92a4047SStephen Boyd struct spmi_voltage_set_points name##_set_points = { \
481e92a4047SStephen Boyd 	.range	= name##_ranges, \
482e92a4047SStephen Boyd 	.count	= ARRAY_SIZE(name##_ranges), \
483e92a4047SStephen Boyd }
484e92a4047SStephen Boyd 
485e92a4047SStephen Boyd /*
486e92a4047SStephen Boyd  * These tables contain the physically available PMIC regulator voltage setpoint
487e92a4047SStephen Boyd  * ranges.  Where two ranges overlap in hardware, one of the ranges is trimmed
488e92a4047SStephen Boyd  * to ensure that the setpoints available to software are monotonically
489e92a4047SStephen Boyd  * increasing and unique.  The set_voltage callback functions expect these
490e92a4047SStephen Boyd  * properties to hold.
491e92a4047SStephen Boyd  */
492e92a4047SStephen Boyd static struct spmi_voltage_range pldo_ranges[] = {
493e92a4047SStephen Boyd 	SPMI_VOLTAGE_RANGE(2,  750000,  750000, 1537500, 1537500, 12500),
494e92a4047SStephen Boyd 	SPMI_VOLTAGE_RANGE(3, 1500000, 1550000, 3075000, 3075000, 25000),
495e92a4047SStephen Boyd 	SPMI_VOLTAGE_RANGE(4, 1750000, 3100000, 4900000, 4900000, 50000),
496e92a4047SStephen Boyd };
497e92a4047SStephen Boyd 
498e92a4047SStephen Boyd static struct spmi_voltage_range nldo1_ranges[] = {
499e92a4047SStephen Boyd 	SPMI_VOLTAGE_RANGE(2,  750000,  750000, 1537500, 1537500, 12500),
500e92a4047SStephen Boyd };
501e92a4047SStephen Boyd 
502e92a4047SStephen Boyd static struct spmi_voltage_range nldo2_ranges[] = {
503e92a4047SStephen Boyd 	SPMI_VOLTAGE_RANGE(0,  375000,       0,       0, 1537500, 12500),
504e92a4047SStephen Boyd 	SPMI_VOLTAGE_RANGE(1,  375000,  375000,  768750,  768750,  6250),
505e92a4047SStephen Boyd 	SPMI_VOLTAGE_RANGE(2,  750000,  775000, 1537500, 1537500, 12500),
506e92a4047SStephen Boyd };
507e92a4047SStephen Boyd 
508e92a4047SStephen Boyd static struct spmi_voltage_range nldo3_ranges[] = {
509e92a4047SStephen Boyd 	SPMI_VOLTAGE_RANGE(0,  375000,  375000, 1537500, 1537500, 12500),
510e92a4047SStephen Boyd 	SPMI_VOLTAGE_RANGE(1,  375000,       0,       0, 1537500, 12500),
511e92a4047SStephen Boyd 	SPMI_VOLTAGE_RANGE(2,  750000,       0,       0, 1537500, 12500),
512e92a4047SStephen Boyd };
513e92a4047SStephen Boyd 
514e92a4047SStephen Boyd static struct spmi_voltage_range ln_ldo_ranges[] = {
515e92a4047SStephen Boyd 	SPMI_VOLTAGE_RANGE(1,  690000,  690000, 1110000, 1110000, 60000),
516e92a4047SStephen Boyd 	SPMI_VOLTAGE_RANGE(0, 1380000, 1380000, 2220000, 2220000, 120000),
517e92a4047SStephen Boyd };
518e92a4047SStephen Boyd 
519e92a4047SStephen Boyd static struct spmi_voltage_range smps_ranges[] = {
520e92a4047SStephen Boyd 	SPMI_VOLTAGE_RANGE(0,  375000,  375000, 1562500, 1562500, 12500),
521e92a4047SStephen Boyd 	SPMI_VOLTAGE_RANGE(1, 1550000, 1575000, 3125000, 3125000, 25000),
522e92a4047SStephen Boyd };
523e92a4047SStephen Boyd 
524e92a4047SStephen Boyd static struct spmi_voltage_range ftsmps_ranges[] = {
525e92a4047SStephen Boyd 	SPMI_VOLTAGE_RANGE(0,       0,  350000, 1275000, 1275000,  5000),
526e92a4047SStephen Boyd 	SPMI_VOLTAGE_RANGE(1,       0, 1280000, 2040000, 2040000, 10000),
527e92a4047SStephen Boyd };
528e92a4047SStephen Boyd 
529e92a4047SStephen Boyd static struct spmi_voltage_range ftsmps2p5_ranges[] = {
530e92a4047SStephen Boyd 	SPMI_VOLTAGE_RANGE(0,   80000,  350000, 1355000, 1355000,  5000),
531e92a4047SStephen Boyd 	SPMI_VOLTAGE_RANGE(1,  160000, 1360000, 2200000, 2200000, 10000),
532e92a4047SStephen Boyd };
533e92a4047SStephen Boyd 
53442ba89c8SJeffrey Hugo static struct spmi_voltage_range ftsmps426_ranges[] = {
53542ba89c8SJeffrey Hugo 	SPMI_VOLTAGE_RANGE(0,       0,  320000, 1352000, 1352000,  4000),
53642ba89c8SJeffrey Hugo };
53742ba89c8SJeffrey Hugo 
538e92a4047SStephen Boyd static struct spmi_voltage_range boost_ranges[] = {
539e92a4047SStephen Boyd 	SPMI_VOLTAGE_RANGE(0, 4000000, 4000000, 5550000, 5550000, 50000),
540e92a4047SStephen Boyd };
541e92a4047SStephen Boyd 
542e92a4047SStephen Boyd static struct spmi_voltage_range boost_byp_ranges[] = {
543e92a4047SStephen Boyd 	SPMI_VOLTAGE_RANGE(0, 2500000, 2500000, 5200000, 5650000, 50000),
544e92a4047SStephen Boyd };
545e92a4047SStephen Boyd 
546e92a4047SStephen Boyd static struct spmi_voltage_range ult_lo_smps_ranges[] = {
547e92a4047SStephen Boyd 	SPMI_VOLTAGE_RANGE(0,  375000,  375000, 1562500, 1562500, 12500),
548e92a4047SStephen Boyd 	SPMI_VOLTAGE_RANGE(1,  750000,       0,       0, 1525000, 25000),
549e92a4047SStephen Boyd };
550e92a4047SStephen Boyd 
551e92a4047SStephen Boyd static struct spmi_voltage_range ult_ho_smps_ranges[] = {
552e92a4047SStephen Boyd 	SPMI_VOLTAGE_RANGE(0, 1550000, 1550000, 2325000, 2325000, 25000),
553e92a4047SStephen Boyd };
554e92a4047SStephen Boyd 
555e92a4047SStephen Boyd static struct spmi_voltage_range ult_nldo_ranges[] = {
556e92a4047SStephen Boyd 	SPMI_VOLTAGE_RANGE(0,  375000,  375000, 1537500, 1537500, 12500),
557e92a4047SStephen Boyd };
558e92a4047SStephen Boyd 
559e92a4047SStephen Boyd static struct spmi_voltage_range ult_pldo_ranges[] = {
560e92a4047SStephen Boyd 	SPMI_VOLTAGE_RANGE(0, 1750000, 1750000, 3337500, 3337500, 12500),
561e92a4047SStephen Boyd };
562e92a4047SStephen Boyd 
563328816c2SAngeloGioacchino Del Regno static struct spmi_voltage_range pldo660_ranges[] = {
564328816c2SAngeloGioacchino Del Regno 	SPMI_VOLTAGE_RANGE(0, 1504000, 1504000, 3544000, 3544000, 8000),
565328816c2SAngeloGioacchino Del Regno };
566328816c2SAngeloGioacchino Del Regno 
567328816c2SAngeloGioacchino Del Regno static struct spmi_voltage_range nldo660_ranges[] = {
568328816c2SAngeloGioacchino Del Regno 	SPMI_VOLTAGE_RANGE(0,  320000,  320000, 1304000, 1304000, 8000),
569328816c2SAngeloGioacchino Del Regno };
570328816c2SAngeloGioacchino Del Regno 
571328816c2SAngeloGioacchino Del Regno static struct spmi_voltage_range ht_lvpldo_ranges[] = {
572328816c2SAngeloGioacchino Del Regno 	SPMI_VOLTAGE_RANGE(0, 1504000, 1504000, 2000000, 2000000, 8000),
573328816c2SAngeloGioacchino Del Regno };
574328816c2SAngeloGioacchino Del Regno 
575328816c2SAngeloGioacchino Del Regno static struct spmi_voltage_range ht_nldo_ranges[] = {
576328816c2SAngeloGioacchino Del Regno 	SPMI_VOLTAGE_RANGE(0,  312000,  312000, 1304000, 1304000, 8000),
577328816c2SAngeloGioacchino Del Regno };
578328816c2SAngeloGioacchino Del Regno 
5790211f68eSJorge Ramirez static struct spmi_voltage_range hfs430_ranges[] = {
5800211f68eSJorge Ramirez 	SPMI_VOLTAGE_RANGE(0, 320000, 320000, 2040000, 2040000, 8000),
5810211f68eSJorge Ramirez };
5820211f68eSJorge Ramirez 
58300f6ebbdSRobert Marko static struct spmi_voltage_range ht_p150_ranges[] = {
58400f6ebbdSRobert Marko 	SPMI_VOLTAGE_RANGE(0, 1616000, 1616000, 3304000, 3304000, 8000),
58500f6ebbdSRobert Marko };
58600f6ebbdSRobert Marko 
5873d04ae8eSRobert Marko static struct spmi_voltage_range ht_p600_ranges[] = {
5883d04ae8eSRobert Marko 	SPMI_VOLTAGE_RANGE(0, 1704000, 1704000, 1896000, 1896000, 8000),
5893d04ae8eSRobert Marko };
5903d04ae8eSRobert Marko 
5910d1cf568SIskren Chernev static struct spmi_voltage_range nldo_510_ranges[] = {
5920d1cf568SIskren Chernev 	SPMI_VOLTAGE_RANGE(0, 320000, 320000, 1304000, 1304000, 8000),
5930d1cf568SIskren Chernev };
5940d1cf568SIskren Chernev 
5950d1cf568SIskren Chernev static struct spmi_voltage_range ftsmps510_ranges[] = {
5960d1cf568SIskren Chernev 	SPMI_VOLTAGE_RANGE(0, 300000, 300000, 1372000, 1372000, 4000),
5970d1cf568SIskren Chernev };
5980d1cf568SIskren Chernev 
599e92a4047SStephen Boyd static DEFINE_SPMI_SET_POINTS(pldo);
600e92a4047SStephen Boyd static DEFINE_SPMI_SET_POINTS(nldo1);
601e92a4047SStephen Boyd static DEFINE_SPMI_SET_POINTS(nldo2);
602e92a4047SStephen Boyd static DEFINE_SPMI_SET_POINTS(nldo3);
603e92a4047SStephen Boyd static DEFINE_SPMI_SET_POINTS(ln_ldo);
604e92a4047SStephen Boyd static DEFINE_SPMI_SET_POINTS(smps);
605e92a4047SStephen Boyd static DEFINE_SPMI_SET_POINTS(ftsmps);
606e92a4047SStephen Boyd static DEFINE_SPMI_SET_POINTS(ftsmps2p5);
60742ba89c8SJeffrey Hugo static DEFINE_SPMI_SET_POINTS(ftsmps426);
608e92a4047SStephen Boyd static DEFINE_SPMI_SET_POINTS(boost);
609e92a4047SStephen Boyd static DEFINE_SPMI_SET_POINTS(boost_byp);
610e92a4047SStephen Boyd static DEFINE_SPMI_SET_POINTS(ult_lo_smps);
611e92a4047SStephen Boyd static DEFINE_SPMI_SET_POINTS(ult_ho_smps);
612e92a4047SStephen Boyd static DEFINE_SPMI_SET_POINTS(ult_nldo);
613e92a4047SStephen Boyd static DEFINE_SPMI_SET_POINTS(ult_pldo);
614328816c2SAngeloGioacchino Del Regno static DEFINE_SPMI_SET_POINTS(pldo660);
615328816c2SAngeloGioacchino Del Regno static DEFINE_SPMI_SET_POINTS(nldo660);
616328816c2SAngeloGioacchino Del Regno static DEFINE_SPMI_SET_POINTS(ht_lvpldo);
617328816c2SAngeloGioacchino Del Regno static DEFINE_SPMI_SET_POINTS(ht_nldo);
6180211f68eSJorge Ramirez static DEFINE_SPMI_SET_POINTS(hfs430);
61900f6ebbdSRobert Marko static DEFINE_SPMI_SET_POINTS(ht_p150);
6203d04ae8eSRobert Marko static DEFINE_SPMI_SET_POINTS(ht_p600);
6210d1cf568SIskren Chernev static DEFINE_SPMI_SET_POINTS(nldo_510);
6220d1cf568SIskren Chernev static DEFINE_SPMI_SET_POINTS(ftsmps510);
623e92a4047SStephen Boyd 
spmi_vreg_read(struct spmi_regulator * vreg,u16 addr,u8 * buf,int len)624e92a4047SStephen Boyd static inline int spmi_vreg_read(struct spmi_regulator *vreg, u16 addr, u8 *buf,
625e92a4047SStephen Boyd 				 int len)
626e92a4047SStephen Boyd {
627e92a4047SStephen Boyd 	return regmap_bulk_read(vreg->regmap, vreg->base + addr, buf, len);
628e92a4047SStephen Boyd }
629e92a4047SStephen Boyd 
spmi_vreg_write(struct spmi_regulator * vreg,u16 addr,u8 * buf,int len)630e92a4047SStephen Boyd static inline int spmi_vreg_write(struct spmi_regulator *vreg, u16 addr,
631e92a4047SStephen Boyd 				u8 *buf, int len)
632e92a4047SStephen Boyd {
633e92a4047SStephen Boyd 	return regmap_bulk_write(vreg->regmap, vreg->base + addr, buf, len);
634e92a4047SStephen Boyd }
635e92a4047SStephen Boyd 
spmi_vreg_update_bits(struct spmi_regulator * vreg,u16 addr,u8 val,u8 mask)636e92a4047SStephen Boyd static int spmi_vreg_update_bits(struct spmi_regulator *vreg, u16 addr, u8 val,
637e92a4047SStephen Boyd 		u8 mask)
638e92a4047SStephen Boyd {
639e92a4047SStephen Boyd 	return regmap_update_bits(vreg->regmap, vreg->base + addr, mask, val);
640e92a4047SStephen Boyd }
641e92a4047SStephen Boyd 
spmi_regulator_vs_enable(struct regulator_dev * rdev)642e92a4047SStephen Boyd static int spmi_regulator_vs_enable(struct regulator_dev *rdev)
643e92a4047SStephen Boyd {
644e92a4047SStephen Boyd 	struct spmi_regulator *vreg = rdev_get_drvdata(rdev);
645e92a4047SStephen Boyd 
646e92a4047SStephen Boyd 	if (vreg->ocp_irq) {
647e92a4047SStephen Boyd 		vreg->ocp_count = 0;
648e92a4047SStephen Boyd 		vreg->vs_enable_time = ktime_get();
649e92a4047SStephen Boyd 	}
650e92a4047SStephen Boyd 
6519d485332SAxel Lin 	return regulator_enable_regmap(rdev);
652e92a4047SStephen Boyd }
653e92a4047SStephen Boyd 
spmi_regulator_vs_ocp(struct regulator_dev * rdev,int lim_uA,int severity,bool enable)65489a6a5e5SMatti Vaittinen static int spmi_regulator_vs_ocp(struct regulator_dev *rdev, int lim_uA,
65589a6a5e5SMatti Vaittinen 				 int severity, bool enable)
656e2adfacdSStephen Boyd {
657e2adfacdSStephen Boyd 	struct spmi_regulator *vreg = rdev_get_drvdata(rdev);
658e2adfacdSStephen Boyd 	u8 reg = SPMI_VS_OCP_OVERRIDE;
659e2adfacdSStephen Boyd 
66089a6a5e5SMatti Vaittinen 	if (lim_uA || !enable || severity != REGULATOR_SEVERITY_PROT)
66189a6a5e5SMatti Vaittinen 		return -EINVAL;
66289a6a5e5SMatti Vaittinen 
663e2adfacdSStephen Boyd 	return spmi_vreg_write(vreg, SPMI_VS_REG_OCP, &reg, 1);
664e2adfacdSStephen Boyd }
665e2adfacdSStephen Boyd 
spmi_regulator_select_voltage(struct spmi_regulator * vreg,int min_uV,int max_uV)666e92a4047SStephen Boyd static int spmi_regulator_select_voltage(struct spmi_regulator *vreg,
6671b5b1968SStephen Boyd 					 int min_uV, int max_uV)
668e92a4047SStephen Boyd {
669e92a4047SStephen Boyd 	const struct spmi_voltage_range *range;
670e92a4047SStephen Boyd 	int uV = min_uV;
671e92a4047SStephen Boyd 	int lim_min_uV, lim_max_uV, i, range_id, range_max_uV;
6721b5b1968SStephen Boyd 	int selector, voltage_sel;
673e92a4047SStephen Boyd 
674e92a4047SStephen Boyd 	/* Check if request voltage is outside of physically settable range. */
675e92a4047SStephen Boyd 	lim_min_uV = vreg->set_points->range[0].set_point_min_uV;
676e92a4047SStephen Boyd 	lim_max_uV =
677e92a4047SStephen Boyd 	  vreg->set_points->range[vreg->set_points->count - 1].set_point_max_uV;
678e92a4047SStephen Boyd 
679e92a4047SStephen Boyd 	if (uV < lim_min_uV && max_uV >= lim_min_uV)
680e92a4047SStephen Boyd 		uV = lim_min_uV;
681e92a4047SStephen Boyd 
682e92a4047SStephen Boyd 	if (uV < lim_min_uV || uV > lim_max_uV) {
683e92a4047SStephen Boyd 		dev_err(vreg->dev,
684e92a4047SStephen Boyd 			"request v=[%d, %d] is outside possible v=[%d, %d]\n",
685e92a4047SStephen Boyd 			 min_uV, max_uV, lim_min_uV, lim_max_uV);
686e92a4047SStephen Boyd 		return -EINVAL;
687e92a4047SStephen Boyd 	}
688e92a4047SStephen Boyd 
689e92a4047SStephen Boyd 	/* Find the range which uV is inside of. */
690e92a4047SStephen Boyd 	for (i = vreg->set_points->count - 1; i > 0; i--) {
691e92a4047SStephen Boyd 		range_max_uV = vreg->set_points->range[i - 1].set_point_max_uV;
692e92a4047SStephen Boyd 		if (uV > range_max_uV && range_max_uV > 0)
693e92a4047SStephen Boyd 			break;
694e92a4047SStephen Boyd 	}
695e92a4047SStephen Boyd 
696e92a4047SStephen Boyd 	range_id = i;
697e92a4047SStephen Boyd 	range = &vreg->set_points->range[range_id];
698e92a4047SStephen Boyd 
699e92a4047SStephen Boyd 	/*
700e92a4047SStephen Boyd 	 * Force uV to be an allowed set point by applying a ceiling function to
701e92a4047SStephen Boyd 	 * the uV value.
702e92a4047SStephen Boyd 	 */
7031b5b1968SStephen Boyd 	voltage_sel = DIV_ROUND_UP(uV - range->min_uV, range->step_uV);
7041b5b1968SStephen Boyd 	uV = voltage_sel * range->step_uV + range->min_uV;
705e92a4047SStephen Boyd 
706e92a4047SStephen Boyd 	if (uV > max_uV) {
707e92a4047SStephen Boyd 		dev_err(vreg->dev,
708e92a4047SStephen Boyd 			"request v=[%d, %d] cannot be met by any set point; "
709e92a4047SStephen Boyd 			"next set point: %d\n",
710e92a4047SStephen Boyd 			min_uV, max_uV, uV);
711e92a4047SStephen Boyd 		return -EINVAL;
712e92a4047SStephen Boyd 	}
713e92a4047SStephen Boyd 
7141b5b1968SStephen Boyd 	selector = 0;
715e92a4047SStephen Boyd 	for (i = 0; i < range_id; i++)
7161b5b1968SStephen Boyd 		selector += vreg->set_points->range[i].n_voltages;
7171b5b1968SStephen Boyd 	selector += (uV - range->set_point_min_uV) / range->step_uV;
718e92a4047SStephen Boyd 
7191b5b1968SStephen Boyd 	return selector;
7201b5b1968SStephen Boyd }
7211b5b1968SStephen Boyd 
spmi_sw_selector_to_hw(struct spmi_regulator * vreg,unsigned selector,u8 * range_sel,u8 * voltage_sel)7221b5b1968SStephen Boyd static int spmi_sw_selector_to_hw(struct spmi_regulator *vreg,
7231b5b1968SStephen Boyd 				  unsigned selector, u8 *range_sel,
7241b5b1968SStephen Boyd 				  u8 *voltage_sel)
7251b5b1968SStephen Boyd {
7261b5b1968SStephen Boyd 	const struct spmi_voltage_range *range, *end;
727ab953b9dSStephen Boyd 	unsigned offset;
7281b5b1968SStephen Boyd 
7291b5b1968SStephen Boyd 	range = vreg->set_points->range;
7301b5b1968SStephen Boyd 	end = range + vreg->set_points->count;
7311b5b1968SStephen Boyd 
7321b5b1968SStephen Boyd 	for (; range < end; range++) {
7331b5b1968SStephen Boyd 		if (selector < range->n_voltages) {
734ab953b9dSStephen Boyd 			/*
735ab953b9dSStephen Boyd 			 * hardware selectors between set point min and real
736ab953b9dSStephen Boyd 			 * min are invalid so we ignore them
737ab953b9dSStephen Boyd 			 */
738ab953b9dSStephen Boyd 			offset = range->set_point_min_uV - range->min_uV;
739ab953b9dSStephen Boyd 			offset /= range->step_uV;
740ab953b9dSStephen Boyd 			*voltage_sel = selector + offset;
7411b5b1968SStephen Boyd 			*range_sel = range->range_sel;
742e92a4047SStephen Boyd 			return 0;
743e92a4047SStephen Boyd 		}
744e92a4047SStephen Boyd 
7451b5b1968SStephen Boyd 		selector -= range->n_voltages;
7461b5b1968SStephen Boyd 	}
7471b5b1968SStephen Boyd 
7481b5b1968SStephen Boyd 	return -EINVAL;
7491b5b1968SStephen Boyd }
7501b5b1968SStephen Boyd 
spmi_hw_selector_to_sw(struct spmi_regulator * vreg,u8 hw_sel,const struct spmi_voltage_range * range)7511b5b1968SStephen Boyd static int spmi_hw_selector_to_sw(struct spmi_regulator *vreg, u8 hw_sel,
7521b5b1968SStephen Boyd 				  const struct spmi_voltage_range *range)
7531b5b1968SStephen Boyd {
754ab953b9dSStephen Boyd 	unsigned sw_sel = 0;
755ab953b9dSStephen Boyd 	unsigned offset, max_hw_sel;
7561b5b1968SStephen Boyd 	const struct spmi_voltage_range *r = vreg->set_points->range;
757ab953b9dSStephen Boyd 	const struct spmi_voltage_range *end = r + vreg->set_points->count;
7581b5b1968SStephen Boyd 
759ab953b9dSStephen Boyd 	for (; r < end; r++) {
760ab953b9dSStephen Boyd 		if (r == range && range->n_voltages) {
761ab953b9dSStephen Boyd 			/*
762ab953b9dSStephen Boyd 			 * hardware selectors between set point min and real
763ab953b9dSStephen Boyd 			 * min and between set point max and real max are
764ab953b9dSStephen Boyd 			 * invalid so we return an error if they're
765ab953b9dSStephen Boyd 			 * programmed into the hardware
766ab953b9dSStephen Boyd 			 */
767ab953b9dSStephen Boyd 			offset = range->set_point_min_uV - range->min_uV;
768ab953b9dSStephen Boyd 			offset /= range->step_uV;
769ab953b9dSStephen Boyd 			if (hw_sel < offset)
770ab953b9dSStephen Boyd 				return -EINVAL;
771ab953b9dSStephen Boyd 
772ab953b9dSStephen Boyd 			max_hw_sel = range->set_point_max_uV - range->min_uV;
773ab953b9dSStephen Boyd 			max_hw_sel /= range->step_uV;
774ab953b9dSStephen Boyd 			if (hw_sel > max_hw_sel)
775ab953b9dSStephen Boyd 				return -EINVAL;
776ab953b9dSStephen Boyd 
777ab953b9dSStephen Boyd 			return sw_sel + hw_sel - offset;
778ab953b9dSStephen Boyd 		}
7791b5b1968SStephen Boyd 		sw_sel += r->n_voltages;
7801b5b1968SStephen Boyd 	}
7811b5b1968SStephen Boyd 
782ab953b9dSStephen Boyd 	return -EINVAL;
7831b5b1968SStephen Boyd }
7841b5b1968SStephen Boyd 
785e92a4047SStephen Boyd static const struct spmi_voltage_range *
spmi_regulator_find_range(struct spmi_regulator * vreg)786e92a4047SStephen Boyd spmi_regulator_find_range(struct spmi_regulator *vreg)
787e92a4047SStephen Boyd {
788e92a4047SStephen Boyd 	u8 range_sel;
789e92a4047SStephen Boyd 	const struct spmi_voltage_range *range, *end;
790e92a4047SStephen Boyd 
791e92a4047SStephen Boyd 	range = vreg->set_points->range;
792e92a4047SStephen Boyd 	end = range + vreg->set_points->count;
793e92a4047SStephen Boyd 
794e92a4047SStephen Boyd 	spmi_vreg_read(vreg, SPMI_COMMON_REG_VOLTAGE_RANGE, &range_sel, 1);
795e92a4047SStephen Boyd 
796e92a4047SStephen Boyd 	for (; range < end; range++)
797e92a4047SStephen Boyd 		if (range->range_sel == range_sel)
798e92a4047SStephen Boyd 			return range;
799e92a4047SStephen Boyd 
800e92a4047SStephen Boyd 	return NULL;
801e92a4047SStephen Boyd }
802e92a4047SStephen Boyd 
spmi_regulator_select_voltage_same_range(struct spmi_regulator * vreg,int min_uV,int max_uV)803e92a4047SStephen Boyd static int spmi_regulator_select_voltage_same_range(struct spmi_regulator *vreg,
8041b5b1968SStephen Boyd 		int min_uV, int max_uV)
805e92a4047SStephen Boyd {
806e92a4047SStephen Boyd 	const struct spmi_voltage_range *range;
807e92a4047SStephen Boyd 	int uV = min_uV;
8081b5b1968SStephen Boyd 	int i, selector;
809e92a4047SStephen Boyd 
810e92a4047SStephen Boyd 	range = spmi_regulator_find_range(vreg);
811e92a4047SStephen Boyd 	if (!range)
812e92a4047SStephen Boyd 		goto different_range;
813e92a4047SStephen Boyd 
814e92a4047SStephen Boyd 	if (uV < range->min_uV && max_uV >= range->min_uV)
815e92a4047SStephen Boyd 		uV = range->min_uV;
816e92a4047SStephen Boyd 
817e92a4047SStephen Boyd 	if (uV < range->min_uV || uV > range->max_uV) {
818e92a4047SStephen Boyd 		/* Current range doesn't support the requested voltage. */
819e92a4047SStephen Boyd 		goto different_range;
820e92a4047SStephen Boyd 	}
821e92a4047SStephen Boyd 
822e92a4047SStephen Boyd 	/*
823e92a4047SStephen Boyd 	 * Force uV to be an allowed set point by applying a ceiling function to
824e92a4047SStephen Boyd 	 * the uV value.
825e92a4047SStephen Boyd 	 */
8261b5b1968SStephen Boyd 	uV = DIV_ROUND_UP(uV - range->min_uV, range->step_uV);
8271b5b1968SStephen Boyd 	uV = uV * range->step_uV + range->min_uV;
828e92a4047SStephen Boyd 
829e92a4047SStephen Boyd 	if (uV > max_uV) {
830e92a4047SStephen Boyd 		/*
831e92a4047SStephen Boyd 		 * No set point in the current voltage range is within the
832e92a4047SStephen Boyd 		 * requested min_uV to max_uV range.
833e92a4047SStephen Boyd 		 */
834e92a4047SStephen Boyd 		goto different_range;
835e92a4047SStephen Boyd 	}
836e92a4047SStephen Boyd 
8371b5b1968SStephen Boyd 	selector = 0;
838e92a4047SStephen Boyd 	for (i = 0; i < vreg->set_points->count; i++) {
839e92a4047SStephen Boyd 		if (uV >= vreg->set_points->range[i].set_point_min_uV
8409b2dfee3SStephen Boyd 		    && uV <= vreg->set_points->range[i].set_point_max_uV) {
8411b5b1968SStephen Boyd 			selector +=
842e92a4047SStephen Boyd 			    (uV - vreg->set_points->range[i].set_point_min_uV)
843e92a4047SStephen Boyd 				/ vreg->set_points->range[i].step_uV;
844e92a4047SStephen Boyd 			break;
8459b2dfee3SStephen Boyd 		}
846e92a4047SStephen Boyd 
8471b5b1968SStephen Boyd 		selector += vreg->set_points->range[i].n_voltages;
848e92a4047SStephen Boyd 	}
849e92a4047SStephen Boyd 
8501b5b1968SStephen Boyd 	if (selector >= vreg->set_points->n_voltages)
851e92a4047SStephen Boyd 		goto different_range;
852e92a4047SStephen Boyd 
853b1d21a24SStephen Boyd 	return selector;
854e92a4047SStephen Boyd 
855e92a4047SStephen Boyd different_range:
8561b5b1968SStephen Boyd 	return spmi_regulator_select_voltage(vreg, min_uV, max_uV);
857e92a4047SStephen Boyd }
858e92a4047SStephen Boyd 
spmi_regulator_common_map_voltage(struct regulator_dev * rdev,int min_uV,int max_uV)8591b5b1968SStephen Boyd static int spmi_regulator_common_map_voltage(struct regulator_dev *rdev,
8601b5b1968SStephen Boyd 					     int min_uV, int max_uV)
8611b5b1968SStephen Boyd {
8621b5b1968SStephen Boyd 	struct spmi_regulator *vreg = rdev_get_drvdata(rdev);
8631b5b1968SStephen Boyd 
8641b5b1968SStephen Boyd 	/*
8651b5b1968SStephen Boyd 	 * Favor staying in the current voltage range if possible.  This avoids
8661b5b1968SStephen Boyd 	 * voltage spikes that occur when changing the voltage range.
8671b5b1968SStephen Boyd 	 */
8681b5b1968SStephen Boyd 	return spmi_regulator_select_voltage_same_range(vreg, min_uV, max_uV);
8691b5b1968SStephen Boyd }
8701b5b1968SStephen Boyd 
8711b5b1968SStephen Boyd static int
spmi_regulator_common_set_voltage(struct regulator_dev * rdev,unsigned selector)8721b5b1968SStephen Boyd spmi_regulator_common_set_voltage(struct regulator_dev *rdev, unsigned selector)
873e92a4047SStephen Boyd {
874e92a4047SStephen Boyd 	struct spmi_regulator *vreg = rdev_get_drvdata(rdev);
875e92a4047SStephen Boyd 	int ret;
876e92a4047SStephen Boyd 	u8 buf[2];
877e92a4047SStephen Boyd 	u8 range_sel, voltage_sel;
878e92a4047SStephen Boyd 
8791b5b1968SStephen Boyd 	ret = spmi_sw_selector_to_hw(vreg, selector, &range_sel, &voltage_sel);
880e92a4047SStephen Boyd 	if (ret)
881e92a4047SStephen Boyd 		return ret;
882e92a4047SStephen Boyd 
883e92a4047SStephen Boyd 	buf[0] = range_sel;
884e92a4047SStephen Boyd 	buf[1] = voltage_sel;
885e92a4047SStephen Boyd 	return spmi_vreg_write(vreg, SPMI_COMMON_REG_VOLTAGE_RANGE, buf, 2);
886e92a4047SStephen Boyd }
887e92a4047SStephen Boyd 
88842ba89c8SJeffrey Hugo static int spmi_regulator_common_list_voltage(struct regulator_dev *rdev,
88942ba89c8SJeffrey Hugo 					      unsigned selector);
89042ba89c8SJeffrey Hugo 
spmi_regulator_ftsmps426_set_voltage(struct regulator_dev * rdev,unsigned selector)89142ba89c8SJeffrey Hugo static int spmi_regulator_ftsmps426_set_voltage(struct regulator_dev *rdev,
89242ba89c8SJeffrey Hugo 					      unsigned selector)
89342ba89c8SJeffrey Hugo {
89442ba89c8SJeffrey Hugo 	struct spmi_regulator *vreg = rdev_get_drvdata(rdev);
89542ba89c8SJeffrey Hugo 	u8 buf[2];
89642ba89c8SJeffrey Hugo 	int mV;
89742ba89c8SJeffrey Hugo 
89842ba89c8SJeffrey Hugo 	mV = spmi_regulator_common_list_voltage(rdev, selector) / 1000;
89942ba89c8SJeffrey Hugo 
90042ba89c8SJeffrey Hugo 	buf[0] = mV & 0xff;
90142ba89c8SJeffrey Hugo 	buf[1] = mV >> 8;
90242ba89c8SJeffrey Hugo 	return spmi_vreg_write(vreg, SPMI_FTSMPS426_REG_VOLTAGE_LSB, buf, 2);
90342ba89c8SJeffrey Hugo }
90442ba89c8SJeffrey Hugo 
spmi_regulator_set_voltage_time_sel(struct regulator_dev * rdev,unsigned int old_selector,unsigned int new_selector)905e92a4047SStephen Boyd static int spmi_regulator_set_voltage_time_sel(struct regulator_dev *rdev,
906e92a4047SStephen Boyd 		unsigned int old_selector, unsigned int new_selector)
907e92a4047SStephen Boyd {
908e92a4047SStephen Boyd 	struct spmi_regulator *vreg = rdev_get_drvdata(rdev);
909e92a4047SStephen Boyd 	int diff_uV;
910e92a4047SStephen Boyd 
91161d7fdc4SJeffrey Hugo 	diff_uV = abs(spmi_regulator_common_list_voltage(rdev, new_selector) -
91261d7fdc4SJeffrey Hugo 		      spmi_regulator_common_list_voltage(rdev, old_selector));
913e92a4047SStephen Boyd 
914e92a4047SStephen Boyd 	return DIV_ROUND_UP(diff_uV, vreg->slew_rate);
915e92a4047SStephen Boyd }
916e92a4047SStephen Boyd 
spmi_regulator_common_get_voltage(struct regulator_dev * rdev)917e92a4047SStephen Boyd static int spmi_regulator_common_get_voltage(struct regulator_dev *rdev)
918e92a4047SStephen Boyd {
919e92a4047SStephen Boyd 	struct spmi_regulator *vreg = rdev_get_drvdata(rdev);
920e92a4047SStephen Boyd 	const struct spmi_voltage_range *range;
921e92a4047SStephen Boyd 	u8 voltage_sel;
922e92a4047SStephen Boyd 
923e92a4047SStephen Boyd 	spmi_vreg_read(vreg, SPMI_COMMON_REG_VOLTAGE_SET, &voltage_sel, 1);
924e92a4047SStephen Boyd 
925e92a4047SStephen Boyd 	range = spmi_regulator_find_range(vreg);
926e92a4047SStephen Boyd 	if (!range)
9271b5b1968SStephen Boyd 		return -EINVAL;
928e92a4047SStephen Boyd 
9291b5b1968SStephen Boyd 	return spmi_hw_selector_to_sw(vreg, voltage_sel, range);
9301b5b1968SStephen Boyd }
9311b5b1968SStephen Boyd 
spmi_regulator_ftsmps426_get_voltage(struct regulator_dev * rdev)93242ba89c8SJeffrey Hugo static int spmi_regulator_ftsmps426_get_voltage(struct regulator_dev *rdev)
93342ba89c8SJeffrey Hugo {
93442ba89c8SJeffrey Hugo 	struct spmi_regulator *vreg = rdev_get_drvdata(rdev);
93542ba89c8SJeffrey Hugo 	const struct spmi_voltage_range *range;
93642ba89c8SJeffrey Hugo 	u8 buf[2];
93742ba89c8SJeffrey Hugo 	int uV;
93842ba89c8SJeffrey Hugo 
93942ba89c8SJeffrey Hugo 	spmi_vreg_read(vreg, SPMI_FTSMPS426_REG_VOLTAGE_LSB, buf, 2);
94042ba89c8SJeffrey Hugo 
94142ba89c8SJeffrey Hugo 	uV = (((unsigned int)buf[1] << 8) | (unsigned int)buf[0]) * 1000;
94242ba89c8SJeffrey Hugo 	range = vreg->set_points->range;
94342ba89c8SJeffrey Hugo 
94442ba89c8SJeffrey Hugo 	return (uV - range->set_point_min_uV) / range->step_uV;
94542ba89c8SJeffrey Hugo }
94642ba89c8SJeffrey Hugo 
spmi_regulator_single_map_voltage(struct regulator_dev * rdev,int min_uV,int max_uV)9471b5b1968SStephen Boyd static int spmi_regulator_single_map_voltage(struct regulator_dev *rdev,
9481b5b1968SStephen Boyd 		int min_uV, int max_uV)
9491b5b1968SStephen Boyd {
9501b5b1968SStephen Boyd 	struct spmi_regulator *vreg = rdev_get_drvdata(rdev);
9511b5b1968SStephen Boyd 
9521b5b1968SStephen Boyd 	return spmi_regulator_select_voltage(vreg, min_uV, max_uV);
953e92a4047SStephen Boyd }
954e92a4047SStephen Boyd 
spmi_regulator_single_range_set_voltage(struct regulator_dev * rdev,unsigned selector)955e92a4047SStephen Boyd static int spmi_regulator_single_range_set_voltage(struct regulator_dev *rdev,
9561b5b1968SStephen Boyd 						   unsigned selector)
957e92a4047SStephen Boyd {
958e92a4047SStephen Boyd 	struct spmi_regulator *vreg = rdev_get_drvdata(rdev);
9591b5b1968SStephen Boyd 	u8 sel = selector;
960e92a4047SStephen Boyd 
961e92a4047SStephen Boyd 	/*
962e92a4047SStephen Boyd 	 * Certain types of regulators do not have a range select register so
963e92a4047SStephen Boyd 	 * only voltage set register needs to be written.
964e92a4047SStephen Boyd 	 */
965e92a4047SStephen Boyd 	return spmi_vreg_write(vreg, SPMI_COMMON_REG_VOLTAGE_SET, &sel, 1);
966e92a4047SStephen Boyd }
967e92a4047SStephen Boyd 
spmi_regulator_single_range_get_voltage(struct regulator_dev * rdev)968e92a4047SStephen Boyd static int spmi_regulator_single_range_get_voltage(struct regulator_dev *rdev)
969e92a4047SStephen Boyd {
970e92a4047SStephen Boyd 	struct spmi_regulator *vreg = rdev_get_drvdata(rdev);
9711b5b1968SStephen Boyd 	u8 selector;
9721b5b1968SStephen Boyd 	int ret;
973e92a4047SStephen Boyd 
9741b5b1968SStephen Boyd 	ret = spmi_vreg_read(vreg, SPMI_COMMON_REG_VOLTAGE_SET, &selector, 1);
9751b5b1968SStephen Boyd 	if (ret)
9761b5b1968SStephen Boyd 		return ret;
977e92a4047SStephen Boyd 
9781b5b1968SStephen Boyd 	return selector;
979e92a4047SStephen Boyd }
980e92a4047SStephen Boyd 
spmi_regulator_ult_lo_smps_set_voltage(struct regulator_dev * rdev,unsigned selector)981e92a4047SStephen Boyd static int spmi_regulator_ult_lo_smps_set_voltage(struct regulator_dev *rdev,
9821b5b1968SStephen Boyd 						  unsigned selector)
983e92a4047SStephen Boyd {
984e92a4047SStephen Boyd 	struct spmi_regulator *vreg = rdev_get_drvdata(rdev);
985e92a4047SStephen Boyd 	int ret;
986e92a4047SStephen Boyd 	u8 range_sel, voltage_sel;
987e92a4047SStephen Boyd 
9881b5b1968SStephen Boyd 	ret = spmi_sw_selector_to_hw(vreg, selector, &range_sel, &voltage_sel);
989e92a4047SStephen Boyd 	if (ret)
990e92a4047SStephen Boyd 		return ret;
991e92a4047SStephen Boyd 
992e92a4047SStephen Boyd 	/*
993e92a4047SStephen Boyd 	 * Calculate VSET based on range
994e92a4047SStephen Boyd 	 * In case of range 0: voltage_sel is a 7 bit value, can be written
995e92a4047SStephen Boyd 	 *			witout any modification.
996e92a4047SStephen Boyd 	 * In case of range 1: voltage_sel is a 5 bit value, bits[7-5] set to
997e92a4047SStephen Boyd 	 *			[011].
998e92a4047SStephen Boyd 	 */
999e92a4047SStephen Boyd 	if (range_sel == 1)
1000e92a4047SStephen Boyd 		voltage_sel |= ULT_SMPS_RANGE_SPLIT;
1001e92a4047SStephen Boyd 
10020f94bffaSJulia Lawall 	return spmi_vreg_update_bits(vreg, SPMI_COMMON_REG_VOLTAGE_SET,
1003e92a4047SStephen Boyd 				     voltage_sel, 0xff);
1004e92a4047SStephen Boyd }
1005e92a4047SStephen Boyd 
spmi_regulator_ult_lo_smps_get_voltage(struct regulator_dev * rdev)1006e92a4047SStephen Boyd static int spmi_regulator_ult_lo_smps_get_voltage(struct regulator_dev *rdev)
1007e92a4047SStephen Boyd {
1008e92a4047SStephen Boyd 	struct spmi_regulator *vreg = rdev_get_drvdata(rdev);
1009e92a4047SStephen Boyd 	const struct spmi_voltage_range *range;
1010e92a4047SStephen Boyd 	u8 voltage_sel;
1011e92a4047SStephen Boyd 
1012e92a4047SStephen Boyd 	spmi_vreg_read(vreg, SPMI_COMMON_REG_VOLTAGE_SET, &voltage_sel, 1);
1013e92a4047SStephen Boyd 
1014e92a4047SStephen Boyd 	range = spmi_regulator_find_range(vreg);
1015e92a4047SStephen Boyd 	if (!range)
10161b5b1968SStephen Boyd 		return -EINVAL;
1017e92a4047SStephen Boyd 
1018e92a4047SStephen Boyd 	if (range->range_sel == 1)
1019e92a4047SStephen Boyd 		voltage_sel &= ~ULT_SMPS_RANGE_SPLIT;
1020e92a4047SStephen Boyd 
10211b5b1968SStephen Boyd 	return spmi_hw_selector_to_sw(vreg, voltage_sel, range);
1022e92a4047SStephen Boyd }
1023e92a4047SStephen Boyd 
spmi_regulator_common_list_voltage(struct regulator_dev * rdev,unsigned selector)1024e92a4047SStephen Boyd static int spmi_regulator_common_list_voltage(struct regulator_dev *rdev,
1025e92a4047SStephen Boyd 			unsigned selector)
1026e92a4047SStephen Boyd {
1027e92a4047SStephen Boyd 	struct spmi_regulator *vreg = rdev_get_drvdata(rdev);
1028e92a4047SStephen Boyd 	int uV = 0;
1029e92a4047SStephen Boyd 	int i;
1030e92a4047SStephen Boyd 
1031e92a4047SStephen Boyd 	if (selector >= vreg->set_points->n_voltages)
1032e92a4047SStephen Boyd 		return 0;
1033e92a4047SStephen Boyd 
1034e92a4047SStephen Boyd 	for (i = 0; i < vreg->set_points->count; i++) {
10359b2dfee3SStephen Boyd 		if (selector < vreg->set_points->range[i].n_voltages) {
1036e92a4047SStephen Boyd 			uV = selector * vreg->set_points->range[i].step_uV
1037e92a4047SStephen Boyd 				+ vreg->set_points->range[i].set_point_min_uV;
1038e92a4047SStephen Boyd 			break;
10399b2dfee3SStephen Boyd 		}
1040e92a4047SStephen Boyd 
1041e92a4047SStephen Boyd 		selector -= vreg->set_points->range[i].n_voltages;
1042e92a4047SStephen Boyd 	}
1043e92a4047SStephen Boyd 
1044e92a4047SStephen Boyd 	return uV;
1045e92a4047SStephen Boyd }
1046e92a4047SStephen Boyd 
1047e92a4047SStephen Boyd static int
spmi_regulator_common_set_bypass(struct regulator_dev * rdev,bool enable)1048e92a4047SStephen Boyd spmi_regulator_common_set_bypass(struct regulator_dev *rdev, bool enable)
1049e92a4047SStephen Boyd {
1050e92a4047SStephen Boyd 	struct spmi_regulator *vreg = rdev_get_drvdata(rdev);
1051e92a4047SStephen Boyd 	u8 mask = SPMI_COMMON_MODE_BYPASS_MASK;
1052e92a4047SStephen Boyd 	u8 val = 0;
1053e92a4047SStephen Boyd 
1054e92a4047SStephen Boyd 	if (enable)
1055e92a4047SStephen Boyd 		val = mask;
1056e92a4047SStephen Boyd 
1057e92a4047SStephen Boyd 	return spmi_vreg_update_bits(vreg, SPMI_COMMON_REG_MODE, val, mask);
1058e92a4047SStephen Boyd }
1059e92a4047SStephen Boyd 
1060e92a4047SStephen Boyd static int
spmi_regulator_common_get_bypass(struct regulator_dev * rdev,bool * enable)1061e92a4047SStephen Boyd spmi_regulator_common_get_bypass(struct regulator_dev *rdev, bool *enable)
1062e92a4047SStephen Boyd {
1063e92a4047SStephen Boyd 	struct spmi_regulator *vreg = rdev_get_drvdata(rdev);
1064e92a4047SStephen Boyd 	u8 val;
1065e92a4047SStephen Boyd 	int ret;
1066e92a4047SStephen Boyd 
1067e92a4047SStephen Boyd 	ret = spmi_vreg_read(vreg, SPMI_COMMON_REG_MODE, &val, 1);
1068e92a4047SStephen Boyd 	*enable = val & SPMI_COMMON_MODE_BYPASS_MASK;
1069e92a4047SStephen Boyd 
1070e92a4047SStephen Boyd 	return ret;
1071e92a4047SStephen Boyd }
1072e92a4047SStephen Boyd 
spmi_regulator_common_get_mode(struct regulator_dev * rdev)1073e92a4047SStephen Boyd static unsigned int spmi_regulator_common_get_mode(struct regulator_dev *rdev)
1074e92a4047SStephen Boyd {
1075e92a4047SStephen Boyd 	struct spmi_regulator *vreg = rdev_get_drvdata(rdev);
1076e92a4047SStephen Boyd 	u8 reg;
1077e92a4047SStephen Boyd 
1078e92a4047SStephen Boyd 	spmi_vreg_read(vreg, SPMI_COMMON_REG_MODE, &reg, 1);
1079e92a4047SStephen Boyd 
1080ba576a62SJeffrey Hugo 	reg &= SPMI_COMMON_MODE_HPM_MASK | SPMI_COMMON_MODE_AUTO_MASK;
1081ba576a62SJeffrey Hugo 
1082ba576a62SJeffrey Hugo 	switch (reg) {
1083ba576a62SJeffrey Hugo 	case SPMI_COMMON_MODE_HPM_MASK:
1084e92a4047SStephen Boyd 		return REGULATOR_MODE_NORMAL;
1085ba576a62SJeffrey Hugo 	case SPMI_COMMON_MODE_AUTO_MASK:
1086e2adfacdSStephen Boyd 		return REGULATOR_MODE_FAST;
1087ba576a62SJeffrey Hugo 	default:
1088e92a4047SStephen Boyd 		return REGULATOR_MODE_IDLE;
1089e92a4047SStephen Boyd 	}
1090ba576a62SJeffrey Hugo }
1091e92a4047SStephen Boyd 
spmi_regulator_ftsmps426_get_mode(struct regulator_dev * rdev)109242ba89c8SJeffrey Hugo static unsigned int spmi_regulator_ftsmps426_get_mode(struct regulator_dev *rdev)
109342ba89c8SJeffrey Hugo {
109442ba89c8SJeffrey Hugo 	struct spmi_regulator *vreg = rdev_get_drvdata(rdev);
109542ba89c8SJeffrey Hugo 	u8 reg;
109642ba89c8SJeffrey Hugo 
109742ba89c8SJeffrey Hugo 	spmi_vreg_read(vreg, SPMI_COMMON_REG_MODE, &reg, 1);
109842ba89c8SJeffrey Hugo 
109942ba89c8SJeffrey Hugo 	switch (reg) {
110042ba89c8SJeffrey Hugo 	case SPMI_FTSMPS426_MODE_HPM_MASK:
110142ba89c8SJeffrey Hugo 		return REGULATOR_MODE_NORMAL;
110242ba89c8SJeffrey Hugo 	case SPMI_FTSMPS426_MODE_AUTO_MASK:
110342ba89c8SJeffrey Hugo 		return REGULATOR_MODE_FAST;
110442ba89c8SJeffrey Hugo 	default:
110542ba89c8SJeffrey Hugo 		return REGULATOR_MODE_IDLE;
110642ba89c8SJeffrey Hugo 	}
110742ba89c8SJeffrey Hugo }
110842ba89c8SJeffrey Hugo 
spmi_regulator_hfsmps_get_mode(struct regulator_dev * rdev)110927850254SIskren Chernev static unsigned int spmi_regulator_hfsmps_get_mode(struct regulator_dev *rdev)
111027850254SIskren Chernev {
111127850254SIskren Chernev 	struct spmi_regulator *vreg = rdev_get_drvdata(rdev);
111227850254SIskren Chernev 	u8 reg;
111327850254SIskren Chernev 
111427850254SIskren Chernev 	spmi_vreg_read(vreg, SPMI_COMMON_REG_MODE, &reg, 1);
111527850254SIskren Chernev 
111627850254SIskren Chernev 	switch (reg) {
111727850254SIskren Chernev 	case SPMI_HFSMPS_MODE_HPM_MASK:
111827850254SIskren Chernev 		return REGULATOR_MODE_NORMAL;
111927850254SIskren Chernev 	case SPMI_HFSMPS_MODE_AUTO_MASK:
112027850254SIskren Chernev 		return REGULATOR_MODE_FAST;
112127850254SIskren Chernev 	default:
112227850254SIskren Chernev 		return REGULATOR_MODE_IDLE;
112327850254SIskren Chernev 	}
112427850254SIskren Chernev }
112527850254SIskren Chernev 
1126e92a4047SStephen Boyd static int
spmi_regulator_common_set_mode(struct regulator_dev * rdev,unsigned int mode)1127e92a4047SStephen Boyd spmi_regulator_common_set_mode(struct regulator_dev *rdev, unsigned int mode)
1128e92a4047SStephen Boyd {
1129e92a4047SStephen Boyd 	struct spmi_regulator *vreg = rdev_get_drvdata(rdev);
1130e2adfacdSStephen Boyd 	u8 mask = SPMI_COMMON_MODE_HPM_MASK | SPMI_COMMON_MODE_AUTO_MASK;
1131ba576a62SJeffrey Hugo 	u8 val;
1132e92a4047SStephen Boyd 
1133ba576a62SJeffrey Hugo 	switch (mode) {
1134ba576a62SJeffrey Hugo 	case REGULATOR_MODE_NORMAL:
1135e2adfacdSStephen Boyd 		val = SPMI_COMMON_MODE_HPM_MASK;
1136ba576a62SJeffrey Hugo 		break;
1137ba576a62SJeffrey Hugo 	case REGULATOR_MODE_FAST:
1138e2adfacdSStephen Boyd 		val = SPMI_COMMON_MODE_AUTO_MASK;
1139ba576a62SJeffrey Hugo 		break;
1140ba576a62SJeffrey Hugo 	default:
1141ba576a62SJeffrey Hugo 		val = 0;
1142ba576a62SJeffrey Hugo 		break;
1143ba576a62SJeffrey Hugo 	}
1144e92a4047SStephen Boyd 
1145e92a4047SStephen Boyd 	return spmi_vreg_update_bits(vreg, SPMI_COMMON_REG_MODE, val, mask);
1146e92a4047SStephen Boyd }
1147e92a4047SStephen Boyd 
1148e92a4047SStephen Boyd static int
spmi_regulator_ftsmps426_set_mode(struct regulator_dev * rdev,unsigned int mode)114942ba89c8SJeffrey Hugo spmi_regulator_ftsmps426_set_mode(struct regulator_dev *rdev, unsigned int mode)
115042ba89c8SJeffrey Hugo {
115142ba89c8SJeffrey Hugo 	struct spmi_regulator *vreg = rdev_get_drvdata(rdev);
115242ba89c8SJeffrey Hugo 	u8 mask = SPMI_FTSMPS426_MODE_MASK;
115342ba89c8SJeffrey Hugo 	u8 val;
115442ba89c8SJeffrey Hugo 
115542ba89c8SJeffrey Hugo 	switch (mode) {
115642ba89c8SJeffrey Hugo 	case REGULATOR_MODE_NORMAL:
115742ba89c8SJeffrey Hugo 		val = SPMI_FTSMPS426_MODE_HPM_MASK;
115842ba89c8SJeffrey Hugo 		break;
115942ba89c8SJeffrey Hugo 	case REGULATOR_MODE_FAST:
116042ba89c8SJeffrey Hugo 		val = SPMI_FTSMPS426_MODE_AUTO_MASK;
116142ba89c8SJeffrey Hugo 		break;
116242ba89c8SJeffrey Hugo 	case REGULATOR_MODE_IDLE:
116342ba89c8SJeffrey Hugo 		val = SPMI_FTSMPS426_MODE_LPM_MASK;
116442ba89c8SJeffrey Hugo 		break;
116542ba89c8SJeffrey Hugo 	default:
116642ba89c8SJeffrey Hugo 		return -EINVAL;
116742ba89c8SJeffrey Hugo 	}
116842ba89c8SJeffrey Hugo 
116942ba89c8SJeffrey Hugo 	return spmi_vreg_update_bits(vreg, SPMI_COMMON_REG_MODE, val, mask);
117042ba89c8SJeffrey Hugo }
117142ba89c8SJeffrey Hugo 
117242ba89c8SJeffrey Hugo static int
spmi_regulator_hfsmps_set_mode(struct regulator_dev * rdev,unsigned int mode)117327850254SIskren Chernev spmi_regulator_hfsmps_set_mode(struct regulator_dev *rdev, unsigned int mode)
117427850254SIskren Chernev {
117527850254SIskren Chernev 	struct spmi_regulator *vreg = rdev_get_drvdata(rdev);
117627850254SIskren Chernev 	u8 mask = SPMI_HFSMPS_MODE_MASK;
117727850254SIskren Chernev 	u8 val;
117827850254SIskren Chernev 
117927850254SIskren Chernev 	switch (mode) {
118027850254SIskren Chernev 	case REGULATOR_MODE_NORMAL:
118127850254SIskren Chernev 		val = SPMI_HFSMPS_MODE_HPM_MASK;
118227850254SIskren Chernev 		break;
118327850254SIskren Chernev 	case REGULATOR_MODE_FAST:
118427850254SIskren Chernev 		val = SPMI_HFSMPS_MODE_AUTO_MASK;
118527850254SIskren Chernev 		break;
118627850254SIskren Chernev 	case REGULATOR_MODE_IDLE:
11870d1cf568SIskren Chernev 		val = vreg->logical_type ==
11880d1cf568SIskren Chernev 				SPMI_REGULATOR_LOGICAL_TYPE_FTSMPS3 ?
11890d1cf568SIskren Chernev 			SPMI_HFSMPS_MODE_RETENTION_MASK :
11900d1cf568SIskren Chernev 			SPMI_HFSMPS_MODE_LPM_MASK;
119127850254SIskren Chernev 		break;
119227850254SIskren Chernev 	default:
119327850254SIskren Chernev 		return -EINVAL;
119427850254SIskren Chernev 	}
119527850254SIskren Chernev 
119627850254SIskren Chernev 	return spmi_vreg_update_bits(vreg, SPMI_COMMON_REG_MODE, val, mask);
119727850254SIskren Chernev }
119827850254SIskren Chernev 
119927850254SIskren Chernev static int
spmi_regulator_common_set_load(struct regulator_dev * rdev,int load_uA)1200e92a4047SStephen Boyd spmi_regulator_common_set_load(struct regulator_dev *rdev, int load_uA)
1201e92a4047SStephen Boyd {
1202e92a4047SStephen Boyd 	struct spmi_regulator *vreg = rdev_get_drvdata(rdev);
1203e92a4047SStephen Boyd 	unsigned int mode;
1204e92a4047SStephen Boyd 
1205e92a4047SStephen Boyd 	if (load_uA >= vreg->hpm_min_load)
1206e92a4047SStephen Boyd 		mode = REGULATOR_MODE_NORMAL;
1207e92a4047SStephen Boyd 	else
1208e92a4047SStephen Boyd 		mode = REGULATOR_MODE_IDLE;
1209e92a4047SStephen Boyd 
1210e92a4047SStephen Boyd 	return spmi_regulator_common_set_mode(rdev, mode);
1211e92a4047SStephen Boyd }
1212e92a4047SStephen Boyd 
spmi_regulator_common_set_pull_down(struct regulator_dev * rdev)1213e92a4047SStephen Boyd static int spmi_regulator_common_set_pull_down(struct regulator_dev *rdev)
1214e92a4047SStephen Boyd {
1215e92a4047SStephen Boyd 	struct spmi_regulator *vreg = rdev_get_drvdata(rdev);
1216e92a4047SStephen Boyd 	unsigned int mask = SPMI_COMMON_PULL_DOWN_ENABLE_MASK;
1217e92a4047SStephen Boyd 
1218e92a4047SStephen Boyd 	return spmi_vreg_update_bits(vreg, SPMI_COMMON_REG_PULL_DOWN,
1219e92a4047SStephen Boyd 				     mask, mask);
1220e92a4047SStephen Boyd }
1221e92a4047SStephen Boyd 
spmi_regulator_hfsmps_set_pull_down(struct regulator_dev * rdev)122227850254SIskren Chernev static int spmi_regulator_hfsmps_set_pull_down(struct regulator_dev *rdev)
122327850254SIskren Chernev {
122427850254SIskren Chernev 	struct spmi_regulator *vreg = rdev_get_drvdata(rdev);
122527850254SIskren Chernev 	unsigned int mask = SPMI_COMMON_PULL_DOWN_ENABLE_MASK;
122627850254SIskren Chernev 
122727850254SIskren Chernev 	return spmi_vreg_update_bits(vreg, SPMI_HFSMPS_REG_PULL_DOWN,
122827850254SIskren Chernev 				     mask, mask);
122927850254SIskren Chernev }
123027850254SIskren Chernev 
spmi_regulator_common_set_soft_start(struct regulator_dev * rdev)1231e92a4047SStephen Boyd static int spmi_regulator_common_set_soft_start(struct regulator_dev *rdev)
1232e92a4047SStephen Boyd {
1233e92a4047SStephen Boyd 	struct spmi_regulator *vreg = rdev_get_drvdata(rdev);
1234e92a4047SStephen Boyd 	unsigned int mask = SPMI_LDO_SOFT_START_ENABLE_MASK;
1235e92a4047SStephen Boyd 
1236e92a4047SStephen Boyd 	return spmi_vreg_update_bits(vreg, SPMI_COMMON_REG_SOFT_START,
1237e92a4047SStephen Boyd 				     mask, mask);
1238e92a4047SStephen Boyd }
1239e92a4047SStephen Boyd 
spmi_regulator_set_ilim(struct regulator_dev * rdev,int ilim_uA)1240e92a4047SStephen Boyd static int spmi_regulator_set_ilim(struct regulator_dev *rdev, int ilim_uA)
1241e92a4047SStephen Boyd {
1242e92a4047SStephen Boyd 	struct spmi_regulator *vreg = rdev_get_drvdata(rdev);
1243e92a4047SStephen Boyd 	enum spmi_regulator_logical_type type = vreg->logical_type;
1244e92a4047SStephen Boyd 	unsigned int current_reg;
1245e92a4047SStephen Boyd 	u8 reg;
1246e92a4047SStephen Boyd 	u8 mask = SPMI_BOOST_CURRENT_LIMIT_MASK |
1247e92a4047SStephen Boyd 		  SPMI_BOOST_CURRENT_LIMIT_ENABLE_MASK;
1248e92a4047SStephen Boyd 	int max = (SPMI_BOOST_CURRENT_LIMIT_MASK + 1) * 500;
1249e92a4047SStephen Boyd 
1250e92a4047SStephen Boyd 	if (type == SPMI_REGULATOR_LOGICAL_TYPE_BOOST)
1251e92a4047SStephen Boyd 		current_reg = SPMI_BOOST_REG_CURRENT_LIMIT;
1252e92a4047SStephen Boyd 	else
1253e92a4047SStephen Boyd 		current_reg = SPMI_BOOST_BYP_REG_CURRENT_LIMIT;
1254e92a4047SStephen Boyd 
1255e92a4047SStephen Boyd 	if (ilim_uA > max || ilim_uA <= 0)
1256e92a4047SStephen Boyd 		return -EINVAL;
1257e92a4047SStephen Boyd 
1258e92a4047SStephen Boyd 	reg = (ilim_uA - 1) / 500;
1259e92a4047SStephen Boyd 	reg |= SPMI_BOOST_CURRENT_LIMIT_ENABLE_MASK;
1260e92a4047SStephen Boyd 
1261e92a4047SStephen Boyd 	return spmi_vreg_update_bits(vreg, current_reg, reg, mask);
1262e92a4047SStephen Boyd }
1263e92a4047SStephen Boyd 
spmi_regulator_vs_clear_ocp(struct spmi_regulator * vreg)1264e92a4047SStephen Boyd static int spmi_regulator_vs_clear_ocp(struct spmi_regulator *vreg)
1265e92a4047SStephen Boyd {
1266e92a4047SStephen Boyd 	int ret;
1267e92a4047SStephen Boyd 
1268e92a4047SStephen Boyd 	ret = spmi_vreg_update_bits(vreg, SPMI_COMMON_REG_ENABLE,
1269e92a4047SStephen Boyd 		SPMI_COMMON_DISABLE, SPMI_COMMON_ENABLE_MASK);
1270e92a4047SStephen Boyd 
1271e92a4047SStephen Boyd 	vreg->vs_enable_time = ktime_get();
1272e92a4047SStephen Boyd 
1273e92a4047SStephen Boyd 	ret = spmi_vreg_update_bits(vreg, SPMI_COMMON_REG_ENABLE,
1274e92a4047SStephen Boyd 		SPMI_COMMON_ENABLE, SPMI_COMMON_ENABLE_MASK);
1275e92a4047SStephen Boyd 
1276e92a4047SStephen Boyd 	return ret;
1277e92a4047SStephen Boyd }
1278e92a4047SStephen Boyd 
spmi_regulator_vs_ocp_work(struct work_struct * work)1279e92a4047SStephen Boyd static void spmi_regulator_vs_ocp_work(struct work_struct *work)
1280e92a4047SStephen Boyd {
1281e92a4047SStephen Boyd 	struct delayed_work *dwork = to_delayed_work(work);
1282e92a4047SStephen Boyd 	struct spmi_regulator *vreg
1283e92a4047SStephen Boyd 		= container_of(dwork, struct spmi_regulator, ocp_work);
1284e92a4047SStephen Boyd 
1285e92a4047SStephen Boyd 	spmi_regulator_vs_clear_ocp(vreg);
1286e92a4047SStephen Boyd }
1287e92a4047SStephen Boyd 
spmi_regulator_vs_ocp_isr(int irq,void * data)1288e92a4047SStephen Boyd static irqreturn_t spmi_regulator_vs_ocp_isr(int irq, void *data)
1289e92a4047SStephen Boyd {
1290e92a4047SStephen Boyd 	struct spmi_regulator *vreg = data;
1291e92a4047SStephen Boyd 	ktime_t ocp_irq_time;
1292e92a4047SStephen Boyd 	s64 ocp_trigger_delay_us;
1293e92a4047SStephen Boyd 
1294e92a4047SStephen Boyd 	ocp_irq_time = ktime_get();
1295e92a4047SStephen Boyd 	ocp_trigger_delay_us = ktime_us_delta(ocp_irq_time,
1296e92a4047SStephen Boyd 						vreg->vs_enable_time);
1297e92a4047SStephen Boyd 
1298e92a4047SStephen Boyd 	/*
1299e92a4047SStephen Boyd 	 * Reset the OCP count if there is a large delay between switch enable
1300e92a4047SStephen Boyd 	 * and when OCP triggers.  This is indicative of a hotplug event as
1301e92a4047SStephen Boyd 	 * opposed to a fault.
1302e92a4047SStephen Boyd 	 */
1303e92a4047SStephen Boyd 	if (ocp_trigger_delay_us > SPMI_VS_OCP_FAULT_DELAY_US)
1304e92a4047SStephen Boyd 		vreg->ocp_count = 0;
1305e92a4047SStephen Boyd 
1306e92a4047SStephen Boyd 	/* Wait for switch output to settle back to 0 V after OCP triggered. */
1307e92a4047SStephen Boyd 	udelay(SPMI_VS_OCP_FALL_DELAY_US);
1308e92a4047SStephen Boyd 
1309e92a4047SStephen Boyd 	vreg->ocp_count++;
1310e92a4047SStephen Boyd 
1311e92a4047SStephen Boyd 	if (vreg->ocp_count == 1) {
1312e92a4047SStephen Boyd 		/* Immediately clear the over current condition. */
1313e92a4047SStephen Boyd 		spmi_regulator_vs_clear_ocp(vreg);
1314e92a4047SStephen Boyd 	} else if (vreg->ocp_count <= vreg->ocp_max_retries) {
1315e92a4047SStephen Boyd 		/* Schedule the over current clear task to run later. */
1316e92a4047SStephen Boyd 		schedule_delayed_work(&vreg->ocp_work,
1317e92a4047SStephen Boyd 			msecs_to_jiffies(vreg->ocp_retry_delay_ms) + 1);
1318e92a4047SStephen Boyd 	} else {
1319e92a4047SStephen Boyd 		dev_err(vreg->dev,
1320e92a4047SStephen Boyd 			"OCP triggered %d times; no further retries\n",
1321e92a4047SStephen Boyd 			vreg->ocp_count);
1322e92a4047SStephen Boyd 	}
1323e92a4047SStephen Boyd 
1324e92a4047SStephen Boyd 	return IRQ_HANDLED;
1325e92a4047SStephen Boyd }
1326e92a4047SStephen Boyd 
13270caecaa8SIlia Lin #define SAW3_VCTL_DATA_MASK	0xFF
13280caecaa8SIlia Lin #define SAW3_VCTL_CLEAR_MASK	0x700FF
13290caecaa8SIlia Lin #define SAW3_AVS_CTL_EN_MASK	0x1
13300caecaa8SIlia Lin #define SAW3_AVS_CTL_TGGL_MASK	0x8000000
13310caecaa8SIlia Lin #define SAW3_AVS_CTL_CLEAR_MASK	0x7efc00
13320caecaa8SIlia Lin 
13339689ca0aSNiklas Cassel static struct regmap *saw_regmap;
13340caecaa8SIlia Lin 
spmi_saw_set_vdd(void * data)13350caecaa8SIlia Lin static void spmi_saw_set_vdd(void *data)
13360caecaa8SIlia Lin {
13370caecaa8SIlia Lin 	u32 vctl, data3, avs_ctl, pmic_sts;
13380caecaa8SIlia Lin 	bool avs_enabled = false;
13390caecaa8SIlia Lin 	unsigned long timeout;
13400caecaa8SIlia Lin 	u8 voltage_sel = *(u8 *)data;
13410caecaa8SIlia Lin 
13420caecaa8SIlia Lin 	regmap_read(saw_regmap, SAW3_AVS_CTL, &avs_ctl);
13430caecaa8SIlia Lin 	regmap_read(saw_regmap, SAW3_VCTL, &vctl);
13440caecaa8SIlia Lin 	regmap_read(saw_regmap, SAW3_SPM_PMIC_DATA_3, &data3);
13450caecaa8SIlia Lin 
13460caecaa8SIlia Lin 	/* select the band */
13470caecaa8SIlia Lin 	vctl &= ~SAW3_VCTL_CLEAR_MASK;
13480caecaa8SIlia Lin 	vctl |= (u32)voltage_sel;
13490caecaa8SIlia Lin 
13500caecaa8SIlia Lin 	data3 &= ~SAW3_VCTL_CLEAR_MASK;
13510caecaa8SIlia Lin 	data3 |= (u32)voltage_sel;
13520caecaa8SIlia Lin 
13530caecaa8SIlia Lin 	/* If AVS is enabled, switch it off during the voltage change */
13540caecaa8SIlia Lin 	avs_enabled = SAW3_AVS_CTL_EN_MASK & avs_ctl;
13550caecaa8SIlia Lin 	if (avs_enabled) {
13560caecaa8SIlia Lin 		avs_ctl &= ~SAW3_AVS_CTL_TGGL_MASK;
13570caecaa8SIlia Lin 		regmap_write(saw_regmap, SAW3_AVS_CTL, avs_ctl);
13580caecaa8SIlia Lin 	}
13590caecaa8SIlia Lin 
13600caecaa8SIlia Lin 	regmap_write(saw_regmap, SAW3_RST, 1);
13610caecaa8SIlia Lin 	regmap_write(saw_regmap, SAW3_VCTL, vctl);
13620caecaa8SIlia Lin 	regmap_write(saw_regmap, SAW3_SPM_PMIC_DATA_3, data3);
13630caecaa8SIlia Lin 
13640caecaa8SIlia Lin 	timeout = jiffies + usecs_to_jiffies(100);
13650caecaa8SIlia Lin 	do {
13660caecaa8SIlia Lin 		regmap_read(saw_regmap, SAW3_PMIC_STS, &pmic_sts);
13670caecaa8SIlia Lin 		pmic_sts &= SAW3_VCTL_DATA_MASK;
13680caecaa8SIlia Lin 		if (pmic_sts == (u32)voltage_sel)
13690caecaa8SIlia Lin 			break;
13700caecaa8SIlia Lin 
13710caecaa8SIlia Lin 		cpu_relax();
13720caecaa8SIlia Lin 
13730caecaa8SIlia Lin 	} while (time_before(jiffies, timeout));
13740caecaa8SIlia Lin 
13750caecaa8SIlia Lin 	/* After successful voltage change, switch the AVS back on */
13760caecaa8SIlia Lin 	if (avs_enabled) {
13770caecaa8SIlia Lin 		pmic_sts &= 0x3f;
13780caecaa8SIlia Lin 		avs_ctl &= ~SAW3_AVS_CTL_CLEAR_MASK;
13790caecaa8SIlia Lin 		avs_ctl |= ((pmic_sts - 4) << 10);
13800caecaa8SIlia Lin 		avs_ctl |= (pmic_sts << 17);
13810caecaa8SIlia Lin 		avs_ctl |= SAW3_AVS_CTL_TGGL_MASK;
13820caecaa8SIlia Lin 		regmap_write(saw_regmap, SAW3_AVS_CTL, avs_ctl);
13830caecaa8SIlia Lin 	}
13840caecaa8SIlia Lin }
13850caecaa8SIlia Lin 
13860caecaa8SIlia Lin static int
spmi_regulator_saw_set_voltage(struct regulator_dev * rdev,unsigned selector)13870caecaa8SIlia Lin spmi_regulator_saw_set_voltage(struct regulator_dev *rdev, unsigned selector)
13880caecaa8SIlia Lin {
13890caecaa8SIlia Lin 	struct spmi_regulator *vreg = rdev_get_drvdata(rdev);
13900caecaa8SIlia Lin 	int ret;
13910caecaa8SIlia Lin 	u8 range_sel, voltage_sel;
13920caecaa8SIlia Lin 
13930caecaa8SIlia Lin 	ret = spmi_sw_selector_to_hw(vreg, selector, &range_sel, &voltage_sel);
13940caecaa8SIlia Lin 	if (ret)
13950caecaa8SIlia Lin 		return ret;
13960caecaa8SIlia Lin 
13970caecaa8SIlia Lin 	if (0 != range_sel) {
13980caecaa8SIlia Lin 		dev_dbg(&rdev->dev, "range_sel = %02X voltage_sel = %02X", \
13990caecaa8SIlia Lin 			range_sel, voltage_sel);
14000caecaa8SIlia Lin 		return -EINVAL;
14010caecaa8SIlia Lin 	}
14020caecaa8SIlia Lin 
14030caecaa8SIlia Lin 	/* Always do the SAW register writes on the first CPU */
14040caecaa8SIlia Lin 	return smp_call_function_single(0, spmi_saw_set_vdd, \
14050caecaa8SIlia Lin 					&voltage_sel, true);
14060caecaa8SIlia Lin }
14070caecaa8SIlia Lin 
14080caecaa8SIlia Lin static struct regulator_ops spmi_saw_ops = {};
14090caecaa8SIlia Lin 
14103b619e3eSRikard Falkeborn static const struct regulator_ops spmi_smps_ops = {
14119d485332SAxel Lin 	.enable			= regulator_enable_regmap,
14129d485332SAxel Lin 	.disable		= regulator_disable_regmap,
14139d485332SAxel Lin 	.is_enabled		= regulator_is_enabled_regmap,
14141b5b1968SStephen Boyd 	.set_voltage_sel	= spmi_regulator_common_set_voltage,
14152cf7b99cSStephen Boyd 	.set_voltage_time_sel	= spmi_regulator_set_voltage_time_sel,
14161b5b1968SStephen Boyd 	.get_voltage_sel	= spmi_regulator_common_get_voltage,
14171b5b1968SStephen Boyd 	.map_voltage		= spmi_regulator_common_map_voltage,
1418e92a4047SStephen Boyd 	.list_voltage		= spmi_regulator_common_list_voltage,
1419e92a4047SStephen Boyd 	.set_mode		= spmi_regulator_common_set_mode,
1420e92a4047SStephen Boyd 	.get_mode		= spmi_regulator_common_get_mode,
1421e92a4047SStephen Boyd 	.set_load		= spmi_regulator_common_set_load,
1422e92a4047SStephen Boyd 	.set_pull_down		= spmi_regulator_common_set_pull_down,
1423e92a4047SStephen Boyd };
1424e92a4047SStephen Boyd 
14253b619e3eSRikard Falkeborn static const struct regulator_ops spmi_ldo_ops = {
14269d485332SAxel Lin 	.enable			= regulator_enable_regmap,
14279d485332SAxel Lin 	.disable		= regulator_disable_regmap,
14289d485332SAxel Lin 	.is_enabled		= regulator_is_enabled_regmap,
14291b5b1968SStephen Boyd 	.set_voltage_sel	= spmi_regulator_common_set_voltage,
14301b5b1968SStephen Boyd 	.get_voltage_sel	= spmi_regulator_common_get_voltage,
14311b5b1968SStephen Boyd 	.map_voltage		= spmi_regulator_common_map_voltage,
1432e92a4047SStephen Boyd 	.list_voltage		= spmi_regulator_common_list_voltage,
1433e92a4047SStephen Boyd 	.set_mode		= spmi_regulator_common_set_mode,
1434e92a4047SStephen Boyd 	.get_mode		= spmi_regulator_common_get_mode,
1435e92a4047SStephen Boyd 	.set_load		= spmi_regulator_common_set_load,
1436e92a4047SStephen Boyd 	.set_bypass		= spmi_regulator_common_set_bypass,
1437e92a4047SStephen Boyd 	.get_bypass		= spmi_regulator_common_get_bypass,
1438e92a4047SStephen Boyd 	.set_pull_down		= spmi_regulator_common_set_pull_down,
1439e92a4047SStephen Boyd 	.set_soft_start		= spmi_regulator_common_set_soft_start,
1440e92a4047SStephen Boyd };
1441e92a4047SStephen Boyd 
14423b619e3eSRikard Falkeborn static const struct regulator_ops spmi_ln_ldo_ops = {
14439d485332SAxel Lin 	.enable			= regulator_enable_regmap,
14449d485332SAxel Lin 	.disable		= regulator_disable_regmap,
14459d485332SAxel Lin 	.is_enabled		= regulator_is_enabled_regmap,
14461b5b1968SStephen Boyd 	.set_voltage_sel	= spmi_regulator_common_set_voltage,
14471b5b1968SStephen Boyd 	.get_voltage_sel	= spmi_regulator_common_get_voltage,
14481b5b1968SStephen Boyd 	.map_voltage		= spmi_regulator_common_map_voltage,
1449e92a4047SStephen Boyd 	.list_voltage		= spmi_regulator_common_list_voltage,
1450e92a4047SStephen Boyd 	.set_bypass		= spmi_regulator_common_set_bypass,
1451e92a4047SStephen Boyd 	.get_bypass		= spmi_regulator_common_get_bypass,
1452e92a4047SStephen Boyd };
1453e92a4047SStephen Boyd 
14543b619e3eSRikard Falkeborn static const struct regulator_ops spmi_vs_ops = {
1455e92a4047SStephen Boyd 	.enable			= spmi_regulator_vs_enable,
14569d485332SAxel Lin 	.disable		= regulator_disable_regmap,
14579d485332SAxel Lin 	.is_enabled		= regulator_is_enabled_regmap,
1458e92a4047SStephen Boyd 	.set_pull_down		= spmi_regulator_common_set_pull_down,
1459e92a4047SStephen Boyd 	.set_soft_start		= spmi_regulator_common_set_soft_start,
1460e2adfacdSStephen Boyd 	.set_over_current_protection = spmi_regulator_vs_ocp,
1461919163f6SStephen Boyd 	.set_mode		= spmi_regulator_common_set_mode,
1462919163f6SStephen Boyd 	.get_mode		= spmi_regulator_common_get_mode,
1463e92a4047SStephen Boyd };
1464e92a4047SStephen Boyd 
14653b619e3eSRikard Falkeborn static const struct regulator_ops spmi_boost_ops = {
14669d485332SAxel Lin 	.enable			= regulator_enable_regmap,
14679d485332SAxel Lin 	.disable		= regulator_disable_regmap,
14689d485332SAxel Lin 	.is_enabled		= regulator_is_enabled_regmap,
14691b5b1968SStephen Boyd 	.set_voltage_sel	= spmi_regulator_single_range_set_voltage,
14701b5b1968SStephen Boyd 	.get_voltage_sel	= spmi_regulator_single_range_get_voltage,
14711b5b1968SStephen Boyd 	.map_voltage		= spmi_regulator_single_map_voltage,
1472e92a4047SStephen Boyd 	.list_voltage		= spmi_regulator_common_list_voltage,
1473e92a4047SStephen Boyd 	.set_input_current_limit = spmi_regulator_set_ilim,
1474e92a4047SStephen Boyd };
1475e92a4047SStephen Boyd 
14763b619e3eSRikard Falkeborn static const struct regulator_ops spmi_ftsmps_ops = {
14779d485332SAxel Lin 	.enable			= regulator_enable_regmap,
14789d485332SAxel Lin 	.disable		= regulator_disable_regmap,
14799d485332SAxel Lin 	.is_enabled		= regulator_is_enabled_regmap,
14801b5b1968SStephen Boyd 	.set_voltage_sel	= spmi_regulator_common_set_voltage,
1481e92a4047SStephen Boyd 	.set_voltage_time_sel	= spmi_regulator_set_voltage_time_sel,
14821b5b1968SStephen Boyd 	.get_voltage_sel	= spmi_regulator_common_get_voltage,
14831b5b1968SStephen Boyd 	.map_voltage		= spmi_regulator_common_map_voltage,
1484e92a4047SStephen Boyd 	.list_voltage		= spmi_regulator_common_list_voltage,
1485e92a4047SStephen Boyd 	.set_mode		= spmi_regulator_common_set_mode,
1486e92a4047SStephen Boyd 	.get_mode		= spmi_regulator_common_get_mode,
1487e92a4047SStephen Boyd 	.set_load		= spmi_regulator_common_set_load,
1488e92a4047SStephen Boyd 	.set_pull_down		= spmi_regulator_common_set_pull_down,
1489e92a4047SStephen Boyd };
1490e92a4047SStephen Boyd 
14913b619e3eSRikard Falkeborn static const struct regulator_ops spmi_ult_lo_smps_ops = {
14929d485332SAxel Lin 	.enable			= regulator_enable_regmap,
14939d485332SAxel Lin 	.disable		= regulator_disable_regmap,
14949d485332SAxel Lin 	.is_enabled		= regulator_is_enabled_regmap,
14951b5b1968SStephen Boyd 	.set_voltage_sel	= spmi_regulator_ult_lo_smps_set_voltage,
14962cf7b99cSStephen Boyd 	.set_voltage_time_sel	= spmi_regulator_set_voltage_time_sel,
14971b5b1968SStephen Boyd 	.get_voltage_sel	= spmi_regulator_ult_lo_smps_get_voltage,
1498e92a4047SStephen Boyd 	.list_voltage		= spmi_regulator_common_list_voltage,
1499e92a4047SStephen Boyd 	.set_mode		= spmi_regulator_common_set_mode,
1500e92a4047SStephen Boyd 	.get_mode		= spmi_regulator_common_get_mode,
1501e92a4047SStephen Boyd 	.set_load		= spmi_regulator_common_set_load,
1502e92a4047SStephen Boyd 	.set_pull_down		= spmi_regulator_common_set_pull_down,
1503e92a4047SStephen Boyd };
1504e92a4047SStephen Boyd 
15053b619e3eSRikard Falkeborn static const struct regulator_ops spmi_ult_ho_smps_ops = {
15069d485332SAxel Lin 	.enable			= regulator_enable_regmap,
15079d485332SAxel Lin 	.disable		= regulator_disable_regmap,
15089d485332SAxel Lin 	.is_enabled		= regulator_is_enabled_regmap,
15091b5b1968SStephen Boyd 	.set_voltage_sel	= spmi_regulator_single_range_set_voltage,
15102cf7b99cSStephen Boyd 	.set_voltage_time_sel	= spmi_regulator_set_voltage_time_sel,
15111b5b1968SStephen Boyd 	.get_voltage_sel	= spmi_regulator_single_range_get_voltage,
15121b5b1968SStephen Boyd 	.map_voltage		= spmi_regulator_single_map_voltage,
1513e92a4047SStephen Boyd 	.list_voltage		= spmi_regulator_common_list_voltage,
1514e92a4047SStephen Boyd 	.set_mode		= spmi_regulator_common_set_mode,
1515e92a4047SStephen Boyd 	.get_mode		= spmi_regulator_common_get_mode,
1516e92a4047SStephen Boyd 	.set_load		= spmi_regulator_common_set_load,
1517e92a4047SStephen Boyd 	.set_pull_down		= spmi_regulator_common_set_pull_down,
1518e92a4047SStephen Boyd };
1519e92a4047SStephen Boyd 
15203b619e3eSRikard Falkeborn static const struct regulator_ops spmi_ult_ldo_ops = {
15219d485332SAxel Lin 	.enable			= regulator_enable_regmap,
15229d485332SAxel Lin 	.disable		= regulator_disable_regmap,
15239d485332SAxel Lin 	.is_enabled		= regulator_is_enabled_regmap,
15241b5b1968SStephen Boyd 	.set_voltage_sel	= spmi_regulator_single_range_set_voltage,
15251b5b1968SStephen Boyd 	.get_voltage_sel	= spmi_regulator_single_range_get_voltage,
15261b5b1968SStephen Boyd 	.map_voltage		= spmi_regulator_single_map_voltage,
1527e92a4047SStephen Boyd 	.list_voltage		= spmi_regulator_common_list_voltage,
1528e92a4047SStephen Boyd 	.set_mode		= spmi_regulator_common_set_mode,
1529e92a4047SStephen Boyd 	.get_mode		= spmi_regulator_common_get_mode,
1530e92a4047SStephen Boyd 	.set_load		= spmi_regulator_common_set_load,
1531e92a4047SStephen Boyd 	.set_bypass		= spmi_regulator_common_set_bypass,
1532e92a4047SStephen Boyd 	.get_bypass		= spmi_regulator_common_get_bypass,
1533e92a4047SStephen Boyd 	.set_pull_down		= spmi_regulator_common_set_pull_down,
1534e92a4047SStephen Boyd 	.set_soft_start		= spmi_regulator_common_set_soft_start,
1535e92a4047SStephen Boyd };
1536e92a4047SStephen Boyd 
15373b619e3eSRikard Falkeborn static const struct regulator_ops spmi_ftsmps426_ops = {
153842ba89c8SJeffrey Hugo 	.enable			= regulator_enable_regmap,
153942ba89c8SJeffrey Hugo 	.disable		= regulator_disable_regmap,
154042ba89c8SJeffrey Hugo 	.is_enabled		= regulator_is_enabled_regmap,
154142ba89c8SJeffrey Hugo 	.set_voltage_sel	= spmi_regulator_ftsmps426_set_voltage,
154242ba89c8SJeffrey Hugo 	.set_voltage_time_sel	= spmi_regulator_set_voltage_time_sel,
154342ba89c8SJeffrey Hugo 	.get_voltage_sel	= spmi_regulator_ftsmps426_get_voltage,
154442ba89c8SJeffrey Hugo 	.map_voltage		= spmi_regulator_single_map_voltage,
154542ba89c8SJeffrey Hugo 	.list_voltage		= spmi_regulator_common_list_voltage,
154642ba89c8SJeffrey Hugo 	.set_mode		= spmi_regulator_ftsmps426_set_mode,
154742ba89c8SJeffrey Hugo 	.get_mode		= spmi_regulator_ftsmps426_get_mode,
154842ba89c8SJeffrey Hugo 	.set_load		= spmi_regulator_common_set_load,
154942ba89c8SJeffrey Hugo 	.set_pull_down		= spmi_regulator_common_set_pull_down,
155042ba89c8SJeffrey Hugo };
155142ba89c8SJeffrey Hugo 
15523b619e3eSRikard Falkeborn static const struct regulator_ops spmi_hfs430_ops = {
15530211f68eSJorge Ramirez 	.enable			= regulator_enable_regmap,
15540211f68eSJorge Ramirez 	.disable		= regulator_disable_regmap,
15550211f68eSJorge Ramirez 	.is_enabled		= regulator_is_enabled_regmap,
15560211f68eSJorge Ramirez 	.set_voltage_sel	= spmi_regulator_ftsmps426_set_voltage,
15570211f68eSJorge Ramirez 	.set_voltage_time_sel	= spmi_regulator_set_voltage_time_sel,
15580211f68eSJorge Ramirez 	.get_voltage_sel	= spmi_regulator_ftsmps426_get_voltage,
15590211f68eSJorge Ramirez 	.map_voltage		= spmi_regulator_single_map_voltage,
15600211f68eSJorge Ramirez 	.list_voltage		= spmi_regulator_common_list_voltage,
15610211f68eSJorge Ramirez 	.set_mode		= spmi_regulator_ftsmps426_set_mode,
15620211f68eSJorge Ramirez 	.get_mode		= spmi_regulator_ftsmps426_get_mode,
15630211f68eSJorge Ramirez };
15640211f68eSJorge Ramirez 
156527850254SIskren Chernev static const struct regulator_ops spmi_hfsmps_ops = {
156627850254SIskren Chernev 	.enable			= regulator_enable_regmap,
156727850254SIskren Chernev 	.disable		= regulator_disable_regmap,
156827850254SIskren Chernev 	.is_enabled		= regulator_is_enabled_regmap,
156927850254SIskren Chernev 	.set_voltage_sel	= spmi_regulator_ftsmps426_set_voltage,
157027850254SIskren Chernev 	.set_voltage_time_sel	= spmi_regulator_set_voltage_time_sel,
157127850254SIskren Chernev 	.get_voltage_sel	= spmi_regulator_ftsmps426_get_voltage,
157227850254SIskren Chernev 	.map_voltage		= spmi_regulator_single_map_voltage,
157327850254SIskren Chernev 	.list_voltage		= spmi_regulator_common_list_voltage,
157427850254SIskren Chernev 	.set_mode		= spmi_regulator_hfsmps_set_mode,
157527850254SIskren Chernev 	.get_mode		= spmi_regulator_hfsmps_get_mode,
157627850254SIskren Chernev 	.set_load		= spmi_regulator_common_set_load,
157727850254SIskren Chernev 	.set_pull_down		= spmi_regulator_hfsmps_set_pull_down,
157827850254SIskren Chernev };
157927850254SIskren Chernev 
1580e92a4047SStephen Boyd /* Maximum possible digital major revision value */
1581e92a4047SStephen Boyd #define INF 0xFF
1582e92a4047SStephen Boyd 
1583e92a4047SStephen Boyd static const struct spmi_regulator_mapping supported_regulators[] = {
1584e92a4047SStephen Boyd 	/*           type subtype dig_min dig_max ltype ops setpoints hpm_min */
15853d04ae8eSRobert Marko 	SPMI_VREG(LDO,   HT_P600,  0, INF, HFS430, hfs430, ht_p600, 10000),
158600f6ebbdSRobert Marko 	SPMI_VREG(LDO,   HT_P150,  0, INF, HFS430, hfs430, ht_p150, 10000),
1587e92a4047SStephen Boyd 	SPMI_VREG(BUCK,  GP_CTL,   0, INF, SMPS,   smps,   smps,   100000),
158827850254SIskren Chernev 	SPMI_VREG(BUCK,  HFS430,   0,   3, HFS430, hfs430, hfs430,  10000),
158927850254SIskren Chernev 	SPMI_VREG(BUCK,  HFSMPS_510, 4, INF, HFSMPS, hfsmps, hfs430, 100000),
1590e92a4047SStephen Boyd 	SPMI_VREG(LDO,   N300,     0, INF, LDO,    ldo,    nldo1,   10000),
1591e92a4047SStephen Boyd 	SPMI_VREG(LDO,   N600,     0,   0, LDO,    ldo,    nldo2,   10000),
1592e92a4047SStephen Boyd 	SPMI_VREG(LDO,   N1200,    0,   0, LDO,    ldo,    nldo2,   10000),
1593e92a4047SStephen Boyd 	SPMI_VREG(LDO,   N600,     1, INF, LDO,    ldo,    nldo3,   10000),
1594e92a4047SStephen Boyd 	SPMI_VREG(LDO,   N1200,    1, INF, LDO,    ldo,    nldo3,   10000),
1595e92a4047SStephen Boyd 	SPMI_VREG(LDO,   N600_ST,  0,   0, LDO,    ldo,    nldo2,   10000),
1596e92a4047SStephen Boyd 	SPMI_VREG(LDO,   N1200_ST, 0,   0, LDO,    ldo,    nldo2,   10000),
1597e92a4047SStephen Boyd 	SPMI_VREG(LDO,   N600_ST,  1, INF, LDO,    ldo,    nldo3,   10000),
1598e92a4047SStephen Boyd 	SPMI_VREG(LDO,   N1200_ST, 1, INF, LDO,    ldo,    nldo3,   10000),
1599e92a4047SStephen Boyd 	SPMI_VREG(LDO,   P50,      0, INF, LDO,    ldo,    pldo,     5000),
1600e92a4047SStephen Boyd 	SPMI_VREG(LDO,   P150,     0, INF, LDO,    ldo,    pldo,    10000),
1601e92a4047SStephen Boyd 	SPMI_VREG(LDO,   P300,     0, INF, LDO,    ldo,    pldo,    10000),
1602e92a4047SStephen Boyd 	SPMI_VREG(LDO,   P600,     0, INF, LDO,    ldo,    pldo,    10000),
1603e92a4047SStephen Boyd 	SPMI_VREG(LDO,   P1200,    0, INF, LDO,    ldo,    pldo,    10000),
1604e92a4047SStephen Boyd 	SPMI_VREG(LDO,   LN,       0, INF, LN_LDO, ln_ldo, ln_ldo,      0),
1605e92a4047SStephen Boyd 	SPMI_VREG(LDO,   LV_P50,   0, INF, LDO,    ldo,    pldo,     5000),
1606e92a4047SStephen Boyd 	SPMI_VREG(LDO,   LV_P150,  0, INF, LDO,    ldo,    pldo,    10000),
1607e92a4047SStephen Boyd 	SPMI_VREG(LDO,   LV_P300,  0, INF, LDO,    ldo,    pldo,    10000),
1608e92a4047SStephen Boyd 	SPMI_VREG(LDO,   LV_P600,  0, INF, LDO,    ldo,    pldo,    10000),
1609e92a4047SStephen Boyd 	SPMI_VREG(LDO,   LV_P1200, 0, INF, LDO,    ldo,    pldo,    10000),
1610328816c2SAngeloGioacchino Del Regno 	SPMI_VREG(LDO, HT_N300_ST,   0, INF, FTSMPS426, ftsmps426,
1611328816c2SAngeloGioacchino Del Regno 							ht_nldo,   30000),
1612328816c2SAngeloGioacchino Del Regno 	SPMI_VREG(LDO, HT_N600_ST,   0, INF, FTSMPS426, ftsmps426,
1613328816c2SAngeloGioacchino Del Regno 							ht_nldo,   30000),
1614328816c2SAngeloGioacchino Del Regno 	SPMI_VREG(LDO, HT_N1200_ST,  0, INF, FTSMPS426, ftsmps426,
1615328816c2SAngeloGioacchino Del Regno 							ht_nldo,   30000),
1616328816c2SAngeloGioacchino Del Regno 	SPMI_VREG(LDO, HT_LVP150,    0, INF, FTSMPS426, ftsmps426,
1617328816c2SAngeloGioacchino Del Regno 							ht_lvpldo, 10000),
1618328816c2SAngeloGioacchino Del Regno 	SPMI_VREG(LDO, HT_LVP300,    0, INF, FTSMPS426, ftsmps426,
1619328816c2SAngeloGioacchino Del Regno 							ht_lvpldo, 10000),
1620328816c2SAngeloGioacchino Del Regno 	SPMI_VREG(LDO, L660_N300_ST, 0, INF, FTSMPS426, ftsmps426,
1621328816c2SAngeloGioacchino Del Regno 							nldo660,   10000),
1622328816c2SAngeloGioacchino Del Regno 	SPMI_VREG(LDO, L660_N600_ST, 0, INF, FTSMPS426, ftsmps426,
1623328816c2SAngeloGioacchino Del Regno 							nldo660,   10000),
1624328816c2SAngeloGioacchino Del Regno 	SPMI_VREG(LDO, L660_P50,     0, INF, FTSMPS426, ftsmps426,
1625328816c2SAngeloGioacchino Del Regno 							pldo660,   10000),
1626328816c2SAngeloGioacchino Del Regno 	SPMI_VREG(LDO, L660_P150,    0, INF, FTSMPS426, ftsmps426,
1627328816c2SAngeloGioacchino Del Regno 							pldo660,   10000),
1628328816c2SAngeloGioacchino Del Regno 	SPMI_VREG(LDO, L660_P600,    0, INF, FTSMPS426, ftsmps426,
1629328816c2SAngeloGioacchino Del Regno 							pldo660,   10000),
1630328816c2SAngeloGioacchino Del Regno 	SPMI_VREG(LDO, L660_LVP150,  0, INF, FTSMPS426, ftsmps426,
1631328816c2SAngeloGioacchino Del Regno 							ht_lvpldo, 10000),
1632328816c2SAngeloGioacchino Del Regno 	SPMI_VREG(LDO, L660_LVP600,  0, INF, FTSMPS426, ftsmps426,
1633328816c2SAngeloGioacchino Del Regno 							ht_lvpldo, 10000),
1634e92a4047SStephen Boyd 	SPMI_VREG_VS(LV100,        0, INF),
1635e92a4047SStephen Boyd 	SPMI_VREG_VS(LV300,        0, INF),
1636e92a4047SStephen Boyd 	SPMI_VREG_VS(MV300,        0, INF),
1637e92a4047SStephen Boyd 	SPMI_VREG_VS(MV500,        0, INF),
1638e92a4047SStephen Boyd 	SPMI_VREG_VS(HDMI,         0, INF),
1639e92a4047SStephen Boyd 	SPMI_VREG_VS(OTG,          0, INF),
1640e92a4047SStephen Boyd 	SPMI_VREG(BOOST, 5V_BOOST, 0, INF, BOOST,  boost,  boost,       0),
1641e92a4047SStephen Boyd 	SPMI_VREG(FTS,   FTS_CTL,  0, INF, FTSMPS, ftsmps, ftsmps, 100000),
1642e92a4047SStephen Boyd 	SPMI_VREG(FTS, FTS2p5_CTL, 0, INF, FTSMPS, ftsmps, ftsmps2p5, 100000),
164342ba89c8SJeffrey Hugo 	SPMI_VREG(FTS, FTS426_CTL, 0, INF, FTSMPS426, ftsmps426, ftsmps426, 100000),
1644e92a4047SStephen Boyd 	SPMI_VREG(BOOST_BYP, BB_2A, 0, INF, BOOST_BYP, boost, boost_byp, 0),
1645e92a4047SStephen Boyd 	SPMI_VREG(ULT_BUCK, ULT_HF_CTL1, 0, INF, ULT_LO_SMPS, ult_lo_smps,
1646e92a4047SStephen Boyd 						ult_lo_smps,   100000),
1647e92a4047SStephen Boyd 	SPMI_VREG(ULT_BUCK, ULT_HF_CTL2, 0, INF, ULT_LO_SMPS, ult_lo_smps,
1648e92a4047SStephen Boyd 						ult_lo_smps,   100000),
1649e92a4047SStephen Boyd 	SPMI_VREG(ULT_BUCK, ULT_HF_CTL3, 0, INF, ULT_LO_SMPS, ult_lo_smps,
1650e92a4047SStephen Boyd 						ult_lo_smps,   100000),
1651e92a4047SStephen Boyd 	SPMI_VREG(ULT_BUCK, ULT_HF_CTL4, 0, INF, ULT_HO_SMPS, ult_ho_smps,
1652e92a4047SStephen Boyd 						ult_ho_smps,   100000),
1653e92a4047SStephen Boyd 	SPMI_VREG(ULT_LDO, N300_ST, 0, INF, ULT_LDO, ult_ldo, ult_nldo, 10000),
1654e92a4047SStephen Boyd 	SPMI_VREG(ULT_LDO, N600_ST, 0, INF, ULT_LDO, ult_ldo, ult_nldo, 10000),
1655e92a4047SStephen Boyd 	SPMI_VREG(ULT_LDO, N900_ST, 0, INF, ULT_LDO, ult_ldo, ult_nldo, 10000),
1656e92a4047SStephen Boyd 	SPMI_VREG(ULT_LDO, N1200_ST, 0, INF, ULT_LDO, ult_ldo, ult_nldo, 10000),
1657438421b0SAngeloGioacchino Del Regno 	SPMI_VREG(ULT_LDO, LV_P50,   0, INF, ULT_LDO, ult_ldo, ult_pldo, 10000),
1658e92a4047SStephen Boyd 	SPMI_VREG(ULT_LDO, LV_P150,  0, INF, ULT_LDO, ult_ldo, ult_pldo, 10000),
1659e92a4047SStephen Boyd 	SPMI_VREG(ULT_LDO, LV_P300,  0, INF, ULT_LDO, ult_ldo, ult_pldo, 10000),
1660e92a4047SStephen Boyd 	SPMI_VREG(ULT_LDO, LV_P450,  0, INF, ULT_LDO, ult_ldo, ult_pldo, 10000),
1661e92a4047SStephen Boyd 	SPMI_VREG(ULT_LDO, P600,     0, INF, ULT_LDO, ult_ldo, ult_pldo, 10000),
1662438421b0SAngeloGioacchino Del Regno 	SPMI_VREG(ULT_LDO, P300,     0, INF, ULT_LDO, ult_ldo, ult_pldo, 10000),
1663e92a4047SStephen Boyd 	SPMI_VREG(ULT_LDO, P150,     0, INF, ULT_LDO, ult_ldo, ult_pldo, 10000),
1664e92a4047SStephen Boyd 	SPMI_VREG(ULT_LDO, P50,     0, INF, ULT_LDO, ult_ldo, ult_pldo, 5000),
16650d1cf568SIskren Chernev 	SPMI_VREG(LDO, LV_P150_510, 0, INF, LDO_510, hfsmps, ht_lvpldo, 10000),
16660d1cf568SIskren Chernev 	SPMI_VREG(LDO, LV_P300_510, 0, INF, LDO_510, hfsmps, ht_lvpldo, 10000),
16670d1cf568SIskren Chernev 	SPMI_VREG(LDO, LV_P600_510, 0, INF, LDO_510, hfsmps, ht_lvpldo, 10000),
16680d1cf568SIskren Chernev 	SPMI_VREG(LDO, MV_P50_510,  0, INF, LDO_510, hfsmps, pldo660, 10000),
16690d1cf568SIskren Chernev 	SPMI_VREG(LDO, MV_P150_510, 0, INF, LDO_510, hfsmps, pldo660, 10000),
16700d1cf568SIskren Chernev 	SPMI_VREG(LDO, MV_P600_510, 0, INF, LDO_510, hfsmps, pldo660, 10000),
16710d1cf568SIskren Chernev 	SPMI_VREG(LDO, N300_510,    0, INF, LDO_510, hfsmps, nldo_510, 10000),
16720d1cf568SIskren Chernev 	SPMI_VREG(LDO, N600_510,    0, INF, LDO_510, hfsmps, nldo_510, 10000),
16730d1cf568SIskren Chernev 	SPMI_VREG(LDO, N1200_510,   0, INF, LDO_510, hfsmps, nldo_510, 10000),
16740d1cf568SIskren Chernev 	SPMI_VREG(FTS, FTSMPS_510,  0, INF, FTSMPS3, hfsmps, ftsmps510, 100000),
1675e92a4047SStephen Boyd };
1676e92a4047SStephen Boyd 
spmi_calculate_num_voltages(struct spmi_voltage_set_points * points)1677e92a4047SStephen Boyd static void spmi_calculate_num_voltages(struct spmi_voltage_set_points *points)
1678e92a4047SStephen Boyd {
1679e92a4047SStephen Boyd 	unsigned int n;
1680e92a4047SStephen Boyd 	struct spmi_voltage_range *range = points->range;
1681e92a4047SStephen Boyd 
1682e92a4047SStephen Boyd 	for (; range < points->range + points->count; range++) {
1683e92a4047SStephen Boyd 		n = 0;
1684e92a4047SStephen Boyd 		if (range->set_point_max_uV) {
1685e92a4047SStephen Boyd 			n = range->set_point_max_uV - range->set_point_min_uV;
1686419d06a1SAxel Lin 			n = (n / range->step_uV) + 1;
1687e92a4047SStephen Boyd 		}
1688e92a4047SStephen Boyd 		range->n_voltages = n;
1689e92a4047SStephen Boyd 		points->n_voltages += n;
1690e92a4047SStephen Boyd 	}
1691e92a4047SStephen Boyd }
1692e92a4047SStephen Boyd 
spmi_regulator_match(struct spmi_regulator * vreg,u16 force_type)1693e92a4047SStephen Boyd static int spmi_regulator_match(struct spmi_regulator *vreg, u16 force_type)
1694e92a4047SStephen Boyd {
1695e92a4047SStephen Boyd 	const struct spmi_regulator_mapping *mapping;
1696e92a4047SStephen Boyd 	int ret, i;
1697e92a4047SStephen Boyd 	u32 dig_major_rev;
1698e92a4047SStephen Boyd 	u8 version[SPMI_COMMON_REG_SUBTYPE - SPMI_COMMON_REG_DIG_MAJOR_REV + 1];
1699e92a4047SStephen Boyd 	u8 type, subtype;
1700e92a4047SStephen Boyd 
1701e92a4047SStephen Boyd 	ret = spmi_vreg_read(vreg, SPMI_COMMON_REG_DIG_MAJOR_REV, version,
1702e92a4047SStephen Boyd 		ARRAY_SIZE(version));
1703e92a4047SStephen Boyd 	if (ret) {
17046ee5c044SStephen Boyd 		dev_dbg(vreg->dev, "could not read version registers\n");
1705e92a4047SStephen Boyd 		return ret;
1706e92a4047SStephen Boyd 	}
1707e92a4047SStephen Boyd 	dig_major_rev	= version[SPMI_COMMON_REG_DIG_MAJOR_REV
1708e92a4047SStephen Boyd 					- SPMI_COMMON_REG_DIG_MAJOR_REV];
17090caecaa8SIlia Lin 
1710e92a4047SStephen Boyd 	if (!force_type) {
1711e92a4047SStephen Boyd 		type		= version[SPMI_COMMON_REG_TYPE -
1712e92a4047SStephen Boyd 					  SPMI_COMMON_REG_DIG_MAJOR_REV];
1713e92a4047SStephen Boyd 		subtype		= version[SPMI_COMMON_REG_SUBTYPE -
1714e92a4047SStephen Boyd 					  SPMI_COMMON_REG_DIG_MAJOR_REV];
1715e92a4047SStephen Boyd 	} else {
1716e92a4047SStephen Boyd 		type = force_type >> 8;
1717e92a4047SStephen Boyd 		subtype = force_type;
1718e92a4047SStephen Boyd 	}
1719e92a4047SStephen Boyd 
1720e92a4047SStephen Boyd 	for (i = 0; i < ARRAY_SIZE(supported_regulators); i++) {
1721e92a4047SStephen Boyd 		mapping = &supported_regulators[i];
1722e92a4047SStephen Boyd 		if (mapping->type == type && mapping->subtype == subtype
1723e92a4047SStephen Boyd 		    && mapping->revision_min <= dig_major_rev
1724e92a4047SStephen Boyd 		    && mapping->revision_max >= dig_major_rev)
1725e92a4047SStephen Boyd 			goto found;
1726e92a4047SStephen Boyd 	}
1727e92a4047SStephen Boyd 
1728e92a4047SStephen Boyd 	dev_err(vreg->dev,
1729e92a4047SStephen Boyd 		"unsupported regulator: name=%s type=0x%02X, subtype=0x%02X, dig major rev=0x%02X\n",
1730e92a4047SStephen Boyd 		vreg->desc.name, type, subtype, dig_major_rev);
1731e92a4047SStephen Boyd 
1732e92a4047SStephen Boyd 	return -ENODEV;
1733e92a4047SStephen Boyd 
1734e92a4047SStephen Boyd found:
1735e92a4047SStephen Boyd 	vreg->logical_type	= mapping->logical_type;
1736e92a4047SStephen Boyd 	vreg->set_points	= mapping->set_points;
1737e92a4047SStephen Boyd 	vreg->hpm_min_load	= mapping->hpm_min_load;
1738e92a4047SStephen Boyd 	vreg->desc.ops		= mapping->ops;
1739e92a4047SStephen Boyd 
1740e92a4047SStephen Boyd 	if (mapping->set_points) {
1741e92a4047SStephen Boyd 		if (!mapping->set_points->n_voltages)
1742e92a4047SStephen Boyd 			spmi_calculate_num_voltages(mapping->set_points);
1743e92a4047SStephen Boyd 		vreg->desc.n_voltages = mapping->set_points->n_voltages;
1744e92a4047SStephen Boyd 	}
1745e92a4047SStephen Boyd 
1746e92a4047SStephen Boyd 	return 0;
1747e92a4047SStephen Boyd }
1748e92a4047SStephen Boyd 
spmi_regulator_init_slew_rate(struct spmi_regulator * vreg)17492cf7b99cSStephen Boyd static int spmi_regulator_init_slew_rate(struct spmi_regulator *vreg)
1750e92a4047SStephen Boyd {
1751e92a4047SStephen Boyd 	int ret;
1752e92a4047SStephen Boyd 	u8 reg = 0;
17532cf7b99cSStephen Boyd 	int step, delay, slew_rate, step_delay;
1754e92a4047SStephen Boyd 	const struct spmi_voltage_range *range;
1755e92a4047SStephen Boyd 
1756e92a4047SStephen Boyd 	ret = spmi_vreg_read(vreg, SPMI_COMMON_REG_STEP_CTRL, &reg, 1);
1757e92a4047SStephen Boyd 	if (ret) {
1758e92a4047SStephen Boyd 		dev_err(vreg->dev, "spmi read failed, ret=%d\n", ret);
1759e92a4047SStephen Boyd 		return ret;
1760e92a4047SStephen Boyd 	}
1761e92a4047SStephen Boyd 
1762e92a4047SStephen Boyd 	range = spmi_regulator_find_range(vreg);
1763e92a4047SStephen Boyd 	if (!range)
1764e92a4047SStephen Boyd 		return -EINVAL;
1765e92a4047SStephen Boyd 
17662cf7b99cSStephen Boyd 	switch (vreg->logical_type) {
17672cf7b99cSStephen Boyd 	case SPMI_REGULATOR_LOGICAL_TYPE_FTSMPS:
17682cf7b99cSStephen Boyd 		step_delay = SPMI_FTSMPS_STEP_DELAY;
17692cf7b99cSStephen Boyd 		break;
17702cf7b99cSStephen Boyd 	default:
17712cf7b99cSStephen Boyd 		step_delay = SPMI_DEFAULT_STEP_DELAY;
17722cf7b99cSStephen Boyd 		break;
17732cf7b99cSStephen Boyd 	}
17742cf7b99cSStephen Boyd 
1775e92a4047SStephen Boyd 	step = reg & SPMI_FTSMPS_STEP_CTRL_STEP_MASK;
1776e92a4047SStephen Boyd 	step >>= SPMI_FTSMPS_STEP_CTRL_STEP_SHIFT;
1777e92a4047SStephen Boyd 
1778e92a4047SStephen Boyd 	delay = reg & SPMI_FTSMPS_STEP_CTRL_DELAY_MASK;
1779e92a4047SStephen Boyd 	delay >>= SPMI_FTSMPS_STEP_CTRL_DELAY_SHIFT;
1780e92a4047SStephen Boyd 
1781e92a4047SStephen Boyd 	/* slew_rate has units of uV/us */
1782e92a4047SStephen Boyd 	slew_rate = SPMI_FTSMPS_CLOCK_RATE * range->step_uV * (1 << step);
17832cf7b99cSStephen Boyd 	slew_rate /= 1000 * (step_delay << delay);
1784e92a4047SStephen Boyd 	slew_rate *= SPMI_FTSMPS_STEP_MARGIN_NUM;
1785e92a4047SStephen Boyd 	slew_rate /= SPMI_FTSMPS_STEP_MARGIN_DEN;
1786e92a4047SStephen Boyd 
1787e92a4047SStephen Boyd 	/* Ensure that the slew rate is greater than 0 */
1788e92a4047SStephen Boyd 	vreg->slew_rate = max(slew_rate, 1);
1789e92a4047SStephen Boyd 
1790e92a4047SStephen Boyd 	return ret;
1791e92a4047SStephen Boyd }
1792e92a4047SStephen Boyd 
spmi_regulator_init_slew_rate_ftsmps426(struct spmi_regulator * vreg,int clock_rate)17930211f68eSJorge Ramirez static int spmi_regulator_init_slew_rate_ftsmps426(struct spmi_regulator *vreg,
17940211f68eSJorge Ramirez 						   int clock_rate)
179542ba89c8SJeffrey Hugo {
179642ba89c8SJeffrey Hugo 	int ret;
179742ba89c8SJeffrey Hugo 	u8 reg = 0;
179842ba89c8SJeffrey Hugo 	int delay, slew_rate;
179942ba89c8SJeffrey Hugo 	const struct spmi_voltage_range *range = &vreg->set_points->range[0];
180042ba89c8SJeffrey Hugo 
180142ba89c8SJeffrey Hugo 	ret = spmi_vreg_read(vreg, SPMI_COMMON_REG_STEP_CTRL, &reg, 1);
180242ba89c8SJeffrey Hugo 	if (ret) {
180342ba89c8SJeffrey Hugo 		dev_err(vreg->dev, "spmi read failed, ret=%d\n", ret);
180442ba89c8SJeffrey Hugo 		return ret;
180542ba89c8SJeffrey Hugo 	}
180642ba89c8SJeffrey Hugo 
180742ba89c8SJeffrey Hugo 	delay = reg & SPMI_FTSMPS426_STEP_CTRL_DELAY_MASK;
180842ba89c8SJeffrey Hugo 	delay >>= SPMI_FTSMPS426_STEP_CTRL_DELAY_SHIFT;
180942ba89c8SJeffrey Hugo 
181042ba89c8SJeffrey Hugo 	/* slew_rate has units of uV/us */
18110211f68eSJorge Ramirez 	slew_rate = clock_rate * range->step_uV;
181242ba89c8SJeffrey Hugo 	slew_rate /= 1000 * (SPMI_FTSMPS426_STEP_DELAY << delay);
181342ba89c8SJeffrey Hugo 	slew_rate *= SPMI_FTSMPS426_STEP_MARGIN_NUM;
181442ba89c8SJeffrey Hugo 	slew_rate /= SPMI_FTSMPS426_STEP_MARGIN_DEN;
181542ba89c8SJeffrey Hugo 
181642ba89c8SJeffrey Hugo 	/* Ensure that the slew rate is greater than 0 */
181742ba89c8SJeffrey Hugo 	vreg->slew_rate = max(slew_rate, 1);
181842ba89c8SJeffrey Hugo 
181942ba89c8SJeffrey Hugo 	return ret;
182042ba89c8SJeffrey Hugo }
182142ba89c8SJeffrey Hugo 
spmi_regulator_init_slew_rate_hfsmps(struct spmi_regulator * vreg)182227850254SIskren Chernev static int spmi_regulator_init_slew_rate_hfsmps(struct spmi_regulator *vreg)
182327850254SIskren Chernev {
182427850254SIskren Chernev 	int ret;
182527850254SIskren Chernev 	u8 reg = 0;
182627850254SIskren Chernev 	int delay;
182727850254SIskren Chernev 
182827850254SIskren Chernev 	ret = spmi_vreg_read(vreg, SPMI_HFSMPS_REG_STEP_CTRL, &reg, 1);
182927850254SIskren Chernev 	if (ret) {
183027850254SIskren Chernev 		dev_err(vreg->dev, "spmi read failed, ret=%d\n", ret);
183127850254SIskren Chernev 		return ret;
183227850254SIskren Chernev 	}
183327850254SIskren Chernev 
183427850254SIskren Chernev 	delay = reg & SPMI_FTSMPS426_STEP_CTRL_DELAY_MASK;
183527850254SIskren Chernev 	delay >>= SPMI_FTSMPS426_STEP_CTRL_DELAY_SHIFT;
183627850254SIskren Chernev 
183727850254SIskren Chernev 	vreg->slew_rate = SPMI_HFSMPS_SLEW_RATE_38p4 >> delay;
183827850254SIskren Chernev 
183927850254SIskren Chernev 	return ret;
184027850254SIskren Chernev }
184127850254SIskren Chernev 
spmi_regulator_init_registers(struct spmi_regulator * vreg,const struct spmi_regulator_init_data * data)1842e2adfacdSStephen Boyd static int spmi_regulator_init_registers(struct spmi_regulator *vreg,
1843e2adfacdSStephen Boyd 				const struct spmi_regulator_init_data *data)
1844e2adfacdSStephen Boyd {
1845e2adfacdSStephen Boyd 	int ret;
1846e2adfacdSStephen Boyd 	enum spmi_regulator_logical_type type;
1847e2adfacdSStephen Boyd 	u8 ctrl_reg[8], reg, mask;
1848e2adfacdSStephen Boyd 
1849e2adfacdSStephen Boyd 	type = vreg->logical_type;
1850e2adfacdSStephen Boyd 
1851e2adfacdSStephen Boyd 	ret = spmi_vreg_read(vreg, SPMI_COMMON_REG_VOLTAGE_RANGE, ctrl_reg, 8);
1852e2adfacdSStephen Boyd 	if (ret)
1853e2adfacdSStephen Boyd 		return ret;
1854e2adfacdSStephen Boyd 
1855e2adfacdSStephen Boyd 	/* Set up enable pin control. */
18566a1fe83bSAxel Lin 	if (!(data->pin_ctrl_enable & SPMI_REGULATOR_PIN_CTRL_ENABLE_HW_DEFAULT)) {
18576a1fe83bSAxel Lin 		switch (type) {
18586a1fe83bSAxel Lin 		case SPMI_REGULATOR_LOGICAL_TYPE_SMPS:
18596a1fe83bSAxel Lin 		case SPMI_REGULATOR_LOGICAL_TYPE_LDO:
18606a1fe83bSAxel Lin 		case SPMI_REGULATOR_LOGICAL_TYPE_VS:
1861e2adfacdSStephen Boyd 			ctrl_reg[SPMI_COMMON_IDX_ENABLE] &=
1862e2adfacdSStephen Boyd 				~SPMI_COMMON_ENABLE_FOLLOW_ALL_MASK;
1863e2adfacdSStephen Boyd 			ctrl_reg[SPMI_COMMON_IDX_ENABLE] |=
1864e2adfacdSStephen Boyd 				data->pin_ctrl_enable & SPMI_COMMON_ENABLE_FOLLOW_ALL_MASK;
18656a1fe83bSAxel Lin 			break;
18666a1fe83bSAxel Lin 		default:
18676a1fe83bSAxel Lin 			break;
18686a1fe83bSAxel Lin 		}
1869e2adfacdSStephen Boyd 	}
1870e2adfacdSStephen Boyd 
1871e2adfacdSStephen Boyd 	/* Set up mode pin control. */
18726a1fe83bSAxel Lin 	if (!(data->pin_ctrl_hpm & SPMI_REGULATOR_PIN_CTRL_HPM_HW_DEFAULT)) {
18736a1fe83bSAxel Lin 		switch (type) {
18746a1fe83bSAxel Lin 		case SPMI_REGULATOR_LOGICAL_TYPE_SMPS:
18756a1fe83bSAxel Lin 		case SPMI_REGULATOR_LOGICAL_TYPE_LDO:
1876e2adfacdSStephen Boyd 			ctrl_reg[SPMI_COMMON_IDX_MODE] &=
1877e2adfacdSStephen Boyd 				~SPMI_COMMON_MODE_FOLLOW_ALL_MASK;
1878e2adfacdSStephen Boyd 			ctrl_reg[SPMI_COMMON_IDX_MODE] |=
1879e2adfacdSStephen Boyd 				data->pin_ctrl_hpm & SPMI_COMMON_MODE_FOLLOW_ALL_MASK;
18806a1fe83bSAxel Lin 			break;
18816a1fe83bSAxel Lin 		case SPMI_REGULATOR_LOGICAL_TYPE_VS:
18826a1fe83bSAxel Lin 		case SPMI_REGULATOR_LOGICAL_TYPE_ULT_LO_SMPS:
18836a1fe83bSAxel Lin 		case SPMI_REGULATOR_LOGICAL_TYPE_ULT_HO_SMPS:
18846a1fe83bSAxel Lin 		case SPMI_REGULATOR_LOGICAL_TYPE_ULT_LDO:
1885e2adfacdSStephen Boyd 			ctrl_reg[SPMI_COMMON_IDX_MODE] &=
1886e2adfacdSStephen Boyd 				~SPMI_COMMON_MODE_FOLLOW_AWAKE_MASK;
1887e2adfacdSStephen Boyd 			ctrl_reg[SPMI_COMMON_IDX_MODE] |=
1888e2adfacdSStephen Boyd 				data->pin_ctrl_hpm & SPMI_COMMON_MODE_FOLLOW_AWAKE_MASK;
18896a1fe83bSAxel Lin 			break;
18906a1fe83bSAxel Lin 		default:
18916a1fe83bSAxel Lin 			break;
1892e2adfacdSStephen Boyd 		}
1893e2adfacdSStephen Boyd 	}
1894e2adfacdSStephen Boyd 
1895e2adfacdSStephen Boyd 	/* Write back any control register values that were modified. */
1896e2adfacdSStephen Boyd 	ret = spmi_vreg_write(vreg, SPMI_COMMON_REG_VOLTAGE_RANGE, ctrl_reg, 8);
1897e2adfacdSStephen Boyd 	if (ret)
1898e2adfacdSStephen Boyd 		return ret;
1899e2adfacdSStephen Boyd 
1900e2adfacdSStephen Boyd 	/* Set soft start strength and over current protection for VS. */
1901e2adfacdSStephen Boyd 	if (type == SPMI_REGULATOR_LOGICAL_TYPE_VS) {
1902e2adfacdSStephen Boyd 		if (data->vs_soft_start_strength
1903e2adfacdSStephen Boyd 				!= SPMI_VS_SOFT_START_STR_HW_DEFAULT) {
1904e2adfacdSStephen Boyd 			reg = data->vs_soft_start_strength
1905e2adfacdSStephen Boyd 				& SPMI_VS_SOFT_START_SEL_MASK;
1906e2adfacdSStephen Boyd 			mask = SPMI_VS_SOFT_START_SEL_MASK;
1907e2adfacdSStephen Boyd 			return spmi_vreg_update_bits(vreg,
1908e2adfacdSStephen Boyd 						     SPMI_VS_REG_SOFT_START,
1909e2adfacdSStephen Boyd 						     reg, mask);
1910e2adfacdSStephen Boyd 		}
1911e2adfacdSStephen Boyd 	}
1912e2adfacdSStephen Boyd 
1913e2adfacdSStephen Boyd 	return 0;
1914e2adfacdSStephen Boyd }
1915e2adfacdSStephen Boyd 
spmi_regulator_get_dt_config(struct spmi_regulator * vreg,struct device_node * node,struct spmi_regulator_init_data * data)1916e2adfacdSStephen Boyd static void spmi_regulator_get_dt_config(struct spmi_regulator *vreg,
1917e2adfacdSStephen Boyd 		struct device_node *node, struct spmi_regulator_init_data *data)
1918e2adfacdSStephen Boyd {
1919e2adfacdSStephen Boyd 	/*
1920e2adfacdSStephen Boyd 	 * Initialize configuration parameters to use hardware default in case
1921e2adfacdSStephen Boyd 	 * no value is specified via device tree.
1922e2adfacdSStephen Boyd 	 */
1923e2adfacdSStephen Boyd 	data->pin_ctrl_enable	    = SPMI_REGULATOR_PIN_CTRL_ENABLE_HW_DEFAULT;
1924e2adfacdSStephen Boyd 	data->pin_ctrl_hpm	    = SPMI_REGULATOR_PIN_CTRL_HPM_HW_DEFAULT;
1925e2adfacdSStephen Boyd 	data->vs_soft_start_strength	= SPMI_VS_SOFT_START_STR_HW_DEFAULT;
1926e2adfacdSStephen Boyd 
1927e2adfacdSStephen Boyd 	/* These bindings are optional, so it is okay if they aren't found. */
1928e2adfacdSStephen Boyd 	of_property_read_u32(node, "qcom,ocp-max-retries",
1929e2adfacdSStephen Boyd 		&vreg->ocp_max_retries);
1930e2adfacdSStephen Boyd 	of_property_read_u32(node, "qcom,ocp-retry-delay",
1931e2adfacdSStephen Boyd 		&vreg->ocp_retry_delay_ms);
1932e2adfacdSStephen Boyd 	of_property_read_u32(node, "qcom,pin-ctrl-enable",
1933e2adfacdSStephen Boyd 		&data->pin_ctrl_enable);
1934e2adfacdSStephen Boyd 	of_property_read_u32(node, "qcom,pin-ctrl-hpm", &data->pin_ctrl_hpm);
1935e2adfacdSStephen Boyd 	of_property_read_u32(node, "qcom,vs-soft-start-strength",
1936e2adfacdSStephen Boyd 		&data->vs_soft_start_strength);
1937e2adfacdSStephen Boyd }
1938e2adfacdSStephen Boyd 
spmi_regulator_of_map_mode(unsigned int mode)1939e92a4047SStephen Boyd static unsigned int spmi_regulator_of_map_mode(unsigned int mode)
1940e92a4047SStephen Boyd {
1941e2adfacdSStephen Boyd 	if (mode == 1)
1942e92a4047SStephen Boyd 		return REGULATOR_MODE_NORMAL;
1943e2adfacdSStephen Boyd 	if (mode == 2)
1944e2adfacdSStephen Boyd 		return REGULATOR_MODE_FAST;
1945e92a4047SStephen Boyd 
1946e92a4047SStephen Boyd 	return REGULATOR_MODE_IDLE;
1947e92a4047SStephen Boyd }
1948e92a4047SStephen Boyd 
spmi_regulator_of_parse(struct device_node * node,const struct regulator_desc * desc,struct regulator_config * config)1949e92a4047SStephen Boyd static int spmi_regulator_of_parse(struct device_node *node,
1950e92a4047SStephen Boyd 			    const struct regulator_desc *desc,
1951e92a4047SStephen Boyd 			    struct regulator_config *config)
1952e92a4047SStephen Boyd {
1953e2adfacdSStephen Boyd 	struct spmi_regulator_init_data data = { };
1954e92a4047SStephen Boyd 	struct spmi_regulator *vreg = config->driver_data;
1955e92a4047SStephen Boyd 	struct device *dev = config->dev;
1956e92a4047SStephen Boyd 	int ret;
1957e92a4047SStephen Boyd 
1958e2adfacdSStephen Boyd 	spmi_regulator_get_dt_config(vreg, node, &data);
1959e2adfacdSStephen Boyd 
1960e2adfacdSStephen Boyd 	if (!vreg->ocp_max_retries)
1961e92a4047SStephen Boyd 		vreg->ocp_max_retries = SPMI_VS_OCP_DEFAULT_MAX_RETRIES;
1962e2adfacdSStephen Boyd 	if (!vreg->ocp_retry_delay_ms)
1963e92a4047SStephen Boyd 		vreg->ocp_retry_delay_ms = SPMI_VS_OCP_DEFAULT_RETRY_DELAY_MS;
1964e92a4047SStephen Boyd 
1965e2adfacdSStephen Boyd 	ret = spmi_regulator_init_registers(vreg, &data);
1966e2adfacdSStephen Boyd 	if (ret) {
1967e2adfacdSStephen Boyd 		dev_err(dev, "common initialization failed, ret=%d\n", ret);
1968e2adfacdSStephen Boyd 		return ret;
1969e2adfacdSStephen Boyd 	}
1970e2adfacdSStephen Boyd 
19712cf7b99cSStephen Boyd 	switch (vreg->logical_type) {
19722cf7b99cSStephen Boyd 	case SPMI_REGULATOR_LOGICAL_TYPE_FTSMPS:
19732cf7b99cSStephen Boyd 	case SPMI_REGULATOR_LOGICAL_TYPE_ULT_LO_SMPS:
19742cf7b99cSStephen Boyd 	case SPMI_REGULATOR_LOGICAL_TYPE_ULT_HO_SMPS:
19752cf7b99cSStephen Boyd 	case SPMI_REGULATOR_LOGICAL_TYPE_SMPS:
19762cf7b99cSStephen Boyd 		ret = spmi_regulator_init_slew_rate(vreg);
1977e92a4047SStephen Boyd 		if (ret)
1978e92a4047SStephen Boyd 			return ret;
197942ba89c8SJeffrey Hugo 		break;
198042ba89c8SJeffrey Hugo 	case SPMI_REGULATOR_LOGICAL_TYPE_FTSMPS426:
19810211f68eSJorge Ramirez 		ret = spmi_regulator_init_slew_rate_ftsmps426(vreg,
19820211f68eSJorge Ramirez 						SPMI_FTSMPS426_CLOCK_RATE);
19830211f68eSJorge Ramirez 		if (ret)
19840211f68eSJorge Ramirez 			return ret;
19850211f68eSJorge Ramirez 		break;
19860211f68eSJorge Ramirez 	case SPMI_REGULATOR_LOGICAL_TYPE_HFS430:
19870211f68eSJorge Ramirez 		ret = spmi_regulator_init_slew_rate_ftsmps426(vreg,
19880211f68eSJorge Ramirez 							SPMI_HFS430_CLOCK_RATE);
198942ba89c8SJeffrey Hugo 		if (ret)
199042ba89c8SJeffrey Hugo 			return ret;
199142ba89c8SJeffrey Hugo 		break;
199227850254SIskren Chernev 	case SPMI_REGULATOR_LOGICAL_TYPE_HFSMPS:
19930d1cf568SIskren Chernev 	case SPMI_REGULATOR_LOGICAL_TYPE_FTSMPS3:
199427850254SIskren Chernev 		ret = spmi_regulator_init_slew_rate_hfsmps(vreg);
199527850254SIskren Chernev 		if (ret)
199627850254SIskren Chernev 			return ret;
199727850254SIskren Chernev 		break;
19982cf7b99cSStephen Boyd 	default:
19992cf7b99cSStephen Boyd 		break;
2000e92a4047SStephen Boyd 	}
2001e92a4047SStephen Boyd 
2002e92a4047SStephen Boyd 	if (vreg->logical_type != SPMI_REGULATOR_LOGICAL_TYPE_VS)
2003e92a4047SStephen Boyd 		vreg->ocp_irq = 0;
2004e92a4047SStephen Boyd 
2005e92a4047SStephen Boyd 	if (vreg->ocp_irq) {
2006e92a4047SStephen Boyd 		ret = devm_request_irq(dev, vreg->ocp_irq,
2007e92a4047SStephen Boyd 			spmi_regulator_vs_ocp_isr, IRQF_TRIGGER_RISING, "ocp",
2008e92a4047SStephen Boyd 			vreg);
2009e92a4047SStephen Boyd 		if (ret < 0) {
2010e92a4047SStephen Boyd 			dev_err(dev, "failed to request irq %d, ret=%d\n",
2011e92a4047SStephen Boyd 				vreg->ocp_irq, ret);
2012e92a4047SStephen Boyd 			return ret;
2013e92a4047SStephen Boyd 		}
2014e92a4047SStephen Boyd 
2015b6688015SMatti Vaittinen 		ret = devm_delayed_work_autocancel(dev, &vreg->ocp_work,
2016b6688015SMatti Vaittinen 						   spmi_regulator_vs_ocp_work);
2017b6688015SMatti Vaittinen 		if (ret)
2018b6688015SMatti Vaittinen 			return ret;
2019e92a4047SStephen Boyd 	}
2020e92a4047SStephen Boyd 
2021e92a4047SStephen Boyd 	return 0;
2022e92a4047SStephen Boyd }
2023e92a4047SStephen Boyd 
2024e62ef4a9SIskren Chernev static const struct spmi_regulator_data pm6125_regulators[] = {
2025e62ef4a9SIskren Chernev 	{ "s1", 0x1400, "vdd_s1" },
2026e62ef4a9SIskren Chernev 	{ "s2", 0x1700, "vdd_s2" },
2027e62ef4a9SIskren Chernev 	{ "s3", 0x1a00, "vdd_s3" },
2028e62ef4a9SIskren Chernev 	{ "s4", 0x1d00, "vdd_s4" },
2029e62ef4a9SIskren Chernev 	{ "s5", 0x2000, "vdd_s5" },
2030e62ef4a9SIskren Chernev 	{ "s6", 0x2300, "vdd_s6" },
2031e62ef4a9SIskren Chernev 	{ "s7", 0x2600, "vdd_s7" },
2032e62ef4a9SIskren Chernev 	{ "s8", 0x2900, "vdd_s8" },
2033e62ef4a9SIskren Chernev 	{ "l1", 0x4000, "vdd_l1_l7_l17_l18" },
2034e62ef4a9SIskren Chernev 	{ "l2", 0x4100, "vdd_l2_l3_l4" },
2035e62ef4a9SIskren Chernev 	{ "l3", 0x4200, "vdd_l2_l3_l4" },
2036e62ef4a9SIskren Chernev 	{ "l4", 0x4300, "vdd_l2_l3_l4" },
2037e62ef4a9SIskren Chernev 	{ "l5", 0x4400, "vdd_l5_l15_l19_l20_l21_l22" },
2038e62ef4a9SIskren Chernev 	{ "l6", 0x4500, "vdd_l6_l8" },
2039e62ef4a9SIskren Chernev 	{ "l7", 0x4600, "vdd_l1_l7_l17_l18" },
2040e62ef4a9SIskren Chernev 	{ "l8", 0x4700, "vdd_l6_l8" },
2041e62ef4a9SIskren Chernev 	{ "l9", 0x4800, "vdd_l9_l11" },
2042e62ef4a9SIskren Chernev 	{ "l10", 0x4900, "vdd_l10_l13_l14" },
2043e62ef4a9SIskren Chernev 	{ "l11", 0x4a00, "vdd_l9_l11" },
2044e62ef4a9SIskren Chernev 	{ "l12", 0x4b00, "vdd_l12_l16" },
2045e62ef4a9SIskren Chernev 	{ "l13", 0x4c00, "vdd_l10_l13_l14" },
2046e62ef4a9SIskren Chernev 	{ "l14", 0x4d00, "vdd_l10_l13_l14" },
2047e62ef4a9SIskren Chernev 	{ "l15", 0x4e00, "vdd_l5_l15_l19_l20_l21_l22" },
2048e62ef4a9SIskren Chernev 	{ "l16", 0x4f00, "vdd_l12_l16" },
2049e62ef4a9SIskren Chernev 	{ "l17", 0x5000, "vdd_l1_l7_l17_l18" },
2050e62ef4a9SIskren Chernev 	{ "l18", 0x5100, "vdd_l1_l7_l17_l18" },
2051e62ef4a9SIskren Chernev 	{ "l19", 0x5200, "vdd_l5_l15_l19_l20_l21_l22" },
2052e62ef4a9SIskren Chernev 	{ "l20", 0x5300, "vdd_l5_l15_l19_l20_l21_l22" },
2053e62ef4a9SIskren Chernev 	{ "l21", 0x5400, "vdd_l5_l15_l19_l20_l21_l22" },
2054e62ef4a9SIskren Chernev 	{ "l22", 0x5500, "vdd_l5_l15_l19_l20_l21_l22" },
2055e62ef4a9SIskren Chernev 	{ "l23", 0x5600, "vdd_l23_l24" },
2056e62ef4a9SIskren Chernev 	{ "l24", 0x5700, "vdd_l23_l24" },
2057e62ef4a9SIskren Chernev };
2058e62ef4a9SIskren Chernev 
20599a2da074SIskren Chernev static const struct spmi_regulator_data pm660_regulators[] = {
20609a2da074SIskren Chernev 	{ "s1", 0x1400, "vdd_s1", },
20619a2da074SIskren Chernev 	{ "s2", 0x1700, "vdd_s2", },
20629a2da074SIskren Chernev 	{ "s3", 0x1a00, "vdd_s3", },
20639a2da074SIskren Chernev 	{ "s4", 0x1d00, "vdd_s3", },
20649a2da074SIskren Chernev 	{ "s5", 0x2000, "vdd_s5", },
20659a2da074SIskren Chernev 	{ "s6", 0x2300, "vdd_s6", },
20669a2da074SIskren Chernev 	{ "l1", 0x4000, "vdd_l1_l6_l7", },
20679a2da074SIskren Chernev 	{ "l2", 0x4100, "vdd_l2_l3", },
20689a2da074SIskren Chernev 	{ "l3", 0x4200, "vdd_l2_l3", },
20699a2da074SIskren Chernev 	/* l4 is unaccessible on PM660 */
20709a2da074SIskren Chernev 	{ "l5", 0x4400, "vdd_l5", },
20719a2da074SIskren Chernev 	{ "l6", 0x4500, "vdd_l1_l6_l7", },
20729a2da074SIskren Chernev 	{ "l7", 0x4600, "vdd_l1_l6_l7", },
20739a2da074SIskren Chernev 	{ "l8", 0x4700, "vdd_l8_l9_l10_l11_l12_l13_l14", },
20749a2da074SIskren Chernev 	{ "l9", 0x4800, "vdd_l8_l9_l10_l11_l12_l13_l14", },
20759a2da074SIskren Chernev 	{ "l10", 0x4900, "vdd_l8_l9_l10_l11_l12_l13_l14", },
20769a2da074SIskren Chernev 	{ "l11", 0x4a00, "vdd_l8_l9_l10_l11_l12_l13_l14", },
20779a2da074SIskren Chernev 	{ "l12", 0x4b00, "vdd_l8_l9_l10_l11_l12_l13_l14", },
20789a2da074SIskren Chernev 	{ "l13", 0x4c00, "vdd_l8_l9_l10_l11_l12_l13_l14", },
20799a2da074SIskren Chernev 	{ "l14", 0x4d00, "vdd_l8_l9_l10_l11_l12_l13_l14", },
20809a2da074SIskren Chernev 	{ "l15", 0x4e00, "vdd_l15_l16_l17_l18_l19", },
20819a2da074SIskren Chernev 	{ "l16", 0x4f00, "vdd_l15_l16_l17_l18_l19", },
20829a2da074SIskren Chernev 	{ "l17", 0x5000, "vdd_l15_l16_l17_l18_l19", },
20839a2da074SIskren Chernev 	{ "l18", 0x5100, "vdd_l15_l16_l17_l18_l19", },
20849a2da074SIskren Chernev 	{ "l19", 0x5200, "vdd_l15_l16_l17_l18_l19", },
20859a2da074SIskren Chernev 	{ }
20869a2da074SIskren Chernev };
20879a2da074SIskren Chernev 
20889a2da074SIskren Chernev static const struct spmi_regulator_data pm660l_regulators[] = {
20899a2da074SIskren Chernev 	{ "s1", 0x1400, "vdd_s1", },
20909a2da074SIskren Chernev 	{ "s2", 0x1700, "vdd_s2", },
20919a2da074SIskren Chernev 	{ "s3", 0x1a00, "vdd_s3", },
20929a2da074SIskren Chernev 	{ "s4", 0x1d00, "vdd_s4", },
20939a2da074SIskren Chernev 	{ "s5", 0x2000, "vdd_s5", },
20949a2da074SIskren Chernev 	{ "l1", 0x4000, "vdd_l1_l9_l10", },
20959a2da074SIskren Chernev 	{ "l2", 0x4100, "vdd_l2", },
20969a2da074SIskren Chernev 	{ "l3", 0x4200, "vdd_l3_l5_l7_l8", },
20979a2da074SIskren Chernev 	{ "l4", 0x4300, "vdd_l4_l6", },
20989a2da074SIskren Chernev 	{ "l5", 0x4400, "vdd_l3_l5_l7_l8", },
20999a2da074SIskren Chernev 	{ "l6", 0x4500, "vdd_l4_l6", },
21009a2da074SIskren Chernev 	{ "l7", 0x4600, "vdd_l3_l5_l7_l8", },
21019a2da074SIskren Chernev 	{ "l8", 0x4700, "vdd_l3_l5_l7_l8", },
21029a2da074SIskren Chernev 	{ "l9", 0x4800, "vdd_l1_l9_l10", },
21039a2da074SIskren Chernev 	{ "l10", 0x4900, "vdd_l1_l9_l10", },
21049a2da074SIskren Chernev 	{ }
21059a2da074SIskren Chernev };
21069a2da074SIskren Chernev 
21079a2da074SIskren Chernev static const struct spmi_regulator_data pm8004_regulators[] = {
21089a2da074SIskren Chernev 	{ "s2", 0x1700, "vdd_s2", },
21099a2da074SIskren Chernev 	{ "s5", 0x2000, "vdd_s5", },
21109a2da074SIskren Chernev 	{ }
21119a2da074SIskren Chernev };
21129a2da074SIskren Chernev 
21139a2da074SIskren Chernev static const struct spmi_regulator_data pm8005_regulators[] = {
21149a2da074SIskren Chernev 	{ "s1", 0x1400, "vdd_s1", },
21159a2da074SIskren Chernev 	{ "s2", 0x1700, "vdd_s2", },
21169a2da074SIskren Chernev 	{ "s3", 0x1a00, "vdd_s3", },
21179a2da074SIskren Chernev 	{ "s4", 0x1d00, "vdd_s4", },
21189a2da074SIskren Chernev 	{ }
21199a2da074SIskren Chernev };
21209a2da074SIskren Chernev 
21215b30cb2aSStephan Gerhold static const struct spmi_regulator_data pm8019_regulators[] = {
21225b30cb2aSStephan Gerhold 	{ "s1", 0x1400, "vdd_s1", },
21235b30cb2aSStephan Gerhold 	{ "s2", 0x1700, "vdd_s2", },
21245b30cb2aSStephan Gerhold 	{ "s3", 0x1a00, "vdd_s3", },
21255b30cb2aSStephan Gerhold 	{ "s4", 0x1d00, "vdd_s4", },
21265b30cb2aSStephan Gerhold 	{ "l1", 0x4000, "vdd_l1", },
21275b30cb2aSStephan Gerhold 	{ "l2", 0x4100, "vdd_l2_l3", },
21285b30cb2aSStephan Gerhold 	{ "l3", 0x4200, "vdd_l2_l3", },
21295b30cb2aSStephan Gerhold 	{ "l4", 0x4300, "vdd_l4_l5_l6", },
21305b30cb2aSStephan Gerhold 	{ "l5", 0x4400, "vdd_l4_l5_l6", },
21315b30cb2aSStephan Gerhold 	{ "l6", 0x4500, "vdd_l4_l5_l6", },
21325b30cb2aSStephan Gerhold 	{ "l7", 0x4600, "vdd_l7_l8_l11", },
21335b30cb2aSStephan Gerhold 	{ "l8", 0x4700, "vdd_l7_l8_l11", },
21345b30cb2aSStephan Gerhold 	{ "l9", 0x4800, "vdd_l9", },
21355b30cb2aSStephan Gerhold 	{ "l10", 0x4900, "vdd_l10", },
21365b30cb2aSStephan Gerhold 	{ "l11", 0x4a00, "vdd_l7_l8_l11", },
21375b30cb2aSStephan Gerhold 	{ "l12", 0x4b00, "vdd_l12", },
21385b30cb2aSStephan Gerhold 	{ "l13", 0x4c00, "vdd_l13_l14", },
21395b30cb2aSStephan Gerhold 	{ "l14", 0x4d00, "vdd_l13_l14", },
21405b30cb2aSStephan Gerhold 	{ }
21415b30cb2aSStephan Gerhold };
21425b30cb2aSStephan Gerhold 
2143f8843e5eSDominik Kobinski static const struct spmi_regulator_data pm8226_regulators[] = {
2144f8843e5eSDominik Kobinski 	{ "s1", 0x1400, "vdd_s1", },
2145f8843e5eSDominik Kobinski 	{ "s2", 0x1700, "vdd_s2", },
2146f8843e5eSDominik Kobinski 	{ "s3", 0x1a00, "vdd_s3", },
2147f8843e5eSDominik Kobinski 	{ "s4", 0x1d00, "vdd_s4", },
2148f8843e5eSDominik Kobinski 	{ "s5", 0x2000, "vdd_s5", },
2149f8843e5eSDominik Kobinski 	{ "l1", 0x4000, "vdd_l1_l2_l4_l5", },
2150f8843e5eSDominik Kobinski 	{ "l2", 0x4100, "vdd_l1_l2_l4_l5", },
2151f8843e5eSDominik Kobinski 	{ "l3", 0x4200, "vdd_l3_l24_l26", },
2152f8843e5eSDominik Kobinski 	{ "l4", 0x4300, "vdd_l1_l2_l4_l5", },
2153f8843e5eSDominik Kobinski 	{ "l5", 0x4400, "vdd_l1_l2_l4_l5", },
2154f8843e5eSDominik Kobinski 	{ "l6", 0x4500, "vdd_l6_l7_l8_l9_l27", },
2155f8843e5eSDominik Kobinski 	{ "l7", 0x4600, "vdd_l6_l7_l8_l9_l27", },
2156f8843e5eSDominik Kobinski 	{ "l8", 0x4700, "vdd_l6_l7_l8_l9_l27", },
2157f8843e5eSDominik Kobinski 	{ "l9", 0x4800, "vdd_l6_l7_l8_l9_l27", },
2158f8843e5eSDominik Kobinski 	{ "l10", 0x4900, "vdd_l10_l11_l13", },
2159f8843e5eSDominik Kobinski 	{ "l11", 0x4a00, "vdd_l10_l11_l13", },
2160f8843e5eSDominik Kobinski 	{ "l12", 0x4b00, "vdd_l12_l14", },
2161f8843e5eSDominik Kobinski 	{ "l13", 0x4c00, "vdd_l10_l11_l13", },
2162f8843e5eSDominik Kobinski 	{ "l14", 0x4d00, "vdd_l12_l14", },
2163f8843e5eSDominik Kobinski 	{ "l15", 0x4e00, "vdd_l15_l16_l17_l18", },
2164f8843e5eSDominik Kobinski 	{ "l16", 0x4f00, "vdd_l15_l16_l17_l18", },
2165f8843e5eSDominik Kobinski 	{ "l17", 0x5000, "vdd_l15_l16_l17_l18", },
2166f8843e5eSDominik Kobinski 	{ "l18", 0x5100, "vdd_l15_l16_l17_l18", },
2167f8843e5eSDominik Kobinski 	{ "l19", 0x5200, "vdd_l19_l20_l21_l22_l23_l28", },
2168f8843e5eSDominik Kobinski 	{ "l20", 0x5300, "vdd_l19_l20_l21_l22_l23_l28", },
2169f8843e5eSDominik Kobinski 	{ "l21", 0x5400, "vdd_l19_l20_l21_l22_l23_l28", },
2170f8843e5eSDominik Kobinski 	{ "l22", 0x5500, "vdd_l19_l20_l21_l22_l23_l28", },
2171f8843e5eSDominik Kobinski 	{ "l23", 0x5600, "vdd_l19_l20_l21_l22_l23_l28", },
2172f8843e5eSDominik Kobinski 	{ "l24", 0x5700, "vdd_l3_l24_l26", },
2173f8843e5eSDominik Kobinski 	{ "l25", 0x5800, "vdd_l25", },
2174f8843e5eSDominik Kobinski 	{ "l26", 0x5900, "vdd_l3_l24_l26", },
2175f8843e5eSDominik Kobinski 	{ "l27", 0x5a00, "vdd_l6_l7_l8_l9_l27", },
2176f8843e5eSDominik Kobinski 	{ "l28", 0x5b00, "vdd_l19_l20_l21_l22_l23_l28", },
2177f8843e5eSDominik Kobinski 	{ "lvs1", 0x8000, "vdd_lvs1", },
2178f8843e5eSDominik Kobinski 	{ }
2179f8843e5eSDominik Kobinski };
2180f8843e5eSDominik Kobinski 
2181e92a4047SStephen Boyd static const struct spmi_regulator_data pm8841_regulators[] = {
2182e92a4047SStephen Boyd 	{ "s1", 0x1400, "vdd_s1", },
2183e92a4047SStephen Boyd 	{ "s2", 0x1700, "vdd_s2", NULL, 0x1c08 },
2184e92a4047SStephen Boyd 	{ "s3", 0x1a00, "vdd_s3", },
2185e92a4047SStephen Boyd 	{ "s4", 0x1d00, "vdd_s4", NULL, 0x1c08 },
2186e92a4047SStephen Boyd 	{ "s5", 0x2000, "vdd_s5", NULL, 0x1c08 },
2187e92a4047SStephen Boyd 	{ "s6", 0x2300, "vdd_s6", NULL, 0x1c08 },
2188e92a4047SStephen Boyd 	{ "s7", 0x2600, "vdd_s7", NULL, 0x1c08 },
2189e92a4047SStephen Boyd 	{ "s8", 0x2900, "vdd_s8", NULL, 0x1c08 },
2190e92a4047SStephen Boyd 	{ }
2191e92a4047SStephen Boyd };
2192e92a4047SStephen Boyd 
2193813d01a4SStephan Gerhold static const struct spmi_regulator_data pm8909_regulators[] = {
2194813d01a4SStephan Gerhold 	{ "s1", 0x1400, "vdd_s1", },
2195813d01a4SStephan Gerhold 	{ "s2", 0x1700, "vdd_s2", },
2196813d01a4SStephan Gerhold 	{ "l1", 0x4000, "vdd_l1", },
2197813d01a4SStephan Gerhold 	{ "l2", 0x4100, "vdd_l2_l5", },
2198813d01a4SStephan Gerhold 	{ "l3", 0x4200, "vdd_l3_l6_l10", },
2199813d01a4SStephan Gerhold 	{ "l4", 0x4300, "vdd_l4_l7", },
2200813d01a4SStephan Gerhold 	{ "l5", 0x4400, "vdd_l2_l5", },
2201813d01a4SStephan Gerhold 	{ "l6", 0x4500, "vdd_l3_l6_l10", },
2202813d01a4SStephan Gerhold 	{ "l7", 0x4600, "vdd_l4_l7", },
2203813d01a4SStephan Gerhold 	{ "l8", 0x4700, "vdd_l8_l11_l15_l18", },
2204813d01a4SStephan Gerhold 	{ "l9", 0x4800, "vdd_l9_l12_l14_l17", },
2205813d01a4SStephan Gerhold 	{ "l10", 0x4900, "vdd_l3_l6_l10", },
2206813d01a4SStephan Gerhold 	{ "l11", 0x4a00, "vdd_l8_l11_l15_l18", },
2207813d01a4SStephan Gerhold 	{ "l12", 0x4b00, "vdd_l9_l12_l14_l17", },
2208813d01a4SStephan Gerhold 	{ "l13", 0x4c00, "vdd_l13", },
2209813d01a4SStephan Gerhold 	{ "l14", 0x4d00, "vdd_l9_l12_l14_l17", },
2210813d01a4SStephan Gerhold 	{ "l15", 0x4e00, "vdd_l8_l11_l15_l18", },
2211813d01a4SStephan Gerhold 	{ "l17", 0x5000, "vdd_l9_l12_l14_l17", },
2212813d01a4SStephan Gerhold 	{ "l18", 0x5100, "vdd_l8_l11_l15_l18", },
2213813d01a4SStephan Gerhold 	{ }
2214813d01a4SStephan Gerhold };
2215813d01a4SStephan Gerhold 
2216e92a4047SStephen Boyd static const struct spmi_regulator_data pm8916_regulators[] = {
2217e92a4047SStephen Boyd 	{ "s1", 0x1400, "vdd_s1", },
2218e92a4047SStephen Boyd 	{ "s2", 0x1700, "vdd_s2", },
2219e92a4047SStephen Boyd 	{ "s3", 0x1a00, "vdd_s3", },
2220e92a4047SStephen Boyd 	{ "s4", 0x1d00, "vdd_s4", },
2221e92a4047SStephen Boyd 	{ "l1", 0x4000, "vdd_l1_l3", },
2222e92a4047SStephen Boyd 	{ "l2", 0x4100, "vdd_l2", },
2223e92a4047SStephen Boyd 	{ "l3", 0x4200, "vdd_l1_l3", },
2224e92a4047SStephen Boyd 	{ "l4", 0x4300, "vdd_l4_l5_l6", },
2225e92a4047SStephen Boyd 	{ "l5", 0x4400, "vdd_l4_l5_l6", },
2226e92a4047SStephen Boyd 	{ "l6", 0x4500, "vdd_l4_l5_l6", },
2227e92a4047SStephen Boyd 	{ "l7", 0x4600, "vdd_l7", },
2228e92a4047SStephen Boyd 	{ "l8", 0x4700, "vdd_l8_l11_l14_l15_l16", },
2229e92a4047SStephen Boyd 	{ "l9", 0x4800, "vdd_l9_l10_l12_l13_l17_l18", },
2230e92a4047SStephen Boyd 	{ "l10", 0x4900, "vdd_l9_l10_l12_l13_l17_l18", },
2231e92a4047SStephen Boyd 	{ "l11", 0x4a00, "vdd_l8_l11_l14_l15_l16", },
2232e92a4047SStephen Boyd 	{ "l12", 0x4b00, "vdd_l9_l10_l12_l13_l17_l18", },
2233e92a4047SStephen Boyd 	{ "l13", 0x4c00, "vdd_l9_l10_l12_l13_l17_l18", },
2234e92a4047SStephen Boyd 	{ "l14", 0x4d00, "vdd_l8_l11_l14_l15_l16", },
2235e92a4047SStephen Boyd 	{ "l15", 0x4e00, "vdd_l8_l11_l14_l15_l16", },
2236e92a4047SStephen Boyd 	{ "l16", 0x4f00, "vdd_l8_l11_l14_l15_l16", },
2237e92a4047SStephen Boyd 	{ "l17", 0x5000, "vdd_l9_l10_l12_l13_l17_l18", },
2238e92a4047SStephen Boyd 	{ "l18", 0x5100, "vdd_l9_l10_l12_l13_l17_l18", },
2239e92a4047SStephen Boyd 	{ }
2240e92a4047SStephen Boyd };
2241e92a4047SStephen Boyd 
2242c0d6b2acSDang Huynh static const struct spmi_regulator_data pm8937_regulators[] = {
2243c0d6b2acSDang Huynh 	{ "s1", 0x1400, "vdd_s1", },
2244c0d6b2acSDang Huynh 	{ "s2", 0x1700, "vdd_s2", },
2245c0d6b2acSDang Huynh 	{ "s3", 0x1a00, "vdd_s3", },
2246c0d6b2acSDang Huynh 	{ "s4", 0x1d00, "vdd_s4", },
2247c0d6b2acSDang Huynh 	{ "s5", 0x2000, "vdd_s5", },
2248c0d6b2acSDang Huynh 	{ "s6", 0x2300, "vdd_s6", },
2249c0d6b2acSDang Huynh 	{ "l1", 0x4000, "vdd_l1_l19", },
2250c0d6b2acSDang Huynh 	{ "l2", 0x4100, "vdd_l2_l23", },
2251c0d6b2acSDang Huynh 	{ "l3", 0x4200, "vdd_l3", },
2252c0d6b2acSDang Huynh 	{ "l4", 0x4300, "vdd_l4_l5_l6_l7_l16", },
2253c0d6b2acSDang Huynh 	{ "l5", 0x4400, "vdd_l4_l5_l6_l7_l16", },
2254c0d6b2acSDang Huynh 	{ "l6", 0x4500, "vdd_l4_l5_l6_l7_l16", },
2255c0d6b2acSDang Huynh 	{ "l7", 0x4600, "vdd_l4_l5_l6_l7_l16", },
2256c0d6b2acSDang Huynh 	{ "l8", 0x4700, "vdd_l8_l11_l12_l17_l22", },
2257c0d6b2acSDang Huynh 	{ "l9", 0x4800, "vdd_l9_l10_l13_l14_l15_l18", },
2258c0d6b2acSDang Huynh 	{ "l10", 0x4900, "vdd_l9_l10_l13_l14_l15_l18", },
2259c0d6b2acSDang Huynh 	{ "l11", 0x4a00, "vdd_l8_l11_l12_l17_l22", },
2260c0d6b2acSDang Huynh 	{ "l12", 0x4b00, "vdd_l8_l11_l12_l17_l22", },
2261c0d6b2acSDang Huynh 	{ "l13", 0x4c00, "vdd_l9_l10_l13_l14_l15_l18", },
2262c0d6b2acSDang Huynh 	{ "l14", 0x4d00, "vdd_l9_l10_l13_l14_l15_l18", },
2263c0d6b2acSDang Huynh 	{ "l15", 0x4e00, "vdd_l9_l10_l13_l14_l15_l18", },
2264c0d6b2acSDang Huynh 	{ "l16", 0x4f00, "vdd_l4_l5_l6_l7_l16", },
2265c0d6b2acSDang Huynh 	{ "l17", 0x5000, "vdd_l8_l11_l12_l17_l22", },
2266c0d6b2acSDang Huynh 	{ "l18", 0x5100, "vdd_l9_l10_l13_l14_l15_l18", },
2267c0d6b2acSDang Huynh 	{ "l19", 0x5200, "vdd_l1_l19", },
2268c0d6b2acSDang Huynh 	{ "l20", 0x5300, "vdd_l20_l21", },
2269c0d6b2acSDang Huynh 	{ "l21", 0x5400, "vdd_l21_l21", },
2270c0d6b2acSDang Huynh 	{ "l22", 0x5500, "vdd_l8_l11_l12_l17_l22", },
2271c0d6b2acSDang Huynh 	{ "l23", 0x5600, "vdd_l2_l23", },
2272c0d6b2acSDang Huynh 	{ }
2273c0d6b2acSDang Huynh };
2274c0d6b2acSDang Huynh 
2275046d7e32SIskren Chernev static const struct spmi_regulator_data pm8941_regulators[] = {
2276046d7e32SIskren Chernev 	{ "s1", 0x1400, "vdd_s1", },
2277046d7e32SIskren Chernev 	{ "s2", 0x1700, "vdd_s2", },
2278046d7e32SIskren Chernev 	{ "s3", 0x1a00, "vdd_s3", },
2279046d7e32SIskren Chernev 	{ "s4", 0xa000, },
2280046d7e32SIskren Chernev 	{ "l1", 0x4000, "vdd_l1_l3", },
2281046d7e32SIskren Chernev 	{ "l2", 0x4100, "vdd_l2_lvs_1_2_3", },
2282046d7e32SIskren Chernev 	{ "l3", 0x4200, "vdd_l1_l3", },
2283046d7e32SIskren Chernev 	{ "l4", 0x4300, "vdd_l4_l11", },
2284046d7e32SIskren Chernev 	{ "l5", 0x4400, "vdd_l5_l7", NULL, 0x0410 },
2285046d7e32SIskren Chernev 	{ "l6", 0x4500, "vdd_l6_l12_l14_l15", },
2286046d7e32SIskren Chernev 	{ "l7", 0x4600, "vdd_l5_l7", NULL, 0x0410 },
2287046d7e32SIskren Chernev 	{ "l8", 0x4700, "vdd_l8_l16_l18_19", },
2288046d7e32SIskren Chernev 	{ "l9", 0x4800, "vdd_l9_l10_l17_l22", },
2289046d7e32SIskren Chernev 	{ "l10", 0x4900, "vdd_l9_l10_l17_l22", },
2290046d7e32SIskren Chernev 	{ "l11", 0x4a00, "vdd_l4_l11", },
2291046d7e32SIskren Chernev 	{ "l12", 0x4b00, "vdd_l6_l12_l14_l15", },
2292046d7e32SIskren Chernev 	{ "l13", 0x4c00, "vdd_l13_l20_l23_l24", },
2293046d7e32SIskren Chernev 	{ "l14", 0x4d00, "vdd_l6_l12_l14_l15", },
2294046d7e32SIskren Chernev 	{ "l15", 0x4e00, "vdd_l6_l12_l14_l15", },
2295046d7e32SIskren Chernev 	{ "l16", 0x4f00, "vdd_l8_l16_l18_19", },
2296046d7e32SIskren Chernev 	{ "l17", 0x5000, "vdd_l9_l10_l17_l22", },
2297046d7e32SIskren Chernev 	{ "l18", 0x5100, "vdd_l8_l16_l18_19", },
2298046d7e32SIskren Chernev 	{ "l19", 0x5200, "vdd_l8_l16_l18_19", },
2299046d7e32SIskren Chernev 	{ "l20", 0x5300, "vdd_l13_l20_l23_l24", },
2300046d7e32SIskren Chernev 	{ "l21", 0x5400, "vdd_l21", },
2301046d7e32SIskren Chernev 	{ "l22", 0x5500, "vdd_l9_l10_l17_l22", },
2302046d7e32SIskren Chernev 	{ "l23", 0x5600, "vdd_l13_l20_l23_l24", },
2303046d7e32SIskren Chernev 	{ "l24", 0x5700, "vdd_l13_l20_l23_l24", },
2304046d7e32SIskren Chernev 	{ "lvs1", 0x8000, "vdd_l2_lvs_1_2_3", },
2305046d7e32SIskren Chernev 	{ "lvs2", 0x8100, "vdd_l2_lvs_1_2_3", },
2306046d7e32SIskren Chernev 	{ "lvs3", 0x8200, "vdd_l2_lvs_1_2_3", },
2307046d7e32SIskren Chernev 	{ "5vs1", 0x8300, "vin_5vs", "ocp-5vs1", },
2308046d7e32SIskren Chernev 	{ "5vs2", 0x8400, "vin_5vs", "ocp-5vs2", },
2309046d7e32SIskren Chernev 	{ }
2310046d7e32SIskren Chernev };
2311046d7e32SIskren Chernev 
2312e4ff1710SAngelo G. Del Regno static const struct spmi_regulator_data pm8950_regulators[] = {
2313e4ff1710SAngelo G. Del Regno 	{ "s1", 0x1400, "vdd_s1", },
2314e4ff1710SAngelo G. Del Regno 	{ "s2", 0x1700, "vdd_s2", },
2315e4ff1710SAngelo G. Del Regno 	{ "s3", 0x1a00, "vdd_s3", },
2316e4ff1710SAngelo G. Del Regno 	{ "s4", 0x1d00, "vdd_s4", },
2317e4ff1710SAngelo G. Del Regno 	{ "s5", 0x2000, "vdd_s5", },
2318e4ff1710SAngelo G. Del Regno 	{ "s6", 0x2300, "vdd_s6", },
2319e4ff1710SAngelo G. Del Regno 	{ "l1", 0x4000, "vdd_l1_l19", },
2320e4ff1710SAngelo G. Del Regno 	{ "l2", 0x4100, "vdd_l2_l23", },
2321e4ff1710SAngelo G. Del Regno 	{ "l3", 0x4200, "vdd_l3", },
2322e4ff1710SAngelo G. Del Regno 	{ "l4", 0x4300, "vdd_l4_l5_l6_l7_l16", },
2323e4ff1710SAngelo G. Del Regno 	{ "l5", 0x4400, "vdd_l4_l5_l6_l7_l16", },
2324e4ff1710SAngelo G. Del Regno 	{ "l6", 0x4500, "vdd_l4_l5_l6_l7_l16", },
2325e4ff1710SAngelo G. Del Regno 	{ "l7", 0x4600, "vdd_l4_l5_l6_l7_l16", },
2326e4ff1710SAngelo G. Del Regno 	{ "l8", 0x4700, "vdd_l8_l11_l12_l17_l22", },
2327e4ff1710SAngelo G. Del Regno 	{ "l9", 0x4800, "vdd_l9_l10_l13_l14_l15_l18", },
2328e4ff1710SAngelo G. Del Regno 	{ "l10", 0x4900, "vdd_l9_l10_l13_l14_l15_l18", },
2329e4ff1710SAngelo G. Del Regno 	{ "l11", 0x4a00, "vdd_l8_l11_l12_l17_l22", },
2330e4ff1710SAngelo G. Del Regno 	{ "l12", 0x4b00, "vdd_l8_l11_l12_l17_l22", },
2331e4ff1710SAngelo G. Del Regno 	{ "l13", 0x4c00, "vdd_l9_l10_l13_l14_l15_l18", },
2332e4ff1710SAngelo G. Del Regno 	{ "l14", 0x4d00, "vdd_l9_l10_l13_l14_l15_l18", },
2333e4ff1710SAngelo G. Del Regno 	{ "l15", 0x4e00, "vdd_l9_l10_l13_l14_l15_l18", },
2334e4ff1710SAngelo G. Del Regno 	{ "l16", 0x4f00, "vdd_l4_l5_l6_l7_l16", },
2335e4ff1710SAngelo G. Del Regno 	{ "l17", 0x5000, "vdd_l8_l11_l12_l17_l22", },
2336e4ff1710SAngelo G. Del Regno 	{ "l18", 0x5100, "vdd_l9_l10_l13_l14_l15_l18", },
2337e4ff1710SAngelo G. Del Regno 	{ "l19", 0x5200, "vdd_l1_l19", },
2338e4ff1710SAngelo G. Del Regno 	{ "l20", 0x5300, "vdd_l20", },
2339e4ff1710SAngelo G. Del Regno 	{ "l21", 0x5400, "vdd_l21", },
2340e4ff1710SAngelo G. Del Regno 	{ "l22", 0x5500, "vdd_l8_l11_l12_l17_l22", },
2341e4ff1710SAngelo G. Del Regno 	{ "l23", 0x5600, "vdd_l2_l23", },
2342e4ff1710SAngelo G. Del Regno 	{ }
2343e4ff1710SAngelo G. Del Regno };
2344e4ff1710SAngelo G. Del Regno 
234550314e55SStephen Boyd static const struct spmi_regulator_data pm8994_regulators[] = {
234650314e55SStephen Boyd 	{ "s1", 0x1400, "vdd_s1", },
234750314e55SStephen Boyd 	{ "s2", 0x1700, "vdd_s2", },
234850314e55SStephen Boyd 	{ "s3", 0x1a00, "vdd_s3", },
234950314e55SStephen Boyd 	{ "s4", 0x1d00, "vdd_s4", },
235050314e55SStephen Boyd 	{ "s5", 0x2000, "vdd_s5", },
235150314e55SStephen Boyd 	{ "s6", 0x2300, "vdd_s6", },
235250314e55SStephen Boyd 	{ "s7", 0x2600, "vdd_s7", },
235350314e55SStephen Boyd 	{ "s8", 0x2900, "vdd_s8", },
235450314e55SStephen Boyd 	{ "s9", 0x2c00, "vdd_s9", },
235550314e55SStephen Boyd 	{ "s10", 0x2f00, "vdd_s10", },
235650314e55SStephen Boyd 	{ "s11", 0x3200, "vdd_s11", },
235750314e55SStephen Boyd 	{ "s12", 0x3500, "vdd_s12", },
235850314e55SStephen Boyd 	{ "l1", 0x4000, "vdd_l1", },
235950314e55SStephen Boyd 	{ "l2", 0x4100, "vdd_l2_l26_l28", },
236050314e55SStephen Boyd 	{ "l3", 0x4200, "vdd_l3_l11", },
236150314e55SStephen Boyd 	{ "l4", 0x4300, "vdd_l4_l27_l31", },
236250314e55SStephen Boyd 	{ "l5", 0x4400, "vdd_l5_l7", },
236350314e55SStephen Boyd 	{ "l6", 0x4500, "vdd_l6_l12_l32", },
236450314e55SStephen Boyd 	{ "l7", 0x4600, "vdd_l5_l7", },
236550314e55SStephen Boyd 	{ "l8", 0x4700, "vdd_l8_l16_l30", },
236650314e55SStephen Boyd 	{ "l9", 0x4800, "vdd_l9_l10_l18_l22", },
236750314e55SStephen Boyd 	{ "l10", 0x4900, "vdd_l9_l10_l18_l22", },
236850314e55SStephen Boyd 	{ "l11", 0x4a00, "vdd_l3_l11", },
236950314e55SStephen Boyd 	{ "l12", 0x4b00, "vdd_l6_l12_l32", },
237050314e55SStephen Boyd 	{ "l13", 0x4c00, "vdd_l13_l19_l23_l24", },
237150314e55SStephen Boyd 	{ "l14", 0x4d00, "vdd_l14_l15", },
237250314e55SStephen Boyd 	{ "l15", 0x4e00, "vdd_l14_l15", },
237350314e55SStephen Boyd 	{ "l16", 0x4f00, "vdd_l8_l16_l30", },
237450314e55SStephen Boyd 	{ "l17", 0x5000, "vdd_l17_l29", },
237550314e55SStephen Boyd 	{ "l18", 0x5100, "vdd_l9_l10_l18_l22", },
237650314e55SStephen Boyd 	{ "l19", 0x5200, "vdd_l13_l19_l23_l24", },
237750314e55SStephen Boyd 	{ "l20", 0x5300, "vdd_l20_l21", },
237850314e55SStephen Boyd 	{ "l21", 0x5400, "vdd_l20_l21", },
237950314e55SStephen Boyd 	{ "l22", 0x5500, "vdd_l9_l10_l18_l22", },
238050314e55SStephen Boyd 	{ "l23", 0x5600, "vdd_l13_l19_l23_l24", },
238150314e55SStephen Boyd 	{ "l24", 0x5700, "vdd_l13_l19_l23_l24", },
238250314e55SStephen Boyd 	{ "l25", 0x5800, "vdd_l25", },
238350314e55SStephen Boyd 	{ "l26", 0x5900, "vdd_l2_l26_l28", },
238450314e55SStephen Boyd 	{ "l27", 0x5a00, "vdd_l4_l27_l31", },
238550314e55SStephen Boyd 	{ "l28", 0x5b00, "vdd_l2_l26_l28", },
238650314e55SStephen Boyd 	{ "l29", 0x5c00, "vdd_l17_l29", },
238750314e55SStephen Boyd 	{ "l30", 0x5d00, "vdd_l8_l16_l30", },
238850314e55SStephen Boyd 	{ "l31", 0x5e00, "vdd_l4_l27_l31", },
238950314e55SStephen Boyd 	{ "l32", 0x5f00, "vdd_l6_l12_l32", },
239050314e55SStephen Boyd 	{ "lvs1", 0x8000, "vdd_lvs_1_2", },
239150314e55SStephen Boyd 	{ "lvs2", 0x8100, "vdd_lvs_1_2", },
239250314e55SStephen Boyd 	{ }
239350314e55SStephen Boyd };
239450314e55SStephen Boyd 
2395317aa3c4SStephan Gerhold static const struct spmi_regulator_data pma8084_regulators[] = {
2396317aa3c4SStephan Gerhold 	{ "s1", 0x1400, "vdd_s1", },
2397317aa3c4SStephan Gerhold 	{ "s2", 0x1700, "vdd_s2", },
2398317aa3c4SStephan Gerhold 	{ "s3", 0x1a00, "vdd_s3", },
2399317aa3c4SStephan Gerhold 	{ "s4", 0x1d00, "vdd_s4", },
2400317aa3c4SStephan Gerhold 	{ "s5", 0x2000, "vdd_s5", },
2401317aa3c4SStephan Gerhold 	{ "s6", 0x2300, "vdd_s6", },
2402317aa3c4SStephan Gerhold 	{ "s7", 0x2600, "vdd_s7", },
2403317aa3c4SStephan Gerhold 	{ "s8", 0x2900, "vdd_s8", },
2404317aa3c4SStephan Gerhold 	{ "s9", 0x2c00, "vdd_s9", },
2405317aa3c4SStephan Gerhold 	{ "s10", 0x2f00, "vdd_s10", },
2406317aa3c4SStephan Gerhold 	{ "s11", 0x3200, "vdd_s11", },
2407317aa3c4SStephan Gerhold 	{ "s12", 0x3500, "vdd_s12", },
2408317aa3c4SStephan Gerhold 	{ "l1", 0x4000, "vdd_l1_l11", },
2409317aa3c4SStephan Gerhold 	{ "l2", 0x4100, "vdd_l2_l3_l4_l27", },
2410317aa3c4SStephan Gerhold 	{ "l3", 0x4200, "vdd_l2_l3_l4_l27", },
2411317aa3c4SStephan Gerhold 	{ "l4", 0x4300, "vdd_l2_l3_l4_l27", },
2412317aa3c4SStephan Gerhold 	{ "l5", 0x4400, "vdd_l5_l7", },
2413317aa3c4SStephan Gerhold 	{ "l6", 0x4500, "vdd_l6_l12_l14_l15_l26", },
2414317aa3c4SStephan Gerhold 	{ "l7", 0x4600, "vdd_l5_l7", },
2415317aa3c4SStephan Gerhold 	{ "l8", 0x4700, "vdd_l8", },
2416317aa3c4SStephan Gerhold 	{ "l9", 0x4800, "vdd_l9_l10_l13_l20_l23_l24", },
2417317aa3c4SStephan Gerhold 	{ "l10", 0x4900, "vdd_l9_l10_l13_l20_l23_l24", },
2418317aa3c4SStephan Gerhold 	{ "l11", 0x4a00, "vdd_l1_l11", },
2419317aa3c4SStephan Gerhold 	{ "l12", 0x4b00, "vdd_l6_l12_l14_l15_l26", },
2420317aa3c4SStephan Gerhold 	{ "l13", 0x4c00, "vdd_l9_l10_l13_l20_l23_l24", },
2421317aa3c4SStephan Gerhold 	{ "l14", 0x4d00, "vdd_l6_l12_l14_l15_l26", },
2422317aa3c4SStephan Gerhold 	{ "l15", 0x4e00, "vdd_l6_l12_l14_l15_l26", },
2423317aa3c4SStephan Gerhold 	{ "l16", 0x4f00, "vdd_l16_l25", },
2424317aa3c4SStephan Gerhold 	{ "l17", 0x5000, "vdd_l17", },
2425317aa3c4SStephan Gerhold 	{ "l18", 0x5100, "vdd_l18", },
2426317aa3c4SStephan Gerhold 	{ "l19", 0x5200, "vdd_l19", },
2427317aa3c4SStephan Gerhold 	{ "l20", 0x5300, "vdd_l9_l10_l13_l20_l23_l24", },
2428317aa3c4SStephan Gerhold 	{ "l21", 0x5400, "vdd_l21", },
2429317aa3c4SStephan Gerhold 	{ "l22", 0x5500, "vdd_l22", },
2430317aa3c4SStephan Gerhold 	{ "l23", 0x5600, "vdd_l9_l10_l13_l20_l23_l24", },
2431317aa3c4SStephan Gerhold 	{ "l24", 0x5700, "vdd_l9_l10_l13_l20_l23_l24", },
2432317aa3c4SStephan Gerhold 	{ "l25", 0x5800, "vdd_l16_l25", },
2433317aa3c4SStephan Gerhold 	{ "l26", 0x5900, "vdd_l6_l12_l14_l15_l26", },
2434317aa3c4SStephan Gerhold 	{ "l27", 0x5a00, "vdd_l2_l3_l4_l27", },
2435317aa3c4SStephan Gerhold 	{ "lvs1", 0x8000, "vdd_lvs1_2", },
2436317aa3c4SStephan Gerhold 	{ "lvs2", 0x8100, "vdd_lvs1_2", },
2437317aa3c4SStephan Gerhold 	{ "lvs3", 0x8200, "vdd_lvs3_4", },
2438317aa3c4SStephan Gerhold 	{ "lvs4", 0x8300, "vdd_lvs3_4", },
2439317aa3c4SStephan Gerhold 	{ "5vs1", 0x8400, "vdd_5vs1", },
2440317aa3c4SStephan Gerhold 	{ }
2441317aa3c4SStephan Gerhold };
2442317aa3c4SStephan Gerhold 
2443ca5cd8c9SRajendra Nayak static const struct spmi_regulator_data pmi8994_regulators[] = {
2444ca5cd8c9SRajendra Nayak 	{ "s1", 0x1400, "vdd_s1", },
2445ca5cd8c9SRajendra Nayak 	{ "s2", 0x1700, "vdd_s2", },
2446ca5cd8c9SRajendra Nayak 	{ "s3", 0x1a00, "vdd_s3", },
2447ca5cd8c9SRajendra Nayak 	{ "l1", 0x4000, "vdd_l1", },
2448ca5cd8c9SRajendra Nayak 	{ }
2449ca5cd8c9SRajendra Nayak };
2450ca5cd8c9SRajendra Nayak 
245134ceb6a6SRobert Marko static const struct spmi_regulator_data pmp8074_regulators[] = {
245234ceb6a6SRobert Marko 	{ "s1", 0x1400, "vdd_s1"},
245334ceb6a6SRobert Marko 	{ "s2", 0x1700, "vdd_s2"},
245434ceb6a6SRobert Marko 	{ "s3", 0x1a00, "vdd_s3"},
245534ceb6a6SRobert Marko 	{ "s4", 0x1d00, "vdd_s4"},
245634ceb6a6SRobert Marko 	{ "s5", 0x2000, "vdd_s5"},
245734ceb6a6SRobert Marko 	{ "l1", 0x4000, "vdd_l1_l2"},
245834ceb6a6SRobert Marko 	{ "l2", 0x4100, "vdd_l1_l2"},
245934ceb6a6SRobert Marko 	{ "l3", 0x4200, "vdd_l3_l8"},
246034ceb6a6SRobert Marko 	{ "l4", 0x4300, "vdd_l4"},
246134ceb6a6SRobert Marko 	{ "l5", 0x4400, "vdd_l5_l6_l15"},
246234ceb6a6SRobert Marko 	{ "l6", 0x4500, "vdd_l5_l6_l15"},
246334ceb6a6SRobert Marko 	{ "l7", 0x4600, "vdd_l7"},
246434ceb6a6SRobert Marko 	{ "l8", 0x4700, "vdd_l3_l8"},
246534ceb6a6SRobert Marko 	{ "l9", 0x4800, "vdd_l9"},
246634ceb6a6SRobert Marko 	/* l10 is currently unsupported HT_P50 */
246734ceb6a6SRobert Marko 	{ "l11", 0x4a00, "vdd_l10_l11_l12_l13"},
246834ceb6a6SRobert Marko 	{ "l12", 0x4b00, "vdd_l10_l11_l12_l13"},
246934ceb6a6SRobert Marko 	{ "l13", 0x4c00, "vdd_l10_l11_l12_l13"},
247034ceb6a6SRobert Marko 	{ }
247134ceb6a6SRobert Marko };
247234ceb6a6SRobert Marko 
24730211f68eSJorge Ramirez static const struct spmi_regulator_data pms405_regulators[] = {
24740211f68eSJorge Ramirez 	{ "s3", 0x1a00, "vdd_s3"},
24750211f68eSJorge Ramirez 	{ }
24760211f68eSJorge Ramirez };
24770211f68eSJorge Ramirez 
2478e92a4047SStephen Boyd static const struct of_device_id qcom_spmi_regulator_match[] = {
2479e62ef4a9SIskren Chernev 	{ .compatible = "qcom,pm6125-regulators", .data = &pm6125_regulators },
24809a2da074SIskren Chernev 	{ .compatible = "qcom,pm660-regulators", .data = &pm660_regulators },
24819a2da074SIskren Chernev 	{ .compatible = "qcom,pm660l-regulators", .data = &pm660l_regulators },
24822e36e140SAngelo G. Del Regno 	{ .compatible = "qcom,pm8004-regulators", .data = &pm8004_regulators },
248342ba89c8SJeffrey Hugo 	{ .compatible = "qcom,pm8005-regulators", .data = &pm8005_regulators },
24845b30cb2aSStephan Gerhold 	{ .compatible = "qcom,pm8019-regulators", .data = &pm8019_regulators },
2485f8843e5eSDominik Kobinski 	{ .compatible = "qcom,pm8226-regulators", .data = &pm8226_regulators },
2486e92a4047SStephen Boyd 	{ .compatible = "qcom,pm8841-regulators", .data = &pm8841_regulators },
2487813d01a4SStephan Gerhold 	{ .compatible = "qcom,pm8909-regulators", .data = &pm8909_regulators },
2488e92a4047SStephen Boyd 	{ .compatible = "qcom,pm8916-regulators", .data = &pm8916_regulators },
2489c0d6b2acSDang Huynh 	{ .compatible = "qcom,pm8937-regulators", .data = &pm8937_regulators },
2490e92a4047SStephen Boyd 	{ .compatible = "qcom,pm8941-regulators", .data = &pm8941_regulators },
2491e4ff1710SAngelo G. Del Regno 	{ .compatible = "qcom,pm8950-regulators", .data = &pm8950_regulators },
249250314e55SStephen Boyd 	{ .compatible = "qcom,pm8994-regulators", .data = &pm8994_regulators },
2493317aa3c4SStephan Gerhold 	{ .compatible = "qcom,pma8084-regulators", .data = &pma8084_regulators },
2494ca5cd8c9SRajendra Nayak 	{ .compatible = "qcom,pmi8994-regulators", .data = &pmi8994_regulators },
249534ceb6a6SRobert Marko 	{ .compatible = "qcom,pmp8074-regulators", .data = &pmp8074_regulators },
24960211f68eSJorge Ramirez 	{ .compatible = "qcom,pms405-regulators", .data = &pms405_regulators },
2497e92a4047SStephen Boyd 	{ }
2498e92a4047SStephen Boyd };
2499e92a4047SStephen Boyd MODULE_DEVICE_TABLE(of, qcom_spmi_regulator_match);
2500e92a4047SStephen Boyd 
qcom_spmi_regulator_probe(struct platform_device * pdev)2501e92a4047SStephen Boyd static int qcom_spmi_regulator_probe(struct platform_device *pdev)
2502e92a4047SStephen Boyd {
2503e92a4047SStephen Boyd 	const struct spmi_regulator_data *reg;
250486f4ff7aSJorge Ramirez-Ortiz 	const struct spmi_voltage_range *range;
2505e92a4047SStephen Boyd 	struct regulator_config config = { };
2506e92a4047SStephen Boyd 	struct regulator_dev *rdev;
2507e92a4047SStephen Boyd 	struct spmi_regulator *vreg;
2508e92a4047SStephen Boyd 	struct regmap *regmap;
2509e92a4047SStephen Boyd 	const char *name;
2510e92a4047SStephen Boyd 	struct device *dev = &pdev->dev;
25110caecaa8SIlia Lin 	struct device_node *node = pdev->dev.of_node;
2512fffe7f52SNiklas Cassel 	struct device_node *syscon, *reg_node;
2513fffe7f52SNiklas Cassel 	struct property *reg_prop;
25140caecaa8SIlia Lin 	int ret, lenp;
2515e92a4047SStephen Boyd 	struct list_head *vreg_list;
2516e92a4047SStephen Boyd 
2517e92a4047SStephen Boyd 	vreg_list = devm_kzalloc(dev, sizeof(*vreg_list), GFP_KERNEL);
2518e92a4047SStephen Boyd 	if (!vreg_list)
2519e92a4047SStephen Boyd 		return -ENOMEM;
2520e92a4047SStephen Boyd 	INIT_LIST_HEAD(vreg_list);
2521e92a4047SStephen Boyd 	platform_set_drvdata(pdev, vreg_list);
2522e92a4047SStephen Boyd 
2523e92a4047SStephen Boyd 	regmap = dev_get_regmap(dev->parent, NULL);
2524e92a4047SStephen Boyd 	if (!regmap)
2525e92a4047SStephen Boyd 		return -ENODEV;
2526e92a4047SStephen Boyd 
25278f7e17d8SRob Herring 	reg = device_get_match_data(&pdev->dev);
25288f7e17d8SRob Herring 	if (!reg)
2529e92a4047SStephen Boyd 		return -ENODEV;
2530e92a4047SStephen Boyd 
25310caecaa8SIlia Lin 	syscon = of_parse_phandle(node, "qcom,saw-reg", 0);
25327540bd33SRob Herring (Arm) 	if (syscon) {
25330caecaa8SIlia Lin 		saw_regmap = syscon_node_to_regmap(syscon);
25340caecaa8SIlia Lin 		of_node_put(syscon);
253585046a15SNiklas Cassel 		if (IS_ERR(saw_regmap))
25360caecaa8SIlia Lin 			dev_err(dev, "ERROR reading SAW regmap\n");
25370caecaa8SIlia Lin 	}
25380caecaa8SIlia Lin 
25398f7e17d8SRob Herring 	for (; reg->name; reg++) {
25400caecaa8SIlia Lin 
2541fffe7f52SNiklas Cassel 		if (saw_regmap) {
2542fffe7f52SNiklas Cassel 			reg_node = of_get_child_by_name(node, reg->name);
2543fffe7f52SNiklas Cassel 			reg_prop = of_find_property(reg_node, "qcom,saw-slave",
2544fffe7f52SNiklas Cassel 						    &lenp);
2545fffe7f52SNiklas Cassel 			of_node_put(reg_node);
2546fffe7f52SNiklas Cassel 			if (reg_prop)
25470caecaa8SIlia Lin 				continue;
25480caecaa8SIlia Lin 		}
25490caecaa8SIlia Lin 
2550e92a4047SStephen Boyd 		vreg = devm_kzalloc(dev, sizeof(*vreg), GFP_KERNEL);
2551e92a4047SStephen Boyd 		if (!vreg)
2552e92a4047SStephen Boyd 			return -ENOMEM;
2553e92a4047SStephen Boyd 
2554e92a4047SStephen Boyd 		vreg->dev = dev;
2555e92a4047SStephen Boyd 		vreg->base = reg->base;
2556e92a4047SStephen Boyd 		vreg->regmap = regmap;
2557e92a4047SStephen Boyd 		if (reg->ocp) {
2558e92a4047SStephen Boyd 			vreg->ocp_irq = platform_get_irq_byname(pdev, reg->ocp);
2559b6688015SMatti Vaittinen 			if (vreg->ocp_irq < 0)
2560b6688015SMatti Vaittinen 				return vreg->ocp_irq;
2561e92a4047SStephen Boyd 		}
2562e92a4047SStephen Boyd 		vreg->desc.id = -1;
2563e92a4047SStephen Boyd 		vreg->desc.owner = THIS_MODULE;
2564e92a4047SStephen Boyd 		vreg->desc.type = REGULATOR_VOLTAGE;
25659d485332SAxel Lin 		vreg->desc.enable_reg = reg->base + SPMI_COMMON_REG_ENABLE;
25669d485332SAxel Lin 		vreg->desc.enable_mask = SPMI_COMMON_ENABLE_MASK;
25679d485332SAxel Lin 		vreg->desc.enable_val = SPMI_COMMON_ENABLE;
2568e92a4047SStephen Boyd 		vreg->desc.name = name = reg->name;
2569e92a4047SStephen Boyd 		vreg->desc.supply_name = reg->supply;
2570e92a4047SStephen Boyd 		vreg->desc.of_match = reg->name;
2571e92a4047SStephen Boyd 		vreg->desc.of_parse_cb = spmi_regulator_of_parse;
2572e92a4047SStephen Boyd 		vreg->desc.of_map_mode = spmi_regulator_of_map_mode;
2573e92a4047SStephen Boyd 
2574e92a4047SStephen Boyd 		ret = spmi_regulator_match(vreg, reg->force_type);
2575e92a4047SStephen Boyd 		if (ret)
25766ee5c044SStephen Boyd 			continue;
2577e92a4047SStephen Boyd 
2578fffe7f52SNiklas Cassel 		if (saw_regmap) {
2579fffe7f52SNiklas Cassel 			reg_node = of_get_child_by_name(node, reg->name);
2580dd72a3b8SRob Herring (Arm) 			if (of_property_read_bool(reg_node, "qcom,saw-leader")) {
25810caecaa8SIlia Lin 				spmi_saw_ops = *(vreg->desc.ops);
2582fffe7f52SNiklas Cassel 				spmi_saw_ops.set_voltage_sel =
25830caecaa8SIlia Lin 					spmi_regulator_saw_set_voltage;
25840caecaa8SIlia Lin 				vreg->desc.ops = &spmi_saw_ops;
25850caecaa8SIlia Lin 			}
2586dd72a3b8SRob Herring (Arm) 			of_node_put(reg_node);
2587fffe7f52SNiklas Cassel 		}
25880caecaa8SIlia Lin 
2589b01d1823SJeffrey Hugo 		if (vreg->set_points && vreg->set_points->count == 1) {
259086f4ff7aSJorge Ramirez-Ortiz 			/* since there is only one range */
259186f4ff7aSJorge Ramirez-Ortiz 			range = vreg->set_points->range;
259286f4ff7aSJorge Ramirez-Ortiz 			vreg->desc.uV_step = range->step_uV;
259386f4ff7aSJorge Ramirez-Ortiz 		}
259486f4ff7aSJorge Ramirez-Ortiz 
2595e92a4047SStephen Boyd 		config.dev = dev;
2596e92a4047SStephen Boyd 		config.driver_data = vreg;
25979d485332SAxel Lin 		config.regmap = regmap;
2598e92a4047SStephen Boyd 		rdev = devm_regulator_register(dev, &vreg->desc, &config);
2599e92a4047SStephen Boyd 		if (IS_ERR(rdev)) {
2600e92a4047SStephen Boyd 			dev_err(dev, "failed to register %s\n", name);
2601b6688015SMatti Vaittinen 			return PTR_ERR(rdev);
2602e92a4047SStephen Boyd 		}
2603e92a4047SStephen Boyd 
2604e92a4047SStephen Boyd 		INIT_LIST_HEAD(&vreg->node);
2605e92a4047SStephen Boyd 		list_add(&vreg->node, vreg_list);
2606e92a4047SStephen Boyd 	}
2607e92a4047SStephen Boyd 
2608e92a4047SStephen Boyd 	return 0;
2609e92a4047SStephen Boyd }
2610e92a4047SStephen Boyd 
2611e92a4047SStephen Boyd static struct platform_driver qcom_spmi_regulator_driver = {
2612e92a4047SStephen Boyd 	.driver		= {
2613e92a4047SStephen Boyd 		.name	= "qcom-spmi-regulator",
2614259b93b2SDouglas Anderson 		.probe_type = PROBE_PREFER_ASYNCHRONOUS,
2615e92a4047SStephen Boyd 		.of_match_table = qcom_spmi_regulator_match,
2616e92a4047SStephen Boyd 	},
2617e92a4047SStephen Boyd 	.probe		= qcom_spmi_regulator_probe,
2618e92a4047SStephen Boyd };
2619e92a4047SStephen Boyd module_platform_driver(qcom_spmi_regulator_driver);
2620e92a4047SStephen Boyd 
2621e92a4047SStephen Boyd MODULE_DESCRIPTION("Qualcomm SPMI PMIC regulator driver");
2622e92a4047SStephen Boyd MODULE_LICENSE("GPL v2");
2623e92a4047SStephen Boyd MODULE_ALIAS("platform:qcom-spmi-regulator");
2624