blob: 5c5328257dca2f5560ccaa33bf98a27b80582b27 [file] [log] [blame]
Amit Kucheriaa329b482010-02-04 12:21:53 -08001/*
Dinh Nguyenb66ff7a2010-11-15 11:30:00 -06002 * Copyright 2008-2010 Freescale Semiconductor, Inc. All Rights Reserved.
Amit Kucheriaa329b482010-02-04 12:21:53 -08003 *
4 * The code contained herein is licensed under the GNU General Public
5 * License. You may obtain a copy of the GNU General Public License
6 * Version 2 or later at the following locations:
7 *
8 * http://www.opensource.org/licenses/gpl-license.html
9 * http://www.gnu.org/copyleft/gpl.html
10 *
11 * This file contains the CPU initialization code.
12 */
13
14#include <linux/types.h>
15#include <linux/kernel.h>
16#include <linux/init.h>
Sascha Hauer54438562010-03-19 10:50:55 +010017#include <linux/module.h>
Amit Kucheriaa329b482010-02-04 12:21:53 -080018#include <mach/hardware.h>
19#include <asm/io.h>
20
Jason Liuc52c9832011-08-26 13:35:23 +080021static int mx5_cpu_rev = -1;
Sascha Hauer54438562010-03-19 10:50:55 +010022
Dinh Nguyen9ab46502010-11-15 11:30:01 -060023#define IIM_SREV 0x24
Dinh Nguyen16f246e2011-03-21 16:30:35 -050024#define MX50_HW_ADADIG_DIGPROG 0xB0
Sascha Hauer54438562010-03-19 10:50:55 +010025
Dinh Nguyen9ab46502010-11-15 11:30:01 -060026static int get_mx51_srev(void)
Sascha Hauer54438562010-03-19 10:50:55 +010027{
Dinh Nguyen9ab46502010-11-15 11:30:01 -060028 void __iomem *iim_base = MX51_IO_ADDRESS(MX51_IIM_BASE_ADDR);
29 u32 rev = readl(iim_base + IIM_SREV) & 0xff;
Sascha Hauer54438562010-03-19 10:50:55 +010030
Jason Liuc52c9832011-08-26 13:35:23 +080031 switch (rev) {
32 case 0x0:
Dinh Nguyen9ab46502010-11-15 11:30:01 -060033 return IMX_CHIP_REVISION_2_0;
Jason Liuc52c9832011-08-26 13:35:23 +080034 case 0x10:
Dinh Nguyen9ab46502010-11-15 11:30:01 -060035 return IMX_CHIP_REVISION_3_0;
Jason Liuc52c9832011-08-26 13:35:23 +080036 default:
37 return IMX_CHIP_REVISION_UNKNOWN;
38 }
Sascha Hauer54438562010-03-19 10:50:55 +010039}
40
41/*
42 * Returns:
43 * the silicon revision of the cpu
44 * -EINVAL - not a mx51
45 */
46int mx51_revision(void)
47{
48 if (!cpu_is_mx51())
49 return -EINVAL;
50
Jason Liuc52c9832011-08-26 13:35:23 +080051 if (mx5_cpu_rev == -1)
52 mx5_cpu_rev = get_mx51_srev();
Sascha Hauer54438562010-03-19 10:50:55 +010053
Jason Liuc52c9832011-08-26 13:35:23 +080054 return mx5_cpu_rev;
Sascha Hauer54438562010-03-19 10:50:55 +010055}
56EXPORT_SYMBOL(mx51_revision);
57
Amit Kucheria33d7c5c2010-09-01 22:49:13 +030058#ifdef CONFIG_NEON
59
60/*
61 * All versions of the silicon before Rev. 3 have broken NEON implementations.
62 * Dependent on link order - so the assumption is that vfp_init is called
63 * before us.
64 */
65static int __init mx51_neon_fixup(void)
66{
Sascha Hauer92fcdc92010-11-04 23:08:17 +010067 if (!cpu_is_mx51())
68 return 0;
69
Dinh Nguyen9ab46502010-11-15 11:30:01 -060070 if (mx51_revision() < IMX_CHIP_REVISION_3_0 && (elf_hwcap & HWCAP_NEON)) {
Amit Kucheria33d7c5c2010-09-01 22:49:13 +030071 elf_hwcap &= ~HWCAP_NEON;
72 pr_info("Turning off NEON support, detected broken NEON implementation\n");
73 }
74 return 0;
75}
76
77late_initcall(mx51_neon_fixup);
78#endif
79
Dinh Nguyen9ab46502010-11-15 11:30:01 -060080static int get_mx53_srev(void)
81{
82 void __iomem *iim_base = MX51_IO_ADDRESS(MX53_IIM_BASE_ADDR);
83 u32 rev = readl(iim_base + IIM_SREV) & 0xff;
84
Richard Zhao503e1632011-02-18 20:26:30 +080085 switch (rev) {
86 case 0x0:
Dinh Nguyen9ab46502010-11-15 11:30:01 -060087 return IMX_CHIP_REVISION_1_0;
Richard Zhao503e1632011-02-18 20:26:30 +080088 case 0x2:
Dinh Nguyen9ab46502010-11-15 11:30:01 -060089 return IMX_CHIP_REVISION_2_0;
Richard Zhao503e1632011-02-18 20:26:30 +080090 case 0x3:
91 return IMX_CHIP_REVISION_2_1;
92 default:
93 return IMX_CHIP_REVISION_UNKNOWN;
94 }
Dinh Nguyen9ab46502010-11-15 11:30:01 -060095}
96
Dinh Nguyenb66ff7a2010-11-15 11:30:00 -060097/*
98 * Returns:
99 * the silicon revision of the cpu
100 * -EINVAL - not a mx53
101 */
102int mx53_revision(void)
103{
104 if (!cpu_is_mx53())
105 return -EINVAL;
106
Jason Liuc52c9832011-08-26 13:35:23 +0800107 if (mx5_cpu_rev == -1)
108 mx5_cpu_rev = get_mx53_srev();
Dinh Nguyenb66ff7a2010-11-15 11:30:00 -0600109
Jason Liuc52c9832011-08-26 13:35:23 +0800110 return mx5_cpu_rev;
Dinh Nguyenb66ff7a2010-11-15 11:30:00 -0600111}
112EXPORT_SYMBOL(mx53_revision);
113
Dinh Nguyen16f246e2011-03-21 16:30:35 -0500114static int get_mx50_srev(void)
115{
116 void __iomem *anatop = ioremap(MX50_ANATOP_BASE_ADDR, SZ_8K);
117 u32 rev;
118
119 if (!anatop) {
Jason Liuc52c9832011-08-26 13:35:23 +0800120 mx5_cpu_rev = -EINVAL;
Dinh Nguyen16f246e2011-03-21 16:30:35 -0500121 return 0;
122 }
123
124 rev = readl(anatop + MX50_HW_ADADIG_DIGPROG);
125 rev &= 0xff;
126
127 iounmap(anatop);
128 if (rev == 0x0)
129 return IMX_CHIP_REVISION_1_0;
130 else if (rev == 0x1)
131 return IMX_CHIP_REVISION_1_1;
132 return 0;
133}
134
135/*
136 * Returns:
137 * the silicon revision of the cpu
138 * -EINVAL - not a mx50
139 */
140int mx50_revision(void)
141{
142 if (!cpu_is_mx50())
143 return -EINVAL;
144
Jason Liuc52c9832011-08-26 13:35:23 +0800145 if (mx5_cpu_rev == -1)
146 mx5_cpu_rev = get_mx50_srev();
Dinh Nguyen16f246e2011-03-21 16:30:35 -0500147
Jason Liuc52c9832011-08-26 13:35:23 +0800148 return mx5_cpu_rev;
Dinh Nguyen16f246e2011-03-21 16:30:35 -0500149}
150EXPORT_SYMBOL(mx50_revision);
151
Amit Kucheriaa329b482010-02-04 12:21:53 -0800152static int __init post_cpu_init(void)
153{
154 unsigned int reg;
155 void __iomem *base;
156
Dinh Nguyenc0abefd2010-11-15 11:29:59 -0600157 if (cpu_is_mx51() || cpu_is_mx53()) {
158 if (cpu_is_mx51())
159 base = MX51_IO_ADDRESS(MX51_AIPS1_BASE_ADDR);
160 else
161 base = MX53_IO_ADDRESS(MX53_AIPS1_BASE_ADDR);
Amit Kucheriaa329b482010-02-04 12:21:53 -0800162
Dinh Nguyenc0abefd2010-11-15 11:29:59 -0600163 __raw_writel(0x0, base + 0x40);
164 __raw_writel(0x0, base + 0x44);
165 __raw_writel(0x0, base + 0x48);
166 __raw_writel(0x0, base + 0x4C);
167 reg = __raw_readl(base + 0x50) & 0x00FFFFFF;
168 __raw_writel(reg, base + 0x50);
Amit Kucheriaa329b482010-02-04 12:21:53 -0800169
Dinh Nguyenc0abefd2010-11-15 11:29:59 -0600170 if (cpu_is_mx51())
171 base = MX51_IO_ADDRESS(MX51_AIPS2_BASE_ADDR);
172 else
173 base = MX53_IO_ADDRESS(MX53_AIPS2_BASE_ADDR);
174
175 __raw_writel(0x0, base + 0x40);
176 __raw_writel(0x0, base + 0x44);
177 __raw_writel(0x0, base + 0x48);
178 __raw_writel(0x0, base + 0x4C);
179 reg = __raw_readl(base + 0x50) & 0x00FFFFFF;
180 __raw_writel(reg, base + 0x50);
181 }
Amit Kucheriaa329b482010-02-04 12:21:53 -0800182
183 return 0;
184}
185
186postcore_initcall(post_cpu_init);