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