PRCM: 34XX: Fix wrong shift value used in dpll4_m4x2_ck enable bit
[linux-ginger.git] / drivers / usb / musb / musb_core.h
blobc2cd5a9c486d96b4dae74c40cd7857afe8f2daa5
1 /*
2 * MUSB OTG driver defines
4 * Copyright 2005 Mentor Graphics Corporation
5 * Copyright (C) 2005-2006 by Texas Instruments
6 * Copyright (C) 2006-2007 Nokia Corporation
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * version 2 as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 * 02110-1301 USA
22 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
23 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
24 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
25 * NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
27 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
28 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
29 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
31 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 #ifndef __MUSB_CORE_H__
36 #define __MUSB_CORE_H__
38 #include <linux/slab.h>
39 #include <linux/list.h>
40 #include <linux/interrupt.h>
41 #include <linux/smp_lock.h>
42 #include <linux/errno.h>
43 #include <linux/clk.h>
44 #include <linux/device.h>
45 #include <linux/usb/ch9.h>
46 #include <linux/usb/gadget.h>
47 #include <linux/usb.h>
48 #include <linux/usb/otg.h>
49 #include <linux/usb/musb.h>
51 struct musb;
52 struct musb_hw_ep;
53 struct musb_ep;
56 #include "musb_debug.h"
57 #include "musb_dma.h"
59 #ifdef CONFIG_USB_MUSB_SOC
61 * Get core configuration from a header converted (by cfg_conv)
62 * from the Verilog config file generated by the core config utility
64 * For now we assume that header is provided along with other
65 * arch-specific files. Discrete chips will need a build tweak.
66 * So will using AHB IDs from silicon that provides them.
68 #include <asm/arch/hdrc_cnf.h>
69 #endif
71 #include "musb_io.h"
72 #include "musb_regs.h"
74 #include "musb_gadget.h"
75 #include "../core/hcd.h"
76 #include "musb_host.h"
80 #ifdef CONFIG_USB_MUSB_OTG
82 #define is_peripheral_enabled(musb) ((musb)->board_mode != MUSB_HOST)
83 #define is_host_enabled(musb) ((musb)->board_mode != MUSB_PERIPHERAL)
84 #define is_otg_enabled(musb) ((musb)->board_mode == MUSB_OTG)
86 /* NOTE: otg and peripheral-only state machines start at B_IDLE.
87 * OTG or host-only go to A_IDLE when ID is sensed.
89 #define is_peripheral_active(m) (!(m)->is_host)
90 #define is_host_active(m) ((m)->is_host)
92 #else
93 #define is_peripheral_enabled(musb) is_peripheral_capable()
94 #define is_host_enabled(musb) is_host_capable()
95 #define is_otg_enabled(musb) 0
97 #define is_peripheral_active(musb) is_peripheral_capable()
98 #define is_host_active(musb) is_host_capable()
99 #endif
101 #if defined(CONFIG_USB_MUSB_OTG) || defined(CONFIG_USB_MUSB_PERIPHERAL)
102 /* for some reason, the "select USB_GADGET_MUSB_HDRC" doesn't always
103 * override that choice selection (often USB_GADGET_DUMMY_HCD).
105 #ifndef CONFIG_USB_GADGET_MUSB_HDRC
106 #error bogus Kconfig output ... select CONFIG_USB_GADGET_MUSB_HDRC
107 #endif
108 #endif /* need MUSB gadget selection */
111 #ifdef CONFIG_PROC_FS
112 #include <linux/fs.h>
113 #define MUSB_CONFIG_PROC_FS
114 #endif
116 /****************************** PERIPHERAL ROLE *****************************/
118 #ifdef CONFIG_USB_GADGET_MUSB_HDRC
120 #define is_peripheral_capable() (1)
122 extern irqreturn_t musb_g_ep0_irq(struct musb *);
123 extern void musb_g_tx(struct musb *, u8);
124 extern void musb_g_rx(struct musb *, u8);
125 extern void musb_g_reset(struct musb *);
126 extern void musb_g_suspend(struct musb *);
127 extern void musb_g_resume(struct musb *);
128 extern void musb_g_wakeup(struct musb *);
129 extern void musb_g_disconnect(struct musb *);
131 #else
133 #define is_peripheral_capable() (0)
135 static inline irqreturn_t musb_g_ep0_irq(struct musb *m) { return IRQ_NONE; }
136 static inline void musb_g_reset(struct musb *m) {}
137 static inline void musb_g_suspend(struct musb *m) {}
138 static inline void musb_g_resume(struct musb *m) {}
139 static inline void musb_g_wakeup(struct musb *m) {}
140 static inline void musb_g_disconnect(struct musb *m) {}
142 #endif
144 /****************************** HOST ROLE ***********************************/
146 #ifdef CONFIG_USB_MUSB_HDRC_HCD
148 #define is_host_capable() (1)
150 extern irqreturn_t musb_h_ep0_irq(struct musb *);
151 extern void musb_host_tx(struct musb *, u8);
152 extern void musb_host_rx(struct musb *, u8);
154 #else
156 #define is_host_capable() (0)
158 static inline irqreturn_t musb_h_ep0_irq(struct musb *m) { return IRQ_NONE; }
159 static inline void musb_host_tx(struct musb *m, u8 e) {}
160 static inline void musb_host_rx(struct musb *m, u8 e) {}
162 #endif
165 /****************************** CONSTANTS ********************************/
167 #ifndef MUSB_C_NUM_EPS
168 #define MUSB_C_NUM_EPS ((u8)16)
169 #endif
171 #ifndef MUSB_MAX_END0_PACKET
172 #define MUSB_MAX_END0_PACKET ((u16)MUSB_EP0_FIFOSIZE)
173 #endif
175 /* host side ep0 states */
176 enum musb_h_ep0_state {
177 MUSB_EP0_IDLE,
178 MUSB_EP0_START, /* expect ack of setup */
179 MUSB_EP0_IN, /* expect IN DATA */
180 MUSB_EP0_OUT, /* expect ack of OUT DATA */
181 MUSB_EP0_STATUS, /* expect ack of STATUS */
182 } __attribute__ ((packed));
184 /* peripheral side ep0 states */
185 enum musb_g_ep0_state {
186 MUSB_EP0_STAGE_SETUP, /* idle, waiting for setup */
187 MUSB_EP0_STAGE_TX, /* IN data */
188 MUSB_EP0_STAGE_RX, /* OUT data */
189 MUSB_EP0_STAGE_STATUSIN, /* (after OUT data) */
190 MUSB_EP0_STAGE_STATUSOUT, /* (after IN data) */
191 MUSB_EP0_STAGE_ACKWAIT, /* after zlp, before statusin */
192 } __attribute__ ((packed));
194 /* OTG protocol constants */
195 #define OTG_TIME_A_WAIT_VRISE 100 /* msec (max) */
196 #define OTG_TIME_A_WAIT_BCON 0 /* 0=infinite; min 1000 msec */
197 #define OTG_TIME_A_IDLE_BDIS 200 /* msec (min) */
199 /*************************** REGISTER ACCESS ********************************/
201 /* Endpoint registers (other than dynfifo setup) can be accessed either
202 * directly with the "flat" model, or after setting up an index register.
205 #if defined(CONFIG_ARCH_DAVINCI) || defined(CONFIG_ARCH_OMAP2430) \
206 || defined(CONFIG_ARCH_OMAP3430)
207 /* REVISIT indexed access seemed to
208 * misbehave (on DaVinci) for at least peripheral IN ...
210 #define MUSB_FLAT_REG
211 #endif
213 /* TUSB mapping: "flat" plus ep0 special cases */
214 #if defined(CONFIG_USB_TUSB6010)
215 #define musb_ep_select(_mbase, _epnum) \
216 musb_writeb((_mbase), MUSB_INDEX, (_epnum))
217 #define MUSB_EP_OFFSET MUSB_TUSB_OFFSET
219 /* "flat" mapping: each endpoint has its own i/o address */
220 #elif defined(MUSB_FLAT_REG)
221 #define musb_ep_select(_mbase, _epnum) (((void)(_mbase)), ((void)(_epnum)))
222 #define MUSB_EP_OFFSET MUSB_FLAT_OFFSET
224 /* "indexed" mapping: INDEX register controls register bank select */
225 #else
226 #define musb_ep_select(_mbase, _epnum) \
227 musb_writeb((_mbase), MUSB_INDEX, (_epnum))
228 #define MUSB_EP_OFFSET MUSB_INDEXED_OFFSET
229 #endif
231 /****************************** FUNCTIONS ********************************/
233 #define MUSB_HST_MODE(_musb)\
234 { (_musb)->is_host = true; }
235 #define MUSB_DEV_MODE(_musb) \
236 { (_musb)->is_host = false; }
238 #define test_devctl_hst_mode(_x) \
239 (musb_readb((_x)->mregs, MUSB_DEVCTL)&MUSB_DEVCTL_HM)
241 #define MUSB_MODE(musb) ((musb)->is_host ? "Host" : "Peripheral")
243 /******************************** TYPES *************************************/
246 * struct musb_hw_ep - endpoint hardware (bidirectional)
248 * Ordered slightly for better cacheline locality.
250 struct musb_hw_ep {
251 struct musb *musb;
252 void __iomem *fifo;
253 void __iomem *regs;
255 #ifdef CONFIG_USB_TUSB6010
256 void __iomem *conf;
257 #endif
259 /* index in musb->endpoints[] */
260 u8 epnum;
262 /* hardware configuration, possibly dynamic */
263 bool is_shared_fifo;
264 bool tx_double_buffered;
265 bool rx_double_buffered;
266 u16 max_packet_sz_tx;
267 u16 max_packet_sz_rx;
269 struct dma_channel *tx_channel;
270 struct dma_channel *rx_channel;
272 #ifdef CONFIG_USB_TUSB6010
273 /* TUSB has "asynchronous" and "synchronous" dma modes */
274 dma_addr_t fifo_async;
275 dma_addr_t fifo_sync;
276 void __iomem *fifo_sync_va;
277 #endif
279 #ifdef CONFIG_USB_MUSB_HDRC_HCD
280 void __iomem *target_regs;
282 /* currently scheduled peripheral endpoint */
283 struct musb_qh *in_qh;
284 struct musb_qh *out_qh;
286 u8 rx_reinit;
287 u8 tx_reinit;
288 #endif
290 #ifdef CONFIG_USB_GADGET_MUSB_HDRC
291 /* peripheral side */
292 struct musb_ep ep_in; /* TX */
293 struct musb_ep ep_out; /* RX */
294 #endif
297 static inline struct usb_request *next_in_request(struct musb_hw_ep *hw_ep)
299 #ifdef CONFIG_USB_GADGET_MUSB_HDRC
300 return next_request(&hw_ep->ep_in);
301 #else
302 return NULL;
303 #endif
306 static inline struct usb_request *next_out_request(struct musb_hw_ep *hw_ep)
308 #ifdef CONFIG_USB_GADGET_MUSB_HDRC
309 return next_request(&hw_ep->ep_out);
310 #else
311 return NULL;
312 #endif
316 * struct musb - Driver instance data.
318 struct musb {
319 spinlock_t lock;
320 struct clk *clock;
321 irqreturn_t (*isr)(int, void *);
322 struct work_struct irq_work;
324 /* this hub status bit is reserved by USB 2.0 and not seen by usbcore */
325 #define MUSB_PORT_STAT_RESUME (1 << 31)
327 u32 port1_status;
329 #ifdef CONFIG_USB_MUSB_HDRC_HCD
330 unsigned long rh_timer;
332 enum musb_h_ep0_state ep0_stage;
334 /* bulk traffic normally dedicates endpoint hardware, and each
335 * direction has its own ring of host side endpoints.
336 * we try to progress the transfer at the head of each endpoint's
337 * queue until it completes or NAKs too much; then we try the next
338 * endpoint.
340 struct musb_hw_ep *bulk_ep;
342 struct list_head control; /* of musb_qh */
343 struct list_head in_bulk; /* of musb_qh */
344 struct list_head out_bulk; /* of musb_qh */
345 struct musb_qh *periodic[32]; /* tree of interrupt+iso */
346 #endif
348 /* called with IRQs blocked; ON/nonzero implies starting a session,
349 * and waiting at least a_wait_vrise_tmout.
351 void (*board_set_vbus)(struct musb *, int is_on);
353 struct dma_controller *dma_controller;
355 struct device *controller;
356 void __iomem *ctrl_base;
357 void __iomem *mregs;
359 #ifdef CONFIG_USB_TUSB6010
360 dma_addr_t async;
361 dma_addr_t sync;
362 void __iomem *sync_va;
363 #endif
365 /* passed down from chip/board specific irq handlers */
366 u8 int_usb;
367 u16 int_rx;
368 u16 int_tx;
370 struct otg_transceiver xceiv;
372 int nIrq;
374 struct musb_hw_ep endpoints[MUSB_C_NUM_EPS];
375 #define control_ep endpoints
377 #define VBUSERR_RETRY_COUNT 3
378 u16 vbuserr_retry;
379 u16 epmask;
380 u8 nr_endpoints;
382 u8 board_mode; /* enum musb_mode */
383 int (*board_set_power)(int state);
385 int (*set_clock)(struct clk *clk, int is_active);
387 u8 min_power; /* vbus for periph, in mA/2 */
389 bool is_host;
391 int a_wait_bcon; /* VBUS timeout in msecs */
392 unsigned long idle_timeout; /* Next timeout in jiffies */
394 /* active means connected and not suspended */
395 unsigned is_active:1;
397 unsigned is_multipoint:1;
398 unsigned ignore_disconnect:1; /* during bus resets */
400 #ifdef C_MP_TX
401 unsigned bulk_split:1;
402 #define can_bulk_split(musb,type) \
403 (((type) == USB_ENDPOINT_XFER_BULK) && (musb)->bulk_split)
404 #else
405 #define can_bulk_split(musb, type) 0
406 #endif
408 #ifdef C_MP_RX
409 unsigned bulk_combine:1;
410 #define can_bulk_combine(musb,type) \
411 (((type) == USB_ENDPOINT_XFER_BULK) && (musb)->bulk_combine)
412 #else
413 #define can_bulk_combine(musb, type) 0
414 #endif
416 #ifdef CONFIG_USB_GADGET_MUSB_HDRC
417 /* is_suspended means USB B_PERIPHERAL suspend */
418 unsigned is_suspended:1;
420 /* may_wakeup means remote wakeup is enabled */
421 unsigned may_wakeup:1;
423 /* is_self_powered is reported in device status and the
424 * config descriptor. is_bus_powered means B_PERIPHERAL
425 * draws some VBUS current; both can be true.
427 unsigned is_self_powered:1;
428 unsigned is_bus_powered:1;
430 unsigned set_address:1;
431 unsigned test_mode:1;
432 unsigned softconnect:1;
434 u8 address;
435 u8 test_mode_nr;
436 u16 ackpend; /* ep0 */
437 enum musb_g_ep0_state ep0_state;
438 struct usb_gadget g; /* the gadget */
439 struct usb_gadget_driver *gadget_driver; /* its driver */
440 #endif
442 #ifdef MUSB_CONFIG_PROC_FS
443 struct proc_dir_entry *proc_entry;
444 #endif
447 static inline void musb_set_vbus(struct musb *musb, int is_on)
449 musb->board_set_vbus(musb, is_on);
452 #ifdef CONFIG_USB_GADGET_MUSB_HDRC
453 static inline struct musb *gadget_to_musb(struct usb_gadget *g)
455 return container_of(g, struct musb, g);
457 #endif
460 /***************************** Glue it together *****************************/
462 extern const char musb_driver_name[];
464 extern void musb_start(struct musb *musb);
465 extern void musb_stop(struct musb *musb);
467 extern void musb_write_fifo(struct musb_hw_ep *ep, u16 len, const u8 *src);
468 extern void musb_read_fifo(struct musb_hw_ep *ep, u16 len, u8 *dst);
470 extern void musb_load_testpacket(struct musb *);
472 extern irqreturn_t musb_interrupt(struct musb *);
474 extern void musb_platform_enable(struct musb *musb);
475 extern void musb_platform_disable(struct musb *musb);
477 extern void musb_hnp_stop(struct musb *musb);
479 extern void musb_platform_set_mode(struct musb *musb, u8 musb_mode);
481 #if defined(CONFIG_USB_TUSB6010) || \
482 defined(CONFIG_ARCH_OMAP2430) || defined(CONFIG_ARCH_OMAP34XX)
483 extern void musb_platform_try_idle(struct musb *musb, unsigned long timeout);
484 #else
485 #define musb_platform_try_idle(x, y) do {} while (0)
486 #endif
488 #ifdef CONFIG_USB_TUSB6010
489 extern int musb_platform_get_vbus_status(struct musb *musb);
490 #else
491 #define musb_platform_get_vbus_status(x) 0
492 #endif
494 extern int __init musb_platform_init(struct musb *musb);
495 extern int musb_platform_exit(struct musb *musb);
497 /*-------------------------- ProcFS definitions ---------------------*/
499 struct proc_dir_entry;
501 #if (MUSB_DEBUG > 0) && defined(MUSB_CONFIG_PROC_FS)
502 extern struct proc_dir_entry *musb_debug_create(char *name, struct musb *data);
503 extern void musb_debug_delete(char *name, struct musb *data);
505 #else
506 static inline struct proc_dir_entry *
507 musb_debug_create(char *name, struct musb *data)
509 return NULL;
511 static inline void musb_debug_delete(char *name, struct musb *data)
514 #endif
516 #endif /* __MUSB_CORE_H__ */