xref: /utopia/UTPA2-700.0.x/modules/gpd/hal/macan/gpd/gpd_reg.c (revision 53ee8cc121a030b8d368113ac3e966b4705770ef)
1 //<MStar Software>
2 //******************************************************************************
3 // MStar Software
4 // Copyright (c) 2010 - 2012 MStar Semiconductor, Inc. All rights reserved.
5 // All software, firmware and related documentation herein ("MStar Software") are
6 // intellectual property of MStar Semiconductor, Inc. ("MStar") and protected by
7 // law, including, but not limited to, copyright law and international treaties.
8 // Any use, modification, reproduction, retransmission, or republication of all
9 // or part of MStar Software is expressly prohibited, unless prior written
10 // permission has been granted by MStar.
11 //
12 // By accessing, browsing and/or using MStar Software, you acknowledge that you
13 // have read, understood, and agree, to be bound by below terms ("Terms") and to
14 // comply with all applicable laws and regulations:
15 //
16 // 1. MStar shall retain any and all right, ownership and interest to MStar
17 //    Software and any modification/derivatives thereof.
18 //    No right, ownership, or interest to MStar Software and any
19 //    modification/derivatives thereof is transferred to you under Terms.
20 //
21 // 2. You understand that MStar Software might include, incorporate or be
22 //    supplied together with third party`s software and the use of MStar
23 //    Software may require additional licenses from third parties.
24 //    Therefore, you hereby agree it is your sole responsibility to separately
25 //    obtain any and all third party right and license necessary for your use of
26 //    such third party`s software.
27 //
28 // 3. MStar Software and any modification/derivatives thereof shall be deemed as
29 //    MStar`s confidential information and you agree to keep MStar`s
30 //    confidential information in strictest confidence and not disclose to any
31 //    third party.
32 //
33 // 4. MStar Software is provided on an "AS IS" basis without warranties of any
34 //    kind. Any warranties are hereby expressly disclaimed by MStar, including
35 //    without limitation, any warranties of merchantability, non-infringement of
36 //    intellectual property rights, fitness for a particular purpose, error free
37 //    and in conformity with any international standard.  You agree to waive any
38 //    claim against MStar for any loss, damage, cost or expense that you may
39 //    incur related to your use of MStar Software.
40 //    In no event shall MStar be liable for any direct, indirect, incidental or
41 //    consequential damages, including without limitation, lost of profit or
42 //    revenues, lost or damage of data, and unauthorized system use.
43 //    You agree that this Section 4 shall still apply without being affected
44 //    even if MStar Software has been modified by MStar in accordance with your
45 //    request or instruction for your use, except otherwise agreed by both
46 //    parties in writing.
47 //
48 // 5. If requested, MStar may from time to time provide technical supports or
49 //    services in relation with MStar Software to you for your use of
50 //    MStar Software in conjunction with your or your customer`s product
51 //    ("Services").
52 //    You understand and agree that, except otherwise agreed by both parties in
53 //    writing, Services are provided on an "AS IS" basis and the warranty
54 //    disclaimer set forth in Section 4 above shall apply.
55 //
56 // 6. Nothing contained herein shall be construed as by implication, estoppels
57 //    or otherwise:
58 //    (a) conferring any license or right to use MStar name, trademark, service
59 //        mark, symbol or any other identification;
60 //    (b) obligating MStar or any of its affiliates to furnish any person,
61 //        including without limitation, you and your customers, any assistance
62 //        of any kind whatsoever, or any information; or
63 //    (c) conferring any license or right under any intellectual property right.
64 //
65 // 7. These terms shall be governed by and construed in accordance with the laws
66 //    of Taiwan, R.O.C., excluding its conflict of law rules.
67 //    Any and all dispute arising out hereof or related hereto shall be finally
68 //    settled by arbitration referred to the Chinese Arbitration Association,
69 //    Taipei in accordance with the ROC Arbitration Law and the Arbitration
70 //    Rules of the Association by three (3) arbitrators appointed in accordance
71 //    with the said Rules.
72 //    The place of arbitration shall be in Taipei, Taiwan and the language shall
73 //    be English.
74 //    The arbitration award shall be final and binding to both parties.
75 //
76 //******************************************************************************
77 //<MStar Software>
78 #include <stdio.h>
79 #include "MsCommon.h"
80 #include "gpd_reg.h"
81 
82 MS_VIRT GPD_REG_BASE;
83 
84 const MS_U16 gpd_reg_addr[] =
85 {
86 0x0 ,
87 0x0 ,
88 0x0 ,
89 0x0 ,
90 0x0 ,
91 0x0 ,
92 0x0 ,
93 0x0 ,
94 0x0 ,
95 0x0 ,
96 0x0 ,
97 0x0 ,
98 0x0 ,
99 0x0 ,
100 0x1 ,
101 0x1 ,
102 0x2 ,
103 0x3 ,
104 0x4 ,
105 0x5 ,
106 0x6 ,
107 0x8 ,
108 0xa ,
109 0xc ,
110 0xe ,
111 0xf ,
112 0x10,
113 0x12,
114 0x13,
115 0x14,
116 0x15,
117 0x15,
118 0x15,
119 0x16,
120 0x17,
121 0x18,
122 0x18,
123 0x18,
124 0x18,
125 0x18,
126 0x18,
127 0x19,
128 0x19,
129 0x1a,
130 0x1a,
131 0x1a,
132 0x1a,
133 0x1a,
134 0x1a,
135 0x1a,
136 0x1a,
137 0x1b,
138 0x1b,
139 0x1b,
140 0x1b,
141 0x1c,
142 0x1c,
143 0x1d,
144 0x1e,
145 0x1e,
146 0x20,
147 0x20,
148 0x22,
149 0x22,
150 0x23,
151 0x23,
152 0x23,
153 0x23,
154 0x24,
155 0x24,
156 0x24,
157 0x25,
158 0x26,
159 0x26,
160 0x28,
161 0x28,
162 0x2a,
163 0x2a,
164 0x2c,
165 0x2c,
166 0x2d,
167 0x2e,
168 0x2e,
169 0x2f,
170 0x30,
171 0x30,
172 0x31,
173 0x32,
174 0x32,
175 0x33,
176 0x34,
177 0x34,
178 0x35,
179 0x35,
180 0x36,
181 0x36,
182 0x36,
183 0x36,
184 0x37,
185 0x37,
186 0x38,
187 0x38,
188 0x38,
189 0x38,
190 0x39,
191 0x39,
192 0x3a,
193 0x3b,
194 0x3c,
195 0x3d,
196 0x3e,
197 0x3f,
198 0x40,
199 0x41,
200 0x42,
201 0x43,
202 0x44,
203 0x45,
204 0x46,
205 0x47,
206 0x48,
207 0x48,
208 0x4a,
209 0x4a,
210 0x4a,
211 0x4a,
212 0x4a,
213 0x4a,
214 0x4a,
215 0x4a,
216 0x4a,
217 0x4b,
218 0x4c,
219 0x4e,
220 0x4f,
221 0x4f,
222 0x4f,
223 0x50,
224 0x51,
225 0x51,
226 0x51,
227 0x52,
228 0x53,
229 0x53,
230 0x53,
231 0x53,
232 0x53,
233 0x54,
234 0x55,
235 0x55,
236 0x55,
237 0x55,
238 0x56,
239 0x58,
240 0x5a,
241 0x5c,
242 0x5e,
243 0x5e,
244 0x5e,
245 0x5e,
246 0x5e,
247 0x5e,
248 0x5e,
249 0x5e,
250 0x5e,
251 0x5e,
252 0x5e,
253 0x5e,
254 0x5e,
255 0x5e,
256 0x5e,
257 0x5e,
258 0x5f,
259 0x5f,
260 0x5f,
261 0x5f,
262 0x5f,
263 0x5f,
264 0x5f,
265 0x60,
266 0x60,
267 0x60,
268 0x60,
269 0x60,
270 0x60,
271 0x61,
272 0x61,
273 0x61,
274 0x61,
275 0x61,
276 0x62,
277 0x64,
278 0x65,
279 0x66,
280 0x66,
281 0x67,
282 0x69,
283 0x6b,
284 0x6b,
285 0x6b,
286 0x6b,
287 0x6c,
288 0x6e,
289 0x70,
290 0x70
291 };
292 
293 const MS_U8 gpd_reg_msb[] =
294 {
295 0 ,
296 1 ,
297 2 ,
298 3 ,
299 4 ,
300 5 ,
301 8 ,
302 9 ,
303 10,
304 11,
305 12,
306 13,
307 14,
308 19,
309 9,
310 15,
311 15,
312 14,
313 15,
314 15,
315 30,
316 30,
317 30,
318 31,
319 8 ,
320 15,
321 15,
322 15,
323 15,
324 15,
325 0,
326 8,
327 15,
328 15,
329 15,
330 0 ,
331 1 ,
332 3 ,
333 6 ,
334 10,
335 15,
336 5,
337 12,
338 0 ,
339 2 ,
340 5 ,
341 6 ,
342 7 ,
343 8 ,
344 9 ,
345 15,
346 8,
347 9,
348 14,
349 15,
350 7 ,
351 16,
352 10,
353 10,
354 22,
355 12,
356 26,
357 14,
358 15,
359 1,
360 4,
361 8,
362 13,
363 5 ,
364 12,
365 20,
366 13,
367 9 ,
368 20,
369 11,
370 24,
371 13,
372 28,
373 8 ,
374 17,
375 10,
376 8 ,
377 17,
378 10,
379 8 ,
380 17,
381 10,
382 8 ,
383 17,
384 10,
385 8 ,
386 17,
387 6,
388 11,
389 4 ,
390 9 ,
391 14,
392 19,
393 8,
394 13,
395 4 ,
396 9 ,
397 14,
398 19,
399 8,
400 13,
401 15,
402 15,
403 15,
404 15,
405 15,
406 15,
407 15,
408 15,
409 15,
410 15,
411 15,
412 15,
413 15,
414 15,
415 14,
416 29,
417 0 ,
418 1 ,
419 4 ,
420 5 ,
421 8 ,
422 10,
423 13,
424 14,
425 15,
426 15,
427 31,
428 23,
429 13,
430 14,
431 15,
432 25,
433 10,
434 14,
435 15,
436 25,
437 10,
438 11,
439 12,
440 14,
441 15,
442 25,
443 10,
444 12,
445 13,
446 14,
447 31,
448 31,
449 27,
450 27,
451 0 ,
452 1 ,
453 2 ,
454 3 ,
455 4 ,
456 5 ,
457 6 ,
458 7 ,
459 8 ,
460 9 ,
461 10,
462 11,
463 12,
464 13,
465 14,
466 15,
467 0,
468 1,
469 2,
470 3,
471 4,
472 5,
473 6,
474 4,
475 9 ,
476 12,
477 13,
478 14,
479 15,
480 4,
481 9,
482 11,
483 13,
484 15,
485 27,
486 27,
487 13,
488 5 ,
489 15,
490 31,
491 17,
492 9,
493 12,
494 13,
495 14,
496 23,
497 31,
498 7,
499 15
500 };
501 
502 const MS_U8 gpd_reg_lsb[] =
503 {
504 0 ,
505 1 ,
506 2 ,
507 3 ,
508 4 ,
509 5 ,
510 6 ,
511 9 ,
512 10,
513 11,
514 12,
515 13,
516 14,
517 15,
518 4,
519 10,
520 0 ,
521 0 ,
522 0 ,
523 0 ,
524 0 ,
525 0 ,
526 0 ,
527 0 ,
528 0 ,
529 0 ,
530 0 ,
531 0,
532 0,
533 0,
534 0,
535 1,
536 9,
537 0,
538 0,
539 0 ,
540 1 ,
541 2 ,
542 4 ,
543 7 ,
544 11,
545 0,
546 6,
547 0 ,
548 1 ,
549 3 ,
550 6 ,
551 7 ,
552 8 ,
553 9 ,
554 10,
555 0,
556 9,
557 10,
558 15,
559 0 ,
560 8 ,
561 1,
562 0 ,
563 11,
564 0 ,
565 13,
566 0 ,
567 15,
568 0,
569 2,
570 5,
571 9,
572 0 ,
573 6 ,
574 13,
575 5,
576 0 ,
577 10,
578 0 ,
579 12,
580 0 ,
581 14,
582 0 ,
583 9 ,
584 2,
585 0 ,
586 9 ,
587 2,
588 0 ,
589 9 ,
590 2,
591 0 ,
592 9 ,
593 2,
594 0 ,
595 9 ,
596 2,
597 7,
598 0 ,
599 5 ,
600 10,
601 15,
602 4,
603 9,
604 0 ,
605 5 ,
606 10,
607 15,
608 4,
609 9,
610 0,
611 0,
612 0,
613 0,
614 0,
615 0,
616 0,
617 0 ,
618 0 ,
619 0 ,
620 0 ,
621 0 ,
622 0 ,
623 0 ,
624 0 ,
625 15,
626 0 ,
627 1 ,
628 2 ,
629 5 ,
630 6 ,
631 9 ,
632 11,
633 14,
634 15,
635 0 ,
636 0 ,
637 0 ,
638 8,
639 14,
640 15,
641 0,
642 10,
643 11,
644 15,
645 0,
646 10,
647 11,
648 12,
649 13,
650 15,
651 0,
652 10,
653 11,
654 13,
655 14,
656 0 ,
657 0 ,
658 0 ,
659 0 ,
660 0 ,
661 1 ,
662 2 ,
663 3 ,
664 4 ,
665 5 ,
666 6 ,
667 7 ,
668 8 ,
669 9 ,
670 10,
671 11,
672 12,
673 13,
674 14,
675 15,
676 0,
677 1,
678 2,
679 3,
680 4,
681 5,
682 6,
683 0,
684 5 ,
685 10,
686 13,
687 14,
688 15,
689 0,
690 5,
691 10,
692 13,
693 14,
694 0 ,
695 0 ,
696 12,
697 0 ,
698 6 ,
699 0,
700 0,
701 0,
702 10,
703 13,
704 14,
705 0,
706 0 ,
707 0,
708 8
709 };
710 
711 const char *gpd_reg_name[] = {
712 "reg_gif_go_le            ",
713 "reg_act_chk_le           ",
714 "reg_gpd_bsaddr_go_le     ",
715 "reg_gpd_rst_le           ",
716 "reg_png_go_le            ",
717 "reg_png_blk_go_le        ",
718 "reg_gif_ltbl_size      ",
719 "reg_gif_local_tbl      ",
720 "reg_gif_done           ",
721 "reg_ofifo_abort        ",
722 "reg_ififo_full         ",
723 "reg_ififo_empty        ",
724 "reg_bsadr_full         ",
725 "reg_ififo_diff         ",
726 "reg_bitpos             ",
727 "reg_png_dtbl_size      ",
728 "reg_gif_state          ",
729 "reg_gpd_pitch          ",
730 "reg_gpd_iwidth         ",
731 "reg_gpd_iheight        ",
732 "reg_gpd_bstart         ",
733 "reg_gpd_bend           ",
734 "reg_gpd_istart         ",
735 "reg_spare1             ",
736 "reg_gpd_boffset        ",
737 "reg_iofifo_state       ",
738 "reg_gpd_roi_hstart     ",
739 "reg_gpd_roi_vstart     ",
740 "reg_gpd_roi_width      ",
741 "reg_gpd_roi_height     ",
742 "reg_gpd_roi_en         ",
743 "reg_gpd_default_alpha  ",
744 "reg_spare2_rst0        ",
745 "reg_png_trans_r        ",
746 "reg_png_trans_g        ",
747 "reg_png_blk_done       ",
748 "reg_png_mincode1       ",
749 "reg_png_mincode2       ",
750 "reg_png_mincode3       ",
751 "reg_png_mincode4       ",
752 "reg_png_mincode5       ",
753 "reg_png_mincode6       ",
754 "reg_png_mincode7       ",
755 "reg_gpd_ipm_en         ",
756 "reg_gpd_ipm_size       ",
757 "reg_gpd_ocolor         ",
758 "reg_gpd_en               ",
759 "reg_ofifo_done         ",
760 "reg_miu_domain_empty   ",
761 "reg_mreq_always_active ",
762 "reg_eng_always_active  ",
763 "reg_png_ltbl_size      ",
764 "reg_gpd_act_chk        ",
765 "reg_png_sca            ",
766 "reg_png_eob            ",
767 "reg_png_mincode8       ",
768 "reg_png_mincode9       ",
769 "reg_png_mincode10      ",
770 "reg_png_mincode11      ",
771 "reg_png_mincode12      ",
772 "reg_png_mincode13      ",
773 "reg_png_mincode14      ",
774 "reg_png_mincode15      ",
775 "reg_png2_mincode1      ",
776 "reg_png2_mincode2      ",
777 "reg_png2_mincode3      ",
778 "reg_png2_mincode4      ",
779 "reg_png2_mincode5      ",
780 "reg_png2_mincode6      ",
781 "reg_png2_mincode7      ",
782 "reg_png2_mincode8      ",
783 "reg_png2_mincode9      ",
784 "reg_png2_mincode10     ",
785 "reg_png2_mincode11     ",
786 "reg_png2_mincode12     ",
787 "reg_png2_mincode13     ",
788 "reg_png2_mincode14     ",
789 "reg_png2_mincode15     ",
790 "reg_png_lbase2         ",
791 "reg_png_lbase3         ",
792 "reg_png_lbase4         ",
793 "reg_png_lbase5         ",
794 "reg_png_lbase6         ",
795 "reg_png_lbase7         ",
796 "reg_png_lbase8         ",
797 "reg_png_lbase9         ",
798 "reg_png_lbase10        ",
799 "reg_png_lbase11        ",
800 "reg_png_lbase12        ",
801 "reg_png_lbase13        ",
802 "reg_png_lbase14        ",
803 "reg_png_lbase15        ",
804 "reg_png_dbase2         ",
805 "reg_png_dbase3         ",
806 "reg_png_dbase4         ",
807 "reg_png_dbase5         ",
808 "reg_png_dbase6         ",
809 "reg_png_dbase7         ",
810 "reg_png_dbase8         ",
811 "reg_png_dbase9         ",
812 "reg_png_dbase10        ",
813 "reg_png_dbase11        ",
814 "reg_png_dbase12        ",
815 "reg_png_dbase13        ",
816 "reg_png_dbase14        ",
817 "reg_png_dbase15        ",
818 "reg_png_scline0_width  ",
819 "reg_png_scline1_width  ",
820 "reg_png_scline2_width  ",
821 "reg_png_scline3_width  ",
822 "reg_png_scline4_width  ",
823 "reg_png_scline5_width  ",
824 "reg_png_scline6_width  ",
825 "reg_png_scline0_height ",
826 "reg_png_scline1_height ",
827 "reg_png_scline2_height ",
828 "reg_png_scline3_height ",
829 "reg_png_scline4_height ",
830 "reg_png_scline5_height ",
831 "reg_png_scline6_height ",
832 "reg_png_mincode_valid  ",
833 "reg_png2_mincode_valid ",
834 "reg_gpd_only_decom_en  ",
835 "reg_png_done           ",
836 "reg_png_color_type     ",
837 "reg_gpd_interlace      ",
838 "reg_spare6             ",
839 "reg_png_compress_type  ",
840 "reg_png_color_depth    ",
841 "reg_miu_act_chk        ",
842 "reg_png_trans_en       ",
843 "reg_png_trans_b        ",
844 "reg_png_state          ",
845 "reg_ififo_cnt          ",
846 "reg_hipri              ",
847 "reg_gpd_premult_alpha_en ",
848 "reg_gpd_gif_alpha_mask_en",
849 "reg_frun_cnt           ",
850 "reg_png_burst_en       ",
851 "reg_gif_mask           ",
852 "reg_deflt_fast_on      ",
853 "reg_ififo_radr         ",
854 "reg_gpd_time_out       ",
855 "reg_gif_code_size_err  ",
856 "reg_gif_err            ",
857 "reg_gpd_pgend          ",
858 "reg_miu64              ",
859 "reg_gpd2mi_adr         ",
860 "reg_wait_last_done     ",
861 "reg_miu_wait_cyc       ",
862 "reg_fixed_pri          ",
863 "reg_last_done_md       ",
864 "reg_gpd_read_data      ",
865 "reg_io_read_gpd        ",
866 "reg_cbuf_bas           ",
867 "reg_zbuf_bas           ",
868 "reg_bist_fail_lz_psram ",
869 "reg_bist_fail_bst_psram",
870 "reg_bist_fail_lit_psram",
871 "reg_bist_fail_flt_psram",
872 "reg_bist_fail_lmem     ",
873 "reg_bist_fail_cmem     ",
874 "reg_bist_fail_omem     ",
875 "reg_bist_fail_imem     ",
876 "reg_bist_fail_dc0_cmem ",
877 "reg_bist_fail_dc1_cmem ",
878 "reg_bist_fail_stk_psram",
879 "reg_bist_fail_dma1     ",
880 "reg_bist_fail_dma0     ",
881 "reg_bist_fail_cmd      ",
882 "reg_bist_fail_data     ",
883 "reg_bist_fail_cc_cmem  ",
884 "reg_bist_fail_cc_dmem  ",
885 "reg_bist_fail_cc_rdmem ",
886 "reg_bist_fail_cc_wdmem ",
887 "reg_bist_fail_zc_cmem  ",
888 "reg_bist_fail_zc_dmem  ",
889 "reg_bist_fail_zc_rdmem ",
890 "reg_bist_fail_zc_wdmem ",
891 "reg_int_mask           ",
892 "reg_int_rst            ",
893 "reg_debug_mux          ",
894 "reg_dram_imi           ",
895 "reg_gpd_istr_8b        ",
896 "reg_gif_act_clr        ",
897 "reg_int_status         ",
898 "reg_int_sw_force       ",
899 "reg_cache_hit_cmp      ",
900 "reg_scale_en           ",
901 "reg_scale_md           ",
902 "reg_lb_addr            ",
903 "reg_ub_addr            ",
904 "reg_gpd_xiu_byte_sel   ",
905 "reg_gpd_read_bits      ",
906 "reg_gpd_reserved1      ",
907 "reg_gpd_cmem_wdata     ",
908 "reg_png_ltbl_wdata     ",
909 "reg_png_dtbl_wdata     ",
910 "reg_debug2_mux         ",
911 "reg_wbe_bypass_go_chk  ",
912 "reg_gpd_sram_sd_en     ",
913 "reg_gpd_debug          ",
914 "reg_gpd_debug2         ",
915 "reg_gpd_version        ",
916 "reg_gpd_tlb            "
917 };
918 
GPD_GET_ADDR(MS_U32 index)919 static volatile MS_VIRT GPD_GET_ADDR(MS_U32 index)
920 {
921     MS_VIRT offset = gpd_reg_addr[index] - (gpd_reg_lsb[index] >> 4);
922     return (volatile MS_VIRT)(GPD_REG_BASE + offset * 4);
923 }
924 
GPD_GET_MS_U32MASK(MS_U32 index)925 static MS_U32 GPD_GET_MS_U32MASK(MS_U32 index)
926 {
927     if(gpd_reg_msb[index] - gpd_reg_lsb[index] == 31)
928 
929       return 0xffffffff;
930 
931     else
932         return (((MS_U32)1 << (gpd_reg_msb[index] - gpd_reg_lsb[index] + 1)) - 1) << gpd_reg_lsb[index];
933 }
934 
GPD_READ_MS_U32(volatile MS_U32 * u32addr)935 static MS_U32 GPD_READ_MS_U32(volatile MS_U32 *u32addr)
936 {
937     //volatile MS_U32 *u32addr = (volatile MS_U32 *)u8addr;
938     return (u32addr[0] & 0xFFFF) | (u32addr[1] << 16);
939 }
940 
GPD_WRITE_MS_U32(volatile MS_U32 * u32addr,MS_U32 value)941 static void GPD_WRITE_MS_U32(volatile MS_U32 *u32addr, MS_U32 value)
942 {
943     //volatile MS_U32 *u32addr = (volatile MS_U32 *)u8addr;
944     u32addr[0] = (value) & 0xFFFF;
945     u32addr[1] = (value) >> 16;
946 }
947 
GPD_GET_MS_U32REG_dbg(MS_U32 index)948 MS_U32 GPD_GET_MS_U32REG_dbg(MS_U32 index)
949 {
950     volatile MS_VIRT u32addr = GPD_GET_ADDR(index);
951 
952 
953     MS_U32 temp = (GPD_READ_MS_U32((volatile MS_U32*)u32addr) & GPD_GET_MS_U32MASK(index)) >> gpd_reg_lsb[index];
954 
955 
956     console_printf("Reg read: %s = 0x%08tx, offset = 0x%02tX, lsb=%td, msb=%td\n", gpd_reg_name[index], (ptrdiff_t)temp,
957         (ptrdiff_t)gpd_reg_addr[index], (ptrdiff_t)gpd_reg_lsb[index], (ptrdiff_t)gpd_reg_msb[index]);
958     return temp;
959 }
960 
GPD_GET_MS_U32REG(MS_U32 index)961 MS_U32 GPD_GET_MS_U32REG(MS_U32 index)
962 {
963     volatile MS_VIRT u32addr = GPD_GET_ADDR(index);
964 
965 
966     MS_U32 temp = (GPD_READ_MS_U32((volatile MS_U32*)u32addr) & GPD_GET_MS_U32MASK(index)) >> gpd_reg_lsb[index];
967 
968 
969     //console_printf("Reg read: %s = 0x%08X, addr = 0x%08X\n", gpd_reg_name[index], temp, u8addr);
970     return temp;
971 }
972 
GPD_SET_MS_U32REG(MS_U32 index,MS_U32 value)973 void GPD_SET_MS_U32REG(MS_U32 index, MS_U32 value)
974 {
975     volatile MS_VIRT u32addr = GPD_GET_ADDR(index);
976     MS_U32 mask = GPD_GET_MS_U32MASK(index);
977     MS_U32 temp = GPD_READ_MS_U32((volatile MS_U32*)u32addr);
978 
979     temp &= ~mask;
980 
981     temp |= ((value) << gpd_reg_lsb[index]) & mask;
982     GPD_WRITE_MS_U32((volatile MS_U32*)u32addr, temp);
983 
984 //    console_printf("Reg write: %s = 0x%08X, offset = 0x%02X, lsb=%d, msb=%d\n", gpd_reg_name[index], (MS_U32)value,
985 //        (MS_U16)gpd_reg_addr[index], gpd_reg_lsb[index], gpd_reg_msb[index]);
986 }
987 
hal_gpd_get_clkbase()988 MS_U32 hal_gpd_get_clkbase()
989 {
990     // macan: clkgen1
991     return (0x03300 * 2);
992 }
993 
hal_gpd_get_clkoffset()994 MS_U32 hal_gpd_get_clkoffset()
995 {
996     // macan: h0028	h0028	4	0	reg_ckg_gpd
997     return (0x50 << 1);
998 }
999 
hal_gpd_reg_base(MS_U32 * u32RIUBase,MS_U32 * u32XIUBase)1000 void hal_gpd_reg_base(MS_U32* u32RIUBase, MS_U32* u32XIUBase)
1001 {
1002     // macan: 113Eh, 113Fh
1003     *u32RIUBase = (0x13E00 * 2);
1004     *u32XIUBase = (0x13F00 * 2);
1005 }
1006 
hal_gpd_miu_client(MS_U8 * u8Offset,MS_U16 * u16BitMask)1007 void hal_gpd_miu_client(MS_U8* u8Offset, MS_U16* u16BitMask)
1008 {
1009     // macan: group2, bit 6==> //h007a	h007a	15	0	reg_miu_sel2
1010     // 0x7a << 1 = 0xf4
1011     *u8Offset = 0xf4;
1012     *u16BitMask = 0x40;
1013 }
1014 
hal_gpd_init_outside_reg(MS_VIRT BankBaseAddr)1015 void hal_gpd_init_outside_reg(MS_VIRT BankBaseAddr)
1016 {
1017     MS_U32 tmp = 0;
1018     // macan: group2, bit 6==> //h0022	h0022	15	0	reg_miu_group2_i64
1019     // @20151022, from ronald's mail I64: addr 0x101e, offset 0x22, bit 6 = 1
1020     tmp = *((volatile MS_U32 *)(MS_VIRT)(BankBaseAddr + 0x1E00*2 + 0x22*2*2));
1021     tmp |= 0x40;
1022     console_printf("set i64 reg to 0x%tx\n", (ptrdiff_t)tmp);
1023     *((volatile MS_U32 *)(MS_VIRT)(BankBaseAddr + 0x1E00*2 + 0x22*2*2)) = tmp;
1024 
1025 }
1026 
1027 
hal_gpd_init_chip_specific_reg(void)1028 void hal_gpd_init_chip_specific_reg(void)
1029 {
1030 }
1031 
hal_gpd_SetMIUProtectMask(MS_VIRT BankBaseAddr,MS_U8 bEnable)1032 void hal_gpd_SetMIUProtectMask(MS_VIRT BankBaseAddr, MS_U8 bEnable)
1033 {
1034     MS_U32 tmp = 0;
1035     // macan: h0043	h0043	15	0	reg_rq2_mask
1036     tmp = *((volatile MS_U32 *)(MS_VIRT)(BankBaseAddr + 0x1200*2 + 0x43*2*2));
1037     if(bEnable==TRUE)
1038     {
1039         tmp |= 0x40;
1040     }
1041     else
1042     {
1043         tmp &=~0x40;
1044     }
1045     *((volatile MS_U32 *)(MS_VIRT)(BankBaseAddr + 0x1200*2 + 0x43*2*2)) = tmp;
1046 
1047     tmp = *((volatile MS_U32 *)(MS_VIRT)(BankBaseAddr + 0x0600*2 + 0x43*2*2));
1048     if(bEnable==TRUE)
1049     {
1050         tmp |= 0x40;
1051     }
1052     else
1053     {
1054         tmp &=~0x40;
1055     }
1056     *((volatile MS_U32 *)(MS_VIRT)(BankBaseAddr + 0x0600*2 + 0x43*2*2)) = tmp;
1057 
1058     console_printf("set miu client protect to 0x%tx\n", (ptrdiff_t)tmp);
1059 
1060     return;
1061 }
1062 
1063