blob: e5b34ddea6eaae96edfbd37f7d12349163bf72c6 [file] [log] [blame]
Linus Nielsen Feltzinga3176e42005-03-18 11:34:26 +00001/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2002 by Linus Nielsen Feltzing
11 *
Daniel Stenberg2acc0ac2008-06-28 18:10:04 +000012 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
Linus Nielsen Feltzinga3176e42005-03-18 11:34:26 +000016 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21
22/*
Christian Gmeiner4894a062005-07-31 17:31:33 +000023 * Driver for MCF52xx's I2C interface
Linus Nielsen Feltzinga3176e42005-03-18 11:34:26 +000024 * 2005-02-17 hubble@mochine.com
25 *
26 */
27
Christian Gmeiner4894a062005-07-31 17:31:33 +000028#ifndef _I2C_COLDFIRE_H
29#define _I2C_COLDFIRE_H
Linus Nielsen Feltzinga3176e42005-03-18 11:34:26 +000030
Linus Nielsen Feltzinged4d7a32006-07-21 08:42:28 +000031#include "cpu.h"
Linus Nielsen Feltzinga3176e42005-03-18 11:34:26 +000032
Linus Nielsen Feltzinged4d7a32006-07-21 08:42:28 +000033void i2c_init(void);
34int i2c_read (volatile unsigned char *iface, unsigned char addr,
35 unsigned char *buf, int count);
36int i2c_write(volatile unsigned char *iface, unsigned char addr,
37 const unsigned char *buf, int count);
38void i2c_close(void);
39void i2c_adjust_prescale(int multiplier);
40
41#define I2C_IFACE_0 ((volatile unsigned char *)&MADR)
42#define I2C_IFACE_1 ((volatile unsigned char *)&MADR2)
Linus Nielsen Feltzinga3176e42005-03-18 11:34:26 +000043
Miika Pekkarinenef72f992005-06-14 14:36:46 +000044#define MAX_LOOP 0x100 /* TODO: select a better value */
Linus Nielsen Feltzinga3176e42005-03-18 11:34:26 +000045
46/* PLLCR control */
47#define QSPISEL (1 << 11) /* Selects QSPI or I2C interface */
48
49/* Offsets to I2C registers from base address */
50#define O_MADR 0x00 /* Slave Address */
51#define O_MFDR 0x04 /* Frequency divider */
52#define O_MBCR 0x08 /* Control register */
53#define O_MBSR 0x0c /* Status register */
54#define O_MBDR 0x10 /* Data register */
55
56/* MBSR - Status register */
57#define ICF (1 << 7) /* Transfer Complete */
58#define IAAS (1 << 6) /* Addressed As Alave */
59#define IBB (1 << 5) /* Bus Busy */
60#define IAL (1 << 4) /* Arbitration Lost */
61#define SRW (1 << 2) /* Slave R/W */
Jens Arnoldeb0a7a32008-03-18 22:48:26 +000062#define IIF (1 << 1) /* I2C Interrupt */
Linus Nielsen Feltzinga3176e42005-03-18 11:34:26 +000063#define RXAK (1 << 0) /* No Ack bit */
64
65/* MBCR - Control register */
66#define IEN (1 << 7) /* I2C Enable */
67#define IIEN (1 << 6) /* Interrupt Enable */
68#define MSTA (1 << 5) /* Master/Slave select */
69#define MTX (1 << 4) /* Transmit/Receive */
70#define TXAK (1 << 3) /* Transfer ACK */
71#define RSTA (1 << 2) /* Restart.. */
72
73
74#endif