Skip to content

Commit

Permalink
regulators/db8500: split off shared dbx500 code
Browse files Browse the repository at this point in the history
As we progress with DB5500 and future voltage domain regulators
based on very similar hardware as found in the DB8500 PRCMU,
it makes sense to split off the generic parts and introduce
some generic debug code for the DBx500 regulators. This patch
accoplish a basic abstraction of the DBx500 voltage domain
regulators.

Signed-off-by: Bengt Jonsson <bengt.g.jonsson@stericsson.com>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
  • Loading branch information
Bengt Jonsson authored and Mark Brown committed Jan 20, 2012
1 parent c835e1c commit 38e9683
Show file tree
Hide file tree
Showing 5 changed files with 341 additions and 86 deletions.
4 changes: 4 additions & 0 deletions drivers/regulator/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -299,9 +299,13 @@ config REGULATOR_AB8500
This driver supports the regulators found on the ST-Ericsson mixed
signal AB8500 PMIC

config REGULATOR_DBX500_PRCMU
bool

config REGULATOR_DB8500_PRCMU
bool "ST-Ericsson DB8500 Voltage Domain Regulators"
depends on MFD_DB8500_PRCMU
select REGULATOR_DBX500_PRCMU
help
This driver supports the voltage domain regulators controlled by the
DB8500 PRCMU
Expand Down
1 change: 1 addition & 0 deletions drivers/regulator/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ obj-$(CONFIG_REGULATOR_TPS65912) += tps65912-regulator.o
obj-$(CONFIG_REGULATOR_88PM8607) += 88pm8607.o
obj-$(CONFIG_REGULATOR_ISL6271A) += isl6271a-regulator.o
obj-$(CONFIG_REGULATOR_AB8500) += ab8500.o
obj-$(CONFIG_REGULATOR_DBX500_PRCMU) += dbx500-prcmu.o
obj-$(CONFIG_REGULATOR_DB8500_PRCMU) += db8500-prcmu.o
obj-$(CONFIG_REGULATOR_TPS65910) += tps65910-regulator.o
obj-$(CONFIG_REGULATOR_TPS62360) += tps62360-regulator.o
Expand Down
118 changes: 32 additions & 86 deletions drivers/regulator/db8500-prcmu.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,91 +18,30 @@
#include <linux/regulator/machine.h>
#include <linux/regulator/db8500-prcmu.h>
#include <linux/module.h>

/*
* power state reference count
*/
static int power_state_active_cnt; /* will initialize to zero */
static DEFINE_SPINLOCK(power_state_active_lock);

static void power_state_active_enable(void)
{
unsigned long flags;

spin_lock_irqsave(&power_state_active_lock, flags);
power_state_active_cnt++;
spin_unlock_irqrestore(&power_state_active_lock, flags);
}

static int power_state_active_disable(void)
{
int ret = 0;
unsigned long flags;

spin_lock_irqsave(&power_state_active_lock, flags);
if (power_state_active_cnt <= 0) {
pr_err("power state: unbalanced enable/disable calls\n");
ret = -EINVAL;
goto out;
}

power_state_active_cnt--;
out:
spin_unlock_irqrestore(&power_state_active_lock, flags);
return ret;
}

/*
* Exported interface for CPUIdle only. This function is called when interrupts
* are turned off. Hence, no locking.
*/
int power_state_active_is_enabled(void)
{
return (power_state_active_cnt > 0);
}

/**
* struct db8500_regulator_info - db8500 regulator information
* @dev: device pointer
* @desc: regulator description
* @rdev: regulator device pointer
* @is_enabled: status of the regulator
* @epod_id: id for EPOD (power domain)
* @is_ramret: RAM retention switch for EPOD (power domain)
* @operating_point: operating point (only for vape, to be removed)
*
*/
struct db8500_regulator_info {
struct device *dev;
struct regulator_desc desc;
struct regulator_dev *rdev;
bool is_enabled;
u16 epod_id;
bool is_ramret;
bool exclude_from_power_state;
unsigned int operating_point;
};
#include "dbx500-prcmu.h"

static int db8500_regulator_enable(struct regulator_dev *rdev)
{
struct db8500_regulator_info *info = rdev_get_drvdata(rdev);
struct dbx500_regulator_info *info = rdev_get_drvdata(rdev);

if (info == NULL)
return -EINVAL;

dev_vdbg(rdev_get_dev(rdev), "regulator-%s-enable\n",
info->desc.name);

info->is_enabled = true;
if (!info->exclude_from_power_state)
power_state_active_enable();
if (!info->is_enabled) {
info->is_enabled = true;
if (!info->exclude_from_power_state)
power_state_active_enable();
}

return 0;
}

