linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: lrg@kernel.org (Liam Girdwood)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH] of: add devicetree API for regulator
Date: Fri, 08 Jul 2011 19:32:30 +0100	[thread overview]
Message-ID: <1310149950.3348.8.camel@odin> (raw)
In-Reply-To: <1310120428-22700-8-git-send-email-haojian.zhuang@marvell.com>

On Fri, 2011-07-08 at 18:20 +0800, Haojian Zhuang wrote:
> Signed-off-by: Haojian Zhuang <haojian.zhuang@marvell.com>
> ---
>  drivers/of/Kconfig           |    4 +
>  drivers/of/Makefile          |    1 +
>  drivers/of/of_regulator.c    |  166 ++++++++++++++++++++++++++++++++++++++++++
>  include/linux/of_regulator.h |   34 +++++++++
>  4 files changed, 205 insertions(+), 0 deletions(-)
>  create mode 100644 drivers/of/of_regulator.c
>  create mode 100644 include/linux/of_regulator.h
> 
> diff --git a/drivers/of/Kconfig b/drivers/of/Kconfig
> index d06a637..edb6601 100644
> --- a/drivers/of/Kconfig
> +++ b/drivers/of/Kconfig
> @@ -75,4 +75,8 @@ config OF_PCI
>  	help
>  	  OpenFirmware PCI bus accessors
>  
> +config OF_REGULATOR
> +	def_tristate REGULATOR
> +	depends on REGULATOR
> +
>  endmenu # OF
> diff --git a/drivers/of/Makefile b/drivers/of/Makefile
> index f7861ed..83ca06f 100644
> --- a/drivers/of/Makefile
> +++ b/drivers/of/Makefile
> @@ -10,3 +10,4 @@ obj-$(CONFIG_OF_NET)	+= of_net.o
>  obj-$(CONFIG_OF_SPI)	+= of_spi.o
>  obj-$(CONFIG_OF_MDIO)	+= of_mdio.o
>  obj-$(CONFIG_OF_PCI)	+= of_pci.o
> +obj-$(CONFIG_OF_REGULATOR)	+= of_regulator.o
> diff --git a/drivers/of/of_regulator.c b/drivers/of/of_regulator.c
> new file mode 100644
> index 0000000..d523302
> --- /dev/null
> +++ b/drivers/of/of_regulator.c
> @@ -0,0 +1,166 @@
> +/*
> + * OF helpers for the Regulator API
> + *
> + * Copyright (c) 2011 Haojian Zhuang <haojian.zhuang@marvell.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/kernel.h>
> +#include <linux/of.h>
> +#include <linux/regulator/machine.h>
> +#include <linux/slab.h>
> +#include <linux/string.h>
> +#include <linux/suspend.h>
> +
> +static int of_regulator_init_constraints(struct device_node *of_dev,
> +				struct regulation_constraints *constraints)
> +{
> +	const __be32 *p;
> +	const char *cp;
> +	const char *ops[] = {"voltage", "current", "mode", "status",
> +				"drms"};
> +	int i, size, len = 0, tmp = 0;
> +
> +	memset(constraints, 0, sizeof(struct regulation_constraints));
> +
> +	p = of_get_property(of_dev, "voltages", &size);
> +	if (p && size / sizeof(int) == 2) {
> +		constraints->min_uV = be32_to_cpu(*p++);
> +		constraints->max_uV = be32_to_cpu(*p);
> +	}
> +	p = of_get_property(of_dev, "currents", &size);
> +	if (p && size / sizeof(int) == 2) {
> +		constraints->min_uA = be32_to_cpu(*p++);
> +		constraints->max_uA = be32_to_cpu(*p);
> +	}
> +	p = of_get_property(of_dev, "modes-mask", NULL);
> +	if (p)
> +		constraints->valid_modes_mask = be32_to_cpu(*p);
> +	cp = of_get_property(of_dev, "ops-mask", &size);
> +	tmp = 0;
> +	if (cp && size > 0) {
> +		i = 0;
> +		do {
> +			len = strlen(ops[i]);
> +			if (!strncmp(cp, ops[i], len)) {
> +				constraints->valid_ops_mask |= 1 << i;
> +				/* need to handle '\0' */
> +				cp += len + 1;
> +				size = size - len - 1;
> +				i = 0;
> +			} else
> +				i++;
> +		} while (i < ARRAY_SIZE(ops));
> +		if (size > 0)
> +			printk(KERN_WARNING "Invalid string:%s\n", cp);
> +	}

This code could also do with a little more comments describing some of
the more complex logic (like the above block).

Liam

  parent reply	other threads:[~2011-07-08 18:32 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-07-08 10:20 [PATCH] ARM: mmp: remove SPARSE_IRQ for mmp Haojian Zhuang
2011-07-08 10:20 ` [PATCH] ARM: mmp: remove builtin gpio driver support Haojian Zhuang
2011-07-08 10:20   ` [PATCH] ARM: mmp: parse irq from DT Haojian Zhuang
2011-07-08 10:20     ` [PATCH] ARM: mmp: support OF by default Haojian Zhuang
2011-07-08 10:20       ` [PATCH] tty: serial: support device tree in pxa Haojian Zhuang
2011-07-08 10:20         ` [PATCH] tty: serial: check ops before registering console Haojian Zhuang
2011-07-08 10:20           ` [PATCH] i2c: pxa: create dynamic platform device from device tree Haojian Zhuang
2011-07-08 10:20             ` [PATCH] of: add devicetree API for regulator Haojian Zhuang
2011-07-08 10:20               ` [PATCH] regulator: convert devicetree to platform data on max8649 Haojian Zhuang
2011-07-08 10:20                 ` [PATCH] mfd: convert devicetree to platform data on max8925 Haojian Zhuang
2011-07-08 10:20                   ` [PATCH] mfd: convert devicetree to platform on 88pm860x Haojian Zhuang
2011-07-08 10:20                     ` [PATCH] ARM: mmp: add DTS file Haojian Zhuang
2011-07-10  7:35                       ` Grant Likely
2011-07-11  5:21                         ` Haojian Zhuang
2011-07-10  7:21                     ` [PATCH] mfd: convert devicetree to platform on 88pm860x Grant Likely
2011-07-10  7:20                   ` [PATCH] mfd: convert devicetree to platform data on max8925 Grant Likely
2011-07-10  9:17                     ` Mark Brown
2011-07-10 10:40                       ` Grant Likely
2011-07-08 14:51               ` [PATCH] of: add devicetree API for regulator Grant Likely
2011-07-09  1:14                 ` Mark Brown
2011-07-08 18:32               ` Liam Girdwood [this message]
2011-07-09  2:03               ` Mark Brown
2011-07-10  5:26             ` [PATCH] i2c: pxa: create dynamic platform device from device tree Grant Likely
2011-07-10  5:11         ` [PATCH] tty: serial: support device tree in pxa Grant Likely
2011-07-10  4:34     ` [PATCH] ARM: mmp: parse irq from DT Grant Likely
2011-07-10  4:02   ` [PATCH] ARM: mmp: remove builtin gpio driver support Grant Likely
2011-07-11  5:05     ` Haojian Zhuang
2011-07-11 11:44       ` Eric Miao
2011-07-08 14:46 ` [PATCH] ARM: mmp: remove SPARSE_IRQ for mmp Grant Likely

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=1310149950.3348.8.camel@odin \
    --to=lrg@kernel.org \
    --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).