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