xref: /linux/arch/arm/mach-imx/cpu.c (revision a28875462bd493fc1bb041c21f811b4a0577a497)
13995eb82SShawn Guo 
23995eb82SShawn Guo #include <linux/module.h>
33995eb82SShawn Guo #include <linux/io.h>
4*a2887546SShawn Guo #include <linux/of.h>
5*a2887546SShawn Guo #include <linux/slab.h>
6*a2887546SShawn 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 }
62*a2887546SShawn Guo 
63*a2887546SShawn Guo struct device * __init imx_soc_device_init(void)
64*a2887546SShawn Guo {
65*a2887546SShawn Guo 	struct soc_device_attribute *soc_dev_attr;
66*a2887546SShawn Guo 	struct soc_device *soc_dev;
67*a2887546SShawn Guo 	struct device_node *root;
68*a2887546SShawn Guo 	const char *soc_id;
69*a2887546SShawn Guo 	int ret;
70*a2887546SShawn Guo 
71*a2887546SShawn Guo 	soc_dev_attr = kzalloc(sizeof(*soc_dev_attr), GFP_KERNEL);
72*a2887546SShawn Guo 	if (!soc_dev_attr)
73*a2887546SShawn Guo 		return NULL;
74*a2887546SShawn Guo 
75*a2887546SShawn Guo 	soc_dev_attr->family = "Freescale i.MX";
76*a2887546SShawn Guo 
77*a2887546SShawn Guo 	root = of_find_node_by_path("/");
78*a2887546SShawn Guo 	ret = of_property_read_string(root, "model", &soc_dev_attr->machine);
79*a2887546SShawn Guo 	of_node_put(root);
80*a2887546SShawn Guo 	if (ret)
81*a2887546SShawn Guo 		goto free_soc;
82*a2887546SShawn Guo 
83*a2887546SShawn Guo 	switch (__mxc_cpu_type) {
84*a2887546SShawn Guo 	case MXC_CPU_MX1:
85*a2887546SShawn Guo 		soc_id = "i.MX1";
86*a2887546SShawn Guo 		break;
87*a2887546SShawn Guo 	case MXC_CPU_MX21:
88*a2887546SShawn Guo 		soc_id = "i.MX21";
89*a2887546SShawn Guo 		break;
90*a2887546SShawn Guo 	case MXC_CPU_MX25:
91*a2887546SShawn Guo 		soc_id = "i.MX25";
92*a2887546SShawn Guo 		break;
93*a2887546SShawn Guo 	case MXC_CPU_MX27:
94*a2887546SShawn Guo 		soc_id = "i.MX27";
95*a2887546SShawn Guo 		break;
96*a2887546SShawn Guo 	case MXC_CPU_MX31:
97*a2887546SShawn Guo 		soc_id = "i.MX31";
98*a2887546SShawn Guo 		break;
99*a2887546SShawn Guo 	case MXC_CPU_MX35:
100*a2887546SShawn Guo 		soc_id = "i.MX35";
101*a2887546SShawn Guo 		break;
102*a2887546SShawn Guo 	case MXC_CPU_MX51:
103*a2887546SShawn Guo 		soc_id = "i.MX51";
104*a2887546SShawn Guo 		break;
105*a2887546SShawn Guo 	case MXC_CPU_MX53:
106*a2887546SShawn Guo 		soc_id = "i.MX53";
107*a2887546SShawn Guo 		break;
108*a2887546SShawn Guo 	case MXC_CPU_IMX6SL:
109*a2887546SShawn Guo 		soc_id = "i.MX6SL";
110*a2887546SShawn Guo 		break;
111*a2887546SShawn Guo 	case MXC_CPU_IMX6DL:
112*a2887546SShawn Guo 		soc_id = "i.MX6DL";
113*a2887546SShawn Guo 		break;
114*a2887546SShawn Guo 	case MXC_CPU_IMX6Q:
115*a2887546SShawn Guo 		soc_id = "i.MX6Q";
116*a2887546SShawn Guo 		break;
117*a2887546SShawn Guo 	default:
118*a2887546SShawn Guo 		soc_id = "Unknown";
119*a2887546SShawn Guo 	}
120*a2887546SShawn Guo 	soc_dev_attr->soc_id = soc_id;
121*a2887546SShawn Guo 
122*a2887546SShawn Guo 	soc_dev_attr->revision = kasprintf(GFP_KERNEL, "%d.%d",
123*a2887546SShawn Guo 					   (imx_soc_revision >> 4) & 0xf,
124*a2887546SShawn Guo 					   imx_soc_revision & 0xf);
125*a2887546SShawn Guo 	if (!soc_dev_attr->revision)
126*a2887546SShawn Guo 		goto free_soc;
127*a2887546SShawn Guo 
128*a2887546SShawn Guo 	soc_dev = soc_device_register(soc_dev_attr);
129*a2887546SShawn Guo 	if (IS_ERR(soc_dev))
130*a2887546SShawn Guo 		goto free_rev;
131*a2887546SShawn Guo 
132*a2887546SShawn Guo 	return soc_device_to_device(soc_dev);
133*a2887546SShawn Guo 
134*a2887546SShawn Guo free_rev:
135*a2887546SShawn Guo 	kfree(soc_dev_attr->revision);
136*a2887546SShawn Guo free_soc:
137*a2887546SShawn Guo 	kfree(soc_dev_attr);
138*a2887546SShawn Guo 	return NULL;
139*a2887546SShawn Guo }
140