public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Heiko Schocher <hs@denx.de>
To: u-boot@lists.denx.de
Subject: [U-Boot] PATCH 2/8 Multi-adapter multi-bus I2C
Date: Mon, 09 Feb 2009 12:45:30 +0100	[thread overview]
Message-ID: <4990175A.4020703@denx.de> (raw)
In-Reply-To: <Pine.LNX.4.64ksi.0902061703330.14843@home-gw.koi8.net>

Hello ksi,

ksi at koi8.net wrote:
[...]
> diff --git a/drivers/i2c/fsl_i2c.c b/drivers/i2c/fsl_i2c.c
> index ce646fd..f7998e3 100644
> --- a/drivers/i2c/fsl_i2c.c
> +++ b/drivers/i2c/fsl_i2c.c
> @@ -1,4 +1,8 @@
>  /*
> + * Copyright (c) 2009 Sergey Kubushyn <ksi@koi8.net>
> + *
> + * Changes for multibus/multiadapter I2C support.
> + *
>   * Copyright 2006 Freescale Semiconductor, Inc.
>   *
>   * This program is free software; you can redistribute it and/or
> @@ -18,7 +22,7 @@
>  
>  #include <common.h>
>  
> -#ifdef CONFIG_HARD_I2C
> +#ifdef CONFIG_FSL_I2C
>  
>  #include <command.h>
>  #include <i2c.h>		/* Functional interface */
> @@ -31,24 +35,15 @@
>  #define I2C_READ_BIT  1
>  #define I2C_WRITE_BIT 0
>  
> -DECLARE_GLOBAL_DATA_PTR;
> -
> -/* Initialize the bus pointer to whatever one the SPD EEPROM is on.
> - * Default is bus 0.  This is necessary because the DDR initialization
> - * runs from ROM, and we can't switch buses because we can't modify
> - * the global variables.
> - */
> -#ifndef CONFIG_SYS_SPD_BUS_NUM
> -#define CONFIG_SYS_SPD_BUS_NUM 0
> -#endif
> -static unsigned int i2c_bus_num __attribute__ ((section (".data"))) = CONFIG_SYS_SPD_BUS_NUM;
> +#define FSL_NAME(arg)	"fsl_i2c@" MK_NAME(arg)
> +#define MK_NAME(arg)	#arg
>  
> -static unsigned int i2c_bus_speed[2] = {CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SPEED};
> +DECLARE_GLOBAL_DATA_PTR;
>  
>  static const struct fsl_i2c *i2c_dev[2] = {
> -	(struct fsl_i2c *) (CONFIG_SYS_IMMR + CONFIG_SYS_I2C_OFFSET),
> -#ifdef CONFIG_SYS_I2C2_OFFSET
> -	(struct fsl_i2c *) (CONFIG_SYS_IMMR + CONFIG_SYS_I2C2_OFFSET)
> +	(struct fsl_i2c *) (CONFIG_SYS_IMMR + CONFIG_SYS_FSL_I2C_OFFSET),
> +#ifdef CONFIG_SYS_FSL_I2C2_OFFSET
> +	(struct fsl_i2c *) (CONFIG_SYS_IMMR + CONFIG_SYS_FSL_I2C2_OFFSET)
>  #endif
>  };
>  
> @@ -126,6 +121,8 @@ static const struct {
>  #endif
>  };
>  
> +i2c_adap_t	fsl_i2c_adap[];
> +
>  /**
>   * Set the I2C bus speed for a given I2C device
>   *
> @@ -169,43 +166,29 @@ static unsigned int set_i2c_bus_speed(const struct fsl_i2c *dev,
>  	return speed;
>  }
>  
> -void
> -i2c_init(int speed, int slaveadd)
> +
> +static void __i2c_init(int adap_no, int speed, int slaveadd)
>  {
> -	struct fsl_i2c *dev;
>  	unsigned int temp;
>  
> -	dev = (struct fsl_i2c *) (CONFIG_SYS_IMMR + CONFIG_SYS_I2C_OFFSET);
> -
> -	writeb(0, &dev->cr);			/* stop I2C controller */
> +	writeb(0, &i2c_dev[adap_no]->cr);	/* stop I2C controller */
>   

Why do you here substitute a "dev->" with "&i2c_dev[adap_no]"?
Why not dev =  &i2c_dev[adap_no] and you can let the dev-> unchanged.

>  	udelay(5);				/* let it shutdown in peace */
> -	temp = set_i2c_bus_speed(dev, gd->i2c1_clk, speed);
> -	if (gd->flags & GD_FLG_RELOC)
> -		i2c_bus_speed[0] = temp;
> -	writeb(slaveadd << 1, &dev->adr);	/* write slave address */
> -	writeb(0x0, &dev->sr);			/* clear status register */
> -	writeb(I2C_CR_MEN, &dev->cr);		/* start I2C controller */
> -
> -#ifdef	CONFIG_SYS_I2C2_OFFSET
> -	dev = (struct fsl_i2c *) (CONFIG_SYS_IMMR + CONFIG_SYS_I2C2_OFFSET);
> -
> -	writeb(0, &dev->cr);			/* stop I2C controller */
> -	udelay(5);				/* let it shutdown in peace */
> -	temp = set_i2c_bus_speed(dev, gd->i2c2_clk, speed);
> -	if (gd->flags & GD_FLG_RELOC)
> -		i2c_bus_speed[1] = temp;
> -	writeb(slaveadd << 1, &dev->adr);	/* write slave address */
> -	writeb(0x0, &dev->sr);			/* clear status register */
> -	writeb(I2C_CR_MEN, &dev->cr);		/* start I2C controller */
> -#endif
> +	temp = set_i2c_bus_speed(i2c_dev[adap_no], gd->i2c1_clk, speed);
> +	if (gd->flags & GD_FLG_RELOC) {
> +		fsl_i2c_adap[adap_no].speed = temp;
> +		fsl_i2c_adap[adap_no].slaveaddr = slaveadd;
> +	}
> +	writeb(slaveadd << 1, &i2c_dev[adap_no]->adr);	/* write slave address */
> +	writeb(0x0, &i2c_dev[adap_no]->sr);			/* clear status register */
> +	writeb(I2C_CR_MEN, &i2c_dev[adap_no]->cr);		/* start I2C controller */
>  }
>  
bye
Heiko

-- 
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany 

  reply	other threads:[~2009-02-09 11:45 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-02-07  1:04 [U-Boot] PATCH 2/8 Multi-adapter multi-bus I2C ksi at koi8.net
2009-02-09 11:45 ` Heiko Schocher [this message]
2009-02-09 21:56   ` ksi at koi8.net
2009-02-09 23:59     ` Wolfgang Denk
2009-02-10  0:07       ` ksi at koi8.net

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=4990175A.4020703@denx.de \
    --to=hs@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