blob: f8221c5ee380b9eb66c6ce590094b2063aab1314 [file] [log] [blame]
Mark A. Greer79c3c0b2009-04-15 12:38:58 -07001/*
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>
Mark A. Greerb14dc0f2009-04-15 12:41:27 -070013#include <linux/etherdevice.h>
Sriramakrishnan8ee2bf92009-11-19 15:58:25 +053014#include <linux/davinci_emac.h>
Mark A. Greer79c3c0b2009-04-15 12:38:58 -070015
16#include <asm/tlb.h>
17#include <asm/mach/map.h>
18
19#include <mach/common.h>
Mark A. Greerb9ab1272009-04-15 12:39:09 -070020#include <mach/cputype.h>
Mark A. Greer79c3c0b2009-04-15 12:38:58 -070021
Mark A. Greer66e0c392009-04-15 12:39:23 -070022#include "clock.h"
23
Mark A. Greer79c3c0b2009-04-15 12:38:58 -070024struct davinci_soc_info davinci_soc_info;
25EXPORT_SYMBOL(davinci_soc_info);
26
Mark A. Greer673dd362009-04-15 12:40:00 -070027void __iomem *davinci_intc_base;
Mark A. Greer0b0c4c22009-04-15 12:41:40 -070028int davinci_intc_type;
Mark A. Greer673dd362009-04-15 12:40:00 -070029
Mark A. Greerb14dc0f2009-04-15 12:41:27 -070030void davinci_get_mac_addr(struct memory_accessor *mem_acc, void *context)
31{
32 char *mac_addr = davinci_soc_info.emac_pdata->mac_addr;
33 off_t offset = (off_t)context;
34
35 /* Read MAC addr from EEPROM */
36 if (mem_acc->read(mem_acc, mac_addr, offset, ETH_ALEN) == ETH_ALEN)
37 pr_info("Read MAC addr from EEPROM: %pM\n", mac_addr);
38}
39
Mark A. Greerb9ab1272009-04-15 12:39:09 -070040static struct davinci_id * __init davinci_get_id(u32 jtag_id)
41{
42 int i;
43 struct davinci_id *dip;
44 u8 variant = (jtag_id & 0xf0000000) >> 28;
45 u16 part_no = (jtag_id & 0x0ffff000) >> 12;
46
47 for (i = 0, dip = davinci_soc_info.ids; i < davinci_soc_info.ids_num;
48 i++, dip++)
49 /* Don't care about the manufacturer right now */
50 if ((dip->part_no == part_no) && (dip->variant == variant))
51 return dip;
52
53 return NULL;
54}
55
Mark A. Greer79c3c0b2009-04-15 12:38:58 -070056void __init davinci_common_init(struct davinci_soc_info *soc_info)
57{
58 int ret;
Mark A. Greerb9ab1272009-04-15 12:39:09 -070059 struct davinci_id *dip;
Mark A. Greer79c3c0b2009-04-15 12:38:58 -070060
61 if (!soc_info) {
62 ret = -EINVAL;
63 goto err;
64 }
65
66 memcpy(&davinci_soc_info, soc_info, sizeof(struct davinci_soc_info));
67
68 if (davinci_soc_info.io_desc && (davinci_soc_info.io_desc_num > 0))
69 iotable_init(davinci_soc_info.io_desc,
70 davinci_soc_info.io_desc_num);
71
72 /*
73 * Normally devicemaps_init() would flush caches and tlb after
74 * mdesc->map_io(), but we must also do it here because of the CPU
75 * revision check below.
76 */
77 local_flush_tlb_all();
78 flush_cache_all();
79
Cyril Chemparathyc78a5bc2010-05-01 18:38:28 -040080 if (!davinci_soc_info.reset)
81 davinci_soc_info.reset = davinci_watchdog_reset;
82
Mark A. Greer79c3c0b2009-04-15 12:38:58 -070083 /*
84 * We want to check CPU revision early for cpu_is_xxxx() macros.
85 * IO space mapping must be initialized before we can do that.
86 */
Mark A. Greerb9ab1272009-04-15 12:39:09 -070087 davinci_soc_info.jtag_id = __raw_readl(davinci_soc_info.jtag_id_base);
88
89 dip = davinci_get_id(davinci_soc_info.jtag_id);
90 if (!dip) {
91 ret = -EINVAL;
Sekhar Nori69872e92009-10-01 12:41:06 +053092 pr_err("Unknown DaVinci JTAG ID 0x%x\n",
93 davinci_soc_info.jtag_id);
Mark A. Greerb9ab1272009-04-15 12:39:09 -070094 goto err;
95 }
96
97 davinci_soc_info.cpu_id = dip->cpu_id;
98 pr_info("DaVinci %s variant 0x%x\n", dip->name, dip->variant);
Mark A. Greer79c3c0b2009-04-15 12:38:58 -070099
Mark A. Greer66e0c392009-04-15 12:39:23 -0700100 if (davinci_soc_info.cpu_clks) {
101 ret = davinci_clk_init(davinci_soc_info.cpu_clks);
102
103 if (ret != 0)
104 goto err;
105 }
106
Mark A. Greer673dd362009-04-15 12:40:00 -0700107 davinci_intc_base = davinci_soc_info.intc_base;
Mark A. Greer0b0c4c22009-04-15 12:41:40 -0700108 davinci_intc_type = davinci_soc_info.intc_type;
Mark A. Greer79c3c0b2009-04-15 12:38:58 -0700109 return;
110
111err:
Sekhar Nori69872e92009-10-01 12:41:06 +0530112 panic("davinci_common_init: SoC Initialization failed\n");
Mark A. Greer79c3c0b2009-04-15 12:38:58 -0700113}