2 * Copyright © 2013 Tony Breeds IBM Corporation
3 * Copyright © 2013 Alistair Popple 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
18 * This program is free software; you can redistribute it and/or
19 * modify it under the terms of the GNU General Public License
20 * as published by the Free Software Foundation; either version
21 * 2 of the License, or (at your option) any later version.
41 #define SPRN_PIR 0x11E /* Processor Indentification Register */
42 #define USERDATA_LEN 256 /* Length of userdata passed in by PIBS */
44 #define DDR3_MR0CF 0x80010011U
45 #define CCTL0_MCO2 0x8000080FU
46 #define CCTL0_MCO3 0x80000810U
47 #define CCTL0_MCO4 0x80000811U
48 #define CCTL0_MCO5 0x80000812U
49 #define CCTL0_MCO6 0x80000813U
51 static unsigned long long ibm_akebono_memsize
;
52 static long long unsigned mac_addr
;
54 static unsigned long long ibm_akebono_detect_memsize(void)
58 unsigned long long memsize
= 0;
60 for (i
= 0; i
< MAX_RANKS
; i
++) {
61 reg
= mfdcrx(DDR3_MR0CF
+ i
);
68 memsize
+= (0x800000ULL
<< reg
);
74 static void ibm_akebono_fixups(void)
79 dt_fixup_memory(0x0ULL
, ibm_akebono_memsize
);
81 /* Fixup the SD timeout frequency */
82 mtdcrx(CCTL0_MCO4
, 0x1);
84 /* Disable SD high-speed mode (which seems to be broken) */
85 reg
= mfdcrx(CCTL0_MCO2
) & ~0x2;
86 mtdcrx(CCTL0_MCO2
, reg
);
88 /* Set the MAC address */
89 emac
= finddevice("/plb/opb/ethernet");
92 setprop(emac
, "local-mac-address",
93 ((u8
*) &mac_addr
) + 2 , 6);
97 void platform_init(char *userdata
)
99 unsigned long end_of_ram
, avail_ram
;
103 int len
, i
, userdata_len
;
106 userdata
[USERDATA_LEN
- 1] = '\0';
107 userdata_len
= strlen(userdata
);
108 for (i
= 0; i
< userdata_len
- 15; i
++) {
109 if (strncmp(&userdata
[i
], "local-mac-addr=", 15) == 0) {
110 if (i
> 0 && userdata
[i
- 1] != ' ') {
111 /* We've only found a substring ending
112 * with local-mac-addr so this isn't
113 * our mac address. */
117 mac_addr
= strtoull(&userdata
[i
+ 15], &end
, 16);
119 /* Remove the "local-mac-addr=<...>" from the kernel
120 * command line, including the tailing space if
125 len
= ((int) end
) - ((int) &userdata
[i
]);
126 memmove(&userdata
[i
], end
,
127 userdata_len
- (len
+ i
) + 1);
132 loader_info
.cmdline
= userdata
;
133 loader_info
.cmdline_len
= 256;
135 ibm_akebono_memsize
= ibm_akebono_detect_memsize();
136 if (ibm_akebono_memsize
>> 32)
139 end_of_ram
= ibm_akebono_memsize
;
140 avail_ram
= end_of_ram
- (unsigned long)_end
;
142 simple_alloc_init(_end
, avail_ram
, 128, 64);
143 platform_ops
.fixups
= ibm_akebono_fixups
;
144 platform_ops
.exit
= ibm44x_dbcr_reset
;
145 pir_reg
= mfspr(SPRN_PIR
);
147 /* Make sure FDT blob is sane */
148 if (fdt_check_header(_dtb_start
) != 0)
149 fatal("Invalid device tree blob\n");
151 node
= fdt_node_offset_by_prop_value(_dtb_start
, -1, "device_type",
152 "cpu", sizeof("cpu"));
154 fatal("Cannot find cpu node\n");
155 timebase
= fdt_getprop(_dtb_start
, node
, "timebase-frequency", &size
);
156 if (timebase
&& (size
== 4))
157 timebase_period_ns
= 1000000000 / *timebase
;
159 fdt_set_boot_cpuid_phys(_dtb_start
, pir_reg
);
160 fdt_init(_dtb_start
);
162 serial_console_init();