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