diff options
author | Dirk Brandewie <dirk.brandewie@gmail.com> | 2011-10-29 05:57:23 -0400 |
---|---|---|
committer | Ben Dooks <ben-linux@fluff.org> | 2011-10-29 06:03:39 -0400 |
commit | 2373f6b9744d5373b886f3ce1a985193cca0a356 (patch) | |
tree | 1d3e76da9c3c0bdac1be935742210ebd5e77719d /drivers/i2c/busses/i2c-designware-core.h | |
parent | 4a423a8c8107b983007199c76c8327cd1747f092 (diff) |
i2c-designware: split of i2c-designware.c into core and bus specific parts
This patch splits i2c-designware.c into three pieces:
i2c-designware-core.c, contains the code that interacts directly
with the core.
i2c-designware-platdrv.c, contains the code specific to the
platform driver using the core.
i2c-designware-core.h contains the definitions and declareations
shared by i2c-designware-core.c and i2c-designware-platdrv.c.
This patch is the first in a set to allow multiple instances of the
designware I2C core in the system.
Signed-off-by: Dirk Brandewie <dirk.brandewie@gmail.com>
Signed-off-by: Ben Dooks <ben-linux@fluff.org>
Diffstat (limited to 'drivers/i2c/busses/i2c-designware-core.h')
-rw-r--r-- | drivers/i2c/busses/i2c-designware-core.h | 194 |
1 files changed, 194 insertions, 0 deletions
diff --git a/drivers/i2c/busses/i2c-designware-core.h b/drivers/i2c/busses/i2c-designware-core.h new file mode 100644 index 000000000000..4e37031c6b68 --- /dev/null +++ b/drivers/i2c/busses/i2c-designware-core.h | |||
@@ -0,0 +1,194 @@ | |||
1 | /* | ||
2 | * Synopsys DesignWare I2C adapter driver (master only). | ||
3 | * | ||
4 | * Based on the TI DAVINCI I2C adapter driver. | ||
5 | * | ||
6 | * Copyright (C) 2006 Texas Instruments. | ||
7 | * Copyright (C) 2007 MontaVista Software Inc. | ||
8 | * Copyright (C) 2009 Provigent Ltd. | ||
9 | * | ||
10 | * ---------------------------------------------------------------------------- | ||
11 | * | ||
12 | * This program is free software; you can redistribute it and/or modify | ||
13 | * it under the terms of the GNU General Public License as published by | ||
14 | * the Free Software Foundation; either version 2 of the License, or | ||
15 | * (at your option) any later version. | ||
16 | * | ||
17 | * This program is distributed in the hope that it will be useful, | ||
18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
20 | * GNU General Public License for more details. | ||
21 | * | ||
22 | * You should have received a copy of the GNU General Public License | ||
23 | * along with this program; if not, write to the Free Software | ||
24 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | ||
25 | * ---------------------------------------------------------------------------- | ||
26 | * | ||
27 | */ | ||
28 | |||
29 | /* | ||
30 | * Registers offset | ||
31 | */ | ||
32 | #define DW_IC_CON 0x0 | ||
33 | #define DW_IC_TAR 0x4 | ||
34 | #define DW_IC_DATA_CMD 0x10 | ||
35 | #define DW_IC_SS_SCL_HCNT 0x14 | ||
36 | #define DW_IC_SS_SCL_LCNT 0x18 | ||
37 | #define DW_IC_FS_SCL_HCNT 0x1c | ||
38 | #define DW_IC_FS_SCL_LCNT 0x20 | ||
39 | #define DW_IC_INTR_STAT 0x2c | ||
40 | #define DW_IC_INTR_MASK 0x30 | ||
41 | #define DW_IC_RAW_INTR_STAT 0x34 | ||
42 | #define DW_IC_RX_TL 0x38 | ||
43 | #define DW_IC_TX_TL 0x3c | ||
44 | #define DW_IC_CLR_INTR 0x40 | ||
45 | #define DW_IC_CLR_RX_UNDER 0x44 | ||
46 | #define DW_IC_CLR_RX_OVER 0x48 | ||
47 | #define DW_IC_CLR_TX_OVER 0x4c | ||
48 | #define DW_IC_CLR_RD_REQ 0x50 | ||
49 | #define DW_IC_CLR_TX_ABRT 0x54 | ||
50 | #define DW_IC_CLR_RX_DONE 0x58 | ||
51 | #define DW_IC_CLR_ACTIVITY 0x5c | ||
52 | #define DW_IC_CLR_STOP_DET 0x60 | ||
53 | #define DW_IC_CLR_START_DET 0x64 | ||
54 | #define DW_IC_CLR_GEN_CALL 0x68 | ||
55 | #define DW_IC_ENABLE 0x6c | ||
56 | #define DW_IC_STATUS 0x70 | ||
57 | #define DW_IC_TXFLR 0x74 | ||
58 | #define DW_IC_RXFLR 0x78 | ||
59 | #define DW_IC_TX_ABRT_SOURCE 0x80 | ||
60 | #define DW_IC_COMP_PARAM_1 0xf4 | ||
61 | #define DW_IC_COMP_TYPE 0xfc | ||
62 | #define DW_IC_COMP_TYPE_VALUE 0x44570140 | ||
63 | |||
64 | #define DW_IC_CON_MASTER 0x1 | ||
65 | #define DW_IC_CON_SPEED_STD 0x2 | ||
66 | #define DW_IC_CON_SPEED_FAST 0x4 | ||
67 | #define DW_IC_CON_10BITADDR_MASTER 0x10 | ||
68 | #define DW_IC_CON_RESTART_EN 0x20 | ||
69 | #define DW_IC_CON_SLAVE_DISABLE 0x40 | ||
70 | |||
71 | #define DW_IC_INTR_RX_UNDER 0x001 | ||
72 | #define DW_IC_INTR_RX_OVER 0x002 | ||
73 | #define DW_IC_INTR_RX_FULL 0x004 | ||
74 | #define DW_IC_INTR_TX_OVER 0x008 | ||
75 | #define DW_IC_INTR_TX_EMPTY 0x010 | ||
76 | #define DW_IC_INTR_RD_REQ 0x020 | ||
77 | #define DW_IC_INTR_TX_ABRT 0x040 | ||
78 | #define DW_IC_INTR_RX_DONE 0x080 | ||
79 | #define DW_IC_INTR_ACTIVITY 0x100 | ||
80 | #define DW_IC_INTR_STOP_DET 0x200 | ||
81 | #define DW_IC_INTR_START_DET 0x400 | ||
82 | #define DW_IC_INTR_GEN_CALL 0x800 | ||
83 | |||
84 | #define DW_IC_INTR_DEFAULT_MASK (DW_IC_INTR_RX_FULL | \ | ||
85 | DW_IC_INTR_TX_EMPTY | \ | ||
86 | DW_IC_INTR_TX_ABRT | \ | ||
87 | DW_IC_INTR_STOP_DET) | ||
88 | |||
89 | #define DW_IC_STATUS_ACTIVITY 0x1 | ||
90 | |||
91 | #define DW_IC_ERR_TX_ABRT 0x1 | ||
92 | |||
93 | /* | ||
94 | * status codes | ||
95 | */ | ||
96 | #define STATUS_IDLE 0x0 | ||
97 | #define STATUS_WRITE_IN_PROGRESS 0x1 | ||
98 | #define STATUS_READ_IN_PROGRESS 0x2 | ||
99 | |||
100 | #define TIMEOUT 20 /* ms */ | ||
101 | |||
102 | /* | ||
103 | * hardware abort codes from the DW_IC_TX_ABRT_SOURCE register | ||
104 | * | ||
105 | * only expected abort codes are listed here | ||
106 | * refer to the datasheet for the full list | ||
107 | */ | ||
108 | #define ABRT_7B_ADDR_NOACK 0 | ||
109 | #define ABRT_10ADDR1_NOACK 1 | ||
110 | #define ABRT_10ADDR2_NOACK 2 | ||
111 | #define ABRT_TXDATA_NOACK 3 | ||
112 | #define ABRT_GCALL_NOACK 4 | ||
113 | #define ABRT_GCALL_READ 5 | ||
114 | #define ABRT_SBYTE_ACKDET 7 | ||
115 | #define ABRT_SBYTE_NORSTRT 9 | ||
116 | #define ABRT_10B_RD_NORSTRT 10 | ||
117 | #define ABRT_MASTER_DIS 11 | ||
118 | #define ARB_LOST 12 | ||
119 | |||
120 | #define DW_IC_TX_ABRT_7B_ADDR_NOACK (1UL << ABRT_7B_ADDR_NOACK) | ||
121 | #define DW_IC_TX_ABRT_10ADDR1_NOACK (1UL << ABRT_10ADDR1_NOACK) | ||
122 | #define DW_IC_TX_ABRT_10ADDR2_NOACK (1UL << ABRT_10ADDR2_NOACK) | ||
123 | #define DW_IC_TX_ABRT_TXDATA_NOACK (1UL << ABRT_TXDATA_NOACK) | ||
124 | #define DW_IC_TX_ABRT_GCALL_NOACK (1UL << ABRT_GCALL_NOACK) | ||
125 | #define DW_IC_TX_ABRT_GCALL_READ (1UL << ABRT_GCALL_READ) | ||
126 | #define DW_IC_TX_ABRT_SBYTE_ACKDET (1UL << ABRT_SBYTE_ACKDET) | ||
127 | #define DW_IC_TX_ABRT_SBYTE_NORSTRT (1UL << ABRT_SBYTE_NORSTRT) | ||
128 | #define DW_IC_TX_ABRT_10B_RD_NORSTRT (1UL << ABRT_10B_RD_NORSTRT) | ||
129 | #define DW_IC_TX_ABRT_MASTER_DIS (1UL << ABRT_MASTER_DIS) | ||
130 | #define DW_IC_TX_ARB_LOST (1UL << ARB_LOST) | ||
131 | |||
132 | #define DW_IC_TX_ABRT_NOACK (DW_IC_TX_ABRT_7B_ADDR_NOACK | \ | ||
133 | DW_IC_TX_ABRT_10ADDR1_NOACK | \ | ||
134 | DW_IC_TX_ABRT_10ADDR2_NOACK | \ | ||
135 | DW_IC_TX_ABRT_TXDATA_NOACK | \ | ||
136 | DW_IC_TX_ABRT_GCALL_NOACK) | ||
137 | /** | ||
138 | * struct dw_i2c_dev - private i2c-designware data | ||
139 | * @dev: driver model device node | ||
140 | * @base: IO registers pointer | ||
141 | * @cmd_complete: tx completion indicator | ||
142 | * @lock: protect this struct and IO registers | ||
143 | * @clk: input reference clock | ||
144 | * @cmd_err: run time hadware error code | ||
145 | * @msgs: points to an array of messages currently being transfered | ||
146 | * @msgs_num: the number of elements in msgs | ||
147 | * @msg_write_idx: the element index of the current tx message in the msgs | ||
148 | * array | ||
149 | * @tx_buf_len: the length of the current tx buffer | ||
150 | * @tx_buf: the current tx buffer | ||
151 | * @msg_read_idx: the element index of the current rx message in the msgs | ||
152 | * array | ||
153 | * @rx_buf_len: the length of the current rx buffer | ||
154 | * @rx_buf: the current rx buffer | ||
155 | * @msg_err: error status of the current transfer | ||
156 | * @status: i2c master status, one of STATUS_* | ||
157 | * @abort_source: copy of the TX_ABRT_SOURCE register | ||
158 | * @irq: interrupt number for the i2c master | ||
159 | * @adapter: i2c subsystem adapter node | ||
160 | * @tx_fifo_depth: depth of the hardware tx fifo | ||
161 | * @rx_fifo_depth: depth of the hardware rx fifo | ||
162 | */ | ||
163 | struct dw_i2c_dev { | ||
164 | struct device *dev; | ||
165 | void __iomem *base; | ||
166 | struct completion cmd_complete; | ||
167 | struct mutex lock; | ||
168 | struct clk *clk; | ||
169 | int cmd_err; | ||
170 | struct i2c_msg *msgs; | ||
171 | int msgs_num; | ||
172 | int msg_write_idx; | ||
173 | u32 tx_buf_len; | ||
174 | u8 *tx_buf; | ||
175 | int msg_read_idx; | ||
176 | u32 rx_buf_len; | ||
177 | u8 *rx_buf; | ||
178 | int msg_err; | ||
179 | unsigned int status; | ||
180 | u32 abort_source; | ||
181 | int irq; | ||
182 | int swab; | ||
183 | struct i2c_adapter adapter; | ||
184 | unsigned int tx_fifo_depth; | ||
185 | unsigned int rx_fifo_depth; | ||
186 | }; | ||
187 | |||
188 | extern u32 dw_readl(struct dw_i2c_dev *dev, int offset); | ||
189 | extern void dw_writel(struct dw_i2c_dev *dev, u32 b, int offset); | ||
190 | extern int i2c_dw_init(struct dw_i2c_dev *dev); | ||
191 | extern int i2c_dw_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[], | ||
192 | int num); | ||
193 | extern u32 i2c_dw_func(struct i2c_adapter *adap); | ||
194 | extern irqreturn_t i2c_dw_isr(int this_irq, void *dev_id); | ||