common.c 2.7 KB

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