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 | |
| 117 | static int fan53555_set_mode(struct regulator_dev *rdev, unsigned int mode) |
| 118 | { |
| 119 | struct fan53555_device_info *di = rdev_get_drvdata(rdev); |
| 120 | |
| 121 | switch (mode) { |
| 122 | case REGULATOR_MODE_FAST: |
| 123 | regmap_update_bits(di->regmap, di->vol_reg, |
| 124 | VSEL_MODE, VSEL_MODE); |
| 125 | break; |
| 126 | case REGULATOR_MODE_NORMAL: |
| 127 | regmap_update_bits(di->regmap, di->vol_reg, VSEL_MODE, 0); |
| 128 | break; |
| 129 | default: |
| 130 | return -EINVAL; |
| 131 | } |
| 132 | return 0; |
| 133 | } |
| 134 | |
| 135 | static unsigned int fan53555_get_mode(struct regulator_dev *rdev) |
| 136 | { |
| 137 | struct fan53555_device_info *di = rdev_get_drvdata(rdev); |
| 138 | unsigned int val; |
| 139 | int ret = 0; |
| 140 | |
| 141 | ret = regmap_read(di->regmap, di->vol_reg, &val); |
| 142 | if (ret < 0) |
| 143 | return ret; |
| 144 | if (val & VSEL_MODE) |
| 145 | return REGULATOR_MODE_FAST; |
| 146 | else |
| 147 | return REGULATOR_MODE_NORMAL; |
| 148 | } |
| 149 | |
Krzysztof Kozlowski | 121b567 | 2015-01-05 10:04:19 +0100 | [diff] [blame^] | 150 | static const int slew_rates[] = { |
Heiko Stuebner | dd7e71f | 2014-09-16 17:54:01 +0200 | [diff] [blame] | 151 | 64000, |
| 152 | 32000, |
| 153 | 16000, |
| 154 | 8000, |
| 155 | 4000, |
| 156 | 2000, |
| 157 | 1000, |
| 158 | 500, |
| 159 | }; |
| 160 | |
| 161 | static int fan53555_set_ramp(struct regulator_dev *rdev, int ramp) |
| 162 | { |
| 163 | struct fan53555_device_info *di = rdev_get_drvdata(rdev); |
| 164 | int regval = -1, i; |
| 165 | |
| 166 | for (i = 0; i < ARRAY_SIZE(slew_rates); i++) { |
| 167 | if (ramp <= slew_rates[i]) |
| 168 | regval = i; |
| 169 | else |
| 170 | break; |
| 171 | } |
| 172 | |
| 173 | if (regval < 0) { |
| 174 | dev_err(di->dev, "unsupported ramp value %d\n", ramp); |
| 175 | return -EINVAL; |
| 176 | } |
| 177 | |
| 178 | return regmap_update_bits(di->regmap, FAN53555_CONTROL, |
| 179 | CTL_SLEW_MASK, regval << CTL_SLEW_SHIFT); |
| 180 | } |
| 181 | |
Yunfan Zhang | 49d8c59 | 2012-09-08 03:52:18 -0700 | [diff] [blame] | 182 | static struct regulator_ops fan53555_regulator_ops = { |
| 183 | .set_voltage_sel = regulator_set_voltage_sel_regmap, |
| 184 | .get_voltage_sel = regulator_get_voltage_sel_regmap, |
| 185 | .map_voltage = regulator_map_voltage_linear, |
| 186 | .list_voltage = regulator_list_voltage_linear, |
| 187 | .set_suspend_voltage = fan53555_set_suspend_voltage, |
| 188 | .enable = regulator_enable_regmap, |
| 189 | .disable = regulator_disable_regmap, |
| 190 | .is_enabled = regulator_is_enabled_regmap, |
| 191 | .set_mode = fan53555_set_mode, |
| 192 | .get_mode = fan53555_get_mode, |
Heiko Stuebner | dd7e71f | 2014-09-16 17:54:01 +0200 | [diff] [blame] | 193 | .set_ramp_delay = fan53555_set_ramp, |
Yunfan Zhang | 49d8c59 | 2012-09-08 03:52:18 -0700 | [diff] [blame] | 194 | }; |
| 195 | |
Heiko Stuebner | ee30928 | 2014-09-16 21:22:54 +0200 | [diff] [blame] | 196 | static int fan53555_voltages_setup_fairchild(struct fan53555_device_info *di) |
Yunfan Zhang | 49d8c59 | 2012-09-08 03:52:18 -0700 | [diff] [blame] | 197 | { |
Yunfan Zhang | 49d8c59 | 2012-09-08 03:52:18 -0700 | [diff] [blame] | 198 | /* Init voltage range and step */ |
| 199 | switch (di->chip_id) { |
| 200 | case FAN53555_CHIP_ID_00: |
| 201 | case FAN53555_CHIP_ID_01: |
| 202 | case FAN53555_CHIP_ID_03: |
| 203 | case FAN53555_CHIP_ID_05: |
| 204 | di->vsel_min = 600000; |
Yunfan Zhang | 49d8c59 | 2012-09-08 03:52:18 -0700 | [diff] [blame] | 205 | di->vsel_step = 10000; |
| 206 | break; |
| 207 | case FAN53555_CHIP_ID_04: |
| 208 | di->vsel_min = 603000; |
Yunfan Zhang | 49d8c59 | 2012-09-08 03:52:18 -0700 | [diff] [blame] | 209 | di->vsel_step = 12826; |
| 210 | break; |
| 211 | default: |
| 212 | dev_err(di->dev, |
Heiko Stuebner | ee30928 | 2014-09-16 21:22:54 +0200 | [diff] [blame] | 213 | "Chip ID %d not supported!\n", di->chip_id); |
Yunfan Zhang | 49d8c59 | 2012-09-08 03:52:18 -0700 | [diff] [blame] | 214 | return -EINVAL; |
| 215 | } |
Heiko Stuebner | dd7e71f | 2014-09-16 17:54:01 +0200 | [diff] [blame] | 216 | |
| 217 | return 0; |
Yunfan Zhang | 49d8c59 | 2012-09-08 03:52:18 -0700 | [diff] [blame] | 218 | } |
| 219 | |
Heiko Stuebner | ee30928 | 2014-09-16 21:22:54 +0200 | [diff] [blame] | 220 | static int fan53555_voltages_setup_silergy(struct fan53555_device_info *di) |
| 221 | { |
| 222 | /* Init voltage range and step */ |
| 223 | switch (di->chip_id) { |
| 224 | case SILERGY_SYR82X: |
| 225 | di->vsel_min = 712500; |
| 226 | di->vsel_step = 12500; |
| 227 | break; |
| 228 | default: |
| 229 | dev_err(di->dev, |
| 230 | "Chip ID %d not supported!\n", di->chip_id); |
| 231 | return -EINVAL; |
| 232 | } |
| 233 | |
| 234 | return 0; |
| 235 | } |
| 236 | |
| 237 | /* For 00,01,03,05 options: |
| 238 | * VOUT = 0.60V + NSELx * 10mV, from 0.60 to 1.23V. |
| 239 | * For 04 option: |
| 240 | * VOUT = 0.603V + NSELx * 12.826mV, from 0.603 to 1.411V. |
| 241 | * */ |
| 242 | static int fan53555_device_setup(struct fan53555_device_info *di, |
| 243 | struct fan53555_platform_data *pdata) |
| 244 | { |
| 245 | int ret = 0; |
| 246 | |
| 247 | /* Setup voltage control register */ |
| 248 | switch (pdata->sleep_vsel_id) { |
| 249 | case FAN53555_VSEL_ID_0: |
| 250 | di->sleep_reg = FAN53555_VSEL0; |
| 251 | di->vol_reg = FAN53555_VSEL1; |
| 252 | break; |
| 253 | case FAN53555_VSEL_ID_1: |
| 254 | di->sleep_reg = FAN53555_VSEL1; |
| 255 | di->vol_reg = FAN53555_VSEL0; |
| 256 | break; |
| 257 | default: |
| 258 | dev_err(di->dev, "Invalid VSEL ID!\n"); |
| 259 | return -EINVAL; |
| 260 | } |
| 261 | |
| 262 | switch (di->vendor) { |
| 263 | case FAN53555_VENDOR_FAIRCHILD: |
| 264 | ret = fan53555_voltages_setup_fairchild(di); |
| 265 | break; |
| 266 | case FAN53555_VENDOR_SILERGY: |
| 267 | ret = fan53555_voltages_setup_silergy(di); |
| 268 | break; |
| 269 | default: |
Axel Lin | fe23053 | 2014-09-18 21:48:48 +0800 | [diff] [blame] | 270 | dev_err(di->dev, "vendor %d not supported!\n", di->vendor); |
Heiko Stuebner | ee30928 | 2014-09-16 21:22:54 +0200 | [diff] [blame] | 271 | return -EINVAL; |
| 272 | } |
| 273 | |
| 274 | return ret; |
| 275 | } |
| 276 | |
Yunfan Zhang | 49d8c59 | 2012-09-08 03:52:18 -0700 | [diff] [blame] | 277 | static int fan53555_regulator_register(struct fan53555_device_info *di, |
| 278 | struct regulator_config *config) |
| 279 | { |
| 280 | struct regulator_desc *rdesc = &di->desc; |
| 281 | |
| 282 | rdesc->name = "fan53555-reg"; |
Heiko Stuebner | 3415d60 | 2014-09-14 21:23:01 +0200 | [diff] [blame] | 283 | rdesc->supply_name = "vin"; |
Yunfan Zhang | 49d8c59 | 2012-09-08 03:52:18 -0700 | [diff] [blame] | 284 | rdesc->ops = &fan53555_regulator_ops; |
| 285 | rdesc->type = REGULATOR_VOLTAGE; |
| 286 | rdesc->n_voltages = FAN53555_NVOLTAGES; |
| 287 | rdesc->enable_reg = di->vol_reg; |
| 288 | rdesc->enable_mask = VSEL_BUCK_EN; |
| 289 | rdesc->min_uV = di->vsel_min; |
| 290 | rdesc->uV_step = di->vsel_step; |
| 291 | rdesc->vsel_reg = di->vol_reg; |
| 292 | rdesc->vsel_mask = VSEL_NSEL_MASK; |
| 293 | rdesc->owner = THIS_MODULE; |
| 294 | |
Axel Lin | b15f5f7 | 2013-09-03 14:27:56 +0800 | [diff] [blame] | 295 | di->rdev = devm_regulator_register(di->dev, &di->desc, config); |
Rusty Russell | 8c6ffba | 2013-07-15 11:20:32 +0930 | [diff] [blame] | 296 | return PTR_ERR_OR_ZERO(di->rdev); |
Yunfan Zhang | 49d8c59 | 2012-09-08 03:52:18 -0700 | [diff] [blame] | 297 | } |
| 298 | |
Krzysztof Kozlowski | 121b567 | 2015-01-05 10:04:19 +0100 | [diff] [blame^] | 299 | static const struct regmap_config fan53555_regmap_config = { |
Yunfan Zhang | 49d8c59 | 2012-09-08 03:52:18 -0700 | [diff] [blame] | 300 | .reg_bits = 8, |
| 301 | .val_bits = 8, |
| 302 | }; |
| 303 | |
Heiko Stuebner | 91f23d8 | 2014-09-16 21:22:53 +0200 | [diff] [blame] | 304 | static struct fan53555_platform_data *fan53555_parse_dt(struct device *dev, |
Javier Martinez Canillas | 072e78b | 2014-11-10 14:43:53 +0100 | [diff] [blame] | 305 | struct device_node *np, |
| 306 | const struct regulator_desc *desc) |
Heiko Stuebner | 91f23d8 | 2014-09-16 21:22:53 +0200 | [diff] [blame] | 307 | { |
| 308 | struct fan53555_platform_data *pdata; |
| 309 | int ret; |
| 310 | u32 tmp; |
| 311 | |
| 312 | pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL); |
| 313 | if (!pdata) |
| 314 | return NULL; |
| 315 | |
Javier Martinez Canillas | 072e78b | 2014-11-10 14:43:53 +0100 | [diff] [blame] | 316 | pdata->regulator = of_get_regulator_init_data(dev, np, desc); |
Heiko Stuebner | 91f23d8 | 2014-09-16 21:22:53 +0200 | [diff] [blame] | 317 | |
| 318 | ret = of_property_read_u32(np, "fcs,suspend-voltage-selector", |
| 319 | &tmp); |
| 320 | if (!ret) |
| 321 | pdata->sleep_vsel_id = tmp; |
| 322 | |
| 323 | return pdata; |
| 324 | } |
| 325 | |
| 326 | static const struct of_device_id fan53555_dt_ids[] = { |
| 327 | { |
| 328 | .compatible = "fcs,fan53555", |
Heiko Stuebner | ee30928 | 2014-09-16 21:22:54 +0200 | [diff] [blame] | 329 | .data = (void *)FAN53555_VENDOR_FAIRCHILD |
| 330 | }, { |
| 331 | .compatible = "silergy,syr827", |
| 332 | .data = (void *)FAN53555_VENDOR_SILERGY, |
| 333 | }, { |
| 334 | .compatible = "silergy,syr828", |
| 335 | .data = (void *)FAN53555_VENDOR_SILERGY, |
Heiko Stuebner | 91f23d8 | 2014-09-16 21:22:53 +0200 | [diff] [blame] | 336 | }, |
| 337 | { } |
| 338 | }; |
| 339 | MODULE_DEVICE_TABLE(of, fan53555_dt_ids); |
| 340 | |
Bill Pemberton | a502357 | 2012-11-19 13:22:22 -0500 | [diff] [blame] | 341 | static int fan53555_regulator_probe(struct i2c_client *client, |
Yunfan Zhang | 49d8c59 | 2012-09-08 03:52:18 -0700 | [diff] [blame] | 342 | const struct i2c_device_id *id) |
| 343 | { |
Heiko Stuebner | 91f23d8 | 2014-09-16 21:22:53 +0200 | [diff] [blame] | 344 | struct device_node *np = client->dev.of_node; |
Yunfan Zhang | 49d8c59 | 2012-09-08 03:52:18 -0700 | [diff] [blame] | 345 | struct fan53555_device_info *di; |
| 346 | struct fan53555_platform_data *pdata; |
| 347 | struct regulator_config config = { }; |
| 348 | unsigned int val; |
| 349 | int ret; |
| 350 | |
Javier Martinez Canillas | 072e78b | 2014-11-10 14:43:53 +0100 | [diff] [blame] | 351 | di = devm_kzalloc(&client->dev, sizeof(struct fan53555_device_info), |
| 352 | GFP_KERNEL); |
| 353 | if (!di) |
| 354 | return -ENOMEM; |
| 355 | |
Jingoo Han | dff91d0 | 2013-07-30 17:20:47 +0900 | [diff] [blame] | 356 | pdata = dev_get_platdata(&client->dev); |
Heiko Stuebner | 91f23d8 | 2014-09-16 21:22:53 +0200 | [diff] [blame] | 357 | if (!pdata) |
Javier Martinez Canillas | 072e78b | 2014-11-10 14:43:53 +0100 | [diff] [blame] | 358 | pdata = fan53555_parse_dt(&client->dev, np, &di->desc); |
Heiko Stuebner | 91f23d8 | 2014-09-16 21:22:53 +0200 | [diff] [blame] | 359 | |
Yunfan Zhang | 49d8c59 | 2012-09-08 03:52:18 -0700 | [diff] [blame] | 360 | if (!pdata || !pdata->regulator) { |
| 361 | dev_err(&client->dev, "Platform data not found!\n"); |
| 362 | return -ENODEV; |
| 363 | } |
| 364 | |
Axel Lin | e13426b | 2014-09-18 21:49:38 +0800 | [diff] [blame] | 365 | di->regulator = pdata->regulator; |
Heiko Stuebner | ee30928 | 2014-09-16 21:22:54 +0200 | [diff] [blame] | 366 | if (client->dev.of_node) { |
| 367 | const struct of_device_id *match; |
| 368 | |
| 369 | match = of_match_device(of_match_ptr(fan53555_dt_ids), |
| 370 | &client->dev); |
| 371 | if (!match) |
| 372 | return -ENODEV; |
| 373 | |
Heiko Stübner | 6f34163 | 2014-09-17 13:21:48 +0200 | [diff] [blame] | 374 | di->vendor = (unsigned long) match->data; |
Heiko Stuebner | ee30928 | 2014-09-16 21:22:54 +0200 | [diff] [blame] | 375 | } else { |
Heiko Stuebner | 91f23d8 | 2014-09-16 21:22:53 +0200 | [diff] [blame] | 376 | /* if no ramp constraint set, get the pdata ramp_delay */ |
| 377 | if (!di->regulator->constraints.ramp_delay) { |
| 378 | int slew_idx = (pdata->slew_rate & 0x7) |
| 379 | ? pdata->slew_rate : 0; |
Heiko Stuebner | dd7e71f | 2014-09-16 17:54:01 +0200 | [diff] [blame] | 380 | |
Heiko Stuebner | 91f23d8 | 2014-09-16 21:22:53 +0200 | [diff] [blame] | 381 | di->regulator->constraints.ramp_delay |
| 382 | = slew_rates[slew_idx]; |
| 383 | } |
Heiko Stuebner | ee30928 | 2014-09-16 21:22:54 +0200 | [diff] [blame] | 384 | |
| 385 | di->vendor = id->driver_data; |
Heiko Stuebner | dd7e71f | 2014-09-16 17:54:01 +0200 | [diff] [blame] | 386 | } |
| 387 | |
Yunfan Zhang | 49d8c59 | 2012-09-08 03:52:18 -0700 | [diff] [blame] | 388 | di->regmap = devm_regmap_init_i2c(client, &fan53555_regmap_config); |
| 389 | if (IS_ERR(di->regmap)) { |
| 390 | dev_err(&client->dev, "Failed to allocate regmap!\n"); |
| 391 | return PTR_ERR(di->regmap); |
| 392 | } |
| 393 | di->dev = &client->dev; |
Yunfan Zhang | 49d8c59 | 2012-09-08 03:52:18 -0700 | [diff] [blame] | 394 | i2c_set_clientdata(client, di); |
| 395 | /* Get chip ID */ |
| 396 | ret = regmap_read(di->regmap, FAN53555_ID1, &val); |
| 397 | if (ret < 0) { |
| 398 | dev_err(&client->dev, "Failed to get chip ID!\n"); |
Sachin Kamat | 145fe1e | 2014-02-18 16:11:04 +0530 | [diff] [blame] | 399 | return ret; |
Yunfan Zhang | 49d8c59 | 2012-09-08 03:52:18 -0700 | [diff] [blame] | 400 | } |
| 401 | di->chip_id = val & DIE_ID; |
| 402 | /* Get chip revision */ |
| 403 | ret = regmap_read(di->regmap, FAN53555_ID2, &val); |
| 404 | if (ret < 0) { |
| 405 | dev_err(&client->dev, "Failed to get chip Rev!\n"); |
Sachin Kamat | 145fe1e | 2014-02-18 16:11:04 +0530 | [diff] [blame] | 406 | return ret; |
Yunfan Zhang | 49d8c59 | 2012-09-08 03:52:18 -0700 | [diff] [blame] | 407 | } |
| 408 | di->chip_rev = val & DIE_REV; |
| 409 | dev_info(&client->dev, "FAN53555 Option[%d] Rev[%d] Detected!\n", |
| 410 | di->chip_id, di->chip_rev); |
| 411 | /* Device init */ |
| 412 | ret = fan53555_device_setup(di, pdata); |
| 413 | if (ret < 0) { |
| 414 | dev_err(&client->dev, "Failed to setup device!\n"); |
| 415 | return ret; |
| 416 | } |
| 417 | /* Register regulator */ |
| 418 | config.dev = di->dev; |
| 419 | config.init_data = di->regulator; |
| 420 | config.regmap = di->regmap; |
| 421 | config.driver_data = di; |
Heiko Stuebner | 91f23d8 | 2014-09-16 21:22:53 +0200 | [diff] [blame] | 422 | config.of_node = np; |
| 423 | |
Yunfan Zhang | 49d8c59 | 2012-09-08 03:52:18 -0700 | [diff] [blame] | 424 | ret = fan53555_regulator_register(di, &config); |
| 425 | if (ret < 0) |
| 426 | dev_err(&client->dev, "Failed to register regulator!\n"); |
| 427 | return ret; |
| 428 | |
| 429 | } |
| 430 | |
Yunfan Zhang | 49d8c59 | 2012-09-08 03:52:18 -0700 | [diff] [blame] | 431 | static const struct i2c_device_id fan53555_id[] = { |
Heiko Stuebner | ee30928 | 2014-09-16 21:22:54 +0200 | [diff] [blame] | 432 | { |
| 433 | .name = "fan53555", |
| 434 | .driver_data = FAN53555_VENDOR_FAIRCHILD |
| 435 | }, { |
| 436 | .name = "syr82x", |
| 437 | .driver_data = FAN53555_VENDOR_SILERGY |
| 438 | }, |
Yunfan Zhang | 49d8c59 | 2012-09-08 03:52:18 -0700 | [diff] [blame] | 439 | { }, |
| 440 | }; |
| 441 | |
| 442 | static struct i2c_driver fan53555_regulator_driver = { |
| 443 | .driver = { |
| 444 | .name = "fan53555-regulator", |
Heiko Stuebner | 91f23d8 | 2014-09-16 21:22:53 +0200 | [diff] [blame] | 445 | .of_match_table = of_match_ptr(fan53555_dt_ids), |
Yunfan Zhang | 49d8c59 | 2012-09-08 03:52:18 -0700 | [diff] [blame] | 446 | }, |
| 447 | .probe = fan53555_regulator_probe, |
Yunfan Zhang | 49d8c59 | 2012-09-08 03:52:18 -0700 | [diff] [blame] | 448 | .id_table = fan53555_id, |
| 449 | }; |
| 450 | |
| 451 | module_i2c_driver(fan53555_regulator_driver); |
| 452 | |
| 453 | MODULE_AUTHOR("Yunfan Zhang <yfzhang@marvell.com>"); |
| 454 | MODULE_DESCRIPTION("FAN53555 regulator driver"); |
| 455 | MODULE_LICENSE("GPL v2"); |