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 | |
Keerthy | dbabd62 | 2014-05-22 14:48:29 +0530 | [diff] [blame] | 30 | static const struct regulator_linear_range smps_low_ranges[] = { |
Nishanth Menon | 6b7f2d8 | 2014-06-04 14:34:31 -0500 | [diff] [blame] | 31 | REGULATOR_LINEAR_RANGE(0, 0x0, 0x0, 0), |
Keerthy | dbabd62 | 2014-05-22 14:48:29 +0530 | [diff] [blame] | 32 | REGULATOR_LINEAR_RANGE(500000, 0x1, 0x6, 0), |
| 33 | REGULATOR_LINEAR_RANGE(510000, 0x7, 0x79, 10000), |
| 34 | REGULATOR_LINEAR_RANGE(1650000, 0x7A, 0x7f, 0), |
| 35 | }; |
| 36 | |
| 37 | static const struct regulator_linear_range smps_high_ranges[] = { |
Nishanth Menon | 6b7f2d8 | 2014-06-04 14:34:31 -0500 | [diff] [blame] | 38 | REGULATOR_LINEAR_RANGE(0, 0x0, 0x0, 0), |
Keerthy | dbabd62 | 2014-05-22 14:48:29 +0530 | [diff] [blame] | 39 | REGULATOR_LINEAR_RANGE(1000000, 0x1, 0x6, 0), |
| 40 | REGULATOR_LINEAR_RANGE(1020000, 0x7, 0x79, 20000), |
| 41 | REGULATOR_LINEAR_RANGE(3300000, 0x7A, 0x7f, 0), |
| 42 | }; |
| 43 | |
Nishanth Menon | 6839cd6 | 2014-06-30 10:57:37 -0500 | [diff] [blame] | 44 | static struct palmas_regs_info palmas_generic_regs_info[] = { |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 45 | { |
| 46 | .name = "SMPS12", |
Laxman Dewangan | 504382c | 2013-03-20 19:26:37 +0530 | [diff] [blame] | 47 | .sname = "smps1-in", |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 48 | .vsel_addr = PALMAS_SMPS12_VOLTAGE, |
| 49 | .ctrl_addr = PALMAS_SMPS12_CTRL, |
| 50 | .tstep_addr = PALMAS_SMPS12_TSTEP, |
Laxman Dewangan | 32b6d3f | 2013-08-21 16:18:16 +0530 | [diff] [blame] | 51 | .sleep_id = PALMAS_EXTERNAL_REQSTR_ID_SMPS12, |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 52 | }, |
| 53 | { |
| 54 | .name = "SMPS123", |
Laxman Dewangan | 504382c | 2013-03-20 19:26:37 +0530 | [diff] [blame] | 55 | .sname = "smps1-in", |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 56 | .vsel_addr = PALMAS_SMPS12_VOLTAGE, |
| 57 | .ctrl_addr = PALMAS_SMPS12_CTRL, |
| 58 | .tstep_addr = PALMAS_SMPS12_TSTEP, |
Laxman Dewangan | 32b6d3f | 2013-08-21 16:18:16 +0530 | [diff] [blame] | 59 | .sleep_id = PALMAS_EXTERNAL_REQSTR_ID_SMPS12, |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 60 | }, |
| 61 | { |
| 62 | .name = "SMPS3", |
Laxman Dewangan | 504382c | 2013-03-20 19:26:37 +0530 | [diff] [blame] | 63 | .sname = "smps3-in", |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 64 | .vsel_addr = PALMAS_SMPS3_VOLTAGE, |
| 65 | .ctrl_addr = PALMAS_SMPS3_CTRL, |
Laxman Dewangan | 32b6d3f | 2013-08-21 16:18:16 +0530 | [diff] [blame] | 66 | .sleep_id = PALMAS_EXTERNAL_REQSTR_ID_SMPS3, |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 67 | }, |
| 68 | { |
| 69 | .name = "SMPS45", |
Laxman Dewangan | 504382c | 2013-03-20 19:26:37 +0530 | [diff] [blame] | 70 | .sname = "smps4-in", |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 71 | .vsel_addr = PALMAS_SMPS45_VOLTAGE, |
| 72 | .ctrl_addr = PALMAS_SMPS45_CTRL, |
| 73 | .tstep_addr = PALMAS_SMPS45_TSTEP, |
Laxman Dewangan | 32b6d3f | 2013-08-21 16:18:16 +0530 | [diff] [blame] | 74 | .sleep_id = PALMAS_EXTERNAL_REQSTR_ID_SMPS45, |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 75 | }, |
| 76 | { |
| 77 | .name = "SMPS457", |
Laxman Dewangan | 504382c | 2013-03-20 19:26:37 +0530 | [diff] [blame] | 78 | .sname = "smps4-in", |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 79 | .vsel_addr = PALMAS_SMPS45_VOLTAGE, |
| 80 | .ctrl_addr = PALMAS_SMPS45_CTRL, |
| 81 | .tstep_addr = PALMAS_SMPS45_TSTEP, |
Laxman Dewangan | 32b6d3f | 2013-08-21 16:18:16 +0530 | [diff] [blame] | 82 | .sleep_id = PALMAS_EXTERNAL_REQSTR_ID_SMPS45, |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 83 | }, |
| 84 | { |
| 85 | .name = "SMPS6", |
Laxman Dewangan | 504382c | 2013-03-20 19:26:37 +0530 | [diff] [blame] | 86 | .sname = "smps6-in", |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 87 | .vsel_addr = PALMAS_SMPS6_VOLTAGE, |
| 88 | .ctrl_addr = PALMAS_SMPS6_CTRL, |
| 89 | .tstep_addr = PALMAS_SMPS6_TSTEP, |
Laxman Dewangan | 32b6d3f | 2013-08-21 16:18:16 +0530 | [diff] [blame] | 90 | .sleep_id = PALMAS_EXTERNAL_REQSTR_ID_SMPS6, |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 91 | }, |
| 92 | { |
| 93 | .name = "SMPS7", |
Laxman Dewangan | 504382c | 2013-03-20 19:26:37 +0530 | [diff] [blame] | 94 | .sname = "smps7-in", |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 95 | .vsel_addr = PALMAS_SMPS7_VOLTAGE, |
| 96 | .ctrl_addr = PALMAS_SMPS7_CTRL, |
Laxman Dewangan | 32b6d3f | 2013-08-21 16:18:16 +0530 | [diff] [blame] | 97 | .sleep_id = PALMAS_EXTERNAL_REQSTR_ID_SMPS7, |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 98 | }, |
| 99 | { |
| 100 | .name = "SMPS8", |
Laxman Dewangan | 504382c | 2013-03-20 19:26:37 +0530 | [diff] [blame] | 101 | .sname = "smps8-in", |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 102 | .vsel_addr = PALMAS_SMPS8_VOLTAGE, |
| 103 | .ctrl_addr = PALMAS_SMPS8_CTRL, |
| 104 | .tstep_addr = PALMAS_SMPS8_TSTEP, |
Laxman Dewangan | 32b6d3f | 2013-08-21 16:18:16 +0530 | [diff] [blame] | 105 | .sleep_id = PALMAS_EXTERNAL_REQSTR_ID_SMPS8, |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 106 | }, |
| 107 | { |
| 108 | .name = "SMPS9", |
Laxman Dewangan | 504382c | 2013-03-20 19:26:37 +0530 | [diff] [blame] | 109 | .sname = "smps9-in", |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 110 | .vsel_addr = PALMAS_SMPS9_VOLTAGE, |
| 111 | .ctrl_addr = PALMAS_SMPS9_CTRL, |
Laxman Dewangan | 32b6d3f | 2013-08-21 16:18:16 +0530 | [diff] [blame] | 112 | .sleep_id = PALMAS_EXTERNAL_REQSTR_ID_SMPS9, |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 113 | }, |
| 114 | { |
Kishon Vijay Abraham I | 77409d9 | 2013-08-12 14:21:14 +0530 | [diff] [blame] | 115 | .name = "SMPS10_OUT2", |
Laxman Dewangan | 504382c | 2013-03-20 19:26:37 +0530 | [diff] [blame] | 116 | .sname = "smps10-in", |
Axel Lin | e31089c | 2013-04-19 20:33:45 +0800 | [diff] [blame] | 117 | .ctrl_addr = PALMAS_SMPS10_CTRL, |
Laxman Dewangan | 32b6d3f | 2013-08-21 16:18:16 +0530 | [diff] [blame] | 118 | .sleep_id = PALMAS_EXTERNAL_REQSTR_ID_SMPS10, |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 119 | }, |
| 120 | { |
Kishon Vijay Abraham I | 77409d9 | 2013-08-12 14:21:14 +0530 | [diff] [blame] | 121 | .name = "SMPS10_OUT1", |
| 122 | .sname = "smps10-out2", |
| 123 | .ctrl_addr = PALMAS_SMPS10_CTRL, |
Laxman Dewangan | 32b6d3f | 2013-08-21 16:18:16 +0530 | [diff] [blame] | 124 | .sleep_id = PALMAS_EXTERNAL_REQSTR_ID_SMPS10, |
Kishon Vijay Abraham I | 77409d9 | 2013-08-12 14:21:14 +0530 | [diff] [blame] | 125 | }, |
| 126 | { |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 127 | .name = "LDO1", |
Laxman Dewangan | 504382c | 2013-03-20 19:26:37 +0530 | [diff] [blame] | 128 | .sname = "ldo1-in", |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 129 | .vsel_addr = PALMAS_LDO1_VOLTAGE, |
| 130 | .ctrl_addr = PALMAS_LDO1_CTRL, |
Laxman Dewangan | 32b6d3f | 2013-08-21 16:18:16 +0530 | [diff] [blame] | 131 | .sleep_id = PALMAS_EXTERNAL_REQSTR_ID_LDO1, |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 132 | }, |
| 133 | { |
| 134 | .name = "LDO2", |
Laxman Dewangan | 504382c | 2013-03-20 19:26:37 +0530 | [diff] [blame] | 135 | .sname = "ldo2-in", |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 136 | .vsel_addr = PALMAS_LDO2_VOLTAGE, |
| 137 | .ctrl_addr = PALMAS_LDO2_CTRL, |
Laxman Dewangan | 32b6d3f | 2013-08-21 16:18:16 +0530 | [diff] [blame] | 138 | .sleep_id = PALMAS_EXTERNAL_REQSTR_ID_LDO2, |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 139 | }, |
| 140 | { |
| 141 | .name = "LDO3", |
Laxman Dewangan | 504382c | 2013-03-20 19:26:37 +0530 | [diff] [blame] | 142 | .sname = "ldo3-in", |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 143 | .vsel_addr = PALMAS_LDO3_VOLTAGE, |
| 144 | .ctrl_addr = PALMAS_LDO3_CTRL, |
Laxman Dewangan | 32b6d3f | 2013-08-21 16:18:16 +0530 | [diff] [blame] | 145 | .sleep_id = PALMAS_EXTERNAL_REQSTR_ID_LDO3, |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 146 | }, |
| 147 | { |
| 148 | .name = "LDO4", |
Laxman Dewangan | 504382c | 2013-03-20 19:26:37 +0530 | [diff] [blame] | 149 | .sname = "ldo4-in", |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 150 | .vsel_addr = PALMAS_LDO4_VOLTAGE, |
| 151 | .ctrl_addr = PALMAS_LDO4_CTRL, |
Laxman Dewangan | 32b6d3f | 2013-08-21 16:18:16 +0530 | [diff] [blame] | 152 | .sleep_id = PALMAS_EXTERNAL_REQSTR_ID_LDO4, |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 153 | }, |
| 154 | { |
| 155 | .name = "LDO5", |
Laxman Dewangan | 504382c | 2013-03-20 19:26:37 +0530 | [diff] [blame] | 156 | .sname = "ldo5-in", |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 157 | .vsel_addr = PALMAS_LDO5_VOLTAGE, |
| 158 | .ctrl_addr = PALMAS_LDO5_CTRL, |
Laxman Dewangan | 32b6d3f | 2013-08-21 16:18:16 +0530 | [diff] [blame] | 159 | .sleep_id = PALMAS_EXTERNAL_REQSTR_ID_LDO5, |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 160 | }, |
| 161 | { |
| 162 | .name = "LDO6", |
Laxman Dewangan | 504382c | 2013-03-20 19:26:37 +0530 | [diff] [blame] | 163 | .sname = "ldo6-in", |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 164 | .vsel_addr = PALMAS_LDO6_VOLTAGE, |
| 165 | .ctrl_addr = PALMAS_LDO6_CTRL, |
Laxman Dewangan | 32b6d3f | 2013-08-21 16:18:16 +0530 | [diff] [blame] | 166 | .sleep_id = PALMAS_EXTERNAL_REQSTR_ID_LDO6, |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 167 | }, |
| 168 | { |
| 169 | .name = "LDO7", |
Laxman Dewangan | 504382c | 2013-03-20 19:26:37 +0530 | [diff] [blame] | 170 | .sname = "ldo7-in", |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 171 | .vsel_addr = PALMAS_LDO7_VOLTAGE, |
| 172 | .ctrl_addr = PALMAS_LDO7_CTRL, |
Laxman Dewangan | 32b6d3f | 2013-08-21 16:18:16 +0530 | [diff] [blame] | 173 | .sleep_id = PALMAS_EXTERNAL_REQSTR_ID_LDO7, |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 174 | }, |
| 175 | { |
| 176 | .name = "LDO8", |
Laxman Dewangan | 504382c | 2013-03-20 19:26:37 +0530 | [diff] [blame] | 177 | .sname = "ldo8-in", |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 178 | .vsel_addr = PALMAS_LDO8_VOLTAGE, |
| 179 | .ctrl_addr = PALMAS_LDO8_CTRL, |
Laxman Dewangan | 32b6d3f | 2013-08-21 16:18:16 +0530 | [diff] [blame] | 180 | .sleep_id = PALMAS_EXTERNAL_REQSTR_ID_LDO8, |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 181 | }, |
| 182 | { |
| 183 | .name = "LDO9", |
Laxman Dewangan | 504382c | 2013-03-20 19:26:37 +0530 | [diff] [blame] | 184 | .sname = "ldo9-in", |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 185 | .vsel_addr = PALMAS_LDO9_VOLTAGE, |
| 186 | .ctrl_addr = PALMAS_LDO9_CTRL, |
Laxman Dewangan | 32b6d3f | 2013-08-21 16:18:16 +0530 | [diff] [blame] | 187 | .sleep_id = PALMAS_EXTERNAL_REQSTR_ID_LDO9, |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 188 | }, |
| 189 | { |
| 190 | .name = "LDOLN", |
Laxman Dewangan | 504382c | 2013-03-20 19:26:37 +0530 | [diff] [blame] | 191 | .sname = "ldoln-in", |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 192 | .vsel_addr = PALMAS_LDOLN_VOLTAGE, |
| 193 | .ctrl_addr = PALMAS_LDOLN_CTRL, |
Laxman Dewangan | 32b6d3f | 2013-08-21 16:18:16 +0530 | [diff] [blame] | 194 | .sleep_id = PALMAS_EXTERNAL_REQSTR_ID_LDOLN, |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 195 | }, |
| 196 | { |
| 197 | .name = "LDOUSB", |
Laxman Dewangan | 504382c | 2013-03-20 19:26:37 +0530 | [diff] [blame] | 198 | .sname = "ldousb-in", |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 199 | .vsel_addr = PALMAS_LDOUSB_VOLTAGE, |
| 200 | .ctrl_addr = PALMAS_LDOUSB_CTRL, |
Laxman Dewangan | 32b6d3f | 2013-08-21 16:18:16 +0530 | [diff] [blame] | 201 | .sleep_id = PALMAS_EXTERNAL_REQSTR_ID_LDOUSB, |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 202 | }, |
Laxman Dewangan | aa07f02 | 2013-04-17 15:13:12 +0530 | [diff] [blame] | 203 | { |
| 204 | .name = "REGEN1", |
| 205 | .ctrl_addr = PALMAS_REGEN1_CTRL, |
Laxman Dewangan | 32b6d3f | 2013-08-21 16:18:16 +0530 | [diff] [blame] | 206 | .sleep_id = PALMAS_EXTERNAL_REQSTR_ID_REGEN1, |
Laxman Dewangan | aa07f02 | 2013-04-17 15:13:12 +0530 | [diff] [blame] | 207 | }, |
| 208 | { |
| 209 | .name = "REGEN2", |
| 210 | .ctrl_addr = PALMAS_REGEN2_CTRL, |
Laxman Dewangan | 32b6d3f | 2013-08-21 16:18:16 +0530 | [diff] [blame] | 211 | .sleep_id = PALMAS_EXTERNAL_REQSTR_ID_REGEN2, |
Laxman Dewangan | aa07f02 | 2013-04-17 15:13:12 +0530 | [diff] [blame] | 212 | }, |
| 213 | { |
| 214 | .name = "REGEN3", |
| 215 | .ctrl_addr = PALMAS_REGEN3_CTRL, |
Laxman Dewangan | 32b6d3f | 2013-08-21 16:18:16 +0530 | [diff] [blame] | 216 | .sleep_id = PALMAS_EXTERNAL_REQSTR_ID_REGEN3, |
Laxman Dewangan | aa07f02 | 2013-04-17 15:13:12 +0530 | [diff] [blame] | 217 | }, |
| 218 | { |
| 219 | .name = "SYSEN1", |
| 220 | .ctrl_addr = PALMAS_SYSEN1_CTRL, |
Laxman Dewangan | 32b6d3f | 2013-08-21 16:18:16 +0530 | [diff] [blame] | 221 | .sleep_id = PALMAS_EXTERNAL_REQSTR_ID_SYSEN1, |
Laxman Dewangan | aa07f02 | 2013-04-17 15:13:12 +0530 | [diff] [blame] | 222 | }, |
| 223 | { |
| 224 | .name = "SYSEN2", |
| 225 | .ctrl_addr = PALMAS_SYSEN2_CTRL, |
Laxman Dewangan | 32b6d3f | 2013-08-21 16:18:16 +0530 | [diff] [blame] | 226 | .sleep_id = PALMAS_EXTERNAL_REQSTR_ID_SYSEN2, |
Laxman Dewangan | aa07f02 | 2013-04-17 15:13:12 +0530 | [diff] [blame] | 227 | }, |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 228 | }; |
| 229 | |
Nishanth Menon | e7cf34e | 2014-06-30 10:57:35 -0500 | [diff] [blame] | 230 | static struct palmas_regs_info tps65917_regs_info[] = { |
Keerthy | d6f8337 | 2014-06-18 15:29:00 +0530 | [diff] [blame] | 231 | { |
| 232 | .name = "SMPS1", |
| 233 | .sname = "smps1-in", |
| 234 | .vsel_addr = TPS65917_SMPS1_VOLTAGE, |
| 235 | .ctrl_addr = TPS65917_SMPS1_CTRL, |
| 236 | .sleep_id = TPS65917_EXTERNAL_REQSTR_ID_SMPS1, |
| 237 | }, |
| 238 | { |
| 239 | .name = "SMPS2", |
| 240 | .sname = "smps2-in", |
| 241 | .vsel_addr = TPS65917_SMPS2_VOLTAGE, |
| 242 | .ctrl_addr = TPS65917_SMPS2_CTRL, |
| 243 | .sleep_id = TPS65917_EXTERNAL_REQSTR_ID_SMPS2, |
| 244 | }, |
| 245 | { |
| 246 | .name = "SMPS3", |
| 247 | .sname = "smps3-in", |
| 248 | .vsel_addr = TPS65917_SMPS3_VOLTAGE, |
| 249 | .ctrl_addr = TPS65917_SMPS3_CTRL, |
| 250 | .sleep_id = TPS65917_EXTERNAL_REQSTR_ID_SMPS3, |
| 251 | }, |
| 252 | { |
| 253 | .name = "SMPS4", |
| 254 | .sname = "smps4-in", |
| 255 | .vsel_addr = TPS65917_SMPS4_VOLTAGE, |
| 256 | .ctrl_addr = TPS65917_SMPS4_CTRL, |
| 257 | .sleep_id = TPS65917_EXTERNAL_REQSTR_ID_SMPS4, |
| 258 | }, |
| 259 | { |
| 260 | .name = "SMPS5", |
| 261 | .sname = "smps5-in", |
| 262 | .vsel_addr = TPS65917_SMPS5_VOLTAGE, |
| 263 | .ctrl_addr = TPS65917_SMPS5_CTRL, |
| 264 | .sleep_id = TPS65917_EXTERNAL_REQSTR_ID_SMPS5, |
| 265 | }, |
| 266 | { |
| 267 | .name = "LDO1", |
| 268 | .sname = "ldo1-in", |
| 269 | .vsel_addr = TPS65917_LDO1_VOLTAGE, |
| 270 | .ctrl_addr = TPS65917_LDO1_CTRL, |
| 271 | .sleep_id = TPS65917_EXTERNAL_REQSTR_ID_LDO1, |
| 272 | }, |
| 273 | { |
| 274 | .name = "LDO2", |
| 275 | .sname = "ldo2-in", |
| 276 | .vsel_addr = TPS65917_LDO2_VOLTAGE, |
| 277 | .ctrl_addr = TPS65917_LDO2_CTRL, |
| 278 | .sleep_id = TPS65917_EXTERNAL_REQSTR_ID_LDO2, |
| 279 | }, |
| 280 | { |
| 281 | .name = "LDO3", |
| 282 | .sname = "ldo3-in", |
| 283 | .vsel_addr = TPS65917_LDO3_VOLTAGE, |
| 284 | .ctrl_addr = TPS65917_LDO3_CTRL, |
| 285 | .sleep_id = TPS65917_EXTERNAL_REQSTR_ID_LDO3, |
| 286 | }, |
| 287 | { |
| 288 | .name = "LDO4", |
| 289 | .sname = "ldo4-in", |
| 290 | .vsel_addr = TPS65917_LDO4_VOLTAGE, |
| 291 | .ctrl_addr = TPS65917_LDO4_CTRL, |
| 292 | .sleep_id = TPS65917_EXTERNAL_REQSTR_ID_LDO4, |
| 293 | }, |
| 294 | { |
| 295 | .name = "LDO5", |
| 296 | .sname = "ldo5-in", |
| 297 | .vsel_addr = TPS65917_LDO5_VOLTAGE, |
| 298 | .ctrl_addr = TPS65917_LDO5_CTRL, |
| 299 | .sleep_id = TPS65917_EXTERNAL_REQSTR_ID_LDO5, |
| 300 | }, |
| 301 | { |
| 302 | .name = "REGEN1", |
| 303 | .ctrl_addr = TPS65917_REGEN1_CTRL, |
| 304 | .sleep_id = TPS65917_EXTERNAL_REQSTR_ID_REGEN1, |
| 305 | }, |
| 306 | { |
| 307 | .name = "REGEN2", |
| 308 | .ctrl_addr = TPS65917_REGEN2_CTRL, |
| 309 | .sleep_id = TPS65917_EXTERNAL_REQSTR_ID_REGEN2, |
| 310 | }, |
| 311 | { |
| 312 | .name = "REGEN3", |
| 313 | .ctrl_addr = TPS65917_REGEN3_CTRL, |
| 314 | .sleep_id = TPS65917_EXTERNAL_REQSTR_ID_REGEN3, |
| 315 | }, |
| 316 | }; |
| 317 | |
Keerthy | cac9e91 | 2014-06-18 15:28:59 +0530 | [diff] [blame] | 318 | #define EXTERNAL_REQUESTOR(_id, _offset, _pos) \ |
| 319 | [PALMAS_EXTERNAL_REQSTR_ID_##_id] = { \ |
| 320 | .id = PALMAS_EXTERNAL_REQSTR_ID_##_id, \ |
| 321 | .reg_offset = _offset, \ |
| 322 | .bit_pos = _pos, \ |
| 323 | } |
| 324 | |
Nishanth Menon | 4b09e17 | 2014-06-30 10:57:34 -0500 | [diff] [blame] | 325 | static struct palmas_sleep_requestor_info palma_sleep_req_info[] = { |
Keerthy | cac9e91 | 2014-06-18 15:28:59 +0530 | [diff] [blame] | 326 | EXTERNAL_REQUESTOR(REGEN1, 0, 0), |
| 327 | EXTERNAL_REQUESTOR(REGEN2, 0, 1), |
| 328 | EXTERNAL_REQUESTOR(SYSEN1, 0, 2), |
| 329 | EXTERNAL_REQUESTOR(SYSEN2, 0, 3), |
| 330 | EXTERNAL_REQUESTOR(CLK32KG, 0, 4), |
| 331 | EXTERNAL_REQUESTOR(CLK32KGAUDIO, 0, 5), |
| 332 | EXTERNAL_REQUESTOR(REGEN3, 0, 6), |
| 333 | EXTERNAL_REQUESTOR(SMPS12, 1, 0), |
| 334 | EXTERNAL_REQUESTOR(SMPS3, 1, 1), |
| 335 | EXTERNAL_REQUESTOR(SMPS45, 1, 2), |
| 336 | EXTERNAL_REQUESTOR(SMPS6, 1, 3), |
| 337 | EXTERNAL_REQUESTOR(SMPS7, 1, 4), |
| 338 | EXTERNAL_REQUESTOR(SMPS8, 1, 5), |
| 339 | EXTERNAL_REQUESTOR(SMPS9, 1, 6), |
| 340 | EXTERNAL_REQUESTOR(SMPS10, 1, 7), |
| 341 | EXTERNAL_REQUESTOR(LDO1, 2, 0), |
| 342 | EXTERNAL_REQUESTOR(LDO2, 2, 1), |
| 343 | EXTERNAL_REQUESTOR(LDO3, 2, 2), |
| 344 | EXTERNAL_REQUESTOR(LDO4, 2, 3), |
| 345 | EXTERNAL_REQUESTOR(LDO5, 2, 4), |
| 346 | EXTERNAL_REQUESTOR(LDO6, 2, 5), |
| 347 | EXTERNAL_REQUESTOR(LDO7, 2, 6), |
| 348 | EXTERNAL_REQUESTOR(LDO8, 2, 7), |
| 349 | EXTERNAL_REQUESTOR(LDO9, 3, 0), |
| 350 | EXTERNAL_REQUESTOR(LDOLN, 3, 1), |
| 351 | EXTERNAL_REQUESTOR(LDOUSB, 3, 2), |
| 352 | }; |
| 353 | |
Keerthy | d6f8337 | 2014-06-18 15:29:00 +0530 | [diff] [blame] | 354 | #define EXTERNAL_REQUESTOR_TPS65917(_id, _offset, _pos) \ |
| 355 | [TPS65917_EXTERNAL_REQSTR_ID_##_id] = { \ |
| 356 | .id = TPS65917_EXTERNAL_REQSTR_ID_##_id, \ |
| 357 | .reg_offset = _offset, \ |
| 358 | .bit_pos = _pos, \ |
| 359 | } |
| 360 | |
| 361 | static struct palmas_sleep_requestor_info tps65917_sleep_req_info[] = { |
| 362 | EXTERNAL_REQUESTOR_TPS65917(REGEN1, 0, 0), |
| 363 | EXTERNAL_REQUESTOR_TPS65917(REGEN2, 0, 1), |
| 364 | EXTERNAL_REQUESTOR_TPS65917(REGEN3, 0, 6), |
| 365 | EXTERNAL_REQUESTOR_TPS65917(SMPS1, 1, 0), |
| 366 | EXTERNAL_REQUESTOR_TPS65917(SMPS2, 1, 1), |
| 367 | EXTERNAL_REQUESTOR_TPS65917(SMPS3, 1, 2), |
| 368 | EXTERNAL_REQUESTOR_TPS65917(SMPS4, 1, 3), |
| 369 | EXTERNAL_REQUESTOR_TPS65917(SMPS5, 1, 4), |
| 370 | EXTERNAL_REQUESTOR_TPS65917(LDO1, 2, 0), |
| 371 | EXTERNAL_REQUESTOR_TPS65917(LDO2, 2, 1), |
| 372 | EXTERNAL_REQUESTOR_TPS65917(LDO3, 2, 2), |
| 373 | EXTERNAL_REQUESTOR_TPS65917(LDO4, 2, 3), |
| 374 | EXTERNAL_REQUESTOR_TPS65917(LDO5, 2, 4), |
| 375 | }; |
| 376 | |
Laxman Dewangan | 28d1e8c | 2013-04-18 18:32:47 +0530 | [diff] [blame] | 377 | static unsigned int palmas_smps_ramp_delay[4] = {0, 10000, 5000, 2500}; |
| 378 | |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 379 | #define SMPS_CTRL_MODE_OFF 0x00 |
| 380 | #define SMPS_CTRL_MODE_ON 0x01 |
| 381 | #define SMPS_CTRL_MODE_ECO 0x02 |
| 382 | #define SMPS_CTRL_MODE_PWM 0x03 |
| 383 | |
Laxman Dewangan | 0f45aa8 | 2013-09-04 15:20:06 +0530 | [diff] [blame] | 384 | #define PALMAS_SMPS_NUM_VOLTAGES 122 |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 385 | #define PALMAS_SMPS10_NUM_VOLTAGES 2 |
| 386 | #define PALMAS_LDO_NUM_VOLTAGES 50 |
| 387 | |
| 388 | #define SMPS10_VSEL (1<<3) |
| 389 | #define SMPS10_BOOST_EN (1<<2) |
| 390 | #define SMPS10_BYPASS_EN (1<<1) |
| 391 | #define SMPS10_SWITCH_EN (1<<0) |
| 392 | |
| 393 | #define REGULATOR_SLAVE 0 |
| 394 | |
| 395 | static int palmas_smps_read(struct palmas *palmas, unsigned int reg, |
| 396 | unsigned int *dest) |
| 397 | { |
| 398 | unsigned int addr; |
| 399 | |
| 400 | addr = PALMAS_BASE_TO_REG(PALMAS_SMPS_BASE, reg); |
| 401 | |
| 402 | return regmap_read(palmas->regmap[REGULATOR_SLAVE], addr, dest); |
| 403 | } |
| 404 | |
| 405 | static int palmas_smps_write(struct palmas *palmas, unsigned int reg, |
| 406 | unsigned int value) |
| 407 | { |
| 408 | unsigned int addr; |
| 409 | |
| 410 | addr = PALMAS_BASE_TO_REG(PALMAS_SMPS_BASE, reg); |
| 411 | |
| 412 | return regmap_write(palmas->regmap[REGULATOR_SLAVE], addr, value); |
| 413 | } |
| 414 | |
| 415 | static int palmas_ldo_read(struct palmas *palmas, unsigned int reg, |
| 416 | unsigned int *dest) |
| 417 | { |
| 418 | unsigned int addr; |
| 419 | |
| 420 | addr = PALMAS_BASE_TO_REG(PALMAS_LDO_BASE, reg); |
| 421 | |
| 422 | return regmap_read(palmas->regmap[REGULATOR_SLAVE], addr, dest); |
| 423 | } |
| 424 | |
| 425 | static int palmas_ldo_write(struct palmas *palmas, unsigned int reg, |
| 426 | unsigned int value) |
| 427 | { |
| 428 | unsigned int addr; |
| 429 | |
| 430 | addr = PALMAS_BASE_TO_REG(PALMAS_LDO_BASE, reg); |
| 431 | |
| 432 | return regmap_write(palmas->regmap[REGULATOR_SLAVE], addr, value); |
| 433 | } |
| 434 | |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 435 | static int palmas_set_mode_smps(struct regulator_dev *dev, unsigned int mode) |
| 436 | { |
Nishanth Menon | cf910b6 | 2014-06-30 10:57:36 -0500 | [diff] [blame] | 437 | int id = rdev_get_id(dev); |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 438 | struct palmas_pmic *pmic = rdev_get_drvdata(dev); |
Keerthy | cac9e91 | 2014-06-18 15:28:59 +0530 | [diff] [blame] | 439 | struct palmas_pmic_driver_data *ddata = pmic->palmas->pmic_ddata; |
Nishanth Menon | cf910b6 | 2014-06-30 10:57:36 -0500 | [diff] [blame] | 440 | struct palmas_regs_info *rinfo = &ddata->palmas_regs_info[id]; |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 441 | unsigned int reg; |
Laxman Dewangan | 51d3a0c | 2013-04-18 18:32:48 +0530 | [diff] [blame] | 442 | bool rail_enable = true; |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 443 | |
Nishanth Menon | cf910b6 | 2014-06-30 10:57:36 -0500 | [diff] [blame] | 444 | palmas_smps_read(pmic->palmas, rinfo->ctrl_addr, ®); |
Keerthy | cac9e91 | 2014-06-18 15:28:59 +0530 | [diff] [blame] | 445 | |
Axel Lin | 999f0c7 | 2012-06-07 17:08:21 +0800 | [diff] [blame] | 446 | reg &= ~PALMAS_SMPS12_CTRL_MODE_ACTIVE_MASK; |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 447 | |
Laxman Dewangan | 51d3a0c | 2013-04-18 18:32:48 +0530 | [diff] [blame] | 448 | if (reg == SMPS_CTRL_MODE_OFF) |
| 449 | rail_enable = false; |
| 450 | |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 451 | switch (mode) { |
| 452 | case REGULATOR_MODE_NORMAL: |
| 453 | reg |= SMPS_CTRL_MODE_ON; |
| 454 | break; |
| 455 | case REGULATOR_MODE_IDLE: |
| 456 | reg |= SMPS_CTRL_MODE_ECO; |
| 457 | break; |
| 458 | case REGULATOR_MODE_FAST: |
| 459 | reg |= SMPS_CTRL_MODE_PWM; |
| 460 | break; |
| 461 | default: |
| 462 | return -EINVAL; |
| 463 | } |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 464 | |
Laxman Dewangan | 51d3a0c | 2013-04-18 18:32:48 +0530 | [diff] [blame] | 465 | pmic->current_reg_mode[id] = reg & PALMAS_SMPS12_CTRL_MODE_ACTIVE_MASK; |
| 466 | if (rail_enable) |
Nishanth Menon | cf910b6 | 2014-06-30 10:57:36 -0500 | [diff] [blame] | 467 | palmas_smps_write(pmic->palmas, rinfo->ctrl_addr, reg); |
Nishanth Menon | 318dbb0 | 2014-06-20 12:26:23 -0500 | [diff] [blame] | 468 | |
| 469 | /* Switch the enable value to ensure this is used for enable */ |
| 470 | pmic->desc[id].enable_val = pmic->current_reg_mode[id]; |
| 471 | |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 472 | return 0; |
| 473 | } |
| 474 | |
| 475 | static unsigned int palmas_get_mode_smps(struct regulator_dev *dev) |
| 476 | { |
| 477 | struct palmas_pmic *pmic = rdev_get_drvdata(dev); |
| 478 | int id = rdev_get_id(dev); |
| 479 | unsigned int reg; |
| 480 | |
Laxman Dewangan | 51d3a0c | 2013-04-18 18:32:48 +0530 | [diff] [blame] | 481 | reg = pmic->current_reg_mode[id] & PALMAS_SMPS12_CTRL_MODE_ACTIVE_MASK; |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 482 | |
| 483 | switch (reg) { |
| 484 | case SMPS_CTRL_MODE_ON: |
| 485 | return REGULATOR_MODE_NORMAL; |
| 486 | case SMPS_CTRL_MODE_ECO: |
| 487 | return REGULATOR_MODE_IDLE; |
| 488 | case SMPS_CTRL_MODE_PWM: |
| 489 | return REGULATOR_MODE_FAST; |
| 490 | } |
| 491 | |
| 492 | return 0; |
| 493 | } |
| 494 | |
Laxman Dewangan | 28d1e8c | 2013-04-18 18:32:47 +0530 | [diff] [blame] | 495 | static int palmas_smps_set_ramp_delay(struct regulator_dev *rdev, |
| 496 | int ramp_delay) |
| 497 | { |
Nishanth Menon | cf910b6 | 2014-06-30 10:57:36 -0500 | [diff] [blame] | 498 | int id = rdev_get_id(rdev); |
Laxman Dewangan | 28d1e8c | 2013-04-18 18:32:47 +0530 | [diff] [blame] | 499 | struct palmas_pmic *pmic = rdev_get_drvdata(rdev); |
Keerthy | cac9e91 | 2014-06-18 15:28:59 +0530 | [diff] [blame] | 500 | struct palmas_pmic_driver_data *ddata = pmic->palmas->pmic_ddata; |
Nishanth Menon | cf910b6 | 2014-06-30 10:57:36 -0500 | [diff] [blame] | 501 | struct palmas_regs_info *rinfo = &ddata->palmas_regs_info[id]; |
Laxman Dewangan | 28d1e8c | 2013-04-18 18:32:47 +0530 | [diff] [blame] | 502 | unsigned int reg = 0; |
Laxman Dewangan | 28d1e8c | 2013-04-18 18:32:47 +0530 | [diff] [blame] | 503 | int ret; |
| 504 | |
Axel Lin | f22c2ba | 2013-04-19 14:18:48 +0800 | [diff] [blame] | 505 | /* SMPS3 and SMPS7 do not have tstep_addr setting */ |
| 506 | switch (id) { |
| 507 | case PALMAS_REG_SMPS3: |
| 508 | case PALMAS_REG_SMPS7: |
| 509 | return 0; |
| 510 | } |
| 511 | |
Laxman Dewangan | 28d1e8c | 2013-04-18 18:32:47 +0530 | [diff] [blame] | 512 | if (ramp_delay <= 0) |
| 513 | reg = 0; |
Axel Lin | 0ea34b5 | 2013-04-22 18:22:49 +0800 | [diff] [blame] | 514 | else if (ramp_delay <= 2500) |
Laxman Dewangan | 28d1e8c | 2013-04-18 18:32:47 +0530 | [diff] [blame] | 515 | reg = 3; |
Axel Lin | 0ea34b5 | 2013-04-22 18:22:49 +0800 | [diff] [blame] | 516 | else if (ramp_delay <= 5000) |
Laxman Dewangan | 28d1e8c | 2013-04-18 18:32:47 +0530 | [diff] [blame] | 517 | reg = 2; |
| 518 | else |
| 519 | reg = 1; |
| 520 | |
Nishanth Menon | cf910b6 | 2014-06-30 10:57:36 -0500 | [diff] [blame] | 521 | ret = palmas_smps_write(pmic->palmas, rinfo->tstep_addr, reg); |
Laxman Dewangan | 28d1e8c | 2013-04-18 18:32:47 +0530 | [diff] [blame] | 522 | if (ret < 0) { |
| 523 | dev_err(pmic->palmas->dev, "TSTEP write failed: %d\n", ret); |
| 524 | return ret; |
| 525 | } |
| 526 | |
| 527 | pmic->ramp_delay[id] = palmas_smps_ramp_delay[reg]; |
| 528 | return ret; |
| 529 | } |
| 530 | |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 531 | static struct regulator_ops palmas_ops_smps = { |
Keerthy | dbabd62 | 2014-05-22 14:48:29 +0530 | [diff] [blame] | 532 | .is_enabled = regulator_is_enabled_regmap, |
| 533 | .enable = regulator_enable_regmap, |
| 534 | .disable = regulator_disable_regmap, |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 535 | .set_mode = palmas_set_mode_smps, |
| 536 | .get_mode = palmas_get_mode_smps, |
Axel Lin | bdc4baa | 2012-11-29 10:01:44 +0800 | [diff] [blame] | 537 | .get_voltage_sel = regulator_get_voltage_sel_regmap, |
| 538 | .set_voltage_sel = regulator_set_voltage_sel_regmap, |
Keerthy | dbabd62 | 2014-05-22 14:48:29 +0530 | [diff] [blame] | 539 | .list_voltage = regulator_list_voltage_linear_range, |
| 540 | .map_voltage = regulator_map_voltage_linear_range, |
| 541 | .set_voltage_time_sel = regulator_set_voltage_time_sel, |
Laxman Dewangan | 28d1e8c | 2013-04-18 18:32:47 +0530 | [diff] [blame] | 542 | .set_ramp_delay = palmas_smps_set_ramp_delay, |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 543 | }; |
| 544 | |
Laxman Dewangan | 32b6d3f | 2013-08-21 16:18:16 +0530 | [diff] [blame] | 545 | static struct regulator_ops palmas_ops_ext_control_smps = { |
| 546 | .set_mode = palmas_set_mode_smps, |
| 547 | .get_mode = palmas_get_mode_smps, |
| 548 | .get_voltage_sel = regulator_get_voltage_sel_regmap, |
| 549 | .set_voltage_sel = regulator_set_voltage_sel_regmap, |
Keerthy | dbabd62 | 2014-05-22 14:48:29 +0530 | [diff] [blame] | 550 | .list_voltage = regulator_list_voltage_linear_range, |
| 551 | .map_voltage = regulator_map_voltage_linear_range, |
| 552 | .set_voltage_time_sel = regulator_set_voltage_time_sel, |
Laxman Dewangan | 32b6d3f | 2013-08-21 16:18:16 +0530 | [diff] [blame] | 553 | .set_ramp_delay = palmas_smps_set_ramp_delay, |
| 554 | }; |
| 555 | |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 556 | static struct regulator_ops palmas_ops_smps10 = { |
| 557 | .is_enabled = regulator_is_enabled_regmap, |
| 558 | .enable = regulator_enable_regmap, |
| 559 | .disable = regulator_disable_regmap, |
| 560 | .get_voltage_sel = regulator_get_voltage_sel_regmap, |
| 561 | .set_voltage_sel = regulator_set_voltage_sel_regmap, |
Axel Lin | 8029a00 | 2012-05-22 12:26:42 +0800 | [diff] [blame] | 562 | .list_voltage = regulator_list_voltage_linear, |
| 563 | .map_voltage = regulator_map_voltage_linear, |
Kishon Vijay Abraham I | 77409d9 | 2013-08-12 14:21:14 +0530 | [diff] [blame] | 564 | .set_bypass = regulator_set_bypass_regmap, |
| 565 | .get_bypass = regulator_get_bypass_regmap, |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 566 | }; |
| 567 | |
Keerthy | d6f8337 | 2014-06-18 15:29:00 +0530 | [diff] [blame] | 568 | static struct regulator_ops tps65917_ops_smps = { |
| 569 | .is_enabled = regulator_is_enabled_regmap, |
| 570 | .enable = regulator_enable_regmap, |
| 571 | .disable = regulator_disable_regmap, |
| 572 | .set_mode = palmas_set_mode_smps, |
| 573 | .get_mode = palmas_get_mode_smps, |
| 574 | .get_voltage_sel = regulator_get_voltage_sel_regmap, |
| 575 | .set_voltage_sel = regulator_set_voltage_sel_regmap, |
| 576 | .list_voltage = regulator_list_voltage_linear_range, |
| 577 | .map_voltage = regulator_map_voltage_linear_range, |
| 578 | .set_voltage_time_sel = regulator_set_voltage_time_sel, |
| 579 | }; |
| 580 | |
| 581 | static struct regulator_ops tps65917_ops_ext_control_smps = { |
| 582 | .set_mode = palmas_set_mode_smps, |
| 583 | .get_mode = palmas_get_mode_smps, |
| 584 | .get_voltage_sel = regulator_get_voltage_sel_regmap, |
| 585 | .set_voltage_sel = regulator_set_voltage_sel_regmap, |
| 586 | .list_voltage = regulator_list_voltage_linear_range, |
| 587 | .map_voltage = regulator_map_voltage_linear_range, |
| 588 | }; |
| 589 | |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 590 | static int palmas_is_enabled_ldo(struct regulator_dev *dev) |
| 591 | { |
Nishanth Menon | cf910b6 | 2014-06-30 10:57:36 -0500 | [diff] [blame] | 592 | int id = rdev_get_id(dev); |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 593 | struct palmas_pmic *pmic = rdev_get_drvdata(dev); |
Keerthy | cac9e91 | 2014-06-18 15:28:59 +0530 | [diff] [blame] | 594 | struct palmas_pmic_driver_data *ddata = pmic->palmas->pmic_ddata; |
Nishanth Menon | cf910b6 | 2014-06-30 10:57:36 -0500 | [diff] [blame] | 595 | struct palmas_regs_info *rinfo = &ddata->palmas_regs_info[id]; |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 596 | unsigned int reg; |
| 597 | |
Nishanth Menon | cf910b6 | 2014-06-30 10:57:36 -0500 | [diff] [blame] | 598 | palmas_ldo_read(pmic->palmas, rinfo->ctrl_addr, ®); |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 599 | |
| 600 | reg &= PALMAS_LDO1_CTRL_STATUS; |
| 601 | |
| 602 | return !!(reg); |
| 603 | } |
| 604 | |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 605 | static struct regulator_ops palmas_ops_ldo = { |
| 606 | .is_enabled = palmas_is_enabled_ldo, |
| 607 | .enable = regulator_enable_regmap, |
| 608 | .disable = regulator_disable_regmap, |
Axel Lin | 4a247a9 | 2012-07-18 12:34:08 +0800 | [diff] [blame] | 609 | .get_voltage_sel = regulator_get_voltage_sel_regmap, |
| 610 | .set_voltage_sel = regulator_set_voltage_sel_regmap, |
Axel Lin | 9119ff6 | 2012-11-27 10:27:34 +0800 | [diff] [blame] | 611 | .list_voltage = regulator_list_voltage_linear, |
| 612 | .map_voltage = regulator_map_voltage_linear, |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 613 | }; |
| 614 | |
Keerthy | b554e14 | 2015-12-14 12:06:55 +0530 | [diff] [blame] | 615 | static struct regulator_ops palmas_ops_ldo9 = { |
| 616 | .is_enabled = palmas_is_enabled_ldo, |
| 617 | .enable = regulator_enable_regmap, |
| 618 | .disable = regulator_disable_regmap, |
| 619 | .get_voltage_sel = regulator_get_voltage_sel_regmap, |
| 620 | .set_voltage_sel = regulator_set_voltage_sel_regmap, |
| 621 | .list_voltage = regulator_list_voltage_linear, |
| 622 | .map_voltage = regulator_map_voltage_linear, |
| 623 | .set_bypass = regulator_set_bypass_regmap, |
| 624 | .get_bypass = regulator_get_bypass_regmap, |
| 625 | }; |
| 626 | |
Laxman Dewangan | 32b6d3f | 2013-08-21 16:18:16 +0530 | [diff] [blame] | 627 | static struct regulator_ops palmas_ops_ext_control_ldo = { |
| 628 | .get_voltage_sel = regulator_get_voltage_sel_regmap, |
| 629 | .set_voltage_sel = regulator_set_voltage_sel_regmap, |
| 630 | .list_voltage = regulator_list_voltage_linear, |
| 631 | .map_voltage = regulator_map_voltage_linear, |
| 632 | }; |
| 633 | |
Laxman Dewangan | aa07f02 | 2013-04-17 15:13:12 +0530 | [diff] [blame] | 634 | static struct regulator_ops palmas_ops_extreg = { |
| 635 | .is_enabled = regulator_is_enabled_regmap, |
| 636 | .enable = regulator_enable_regmap, |
| 637 | .disable = regulator_disable_regmap, |
| 638 | }; |
| 639 | |
Laxman Dewangan | 32b6d3f | 2013-08-21 16:18:16 +0530 | [diff] [blame] | 640 | static struct regulator_ops palmas_ops_ext_control_extreg = { |
| 641 | }; |
| 642 | |
Keerthy | d6f8337 | 2014-06-18 15:29:00 +0530 | [diff] [blame] | 643 | static struct regulator_ops tps65917_ops_ldo = { |
| 644 | .is_enabled = palmas_is_enabled_ldo, |
| 645 | .enable = regulator_enable_regmap, |
| 646 | .disable = regulator_disable_regmap, |
| 647 | .get_voltage_sel = regulator_get_voltage_sel_regmap, |
| 648 | .set_voltage_sel = regulator_set_voltage_sel_regmap, |
| 649 | .list_voltage = regulator_list_voltage_linear, |
| 650 | .map_voltage = regulator_map_voltage_linear, |
| 651 | .set_voltage_time_sel = regulator_set_voltage_time_sel, |
| 652 | }; |
| 653 | |
Keerthy | b554e14 | 2015-12-14 12:06:55 +0530 | [diff] [blame] | 654 | static struct regulator_ops tps65917_ops_ldo_1_2 = { |
| 655 | .is_enabled = palmas_is_enabled_ldo, |
| 656 | .enable = regulator_enable_regmap, |
| 657 | .disable = regulator_disable_regmap, |
| 658 | .get_voltage_sel = regulator_get_voltage_sel_regmap, |
| 659 | .set_voltage_sel = regulator_set_voltage_sel_regmap, |
| 660 | .list_voltage = regulator_list_voltage_linear, |
| 661 | .map_voltage = regulator_map_voltage_linear, |
| 662 | .set_voltage_time_sel = regulator_set_voltage_time_sel, |
| 663 | .set_bypass = regulator_set_bypass_regmap, |
| 664 | .get_bypass = regulator_get_bypass_regmap, |
| 665 | }; |
| 666 | |
Laxman Dewangan | 32b6d3f | 2013-08-21 16:18:16 +0530 | [diff] [blame] | 667 | static int palmas_regulator_config_external(struct palmas *palmas, int id, |
| 668 | struct palmas_reg_init *reg_init) |
| 669 | { |
Nishanth Menon | cf910b6 | 2014-06-30 10:57:36 -0500 | [diff] [blame] | 670 | struct palmas_pmic_driver_data *ddata = palmas->pmic_ddata; |
| 671 | struct palmas_regs_info *rinfo = &ddata->palmas_regs_info[id]; |
Laxman Dewangan | 32b6d3f | 2013-08-21 16:18:16 +0530 | [diff] [blame] | 672 | int ret; |
| 673 | |
Nishanth Menon | cf910b6 | 2014-06-30 10:57:36 -0500 | [diff] [blame] | 674 | ret = palmas_ext_control_req_config(palmas, rinfo->sleep_id, |
| 675 | reg_init->roof_floor, true); |
Laxman Dewangan | 32b6d3f | 2013-08-21 16:18:16 +0530 | [diff] [blame] | 676 | if (ret < 0) |
| 677 | dev_err(palmas->dev, |
| 678 | "Ext control config for regulator %d failed %d\n", |
| 679 | id, ret); |
| 680 | return ret; |
| 681 | } |
| 682 | |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 683 | /* |
| 684 | * setup the hardware based sleep configuration of the SMPS/LDO regulators |
| 685 | * from the platform data. This is different to the software based control |
| 686 | * supported by the regulator framework as it is controlled by toggling |
| 687 | * pins on the PMIC such as PREQ, SYSEN, ... |
| 688 | */ |
| 689 | static int palmas_smps_init(struct palmas *palmas, int id, |
| 690 | struct palmas_reg_init *reg_init) |
| 691 | { |
| 692 | unsigned int reg; |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 693 | int ret; |
Keerthy | cac9e91 | 2014-06-18 15:28:59 +0530 | [diff] [blame] | 694 | struct palmas_pmic_driver_data *ddata = palmas->pmic_ddata; |
Nishanth Menon | cf910b6 | 2014-06-30 10:57:36 -0500 | [diff] [blame] | 695 | struct palmas_regs_info *rinfo = &ddata->palmas_regs_info[id]; |
| 696 | unsigned int addr = rinfo->ctrl_addr; |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 697 | |
| 698 | ret = palmas_smps_read(palmas, addr, ®); |
| 699 | if (ret) |
| 700 | return ret; |
| 701 | |
Axel Lin | fedd89b | 2012-06-06 20:01:38 +0800 | [diff] [blame] | 702 | switch (id) { |
Kishon Vijay Abraham I | 77409d9 | 2013-08-12 14:21:14 +0530 | [diff] [blame] | 703 | case PALMAS_REG_SMPS10_OUT1: |
| 704 | case PALMAS_REG_SMPS10_OUT2: |
Laxman Dewangan | 30590d0 | 2013-04-17 15:13:11 +0530 | [diff] [blame] | 705 | reg &= ~PALMAS_SMPS10_CTRL_MODE_SLEEP_MASK; |
| 706 | if (reg_init->mode_sleep) |
Axel Lin | fedd89b | 2012-06-06 20:01:38 +0800 | [diff] [blame] | 707 | reg |= reg_init->mode_sleep << |
| 708 | PALMAS_SMPS10_CTRL_MODE_SLEEP_SHIFT; |
Axel Lin | fedd89b | 2012-06-06 20:01:38 +0800 | [diff] [blame] | 709 | break; |
| 710 | default: |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 711 | if (reg_init->warm_reset) |
| 712 | reg |= PALMAS_SMPS12_CTRL_WR_S; |
Laxman Dewangan | 30590d0 | 2013-04-17 15:13:11 +0530 | [diff] [blame] | 713 | else |
| 714 | reg &= ~PALMAS_SMPS12_CTRL_WR_S; |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 715 | |
| 716 | if (reg_init->roof_floor) |
| 717 | reg |= PALMAS_SMPS12_CTRL_ROOF_FLOOR_EN; |
Laxman Dewangan | 30590d0 | 2013-04-17 15:13:11 +0530 | [diff] [blame] | 718 | else |
| 719 | reg &= ~PALMAS_SMPS12_CTRL_ROOF_FLOOR_EN; |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 720 | |
Laxman Dewangan | 30590d0 | 2013-04-17 15:13:11 +0530 | [diff] [blame] | 721 | reg &= ~PALMAS_SMPS12_CTRL_MODE_SLEEP_MASK; |
| 722 | if (reg_init->mode_sleep) |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 723 | reg |= reg_init->mode_sleep << |
| 724 | PALMAS_SMPS12_CTRL_MODE_SLEEP_SHIFT; |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 725 | } |
Axel Lin | fedd89b | 2012-06-06 20:01:38 +0800 | [diff] [blame] | 726 | |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 727 | ret = palmas_smps_write(palmas, addr, reg); |
| 728 | if (ret) |
| 729 | return ret; |
| 730 | |
Nishanth Menon | cf910b6 | 2014-06-30 10:57:36 -0500 | [diff] [blame] | 731 | if (rinfo->vsel_addr && reg_init->vsel) { |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 732 | |
| 733 | reg = reg_init->vsel; |
| 734 | |
Nishanth Menon | cf910b6 | 2014-06-30 10:57:36 -0500 | [diff] [blame] | 735 | ret = palmas_smps_write(palmas, rinfo->vsel_addr, reg); |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 736 | if (ret) |
| 737 | return ret; |
| 738 | } |
| 739 | |
Laxman Dewangan | 32b6d3f | 2013-08-21 16:18:16 +0530 | [diff] [blame] | 740 | if (reg_init->roof_floor && (id != PALMAS_REG_SMPS10_OUT1) && |
| 741 | (id != PALMAS_REG_SMPS10_OUT2)) { |
| 742 | /* Enable externally controlled regulator */ |
Laxman Dewangan | 32b6d3f | 2013-08-21 16:18:16 +0530 | [diff] [blame] | 743 | ret = palmas_smps_read(palmas, addr, ®); |
| 744 | if (ret < 0) |
| 745 | return ret; |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 746 | |
Laxman Dewangan | 32b6d3f | 2013-08-21 16:18:16 +0530 | [diff] [blame] | 747 | if (!(reg & PALMAS_SMPS12_CTRL_MODE_ACTIVE_MASK)) { |
| 748 | reg |= SMPS_CTRL_MODE_ON; |
| 749 | ret = palmas_smps_write(palmas, addr, reg); |
| 750 | if (ret < 0) |
| 751 | return ret; |
| 752 | } |
| 753 | return palmas_regulator_config_external(palmas, id, reg_init); |
| 754 | } |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 755 | return 0; |
| 756 | } |
| 757 | |
| 758 | static int palmas_ldo_init(struct palmas *palmas, int id, |
| 759 | struct palmas_reg_init *reg_init) |
| 760 | { |
| 761 | unsigned int reg; |
| 762 | unsigned int addr; |
| 763 | int ret; |
Keerthy | cac9e91 | 2014-06-18 15:28:59 +0530 | [diff] [blame] | 764 | struct palmas_pmic_driver_data *ddata = palmas->pmic_ddata; |
Nishanth Menon | cf910b6 | 2014-06-30 10:57:36 -0500 | [diff] [blame] | 765 | struct palmas_regs_info *rinfo = &ddata->palmas_regs_info[id]; |
Keerthy | cac9e91 | 2014-06-18 15:28:59 +0530 | [diff] [blame] | 766 | |
Nishanth Menon | cf910b6 | 2014-06-30 10:57:36 -0500 | [diff] [blame] | 767 | addr = rinfo->ctrl_addr; |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 768 | |
Axel Lin | 2735dae | 2012-07-18 12:31:59 +0800 | [diff] [blame] | 769 | ret = palmas_ldo_read(palmas, addr, ®); |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 770 | if (ret) |
| 771 | return ret; |
| 772 | |
| 773 | if (reg_init->warm_reset) |
| 774 | reg |= PALMAS_LDO1_CTRL_WR_S; |
Laxman Dewangan | 30590d0 | 2013-04-17 15:13:11 +0530 | [diff] [blame] | 775 | else |
| 776 | reg &= ~PALMAS_LDO1_CTRL_WR_S; |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 777 | |
| 778 | if (reg_init->mode_sleep) |
| 779 | reg |= PALMAS_LDO1_CTRL_MODE_SLEEP; |
Laxman Dewangan | 30590d0 | 2013-04-17 15:13:11 +0530 | [diff] [blame] | 780 | else |
| 781 | reg &= ~PALMAS_LDO1_CTRL_MODE_SLEEP; |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 782 | |
Axel Lin | 2735dae | 2012-07-18 12:31:59 +0800 | [diff] [blame] | 783 | ret = palmas_ldo_write(palmas, addr, reg); |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 784 | if (ret) |
| 785 | return ret; |
| 786 | |
Laxman Dewangan | 32b6d3f | 2013-08-21 16:18:16 +0530 | [diff] [blame] | 787 | if (reg_init->roof_floor) { |
| 788 | /* Enable externally controlled regulator */ |
Laxman Dewangan | 32b6d3f | 2013-08-21 16:18:16 +0530 | [diff] [blame] | 789 | ret = palmas_update_bits(palmas, PALMAS_LDO_BASE, |
| 790 | addr, PALMAS_LDO1_CTRL_MODE_ACTIVE, |
| 791 | PALMAS_LDO1_CTRL_MODE_ACTIVE); |
| 792 | if (ret < 0) { |
| 793 | dev_err(palmas->dev, |
| 794 | "LDO Register 0x%02x update failed %d\n", |
| 795 | addr, ret); |
| 796 | return ret; |
| 797 | } |
| 798 | return palmas_regulator_config_external(palmas, id, reg_init); |
| 799 | } |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 800 | return 0; |
| 801 | } |
| 802 | |
Laxman Dewangan | aa07f02 | 2013-04-17 15:13:12 +0530 | [diff] [blame] | 803 | static int palmas_extreg_init(struct palmas *palmas, int id, |
| 804 | struct palmas_reg_init *reg_init) |
| 805 | { |
| 806 | unsigned int addr; |
| 807 | int ret; |
| 808 | unsigned int val = 0; |
Keerthy | cac9e91 | 2014-06-18 15:28:59 +0530 | [diff] [blame] | 809 | struct palmas_pmic_driver_data *ddata = palmas->pmic_ddata; |
Nishanth Menon | cf910b6 | 2014-06-30 10:57:36 -0500 | [diff] [blame] | 810 | struct palmas_regs_info *rinfo = &ddata->palmas_regs_info[id]; |
Keerthy | cac9e91 | 2014-06-18 15:28:59 +0530 | [diff] [blame] | 811 | |
Nishanth Menon | cf910b6 | 2014-06-30 10:57:36 -0500 | [diff] [blame] | 812 | addr = rinfo->ctrl_addr; |
Laxman Dewangan | aa07f02 | 2013-04-17 15:13:12 +0530 | [diff] [blame] | 813 | |
| 814 | if (reg_init->mode_sleep) |
| 815 | val = PALMAS_REGEN1_CTRL_MODE_SLEEP; |
| 816 | |
| 817 | ret = palmas_update_bits(palmas, PALMAS_RESOURCE_BASE, |
| 818 | addr, PALMAS_REGEN1_CTRL_MODE_SLEEP, val); |
| 819 | if (ret < 0) { |
| 820 | dev_err(palmas->dev, "Resource reg 0x%02x update failed %d\n", |
| 821 | addr, ret); |
| 822 | return ret; |
| 823 | } |
Laxman Dewangan | 32b6d3f | 2013-08-21 16:18:16 +0530 | [diff] [blame] | 824 | |
| 825 | if (reg_init->roof_floor) { |
| 826 | /* Enable externally controlled regulator */ |
Laxman Dewangan | 32b6d3f | 2013-08-21 16:18:16 +0530 | [diff] [blame] | 827 | ret = palmas_update_bits(palmas, PALMAS_RESOURCE_BASE, |
| 828 | addr, PALMAS_REGEN1_CTRL_MODE_ACTIVE, |
| 829 | PALMAS_REGEN1_CTRL_MODE_ACTIVE); |
| 830 | if (ret < 0) { |
| 831 | dev_err(palmas->dev, |
| 832 | "Resource Register 0x%02x update failed %d\n", |
| 833 | addr, ret); |
| 834 | return ret; |
| 835 | } |
| 836 | return palmas_regulator_config_external(palmas, id, reg_init); |
| 837 | } |
Laxman Dewangan | aa07f02 | 2013-04-17 15:13:12 +0530 | [diff] [blame] | 838 | return 0; |
| 839 | } |
| 840 | |
Laxman Dewangan | 17c11a7 | 2013-04-17 15:13:13 +0530 | [diff] [blame] | 841 | static void palmas_enable_ldo8_track(struct palmas *palmas) |
| 842 | { |
| 843 | unsigned int reg; |
| 844 | unsigned int addr; |
| 845 | int ret; |
Keerthy | cac9e91 | 2014-06-18 15:28:59 +0530 | [diff] [blame] | 846 | struct palmas_pmic_driver_data *ddata = palmas->pmic_ddata; |
Nishanth Menon | cf910b6 | 2014-06-30 10:57:36 -0500 | [diff] [blame] | 847 | struct palmas_regs_info *rinfo; |
Keerthy | cac9e91 | 2014-06-18 15:28:59 +0530 | [diff] [blame] | 848 | |
Nishanth Menon | cf910b6 | 2014-06-30 10:57:36 -0500 | [diff] [blame] | 849 | rinfo = &ddata->palmas_regs_info[PALMAS_REG_LDO8]; |
| 850 | addr = rinfo->ctrl_addr; |
Laxman Dewangan | 17c11a7 | 2013-04-17 15:13:13 +0530 | [diff] [blame] | 851 | |
| 852 | ret = palmas_ldo_read(palmas, addr, ®); |
| 853 | if (ret) { |
| 854 | dev_err(palmas->dev, "Error in reading ldo8 control reg\n"); |
| 855 | return; |
| 856 | } |
| 857 | |
| 858 | reg |= PALMAS_LDO8_CTRL_LDO_TRACKING_EN; |
| 859 | ret = palmas_ldo_write(palmas, addr, reg); |
| 860 | if (ret < 0) { |
| 861 | dev_err(palmas->dev, "Error in enabling tracking mode\n"); |
| 862 | return; |
| 863 | } |
| 864 | /* |
| 865 | * When SMPS45 is set to off and LDO8 tracking is enabled, the LDO8 |
| 866 | * output is defined by the LDO8_VOLTAGE.VSEL register divided by two, |
| 867 | * and can be set from 0.45 to 1.65 V. |
| 868 | */ |
Nishanth Menon | cf910b6 | 2014-06-30 10:57:36 -0500 | [diff] [blame] | 869 | addr = rinfo->vsel_addr; |
Laxman Dewangan | 17c11a7 | 2013-04-17 15:13:13 +0530 | [diff] [blame] | 870 | ret = palmas_ldo_read(palmas, addr, ®); |
| 871 | if (ret) { |
| 872 | dev_err(palmas->dev, "Error in reading ldo8 voltage reg\n"); |
| 873 | return; |
| 874 | } |
| 875 | |
| 876 | reg = (reg << 1) & PALMAS_LDO8_VOLTAGE_VSEL_MASK; |
| 877 | ret = palmas_ldo_write(palmas, addr, reg); |
| 878 | if (ret < 0) |
| 879 | dev_err(palmas->dev, "Error in setting ldo8 voltage reg\n"); |
| 880 | |
| 881 | return; |
| 882 | } |
| 883 | |
Keerthy | cac9e91 | 2014-06-18 15:28:59 +0530 | [diff] [blame] | 884 | static int palmas_ldo_registration(struct palmas_pmic *pmic, |
| 885 | struct palmas_pmic_driver_data *ddata, |
| 886 | struct palmas_pmic_platform_data *pdata, |
| 887 | const char *pdev_name, |
| 888 | struct regulator_config config) |
Graeme Gregory | a361cd9 | 2012-08-28 13:47:40 +0200 | [diff] [blame] | 889 | { |
Keerthy | cac9e91 | 2014-06-18 15:28:59 +0530 | [diff] [blame] | 890 | int id, ret; |
| 891 | struct regulator_dev *rdev; |
| 892 | struct palmas_reg_init *reg_init; |
Nishanth Menon | cf910b6 | 2014-06-30 10:57:36 -0500 | [diff] [blame] | 893 | struct palmas_regs_info *rinfo; |
Nishanth Menon | 429222d | 2014-06-30 10:57:38 -0500 | [diff] [blame] | 894 | struct regulator_desc *desc; |
Graeme Gregory | a361cd9 | 2012-08-28 13:47:40 +0200 | [diff] [blame] | 895 | |
Keerthy | cac9e91 | 2014-06-18 15:28:59 +0530 | [diff] [blame] | 896 | for (id = ddata->ldo_begin; id < ddata->max_reg; id++) { |
| 897 | if (pdata && pdata->reg_init[id]) |
| 898 | reg_init = pdata->reg_init[id]; |
| 899 | else |
| 900 | reg_init = NULL; |
Graeme Gregory | a361cd9 | 2012-08-28 13:47:40 +0200 | [diff] [blame] | 901 | |
Nishanth Menon | cf910b6 | 2014-06-30 10:57:36 -0500 | [diff] [blame] | 902 | rinfo = &ddata->palmas_regs_info[id]; |
Keerthy | cac9e91 | 2014-06-18 15:28:59 +0530 | [diff] [blame] | 903 | /* Miss out regulators which are not available due |
| 904 | * to alternate functions. |
| 905 | */ |
Graeme Gregory | a361cd9 | 2012-08-28 13:47:40 +0200 | [diff] [blame] | 906 | |
Keerthy | cac9e91 | 2014-06-18 15:28:59 +0530 | [diff] [blame] | 907 | /* Register the regulators */ |
Nishanth Menon | 429222d | 2014-06-30 10:57:38 -0500 | [diff] [blame] | 908 | desc = &pmic->desc[id]; |
| 909 | desc->name = rinfo->name; |
| 910 | desc->id = id; |
| 911 | desc->type = REGULATOR_VOLTAGE; |
| 912 | desc->owner = THIS_MODULE; |
Graeme Gregory | a361cd9 | 2012-08-28 13:47:40 +0200 | [diff] [blame] | 913 | |
Keerthy | cac9e91 | 2014-06-18 15:28:59 +0530 | [diff] [blame] | 914 | if (id < PALMAS_REG_REGEN1) { |
Nishanth Menon | 429222d | 2014-06-30 10:57:38 -0500 | [diff] [blame] | 915 | desc->n_voltages = PALMAS_LDO_NUM_VOLTAGES; |
Keerthy | cac9e91 | 2014-06-18 15:28:59 +0530 | [diff] [blame] | 916 | if (reg_init && reg_init->roof_floor) |
Nishanth Menon | 429222d | 2014-06-30 10:57:38 -0500 | [diff] [blame] | 917 | desc->ops = &palmas_ops_ext_control_ldo; |
Keerthy | cac9e91 | 2014-06-18 15:28:59 +0530 | [diff] [blame] | 918 | else |
Nishanth Menon | 429222d | 2014-06-30 10:57:38 -0500 | [diff] [blame] | 919 | desc->ops = &palmas_ops_ldo; |
| 920 | desc->min_uV = 900000; |
| 921 | desc->uV_step = 50000; |
| 922 | desc->linear_min_sel = 1; |
| 923 | desc->enable_time = 500; |
| 924 | desc->vsel_reg = PALMAS_BASE_TO_REG(PALMAS_LDO_BASE, |
| 925 | rinfo->vsel_addr); |
| 926 | desc->vsel_mask = PALMAS_LDO1_VOLTAGE_VSEL_MASK; |
| 927 | desc->enable_reg = PALMAS_BASE_TO_REG(PALMAS_LDO_BASE, |
| 928 | rinfo->ctrl_addr); |
| 929 | desc->enable_mask = PALMAS_LDO1_CTRL_MODE_ACTIVE; |
Graeme Gregory | a361cd9 | 2012-08-28 13:47:40 +0200 | [diff] [blame] | 930 | |
Keerthy | cac9e91 | 2014-06-18 15:28:59 +0530 | [diff] [blame] | 931 | /* Check if LDO8 is in tracking mode or not */ |
| 932 | if (pdata && (id == PALMAS_REG_LDO8) && |
| 933 | pdata->enable_ldo8_tracking) { |
| 934 | palmas_enable_ldo8_track(pmic->palmas); |
Nishanth Menon | 429222d | 2014-06-30 10:57:38 -0500 | [diff] [blame] | 935 | desc->min_uV = 450000; |
| 936 | desc->uV_step = 25000; |
Laxman Dewangan | 32b6d3f | 2013-08-21 16:18:16 +0530 | [diff] [blame] | 937 | } |
Keerthy | cac9e91 | 2014-06-18 15:28:59 +0530 | [diff] [blame] | 938 | |
| 939 | /* LOD6 in vibrator mode will have enable time 2000us */ |
| 940 | if (pdata && pdata->ldo6_vibrator && |
| 941 | (id == PALMAS_REG_LDO6)) |
Nishanth Menon | 429222d | 2014-06-30 10:57:38 -0500 | [diff] [blame] | 942 | desc->enable_time = 2000; |
Keerthy | b554e14 | 2015-12-14 12:06:55 +0530 | [diff] [blame] | 943 | |
| 944 | if (id == PALMAS_REG_LDO9) { |
| 945 | desc->ops = &palmas_ops_ldo9; |
| 946 | desc->bypass_reg = desc->enable_reg; |
| 947 | desc->bypass_mask = |
| 948 | PALMAS_LDO9_CTRL_LDO_BYPASS_EN; |
| 949 | } |
Keerthy | cac9e91 | 2014-06-18 15:28:59 +0530 | [diff] [blame] | 950 | } else { |
Keerthy | e999c72 | 2015-03-17 15:56:05 +0530 | [diff] [blame] | 951 | if (!ddata->has_regen3 && id == PALMAS_REG_REGEN3) |
| 952 | continue; |
| 953 | |
Nishanth Menon | 429222d | 2014-06-30 10:57:38 -0500 | [diff] [blame] | 954 | desc->n_voltages = 1; |
Keerthy | cac9e91 | 2014-06-18 15:28:59 +0530 | [diff] [blame] | 955 | if (reg_init && reg_init->roof_floor) |
Nishanth Menon | 429222d | 2014-06-30 10:57:38 -0500 | [diff] [blame] | 956 | desc->ops = &palmas_ops_ext_control_extreg; |
Keerthy | cac9e91 | 2014-06-18 15:28:59 +0530 | [diff] [blame] | 957 | else |
Nishanth Menon | 429222d | 2014-06-30 10:57:38 -0500 | [diff] [blame] | 958 | desc->ops = &palmas_ops_extreg; |
| 959 | desc->enable_reg = |
Keerthy | cac9e91 | 2014-06-18 15:28:59 +0530 | [diff] [blame] | 960 | PALMAS_BASE_TO_REG(PALMAS_RESOURCE_BASE, |
Nishanth Menon | cf910b6 | 2014-06-30 10:57:36 -0500 | [diff] [blame] | 961 | rinfo->ctrl_addr); |
Nishanth Menon | 429222d | 2014-06-30 10:57:38 -0500 | [diff] [blame] | 962 | desc->enable_mask = PALMAS_REGEN1_CTRL_MODE_ACTIVE; |
Laxman Dewangan | 32b6d3f | 2013-08-21 16:18:16 +0530 | [diff] [blame] | 963 | } |
Graeme Gregory | a361cd9 | 2012-08-28 13:47:40 +0200 | [diff] [blame] | 964 | |
Keerthy | cac9e91 | 2014-06-18 15:28:59 +0530 | [diff] [blame] | 965 | if (pdata) |
| 966 | config.init_data = pdata->reg_data[id]; |
| 967 | else |
| 968 | config.init_data = NULL; |
Graeme Gregory | a361cd9 | 2012-08-28 13:47:40 +0200 | [diff] [blame] | 969 | |
Nishanth Menon | 429222d | 2014-06-30 10:57:38 -0500 | [diff] [blame] | 970 | desc->supply_name = rinfo->sname; |
Keerthy | cac9e91 | 2014-06-18 15:28:59 +0530 | [diff] [blame] | 971 | config.of_node = ddata->palmas_matches[id].of_node; |
Graeme Gregory | a361cd9 | 2012-08-28 13:47:40 +0200 | [diff] [blame] | 972 | |
Nishanth Menon | 429222d | 2014-06-30 10:57:38 -0500 | [diff] [blame] | 973 | rdev = devm_regulator_register(pmic->dev, desc, &config); |
Keerthy | cac9e91 | 2014-06-18 15:28:59 +0530 | [diff] [blame] | 974 | if (IS_ERR(rdev)) { |
| 975 | dev_err(pmic->dev, |
| 976 | "failed to register %s regulator\n", |
| 977 | pdev_name); |
| 978 | return PTR_ERR(rdev); |
| 979 | } |
| 980 | |
| 981 | /* Save regulator for cleanup */ |
| 982 | pmic->rdev[id] = rdev; |
| 983 | |
| 984 | /* Initialise sleep/init values from platform data */ |
| 985 | if (pdata) { |
| 986 | reg_init = pdata->reg_init[id]; |
| 987 | if (reg_init) { |
| 988 | if (id <= ddata->ldo_end) |
| 989 | ret = palmas_ldo_init(pmic->palmas, id, |
| 990 | reg_init); |
| 991 | else |
| 992 | ret = palmas_extreg_init(pmic->palmas, |
| 993 | id, reg_init); |
| 994 | if (ret) |
| 995 | return ret; |
| 996 | } |
| 997 | } |
Graeme Gregory | a361cd9 | 2012-08-28 13:47:40 +0200 | [diff] [blame] | 998 | } |
| 999 | |
Keerthy | cac9e91 | 2014-06-18 15:28:59 +0530 | [diff] [blame] | 1000 | return 0; |
Graeme Gregory | a361cd9 | 2012-08-28 13:47:40 +0200 | [diff] [blame] | 1001 | } |
| 1002 | |
Keerthy | d6f8337 | 2014-06-18 15:29:00 +0530 | [diff] [blame] | 1003 | static int tps65917_ldo_registration(struct palmas_pmic *pmic, |
| 1004 | struct palmas_pmic_driver_data *ddata, |
| 1005 | struct palmas_pmic_platform_data *pdata, |
| 1006 | const char *pdev_name, |
| 1007 | struct regulator_config config) |
| 1008 | { |
| 1009 | int id, ret; |
| 1010 | struct regulator_dev *rdev; |
| 1011 | struct palmas_reg_init *reg_init; |
Nishanth Menon | cf910b6 | 2014-06-30 10:57:36 -0500 | [diff] [blame] | 1012 | struct palmas_regs_info *rinfo; |
Nishanth Menon | 429222d | 2014-06-30 10:57:38 -0500 | [diff] [blame] | 1013 | struct regulator_desc *desc; |
Keerthy | d6f8337 | 2014-06-18 15:29:00 +0530 | [diff] [blame] | 1014 | |
| 1015 | for (id = ddata->ldo_begin; id < ddata->max_reg; id++) { |
| 1016 | if (pdata && pdata->reg_init[id]) |
| 1017 | reg_init = pdata->reg_init[id]; |
| 1018 | else |
| 1019 | reg_init = NULL; |
| 1020 | |
| 1021 | /* Miss out regulators which are not available due |
| 1022 | * to alternate functions. |
| 1023 | */ |
Nishanth Menon | cf910b6 | 2014-06-30 10:57:36 -0500 | [diff] [blame] | 1024 | rinfo = &ddata->palmas_regs_info[id]; |
Keerthy | d6f8337 | 2014-06-18 15:29:00 +0530 | [diff] [blame] | 1025 | |
| 1026 | /* Register the regulators */ |
Nishanth Menon | 429222d | 2014-06-30 10:57:38 -0500 | [diff] [blame] | 1027 | desc = &pmic->desc[id]; |
| 1028 | desc->name = rinfo->name; |
| 1029 | desc->id = id; |
| 1030 | desc->type = REGULATOR_VOLTAGE; |
| 1031 | desc->owner = THIS_MODULE; |
Keerthy | d6f8337 | 2014-06-18 15:29:00 +0530 | [diff] [blame] | 1032 | |
| 1033 | if (id < TPS65917_REG_REGEN1) { |
Nishanth Menon | 429222d | 2014-06-30 10:57:38 -0500 | [diff] [blame] | 1034 | desc->n_voltages = PALMAS_LDO_NUM_VOLTAGES; |
Keerthy | d6f8337 | 2014-06-18 15:29:00 +0530 | [diff] [blame] | 1035 | if (reg_init && reg_init->roof_floor) |
Nishanth Menon | 429222d | 2014-06-30 10:57:38 -0500 | [diff] [blame] | 1036 | desc->ops = &palmas_ops_ext_control_ldo; |
Keerthy | d6f8337 | 2014-06-18 15:29:00 +0530 | [diff] [blame] | 1037 | else |
Nishanth Menon | 429222d | 2014-06-30 10:57:38 -0500 | [diff] [blame] | 1038 | desc->ops = &tps65917_ops_ldo; |
| 1039 | desc->min_uV = 900000; |
| 1040 | desc->uV_step = 50000; |
| 1041 | desc->linear_min_sel = 1; |
| 1042 | desc->enable_time = 500; |
| 1043 | desc->vsel_reg = PALMAS_BASE_TO_REG(PALMAS_LDO_BASE, |
| 1044 | rinfo->vsel_addr); |
| 1045 | desc->vsel_mask = PALMAS_LDO1_VOLTAGE_VSEL_MASK; |
| 1046 | desc->enable_reg = PALMAS_BASE_TO_REG(PALMAS_LDO_BASE, |
| 1047 | rinfo->ctrl_addr); |
| 1048 | desc->enable_mask = PALMAS_LDO1_CTRL_MODE_ACTIVE; |
Keerthy | d6f8337 | 2014-06-18 15:29:00 +0530 | [diff] [blame] | 1049 | /* |
| 1050 | * To be confirmed. Discussion on going with PMIC Team. |
| 1051 | * It is of the order of ~60mV/uS. |
| 1052 | */ |
Nishanth Menon | 429222d | 2014-06-30 10:57:38 -0500 | [diff] [blame] | 1053 | desc->ramp_delay = 2500; |
Keerthy | b554e14 | 2015-12-14 12:06:55 +0530 | [diff] [blame] | 1054 | if (id == TPS65917_REG_LDO1 || |
| 1055 | id == TPS65917_REG_LDO2) { |
| 1056 | desc->ops = &tps65917_ops_ldo_1_2; |
| 1057 | desc->bypass_reg = desc->enable_reg; |
| 1058 | desc->bypass_mask = |
| 1059 | TPS65917_LDO1_CTRL_BYPASS_EN; |
| 1060 | } |
Keerthy | d6f8337 | 2014-06-18 15:29:00 +0530 | [diff] [blame] | 1061 | } else { |
Nishanth Menon | 429222d | 2014-06-30 10:57:38 -0500 | [diff] [blame] | 1062 | desc->n_voltages = 1; |
Keerthy | d6f8337 | 2014-06-18 15:29:00 +0530 | [diff] [blame] | 1063 | if (reg_init && reg_init->roof_floor) |
Nishanth Menon | 429222d | 2014-06-30 10:57:38 -0500 | [diff] [blame] | 1064 | desc->ops = &palmas_ops_ext_control_extreg; |
Keerthy | d6f8337 | 2014-06-18 15:29:00 +0530 | [diff] [blame] | 1065 | else |
Nishanth Menon | 429222d | 2014-06-30 10:57:38 -0500 | [diff] [blame] | 1066 | desc->ops = &palmas_ops_extreg; |
| 1067 | desc->enable_reg = |
Keerthy | d6f8337 | 2014-06-18 15:29:00 +0530 | [diff] [blame] | 1068 | PALMAS_BASE_TO_REG(PALMAS_RESOURCE_BASE, |
Nishanth Menon | cf910b6 | 2014-06-30 10:57:36 -0500 | [diff] [blame] | 1069 | rinfo->ctrl_addr); |
Nishanth Menon | 429222d | 2014-06-30 10:57:38 -0500 | [diff] [blame] | 1070 | desc->enable_mask = PALMAS_REGEN1_CTRL_MODE_ACTIVE; |
Keerthy | d6f8337 | 2014-06-18 15:29:00 +0530 | [diff] [blame] | 1071 | } |
| 1072 | |
| 1073 | if (pdata) |
| 1074 | config.init_data = pdata->reg_data[id]; |
| 1075 | else |
| 1076 | config.init_data = NULL; |
| 1077 | |
Nishanth Menon | 429222d | 2014-06-30 10:57:38 -0500 | [diff] [blame] | 1078 | desc->supply_name = rinfo->sname; |
Keerthy | d6f8337 | 2014-06-18 15:29:00 +0530 | [diff] [blame] | 1079 | config.of_node = ddata->palmas_matches[id].of_node; |
| 1080 | |
Nishanth Menon | 429222d | 2014-06-30 10:57:38 -0500 | [diff] [blame] | 1081 | rdev = devm_regulator_register(pmic->dev, desc, &config); |
Keerthy | d6f8337 | 2014-06-18 15:29:00 +0530 | [diff] [blame] | 1082 | if (IS_ERR(rdev)) { |
| 1083 | dev_err(pmic->dev, |
| 1084 | "failed to register %s regulator\n", |
| 1085 | pdev_name); |
| 1086 | return PTR_ERR(rdev); |
| 1087 | } |
| 1088 | |
| 1089 | /* Save regulator for cleanup */ |
| 1090 | pmic->rdev[id] = rdev; |
| 1091 | |
| 1092 | /* Initialise sleep/init values from platform data */ |
| 1093 | if (pdata) { |
| 1094 | reg_init = pdata->reg_init[id]; |
| 1095 | if (reg_init) { |
| 1096 | if (id < TPS65917_REG_REGEN1) |
| 1097 | ret = palmas_ldo_init(pmic->palmas, |
| 1098 | id, reg_init); |
| 1099 | else |
| 1100 | ret = palmas_extreg_init(pmic->palmas, |
| 1101 | id, reg_init); |
| 1102 | if (ret) |
| 1103 | return ret; |
| 1104 | } |
| 1105 | } |
| 1106 | } |
| 1107 | |
| 1108 | return 0; |
| 1109 | } |
| 1110 | |
Keerthy | cac9e91 | 2014-06-18 15:28:59 +0530 | [diff] [blame] | 1111 | static int palmas_smps_registration(struct palmas_pmic *pmic, |
| 1112 | struct palmas_pmic_driver_data *ddata, |
| 1113 | struct palmas_pmic_platform_data *pdata, |
| 1114 | const char *pdev_name, |
| 1115 | struct regulator_config config) |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 1116 | { |
Keerthy | cac9e91 | 2014-06-18 15:28:59 +0530 | [diff] [blame] | 1117 | int id, ret; |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 1118 | unsigned int addr, reg; |
Keerthy | cac9e91 | 2014-06-18 15:28:59 +0530 | [diff] [blame] | 1119 | struct regulator_dev *rdev; |
| 1120 | struct palmas_reg_init *reg_init; |
Nishanth Menon | cf910b6 | 2014-06-30 10:57:36 -0500 | [diff] [blame] | 1121 | struct palmas_regs_info *rinfo; |
Nishanth Menon | 429222d | 2014-06-30 10:57:38 -0500 | [diff] [blame] | 1122 | struct regulator_desc *desc; |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 1123 | |
Keerthy | cac9e91 | 2014-06-18 15:28:59 +0530 | [diff] [blame] | 1124 | for (id = ddata->smps_start; id <= ddata->smps_end; id++) { |
Laxman Dewangan | 28d1e8c | 2013-04-18 18:32:47 +0530 | [diff] [blame] | 1125 | bool ramp_delay_support = false; |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 1126 | |
| 1127 | /* |
| 1128 | * Miss out regulators which are not available due |
| 1129 | * to slaving configurations. |
| 1130 | */ |
| 1131 | switch (id) { |
| 1132 | case PALMAS_REG_SMPS12: |
| 1133 | case PALMAS_REG_SMPS3: |
| 1134 | if (pmic->smps123) |
| 1135 | continue; |
Laxman Dewangan | 28d1e8c | 2013-04-18 18:32:47 +0530 | [diff] [blame] | 1136 | if (id == PALMAS_REG_SMPS12) |
| 1137 | ramp_delay_support = true; |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 1138 | break; |
| 1139 | case PALMAS_REG_SMPS123: |
| 1140 | if (!pmic->smps123) |
| 1141 | continue; |
Laxman Dewangan | 28d1e8c | 2013-04-18 18:32:47 +0530 | [diff] [blame] | 1142 | ramp_delay_support = true; |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 1143 | break; |
| 1144 | case PALMAS_REG_SMPS45: |
| 1145 | case PALMAS_REG_SMPS7: |
| 1146 | if (pmic->smps457) |
| 1147 | continue; |
Laxman Dewangan | 28d1e8c | 2013-04-18 18:32:47 +0530 | [diff] [blame] | 1148 | if (id == PALMAS_REG_SMPS45) |
| 1149 | ramp_delay_support = true; |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 1150 | break; |
| 1151 | case PALMAS_REG_SMPS457: |
| 1152 | if (!pmic->smps457) |
| 1153 | continue; |
Laxman Dewangan | 28d1e8c | 2013-04-18 18:32:47 +0530 | [diff] [blame] | 1154 | ramp_delay_support = true; |
| 1155 | break; |
Kishon Vijay Abraham I | 77409d9 | 2013-08-12 14:21:14 +0530 | [diff] [blame] | 1156 | case PALMAS_REG_SMPS10_OUT1: |
| 1157 | case PALMAS_REG_SMPS10_OUT2: |
Keerthy | cac9e91 | 2014-06-18 15:28:59 +0530 | [diff] [blame] | 1158 | if (!PALMAS_PMIC_HAS(pmic->palmas, SMPS10_BOOST)) |
J Keerthy | 1ffb0be | 2013-06-19 11:27:48 +0530 | [diff] [blame] | 1159 | continue; |
Laxman Dewangan | 28d1e8c | 2013-04-18 18:32:47 +0530 | [diff] [blame] | 1160 | } |
Nishanth Menon | cf910b6 | 2014-06-30 10:57:36 -0500 | [diff] [blame] | 1161 | rinfo = &ddata->palmas_regs_info[id]; |
Nishanth Menon | 429222d | 2014-06-30 10:57:38 -0500 | [diff] [blame] | 1162 | desc = &pmic->desc[id]; |
Laxman Dewangan | 28d1e8c | 2013-04-18 18:32:47 +0530 | [diff] [blame] | 1163 | |
Sachin Kamat | 3f4d636 | 2013-05-08 16:09:06 +0530 | [diff] [blame] | 1164 | if ((id == PALMAS_REG_SMPS6) || (id == PALMAS_REG_SMPS8)) |
Laxman Dewangan | 28d1e8c | 2013-04-18 18:32:47 +0530 | [diff] [blame] | 1165 | ramp_delay_support = true; |
| 1166 | |
| 1167 | if (ramp_delay_support) { |
Nishanth Menon | cf910b6 | 2014-06-30 10:57:36 -0500 | [diff] [blame] | 1168 | addr = rinfo->tstep_addr; |
Laxman Dewangan | 28d1e8c | 2013-04-18 18:32:47 +0530 | [diff] [blame] | 1169 | ret = palmas_smps_read(pmic->palmas, addr, ®); |
| 1170 | if (ret < 0) { |
Keerthy | cac9e91 | 2014-06-18 15:28:59 +0530 | [diff] [blame] | 1171 | dev_err(pmic->dev, |
Laxman Dewangan | 28d1e8c | 2013-04-18 18:32:47 +0530 | [diff] [blame] | 1172 | "reading TSTEP reg failed: %d\n", ret); |
Sachin Kamat | 51c86b3 | 2013-09-04 12:01:01 +0530 | [diff] [blame] | 1173 | return ret; |
Laxman Dewangan | 28d1e8c | 2013-04-18 18:32:47 +0530 | [diff] [blame] | 1174 | } |
Nishanth Menon | 429222d | 2014-06-30 10:57:38 -0500 | [diff] [blame] | 1175 | desc->ramp_delay = palmas_smps_ramp_delay[reg & 0x3]; |
| 1176 | pmic->ramp_delay[id] = desc->ramp_delay; |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 1177 | } |
| 1178 | |
Axel Lin | bdc4baa | 2012-11-29 10:01:44 +0800 | [diff] [blame] | 1179 | /* Initialise sleep/init values from platform data */ |
| 1180 | if (pdata && pdata->reg_init[id]) { |
| 1181 | reg_init = pdata->reg_init[id]; |
Keerthy | cac9e91 | 2014-06-18 15:28:59 +0530 | [diff] [blame] | 1182 | ret = palmas_smps_init(pmic->palmas, id, reg_init); |
Axel Lin | bdc4baa | 2012-11-29 10:01:44 +0800 | [diff] [blame] | 1183 | if (ret) |
Sachin Kamat | 51c86b3 | 2013-09-04 12:01:01 +0530 | [diff] [blame] | 1184 | return ret; |
Laxman Dewangan | 32b6d3f | 2013-08-21 16:18:16 +0530 | [diff] [blame] | 1185 | } else { |
| 1186 | reg_init = NULL; |
Axel Lin | bdc4baa | 2012-11-29 10:01:44 +0800 | [diff] [blame] | 1187 | } |
| 1188 | |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 1189 | /* Register the regulators */ |
Nishanth Menon | 429222d | 2014-06-30 10:57:38 -0500 | [diff] [blame] | 1190 | desc->name = rinfo->name; |
| 1191 | desc->id = id; |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 1192 | |
Axel Lin | fedd89b | 2012-06-06 20:01:38 +0800 | [diff] [blame] | 1193 | switch (id) { |
Kishon Vijay Abraham I | 77409d9 | 2013-08-12 14:21:14 +0530 | [diff] [blame] | 1194 | case PALMAS_REG_SMPS10_OUT1: |
| 1195 | case PALMAS_REG_SMPS10_OUT2: |
Nishanth Menon | 429222d | 2014-06-30 10:57:38 -0500 | [diff] [blame] | 1196 | desc->n_voltages = PALMAS_SMPS10_NUM_VOLTAGES; |
| 1197 | desc->ops = &palmas_ops_smps10; |
| 1198 | desc->vsel_reg = PALMAS_BASE_TO_REG(PALMAS_SMPS_BASE, |
| 1199 | PALMAS_SMPS10_CTRL); |
| 1200 | desc->vsel_mask = SMPS10_VSEL; |
| 1201 | desc->enable_reg = PALMAS_BASE_TO_REG(PALMAS_SMPS_BASE, |
| 1202 | PALMAS_SMPS10_CTRL); |
Kishon Vijay Abraham I | 77409d9 | 2013-08-12 14:21:14 +0530 | [diff] [blame] | 1203 | if (id == PALMAS_REG_SMPS10_OUT1) |
Nishanth Menon | 429222d | 2014-06-30 10:57:38 -0500 | [diff] [blame] | 1204 | desc->enable_mask = SMPS10_SWITCH_EN; |
Kishon Vijay Abraham I | 77409d9 | 2013-08-12 14:21:14 +0530 | [diff] [blame] | 1205 | else |
Nishanth Menon | 429222d | 2014-06-30 10:57:38 -0500 | [diff] [blame] | 1206 | desc->enable_mask = SMPS10_BOOST_EN; |
| 1207 | desc->bypass_reg = PALMAS_BASE_TO_REG(PALMAS_SMPS_BASE, |
| 1208 | PALMAS_SMPS10_CTRL); |
| 1209 | desc->bypass_mask = SMPS10_BYPASS_EN; |
| 1210 | desc->min_uV = 3750000; |
| 1211 | desc->uV_step = 1250000; |
Axel Lin | fedd89b | 2012-06-06 20:01:38 +0800 | [diff] [blame] | 1212 | break; |
| 1213 | default: |
Axel Lin | bdc4baa | 2012-11-29 10:01:44 +0800 | [diff] [blame] | 1214 | /* |
| 1215 | * Read and store the RANGE bit for later use |
| 1216 | * This must be done before regulator is probed, |
Laxman Dewangan | 51d3a0c | 2013-04-18 18:32:48 +0530 | [diff] [blame] | 1217 | * otherwise we error in probe with unsupportable |
| 1218 | * ranges. Read the current smps mode for later use. |
Axel Lin | bdc4baa | 2012-11-29 10:01:44 +0800 | [diff] [blame] | 1219 | */ |
Nishanth Menon | cf910b6 | 2014-06-30 10:57:36 -0500 | [diff] [blame] | 1220 | addr = rinfo->vsel_addr; |
Nishanth Menon | 429222d | 2014-06-30 10:57:38 -0500 | [diff] [blame] | 1221 | desc->n_linear_ranges = 3; |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 1222 | |
| 1223 | ret = palmas_smps_read(pmic->palmas, addr, ®); |
| 1224 | if (ret) |
Sachin Kamat | 51c86b3 | 2013-09-04 12:01:01 +0530 | [diff] [blame] | 1225 | return ret; |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 1226 | if (reg & PALMAS_SMPS12_VOLTAGE_RANGE) |
| 1227 | pmic->range[id] = 1; |
Keerthy | dbabd62 | 2014-05-22 14:48:29 +0530 | [diff] [blame] | 1228 | if (pmic->range[id]) |
Nishanth Menon | 429222d | 2014-06-30 10:57:38 -0500 | [diff] [blame] | 1229 | desc->linear_ranges = smps_high_ranges; |
Keerthy | dbabd62 | 2014-05-22 14:48:29 +0530 | [diff] [blame] | 1230 | else |
Nishanth Menon | 429222d | 2014-06-30 10:57:38 -0500 | [diff] [blame] | 1231 | desc->linear_ranges = smps_low_ranges; |
Axel Lin | bdc4baa | 2012-11-29 10:01:44 +0800 | [diff] [blame] | 1232 | |
Laxman Dewangan | 32b6d3f | 2013-08-21 16:18:16 +0530 | [diff] [blame] | 1233 | if (reg_init && reg_init->roof_floor) |
Nishanth Menon | 429222d | 2014-06-30 10:57:38 -0500 | [diff] [blame] | 1234 | desc->ops = &palmas_ops_ext_control_smps; |
Laxman Dewangan | 32b6d3f | 2013-08-21 16:18:16 +0530 | [diff] [blame] | 1235 | else |
Nishanth Menon | 429222d | 2014-06-30 10:57:38 -0500 | [diff] [blame] | 1236 | desc->ops = &palmas_ops_smps; |
| 1237 | desc->n_voltages = PALMAS_SMPS_NUM_VOLTAGES; |
| 1238 | desc->vsel_reg = PALMAS_BASE_TO_REG(PALMAS_SMPS_BASE, |
| 1239 | rinfo->vsel_addr); |
| 1240 | desc->vsel_mask = PALMAS_SMPS12_VOLTAGE_VSEL_MASK; |
Laxman Dewangan | 51d3a0c | 2013-04-18 18:32:48 +0530 | [diff] [blame] | 1241 | |
| 1242 | /* Read the smps mode for later use. */ |
Nishanth Menon | cf910b6 | 2014-06-30 10:57:36 -0500 | [diff] [blame] | 1243 | addr = rinfo->ctrl_addr; |
Laxman Dewangan | 51d3a0c | 2013-04-18 18:32:48 +0530 | [diff] [blame] | 1244 | ret = palmas_smps_read(pmic->palmas, addr, ®); |
| 1245 | if (ret) |
Sachin Kamat | 51c86b3 | 2013-09-04 12:01:01 +0530 | [diff] [blame] | 1246 | return ret; |
Laxman Dewangan | 51d3a0c | 2013-04-18 18:32:48 +0530 | [diff] [blame] | 1247 | pmic->current_reg_mode[id] = reg & |
| 1248 | PALMAS_SMPS12_CTRL_MODE_ACTIVE_MASK; |
Nishanth Menon | 318dbb0 | 2014-06-20 12:26:23 -0500 | [diff] [blame] | 1249 | |
Nishanth Menon | 429222d | 2014-06-30 10:57:38 -0500 | [diff] [blame] | 1250 | desc->enable_reg = PALMAS_BASE_TO_REG(PALMAS_SMPS_BASE, |
| 1251 | rinfo->ctrl_addr); |
| 1252 | desc->enable_mask = PALMAS_SMPS12_CTRL_MODE_ACTIVE_MASK; |
Nishanth Menon | 318dbb0 | 2014-06-20 12:26:23 -0500 | [diff] [blame] | 1253 | /* set_mode overrides this value */ |
Nishanth Menon | 429222d | 2014-06-30 10:57:38 -0500 | [diff] [blame] | 1254 | desc->enable_val = SMPS_CTRL_MODE_ON; |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 1255 | } |
| 1256 | |
Nishanth Menon | 429222d | 2014-06-30 10:57:38 -0500 | [diff] [blame] | 1257 | desc->type = REGULATOR_VOLTAGE; |
| 1258 | desc->owner = THIS_MODULE; |
Axel Lin | bdc4baa | 2012-11-29 10:01:44 +0800 | [diff] [blame] | 1259 | |
Graeme Gregory | a361cd9 | 2012-08-28 13:47:40 +0200 | [diff] [blame] | 1260 | if (pdata) |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 1261 | config.init_data = pdata->reg_data[id]; |
| 1262 | else |
| 1263 | config.init_data = NULL; |
| 1264 | |
Nishanth Menon | 429222d | 2014-06-30 10:57:38 -0500 | [diff] [blame] | 1265 | desc->supply_name = rinfo->sname; |
Keerthy | cac9e91 | 2014-06-18 15:28:59 +0530 | [diff] [blame] | 1266 | config.of_node = ddata->palmas_matches[id].of_node; |
Graeme Gregory | a361cd9 | 2012-08-28 13:47:40 +0200 | [diff] [blame] | 1267 | |
Nishanth Menon | 429222d | 2014-06-30 10:57:38 -0500 | [diff] [blame] | 1268 | rdev = devm_regulator_register(pmic->dev, desc, &config); |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 1269 | if (IS_ERR(rdev)) { |
Keerthy | cac9e91 | 2014-06-18 15:28:59 +0530 | [diff] [blame] | 1270 | dev_err(pmic->dev, |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 1271 | "failed to register %s regulator\n", |
Keerthy | cac9e91 | 2014-06-18 15:28:59 +0530 | [diff] [blame] | 1272 | pdev_name); |
Sachin Kamat | 51c86b3 | 2013-09-04 12:01:01 +0530 | [diff] [blame] | 1273 | return PTR_ERR(rdev); |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 1274 | } |
| 1275 | |
| 1276 | /* Save regulator for cleanup */ |
| 1277 | pmic->rdev[id] = rdev; |
| 1278 | } |
| 1279 | |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 1280 | return 0; |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 1281 | } |
| 1282 | |
Keerthy | d6f8337 | 2014-06-18 15:29:00 +0530 | [diff] [blame] | 1283 | static int tps65917_smps_registration(struct palmas_pmic *pmic, |
| 1284 | struct palmas_pmic_driver_data *ddata, |
| 1285 | struct palmas_pmic_platform_data *pdata, |
| 1286 | const char *pdev_name, |
| 1287 | struct regulator_config config) |
| 1288 | { |
| 1289 | int id, ret; |
| 1290 | unsigned int addr, reg; |
| 1291 | struct regulator_dev *rdev; |
| 1292 | struct palmas_reg_init *reg_init; |
Nishanth Menon | cf910b6 | 2014-06-30 10:57:36 -0500 | [diff] [blame] | 1293 | struct palmas_regs_info *rinfo; |
Nishanth Menon | 429222d | 2014-06-30 10:57:38 -0500 | [diff] [blame] | 1294 | struct regulator_desc *desc; |
Keerthy | d6f8337 | 2014-06-18 15:29:00 +0530 | [diff] [blame] | 1295 | |
| 1296 | for (id = ddata->smps_start; id <= ddata->smps_end; id++) { |
| 1297 | /* |
| 1298 | * Miss out regulators which are not available due |
| 1299 | * to slaving configurations. |
| 1300 | */ |
Nishanth Menon | 429222d | 2014-06-30 10:57:38 -0500 | [diff] [blame] | 1301 | desc = &pmic->desc[id]; |
| 1302 | desc->n_linear_ranges = 3; |
Keerthy | d6f8337 | 2014-06-18 15:29:00 +0530 | [diff] [blame] | 1303 | if ((id == TPS65917_REG_SMPS2) && pmic->smps12) |
| 1304 | continue; |
| 1305 | |
| 1306 | /* Initialise sleep/init values from platform data */ |
| 1307 | if (pdata && pdata->reg_init[id]) { |
| 1308 | reg_init = pdata->reg_init[id]; |
| 1309 | ret = palmas_smps_init(pmic->palmas, id, reg_init); |
| 1310 | if (ret) |
| 1311 | return ret; |
| 1312 | } else { |
| 1313 | reg_init = NULL; |
| 1314 | } |
Nishanth Menon | cf910b6 | 2014-06-30 10:57:36 -0500 | [diff] [blame] | 1315 | rinfo = &ddata->palmas_regs_info[id]; |
Keerthy | d6f8337 | 2014-06-18 15:29:00 +0530 | [diff] [blame] | 1316 | |
| 1317 | /* Register the regulators */ |
Nishanth Menon | 429222d | 2014-06-30 10:57:38 -0500 | [diff] [blame] | 1318 | desc->name = rinfo->name; |
| 1319 | desc->id = id; |
Keerthy | d6f8337 | 2014-06-18 15:29:00 +0530 | [diff] [blame] | 1320 | |
| 1321 | /* |
| 1322 | * Read and store the RANGE bit for later use |
| 1323 | * This must be done before regulator is probed, |
| 1324 | * otherwise we error in probe with unsupportable |
| 1325 | * ranges. Read the current smps mode for later use. |
| 1326 | */ |
Nishanth Menon | cf910b6 | 2014-06-30 10:57:36 -0500 | [diff] [blame] | 1327 | addr = rinfo->vsel_addr; |
Keerthy | d6f8337 | 2014-06-18 15:29:00 +0530 | [diff] [blame] | 1328 | |
| 1329 | ret = palmas_smps_read(pmic->palmas, addr, ®); |
| 1330 | if (ret) |
| 1331 | return ret; |
| 1332 | if (reg & TPS65917_SMPS1_VOLTAGE_RANGE) |
| 1333 | pmic->range[id] = 1; |
| 1334 | |
| 1335 | if (pmic->range[id]) |
Nishanth Menon | 429222d | 2014-06-30 10:57:38 -0500 | [diff] [blame] | 1336 | desc->linear_ranges = smps_high_ranges; |
| 1337 | else |
| 1338 | desc->linear_ranges = smps_low_ranges; |
Keerthy | d6f8337 | 2014-06-18 15:29:00 +0530 | [diff] [blame] | 1339 | |
| 1340 | if (reg_init && reg_init->roof_floor) |
Nishanth Menon | 429222d | 2014-06-30 10:57:38 -0500 | [diff] [blame] | 1341 | desc->ops = &tps65917_ops_ext_control_smps; |
Keerthy | d6f8337 | 2014-06-18 15:29:00 +0530 | [diff] [blame] | 1342 | else |
Nishanth Menon | 429222d | 2014-06-30 10:57:38 -0500 | [diff] [blame] | 1343 | desc->ops = &tps65917_ops_smps; |
| 1344 | desc->n_voltages = PALMAS_SMPS_NUM_VOLTAGES; |
| 1345 | desc->vsel_reg = PALMAS_BASE_TO_REG(PALMAS_SMPS_BASE, |
| 1346 | rinfo->vsel_addr); |
| 1347 | desc->vsel_mask = PALMAS_SMPS12_VOLTAGE_VSEL_MASK; |
| 1348 | desc->ramp_delay = 2500; |
Keerthy | d6f8337 | 2014-06-18 15:29:00 +0530 | [diff] [blame] | 1349 | |
| 1350 | /* Read the smps mode for later use. */ |
Nishanth Menon | cf910b6 | 2014-06-30 10:57:36 -0500 | [diff] [blame] | 1351 | addr = rinfo->ctrl_addr; |
Keerthy | d6f8337 | 2014-06-18 15:29:00 +0530 | [diff] [blame] | 1352 | ret = palmas_smps_read(pmic->palmas, addr, ®); |
| 1353 | if (ret) |
| 1354 | return ret; |
| 1355 | pmic->current_reg_mode[id] = reg & |
| 1356 | PALMAS_SMPS12_CTRL_MODE_ACTIVE_MASK; |
Nishanth Menon | b632815 | 2014-06-30 10:57:39 -0500 | [diff] [blame] | 1357 | desc->enable_reg = PALMAS_BASE_TO_REG(PALMAS_SMPS_BASE, |
| 1358 | rinfo->ctrl_addr); |
| 1359 | desc->enable_mask = PALMAS_SMPS12_CTRL_MODE_ACTIVE_MASK; |
| 1360 | /* set_mode overrides this value */ |
| 1361 | desc->enable_val = SMPS_CTRL_MODE_ON; |
Keerthy | d6f8337 | 2014-06-18 15:29:00 +0530 | [diff] [blame] | 1362 | |
Nishanth Menon | 429222d | 2014-06-30 10:57:38 -0500 | [diff] [blame] | 1363 | desc->type = REGULATOR_VOLTAGE; |
| 1364 | desc->owner = THIS_MODULE; |
Keerthy | d6f8337 | 2014-06-18 15:29:00 +0530 | [diff] [blame] | 1365 | |
| 1366 | if (pdata) |
| 1367 | config.init_data = pdata->reg_data[id]; |
| 1368 | else |
| 1369 | config.init_data = NULL; |
| 1370 | |
Nishanth Menon | 429222d | 2014-06-30 10:57:38 -0500 | [diff] [blame] | 1371 | desc->supply_name = rinfo->sname; |
Keerthy | d6f8337 | 2014-06-18 15:29:00 +0530 | [diff] [blame] | 1372 | config.of_node = ddata->palmas_matches[id].of_node; |
| 1373 | |
Nishanth Menon | 429222d | 2014-06-30 10:57:38 -0500 | [diff] [blame] | 1374 | rdev = devm_regulator_register(pmic->dev, desc, &config); |
Keerthy | d6f8337 | 2014-06-18 15:29:00 +0530 | [diff] [blame] | 1375 | if (IS_ERR(rdev)) { |
| 1376 | dev_err(pmic->dev, |
| 1377 | "failed to register %s regulator\n", |
| 1378 | pdev_name); |
| 1379 | return PTR_ERR(rdev); |
| 1380 | } |
| 1381 | |
| 1382 | /* Save regulator for cleanup */ |
| 1383 | pmic->rdev[id] = rdev; |
| 1384 | } |
| 1385 | |
| 1386 | return 0; |
| 1387 | } |
| 1388 | |
Keerthy | cac9e91 | 2014-06-18 15:28:59 +0530 | [diff] [blame] | 1389 | static struct of_regulator_match palmas_matches[] = { |
| 1390 | { .name = "smps12", }, |
| 1391 | { .name = "smps123", }, |
| 1392 | { .name = "smps3", }, |
| 1393 | { .name = "smps45", }, |
| 1394 | { .name = "smps457", }, |
| 1395 | { .name = "smps6", }, |
| 1396 | { .name = "smps7", }, |
| 1397 | { .name = "smps8", }, |
| 1398 | { .name = "smps9", }, |
| 1399 | { .name = "smps10_out2", }, |
| 1400 | { .name = "smps10_out1", }, |
| 1401 | { .name = "ldo1", }, |
| 1402 | { .name = "ldo2", }, |
| 1403 | { .name = "ldo3", }, |
| 1404 | { .name = "ldo4", }, |
| 1405 | { .name = "ldo5", }, |
| 1406 | { .name = "ldo6", }, |
| 1407 | { .name = "ldo7", }, |
| 1408 | { .name = "ldo8", }, |
| 1409 | { .name = "ldo9", }, |
| 1410 | { .name = "ldoln", }, |
| 1411 | { .name = "ldousb", }, |
| 1412 | { .name = "regen1", }, |
| 1413 | { .name = "regen2", }, |
| 1414 | { .name = "regen3", }, |
| 1415 | { .name = "sysen1", }, |
| 1416 | { .name = "sysen2", }, |
| 1417 | }; |
| 1418 | |
Keerthy | d6f8337 | 2014-06-18 15:29:00 +0530 | [diff] [blame] | 1419 | static struct of_regulator_match tps65917_matches[] = { |
| 1420 | { .name = "smps1", }, |
| 1421 | { .name = "smps2", }, |
| 1422 | { .name = "smps3", }, |
| 1423 | { .name = "smps4", }, |
| 1424 | { .name = "smps5", }, |
| 1425 | { .name = "ldo1", }, |
| 1426 | { .name = "ldo2", }, |
| 1427 | { .name = "ldo3", }, |
| 1428 | { .name = "ldo4", }, |
| 1429 | { .name = "ldo5", }, |
| 1430 | { .name = "regen1", }, |
| 1431 | { .name = "regen2", }, |
| 1432 | { .name = "regen3", }, |
| 1433 | { .name = "sysen1", }, |
| 1434 | { .name = "sysen2", }, |
| 1435 | }; |
| 1436 | |
Nishanth Menon | 4b09e17 | 2014-06-30 10:57:34 -0500 | [diff] [blame] | 1437 | static struct palmas_pmic_driver_data palmas_ddata = { |
Keerthy | cac9e91 | 2014-06-18 15:28:59 +0530 | [diff] [blame] | 1438 | .smps_start = PALMAS_REG_SMPS12, |
| 1439 | .smps_end = PALMAS_REG_SMPS10_OUT1, |
| 1440 | .ldo_begin = PALMAS_REG_LDO1, |
| 1441 | .ldo_end = PALMAS_REG_LDOUSB, |
| 1442 | .max_reg = PALMAS_NUM_REGS, |
Keerthy | e999c72 | 2015-03-17 15:56:05 +0530 | [diff] [blame] | 1443 | .has_regen3 = true, |
Nishanth Menon | 6839cd6 | 2014-06-30 10:57:37 -0500 | [diff] [blame] | 1444 | .palmas_regs_info = palmas_generic_regs_info, |
Keerthy | cac9e91 | 2014-06-18 15:28:59 +0530 | [diff] [blame] | 1445 | .palmas_matches = palmas_matches, |
| 1446 | .sleep_req_info = palma_sleep_req_info, |
| 1447 | .smps_register = palmas_smps_registration, |
| 1448 | .ldo_register = palmas_ldo_registration, |
| 1449 | }; |
| 1450 | |
Nishanth Menon | 4b09e17 | 2014-06-30 10:57:34 -0500 | [diff] [blame] | 1451 | static struct palmas_pmic_driver_data tps65917_ddata = { |
Keerthy | d6f8337 | 2014-06-18 15:29:00 +0530 | [diff] [blame] | 1452 | .smps_start = TPS65917_REG_SMPS1, |
| 1453 | .smps_end = TPS65917_REG_SMPS5, |
| 1454 | .ldo_begin = TPS65917_REG_LDO1, |
| 1455 | .ldo_end = TPS65917_REG_LDO5, |
| 1456 | .max_reg = TPS65917_NUM_REGS, |
Keerthy | e999c72 | 2015-03-17 15:56:05 +0530 | [diff] [blame] | 1457 | .has_regen3 = true, |
Keerthy | d6f8337 | 2014-06-18 15:29:00 +0530 | [diff] [blame] | 1458 | .palmas_regs_info = tps65917_regs_info, |
| 1459 | .palmas_matches = tps65917_matches, |
| 1460 | .sleep_req_info = tps65917_sleep_req_info, |
| 1461 | .smps_register = tps65917_smps_registration, |
| 1462 | .ldo_register = tps65917_ldo_registration, |
| 1463 | }; |
| 1464 | |
Keerthy | cac9e91 | 2014-06-18 15:28:59 +0530 | [diff] [blame] | 1465 | static void palmas_dt_to_pdata(struct device *dev, |
| 1466 | struct device_node *node, |
| 1467 | struct palmas_pmic_platform_data *pdata, |
| 1468 | struct palmas_pmic_driver_data *ddata) |
| 1469 | { |
| 1470 | struct device_node *regulators; |
| 1471 | u32 prop; |
| 1472 | int idx, ret; |
| 1473 | |
Keerthy | cac9e91 | 2014-06-18 15:28:59 +0530 | [diff] [blame] | 1474 | regulators = of_get_child_by_name(node, "regulators"); |
| 1475 | if (!regulators) { |
| 1476 | dev_info(dev, "regulator node not found\n"); |
| 1477 | return; |
| 1478 | } |
| 1479 | |
| 1480 | ret = of_regulator_match(dev, regulators, ddata->palmas_matches, |
| 1481 | ddata->max_reg); |
| 1482 | of_node_put(regulators); |
| 1483 | if (ret < 0) { |
| 1484 | dev_err(dev, "Error parsing regulator init data: %d\n", ret); |
| 1485 | return; |
| 1486 | } |
| 1487 | |
| 1488 | for (idx = 0; idx < ddata->max_reg; idx++) { |
| 1489 | if (!ddata->palmas_matches[idx].init_data || |
| 1490 | !ddata->palmas_matches[idx].of_node) |
| 1491 | continue; |
| 1492 | |
| 1493 | pdata->reg_data[idx] = ddata->palmas_matches[idx].init_data; |
| 1494 | |
| 1495 | pdata->reg_init[idx] = devm_kzalloc(dev, |
| 1496 | sizeof(struct palmas_reg_init), GFP_KERNEL); |
| 1497 | |
| 1498 | pdata->reg_init[idx]->warm_reset = |
| 1499 | of_property_read_bool(ddata->palmas_matches[idx].of_node, |
| 1500 | "ti,warm-reset"); |
| 1501 | |
| 1502 | ret = of_property_read_u32(ddata->palmas_matches[idx].of_node, |
| 1503 | "ti,roof-floor", &prop); |
| 1504 | /* EINVAL: Property not found */ |
| 1505 | if (ret != -EINVAL) { |
| 1506 | int econtrol; |
| 1507 | |
| 1508 | /* use default value, when no value is specified */ |
| 1509 | econtrol = PALMAS_EXT_CONTROL_NSLEEP; |
| 1510 | if (!ret) { |
| 1511 | switch (prop) { |
| 1512 | case 1: |
| 1513 | econtrol = PALMAS_EXT_CONTROL_ENABLE1; |
| 1514 | break; |
| 1515 | case 2: |
| 1516 | econtrol = PALMAS_EXT_CONTROL_ENABLE2; |
| 1517 | break; |
| 1518 | case 3: |
| 1519 | econtrol = PALMAS_EXT_CONTROL_NSLEEP; |
| 1520 | break; |
| 1521 | default: |
| 1522 | WARN_ON(1); |
| 1523 | dev_warn(dev, |
| 1524 | "%s: Invalid roof-floor option: %u\n", |
| 1525 | palmas_matches[idx].name, prop); |
| 1526 | break; |
| 1527 | } |
| 1528 | } |
| 1529 | pdata->reg_init[idx]->roof_floor = econtrol; |
| 1530 | } |
| 1531 | |
| 1532 | ret = of_property_read_u32(ddata->palmas_matches[idx].of_node, |
| 1533 | "ti,mode-sleep", &prop); |
| 1534 | if (!ret) |
| 1535 | pdata->reg_init[idx]->mode_sleep = prop; |
| 1536 | |
| 1537 | ret = of_property_read_bool(ddata->palmas_matches[idx].of_node, |
| 1538 | "ti,smps-range"); |
| 1539 | if (ret) |
| 1540 | pdata->reg_init[idx]->vsel = |
| 1541 | PALMAS_SMPS12_VOLTAGE_RANGE; |
| 1542 | |
| 1543 | if (idx == PALMAS_REG_LDO8) |
| 1544 | pdata->enable_ldo8_tracking = of_property_read_bool( |
| 1545 | ddata->palmas_matches[idx].of_node, |
| 1546 | "ti,enable-ldo8-tracking"); |
| 1547 | } |
| 1548 | |
| 1549 | pdata->ldo6_vibrator = of_property_read_bool(node, "ti,ldo6-vibrator"); |
| 1550 | } |
| 1551 | |
Fabian Frederick | cdbf6f0 | 2015-03-16 20:17:08 +0100 | [diff] [blame] | 1552 | static const struct of_device_id of_palmas_match_tbl[] = { |
Keerthy | cac9e91 | 2014-06-18 15:28:59 +0530 | [diff] [blame] | 1553 | { |
| 1554 | .compatible = "ti,palmas-pmic", |
| 1555 | .data = &palmas_ddata, |
| 1556 | }, |
| 1557 | { |
| 1558 | .compatible = "ti,twl6035-pmic", |
| 1559 | .data = &palmas_ddata, |
| 1560 | }, |
| 1561 | { |
| 1562 | .compatible = "ti,twl6036-pmic", |
| 1563 | .data = &palmas_ddata, |
| 1564 | }, |
| 1565 | { |
| 1566 | .compatible = "ti,twl6037-pmic", |
| 1567 | .data = &palmas_ddata, |
| 1568 | }, |
| 1569 | { |
| 1570 | .compatible = "ti,tps65913-pmic", |
| 1571 | .data = &palmas_ddata, |
| 1572 | }, |
| 1573 | { |
| 1574 | .compatible = "ti,tps65914-pmic", |
| 1575 | .data = &palmas_ddata, |
| 1576 | }, |
| 1577 | { |
| 1578 | .compatible = "ti,tps80036-pmic", |
| 1579 | .data = &palmas_ddata, |
| 1580 | }, |
| 1581 | { |
| 1582 | .compatible = "ti,tps659038-pmic", |
| 1583 | .data = &palmas_ddata, |
| 1584 | }, |
Keerthy | d6f8337 | 2014-06-18 15:29:00 +0530 | [diff] [blame] | 1585 | { |
| 1586 | .compatible = "ti,tps65917-pmic", |
| 1587 | .data = &tps65917_ddata, |
| 1588 | }, |
Graeme Gregory | a361cd9 | 2012-08-28 13:47:40 +0200 | [diff] [blame] | 1589 | { /* end */ } |
| 1590 | }; |
| 1591 | |
Keerthy | cac9e91 | 2014-06-18 15:28:59 +0530 | [diff] [blame] | 1592 | static int palmas_regulators_probe(struct platform_device *pdev) |
| 1593 | { |
| 1594 | struct palmas *palmas = dev_get_drvdata(pdev->dev.parent); |
| 1595 | struct palmas_pmic_platform_data *pdata = dev_get_platdata(&pdev->dev); |
| 1596 | struct device_node *node = pdev->dev.of_node; |
| 1597 | struct palmas_pmic_driver_data *driver_data; |
| 1598 | struct regulator_config config = { }; |
| 1599 | struct palmas_pmic *pmic; |
| 1600 | const char *pdev_name; |
| 1601 | const struct of_device_id *match; |
| 1602 | int ret = 0; |
| 1603 | unsigned int reg; |
| 1604 | |
| 1605 | match = of_match_device(of_match_ptr(of_palmas_match_tbl), &pdev->dev); |
| 1606 | |
| 1607 | if (!match) |
| 1608 | return -ENODATA; |
| 1609 | |
| 1610 | driver_data = (struct palmas_pmic_driver_data *)match->data; |
| 1611 | pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL); |
| 1612 | if (!pdata) |
| 1613 | return -ENOMEM; |
| 1614 | |
| 1615 | pmic = devm_kzalloc(&pdev->dev, sizeof(*pmic), GFP_KERNEL); |
| 1616 | if (!pmic) |
| 1617 | return -ENOMEM; |
| 1618 | |
Keerthy | e999c72 | 2015-03-17 15:56:05 +0530 | [diff] [blame] | 1619 | if (of_device_is_compatible(node, "ti,tps659038-pmic")) { |
Keerthy | e03826d | 2015-03-17 15:56:04 +0530 | [diff] [blame] | 1620 | palmas_generic_regs_info[PALMAS_REG_REGEN2].ctrl_addr = |
| 1621 | TPS659038_REGEN2_CTRL; |
Keerthy | e999c72 | 2015-03-17 15:56:05 +0530 | [diff] [blame] | 1622 | palmas_ddata.has_regen3 = false; |
| 1623 | } |
Keerthy | e03826d | 2015-03-17 15:56:04 +0530 | [diff] [blame] | 1624 | |
Keerthy | cac9e91 | 2014-06-18 15:28:59 +0530 | [diff] [blame] | 1625 | pmic->dev = &pdev->dev; |
| 1626 | pmic->palmas = palmas; |
| 1627 | palmas->pmic = pmic; |
| 1628 | platform_set_drvdata(pdev, pmic); |
| 1629 | pmic->palmas->pmic_ddata = driver_data; |
| 1630 | |
| 1631 | palmas_dt_to_pdata(&pdev->dev, node, pdata, driver_data); |
| 1632 | |
| 1633 | ret = palmas_smps_read(palmas, PALMAS_SMPS_CTRL, ®); |
| 1634 | if (ret) |
| 1635 | return ret; |
| 1636 | |
| 1637 | if (reg & PALMAS_SMPS_CTRL_SMPS12_SMPS123_EN) |
| 1638 | pmic->smps123 = 1; |
| 1639 | |
| 1640 | if (reg & PALMAS_SMPS_CTRL_SMPS45_SMPS457_EN) |
| 1641 | pmic->smps457 = 1; |
| 1642 | |
| 1643 | config.regmap = palmas->regmap[REGULATOR_SLAVE]; |
| 1644 | config.dev = &pdev->dev; |
| 1645 | config.driver_data = pmic; |
| 1646 | pdev_name = pdev->name; |
| 1647 | |
| 1648 | ret = driver_data->smps_register(pmic, driver_data, pdata, pdev_name, |
| 1649 | config); |
| 1650 | if (ret) |
| 1651 | return ret; |
| 1652 | |
| 1653 | ret = driver_data->ldo_register(pmic, driver_data, pdata, pdev_name, |
| 1654 | config); |
| 1655 | |
| 1656 | return ret; |
| 1657 | } |
| 1658 | |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 1659 | static struct platform_driver palmas_driver = { |
| 1660 | .driver = { |
| 1661 | .name = "palmas-pmic", |
Graeme Gregory | a361cd9 | 2012-08-28 13:47:40 +0200 | [diff] [blame] | 1662 | .of_match_table = of_palmas_match_tbl, |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 1663 | }, |
Laxman Dewangan | bbcf50b | 2013-03-18 14:59:49 +0530 | [diff] [blame] | 1664 | .probe = palmas_regulators_probe, |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 1665 | }; |
| 1666 | |
| 1667 | static int __init palmas_init(void) |
| 1668 | { |
| 1669 | return platform_driver_register(&palmas_driver); |
| 1670 | } |
| 1671 | subsys_initcall(palmas_init); |
| 1672 | |
| 1673 | static void __exit palmas_exit(void) |
| 1674 | { |
| 1675 | platform_driver_unregister(&palmas_driver); |
| 1676 | } |
| 1677 | module_exit(palmas_exit); |
| 1678 | |
| 1679 | MODULE_AUTHOR("Graeme Gregory <gg@slimlogic.co.uk>"); |
| 1680 | MODULE_DESCRIPTION("Palmas voltage regulator driver"); |
| 1681 | MODULE_LICENSE("GPL"); |
| 1682 | MODULE_ALIAS("platform:palmas-pmic"); |
Graeme Gregory | a361cd9 | 2012-08-28 13:47:40 +0200 | [diff] [blame] | 1683 | MODULE_DEVICE_TABLE(of, of_palmas_match_tbl); |