From: grant.likely@secretlab.ca (Grant Likely)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH v2 3/5] regulator: helper routine to extract regulator_init_data
Date: Thu, 13 Oct 2011 12:40:07 -0600 [thread overview]
Message-ID: <20111013184007.GO18574@ponder.secretlab.ca> (raw)
In-Reply-To: <1318263578-7407-4-git-send-email-rnayak@ti.com>
On Mon, Oct 10, 2011 at 09:49:36PM +0530, Rajendra Nayak wrote:
> The helper routine is meant to be used by regulator drivers
> to extract the regulator_init_data structure from the data
> that is passed from device tree.
> 'consumer_supplies' which is part of regulator_init_data is not extracted
> as the regulator consumer mappings are passed through DT differently,
> implemented in subsequent patches.
> Similarly the regulator<-->parent/supply mapping is handled in
> subsequent patches.
>
> Also add documentation for regulator bindings to be used to pass
> regulator_init_data struct information from device tree.
>
> Signed-off-by: Rajendra Nayak <rnayak@ti.com>
> ---
> .../devicetree/bindings/regulator/regulator.txt | 44 +++++++++
> drivers/regulator/Kconfig | 8 ++
> drivers/regulator/Makefile | 1 +
> drivers/regulator/of_regulator.c | 93 ++++++++++++++++++++
> include/linux/regulator/of_regulator.h | 21 +++++
> 5 files changed, 167 insertions(+), 0 deletions(-)
> create mode 100644 Documentation/devicetree/bindings/regulator/regulator.txt
> create mode 100644 drivers/regulator/of_regulator.c
> create mode 100644 include/linux/regulator/of_regulator.h
>
> diff --git a/Documentation/devicetree/bindings/regulator/regulator.txt b/Documentation/devicetree/bindings/regulator/regulator.txt
> new file mode 100644
> index 0000000..a623fdd
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/regulator/regulator.txt
> @@ -0,0 +1,44 @@
> +Voltage/Current Regulators
> +
> +Optional properties:
> +- regulator-min-uV: smallest voltage consumers may set
> +- regulator-max-uV: largest voltage consumers may set
> +- regulator-uV-offset: Offset applied to voltages to compensate for voltage drops
> +- regulator-min-uA: smallest current consumers may set
> +- regulator-max-uA: largest current consumers may set
> +- regulator-change-voltage: boolean, Output voltage can be changed by software
> +- regulator-change-current: boolean, Output current can be chnaged by software
> +- regulator-change-mode: boolean, Operating mode can be changed by software
> +- regulator-change-status: boolean, Enable/Disable control for regulator exists
> +- regulator-change-drms: boolean, Dynamic regulator mode switching is enabled
> +- regulator-mode-fast: boolean, allow/set fast mode for the regulator
> +- regulator-mode-normal: boolean, allow/set normal mode for the regulator
> +- regulator-mode-idle: boolean, allow/set idle mode for the regulator
> +- regulator-mode-standby: boolean, allow/set standby mode for the regulator
> +- regulator-input-uV: Input voltage for regulator when supplied by another regulator
> +- regulator-always-on: boolean, regulator should never be disabled
> +- regulator-boot-on: bootloader/firmware enabled regulator
> +- <name>-supply: phandle to the parent supply/regulator node
> +
> +Example:
> +
> + xyzreg: regulator at 0 {
> + regulator-min-uV = <1000000>;
> + regulator-max-uV = <2500000>;
> + regulator-mode-fast;
> + regulator-change-voltage;
> + regulator-always-on;
> + vin-supply = <&vin>;
> + };
> +
> +The same binding used by a regulator to reference its
> +supply can be used by any consumer to reference its
> +regulator/supply
> +
> +Example of a device node referencing a regulator node,
> +
> + devicenode: node at 0x0 {
> + ...
> + ...
> + <name>-supply = <&xyzreg>;
> + };
> diff --git a/drivers/regulator/Kconfig b/drivers/regulator/Kconfig
> index c7fd2c0..981c92e 100644
> --- a/drivers/regulator/Kconfig
> +++ b/drivers/regulator/Kconfig
> @@ -64,6 +64,14 @@ config REGULATOR_USERSPACE_CONSUMER
>
> If unsure, say no.
>
> +config OF_REGULATOR
> + tristate "OF regulator helpers"
> + depends on OF
> + default y if OF
drop the default y line. This probably shouldn't even be a
user-visible option. Make drivers select OF_REGULATOR if it needs
it.
> + help
> + OpenFirmware regulator framework helper routines that can
> + used by regulator drivers to extract data from device tree.
> +
> config REGULATOR_BQ24022
> tristate "TI bq24022 Dual Input 1-Cell Li-Ion Charger IC"
> help
> diff --git a/drivers/regulator/Makefile b/drivers/regulator/Makefile
> index 040d5aa..e6bc009 100644
> --- a/drivers/regulator/Makefile
> +++ b/drivers/regulator/Makefile
> @@ -7,6 +7,7 @@ obj-$(CONFIG_REGULATOR) += core.o dummy.o
> obj-$(CONFIG_REGULATOR_FIXED_VOLTAGE) += fixed.o
> obj-$(CONFIG_REGULATOR_VIRTUAL_CONSUMER) += virtual.o
> obj-$(CONFIG_REGULATOR_USERSPACE_CONSUMER) += userspace-consumer.o
> +obj-$(CONFIG_OF_REGULATOR) += of_regulator.o
>
> obj-$(CONFIG_REGULATOR_AD5398) += ad5398.o
> obj-$(CONFIG_REGULATOR_BQ24022) += bq24022.o
> diff --git a/drivers/regulator/of_regulator.c b/drivers/regulator/of_regulator.c
> new file mode 100644
> index 0000000..9262d06
> --- /dev/null
> +++ b/drivers/regulator/of_regulator.c
> @@ -0,0 +1,93 @@
> +/*
> + * OF helpers for regulator framework
> + *
> + * Copyright (C) 2011 Texas Instruments, Inc.
> + * Rajendra Nayak <rnayak@ti.com>
> + *
> + * This program is free software; you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License as published by
> + * the Free Software Foundation; either version 2 of the License, or
> + * (at your option) any later version.
> + */
> +
> +#include <linux/slab.h>
> +#include <linux/of.h>
> +#include <linux/regulator/machine.h>
> +
> +static void of_get_regulation_constraints(struct device_node *np,
> + struct regulator_init_data **init_data)
> +{
> + const __be32 *min_uV, *max_uV, *uV_offset;
> + const __be32 *min_uA, *max_uA, *input_uV;
> + unsigned int valid_modes_mask = 0, valid_ops_mask = 0;
> +
> + min_uV = of_get_property(np, "regulator-min-uV", NULL);
> + if (min_uV)
> + (*init_data)->constraints.min_uV = be32_to_cpu(*min_uV);
> + max_uV = of_get_property(np, "regulator-max-uV", NULL);
> + if (max_uV)
> + (*init_data)->constraints.max_uV = be32_to_cpu(*max_uV);
> + uV_offset = of_get_property(np, "regulator-uV-offset", NULL);
> + if (uV_offset)
> + (*init_data)->constraints.uV_offset = be32_to_cpu(*uV_offset);
> + min_uA = of_get_property(np, "regulator-min-uA", NULL);
> + if (min_uA)
> + (*init_data)->constraints.min_uA = be32_to_cpu(*min_uA);
> + max_uA = of_get_property(np, "regulator-max-uA", NULL);
> + if (max_uA)
> + (*init_data)->constraints.max_uA = be32_to_cpu(*max_uA);
> + input_uV = of_get_property(np, "regulator-input-uV", NULL);
> + if (input_uV)
> + (*init_data)->constraints.input_uV = be32_to_cpu(*input_uV);
> +
> + /* valid modes mask */
> + if (of_find_property(np, "regulator-mode-fast", NULL))
> + valid_modes_mask |= REGULATOR_MODE_FAST;
> + if (of_find_property(np, "regulator-mode-normal", NULL))
> + valid_modes_mask |= REGULATOR_MODE_NORMAL;
> + if (of_find_property(np, "regulator-mode-idle", NULL))
> + valid_modes_mask |= REGULATOR_MODE_IDLE;
> + if (of_find_property(np, "regulator-mode-standby", NULL))
> + valid_modes_mask |= REGULATOR_MODE_STANDBY;
> +
> + /* valid ops mask */
> + if (of_find_property(np, "regulator-change-voltage", NULL))
> + valid_ops_mask |= REGULATOR_CHANGE_VOLTAGE;
> + if (of_find_property(np, "regulator-change-current", NULL))
> + valid_ops_mask |= REGULATOR_CHANGE_CURRENT;
> + if (of_find_property(np, "regulator-change-mode", NULL))
> + valid_ops_mask |= REGULATOR_CHANGE_MODE;
> + if (of_find_property(np, "regulator-change-status", NULL))
> + valid_ops_mask |= REGULATOR_CHANGE_STATUS;
> +
> + (*init_data)->constraints.valid_modes_mask = valid_modes_mask;
> + (*init_data)->constraints.valid_ops_mask = valid_ops_mask;
> +
> + if (of_find_property(np, "regulator-always-on", NULL))
> + (*init_data)->constraints.always_on = true;
> + if (of_find_property(np, "regulator-boot-on", NULL))
> + (*init_data)->constraints.boot_on = true;
> +}
> +
> +/**
> + * of_get_regulator_init_data - extract regulator_init_data structure info
> + * @dev: device requesting for regulator_init_data
> + *
> + * Populates regulator_init_data structure by extracting data from device
> + * tree node, returns a pointer to the populated struture or NULL if memory
> + * alloc fails.
> + */
> +struct regulator_init_data *of_get_regulator_init_data(struct device *dev)
> +{
> + struct regulator_init_data *init_data;
> +
> + if (!dev->of_node)
> + return NULL;
> +
> + init_data = devm_kzalloc(dev, sizeof(*init_data), GFP_KERNEL);
> + if (!init_data)
> + return NULL; /* Out of memory? */
> +
> + of_get_regulation_constraints(dev->of_node, &init_data);
> + return init_data;
> +}
> diff --git a/include/linux/regulator/of_regulator.h b/include/linux/regulator/of_regulator.h
> new file mode 100644
> index 0000000..c5a1ad6
> --- /dev/null
> +++ b/include/linux/regulator/of_regulator.h
> @@ -0,0 +1,21 @@
> +/*
> + * OpenFirmware regulator support routines
> + *
> + */
> +
> +#ifndef __LINUX_OF_REG_H
> +#define __LINUX_OF_REG_H
> +
> +#if defined(CONFIG_OF_REGULATOR)
> +extern struct regulator_init_data
> + *of_get_regulator_init_data(struct device *dev);
> +#else
> +static inline struct regulator_init_data
> + *of_get_regulator_init_data(struct device *dev)
> +{
> + return NULL;
> +}
> +#endif /* CONFIG_OF_REGULATOR */
> +
> +#endif /* __LINUX_OF_REG_H */
> +
> --
> 1.7.1
>
next prev parent reply other threads:[~2011-10-13 18:40 UTC|newest]
Thread overview: 89+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-10-10 16:19 [PATCH v2 0/5] Device tree support for regulators Rajendra Nayak
2011-10-10 16:19 ` [PATCH v2 1/5] regulator: twl: Remove hardcoded board constraints from driver Rajendra Nayak
2011-10-10 16:25 ` Mark Brown
2011-10-10 16:34 ` Rajendra Nayak
2011-10-10 16:19 ` [PATCH v2 2/5] dt: add empty dt helpers for non-dt build Rajendra Nayak
2011-10-13 18:32 ` Grant Likely
2011-10-10 16:19 ` [PATCH v2 3/5] regulator: helper routine to extract regulator_init_data Rajendra Nayak
2011-10-10 17:22 ` Mark Brown
2011-10-11 5:59 ` Rajendra Nayak
2011-10-13 18:38 ` Grant Likely
2011-10-13 22:12 ` Mark Brown
2011-10-13 18:40 ` Grant Likely [this message]
2011-10-16 14:55 ` Shawn Guo
2011-10-17 4:17 ` Rajendra Nayak
2011-10-18 11:58 ` Shawn Guo
2011-10-18 16:00 ` Mark Brown
2011-10-19 5:33 ` Shawn Guo
2011-10-19 14:47 ` Mark Brown
2011-10-19 15:04 ` Shawn Guo
2011-10-19 15:10 ` Mark Brown
2011-10-20 3:42 ` Rajendra Nayak
2011-10-20 9:41 ` Mark Brown
2011-10-20 12:10 ` Rajendra Nayak
2011-10-20 16:27 ` Tony Lindgren
2011-10-20 16:40 ` Mark Brown
2011-10-20 17:05 ` Tony Lindgren
2011-10-20 17:22 ` Tony Lindgren
2011-10-20 19:57 ` Mark Brown
2011-10-20 20:10 ` Tony Lindgren
2011-10-20 21:42 ` Mark Brown
2011-10-20 22:09 ` Tony Lindgren
2011-10-24 9:07 ` Grant Likely
2011-10-20 19:56 ` Mark Brown
2011-10-18 13:20 ` Shawn Guo
2011-10-19 11:35 ` Rajendra Nayak
2011-10-19 14:42 ` Shawn Guo
2011-10-19 14:50 ` Mark Brown
2011-10-20 5:18 ` Rajendra Nayak
2011-10-20 6:14 ` Shawn Guo
2011-10-20 12:09 ` Rajendra Nayak
2011-10-21 8:23 ` Shawn Guo
2011-10-21 8:41 ` Rajendra Nayak
2011-10-21 11:58 ` Shawn Guo
2011-10-24 6:02 ` Rajendra Nayak
2011-10-24 7:34 ` Mark Brown
2011-10-24 8:17 ` Grant Likely
2011-10-24 8:53 ` Rajendra Nayak
2011-10-24 9:19 ` Mark Brown
2011-10-24 10:05 ` Rajendra Nayak
2011-10-24 9:23 ` Shawn Guo
2011-10-24 9:02 ` Shawn Guo
2011-10-24 8:56 ` Rajendra Nayak
2011-10-24 9:11 ` Shawn Guo
2011-10-24 9:13 ` Rajendra Nayak
2011-10-24 13:47 ` Shawn Guo
2011-10-25 6:00 ` Rajendra Nayak
2011-10-25 6:26 ` Rajendra Nayak
2011-10-25 6:52 ` Shawn Guo
2011-10-25 6:56 ` Rajendra Nayak
2011-10-25 7:20 ` Shawn Guo
2011-10-25 7:13 ` Rajendra Nayak
2011-10-25 7:42 ` Shawn Guo
2011-10-24 11:35 ` Grant Likely
2011-10-24 9:24 ` Grant Likely
2011-10-24 9:39 ` Mark Brown
2011-10-24 13:04 ` Shawn Guo
2011-10-24 13:06 ` Mark Brown
2011-10-24 13:40 ` Shawn Guo
2011-10-24 13:49 ` Mark Brown
2011-10-24 14:47 ` Shawn Guo
2011-10-25 7:11 ` Mark Brown
2011-10-24 13:59 ` Grant Likely
2011-10-24 14:51 ` Shawn Guo
2011-10-24 14:56 ` Grant Likely
2011-10-24 15:51 ` Shawn Guo
2011-10-24 22:21 ` Grant Likely
2011-10-25 6:10 ` Rajendra Nayak
2011-10-25 7:08 ` Shawn Guo
2011-10-25 7:01 ` Rajendra Nayak
2011-10-25 7:28 ` Shawn Guo
2011-10-10 16:19 ` [PATCH v2 4/5] regulator: adapt fixed regulator driver to dt Rajendra Nayak
2011-10-13 18:43 ` Grant Likely
2011-10-10 16:19 ` [PATCH v2 5/5] regulator: map consumer regulator based on device tree Rajendra Nayak
2011-10-10 17:35 ` Mark Brown
2011-10-11 5:49 ` Rajendra Nayak
2011-10-11 7:08 ` Nayak, Rajendra
2011-10-13 16:52 ` Mark Brown
2011-10-13 18:46 ` Grant Likely
2011-10-18 13:33 ` Shawn Guo
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20111013184007.GO18574@ponder.secretlab.ca \
--to=grant.likely@secretlab.ca \
--cc=linux-arm-kernel@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).