common.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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. unsigned int ath79_soc_rev;
  27. void __iomem *ath79_pll_base;
  28. void __iomem *ath79_reset_base;
  29. EXPORT_SYMBOL_GPL(ath79_reset_base);
  30. void __iomem *ath79_ddr_base;
  31. void ath79_ddr_wb_flush(u32 reg)
  32. {
  33. void __iomem *flush_reg = ath79_ddr_base + reg;
  34. /* Flush the DDR write buffer. */
  35. __raw_writel(0x1, flush_reg);
  36. while (__raw_readl(flush_reg) & 0x1)
  37. ;
  38. /* It must be run twice. */
  39. __raw_writel(0x1, flush_reg);
  40. while (__raw_readl(flush_reg) & 0x1)
  41. ;
  42. }
  43. EXPORT_SYMBOL_GPL(ath79_ddr_wb_flush);
  44. void ath79_device_reset_set(u32 mask)
  45. {
  46. unsigned long flags;
  47. u32 reg;
  48. u32 t;
  49. if (soc_is_ar71xx())
  50. reg = AR71XX_RESET_REG_RESET_MODULE;
  51. else if (soc_is_ar724x())
  52. reg = AR724X_RESET_REG_RESET_MODULE;
  53. else if (soc_is_ar913x())
  54. reg = AR913X_RESET_REG_RESET_MODULE;
  55. else if (soc_is_ar933x())
  56. reg = AR933X_RESET_REG_RESET_MODULE;
  57. else
  58. BUG();
  59. spin_lock_irqsave(&ath79_device_reset_lock, flags);
  60. t = ath79_reset_rr(reg);
  61. ath79_reset_wr(reg, t | mask);
  62. spin_unlock_irqrestore(&ath79_device_reset_lock, flags);
  63. }
  64. EXPORT_SYMBOL_GPL(ath79_device_reset_set);
  65. void ath79_device_reset_clear(u32 mask)
  66. {
  67. unsigned long flags;
  68. u32 reg;
  69. u32 t;
  70. if (soc_is_ar71xx())
  71. reg = AR71XX_RESET_REG_RESET_MODULE;
  72. else if (soc_is_ar724x())
  73. reg = AR724X_RESET_REG_RESET_MODULE;
  74. else if (soc_is_ar913x())
  75. reg = AR913X_RESET_REG_RESET_MODULE;
  76. else if (soc_is_ar933x())
  77. reg = AR933X_RESET_REG_RESET_MODULE;
  78. else
  79. BUG();
  80. spin_lock_irqsave(&ath79_device_reset_lock, flags);
  81. t = ath79_reset_rr(reg);
  82. ath79_reset_wr(reg, t & ~mask);
  83. spin_unlock_irqrestore(&ath79_device_reset_lock, flags);
  84. }
  85. EXPORT_SYMBOL_GPL(ath79_device_reset_clear);