[ar71xx] update flash locking code
[openwrt/svn-archive/archive.git] / target / linux / ar71xx / files / arch / mips / ar71xx / ar71xx.c
1 /*
2 * AR71xx SoC routines
3 *
4 * Copyright (C) 2008-2009 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/mutex.h>
16
17 #include <asm/mach-ar71xx/ar71xx.h>
18
19 static DEFINE_MUTEX(ar71xx_flash_mutex);
20
21 void __iomem *ar71xx_ddr_base;
22 EXPORT_SYMBOL_GPL(ar71xx_ddr_base);
23
24 void __iomem *ar71xx_pll_base;
25 EXPORT_SYMBOL_GPL(ar71xx_pll_base);
26
27 void __iomem *ar71xx_reset_base;
28 EXPORT_SYMBOL_GPL(ar71xx_reset_base);
29
30 void __iomem *ar71xx_gpio_base;
31 EXPORT_SYMBOL_GPL(ar71xx_gpio_base);
32
33 void __iomem *ar71xx_usb_ctrl_base;
34 EXPORT_SYMBOL_GPL(ar71xx_usb_ctrl_base);
35
36 void ar71xx_device_stop(u32 mask)
37 {
38 unsigned long flags;
39 u32 t;
40
41 switch (ar71xx_soc) {
42 case AR71XX_SOC_AR7130:
43 case AR71XX_SOC_AR7141:
44 case AR71XX_SOC_AR7161:
45 local_irq_save(flags);
46 t = ar71xx_reset_rr(AR71XX_RESET_REG_RESET_MODULE);
47 ar71xx_reset_wr(AR71XX_RESET_REG_RESET_MODULE, t | mask);
48 local_irq_restore(flags);
49 break;
50
51 case AR71XX_SOC_AR9130:
52 case AR71XX_SOC_AR9132:
53 local_irq_save(flags);
54 t = ar71xx_reset_rr(AR91XX_RESET_REG_RESET_MODULE);
55 ar71xx_reset_wr(AR91XX_RESET_REG_RESET_MODULE, t | mask);
56 local_irq_restore(flags);
57 break;
58
59 default:
60 BUG();
61 }
62 }
63 EXPORT_SYMBOL_GPL(ar71xx_device_stop);
64
65 void ar71xx_device_start(u32 mask)
66 {
67 unsigned long flags;
68 u32 t;
69
70 switch (ar71xx_soc) {
71 case AR71XX_SOC_AR7130:
72 case AR71XX_SOC_AR7141:
73 case AR71XX_SOC_AR7161:
74 local_irq_save(flags);
75 t = ar71xx_reset_rr(AR71XX_RESET_REG_RESET_MODULE);
76 ar71xx_reset_wr(AR71XX_RESET_REG_RESET_MODULE, t & ~mask);
77 local_irq_restore(flags);
78 break;
79
80 case AR71XX_SOC_AR9130:
81 case AR71XX_SOC_AR9132:
82 local_irq_save(flags);
83 t = ar71xx_reset_rr(AR91XX_RESET_REG_RESET_MODULE);
84 ar71xx_reset_wr(AR91XX_RESET_REG_RESET_MODULE, t & ~mask);
85 local_irq_restore(flags);
86 break;
87
88 default:
89 BUG();
90 }
91 }
92 EXPORT_SYMBOL_GPL(ar71xx_device_start);
93
94 void ar71xx_ddr_flush(u32 reg)
95 {
96 ar71xx_ddr_wr(reg, 1);
97 while ((ar71xx_ddr_rr(reg) & 0x1));
98
99 ar71xx_ddr_wr(reg, 1);
100 while ((ar71xx_ddr_rr(reg) & 0x1));
101 }
102 EXPORT_SYMBOL_GPL(ar71xx_ddr_flush);
103
104 void ar71xx_flash_acquire(void)
105 {
106 mutex_lock(&ar71xx_flash_mutex);
107 }
108 EXPORT_SYMBOL_GPL(ar71xx_flash_acquire);
109
110 void ar71xx_flash_release(void)
111 {
112 mutex_unlock(&ar71xx_flash_mutex);
113 }
114 EXPORT_SYMBOL_GPL(ar71xx_flash_release);