regulator: ti-abb: Add support for interleaved LDO registers

Certain platforms such as DRA7 have quirky memory maps such as:
PRM_ABBLDO_DSPEVE_CTRL	0x4ae07e20
PRM_ABBLDO_IVA_CTRL	0x4ae07e24
other-registers
PRM_ABBLDO_DSPEVE_SETUP	0x4ae07e30
PRM_ABBLDO_IVA_SETUP	0x4ae07e34

These need the address range allocation to be either not reserved OR
unique allocation per register instance or use something like syscon
based solution.

By going with unique allocation per register, we are able to now have
a single compatible driver for all instances on all platforms which
use the IP block.

So, introduce a new "ti,abb-v3" compatible to allow for definitions
where explicit register definitions are provided, while maintaining
backward compatibility of older predefined register offsets provided
by "ti-abb-v1" and "ti-abb-v2".

As part of this change, we rename a few variables to indicate the
appropriate meaning.

Signed-off-by: Nishanth Menon <nm@ti.com>
Signed-off-by: Mark Brown <broonie@linaro.org>
This commit is contained in:
Nishanth Menon 2014-01-23 11:57:27 -06:00 committed by Mark Brown
parent 38dbfb59d1
commit 6127daa850
2 changed files with 62 additions and 30 deletions

View File

@ -4,10 +4,14 @@ Required Properties:
- compatible: Should be one of: - compatible: Should be one of:
- "ti,abb-v1" for older SoCs like OMAP3 - "ti,abb-v1" for older SoCs like OMAP3
- "ti,abb-v2" for newer SoCs like OMAP4, OMAP5 - "ti,abb-v2" for newer SoCs like OMAP4, OMAP5
- "ti,abb-v3" for a generic definition where setup and control registers are
provided (example: DRA7)
- reg: Address and length of the register set for the device. It contains - reg: Address and length of the register set for the device. It contains
the information of registers in the same order as described by reg-names the information of registers in the same order as described by reg-names
- reg-names: Should contain the reg names - reg-names: Should contain the reg names
- "base-address" - contains base address of ABB module - "base-address" - contains base address of ABB module (ti,abb-v1,ti,abb-v2)
- "control-address" - contains control register address of ABB module (ti,abb-v3)
- "setup-address" - contains setup register address of ABB module (ti,abb-v3)
- "int-address" - contains address of interrupt register for ABB module - "int-address" - contains address of interrupt register for ABB module
(also see Optional properties) (also see Optional properties)
- #address-cell: should be 0 - #address-cell: should be 0

View File

