All of lore.kernel.org
 help / color / mirror / Atom feed
From: Minkyu Kang <mk7.kang@samsung.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH V5 5/6] exynos: Add a common DT based PMIC driver initialization
Date: Mon, 03 Feb 2014 16:25:07 +0900	[thread overview]
Message-ID: <52EF4453.1050800@samsung.com> (raw)
In-Reply-To: <52EF4023.9070907@samsung.com>

On 16/01/14 17:55, Leela Krishna Amudala wrote:
> Most of i2c PMIC drivers follow the same initialization sequence,
> let's generalize it in a common file.
> 
> The initialization function finds the PMIC in the device tree, and if
> found - registers it in the list of known PMICs and initializes it,
> iterating through the table of settings supplied by the caller.
> 
> Signed-off-by: Vadim Bendebury <vbendeb@chromium.org>
> Signed-off-by: Leela Krishna Amudala <l.krishna@samsung.com>
> Reviewed-by: Doug Anderson <dianders@google.com>
> Acked-by: Simon Glass <sjg@chromium.org>
> ---
>  board/samsung/common/board.c     |   26 ++++++++++++
>  drivers/power/pmic/Makefile      |    1 +
>  drivers/power/pmic/pmic_common.c |   87 ++++++++++++++++++++++++++++++++++++++
>  drivers/power/power_core.c       |   14 ++++++
>  include/power/pmic.h             |   36 ++++++++++++++++
>  5 files changed, 164 insertions(+)
>  create mode 100644 drivers/power/pmic/pmic_common.c
> 
> diff --git a/drivers/power/pmic/pmic_common.c b/drivers/power/pmic/pmic_common.c
> new file mode 100644
> index 0000000..ea1e90f
> --- /dev/null
> +++ b/drivers/power/pmic/pmic_common.c
> @@ -0,0 +1,87 @@
> +/*
> + * Copyright (c) 2013 The Chromium OS Authors. All rights reserved.
> + *
> + * SPDX-License-Identifier:	GPL-2.0+
> + *
> + * Author: Vadim Bendebury <vbendeb@chromium.org>
> + */
> +#include <common.h>
> +#include <fdtdec.h>
> +#include <errno.h>
> +#include <power/pmic.h>
> +
> +DECLARE_GLOBAL_DATA_PTR;
> +
> +int pmic_common_init(enum fdt_compat_id pmic_compat,
> +		     const struct pmic_init_ops *pmic_ops,
> +		     unsigned int number_of_regs)
> +{
> +	const void *blob = gd->fdt_blob;
> +	struct pmic *p;
> +	int node, parent, ret;
> +	const char *pmic_name, *comma;
> +
> +	if (!number_of_regs) {
> +		printf("%s: %s - not a supported PMIC\n",
> +		       __func__, fdtdec_get_compatible(pmic_compat));
> +		return -1;
> +	}
> +
> +	node = fdtdec_next_compatible(blob, 0, pmic_compat);
> +	if (node < 0) {
> +		debug("PMIC: Error %s. No node for %s in device tree\n",
> +		      fdt_strerror(node), fdtdec_get_compatible(pmic_compat));
> +		return node;
> +	}
> +
> +	pmic_name = fdtdec_get_compatible(pmic_compat);
> +	comma = strchr(pmic_name, ',');
> +	if (comma)
> +		pmic_name = comma + 1;
> +
> +	p = pmic_alloc();
> +
> +	if (!p) {
> +		printf("%s: POWER allocation error!\n", __func__);
> +		return -ENOMEM;
> +	}
> +	parent = fdt_parent_offset(blob, node);
> +	if (parent < 0) {
> +		debug("%s: Cannot find node parent\n", __func__);
> +		return -1;
> +	}
> +
> +	p->bus = i2c_get_bus_num_fdt(parent);
> +	if (p->bus < 0) {
> +		debug("%s: Cannot find I2C bus\n", __func__);
> +		return -1;
> +	}
> +	p->hw.i2c.addr = fdtdec_get_int(blob, node, "reg", 9);
> +
> +	p->name = pmic_name;
> +	p->interface = PMIC_I2C;
> +	p->hw.i2c.tx_num = 1;
> +	p->number_of_regs = number_of_regs;
> +	p->compat_id = pmic_compat;
> +
> +	ret = 0;

ret = 0; unnecessary.

> +	while (pmic_ops->reg_op != PMIC_REG_BAIL) {
> +		if (pmic_ops->reg_op == PMIC_REG_WRITE)
> +			ret = pmic_reg_write(p,
> +					     pmic_ops->reg_addr,
> +					     pmic_ops->reg_value);
> +		else
> +			ret = pmic_reg_update(p,
> +					     pmic_ops->reg_addr,
> +					     pmic_ops->reg_value);
> +		if (ret) {
> +			printf("%s: Failed accessing reg 0x%x of %s\n",
> +			       __func__, pmic_ops->reg_addr, p->name);
> +			return ret;
> +		}
> +		pmic_ops++;
> +	}
> +
> +	printf("PMIC %s initialized\n", p->name);
> +	return ret;
> +}
> diff --git a/drivers/power/power_core.c b/drivers/power/power_core.c
> index a1c4fd0..f40be31 100644
> --- a/drivers/power/power_core.c
> +++ b/drivers/power/power_core.c
> @@ -228,6 +228,20 @@ int pmic_reg_update(struct pmic *p, int reg, u32 val)
>  	return 0;
>  }
>  
> +struct pmic *pmic_get_by_id(enum fdt_compat_id pmic_compat)

Seems to did not use anywhere.

> +{
> +	struct pmic *p;
> +
> +	list_for_each_entry(p, &pmic_list, list) {
> +		if (p->compat_id == pmic_compat) {
> +			debug("%s: pmic %s -> 0x%p\n", __func__, p->name, p);
> +			return p;
> +		}
> +	}
> +
> +	return NULL;
> +}
> +
>  U_BOOT_CMD(
>  	pmic,	CONFIG_SYS_MAXARGS, 1, do_pmic,
>  	"PMIC",

Thanks,
Minkyu Kang.

  parent reply	other threads:[~2014-02-03  7:25 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-01-16  8:55 [U-Boot] [PATCH V5 0/6] SMDK5420: Add S2MPS11 pmic support to SMDK5420 Leela Krishna Amudala
2014-01-16  8:55 ` [U-Boot] [PATCH V5 1/6] exynos: Use common pmic_reg_update() definition Leela Krishna Amudala
2014-01-16  8:55 ` [U-Boot] [PATCH V5 2/6] power: Explicitly select pmic device's bus Leela Krishna Amudala
2014-01-16  8:55 ` [U-Boot] [PATCH V5 3/6] FDT: Exynos5420: Add compatible srings for PMIC Leela Krishna Amudala
2014-01-16  8:55 ` [U-Boot] [PATCH V5 4/6] SMDK5420: S2MPS11: Adds the register settings for S2MPS11 Leela Krishna Amudala
2014-01-16  8:55 ` [U-Boot] [PATCH V5 5/6] exynos: Add a common DT based PMIC driver initialization Leela Krishna Amudala
     [not found]   ` <52EF4023.9070907@samsung.com>
2014-02-03  7:25     ` Minkyu Kang [this message]
2014-01-16  8:55 ` [U-Boot] [PATCH V5 6/6] config: SMDK5420: Enable S2MPS11 pmic Leela Krishna Amudala

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=52EF4453.1050800@samsung.com \
    --to=mk7.kang@samsung.com \
    --cc=u-boot@lists.denx.de \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.