// SPDX-License-Identifier: GPL-2.0+ /* * Handles the Intel 27x USB Device Controller (UDC) * * Inspired by original driver by Frank Becker, David Brownell, and others. * Copyright (C) 2008 Robert Jarzmik */ #include <linux/module.h> #include <linux/kernel.h> #include <linux/types.h> #include <linux/errno.h> #include <linux/err.h> #include <linux/platform_device.h> #include <linux/delay.h> #include <linux/list.h> #include <linux/interrupt.h> #include <linux/proc_fs.h> #include <linux/clk.h> #include <linux/irq.h> #include <linux/gpio.h> #include <linux/gpio/consumer.h> #include <linux/slab.h> #include <linux/prefetch.h> #include <linux/byteorder/generic.h> #include <linux/platform_data/pxa2xx_udc.h> #include <linux/of.h> #include <linux/usb.h> #include <linux/usb/ch9.h> #include <linux/usb/gadget.h> #include <linux/usb/phy.h> #include "pxa27x_udc.h" /* * This driver handles the USB Device Controller (UDC) in Intel's PXA 27x * series processors. * * Such controller drivers work with a gadget driver. The gadget driver * returns descriptors, implements configuration and data protocols used * by the host to interact with this device, and allocates endpoints to * the different protocol interfaces. The controller driver virtualizes * usb hardware so that the gadget drivers will be more portable. * * This UDC hardware wants to implement a bit too much USB protocol. The * biggest issues are: that the endpoints have to be set up before the * controller can be enabled (minor, and not uncommon); and each endpoint * can only have one configuration, interface and alternative interface * number (major, and very unusual). Once set up, these cannot be changed * without a controller reset. * * The workaround is to setup all combinations necessary for the gadgets which * will work with this driver. This is done in pxa_udc structure, statically. * See pxa_udc, udc_usb_ep versus pxa_ep, and matching function find_pxa_ep. * (You could modify this if needed. Some drivers have a "fifo_mode" module * parameter to facilitate such changes.) * * The combinations have been tested with these gadgets : * - zero gadget * - file storage gadget * - ether gadget * * The driver doesn't use DMA, only IO access and IRQ callbacks. No use is * made of UDC's double buffering either. USB "On-The-Go" is not implemented. * * All the requests are handled the same way : * - the drivers tries to handle the request directly to the IO * - if the IO fifo is not big enough, the remaining is send/received in * interrupt handling. */ #define DRIVER_VERSION … #define DRIVER_DESC … static const char driver_name[] = …; static struct pxa_udc *the_controller; static void handle_ep(struct pxa_ep *ep); /* * Debug filesystem */ #ifdef CONFIG_USB_GADGET_DEBUG_FS #include <linux/debugfs.h> #include <linux/uaccess.h> #include <linux/seq_file.h> static int state_dbg_show(struct seq_file *s, void *p) { … } DEFINE_SHOW_ATTRIBUTE(…); static int queues_dbg_show(struct seq_file *s, void *p) { … } DEFINE_SHOW_ATTRIBUTE(…); static int eps_dbg_show(struct seq_file *s, void *p) { … } DEFINE_SHOW_ATTRIBUTE(…); static void pxa_init_debugfs(struct pxa_udc *udc) { … } static void pxa_cleanup_debugfs(struct pxa_udc *udc) { … } #else static inline void pxa_init_debugfs(struct pxa_udc *udc) { } static inline void pxa_cleanup_debugfs(struct pxa_udc *udc) { } #endif /** * is_match_usb_pxa - check if usb_ep and pxa_ep match * @udc_usb_ep: usb endpoint * @ep: pxa endpoint * @config: configuration required in pxa_ep * @interface: interface required in pxa_ep * @altsetting: altsetting required in pxa_ep * * Returns 1 if all criteria match between pxa and usb endpoint, 0 otherwise */ static int is_match_usb_pxa(struct udc_usb_ep *udc_usb_ep, struct pxa_ep *ep, int config, int interface, int altsetting) { … } /** * find_pxa_ep - find pxa_ep structure matching udc_usb_ep * @udc: pxa udc * @udc_usb_ep: udc_usb_ep structure * * Match udc_usb_ep and all pxa_ep available, to see if one matches. * This is necessary because of the strong pxa hardware restriction requiring * that once pxa endpoints are initialized, their configuration is freezed, and * no change can be made to their address, direction, or in which configuration, * interface or altsetting they are active ... which differs from more usual * models which have endpoints be roughly just addressable fifos, and leave * configuration events up to gadget drivers (like all control messages). * * Note that there is still a blurred point here : * - we rely on UDCCR register "active interface" and "active altsetting". * This is a nonsense in regard of USB spec, where multiple interfaces are * active at the same time. * - if we knew for sure that the pxa can handle multiple interface at the * same time, assuming Intel's Developer Guide is wrong, this function * should be reviewed, and a cache of couples (iface, altsetting) should * be kept in the pxa_udc structure. In this case this function would match * against the cache of couples instead of the "last altsetting" set up. * * Returns the matched pxa_ep structure or NULL if none found */ static struct pxa_ep *find_pxa_ep(struct pxa_udc *udc, struct udc_usb_ep *udc_usb_ep) { … } /** * update_pxa_ep_matches - update pxa_ep cached values in all udc_usb_ep * @udc: pxa udc * * Context: interrupt handler * * Updates all pxa_ep fields in udc_usb_ep structures, if this field was * previously set up (and is not NULL). The update is necessary is a * configuration change or altsetting change was issued by the USB host. */ static void update_pxa_ep_matches(struct pxa_udc *udc) { … } /** * pio_irq_enable - Enables irq generation for one endpoint * @ep: udc endpoint */ static void pio_irq_enable(struct pxa_ep *ep) { … } /** * pio_irq_disable - Disables irq generation for one endpoint * @ep: udc endpoint */ static void pio_irq_disable(struct pxa_ep *ep) { … } /** * udc_set_mask_UDCCR - set bits in UDCCR * @udc: udc device * @mask: bits to set in UDCCR * * Sets bits in UDCCR, leaving DME and FST bits as they were. */ static inline void udc_set_mask_UDCCR(struct pxa_udc *udc, int mask) { … } /** * udc_clear_mask_UDCCR - clears bits in UDCCR * @udc: udc device * @mask: bit to clear in UDCCR * * Clears bits in UDCCR, leaving DME and FST bits as they were. */ static inline void udc_clear_mask_UDCCR(struct pxa_udc *udc, int mask) { … } /** * ep_write_UDCCSR - set bits in UDCCSR * @ep: udc endpoint * @mask: bits to set in UDCCR * * Sets bits in UDCCSR (UDCCSR0 and UDCCSR*). * * A specific case is applied to ep0 : the ACM bit is always set to 1, for * SET_INTERFACE and SET_CONFIGURATION. */ static inline void ep_write_UDCCSR(struct pxa_ep *ep, int mask) { … } /** * ep_count_bytes_remain - get how many bytes in udc endpoint * @ep: udc endpoint * * Returns number of bytes in OUT fifos. Broken for IN fifos (-EOPNOTSUPP) */ static int ep_count_bytes_remain(struct pxa_ep *ep) { … } /** * ep_is_empty - checks if ep has byte ready for reading * @ep: udc endpoint * * If endpoint is the control endpoint, checks if there are bytes in the * control endpoint fifo. If endpoint is a data endpoint, checks if bytes * are ready for reading on OUT endpoint. * * Returns 0 if ep not empty, 1 if ep empty, -EOPNOTSUPP if IN endpoint */ static int ep_is_empty(struct pxa_ep *ep) { … } /** * ep_is_full - checks if ep has place to write bytes * @ep: udc endpoint * * If endpoint is not the control endpoint and is an IN endpoint, checks if * there is place to write bytes into the endpoint. * * Returns 0 if ep not full, 1 if ep full, -EOPNOTSUPP if OUT endpoint */ static int ep_is_full(struct pxa_ep *ep) { … } /** * epout_has_pkt - checks if OUT endpoint fifo has a packet available * @ep: pxa endpoint * * Returns 1 if a complete packet is available, 0 if not, -EOPNOTSUPP for IN ep. */ static int epout_has_pkt(struct pxa_ep *ep) { … } /** * set_ep0state - Set ep0 automata state * @udc: udc device * @state: state */ static void set_ep0state(struct pxa_udc *udc, int state) { … } /** * ep0_idle - Put control endpoint into idle state * @dev: udc device */ static void ep0_idle(struct pxa_udc *dev) { … } /** * inc_ep_stats_reqs - Update ep stats counts * @ep: physical endpoint * @is_in: ep direction (USB_DIR_IN or 0) * */ static void inc_ep_stats_reqs(struct pxa_ep *ep, int is_in) { … } /** * inc_ep_stats_bytes - Update ep stats counts * @ep: physical endpoint * @count: bytes transferred on endpoint * @is_in: ep direction (USB_DIR_IN or 0) */ static void inc_ep_stats_bytes(struct pxa_ep *ep, int count, int is_in) { … } /** * pxa_ep_setup - Sets up an usb physical endpoint * @ep: pxa27x physical endpoint * * Find the physical pxa27x ep, and setup its UDCCR */ static void pxa_ep_setup(struct pxa_ep *ep) { … } /** * pxa_eps_setup - Sets up all usb physical endpoints * @dev: udc device * * Setup all pxa physical endpoints, except ep0 */ static void pxa_eps_setup(struct pxa_udc *dev) { … } /** * pxa_ep_alloc_request - Allocate usb request * @_ep: usb endpoint * @gfp_flags: * * For the pxa27x, these can just wrap kmalloc/kfree. gadget drivers * must still pass correctly initialized endpoints, since other controller * drivers may care about how it's currently set up (dma issues etc). */ static struct usb_request * pxa_ep_alloc_request(struct usb_ep *_ep, gfp_t gfp_flags) { … } /** * pxa_ep_free_request - Free usb request * @_ep: usb endpoint * @_req: usb request * * Wrapper around kfree to free _req */ static void pxa_ep_free_request(struct usb_ep *_ep, struct usb_request *_req) { … } /** * ep_add_request - add a request to the endpoint's queue * @ep: usb endpoint * @req: usb request * * Context: ep->lock held * * Queues the request in the endpoint's queue, and enables the interrupts * on the endpoint. */ static void ep_add_request(struct pxa_ep *ep, struct pxa27x_request *req) { … } /** * ep_del_request - removes a request from the endpoint's queue * @ep: usb endpoint * @req: usb request * * Context: ep->lock held * * Unqueue the request from the endpoint's queue. If there are no more requests * on the endpoint, and if it's not the control endpoint, interrupts are * disabled on the endpoint. */ static void ep_del_request(struct pxa_ep *ep, struct pxa27x_request *req) { … } /** * req_done - Complete an usb request * @ep: pxa physical endpoint * @req: pxa request * @status: usb request status sent to gadget API * @pflags: flags of previous spinlock_irq_save() or NULL if no lock held * * Context: ep->lock held if flags not NULL, else ep->lock released * * Retire a pxa27x usb request. Endpoint must be locked. */ static void req_done(struct pxa_ep *ep, struct pxa27x_request *req, int status, unsigned long *pflags) { … } /** * ep_end_out_req - Ends endpoint OUT request * @ep: physical endpoint * @req: pxa request * @pflags: flags of previous spinlock_irq_save() or NULL if no lock held * * Context: ep->lock held or released (see req_done()) * * Ends endpoint OUT request (completes usb request). */ static void ep_end_out_req(struct pxa_ep *ep, struct pxa27x_request *req, unsigned long *pflags) { … } /** * ep0_end_out_req - Ends control endpoint OUT request (ends data stage) * @ep: physical endpoint * @req: pxa request * @pflags: flags of previous spinlock_irq_save() or NULL if no lock held * * Context: ep->lock held or released (see req_done()) * * Ends control endpoint OUT request (completes usb request), and puts * control endpoint into idle state */ static void ep0_end_out_req(struct pxa_ep *ep, struct pxa27x_request *req, unsigned long *pflags) { … } /** * ep_end_in_req - Ends endpoint IN request * @ep: physical endpoint * @req: pxa request * @pflags: flags of previous spinlock_irq_save() or NULL if no lock held * * Context: ep->lock held or released (see req_done()) * * Ends endpoint IN request (completes usb request). */ static void ep_end_in_req(struct pxa_ep *ep, struct pxa27x_request *req, unsigned long *pflags) { … } /** * ep0_end_in_req - Ends control endpoint IN request (ends data stage) * @ep: physical endpoint * @req: pxa request * @pflags: flags of previous spinlock_irq_save() or NULL if no lock held * * Context: ep->lock held or released (see req_done()) * * Ends control endpoint IN request (completes usb request), and puts * control endpoint into status state */ static void ep0_end_in_req(struct pxa_ep *ep, struct pxa27x_request *req, unsigned long *pflags) { … } /** * nuke - Dequeue all requests * @ep: pxa endpoint * @status: usb request status * * Context: ep->lock released * * Dequeues all requests on an endpoint. As a side effect, interrupts will be * disabled on that endpoint (because no more requests). */ static void nuke(struct pxa_ep *ep, int status) { … } /** * read_packet - transfer 1 packet from an OUT endpoint into request * @ep: pxa physical endpoint * @req: usb request * * Takes bytes from OUT endpoint and transfers them info the usb request. * If there is less space in request than bytes received in OUT endpoint, * bytes are left in the OUT endpoint. * * Returns how many bytes were actually transferred */ static int read_packet(struct pxa_ep *ep, struct pxa27x_request *req) { … } /** * write_packet - transfer 1 packet from request into an IN endpoint * @ep: pxa physical endpoint * @req: usb request * @max: max bytes that fit into endpoint * * Takes bytes from usb request, and transfers them into the physical * endpoint. If there are no bytes to transfer, doesn't write anything * to physical endpoint. * * Returns how many bytes were actually transferred. */ static int write_packet(struct pxa_ep *ep, struct pxa27x_request *req, unsigned int max) { … } /** * read_fifo - Transfer packets from OUT endpoint into usb request * @ep: pxa physical endpoint * @req: usb request * * Context: interrupt handler * * Unload as many packets as possible from the fifo we use for usb OUT * transfers and put them into the request. Caller should have made sure * there's at least one packet ready. * Doesn't complete the request, that's the caller's job * * Returns 1 if the request completed, 0 otherwise */ static int read_fifo(struct pxa_ep *ep, struct pxa27x_request *req) { … } /** * write_fifo - transfer packets from usb request into an IN endpoint * @ep: pxa physical endpoint * @req: pxa usb request * * Write to an IN endpoint fifo, as many packets as possible. * irqs will use this to write the rest later. * caller guarantees at least one packet buffer is ready (or a zlp). * Doesn't complete the request, that's the caller's job * * Returns 1 if request fully transferred, 0 if partial transfer */ static int write_fifo(struct pxa_ep *ep, struct pxa27x_request *req) { … } /** * read_ep0_fifo - Transfer packets from control endpoint into usb request * @ep: control endpoint * @req: pxa usb request * * Special ep0 version of the above read_fifo. Reads as many bytes from control * endpoint as can be read, and stores them into usb request (limited by request * maximum length). * * Returns 0 if usb request only partially filled, 1 if fully filled */ static int read_ep0_fifo(struct pxa_ep *ep, struct pxa27x_request *req) { … } /** * write_ep0_fifo - Send a request to control endpoint (ep0 in) * @ep: control endpoint * @req: request * * Context: interrupt handler * * Sends a request (or a part of the request) to the control endpoint (ep0 in). * If the request doesn't fit, the remaining part will be sent from irq. * The request is considered fully written only if either : * - last write transferred all remaining bytes, but fifo was not fully filled * - last write was a 0 length write * * Returns 1 if request fully written, 0 if request only partially sent */ static int write_ep0_fifo(struct pxa_ep *ep, struct pxa27x_request *req) { … } /** * pxa_ep_queue - Queue a request into an IN endpoint * @_ep: usb endpoint * @_req: usb request * @gfp_flags: flags * * Context: thread context or from the interrupt handler in the * special case of ep0 setup : * (irq->handle_ep0_ctrl_req->gadget_setup->pxa_ep_queue) * * Returns 0 if succedeed, error otherwise */ static int pxa_ep_queue(struct usb_ep *_ep, struct usb_request *_req, gfp_t gfp_flags) { … } /** * pxa_ep_dequeue - Dequeue one request * @_ep: usb endpoint * @_req: usb request * * Return 0 if no error, -EINVAL or -ECONNRESET otherwise */ static int pxa_ep_dequeue(struct usb_ep *_ep, struct usb_request *_req) { … } /** * pxa_ep_set_halt - Halts operations on one endpoint * @_ep: usb endpoint * @value: * * Returns 0 if no error, -EINVAL, -EROFS, -EAGAIN otherwise */ static int pxa_ep_set_halt(struct usb_ep *_ep, int value) { … } /** * pxa_ep_fifo_status - Get how many bytes in physical endpoint * @_ep: usb endpoint * * Returns number of bytes in OUT fifos. Broken for IN fifos. */ static int pxa_ep_fifo_status(struct usb_ep *_ep) { … } /** * pxa_ep_fifo_flush - Flushes one endpoint * @_ep: usb endpoint * * Discards all data in one endpoint(IN or OUT), except control endpoint. */ static void pxa_ep_fifo_flush(struct usb_ep *_ep) { … } /** * pxa_ep_enable - Enables usb endpoint * @_ep: usb endpoint * @desc: usb endpoint descriptor * * Nothing much to do here, as ep configuration is done once and for all * before udc is enabled. After udc enable, no physical endpoint configuration * can be changed. * Function makes sanity checks and flushes the endpoint. */ static int pxa_ep_enable(struct usb_ep *_ep, const struct usb_endpoint_descriptor *desc) { … } /** * pxa_ep_disable - Disable usb endpoint * @_ep: usb endpoint * * Same as for pxa_ep_enable, no physical endpoint configuration can be * changed. * Function flushes the endpoint and related requests. */ static int pxa_ep_disable(struct usb_ep *_ep) { … } static const struct usb_ep_ops pxa_ep_ops = …; /** * dplus_pullup - Connect or disconnect pullup resistor to D+ pin * @udc: udc device * @on: 0 if disconnect pullup resistor, 1 otherwise * Context: any * * Handle D+ pullup resistor, make the device visible to the usb bus, and * declare it as a full speed usb device */ static void dplus_pullup(struct pxa_udc *udc, int on) { … } /** * pxa_udc_get_frame - Returns usb frame number * @_gadget: usb gadget */ static int pxa_udc_get_frame(struct usb_gadget *_gadget) { … } /** * pxa_udc_wakeup - Force udc device out of suspend * @_gadget: usb gadget * * Returns 0 if successful, error code otherwise */ static int pxa_udc_wakeup(struct usb_gadget *_gadget) { … } static void udc_enable(struct pxa_udc *udc); static void udc_disable(struct pxa_udc *udc); /** * should_enable_udc - Tells if UDC should be enabled * @udc: udc device * Context: any * * The UDC should be enabled if : * - the pullup resistor is connected * - and a gadget driver is bound * - and vbus is sensed (or no vbus sense is available) * * Returns 1 if UDC should be enabled, 0 otherwise */ static int should_enable_udc(struct pxa_udc *udc) { … } /** * should_disable_udc - Tells if UDC should be disabled * @udc: udc device * Context: any * * The UDC should be disabled if : * - the pullup resistor is not connected * - or no gadget driver is bound * - or no vbus is sensed (when vbus sesing is available) * * Returns 1 if UDC should be disabled */ static int should_disable_udc(struct pxa_udc *udc) { … } /** * pxa_udc_pullup - Offer manual D+ pullup control * @_gadget: usb gadget using the control * @is_active: 0 if disconnect, else connect D+ pullup resistor * * Context: task context, might sleep * * Returns 0 if OK, -EOPNOTSUPP if udc driver doesn't handle D+ pullup */ static int pxa_udc_pullup(struct usb_gadget *_gadget, int is_active) { … } /** * pxa_udc_vbus_session - Called by external transceiver to enable/disable udc * @_gadget: usb gadget * @is_active: 0 if should disable the udc, 1 if should enable * * Enables the udc, and optionnaly activates D+ pullup resistor. Or disables the * udc, and deactivates D+ pullup resistor. * * Returns 0 */ static int pxa_udc_vbus_session(struct usb_gadget *_gadget, int is_active) { … } /** * pxa_udc_vbus_draw - Called by gadget driver after SET_CONFIGURATION completed * @_gadget: usb gadget * @mA: current drawn * * Context: task context, might sleep * * Called after a configuration was chosen by a USB host, to inform how much * current can be drawn by the device from VBus line. * * Returns 0 or -EOPNOTSUPP if no transceiver is handling the udc */ static int pxa_udc_vbus_draw(struct usb_gadget *_gadget, unsigned mA) { … } /** * pxa_udc_phy_event - Called by phy upon VBus event * @nb: notifier block * @action: phy action, is vbus connect or disconnect * @data: the usb_gadget structure in pxa_udc * * Called by the USB Phy when a cable connect or disconnect is sensed. * * Returns 0 */ static int pxa_udc_phy_event(struct notifier_block *nb, unsigned long action, void *data) { … } static struct notifier_block pxa27x_udc_phy = …; static int pxa27x_udc_start(struct usb_gadget *g, struct usb_gadget_driver *driver); static int pxa27x_udc_stop(struct usb_gadget *g); static const struct usb_gadget_ops pxa_udc_ops = …; /** * udc_disable - disable udc device controller * @udc: udc device * Context: any * * Disables the udc device : disables clocks, udc interrupts, control endpoint * interrupts. */ static void udc_disable(struct pxa_udc *udc) { … } /** * udc_init_data - Initialize udc device data structures * @dev: udc device * * Initializes gadget endpoint list, endpoints locks. No action is taken * on the hardware. */ static void udc_init_data(struct pxa_udc *dev) { … } /** * udc_enable - Enables the udc device * @udc: udc device * * Enables the udc device : enables clocks, udc interrupts, control endpoint * interrupts, sets usb as UDC client and setups endpoints. */ static void udc_enable(struct pxa_udc *udc) { … } /** * pxa27x_udc_start - Register gadget driver * @g: gadget * @driver: gadget driver * * When a driver is successfully registered, it will receive control requests * including set_configuration(), which enables non-control requests. Then * usb traffic follows until a disconnect is reported. Then a host may connect * again, or the driver might get unbound. * * Note that the udc is not automatically enabled. Check function * should_enable_udc(). * * Returns 0 if no error, -EINVAL, -ENODEV, -EBUSY otherwise */ static int pxa27x_udc_start(struct usb_gadget *g, struct usb_gadget_driver *driver) { … } /** * stop_activity - Stops udc endpoints * @udc: udc device * * Disables all udc endpoints (even control endpoint), report disconnect to * the gadget user. */ static void stop_activity(struct pxa_udc *udc) { … } /** * pxa27x_udc_stop - Unregister the gadget driver * @g: gadget * * Returns 0 if no error, -ENODEV, -EINVAL otherwise */ static int pxa27x_udc_stop(struct usb_gadget *g) { … } /** * handle_ep0_ctrl_req - handle control endpoint control request * @udc: udc device * @req: control request */ static void handle_ep0_ctrl_req(struct pxa_udc *udc, struct pxa27x_request *req) { … } /** * handle_ep0 - Handle control endpoint data transfers * @udc: udc device * @fifo_irq: 1 if triggered by fifo service type irq * @opc_irq: 1 if triggered by output packet complete type irq * * Context : interrupt handler * * Tries to transfer all pending request data into the endpoint and/or * transfer all pending data in the endpoint into usb requests. * Handles states of ep0 automata. * * PXA27x hardware handles several standard usb control requests without * driver notification. The requests fully handled by hardware are : * SET_ADDRESS, SET_FEATURE, CLEAR_FEATURE, GET_CONFIGURATION, GET_INTERFACE, * GET_STATUS * The requests handled by hardware, but with irq notification are : * SYNCH_FRAME, SET_CONFIGURATION, SET_INTERFACE * The remaining standard requests really handled by handle_ep0 are : * GET_DESCRIPTOR, SET_DESCRIPTOR, specific requests. * Requests standardized outside of USB 2.0 chapter 9 are handled more * uniformly, by gadget drivers. * * The control endpoint state machine is _not_ USB spec compliant, it's even * hardly compliant with Intel PXA270 developers guide. * The key points which inferred this state machine are : * - on every setup token, bit UDCCSR0_SA is raised and held until cleared by * software. * - on every OUT packet received, UDCCSR0_OPC is raised and held until * cleared by software. * - clearing UDCCSR0_OPC always flushes ep0. If in setup stage, never do it * before reading ep0. * This is true only for PXA27x. This is not true anymore for PXA3xx family * (check Back-to-Back setup packet in developers guide). * - irq can be called on a "packet complete" event (opc_irq=1), while * UDCCSR0_OPC is not yet raised (delta can be as big as 100ms * from experimentation). * - as UDCCSR0_SA can be activated while in irq handling, and clearing * UDCCSR0_OPC would flush the setup data, we almost never clear UDCCSR0_OPC * => we never actually read the "status stage" packet of an IN data stage * => this is not documented in Intel documentation * - hardware as no idea of STATUS STAGE, it only handle SETUP STAGE and DATA * STAGE. The driver add STATUS STAGE to send last zero length packet in * OUT_STATUS_STAGE. * - special attention was needed for IN_STATUS_STAGE. If a packet complete * event is detected, we terminate the status stage without ackowledging the * packet (not to risk to loose a potential SETUP packet) */ static void handle_ep0(struct pxa_udc *udc, int fifo_irq, int opc_irq) { … } /** * handle_ep - Handle endpoint data tranfers * @ep: pxa physical endpoint * * Tries to transfer all pending request data into the endpoint and/or * transfer all pending data in the endpoint into usb requests. * * Is always called from the interrupt handler. ep->lock must not be held. */ static void handle_ep(struct pxa_ep *ep) { … } /** * pxa27x_change_configuration - Handle SET_CONF usb request notification * @udc: udc device * @config: usb configuration * * Post the request to upper level. * Don't use any pxa specific harware configuration capabilities */ static void pxa27x_change_configuration(struct pxa_udc *udc, int config) { … } /** * pxa27x_change_interface - Handle SET_INTERF usb request notification * @udc: udc device * @iface: interface number * @alt: alternate setting number * * Post the request to upper level. * Don't use any pxa specific harware configuration capabilities */ static void pxa27x_change_interface(struct pxa_udc *udc, int iface, int alt) { … } /* * irq_handle_data - Handle data transfer * @irq: irq IRQ number * @udc: dev pxa_udc device structure * * Called from irq handler, transferts data to or from endpoint to queue */ static void irq_handle_data(int irq, struct pxa_udc *udc) { … } /** * irq_udc_suspend - Handle IRQ "UDC Suspend" * @udc: udc device */ static void irq_udc_suspend(struct pxa_udc *udc) { … } /** * irq_udc_resume - Handle IRQ "UDC Resume" * @udc: udc device */ static void irq_udc_resume(struct pxa_udc *udc) { … } /** * irq_udc_reconfig - Handle IRQ "UDC Change Configuration" * @udc: udc device */ static void irq_udc_reconfig(struct pxa_udc *udc) { … } /** * irq_udc_reset - Handle IRQ "UDC Reset" * @udc: udc device */ static void irq_udc_reset(struct pxa_udc *udc) { … } /** * pxa_udc_irq - Main irq handler * @irq: irq number * @_dev: udc device * * Handles all udc interrupts */ static irqreturn_t pxa_udc_irq(int irq, void *_dev) { … } static struct pxa_udc memory = …; #if defined(CONFIG_OF) static const struct of_device_id udc_pxa_dt_ids[] = …; MODULE_DEVICE_TABLE(of, udc_pxa_dt_ids); #endif /** * pxa_udc_probe - probes the udc device * @pdev: platform device * * Perform basic init : allocates udc clock, creates sysfs files, requests * irq. */ static int pxa_udc_probe(struct platform_device *pdev) { … } /** * pxa_udc_remove - removes the udc device driver * @_dev: platform device */ static void pxa_udc_remove(struct platform_device *_dev) { … } static void pxa_udc_shutdown(struct platform_device *_dev) { … } #ifdef CONFIG_PM /** * pxa_udc_suspend - Suspend udc device * @_dev: platform device * @state: suspend state * * Suspends udc : saves configuration registers (UDCCR*), then disables the udc * device. */ static int pxa_udc_suspend(struct platform_device *_dev, pm_message_t state) { … } /** * pxa_udc_resume - Resume udc device * @_dev: platform device * * Resumes udc : restores configuration registers (UDCCR*), then enables the udc * device. */ static int pxa_udc_resume(struct platform_device *_dev) { … } #endif /* work with hotplug and coldplug */ MODULE_ALIAS(…) …; static struct platform_driver udc_driver = …; module_platform_driver(…) …; MODULE_DESCRIPTION(…); MODULE_AUTHOR(…) …; MODULE_LICENSE(…) …;