@ -54,8 +54,8 @@ struct ti_abb_info {
/** /**
* struct ti_abb_reg - Register description for ABB block * struct ti_abb_reg - Register description for ABB block
* @setup_reg: setup register offset from base * @setup_off: setup register offset from base
* @control_reg: control register offset from base * @control_off: control register offset from base
* @sr2_wtcnt_value_mask: setup register- sr2_wtcnt_value mask * @sr2_wtcnt_value_mask: setup register- sr2_wtcnt_value mask
* @fbb_sel_mask: setup register- FBB sel mask * @fbb_sel_mask: setup register- FBB sel mask
* @rbb_sel_mask: setup register- RBB sel mask * @rbb_sel_mask: setup register- RBB sel mask
@ -64,8 +64,8 @@ struct ti_abb_info {
* @opp_sel_mask: control register - mask for mode to operate * @opp_sel_mask: control register - mask for mode to operate
*/ */
struct ti_abb_reg { struct ti_abb_reg {
u32 setup_reg; u32 setup_off;
u32 control_reg; u32 control_off;
/* Setup register fields */ /* Setup register fields */
u32 sr2_wtcnt_value_mask; u32 sr2_wtcnt_value_mask;
@ -83,6 +83,8 @@ struct ti_abb_reg {
* @rdesc: regulator descriptor * @rdesc: regulator descriptor
* @clk: clock(usually sysclk) supplying ABB block * @clk: clock(usually sysclk) supplying ABB block
* @base: base address of ABB block * @base: base address of ABB block
* @setup_reg: setup register of ABB block
* @control_reg: control register of ABB block
* @int_base: interrupt register base address * @int_base: interrupt register base address
* @efuse_base: (optional) efuse base address for ABB modes * @efuse_base: (optional) efuse base address for ABB modes
* @ldo_base: (optional) LDOVBB vset override base address * @ldo_base: (optional) LDOVBB vset override base address
@ -99,6 +101,8 @@ struct ti_abb {
struct regulator_desc rdesc; struct regulator_desc rdesc;
struct clk *clk; struct clk *clk;
void __iomem *base; void __iomem *base;
void __iomem *setup_reg;
void __iomem *control_reg;
void __iomem *int_base; void __iomem *int_base;
void __iomem *efuse_base; void __iomem *efuse_base;
void __iomem *ldo_base; void __iomem *ldo_base;
@ -118,20 +122,18 @@ struct ti_abb {
* ti_abb_rmw() - handy wrapper to set specific register bits * ti_abb_rmw() - handy wrapper to set specific register bits
* @mask: mask for register field * @mask: mask for register field
* @value: value shifted to mask location and written * @value: value shifted to mask location and written
* @offset: offset of register * @reg: register address
* @base: base address
* *
* Return: final register value (may be unused) * Return: final register value (may be unused)
*/ */
static inline u32 ti_abb_rmw(u32 mask, u32 value, u32 offset, static inline u32 ti_abb_rmw(u32 mask, u32 value, void __iomem *reg)
void __iomem *base)
{ {
u32 val; u32 val;
val = readl(base + offset); val = readl(reg);
val &= ~mask; val &= ~mask;
val |= (value << __ffs(mask)) & mask; val |= (value << __ffs(mask)) & mask;
writel(val, base + offset); writel(val, reg);
return val; return val;
} }
@ -263,21 +265,19 @@ static int ti_abb_set_opp(struct regulator_dev *rdev, struct ti_abb *abb,
if (ret) if (ret)
goto out; goto out;
ti_abb_rmw(regs->fbb_sel_mask | regs->rbb_sel_mask, 0, regs->setup_reg, ti_abb_rmw(regs->fbb_sel_mask | regs->rbb_sel_mask, 0, abb->setup_reg);
abb->base);
switch (info->opp_sel) { switch (info->opp_sel) {
case TI_ABB_SLOW_OPP: case TI_ABB_SLOW_OPP:
ti_abb_rmw(regs->rbb_sel_mask, 1, regs->setup_reg, abb->base); ti_abb_rmw(regs->rbb_sel_mask, 1, abb->setup_reg);
break; break;
case TI_ABB_FAST_OPP: case TI_ABB_FAST_OPP:
ti_abb_rmw(regs->fbb_sel_mask, 1, regs->setup_reg, abb->base); ti_abb_rmw(regs->fbb_sel_mask, 1, abb->setup_reg);
break; break;
} }
/* program next state of ABB ldo */ /* program next state of ABB ldo */
ti_abb_rmw(regs->opp_sel_mask, info->opp_sel, regs->control_reg, ti_abb_rmw(regs->opp_sel_mask, info->opp_sel, abb->control_reg);
abb->base);
/* /*
* program LDO VBB vset override if needed for !bypass mode * program LDO VBB vset override if needed for !bypass mode
@ -288,7 +288,7 @@ static int ti_abb_set_opp(struct regulator_dev *rdev, struct ti_abb *abb,
ti_abb_program_ldovbb(dev, abb, info); ti_abb_program_ldovbb(dev, abb, info);
/* Initiate ABB ldo change */ /* Initiate ABB ldo change */
ti_abb_rmw(regs->opp_change_mask, 1, regs->control_reg, abb->base); ti_abb_rmw(regs->opp_change_mask, 1, abb->control_reg);
/* Wait for ABB LDO to complete transition to new Bias setting */ /* Wait for ABB LDO to complete transition to new Bias setting */
ret = ti_abb_wait_txdone(dev, abb); ret = ti_abb_wait_txdone(dev, abb);
@ -490,8 +490,7 @@ static int ti_abb_init_timings(struct device *dev, struct ti_abb *abb)
dev_dbg(dev, "%s: Clk_rate=%ld, sr2_cnt=0x%08x\n", __func__, dev_dbg(dev, "%s: Clk_rate=%ld, sr2_cnt=0x%08x\n", __func__,
clk_get_rate(abb->clk), sr2_wt_cnt_val); clk_get_rate(abb->clk), sr2_wt_cnt_val);
ti_abb_rmw(regs->sr2_wtcnt_value_mask, sr2_wt_cnt_val, regs->setup_reg, ti_abb_rmw(regs->sr2_wtcnt_value_mask, sr2_wt_cnt_val, abb->setup_reg);
abb->base);
return 0; return 0;
} }
@ -648,8 +647,8 @@ static struct regulator_ops ti_abb_reg_ops = {
/* Default ABB block offsets, IF this changes in future, create new one */ /* Default ABB block offsets, IF this changes in future, create new one */
static const struct ti_abb_reg abb_regs_v1 = { static const struct ti_abb_reg abb_regs_v1 = {
/* WARNING: registers are wrongly documented in TRM */ /* WARNING: registers are wrongly documented in TRM */
.setup_reg = 0x04, .setup_off = 0x04,
.control_reg = 0x00, .control_off = 0x00,
.sr2_wtcnt_value_mask = (0xff << 8), .sr2_wtcnt_value_mask = (0xff << 8),
.fbb_sel_mask = (0x01 << 2), .fbb_sel_mask = (0x01 << 2),
@ -661,8 +660,8 @@ static const struct ti_abb_reg abb_regs_v1 = {
}; };
static const struct ti_abb_reg abb_regs_v2 = { static const struct ti_abb_reg abb_regs_v2 = {
.setup_reg = 0x00, .setup_off = 0x00,
.control_reg = 0x04, .control_off = 0x04,
.sr2_wtcnt_value_mask = (0xff << 8), .sr2_wtcnt_value_mask = (0xff << 8),
.fbb_sel_mask = (0x01 << 2), .fbb_sel_mask = (0x01 << 2),
@ -673,9 +672,20 @@ static const struct ti_abb_reg abb_regs_v2 = {
.opp_sel_mask = (0x03 << 0), .opp_sel_mask = (0x03 << 0),
}; };
static const struct ti_abb_reg abb_regs_generic = {
.sr2_wtcnt_value_mask = (0xff << 8),
.fbb_sel_mask = (0x01 << 2),
.rbb_sel_mask = (0x01 << 1),
.sr2_en_mask = (0x01 << 0),
.opp_change_mask = (0x01 << 2),
.opp_sel_mask = (0x03 << 0),
};
static const struct of_device_id ti_abb_of_match[] = { static const struct of_device_id ti_abb_of_match[] = {
{.compatible = "ti,abb-v1", .data = &abb_regs_v1}, {.compatible = "ti,abb-v1", .data = &abb_regs_v1},
{.compatible = "ti,abb-v2", .data = &abb_regs_v2}, {.compatible = "ti,abb-v2", .data = &abb_regs_v2},
{.compatible = "ti,abb-v3", .data = &abb_regs_generic},
{ }, { },
}; };
@ -722,11 +732,29 @@ static int ti_abb_probe(struct platform_device *pdev)
abb->regs = match->data; abb->regs = match->data;
/* Map ABB resources */ /* Map ABB resources */
pname = "base-address"; if (abb->regs->setup_off || abb->regs->control_off) {
res = platform_get_resource_byname(pdev, IORESOURCE_MEM, pname); pname = "base-address";
abb->base = devm_ioremap_resource(dev, res); res = platform_get_resource_byname(pdev, IORESOURCE_MEM, pname);
if (IS_ERR(abb->base)) abb->base = devm_ioremap_resource(dev, res);
return PTR_ERR(abb->base); if (IS_ERR(abb->base))
return PTR_ERR(abb->base);
abb->setup_reg = abb->base + abb->regs->setup_off;
abb->control_reg = abb->base + abb->regs->control_off;
} else {
pname = "control-address";
res = platform_get_resource_byname(pdev, IORESOURCE_MEM, pname);
abb->control_reg = devm_ioremap_resource(dev, res);
if (IS_ERR(abb->control_reg))
return PTR_ERR(abb->control_reg);
pname = "setup-address";
res = platform_get_resource_byname(pdev, IORESOURCE_MEM, pname);
abb->setup_reg = devm_ioremap_resource(dev, res);
if (IS_ERR(abb->setup_reg))
return PTR_ERR(abb->setup_reg);
}
pname = "int-address"; pname = "int-address";
res = platform_get_resource_byname(pdev, IORESOURCE_MEM, pname); res = platform_get_resource_byname(pdev, IORESOURCE_MEM, pname);
@ -860,7 +888,7 @@ skip_opt:
platform_set_drvdata(pdev, rdev); platform_set_drvdata(pdev, rdev);
/* Enable the ldo if not already done by bootloader */ /* Enable the ldo if not already done by bootloader */
ti_abb_rmw(abb->regs->sr2_en_mask, 1, abb->regs->setup_reg, abb->base); ti_abb_rmw(abb->regs->sr2_en_mask, 1, abb->setup_reg);
return 0; return 0;
} }