1*1ddd35beSThierry Reding #include <linux/err.h> 23995eb82SShawn Guo #include <linux/module.h> 33995eb82SShawn Guo #include <linux/io.h> 4a2887546SShawn Guo #include <linux/of.h> 5a2887546SShawn Guo #include <linux/slab.h> 6a2887546SShawn Guo #include <linux/sys_soc.h> 750f2de61SShawn Guo 850f2de61SShawn Guo #include "hardware.h" 9e7feaaa7SFabio Estevam #include "common.h" 103995eb82SShawn Guo 113995eb82SShawn Guo unsigned int __mxc_cpu_type; 123995eb82SShawn Guo EXPORT_SYMBOL(__mxc_cpu_type); 133995eb82SShawn Guo 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 */ 473995eb82SShawn Guo __raw_writel(0x77777777, base + 0x0); 483995eb82SShawn Guo __raw_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 */ 553995eb82SShawn Guo __raw_writel(0x0, base + 0x40); 563995eb82SShawn Guo __raw_writel(0x0, base + 0x44); 573995eb82SShawn Guo __raw_writel(0x0, base + 0x48); 583995eb82SShawn Guo __raw_writel(0x0, base + 0x4C); 593995eb82SShawn Guo reg = __raw_readl(base + 0x50) & 0x00FFFFFF; 603995eb82SShawn Guo __raw_writel(reg, base + 0x50); 613995eb82SShawn Guo } 62a2887546SShawn Guo 63a2887546SShawn Guo struct device * __init imx_soc_device_init(void) 64a2887546SShawn Guo { 65a2887546SShawn Guo struct soc_device_attribute *soc_dev_attr; 66a2887546SShawn Guo struct soc_device *soc_dev; 67a2887546SShawn Guo struct device_node *root; 68a2887546SShawn Guo const char *soc_id; 69a2887546SShawn Guo int ret; 70a2887546SShawn Guo 71a2887546SShawn Guo soc_dev_attr = kzalloc(sizeof(*soc_dev_attr), GFP_KERNEL); 72a2887546SShawn Guo if (!soc_dev_attr) 73a2887546SShawn Guo return NULL; 74a2887546SShawn Guo 75a2887546SShawn Guo soc_dev_attr->family = "Freescale i.MX"; 76a2887546SShawn Guo 77a2887546SShawn Guo root = of_find_node_by_path("/"); 78a2887546SShawn Guo ret = of_property_read_string(root, "model", &soc_dev_attr->machine); 79a2887546SShawn Guo of_node_put(root); 80a2887546SShawn Guo if (ret) 81a2887546SShawn Guo goto free_soc; 82a2887546SShawn Guo 83a2887546SShawn Guo switch (__mxc_cpu_type) { 84a2887546SShawn Guo case MXC_CPU_MX1: 85a2887546SShawn Guo soc_id = "i.MX1"; 86a2887546SShawn Guo break; 87a2887546SShawn Guo case MXC_CPU_MX21: 88a2887546SShawn Guo soc_id = "i.MX21"; 89a2887546SShawn Guo break; 90a2887546SShawn Guo case MXC_CPU_MX25: 91a2887546SShawn Guo soc_id = "i.MX25"; 92a2887546SShawn Guo break; 93a2887546SShawn Guo case MXC_CPU_MX27: 94a2887546SShawn Guo soc_id = "i.MX27"; 95a2887546SShawn Guo break; 96a2887546SShawn Guo case MXC_CPU_MX31: 97a2887546SShawn Guo soc_id = "i.MX31"; 98a2887546SShawn Guo break; 99a2887546SShawn Guo case MXC_CPU_MX35: 100a2887546SShawn Guo soc_id = "i.MX35"; 101a2887546SShawn Guo break; 102a2887546SShawn Guo case MXC_CPU_MX51: 103a2887546SShawn Guo soc_id = "i.MX51"; 104a2887546SShawn Guo break; 105a2887546SShawn Guo case MXC_CPU_MX53: 106a2887546SShawn Guo soc_id = "i.MX53"; 107a2887546SShawn Guo break; 108a2887546SShawn Guo case MXC_CPU_IMX6SL: 109a2887546SShawn Guo soc_id = "i.MX6SL"; 110a2887546SShawn Guo break; 111a2887546SShawn Guo case MXC_CPU_IMX6DL: 112a2887546SShawn Guo soc_id = "i.MX6DL"; 113a2887546SShawn Guo break; 114a2887546SShawn Guo case MXC_CPU_IMX6Q: 115a2887546SShawn Guo soc_id = "i.MX6Q"; 116a2887546SShawn Guo break; 117a2887546SShawn Guo default: 118a2887546SShawn Guo soc_id = "Unknown"; 119a2887546SShawn Guo } 120a2887546SShawn Guo soc_dev_attr->soc_id = soc_id; 121a2887546SShawn Guo 122a2887546SShawn Guo soc_dev_attr->revision = kasprintf(GFP_KERNEL, "%d.%d", 123a2887546SShawn Guo (imx_soc_revision >> 4) & 0xf, 124a2887546SShawn Guo imx_soc_revision & 0xf); 125a2887546SShawn Guo if (!soc_dev_attr->revision) 126a2887546SShawn Guo goto free_soc; 127a2887546SShawn Guo 128a2887546SShawn Guo soc_dev = soc_device_register(soc_dev_attr); 129a2887546SShawn Guo if (IS_ERR(soc_dev)) 130a2887546SShawn Guo goto free_rev; 131a2887546SShawn Guo 132a2887546SShawn Guo return soc_device_to_device(soc_dev); 133a2887546SShawn Guo 134a2887546SShawn Guo free_rev: 135a2887546SShawn Guo kfree(soc_dev_attr->revision); 136a2887546SShawn Guo free_soc: 137a2887546SShawn Guo kfree(soc_dev_attr); 138a2887546SShawn Guo return NULL; 139a2887546SShawn Guo } 140