USB device driver of Topcliff PCH
PATCH v2 1/1 USB device driver of Topcliff PCH
This patch adds the USB device driver of Topcliff PCH.
Topcliff PCH is the platform controller hub that is going to be used in Intel's upcoming general embedded platform. All IO peripherals in Topcliff PCH are actually devices sitting on AMBA bus.
Topcliff PCH has USB device I/F. Using this I/F, it is able to access system devices connected to USB device.
--- drivers/usb/gadget/Kconfig | 24 + drivers/usb/gadget/Makefile | 2 +- drivers/usb/gadget/gadget_chips.h | 7 + drivers/usb/gadget/pch_udc.c | 3412 +++++++++++++++++++++++++++++++++++++ 4 files changed, 3444 insertions(+), 1 deletions(-) create mode 100755 drivers/usb/gadget/pch_udc.c
drivers/usb/gadget/Kconfig +24 -0
@@ -220,6 +220,30 @@ config USB_OTG Select this only if your OMAP board has a Mini-AB connector. +config USB_GADGET_PCH + boolean "PCH USB Device controller" + depends on PCI + select USB_GADGET_DUALSPEED + help + This is a USB device driver for Topcliff PCH. + Topcliff PCH is the platform controller hub that is used in Intel's + general embedded platform. + Topcliff PCH has USB device interface. + Using this interface, it is able to access system devices connected + to USB device. + This driver enables USB device function. + USB device is a USB peripheral controller which + supports both full and high speed USB 2.0 data transfers. + This driver supports for control transfer, and bulk transfer modes. + This driver dose not support interrupt transfer, and isochronous + transfer modes. + +config PCH_USBDEV + tristate + depends on USB_GADGET_PCH + default USB_GADGET + select USB_GADGET_SELECTED + config USB_GADGET_PXA25X boolean "PXA 25x or IXP 4xx" depends on (ARCH_PXA && PXA25x) || ARCH_IXP4XX
drivers/usb/gadget/Makefile +1 -1
@@ -63,4 +63,4 @@ obj-$(CONFIG_USB_G_HID) += g_hid.o obj-$(CONFIG_USB_G_MULTI) += g_multi.o obj-$(CONFIG_USB_G_NOKIA) += g_nokia.o obj-$(CONFIG_USB_G_WEBCAM) += g_webcam.o - +obj-$(CONFIG_PCH_USBDEV) += pch_udc.o
drivers/usb/gadget/gadget_chips.h +7 -0
@@ -142,6 +142,11 @@#define gadget_is_s3c_hsotg (g) 0#endif +#ifdef CONFIG_USB_GADGET_PCH +#define gadget_is_pch (g) (!strcmp("pch_udc", (g)->name)) +#else +#define gadget_is_pch (g) 0 +#endif /** * usb_gadget_controller_number - support bcdDevice id convention
@@ -200,6 +205,8 @@ static inline int usb_gadget_controller_number(struct usb_gadget *gadget)return 0x25 ; else if (gadget_is_s3c_hsotg(gadget)) return 0x26; + else if (gadget_is_pch(gadget)) + return 0x27;return -ENOENT ; }
drivers/usb/gadget/pch_udc.c new file +3412 -0
2,946 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
1.6.2.5
Part of the diff is not shown here. View the raw message.
Op 14-09-10 10:43, Masayuki Ohtake schreef:
Quoted 8 lines
This patch adds the USB device driver of Topcliff PCH.
Topcliff PCH is the platform controller hub that is going to be used in Intel's upcoming general embedded platform. All IO peripherals in Topcliff PCH are actually devices sitting on AMBA bus.
Topcliff PCH has USB device I/F. Using this I/F, it is able to access system devices connected to USB device.
Quoted 8 lines
Signed-off-by Masayuki Ohtake <[email protected]>---
drivers/usb/gadget/Kconfig| 24 +drivers/usb/gadget/Makefile| 2 +-drivers/usb/gadget/gadget_chips.h| 7 +drivers/usb/gadget/pch_udc.c| 3412 +++++++++++++++++++++++++++++++++++++4 files changed, 3444 insertions(+), 1 deletions(-)create mode 100755
drivers/usb/gadget/pch_udc.c
pch_udc.c is still executable..
[snip]
Quoted 8 lines
drivers/usb/gadget/pch_udc.c new file +8
-0+ +/** +* pch_udc_write_csr() - Write the command and status registers. +* @val: value to be written to CSR register +* @addr: address of CSR register +*/ +static void pch_udc_write_csr (struct pch_udc_dev *dev,unsigned long val, +unsigned long reg)
drivers/usb/gadget/pch_udc.c line 472
Quoted 10 lines
drivers/usb/gadget/pch_udc.c new file +10
-0+{ +unsigned int count =MAX_LOOP ; + +/* Wait till idle */ +while ((pch_udc_readl (dev,UDC_CSR_BUSY_ADDR ) &UDC_CSR_BUSY ) + && (count >0 )) + count--; +if (!count) +dev_err (&dev->pdev->dev,"%s: wait error; count = %x" , + __func__, count);
Moving this to pch_udc_wait_csr_busy() seems like a good idea
Quoted 9 lines
+
pch_udc_writel(dev, val, reg);
+ /* Wait till idle */
+ count =MAX_LOOP;
+ while ((pch_udc_readl(dev, UDC_CSR_BUSY_ADDR)&UDC_CSR_BUSY)
+ && (count > 0))
+ count--;
+ if (!count)
+ dev_err(&dev->pdev->dev, "%s: wait error; count = %x",
+__func__, count);
Same here
Quoted 9 lines
drivers/usb/gadget/pch_udc.c new file +9
-0+} + +/** +* pch_udc_read_csr() - Read the command and status registers. +* @addr: address of CSR register +* Returns +* content of CSR register +*/ +static u32 pch_udc_read_csr (struct pch_udc_dev *dev,unsigned long reg)
drivers/usb/gadget/pch_udc.c line 500
Quoted 10 lines
drivers/usb/gadget/pch_udc.c new file +10
-0+{ +unsigned int count =MAX_LOOP ; + +/* Wait till idle */ +while ((pch_udc_readl (dev,UDC_CSR_BUSY_ADDR ) &UDC_CSR_BUSY ) + && (count >0 )) + count--; +if (!count) +dev_err (&dev->pdev->dev,"%s: wait error; count = %x" , + __func__, count);
And here
Quoted 10 lines
+ /* Dummy read */
+pch_udc_readl(dev, reg);
+ count =MAX_LOOP;
+ /* Wait till idle */
+ while ((pch_udc_readl(dev, UDC_CSR_BUSY_ADDR)&UDC_CSR_BUSY)
+ && (count > 0))
+ count--;
+ if (!count)
+ dev_err(&dev->pdev->dev, "%s: wait error; count = %x",
+__func__, count);
And here
Quoted 3 lines
+ return
pch_udc_readl(dev, reg);(quoted diff) +2
-0+} +
[snip]
Quoted 9 lines
drivers/usb/gadget/pch_udc.c new file +9
-0+static void pch_udc_ep_clear_nak (struct pch_udc_ep *ep) +{ +unsigned int loopcnt =0 ; +struct pch_udc_dev *dev = ep->dev; + +if (!(pch_udc_readl (ep->dev, ep->offset_addr +UDC_EPCTL_ADDR ) & +UDC_EPCTL_NAK )) +return ; +if (!ep->in) {
drivers/usb/gadget/pch_udc.c line 937
Quoted 10 lines
drivers/usb/gadget/pch_udc.c new file +10
-0+while ((pch_udc_read_ep_status (ep) & +UDC_EPSTS_MRXFIFO_EMP ) ==0 ) { +if (loopcnt++ >100000 ) { +dev_dbg (&dev->pdev->dev,"%s: RxFIFO not Empty " +"loop count = %d" , __func__, loopcnt); +break ; + } +udelay (100 ); + } + }
Shouldn't you reinitialise loopcnt to 0 here?
Quoted 14 lines
+ while (
pch_udc_readl(ep->dev, ep->offset_addr + UDC_EPCTL_ADDR)&
+UDC_EPCTL_NAK) {
+ PCH_UDC_BIT_SET(ep->dev,ep->offset_addr+UDC_EPCTL_ADDR,
+UDC_EPCTL_CNAK);
+ udelay(5);
+ if (loopcnt++ >= 25) {
+ dev_dbg(&dev->pdev->dev, "%s: Clear NAK not set "
+ "for ep%d%s: counter=%d",__func__,ep->num,
+ (ep->in? "in" : "out"), loopcnt);
+ break;
+ }
+ }(quoted diff) +2
-0+} +
[snip]
Quoted 31 lines
drivers/usb/gadget/pch_udc.c new file +31
-0+static void pch_udc_ep_enable (struct pch_udc_ep *ep, +struct pch_udc_cfg_data *cfg, +const struct usb_endpoint_descriptor *desc) +{ +struct pch_udc_dev *dev = ep->dev; +u32 val =0 ; +u32 buff_size =0 ; + +dev_dbg (&dev->pdev->dev,"%s: ep%x%s bmAttributes = %d wMaxPacketSize" +" = %d" , __func__, ep->num, (ep->in ?"in" :"out" ), + desc->bmAttributes, desc->wMaxPacketSize); +/* set traffic type */ +pch_udc_ep_set_trfr_type (ep, desc->bmAttributes); +/* Set buff size */ +if (ep->in) + buff_size =UDC_EPIN_BUFF_SIZE ; +else + buff_size =UDC_EPOUT_BUFF_SIZE ; + +pch_udc_ep_set_bufsz (ep, buff_size, ep->in); +/* Set max packet size */ +pch_udc_ep_set_maxpkt (ep,le16_to_cpu (desc->wMaxPacketSize)); +/* Set NAK */ +pch_udc_ep_set_nak (ep); +/* Flush fifo */ +pch_udc_ep_fifo_flush (ep, ep->in); +/* Configure the endpoint */ + val = ep->num <<UDC_CSR_NE_NUM_OFS | ep->in <<UDC_CSR_NE_DIR_OFS | + ((desc->bmAttributes &USB_ENDPOINT_XFERTYPE_MASK ) << +UDC_CSR_NE_TYPE_OFS ) | + (cfg->cur_cfg << UDC_CSR_NE_CFG_OFS) |
drivers/usb/gadget/pch_udc.c line 1035
Quoted 10 lines
drivers/usb/gadget/pch_udc.c new file +10
-0+ (cfg->cur_intf <<UDC_CSR_NE_INTF_OFS ) | + (cfg->cur_alt <<UDC_CSR_NE_ALT_OFS ) | +le16_to_cpu (desc->wMaxPacketSize) <<UDC_CSR_NE_MAX_PKT_OFS ; + +if (ep->in) +pch_udc_write_csr (ep->dev, val, (UDC_CSR_ADDR + + (ep->num *2 ) *4 )); +else +pch_udc_write_csr (ep->dev, val, (UDC_CSR_ADDR + + (ep->num *2 +1 ) *4 ));
Why not reuse PCH_UDC_CSR() here?
Even better, why not change pch_udc_write_csr() to pch_udc_write_csr(struct pch_udc_dev *dev, unsigned long val, int ep) and do the PCH_UDC_CSR() calculation in the function itself?
Quoted 3 lines
+ dev_dbg(&dev->pdev->dev, "%s: Endpoint register = 0x%08x",
__func__,
+ val);
+}
--
Maurus Cuelenaere
drivers/usb/gadget/Kconfig config USB_OTG · line 245
Quoted 6 lines · Masayuki Ohtake
drivers/usb/gadget/Kconfig +5
-0+config PCH_USBDEV + tristate + depends on USB_GADGET_PCH + default USB_GADGET + select USB_GADGET_SELECTED
What's the use of this symbol? Why is it missing help and prompt?
drivers/usb/gadget/Kconfig
Quoted 8 lines
drivers/usb/gadget/Kconfig +8
-0+/** + * struct pch_udc_data_dma_desc - Structure to hold DMA descriptor information + * for data + * @status: Status quadlet + * @reserved: Reserved + * @dataptr: Buffer descriptor + * @next: Next descriptor +*/
^ space missing.
Quoted 3 lines
+/**
+ * unionpch_udc_ep- Structure holding setup request data
+ *
Needless line.
Quoted 1 line
+ * @data[2]: 8 bytes of setup data
Needless "[2]".
drivers/usb/gadget/Kconfig
Quoted 6 lines
+ * @request: setup request for gadget driver
+ */drivers/usb/gadget/Kconfig +4
-0+union pch_udc_setup_data { + u32 data[2]; + struct usb_ctrlrequest request; +};
Besides, do you really need this union?
Quoted 4 lines
+/**
+ * structpch_udc_dev- Structure holding complete information
+ * of the PCH USB device
+ *
Needless empty line.
Quoted 4 lines
+ * @gadget: gadget driver data
+ * @driver: reference to gadget driver bound
+ * @pdev: reference to the PCI device
+ * @ep[PCH_UDC_EP_NUM]: array of endpoints
Needless "[...]".
Quoted 22 lines
+ * @lock: protects all state
+ * @active: enabled the PCI device
+ * @stall: stall requested
+ * @prot_stall: protcol stall requested
+ * @irq_registered: irq registered with system
+ * @mem_region: device memory mapped
+ * @registered: driver regsitered with system
+ * @suspended: driver in suspended state
+ * @connected: gadget driver associated
+ * @set_cfg_not_acked: pending acknowledgement 4 setup
+ * @waiting_zlp_ack: pending acknowledgement 4 ZLP
+ * @data_requests: DMA pool for data requests
+ * @stp_requests: DMA pool for setup requests
+ * @dma_addr: DMA pool for received
+ * @ep0out_buf[64]: Buffer for DMA
+ * @setup_data: Received setup data
+ * @phys_addr: of device memory
+ * @base_addr: for mapped device memory
+ * @irq: IRQ line for the device
+ * @cfg_data: current cfg, intf, and alt in use
+ */
drivers/usb/gadget/Kconfig
Quoted 7 lines
drivers/usb/gadget/Kconfig +7
-0+/* macro to set a specified bit(mask) at the specified address */ +#define PCH_UDC_BIT_SET(dev, reg, bitmask) \ + pch_udc_writel((dev), ((pch_udc_readl((dev), (reg)) | (bitmask))), (reg)) + +/* macro to clear a specified bit(mask) at the specified address */ +#define PCH_UDC_BIT_CLR(dev, reg, bitMask) \ + pch_udc_writel((dev), (pch_udc_readl((dev), (reg)) & (~(bitMask))), (reg))
You might want to make it into a static inline -- it should make some people more happy. ;) You can put it after the pch_udc_writel() function.
Quoted 4 lines
drivers/usb/gadget/Kconfig +4
-0+/** + * struct pch_udc_request - Structure holding a PCH USB device request + * @req: embedded ep request + * @td_data_phys: phys. address
drivers/usb/gadget/Kconfig
Quoted 10 lines
drivers/usb/gadget/Kconfig +10
-0+ * @td_data: first dma desc. of chain + * @td_data_last: last dma desc. of chain + * @queue: associated queue + * @dma_going: DMA in progress for request + * @dma_mapped: DMA memory mapped for request + * @dma_done: DMA completed for request + * @chain_len: chain length + */ +struct pch_udc_request /* request packet */ +{
"{" should go at the same line as "struct".
Quoted 15 lines
drivers/usb/gadget/Kconfig +14
-0+ struct usb_request req; + dma_addr_t td_data_phys; + struct pch_udc_data_dma_desc *td_data; + struct pch_udc_data_dma_desc *td_data_last; + struct list_head queue; + unsigned dma_going:1, + dma_mapped:1, + dma_done:1; + unsigned chain_len; +}; +/** + * pch_udc_write_csr() - Write the command and status registers. + * @val: value to be written to CSR register + * @addr: address of CSR register
drivers/usb/gadget/Kconfig
Quoted 10 lines
drivers/usb/gadget/Kconfig +10
-0+ */ +static void pch_udc_write_csr(struct pch_udc_dev *dev, unsigned long val, + unsigned long reg) +{ + unsigned int count = MAX_LOOP; + + /* Wait till idle */ + while ((pch_udc_readl(dev, UDC_CSR_BUSY_ADDR) & UDC_CSR_BUSY) + && (count > 0)) + count--;
Come to think of it, you sort of ignore the result of the last read if all possible loop iterations were done. I mean, when count hits zero you still read the register but it does not really matter what the read value is. Because of that, I'd change the while to:
+ while ((pch_udc_readl(...) & UDC_CSR_BUSY) && --count)
+ /* nop */;
This also applies to other loops in other functions as well.
drivers/usb/gadget/Kconfig
Quoted 3 lines
drivers/usb/gadget/Kconfig +3
-0+ if (!count) + dev_err(&dev->pdev->dev, "%s: wait error; count = %x", + __func__, count);
Writing count here is rather useless. It's always zero. This also applies to other loops in other functions as well.
Besides, the loop repeats in four different places (if I notices all of them). Why not make a function out of it?
Quoted 13 lines
drivers/usb/gadget/Kconfig +12
-0+ pch_udc_writel(dev, val, reg); + /* Wait till idle */ + count = MAX_LOOP; + while ((pch_udc_readl(dev, UDC_CSR_BUSY_ADDR) & UDC_CSR_BUSY) + && (count > 0)) + count--; + if (!count) + dev_err(&dev->pdev->dev, "%s: wait error; count = %x", + __func__, count); +} +static u32 pch_udc_read_csr(struct pch_udc_dev *dev, unsigned long reg) +{
[...]
drivers/usb/gadget/Kconfig
Quoted 2 lines
drivers/usb/gadget/Kconfig +2
-0+ /* Dummy read */ + pch_udc_readl(dev, reg);
O_o... I'll just assume this makes sense for the hardware. ;) A comment about why this is done in such a way would be nice though.
[...]
Quoted 8 lines
drivers/usb/gadget/Kconfig +7
-0+} +static inline void pch_udc_vbus_session(struct pch_udc_dev *dev, + int is_active) +{ + if (is_active == 0) + pch_udc_set_disconnect(dev); + else
drivers/usb/gadget/Kconfig
Quoted 10 lines
drivers/usb/gadget/Kconfig +9
-0+ pch_udc_clear_disconnect(dev); +} +static void pch_udc_ep_clear_nak(struct pch_udc_ep *ep) +{ + unsigned int loopcnt = 0; + struct pch_udc_dev *dev = ep->dev; + + if (!(pch_udc_readl(ep->dev, ep->offset_addr + UDC_EPCTL_ADDR) & + UDC_EPCTL_NAK))
Just a thought, but maybe it would be feasible to create pch_ep_readl() and pch_ep_writel() functions so that you wouldn't have to add the ep->offset_addr each time.
drivers/usb/gadget/Kconfig
Quoted 2 lines
drivers/usb/gadget/Kconfig +2
-0+ return; + if (!ep->in) {
Useless "{ ... }".
drivers/usb/gadget/Kconfig
Quoted 3 lines
drivers/usb/gadget/Kconfig +3
-0+ while ((pch_udc_read_ep_status(ep) & + UDC_EPSTS_MRXFIFO_EMP) == 0) { + if (loopcnt++ > 100000) {
Why not preincrementation? Why not loop form 100000 to zero rather than from zero to 100000.
drivers/usb/gadget/Kconfig
Quoted 7 lines
drivers/usb/gadget/Kconfig +7
-0+ dev_dbg(&dev->pdev->dev, "%s: RxFIFO not Empty " + "loop count = %d", __func__, loopcnt); + break; + } + udelay(100); + } + }
You need to zero loopcnt here. Also, I'd use a loop from 25 to zero rather than from zero to 25 here the same as above.
Quoted 16 lines
drivers/usb/gadget/Kconfig +15
-0+ while (pch_udc_readl(ep->dev, ep->offset_addr + UDC_EPCTL_ADDR) & + UDC_EPCTL_NAK) { + PCH_UDC_BIT_SET(ep->dev, ep->offset_addr + UDC_EPCTL_ADDR, + UDC_EPCTL_CNAK); + udelay(5); + if (loopcnt++ >= 25) { + dev_dbg(&dev->pdev->dev, "%s: Clear NAK not set " + "for ep%d%s: counter=%d", __func__, ep->num, + (ep->in ? "in" : "out"), loopcnt); + break; + } + } +} +static void pch_udc_ep_fifo_flush(struct pch_udc_ep *ep, int dir) +{
drivers/usb/gadget/Kconfig
Quoted 10 lines
drivers/usb/gadget/Kconfig +10
-0+ unsigned int loopcnt = 0; + struct pch_udc_dev *dev = ep->dev; + + dev_dbg(&dev->pdev->dev, "%s: ep%d%s", __func__, ep->num, + (ep->in ? "in" : "out")); + if (dir) { /* IN ep */ + PCH_UDC_BIT_SET(ep->dev, ep->offset_addr + UDC_EPCTL_ADDR, + UDC_EPCTL_F); + return; + } else {
Drop "else", "{" ... "}" and indention.
Quoted 21 lines
drivers/usb/gadget/Kconfig +20
-0+ if (pch_udc_read_ep_status(ep) & UDC_EPSTS_MRXFIFO_EMP) + return; + PCH_UDC_BIT_SET(ep->dev, ep->offset_addr + UDC_EPCTL_ADDR, + UDC_EPCTL_MRXFLUSH); + /* Wait for RxFIFO Empty */ + while ((pch_udc_read_ep_status(ep) & + UDC_EPSTS_MRXFIFO_EMP) == 0) { + if (loopcnt++ > 1000000) { + dev_dbg(&dev->pdev->dev, "RxFIFO not Empty " + "loop count = %d", loopcnt); + break; + } + udelay(100); + } + PCH_UDC_BIT_CLR(ep->dev, ep->offset_addr + UDC_EPCTL_ADDR, + UDC_EPCTL_MRXFLUSH); + } +} +static void pch_udc_init(struct pch_udc_dev *dev) +{
[...]
drivers/usb/gadget/Kconfig
Quoted 8 lines
drivers/usb/gadget/Kconfig +8
-0+ /* enable dynamic CSR programmingi, self powered and device speed */ + if (speed_fs) { + PCH_UDC_BIT_SET(dev, UDC_DEVCFG_ADDR, UDC_DEVCFG_CSR_PRG | + UDC_DEVCFG_SP | UDC_DEVCFG_SPD_FS); + } else { /* defaul high speed */ + PCH_UDC_BIT_SET(dev, UDC_DEVCFG_ADDR, UDC_DEVCFG_CSR_PRG | + UDC_DEVCFG_SP | UDC_DEVCFG_SPD_HS); + }
Useless "{ ... }".
[...]
Quoted 6 lines
drivers/usb/gadget/Kconfig +5
-0+} +static int pch_udc_pcd_pullup(struct usb_gadget *gadget, int is_on) +{ + struct pch_udc_dev *dev; +
drivers/usb/gadget/Kconfig
Quoted 10 lines
drivers/usb/gadget/Kconfig +10
-0+ if (gadget == NULL) { + pr_debug("%s: exit -EINVAL", __func__); + return -EINVAL; + } + dev = container_of(gadget, struct pch_udc_dev, gadget); + if (is_on == 0) + pch_udc_set_disconnect(dev); + else + pch_udc_clear_disconnect(dev); + return 0;
You can use pch_udc_vbus_session() here.
drivers/usb/gadget/Kconfig
Quoted 11 lines
drivers/usb/gadget/Kconfig +10
-0+} +static int pch_udc_pcd_vbus_draw(struct usb_gadget *gadget, unsigned int mA) +{ + if ((gadget == NULL) || (mA > 250)) { /* Max is 250 in 2mA unit */ + pr_debug("%s: exit -EINVAL", __func__); + return -EINVAL; + } + /* Could not find any regs where we can set the limit */ + return -EOPNOTSUPP; +}
Wouldn't it be easier to just always return -EOPNOTSUPP?
Quoted 1 line
+const struct
usb_gadget_opspch_udc_ops= {
Why not static?
Quoted 10 lines
drivers/usb/gadget/Kconfig +9
-0+ .get_frame = pch_udc_pcd_get_frame, + .wakeup = pch_udc_pcd_wakeup, + .set_selfpowered = pch_udc_pcd_selfpowered, + .pullup = pch_udc_pcd_pullup, + .vbus_session = pch_udc_pcd_vbus_session, + .vbus_draw = pch_udc_pcd_vbus_draw, +}; +static void complete_req(struct pch_udc_ep *ep, struct pch_udc_request *req, + int status)
drivers/usb/gadget/Kconfig
Quoted 10 lines
drivers/usb/gadget/Kconfig +9
-0+{ + if (req->dma_mapped) { + if (ep->in) { + pci_unmap_single(dev->pdev, req->req.dma, + req->req.length, PCI_DMA_TODEVICE); + } else { + pci_unmap_single(dev->pdev, req->req.dma, + req->req.length, PCI_DMA_FROMDEVICE); + }
Useless "{ ... }".
Quoted 10 lines
drivers/usb/gadget/Kconfig +9
-0+ req->dma_mapped = 0; + req->req.dma = DMA_ADDR_INVALID; + } +} + +/** + * empty_req_queue() - This API empties the request queue of an endpoint + * @ep: Reference to the endpoint structure + */
drivers/usb/gadget/Kconfig
Quoted 10 lines
drivers/usb/gadget/Kconfig +10
-0+static void empty_req_queue(struct pch_udc_ep *ep) +{ + struct pch_udc_request *req; + + ep->halted = 1; + while (!list_empty(&ep->queue)) { + req = list_entry(ep->queue.next, struct pch_udc_request, queue); + pr_debug("%s: complete_req ep%d%s", __func__, ep->num, + (ep->in ? "in" : "out")); + complete_req(ep, req, -ESHUTDOWN);
complete_req() removes from list, right? I think it's worth adding a comment.
Quoted 16 lines
drivers/usb/gadget/Kconfig +13
-0+ } +} +static int pch_udc_create_dma_chain(struct pch_udc_ep *ep, + struct pch_udc_request *req, + unsigned long buf_len, + gfp_t gfp_flags) +{ + for (i = buf_len; i < bytes; i += buf_len) { + dma_addr = DMA_ADDR_INVALID; + /* create or determine next desc. */ + td = pci_pool_alloc(ep->dev->data_requests, gfp_flags, + &dma_addr); + if (td == NULL)
drivers/usb/gadget/Kconfig
Quoted 10 lines
drivers/usb/gadget/Kconfig +10
-0+ return -ENOMEM; + + td->status = 0; + td->dataptr = req->req.dma + i; /* assign buffer */ + + if ((bytes - i) >= buf_len) { + txbytes = buf_len; + } else { /* short packet */ + txbytes = bytes - i; + }
Useless "{ ... }".
Quoted 8 lines
drivers/usb/gadget/Kconfig +7
-0+static int prepare_dma(struct pch_udc_ep *ep, struct pch_udc_request *req, + gfp_t gfp) +{ + /* Allocate and create a DMA chain */ + retval = pch_udc_create_dma_chain(ep, req, ep->ep.maxpacket, gfp); + if (retval) { + if (retval == -ENOMEM)
drivers/usb/gadget/Kconfig
Quoted 10 lines
drivers/usb/gadget/Kconfig +10
-0+ pr_err("%s: Out of DMA memory", __func__); + return retval; + } + if (ep->in) { + if (req->req.length <= ep->ep.maxpacket) { + /* write tx bytes */ + req->td_data->status = PCH_UDC_DMA_LAST | + PCH_UDC_BS_HST_BSY | + req->req.length; + }
Useless "{ ... "}".
Quoted 7 lines
drivers/usb/gadget/Kconfig +7
-0+/** + * process_zlp() - This function process zero length packets + * from the gadget driver + * @ep: Reference to the endpoint structure + * @req: Reference to the request + */ +static void process_zlp(struct pch_udc_ep *ep, struct pch_udc_request *req)
drivers/usb/gadget/Kconfig
Quoted 10 lines
drivers/usb/gadget/Kconfig +10
-0+{ + struct pch_udc_dev *dev = ep->dev; + + dev_dbg(&dev->pdev->dev, "%s: enter ep%d%s", __func__, ep->num, + (ep->in ? "in" : "out")); + /* IN zlp's are handled by hardware */ + complete_req(ep, req, 0); + + /* if set_config or set_intf is waiting for ack by zlp + *then set CSR_DONE
^ missing space.
drivers/usb/gadget/Kconfig
Quoted 5 lines
drivers/usb/gadget/Kconfig +4
-0+ */ + /* setup command is ACK'ed now by zlp */ + if (!dev->stall) { + if (dev->waiting_zlp_ack) {
Join both ifs into a single if with &&.
Quoted 19 lines
drivers/usb/gadget/Kconfig +19
-0+ /* clear NAK by writing CNAK in EP0_IN */ + pch_udc_ep_clear_nak(&(dev->ep[UDC_EP0IN_IDX])); + dev->waiting_zlp_ack = 0; + } + } +} + +/** + * pch_udc_start_rxrequest() - This function starts the receive requirement. + * @ep: Reference to the endpoint structure + * @req: Reference to the request structure + */ +static void pch_udc_start_rxrequest(struct pch_udc_ep *ep, + struct pch_udc_request *req) +{ + struct pch_udc_data_dma_desc *td_data; + + pch_udc_clear_dma(ep->dev, DMA_DIR_RX); + td_data = req->td_data;
drivers/usb/gadget/Kconfig
Quoted 10 lines
drivers/usb/gadget/Kconfig +10
-0+ ep->td_data = req->td_data; + /* Set the status bits for all descriptors */ + while (1) { + td_data->status = (td_data->status & ~PCH_UDC_BUFF_STS) | + PCH_UDC_BS_HST_RDY; + if ((td_data->status & PCH_UDC_DMA_LAST) == PCH_UDC_DMA_LAST) + break; + + td_data = (struct pch_udc_data_dma_desc *) \ + phys_to_virt(td_data->next);
Useless cast. phys_to_virt() returns void*.
drivers/usb/gadget/Kconfig
Quoted 9 lines
drivers/usb/gadget/Kconfig +8
-0+ } + if (ep->in) { + usbreq->dma = pci_map_single(dev->pdev, usbreq->buf, + usbreq->length, PCI_DMA_TODEVICE); + } else { + usbreq->dma = pci_map_single(dev->pdev, usbreq->buf, + usbreq->length, PCI_DMA_FROMDEVICE); + }
Useless "{ ... }".
drivers/usb/gadget/Kconfig
Quoted 12 lines
drivers/usb/gadget/Kconfig +12
-0+static void pch_udc_complete_transfer(struct pch_udc_ep *ep) +{ + struct pch_udc_request *req; + struct pch_udc_dev *dev = ep->dev; + + if (list_empty(&ep->queue)) + return; + + dev_dbg(&dev->pdev->dev, "%s: list_entry", __func__); + req = list_entry(ep->queue.next, struct pch_udc_request, queue); + if (!req) + return;
This can never happen. list_head's next is never set to NULL. Moreover, you already check if the queue is not empty a few lines above.
drivers/usb/gadget/Kconfig
Quoted 9 lines
drivers/usb/gadget/Kconfig +8
-0+ if ((req->td_data_last->status & PCH_UDC_BUFF_STS) != + PCH_UDC_BS_DMA_DONE) + return; + +#ifdef DMA_PPB_WITH_DESC_UPDATE + for (i = 0; i < req->chain_len; i++) { + req->td_data = (struct pch_udc_data_dma_desc *) + phys_to_virt(req->td_data->next);
Useless cast.
Quoted 21 lines
drivers/usb/gadget/Kconfig +19
-0+ } +#else +#endif +static void pch_udc_complete_receiver(struct pch_udc_ep *ep) +{ + struct pch_udc_request *req; + struct pch_udc_dev *dev = ep->dev; + unsigned int count; + + if (list_empty(&ep->queue)) + return; + + /* next request */ + req = list_entry(ep->queue.next, struct pch_udc_request, queue); + if (!req || (req->td_data_last->status & PCH_UDC_BUFF_STS) != + PCH_UDC_BS_DMA_DONE) { +#ifdef DMA_PPB_WITH_DESC_UPDATE + dev_dbg(&dev->pdev->dev, "%s: ep%d%s DMA not Done", + __func__, ep->num, (ep->in ? "in" : "out"));
drivers/usb/gadget/Kconfig
Quoted 10 lines
drivers/usb/gadget/Kconfig +10
-0+ pch_udc_ep_set_rrdy(ep); +#endif + return; + } + dev_dbg(&dev->pdev->dev, "%s: ep%d%s DMA Done", __func__, ep->num, + (ep->in ? "in" : "out")); + /* Disable DMA */ + pch_udc_clear_dma(ep->dev, DMA_DIR_RX); +#ifdef DMA_PPB_WITH_DESC_UPDATE +{
This should be indented.
drivers/usb/gadget/Kconfig
Quoted 13 lines
drivers/usb/gadget/Kconfig +13
-0+ /* Get Rx bytes */ + struct pch_udc_data_dma_desc *td_data = req->td_data; + for (i = 0, count = 0; i < req->chain_len; i++) { + if ((td_data->status & PCH_UDC_RXTX_STS) != PCH_UDC_RTS_SUCC) { + dev_err(&dev->pdev->dev, "Invalid RXTX status (0x%08x) " + "epstatus=0x%08x\n", + (td_data->status & PCH_UDC_RXTX_STS), + (int)(ep->epsts)); + return; + } + count += td_data->status & PCH_UDC_RXTX_BYTES; + td_data = + (struct pch_udc_data_dma_desc *) phys_to_virt(td_data->next);
Useless cast.
Quoted 15 lines
drivers/usb/gadget/Kconfig +13
-0+ } +} +#else +#endif +/** + * pch_udc_svc_data_out() - Handles interrupts from OUT endpoint + * @dev: Reference to the device structure + * @ep_num: Endpoint that generated the interrupt + */ +static void pch_udc_svc_data_out(struct pch_udc_dev *dev, int ep_num) +{ + u32 epsts; + struct pch_udc_ep *ep;
drivers/usb/gadget/Kconfig
Quoted 10 lines
drivers/usb/gadget/Kconfig +10
-0+ struct pch_udc_request *req = NULL; + + ep = &dev->ep[2*ep_num + 1]; + epsts = ep->epsts; + ep->epsts = 0; + + dev_dbg(&dev->pdev->dev, "%s: enter ep%d%s status = 0x%08x", __func__, + ep->num, (ep->in ? "in" : "out"), epsts); + if (epsts & UDC_EPSTS_BNA) { /* Just log it; only in DMA mode */ + if (!list_empty(&ep->queue)) {
Those two ifs can be joined into one with &&.
[...]
Quoted 5 lines
drivers/usb/gadget/Kconfig +4
-0+ } + } +} +
drivers/usb/gadget/Kconfig
Quoted 10 lines
drivers/usb/gadget/Kconfig +9
-0+/** + * pch_udc_svc_control_in() - Handle Control IN endpoint interrupts + * @dev: Reference to the device structure + */ +static void pch_udc_svc_control_in(struct pch_udc_dev *dev) +{ + if (epsts & UDC_EPSTS_TXEMPTY) { /* Tx empty */ + dev_dbg(&dev->pdev->dev, "%s: TXEMPTY", __func__); + }
Useless "{ ... }".
Quoted 33 lines
drivers/usb/gadget/Kconfig +33
-0+} + +/** + * pch_udc_svc_control_out() - Routine that handle Control + * OUT endpoint interrupts + * @dev: Reference to the device structure + */ +static void pch_udc_svc_control_out(struct pch_udc_dev *dev) +{ + u32 stat; + int setup_supported; + struct pch_udc_ep *ep; + + ep = &dev->ep[UDC_EP0OUT_IDX]; + stat = ep->epsts; + ep->epsts = 0; + + if (stat & UDC_EPSTS_BNA) + dev_dbg(&dev->pdev->dev, "%s: EP0: BNA", __func__); + /* When we get a request, we will populate the descriptors. */ + /* Anything else to do? */ + /* If setup data */ + if (((stat & UDC_EPSTS_OUT_MASK) >> UDC_EPSTS_OUT_OFS) == + UDC_EPSTS_OUT_SETUP) { + dev->stall = 0; + dev->ep[UDC_EP0IN_IDX].halted = 0; + dev->ep[UDC_EP0OUT_IDX].halted = 0; + /* In data not ready */ + pch_udc_ep_set_nak(&(dev->ep[UDC_EP0IN_IDX])); + dev->setup_data.data[0] = ep->td_stp->data12; + dev->setup_data.data[1] = ep->td_stp->data34; + dev_dbg(&dev->pdev->dev, "%s: EP0 setup data12: 0x%x " + "data34:0x%x", __func__, ep->td_stp->data12,
drivers/usb/gadget/Kconfig
Quoted 10 lines
drivers/usb/gadget/Kconfig +10
-0+ ep->td_stp->data34); + pch_udc_init_setup_buff(ep->td_stp); + pch_udc_clear_dma(dev, DMA_DIR_TX); + pch_udc_ep_fifo_flush(&(dev->ep[UDC_EP0IN_IDX]), + dev->ep[UDC_EP0IN_IDX].in); + if ((dev->setup_data.request.bRequestType & USB_DIR_IN) != 0) { + dev->gadget.ep0 = &dev->ep[UDC_EP0IN_IDX].ep; + } else { /* OUT */ + dev->gadget.ep0 = &ep->ep; + }
Useless "{ ... }".
Quoted 2 lines
drivers/usb/gadget/Kconfig +2
-0+static void pch_udc_dev_isr(struct pch_udc_dev *dev, u32 dev_intr) +{
[...]
drivers/usb/gadget/Kconfig
Quoted 4 lines
drivers/usb/gadget/Kconfig +4
-0+ /* RWKP interrupt */ + if (dev_intr & UDC_DEVINT_RWKP) + dev_dbg(&dev->pdev->dev, "RWKP"); +
Useless empty line.
drivers/usb/gadget/Kconfig
Quoted 5 lines
drivers/usb/gadget/Kconfig +4
-0+} +static void pch_udc_pcd_reinit(struct pch_udc_dev *dev) +{ + static const char *ep_string[] = {
Why not static "const char *const ep_string[]"?
drivers/usb/gadget/Kconfig
Quoted 9 lines
drivers/usb/gadget/Kconfig +8
-0+ ep0_string, "ep0out", "ep1in", "ep1out", "ep2in", "ep2out", + "ep3in", "ep3out", "ep4in", "ep4out", "ep5in", "ep5out", + "ep6in", "ep6out", "ep7in", "ep7out", "ep8in", "ep8out", + "ep9in", "ep9out", "ep10in", "ep10out", "ep11in", "ep11out", + "ep12in", "ep12out", "ep13in", "ep13out", "ep14in", "ep14out", + "ep15in", "ep15out", + }; +}
Also, please run checkpatch.pl on the patch.
Signature · 4 lines
Best regards, _ _ | Humble Liege of Serenely Enlightened Majesty of o' \,=./ `o | Computer Science, Michał "mina86" Nazarewicz (o o) +----[mina86*mina86.com]---[mina86*jabber.org]----ooO--(_)--Ooo--