Chris Zhong | 2cd64ae | 2014-08-20 11:36:42 +0800 | [diff] [blame] | 1 | /* |
| 2 | * Regulator driver for Rockchip RK808 |
| 3 | * |
| 4 | * Copyright (c) 2014, Fuzhou Rockchip Electronics Co., Ltd |
| 5 | * |
| 6 | * Author: Chris Zhong <zyw@rock-chips.com> |
| 7 | * Author: Zhang Qing <zhangqing@rock-chips.com> |
| 8 | * |
| 9 | * This program is free software; you can redistribute it and/or modify it |
| 10 | * under the terms and conditions of the GNU General Public License, |
| 11 | * version 2, as published by the Free Software Foundation. |
| 12 | * |
| 13 | * This program is distributed in the hope it will be useful, but WITHOUT |
| 14 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 15 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 16 | * more details. |
Chris Zhong | 2cd64ae | 2014-08-20 11:36:42 +0800 | [diff] [blame] | 17 | */ |
| 18 | |
| 19 | #include <linux/module.h> |
Chris Zhong | 2cd64ae | 2014-08-20 11:36:42 +0800 | [diff] [blame] | 20 | #include <linux/i2c.h> |
Chris Zhong | 2cd64ae | 2014-08-20 11:36:42 +0800 | [diff] [blame] | 21 | #include <linux/mfd/rk808.h> |
Chris Zhong | 2cd64ae | 2014-08-20 11:36:42 +0800 | [diff] [blame] | 22 | #include <linux/of_device.h> |
| 23 | #include <linux/regulator/driver.h> |
| 24 | #include <linux/regulator/of_regulator.h> |
Chris Zhong | 571a401 | 2014-09-10 09:18:06 +0800 | [diff] [blame] | 25 | |
| 26 | /* Field Definitions */ |
Chris Zhong | 2cd64ae | 2014-08-20 11:36:42 +0800 | [diff] [blame] | 27 | #define RK808_BUCK_VSEL_MASK 0x3f |
| 28 | #define RK808_BUCK4_VSEL_MASK 0xf |
| 29 | #define RK808_LDO_VSEL_MASK 0x1f |
| 30 | |
Doug Anderson | 8af2522 | 2014-09-16 10:22:54 -0700 | [diff] [blame] | 31 | /* Ramp rate definitions for buck1 / buck2 only */ |
| 32 | #define RK808_RAMP_RATE_OFFSET 3 |
| 33 | #define RK808_RAMP_RATE_MASK (3 << RK808_RAMP_RATE_OFFSET) |
| 34 | #define RK808_RAMP_RATE_2MV_PER_US (0 << RK808_RAMP_RATE_OFFSET) |
| 35 | #define RK808_RAMP_RATE_4MV_PER_US (1 << RK808_RAMP_RATE_OFFSET) |
| 36 | #define RK808_RAMP_RATE_6MV_PER_US (2 << RK808_RAMP_RATE_OFFSET) |
| 37 | #define RK808_RAMP_RATE_10MV_PER_US (3 << RK808_RAMP_RATE_OFFSET) |
| 38 | |
| 39 | static const int rk808_buck_config_regs[] = { |
| 40 | RK808_BUCK1_CONFIG_REG, |
| 41 | RK808_BUCK2_CONFIG_REG, |
| 42 | RK808_BUCK3_CONFIG_REG, |
| 43 | RK808_BUCK4_CONFIG_REG, |
| 44 | }; |
| 45 | |
Chris Zhong | 2cd64ae | 2014-08-20 11:36:42 +0800 | [diff] [blame] | 46 | static const struct regulator_linear_range rk808_buck_voltage_ranges[] = { |
Chris Zhong | 1575e28 | 2014-09-30 17:44:54 +0800 | [diff] [blame] | 47 | REGULATOR_LINEAR_RANGE(712500, 0, 63, 12500), |
Chris Zhong | 2cd64ae | 2014-08-20 11:36:42 +0800 | [diff] [blame] | 48 | }; |
| 49 | |
| 50 | static const struct regulator_linear_range rk808_buck4_voltage_ranges[] = { |
| 51 | REGULATOR_LINEAR_RANGE(1800000, 0, 15, 100000), |
| 52 | }; |
| 53 | |
| 54 | static const struct regulator_linear_range rk808_ldo_voltage_ranges[] = { |
| 55 | REGULATOR_LINEAR_RANGE(1800000, 0, 16, 100000), |
| 56 | }; |
| 57 | |
| 58 | static const struct regulator_linear_range rk808_ldo3_voltage_ranges[] = { |
| 59 | REGULATOR_LINEAR_RANGE(800000, 0, 13, 100000), |
| 60 | REGULATOR_LINEAR_RANGE(2500000, 15, 15, 0), |
| 61 | }; |
| 62 | |
| 63 | static const struct regulator_linear_range rk808_ldo6_voltage_ranges[] = { |
| 64 | REGULATOR_LINEAR_RANGE(800000, 0, 17, 100000), |
| 65 | }; |
| 66 | |
Doug Anderson | 8af2522 | 2014-09-16 10:22:54 -0700 | [diff] [blame] | 67 | static int rk808_set_ramp_delay(struct regulator_dev *rdev, int ramp_delay) |
| 68 | { |
| 69 | unsigned int ramp_value = RK808_RAMP_RATE_10MV_PER_US; |
| 70 | unsigned int reg = rk808_buck_config_regs[rdev->desc->id - |
| 71 | RK808_ID_DCDC1]; |
| 72 | |
| 73 | switch (ramp_delay) { |
| 74 | case 1 ... 2000: |
| 75 | ramp_value = RK808_RAMP_RATE_2MV_PER_US; |
| 76 | break; |
| 77 | case 2001 ... 4000: |
| 78 | ramp_value = RK808_RAMP_RATE_4MV_PER_US; |
| 79 | break; |
| 80 | case 4001 ... 6000: |
| 81 | ramp_value = RK808_RAMP_RATE_6MV_PER_US; |
| 82 | break; |
| 83 | case 6001 ... 10000: |
| 84 | break; |
| 85 | default: |
| 86 | pr_warn("%s ramp_delay: %d not supported, setting 10000\n", |
| 87 | rdev->desc->name, ramp_delay); |
| 88 | } |
| 89 | |
| 90 | return regmap_update_bits(rdev->regmap, reg, |
| 91 | RK808_RAMP_RATE_MASK, ramp_value); |
| 92 | } |
| 93 | |
| 94 | static struct regulator_ops rk808_buck1_2_ops = { |
| 95 | .list_voltage = regulator_list_voltage_linear_range, |
| 96 | .map_voltage = regulator_map_voltage_linear_range, |
| 97 | .get_voltage_sel = regulator_get_voltage_sel_regmap, |
| 98 | .set_voltage_sel = regulator_set_voltage_sel_regmap, |
| 99 | .enable = regulator_enable_regmap, |
| 100 | .disable = regulator_disable_regmap, |
| 101 | .is_enabled = regulator_is_enabled_regmap, |
| 102 | .set_ramp_delay = rk808_set_ramp_delay, |
| 103 | }; |
| 104 | |
Chris Zhong | 2cd64ae | 2014-08-20 11:36:42 +0800 | [diff] [blame] | 105 | static struct regulator_ops rk808_reg_ops = { |
| 106 | .list_voltage = regulator_list_voltage_linear_range, |
| 107 | .map_voltage = regulator_map_voltage_linear_range, |
| 108 | .get_voltage_sel = regulator_get_voltage_sel_regmap, |
| 109 | .set_voltage_sel = regulator_set_voltage_sel_regmap, |
| 110 | .enable = regulator_enable_regmap, |
| 111 | .disable = regulator_disable_regmap, |
| 112 | .is_enabled = regulator_is_enabled_regmap, |
| 113 | }; |
| 114 | |
| 115 | static struct regulator_ops rk808_switch_ops = { |
| 116 | .enable = regulator_enable_regmap, |
| 117 | .disable = regulator_disable_regmap, |
| 118 | .is_enabled = regulator_is_enabled_regmap, |
| 119 | }; |
| 120 | |
| 121 | static const struct regulator_desc rk808_reg[] = { |
| 122 | { |
| 123 | .name = "DCDC_REG1", |
Doug Anderson | b8074eb | 2014-09-02 09:14:28 -0700 | [diff] [blame] | 124 | .supply_name = "vcc1", |
Chris Zhong | 2cd64ae | 2014-08-20 11:36:42 +0800 | [diff] [blame] | 125 | .id = RK808_ID_DCDC1, |
Doug Anderson | 8af2522 | 2014-09-16 10:22:54 -0700 | [diff] [blame] | 126 | .ops = &rk808_buck1_2_ops, |
Chris Zhong | 2cd64ae | 2014-08-20 11:36:42 +0800 | [diff] [blame] | 127 | .type = REGULATOR_VOLTAGE, |
| 128 | .n_voltages = 64, |
| 129 | .linear_ranges = rk808_buck_voltage_ranges, |
| 130 | .n_linear_ranges = ARRAY_SIZE(rk808_buck_voltage_ranges), |
| 131 | .vsel_reg = RK808_BUCK1_ON_VSEL_REG, |
| 132 | .vsel_mask = RK808_BUCK_VSEL_MASK, |
| 133 | .enable_reg = RK808_DCDC_EN_REG, |
| 134 | .enable_mask = BIT(0), |
| 135 | .owner = THIS_MODULE, |
| 136 | }, { |
| 137 | .name = "DCDC_REG2", |
Doug Anderson | b8074eb | 2014-09-02 09:14:28 -0700 | [diff] [blame] | 138 | .supply_name = "vcc2", |
Chris Zhong | 2cd64ae | 2014-08-20 11:36:42 +0800 | [diff] [blame] | 139 | .id = RK808_ID_DCDC2, |
Doug Anderson | 8af2522 | 2014-09-16 10:22:54 -0700 | [diff] [blame] | 140 | .ops = &rk808_buck1_2_ops, |
Chris Zhong | 2cd64ae | 2014-08-20 11:36:42 +0800 | [diff] [blame] | 141 | .type = REGULATOR_VOLTAGE, |
| 142 | .n_voltages = 64, |
| 143 | .linear_ranges = rk808_buck_voltage_ranges, |
| 144 | .n_linear_ranges = ARRAY_SIZE(rk808_buck_voltage_ranges), |
| 145 | .vsel_reg = RK808_BUCK2_ON_VSEL_REG, |
| 146 | .vsel_mask = RK808_BUCK_VSEL_MASK, |
| 147 | .enable_reg = RK808_DCDC_EN_REG, |
| 148 | .enable_mask = BIT(1), |
| 149 | .owner = THIS_MODULE, |
| 150 | }, { |
| 151 | .name = "DCDC_REG3", |
Doug Anderson | b8074eb | 2014-09-02 09:14:28 -0700 | [diff] [blame] | 152 | .supply_name = "vcc3", |
Chris Zhong | 2cd64ae | 2014-08-20 11:36:42 +0800 | [diff] [blame] | 153 | .id = RK808_ID_DCDC3, |
| 154 | .ops = &rk808_switch_ops, |
| 155 | .type = REGULATOR_VOLTAGE, |
| 156 | .n_voltages = 1, |
| 157 | .enable_reg = RK808_DCDC_EN_REG, |
| 158 | .enable_mask = BIT(2), |
| 159 | .owner = THIS_MODULE, |
| 160 | }, { |
| 161 | .name = "DCDC_REG4", |
Doug Anderson | b8074eb | 2014-09-02 09:14:28 -0700 | [diff] [blame] | 162 | .supply_name = "vcc4", |
Chris Zhong | 2cd64ae | 2014-08-20 11:36:42 +0800 | [diff] [blame] | 163 | .id = RK808_ID_DCDC4, |
| 164 | .ops = &rk808_reg_ops, |
| 165 | .type = REGULATOR_VOLTAGE, |
Axel Lin | 5a82067 | 2014-09-02 08:47:31 +0800 | [diff] [blame] | 166 | .n_voltages = 16, |
Chris Zhong | 2cd64ae | 2014-08-20 11:36:42 +0800 | [diff] [blame] | 167 | .linear_ranges = rk808_buck4_voltage_ranges, |
| 168 | .n_linear_ranges = ARRAY_SIZE(rk808_buck4_voltage_ranges), |
| 169 | .vsel_reg = RK808_BUCK4_ON_VSEL_REG, |
| 170 | .vsel_mask = RK808_BUCK4_VSEL_MASK, |
| 171 | .enable_reg = RK808_DCDC_EN_REG, |
| 172 | .enable_mask = BIT(3), |
| 173 | .owner = THIS_MODULE, |
| 174 | }, { |
| 175 | .name = "LDO_REG1", |
Doug Anderson | b8074eb | 2014-09-02 09:14:28 -0700 | [diff] [blame] | 176 | .supply_name = "vcc6", |
Chris Zhong | 2cd64ae | 2014-08-20 11:36:42 +0800 | [diff] [blame] | 177 | .id = RK808_ID_LDO1, |
| 178 | .ops = &rk808_reg_ops, |
| 179 | .type = REGULATOR_VOLTAGE, |
| 180 | .n_voltages = 17, |
| 181 | .linear_ranges = rk808_ldo_voltage_ranges, |
| 182 | .n_linear_ranges = ARRAY_SIZE(rk808_ldo_voltage_ranges), |
| 183 | .vsel_reg = RK808_LDO1_ON_VSEL_REG, |
| 184 | .vsel_mask = RK808_LDO_VSEL_MASK, |
| 185 | .enable_reg = RK808_LDO_EN_REG, |
| 186 | .enable_mask = BIT(0), |
| 187 | .owner = THIS_MODULE, |
| 188 | }, { |
| 189 | .name = "LDO_REG2", |
Doug Anderson | b8074eb | 2014-09-02 09:14:28 -0700 | [diff] [blame] | 190 | .supply_name = "vcc6", |
Chris Zhong | 2cd64ae | 2014-08-20 11:36:42 +0800 | [diff] [blame] | 191 | .id = RK808_ID_LDO2, |
| 192 | .ops = &rk808_reg_ops, |
| 193 | .type = REGULATOR_VOLTAGE, |
| 194 | .n_voltages = 17, |
| 195 | .linear_ranges = rk808_ldo_voltage_ranges, |
| 196 | .n_linear_ranges = ARRAY_SIZE(rk808_ldo_voltage_ranges), |
| 197 | .vsel_reg = RK808_LDO2_ON_VSEL_REG, |
| 198 | .vsel_mask = RK808_LDO_VSEL_MASK, |
| 199 | .enable_reg = RK808_LDO_EN_REG, |
| 200 | .enable_mask = BIT(1), |
| 201 | .owner = THIS_MODULE, |
| 202 | }, { |
| 203 | .name = "LDO_REG3", |
Doug Anderson | b8074eb | 2014-09-02 09:14:28 -0700 | [diff] [blame] | 204 | .supply_name = "vcc7", |
Chris Zhong | 2cd64ae | 2014-08-20 11:36:42 +0800 | [diff] [blame] | 205 | .id = RK808_ID_LDO3, |
| 206 | .ops = &rk808_reg_ops, |
| 207 | .type = REGULATOR_VOLTAGE, |
| 208 | .n_voltages = 16, |
| 209 | .linear_ranges = rk808_ldo3_voltage_ranges, |
| 210 | .n_linear_ranges = ARRAY_SIZE(rk808_ldo3_voltage_ranges), |
| 211 | .vsel_reg = RK808_LDO3_ON_VSEL_REG, |
| 212 | .vsel_mask = RK808_BUCK4_VSEL_MASK, |
| 213 | .enable_reg = RK808_LDO_EN_REG, |
| 214 | .enable_mask = BIT(2), |
| 215 | .owner = THIS_MODULE, |
| 216 | }, { |
| 217 | .name = "LDO_REG4", |
Doug Anderson | b8074eb | 2014-09-02 09:14:28 -0700 | [diff] [blame] | 218 | .supply_name = "vcc9", |
Chris Zhong | 2cd64ae | 2014-08-20 11:36:42 +0800 | [diff] [blame] | 219 | .id = RK808_ID_LDO4, |
| 220 | .ops = &rk808_reg_ops, |
| 221 | .type = REGULATOR_VOLTAGE, |
| 222 | .n_voltages = 17, |
| 223 | .linear_ranges = rk808_ldo_voltage_ranges, |
| 224 | .n_linear_ranges = ARRAY_SIZE(rk808_ldo_voltage_ranges), |
| 225 | .vsel_reg = RK808_LDO4_ON_VSEL_REG, |
| 226 | .vsel_mask = RK808_LDO_VSEL_MASK, |
| 227 | .enable_reg = RK808_LDO_EN_REG, |
| 228 | .enable_mask = BIT(3), |
| 229 | .owner = THIS_MODULE, |
| 230 | }, { |
| 231 | .name = "LDO_REG5", |
Doug Anderson | b8074eb | 2014-09-02 09:14:28 -0700 | [diff] [blame] | 232 | .supply_name = "vcc9", |
Chris Zhong | 2cd64ae | 2014-08-20 11:36:42 +0800 | [diff] [blame] | 233 | .id = RK808_ID_LDO5, |
| 234 | .ops = &rk808_reg_ops, |
| 235 | .type = REGULATOR_VOLTAGE, |
| 236 | .n_voltages = 17, |
| 237 | .linear_ranges = rk808_ldo_voltage_ranges, |
| 238 | .n_linear_ranges = ARRAY_SIZE(rk808_ldo_voltage_ranges), |
| 239 | .vsel_reg = RK808_LDO5_ON_VSEL_REG, |
| 240 | .vsel_mask = RK808_LDO_VSEL_MASK, |
| 241 | .enable_reg = RK808_LDO_EN_REG, |
| 242 | .enable_mask = BIT(4), |
| 243 | .owner = THIS_MODULE, |
| 244 | }, { |
| 245 | .name = "LDO_REG6", |
Doug Anderson | b8074eb | 2014-09-02 09:14:28 -0700 | [diff] [blame] | 246 | .supply_name = "vcc10", |
Chris Zhong | 2cd64ae | 2014-08-20 11:36:42 +0800 | [diff] [blame] | 247 | .id = RK808_ID_LDO6, |
| 248 | .ops = &rk808_reg_ops, |
| 249 | .type = REGULATOR_VOLTAGE, |
| 250 | .n_voltages = 18, |
| 251 | .linear_ranges = rk808_ldo6_voltage_ranges, |
| 252 | .n_linear_ranges = ARRAY_SIZE(rk808_ldo6_voltage_ranges), |
| 253 | .vsel_reg = RK808_LDO6_ON_VSEL_REG, |
| 254 | .vsel_mask = RK808_LDO_VSEL_MASK, |
| 255 | .enable_reg = RK808_LDO_EN_REG, |
| 256 | .enable_mask = BIT(5), |
| 257 | .owner = THIS_MODULE, |
| 258 | }, { |
| 259 | .name = "LDO_REG7", |
Doug Anderson | b8074eb | 2014-09-02 09:14:28 -0700 | [diff] [blame] | 260 | .supply_name = "vcc7", |
Chris Zhong | 2cd64ae | 2014-08-20 11:36:42 +0800 | [diff] [blame] | 261 | .id = RK808_ID_LDO7, |
| 262 | .ops = &rk808_reg_ops, |
| 263 | .type = REGULATOR_VOLTAGE, |
| 264 | .n_voltages = 18, |
| 265 | .linear_ranges = rk808_ldo6_voltage_ranges, |
| 266 | .n_linear_ranges = ARRAY_SIZE(rk808_ldo6_voltage_ranges), |
| 267 | .vsel_reg = RK808_LDO7_ON_VSEL_REG, |
| 268 | .vsel_mask = RK808_LDO_VSEL_MASK, |
| 269 | .enable_reg = RK808_LDO_EN_REG, |
| 270 | .enable_mask = BIT(6), |
| 271 | .owner = THIS_MODULE, |
| 272 | }, { |
| 273 | .name = "LDO_REG8", |
Doug Anderson | b8074eb | 2014-09-02 09:14:28 -0700 | [diff] [blame] | 274 | .supply_name = "vcc11", |
Chris Zhong | 2cd64ae | 2014-08-20 11:36:42 +0800 | [diff] [blame] | 275 | .id = RK808_ID_LDO8, |
| 276 | .ops = &rk808_reg_ops, |
| 277 | .type = REGULATOR_VOLTAGE, |
| 278 | .n_voltages = 17, |
| 279 | .linear_ranges = rk808_ldo_voltage_ranges, |
| 280 | .n_linear_ranges = ARRAY_SIZE(rk808_ldo_voltage_ranges), |
| 281 | .vsel_reg = RK808_LDO8_ON_VSEL_REG, |
| 282 | .vsel_mask = RK808_LDO_VSEL_MASK, |
| 283 | .enable_reg = RK808_LDO_EN_REG, |
| 284 | .enable_mask = BIT(7), |
| 285 | .owner = THIS_MODULE, |
| 286 | }, { |
| 287 | .name = "SWITCH_REG1", |
Doug Anderson | b8074eb | 2014-09-02 09:14:28 -0700 | [diff] [blame] | 288 | .supply_name = "vcc8", |
Chris Zhong | 2cd64ae | 2014-08-20 11:36:42 +0800 | [diff] [blame] | 289 | .id = RK808_ID_SWITCH1, |
| 290 | .ops = &rk808_switch_ops, |
| 291 | .type = REGULATOR_VOLTAGE, |
| 292 | .enable_reg = RK808_DCDC_EN_REG, |
| 293 | .enable_mask = BIT(5), |
| 294 | .owner = THIS_MODULE, |
| 295 | }, { |
| 296 | .name = "SWITCH_REG2", |
Doug Anderson | b8074eb | 2014-09-02 09:14:28 -0700 | [diff] [blame] | 297 | .supply_name = "vcc12", |
Chris Zhong | 2cd64ae | 2014-08-20 11:36:42 +0800 | [diff] [blame] | 298 | .id = RK808_ID_SWITCH2, |
| 299 | .ops = &rk808_switch_ops, |
| 300 | .type = REGULATOR_VOLTAGE, |
| 301 | .enable_reg = RK808_DCDC_EN_REG, |
| 302 | .enable_mask = BIT(6), |
| 303 | .owner = THIS_MODULE, |
| 304 | }, |
| 305 | }; |
| 306 | |
| 307 | static struct of_regulator_match rk808_reg_matches[] = { |
| 308 | [RK808_ID_DCDC1] = { .name = "DCDC_REG1" }, |
| 309 | [RK808_ID_DCDC2] = { .name = "DCDC_REG2" }, |
| 310 | [RK808_ID_DCDC3] = { .name = "DCDC_REG3" }, |
| 311 | [RK808_ID_DCDC4] = { .name = "DCDC_REG4" }, |
| 312 | [RK808_ID_LDO1] = { .name = "LDO_REG1" }, |
| 313 | [RK808_ID_LDO2] = { .name = "LDO_REG2" }, |
| 314 | [RK808_ID_LDO3] = { .name = "LDO_REG3" }, |
| 315 | [RK808_ID_LDO4] = { .name = "LDO_REG4" }, |
| 316 | [RK808_ID_LDO5] = { .name = "LDO_REG5" }, |
| 317 | [RK808_ID_LDO6] = { .name = "LDO_REG6" }, |
| 318 | [RK808_ID_LDO7] = { .name = "LDO_REG7" }, |
| 319 | [RK808_ID_LDO8] = { .name = "LDO_REG8" }, |
| 320 | [RK808_ID_SWITCH1] = { .name = "SWITCH_REG1" }, |
| 321 | [RK808_ID_SWITCH2] = { .name = "SWITCH_REG2" }, |
| 322 | }; |
| 323 | |
Chris Zhong | 571a401 | 2014-09-10 09:18:06 +0800 | [diff] [blame] | 324 | static int rk808_regulator_probe(struct platform_device *pdev) |
Chris Zhong | 2cd64ae | 2014-08-20 11:36:42 +0800 | [diff] [blame] | 325 | { |
Chris Zhong | 571a401 | 2014-09-10 09:18:06 +0800 | [diff] [blame] | 326 | struct rk808 *rk808 = dev_get_drvdata(pdev->dev.parent); |
| 327 | struct i2c_client *client = rk808->i2c; |
| 328 | struct device_node *reg_np; |
| 329 | struct regulator_config config = {}; |
| 330 | struct regulator_dev *rk808_rdev; |
| 331 | int ret, i; |
Chris Zhong | 2cd64ae | 2014-08-20 11:36:42 +0800 | [diff] [blame] | 332 | |
Chris Zhong | 571a401 | 2014-09-10 09:18:06 +0800 | [diff] [blame] | 333 | reg_np = of_get_child_by_name(client->dev.of_node, "regulators"); |
Chris Zhong | 2cd64ae | 2014-08-20 11:36:42 +0800 | [diff] [blame] | 334 | if (!reg_np) |
| 335 | return -ENXIO; |
| 336 | |
Axel Lin | 1ed3f8c | 2014-09-11 18:22:48 +0800 | [diff] [blame] | 337 | ret = of_regulator_match(&pdev->dev, reg_np, rk808_reg_matches, |
Chris Zhong | 2cd64ae | 2014-08-20 11:36:42 +0800 | [diff] [blame] | 338 | RK808_NUM_REGULATORS); |
Axel Lin | 1ed3f8c | 2014-09-11 18:22:48 +0800 | [diff] [blame] | 339 | of_node_put(reg_np); |
Chris Zhong | 571a401 | 2014-09-10 09:18:06 +0800 | [diff] [blame] | 340 | if (ret < 0) |
Chris Zhong | 2cd64ae | 2014-08-20 11:36:42 +0800 | [diff] [blame] | 341 | return ret; |
Chris Zhong | 2cd64ae | 2014-08-20 11:36:42 +0800 | [diff] [blame] | 342 | |
Chris Zhong | 571a401 | 2014-09-10 09:18:06 +0800 | [diff] [blame] | 343 | /* Instantiate the regulators */ |
Chris Zhong | 2cd64ae | 2014-08-20 11:36:42 +0800 | [diff] [blame] | 344 | for (i = 0; i < RK808_NUM_REGULATORS; i++) { |
| 345 | if (!rk808_reg_matches[i].init_data || |
| 346 | !rk808_reg_matches[i].of_node) |
| 347 | continue; |
| 348 | |
Chris Zhong | d76c333 | 2014-08-25 21:37:06 +0800 | [diff] [blame] | 349 | config.dev = &client->dev; |
Chris Zhong | 2cd64ae | 2014-08-20 11:36:42 +0800 | [diff] [blame] | 350 | config.driver_data = rk808; |
| 351 | config.regmap = rk808->regmap; |
Chris Zhong | 571a401 | 2014-09-10 09:18:06 +0800 | [diff] [blame] | 352 | config.of_node = rk808_reg_matches[i].of_node; |
| 353 | config.init_data = rk808_reg_matches[i].init_data; |
Chris Zhong | 2cd64ae | 2014-08-20 11:36:42 +0800 | [diff] [blame] | 354 | |
| 355 | rk808_rdev = devm_regulator_register(&pdev->dev, |
| 356 | &rk808_reg[i], &config); |
| 357 | if (IS_ERR(rk808_rdev)) { |
Chris Zhong | d76c333 | 2014-08-25 21:37:06 +0800 | [diff] [blame] | 358 | dev_err(&client->dev, |
Chris Zhong | 2cd64ae | 2014-08-20 11:36:42 +0800 | [diff] [blame] | 359 | "failed to register %d regulator\n", i); |
| 360 | return PTR_ERR(rk808_rdev); |
| 361 | } |
Chris Zhong | 2cd64ae | 2014-08-20 11:36:42 +0800 | [diff] [blame] | 362 | } |
Chris Zhong | 571a401 | 2014-09-10 09:18:06 +0800 | [diff] [blame] | 363 | |
Chris Zhong | 2cd64ae | 2014-08-20 11:36:42 +0800 | [diff] [blame] | 364 | return 0; |
| 365 | } |
| 366 | |
| 367 | static struct platform_driver rk808_regulator_driver = { |
| 368 | .probe = rk808_regulator_probe, |
| 369 | .driver = { |
| 370 | .name = "rk808-regulator", |
| 371 | .owner = THIS_MODULE, |
| 372 | }, |
| 373 | }; |
| 374 | |
| 375 | module_platform_driver(rk808_regulator_driver); |
| 376 | |
| 377 | MODULE_DESCRIPTION("regulator driver for the rk808 series PMICs"); |
| 378 | MODULE_AUTHOR("Chris Zhong<zyw@rock-chips.com>"); |
Chris Zhong | 571a401 | 2014-09-10 09:18:06 +0800 | [diff] [blame] | 379 | MODULE_AUTHOR("Zhang Qing<zhangqing@rock-chips.com>"); |
Chris Zhong | 2cd64ae | 2014-08-20 11:36:42 +0800 | [diff] [blame] | 380 | MODULE_LICENSE("GPL"); |
| 381 | MODULE_ALIAS("platform:rk808-regulator"); |