2 * Partially derived from board code for digsyMTC,
4 * Grzegorz Bernacki, Semihalf, gjb@semihalf.com
7 * DENX Software Engineering, Anatolij Gustschin <agust@denx.de>
9 * See file CREDITS for list of people who contributed to this
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License as
14 * published by the Free Software Foundation; either version 2 of
15 * the License, or (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
30 #include <asm/processor.h>
33 #include <fdt_support.h>
39 DECLARE_GLOBAL_DATA_PTR
;
41 #define SDRAM_MODE 0x00CD0000
42 #define SDRAM_CONTROL 0x504F0000
43 #define SDRAM_CONFIG1 0xD2322800
44 #define SDRAM_CONFIG2 0x8AD70000
46 enum ifm_sensor_type
{
47 O2DNT
= 0x00, /* !< O2DNT 32MB */
48 O2DNT2
= 0x01, /* !< O2DNT2 64MB */
49 O3DNT
= 0x02, /* !< O3DNT 32MB */
50 O3DNT_MIN
= 0x40, /* !< O3DNT Minerva 32MB */
51 UNKNOWN
= 0xff, /* !< Unknow sensor */
54 static enum ifm_sensor_type gt_ifm_sensor_type
;
56 #ifndef CONFIG_SYS_RAMBOOT
57 static void sdram_start(int hi_addr
)
59 struct mpc5xxx_sdram
*sdram
= (struct mpc5xxx_sdram
*)MPC5XXX_SDRAM
;
60 long hi_addr_bit
= hi_addr
? 0x01000000 : 0;
61 long control
= SDRAM_CONTROL
| hi_addr_bit
;
63 /* unlock mode register */
64 out_be32(&sdram
->ctrl
, control
| 0x80000000);
66 /* precharge all banks */
67 out_be32(&sdram
->ctrl
, control
| 0x80000002);
70 out_be32(&sdram
->ctrl
, control
| 0x80000004);
72 /* set mode register */
73 out_be32(&sdram
->mode
, SDRAM_MODE
);
75 /* normal operation */
76 out_be32(&sdram
->ctrl
, control
);
81 * ATTENTION: Although partially referenced initdram does NOT make real use
82 * use of CONFIG_SYS_SDRAM_BASE. The code does not work if
83 * CONFIG_SYS_SDRAM_BASE is something else than 0x00000000.
85 phys_size_t
initdram(int board_type
)
87 struct mpc5xxx_mmap_ctl
*mmap_ctl
=
88 (struct mpc5xxx_mmap_ctl
*)CONFIG_SYS_MBAR
;
89 struct mpc5xxx_sdram
*sdram
= (struct mpc5xxx_sdram
*)MPC5XXX_SDRAM
;
94 if (gt_ifm_sensor_type
== O2DNT2
) {
95 /* activate SDRAM CS1 */
96 setbits_be32((void *)MPC5XXX_GPS_PORT_CONFIG
, 0x80000000);
99 #ifndef CONFIG_SYS_RAMBOOT
102 /* setup SDRAM chip selects */
103 out_be32(&mmap_ctl
->sdram0
, 0x0000001E); /* 2 GB at 0x0 */
104 out_be32(&mmap_ctl
->sdram1
, 0x00000000); /* disabled */
106 /* setup config registers */
107 out_be32(&sdram
->config1
, SDRAM_CONFIG1
);
108 out_be32(&sdram
->config2
, SDRAM_CONFIG2
);
110 /* find RAM size using SDRAM CS0 only */
112 test1
= get_ram_size((long *)CONFIG_SYS_SDRAM_BASE
, 0x08000000);
114 test2
= get_ram_size((long *)CONFIG_SYS_SDRAM_BASE
, 0x08000000);
122 /* memory smaller than 1MB is impossible */
123 if (dramsize
< (1 << 20))
126 /* set SDRAM CS0 size according to the amount of RAM found */
128 out_be32(&mmap_ctl
->sdram0
,
129 (0x13 + __builtin_ffs(dramsize
>> 20) - 1));
131 out_be32(&mmap_ctl
->sdram0
, 0); /* disabled */
134 /* let SDRAM CS1 start right after CS0 */
135 out_be32(&mmap_ctl
->sdram1
, dramsize
+ 0x0000001E); /* 2G */
137 /* find RAM size using SDRAM CS1 only */
141 test2
= test1
= get_ram_size((long *)(CONFIG_SYS_SDRAM_BASE
+ dramsize
),
145 test2
= get_ram_size((long *)(CONFIG_SYS_SDRAM_BASE
+ dramsize
),
156 /* memory smaller than 1MB is impossible */
157 if (dramsize2
< (1 << 20))
160 /* set SDRAM CS1 size according to the amount of RAM found */
162 out_be32(&mmap_ctl
->sdram1
, (dramsize
|
163 (0x13 + __builtin_ffs(dramsize2
>> 20) - 1)));
165 out_be32(&mmap_ctl
->sdram1
, dramsize
); /* disabled */
168 #else /* CONFIG_SYS_RAMBOOT */
169 /* retrieve size of memory connected to SDRAM CS0 */
170 dramsize
= in_be32(&mmap_ctl
->sdram0
) & 0xFF;
171 if (dramsize
>= 0x13)
172 dramsize
= (1 << (dramsize
- 0x13)) << 20;
176 /* retrieve size of memory connected to SDRAM CS1 */
177 dramsize2
= in_be32(&mmap_ctl
->sdram1
) & 0xFF;
178 if (dramsize2
>= 0x13)
179 dramsize2
= (1 << (dramsize2
- 0x13)) << 20;
183 #endif /* CONFIG_SYS_RAMBOOT */
186 * On MPC5200B we need to set the special configuration delay in the
187 * DDR controller. Please refer to Freescale's AN3221 "MPC5200B SDRAM
188 * Initialization and Configuration", 3.3.1 SDelay--MBAR + 0x0190:
190 * "The SDelay should be written to a value of 0x00000004. It is
191 * required to account for changes caused by normal wafer processing
196 if ((SVR_MJREV(svr
) >= 2) &&
197 (PVR_MAJ(pvr
) == 1) && (PVR_MIN(pvr
) == 4))
198 out_be32(&sdram
->sdelay
, 0x04);
200 return dramsize
+ dramsize2
;
204 #define GPT_GPIO_IN 0x4
208 struct mpc5xxx_gpt
*gpt
= (struct mpc5xxx_gpt
*)MPC5XXX_GPT
;
209 unsigned char board_config
= 0;
212 /* switch gpt0 - gpt7 to input */
213 for (i
= 0; i
< 7; i
++)
214 out_be32(&gpt
[i
].emsr
, GPT_GPIO_IN
);
216 /* get configuration byte on timer-port */
217 for (i
= 0; i
< 7; i
++)
218 board_config
|= (in_be32(&gpt
[i
].sr
) & 0x100) >> (8 - i
);
222 switch (board_config
) {
225 gt_ifm_sensor_type
= O2DNT
;
229 gt_ifm_sensor_type
= O3DNT
;
233 gt_ifm_sensor_type
= O2DNT2
;
236 puts("O3DNT Minerva\n");
237 gt_ifm_sensor_type
= O3DNT_MIN
;
241 gt_ifm_sensor_type
= UNKNOWN
;
248 int board_early_init_r(void)
250 struct mpc5xxx_lpb
*lpb_regs
= (struct mpc5xxx_lpb
*)MPC5XXX_LPB
;
253 * Now, when we are in RAM, enable flash write access for detection
254 * process. Note that CS_BOOT cannot be cleared when executing in flash.
256 clrbits_be32(&lpb_regs
->cs0_cfg
, 1); /* clear RO */
257 /* disable CS_BOOT */
258 clrbits_be32((void *)MPC5XXX_ADDECR
, (1 << 25));
260 setbits_be32((void *)MPC5XXX_ADDECR
, (1 << 16));
265 #define MIIM_LXT971_LED_CFG_REG 0x14
266 #define LXT971_LED_CFG_LINK_STATUS 0x4000
267 #define LXT971_LED_CFG_RX_TX_ACTIVITY 0x0700
268 #define LXT971_LED_CFG_LINK_ACTIVITY 0x00D0
269 #define LXT971_LED_CFG_PULSE_STRETCH 0x0002
271 * Additional PHY intialization after reset in mpc5xxx_fec_init_phy()
276 * Set LED configuration bits.
277 * It can't be done in misc_init_r() since FEC is not
278 * initialized at this time. Therefore we do it here.
280 miiphy_write("FEC", CONFIG_PHY_ADDR
, MIIM_LXT971_LED_CFG_REG
,
281 LXT971_LED_CFG_LINK_STATUS
|
282 LXT971_LED_CFG_RX_TX_ACTIVITY
|
283 LXT971_LED_CFG_LINK_ACTIVITY
|
284 LXT971_LED_CFG_PULSE_STRETCH
);
287 #if defined(CONFIG_POST)
289 * Reads GPIO pin PSC6_3. A keypress is reported, if PSC6_3 is low. If PSC6_3
290 * is left open, no keypress is detected.
292 int post_hotkeys_pressed(void)
294 struct mpc5xxx_gpio
*gpio
= (struct mpc5xxx_gpio
*) MPC5XXX_GPIO
;
297 * Configure PSC6_1 and PSC6_3 as GPIO. PSC6 then couldn't be used in
298 * CODEC or UART mode. Consumer IrDA should still be possible.
300 clrbits_be32(&gpio
->port_config
, 0x07000000);
301 setbits_be32(&gpio
->port_config
, 0x03000000);
303 /* Enable GPIO for GPIO_IRDA_1 (IR_USB_CLK pin) = PSC6_3 */
304 setbits_be32(&gpio
->simple_gpioe
, 0x20000000);
306 /* Configure GPIO_IRDA_1 as input */
307 clrbits_be32(&gpio
->simple_ddr
, 0x20000000);
309 return (in_be32(&gpio
->simple_ival
) & 0x20000000) ? 0 : 1;
314 static struct pci_controller hose
;
316 void pci_init_board(void)
318 pci_mpc5xxx_init(&hose
);
322 #if defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP)
323 #if defined(CONFIG_SYS_UPDATE_FLASH_SIZE)
324 static void ft_adapt_flash_base(void *blob
)
326 flash_info_t
*dev
= &flash_info
[0];
328 struct fdt_property
*prop
;
332 off
= fdt_node_offset_by_compatible(blob
, -1, "fsl,mpc5200b-lpb");
334 printf("Could not find fsl,mpc5200b-lpb node.\n");
338 /* found compatible property */
339 prop
= fdt_get_property_w(blob
, off
, "ranges", &len
);
341 reg
= reg2
= (u32
*)&prop
->data
[0];
343 reg
[2] = dev
->start
[0];
345 fdt_setprop(blob
, off
, "ranges", reg2
, len
);
347 printf("Could not find ranges\n");
350 extern ulong
flash_get_size(phys_addr_t base
, int banknum
);
352 /* Update the flash baseaddr settings */
353 int update_flash_size(int flash_size
)
355 struct mpc5xxx_mmap_ctl
*mm
=
356 (struct mpc5xxx_mmap_ctl
*) CONFIG_SYS_MBAR
;
360 unsigned long base
= 0x0;
361 u32
*cs_reg
= (u32
*)&mm
->cs0_start
;
363 for (i
= 0; i
< 2; i
++) {
364 dev
= &flash_info
[i
];
367 /* calculate new base addr for this chipselect */
369 out_be32(cs_reg
, START_REG(base
));
371 out_be32(cs_reg
, STOP_REG(base
, dev
->size
));
373 /* recalculate the sectoraddr in the cfi driver */
374 size
+= flash_get_size(base
, i
);
377 flash_protect_default();
378 gd
->bd
->bi_flashstart
= base
;
381 #endif /* defined(CONFIG_SYS_UPDATE_FLASH_SIZE) */
383 void ft_board_setup(void *blob
, bd_t
*bd
)
385 int phy_addr
= CONFIG_PHY_ADDR
;
386 char eth_path
[] = "/soc5200@f0000000/mdio@3000/ethernet-phy@0";
388 ft_cpu_setup(blob
, bd
);
390 #if defined(CONFIG_SYS_UPDATE_FLASH_SIZE)
391 #ifdef CONFIG_FDT_FIXUP_NOR_FLASH_SIZE
392 /* Update reg property in all nor flash nodes too */
393 fdt_fixup_nor_flash_size(blob
);
395 ft_adapt_flash_base(blob
);
397 /* fix up the phy address */
398 do_fixup_by_path(blob
, eth_path
, "reg", &phy_addr
, sizeof(int), 0);
400 #endif /* defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP) */