blob: ad56263778f936d2e1f0f9a2e6a548b201da7d1a [file] [log] [blame]
Thomas Gleixnerfcaf2032019-05-27 08:55:08 +02001// SPDX-License-Identifier: GPL-2.0-or-later
Amit Kucheriaa329b482010-02-04 12:21:53 -08002/*
Dinh Nguyenb66ff7a2010-11-15 11:30:00 -06003 * Copyright 2008-2010 Freescale Semiconductor, Inc. All Rights Reserved.
Amit Kucheriaa329b482010-02-04 12:21:53 -08004 *
Amit Kucheriaa329b482010-02-04 12:21:53 -08005 * This file contains the CPU initialization code.
6 */
7
8#include <linux/types.h>
9#include <linux/kernel.h>
10#include <linux/init.h>
Sascha Hauer54438562010-03-19 10:50:55 +010011#include <linux/module.h>
Fabio Estevamca066792011-11-21 16:26:52 -020012#include <linux/io.h>
Shawn Guoee18a712014-05-19 22:23:43 +080013#include <linux/of.h>
14#include <linux/of_address.h>
Amit Kucheriaa329b482010-02-04 12:21:53 -080015
Shawn Guo50f2de62012-09-14 14:14:45 +080016#include "hardware.h"
Fabio Estevam22567792013-03-25 09:20:31 -030017#include "common.h"
Shawn Guo50f2de62012-09-14 14:14:45 +080018
Jason Liuc52c9832011-08-26 13:35:23 +080019static int mx5_cpu_rev = -1;
Sascha Hauer54438562010-03-19 10:50:55 +010020
Dinh Nguyen9ab46502010-11-15 11:30:01 -060021#define IIM_SREV 0x24
Sascha Hauer54438562010-03-19 10:50:55 +010022
Shawn Guoee18a712014-05-19 22:23:43 +080023static u32 imx5_read_srev_reg(const char *compat)
24{
25 void __iomem *iim_base;
26 struct device_node *np;
27 u32 srev;
28
29 np = of_find_compatible_node(NULL, NULL, compat);
30 iim_base = of_iomap(np, 0);
31 WARN_ON(!iim_base);
32
33 srev = readl(iim_base + IIM_SREV) & 0xff;
34
35 iounmap(iim_base);
36
37 return srev;
38}
39
Dinh Nguyen9ab46502010-11-15 11:30:01 -060040static int get_mx51_srev(void)
Sascha Hauer54438562010-03-19 10:50:55 +010041{
Shawn Guoee18a712014-05-19 22:23:43 +080042 u32 rev = imx5_read_srev_reg("fsl,imx51-iim");
Sascha Hauer54438562010-03-19 10:50:55 +010043
Jason Liuc52c9832011-08-26 13:35:23 +080044 switch (rev) {
45 case 0x0:
Dinh Nguyen9ab46502010-11-15 11:30:01 -060046 return IMX_CHIP_REVISION_2_0;
Jason Liuc52c9832011-08-26 13:35:23 +080047 case 0x10:
Dinh Nguyen9ab46502010-11-15 11:30:01 -060048 return IMX_CHIP_REVISION_3_0;
Jason Liuc52c9832011-08-26 13:35:23 +080049 default:
50 return IMX_CHIP_REVISION_UNKNOWN;
51 }
Sascha Hauer54438562010-03-19 10:50:55 +010052}
53
54/*
55 * Returns:
56 * the silicon revision of the cpu
Sascha Hauer54438562010-03-19 10:50:55 +010057 */
58int mx51_revision(void)
59{
Jason Liuc52c9832011-08-26 13:35:23 +080060 if (mx5_cpu_rev == -1)
61 mx5_cpu_rev = get_mx51_srev();
Sascha Hauer54438562010-03-19 10:50:55 +010062
Jason Liuc52c9832011-08-26 13:35:23 +080063 return mx5_cpu_rev;
Sascha Hauer54438562010-03-19 10:50:55 +010064}
65EXPORT_SYMBOL(mx51_revision);
66
Amit Kucheria33d7c5c2010-09-01 22:49:13 +030067#ifdef CONFIG_NEON
68
69/*
70 * All versions of the silicon before Rev. 3 have broken NEON implementations.
71 * Dependent on link order - so the assumption is that vfp_init is called
72 * before us.
73 */
Shawn Guo8321b752012-04-26 11:42:34 +080074int __init mx51_neon_fixup(void)
Amit Kucheria33d7c5c2010-09-01 22:49:13 +030075{
Fabio Estevamca066792011-11-21 16:26:52 -020076 if (mx51_revision() < IMX_CHIP_REVISION_3_0 &&
77 (elf_hwcap & HWCAP_NEON)) {
Amit Kucheria33d7c5c2010-09-01 22:49:13 +030078 elf_hwcap &= ~HWCAP_NEON;
79 pr_info("Turning off NEON support, detected broken NEON implementation\n");
80 }
81 return 0;
82}
83
Amit Kucheria33d7c5c2010-09-01 22:49:13 +030084#endif
85
Dinh Nguyen9ab46502010-11-15 11:30:01 -060086static int get_mx53_srev(void)
87{
Shawn Guoee18a712014-05-19 22:23:43 +080088 u32 rev = imx5_read_srev_reg("fsl,imx53-iim");
Dinh Nguyen9ab46502010-11-15 11:30:01 -060089
Richard Zhao503e1632011-02-18 20:26:30 +080090 switch (rev) {
91 case 0x0:
Dinh Nguyen9ab46502010-11-15 11:30:01 -060092 return IMX_CHIP_REVISION_1_0;
Richard Zhao503e1632011-02-18 20:26:30 +080093 case 0x2:
Dinh Nguyen9ab46502010-11-15 11:30:01 -060094 return IMX_CHIP_REVISION_2_0;
Richard Zhao503e1632011-02-18 20:26:30 +080095 case 0x3:
96 return IMX_CHIP_REVISION_2_1;
97 default:
98 return IMX_CHIP_REVISION_UNKNOWN;
99 }
Dinh Nguyen9ab46502010-11-15 11:30:01 -0600100}
101
Dinh Nguyenb66ff7a2010-11-15 11:30:00 -0600102/*
103 * Returns:
104 * the silicon revision of the cpu
Dinh Nguyenb66ff7a2010-11-15 11:30:00 -0600105 */
106int mx53_revision(void)
107{
Jason Liuc52c9832011-08-26 13:35:23 +0800108 if (mx5_cpu_rev == -1)
109 mx5_cpu_rev = get_mx53_srev();
Dinh Nguyenb66ff7a2010-11-15 11:30:00 -0600110
Jason Liuc52c9832011-08-26 13:35:23 +0800111 return mx5_cpu_rev;
Dinh Nguyenb66ff7a2010-11-15 11:30:00 -0600112}
113EXPORT_SYMBOL(mx53_revision);
Fabio Estevam26b754f2018-07-10 13:31:48 -0300114
115#define ARM_GPC 0x4
116#define DBGEN BIT(16)
117
118/*
119 * This enables the DBGEN bit in ARM_GPC register, which is
120 * required for accessing some performance counter features.
121 * Technically it is only required while perf is used, but to
122 * keep the source code simple we just enable it all the time
123 * when the kernel configuration allows using the feature.
124 */
125void __init imx5_pmu_init(void)
126{
127 void __iomem *tigerp_base;
128 struct device_node *np;
129 u32 gpc;
130
131 if (!IS_ENABLED(CONFIG_ARM_PMU))
132 return;
133
134 np = of_find_compatible_node(NULL, NULL, "arm,cortex-a8-pmu");
135 if (!np)
136 return;
137
138 if (!of_property_read_bool(np, "secure-reg-access"))
139 goto exit;
140
141 of_node_put(np);
142
143 np = of_find_compatible_node(NULL, NULL, "fsl,imx51-tigerp");
144 if (!np)
145 return;
146
147 tigerp_base = of_iomap(np, 0);
148 if (!tigerp_base)
149 goto exit;
150
151 gpc = readl_relaxed(tigerp_base + ARM_GPC);
152 gpc |= DBGEN;
153 writel_relaxed(gpc, tigerp_base + ARM_GPC);
154 iounmap(tigerp_base);
155exit:
156 of_node_put(np);
157
158}