blob: 80e7d8ab9f1bb81ad4a70fb8805a45bb170ff01f [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 * MX35 CPU type detection
4 *
5 * Copyright (c) 2009 Daniel Mack <daniel@caiaq.de>
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00006 */
7#include <linux/module.h>
Olivier Deprez157378f2022-04-04 15:47:50 +02008#include <linux/of_address.h>
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00009#include <linux/io.h>
10
11#include "hardware.h"
12#include "iim.h"
13
14static int mx35_cpu_rev = -1;
15
16static int mx35_read_cpu_rev(void)
17{
Olivier Deprez157378f2022-04-04 15:47:50 +020018 void __iomem *iim_base;
19 struct device_node *np;
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000020 u32 rev;
21
Olivier Deprez157378f2022-04-04 15:47:50 +020022 np = of_find_compatible_node(NULL, NULL, "fsl,imx35-iim");
23 iim_base = of_iomap(np, 0);
24 BUG_ON(!iim_base);
25
26 rev = imx_readl(iim_base + MXC_IIMSREV);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000027 switch (rev) {
28 case 0x00:
29 return IMX_CHIP_REVISION_1_0;
30 case 0x10:
31 return IMX_CHIP_REVISION_2_0;
32 case 0x11:
33 return IMX_CHIP_REVISION_2_1;
34 default:
35 return IMX_CHIP_REVISION_UNKNOWN;
36 }
37}
38
39int mx35_revision(void)
40{
41 if (mx35_cpu_rev == -1)
42 mx35_cpu_rev = mx35_read_cpu_rev();
43
44 return mx35_cpu_rev;
45}
46EXPORT_SYMBOL(mx35_revision);