]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/arm/at91/at91_twireg.h
Properly support the GPIO_PIN_PRESET_{LOW,HIGH} options when configuring
[FreeBSD/FreeBSD.git] / sys / arm / at91 / at91_twireg.h
1 /*-
2  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
3  *
4  * Copyright (c) 2006 M. Warner Losh.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18  * ARE DISCLAIMED.  IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
19  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25  * SUCH DAMAGE.
26  */
27
28 /* $FreeBSD$ */
29
30 #ifndef ARM_AT91_AT91_TWIREG_H
31 #define ARM_AT91_AT91_TWIREG_H
32
33 #define TWI_CR          0x00            /* TWI Control Register */
34 #define TWI_MMR         0x04            /* TWI Master Mode Register */
35 #define TWI_SMR         0x08            /* TWI Master Mode Register */
36 #define TWI_IADR        0x0c            /* TWI Internal Address Register */
37 #define TWI_CWGR        0x10            /* TWI Clock Waveform Generator Reg */
38                 /*      0x14               reserved */
39                 /*      0x18               reserved */
40                 /*      0x1c               reserved */
41 #define TWI_SR          0x20            /* TWI Status Register */
42 #define TWI_IER         0x24            /* TWI Interrupt Enable Register */
43 #define TWI_IDR         0x28            /* TWI Interrupt Disable Register */
44 #define TWI_IMR         0x2c            /* TWI Interrupt Mask Register */
45 #define TWI_RHR         0x30            /* TWI Receiver Holding Register */
46 #define TWI_THR         0x34            /* TWI Transmit Holding Register */
47
48 /* TWI_CR */
49 #define TWI_CR_START    (1U << 0)       /* Send a start */
50 #define TWI_CR_STOP     (1U << 1)       /* Send a stop */
51 #define TWI_CR_MSEN     (1U << 2)       /* Master Transfer Enable */
52 #define TWI_CR_MSDIS    (1U << 3)       /* Master Transfer Disable */
53 #define TWI_CR_SVEN     (1U << 4)       /* Slave Transfer Enable */
54 #define TWI_CR_SVDIS    (1U << 5)       /* Slave Transfer Disable */
55 #define TWI_CR_SWRST    (1U << 7)       /* Software Reset */
56
57 /* TWI_MMR */
58 /* TWI_SMR */
59 #define TWI_MMR_IADRSZ(n) ((n) << 8)    /* Set size of transfer */
60 #define TWI_MMR_MWRITE  0U              /* Master Read Direction */
61 #define TWI_MMR_MREAD   (1U << 12)      /* Master Read Direction */
62 #define TWI_MMR_DADR(n) ((n) << 15)     /* Device Address */
63
64 /* TWI_CWGR */
65 #define TWI_CWGR_CKDIV(x) ((x) << 16)   /* Clock Divider */
66 #define TWI_CWGR_CHDIV(x) ((x) << 8)    /* Clock High Divider */
67 #define TWI_CWGR_CLDIV(x) ((x) << 0)    /* Clock Low Divider */
68 #define TWI_CWGR_DIV(rate)                              \
69         (at91_is_sam9() || at91_is_sam9xe() ?           \
70             ((at91_master_clock / (4 * (rate))) - 3) :  \
71             ((at91_master_clock / (4 * (rate))) - 2))
72
73 /* TWI_SR */
74 /* TWI_IER */
75 /* TWI_IDR */
76 /* TWI_IMR */
77 #define TWI_SR_TXCOMP   (1U << 0)       /* Transmission Completed */
78 #define TWI_SR_RXRDY    (1U << 1)       /* Receive Holding Register Ready */
79 #define TWI_SR_TXRDY    (1U << 2)       /* Transmit Holding Register Ready */
80 #define TWI_SR_SVREAD   (1U << 3)       /* Slave Read */
81 #define TWI_SR_SVACC    (1U << 4)       /* Slave Access */
82 #define TWI_SR_GCACC    (1U << 5)       /* General Call Access */
83 #define TWI_SR_OVRE     (1U << 6)       /* Overrun error */
84 #define TWI_SR_UNRE     (1U << 7)       /* Underrun Error */
85 #define TWI_SR_NACK     (1U << 8)       /* Not Acknowledged */
86 #define TWI_SR_ARBLST   (1U << 9)       /* Arbitration Lost */
87
88 #endif /* ARM_AT91_AT91_TWIREG_H */