blob: bf70e13bbe9ee0ad41155a407006becf8f51d9f2 [file] [log] [blame]
David Brazdil0f672f62019-12-10 10:32:29 +00001// SPDX-License-Identifier: GPL-2.0-or-later
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00002/*
3 * Copyright 2007 Freescale Semiconductor, Inc. All Rights Reserved.
4 * Copyright 2008 Juergen Beisert, kernel@pengutronix.de
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00005 */
6
7/*
8 * i.MX27 specific CPU detection code
9 */
10
11#include <linux/io.h>
Olivier Deprez157378f2022-04-04 15:47:50 +020012#include <linux/of_address.h>
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000013#include <linux/module.h>
14
15#include "hardware.h"
16
17static int mx27_cpu_rev = -1;
18static int mx27_cpu_partnumber;
19
20#define SYS_CHIP_ID 0x00 /* The offset of CHIP ID register */
Olivier Deprez157378f2022-04-04 15:47:50 +020021#define SYSCTRL_OFFSET 0x800 /* Offset from CCM base address */
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000022
23static int mx27_read_cpu_rev(void)
24{
Olivier Deprez157378f2022-04-04 15:47:50 +020025 void __iomem *ccm_base;
26 struct device_node *np;
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000027 u32 val;
Olivier Deprez157378f2022-04-04 15:47:50 +020028
29 np = of_find_compatible_node(NULL, NULL, "fsl,imx27-ccm");
30 ccm_base = of_iomap(np, 0);
31 BUG_ON(!ccm_base);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000032 /*
33 * now we have access to the IO registers. As we need
34 * the silicon revision very early we read it here to
35 * avoid any further hooks
36 */
Olivier Deprez157378f2022-04-04 15:47:50 +020037 val = imx_readl(ccm_base + SYSCTRL_OFFSET + SYS_CHIP_ID);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000038
39 mx27_cpu_partnumber = (int)((val >> 12) & 0xFFFF);
40
41 switch (val >> 28) {
42 case 0:
43 return IMX_CHIP_REVISION_1_0;
44 case 1:
45 return IMX_CHIP_REVISION_2_0;
46 case 2:
47 return IMX_CHIP_REVISION_2_1;
48 default:
49 return IMX_CHIP_REVISION_UNKNOWN;
50 }
51}
52
53/*
54 * Returns:
55 * the silicon revision of the cpu
56 * -EINVAL - not a mx27
57 */
58int mx27_revision(void)
59{
60 if (mx27_cpu_rev == -1)
61 mx27_cpu_rev = mx27_read_cpu_rev();
62
63 if (mx27_cpu_partnumber != 0x8821)
64 return -EINVAL;
65
66 return mx27_cpu_rev;
67}
68EXPORT_SYMBOL(mx27_revision);