xref: /openbmc/linux/arch/powerpc/boot/fsl-soc.c (revision 7d545e77)
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3  * Freescale SOC support functions
4  *
5  * Author: Scott Wood <scottwood@freescale.com>
6  *
7  * Copyright (c) 2007 Freescale Semiconductor, Inc.
8  */
9 
10 #include "ops.h"
11 #include "types.h"
12 #include "fsl-soc.h"
13 #include "stdio.h"
14 
15 static u32 prop_buf[MAX_PROP_LEN / 4];
16 
17 u32 *fsl_get_immr(void)
18 {
19 	void *soc;
20 	unsigned long ret = 0;
21 
22 	soc = find_node_by_devtype(NULL, "soc");
23 	if (soc) {
24 		int size;
25 		u32 naddr;
26 
27 		size = getprop(soc, "#address-cells", prop_buf, MAX_PROP_LEN);
28 		if (size == 4)
29 			naddr = prop_buf[0];
30 		else
31 			naddr = 2;
32 
33 		if (naddr != 1 && naddr != 2)
34 			goto err;
35 
36 		size = getprop(soc, "ranges", prop_buf, MAX_PROP_LEN);
37 
38 		if (size < 12)
39 			goto err;
40 		if (prop_buf[0] != 0)
41 			goto err;
42 		if (naddr == 2 && prop_buf[1] != 0)
43 			goto err;
44 
45 		if (!dt_xlate_addr(soc, prop_buf + naddr, 8, &ret))
46 			ret = 0;
47 	}
48 
49 err:
50 	if (!ret)
51 		printf("fsl_get_immr: Failed to find immr base\r\n");
52 
53 	return (u32 *)ret;
54 }
55