blob: 42340d5a7dae224efea5c8252f1787c8bf7249ac [file] [log] [blame]
rjw6c1fd8f2022-11-30 14:33:01 +08001#!/usr/bin/perl
2
3my $DebugPrint = 0;
4
5#****************************************************************************
6# subroutine: custom_EMI_release_h_file_body
7# return:
8#****************************************************************************
9sub custom_EMI_release_h_file_body
10{
11 my ($CUSTOM_MEM_DEV_OPTIONS_LOCAL, $COMM_MDL_INFO_LOCAL, $emi_clk_config_LOCAL, $cus_include, $cus_def, $cus_enum, $cus_struct, $cus_api) = @_;
12 my $emi_clk_str;
13 my $emi_device_mode;
14
15 if (($CUSTOM_MEM_DEV_OPTIONS_LOCAL->{FLASH_ACCESS_TYPE} eq 'SYNC_ACCESS') && ($CUSTOM_MEM_DEV_OPTIONS_LOCAL->{RAM_ACCESS_TYPE} eq 'SYNC_ACCESS'))
16 {
17 $emi_clk_str = sprintf("#define __EMI_CLK_%sMHZ__", $emi_clk_config_LOCAL);
18 if ($emi_clk_str =~ /\./)
19 {
20 $emi_clk_str =~ s/\./_/;
21 }
22 }
23 if ($CUSTOM_MEM_DEV_OPTIONS_LOCAL->{MEMORY_DEVICE_TYPE} =~ /LPDDR2/)
24 {
25 $emi_device_mode = "#define __EMI_DEVICE_LPDDR2__\n#define __EMI_MODE_2X__";
26 }
27 elsif ($CUSTOM_MEM_DEV_OPTIONS_LOCAL->{MEMORY_DEVICE_TYPE} =~ /LPDDR/)
28 {
29 $emi_device_mode = "#define __EMI_DEVICE_LPDDR1__\n#define __EMI_MODE_1X__";
30 }
31 else
32 {
33 &error_handler("MEMORY_DEVICE_TYPE:$CUSTOM_MEM_DEV_OPTIONS_LOCAL->{MEMORY_DEVICE_TYPE} didn't support yet!", __FILE__, __LINE__);
34 }
35
36 print "MDL info:$COMM_MDL_INFO_LOCAL->{1}->{'Size (Mb)'}\n" if ($DebugPrint == 1);
37
38 my $template = <<"__TEMPLATE";
39#ifndef __CUSTOM_EMI_RELEASE_H__
40#define __CUSTOM_EMI_RELEASE_H__
41/********************************************
42 * Include.
43 ********************************************/
44#include "kal_general_types.h"
45$cus_include
46/********************************************
47 * Definition.
48 ********************************************/
49/**
50 * Define EMI's clock rate.
51 * comes from EMI_CLK definition in custom_MemoryDevice.h, or highest freq in MDL
52 */
53$emi_clk_str
54
55/**
56 * Define memory's mode.
57 */
58$emi_device_mode
59
60/**
61 * Define RAM size in Bytes.
62 */
63#define EMI_EXTSRAM_SIZE ((($COMM_MDL_INFO_LOCAL->{1}->{'Size (Mb)'})>>3)<<20)
64$cus_def
65/********************************************
66 * Enum.
67 ********************************************/
68$cus_enum
69/********************************************
70 * Struct.
71 ********************************************/
72$cus_struct
73/********************************************
74 * Exposed APIs.
75 ********************************************/
76$cus_api
77#endif /* __CUSTOM_EMI_RELEASE_H__ */
78
79__TEMPLATE
80
81 return $template;
82}
83
84
85#****************************************************************************
86# subroutine: custom_EMI_release_h_90_file_body
87# return:
88#****************************************************************************
89sub custom_EMI_release_h_90_file_body
90{
91 my ($MAKEFILE_OPTIONS_LOCAL, $CUSTOM_MEM_DEV_OPTIONS_LOCAL, $MDL_INFO_LIST_LOCAL, $COMM_MDL_INFO_LOCAL, $LPSDRAM_CHIP_SELECT_LOCAL, $emi_clk_config_LOCAL) = @_;
92 my ($cus_include, $cus_def, $cus_enum, $cus_struct, $cus_api);
93
94 return &custom_EMI_release_h_file_body($CUSTOM_MEM_DEV_OPTIONS_LOCAL, $COMM_MDL_INFO_LOCAL, $emi_clk_config_LOCAL, $cus_include, $cus_def, $cus_enum, $cus_struct, $cus_api);
95}
96
97#****************************************************************************
98# subroutine: custom_EMI_h_file_body
99# return:
100#****************************************************************************
101sub custom_EMI_h_file_body
102{
103 ### EMI register value for each MCP
104 my ($MAKEFILE_OPTIONS_LOCAL, $CUSTOM_MEM_DEV_OPTIONS_LOCAL, $MDL_INFO_LIST_LOCAL, $cus_include, $cus_def, $cus_enum, $cus_struct, $cus_api) = @_;
105 my ($combo_mem_emi_reg, $combo_mem_emi_reg_clk);
106 my $emi_reg_bb_key_ref;
107 my $clk, $first_parse_clk;
108 my $mtk_emi_info;
109
110 for (1..$CUSTOM_MEM_DEV_OPTIONS_LOCAL->{COMBO_MEM_ENTRY_COUNT})
111 {
112 my $combo_idx = $_ - 1;
113 my $def_pre = undef;
114 undef $mtk_emi_info;
115 undef $first_parse_clk;
116
117 $combo_mem_emi_reg .= <<"__TEMPLATE";
118/*
119 * EMI register value definition
120 * EMI/MEM configuration information of MCP$combo_idx
121 */
122__TEMPLATE
123 $def_pre = "#define DRAM_VENDOR_MCP$combo_idx";
124 $combo_mem_emi_reg .= $def_pre;
125 $combo_mem_emi_reg .= " " x (47 - length($def_pre));
126 $combo_mem_emi_reg .= " (\"$MDL_INFO_LIST_LOCAL->[$_]->{0}->{'Vendor'}\")\n";
127 $def_pre = "#define DRAM_PART_NUMBER_MCP$combo_idx";
128 $combo_mem_emi_reg .= $def_pre;
129 $combo_mem_emi_reg .= " " x (47 - length($def_pre));
130 $combo_mem_emi_reg .= " (\"$MDL_INFO_LIST_LOCAL->[$_]->{0}->{'Part Number'}\")\n";
131 my $emi_reg_bb_key_ref = $MDL_INFO_LIST_LOCAL->[$_]->{0}->{$MAKEFILE_OPTIONS_LOCAL->{'platform'}};
132 foreach my $emi_key (sort keys %{$emi_reg_bb_key_ref})
133 {
134 if ($emi_key =~ /(\d+)MHZ EMI Driving/)
135 {
136 $clk = $1;
137 if (! defined $first_parse_clk)
138 {
139 $first_parse_clk = $clk;
140 }
141 if (! defined $combo_mem_emi_reg_clk)
142 {
143 $combo_mem_emi_reg_clk = "#if defined(__EMI_CLK_$clk\MHZ__)\n";
144 }
145 else
146 {
147 $combo_mem_emi_reg_clk .= "#elif defined(__EMI_CLK_$clk\MHZ__)\n";
148 }
149 my $emi_clk_dri = $emi_key;
150 foreach my $emi_key (sort keys %{$emi_reg_bb_key_ref->{$emi_clk_dri}})
151 {
152 my $val = $emi_reg_bb_key_ref->{$emi_clk_dri}->{$emi_key};
153 if (($val ne 'x') && ($val ne 'X') && ($val ne ''))
154 {
155 $def_pre = "#define $emi_key\_MCP$combo_idx";
156 $combo_mem_emi_reg_clk .= $def_pre;
157 # for alignment
158 $combo_mem_emi_reg_clk .= " " x (47 - length($def_pre));
159 $combo_mem_emi_reg_clk .= " ($val)\n";
160 }
161
162 if ($first_parse_clk == $clk)
163 {
164 $mtk_emi_info .= " unsigned int " . lc($emi_key) . ";\n";
165 }
166 }
167 }
168 else
169 {
170 my $val = $emi_reg_bb_key_ref->{$emi_key};
171 $def_pre = "#define $emi_key\_MCP$combo_idx";
172 if (($val ne 'x') && ($val ne 'X') && ($val ne ''))
173 {
174 $combo_mem_emi_reg .= $def_pre;
175 # for alignment
176 $combo_mem_emi_reg .= " " x (47 - length($def_pre));
177 $combo_mem_emi_reg .= " ($val)\n";
178 }
179 $mtk_emi_info .= " unsigned int " . lc($emi_key) . ";\n";
180 }
181 }
182 $combo_mem_emi_reg_clk .= "#endif /* __EMI_CLK_$clk\MHZ__ */\n";
183
184 $combo_mem_emi_reg .= <<"__TEMPLATE";
185
186$combo_mem_emi_reg_clk
187/*
188 * End of EMI/MEM configuration information of MCP$combo_idx
189 */
190__TEMPLATE
191
192 undef $combo_mem_emi_reg_clk;
193 }
194
195 my $template = <<"__TEMPLATE";
196#ifndef __CUSTOM_EMI_H__
197#define __CUSTOM_EMI_H__
198/********************************************
199 * Include.
200 ********************************************/
201$cus_include
202/********************************************
203 * Definition.
204 ********************************************/
205$combo_mem_emi_reg
206$cus_def
207/********************************************
208 * Enum.
209 ********************************************/
210typedef enum {
211 DRAMType_Invalid = 0x0,
212 DRAMType_DDR,
213 DRAMType_DDR2,
214 DRAMType_DDR_166M,
215 DRAMType_DDR_200M,
216 DRAMType_DDR2_166M,
217 DRAMType_DDR2_200M,
218 DRAMType_LPDDR = 0x800,
219 DRAMType_LPDDR2,
220 DRAMType_LPDDR_166M,
221 DRAMType_LPDDR_200M,
222 DRAMType_LPDDR2_166M,
223 DRAMType_LPDDR2_200M,
224 DRAMType_DDR_166M_SIP = 0x1000,
225 DRAMType_DDR_200M_SIP,
226 DRAMType_DDR2_166M_SIP,
227 DRAMType_DDR2_200M_SIP,
228 DRAMType_LPDDR_SIP = 0x1800,
229 DRAMType_LPDDR2_SIP,
230 DRAMType_LPDDR_166M_SIP,
231 DRAMType_LPDDR_200M_SIP,
232 DRAMType_LPDDR2_166M_SIP,
233 DRAMType_LPDDR2_200M_SIP,
234 DRAMType_End = 0x42424242
235} DRAMType;
236$cus_enum
237/********************************************
238 * Struct.
239 ********************************************/
240typedef struct {
241 DRAMType ramType;
242$mtk_emi_info} MTK_EMI_Info;
243$cus_struct
244/********************************************
245 * Exposed APIs.
246 ********************************************/
247$cus_api
248#endif /* end of __CUSTOM_EMI_H__ */
249__TEMPLATE
250
251 return $template;
252}
253
254#****************************************************************************
255# subroutine: custom_EMI_h_90_file_body
256# return:
257#****************************************************************************
258sub custom_EMI_h_90_file_body
259{
260 my ($MAKEFILE_OPTIONS_LOCAL, $CUSTOM_MEM_DEV_OPTIONS_LOCAL, $MDL_INFO_LIST_LOCAL, $COMM_MDL_INFO_LOCAL, $PART_NUMBER_LOCAL, $CUSTOM_MEMORY_DEVICE_HDR_LOCAL, $LPSDRAM_CHIP_SELECT_LOCAL, $emi_clk_config_LOCAL, $emi_nor_cmd_num_max_LOCAL, $emi_psram_cmd_num_max_LOCAL, $MCP_LIST_LOCAL) = @_;
261 my ($cus_include, $cus_def, $cus_enum, $cus_struct, $cus_api);
262
263 $cus_def = <<"__TEMPLATE";
264/* Initial EMI Definition */
265#define USE_DUAL_RANK_DDR
266#define DRAM_START (0x00000000)
267
268#define MAX_DQ_DATA_WIDTH (32)
269
270#define DQ_NUMBER_PER_DQS (8)
271#define DQS_NUMBER (dq_data_width / DQ_NUMBER_PER_DQS)
272#define TX_STEPS (8) // This value is obtained by measurement of waveform for the relationship between DQS and CLK.
273__TEMPLATE
274
275 $cus_api = <<"__TEMPLATE";
276kal_int8 custom_InitDRAM(void);
277__TEMPLATE
278
279 return &custom_EMI_h_file_body($MAKEFILE_OPTIONS_LOCAL, $CUSTOM_MEM_DEV_OPTIONS_LOCAL, $MDL_INFO_LIST_LOCAL, $cus_include, $cus_def, $cus_enum, $cus_struct, $cus_api);
280}
281
282#****************************************************************************
283# subroutine: custom_EMI_info_h_file_body
284# return:
285#****************************************************************************
286sub custom_EMI_info_h_file_body
287{
288 my ($MAKEFILE_OPTIONS_LOCAL, $CUSTOM_MEM_DEV_OPTIONS_LOCAL, $MDL_INFO_LIST_LOCAL, $emi_clk_config_LOCAL, $cus_include, $cus_def, $cus_enum, $cus_struct, $cus_api) = @_;
289 my $combo_mem_emi_info_struct;
290 my $combo_mem_emi_type;
291
292 $combo_mem_emi_type = "DRAMType_";
293 if ($CUSTOM_MEM_DEV_OPTIONS_LOCAL->{MEMORY_DEVICE_TYPE} =~ /[A-Za-z]*DDR[0-9]*/)
294 {
295 $combo_mem_emi_type .= $&;
296 }
297 if (($CUSTOM_MEM_DEV_OPTIONS_LOCAL->{FLASH_ACCESS_TYPE} eq 'SYNC_ACCESS') && ($CUSTOM_MEM_DEV_OPTIONS_LOCAL->{RAM_ACCESS_TYPE} eq 'SYNC_ACCESS'))
298 {
299 $combo_mem_emi_type .= sprintf("_%sM", $emi_clk_config_LOCAL);
300 }
301 if ($MAKEFILE_OPTIONS_LOCAL->{'sip_ram_size'} ne "NONE") {
302 $combo_mem_emi_type .= "_SIP";
303 }
304 for (1..$CUSTOM_MEM_DEV_OPTIONS_LOCAL->{COMBO_MEM_ENTRY_COUNT})
305 {
306 my $combo_idx = $_ - 1;
307 $combo_mem_emi_info_struct .= <<"__TEMPLATE";
308 {
309 .ramType = $combo_mem_emi_type,
310__TEMPLATE
311 my $emi_reg_bb_key_ref = $MDL_INFO_LIST_LOCAL->[$_]->{0}->{$MAKEFILE_OPTIONS_LOCAL->{'platform'}};
312 foreach my $emi_key (sort keys %{$emi_reg_bb_key_ref})
313 {
314 if ($emi_key =~ /(\d+)MHZ EMI Driving/)
315 {
316 my $emi_clk_dri = $emi_key;
317 foreach my $emi_key (sort keys %{$emi_reg_bb_key_ref->{$emi_clk_dri}})
318 {
319 my $val = $emi_reg_bb_key_ref->{$emi_clk_dri}->{$emi_key};
320 if (($val ne 'x') && ($val ne 'X') && ($val ne ''))
321 {
322 my $emi_info_def = "$emi_key\_MCP$combo_idx";
323 $combo_mem_emi_info_struct .= " ." . lc($emi_key) . " = " . $emi_info_def . ",\n";
324 }
325 }
326 }
327 else
328 {
329 my $val = $emi_reg_bb_key_ref->{$emi_key};
330 if (($val ne 'x') && ($val ne 'X') && ($val ne ''))
331 {
332 my $emi_info_def = "$emi_key\_MCP$combo_idx";
333 $combo_mem_emi_info_struct .= " ." . lc($emi_key) . " = " . $emi_info_def . ",\n";
334 }
335 }
336 }
337 $combo_mem_emi_info_struct .= " },\n";
338 }
339 my $template = <<"__TEMPLATE";
340#ifndef __CUSTOM_EMI_INFO_H__
341#define __CUSTOM_EMI_INFO_H__
342/********************************************
343 * Include.
344 ********************************************/
345#include "custom_EMI_release.h"
346#include "custom_EMI.h"
347$cus_include
348/********************************************
349 * Definition.
350 ********************************************/
351$cus_def
352/********************************************
353 * Enum.
354 ********************************************/
355$cus_enum
356/********************************************
357 * Struct.
358 ********************************************/
359MTK_EMI_Info EMI_INFO[] = {
360$combo_mem_emi_info_struct
361}; /* End of EMI_INFO struct */
362$cus_struct
363/********************************************
364 * Exposed APIs.
365 ********************************************/
366$cus_api
367
368#endif /* __CUSTOM_EMI_INFO_H__ */
369__TEMPLATE
370
371 return $template;
372}
373
374#****************************************************************************
375# subroutine: custom_EMI_info_h_90_file_body
376# return:
377#****************************************************************************
378sub custom_EMI_info_h_90_file_body
379{
380 my ($MAKEFILE_OPTIONS_LOCAL, $CUSTOM_MEM_DEV_OPTIONS_LOCAL, $MDL_INFO_LIST_LOCAL, $COMM_MDL_INFO_LOCAL, $PART_NUMBER_LOCAL, $CUSTOM_MEMORY_DEVICE_HDR_LOCAL, $LPSDRAM_CHIP_SELECT_LOCAL, $emi_clk_config_LOCAL, $emi_nor_cmd_num_max_LOCAL, $emi_psram_cmd_num_max_LOCAL) = @_;
381 my ($cus_include, $cus_def, $cus_enum, $cus_struct, $cus_api);
382
383 return &custom_EMI_info_h_file_body($MAKEFILE_OPTIONS_LOCAL, $CUSTOM_MEM_DEV_OPTIONS_LOCAL, $MDL_INFO_LIST_LOCAL, $emi_clk_config_LOCAL, $cus_include, $cus_def, $cus_enum, $cus_struct, $cus_api);
384}
385
386return 1;