All of lore.kernel.org
 help / color / mirror / Atom feed
From: Stefano Babic <sbabic@denx.de>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH V7 2/3] PMIC: Add dialog pmic support
Date: Thu, 12 May 2011 11:19:20 +0200	[thread overview]
Message-ID: <4DCBA618.2060608@denx.de> (raw)
In-Reply-To: <1305101022-22546-2-git-send-email-jason.hui@linaro.org>

On 05/11/2011 10:03 AM, Jason Liu wrote:
> This patch add dialog pmic(DA9053) driver with I2C interface support
> In order to not duplicate code and according to the discussion on the
> mail-list, change fsl_pmic.c to spi_i2c_pmic.c.Actaully,spi_i2c_pmic.c
> is just a wrapper for PMIC communication when SPI or I2C is used.
> 
> Signed-off-by: Jason Liu <jason.hui@linaro.org>
> Cc: sbabic at denx.de <sbabic@denx.de>
> Cc: Detlev Zundel <dzu@denx.de>

Hi Jason,

> --- a/drivers/misc/fsl_pmic.c
> +++ b/drivers/misc/spi_i2c_pmic.c
> @@ -22,13 +22,16 @@
>  
>  #include <config.h>
>  #include <common.h>
> +#include <i2c.h>
>  #include <asm/errno.h>
>  #include <linux/types.h>
> +#if defined(CONFIG_FSL_PMIC)
>  #include <fsl_pmic.h>
> +#endif
>  
> -static int check_param(u32 reg, u32 write)
> +static int check_param(u32 reg, u32 write, u32 max_reg)
>  {
> -	if (reg > 63 || write > 1) {
> +	if (reg > max_reg || write > 1) {
>  		printf("<reg num> = %d is invalid. Should be less then 63\n",
>  			reg);
>  		return -1;
> @@ -37,15 +40,13 @@ static int check_param(u32 reg, u32 write)
>  	return 0;
>  }
>  
> -#ifdef CONFIG_FSL_PMIC_I2C
> -#include <i2c.h>
> -
> -u32 pmic_reg(u32 reg, u32 val, u32 write)
> +#if defined(CONFIG_FSL_PMIC_I2C)
> +u32 fsl_pmic_reg(u32 reg, u32 val, u32 write)
>  {
> -	unsigned char buf[4] = { 0 };
>  	u32 ret_val = 0;
> +	unsigned char buf[4] = { 0 };
>  
> -	if (check_param(reg, write))
> +	if (check_param(reg, write, 63))
>  		return -1;
>  
>  	if (write) {
> @@ -62,7 +63,44 @@ u32 pmic_reg(u32 reg, u32 val, u32 write)
>  
>  	return ret_val;
>  }
> -#else /* SPI interface */
> +#endif
> +
> +#if defined(CONFIG_DIALOG_PMIC_I2C)
> +u32 dlg_pmic_reg(u32 reg, u32 val, u32 write)
> +{
> +	u32 ret_val = 0;
> +	unsigned char buf[1] = { 0 };
> +
> +	if (check_param(reg, write, 142))
> +		return -1;
> +
> +	if (write) {
> +		buf[0] = (val) & 0xff;
> +		if (i2c_write(CONFIG_SYS_DIALOG_PMIC_I2C_ADDR, reg, 1, buf, 1))
> +			return -1;
> +	} else {
> +		if (i2c_read(CONFIG_SYS_DIALOG_PMIC_I2C_ADDR, reg, 1, buf, 1))
> +			return -1;
> +		ret_val = buf[0];
> +	}
> +
> +	return ret_val;

This is not what I meant. You have duplicated the code, instead of merge
the two functions together. And I think the switch is wrong.
This file provides a general access to PMIc using SPI/I2C. There should
not be #ifdef related to a single PMIC. Instead of that, You need
additional CONFIG_ to select how to access the PMIC (8 bit or 32 bit).

IMHO we can rid of the check_param() function, as this is a constraint
to have an implementation independent from a single PMIC.

I would prefer something like this:

u32 pmic_reg(u32 reg, u32 val, u32 write) {

	........
#ifdef CONFIG_SYS_PMIC_8BIT
	
	<read / write 8 bit register>
#else

	<actual implementation for fsl PMICs>
#endif


> +#if defined(CONFIG_FSL_PMIC_I2C) || defined(CONFIG_DIALOG_PMIC_I2C)

Same comments apply here. We should select only between I2C and SPI, not
the chip.

> +#if defined(CONFIG_FSL_PMIC)
> +#define PMIC_NAME "Freescale PMIC (Atlas)"
> +#elif defined(CONFIG_DIALOG_PMIC)
> +#define PMIC_NAME "Dialog PMIC (DA905x)"
> +#else
> +#error "Unkown PMIC name"
> +#endif

Instead of that, we can set a general name or put the PMIC_NAME inside
the specific PMIC header file.

Best regards,
Stefano

-- 
=====================================================================
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-0 Fax: +49-8142-66989-80  Email: office at denx.de
=====================================================================

  reply	other threads:[~2011-05-12  9:19 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-05-11  8:03 [U-Boot] [PATCH V7 1/3] MX5: clock: Add clock config interface Jason Liu
2011-05-11  8:03 ` [U-Boot] [PATCH V7 2/3] PMIC: Add dialog pmic support Jason Liu
2011-05-12  9:19   ` Stefano Babic [this message]
2011-05-13  3:08     ` Jason Liu
2011-05-13  6:38       ` Stefano Babic
2011-05-13  8:41         ` Jason Liu
2011-05-13  8:47           ` Stefano Babic
2011-05-13  9:04             ` Jason Hui
2011-05-11  8:03 ` [U-Boot] [PATCH V7 3/3] MX53: support for freescale MX53LOCO board Jason Liu
2011-05-11 12:03   ` Fabio Estevam
2011-05-12  5:31     ` Jason Hui
2011-05-11 12:37   ` Stefano Babic
2011-05-12  5:32     ` Jason Hui
2011-05-12  6:13     ` Jason Liu
2011-05-12  9:03       ` Stefano Babic
2011-05-13  3:13         ` Jason Hui
2011-05-20 18:35   ` Albert ARIBAUD
2011-05-16  9:26 ` [U-Boot] [PATCH V7 1/3] MX5: clock: Add clock config interface Stefano Babic
2011-05-17  6:25   ` Jason Liu
2011-05-17 11:15     ` Stefano Babic

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=4DCBA618.2060608@denx.de \
    --to=sbabic@denx.de \
    --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.