gadget.c (47a1685f139271de401212bd69d17374ca5a5270) | gadget.c (f7c0b14351c483bdeb86a81d609e26263cb0dd30) |
---|---|
1/** 2 * linux/drivers/usb/gadget/s3c-hsotg.c 3 * 4 * Copyright (c) 2011 Samsung Electronics Co., Ltd. 5 * http://www.samsung.com 6 * 7 * Copyright 2008 Openmoko, Inc. 8 * Copyright 2008 Simtec Electronics --- 23 unchanged lines hidden (view full) --- 32#include <linux/of_platform.h> 33#include <linux/phy/phy.h> 34 35#include <linux/usb/ch9.h> 36#include <linux/usb/gadget.h> 37#include <linux/usb/phy.h> 38#include <linux/platform_data/s3c-hsotg.h> 39 | 1/** 2 * linux/drivers/usb/gadget/s3c-hsotg.c 3 * 4 * Copyright (c) 2011 Samsung Electronics Co., Ltd. 5 * http://www.samsung.com 6 * 7 * Copyright 2008 Openmoko, Inc. 8 * Copyright 2008 Simtec Electronics --- 23 unchanged lines hidden (view full) --- 32#include <linux/of_platform.h> 33#include <linux/phy/phy.h> 34 35#include <linux/usb/ch9.h> 36#include <linux/usb/gadget.h> 37#include <linux/usb/phy.h> 38#include <linux/platform_data/s3c-hsotg.h> 39 |
40#include "hw.h" | 40#include "core.h" |
41 | 41 |
42static const char * const s3c_hsotg_supply_names[] = { 43 "vusb_d", /* digital USB supply, 1.2V */ 44 "vusb_a", /* analog USB supply, 1.1V */ 45}; 46 47/* 48 * EP0_MPS_LIMIT 49 * 50 * Unfortunately there seems to be a limit of the amount of data that can 51 * be transferred by IN transactions on EP0. This is either 127 bytes or 3 52 * packets (which practically means 1 packet and 63 bytes of data) when the 53 * MPS is set to 64. 54 * 55 * This means if we are wanting to move >127 bytes of data, we need to 56 * split the transactions up, but just doing one packet at a time does 57 * not work (this may be an implicit DATA0 PID on first packet of the 58 * transaction) and doing 2 packets is outside the controller's limits. 59 * 60 * If we try to lower the MPS size for EP0, then no transfers work properly 61 * for EP0, and the system will fail basic enumeration. As no cause for this 62 * has currently been found, we cannot support any large IN transfers for 63 * EP0. 64 */ 65#define EP0_MPS_LIMIT 64 66 67struct s3c_hsotg; 68struct s3c_hsotg_req; 69 70/** 71 * struct s3c_hsotg_ep - driver endpoint definition. 72 * @ep: The gadget layer representation of the endpoint. 73 * @name: The driver generated name for the endpoint. 74 * @queue: Queue of requests for this endpoint. 75 * @parent: Reference back to the parent device structure. 76 * @req: The current request that the endpoint is processing. This is 77 * used to indicate an request has been loaded onto the endpoint 78 * and has yet to be completed (maybe due to data move, or simply 79 * awaiting an ack from the core all the data has been completed). 80 * @debugfs: File entry for debugfs file for this endpoint. 81 * @lock: State lock to protect contents of endpoint. 82 * @dir_in: Set to true if this endpoint is of the IN direction, which 83 * means that it is sending data to the Host. 84 * @index: The index for the endpoint registers. 85 * @mc: Multi Count - number of transactions per microframe 86 * @interval - Interval for periodic endpoints 87 * @name: The name array passed to the USB core. 88 * @halted: Set if the endpoint has been halted. 89 * @periodic: Set if this is a periodic ep, such as Interrupt 90 * @isochronous: Set if this is a isochronous ep 91 * @sent_zlp: Set if we've sent a zero-length packet. 92 * @total_data: The total number of data bytes done. 93 * @fifo_size: The size of the FIFO (for periodic IN endpoints) 94 * @fifo_load: The amount of data loaded into the FIFO (periodic IN) 95 * @last_load: The offset of data for the last start of request. 96 * @size_loaded: The last loaded size for DxEPTSIZE for periodic IN 97 * 98 * This is the driver's state for each registered enpoint, allowing it 99 * to keep track of transactions that need doing. Each endpoint has a 100 * lock to protect the state, to try and avoid using an overall lock 101 * for the host controller as much as possible. 102 * 103 * For periodic IN endpoints, we have fifo_size and fifo_load to try 104 * and keep track of the amount of data in the periodic FIFO for each 105 * of these as we don't have a status register that tells us how much 106 * is in each of them. (note, this may actually be useless information 107 * as in shared-fifo mode periodic in acts like a single-frame packet 108 * buffer than a fifo) 109 */ 110struct s3c_hsotg_ep { 111 struct usb_ep ep; 112 struct list_head queue; 113 struct s3c_hsotg *parent; 114 struct s3c_hsotg_req *req; 115 struct dentry *debugfs; 116 117 118 unsigned long total_data; 119 unsigned int size_loaded; 120 unsigned int last_load; 121 unsigned int fifo_load; 122 unsigned short fifo_size; 123 124 unsigned char dir_in; 125 unsigned char index; 126 unsigned char mc; 127 unsigned char interval; 128 129 unsigned int halted:1; 130 unsigned int periodic:1; 131 unsigned int isochronous:1; 132 unsigned int sent_zlp:1; 133 134 char name[10]; 135}; 136 137/** 138 * struct s3c_hsotg - driver state. 139 * @dev: The parent device supplied to the probe function 140 * @driver: USB gadget driver 141 * @phy: The otg phy transceiver structure for phy control. 142 * @uphy: The otg phy transceiver structure for old USB phy control. 143 * @plat: The platform specific configuration data. This can be removed once 144 * all SoCs support usb transceiver. 145 * @regs: The memory area mapped for accessing registers. 146 * @irq: The IRQ number we are using 147 * @supplies: Definition of USB power supplies 148 * @phyif: PHY interface width 149 * @dedicated_fifos: Set if the hardware has dedicated IN-EP fifos. 150 * @num_of_eps: Number of available EPs (excluding EP0) 151 * @debug_root: root directrory for debugfs. 152 * @debug_file: main status file for debugfs. 153 * @debug_fifo: FIFO status file for debugfs. 154 * @ep0_reply: Request used for ep0 reply. 155 * @ep0_buff: Buffer for EP0 reply data, if needed. 156 * @ctrl_buff: Buffer for EP0 control requests. 157 * @ctrl_req: Request for EP0 control packets. 158 * @setup: NAK management for EP0 SETUP 159 * @last_rst: Time of last reset 160 * @eps: The endpoints being supplied to the gadget framework 161 */ 162struct s3c_hsotg { 163 struct device *dev; 164 struct usb_gadget_driver *driver; 165 struct phy *phy; 166 struct usb_phy *uphy; 167 struct s3c_hsotg_plat *plat; 168 169 spinlock_t lock; 170 171 void __iomem *regs; 172 int irq; 173 struct clk *clk; 174 175 struct regulator_bulk_data supplies[ARRAY_SIZE(s3c_hsotg_supply_names)]; 176 177 u32 phyif; 178 unsigned int dedicated_fifos:1; 179 unsigned char num_of_eps; 180 181 struct dentry *debug_root; 182 struct dentry *debug_file; 183 struct dentry *debug_fifo; 184 185 struct usb_request *ep0_reply; 186 struct usb_request *ctrl_req; 187 u8 ep0_buff[8]; 188 u8 ctrl_buff[8]; 189 190 struct usb_gadget gadget; 191 unsigned int setup; 192 unsigned long last_rst; 193 struct s3c_hsotg_ep *eps; 194}; 195 196/** 197 * struct s3c_hsotg_req - data transfer request 198 * @req: The USB gadget request 199 * @queue: The list of requests for the endpoint this is queued for. 200 * @in_progress: Has already had size/packets written to core 201 * @mapped: DMA buffer for this request has been mapped via dma_map_single(). 202 */ 203struct s3c_hsotg_req { 204 struct usb_request req; 205 struct list_head queue; 206 unsigned char in_progress; 207 unsigned char mapped; 208}; 209 | |
210/* conversion functions */ 211static inline struct s3c_hsotg_req *our_req(struct usb_request *req) 212{ 213 return container_of(req, struct s3c_hsotg_req, req); 214} 215 216static inline struct s3c_hsotg_ep *our_ep(struct usb_ep *ep) 217{ --- 1943 unchanged lines hidden (view full) --- 2161 s3c_hsotg_complete_request(hsotg, ep, req, 2162 result); 2163 } 2164 if(hsotg->dedicated_fifos) 2165 if ((readl(hsotg->regs + DTXFSTS(ep->index)) & 0xffff) * 4 < 3072) 2166 s3c_hsotg_txfifo_flush(hsotg, ep->index); 2167} 2168 | 42/* conversion functions */ 43static inline struct s3c_hsotg_req *our_req(struct usb_request *req) 44{ 45 return container_of(req, struct s3c_hsotg_req, req); 46} 47 48static inline struct s3c_hsotg_ep *our_ep(struct usb_ep *ep) 49{ --- 1943 unchanged lines hidden (view full) --- 1993 s3c_hsotg_complete_request(hsotg, ep, req, 1994 result); 1995 } 1996 if(hsotg->dedicated_fifos) 1997 if ((readl(hsotg->regs + DTXFSTS(ep->index)) & 0xffff) * 4 < 3072) 1998 s3c_hsotg_txfifo_flush(hsotg, ep->index); 1999} 2000 |
2169#define call_gadget(_hs, _entry) \ 2170do { \ 2171 if ((_hs)->gadget.speed != USB_SPEED_UNKNOWN && \ 2172 (_hs)->driver && (_hs)->driver->_entry) { \ 2173 spin_unlock(&_hs->lock); \ 2174 (_hs)->driver->_entry(&(_hs)->gadget); \ 2175 spin_lock(&_hs->lock); \ 2176 } \ 2177} while (0) 2178 | |
2179/** 2180 * s3c_hsotg_disconnect - disconnect service 2181 * @hsotg: The device state. 2182 * 2183 * The device has been disconnected. Remove all current 2184 * transactions and signal the gadget driver that this 2185 * has happened. 2186 */ --- 1664 unchanged lines hidden --- | 2001/** 2002 * s3c_hsotg_disconnect - disconnect service 2003 * @hsotg: The device state. 2004 * 2005 * The device has been disconnected. Remove all current 2006 * transactions and signal the gadget driver that this 2007 * has happened. 2008 */ --- 1664 unchanged lines hidden --- |