Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Driver for Regulator part of Palmas PMIC Chips |
| 3 | * |
Graeme Gregory | 7be859f | 2013-03-07 13:17:48 +0000 | [diff] [blame] | 4 | * Copyright 2011-2013 Texas Instruments Inc. |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 5 | * |
| 6 | * Author: Graeme Gregory <gg@slimlogic.co.uk> |
Graeme Gregory | a7dddf2 | 2013-02-23 16:35:40 +0000 | [diff] [blame] | 7 | * Author: Ian Lartey <ian@slimlogic.co.uk> |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 8 | * |
| 9 | * This program is free software; you can redistribute it and/or modify it |
| 10 | * under the terms of the GNU General Public License as published by the |
| 11 | * Free Software Foundation; either version 2 of the License, or (at your |
| 12 | * option) any later version. |
| 13 | * |
| 14 | */ |
| 15 | |
| 16 | #include <linux/kernel.h> |
| 17 | #include <linux/module.h> |
| 18 | #include <linux/init.h> |
| 19 | #include <linux/err.h> |
| 20 | #include <linux/platform_device.h> |
| 21 | #include <linux/regulator/driver.h> |
| 22 | #include <linux/regulator/machine.h> |
| 23 | #include <linux/slab.h> |
| 24 | #include <linux/regmap.h> |
| 25 | #include <linux/mfd/palmas.h> |
Graeme Gregory | a361cd9 | 2012-08-28 13:47:40 +0200 | [diff] [blame] | 26 | #include <linux/of.h> |
| 27 | #include <linux/of_platform.h> |
| 28 | #include <linux/regulator/of_regulator.h> |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 29 | |
| 30 | struct regs_info { |
| 31 | char *name; |
Laxman Dewangan | 504382c | 2013-03-20 19:26:37 +0530 | [diff] [blame] | 32 | char *sname; |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 33 | u8 vsel_addr; |
| 34 | u8 ctrl_addr; |
| 35 | u8 tstep_addr; |
Laxman Dewangan | 32b6d3f | 2013-08-21 16:18:16 +0530 | [diff] [blame] | 36 | int sleep_id; |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 37 | }; |
| 38 | |
Keerthy | dbabd62 | 2014-05-22 14:48:29 +0530 | [diff] [blame] | 39 | static const struct regulator_linear_range smps_low_ranges[] = { |
Nishanth Menon | 6b7f2d8 | 2014-06-04 14:34:31 -0500 | [diff] [blame] | 40 | REGULATOR_LINEAR_RANGE(0, 0x0, 0x0, 0), |
Keerthy | dbabd62 | 2014-05-22 14:48:29 +0530 | [diff] [blame] | 41 | REGULATOR_LINEAR_RANGE(500000, 0x1, 0x6, 0), |
| 42 | REGULATOR_LINEAR_RANGE(510000, 0x7, 0x79, 10000), |
| 43 | REGULATOR_LINEAR_RANGE(1650000, 0x7A, 0x7f, 0), |
| 44 | }; |
| 45 | |
| 46 | static const struct regulator_linear_range smps_high_ranges[] = { |
Nishanth Menon | 6b7f2d8 | 2014-06-04 14:34:31 -0500 | [diff] [blame] | 47 | REGULATOR_LINEAR_RANGE(0, 0x0, 0x0, 0), |
Keerthy | dbabd62 | 2014-05-22 14:48:29 +0530 | [diff] [blame] | 48 | REGULATOR_LINEAR_RANGE(1000000, 0x1, 0x6, 0), |
| 49 | REGULATOR_LINEAR_RANGE(1020000, 0x7, 0x79, 20000), |
| 50 | REGULATOR_LINEAR_RANGE(3300000, 0x7A, 0x7f, 0), |
| 51 | }; |
| 52 | |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 53 | static const struct regs_info palmas_regs_info[] = { |
| 54 | { |
| 55 | .name = "SMPS12", |
Laxman Dewangan | 504382c | 2013-03-20 19:26:37 +0530 | [diff] [blame] | 56 | .sname = "smps1-in", |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 57 | .vsel_addr = PALMAS_SMPS12_VOLTAGE, |
| 58 | .ctrl_addr = PALMAS_SMPS12_CTRL, |
| 59 | .tstep_addr = PALMAS_SMPS12_TSTEP, |
Laxman Dewangan | 32b6d3f | 2013-08-21 16:18:16 +0530 | [diff] [blame] | 60 | .sleep_id = PALMAS_EXTERNAL_REQSTR_ID_SMPS12, |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 61 | }, |
| 62 | { |
| 63 | .name = "SMPS123", |
Laxman Dewangan | 504382c | 2013-03-20 19:26:37 +0530 | [diff] [blame] | 64 | .sname = "smps1-in", |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 65 | .vsel_addr = PALMAS_SMPS12_VOLTAGE, |
| 66 | .ctrl_addr = PALMAS_SMPS12_CTRL, |
| 67 | .tstep_addr = PALMAS_SMPS12_TSTEP, |
Laxman Dewangan | 32b6d3f | 2013-08-21 16:18:16 +0530 | [diff] [blame] | 68 | .sleep_id = PALMAS_EXTERNAL_REQSTR_ID_SMPS12, |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 69 | }, |
| 70 | { |
| 71 | .name = "SMPS3", |
Laxman Dewangan | 504382c | 2013-03-20 19:26:37 +0530 | [diff] [blame] | 72 | .sname = "smps3-in", |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 73 | .vsel_addr = PALMAS_SMPS3_VOLTAGE, |
| 74 | .ctrl_addr = PALMAS_SMPS3_CTRL, |
Laxman Dewangan | 32b6d3f | 2013-08-21 16:18:16 +0530 | [diff] [blame] | 75 | .sleep_id = PALMAS_EXTERNAL_REQSTR_ID_SMPS3, |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 76 | }, |
| 77 | { |
| 78 | .name = "SMPS45", |
Laxman Dewangan | 504382c | 2013-03-20 19:26:37 +0530 | [diff] [blame] | 79 | .sname = "smps4-in", |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 80 | .vsel_addr = PALMAS_SMPS45_VOLTAGE, |
| 81 | .ctrl_addr = PALMAS_SMPS45_CTRL, |
| 82 | .tstep_addr = PALMAS_SMPS45_TSTEP, |
Laxman Dewangan | 32b6d3f | 2013-08-21 16:18:16 +0530 | [diff] [blame] | 83 | .sleep_id = PALMAS_EXTERNAL_REQSTR_ID_SMPS45, |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 84 | }, |
| 85 | { |
| 86 | .name = "SMPS457", |
Laxman Dewangan | 504382c | 2013-03-20 19:26:37 +0530 | [diff] [blame] | 87 | .sname = "smps4-in", |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 88 | .vsel_addr = PALMAS_SMPS45_VOLTAGE, |
| 89 | .ctrl_addr = PALMAS_SMPS45_CTRL, |
| 90 | .tstep_addr = PALMAS_SMPS45_TSTEP, |
Laxman Dewangan | 32b6d3f | 2013-08-21 16:18:16 +0530 | [diff] [blame] | 91 | .sleep_id = PALMAS_EXTERNAL_REQSTR_ID_SMPS45, |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 92 | }, |
| 93 | { |
| 94 | .name = "SMPS6", |
Laxman Dewangan | 504382c | 2013-03-20 19:26:37 +0530 | [diff] [blame] | 95 | .sname = "smps6-in", |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 96 | .vsel_addr = PALMAS_SMPS6_VOLTAGE, |
| 97 | .ctrl_addr = PALMAS_SMPS6_CTRL, |
| 98 | .tstep_addr = PALMAS_SMPS6_TSTEP, |
Laxman Dewangan | 32b6d3f | 2013-08-21 16:18:16 +0530 | [diff] [blame] | 99 | .sleep_id = PALMAS_EXTERNAL_REQSTR_ID_SMPS6, |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 100 | }, |
| 101 | { |
| 102 | .name = "SMPS7", |
Laxman Dewangan | 504382c | 2013-03-20 19:26:37 +0530 | [diff] [blame] | 103 | .sname = "smps7-in", |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 104 | .vsel_addr = PALMAS_SMPS7_VOLTAGE, |
| 105 | .ctrl_addr = PALMAS_SMPS7_CTRL, |
Laxman Dewangan | 32b6d3f | 2013-08-21 16:18:16 +0530 | [diff] [blame] | 106 | .sleep_id = PALMAS_EXTERNAL_REQSTR_ID_SMPS7, |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 107 | }, |
| 108 | { |
| 109 | .name = "SMPS8", |
Laxman Dewangan | 504382c | 2013-03-20 19:26:37 +0530 | [diff] [blame] | 110 | .sname = "smps8-in", |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 111 | .vsel_addr = PALMAS_SMPS8_VOLTAGE, |
| 112 | .ctrl_addr = PALMAS_SMPS8_CTRL, |
| 113 | .tstep_addr = PALMAS_SMPS8_TSTEP, |
Laxman Dewangan | 32b6d3f | 2013-08-21 16:18:16 +0530 | [diff] [blame] | 114 | .sleep_id = PALMAS_EXTERNAL_REQSTR_ID_SMPS8, |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 115 | }, |
| 116 | { |
| 117 | .name = "SMPS9", |
Laxman Dewangan | 504382c | 2013-03-20 19:26:37 +0530 | [diff] [blame] | 118 | .sname = "smps9-in", |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 119 | .vsel_addr = PALMAS_SMPS9_VOLTAGE, |
| 120 | .ctrl_addr = PALMAS_SMPS9_CTRL, |
Laxman Dewangan | 32b6d3f | 2013-08-21 16:18:16 +0530 | [diff] [blame] | 121 | .sleep_id = PALMAS_EXTERNAL_REQSTR_ID_SMPS9, |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 122 | }, |
| 123 | { |
Kishon Vijay Abraham I | 77409d9 | 2013-08-12 14:21:14 +0530 | [diff] [blame] | 124 | .name = "SMPS10_OUT2", |
Laxman Dewangan | 504382c | 2013-03-20 19:26:37 +0530 | [diff] [blame] | 125 | .sname = "smps10-in", |
Axel Lin | e31089c | 2013-04-19 20:33:45 +0800 | [diff] [blame] | 126 | .ctrl_addr = PALMAS_SMPS10_CTRL, |
Laxman Dewangan | 32b6d3f | 2013-08-21 16:18:16 +0530 | [diff] [blame] | 127 | .sleep_id = PALMAS_EXTERNAL_REQSTR_ID_SMPS10, |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 128 | }, |
| 129 | { |
Kishon Vijay Abraham I | 77409d9 | 2013-08-12 14:21:14 +0530 | [diff] [blame] | 130 | .name = "SMPS10_OUT1", |
| 131 | .sname = "smps10-out2", |
| 132 | .ctrl_addr = PALMAS_SMPS10_CTRL, |
Laxman Dewangan | 32b6d3f | 2013-08-21 16:18:16 +0530 | [diff] [blame] | 133 | .sleep_id = PALMAS_EXTERNAL_REQSTR_ID_SMPS10, |
Kishon Vijay Abraham I | 77409d9 | 2013-08-12 14:21:14 +0530 | [diff] [blame] | 134 | }, |
| 135 | { |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 136 | .name = "LDO1", |
Laxman Dewangan | 504382c | 2013-03-20 19:26:37 +0530 | [diff] [blame] | 137 | .sname = "ldo1-in", |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 138 | .vsel_addr = PALMAS_LDO1_VOLTAGE, |
| 139 | .ctrl_addr = PALMAS_LDO1_CTRL, |
Laxman Dewangan | 32b6d3f | 2013-08-21 16:18:16 +0530 | [diff] [blame] | 140 | .sleep_id = PALMAS_EXTERNAL_REQSTR_ID_LDO1, |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 141 | }, |
| 142 | { |
| 143 | .name = "LDO2", |
Laxman Dewangan | 504382c | 2013-03-20 19:26:37 +0530 | [diff] [blame] | 144 | .sname = "ldo2-in", |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 145 | .vsel_addr = PALMAS_LDO2_VOLTAGE, |
| 146 | .ctrl_addr = PALMAS_LDO2_CTRL, |
Laxman Dewangan | 32b6d3f | 2013-08-21 16:18:16 +0530 | [diff] [blame] | 147 | .sleep_id = PALMAS_EXTERNAL_REQSTR_ID_LDO2, |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 148 | }, |
| 149 | { |
| 150 | .name = "LDO3", |
Laxman Dewangan | 504382c | 2013-03-20 19:26:37 +0530 | [diff] [blame] | 151 | .sname = "ldo3-in", |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 152 | .vsel_addr = PALMAS_LDO3_VOLTAGE, |
| 153 | .ctrl_addr = PALMAS_LDO3_CTRL, |
Laxman Dewangan | 32b6d3f | 2013-08-21 16:18:16 +0530 | [diff] [blame] | 154 | .sleep_id = PALMAS_EXTERNAL_REQSTR_ID_LDO3, |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 155 | }, |
| 156 | { |
| 157 | .name = "LDO4", |
Laxman Dewangan | 504382c | 2013-03-20 19:26:37 +0530 | [diff] [blame] | 158 | .sname = "ldo4-in", |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 159 | .vsel_addr = PALMAS_LDO4_VOLTAGE, |
| 160 | .ctrl_addr = PALMAS_LDO4_CTRL, |
Laxman Dewangan | 32b6d3f | 2013-08-21 16:18:16 +0530 | [diff] [blame] | 161 | .sleep_id = PALMAS_EXTERNAL_REQSTR_ID_LDO4, |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 162 | }, |
| 163 | { |
| 164 | .name = "LDO5", |
Laxman Dewangan | 504382c | 2013-03-20 19:26:37 +0530 | [diff] [blame] | 165 | .sname = "ldo5-in", |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 166 | .vsel_addr = PALMAS_LDO5_VOLTAGE, |
| 167 | .ctrl_addr = PALMAS_LDO5_CTRL, |
Laxman Dewangan | 32b6d3f | 2013-08-21 16:18:16 +0530 | [diff] [blame] | 168 | .sleep_id = PALMAS_EXTERNAL_REQSTR_ID_LDO5, |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 169 | }, |
| 170 | { |
| 171 | .name = "LDO6", |
Laxman Dewangan | 504382c | 2013-03-20 19:26:37 +0530 | [diff] [blame] | 172 | .sname = "ldo6-in", |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 173 | .vsel_addr = PALMAS_LDO6_VOLTAGE, |
| 174 | .ctrl_addr = PALMAS_LDO6_CTRL, |
Laxman Dewangan | 32b6d3f | 2013-08-21 16:18:16 +0530 | [diff] [blame] | 175 | .sleep_id = PALMAS_EXTERNAL_REQSTR_ID_LDO6, |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 176 | }, |
| 177 | { |
| 178 | .name = "LDO7", |
Laxman Dewangan | 504382c | 2013-03-20 19:26:37 +0530 | [diff] [blame] | 179 | .sname = "ldo7-in", |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 180 | .vsel_addr = PALMAS_LDO7_VOLTAGE, |
| 181 | .ctrl_addr = PALMAS_LDO7_CTRL, |
Laxman Dewangan | 32b6d3f | 2013-08-21 16:18:16 +0530 | [diff] [blame] | 182 | .sleep_id = PALMAS_EXTERNAL_REQSTR_ID_LDO7, |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 183 | }, |
| 184 | { |
| 185 | .name = "LDO8", |
Laxman Dewangan | 504382c | 2013-03-20 19:26:37 +0530 | [diff] [blame] | 186 | .sname = "ldo8-in", |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 187 | .vsel_addr = PALMAS_LDO8_VOLTAGE, |
| 188 | .ctrl_addr = PALMAS_LDO8_CTRL, |
Laxman Dewangan | 32b6d3f | 2013-08-21 16:18:16 +0530 | [diff] [blame] | 189 | .sleep_id = PALMAS_EXTERNAL_REQSTR_ID_LDO8, |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 190 | }, |
| 191 | { |
| 192 | .name = "LDO9", |
Laxman Dewangan | 504382c | 2013-03-20 19:26:37 +0530 | [diff] [blame] | 193 | .sname = "ldo9-in", |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 194 | .vsel_addr = PALMAS_LDO9_VOLTAGE, |
| 195 | .ctrl_addr = PALMAS_LDO9_CTRL, |
Laxman Dewangan | 32b6d3f | 2013-08-21 16:18:16 +0530 | [diff] [blame] | 196 | .sleep_id = PALMAS_EXTERNAL_REQSTR_ID_LDO9, |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 197 | }, |
| 198 | { |
| 199 | .name = "LDOLN", |
Laxman Dewangan | 504382c | 2013-03-20 19:26:37 +0530 | [diff] [blame] | 200 | .sname = "ldoln-in", |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 201 | .vsel_addr = PALMAS_LDOLN_VOLTAGE, |
| 202 | .ctrl_addr = PALMAS_LDOLN_CTRL, |
Laxman Dewangan | 32b6d3f | 2013-08-21 16:18:16 +0530 | [diff] [blame] | 203 | .sleep_id = PALMAS_EXTERNAL_REQSTR_ID_LDOLN, |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 204 | }, |
| 205 | { |
| 206 | .name = "LDOUSB", |
Laxman Dewangan | 504382c | 2013-03-20 19:26:37 +0530 | [diff] [blame] | 207 | .sname = "ldousb-in", |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 208 | .vsel_addr = PALMAS_LDOUSB_VOLTAGE, |
| 209 | .ctrl_addr = PALMAS_LDOUSB_CTRL, |
Laxman Dewangan | 32b6d3f | 2013-08-21 16:18:16 +0530 | [diff] [blame] | 210 | .sleep_id = PALMAS_EXTERNAL_REQSTR_ID_LDOUSB, |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 211 | }, |
Laxman Dewangan | aa07f02 | 2013-04-17 15:13:12 +0530 | [diff] [blame] | 212 | { |
| 213 | .name = "REGEN1", |
| 214 | .ctrl_addr = PALMAS_REGEN1_CTRL, |
Laxman Dewangan | 32b6d3f | 2013-08-21 16:18:16 +0530 | [diff] [blame] | 215 | .sleep_id = PALMAS_EXTERNAL_REQSTR_ID_REGEN1, |
Laxman Dewangan | aa07f02 | 2013-04-17 15:13:12 +0530 | [diff] [blame] | 216 | }, |
| 217 | { |
| 218 | .name = "REGEN2", |
| 219 | .ctrl_addr = PALMAS_REGEN2_CTRL, |
Laxman Dewangan | 32b6d3f | 2013-08-21 16:18:16 +0530 | [diff] [blame] | 220 | .sleep_id = PALMAS_EXTERNAL_REQSTR_ID_REGEN2, |
Laxman Dewangan | aa07f02 | 2013-04-17 15:13:12 +0530 | [diff] [blame] | 221 | }, |
| 222 | { |
| 223 | .name = "REGEN3", |
| 224 | .ctrl_addr = PALMAS_REGEN3_CTRL, |
Laxman Dewangan | 32b6d3f | 2013-08-21 16:18:16 +0530 | [diff] [blame] | 225 | .sleep_id = PALMAS_EXTERNAL_REQSTR_ID_REGEN3, |
Laxman Dewangan | aa07f02 | 2013-04-17 15:13:12 +0530 | [diff] [blame] | 226 | }, |
| 227 | { |
| 228 | .name = "SYSEN1", |
| 229 | .ctrl_addr = PALMAS_SYSEN1_CTRL, |
Laxman Dewangan | 32b6d3f | 2013-08-21 16:18:16 +0530 | [diff] [blame] | 230 | .sleep_id = PALMAS_EXTERNAL_REQSTR_ID_SYSEN1, |
Laxman Dewangan | aa07f02 | 2013-04-17 15:13:12 +0530 | [diff] [blame] | 231 | }, |
| 232 | { |
| 233 | .name = "SYSEN2", |
| 234 | .ctrl_addr = PALMAS_SYSEN2_CTRL, |
Laxman Dewangan | 32b6d3f | 2013-08-21 16:18:16 +0530 | [diff] [blame] | 235 | .sleep_id = PALMAS_EXTERNAL_REQSTR_ID_SYSEN2, |
Laxman Dewangan | aa07f02 | 2013-04-17 15:13:12 +0530 | [diff] [blame] | 236 | }, |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 237 | }; |
| 238 | |
Laxman Dewangan | 28d1e8c | 2013-04-18 18:32:47 +0530 | [diff] [blame] | 239 | static unsigned int palmas_smps_ramp_delay[4] = {0, 10000, 5000, 2500}; |
| 240 | |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 241 | #define SMPS_CTRL_MODE_OFF 0x00 |
| 242 | #define SMPS_CTRL_MODE_ON 0x01 |
| 243 | #define SMPS_CTRL_MODE_ECO 0x02 |
| 244 | #define SMPS_CTRL_MODE_PWM 0x03 |
| 245 | |
Laxman Dewangan | 0f45aa8 | 2013-09-04 15:20:06 +0530 | [diff] [blame] | 246 | #define PALMAS_SMPS_NUM_VOLTAGES 122 |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 247 | #define PALMAS_SMPS10_NUM_VOLTAGES 2 |
| 248 | #define PALMAS_LDO_NUM_VOLTAGES 50 |
| 249 | |
| 250 | #define SMPS10_VSEL (1<<3) |
| 251 | #define SMPS10_BOOST_EN (1<<2) |
| 252 | #define SMPS10_BYPASS_EN (1<<1) |
| 253 | #define SMPS10_SWITCH_EN (1<<0) |
| 254 | |
| 255 | #define REGULATOR_SLAVE 0 |
| 256 | |
| 257 | static int palmas_smps_read(struct palmas *palmas, unsigned int reg, |
| 258 | unsigned int *dest) |
| 259 | { |
| 260 | unsigned int addr; |
| 261 | |
| 262 | addr = PALMAS_BASE_TO_REG(PALMAS_SMPS_BASE, reg); |
| 263 | |
| 264 | return regmap_read(palmas->regmap[REGULATOR_SLAVE], addr, dest); |
| 265 | } |
| 266 | |
| 267 | static int palmas_smps_write(struct palmas *palmas, unsigned int reg, |
| 268 | unsigned int value) |
| 269 | { |
| 270 | unsigned int addr; |
| 271 | |
| 272 | addr = PALMAS_BASE_TO_REG(PALMAS_SMPS_BASE, reg); |
| 273 | |
| 274 | return regmap_write(palmas->regmap[REGULATOR_SLAVE], addr, value); |
| 275 | } |
| 276 | |
| 277 | static int palmas_ldo_read(struct palmas *palmas, unsigned int reg, |
| 278 | unsigned int *dest) |
| 279 | { |
| 280 | unsigned int addr; |
| 281 | |
| 282 | addr = PALMAS_BASE_TO_REG(PALMAS_LDO_BASE, reg); |
| 283 | |
| 284 | return regmap_read(palmas->regmap[REGULATOR_SLAVE], addr, dest); |
| 285 | } |
| 286 | |
| 287 | static int palmas_ldo_write(struct palmas *palmas, unsigned int reg, |
| 288 | unsigned int value) |
| 289 | { |
| 290 | unsigned int addr; |
| 291 | |
| 292 | addr = PALMAS_BASE_TO_REG(PALMAS_LDO_BASE, reg); |
| 293 | |
| 294 | return regmap_write(palmas->regmap[REGULATOR_SLAVE], addr, value); |
| 295 | } |
| 296 | |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 297 | static int palmas_set_mode_smps(struct regulator_dev *dev, unsigned int mode) |
| 298 | { |
| 299 | struct palmas_pmic *pmic = rdev_get_drvdata(dev); |
| 300 | int id = rdev_get_id(dev); |
| 301 | unsigned int reg; |
Laxman Dewangan | 51d3a0c | 2013-04-18 18:32:48 +0530 | [diff] [blame] | 302 | bool rail_enable = true; |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 303 | |
| 304 | palmas_smps_read(pmic->palmas, palmas_regs_info[id].ctrl_addr, ®); |
Axel Lin | 999f0c7 | 2012-06-07 17:08:21 +0800 | [diff] [blame] | 305 | reg &= ~PALMAS_SMPS12_CTRL_MODE_ACTIVE_MASK; |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 306 | |
Laxman Dewangan | 51d3a0c | 2013-04-18 18:32:48 +0530 | [diff] [blame] | 307 | if (reg == SMPS_CTRL_MODE_OFF) |
| 308 | rail_enable = false; |
| 309 | |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 310 | switch (mode) { |
| 311 | case REGULATOR_MODE_NORMAL: |
| 312 | reg |= SMPS_CTRL_MODE_ON; |
| 313 | break; |
| 314 | case REGULATOR_MODE_IDLE: |
| 315 | reg |= SMPS_CTRL_MODE_ECO; |
| 316 | break; |
| 317 | case REGULATOR_MODE_FAST: |
| 318 | reg |= SMPS_CTRL_MODE_PWM; |
| 319 | break; |
| 320 | default: |
| 321 | return -EINVAL; |
| 322 | } |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 323 | |
Laxman Dewangan | 51d3a0c | 2013-04-18 18:32:48 +0530 | [diff] [blame] | 324 | pmic->current_reg_mode[id] = reg & PALMAS_SMPS12_CTRL_MODE_ACTIVE_MASK; |
| 325 | if (rail_enable) |
| 326 | palmas_smps_write(pmic->palmas, |
| 327 | palmas_regs_info[id].ctrl_addr, reg); |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 328 | return 0; |
| 329 | } |
| 330 | |
| 331 | static unsigned int palmas_get_mode_smps(struct regulator_dev *dev) |
| 332 | { |
| 333 | struct palmas_pmic *pmic = rdev_get_drvdata(dev); |
| 334 | int id = rdev_get_id(dev); |
| 335 | unsigned int reg; |
| 336 | |
Laxman Dewangan | 51d3a0c | 2013-04-18 18:32:48 +0530 | [diff] [blame] | 337 | reg = pmic->current_reg_mode[id] & PALMAS_SMPS12_CTRL_MODE_ACTIVE_MASK; |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 338 | |
| 339 | switch (reg) { |
| 340 | case SMPS_CTRL_MODE_ON: |
| 341 | return REGULATOR_MODE_NORMAL; |
| 342 | case SMPS_CTRL_MODE_ECO: |
| 343 | return REGULATOR_MODE_IDLE; |
| 344 | case SMPS_CTRL_MODE_PWM: |
| 345 | return REGULATOR_MODE_FAST; |
| 346 | } |
| 347 | |
| 348 | return 0; |
| 349 | } |
| 350 | |
Laxman Dewangan | 28d1e8c | 2013-04-18 18:32:47 +0530 | [diff] [blame] | 351 | static int palmas_smps_set_ramp_delay(struct regulator_dev *rdev, |
| 352 | int ramp_delay) |
| 353 | { |
| 354 | struct palmas_pmic *pmic = rdev_get_drvdata(rdev); |
| 355 | int id = rdev_get_id(rdev); |
| 356 | unsigned int reg = 0; |
| 357 | unsigned int addr = palmas_regs_info[id].tstep_addr; |
| 358 | int ret; |
| 359 | |
Axel Lin | f22c2ba | 2013-04-19 14:18:48 +0800 | [diff] [blame] | 360 | /* SMPS3 and SMPS7 do not have tstep_addr setting */ |
| 361 | switch (id) { |
| 362 | case PALMAS_REG_SMPS3: |
| 363 | case PALMAS_REG_SMPS7: |
| 364 | return 0; |
| 365 | } |
| 366 | |
Laxman Dewangan | 28d1e8c | 2013-04-18 18:32:47 +0530 | [diff] [blame] | 367 | if (ramp_delay <= 0) |
| 368 | reg = 0; |
Axel Lin | 0ea34b5 | 2013-04-22 18:22:49 +0800 | [diff] [blame] | 369 | else if (ramp_delay <= 2500) |
Laxman Dewangan | 28d1e8c | 2013-04-18 18:32:47 +0530 | [diff] [blame] | 370 | reg = 3; |
Axel Lin | 0ea34b5 | 2013-04-22 18:22:49 +0800 | [diff] [blame] | 371 | else if (ramp_delay <= 5000) |
Laxman Dewangan | 28d1e8c | 2013-04-18 18:32:47 +0530 | [diff] [blame] | 372 | reg = 2; |
| 373 | else |
| 374 | reg = 1; |
| 375 | |
| 376 | ret = palmas_smps_write(pmic->palmas, addr, reg); |
| 377 | if (ret < 0) { |
| 378 | dev_err(pmic->palmas->dev, "TSTEP write failed: %d\n", ret); |
| 379 | return ret; |
| 380 | } |
| 381 | |
| 382 | pmic->ramp_delay[id] = palmas_smps_ramp_delay[reg]; |
| 383 | return ret; |
| 384 | } |
| 385 | |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 386 | static struct regulator_ops palmas_ops_smps = { |
Keerthy | dbabd62 | 2014-05-22 14:48:29 +0530 | [diff] [blame] | 387 | .is_enabled = regulator_is_enabled_regmap, |
| 388 | .enable = regulator_enable_regmap, |
| 389 | .disable = regulator_disable_regmap, |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 390 | .set_mode = palmas_set_mode_smps, |
| 391 | .get_mode = palmas_get_mode_smps, |
Axel Lin | bdc4baa | 2012-11-29 10:01:44 +0800 | [diff] [blame] | 392 | .get_voltage_sel = regulator_get_voltage_sel_regmap, |
| 393 | .set_voltage_sel = regulator_set_voltage_sel_regmap, |
Keerthy | dbabd62 | 2014-05-22 14:48:29 +0530 | [diff] [blame] | 394 | .list_voltage = regulator_list_voltage_linear_range, |
| 395 | .map_voltage = regulator_map_voltage_linear_range, |
| 396 | .set_voltage_time_sel = regulator_set_voltage_time_sel, |
Laxman Dewangan | 28d1e8c | 2013-04-18 18:32:47 +0530 | [diff] [blame] | 397 | .set_ramp_delay = palmas_smps_set_ramp_delay, |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 398 | }; |
| 399 | |
Laxman Dewangan | 32b6d3f | 2013-08-21 16:18:16 +0530 | [diff] [blame] | 400 | static struct regulator_ops palmas_ops_ext_control_smps = { |
| 401 | .set_mode = palmas_set_mode_smps, |
| 402 | .get_mode = palmas_get_mode_smps, |
| 403 | .get_voltage_sel = regulator_get_voltage_sel_regmap, |
| 404 | .set_voltage_sel = regulator_set_voltage_sel_regmap, |
Keerthy | dbabd62 | 2014-05-22 14:48:29 +0530 | [diff] [blame] | 405 | .list_voltage = regulator_list_voltage_linear_range, |
| 406 | .map_voltage = regulator_map_voltage_linear_range, |
| 407 | .set_voltage_time_sel = regulator_set_voltage_time_sel, |
Laxman Dewangan | 32b6d3f | 2013-08-21 16:18:16 +0530 | [diff] [blame] | 408 | .set_ramp_delay = palmas_smps_set_ramp_delay, |
| 409 | }; |
| 410 | |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 411 | static struct regulator_ops palmas_ops_smps10 = { |
| 412 | .is_enabled = regulator_is_enabled_regmap, |
| 413 | .enable = regulator_enable_regmap, |
| 414 | .disable = regulator_disable_regmap, |
| 415 | .get_voltage_sel = regulator_get_voltage_sel_regmap, |
| 416 | .set_voltage_sel = regulator_set_voltage_sel_regmap, |
Axel Lin | 8029a00 | 2012-05-22 12:26:42 +0800 | [diff] [blame] | 417 | .list_voltage = regulator_list_voltage_linear, |
| 418 | .map_voltage = regulator_map_voltage_linear, |
Kishon Vijay Abraham I | 77409d9 | 2013-08-12 14:21:14 +0530 | [diff] [blame] | 419 | .set_bypass = regulator_set_bypass_regmap, |
| 420 | .get_bypass = regulator_get_bypass_regmap, |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 421 | }; |
| 422 | |
| 423 | static int palmas_is_enabled_ldo(struct regulator_dev *dev) |
| 424 | { |
| 425 | struct palmas_pmic *pmic = rdev_get_drvdata(dev); |
| 426 | int id = rdev_get_id(dev); |
| 427 | unsigned int reg; |
| 428 | |
| 429 | palmas_ldo_read(pmic->palmas, palmas_regs_info[id].ctrl_addr, ®); |
| 430 | |
| 431 | reg &= PALMAS_LDO1_CTRL_STATUS; |
| 432 | |
| 433 | return !!(reg); |
| 434 | } |
| 435 | |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 436 | static struct regulator_ops palmas_ops_ldo = { |
| 437 | .is_enabled = palmas_is_enabled_ldo, |
| 438 | .enable = regulator_enable_regmap, |
| 439 | .disable = regulator_disable_regmap, |
Axel Lin | 4a247a9 | 2012-07-18 12:34:08 +0800 | [diff] [blame] | 440 | .get_voltage_sel = regulator_get_voltage_sel_regmap, |
| 441 | .set_voltage_sel = regulator_set_voltage_sel_regmap, |
Axel Lin | 9119ff6 | 2012-11-27 10:27:34 +0800 | [diff] [blame] | 442 | .list_voltage = regulator_list_voltage_linear, |
| 443 | .map_voltage = regulator_map_voltage_linear, |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 444 | }; |
| 445 | |
Laxman Dewangan | 32b6d3f | 2013-08-21 16:18:16 +0530 | [diff] [blame] | 446 | static struct regulator_ops palmas_ops_ext_control_ldo = { |
| 447 | .get_voltage_sel = regulator_get_voltage_sel_regmap, |
| 448 | .set_voltage_sel = regulator_set_voltage_sel_regmap, |
| 449 | .list_voltage = regulator_list_voltage_linear, |
| 450 | .map_voltage = regulator_map_voltage_linear, |
| 451 | }; |
| 452 | |
Laxman Dewangan | aa07f02 | 2013-04-17 15:13:12 +0530 | [diff] [blame] | 453 | static struct regulator_ops palmas_ops_extreg = { |
| 454 | .is_enabled = regulator_is_enabled_regmap, |
| 455 | .enable = regulator_enable_regmap, |
| 456 | .disable = regulator_disable_regmap, |
| 457 | }; |
| 458 | |
Laxman Dewangan | 32b6d3f | 2013-08-21 16:18:16 +0530 | [diff] [blame] | 459 | static struct regulator_ops palmas_ops_ext_control_extreg = { |
| 460 | }; |
| 461 | |
| 462 | static int palmas_regulator_config_external(struct palmas *palmas, int id, |
| 463 | struct palmas_reg_init *reg_init) |
| 464 | { |
| 465 | int sleep_id = palmas_regs_info[id].sleep_id; |
| 466 | int ret; |
| 467 | |
| 468 | ret = palmas_ext_control_req_config(palmas, sleep_id, |
| 469 | reg_init->roof_floor, true); |
| 470 | if (ret < 0) |
| 471 | dev_err(palmas->dev, |
| 472 | "Ext control config for regulator %d failed %d\n", |
| 473 | id, ret); |
| 474 | return ret; |
| 475 | } |
| 476 | |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 477 | /* |
| 478 | * setup the hardware based sleep configuration of the SMPS/LDO regulators |
| 479 | * from the platform data. This is different to the software based control |
| 480 | * supported by the regulator framework as it is controlled by toggling |
| 481 | * pins on the PMIC such as PREQ, SYSEN, ... |
| 482 | */ |
| 483 | static int palmas_smps_init(struct palmas *palmas, int id, |
| 484 | struct palmas_reg_init *reg_init) |
| 485 | { |
| 486 | unsigned int reg; |
| 487 | unsigned int addr; |
| 488 | int ret; |
| 489 | |
| 490 | addr = palmas_regs_info[id].ctrl_addr; |
| 491 | |
| 492 | ret = palmas_smps_read(palmas, addr, ®); |
| 493 | if (ret) |
| 494 | return ret; |
| 495 | |
Axel Lin | fedd89b | 2012-06-06 20:01:38 +0800 | [diff] [blame] | 496 | switch (id) { |
Kishon Vijay Abraham I | 77409d9 | 2013-08-12 14:21:14 +0530 | [diff] [blame] | 497 | case PALMAS_REG_SMPS10_OUT1: |
| 498 | case PALMAS_REG_SMPS10_OUT2: |
Laxman Dewangan | 30590d0 | 2013-04-17 15:13:11 +0530 | [diff] [blame] | 499 | reg &= ~PALMAS_SMPS10_CTRL_MODE_SLEEP_MASK; |
| 500 | if (reg_init->mode_sleep) |
Axel Lin | fedd89b | 2012-06-06 20:01:38 +0800 | [diff] [blame] | 501 | reg |= reg_init->mode_sleep << |
| 502 | PALMAS_SMPS10_CTRL_MODE_SLEEP_SHIFT; |
Axel Lin | fedd89b | 2012-06-06 20:01:38 +0800 | [diff] [blame] | 503 | break; |
| 504 | default: |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 505 | if (reg_init->warm_reset) |
| 506 | reg |= PALMAS_SMPS12_CTRL_WR_S; |
Laxman Dewangan | 30590d0 | 2013-04-17 15:13:11 +0530 | [diff] [blame] | 507 | else |
| 508 | reg &= ~PALMAS_SMPS12_CTRL_WR_S; |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 509 | |
| 510 | if (reg_init->roof_floor) |
| 511 | reg |= PALMAS_SMPS12_CTRL_ROOF_FLOOR_EN; |
Laxman Dewangan | 30590d0 | 2013-04-17 15:13:11 +0530 | [diff] [blame] | 512 | else |
| 513 | reg &= ~PALMAS_SMPS12_CTRL_ROOF_FLOOR_EN; |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 514 | |
Laxman Dewangan | 30590d0 | 2013-04-17 15:13:11 +0530 | [diff] [blame] | 515 | reg &= ~PALMAS_SMPS12_CTRL_MODE_SLEEP_MASK; |
| 516 | if (reg_init->mode_sleep) |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 517 | reg |= reg_init->mode_sleep << |
| 518 | PALMAS_SMPS12_CTRL_MODE_SLEEP_SHIFT; |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 519 | } |
Axel Lin | fedd89b | 2012-06-06 20:01:38 +0800 | [diff] [blame] | 520 | |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 521 | ret = palmas_smps_write(palmas, addr, reg); |
| 522 | if (ret) |
| 523 | return ret; |
| 524 | |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 525 | if (palmas_regs_info[id].vsel_addr && reg_init->vsel) { |
| 526 | addr = palmas_regs_info[id].vsel_addr; |
| 527 | |
| 528 | reg = reg_init->vsel; |
| 529 | |
| 530 | ret = palmas_smps_write(palmas, addr, reg); |
| 531 | if (ret) |
| 532 | return ret; |
| 533 | } |
| 534 | |
Laxman Dewangan | 32b6d3f | 2013-08-21 16:18:16 +0530 | [diff] [blame] | 535 | if (reg_init->roof_floor && (id != PALMAS_REG_SMPS10_OUT1) && |
| 536 | (id != PALMAS_REG_SMPS10_OUT2)) { |
| 537 | /* Enable externally controlled regulator */ |
| 538 | addr = palmas_regs_info[id].ctrl_addr; |
| 539 | ret = palmas_smps_read(palmas, addr, ®); |
| 540 | if (ret < 0) |
| 541 | return ret; |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 542 | |
Laxman Dewangan | 32b6d3f | 2013-08-21 16:18:16 +0530 | [diff] [blame] | 543 | if (!(reg & PALMAS_SMPS12_CTRL_MODE_ACTIVE_MASK)) { |
| 544 | reg |= SMPS_CTRL_MODE_ON; |
| 545 | ret = palmas_smps_write(palmas, addr, reg); |
| 546 | if (ret < 0) |
| 547 | return ret; |
| 548 | } |
| 549 | return palmas_regulator_config_external(palmas, id, reg_init); |
| 550 | } |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 551 | return 0; |
| 552 | } |
| 553 | |
| 554 | static int palmas_ldo_init(struct palmas *palmas, int id, |
| 555 | struct palmas_reg_init *reg_init) |
| 556 | { |
| 557 | unsigned int reg; |
| 558 | unsigned int addr; |
| 559 | int ret; |
| 560 | |
| 561 | addr = palmas_regs_info[id].ctrl_addr; |
| 562 | |
Axel Lin | 2735dae | 2012-07-18 12:31:59 +0800 | [diff] [blame] | 563 | ret = palmas_ldo_read(palmas, addr, ®); |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 564 | if (ret) |
| 565 | return ret; |
| 566 | |
| 567 | if (reg_init->warm_reset) |
| 568 | reg |= PALMAS_LDO1_CTRL_WR_S; |
Laxman Dewangan | 30590d0 | 2013-04-17 15:13:11 +0530 | [diff] [blame] | 569 | else |
| 570 | reg &= ~PALMAS_LDO1_CTRL_WR_S; |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 571 | |
| 572 | if (reg_init->mode_sleep) |
| 573 | reg |= PALMAS_LDO1_CTRL_MODE_SLEEP; |
Laxman Dewangan | 30590d0 | 2013-04-17 15:13:11 +0530 | [diff] [blame] | 574 | else |
| 575 | reg &= ~PALMAS_LDO1_CTRL_MODE_SLEEP; |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 576 | |
Axel Lin | 2735dae | 2012-07-18 12:31:59 +0800 | [diff] [blame] | 577 | ret = palmas_ldo_write(palmas, addr, reg); |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 578 | if (ret) |
| 579 | return ret; |
| 580 | |
Laxman Dewangan | 32b6d3f | 2013-08-21 16:18:16 +0530 | [diff] [blame] | 581 | if (reg_init->roof_floor) { |
| 582 | /* Enable externally controlled regulator */ |
| 583 | addr = palmas_regs_info[id].ctrl_addr; |
| 584 | ret = palmas_update_bits(palmas, PALMAS_LDO_BASE, |
| 585 | addr, PALMAS_LDO1_CTRL_MODE_ACTIVE, |
| 586 | PALMAS_LDO1_CTRL_MODE_ACTIVE); |
| 587 | if (ret < 0) { |
| 588 | dev_err(palmas->dev, |
| 589 | "LDO Register 0x%02x update failed %d\n", |
| 590 | addr, ret); |
| 591 | return ret; |
| 592 | } |
| 593 | return palmas_regulator_config_external(palmas, id, reg_init); |
| 594 | } |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 595 | return 0; |
| 596 | } |
| 597 | |
Laxman Dewangan | aa07f02 | 2013-04-17 15:13:12 +0530 | [diff] [blame] | 598 | static int palmas_extreg_init(struct palmas *palmas, int id, |
| 599 | struct palmas_reg_init *reg_init) |
| 600 | { |
| 601 | unsigned int addr; |
| 602 | int ret; |
| 603 | unsigned int val = 0; |
| 604 | |
| 605 | addr = palmas_regs_info[id].ctrl_addr; |
| 606 | |
| 607 | if (reg_init->mode_sleep) |
| 608 | val = PALMAS_REGEN1_CTRL_MODE_SLEEP; |
| 609 | |
| 610 | ret = palmas_update_bits(palmas, PALMAS_RESOURCE_BASE, |
| 611 | addr, PALMAS_REGEN1_CTRL_MODE_SLEEP, val); |
| 612 | if (ret < 0) { |
| 613 | dev_err(palmas->dev, "Resource reg 0x%02x update failed %d\n", |
| 614 | addr, ret); |
| 615 | return ret; |
| 616 | } |
Laxman Dewangan | 32b6d3f | 2013-08-21 16:18:16 +0530 | [diff] [blame] | 617 | |
| 618 | if (reg_init->roof_floor) { |
| 619 | /* Enable externally controlled regulator */ |
| 620 | addr = palmas_regs_info[id].ctrl_addr; |
| 621 | ret = palmas_update_bits(palmas, PALMAS_RESOURCE_BASE, |
| 622 | addr, PALMAS_REGEN1_CTRL_MODE_ACTIVE, |
| 623 | PALMAS_REGEN1_CTRL_MODE_ACTIVE); |
| 624 | if (ret < 0) { |
| 625 | dev_err(palmas->dev, |
| 626 | "Resource Register 0x%02x update failed %d\n", |
| 627 | addr, ret); |
| 628 | return ret; |
| 629 | } |
| 630 | return palmas_regulator_config_external(palmas, id, reg_init); |
| 631 | } |
Laxman Dewangan | aa07f02 | 2013-04-17 15:13:12 +0530 | [diff] [blame] | 632 | return 0; |
| 633 | } |
| 634 | |
Laxman Dewangan | 17c11a7 | 2013-04-17 15:13:13 +0530 | [diff] [blame] | 635 | static void palmas_enable_ldo8_track(struct palmas *palmas) |
| 636 | { |
| 637 | unsigned int reg; |
| 638 | unsigned int addr; |
| 639 | int ret; |
| 640 | |
| 641 | addr = palmas_regs_info[PALMAS_REG_LDO8].ctrl_addr; |
| 642 | |
| 643 | ret = palmas_ldo_read(palmas, addr, ®); |
| 644 | if (ret) { |
| 645 | dev_err(palmas->dev, "Error in reading ldo8 control reg\n"); |
| 646 | return; |
| 647 | } |
| 648 | |
| 649 | reg |= PALMAS_LDO8_CTRL_LDO_TRACKING_EN; |
| 650 | ret = palmas_ldo_write(palmas, addr, reg); |
| 651 | if (ret < 0) { |
| 652 | dev_err(palmas->dev, "Error in enabling tracking mode\n"); |
| 653 | return; |
| 654 | } |
| 655 | /* |
| 656 | * When SMPS45 is set to off and LDO8 tracking is enabled, the LDO8 |
| 657 | * output is defined by the LDO8_VOLTAGE.VSEL register divided by two, |
| 658 | * and can be set from 0.45 to 1.65 V. |
| 659 | */ |
| 660 | addr = palmas_regs_info[PALMAS_REG_LDO8].vsel_addr; |
| 661 | ret = palmas_ldo_read(palmas, addr, ®); |
| 662 | if (ret) { |
| 663 | dev_err(palmas->dev, "Error in reading ldo8 voltage reg\n"); |
| 664 | return; |
| 665 | } |
| 666 | |
| 667 | reg = (reg << 1) & PALMAS_LDO8_VOLTAGE_VSEL_MASK; |
| 668 | ret = palmas_ldo_write(palmas, addr, reg); |
| 669 | if (ret < 0) |
| 670 | dev_err(palmas->dev, "Error in setting ldo8 voltage reg\n"); |
| 671 | |
| 672 | return; |
| 673 | } |
| 674 | |
Graeme Gregory | a361cd9 | 2012-08-28 13:47:40 +0200 | [diff] [blame] | 675 | static struct of_regulator_match palmas_matches[] = { |
| 676 | { .name = "smps12", }, |
| 677 | { .name = "smps123", }, |
| 678 | { .name = "smps3", }, |
| 679 | { .name = "smps45", }, |
| 680 | { .name = "smps457", }, |
| 681 | { .name = "smps6", }, |
| 682 | { .name = "smps7", }, |
| 683 | { .name = "smps8", }, |
| 684 | { .name = "smps9", }, |
Kishon Vijay Abraham I | 77409d9 | 2013-08-12 14:21:14 +0530 | [diff] [blame] | 685 | { .name = "smps10_out2", }, |
| 686 | { .name = "smps10_out1", }, |
Graeme Gregory | a361cd9 | 2012-08-28 13:47:40 +0200 | [diff] [blame] | 687 | { .name = "ldo1", }, |
| 688 | { .name = "ldo2", }, |
| 689 | { .name = "ldo3", }, |
| 690 | { .name = "ldo4", }, |
| 691 | { .name = "ldo5", }, |
| 692 | { .name = "ldo6", }, |
| 693 | { .name = "ldo7", }, |
| 694 | { .name = "ldo8", }, |
| 695 | { .name = "ldo9", }, |
| 696 | { .name = "ldoln", }, |
| 697 | { .name = "ldousb", }, |
Laxman Dewangan | aa07f02 | 2013-04-17 15:13:12 +0530 | [diff] [blame] | 698 | { .name = "regen1", }, |
| 699 | { .name = "regen2", }, |
| 700 | { .name = "regen3", }, |
| 701 | { .name = "sysen1", }, |
| 702 | { .name = "sysen2", }, |
Graeme Gregory | a361cd9 | 2012-08-28 13:47:40 +0200 | [diff] [blame] | 703 | }; |
| 704 | |
Bill Pemberton | a502357 | 2012-11-19 13:22:22 -0500 | [diff] [blame] | 705 | static void palmas_dt_to_pdata(struct device *dev, |
Graeme Gregory | a361cd9 | 2012-08-28 13:47:40 +0200 | [diff] [blame] | 706 | struct device_node *node, |
| 707 | struct palmas_pmic_platform_data *pdata) |
| 708 | { |
| 709 | struct device_node *regulators; |
| 710 | u32 prop; |
| 711 | int idx, ret; |
| 712 | |
Axel Lin | c92f5dd | 2013-01-27 21:16:56 +0800 | [diff] [blame] | 713 | node = of_node_get(node); |
Laxman Dewangan | acc1cca | 2013-10-03 19:36:37 +0530 | [diff] [blame] | 714 | regulators = of_get_child_by_name(node, "regulators"); |
Graeme Gregory | a361cd9 | 2012-08-28 13:47:40 +0200 | [diff] [blame] | 715 | if (!regulators) { |
| 716 | dev_info(dev, "regulator node not found\n"); |
| 717 | return; |
| 718 | } |
| 719 | |
| 720 | ret = of_regulator_match(dev, regulators, palmas_matches, |
| 721 | PALMAS_NUM_REGS); |
Axel Lin | c92f5dd | 2013-01-27 21:16:56 +0800 | [diff] [blame] | 722 | of_node_put(regulators); |
Graeme Gregory | a361cd9 | 2012-08-28 13:47:40 +0200 | [diff] [blame] | 723 | if (ret < 0) { |
| 724 | dev_err(dev, "Error parsing regulator init data: %d\n", ret); |
| 725 | return; |
| 726 | } |
| 727 | |
| 728 | for (idx = 0; idx < PALMAS_NUM_REGS; idx++) { |
| 729 | if (!palmas_matches[idx].init_data || |
| 730 | !palmas_matches[idx].of_node) |
| 731 | continue; |
| 732 | |
| 733 | pdata->reg_data[idx] = palmas_matches[idx].init_data; |
| 734 | |
| 735 | pdata->reg_init[idx] = devm_kzalloc(dev, |
| 736 | sizeof(struct palmas_reg_init), GFP_KERNEL); |
| 737 | |
Graeme Gregory | 7be859f | 2013-03-07 13:17:48 +0000 | [diff] [blame] | 738 | pdata->reg_init[idx]->warm_reset = |
Axel Lin | 71f2146 | 2013-03-12 23:40:19 +0800 | [diff] [blame] | 739 | of_property_read_bool(palmas_matches[idx].of_node, |
| 740 | "ti,warm-reset"); |
Graeme Gregory | a361cd9 | 2012-08-28 13:47:40 +0200 | [diff] [blame] | 741 | |
Laxman Dewangan | 32b6d3f | 2013-08-21 16:18:16 +0530 | [diff] [blame] | 742 | ret = of_property_read_u32(palmas_matches[idx].of_node, |
| 743 | "ti,roof-floor", &prop); |
| 744 | /* EINVAL: Property not found */ |
| 745 | if (ret != -EINVAL) { |
| 746 | int econtrol; |
| 747 | |
| 748 | /* use default value, when no value is specified */ |
| 749 | econtrol = PALMAS_EXT_CONTROL_NSLEEP; |
| 750 | if (!ret) { |
| 751 | switch (prop) { |
| 752 | case 1: |
| 753 | econtrol = PALMAS_EXT_CONTROL_ENABLE1; |
| 754 | break; |
| 755 | case 2: |
| 756 | econtrol = PALMAS_EXT_CONTROL_ENABLE2; |
| 757 | break; |
| 758 | case 3: |
| 759 | econtrol = PALMAS_EXT_CONTROL_NSLEEP; |
| 760 | break; |
| 761 | default: |
| 762 | WARN_ON(1); |
| 763 | dev_warn(dev, |
| 764 | "%s: Invalid roof-floor option: %u\n", |
| 765 | palmas_matches[idx].name, prop); |
| 766 | break; |
| 767 | } |
| 768 | } |
| 769 | pdata->reg_init[idx]->roof_floor = econtrol; |
| 770 | } |
Graeme Gregory | a361cd9 | 2012-08-28 13:47:40 +0200 | [diff] [blame] | 771 | |
| 772 | ret = of_property_read_u32(palmas_matches[idx].of_node, |
J Keerthy | 3c870e3 | 2013-02-18 10:44:20 +0530 | [diff] [blame] | 773 | "ti,mode-sleep", &prop); |
Graeme Gregory | a361cd9 | 2012-08-28 13:47:40 +0200 | [diff] [blame] | 774 | if (!ret) |
| 775 | pdata->reg_init[idx]->mode_sleep = prop; |
| 776 | |
Graeme Gregory | 7be859f | 2013-03-07 13:17:48 +0000 | [diff] [blame] | 777 | ret = of_property_read_bool(palmas_matches[idx].of_node, |
| 778 | "ti,smps-range"); |
| 779 | if (ret) |
| 780 | pdata->reg_init[idx]->vsel = |
| 781 | PALMAS_SMPS12_VOLTAGE_RANGE; |
Graeme Gregory | a361cd9 | 2012-08-28 13:47:40 +0200 | [diff] [blame] | 782 | |
Laxman Dewangan | 17c11a7 | 2013-04-17 15:13:13 +0530 | [diff] [blame] | 783 | if (idx == PALMAS_REG_LDO8) |
| 784 | pdata->enable_ldo8_tracking = of_property_read_bool( |
| 785 | palmas_matches[idx].of_node, |
| 786 | "ti,enable-ldo8-tracking"); |
Graeme Gregory | a361cd9 | 2012-08-28 13:47:40 +0200 | [diff] [blame] | 787 | } |
| 788 | |
Graeme Gregory | 7be859f | 2013-03-07 13:17:48 +0000 | [diff] [blame] | 789 | pdata->ldo6_vibrator = of_property_read_bool(node, "ti,ldo6-vibrator"); |
Graeme Gregory | a361cd9 | 2012-08-28 13:47:40 +0200 | [diff] [blame] | 790 | } |
| 791 | |
| 792 | |
Laxman Dewangan | bbcf50b | 2013-03-18 14:59:49 +0530 | [diff] [blame] | 793 | static int palmas_regulators_probe(struct platform_device *pdev) |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 794 | { |
| 795 | struct palmas *palmas = dev_get_drvdata(pdev->dev.parent); |
Jingoo Han | dff91d0 | 2013-07-30 17:20:47 +0900 | [diff] [blame] | 796 | struct palmas_pmic_platform_data *pdata = dev_get_platdata(&pdev->dev); |
Graeme Gregory | a361cd9 | 2012-08-28 13:47:40 +0200 | [diff] [blame] | 797 | struct device_node *node = pdev->dev.of_node; |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 798 | struct regulator_dev *rdev; |
| 799 | struct regulator_config config = { }; |
| 800 | struct palmas_pmic *pmic; |
| 801 | struct palmas_reg_init *reg_init; |
| 802 | int id = 0, ret; |
| 803 | unsigned int addr, reg; |
| 804 | |
Graeme Gregory | a361cd9 | 2012-08-28 13:47:40 +0200 | [diff] [blame] | 805 | if (node && !pdata) { |
| 806 | pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL); |
| 807 | |
| 808 | if (!pdata) |
| 809 | return -ENOMEM; |
| 810 | |
| 811 | palmas_dt_to_pdata(&pdev->dev, node, pdata); |
| 812 | } |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 813 | |
| 814 | pmic = devm_kzalloc(&pdev->dev, sizeof(*pmic), GFP_KERNEL); |
| 815 | if (!pmic) |
| 816 | return -ENOMEM; |
| 817 | |
| 818 | pmic->dev = &pdev->dev; |
| 819 | pmic->palmas = palmas; |
| 820 | palmas->pmic = pmic; |
| 821 | platform_set_drvdata(pdev, pmic); |
| 822 | |
| 823 | ret = palmas_smps_read(palmas, PALMAS_SMPS_CTRL, ®); |
| 824 | if (ret) |
Axel Lin | 1c9d2d7 | 2012-07-18 12:33:20 +0800 | [diff] [blame] | 825 | return ret; |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 826 | |
| 827 | if (reg & PALMAS_SMPS_CTRL_SMPS12_SMPS123_EN) |
| 828 | pmic->smps123 = 1; |
| 829 | |
| 830 | if (reg & PALMAS_SMPS_CTRL_SMPS45_SMPS457_EN) |
| 831 | pmic->smps457 = 1; |
| 832 | |
| 833 | config.regmap = palmas->regmap[REGULATOR_SLAVE]; |
| 834 | config.dev = &pdev->dev; |
| 835 | config.driver_data = pmic; |
| 836 | |
| 837 | for (id = 0; id < PALMAS_REG_LDO1; id++) { |
Laxman Dewangan | 28d1e8c | 2013-04-18 18:32:47 +0530 | [diff] [blame] | 838 | bool ramp_delay_support = false; |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 839 | |
| 840 | /* |
| 841 | * Miss out regulators which are not available due |
| 842 | * to slaving configurations. |
| 843 | */ |
| 844 | switch (id) { |
| 845 | case PALMAS_REG_SMPS12: |
| 846 | case PALMAS_REG_SMPS3: |
| 847 | if (pmic->smps123) |
| 848 | continue; |
Laxman Dewangan | 28d1e8c | 2013-04-18 18:32:47 +0530 | [diff] [blame] | 849 | if (id == PALMAS_REG_SMPS12) |
| 850 | ramp_delay_support = true; |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 851 | break; |
| 852 | case PALMAS_REG_SMPS123: |
| 853 | if (!pmic->smps123) |
| 854 | continue; |
Laxman Dewangan | 28d1e8c | 2013-04-18 18:32:47 +0530 | [diff] [blame] | 855 | ramp_delay_support = true; |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 856 | break; |
| 857 | case PALMAS_REG_SMPS45: |
| 858 | case PALMAS_REG_SMPS7: |
| 859 | if (pmic->smps457) |
| 860 | continue; |
Laxman Dewangan | 28d1e8c | 2013-04-18 18:32:47 +0530 | [diff] [blame] | 861 | if (id == PALMAS_REG_SMPS45) |
| 862 | ramp_delay_support = true; |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 863 | break; |
| 864 | case PALMAS_REG_SMPS457: |
| 865 | if (!pmic->smps457) |
| 866 | continue; |
Laxman Dewangan | 28d1e8c | 2013-04-18 18:32:47 +0530 | [diff] [blame] | 867 | ramp_delay_support = true; |
| 868 | break; |
Kishon Vijay Abraham I | 77409d9 | 2013-08-12 14:21:14 +0530 | [diff] [blame] | 869 | case PALMAS_REG_SMPS10_OUT1: |
| 870 | case PALMAS_REG_SMPS10_OUT2: |
J Keerthy | 1ffb0be | 2013-06-19 11:27:48 +0530 | [diff] [blame] | 871 | if (!PALMAS_PMIC_HAS(palmas, SMPS10_BOOST)) |
| 872 | continue; |
Laxman Dewangan | 28d1e8c | 2013-04-18 18:32:47 +0530 | [diff] [blame] | 873 | } |
| 874 | |
Sachin Kamat | 3f4d636 | 2013-05-08 16:09:06 +0530 | [diff] [blame] | 875 | if ((id == PALMAS_REG_SMPS6) || (id == PALMAS_REG_SMPS8)) |
Laxman Dewangan | 28d1e8c | 2013-04-18 18:32:47 +0530 | [diff] [blame] | 876 | ramp_delay_support = true; |
| 877 | |
| 878 | if (ramp_delay_support) { |
| 879 | addr = palmas_regs_info[id].tstep_addr; |
| 880 | ret = palmas_smps_read(pmic->palmas, addr, ®); |
| 881 | if (ret < 0) { |
| 882 | dev_err(&pdev->dev, |
| 883 | "reading TSTEP reg failed: %d\n", ret); |
Sachin Kamat | 51c86b3 | 2013-09-04 12:01:01 +0530 | [diff] [blame] | 884 | return ret; |
Laxman Dewangan | 28d1e8c | 2013-04-18 18:32:47 +0530 | [diff] [blame] | 885 | } |
| 886 | pmic->desc[id].ramp_delay = |
| 887 | palmas_smps_ramp_delay[reg & 0x3]; |
| 888 | pmic->ramp_delay[id] = pmic->desc[id].ramp_delay; |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 889 | } |
| 890 | |
Axel Lin | bdc4baa | 2012-11-29 10:01:44 +0800 | [diff] [blame] | 891 | /* Initialise sleep/init values from platform data */ |
| 892 | if (pdata && pdata->reg_init[id]) { |
| 893 | reg_init = pdata->reg_init[id]; |
| 894 | ret = palmas_smps_init(palmas, id, reg_init); |
| 895 | if (ret) |
Sachin Kamat | 51c86b3 | 2013-09-04 12:01:01 +0530 | [diff] [blame] | 896 | return ret; |
Laxman Dewangan | 32b6d3f | 2013-08-21 16:18:16 +0530 | [diff] [blame] | 897 | } else { |
| 898 | reg_init = NULL; |
Axel Lin | bdc4baa | 2012-11-29 10:01:44 +0800 | [diff] [blame] | 899 | } |
| 900 | |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 901 | /* Register the regulators */ |
| 902 | pmic->desc[id].name = palmas_regs_info[id].name; |
| 903 | pmic->desc[id].id = id; |
| 904 | |
Axel Lin | fedd89b | 2012-06-06 20:01:38 +0800 | [diff] [blame] | 905 | switch (id) { |
Kishon Vijay Abraham I | 77409d9 | 2013-08-12 14:21:14 +0530 | [diff] [blame] | 906 | case PALMAS_REG_SMPS10_OUT1: |
| 907 | case PALMAS_REG_SMPS10_OUT2: |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 908 | pmic->desc[id].n_voltages = PALMAS_SMPS10_NUM_VOLTAGES; |
| 909 | pmic->desc[id].ops = &palmas_ops_smps10; |
Axel Lin | 12565b1 | 2012-07-18 12:31:03 +0800 | [diff] [blame] | 910 | pmic->desc[id].vsel_reg = |
| 911 | PALMAS_BASE_TO_REG(PALMAS_SMPS_BASE, |
| 912 | PALMAS_SMPS10_CTRL); |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 913 | pmic->desc[id].vsel_mask = SMPS10_VSEL; |
Graeme Gregory | a68de07 | 2012-06-22 13:36:20 +0100 | [diff] [blame] | 914 | pmic->desc[id].enable_reg = |
| 915 | PALMAS_BASE_TO_REG(PALMAS_SMPS_BASE, |
Kishon Vijay Abraham I | f232168 | 2013-05-30 15:55:09 +0530 | [diff] [blame] | 916 | PALMAS_SMPS10_CTRL); |
Kishon Vijay Abraham I | 77409d9 | 2013-08-12 14:21:14 +0530 | [diff] [blame] | 917 | if (id == PALMAS_REG_SMPS10_OUT1) |
| 918 | pmic->desc[id].enable_mask = SMPS10_SWITCH_EN; |
| 919 | else |
| 920 | pmic->desc[id].enable_mask = SMPS10_BOOST_EN; |
| 921 | pmic->desc[id].bypass_reg = |
| 922 | PALMAS_BASE_TO_REG(PALMAS_SMPS_BASE, |
| 923 | PALMAS_SMPS10_CTRL); |
| 924 | pmic->desc[id].bypass_mask = SMPS10_BYPASS_EN; |
Axel Lin | 8029a00 | 2012-05-22 12:26:42 +0800 | [diff] [blame] | 925 | pmic->desc[id].min_uV = 3750000; |
| 926 | pmic->desc[id].uV_step = 1250000; |
Axel Lin | fedd89b | 2012-06-06 20:01:38 +0800 | [diff] [blame] | 927 | break; |
| 928 | default: |
Axel Lin | bdc4baa | 2012-11-29 10:01:44 +0800 | [diff] [blame] | 929 | /* |
| 930 | * Read and store the RANGE bit for later use |
| 931 | * This must be done before regulator is probed, |
Laxman Dewangan | 51d3a0c | 2013-04-18 18:32:48 +0530 | [diff] [blame] | 932 | * otherwise we error in probe with unsupportable |
| 933 | * ranges. Read the current smps mode for later use. |
Axel Lin | bdc4baa | 2012-11-29 10:01:44 +0800 | [diff] [blame] | 934 | */ |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 935 | addr = palmas_regs_info[id].vsel_addr; |
Keerthy | dbabd62 | 2014-05-22 14:48:29 +0530 | [diff] [blame] | 936 | pmic->desc[id].n_linear_ranges = 3; |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 937 | |
| 938 | ret = palmas_smps_read(pmic->palmas, addr, ®); |
| 939 | if (ret) |
Sachin Kamat | 51c86b3 | 2013-09-04 12:01:01 +0530 | [diff] [blame] | 940 | return ret; |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 941 | if (reg & PALMAS_SMPS12_VOLTAGE_RANGE) |
| 942 | pmic->range[id] = 1; |
Keerthy | dbabd62 | 2014-05-22 14:48:29 +0530 | [diff] [blame] | 943 | if (pmic->range[id]) |
| 944 | pmic->desc[id].linear_ranges = smps_high_ranges; |
| 945 | else |
| 946 | pmic->desc[id].linear_ranges = smps_low_ranges; |
Axel Lin | bdc4baa | 2012-11-29 10:01:44 +0800 | [diff] [blame] | 947 | |
Laxman Dewangan | 32b6d3f | 2013-08-21 16:18:16 +0530 | [diff] [blame] | 948 | if (reg_init && reg_init->roof_floor) |
| 949 | pmic->desc[id].ops = |
| 950 | &palmas_ops_ext_control_smps; |
| 951 | else |
| 952 | pmic->desc[id].ops = &palmas_ops_smps; |
Axel Lin | bdc4baa | 2012-11-29 10:01:44 +0800 | [diff] [blame] | 953 | pmic->desc[id].n_voltages = PALMAS_SMPS_NUM_VOLTAGES; |
| 954 | pmic->desc[id].vsel_reg = |
| 955 | PALMAS_BASE_TO_REG(PALMAS_SMPS_BASE, |
| 956 | palmas_regs_info[id].vsel_addr); |
| 957 | pmic->desc[id].vsel_mask = |
| 958 | PALMAS_SMPS12_VOLTAGE_VSEL_MASK; |
Laxman Dewangan | 51d3a0c | 2013-04-18 18:32:48 +0530 | [diff] [blame] | 959 | |
| 960 | /* Read the smps mode for later use. */ |
| 961 | addr = palmas_regs_info[id].ctrl_addr; |
| 962 | ret = palmas_smps_read(pmic->palmas, addr, ®); |
| 963 | if (ret) |
Sachin Kamat | 51c86b3 | 2013-09-04 12:01:01 +0530 | [diff] [blame] | 964 | return ret; |
Laxman Dewangan | 51d3a0c | 2013-04-18 18:32:48 +0530 | [diff] [blame] | 965 | pmic->current_reg_mode[id] = reg & |
| 966 | PALMAS_SMPS12_CTRL_MODE_ACTIVE_MASK; |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 967 | } |
| 968 | |
Axel Lin | bdc4baa | 2012-11-29 10:01:44 +0800 | [diff] [blame] | 969 | pmic->desc[id].type = REGULATOR_VOLTAGE; |
| 970 | pmic->desc[id].owner = THIS_MODULE; |
| 971 | |
Graeme Gregory | a361cd9 | 2012-08-28 13:47:40 +0200 | [diff] [blame] | 972 | if (pdata) |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 973 | config.init_data = pdata->reg_data[id]; |
| 974 | else |
| 975 | config.init_data = NULL; |
| 976 | |
Laxman Dewangan | 504382c | 2013-03-20 19:26:37 +0530 | [diff] [blame] | 977 | pmic->desc[id].supply_name = palmas_regs_info[id].sname; |
Graeme Gregory | a361cd9 | 2012-08-28 13:47:40 +0200 | [diff] [blame] | 978 | config.of_node = palmas_matches[id].of_node; |
| 979 | |
Sachin Kamat | 51c86b3 | 2013-09-04 12:01:01 +0530 | [diff] [blame] | 980 | rdev = devm_regulator_register(&pdev->dev, &pmic->desc[id], |
| 981 | &config); |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 982 | if (IS_ERR(rdev)) { |
| 983 | dev_err(&pdev->dev, |
| 984 | "failed to register %s regulator\n", |
| 985 | pdev->name); |
Sachin Kamat | 51c86b3 | 2013-09-04 12:01:01 +0530 | [diff] [blame] | 986 | return PTR_ERR(rdev); |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 987 | } |
| 988 | |
| 989 | /* Save regulator for cleanup */ |
| 990 | pmic->rdev[id] = rdev; |
| 991 | } |
| 992 | |
| 993 | /* Start this loop from the id left from previous loop */ |
| 994 | for (; id < PALMAS_NUM_REGS; id++) { |
Laxman Dewangan | 32b6d3f | 2013-08-21 16:18:16 +0530 | [diff] [blame] | 995 | if (pdata && pdata->reg_init[id]) |
| 996 | reg_init = pdata->reg_init[id]; |
| 997 | else |
| 998 | reg_init = NULL; |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 999 | |
| 1000 | /* Miss out regulators which are not available due |
| 1001 | * to alternate functions. |
| 1002 | */ |
| 1003 | |
| 1004 | /* Register the regulators */ |
| 1005 | pmic->desc[id].name = palmas_regs_info[id].name; |
| 1006 | pmic->desc[id].id = id; |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 1007 | pmic->desc[id].type = REGULATOR_VOLTAGE; |
| 1008 | pmic->desc[id].owner = THIS_MODULE; |
Laxman Dewangan | aa07f02 | 2013-04-17 15:13:12 +0530 | [diff] [blame] | 1009 | |
| 1010 | if (id < PALMAS_REG_REGEN1) { |
| 1011 | pmic->desc[id].n_voltages = PALMAS_LDO_NUM_VOLTAGES; |
Laxman Dewangan | 32b6d3f | 2013-08-21 16:18:16 +0530 | [diff] [blame] | 1012 | if (reg_init && reg_init->roof_floor) |
| 1013 | pmic->desc[id].ops = |
| 1014 | &palmas_ops_ext_control_ldo; |
| 1015 | else |
| 1016 | pmic->desc[id].ops = &palmas_ops_ldo; |
Laxman Dewangan | aa07f02 | 2013-04-17 15:13:12 +0530 | [diff] [blame] | 1017 | pmic->desc[id].min_uV = 900000; |
| 1018 | pmic->desc[id].uV_step = 50000; |
| 1019 | pmic->desc[id].linear_min_sel = 1; |
Laxman Dewangan | 087d30e | 2013-09-10 16:48:07 +0530 | [diff] [blame] | 1020 | pmic->desc[id].enable_time = 500; |
Laxman Dewangan | aa07f02 | 2013-04-17 15:13:12 +0530 | [diff] [blame] | 1021 | pmic->desc[id].vsel_reg = |
| 1022 | PALMAS_BASE_TO_REG(PALMAS_LDO_BASE, |
Axel Lin | 4a247a9 | 2012-07-18 12:34:08 +0800 | [diff] [blame] | 1023 | palmas_regs_info[id].vsel_addr); |
Laxman Dewangan | aa07f02 | 2013-04-17 15:13:12 +0530 | [diff] [blame] | 1024 | pmic->desc[id].vsel_mask = |
| 1025 | PALMAS_LDO1_VOLTAGE_VSEL_MASK; |
| 1026 | pmic->desc[id].enable_reg = |
| 1027 | PALMAS_BASE_TO_REG(PALMAS_LDO_BASE, |
Graeme Gregory | a68de07 | 2012-06-22 13:36:20 +0100 | [diff] [blame] | 1028 | palmas_regs_info[id].ctrl_addr); |
Laxman Dewangan | aa07f02 | 2013-04-17 15:13:12 +0530 | [diff] [blame] | 1029 | pmic->desc[id].enable_mask = |
| 1030 | PALMAS_LDO1_CTRL_MODE_ACTIVE; |
Laxman Dewangan | 17c11a7 | 2013-04-17 15:13:13 +0530 | [diff] [blame] | 1031 | |
| 1032 | /* Check if LDO8 is in tracking mode or not */ |
| 1033 | if (pdata && (id == PALMAS_REG_LDO8) && |
| 1034 | pdata->enable_ldo8_tracking) { |
| 1035 | palmas_enable_ldo8_track(palmas); |
Axel Lin | 3df4a81 | 2013-04-19 00:53:52 +0800 | [diff] [blame] | 1036 | pmic->desc[id].min_uV = 450000; |
Laxman Dewangan | 17c11a7 | 2013-04-17 15:13:13 +0530 | [diff] [blame] | 1037 | pmic->desc[id].uV_step = 25000; |
| 1038 | } |
Laxman Dewangan | 087d30e | 2013-09-10 16:48:07 +0530 | [diff] [blame] | 1039 | |
| 1040 | /* LOD6 in vibrator mode will have enable time 2000us */ |
| 1041 | if (pdata && pdata->ldo6_vibrator && |
| 1042 | (id == PALMAS_REG_LDO6)) |
| 1043 | pmic->desc[id].enable_time = 2000; |
Laxman Dewangan | aa07f02 | 2013-04-17 15:13:12 +0530 | [diff] [blame] | 1044 | } else { |
| 1045 | pmic->desc[id].n_voltages = 1; |
Laxman Dewangan | 32b6d3f | 2013-08-21 16:18:16 +0530 | [diff] [blame] | 1046 | if (reg_init && reg_init->roof_floor) |
| 1047 | pmic->desc[id].ops = |
| 1048 | &palmas_ops_ext_control_extreg; |
| 1049 | else |
| 1050 | pmic->desc[id].ops = &palmas_ops_extreg; |
Laxman Dewangan | aa07f02 | 2013-04-17 15:13:12 +0530 | [diff] [blame] | 1051 | pmic->desc[id].enable_reg = |
| 1052 | PALMAS_BASE_TO_REG(PALMAS_RESOURCE_BASE, |
| 1053 | palmas_regs_info[id].ctrl_addr); |
| 1054 | pmic->desc[id].enable_mask = |
| 1055 | PALMAS_REGEN1_CTRL_MODE_ACTIVE; |
| 1056 | } |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 1057 | |
Graeme Gregory | a361cd9 | 2012-08-28 13:47:40 +0200 | [diff] [blame] | 1058 | if (pdata) |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 1059 | config.init_data = pdata->reg_data[id]; |
| 1060 | else |
| 1061 | config.init_data = NULL; |
| 1062 | |
Laxman Dewangan | 504382c | 2013-03-20 19:26:37 +0530 | [diff] [blame] | 1063 | pmic->desc[id].supply_name = palmas_regs_info[id].sname; |
Graeme Gregory | a361cd9 | 2012-08-28 13:47:40 +0200 | [diff] [blame] | 1064 | config.of_node = palmas_matches[id].of_node; |
| 1065 | |
Sachin Kamat | 51c86b3 | 2013-09-04 12:01:01 +0530 | [diff] [blame] | 1066 | rdev = devm_regulator_register(&pdev->dev, &pmic->desc[id], |
| 1067 | &config); |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 1068 | if (IS_ERR(rdev)) { |
| 1069 | dev_err(&pdev->dev, |
| 1070 | "failed to register %s regulator\n", |
| 1071 | pdev->name); |
Sachin Kamat | 51c86b3 | 2013-09-04 12:01:01 +0530 | [diff] [blame] | 1072 | return PTR_ERR(rdev); |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 1073 | } |
| 1074 | |
| 1075 | /* Save regulator for cleanup */ |
| 1076 | pmic->rdev[id] = rdev; |
| 1077 | |
| 1078 | /* Initialise sleep/init values from platform data */ |
Graeme Gregory | a361cd9 | 2012-08-28 13:47:40 +0200 | [diff] [blame] | 1079 | if (pdata) { |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 1080 | reg_init = pdata->reg_init[id]; |
| 1081 | if (reg_init) { |
Laxman Dewangan | aa07f02 | 2013-04-17 15:13:12 +0530 | [diff] [blame] | 1082 | if (id < PALMAS_REG_REGEN1) |
| 1083 | ret = palmas_ldo_init(palmas, |
| 1084 | id, reg_init); |
| 1085 | else |
| 1086 | ret = palmas_extreg_init(palmas, |
| 1087 | id, reg_init); |
Axel Lin | cb2e45e | 2013-09-05 11:31:25 +0800 | [diff] [blame] | 1088 | if (ret) |
Sachin Kamat | 51c86b3 | 2013-09-04 12:01:01 +0530 | [diff] [blame] | 1089 | return ret; |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 1090 | } |
| 1091 | } |
| 1092 | } |
| 1093 | |
Laxman Dewangan | 17c11a7 | 2013-04-17 15:13:13 +0530 | [diff] [blame] | 1094 | |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 1095 | return 0; |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 1096 | } |
| 1097 | |
Jingoo Han | 2449df9 | 2014-05-07 17:07:54 +0900 | [diff] [blame] | 1098 | static const struct of_device_id of_palmas_match_tbl[] = { |
Graeme Gregory | a361cd9 | 2012-08-28 13:47:40 +0200 | [diff] [blame] | 1099 | { .compatible = "ti,palmas-pmic", }, |
Graeme Gregory | 7be859f | 2013-03-07 13:17:48 +0000 | [diff] [blame] | 1100 | { .compatible = "ti,twl6035-pmic", }, |
| 1101 | { .compatible = "ti,twl6036-pmic", }, |
| 1102 | { .compatible = "ti,twl6037-pmic", }, |
| 1103 | { .compatible = "ti,tps65913-pmic", }, |
| 1104 | { .compatible = "ti,tps65914-pmic", }, |
| 1105 | { .compatible = "ti,tps80036-pmic", }, |
J Keerthy | b5c4678 | 2013-06-20 16:32:15 +0530 | [diff] [blame] | 1106 | { .compatible = "ti,tps659038-pmic", }, |
Graeme Gregory | a361cd9 | 2012-08-28 13:47:40 +0200 | [diff] [blame] | 1107 | { /* end */ } |
| 1108 | }; |
| 1109 | |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 1110 | static struct platform_driver palmas_driver = { |
| 1111 | .driver = { |
| 1112 | .name = "palmas-pmic", |
Graeme Gregory | a361cd9 | 2012-08-28 13:47:40 +0200 | [diff] [blame] | 1113 | .of_match_table = of_palmas_match_tbl, |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 1114 | .owner = THIS_MODULE, |
| 1115 | }, |
Laxman Dewangan | bbcf50b | 2013-03-18 14:59:49 +0530 | [diff] [blame] | 1116 | .probe = palmas_regulators_probe, |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 1117 | }; |
| 1118 | |
| 1119 | static int __init palmas_init(void) |
| 1120 | { |
| 1121 | return platform_driver_register(&palmas_driver); |
| 1122 | } |
| 1123 | subsys_initcall(palmas_init); |
| 1124 | |
| 1125 | static void __exit palmas_exit(void) |
| 1126 | { |
| 1127 | platform_driver_unregister(&palmas_driver); |
| 1128 | } |
| 1129 | module_exit(palmas_exit); |
| 1130 | |
| 1131 | MODULE_AUTHOR("Graeme Gregory <gg@slimlogic.co.uk>"); |
| 1132 | MODULE_DESCRIPTION("Palmas voltage regulator driver"); |
| 1133 | MODULE_LICENSE("GPL"); |
| 1134 | MODULE_ALIAS("platform:palmas-pmic"); |
Graeme Gregory | a361cd9 | 2012-08-28 13:47:40 +0200 | [diff] [blame] | 1135 | MODULE_DEVICE_TABLE(of, of_palmas_match_tbl); |