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