blob: 2c0baa622797e0543b9fc0bc10f0c5895c48c7a1 [file] [log] [blame]
Shashank Mittalc69512e2010-09-22 16:40:48 -07001/* Copyright (c) 2010, Code Aurora Forum. All rights reserved.
2 *
3 * Redistribution and use in source and binary forms, with or without
4 * modification, are permitted provided that the following conditions are
5 * met:
6 * * Redistributions of source code must retain the above copyright
7 * notice, this list of conditions and the following disclaimer.
8 * * Redistributions in binary form must reproduce the above
9 * copyright notice, this list of conditions and the following
10 * disclaimer in the documentation and/or other materials provided
11 * with the distribution.
12 * * Neither the name of Code Aurora Forum, Inc. nor the names of its
13 * contributors may be used to endorse or promote products derived
14 * from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
23 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
24 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
25 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
26 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29#ifndef __I2C_QUP__
30#define __I2C_QUP__
31
32/**
33 * struct i2c_msg - an I2C transaction segment beginning with START
34 * @addr: Slave address, either seven or ten bits. When this is a ten
35 * bit address, I2C_M_TEN must be set in @flags and the adapter
36 * must support I2C_FUNC_10BIT_ADDR.
37 * @flags: I2C_M_RD is handled by all adapters. No other flags may be
38 * provided unless the adapter exported the relevant I2C_FUNC_*
39 * flags through i2c_check_functionality().
40 * @len: Number of data bytes in @buf being read from or written to the
41 * I2C slave address. For read transactions where I2C_M_RECV_LEN
42 * is set, the caller guarantees that this buffer can hold up to
43 * 32 bytes in addition to the initial length byte sent by the
44 * slave (plus, if used, the SMBus PEC); and this value will be
45 * incremented by the number of block data bytes received.
46 * @buf: The buffer into which data is read, or from which it's written.
47 *
48 * An i2c_msg is the low level representation of one segment of an I2C
49 * transaction. It is visible to drivers in the @i2c_transfer() procedure,
50 * to userspace from i2c-dev, and to I2C adapter drivers through the
51 * @i2c_adapter.@master_xfer() method.
52 *
53 * Except when I2C "protocol mangling" is used, all I2C adapters implement
54 * the standard rules for I2C transactions. Each transaction begins with a
55 * START. That is followed by the slave address, and a bit encoding read
56 * versus write. Then follow all the data bytes, possibly including a byte
57 * with SMBus PEC. The transfer terminates with a NAK, or when all those
58 * bytes have been transferred and ACKed. If this is the last message in a
59 * group, it is followed by a STOP. Otherwise it is followed by the next
60 * @i2c_msg transaction segment, beginning with a (repeated) START.
61 *
62 * Alternatively, when the adapter supports I2C_FUNC_PROTOCOL_MANGLING then
63 * passing certain @flags may have changed those standard protocol behaviors.
64 * Those flags are only for use with broken/nonconforming slaves, and with
65 * adapters which are known to support the specific mangling options they
66 * need (one or more of IGNORE_NAK, NO_RD_ACK, NOSTART, and REV_DIR_ADDR).
67 */
68struct i2c_msg {
69 unsigned short addr; /* slave address */
70 unsigned short flags;
71#define I2C_M_TEN 0x0010 /* this is a ten bit chip address */
72#define I2C_M_WR 0x0000 /* write data, from master to slave */
73#define I2C_M_RD 0x0001 /* read data, from slave to master */
74#define I2C_M_NOSTART 0x4000 /* if I2C_FUNC_PROTOCOL_MANGLING */
75#define I2C_M_REV_DIR_ADDR 0x2000 /* if I2C_FUNC_PROTOCOL_MANGLING */
76#define I2C_M_IGNORE_NAK 0x1000 /* if I2C_FUNC_PROTOCOL_MANGLING */
77#define I2C_M_NO_RD_ACK 0x0800 /* if I2C_FUNC_PROTOCOL_MANGLING */
78#define I2C_M_RECV_LEN 0x0400 /* length will be first received byte */
79 unsigned short len; /* msg length */
80 unsigned char *buf; /* pointer to msg data */
81};
82
83struct qup_i2c_dev {
84 unsigned int base;
85 unsigned int gsbi_number;
86 int qup_irq;
87 int num_irqs;
88 struct i2c_msg *msg;
89 int pos;
90 int cnt;
91 int err;
92 int mode;
93 int clk_ctl;
94 int clk_freq;
95 int src_clk_freq;
96 int one_bit_t;
97 int out_fifo_sz;
98 int in_fifo_sz;
99 int out_blk_sz;
100 int in_blk_sz;
101 int wr_sz;
102 int suspended;
103 int clk_state;
104};
105
106/* Function Definitions */
107struct qup_i2c_dev *qup_i2c_init(unsigned base,
108 unsigned clk_freq, unsigned src_clk_freq);
109int qup_i2c_deinit(struct qup_i2c_dev *dev);
110int qup_i2c_xfer(struct qup_i2c_dev *dev, struct i2c_msg msgs[], int num);
111
112struct device {
113 struct device *parent;
114 const char *init_name; /* initial name of the device */
115 void (*release) (struct device * dev);
116};
117
118/**
119 * enum irqreturn
120 * @IRQ_NONE interrupt was not from this device
121 * @IRQ_HANDLED interrupt was handled by this device
122 * @IRQ_WAKE_THREAD handler requests to wake the handler thread
123 */
124enum irqreturn {
125 IRQ_NONE,
126 IRQ_HANDLED,
127 IRQ_WAKE_THREAD,
128 IRQ_FAIL,
129};
130
131typedef enum irqreturn irqreturn_t;
132
133#define I2C_SMBUS_BLOCK_MAX 32
134union i2c_smbus_data {
135 unsigned char byte;
136 unsigned short word;
137 unsigned char block[I2C_SMBUS_BLOCK_MAX + 2];
138};
139
140/*
141 * i2c_adapter is the structure used to identify a physical i2c bus along
142 * with the access algorithms necessary to access it.
143 */
144struct i2c_adapter {
145 struct module *owner;
146 unsigned int id;
147 unsigned int class; /* classes to allow probing for */
148 const struct i2c_algorithm *algo; /* the algorithm to access the bus */
149 void *algo_data;
150 /* data fields that are valid for all devices */
151 unsigned int level; /* nesting level for lockdep */
152 int timeout; /* in jiffies */
153 int retries;
154 struct device dev; /* the adapter device */
155 int nr;
156 char name[48];
157};
158
159/*
160 * The following structs are for those who like to implement new bus drivers:
161 * i2c_algorithm is the interface to a class of hardware solutions which can
162 * be addressed using the same bus algorithms - i.e. bit-banging or the PCF8584
163 * to name two of the most common.
164 */
165struct i2c_algorithm {
166 /* If an adapter algorithm can't do I2C-level access, set master_xfer to
167 NULL. If an adapter algorithm can do SMBus access, set smbus_xfer. If
168 set to NULL, the SMBus protocol is simulated using common I2C messages */
169 /* master_xfer should return the number of messages successfully processed,
170 or a negative value on error */
171 int (*master_xfer) (struct i2c_adapter * adap, struct i2c_msg * msgs,
172 int num);
173 int (*smbus_xfer) (struct i2c_adapter * adap, unsigned short addr,
174 unsigned short flags, char read_write,
175 unsigned char command, int size,
176 union i2c_smbus_data * data);
177
178 /* To determine what the adapter supports */
179 unsigned int (*functionality) (struct i2c_adapter *);
180};
181
182#define EIO 5
183#define ENOMEM 12
184#define EBUSY 16
185#define ENODEV 19
186#define ENOSYS 38
187#define EPROTONOSUPPORT 93
188#define ETIMEDOUT 110
189
190#define FALSE 0
191#define TRUE 1
192
193#define USEC_PER_SEC 1000000L
194
195#define IRQF_TRIGGER_NONE 0x00000000
196#define IRQF_TRIGGER_RISING 0x00000001
197#define IRQF_TRIGGER_FALLING 0x00000002
198#define IRQF_TRIGGER_HIGH 0x00000004
199#define IRQF_TRIGGER_LOW 0x00000008
200#define IRQF_TRIGGER_MASK (IRQF_TRIGGER_HIGH | IRQF_TRIGGER_LOW | \
201 IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING)
202#define IRQF_TRIGGER_PROBE 0x00000010
203
204/* To determine what functionality is present */
205
206#define I2C_FUNC_I2C 0x00000001
207#define I2C_FUNC_10BIT_ADDR 0x00000002
208#define I2C_FUNC_PROTOCOL_MANGLING 0x00000004 /* I2C_M_NOSTART etc. */
209#define I2C_FUNC_SMBUS_PEC 0x00000008
210#define I2C_FUNC_SMBUS_BLOCK_PROC_CALL 0x00008000 /* SMBus 2.0 */
211#define I2C_FUNC_SMBUS_QUICK 0x00010000
212#define I2C_FUNC_SMBUS_READ_BYTE 0x00020000
213#define I2C_FUNC_SMBUS_WRITE_BYTE 0x00040000
214#define I2C_FUNC_SMBUS_READ_BYTE_DATA 0x00080000
215#define I2C_FUNC_SMBUS_WRITE_BYTE_DATA 0x00100000
216#define I2C_FUNC_SMBUS_READ_WORD_DATA 0x00200000
217#define I2C_FUNC_SMBUS_WRITE_WORD_DATA 0x00400000
218#define I2C_FUNC_SMBUS_PROC_CALL 0x00800000
219#define I2C_FUNC_SMBUS_READ_BLOCK_DATA 0x01000000
220#define I2C_FUNC_SMBUS_WRITE_BLOCK_DATA 0x02000000
221#define I2C_FUNC_SMBUS_READ_I2C_BLOCK 0x04000000 /* I2C-like block xfer */
222#define I2C_FUNC_SMBUS_WRITE_I2C_BLOCK 0x08000000 /* w/ 1-byte reg. addr. */
223
224#define I2C_FUNC_SMBUS_BYTE (I2C_FUNC_SMBUS_READ_BYTE | \
225 I2C_FUNC_SMBUS_WRITE_BYTE)
226#define I2C_FUNC_SMBUS_BYTE_DATA (I2C_FUNC_SMBUS_READ_BYTE_DATA | \
227 I2C_FUNC_SMBUS_WRITE_BYTE_DATA)
228#define I2C_FUNC_SMBUS_WORD_DATA (I2C_FUNC_SMBUS_READ_WORD_DATA | \
229 I2C_FUNC_SMBUS_WRITE_WORD_DATA)
230#define I2C_FUNC_SMBUS_BLOCK_DATA (I2C_FUNC_SMBUS_READ_BLOCK_DATA | \
231 I2C_FUNC_SMBUS_WRITE_BLOCK_DATA)
232#define I2C_FUNC_SMBUS_I2C_BLOCK (I2C_FUNC_SMBUS_READ_I2C_BLOCK | \
233 I2C_FUNC_SMBUS_WRITE_I2C_BLOCK)
234
235#define I2C_FUNC_SMBUS_EMUL (I2C_FUNC_SMBUS_QUICK | \
236 I2C_FUNC_SMBUS_BYTE | \
237 I2C_FUNC_SMBUS_BYTE_DATA | \
238 I2C_FUNC_SMBUS_WORD_DATA | \
239 I2C_FUNC_SMBUS_PROC_CALL | \
240 I2C_FUNC_SMBUS_WRITE_BLOCK_DATA | \
241 I2C_FUNC_SMBUS_I2C_BLOCK | \
242 I2C_FUNC_SMBUS_PEC)
243
244/* GSBI/I2C QUP APPS CLK definitions */
245#define I2C_APPS_CLK_MD_24MHz 0x000100FB
246#define I2C_APPS_CLK_NS_24MHz 0x00FC005B
247
248#define GSBI8_HCLK_CTL_S (4)
249#define GSBI8_HCLK_CTL_CLK_ENA (0x1)
250
251#define GSBI_CTRL_REG_PROTOCOL_CODE_S (4)
252#define GSBI_PROTOCOL_CODE_I2C (0x2)
253
254#endif /* __I2C_QUP__ */