blob: 6c973b6995bb26b19a9a14a3634d71542aa9c8a5 [file] [log] [blame]
Lukasz Majewski38517a72011-10-27 10:36:46 +02001/*
2 * drivers/usb/gadget/s3c_udc.h
3 * Samsung S3C on-chip full/high speed USB device controllers
4 * Copyright (C) 2005 for Samsung Electronics
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 *
20 */
21
22#ifndef __S3C_USB_GADGET
23#define __S3C_USB_GADGET
24
25#include <asm/errno.h>
26#include <linux/usb/ch9.h>
27#include <linux/usb/gadget.h>
28#include <linux/list.h>
29#include <usb/lin_gadget_compat.h>
30
31#define PHY0_SLEEP (1 << 5)
32
33/*-------------------------------------------------------------------------*/
34/* DMA bounce buffer size, 16K is enough even for mass storage */
35#define DMA_BUFFER_SIZE (4096*4)
36
37#define EP0_FIFO_SIZE 64
38#define EP_FIFO_SIZE 512
39#define EP_FIFO_SIZE2 1024
40/* ep0-control, ep1in-bulk, ep2out-bulk, ep3in-int */
41#define S3C_MAX_ENDPOINTS 4
42#define S3C_MAX_HW_ENDPOINTS 16
43
44#define WAIT_FOR_SETUP 0
45#define DATA_STATE_XMIT 1
46#define DATA_STATE_NEED_ZLP 2
47#define WAIT_FOR_OUT_STATUS 3
48#define DATA_STATE_RECV 4
49#define WAIT_FOR_COMPLETE 5
50#define WAIT_FOR_OUT_COMPLETE 6
51#define WAIT_FOR_IN_COMPLETE 7
52#define WAIT_FOR_NULL_COMPLETE 8
53
54#define TEST_J_SEL 0x1
55#define TEST_K_SEL 0x2
56#define TEST_SE0_NAK_SEL 0x3
57#define TEST_PACKET_SEL 0x4
58#define TEST_FORCE_ENABLE_SEL 0x5
59
60/* ************************************************************************* */
61/* IO
62 */
63
64enum ep_type {
65 ep_control, ep_bulk_in, ep_bulk_out, ep_interrupt
66};
67
68struct s3c_ep {
69 struct usb_ep ep;
70 struct s3c_udc *dev;
71
72 const struct usb_endpoint_descriptor *desc;
73 struct list_head queue;
74 unsigned long pio_irqs;
75 int len;
76 void *dma_buf;
77
78 u8 stopped;
79 u8 bEndpointAddress;
80 u8 bmAttributes;
81
82 enum ep_type ep_type;
83 int fifo_num;
84};
85
86struct s3c_request {
87 struct usb_request req;
88 struct list_head queue;
89};
90
91struct s3c_udc {
92 struct usb_gadget gadget;
93 struct usb_gadget_driver *driver;
94
95 struct s3c_plat_otg_data *pdata;
96
97 void *dma_buf[S3C_MAX_ENDPOINTS+1];
98 dma_addr_t dma_addr[S3C_MAX_ENDPOINTS+1];
99
100 int ep0state;
101 struct s3c_ep ep[S3C_MAX_ENDPOINTS];
102
103 unsigned char usb_address;
104
Ɓukasz Majewski7cf7bef2012-03-12 22:08:06 +0000105 unsigned req_pending:1, req_std:1;
Lukasz Majewski38517a72011-10-27 10:36:46 +0200106};
107
108extern struct s3c_udc *the_controller;
109
110#define ep_is_in(EP) (((EP)->bEndpointAddress&USB_DIR_IN) == USB_DIR_IN)
111#define ep_index(EP) ((EP)->bEndpointAddress&0xF)
112#define ep_maxpacket(EP) ((EP)->ep.maxpacket)
113
114/*-------------------------------------------------------------------------*/
115/* #define DEBUG_UDC */
116#ifdef DEBUG_UDC
117#define DBG(stuff...) printf("udc: " stuff)
118#else
119#define DBG(stuff...) do {} while (0)
120#endif
121
122#ifdef DEBUG_S3C_UDC_SETUP
123#define DEBUG_SETUP(fmt, args...) printk(fmt, ##args)
124#else
125#define DEBUG_SETUP(fmt, args...) do {} while (0)
126#endif
127
128#ifdef DEBUG_S3C_UDC_EP0
129#define DEBUG_EP0(fmt, args...) printk(fmt, ##args)
130#else
131#define DEBUG_EP0(fmt, args...) do {} while (0)
132#endif
133
Lukasz Majewski38517a72011-10-27 10:36:46 +0200134#ifdef DEBUG_S3C_UDC_ISR
Anatolij Gustschinea2d9152011-12-19 04:20:35 +0000135#define DEBUG_ISR 1
Lukasz Majewski38517a72011-10-27 10:36:46 +0200136#else
Anatolij Gustschinea2d9152011-12-19 04:20:35 +0000137#define DEBUG_ISR 0
Lukasz Majewski38517a72011-10-27 10:36:46 +0200138#endif
139
140#ifdef DEBUG_S3C_UDC_OUT_EP
141#define DEBUG_OUT_EP(fmt, args...) printk(fmt, ##args)
142#else
143#define DEBUG_OUT_EP(fmt, args...) do {} while (0)
144#endif
145
146#ifdef DEBUG_S3C_UDC_IN_EP
Anatolij Gustschinea2d9152011-12-19 04:20:35 +0000147#define DEBUG_IN_EP 1
Lukasz Majewski38517a72011-10-27 10:36:46 +0200148#else
Anatolij Gustschinea2d9152011-12-19 04:20:35 +0000149#define DEBUG_IN_EP 0
150#endif
151
152#if defined(DEBUG_S3C_UDC_SETUP) || defined(DEBUG_S3C_UDC_EP0) || \
153 defined(DEBUG_S3C_UDC_ISR) || defined(DEBUG_S3C_UDC_OUT_EP) || \
154 defined(DEBUG_S3C_UDC_IN_EP) || defined(DEBUG_S3C_UDC)
155#define DEBUG
Lukasz Majewski38517a72011-10-27 10:36:46 +0200156#endif
157
158#define ERR(stuff...) printf("ERR udc: " stuff)
159#define WARN(stuff...) printf("WARNING udc: " stuff)
160#define INFO(stuff...) printf("INFO udc: " stuff)
161
162extern void otg_phy_init(struct s3c_udc *dev);
163extern void otg_phy_off(struct s3c_udc *dev);
164
165extern void s3c_udc_ep_set_stall(struct s3c_ep *ep);
166extern int s3c_udc_probe(struct s3c_plat_otg_data *pdata);
167
168struct s3c_plat_otg_data {
169 int (*phy_control)(int on);
170 unsigned int regs_phy;
171 unsigned int regs_otg;
172 unsigned int usb_phy_ctrl;
173 unsigned int usb_flags;
174};
175#endif