Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 312540
b: refs/heads/master
c: c705742
h: refs/heads/master
v: v3
  • Loading branch information
Axel Lin authored and Mark Brown committed Jun 17, 2012
1 parent cc1e0e9 commit dd78221
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 78 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: a967fbfaca0a979fc34c1097b37d824039a709b1
refs/heads/master: c705742201260afd08b05ff84674507735e2b16b
127 changes: 50 additions & 77 deletions trunk/drivers/regulator/wm8350-regulator.c
Original file line number Diff line number Diff line change
Expand Up @@ -108,24 +108,6 @@ static int get_isink_val(int min_uA, int max_uA, u16 *setting)
return -EINVAL;
}

static inline unsigned int wm8350_ldo_mvolts_to_val(int mV)
{
if (mV < 1800)
return (mV - 900) / 50;
else
return ((mV - 1800) / 100) + 16;
}

static inline int wm8350_dcdc_val_to_mvolts(unsigned int val)
{
return (val * 25) + 850;
}

static inline unsigned int wm8350_dcdc_mvolts_to_val(int mV)
{
return (mV - 850) / 25;
}

static int wm8350_isink_set_current(struct regulator_dev *rdev, int min_uA,
int max_uA)
{
Expand Down Expand Up @@ -353,19 +335,10 @@ EXPORT_SYMBOL_GPL(wm8350_isink_set_flash);
static int wm8350_dcdc_set_suspend_voltage(struct regulator_dev *rdev, int uV)
{
struct wm8350 *wm8350 = rdev_get_drvdata(rdev);
int volt_reg, mV = uV / 1000, dcdc = rdev_get_id(rdev);
int sel, volt_reg, dcdc = rdev_get_id(rdev);
u16 val;

dev_dbg(wm8350->dev, "%s %d mV %d\n", __func__, dcdc, mV);

if (mV && (mV < 850 || mV > 4025)) {
dev_err(wm8350->dev,
"DCDC%d suspend voltage %d mV out of range\n",
dcdc, mV);
return -EINVAL;
}
if (mV == 0)
mV = 850;
dev_dbg(wm8350->dev, "%s %d mV %d\n", __func__, dcdc, uV / 1000);

switch (dcdc) {
case WM8350_DCDC_1:
Expand All @@ -386,10 +359,13 @@ static int wm8350_dcdc_set_suspend_voltage(struct regulator_dev *rdev, int uV)
return -EINVAL;
}

sel = regulator_map_voltage_linear(rdev, uV, uV);
if (sel < 0)
return -EINVAL;

/* all DCDCs have same mV bits */
val = wm8350_reg_read(wm8350, volt_reg) & ~WM8350_DC1_VSEL_MASK;
wm8350_reg_write(wm8350, volt_reg,
val | wm8350_dcdc_mvolts_to_val(mV));
wm8350_reg_write(wm8350, volt_reg, val | sel);
return 0;
}

Expand Down Expand Up @@ -566,19 +542,49 @@ static int wm8350_dcdc_set_suspend_mode(struct regulator_dev *rdev,
return 0;
}

static int wm8350_ldo_list_voltage(struct regulator_dev *rdev,
unsigned selector)
{
if (selector > WM8350_LDO1_VSEL_MASK)
return -EINVAL;

if (selector < 16)
return (selector * 50000) + 900000;
else
return ((selector - 16) * 100000) + 1800000;
}

static int wm8350_ldo_map_voltage(struct regulator_dev *rdev, int min_uV,
int max_uV)
{
int volt, sel;
int min_mV = min_uV / 1000;
int max_mV = max_uV / 1000;

if (min_mV < 900 || min_mV > 3300)
return -EINVAL;
if (max_mV < 900 || max_mV > 3300)
return -EINVAL;

if (min_mV < 1800) /* step size is 50mV < 1800mV */
sel = DIV_ROUND_UP(min_uV - 900, 50);
else /* step size is 100mV > 1800mV */
sel = DIV_ROUND_UP(min_uV - 1800, 100) + 16;

volt = wm8350_ldo_list_voltage(rdev, sel);
if (volt < min_uV || volt > max_uV)
return -EINVAL;

return sel;
}

static int wm8350_ldo_set_suspend_voltage(struct regulator_dev *rdev, int uV)
{
struct wm8350 *wm8350 = rdev_get_drvdata(rdev);
int volt_reg, mV = uV / 1000, ldo = rdev_get_id(rdev);
int sel, volt_reg, ldo = rdev_get_id(rdev);
u16 val;

dev_dbg(wm8350->dev, "%s %d mV %d\n", __func__, ldo, mV);

if (mV < 900 || mV > 3300) {
dev_err(wm8350->dev, "LDO%d voltage %d mV out of range\n",
ldo, mV);
return -EINVAL;
}
dev_dbg(wm8350->dev, "%s %d mV %d\n", __func__, ldo, uV / 1000);

switch (ldo) {
case WM8350_LDO_1:
Expand All @@ -597,10 +603,13 @@ static int wm8350_ldo_set_suspend_voltage(struct regulator_dev *rdev, int uV)
return -EINVAL;
}

sel = wm8350_ldo_map_voltage(rdev, uV, uV);
if (sel < 0)
return -EINVAL;

/* all LDOs have same mV bits */
val = wm8350_reg_read(wm8350, volt_reg) & ~WM8350_LDO1_VSEL_MASK;
wm8350_reg_write(wm8350, volt_reg,
val | wm8350_ldo_mvolts_to_val(mV));
wm8350_reg_write(wm8350, volt_reg, val | sel);
return 0;
}

Expand Down Expand Up @@ -662,42 +671,6 @@ static int wm8350_ldo_set_suspend_disable(struct regulator_dev *rdev)
return 0;
}

static int wm8350_ldo_list_voltage(struct regulator_dev *rdev,
unsigned selector)
{
if (selector > WM8350_LDO1_VSEL_MASK)
return -EINVAL;

if (selector < 16)
return (selector * 50000) + 900000;
else
return ((selector - 16) * 100000) + 1800000;
}

static int wm8350_ldo_map_voltage(struct regulator_dev *rdev, int min_uV,
int max_uV)
{
int volt, sel;
int min_mV = min_uV / 1000;
int max_mV = max_uV / 1000;

if (min_mV < 900 || min_mV > 3300)
return -EINVAL;
if (max_mV < 900 || max_mV > 3300)
return -EINVAL;

if (min_mV < 1800) /* step size is 50mV < 1800mV */
sel = DIV_ROUND_UP(min_uV - 900, 50);
else /* step size is 100mV > 1800mV */
sel = DIV_ROUND_UP(min_uV - 1800, 100) + 16;

volt = wm8350_ldo_list_voltage(rdev, sel);
if (volt < min_uV || volt > max_uV)
return -EINVAL;

return sel;
}

int wm8350_dcdc_set_slot(struct wm8350 *wm8350, int dcdc, u16 start,
u16 stop, u16 fault)
{
Expand Down

0 comments on commit dd78221

Please sign in to comment.