common.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. /*
  2. * arch/arm/mach-lpc32xx/common.c
  3. *
  4. * Author: Kevin Wells <kevin.wells@nxp.com>
  5. *
  6. * Copyright (C) 2010 NXP Semiconductors
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. */
  18. #include <linux/init.h>
  19. #include <asm/mach/map.h>
  20. #include <asm/system_info.h>
  21. #include <mach/hardware.h>
  22. #include <mach/platform.h>
  23. #include "common.h"
  24. /*
  25. * Returns the unique ID for the device
  26. */
  27. void lpc32xx_get_uid(u32 devid[4])
  28. {
  29. int i;
  30. for (i = 0; i < 4; i++)
  31. devid[i] = __raw_readl(LPC32XX_CLKPWR_DEVID(i << 2));
  32. }
  33. /*
  34. * Detects and returns IRAM size for the device variation
  35. */
  36. #define LPC32XX_IRAM_BANK_SIZE SZ_128K
  37. static u32 iram_size;
  38. u32 lpc32xx_return_iram_size(void)
  39. {
  40. if (iram_size == 0) {
  41. u32 savedval1, savedval2;
  42. void __iomem *iramptr1, *iramptr2;
  43. iramptr1 = io_p2v(LPC32XX_IRAM_BASE);
  44. iramptr2 = io_p2v(LPC32XX_IRAM_BASE + LPC32XX_IRAM_BANK_SIZE);
  45. savedval1 = __raw_readl(iramptr1);
  46. savedval2 = __raw_readl(iramptr2);
  47. if (savedval1 == savedval2) {
  48. __raw_writel(savedval2 + 1, iramptr2);
  49. if (__raw_readl(iramptr1) == savedval2 + 1)
  50. iram_size = LPC32XX_IRAM_BANK_SIZE;
  51. else
  52. iram_size = LPC32XX_IRAM_BANK_SIZE * 2;
  53. __raw_writel(savedval2, iramptr2);
  54. } else
  55. iram_size = LPC32XX_IRAM_BANK_SIZE * 2;
  56. }
  57. return iram_size;
  58. }
  59. EXPORT_SYMBOL_GPL(lpc32xx_return_iram_size);
  60. static struct map_desc lpc32xx_io_desc[] __initdata = {
  61. {
  62. .virtual = (unsigned long)IO_ADDRESS(LPC32XX_AHB0_START),
  63. .pfn = __phys_to_pfn(LPC32XX_AHB0_START),
  64. .length = LPC32XX_AHB0_SIZE,
  65. .type = MT_DEVICE
  66. },
  67. {
  68. .virtual = (unsigned long)IO_ADDRESS(LPC32XX_AHB1_START),
  69. .pfn = __phys_to_pfn(LPC32XX_AHB1_START),
  70. .length = LPC32XX_AHB1_SIZE,
  71. .type = MT_DEVICE
  72. },
  73. {
  74. .virtual = (unsigned long)IO_ADDRESS(LPC32XX_FABAPB_START),
  75. .pfn = __phys_to_pfn(LPC32XX_FABAPB_START),
  76. .length = LPC32XX_FABAPB_SIZE,
  77. .type = MT_DEVICE
  78. },
  79. {
  80. .virtual = (unsigned long)IO_ADDRESS(LPC32XX_IRAM_BASE),
  81. .pfn = __phys_to_pfn(LPC32XX_IRAM_BASE),
  82. .length = (LPC32XX_IRAM_BANK_SIZE * 2),
  83. .type = MT_DEVICE
  84. },
  85. };
  86. void __init lpc32xx_map_io(void)
  87. {
  88. iotable_init(lpc32xx_io_desc, ARRAY_SIZE(lpc32xx_io_desc));
  89. }
  90. static int __init lpc32xx_check_uid(void)
  91. {
  92. u32 uid[4];
  93. lpc32xx_get_uid(uid);
  94. printk(KERN_INFO "LPC32XX unique ID: %08x%08x%08x%08x\n",
  95. uid[3], uid[2], uid[1], uid[0]);
  96. if (!system_serial_low && !system_serial_high) {
  97. system_serial_low = uid[0];
  98. system_serial_high = uid[1];
  99. }
  100. return 1;
  101. }
  102. arch_initcall(lpc32xx_check_uid);