1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
|
////////////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2006-2012 MStar Semiconductor, Inc.
// All rights reserved.
//
// Unless otherwise stipulated in writing, any and all information contained
// herein regardless in any format shall remain the sole proprietary of
// MStar Semiconductor Inc. and be kept in strict confidence
// (??MStar Confidential Information??) by the recipient.
// Any unauthorized act including without limitation unauthorized disclosure,
// copying, use, reproduction, sale, distribution, modification, disassembling,
// reverse engineering and compiling of the contents of MStar Confidential
// Information is unlawful and strictly prohibited. MStar hereby reserves the
// rights to any and all damages, losses, costs and expenses resulting therefrom.
//
////////////////////////////////////////////////////////////////////////////////
/**
*
* @file mstar_drv_utility_adaption.c
*
* @brief This file defines the interface of touch screen
*
* @version v2.2.0.0
*
*/
////////////////////////////////////////////////////////////
/// Included Files
////////////////////////////////////////////////////////////
#include "mstar_drv_utility_adaption.h"
////////////////////////////////////////////////////////////
/// Data Types
////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////
/// Constant
////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////
/// Variables
////////////////////////////////////////////////////////////
extern struct i2c_client *g_I2cClient;
////////////////////////////////////////////////////////////
/// Macro
////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////
/// Function Prototypes
////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////
/// Function Implementation
////////////////////////////////////////////////////////////
#ifdef CONFIG_ENABLE_DMA_IIC
#include <linux/dma-mapping.h>
#include <linux/mm_types.h>
#include <linux/mm.h>
#include <asm/uaccess.h>
#include <asm/page.h>
#include <linux/vmalloc.h>
static unsigned char *I2CDMABuf_va = NULL;
static volatile unsigned int I2CDMABuf_pa = NULL;
void DmaAlloc(void)
{
if (NULL == I2CDMABuf_va)
{
I2CDMABuf_va = (u8 *)dma_alloc_coherent(NULL, 4096, &I2CDMABuf_pa, GFP_KERNEL);
}
if (NULL == I2CDMABuf_va)
{
DBG("DrvCommonDmaAlloc FAILED!");
}
else
{
DBG("DrvCommonDmaAlloc SUCCESS!");
}
}
void DmaFree(void)
{
if (NULL != I2CDMABuf_va)
{
dma_free_coherent(NULL, 4096, I2CDMABuf_va, I2CDMABuf_pa);
I2CDMABuf_va = NULL;
I2CDMABuf_pa = 0;
}
}
#endif //CONFIG_ENABLE_DMA_IIC
//------------------------------------------------------------------------------//
u16 RegGet16BitValue(u16 nAddr)
{
u8 tx_data[3] = {0x10, (nAddr >> 8) & 0xFF, nAddr & 0xFF};
u8 rx_data[2] = {0};
IicWriteData(SLAVE_I2C_ID_DBBUS, &tx_data[0], 3);
IicReadData(SLAVE_I2C_ID_DBBUS, &rx_data[0], 2);
return (rx_data[1] << 8 | rx_data[0]);
}
u8 RegGetLByteValue(u16 nAddr)
{
u8 tx_data[3] = {0x10, (nAddr >> 8) & 0xFF, nAddr & 0xFF};
u8 rx_data = {0};
IicWriteData(SLAVE_I2C_ID_DBBUS, &tx_data[0], 3);
IicReadData(SLAVE_I2C_ID_DBBUS, &rx_data, 1);
return (rx_data);
}
u8 RegGetHByteValue(u16 nAddr)
{
u8 tx_data[3] = {0x10, (nAddr >> 8) & 0xFF, (nAddr & 0xFF) + 1};
u8 rx_data = {0};
IicWriteData(SLAVE_I2C_ID_DBBUS, &tx_data[0], 3);
IicReadData(SLAVE_I2C_ID_DBBUS, &rx_data, 1);
return (rx_data);
}
void RegSet16BitValue(u16 nAddr, u16 nData)
{
u8 tx_data[5] = {0x10, (nAddr >> 8) & 0xFF, nAddr & 0xFF, nData & 0xFF, nData >> 8};
IicWriteData(SLAVE_I2C_ID_DBBUS, &tx_data[0], 5);
}
void RegSetLByteValue(u16 nAddr, u8 nData)
{
u8 tx_data[4] = {0x10, (nAddr >> 8) & 0xFF, nAddr & 0xFF, nData};
IicWriteData(SLAVE_I2C_ID_DBBUS, &tx_data[0], 4);
}
void RegSetHByteValue(u16 nAddr, u8 nData)
{
u8 tx_data[4] = {0x10, (nAddr >> 8) & 0xFF, (nAddr & 0xFF) + 1, nData};
IicWriteData(SLAVE_I2C_ID_DBBUS, &tx_data[0], 4);
}
void RegSet16BitValueOn(u16 nAddr, u16 nData) //Set bit on nData from 0 to 1
{
u16 rData = RegGet16BitValue(nAddr);
rData |= nData;
RegSet16BitValue(nAddr, rData);
}
void RegSet16BitValueOff(u16 nAddr, u16 nData) //Set bit on nData from 1 to 0
{
u16 rData = RegGet16BitValue(nAddr);
rData &= (~nData);
RegSet16BitValue(nAddr, rData);
}
void DbBusEnterSerialDebugMode(void)
{
u8 data[5];
// Enter the Serial Debug Mode
data[0] = 0x53;
data[1] = 0x45;
data[2] = 0x52;
data[3] = 0x44;
data[4] = 0x42;
IicWriteData(SLAVE_I2C_ID_DBBUS, data, 5);
}
void DbBusExitSerialDebugMode(void)
{
u8 data[1];
// Exit the Serial Debug Mode
data[0] = 0x45;
IicWriteData(SLAVE_I2C_ID_DBBUS, data, 1);
// Delay some interval to guard the next transaction
// udelay(200); // delay about 0.2ms
}
void DbBusIICUseBus(void)
{
u8 data[1];
// IIC Use Bus
data[0] = 0x35;
IicWriteData(SLAVE_I2C_ID_DBBUS, data, 1);
}
void DbBusIICNotUseBus(void)
{
u8 data[1];
// IIC Not Use Bus
data[0] = 0x34;
IicWriteData(SLAVE_I2C_ID_DBBUS, data, 1);
}
void DbBusIICReshape(void)
{
u8 data[1];
// IIC Re-shape
data[0] = 0x71;
IicWriteData(SLAVE_I2C_ID_DBBUS, data, 1);
}
void DbBusStopMCU(void)
{
u8 data[1];
// Stop the MCU
data[0] = 0x37;
IicWriteData(SLAVE_I2C_ID_DBBUS, data, 1);
}
void DbBusNotStopMCU(void)
{
u8 data[1];
// Not Stop the MCU
data[0] = 0x36;
IicWriteData(SLAVE_I2C_ID_DBBUS, data, 1);
}
s32 IicWriteData(u8 nSlaveId, u8* pBuf, u16 nSize)
{
s32 rc = 0;
#if defined(CONFIG_TOUCH_DRIVER_RUN_ON_SPRD_PLATFORM) || defined(CONFIG_TOUCH_DRIVER_RUN_ON_QCOM_PLATFORM)
struct i2c_msg msgs[] =
{
{
.addr = nSlaveId,
.flags = 0, // if read flag is undefined, then it means write flag.
.len = nSize,
.buf = pBuf,
},
};
/* If everything went ok (i.e. 1 msg transmitted), return #bytes
transmitted, else error code. */
if (g_I2cClient != NULL)
{
rc = i2c_transfer(g_I2cClient->adapter, msgs, 1);
if (rc < 0)
{
PRINTF_ERR("IicWriteData() error %d\n", rc);
}
}
else
{
PRINTF_ERR("i2c client is NULL\n");
}
#elif defined(CONFIG_TOUCH_DRIVER_RUN_ON_MTK_PLATFORM)
if (g_I2cClient != NULL)
{
u8 nAddrBefore = g_I2cClient->addr;
g_I2cClient->addr = nSlaveId;
// g_I2cClient->addr = (g_I2cClient->addr & I2C_MASK_FLAG ) | (I2C_ENEXT_FLAG);
#ifdef CONFIG_ENABLE_DMA_IIC
if (nSize > 8 && NULL != I2CDMABuf_va)
{
s32 i = 0;
for (i = 0; i < nSize; i ++)
{
I2CDMABuf_va[i] = pBuf[i];
}
g_I2cClient->ext_flag = g_I2cClient->ext_flag | I2C_DMA_FLAG;
rc = i2c_master_send(g_I2cClient, (unsigned char *)I2CDMABuf_pa, nSize);
}
else
{
g_I2cClient->ext_flag = g_I2cClient->ext_flag & (~I2C_DMA_FLAG);
rc = i2c_master_send(g_I2cClient, pBuf, nSize);
}
#else
rc = i2c_master_send(g_I2cClient, pBuf, nSize);
#endif //CONFIG_ENABLE_DMA_IIC
g_I2cClient->addr = nAddrBefore;
if (rc < 0)
{
PRINTF_ERR("IicWriteData() error %d, nSlaveId=%d, nSize=%d\n", rc, nSlaveId, nSize);
}
}
else
{
PRINTF_ERR("i2c client is NULL\n");
}
#endif
return rc;
}
s32 IicReadData(u8 nSlaveId, u8* pBuf, u16 nSize)
{
s32 rc = 0;
#if defined(CONFIG_TOUCH_DRIVER_RUN_ON_SPRD_PLATFORM) || defined(CONFIG_TOUCH_DRIVER_RUN_ON_QCOM_PLATFORM)
struct i2c_msg msgs[] =
{
{
.addr = nSlaveId,
.flags = I2C_M_RD, // read flag
.len = nSize,
.buf = pBuf,
},
};
/* If everything went ok (i.e. 1 msg transmitted), return #bytes
transmitted, else error code. */
if (g_I2cClient != NULL)
{
rc = i2c_transfer(g_I2cClient->adapter, msgs, 1);
if (rc < 0)
{
PRINTF_ERR("IicReadData() error %d\n", rc);
}
}
else
{
PRINTF_ERR("i2c client is NULL\n");
}
#elif defined(CONFIG_TOUCH_DRIVER_RUN_ON_MTK_PLATFORM)
if (g_I2cClient != NULL)
{
u8 nAddrBefore = g_I2cClient->addr;
g_I2cClient->addr = nSlaveId;
// g_I2cClient->addr = (g_I2cClient->addr & I2C_MASK_FLAG) | (I2C_ENEXT_FLAG);
#ifdef CONFIG_ENABLE_DMA_IIC
if (nSize > 8 && NULL != I2CDMABuf_va)
{
s32 i = 0;
g_I2cClient->ext_flag = g_I2cClient->ext_flag | I2C_DMA_FLAG;
rc = i2c_master_recv(g_I2cClient, (unsigned char *)I2CDMABuf_pa, nSize);
for (i = 0; i < nSize; i ++)
{
pBuf[i] = I2CDMABuf_va[i];
}
}
else
{
g_I2cClient->ext_flag = g_I2cClient->ext_flag & (~I2C_DMA_FLAG);
rc = i2c_master_recv(g_I2cClient, pBuf, nSize);
}
#else
rc = i2c_master_recv(g_I2cClient, pBuf, nSize);
#endif //CONFIG_ENABLE_DMA_IIC
g_I2cClient->addr = nAddrBefore;
if (rc < 0)
{
PRINTF_ERR("IicReadData() error %d, nSlaveId=%d, nSize=%d\n", rc, nSlaveId, nSize);
}
}
else
{
PRINTF_ERR("i2c client is NULL\n");
}
#endif
return rc;
}
void mstpMemSet(void *pDst, s8 nVal, u32 nSize)
{
memset(pDst, nVal, nSize);
}
void mstpMemCopy(void *pDst, void *pSource, u32 nSize)
{
memcpy(pDst, pSource, nSize);
}
void mstpDelay(u32 nTime)
{
mdelay(nTime);
}
//------------------------------------------------------------------------------//
|