xref: /linux/arch/arm/mach-imx/cpu.c (revision e57e4ab5fc2e4e58447d13493c3e567b61359523)
11ddd35beSThierry Reding #include <linux/err.h>
23995eb82SShawn Guo #include <linux/module.h>
33995eb82SShawn Guo #include <linux/io.h>
4a2887546SShawn Guo #include <linux/of.h>
5*e57e4ab5SSteffen Trumtrar #include <linux/of_address.h>
6a2887546SShawn Guo #include <linux/slab.h>
7a2887546SShawn Guo #include <linux/sys_soc.h>
850f2de61SShawn Guo 
950f2de61SShawn Guo #include "hardware.h"
10e7feaaa7SFabio Estevam #include "common.h"
113995eb82SShawn Guo 
123995eb82SShawn Guo unsigned int __mxc_cpu_type;
133995eb82SShawn Guo EXPORT_SYMBOL(__mxc_cpu_type);
143995eb82SShawn Guo 
15bfefdff8SShawn Guo static unsigned int imx_soc_revision;
16bfefdff8SShawn Guo 
173995eb82SShawn Guo void mxc_set_cpu_type(unsigned int type)
183995eb82SShawn Guo {
193995eb82SShawn Guo 	__mxc_cpu_type = type;
203995eb82SShawn Guo }
213995eb82SShawn Guo 
22bfefdff8SShawn Guo void imx_set_soc_revision(unsigned int rev)
23bfefdff8SShawn Guo {
24bfefdff8SShawn Guo 	imx_soc_revision = rev;
25bfefdff8SShawn Guo }
26bfefdff8SShawn Guo 
27bfefdff8SShawn Guo unsigned int imx_get_soc_revision(void)
28bfefdff8SShawn Guo {
29bfefdff8SShawn Guo 	return imx_soc_revision;
30bfefdff8SShawn Guo }
31bfefdff8SShawn Guo 
323995eb82SShawn Guo void imx_print_silicon_rev(const char *cpu, int srev)
333995eb82SShawn Guo {
343995eb82SShawn Guo 	if (srev == IMX_CHIP_REVISION_UNKNOWN)
353995eb82SShawn Guo 		pr_info("CPU identified as %s, unknown revision\n", cpu);
363995eb82SShawn Guo 	else
373995eb82SShawn Guo 		pr_info("CPU identified as %s, silicon rev %d.%d\n",
383995eb82SShawn Guo 				cpu, (srev >> 4) & 0xf, srev & 0xf);
393995eb82SShawn Guo }
403995eb82SShawn Guo 
413995eb82SShawn Guo void __init imx_set_aips(void __iomem *base)
423995eb82SShawn Guo {
433995eb82SShawn Guo 	unsigned int reg;
443995eb82SShawn Guo /*
453995eb82SShawn Guo  * Set all MPROTx to be non-bufferable, trusted for R/W,
463995eb82SShawn Guo  * not forced to user-mode.
473995eb82SShawn Guo  */
483995eb82SShawn Guo 	__raw_writel(0x77777777, base + 0x0);
493995eb82SShawn Guo 	__raw_writel(0x77777777, base + 0x4);
503995eb82SShawn Guo 
513995eb82SShawn Guo /*
523995eb82SShawn Guo  * Set all OPACRx to be non-bufferable, to not require
533995eb82SShawn Guo  * supervisor privilege level for access, allow for
543995eb82SShawn Guo  * write access and untrusted master access.
553995eb82SShawn Guo  */
563995eb82SShawn Guo 	__raw_writel(0x0, base + 0x40);
573995eb82SShawn Guo 	__raw_writel(0x0, base + 0x44);
583995eb82SShawn Guo 	__raw_writel(0x0, base + 0x48);
593995eb82SShawn Guo 	__raw_writel(0x0, base + 0x4C);
603995eb82SShawn Guo 	reg = __raw_readl(base + 0x50) & 0x00FFFFFF;
613995eb82SShawn Guo 	__raw_writel(reg, base + 0x50);
623995eb82SShawn Guo }
63a2887546SShawn Guo 
64*e57e4ab5SSteffen Trumtrar void __init imx_aips_allow_unprivileged_access(
65*e57e4ab5SSteffen Trumtrar 		const char *compat)
66*e57e4ab5SSteffen Trumtrar {
67*e57e4ab5SSteffen Trumtrar 	void __iomem *aips_base_addr;
68*e57e4ab5SSteffen Trumtrar 	struct device_node *np;
69*e57e4ab5SSteffen Trumtrar 
70*e57e4ab5SSteffen Trumtrar 	for_each_compatible_node(np, NULL, compat) {
71*e57e4ab5SSteffen Trumtrar 		aips_base_addr = of_iomap(np, 0);
72*e57e4ab5SSteffen Trumtrar 		imx_set_aips(aips_base_addr);
73*e57e4ab5SSteffen Trumtrar 	}
74*e57e4ab5SSteffen Trumtrar }
75*e57e4ab5SSteffen Trumtrar 
76a2887546SShawn Guo struct device * __init imx_soc_device_init(void)
77a2887546SShawn Guo {
78a2887546SShawn Guo 	struct soc_device_attribute *soc_dev_attr;
79a2887546SShawn Guo 	struct soc_device *soc_dev;
80a2887546SShawn Guo 	struct device_node *root;
81a2887546SShawn Guo 	const char *soc_id;
82a2887546SShawn Guo 	int ret;
83a2887546SShawn Guo 
84a2887546SShawn Guo 	soc_dev_attr = kzalloc(sizeof(*soc_dev_attr), GFP_KERNEL);
85a2887546SShawn Guo 	if (!soc_dev_attr)
86a2887546SShawn Guo 		return NULL;
87a2887546SShawn Guo 
88a2887546SShawn Guo 	soc_dev_attr->family = "Freescale i.MX";
89a2887546SShawn Guo 
90a2887546SShawn Guo 	root = of_find_node_by_path("/");
91a2887546SShawn Guo 	ret = of_property_read_string(root, "model", &soc_dev_attr->machine);
92a2887546SShawn Guo 	of_node_put(root);
93a2887546SShawn Guo 	if (ret)
94a2887546SShawn Guo 		goto free_soc;
95a2887546SShawn Guo 
96a2887546SShawn Guo 	switch (__mxc_cpu_type) {
97a2887546SShawn Guo 	case MXC_CPU_MX1:
98a2887546SShawn Guo 		soc_id = "i.MX1";
99a2887546SShawn Guo 		break;
100a2887546SShawn Guo 	case MXC_CPU_MX21:
101a2887546SShawn Guo 		soc_id = "i.MX21";
102a2887546SShawn Guo 		break;
103a2887546SShawn Guo 	case MXC_CPU_MX25:
104a2887546SShawn Guo 		soc_id = "i.MX25";
105a2887546SShawn Guo 		break;
106a2887546SShawn Guo 	case MXC_CPU_MX27:
107a2887546SShawn Guo 		soc_id = "i.MX27";
108a2887546SShawn Guo 		break;
109a2887546SShawn Guo 	case MXC_CPU_MX31:
110a2887546SShawn Guo 		soc_id = "i.MX31";
111a2887546SShawn Guo 		break;
112a2887546SShawn Guo 	case MXC_CPU_MX35:
113a2887546SShawn Guo 		soc_id = "i.MX35";
114a2887546SShawn Guo 		break;
115a2887546SShawn Guo 	case MXC_CPU_MX51:
116a2887546SShawn Guo 		soc_id = "i.MX51";
117a2887546SShawn Guo 		break;
118a2887546SShawn Guo 	case MXC_CPU_MX53:
119a2887546SShawn Guo 		soc_id = "i.MX53";
120a2887546SShawn Guo 		break;
121a2887546SShawn Guo 	case MXC_CPU_IMX6SL:
122a2887546SShawn Guo 		soc_id = "i.MX6SL";
123a2887546SShawn Guo 		break;
124a2887546SShawn Guo 	case MXC_CPU_IMX6DL:
125a2887546SShawn Guo 		soc_id = "i.MX6DL";
126a2887546SShawn Guo 		break;
127d9654dceSShawn Guo 	case MXC_CPU_IMX6SX:
128d9654dceSShawn Guo 		soc_id = "i.MX6SX";
129d9654dceSShawn Guo 		break;
130a2887546SShawn Guo 	case MXC_CPU_IMX6Q:
131a2887546SShawn Guo 		soc_id = "i.MX6Q";
132a2887546SShawn Guo 		break;
133a2887546SShawn Guo 	default:
134a2887546SShawn Guo 		soc_id = "Unknown";
135a2887546SShawn Guo 	}
136a2887546SShawn Guo 	soc_dev_attr->soc_id = soc_id;
137a2887546SShawn Guo 
138a2887546SShawn Guo 	soc_dev_attr->revision = kasprintf(GFP_KERNEL, "%d.%d",
139a2887546SShawn Guo 					   (imx_soc_revision >> 4) & 0xf,
140a2887546SShawn Guo 					   imx_soc_revision & 0xf);
141a2887546SShawn Guo 	if (!soc_dev_attr->revision)
142a2887546SShawn Guo 		goto free_soc;
143a2887546SShawn Guo 
144a2887546SShawn Guo 	soc_dev = soc_device_register(soc_dev_attr);
145a2887546SShawn Guo 	if (IS_ERR(soc_dev))
146a2887546SShawn Guo 		goto free_rev;
147a2887546SShawn Guo 
148a2887546SShawn Guo 	return soc_device_to_device(soc_dev);
149a2887546SShawn Guo 
150a2887546SShawn Guo free_rev:
151a2887546SShawn Guo 	kfree(soc_dev_attr->revision);
152a2887546SShawn Guo free_soc:
153a2887546SShawn Guo 	kfree(soc_dev_attr);
154a2887546SShawn Guo 	return NULL;
155a2887546SShawn Guo }
156