forked from len0rd/rockbox
Clean up PP5002 I2C code (no functional changes):
Move into target tree. Use #defines instead of inb/outb. Also restore comments in PP5020 I2C code. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@12124 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
parent
5e765b2ea2
commit
adc349891e
5 changed files with 31 additions and 38 deletions
|
|
@ -257,7 +257,7 @@ target/arm/memset16-arm.S
|
|||
#if CONFIG_I2C == I2C_PP5020
|
||||
target/arm/i2c-pp5020.c
|
||||
#elif CONFIG_I2C == I2C_PP5002
|
||||
drivers/i2c-pp5002.c
|
||||
target/arm/i2c-pp5002.c
|
||||
#elif CONFIG_I2C == I2C_PNX0101
|
||||
drivers/i2c-pnx0101.c
|
||||
#elif CONFIG_I2C == I2C_S3C2440
|
||||
|
|
|
|||
|
|
@ -25,6 +25,17 @@
|
|||
#ifndef _I2C_PP5002_H
|
||||
#define _I2C_PP5002_H
|
||||
|
||||
#define I2C_CTRL (*(volatile unsigned char*)(I2C_BASE+0x00))
|
||||
#define I2C_ADDR (*(volatile unsigned char*)(I2C_BASE+0x04))
|
||||
#define I2C_DATA(X) (*(volatile unsigned char*)(I2C_BASE+0xc+(4*X)))
|
||||
#define I2C_STATUS (*(volatile unsigned char*)(I2C_BASE+0x1c))
|
||||
|
||||
/* I2C_CTRL bit definitions */
|
||||
#define I2C_SEND 0x80
|
||||
|
||||
/* I2C_STATUS bit definitions */
|
||||
#define I2C_BUSY (1<<6)
|
||||
|
||||
/* TODO: Fully implement i2c driver */
|
||||
|
||||
void i2c_init(void);
|
||||
|
|
|
|||
|
|
@ -59,6 +59,7 @@
|
|||
#define DEV_RS (*(volatile unsigned long *)( 0xcf005030))
|
||||
#define DEV_EN (*(volatile unsigned long *)( 0xcf005000))
|
||||
|
||||
#define DEV_I2C (1<<8)
|
||||
#define DEV_USB 0x400000
|
||||
|
||||
#define DEV_INIT (*(volatile unsigned long *)(0x70000020))
|
||||
|
|
@ -78,6 +79,8 @@
|
|||
#define IISFIFO_WR (*(volatile unsigned long*)(0xc0002540))
|
||||
#define IISFIFO_RD (*(volatile unsigned long*)(0xc0002580))
|
||||
|
||||
#define I2C_BASE 0xc0008000
|
||||
|
||||
#define TIMER1_CFG (*(volatile unsigned long *)(0xcf001100))
|
||||
#define TIMER1_VAL (*(volatile unsigned long *)(0xcf001104))
|
||||
#define TIMER2_CFG (*(volatile unsigned long *)(0xcf001108))
|
||||
|
|
|
|||
|
|
@ -32,21 +32,6 @@
|
|||
|
||||
/* Local functions definitions */
|
||||
|
||||
#define IPOD_I2C_BASE 0xc0008000
|
||||
#define IPOD_I2C_CTRL (IPOD_I2C_BASE+0x00)
|
||||
#define IPOD_I2C_ADDR (IPOD_I2C_BASE+0x04)
|
||||
#define IPOD_I2C_DATA0 (IPOD_I2C_BASE+0x0c)
|
||||
#define IPOD_I2C_DATA1 (IPOD_I2C_BASE+0x10)
|
||||
#define IPOD_I2C_DATA2 (IPOD_I2C_BASE+0x14)
|
||||
#define IPOD_I2C_DATA3 (IPOD_I2C_BASE+0x18)
|
||||
#define IPOD_I2C_STATUS (IPOD_I2C_BASE+0x1c)
|
||||
|
||||
/* IPOD_I2C_CTRL bit definitions */
|
||||
#define IPOD_I2C_SEND 0x80
|
||||
|
||||
/* IPOD_I2C_STATUS bit definitions */
|
||||
#define IPOD_I2C_BUSY (1<<6)
|
||||
|
||||
#define POLL_TIMEOUT (HZ)
|
||||
|
||||
static int pp_i2c_wait_not_busy(void)
|
||||
|
|
@ -54,7 +39,7 @@ static int pp_i2c_wait_not_busy(void)
|
|||
unsigned long timeout;
|
||||
timeout = current_tick + POLL_TIMEOUT;
|
||||
while (TIME_BEFORE(current_tick, timeout)) {
|
||||
if (!(inb(IPOD_I2C_STATUS) & IPOD_I2C_BUSY)) {
|
||||
if (!(I2C_STATUS & I2C_BUSY)) {
|
||||
return 0;
|
||||
}
|
||||
yield();
|
||||
|
|
@ -74,11 +59,11 @@ int pp_i2c_read_byte(unsigned int addr, unsigned int *data)
|
|||
}
|
||||
|
||||
/* clear top 15 bits, left shift 1, or in 0x1 for a read */
|
||||
outb(((addr << 17) >> 16) | 0x1, IPOD_I2C_ADDR);
|
||||
I2C_ADDR = ((addr << 17) >> 16) | 0x1 ;
|
||||
|
||||
outb(inb(IPOD_I2C_CTRL) | 0x20, IPOD_I2C_CTRL);
|
||||
I2C_CTRL |= 0x20;
|
||||
|
||||
outb(inb(IPOD_I2C_CTRL) | IPOD_I2C_SEND, IPOD_I2C_CTRL);
|
||||
I2C_CTRL |= I2C_SEND;
|
||||
|
||||
if (pp_i2c_wait_not_busy() < 0)
|
||||
{
|
||||
|
|
@ -87,7 +72,7 @@ int pp_i2c_read_byte(unsigned int addr, unsigned int *data)
|
|||
|
||||
if (data)
|
||||
{
|
||||
*data = inb(IPOD_I2C_DATA0);
|
||||
*data = I2C_DATA(0);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
|
@ -95,7 +80,6 @@ int pp_i2c_read_byte(unsigned int addr, unsigned int *data)
|
|||
|
||||
int pp_i2c_send_bytes(unsigned int addr, unsigned int len, unsigned char *data)
|
||||
{
|
||||
int data_addr;
|
||||
unsigned int i;
|
||||
|
||||
if (len < 1 || len > 4)
|
||||
|
|
@ -109,20 +93,18 @@ int pp_i2c_send_bytes(unsigned int addr, unsigned int len, unsigned char *data)
|
|||
}
|
||||
|
||||
/* clear top 15 bits, left shift 1 */
|
||||
outb((addr << 17) >> 16, IPOD_I2C_ADDR);
|
||||
I2C_ADDR = (addr << 17) >> 16;
|
||||
|
||||
outb(inb(IPOD_I2C_CTRL) & ~0x20, IPOD_I2C_CTRL);
|
||||
I2C_CTRL &= ~0x20;
|
||||
|
||||
data_addr = IPOD_I2C_DATA0;
|
||||
for ( i = 0; i < len; i++ )
|
||||
{
|
||||
outb(*data++, data_addr);
|
||||
data_addr += 4;
|
||||
I2C_DATA(i) = *data++;
|
||||
}
|
||||
|
||||
outb((inb(IPOD_I2C_CTRL) & ~0x26) | ((len-1) << 1), IPOD_I2C_CTRL);
|
||||
I2C_CTRL = (I2C_CTRL & ~0x26) | ((len-1) << 1);
|
||||
|
||||
outb(inb(IPOD_I2C_CTRL) | IPOD_I2C_SEND, IPOD_I2C_CTRL);
|
||||
I2C_CTRL |= I2C_SEND;
|
||||
|
||||
return 0x0;
|
||||
}
|
||||
|
|
@ -169,10 +151,7 @@ int pp_i2c_send(unsigned int addr, int data0, int data1)
|
|||
|
||||
void i2c_init(void)
|
||||
{
|
||||
/* From ipodlinux */
|
||||
|
||||
outl(inl(0xcf005000) | 0x2, 0xcf005000);
|
||||
|
||||
outl(inl(0xcf005030) | (1<<8), 0xcf005030);
|
||||
outl(inl(0xcf005030) & ~(1<<8), 0xcf005030);
|
||||
DEV_EN |= 0x2; /* Enable I2C-should this be DEV_I2C rather than 0x2? */
|
||||
DEV_RS |= DEV_I2C; /* Start I2C Reset */
|
||||
DEV_RS &=~DEV_I2C; /* End I2C Reset */
|
||||
}
|
||||
|
|
@ -185,9 +185,9 @@ void i2c_init(void)
|
|||
GPIOC_ENABLE &= ~0x20;
|
||||
#endif
|
||||
|
||||
DEV_EN |= DEV_I2C;
|
||||
DEV_RS |= DEV_I2C;
|
||||
DEV_RS &=~DEV_I2C;
|
||||
DEV_EN |= DEV_I2C; /* Enable I2C */
|
||||
DEV_RS |= DEV_I2C; /* Start I2C Reset */
|
||||
DEV_RS &=~DEV_I2C; /* End I2C Reset */
|
||||
|
||||
outl(0x0, 0x600060a4);
|
||||
outl(0x80 | (0 << 8), 0x600060a4);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue