Thomas Gleixner | 2874c5f | 2019-05-27 08:55:01 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
Graeme Gregory | 518fb72 | 2011-05-02 16:20:08 -0500 | [diff] [blame] | 2 | /* |
| 3 | * tps65910.c -- TI tps65910 |
| 4 | * |
| 5 | * Copyright 2010 Texas Instruments Inc. |
| 6 | * |
| 7 | * Author: Graeme Gregory <gg@slimlogic.co.uk> |
| 8 | * Author: Jorge Eduardo Candelaria <jedu@slimlogic.co.uk> |
Graeme Gregory | 518fb72 | 2011-05-02 16:20:08 -0500 | [diff] [blame] | 9 | */ |
| 10 | |
| 11 | #include <linux/kernel.h> |
| 12 | #include <linux/module.h> |
| 13 | #include <linux/init.h> |
| 14 | #include <linux/err.h> |
Geert Uytterhoeven | d16da51 | 2015-03-15 14:03:50 +0100 | [diff] [blame] | 15 | #include <linux/of.h> |
Graeme Gregory | 518fb72 | 2011-05-02 16:20:08 -0500 | [diff] [blame] | 16 | #include <linux/platform_device.h> |
| 17 | #include <linux/regulator/driver.h> |
| 18 | #include <linux/regulator/machine.h> |
Graeme Gregory | 518fb72 | 2011-05-02 16:20:08 -0500 | [diff] [blame] | 19 | #include <linux/slab.h> |
| 20 | #include <linux/gpio.h> |
| 21 | #include <linux/mfd/tps65910.h> |
Rhyland Klein | 6790178 | 2012-05-08 11:42:41 -0700 | [diff] [blame] | 22 | #include <linux/regulator/of_regulator.h> |
Graeme Gregory | 518fb72 | 2011-05-02 16:20:08 -0500 | [diff] [blame] | 23 | |
Graeme Gregory | 518fb72 | 2011-05-02 16:20:08 -0500 | [diff] [blame] | 24 | #define TPS65910_SUPPLY_STATE_ENABLED 0x1 |
Laxman Dewangan | 1e0c66f | 2012-01-28 15:07:57 +0530 | [diff] [blame] | 25 | #define EXT_SLEEP_CONTROL (TPS65910_SLEEP_CONTROL_EXT_INPUT_EN1 | \ |
| 26 | TPS65910_SLEEP_CONTROL_EXT_INPUT_EN2 | \ |
Laxman Dewangan | f30b071 | 2012-03-07 18:21:49 +0530 | [diff] [blame] | 27 | TPS65910_SLEEP_CONTROL_EXT_INPUT_EN3 | \ |
| 28 | TPS65911_SLEEP_CONTROL_EXT_INPUT_SLEEP) |
Graeme Gregory | 518fb72 | 2011-05-02 16:20:08 -0500 | [diff] [blame] | 29 | |
Axel Lin | d9fe28f | 2012-06-21 18:48:00 +0800 | [diff] [blame] | 30 | /* supported VIO voltages in microvolts */ |
| 31 | static const unsigned int VIO_VSEL_table[] = { |
| 32 | 1500000, 1800000, 2500000, 3300000, |
Graeme Gregory | 518fb72 | 2011-05-02 16:20:08 -0500 | [diff] [blame] | 33 | }; |
| 34 | |
Jorge Eduardo Candelaria | a320e3c | 2011-05-16 18:35:03 -0500 | [diff] [blame] | 35 | /* VSEL tables for TPS65910 specific LDOs and dcdc's */ |
| 36 | |
AnilKumar Ch | a9a5659 | 2012-10-15 17:45:58 +0530 | [diff] [blame] | 37 | /* supported VRTC voltages in microvolts */ |
| 38 | static const unsigned int VRTC_VSEL_table[] = { |
| 39 | 1800000, |
| 40 | }; |
| 41 | |
Axel Lin | d9fe28f | 2012-06-21 18:48:00 +0800 | [diff] [blame] | 42 | /* supported VDD3 voltages in microvolts */ |
| 43 | static const unsigned int VDD3_VSEL_table[] = { |
| 44 | 5000000, |
Graeme Gregory | 518fb72 | 2011-05-02 16:20:08 -0500 | [diff] [blame] | 45 | }; |
| 46 | |
Axel Lin | d9fe28f | 2012-06-21 18:48:00 +0800 | [diff] [blame] | 47 | /* supported VDIG1 voltages in microvolts */ |
| 48 | static const unsigned int VDIG1_VSEL_table[] = { |
| 49 | 1200000, 1500000, 1800000, 2700000, |
Graeme Gregory | 518fb72 | 2011-05-02 16:20:08 -0500 | [diff] [blame] | 50 | }; |
| 51 | |
Axel Lin | d9fe28f | 2012-06-21 18:48:00 +0800 | [diff] [blame] | 52 | /* supported VDIG2 voltages in microvolts */ |
| 53 | static const unsigned int VDIG2_VSEL_table[] = { |
| 54 | 1000000, 1100000, 1200000, 1800000, |
Graeme Gregory | 518fb72 | 2011-05-02 16:20:08 -0500 | [diff] [blame] | 55 | }; |
| 56 | |
Axel Lin | d9fe28f | 2012-06-21 18:48:00 +0800 | [diff] [blame] | 57 | /* supported VPLL voltages in microvolts */ |
| 58 | static const unsigned int VPLL_VSEL_table[] = { |
| 59 | 1000000, 1100000, 1800000, 2500000, |
Graeme Gregory | 518fb72 | 2011-05-02 16:20:08 -0500 | [diff] [blame] | 60 | }; |
| 61 | |
Axel Lin | d9fe28f | 2012-06-21 18:48:00 +0800 | [diff] [blame] | 62 | /* supported VDAC voltages in microvolts */ |
| 63 | static const unsigned int VDAC_VSEL_table[] = { |
| 64 | 1800000, 2600000, 2800000, 2850000, |
Graeme Gregory | 518fb72 | 2011-05-02 16:20:08 -0500 | [diff] [blame] | 65 | }; |
| 66 | |
Axel Lin | d9fe28f | 2012-06-21 18:48:00 +0800 | [diff] [blame] | 67 | /* supported VAUX1 voltages in microvolts */ |
| 68 | static const unsigned int VAUX1_VSEL_table[] = { |
| 69 | 1800000, 2500000, 2800000, 2850000, |
Graeme Gregory | 518fb72 | 2011-05-02 16:20:08 -0500 | [diff] [blame] | 70 | }; |
| 71 | |
Axel Lin | d9fe28f | 2012-06-21 18:48:00 +0800 | [diff] [blame] | 72 | /* supported VAUX2 voltages in microvolts */ |
| 73 | static const unsigned int VAUX2_VSEL_table[] = { |
| 74 | 1800000, 2800000, 2900000, 3300000, |
Graeme Gregory | 518fb72 | 2011-05-02 16:20:08 -0500 | [diff] [blame] | 75 | }; |
| 76 | |
Axel Lin | d9fe28f | 2012-06-21 18:48:00 +0800 | [diff] [blame] | 77 | /* supported VAUX33 voltages in microvolts */ |
| 78 | static const unsigned int VAUX33_VSEL_table[] = { |
| 79 | 1800000, 2000000, 2800000, 3300000, |
Graeme Gregory | 518fb72 | 2011-05-02 16:20:08 -0500 | [diff] [blame] | 80 | }; |
| 81 | |
Axel Lin | d9fe28f | 2012-06-21 18:48:00 +0800 | [diff] [blame] | 82 | /* supported VMMC voltages in microvolts */ |
| 83 | static const unsigned int VMMC_VSEL_table[] = { |
| 84 | 1800000, 2800000, 3000000, 3300000, |
Graeme Gregory | 518fb72 | 2011-05-02 16:20:08 -0500 | [diff] [blame] | 85 | }; |
| 86 | |
Markus Pargmann | 03746dc | 2013-12-20 12:43:27 +0100 | [diff] [blame] | 87 | /* supported BBCH voltages in microvolts */ |
| 88 | static const unsigned int VBB_VSEL_table[] = { |
| 89 | 3000000, 2520000, 3150000, 5000000, |
| 90 | }; |
| 91 | |
Graeme Gregory | 518fb72 | 2011-05-02 16:20:08 -0500 | [diff] [blame] | 92 | struct tps_info { |
| 93 | const char *name; |
Laxman Dewangan | 19228a6 | 2012-07-06 14:13:12 +0530 | [diff] [blame] | 94 | const char *vin_name; |
Laxman Dewangan | 7d38a3c | 2012-01-20 16:36:22 +0530 | [diff] [blame] | 95 | u8 n_voltages; |
Axel Lin | d9fe28f | 2012-06-21 18:48:00 +0800 | [diff] [blame] | 96 | const unsigned int *voltage_table; |
Laxman Dewangan | 0651eed | 2012-03-13 11:35:20 +0530 | [diff] [blame] | 97 | int enable_time_us; |
Graeme Gregory | 518fb72 | 2011-05-02 16:20:08 -0500 | [diff] [blame] | 98 | }; |
| 99 | |
| 100 | static struct tps_info tps65910_regs[] = { |
| 101 | { |
Laxman Dewangan | 33a6943 | 2012-05-19 20:04:06 +0530 | [diff] [blame] | 102 | .name = "vrtc", |
Laxman Dewangan | 19228a6 | 2012-07-06 14:13:12 +0530 | [diff] [blame] | 103 | .vin_name = "vcc7", |
AnilKumar Ch | a9a5659 | 2012-10-15 17:45:58 +0530 | [diff] [blame] | 104 | .n_voltages = ARRAY_SIZE(VRTC_VSEL_table), |
| 105 | .voltage_table = VRTC_VSEL_table, |
Laxman Dewangan | 0651eed | 2012-03-13 11:35:20 +0530 | [diff] [blame] | 106 | .enable_time_us = 2200, |
Graeme Gregory | 518fb72 | 2011-05-02 16:20:08 -0500 | [diff] [blame] | 107 | }, |
| 108 | { |
Laxman Dewangan | 33a6943 | 2012-05-19 20:04:06 +0530 | [diff] [blame] | 109 | .name = "vio", |
Laxman Dewangan | 19228a6 | 2012-07-06 14:13:12 +0530 | [diff] [blame] | 110 | .vin_name = "vccio", |
Laxman Dewangan | 7d38a3c | 2012-01-20 16:36:22 +0530 | [diff] [blame] | 111 | .n_voltages = ARRAY_SIZE(VIO_VSEL_table), |
| 112 | .voltage_table = VIO_VSEL_table, |
Laxman Dewangan | 0651eed | 2012-03-13 11:35:20 +0530 | [diff] [blame] | 113 | .enable_time_us = 350, |
Graeme Gregory | 518fb72 | 2011-05-02 16:20:08 -0500 | [diff] [blame] | 114 | }, |
| 115 | { |
Laxman Dewangan | 33a6943 | 2012-05-19 20:04:06 +0530 | [diff] [blame] | 116 | .name = "vdd1", |
Laxman Dewangan | 19228a6 | 2012-07-06 14:13:12 +0530 | [diff] [blame] | 117 | .vin_name = "vcc1", |
Laxman Dewangan | 0651eed | 2012-03-13 11:35:20 +0530 | [diff] [blame] | 118 | .enable_time_us = 350, |
Graeme Gregory | 518fb72 | 2011-05-02 16:20:08 -0500 | [diff] [blame] | 119 | }, |
| 120 | { |
Laxman Dewangan | 33a6943 | 2012-05-19 20:04:06 +0530 | [diff] [blame] | 121 | .name = "vdd2", |
Laxman Dewangan | 19228a6 | 2012-07-06 14:13:12 +0530 | [diff] [blame] | 122 | .vin_name = "vcc2", |
Laxman Dewangan | 0651eed | 2012-03-13 11:35:20 +0530 | [diff] [blame] | 123 | .enable_time_us = 350, |
Graeme Gregory | 518fb72 | 2011-05-02 16:20:08 -0500 | [diff] [blame] | 124 | }, |
| 125 | { |
Laxman Dewangan | 33a6943 | 2012-05-19 20:04:06 +0530 | [diff] [blame] | 126 | .name = "vdd3", |
Laxman Dewangan | 7d38a3c | 2012-01-20 16:36:22 +0530 | [diff] [blame] | 127 | .n_voltages = ARRAY_SIZE(VDD3_VSEL_table), |
| 128 | .voltage_table = VDD3_VSEL_table, |
Laxman Dewangan | 0651eed | 2012-03-13 11:35:20 +0530 | [diff] [blame] | 129 | .enable_time_us = 200, |
Graeme Gregory | 518fb72 | 2011-05-02 16:20:08 -0500 | [diff] [blame] | 130 | }, |
| 131 | { |
Laxman Dewangan | 33a6943 | 2012-05-19 20:04:06 +0530 | [diff] [blame] | 132 | .name = "vdig1", |
Laxman Dewangan | 19228a6 | 2012-07-06 14:13:12 +0530 | [diff] [blame] | 133 | .vin_name = "vcc6", |
Laxman Dewangan | 7d38a3c | 2012-01-20 16:36:22 +0530 | [diff] [blame] | 134 | .n_voltages = ARRAY_SIZE(VDIG1_VSEL_table), |
| 135 | .voltage_table = VDIG1_VSEL_table, |
Laxman Dewangan | 0651eed | 2012-03-13 11:35:20 +0530 | [diff] [blame] | 136 | .enable_time_us = 100, |
Graeme Gregory | 518fb72 | 2011-05-02 16:20:08 -0500 | [diff] [blame] | 137 | }, |
| 138 | { |
Laxman Dewangan | 33a6943 | 2012-05-19 20:04:06 +0530 | [diff] [blame] | 139 | .name = "vdig2", |
Laxman Dewangan | 19228a6 | 2012-07-06 14:13:12 +0530 | [diff] [blame] | 140 | .vin_name = "vcc6", |
Laxman Dewangan | 7d38a3c | 2012-01-20 16:36:22 +0530 | [diff] [blame] | 141 | .n_voltages = ARRAY_SIZE(VDIG2_VSEL_table), |
| 142 | .voltage_table = VDIG2_VSEL_table, |
Laxman Dewangan | 0651eed | 2012-03-13 11:35:20 +0530 | [diff] [blame] | 143 | .enable_time_us = 100, |
Graeme Gregory | 518fb72 | 2011-05-02 16:20:08 -0500 | [diff] [blame] | 144 | }, |
| 145 | { |
Laxman Dewangan | 33a6943 | 2012-05-19 20:04:06 +0530 | [diff] [blame] | 146 | .name = "vpll", |
Laxman Dewangan | 19228a6 | 2012-07-06 14:13:12 +0530 | [diff] [blame] | 147 | .vin_name = "vcc5", |
Laxman Dewangan | 7d38a3c | 2012-01-20 16:36:22 +0530 | [diff] [blame] | 148 | .n_voltages = ARRAY_SIZE(VPLL_VSEL_table), |
| 149 | .voltage_table = VPLL_VSEL_table, |
Laxman Dewangan | 0651eed | 2012-03-13 11:35:20 +0530 | [diff] [blame] | 150 | .enable_time_us = 100, |
Graeme Gregory | 518fb72 | 2011-05-02 16:20:08 -0500 | [diff] [blame] | 151 | }, |
| 152 | { |
Laxman Dewangan | 33a6943 | 2012-05-19 20:04:06 +0530 | [diff] [blame] | 153 | .name = "vdac", |
Laxman Dewangan | 19228a6 | 2012-07-06 14:13:12 +0530 | [diff] [blame] | 154 | .vin_name = "vcc5", |
Laxman Dewangan | 7d38a3c | 2012-01-20 16:36:22 +0530 | [diff] [blame] | 155 | .n_voltages = ARRAY_SIZE(VDAC_VSEL_table), |
| 156 | .voltage_table = VDAC_VSEL_table, |
Laxman Dewangan | 0651eed | 2012-03-13 11:35:20 +0530 | [diff] [blame] | 157 | .enable_time_us = 100, |
Graeme Gregory | 518fb72 | 2011-05-02 16:20:08 -0500 | [diff] [blame] | 158 | }, |
| 159 | { |
Laxman Dewangan | 33a6943 | 2012-05-19 20:04:06 +0530 | [diff] [blame] | 160 | .name = "vaux1", |
Laxman Dewangan | 19228a6 | 2012-07-06 14:13:12 +0530 | [diff] [blame] | 161 | .vin_name = "vcc4", |
Laxman Dewangan | 7d38a3c | 2012-01-20 16:36:22 +0530 | [diff] [blame] | 162 | .n_voltages = ARRAY_SIZE(VAUX1_VSEL_table), |
| 163 | .voltage_table = VAUX1_VSEL_table, |
Laxman Dewangan | 0651eed | 2012-03-13 11:35:20 +0530 | [diff] [blame] | 164 | .enable_time_us = 100, |
Graeme Gregory | 518fb72 | 2011-05-02 16:20:08 -0500 | [diff] [blame] | 165 | }, |
| 166 | { |
Laxman Dewangan | 33a6943 | 2012-05-19 20:04:06 +0530 | [diff] [blame] | 167 | .name = "vaux2", |
Laxman Dewangan | 19228a6 | 2012-07-06 14:13:12 +0530 | [diff] [blame] | 168 | .vin_name = "vcc4", |
Laxman Dewangan | 7d38a3c | 2012-01-20 16:36:22 +0530 | [diff] [blame] | 169 | .n_voltages = ARRAY_SIZE(VAUX2_VSEL_table), |
| 170 | .voltage_table = VAUX2_VSEL_table, |
Laxman Dewangan | 0651eed | 2012-03-13 11:35:20 +0530 | [diff] [blame] | 171 | .enable_time_us = 100, |
Graeme Gregory | 518fb72 | 2011-05-02 16:20:08 -0500 | [diff] [blame] | 172 | }, |
| 173 | { |
Laxman Dewangan | 33a6943 | 2012-05-19 20:04:06 +0530 | [diff] [blame] | 174 | .name = "vaux33", |
Laxman Dewangan | 19228a6 | 2012-07-06 14:13:12 +0530 | [diff] [blame] | 175 | .vin_name = "vcc3", |
Laxman Dewangan | 7d38a3c | 2012-01-20 16:36:22 +0530 | [diff] [blame] | 176 | .n_voltages = ARRAY_SIZE(VAUX33_VSEL_table), |
| 177 | .voltage_table = VAUX33_VSEL_table, |
Laxman Dewangan | 0651eed | 2012-03-13 11:35:20 +0530 | [diff] [blame] | 178 | .enable_time_us = 100, |
Graeme Gregory | 518fb72 | 2011-05-02 16:20:08 -0500 | [diff] [blame] | 179 | }, |
| 180 | { |
Laxman Dewangan | 33a6943 | 2012-05-19 20:04:06 +0530 | [diff] [blame] | 181 | .name = "vmmc", |
Laxman Dewangan | 19228a6 | 2012-07-06 14:13:12 +0530 | [diff] [blame] | 182 | .vin_name = "vcc3", |
Laxman Dewangan | 7d38a3c | 2012-01-20 16:36:22 +0530 | [diff] [blame] | 183 | .n_voltages = ARRAY_SIZE(VMMC_VSEL_table), |
| 184 | .voltage_table = VMMC_VSEL_table, |
Laxman Dewangan | 0651eed | 2012-03-13 11:35:20 +0530 | [diff] [blame] | 185 | .enable_time_us = 100, |
Graeme Gregory | 518fb72 | 2011-05-02 16:20:08 -0500 | [diff] [blame] | 186 | }, |
Markus Pargmann | 03746dc | 2013-12-20 12:43:27 +0100 | [diff] [blame] | 187 | { |
| 188 | .name = "vbb", |
| 189 | .vin_name = "vcc7", |
| 190 | .n_voltages = ARRAY_SIZE(VBB_VSEL_table), |
| 191 | .voltage_table = VBB_VSEL_table, |
| 192 | }, |
Graeme Gregory | 518fb72 | 2011-05-02 16:20:08 -0500 | [diff] [blame] | 193 | }; |
| 194 | |
Jorge Eduardo Candelaria | a320e3c | 2011-05-16 18:35:03 -0500 | [diff] [blame] | 195 | static struct tps_info tps65911_regs[] = { |
| 196 | { |
Laxman Dewangan | 33a6943 | 2012-05-19 20:04:06 +0530 | [diff] [blame] | 197 | .name = "vrtc", |
Laxman Dewangan | 19228a6 | 2012-07-06 14:13:12 +0530 | [diff] [blame] | 198 | .vin_name = "vcc7", |
Laxman Dewangan | 0651eed | 2012-03-13 11:35:20 +0530 | [diff] [blame] | 199 | .enable_time_us = 2200, |
Laxman Dewangan | c2f8efd | 2012-01-18 20:46:56 +0530 | [diff] [blame] | 200 | }, |
| 201 | { |
Laxman Dewangan | 33a6943 | 2012-05-19 20:04:06 +0530 | [diff] [blame] | 202 | .name = "vio", |
Laxman Dewangan | 19228a6 | 2012-07-06 14:13:12 +0530 | [diff] [blame] | 203 | .vin_name = "vccio", |
Laxman Dewangan | 7d38a3c | 2012-01-20 16:36:22 +0530 | [diff] [blame] | 204 | .n_voltages = ARRAY_SIZE(VIO_VSEL_table), |
| 205 | .voltage_table = VIO_VSEL_table, |
Laxman Dewangan | 0651eed | 2012-03-13 11:35:20 +0530 | [diff] [blame] | 206 | .enable_time_us = 350, |
Jorge Eduardo Candelaria | a320e3c | 2011-05-16 18:35:03 -0500 | [diff] [blame] | 207 | }, |
| 208 | { |
Laxman Dewangan | 33a6943 | 2012-05-19 20:04:06 +0530 | [diff] [blame] | 209 | .name = "vdd1", |
Laxman Dewangan | 19228a6 | 2012-07-06 14:13:12 +0530 | [diff] [blame] | 210 | .vin_name = "vcc1", |
Laxman Dewangan | 7be5318 | 2012-07-09 20:27:13 +0530 | [diff] [blame] | 211 | .n_voltages = 0x4C, |
Laxman Dewangan | 0651eed | 2012-03-13 11:35:20 +0530 | [diff] [blame] | 212 | .enable_time_us = 350, |
Jorge Eduardo Candelaria | a320e3c | 2011-05-16 18:35:03 -0500 | [diff] [blame] | 213 | }, |
| 214 | { |
Laxman Dewangan | 33a6943 | 2012-05-19 20:04:06 +0530 | [diff] [blame] | 215 | .name = "vdd2", |
Laxman Dewangan | 19228a6 | 2012-07-06 14:13:12 +0530 | [diff] [blame] | 216 | .vin_name = "vcc2", |
Laxman Dewangan | 7be5318 | 2012-07-09 20:27:13 +0530 | [diff] [blame] | 217 | .n_voltages = 0x4C, |
Laxman Dewangan | 0651eed | 2012-03-13 11:35:20 +0530 | [diff] [blame] | 218 | .enable_time_us = 350, |
Jorge Eduardo Candelaria | a320e3c | 2011-05-16 18:35:03 -0500 | [diff] [blame] | 219 | }, |
| 220 | { |
Laxman Dewangan | 33a6943 | 2012-05-19 20:04:06 +0530 | [diff] [blame] | 221 | .name = "vddctrl", |
Laxman Dewangan | 7be5318 | 2012-07-09 20:27:13 +0530 | [diff] [blame] | 222 | .n_voltages = 0x44, |
Laxman Dewangan | 0651eed | 2012-03-13 11:35:20 +0530 | [diff] [blame] | 223 | .enable_time_us = 900, |
Jorge Eduardo Candelaria | a320e3c | 2011-05-16 18:35:03 -0500 | [diff] [blame] | 224 | }, |
| 225 | { |
Laxman Dewangan | 33a6943 | 2012-05-19 20:04:06 +0530 | [diff] [blame] | 226 | .name = "ldo1", |
Laxman Dewangan | 19228a6 | 2012-07-06 14:13:12 +0530 | [diff] [blame] | 227 | .vin_name = "vcc6", |
Laxman Dewangan | 7be5318 | 2012-07-09 20:27:13 +0530 | [diff] [blame] | 228 | .n_voltages = 0x33, |
Laxman Dewangan | 0651eed | 2012-03-13 11:35:20 +0530 | [diff] [blame] | 229 | .enable_time_us = 420, |
Jorge Eduardo Candelaria | a320e3c | 2011-05-16 18:35:03 -0500 | [diff] [blame] | 230 | }, |
| 231 | { |
Laxman Dewangan | 33a6943 | 2012-05-19 20:04:06 +0530 | [diff] [blame] | 232 | .name = "ldo2", |
Laxman Dewangan | 19228a6 | 2012-07-06 14:13:12 +0530 | [diff] [blame] | 233 | .vin_name = "vcc6", |
Laxman Dewangan | 7be5318 | 2012-07-09 20:27:13 +0530 | [diff] [blame] | 234 | .n_voltages = 0x33, |
Laxman Dewangan | 0651eed | 2012-03-13 11:35:20 +0530 | [diff] [blame] | 235 | .enable_time_us = 420, |
Jorge Eduardo Candelaria | a320e3c | 2011-05-16 18:35:03 -0500 | [diff] [blame] | 236 | }, |
| 237 | { |
Laxman Dewangan | 33a6943 | 2012-05-19 20:04:06 +0530 | [diff] [blame] | 238 | .name = "ldo3", |
Laxman Dewangan | 19228a6 | 2012-07-06 14:13:12 +0530 | [diff] [blame] | 239 | .vin_name = "vcc5", |
Laxman Dewangan | 7be5318 | 2012-07-09 20:27:13 +0530 | [diff] [blame] | 240 | .n_voltages = 0x1A, |
Laxman Dewangan | 0651eed | 2012-03-13 11:35:20 +0530 | [diff] [blame] | 241 | .enable_time_us = 230, |
Jorge Eduardo Candelaria | a320e3c | 2011-05-16 18:35:03 -0500 | [diff] [blame] | 242 | }, |
| 243 | { |
Laxman Dewangan | 33a6943 | 2012-05-19 20:04:06 +0530 | [diff] [blame] | 244 | .name = "ldo4", |
Laxman Dewangan | 19228a6 | 2012-07-06 14:13:12 +0530 | [diff] [blame] | 245 | .vin_name = "vcc5", |
Laxman Dewangan | 7be5318 | 2012-07-09 20:27:13 +0530 | [diff] [blame] | 246 | .n_voltages = 0x33, |
Laxman Dewangan | 0651eed | 2012-03-13 11:35:20 +0530 | [diff] [blame] | 247 | .enable_time_us = 230, |
Jorge Eduardo Candelaria | a320e3c | 2011-05-16 18:35:03 -0500 | [diff] [blame] | 248 | }, |
| 249 | { |
Laxman Dewangan | 33a6943 | 2012-05-19 20:04:06 +0530 | [diff] [blame] | 250 | .name = "ldo5", |
Laxman Dewangan | 19228a6 | 2012-07-06 14:13:12 +0530 | [diff] [blame] | 251 | .vin_name = "vcc4", |
Laxman Dewangan | 7be5318 | 2012-07-09 20:27:13 +0530 | [diff] [blame] | 252 | .n_voltages = 0x1A, |
Laxman Dewangan | 0651eed | 2012-03-13 11:35:20 +0530 | [diff] [blame] | 253 | .enable_time_us = 230, |
Jorge Eduardo Candelaria | a320e3c | 2011-05-16 18:35:03 -0500 | [diff] [blame] | 254 | }, |
| 255 | { |
Laxman Dewangan | 33a6943 | 2012-05-19 20:04:06 +0530 | [diff] [blame] | 256 | .name = "ldo6", |
Laxman Dewangan | 19228a6 | 2012-07-06 14:13:12 +0530 | [diff] [blame] | 257 | .vin_name = "vcc3", |
Laxman Dewangan | 7be5318 | 2012-07-09 20:27:13 +0530 | [diff] [blame] | 258 | .n_voltages = 0x1A, |
Laxman Dewangan | 0651eed | 2012-03-13 11:35:20 +0530 | [diff] [blame] | 259 | .enable_time_us = 230, |
Jorge Eduardo Candelaria | a320e3c | 2011-05-16 18:35:03 -0500 | [diff] [blame] | 260 | }, |
| 261 | { |
Laxman Dewangan | 33a6943 | 2012-05-19 20:04:06 +0530 | [diff] [blame] | 262 | .name = "ldo7", |
Laxman Dewangan | 19228a6 | 2012-07-06 14:13:12 +0530 | [diff] [blame] | 263 | .vin_name = "vcc3", |
Laxman Dewangan | 7be5318 | 2012-07-09 20:27:13 +0530 | [diff] [blame] | 264 | .n_voltages = 0x1A, |
Laxman Dewangan | 0651eed | 2012-03-13 11:35:20 +0530 | [diff] [blame] | 265 | .enable_time_us = 230, |
Jorge Eduardo Candelaria | a320e3c | 2011-05-16 18:35:03 -0500 | [diff] [blame] | 266 | }, |
| 267 | { |
Laxman Dewangan | 33a6943 | 2012-05-19 20:04:06 +0530 | [diff] [blame] | 268 | .name = "ldo8", |
Laxman Dewangan | 19228a6 | 2012-07-06 14:13:12 +0530 | [diff] [blame] | 269 | .vin_name = "vcc3", |
Laxman Dewangan | 7be5318 | 2012-07-09 20:27:13 +0530 | [diff] [blame] | 270 | .n_voltages = 0x1A, |
Laxman Dewangan | 0651eed | 2012-03-13 11:35:20 +0530 | [diff] [blame] | 271 | .enable_time_us = 230, |
Jorge Eduardo Candelaria | a320e3c | 2011-05-16 18:35:03 -0500 | [diff] [blame] | 272 | }, |
| 273 | }; |
| 274 | |
Laxman Dewangan | 1e0c66f | 2012-01-28 15:07:57 +0530 | [diff] [blame] | 275 | #define EXT_CONTROL_REG_BITS(id, regs_offs, bits) (((regs_offs) << 8) | (bits)) |
| 276 | static unsigned int tps65910_ext_sleep_control[] = { |
| 277 | 0, |
| 278 | EXT_CONTROL_REG_BITS(VIO, 1, 0), |
| 279 | EXT_CONTROL_REG_BITS(VDD1, 1, 1), |
| 280 | EXT_CONTROL_REG_BITS(VDD2, 1, 2), |
| 281 | EXT_CONTROL_REG_BITS(VDD3, 1, 3), |
| 282 | EXT_CONTROL_REG_BITS(VDIG1, 0, 1), |
| 283 | EXT_CONTROL_REG_BITS(VDIG2, 0, 2), |
| 284 | EXT_CONTROL_REG_BITS(VPLL, 0, 6), |
| 285 | EXT_CONTROL_REG_BITS(VDAC, 0, 7), |
| 286 | EXT_CONTROL_REG_BITS(VAUX1, 0, 3), |
| 287 | EXT_CONTROL_REG_BITS(VAUX2, 0, 4), |
| 288 | EXT_CONTROL_REG_BITS(VAUX33, 0, 5), |
| 289 | EXT_CONTROL_REG_BITS(VMMC, 0, 0), |
| 290 | }; |
| 291 | |
| 292 | static unsigned int tps65911_ext_sleep_control[] = { |
| 293 | 0, |
| 294 | EXT_CONTROL_REG_BITS(VIO, 1, 0), |
| 295 | EXT_CONTROL_REG_BITS(VDD1, 1, 1), |
| 296 | EXT_CONTROL_REG_BITS(VDD2, 1, 2), |
| 297 | EXT_CONTROL_REG_BITS(VDDCTRL, 1, 3), |
| 298 | EXT_CONTROL_REG_BITS(LDO1, 0, 1), |
| 299 | EXT_CONTROL_REG_BITS(LDO2, 0, 2), |
| 300 | EXT_CONTROL_REG_BITS(LDO3, 0, 7), |
| 301 | EXT_CONTROL_REG_BITS(LDO4, 0, 6), |
| 302 | EXT_CONTROL_REG_BITS(LDO5, 0, 3), |
| 303 | EXT_CONTROL_REG_BITS(LDO6, 0, 0), |
| 304 | EXT_CONTROL_REG_BITS(LDO7, 0, 5), |
| 305 | EXT_CONTROL_REG_BITS(LDO8, 0, 4), |
| 306 | }; |
| 307 | |
Graeme Gregory | 518fb72 | 2011-05-02 16:20:08 -0500 | [diff] [blame] | 308 | struct tps65910_reg { |
Axel Lin | 39aa9b6 | 2011-07-11 09:57:43 +0800 | [diff] [blame] | 309 | struct regulator_desc *desc; |
Graeme Gregory | 518fb72 | 2011-05-02 16:20:08 -0500 | [diff] [blame] | 310 | struct tps65910 *mfd; |
Axel Lin | 39aa9b6 | 2011-07-11 09:57:43 +0800 | [diff] [blame] | 311 | struct regulator_dev **rdev; |
| 312 | struct tps_info **info; |
Axel Lin | 39aa9b6 | 2011-07-11 09:57:43 +0800 | [diff] [blame] | 313 | int num_regulators; |
Graeme Gregory | 518fb72 | 2011-05-02 16:20:08 -0500 | [diff] [blame] | 314 | int mode; |
Jorge Eduardo Candelaria | a320e3c | 2011-05-16 18:35:03 -0500 | [diff] [blame] | 315 | int (*get_ctrl_reg)(int); |
Laxman Dewangan | 1e0c66f | 2012-01-28 15:07:57 +0530 | [diff] [blame] | 316 | unsigned int *ext_sleep_control; |
| 317 | unsigned int board_ext_control[TPS65910_NUM_REGS]; |
Graeme Gregory | 518fb72 | 2011-05-02 16:20:08 -0500 | [diff] [blame] | 318 | }; |
| 319 | |
Graeme Gregory | 518fb72 | 2011-05-02 16:20:08 -0500 | [diff] [blame] | 320 | static int tps65910_get_ctrl_register(int id) |
| 321 | { |
| 322 | switch (id) { |
| 323 | case TPS65910_REG_VRTC: |
| 324 | return TPS65910_VRTC; |
| 325 | case TPS65910_REG_VIO: |
| 326 | return TPS65910_VIO; |
| 327 | case TPS65910_REG_VDD1: |
| 328 | return TPS65910_VDD1; |
| 329 | case TPS65910_REG_VDD2: |
| 330 | return TPS65910_VDD2; |
| 331 | case TPS65910_REG_VDD3: |
| 332 | return TPS65910_VDD3; |
| 333 | case TPS65910_REG_VDIG1: |
| 334 | return TPS65910_VDIG1; |
| 335 | case TPS65910_REG_VDIG2: |
| 336 | return TPS65910_VDIG2; |
| 337 | case TPS65910_REG_VPLL: |
| 338 | return TPS65910_VPLL; |
| 339 | case TPS65910_REG_VDAC: |
| 340 | return TPS65910_VDAC; |
| 341 | case TPS65910_REG_VAUX1: |
| 342 | return TPS65910_VAUX1; |
| 343 | case TPS65910_REG_VAUX2: |
| 344 | return TPS65910_VAUX2; |
| 345 | case TPS65910_REG_VAUX33: |
| 346 | return TPS65910_VAUX33; |
| 347 | case TPS65910_REG_VMMC: |
| 348 | return TPS65910_VMMC; |
Markus Pargmann | 03746dc | 2013-12-20 12:43:27 +0100 | [diff] [blame] | 349 | case TPS65910_REG_VBB: |
| 350 | return TPS65910_BBCH; |
Graeme Gregory | 518fb72 | 2011-05-02 16:20:08 -0500 | [diff] [blame] | 351 | default: |
| 352 | return -EINVAL; |
| 353 | } |
| 354 | } |
| 355 | |
Jorge Eduardo Candelaria | a320e3c | 2011-05-16 18:35:03 -0500 | [diff] [blame] | 356 | static int tps65911_get_ctrl_register(int id) |
| 357 | { |
| 358 | switch (id) { |
| 359 | case TPS65910_REG_VRTC: |
| 360 | return TPS65910_VRTC; |
| 361 | case TPS65910_REG_VIO: |
| 362 | return TPS65910_VIO; |
| 363 | case TPS65910_REG_VDD1: |
| 364 | return TPS65910_VDD1; |
| 365 | case TPS65910_REG_VDD2: |
| 366 | return TPS65910_VDD2; |
| 367 | case TPS65911_REG_VDDCTRL: |
| 368 | return TPS65911_VDDCTRL; |
| 369 | case TPS65911_REG_LDO1: |
| 370 | return TPS65911_LDO1; |
| 371 | case TPS65911_REG_LDO2: |
| 372 | return TPS65911_LDO2; |
| 373 | case TPS65911_REG_LDO3: |
| 374 | return TPS65911_LDO3; |
| 375 | case TPS65911_REG_LDO4: |
| 376 | return TPS65911_LDO4; |
| 377 | case TPS65911_REG_LDO5: |
| 378 | return TPS65911_LDO5; |
| 379 | case TPS65911_REG_LDO6: |
| 380 | return TPS65911_LDO6; |
| 381 | case TPS65911_REG_LDO7: |
| 382 | return TPS65911_LDO7; |
| 383 | case TPS65911_REG_LDO8: |
| 384 | return TPS65911_LDO8; |
| 385 | default: |
| 386 | return -EINVAL; |
| 387 | } |
| 388 | } |
| 389 | |
Graeme Gregory | 518fb72 | 2011-05-02 16:20:08 -0500 | [diff] [blame] | 390 | static int tps65910_set_mode(struct regulator_dev *dev, unsigned int mode) |
| 391 | { |
| 392 | struct tps65910_reg *pmic = rdev_get_drvdata(dev); |
| 393 | struct tps65910 *mfd = pmic->mfd; |
| 394 | int reg, value, id = rdev_get_id(dev); |
Jorge Eduardo Candelaria | a320e3c | 2011-05-16 18:35:03 -0500 | [diff] [blame] | 395 | |
| 396 | reg = pmic->get_ctrl_reg(id); |
Graeme Gregory | 518fb72 | 2011-05-02 16:20:08 -0500 | [diff] [blame] | 397 | if (reg < 0) |
| 398 | return reg; |
| 399 | |
| 400 | switch (mode) { |
| 401 | case REGULATOR_MODE_NORMAL: |
Axel Lin | faa95fd | 2012-07-11 19:44:13 +0800 | [diff] [blame] | 402 | return tps65910_reg_update_bits(pmic->mfd, reg, |
| 403 | LDO_ST_MODE_BIT | LDO_ST_ON_BIT, |
| 404 | LDO_ST_ON_BIT); |
Graeme Gregory | 518fb72 | 2011-05-02 16:20:08 -0500 | [diff] [blame] | 405 | case REGULATOR_MODE_IDLE: |
| 406 | value = LDO_ST_ON_BIT | LDO_ST_MODE_BIT; |
Rhyland Klein | 3f7e827 | 2012-05-08 11:42:38 -0700 | [diff] [blame] | 407 | return tps65910_reg_set_bits(mfd, reg, value); |
Graeme Gregory | 518fb72 | 2011-05-02 16:20:08 -0500 | [diff] [blame] | 408 | case REGULATOR_MODE_STANDBY: |
Rhyland Klein | 3f7e827 | 2012-05-08 11:42:38 -0700 | [diff] [blame] | 409 | return tps65910_reg_clear_bits(mfd, reg, LDO_ST_ON_BIT); |
Graeme Gregory | 518fb72 | 2011-05-02 16:20:08 -0500 | [diff] [blame] | 410 | } |
| 411 | |
| 412 | return -EINVAL; |
| 413 | } |
| 414 | |
| 415 | static unsigned int tps65910_get_mode(struct regulator_dev *dev) |
| 416 | { |
| 417 | struct tps65910_reg *pmic = rdev_get_drvdata(dev); |
Axel Lin | faa95fd | 2012-07-11 19:44:13 +0800 | [diff] [blame] | 418 | int ret, reg, value, id = rdev_get_id(dev); |
Graeme Gregory | 518fb72 | 2011-05-02 16:20:08 -0500 | [diff] [blame] | 419 | |
Jorge Eduardo Candelaria | a320e3c | 2011-05-16 18:35:03 -0500 | [diff] [blame] | 420 | reg = pmic->get_ctrl_reg(id); |
Graeme Gregory | 518fb72 | 2011-05-02 16:20:08 -0500 | [diff] [blame] | 421 | if (reg < 0) |
| 422 | return reg; |
| 423 | |
Axel Lin | faa95fd | 2012-07-11 19:44:13 +0800 | [diff] [blame] | 424 | ret = tps65910_reg_read(pmic->mfd, reg, &value); |
| 425 | if (ret < 0) |
| 426 | return ret; |
Graeme Gregory | 518fb72 | 2011-05-02 16:20:08 -0500 | [diff] [blame] | 427 | |
Axel Lin | 5859939 | 2012-03-13 07:15:27 +0800 | [diff] [blame] | 428 | if (!(value & LDO_ST_ON_BIT)) |
Graeme Gregory | 518fb72 | 2011-05-02 16:20:08 -0500 | [diff] [blame] | 429 | return REGULATOR_MODE_STANDBY; |
| 430 | else if (value & LDO_ST_MODE_BIT) |
| 431 | return REGULATOR_MODE_IDLE; |
| 432 | else |
| 433 | return REGULATOR_MODE_NORMAL; |
| 434 | } |
| 435 | |
Laxman Dewangan | 18039e0 | 2012-03-14 13:00:58 +0530 | [diff] [blame] | 436 | static int tps65910_get_voltage_dcdc_sel(struct regulator_dev *dev) |
Graeme Gregory | 518fb72 | 2011-05-02 16:20:08 -0500 | [diff] [blame] | 437 | { |
| 438 | struct tps65910_reg *pmic = rdev_get_drvdata(dev); |
Axel Lin | faa95fd | 2012-07-11 19:44:13 +0800 | [diff] [blame] | 439 | int ret, id = rdev_get_id(dev); |
Jorge Eduardo Candelaria | a320e3c | 2011-05-16 18:35:03 -0500 | [diff] [blame] | 440 | int opvsel = 0, srvsel = 0, vselmax = 0, mult = 0, sr = 0; |
Graeme Gregory | 518fb72 | 2011-05-02 16:20:08 -0500 | [diff] [blame] | 441 | |
| 442 | switch (id) { |
| 443 | case TPS65910_REG_VDD1: |
Axel Lin | faa95fd | 2012-07-11 19:44:13 +0800 | [diff] [blame] | 444 | ret = tps65910_reg_read(pmic->mfd, TPS65910_VDD1_OP, &opvsel); |
| 445 | if (ret < 0) |
| 446 | return ret; |
| 447 | ret = tps65910_reg_read(pmic->mfd, TPS65910_VDD1, &mult); |
| 448 | if (ret < 0) |
| 449 | return ret; |
Graeme Gregory | 518fb72 | 2011-05-02 16:20:08 -0500 | [diff] [blame] | 450 | mult = (mult & VDD1_VGAIN_SEL_MASK) >> VDD1_VGAIN_SEL_SHIFT; |
Axel Lin | faa95fd | 2012-07-11 19:44:13 +0800 | [diff] [blame] | 451 | ret = tps65910_reg_read(pmic->mfd, TPS65910_VDD1_SR, &srvsel); |
| 452 | if (ret < 0) |
| 453 | return ret; |
Graeme Gregory | 518fb72 | 2011-05-02 16:20:08 -0500 | [diff] [blame] | 454 | sr = opvsel & VDD1_OP_CMD_MASK; |
| 455 | opvsel &= VDD1_OP_SEL_MASK; |
| 456 | srvsel &= VDD1_SR_SEL_MASK; |
Jorge Eduardo Candelaria | a320e3c | 2011-05-16 18:35:03 -0500 | [diff] [blame] | 457 | vselmax = 75; |
Graeme Gregory | 518fb72 | 2011-05-02 16:20:08 -0500 | [diff] [blame] | 458 | break; |
| 459 | case TPS65910_REG_VDD2: |
Axel Lin | faa95fd | 2012-07-11 19:44:13 +0800 | [diff] [blame] | 460 | ret = tps65910_reg_read(pmic->mfd, TPS65910_VDD2_OP, &opvsel); |
| 461 | if (ret < 0) |
| 462 | return ret; |
| 463 | ret = tps65910_reg_read(pmic->mfd, TPS65910_VDD2, &mult); |
| 464 | if (ret < 0) |
| 465 | return ret; |
Graeme Gregory | 518fb72 | 2011-05-02 16:20:08 -0500 | [diff] [blame] | 466 | mult = (mult & VDD2_VGAIN_SEL_MASK) >> VDD2_VGAIN_SEL_SHIFT; |
Axel Lin | faa95fd | 2012-07-11 19:44:13 +0800 | [diff] [blame] | 467 | ret = tps65910_reg_read(pmic->mfd, TPS65910_VDD2_SR, &srvsel); |
| 468 | if (ret < 0) |
| 469 | return ret; |
Graeme Gregory | 518fb72 | 2011-05-02 16:20:08 -0500 | [diff] [blame] | 470 | sr = opvsel & VDD2_OP_CMD_MASK; |
| 471 | opvsel &= VDD2_OP_SEL_MASK; |
| 472 | srvsel &= VDD2_SR_SEL_MASK; |
Jorge Eduardo Candelaria | a320e3c | 2011-05-16 18:35:03 -0500 | [diff] [blame] | 473 | vselmax = 75; |
| 474 | break; |
| 475 | case TPS65911_REG_VDDCTRL: |
Axel Lin | faa95fd | 2012-07-11 19:44:13 +0800 | [diff] [blame] | 476 | ret = tps65910_reg_read(pmic->mfd, TPS65911_VDDCTRL_OP, |
| 477 | &opvsel); |
| 478 | if (ret < 0) |
| 479 | return ret; |
| 480 | ret = tps65910_reg_read(pmic->mfd, TPS65911_VDDCTRL_SR, |
| 481 | &srvsel); |
| 482 | if (ret < 0) |
| 483 | return ret; |
Jorge Eduardo Candelaria | a320e3c | 2011-05-16 18:35:03 -0500 | [diff] [blame] | 484 | sr = opvsel & VDDCTRL_OP_CMD_MASK; |
| 485 | opvsel &= VDDCTRL_OP_SEL_MASK; |
| 486 | srvsel &= VDDCTRL_SR_SEL_MASK; |
| 487 | vselmax = 64; |
Graeme Gregory | 518fb72 | 2011-05-02 16:20:08 -0500 | [diff] [blame] | 488 | break; |
| 489 | } |
| 490 | |
| 491 | /* multiplier 0 == 1 but 2,3 normal */ |
| 492 | if (!mult) |
Jingoo Han | 4b57927 | 2013-10-14 17:53:40 +0900 | [diff] [blame] | 493 | mult = 1; |
Graeme Gregory | 518fb72 | 2011-05-02 16:20:08 -0500 | [diff] [blame] | 494 | |
| 495 | if (sr) { |
Jorge Eduardo Candelaria | a320e3c | 2011-05-16 18:35:03 -0500 | [diff] [blame] | 496 | /* normalise to valid range */ |
| 497 | if (srvsel < 3) |
| 498 | srvsel = 3; |
| 499 | if (srvsel > vselmax) |
| 500 | srvsel = vselmax; |
Laxman Dewangan | 18039e0 | 2012-03-14 13:00:58 +0530 | [diff] [blame] | 501 | return srvsel - 3; |
Graeme Gregory | 518fb72 | 2011-05-02 16:20:08 -0500 | [diff] [blame] | 502 | } else { |
| 503 | |
Jorge Eduardo Candelaria | a320e3c | 2011-05-16 18:35:03 -0500 | [diff] [blame] | 504 | /* normalise to valid range*/ |
| 505 | if (opvsel < 3) |
| 506 | opvsel = 3; |
| 507 | if (opvsel > vselmax) |
| 508 | opvsel = vselmax; |
Laxman Dewangan | 18039e0 | 2012-03-14 13:00:58 +0530 | [diff] [blame] | 509 | return opvsel - 3; |
Graeme Gregory | 518fb72 | 2011-05-02 16:20:08 -0500 | [diff] [blame] | 510 | } |
Laxman Dewangan | 18039e0 | 2012-03-14 13:00:58 +0530 | [diff] [blame] | 511 | return -EINVAL; |
Graeme Gregory | 518fb72 | 2011-05-02 16:20:08 -0500 | [diff] [blame] | 512 | } |
| 513 | |
Axel Lin | 1f904fd | 2012-05-09 09:22:47 +0800 | [diff] [blame] | 514 | static int tps65910_get_voltage_sel(struct regulator_dev *dev) |
Graeme Gregory | 518fb72 | 2011-05-02 16:20:08 -0500 | [diff] [blame] | 515 | { |
| 516 | struct tps65910_reg *pmic = rdev_get_drvdata(dev); |
Axel Lin | faa95fd | 2012-07-11 19:44:13 +0800 | [diff] [blame] | 517 | int ret, reg, value, id = rdev_get_id(dev); |
Graeme Gregory | 518fb72 | 2011-05-02 16:20:08 -0500 | [diff] [blame] | 518 | |
Jorge Eduardo Candelaria | a320e3c | 2011-05-16 18:35:03 -0500 | [diff] [blame] | 519 | reg = pmic->get_ctrl_reg(id); |
Graeme Gregory | 518fb72 | 2011-05-02 16:20:08 -0500 | [diff] [blame] | 520 | if (reg < 0) |
| 521 | return reg; |
| 522 | |
Axel Lin | faa95fd | 2012-07-11 19:44:13 +0800 | [diff] [blame] | 523 | ret = tps65910_reg_read(pmic->mfd, reg, &value); |
| 524 | if (ret < 0) |
| 525 | return ret; |
Graeme Gregory | 518fb72 | 2011-05-02 16:20:08 -0500 | [diff] [blame] | 526 | |
| 527 | switch (id) { |
| 528 | case TPS65910_REG_VIO: |
| 529 | case TPS65910_REG_VDIG1: |
| 530 | case TPS65910_REG_VDIG2: |
| 531 | case TPS65910_REG_VPLL: |
| 532 | case TPS65910_REG_VDAC: |
| 533 | case TPS65910_REG_VAUX1: |
| 534 | case TPS65910_REG_VAUX2: |
| 535 | case TPS65910_REG_VAUX33: |
| 536 | case TPS65910_REG_VMMC: |
| 537 | value &= LDO_SEL_MASK; |
| 538 | value >>= LDO_SEL_SHIFT; |
| 539 | break; |
Markus Pargmann | 03746dc | 2013-12-20 12:43:27 +0100 | [diff] [blame] | 540 | case TPS65910_REG_VBB: |
| 541 | value &= BBCH_BBSEL_MASK; |
| 542 | value >>= BBCH_BBSEL_SHIFT; |
| 543 | break; |
Graeme Gregory | 518fb72 | 2011-05-02 16:20:08 -0500 | [diff] [blame] | 544 | default: |
| 545 | return -EINVAL; |
| 546 | } |
| 547 | |
Axel Lin | 1f904fd | 2012-05-09 09:22:47 +0800 | [diff] [blame] | 548 | return value; |
Graeme Gregory | 518fb72 | 2011-05-02 16:20:08 -0500 | [diff] [blame] | 549 | } |
| 550 | |
| 551 | static int tps65910_get_voltage_vdd3(struct regulator_dev *dev) |
| 552 | { |
Axel Lin | d9fe28f | 2012-06-21 18:48:00 +0800 | [diff] [blame] | 553 | return dev->desc->volt_table[0]; |
Graeme Gregory | 518fb72 | 2011-05-02 16:20:08 -0500 | [diff] [blame] | 554 | } |
| 555 | |
Axel Lin | 1f904fd | 2012-05-09 09:22:47 +0800 | [diff] [blame] | 556 | static int tps65911_get_voltage_sel(struct regulator_dev *dev) |
Jorge Eduardo Candelaria | a320e3c | 2011-05-16 18:35:03 -0500 | [diff] [blame] | 557 | { |
| 558 | struct tps65910_reg *pmic = rdev_get_drvdata(dev); |
Axel Lin | faa95fd | 2012-07-11 19:44:13 +0800 | [diff] [blame] | 559 | int ret, id = rdev_get_id(dev); |
| 560 | unsigned int value, reg; |
Jorge Eduardo Candelaria | a320e3c | 2011-05-16 18:35:03 -0500 | [diff] [blame] | 561 | |
| 562 | reg = pmic->get_ctrl_reg(id); |
| 563 | |
Axel Lin | faa95fd | 2012-07-11 19:44:13 +0800 | [diff] [blame] | 564 | ret = tps65910_reg_read(pmic->mfd, reg, &value); |
| 565 | if (ret < 0) |
| 566 | return ret; |
Jorge Eduardo Candelaria | a320e3c | 2011-05-16 18:35:03 -0500 | [diff] [blame] | 567 | |
| 568 | switch (id) { |
| 569 | case TPS65911_REG_LDO1: |
| 570 | case TPS65911_REG_LDO2: |
| 571 | case TPS65911_REG_LDO4: |
| 572 | value &= LDO1_SEL_MASK; |
| 573 | value >>= LDO_SEL_SHIFT; |
Jorge Eduardo Candelaria | a320e3c | 2011-05-16 18:35:03 -0500 | [diff] [blame] | 574 | break; |
| 575 | case TPS65911_REG_LDO3: |
| 576 | case TPS65911_REG_LDO5: |
| 577 | case TPS65911_REG_LDO6: |
| 578 | case TPS65911_REG_LDO7: |
| 579 | case TPS65911_REG_LDO8: |
| 580 | value &= LDO3_SEL_MASK; |
| 581 | value >>= LDO_SEL_SHIFT; |
Jorge Eduardo Candelaria | a320e3c | 2011-05-16 18:35:03 -0500 | [diff] [blame] | 582 | break; |
| 583 | case TPS65910_REG_VIO: |
Laxman Dewangan | e882eae | 2012-02-17 18:56:11 +0530 | [diff] [blame] | 584 | value &= LDO_SEL_MASK; |
| 585 | value >>= LDO_SEL_SHIFT; |
Axel Lin | 1f904fd | 2012-05-09 09:22:47 +0800 | [diff] [blame] | 586 | break; |
Jorge Eduardo Candelaria | a320e3c | 2011-05-16 18:35:03 -0500 | [diff] [blame] | 587 | default: |
| 588 | return -EINVAL; |
| 589 | } |
| 590 | |
Axel Lin | 1f904fd | 2012-05-09 09:22:47 +0800 | [diff] [blame] | 591 | return value; |
Jorge Eduardo Candelaria | a320e3c | 2011-05-16 18:35:03 -0500 | [diff] [blame] | 592 | } |
| 593 | |
Axel Lin | 94732b9 | 2012-03-09 10:22:20 +0800 | [diff] [blame] | 594 | static int tps65910_set_voltage_dcdc_sel(struct regulator_dev *dev, |
| 595 | unsigned selector) |
Graeme Gregory | 518fb72 | 2011-05-02 16:20:08 -0500 | [diff] [blame] | 596 | { |
| 597 | struct tps65910_reg *pmic = rdev_get_drvdata(dev); |
| 598 | int id = rdev_get_id(dev), vsel; |
Jorge Eduardo Candelaria | a320e3c | 2011-05-16 18:35:03 -0500 | [diff] [blame] | 599 | int dcdc_mult = 0; |
Graeme Gregory | 518fb72 | 2011-05-02 16:20:08 -0500 | [diff] [blame] | 600 | |
Jorge Eduardo Candelaria | a320e3c | 2011-05-16 18:35:03 -0500 | [diff] [blame] | 601 | switch (id) { |
| 602 | case TPS65910_REG_VDD1: |
Afzal Mohammed | 780dc9b | 2011-11-08 18:54:10 +0530 | [diff] [blame] | 603 | dcdc_mult = (selector / VDD1_2_NUM_VOLT_FINE) + 1; |
Jorge Eduardo Candelaria | a320e3c | 2011-05-16 18:35:03 -0500 | [diff] [blame] | 604 | if (dcdc_mult == 1) |
| 605 | dcdc_mult--; |
Afzal Mohammed | 780dc9b | 2011-11-08 18:54:10 +0530 | [diff] [blame] | 606 | vsel = (selector % VDD1_2_NUM_VOLT_FINE) + 3; |
Graeme Gregory | 518fb72 | 2011-05-02 16:20:08 -0500 | [diff] [blame] | 607 | |
Axel Lin | faa95fd | 2012-07-11 19:44:13 +0800 | [diff] [blame] | 608 | tps65910_reg_update_bits(pmic->mfd, TPS65910_VDD1, |
| 609 | VDD1_VGAIN_SEL_MASK, |
| 610 | dcdc_mult << VDD1_VGAIN_SEL_SHIFT); |
| 611 | tps65910_reg_write(pmic->mfd, TPS65910_VDD1_OP, vsel); |
Jorge Eduardo Candelaria | a320e3c | 2011-05-16 18:35:03 -0500 | [diff] [blame] | 612 | break; |
| 613 | case TPS65910_REG_VDD2: |
Afzal Mohammed | 780dc9b | 2011-11-08 18:54:10 +0530 | [diff] [blame] | 614 | dcdc_mult = (selector / VDD1_2_NUM_VOLT_FINE) + 1; |
Jorge Eduardo Candelaria | a320e3c | 2011-05-16 18:35:03 -0500 | [diff] [blame] | 615 | if (dcdc_mult == 1) |
| 616 | dcdc_mult--; |
Afzal Mohammed | 780dc9b | 2011-11-08 18:54:10 +0530 | [diff] [blame] | 617 | vsel = (selector % VDD1_2_NUM_VOLT_FINE) + 3; |
Jorge Eduardo Candelaria | a320e3c | 2011-05-16 18:35:03 -0500 | [diff] [blame] | 618 | |
Axel Lin | faa95fd | 2012-07-11 19:44:13 +0800 | [diff] [blame] | 619 | tps65910_reg_update_bits(pmic->mfd, TPS65910_VDD2, |
| 620 | VDD1_VGAIN_SEL_MASK, |
| 621 | dcdc_mult << VDD2_VGAIN_SEL_SHIFT); |
| 622 | tps65910_reg_write(pmic->mfd, TPS65910_VDD2_OP, vsel); |
Jorge Eduardo Candelaria | a320e3c | 2011-05-16 18:35:03 -0500 | [diff] [blame] | 623 | break; |
| 624 | case TPS65911_REG_VDDCTRL: |
Laxman Dewangan | c4632ae | 2012-03-07 16:39:05 +0530 | [diff] [blame] | 625 | vsel = selector + 3; |
Axel Lin | faa95fd | 2012-07-11 19:44:13 +0800 | [diff] [blame] | 626 | tps65910_reg_write(pmic->mfd, TPS65911_VDDCTRL_OP, vsel); |
Graeme Gregory | 518fb72 | 2011-05-02 16:20:08 -0500 | [diff] [blame] | 627 | } |
| 628 | |
| 629 | return 0; |
| 630 | } |
| 631 | |
Axel Lin | 94732b9 | 2012-03-09 10:22:20 +0800 | [diff] [blame] | 632 | static int tps65910_set_voltage_sel(struct regulator_dev *dev, |
| 633 | unsigned selector) |
Graeme Gregory | 518fb72 | 2011-05-02 16:20:08 -0500 | [diff] [blame] | 634 | { |
| 635 | struct tps65910_reg *pmic = rdev_get_drvdata(dev); |
| 636 | int reg, id = rdev_get_id(dev); |
| 637 | |
Jorge Eduardo Candelaria | a320e3c | 2011-05-16 18:35:03 -0500 | [diff] [blame] | 638 | reg = pmic->get_ctrl_reg(id); |
Graeme Gregory | 518fb72 | 2011-05-02 16:20:08 -0500 | [diff] [blame] | 639 | if (reg < 0) |
| 640 | return reg; |
| 641 | |
| 642 | switch (id) { |
| 643 | case TPS65910_REG_VIO: |
| 644 | case TPS65910_REG_VDIG1: |
| 645 | case TPS65910_REG_VDIG2: |
| 646 | case TPS65910_REG_VPLL: |
| 647 | case TPS65910_REG_VDAC: |
| 648 | case TPS65910_REG_VAUX1: |
| 649 | case TPS65910_REG_VAUX2: |
| 650 | case TPS65910_REG_VAUX33: |
| 651 | case TPS65910_REG_VMMC: |
Axel Lin | faa95fd | 2012-07-11 19:44:13 +0800 | [diff] [blame] | 652 | return tps65910_reg_update_bits(pmic->mfd, reg, LDO_SEL_MASK, |
| 653 | selector << LDO_SEL_SHIFT); |
Markus Pargmann | 03746dc | 2013-12-20 12:43:27 +0100 | [diff] [blame] | 654 | case TPS65910_REG_VBB: |
| 655 | return tps65910_reg_update_bits(pmic->mfd, reg, BBCH_BBSEL_MASK, |
| 656 | selector << BBCH_BBSEL_SHIFT); |
Graeme Gregory | 518fb72 | 2011-05-02 16:20:08 -0500 | [diff] [blame] | 657 | } |
| 658 | |
| 659 | return -EINVAL; |
| 660 | } |
| 661 | |
Axel Lin | 94732b9 | 2012-03-09 10:22:20 +0800 | [diff] [blame] | 662 | static int tps65911_set_voltage_sel(struct regulator_dev *dev, |
| 663 | unsigned selector) |
Jorge Eduardo Candelaria | a320e3c | 2011-05-16 18:35:03 -0500 | [diff] [blame] | 664 | { |
| 665 | struct tps65910_reg *pmic = rdev_get_drvdata(dev); |
| 666 | int reg, id = rdev_get_id(dev); |
| 667 | |
| 668 | reg = pmic->get_ctrl_reg(id); |
| 669 | if (reg < 0) |
| 670 | return reg; |
| 671 | |
| 672 | switch (id) { |
| 673 | case TPS65911_REG_LDO1: |
| 674 | case TPS65911_REG_LDO2: |
| 675 | case TPS65911_REG_LDO4: |
Axel Lin | faa95fd | 2012-07-11 19:44:13 +0800 | [diff] [blame] | 676 | return tps65910_reg_update_bits(pmic->mfd, reg, LDO1_SEL_MASK, |
| 677 | selector << LDO_SEL_SHIFT); |
Jorge Eduardo Candelaria | a320e3c | 2011-05-16 18:35:03 -0500 | [diff] [blame] | 678 | case TPS65911_REG_LDO3: |
| 679 | case TPS65911_REG_LDO5: |
| 680 | case TPS65911_REG_LDO6: |
| 681 | case TPS65911_REG_LDO7: |
| 682 | case TPS65911_REG_LDO8: |
Axel Lin | faa95fd | 2012-07-11 19:44:13 +0800 | [diff] [blame] | 683 | return tps65910_reg_update_bits(pmic->mfd, reg, LDO3_SEL_MASK, |
| 684 | selector << LDO_SEL_SHIFT); |
Laxman Dewangan | e882eae | 2012-02-17 18:56:11 +0530 | [diff] [blame] | 685 | case TPS65910_REG_VIO: |
Axel Lin | faa95fd | 2012-07-11 19:44:13 +0800 | [diff] [blame] | 686 | return tps65910_reg_update_bits(pmic->mfd, reg, LDO_SEL_MASK, |
| 687 | selector << LDO_SEL_SHIFT); |
Markus Pargmann | 03746dc | 2013-12-20 12:43:27 +0100 | [diff] [blame] | 688 | case TPS65910_REG_VBB: |
| 689 | return tps65910_reg_update_bits(pmic->mfd, reg, BBCH_BBSEL_MASK, |
| 690 | selector << BBCH_BBSEL_SHIFT); |
Jorge Eduardo Candelaria | a320e3c | 2011-05-16 18:35:03 -0500 | [diff] [blame] | 691 | } |
| 692 | |
| 693 | return -EINVAL; |
| 694 | } |
| 695 | |
| 696 | |
Graeme Gregory | 518fb72 | 2011-05-02 16:20:08 -0500 | [diff] [blame] | 697 | static int tps65910_list_voltage_dcdc(struct regulator_dev *dev, |
| 698 | unsigned selector) |
| 699 | { |
Jorge Eduardo Candelaria | a320e3c | 2011-05-16 18:35:03 -0500 | [diff] [blame] | 700 | int volt, mult = 1, id = rdev_get_id(dev); |
Graeme Gregory | 518fb72 | 2011-05-02 16:20:08 -0500 | [diff] [blame] | 701 | |
Jorge Eduardo Candelaria | a320e3c | 2011-05-16 18:35:03 -0500 | [diff] [blame] | 702 | switch (id) { |
| 703 | case TPS65910_REG_VDD1: |
| 704 | case TPS65910_REG_VDD2: |
Afzal Mohammed | 780dc9b | 2011-11-08 18:54:10 +0530 | [diff] [blame] | 705 | mult = (selector / VDD1_2_NUM_VOLT_FINE) + 1; |
Jorge Eduardo Candelaria | a320e3c | 2011-05-16 18:35:03 -0500 | [diff] [blame] | 706 | volt = VDD1_2_MIN_VOLT + |
Jingoo Han | 4b57927 | 2013-10-14 17:53:40 +0900 | [diff] [blame] | 707 | (selector % VDD1_2_NUM_VOLT_FINE) * VDD1_2_OFFSET; |
Axel Lin | d04156b | 2011-07-10 21:44:09 +0800 | [diff] [blame] | 708 | break; |
Jorge Eduardo Candelaria | a320e3c | 2011-05-16 18:35:03 -0500 | [diff] [blame] | 709 | case TPS65911_REG_VDDCTRL: |
| 710 | volt = VDDCTRL_MIN_VOLT + (selector * VDDCTRL_OFFSET); |
Axel Lin | d04156b | 2011-07-10 21:44:09 +0800 | [diff] [blame] | 711 | break; |
| 712 | default: |
| 713 | BUG(); |
| 714 | return -EINVAL; |
Jorge Eduardo Candelaria | a320e3c | 2011-05-16 18:35:03 -0500 | [diff] [blame] | 715 | } |
Graeme Gregory | 518fb72 | 2011-05-02 16:20:08 -0500 | [diff] [blame] | 716 | |
| 717 | return volt * 100 * mult; |
| 718 | } |
| 719 | |
Jorge Eduardo Candelaria | a320e3c | 2011-05-16 18:35:03 -0500 | [diff] [blame] | 720 | static int tps65911_list_voltage(struct regulator_dev *dev, unsigned selector) |
| 721 | { |
| 722 | struct tps65910_reg *pmic = rdev_get_drvdata(dev); |
| 723 | int step_mv = 0, id = rdev_get_id(dev); |
| 724 | |
Jingoo Han | 4b57927 | 2013-10-14 17:53:40 +0900 | [diff] [blame] | 725 | switch (id) { |
Jorge Eduardo Candelaria | a320e3c | 2011-05-16 18:35:03 -0500 | [diff] [blame] | 726 | case TPS65911_REG_LDO1: |
| 727 | case TPS65911_REG_LDO2: |
| 728 | case TPS65911_REG_LDO4: |
| 729 | /* The first 5 values of the selector correspond to 1V */ |
| 730 | if (selector < 5) |
| 731 | selector = 0; |
| 732 | else |
| 733 | selector -= 4; |
| 734 | |
| 735 | step_mv = 50; |
| 736 | break; |
| 737 | case TPS65911_REG_LDO3: |
| 738 | case TPS65911_REG_LDO5: |
| 739 | case TPS65911_REG_LDO6: |
| 740 | case TPS65911_REG_LDO7: |
| 741 | case TPS65911_REG_LDO8: |
| 742 | /* The first 3 values of the selector correspond to 1V */ |
| 743 | if (selector < 3) |
| 744 | selector = 0; |
| 745 | else |
| 746 | selector -= 2; |
| 747 | |
| 748 | step_mv = 100; |
| 749 | break; |
| 750 | case TPS65910_REG_VIO: |
Axel Lin | d9fe28f | 2012-06-21 18:48:00 +0800 | [diff] [blame] | 751 | return pmic->info[id]->voltage_table[selector]; |
Jorge Eduardo Candelaria | a320e3c | 2011-05-16 18:35:03 -0500 | [diff] [blame] | 752 | default: |
| 753 | return -EINVAL; |
| 754 | } |
| 755 | |
| 756 | return (LDO_MIN_VOLT + selector * step_mv) * 1000; |
| 757 | } |
| 758 | |
Graeme Gregory | 518fb72 | 2011-05-02 16:20:08 -0500 | [diff] [blame] | 759 | /* Regulator ops (except VRTC) */ |
| 760 | static struct regulator_ops tps65910_ops_dcdc = { |
Axel Lin | a40a9c4 | 2012-04-17 14:34:46 +0800 | [diff] [blame] | 761 | .is_enabled = regulator_is_enabled_regmap, |
| 762 | .enable = regulator_enable_regmap, |
| 763 | .disable = regulator_disable_regmap, |
Graeme Gregory | 518fb72 | 2011-05-02 16:20:08 -0500 | [diff] [blame] | 764 | .set_mode = tps65910_set_mode, |
| 765 | .get_mode = tps65910_get_mode, |
Laxman Dewangan | 18039e0 | 2012-03-14 13:00:58 +0530 | [diff] [blame] | 766 | .get_voltage_sel = tps65910_get_voltage_dcdc_sel, |
Axel Lin | 94732b9 | 2012-03-09 10:22:20 +0800 | [diff] [blame] | 767 | .set_voltage_sel = tps65910_set_voltage_dcdc_sel, |
Axel Lin | 01bc3a1 | 2012-06-20 22:40:10 +0800 | [diff] [blame] | 768 | .set_voltage_time_sel = regulator_set_voltage_time_sel, |
Graeme Gregory | 518fb72 | 2011-05-02 16:20:08 -0500 | [diff] [blame] | 769 | .list_voltage = tps65910_list_voltage_dcdc, |
Axel Lin | 9fa8175 | 2013-04-20 10:30:17 +0800 | [diff] [blame] | 770 | .map_voltage = regulator_map_voltage_ascend, |
Graeme Gregory | 518fb72 | 2011-05-02 16:20:08 -0500 | [diff] [blame] | 771 | }; |
| 772 | |
| 773 | static struct regulator_ops tps65910_ops_vdd3 = { |
Axel Lin | a40a9c4 | 2012-04-17 14:34:46 +0800 | [diff] [blame] | 774 | .is_enabled = regulator_is_enabled_regmap, |
| 775 | .enable = regulator_enable_regmap, |
| 776 | .disable = regulator_disable_regmap, |
Graeme Gregory | 518fb72 | 2011-05-02 16:20:08 -0500 | [diff] [blame] | 777 | .set_mode = tps65910_set_mode, |
| 778 | .get_mode = tps65910_get_mode, |
| 779 | .get_voltage = tps65910_get_voltage_vdd3, |
Axel Lin | d9fe28f | 2012-06-21 18:48:00 +0800 | [diff] [blame] | 780 | .list_voltage = regulator_list_voltage_table, |
Axel Lin | 9fa8175 | 2013-04-20 10:30:17 +0800 | [diff] [blame] | 781 | .map_voltage = regulator_map_voltage_ascend, |
Graeme Gregory | 518fb72 | 2011-05-02 16:20:08 -0500 | [diff] [blame] | 782 | }; |
| 783 | |
Markus Pargmann | 03746dc | 2013-12-20 12:43:27 +0100 | [diff] [blame] | 784 | static struct regulator_ops tps65910_ops_vbb = { |
| 785 | .is_enabled = regulator_is_enabled_regmap, |
| 786 | .enable = regulator_enable_regmap, |
| 787 | .disable = regulator_disable_regmap, |
| 788 | .set_mode = tps65910_set_mode, |
| 789 | .get_mode = tps65910_get_mode, |
| 790 | .get_voltage_sel = tps65910_get_voltage_sel, |
| 791 | .set_voltage_sel = tps65910_set_voltage_sel, |
| 792 | .list_voltage = regulator_list_voltage_table, |
| 793 | .map_voltage = regulator_map_voltage_iterate, |
| 794 | }; |
| 795 | |
Graeme Gregory | 518fb72 | 2011-05-02 16:20:08 -0500 | [diff] [blame] | 796 | static struct regulator_ops tps65910_ops = { |
Axel Lin | a40a9c4 | 2012-04-17 14:34:46 +0800 | [diff] [blame] | 797 | .is_enabled = regulator_is_enabled_regmap, |
| 798 | .enable = regulator_enable_regmap, |
| 799 | .disable = regulator_disable_regmap, |
Graeme Gregory | 518fb72 | 2011-05-02 16:20:08 -0500 | [diff] [blame] | 800 | .set_mode = tps65910_set_mode, |
| 801 | .get_mode = tps65910_get_mode, |
Axel Lin | 1f904fd | 2012-05-09 09:22:47 +0800 | [diff] [blame] | 802 | .get_voltage_sel = tps65910_get_voltage_sel, |
Axel Lin | 94732b9 | 2012-03-09 10:22:20 +0800 | [diff] [blame] | 803 | .set_voltage_sel = tps65910_set_voltage_sel, |
Axel Lin | d9fe28f | 2012-06-21 18:48:00 +0800 | [diff] [blame] | 804 | .list_voltage = regulator_list_voltage_table, |
Axel Lin | 9fa8175 | 2013-04-20 10:30:17 +0800 | [diff] [blame] | 805 | .map_voltage = regulator_map_voltage_ascend, |
Graeme Gregory | 518fb72 | 2011-05-02 16:20:08 -0500 | [diff] [blame] | 806 | }; |
| 807 | |
Jorge Eduardo Candelaria | a320e3c | 2011-05-16 18:35:03 -0500 | [diff] [blame] | 808 | static struct regulator_ops tps65911_ops = { |
Axel Lin | a40a9c4 | 2012-04-17 14:34:46 +0800 | [diff] [blame] | 809 | .is_enabled = regulator_is_enabled_regmap, |
| 810 | .enable = regulator_enable_regmap, |
| 811 | .disable = regulator_disable_regmap, |
Jorge Eduardo Candelaria | a320e3c | 2011-05-16 18:35:03 -0500 | [diff] [blame] | 812 | .set_mode = tps65910_set_mode, |
| 813 | .get_mode = tps65910_get_mode, |
Axel Lin | 1f904fd | 2012-05-09 09:22:47 +0800 | [diff] [blame] | 814 | .get_voltage_sel = tps65911_get_voltage_sel, |
Axel Lin | 94732b9 | 2012-03-09 10:22:20 +0800 | [diff] [blame] | 815 | .set_voltage_sel = tps65911_set_voltage_sel, |
Jorge Eduardo Candelaria | a320e3c | 2011-05-16 18:35:03 -0500 | [diff] [blame] | 816 | .list_voltage = tps65911_list_voltage, |
Axel Lin | 9fa8175 | 2013-04-20 10:30:17 +0800 | [diff] [blame] | 817 | .map_voltage = regulator_map_voltage_ascend, |
Jorge Eduardo Candelaria | a320e3c | 2011-05-16 18:35:03 -0500 | [diff] [blame] | 818 | }; |
| 819 | |
Laxman Dewangan | 1e0c66f | 2012-01-28 15:07:57 +0530 | [diff] [blame] | 820 | static int tps65910_set_ext_sleep_config(struct tps65910_reg *pmic, |
| 821 | int id, int ext_sleep_config) |
| 822 | { |
| 823 | struct tps65910 *mfd = pmic->mfd; |
| 824 | u8 regoffs = (pmic->ext_sleep_control[id] >> 8) & 0xFF; |
| 825 | u8 bit_pos = (1 << pmic->ext_sleep_control[id] & 0xFF); |
| 826 | int ret; |
| 827 | |
| 828 | /* |
| 829 | * Regulator can not be control from multiple external input EN1, EN2 |
| 830 | * and EN3 together. |
| 831 | */ |
| 832 | if (ext_sleep_config & EXT_SLEEP_CONTROL) { |
| 833 | int en_count; |
| 834 | en_count = ((ext_sleep_config & |
| 835 | TPS65910_SLEEP_CONTROL_EXT_INPUT_EN1) != 0); |
| 836 | en_count += ((ext_sleep_config & |
| 837 | TPS65910_SLEEP_CONTROL_EXT_INPUT_EN2) != 0); |
| 838 | en_count += ((ext_sleep_config & |
| 839 | TPS65910_SLEEP_CONTROL_EXT_INPUT_EN3) != 0); |
Laxman Dewangan | f30b071 | 2012-03-07 18:21:49 +0530 | [diff] [blame] | 840 | en_count += ((ext_sleep_config & |
| 841 | TPS65911_SLEEP_CONTROL_EXT_INPUT_SLEEP) != 0); |
Laxman Dewangan | 1e0c66f | 2012-01-28 15:07:57 +0530 | [diff] [blame] | 842 | if (en_count > 1) { |
| 843 | dev_err(mfd->dev, |
| 844 | "External sleep control flag is not proper\n"); |
| 845 | return -EINVAL; |
| 846 | } |
| 847 | } |
| 848 | |
| 849 | pmic->board_ext_control[id] = ext_sleep_config; |
| 850 | |
| 851 | /* External EN1 control */ |
| 852 | if (ext_sleep_config & TPS65910_SLEEP_CONTROL_EXT_INPUT_EN1) |
Rhyland Klein | 3f7e827 | 2012-05-08 11:42:38 -0700 | [diff] [blame] | 853 | ret = tps65910_reg_set_bits(mfd, |
Laxman Dewangan | 1e0c66f | 2012-01-28 15:07:57 +0530 | [diff] [blame] | 854 | TPS65910_EN1_LDO_ASS + regoffs, bit_pos); |
| 855 | else |
Rhyland Klein | 3f7e827 | 2012-05-08 11:42:38 -0700 | [diff] [blame] | 856 | ret = tps65910_reg_clear_bits(mfd, |
Laxman Dewangan | 1e0c66f | 2012-01-28 15:07:57 +0530 | [diff] [blame] | 857 | TPS65910_EN1_LDO_ASS + regoffs, bit_pos); |
| 858 | if (ret < 0) { |
| 859 | dev_err(mfd->dev, |
| 860 | "Error in configuring external control EN1\n"); |
| 861 | return ret; |
| 862 | } |
| 863 | |
| 864 | /* External EN2 control */ |
| 865 | if (ext_sleep_config & TPS65910_SLEEP_CONTROL_EXT_INPUT_EN2) |
Rhyland Klein | 3f7e827 | 2012-05-08 11:42:38 -0700 | [diff] [blame] | 866 | ret = tps65910_reg_set_bits(mfd, |
Laxman Dewangan | 1e0c66f | 2012-01-28 15:07:57 +0530 | [diff] [blame] | 867 | TPS65910_EN2_LDO_ASS + regoffs, bit_pos); |
| 868 | else |
Rhyland Klein | 3f7e827 | 2012-05-08 11:42:38 -0700 | [diff] [blame] | 869 | ret = tps65910_reg_clear_bits(mfd, |
Laxman Dewangan | 1e0c66f | 2012-01-28 15:07:57 +0530 | [diff] [blame] | 870 | TPS65910_EN2_LDO_ASS + regoffs, bit_pos); |
| 871 | if (ret < 0) { |
| 872 | dev_err(mfd->dev, |
| 873 | "Error in configuring external control EN2\n"); |
| 874 | return ret; |
| 875 | } |
| 876 | |
| 877 | /* External EN3 control for TPS65910 LDO only */ |
| 878 | if ((tps65910_chip_id(mfd) == TPS65910) && |
| 879 | (id >= TPS65910_REG_VDIG1)) { |
| 880 | if (ext_sleep_config & TPS65910_SLEEP_CONTROL_EXT_INPUT_EN3) |
Rhyland Klein | 3f7e827 | 2012-05-08 11:42:38 -0700 | [diff] [blame] | 881 | ret = tps65910_reg_set_bits(mfd, |
Laxman Dewangan | 1e0c66f | 2012-01-28 15:07:57 +0530 | [diff] [blame] | 882 | TPS65910_EN3_LDO_ASS + regoffs, bit_pos); |
| 883 | else |
Rhyland Klein | 3f7e827 | 2012-05-08 11:42:38 -0700 | [diff] [blame] | 884 | ret = tps65910_reg_clear_bits(mfd, |
Laxman Dewangan | 1e0c66f | 2012-01-28 15:07:57 +0530 | [diff] [blame] | 885 | TPS65910_EN3_LDO_ASS + regoffs, bit_pos); |
| 886 | if (ret < 0) { |
| 887 | dev_err(mfd->dev, |
| 888 | "Error in configuring external control EN3\n"); |
| 889 | return ret; |
| 890 | } |
| 891 | } |
| 892 | |
| 893 | /* Return if no external control is selected */ |
| 894 | if (!(ext_sleep_config & EXT_SLEEP_CONTROL)) { |
| 895 | /* Clear all sleep controls */ |
Rhyland Klein | 3f7e827 | 2012-05-08 11:42:38 -0700 | [diff] [blame] | 896 | ret = tps65910_reg_clear_bits(mfd, |
Laxman Dewangan | 1e0c66f | 2012-01-28 15:07:57 +0530 | [diff] [blame] | 897 | TPS65910_SLEEP_KEEP_LDO_ON + regoffs, bit_pos); |
| 898 | if (!ret) |
Rhyland Klein | 3f7e827 | 2012-05-08 11:42:38 -0700 | [diff] [blame] | 899 | ret = tps65910_reg_clear_bits(mfd, |
Laxman Dewangan | 1e0c66f | 2012-01-28 15:07:57 +0530 | [diff] [blame] | 900 | TPS65910_SLEEP_SET_LDO_OFF + regoffs, bit_pos); |
| 901 | if (ret < 0) |
| 902 | dev_err(mfd->dev, |
| 903 | "Error in configuring SLEEP register\n"); |
| 904 | return ret; |
| 905 | } |
| 906 | |
| 907 | /* |
| 908 | * For regulator that has separate operational and sleep register make |
| 909 | * sure that operational is used and clear sleep register to turn |
| 910 | * regulator off when external control is inactive |
| 911 | */ |
| 912 | if ((id == TPS65910_REG_VDD1) || |
| 913 | (id == TPS65910_REG_VDD2) || |
| 914 | ((id == TPS65911_REG_VDDCTRL) && |
| 915 | (tps65910_chip_id(mfd) == TPS65911))) { |
| 916 | int op_reg_add = pmic->get_ctrl_reg(id) + 1; |
| 917 | int sr_reg_add = pmic->get_ctrl_reg(id) + 2; |
Axel Lin | faa95fd | 2012-07-11 19:44:13 +0800 | [diff] [blame] | 918 | int opvsel, srvsel; |
| 919 | |
| 920 | ret = tps65910_reg_read(pmic->mfd, op_reg_add, &opvsel); |
| 921 | if (ret < 0) |
| 922 | return ret; |
| 923 | ret = tps65910_reg_read(pmic->mfd, sr_reg_add, &srvsel); |
| 924 | if (ret < 0) |
| 925 | return ret; |
| 926 | |
Laxman Dewangan | 1e0c66f | 2012-01-28 15:07:57 +0530 | [diff] [blame] | 927 | if (opvsel & VDD1_OP_CMD_MASK) { |
| 928 | u8 reg_val = srvsel & VDD1_OP_SEL_MASK; |
Axel Lin | faa95fd | 2012-07-11 19:44:13 +0800 | [diff] [blame] | 929 | |
| 930 | ret = tps65910_reg_write(pmic->mfd, op_reg_add, |
| 931 | reg_val); |
Laxman Dewangan | 1e0c66f | 2012-01-28 15:07:57 +0530 | [diff] [blame] | 932 | if (ret < 0) { |
| 933 | dev_err(mfd->dev, |
| 934 | "Error in configuring op register\n"); |
| 935 | return ret; |
| 936 | } |
| 937 | } |
Axel Lin | faa95fd | 2012-07-11 19:44:13 +0800 | [diff] [blame] | 938 | ret = tps65910_reg_write(pmic->mfd, sr_reg_add, 0); |
Laxman Dewangan | 1e0c66f | 2012-01-28 15:07:57 +0530 | [diff] [blame] | 939 | if (ret < 0) { |
Masanari Iida | 6d3be30 | 2013-09-30 23:19:09 +0900 | [diff] [blame] | 940 | dev_err(mfd->dev, "Error in setting sr register\n"); |
Laxman Dewangan | 1e0c66f | 2012-01-28 15:07:57 +0530 | [diff] [blame] | 941 | return ret; |
| 942 | } |
| 943 | } |
| 944 | |
Rhyland Klein | 3f7e827 | 2012-05-08 11:42:38 -0700 | [diff] [blame] | 945 | ret = tps65910_reg_clear_bits(mfd, |
Laxman Dewangan | 1e0c66f | 2012-01-28 15:07:57 +0530 | [diff] [blame] | 946 | TPS65910_SLEEP_KEEP_LDO_ON + regoffs, bit_pos); |
Laxman Dewangan | f30b071 | 2012-03-07 18:21:49 +0530 | [diff] [blame] | 947 | if (!ret) { |
| 948 | if (ext_sleep_config & TPS65911_SLEEP_CONTROL_EXT_INPUT_SLEEP) |
Rhyland Klein | 3f7e827 | 2012-05-08 11:42:38 -0700 | [diff] [blame] | 949 | ret = tps65910_reg_set_bits(mfd, |
Laxman Dewangan | f30b071 | 2012-03-07 18:21:49 +0530 | [diff] [blame] | 950 | TPS65910_SLEEP_SET_LDO_OFF + regoffs, bit_pos); |
| 951 | else |
Rhyland Klein | 3f7e827 | 2012-05-08 11:42:38 -0700 | [diff] [blame] | 952 | ret = tps65910_reg_clear_bits(mfd, |
Laxman Dewangan | f30b071 | 2012-03-07 18:21:49 +0530 | [diff] [blame] | 953 | TPS65910_SLEEP_SET_LDO_OFF + regoffs, bit_pos); |
| 954 | } |
Laxman Dewangan | 1e0c66f | 2012-01-28 15:07:57 +0530 | [diff] [blame] | 955 | if (ret < 0) |
| 956 | dev_err(mfd->dev, |
| 957 | "Error in configuring SLEEP register\n"); |
Laxman Dewangan | f30b071 | 2012-03-07 18:21:49 +0530 | [diff] [blame] | 958 | |
Laxman Dewangan | 1e0c66f | 2012-01-28 15:07:57 +0530 | [diff] [blame] | 959 | return ret; |
| 960 | } |
| 961 | |
Rhyland Klein | 6790178 | 2012-05-08 11:42:41 -0700 | [diff] [blame] | 962 | #ifdef CONFIG_OF |
| 963 | |
| 964 | static struct of_regulator_match tps65910_matches[] = { |
Laxman Dewangan | 33a6943 | 2012-05-19 20:04:06 +0530 | [diff] [blame] | 965 | { .name = "vrtc", .driver_data = (void *) &tps65910_regs[0] }, |
| 966 | { .name = "vio", .driver_data = (void *) &tps65910_regs[1] }, |
| 967 | { .name = "vdd1", .driver_data = (void *) &tps65910_regs[2] }, |
| 968 | { .name = "vdd2", .driver_data = (void *) &tps65910_regs[3] }, |
| 969 | { .name = "vdd3", .driver_data = (void *) &tps65910_regs[4] }, |
| 970 | { .name = "vdig1", .driver_data = (void *) &tps65910_regs[5] }, |
| 971 | { .name = "vdig2", .driver_data = (void *) &tps65910_regs[6] }, |
| 972 | { .name = "vpll", .driver_data = (void *) &tps65910_regs[7] }, |
| 973 | { .name = "vdac", .driver_data = (void *) &tps65910_regs[8] }, |
| 974 | { .name = "vaux1", .driver_data = (void *) &tps65910_regs[9] }, |
| 975 | { .name = "vaux2", .driver_data = (void *) &tps65910_regs[10] }, |
| 976 | { .name = "vaux33", .driver_data = (void *) &tps65910_regs[11] }, |
| 977 | { .name = "vmmc", .driver_data = (void *) &tps65910_regs[12] }, |
Markus Pargmann | 03746dc | 2013-12-20 12:43:27 +0100 | [diff] [blame] | 978 | { .name = "vbb", .driver_data = (void *) &tps65910_regs[13] }, |
Rhyland Klein | 6790178 | 2012-05-08 11:42:41 -0700 | [diff] [blame] | 979 | }; |
| 980 | |
| 981 | static struct of_regulator_match tps65911_matches[] = { |
Laxman Dewangan | 33a6943 | 2012-05-19 20:04:06 +0530 | [diff] [blame] | 982 | { .name = "vrtc", .driver_data = (void *) &tps65911_regs[0] }, |
| 983 | { .name = "vio", .driver_data = (void *) &tps65911_regs[1] }, |
| 984 | { .name = "vdd1", .driver_data = (void *) &tps65911_regs[2] }, |
| 985 | { .name = "vdd2", .driver_data = (void *) &tps65911_regs[3] }, |
| 986 | { .name = "vddctrl", .driver_data = (void *) &tps65911_regs[4] }, |
| 987 | { .name = "ldo1", .driver_data = (void *) &tps65911_regs[5] }, |
| 988 | { .name = "ldo2", .driver_data = (void *) &tps65911_regs[6] }, |
| 989 | { .name = "ldo3", .driver_data = (void *) &tps65911_regs[7] }, |
| 990 | { .name = "ldo4", .driver_data = (void *) &tps65911_regs[8] }, |
| 991 | { .name = "ldo5", .driver_data = (void *) &tps65911_regs[9] }, |
| 992 | { .name = "ldo6", .driver_data = (void *) &tps65911_regs[10] }, |
| 993 | { .name = "ldo7", .driver_data = (void *) &tps65911_regs[11] }, |
| 994 | { .name = "ldo8", .driver_data = (void *) &tps65911_regs[12] }, |
Rhyland Klein | 6790178 | 2012-05-08 11:42:41 -0700 | [diff] [blame] | 995 | }; |
| 996 | |
| 997 | static struct tps65910_board *tps65910_parse_dt_reg_data( |
Laxman Dewangan | 84df8c1 | 2012-05-20 21:48:50 +0530 | [diff] [blame] | 998 | struct platform_device *pdev, |
| 999 | struct of_regulator_match **tps65910_reg_matches) |
Rhyland Klein | 6790178 | 2012-05-08 11:42:41 -0700 | [diff] [blame] | 1000 | { |
| 1001 | struct tps65910_board *pmic_plat_data; |
| 1002 | struct tps65910 *tps65910 = dev_get_drvdata(pdev->dev.parent); |
Axel Lin | c92f5dd | 2013-01-27 21:16:56 +0800 | [diff] [blame] | 1003 | struct device_node *np, *regulators; |
Rhyland Klein | 6790178 | 2012-05-08 11:42:41 -0700 | [diff] [blame] | 1004 | struct of_regulator_match *matches; |
| 1005 | unsigned int prop; |
| 1006 | int idx = 0, ret, count; |
| 1007 | |
| 1008 | pmic_plat_data = devm_kzalloc(&pdev->dev, sizeof(*pmic_plat_data), |
| 1009 | GFP_KERNEL); |
Sachin Kamat | bcb2c0d | 2014-02-20 14:23:18 +0530 | [diff] [blame] | 1010 | if (!pmic_plat_data) |
Rhyland Klein | 6790178 | 2012-05-08 11:42:41 -0700 | [diff] [blame] | 1011 | return NULL; |
Rhyland Klein | 6790178 | 2012-05-08 11:42:41 -0700 | [diff] [blame] | 1012 | |
Guodong Xu | b8b27a4 | 2014-09-10 11:50:39 +0800 | [diff] [blame] | 1013 | np = pdev->dev.parent->of_node; |
Laxman Dewangan | 4ae1ff7 | 2013-10-08 19:31:04 +0530 | [diff] [blame] | 1014 | regulators = of_get_child_by_name(np, "regulators"); |
Laxman Dewangan | 92ab953 | 2012-05-20 21:48:49 +0530 | [diff] [blame] | 1015 | if (!regulators) { |
| 1016 | dev_err(&pdev->dev, "regulator node not found\n"); |
| 1017 | return NULL; |
| 1018 | } |
Rhyland Klein | 6790178 | 2012-05-08 11:42:41 -0700 | [diff] [blame] | 1019 | |
| 1020 | switch (tps65910_chip_id(tps65910)) { |
| 1021 | case TPS65910: |
| 1022 | count = ARRAY_SIZE(tps65910_matches); |
| 1023 | matches = tps65910_matches; |
| 1024 | break; |
| 1025 | case TPS65911: |
| 1026 | count = ARRAY_SIZE(tps65911_matches); |
| 1027 | matches = tps65911_matches; |
| 1028 | break; |
| 1029 | default: |
Axel Lin | c92f5dd | 2013-01-27 21:16:56 +0800 | [diff] [blame] | 1030 | of_node_put(regulators); |
Laxman Dewangan | 7e9a57e | 2012-05-20 21:48:48 +0530 | [diff] [blame] | 1031 | dev_err(&pdev->dev, "Invalid tps chip version\n"); |
Rhyland Klein | 6790178 | 2012-05-08 11:42:41 -0700 | [diff] [blame] | 1032 | return NULL; |
| 1033 | } |
| 1034 | |
Axel Lin | 08337fd | 2013-01-24 10:31:45 +0800 | [diff] [blame] | 1035 | ret = of_regulator_match(&pdev->dev, regulators, matches, count); |
Axel Lin | c92f5dd | 2013-01-27 21:16:56 +0800 | [diff] [blame] | 1036 | of_node_put(regulators); |
Rhyland Klein | 6790178 | 2012-05-08 11:42:41 -0700 | [diff] [blame] | 1037 | if (ret < 0) { |
| 1038 | dev_err(&pdev->dev, "Error parsing regulator init data: %d\n", |
| 1039 | ret); |
| 1040 | return NULL; |
| 1041 | } |
| 1042 | |
Laxman Dewangan | 84df8c1 | 2012-05-20 21:48:50 +0530 | [diff] [blame] | 1043 | *tps65910_reg_matches = matches; |
| 1044 | |
Rhyland Klein | 6790178 | 2012-05-08 11:42:41 -0700 | [diff] [blame] | 1045 | for (idx = 0; idx < count; idx++) { |
Axel Lin | 23b1134 | 2014-02-18 21:11:48 +0800 | [diff] [blame] | 1046 | if (!matches[idx].of_node) |
Rhyland Klein | 6790178 | 2012-05-08 11:42:41 -0700 | [diff] [blame] | 1047 | continue; |
| 1048 | |
| 1049 | pmic_plat_data->tps65910_pmic_init_data[idx] = |
| 1050 | matches[idx].init_data; |
| 1051 | |
| 1052 | ret = of_property_read_u32(matches[idx].of_node, |
| 1053 | "ti,regulator-ext-sleep-control", &prop); |
| 1054 | if (!ret) |
| 1055 | pmic_plat_data->regulator_ext_sleep_control[idx] = prop; |
Laxman Dewangan | 19228a6 | 2012-07-06 14:13:12 +0530 | [diff] [blame] | 1056 | |
Rhyland Klein | 6790178 | 2012-05-08 11:42:41 -0700 | [diff] [blame] | 1057 | } |
| 1058 | |
| 1059 | return pmic_plat_data; |
| 1060 | } |
| 1061 | #else |
| 1062 | static inline struct tps65910_board *tps65910_parse_dt_reg_data( |
Laxman Dewangan | 84df8c1 | 2012-05-20 21:48:50 +0530 | [diff] [blame] | 1063 | struct platform_device *pdev, |
| 1064 | struct of_regulator_match **tps65910_reg_matches) |
Rhyland Klein | 6790178 | 2012-05-08 11:42:41 -0700 | [diff] [blame] | 1065 | { |
Laxman Dewangan | 84df8c1 | 2012-05-20 21:48:50 +0530 | [diff] [blame] | 1066 | *tps65910_reg_matches = NULL; |
Mark Brown | 74ea0e5 | 2012-06-15 19:04:33 +0100 | [diff] [blame] | 1067 | return NULL; |
Rhyland Klein | 6790178 | 2012-05-08 11:42:41 -0700 | [diff] [blame] | 1068 | } |
| 1069 | #endif |
| 1070 | |
Bill Pemberton | a502357 | 2012-11-19 13:22:22 -0500 | [diff] [blame] | 1071 | static int tps65910_probe(struct platform_device *pdev) |
Graeme Gregory | 518fb72 | 2011-05-02 16:20:08 -0500 | [diff] [blame] | 1072 | { |
| 1073 | struct tps65910 *tps65910 = dev_get_drvdata(pdev->dev.parent); |
Mark Brown | c172708 | 2012-04-04 00:50:22 +0100 | [diff] [blame] | 1074 | struct regulator_config config = { }; |
Jorge Eduardo Candelaria | a320e3c | 2011-05-16 18:35:03 -0500 | [diff] [blame] | 1075 | struct tps_info *info; |
Graeme Gregory | 518fb72 | 2011-05-02 16:20:08 -0500 | [diff] [blame] | 1076 | struct regulator_dev *rdev; |
| 1077 | struct tps65910_reg *pmic; |
| 1078 | struct tps65910_board *pmic_plat_data; |
Laxman Dewangan | 84df8c1 | 2012-05-20 21:48:50 +0530 | [diff] [blame] | 1079 | struct of_regulator_match *tps65910_reg_matches = NULL; |
Graeme Gregory | 518fb72 | 2011-05-02 16:20:08 -0500 | [diff] [blame] | 1080 | int i, err; |
| 1081 | |
| 1082 | pmic_plat_data = dev_get_platdata(tps65910->dev); |
Rhyland Klein | 6790178 | 2012-05-08 11:42:41 -0700 | [diff] [blame] | 1083 | if (!pmic_plat_data && tps65910->dev->of_node) |
Laxman Dewangan | 84df8c1 | 2012-05-20 21:48:50 +0530 | [diff] [blame] | 1084 | pmic_plat_data = tps65910_parse_dt_reg_data(pdev, |
| 1085 | &tps65910_reg_matches); |
Rhyland Klein | 6790178 | 2012-05-08 11:42:41 -0700 | [diff] [blame] | 1086 | |
Laxman Dewangan | 7e9a57e | 2012-05-20 21:48:48 +0530 | [diff] [blame] | 1087 | if (!pmic_plat_data) { |
| 1088 | dev_err(&pdev->dev, "Platform data not found\n"); |
Graeme Gregory | 518fb72 | 2011-05-02 16:20:08 -0500 | [diff] [blame] | 1089 | return -EINVAL; |
Laxman Dewangan | 7e9a57e | 2012-05-20 21:48:48 +0530 | [diff] [blame] | 1090 | } |
Graeme Gregory | 518fb72 | 2011-05-02 16:20:08 -0500 | [diff] [blame] | 1091 | |
Axel Lin | 9eb0c42 | 2012-04-11 14:40:18 +0800 | [diff] [blame] | 1092 | pmic = devm_kzalloc(&pdev->dev, sizeof(*pmic), GFP_KERNEL); |
Sachin Kamat | bcb2c0d | 2014-02-20 14:23:18 +0530 | [diff] [blame] | 1093 | if (!pmic) |
Graeme Gregory | 518fb72 | 2011-05-02 16:20:08 -0500 | [diff] [blame] | 1094 | return -ENOMEM; |
| 1095 | |
Graeme Gregory | 518fb72 | 2011-05-02 16:20:08 -0500 | [diff] [blame] | 1096 | pmic->mfd = tps65910; |
| 1097 | platform_set_drvdata(pdev, pmic); |
| 1098 | |
| 1099 | /* Give control of all register to control port */ |
Kangjie Lu | cd07e37 | 2018-12-21 00:29:19 -0600 | [diff] [blame] | 1100 | err = tps65910_reg_set_bits(pmic->mfd, TPS65910_DEVCTRL, |
Graeme Gregory | 518fb72 | 2011-05-02 16:20:08 -0500 | [diff] [blame] | 1101 | DEVCTRL_SR_CTL_I2C_SEL_MASK); |
Kangjie Lu | cd07e37 | 2018-12-21 00:29:19 -0600 | [diff] [blame] | 1102 | if (err < 0) |
| 1103 | return err; |
Graeme Gregory | 518fb72 | 2011-05-02 16:20:08 -0500 | [diff] [blame] | 1104 | |
Jingoo Han | 4b57927 | 2013-10-14 17:53:40 +0900 | [diff] [blame] | 1105 | switch (tps65910_chip_id(tps65910)) { |
Jorge Eduardo Candelaria | a320e3c | 2011-05-16 18:35:03 -0500 | [diff] [blame] | 1106 | case TPS65910: |
Michał Mirosław | fe95390 | 2017-06-13 16:41:56 +0200 | [diff] [blame] | 1107 | BUILD_BUG_ON(TPS65910_NUM_REGS < ARRAY_SIZE(tps65910_regs)); |
Jorge Eduardo Candelaria | a320e3c | 2011-05-16 18:35:03 -0500 | [diff] [blame] | 1108 | pmic->get_ctrl_reg = &tps65910_get_ctrl_register; |
Axel Lin | 39aa9b6 | 2011-07-11 09:57:43 +0800 | [diff] [blame] | 1109 | pmic->num_regulators = ARRAY_SIZE(tps65910_regs); |
Laxman Dewangan | 1e0c66f | 2012-01-28 15:07:57 +0530 | [diff] [blame] | 1110 | pmic->ext_sleep_control = tps65910_ext_sleep_control; |
Jorge Eduardo Candelaria | a320e3c | 2011-05-16 18:35:03 -0500 | [diff] [blame] | 1111 | info = tps65910_regs; |
Jan Remmet | 8f9165c | 2016-09-23 10:52:00 +0200 | [diff] [blame] | 1112 | /* Work around silicon erratum SWCZ010: output programmed |
| 1113 | * voltage level can go higher than expected or crash |
| 1114 | * Workaround: use no synchronization of DCDC clocks |
| 1115 | */ |
| 1116 | tps65910_reg_clear_bits(pmic->mfd, TPS65910_DCDCCTRL, |
| 1117 | DCDCCTRL_DCDCCKSYNC_MASK); |
Axel Lin | d04156b | 2011-07-10 21:44:09 +0800 | [diff] [blame] | 1118 | break; |
Jorge Eduardo Candelaria | a320e3c | 2011-05-16 18:35:03 -0500 | [diff] [blame] | 1119 | case TPS65911: |
Michał Mirosław | fe95390 | 2017-06-13 16:41:56 +0200 | [diff] [blame] | 1120 | BUILD_BUG_ON(TPS65910_NUM_REGS < ARRAY_SIZE(tps65911_regs)); |
Jorge Eduardo Candelaria | a320e3c | 2011-05-16 18:35:03 -0500 | [diff] [blame] | 1121 | pmic->get_ctrl_reg = &tps65911_get_ctrl_register; |
Axel Lin | 39aa9b6 | 2011-07-11 09:57:43 +0800 | [diff] [blame] | 1122 | pmic->num_regulators = ARRAY_SIZE(tps65911_regs); |
Laxman Dewangan | 1e0c66f | 2012-01-28 15:07:57 +0530 | [diff] [blame] | 1123 | pmic->ext_sleep_control = tps65911_ext_sleep_control; |
Jorge Eduardo Candelaria | a320e3c | 2011-05-16 18:35:03 -0500 | [diff] [blame] | 1124 | info = tps65911_regs; |
Axel Lin | d04156b | 2011-07-10 21:44:09 +0800 | [diff] [blame] | 1125 | break; |
Jorge Eduardo Candelaria | a320e3c | 2011-05-16 18:35:03 -0500 | [diff] [blame] | 1126 | default: |
Laxman Dewangan | 7e9a57e | 2012-05-20 21:48:48 +0530 | [diff] [blame] | 1127 | dev_err(&pdev->dev, "Invalid tps chip version\n"); |
Jorge Eduardo Candelaria | a320e3c | 2011-05-16 18:35:03 -0500 | [diff] [blame] | 1128 | return -ENODEV; |
| 1129 | } |
| 1130 | |
Kees Cook | a86854d | 2018-06-12 14:07:58 -0700 | [diff] [blame] | 1131 | pmic->desc = devm_kcalloc(&pdev->dev, |
| 1132 | pmic->num_regulators, |
| 1133 | sizeof(struct regulator_desc), |
| 1134 | GFP_KERNEL); |
Sachin Kamat | bcb2c0d | 2014-02-20 14:23:18 +0530 | [diff] [blame] | 1135 | if (!pmic->desc) |
Laxman Dewangan | 68d8c1c | 2012-05-19 20:04:09 +0530 | [diff] [blame] | 1136 | return -ENOMEM; |
Axel Lin | 39aa9b6 | 2011-07-11 09:57:43 +0800 | [diff] [blame] | 1137 | |
Kees Cook | a86854d | 2018-06-12 14:07:58 -0700 | [diff] [blame] | 1138 | pmic->info = devm_kcalloc(&pdev->dev, |
| 1139 | pmic->num_regulators, |
| 1140 | sizeof(struct tps_info *), |
| 1141 | GFP_KERNEL); |
Sachin Kamat | bcb2c0d | 2014-02-20 14:23:18 +0530 | [diff] [blame] | 1142 | if (!pmic->info) |
Laxman Dewangan | 68d8c1c | 2012-05-19 20:04:09 +0530 | [diff] [blame] | 1143 | return -ENOMEM; |
Axel Lin | 39aa9b6 | 2011-07-11 09:57:43 +0800 | [diff] [blame] | 1144 | |
Kees Cook | a86854d | 2018-06-12 14:07:58 -0700 | [diff] [blame] | 1145 | pmic->rdev = devm_kcalloc(&pdev->dev, |
| 1146 | pmic->num_regulators, |
| 1147 | sizeof(struct regulator_dev *), |
| 1148 | GFP_KERNEL); |
Sachin Kamat | bcb2c0d | 2014-02-20 14:23:18 +0530 | [diff] [blame] | 1149 | if (!pmic->rdev) |
Laxman Dewangan | 68d8c1c | 2012-05-19 20:04:09 +0530 | [diff] [blame] | 1150 | return -ENOMEM; |
Axel Lin | 39aa9b6 | 2011-07-11 09:57:43 +0800 | [diff] [blame] | 1151 | |
Michał Mirosław | fe95390 | 2017-06-13 16:41:56 +0200 | [diff] [blame] | 1152 | for (i = 0; i < pmic->num_regulators; i++, info++) { |
Graeme Gregory | 518fb72 | 2011-05-02 16:20:08 -0500 | [diff] [blame] | 1153 | /* Register the regulators */ |
| 1154 | pmic->info[i] = info; |
| 1155 | |
| 1156 | pmic->desc[i].name = info->name; |
Laxman Dewangan | d2cfdb0 | 2012-07-17 11:34:06 +0530 | [diff] [blame] | 1157 | pmic->desc[i].supply_name = info->vin_name; |
Axel Lin | 77fa44d | 2011-05-12 13:47:50 +0800 | [diff] [blame] | 1158 | pmic->desc[i].id = i; |
Laxman Dewangan | 7d38a3c | 2012-01-20 16:36:22 +0530 | [diff] [blame] | 1159 | pmic->desc[i].n_voltages = info->n_voltages; |
Axel Lin | 94f48ab | 2012-07-04 09:59:17 +0800 | [diff] [blame] | 1160 | pmic->desc[i].enable_time = info->enable_time_us; |
Graeme Gregory | 518fb72 | 2011-05-02 16:20:08 -0500 | [diff] [blame] | 1161 | |
Jorge Eduardo Candelaria | a320e3c | 2011-05-16 18:35:03 -0500 | [diff] [blame] | 1162 | if (i == TPS65910_REG_VDD1 || i == TPS65910_REG_VDD2) { |
Graeme Gregory | 518fb72 | 2011-05-02 16:20:08 -0500 | [diff] [blame] | 1163 | pmic->desc[i].ops = &tps65910_ops_dcdc; |
Afzal Mohammed | 780dc9b | 2011-11-08 18:54:10 +0530 | [diff] [blame] | 1164 | pmic->desc[i].n_voltages = VDD1_2_NUM_VOLT_FINE * |
| 1165 | VDD1_2_NUM_VOLT_COARSE; |
Axel Lin | 01bc3a1 | 2012-06-20 22:40:10 +0800 | [diff] [blame] | 1166 | pmic->desc[i].ramp_delay = 12500; |
Jorge Eduardo Candelaria | a320e3c | 2011-05-16 18:35:03 -0500 | [diff] [blame] | 1167 | } else if (i == TPS65910_REG_VDD3) { |
Axel Lin | 01bc3a1 | 2012-06-20 22:40:10 +0800 | [diff] [blame] | 1168 | if (tps65910_chip_id(tps65910) == TPS65910) { |
Jorge Eduardo Candelaria | a320e3c | 2011-05-16 18:35:03 -0500 | [diff] [blame] | 1169 | pmic->desc[i].ops = &tps65910_ops_vdd3; |
Axel Lin | d9fe28f | 2012-06-21 18:48:00 +0800 | [diff] [blame] | 1170 | pmic->desc[i].volt_table = info->voltage_table; |
Axel Lin | 01bc3a1 | 2012-06-20 22:40:10 +0800 | [diff] [blame] | 1171 | } else { |
Jorge Eduardo Candelaria | a320e3c | 2011-05-16 18:35:03 -0500 | [diff] [blame] | 1172 | pmic->desc[i].ops = &tps65910_ops_dcdc; |
Axel Lin | 01bc3a1 | 2012-06-20 22:40:10 +0800 | [diff] [blame] | 1173 | pmic->desc[i].ramp_delay = 5000; |
| 1174 | } |
Markus Pargmann | 03746dc | 2013-12-20 12:43:27 +0100 | [diff] [blame] | 1175 | } else if (i == TPS65910_REG_VBB && |
| 1176 | tps65910_chip_id(tps65910) == TPS65910) { |
| 1177 | pmic->desc[i].ops = &tps65910_ops_vbb; |
| 1178 | pmic->desc[i].volt_table = info->voltage_table; |
Jorge Eduardo Candelaria | a320e3c | 2011-05-16 18:35:03 -0500 | [diff] [blame] | 1179 | } else { |
Axel Lin | d9fe28f | 2012-06-21 18:48:00 +0800 | [diff] [blame] | 1180 | if (tps65910_chip_id(tps65910) == TPS65910) { |
Jorge Eduardo Candelaria | a320e3c | 2011-05-16 18:35:03 -0500 | [diff] [blame] | 1181 | pmic->desc[i].ops = &tps65910_ops; |
Axel Lin | d9fe28f | 2012-06-21 18:48:00 +0800 | [diff] [blame] | 1182 | pmic->desc[i].volt_table = info->voltage_table; |
| 1183 | } else { |
Jorge Eduardo Candelaria | a320e3c | 2011-05-16 18:35:03 -0500 | [diff] [blame] | 1184 | pmic->desc[i].ops = &tps65911_ops; |
Axel Lin | d9fe28f | 2012-06-21 18:48:00 +0800 | [diff] [blame] | 1185 | } |
Jorge Eduardo Candelaria | a320e3c | 2011-05-16 18:35:03 -0500 | [diff] [blame] | 1186 | } |
Graeme Gregory | 518fb72 | 2011-05-02 16:20:08 -0500 | [diff] [blame] | 1187 | |
Laxman Dewangan | 1e0c66f | 2012-01-28 15:07:57 +0530 | [diff] [blame] | 1188 | err = tps65910_set_ext_sleep_config(pmic, i, |
| 1189 | pmic_plat_data->regulator_ext_sleep_control[i]); |
| 1190 | /* |
| 1191 | * Failing on regulator for configuring externally control |
| 1192 | * is not a serious issue, just throw warning. |
| 1193 | */ |
| 1194 | if (err < 0) |
| 1195 | dev_warn(tps65910->dev, |
| 1196 | "Failed to initialise ext control config\n"); |
| 1197 | |
Graeme Gregory | 518fb72 | 2011-05-02 16:20:08 -0500 | [diff] [blame] | 1198 | pmic->desc[i].type = REGULATOR_VOLTAGE; |
| 1199 | pmic->desc[i].owner = THIS_MODULE; |
Axel Lin | a40a9c4 | 2012-04-17 14:34:46 +0800 | [diff] [blame] | 1200 | pmic->desc[i].enable_reg = pmic->get_ctrl_reg(i); |
Axel Lin | b8903eb | 2013-12-29 17:00:20 +0800 | [diff] [blame] | 1201 | pmic->desc[i].enable_mask = TPS65910_SUPPLY_STATE_ENABLED; |
Graeme Gregory | 518fb72 | 2011-05-02 16:20:08 -0500 | [diff] [blame] | 1202 | |
Mark Brown | c172708 | 2012-04-04 00:50:22 +0100 | [diff] [blame] | 1203 | config.dev = tps65910->dev; |
Axel Lin | 23b1134 | 2014-02-18 21:11:48 +0800 | [diff] [blame] | 1204 | config.init_data = pmic_plat_data->tps65910_pmic_init_data[i]; |
Mark Brown | c172708 | 2012-04-04 00:50:22 +0100 | [diff] [blame] | 1205 | config.driver_data = pmic; |
Axel Lin | a40a9c4 | 2012-04-17 14:34:46 +0800 | [diff] [blame] | 1206 | config.regmap = tps65910->regmap; |
Mark Brown | c172708 | 2012-04-04 00:50:22 +0100 | [diff] [blame] | 1207 | |
Laxman Dewangan | 84df8c1 | 2012-05-20 21:48:50 +0530 | [diff] [blame] | 1208 | if (tps65910_reg_matches) |
| 1209 | config.of_node = tps65910_reg_matches[i].of_node; |
Rhyland Klein | 6790178 | 2012-05-08 11:42:41 -0700 | [diff] [blame] | 1210 | |
Sachin Kamat | 95095e4 | 2013-09-04 17:17:51 +0530 | [diff] [blame] | 1211 | rdev = devm_regulator_register(&pdev->dev, &pmic->desc[i], |
| 1212 | &config); |
Graeme Gregory | 518fb72 | 2011-05-02 16:20:08 -0500 | [diff] [blame] | 1213 | if (IS_ERR(rdev)) { |
| 1214 | dev_err(tps65910->dev, |
| 1215 | "failed to register %s regulator\n", |
| 1216 | pdev->name); |
Sachin Kamat | 95095e4 | 2013-09-04 17:17:51 +0530 | [diff] [blame] | 1217 | return PTR_ERR(rdev); |
Graeme Gregory | 518fb72 | 2011-05-02 16:20:08 -0500 | [diff] [blame] | 1218 | } |
| 1219 | |
| 1220 | /* Save regulator for cleanup */ |
| 1221 | pmic->rdev[i] = rdev; |
| 1222 | } |
| 1223 | return 0; |
Graeme Gregory | 518fb72 | 2011-05-02 16:20:08 -0500 | [diff] [blame] | 1224 | } |
| 1225 | |
Laxman Dewangan | 1e0c66f | 2012-01-28 15:07:57 +0530 | [diff] [blame] | 1226 | static void tps65910_shutdown(struct platform_device *pdev) |
| 1227 | { |
| 1228 | struct tps65910_reg *pmic = platform_get_drvdata(pdev); |
| 1229 | int i; |
| 1230 | |
| 1231 | /* |
| 1232 | * Before bootloader jumps to kernel, it makes sure that required |
| 1233 | * external control signals are in desired state so that given rails |
| 1234 | * can be configure accordingly. |
| 1235 | * If rails are configured to be controlled from external control |
| 1236 | * then before shutting down/rebooting the system, the external |
| 1237 | * control configuration need to be remove from the rails so that |
| 1238 | * its output will be available as per register programming even |
| 1239 | * if external controls are removed. This is require when the POR |
| 1240 | * value of the control signals are not in active state and before |
| 1241 | * bootloader initializes it, the system requires the rail output |
| 1242 | * to be active for booting. |
| 1243 | */ |
| 1244 | for (i = 0; i < pmic->num_regulators; i++) { |
| 1245 | int err; |
| 1246 | if (!pmic->rdev[i]) |
| 1247 | continue; |
| 1248 | |
| 1249 | err = tps65910_set_ext_sleep_config(pmic, i, 0); |
| 1250 | if (err < 0) |
| 1251 | dev_err(&pdev->dev, |
| 1252 | "Error in clearing external control\n"); |
| 1253 | } |
| 1254 | } |
| 1255 | |
Graeme Gregory | 518fb72 | 2011-05-02 16:20:08 -0500 | [diff] [blame] | 1256 | static struct platform_driver tps65910_driver = { |
| 1257 | .driver = { |
| 1258 | .name = "tps65910-pmic", |
Graeme Gregory | 518fb72 | 2011-05-02 16:20:08 -0500 | [diff] [blame] | 1259 | }, |
| 1260 | .probe = tps65910_probe, |
Laxman Dewangan | 1e0c66f | 2012-01-28 15:07:57 +0530 | [diff] [blame] | 1261 | .shutdown = tps65910_shutdown, |
Graeme Gregory | 518fb72 | 2011-05-02 16:20:08 -0500 | [diff] [blame] | 1262 | }; |
| 1263 | |
| 1264 | static int __init tps65910_init(void) |
| 1265 | { |
| 1266 | return platform_driver_register(&tps65910_driver); |
| 1267 | } |
| 1268 | subsys_initcall(tps65910_init); |
| 1269 | |
| 1270 | static void __exit tps65910_cleanup(void) |
| 1271 | { |
| 1272 | platform_driver_unregister(&tps65910_driver); |
| 1273 | } |
| 1274 | module_exit(tps65910_cleanup); |
| 1275 | |
| 1276 | MODULE_AUTHOR("Graeme Gregory <gg@slimlogic.co.uk>"); |
Axel Lin | ae0e654 | 2012-02-21 10:14:55 +0800 | [diff] [blame] | 1277 | MODULE_DESCRIPTION("TPS65910/TPS65911 voltage regulator driver"); |
Graeme Gregory | 518fb72 | 2011-05-02 16:20:08 -0500 | [diff] [blame] | 1278 | MODULE_LICENSE("GPL v2"); |
| 1279 | MODULE_ALIAS("platform:tps65910-pmic"); |