Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 /*
0003  * Driver for the NXP ISP1761 device controller
0004  *
0005  * Copyright 2021 Linaro, Rui Miguel Silva
0006  * Copyright 2014 Ideas on Board Oy
0007  *
0008  * Contacts:
0009  *  Laurent Pinchart <laurent.pinchart@ideasonboard.com>
0010  *  Rui Miguel Silva <rui.silva@linaro.org>
0011  */
0012 
0013 #ifndef _ISP1760_UDC_H_
0014 #define _ISP1760_UDC_H_
0015 
0016 #include <linux/ioport.h>
0017 #include <linux/list.h>
0018 #include <linux/spinlock.h>
0019 #include <linux/timer.h>
0020 #include <linux/usb/gadget.h>
0021 
0022 #include "isp1760-regs.h"
0023 
0024 struct isp1760_device;
0025 struct isp1760_udc;
0026 
0027 enum isp1760_ctrl_state {
0028     ISP1760_CTRL_SETUP,     /* Waiting for a SETUP transaction */
0029     ISP1760_CTRL_DATA_IN,       /* Setup received, data IN stage */
0030     ISP1760_CTRL_DATA_OUT,      /* Setup received, data OUT stage */
0031     ISP1760_CTRL_STATUS,        /* 0-length request in status stage */
0032 };
0033 
0034 struct isp1760_ep {
0035     struct isp1760_udc *udc;
0036     struct usb_ep ep;
0037 
0038     struct list_head queue;
0039 
0040     unsigned int addr;
0041     unsigned int maxpacket;
0042     char name[7];
0043 
0044     const struct usb_endpoint_descriptor *desc;
0045 
0046     bool rx_pending;
0047     bool halted;
0048     bool wedged;
0049 };
0050 
0051 /**
0052  * struct isp1760_udc - UDC state information
0053  * irq: IRQ number
0054  * irqname: IRQ name (as passed to request_irq)
0055  * regs: regmap for UDC registers
0056  * driver: Gadget driver
0057  * gadget: Gadget device
0058  * lock: Protects driver, vbus_timer, ep, ep0_*, DC_EPINDEX register
0059  * ep: Array of endpoints
0060  * ep0_state: Control request state for endpoint 0
0061  * ep0_dir: Direction of the current control request
0062  * ep0_length: Length of the current control request
0063  * connected: Tracks gadget driver bus connection state
0064  */
0065 struct isp1760_udc {
0066     struct isp1760_device *isp;
0067 
0068     int irq;
0069     char *irqname;
0070 
0071     struct regmap *regs;
0072     struct regmap_field *fields[DC_FIELD_MAX];
0073 
0074     struct usb_gadget_driver *driver;
0075     struct usb_gadget gadget;
0076 
0077     spinlock_t lock;
0078     struct timer_list vbus_timer;
0079 
0080     struct isp1760_ep ep[15];
0081 
0082     enum isp1760_ctrl_state ep0_state;
0083     u8 ep0_dir;
0084     u16 ep0_length;
0085 
0086     bool connected;
0087     bool is_isp1763;
0088 
0089     unsigned int devstatus;
0090 };
0091 
0092 #ifdef CONFIG_USB_ISP1761_UDC
0093 int isp1760_udc_register(struct isp1760_device *isp, int irq,
0094              unsigned long irqflags);
0095 void isp1760_udc_unregister(struct isp1760_device *isp);
0096 #else
0097 static inline int isp1760_udc_register(struct isp1760_device *isp, int irq,
0098                        unsigned long irqflags)
0099 {
0100     return 0;
0101 }
0102 
0103 static inline void isp1760_udc_unregister(struct isp1760_device *isp)
0104 {
0105 }
0106 #endif
0107 
0108 #endif