1 /* cyangadget.h - Linux USB Gadget driver file for the Cypress West Bridge
2 ## ===========================
3 ## Copyright (C) 2010 Cypress Semiconductor
5 ## This program is free software; you can redistribute it and/or
6 ## modify it under the terms of the GNU General Public License
7 ## as published by the Free Software Foundation; either version 2
8 ## of the License, or (at your option) any later version.
10 ## This program is distributed in the hope that it will be useful,
11 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 ## GNU General Public License for more details.
15 ## You should have received a copy of the GNU General Public License
16 ## along with this program; if not, write to the Free Software
17 ## Foundation, Inc., 51 Franklin Street, Fifth Floor
18 ## Boston, MA 02110-1301, USA.
19 ## ===========================
23 * Cypress West Bridge high/full speed USB device controller code
24 * Based on the Netchip 2280 device controller by David Brownell
25 * in the linux 2.6.10 kernel
27 * linux/drivers/usb/gadget/net2280.h
31 * Copyright (C) 2002 NetChip Technology, Inc. (http://www.netchip.com)
32 * Copyright (C) 2003 David Brownell
34 * This program is free software; you can redistribute it and/or modify
35 * it under the terms of the GNU General Public License as published by
36 * the Free Software Foundation; either version 2 of the License, or
37 * (at your option) any later version.
39 * This program is distributed in the hope that it will be useful,
40 * but WITHOUT ANY WARRANTY; without even the implied warranty of
41 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
42 * GNU General Public License for more details.
44 * You should have received a copy of the GNU General Public License
45 * along with this program; if not, write to the Free Software
46 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
49 #ifndef _INCLUDED_CYANGADGET_H_
50 #define _INCLUDED_CYANGADGET_H_
52 #include <linux/device.h>
53 #include <linux/moduleparam.h>
54 #include <linux/usb/ch9.h>
55 #include <linux/usb/gadget.h>
56 #include <linux/sched.h>
58 #include "../include/linux/westbridge/cyastoria.h"
59 #include "../include/linux/westbridge/cyashal.h"
60 #include "../include/linux/westbridge/cyasdevice.h"
61 #include "cyasgadget_ioctl.h"
63 #include <linux/module.h>
64 #include <linux/init.h>
66 /*char driver defines, revisit*/
67 #include <linux/module.h>
68 #include <linux/moduleparam.h>
69 #include <linux/init.h>
70 #include <linux/fs.h> /* everything... */
71 #include <linux/errno.h> /* error codes */
72 #include <linux/types.h> /* size_t */
73 #include <linux/proc_fs.h>
74 #include <linux/fcntl.h> /* O_ACCMODE */
75 #include <linux/seq_file.h>
76 #include <linux/cdev.h>
77 #include <linux/scatterlist.h>
78 #include <linux/pagemap.h>
79 #include <linux/vmalloc.h> /* vmalloc(), vfree */
80 #include <linux/msdos_fs.h> /*fat_alloc_cluster*/
81 #include <linux/buffer_head.h>
82 #include <asm/system.h> /* cli(), *_flags */
83 #include <linux/uaccess.h> /* copy_*_user */
85 extern int mpage_cleardirty(struct address_space *mapping, int num_pages);
86 extern int fat_get_block(struct inode *, sector_t , struct buffer_head *, int);
87 extern cy_as_device_handle *cyasdevice_getdevhandle(void);
89 /* Driver data structures and utilities */
90 typedef struct cyasgadget_ep {
91 struct usb_ep usb_ep_inst;
92 struct cyasgadget *dev;
94 /* analogous to a host-side qh */
95 struct list_head queue;
96 const struct usb_endpoint_descriptor *desc;
104 cy_as_usb_end_point_config cyepconfig;
107 typedef struct cyasgadget_req {
108 struct usb_request req;
109 struct list_head queue;
117 typedef struct cyasgadget {
118 /* each device provides one gadget, several endpoints */
119 struct usb_gadget gadget;
121 struct cyasgadget_ep an_gadget_ep[16];
122 struct usb_gadget_driver *driver;
123 /* Handle to the West Bridge device */
124 cy_as_device_handle dev_handle;
129 struct completion thread_complete;
130 wait_queue_head_t thread_wq;
131 struct semaphore thread_sem;
132 struct list_head thread_queue;
134 cy_bool tmtp_send_complete;
135 cy_bool tmtp_get_complete;
136 cy_bool tmtp_need_new_blk_tbl;
137 /* Data member used to store the SendObjectComplete event data */
138 cy_as_mtp_send_object_complete_data tmtp_send_complete_data;
139 /* Data member used to store the GetObjectComplete event data */
140 cy_as_mtp_get_object_complete_data tmtp_get_complete_data;
144 static inline void set_halt(cyasgadget_ep *ep)
149 static inline void clear_halt(cyasgadget_ep *ep)
154 #define xprintk(dev, level, fmt, args...) \
155 printk(level "%s %s: " fmt, driver_name, \
156 pci_name(dev->pdev), ## args)
160 #define DEBUG(dev, fmt, args...) \
161 xprintk(dev, KERN_DEBUG, fmt, ## args)
163 #define DEBUG(dev, fmt, args...) \
170 #define VDEBUG(dev, fmt, args...) \
174 #define ERROR(dev, fmt, args...) \
175 xprintk(dev, KERN_ERR, fmt, ## args)
176 #define GADG_WARN(dev, fmt, args...) \
177 xprintk(dev, KERN_WARNING, fmt, ## args)
178 #define INFO(dev, fmt, args...) \
179 xprintk(dev, KERN_INFO, fmt, ## args)
181 /*-------------------------------------------------------------------------*/
183 static inline void start_out_naking(struct cyasgadget_ep *ep)
188 static inline void stop_out_naking(struct cyasgadget_ep *ep)
193 #endif /* _INCLUDED_CYANGADGET_H_ */