From: Mike Frysinger <vapier@gentoo.org>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH v4] sh: i2c: Add support I2C controller of SH7734
Date: Wed, 29 Feb 2012 22:24:34 -0500 [thread overview]
Message-ID: <201202292224.38696.vapier@gentoo.org> (raw)
In-Reply-To: <1330570723-10002-1-git-send-email-nobuhiro.iwamatsu.yj@renesas.com>
On Wednesday 29 February 2012 21:58:42 Nobuhiro Iwamatsu wrote:
> --- /dev/null
> +++ b/drivers/i2c/sh_sh7734_i2c.c
>
> +#include <common.h>
> +#include <asm/io.h>
should include i2c.h too so you know your funcs match the prototypes everyone
else uses
> +static int check_stop(struct sh_i2c *base)
> +{
> + int i, ret = 1;
> +
> + for (i = 0; i < IRQ_WAIT; i++) {
> + if (SH_I2C_ICSR_STOP & readb(&base->icsr)) {
> + ret = 0;
> + break;
> + }
> + udelay(10);
> + }
> +
> + clrbits_le8(&base->icsr, SH_I2C_ICSR_STOP);
> +
> + return ret;
> +}
> +
> +static int check_tend(struct sh_i2c *base, int stop)
> +{
> + int i, ret = 1;
> +
> + for (i = 0; i < IRQ_WAIT; i++) {
> + if (SH_I2C_ICSR_TEND & readb(&base->icsr)) {
> + ret = 0;
> + break;
> + }
> + udelay(10);
> + }
> +
> + if (stop) {
> + u8 data;
> +
> + clrbits_le8(&base->icsr, SH_I2C_ICSR_STOP);
> +
> + sh_i2c_send_stop(base);
> + }
> +
> + clrbits_le8(&base->icsr, SH_I2C_ICSR_TEND);
> +
> + return ret;
> +}
> +
> +static int check_tdre(struct sh_i2c *base)
> +{
> + int i;
> +
> + for (i = 0; i < IRQ_WAIT; i++) {
> + if (SH_I2C_ICSR_TDRE & readb(&base->icsr))
> + return 0;
> + udelay(10);
> + }
> +
> + return 1;
> +}
> +
> +static int check_rdrf(struct sh_i2c *base)
> +{
> + int i;
> +
> + for (i = 0; i < IRQ_WAIT; i++) {
> + if (SH_I2C_ICSR_RDRF & readb(&base->icsr))
> + return 0;
> + udelay(10);
> + }
> +
> + return 1;
> +}
you've got the same icsr bit polling logic here. probably better to put it
into a dedicated func which takes the bit flag to check and the rest will call
that.
static int check_icsr_bit(struct sh_i2c *base, uint bit)
{
int i;
for (i = 0; i < IRQ_WAIT; i++) {
if (bit & readb(&base->icsr))
return 0;
udelay(10);
}
return 1;
}
static int check_tdre(struct sh_i2c *base)
{
return check_icsr_bit(base, SH_I2C_ICSR_TDRE);
}
> +static u8 i2c_raw_read(struct sh_i2c *base, u8 id, u8 reg)
> +{
> ...
> + writeb(id << 1 | 1, &base->icdrt);
shifting and bit ops can lead to unexpected behavior ... might be better:
writeb((id << 1) | 1, &base->icdrt);
> +/*
> + * i2c_probe: - Test if a chip answers for a given i2c address
> + *
> + * @chip: address of the chip which is searched for
> + * @return: 0 if a chip was found, -1 otherwhise
> + */
> +int i2c_probe(u8 chip)
> +{
> + return 0;
> +}
should implement this. look at the Blackfin twi driver for an easy one.
-mike
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: This is a digitally signed message part.
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20120229/7c82d16a/attachment.pgp>
next prev parent reply other threads:[~2012-03-01 3:24 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-03-01 2:58 [U-Boot] [PATCH v4] sh: i2c: Add support I2C controller of SH7734 Nobuhiro Iwamatsu
2012-03-01 3:24 ` Mike Frysinger [this message]
2012-03-02 3:40 ` Nobuhiro Iwamatsu
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=201202292224.38696.vapier@gentoo.org \
--to=vapier@gentoo.org \
--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