149d8c599SYunfan Zhang /* 249d8c599SYunfan Zhang * FAN53555 Fairchild Digitally Programmable TinyBuck Regulator Driver. 349d8c599SYunfan Zhang * 449d8c599SYunfan Zhang * Supported Part Numbers: 549d8c599SYunfan Zhang * FAN53555UC00X/01X/03X/04X/05X 649d8c599SYunfan Zhang * 749d8c599SYunfan Zhang * Copyright (c) 2012 Marvell Technology Ltd. 849d8c599SYunfan Zhang * Yunfan Zhang <yfzhang@marvell.com> 949d8c599SYunfan Zhang * 1049d8c599SYunfan Zhang * This package is free software; you can redistribute it and/or modify 1149d8c599SYunfan Zhang * it under the terms of the GNU General Public License version 2 as 1249d8c599SYunfan Zhang * published by the Free Software Foundation. 1349d8c599SYunfan Zhang * 1449d8c599SYunfan Zhang */ 1549d8c599SYunfan Zhang #include <linux/module.h> 1649d8c599SYunfan Zhang #include <linux/param.h> 1749d8c599SYunfan Zhang #include <linux/err.h> 1849d8c599SYunfan Zhang #include <linux/platform_device.h> 1949d8c599SYunfan Zhang #include <linux/regulator/driver.h> 2049d8c599SYunfan Zhang #include <linux/regulator/machine.h> 2191f23d8fSHeiko Stuebner #include <linux/regulator/of_regulator.h> 2291f23d8fSHeiko Stuebner #include <linux/of_device.h> 2349d8c599SYunfan Zhang #include <linux/i2c.h> 2449d8c599SYunfan Zhang #include <linux/slab.h> 2549d8c599SYunfan Zhang #include <linux/regmap.h> 2649d8c599SYunfan Zhang #include <linux/regulator/fan53555.h> 2749d8c599SYunfan Zhang 2849d8c599SYunfan Zhang /* Voltage setting */ 2949d8c599SYunfan Zhang #define FAN53555_VSEL0 0x00 3049d8c599SYunfan Zhang #define FAN53555_VSEL1 0x01 3149d8c599SYunfan Zhang /* Control register */ 3249d8c599SYunfan Zhang #define FAN53555_CONTROL 0x02 3349d8c599SYunfan Zhang /* IC Type */ 3449d8c599SYunfan Zhang #define FAN53555_ID1 0x03 3549d8c599SYunfan Zhang /* IC mask version */ 3649d8c599SYunfan Zhang #define FAN53555_ID2 0x04 3749d8c599SYunfan Zhang /* Monitor register */ 3849d8c599SYunfan Zhang #define FAN53555_MONITOR 0x05 3949d8c599SYunfan Zhang 4049d8c599SYunfan Zhang /* VSEL bit definitions */ 4149d8c599SYunfan Zhang #define VSEL_BUCK_EN (1 << 7) 4249d8c599SYunfan Zhang #define VSEL_MODE (1 << 6) 4349d8c599SYunfan Zhang #define VSEL_NSEL_MASK 0x3F 4449d8c599SYunfan Zhang /* Chip ID and Verison */ 4549d8c599SYunfan Zhang #define DIE_ID 0x0F /* ID1 */ 4649d8c599SYunfan Zhang #define DIE_REV 0x0F /* ID2 */ 4749d8c599SYunfan Zhang /* Control bit definitions */ 4849d8c599SYunfan Zhang #define CTL_OUTPUT_DISCHG (1 << 7) 4949d8c599SYunfan Zhang #define CTL_SLEW_MASK (0x7 << 4) 5049d8c599SYunfan Zhang #define CTL_SLEW_SHIFT 4 5149d8c599SYunfan Zhang #define CTL_RESET (1 << 2) 5249d8c599SYunfan Zhang 5349d8c599SYunfan Zhang #define FAN53555_NVOLTAGES 64 /* Numbers of voltages */ 5449d8c599SYunfan Zhang 55ee30928aSHeiko Stuebner enum fan53555_vendor { 56ee30928aSHeiko Stuebner FAN53555_VENDOR_FAIRCHILD = 0, 57ee30928aSHeiko Stuebner FAN53555_VENDOR_SILERGY, 58ee30928aSHeiko Stuebner }; 59ee30928aSHeiko Stuebner 6049d8c599SYunfan Zhang /* IC Type */ 6149d8c599SYunfan Zhang enum { 6249d8c599SYunfan Zhang FAN53555_CHIP_ID_00 = 0, 6349d8c599SYunfan Zhang FAN53555_CHIP_ID_01, 6449d8c599SYunfan Zhang FAN53555_CHIP_ID_02, 6549d8c599SYunfan Zhang FAN53555_CHIP_ID_03, 6649d8c599SYunfan Zhang FAN53555_CHIP_ID_04, 6749d8c599SYunfan Zhang FAN53555_CHIP_ID_05, 6849d8c599SYunfan Zhang }; 6949d8c599SYunfan Zhang 70ee30928aSHeiko Stuebner enum { 71ee30928aSHeiko Stuebner SILERGY_SYR82X = 8, 72ee30928aSHeiko Stuebner }; 73ee30928aSHeiko Stuebner 7449d8c599SYunfan Zhang struct fan53555_device_info { 75ee30928aSHeiko Stuebner enum fan53555_vendor vendor; 7649d8c599SYunfan Zhang struct regmap *regmap; 7749d8c599SYunfan Zhang struct device *dev; 7849d8c599SYunfan Zhang struct regulator_desc desc; 7949d8c599SYunfan Zhang struct regulator_dev *rdev; 8049d8c599SYunfan Zhang struct regulator_init_data *regulator; 8149d8c599SYunfan Zhang /* IC Type and Rev */ 8249d8c599SYunfan Zhang int chip_id; 8349d8c599SYunfan Zhang int chip_rev; 8449d8c599SYunfan Zhang /* Voltage setting register */ 8549d8c599SYunfan Zhang unsigned int vol_reg; 8649d8c599SYunfan Zhang unsigned int sleep_reg; 8749d8c599SYunfan Zhang /* Voltage range and step(linear) */ 8849d8c599SYunfan Zhang unsigned int vsel_min; 8949d8c599SYunfan Zhang unsigned int vsel_step; 9049d8c599SYunfan Zhang /* Voltage slew rate limiting */ 9149d8c599SYunfan Zhang unsigned int slew_rate; 9249d8c599SYunfan Zhang /* Sleep voltage cache */ 9349d8c599SYunfan Zhang unsigned int sleep_vol_cache; 9449d8c599SYunfan Zhang }; 9549d8c599SYunfan Zhang 9649d8c599SYunfan Zhang static int fan53555_set_suspend_voltage(struct regulator_dev *rdev, int uV) 9749d8c599SYunfan Zhang { 9849d8c599SYunfan Zhang struct fan53555_device_info *di = rdev_get_drvdata(rdev); 9949d8c599SYunfan Zhang int ret; 10049d8c599SYunfan Zhang 10149d8c599SYunfan Zhang if (di->sleep_vol_cache == uV) 10249d8c599SYunfan Zhang return 0; 10349d8c599SYunfan Zhang ret = regulator_map_voltage_linear(rdev, uV, uV); 10449d8c599SYunfan Zhang if (ret < 0) 105145fe1e1SSachin Kamat return ret; 10649d8c599SYunfan Zhang ret = regmap_update_bits(di->regmap, di->sleep_reg, 10749d8c599SYunfan Zhang VSEL_NSEL_MASK, ret); 10849d8c599SYunfan Zhang if (ret < 0) 109145fe1e1SSachin Kamat return ret; 11049d8c599SYunfan Zhang /* Cache the sleep voltage setting. 11149d8c599SYunfan Zhang * Might not be the real voltage which is rounded */ 11249d8c599SYunfan Zhang di->sleep_vol_cache = uV; 11349d8c599SYunfan Zhang 11449d8c599SYunfan Zhang return 0; 11549d8c599SYunfan Zhang } 11649d8c599SYunfan Zhang 11749d8c599SYunfan Zhang static int fan53555_set_mode(struct regulator_dev *rdev, unsigned int mode) 11849d8c599SYunfan Zhang { 11949d8c599SYunfan Zhang struct fan53555_device_info *di = rdev_get_drvdata(rdev); 12049d8c599SYunfan Zhang 12149d8c599SYunfan Zhang switch (mode) { 12249d8c599SYunfan Zhang case REGULATOR_MODE_FAST: 12349d8c599SYunfan Zhang regmap_update_bits(di->regmap, di->vol_reg, 12449d8c599SYunfan Zhang VSEL_MODE, VSEL_MODE); 12549d8c599SYunfan Zhang break; 12649d8c599SYunfan Zhang case REGULATOR_MODE_NORMAL: 12749d8c599SYunfan Zhang regmap_update_bits(di->regmap, di->vol_reg, VSEL_MODE, 0); 12849d8c599SYunfan Zhang break; 12949d8c599SYunfan Zhang default: 13049d8c599SYunfan Zhang return -EINVAL; 13149d8c599SYunfan Zhang } 13249d8c599SYunfan Zhang return 0; 13349d8c599SYunfan Zhang } 13449d8c599SYunfan Zhang 13549d8c599SYunfan Zhang static unsigned int fan53555_get_mode(struct regulator_dev *rdev) 13649d8c599SYunfan Zhang { 13749d8c599SYunfan Zhang struct fan53555_device_info *di = rdev_get_drvdata(rdev); 13849d8c599SYunfan Zhang unsigned int val; 13949d8c599SYunfan Zhang int ret = 0; 14049d8c599SYunfan Zhang 14149d8c599SYunfan Zhang ret = regmap_read(di->regmap, di->vol_reg, &val); 14249d8c599SYunfan Zhang if (ret < 0) 14349d8c599SYunfan Zhang return ret; 14449d8c599SYunfan Zhang if (val & VSEL_MODE) 14549d8c599SYunfan Zhang return REGULATOR_MODE_FAST; 14649d8c599SYunfan Zhang else 14749d8c599SYunfan Zhang return REGULATOR_MODE_NORMAL; 14849d8c599SYunfan Zhang } 14949d8c599SYunfan Zhang 150dd7e71fbSHeiko Stuebner static int slew_rates[] = { 151dd7e71fbSHeiko Stuebner 64000, 152dd7e71fbSHeiko Stuebner 32000, 153dd7e71fbSHeiko Stuebner 16000, 154dd7e71fbSHeiko Stuebner 8000, 155dd7e71fbSHeiko Stuebner 4000, 156dd7e71fbSHeiko Stuebner 2000, 157dd7e71fbSHeiko Stuebner 1000, 158dd7e71fbSHeiko Stuebner 500, 159dd7e71fbSHeiko Stuebner }; 160dd7e71fbSHeiko Stuebner 161dd7e71fbSHeiko Stuebner static int fan53555_set_ramp(struct regulator_dev *rdev, int ramp) 162dd7e71fbSHeiko Stuebner { 163dd7e71fbSHeiko Stuebner struct fan53555_device_info *di = rdev_get_drvdata(rdev); 164dd7e71fbSHeiko Stuebner int regval = -1, i; 165dd7e71fbSHeiko Stuebner 166dd7e71fbSHeiko Stuebner for (i = 0; i < ARRAY_SIZE(slew_rates); i++) { 167dd7e71fbSHeiko Stuebner if (ramp <= slew_rates[i]) 168dd7e71fbSHeiko Stuebner regval = i; 169dd7e71fbSHeiko Stuebner else 170dd7e71fbSHeiko Stuebner break; 171dd7e71fbSHeiko Stuebner } 172dd7e71fbSHeiko Stuebner 173dd7e71fbSHeiko Stuebner if (regval < 0) { 174dd7e71fbSHeiko Stuebner dev_err(di->dev, "unsupported ramp value %d\n", ramp); 175dd7e71fbSHeiko Stuebner return -EINVAL; 176dd7e71fbSHeiko Stuebner } 177dd7e71fbSHeiko Stuebner 178dd7e71fbSHeiko Stuebner return regmap_update_bits(di->regmap, FAN53555_CONTROL, 179dd7e71fbSHeiko Stuebner CTL_SLEW_MASK, regval << CTL_SLEW_SHIFT); 180dd7e71fbSHeiko Stuebner } 181dd7e71fbSHeiko Stuebner 18249d8c599SYunfan Zhang static struct regulator_ops fan53555_regulator_ops = { 18349d8c599SYunfan Zhang .set_voltage_sel = regulator_set_voltage_sel_regmap, 18449d8c599SYunfan Zhang .get_voltage_sel = regulator_get_voltage_sel_regmap, 18549d8c599SYunfan Zhang .map_voltage = regulator_map_voltage_linear, 18649d8c599SYunfan Zhang .list_voltage = regulator_list_voltage_linear, 18749d8c599SYunfan Zhang .set_suspend_voltage = fan53555_set_suspend_voltage, 18849d8c599SYunfan Zhang .enable = regulator_enable_regmap, 18949d8c599SYunfan Zhang .disable = regulator_disable_regmap, 19049d8c599SYunfan Zhang .is_enabled = regulator_is_enabled_regmap, 19149d8c599SYunfan Zhang .set_mode = fan53555_set_mode, 19249d8c599SYunfan Zhang .get_mode = fan53555_get_mode, 193dd7e71fbSHeiko Stuebner .set_ramp_delay = fan53555_set_ramp, 19449d8c599SYunfan Zhang }; 19549d8c599SYunfan Zhang 196ee30928aSHeiko Stuebner static int fan53555_voltages_setup_fairchild(struct fan53555_device_info *di) 19749d8c599SYunfan Zhang { 19849d8c599SYunfan Zhang /* Init voltage range and step */ 19949d8c599SYunfan Zhang switch (di->chip_id) { 20049d8c599SYunfan Zhang case FAN53555_CHIP_ID_00: 20149d8c599SYunfan Zhang case FAN53555_CHIP_ID_01: 20249d8c599SYunfan Zhang case FAN53555_CHIP_ID_03: 20349d8c599SYunfan Zhang case FAN53555_CHIP_ID_05: 20449d8c599SYunfan Zhang di->vsel_min = 600000; 20549d8c599SYunfan Zhang di->vsel_step = 10000; 20649d8c599SYunfan Zhang break; 20749d8c599SYunfan Zhang case FAN53555_CHIP_ID_04: 20849d8c599SYunfan Zhang di->vsel_min = 603000; 20949d8c599SYunfan Zhang di->vsel_step = 12826; 21049d8c599SYunfan Zhang break; 21149d8c599SYunfan Zhang default: 21249d8c599SYunfan Zhang dev_err(di->dev, 213ee30928aSHeiko Stuebner "Chip ID %d not supported!\n", di->chip_id); 21449d8c599SYunfan Zhang return -EINVAL; 21549d8c599SYunfan Zhang } 216dd7e71fbSHeiko Stuebner 217dd7e71fbSHeiko Stuebner return 0; 21849d8c599SYunfan Zhang } 21949d8c599SYunfan Zhang 220ee30928aSHeiko Stuebner static int fan53555_voltages_setup_silergy(struct fan53555_device_info *di) 221ee30928aSHeiko Stuebner { 222ee30928aSHeiko Stuebner /* Init voltage range and step */ 223ee30928aSHeiko Stuebner switch (di->chip_id) { 224ee30928aSHeiko Stuebner case SILERGY_SYR82X: 225ee30928aSHeiko Stuebner di->vsel_min = 712500; 226ee30928aSHeiko Stuebner di->vsel_step = 12500; 227ee30928aSHeiko Stuebner break; 228ee30928aSHeiko Stuebner default: 229ee30928aSHeiko Stuebner dev_err(di->dev, 230ee30928aSHeiko Stuebner "Chip ID %d not supported!\n", di->chip_id); 231ee30928aSHeiko Stuebner return -EINVAL; 232ee30928aSHeiko Stuebner } 233ee30928aSHeiko Stuebner 234ee30928aSHeiko Stuebner return 0; 235ee30928aSHeiko Stuebner } 236ee30928aSHeiko Stuebner 237ee30928aSHeiko Stuebner /* For 00,01,03,05 options: 238ee30928aSHeiko Stuebner * VOUT = 0.60V + NSELx * 10mV, from 0.60 to 1.23V. 239ee30928aSHeiko Stuebner * For 04 option: 240ee30928aSHeiko Stuebner * VOUT = 0.603V + NSELx * 12.826mV, from 0.603 to 1.411V. 241ee30928aSHeiko Stuebner * */ 242ee30928aSHeiko Stuebner static int fan53555_device_setup(struct fan53555_device_info *di, 243ee30928aSHeiko Stuebner struct fan53555_platform_data *pdata) 244ee30928aSHeiko Stuebner { 245ee30928aSHeiko Stuebner int ret = 0; 246ee30928aSHeiko Stuebner 247ee30928aSHeiko Stuebner /* Setup voltage control register */ 248ee30928aSHeiko Stuebner switch (pdata->sleep_vsel_id) { 249ee30928aSHeiko Stuebner case FAN53555_VSEL_ID_0: 250ee30928aSHeiko Stuebner di->sleep_reg = FAN53555_VSEL0; 251ee30928aSHeiko Stuebner di->vol_reg = FAN53555_VSEL1; 252ee30928aSHeiko Stuebner break; 253ee30928aSHeiko Stuebner case FAN53555_VSEL_ID_1: 254ee30928aSHeiko Stuebner di->sleep_reg = FAN53555_VSEL1; 255ee30928aSHeiko Stuebner di->vol_reg = FAN53555_VSEL0; 256ee30928aSHeiko Stuebner break; 257ee30928aSHeiko Stuebner default: 258ee30928aSHeiko Stuebner dev_err(di->dev, "Invalid VSEL ID!\n"); 259ee30928aSHeiko Stuebner return -EINVAL; 260ee30928aSHeiko Stuebner } 261ee30928aSHeiko Stuebner 262ee30928aSHeiko Stuebner switch (di->vendor) { 263ee30928aSHeiko Stuebner case FAN53555_VENDOR_FAIRCHILD: 264ee30928aSHeiko Stuebner ret = fan53555_voltages_setup_fairchild(di); 265ee30928aSHeiko Stuebner break; 266ee30928aSHeiko Stuebner case FAN53555_VENDOR_SILERGY: 267ee30928aSHeiko Stuebner ret = fan53555_voltages_setup_silergy(di); 268ee30928aSHeiko Stuebner break; 269ee30928aSHeiko Stuebner default: 270fe230531SAxel Lin dev_err(di->dev, "vendor %d not supported!\n", di->vendor); 271ee30928aSHeiko Stuebner return -EINVAL; 272ee30928aSHeiko Stuebner } 273ee30928aSHeiko Stuebner 274ee30928aSHeiko Stuebner return ret; 275ee30928aSHeiko Stuebner } 276ee30928aSHeiko Stuebner 27749d8c599SYunfan Zhang static int fan53555_regulator_register(struct fan53555_device_info *di, 27849d8c599SYunfan Zhang struct regulator_config *config) 27949d8c599SYunfan Zhang { 28049d8c599SYunfan Zhang struct regulator_desc *rdesc = &di->desc; 28149d8c599SYunfan Zhang 28249d8c599SYunfan Zhang rdesc->name = "fan53555-reg"; 2833415d601SHeiko Stuebner rdesc->supply_name = "vin"; 28449d8c599SYunfan Zhang rdesc->ops = &fan53555_regulator_ops; 28549d8c599SYunfan Zhang rdesc->type = REGULATOR_VOLTAGE; 28649d8c599SYunfan Zhang rdesc->n_voltages = FAN53555_NVOLTAGES; 28749d8c599SYunfan Zhang rdesc->enable_reg = di->vol_reg; 28849d8c599SYunfan Zhang rdesc->enable_mask = VSEL_BUCK_EN; 28949d8c599SYunfan Zhang rdesc->min_uV = di->vsel_min; 29049d8c599SYunfan Zhang rdesc->uV_step = di->vsel_step; 29149d8c599SYunfan Zhang rdesc->vsel_reg = di->vol_reg; 29249d8c599SYunfan Zhang rdesc->vsel_mask = VSEL_NSEL_MASK; 29349d8c599SYunfan Zhang rdesc->owner = THIS_MODULE; 29449d8c599SYunfan Zhang 295b15f5f76SAxel Lin di->rdev = devm_regulator_register(di->dev, &di->desc, config); 2968c6ffba0SRusty Russell return PTR_ERR_OR_ZERO(di->rdev); 29749d8c599SYunfan Zhang } 29849d8c599SYunfan Zhang 29949d8c599SYunfan Zhang static struct regmap_config fan53555_regmap_config = { 30049d8c599SYunfan Zhang .reg_bits = 8, 30149d8c599SYunfan Zhang .val_bits = 8, 30249d8c599SYunfan Zhang }; 30349d8c599SYunfan Zhang 30491f23d8fSHeiko Stuebner static struct fan53555_platform_data *fan53555_parse_dt(struct device *dev, 30591f23d8fSHeiko Stuebner struct device_node *np) 30691f23d8fSHeiko Stuebner { 30791f23d8fSHeiko Stuebner struct fan53555_platform_data *pdata; 30891f23d8fSHeiko Stuebner int ret; 30991f23d8fSHeiko Stuebner u32 tmp; 31091f23d8fSHeiko Stuebner 31191f23d8fSHeiko Stuebner pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL); 31291f23d8fSHeiko Stuebner if (!pdata) 31391f23d8fSHeiko Stuebner return NULL; 31491f23d8fSHeiko Stuebner 31591f23d8fSHeiko Stuebner pdata->regulator = of_get_regulator_init_data(dev, np); 31691f23d8fSHeiko Stuebner 31791f23d8fSHeiko Stuebner ret = of_property_read_u32(np, "fcs,suspend-voltage-selector", 31891f23d8fSHeiko Stuebner &tmp); 31991f23d8fSHeiko Stuebner if (!ret) 32091f23d8fSHeiko Stuebner pdata->sleep_vsel_id = tmp; 32191f23d8fSHeiko Stuebner 32291f23d8fSHeiko Stuebner return pdata; 32391f23d8fSHeiko Stuebner } 32491f23d8fSHeiko Stuebner 32591f23d8fSHeiko Stuebner static const struct of_device_id fan53555_dt_ids[] = { 32691f23d8fSHeiko Stuebner { 32791f23d8fSHeiko Stuebner .compatible = "fcs,fan53555", 328ee30928aSHeiko Stuebner .data = (void *)FAN53555_VENDOR_FAIRCHILD 329ee30928aSHeiko Stuebner }, { 330ee30928aSHeiko Stuebner .compatible = "silergy,syr827", 331ee30928aSHeiko Stuebner .data = (void *)FAN53555_VENDOR_SILERGY, 332ee30928aSHeiko Stuebner }, { 333ee30928aSHeiko Stuebner .compatible = "silergy,syr828", 334ee30928aSHeiko Stuebner .data = (void *)FAN53555_VENDOR_SILERGY, 33591f23d8fSHeiko Stuebner }, 33691f23d8fSHeiko Stuebner { } 33791f23d8fSHeiko Stuebner }; 33891f23d8fSHeiko Stuebner MODULE_DEVICE_TABLE(of, fan53555_dt_ids); 33991f23d8fSHeiko Stuebner 340a5023574SBill Pemberton static int fan53555_regulator_probe(struct i2c_client *client, 34149d8c599SYunfan Zhang const struct i2c_device_id *id) 34249d8c599SYunfan Zhang { 34391f23d8fSHeiko Stuebner struct device_node *np = client->dev.of_node; 34449d8c599SYunfan Zhang struct fan53555_device_info *di; 34549d8c599SYunfan Zhang struct fan53555_platform_data *pdata; 34649d8c599SYunfan Zhang struct regulator_config config = { }; 34749d8c599SYunfan Zhang unsigned int val; 34849d8c599SYunfan Zhang int ret; 34949d8c599SYunfan Zhang 350dff91d0bSJingoo Han pdata = dev_get_platdata(&client->dev); 35191f23d8fSHeiko Stuebner if (!pdata) 35291f23d8fSHeiko Stuebner pdata = fan53555_parse_dt(&client->dev, np); 35391f23d8fSHeiko Stuebner 35449d8c599SYunfan Zhang if (!pdata || !pdata->regulator) { 35549d8c599SYunfan Zhang dev_err(&client->dev, "Platform data not found!\n"); 35649d8c599SYunfan Zhang return -ENODEV; 35749d8c599SYunfan Zhang } 35849d8c599SYunfan Zhang 35949d8c599SYunfan Zhang di = devm_kzalloc(&client->dev, sizeof(struct fan53555_device_info), 36049d8c599SYunfan Zhang GFP_KERNEL); 361df948bbfSSachin Kamat if (!di) 36249d8c599SYunfan Zhang return -ENOMEM; 363df948bbfSSachin Kamat 364*e13426bfSAxel Lin di->regulator = pdata->regulator; 365ee30928aSHeiko Stuebner if (client->dev.of_node) { 366ee30928aSHeiko Stuebner const struct of_device_id *match; 367ee30928aSHeiko Stuebner 368ee30928aSHeiko Stuebner match = of_match_device(of_match_ptr(fan53555_dt_ids), 369ee30928aSHeiko Stuebner &client->dev); 370ee30928aSHeiko Stuebner if (!match) 371ee30928aSHeiko Stuebner return -ENODEV; 372ee30928aSHeiko Stuebner 3736f34163cSHeiko Stübner di->vendor = (unsigned long) match->data; 374ee30928aSHeiko Stuebner } else { 375dd7e71fbSHeiko Stuebner /* if no ramp constraint set, get the pdata ramp_delay */ 376dd7e71fbSHeiko Stuebner if (!di->regulator->constraints.ramp_delay) { 37791f23d8fSHeiko Stuebner int slew_idx = (pdata->slew_rate & 0x7) 37891f23d8fSHeiko Stuebner ? pdata->slew_rate : 0; 379dd7e71fbSHeiko Stuebner 38091f23d8fSHeiko Stuebner di->regulator->constraints.ramp_delay 38191f23d8fSHeiko Stuebner = slew_rates[slew_idx]; 38291f23d8fSHeiko Stuebner } 383ee30928aSHeiko Stuebner 384ee30928aSHeiko Stuebner di->vendor = id->driver_data; 385dd7e71fbSHeiko Stuebner } 386dd7e71fbSHeiko Stuebner 38749d8c599SYunfan Zhang di->regmap = devm_regmap_init_i2c(client, &fan53555_regmap_config); 38849d8c599SYunfan Zhang if (IS_ERR(di->regmap)) { 38949d8c599SYunfan Zhang dev_err(&client->dev, "Failed to allocate regmap!\n"); 39049d8c599SYunfan Zhang return PTR_ERR(di->regmap); 39149d8c599SYunfan Zhang } 39249d8c599SYunfan Zhang di->dev = &client->dev; 39349d8c599SYunfan Zhang i2c_set_clientdata(client, di); 39449d8c599SYunfan Zhang /* Get chip ID */ 39549d8c599SYunfan Zhang ret = regmap_read(di->regmap, FAN53555_ID1, &val); 39649d8c599SYunfan Zhang if (ret < 0) { 39749d8c599SYunfan Zhang dev_err(&client->dev, "Failed to get chip ID!\n"); 398145fe1e1SSachin Kamat return ret; 39949d8c599SYunfan Zhang } 40049d8c599SYunfan Zhang di->chip_id = val & DIE_ID; 40149d8c599SYunfan Zhang /* Get chip revision */ 40249d8c599SYunfan Zhang ret = regmap_read(di->regmap, FAN53555_ID2, &val); 40349d8c599SYunfan Zhang if (ret < 0) { 40449d8c599SYunfan Zhang dev_err(&client->dev, "Failed to get chip Rev!\n"); 405145fe1e1SSachin Kamat return ret; 40649d8c599SYunfan Zhang } 40749d8c599SYunfan Zhang di->chip_rev = val & DIE_REV; 40849d8c599SYunfan Zhang dev_info(&client->dev, "FAN53555 Option[%d] Rev[%d] Detected!\n", 40949d8c599SYunfan Zhang di->chip_id, di->chip_rev); 41049d8c599SYunfan Zhang /* Device init */ 41149d8c599SYunfan Zhang ret = fan53555_device_setup(di, pdata); 41249d8c599SYunfan Zhang if (ret < 0) { 41349d8c599SYunfan Zhang dev_err(&client->dev, "Failed to setup device!\n"); 41449d8c599SYunfan Zhang return ret; 41549d8c599SYunfan Zhang } 41649d8c599SYunfan Zhang /* Register regulator */ 41749d8c599SYunfan Zhang config.dev = di->dev; 41849d8c599SYunfan Zhang config.init_data = di->regulator; 41949d8c599SYunfan Zhang config.regmap = di->regmap; 42049d8c599SYunfan Zhang config.driver_data = di; 42191f23d8fSHeiko Stuebner config.of_node = np; 42291f23d8fSHeiko Stuebner 42349d8c599SYunfan Zhang ret = fan53555_regulator_register(di, &config); 42449d8c599SYunfan Zhang if (ret < 0) 42549d8c599SYunfan Zhang dev_err(&client->dev, "Failed to register regulator!\n"); 42649d8c599SYunfan Zhang return ret; 42749d8c599SYunfan Zhang 42849d8c599SYunfan Zhang } 42949d8c599SYunfan Zhang 43049d8c599SYunfan Zhang static const struct i2c_device_id fan53555_id[] = { 431ee30928aSHeiko Stuebner { 432ee30928aSHeiko Stuebner .name = "fan53555", 433ee30928aSHeiko Stuebner .driver_data = FAN53555_VENDOR_FAIRCHILD 434ee30928aSHeiko Stuebner }, { 435ee30928aSHeiko Stuebner .name = "syr82x", 436ee30928aSHeiko Stuebner .driver_data = FAN53555_VENDOR_SILERGY 437ee30928aSHeiko Stuebner }, 43849d8c599SYunfan Zhang { }, 43949d8c599SYunfan Zhang }; 44049d8c599SYunfan Zhang 44149d8c599SYunfan Zhang static struct i2c_driver fan53555_regulator_driver = { 44249d8c599SYunfan Zhang .driver = { 44349d8c599SYunfan Zhang .name = "fan53555-regulator", 44491f23d8fSHeiko Stuebner .of_match_table = of_match_ptr(fan53555_dt_ids), 44549d8c599SYunfan Zhang }, 44649d8c599SYunfan Zhang .probe = fan53555_regulator_probe, 44749d8c599SYunfan Zhang .id_table = fan53555_id, 44849d8c599SYunfan Zhang }; 44949d8c599SYunfan Zhang 45049d8c599SYunfan Zhang module_i2c_driver(fan53555_regulator_driver); 45149d8c599SYunfan Zhang 45249d8c599SYunfan Zhang MODULE_AUTHOR("Yunfan Zhang <yfzhang@marvell.com>"); 45349d8c599SYunfan Zhang MODULE_DESCRIPTION("FAN53555 regulator driver"); 45449d8c599SYunfan Zhang MODULE_LICENSE("GPL v2"); 455