rjw | 1f88458 | 2022-01-06 17:20:42 +0800 | [diff] [blame^] | 1 | #!/usr/bin/perl |
| 2 | |
| 3 | use Class::Struct (); |
| 4 | |
| 5 | my $DebugPrint = 0; |
| 6 | |
| 7 | #**************************************************************************** |
| 8 | # subroutine: custom_EMI_release_h_file_body_for_91 |
| 9 | # return: |
| 10 | #**************************************************************************** |
| 11 | sub custom_EMI_release_h_file_body_for_91 |
| 12 | { |
| 13 | 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) = @_; |
| 14 | my ($cus_include, $cus_def, $cus_enum, $cus_struct, $cus_api); |
| 15 | my $emi_clk_str; |
| 16 | my $emi_device_mode; |
| 17 | |
| 18 | if (($CUSTOM_MEM_DEV_OPTIONS_LOCAL->{FLASH_ACCESS_TYPE} eq 'SYNC_ACCESS') && ($CUSTOM_MEM_DEV_OPTIONS_LOCAL->{RAM_ACCESS_TYPE} eq 'SYNC_ACCESS')) |
| 19 | { |
| 20 | $emi_clk_str = sprintf("#define __EMI_CLK_%sMHZ__", $emi_clk_config_LOCAL); |
| 21 | if ($emi_clk_str =~ /\./) |
| 22 | { |
| 23 | $emi_clk_str =~ s/\./_/; |
| 24 | } |
| 25 | } |
| 26 | if ($CUSTOM_MEM_DEV_OPTIONS_LOCAL->{MEMORY_DEVICE_TYPE} =~ /LPDDR3/) |
| 27 | { |
| 28 | $emi_device_mode = "#define __EMI_DEVICE_LPDDR3__\n#define __EMI_MODE_2X__"; |
| 29 | } |
| 30 | elsif ($CUSTOM_MEM_DEV_OPTIONS_LOCAL->{MEMORY_DEVICE_TYPE} =~ /LPDDR2/) |
| 31 | { |
| 32 | $emi_device_mode = "#define __EMI_DEVICE_LPDDR2__\n#define __EMI_MODE_2X__"; |
| 33 | } |
| 34 | elsif ($CUSTOM_MEM_DEV_OPTIONS_LOCAL->{MEMORY_DEVICE_TYPE} =~ /LPDDR/) |
| 35 | { |
| 36 | $emi_device_mode = "#define __EMI_DEVICE_LPDDR1__\n#define __EMI_MODE_1X__"; |
| 37 | } |
| 38 | else |
| 39 | { |
| 40 | &error_handler("MEMORY_DEVICE_TYPE:$CUSTOM_MEM_DEV_OPTIONS_LOCAL->{MEMORY_DEVICE_TYPE} didn't support yet!", __FILE__, __LINE__); |
| 41 | } |
| 42 | |
| 43 | print "MDL info:$COMM_MDL_INFO_LOCAL->{1}->{'Size (Mb)'}\n" if ($DebugPrint == 1); |
| 44 | |
| 45 | my $template = <<"__TEMPLATE"; |
| 46 | #ifndef __CUSTOM_EMI_RELEASE_H__ |
| 47 | #define __CUSTOM_EMI_RELEASE_H__ |
| 48 | /******************************************** |
| 49 | * Include. |
| 50 | ********************************************/ |
| 51 | $cus_include |
| 52 | /******************************************** |
| 53 | * Definition. |
| 54 | ********************************************/ |
| 55 | /** |
| 56 | * Define EMI's clock rate. |
| 57 | * comes from EMI_CLK definition in custom_MemoryDevice.h, or highest freq in MDL |
| 58 | */ |
| 59 | $emi_clk_str |
| 60 | |
| 61 | /** |
| 62 | * Define memory's mode. |
| 63 | */ |
| 64 | $emi_device_mode |
| 65 | |
| 66 | /** |
| 67 | * Define RAM size in Bytes. |
| 68 | */ |
| 69 | #define EMI_EXTSRAM_SIZE ((($COMM_MDL_INFO_LOCAL->{1}->{'Size (Mb)'})>>3)<<20) |
| 70 | $cus_def |
| 71 | /******************************************** |
| 72 | * Enum. |
| 73 | ********************************************/ |
| 74 | $cus_enum |
| 75 | /******************************************** |
| 76 | * Struct. |
| 77 | ********************************************/ |
| 78 | $cus_struct |
| 79 | /******************************************** |
| 80 | * Exposed APIs. |
| 81 | ********************************************/ |
| 82 | $cus_api |
| 83 | #endif /* __CUSTOM_EMI_RELEASE_H__ */ |
| 84 | |
| 85 | __TEMPLATE |
| 86 | |
| 87 | return $template; |
| 88 | } |
| 89 | |
| 90 | #**************************************************************************** |
| 91 | # subroutine: custom_EMI_h_file_body_for_91 |
| 92 | # return: |
| 93 | #**************************************************************************** |
| 94 | sub custom_EMI_h_file_body_for_91 |
| 95 | { |
| 96 | ### EMI register value for each MCP |
| 97 | #my ($MAKEFILE_OPTIONS_LOCAL, $CUSTOM_MEM_DEV_OPTIONS_LOCAL, $MDL_INFO_LIST_LOCAL, $cus_include, $cus_def, $cus_enum, $cus_struct, $cus_api) = @_; |
| 98 | 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) = @_; |
| 99 | my ($cus_include, $cus_def, $cus_enum, $cus_struct, $cus_api); |
| 100 | my ($combo_mem_emi_reg, $combo_mem_emi_reg_clk); |
| 101 | my $emi_reg_bb_key_ref; |
| 102 | my $clk, $first_parse_clk; |
| 103 | my $mtk_emi_info; |
| 104 | |
| 105 | $cus_def = <<"__TEMPLATE"; |
| 106 | /* Initial EMI Definition */ |
| 107 | #define DRAM_START (0x00000000) |
| 108 | |
| 109 | #define MAX_DQ_DATA_WIDTH (32) |
| 110 | #define DQ_NUMBER_PER_DQS (8) |
| 111 | #define DQS_NUMBER (MAX_DQ_DATA_WIDTH / DQ_NUMBER_PER_DQS) |
| 112 | __TEMPLATE |
| 113 | |
| 114 | $cus_api = <<"__TEMPLATE"; |
| 115 | int custom_InitDRAM(void); |
| 116 | __TEMPLATE |
| 117 | |
| 118 | for (1..$CUSTOM_MEM_DEV_OPTIONS_LOCAL->{COMBO_MEM_ENTRY_COUNT}) |
| 119 | { |
| 120 | my $combo_idx = $_ - 1; |
| 121 | my $def_pre = undef; |
| 122 | undef $mtk_emi_info; |
| 123 | undef $first_parse_clk; |
| 124 | |
| 125 | $combo_mem_emi_reg .= <<"__TEMPLATE"; |
| 126 | /* |
| 127 | * EMI register value definition |
| 128 | * EMI/MEM configuration information of MCP$combo_idx |
| 129 | */ |
| 130 | __TEMPLATE |
| 131 | $def_pre = "#define DRAM_VENDOR_MCP$combo_idx"; |
| 132 | $combo_mem_emi_reg .= $def_pre; |
| 133 | $combo_mem_emi_reg .= " " x (47 - length($def_pre)); |
| 134 | $combo_mem_emi_reg .= " (\"$MDL_INFO_LIST_LOCAL->[$_]->{0}->{'Vendor'}\")\n"; |
| 135 | $def_pre = "#define DRAM_PART_NUMBER_MCP$combo_idx"; |
| 136 | $combo_mem_emi_reg .= $def_pre; |
| 137 | $combo_mem_emi_reg .= " " x (47 - length($def_pre)); |
| 138 | $combo_mem_emi_reg .= " (\"$MDL_INFO_LIST_LOCAL->[$_]->{0}->{'Part Number'}\")\n"; |
| 139 | my $emi_reg_bb_key_ref = $MDL_INFO_LIST_LOCAL->[$_]->{0}->{$MAKEFILE_OPTIONS_LOCAL->{'platform'}}; |
| 140 | foreach my $emi_key (sort keys %{$emi_reg_bb_key_ref}) |
| 141 | { |
| 142 | if ($emi_key =~ /(\d+)MHZ EMI Driving/) |
| 143 | { |
| 144 | $clk = $1; |
| 145 | if (! defined $first_parse_clk) |
| 146 | { |
| 147 | $first_parse_clk = $clk; |
| 148 | } |
| 149 | if (! defined $combo_mem_emi_reg_clk) |
| 150 | { |
| 151 | $combo_mem_emi_reg_clk = "#if defined(__EMI_CLK_$clk\MHZ__)\n"; |
| 152 | } |
| 153 | else |
| 154 | { |
| 155 | $combo_mem_emi_reg_clk .= "#elif defined(__EMI_CLK_$clk\MHZ__)\n"; |
| 156 | } |
| 157 | my $emi_clk_dri = $emi_key; |
| 158 | foreach my $emi_key (sort keys %{$emi_reg_bb_key_ref->{$emi_clk_dri}}) |
| 159 | { |
| 160 | my $val = $emi_reg_bb_key_ref->{$emi_clk_dri}->{$emi_key}; |
| 161 | if (($val ne 'x') && ($val ne 'X') && ($val ne '')) |
| 162 | { |
| 163 | $def_pre = "#define $emi_key\_MCP$combo_idx"; |
| 164 | $combo_mem_emi_reg_clk .= $def_pre; |
| 165 | # for alignment |
| 166 | $combo_mem_emi_reg_clk .= " " x (47 - length($def_pre)); |
| 167 | $combo_mem_emi_reg_clk .= " ($val)\n"; |
| 168 | } |
| 169 | |
| 170 | if ($first_parse_clk == $clk) |
| 171 | { |
| 172 | $mtk_emi_info .= " unsigned int " . lc($emi_key) . ";\n"; |
| 173 | } |
| 174 | } |
| 175 | } |
| 176 | else |
| 177 | { |
| 178 | my $val = $emi_reg_bb_key_ref->{$emi_key}; |
| 179 | $def_pre = "#define $emi_key\_MCP$combo_idx"; |
| 180 | if (($val ne 'x') && ($val ne 'X') && ($val ne '')) |
| 181 | { |
| 182 | $combo_mem_emi_reg .= $def_pre; |
| 183 | # for alignment |
| 184 | $combo_mem_emi_reg .= " " x (47 - length($def_pre)); |
| 185 | $combo_mem_emi_reg .= " ($val)\n"; |
| 186 | } |
| 187 | $mtk_emi_info .= " unsigned int " . lc($emi_key) . ";\n"; |
| 188 | } |
| 189 | } |
| 190 | $combo_mem_emi_reg_clk .= "#endif /* __EMI_CLK_$clk\MHZ__ */\n"; |
| 191 | |
| 192 | $combo_mem_emi_reg .= <<"__TEMPLATE"; |
| 193 | |
| 194 | $combo_mem_emi_reg_clk |
| 195 | /* |
| 196 | * End of EMI/MEM configuration information of MCP$combo_idx |
| 197 | */ |
| 198 | __TEMPLATE |
| 199 | |
| 200 | undef $combo_mem_emi_reg_clk; |
| 201 | } |
| 202 | |
| 203 | my $template = <<"__TEMPLATE"; |
| 204 | #ifndef __CUSTOM_EMI_H__ |
| 205 | #define __CUSTOM_EMI_H__ |
| 206 | /******************************************** |
| 207 | * Include. |
| 208 | ********************************************/ |
| 209 | #include "custom_EMI_release.h" |
| 210 | $cus_include |
| 211 | /******************************************** |
| 212 | * Definition. |
| 213 | ********************************************/ |
| 214 | $combo_mem_emi_reg |
| 215 | $cus_def |
| 216 | /******************************************** |
| 217 | * Enum. |
| 218 | ********************************************/ |
| 219 | typedef enum { |
| 220 | DRAMType_Invalid = 0x0, |
| 221 | DRAMType_DDR, |
| 222 | DRAMType_DDR2, |
| 223 | DRAMType_DDR_166M, |
| 224 | DRAMType_DDR_200M, |
| 225 | DRAMType_DDR2_166M, |
| 226 | DRAMType_DDR2_200M, |
| 227 | DRAMType_LPDDR = 0x800, |
| 228 | DRAMType_LPDDR2, |
| 229 | DRAMType_LPDDR_166M, |
| 230 | DRAMType_LPDDR_200M, |
| 231 | DRAMType_LPDDR2_166M, |
| 232 | DRAMType_LPDDR2_200M, |
| 233 | DRAMType_LPDDR2_266M, |
| 234 | DRAMType_LPDDR3_303M = 0x900, |
| 235 | DRAMType_DDR_166M_SIP = 0x1000, |
| 236 | DRAMType_DDR_200M_SIP, |
| 237 | DRAMType_DDR2_166M_SIP, |
| 238 | DRAMType_DDR2_200M_SIP, |
| 239 | DRAMType_LPDDR_SIP = 0x1800, |
| 240 | DRAMType_LPDDR2_SIP, |
| 241 | DRAMType_LPDDR_166M_SIP, |
| 242 | DRAMType_LPDDR_200M_SIP, |
| 243 | DRAMType_LPDDR2_166M_SIP, |
| 244 | DRAMType_LPDDR2_200M_SIP, |
| 245 | DRAMType_End = 0x42424242 |
| 246 | } DRAMType; |
| 247 | $cus_enum |
| 248 | /******************************************** |
| 249 | * Struct. |
| 250 | ********************************************/ |
| 251 | typedef struct { |
| 252 | DRAMType ramType; |
| 253 | $mtk_emi_info} MTK_EMI_Info; |
| 254 | $cus_struct |
| 255 | /******************************************** |
| 256 | * Exposed APIs. |
| 257 | ********************************************/ |
| 258 | $cus_api |
| 259 | #endif /* end of __CUSTOM_EMI_H__ */ |
| 260 | __TEMPLATE |
| 261 | |
| 262 | return $template; |
| 263 | } |
| 264 | |
| 265 | #**************************************************************************** |
| 266 | # subroutine: custom_EMI_info_h_file_body |
| 267 | # return: |
| 268 | #**************************************************************************** |
| 269 | sub custom_EMI_info_h_file_body |
| 270 | { |
| 271 | 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) = @_; |
| 272 | my $combo_mem_emi_info_struct; |
| 273 | my $combo_mem_emi_type; |
| 274 | |
| 275 | $combo_mem_emi_type = "DRAMType_"; |
| 276 | if ($CUSTOM_MEM_DEV_OPTIONS_LOCAL->{MEMORY_DEVICE_TYPE} =~ /[A-Za-z]*DDR[0-9]*/) |
| 277 | { |
| 278 | $combo_mem_emi_type .= $&; |
| 279 | } |
| 280 | if (($CUSTOM_MEM_DEV_OPTIONS_LOCAL->{FLASH_ACCESS_TYPE} eq 'SYNC_ACCESS') && ($CUSTOM_MEM_DEV_OPTIONS_LOCAL->{RAM_ACCESS_TYPE} eq 'SYNC_ACCESS')) |
| 281 | { |
| 282 | $combo_mem_emi_type .= sprintf("_%sM", $emi_clk_config_LOCAL); |
| 283 | } |
| 284 | if ($MAKEFILE_OPTIONS_LOCAL->{'sip_ram_size'} ne "NONE") { |
| 285 | $combo_mem_emi_type .= "_SIP"; |
| 286 | } |
| 287 | for (1..$CUSTOM_MEM_DEV_OPTIONS_LOCAL->{COMBO_MEM_ENTRY_COUNT}) |
| 288 | { |
| 289 | my $combo_idx = $_ - 1; |
| 290 | $combo_mem_emi_info_struct .= <<"__TEMPLATE"; |
| 291 | { |
| 292 | .ramType = $combo_mem_emi_type, |
| 293 | __TEMPLATE |
| 294 | my $emi_reg_bb_key_ref = $MDL_INFO_LIST_LOCAL->[$_]->{0}->{$MAKEFILE_OPTIONS_LOCAL->{'platform'}}; |
| 295 | foreach my $emi_key (sort keys %{$emi_reg_bb_key_ref}) |
| 296 | { |
| 297 | if ($emi_key =~ /(\d+)MHZ EMI Driving/) |
| 298 | { |
| 299 | my $emi_clk_dri = $emi_key; |
| 300 | foreach my $emi_key (sort keys %{$emi_reg_bb_key_ref->{$emi_clk_dri}}) |
| 301 | { |
| 302 | my $val = $emi_reg_bb_key_ref->{$emi_clk_dri}->{$emi_key}; |
| 303 | if (($val ne 'x') && ($val ne 'X') && ($val ne '')) |
| 304 | { |
| 305 | my $emi_info_def = "$emi_key\_MCP$combo_idx"; |
| 306 | $combo_mem_emi_info_struct .= " ." . lc($emi_key) . " = " . $emi_info_def . ",\n"; |
| 307 | } |
| 308 | } |
| 309 | } |
| 310 | else |
| 311 | { |
| 312 | my $val = $emi_reg_bb_key_ref->{$emi_key}; |
| 313 | if (($val ne 'x') && ($val ne 'X') && ($val ne '')) |
| 314 | { |
| 315 | my $emi_info_def = "$emi_key\_MCP$combo_idx"; |
| 316 | $combo_mem_emi_info_struct .= " ." . lc($emi_key) . " = " . $emi_info_def . ",\n"; |
| 317 | } |
| 318 | } |
| 319 | } |
| 320 | $combo_mem_emi_info_struct .= " },\n"; |
| 321 | } |
| 322 | my $template = <<"__TEMPLATE"; |
| 323 | #ifndef __CUSTOM_EMI_INFO_H__ |
| 324 | #define __CUSTOM_EMI_INFO_H__ |
| 325 | /******************************************** |
| 326 | * Include. |
| 327 | ********************************************/ |
| 328 | #include "custom_EMI_release.h" |
| 329 | #include "custom_EMI.h" |
| 330 | $cus_include |
| 331 | /******************************************** |
| 332 | * Definition. |
| 333 | ********************************************/ |
| 334 | $cus_def |
| 335 | /******************************************** |
| 336 | * Enum. |
| 337 | ********************************************/ |
| 338 | $cus_enum |
| 339 | /******************************************** |
| 340 | * Struct. |
| 341 | ********************************************/ |
| 342 | MTK_EMI_Info EMI_INFO[] = { |
| 343 | $combo_mem_emi_info_struct |
| 344 | }; /* End of EMI_INFO struct */ |
| 345 | $cus_struct |
| 346 | /******************************************** |
| 347 | * Exposed APIs. |
| 348 | ********************************************/ |
| 349 | $cus_api |
| 350 | |
| 351 | #endif /* __CUSTOM_EMI_INFO_H__ */ |
| 352 | __TEMPLATE |
| 353 | |
| 354 | return $template; |
| 355 | } |
| 356 | |
| 357 | #**************************************************************************** |
| 358 | # subroutine: custom_EMI_info_c_file_body |
| 359 | # return: |
| 360 | #**************************************************************************** |
| 361 | sub custom_EMI_info_c_file_body_for_91 |
| 362 | { |
| 363 | 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) = @_; |
| 364 | my ($cus_include, $cus_def, $cus_enum, $cus_struct, $cus_api); |
| 365 | my $combo_mem_emi_info_struct; |
| 366 | my $combo_mem_emi_type; |
| 367 | |
| 368 | $combo_mem_emi_type = "DRAMType_"; |
| 369 | if ($CUSTOM_MEM_DEV_OPTIONS_LOCAL->{MEMORY_DEVICE_TYPE} =~ /[A-Za-z]*DDR[0-9]*/) |
| 370 | { |
| 371 | $combo_mem_emi_type .= $&; |
| 372 | } |
| 373 | if (($CUSTOM_MEM_DEV_OPTIONS_LOCAL->{FLASH_ACCESS_TYPE} eq 'SYNC_ACCESS') && ($CUSTOM_MEM_DEV_OPTIONS_LOCAL->{RAM_ACCESS_TYPE} eq 'SYNC_ACCESS')) |
| 374 | { |
| 375 | $combo_mem_emi_type .= sprintf("_%sM", $emi_clk_config_LOCAL); |
| 376 | } |
| 377 | if ($MAKEFILE_OPTIONS_LOCAL->{'sip_ram_size'} ne "NONE") { |
| 378 | $combo_mem_emi_type .= "_SIP"; |
| 379 | } |
| 380 | for (1..$CUSTOM_MEM_DEV_OPTIONS_LOCAL->{COMBO_MEM_ENTRY_COUNT}) |
| 381 | { |
| 382 | my $combo_idx = $_ - 1; |
| 383 | $combo_mem_emi_info_struct .= <<"__TEMPLATE"; |
| 384 | { |
| 385 | .ramType = $combo_mem_emi_type, |
| 386 | __TEMPLATE |
| 387 | my $emi_reg_bb_key_ref = $MDL_INFO_LIST_LOCAL->[$_]->{0}->{$MAKEFILE_OPTIONS_LOCAL->{'platform'}}; |
| 388 | foreach my $emi_key (sort keys %{$emi_reg_bb_key_ref}) |
| 389 | { |
| 390 | if ($emi_key =~ /(\d+)MHZ EMI Driving/) |
| 391 | { |
| 392 | my $emi_clk_dri = $emi_key; |
| 393 | foreach my $emi_key (sort keys %{$emi_reg_bb_key_ref->{$emi_clk_dri}}) |
| 394 | { |
| 395 | my $val = $emi_reg_bb_key_ref->{$emi_clk_dri}->{$emi_key}; |
| 396 | if (($val ne 'x') && ($val ne 'X') && ($val ne '')) |
| 397 | { |
| 398 | my $emi_info_def = "$emi_key\_MCP$combo_idx"; |
| 399 | $combo_mem_emi_info_struct .= " ." . lc($emi_key) . " = " . $emi_info_def . ",\n"; |
| 400 | } |
| 401 | } |
| 402 | } |
| 403 | else |
| 404 | { |
| 405 | my $val = $emi_reg_bb_key_ref->{$emi_key}; |
| 406 | if (($val ne 'x') && ($val ne 'X') && ($val ne '')) |
| 407 | { |
| 408 | my $emi_info_def = "$emi_key\_MCP$combo_idx"; |
| 409 | $combo_mem_emi_info_struct .= " ." . lc($emi_key) . " = " . $emi_info_def . ",\n"; |
| 410 | } |
| 411 | } |
| 412 | } |
| 413 | $combo_mem_emi_info_struct .= " },\n"; |
| 414 | } |
| 415 | my $template = <<"__TEMPLATE"; |
| 416 | /******************************************** |
| 417 | * Include. |
| 418 | ********************************************/ |
| 419 | #include "custom_EMI_release.h" |
| 420 | #include "custom_EMI.h" |
| 421 | $cus_include |
| 422 | /******************************************** |
| 423 | * Definition. |
| 424 | ********************************************/ |
| 425 | $cus_def |
| 426 | /******************************************** |
| 427 | * Enum. |
| 428 | ********************************************/ |
| 429 | $cus_enum |
| 430 | /******************************************** |
| 431 | * Struct. |
| 432 | ********************************************/ |
| 433 | MTK_EMI_Info EMI_INFO[] = { |
| 434 | $combo_mem_emi_info_struct |
| 435 | }; /* End of EMI_INFO struct */ |
| 436 | $cus_struct |
| 437 | /******************************************** |
| 438 | * Exposed APIs. |
| 439 | ********************************************/ |
| 440 | $cus_api |
| 441 | |
| 442 | __TEMPLATE |
| 443 | |
| 444 | return $template; |
| 445 | } |
| 446 | |
| 447 | |
| 448 | #**************************************************************************** |
| 449 | # custom_emi_h for MT6297 |
| 450 | #**************************************************************************** |
| 451 | Class::Struct::struct(EMI_SETTING => {name => '$', xls_name => '$', value => '$'}); |
| 452 | my @EMI_SETTINGS = ( |
| 453 | EMI_SETTING->new(name => "sub_version", xls_name => undef, value => 0x1), |
| 454 | EMI_SETTING->new(name => "type", xls_name => "Type"), |
| 455 | EMI_SETTING->new(name => "dram_cbt_mode_extern", xls_name => "Mode"), |
| 456 | EMI_SETTING->new(name => "DRAM_RANK_SIZE", xls_name => "Density (Mb)"), |
| 457 | EMI_SETTING->new(name => "DRAM_RANK_SIZE_0L", xls_name => undef), |
| 458 | EMI_SETTING->new(name => "DRAM_RANK_SIZE_0H", xls_name => undef), |
| 459 | EMI_SETTING->new(name => "DRAM_RANK_SIZE_1L", xls_name => undef), |
| 460 | EMI_SETTING->new(name => "DRAM_RANK_SIZE_1H", xls_name => undef), |
| 461 | # by platform |
| 462 | EMI_SETTING->new(name => "EMI_CONA_VAL", xls_name => "CONA_VAL"), |
| 463 | EMI_SETTING->new(name => "CHN0_EMI_CONA_VAL", xls_name => "CHN0_CONA_VAL"), |
| 464 | EMI_SETTING->new(name => "CHN1_EMI_CONA_VAL", xls_name => "CHN1_CONA_VAL"), |
| 465 | EMI_SETTING->new(name => "EMI_CONF_VAL", xls_name => "CONF_VAL"), |
| 466 | EMI_SETTING->new(name => "EMI_CONH_VAL", xls_name => "CONH_VAL"), |
| 467 | EMI_SETTING->new(name => "iLPDDR3_MODE_REG_5", xls_name => "MODE_REG5"), |
| 468 | EMI_SETTING->new(name => "PIN_MUX_TYPE", xls_name => "PIN_MUX_TYPE"), |
| 469 | ); |
| 470 | |
| 471 | sub emi_setting_type |
| 472 | { |
| 473 | my $typ = shift; |
| 474 | my %mcp = ("Discrete" => 0, "NAND" => 1, "eMMC" => 2, "UFS" => 3); |
| 475 | my %ddr = ("DDR1" => 1, "LPDDR2" => 2, "LPDDR3" => 3, "PCDDR3" => 4, "LPDDR4" => 5, "LPDR4X" => 6, "LPDDR4P" => 7); |
| 476 | |
| 477 | if (($typ =~ /(Discrete)\s+(\w+)/) or ($typ =~ /MCP\((\w+)\+(\w+)\)/)) { |
| 478 | return ($mcp{$1} << 8) + ($ddr{$2}); |
| 479 | } |
| 480 | return undef; |
| 481 | } |
| 482 | |
| 483 | sub emi_setting_cbt |
| 484 | { |
| 485 | my $cbt = shift; |
| 486 | my %cbt_h = ( "CBT_R0_R1_NORMAL" => 0, "CBT_R0_R1_BYTE" => 1, "CBT_R0_NORMAL_R1_BYTE" => 2, "CBT_R0_BYTE_R1_NORMAL" => 3); |
| 487 | |
| 488 | return $cbt_h{$cbt}; |
| 489 | } |
| 490 | |
| 491 | sub custom_emi_h_file_body_for_97 |
| 492 | { |
| 493 | my ($MAKEFILE_OPTIONS_LOCAL, $MDL_INFO_LIST_LOCAL) = @_; |
| 494 | my $platform = $MAKEFILE_OPTIONS_LOCAL->{platform}; |
| 495 | my @size; |
| 496 | |
| 497 | for my $emi (@EMI_SETTINGS) { # update value |
| 498 | if ($emi->name eq "type") { |
| 499 | $emi->value(sprintf "%#05x", &emi_setting_type($MDL_INFO_LIST_LOCAL->[1]->{0}->{$emi->xls_name})); |
| 500 | } elsif ($emi->name eq "dram_cbt_mode_extern") { |
| 501 | my $v = $MDL_INFO_LIST_LOCAL->[1]->{0}->{$emi->xls_name}; |
| 502 | $emi->value(sprintf "%d/*%s*/", &emi_setting_cbt($v), $v); |
| 503 | } elsif ($emi->name eq "DRAM_RANK_SIZE") { |
| 504 | for (split(/\+/, $MDL_INFO_LIST_LOCAL->[1]->{0}->{$emi->xls_name})) { |
| 505 | my $s = int($_) * 1024 * 1024 / 8; # Mbit -> Byte |
| 506 | push @size, sprintf("%#x", $s & 0xffffffff); |
| 507 | push @size, sprintf("%#x", $s >> 32); |
| 508 | } |
| 509 | } elsif ($emi->name =~ /DRAM_RANK_SIZE_\d[LH]/i) { |
| 510 | $emi->value(shift @size); |
| 511 | } elsif (defined $emi->xls_name) { |
| 512 | $emi->value($MDL_INFO_LIST_LOCAL->[1]->{0}->{$platform}->{$emi->xls_name}); |
| 513 | } |
| 514 | } |
| 515 | |
| 516 | my @setting; |
| 517 | for my $emi (@EMI_SETTINGS) { |
| 518 | push(@setting, ".".$emi->name." = ".$emi->value) if defined($emi->value); |
| 519 | } |
| 520 | my $setting_str = join(",\n ", @setting); |
| 521 | |
| 522 | my $template = <<"__TEMPLATE"; |
| 523 | #ifndef __CUSTOM_EMI_H__ |
| 524 | #define __CUSTOM_EMI_H__ |
| 525 | |
| 526 | #include "emi.h" |
| 527 | |
| 528 | // $MDL_INFO_LIST_LOCAL->[1]->{0}->{"Part Number"} |
| 529 | EMI_SETTINGS default_emi_setting = |
| 530 | { |
| 531 | $setting_str |
| 532 | }; |
| 533 | |
| 534 | #endif |
| 535 | __TEMPLATE |
| 536 | |
| 537 | return $template; |
| 538 | } |
| 539 | |
| 540 | return 1; |