summaryrefslogtreecommitdiff
path: root/drivers
diff options
context:
space:
mode:
authorMark Brown <broonie@opensource.wolfsonmicro.com>2010-11-29 15:55:17 +0000
committerNiket Sirsi <nsirsi@nvidia.com>2011-05-23 16:55:41 -0700
commit54b9754390a04be871ab1defee7381e1fb580bbd (patch)
tree5f337ecc41a55bc800607f5ec519ff4d1b689581 /drivers
parent1bbeff1c53f90475f79c7078ce65e2d4e1fac2ee (diff)
regulator: Copy constraints from regulators when initialising them
Currently the regulator API uses the constraints structure passed in to the core throughout the lifetime of the object. This means that it is not possible to mark the constraints as __initdata so if the kernel supports many boards the constraints for all of them are kept around throughout the lifetime of the system, consuming memory needlessly. By copying constraints that are actually used we allow the use of __initdata, saving memory when multiple boards are supported. This also means the constraints can be const. Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com> Signed-off-by: Liam Girdwood <lrg@slimlogic.co.uk> (cherry picked from commit f8c12fe329c8da9f50d8b2b1183eeaa4d587e747) Reviewed-on: http://git.kernel.org/?p=linux/kernel/git/torvalds/ linux-2.6.git;a=commit;h=f8c12fe329c8da9f50d8b2b1183eeaa4d587e747 Change-Id: Ifaa6a8d1b083960a817c23c970e4fccbad67af05 Reviewed-on: http://git-master/r/30954 Tested-by: Varun Wadekar <vwadekar@nvidia.com> Reviewed-by: Scott Williams <scwilliams@nvidia.com> Reviewed-by: Daniel Willemsen <dwillemsen@nvidia.com>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/regulator/core.c19
1 files changed, 12 insertions, 7 deletions
diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
index 4a93e8cc0bf1..3a94ef493132 100644
--- a/drivers/regulator/core.c
+++ b/drivers/regulator/core.c
@@ -823,23 +823,26 @@ static int machine_constraints_voltage(struct regulator_dev *rdev,
* set_mode.
*/
static int set_machine_constraints(struct regulator_dev *rdev,
- struct regulation_constraints *constraints)
+ const struct regulation_constraints *constraints)
{
int ret = 0;
const char *name;
struct regulator_ops *ops = rdev->desc->ops;
- rdev->constraints = constraints;
+ rdev->constraints = kmemdup(constraints, sizeof(*constraints),
+ GFP_KERNEL);
+ if (!rdev->constraints)
+ return -ENOMEM;
name = rdev_get_name(rdev);
- ret = machine_constraints_voltage(rdev, constraints);
+ ret = machine_constraints_voltage(rdev, rdev->constraints);
if (ret != 0)
goto out;
/* do we need to setup our suspend state */
if (constraints->initial_state) {
- ret = suspend_prepare(rdev, constraints->initial_state);
+ ret = suspend_prepare(rdev, rdev->constraints->initial_state);
if (ret < 0) {
printk(KERN_ERR "%s: failed to set suspend state for %s\n",
__func__, name);
@@ -856,7 +859,7 @@ static int set_machine_constraints(struct regulator_dev *rdev,
goto out;
}
- ret = ops->set_mode(rdev, constraints->initial_mode);
+ ret = ops->set_mode(rdev, rdev->constraints->initial_mode);
if (ret < 0) {
printk(KERN_ERR
"%s: failed to set initial mode for %s: %d\n",
@@ -868,7 +871,8 @@ static int set_machine_constraints(struct regulator_dev *rdev,
/* If the constraints say the regulator should be on at this point
* and we have control then make sure it is enabled.
*/
- if ((constraints->always_on || constraints->boot_on) && ops->enable) {
+ if ((rdev->constraints->always_on || rdev->constraints->boot_on) &&
+ ops->enable) {
ret = ops->enable(rdev);
if (ret < 0) {
printk(KERN_ERR "%s: failed to enable %s\n",
@@ -2277,7 +2281,7 @@ static int add_regulator_attributes(struct regulator_dev *rdev)
* Returns 0 on success.
*/
struct regulator_dev *regulator_register(struct regulator_desc *regulator_desc,
- struct device *dev, struct regulator_init_data *init_data,
+ struct device *dev, const struct regulator_init_data *init_data,
void *driver_data)
{
static atomic_t regulator_no = ATOMIC_INIT(0);
@@ -2430,6 +2434,7 @@ void regulator_unregister(struct regulator_dev *rdev)
if (rdev->supply)
sysfs_remove_link(&rdev->dev.kobj, "supply");
device_unregister(&rdev->dev);
+ kfree(rdev->constraints);
mutex_unlock(&regulator_list_mutex);
}
EXPORT_SYMBOL_GPL(regulator_unregister);