static int db8500_regulator_disable(struct regulator_dev *rdev)
{
struct db8500_regulator_info *info = rdev_get_drvdata(rdev);
struct dbx500_regulator_info *info = rdev_get_drvdata(rdev);
int ret = 0;

if (info == NULL)
Expand All @@ -111,16 +50,18 @@ static int db8500_regulator_disable(struct regulator_dev *rdev)
dev_vdbg(rdev_get_dev(rdev), "regulator-%s-disable\n",
info->desc.name);

info->is_enabled = false;
if (!info->exclude_from_power_state)
ret = power_state_active_disable();
if (info->is_enabled) {
info->is_enabled = false;
if (!info->exclude_from_power_state)
ret = power_state_active_disable();
}

return ret;
}

static int db8500_regulator_is_enabled(struct regulator_dev *rdev)
{
struct db8500_regulator_info *info = rdev_get_drvdata(rdev);
struct dbx500_regulator_info *info = rdev_get_drvdata(rdev);

if (info == NULL)
return -EINVAL;
Expand Down Expand Up @@ -197,7 +138,7 @@ static int disable_epod(u16 epod_id, bool ramret)
*/
static int db8500_regulator_switch_enable(struct regulator_dev *rdev)
{
struct db8500_regulator_info *info = rdev_get_drvdata(rdev);
struct dbx500_regulator_info *info = rdev_get_drvdata(rdev);
int ret;

if (info == NULL)
Expand All @@ -221,7 +162,7 @@ static int db8500_regulator_switch_enable(struct regulator_dev *rdev)

static int db8500_regulator_switch_disable(struct regulator_dev *rdev)
{
struct db8500_regulator_info *info = rdev_get_drvdata(rdev);
struct dbx500_regulator_info *info = rdev_get_drvdata(rdev);
int ret;

if (info == NULL)
Expand All @@ -245,7 +186,7 @@ static int db8500_regulator_switch_disable(struct regulator_dev *rdev)

static int db8500_regulator_switch_is_enabled(struct regulator_dev *rdev)
{
struct db8500_regulator_info *info = rdev_get_drvdata(rdev);
struct dbx500_regulator_info *info = rdev_get_drvdata(rdev);

if (info == NULL)
return -EINVAL;
Expand All @@ -266,8 +207,8 @@ static struct regulator_ops db8500_regulator_switch_ops = {
/*
* Regulator information
*/
static struct db8500_regulator_info
db8500_regulator_info[DB8500_NUM_REGULATORS] = {
static struct dbx500_regulator_info
dbx500_regulator_info[DB8500_NUM_REGULATORS] = {
[DB8500_REGULATOR_VAPE] = {
.desc = {
.name = "db8500-vape",
Expand Down Expand Up @@ -476,12 +417,12 @@ static int __devinit db8500_regulator_probe(struct platform_device *pdev)
int i, err;

/* register all regulators */
for (i = 0; i < ARRAY_SIZE(db8500_regulator_info); i++) {
struct db8500_regulator_info *info;
for (i = 0; i < ARRAY_SIZE(dbx500_regulator_info); i++) {
struct dbx500_regulator_info *info;
struct regulator_init_data *init_data = &db8500_init_data[i];

/* assign per-regulator data */
info = &db8500_regulator_info[i];
info = &dbx500_regulator_info[i];
info->dev = &pdev->dev;

/* register with the regulator framework */
Expand All @@ -494,7 +435,7 @@ static int __devinit db8500_regulator_probe(struct platform_device *pdev)

/* if failing, unregister all earlier regulators */
while (--i >= 0) {
info = &db8500_regulator_info[i];
info = &dbx500_regulator_info[i];
regulator_unregister(info->rdev);
}
return err;
Expand All @@ -503,17 +444,22 @@ static int __devinit db8500_regulator_probe(struct platform_device *pdev)
dev_dbg(rdev_get_dev(info->rdev),
"regulator-%s-probed\n", info->desc.name);
}
err = ux500_regulator_debug_init(pdev,
dbx500_regulator_info,
ARRAY_SIZE(dbx500_regulator_info));

return 0;
return err;
}

static int __exit db8500_regulator_remove(struct platform_device *pdev)
{
int i;

for (i = 0; i < ARRAY_SIZE(db8500_regulator_info); i++) {
struct db8500_regulator_info *info;
info = &db8500_regulator_info[i];
ux500_regulator_debug_exit();

for (i = 0; i < ARRAY_SIZE(dbx500_regulator_info); i++) {
struct dbx500_regulator_info *info;
info = &dbx500_regulator_info[i];

dev_vdbg(rdev_get_dev(info->rdev),
"regulator-%s-remove\n", info->desc.name);
Expand Down
Loading

0 comments on commit 38e9683

Please sign in to comment.