common: Drop net.h from common header
[oweals/u-boot.git] / board / freescale / mpc8610hpcd / mpc8610hpcd.c
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * Copyright 2007,2009-2011 Freescale Semiconductor, Inc.
4  */
5
6 #include <common.h>
7 #include <command.h>
8 #include <init.h>
9 #include <net.h>
10 #include <pci.h>
11 #include <asm/processor.h>
12 #include <asm/immap_86xx.h>
13 #include <asm/fsl_pci.h>
14 #include <fsl_ddr_sdram.h>
15 #include <asm/fsl_serdes.h>
16 #include <i2c.h>
17 #include <asm/io.h>
18 #include <linux/libfdt.h>
19 #include <fdt_support.h>
20 #include <spd_sdram.h>
21 #include <netdev.h>
22
23 DECLARE_GLOBAL_DATA_PTR;
24
25 void sdram_init(void);
26 phys_size_t fixed_sdram(void);
27 int mpc8610hpcd_diu_init(void);
28
29
30 /* called before any console output */
31 int board_early_init_f(void)
32 {
33         volatile immap_t *immap = (immap_t *)CONFIG_SYS_IMMR;
34         volatile ccsr_gur_t *gur = &immap->im_gur;
35
36         gur->gpiocr |= 0x88aa5500; /* DIU16, IR1, UART0, UART2 */
37
38         return 0;
39 }
40
41 int misc_init_r(void)
42 {
43         u8 tmp_val, version;
44         u8 *pixis_base = (u8 *)PIXIS_BASE;
45
46         /*Do not use 8259PIC*/
47         tmp_val = in_8(pixis_base + PIXIS_BRDCFG0);
48         out_8(pixis_base + PIXIS_BRDCFG0, tmp_val | 0x80);
49
50         /*For FPGA V7 or higher, set the IRQMAPSEL to 0 to use MAP0 interrupt*/
51         version = in_8(pixis_base + PIXIS_PVER);
52         if(version >= 0x07) {
53                 tmp_val = in_8(pixis_base + PIXIS_BRDCFG0);
54                 out_8(pixis_base + PIXIS_BRDCFG0, tmp_val & 0xbf);
55         }
56
57         /* Using this for DIU init before the driver in linux takes over
58          *  Enable the TFP410 Encoder (I2C address 0x38)
59          */
60
61         tmp_val = 0xBF;
62         i2c_write(0x38, 0x08, 1, &tmp_val, sizeof(tmp_val));
63         /* Verify if enabled */
64         tmp_val = 0;
65         i2c_read(0x38, 0x08, 1, &tmp_val, sizeof(tmp_val));
66         debug("DVI Encoder Read: 0x%02x\n", tmp_val);
67
68         tmp_val = 0x10;
69         i2c_write(0x38, 0x0A, 1, &tmp_val, sizeof(tmp_val));
70         /* Verify if enabled */
71         tmp_val = 0;
72         i2c_read(0x38, 0x0A, 1, &tmp_val, sizeof(tmp_val));
73         debug("DVI Encoder Read: 0x%02x\n", tmp_val);
74
75         return 0;
76 }
77
78 int checkboard(void)
79 {
80         volatile immap_t *immap = (immap_t *)CONFIG_SYS_IMMR;
81         volatile ccsr_local_mcm_t *mcm = &immap->im_local_mcm;
82         u8 *pixis_base = (u8 *)PIXIS_BASE;
83
84         printf ("Board: MPC8610HPCD, Sys ID: 0x%02x, "
85                 "Sys Ver: 0x%02x, FPGA Ver: 0x%02x, ",
86                 in_8(pixis_base + PIXIS_ID), in_8(pixis_base + PIXIS_VER),
87                 in_8(pixis_base + PIXIS_PVER));
88
89         /*
90          * The MPC8610 HPCD workbook says that LBMAP=11 is the "normal" boot
91          * bank and LBMAP=00 is the alternate bank.  However, the pixis
92          * altbank code can only set bits, not clear them, so we treat 00 as
93          * the normal bank and 11 as the alternate.
94          */
95         switch (in_8(pixis_base + PIXIS_VBOOT) & 0xC0) {
96         case 0:
97                 puts("vBank: Standard\n");
98                 break;
99         case 0x40:
100                 puts("Promjet\n");
101                 break;
102         case 0x80:
103                 puts("NAND\n");
104                 break;
105         case 0xC0:
106                 puts("vBank: Alternate\n");
107                 break;
108         }
109
110         mcm->abcr |= 0x00010000; /* 0 */
111         mcm->hpmr3 = 0x80000008; /* 4c */
112         mcm->hpmr0 = 0;
113         mcm->hpmr1 = 0;
114         mcm->hpmr2 = 0;
115         mcm->hpmr4 = 0;
116         mcm->hpmr5 = 0;
117
118         return 0;
119 }
120
121
122 int dram_init(void)
123 {
124         phys_size_t dram_size = 0;
125
126 #if defined(CONFIG_SPD_EEPROM)
127         dram_size = fsl_ddr_sdram();
128 #else
129         dram_size = fixed_sdram();
130 #endif
131
132         setup_ddr_bat(dram_size);
133
134         debug(" DDR: ");
135         gd->ram_size = dram_size;
136
137         return 0;
138 }
139
140
141 #if !defined(CONFIG_SPD_EEPROM)
142 /*
143  * Fixed sdram init -- doesn't use serial presence detect.
144  */
145
146 phys_size_t fixed_sdram(void)
147 {
148 #if !defined(CONFIG_SYS_RAMBOOT)
149         volatile immap_t *immap = (immap_t *)CONFIG_SYS_IMMR;
150         struct ccsr_ddr __iomem *ddr = &immap->im_ddr1;
151         uint d_init;
152
153         ddr->cs0_bnds = 0x0000001f;
154         ddr->cs0_config = 0x80010202;
155
156         ddr->timing_cfg_3 = 0x00000000;
157         ddr->timing_cfg_0 = 0x00260802;
158         ddr->timing_cfg_1 = 0x3935d322;
159         ddr->timing_cfg_2 = 0x14904cc8;
160         ddr->sdram_mode = 0x00480432;
161         ddr->sdram_mode_2 = 0x00000000;
162         ddr->sdram_interval = 0x06180fff; /* 0x06180100; */
163         ddr->sdram_data_init = 0xDEADBEEF;
164         ddr->sdram_clk_cntl = 0x03800000;
165         ddr->sdram_cfg_2 = 0x04400010;
166
167 #if defined(CONFIG_DDR_ECC)
168         ddr->err_int_en = 0x0000000d;
169         ddr->err_disable = 0x00000000;
170         ddr->err_sbe = 0x00010000;
171 #endif
172         asm("sync;isync");
173
174         udelay(500);
175
176         ddr->sdram_cfg = 0xc3000000; /* 0xe3008000;*/
177
178
179 #if defined(CONFIG_ECC_INIT_VIA_DDRCONTROLLER)
180         d_init = 1;
181         debug("DDR - 1st controller: memory initializing\n");
182         /*
183          * Poll until memory is initialized.
184          * 512 Meg at 400 might hit this 200 times or so.
185          */
186         while ((ddr->sdram_cfg_2 & (d_init << 4)) != 0)
187                 udelay(1000);
188
189         debug("DDR: memory initialized\n\n");
190         asm("sync; isync");
191         udelay(500);
192 #endif
193
194         return 512 * 1024 * 1024;
195 #endif
196         return CONFIG_SYS_SDRAM_SIZE * 1024 * 1024;
197 }
198
199 #endif
200
201 #if defined(CONFIG_PCI)
202 /*
203  * Initialize PCI Devices, report devices found.
204  */
205
206 #ifndef CONFIG_PCI_PNP
207 static struct pci_config_table pci_fsl86xxads_config_table[] = {
208         {PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID,
209          PCI_IDSEL_NUMBER, PCI_ANY_ID,
210          pci_cfgfunc_config_device, {PCI_ENET0_IOADDR,
211                                  PCI_ENET0_MEMADDR,
212                                  PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER} },
213         {}
214 };
215 #endif
216
217
218 static struct pci_controller pci1_hose;
219 #endif /* CONFIG_PCI */
220
221 void pci_init_board(void)
222 {
223         volatile immap_t *immap = (immap_t *) CONFIG_SYS_CCSRBAR;
224         volatile ccsr_gur_t *gur = &immap->im_gur;
225         struct fsl_pci_info pci_info;
226         u32 devdisr;
227         int first_free_busno;
228         int pci_agent;
229
230         devdisr = in_be32(&gur->devdisr);
231
232         first_free_busno = fsl_pcie_init_board(0);
233
234 #ifdef CONFIG_PCI1
235         if (!(devdisr & MPC86xx_DEVDISR_PCI1)) {
236                 SET_STD_PCI_INFO(pci_info, 1);
237                 set_next_law(pci_info.mem_phys,
238                         law_size_bits(pci_info.mem_size), pci_info.law);
239                 set_next_law(pci_info.io_phys,
240                         law_size_bits(pci_info.io_size), pci_info.law);
241
242                 pci_agent = fsl_setup_hose(&pci1_hose, pci_info.regs);
243                 printf("PCI: connected to PCI slots as %s" \
244                         " (base address %lx)\n",
245                         pci_agent ? "Agent" : "Host",
246                         pci_info.regs);
247 #ifndef CONFIG_PCI_PNP
248                 pci1_hose.config_table = pci_mpc86xxcts_config_table;
249 #endif
250                 first_free_busno = fsl_pci_init_port(&pci_info,
251                                         &pci1_hose, first_free_busno);
252         } else {
253                 printf("PCI: disabled\n");
254         }
255
256         puts("\n");
257 #else
258         setbits_be32(&gur->devdisr, MPC86xx_DEVDISR_PCI1); /* disable */
259 #endif
260
261         fsl_pcie_init_board(first_free_busno);
262 }
263
264 #if defined(CONFIG_OF_BOARD_SETUP)
265 int ft_board_setup(void *blob, bd_t *bd)
266 {
267         ft_cpu_setup(blob, bd);
268
269         FT_FSL_PCI_SETUP;
270
271         return 0;
272 }
273 #endif
274
275 /*
276  * get_board_sys_clk
277  * Reads the FPGA on board for CONFIG_SYS_CLK_FREQ
278  */
279
280 unsigned long
281 get_board_sys_clk(ulong dummy)
282 {
283         u8 i;
284         ulong val = 0;
285         u8 *pixis_base = (u8 *)PIXIS_BASE;
286
287         i = in_8(pixis_base + PIXIS_SPD);
288         i &= 0x07;
289
290         switch (i) {
291         case 0:
292                 val = 33333000;
293                 break;
294         case 1:
295                 val = 39999600;
296                 break;
297         case 2:
298                 val = 49999500;
299                 break;
300         case 3:
301                 val = 66666000;
302                 break;
303         case 4:
304                 val = 83332500;
305                 break;
306         case 5:
307                 val = 99999000;
308                 break;
309         case 6:
310                 val = 133332000;
311                 break;
312         case 7:
313                 val = 166665000;
314                 break;
315         }
316
317         return val;
318 }
319
320 int board_eth_init(bd_t *bis)
321 {
322         return pci_eth_init(bis);
323 }
324
325 void board_reset(void)
326 {
327         u8 *pixis_base = (u8 *)PIXIS_BASE;
328
329         out_8(pixis_base + PIXIS_RST, 0);
330
331         while (1)
332                 ;
333 }