fsl-i2c: fix writes to data segment before relocation

Prevent i2c_init() in fsl_i2c.c from writing to the data segment before
relocation.  Commit d8c82db4 added the ability for i2c_init() to program the
I2C bus speed and save the value in i2c_bus_speed[], which is a global
variable.  It is an error to write to the data segment before relocation,
which is what i2c_init() does when it stores the bus speed in i2c_bus_speed[].

Signed-off-by: Timur Tabi <timur@freescale.com>
This commit is contained in:
Timur Tabi 2008-07-21 14:26:23 -05:00 committed by Wolfgang Denk
parent 1953d128fd
commit e4dafff86f

View File

@ -143,12 +143,15 @@ void
i2c_init(int speed, int slaveadd) i2c_init(int speed, int slaveadd)
{ {
struct fsl_i2c *dev; struct fsl_i2c *dev;
unsigned int temp;
dev = (struct fsl_i2c *) (CFG_IMMR + CFG_I2C_OFFSET); dev = (struct fsl_i2c *) (CFG_IMMR + CFG_I2C_OFFSET);
writeb(0, &dev->cr); /* stop I2C controller */ writeb(0, &dev->cr); /* stop I2C controller */
udelay(5); /* let it shutdown in peace */ udelay(5); /* let it shutdown in peace */
i2c_bus_speed[0] = set_i2c_bus_speed(dev, gd->i2c1_clk, speed); 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(slaveadd << 1, &dev->adr); /* write slave address */
writeb(0x0, &dev->sr); /* clear status register */ writeb(0x0, &dev->sr); /* clear status register */
writeb(I2C_CR_MEN, &dev->cr); /* start I2C controller */ writeb(I2C_CR_MEN, &dev->cr); /* start I2C controller */
@ -158,7 +161,9 @@ i2c_init(int speed, int slaveadd)
writeb(0, &dev->cr); /* stop I2C controller */ writeb(0, &dev->cr); /* stop I2C controller */
udelay(5); /* let it shutdown in peace */ udelay(5); /* let it shutdown in peace */
i2c_bus_speed[1] = set_i2c_bus_speed(dev, gd->i2c2_clk, speed); 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(slaveadd << 1, &dev->adr); /* write slave address */
writeb(0x0, &dev->sr); /* clear status register */ writeb(0x0, &dev->sr); /* clear status register */
writeb(I2C_CR_MEN, &dev->cr); /* start I2C controller */ writeb(I2C_CR_MEN, &dev->cr); /* start I2C controller */