xref: /openbmc/linux/arch/arm/mach-davinci/common.c (revision 2a598d0b)
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3  * Code commons to all DaVinci SoCs.
4  *
5  * Author: Mark A. Greer <mgreer@mvista.com>
6  *
7  * 2009 (c) MontaVista Software, Inc.
8  */
9 #include <linux/module.h>
10 #include <linux/io.h>
11 #include <linux/etherdevice.h>
12 #include <linux/davinci_emac.h>
13 #include <linux/dma-mapping.h>
14 #include <linux/platform_data/davinci-cpufreq.h>
15 
16 #include <asm/tlb.h>
17 #include <asm/mach/map.h>
18 
19 #include "common.h"
20 #include "cputype.h"
21 
22 struct davinci_soc_info davinci_soc_info;
23 EXPORT_SYMBOL(davinci_soc_info);
24 
25 static int __init davinci_init_id(struct davinci_soc_info *soc_info)
26 {
27 	int			i;
28 	struct davinci_id	*dip;
29 	u8			variant;
30 	u16			part_no;
31 	void __iomem		*base;
32 
33 	base = ioremap(soc_info->jtag_id_reg, SZ_4K);
34 	if (!base) {
35 		pr_err("Unable to map JTAG ID register\n");
36 		return -ENOMEM;
37 	}
38 
39 	soc_info->jtag_id = __raw_readl(base);
40 	iounmap(base);
41 
42 	variant = (soc_info->jtag_id & 0xf0000000) >> 28;
43 	part_no = (soc_info->jtag_id & 0x0ffff000) >> 12;
44 
45 	for (i = 0, dip = soc_info->ids; i < soc_info->ids_num;
46 			i++, dip++)
47 		/* Don't care about the manufacturer right now */
48 		if ((dip->part_no == part_no) && (dip->variant == variant)) {
49 			soc_info->cpu_id = dip->cpu_id;
50 			pr_info("DaVinci %s variant 0x%x\n", dip->name,
51 					dip->variant);
52 			return 0;
53 		}
54 
55 	pr_err("Unknown DaVinci JTAG ID 0x%x\n", soc_info->jtag_id);
56 	return -EINVAL;
57 }
58 
59 void __init davinci_common_init(const struct davinci_soc_info *soc_info)
60 {
61 	int ret;
62 
63 	if (!soc_info) {
64 		ret = -EINVAL;
65 		goto err;
66 	}
67 
68 	memcpy(&davinci_soc_info, soc_info, sizeof(struct davinci_soc_info));
69 
70 	if (davinci_soc_info.io_desc && (davinci_soc_info.io_desc_num > 0))
71 		iotable_init(davinci_soc_info.io_desc,
72 				davinci_soc_info.io_desc_num);
73 
74 	/*
75 	 * Normally devicemaps_init() would flush caches and tlb after
76 	 * mdesc->map_io(), but we must also do it here because of the CPU
77 	 * revision check below.
78 	 */
79 	local_flush_tlb_all();
80 	flush_cache_all();
81 
82 	/*
83 	 * We want to check CPU revision early for cpu_is_xxxx() macros.
84 	 * IO space mapping must be initialized before we can do that.
85 	 */
86 	ret = davinci_init_id(&davinci_soc_info);
87 	if (ret < 0)
88 		goto err;
89 
90 
91 	return;
92 
93 err:
94 	panic("davinci_common_init: SoC Initialization failed\n");
95 }
96 
97 void __init davinci_init_late(void)
98 {
99 	davinci_cpufreq_init();
100 }
101