lkml.org 
[lkml]   [2012]   [Jun]   [18]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
Date
From
Subject[PATCH 1/2 v2] regulator: support multiple dummy fixed regulators
Currently regulator_register_fixed() uses a constant name to register a
fixed dummy regulator. This is sufficient in principle, since there is no
reason to register multiple such regulators. The user can simply supply all
consumers in one array and use it to initialise such a regulator. However,
in some cases it can be convenient to register multiple such regulators.
This is also easy to achieve by appending the device ID to the name. It is
also consistent with the current behaviour of the code, that fixes a name
itself without giving the user a possibility to provide a custom one.

Signed-off-by: Guennadi Liakhovetski <g.liakhovetski@gmx.de>
---
drivers/regulator/fixed-helper.c | 12 +++++++++++-
1 files changed, 11 insertions(+), 1 deletions(-)

diff --git a/drivers/regulator/fixed-helper.c b/drivers/regulator/fixed-helper.c
index cacd33c..f66d9e8 100644
--- a/drivers/regulator/fixed-helper.c
+++ b/drivers/regulator/fixed-helper.c
@@ -1,12 +1,17 @@
#include <linux/slab.h>
+#include <linux/string.h>
#include <linux/platform_device.h>
#include <linux/regulator/machine.h>
#include <linux/regulator/fixed.h>

+#define FIXED_BASE "fixed-dummy"
+#define FIXED_NAME FIXED_BASE "-00"
+
struct fixed_regulator_data {
struct fixed_voltage_config cfg;
struct regulator_init_data init_data;
struct platform_device pdev;
+ char name[sizeof(FIXED_NAME)];
};

static void regulator_fixed_release(struct device *dev)
@@ -31,7 +36,12 @@ struct platform_device *regulator_register_fixed(int id,
if (!data)
return NULL;

- data->cfg.supply_name = "fixed-dummy";
+ if (id < 0)
+ strcpy(data->name, FIXED_BASE);
+ else
+ snprintf(data->name, sizeof(FIXED_NAME), FIXED_BASE "-%d", id);
+
+ data->cfg.supply_name = data->name;
data->cfg.microvolts = 0;
data->cfg.gpio = -EINVAL;
data->cfg.enabled_at_boot = 1;
--
1.7.2.5


\
 
 \ /
  Last update: 2012-06-18 18:41    [W:0.207 / U:0.104 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site