Home | History | Annotate | Line # | Download | only in i2c
motoi2creg.h revision 1.2.8.2
      1  1.2.8.2  rmind /* $NetBSD: motoi2creg.h,v 1.2.8.2 2011/03/05 20:53:10 rmind Exp $ */
      2  1.2.8.2  rmind 
      3  1.2.8.2  rmind /*-
      4  1.2.8.2  rmind  * Copyright (c) 2007, 2010 The NetBSD Foundation, Inc.
      5  1.2.8.2  rmind  * All rights reserved.
      6  1.2.8.2  rmind  *
      7  1.2.8.2  rmind  * This code is derived from software contributed to The NetBSD Foundation
      8  1.2.8.2  rmind  * by Matt Thomas.
      9  1.2.8.2  rmind  *
     10  1.2.8.2  rmind  * Redistribution and use in source and binary forms, with or without
     11  1.2.8.2  rmind  * modification, are permitted provided that the following conditions
     12  1.2.8.2  rmind  * are met:
     13  1.2.8.2  rmind  * 1. Redistributions of source code must retain the above copyright
     14  1.2.8.2  rmind  *    notice, this list of conditions and the following disclaimer.
     15  1.2.8.2  rmind  * 2. Redistributions in binary form must reproduce the above copyright
     16  1.2.8.2  rmind  *    notice, this list of conditions and the following disclaimer in the
     17  1.2.8.2  rmind  *    documentation and/or other materials provided with the distribution.
     18  1.2.8.2  rmind  *
     19  1.2.8.2  rmind  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20  1.2.8.2  rmind  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21  1.2.8.2  rmind  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22  1.2.8.2  rmind  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23  1.2.8.2  rmind  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24  1.2.8.2  rmind  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25  1.2.8.2  rmind  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26  1.2.8.2  rmind  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27  1.2.8.2  rmind  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28  1.2.8.2  rmind  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29  1.2.8.2  rmind  * POSSIBILITY OF SUCH DAMAGE.
     30  1.2.8.2  rmind  */
     31  1.2.8.2  rmind 
     32  1.2.8.2  rmind #ifndef _DEV_I2C_MOTOI2CREG_H_
     33  1.2.8.2  rmind #define _DEV_I2C_MOTOI2CREG_H_
     34  1.2.8.2  rmind 
     35  1.2.8.2  rmind /*
     36  1.2.8.2  rmind  * This I2C controller is a common design used on many Motorola/Freescale
     37  1.2.8.2  rmind  * chip like the i.MX/MC9328, MPC8548, etc.  Different names in bit field
     38  1.2.8.2  rmind  * definition and not suffered from document error.
     39  1.2.8.2  rmind  */
     40  1.2.8.2  rmind #define I2CADR	0x0000	/* my own I2C addr to respond for an external master */
     41  1.2.8.2  rmind #define I2CFDR	0x0004	/* frequency devider */
     42  1.2.8.2  rmind #define I2CCR	0x0008	/* control */
     43  1.2.8.2  rmind #define	 CR_MEN   0x80	/* enable this HW */
     44  1.2.8.2  rmind #define	 CR_MIEN  0x40	/* enable interrupt */
     45  1.2.8.2  rmind #define	 CR_MSTA  0x20	/* 0->1 activates START, 1->0 makes STOP condition */
     46  1.2.8.2  rmind #define	 CR_MTX   0x10	/* 1 for Tx, 0 for Rx */
     47  1.2.8.2  rmind #define	 CR_TXAK  0x08	/* 1 makes no acknowledge when Rx */
     48  1.2.8.2  rmind #define	 CR_RSTA  0x04	/* generate repeated START condition */
     49  1.2.8.2  rmind #define I2CSR	0x000c	/* status */
     50  1.2.8.2  rmind #define	 SR_MCF   0x80	/* 0 means transfer in progress, 1 when completed */
     51  1.2.8.2  rmind #define	 SR_MAAS  0x40	/* 1 means addressed as slave */
     52  1.2.8.2  rmind #define	 SR_MBB   0x20	/* 1 before STOP condition is detected */
     53  1.2.8.2  rmind #define	 SR_MAL   0x10	/* arbitration was lost */
     54  1.2.8.2  rmind #define	 SR_MIF   0x02	/* indicates data transter completion */
     55  1.2.8.2  rmind #define	 SR_RXAK  0x01	/* 1 to indicate receive has completed */
     56  1.2.8.2  rmind #define I2CDR	0x0010	/* data */
     57  1.2.8.2  rmind #define	I2CDFSRR 0x0014	/* digital filter sampling rate register */
     58  1.2.8.2  rmind 
     59  1.2.8.2  rmind /*
     60  1.2.8.2  rmind  * The equation to calculate the divider frequency (from AN2919) is:
     61  1.2.8.2  rmind  *
     62  1.2.8.2  rmind  * Frequency divider = B * (A + (floor(3 * C / B) * 2))
     63  1.2.8.2  rmind  *
     64  1.2.8.2  rmind  * where (in little endian bit order, msb to lsb) FDR is split into 2 3-bit
     65  1.2.8.2  rmind  * fields: fA contains bits 5,1,0 and fB contains bits 4,3,2.
     66  1.2.8.2  rmind  *
     67  1.2.8.2  rmind  * A is used as an index into { 9, 10, 12, 15, 5, 6, 7, 8 } though
     68  1.2.8.2  rmind  * on faster machines these are doubled to { 18, 20, 24, 50, 10, 12, 14, 16 }.
     69  1.2.8.2  rmind  * B is either 2**(b + 1) or 2**(b + 4).
     70  1.2.8.2  rmind  *
     71  1.2.8.2  rmind  * C is the sampling rate, which may be settable via I2CDFSRR register though
     72  1.2.8.2  rmind  * not all implementations have it.  Regardless, we just leave it at its
     73  1.2.8.2  rmind  * default setting (16).  So floor(3 * C / B) * 2 becomes a precomputable
     74  1.2.8.2  rmind  * quantity.  Once we know its value for fB=0, we can simply shift it right
     75  1.2.8.2  rmind  * as fB increases since B is a power-of-2.
     76  1.2.8.2  rmind  */
     77  1.2.8.2  rmind 
     78  1.2.8.2  rmind #define FDR_A(n)		(((n) & 0x20) >> 3) | ((n) & 3))
     79  1.2.8.2  rmind #define FDR_B(n)		(((n) & 0x1c) >> 2)
     80  1.2.8.2  rmind 
     81  1.2.8.2  rmind #define	MOTOI2C_GROUP_A_VALUES	0x8765fca9U
     82  1.2.8.2  rmind #define	MOTOI2C_A(a)		((MOTOI2C_GROUP_A_VALUE >> (4*(fdr_a))) & 0xf)
     83  1.2.8.2  rmind #define	MOTOI2C_B(b)		(1 + (fdr_b))
     84  1.2.8.2  rmind #define	MOTOI2C_DIV(name, fdr)	\
     85  1.2.8.2  rmind 	((name##_A(FDR_A(hdr)) + named##_C(FDR_B(fdr))) << name##_B(FDR_B(hdr)))
     86  1.2.8.2  rmind 
     87  1.2.8.2  rmind #define	IMX31_A(fdr_a)		MOTOI2C_A(fdr_a)
     88  1.2.8.2  rmind #define	IMX31_B(fdr_b)		MOTOI2C_B(fdr_b)
     89  1.2.8.2  rmind #define IMX31_C(fdr_b)		(6 >> (fdr_b))
     90  1.2.8.2  rmind #define	IMX31_DIV(fdr)		MOTOI2C_DIV(IMX31, fdr)
     91  1.2.8.2  rmind 
     92  1.2.8.2  rmind #define	MCF52259_A(fdr_a)	MOTOI2C_A(fdr_a)
     93  1.2.8.2  rmind #define	MCF52259_B(fdr_b)	MOTOI2C_B(fdr_b)
     94  1.2.8.2  rmind #define MCF52259_C(fdr_b)	(5 >> (fdr_b))
     95  1.2.8.2  rmind #define	MCF52259_DIV(fdr)	MOTOI2C_DIV(MCF52259, fdr)
     96  1.2.8.2  rmind 
     97  1.2.8.2  rmind #define	MPC85xx_A(fdr_a)	(MOTOI2C_A(fdr_a) << 1)
     98  1.2.8.2  rmind #define	MPC85xx_B(fdr_b)	(4 + (fdr_b))
     99  1.2.8.2  rmind #define	MPC85xx_C(fdr_b)	((6 >> (fdr_b)) & ~1)
    100  1.2.8.2  rmind #define	MPC85xx_DIV(fdr)	MOTOI2C_DIV(MPC85xx, fdr)
    101  1.2.8.2  rmind 
    102  1.2.8.2  rmind #endif /* !_DEV_I2C_MOTOI2CREG_H_ */
    103