From 4894a06a152fc0da99d8812958c3eb60d40de610 Mon Sep 17 00:00:00 2001 From: Christian Gmeiner Date: Sun, 31 Jul 2005 17:31:33 +0000 Subject: iAudio, iRiver: As both platforms use the same i2c interface i have renamed i2c-h100.c/h to i2c-coldfire.c/h. Also i have changed some stuff in config.h and config-xx.h. Hope everybody agrees with this patch, else we can unroll and improve it. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@7271 a1c6a512-1295-4272-9138-f99709370657 --- firmware/SOURCES | 4 +- firmware/drivers/i2c-coldfire.c | 174 ++++++++++++++++++++++++++++++++++++++ firmware/drivers/i2c-h100.c | 174 -------------------------------------- firmware/export/config-h100.h | 3 +- firmware/export/config-h120.h | 3 +- firmware/export/config-h300.h | 3 +- firmware/export/config-iaudiox5.h | 5 +- firmware/export/config.h | 3 +- firmware/export/i2c-coldfire.h | 64 ++++++++++++++ firmware/export/i2c-h100.h | 64 -------------- 10 files changed, 250 insertions(+), 247 deletions(-) create mode 100644 firmware/drivers/i2c-coldfire.c delete mode 100644 firmware/drivers/i2c-h100.c create mode 100644 firmware/export/i2c-coldfire.h delete mode 100644 firmware/export/i2c-h100.h diff --git a/firmware/SOURCES b/firmware/SOURCES index 06b4ce0765..937bb0bfb6 100644 --- a/firmware/SOURCES +++ b/firmware/SOURCES @@ -79,8 +79,8 @@ drivers/fmradio_i2c.c tuner_philips.c #endif #endif -#if CONFIG_I2C == I2C_H100 -drivers/i2c-h100.c +#if CONFIG_I2C == I2C_COLDFIRE +drivers/i2c-coldfire.c #else drivers/i2c.c #endif diff --git a/firmware/drivers/i2c-coldfire.c b/firmware/drivers/i2c-coldfire.c new file mode 100644 index 0000000000..5b4f4a1830 --- /dev/null +++ b/firmware/drivers/i2c-coldfire.c @@ -0,0 +1,174 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2005 by Andy Young + * + * 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 "debug.h" +#include "system.h" +#include "i2c-coldfire.h" + +#define I2C_DEVICE_1 ((volatile unsigned char *)&MADR) +#define I2C_DEVICE_2 ((volatile unsigned char *)&MADR2) + +/* Local functions definitions */ + +static int i2c_write_byte(int device, unsigned char data); +static int i2c_gen_start(int device); +static void i2c_gen_stop(int device); +static volatile unsigned char *i2c_get_addr(int device); + +/* Public functions */ + +void i2c_init(void) +{ +#if (CONFIG_KEYPAD == IRIVER_H100_PAD) || (CONFIG_KEYPAD == IRIVER_H300_PAD) + /* Audio Codec */ + MADR = 0x6c; /* iRiver firmware uses this addr */ + MBDR = 0; /* iRiver firmware does this */ + MBCR = IEN; /* Enable interface */ + +#if 0 + /* FM Tuner */ + MADR2 = 0x6c; + MBDR2 = 0; + MBCR2 = IEN; +#endif + +#endif +} + +void i2c_close(void) +{ + MBCR = 0; + MBCR2 = 0; +} + +/** + * Writes bytes to the selected device. + * + * Use device=1 for bus 1 at 0x40000280 + * Use device=2 for bus 2 at 0x80000440 + * + * Returns number of bytes successfully send or -1 if START failed + */ +int i2c_write(int device, unsigned char *buf, int count) +{ + int i; + int rc; + + rc = i2c_gen_start(device); + if (rc < 0) + { + DEBUGF("i2c: gen_start failed (d=%d)", device); + return rc*10 - 1; + } + + for (i=0; i= MAX_LOOP) + return -1; + + count = 0; + + /* Wait for interrupt flag */ + while (!(regs[O_MBSR] & IFF) && count < MAX_LOOP) + { + yield(); + count++; + } + + if (count >= MAX_LOOP) + return -2; + + regs[O_MBSR] &= ~IFF; /* Clear interrupt flag */ + + if (!(regs[O_MBSR] & ICF)) /* Check that transfer is complete */ + return -3; + + if (regs[O_MBSR] & RXAK) /* Check that the byte has been ACKed */ + return -4; + + return 0; +} + + +/* Returns 0 on success, -1 on failure */ +int i2c_gen_start(int device) +{ + volatile unsigned char *regs = i2c_get_addr(device); + long count = 0; + + /* Wait for bus to become free */ + while ((regs[O_MBSR] & IBB) && (count < MAX_LOOP)) + { + yield(); + count++; + } + + if (count >= MAX_LOOP) + return -1; + + regs[O_MBCR] |= MSTA | MTX; /* Generate START */ + + return 0; +} + +void i2c_gen_stop(int device) +{ + volatile unsigned char *regs = i2c_get_addr(device); + regs[O_MBCR] &= ~MSTA; /* Clear MSTA to generate STOP */ +} + + +volatile unsigned char *i2c_get_addr(int device) +{ + if (device == 1) + return I2C_DEVICE_1; + + return I2C_DEVICE_2; +} diff --git a/firmware/drivers/i2c-h100.c b/firmware/drivers/i2c-h100.c deleted file mode 100644 index c50cd7ed0a..0000000000 --- a/firmware/drivers/i2c-h100.c +++ /dev/null @@ -1,174 +0,0 @@ -/*************************************************************************** - * __________ __ ___. - * Open \______ \ ____ ____ | | _\_ |__ _______ ___ - * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / - * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < - * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ - * \/ \/ \/ \/ \/ - * $Id$ - * - * Copyright (C) 2005 by Andy Young - * - * 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 "debug.h" -#include "system.h" -#include "i2c-h100.h" - -#define I2C_DEVICE_1 ((volatile unsigned char *)&MADR) -#define I2C_DEVICE_2 ((volatile unsigned char *)&MADR2) - -/* Local functions definitions */ - -static int i2c_write_byte(int device, unsigned char data); -static int i2c_gen_start(int device); -static void i2c_gen_stop(int device); -static volatile unsigned char *i2c_get_addr(int device); - -/* Public functions */ - -void i2c_init(void) -{ - /* Audio Codec */ - MADR = 0x6c; /* iRiver firmware uses this addr */ - MBDR = 0; /* iRiver firmware does this */ - MBCR = IEN; /* Enable interface */ - -#if 0 - /* FM Tuner */ - MADR2 = 0x6c; - MBDR2 = 0; - MBCR2 = IEN; -#endif -} - -void i2c_close(void) -{ - MBCR = 0; - -#if 0 - MBCR2 = 0; -#endif -} - -/** - * Writes bytes to the selected device. - * - * Use device=1 for bus 1 at 0x40000280 (Audio Codec) - * Use device=2 for bus 2 at 0x80000440 (Tuner ?) - * - * Returns number of bytes successfully send or -1 if START failed - */ -int i2c_write(int device, unsigned char *buf, int count) -{ - int i; - int rc; - - rc = i2c_gen_start(device); - if (rc < 0) - { - DEBUGF("i2c: gen_start failed (d=%d)", device); - return rc*10 - 1; - } - - for (i=0; i= MAX_LOOP) - return -1; - - count = 0; - - /* Wait for interrupt flag */ - while (!(regs[O_MBSR] & IFF) && count < MAX_LOOP) - { - yield(); - count++; - } - - if (count >= MAX_LOOP) - return -2; - - regs[O_MBSR] &= ~IFF; /* Clear interrupt flag */ - - if (!(regs[O_MBSR] & ICF)) /* Check that transfer is complete */ - return -3; - - if (regs[O_MBSR] & RXAK) /* Check that the byte has been ACKed */ - return -4; - - return 0; -} - - -/* Returns 0 on success, -1 on failure */ -int i2c_gen_start(int device) -{ - volatile unsigned char *regs = i2c_get_addr(device); - long count = 0; - - /* Wait for bus to become free */ - while ((regs[O_MBSR] & IBB) && (count < MAX_LOOP)) - { - yield(); - count++; - } - - if (count >= MAX_LOOP) - return -1; - - regs[O_MBCR] |= MSTA | MTX; /* Generate START */ - - return 0; -} - -void i2c_gen_stop(int device) -{ - volatile unsigned char *regs = i2c_get_addr(device); - regs[O_MBCR] &= ~MSTA; /* Clear MSTA to generate STOP */ -} - - -volatile unsigned char *i2c_get_addr(int device) -{ - if (device == 1) - return I2C_DEVICE_1; - - return I2C_DEVICE_2; -} diff --git a/firmware/export/config-h100.h b/firmware/export/config-h100.h index e33b985509..6bd94a2f95 100644 --- a/firmware/export/config-h100.h +++ b/firmware/export/config-h100.h @@ -52,7 +52,8 @@ /* Define this if you have a Motorola SCF5249 */ #define CONFIG_CPU MCF5249 -#define CONFIG_I2C I2C_H100 +/* Define this if you want to use coldfire's i2c interface */ +#define CONFIG_I2C I2C_COLDFIRE #define HAVE_UDA1380 diff --git a/firmware/export/config-h120.h b/firmware/export/config-h120.h index 9b93eae070..2ddf821533 100644 --- a/firmware/export/config-h120.h +++ b/firmware/export/config-h120.h @@ -48,7 +48,8 @@ /* Define this if you have a Motorola SCF5249 */ #define CONFIG_CPU MCF5249 -#define CONFIG_I2C I2C_H100 +/* Define this if you want to use coldfire's i2c interface */ +#define CONFIG_I2C I2C_COLDFIRE #define HAVE_UDA1380 diff --git a/firmware/export/config-h300.h b/firmware/export/config-h300.h index be6511cb2f..251b6912b3 100644 --- a/firmware/export/config-h300.h +++ b/firmware/export/config-h300.h @@ -44,7 +44,8 @@ /* Define this if you have a Motorola SCF5249 */ #define CONFIG_CPU MCF5249 -#define CONFIG_I2C I2C_H100 +/* Define this if you want to use coldfire's i2c interface */ +#define CONFIG_I2C I2C_COLDFIRE #define HAVE_UDA1380 diff --git a/firmware/export/config-iaudiox5.h b/firmware/export/config-iaudiox5.h index 7cdc861435..e2a170af66 100644 --- a/firmware/export/config-iaudiox5.h +++ b/firmware/export/config-iaudiox5.h @@ -42,10 +42,11 @@ #ifndef SIMULATOR -/* Define this if you have a Motorola SCF5249 */ +/* Define this if you have a Motorola SCF5250 */ #define CONFIG_CPU MCF5250 -#define CONFIG_I2C I2C_IAUDIO +/* Define this if you want to use coldfire's i2c interface */ +#define CONFIG_I2C I2C_COLDFIRE #define HAVE_TLV320 diff --git a/firmware/export/config.h b/firmware/export/config.h index 6b77f0dfc1..16e235d1ba 100644 --- a/firmware/export/config.h +++ b/firmware/export/config.h @@ -81,8 +81,7 @@ #define I2C_PLAYREC 0 /* Archos Player/Recorder style */ #define I2C_ONDIO 1 /* Ondio style */ #define I2C_GMINI 2 /* Gmini style */ -#define I2C_H100 3 /* iRiver h100 style */ -#define I2C_IAUDIO 4 /* iAuido style */ +#define I2C_COLDFIRE 3 /* Coldfire style */ /* CONFIG_LED */ #define LED_REAL 1 /* SW controlled LED (Archos recorders, player, Gmini) */ diff --git a/firmware/export/i2c-coldfire.h b/firmware/export/i2c-coldfire.h new file mode 100644 index 0000000000..d4a5781116 --- /dev/null +++ b/firmware/export/i2c-coldfire.h @@ -0,0 +1,64 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2002 by Linus Nielsen Feltzing + * + * 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. + * + ****************************************************************************/ + +/* + * Driver for MCF52xx's I2C interface + * 2005-02-17 hubble@mochine.com + * + */ + +#ifndef _I2C_COLDFIRE_H +#define _I2C_COLDFIRE_H + +void i2c_init(void); +int i2c_write(int device, unsigned char *buf, int count); +void i2c_close(void); + + +#define MAX_LOOP 0x100 /* TODO: select a better value */ + +/* PLLCR control */ +#define QSPISEL (1 << 11) /* Selects QSPI or I2C interface */ + +/* Offsets to I2C registers from base address */ +#define O_MADR 0x00 /* Slave Address */ +#define O_MFDR 0x04 /* Frequency divider */ +#define O_MBCR 0x08 /* Control register */ +#define O_MBSR 0x0c /* Status register */ +#define O_MBDR 0x10 /* Data register */ + +/* MBSR - Status register */ +#define ICF (1 << 7) /* Transfer Complete */ +#define IAAS (1 << 6) /* Addressed As Alave */ +#define IBB (1 << 5) /* Bus Busy */ +#define IAL (1 << 4) /* Arbitration Lost */ +#define SRW (1 << 2) /* Slave R/W */ +#define IFF (1 << 1) /* I2C Interrupt */ +#define RXAK (1 << 0) /* No Ack bit */ + +/* MBCR - Control register */ +#define IEN (1 << 7) /* I2C Enable */ +#define IIEN (1 << 6) /* Interrupt Enable */ +#define MSTA (1 << 5) /* Master/Slave select */ +#define MTX (1 << 4) /* Transmit/Receive */ +#define TXAK (1 << 3) /* Transfer ACK */ +#define RSTA (1 << 2) /* Restart.. */ + + +#endif diff --git a/firmware/export/i2c-h100.h b/firmware/export/i2c-h100.h deleted file mode 100644 index 5647b502db..0000000000 --- a/firmware/export/i2c-h100.h +++ /dev/null @@ -1,64 +0,0 @@ -/*************************************************************************** - * __________ __ ___. - * Open \______ \ ____ ____ | | _\_ |__ _______ ___ - * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / - * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < - * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ - * \/ \/ \/ \/ \/ - * $Id$ - * - * Copyright (C) 2002 by Linus Nielsen Feltzing - * - * 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. - * - ****************************************************************************/ - -/* - * Driver for MCF5249's I2C interface - * 2005-02-17 hubble@mochine.com - * - */ - -#ifndef _I2C_H100_H -#define _I2C_H100_H - -void i2c_init(void); -int i2c_write(int device, unsigned char *buf, int count); -void i2c_close(void); - - -#define MAX_LOOP 0x100 /* TODO: select a better value */ - -/* PLLCR control */ -#define QSPISEL (1 << 11) /* Selects QSPI or I2C interface */ - -/* Offsets to I2C registers from base address */ -#define O_MADR 0x00 /* Slave Address */ -#define O_MFDR 0x04 /* Frequency divider */ -#define O_MBCR 0x08 /* Control register */ -#define O_MBSR 0x0c /* Status register */ -#define O_MBDR 0x10 /* Data register */ - -/* MBSR - Status register */ -#define ICF (1 << 7) /* Transfer Complete */ -#define IAAS (1 << 6) /* Addressed As Alave */ -#define IBB (1 << 5) /* Bus Busy */ -#define IAL (1 << 4) /* Arbitration Lost */ -#define SRW (1 << 2) /* Slave R/W */ -#define IFF (1 << 1) /* I2C Interrupt */ -#define RXAK (1 << 0) /* No Ack bit */ - -/* MBCR - Control register */ -#define IEN (1 << 7) /* I2C Enable */ -#define IIEN (1 << 6) /* Interrupt Enable */ -#define MSTA (1 << 5) /* Master/Slave select */ -#define MTX (1 << 4) /* Transmit/Receive */ -#define TXAK (1 << 3) /* Transfer ACK */ -#define RSTA (1 << 2) /* Restart.. */ - - -#endif -- cgit v1.2.3