xref: /utopia/UTPA2-700.0.x/modules/dscmb/api/nsk2hdi/nsk2hdi_otp.c (revision 53ee8cc121a030b8d368113ac3e966b4705770ef)
1 
2 
3 #include <stdlib.h>
4 #include <string.h>
5 #include "MsCommon.h"
6 
7 #include "nsk_dbg.h"
8 
9 #include "nsk_282.h"
10 #include "nsk_dbg.h"
11 #include "nsk_3014.h"
12 #include "hdi_121.h"
13 #include "drvNSK2.h"
14 #include "nsk2hdi_header.h"
15 #include "drvCA.h"
16 #include "drvNSK2.h"
17 
18 
19 /*****************************************************************************\
20   \Definitions
21 \*****************************************************************************/
22 
23 
24 /*****************************************************************************\
25   \ global variables
26 \*****************************************************************************/
27 
28 /*****************************************************************************\
29   \ NSK2HDI otp related functions
30 \*****************************************************************************/
31 /*****************************************************************************\
32   \ OTP device
33 \*****************************************************************************/
34 
35 #define USEDrvFunction
36 
37 #ifndef USEDrvFunction
38 #define OTP_REG(addr)            (*((volatile MS_U32*)(0xbf320000 + addr )))
39 #define OTP_REG8(addr)           (*((volatile MS_U8*)(0xbf320000 + addr )))
40 #endif
41 
42 extern MS_U32 NSKHDI_GetHandle(NSK2HDI_HANDLE Handle);
43 
44 
45 #define MaxOTPHandleNum    10
46 
47 
48 typedef struct _OTP_Info_
49 {
50     MS_BOOL         alloc;
51     NDS_ULONG       Otp_ID;
52     MS_U32          handle_id;
53 } OTP_Info;
54 
55 
56 OTP_Info OTPInfo[MaxOTPHandleNum];
57 
NSKHDI_OtpDevice_Open(NSK2HDI_DEVICE_ID Otp_ID,NSK2HDI_HANDLE * Otp_handle)58 NSK2HDI_STATUS NSKHDI_OtpDevice_Open (NSK2HDI_DEVICE_ID   Otp_ID,
59                                       NSK2HDI_HANDLE      *Otp_handle)
60 {
61     NSK_TRACE(("Enter\n"));
62     MS_U32 i;
63 
64     if(*Otp_handle != NULL)
65     {
66         NSK_TRACE(("Otp_handle is not NULL\n"));
67     }
68 
69     for(i = 0; i < MaxOTPHandleNum; i++)
70     {
71         if (OTPInfo[i].alloc == FALSE)
72         {
73             break;
74         }
75     }
76     if (i == MaxOTPHandleNum)
77     {
78         return (NSK2HDI_STATUS_FAILED);
79     }
80 
81 
82     //should allocate dscmb here....
83     OTPInfo[i].alloc = TRUE;
84     OTPInfo[i].handle_id = i;
85     OTPInfo[i].Otp_ID = Otp_ID;
86 
87 
88     *Otp_handle = (NSK2HDI_HANDLE)&OTPInfo[i].handle_id;
89 
90     NSK_TRACE(("Otp_ID = 0x%x, Otp_handle = 0x%08x\n",Otp_ID,OTPInfo[i].handle_id));
91     NSK_TRACE(("Exit\n"));
92     return NSK2HDI_STATUS_OK;
93 }
94 
NSKHDI_OtpDevice_Close(NSK2HDI_HANDLE Otp_handle)95 NSK2HDI_STATUS NSKHDI_OtpDevice_Close (NSK2HDI_HANDLE Otp_handle)
96 {
97     NSK_TRACE(("Enter\n"));
98     MS_U32 u32Handle = NSKHDI_GetHandle(Otp_handle);
99 
100 
101     OTPInfo[u32Handle].alloc = FALSE;
102     OTPInfo[u32Handle].handle_id = 0;
103 
104 
105     NSK_TRACE(("Exit\n"));
106     return NSK2HDI_STATUS_OK;
107 }
108 
NSKHDI_OtpDevice_GetProperties(NSK2HDI_HANDLE Otp_handle,NDS_ULONG request_id,NDS_ULONG * desc_size,NDS_UBYTE * desc)109 NSK2HDI_STATUS NSKHDI_OtpDevice_GetProperties( NSK2HDI_HANDLE  Otp_handle,
110                                                NDS_ULONG       request_id,
111                                                NDS_ULONG       *desc_size,
112                                                NDS_UBYTE       *desc)
113 {
114     NSK_TRACE(("Enter\n"));
115 
116 
117     //in desc_size
118     NSK_TRACE(("request_id = 0x%x, desc_size = 0x%x\n",request_id,*desc_size));
119 
120     if(request_id == NSK2HDI_OTP_READ_ALL_DESCRIPTORS_REQUEST)
121     {
122         MDrv_NSK2_GetOTPProperties((MS_U32*)desc_size, (MS_U8*)desc);
123     }
124     else if(request_id == NSK2HDI_OTP_READ_FULLCHIPCONFIGURATION)
125     {
126         MDrv_NSK2_GetFullChipConfig((MS_U32*)desc_size, (MS_U8*)desc);
127     }
128     else if(request_id == NSK2HDI_OTP_MAX_NVCOUNTER_UPDATES)
129     {
130         MDrv_NSK2_GetNVCounterConfig((MS_U32*)desc_size, (MS_U8*)desc);
131     }
132 
133 
134     NSK_TRACE(("Exit\n"));
135     return NSK2HDI_STATUS_OK;
136 }
137 
138 
139 
140 
141