1b2441318SGreg Kroah-Hartman // SPDX-License-Identifier: GPL-2.0
21ddd35beSThierry Reding #include <linux/err.h>
33995eb82SShawn Guo #include <linux/module.h>
43995eb82SShawn Guo #include <linux/io.h>
5a2887546SShawn Guo #include <linux/of.h>
6e57e4ab5SSteffen Trumtrar #include <linux/of_address.h>
750f2de61SShawn Guo
850f2de61SShawn Guo #include "hardware.h"
9e7feaaa7SFabio Estevam #include "common.h"
103995eb82SShawn Guo
113995eb82SShawn Guo unsigned int __mxc_cpu_type;
12bfefdff8SShawn Guo static unsigned int imx_soc_revision;
13bfefdff8SShawn Guo
mxc_set_cpu_type(unsigned int type)143995eb82SShawn Guo void mxc_set_cpu_type(unsigned int type)
153995eb82SShawn Guo {
163995eb82SShawn Guo __mxc_cpu_type = type;
173995eb82SShawn Guo }
183995eb82SShawn Guo
imx_set_soc_revision(unsigned int rev)19bfefdff8SShawn Guo void imx_set_soc_revision(unsigned int rev)
20bfefdff8SShawn Guo {
21bfefdff8SShawn Guo imx_soc_revision = rev;
22bfefdff8SShawn Guo }
23bfefdff8SShawn Guo
imx_get_soc_revision(void)24bfefdff8SShawn Guo unsigned int imx_get_soc_revision(void)
25bfefdff8SShawn Guo {
26bfefdff8SShawn Guo return imx_soc_revision;
27bfefdff8SShawn Guo }
28bfefdff8SShawn Guo
imx_print_silicon_rev(const char * cpu,int srev)293995eb82SShawn Guo void imx_print_silicon_rev(const char *cpu, int srev)
303995eb82SShawn Guo {
313995eb82SShawn Guo if (srev == IMX_CHIP_REVISION_UNKNOWN)
323995eb82SShawn Guo pr_info("CPU identified as %s, unknown revision\n", cpu);
333995eb82SShawn Guo else
343995eb82SShawn Guo pr_info("CPU identified as %s, silicon rev %d.%d\n",
353995eb82SShawn Guo cpu, (srev >> 4) & 0xf, srev & 0xf);
363995eb82SShawn Guo }
373995eb82SShawn Guo
imx_set_aips(void __iomem * base)383995eb82SShawn Guo void __init imx_set_aips(void __iomem *base)
393995eb82SShawn Guo {
403995eb82SShawn Guo unsigned int reg;
413995eb82SShawn Guo /*
423995eb82SShawn Guo * Set all MPROTx to be non-bufferable, trusted for R/W,
433995eb82SShawn Guo * not forced to user-mode.
443995eb82SShawn Guo */
45c553138fSJohannes Berg imx_writel(0x77777777, base + 0x0);
46c553138fSJohannes Berg imx_writel(0x77777777, base + 0x4);
473995eb82SShawn Guo
483995eb82SShawn Guo /*
493995eb82SShawn Guo * Set all OPACRx to be non-bufferable, to not require
503995eb82SShawn Guo * supervisor privilege level for access, allow for
513995eb82SShawn Guo * write access and untrusted master access.
523995eb82SShawn Guo */
53c553138fSJohannes Berg imx_writel(0x0, base + 0x40);
54c553138fSJohannes Berg imx_writel(0x0, base + 0x44);
55c553138fSJohannes Berg imx_writel(0x0, base + 0x48);
56c553138fSJohannes Berg imx_writel(0x0, base + 0x4C);
57c553138fSJohannes Berg reg = imx_readl(base + 0x50) & 0x00FFFFFF;
58c553138fSJohannes Berg imx_writel(reg, base + 0x50);
593995eb82SShawn Guo }
60a2887546SShawn Guo
imx_aips_allow_unprivileged_access(const char * compat)61e57e4ab5SSteffen Trumtrar void __init imx_aips_allow_unprivileged_access(
62e57e4ab5SSteffen Trumtrar const char *compat)
63e57e4ab5SSteffen Trumtrar {
64e57e4ab5SSteffen Trumtrar void __iomem *aips_base_addr;
65e57e4ab5SSteffen Trumtrar struct device_node *np;
66e57e4ab5SSteffen Trumtrar
67e57e4ab5SSteffen Trumtrar for_each_compatible_node(np, NULL, compat) {
68e57e4ab5SSteffen Trumtrar aips_base_addr = of_iomap(np, 0);
69*cff70654SNicholas Mc Guire WARN_ON(!aips_base_addr);
70e57e4ab5SSteffen Trumtrar imx_set_aips(aips_base_addr);
71e57e4ab5SSteffen Trumtrar }
72e57e4ab5SSteffen Trumtrar }
73