• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2020 HiSilicon (Shanghai) Technologies CO., LIMITED.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef __I2C_H_
17 #define __I2C_H_
18 
19 #include <hi3861_platform_base.h>
20 
21 #define I2C_CLK              CONFIG_WDT_CLOCK
22 #define I2C_NUM              2
23 
24 #define I2C_FIFO_LINE_MIN    1
25 #define I2C_FIFO_LINE_MAX    32
26 #define I2C_FIFO_INIT_COUNT  1
27 #define I2C_FIFO_INIT_VALUE  0x1fff
28 #define I2C_INIT_VALUE       0x1ff
29 #define READ_OPERATION       (1<<0)
30 #define WRITE_OPERATION      (~READ_OPERATION)
31 
32 #define I2C_CTRL             0x000
33 #define I2C_COM              0x004
34 #define I2C_ICR              0x008
35 #define I2C_SR               0x00C
36 #define I2C_SCL_H            0x010
37 #define I2C_SCL_L            0x014
38 #define I2C_TXR              0x018
39 #define I2C_RXR              0x01C
40 #define I2C_FIFOSTATUS       0x020
41 #define I2C_TXCOUNT          0x024
42 #define I2C_RXCOUNT          0x028
43 #define I2C_RXTIDE           0x02C
44 #define I2C_TXTIDE           0x030
45 
46 /* I2C_CTRL */
47 #define I2C_UNMASK_FIFO_EMPTY       (1<<12)
48 #define I2C_FIFO_ENABLE             (1<<11)
49 #define I2C_UNMASK_FIFO_SEND_OF     (1<<10)
50 #define I2C_UNMASK_FIFO_RECEIVE_OF  (1<<9)
51 #define I2C_IP_ENABLE        (1<<8)
52 #define I2C_UNMASK_ALL       (1<<7)
53 #define I2C_UNMASK_START     (1<<6)
54 #define I2C_UNMASK_END       (1<<5)
55 #define I2C_UNMASK_SEND      (1<<4)
56 #define I2C_UNMASK_RECEIVE   (1<<3)
57 #define I2C_UNMASK_ACK       (1<<2)
58 #define I2C_UNMASK_ARBITRATE (1<<1)
59 #define I2C_UNMASK_OVER      (1<<0)
60 
61 /* I2C_COM */
62 #define I2C_SEND_ACK         (~(1<<4))
63 #define I2C_START            (1<<3)
64 #define I2C_READ             (1<<2)
65 #define I2C_WRITE            (1<<1)
66 #define I2C_STOP             (1<<0)
67 
68 /* I2C_ICR */
69 #define I2C_CLEAR_FIFO_EMPTY      (1<<9)
70 #define I2C_CLEAR_FIFO_SEND_OF    (1<<8)
71 #define I2C_CLEAR_FIFO_RECEIVE_OF (1<<7)
72 #define I2C_CLEAR_START      (1<<6)
73 #define I2C_CLEAR_END        (1<<5)
74 #define I2C_CLEAR_SEND       (1<<4)
75 #define I2C_CLEAR_RECEIVE    (1<<3)
76 #define I2C_CLEAR_ACK        (1<<2)
77 #define I2C_CLEAR_ARBITRATE  (1<<1)
78 #define I2C_CLEAR_OVER       (1<<0)
79 #define I2C_CLEAR_ALL        (I2C_CLEAR_FIFO_EMPTY | \
80                               I2C_CLEAR_FIFO_SEND_OF | I2C_CLEAR_FIFO_RECEIVE_OF | \
81                               I2C_CLEAR_START | I2C_CLEAR_END | \
82                               I2C_CLEAR_SEND | I2C_CLEAR_RECEIVE | \
83                               I2C_CLEAR_ACK | I2C_CLEAR_ARBITRATE | \
84                               I2C_CLEAR_OVER)
85 
86 /* I2C_SR */
87 #define I2C_FIFO_EMPTY       (1<<10)
88 #define I2C_FIFO_SEND_OF     (1<<9)
89 #define I2C_FIFO_RECEIVE_OF  (1<<8)
90 #define I2C_BUSY             (1<<7)
91 #define I2C_START_INTR       (1<<6)
92 #define I2C_END_INTR         (1<<5)
93 #define I2C_SEND_INTR        (1<<4)
94 #define I2C_RECEIVE_INTR     (1<<3)
95 #define I2C_ACK_INTR         (1<<2)
96 #define I2C_ARBITRATE_INTR   (1<<1)
97 #define I2C_INT_DONE         (1<<0)
98 
99 #define I2C_START_END        (I2C_START_INTR | I2C_INT_DONE)
100 #define I2C_STOP_END         (I2C_END_INTR | I2C_INT_DONE)
101 
102 #define I2C_START_EMPTY      (I2C_START_INTR | I2C_FIFO_EMPTY)
103 #define I2C_STOP_EMPTY       (I2C_END_INTR | I2C_FIFO_EMPTY)
104 
105 /* I2C_FIFOSTATUS */
106 #define I2C_RECVFIFO_EMPTY   (1<<3)
107 #define I2C_RECVFIFO_FULL    (1<<2)
108 #define I2C_SENDFIFO_EMPTY   (1<<1)
109 #define I2C_SENDFIFO_FULL    (1<<0)
110 
111 
112 #define I2C_SC_SCPERCTRL0    0x1c
113 #define I2C_SC_SCPERCTRL2    0x34
114 
115 #define i2c_error(_fmt, arg...)
116 
117 #endif
118 
119