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
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
|
/**************************************************************
spi_os.c
adapt os api and spi api
This is MATER side.
***************************************************************/
/**************************************************************
Preprocessor by common
***************************************************************/
#include "spi_main.h"
#include "spi_os.h"
/**************************************************************
Preprocessor by platform
(Android)
***************************************************************/
#include <linux/vmalloc.h>
#include <linux/spi/spi.h>
#include <linux/gpio.h>
#include <linux/delay.h>
#include <linux/in.h>
#include <linux/time.h>
/**********************************************************
Prototype void * spi_os_malloc ( unsigned int length )
Type function
Description allocate memory
Param input length : length of size
Return value 0 : fail
(other) : address of memory allocated
***********************************************************/
void *spi_os_malloc(unsigned int length)
{
if (length <= 0) {
SPI_OS_ERROR(("[SPI] ERROR : spi_os_malloc fail : len 0\n"));
return 0;
}
return kmalloc(length, GFP_ATOMIC);
}
/*====================================
Prototype void * spi_os_vmalloc ( unsigned int length )
Type function
Description allocate memory with vmalloc
Param input length : length of size
Return value 0 : fail
(other) : address of memory allocated
====================================*/
void *spi_os_vmalloc(unsigned int length)
{
if (length <= 0) {
SPI_OS_ERROR(("spi_os_malloc fail : length is 0\n"));
return 0;
}
return vmalloc(length);
}
/**********************************************************
Prototype int spi_os_free ( void * addr )
Type function
Description free memory
Param input addr : address of memory to be released
Return value 0 : fail
1 : success
***********************************************************/
int spi_os_free(void *addr)
{
if (addr == 0) {
SPI_OS_ERROR(("[SPI] ERROR : spi_os_free fail : addr is 0\n"));
return 0;
}
kfree(addr);
return 1;
}
/**********************************************************
Prototype int spi_os_vfree ( void * addr )
Type function
Description free memory with vfree
Param input addr : address of memory to be released
Return value 0 : fail
1 : success
***********************************************************/
int spi_os_vfree(void *addr)
{
if (addr == 0) {
SPI_OS_ERROR(("spi_os_free fail : addr is 0\n"));
return 0;
}
#ifdef SPI_FEATURE_OMAP4430
vfree(addr);
#elif defined SPI_FEATURE_SC8800G
SCI_FREE(addr);
#endif
return 1;
}
/**********************************************************
Prototype int spi_os_memcpy ( void * dest, void * src, unsigned int length )
Type function
Description copy memory
Param input dest : address of memory to be save
src : address of memory to copy
length : length of memory to copy
Return value 0 : fail
1 : success
***********************************************************/
int spi_os_memcpy(void *dest, void *src, unsigned int length)
{
if (dest == 0 || src == 0) {
SPI_OS_ERROR(("[SPI] ERROR : spi_os_memcpy fail\n"));
return 0;
}
memcpy(dest, src, length);
return 1;
}
/**********************************************************
Prototype void * spi_os_memset ( void * addr, int value, unsigned int length )
Type function
Description set memory as parameter
Param input addr : address of memory to be set
value : value to set
length : length of memory to be set
Return value (none)
***********************************************************/
void *spi_os_memset(void *addr, int value, unsigned int length)
{
if (addr == 0) {
SPI_OS_ERROR(("[SPI] ERROR : spi_os_memcpy fail\n"));
return 0;
}
return memset(addr, value, length);
}
/**********************************************************
Prototype int spi_os_create_mutex( char * name, unsigned int priority_inherit )
Type function
Description create mutex
Param input name : name of mutex
priority_inherit : mutex inheritance
Return value id of mutex created
***********************************************************/
int spi_os_create_mutex(char *name, unsigned int priority_inherit)
{
if (name == 0) {
SPI_OS_ERROR(("[SPI] ERROR : spi_os_memcpy fail\n"));
return 0;
}
return 0;
}
/**********************************************************
Prototype int spi_os_delete_mutex ( int pmutex )
Type function
Description delete mutex
Param input pmutex : id of mutex
Return value 0 : success
1 : fail
***********************************************************/
int spi_os_delete_mutex(int pmutex)
{
return 0;
}
/**********************************************************
Prototype int spi_os_acquire_mutex ( int pmutex, unsigned int wait )
Type function
Description acquire mutex
Param input pmutex : id of mutex to acquire
wait : mutex waiting time
Return value 0 : success
1 : fail
***********************************************************/
int spi_os_acquire_mutex(int pmutex, unsigned int wait)
{
return 0;
}
/**********************************************************
Prototype int spi_os_release_mutex (int pmutex )
Type function
Description release mutex
Param input pmutex : id of mutex to release
Return value 0 : success
1 : fail
***********************************************************/
int spi_os_release_mutex(int pmutex)
{
return 0;
}
/**********************************************************
Prototype int spi_os_create_sem ( char * name, unsigned int init_count)
Type function
Description create semaphore
Param input name : name of semaphore
init_count : semaphore count
Return value id of semaphore created
***********************************************************/
int spi_os_create_sem(char *name, unsigned int init_count)
{
if (name == 0) {
SPI_OS_ERROR(("[SPI] ERROR : spi_os_memcpy fail\n"));
return 0;
}
return 0;
}
/**********************************************************
Prototype int spi_os_delete_sem ( int sem )
Type function
Description delete semaphore
Param input sem : id of semaphore to delete
Return value 0 : success
1 : fail
***********************************************************/
int spi_os_delete_sem(int sem)
{
return 0;
}
/**********************************************************
Prototype int spi_os_acquire_sem (int sem, unsigned int wait )
Type function
Description acquire semaphore
Param input sem : id of semaphore to acquire
wait : mutex waiting time
Return value 0 : success
1 : fail
***********************************************************/
int spi_os_acquire_sem(int sem, unsigned int wait)
{
return 0;
}
/**********************************************************
Prototype int spi_os_release_sem (int sem )
Type function
Description release semaphore
Param input sem : id of semaphore to release
Return value 0 : success
1 : fail
***********************************************************/
int spi_os_release_sem(int sem)
{
return 0;
}
/**********************************************************
Prototype void spi_os_sleep ( unsigned long msec )
Type function
Description sleep os
Param input msec : time to sleep
Return value (none)
***********************************************************/
void spi_os_sleep(unsigned long msec)
{
if (msec <= 0) {
SPI_OS_ERROR(("[SPI] ERROR : spi_os_sleep fail\n"));
return;
}
msleep(msec);
}
/**********************************************************
Prototype void spi_os_loop_delay ( unsigned long cnt )
Type function
Description delay task with loop
Param input cnt : delay count
Return value (none)
***********************************************************/
void spi_os_loop_delay(unsigned long cnt)
{
unsigned int timeout;
timeout = 0;
while (++timeout < cnt)
;
}
/**********************************************************
Prototype void * spi_os_create_timer
Type function
Description create timer
Param input name : timer name
callback : timer callback function
param : timer param
duration : timer expire duration
Return value timer ptr
***********************************************************/
int spi_os_create_timer(void *timer, char *name,
SPI_OS_TIMER_T callback, int param, unsigned long duration)
{
struct timer_list *tm = timer;
if (name == 0 || callback == 0 || param <= 0 || duration <= 0) {
SPI_OS_ERROR(("[SPI] ERROR : spi_os_create_timer fail\n"));
return 0;
}
init_timer(tm);
tm->expires = jiffies + ((duration * HZ) / 1000);
tm->data = (unsigned long) param;
tm->function = callback;
return 1;
}
/**********************************************************
Prototype int spi_os_start_timer
Type function
Description start timer
Param input timer : timer ptr
callback : timer callback function
param : timer param
duration : timer expire duration
Return value 1 : success
0 : fail
***********************************************************/
int spi_os_start_timer(void *timer, SPI_OS_TIMER_T callback,
int param, unsigned long duration)
{
add_timer((struct timer_list *) timer);
return 1;
}
/**********************************************************
Prototype int spi_os_stop_timer (void * timer)
Type function
Description stop timer
Param input timer : timer ptr
Return value 1 : success
0 : fail
***********************************************************/
int spi_os_stop_timer(void *timer)
{
int value = 0;
value = del_timer((struct timer_list *) timer);
return value;
}
/**********************************************************
Prototype int spi_os_delete_timer (void * timer)
Type function
Description delete timer
Param input timer : timer ptr
Return value 1 : success
0 : fail
***********************************************************/
int spi_os_delete_timer(void *timer)
{
return 1;
}
/**********************************************************
Prototype unsigned long spi_os_get_tick (void)
Type function
Description get system tick
Param input (none)
Return value system tick
***********************************************************/
unsigned long spi_os_get_tick(void)
{
unsigned long tick = 0;
tick = jiffies_to_msecs(jiffies);
return tick;
}
/**********************************************************
Prototype void spi_os_get_tick_by_log (char * name)
Type function
Description print tick time to log
Param input name : print name
Return value (none)
***********************************************************/
void spi_os_get_tick_by_log(char *name)
{
SPI_OS_TRACE(("[SPI] %s tick %lu ms\n", name, spi_os_get_tick()));
}
/**********************************************************
Prototype void spi_os_trace_dump (char * name, void * data, int length)
Description print buffer value by hex code
if buffer size too big, it change to....
and print 64 byte of front and 64 byte of tail
Param input name : print name
data : buffer for print
length : print length
Return value (none)
***********************************************************/
void spi_os_trace_dump(char *name, void *data, int length)
{
#ifdef SPI_FEATURE_DEBUG
#define SPI_OS_TRACE_DUMP_PER_LINE 16
#define SPI_OS_TRACE_MAX_LINE 8
#define SPI_OS_TRACE_HALF_LINE
(SPI_OS_TRACE_MAX_LINE / 2)
#define SPI_OS_TRACE_MAX_DUMP_SIZE
(SPI_OS_TRACE_DUMP_PER_LINE*SPI_OS_TRACE_MAX_LINE)
int i = 0, lines = 0, halflinemode = 0;
char buf[SPI_OS_TRACE_DUMP_PER_LINE * 3 + 1];
char *pdata = NULL;
char ch = 0;
SPI_OS_TRACE_MID(("[SPI] spi_os_trace_dump (%s length[%d])\n",
name, length));
spi_os_memset(buf, 0x00, sizeof(buf));
if (length > SPI_OS_TRACE_MAX_DUMP_SIZE)
halflinemode = 1;
pdata = data;
for (i = 0 ; i < length ; i++) {
if ((i != 0) && ((i % SPI_OS_TRACE_DUMP_PER_LINE) == 0)) {
buf[SPI_OS_TRACE_DUMP_PER_LINE*3] = 0;
SPI_OS_TRACE_MID(("%s\n", buf));
spi_os_memset(buf, 0x00, sizeof(buf));
lines++;
if (SPI_OS_TRACE_HALF_LINE == lines
&& halflinemode == 1) {
SPI_OS_TRACE_MID((" ......\n"));
pdata += (length - SPI_OS_TRACE_MAX_DUMP_SIZE);
i += (length - SPI_OS_TRACE_MAX_DUMP_SIZE);
}
}
ch = (*pdata&0xF0)>>4;
buf[(i%SPI_OS_TRACE_DUMP_PER_LINE)*3] =
((ch > 9) ? (ch-10 + 'A') : (ch + '0'));
ch = (*pdata&0x0F);
buf[(i%SPI_OS_TRACE_DUMP_PER_LINE)*3+1] =
((ch > 9) ? (ch-10 + 'A') : (ch + '0'));
buf[(i%SPI_OS_TRACE_DUMP_PER_LINE)*3+2] = 0x20;
pdata++;
}
if (buf[0] != '\0')
SPI_OS_TRACE_MID(("%s\n", buf));
#undef SPI_OS_TRACE_DUMP_PER_LINE
#undef SPI_OS_TRACE_MAX_LINE
#undef SPI_OS_TRACE_HALF_LINE
#undef SPI_OS_TRACE_MAX_DUMP_SIZE
#endif
}
/**********************************************************
Prototype void spi_os_trace_dump (char * name, void * data, int length)
Description print buffer value by hex code as SPI_OS_TRACE
this function print only 16 byte
Param input name : print name
data : buffer for print
length : print length
Return value (none)
***********************************************************/
void spi_os_trace_dump_low(char *name, void *data, int length)
{
#define SPI_OS_TRACE_DUMP_PER_LINE 16
int i = 0;
char buf[SPI_OS_TRACE_DUMP_PER_LINE * 3 + 1] = {0,};
char *pdata = NULL;
char ch = 0;
SPI_OS_ERROR(("[SPI] spi_os_trace_dump_low (%s length[%d])\n",
name, length));
spi_os_memset(buf, 0x00, sizeof(buf));
if (length > SPI_OS_TRACE_DUMP_PER_LINE)
length = SPI_OS_TRACE_DUMP_PER_LINE;
pdata = data;
for (i = 0 ; i < length ; i++) {
ch = (*pdata&0xF0)>>4;
buf[(i%SPI_OS_TRACE_DUMP_PER_LINE)*3] =
((ch > 9) ? (ch-10 + 'A') : (ch + '0'));
ch = (*pdata&0x0F);
buf[(i%SPI_OS_TRACE_DUMP_PER_LINE)*3+1] =
((ch > 9) ? (ch-10 + 'A') : (ch + '0'));
buf[(i%SPI_OS_TRACE_DUMP_PER_LINE)*3+2] = 0x20;
pdata++;
}
if (buf[0] != '\0')
SPI_OS_ERROR(("%s\n", buf));
#undef SPI_OS_TRACE_DUMP_PER_LINE
}
|