setup-rcar-gen2.c 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /*
  2. * R-Car Generation 2 support
  3. *
  4. * Copyright (C) 2013 Renesas Solutions Corp.
  5. * Copyright (C) 2013 Magnus Damm
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; version 2 of the License.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  19. */
  20. #include <linux/clocksource.h>
  21. #include <linux/io.h>
  22. #include <linux/kernel.h>
  23. #include <mach/common.h>
  24. #include <mach/rcar-gen2.h>
  25. #include <asm/mach/arch.h>
  26. #define MODEMR 0xe6160060
  27. u32 __init rcar_gen2_read_mode_pins(void)
  28. {
  29. void __iomem *modemr = ioremap_nocache(MODEMR, 4);
  30. u32 mode;
  31. BUG_ON(!modemr);
  32. mode = ioread32(modemr);
  33. iounmap(modemr);
  34. return mode;
  35. }
  36. #define CNTCR 0
  37. #define CNTFID0 0x20
  38. void __init rcar_gen2_timer_init(void)
  39. {
  40. #ifdef CONFIG_ARM_ARCH_TIMER
  41. u32 mode = rcar_gen2_read_mode_pins();
  42. void __iomem *base;
  43. int extal_mhz = 0;
  44. u32 freq;
  45. /* At Linux boot time the r8a7790 arch timer comes up
  46. * with the counter disabled. Moreover, it may also report
  47. * a potentially incorrect fixed 13 MHz frequency. To be
  48. * correct these registers need to be updated to use the
  49. * frequency EXTAL / 2 which can be determined by the MD pins.
  50. */
  51. switch (mode & (MD(14) | MD(13))) {
  52. case 0:
  53. extal_mhz = 15;
  54. break;
  55. case MD(13):
  56. extal_mhz = 20;
  57. break;
  58. case MD(14):
  59. extal_mhz = 26;
  60. break;
  61. case MD(13) | MD(14):
  62. extal_mhz = 30;
  63. break;
  64. }
  65. /* The arch timer frequency equals EXTAL / 2 */
  66. freq = extal_mhz * (1000000 / 2);
  67. /* Remap "armgcnt address map" space */
  68. base = ioremap(0xe6080000, PAGE_SIZE);
  69. /* Update registers with correct frequency */
  70. iowrite32(freq, base + CNTFID0);
  71. asm volatile("mcr p15, 0, %0, c14, c0, 0" : : "r" (freq));
  72. /* make sure arch timer is started by setting bit 0 of CNTCR */
  73. iowrite32(1, base + CNTCR);
  74. iounmap(base);
  75. #endif /* CONFIG_ARM_ARCH_TIMER */
  76. clocksource_of_init();
  77. }