Loading...
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
12#include <linux/kernel.h>
13#include <linux/module.h>
14#include <linux/types.h>
15#include <linux/spinlock.h>
16
17#include <asm/mach-ath79/ath79.h>
18#include <asm/mach-ath79/ar71xx_regs.h>
19#include "common.h"
20
21static DEFINE_SPINLOCK(ath79_device_reset_lock);
22
23u32 ath79_cpu_freq;
24EXPORT_SYMBOL_GPL(ath79_cpu_freq);
25
26u32 ath79_ahb_freq;
27EXPORT_SYMBOL_GPL(ath79_ahb_freq);
28
29u32 ath79_ddr_freq;
30EXPORT_SYMBOL_GPL(ath79_ddr_freq);
31
32enum ath79_soc_type ath79_soc;
33
34void __iomem *ath79_pll_base;
35void __iomem *ath79_reset_base;
36EXPORT_SYMBOL_GPL(ath79_reset_base);
37void __iomem *ath79_ddr_base;
38
39void ath79_ddr_wb_flush(u32 reg)
40{
41 void __iomem *flush_reg = ath79_ddr_base + reg;
42
43 /* Flush the DDR write buffer. */
44 __raw_writel(0x1, flush_reg);
45 while (__raw_readl(flush_reg) & 0x1)
46 ;
47
48 /* It must be run twice. */
49 __raw_writel(0x1, flush_reg);
50 while (__raw_readl(flush_reg) & 0x1)
51 ;
52}
53EXPORT_SYMBOL_GPL(ath79_ddr_wb_flush);
54
55void ath79_device_reset_set(u32 mask)
56{
57 unsigned long flags;
58 u32 reg;
59 u32 t;
60
61 if (soc_is_ar71xx())
62 reg = AR71XX_RESET_REG_RESET_MODULE;
63 else if (soc_is_ar724x())
64 reg = AR724X_RESET_REG_RESET_MODULE;
65 else if (soc_is_ar913x())
66 reg = AR913X_RESET_REG_RESET_MODULE;
67 else
68 BUG();
69
70 spin_lock_irqsave(&ath79_device_reset_lock, flags);
71 t = ath79_reset_rr(reg);
72 ath79_reset_wr(reg, t | mask);
73 spin_unlock_irqrestore(&ath79_device_reset_lock, flags);
74}
75EXPORT_SYMBOL_GPL(ath79_device_reset_set);
76
77void ath79_device_reset_clear(u32 mask)
78{
79 unsigned long flags;
80 u32 reg;
81 u32 t;
82
83 if (soc_is_ar71xx())
84 reg = AR71XX_RESET_REG_RESET_MODULE;
85 else if (soc_is_ar724x())
86 reg = AR724X_RESET_REG_RESET_MODULE;
87 else if (soc_is_ar913x())
88 reg = AR913X_RESET_REG_RESET_MODULE;
89 else
90 BUG();
91
92 spin_lock_irqsave(&ath79_device_reset_lock, flags);
93 t = ath79_reset_rr(reg);
94 ath79_reset_wr(reg, t & ~mask);
95 spin_unlock_irqrestore(&ath79_device_reset_lock, flags);
96}
97EXPORT_SYMBOL_GPL(ath79_device_reset_clear);
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
15#include <linux/kernel.h>
16#include <linux/module.h>
17#include <linux/types.h>
18#include <linux/spinlock.h>
19
20#include <asm/mach-ath79/ath79.h>
21#include <asm/mach-ath79/ar71xx_regs.h>
22#include "common.h"
23
24static DEFINE_SPINLOCK(ath79_device_reset_lock);
25
26u32 ath79_cpu_freq;
27EXPORT_SYMBOL_GPL(ath79_cpu_freq);
28
29u32 ath79_ahb_freq;
30EXPORT_SYMBOL_GPL(ath79_ahb_freq);
31
32u32 ath79_ddr_freq;
33EXPORT_SYMBOL_GPL(ath79_ddr_freq);
34
35enum ath79_soc_type ath79_soc;
36unsigned int ath79_soc_rev;
37
38void __iomem *ath79_pll_base;
39void __iomem *ath79_reset_base;
40EXPORT_SYMBOL_GPL(ath79_reset_base);
41void __iomem *ath79_ddr_base;
42
43void ath79_ddr_wb_flush(u32 reg)
44{
45 void __iomem *flush_reg = ath79_ddr_base + reg;
46
47 /* Flush the DDR write buffer. */
48 __raw_writel(0x1, flush_reg);
49 while (__raw_readl(flush_reg) & 0x1)
50 ;
51
52 /* It must be run twice. */
53 __raw_writel(0x1, flush_reg);
54 while (__raw_readl(flush_reg) & 0x1)
55 ;
56}
57EXPORT_SYMBOL_GPL(ath79_ddr_wb_flush);
58
59void ath79_device_reset_set(u32 mask)
60{
61 unsigned long flags;
62 u32 reg;
63 u32 t;
64
65 if (soc_is_ar71xx())
66 reg = AR71XX_RESET_REG_RESET_MODULE;
67 else if (soc_is_ar724x())
68 reg = AR724X_RESET_REG_RESET_MODULE;
69 else if (soc_is_ar913x())
70 reg = AR913X_RESET_REG_RESET_MODULE;
71 else if (soc_is_ar933x())
72 reg = AR933X_RESET_REG_RESET_MODULE;
73 else if (soc_is_ar934x())
74 reg = AR934X_RESET_REG_RESET_MODULE;
75 else
76 BUG();
77
78 spin_lock_irqsave(&ath79_device_reset_lock, flags);
79 t = ath79_reset_rr(reg);
80 ath79_reset_wr(reg, t | mask);
81 spin_unlock_irqrestore(&ath79_device_reset_lock, flags);
82}
83EXPORT_SYMBOL_GPL(ath79_device_reset_set);
84
85void ath79_device_reset_clear(u32 mask)
86{
87 unsigned long flags;
88 u32 reg;
89 u32 t;
90
91 if (soc_is_ar71xx())
92 reg = AR71XX_RESET_REG_RESET_MODULE;
93 else if (soc_is_ar724x())
94 reg = AR724X_RESET_REG_RESET_MODULE;
95 else if (soc_is_ar913x())
96 reg = AR913X_RESET_REG_RESET_MODULE;
97 else if (soc_is_ar933x())
98 reg = AR933X_RESET_REG_RESET_MODULE;
99 else if (soc_is_ar934x())
100 reg = AR934X_RESET_REG_RESET_MODULE;
101 else
102 BUG();
103
104 spin_lock_irqsave(&ath79_device_reset_lock, flags);
105 t = ath79_reset_rr(reg);
106 ath79_reset_wr(reg, t & ~mask);
107 spin_unlock_irqrestore(&ath79_device_reset_lock, flags);
108}
109EXPORT_SYMBOL_GPL(ath79_device_reset_clear);