2005-11-07 23:07:19 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
* $Id$
|
|
|
|
*
|
2005-12-19 14:30:52 +00:00
|
|
|
* PP5020 I2C driver
|
|
|
|
*
|
|
|
|
* Based on code from the ipodlinux project - http://ipodlinux.org/
|
|
|
|
* Adapted for Rockbox in November 2005
|
|
|
|
*
|
|
|
|
* Original file: linux/arch/armnommu/mach-ipod/hardware.c
|
|
|
|
*
|
|
|
|
* Copyright (c) 2003-2005 Bernard Leach (leachbj@bouncycastle.org)
|
2005-11-07 23:07:19 +00:00
|
|
|
*
|
|
|
|
* 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-pp5020.h"
|
|
|
|
|
|
|
|
/* Local functions definitions */
|
|
|
|
|
|
|
|
#define IPOD_I2C_BASE 0x7000c000
|
|
|
|
#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)
|
|
|
|
|
2005-12-11 10:52:17 +00:00
|
|
|
static int ipod_i2c_wait_not_busy(void)
|
2005-11-07 23:07:19 +00:00
|
|
|
{
|
2005-11-11 17:51:35 +00:00
|
|
|
unsigned long timeout;
|
2005-12-11 10:52:17 +00:00
|
|
|
timeout = current_tick + POLL_TIMEOUT;
|
|
|
|
while (TIME_BEFORE(current_tick, timeout)) {
|
2005-11-07 23:07:19 +00:00
|
|
|
if (!(inb(IPOD_I2C_STATUS) & IPOD_I2C_BUSY)) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-12-11 10:52:17 +00:00
|
|
|
return -1;
|
2005-11-07 23:07:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Public functions */
|
|
|
|
|
2005-12-11 10:52:17 +00:00
|
|
|
int ipod_i2c_read_byte(unsigned int addr, unsigned int *data)
|
2005-11-07 23:07:19 +00:00
|
|
|
{
|
2005-12-11 10:52:17 +00:00
|
|
|
if (ipod_i2c_wait_not_busy() < 0)
|
|
|
|
{
|
|
|
|
return -1;
|
|
|
|
}
|
2005-11-07 23:07:19 +00:00
|
|
|
|
2005-12-11 10:52:17 +00:00
|
|
|
/* clear top 15 bits, left shift 1, or in 0x1 for a read */
|
|
|
|
outb(((addr << 17) >> 16) | 0x1, IPOD_I2C_ADDR);
|
2005-11-07 23:07:19 +00:00
|
|
|
|
2005-12-11 10:52:17 +00:00
|
|
|
outb(inb(IPOD_I2C_CTRL) | 0x20, IPOD_I2C_CTRL);
|
2005-11-07 23:07:19 +00:00
|
|
|
|
2005-12-11 10:52:17 +00:00
|
|
|
outb(inb(IPOD_I2C_CTRL) | IPOD_I2C_SEND, IPOD_I2C_CTRL);
|
2005-11-07 23:07:19 +00:00
|
|
|
|
2005-12-11 10:52:17 +00:00
|
|
|
if (ipod_i2c_wait_not_busy() < 0)
|
|
|
|
{
|
|
|
|
return -1;
|
|
|
|
}
|
2005-11-07 23:07:19 +00:00
|
|
|
|
2005-12-11 10:52:17 +00:00
|
|
|
if (data)
|
|
|
|
{
|
|
|
|
*data = inb(IPOD_I2C_DATA0);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2005-11-07 23:07:19 +00:00
|
|
|
}
|
|
|
|
|
2005-12-11 10:52:17 +00:00
|
|
|
int ipod_i2c_send_bytes(unsigned int addr, unsigned int len, unsigned char *data)
|
2005-11-07 23:07:19 +00:00
|
|
|
{
|
2005-12-11 10:52:17 +00:00
|
|
|
int data_addr;
|
|
|
|
unsigned int i;
|
2005-11-07 23:07:19 +00:00
|
|
|
|
2005-12-11 10:52:17 +00:00
|
|
|
if (len < 1 || len > 4)
|
|
|
|
{
|
|
|
|
return -1;
|
|
|
|
}
|
2005-11-07 23:07:19 +00:00
|
|
|
|
2005-12-11 10:52:17 +00:00
|
|
|
if (ipod_i2c_wait_not_busy() < 0)
|
|
|
|
{
|
|
|
|
return -2;
|
|
|
|
}
|
2005-11-07 23:07:19 +00:00
|
|
|
|
2005-12-11 10:52:17 +00:00
|
|
|
/* clear top 15 bits, left shift 1 */
|
|
|
|
outb((addr << 17) >> 16, IPOD_I2C_ADDR);
|
2005-11-07 23:07:19 +00:00
|
|
|
|
2005-12-11 10:52:17 +00:00
|
|
|
outb(inb(IPOD_I2C_CTRL) & ~0x20, IPOD_I2C_CTRL);
|
2005-11-07 23:07:19 +00:00
|
|
|
|
2005-12-11 10:52:17 +00:00
|
|
|
data_addr = IPOD_I2C_DATA0;
|
|
|
|
for ( i = 0; i < len; i++ )
|
|
|
|
{
|
|
|
|
outb(*data++, data_addr);
|
|
|
|
data_addr += 4;
|
|
|
|
}
|
2005-11-07 23:07:19 +00:00
|
|
|
|
2005-12-11 10:52:17 +00:00
|
|
|
outb((inb(IPOD_I2C_CTRL) & ~0x26) | ((len-1) << 1), IPOD_I2C_CTRL);
|
2005-11-07 23:07:19 +00:00
|
|
|
|
2005-12-11 10:52:17 +00:00
|
|
|
outb(inb(IPOD_I2C_CTRL) | IPOD_I2C_SEND, IPOD_I2C_CTRL);
|
2005-11-07 23:07:19 +00:00
|
|
|
|
2005-12-11 10:52:17 +00:00
|
|
|
return 0x0;
|
2005-11-07 23:07:19 +00:00
|
|
|
}
|
|
|
|
|
2005-12-11 10:52:17 +00:00
|
|
|
int ipod_i2c_send_byte(unsigned int addr, int data0)
|
2005-11-07 23:07:19 +00:00
|
|
|
{
|
2005-12-11 10:52:17 +00:00
|
|
|
unsigned char data[1];
|
2005-11-07 23:07:19 +00:00
|
|
|
|
2005-12-11 10:52:17 +00:00
|
|
|
data[0] = data0;
|
2005-11-07 23:07:19 +00:00
|
|
|
|
2005-12-11 10:52:17 +00:00
|
|
|
return ipod_i2c_send_bytes(addr, 1, data);
|
|
|
|
}
|
2005-11-07 23:07:19 +00:00
|
|
|
|
|
|
|
|
2005-12-11 10:52:17 +00:00
|
|
|
int i2c_readbyte(unsigned int dev_addr, int addr)
|
|
|
|
{
|
|
|
|
int data;
|
2005-11-07 23:07:19 +00:00
|
|
|
|
2005-12-11 10:52:17 +00:00
|
|
|
ipod_i2c_send_byte(dev_addr, addr);
|
|
|
|
ipod_i2c_read_byte(dev_addr, &data);
|
2005-11-07 23:07:19 +00:00
|
|
|
|
2005-12-11 10:52:17 +00:00
|
|
|
return data;
|
2005-11-07 23:07:19 +00:00
|
|
|
}
|
|
|
|
|
2005-12-11 10:52:17 +00:00
|
|
|
int ipod_i2c_send(unsigned int addr, int data0, int data1)
|
2005-11-07 23:07:19 +00:00
|
|
|
{
|
2005-12-11 10:52:17 +00:00
|
|
|
unsigned char data[2];
|
2005-11-07 23:07:19 +00:00
|
|
|
|
2005-12-11 10:52:17 +00:00
|
|
|
data[0] = data0;
|
|
|
|
data[1] = data1;
|
2005-11-07 23:07:19 +00:00
|
|
|
|
2005-12-11 10:52:17 +00:00
|
|
|
return ipod_i2c_send_bytes(addr, 2, data);
|
|
|
|
}
|
2005-11-07 23:07:19 +00:00
|
|
|
|
2005-12-11 10:52:17 +00:00
|
|
|
void i2c_init(void)
|
2005-11-07 23:07:19 +00:00
|
|
|
{
|
2005-12-11 10:52:17 +00:00
|
|
|
/* From ipodlinux */
|
2005-11-07 23:07:19 +00:00
|
|
|
|
2006-02-27 12:35:05 +00:00
|
|
|
#if defined(APPLE_IPODMINI)
|
|
|
|
/* GPIO port C disable port 0x10 */
|
|
|
|
GPIOC_ENABLE &= ~0x10;
|
|
|
|
|
|
|
|
/* GPIO port C disable port 0x20 */
|
|
|
|
GPIOC_ENABLE &= ~0x20;
|
|
|
|
#endif
|
|
|
|
|
2005-12-11 10:52:17 +00:00
|
|
|
outl(inl(0x6000600c) | 0x1000, 0x6000600c); /* enable 12 */
|
|
|
|
outl(inl(0x60006004) | 0x1000, 0x60006004); /* start reset 12 */
|
|
|
|
outl(inl(0x60006004) & ~0x1000, 0x60006004); /* end reset 12 */
|
2005-11-07 23:07:19 +00:00
|
|
|
|
2005-12-11 10:52:17 +00:00
|
|
|
outl(0x0, 0x600060a4);
|
|
|
|
outl(0x80 | (0 << 8), 0x600060a4);
|
2005-11-07 23:07:19 +00:00
|
|
|
|
2005-12-11 10:52:17 +00:00
|
|
|
i2c_readbyte(0x8, 0);
|
2005-11-07 23:07:19 +00:00
|
|
|
}
|