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