Yunfan Zhang | 49d8c59 | 2012-09-08 03:52:18 -0700 | [diff] [blame] | 1 | /* |
| 2 | * FAN53555 Fairchild Digitally Programmable TinyBuck Regulator Driver. |
| 3 | * |
| 4 | * Supported Part Numbers: |
| 5 | * FAN53555UC00X/01X/03X/04X/05X |
| 6 | * |
| 7 | * Copyright (c) 2012 Marvell Technology Ltd. |
| 8 | * Yunfan Zhang <yfzhang@marvell.com> |
| 9 | * |
| 10 | * This package is free software; you can redistribute it and/or modify |
| 11 | * it under the terms of the GNU General Public License version 2 as |
| 12 | * published by the Free Software Foundation. |
| 13 | * |
| 14 | */ |
| 15 | #include <linux/module.h> |
| 16 | #include <linux/param.h> |
| 17 | #include <linux/err.h> |
| 18 | #include <linux/platform_device.h> |
| 19 | #include <linux/regulator/driver.h> |
| 20 | #include <linux/regulator/machine.h> |
Heiko Stuebner | 91f23d8 | 2014-09-16 21:22:53 +0200 | [diff] [blame] | 21 | #include <linux/regulator/of_regulator.h> |
| 22 | #include <linux/of_device.h> |
Yunfan Zhang | 49d8c59 | 2012-09-08 03:52:18 -0700 | [diff] [blame] | 23 | #include <linux/i2c.h> |
| 24 | #include <linux/slab.h> |
| 25 | #include <linux/regmap.h> |
| 26 | #include <linux/regulator/fan53555.h> |
| 27 | |
| 28 | /* Voltage setting */ |
| 29 | #define FAN53555_VSEL0 0x00 |
| 30 | #define FAN53555_VSEL1 0x01 |
| 31 | /* Control register */ |
| 32 | #define FAN53555_CONTROL 0x02 |
| 33 | /* IC Type */ |
| 34 | #define FAN53555_ID1 0x03 |
| 35 | /* IC mask version */ |
| 36 | #define FAN53555_ID2 0x04 |
| 37 | /* Monitor register */ |
| 38 | #define FAN53555_MONITOR 0x05 |
| 39 | |
| 40 | /* VSEL bit definitions */ |
| 41 | #define VSEL_BUCK_EN (1 << 7) |
| 42 | #define VSEL_MODE (1 << 6) |
| 43 | #define VSEL_NSEL_MASK 0x3F |
| 44 | /* Chip ID and Verison */ |
| 45 | #define DIE_ID 0x0F /* ID1 */ |
| 46 | #define DIE_REV 0x0F /* ID2 */ |
| 47 | /* Control bit definitions */ |
| 48 | #define CTL_OUTPUT_DISCHG (1 << 7) |
| 49 | #define CTL_SLEW_MASK (0x7 << 4) |
| 50 | #define CTL_SLEW_SHIFT 4 |
| 51 | #define CTL_RESET (1 << 2) |
| 52 | |
| 53 | #define FAN53555_NVOLTAGES 64 /* Numbers of voltages */ |
| 54 | |
Heiko Stuebner | ee30928 | 2014-09-16 21:22:54 +0200 | [diff] [blame] | 55 | enum fan53555_vendor { |
| 56 | FAN53555_VENDOR_FAIRCHILD = 0, |
| 57 | FAN53555_VENDOR_SILERGY, |
| 58 | }; |
| 59 | |
Yunfan Zhang | 49d8c59 | 2012-09-08 03:52:18 -0700 | [diff] [blame] | 60 | /* IC Type */ |
| 61 | enum { |
| 62 | FAN53555_CHIP_ID_00 = 0, |
| 63 | FAN53555_CHIP_ID_01, |
| 64 | FAN53555_CHIP_ID_02, |
| 65 | FAN53555_CHIP_ID_03, |
| 66 | FAN53555_CHIP_ID_04, |
| 67 | FAN53555_CHIP_ID_05, |
| 68 | }; |
| 69 | |
Heiko Stuebner | ee30928 | 2014-09-16 21:22:54 +0200 | [diff] [blame] | 70 | enum { |
| 71 | SILERGY_SYR82X = 8, |
| 72 | }; |
| 73 | |
Yunfan Zhang | 49d8c59 | 2012-09-08 03:52:18 -0700 | [diff] [blame] | 74 | struct fan53555_device_info { |
Heiko Stuebner | ee30928 | 2014-09-16 21:22:54 +0200 | [diff] [blame] | 75 | enum fan53555_vendor vendor; |
Yunfan Zhang | 49d8c59 | 2012-09-08 03:52:18 -0700 | [diff] [blame] | 76 | struct regmap *regmap; |
| 77 | struct device *dev; |
| 78 | struct regulator_desc desc; |
| 79 | struct regulator_dev *rdev; |
| 80 | struct regulator_init_data *regulator; |
| 81 | /* IC Type and Rev */ |
| 82 | int chip_id; |
| 83 | int chip_rev; |
| 84 | /* Voltage setting register */ |
| 85 | unsigned int vol_reg; |
| 86 | unsigned int sleep_reg; |
| 87 | /* Voltage range and step(linear) */ |
| 88 | unsigned int vsel_min; |
Yunfan Zhang | 49d8c59 | 2012-09-08 03:52:18 -0700 | [diff] [blame] | 89 | unsigned int vsel_step; |
| 90 | /* Voltage slew rate limiting */ |
| 91 | unsigned int slew_rate; |
| 92 | /* Sleep voltage cache */ |
| 93 | unsigned int sleep_vol_cache; |
| 94 | }; |
| 95 | |
| 96 | static int fan53555_set_suspend_voltage(struct regulator_dev *rdev, int uV) |
| 97 | { |
| 98 | struct fan53555_device_info *di = rdev_get_drvdata(rdev); |
| 99 | int ret; |
| 100 | |
| 101 | if (di->sleep_vol_cache == uV) |
| 102 | return 0; |
| 103 | ret = regulator_map_voltage_linear(rdev, uV, uV); |
| 104 | if (ret < 0) |
Sachin Kamat | 145fe1e | 2014-02-18 16:11:04 +0530 | [diff] [blame] | 105 | return ret; |
Yunfan Zhang | 49d8c59 | 2012-09-08 03:52:18 -0700 | [diff] [blame] | 106 | ret = regmap_update_bits(di->regmap, di->sleep_reg, |
| 107 | VSEL_NSEL_MASK, ret); |
| 108 | if (ret < 0) |
Sachin Kamat | 145fe1e | 2014-02-18 16:11:04 +0530 | [diff] [blame] | 109 | return ret; |
Yunfan Zhang | 49d8c59 | 2012-09-08 03:52:18 -0700 | [diff] [blame] | 110 | /* Cache the sleep voltage setting. |
| 111 | * Might not be the real voltage which is rounded */ |
| 112 | di->sleep_vol_cache = uV; |
| 113 | |
| 114 | return 0; |
| 115 | } |
| 116 | |
zhangqing | ab7cad3 | 2016-01-12 03:05:56 -0800 | [diff] [blame^] | 117 | static int fan53555_set_suspend_enable(struct regulator_dev *rdev) |
| 118 | { |
| 119 | struct fan53555_device_info *di = rdev_get_drvdata(rdev); |
| 120 | |
| 121 | return regmap_update_bits(di->regmap, di->sleep_reg, |
| 122 | VSEL_BUCK_EN, VSEL_BUCK_EN); |
| 123 | } |
| 124 | |
| 125 | static int fan53555_set_suspend_disable(struct regulator_dev *rdev) |
| 126 | { |
| 127 | struct fan53555_device_info *di = rdev_get_drvdata(rdev); |
| 128 | |
| 129 | return regmap_update_bits(di->regmap, di->sleep_reg, |
| 130 | VSEL_BUCK_EN, 0); |
| 131 | } |
| 132 | |
Yunfan Zhang | 49d8c59 | 2012-09-08 03:52:18 -0700 | [diff] [blame] | 133 | static int fan53555_set_mode(struct regulator_dev *rdev, unsigned int mode) |
| 134 | { |
| 135 | struct fan53555_device_info *di = rdev_get_drvdata(rdev); |
| 136 | |
| 137 | switch (mode) { |
| 138 | case REGULATOR_MODE_FAST: |
| 139 | regmap_update_bits(di->regmap, di->vol_reg, |
| 140 | VSEL_MODE, VSEL_MODE); |
| 141 | break; |
| 142 | case REGULATOR_MODE_NORMAL: |
| 143 | regmap_update_bits(di->regmap, di->vol_reg, VSEL_MODE, 0); |
| 144 | break; |
| 145 | default: |
| 146 | return -EINVAL; |
| 147 | } |
| 148 | return 0; |
| 149 | } |
| 150 | |
| 151 | static unsigned int fan53555_get_mode(struct regulator_dev *rdev) |
| 152 | { |
| 153 | struct fan53555_device_info *di = rdev_get_drvdata(rdev); |
| 154 | unsigned int val; |
| 155 | int ret = 0; |
| 156 | |
| 157 | ret = regmap_read(di->regmap, di->vol_reg, &val); |
| 158 | if (ret < 0) |
| 159 | return ret; |
| 160 | if (val & VSEL_MODE) |
| 161 | return REGULATOR_MODE_FAST; |
| 162 | else |
| 163 | return REGULATOR_MODE_NORMAL; |
| 164 | } |
| 165 | |
Krzysztof Kozlowski | 121b567 | 2015-01-05 10:04:19 +0100 | [diff] [blame] | 166 | static const int slew_rates[] = { |
Heiko Stuebner | dd7e71f | 2014-09-16 17:54:01 +0200 | [diff] [blame] | 167 | 64000, |
| 168 | 32000, |
| 169 | 16000, |
| 170 | 8000, |
| 171 | 4000, |
| 172 | 2000, |
| 173 | 1000, |
| 174 | 500, |
| 175 | }; |
| 176 | |
| 177 | static int fan53555_set_ramp(struct regulator_dev *rdev, int ramp) |
| 178 | { |
| 179 | struct fan53555_device_info *di = rdev_get_drvdata(rdev); |
| 180 | int regval = -1, i; |
| 181 | |
| 182 | for (i = 0; i < ARRAY_SIZE(slew_rates); i++) { |
| 183 | if (ramp <= slew_rates[i]) |
| 184 | regval = i; |
| 185 | else |
| 186 | break; |
| 187 | } |
| 188 | |
| 189 | if (regval < 0) { |
| 190 | dev_err(di->dev, "unsupported ramp value %d\n", ramp); |
| 191 | return -EINVAL; |
| 192 | } |
| 193 | |
| 194 | return regmap_update_bits(di->regmap, FAN53555_CONTROL, |
| 195 | CTL_SLEW_MASK, regval << CTL_SLEW_SHIFT); |
| 196 | } |
| 197 | |
Yunfan Zhang | 49d8c59 | 2012-09-08 03:52:18 -0700 | [diff] [blame] | 198 | static struct regulator_ops fan53555_regulator_ops = { |
| 199 | .set_voltage_sel = regulator_set_voltage_sel_regmap, |
| 200 | .get_voltage_sel = regulator_get_voltage_sel_regmap, |
Heiko Stuebner | fda87a4 | 2015-05-26 18:19:45 +0200 | [diff] [blame] | 201 | .set_voltage_time_sel = regulator_set_voltage_time_sel, |
Yunfan Zhang | 49d8c59 | 2012-09-08 03:52:18 -0700 | [diff] [blame] | 202 | .map_voltage = regulator_map_voltage_linear, |
| 203 | .list_voltage = regulator_list_voltage_linear, |
| 204 | .set_suspend_voltage = fan53555_set_suspend_voltage, |
| 205 | .enable = regulator_enable_regmap, |
| 206 | .disable = regulator_disable_regmap, |
| 207 | .is_enabled = regulator_is_enabled_regmap, |
| 208 | .set_mode = fan53555_set_mode, |
| 209 | .get_mode = fan53555_get_mode, |
Heiko Stuebner | dd7e71f | 2014-09-16 17:54:01 +0200 | [diff] [blame] | 210 | .set_ramp_delay = fan53555_set_ramp, |
zhangqing | ab7cad3 | 2016-01-12 03:05:56 -0800 | [diff] [blame^] | 211 | .set_suspend_enable = fan53555_set_suspend_enable, |
| 212 | .set_suspend_disable = fan53555_set_suspend_disable, |
Yunfan Zhang | 49d8c59 | 2012-09-08 03:52:18 -0700 | [diff] [blame] | 213 | }; |
| 214 | |
Heiko Stuebner | ee30928 | 2014-09-16 21:22:54 +0200 | [diff] [blame] | 215 | static int fan53555_voltages_setup_fairchild(struct fan53555_device_info *di) |
Yunfan Zhang | 49d8c59 | 2012-09-08 03:52:18 -0700 | [diff] [blame] | 216 | { |
Yunfan Zhang | 49d8c59 | 2012-09-08 03:52:18 -0700 | [diff] [blame] | 217 | /* Init voltage range and step */ |
| 218 | switch (di->chip_id) { |
| 219 | case FAN53555_CHIP_ID_00: |
| 220 | case FAN53555_CHIP_ID_01: |
| 221 | case FAN53555_CHIP_ID_03: |
| 222 | case FAN53555_CHIP_ID_05: |
| 223 | di->vsel_min = 600000; |
Yunfan Zhang | 49d8c59 | 2012-09-08 03:52:18 -0700 | [diff] [blame] | 224 | di->vsel_step = 10000; |
| 225 | break; |
| 226 | case FAN53555_CHIP_ID_04: |
| 227 | di->vsel_min = 603000; |
Yunfan Zhang | 49d8c59 | 2012-09-08 03:52:18 -0700 | [diff] [blame] | 228 | di->vsel_step = 12826; |
| 229 | break; |
| 230 | default: |
| 231 | dev_err(di->dev, |
Heiko Stuebner | ee30928 | 2014-09-16 21:22:54 +0200 | [diff] [blame] | 232 | "Chip ID %d not supported!\n", di->chip_id); |
Yunfan Zhang | 49d8c59 | 2012-09-08 03:52:18 -0700 | [diff] [blame] | 233 | return -EINVAL; |
| 234 | } |
Heiko Stuebner | dd7e71f | 2014-09-16 17:54:01 +0200 | [diff] [blame] | 235 | |
| 236 | return 0; |
Yunfan Zhang | 49d8c59 | 2012-09-08 03:52:18 -0700 | [diff] [blame] | 237 | } |
| 238 | |
Heiko Stuebner | ee30928 | 2014-09-16 21:22:54 +0200 | [diff] [blame] | 239 | static int fan53555_voltages_setup_silergy(struct fan53555_device_info *di) |
| 240 | { |
| 241 | /* Init voltage range and step */ |
| 242 | switch (di->chip_id) { |
| 243 | case SILERGY_SYR82X: |
| 244 | di->vsel_min = 712500; |
| 245 | di->vsel_step = 12500; |
| 246 | break; |
| 247 | default: |
| 248 | dev_err(di->dev, |
| 249 | "Chip ID %d not supported!\n", di->chip_id); |
| 250 | return -EINVAL; |
| 251 | } |
| 252 | |
| 253 | return 0; |
| 254 | } |
| 255 | |
| 256 | /* For 00,01,03,05 options: |
| 257 | * VOUT = 0.60V + NSELx * 10mV, from 0.60 to 1.23V. |
| 258 | * For 04 option: |
| 259 | * VOUT = 0.603V + NSELx * 12.826mV, from 0.603 to 1.411V. |
| 260 | * */ |
| 261 | static int fan53555_device_setup(struct fan53555_device_info *di, |
| 262 | struct fan53555_platform_data *pdata) |
| 263 | { |
| 264 | int ret = 0; |
| 265 | |
| 266 | /* Setup voltage control register */ |
| 267 | switch (pdata->sleep_vsel_id) { |
| 268 | case FAN53555_VSEL_ID_0: |
| 269 | di->sleep_reg = FAN53555_VSEL0; |
| 270 | di->vol_reg = FAN53555_VSEL1; |
| 271 | break; |
| 272 | case FAN53555_VSEL_ID_1: |
| 273 | di->sleep_reg = FAN53555_VSEL1; |
| 274 | di->vol_reg = FAN53555_VSEL0; |
| 275 | break; |
| 276 | default: |
| 277 | dev_err(di->dev, "Invalid VSEL ID!\n"); |
| 278 | return -EINVAL; |
| 279 | } |
| 280 | |
| 281 | switch (di->vendor) { |
| 282 | case FAN53555_VENDOR_FAIRCHILD: |
| 283 | ret = fan53555_voltages_setup_fairchild(di); |
| 284 | break; |
| 285 | case FAN53555_VENDOR_SILERGY: |
| 286 | ret = fan53555_voltages_setup_silergy(di); |
| 287 | break; |
| 288 | default: |
Axel Lin | fe23053 | 2014-09-18 21:48:48 +0800 | [diff] [blame] | 289 | dev_err(di->dev, "vendor %d not supported!\n", di->vendor); |
Heiko Stuebner | ee30928 | 2014-09-16 21:22:54 +0200 | [diff] [blame] | 290 | return -EINVAL; |
| 291 | } |
| 292 | |
| 293 | return ret; |
| 294 | } |
| 295 | |
Yunfan Zhang | 49d8c59 | 2012-09-08 03:52:18 -0700 | [diff] [blame] | 296 | static int fan53555_regulator_register(struct fan53555_device_info *di, |
| 297 | struct regulator_config *config) |
| 298 | { |
| 299 | struct regulator_desc *rdesc = &di->desc; |
| 300 | |
| 301 | rdesc->name = "fan53555-reg"; |
Heiko Stuebner | 3415d60 | 2014-09-14 21:23:01 +0200 | [diff] [blame] | 302 | rdesc->supply_name = "vin"; |
Yunfan Zhang | 49d8c59 | 2012-09-08 03:52:18 -0700 | [diff] [blame] | 303 | rdesc->ops = &fan53555_regulator_ops; |
| 304 | rdesc->type = REGULATOR_VOLTAGE; |
| 305 | rdesc->n_voltages = FAN53555_NVOLTAGES; |
| 306 | rdesc->enable_reg = di->vol_reg; |
| 307 | rdesc->enable_mask = VSEL_BUCK_EN; |
| 308 | rdesc->min_uV = di->vsel_min; |
| 309 | rdesc->uV_step = di->vsel_step; |
| 310 | rdesc->vsel_reg = di->vol_reg; |
| 311 | rdesc->vsel_mask = VSEL_NSEL_MASK; |
| 312 | rdesc->owner = THIS_MODULE; |
| 313 | |
Axel Lin | b15f5f7 | 2013-09-03 14:27:56 +0800 | [diff] [blame] | 314 | di->rdev = devm_regulator_register(di->dev, &di->desc, config); |
Rusty Russell | 8c6ffba | 2013-07-15 11:20:32 +0930 | [diff] [blame] | 315 | return PTR_ERR_OR_ZERO(di->rdev); |
Yunfan Zhang | 49d8c59 | 2012-09-08 03:52:18 -0700 | [diff] [blame] | 316 | } |
| 317 | |
Krzysztof Kozlowski | 121b567 | 2015-01-05 10:04:19 +0100 | [diff] [blame] | 318 | static const struct regmap_config fan53555_regmap_config = { |
Yunfan Zhang | 49d8c59 | 2012-09-08 03:52:18 -0700 | [diff] [blame] | 319 | .reg_bits = 8, |
| 320 | .val_bits = 8, |
| 321 | }; |
| 322 | |
Heiko Stuebner | 91f23d8 | 2014-09-16 21:22:53 +0200 | [diff] [blame] | 323 | static struct fan53555_platform_data *fan53555_parse_dt(struct device *dev, |
Javier Martinez Canillas | 072e78b | 2014-11-10 14:43:53 +0100 | [diff] [blame] | 324 | struct device_node *np, |
| 325 | const struct regulator_desc *desc) |
Heiko Stuebner | 91f23d8 | 2014-09-16 21:22:53 +0200 | [diff] [blame] | 326 | { |
| 327 | struct fan53555_platform_data *pdata; |
| 328 | int ret; |
| 329 | u32 tmp; |
| 330 | |
| 331 | pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL); |
| 332 | if (!pdata) |
| 333 | return NULL; |
| 334 | |
Javier Martinez Canillas | 072e78b | 2014-11-10 14:43:53 +0100 | [diff] [blame] | 335 | pdata->regulator = of_get_regulator_init_data(dev, np, desc); |
Heiko Stuebner | 91f23d8 | 2014-09-16 21:22:53 +0200 | [diff] [blame] | 336 | |
| 337 | ret = of_property_read_u32(np, "fcs,suspend-voltage-selector", |
| 338 | &tmp); |
| 339 | if (!ret) |
| 340 | pdata->sleep_vsel_id = tmp; |
| 341 | |
| 342 | return pdata; |
| 343 | } |
| 344 | |
| 345 | static const struct of_device_id fan53555_dt_ids[] = { |
| 346 | { |
| 347 | .compatible = "fcs,fan53555", |
Heiko Stuebner | ee30928 | 2014-09-16 21:22:54 +0200 | [diff] [blame] | 348 | .data = (void *)FAN53555_VENDOR_FAIRCHILD |
| 349 | }, { |
| 350 | .compatible = "silergy,syr827", |
| 351 | .data = (void *)FAN53555_VENDOR_SILERGY, |
| 352 | }, { |
| 353 | .compatible = "silergy,syr828", |
| 354 | .data = (void *)FAN53555_VENDOR_SILERGY, |
Heiko Stuebner | 91f23d8 | 2014-09-16 21:22:53 +0200 | [diff] [blame] | 355 | }, |
| 356 | { } |
| 357 | }; |
| 358 | MODULE_DEVICE_TABLE(of, fan53555_dt_ids); |
| 359 | |
Bill Pemberton | a502357 | 2012-11-19 13:22:22 -0500 | [diff] [blame] | 360 | static int fan53555_regulator_probe(struct i2c_client *client, |
Yunfan Zhang | 49d8c59 | 2012-09-08 03:52:18 -0700 | [diff] [blame] | 361 | const struct i2c_device_id *id) |
| 362 | { |
Heiko Stuebner | 91f23d8 | 2014-09-16 21:22:53 +0200 | [diff] [blame] | 363 | struct device_node *np = client->dev.of_node; |
Yunfan Zhang | 49d8c59 | 2012-09-08 03:52:18 -0700 | [diff] [blame] | 364 | struct fan53555_device_info *di; |
| 365 | struct fan53555_platform_data *pdata; |
| 366 | struct regulator_config config = { }; |
| 367 | unsigned int val; |
| 368 | int ret; |
| 369 | |
Javier Martinez Canillas | 072e78b | 2014-11-10 14:43:53 +0100 | [diff] [blame] | 370 | di = devm_kzalloc(&client->dev, sizeof(struct fan53555_device_info), |
| 371 | GFP_KERNEL); |
| 372 | if (!di) |
| 373 | return -ENOMEM; |
| 374 | |
Jingoo Han | dff91d0 | 2013-07-30 17:20:47 +0900 | [diff] [blame] | 375 | pdata = dev_get_platdata(&client->dev); |
Heiko Stuebner | 91f23d8 | 2014-09-16 21:22:53 +0200 | [diff] [blame] | 376 | if (!pdata) |
Javier Martinez Canillas | 072e78b | 2014-11-10 14:43:53 +0100 | [diff] [blame] | 377 | pdata = fan53555_parse_dt(&client->dev, np, &di->desc); |
Heiko Stuebner | 91f23d8 | 2014-09-16 21:22:53 +0200 | [diff] [blame] | 378 | |
Yunfan Zhang | 49d8c59 | 2012-09-08 03:52:18 -0700 | [diff] [blame] | 379 | if (!pdata || !pdata->regulator) { |
| 380 | dev_err(&client->dev, "Platform data not found!\n"); |
| 381 | return -ENODEV; |
| 382 | } |
| 383 | |
Axel Lin | e13426b | 2014-09-18 21:49:38 +0800 | [diff] [blame] | 384 | di->regulator = pdata->regulator; |
Heiko Stuebner | ee30928 | 2014-09-16 21:22:54 +0200 | [diff] [blame] | 385 | if (client->dev.of_node) { |
| 386 | const struct of_device_id *match; |
| 387 | |
| 388 | match = of_match_device(of_match_ptr(fan53555_dt_ids), |
| 389 | &client->dev); |
| 390 | if (!match) |
| 391 | return -ENODEV; |
| 392 | |
Heiko Stübner | 6f34163 | 2014-09-17 13:21:48 +0200 | [diff] [blame] | 393 | di->vendor = (unsigned long) match->data; |
Heiko Stuebner | ee30928 | 2014-09-16 21:22:54 +0200 | [diff] [blame] | 394 | } else { |
Heiko Stuebner | 91f23d8 | 2014-09-16 21:22:53 +0200 | [diff] [blame] | 395 | /* if no ramp constraint set, get the pdata ramp_delay */ |
| 396 | if (!di->regulator->constraints.ramp_delay) { |
| 397 | int slew_idx = (pdata->slew_rate & 0x7) |
| 398 | ? pdata->slew_rate : 0; |
Heiko Stuebner | dd7e71f | 2014-09-16 17:54:01 +0200 | [diff] [blame] | 399 | |
Heiko Stuebner | 91f23d8 | 2014-09-16 21:22:53 +0200 | [diff] [blame] | 400 | di->regulator->constraints.ramp_delay |
| 401 | = slew_rates[slew_idx]; |
| 402 | } |
Heiko Stuebner | ee30928 | 2014-09-16 21:22:54 +0200 | [diff] [blame] | 403 | |
| 404 | di->vendor = id->driver_data; |
Heiko Stuebner | dd7e71f | 2014-09-16 17:54:01 +0200 | [diff] [blame] | 405 | } |
| 406 | |
Yunfan Zhang | 49d8c59 | 2012-09-08 03:52:18 -0700 | [diff] [blame] | 407 | di->regmap = devm_regmap_init_i2c(client, &fan53555_regmap_config); |
| 408 | if (IS_ERR(di->regmap)) { |
| 409 | dev_err(&client->dev, "Failed to allocate regmap!\n"); |
| 410 | return PTR_ERR(di->regmap); |
| 411 | } |
| 412 | di->dev = &client->dev; |
Yunfan Zhang | 49d8c59 | 2012-09-08 03:52:18 -0700 | [diff] [blame] | 413 | i2c_set_clientdata(client, di); |
| 414 | /* Get chip ID */ |
| 415 | ret = regmap_read(di->regmap, FAN53555_ID1, &val); |
| 416 | if (ret < 0) { |
| 417 | dev_err(&client->dev, "Failed to get chip ID!\n"); |
Sachin Kamat | 145fe1e | 2014-02-18 16:11:04 +0530 | [diff] [blame] | 418 | return ret; |
Yunfan Zhang | 49d8c59 | 2012-09-08 03:52:18 -0700 | [diff] [blame] | 419 | } |
| 420 | di->chip_id = val & DIE_ID; |
| 421 | /* Get chip revision */ |
| 422 | ret = regmap_read(di->regmap, FAN53555_ID2, &val); |
| 423 | if (ret < 0) { |
| 424 | dev_err(&client->dev, "Failed to get chip Rev!\n"); |
Sachin Kamat | 145fe1e | 2014-02-18 16:11:04 +0530 | [diff] [blame] | 425 | return ret; |
Yunfan Zhang | 49d8c59 | 2012-09-08 03:52:18 -0700 | [diff] [blame] | 426 | } |
| 427 | di->chip_rev = val & DIE_REV; |
| 428 | dev_info(&client->dev, "FAN53555 Option[%d] Rev[%d] Detected!\n", |
| 429 | di->chip_id, di->chip_rev); |
| 430 | /* Device init */ |
| 431 | ret = fan53555_device_setup(di, pdata); |
| 432 | if (ret < 0) { |
| 433 | dev_err(&client->dev, "Failed to setup device!\n"); |
| 434 | return ret; |
| 435 | } |
| 436 | /* Register regulator */ |
| 437 | config.dev = di->dev; |
| 438 | config.init_data = di->regulator; |
| 439 | config.regmap = di->regmap; |
| 440 | config.driver_data = di; |
Heiko Stuebner | 91f23d8 | 2014-09-16 21:22:53 +0200 | [diff] [blame] | 441 | config.of_node = np; |
| 442 | |
Yunfan Zhang | 49d8c59 | 2012-09-08 03:52:18 -0700 | [diff] [blame] | 443 | ret = fan53555_regulator_register(di, &config); |
| 444 | if (ret < 0) |
| 445 | dev_err(&client->dev, "Failed to register regulator!\n"); |
| 446 | return ret; |
| 447 | |
| 448 | } |
| 449 | |
Yunfan Zhang | 49d8c59 | 2012-09-08 03:52:18 -0700 | [diff] [blame] | 450 | static const struct i2c_device_id fan53555_id[] = { |
Heiko Stuebner | ee30928 | 2014-09-16 21:22:54 +0200 | [diff] [blame] | 451 | { |
| 452 | .name = "fan53555", |
| 453 | .driver_data = FAN53555_VENDOR_FAIRCHILD |
| 454 | }, { |
| 455 | .name = "syr82x", |
| 456 | .driver_data = FAN53555_VENDOR_SILERGY |
| 457 | }, |
Yunfan Zhang | 49d8c59 | 2012-09-08 03:52:18 -0700 | [diff] [blame] | 458 | { }, |
| 459 | }; |
Javier Martinez Canillas | e80c47b | 2015-07-30 18:18:40 +0200 | [diff] [blame] | 460 | MODULE_DEVICE_TABLE(i2c, fan53555_id); |
Yunfan Zhang | 49d8c59 | 2012-09-08 03:52:18 -0700 | [diff] [blame] | 461 | |
| 462 | static struct i2c_driver fan53555_regulator_driver = { |
| 463 | .driver = { |
| 464 | .name = "fan53555-regulator", |
Heiko Stuebner | 91f23d8 | 2014-09-16 21:22:53 +0200 | [diff] [blame] | 465 | .of_match_table = of_match_ptr(fan53555_dt_ids), |
Yunfan Zhang | 49d8c59 | 2012-09-08 03:52:18 -0700 | [diff] [blame] | 466 | }, |
| 467 | .probe = fan53555_regulator_probe, |
Yunfan Zhang | 49d8c59 | 2012-09-08 03:52:18 -0700 | [diff] [blame] | 468 | .id_table = fan53555_id, |
| 469 | }; |
| 470 | |
| 471 | module_i2c_driver(fan53555_regulator_driver); |
| 472 | |
| 473 | MODULE_AUTHOR("Yunfan Zhang <yfzhang@marvell.com>"); |
| 474 | MODULE_DESCRIPTION("FAN53555 regulator driver"); |
| 475 | MODULE_LICENSE("GPL v2"); |