]> rtime.felk.cvut.cz Git - sysless.git/blob - board/h8300/edk2638/libs/bspbase/bsp0hwinit.c
7d60c1cc7749cf3398c49f007acb121af108322d
[sysless.git] / board / h8300 / edk2638 / libs / bspbase / bsp0hwinit.c
1 /* procesor H8S/2638 board EDK2638 ver 1.1 */
2 #include <types.h>
3 #include <cpu_def.h>
4 #include <h8s2638h.h>
5 #include <system_def.h>
6 #include <string.h>
7 #include <boot_fn.h>
8
9 #ifdef XRAM_SUPPORT_ENABLED
10 #define FULL_XRAM_ADRBUS
11 #endif /*XRAM_SUPPORT_ENABLED*/
12 #define SMALL_ADRBUS 8
13
14 static void deb_led_out(char val)
15 {
16  #if 0
17   *DIO_P1DR &= ~0xf;
18   *DIO_P1DR |= ~val & 0xf;
19  #elif 0
20   /*2,6,7*/
21   *DIO_P3DR &= ~0xc4;
22   *DIO_P3DR |= ~(val<<5) & 0xc0;
23   if(!(val&1))
24     *DIO_P3DR |= 4;
25  #else
26   SHADOW_REG_SET(DIO_P1DDR,(P1DDR_P15DDRm|P1DDR_P14DDRm)); /* set P1.5 and P1.4 as output */
27
28   if (val&1)
29     *DIO_P1DR |=P1DR_P14DRm;
30   else
31     *DIO_P1DR &=~P1DR_P14DRm;
32
33    if (val&2)
34     *DIO_P1DR |=P1DR_P15DRm;
35   else
36     *DIO_P1DR &=~P1DR_P15DRm;
37
38
39  #endif
40 }
41
42 void _setup_board()
43 {
44   //int i, j;// POE-100
45
46   //int i, j;// POE-100
47   __u8 *p;
48
49  #if 1 /* registers setup */
50   /* Internal RAM enabled, advanced interrupt mode */
51   /* *SYS_SYSCR = 1*SYSCR_RAMEm | 1*SYSCR_INTM1m ; */
52
53   /* Remap 4kB of RAM from 0xffd000-0xffdfff to 0x0-0xfff */
54   /* *FLM_RAMER= 1*RAMER_RAMSm | 0&RAMER_RAMxm */
55   /* Sideefect - sets Flash software protection */
56
57   /* Enables access to flash control registers */
58   *IIC_SCRX |= SCRX_FLSHEm;
59
60   /* set shadow registers */
61   DIO_P1DDR_shadow=0;
62   DIO_P3DDR_shadow=0;
63
64   /* show something on debug leds */
65   /* deb_led_out(0);
66   FlWait(2*1000000); */
67
68
69   //SHADOW_REG_SET(DIO_P3DDR,0xc4);
70   //SHADOW_REG_SET(DIO_P1DDR,0x03); /*A20 and A21 are outputs*/
71   *DIO_P3DR=0x09;       /* Inactive value of TxD0 and TxD1 has to be log 1 */
72   SHADOW_REG_SET(DIO_P3DDR,0x09); /* TxD0 and TxD1 to outputs */
73
74   /* Setup system clock oscilator */
75   /* PLL mode x4, */
76   /* *SYS_LPWRCR=2&LPWRCR_STCxm; */
77   /* PLL mode x2, */
78   /* *SYS_LPWRCR=1&LPWRCR_STCxm; */
79   { const char clkrat2stc[]={0,0/*1*/,1/*2*/,1,2/*4*/,2,2,2,3/*8*/};
80     *SYS_LPWRCR=LPWRCR_STCxm&(LPWRCR_STC0m*
81                 clkrat2stc[(CPU_SYS_HZ+CPU_REF_HZ/2)/CPU_REF_HZ]);
82   }
83   /* deb_led_out(1);
84   FlWait(2*1000000); */
85
86   /* No clock disable, immediate change, busmaster high-speed */
87   *SYS_SCKCR=(0*SCKCR_PSTOPm)|(1*SCKCR_STCSm)|(0&SCKCR_SCKxm);
88 // POE-100
89  #if 0
90   /* Setup chipselect outputs CS4 CS5 CS6 */
91   *DIO_P7DR |=1|2|4;
92   SHADOW_REG_SET(DIO_P7DDR,1|2|4);
93  #else
94   // SHADOW_REG_SET(DIO_P7DDR,0); not on 2638
95  #endif
96
97   /* Setup chipselect outputs CS3 CS2 CS1 CS0 */
98   // *DIO_PGDR |=2|4|8|0x10; no on 2638
99  #if 0
100   SHADOW_REG_SET(DIO_PGDDR,2|4|8|0x10);
101  #else
102   // SHADOW_REG_SET(DIO_PGDDR,2|4); no on 2638
103  #endif
104
105  #if 0
106   /* setup chipselect 0 - FLASH */
107   *BUS_ABWCR&=~ABWCR_ABW0m;     /* 16 bit width */
108   *BUS_ASTCR&=~ASTCR_AST0m;     /* 2 states access */
109   *BUS_WCRL&=~(WCRL_W01m|WCRL_W00m);/* 0 additional wait states */
110
111   /* setup chipselect 1 - XRAM */
112   *BUS_ABWCR&=~ABWCR_ABW1m;     /* 16 bit width */
113   *BUS_ASTCR&=~ASTCR_AST1m;     /* 2 states access */
114   *BUS_WCRL&=~(WCRL_W11m|WCRL_W10m);/* 0 additional wait states */
115
116   /* setup chipselect 2 - SGM_LCD */
117   *BUS_ABWCR|=ABWCR_ABW2m;      /* 8 bit width */
118   *BUS_ASTCR|=ASTCR_AST2m;      /* 3 states access */
119   *BUS_WCRL&=~(WCRL_W21m|WCRL_W20m);/* 0 additional wait states */
120   *BUS_WCRL|=0*WCRL_W21m;       /* 0/1 additional wait state */
121   #endif
122
123   /* setup chipselect 3 - SRAM */
124   //*BUS_ABWCR|=ABWCR_ABW3m;    /* 8 bit width */
125   *BUS_ABWCR&=~ABWCR_ABW0m;     /* 16 bit width EDK 2638 */
126   //*BUS_ASTCR|=ASTCR_AST3m;    /* 3 states access */
127   *BUS_ASTCR|=ASTCR_AST0m;      /* 3 states access EDK 2638 */
128   //*BUS_WCRL&=~(WCRL_W31m|WCRL_W30m);  /* 0 additional wait states */
129   *BUS_WCRL&=~(WCRL_W01m|WCRL_W00m);    /* 0 additional wait states EDK 2638*/
130
131   /* deb_led_out(2);
132   FlWait(2*1000000); */
133
134  #if 0
135   /* setup chipselect 4 - IDE */
136   *BUS_ABWCR&=~ABWCR_ABW4m;     /* 16 bit width */
137   *BUS_ASTCR|=ASTCR_AST4m;      /* 3 states access */
138   *BUS_WCRH&=~(WCRH_W41m|WCRH_W40m);/* 0 additional wait states */
139
140   /* setup chipselect 5 - IDE */
141   *BUS_ABWCR&=~ABWCR_ABW5m;     /* 16 bit width */
142   *BUS_ASTCR|=ASTCR_AST5m;      /* 3 states access */
143   *BUS_WCRH&=~(WCRH_W51m|WCRH_W50m);/* 0 additional wait states */
144
145   /* setup chipselect 6 - KL41 */
146   *BUS_ABWCR|=ABWCR_ABW6m;      /* 8 bit width */
147   *BUS_ASTCR|=ASTCR_AST6m;      /* 3 states access */
148   *BUS_WCRH=WCRH_W61m|WCRH_W60m;        /* 3 additional wait states */
149  #endif
150
151 #if 1
152          /*  cross cs wait| rd/wr wait    | no burst and DRAM */
153   *BUS_BCRH=0*BCRH_ICIS1m | 0*BCRH_ICIS0m;
154          /* release      | no DMAC buffer | no external wait */
155   *BUS_BCRL=0*BCRL_WDBEm; // 0*BCRL_BRLEm | 0*BCRL_WDBEm | 0*BCRL_WAITEm;  BRLE and WAITE not build in 2638
156   *DIO_PCDDR=0xff;              /* A0-A7 are outputs */
157  #ifndef SMALL_ADRBUS
158   *DIO_PBDDR=0xff;              /* A8-A15 are outputs */
159  #endif /*SMALL_ADRBUS*/
160  #ifndef FULL_XRAM_ADRBUS
161   #ifndef SMALL_ADRBUS
162    /* *SYS_PFCR=__val2mfld(PFCR_AExm,16-8);      only 16 address lines */
163    *SYS_PFCR=__val2mfld(PFCR_AExm,18-8);        /* only 18 address lines fer EDK238 Extend*/
164   #else /*SMALL_ADRBUS*/
165    *SYS_PFCR=__val2mfld(PFCR_AExm,SMALL_ADRBUS-8); /* only SMALL_ADRBUS address lines */
166   #endif /*SMALL_ADRBUS*/
167  #endif /* FULL_XRAM_ADRBUS */
168
169  #endif /* registers setup */
170
171   FlWait(1*1000000);
172
173  #ifdef FULL_XRAM_ADRBUS
174   /* Setup full 20 address lines */
175   *DIO_PADR|=0x0f;
176   *DIO_PADDR=0x0f;              /* A16-A19 are outputs */
177          /* number of address output signals */
178   /* *SYS_PFCR=__val2mfld(PFCR_AExm,20-8); */
179   *SYS_PFCR=__val2mfld(PFCR_AExm,18-8); /* only 18 address lines fer EDK238 Extend*/
180  #endif /*FULL_XRAM_ADRBUS*/
181 #endif
182 }
183