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