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