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