USB device driver of Topcliff PCH
PATCH v7 1/1 USB device driver of Topcliff PCH
Hi Greg
This patch was acked by Michal Nazarewicz.
Could you review this patch?
Best regards
Toshiharu Okada (OKI SEMICONDUCTOR)
---
This patch adds the USB device driver of EG20T PCH.
EG20T PCH is the platform controller hub that is going to be used in Intel's upcoming general embedded platform. All IO peripherals in EG20T PCH are actually devices sitting on AMBA bus.
EG20T 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 | 22 + drivers/usb/gadget/Makefile | 2 +- drivers/usb/gadget/gadget_chips.h | 7 + drivers/usb/gadget/pch_udc.c | 3284 +++++++++++++++++++++++++++++++++++++ 4 files changed, 3314 insertions(+), 1 deletions(-) create mode 100644 drivers/usb/gadget/pch_udc.c
drivers/usb/gadget/Kconfig +22 -0
@@ -505,6 +505,28 @@ config USB_LANGWELL default USB_GADGET select USB_GADGET_SELECTED +config USB_GADGET_PCH + boolean "PCH USB Device controller" + depends on PCI + select USB_GADGET_DUALSPEED + help + This is a USB device driver for EG20T PCH. + EG20T PCH is the platform controller hub that is used in Intel's + general embedded platform. EG20T 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 USB_PCH + tristate + depends on USB_GADGET_PCH + default USB_GADGET + select USB_GADGET_SELECTED # # LAST -- dummy/emulated controller
drivers/usb/gadget/Makefile +1 -1
@@ -28,6 +28,7 @@ obj-$(CONFIG_USB_FSL_QE) += fsl_qe_udc.o obj-$(CONFIG_USB_CI13XXX) += ci13xxx_udc.o obj-$(CONFIG_USB_S3C_HSOTG) += s3c-hsotg.o obj-$(CONFIG_USB_LANGWELL) += langwell_udc.o +obj-$(CONFIG_USB_PCH) += pch_udc.o # # USB gadget drivers
@@ -64,4 +65,3 @@ obj-$(CONFIG_USB_G_DBGP) += g_dbgp.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 -
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 +3284 -0
2,942 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.
drivers/usb/gadget/Kconfig config USB_LANGWELL · line 509
Quoted 10 lines · Toshiharu Okada
This patch adds the USB device driver of EG20T PCH.
EG20T PCH is the platform controller hub that is going to be used in Intel's upcoming general embedded platform. All IO peripherals in EG20T PCH are actually devices sitting on AMBA bus.
EG20T 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 +2
-0+config USB_GADGET_PCH + boolean "PCH USB Device controller"
This description is way too generic. "Intel EG20T (Topcliff) USB Device controller" would be better. The config option should probably be USB_GADGET_EG20T as well.
drivers/usb/gadget/Kconfig config USB_LANGWELL · line 521
Quoted 8 lines
drivers/usb/gadget/Kconfig +8
-0+ EG20T PCH is the platform controller hub that is used in Intel's + general embedded platform. EG20T 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 supports both control transfer and bulk transfer modes."
drivers/usb/gadget/Kconfig config USB_LANGWELL · line 523
Quoted 2 lines
drivers/usb/gadget/Kconfig +2
-0+ This driver dose not support interrupt transfer, and isochronous + transfer modes.
"This driver does not support interrupt transfer or isochronous transfer modes."
drivers/usb/gadget/Kconfig config USB_LANGWELL · line 526
Quoted 2 lines
drivers/usb/gadget/Kconfig +2
-0+config USB_PCH + tristate
Does this option need a description string?
Quoted 1 line
+++
b/drivers/usb/gadget/pch_udc.c
[snip]
Quoted 11 lines
drivers/usb/gadget/pch_udc.c new file +11
-0+#include <linux/types.h> +#include <linux/module.h> +#include <linux/pci.h> +#include <linux/kernel.h> +#include <linux/delay.h> +#include <linux/ioport.h> +#include <linux/sched.h> +#include <linux/slab.h> +#include <linux/smp_lock.h> +#include <linux/errno.h> +#include <linux/init.h>
drivers/usb/gadget/pch_udc.c line 38
Quoted 10 lines
drivers/usb/gadget/pch_udc.c new file +10
-0+#include <linux/timer.h> +#include <linux/list.h> +#include <linux/interrupt.h> +#include <linux/ioctl.h> +#include <linux/fs.h> +#include <linux/dmapool.h> +#include <linux/moduleparam.h> +#include <linux/device.h> +#include <linux/io.h> +#include <linux/irq.h>
Do you really need all of these includes?
drivers/usb/gadget/pch_udc.c line 139
Quoted 5 lines
drivers/usb/gadget/pch_udc.c new file +5
-0+#define UDC_DEVSTS_TS_OFS 18 +#define UDC_DEVSTS_ENUM_SPEED_OFS 13 +#define UDC_DEVSTS_ALT_OFS 8 +#define UDC_DEVSTS_INTF_OFS 4 +#define UDC_DEVSTS_CFG_OFS 0
Please rename all _OFS constants to _SHIFT for clarity. (However, if the rename will cause many lines to exceed 80 characters, then please choose another name.)
drivers/usb/gadget/pch_udc.c line 495
Quoted 4 lines
drivers/usb/gadget/pch_udc.c new file +4
-0+static void pch_udc_write_csr (struct pch_udc_dev *dev,unsigned long val, +unsigned int ep) +{ +unsigned long reg =PCH_UDC_CSR (ep);
Add a blank line between variables and code.
drivers/usb/gadget/pch_udc.c line 507
Quoted 11 lines
drivers/usb/gadget/pch_udc.c new file +9
-0+pch_udc_csr_busy (dev);/* Wait till idle */ +pch_udc_writel (dev, val, reg); +/** +* pch_udc_read_csr() - Read the command and status registers. +* @dev: Reference to pch_udc_dev structure +* @addr: address of CSR register +* Returns +* content of CSR register +*/
Please read Documentation/kernel-doc-nano-HOWTO.txt and verify this is correct. I am not sure, but I think you need a blank line after the last @variable, and should say "Return value:".
drivers/usb/gadget/pch_udc.c line 510
Quoted 3 lines
drivers/usb/gadget/pch_udc.c new file +3
-0+static u32 pch_udc_read_csr (struct pch_udc_dev *dev,unsigned int ep) +{ +unsigned long reg =PCH_UDC_CSR (ep);
Please check all your functions and ensure there is a proper blank line here.
drivers/usb/gadget/pch_udc.c line 736
Quoted 13 lines
drivers/usb/gadget/pch_udc.c new file +11
-0+pch_udc_csr_busy (dev);/* Wait till idle */ +pch_udc_readl (dev, reg);/* Dummy read */ +pch_udc_csr_busy (dev);/* Wait till idle */ +/** +* pch_udc_clear_dma() - Clear the 'TDE' or RDE bit of device control +* register depending on the direction specified +* @dev: Reference to structure of type pch_udc_regs +* @dir: Whether Tx or Rx +* - dir = DMA_DIR_RX Receive +* - dir = DMA_DIR_TX Transmit +*/
This will not format correctly, please read nano-howto.txt.
drivers/usb/gadget/pch_udc.c line 743
Quoted 7 lines
drivers/usb/gadget/pch_udc.c new file +7
-0+static inline void pch_udc_clear_dma (struct pch_udc_dev *dev,int dir) +{ +if (dir ==DMA_DIR_RX ) +pch_udc_bit_clr (dev,UDC_DEVCTL_ADDR ,UDC_DEVCTL_RDE ); +else if (dir ==DMA_DIR_TX ) +pch_udc_bit_clr (dev,UDC_DEVCTL_ADDR ,UDC_DEVCTL_TDE ); +
Delete this extra blank line. Check for unneeded blank lines throughout.
drivers/usb/gadget/pch_udc.c line 1415
Quoted 7 lines
drivers/usb/gadget/pch_udc.c new file +5
-0+} +pr_debug ("%s: enter req->req.dma=0x%08x" , __func__, req->req.dma); +/* set buffer pointer */ + req->td_data->dataptr = req->req.dma; +/* set last bit */
These comments are useless, because they just repeat what the code says. Please remove them or replace them with comments that actually explain what is happening. For example, this line could use a comment:
Review
Quoted 1 line
(quoted diff) +1
-0+ req->td_data->status |= PCH_UDC_DMA_LAST;
*Why* are we setting DMA_LAST? (I *think* I know, but am not entirely sure.) Probably it doesn't need a comment at all, but if it does, the comment should answer the "Why?" question.
You have many examples of this pattern of one-comment-per-line-of-code. Please review them all.
[snip]
drivers/usb/gadget/pch_udc.c line 1433
Quoted 3 lines
drivers/usb/gadget/pch_udc.c new file +3
-0+/* if bytes < max packet then tx bytes must +* be written in packet per buffer mode +*/
This is a good comment!
drivers/usb/gadget/pch_udc.c line 1435
Quoted 2 lines
drivers/usb/gadget/pch_udc.c new file +2
-0+if ((req->req.length < ep->ep.maxpacket) || !ep->num) +/* write the count */
This is a bad comment.
Quoted 2 lines
drivers/usb/gadget/pch_udc.c new file +2
-0+ req->td_data->status = (req->td_data->status & + ~PCH_UDC_RXTX_BYTES ) | req->req.length;
[snip]
drivers/usb/gadget/pch_udc.c line 1488
Quoted 9 lines
drivers/usb/gadget/pch_udc.c new file +9
-0+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; + ep->td_data = req->td_data; +/* Set the status bits for all descriptors */
Here is an example of a one-line comment that is not bad, since it explains why the loop is here. So in your review, be careful not to remove good comments like this...
drivers/usb/gadget/pch_udc.c line 1497
Quoted 9 lines
drivers/usb/gadget/pch_udc.c new file +9
-0+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 =phys_to_virt (td_data->next); + } +/* Write the descriptor pointer */ +pch_udc_ep_set_ddptr (ep, req->td_data_phys);
Suprisingly, this comment is good too, I think, since it helps explain the effect of set_ddptr.
drivers/usb/gadget/pch_udc.c line 1628
Quoted 5 lines
drivers/usb/gadget/pch_udc.c new file +5
-0+dev_dbg (&dev->pdev->dev,"%s: req = 0x%p dma_desc = 0x%p, td_phys = " +"0x%08lx" , __func__, req, dma_desc, + (unsigned long )req->td_data_phys); +/* prevent from using desc. - set HOST BUSY */ + dma_desc->status |=PCH_UDC_BS_HST_BSY ;
This comment should explain what is being prevented from using desc, I think it's the USB controller but the comment should explain clearly.
Quoted 2 lines
drivers/usb/gadget/pch_udc.c new file +2
-0+static int pch_udc_pcd_set_halt (struct usb_ep *usbep,int halt) +{
[snip]
Quoted 4 lines
drivers/usb/gadget/pch_udc.c new file +4
-0+if (!list_empty (&ep->queue)) { +dev_dbg (&dev->pdev->dev,"%s: list not empty" , __func__); + ret = -EAGAIN ; + }else if (!halt) {/* halt or clear halt */
drivers/usb/gadget/pch_udc.c line 1866
Quoted 10 lines
drivers/usb/gadget/pch_udc.c new file +10
-0+pch_udc_ep_clear_stall (ep); + ret =0 ; + }else { +if (ep->num ==PCH_UDC_EP0 ) + ep->dev->stall =1 ; +pch_udc_ep_set_stall (ep); +pch_udc_enable_ep_interrupts (ep->dev, +PCH_UDC_EPINT (ep->in, ep->num)); + ret =0 ; + }
I think this would be clearer as
+ if (!list_empty(&ep->queue)) {
+ dev_dbg(&dev->pdev->dev, "%s: list not empty", __func__);
+ ret = -EAGAIN;
+ }
+ if (halt) {
+ if (ep->num == PCH_UDC_EP0)
+ ep->dev->stall = 1;
+ pch_udc_ep_set_stall(ep);
+ pch_udc_enable_ep_interrupts(ep->dev,
+ PCH_UDC_EPINT(ep->in, ep->num));
+ ret = 0;
+ } else {
+ pch_udc_ep_clear_stall(ep);
+ ret = 0;
+ }
because:
1. if (!list_empty is a standalone check, there is no if/else if/else connection between list_empty() and halt.
2. I prefer if (foo) {} else {} instead of if (!foo) {} else {}, unless there is a significant reason to do the negated test.
drivers/usb/gadget/pch_udc.c line 1929
Quoted 1 line
drivers/usb/gadget/pch_udc.c new file +1
-0+struct pch_udc_ep *ep ;
random extra whitespace before ;.
drivers/usb/gadget/pch_udc.c line 1934
Quoted 1 line
drivers/usb/gadget/pch_udc.c new file +1
-0+pr_debug ("%s: %s" , __func__, usbep->name);
There are probably too many pr_debug() and dev_dbg()s in this driver. Please reconsider which ones are appropriate for mainline.
Quoted 1 line
+#ifdef
DMA_PPB_WITH_DESC_UPDATE
I don't see this defined anywhere, is this dead code?
drivers/usb/gadget/pch_udc.c line 2395
Quoted 4 lines
drivers/usb/gadget/pch_udc.c new file +4
-0+ }else if ((((stat &UDC_EPSTS_OUT_MASK ) >>UDC_EPSTS_OUT_OFS ) == +UDC_EPSTS_OUT_DATA ) && !dev->stall) { +if (list_empty (&ep->queue)) { +dev_err (&dev->pdev->dev,"%s: ZLP" , __func__);
Please provide a useful error message here.
drivers/usb/gadget/pch_udc.c line 2544
Quoted 3 lines
drivers/usb/gadget/pch_udc.c new file +3
-0+for (i =0 ; i <PCH_UDC_EP_NUM ; i++) { + ep = &dev->ep[i]; +pch_udc_clear_ep_status (ep,0x1F0006F0 );
This magic number needs a #define.
Overall, the code cleanliness looks OK once the above are addressed. I am not qualified to review the USB gadget interfaces, but the general structure appears to be sane.
-andy
Hi Andy.
Thank you for your comment.
We will modify like your comment and resubmit it
I have a question.
Quoted 4 lines
Quoted 2 lines
+config
USB_PCH
+ tristateDoes this option need a description string?
What meaning?
Could you tell me details?
--------------
config USB_PCH
tristate
depends on USB_GADGET_PCH default USB_GADGET
select USB_GADGET_SELECTED
--------------
We wrote this block like description of other drivers.
Best regards
Toshiharu Okada (OKI SEMICONDUCTOR)
----- Original Message -----
Date: Wed, 3 Nov 2010 11:37:50 -0700
From: Andy Isaacson <[email protected]>
Subject: Re: [PATCH v7] USB device driver of Topcliff PCH
Quoted 7 lines · Toshiharu Okada
Quoted 6 lines
This patch adds the USB device driver of EG20T PCH.
EG20T PCH is the platform controller hub that is going to be used in Intel's upcoming general embedded platform. All IO peripherals in EG20T PCH are actually devices sitting on AMBA bus.
EG20T PCH has USB device I/F. Using this I/F, it is able to access
system
Quoted 57 lines
Quoted 4 lines
devices connected to USB device.
+config
USB_GADGET_PCH
+ boolean "PCH USB Device controller"This description is way too generic. "Intel EG20T (Topcliff) USB Device controller" would be better. The config option should probably be
USB_GADGET_EG20Tas well.drivers/usb/gadget/Kconfig config USB_LANGWELL · line 521
Quoted 8 lines
drivers/usb/gadget/Kconfig +8
-0+ EG20T PCH is the platform controller hub that is used in Intel's + general embedded platform. EG20T 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 supports both control transfer and bulk transfer modes."
drivers/usb/gadget/Kconfig config USB_LANGWELL · line 523
Quoted 2 lines
drivers/usb/gadget/Kconfig +2
-0+ This driver dose not support interrupt transfer, and isochronous + transfer modes."This driver does not support interrupt transfer or isochronous transfer modes."
Quoted 2 lines
+config
USB_PCH
+ tristateDoes this option need a description string?
Quoted 1 line
+++
b/drivers/usb/gadget/pch_udc.c[snip]
Quoted 11 lines
drivers/usb/gadget/pch_udc.c new file +11
-0+#include <linux/types.h> +#include <linux/module.h> +#include <linux/pci.h> +#include <linux/kernel.h> +#include <linux/delay.h> +#include <linux/ioport.h> +#include <linux/sched.h> +#include <linux/slab.h> +#include <linux/smp_lock.h> +#include <linux/errno.h> +#include <linux/init.h> drivers/usb/gadget/pch_udc.c line 38
Quoted 10 lines
drivers/usb/gadget/pch_udc.c new file +10
-0+#include <linux/timer.h> +#include <linux/list.h> +#include <linux/interrupt.h> +#include <linux/ioctl.h> +#include <linux/fs.h> +#include <linux/dmapool.h> +#include <linux/moduleparam.h> +#include <linux/device.h> +#include <linux/io.h> +#include <linux/irq.h> Do you really need all of these includes?
Quoted 11 lines
drivers/usb/gadget/pch_udc.c line 139
Quoted 5 lines
drivers/usb/gadget/pch_udc.c new file +5
-0+#define UDC_DEVSTS_TS_OFS 18 +#define UDC_DEVSTS_ENUM_SPEED_OFS 13 +#define UDC_DEVSTS_ALT_OFS 8 +#define UDC_DEVSTS_INTF_OFS 4 +#define UDC_DEVSTS_CFG_OFS 0Please rename all
_OFSconstants to_SHIFTfor clarity. (However, if the rename will cause many lines to exceed 80 characters, then please choose another name.)Quoted 1 line
+static void pch_udc_write_csr(struct
pch_udc_dev*dev, unsigned long
val,
Quoted 210 lines
drivers/usb/gadget/pch_udc.c line 495
Quoted 3 lines
drivers/usb/gadget/pch_udc.c new file +3
-0+ unsigned int ep) +{ +unsigned long reg =PCH_UDC_CSR (ep);Add a blank line between variables and code.
Quoted 11 lines
+
pch_udc_csr_busy(dev); /* Wait till idle */
+pch_udc_writel(dev, val, reg);+/**
+ *pch_udc_read_csr()- Read the command and status registers.
+ * @dev: Reference topch_udc_devstructure
+ * @addr: address of CSR register
+ * Returns
+ * content of CSR register
+ */Please read
Documentation/kernel-doc-nano-HOWTO.txtand verify this is correct. I am not sure, but I think you need a blank line after the last @variable, and should say "Return value:".drivers/usb/gadget/pch_udc.c line 510
Quoted 3 lines
drivers/usb/gadget/pch_udc.c new file +3
-0+static u32 pch_udc_read_csr (struct pch_udc_dev *dev,unsigned int ep) +{ +unsigned long reg =PCH_UDC_CSR (ep);Please check all your functions and ensure there is a proper blank line here.
Quoted 5 lines
+
pch_udc_csr_busy(dev); /* Wait till idle */
+pch_udc_readl(dev, reg); /* Dummy read */
+pch_udc_csr_busy(dev); /* Wait till idle */Quoted 8 lines
+/**
+ *pch_udc_clear_dma()- Clear the 'TDE' or RDE bit of device control
+ * register depending on the direction specified
+ * @dev: Reference to structure of typepch_udc_regs
+ * @dir: Whether Tx or Rx
+ * - dir =DMA_DIR_RXReceive
+ * - dir =DMA_DIR_TXTransmit
+ */This will not format correctly, please read nano-howto.txt.
drivers/usb/gadget/pch_udc.c line 743
Quoted 7 lines
drivers/usb/gadget/pch_udc.c new file +7
-0+static inline void pch_udc_clear_dma (struct pch_udc_dev *dev,int dir) +{ +if (dir ==DMA_DIR_RX ) +pch_udc_bit_clr (dev,UDC_DEVCTL_ADDR ,UDC_DEVCTL_RDE ); +else if (dir ==DMA_DIR_TX ) +pch_udc_bit_clr (dev,UDC_DEVCTL_ADDR ,UDC_DEVCTL_TDE ); +Delete this extra blank line. Check for unneeded blank lines throughout.
Quoted 7 lines
+}
+
pr_debug("%s: enter req->req.dma=0x%08x", __func__, req->req.dma);
+ /* set buffer pointer */
+req->td_data->dataptr=req->req.dma;
+ /* set last bit */These comments are useless, because they just repeat what the code says. Please remove them or replace them with comments that actually explain what is happening. For example, this line could use a comment:
Quoted 1 line
+
req->td_data->status|=PCH_UDC_DMA_LAST;*Why* are we setting
DMA_LAST? (I *think* I know, but am not entirely sure.) Probably it doesn't need a comment at all, but if it does, the comment should answer the "Why?" question.You have many examples of this pattern of one-comment-per-line-of-code. Please review them all.
[snip]
Quoted 3 lines
+ /* if bytes < max packet then tx bytes must
+ * be written in packet per buffer mode
+ */This is a good comment!
Quoted 2 lines
+ if ((
req->req.length<ep->ep.maxpacket) || !ep->num)
+ /* write the count */This is a bad comment.
Quoted 2 lines
+
req->td_data->status= (req->td_data->status&
+ ~PCH_UDC_RXTX_BYTES) |req->req.length;[snip]
drivers/usb/gadget/pch_udc.c line 1488
Quoted 9 lines
drivers/usb/gadget/pch_udc.c new file +9
-0+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; + ep->td_data = req->td_data; +/* Set the status bits for all descriptors */ Here is an example of a one-line comment that is not bad, since it explains why the loop is here. So in your review, be careful not to remove good comments like this...
Quoted 9 lines
+ 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=phys_to_virt(td_data->next);
+ }
+ /* Write the descriptor pointer */
+pch_udc_ep_set_ddptr(ep, req->td_data_phys);Suprisingly, this comment is good too, I think, since it helps explain the effect of
set_ddptr.Quoted 5 lines
+ dev_dbg(&dev->pdev->dev, "%s: req = 0x%p
dma_desc= 0x%p,td_phys= "
+ "0x%08lx",__func__, req,dma_desc,
+ (unsigned long)req->td_data_phys);
+ /* prevent from using desc. - set HOST BUSY */
+dma_desc->status|=PCH_UDC_BS_HST_BSY;This comment should explain what is being prevented from using desc, I think it's the USB controller but the comment should explain clearly.
Quoted 2 lines
drivers/usb/gadget/pch_udc.c new file +2
-0+static int pch_udc_pcd_set_halt (struct usb_ep *usbep,int halt) +{[snip]
Quoted 6 lines
+ if (!list_empty(&ep->queue)) {
+dev_dbg(&dev->pdev->dev, "%s: list not empty", __func__);
+ ret =-EAGAIN;
+ } else if (!halt) { /* halt or clear halt */
+pch_udc_ep_clear_stall(ep);
+ ret = 0;Quoted 8 lines
+ } else {
+ if (ep->num==PCH_UDC_EP0)
+ep->dev->stall= 1;
+pch_udc_ep_set_stall(ep);
+ pch_udc_enable_ep_interrupts(ep->dev,
+PCH_UDC_EPINT(ep->in, ep->num));
+ ret = 0;
+ }I think this would be clearer as
+ if (!list_empty(&ep->queue)) {
+dev_dbg(&dev->pdev->dev, "%s: list not empty", __func__);
+ ret =-EAGAIN;
+ }
+ if (halt) {
+ if (ep->num==PCH_UDC_EP0)
+ep->dev->stall= 1;
+pch_udc_ep_set_stall(ep);
+ pch_udc_enable_ep_interrupts(ep->dev,
+PCH_UDC_EPINT(ep->in, ep->num));
+ ret = 0;
+ } else {
+pch_udc_ep_clear_stall(ep);
+ ret = 0;
+ }because:
1. if (!list_empty is a standalone check, there is no if/else if/else connection betweenlist_empty()and halt.
2. I prefer if (foo) {} else {} instead of if (!foo) {} else {}, unless there is a significant reason to do the negated test.Quoted 1 line
+ struct
pch_udc_ep*ep ;random extra whitespace before ;.
Quoted 1 line
+
pr_debug("%s: %s", __func__, usbep->name);There are probably too many
pr_debug()and dev_dbg()s in this driver. Please reconsider which ones are appropriate for mainline.Quoted 1 line
+#ifdef
DMA_PPB_WITH_DESC_UPDATEI don't see this defined anywhere, is this dead code?
Quoted 4 lines
+ } else if ((((stat &
UDC_EPSTS_OUT_MASK) >>UDC_EPSTS_OUT_OFS) ==
+UDC_EPSTS_OUT_DATA) && !dev->stall) {
+ if (list_empty(&ep->queue)) {
+dev_err(&dev->pdev->dev, "%s: ZLP", __func__);Please provide a useful error message here.
Quoted 3 lines
+ for (i = 0; i <
PCH_UDC_EP_NUM; i++) {
+ ep = &dev->ep[i];
+pch_udc_clear_ep_status(ep, 0x1F0006F0);This magic number needs a #define.
Overall, the code cleanliness looks OK once the above are addressed. I am not qualified to review the USB gadget interfaces, but the general structure appears to be sane.
-andy
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 15 lines · Toshiharu Okada
Quoted 14 lines
drivers/usb/gadget/pch_udc.c new file +14
-0+if (!list_empty (&ep->queue)) { +dev_dbg (&dev->pdev->dev,"%s: list not empty" , __func__); + ret = -EAGAIN ; + }else if (!halt) {/* halt or clear halt */ +pch_udc_ep_clear_stall (ep); + ret =0 ; + }else { +if (ep->num ==PCH_UDC_EP0 ) + ep->dev->stall =1 ; +pch_udc_ep_set_stall (ep); +pch_udc_enable_ep_interrupts (ep->dev, +PCH_UDC_EPINT (ep->in, ep->num)); + ret =0 ; + }
Quoted 7 lines · Andy Isaacson
I think this would be clearer as
drivers/usb/gadget/pch_udc.c new file +5
-0+if (!list_empty (&ep->queue)) { +dev_dbg (&dev->pdev->dev,"%s: list not empty" , __func__); + ret = -EAGAIN ; + } +if (halt) {
drivers/usb/gadget/pch_udc.c line 1918
Quoted 10 lines
drivers/usb/gadget/pch_udc.c new file +10
-0+if (ep->num ==PCH_UDC_EP0 ) + ep->dev->stall =1 ; +pch_udc_ep_set_stall (ep); +pch_udc_enable_ep_interrupts (ep->dev, +PCH_UDC_EPINT (ep->in, ep->num)); + ret =0 ; + }else { +pch_udc_ep_clear_stall (ep); + ret =0 ; + }
This changes the behavior of the construct though.
Quoted 3 lines
because:
1. if (!list_empty is a standalone check, there is no if/else if/else connection betweenlist_empty()and halt.
This depends on how you look at it. The way I see it is that there are three mutually exclusive cases: the list is not empty, it is a halt, it is not a halt. This way, if-else-if-else seems like a good construct to me.
Quoted 2 lines
2. I prefer if (foo) {} else {} instead of if (!foo) {} else {}, unless there is a significant reason to do the negated test.
I agree on that though.
Quoted 4 lines
drivers/usb/gadget/pch_udc.c line 1934
Quoted 1 line
drivers/usb/gadget/pch_udc.c new file +1
-0+pr_debug ("%s: %s" , __func__, usbep->name);There are probably too many
pr_debug()and dev_dbg()s in this driver. Please reconsider which ones are appropriate for mainline.
Do we really care? Just don't define DEBUG...
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--
Hi Michal
Thank you for your comment.
I will modify to "if-else-if-else" as follows.
-----------
if (!list_empty(&ep->queue)) {
dev_dbg(&dev->pdev->dev, "%s: list not empty", __func__);
ret = -EAGAIN;
} else {
if (halt) { /* halt or clear halt */
if (ep->num == PCH_UDC_EP0)
ep->dev->stall = 1;
pch_udc_ep_set_stall(ep);
pch_udc_enable_ep_interrupts(ep->dev, PCH_UDC_EPINT(ep->in,
ep->num));
ret = 0;
} else {
pch_udc_ep_clear_stall(ep);
ret = 0;
}
}-------------
Best regards
Toshiharu Okada (OKI SEMICONDUCTOR)
-----
Date: Mon, 08 Nov 2010 12:22:51 +0100
From: "Michał Nazarewicz" <[email protected]>
Quoted 1 line
On Wed, 03 Nov 2010 19:37:50 +0100, Andy Isaacson <[email protected]>
Quoted 18 lines · wrote:
Quoted 17 lines
I think this would be clearer as
+ if (!list_empty(&ep->queue)) {
+dev_dbg(&dev->pdev->dev, "%s: list not empty", __func__);
+ ret =-EAGAIN;
+ }
+ if (halt) {
+ if (ep->num==PCH_UDC_EP0)
+ep->dev->stall= 1;
+pch_udc_ep_set_stall(ep);
+ pch_udc_enable_ep_interrupts(ep->dev,
+PCH_UDC_EPINT(ep->in, ep->num));
+ ret = 0;
+ } else {
+pch_udc_ep_clear_stall(ep);
+ ret = 0;
+ }
Quoted 7 lines
This changes the behavior of the construct though.
Quoted 3 lines
because:
1. if (!list_empty is a standalone check, there is no if/else if/else connection betweenlist_empty()and halt.This depends on how you look at it. The way I see it is that there are
three
Quoted 26 lines
mutually exclusive cases: the list is not empty, it is a halt, it is not a halt. This way, if-else-if-else seems like a good construct to me.
Quoted 2 lines
2. I prefer if (foo) {} else {} instead of if (!foo) {} else {}, unless there is a significant reason to do the negated test.
I agree on that though.
Quoted 4 lines
Quoted 1 line
+
pr_debug("%s: %s", __func__, usbep->name);There are probably too many
pr_debug()and dev_dbg()s in this driver. Please reconsider which ones are appropriate for mainline.Do we really care? Just don't define DEBUG...
Signature · 9 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-- -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
Quoted 18 lines · Toshiharu Okada
I will modify to "if-else-if-else" as follows.
if (!list_empty(&ep->queue)) { dev_dbg(&dev->pdev->dev, "%s: list not empty", __func__); ret = -EAGAIN; } else { if (halt) { /* halt or clear halt */ if (ep->num == PCH_UDC_EP0) ep->dev->stall = 1; pch_udc_ep_set_stall(ep); pch_udc_enable_ep_interrupts(ep->dev, PCH_UDC_EPINT(ep->in, ep->num)); ret = 0; } else { pch_udc_ep_clear_stall(ep); ret = 0; } }
In that case, make it:
if (list_empty(&ep->queue)) {
if (halt) { /* halt or clear halt */
if (ep->num == PCH_UDC_EP0)
ep->dev->stall = 1;
pch_udc_ep_set_stall(ep);
pch_udc_enable_ep_interrupts(ep->dev, PCH_UDC_EPINT(ep->in, ep->num));
} else {
pch_udc_ep_clear_stall(ep);
}
ret = 0;
} else {
dev_dbg(&dev->pdev->dev, "%s: list not empty", __func__);
ret = -EAGAIN;
}Ie. no need to put "ret = 0;" twice in the code.
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--
Hi Michal
Thank you for your comment.
I will modify.
Best regards
Toshiharu Okada (OKI SEMICONDUCTOR)
----- Original Message -----
Date: Wed, 10 Nov 2010 13:29:58 +0100
From: "Michał Nazarewicz" <[email protected]>
Quoted 20 lines
In that case, make it:
if (
list_empty(&ep->queue)) {
if (halt) { /* halt or clear halt */
if (ep->num==PCH_UDC_EP0)ep->dev->stall= 1;pch_udc_ep_set_stall(ep);pch_udc_enable_ep_interrupts(ep->dev, PCH_UDC_EPINT(ep->in, ep->num)); } else {pch_udc_ep_clear_stall(ep);
}
ret = 0;
} else {dev_dbg(&dev->pdev->dev, "%s: list not empty", __func__); ret =-EAGAIN;
}Ie. no need to put "ret = 0;" twice in the code.