diff options
author | Daniel Ankers <dan@weirdo.org.uk> | 2007-01-27 17:17:52 +0000 |
---|---|---|
committer | Daniel Ankers <dan@weirdo.org.uk> | 2007-01-27 17:17:52 +0000 |
commit | e9a2caee2bbd363058ed707acbe2df613c94c0e8 (patch) | |
tree | ff5618e2af879ddd588d90251130a172b373f879 | |
parent | 369b6bd367d96e0c4a13c1f8c14830091737e84f (diff) |
Unify I2C driver for all PortalPlayer targets
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@12126 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r-- | firmware/SOURCES | 6 | ||||
-rw-r--r-- | firmware/target/arm/i2c-pp.c (renamed from firmware/target/arm/i2c-pp5020.c) | 12 | ||||
-rw-r--r-- | firmware/target/arm/i2c-pp5002.c | 157 |
3 files changed, 13 insertions, 162 deletions
diff --git a/firmware/SOURCES b/firmware/SOURCES index 00fbc74b67..4a1aa3f244 100644 --- a/firmware/SOURCES +++ b/firmware/SOURCES @@ -254,10 +254,8 @@ common/strlen.c #ifndef SIMULATOR target/arm/memset-arm.S target/arm/memset16-arm.S -#if CONFIG_I2C == I2C_PP5020 -target/arm/i2c-pp5020.c -#elif CONFIG_I2C == I2C_PP5002 -target/arm/i2c-pp5002.c +#if CONFIG_I2C == I2C_PP5020 || CONFIG_I2C == I2C_PP5002 +target/arm/i2c-pp.c #elif CONFIG_I2C == I2C_PNX0101 drivers/i2c-pnx0101.c #elif CONFIG_I2C == I2C_S3C2440 diff --git a/firmware/target/arm/i2c-pp5020.c b/firmware/target/arm/i2c-pp.c index ebd0318f0b..0c8aec8f4b 100644 --- a/firmware/target/arm/i2c-pp5020.c +++ b/firmware/target/arm/i2c-pp.c @@ -7,7 +7,7 @@ * \/ \/ \/ \/ \/ * $Id$ * - * PP5020 I2C driver + * PP502X and PP5002 I2C driver * * Based on code from the ipodlinux project - http://ipodlinux.org/ * Adapted for Rockbox in November 2005 @@ -28,7 +28,11 @@ #include "kernel.h" #include "logf.h" #include "system.h" +#if CONFIG_I2C == I2C_PP5002 +#include "i2c-pp5002.h" +#else #include "i2c-pp5020.h" +#endif /* Local functions definitions */ @@ -185,12 +189,18 @@ void i2c_init(void) GPIOC_ENABLE &= ~0x20; #endif +#if CONFIG_I2C == I2C_PP5002 + DEV_EN |= 0x2; +#else DEV_EN |= DEV_I2C; /* Enable I2C */ +#endif DEV_RS |= DEV_I2C; /* Start I2C Reset */ DEV_RS &=~DEV_I2C; /* End I2C Reset */ +#if CONFIG_I2C == I2C_PP5020 outl(0x0, 0x600060a4); outl(0x80 | (0 << 8), 0x600060a4); +#endif mutex_init(&i2c_mutex); diff --git a/firmware/target/arm/i2c-pp5002.c b/firmware/target/arm/i2c-pp5002.c deleted file mode 100644 index ad6d50721d..0000000000 --- a/firmware/target/arm/i2c-pp5002.c +++ /dev/null @@ -1,157 +0,0 @@ -/*************************************************************************** - * __________ __ ___. - * Open \______ \ ____ ____ | | _\_ |__ _______ ___ - * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / - * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < - * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ - * \/ \/ \/ \/ \/ - * $Id$ - * - * PP5002 I2C driver - * - * Based on code from the ipodlinux project - http://ipodlinux.org/ - * Adapted for Rockbox in January 2006 - * - * Original file: linux/arch/armnommu/mach-ipod/hardware.c - * - * Copyright (c) 2003-2005 Bernard Leach (leachbj@bouncycastle.org) - * - * All files in this archive are subject to the GNU General Public License. - * See the file COPYING in the source tree root for full license agreement. - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY - * KIND, either express or implied. - * - ****************************************************************************/ - -#include "cpu.h" -#include "kernel.h" -#include "logf.h" -#include "system.h" -#include "i2c-pp5002.h" - -/* Local functions definitions */ - -#define POLL_TIMEOUT (HZ) - -static int pp_i2c_wait_not_busy(void) -{ - unsigned long timeout; - timeout = current_tick + POLL_TIMEOUT; - while (TIME_BEFORE(current_tick, timeout)) { - if (!(I2C_STATUS & I2C_BUSY)) { - return 0; - } - yield(); - } - - return -1; -} - - -/* Public functions */ - -int pp_i2c_read_byte(unsigned int addr, unsigned int *data) -{ - if (pp_i2c_wait_not_busy() < 0) - { - return -1; - } - - /* clear top 15 bits, left shift 1, or in 0x1 for a read */ - I2C_ADDR = ((addr << 17) >> 16) | 0x1 ; - - I2C_CTRL |= 0x20; - - I2C_CTRL |= I2C_SEND; - - if (pp_i2c_wait_not_busy() < 0) - { - return -1; - } - - if (data) - { - *data = I2C_DATA(0); - } - - return 0; -} - -int pp_i2c_send_bytes(unsigned int addr, unsigned int len, unsigned char *data) -{ - unsigned int i; - - if (len < 1 || len > 4) - { - return -1; - } - - if (pp_i2c_wait_not_busy() < 0) - { - return -2; - } - - /* clear top 15 bits, left shift 1 */ - I2C_ADDR = (addr << 17) >> 16; - - I2C_CTRL &= ~0x20; - - for ( i = 0; i < len; i++ ) - { - I2C_DATA(i) = *data++; - } - - I2C_CTRL = (I2C_CTRL & ~0x26) | ((len-1) << 1); - - I2C_CTRL |= I2C_SEND; - - return 0x0; -} - -int pp_i2c_send_byte(unsigned int addr, int data0) -{ - unsigned char data[1]; - - data[0] = data0; - - return pp_i2c_send_bytes(addr, 1, data); -} - -int i2c_readbytes(unsigned int dev_addr, int addr, int len, unsigned char *data) { - unsigned int temp; - int i; - pp_i2c_send_byte(dev_addr, addr); - for (i = 0; i < len; i++) { - pp_i2c_read_byte(dev_addr, &temp); - data[i] = temp; - } - return i; -} - -int i2c_readbyte(unsigned int dev_addr, int addr) -{ - int data; - - pp_i2c_send_byte(dev_addr, addr); - pp_i2c_read_byte(dev_addr, &data); - - return data; -} - -int pp_i2c_send(unsigned int addr, int data0, int data1) -{ - unsigned char data[2]; - - data[0] = data0; - data[1] = data1; - - return pp_i2c_send_bytes(addr, 2, data); -} - -void i2c_init(void) -{ - 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 */ -} |