xref: /openbmc/linux/arch/arm/mach-davinci/common.c (revision b9ab1279)
1 /*
2  * Code commons to all DaVinci SoCs.
3  *
4  * Author: Mark A. Greer <mgreer@mvista.com>
5  *
6  * 2009 (c) MontaVista Software, Inc. This file is licensed under
7  * the terms of the GNU General Public License version 2. This program
8  * is licensed "as is" without any warranty of any kind, whether express
9  * or implied.
10  */
11 #include <linux/module.h>
12 #include <linux/io.h>
13 
14 #include <asm/tlb.h>
15 #include <asm/mach/map.h>
16 
17 #include <mach/common.h>
18 #include <mach/cputype.h>
19 
20 struct davinci_soc_info davinci_soc_info;
21 EXPORT_SYMBOL(davinci_soc_info);
22 
23 static struct davinci_id * __init davinci_get_id(u32 jtag_id)
24 {
25 	int i;
26 	struct davinci_id *dip;
27 	u8 variant = (jtag_id & 0xf0000000) >> 28;
28 	u16 part_no = (jtag_id & 0x0ffff000) >> 12;
29 
30 	for (i = 0, dip = davinci_soc_info.ids; i < davinci_soc_info.ids_num;
31 			i++, dip++)
32 		/* Don't care about the manufacturer right now */
33 		if ((dip->part_no == part_no) && (dip->variant == variant))
34 			return dip;
35 
36 	return NULL;
37 }
38 
39 void __init davinci_common_init(struct davinci_soc_info *soc_info)
40 {
41 	int ret;
42 	struct davinci_id *dip;
43 
44 	if (!soc_info) {
45 		ret = -EINVAL;
46 		goto err;
47 	}
48 
49 	memcpy(&davinci_soc_info, soc_info, sizeof(struct davinci_soc_info));
50 
51 	if (davinci_soc_info.io_desc && (davinci_soc_info.io_desc_num > 0))
52 		iotable_init(davinci_soc_info.io_desc,
53 				davinci_soc_info.io_desc_num);
54 
55 	/*
56 	 * Normally devicemaps_init() would flush caches and tlb after
57 	 * mdesc->map_io(), but we must also do it here because of the CPU
58 	 * revision check below.
59 	 */
60 	local_flush_tlb_all();
61 	flush_cache_all();
62 
63 	/*
64 	 * We want to check CPU revision early for cpu_is_xxxx() macros.
65 	 * IO space mapping must be initialized before we can do that.
66 	 */
67 	davinci_soc_info.jtag_id = __raw_readl(davinci_soc_info.jtag_id_base);
68 
69 	dip = davinci_get_id(davinci_soc_info.jtag_id);
70 	if (!dip) {
71 		ret = -EINVAL;
72 		goto err;
73 	}
74 
75 	davinci_soc_info.cpu_id = dip->cpu_id;
76 	pr_info("DaVinci %s variant 0x%x\n", dip->name, dip->variant);
77 
78 	return;
79 
80 err:
81 	pr_err("davinci_common_init: SoC Initialization failed\n");
82 }
83