[cns3xxx]: various dwc (OTG) driver fixups
[openwrt.git] / target / linux / cns3xxx / files / drivers / usb / dwc / otg_plat.h
1 /* ==========================================================================
2  * $File: //dwh/usb_iip/dev/software/otg/linux/platform/dwc_otg_plat.h $
3  * $Revision: #23 $
4  * $Date: 2008/07/15 $
5  * $Change: 1064915 $
6  *
7  * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
8  * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
9  * otherwise expressly agreed to in writing between Synopsys and you.
10  *
11  * The Software IS NOT an item of Licensed Software or Licensed Product under
12  * any End User Software License Agreement or Agreement for Licensed Product
13  * with Synopsys or any supplement thereto. You are permitted to use and
14  * redistribute this Software in source and binary forms, with or without
15  * modification, provided that redistributions of source code must retain this
16  * notice. You may not view, use, disclose, copy or distribute this file or
17  * any information contained herein except pursuant to this license grant from
18  * Synopsys. If you do not agree with this notice, including the disclaimer
19  * below, then you are not authorized to use the Software.
20  *
21  * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
22  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24  * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
25  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
26  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
31  * DAMAGE.
32  * ========================================================================== */
33
34 #if !defined(__DWC_OTG_PLAT_H__)
35 #define __DWC_OTG_PLAT_H__
36
37 #include <linux/types.h>
38 #include <linux/slab.h>
39 #include <linux/list.h>
40 #include <linux/delay.h>
41 #include <asm/io.h>
42
43 /* Changed all readl and writel to __raw_readl, __raw_writel */
44
45 /**
46  * @file
47  *
48  * This file contains the Platform Specific constants, interfaces
49  * (functions and macros) for Linux.
50  *
51  */
52 //#if !defined(__LINUX_ARM_ARCH__)
53 //#error "The contents of this file is Linux specific!!!"
54 //#endif
55
56 /**
57  * Reads the content of a register.
58  *
59  * @param reg address of register to read.
60  * @return contents of the register.
61  *
62
63  * Usage:<br>
64  * <code>uint32_t dev_ctl = dwc_read_reg32(&dev_regs->dctl);</code>
65  */
66 static __inline__ uint32_t dwc_read_reg32( volatile uint32_t *reg)
67 {
68                   return __raw_readl(reg);
69      //   return readl(reg);
70 };
71
72 /**
73  * Writes a register with a 32 bit value.
74  *
75  * @param reg address of register to read.
76  * @param value to write to _reg.
77  *
78  * Usage:<br>
79  * <code>dwc_write_reg32(&dev_regs->dctl, 0); </code>
80  */
81 static __inline__ void dwc_write_reg32( volatile uint32_t *reg, const uint32_t value)
82 {
83      //   writel( value, reg );
84                   __raw_writel(value, reg);
85
86 };
87
88 /**
89  * This function modifies bit values in a register.  Using the
90  * algorithm: (reg_contents & ~clear_mask) | set_mask.
91  *
92  * @param reg address of register to read.
93  * @param clear_mask bit mask to be cleared.
94  * @param set_mask bit mask to be set.
95  *
96  * Usage:<br>
97  * <code> // Clear the SOF Interrupt Mask bit and <br>
98  * // set the OTG Interrupt mask bit, leaving all others as they were.
99  *    dwc_modify_reg32(&dev_regs->gintmsk, DWC_SOF_INT, DWC_OTG_INT);</code>
100  */
101 static __inline__
102  void dwc_modify_reg32( volatile uint32_t *reg, const uint32_t clear_mask, const uint32_t set_mask)
103 {
104       //  writel( (readl(reg) & ~clear_mask) | set_mask, reg );
105         __raw_writel( (__raw_readl(reg) & ~clear_mask) | set_mask, reg );
106 };
107
108
109 /**
110  * Wrapper for the OS micro-second delay function.
111  * @param[in] usecs Microseconds of delay
112  */
113 static __inline__ void UDELAY( const uint32_t usecs )
114 {
115         udelay( usecs );
116 }
117
118 /**
119  * Wrapper for the OS milli-second delay function.
120  * @param[in] msecs milliseconds of delay
121  */
122 static __inline__ void MDELAY( const uint32_t msecs )
123 {
124         mdelay( msecs );
125 }
126
127 /**
128  * Wrapper for the Linux spin_lock.  On the ARM (Integrator)
129  * spin_lock() is a nop.
130  *
131  * @param lock Pointer to the spinlock.
132  */
133 static __inline__ void SPIN_LOCK( spinlock_t *lock )
134 {
135         spin_lock(lock);
136 }
137
138 /**
139  * Wrapper for the Linux spin_unlock.  On the ARM (Integrator)
140  * spin_lock() is a nop.
141  *
142  * @param lock Pointer to the spinlock.
143  */
144 static __inline__ void SPIN_UNLOCK( spinlock_t *lock )
145 {
146         spin_unlock(lock);
147 }
148
149 /**
150  * Wrapper (macro) for the Linux spin_lock_irqsave.  On the ARM
151  * (Integrator) spin_lock() is a nop.
152  *
153  * @param l Pointer to the spinlock.
154  * @param f unsigned long for irq flags storage.
155  */
156 #define SPIN_LOCK_IRQSAVE( l, f )  spin_lock_irqsave(l,f);
157
158 /**
159  * Wrapper (macro) for the Linux spin_unlock_irqrestore.  On the ARM
160  * (Integrator) spin_lock() is a nop.
161  *
162  * @param l Pointer to the spinlock.
163  * @param f unsigned long for irq flags storage.
164  */
165 #define SPIN_UNLOCK_IRQRESTORE( l,f ) spin_unlock_irqrestore(l,f);
166
167 /*
168  * Debugging support vanishes in non-debug builds.
169  */
170
171
172 /**
173  * The Debug Level bit-mask variable.
174  */
175 extern uint32_t g_dbg_lvl;
176 /**
177  * Set the Debug Level variable.
178  */
179 static inline uint32_t SET_DEBUG_LEVEL( const uint32_t new )
180 {
181         uint32_t old = g_dbg_lvl;
182         g_dbg_lvl = new;
183         return old;
184 }
185
186 /** When debug level has the DBG_CIL bit set, display CIL Debug messages. */
187 #define DBG_CIL         (0x2)
188 /** When debug level has the DBG_CILV bit set, display CIL Verbose debug
189  * messages */
190 #define DBG_CILV        (0x20)
191 /**  When debug level has the DBG_PCD bit set, display PCD (Device) debug
192  *  messages */
193 #define DBG_PCD         (0x4)
194 /** When debug level has the DBG_PCDV set, display PCD (Device) Verbose debug
195  * messages */
196 #define DBG_PCDV        (0x40)
197 /** When debug level has the DBG_HCD bit set, display Host debug messages */
198 #define DBG_HCD         (0x8)
199 /** When debug level has the DBG_HCDV bit set, display Verbose Host debug
200  * messages */
201 #define DBG_HCDV        (0x80)
202 /** When debug level has the DBG_HCD_URB bit set, display enqueued URBs in host
203  *  mode. */
204 #define DBG_HCD_URB     (0x800)
205 #define DBG_HCD_FLOOD (0x1)
206
207 /** When debug level has any bit set, display debug messages */
208 #define DBG_ANY         (0xFF)
209
210 /** All debug messages off */
211 #define DBG_OFF         0
212
213 /** Prefix string for DWC_DEBUG print macros. */
214 #define USB_DWC "DWC_otg: "
215
216 /**
217  * Print a debug message when the Global debug level variable contains
218  * the bit defined in <code>lvl</code>.
219  *
220  * @param[in] lvl - Debug level, use one of the DBG_ constants above.
221  * @param[in] x - like printf
222  *
223  *    Example:<p>
224  * <code>
225  *      DWC_DEBUGPL( DBG_ANY, "%s(%p)\n", __func__, _reg_base_addr);
226  * </code>
227  * <br>
228  * results in:<br>
229  * <code>
230  * usb-DWC_otg: dwc_otg_cil_init(ca867000)
231  * </code>
232  */
233 #ifdef DEBUG
234
235 # define DWC_DEBUGPL(lvl, x...) do{ if ((lvl)&g_dbg_lvl)printk( KERN_DEBUG USB_DWC x ); }while(0)
236 # define DWC_DEBUGP(x...)       DWC_DEBUGPL(DBG_ANY, x )
237
238 # define CHK_DEBUG_LEVEL(level) ((level) & g_dbg_lvl)
239
240 #else
241
242 # define DWC_DEBUGPL(lvl, x...) do{}while(0)
243 # define DWC_DEBUGP(x...)
244
245 # define CHK_DEBUG_LEVEL(level) (0)
246
247 #endif /*DEBUG*/
248
249 /**
250  * Print an Error message.
251  */
252 #define DWC_ERROR(x...) printk( KERN_ERR USB_DWC x )
253 /**
254  * Print a Warning message.
255  */
256 #define DWC_WARN(x...) printk( KERN_WARNING USB_DWC x )
257 /**
258  * Print a notice (normal but significant message).
259  */
260 #define DWC_NOTICE(x...) printk( KERN_NOTICE USB_DWC x )
261 /**
262  *  Basic message printing.
263  */
264 #define DWC_PRINT(x...) printk( KERN_INFO USB_DWC x )
265
266 #endif
267