common.c 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /*
  2. * Atheros AR71XX/AR724X/AR913X common routines
  3. *
  4. * Copyright (C) 2008-2010 Gabor Juhos <juhosg@openwrt.org>
  5. * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
  6. *
  7. * This program is free software; you can redistribute it and/or modify it
  8. * under the terms of the GNU General Public License version 2 as published
  9. * by the Free Software Foundation.
  10. */
  11. #include <linux/kernel.h>
  12. #include <linux/module.h>
  13. #include <linux/types.h>
  14. #include <linux/spinlock.h>
  15. #include <asm/mach-ath79/ath79.h>
  16. #include <asm/mach-ath79/ar71xx_regs.h>
  17. #include "common.h"
  18. static DEFINE_SPINLOCK(ath79_device_reset_lock);
  19. u32 ath79_cpu_freq;
  20. EXPORT_SYMBOL_GPL(ath79_cpu_freq);
  21. u32 ath79_ahb_freq;
  22. EXPORT_SYMBOL_GPL(ath79_ahb_freq);
  23. u32 ath79_ddr_freq;
  24. EXPORT_SYMBOL_GPL(ath79_ddr_freq);
  25. enum ath79_soc_type ath79_soc;
  26. void __iomem *ath79_pll_base;
  27. void __iomem *ath79_reset_base;
  28. EXPORT_SYMBOL_GPL(ath79_reset_base);
  29. void __iomem *ath79_ddr_base;
  30. void ath79_ddr_wb_flush(u32 reg)
  31. {
  32. void __iomem *flush_reg = ath79_ddr_base + reg;
  33. /* Flush the DDR write buffer. */
  34. __raw_writel(0x1, flush_reg);
  35. while (__raw_readl(flush_reg) & 0x1)
  36. ;
  37. /* It must be run twice. */
  38. __raw_writel(0x1, flush_reg);
  39. while (__raw_readl(flush_reg) & 0x1)
  40. ;
  41. }
  42. EXPORT_SYMBOL_GPL(ath79_ddr_wb_flush);
  43. void ath79_device_reset_set(u32 mask)
  44. {
  45. unsigned long flags;
  46. u32 reg;
  47. u32 t;
  48. if (soc_is_ar71xx())
  49. reg = AR71XX_RESET_REG_RESET_MODULE;
  50. else if (soc_is_ar724x())
  51. reg = AR724X_RESET_REG_RESET_MODULE;
  52. else if (soc_is_ar913x())
  53. reg = AR913X_RESET_REG_RESET_MODULE;
  54. else
  55. BUG();
  56. spin_lock_irqsave(&ath79_device_reset_lock, flags);
  57. t = ath79_reset_rr(reg);
  58. ath79_reset_wr(reg, t | mask);
  59. spin_unlock_irqrestore(&ath79_device_reset_lock, flags);
  60. }
  61. EXPORT_SYMBOL_GPL(ath79_device_reset_set);
  62. void ath79_device_reset_clear(u32 mask)
  63. {
  64. unsigned long flags;
  65. u32 reg;
  66. u32 t;
  67. if (soc_is_ar71xx())
  68. reg = AR71XX_RESET_REG_RESET_MODULE;
  69. else if (soc_is_ar724x())
  70. reg = AR724X_RESET_REG_RESET_MODULE;
  71. else if (soc_is_ar913x())
  72. reg = AR913X_RESET_REG_RESET_MODULE;
  73. else
  74. BUG();
  75. spin_lock_irqsave(&ath79_device_reset_lock, flags);
  76. t = ath79_reset_rr(reg);
  77. ath79_reset_wr(reg, t & ~mask);
  78. spin_unlock_irqrestore(&ath79_device_reset_lock, flags);
  79. }
  80. EXPORT_SYMBOL_GPL(ath79_device_reset_clear);