diff options
Diffstat (limited to 'drivers/regulator/pfuze100-regulator.c')
-rw-r--r-- | drivers/regulator/pfuze100-regulator.c | 110 |
1 files changed, 109 insertions, 1 deletions
diff --git a/drivers/regulator/pfuze100-regulator.c b/drivers/regulator/pfuze100-regulator.c index ffb1f61d2c75..f4f622ee3556 100644 --- a/drivers/regulator/pfuze100-regulator.c +++ b/drivers/regulator/pfuze100-regulator.c @@ -1,5 +1,6 @@ /* * Copyright (C) 2011-2013 Freescale Semiconductor, Inc. All Rights Reserved. + * Copyright 2017 NXP * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -35,6 +36,15 @@ #define PFUZE100_STANDBY_OFFSET 1 #define PFUZE100_MODE_OFFSET 3 #define PFUZE100_CONF_OFFSET 4 +/* + * below regs will lost after exit from LPSR mode(PFUZE3000), need to be saved + * and restored: + * 0x20~0x40: 33 + * 0x66~0x71: 12 + * 0x7f: 1 + * total 46 registers. + */ +#define PFUZE100_REG_SAVED_NUM (33 + 12 + 1) #define PFUZE100_DEVICEID 0x0 #define PFUZE100_REVID 0x3 @@ -68,6 +78,8 @@ struct pfuze_chip { int chip_id; struct regmap *regmap; struct device *dev; + bool need_restore; + unsigned int reg_save_array[PFUZE100_REG_SAVED_NUM]; struct pfuze_regulator regulator_descs[PFUZE100_MAX_REGULATOR]; struct regulator_dev *regulators[PFUZE100_MAX_REGULATOR]; struct pfuze_regulator *pfuze_regulators; @@ -81,6 +93,13 @@ static const int pfuze100_vsnvs[] = { 1000000, 1100000, 1200000, 1300000, 1500000, 1800000, 3000000, }; +static const int pfuze3000_sw1a[] = { + 700000, 725000, 750000, 775000, 800000, 825000, 850000, 875000, + 900000, 925000, 950000, 975000, 1000000, 1025000, 1050000, 1075000, + 1100000, 1125000, 1150000, 1175000, 1200000, 1225000, 1250000, 1275000, + 1300000, 1325000, 1350000, 1375000, 1400000, 1425000, 1800000, 3300000, +}; + static const int pfuze3000_sw2lo[] = { 1500000, 1550000, 1600000, 1650000, 1700000, 1750000, 1800000, 1850000, }; @@ -143,6 +162,9 @@ static struct regulator_ops pfuze100_fixed_regulator_ops = { }; static struct regulator_ops pfuze100_sw_regulator_ops = { + .enable = regulator_enable_regmap, + .disable = regulator_disable_regmap, + .is_enabled = regulator_is_enabled_regmap, .list_voltage = regulator_list_voltage_linear, .set_voltage_sel = regulator_set_voltage_sel_regmap, .get_voltage_sel = regulator_get_voltage_sel_regmap, @@ -189,6 +211,11 @@ static struct regulator_ops pfuze100_swb_regulator_ops = { .uV_step = (step), \ .vsel_reg = (base) + PFUZE100_VOL_OFFSET, \ .vsel_mask = 0x3f, \ + .enable_reg = (base) + PFUZE100_MODE_OFFSET, \ + .enable_val = 0xc, \ + .disable_val = 0x0, \ + .enable_mask = 0xf, \ + .enable_time = 500, \ }, \ .stby_reg = (base) + PFUZE100_STANDBY_OFFSET, \ .stby_mask = 0x3f, \ @@ -321,7 +348,7 @@ static struct pfuze_regulator pfuze200_regulators[] = { }; static struct pfuze_regulator pfuze3000_regulators[] = { - PFUZE100_SW_REG(PFUZE3000, SW1A, PFUZE100_SW1ABVOL, 700000, 1475000, 25000), + PFUZE100_SWB_REG(PFUZE3000, SW1A, PFUZE100_SW1ABVOL, 0x1f, pfuze3000_sw1a), PFUZE100_SW_REG(PFUZE3000, SW1B, PFUZE100_SW1CVOL, 700000, 1475000, 25000), PFUZE100_SWB_REG(PFUZE3000, SW2, PFUZE100_SW2VOL, 0x7, pfuze3000_sw2lo), PFUZE3000_SW3_REG(PFUZE3000, SW3, PFUZE100_SW3AVOL, 900000, 1650000, 50000), @@ -642,14 +669,95 @@ static int pfuze100_regulator_probe(struct i2c_client *client, } } + + if (of_get_property(client->dev.of_node, "fsl,lpsr-mode", NULL)) + pfuze_chip->need_restore = true; + + return 0; +} + +static int pfuze_reg_save_restore(struct pfuze_chip *pfuze_chip, int start, + int end, int index, bool save) +{ + int i, ret; + + for (i = 0; i < end - start + 1; i++) { + if (save) + ret = regmap_read(pfuze_chip->regmap, start + i, + &pfuze_chip->reg_save_array[index + i]); + else + ret = regmap_write(pfuze_chip->regmap, start + i, + pfuze_chip->reg_save_array[index + i]); + + if (ret) + return ret; + } + + return index + i; +} + +static int pfuze_suspend(struct device *dev) +{ + struct pfuze_chip *pfuze_chip = i2c_get_clientdata(to_i2c_client(dev)); + int index = 0; + + if (pfuze_chip->need_restore) { + /* 0x20~0x40 */ + index = pfuze_reg_save_restore(pfuze_chip, 0x20, 0x40, index, true); + if (index < 0) + goto err_ret; + /* 0x66~0x71 */ + index = pfuze_reg_save_restore(pfuze_chip, 0x66, 0x71, ++index, true); + if (index < 0) + goto err_ret; + /* 0x7f */ + index = pfuze_reg_save_restore(pfuze_chip, 0x7f, 0x7f, ++index, true); + if (index < 0) + goto err_ret; + } + return 0; + +err_ret: + return index; } +static int pfuze_resume(struct device *dev) +{ + struct pfuze_chip *pfuze_chip = i2c_get_clientdata(to_i2c_client(dev)); + int index = 0; + + if (pfuze_chip->need_restore) { + /* 0x20~0x40 */ + index = pfuze_reg_save_restore(pfuze_chip, 0x20, 0x40, index, false); + if (index < 0) + goto err_ret; + /* 0x66~0x71 */ + index = pfuze_reg_save_restore(pfuze_chip, 0x66, 0x71, ++index, false); + if (index < 0) + goto err_ret; + /* 0x7f */ + index = pfuze_reg_save_restore(pfuze_chip, 0x7f, 0x7f, ++index, false); + if (index < 0) + goto err_ret; + } + + return 0; + +err_ret: + return index; +} + +static const struct dev_pm_ops pfuze_pm_ops = { + SET_SYSTEM_SLEEP_PM_OPS(pfuze_suspend, pfuze_resume) +}; + static struct i2c_driver pfuze_driver = { .id_table = pfuze_device_id, .driver = { .name = "pfuze100-regulator", .of_match_table = pfuze_dt_ids, + .pm = &pfuze_pm_ops, }, .probe = pfuze100_regulator_probe, }; |