2005-03-18 11:34:26 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
* Copyright (C) 2002 by Linus Nielsen Feltzing
|
|
|
|
*
|
2008-06-28 18:10:04 +00:00
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
2005-03-18 11:34:26 +00:00
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/*
|
2005-07-31 17:31:33 +00:00
|
|
|
* Driver for MCF52xx's I2C interface
|
2005-03-18 11:34:26 +00:00
|
|
|
* 2005-02-17 hubble@mochine.com
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2005-07-31 17:31:33 +00:00
|
|
|
#ifndef _I2C_COLDFIRE_H
|
|
|
|
#define _I2C_COLDFIRE_H
|
2005-03-18 11:34:26 +00:00
|
|
|
|
2006-07-21 08:42:28 +00:00
|
|
|
#include "cpu.h"
|
|
|
|
|
2005-03-18 11:34:26 +00:00
|
|
|
void i2c_init(void);
|
2006-07-21 08:42:28 +00:00
|
|
|
int i2c_read (volatile unsigned char *iface, unsigned char addr,
|
|
|
|
unsigned char *buf, int count);
|
|
|
|
int i2c_write(volatile unsigned char *iface, unsigned char addr,
|
|
|
|
const unsigned char *buf, int count);
|
2005-03-18 11:34:26 +00:00
|
|
|
void i2c_close(void);
|
2006-07-21 08:42:28 +00:00
|
|
|
void i2c_adjust_prescale(int multiplier);
|
2005-03-18 11:34:26 +00:00
|
|
|
|
2006-07-21 08:42:28 +00:00
|
|
|
#define I2C_IFACE_0 ((volatile unsigned char *)&MADR)
|
|
|
|
#define I2C_IFACE_1 ((volatile unsigned char *)&MADR2)
|
2005-03-18 11:34:26 +00:00
|
|
|
|
2005-06-14 14:36:46 +00:00
|
|
|
#define MAX_LOOP 0x100 /* TODO: select a better value */
|
2005-03-18 11:34:26 +00:00
|
|
|
|
|
|
|
/* PLLCR control */
|
2010-01-03 10:27:43 +00:00
|
|
|
#define QSPISEL (1 << 11) /* Selects QSPI or I2C interface */
|
2005-03-18 11:34:26 +00:00
|
|
|
|
|
|
|
/* Offsets to I2C registers from base address */
|
2010-01-03 10:27:43 +00:00
|
|
|
#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 */
|
2005-03-18 11:34:26 +00:00
|
|
|
|
|
|
|
/* MBSR - Status register */
|
2010-01-03 10:27:43 +00:00
|
|
|
#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 IIF (1 << 1) /* I2C Interrupt */
|
|
|
|
#define RXAK (1 << 0) /* No Ack bit */
|
2005-03-18 11:34:26 +00:00
|
|
|
|
|
|
|
/* MBCR - Control register */
|
2010-01-03 10:27:43 +00:00
|
|
|
#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.. */
|
2005-03-18 11:34:26 +00:00
|
|
|
|
|
|
|
|
|
|
|
#endif
|