regulator: onsemi-ncp6335d: add device tree support for mode selection
Add support to the onsemi-ncp6335d driver to select which regulator
operating mode to utilize. There are two possible mode selections: PWM mode
and auto mode. If no mode property is specified in device tree, the
regulator will operate in the hardware default mode.
CRs-Fixed: 607899
Change-Id: I2e21c452a3ea3963146d9abbc7e89e811fd90388
Signed-off-by: Ke Liu <keliu@codeaurora.org>
diff --git a/Documentation/devicetree/bindings/regulator/onsemi-ncp6335d.txt b/Documentation/devicetree/bindings/regulator/onsemi-ncp6335d.txt
index 076fa42..648cb11 100644
--- a/Documentation/devicetree/bindings/regulator/onsemi-ncp6335d.txt
+++ b/Documentation/devicetree/bindings/regulator/onsemi-ncp6335d.txt
@@ -46,7 +46,10 @@
The 2 elements with index[0..1] are:
[0] => the mask value;
[1] => the value to write into the masked bits.
-
+- onnn,mode: A string which specifies the initial mode to use for the regulator.
+ Supported values are "pwm" and "auto". PWM mode is more
+ robust, but draws more current than auto mode. If this propery
+ is not specified, then the regulator will be in the hardware default mode.
Example:
i2c_0 {
diff --git a/drivers/regulator/onsemi-ncp6335d.c b/drivers/regulator/onsemi-ncp6335d.c
index 52436db..3d4dd04 100644
--- a/drivers/regulator/onsemi-ncp6335d.c
+++ b/drivers/regulator/onsemi-ncp6335d.c
@@ -24,6 +24,7 @@
#include <linux/of_gpio.h>
#include <linux/regmap.h>
#include <linux/regulator/onsemi-ncp6335d.h>
+#include <linux/string.h>
#include <mach/gpiomux.h>
/* registers */
@@ -469,6 +470,7 @@
{
struct ncp6335d_platform_data *pdata = NULL;
struct regulator_init_data *init_data;
+ const char *mode_name;
int rc;
init_data = of_get_regulator_init_data(&client->dev,
@@ -517,7 +519,23 @@
init_data->constraints.valid_modes_mask =
REGULATOR_MODE_NORMAL |
REGULATOR_MODE_FAST;
- init_data->constraints.initial_mode = REGULATOR_MODE_NORMAL;
+
+ rc = of_property_read_string(client->dev.of_node, "onnn,mode",
+ &mode_name);
+ if (!rc) {
+ if (strcmp("pwm", mode_name) == 0) {
+ init_data->constraints.initial_mode =
+ REGULATOR_MODE_FAST;
+ } else if (strcmp("auto", mode_name) == 0) {
+ init_data->constraints.initial_mode =
+ REGULATOR_MODE_NORMAL;
+ } else {
+ dev_err(&client->dev, "onnn,mode, unknown regulator mode: %s\n",
+ mode_name);
+ return NULL;
+ }
+ }
+
return pdata;
}