4 * Copyright (C) 2008-2009 Gabor Juhos <juhosg@openwrt.org>
5 * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
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.
12 #include <linux/kernel.h>
13 #include <linux/module.h>
14 #include <linux/types.h>
15 #include <linux/mutex.h>
16 #include <linux/spinlock.h>
18 #include <asm/mach-ar71xx/ar71xx.h>
20 static DEFINE_MUTEX(ar71xx_flash_mutex
);
21 static DEFINE_SPINLOCK(ar71xx_device_lock
);
23 void __iomem
*ar71xx_ddr_base
;
24 EXPORT_SYMBOL_GPL(ar71xx_ddr_base
);
26 void __iomem
*ar71xx_pll_base
;
27 EXPORT_SYMBOL_GPL(ar71xx_pll_base
);
29 void __iomem
*ar71xx_reset_base
;
30 EXPORT_SYMBOL_GPL(ar71xx_reset_base
);
32 void __iomem
*ar71xx_gpio_base
;
33 EXPORT_SYMBOL_GPL(ar71xx_gpio_base
);
35 void __iomem
*ar71xx_usb_ctrl_base
;
36 EXPORT_SYMBOL_GPL(ar71xx_usb_ctrl_base
);
38 void ar71xx_device_stop(u32 mask
)
45 case AR71XX_SOC_AR7130
:
46 case AR71XX_SOC_AR7141
:
47 case AR71XX_SOC_AR7161
:
48 spin_lock_irqsave(&ar71xx_device_lock
, flags
);
49 t
= ar71xx_reset_rr(AR71XX_RESET_REG_RESET_MODULE
);
50 ar71xx_reset_wr(AR71XX_RESET_REG_RESET_MODULE
, t
| mask
);
51 spin_unlock_irqrestore(&ar71xx_device_lock
, flags
);
54 case AR71XX_SOC_AR7240
:
55 case AR71XX_SOC_AR7241
:
56 case AR71XX_SOC_AR7242
:
57 mask_inv
= mask
& RESET_MODULE_USB_OHCI_DLL_7240
;
58 spin_lock_irqsave(&ar71xx_device_lock
, flags
);
59 t
= ar71xx_reset_rr(AR724X_RESET_REG_RESET_MODULE
);
62 ar71xx_reset_wr(AR724X_RESET_REG_RESET_MODULE
, t
);
63 spin_unlock_irqrestore(&ar71xx_device_lock
, flags
);
66 case AR71XX_SOC_AR9130
:
67 case AR71XX_SOC_AR9132
:
68 spin_lock_irqsave(&ar71xx_device_lock
, flags
);
69 t
= ar71xx_reset_rr(AR91XX_RESET_REG_RESET_MODULE
);
70 ar71xx_reset_wr(AR91XX_RESET_REG_RESET_MODULE
, t
| mask
);
71 spin_unlock_irqrestore(&ar71xx_device_lock
, flags
);
74 case AR71XX_SOC_AR9341
:
75 case AR71XX_SOC_AR9342
:
76 case AR71XX_SOC_AR9344
:
77 spin_lock_irqsave(&ar71xx_device_lock
, flags
);
78 t
= ar71xx_reset_rr(AR934X_RESET_REG_RESET_MODULE
);
79 ar71xx_reset_wr(AR934X_RESET_REG_RESET_MODULE
, t
| mask
);
80 spin_unlock_irqrestore(&ar71xx_device_lock
, flags
);
87 EXPORT_SYMBOL_GPL(ar71xx_device_stop
);
89 void ar71xx_device_start(u32 mask
)
96 case AR71XX_SOC_AR7130
:
97 case AR71XX_SOC_AR7141
:
98 case AR71XX_SOC_AR7161
:
99 spin_lock_irqsave(&ar71xx_device_lock
, flags
);
100 t
= ar71xx_reset_rr(AR71XX_RESET_REG_RESET_MODULE
);
101 ar71xx_reset_wr(AR71XX_RESET_REG_RESET_MODULE
, t
& ~mask
);
102 spin_unlock_irqrestore(&ar71xx_device_lock
, flags
);
105 case AR71XX_SOC_AR7240
:
106 case AR71XX_SOC_AR7241
:
107 case AR71XX_SOC_AR7242
:
108 mask_inv
= mask
& RESET_MODULE_USB_OHCI_DLL_7240
;
109 spin_lock_irqsave(&ar71xx_device_lock
, flags
);
110 t
= ar71xx_reset_rr(AR724X_RESET_REG_RESET_MODULE
);
113 ar71xx_reset_wr(AR724X_RESET_REG_RESET_MODULE
, t
);
114 spin_unlock_irqrestore(&ar71xx_device_lock
, flags
);
117 case AR71XX_SOC_AR9130
:
118 case AR71XX_SOC_AR9132
:
119 spin_lock_irqsave(&ar71xx_device_lock
, flags
);
120 t
= ar71xx_reset_rr(AR91XX_RESET_REG_RESET_MODULE
);
121 ar71xx_reset_wr(AR91XX_RESET_REG_RESET_MODULE
, t
& ~mask
);
122 spin_unlock_irqrestore(&ar71xx_device_lock
, flags
);
125 case AR71XX_SOC_AR9341
:
126 case AR71XX_SOC_AR9342
:
127 case AR71XX_SOC_AR9344
:
128 spin_lock_irqsave(&ar71xx_device_lock
, flags
);
129 t
= ar71xx_reset_rr(AR934X_RESET_REG_RESET_MODULE
);
130 ar71xx_reset_wr(AR934X_RESET_REG_RESET_MODULE
, t
& ~mask
);
131 spin_unlock_irqrestore(&ar71xx_device_lock
, flags
);
138 EXPORT_SYMBOL_GPL(ar71xx_device_start
);
140 int ar71xx_device_stopped(u32 mask
)
145 switch (ar71xx_soc
) {
146 case AR71XX_SOC_AR7130
:
147 case AR71XX_SOC_AR7141
:
148 case AR71XX_SOC_AR7161
:
149 spin_lock_irqsave(&ar71xx_device_lock
, flags
);
150 t
= ar71xx_reset_rr(AR71XX_RESET_REG_RESET_MODULE
);
151 spin_unlock_irqrestore(&ar71xx_device_lock
, flags
);
154 case AR71XX_SOC_AR7240
:
155 case AR71XX_SOC_AR7241
:
156 case AR71XX_SOC_AR7242
:
157 spin_lock_irqsave(&ar71xx_device_lock
, flags
);
158 t
= ar71xx_reset_rr(AR724X_RESET_REG_RESET_MODULE
);
159 spin_unlock_irqrestore(&ar71xx_device_lock
, flags
);
162 case AR71XX_SOC_AR9130
:
163 case AR71XX_SOC_AR9132
:
164 spin_lock_irqsave(&ar71xx_device_lock
, flags
);
165 t
= ar71xx_reset_rr(AR91XX_RESET_REG_RESET_MODULE
);
166 spin_unlock_irqrestore(&ar71xx_device_lock
, flags
);
169 case AR71XX_SOC_AR9341
:
170 case AR71XX_SOC_AR9342
:
171 case AR71XX_SOC_AR9344
:
172 spin_lock_irqsave(&ar71xx_device_lock
, flags
);
173 t
= ar71xx_reset_rr(AR934X_RESET_REG_RESET_MODULE
);
174 spin_unlock_irqrestore(&ar71xx_device_lock
, flags
);
181 return ((t
& mask
) == mask
);
183 EXPORT_SYMBOL_GPL(ar71xx_device_stopped
);
185 void ar71xx_ddr_flush(u32 reg
)
187 ar71xx_ddr_wr(reg
, 1);
188 while ((ar71xx_ddr_rr(reg
) & 0x1))
191 ar71xx_ddr_wr(reg
, 1);
192 while ((ar71xx_ddr_rr(reg
) & 0x1))
195 EXPORT_SYMBOL_GPL(ar71xx_ddr_flush
);
197 void ar71xx_flash_acquire(void)
199 mutex_lock(&ar71xx_flash_mutex
);
201 EXPORT_SYMBOL_GPL(ar71xx_flash_acquire
);
203 void ar71xx_flash_release(void)
205 mutex_unlock(&ar71xx_flash_mutex
);
207 EXPORT_SYMBOL_GPL(ar71xx_flash_release
);