1*b2441318SGreg 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> 7a2887546SShawn Guo #include <linux/slab.h> 8a2887546SShawn Guo #include <linux/sys_soc.h> 950f2de61SShawn Guo 1050f2de61SShawn Guo #include "hardware.h" 11e7feaaa7SFabio Estevam #include "common.h" 123995eb82SShawn Guo 133995eb82SShawn Guo unsigned int __mxc_cpu_type; 14bfefdff8SShawn Guo static unsigned int imx_soc_revision; 15bfefdff8SShawn Guo 163995eb82SShawn Guo void mxc_set_cpu_type(unsigned int type) 173995eb82SShawn Guo { 183995eb82SShawn Guo __mxc_cpu_type = type; 193995eb82SShawn Guo } 203995eb82SShawn Guo 21bfefdff8SShawn Guo void imx_set_soc_revision(unsigned int rev) 22bfefdff8SShawn Guo { 23bfefdff8SShawn Guo imx_soc_revision = rev; 24bfefdff8SShawn Guo } 25bfefdff8SShawn Guo 26bfefdff8SShawn Guo unsigned int imx_get_soc_revision(void) 27bfefdff8SShawn Guo { 28bfefdff8SShawn Guo return imx_soc_revision; 29bfefdff8SShawn Guo } 30bfefdff8SShawn Guo 313995eb82SShawn Guo void imx_print_silicon_rev(const char *cpu, int srev) 323995eb82SShawn Guo { 333995eb82SShawn Guo if (srev == IMX_CHIP_REVISION_UNKNOWN) 343995eb82SShawn Guo pr_info("CPU identified as %s, unknown revision\n", cpu); 353995eb82SShawn Guo else 363995eb82SShawn Guo pr_info("CPU identified as %s, silicon rev %d.%d\n", 373995eb82SShawn Guo cpu, (srev >> 4) & 0xf, srev & 0xf); 383995eb82SShawn Guo } 393995eb82SShawn Guo 403995eb82SShawn Guo void __init imx_set_aips(void __iomem *base) 413995eb82SShawn Guo { 423995eb82SShawn Guo unsigned int reg; 433995eb82SShawn Guo /* 443995eb82SShawn Guo * Set all MPROTx to be non-bufferable, trusted for R/W, 453995eb82SShawn Guo * not forced to user-mode. 463995eb82SShawn Guo */ 47c553138fSJohannes Berg imx_writel(0x77777777, base + 0x0); 48c553138fSJohannes Berg imx_writel(0x77777777, base + 0x4); 493995eb82SShawn Guo 503995eb82SShawn Guo /* 513995eb82SShawn Guo * Set all OPACRx to be non-bufferable, to not require 523995eb82SShawn Guo * supervisor privilege level for access, allow for 533995eb82SShawn Guo * write access and untrusted master access. 543995eb82SShawn Guo */ 55c553138fSJohannes Berg imx_writel(0x0, base + 0x40); 56c553138fSJohannes Berg imx_writel(0x0, base + 0x44); 57c553138fSJohannes Berg imx_writel(0x0, base + 0x48); 58c553138fSJohannes Berg imx_writel(0x0, base + 0x4C); 59c553138fSJohannes Berg reg = imx_readl(base + 0x50) & 0x00FFFFFF; 60c553138fSJohannes Berg imx_writel(reg, base + 0x50); 613995eb82SShawn Guo } 62a2887546SShawn Guo 63e57e4ab5SSteffen Trumtrar void __init imx_aips_allow_unprivileged_access( 64e57e4ab5SSteffen Trumtrar const char *compat) 65e57e4ab5SSteffen Trumtrar { 66e57e4ab5SSteffen Trumtrar void __iomem *aips_base_addr; 67e57e4ab5SSteffen Trumtrar struct device_node *np; 68e57e4ab5SSteffen Trumtrar 69e57e4ab5SSteffen Trumtrar for_each_compatible_node(np, NULL, compat) { 70e57e4ab5SSteffen Trumtrar aips_base_addr = of_iomap(np, 0); 71e57e4ab5SSteffen Trumtrar imx_set_aips(aips_base_addr); 72e57e4ab5SSteffen Trumtrar } 73e57e4ab5SSteffen Trumtrar } 74e57e4ab5SSteffen Trumtrar 75a2887546SShawn Guo struct device * __init imx_soc_device_init(void) 76a2887546SShawn Guo { 77a2887546SShawn Guo struct soc_device_attribute *soc_dev_attr; 78a2887546SShawn Guo struct soc_device *soc_dev; 79a2887546SShawn Guo struct device_node *root; 80a2887546SShawn Guo const char *soc_id; 81a2887546SShawn Guo int ret; 82a2887546SShawn Guo 83a2887546SShawn Guo soc_dev_attr = kzalloc(sizeof(*soc_dev_attr), GFP_KERNEL); 84a2887546SShawn Guo if (!soc_dev_attr) 85a2887546SShawn Guo return NULL; 86a2887546SShawn Guo 87a2887546SShawn Guo soc_dev_attr->family = "Freescale i.MX"; 88a2887546SShawn Guo 89a2887546SShawn Guo root = of_find_node_by_path("/"); 90a2887546SShawn Guo ret = of_property_read_string(root, "model", &soc_dev_attr->machine); 91a2887546SShawn Guo of_node_put(root); 92a2887546SShawn Guo if (ret) 93a2887546SShawn Guo goto free_soc; 94a2887546SShawn Guo 95a2887546SShawn Guo switch (__mxc_cpu_type) { 96a2887546SShawn Guo case MXC_CPU_MX1: 97a2887546SShawn Guo soc_id = "i.MX1"; 98a2887546SShawn Guo break; 99a2887546SShawn Guo case MXC_CPU_MX21: 100a2887546SShawn Guo soc_id = "i.MX21"; 101a2887546SShawn Guo break; 102a2887546SShawn Guo case MXC_CPU_MX25: 103a2887546SShawn Guo soc_id = "i.MX25"; 104a2887546SShawn Guo break; 105a2887546SShawn Guo case MXC_CPU_MX27: 106a2887546SShawn Guo soc_id = "i.MX27"; 107a2887546SShawn Guo break; 108a2887546SShawn Guo case MXC_CPU_MX31: 109a2887546SShawn Guo soc_id = "i.MX31"; 110a2887546SShawn Guo break; 111a2887546SShawn Guo case MXC_CPU_MX35: 112a2887546SShawn Guo soc_id = "i.MX35"; 113a2887546SShawn Guo break; 114a2887546SShawn Guo case MXC_CPU_MX51: 115a2887546SShawn Guo soc_id = "i.MX51"; 116a2887546SShawn Guo break; 117a2887546SShawn Guo case MXC_CPU_MX53: 118a2887546SShawn Guo soc_id = "i.MX53"; 119a2887546SShawn Guo break; 120a2887546SShawn Guo case MXC_CPU_IMX6SL: 121a2887546SShawn Guo soc_id = "i.MX6SL"; 122a2887546SShawn Guo break; 123a2887546SShawn Guo case MXC_CPU_IMX6DL: 124a2887546SShawn Guo soc_id = "i.MX6DL"; 125a2887546SShawn Guo break; 126d9654dceSShawn Guo case MXC_CPU_IMX6SX: 127d9654dceSShawn Guo soc_id = "i.MX6SX"; 128d9654dceSShawn Guo break; 129a2887546SShawn Guo case MXC_CPU_IMX6Q: 130a2887546SShawn Guo soc_id = "i.MX6Q"; 131a2887546SShawn Guo break; 132022d0716SFrank Li case MXC_CPU_IMX6UL: 133022d0716SFrank Li soc_id = "i.MX6UL"; 134022d0716SFrank Li break; 135b3ea5757SLeonard Crestez case MXC_CPU_IMX6ULL: 136b3ea5757SLeonard Crestez soc_id = "i.MX6ULL"; 137b3ea5757SLeonard Crestez break; 1385739b919SAnson Huang case MXC_CPU_IMX7D: 1395739b919SAnson Huang soc_id = "i.MX7D"; 1405739b919SAnson Huang break; 141a2887546SShawn Guo default: 142a2887546SShawn Guo soc_id = "Unknown"; 143a2887546SShawn Guo } 144a2887546SShawn Guo soc_dev_attr->soc_id = soc_id; 145a2887546SShawn Guo 146a2887546SShawn Guo soc_dev_attr->revision = kasprintf(GFP_KERNEL, "%d.%d", 147a2887546SShawn Guo (imx_soc_revision >> 4) & 0xf, 148a2887546SShawn Guo imx_soc_revision & 0xf); 149a2887546SShawn Guo if (!soc_dev_attr->revision) 150a2887546SShawn Guo goto free_soc; 151a2887546SShawn Guo 152a2887546SShawn Guo soc_dev = soc_device_register(soc_dev_attr); 153a2887546SShawn Guo if (IS_ERR(soc_dev)) 154a2887546SShawn Guo goto free_rev; 155a2887546SShawn Guo 156a2887546SShawn Guo return soc_device_to_device(soc_dev); 157a2887546SShawn Guo 158a2887546SShawn Guo free_rev: 159a2887546SShawn Guo kfree(soc_dev_attr->revision); 160a2887546SShawn Guo free_soc: 161a2887546SShawn Guo kfree(soc_dev_attr); 162a2887546SShawn Guo return NULL; 163a2887546SShawn Guo } 164