xref: /openbmc/linux/arch/arm/mach-davinci/common.c (revision 96de2506)
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 void davinci_get_mac_addr(struct nvmem_device *nvmem, void *context)
30 {
31 	char *mac_addr = davinci_soc_info.emac_pdata->mac_addr;
32 	off_t offset = (off_t)context;
33 
34 	if (!IS_BUILTIN(CONFIG_NVMEM)) {
35 		pr_warn("Cannot read MAC addr from EEPROM without CONFIG_NVMEM\n");
36 		return;
37 	}
38 
39 	/* Read MAC addr from EEPROM */
40 	if (nvmem_device_read(nvmem, offset, ETH_ALEN, mac_addr) == ETH_ALEN)
41 		pr_info("Read MAC addr from EEPROM: %pM\n", mac_addr);
42 }
43 
44 static int __init davinci_init_id(struct davinci_soc_info *soc_info)
45 {
46 	int			i;
47 	struct davinci_id	*dip;
48 	u8			variant;
49 	u16			part_no;
50 	void __iomem		*base;
51 
52 	base = ioremap(soc_info->jtag_id_reg, SZ_4K);
53 	if (!base) {
54 		pr_err("Unable to map JTAG ID register\n");
55 		return -ENOMEM;
56 	}
57 
58 	soc_info->jtag_id = __raw_readl(base);
59 	iounmap(base);
60 
61 	variant = (soc_info->jtag_id & 0xf0000000) >> 28;
62 	part_no = (soc_info->jtag_id & 0x0ffff000) >> 12;
63 
64 	for (i = 0, dip = soc_info->ids; i < soc_info->ids_num;
65 			i++, dip++)
66 		/* Don't care about the manufacturer right now */
67 		if ((dip->part_no == part_no) && (dip->variant == variant)) {
68 			soc_info->cpu_id = dip->cpu_id;
69 			pr_info("DaVinci %s variant 0x%x\n", dip->name,
70 					dip->variant);
71 			return 0;
72 		}
73 
74 	pr_err("Unknown DaVinci JTAG ID 0x%x\n", soc_info->jtag_id);
75 	return -EINVAL;
76 }
77 
78 void __init davinci_common_init(const struct davinci_soc_info *soc_info)
79 {
80 	int ret;
81 
82 	if (!soc_info) {
83 		ret = -EINVAL;
84 		goto err;
85 	}
86 
87 	memcpy(&davinci_soc_info, soc_info, sizeof(struct davinci_soc_info));
88 
89 	if (davinci_soc_info.io_desc && (davinci_soc_info.io_desc_num > 0))
90 		iotable_init(davinci_soc_info.io_desc,
91 				davinci_soc_info.io_desc_num);
92 
93 	/*
94 	 * Normally devicemaps_init() would flush caches and tlb after
95 	 * mdesc->map_io(), but we must also do it here because of the CPU
96 	 * revision check below.
97 	 */
98 	local_flush_tlb_all();
99 	flush_cache_all();
100 
101 	/*
102 	 * We want to check CPU revision early for cpu_is_xxxx() macros.
103 	 * IO space mapping must be initialized before we can do that.
104 	 */
105 	ret = davinci_init_id(&davinci_soc_info);
106 	if (ret < 0)
107 		goto err;
108 
109 
110 	return;
111 
112 err:
113 	panic("davinci_common_init: SoC Initialization failed\n");
114 }
115 
116 void __init davinci_init_late(void)
117 {
118 	davinci_cpufreq_init();
119 }
120