1 /***************************************************************************
5 * SiI9244 - MHL Transmitter Driver
9 * Copyright (C) (2011, Silicon Image Inc)
13 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
17 * the Free Software Foundation version 2.
21 * This program is distributed ¡°as is¡± WITHOUT ANY WARRANTY of any
23 * kind, whether express or implied; without even the implied warranty
25 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27 * GNU General Public License for more details.
31 *****************************************************************************/
33 /*===========================================================================
37 when who what, where, why
38 -------- --- ----------------------------------------------------------
39 2010/10/25 Daniel Lee(Philju) Initial version of file, SIMG Korea
40 ===========================================================================*/
41 #include <linux/interrupt.h>
42 #include <linux/irq.h>
43 #include <linux/i2c.h>
44 #include <linux/gpio.h>
47 #include <linux/delay.h>
48 #include <plat/gpio-cfg.h>
49 #include <mach/regs-gpio.h>
50 #include <mach/regs-clock.h>
52 #include <linux/syscalls.h>
53 #include <linux/fcntl.h>
54 #include <asm/uaccess.h>
55 #include <linux/types.h>
58 #include "Common_Def.h"
59 #include "SiI9234_I2C_slave_add.h"
62 /*===========================================================================
64 ===========================================================================*/
70 #define NOT_LAST_BYTE 0
73 #define TPI_INDEXED_PAGE_REG 0xBC
74 #define TPI_INDEXED_OFFSET_REG 0xBD
75 #define TPI_INDEXED_VALUE_REG 0xBE
78 /*===========================================================================
80 ===========================================================================*/
81 //------------------------------------------------------------------------------
82 // Function: I2C_WriteByte
84 //------------------------------------------------------------------------------
85 void I2C_WriteByte(byte deviceID, byte offset, byte value)
88 struct i2c_client* client_ptr = get_sii9234_client(deviceID);
91 printk("[MHL]I2C_WriteByte error %x\n",deviceID);
96 sii9234_i2c_write(client_ptr,offset,value);
97 else if(deviceID == 0x7A)
98 sii9234_i2c_write(client_ptr,offset,value);
99 else if(deviceID == 0x92)
100 sii9234_i2c_write(client_ptr,offset,value);
101 else if(deviceID == 0xC8)
102 sii9234_i2c_write(client_ptr,offset,value);
108 byte I2C_ReadByte(byte deviceID, byte offset)
111 struct i2c_client* client_ptr = get_sii9234_client(deviceID);
114 printk("[MHL]I2C_ReadByte error %x\n",deviceID);
120 number = sii9234_i2c_read(client_ptr,offset);
121 else if(deviceID == 0x7A)
122 number = sii9234_i2c_read(client_ptr,offset);
123 else if(deviceID == 0x92)
124 number = sii9234_i2c_read(client_ptr,offset);
125 else if(deviceID == 0xC8)
126 number = sii9234_i2c_read(client_ptr,offset);
132 byte ReadByteTPI (byte Offset)
134 return I2C_ReadByte(SA_TX_Page0_Primary, Offset);
137 void WriteByteTPI (byte Offset, byte Data)
139 I2C_WriteByte(SA_TX_Page0_Primary, Offset, Data);
144 void ReadModifyWriteTPI(byte Offset, byte Mask, byte Data)
149 Temp = ReadByteTPI(Offset); // Read the current value of the register.
150 Temp &= ~Mask; // Clear the bits that are set in Mask.
151 Temp |= (Data & Mask); // OR in new value. Apply Mask to Value for safety.
152 WriteByteTPI(Offset, Temp); // Write new value back to register.
155 byte ReadByteCBUS (byte Offset)
157 return I2C_ReadByte(SA_TX_CBUS_Primary, Offset);
160 void WriteByteCBUS(byte Offset, byte Data)
162 I2C_WriteByte(SA_TX_CBUS_Primary, Offset, Data);
165 void ReadModifyWriteCBUS(byte Offset, byte Mask, byte Value)
169 Temp = ReadByteCBUS(Offset);
171 Temp |= (Value & Mask);
172 WriteByteCBUS(Offset, Temp);
176 //////////////////////////////////////////////////////////////////////////////
178 // FUNCTION : ReadIndexedRegister ()
180 // PURPOSE : Read the value from an indexed register.
183 // 1. 0xBC => Indexed page num
184 // 2. 0xBD => Indexed register offset
187 // 3. 0xBE => Returns the indexed register value
189 // INPUT PARAMS : PageNum - indexed page number
190 // Offset - offset of the register within the indexed page.
192 // OUTPUT PARAMS: None
194 // GLOBALS USED : None
196 // RETURNS : The value read from the indexed register.
198 //////////////////////////////////////////////////////////////////////////////
200 byte ReadIndexedRegister (byte PageNum, byte Offset)
202 WriteByteTPI(TPI_INDEXED_PAGE_REG, PageNum); // Indexed page
203 WriteByteTPI(TPI_INDEXED_OFFSET_REG, Offset); // Indexed register
204 return ReadByteTPI(TPI_INDEXED_VALUE_REG); // Return read value
208 //////////////////////////////////////////////////////////////////////////////
210 // FUNCTION : WriteIndexedRegister ()
212 // PURPOSE : Write a value to an indexed register
215 // 1. 0xBC => Indexed page num
216 // 2. 0xBD => Indexed register offset
217 // 3. 0xBE => Set the indexed register value
219 // INPUT PARAMS : PageNum - indexed page number
220 // Offset - offset of the register within the indexed page.
221 // Data - the value to be written.
223 // OUTPUT PARAMS: None
225 // GLOBALS USED : None
229 //////////////////////////////////////////////////////////////////////////////
231 void WriteIndexedRegister (byte PageNum, byte Offset, byte Data)
233 WriteByteTPI(TPI_INDEXED_PAGE_REG, PageNum); // Indexed page
234 WriteByteTPI(TPI_INDEXED_OFFSET_REG, Offset); // Indexed register
235 WriteByteTPI(TPI_INDEXED_VALUE_REG, Data); // Write value
239 //////////////////////////////////////////////////////////////////////////////
241 // FUNCTION : ReadModifyWriteIndexedRegister ()
243 // PURPOSE : Set or clear individual bits in a TPI register.
245 // INPUT PARAMS : PageNum - indexed page number
246 // Offset - the offset of the indexed register to be modified.
247 // Mask - "1" for each indexed register bit that needs to be
249 // Data - The desired value for the register bits in their
252 // OUTPUT PARAMS: None
254 // GLOBALS USED : None
258 //////////////////////////////////////////////////////////////////////////////
260 void ReadModifyWriteIndexedRegister (byte PageNum, byte Offset, byte Mask, byte Data)
265 Temp = ReadIndexedRegister (PageNum, Offset); // Read the current value of the register.
266 Temp &= ~Mask; // Clear the bits that are set in Mask.
267 Temp |= (Data & Mask); // OR in new value. Apply Mask to Value for safety.
268 WriteByteTPI(TPI_INDEXED_VALUE_REG, Temp); // Write new value back to register.