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