Commit | Line | Data |
---|---|---|
79c3c0b7 MG |
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> | |
b14dc0f9 | 13 | #include <linux/etherdevice.h> |
79c3c0b7 MG |
14 | |
15 | #include <asm/tlb.h> | |
16 | #include <asm/mach/map.h> | |
17 | ||
18 | #include <mach/common.h> | |
b9ab1279 | 19 | #include <mach/cputype.h> |
b14dc0f9 | 20 | #include <mach/emac.h> |
79c3c0b7 | 21 | |
66e0c399 MG |
22 | #include "clock.h" |
23 | ||
79c3c0b7 MG |
24 | struct davinci_soc_info davinci_soc_info; |
25 | EXPORT_SYMBOL(davinci_soc_info); | |
26 | ||
673dd36f MG |
27 | void __iomem *davinci_intc_base; |
28 | ||
b14dc0f9 MG |
29 | void davinci_get_mac_addr(struct memory_accessor *mem_acc, void *context) |
30 | { | |
31 | char *mac_addr = davinci_soc_info.emac_pdata->mac_addr; | |
32 | off_t offset = (off_t)context; | |
33 | ||
34 | /* Read MAC addr from EEPROM */ | |
35 | if (mem_acc->read(mem_acc, mac_addr, offset, ETH_ALEN) == ETH_ALEN) | |
36 | pr_info("Read MAC addr from EEPROM: %pM\n", mac_addr); | |
37 | } | |
38 | ||
b9ab1279 MG |
39 | static struct davinci_id * __init davinci_get_id(u32 jtag_id) |
40 | { | |
41 | int i; | |
42 | struct davinci_id *dip; | |
43 | u8 variant = (jtag_id & 0xf0000000) >> 28; | |
44 | u16 part_no = (jtag_id & 0x0ffff000) >> 12; | |
45 | ||
46 | for (i = 0, dip = davinci_soc_info.ids; i < davinci_soc_info.ids_num; | |
47 | i++, dip++) | |
48 | /* Don't care about the manufacturer right now */ | |
49 | if ((dip->part_no == part_no) && (dip->variant == variant)) | |
50 | return dip; | |
51 | ||
52 | return NULL; | |
53 | } | |
54 | ||
79c3c0b7 MG |
55 | void __init davinci_common_init(struct davinci_soc_info *soc_info) |
56 | { | |
57 | int ret; | |
b9ab1279 | 58 | struct davinci_id *dip; |
79c3c0b7 MG |
59 | |
60 | if (!soc_info) { | |
61 | ret = -EINVAL; | |
62 | goto err; | |
63 | } | |
64 | ||
65 | memcpy(&davinci_soc_info, soc_info, sizeof(struct davinci_soc_info)); | |
66 | ||
67 | if (davinci_soc_info.io_desc && (davinci_soc_info.io_desc_num > 0)) | |
68 | iotable_init(davinci_soc_info.io_desc, | |
69 | davinci_soc_info.io_desc_num); | |
70 | ||
71 | /* | |
72 | * Normally devicemaps_init() would flush caches and tlb after | |
73 | * mdesc->map_io(), but we must also do it here because of the CPU | |
74 | * revision check below. | |
75 | */ | |
76 | local_flush_tlb_all(); | |
77 | flush_cache_all(); | |
78 | ||
79 | /* | |
80 | * We want to check CPU revision early for cpu_is_xxxx() macros. | |
81 | * IO space mapping must be initialized before we can do that. | |
82 | */ | |
b9ab1279 MG |
83 | davinci_soc_info.jtag_id = __raw_readl(davinci_soc_info.jtag_id_base); |
84 | ||
85 | dip = davinci_get_id(davinci_soc_info.jtag_id); | |
86 | if (!dip) { | |
87 | ret = -EINVAL; | |
88 | goto err; | |
89 | } | |
90 | ||
91 | davinci_soc_info.cpu_id = dip->cpu_id; | |
92 | pr_info("DaVinci %s variant 0x%x\n", dip->name, dip->variant); | |
79c3c0b7 | 93 | |
66e0c399 MG |
94 | if (davinci_soc_info.cpu_clks) { |
95 | ret = davinci_clk_init(davinci_soc_info.cpu_clks); | |
96 | ||
97 | if (ret != 0) | |
98 | goto err; | |
99 | } | |
100 | ||
673dd36f | 101 | davinci_intc_base = davinci_soc_info.intc_base; |
79c3c0b7 MG |
102 | return; |
103 | ||
104 | err: | |
105 | pr_err("davinci_common_init: SoC Initialization failed\n"); | |
106 | } |