Jonghwa Lee | 133d401 | 2012-06-01 13:17:14 +0900 | [diff] [blame] | 1 | /* |
| 2 | * max77686.c - Regulator driver for the Maxim 77686 |
| 3 | * |
| 4 | * Copyright (C) 2012 Samsung Electronics |
Fabio Estevam | e4e8ccc | 2015-04-20 16:19:01 -0300 | [diff] [blame] | 5 | * Chiwoong Byun <woong.byun@samsung.com> |
Jonghwa Lee | 133d401 | 2012-06-01 13:17:14 +0900 | [diff] [blame] | 6 | * Jonghwa Lee <jonghwa3.lee@samsung.com> |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU General Public License as published by |
| 10 | * the Free Software Foundation; either version 2 of the License, or |
| 11 | * (at your option) any later version. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | * GNU General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License |
| 19 | * along with this program; if not, write to the Free Software |
| 20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 21 | * |
| 22 | * This driver is based on max8997.c |
| 23 | */ |
| 24 | |
| 25 | #include <linux/kernel.h> |
| 26 | #include <linux/bug.h> |
Jonghwa Lee | 133d401 | 2012-06-01 13:17:14 +0900 | [diff] [blame] | 27 | #include <linux/err.h> |
| 28 | #include <linux/gpio.h> |
Krzysztof Kozlowski | 3307e90 | 2015-01-05 12:48:43 +0100 | [diff] [blame] | 29 | #include <linux/of_gpio.h> |
Jonghwa Lee | 133d401 | 2012-06-01 13:17:14 +0900 | [diff] [blame] | 30 | #include <linux/slab.h> |
| 31 | #include <linux/platform_device.h> |
| 32 | #include <linux/regulator/driver.h> |
| 33 | #include <linux/regulator/machine.h> |
Yadwinder Singh Brar | 4706fca | 2012-07-05 09:28:25 +0530 | [diff] [blame] | 34 | #include <linux/regulator/of_regulator.h> |
Jonghwa Lee | 133d401 | 2012-06-01 13:17:14 +0900 | [diff] [blame] | 35 | #include <linux/mfd/max77686.h> |
| 36 | #include <linux/mfd/max77686-private.h> |
| 37 | |
| 38 | #define MAX77686_LDO_MINUV 800000 |
| 39 | #define MAX77686_LDO_UVSTEP 50000 |
| 40 | #define MAX77686_LDO_LOW_MINUV 800000 |
| 41 | #define MAX77686_LDO_LOW_UVSTEP 25000 |
| 42 | #define MAX77686_BUCK_MINUV 750000 |
| 43 | #define MAX77686_BUCK_UVSTEP 50000 |
Yadwinder Singh Brar | 852abad | 2012-06-19 13:23:42 +0530 | [diff] [blame] | 44 | #define MAX77686_RAMP_DELAY 100000 /* uV/us */ |
| 45 | #define MAX77686_DVS_RAMP_DELAY 27500 /* uV/us */ |
Jonghwa Lee | 133d401 | 2012-06-01 13:17:14 +0900 | [diff] [blame] | 46 | #define MAX77686_DVS_MINUV 600000 |
| 47 | #define MAX77686_DVS_UVSTEP 12500 |
| 48 | |
Krzysztof Kozlowski | 7636f19 | 2014-10-27 13:11:47 +0100 | [diff] [blame] | 49 | /* |
Krzysztof Kozlowski | 3307e90 | 2015-01-05 12:48:43 +0100 | [diff] [blame] | 50 | * Value for configuring buck[89] and LDO{20,21,22} as GPIO control. |
| 51 | * It is the same as 'off' for other regulators. |
| 52 | */ |
| 53 | #define MAX77686_GPIO_CONTROL 0x0 |
| 54 | /* |
Krzysztof Kozlowski | 7636f19 | 2014-10-27 13:11:47 +0100 | [diff] [blame] | 55 | * Values used for configuring LDOs and bucks. |
| 56 | * Forcing low power mode: LDO1, 3-5, 9, 13, 17-26 |
| 57 | */ |
| 58 | #define MAX77686_LDO_LOWPOWER 0x1 |
| 59 | /* |
| 60 | * On/off controlled by PWRREQ: |
| 61 | * - LDO2, 6-8, 10-12, 14-16 |
| 62 | * - buck[1234] |
| 63 | */ |
| 64 | #define MAX77686_OFF_PWRREQ 0x1 |
| 65 | /* Low power mode controlled by PWRREQ: All LDOs */ |
| 66 | #define MAX77686_LDO_LOWPOWER_PWRREQ 0x2 |
| 67 | /* Forcing low power mode: buck[234] */ |
| 68 | #define MAX77686_BUCK_LOWPOWER 0x2 |
| 69 | #define MAX77686_NORMAL 0x3 |
| 70 | |
Jonghwa Lee | 133d401 | 2012-06-01 13:17:14 +0900 | [diff] [blame] | 71 | #define MAX77686_OPMODE_SHIFT 6 |
| 72 | #define MAX77686_OPMODE_BUCK234_SHIFT 4 |
| 73 | #define MAX77686_OPMODE_MASK 0x3 |
| 74 | |
| 75 | #define MAX77686_VSEL_MASK 0x3F |
| 76 | #define MAX77686_DVS_VSEL_MASK 0xFF |
| 77 | |
| 78 | #define MAX77686_RAMP_RATE_MASK 0xC0 |
| 79 | |
| 80 | #define MAX77686_REGULATORS MAX77686_REG_MAX |
| 81 | #define MAX77686_LDOS 26 |
| 82 | |
| 83 | enum max77686_ramp_rate { |
| 84 | RAMP_RATE_13P75MV, |
| 85 | RAMP_RATE_27P5MV, |
| 86 | RAMP_RATE_55MV, |
| 87 | RAMP_RATE_NO_CTRL, /* 100mV/us */ |
| 88 | }; |
| 89 | |
| 90 | struct max77686_data { |
Joe Perches | c53403a | 2015-05-18 10:01:03 -0700 | [diff] [blame] | 91 | DECLARE_BITMAP(gpio_enabled, MAX77686_REGULATORS); |
Krzysztof Kozlowski | 3307e90 | 2015-01-05 12:48:43 +0100 | [diff] [blame] | 92 | |
Krzysztof Kozlowski | eca29da | 2014-11-04 09:49:41 +0100 | [diff] [blame] | 93 | /* Array indexed by regulator id */ |
Yadwinder Singh Brar | 6d2c896 | 2012-10-16 17:24:18 +0530 | [diff] [blame] | 94 | unsigned int opmode[MAX77686_REGULATORS]; |
Jonghwa Lee | 133d401 | 2012-06-01 13:17:14 +0900 | [diff] [blame] | 95 | }; |
| 96 | |
Krzysztof Kozlowski | 68c5d18 | 2014-10-27 13:11:48 +0100 | [diff] [blame] | 97 | static unsigned int max77686_get_opmode_shift(int id) |
| 98 | { |
| 99 | switch (id) { |
| 100 | case MAX77686_BUCK1: |
| 101 | case MAX77686_BUCK5 ... MAX77686_BUCK9: |
| 102 | return 0; |
| 103 | case MAX77686_BUCK2 ... MAX77686_BUCK4: |
| 104 | return MAX77686_OPMODE_BUCK234_SHIFT; |
| 105 | default: |
| 106 | /* all LDOs */ |
| 107 | return MAX77686_OPMODE_SHIFT; |
| 108 | } |
| 109 | } |
| 110 | |
Krzysztof Kozlowski | 3307e90 | 2015-01-05 12:48:43 +0100 | [diff] [blame] | 111 | /* |
| 112 | * When regulator is configured for GPIO control then it |
| 113 | * replaces "normal" mode. Any change from low power mode to normal |
| 114 | * should actually change to GPIO control. |
| 115 | * Map normal mode to proper value for such regulators. |
| 116 | */ |
| 117 | static unsigned int max77686_map_normal_mode(struct max77686_data *max77686, |
| 118 | int id) |
| 119 | { |
| 120 | switch (id) { |
| 121 | case MAX77686_BUCK8: |
| 122 | case MAX77686_BUCK9: |
| 123 | case MAX77686_LDO20 ... MAX77686_LDO22: |
Joe Perches | c53403a | 2015-05-18 10:01:03 -0700 | [diff] [blame] | 124 | if (test_bit(id, max77686->gpio_enabled)) |
Krzysztof Kozlowski | 3307e90 | 2015-01-05 12:48:43 +0100 | [diff] [blame] | 125 | return MAX77686_GPIO_CONTROL; |
| 126 | } |
| 127 | |
| 128 | return MAX77686_NORMAL; |
| 129 | } |
| 130 | |
Krzysztof Kozlowski | 78ce612 | 2014-10-29 12:14:52 +0100 | [diff] [blame] | 131 | /* Some BUCKs and LDOs supports Normal[ON/OFF] mode during suspend */ |
| 132 | static int max77686_set_suspend_disable(struct regulator_dev *rdev) |
Yadwinder Singh Brar | 15282ba | 2012-10-16 17:24:19 +0530 | [diff] [blame] | 133 | { |
Krzysztof Kozlowski | 68c5d18 | 2014-10-27 13:11:48 +0100 | [diff] [blame] | 134 | unsigned int val, shift; |
Yadwinder Singh Brar | 15282ba | 2012-10-16 17:24:19 +0530 | [diff] [blame] | 135 | struct max77686_data *max77686 = rdev_get_drvdata(rdev); |
Axel Lin | 3ecf198 | 2013-04-27 16:18:16 +0800 | [diff] [blame] | 136 | int ret, id = rdev_get_id(rdev); |
Yadwinder Singh Brar | 15282ba | 2012-10-16 17:24:19 +0530 | [diff] [blame] | 137 | |
Krzysztof Kozlowski | 68c5d18 | 2014-10-27 13:11:48 +0100 | [diff] [blame] | 138 | shift = max77686_get_opmode_shift(id); |
| 139 | val = MAX77686_OFF_PWRREQ; |
Yadwinder Singh Brar | 15282ba | 2012-10-16 17:24:19 +0530 | [diff] [blame] | 140 | |
Axel Lin | 3ecf198 | 2013-04-27 16:18:16 +0800 | [diff] [blame] | 141 | ret = regmap_update_bits(rdev->regmap, rdev->desc->enable_reg, |
Krzysztof Kozlowski | 68c5d18 | 2014-10-27 13:11:48 +0100 | [diff] [blame] | 142 | rdev->desc->enable_mask, val << shift); |
Axel Lin | 3ecf198 | 2013-04-27 16:18:16 +0800 | [diff] [blame] | 143 | if (ret) |
| 144 | return ret; |
| 145 | |
Thiago Farina | 40e7214 | 2013-02-13 17:52:26 -0200 | [diff] [blame] | 146 | max77686->opmode[id] = val; |
Axel Lin | 3ecf198 | 2013-04-27 16:18:16 +0800 | [diff] [blame] | 147 | return 0; |
Yadwinder Singh Brar | 15282ba | 2012-10-16 17:24:19 +0530 | [diff] [blame] | 148 | } |
| 149 | |
| 150 | /* Some LDOs supports [LPM/Normal]ON mode during suspend state */ |
| 151 | static int max77686_set_suspend_mode(struct regulator_dev *rdev, |
| 152 | unsigned int mode) |
| 153 | { |
| 154 | struct max77686_data *max77686 = rdev_get_drvdata(rdev); |
| 155 | unsigned int val; |
Axel Lin | 3ecf198 | 2013-04-27 16:18:16 +0800 | [diff] [blame] | 156 | int ret, id = rdev_get_id(rdev); |
Yadwinder Singh Brar | 15282ba | 2012-10-16 17:24:19 +0530 | [diff] [blame] | 157 | |
| 158 | /* BUCK[5-9] doesn't support this feature */ |
Thiago Farina | 40e7214 | 2013-02-13 17:52:26 -0200 | [diff] [blame] | 159 | if (id >= MAX77686_BUCK5) |
Yadwinder Singh Brar | 15282ba | 2012-10-16 17:24:19 +0530 | [diff] [blame] | 160 | return 0; |
| 161 | |
| 162 | switch (mode) { |
| 163 | case REGULATOR_MODE_IDLE: /* ON in LP Mode */ |
Krzysztof Kozlowski | 68c5d18 | 2014-10-27 13:11:48 +0100 | [diff] [blame] | 164 | val = MAX77686_LDO_LOWPOWER_PWRREQ; |
Yadwinder Singh Brar | 15282ba | 2012-10-16 17:24:19 +0530 | [diff] [blame] | 165 | break; |
| 166 | case REGULATOR_MODE_NORMAL: /* ON in Normal Mode */ |
Krzysztof Kozlowski | 3307e90 | 2015-01-05 12:48:43 +0100 | [diff] [blame] | 167 | val = max77686_map_normal_mode(max77686, id); |
Yadwinder Singh Brar | 15282ba | 2012-10-16 17:24:19 +0530 | [diff] [blame] | 168 | break; |
| 169 | default: |
| 170 | pr_warn("%s: regulator_suspend_mode : 0x%x not supported\n", |
| 171 | rdev->desc->name, mode); |
| 172 | return -EINVAL; |
| 173 | } |
| 174 | |
Axel Lin | 3ecf198 | 2013-04-27 16:18:16 +0800 | [diff] [blame] | 175 | ret = regmap_update_bits(rdev->regmap, rdev->desc->enable_reg, |
Krzysztof Kozlowski | 68c5d18 | 2014-10-27 13:11:48 +0100 | [diff] [blame] | 176 | rdev->desc->enable_mask, |
| 177 | val << MAX77686_OPMODE_SHIFT); |
Axel Lin | 3ecf198 | 2013-04-27 16:18:16 +0800 | [diff] [blame] | 178 | if (ret) |
| 179 | return ret; |
| 180 | |
Thiago Farina | 40e7214 | 2013-02-13 17:52:26 -0200 | [diff] [blame] | 181 | max77686->opmode[id] = val; |
Axel Lin | 3ecf198 | 2013-04-27 16:18:16 +0800 | [diff] [blame] | 182 | return 0; |
Yadwinder Singh Brar | 15282ba | 2012-10-16 17:24:19 +0530 | [diff] [blame] | 183 | } |
| 184 | |
| 185 | /* Some LDOs supports LPM-ON/OFF/Normal-ON mode during suspend state */ |
| 186 | static int max77686_ldo_set_suspend_mode(struct regulator_dev *rdev, |
| 187 | unsigned int mode) |
| 188 | { |
| 189 | unsigned int val; |
| 190 | struct max77686_data *max77686 = rdev_get_drvdata(rdev); |
Krzysztof Kozlowski | 3307e90 | 2015-01-05 12:48:43 +0100 | [diff] [blame] | 191 | int ret, id = rdev_get_id(rdev); |
Yadwinder Singh Brar | 15282ba | 2012-10-16 17:24:19 +0530 | [diff] [blame] | 192 | |
| 193 | switch (mode) { |
| 194 | case REGULATOR_MODE_STANDBY: /* switch off */ |
Krzysztof Kozlowski | 68c5d18 | 2014-10-27 13:11:48 +0100 | [diff] [blame] | 195 | val = MAX77686_OFF_PWRREQ; |
Yadwinder Singh Brar | 15282ba | 2012-10-16 17:24:19 +0530 | [diff] [blame] | 196 | break; |
| 197 | case REGULATOR_MODE_IDLE: /* ON in LP Mode */ |
Krzysztof Kozlowski | 68c5d18 | 2014-10-27 13:11:48 +0100 | [diff] [blame] | 198 | val = MAX77686_LDO_LOWPOWER_PWRREQ; |
Yadwinder Singh Brar | 15282ba | 2012-10-16 17:24:19 +0530 | [diff] [blame] | 199 | break; |
| 200 | case REGULATOR_MODE_NORMAL: /* ON in Normal Mode */ |
Krzysztof Kozlowski | 3307e90 | 2015-01-05 12:48:43 +0100 | [diff] [blame] | 201 | val = max77686_map_normal_mode(max77686, id); |
Yadwinder Singh Brar | 15282ba | 2012-10-16 17:24:19 +0530 | [diff] [blame] | 202 | break; |
| 203 | default: |
| 204 | pr_warn("%s: regulator_suspend_mode : 0x%x not supported\n", |
| 205 | rdev->desc->name, mode); |
| 206 | return -EINVAL; |
| 207 | } |
| 208 | |
Axel Lin | 3ecf198 | 2013-04-27 16:18:16 +0800 | [diff] [blame] | 209 | ret = regmap_update_bits(rdev->regmap, rdev->desc->enable_reg, |
Krzysztof Kozlowski | 68c5d18 | 2014-10-27 13:11:48 +0100 | [diff] [blame] | 210 | rdev->desc->enable_mask, |
| 211 | val << MAX77686_OPMODE_SHIFT); |
Axel Lin | 3ecf198 | 2013-04-27 16:18:16 +0800 | [diff] [blame] | 212 | if (ret) |
| 213 | return ret; |
| 214 | |
Krzysztof Kozlowski | 3307e90 | 2015-01-05 12:48:43 +0100 | [diff] [blame] | 215 | max77686->opmode[id] = val; |
Axel Lin | 3ecf198 | 2013-04-27 16:18:16 +0800 | [diff] [blame] | 216 | return 0; |
Yadwinder Singh Brar | 15282ba | 2012-10-16 17:24:19 +0530 | [diff] [blame] | 217 | } |
| 218 | |
Yadwinder Singh Brar | 38d3403 | 2012-10-22 09:39:28 +0530 | [diff] [blame] | 219 | static int max77686_enable(struct regulator_dev *rdev) |
Yadwinder Singh Brar | 6d2c896 | 2012-10-16 17:24:18 +0530 | [diff] [blame] | 220 | { |
| 221 | struct max77686_data *max77686 = rdev_get_drvdata(rdev); |
Krzysztof Kozlowski | 68c5d18 | 2014-10-27 13:11:48 +0100 | [diff] [blame] | 222 | unsigned int shift; |
| 223 | int id = rdev_get_id(rdev); |
| 224 | |
| 225 | shift = max77686_get_opmode_shift(id); |
Yadwinder Singh Brar | 6d2c896 | 2012-10-16 17:24:18 +0530 | [diff] [blame] | 226 | |
Krzysztof Kozlowski | 78ce612 | 2014-10-29 12:14:52 +0100 | [diff] [blame] | 227 | if (max77686->opmode[id] == MAX77686_OFF_PWRREQ) |
Krzysztof Kozlowski | 3307e90 | 2015-01-05 12:48:43 +0100 | [diff] [blame] | 228 | max77686->opmode[id] = max77686_map_normal_mode(max77686, id); |
Krzysztof Kozlowski | 78ce612 | 2014-10-29 12:14:52 +0100 | [diff] [blame] | 229 | |
Yadwinder Singh Brar | 6d2c896 | 2012-10-16 17:24:18 +0530 | [diff] [blame] | 230 | return regmap_update_bits(rdev->regmap, rdev->desc->enable_reg, |
| 231 | rdev->desc->enable_mask, |
Krzysztof Kozlowski | 68c5d18 | 2014-10-27 13:11:48 +0100 | [diff] [blame] | 232 | max77686->opmode[id] << shift); |
Yadwinder Singh Brar | 6d2c896 | 2012-10-16 17:24:18 +0530 | [diff] [blame] | 233 | } |
| 234 | |
Yadwinder Singh Brar | f503071 | 2012-06-20 10:50:51 +0530 | [diff] [blame] | 235 | static int max77686_set_ramp_delay(struct regulator_dev *rdev, int ramp_delay) |
| 236 | { |
| 237 | unsigned int ramp_value = RAMP_RATE_NO_CTRL; |
| 238 | |
| 239 | switch (ramp_delay) { |
| 240 | case 1 ... 13750: |
| 241 | ramp_value = RAMP_RATE_13P75MV; |
| 242 | break; |
| 243 | case 13751 ... 27500: |
| 244 | ramp_value = RAMP_RATE_27P5MV; |
| 245 | break; |
| 246 | case 27501 ... 55000: |
| 247 | ramp_value = RAMP_RATE_55MV; |
| 248 | break; |
| 249 | case 55001 ... 100000: |
| 250 | break; |
| 251 | default: |
| 252 | pr_warn("%s: ramp_delay: %d not supported, setting 100000\n", |
| 253 | rdev->desc->name, ramp_delay); |
| 254 | } |
| 255 | |
| 256 | return regmap_update_bits(rdev->regmap, rdev->desc->enable_reg, |
| 257 | MAX77686_RAMP_RATE_MASK, ramp_value << 6); |
| 258 | } |
| 259 | |
Krzysztof Kozlowski | 3307e90 | 2015-01-05 12:48:43 +0100 | [diff] [blame] | 260 | static int max77686_of_parse_cb(struct device_node *np, |
| 261 | const struct regulator_desc *desc, |
| 262 | struct regulator_config *config) |
| 263 | { |
| 264 | struct max77686_data *max77686 = config->driver_data; |
| 265 | |
| 266 | switch (desc->id) { |
| 267 | case MAX77686_BUCK8: |
| 268 | case MAX77686_BUCK9: |
| 269 | case MAX77686_LDO20 ... MAX77686_LDO22: |
| 270 | config->ena_gpio = of_get_named_gpio(np, |
| 271 | "maxim,ena-gpios", 0); |
| 272 | config->ena_gpio_flags = GPIOF_OUT_INIT_HIGH; |
| 273 | config->ena_gpio_initialized = true; |
| 274 | break; |
| 275 | default: |
| 276 | return 0; |
| 277 | } |
| 278 | |
| 279 | if (gpio_is_valid(config->ena_gpio)) { |
Joe Perches | c53403a | 2015-05-18 10:01:03 -0700 | [diff] [blame] | 280 | set_bit(desc->id, max77686->gpio_enabled); |
Krzysztof Kozlowski | 3307e90 | 2015-01-05 12:48:43 +0100 | [diff] [blame] | 281 | |
| 282 | return regmap_update_bits(config->regmap, desc->enable_reg, |
| 283 | desc->enable_mask, |
| 284 | MAX77686_GPIO_CONTROL); |
| 285 | } |
| 286 | |
| 287 | return 0; |
| 288 | } |
| 289 | |
Jonghwa Lee | 133d401 | 2012-06-01 13:17:14 +0900 | [diff] [blame] | 290 | static struct regulator_ops max77686_ops = { |
| 291 | .list_voltage = regulator_list_voltage_linear, |
Axel Lin | 2e3f7f2 | 2012-06-03 22:46:14 +0800 | [diff] [blame] | 292 | .map_voltage = regulator_map_voltage_linear, |
Jonghwa Lee | 133d401 | 2012-06-01 13:17:14 +0900 | [diff] [blame] | 293 | .is_enabled = regulator_is_enabled_regmap, |
Yadwinder Singh Brar | 6d2c896 | 2012-10-16 17:24:18 +0530 | [diff] [blame] | 294 | .enable = max77686_enable, |
Jonghwa Lee | 133d401 | 2012-06-01 13:17:14 +0900 | [diff] [blame] | 295 | .disable = regulator_disable_regmap, |
| 296 | .get_voltage_sel = regulator_get_voltage_sel_regmap, |
| 297 | .set_voltage_sel = regulator_set_voltage_sel_regmap, |
Yadwinder Singh Brar | 852abad | 2012-06-19 13:23:42 +0530 | [diff] [blame] | 298 | .set_voltage_time_sel = regulator_set_voltage_time_sel, |
Yadwinder Singh Brar | 15282ba | 2012-10-16 17:24:19 +0530 | [diff] [blame] | 299 | .set_suspend_mode = max77686_set_suspend_mode, |
| 300 | }; |
| 301 | |
| 302 | static struct regulator_ops max77686_ldo_ops = { |
| 303 | .list_voltage = regulator_list_voltage_linear, |
| 304 | .map_voltage = regulator_map_voltage_linear, |
| 305 | .is_enabled = regulator_is_enabled_regmap, |
| 306 | .enable = max77686_enable, |
| 307 | .disable = regulator_disable_regmap, |
| 308 | .get_voltage_sel = regulator_get_voltage_sel_regmap, |
| 309 | .set_voltage_sel = regulator_set_voltage_sel_regmap, |
| 310 | .set_voltage_time_sel = regulator_set_voltage_time_sel, |
| 311 | .set_suspend_mode = max77686_ldo_set_suspend_mode, |
Krzysztof Kozlowski | 78ce612 | 2014-10-29 12:14:52 +0100 | [diff] [blame] | 312 | .set_suspend_disable = max77686_set_suspend_disable, |
Yadwinder Singh Brar | 15282ba | 2012-10-16 17:24:19 +0530 | [diff] [blame] | 313 | }; |
| 314 | |
| 315 | static struct regulator_ops max77686_buck1_ops = { |
| 316 | .list_voltage = regulator_list_voltage_linear, |
| 317 | .map_voltage = regulator_map_voltage_linear, |
| 318 | .is_enabled = regulator_is_enabled_regmap, |
| 319 | .enable = max77686_enable, |
| 320 | .disable = regulator_disable_regmap, |
| 321 | .get_voltage_sel = regulator_get_voltage_sel_regmap, |
| 322 | .set_voltage_sel = regulator_set_voltage_sel_regmap, |
| 323 | .set_voltage_time_sel = regulator_set_voltage_time_sel, |
Krzysztof Kozlowski | 78ce612 | 2014-10-29 12:14:52 +0100 | [diff] [blame] | 324 | .set_suspend_disable = max77686_set_suspend_disable, |
Jonghwa Lee | 133d401 | 2012-06-01 13:17:14 +0900 | [diff] [blame] | 325 | }; |
| 326 | |
| 327 | static struct regulator_ops max77686_buck_dvs_ops = { |
| 328 | .list_voltage = regulator_list_voltage_linear, |
Axel Lin | 2e3f7f2 | 2012-06-03 22:46:14 +0800 | [diff] [blame] | 329 | .map_voltage = regulator_map_voltage_linear, |
Jonghwa Lee | 133d401 | 2012-06-01 13:17:14 +0900 | [diff] [blame] | 330 | .is_enabled = regulator_is_enabled_regmap, |
Yadwinder Singh Brar | 6d2c896 | 2012-10-16 17:24:18 +0530 | [diff] [blame] | 331 | .enable = max77686_enable, |
Jonghwa Lee | 133d401 | 2012-06-01 13:17:14 +0900 | [diff] [blame] | 332 | .disable = regulator_disable_regmap, |
| 333 | .get_voltage_sel = regulator_get_voltage_sel_regmap, |
| 334 | .set_voltage_sel = regulator_set_voltage_sel_regmap, |
Yadwinder Singh Brar | 852abad | 2012-06-19 13:23:42 +0530 | [diff] [blame] | 335 | .set_voltage_time_sel = regulator_set_voltage_time_sel, |
Yadwinder Singh Brar | f503071 | 2012-06-20 10:50:51 +0530 | [diff] [blame] | 336 | .set_ramp_delay = max77686_set_ramp_delay, |
Krzysztof Kozlowski | 78ce612 | 2014-10-29 12:14:52 +0100 | [diff] [blame] | 337 | .set_suspend_disable = max77686_set_suspend_disable, |
Jonghwa Lee | 133d401 | 2012-06-01 13:17:14 +0900 | [diff] [blame] | 338 | }; |
| 339 | |
| 340 | #define regulator_desc_ldo(num) { \ |
| 341 | .name = "LDO"#num, \ |
Krzysztof Kozlowski | 0480395 | 2014-11-05 10:47:50 +0100 | [diff] [blame] | 342 | .of_match = of_match_ptr("LDO"#num), \ |
| 343 | .regulators_node = of_match_ptr("voltage-regulators"), \ |
Krzysztof Kozlowski | 3307e90 | 2015-01-05 12:48:43 +0100 | [diff] [blame] | 344 | .of_parse_cb = max77686_of_parse_cb, \ |
Jonghwa Lee | 133d401 | 2012-06-01 13:17:14 +0900 | [diff] [blame] | 345 | .id = MAX77686_LDO##num, \ |
| 346 | .ops = &max77686_ops, \ |
| 347 | .type = REGULATOR_VOLTAGE, \ |
| 348 | .owner = THIS_MODULE, \ |
| 349 | .min_uV = MAX77686_LDO_MINUV, \ |
| 350 | .uV_step = MAX77686_LDO_UVSTEP, \ |
Yadwinder Singh Brar | 852abad | 2012-06-19 13:23:42 +0530 | [diff] [blame] | 351 | .ramp_delay = MAX77686_RAMP_DELAY, \ |
Jonghwa Lee | 133d401 | 2012-06-01 13:17:14 +0900 | [diff] [blame] | 352 | .n_voltages = MAX77686_VSEL_MASK + 1, \ |
| 353 | .vsel_reg = MAX77686_REG_LDO1CTRL1 + num - 1, \ |
| 354 | .vsel_mask = MAX77686_VSEL_MASK, \ |
| 355 | .enable_reg = MAX77686_REG_LDO1CTRL1 + num - 1, \ |
| 356 | .enable_mask = MAX77686_OPMODE_MASK \ |
| 357 | << MAX77686_OPMODE_SHIFT, \ |
| 358 | } |
Yadwinder Singh Brar | 15282ba | 2012-10-16 17:24:19 +0530 | [diff] [blame] | 359 | #define regulator_desc_lpm_ldo(num) { \ |
| 360 | .name = "LDO"#num, \ |
Krzysztof Kozlowski | 0480395 | 2014-11-05 10:47:50 +0100 | [diff] [blame] | 361 | .of_match = of_match_ptr("LDO"#num), \ |
| 362 | .regulators_node = of_match_ptr("voltage-regulators"), \ |
Yadwinder Singh Brar | 15282ba | 2012-10-16 17:24:19 +0530 | [diff] [blame] | 363 | .id = MAX77686_LDO##num, \ |
| 364 | .ops = &max77686_ldo_ops, \ |
| 365 | .type = REGULATOR_VOLTAGE, \ |
| 366 | .owner = THIS_MODULE, \ |
| 367 | .min_uV = MAX77686_LDO_MINUV, \ |
| 368 | .uV_step = MAX77686_LDO_UVSTEP, \ |
| 369 | .ramp_delay = MAX77686_RAMP_DELAY, \ |
| 370 | .n_voltages = MAX77686_VSEL_MASK + 1, \ |
| 371 | .vsel_reg = MAX77686_REG_LDO1CTRL1 + num - 1, \ |
| 372 | .vsel_mask = MAX77686_VSEL_MASK, \ |
| 373 | .enable_reg = MAX77686_REG_LDO1CTRL1 + num - 1, \ |
| 374 | .enable_mask = MAX77686_OPMODE_MASK \ |
| 375 | << MAX77686_OPMODE_SHIFT, \ |
| 376 | } |
Jonghwa Lee | 133d401 | 2012-06-01 13:17:14 +0900 | [diff] [blame] | 377 | #define regulator_desc_ldo_low(num) { \ |
| 378 | .name = "LDO"#num, \ |
Krzysztof Kozlowski | 0480395 | 2014-11-05 10:47:50 +0100 | [diff] [blame] | 379 | .of_match = of_match_ptr("LDO"#num), \ |
| 380 | .regulators_node = of_match_ptr("voltage-regulators"), \ |
Jonghwa Lee | 133d401 | 2012-06-01 13:17:14 +0900 | [diff] [blame] | 381 | .id = MAX77686_LDO##num, \ |
Yadwinder Singh Brar | 15282ba | 2012-10-16 17:24:19 +0530 | [diff] [blame] | 382 | .ops = &max77686_ldo_ops, \ |
| 383 | .type = REGULATOR_VOLTAGE, \ |
| 384 | .owner = THIS_MODULE, \ |
| 385 | .min_uV = MAX77686_LDO_LOW_MINUV, \ |
| 386 | .uV_step = MAX77686_LDO_LOW_UVSTEP, \ |
| 387 | .ramp_delay = MAX77686_RAMP_DELAY, \ |
| 388 | .n_voltages = MAX77686_VSEL_MASK + 1, \ |
| 389 | .vsel_reg = MAX77686_REG_LDO1CTRL1 + num - 1, \ |
| 390 | .vsel_mask = MAX77686_VSEL_MASK, \ |
| 391 | .enable_reg = MAX77686_REG_LDO1CTRL1 + num - 1, \ |
| 392 | .enable_mask = MAX77686_OPMODE_MASK \ |
| 393 | << MAX77686_OPMODE_SHIFT, \ |
| 394 | } |
| 395 | #define regulator_desc_ldo1_low(num) { \ |
| 396 | .name = "LDO"#num, \ |
Krzysztof Kozlowski | 0480395 | 2014-11-05 10:47:50 +0100 | [diff] [blame] | 397 | .of_match = of_match_ptr("LDO"#num), \ |
| 398 | .regulators_node = of_match_ptr("voltage-regulators"), \ |
Yadwinder Singh Brar | 15282ba | 2012-10-16 17:24:19 +0530 | [diff] [blame] | 399 | .id = MAX77686_LDO##num, \ |
Jonghwa Lee | 133d401 | 2012-06-01 13:17:14 +0900 | [diff] [blame] | 400 | .ops = &max77686_ops, \ |
| 401 | .type = REGULATOR_VOLTAGE, \ |
| 402 | .owner = THIS_MODULE, \ |
| 403 | .min_uV = MAX77686_LDO_LOW_MINUV, \ |
| 404 | .uV_step = MAX77686_LDO_LOW_UVSTEP, \ |
Yadwinder Singh Brar | 852abad | 2012-06-19 13:23:42 +0530 | [diff] [blame] | 405 | .ramp_delay = MAX77686_RAMP_DELAY, \ |
Jonghwa Lee | 133d401 | 2012-06-01 13:17:14 +0900 | [diff] [blame] | 406 | .n_voltages = MAX77686_VSEL_MASK + 1, \ |
| 407 | .vsel_reg = MAX77686_REG_LDO1CTRL1 + num - 1, \ |
| 408 | .vsel_mask = MAX77686_VSEL_MASK, \ |
| 409 | .enable_reg = MAX77686_REG_LDO1CTRL1 + num - 1, \ |
| 410 | .enable_mask = MAX77686_OPMODE_MASK \ |
| 411 | << MAX77686_OPMODE_SHIFT, \ |
| 412 | } |
| 413 | #define regulator_desc_buck(num) { \ |
| 414 | .name = "BUCK"#num, \ |
Krzysztof Kozlowski | 0480395 | 2014-11-05 10:47:50 +0100 | [diff] [blame] | 415 | .of_match = of_match_ptr("BUCK"#num), \ |
| 416 | .regulators_node = of_match_ptr("voltage-regulators"), \ |
Krzysztof Kozlowski | 3307e90 | 2015-01-05 12:48:43 +0100 | [diff] [blame] | 417 | .of_parse_cb = max77686_of_parse_cb, \ |
Jonghwa Lee | 133d401 | 2012-06-01 13:17:14 +0900 | [diff] [blame] | 418 | .id = MAX77686_BUCK##num, \ |
| 419 | .ops = &max77686_ops, \ |
| 420 | .type = REGULATOR_VOLTAGE, \ |
| 421 | .owner = THIS_MODULE, \ |
| 422 | .min_uV = MAX77686_BUCK_MINUV, \ |
| 423 | .uV_step = MAX77686_BUCK_UVSTEP, \ |
Yadwinder Singh Brar | 852abad | 2012-06-19 13:23:42 +0530 | [diff] [blame] | 424 | .ramp_delay = MAX77686_RAMP_DELAY, \ |
Jonghwa Lee | 133d401 | 2012-06-01 13:17:14 +0900 | [diff] [blame] | 425 | .n_voltages = MAX77686_VSEL_MASK + 1, \ |
| 426 | .vsel_reg = MAX77686_REG_BUCK5OUT + (num - 5) * 2, \ |
| 427 | .vsel_mask = MAX77686_VSEL_MASK, \ |
| 428 | .enable_reg = MAX77686_REG_BUCK5CTRL + (num - 5) * 2, \ |
| 429 | .enable_mask = MAX77686_OPMODE_MASK, \ |
| 430 | } |
| 431 | #define regulator_desc_buck1(num) { \ |
| 432 | .name = "BUCK"#num, \ |
Krzysztof Kozlowski | 0480395 | 2014-11-05 10:47:50 +0100 | [diff] [blame] | 433 | .of_match = of_match_ptr("BUCK"#num), \ |
| 434 | .regulators_node = of_match_ptr("voltage-regulators"), \ |
Jonghwa Lee | 133d401 | 2012-06-01 13:17:14 +0900 | [diff] [blame] | 435 | .id = MAX77686_BUCK##num, \ |
Yadwinder Singh Brar | 15282ba | 2012-10-16 17:24:19 +0530 | [diff] [blame] | 436 | .ops = &max77686_buck1_ops, \ |
Jonghwa Lee | 133d401 | 2012-06-01 13:17:14 +0900 | [diff] [blame] | 437 | .type = REGULATOR_VOLTAGE, \ |
| 438 | .owner = THIS_MODULE, \ |
| 439 | .min_uV = MAX77686_BUCK_MINUV, \ |
| 440 | .uV_step = MAX77686_BUCK_UVSTEP, \ |
Yadwinder Singh Brar | 852abad | 2012-06-19 13:23:42 +0530 | [diff] [blame] | 441 | .ramp_delay = MAX77686_RAMP_DELAY, \ |
Jonghwa Lee | 133d401 | 2012-06-01 13:17:14 +0900 | [diff] [blame] | 442 | .n_voltages = MAX77686_VSEL_MASK + 1, \ |
| 443 | .vsel_reg = MAX77686_REG_BUCK1OUT, \ |
| 444 | .vsel_mask = MAX77686_VSEL_MASK, \ |
| 445 | .enable_reg = MAX77686_REG_BUCK1CTRL, \ |
| 446 | .enable_mask = MAX77686_OPMODE_MASK, \ |
| 447 | } |
| 448 | #define regulator_desc_buck_dvs(num) { \ |
| 449 | .name = "BUCK"#num, \ |
Krzysztof Kozlowski | 0480395 | 2014-11-05 10:47:50 +0100 | [diff] [blame] | 450 | .of_match = of_match_ptr("BUCK"#num), \ |
| 451 | .regulators_node = of_match_ptr("voltage-regulators"), \ |
Jonghwa Lee | 133d401 | 2012-06-01 13:17:14 +0900 | [diff] [blame] | 452 | .id = MAX77686_BUCK##num, \ |
Axel Lin | 74adfee5 | 2012-06-04 10:19:18 +0800 | [diff] [blame] | 453 | .ops = &max77686_buck_dvs_ops, \ |
Jonghwa Lee | 133d401 | 2012-06-01 13:17:14 +0900 | [diff] [blame] | 454 | .type = REGULATOR_VOLTAGE, \ |
| 455 | .owner = THIS_MODULE, \ |
| 456 | .min_uV = MAX77686_DVS_MINUV, \ |
| 457 | .uV_step = MAX77686_DVS_UVSTEP, \ |
Yadwinder Singh Brar | 852abad | 2012-06-19 13:23:42 +0530 | [diff] [blame] | 458 | .ramp_delay = MAX77686_DVS_RAMP_DELAY, \ |
Jonghwa Lee | 133d401 | 2012-06-01 13:17:14 +0900 | [diff] [blame] | 459 | .n_voltages = MAX77686_DVS_VSEL_MASK + 1, \ |
| 460 | .vsel_reg = MAX77686_REG_BUCK2DVS1 + (num - 2) * 10, \ |
| 461 | .vsel_mask = MAX77686_DVS_VSEL_MASK, \ |
| 462 | .enable_reg = MAX77686_REG_BUCK2CTRL1 + (num - 2) * 10, \ |
| 463 | .enable_mask = MAX77686_OPMODE_MASK \ |
| 464 | << MAX77686_OPMODE_BUCK234_SHIFT, \ |
| 465 | } |
| 466 | |
Krzysztof Kozlowski | 73dbdf8 | 2014-10-27 16:03:42 +0100 | [diff] [blame] | 467 | static const struct regulator_desc regulators[] = { |
Yadwinder Singh Brar | 15282ba | 2012-10-16 17:24:19 +0530 | [diff] [blame] | 468 | regulator_desc_ldo1_low(1), |
Jonghwa Lee | 133d401 | 2012-06-01 13:17:14 +0900 | [diff] [blame] | 469 | regulator_desc_ldo_low(2), |
| 470 | regulator_desc_ldo(3), |
| 471 | regulator_desc_ldo(4), |
| 472 | regulator_desc_ldo(5), |
| 473 | regulator_desc_ldo_low(6), |
| 474 | regulator_desc_ldo_low(7), |
| 475 | regulator_desc_ldo_low(8), |
| 476 | regulator_desc_ldo(9), |
Yadwinder Singh Brar | 15282ba | 2012-10-16 17:24:19 +0530 | [diff] [blame] | 477 | regulator_desc_lpm_ldo(10), |
| 478 | regulator_desc_lpm_ldo(11), |
| 479 | regulator_desc_lpm_ldo(12), |
Jonghwa Lee | 133d401 | 2012-06-01 13:17:14 +0900 | [diff] [blame] | 480 | regulator_desc_ldo(13), |
Yadwinder Singh Brar | 15282ba | 2012-10-16 17:24:19 +0530 | [diff] [blame] | 481 | regulator_desc_lpm_ldo(14), |
Jonghwa Lee | 133d401 | 2012-06-01 13:17:14 +0900 | [diff] [blame] | 482 | regulator_desc_ldo_low(15), |
Yadwinder Singh Brar | 15282ba | 2012-10-16 17:24:19 +0530 | [diff] [blame] | 483 | regulator_desc_lpm_ldo(16), |
Jonghwa Lee | 133d401 | 2012-06-01 13:17:14 +0900 | [diff] [blame] | 484 | regulator_desc_ldo(17), |
| 485 | regulator_desc_ldo(18), |
| 486 | regulator_desc_ldo(19), |
| 487 | regulator_desc_ldo(20), |
| 488 | regulator_desc_ldo(21), |
| 489 | regulator_desc_ldo(22), |
| 490 | regulator_desc_ldo(23), |
| 491 | regulator_desc_ldo(24), |
| 492 | regulator_desc_ldo(25), |
| 493 | regulator_desc_ldo(26), |
| 494 | regulator_desc_buck1(1), |
| 495 | regulator_desc_buck_dvs(2), |
| 496 | regulator_desc_buck_dvs(3), |
| 497 | regulator_desc_buck_dvs(4), |
| 498 | regulator_desc_buck(5), |
| 499 | regulator_desc_buck(6), |
| 500 | regulator_desc_buck(7), |
| 501 | regulator_desc_buck(8), |
| 502 | regulator_desc_buck(9), |
| 503 | }; |
| 504 | |
Bill Pemberton | a502357 | 2012-11-19 13:22:22 -0500 | [diff] [blame] | 505 | static int max77686_pmic_probe(struct platform_device *pdev) |
Jonghwa Lee | 133d401 | 2012-06-01 13:17:14 +0900 | [diff] [blame] | 506 | { |
| 507 | struct max77686_dev *iodev = dev_get_drvdata(pdev->dev.parent); |
Jonghwa Lee | 133d401 | 2012-06-01 13:17:14 +0900 | [diff] [blame] | 508 | struct max77686_data *max77686; |
Krzysztof Kozlowski | 0480395 | 2014-11-05 10:47:50 +0100 | [diff] [blame] | 509 | int i; |
Axel Lin | c59d2a6 | 2012-06-20 15:01:25 +0800 | [diff] [blame] | 510 | struct regulator_config config = { }; |
Jonghwa Lee | 133d401 | 2012-06-01 13:17:14 +0900 | [diff] [blame] | 511 | |
| 512 | dev_dbg(&pdev->dev, "%s\n", __func__); |
| 513 | |
| 514 | max77686 = devm_kzalloc(&pdev->dev, sizeof(struct max77686_data), |
| 515 | GFP_KERNEL); |
| 516 | if (!max77686) |
| 517 | return -ENOMEM; |
| 518 | |
Krzysztof Kozlowski | 0480395 | 2014-11-05 10:47:50 +0100 | [diff] [blame] | 519 | config.dev = iodev->dev; |
Yadwinder Singh Brar | f503071 | 2012-06-20 10:50:51 +0530 | [diff] [blame] | 520 | config.regmap = iodev->regmap; |
Yadwinder Singh Brar | 6d2c896 | 2012-10-16 17:24:18 +0530 | [diff] [blame] | 521 | config.driver_data = max77686; |
Jonghwa Lee | 133d401 | 2012-06-01 13:17:14 +0900 | [diff] [blame] | 522 | platform_set_drvdata(pdev, max77686); |
| 523 | |
Axel Lin | ab0d1cb | 2012-06-08 12:03:04 +0800 | [diff] [blame] | 524 | for (i = 0; i < MAX77686_REGULATORS; i++) { |
Krzysztof Kozlowski | b0c13e8 | 2014-03-10 09:32:45 +0100 | [diff] [blame] | 525 | struct regulator_dev *rdev; |
Krzysztof Kozlowski | eca29da | 2014-11-04 09:49:41 +0100 | [diff] [blame] | 526 | int id = regulators[i].id; |
Krzysztof Kozlowski | b0c13e8 | 2014-03-10 09:32:45 +0100 | [diff] [blame] | 527 | |
Krzysztof Kozlowski | 4524df8 | 2014-11-04 09:49:42 +0100 | [diff] [blame] | 528 | max77686->opmode[id] = MAX77686_NORMAL; |
Krzysztof Kozlowski | b0c13e8 | 2014-03-10 09:32:45 +0100 | [diff] [blame] | 529 | rdev = devm_regulator_register(&pdev->dev, |
Sachin Kamat | 44815b4 | 2013-09-04 11:07:54 +0530 | [diff] [blame] | 530 | ®ulators[i], &config); |
Krzysztof Kozlowski | b0c13e8 | 2014-03-10 09:32:45 +0100 | [diff] [blame] | 531 | if (IS_ERR(rdev)) { |
Krzysztof Kozlowski | 0480395 | 2014-11-05 10:47:50 +0100 | [diff] [blame] | 532 | int ret = PTR_ERR(rdev); |
Yadwinder Singh Brar | f503071 | 2012-06-20 10:50:51 +0530 | [diff] [blame] | 533 | dev_err(&pdev->dev, |
Krzysztof Kozlowski | 0480395 | 2014-11-05 10:47:50 +0100 | [diff] [blame] | 534 | "regulator init failed for %d: %d\n", i, ret); |
| 535 | return ret; |
Jonghwa Lee | 133d401 | 2012-06-01 13:17:14 +0900 | [diff] [blame] | 536 | } |
Jonghwa Lee | 133d401 | 2012-06-01 13:17:14 +0900 | [diff] [blame] | 537 | } |
Axel Lin | ab0d1cb | 2012-06-08 12:03:04 +0800 | [diff] [blame] | 538 | |
Jonghwa Lee | 133d401 | 2012-06-01 13:17:14 +0900 | [diff] [blame] | 539 | return 0; |
Jonghwa Lee | 133d401 | 2012-06-01 13:17:14 +0900 | [diff] [blame] | 540 | } |
| 541 | |
| 542 | static const struct platform_device_id max77686_pmic_id[] = { |
| 543 | {"max77686-pmic", 0}, |
| 544 | { }, |
| 545 | }; |
| 546 | MODULE_DEVICE_TABLE(platform, max77686_pmic_id); |
| 547 | |
| 548 | static struct platform_driver max77686_pmic_driver = { |
| 549 | .driver = { |
| 550 | .name = "max77686-pmic", |
Jonghwa Lee | 133d401 | 2012-06-01 13:17:14 +0900 | [diff] [blame] | 551 | }, |
| 552 | .probe = max77686_pmic_probe, |
Jonghwa Lee | 133d401 | 2012-06-01 13:17:14 +0900 | [diff] [blame] | 553 | .id_table = max77686_pmic_id, |
| 554 | }; |
| 555 | |
| 556 | static int __init max77686_pmic_init(void) |
| 557 | { |
| 558 | return platform_driver_register(&max77686_pmic_driver); |
| 559 | } |
| 560 | subsys_initcall(max77686_pmic_init); |
| 561 | |
| 562 | static void __exit max77686_pmic_cleanup(void) |
| 563 | { |
| 564 | platform_driver_unregister(&max77686_pmic_driver); |
| 565 | } |
| 566 | module_exit(max77686_pmic_cleanup); |
| 567 | |
| 568 | MODULE_DESCRIPTION("MAXIM 77686 Regulator Driver"); |
| 569 | MODULE_AUTHOR("Chiwoong Byun <woong.byun@samsung.com>"); |
| 570 | MODULE_LICENSE("GPL"); |