blob: 3e6135a6bd977c4f25201840111f6ebf2f549c0c [file] [log] [blame]
Lukasz Majewskiac3c8312011-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>
Lukasz Majewski373cc992012-05-02 13:11:34 +020027#include <usbdescriptors.h>
Lukasz Majewskiac3c8312011-10-27 10:36:46 +020028#include <linux/usb/gadget.h>
29#include <linux/list.h>
30#include <usb/lin_gadget_compat.h>
31
32#define PHY0_SLEEP (1 << 5)
33
34/*-------------------------------------------------------------------------*/
35/* DMA bounce buffer size, 16K is enough even for mass storage */
36#define DMA_BUFFER_SIZE (4096*4)
37
38#define EP0_FIFO_SIZE 64
39#define EP_FIFO_SIZE 512
40#define EP_FIFO_SIZE2 1024
41/* ep0-control, ep1in-bulk, ep2out-bulk, ep3in-int */
42#define S3C_MAX_ENDPOINTS 4
43#define S3C_MAX_HW_ENDPOINTS 16
44
45#define WAIT_FOR_SETUP 0
46#define DATA_STATE_XMIT 1
47#define DATA_STATE_NEED_ZLP 2
48#define WAIT_FOR_OUT_STATUS 3
49#define DATA_STATE_RECV 4
50#define WAIT_FOR_COMPLETE 5
51#define WAIT_FOR_OUT_COMPLETE 6
52#define WAIT_FOR_IN_COMPLETE 7
53#define WAIT_FOR_NULL_COMPLETE 8
54
55#define TEST_J_SEL 0x1
56#define TEST_K_SEL 0x2
57#define TEST_SE0_NAK_SEL 0x3
58#define TEST_PACKET_SEL 0x4
59#define TEST_FORCE_ENABLE_SEL 0x5
60
61/* ************************************************************************* */
62/* IO
63 */
64
65enum ep_type {
66 ep_control, ep_bulk_in, ep_bulk_out, ep_interrupt
67};
68
69struct s3c_ep {
70 struct usb_ep ep;
71 struct s3c_udc *dev;
72
73 const struct usb_endpoint_descriptor *desc;
74 struct list_head queue;
75 unsigned long pio_irqs;
76 int len;
77 void *dma_buf;
78
79 u8 stopped;
80 u8 bEndpointAddress;
81 u8 bmAttributes;
82
83 enum ep_type ep_type;
84 int fifo_num;
85};
86
87struct s3c_request {
88 struct usb_request req;
89 struct list_head queue;
90};
91
92struct s3c_udc {
93 struct usb_gadget gadget;
94 struct usb_gadget_driver *driver;
95
96 struct s3c_plat_otg_data *pdata;
97
98 void *dma_buf[S3C_MAX_ENDPOINTS+1];
99 dma_addr_t dma_addr[S3C_MAX_ENDPOINTS+1];
100
101 int ep0state;
102 struct s3c_ep ep[S3C_MAX_ENDPOINTS];
103
104 unsigned char usb_address;
105
Ɓukasz Majewski22c8a872012-03-12 22:08:06 +0000106 unsigned req_pending:1, req_std:1;
Lukasz Majewskiac3c8312011-10-27 10:36:46 +0200107};
108
109extern struct s3c_udc *the_controller;
110
111#define ep_is_in(EP) (((EP)->bEndpointAddress&USB_DIR_IN) == USB_DIR_IN)
112#define ep_index(EP) ((EP)->bEndpointAddress&0xF)
113#define ep_maxpacket(EP) ((EP)->ep.maxpacket)
114
115/*-------------------------------------------------------------------------*/
116/* #define DEBUG_UDC */
117#ifdef DEBUG_UDC
118#define DBG(stuff...) printf("udc: " stuff)
119#else
120#define DBG(stuff...) do {} while (0)
121#endif
122
123#ifdef DEBUG_S3C_UDC_SETUP
124#define DEBUG_SETUP(fmt, args...) printk(fmt, ##args)
125#else
126#define DEBUG_SETUP(fmt, args...) do {} while (0)
127#endif
128
129#ifdef DEBUG_S3C_UDC_EP0
130#define DEBUG_EP0(fmt, args...) printk(fmt, ##args)
131#else
132#define DEBUG_EP0(fmt, args...) do {} while (0)
133#endif
134
Lukasz Majewskiac3c8312011-10-27 10:36:46 +0200135#ifdef DEBUG_S3C_UDC_ISR
Anatolij Gustschine63ce4f2011-12-19 04:20:35 +0000136#define DEBUG_ISR 1
Lukasz Majewskiac3c8312011-10-27 10:36:46 +0200137#else
Anatolij Gustschine63ce4f2011-12-19 04:20:35 +0000138#define DEBUG_ISR 0
Lukasz Majewskiac3c8312011-10-27 10:36:46 +0200139#endif
140
141#ifdef DEBUG_S3C_UDC_OUT_EP
142#define DEBUG_OUT_EP(fmt, args...) printk(fmt, ##args)
143#else
144#define DEBUG_OUT_EP(fmt, args...) do {} while (0)
145#endif
146
147#ifdef DEBUG_S3C_UDC_IN_EP
Anatolij Gustschine63ce4f2011-12-19 04:20:35 +0000148#define DEBUG_IN_EP 1
Lukasz Majewskiac3c8312011-10-27 10:36:46 +0200149#else
Anatolij Gustschine63ce4f2011-12-19 04:20:35 +0000150#define DEBUG_IN_EP 0
151#endif
152
153#if defined(DEBUG_S3C_UDC_SETUP) || defined(DEBUG_S3C_UDC_EP0) || \
154 defined(DEBUG_S3C_UDC_ISR) || defined(DEBUG_S3C_UDC_OUT_EP) || \
155 defined(DEBUG_S3C_UDC_IN_EP) || defined(DEBUG_S3C_UDC)
156#define DEBUG
Lukasz Majewskiac3c8312011-10-27 10:36:46 +0200157#endif
158
159#define ERR(stuff...) printf("ERR udc: " stuff)
160#define WARN(stuff...) printf("WARNING udc: " stuff)
161#define INFO(stuff...) printf("INFO udc: " stuff)
162
163extern void otg_phy_init(struct s3c_udc *dev);
164extern void otg_phy_off(struct s3c_udc *dev);
165
166extern void s3c_udc_ep_set_stall(struct s3c_ep *ep);
167extern int s3c_udc_probe(struct s3c_plat_otg_data *pdata);
168
169struct s3c_plat_otg_data {
170 int (*phy_control)(int on);
171 unsigned int regs_phy;
172 unsigned int regs_otg;
173 unsigned int usb_phy_ctrl;
174 unsigned int usb_flags;
175};
176#endif