USB device driver of Topcliff PCH
PATCH 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 | 3153 +++++++++++++++++++++++++++++++++++++ drivers/usb/gadget/pch_udc.h | 495 ++++++ 5 files changed, 3680 insertions(+), 1 deletions(-) create mode 100755 drivers/usb/gadget/pch_udc.c create mode 100755 drivers/usb/gadget/pch_udc.h
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 Dev" + 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 +3153 -0
2,946 lines not on this page · raw message
drivers/usb/gadget/pch_udc.h new file +495 -0
495 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.
2010/9/7 Masayuki Ohtake <[email protected]>
Quoted 9 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.Signed-off-by Masayuki Ohtake <[email protected]>
No need to mail all these people, just the maintainers and appropriate mailing lists will do.
Quoted 10 lines
---
drivers/usb/gadget/Kconfig | 24 +drivers/usb/gadget/Makefile| 2 +-drivers/usb/gadget/gadget_chips.h| 7 +drivers/usb/gadget/pch_udc.c| 3153 +++++++++++++++++++++++++++++++++++++drivers/usb/gadget/pch_udc.h| 495 ++++++5 files changed, 3680 insertions(+), 1 deletions(-)create mode 100755
drivers/usb/gadget/pch_udc.c
create mode 100755drivers/usb/gadget/pch_udc.h
[snip]
Quoted 5 lines
drivers/usb/gadget/pch_udc.c new file +0
-0
[snip]
drivers/usb/gadget/pch_udc.c line 69
Quoted 9 lines
drivers/usb/gadget/pch_udc.c new file +9
-0+ +const char ep0_string[] = "ep0in"; +static DEFINE_SPINLOCK(udc_stall_spinlock); /* stall spin lock */ +static u32 pch_udc_base; +static union pch_udc_setup_data setup_data; /* received setup data */ +static unsigned long ep0out_buf[64 ]; +static dma_addr_t dma_addr; +struct pch_udc_dev *pch_udc; /* pointer to device object */ +int speed_fs;
I'd put all these in struct phc_udc_dev or similar, so you could have multiple controllers.
drivers/usb/gadget/pch_udc.c line 81
Quoted 12 lines
drivers/usb/gadget/pch_udc.c new file +12
-0+ +module_param_named (speed_fs, speed_fs, bool,S_IRUGO ); +MODULE_PARM_DESC (speed_fs,"true for Full speed operation" ); +MODULE_DESCRIPTION ("OKISEMI PCH UDC - USB Device Controller" ); +MODULE_LICENSE ("GPL" ); + +/** +* pch_udc_write_csr - Write the command and status registers. +* @val: value to be written to CSR register +* @addr: address of CSR register +*/ +inline void pch_udc_write_csr (unsigned long val,unsigned long addr)
Make all these functions static.
drivers/usb/gadget/pch_udc.c line 88
Quoted 7 lines
drivers/usb/gadget/pch_udc.c new file +7
-0+{ + int count = MAX_LOOP; + + /* Wait till idle */ + while ((count > 0) &&\ + (ioread32((u32 *)(PCH_UDC_CSR_BUSY_ADDR + pch_udc_base)) & + PCH_UDC_CSR_BUSY))
Why not define PCH_UDC_* as (void __iomem*) so no casting is necessary.
Quoted 15 lines
+ count--;
drivers/usb/gadget/pch_udc.c new file +14
-0+ + if (count < 0) + pr_debug("%s: wait error; count = %x", __func__, count); + + iowrite32(val, (u32 *)addr); + /* Wait till idle */ + count = MAX_LOOP; + while ((count > 0) && + (ioread32((u32 *)(PCH_UDC_CSR_BUSY_ADDR + pch_udc_base)) & + PCH_UDC_CSR_BUSY)) + count--; + + if (count < 0) + pr_debug("%s: wait error; count = %x", __func__, count);
drivers/usb/gadget/pch_udc.c line 113
Quoted 10 lines
drivers/usb/gadget/pch_udc.c new file +10
-0+ +} + +/** +* pch_udc_read_csr - Read the command and status registers. +* @addr: address of CSR register +* Returns +* content of CSR register +*/ +inline u32 pch_udc_read_csr (unsigned long addr)
void __iomem *addr
Quoted 37 lines
drivers/usb/gadget/pch_udc.c new file +37
-0+{ + int count = MAX_LOOP; + + /* Wait till idle */ + while ((count > 0) && + (ioread32((u32 *)(PCH_UDC_CSR_BUSY_ADDR + pch_udc_base)) & + PCH_UDC_CSR_BUSY)) + count--; + + if (count < 0) + pr_debug("%s: wait error; count = %x", __func__, count); + /* Dummy read */ + ioread32((u32 *)addr); + count = MAX_LOOP; + /* Wait till idle */ + while ((count > 0) && + (ioread32((u32 *)(PCH_UDC_CSR_BUSY_ADDR + pch_udc_base)) & + PCH_UDC_CSR_BUSY)) + count--; + /* actual read */ + if (count < 0) + pr_debug("%s: wait error; count = %x", __func__, count); + + return ioread32((u32 *)addr); +} + +/** +* pch_udc_rmt_wakeup - Initiate for remote wakeup +* @dev: Reference to pch_udc_regs structure +*/ +inline void pch_udc_rmt_wakeup (struct pch_udc_regs *dev) +{ + PCH_UDC_BIT_SET(&dev->devctl, 1 << UDC_DEVCTL_RES); + mdelay(1); + PCH_UDC_BIT_CLR(&dev->devctl, 1 << UDC_DEVCTL_RES); +} +
drivers/usb/gadget/pch_udc.c line 160
Quoted 10 lines
drivers/usb/gadget/pch_udc.c new file +10
-0+/** +* pch_udc_get_frame - Get the current frame from device status register +* @dev: Reference to pch_udc_regs structure +* Retern current frame +*/ +inline int pch_udc_get_frame (struct pch_udc_regs *dev) +{ + u32 frame; + + frame = ioread32(&dev->devsts);
Why not just get rid of struct pch_udc_regs and do something like:
static inline u32 pch_readl(struct pch_udc_dev *dev, unsigned long reg)
{
return ioread32(dev->base_addr + reg);
}(and similar for pch_writel)
Quoted 2 lines
+ return (frame &
UDC_DEVSTS_TS_MASK) >>UDC_DEVSTS_TS_OFS; +}
[snip]
Quoted 8 lines
drivers/usb/gadget/pch_udc.c new file +8
-0+static struct usb_request *pch_udc_alloc_request (struct usb_ep *usbep, + gfp_t gfp) +{ + struct pch_udc_request *req; + struct pch_udc_ep *ep; + + pr_debug("%s: enter", __func__); + if (usbep == NULL)
drivers/usb/gadget/pch_udc.c line 1365
Quoted 10 lines
drivers/usb/gadget/pch_udc.c new file +10
-0+ return NULL; + + ep = container_of(usbep, struct pch_udc_ep, ep); + pr_debug("%s: ep %s", __func__, usbep->name); + req = kzalloc(sizeof(struct pch_udc_request), gfp); + if (req == NULL) { + pr_debug("%s: no memory for request", __func__); + return NULL; + } + memset(req, 0, sizeof(struct pch_udc_request));
kzalloc does this..
Quoted 27 lines
+
req->req.dma=DMA_ADDR_INVALID;
+INIT_LIST_HEAD(&req->queue);drivers/usb/gadget/pch_udc.c new file +25
-0+ + if (ep->dma != NULL) { + struct pch_udc_data_dma_desc *dma_desc; + + /* ep0 in requests are allocated from data pool here */ + dma_desc = pci_pool_alloc(ep->dev->data_requests, gfp, + &req->td_data_phys); + if (NULL == dma_desc) { + kfree(req); + return NULL; + } + + pr_debug("%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; + dma_desc->dataptr = __constant_cpu_to_le32(DMA_ADDR_INVALID); + req->td_data = dma_desc; + req->td_data_last = dma_desc; + req->chain_len = 1; + } + return &req->req; +}
[snip]
Quoted 5 lines
drivers/usb/gadget/pch_udc.c new file +5
-0+ +/** +* pch_udc_start_next_txrequest - This function starts +* the next transmission requirement +* @ep: Reference to the endpoint structure
drivers/usb/gadget/pch_udc.c line 1760
Quoted 10 lines
drivers/usb/gadget/pch_udc.c new file +10
-0+*/ +static void pch_udc_start_next_txrequest (struct pch_udc_ep *ep) +{ + struct pch_udc_request *req; + + pr_debug("%s: enter", __func__); + if (pch_udc_read_ep_control(ep->regs) & (1 << UDC_EPCTL_P)) + return; + + if (!list_empty(&ep->queue)) {
Convert this into:
if (list_empty(&ep->queue))
return;
That way you get rid of the unnecessary spacing below
Quoted 45 lines
+ /* next request */
+ req =list_entry(ep->queue.next, struct pch_udc_request, queue);
+ if (req && !req->dma_going) {
+ pr_debug("%s: Set request: req=%p req->td_data=%p",
+__func__, req,req->td_data);
+ if (req->td_data) {
+ structpch_udc_data_dma_desc*td_data;drivers/usb/gadget/pch_udc.c new file +38
-0+ + while (pch_udc_read_ep_control(ep->regs) & + (1 << UDC_EPCTL_S)) + udelay(100); + + req->dma_going = 1; + /* Clear the descriptor pointer */ + pch_udc_ep_set_ddptr(ep->regs, 0); + + td_data = req->td_data; + 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); + } + /* Write the descriptor pointer */ + pch_udc_ep_set_ddptr(ep->regs, + req->td_data_phys); + pch_udc_set_dma(ep->dev->regs, DMA_DIR_TX); + /* Set the poll demand bit */ + pch_udc_ep_set_pd(ep->regs); + pch_udc_enable_ep_interrupts(ep->dev->regs, + 1 << (ep->in ? ep->num :\ + ep->num + UDC_EPINT_OUT_EP0)); + pch_udc_ep_clear_nak(ep->regs); + } + } + } +} +
drivers/usb/gadget/pch_udc.c line 1815
Quoted 10 lines
drivers/usb/gadget/pch_udc.c new file +10
-0+/** +* pch_udc_complete_transfer - This function completes a transfer +* @ep: Reference to the endpoint structure +*/ +static void pch_udc_complete_transfer(struct pch_udc_ep *ep) +{ + struct pch_udc_request *req; + + pr_debug("%s: enter", __func__); + if (!list_empty(&ep->queue)) {
Same here
Quoted 55 lines
+
pr_debug("%s: list_entry", __func__);
+ 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)) {drivers/usb/gadget/pch_udc.c new file +51
-0+#ifdef DMA_PPB_WITH_DESC_UPDATE + struct pch_udc_data_dma_desc *td_data = req->td_data; + for (i = 0; i < req->chain_len; i++) { + if ((td_data->status & PCH_UDC_RXTX_STS) != + PCH_UDC_RTS_SUCC) { + pr_err("Invalid RXTX status (0x%08x)" + " epstatus=0x%08x\n", + (td_data->status & + PCH_UDC_RXTX_STS), + (int)(ep->epsts)); + return; + } + td_data = (struct pch_udc_data_dma_desc *) + phys_to_virt(td_data->next); + } +#else + if ((req->td_data_last->status & PCH_UDC_RXTX_STS) != + PCH_UDC_RTS_SUCC) { + pr_err("Invalid RXTX status (0x%08x)" + " epstatus=0x%08x\n", + (req->td_data_last->status & + PCH_UDC_RXTX_STS), + (int)(ep->epsts)); + return; + } +#endif + req->req.actual = req->req.length; + req->td_data_last->status = PCH_UDC_BS_HST_BSY | + PCH_UDC_DMA_LAST; + req->td_data->status = PCH_UDC_BS_HST_BSY | + PCH_UDC_DMA_LAST; + /* complete req */ + complete_req(ep, req, 0); + req->dma_going = 0; + if (!list_empty(&ep->queue)) { + while (pch_udc_read_ep_control(ep->regs) & + (1 << UDC_EPCTL_S)) + udelay(100); + + pch_udc_ep_clear_nak(ep->regs); + pch_udc_enable_ep_interrupts(ep->dev->regs, + 1 << (ep->in ? ep->num : ep->num + + UDC_EPINT_OUT_EP0)); + } else { + pch_udc_disable_ep_interrupts(ep->dev->regs, + 1 << (ep->in ? ep->num : ep->num + + UDC_EPINT_OUT_EP0)); + } + } + } +}
[snip]
Quoted 20 lines
drivers/usb/gadget/pch_udc.c new file +20
-0+ +/** +* pch_udc_svc_enum_interrupt - This function handles a USB speed enumeration +* done interrupt +* @dev: Reference to driver structure +*/ +void +pch_udc_svc_enum_interrupt (struct pch_udc_dev *dev) +{ + u32 dev_stat, dev_speed; + u32 speed = USB_SPEED_FULL; + + pr_debug("%s: enter", __func__); + dev_stat = pch_udc_read_device_status(dev->regs); + dev_speed = (dev_stat & UDC_DEVSTS_ENUM_SPEED_MASK) >> + UDC_DEVSTS_ENUM_SPEED_OFS; + + pr_debug("%s: dev_speed = 0x%08x", __func__, dev_speed); + + if (dev_speed == UDC_DEVSTS_ENUM_SPEED_HIGH) {
drivers/usb/gadget/pch_udc.c line 2431
Quoted 10 lines
drivers/usb/gadget/pch_udc.c new file +10
-0+ pr_debug("HighSpeed"); + speed = USB_SPEED_HIGH; + } else if (dev_speed == UDC_DEVSTS_ENUM_SPEED_FULL) { + pr_debug("FullSpeed"); + speed = USB_SPEED_FULL; + } else if (dev_speed == UDC_DEVSTS_ENUM_SPEED_LOW) { + pr_debug("LowSpeed?"); + speed = USB_SPEED_LOW; + } else { + pr_debug("FullSpeed?");
BUG() perhaps? Also, change this into a switch statement
Quoted 17 lines
+ }
+dev->gadget.speed= speed;drivers/usb/gadget/pch_udc.c new file +15
-0+ + pch_udc_activate_control_ep(dev); + + /* enable ep0 interrupts */ + pch_udc_enable_ep_interrupts(dev->regs, 1 << UDC_EPINT_IN_EP0 | + 1 << UDC_EPINT_OUT_EP0); + /* enable DMA */ + pch_udc_set_dma(dev->regs, DMA_DIR_TX); + pch_udc_set_dma(dev->regs, DMA_DIR_RX); + pch_udc_ep_set_rrdy(dev->ep[UDC_EP0OUT_IDX].regs); + + + pr_debug("%s: EP mask set to %x", __func__, + ioread32(&dev->regs->epirqmsk)); +}
[snip]
Quoted 13 lines
drivers/usb/gadget/pch_udc.c new file +13
-0+ +int pch_udc_probe (struct pci_dev *pdev,const struct pci_device_id *id) +{ + unsigned long resource; + unsigned long len; + int retval = 0; + struct pch_udc_dev *dev; + + dev_dbg(&pdev->dev, "%s: enter", __func__); + /* one udc only */ + if (pch_udc != NULL) { + dev_err(&pdev->dev, "%s: already probed", __func__); + return -EBUSY;
drivers/usb/gadget/pch_udc.c line 3032
Quoted 10 lines
drivers/usb/gadget/pch_udc.c new file +10
-0+ } + + /* init */ + dev = kzalloc(sizeof(struct pch_udc_dev), GFP_KERNEL); + if (dev == NULL) { + dev_err(&pdev->dev, "%s: no memory for device structure", + __func__); + return -ENOMEM; + } + memset(dev, 0, sizeof(struct pch_udc_dev));
kzalloc already does this for you
Quoted 98 lines
+ /* pci setup */
+ if (pci_enable_device(pdev)< 0) {
+ kfree(dev);
+dev_err(&pdev->dev, "%s: pci_enable_device failed", __func__);
+ return-ENODEV;
+ }
+dev->active= 1;
+pci_set_drvdata(pdev, dev);drivers/usb/gadget/pch_udc.c new file +90
-0+ + /* PCI resource allocation */ + resource = pci_resource_start(pdev, 1); + len = pci_resource_len(pdev, 1); + dev_dbg(&pdev->dev, "%s: resource %lx, len %ld", + __func__, resource, len); + + if (request_mem_region(resource, len, KBUILD_MODNAME) == NULL) { + dev_err(&pdev->dev, "%s: pci device used already", __func__); + retval = -EBUSY; + goto finished; + } + dev->phys_addr = resource; + dev->mem_region = 1; + + dev->virt_addr = ioremap_nocache(resource, len); + if (dev->virt_addr == NULL) { + dev_err(&pdev->dev, "%s: device memory cannot be mapped", + __func__); + retval = -ENOMEM; + goto finished; + } + dev_dbg(&pdev->dev, "%s: device memory mapped at %x", __func__, + (int)dev->virt_addr); + + if (pdev->irq == 0) { + dev_err(&pdev->dev, "%s: irq not set", __func__); + retval = -ENODEV; + goto finished; + } + + pch_udc = dev; + + /* initialize the hardware */ + if (pch_udc_pcd_init(dev) != 0) + goto finished; + + if (request_irq(pdev->irq, pch_udc_isr, IRQF_SHARED, + KBUILD_MODNAME, dev) != 0) { + dev_err(&pdev->dev, "%s: request_irq(%d) fail", __func__, + pdev->irq); + retval = -ENODEV; + goto finished; + } + dev->irq = pdev->irq; + dev->irq_registered = 1; + + pci_set_master(pdev); + pci_try_set_mwi(pdev); + + /* device struct setup */ + spin_lock_init(&dev->lock); + dev->pdev = pdev; + dev->gadget.ops = &pch_udc_ops; + + retval = init_dma_pools(dev); + if (retval != 0) + goto finished; + + dev_set_name(&dev->gadget.dev, "gadget"); + dev->gadget.dev.parent = &pdev->dev; + dev->gadget.dev.dma_mask = pdev->dev.dma_mask; + dev->gadget.dev.release = gadget_release; + dev->gadget.name = KBUILD_MODNAME; + dev->gadget.is_dualspeed = 1; + + retval = device_register(&dev->gadget.dev); + if (retval != 0) + goto finished; + dev->registered = 1; + + /* Put the device in disconnected state till a driver is bound */ + pch_udc_set_disconnect(dev->regs); + return 0; + +finished: + pch_udc_remove(pdev); + return retval; +} + +static const struct pci_device_id pch_udc_pcidev_id[] = { + { + PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_PCH1_UDC), + .class = (PCI_CLASS_SERIAL_USB << 8) | 0xfe, + .class_mask = 0xffffffff, + }, + { 0 }, +}; + +MODULE_DEVICE_TABLE (pci, pch_udc_pcidev_id);
drivers/usb/gadget/pch_udc.c line 3140
Quoted 10 lines
drivers/usb/gadget/pch_udc.c new file +10
-0+ + +static struct pci_driver pch_udc_driver = { + .name = KBUILD_MODNAME, + .id_table = pch_udc_pcidev_id, + .probe = pch_udc_probe, + .remove = pch_udc_remove, + .suspend = pch_udc_suspend, + .resume = pch_udc_resume, + .shutdown = pch_udc_shutdown,
Make all these functions static
Quoted 54 lines
drivers/usb/gadget/pch_udc.c new file +13
-0+}; + +static int __init pch_udc_pci_init (void ) +{ + return pci_register_driver(&pch_udc_driver); +} +module_init (pch_udc_pci_init); + +static void __exit pch_udc_pci_exit(void) +{ + pci_unregister_driver(&pch_udc_driver); +} +module_exit (pch_udc_pci_exit);drivers/usb/gadget/pch_udc.h new file +35
-0@@ -0,0 +1,495 @@ +/* +* Copyright (C) 2010 OKI SEMICONDUCTOR Co., LTD. +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; version 2 of the License. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. +*/ + +#ifndef _PCH_UDC_H_ +#define _PCH_UDC_H_ + +/* Address offset of Registers */ +#define UDC_EPIN_REGS_ADDR 0x000 +#define UDC_EPOUT_REGS_ADDR 0x200 +#define UDC_EP_REG_OFS 0x20/* Offset to next EP */ +#define UDC_DEVCFG_ADDR 0x400 +#define PCH_UDC_CSR_BUSY_ADDR 0x4f0 +#define PCH_UDC_SRST_ADDR 0x4fc +#define UDC_CSR_ADDR 0x500 + +/* Bit position in UDC CSR Busy status Register */ +#define PCH_UDC_CSR_BUSY 1 +/* Bit position in UDC Soft reset Register */ +#define PCH_UDC_PSRST 1 +#define PCH_UDC_SRST 0 +
[snip]
drivers/usb/gadget/pch_udc.h line 70
Quoted 6 lines
drivers/usb/gadget/pch_udc.h new file +6
-0+ +/** +* pch_udc_csrs - Structure to Endpoint configuration registers +*/ +struct pch_udc_csrs { + u32 ne[PCH_UDC_USED_EP_NUM * 2];
Why not do away with the structs and do something like:
#define PCH_UDC_CSR(ep) (UDC_CSR_ADDR + ep*4)
(and similar for the others)
Quoted 18 lines
drivers/usb/gadget/pch_udc.h new file +18
-0+/* Starting bit position */ +#define UDC_CSR_NE_NUM_OFS 0 +#define UDC_CSR_NE_DIR_OFS 4 +#define UDC_CSR_NE_TYPE_OFS 5 +#define UDC_CSR_NE_CFG_OFS 7 +#define UDC_CSR_NE_INTF_OFS 11 +#define UDC_CSR_NE_ALT_OFS 15 +#define UDC_CSR_NE_MAX_PKT_OFS 19 +/* Mask patern */ +#define UDC_CSR_NE_NUM_MASK 0x0000000f +#define UDC_CSR_NE_DIR_MASK 0x00000010 +#define UDC_CSR_NE_TYPE_MASK 0x00000060 +#define UDC_CSR_NE_CFG_MASK 0x00000780 +#define UDC_CSR_NE_INTF_MASK 0x00007800 +#define UDC_CSR_NE_ALT_MASK 0x00078000 +#define UDC_CSR_NE_MAX_PKT_MASK 0x3ff80000 +}; +
[snip]
Quoted 5 lines
drivers/usb/gadget/pch_udc.h new file +5
-0+ +/** +* pch_udc_request - Structure holding a PCH USB device request +* @req embedded ep request +* @td_data_phys phys. address
drivers/usb/gadget/pch_udc.h line 380
Quoted 10 lines
drivers/usb/gadget/pch_udc.h new file +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 */ +{
I don't see any reason to not put this in the main .c file? (same for struct pch_udc_{ep,request})
Quoted 11 lines
+ struct
usb_requestreq;
+dma_addr_ttd_data_phys;
+ structpch_udc_data_dma_desc*td_data;
+ structpch_udc_data_dma_desc*td_data_last;
+ structlist_headqueue;
+ unsigned dma_going:1,
+ dma_mapped:1,
+ dma_done:1;
+ unsigned chain_len;drivers/usb/gadget/pch_udc.h new file +2
-0+}; +
[snip]
Quoted 11 lines
drivers/usb/gadget/pch_udc.h new file +11
-0+ +struct pch_udc_dev { + struct usb_gadget gadget; + struct usb_gadget_driver *driver; + struct pci_dev *pdev; + /* all endpoints */ + struct pch_udc_ep ep[PCH_UDC_EP_NUM]; + spinlock_t lock; + unsigned active:1, + stall:1, + prot_stall:1,
drivers/usb/gadget/pch_udc.h line 475
Quoted 10 lines
drivers/usb/gadget/pch_udc.h new file +10
-0+ irq_registered:1, + mem_region:1, + registered:1, + suspended:1, + connected:1, + set_cfg_not_acked:1, + waiting_zlp_ack:1; + struct pch_udc_csrs __iomem *csr; + struct pch_udc_regs __iomem *regs; + struct pch_udc_ep_regs __iomem *ep_regs;
These pointers just seem unnecessary, especially as you could easily construct them in-place by adding the appropriate offset to your base address..
Quoted 7 lines
+ struct
pci_pool*data_requests;
+ structpci_pool*stp_requests;
+ unsigned longphys_addr;
+ void__iomem*virt_addr;
+ unsigned irq;
+ structpch_udc_cfg_datacfg_data; +};
���{.n�+�������+%�����ݶ��w��{.n�+����{��G�����{ay�ʇڙ�,j��f���h��������z_�(�階�ݢj"���m������G������?����&���~��iO��z��v�^�m����������?�I�
Quoted 9 lines · Masayuki Ohtake
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.Signed-off-by Masayuki Ohtake <[email protected]>
Quoted 9 lines
--- drivers/usb/gadget/Kconfig | 24 + drivers/usb/gadget/Makefile | 2 +- drivers/usb/gadget/gadget_chips.h | 7 + drivers/usb/gadget/pch_udc.c | 3153 +++++++++++++++++++++++++++++++++++++ drivers/usb/gadget/pch_udc.h | 495 ++++++ 5 files changed, 3680 insertions(+), 1 deletions(-) create mode 100755 drivers/usb/gadget/pch_udc.c create mode 100755 drivers/usb/gadget/pch_udc.h
Heh, really? executable .c and .h files? I think you need to look at your development system :)
drivers/usb/gadget/Kconfig config USB_OTG · line 224
Quoted 11 lines
drivers/usb/gadget/Kconfig +2
-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 Dev"
Please spell this out a lot more as to what it is.
Quoted 103 lines
drivers/usb/gadget/Kconfig +22
-0+ 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_IXP4XXdrivers/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.odrivers/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 +37
-0@@ -0,0 +1,3153 @@ +/* +* Copyright (C) 2010 OKI SEMICONDUCTOR Co., LTD. +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; version 2 of the License. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. +*/ +#define pr_fmt (fmt) KBUILD_MODNAME ": " fmt +#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> +#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>
drivers/usb/gadget/pch_udc.c line 47
Quoted 10 lines
drivers/usb/gadget/pch_udc.c new file +10
-0+#include <linux/irq.h> + +#include <asm/byteorder.h> +#include <asm/system.h> +#include <asm/unaligned.h> + +/* gadget stack */ +#include <linux/usb/ch9.h> +#include <linux/usb/gadget.h> +#include "pch_udc.h"
Why do you need a .h file?
drivers/usb/gadget/pch_udc.c line 55
Quoted 6 lines
drivers/usb/gadget/pch_udc.c new file +6
-0+/* macro to set a specified bit(mask) at the specified address */ +#define PCH_UDC_BIT_SET (reg, bitmask) \ + iowrite32(((ioread32((reg)) | (bitmask))), (reg)) +/* macro to clear a specified bit(mask) at the specified address */ +#define PCH_UDC_BIT_CLR (reg, bitMask) \ + iowrite32((ioread32((reg)) & (~(bitMask))), (reg))
Why not just use the iowrite32 functions directly? Or surely there's another built-in kernel macro for this somewhere, right?
drivers/usb/gadget/pch_udc.c line 59
Quoted 3 lines
drivers/usb/gadget/pch_udc.c new file +3
-0+#define MAX_LOOP 200 +#define PCH_UDC_PCI_BAR 1 +#define PCI_VENDOR_ID_INTEL 0x8086
No need to define this, it's in pci_ids.h already.
drivers/usb/gadget/pch_udc.c line 60
Quoted 1 line
drivers/usb/gadget/pch_udc.c new file +1
-0+#define PCI_DEVICE_ID_INTEL_PCH1_UDC 0x8808
I think this is there too.
drivers/usb/gadget/pch_udc.c line 69
Quoted 9 lines
drivers/usb/gadget/pch_udc.c new file +9
-0+ +const char ep0_string[] ="ep0in" ; +static DEFINE_SPINLOCK (udc_stall_spinlock);/* stall spin lock */ +static u32 pch_udc_base; +static union pch_udc_setup_data setup_data;/* received setup data */ +static unsigned long ep0out_buf[64 ]; +static dma_addr_t dma_addr; +struct pch_udc_dev *pch_udc;/* pointer to device object */ +int speed_fs;
Why are 2 of these not static variables?
Have you run this driver through the sparse tool? It will catch these errors. Please do so.
thanks,
greg k-h
Not sure why I'm on the "To" list, but here are a few of my comments:
Quoted 2 lines · Masayuki Ohtake
+/**
+ *pch_udc_write_csr- Write the command and status registers.
IIRC, the correct way to write kernel doc is:
+ * pch_udc_write_csr() - Write the command and status registers.
Note the "()". This applies to other functions as well.
Quoted 4 lines
+ * @val: value to be written to CSR register
+ * @addr: address of CSR register
+ */
+inline voidpch_udc_write_csr(unsigned long val, unsigned long addr)
As it was pointed, unless those functions are extern, make them static and remove the inline.
drivers/usb/gadget/pch_udc.c line 89
Quoted 8 lines
drivers/usb/gadget/pch_udc.c new file +8
-0+{ +int count =MAX_LOOP ; + +/* Wait till idle */ +while ((count >0 ) &&\ + (ioread32 ((u32 *)(PCH_UDC_CSR_BUSY_ADDR + pch_udc_base)) & +PCH_UDC_CSR_BUSY )) + count--;
I'd say: "while (ioread(...) && --count);" Also, I'd make count to be unsigned.
drivers/usb/gadget/pch_udc.c line 92
Quoted 3 lines
drivers/usb/gadget/pch_udc.c new file +3
-0+ +if (count <0 ) +pr_debug ("%s: wait error; count = %x" , __func__, count);
Dead code. If MAX_LOOP is >= 0 count will never get negative. Did you mean if (!count)?
drivers/usb/gadget/pch_udc.c line 103
Quoted 11 lines
drivers/usb/gadget/pch_udc.c new file +11
-0+ +iowrite32 (val, (u32 *)addr); +/* Wait till idle */ + count =MAX_LOOP ; +while ((count >0 ) && + (ioread32 ((u32 *)(PCH_UDC_CSR_BUSY_ADDR + pch_udc_base)) & +PCH_UDC_CSR_BUSY )) + count--; + +if (count <0 ) +pr_debug ("%s: wait error; count = %x" , __func__, count);
Dead code.
drivers/usb/gadget/pch_udc.c line 113
Quoted 7 lines
drivers/usb/gadget/pch_udc.c new file +7
-0+/** +* pch_udc_read_csr - Read the command and status registers. +* @addr: address of CSR register +* Returns +* content of CSR register +*/ +inline u32 pch_udc_read_csr (unsigned long addr)
All comments to the pch_udc_write_csr() function apply here as well.
drivers/usb/gadget/pch_udc.c line 200
Quoted 10 lines
drivers/usb/gadget/pch_udc.c new file +10
-0+/** +* pch_udc_get_speed - Return the speed status +* @dev: Reference to pch_udc_regs structure +* Retern The speed(LOW=1, FULL=2, HIGH=3) +*/ +inline int pch_udc_get_speed (struct pch_udc_regs __iomem *dev) +{ +u32 val; + + val =ioread32 (&dev->devsts);
It's just me, but why not join the two lines together:
+ u32 val = ioread32(&dev->devsts);
drivers/usb/gadget/pch_udc.c line 584
Quoted 13 lines
drivers/usb/gadget/pch_udc.c new file +12
-0+return (val &UDC_DEVSTS_ENUM_SPEED_MASK ) >>UDC_DEVSTS_ENUM_SPEED_OFS ; +} +/** +* pch_udc_ep_clear_nak - Set the bit 8 (CNAK field) +* of the endpoint control register +* @ep: reference to structure of type pch_udc_ep_regs +*/ +void pch_udc_ep_clear_nak (struct pch_udc_ep_regs __iomem *ep) +{ +unsigned int loopcnt =0 ; + +if (ioread32 (&ep->epctl) & (1 <<UDC_EPCTL_NAK )) {
if (!(ioread32(&ep->epctl) & (1 << UDC_EPCTL_NAK))) return;
and then drop one indention level for the rest of the function. This will help to keep indention level nearer the recommended limit of 3.
Quoted 32 lines
drivers/usb/gadget/pch_udc.c new file +32
-0+if (!(EP_IS_IN (ep))) { +while ((pch_udc_read_ep_status (ep) & + (1 <<UDC_EPSTS_MRXFIFO_EMP )) ==0 ) { +if (loopcnt++ >100000 ) { +pr_debug ("%s: RxFIFO not Empty " +"loop count = %d" , + __func__, loopcnt); +break ; + } +udelay (100 ); + } + } +while (ioread32 (&ep->epctl) & (1 <<UDC_EPCTL_NAK )) { +PCH_UDC_BIT_SET (&ep->epctl,1 <<UDC_EPCTL_CNAK ); +udelay (5 ); +if (loopcnt++ >=25 ) { +pr_debug ("%s: Clear NAK not set for" +"ep%d%s: counter=%d" , + __func__,EP_NUM (ep), + (EP_IS_IN (ep) ?"in" :"out" ), + loopcnt); +break ; + } + } + } +} + +/** +* pch_udc_ep_fifo_flush - Flush the endpoint fifo +* @ep: reference to structure of type pch_udc_ep_regs +* @dir: direction of endpoint +* - dir = 0 endpoint is OUT
drivers/usb/gadget/pch_udc.c line 626
Quoted 10 lines
drivers/usb/gadget/pch_udc.c new file +10
-0+* - dir != 0 endpoint is IN +*/ +void pch_udc_ep_fifo_flush (struct pch_udc_ep_regs __iomem *ep,int dir) +{ +unsigned int loopcnt =0 ; + +pr_debug ("%s: ep%d%s" , __func__,EP_NUM (ep), + (EP_IS_IN (ep) ?"in" :"out" )); +if (dir) {/* IN ep */ +PCH_UDC_BIT_SET (&ep->epctl,1 <<UDC_EPCTL_F );
I'd add "return;" here and move the else part out of the else dropping one indention level.
drivers/usb/gadget/pch_udc.c line 629
Quoted 3 lines
drivers/usb/gadget/pch_udc.c new file +3
-0+ }else { +if ((pch_udc_read_ep_status (ep) & + (1 <<UDC_EPSTS_MRXFIFO_EMP )) ==0 ) {
if (pch_udc_read_ep_status(ep) & (1 << UDC_EPSTS_MRXFIFO_EMP) return;
and drop indention.
Quoted 20 lines
drivers/usb/gadget/pch_udc.c new file +19
-0+PCH_UDC_BIT_SET (&ep->epctl,1 <<UDC_EPCTL_MRXFLUSH ); +/* Wait for RxFIFO Empty */ +while ((pch_udc_read_ep_status (ep) & + (1 <<UDC_EPSTS_MRXFIFO_EMP )) ==0 ) { +if (loopcnt++ >1000000 ) { +pr_debug ("RxFIFO not Empty loop" +" count = %d" , loopcnt); +break ; + } +udelay (100 ); + } +PCH_UDC_BIT_CLR (&ep->epctl,1 <<UDC_EPCTL_MRXFLUSH ); + } + } +} +/** +* pch_udc_pcd_pullup - This API is invoked to make the device +* visible/invisible to the host +* @gadget: Reference to the gadget driver
drivers/usb/gadget/pch_udc.c line 704
Quoted 10 lines
drivers/usb/gadget/pch_udc.c new file +10
-0+* @is_on: Specifies whether the pull up is made active or inactive +* Returns +* 0: Success +* -EINVAL: If the gadget passed is NULL +*/ +static int pch_udc_pcd_pullup (struct usb_gadget *gadget,int is_on) +{ +struct pch_udc_dev *dev; + +pr_debug ("%s: enter" , __func__);
It just struck me. Wouldn't it be feasible to use "dev_*" instead of "pr_*"?
drivers/usb/gadget/pch_udc.c line 889
Quoted 9 lines
drivers/usb/gadget/pch_udc.c new file +9
-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->regs); +else +pch_udc_clear_disconnect (dev->regs);
There was function that did exactly that I think. Wasn't there?
Quoted 7 lines
drivers/usb/gadget/pch_udc.c new file +6
-0+return 0 ; +} +/** +* pch_udc_start_next_txrequest - This function starts +* the next transmission requirement +* @ep: Reference to the endpoint structure
drivers/usb/gadget/pch_udc.c line 1760
Quoted 10 lines
drivers/usb/gadget/pch_udc.c new file +10
-0+*/ +static void pch_udc_start_next_txrequest (struct pch_udc_ep *ep) +{ +struct pch_udc_request *req; + +pr_debug ("%s: enter" , __func__); +if (pch_udc_read_ep_control (ep->regs) & (1 <<UDC_EPCTL_P )) +return ; + +if (!list_empty (&ep->queue)) {
if (list_empty(...))
return;
and drop indention.
drivers/usb/gadget/pch_udc.c line 1763
Quoted 3 lines
drivers/usb/gadget/pch_udc.c new file +3
-0+/* next request */ + req = list_entry(ep->queue.next, struct pch_udc_request, queue); +if (req && !req->dma_going) {
Same here.
drivers/usb/gadget/pch_udc.c line 1766
Quoted 3 lines
drivers/usb/gadget/pch_udc.c new file +3
-0+pr_debug ("%s: Set request: req=%p req->td_data=%p" , + __func__, req, req->td_data); +if (req->td_data) {
Same eher.
Quoted 9 lines
drivers/usb/gadget/pch_udc.c new file +9
-0+struct pch_udc_data_dma_desc *td_data; + +while (pch_udc_read_ep_control (ep->regs) & + (1 <<UDC_EPCTL_S )) +udelay (100 ); + + req->dma_going =1 ; +/* Clear the descriptor pointer */ +pch_udc_ep_set_ddptr (ep->regs,0 );
drivers/usb/gadget/pch_udc.c line 1785
Quoted 10 lines
drivers/usb/gadget/pch_udc.c new file +10
-0+ + td_data = req->td_data; +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 ;
The line above has 6 levels of indention. If you drop indentions the way described above you get back to 3.
Quoted 15 lines
drivers/usb/gadget/pch_udc.c new file +15
-0+ + td_data = + (struct pch_udc_data_dma_desc *)\ +phys_to_virt (td_data->next); + } +/* Write the descriptor pointer */ +pch_udc_ep_set_ddptr (ep->regs, + req->td_data_phys); +pch_udc_set_dma (ep->dev->regs,DMA_DIR_TX ); +/* Set the poll demand bit */ +pch_udc_ep_set_pd (ep->regs); +pch_udc_enable_ep_interrupts (ep->dev->regs, +1 << (ep->in ? ep->num :\ + ep->num +UDC_EPINT_OUT_EP0 )); +pch_udc_ep_clear_nak (ep->regs);
drivers/usb/gadget/pch_udc.c line 1810
Quoted 10 lines
drivers/usb/gadget/pch_udc.c new file +10
-0+ } + } + } +} + +/** +* pch_udc_complete_transfer - This function completes a transfer +* @ep: Reference to the endpoint structure +*/ +static void pch_udc_complete_transfer (struct pch_udc_ep *ep)
Same as with the function above.
drivers/usb/gadget/pch_udc.c line 1876
Quoted 5 lines
drivers/usb/gadget/pch_udc.c new file +5
-0+/** +* pch_udc_complete_receiver - This function completes a receiver +* @ep: Reference to the endpoint structure +*/ +static void pch_udc_complete_receiver (struct pch_udc_ep *ep)
This function would use some indention fixing as well.
drivers/usb/gadget/pch_udc.c line 2093
Quoted 4 lines
drivers/usb/gadget/pch_udc.c new file +4
-0+if (list_empty (&ep->queue)) { +/* enable DMA */ +pch_udc_set_dma (dev->regs,DMA_DIR_RX ); + }
Drop the "{" and "}". script/checkpatch.pl will find issues like this one.
Quoted 12 lines
drivers/usb/gadget/pch_udc.c new file +11
-0+} +static void pch_udc_read_all_epstatus (struct pch_udc_dev *dev,u32 ep_intr) +{ +int i; +struct pch_udc_ep *ep; + +for (i =0 ; i <PCH_UDC_USED_EP_NUM ; i++) { +/* IN */ +if (ep_intr & (0x1 << i)) { + ep = &dev->ep[2 *i]; + ep->epsts =pch_udc_read_ep_status (ep->regs);
drivers/usb/gadget/pch_udc.c line 2290
Quoted 10 lines
drivers/usb/gadget/pch_udc.c new file +10
-0+pch_udc_clear_ep_status (ep->regs, ep->epsts); + } +/* OUT */ +if (ep_intr & (0x10000 << i)) { + ep = &dev->ep[2 *i+1 ]; + ep->epsts =pch_udc_read_ep_status (ep->regs); +pch_udc_clear_ep_status (ep->regs, ep->epsts); + } + } +return ;
Useless return.
drivers/usb/gadget/pch_udc.c line 2409
Quoted 9 lines
drivers/usb/gadget/pch_udc.c new file +8
-0+} +/** +* pch_udc_svc_enum_interrupt - This function handles a USB speed enumeration +* done interrupt +* @dev: Reference to driver structure +*/ +void +pch_udc_svc_enum_interrupt (struct pch_udc_dev *dev)
Useless line break. This applies not only to this function.
Quoted 25 lines
drivers/usb/gadget/pch_udc.c new file +25
-0+void +pch_udc_svc_intf_interrupt (struct pch_udc_dev *dev) +{ +u32 reg, dev_stat =0 ; +int i, ret; + +pr_debug ("%s: enter" , __func__); + dev_stat =pch_udc_read_device_status (dev->regs); + dev->cfg_data.cur_intf = (dev_stat &UDC_DEVSTS_INTF_MASK ) >> +UDC_DEVSTS_INTF_OFS ; + dev->cfg_data.cur_alt = (dev_stat &UDC_DEVSTS_ALT_MASK ) >> +UDC_DEVSTS_ALT_OFS ; +pr_debug ("DVSTATUS=%08x, cfg=%d, intf=%d, alt=%d" , dev_stat, + (dev_stat &UDC_CSR_NE_CFG_MASK ) >>UDC_CSR_NE_CFG_OFS , + dev->cfg_data.cur_intf, dev->cfg_data.cur_alt); + + dev->set_cfg_not_acked =1 ; + +/* Construct the usb request for gadget driver and inform it */ +memset (&setup_data,0 ,sizeof setup_data); + setup_data.request.bRequest =USB_REQ_SET_INTERFACE ; + setup_data.request.bRequestType =USB_RECIP_INTERFACE ; + setup_data.request.wValue =cpu_to_le16 (dev->cfg_data.cur_alt); + setup_data.request.wIndex =cpu_to_le16 (dev->cfg_data.cur_intf); +
drivers/usb/gadget/pch_udc.c line 2488
Quoted 10 lines
drivers/usb/gadget/pch_udc.c new file +10
-0+/* programm the Endpoint Cfg registers */ +for (i =0 ; i <PCH_UDC_USED_EP_NUM *2 ; i++) { +if (i ==1 ) {/* Only one end point cfg register */ + reg =pch_udc_read_csr ((u32) (&dev->csr->ne[i])); + reg = (reg & ~UDC_CSR_NE_INTF_MASK ) | + (dev->cfg_data.cur_intf <<UDC_CSR_NE_INTF_OFS ); + reg = (reg & ~UDC_CSR_NE_ALT_MASK ) | + (dev->cfg_data.cur_alt <<UDC_CSR_NE_ALT_OFS ); +pch_udc_write_csr (reg, (u32) (&dev->csr->ne[i])); + }
Could this if be put outside of the loop? This applies not only to this function.
Quoted 19 lines
drivers/usb/gadget/pch_udc.c new file +18
-0+/* clear stall bits */ +pch_udc_ep_clear_stall (dev->ep[i].regs); + dev->ep[i].halted =0 ; + } + dev->stall =0 ; +spin_unlock (&dev->lock); + ret = dev->driver->setup (&dev->gadget, &setup_data.request); +spin_lock (&dev->lock); +} +irqreturn_t pch_udc_isr (int irq,void *pdev) +{ +struct pch_udc_dev *dev; +u32 dev_intr, ep_intr; +int i; + +pr_debug ("%s: enter" , __func__); + dev = (struct pch_udc_dev *) pdev; + dev_intr =pch_udc_read_device_interrupts (dev->regs);
drivers/usb/gadget/pch_udc.c line 2611
Quoted 10 lines
drivers/usb/gadget/pch_udc.c new file +10
-0+ ep_intr =pch_udc_read_ep_interrupts (dev->regs); + +if (dev_intr !=0 ) { +/* Clear device interrupts */ +pch_udc_write_device_interrupts (dev->regs, dev_intr); + } +if (ep_intr !=0 ) { +/* Clear ep interrupts */ +pch_udc_write_ep_interrupts (dev->regs, ep_intr); + }
Useless "{" and "}" in the two above ifs.
Quoted 28 lines
drivers/usb/gadget/pch_udc.c new file +28
-0+if ((dev_intr ==0 ) && (ep_intr ==0 )) { +pr_debug ("%s: exit IRQ_NONE" , __func__); +return IRQ_NONE ; + } +spin_lock (&dev->lock); + +if (dev_intr !=0 ) { +pr_debug ("%s: device intr 0x%x" , __func__, dev_intr); +pch_udc_dev_isr (dev, dev_intr); + } + +if (ep_intr !=0 ) { +pr_debug ("%s: ep intr 0x%x" , __func__, ep_intr); +pch_udc_read_all_epstatus (dev, ep_intr); + +/* Process Control In interrupts, if present */ +if (ep_intr & (1 <<UDC_EPINT_IN_EP0 )) { +pch_udc_svc_control_in (dev); +pch_udc_postsvc_epinters (dev,0 ); + } +/* Process Control Out interrupts, if present */ +if (ep_intr & (1 <<UDC_EPINT_OUT_EP0 )) +pch_udc_svc_control_out (dev); + +/* Process data in end point interrupts */ +for (i =1 ; i <PCH_UDC_USED_EP_NUM ; i++) { +if (ep_intr & (1 << i)) { +pch_udc_svc_data_in (dev, i);
drivers/usb/gadget/pch_udc.c line 2649
Quoted 10 lines
drivers/usb/gadget/pch_udc.c new file +10
-0+pch_udc_postsvc_epinters (dev, i); + } + } +/* Process data out end point interrupts */ +for (i =UDC_EPINT_OUT_EP1 ; i < (UDC_EPINT_OUT_EP0 + +PCH_UDC_USED_EP_NUM ); i++) { +if (ep_intr & (1 << i)) +pch_udc_svc_data_out (dev, i - +UDC_EPINT_OUT_EP0 ); + }
Useless "{" and "}" in for.
Quoted 11 lines
drivers/usb/gadget/pch_udc.c new file +10
-0+ } +spin_unlock (&dev->lock); +return IRQ_HANDLED ; +} +int pch_udc_probe (struct pci_dev *pdev,const struct pci_device_id *id) +{ +unsigned long resource; +unsigned long len; +int retval =0 ; +struct pch_udc_dev *dev;
drivers/usb/gadget/pch_udc.c line 3026
Quoted 10 lines
drivers/usb/gadget/pch_udc.c new file +10
-0+ +dev_dbg (&pdev->dev,"%s: enter" , __func__); +/* one udc only */ +if (pch_udc !=NULL ) { +dev_err (&pdev->dev,"%s: already probed" , __func__); +return -EBUSY ; + } + +/* init */ + dev =kzalloc (sizeof (struct pch_udc_dev ),GFP_KERNEL );
I just noticed it here but it may apply to other places as well. I recommend:
+ dev = kzalloc(sizeof *dev, GFP_KERNEL);
drivers/usb/gadget/pch_udc.c line 3032
Quoted 6 lines
drivers/usb/gadget/pch_udc.c new file +6
-0+if (dev ==NULL ) { +dev_err (&pdev->dev,"%s: no memory for device structure" , + __func__); +return -ENOMEM ; + } +memset (dev,0 ,sizeof (struct pch_udc_dev ));
kzalloc() does that.
Quoted 3 lines
+/**
+ *pch_udc_cfg_data- Structure to hold current configuration
+ * and interface information
This applies to other places as well. The above should read:
+ * struct pch_udc_cfg_data - ...
Quoted 3 lines
+ * @cur_cfg current configuration in use
+ * @cur_intf current interface in use
+ * @cur_alt current alt interface in use
And there should be ":" after member name.
Quoted 25 lines
+ */
drivers/usb/gadget/pch_udc.h new file +23
-0+struct pch_udc_cfg_data { +u16 cur_cfg; +u16 cur_intf; +u16 cur_alt; +}; +/** +* pch_udc_dev - Structure holding complete information of the PCH USB device +* +* @gadget gadget driver data +* @driver; reference to gadget driver bound +* @pdev; reference to the PCI device +* @ep[PCH_UDC_EP_NUM]; array of endpoints +* @lock; protects all state +* @active:1, enabled the PCI device +* @stall:1, stall requested +* @prot_stall:1, protcol stall requested +* @irq_registered:1, irq registered with system +* @mem_region:1, device memory mapped +* @registered:1, driver regsitered with system +* @suspended:1, driver in suspended state +* @connected:1, gadget driver associated +* @set_cfg_not_acked:1, pending acknowledgement 4 setup +* @waiting_zlp_ack:1; pending acknowledgement 4 ZLP
drivers/usb/gadget/pch_udc.h line 454
Quoted 10 lines
drivers/usb/gadget/pch_udc.h new file +10
-0+* @csr; address of config & status +* @regs; address of device registers +* @*ep_regs; address of endpoint registers +* @data_requests; DMA pool for data requests +* @stp_requests; DMA pool for setup requests +* @phys_addr; of device memory +* @virt_addr; for mapped device memory +* @irq; IRQ line for the device +* @cfg_data; current cfg, intf, and alt in use +*/
Useless ":1", there should be ":" after member name and not nothing, ";" or ",".
Quoted 1 line
+
Needless empty line.
Quoted 1 line
+struct
pch_udc_dev{
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 Micha?, Greg and Maurus.
Thank you for your comments.
I confirm them.
Thanks, Ohtake
----- Original Message -----
From: "Micha? Nazarewicz" <[email protected]>
To: "Randy Dunlap" <[email protected]>; "Peter Korsgaard" <[email protected]>; "Nicolas Ferre" <[email protected]>; "Maurus Cuelenaere" <[email protected]>; "linux-usb" <[email protected]>; "Laurent Pinchart" <[email protected]>; "Greg Kroah-Hartman" <[email protected]>; "Fabien Chouteau" <[email protected]>; "david Brownell" <[email protected]>; "Christoph Egger" <[email protected]>; "LKML" <[email protected]>; "MeeGo" <[email protected]>; "Masayuki Ohtake" <[email protected]>
Cc: "Wang, Qi" <[email protected]>; "Wang, Yong Y" <[email protected]>; "Andrew" <[email protected]>; "Intel OTC" <[email protected]>; "Foster, Margie" <[email protected]>; "Arjan" <[email protected]>; "Toshiharu Okada" <[email protected]>; "Takahiro Shimizu" <[email protected]>; "Tomoya Morinaga" <[email protected]>
Sent: Wednesday, September 08, 2010 10:58 AM
Subject: Re: [PATCH] USB device driver of Topcliff PCH
Not sure why I'm on the "To" list, but here are a few of my comments:
Quoted 2 lines · Masayuki Ohtake
+/**
+ *pch_udc_write_csr- Write the command and status registers.
IIRC, the correct way to write kernel doc is:
+ * pch_udc_write_csr() - Write the command and status registers.
Note the "()". This applies to other functions as well.
Quoted 4 lines
+ * @val: value to be written to CSR register
+ * @addr: address of CSR register
+ */
+inline voidpch_udc_write_csr(unsigned long val, unsigned long addr)
As it was pointed, unless those functions are extern, make them static and remove the inline.
drivers/usb/gadget/pch_udc.c line 89
Quoted 8 lines
drivers/usb/gadget/pch_udc.c new file +8
-0+{ +int count =MAX_LOOP ; + +/* Wait till idle */ +while ((count >0 ) &&\ + (ioread32 ((u32 *)(PCH_UDC_CSR_BUSY_ADDR + pch_udc_base)) & +PCH_UDC_CSR_BUSY )) + count--;
I'd say: "while (ioread(...) && --count);" Also, I'd make count to be unsigned.
Quoted 3 lines
+
+ if (count < 0)
+pr_debug("%s: wait error; count = %x", __func__, count);
Dead code. If MAX_LOOP is >= 0 count will never get negative. Did you mean if (!count)?
drivers/usb/gadget/pch_udc.c line 103
Quoted 11 lines
drivers/usb/gadget/pch_udc.c new file +11
-0+ +iowrite32 (val, (u32 *)addr); +/* Wait till idle */ + count =MAX_LOOP ; +while ((count >0 ) && + (ioread32 ((u32 *)(PCH_UDC_CSR_BUSY_ADDR + pch_udc_base)) & +PCH_UDC_CSR_BUSY )) + count--; + +if (count <0 ) +pr_debug ("%s: wait error; count = %x" , __func__, count);
Dead code.
drivers/usb/gadget/pch_udc.c line 113
Quoted 7 lines
drivers/usb/gadget/pch_udc.c new file +7
-0+/** +* pch_udc_read_csr - Read the command and status registers. +* @addr: address of CSR register +* Returns +* content of CSR register +*/ +inline u32 pch_udc_read_csr (unsigned long addr)
All comments to the pch_udc_write_csr() function apply here as well.
drivers/usb/gadget/pch_udc.c line 200
Quoted 10 lines
drivers/usb/gadget/pch_udc.c new file +10
-0+/** +* pch_udc_get_speed - Return the speed status +* @dev: Reference to pch_udc_regs structure +* Retern The speed(LOW=1, FULL=2, HIGH=3) +*/ +inline int pch_udc_get_speed (struct pch_udc_regs __iomem *dev) +{ +u32 val; + + val =ioread32 (&dev->devsts);
It's just me, but why not join the two lines together:
+ u32 val = ioread32(&dev->devsts);
drivers/usb/gadget/pch_udc.c line 584
Quoted 13 lines
+ return (val &
UDC_DEVSTS_ENUM_SPEED_MASK) >>UDC_DEVSTS_ENUM_SPEED_OFS;drivers/usb/gadget/pch_udc.c new file +11
-0+} +/** +* pch_udc_ep_clear_nak - Set the bit 8 (CNAK field) +* of the endpoint control register +* @ep: reference to structure of type pch_udc_ep_regs +*/ +void pch_udc_ep_clear_nak (struct pch_udc_ep_regs __iomem *ep) +{ +unsigned int loopcnt =0 ; + +if (ioread32 (&ep->epctl) & (1 <<UDC_EPCTL_NAK )) {
if (!(ioread32(&ep->epctl) & (1 << UDC_EPCTL_NAK))) return;
and then drop one indention level for the rest of the function. This will help to keep indention level nearer the recommended limit of 3.
Quoted 32 lines
+ if (!(EP_IS_IN(ep))) {
+ while ((pch_udc_read_ep_status(ep)&
+ (1 <<UDC_EPSTS_MRXFIFO_EMP)) == 0) {
+ if (loopcnt++ > 100000) {
+ pr_debug("%s: RxFIFO not Empty "drivers/usb/gadget/pch_udc.c new file +27
-0+"loop count = %d" , + __func__, loopcnt); +break ; + } +udelay (100 ); + } + } +while (ioread32 (&ep->epctl) & (1 <<UDC_EPCTL_NAK )) { +PCH_UDC_BIT_SET (&ep->epctl,1 <<UDC_EPCTL_CNAK ); +udelay (5 ); +if (loopcnt++ >=25 ) { +pr_debug ("%s: Clear NAK not set for" +"ep%d%s: counter=%d" , + __func__,EP_NUM (ep), + (EP_IS_IN (ep) ?"in" :"out" ), + loopcnt); +break ; + } + } + } +} + +/** +* pch_udc_ep_fifo_flush - Flush the endpoint fifo +* @ep: reference to structure of type pch_udc_ep_regs +* @dir: direction of endpoint +* - dir = 0 endpoint is OUT
drivers/usb/gadget/pch_udc.c line 626
Quoted 10 lines
drivers/usb/gadget/pch_udc.c new file +10
-0+* - dir != 0 endpoint is IN +*/ +void pch_udc_ep_fifo_flush (struct pch_udc_ep_regs __iomem *ep,int dir) +{ +unsigned int loopcnt =0 ; + +pr_debug ("%s: ep%d%s" , __func__,EP_NUM (ep), + (EP_IS_IN (ep) ?"in" :"out" )); +if (dir) {/* IN ep */ +PCH_UDC_BIT_SET (&ep->epctl,1 <<UDC_EPCTL_F );
I'd add "return;" here and move the else part out of the else dropping one indention level.
Quoted 3 lines
+ } else {
+ if ((pch_udc_read_ep_status(ep)&
+ (1 <<UDC_EPSTS_MRXFIFO_EMP)) == 0) {
if (pch_udc_read_ep_status(ep) & (1 << UDC_EPSTS_MRXFIFO_EMP) return;
and drop indention.
Quoted 20 lines
+
PCH_UDC_BIT_SET(&ep->epctl, 1 << UDC_EPCTL_MRXFLUSH);
+ /* Wait for RxFIFO Empty */
+ while ((pch_udc_read_ep_status(ep)&
+ (1 <<UDC_EPSTS_MRXFIFO_EMP)) == 0) {
+ if (loopcnt++ > 1000000) {
+ pr_debug("RxFIFO not Empty loop"drivers/usb/gadget/pch_udc.c new file +13
-0+ " count = %d", loopcnt); +break ; + } +udelay (100 ); + } +PCH_UDC_BIT_CLR (&ep->epctl,1 <<UDC_EPCTL_MRXFLUSH ); + } + } +} +/** +* pch_udc_pcd_pullup - This API is invoked to make the device +* visible/invisible to the host +* @gadget: Reference to the gadget driver
drivers/usb/gadget/pch_udc.c line 880
Quoted 10 lines
drivers/usb/gadget/pch_udc.c new file +10
-0+* @is_on: Specifies whether the pull up is made active or inactive +* Returns +* 0: Success +* -EINVAL: If the gadget passed is NULL +*/ +static int pch_udc_pcd_pullup (struct usb_gadget *gadget,int is_on) +{ +struct pch_udc_dev *dev; + +pr_debug ("%s: enter" , __func__);
It just struck me. Wouldn't it be feasible to use "dev_*" instead of "pr_*"?
Quoted 9 lines
+ 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->regs);
+ else
+pch_udc_clear_disconnect(dev->regs);
There was function that did exactly that I think. Wasn't there?
Quoted 7 lines
+ return 0;
drivers/usb/gadget/pch_udc.c new file +5
-0+} +/** +* pch_udc_start_next_txrequest - This function starts +* the next transmission requirement +* @ep: Reference to the endpoint structure
drivers/usb/gadget/pch_udc.c line 1760
Quoted 10 lines
drivers/usb/gadget/pch_udc.c new file +10
-0+*/ +static void pch_udc_start_next_txrequest (struct pch_udc_ep *ep) +{ +struct pch_udc_request *req; + +pr_debug ("%s: enter" , __func__); +if (pch_udc_read_ep_control (ep->regs) & (1 <<UDC_EPCTL_P )) +return ; + +if (!list_empty (&ep->queue)) {
if (list_empty(...))
return;
and drop indention.
Quoted 3 lines
+ /* next request */
+ req =list_entry(ep->queue.next, struct pch_udc_request, queue);
+ if (req && !req->dma_going) {
Same here.
Quoted 3 lines
+ pr_debug("%s: Set request: req=%p req->td_data=%p",
+__func__, req,req->td_data);
+ if (req->td_data) {
Same eher.
Quoted 9 lines
+ struct
pch_udc_data_dma_desc*td_data;drivers/usb/gadget/pch_udc.c new file +8
-0+ +while (pch_udc_read_ep_control (ep->regs) & + (1 <<UDC_EPCTL_S )) +udelay (100 ); + + req->dma_going =1 ; +/* Clear the descriptor pointer */ +pch_udc_ep_set_ddptr (ep->regs,0 );
drivers/usb/gadget/pch_udc.c line 1785
Quoted 10 lines
drivers/usb/gadget/pch_udc.c new file +10
-0+ + td_data = req->td_data; +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 ;
The line above has 6 levels of indention. If you drop indentions the way described above you get back to 3.
Quoted 15 lines
drivers/usb/gadget/pch_udc.c new file +15
-0+ + td_data = + (struct pch_udc_data_dma_desc *)\ +phys_to_virt (td_data->next); + } +/* Write the descriptor pointer */ +pch_udc_ep_set_ddptr (ep->regs, + req->td_data_phys); +pch_udc_set_dma (ep->dev->regs,DMA_DIR_TX ); +/* Set the poll demand bit */ +pch_udc_ep_set_pd (ep->regs); +pch_udc_enable_ep_interrupts (ep->dev->regs, +1 << (ep->in ? ep->num :\ + ep->num +UDC_EPINT_OUT_EP0 )); +pch_udc_ep_clear_nak (ep->regs);
drivers/usb/gadget/pch_udc.c line 1810
Quoted 10 lines
drivers/usb/gadget/pch_udc.c new file +10
-0+ } + } + } +} + +/** +* pch_udc_complete_transfer - This function completes a transfer +* @ep: Reference to the endpoint structure +*/ +static void pch_udc_complete_transfer (struct pch_udc_ep *ep)
Same as with the function above.
drivers/usb/gadget/pch_udc.c line 1876
Quoted 5 lines
drivers/usb/gadget/pch_udc.c new file +5
-0+/** +* pch_udc_complete_receiver - This function completes a receiver +* @ep: Reference to the endpoint structure +*/ +static void pch_udc_complete_receiver (struct pch_udc_ep *ep)
This function would use some indention fixing as well.
Quoted 4 lines
+ if (
list_empty(&ep->queue)) {
+ /* enable DMA */
+pch_udc_set_dma(dev->regs, DMA_DIR_RX);
+ }
Drop the "{" and "}". script/checkpatch.pl will find issues like this one.
Quoted 12 lines
drivers/usb/gadget/pch_udc.c new file +11
-0+} +static void pch_udc_read_all_epstatus (struct pch_udc_dev *dev,u32 ep_intr) +{ +int i; +struct pch_udc_ep *ep; + +for (i =0 ; i <PCH_UDC_USED_EP_NUM ; i++) { +/* IN */ +if (ep_intr & (0x1 << i)) { + ep = &dev->ep[2 *i]; + ep->epsts =pch_udc_read_ep_status (ep->regs);
drivers/usb/gadget/pch_udc.c line 2290
Quoted 10 lines
drivers/usb/gadget/pch_udc.c new file +10
-0+pch_udc_clear_ep_status (ep->regs, ep->epsts); + } +/* OUT */ +if (ep_intr & (0x10000 << i)) { + ep = &dev->ep[2 *i+1 ]; + ep->epsts =pch_udc_read_ep_status (ep->regs); +pch_udc_clear_ep_status (ep->regs, ep->epsts); + } + } +return ;
Useless return.
drivers/usb/gadget/pch_udc.c line 2409
Quoted 9 lines
drivers/usb/gadget/pch_udc.c new file +8
-0+} +/** +* pch_udc_svc_enum_interrupt - This function handles a USB speed enumeration +* done interrupt +* @dev: Reference to driver structure +*/ +void +pch_udc_svc_enum_interrupt (struct pch_udc_dev *dev)
Useless line break. This applies not only to this function.
Quoted 25 lines
drivers/usb/gadget/pch_udc.c new file +25
-0+void +pch_udc_svc_intf_interrupt (struct pch_udc_dev *dev) +{ +u32 reg, dev_stat =0 ; +int i, ret; + +pr_debug ("%s: enter" , __func__); + dev_stat =pch_udc_read_device_status (dev->regs); + dev->cfg_data.cur_intf = (dev_stat &UDC_DEVSTS_INTF_MASK ) >> +UDC_DEVSTS_INTF_OFS ; + dev->cfg_data.cur_alt = (dev_stat &UDC_DEVSTS_ALT_MASK ) >> +UDC_DEVSTS_ALT_OFS ; +pr_debug ("DVSTATUS=%08x, cfg=%d, intf=%d, alt=%d" , dev_stat, + (dev_stat &UDC_CSR_NE_CFG_MASK ) >>UDC_CSR_NE_CFG_OFS , + dev->cfg_data.cur_intf, dev->cfg_data.cur_alt); + + dev->set_cfg_not_acked =1 ; + +/* Construct the usb request for gadget driver and inform it */ +memset (&setup_data,0 ,sizeof setup_data); + setup_data.request.bRequest =USB_REQ_SET_INTERFACE ; + setup_data.request.bRequestType =USB_RECIP_INTERFACE ; + setup_data.request.wValue =cpu_to_le16 (dev->cfg_data.cur_alt); + setup_data.request.wIndex =cpu_to_le16 (dev->cfg_data.cur_intf); +
drivers/usb/gadget/pch_udc.c line 2488
Quoted 10 lines
drivers/usb/gadget/pch_udc.c new file +10
-0+/* programm the Endpoint Cfg registers */ +for (i =0 ; i <PCH_UDC_USED_EP_NUM *2 ; i++) { +if (i ==1 ) {/* Only one end point cfg register */ + reg =pch_udc_read_csr ((u32) (&dev->csr->ne[i])); + reg = (reg & ~UDC_CSR_NE_INTF_MASK ) | + (dev->cfg_data.cur_intf <<UDC_CSR_NE_INTF_OFS ); + reg = (reg & ~UDC_CSR_NE_ALT_MASK ) | + (dev->cfg_data.cur_alt <<UDC_CSR_NE_ALT_OFS ); +pch_udc_write_csr (reg, (u32) (&dev->csr->ne[i])); + }
Could this if be put outside of the loop? This applies not only to this function.
Quoted 19 lines
+ /* clear stall bits */
+pch_udc_ep_clear_stall(dev->ep[i].regs);
+ dev->ep[i].halted = 0;
+ }
+dev->stall= 0;
+spin_unlock(&dev->lock);
+ ret =dev->driver->setup(&dev->gadget, &setup_data.request);
+spin_lock(&dev->lock);drivers/usb/gadget/pch_udc.c new file +10
-0+} +irqreturn_t pch_udc_isr (int irq,void *pdev) +{ +struct pch_udc_dev *dev; +u32 dev_intr, ep_intr; +int i; + +pr_debug ("%s: enter" , __func__); + dev = (struct pch_udc_dev *) pdev; + dev_intr =pch_udc_read_device_interrupts (dev->regs);
drivers/usb/gadget/pch_udc.c line 2611
Quoted 10 lines
drivers/usb/gadget/pch_udc.c new file +10
-0+ ep_intr =pch_udc_read_ep_interrupts (dev->regs); + +if (dev_intr !=0 ) { +/* Clear device interrupts */ +pch_udc_write_device_interrupts (dev->regs, dev_intr); + } +if (ep_intr !=0 ) { +/* Clear ep interrupts */ +pch_udc_write_ep_interrupts (dev->regs, ep_intr); + }
Useless "{" and "}" in the two above ifs.
Quoted 28 lines
+ if ((
dev_intr== 0) && (ep_intr== 0)) {
+pr_debug("%s: exit IRQ_NONE", __func__);
+ returnIRQ_NONE;
+ }
+spin_lock(&dev->lock);drivers/usb/gadget/pch_udc.c new file +23
-0+ +if (dev_intr !=0 ) { +pr_debug ("%s: device intr 0x%x" , __func__, dev_intr); +pch_udc_dev_isr (dev, dev_intr); + } + +if (ep_intr !=0 ) { +pr_debug ("%s: ep intr 0x%x" , __func__, ep_intr); +pch_udc_read_all_epstatus (dev, ep_intr); + +/* Process Control In interrupts, if present */ +if (ep_intr & (1 <<UDC_EPINT_IN_EP0 )) { +pch_udc_svc_control_in (dev); +pch_udc_postsvc_epinters (dev,0 ); + } +/* Process Control Out interrupts, if present */ +if (ep_intr & (1 <<UDC_EPINT_OUT_EP0 )) +pch_udc_svc_control_out (dev); + +/* Process data in end point interrupts */ +for (i =1 ; i <PCH_UDC_USED_EP_NUM ; i++) { +if (ep_intr & (1 << i)) { +pch_udc_svc_data_in (dev, i);
drivers/usb/gadget/pch_udc.c line 2649
Quoted 10 lines
drivers/usb/gadget/pch_udc.c new file +10
-0+pch_udc_postsvc_epinters (dev, i); + } + } +/* Process data out end point interrupts */ +for (i =UDC_EPINT_OUT_EP1 ; i < (UDC_EPINT_OUT_EP0 + +PCH_UDC_USED_EP_NUM ); i++) { +if (ep_intr & (1 << i)) +pch_udc_svc_data_out (dev, i - +UDC_EPINT_OUT_EP0 ); + }
Useless "{" and "}" in for.
Quoted 11 lines
+ }
+spin_unlock(&dev->lock);
+ returnIRQ_HANDLED;drivers/usb/gadget/pch_udc.c new file +7
-0+} +int pch_udc_probe (struct pci_dev *pdev,const struct pci_device_id *id) +{ +unsigned long resource; +unsigned long len; +int retval =0 ; +struct pch_udc_dev *dev;
drivers/usb/gadget/pch_udc.c line 3026
Quoted 10 lines
drivers/usb/gadget/pch_udc.c new file +10
-0+ +dev_dbg (&pdev->dev,"%s: enter" , __func__); +/* one udc only */ +if (pch_udc !=NULL ) { +dev_err (&pdev->dev,"%s: already probed" , __func__); +return -EBUSY ; + } + +/* init */ + dev =kzalloc (sizeof (struct pch_udc_dev ),GFP_KERNEL );
I just noticed it here but it may apply to other places as well. I recommend:
+ dev = kzalloc(sizeof *dev, GFP_KERNEL);
Quoted 6 lines
+ if (dev == NULL) {
+ dev_err(&pdev->dev, "%s: no memory for device structure",
+__func__);
+ return-ENOMEM;
+ }
+memset(dev, 0, sizeof(struct pch_udc_dev));
kzalloc() does that.
Quoted 3 lines
+/**
+ *pch_udc_cfg_data- Structure to hold current configuration
+ * and interface information
This applies to other places as well. The above should read:
+ * struct pch_udc_cfg_data - ...
Quoted 3 lines
+ * @cur_cfg current configuration in use
+ * @cur_intf current interface in use
+ * @cur_alt current alt interface in use
And there should be ":" after member name.
Quoted 25 lines
+ */
drivers/usb/gadget/pch_udc.h new file +23
-0+struct pch_udc_cfg_data { +u16 cur_cfg; +u16 cur_intf; +u16 cur_alt; +}; +/** +* pch_udc_dev - Structure holding complete information of the PCH USB device +* +* @gadget gadget driver data +* @driver; reference to gadget driver bound +* @pdev; reference to the PCI device +* @ep[PCH_UDC_EP_NUM]; array of endpoints +* @lock; protects all state +* @active:1, enabled the PCI device +* @stall:1, stall requested +* @prot_stall:1, protcol stall requested +* @irq_registered:1, irq registered with system +* @mem_region:1, device memory mapped +* @registered:1, driver regsitered with system +* @suspended:1, driver in suspended state +* @connected:1, gadget driver associated +* @set_cfg_not_acked:1, pending acknowledgement 4 setup +* @waiting_zlp_ack:1; pending acknowledgement 4 ZLP
drivers/usb/gadget/pch_udc.h line 454
Quoted 10 lines
drivers/usb/gadget/pch_udc.h new file +10
-0+* @csr; address of config & status +* @regs; address of device registers +* @*ep_regs; address of endpoint registers +* @data_requests; DMA pool for data requests +* @stp_requests; DMA pool for setup requests +* @phys_addr; of device memory +* @virt_addr; for mapped device memory +* @irq; IRQ line for the device +* @cfg_data; current cfg, intf, and alt in use +*/
Useless ":1", there should be ":" after member name and not nothing, ";" or ",".
Quoted 1 line
+
Needless empty line.
Quoted 1 line
+struct
pch_udc_dev{
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
My reply comments are included in the following.
Thanks Ohtake
Date: Wed, 08 Sep 2010 03:58:04 +0200
From: "Micha? Nazarewicz" <[email protected]>
Quoted 1 line
Not sure why I'm on the "To" list, but here are a few of my comments:
[masa]
Your address was got the following scripts as maintainer. "./scripts/get_maintainer.pl"
Whom should I submit patch to?
Quoted 10 lines · Masayuki Ohtake
Quoted 2 lines
+/**
+ *pch_udc_write_csr- Write the command and status registers.IIRC, the correct way to write kernel doc is:
+ *
pch_udc_write_csr()- Write the command and status registers.Note the "()". This applies to other functions as well.
[masa]
This will be modified.
Quoted 7 lines
Quoted 4 lines
+ * @val: value to be written to CSR register
+ * @addr: address of CSR register
+ */
+inline voidpch_udc_write_csr(unsigned long val, unsigned long addr)As it was pointed, unless those functions are extern, make them static and remove the inline.
[masa]
This will be modified as
"static void pch_udc_write_csr(unsigned long val, unsigned long addr)"
Quoted 10 lines
drivers/usb/gadget/pch_udc.c line 89
Quoted 8 lines
drivers/usb/gadget/pch_udc.c new file +8
-0+{ +int count =MAX_LOOP ; + +/* Wait till idle */ +while ((count >0 ) &&\ + (ioread32 ((u32 *)(PCH_UDC_CSR_BUSY_ADDR + pch_udc_base)) & +PCH_UDC_CSR_BUSY )) + count--;I'd say: "while (ioread(...) && --count);" Also, I'd make count to be unsigned.
[masa]
This will be modified.
Quoted 6 lines
Quoted 3 lines
+
+ if (count < 0)
+pr_debug("%s: wait error; count = %x", __func__, count);Dead code. If
MAX_LOOPis >= 0 count will never get negative. Did you mean if (!count)?
[masa]
This will be modified.
Quoted 5 lines
Quoted 5 lines
+
+iowrite32(val, (u32 *)addr);
+ /* Wait till idle */
+ count =MAX_LOOP;
+ while ((count > 0) &&
Quoted 8 lines
Quoted 6 lines
+ (
ioread32((u32 *)(PCH_UDC_CSR_BUSY_ADDR + pch_udc_base))&
+PCH_UDC_CSR_BUSY))
+ count--;
+
+ if (count < 0)
+pr_debug("%s: wait error; count = %x", __func__, count);Dead code.
[masa]
This will be modified.
Quoted 9 lines
drivers/usb/gadget/pch_udc.c line 113
Quoted 7 lines
drivers/usb/gadget/pch_udc.c new file +7
-0+/** +* pch_udc_read_csr - Read the command and status registers. +* @addr: address of CSR register +* Returns +* content of CSR register +*/ +inline u32 pch_udc_read_csr (unsigned long addr)All comments to the
pch_udc_write_csr()function apply here as well.
[masa]
This will be modified.
Quoted 13 lines
drivers/usb/gadget/pch_udc.c line 200
Quoted 10 lines
drivers/usb/gadget/pch_udc.c new file +10
-0+/** +* pch_udc_get_speed - Return the speed status +* @dev: Reference to pch_udc_regs structure +* Retern The speed(LOW=1, FULL=2, HIGH=3) +*/ +inline int pch_udc_get_speed (struct pch_udc_regs __iomem *dev) +{ +u32 val; + + val =ioread32 (&dev->devsts);It's just me, but why not join the two lines together:
Quoted 4 lines
+ u32 val =
ioread32(&dev->devsts);Quoted 2 lines
+ return (val &
UDC_DEVSTS_ENUM_SPEED_MASK) >>UDC_DEVSTS_ENUM_SPEED_OFS; +}
[masa]
This will be modified.
Quoted 14 lines
drivers/usb/gadget/pch_udc.c line 584
Quoted 10 lines
drivers/usb/gadget/pch_udc.c new file +10
-0+/** +* pch_udc_ep_clear_nak - Set the bit 8 (CNAK field) +* of the endpoint control register +* @ep: reference to structure of type pch_udc_ep_regs +*/ +void pch_udc_ep_clear_nak (struct pch_udc_ep_regs __iomem *ep) +{ +unsigned int loopcnt =0 ; + +if (ioread32 (&ep->epctl) & (1 <<UDC_EPCTL_NAK )) {if (!(ioread32(&ep->epctl) & (1 <<
UDC_EPCTL_NAK))) return;
Quoted 3 lines
and then drop one indention level for the rest of the function. This will help to keep indention level nearer the recommended limit of 3.
[masa]
This will be modified.
Quoted 11 lines
drivers/usb/gadget/pch_udc.c line 626
Quoted 8 lines
drivers/usb/gadget/pch_udc.c new file +8
-0+void pch_udc_ep_fifo_flush (struct pch_udc_ep_regs __iomem *ep,int dir) +{ +unsigned int loopcnt =0 ; + +pr_debug ("%s: ep%d%s" , __func__,EP_NUM (ep), + (EP_IS_IN (ep) ?"in" :"out" )); +if (dir) {/* IN ep */ +PCH_UDC_BIT_SET (&ep->epctl,1 <<UDC_EPCTL_F );I'd add "return;" here and move the else part out of the else dropping one indention level.
[masa]
This will be modified.
Quoted 8 lines
Quoted 3 lines
+ } else {
+ if ((pch_udc_read_ep_status(ep)&
+ (1 <<UDC_EPSTS_MRXFIFO_EMP)) == 0) {if (
pch_udc_read_ep_status(ep)& (1 <<UDC_EPSTS_MRXFIFO_EMP) return;and drop indention.
[masa]
This will be modified.
Quoted 8 lines
Quoted 8 lines
+/**
+ *pch_udc_pcd_pullup- This API is invoked to make the device
+ * visible/invisible to the host
+ * @gadget: Reference to the gadget driver
+ * @is_on: Specifies whether the pull up is made active or inactive
+ * Returns
+ * 0: Success
+ *-EINVAL: If the gadget passed is NULL
Quoted 8 lines
drivers/usb/gadget/pch_udc.c line 880
Quoted 6 lines
+ */
drivers/usb/gadget/pch_udc.c new file +5
-0+static int pch_udc_pcd_pullup (struct usb_gadget *gadget,int is_on) +{ +struct pch_udc_dev *dev; + +pr_debug ("%s: enter" , __func__);It just struck me. Wouldn't it be feasible to use "dev_*" instead of "pr_*"?
[masa]
This will be modified.
Quoted 11 lines
Quoted 9 lines
+ 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->regs);
+ else
+pch_udc_clear_disconnect(dev->regs);There was function that did exactly that I think. Wasn't there?
[masa] ???
Quoted 18 lines
Quoted 4 lines
drivers/usb/gadget/pch_udc.c new file +4
-0+/** +* pch_udc_start_next_txrequest - This function starts +* the next transmission requirement +* @ep: Reference to the endpoint structure drivers/usb/gadget/pch_udc.c line 1760
Quoted 10 lines
drivers/usb/gadget/pch_udc.c new file +10
-0+*/ +static void pch_udc_start_next_txrequest (struct pch_udc_ep *ep) +{ +struct pch_udc_request *req; + +pr_debug ("%s: enter" , __func__); +if (pch_udc_read_ep_control (ep->regs) & (1 <<UDC_EPCTL_P )) +return ; + +if (!list_empty (&ep->queue)) {if (
list_empty(...))
return;
Quoted 1 line
and drop indention.
[masa]
This will be modified.
Quoted 5 lines
Quoted 3 lines
+ /* next request */
+ req =list_entry(ep->queue.next, struct pch_udc_request, queue);
+ if (req && !req->dma_going) {Same here.
[masa]
This will be modified.
Quoted 5 lines
Quoted 3 lines
+ pr_debug("%s: Set request: req=%p req->td_data=%p",
+__func__, req,req->td_data);
+ if (req->td_data) {Same eher.
[masa]
This will be modified.
Quoted 14 lines
Quoted 14 lines
+ struct
pch_udc_data_dma_desc*td_data;drivers/usb/gadget/pch_udc.c new file +13
-0+ +while (pch_udc_read_ep_control (ep->regs) & + (1 <<UDC_EPCTL_S )) +udelay (100 ); + + req->dma_going =1 ; +/* Clear the descriptor pointer */ +pch_udc_ep_set_ddptr (ep->regs,0 ); + + td_data = req->td_data; +while (1 ) { + td_data->status = (td_data->status & + ~PCH_UDC_BUFF_STS) |
Quoted 8 lines
Quoted 5 lines
+
PCH_UDC_BS_HST_RDY;
+ if ((td_data->status&
+PCH_UDC_DMA_LAST) ==
+PCH_UDC_DMA_LAST)
+ break;The line above has 6 levels of indention. If you drop indentions the way described above you get back to 3.
[masa]
This will be modified.
Quoted 3 lines
Quoted 1 line
+static void
pch_udc_complete_transfer(struct pch_udc_ep *ep)Same as with the function above.
[masa]
This will be modified.
Quoted 7 lines
drivers/usb/gadget/pch_udc.c line 1876
Quoted 5 lines
drivers/usb/gadget/pch_udc.c new file +5
-0+/** +* pch_udc_complete_receiver - This function completes a receiver +* @ep: Reference to the endpoint structure +*/ +static void pch_udc_complete_receiver (struct pch_udc_ep *ep)This function would use some indention fixing as well.
[masa]
This will be modified.
Quoted 6 lines
Quoted 4 lines
+ if (
list_empty(&ep->queue)) {
+ /* enable DMA */
+pch_udc_set_dma(dev->regs, DMA_DIR_RX);
+ }Drop the "{" and "}".
script/checkpatch.plwill find issues like this one.
[masa]
This will be deleted.
Quoted 14 lines
Quoted 14 lines
drivers/usb/gadget/pch_udc.c new file +14
-0+static void pch_udc_read_all_epstatus (struct pch_udc_dev *dev,u32 ep_intr) +{ +int i; +struct pch_udc_ep *ep; + +for (i =0 ; i <PCH_UDC_USED_EP_NUM ; i++) { +/* IN */ +if (ep_intr & (0x1 << i)) { + ep = &dev->ep[2 *i]; + ep->epsts =pch_udc_read_ep_status (ep->regs); +pch_udc_clear_ep_status (ep->regs, ep->epsts); + } +/* OUT */ +if (ep_intr & (0x10000 << i)) {
Quoted 8 lines
Quoted 6 lines
+ ep = &dev->ep[2*i+1];
+ep->epsts=pch_udc_read_ep_status(ep->regs);
+pch_udc_clear_ep_status(ep->regs, ep->epsts);
+ }
+ }
+ return;Useless return.
[masa]
This will be deleted.
Quoted 9 lines
drivers/usb/gadget/pch_udc.c line 2409
Quoted 7 lines
drivers/usb/gadget/pch_udc.c new file +7
-0+/** +* pch_udc_svc_enum_interrupt - This function handles a USB speed enumeration +* done interrupt +* @dev: Reference to driver structure +*/ +void +pch_udc_svc_enum_interrupt (struct pch_udc_dev *dev)Useless line break. This applies not only to this function.
[masa]
This will be modified as
"void pch_udc_svc_enum_interrupt(struct pch_udc_dev *dev)"
Quoted 29 lines
Quoted 29 lines
drivers/usb/gadget/pch_udc.c new file +29
-0+void +pch_udc_svc_intf_interrupt (struct pch_udc_dev *dev) +{ +u32 reg, dev_stat =0 ; +int i, ret; + +pr_debug ("%s: enter" , __func__); + dev_stat =pch_udc_read_device_status (dev->regs); + dev->cfg_data.cur_intf = (dev_stat &UDC_DEVSTS_INTF_MASK ) >> +UDC_DEVSTS_INTF_OFS ; + dev->cfg_data.cur_alt = (dev_stat &UDC_DEVSTS_ALT_MASK ) >> +UDC_DEVSTS_ALT_OFS ; +pr_debug ("DVSTATUS=%08x, cfg=%d, intf=%d, alt=%d" , dev_stat, + (dev_stat &UDC_CSR_NE_CFG_MASK ) >>UDC_CSR_NE_CFG_OFS , + dev->cfg_data.cur_intf, dev->cfg_data.cur_alt); + + dev->set_cfg_not_acked =1 ; + +/* Construct the usb request for gadget driver and inform it */ +memset (&setup_data,0 ,sizeof setup_data); + setup_data.request.bRequest =USB_REQ_SET_INTERFACE ; + setup_data.request.bRequestType =USB_RECIP_INTERFACE ; + setup_data.request.wValue =cpu_to_le16 (dev->cfg_data.cur_alt); + setup_data.request.wIndex =cpu_to_le16 (dev->cfg_data.cur_intf); + +/* programm the Endpoint Cfg registers */ +for (i =0 ; i <PCH_UDC_USED_EP_NUM *2 ; i++) { +if (i ==1 ) {/* Only one end point cfg register */ + reg =pch_udc_read_csr ((u32) (&dev->csr->ne[i]));
Quoted 8 lines
Quoted 6 lines
+ reg = (reg & ~UDC_CSR_NE_INTF_MASK) |
+ (dev->cfg_data.cur_intf<<UDC_CSR_NE_INTF_OFS);
+ reg = (reg & ~UDC_CSR_NE_ALT_MASK) |
+ (dev->cfg_data.cur_alt<<UDC_CSR_NE_ALT_OFS);
+pch_udc_write_csr(reg, (u32) (&dev->csr->ne[i]));
+ }Could this if be put outside of the loop? This applies not only to this function.
[masa]
This will be modified.
Quoted 13 lines
Quoted 13 lines
drivers/usb/gadget/pch_udc.c new file +13
-0+irqreturn_t pch_udc_isr (int irq,void *pdev) +{ +struct pch_udc_dev *dev; +u32 dev_intr, ep_intr; +int i; + +pr_debug ("%s: enter" , __func__); + dev = (struct pch_udc_dev *) pdev; + dev_intr =pch_udc_read_device_interrupts (dev->regs); + ep_intr =pch_udc_read_ep_interrupts (dev->regs); + +if (dev_intr !=0 ) { +/* Clear device interrupts */
Quoted 8 lines
Quoted 6 lines
+
pch_udc_write_device_interrupts(dev->regs, dev_intr);
+ }
+ if (ep_intr!= 0) {
+ /* Clear ep interrupts */
+pch_udc_write_ep_interrupts(dev->regs, ep_intr);
+ }Useless "{" and "}" in the two above ifs.
[masa]
This will be deleted.
Quoted 15 lines
Quoted 6 lines
+ /* Process data in end point interrupts */
+ for (i = 1; i <PCH_UDC_USED_EP_NUM; i++) {
+ if (ep_intr& (1 << i)) {
+pch_udc_svc_data_in(dev, i);
+pch_udc_postsvc_epinters(dev, i);
+ }Quoted 8 lines
+ }
+ /* Process data out end point interrupts */
+ for (i =UDC_EPINT_OUT_EP1; i < (UDC_EPINT_OUT_EP0+
+PCH_UDC_USED_EP_NUM); i++) {
+ if (ep_intr& (1 << i))
+ pch_udc_svc_data_out(dev, i -
+UDC_EPINT_OUT_EP0);
+ }
Quoted 1 line
Useless "{" and "}" in for.
[masa]
This will be deleted.
Quoted 19 lines
Quoted 6 lines
drivers/usb/gadget/pch_udc.c new file +6
-0+int pch_udc_probe (struct pci_dev *pdev,const struct pci_device_id *id) +{ +unsigned long resource; +unsigned long len; +int retval =0 ; +struct pch_udc_dev *dev;drivers/usb/gadget/pch_udc.c line 3026
Quoted 10 lines
drivers/usb/gadget/pch_udc.c new file +10
-0+ +dev_dbg (&pdev->dev,"%s: enter" , __func__); +/* one udc only */ +if (pch_udc !=NULL ) { +dev_err (&pdev->dev,"%s: already probed" , __func__); +return -EBUSY ; + } + +/* init */ + dev =kzalloc (sizeof (struct pch_udc_dev ),GFP_KERNEL );I just noticed it here but it may apply to other places as well. I recommend:
Quoted 1 line
+ dev =
kzalloc(sizeof *dev, GFP_KERNEL);
[masa]
This will be modeified.
Quoted 8 lines
Quoted 6 lines
+ if (dev == NULL) {
+ dev_err(&pdev->dev, "%s: no memory for device structure",
+__func__);
+ return-ENOMEM;
+ }
+memset(dev, 0, sizeof(struct pch_udc_dev));
kzalloc()does that.
[masa]
This will be deleted.
Quoted 7 lines
Quoted 3 lines
+/**
+ *pch_udc_cfg_data- Structure to hold current configuration
+ * and interface informationThis applies to other places as well. The above should read:
+ * struct
pch_udc_cfg_data- ...
[masa]
This will be modeified.
Quoted 5 lines
Quoted 3 lines
+ * @cur_cfg current configuration in use
+ * @cur_intf current interface in use
+ * @cur_alt current alt interface in useAnd there should be ":" after member name.
[masa]
This will be modeified.
Quoted 29 lines
Quoted 20 lines
+/**
+ *pch_udc_dev- Structure holding complete information of the PCH USB device
+ *
+ * @gadget gadget driver data
+ * @driver; reference to gadget driver bound
+ * @pdev; reference to the PCI device
+ * @ep[PCH_UDC_EP_NUM]; array of endpoints
+ * @lock; protects all state
+ * @active:1, enabled the PCI device
+ * @stall:1, stall requested
+ * @prot_stall:1, protcol stall requested
+ * @irq_registered:1, irq registered with system
+ * @mem_region:1, device memory mapped
+ * @registered:1, driver regsitered with system
+ * @suspended:1, driver in suspended state
+ * @connected:1, gadget driver associated
+ * @set_cfg_not_acked:1, pending acknowledgement 4 setup
+ * @waiting_zlp_ack:1; pending acknowledgement 4 ZLP
+ * @csr; address of config & status
+ * @regs; address of device registersQuoted 8 lines
+ * @*ep_regs; address of endpoint registers
+ * @data_requests; DMA pool for data requests
+ * @stp_requests; DMA pool for setup requests
+ * @phys_addr; of device memory
+ * @virt_addr; for mapped device memory
+ * @irq; IRQ line for the device
+ * @cfg_data; current cfg, intf, and alt in use
+ */
Quoted 1 line
Useless ":1", there should be ":" after member name and not nothing, ";" or ",".
[masa]
This will be modeified.
Quoted 5 lines
Quoted 1 line
+
Needless empty line.
Quoted 1 line
+struct
pch_udc_dev{
[masa]
This will be modeified.
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 Maurus
My reply comments are included in the following. I will resubmit after modified
Thanks Ohtake
From: Maurus Cuelenaere <[email protected]>
Date: Tue, 7 Sep 2010 14:53:05 +0200
Quoted 9 lines
2010/9/7 Masayuki Ohtake <[email protected]>
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 4 lines
Quoted 1 line
Signed-off-by Masayuki Ohtake <[email protected]>No need to mail all these people, just the maintainers and appropriate mailing lists will do.
[masa]
I have question. Please tell me.
Whom should I submit patch to?
TO: LKML and maintainers
Is it correct?
The maintainer was got the following scripts. "./scripts/get_maintainer.pl"
Quoted 18 lines
Quoted 11 lines
---
drivers/usb/gadget/Kconfig| 24 +drivers/usb/gadget/Makefile| 2 +-drivers/usb/gadget/gadget_chips.h| 7 +drivers/usb/gadget/pch_udc.c| 3153 +++++++++++++++++++++++++++++++++++++drivers/usb/gadget/pch_udc.h| 495 ++++++5 files changed, 3680 insertions(+), 1 deletions(-)create mode 100755
drivers/usb/gadget/pch_udc.c
create mode 100755drivers/usb/gadget/pch_udc.h[snip]
Quoted 5 lines
drivers/usb/gadget/pch_udc.c new file +0
-0[snip]
Quoted 12 lines
drivers/usb/gadget/pch_udc.c line 69
Quoted 9 lines
drivers/usb/gadget/pch_udc.c new file +9
-0+ +const char ep0_string[] ="ep0in" ; +static DEFINE_SPINLOCK (udc_stall_spinlock);/* stall spin lock */ +static u32 pch_udc_base; +static union pch_udc_setup_data setup_data;/* received setup data */ +static unsigned long ep0out_buf[64 ]; +static dma_addr_t dma_addr; +struct pch_udc_dev *pch_udc;/* pointer to device object */ +int speed_fs;I'd put all these in struct
phc_udc_devor similar, so you could have multiple controllers.
[masa]
This will be modified.
Quoted 15 lines
drivers/usb/gadget/pch_udc.c line 81
Quoted 13 lines
drivers/usb/gadget/pch_udc.c new file +12
-0+ +module_param_named (speed_fs, speed_fs, bool,S_IRUGO ); +MODULE_PARM_DESC (speed_fs,"true for Full speed operation" ); +MODULE_DESCRIPTION ("OKISEMI PCH UDC - USB Device Controller" ); +MODULE_LICENSE ("GPL" ); + +/** +* pch_udc_write_csr - Write the command and status registers. +* @val: value to be written to CSR register +* @addr: address of CSR register +*/ +inline void pch_udc_write_csr (unsigned long val,unsigned long addr)Make all these functions static.
[masa]
This will be modified.
Quoted 10 lines
drivers/usb/gadget/pch_udc.c line 88
Quoted 8 lines
drivers/usb/gadget/pch_udc.c new file +7
-0+{ +int count =MAX_LOOP ; + +/* Wait till idle */ +while ((count >0 ) &&\ + (ioread32 ((u32 *)(PCH_UDC_CSR_BUSY_ADDR + pch_udc_base)) & +PCH_UDC_CSR_BUSY ))Why not define PCH_UDC_* as (void __iomem*) so no casting is necessary.
[masa]
This will be modified.
Quoted 20 lines
Quoted 20 lines
+ count--;
drivers/usb/gadget/pch_udc.c new file +18
-0+ +if (count <0 ) +pr_debug ("%s: wait error; count = %x" , __func__, count); + +iowrite32 (val, (u32 *)addr); +/* Wait till idle */ + count =MAX_LOOP ; +while ((count >0 ) && + (ioread32 ((u32 *)(PCH_UDC_CSR_BUSY_ADDR + pch_udc_base)) & +PCH_UDC_CSR_BUSY )) + count--; + +if (count <0 ) +pr_debug ("%s: wait error; count = %x" , __func__, count); + +} + +/**
Quoted 8 lines
Quoted 6 lines
+ *
pch_udc_read_csr- Read the command and status registers.
+ * @addr: address of CSR register
+ * Returns
+ * content of CSR register
+ */
+inline u32pch_udc_read_csr(unsigned long addr)void
__iomem*addr
[masa]
This will be modified.
Quoted 51 lines
Quoted 38 lines
drivers/usb/gadget/pch_udc.c new file +37
-0+{ +int count =MAX_LOOP ; + +/* Wait till idle */ +while ((count >0 ) && + (ioread32 ((u32 *)(PCH_UDC_CSR_BUSY_ADDR + pch_udc_base)) & +PCH_UDC_CSR_BUSY )) + count--; + +if (count <0 ) +pr_debug ("%s: wait error; count = %x" , __func__, count); +/* Dummy read */ +ioread32 ((u32 *)addr); + count =MAX_LOOP ; +/* Wait till idle */ +while ((count >0 ) && + (ioread32 ((u32 *)(PCH_UDC_CSR_BUSY_ADDR + pch_udc_base)) & +PCH_UDC_CSR_BUSY )) + count--; +/* actual read */ +if (count <0 ) +pr_debug ("%s: wait error; count = %x" , __func__, count); + +return ioread32 ((u32 *)addr); +} + +/** +* pch_udc_rmt_wakeup - Initiate for remote wakeup +* @dev: Reference to pch_udc_regs structure +*/ +inline void pch_udc_rmt_wakeup (struct pch_udc_regs *dev) +{ +PCH_UDC_BIT_SET (&dev->devctl,1 <<UDC_DEVCTL_RES ); +mdelay (1 ); +PCH_UDC_BIT_CLR (&dev->devctl,1 <<UDC_DEVCTL_RES ); +} +drivers/usb/gadget/pch_udc.c line 160
Quoted 10 lines
drivers/usb/gadget/pch_udc.c new file +10
-0+/** +* pch_udc_get_frame - Get the current frame from device status register +* @dev: Reference to pch_udc_regs structure +* Retern current frame +*/ +inline int pch_udc_get_frame (struct pch_udc_regs *dev) +{ +u32 frame; + + frame =ioread32 (&dev->devsts);Why not just get rid of struct
pch_udc_regsand do something like:
Quoted 6 lines
static inline u32
pch_readl(struct pch_udc_dev *dev, unsigned long reg){
returnioread32(dev->base_addr + reg);
}(and similar for
pch_writel)
[masa]
This will be modified.
Quoted 16 lines
Quoted 3 lines
+ return (frame &
UDC_DEVSTS_TS_MASK) >>UDC_DEVSTS_TS_OFS; +}[snip]
Quoted 12 lines
drivers/usb/gadget/pch_udc.c new file +12
-0+static struct usb_request *pch_udc_alloc_request (struct usb_ep *usbep, +gfp_t gfp) +{ +struct pch_udc_request *req; +struct pch_udc_ep *ep; + +pr_debug ("%s: enter" , __func__); +if (usbep ==NULL ) +return NULL ; + + ep = container_of(usbep, struct pch_udc_ep, ep); +pr_debug ("%s: ep %s" , __func__, usbep->name);
Quoted 8 lines
Quoted 6 lines
+ req =
kzalloc(sizeof(struct pch_udc_request), gfp);
+ if (req == NULL) {
+pr_debug("%s: no memory for request", __func__);
+ return NULL;
+ }
+memset(req, 0, sizeof(struct pch_udc_request));kzalloc does this..
[masa]memset() is removed
Quoted 49 lines
Quoted 28 lines
+
req->req.dma=DMA_ADDR_INVALID;
+INIT_LIST_HEAD(&req->queue);drivers/usb/gadget/pch_udc.c new file +25
-0+ +if (ep->dma !=NULL ) { +struct pch_udc_data_dma_desc *dma_desc; + +/* ep0 in requests are allocated from data pool here */ + dma_desc =pci_pool_alloc (ep->dev->data_requests, gfp, + &req->td_data_phys); +if (NULL == dma_desc) { +kfree (req); +return NULL ; + } + +pr_debug ("%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 ; + dma_desc->dataptr =__constant_cpu_to_le32 (DMA_ADDR_INVALID ); + req->td_data = dma_desc; + req->td_data_last = dma_desc; + req->chain_len =1 ; + } +return &req->req; +}[snip]
Quoted 5 lines
drivers/usb/gadget/pch_udc.c new file +5
-0+ +/** +* pch_udc_start_next_txrequest - This function starts +* the next transmission requirement +* @ep: Reference to the endpoint structure drivers/usb/gadget/pch_udc.c line 1760
Quoted 10 lines
drivers/usb/gadget/pch_udc.c new file +10
-0+*/ +static void pch_udc_start_next_txrequest (struct pch_udc_ep *ep) +{ +struct pch_udc_request *req; + +pr_debug ("%s: enter" , __func__); +if (pch_udc_read_ep_control (ep->regs) & (1 <<UDC_EPCTL_P )) +return ; + +if (!list_empty (&ep->queue)) {Convert this into:
if (list_empty(&ep->queue))
return;
Quoted 1 line
That way you get rid of the unnecessary spacing below
[masa]
This will be modified.
Quoted 50 lines
Quoted 50 lines
+ /* next request */
+ req =list_entry(ep->queue.next, struct pch_udc_request, queue);
+ if (req && !req->dma_going) {
+ pr_debug("%s: Set request: req=%p req->td_data=%p",
+__func__, req,req->td_data);
+ if (req->td_data) {
+ structpch_udc_data_dma_desc*td_data;drivers/usb/gadget/pch_udc.c new file +42
-0+ +while (pch_udc_read_ep_control (ep->regs) & + (1 <<UDC_EPCTL_S )) +udelay (100 ); + + req->dma_going =1 ; +/* Clear the descriptor pointer */ +pch_udc_ep_set_ddptr (ep->regs,0 ); + + td_data = req->td_data; +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); + } +/* Write the descriptor pointer */ +pch_udc_ep_set_ddptr (ep->regs, + req->td_data_phys); +pch_udc_set_dma (ep->dev->regs,DMA_DIR_TX ); +/* Set the poll demand bit */ +pch_udc_ep_set_pd (ep->regs); +pch_udc_enable_ep_interrupts (ep->dev->regs, +1 << (ep->in ? ep->num :\ + ep->num +UDC_EPINT_OUT_EP0 )); +pch_udc_ep_clear_nak (ep->regs); + } + } + } +} + +/** +* pch_udc_complete_transfer - This function completes a transfer +* @ep: Reference to the endpoint structure +*/
Quoted 8 lines
drivers/usb/gadget/pch_udc.c line 1815
Quoted 6 lines
drivers/usb/gadget/pch_udc.c new file +6
-0+static void pch_udc_complete_transfer (struct pch_udc_ep *ep) +{ +struct pch_udc_request *req; + +pr_debug ("%s: enter" , __func__); +if (!list_empty (&ep->queue)) {Same here
[masa]
This will be modified.
Quoted 81 lines
Quoted 56 lines
+
pr_debug("%s: list_entry", __func__);
+ 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)) {drivers/usb/gadget/pch_udc.c new file +51
-0+#ifdef DMA_PPB_WITH_DESC_UPDATE +struct pch_udc_data_dma_desc *td_data = req->td_data; +for (i =0 ; i < req->chain_len; i++) { +if ((td_data->status &PCH_UDC_RXTX_STS ) != +PCH_UDC_RTS_SUCC ) { +pr_err ("Invalid RXTX status (0x%08x)" +" epstatus=0x%08x\n" , + (td_data->status & +PCH_UDC_RXTX_STS ), + (int )(ep->epsts)); +return ; + } + td_data = (struct pch_udc_data_dma_desc *) +phys_to_virt (td_data->next); + } +#else +if ((req->td_data_last->status &PCH_UDC_RXTX_STS ) != +PCH_UDC_RTS_SUCC ) { +pr_err ("Invalid RXTX status (0x%08x)" +" epstatus=0x%08x\n" , + (req->td_data_last->status & +PCH_UDC_RXTX_STS ), + (int )(ep->epsts)); +return ; + } +#endif + req->req.actual = req->req.length; + req->td_data_last->status =PCH_UDC_BS_HST_BSY | +PCH_UDC_DMA_LAST ; + req->td_data->status =PCH_UDC_BS_HST_BSY | +PCH_UDC_DMA_LAST ; +/* complete req */ +complete_req (ep, req,0 ); + req->dma_going =0 ; +if (!list_empty (&ep->queue)) { +while (pch_udc_read_ep_control (ep->regs) & + (1 <<UDC_EPCTL_S )) +udelay (100 ); + +pch_udc_ep_clear_nak (ep->regs); +pch_udc_enable_ep_interrupts (ep->dev->regs, +1 << (ep->in ? ep->num : ep->num + +UDC_EPINT_OUT_EP0 )); + }else { +pch_udc_disable_ep_interrupts (ep->dev->regs, +1 << (ep->in ? ep->num : ep->num + +UDC_EPINT_OUT_EP0 )); + } + } + } +}[snip]
Quoted 24 lines
drivers/usb/gadget/pch_udc.c new file +24
-0+ +/** +* pch_udc_svc_enum_interrupt - This function handles a USB speed enumeration +* done interrupt +* @dev: Reference to driver structure +*/ +void +pch_udc_svc_enum_interrupt (struct pch_udc_dev *dev) +{ +u32 dev_stat, dev_speed; +u32 speed =USB_SPEED_FULL ; + +pr_debug ("%s: enter" , __func__); + dev_stat =pch_udc_read_device_status (dev->regs); + dev_speed = (dev_stat &UDC_DEVSTS_ENUM_SPEED_MASK ) >> +UDC_DEVSTS_ENUM_SPEED_OFS ; + +pr_debug ("%s: dev_speed = 0x%08x" , __func__, dev_speed); + +if (dev_speed ==UDC_DEVSTS_ENUM_SPEED_HIGH ) { +pr_debug ("HighSpeed" ); + speed =USB_SPEED_HIGH ; + }else if (dev_speed ==UDC_DEVSTS_ENUM_SPEED_FULL ) { +pr_debug ("FullSpeed" );
Quoted 8 lines
Quoted 6 lines
+ speed =
USB_SPEED_FULL;
+ } else if (dev_speed==UDC_DEVSTS_ENUM_SPEED_LOW) {
+pr_debug("LowSpeed?");
+ speed =USB_SPEED_LOW;
+ } else {
+pr_debug("FullSpeed?");
BUG()perhaps? Also, change this into a switch statement
[masa]
This will be modified.
Quoted 36 lines
Quoted 18 lines
+ }
+dev->gadget.speed= speed;drivers/usb/gadget/pch_udc.c new file +15
-0+ +pch_udc_activate_control_ep (dev); + +/* enable ep0 interrupts */ +pch_udc_enable_ep_interrupts (dev->regs,1 <<UDC_EPINT_IN_EP0 | +1 <<UDC_EPINT_OUT_EP0 ); +/* enable DMA */ +pch_udc_set_dma (dev->regs,DMA_DIR_TX ); +pch_udc_set_dma (dev->regs,DMA_DIR_RX ); +pch_udc_ep_set_rrdy (dev->ep[UDC_EP0OUT_IDX ].regs); + + +pr_debug ("%s: EP mask set to %x" , __func__, +ioread32 (&dev->regs->epirqmsk)); +}[snip]
Quoted 17 lines
drivers/usb/gadget/pch_udc.c new file +17
-0+ +int pch_udc_probe (struct pci_dev *pdev,const struct pci_device_id *id) +{ +unsigned long resource; +unsigned long len; +int retval =0 ; +struct pch_udc_dev *dev; + +dev_dbg (&pdev->dev,"%s: enter" , __func__); +/* one udc only */ +if (pch_udc !=NULL ) { +dev_err (&pdev->dev,"%s: already probed" , __func__); +return -EBUSY ; + } + +/* init */ + dev =kzalloc (sizeof (struct pch_udc_dev ),GFP_KERNEL );
Quoted 8 lines
Quoted 6 lines
+ if (dev == NULL) {
+ dev_err(&pdev->dev, "%s: no memory for device structure",
+__func__);
+ return-ENOMEM;
+ }
+memset(dev, 0, sizeof(struct pch_udc_dev));kzalloc already does this for you
[masa]
memset is removed.
Quoted 103 lines
Quoted 103 lines
+ /* pci setup */
+ if (pci_enable_device(pdev)< 0) {
+ kfree(dev);
+dev_err(&pdev->dev, "%s: pci_enable_device failed", __func__);
+ return-ENODEV;
+ }
+dev->active= 1;
+pci_set_drvdata(pdev, dev);drivers/usb/gadget/pch_udc.c new file +94
-0+ +/* PCI resource allocation */ + resource =pci_resource_start (pdev,1 ); + len =pci_resource_len (pdev,1 ); +dev_dbg (&pdev->dev,"%s: resource %lx, len %ld" , + __func__, resource, len); + +if (request_mem_region (resource, len,KBUILD_MODNAME ) ==NULL ) { +dev_err (&pdev->dev,"%s: pci device used already" , __func__); + retval = -EBUSY ; + goto finished; + } + dev->phys_addr = resource; + dev->mem_region =1 ; + + dev->virt_addr =ioremap_nocache (resource, len); +if (dev->virt_addr ==NULL ) { +dev_err (&pdev->dev,"%s: device memory cannot be mapped" , + __func__); + retval = -ENOMEM ; + goto finished; + } +dev_dbg (&pdev->dev,"%s: device memory mapped at %x" , __func__, + (int )dev->virt_addr); + +if (pdev->irq ==0 ) { +dev_err (&pdev->dev,"%s: irq not set" , __func__); + retval = -ENODEV ; + goto finished; + } + + pch_udc = dev; + +/* initialize the hardware */ +if (pch_udc_pcd_init (dev) !=0 ) + goto finished; + +if (request_irq (pdev->irq, pch_udc_isr,IRQF_SHARED , +KBUILD_MODNAME , dev) !=0 ) { +dev_err (&pdev->dev,"%s: request_irq(%d) fail" , __func__, + pdev->irq); + retval = -ENODEV ; + goto finished; + } + dev->irq = pdev->irq; + dev->irq_registered =1 ; + +pci_set_master (pdev); +pci_try_set_mwi (pdev); + +/* device struct setup */ +spin_lock_init (&dev->lock); + dev->pdev = pdev; + dev->gadget.ops = &pch_udc_ops; + + retval =init_dma_pools (dev); +if (retval !=0 ) + goto finished; + +dev_set_name (&dev->gadget.dev,"gadget" ); + dev->gadget.dev.parent = &pdev->dev; + dev->gadget.dev.dma_mask = pdev->dev.dma_mask; + dev->gadget.dev.release = gadget_release; + dev->gadget.name =KBUILD_MODNAME ; + dev->gadget.is_dualspeed =1 ; + + retval =device_register (&dev->gadget.dev); +if (retval !=0 ) + goto finished; + dev->registered =1 ; + +/* Put the device in disconnected state till a driver is bound */ +pch_udc_set_disconnect (dev->regs); +return 0 ; + +finished: +pch_udc_remove (pdev); +return retval; +} + +static const struct pci_device_id pch_udc_pcidev_id[] = { + { +PCI_DEVICE (PCI_VENDOR_ID_INTEL ,PCI_DEVICE_ID_INTEL_PCH1_UDC ), + .class = (PCI_CLASS_SERIAL_USB <<8 ) |0xfe , + .class_mask =0xffffffff , + }, + {0 }, +}; + +MODULE_DEVICE_TABLE (pci, pch_udc_pcidev_id); + + +static struct pci_driver pch_udc_driver = { + .name =KBUILD_MODNAME ,
Quoted 8 lines
Quoted 6 lines
+ .id_table =
pch_udc_pcidev_id,
+ .probe =pch_udc_probe,
+ .remove =pch_udc_remove,
+ .suspend =pch_udc_suspend,
+ .resume =pch_udc_resume,
+ .shutdown =pch_udc_shutdown,Make all these functions static
[masa]
This will be modified.
Quoted 65 lines
Quoted 55 lines
drivers/usb/gadget/pch_udc.c new file +13
-0+}; + +static int __init pch_udc_pci_init (void ) +{ +return pci_register_driver (&pch_udc_driver); +} +module_init (pch_udc_pci_init); + +static void __exit pch_udc_pci_exit(void) +{ +pci_unregister_driver (&pch_udc_driver); +} +module_exit (pch_udc_pci_exit);drivers/usb/gadget/pch_udc.h new file +35
-0@@ -0,0 +1,495 @@ +/* +* Copyright (C) 2010 OKI SEMICONDUCTOR Co., LTD. +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; version 2 of the License. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. +*/ + +#ifndef _PCH_UDC_H_ +#define _PCH_UDC_H_ + +/* Address offset of Registers */ +#define UDC_EPIN_REGS_ADDR 0x000 +#define UDC_EPOUT_REGS_ADDR 0x200 +#define UDC_EP_REG_OFS 0x20/* Offset to next EP */ +#define UDC_DEVCFG_ADDR 0x400 +#define PCH_UDC_CSR_BUSY_ADDR 0x4f0 +#define PCH_UDC_SRST_ADDR 0x4fc +#define UDC_CSR_ADDR 0x500 + +/* Bit position in UDC CSR Busy status Register */ +#define PCH_UDC_CSR_BUSY 1 +/* Bit position in UDC Soft reset Register */ +#define PCH_UDC_PSRST 1 +#define PCH_UDC_SRST 0 +[snip]
drivers/usb/gadget/pch_udc.h line 70
Quoted 6 lines
drivers/usb/gadget/pch_udc.h new file +6
-0+ +/** +* pch_udc_csrs - Structure to Endpoint configuration registers +*/ +struct pch_udc_csrs { +u32 ne[PCH_UDC_USED_EP_NUM *2 ];Why not do away with the structs and do something like:
Quoted 3 lines
#define
PCH_UDC_CSR(ep)(UDC_CSR_ADDR+ ep*4)(and similar for the others)
[masa]
This will be modified.
Quoted 30 lines
Quoted 19 lines
drivers/usb/gadget/pch_udc.h new file +18
-0+/* Starting bit position */ +#define UDC_CSR_NE_NUM_OFS 0 +#define UDC_CSR_NE_DIR_OFS 4 +#define UDC_CSR_NE_TYPE_OFS 5 +#define UDC_CSR_NE_CFG_OFS 7 +#define UDC_CSR_NE_INTF_OFS 11 +#define UDC_CSR_NE_ALT_OFS 15 +#define UDC_CSR_NE_MAX_PKT_OFS 19 +/* Mask patern */ +#define UDC_CSR_NE_NUM_MASK 0x0000000f +#define UDC_CSR_NE_DIR_MASK 0x00000010 +#define UDC_CSR_NE_TYPE_MASK 0x00000060 +#define UDC_CSR_NE_CFG_MASK 0x00000780 +#define UDC_CSR_NE_INTF_MASK 0x00007800 +#define UDC_CSR_NE_ALT_MASK 0x00078000 +#define UDC_CSR_NE_MAX_PKT_MASK 0x3ff80000 +}; +[snip]
Quoted 10 lines
drivers/usb/gadget/pch_udc.h new file +10
-0+ +/** +* pch_udc_request - Structure holding a PCH USB device request +* @req embedded ep request +* @td_data_phys phys. address +* @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
Quoted 8 lines
drivers/usb/gadget/pch_udc.h line 380
Quoted 5 lines
+ * @dma_done DMA completed for request
+ * @chain_len chain length
+ */drivers/usb/gadget/pch_udc.h new file +2
-0+struct pch_udc_request /* request packet */ +{I don't see any reason to not put this in the main .c file? (same for struct pch_udc_{ep,request})
[masa]
This moves to main.c.
Quoted 29 lines
Quoted 12 lines
+ struct
usb_requestreq;
+dma_addr_ttd_data_phys;
+ structpch_udc_data_dma_desc*td_data;
+ structpch_udc_data_dma_desc*td_data_last;
+ structlist_headqueue;
+ unsigned dma_going:1,
+ dma_mapped:1,
+ dma_done:1;
+ unsignedchain_len;drivers/usb/gadget/pch_udc.h new file +2
-0+}; +[snip]
Quoted 16 lines
drivers/usb/gadget/pch_udc.h new file +16
-0+ +struct pch_udc_dev { +struct usb_gadget gadget; +struct usb_gadget_driver *driver; +struct pci_dev *pdev; +/* all endpoints */ +struct pch_udc_ep ep[PCH_UDC_EP_NUM ]; +spinlock_t lock; +unsigned active:1 , + stall:1 , + prot_stall:1 , + irq_registered:1 , + mem_region:1 , + registered:1 , + suspended:1 , + connected:1,
Quoted 8 lines
Quoted 5 lines
+ set_cfg_not_acked:1,
+ waiting_zlp_ack:1;
+ structpch_udc_csrs__iomem*csr;
+ structpch_udc_regs__iomem*regs;
+ structpch_udc_ep_regs__iomem*ep_regs;These pointers just seem unnecessary, especially as you could easily construct them in-place by adding the appropriate offset to your base address..
[masa]
This will be deleted.
Hi Greg
Quoted 6 lines
Quoted 2 lines
+#define
PCH_UDC_BIT_CLR(reg, bitMask)\
+iowrite32((ioread32((reg)) & (~(bitMask))), (reg))Why not just use the iowrite32 functions directly? Or surely there's another built-in kernel macro for this somewhere, right?
[masa]
Which macro is it?
Do you know?
My reply comments are included in the following.
Thanks Ohtake
---------
Date: Tue, 7 Sep 2010 17:22:29 -0700
From: Greg KH <[email protected]>
Quoted 20 lines · Masayuki Ohtake
Quoted 9 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.Signed-off-by Masayuki Ohtake <[email protected]>Quoted 9 lines
--- drivers/usb/gadget/Kconfig | 24 + drivers/usb/gadget/Makefile | 2 +- drivers/usb/gadget/gadget_chips.h | 7 + drivers/usb/gadget/pch_udc.c | 3153 +++++++++++++++++++++++++++++++++++++ drivers/usb/gadget/pch_udc.h | 495 ++++++ 5 files changed, 3680 insertions(+), 1 deletions(-) create mode 100755 drivers/usb/gadget/pch_udc.c create mode 100755 drivers/usb/gadget/pch_udc.h
Quoted 2 lines
Heh, really? executable .c and .h files? I think you need to look at your development system :)
[masa]
"pch_udc.h" will be removed
It includes in "pch_udc.c"
Quoted 9 lines
Quoted 9 lines
drivers/usb/gadget/Kconfig +0
-0@@ -220,6 +220,30 @@ config USB_OTG
Quoted 6 lines
drivers/usb/gadget/Kconfig config USB_OTG · line 224
Quoted 4 lines
drivers/usb/gadget/Kconfig +2
-0Select this only if your OMAP board has a Mini-AB connector. +config USB_GADGET_PCH + boolean "PCH USB Dev"Please spell this out a lot more as to what it is.
[masa]
This will be modified as "boolean "PCH USB Device controller""
Quoted 108 lines
Quoted 108 lines
drivers/usb/gadget/Kconfig +22
-0+ 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_IXP4XXdrivers/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.odrivers/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 +41
-0@@ -0,0 +1,3153 @@ +/* +* Copyright (C) 2010 OKI SEMICONDUCTOR Co., LTD. +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; version 2 of the License. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. +*/ +#define pr_fmt (fmt) KBUILD_MODNAME ": " fmt +#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> +#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> + +#include <asm/byteorder.h> +#include <asm/system.h>
Quoted 8 lines
drivers/usb/gadget/pch_udc.c line 47
Quoted 6 lines
drivers/usb/gadget/pch_udc.c new file +6
-0+#include <asm/unaligned.h> + +/* gadget stack */ +#include <linux/usb/ch9.h> +#include <linux/usb/gadget.h> +#include "pch_udc.h" Why do you need a .h file?
[masa]
"pch_udc.h" will be removed
It includes in "pch_udc.c"
Quoted 11 lines
drivers/usb/gadget/pch_udc.c line 55
Quoted 7 lines
drivers/usb/gadget/pch_udc.c new file +6
-0+/* macro to set a specified bit(mask) at the specified address */ +#define PCH_UDC_BIT_SET (reg, bitmask) \ + iowrite32(((ioread32((reg)) | (bitmask))), (reg)) +/* macro to clear a specified bit(mask) at the specified address */ +#define PCH_UDC_BIT_CLR (reg, bitMask) \ + iowrite32((ioread32((reg)) & (~(bitMask))), (reg))Why not just use the iowrite32 functions directly? Or surely there's another built-in kernel macro for this somewhere, right?
[masa]
Which macro is it?
Do you know?
Quoted 6 lines
drivers/usb/gadget/pch_udc.c line 59
Quoted 4 lines
drivers/usb/gadget/pch_udc.c new file +3
-0+#define MAX_LOOP 200 +#define PCH_UDC_PCI_BAR 1 +#define PCI_VENDOR_ID_INTEL 0x8086No need to define this, it's in
pci_ids.halready.
[masa]
OK.
This will be removed.
Quoted 4 lines
drivers/usb/gadget/pch_udc.c line 60
Quoted 2 lines
drivers/usb/gadget/pch_udc.c new file +1
-0+#define PCI_DEVICE_ID_INTEL_PCH1_UDC 0x8808I think this is there too.
[masa]
This is not still in pci.h.
Quoted 12 lines
drivers/usb/gadget/pch_udc.c line 69
Quoted 10 lines
drivers/usb/gadget/pch_udc.c new file +9
-0+ +const char ep0_string[] ="ep0in" ; +static DEFINE_SPINLOCK (udc_stall_spinlock);/* stall spin lock */ +static u32 pch_udc_base; +static union pch_udc_setup_data setup_data;/* received setup data */ +static unsigned long ep0out_buf[64 ]; +static dma_addr_t dma_addr; +struct pch_udc_dev *pch_udc;/* pointer to device object */ +int speed_fs;Why are 2 of these not static variables?
[masa]
This will be modified.
Quoted 4 lines
Have you run this driver through the sparse tool? It will catch these errors. Please do so.
[masa]
I will do.
Op 13-09-10 06:23, Masayuki Ohtake schreef:
Quoted 1 line
Hi Maurus
Hi Ohtake,
Quoted 19 lines
My reply comments are included in the following. I will resubmit after modified
Thanks Ohtake
From: Maurus Cuelenaere <[email protected]>
Date: Tue, 7 Sep 2010 14:53:05 +0200Quoted 11 lines
2010/9/7 Masayuki Ohtake <[email protected]>
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.Signed-off-by Masayuki Ohtake <[email protected]>No need to mail all these people, just the maintainers and appropriate mailing lists will do.
Quoted 8 lines
[masa]
I have question. Please tell me.
Whom should I submit patch to?
TO: LKML and maintainers
Is it correct?The maintainer was got the following scripts. "
./scripts/get_maintainer.pl"
If you do scripts/get_maintainer.pl --rolestats <patch>, you'll see why get_maintainer.pl picked these persons. I generally CC anyone that's "above" commit_signer or that I know has an important relation to the patch (e.g. the author of a driver you're editing).
If there are any mailing lists listed (linux-usb in this case), be sure to CC them too (except LKML, I wouldn't CC them unless it's a special case like the changes are kernel-wide or need to reviewed by a wide variation of audience or ...)
IIRC, these rules are also explained at Documentation/Submit*.
--
Maurus Cuelenaere
Quoted 4 lines · Maurus Cuelenaere
If there are any mailing lists listed (linux-usb in this case), be sure to CC them too (except LKML, I wouldn't CC them unless it's a special case like the changes are kernel-wide or need to reviewed by a wide variation of audience or ...)
Actually, Documentation/SubmittingPatches says:
Unless you have a reason NOT to do so, CC
[email protected].
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--
Quoted 6 lines · Masayuki Ohtake
Hi Greg
Quoted 4 lines
Quoted 2 lines
+#define
PCH_UDC_BIT_CLR(reg, bitMask)\
+iowrite32((ioread32((reg)) & (~(bitMask))), (reg))
Quoted 6 lines
Quoted 2 lines
Why not just use the iowrite32 functions directly? Or surely there's another built-in kernel macro for this somewhere, right?
[masa]
Which macro is it?
Do you know?
Nope, sorry, try digging around.
good luck,
greg k-h
Hi Michal and Maurus
Thank you for your reply.
I will resubmit patch so.
Thanks Ohtake
-----
Date: Mon, 13 Sep 2010 13:31:13 +0200
From: "Micha? Nazarewicz" <[email protected]>
Quoted 4 lines · Maurus Cuelenaere
If there are any mailing lists listed (linux-usb in this case), be sure to CC them too (except LKML, I wouldn't CC them unless it's a special case like the changes are kernel-wide or need to reviewed by a wide variation of audience or ...)
Actually, Documentation/SubmittingPatches says:
Unless you have a reason NOT to do so, CC
[email protected].
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--
Op 13-09-10 13:31, Michał Nazarewicz schreef:
Quoted 11 lines · Maurus Cuelenaere
Quoted 4 lines
If there are any mailing lists listed (linux-usb in this case), be sure to CC them too (except LKML, I wouldn't CC them unless it's a special case like the changes are kernel-wide or need to reviewed by a wide variation of audience or ...)
Actually,
Documentation/SubmittingPatchessays:Unless you have a reason NOT to do so, CC
[email protected].
Ah, well IMHO it's better not to spam LKML with subsystem-related stuff..
--
Maurus Cuelenaere
Quoted 1 line · Maurus Cuelenaere
Ah, well IMHO it's better not to spam LKML with subsystem-related stuff..
On the flip side, posting to LKML as well means that it's a bit harder for a patch series to go totally down a rathole, because people outside the subsystem then have a chance to look at the code and point out where it's going in the wrong direction. My last code comment was regarding hardware I didn't have, and happened because I asked myself "What would happen if that code tried to run on my laptop?". Similarly, we see lots of stuff posted that looks good to those of us on 1-4 core systems, only to have somebody from SGI point out that it will add 45 hours to boot time on one of their big boxes. And so on.