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