public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Stefano Babic <sbabic@denx.de>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH 2/3]  fsl_pmic: add I2C interface support
Date: Mon, 27 Dec 2010 11:43:40 +0100	[thread overview]
Message-ID: <4D186DDC.2020100@denx.de> (raw)
In-Reply-To: <1293024231-4897-2-git-send-email-r64343@freescale.com>

On 12/22/2010 02:23 PM, Jason Liu wrote:
> This patch add I2C interface for fsl_pmic driver support
> 
> +#ifdef CONFIG_FSL_PMIC_I2C
> +#include <i2c.h>
> +static int init_done;
> +
> +u32 pmic_reg(u32 reg, u32 val, u32 write)
> +{
> +	unsigned char buf[4] = { 0 };
> +	u32 ret_val = 0;
> +
> +	if (reg > 63 || write > 1) {
> +		printf("<reg num> = %d is invalid. Should be less then 63\n",
> +			reg);
> +		return -1;
> +	}

Probably we can factorize better this function and do not duplicate the
pmic_reg function for SPI and I2C.

> +
> +	if (init_done == 0) {
> +		i2c_init(CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE);
> +		init_done = 1;
> +	}
> +
> +	if (write) {
> +		buf[0] = (val >> 16) & 0xff;
> +		buf[1] = (val >> 8) & 0xff;
> +		buf[2] = (val) & 0xff;

It seems you are converting the endianess. No chance to use an already
provided accessor ?

> +		if (i2c_write(CONFIG_SYS_FSL_PMIC_I2C_ADDR, reg, 1, buf, 3))
> +			return -1;
> +	} else {
> +		if (i2c_read(CONFIG_SYS_FSL_PMIC_I2C_ADDR, reg, 1, buf, 3)) {
> +			return -1;
> +		ret_val = buf[0] << 16 | buf[1] << 8 | buf[2];

Ditto.

Best regards,
Stefano Babic

-- 
=====================================================================
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@denx.de
=====================================================================

  reply	other threads:[~2010-12-27 10:43 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-12-22 13:23 [U-Boot] [PATCH 1/3] mxc_gpio: add support for MX53 processor Jason Liu
2010-12-22 13:23 ` [U-Boot] [PATCH 2/3] fsl_pmic: add I2C interface support Jason Liu
2010-12-27 10:43   ` Stefano Babic [this message]
2010-12-28  8:00     ` Jason Liu
2010-12-28  8:53     ` Jason Liu
2010-12-22 13:23 ` [U-Boot] [PATCH 3/3] imximage: Add MX53 boot image support Jason Liu
2010-12-27 10:55   ` Stefano Babic
2010-12-28  8:08     ` Jason Liu
2010-12-28  8:23       ` Stefano Babic
2010-12-28  8:34         ` Jason Liu
2010-12-28  9:21           ` Stefano Babic
2010-12-27 10:26 ` [U-Boot] [PATCH 1/3] mxc_gpio: add support for MX53 processor Stefano Babic
2010-12-28  8:00   ` Jason Liu

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=4D186DDC.2020100@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox