blob: 64b0f65a8639aa919173b597c8134e55192972b6 [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>
Jon Medhurstfd24f902011-08-04 14:51:45 +010015#include <linux/dma-mapping.h>
Mark A. Greer79c3c0b2009-04-15 12:38:58 -070016
17#include <asm/tlb.h>
18#include <asm/mach/map.h>
19
20#include <mach/common.h>
Mark A. Greerb9ab1272009-04-15 12:39:09 -070021#include <mach/cputype.h>
Mark A. Greer79c3c0b2009-04-15 12:38:58 -070022
Mark A. Greer66e0c392009-04-15 12:39:23 -070023#include "clock.h"
24
Mark A. Greer79c3c0b2009-04-15 12:38:58 -070025struct davinci_soc_info davinci_soc_info;
26EXPORT_SYMBOL(davinci_soc_info);
27
Mark A. Greer673dd362009-04-15 12:40:00 -070028void __iomem *davinci_intc_base;
Mark A. Greer0b0c4c22009-04-15 12:41:40 -070029int davinci_intc_type;
Mark A. Greer673dd362009-04-15 12:40:00 -070030
Mark A. Greerb14dc0f2009-04-15 12:41:27 -070031void davinci_get_mac_addr(struct memory_accessor *mem_acc, void *context)
32{
33 char *mac_addr = davinci_soc_info.emac_pdata->mac_addr;
34 off_t offset = (off_t)context;
35
36 /* Read MAC addr from EEPROM */
37 if (mem_acc->read(mem_acc, mac_addr, offset, ETH_ALEN) == ETH_ALEN)
38 pr_info("Read MAC addr from EEPROM: %pM\n", mac_addr);
39}
40
Cyril Chemparathy3347db82010-05-07 17:06:34 -040041static int __init davinci_init_id(struct davinci_soc_info *soc_info)
Mark A. Greerb9ab1272009-04-15 12:39:09 -070042{
Cyril Chemparathy3347db82010-05-07 17:06:34 -040043 int i;
44 struct davinci_id *dip;
45 u8 variant;
46 u16 part_no;
47 void __iomem *base;
Mark A. Greerb9ab1272009-04-15 12:39:09 -070048
Cyril Chemparathy3347db82010-05-07 17:06:34 -040049 base = ioremap(soc_info->jtag_id_reg, SZ_4K);
50 if (!base) {
51 pr_err("Unable to map JTAG ID register\n");
52 return -ENOMEM;
53 }
54
55 soc_info->jtag_id = __raw_readl(base);
56 iounmap(base);
57
58 variant = (soc_info->jtag_id & 0xf0000000) >> 28;
59 part_no = (soc_info->jtag_id & 0x0ffff000) >> 12;
60
61 for (i = 0, dip = soc_info->ids; i < soc_info->ids_num;
Mark A. Greerb9ab1272009-04-15 12:39:09 -070062 i++, dip++)
63 /* Don't care about the manufacturer right now */
Cyril Chemparathy3347db82010-05-07 17:06:34 -040064 if ((dip->part_no == part_no) && (dip->variant == variant)) {
65 soc_info->cpu_id = dip->cpu_id;
66 pr_info("DaVinci %s variant 0x%x\n", dip->name,
67 dip->variant);
68 return 0;
69 }
Mark A. Greerb9ab1272009-04-15 12:39:09 -070070
Cyril Chemparathy3347db82010-05-07 17:06:34 -040071 pr_err("Unknown DaVinci JTAG ID 0x%x\n", soc_info->jtag_id);
72 return -EINVAL;
Mark A. Greerb9ab1272009-04-15 12:39:09 -070073}
74
Mark A. Greer79c3c0b2009-04-15 12:38:58 -070075void __init davinci_common_init(struct davinci_soc_info *soc_info)
76{
77 int ret;
78
79 if (!soc_info) {
80 ret = -EINVAL;
81 goto err;
82 }
83
84 memcpy(&davinci_soc_info, soc_info, sizeof(struct davinci_soc_info));
85
86 if (davinci_soc_info.io_desc && (davinci_soc_info.io_desc_num > 0))
87 iotable_init(davinci_soc_info.io_desc,
88 davinci_soc_info.io_desc_num);
89
Jon Medhurstfd24f902011-08-04 14:51:45 +010090 init_consistent_dma_size(14 << 20);
91
Mark A. Greer79c3c0b2009-04-15 12:38:58 -070092 /*
93 * Normally devicemaps_init() would flush caches and tlb after
94 * mdesc->map_io(), but we must also do it here because of the CPU
95 * revision check below.
96 */
97 local_flush_tlb_all();
98 flush_cache_all();
99
100 /*
101 * We want to check CPU revision early for cpu_is_xxxx() macros.
102 * IO space mapping must be initialized before we can do that.
103 */
Cyril Chemparathy3347db82010-05-07 17:06:34 -0400104 ret = davinci_init_id(&davinci_soc_info);
105 if (ret < 0)
Mark A. Greerb9ab1272009-04-15 12:39:09 -0700106 goto err;
Mark A. Greer79c3c0b2009-04-15 12:38:58 -0700107
Mark A. Greer66e0c392009-04-15 12:39:23 -0700108 if (davinci_soc_info.cpu_clks) {
109 ret = davinci_clk_init(davinci_soc_info.cpu_clks);
110
111 if (ret != 0)
112 goto err;
113 }
114
Mark A. Greer79c3c0b2009-04-15 12:38:58 -0700115 return;
116
117err:
Sekhar Nori69872e92009-10-01 12:41:06 +0530118 panic("davinci_common_init: SoC Initialization failed\n");
Mark A. Greer79c3c0b2009-04-15 12:38:58 -0700119}
Shawn Guo3aa3e842012-04-26 09:45:39 +0800120
121void __init davinci_init_late(void)
122{
123 davinci_cpufreq_init();
124 davinci_pm_init();
125 davinci_clk_disable_unused();
126}