Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 1 | /* |
| 2 | * s5m8767.c |
| 3 | * |
| 4 | * Copyright (c) 2011 Samsung Electronics Co., Ltd |
| 5 | * http://www.samsung.com |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify it |
| 8 | * under the terms of the GNU General Public License as published by the |
| 9 | * Free Software Foundation; either version 2 of the License, or (at your |
| 10 | * option) any later version. |
| 11 | * |
| 12 | */ |
| 13 | |
| 14 | #include <linux/bug.h> |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 15 | #include <linux/err.h> |
| 16 | #include <linux/gpio.h> |
| 17 | #include <linux/slab.h> |
| 18 | #include <linux/module.h> |
| 19 | #include <linux/platform_device.h> |
| 20 | #include <linux/regulator/driver.h> |
| 21 | #include <linux/regulator/machine.h> |
Sangbeom Kim | 54227bc | 2012-07-11 21:07:16 +0900 | [diff] [blame] | 22 | #include <linux/mfd/samsung/core.h> |
| 23 | #include <linux/mfd/samsung/s5m8767.h> |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 24 | |
| 25 | struct s5m8767_info { |
| 26 | struct device *dev; |
Sangbeom Kim | 63063bf | 2012-07-11 21:06:55 +0900 | [diff] [blame] | 27 | struct sec_pmic_dev *iodev; |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 28 | int num_regulators; |
| 29 | struct regulator_dev **rdev; |
Sangbeom Kim | 63063bf | 2012-07-11 21:06:55 +0900 | [diff] [blame] | 30 | struct sec_opmode_data *opmode; |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 31 | |
| 32 | int ramp_delay; |
| 33 | bool buck2_ramp; |
| 34 | bool buck3_ramp; |
| 35 | bool buck4_ramp; |
| 36 | |
| 37 | bool buck2_gpiodvs; |
| 38 | bool buck3_gpiodvs; |
| 39 | bool buck4_gpiodvs; |
| 40 | u8 buck2_vol[8]; |
| 41 | u8 buck3_vol[8]; |
| 42 | u8 buck4_vol[8]; |
| 43 | int buck_gpios[3]; |
Sangbeom Kim | c848bc8 | 2012-06-18 09:49:20 +0900 | [diff] [blame] | 44 | int buck_ds[3]; |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 45 | int buck_gpioindex; |
| 46 | }; |
| 47 | |
Sangbeom Kim | 63063bf | 2012-07-11 21:06:55 +0900 | [diff] [blame] | 48 | struct sec_voltage_desc { |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 49 | int max; |
| 50 | int min; |
| 51 | int step; |
| 52 | }; |
| 53 | |
Sangbeom Kim | 63063bf | 2012-07-11 21:06:55 +0900 | [diff] [blame] | 54 | static const struct sec_voltage_desc buck_voltage_val1 = { |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 55 | .max = 2225000, |
| 56 | .min = 650000, |
| 57 | .step = 6250, |
| 58 | }; |
| 59 | |
Sangbeom Kim | 63063bf | 2012-07-11 21:06:55 +0900 | [diff] [blame] | 60 | static const struct sec_voltage_desc buck_voltage_val2 = { |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 61 | .max = 1600000, |
| 62 | .min = 600000, |
| 63 | .step = 6250, |
| 64 | }; |
| 65 | |
Sangbeom Kim | 63063bf | 2012-07-11 21:06:55 +0900 | [diff] [blame] | 66 | static const struct sec_voltage_desc buck_voltage_val3 = { |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 67 | .max = 3000000, |
| 68 | .min = 750000, |
| 69 | .step = 12500, |
| 70 | }; |
| 71 | |
Sangbeom Kim | 63063bf | 2012-07-11 21:06:55 +0900 | [diff] [blame] | 72 | static const struct sec_voltage_desc ldo_voltage_val1 = { |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 73 | .max = 3950000, |
| 74 | .min = 800000, |
| 75 | .step = 50000, |
| 76 | }; |
| 77 | |
Sangbeom Kim | 63063bf | 2012-07-11 21:06:55 +0900 | [diff] [blame] | 78 | static const struct sec_voltage_desc ldo_voltage_val2 = { |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 79 | .max = 2375000, |
| 80 | .min = 800000, |
| 81 | .step = 25000, |
| 82 | }; |
| 83 | |
Sangbeom Kim | 63063bf | 2012-07-11 21:06:55 +0900 | [diff] [blame] | 84 | static const struct sec_voltage_desc *reg_voltage_map[] = { |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 85 | [S5M8767_LDO1] = &ldo_voltage_val2, |
| 86 | [S5M8767_LDO2] = &ldo_voltage_val2, |
| 87 | [S5M8767_LDO3] = &ldo_voltage_val1, |
| 88 | [S5M8767_LDO4] = &ldo_voltage_val1, |
| 89 | [S5M8767_LDO5] = &ldo_voltage_val1, |
| 90 | [S5M8767_LDO6] = &ldo_voltage_val2, |
| 91 | [S5M8767_LDO7] = &ldo_voltage_val2, |
| 92 | [S5M8767_LDO8] = &ldo_voltage_val2, |
| 93 | [S5M8767_LDO9] = &ldo_voltage_val1, |
| 94 | [S5M8767_LDO10] = &ldo_voltage_val1, |
| 95 | [S5M8767_LDO11] = &ldo_voltage_val1, |
| 96 | [S5M8767_LDO12] = &ldo_voltage_val1, |
| 97 | [S5M8767_LDO13] = &ldo_voltage_val1, |
| 98 | [S5M8767_LDO14] = &ldo_voltage_val1, |
| 99 | [S5M8767_LDO15] = &ldo_voltage_val2, |
| 100 | [S5M8767_LDO16] = &ldo_voltage_val1, |
| 101 | [S5M8767_LDO17] = &ldo_voltage_val1, |
| 102 | [S5M8767_LDO18] = &ldo_voltage_val1, |
| 103 | [S5M8767_LDO19] = &ldo_voltage_val1, |
| 104 | [S5M8767_LDO20] = &ldo_voltage_val1, |
| 105 | [S5M8767_LDO21] = &ldo_voltage_val1, |
| 106 | [S5M8767_LDO22] = &ldo_voltage_val1, |
| 107 | [S5M8767_LDO23] = &ldo_voltage_val1, |
| 108 | [S5M8767_LDO24] = &ldo_voltage_val1, |
| 109 | [S5M8767_LDO25] = &ldo_voltage_val1, |
| 110 | [S5M8767_LDO26] = &ldo_voltage_val1, |
| 111 | [S5M8767_LDO27] = &ldo_voltage_val1, |
| 112 | [S5M8767_LDO28] = &ldo_voltage_val1, |
| 113 | [S5M8767_BUCK1] = &buck_voltage_val1, |
| 114 | [S5M8767_BUCK2] = &buck_voltage_val2, |
| 115 | [S5M8767_BUCK3] = &buck_voltage_val2, |
| 116 | [S5M8767_BUCK4] = &buck_voltage_val2, |
| 117 | [S5M8767_BUCK5] = &buck_voltage_val1, |
| 118 | [S5M8767_BUCK6] = &buck_voltage_val1, |
| 119 | [S5M8767_BUCK7] = NULL, |
| 120 | [S5M8767_BUCK8] = NULL, |
| 121 | [S5M8767_BUCK9] = &buck_voltage_val3, |
| 122 | }; |
| 123 | |
Mark Brown | 5ceba7b | 2012-05-09 20:37:51 +0100 | [diff] [blame] | 124 | static unsigned int s5m8767_opmode_reg[][4] = { |
Sangbeom Kim | 7e44bb8 | 2012-03-09 17:55:34 +0900 | [diff] [blame] | 125 | /* {OFF, ON, LOWPOWER, SUSPEND} */ |
| 126 | /* LDO1 ... LDO28 */ |
| 127 | {0x0, 0x3, 0x2, 0x1}, /* LDO1 */ |
| 128 | {0x0, 0x3, 0x2, 0x1}, |
| 129 | {0x0, 0x3, 0x2, 0x1}, |
| 130 | {0x0, 0x0, 0x0, 0x0}, |
| 131 | {0x0, 0x3, 0x2, 0x1}, /* LDO5 */ |
| 132 | {0x0, 0x3, 0x2, 0x1}, |
| 133 | {0x0, 0x3, 0x2, 0x1}, |
| 134 | {0x0, 0x3, 0x2, 0x1}, |
| 135 | {0x0, 0x3, 0x2, 0x1}, |
| 136 | {0x0, 0x3, 0x2, 0x1}, /* LDO10 */ |
| 137 | {0x0, 0x3, 0x2, 0x1}, |
| 138 | {0x0, 0x3, 0x2, 0x1}, |
| 139 | {0x0, 0x3, 0x2, 0x1}, |
| 140 | {0x0, 0x3, 0x2, 0x1}, |
| 141 | {0x0, 0x3, 0x2, 0x1}, /* LDO15 */ |
| 142 | {0x0, 0x3, 0x2, 0x1}, |
| 143 | {0x0, 0x3, 0x2, 0x1}, |
| 144 | {0x0, 0x0, 0x0, 0x0}, |
| 145 | {0x0, 0x3, 0x2, 0x1}, |
| 146 | {0x0, 0x3, 0x2, 0x1}, /* LDO20 */ |
| 147 | {0x0, 0x3, 0x2, 0x1}, |
| 148 | {0x0, 0x3, 0x2, 0x1}, |
| 149 | {0x0, 0x0, 0x0, 0x0}, |
| 150 | {0x0, 0x3, 0x2, 0x1}, |
| 151 | {0x0, 0x3, 0x2, 0x1}, /* LDO25 */ |
| 152 | {0x0, 0x3, 0x2, 0x1}, |
| 153 | {0x0, 0x3, 0x2, 0x1}, |
| 154 | {0x0, 0x3, 0x2, 0x1}, /* LDO28 */ |
| 155 | |
| 156 | /* BUCK1 ... BUCK9 */ |
| 157 | {0x0, 0x3, 0x1, 0x1}, /* BUCK1 */ |
| 158 | {0x0, 0x3, 0x1, 0x1}, |
| 159 | {0x0, 0x3, 0x1, 0x1}, |
| 160 | {0x0, 0x3, 0x1, 0x1}, |
| 161 | {0x0, 0x3, 0x2, 0x1}, /* BUCK5 */ |
| 162 | {0x0, 0x3, 0x1, 0x1}, |
| 163 | {0x0, 0x3, 0x1, 0x1}, |
| 164 | {0x0, 0x3, 0x1, 0x1}, |
| 165 | {0x0, 0x3, 0x1, 0x1}, /* BUCK9 */ |
| 166 | }; |
| 167 | |
| 168 | static int s5m8767_get_register(struct regulator_dev *rdev, int *reg, |
| 169 | int *enable_ctrl) |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 170 | { |
Amit Daniel Kachhap | 9bb096f | 2012-12-10 18:19:39 +0530 | [diff] [blame] | 171 | int i, reg_id = rdev_get_id(rdev); |
Sangbeom Kim | 7e44bb8 | 2012-03-09 17:55:34 +0900 | [diff] [blame] | 172 | unsigned int mode; |
| 173 | struct s5m8767_info *s5m8767 = rdev_get_drvdata(rdev); |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 174 | |
| 175 | switch (reg_id) { |
| 176 | case S5M8767_LDO1 ... S5M8767_LDO2: |
| 177 | *reg = S5M8767_REG_LDO1CTRL + (reg_id - S5M8767_LDO1); |
| 178 | break; |
| 179 | case S5M8767_LDO3 ... S5M8767_LDO28: |
| 180 | *reg = S5M8767_REG_LDO3CTRL + (reg_id - S5M8767_LDO3); |
| 181 | break; |
| 182 | case S5M8767_BUCK1: |
| 183 | *reg = S5M8767_REG_BUCK1CTRL1; |
| 184 | break; |
| 185 | case S5M8767_BUCK2 ... S5M8767_BUCK4: |
| 186 | *reg = S5M8767_REG_BUCK2CTRL + (reg_id - S5M8767_BUCK2) * 9; |
| 187 | break; |
| 188 | case S5M8767_BUCK5: |
| 189 | *reg = S5M8767_REG_BUCK5CTRL1; |
| 190 | break; |
| 191 | case S5M8767_BUCK6 ... S5M8767_BUCK9: |
| 192 | *reg = S5M8767_REG_BUCK6CTRL1 + (reg_id - S5M8767_BUCK6) * 2; |
| 193 | break; |
| 194 | default: |
| 195 | return -EINVAL; |
| 196 | } |
| 197 | |
Amit Daniel Kachhap | 9bb096f | 2012-12-10 18:19:39 +0530 | [diff] [blame] | 198 | for (i = 0; i < s5m8767->num_regulators; i++) { |
| 199 | if (s5m8767->opmode[i].id == reg_id) { |
| 200 | mode = s5m8767->opmode[i].mode; |
| 201 | break; |
| 202 | } |
| 203 | } |
| 204 | |
| 205 | if (i < s5m8767->num_regulators) |
| 206 | *enable_ctrl = |
| 207 | s5m8767_opmode_reg[reg_id][mode] << S5M8767_ENCTRL_SHIFT; |
| 208 | |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 209 | return 0; |
| 210 | } |
| 211 | |
| 212 | static int s5m8767_reg_is_enabled(struct regulator_dev *rdev) |
| 213 | { |
| 214 | struct s5m8767_info *s5m8767 = rdev_get_drvdata(rdev); |
| 215 | int ret, reg; |
Sangbeom Kim | 7e44bb8 | 2012-03-09 17:55:34 +0900 | [diff] [blame] | 216 | int mask = 0xc0, enable_ctrl; |
Inderpal Singh | 3ef3039 | 2012-12-12 08:57:00 +0530 | [diff] [blame] | 217 | unsigned int val; |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 218 | |
Sangbeom Kim | 7e44bb8 | 2012-03-09 17:55:34 +0900 | [diff] [blame] | 219 | ret = s5m8767_get_register(rdev, ®, &enable_ctrl); |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 220 | if (ret == -EINVAL) |
| 221 | return 1; |
| 222 | else if (ret) |
| 223 | return ret; |
| 224 | |
Sangbeom Kim | 63063bf | 2012-07-11 21:06:55 +0900 | [diff] [blame] | 225 | ret = sec_reg_read(s5m8767->iodev, reg, &val); |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 226 | if (ret) |
| 227 | return ret; |
| 228 | |
Sangbeom Kim | 7e44bb8 | 2012-03-09 17:55:34 +0900 | [diff] [blame] | 229 | return (val & mask) == enable_ctrl; |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 230 | } |
| 231 | |
| 232 | static int s5m8767_reg_enable(struct regulator_dev *rdev) |
| 233 | { |
| 234 | struct s5m8767_info *s5m8767 = rdev_get_drvdata(rdev); |
| 235 | int ret, reg; |
Sangbeom Kim | 7e44bb8 | 2012-03-09 17:55:34 +0900 | [diff] [blame] | 236 | int mask = 0xc0, enable_ctrl; |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 237 | |
Sangbeom Kim | 7e44bb8 | 2012-03-09 17:55:34 +0900 | [diff] [blame] | 238 | ret = s5m8767_get_register(rdev, ®, &enable_ctrl); |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 239 | if (ret) |
| 240 | return ret; |
| 241 | |
Sangbeom Kim | 63063bf | 2012-07-11 21:06:55 +0900 | [diff] [blame] | 242 | return sec_reg_update(s5m8767->iodev, reg, enable_ctrl, mask); |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 243 | } |
| 244 | |
| 245 | static int s5m8767_reg_disable(struct regulator_dev *rdev) |
| 246 | { |
| 247 | struct s5m8767_info *s5m8767 = rdev_get_drvdata(rdev); |
| 248 | int ret, reg; |
Sangbeom Kim | 7e44bb8 | 2012-03-09 17:55:34 +0900 | [diff] [blame] | 249 | int mask = 0xc0, enable_ctrl; |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 250 | |
Sangbeom Kim | 7e44bb8 | 2012-03-09 17:55:34 +0900 | [diff] [blame] | 251 | ret = s5m8767_get_register(rdev, ®, &enable_ctrl); |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 252 | if (ret) |
| 253 | return ret; |
| 254 | |
Sangbeom Kim | 63063bf | 2012-07-11 21:06:55 +0900 | [diff] [blame] | 255 | return sec_reg_update(s5m8767->iodev, reg, ~mask, mask); |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 256 | } |
| 257 | |
Axel Lin | 31a932e | 2013-01-18 09:55:06 +0800 | [diff] [blame^] | 258 | static int s5m8767_get_vsel_reg(int reg_id, struct s5m8767_info *s5m8767) |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 259 | { |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 260 | int reg; |
| 261 | |
| 262 | switch (reg_id) { |
| 263 | case S5M8767_LDO1 ... S5M8767_LDO2: |
| 264 | reg = S5M8767_REG_LDO1CTRL + (reg_id - S5M8767_LDO1); |
| 265 | break; |
| 266 | case S5M8767_LDO3 ... S5M8767_LDO28: |
| 267 | reg = S5M8767_REG_LDO3CTRL + (reg_id - S5M8767_LDO3); |
| 268 | break; |
| 269 | case S5M8767_BUCK1: |
| 270 | reg = S5M8767_REG_BUCK1CTRL2; |
| 271 | break; |
| 272 | case S5M8767_BUCK2: |
Amit Daniel Kachhap | da130ab | 2012-12-10 18:19:40 +0530 | [diff] [blame] | 273 | reg = S5M8767_REG_BUCK2DVS1; |
Axel Lin | 0a41685 | 2012-03-10 10:59:43 +0800 | [diff] [blame] | 274 | if (s5m8767->buck2_gpiodvs) |
| 275 | reg += s5m8767->buck_gpioindex; |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 276 | break; |
| 277 | case S5M8767_BUCK3: |
Amit Daniel Kachhap | da130ab | 2012-12-10 18:19:40 +0530 | [diff] [blame] | 278 | reg = S5M8767_REG_BUCK3DVS1; |
Axel Lin | 0a41685 | 2012-03-10 10:59:43 +0800 | [diff] [blame] | 279 | if (s5m8767->buck3_gpiodvs) |
| 280 | reg += s5m8767->buck_gpioindex; |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 281 | break; |
| 282 | case S5M8767_BUCK4: |
Amit Daniel Kachhap | da130ab | 2012-12-10 18:19:40 +0530 | [diff] [blame] | 283 | reg = S5M8767_REG_BUCK4DVS1; |
Axel Lin | 0a41685 | 2012-03-10 10:59:43 +0800 | [diff] [blame] | 284 | if (s5m8767->buck4_gpiodvs) |
| 285 | reg += s5m8767->buck_gpioindex; |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 286 | break; |
| 287 | case S5M8767_BUCK5: |
| 288 | reg = S5M8767_REG_BUCK5CTRL2; |
| 289 | break; |
| 290 | case S5M8767_BUCK6 ... S5M8767_BUCK9: |
| 291 | reg = S5M8767_REG_BUCK6CTRL2 + (reg_id - S5M8767_BUCK6) * 2; |
| 292 | break; |
| 293 | default: |
| 294 | return -EINVAL; |
| 295 | } |
| 296 | |
Axel Lin | 31a932e | 2013-01-18 09:55:06 +0800 | [diff] [blame^] | 297 | return reg; |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 298 | } |
| 299 | |
Axel Lin | 854f73e | 2012-12-29 09:38:50 +0800 | [diff] [blame] | 300 | static int s5m8767_convert_voltage_to_sel(const struct sec_voltage_desc *desc, |
| 301 | int min_vol) |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 302 | { |
Axel Lin | 5b5e977 | 2012-03-09 11:31:08 +0800 | [diff] [blame] | 303 | int selector = 0; |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 304 | |
| 305 | if (desc == NULL) |
| 306 | return -EINVAL; |
| 307 | |
Axel Lin | 854f73e | 2012-12-29 09:38:50 +0800 | [diff] [blame] | 308 | if (min_vol > desc->max) |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 309 | return -EINVAL; |
| 310 | |
Axel Lin | 94e85a3 | 2012-04-13 09:30:05 +0800 | [diff] [blame] | 311 | if (min_vol < desc->min) |
| 312 | min_vol = desc->min; |
| 313 | |
| 314 | selector = DIV_ROUND_UP(min_vol - desc->min, desc->step); |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 315 | |
Axel Lin | 854f73e | 2012-12-29 09:38:50 +0800 | [diff] [blame] | 316 | if (desc->min + desc->step * selector > desc->max) |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 317 | return -EINVAL; |
| 318 | |
Axel Lin | 5b5e977 | 2012-03-09 11:31:08 +0800 | [diff] [blame] | 319 | return selector; |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 320 | } |
| 321 | |
Sangbeom Kim | df2643c | 2012-06-13 17:28:18 +0900 | [diff] [blame] | 322 | static inline int s5m8767_set_high(struct s5m8767_info *s5m8767) |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 323 | { |
| 324 | int temp_index = s5m8767->buck_gpioindex; |
| 325 | |
| 326 | gpio_set_value(s5m8767->buck_gpios[0], (temp_index >> 2) & 0x1); |
| 327 | gpio_set_value(s5m8767->buck_gpios[1], (temp_index >> 1) & 0x1); |
| 328 | gpio_set_value(s5m8767->buck_gpios[2], temp_index & 0x1); |
Sangbeom Kim | df2643c | 2012-06-13 17:28:18 +0900 | [diff] [blame] | 329 | |
| 330 | return 0; |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 331 | } |
| 332 | |
Sangbeom Kim | df2643c | 2012-06-13 17:28:18 +0900 | [diff] [blame] | 333 | static inline int s5m8767_set_low(struct s5m8767_info *s5m8767) |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 334 | { |
| 335 | int temp_index = s5m8767->buck_gpioindex; |
| 336 | |
| 337 | gpio_set_value(s5m8767->buck_gpios[2], temp_index & 0x1); |
| 338 | gpio_set_value(s5m8767->buck_gpios[1], (temp_index >> 1) & 0x1); |
| 339 | gpio_set_value(s5m8767->buck_gpios[0], (temp_index >> 2) & 0x1); |
Sangbeom Kim | df2643c | 2012-06-13 17:28:18 +0900 | [diff] [blame] | 340 | |
| 341 | return 0; |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 342 | } |
| 343 | |
Sangbeom Kim | df2643c | 2012-06-13 17:28:18 +0900 | [diff] [blame] | 344 | static int s5m8767_set_voltage_sel(struct regulator_dev *rdev, |
| 345 | unsigned selector) |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 346 | { |
| 347 | struct s5m8767_info *s5m8767 = rdev_get_drvdata(rdev); |
Axel Lin | 321d2ab | 2012-04-10 14:05:44 +0800 | [diff] [blame] | 348 | int reg_id = rdev_get_id(rdev); |
Axel Lin | 31a932e | 2013-01-18 09:55:06 +0800 | [diff] [blame^] | 349 | int old_index, index = 0; |
Axel Lin | 321d2ab | 2012-04-10 14:05:44 +0800 | [diff] [blame] | 350 | u8 *buck234_vol = NULL; |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 351 | |
| 352 | switch (reg_id) { |
Axel Lin | 321d2ab | 2012-04-10 14:05:44 +0800 | [diff] [blame] | 353 | case S5M8767_LDO1 ... S5M8767_LDO28: |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 354 | break; |
Axel Lin | 321d2ab | 2012-04-10 14:05:44 +0800 | [diff] [blame] | 355 | case S5M8767_BUCK1 ... S5M8767_BUCK6: |
Axel Lin | 321d2ab | 2012-04-10 14:05:44 +0800 | [diff] [blame] | 356 | if (reg_id == S5M8767_BUCK2 && s5m8767->buck2_gpiodvs) |
| 357 | buck234_vol = &s5m8767->buck2_vol[0]; |
| 358 | else if (reg_id == S5M8767_BUCK3 && s5m8767->buck3_gpiodvs) |
| 359 | buck234_vol = &s5m8767->buck3_vol[0]; |
| 360 | else if (reg_id == S5M8767_BUCK4 && s5m8767->buck4_gpiodvs) |
| 361 | buck234_vol = &s5m8767->buck4_vol[0]; |
| 362 | break; |
| 363 | case S5M8767_BUCK7 ... S5M8767_BUCK8: |
| 364 | return -EINVAL; |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 365 | case S5M8767_BUCK9: |
Axel Lin | 321d2ab | 2012-04-10 14:05:44 +0800 | [diff] [blame] | 366 | break; |
| 367 | default: |
| 368 | return -EINVAL; |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 369 | } |
| 370 | |
Axel Lin | 321d2ab | 2012-04-10 14:05:44 +0800 | [diff] [blame] | 371 | /* buck234_vol != NULL means to control buck234 voltage via DVS GPIO */ |
| 372 | if (buck234_vol) { |
Sangbeom Kim | df2643c | 2012-06-13 17:28:18 +0900 | [diff] [blame] | 373 | while (*buck234_vol != selector) { |
Axel Lin | 321d2ab | 2012-04-10 14:05:44 +0800 | [diff] [blame] | 374 | buck234_vol++; |
| 375 | index++; |
| 376 | } |
| 377 | old_index = s5m8767->buck_gpioindex; |
| 378 | s5m8767->buck_gpioindex = index; |
| 379 | |
| 380 | if (index > old_index) |
Sangbeom Kim | df2643c | 2012-06-13 17:28:18 +0900 | [diff] [blame] | 381 | return s5m8767_set_high(s5m8767); |
Axel Lin | 321d2ab | 2012-04-10 14:05:44 +0800 | [diff] [blame] | 382 | else |
Sangbeom Kim | df2643c | 2012-06-13 17:28:18 +0900 | [diff] [blame] | 383 | return s5m8767_set_low(s5m8767); |
Axel Lin | 321d2ab | 2012-04-10 14:05:44 +0800 | [diff] [blame] | 384 | } else { |
Axel Lin | 31a932e | 2013-01-18 09:55:06 +0800 | [diff] [blame^] | 385 | return regulator_set_voltage_sel_regmap(rdev, selector); |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 386 | } |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 387 | } |
| 388 | |
| 389 | static int s5m8767_set_voltage_time_sel(struct regulator_dev *rdev, |
| 390 | unsigned int old_sel, |
| 391 | unsigned int new_sel) |
| 392 | { |
| 393 | struct s5m8767_info *s5m8767 = rdev_get_drvdata(rdev); |
Sangbeom Kim | 63063bf | 2012-07-11 21:06:55 +0900 | [diff] [blame] | 394 | const struct sec_voltage_desc *desc; |
Axel Lin | 20a14b8 | 2012-01-31 15:13:31 +0800 | [diff] [blame] | 395 | int reg_id = rdev_get_id(rdev); |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 396 | |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 397 | desc = reg_voltage_map[reg_id]; |
| 398 | |
Sangbeom Kim | 9d88fc0 | 2012-06-13 17:27:16 +0900 | [diff] [blame] | 399 | if ((old_sel < new_sel) && s5m8767->ramp_delay) |
Axel Lin | 89e0f0e | 2012-02-24 14:52:45 +0800 | [diff] [blame] | 400 | return DIV_ROUND_UP(desc->step * (new_sel - old_sel), |
Sangbeom Kim | 0f8b9c7 | 2012-03-09 16:28:10 +0900 | [diff] [blame] | 401 | s5m8767->ramp_delay * 1000); |
Axel Lin | 89e0f0e | 2012-02-24 14:52:45 +0800 | [diff] [blame] | 402 | return 0; |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 403 | } |
| 404 | |
Axel Lin | d35aad0 | 2012-04-10 14:07:15 +0800 | [diff] [blame] | 405 | static struct regulator_ops s5m8767_ops = { |
Axel Lin | e2eb169 | 2012-06-18 14:25:27 +0800 | [diff] [blame] | 406 | .list_voltage = regulator_list_voltage_linear, |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 407 | .is_enabled = s5m8767_reg_is_enabled, |
| 408 | .enable = s5m8767_reg_enable, |
| 409 | .disable = s5m8767_reg_disable, |
Axel Lin | 31a932e | 2013-01-18 09:55:06 +0800 | [diff] [blame^] | 410 | .get_voltage_sel = regulator_get_voltage_sel_regmap, |
Sangbeom Kim | df2643c | 2012-06-13 17:28:18 +0900 | [diff] [blame] | 411 | .set_voltage_sel = s5m8767_set_voltage_sel, |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 412 | .set_voltage_time_sel = s5m8767_set_voltage_time_sel, |
| 413 | }; |
| 414 | |
Axel Lin | e2eb169 | 2012-06-18 14:25:27 +0800 | [diff] [blame] | 415 | static struct regulator_ops s5m8767_buck78_ops = { |
| 416 | .is_enabled = s5m8767_reg_is_enabled, |
| 417 | .enable = s5m8767_reg_enable, |
| 418 | .disable = s5m8767_reg_disable, |
| 419 | }; |
| 420 | |
Axel Lin | 65896e7 | 2012-04-10 14:08:19 +0800 | [diff] [blame] | 421 | #define s5m8767_regulator_desc(_name) { \ |
| 422 | .name = #_name, \ |
| 423 | .id = S5M8767_##_name, \ |
| 424 | .ops = &s5m8767_ops, \ |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 425 | .type = REGULATOR_VOLTAGE, \ |
| 426 | .owner = THIS_MODULE, \ |
| 427 | } |
| 428 | |
Axel Lin | e2eb169 | 2012-06-18 14:25:27 +0800 | [diff] [blame] | 429 | #define s5m8767_regulator_buck78_desc(_name) { \ |
| 430 | .name = #_name, \ |
| 431 | .id = S5M8767_##_name, \ |
| 432 | .ops = &s5m8767_buck78_ops, \ |
| 433 | .type = REGULATOR_VOLTAGE, \ |
| 434 | .owner = THIS_MODULE, \ |
| 435 | } |
| 436 | |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 437 | static struct regulator_desc regulators[] = { |
Axel Lin | 65896e7 | 2012-04-10 14:08:19 +0800 | [diff] [blame] | 438 | s5m8767_regulator_desc(LDO1), |
| 439 | s5m8767_regulator_desc(LDO2), |
| 440 | s5m8767_regulator_desc(LDO3), |
| 441 | s5m8767_regulator_desc(LDO4), |
| 442 | s5m8767_regulator_desc(LDO5), |
| 443 | s5m8767_regulator_desc(LDO6), |
| 444 | s5m8767_regulator_desc(LDO7), |
| 445 | s5m8767_regulator_desc(LDO8), |
| 446 | s5m8767_regulator_desc(LDO9), |
| 447 | s5m8767_regulator_desc(LDO10), |
| 448 | s5m8767_regulator_desc(LDO11), |
| 449 | s5m8767_regulator_desc(LDO12), |
| 450 | s5m8767_regulator_desc(LDO13), |
| 451 | s5m8767_regulator_desc(LDO14), |
| 452 | s5m8767_regulator_desc(LDO15), |
| 453 | s5m8767_regulator_desc(LDO16), |
| 454 | s5m8767_regulator_desc(LDO17), |
| 455 | s5m8767_regulator_desc(LDO18), |
| 456 | s5m8767_regulator_desc(LDO19), |
| 457 | s5m8767_regulator_desc(LDO20), |
| 458 | s5m8767_regulator_desc(LDO21), |
| 459 | s5m8767_regulator_desc(LDO22), |
| 460 | s5m8767_regulator_desc(LDO23), |
| 461 | s5m8767_regulator_desc(LDO24), |
| 462 | s5m8767_regulator_desc(LDO25), |
| 463 | s5m8767_regulator_desc(LDO26), |
| 464 | s5m8767_regulator_desc(LDO27), |
| 465 | s5m8767_regulator_desc(LDO28), |
| 466 | s5m8767_regulator_desc(BUCK1), |
| 467 | s5m8767_regulator_desc(BUCK2), |
| 468 | s5m8767_regulator_desc(BUCK3), |
| 469 | s5m8767_regulator_desc(BUCK4), |
| 470 | s5m8767_regulator_desc(BUCK5), |
| 471 | s5m8767_regulator_desc(BUCK6), |
Axel Lin | e2eb169 | 2012-06-18 14:25:27 +0800 | [diff] [blame] | 472 | s5m8767_regulator_buck78_desc(BUCK7), |
| 473 | s5m8767_regulator_buck78_desc(BUCK8), |
Axel Lin | 65896e7 | 2012-04-10 14:08:19 +0800 | [diff] [blame] | 474 | s5m8767_regulator_desc(BUCK9), |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 475 | }; |
| 476 | |
Bill Pemberton | a502357 | 2012-11-19 13:22:22 -0500 | [diff] [blame] | 477 | static int s5m8767_pmic_probe(struct platform_device *pdev) |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 478 | { |
Sangbeom Kim | 63063bf | 2012-07-11 21:06:55 +0900 | [diff] [blame] | 479 | struct sec_pmic_dev *iodev = dev_get_drvdata(pdev->dev.parent); |
| 480 | struct sec_platform_data *pdata = dev_get_platdata(iodev->dev); |
Mark Brown | c172708d | 2012-04-04 00:50:22 +0100 | [diff] [blame] | 481 | struct regulator_config config = { }; |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 482 | struct regulator_dev **rdev; |
| 483 | struct s5m8767_info *s5m8767; |
Sangbeom Kim | c848bc8 | 2012-06-18 09:49:20 +0900 | [diff] [blame] | 484 | int i, ret, size, buck_init; |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 485 | |
| 486 | if (!pdata) { |
| 487 | dev_err(pdev->dev.parent, "Platform data not supplied\n"); |
| 488 | return -ENODEV; |
| 489 | } |
| 490 | |
Axel Lin | 6c4efe2 | 2012-03-10 08:43:02 +0800 | [diff] [blame] | 491 | if (pdata->buck2_gpiodvs) { |
| 492 | if (pdata->buck3_gpiodvs || pdata->buck4_gpiodvs) { |
| 493 | dev_err(&pdev->dev, "S5M8767 GPIO DVS NOT VALID\n"); |
| 494 | return -EINVAL; |
| 495 | } |
| 496 | } |
| 497 | |
| 498 | if (pdata->buck3_gpiodvs) { |
| 499 | if (pdata->buck2_gpiodvs || pdata->buck4_gpiodvs) { |
| 500 | dev_err(&pdev->dev, "S5M8767 GPIO DVS NOT VALID\n"); |
| 501 | return -EINVAL; |
| 502 | } |
| 503 | } |
| 504 | |
| 505 | if (pdata->buck4_gpiodvs) { |
| 506 | if (pdata->buck2_gpiodvs || pdata->buck3_gpiodvs) { |
| 507 | dev_err(&pdev->dev, "S5M8767 GPIO DVS NOT VALID\n"); |
| 508 | return -EINVAL; |
| 509 | } |
| 510 | } |
| 511 | |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 512 | s5m8767 = devm_kzalloc(&pdev->dev, sizeof(struct s5m8767_info), |
| 513 | GFP_KERNEL); |
| 514 | if (!s5m8767) |
| 515 | return -ENOMEM; |
| 516 | |
| 517 | size = sizeof(struct regulator_dev *) * (S5M8767_REG_MAX - 2); |
| 518 | s5m8767->rdev = devm_kzalloc(&pdev->dev, size, GFP_KERNEL); |
| 519 | if (!s5m8767->rdev) |
| 520 | return -ENOMEM; |
| 521 | |
| 522 | rdev = s5m8767->rdev; |
| 523 | s5m8767->dev = &pdev->dev; |
| 524 | s5m8767->iodev = iodev; |
Amit Daniel Kachhap | 9bb096f | 2012-12-10 18:19:39 +0530 | [diff] [blame] | 525 | s5m8767->num_regulators = pdata->num_regulators; |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 526 | platform_set_drvdata(pdev, s5m8767); |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 527 | |
| 528 | s5m8767->buck_gpioindex = pdata->buck_default_idx; |
| 529 | s5m8767->buck2_gpiodvs = pdata->buck2_gpiodvs; |
| 530 | s5m8767->buck3_gpiodvs = pdata->buck3_gpiodvs; |
| 531 | s5m8767->buck4_gpiodvs = pdata->buck4_gpiodvs; |
| 532 | s5m8767->buck_gpios[0] = pdata->buck_gpios[0]; |
| 533 | s5m8767->buck_gpios[1] = pdata->buck_gpios[1]; |
| 534 | s5m8767->buck_gpios[2] = pdata->buck_gpios[2]; |
Sangbeom Kim | c848bc8 | 2012-06-18 09:49:20 +0900 | [diff] [blame] | 535 | s5m8767->buck_ds[0] = pdata->buck_ds[0]; |
| 536 | s5m8767->buck_ds[1] = pdata->buck_ds[1]; |
| 537 | s5m8767->buck_ds[2] = pdata->buck_ds[2]; |
| 538 | |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 539 | s5m8767->ramp_delay = pdata->buck_ramp_delay; |
| 540 | s5m8767->buck2_ramp = pdata->buck2_ramp_enable; |
| 541 | s5m8767->buck3_ramp = pdata->buck3_ramp_enable; |
| 542 | s5m8767->buck4_ramp = pdata->buck4_ramp_enable; |
Sangbeom Kim | 7e44bb8 | 2012-03-09 17:55:34 +0900 | [diff] [blame] | 543 | s5m8767->opmode = pdata->opmode; |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 544 | |
Sangbeom Kim | c848bc8 | 2012-06-18 09:49:20 +0900 | [diff] [blame] | 545 | buck_init = s5m8767_convert_voltage_to_sel(&buck_voltage_val2, |
Axel Lin | 854f73e | 2012-12-29 09:38:50 +0800 | [diff] [blame] | 546 | pdata->buck2_init); |
Sangbeom Kim | c848bc8 | 2012-06-18 09:49:20 +0900 | [diff] [blame] | 547 | |
Samuel Ortiz | 938e05b | 2012-07-31 00:36:16 +0200 | [diff] [blame] | 548 | sec_reg_write(s5m8767->iodev, S5M8767_REG_BUCK2DVS2, buck_init); |
Sangbeom Kim | c848bc8 | 2012-06-18 09:49:20 +0900 | [diff] [blame] | 549 | |
| 550 | buck_init = s5m8767_convert_voltage_to_sel(&buck_voltage_val2, |
Axel Lin | 854f73e | 2012-12-29 09:38:50 +0800 | [diff] [blame] | 551 | pdata->buck3_init); |
Sangbeom Kim | c848bc8 | 2012-06-18 09:49:20 +0900 | [diff] [blame] | 552 | |
Samuel Ortiz | 938e05b | 2012-07-31 00:36:16 +0200 | [diff] [blame] | 553 | sec_reg_write(s5m8767->iodev, S5M8767_REG_BUCK3DVS2, buck_init); |
Sangbeom Kim | c848bc8 | 2012-06-18 09:49:20 +0900 | [diff] [blame] | 554 | |
| 555 | buck_init = s5m8767_convert_voltage_to_sel(&buck_voltage_val2, |
Axel Lin | 854f73e | 2012-12-29 09:38:50 +0800 | [diff] [blame] | 556 | pdata->buck4_init); |
Sangbeom Kim | c848bc8 | 2012-06-18 09:49:20 +0900 | [diff] [blame] | 557 | |
Samuel Ortiz | 938e05b | 2012-07-31 00:36:16 +0200 | [diff] [blame] | 558 | sec_reg_write(s5m8767->iodev, S5M8767_REG_BUCK4DVS2, buck_init); |
Sangbeom Kim | c848bc8 | 2012-06-18 09:49:20 +0900 | [diff] [blame] | 559 | |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 560 | for (i = 0; i < 8; i++) { |
| 561 | if (s5m8767->buck2_gpiodvs) { |
| 562 | s5m8767->buck2_vol[i] = |
Axel Lin | 5b5e977 | 2012-03-09 11:31:08 +0800 | [diff] [blame] | 563 | s5m8767_convert_voltage_to_sel( |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 564 | &buck_voltage_val2, |
Axel Lin | 854f73e | 2012-12-29 09:38:50 +0800 | [diff] [blame] | 565 | pdata->buck2_voltage[i]); |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 566 | } |
| 567 | |
| 568 | if (s5m8767->buck3_gpiodvs) { |
| 569 | s5m8767->buck3_vol[i] = |
Axel Lin | 5b5e977 | 2012-03-09 11:31:08 +0800 | [diff] [blame] | 570 | s5m8767_convert_voltage_to_sel( |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 571 | &buck_voltage_val2, |
Axel Lin | 854f73e | 2012-12-29 09:38:50 +0800 | [diff] [blame] | 572 | pdata->buck3_voltage[i]); |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 573 | } |
| 574 | |
| 575 | if (s5m8767->buck4_gpiodvs) { |
| 576 | s5m8767->buck4_vol[i] = |
Axel Lin | 5b5e977 | 2012-03-09 11:31:08 +0800 | [diff] [blame] | 577 | s5m8767_convert_voltage_to_sel( |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 578 | &buck_voltage_val2, |
Axel Lin | 854f73e | 2012-12-29 09:38:50 +0800 | [diff] [blame] | 579 | pdata->buck4_voltage[i]); |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 580 | } |
| 581 | } |
| 582 | |
Amit Daniel Kachhap | 76c854d | 2012-12-10 18:19:41 +0530 | [diff] [blame] | 583 | if (pdata->buck2_gpiodvs || pdata->buck3_gpiodvs || |
| 584 | pdata->buck4_gpiodvs) { |
| 585 | |
| 586 | if (!gpio_is_valid(pdata->buck_gpios[0]) || |
| 587 | !gpio_is_valid(pdata->buck_gpios[1]) || |
| 588 | !gpio_is_valid(pdata->buck_gpios[2])) { |
| 589 | dev_err(&pdev->dev, "GPIO NOT VALID\n"); |
| 590 | return -EINVAL; |
| 591 | } |
| 592 | |
Axel Lin | 5febb3c | 2012-07-05 23:12:49 +0800 | [diff] [blame] | 593 | ret = devm_gpio_request(&pdev->dev, pdata->buck_gpios[0], |
| 594 | "S5M8767 SET1"); |
| 595 | if (ret) |
| 596 | return ret; |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 597 | |
Axel Lin | 5febb3c | 2012-07-05 23:12:49 +0800 | [diff] [blame] | 598 | ret = devm_gpio_request(&pdev->dev, pdata->buck_gpios[1], |
| 599 | "S5M8767 SET2"); |
| 600 | if (ret) |
| 601 | return ret; |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 602 | |
Axel Lin | 5febb3c | 2012-07-05 23:12:49 +0800 | [diff] [blame] | 603 | ret = devm_gpio_request(&pdev->dev, pdata->buck_gpios[2], |
| 604 | "S5M8767 SET3"); |
| 605 | if (ret) |
| 606 | return ret; |
| 607 | |
Sangbeom Kim | c848bc8 | 2012-06-18 09:49:20 +0900 | [diff] [blame] | 608 | /* SET1 GPIO */ |
| 609 | gpio_direction_output(pdata->buck_gpios[0], |
| 610 | (s5m8767->buck_gpioindex >> 2) & 0x1); |
| 611 | /* SET2 GPIO */ |
| 612 | gpio_direction_output(pdata->buck_gpios[1], |
| 613 | (s5m8767->buck_gpioindex >> 1) & 0x1); |
| 614 | /* SET3 GPIO */ |
| 615 | gpio_direction_output(pdata->buck_gpios[2], |
| 616 | (s5m8767->buck_gpioindex >> 0) & 0x1); |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 617 | } |
| 618 | |
Axel Lin | 5febb3c | 2012-07-05 23:12:49 +0800 | [diff] [blame] | 619 | ret = devm_gpio_request(&pdev->dev, pdata->buck_ds[0], "S5M8767 DS2"); |
| 620 | if (ret) |
| 621 | return ret; |
Sangbeom Kim | c848bc8 | 2012-06-18 09:49:20 +0900 | [diff] [blame] | 622 | |
Axel Lin | 5febb3c | 2012-07-05 23:12:49 +0800 | [diff] [blame] | 623 | ret = devm_gpio_request(&pdev->dev, pdata->buck_ds[1], "S5M8767 DS3"); |
| 624 | if (ret) |
| 625 | return ret; |
Sangbeom Kim | c848bc8 | 2012-06-18 09:49:20 +0900 | [diff] [blame] | 626 | |
Axel Lin | 5febb3c | 2012-07-05 23:12:49 +0800 | [diff] [blame] | 627 | ret = devm_gpio_request(&pdev->dev, pdata->buck_ds[2], "S5M8767 DS4"); |
| 628 | if (ret) |
| 629 | return ret; |
Sangbeom Kim | c848bc8 | 2012-06-18 09:49:20 +0900 | [diff] [blame] | 630 | |
| 631 | /* DS2 GPIO */ |
| 632 | gpio_direction_output(pdata->buck_ds[0], 0x0); |
| 633 | /* DS3 GPIO */ |
| 634 | gpio_direction_output(pdata->buck_ds[1], 0x0); |
| 635 | /* DS4 GPIO */ |
| 636 | gpio_direction_output(pdata->buck_ds[2], 0x0); |
| 637 | |
| 638 | if (pdata->buck2_gpiodvs || pdata->buck3_gpiodvs || |
| 639 | pdata->buck4_gpiodvs) { |
Linus Torvalds | 3e701cd | 2012-07-30 12:41:17 -0700 | [diff] [blame] | 640 | sec_reg_update(s5m8767->iodev, S5M8767_REG_BUCK2CTRL, |
Sangbeom Kim | c848bc8 | 2012-06-18 09:49:20 +0900 | [diff] [blame] | 641 | (pdata->buck2_gpiodvs) ? (1 << 1) : (0 << 1), |
| 642 | 1 << 1); |
Linus Torvalds | 3e701cd | 2012-07-30 12:41:17 -0700 | [diff] [blame] | 643 | sec_reg_update(s5m8767->iodev, S5M8767_REG_BUCK3CTRL, |
Sangbeom Kim | c848bc8 | 2012-06-18 09:49:20 +0900 | [diff] [blame] | 644 | (pdata->buck3_gpiodvs) ? (1 << 1) : (0 << 1), |
| 645 | 1 << 1); |
Linus Torvalds | 3e701cd | 2012-07-30 12:41:17 -0700 | [diff] [blame] | 646 | sec_reg_update(s5m8767->iodev, S5M8767_REG_BUCK4CTRL, |
Sangbeom Kim | c848bc8 | 2012-06-18 09:49:20 +0900 | [diff] [blame] | 647 | (pdata->buck4_gpiodvs) ? (1 << 1) : (0 << 1), |
| 648 | 1 << 1); |
| 649 | } |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 650 | |
| 651 | /* Initialize GPIO DVS registers */ |
| 652 | for (i = 0; i < 8; i++) { |
| 653 | if (s5m8767->buck2_gpiodvs) { |
Sangbeom Kim | 63063bf | 2012-07-11 21:06:55 +0900 | [diff] [blame] | 654 | sec_reg_write(s5m8767->iodev, S5M8767_REG_BUCK2DVS1 + i, |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 655 | s5m8767->buck2_vol[i]); |
| 656 | } |
| 657 | |
| 658 | if (s5m8767->buck3_gpiodvs) { |
Sangbeom Kim | 63063bf | 2012-07-11 21:06:55 +0900 | [diff] [blame] | 659 | sec_reg_write(s5m8767->iodev, S5M8767_REG_BUCK3DVS1 + i, |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 660 | s5m8767->buck3_vol[i]); |
| 661 | } |
| 662 | |
| 663 | if (s5m8767->buck4_gpiodvs) { |
Sangbeom Kim | 63063bf | 2012-07-11 21:06:55 +0900 | [diff] [blame] | 664 | sec_reg_write(s5m8767->iodev, S5M8767_REG_BUCK4DVS1 + i, |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 665 | s5m8767->buck4_vol[i]); |
| 666 | } |
| 667 | } |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 668 | |
| 669 | if (s5m8767->buck2_ramp) |
Sangbeom Kim | 63063bf | 2012-07-11 21:06:55 +0900 | [diff] [blame] | 670 | sec_reg_update(s5m8767->iodev, S5M8767_REG_DVSRAMP, 0x08, 0x08); |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 671 | |
| 672 | if (s5m8767->buck3_ramp) |
Sangbeom Kim | 63063bf | 2012-07-11 21:06:55 +0900 | [diff] [blame] | 673 | sec_reg_update(s5m8767->iodev, S5M8767_REG_DVSRAMP, 0x04, 0x04); |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 674 | |
| 675 | if (s5m8767->buck4_ramp) |
Sangbeom Kim | 63063bf | 2012-07-11 21:06:55 +0900 | [diff] [blame] | 676 | sec_reg_update(s5m8767->iodev, S5M8767_REG_DVSRAMP, 0x02, 0x02); |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 677 | |
| 678 | if (s5m8767->buck2_ramp || s5m8767->buck3_ramp |
| 679 | || s5m8767->buck4_ramp) { |
| 680 | switch (s5m8767->ramp_delay) { |
Sangbeom Kim | 1af142c | 2012-06-13 17:27:54 +0900 | [diff] [blame] | 681 | case 5: |
Sangbeom Kim | 63063bf | 2012-07-11 21:06:55 +0900 | [diff] [blame] | 682 | sec_reg_update(s5m8767->iodev, S5M8767_REG_DVSRAMP, |
Sangbeom Kim | 1af142c | 2012-06-13 17:27:54 +0900 | [diff] [blame] | 683 | 0x40, 0xf0); |
| 684 | break; |
| 685 | case 10: |
Linus Torvalds | 3e701cd | 2012-07-30 12:41:17 -0700 | [diff] [blame] | 686 | sec_reg_update(s5m8767->iodev, S5M8767_REG_DVSRAMP, |
Sangbeom Kim | 1af142c | 2012-06-13 17:27:54 +0900 | [diff] [blame] | 687 | 0x90, 0xf0); |
Axel Lin | 047ec22 | 2012-01-12 14:57:09 +0800 | [diff] [blame] | 688 | break; |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 689 | case 25: |
Sangbeom Kim | 63063bf | 2012-07-11 21:06:55 +0900 | [diff] [blame] | 690 | sec_reg_update(s5m8767->iodev, S5M8767_REG_DVSRAMP, |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 691 | 0xd0, 0xf0); |
Axel Lin | 047ec22 | 2012-01-12 14:57:09 +0800 | [diff] [blame] | 692 | break; |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 693 | case 50: |
Sangbeom Kim | 63063bf | 2012-07-11 21:06:55 +0900 | [diff] [blame] | 694 | sec_reg_update(s5m8767->iodev, S5M8767_REG_DVSRAMP, |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 695 | 0xe0, 0xf0); |
Axel Lin | 047ec22 | 2012-01-12 14:57:09 +0800 | [diff] [blame] | 696 | break; |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 697 | case 100: |
Sangbeom Kim | 63063bf | 2012-07-11 21:06:55 +0900 | [diff] [blame] | 698 | sec_reg_update(s5m8767->iodev, S5M8767_REG_DVSRAMP, |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 699 | 0xf0, 0xf0); |
Axel Lin | 047ec22 | 2012-01-12 14:57:09 +0800 | [diff] [blame] | 700 | break; |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 701 | default: |
Sangbeom Kim | 63063bf | 2012-07-11 21:06:55 +0900 | [diff] [blame] | 702 | sec_reg_update(s5m8767->iodev, S5M8767_REG_DVSRAMP, |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 703 | 0x90, 0xf0); |
| 704 | } |
| 705 | } |
| 706 | |
| 707 | for (i = 0; i < pdata->num_regulators; i++) { |
Sangbeom Kim | 63063bf | 2012-07-11 21:06:55 +0900 | [diff] [blame] | 708 | const struct sec_voltage_desc *desc; |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 709 | int id = pdata->regulators[i].id; |
| 710 | |
| 711 | desc = reg_voltage_map[id]; |
Axel Lin | e2eb169 | 2012-06-18 14:25:27 +0800 | [diff] [blame] | 712 | if (desc) { |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 713 | regulators[id].n_voltages = |
| 714 | (desc->max - desc->min) / desc->step + 1; |
Axel Lin | e2eb169 | 2012-06-18 14:25:27 +0800 | [diff] [blame] | 715 | regulators[id].min_uV = desc->min; |
| 716 | regulators[id].uV_step = desc->step; |
Axel Lin | 31a932e | 2013-01-18 09:55:06 +0800 | [diff] [blame^] | 717 | regulators[id].vsel_reg = |
| 718 | s5m8767_get_vsel_reg(id, s5m8767); |
| 719 | if (id < S5M8767_BUCK1) |
| 720 | regulators[id].vsel_mask = 0x3f; |
| 721 | else |
| 722 | regulators[id].vsel_mask = 0xff; |
Axel Lin | e2eb169 | 2012-06-18 14:25:27 +0800 | [diff] [blame] | 723 | } |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 724 | |
Mark Brown | c172708d | 2012-04-04 00:50:22 +0100 | [diff] [blame] | 725 | config.dev = s5m8767->dev; |
| 726 | config.init_data = pdata->regulators[i].initdata; |
| 727 | config.driver_data = s5m8767; |
Axel Lin | 31a932e | 2013-01-18 09:55:06 +0800 | [diff] [blame^] | 728 | config.regmap = iodev->regmap; |
Mark Brown | c172708d | 2012-04-04 00:50:22 +0100 | [diff] [blame] | 729 | |
| 730 | rdev[i] = regulator_register(®ulators[id], &config); |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 731 | if (IS_ERR(rdev[i])) { |
| 732 | ret = PTR_ERR(rdev[i]); |
| 733 | dev_err(s5m8767->dev, "regulator init failed for %d\n", |
| 734 | id); |
| 735 | rdev[i] = NULL; |
| 736 | goto err; |
| 737 | } |
| 738 | } |
| 739 | |
| 740 | return 0; |
| 741 | err: |
| 742 | for (i = 0; i < s5m8767->num_regulators; i++) |
| 743 | if (rdev[i]) |
| 744 | regulator_unregister(rdev[i]); |
| 745 | |
| 746 | return ret; |
| 747 | } |
| 748 | |
Bill Pemberton | 8dc995f | 2012-11-19 13:26:10 -0500 | [diff] [blame] | 749 | static int s5m8767_pmic_remove(struct platform_device *pdev) |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 750 | { |
| 751 | struct s5m8767_info *s5m8767 = platform_get_drvdata(pdev); |
| 752 | struct regulator_dev **rdev = s5m8767->rdev; |
| 753 | int i; |
| 754 | |
| 755 | for (i = 0; i < s5m8767->num_regulators; i++) |
| 756 | if (rdev[i]) |
| 757 | regulator_unregister(rdev[i]); |
| 758 | |
| 759 | return 0; |
| 760 | } |
| 761 | |
| 762 | static const struct platform_device_id s5m8767_pmic_id[] = { |
| 763 | { "s5m8767-pmic", 0}, |
| 764 | { }, |
| 765 | }; |
| 766 | MODULE_DEVICE_TABLE(platform, s5m8767_pmic_id); |
| 767 | |
| 768 | static struct platform_driver s5m8767_pmic_driver = { |
| 769 | .driver = { |
| 770 | .name = "s5m8767-pmic", |
| 771 | .owner = THIS_MODULE, |
| 772 | }, |
| 773 | .probe = s5m8767_pmic_probe, |
Bill Pemberton | 5eb9f2b | 2012-11-19 13:20:42 -0500 | [diff] [blame] | 774 | .remove = s5m8767_pmic_remove, |
Sangbeom Kim | 9767ec7 | 2012-01-09 19:10:25 +0900 | [diff] [blame] | 775 | .id_table = s5m8767_pmic_id, |
| 776 | }; |
| 777 | |
| 778 | static int __init s5m8767_pmic_init(void) |
| 779 | { |
| 780 | return platform_driver_register(&s5m8767_pmic_driver); |
| 781 | } |
| 782 | subsys_initcall(s5m8767_pmic_init); |
| 783 | |
| 784 | static void __exit s5m8767_pmic_exit(void) |
| 785 | { |
| 786 | platform_driver_unregister(&s5m8767_pmic_driver); |
| 787 | } |
| 788 | module_exit(s5m8767_pmic_exit); |
| 789 | |
| 790 | /* Module information */ |
| 791 | MODULE_AUTHOR("Sangbeom Kim <sbkim73@samsung.com>"); |
| 792 | MODULE_DESCRIPTION("SAMSUNG S5M8767 Regulator Driver"); |
| 793 | MODULE_LICENSE("GPL"); |