source: svn/trunk/zas_dstar/hal/platform/dstddsys.c @ 2

Last change on this file since 2 was 2, checked in by phkim, 11 years ago

1.phkim

  1. revision copy newcon3sk r27
File size: 14.4 KB
Line 
1/******************************************************************************
2 *_Copyright (c) 2009 Digital Stream Technology Inc. All Rights Reserved.
3 *
4 * Module: dstdd
5 *
6 * Description
7 *
8 * @author
9 * @version $Revision: 1.1 $
10 *
11 ******************************************************************************/
12
13#include <stdio.h>
14#include <stdlib.h>
15#include <fcntl.h>
16#include <getopt.h>
17#include <sys/ioctl.h>
18#include <sys/time.h>
19#include <string.h>
20#include <unistd.h>
21#ifndef USE_CYGWIN
22#include <linux/types.h>
23#include <linux/ioctl.h>
24#endif
25
26#include "dsthalcommon.h"
27#include "dstddsys.h"
28#include "dstddgpio.h"
29#include "dstddcap.h"
30#include "dstdddtv.h"
31
32/******************************************************************************
33 * Global variable declaration
34 ******************************************************************************/
35
36/******************************************************************************
37 * Imported variable declaration
38 ******************************************************************************/
39extern int gdhlSysDbgLvl;
40
41/******************************************************************************
42 * Imported function declaration
43 ******************************************************************************/
44
45/******************************************************************************
46 * Local definitions
47 ******************************************************************************/
48
49/******************************************************************************
50 * Local typedefs
51 ******************************************************************************/
52
53/******************************************************************************
54 * Local variables declaration
55 ******************************************************************************/
56static int s_DebugMode;
57static int MAX_GPIO_NUM;
58static GPIO_DESC_t *pGPIOConfig;
59static GPIO_DESC_t GPIOConfig_R0_1[] = {
60        /*      GPIO_NAME                       "strPinName"            iPinGroup       iPinNum         iPinDirection   iPinReset */
61        { GPIO_WI_SDI,                  "WI_SDI",                       GPIO_31_0,      0,                      GPIO_INPUT,             2               },
62        { GPIO_WI_SCLK,         "WI_SCLK",          GPIO_31_0,  1,                      GPIO_OUTPUT,    2   },
63        { GPIO_WI_SSB,          "WI_SSB",           GPIO_31_0,  2,                      GPIO_OUTPUT,    2   },
64        { GPIO_WI_SDO,          "WI_SDO",           GPIO_31_0,  3,                      GPIO_OUTPUT,    2   },
65        { GPIO_HW_BIT0,         "HW_BIT0",          GPIO_31_0,  4,                      GPIO_INPUT,             2   },
66        { GPIO_HW_BIT1,         "HW_BIT1",          GPIO_31_0,  5,                      GPIO_INPUT,             2   },
67        { GPIO_HW_BIT2,             "HW_BIT2",          GPIO_31_0,      6,                      GPIO_INPUT,             2   },
68        { GPIO_NAND_RDY,        "NAND_RDY",         GPIO_31_0,  7,                      GPIO_PWMOUT,    2   },
69        { GPIO_1024_DK,         "1024_DK",              GPIO_31_0,      8,                      GPIO_OUTPUT,    0   },
70        { GPIO_1024_OE,                 "1024_OE",                      GPIO_31_0,      9,                      GPIO_OUTPUT,    1   },
71        { GPIO_HDMI_TX_RESET,   "HDMI_TX_RESET",    GPIO_31_0,  10,                     GPIO_OUTPUT,    1   },
72        { GPIO_HDMI_TX_INT,     "HDMI_TX_INT",      GPIO_31_0,  11,                     GPIO_INPUT,             2   },
73        { GPIO_DEMOD_RESETN,    "DEMOD_RESETN",     GPIO_31_0,  12,                     GPIO_OUTPUT,    0   },
74        { GPIO_AP_RESETN,       "AP_RESETN",        GPIO_31_0,  13,                     GPIO_OUTPUT,    0   },
75        { GPIO_MICOM_INT,       "MICOM_INT",        GPIO_31_0,  14,                     GPIO_INPUT,             2   },
76        { GPIO_HDMI_SW_EQ,      "HDMI_SW_EQ",       GPIO_31_0,  15,                     GPIO_OUTPUT,    1   },
77        { GPIO_HDMI_S1,             "HDMI_S1",                  GPIO_31_0,      16,                     GPIO_OUTPUT,    1   },
78        { GPIO_HDMI_S2,         "HDMI_S2",              GPIO_31_0,      17,                     GPIO_OUTPUT,    0   },
79        { GPIO_HDMI_HPD,        "HDMI_HPD",             GPIO_31_0,      18,                     GPIO_OUTPUT,    0   },
80        { GPIO_SPDIF_SEL,       "SPDIF_SEL",        GPIO_31_0,  19,                     GPIO_OUTPUT,    1   },
81        { GPIO_EDID_WR_EN,      "EDID_WR_EN",       GPIO_31_0,  20,                     GPIO_OUTPUT,    0   },
82        { GPIO_1024_MODE,       "GPIO_1024_MODE",       GPIO_31_0,      21,                     GPIO_OUTPUT,    0   },
83        { GPIO_CEC_ON,          "GPIO_CEC_ON",          GPIO_31_0,      22,                     GPIO_INPUT,             2   },
84};
85
86/******************************************************************************
87 * Local function prototypes
88 ******************************************************************************/
89DHL_RESULT DD_SYS_InitGPIO(void);
90
91#if 0
92___Common_Functions___()
93#endif
94DHL_RESULT DD_SYS_Initiate(void)
95{
96        DHL_RESULT dhlResult = DHL_OK;
97
98
99        //
100        // GPIO_SELECT and check HW_BIT
101        //
102       
103    pGPIOConfig = GPIOConfig_R0_1;
104
105        return dhlResult;
106}
107
108DHL_RESULT DD_SYS_CheckDevice(void)
109{
110        return DHL_OK;
111}
112
113DHL_RESULT DD_SYS_Terminate(void)
114{
115        DHL_RESULT dhlResult = DHL_OK;
116       
117        exit(0);
118
119    SysNEVER_GET_HERE();
120        return dhlResult;
121}
122
123DHL_RESULT DD_SYS_SetDbgLvl(DS_U32 uDbgLvl)
124{
125        DHL_RESULT dhlResult = DHL_OK;
126       
127        return dhlResult;
128}
129
130DHL_RESULT DD_SYS_Reset(void)
131{
132        DHL_RESULT dhlResult = DHL_OK;
133       
134        return dhlResult;
135}
136
137DHL_RESULT DD_SYS_SetPWM(int Period, int Duty)
138{
139        DHL_RESULT dhlResult = DHL_OK;
140
141        return dhlResult;
142}
143
144DHL_RESULT DD_SYS_SetADIM(DS_U16 Period)
145{
146        DHL_RESULT dhlResult = DHL_OK;
147       
148        return dhlResult;
149}
150
151DS_U32 DD_SYS_GetLoaderVer(void)
152{
153        return OS_GetLoaderVer();
154}
155
156DS_U32 DD_SYS_GetDrvVenVersion(void)
157{
158    /*
159     * Shall return Vendor-supplied driver version.
160     */
161
162        return 0;
163}
164
165DS_U32 DD_SYS_GetDrvDstVersion(void)
166{
167    /*
168     * Shall return DST Tag Number for vendor-supplied driver.
169     */
170     
171        return 0;
172}
173
174DHL_RESULT DD_SYS_IsUsbValid(void)
175{
176        static DHL_RESULT dhlResult = DHL_FAIL;
177
178        return dhlResult;
179}
180
181DHL_RESULT DD_SYS_InitGPIO(void)
182{
183        DHL_RESULT dhlResult = DHL_OK;
184        int i;
185       
186        for (i=0; i<MAX_GPIO_NUM; i++)
187        {
188                if ( pGPIOConfig[i].iPinDirection == GPIO_OUTPUT && pGPIOConfig[i].iPinReset != 2 ) 
189                {
190                    /*
191                     * Do apply reset value on the Output GPIO.
192                     */
193                     
194                }
195               
196                switch( pGPIOConfig[i].iPinDirection ) {
197                        case GPIO_INPUT:  break;
198                        case GPIO_OUTPUT: break;
199                        case GPIO_PWMOUT: break;
200                        default:
201                                printf("|%s| ERROR: Invalid GPIO mode. LINE=%d (i=%d)\n", __FUNCTION__, __LINE__, i);
202                                return DHL_FAIL;
203                }
204               
205                /*
206                 * Change GPIO direction be pGPIOConfig[i].iPinDirection.
207                 */
208                 
209        }
210                       
211        return dhlResult;
212}
213
214DHL_RESULT DD_SYS_SetGPIO( int GpioNum, int Value )
215{
216        DHL_RESULT dhlResult = DHL_OK;
217        int i;
218
219        if ( GpioNum < 0 /*|| GpioNum > (MAX_GPIO_NUM+1)*/ ) {
220                DHL_DbgPrintf(gdhlSysDbgLvl,DHLDBG_SYS, "Invalid GPIO Number: tried num=0x%x\n", GpioNum );
221                Value = -1;
222                goto done;
223        }
224
225    /*
226     * Find GPIO entry in GPIO Table.
227     */
228    for (i=0; i<MAX_GPIO_NUM; i++) 
229    {
230        if ( pGPIOConfig[i].iGpioName == GpioNum )
231            break;
232    }
233   
234    if ( i == MAX_GPIO_NUM ) {
235        printf("Invalid GPIO Number: tried num=%d\n", GpioNum);
236        dhlResult = DHL_FAIL;
237        goto done;
238    }
239
240    /*
241     * Save last value into pGPIOConfig[i].iPinReset field.
242     */
243    pGPIOConfig[i].iPinReset = Value;
244
245    /*
246     * Make Output GPIO be high or low based on the Value argument.
247     */
248   
249done:
250        return dhlResult;
251}
252
253DHL_RESULT DD_SYS_SetGPIODefault( int GpioNum )
254{
255    DHL_RESULT dhlResult = DHL_OK;
256    int i;
257   
258        if ( GpioNum < 0 /*|| GpioNum > (MAX_GPIO_NUM+1)*/ ) 
259        {
260                DHL_DbgPrintf(gdhlSysDbgLvl,DHLDBG_SYS, "Invalid GPIO Number: tried num=0x%x\n", GpioNum );
261                goto done;
262        }
263
264    /*
265     * Find GPIO entry in GPIO Table.
266     */
267    for (i=0; i<MAX_GPIO_NUM; i++) 
268    {
269        if ( pGPIOConfig[i].iGpioName == GpioNum )
270            break;
271    }
272   
273    if ( i == MAX_GPIO_NUM ) 
274    {
275        printf("Invalid GPIO Number: tried num=%d\n", GpioNum);
276        dhlResult = DHL_FAIL;
277        goto done;
278    }
279   
280    DD_SYS_SetGPIO( GpioNum, pGPIOConfig[i].iPinReset );
281   
282done:
283    return dhlResult;
284}
285
286int DD_SYS_GetGPIO( int GpioNum )
287{
288        unsigned char v=0;
289        int i;
290       
291    /*
292     * Find GPIO entry in GPIO Table.
293     */
294    for (i=0; i<MAX_GPIO_NUM; i++) 
295    {
296        if ( pGPIOConfig[i].iGpioName == GpioNum )
297            break;
298    }
299
300    if ( i == MAX_GPIO_NUM ) 
301    {
302        printf("Invalid GPIO Number: tried num=%d\n", GpioNum);
303        return -1;
304    }
305   
306    /*
307     * Get current value from INPUT-GPIO.
308     */
309
310        return (int)v;
311}
312
313int DD_SYS_GetGPIOOut(int GpioNum)
314{
315        int i;
316        int Value = 0;
317       
318    /*
319     * Find GPIO entry in GPIO Table.
320     */
321    for (i=0; i<MAX_GPIO_NUM; i++) 
322    {
323        if ( pGPIOConfig[i].iGpioName == GpioNum )
324            break;
325    }
326
327    if ( i == MAX_GPIO_NUM ) 
328    {
329        printf("Invalid GPIO Number: tried num=%d\n", GpioNum);
330        return DHL_FAIL;
331    }
332
333    /*
334     * Get current value from OUTPUT-GPIO.
335     * This is to get the value from Open-Drain output GPIO.
336     */
337
338        return Value;
339}
340
341char *DD_SYS_GetGPIOName( int GpioNum )
342{
343        int i;
344        char *ptr;
345
346        if ( GpioNum < 0 || GpioNum > (GPIO_MAX) ) 
347        {
348                DHL_DbgPrintf(gdhlSysDbgLvl,DHLDBG_SYS, "Invalid GPIO Number: tried num=0x%x\n", GpioNum );
349                return (char *)0;
350        }
351
352    /*
353     * Find GPIO entry in GPIO Table.
354     */
355    for (i=0; i<MAX_GPIO_NUM; i++) 
356    {
357        if ( pGPIOConfig[i].iGpioName == GpioNum )
358            break;
359    }
360
361    if ( i == MAX_GPIO_NUM ) {
362        printf("Invalid GPIO Number: tried num=%d\n", GpioNum);
363        return (char *)0;
364    }
365
366        ptr = pGPIOConfig[i].strPinName;       
367        return ptr;
368}
369
370int DD_SYS_FindGPIONum( const char *gpioName )
371{
372        int i;
373       
374        if ( !gpioName ) {
375                DHL_DbgPrintf(gdhlSysDbgLvl,DHLDBG_SYS, "ERROR: argument is null pointer.\n");
376                return -1;
377        }
378       
379        for (i=0; i<MAX_GPIO_NUM; i++) {
380                if ( strncmp( gpioName, pGPIOConfig[i].strPinName, strlen(gpioName) ) == 0 )
381                        break;
382        }
383       
384        if ( i==MAX_GPIO_NUM )
385                return -1;
386               
387        return i;
388}
389
390void *DD_SYS_PhyMemAlloc(int size)
391{
392        return malloc(size);
393}
394
395void DD_SYS_PhyMemFree(void *addr)
396{
397        free(addr);
398}
399
400void DD_SYS_SetDebugMode(int bOnOff)
401{
402        s_DebugMode = bOnOff;
403}
404
405int DD_SYS_IsDebugMode(void)
406{
407        return s_DebugMode;
408}
409
410void hdumpgpio(void)
411{
412        int i;
413
414        printf( "|Idx|       Name      |Pin#| DIR |ResetValue|\n");
415        for(i=GPIO_MIN; i<=GPIO_MAX; i++) 
416        {
417            if ( DD_SYS_GetGPIOName(i) == (char *)0 )
418                continue;
419                printf( "|%3d| %-15s | %2d | %-3s |         %d|\n", i, DD_SYS_GetGPIOName(i), pGPIOConfig[i].iPinNum, pGPIOConfig[i].iPinDirection == GPIO_PWMOUT ? "PWM" : pGPIOConfig[i].iPinDirection == GPIO_OUTPUT ? "OUT" : "IN", pGPIOConfig[i].iPinReset);
420    }
421}
422
423static int isI2cM_Init = 0;
424int DD_SYS_I2cInit(void)
425{
426        int ret = 0;
427       
428        if ( isI2cM_Init == 1 ) 
429        {
430            printf("|%s| This function is called twice or more.\n", __FUNCTION__);
431                return ret;
432        }
433
434    /*
435     * Call the vendor-supplied I2C initialization driver APIs here.
436     */
437   
438   
439        isI2cM_Init = 1; 
440       
441        return ret;
442}
443
444int DD_SYS_I2cWrite(int i2cBus, unsigned char addr, int nSubAddress, int subAddress, unsigned char *buf, int len)
445{
446        unsigned char sub[4];
447        int ret;
448       
449        if ( isI2cM_Init == 0 ) 
450        {
451                ret = DD_SYS_I2cInit();
452                if ( ret < 0 )
453                        return -1;
454        }
455       
456        if ( i2cBus != 0 && i2cBus != 1 ) 
457        {
458                printf("|%s| INVALID PARAM, i2cBus = %d\n", __FUNCTION__, i2cBus);
459                return -1;
460        }
461
462    switch (nSubAddress)
463    {
464        case 0:
465            /* Without SubAddress */
466            break;
467       
468        case 1:
469            /* 8-bit SubAddress */
470            sub[0] = subAddress & 0xFF;
471            break;
472       
473        case 2:
474            /* 16-bit SubAddress */
475            sub[0] = subAddress & 0xFF;
476            sub[1] = (subAddress>>8) & 0xFF;
477            break;
478       
479        case 3:
480            /* 24-bit SubAddress */
481            sub[0] = subAddress & 0xFF;
482            sub[1] = (subAddress>>8) & 0xFF;
483            sub[2] = (subAddress>>16) & 0xFF;
484            break;
485       
486        default:
487            break;
488    }
489       
490        /*
491         * Call the lower I2C drivers.
492         */
493        ret = len;
494       
495        return ret;
496}
497
498int DD_SYS_I2cRead(int i2cBus, unsigned char addr, int isSubAddress, int subAddress, unsigned char *buf, int len)
499{
500        //unsigned char sub[4];
501        int ret = 0;
502       
503        if ( isI2cM_Init == 0 ) 
504        {
505                ret = DD_SYS_I2cInit();
506                if ( ret < 0 )
507                        return -1;
508        }
509       
510        if ( i2cBus != 0 && i2cBus != 1 ) 
511        {
512                printf("|%s| INVALID PARAM, i2cBus = %d\n", __FUNCTION__, i2cBus);
513                return -1;
514        }
515       
516        /*
517         * Call the lower I2C drivers.
518         */
519        ret = len;
520       
521    return ret;
522}
523
524DHL_RESULT DD_SYS_SetI2CSpeed(unsigned char bus, unsigned int speed)
525{
526        DHL_RESULT dhlResult = DHL_OK;
527       
528        if ( bus != 0 && bus != 1 ) {
529                printf("|%s| INVALID PARAM, i2cBus = %d\n", __FUNCTION__, bus);
530                return -1;
531        }
532       
533        /*
534         * Call the lower I2C drivers.
535         */
536       
537        return dhlResult;
538}
539
540char *DD_SYS_GetSystemErrorCode(DS_U8 ErrCode)
541{
542        return "NOT_IMPLEMENTED";
543}
544
545void DD_SYS_SetRegister8(DS_U32 Addr, DS_U8 Value)
546{
547        OS_WriteRegisterByte(Addr, Value);
548}
549
550void DD_SYS_SetRegister16(DS_U32 Addr, DS_U16 Value)
551{
552        DS_U32 regAddr;
553       
554        if ( Addr & 1 ) 
555        {
556                printf("|%s| Address is not aligned: 0x%08lX\n", __FUNCTION__, Addr );
557                return;
558        }
559
560    regAddr = Addr;
561   
562        OS_WriteRegisterWord(regAddr, Value);
563}
564
565void DD_SYS_SetRegister32(DS_U32 Addr, DS_U32 Value)
566{
567        DS_U32 regAddr = Addr;
568       
569        if ( Addr & 3 ) 
570        {
571                printf("|%s| Address is not aligned: 0x%08lX\n", __FUNCTION__, Addr );
572                return;
573        }
574
575        OS_WriteRegister(regAddr, Value);
576}
577
578DS_U8 DD_SYS_GetRegister8(DS_U32 Addr)
579{
580        return OS_ReadRegisterByte(Addr);
581}
582
583DS_U16 DD_SYS_GetRegister16(DS_U32 Addr)
584{
585        DS_U32 regAddr;
586       
587        if ( Addr & 1 ) 
588        {
589                printf("|%s| Address is not aligned: 0x%08lX\n", __FUNCTION__, Addr );
590                return (DS_U16)-1;
591        }
592
593#if 0
594        regAddr = Addr & (~2);
595        regAddr += (~(Addr & 2)) & 2;
596#else
597    regAddr = Addr;
598#endif
599
600        return OS_ReadRegisterWord(regAddr);
601}
602
603DS_U32 DD_SYS_GetRegister32(DS_U32 Addr)
604{
605        DS_U32 regAddr = Addr;
606       
607        if ( Addr & 3 ) 
608        {
609                printf("|%s| Address is not aligned: 0x%08lX\n", __FUNCTION__, Addr );
610                return (DS_U32)-1;
611        }
612
613        return OS_ReadRegister(regAddr);
614}
615
616typedef struct tagTaskStruct {
617        int pid;
618        char comm[16];
619        char state;
620        int ppid, pgrp, session;
621        int flags;
622        unsigned int esp, eip; 
623        int priority;
624} TaskStruct;
625
626TaskStruct task;
627static char stat_buffer[256];
628int print_stat(int pid)
629{
630        int fd;
631        char pathname[256];
632        int n;
633        int dummy;
634       
635        sprintf(pathname, "/proc/%d/stat", pid);
636        fd = open(pathname, O_RDONLY);
637        if ( fd < 0 ) {
638                printf("ERROR: open() = -1\n");
639                return -1;
640        }
641       
642        n = read(fd, stat_buffer, 256);
643        if ( n <= 0 )
644                return -1;
645       
646       
647       
648       
649       
650        sscanf(stat_buffer,"%d %s %c %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d\n", 
651                &task.pid,
652                task.comm,
653                &task.state,
654                &task.ppid,
655                &task.pgrp,
656                &dummy,
657                &dummy,
658                &dummy,
659                &dummy,
660                &dummy,
661                &dummy,
662                &dummy,
663                &dummy,
664                &dummy,
665                &dummy,
666                &dummy,
667                &dummy,
668                &task.priority,
669                &dummy,
670                &dummy,
671                &dummy,
672                &dummy,
673                &dummy,
674                &dummy,
675                &dummy,
676                &dummy,
677                &dummy,
678                &dummy,
679                &task.esp,
680                &task.eip,
681                &dummy,
682                &dummy,
683                &dummy,
684                &dummy,
685                &dummy,
686                &dummy,
687                &dummy,
688                &dummy,
689                &dummy);
690
691        printf("Task: %s (%d) (%c), Priority:%d, SP:0x%08lX, IP:0x%08lX, PPID: %d\n", task.comm, task.pid, task.state, task.priority, (unsigned long)task.esp, (unsigned long)task.eip, task.ppid);
692
693        return 0;
694}
Note: See TracBrowser for help on using the repository browser.