1
0
mirror of git://projects.qi-hardware.com/openwrt-xburst.git synced 2024-12-01 10:58:06 +02:00

Cleanup udc driver (a bit).

This commit is contained in:
Lars-Peter Clausen 2009-09-09 17:26:25 +02:00 committed by Xiangfu Liu
parent 055e2e36f7
commit 88f159b443

View File

@ -43,10 +43,7 @@
#include "udc_hotplug.h"
//#define DEBUG(fmt,args...) printk(KERN_DEBUG fmt , ## args)
//#define DEBUG(fmt,args...) printk(fmt , ## args)
//#define DEBUG_EP0(fmt,args...) printk(fmt , ## args)
//#define DEBUG_SETUP(fmt,args...) printk(fmt , ## args)
#define DEBUG(fmt,args...) printk(fmt, ## args)
#ifndef DEBUG
# define DEBUG(fmt,args...) do {} while(0)
@ -64,36 +61,18 @@ static unsigned int udc_debug = 0; /* 0: normal mode, 1: test udc cable type mod
module_param(udc_debug, int, 0);
MODULE_PARM_DESC(udc_debug, "test udc cable or power type");
static unsigned int use_dma = 1; /* 1: use DMA, 0: use PIO */
static unsigned int use_dma = 0; /* 1: use DMA, 0: use PIO */
module_param(use_dma, int, 0);
MODULE_PARM_DESC(use_dma, "DMA mode enable flag");
/*
* Local definintions.
*/
#define DRIVER_VERSION "13-Mar-2008"
#define DRIVER_DESC "JZ4740 USB Device Controller"
static const char gadget_name [] = "ingenic_hsusb";
struct jz4740_udc *the_controller;
static const char driver_name [] = "ingenic_hsusb";
static const char driver_desc [] = DRIVER_DESC;
static const char ep0name[] = "ep0";
#ifndef NO_STATES
static char *state_names[] = {
"WAIT_FOR_SETUP",
"DATA_STATE_XMIT",
"DATA_STATE_NEED_ZLP",
"WAIT_FOR_OUT_STATUS",
"DATA_STATE_RECV"
};
#endif
/*
* Local declarations.
*/
@ -122,7 +101,6 @@ static void nuke(struct jz4740_ep *ep, int status);
static void flush(struct jz4740_ep *ep);
static void udc_enable(struct jz4740_udc *dev);
static void udc_set_address(struct jz4740_udc *dev, unsigned char address);
static void jz4740_udc_release (struct device *dev) {}
extern void *dma_alloc_noncoherent(struct device *dev, size_t size,
dma_addr_t *dma_handle, gfp_t flag);
@ -422,26 +400,23 @@ int usb_gadget_register_driver(struct usb_gadget_driver *driver)
struct jz4740_udc *dev = the_controller;
int retval;
if (!driver
|| !driver->bind
|| !driver->unbind || !driver->disconnect || !driver->setup)
if (!driver || !driver->bind)
{
printk("\n-EINVAL");
return -EINVAL;
}
if (!dev)
{
printk("\n-ENODEV");
return -ENODEV;
}
if (dev->driver)
{
printk("\n-EBUSY");
return -EBUSY;
}
/* hook up the driver */
dev->driver = driver;
dev->gadget.dev.driver = &driver->driver;
retval = driver->bind(&dev->gadget);
if (retval) {
DEBUG("%s: bind to driver %s --> error %d\n", dev->gadget.name,
@ -804,6 +779,8 @@ static void pio_irq_disable(struct jz4740_ep *ep)
{
DEBUG("%s: EP%d %s\n", __FUNCTION__, ep_index(ep), ep_is_in(ep) ? "IN": "OUT");
return;
if (ep_is_in(ep)) {
switch (ep_index(ep)) {
case 1:
@ -983,6 +960,7 @@ static int jz4740_ep_enable(struct usb_ep *_ep,
struct jz4740_udc *dev;
unsigned long flags;
u32 max, csrh = 0;
DEBUG("%s: trying to enable %s\n", __FUNCTION__, _ep->name);
ep = container_of(_ep, struct jz4740_ep, ep);
if (!_ep || !desc || ep->desc || _ep->name == ep0name
@ -1011,6 +989,7 @@ static int jz4740_ep_enable(struct usb_ep *_ep,
/* Configure the endpoint */
usb_set_index(desc->bEndpointAddress & 0x0F);
if (ep_is_in(ep)) {
printk("%s: ep is in\n", __FUNCTION__);
usb_writew(USB_REG_INMAXP, max);
switch (desc->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) {
case USB_ENDPOINT_XFER_BULK:
@ -1024,6 +1003,7 @@ static int jz4740_ep_enable(struct usb_ep *_ep,
usb_writeb(USB_REG_INCSRH, csrh);
}
else {
printk("%s: ep is out\n", __FUNCTION__);
usb_writew(USB_REG_OUTMAXP, max);
switch (desc->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) {
case USB_ENDPOINT_XFER_BULK:
@ -2121,9 +2101,9 @@ static struct jz4740_udc udc_dev = {
.gadget = {
.ops = &jz4740_udc_ops,
.ep0 = &udc_dev.ep[0].ep,
.name = driver_name,
.name = "jz-udc",
.dev = {
.bus_id = "gadget",
.init_name = "gadget",
},
},
@ -2196,24 +2176,28 @@ static struct jz4740_udc udc_dev = {
},
};
static void gadget_release(struct device *_dev)
{
}
static int jz4740_udc_probe(struct platform_device *pdev)
{
struct jz4740_udc *dev = &udc_dev;
int rc;
DEBUG("%s\n", __FUNCTION__);
spin_lock_init(&dev->lock);
the_controller = dev;
dev->dev = &pdev->dev;
// device_initialize(&dev->gadget.dev); /* device_register() will do this. In Linux-2.6.27 re-initializing a kobject will cause a warning. */
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;
// strcpy (dum->gadget.dev.bus_id, "gadget");
dev->gadget.dev.release = jz4740_udc_release;
if ((rc = device_register (&dev->gadget.dev)) < 0)
return rc;
platform_set_drvdata(pdev, dev);
udc_disable(dev);
@ -2221,21 +2205,17 @@ static int jz4740_udc_probe(struct platform_device *pdev)
/* irq setup */
if (request_irq(IRQ_UDC, jz4740_udc_irq, IRQF_DISABLED,//SA_SHIRQ/*|SA_SAMPLE_RANDOM*/,
driver_name, dev) != 0) {
pdev->name, dev) != 0) {
printk(KERN_INFO "request UDC interrupt %d failed\n", IRQ_UDC);
return -EBUSY;
}
printk(KERN_INFO "%s\n", driver_desc);
printk(KERN_INFO "version: " DRIVER_VERSION "\n");
return 0;
}
static int jz4740_udc_remove(struct platform_device *pdev)
{
struct jz4740_udc *dev = platform_get_drvdata(pdev);
DEBUG("%s: %p\n", __FUNCTION__, dev);
if (dev->driver)
return -EBUSY;
@ -2256,37 +2236,22 @@ static int jz4740_udc_remove(struct platform_device *pdev)
static struct platform_driver udc_driver = {
.probe = jz4740_udc_probe,
.remove = jz4740_udc_remove,
.suspend = NULL,
.resume = NULL,
.driver = {
.name = (char *) driver_name,
.name = "jz-udc",
.owner = THIS_MODULE,
},
};
static struct platform_device the_udc_pdev = {
.name = (char *) gadget_name,
.id = -1,
.dev = {
.release = jz4740_udc_release,
},
};
/*-------------------------------------------------------------------------*/
static int __init udc_init (void)
{
platform_driver_register(&udc_driver);
return platform_device_register (&the_udc_pdev);
return platform_driver_register(&udc_driver);
}
static void __exit udc_exit (void)
{
platform_driver_unregister(&udc_driver);
platform_device_unregister(&the_udc_pdev);
}
module_init(udc_init);