blob: 6787f1e72c6be2d4ae68055788bacdbb20faf108 [file] [log] [blame]
Thomas Gleixnerd2912cb2019-06-04 10:11:33 +02001// SPDX-License-Identifier: GPL-2.0-only
Thara Gopinathfbc319f2010-12-10 22:51:05 +05302/**
Masahiro Yamada183b8022017-02-27 14:29:20 -08003 * OMAP and TWL PMIC specific initializations.
Thara Gopinathfbc319f2010-12-10 22:51:05 +05304 *
5 * Copyright (C) 2010 Texas Instruments Incorporated.
6 * Thara Gopinath
7 * Copyright (C) 2009 Texas Instruments Incorporated.
8 * Nishanth Menon
9 * Copyright (C) 2009 Nokia Corporation
10 * Paul Walmsley
Thara Gopinathfbc319f2010-12-10 22:51:05 +053011 */
12
13#include <linux/err.h>
14#include <linux/io.h>
15#include <linux/kernel.h>
Wolfram Sanga2054252017-08-14 18:34:24 +020016#include <linux/mfd/twl.h>
Thara Gopinathfbc319f2010-12-10 22:51:05 +053017
Tony Lindgrene4c060d2012-10-05 13:25:59 -070018#include "soc.h"
Paul Walmsleye1d6f472011-02-25 15:54:33 -070019#include "voltage.h"
Thara Gopinathfbc319f2010-12-10 22:51:05 +053020
Nishanth Menondda0aea2011-01-03 12:58:30 -060021#include "pm.h"
22
Thara Gopinathfbc319f2010-12-10 22:51:05 +053023#define OMAP3_SRI2C_SLAVE_ADDR 0x12
24#define OMAP3_VDD_MPU_SR_CONTROL_REG 0x00
25#define OMAP3_VDD_CORE_SR_CONTROL_REG 0x01
26#define OMAP3_VP_CONFIG_ERROROFFSET 0x00
27#define OMAP3_VP_VSTEPMIN_VSTEPMIN 0x1
28#define OMAP3_VP_VSTEPMAX_VSTEPMAX 0x04
29#define OMAP3_VP_VLIMITTO_TIMEOUT_US 200
30
Thara Gopinath7bc3ed92010-12-10 23:15:16 +053031#define OMAP4_SRI2C_SLAVE_ADDR 0x12
32#define OMAP4_VDD_MPU_SR_VOLT_REG 0x55
Nishanth Menonee7fbba2011-05-18 00:17:34 -050033#define OMAP4_VDD_MPU_SR_CMD_REG 0x56
Thara Gopinath7bc3ed92010-12-10 23:15:16 +053034#define OMAP4_VDD_IVA_SR_VOLT_REG 0x5B
Nishanth Menonee7fbba2011-05-18 00:17:34 -050035#define OMAP4_VDD_IVA_SR_CMD_REG 0x5C
Thara Gopinath7bc3ed92010-12-10 23:15:16 +053036#define OMAP4_VDD_CORE_SR_VOLT_REG 0x61
Nishanth Menonee7fbba2011-05-18 00:17:34 -050037#define OMAP4_VDD_CORE_SR_CMD_REG 0x62
Thara Gopinath7bc3ed92010-12-10 23:15:16 +053038
39#define OMAP4_VP_CONFIG_ERROROFFSET 0x00
40#define OMAP4_VP_VSTEPMIN_VSTEPMIN 0x01
41#define OMAP4_VP_VSTEPMAX_VSTEPMAX 0x04
42#define OMAP4_VP_VLIMITTO_TIMEOUT_US 200
43
Thara Gopinath7bc3ed92010-12-10 23:15:16 +053044static bool is_offset_valid;
45static u8 smps_offset;
46
47#define REG_SMPS_OFFSET 0xE0
48
Nishanth Menonc84ff1c2011-01-03 12:58:29 -060049static unsigned long twl4030_vsel_to_uv(const u8 vsel)
Thara Gopinathfbc319f2010-12-10 22:51:05 +053050{
51 return (((vsel * 125) + 6000)) * 100;
52}
53
Nishanth Menonc84ff1c2011-01-03 12:58:29 -060054static u8 twl4030_uv_to_vsel(unsigned long uv)
Thara Gopinathfbc319f2010-12-10 22:51:05 +053055{
56 return DIV_ROUND_UP(uv - 600000, 12500);
57}
58
Nishanth Menonc84ff1c2011-01-03 12:58:29 -060059static unsigned long twl6030_vsel_to_uv(const u8 vsel)
Thara Gopinath7bc3ed92010-12-10 23:15:16 +053060{
61 /*
62 * In TWL6030 depending on the value of SMPS_OFFSET
63 * efuse register the voltage range supported in
64 * standard mode can be either between 0.6V - 1.3V or
65 * 0.7V - 1.4V. In TWL6030 ES1.0 SMPS_OFFSET efuse
66 * is programmed to all 0's where as starting from
67 * TWL6030 ES1.1 the efuse is programmed to 1
68 */
69 if (!is_offset_valid) {
70 twl_i2c_read_u8(TWL6030_MODULE_ID0, &smps_offset,
71 REG_SMPS_OFFSET);
72 is_offset_valid = true;
73 }
74
Nishanth Menon2aed5b92011-05-18 00:17:32 -050075 if (!vsel)
76 return 0;
Thara Gopinath7bc3ed92010-12-10 23:15:16 +053077 /*
78 * There is no specific formula for voltage to vsel
79 * conversion above 1.3V. There are special hardcoded
80 * values for voltages above 1.3V. Currently we are
81 * hardcoding only for 1.35 V which is used for 1GH OPP for
82 * OMAP4430.
83 */
84 if (vsel == 0x3A)
85 return 1350000;
86
87 if (smps_offset & 0x8)
Patrick Titiano58e241f2011-05-18 00:17:30 -050088 return ((((vsel - 1) * 1266) + 70900)) * 10;
Thara Gopinath7bc3ed92010-12-10 23:15:16 +053089 else
Patrick Titiano58e241f2011-05-18 00:17:30 -050090 return ((((vsel - 1) * 1266) + 60770)) * 10;
Thara Gopinath7bc3ed92010-12-10 23:15:16 +053091}
92
Nishanth Menonc84ff1c2011-01-03 12:58:29 -060093static u8 twl6030_uv_to_vsel(unsigned long uv)
Thara Gopinath7bc3ed92010-12-10 23:15:16 +053094{
95 /*
96 * In TWL6030 depending on the value of SMPS_OFFSET
97 * efuse register the voltage range supported in
98 * standard mode can be either between 0.6V - 1.3V or
99 * 0.7V - 1.4V. In TWL6030 ES1.0 SMPS_OFFSET efuse
100 * is programmed to all 0's where as starting from
101 * TWL6030 ES1.1 the efuse is programmed to 1
102 */
103 if (!is_offset_valid) {
104 twl_i2c_read_u8(TWL6030_MODULE_ID0, &smps_offset,
105 REG_SMPS_OFFSET);
106 is_offset_valid = true;
107 }
108
Nishanth Menon2aed5b92011-05-18 00:17:32 -0500109 if (!uv)
110 return 0x00;
Thara Gopinath7bc3ed92010-12-10 23:15:16 +0530111 /*
112 * There is no specific formula for voltage to vsel
113 * conversion above 1.3V. There are special hardcoded
114 * values for voltages above 1.3V. Currently we are
115 * hardcoding only for 1.35 V which is used for 1GH OPP for
116 * OMAP4430.
117 */
Nishanth Menon36649422011-05-18 00:17:31 -0500118 if (uv > twl6030_vsel_to_uv(0x39)) {
119 if (uv == 1350000)
120 return 0x3A;
121 pr_err("%s:OUT OF RANGE! non mapped vsel for %ld Vs max %ld\n",
122 __func__, uv, twl6030_vsel_to_uv(0x39));
Thara Gopinath7bc3ed92010-12-10 23:15:16 +0530123 return 0x3A;
Nishanth Menon36649422011-05-18 00:17:31 -0500124 }
Thara Gopinath7bc3ed92010-12-10 23:15:16 +0530125
126 if (smps_offset & 0x8)
Patrick Titiano58e241f2011-05-18 00:17:30 -0500127 return DIV_ROUND_UP(uv - 709000, 12660) + 1;
Thara Gopinath7bc3ed92010-12-10 23:15:16 +0530128 else
Patrick Titiano58e241f2011-05-18 00:17:30 -0500129 return DIV_ROUND_UP(uv - 607700, 12660) + 1;
Thara Gopinath7bc3ed92010-12-10 23:15:16 +0530130}
131
Kevin Hilmance8ebe02011-03-30 11:01:10 -0700132static struct omap_voltdm_pmic omap3_mpu_pmic = {
Thara Gopinathfbc319f2010-12-10 22:51:05 +0530133 .slew_rate = 4000,
134 .step_size = 12500,
Thara Gopinathfbc319f2010-12-10 22:51:05 +0530135 .vp_erroroffset = OMAP3_VP_CONFIG_ERROROFFSET,
136 .vp_vstepmin = OMAP3_VP_VSTEPMIN_VSTEPMIN,
137 .vp_vstepmax = OMAP3_VP_VSTEPMAX_VSTEPMAX,
Tero Kristo5a84dc52012-09-25 19:33:42 +0300138 .vddmin = 600000,
139 .vddmax = 1450000,
Thara Gopinathfbc319f2010-12-10 22:51:05 +0530140 .vp_timeout_us = OMAP3_VP_VLIMITTO_TIMEOUT_US,
141 .i2c_slave_addr = OMAP3_SRI2C_SLAVE_ADDR,
Kevin Hilmane74e4402011-03-22 14:12:37 -0700142 .volt_reg_addr = OMAP3_VDD_MPU_SR_CONTROL_REG,
Kevin Hilmanf5395482011-03-30 16:36:30 -0700143 .i2c_high_speed = true,
Thara Gopinathfbc319f2010-12-10 22:51:05 +0530144 .vsel_to_uv = twl4030_vsel_to_uv,
145 .uv_to_vsel = twl4030_uv_to_vsel,
146};
147
Kevin Hilmance8ebe02011-03-30 11:01:10 -0700148static struct omap_voltdm_pmic omap3_core_pmic = {
Thara Gopinathfbc319f2010-12-10 22:51:05 +0530149 .slew_rate = 4000,
150 .step_size = 12500,
Thara Gopinathfbc319f2010-12-10 22:51:05 +0530151 .vp_erroroffset = OMAP3_VP_CONFIG_ERROROFFSET,
152 .vp_vstepmin = OMAP3_VP_VSTEPMIN_VSTEPMIN,
153 .vp_vstepmax = OMAP3_VP_VSTEPMAX_VSTEPMAX,
Tero Kristo5a84dc52012-09-25 19:33:42 +0300154 .vddmin = 600000,
155 .vddmax = 1450000,
Thara Gopinathfbc319f2010-12-10 22:51:05 +0530156 .vp_timeout_us = OMAP3_VP_VLIMITTO_TIMEOUT_US,
157 .i2c_slave_addr = OMAP3_SRI2C_SLAVE_ADDR,
Kevin Hilmane74e4402011-03-22 14:12:37 -0700158 .volt_reg_addr = OMAP3_VDD_CORE_SR_CONTROL_REG,
Kevin Hilmanf5395482011-03-30 16:36:30 -0700159 .i2c_high_speed = true,
Thara Gopinathfbc319f2010-12-10 22:51:05 +0530160 .vsel_to_uv = twl4030_vsel_to_uv,
161 .uv_to_vsel = twl4030_uv_to_vsel,
162};
163
Kevin Hilmance8ebe02011-03-30 11:01:10 -0700164static struct omap_voltdm_pmic omap4_mpu_pmic = {
Thara Gopinath7bc3ed92010-12-10 23:15:16 +0530165 .slew_rate = 4000,
Patrick Titiano58e241f2011-05-18 00:17:30 -0500166 .step_size = 12660,
Thara Gopinath7bc3ed92010-12-10 23:15:16 +0530167 .vp_erroroffset = OMAP4_VP_CONFIG_ERROROFFSET,
168 .vp_vstepmin = OMAP4_VP_VSTEPMIN_VSTEPMIN,
169 .vp_vstepmax = OMAP4_VP_VSTEPMAX_VSTEPMAX,
Tero Kristo5a84dc52012-09-25 19:33:42 +0300170 .vddmin = 0,
171 .vddmax = 2100000,
Thara Gopinath7bc3ed92010-12-10 23:15:16 +0530172 .vp_timeout_us = OMAP4_VP_VLIMITTO_TIMEOUT_US,
173 .i2c_slave_addr = OMAP4_SRI2C_SLAVE_ADDR,
Kevin Hilmane74e4402011-03-22 14:12:37 -0700174 .volt_reg_addr = OMAP4_VDD_MPU_SR_VOLT_REG,
Nishanth Menonee7fbba2011-05-18 00:17:34 -0500175 .cmd_reg_addr = OMAP4_VDD_MPU_SR_CMD_REG,
Kevin Hilmanf5395482011-03-30 16:36:30 -0700176 .i2c_high_speed = true,
Tero Kristo00bd2282012-09-25 19:33:48 +0300177 .i2c_pad_load = 3,
Thara Gopinath7bc3ed92010-12-10 23:15:16 +0530178 .vsel_to_uv = twl6030_vsel_to_uv,
179 .uv_to_vsel = twl6030_uv_to_vsel,
180};
181
Kevin Hilmance8ebe02011-03-30 11:01:10 -0700182static struct omap_voltdm_pmic omap4_iva_pmic = {
Thara Gopinath7bc3ed92010-12-10 23:15:16 +0530183 .slew_rate = 4000,
Patrick Titiano58e241f2011-05-18 00:17:30 -0500184 .step_size = 12660,
Thara Gopinath7bc3ed92010-12-10 23:15:16 +0530185 .vp_erroroffset = OMAP4_VP_CONFIG_ERROROFFSET,
186 .vp_vstepmin = OMAP4_VP_VSTEPMIN_VSTEPMIN,
187 .vp_vstepmax = OMAP4_VP_VSTEPMAX_VSTEPMAX,
Tero Kristo5a84dc52012-09-25 19:33:42 +0300188 .vddmin = 0,
189 .vddmax = 2100000,
Thara Gopinath7bc3ed92010-12-10 23:15:16 +0530190 .vp_timeout_us = OMAP4_VP_VLIMITTO_TIMEOUT_US,
191 .i2c_slave_addr = OMAP4_SRI2C_SLAVE_ADDR,
Kevin Hilmane74e4402011-03-22 14:12:37 -0700192 .volt_reg_addr = OMAP4_VDD_IVA_SR_VOLT_REG,
Nishanth Menonee7fbba2011-05-18 00:17:34 -0500193 .cmd_reg_addr = OMAP4_VDD_IVA_SR_CMD_REG,
Kevin Hilmanf5395482011-03-30 16:36:30 -0700194 .i2c_high_speed = true,
Tero Kristo00bd2282012-09-25 19:33:48 +0300195 .i2c_pad_load = 3,
Thara Gopinath7bc3ed92010-12-10 23:15:16 +0530196 .vsel_to_uv = twl6030_vsel_to_uv,
197 .uv_to_vsel = twl6030_uv_to_vsel,
198};
199
Kevin Hilmance8ebe02011-03-30 11:01:10 -0700200static struct omap_voltdm_pmic omap4_core_pmic = {
Thara Gopinath7bc3ed92010-12-10 23:15:16 +0530201 .slew_rate = 4000,
Patrick Titiano58e241f2011-05-18 00:17:30 -0500202 .step_size = 12660,
Thara Gopinath7bc3ed92010-12-10 23:15:16 +0530203 .vp_erroroffset = OMAP4_VP_CONFIG_ERROROFFSET,
204 .vp_vstepmin = OMAP4_VP_VSTEPMIN_VSTEPMIN,
205 .vp_vstepmax = OMAP4_VP_VSTEPMAX_VSTEPMAX,
Tero Kristo5a84dc52012-09-25 19:33:42 +0300206 .vddmin = 0,
207 .vddmax = 2100000,
Thara Gopinath7bc3ed92010-12-10 23:15:16 +0530208 .vp_timeout_us = OMAP4_VP_VLIMITTO_TIMEOUT_US,
209 .i2c_slave_addr = OMAP4_SRI2C_SLAVE_ADDR,
Kevin Hilmane74e4402011-03-22 14:12:37 -0700210 .volt_reg_addr = OMAP4_VDD_CORE_SR_VOLT_REG,
Nishanth Menonee7fbba2011-05-18 00:17:34 -0500211 .cmd_reg_addr = OMAP4_VDD_CORE_SR_CMD_REG,
Tero Kristo83b5b552012-09-25 19:33:49 +0300212 .i2c_high_speed = true,
Tero Kristo00bd2282012-09-25 19:33:48 +0300213 .i2c_pad_load = 3,
Thara Gopinath7bc3ed92010-12-10 23:15:16 +0530214 .vsel_to_uv = twl6030_vsel_to_uv,
215 .uv_to_vsel = twl6030_uv_to_vsel,
216};
217
218int __init omap4_twl_init(void)
219{
220 struct voltagedomain *voltdm;
221
222 if (!cpu_is_omap44xx())
223 return -ENODEV;
224
Kevin Hilman81a60482011-03-16 14:25:45 -0700225 voltdm = voltdm_lookup("mpu");
Kevin Hilmance8ebe02011-03-30 11:01:10 -0700226 omap_voltage_register_pmic(voltdm, &omap4_mpu_pmic);
Thara Gopinath7bc3ed92010-12-10 23:15:16 +0530227
Kevin Hilman81a60482011-03-16 14:25:45 -0700228 voltdm = voltdm_lookup("iva");
Kevin Hilmance8ebe02011-03-30 11:01:10 -0700229 omap_voltage_register_pmic(voltdm, &omap4_iva_pmic);
Thara Gopinath7bc3ed92010-12-10 23:15:16 +0530230
Kevin Hilman81a60482011-03-16 14:25:45 -0700231 voltdm = voltdm_lookup("core");
Kevin Hilmance8ebe02011-03-30 11:01:10 -0700232 omap_voltage_register_pmic(voltdm, &omap4_core_pmic);
Thara Gopinath7bc3ed92010-12-10 23:15:16 +0530233
234 return 0;
235}
236
Thara Gopinathfbc319f2010-12-10 22:51:05 +0530237int __init omap3_twl_init(void)
238{
239 struct voltagedomain *voltdm;
240
241 if (!cpu_is_omap34xx())
242 return -ENODEV;
243
Kevin Hilman280a7272011-03-23 11:18:08 -0700244 voltdm = voltdm_lookup("mpu_iva");
Kevin Hilmance8ebe02011-03-30 11:01:10 -0700245 omap_voltage_register_pmic(voltdm, &omap3_mpu_pmic);
Thara Gopinathfbc319f2010-12-10 22:51:05 +0530246
Kevin Hilman81a60482011-03-16 14:25:45 -0700247 voltdm = voltdm_lookup("core");
Kevin Hilmance8ebe02011-03-30 11:01:10 -0700248 omap_voltage_register_pmic(voltdm, &omap3_core_pmic);
Thara Gopinathfbc319f2010-12-10 22:51:05 +0530249
250 return 0;
251}