common.c 2.9 KB

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