blob: 1e2b81fcbda0238f190db7c2bd43c66165626e78 [file] [log] [blame]
rjw6c1fd8f2022-11-30 14:33:01 +08001my $PMU_INITSETTING_VERNO = " V1.00";
2$time =localtime(time);
3
4my @desc_list = ("pmu_init.c",
5 "This file provide for pmu initial setting",
6 "Oscar Liu", $PMU_INITSETTING_VERNO, $time);
7#information by pmu chip
8$pmu = 1; # pmu = 0 if using PMIC
9$pmu_name;
10
11print "Input file :";
12#my $data_file = <STDIN>;
13chomp($data_file=<STDIN>);
14#pmu initial parameter
15@address;
16@mask;
17@value;
18
19#pmic initial parameter
20@APshift;
21@APmask;
22@APvalue;
23@APbank;
24
25#ECO Version
26@ECO; #c code string
27@ECO_version;
28
29$data_number = 0; #number of initial data
30$ECO_number = 0;
31$latest_ECOversion = 0;
32$parsing = 0;
33$linenumber = 0;
34
35open(IN_FILE_INDEX,$data_file) || die("Could not open file!");
36@raw_data = <IN_FILE_INDEX>; #put the input data to raw_data(array)
37
38foreach $data_handle (@raw_data) #parsing total ECO number;
39{
40 if($data_handle =~/^\/\// ) #check //¶}ÀYªºstring
41 {
42 }
43 else
44 {
45 $data_handle =~ s/\s+//g; #remove all white space
46 }
47
48
49 if($data_handle =~/^ECO_E(\d+)/)
50 {
51 $ECO_version[$1]=1; #save the ECO_Ex to variable $1
52 #print $maxECOnumber;
53 $ECO_number ++;
54 #print $ECO_number;
55 }
56}
57
58if($ECO_number != 1) #only 1 ECO version, no need ECO version judgement
59{
60 $ECO_String = $ECO_String."\t"."ECO_VERSION ChipVersion = INT_ecoVersion();"."\n";
61}
62
63for($i=20;$i!=0;$i--)
64{
65 $parsing = 0;
66 $linenumber = 0;
67 if($ECO_version[$i] == 1)
68 {
69
70 if($latest_ECOversion == 0)
71 {
72 if($ECO_number != 1) #only 1 ECO version, no need ECO version judgement
73 {
74 $ECO[$i] = $ECO[$i]."\t"."if(ChipVersion >= ECO_E"."$i".")\n";
75 }
76 $ECO[$i] = $ECO[$i]."\t{\n";
77 $latest_ECOversion = 1; #set latest ECO version on the top of C code
78 }
79 else
80 {
81 $ECO[$i] = $ECO[$i]."\t"."else if(ChipVersion >= ECO_E"."$i".")\n";
82 $ECO[$i] = $ECO[$i]."\t{\n";
83 }
84
85 foreach $data_handle (@raw_data)
86 {
87 $error = 0; #check input data error
88 chomp($data_handle); #remove CR/LF(´«¦æ)
89
90
91 #$data_handle =~ s/\s+//g; #remove all white space
92 $linenumber++;
93
94 if($data_handle =~/^PMIC/ ) #check ¬O§_¬°ECO¶}ÀY, check ECO version
95 {
96 $pmu = 0;
97 #print $pmu;
98 }
99
100 if($data_handle =~/^pmu(\d+)/)
101 {
102 $pmu_name = "pmu"."$1";
103 #print $pmu_name;
104 }
105 elsif($data_handle =~/^pmic(\d+)/ )
106 {
107 $pmu_name = "pmic"."$1";
108 #print $pmu_name;
109 }
110
111 if($data_handle =~/^ECO_E(\d+)/ ) #check ¬O§_¬°ECO¶}ÀY, check ECO version
112 {
113 if($1 == $i)
114 {
115 $parsing = 1;
116 #print "$i yes\n"
117 }
118 else
119 {
120 $parsing = 0;
121 #print "$i no\n"
122 }
123 }
124 else
125 {
126 #print "$i $parsing\n"
127 }
128 if($parsing == 1)
129 {
130
131 if($data_handle =~s/^$// ) #delete ªÅ¥Õ¦æ
132 {
133
134 }
135 elsif($data_handle =~/^ECO_E/ ) #check ¬O§_¬°ECO¶}ÀY, check ECO version
136 {
137
138 }
139 elsif($data_handle =~/^\/\// ) #check //¶}ÀYªºstring
140 {
141 $ECO[$i] = $ECO[$i]."\t".$data_handle."\n";
142 #print $data_handle."\n";
143 }
144 elsif($data_handle =~/^\// ) #check /¶}ÀYªºstring
145 {
146 print "$data_handle"." is not acceptable, missing / ,line $linenumber \n";
147 }
148 elsif($data_handle !~/\,\w+\,/ ) #check ¬O§_¤£¬°,[a-zA-Z0-9],
149 {
150 print "$data_handle"." is not acceptable, line $linenumber \n";
151 }
152 else
153 {
154
155 ($address[$data_number],$mask[$data_number],$value[$data_number], $APshift[$data_number], $APmask[$data_number], $APvalue[$data_number],$APbank[$data_number]) = split(/,/,$data_handle);
156
157 if($address[$data_number] =~/[g-wyzG-Z]/) #check ¬O§_¬°¥¿½Tªº16¶i¦ì))
158 {
159 print "$address[$data_number]"." is not acceptable, line $linenumber \n";
160 $error = 1;
161 }
162 if($mask[$data_number] =~/[g-wyzG-Z]/) #check ¬O§_¬°¥¿½Tªº16¶i¦ì))
163 {
164 print "$mask[$data_number]"." is not acceptable, line $linenumber \n";
165 $error = 1;
166 }
167 if($value[$data_number] =~/[g-wyzG-Z]/) #check ¬O§_¬°¥¿½Tªº16¶i¦ì))
168 {
169 print "$value[$data_number]"." is not acceptable, line $linenumber \n";
170 $error = 1;
171 }
172 if($APshift[$data_number] =~/[g-wyzG-Z]/) #check ¬O§_¬°¥¿½Tªº16¶i¦ì))
173 {
174 print "$APshift[$data_number]"." is not acceptable, line $linenumber \n";
175 $error = 1;
176 }
177 if($APmask[$data_number] =~/[g-wyzG-Z]/) #check ¬O§_¬°¥¿½Tªº16¶i¦ì))
178 {
179 print "$APmask[$data_number]"." is not acceptable, line $linenumber \n";
180 $error = 1;
181 }
182 if($APvalue[$data_number] =~/[g-wyzG-Z]/) #check ¬O§_¬°¥¿½Tªº16¶i¦ì))
183 {
184 print "$APvalue[$data_number]"." is not acceptable, line $linenumber \n";
185 $error = 1;
186 }
187 if($APbank[$data_number] =~/[g-wyzG-Z]/) #check ¬O§_¬°¥¿½Tªº16¶i¦ì))
188 {
189 print "$APbank[$data_number]"." is not acceptable, line $linenumber \n";
190 $error = 1;
191 }
192
193 if($address[$data_number] !~/^0x/ ) #check ¬O§_¬°0x¶}ÀY))
194 {
195 print "$address[$data_number]"." is not acceptable, line $linenumber \n";
196 $error = 1;
197 }
198 if($mask[$data_number] !~/^0x/ ) #check ¬O§_¬°0x¶}ÀY))
199 {
200 print "$mask[$data_number]"." is not acceptable, line $linenumber \n";
201 $error = 1;
202 }
203 if($value[$data_number] !~/^0x/ ) #check ¬O§_¬°0x¶}ÀY))
204 {
205 print "$value[$data_number]"." is not acceptable, line $linenumber \n";
206 $error = 1;
207 }
208
209 if($APshift[$data_number] !~/^0x/ ) #check ¬O§_¬°0x¶}ÀY))
210 {
211 print "$APshift[$data_number]"." is not acceptable, line $linenumber \n";
212 $error = 1;
213 }
214 if($APmask[$data_number] !~/^0x/ ) #check ¬O§_¬°0x¶}ÀY))
215 {
216 print "$APmask[$data_number]"." is not acceptable, line $linenumber \n";
217 $error = 1;
218 }
219 if($APvalue[$data_number] !~/^0x/ ) #check ¬O§_¬°0x¶}ÀY))
220 {
221 print "$APvalue[$data_number]"." is not acceptable, line $linenumber \n";
222 $error = 1;
223 }
224 if($APbank[$data_number] !~/^0x/ ) #check ¬O§_¬°0x¶}ÀY))
225 {
226 print "$APbank[$data_number]"." is not acceptable, line $linenumber \n";
227 $error = 1;
228 }
229
230 #print "PMU_DRV_SetData16(".$address[$data_number].",".$mask[$data_number].",".$startbit[$data_number].");\n";
231 if($error == 0)
232 {
233 if($pmu ==1)
234 {
235 $ECO[$i] = $ECO[$i]."\t"."\t"."PMU_DRV_SetData16(".$address[$data_number].",".$mask[$data_number].",".$value[$data_number].");\n";
236 }
237 else
238 {
239 $ECO[$i] = $ECO[$i]."\t"."\t"."PMIC_DRV_SetData(".$address[$data_number].",".$mask[$data_number].",".$value[$data_number].",".$APbank[$data_number].");\n";
240 }
241 }
242 }
243
244
245 #print "$address[$data_number] $mask[$data_number] $startbit[$data_number] $value[$data_number] $data_number";
246
247 $data_number++;
248
249 }
250
251 }
252
253 $ECO[$i] = $ECO[$i]."\t}\n";
254 $ECO_String = $ECO_String.$ECO[$i];
255 }
256
257}
258close(IN_FILE_INDEX);
259
260if($error == 0)
261{
262 print "code generation OK";
263}
264# //translate the number to string
265#$address_string = join ',' , @address;
266#$mask_string = join ',' , @mask;
267#$startbit_string = join ',' , @startbit;
268#$value_string = join ',' , @value;
269#print "$address_string $mask_string $startbit_string $value_string";
270
271
272if($pmu ==1)
273{
274 $file_body_func_name = "config_PMUc_file_body";
275}
276else
277{
278 $file_body_func_name = "config_PMICc_file_body";
279}
280
281$output_file = "..\\hal\\peripheral\\src\\dcl_"."$pmu_name"."_init.c";
282$pmu_fuunction_name = "dcl_"."$pmu_name"."_internal_init";
283open(OUT_FILE_INDEX,">$output_file") || die("Cannot Open File");
284print OUT_FILE_INDEX &copyright_file_header();
285print OUT_FILE_INDEX &description_file_header(@desc_list);
286print OUT_FILE_INDEX &{$file_body_func_name}($pmu_fuunction_name,$ECO_String);
287close(OUT_FILE_INDEX);
288
289
290#****************************************************************************
291# subroutine: generate pmu_init.c content body
292# return: the body strings
293#****************************************************************************
294sub config_PMUc_file_body
295{
296 my($pmu_fuunction_name,$ECO_String) = @_;
297 my $template = <<"__TEMPLATE";
298#include "drv_comm.h"
299#include "init.h"
300#include "dcl.h"
301#include "dcl_pmu_sw.h"
302
303//$data_file
304void $pmu_fuunction_name(void)
305{
306$ECO_String}
307
308__TEMPLATE
309
310 return $template;
311}
312
313
314#****************************************************************************
315# subroutine: generate pmu_init.c content body
316# return: the body strings
317#****************************************************************************
318sub config_PMICc_file_body
319{
320 my($pmu_fuunction_name,$ECO_String) = @_;
321 my $template = <<"__TEMPLATE";
322#include "init.h"
323#include "dcl.h"
324
325extern DCL_UINT32 DRV_Read_PMIC_Data(DCL_UINT32 pmic_addr);
326extern void DRV_Write_PMIC_Data(DCL_UINT32 pmic_addr, DCL_UINT32 value);
327
328void PMIC_DRV_SetData(DCL_UINT32 addr, DCL_UINT32 bitmask, DCL_UINT16 value, DCL_UINT32 bank)
329{
330 DCL_UINT32 temp;
331 addr |= (bank << 31);
332 temp = (~(bitmask)) & DRV_Read_PMIC_Data(addr);
333 temp |= ((value) & (bitmask));
334 DRV_Write_PMIC_Data(addr,temp);
335}
336
337//$data_file
338void $pmu_fuunction_name(void)
339{
340$ECO_String}
341
342__TEMPLATE
343
344 return $template;
345}
346#****************************************************************************
347# subroutine: copyright_file_header
348# return: file header -- copyright
349#****************************************************************************
350sub copyright_file_header
351{
352 my $template = <<"__TEMPLATE";
353/*****************************************************************************
354* Copyright Statement:
355* --------------------
356* This software is protected by Copyright and the information contained
357* herein is confidential. The software may not be copied and the information
358* contained herein may not be used or disclosed except with the written
359* permission of MediaTek Inc. (C) 2006
360*
361* BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
362* THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
363* RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON
364* AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
365* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
366* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
367* NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
368* SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
369* SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH
370* THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO
371* NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S
372* SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
373*
374* BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
375* LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
376* AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
377* OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO
378* MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
379*
380* THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
381* WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF
382* LAWS PRINCIPLES. ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND
383* RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER
384* THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC).
385*
386*****************************************************************************/
387
388__TEMPLATE
389
390 return $template;
391}
392
393
394#****************************************************************************
395# subroutine: description_file_header
396# return: file header -- description
397# input: $filename: filename
398# input: $description: one line description
399# input: $author: optional
400#****************************************************************************
401sub description_file_header
402{
403 my ($filename, $description, $author, $PMU_INITSETTING_VERNO, $time) = @_;
404 my $template = <<"__TEMPLATE";
405/*****************************************************************************
406 *
407 * Filename:
408 * ---------
409 * $filename
410 *
411 * Project:
412 * --------
413 * Maui_Software
414 *
415 * Description:
416 * ------------
417 * $description
418 *
419 * Author:
420 * -------
421 * $author
422 *
423 *============================================================================
424 * HISTORY
425 * Below this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
426 *------------------------------------------------------------------------------
427 * \$Revision\$ $PMU_INITSETTING_VERNO
428 * \$Modtime\$ $time
429 * \$Log\$
430 *
431 *------------------------------------------------------------------------------
432 * Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
433 *============================================================================
434 ****************************************************************************/
435__TEMPLATE
436
437 return $template;
438}