1 // SPDX-License-Identifier: GPL-2.0-only
3 * pmic-cpcap.c - CPCAP-specific functions for the OPP code
5 * Adapted from Motorola Mapphone Android Linux kernel
6 * Copyright (C) 2011 Motorola, Inc.
11 #include <linux/kernel.h>
17 #include <linux/init.h>
21 * omap_cpcap_vsel_to_vdc - convert CPCAP VSEL value to microvolts DC
22 * @vsel: CPCAP VSEL value to convert
24 * Returns the microvolts DC that the CPCAP PMIC should generate when
25 * programmed with @vsel.
27 static unsigned long omap_cpcap_vsel_to_uv(unsigned char vsel
)
31 return (((vsel
* 125) + 6000)) * 100;
35 * omap_cpcap_uv_to_vsel - convert microvolts DC to CPCAP VSEL value
36 * @uv: microvolts DC to convert
38 * Returns the VSEL value necessary for the CPCAP PMIC to
39 * generate an output voltage equal to or greater than @uv microvolts DC.
41 static unsigned char omap_cpcap_uv_to_vsel(unsigned long uv
)
45 else if (uv
> 1450000)
47 return DIV_ROUND_UP(uv
- 600000, 12500);
50 static struct omap_voltdm_pmic omap_cpcap_core
= {
53 .vp_erroroffset
= OMAP4_VP_CONFIG_ERROROFFSET
,
54 .vp_vstepmin
= OMAP4_VP_VSTEPMIN_VSTEPMIN
,
55 .vp_vstepmax
= OMAP4_VP_VSTEPMAX_VSTEPMAX
,
58 .vp_timeout_us
= OMAP4_VP_VLIMITTO_TIMEOUT_US
,
59 .i2c_slave_addr
= 0x02,
60 .volt_reg_addr
= 0x00,
62 .i2c_high_speed
= false,
63 .vsel_to_uv
= omap_cpcap_vsel_to_uv
,
64 .uv_to_vsel
= omap_cpcap_uv_to_vsel
,
67 static struct omap_voltdm_pmic omap_cpcap_iva
= {
70 .vp_erroroffset
= OMAP4_VP_CONFIG_ERROROFFSET
,
71 .vp_vstepmin
= OMAP4_VP_VSTEPMIN_VSTEPMIN
,
72 .vp_vstepmax
= OMAP4_VP_VSTEPMAX_VSTEPMAX
,
75 .vp_timeout_us
= OMAP4_VP_VLIMITTO_TIMEOUT_US
,
76 .i2c_slave_addr
= 0x44,
79 .i2c_high_speed
= false,
80 .vsel_to_uv
= omap_cpcap_vsel_to_uv
,
81 .uv_to_vsel
= omap_cpcap_uv_to_vsel
,
85 * omap_max8952_vsel_to_vdc - convert MAX8952 VSEL value to microvolts DC
86 * @vsel: MAX8952 VSEL value to convert
88 * Returns the microvolts DC that the MAX8952 Regulator should generate when
89 * programmed with @vsel.
91 static unsigned long omap_max8952_vsel_to_uv(unsigned char vsel
)
95 return (((vsel
* 100) + 7700)) * 100;
99 * omap_max8952_uv_to_vsel - convert microvolts DC to MAX8952 VSEL value
100 * @uv: microvolts DC to convert
102 * Returns the VSEL value necessary for the MAX8952 Regulator to
103 * generate an output voltage equal to or greater than @uv microvolts DC.
105 static unsigned char omap_max8952_uv_to_vsel(unsigned long uv
)
109 else if (uv
> 1400000)
111 return DIV_ROUND_UP(uv
- 770000, 10000);
114 static struct omap_voltdm_pmic omap443x_max8952_mpu
= {
117 .vp_erroroffset
= OMAP4_VP_CONFIG_ERROROFFSET
,
118 .vp_vstepmin
= OMAP4_VP_VSTEPMIN_VSTEPMIN
,
119 .vp_vstepmax
= OMAP4_VP_VSTEPMAX_VSTEPMAX
,
122 .vp_timeout_us
= OMAP4_VP_VLIMITTO_TIMEOUT_US
,
123 .i2c_slave_addr
= 0x60,
124 .volt_reg_addr
= 0x03,
125 .cmd_reg_addr
= 0x03,
126 .i2c_high_speed
= false,
127 .vsel_to_uv
= omap_max8952_vsel_to_uv
,
128 .uv_to_vsel
= omap_max8952_uv_to_vsel
,
132 * omap_fan5355_vsel_to_vdc - convert FAN535503 VSEL value to microvolts DC
133 * @vsel: FAN535503 VSEL value to convert
135 * Returns the microvolts DC that the FAN535503 Regulator should generate when
136 * programmed with @vsel.
138 static unsigned long omap_fan535503_vsel_to_uv(unsigned char vsel
)
140 /* Extract bits[5:0] */
143 return (((vsel
* 125) + 7500)) * 100;
147 * omap_fan535508_vsel_to_vdc - convert FAN535508 VSEL value to microvolts DC
148 * @vsel: FAN535508 VSEL value to convert
150 * Returns the microvolts DC that the FAN535508 Regulator should generate when
151 * programmed with @vsel.
153 static unsigned long omap_fan535508_vsel_to_uv(unsigned char vsel
)
155 /* Extract bits[5:0] */
160 return (((vsel
* 125) + 7500)) * 100;
165 * omap_fan535503_uv_to_vsel - convert microvolts DC to FAN535503 VSEL value
166 * @uv: microvolts DC to convert
168 * Returns the VSEL value necessary for the MAX8952 Regulator to
169 * generate an output voltage equal to or greater than @uv microvolts DC.
171 static unsigned char omap_fan535503_uv_to_vsel(unsigned long uv
)
176 else if (uv
> 1537500)
179 vsel
= DIV_ROUND_UP(uv
- 750000, 12500);
184 * omap_fan535508_uv_to_vsel - convert microvolts DC to FAN535508 VSEL value
185 * @uv: microvolts DC to convert
187 * Returns the VSEL value necessary for the MAX8952 Regulator to
188 * generate an output voltage equal to or greater than @uv microvolts DC.
190 static unsigned char omap_fan535508_uv_to_vsel(unsigned long uv
)
195 else if (uv
> 1437500)
198 vsel
= DIV_ROUND_UP(uv
- 750000, 12500);
203 static struct omap_voltdm_pmic omap4_fan_core
= {
206 .vp_erroroffset
= OMAP4_VP_CONFIG_ERROROFFSET
,
207 .vp_vstepmin
= OMAP4_VP_VSTEPMIN_VSTEPMIN
,
208 .vp_vstepmax
= OMAP4_VP_VSTEPMAX_VSTEPMAX
,
211 .vp_timeout_us
= OMAP4_VP_VLIMITTO_TIMEOUT_US
,
212 .i2c_slave_addr
= 0x4A,
213 .i2c_high_speed
= false,
214 .volt_reg_addr
= 0x01,
215 .cmd_reg_addr
= 0x01,
216 .vsel_to_uv
= omap_fan535508_vsel_to_uv
,
217 .uv_to_vsel
= omap_fan535508_uv_to_vsel
,
221 static struct omap_voltdm_pmic omap4_fan_iva
= {
224 .vp_erroroffset
= OMAP4_VP_CONFIG_ERROROFFSET
,
225 .vp_vstepmin
= OMAP4_VP_VSTEPMIN_VSTEPMIN
,
226 .vp_vstepmax
= OMAP4_VP_VSTEPMAX_VSTEPMAX
,
229 .vp_timeout_us
= OMAP4_VP_VLIMITTO_TIMEOUT_US
,
230 .i2c_slave_addr
= 0x48,
231 .volt_reg_addr
= 0x01,
232 .cmd_reg_addr
= 0x01,
233 .i2c_high_speed
= false,
234 .vsel_to_uv
= omap_fan535503_vsel_to_uv
,
235 .uv_to_vsel
= omap_fan535503_uv_to_vsel
,
238 int __init
omap4_cpcap_init(void)
240 struct voltagedomain
*voltdm
;
242 if (!of_find_compatible_node(NULL
, NULL
, "motorola,cpcap"))
245 voltdm
= voltdm_lookup("mpu");
246 omap_voltage_register_pmic(voltdm
, &omap443x_max8952_mpu
);
248 if (of_machine_is_compatible("motorola,droid-bionic")) {
249 voltdm
= voltdm_lookup("mpu");
250 omap_voltage_register_pmic(voltdm
, &omap_cpcap_core
);
252 voltdm
= voltdm_lookup("mpu");
253 omap_voltage_register_pmic(voltdm
, &omap_cpcap_iva
);
255 voltdm
= voltdm_lookup("core");
256 omap_voltage_register_pmic(voltdm
, &omap4_fan_core
);
258 voltdm
= voltdm_lookup("iva");
259 omap_voltage_register_pmic(voltdm
, &omap4_fan_iva
);
265 static int __init
cpcap_late_init(void)
267 omap4_vc_set_pmic_signaling(PWRDM_POWER_RET
);
271 omap_late_initcall(cpcap_late_init
);