Mark A. Greer | 79c3c0b | 2009-04-15 12:38:58 -0700 | [diff] [blame] | 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> |
Mark A. Greer | b14dc0f | 2009-04-15 12:41:27 -0700 | [diff] [blame] | 13 | #include <linux/etherdevice.h> |
Sriramakrishnan | 8ee2bf9 | 2009-11-19 15:58:25 +0530 | [diff] [blame] | 14 | #include <linux/davinci_emac.h> |
Jon Medhurst | fd24f90 | 2011-08-04 14:51:45 +0100 | [diff] [blame] | 15 | #include <linux/dma-mapping.h> |
Mark A. Greer | 79c3c0b | 2009-04-15 12:38:58 -0700 | [diff] [blame] | 16 | |
| 17 | #include <asm/tlb.h> |
| 18 | #include <asm/mach/map.h> |
| 19 | |
| 20 | #include <mach/common.h> |
Mark A. Greer | b9ab127 | 2009-04-15 12:39:09 -0700 | [diff] [blame] | 21 | #include <mach/cputype.h> |
Mark A. Greer | 79c3c0b | 2009-04-15 12:38:58 -0700 | [diff] [blame] | 22 | |
Mark A. Greer | 66e0c39 | 2009-04-15 12:39:23 -0700 | [diff] [blame] | 23 | #include "clock.h" |
| 24 | |
Mark A. Greer | 79c3c0b | 2009-04-15 12:38:58 -0700 | [diff] [blame] | 25 | struct davinci_soc_info davinci_soc_info; |
| 26 | EXPORT_SYMBOL(davinci_soc_info); |
| 27 | |
Mark A. Greer | 673dd36 | 2009-04-15 12:40:00 -0700 | [diff] [blame] | 28 | void __iomem *davinci_intc_base; |
Mark A. Greer | 0b0c4c2 | 2009-04-15 12:41:40 -0700 | [diff] [blame] | 29 | int davinci_intc_type; |
Mark A. Greer | 673dd36 | 2009-04-15 12:40:00 -0700 | [diff] [blame] | 30 | |
Andrew Lunn | bec3c11 | 2016-02-26 20:59:24 +0100 | [diff] [blame] | 31 | void davinci_get_mac_addr(struct nvmem_device *nvmem, void *context) |
Mark A. Greer | b14dc0f | 2009-04-15 12:41:27 -0700 | [diff] [blame] | 32 | { |
| 33 | char *mac_addr = davinci_soc_info.emac_pdata->mac_addr; |
| 34 | off_t offset = (off_t)context; |
| 35 | |
Arnd Bergmann | 04b9665 | 2016-03-15 22:34:45 +0100 | [diff] [blame] | 36 | if (!IS_BUILTIN(CONFIG_NVMEM)) { |
| 37 | pr_warn("Cannot read MAC addr from EEPROM without CONFIG_NVMEM\n"); |
| 38 | return; |
| 39 | } |
| 40 | |
Mark A. Greer | b14dc0f | 2009-04-15 12:41:27 -0700 | [diff] [blame] | 41 | /* Read MAC addr from EEPROM */ |
Andrew Lunn | bec3c11 | 2016-02-26 20:59:24 +0100 | [diff] [blame] | 42 | if (nvmem_device_read(nvmem, offset, ETH_ALEN, mac_addr) == ETH_ALEN) |
Mark A. Greer | b14dc0f | 2009-04-15 12:41:27 -0700 | [diff] [blame] | 43 | pr_info("Read MAC addr from EEPROM: %pM\n", mac_addr); |
| 44 | } |
| 45 | |
Cyril Chemparathy | 3347db8 | 2010-05-07 17:06:34 -0400 | [diff] [blame] | 46 | static int __init davinci_init_id(struct davinci_soc_info *soc_info) |
Mark A. Greer | b9ab127 | 2009-04-15 12:39:09 -0700 | [diff] [blame] | 47 | { |
Cyril Chemparathy | 3347db8 | 2010-05-07 17:06:34 -0400 | [diff] [blame] | 48 | int i; |
| 49 | struct davinci_id *dip; |
| 50 | u8 variant; |
| 51 | u16 part_no; |
| 52 | void __iomem *base; |
Mark A. Greer | b9ab127 | 2009-04-15 12:39:09 -0700 | [diff] [blame] | 53 | |
Cyril Chemparathy | 3347db8 | 2010-05-07 17:06:34 -0400 | [diff] [blame] | 54 | base = ioremap(soc_info->jtag_id_reg, SZ_4K); |
| 55 | if (!base) { |
| 56 | pr_err("Unable to map JTAG ID register\n"); |
| 57 | return -ENOMEM; |
| 58 | } |
| 59 | |
| 60 | soc_info->jtag_id = __raw_readl(base); |
| 61 | iounmap(base); |
| 62 | |
| 63 | variant = (soc_info->jtag_id & 0xf0000000) >> 28; |
| 64 | part_no = (soc_info->jtag_id & 0x0ffff000) >> 12; |
| 65 | |
| 66 | for (i = 0, dip = soc_info->ids; i < soc_info->ids_num; |
Mark A. Greer | b9ab127 | 2009-04-15 12:39:09 -0700 | [diff] [blame] | 67 | i++, dip++) |
| 68 | /* Don't care about the manufacturer right now */ |
Cyril Chemparathy | 3347db8 | 2010-05-07 17:06:34 -0400 | [diff] [blame] | 69 | if ((dip->part_no == part_no) && (dip->variant == variant)) { |
| 70 | soc_info->cpu_id = dip->cpu_id; |
| 71 | pr_info("DaVinci %s variant 0x%x\n", dip->name, |
| 72 | dip->variant); |
| 73 | return 0; |
| 74 | } |
Mark A. Greer | b9ab127 | 2009-04-15 12:39:09 -0700 | [diff] [blame] | 75 | |
Cyril Chemparathy | 3347db8 | 2010-05-07 17:06:34 -0400 | [diff] [blame] | 76 | pr_err("Unknown DaVinci JTAG ID 0x%x\n", soc_info->jtag_id); |
| 77 | return -EINVAL; |
Mark A. Greer | b9ab127 | 2009-04-15 12:39:09 -0700 | [diff] [blame] | 78 | } |
| 79 | |
Bhumika Goyal | 1a6d490b | 2017-10-16 12:08:23 +0200 | [diff] [blame] | 80 | void __init davinci_common_init(const struct davinci_soc_info *soc_info) |
Mark A. Greer | 79c3c0b | 2009-04-15 12:38:58 -0700 | [diff] [blame] | 81 | { |
| 82 | int ret; |
| 83 | |
| 84 | if (!soc_info) { |
| 85 | ret = -EINVAL; |
| 86 | goto err; |
| 87 | } |
| 88 | |
| 89 | memcpy(&davinci_soc_info, soc_info, sizeof(struct davinci_soc_info)); |
| 90 | |
| 91 | if (davinci_soc_info.io_desc && (davinci_soc_info.io_desc_num > 0)) |
| 92 | iotable_init(davinci_soc_info.io_desc, |
| 93 | davinci_soc_info.io_desc_num); |
| 94 | |
| 95 | /* |
| 96 | * Normally devicemaps_init() would flush caches and tlb after |
| 97 | * mdesc->map_io(), but we must also do it here because of the CPU |
| 98 | * revision check below. |
| 99 | */ |
| 100 | local_flush_tlb_all(); |
| 101 | flush_cache_all(); |
| 102 | |
| 103 | /* |
| 104 | * We want to check CPU revision early for cpu_is_xxxx() macros. |
| 105 | * IO space mapping must be initialized before we can do that. |
| 106 | */ |
Cyril Chemparathy | 3347db8 | 2010-05-07 17:06:34 -0400 | [diff] [blame] | 107 | ret = davinci_init_id(&davinci_soc_info); |
| 108 | if (ret < 0) |
Mark A. Greer | b9ab127 | 2009-04-15 12:39:09 -0700 | [diff] [blame] | 109 | goto err; |
Mark A. Greer | 79c3c0b | 2009-04-15 12:38:58 -0700 | [diff] [blame] | 110 | |
Mark A. Greer | 66e0c39 | 2009-04-15 12:39:23 -0700 | [diff] [blame] | 111 | |
Mark A. Greer | 79c3c0b | 2009-04-15 12:38:58 -0700 | [diff] [blame] | 112 | return; |
| 113 | |
| 114 | err: |
Sekhar Nori | 69872e9 | 2009-10-01 12:41:06 +0530 | [diff] [blame] | 115 | panic("davinci_common_init: SoC Initialization failed\n"); |
Mark A. Greer | 79c3c0b | 2009-04-15 12:38:58 -0700 | [diff] [blame] | 116 | } |
Shawn Guo | 3aa3e84 | 2012-04-26 09:45:39 +0800 | [diff] [blame] | 117 | |
| 118 | void __init davinci_init_late(void) |
| 119 | { |
| 120 | davinci_cpufreq_init(); |
Shawn Guo | 3aa3e84 | 2012-04-26 09:45:39 +0800 | [diff] [blame] | 121 | davinci_clk_disable_unused(); |
| 122 | } |