1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Copyright © 2011 Tony Breeds IBM Corporation
5 * Based on earlier code:
6 * Copyright (C) Paul Mackerras 1997.
8 * Matt Porter <mporter@kernel.crashing.org>
9 * Copyright 2002-2005 MontaVista Software Inc.
11 * Eugene Surovegin <eugene.surovegin@zultys.com> or <ebs@ebshome.net>
12 * Copyright (c) 2003, 2004 Zultys Technologies
14 * Copyright 2007 David Gibson, IBM Corporation.
15 * Copyright 2010 Ben. Herrenschmidt, IBM Corporation.
16 * Copyright © 2011 David Kleikamp IBM Corporation
36 #define DDR3_MR0CF 0x80010011U
38 static unsigned long long ibm_currituck_memsize
;
39 static unsigned long long ibm_currituck_detect_memsize(void)
43 unsigned long long memsize
= 0;
45 for(i
= 0; i
< MAX_RANKS
; i
++){
46 reg
= mfdcrx(DDR3_MR0CF
+ i
);
53 memsize
+= (0x800000ULL
<< reg
);
59 static void ibm_currituck_fixups(void)
61 void *devp
= finddevice("/");
64 dt_fixup_memory(0x0ULL
, ibm_currituck_memsize
);
66 while ((devp
= find_node_by_devtype(devp
, "pci"))) {
67 if (getprop(devp
, "dma-ranges", dma_ranges
, sizeof(dma_ranges
)) < 0) {
68 printf("%s: Failed to get dma-ranges\r\n", __func__
);
72 dma_ranges
[5] = ibm_currituck_memsize
>> 32;
73 dma_ranges
[6] = ibm_currituck_memsize
& 0xffffffffUL
;
75 setprop(devp
, "dma-ranges", dma_ranges
, sizeof(dma_ranges
));
79 #define SPRN_PIR 0x11E /* Processor Identification Register */
80 void platform_init(void)
82 unsigned long end_of_ram
, avail_ram
;
87 ibm_currituck_memsize
= ibm_currituck_detect_memsize();
88 if (ibm_currituck_memsize
>> 32)
91 end_of_ram
= ibm_currituck_memsize
;
92 avail_ram
= end_of_ram
- (unsigned long)_end
;
94 simple_alloc_init(_end
, avail_ram
, 128, 64);
95 platform_ops
.fixups
= ibm_currituck_fixups
;
96 platform_ops
.exit
= ibm44x_dbcr_reset
;
97 pir_reg
= mfspr(SPRN_PIR
);
99 /* Make sure FDT blob is sane */
100 if (fdt_check_header(_dtb_start
) != 0)
101 fatal("Invalid device tree blob\n");
103 node
= fdt_node_offset_by_prop_value(_dtb_start
, -1, "device_type",
104 "cpu", sizeof("cpu"));
106 fatal("Cannot find cpu node\n");
107 timebase
= fdt_getprop(_dtb_start
, node
, "timebase-frequency", &size
);
108 if (timebase
&& (size
== 4))
109 timebase_period_ns
= 1000000000 / *timebase
;
111 fdt_set_boot_cpuid_phys(_dtb_start
, pir_reg
);
112 fdt_init(_dtb_start
);
114 serial_console_init();