common.c 2.8 KB

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