common.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. /*
  2. * Atheros AR71XX/AR724X/AR913X common routines
  3. *
  4. * Copyright (C) 2010-2011 Jaiganesh Narayanan <jnarayanan@atheros.com>
  5. * Copyright (C) 2008-2011 Gabor Juhos <juhosg@openwrt.org>
  6. * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
  7. *
  8. * Parts of this file are based on Atheros' 2.6.15/2.6.31 BSP
  9. *
  10. * This program is free software; you can redistribute it and/or modify it
  11. * under the terms of the GNU General Public License version 2 as published
  12. * by the Free Software Foundation.
  13. */
  14. #include <linux/kernel.h>
  15. #include <linux/module.h>
  16. #include <linux/types.h>
  17. #include <linux/spinlock.h>
  18. #include <asm/mach-ath79/ath79.h>
  19. #include <asm/mach-ath79/ar71xx_regs.h>
  20. #include "common.h"
  21. static DEFINE_SPINLOCK(ath79_device_reset_lock);
  22. u32 ath79_cpu_freq;
  23. EXPORT_SYMBOL_GPL(ath79_cpu_freq);
  24. u32 ath79_ahb_freq;
  25. EXPORT_SYMBOL_GPL(ath79_ahb_freq);
  26. u32 ath79_ddr_freq;
  27. EXPORT_SYMBOL_GPL(ath79_ddr_freq);
  28. enum ath79_soc_type ath79_soc;
  29. unsigned int ath79_soc_rev;
  30. void __iomem *ath79_pll_base;
  31. void __iomem *ath79_reset_base;
  32. EXPORT_SYMBOL_GPL(ath79_reset_base);
  33. static void __iomem *ath79_ddr_base;
  34. static void __iomem *ath79_ddr_wb_flush_base;
  35. static void __iomem *ath79_ddr_pci_win_base;
  36. void ath79_ddr_ctrl_init(void)
  37. {
  38. ath79_ddr_base = ioremap_nocache(AR71XX_DDR_CTRL_BASE,
  39. AR71XX_DDR_CTRL_SIZE);
  40. if (soc_is_ar71xx() || soc_is_ar934x()) {
  41. ath79_ddr_wb_flush_base = ath79_ddr_base + 0x9c;
  42. ath79_ddr_pci_win_base = ath79_ddr_base + 0x7c;
  43. } else {
  44. ath79_ddr_wb_flush_base = ath79_ddr_base + 0x7c;
  45. ath79_ddr_pci_win_base = 0;
  46. }
  47. }
  48. EXPORT_SYMBOL_GPL(ath79_ddr_ctrl_init);
  49. void ath79_ddr_wb_flush(u32 reg)
  50. {
  51. void __iomem *flush_reg = ath79_ddr_wb_flush_base + (reg * 4);
  52. /* Flush the DDR write buffer. */
  53. __raw_writel(0x1, flush_reg);
  54. while (__raw_readl(flush_reg) & 0x1)
  55. ;
  56. /* It must be run twice. */
  57. __raw_writel(0x1, flush_reg);
  58. while (__raw_readl(flush_reg) & 0x1)
  59. ;
  60. }
  61. EXPORT_SYMBOL_GPL(ath79_ddr_wb_flush);
  62. void ath79_ddr_set_pci_windows(void)
  63. {
  64. BUG_ON(!ath79_ddr_pci_win_base);
  65. __raw_writel(AR71XX_PCI_WIN0_OFFS, ath79_ddr_pci_win_base + 0x0);
  66. __raw_writel(AR71XX_PCI_WIN1_OFFS, ath79_ddr_pci_win_base + 0x4);
  67. __raw_writel(AR71XX_PCI_WIN2_OFFS, ath79_ddr_pci_win_base + 0x8);
  68. __raw_writel(AR71XX_PCI_WIN3_OFFS, ath79_ddr_pci_win_base + 0xc);
  69. __raw_writel(AR71XX_PCI_WIN4_OFFS, ath79_ddr_pci_win_base + 0x10);
  70. __raw_writel(AR71XX_PCI_WIN5_OFFS, ath79_ddr_pci_win_base + 0x14);
  71. __raw_writel(AR71XX_PCI_WIN6_OFFS, ath79_ddr_pci_win_base + 0x18);
  72. __raw_writel(AR71XX_PCI_WIN7_OFFS, ath79_ddr_pci_win_base + 0x1c);
  73. }
  74. EXPORT_SYMBOL_GPL(ath79_ddr_set_pci_windows);
  75. void ath79_device_reset_set(u32 mask)
  76. {
  77. unsigned long flags;
  78. u32 reg;
  79. u32 t;
  80. if (soc_is_ar71xx())
  81. reg = AR71XX_RESET_REG_RESET_MODULE;
  82. else if (soc_is_ar724x())
  83. reg = AR724X_RESET_REG_RESET_MODULE;
  84. else if (soc_is_ar913x())
  85. reg = AR913X_RESET_REG_RESET_MODULE;
  86. else if (soc_is_ar933x())
  87. reg = AR933X_RESET_REG_RESET_MODULE;
  88. else if (soc_is_ar934x())
  89. reg = AR934X_RESET_REG_RESET_MODULE;
  90. else if (soc_is_qca955x())
  91. reg = QCA955X_RESET_REG_RESET_MODULE;
  92. else
  93. BUG();
  94. spin_lock_irqsave(&ath79_device_reset_lock, flags);
  95. t = ath79_reset_rr(reg);
  96. ath79_reset_wr(reg, t | mask);
  97. spin_unlock_irqrestore(&ath79_device_reset_lock, flags);
  98. }
  99. EXPORT_SYMBOL_GPL(ath79_device_reset_set);
  100. void ath79_device_reset_clear(u32 mask)
  101. {
  102. unsigned long flags;
  103. u32 reg;
  104. u32 t;
  105. if (soc_is_ar71xx())
  106. reg = AR71XX_RESET_REG_RESET_MODULE;
  107. else if (soc_is_ar724x())
  108. reg = AR724X_RESET_REG_RESET_MODULE;
  109. else if (soc_is_ar913x())
  110. reg = AR913X_RESET_REG_RESET_MODULE;
  111. else if (soc_is_ar933x())
  112. reg = AR933X_RESET_REG_RESET_MODULE;
  113. else if (soc_is_ar934x())
  114. reg = AR934X_RESET_REG_RESET_MODULE;
  115. else if (soc_is_qca955x())
  116. reg = QCA955X_RESET_REG_RESET_MODULE;
  117. else
  118. BUG();
  119. spin_lock_irqsave(&ath79_device_reset_lock, flags);
  120. t = ath79_reset_rr(reg);
  121. ath79_reset_wr(reg, t & ~mask);
  122. spin_unlock_irqrestore(&ath79_device_reset_lock, flags);
  123. }
  124. EXPORT_SYMBOL_GPL(ath79_device_reset_clear);