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