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