Commit 4166c817 authored by David Brownell's avatar David Brownell Committed by Greg Kroah-Hartman

[PATCH] USB: gadget cleanup of #ifdefs

> can you get rid of all of the #ifdef HAVE_DRIVER_MODEL stuff?

Done.  Now this code "knows" it's running in a 2.5
environment, and needs modifications to run on 2.4.

I also changed the file modes in the module_parm()
calls so the parameters will be writable when they
eventually show up in sysfs; and fixed a typo.

Compile-tested with and without DEBUG enabled.
parent 02d57f34
...@@ -118,7 +118,7 @@ config USB_ETH ...@@ -118,7 +118,7 @@ config USB_ETH
This driver implements the "Communication Device Class" (CDC) This driver implements the "Communication Device Class" (CDC)
Ethernet Control Model. That protocol is often avoided with pure Ethernet Control Model. That protocol is often avoided with pure
Ethernet adapters, in favor of simpler vendor-specific hardware, Ethernet adapters, in favor of simpler vendor-specific hardware,
but is widely suppored by firmware for smart network devices. but is widely supported by firmware for smart network devices.
Within the USB device, this gadget driver exposes a network device Within the USB device, this gadget driver exposes a network device
"usbX", where X depends on what other networking devices you have. "usbX", where X depends on what other networking devices you have.
......
...@@ -37,6 +37,8 @@ ...@@ -37,6 +37,8 @@
#include <linux/interrupt.h> #include <linux/interrupt.h>
#include <linux/uts.h> #include <linux/uts.h>
#include <linux/version.h> #include <linux/version.h>
#include <linux/device.h>
#include <linux/moduleparam.h>
#include <asm/byteorder.h> #include <asm/byteorder.h>
#include <asm/io.h> #include <asm/io.h>
...@@ -118,17 +120,8 @@ static unsigned qmult = 4; ...@@ -118,17 +120,8 @@ static unsigned qmult = 4;
#define TX_DELAY 8 #define TX_DELAY 8
#ifdef HAVE_DRIVER_MODEL module_param (qmult, uint, S_IRUGO|S_IWUSR);
#include <linux/moduleparam.h>
module_param (qmult, uint, 0);
#else
MODULE_PARM (qmult, "i");
MODULE_PARM_DESC (qmult, "rx/tx buffering factor");
#endif /* HAVE_DRIVER_MODEL */
/*-------------------------------------------------------------------------*/ /*-------------------------------------------------------------------------*/
...@@ -279,14 +272,8 @@ static const char EP_IN_NAME [] = "ep2in-bulk"; ...@@ -279,14 +272,8 @@ static const char EP_IN_NAME [] = "ep2in-bulk";
/*-------------------------------------------------------------------------*/ /*-------------------------------------------------------------------------*/
#ifdef HAVE_DRIVER_MODEL #define xprintk(d,level,fmt,args...) \
#define xprintk(dev,level,fmt,args...) \ dev_printk(level , &(d)->gadget->dev , fmt , ## args)
dev_printk(level , &dev->gadget->dev , fmt , ## args)
#else
#define xprintk(dev,level,fmt,args...) \
printk(level "%s %s: " fmt , shortname, dev->gadget->dev.bus_id, \
## args)
#endif /* HAVE_DRIVER_MODEL */
#ifdef DEBUG #ifdef DEBUG
#undef DEBUG #undef DEBUG
...@@ -954,12 +941,10 @@ static void issue_start_status (struct eth_dev *dev) ...@@ -954,12 +941,10 @@ static void issue_start_status (struct eth_dev *dev)
static void eth_setup_complete (struct usb_ep *ep, struct usb_request *req) static void eth_setup_complete (struct usb_ep *ep, struct usb_request *req)
{ {
if (req->status || req->actual != req->length) { if (req->status || req->actual != req->length)
struct eth_dev *dev = ep->driver_data; DEBUG ((struct eth_dev *) ep->driver_data,
"setup complete --> %d, %d/%d\n",
DEBUG (dev, "setup complete --> %d, %d/%d\n",
req->status, req->actual, req->length); req->status, req->actual, req->length);
}
} }
/* see section 3.8.2 table 10 of the CDC spec for more ethernet /* see section 3.8.2 table 10 of the CDC spec for more ethernet
......
...@@ -60,8 +60,8 @@ ...@@ -60,8 +60,8 @@
#include <linux/timer.h> #include <linux/timer.h>
#include <linux/list.h> #include <linux/list.h>
#include <linux/interrupt.h> #include <linux/interrupt.h>
#include <linux/version.h> #include <linux/moduleparam.h>
#include <linux/device.h>
#include <linux/usb_ch9.h> #include <linux/usb_ch9.h>
#include <linux/usb_gadget.h> #include <linux/usb_gadget.h>
...@@ -79,6 +79,7 @@ ...@@ -79,6 +79,7 @@
#define EP_DONTUSE 13 /* nonzero */ #define EP_DONTUSE 13 /* nonzero */
#define USE_RDK_LEDS /* GPIO pins control three LEDs */ #define USE_RDK_LEDS /* GPIO pins control three LEDs */
#define USE_SYSFS_DEBUG_FILES
static const char driver_name [] = "net2280"; static const char driver_name [] = "net2280";
...@@ -93,26 +94,12 @@ static const char *ep_name [] = { ...@@ -93,26 +94,12 @@ static const char *ep_name [] = {
static int use_dma = 1; static int use_dma = 1;
#ifdef HAVE_DRIVER_MODEL
#include <linux/moduleparam.h>
/* "modprobe net2280 use_dma=n" etc */ /* "modprobe net2280 use_dma=n" etc */
module_param (use_dma, bool, S_IRUGO|S_IWUSR); module_param (use_dma, bool, S_IRUGO|S_IWUSR);
#else
/* use zero/nonzero for older versions */
MODULE_PARM (use_dma, "i");
MODULE_PARM_DESC (use_dma, "true to use dma controllers");
#endif
#include "net2280.h"
#define valid_bit cpu_to_le32 (1 << VALID_BIT)
#define dma_done_ie cpu_to_le32 (1 << DMA_DONE_INTERRUPT_ENABLE)
/*-------------------------------------------------------------------------*/
#define DIR_STRING(bAddress) (((bAddress) & USB_DIR_IN) ? "in" : "out") #define DIR_STRING(bAddress) (((bAddress) & USB_DIR_IN) ? "in" : "out")
#if defined(USE_SYSFS_DEBUG_FILES) || defined (DEBUG)
static char *type_string (u8 bmAttributes) static char *type_string (u8 bmAttributes)
{ {
switch ((bmAttributes) & USB_ENDPOINT_XFERTYPE_MASK) { switch ((bmAttributes) & USB_ENDPOINT_XFERTYPE_MASK) {
...@@ -122,6 +109,14 @@ static char *type_string (u8 bmAttributes) ...@@ -122,6 +109,14 @@ static char *type_string (u8 bmAttributes)
}; };
return "control"; return "control";
} }
#endif
#include "net2280.h"
#define valid_bit cpu_to_le32 (1 << VALID_BIT)
#define dma_done_ie cpu_to_le32 (1 << DMA_DONE_INTERRUPT_ENABLE)
/*-------------------------------------------------------------------------*/
static int static int
net2280_enable (struct usb_ep *_ep, const struct usb_endpoint_descriptor *desc) net2280_enable (struct usb_ep *_ep, const struct usb_endpoint_descriptor *desc)
...@@ -1280,7 +1275,7 @@ static const struct usb_gadget_ops net2280_ops = { ...@@ -1280,7 +1275,7 @@ static const struct usb_gadget_ops net2280_ops = {
/*-------------------------------------------------------------------------*/ /*-------------------------------------------------------------------------*/
#ifdef HAVE_DRIVER_MODEL #ifdef USE_SYSFS_DEBUG_FILES
/* "function" sysfs attribute */ /* "function" sysfs attribute */
static ssize_t static ssize_t
...@@ -1771,25 +1766,19 @@ int usb_gadget_register_driver (struct usb_gadget_driver *driver) ...@@ -1771,25 +1766,19 @@ int usb_gadget_register_driver (struct usb_gadget_driver *driver)
/* hook up the driver ... */ /* hook up the driver ... */
dev->driver = driver; dev->driver = driver;
#ifdef HAVE_DRIVER_MODEL
dev->gadget.dev.driver = &driver->driver; dev->gadget.dev.driver = &driver->driver;
#endif
retval = driver->bind (&dev->gadget); retval = driver->bind (&dev->gadget);
if (retval) { if (retval) {
DEBUG (dev, "bind to driver %s --> %d\n", DEBUG (dev, "bind to driver %s --> %d\n",
driver->driver.name, retval); driver->driver.name, retval);
dev->driver = 0; dev->driver = 0;
#ifdef HAVE_DRIVER_MODEL
dev->gadget.dev.driver = 0; dev->gadget.dev.driver = 0;
#endif
return retval; return retval;
} }
#ifdef HAVE_DRIVER_MODEL
// FIXME // FIXME
// driver_register (&driver->driver); // driver_register (&driver->driver);
// device_register (&dev->gadget.dev); // device_register (&dev->gadget.dev);
#endif
device_create_file (&dev->pdev->dev, &dev_attr_function); device_create_file (&dev->pdev->dev, &dev_attr_function);
device_create_file (&dev->pdev->dev, &dev_attr_queues); device_create_file (&dev->pdev->dev, &dev_attr_queues);
...@@ -2501,14 +2490,10 @@ static int net2280_probe (struct pci_dev *pdev, const struct pci_device_id *id) ...@@ -2501,14 +2490,10 @@ static int net2280_probe (struct pci_dev *pdev, const struct pci_device_id *id)
dev->pdev = pdev; dev->pdev = pdev;
dev->gadget.ops = &net2280_ops; dev->gadget.ops = &net2280_ops;
#ifdef HAVE_DRIVER_MODEL
strcpy (dev->gadget.dev.bus_id, pdev->slot_name); strcpy (dev->gadget.dev.bus_id, pdev->slot_name);
strcpy (dev->gadget.dev.name, pdev->dev.name); strcpy (dev->gadget.dev.name, pdev->dev.name);
dev->gadget.dev.parent = &pdev->dev; dev->gadget.dev.parent = &pdev->dev;
dev->gadget.dev.dma_mask = pdev->dev.dma_mask; dev->gadget.dev.dma_mask = pdev->dev.dma_mask;
#else
dev->gadget.dev.bus_id = pdev->slot_name;
#endif
dev->gadget.name = driver_name; dev->gadget.name = driver_name;
/* now all the pci goodies ... */ /* now all the pci goodies ... */
...@@ -2601,9 +2586,7 @@ static int net2280_probe (struct pci_dev *pdev, const struct pci_device_id *id) ...@@ -2601,9 +2586,7 @@ static int net2280_probe (struct pci_dev *pdev, const struct pci_device_id *id)
, &dev->pci->pcimstctl); , &dev->pci->pcimstctl);
/* erratum 0115 shouldn't appear: Linux inits PCI_LATENCY_TIMER */ /* erratum 0115 shouldn't appear: Linux inits PCI_LATENCY_TIMER */
pci_set_master (pdev); pci_set_master (pdev);
#ifdef HAVE_PCI_SET_MWI
pci_set_mwi (pdev); pci_set_mwi (pdev);
#endif
/* ... also flushes any posted pci writes */ /* ... also flushes any posted pci writes */
dev->chiprev = get_idx_reg (dev->regs, REG_CHIPREV) & 0xffff; dev->chiprev = get_idx_reg (dev->regs, REG_CHIPREV) & 0xffff;
......
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
#include <linux/kernel.h> #include <linux/kernel.h>
#include <linux/list.h> #include <linux/list.h>
#include <linux/string.h> #include <linux/string.h>
#include <linux/version.h> #include <linux/device.h>
#include <linux/usb_ch9.h> #include <linux/usb_ch9.h>
#include <linux/usb_gadget.h> #include <linux/usb_gadget.h>
......
...@@ -77,6 +77,8 @@ ...@@ -77,6 +77,8 @@
#include <linux/interrupt.h> #include <linux/interrupt.h>
#include <linux/uts.h> #include <linux/uts.h>
#include <linux/version.h> #include <linux/version.h>
#include <linux/device.h>
#include <linux/moduleparam.h>
#include <asm/byteorder.h> #include <asm/byteorder.h>
#include <asm/io.h> #include <asm/io.h>
...@@ -259,14 +261,8 @@ struct zero_dev { ...@@ -259,14 +261,8 @@ struct zero_dev {
struct usb_ep *in_ep, *out_ep; struct usb_ep *in_ep, *out_ep;
}; };
#ifdef HAVE_DRIVER_MODEL #define xprintk(d,level,fmt,args...) \
#define xprintk(dev,level,fmt,args...) \ dev_printk(level , &(d)->gadget->dev , fmt , ## args)
dev_printk(level , &dev->gadget->dev , fmt , ## args)
#else
#define xprintk(dev,level,fmt,args...) \
printk(level "%s %s: " fmt , shortname, dev->gadget->dev.bus_id, \
## args)
#endif /* HAVE_DRIVER_MODEL */
#ifdef DEBUG #ifdef DEBUG
#undef DEBUG #undef DEBUG
...@@ -296,6 +292,9 @@ struct zero_dev { ...@@ -296,6 +292,9 @@ struct zero_dev {
static unsigned buflen = 4096; static unsigned buflen = 4096;
static unsigned qlen = 32; static unsigned qlen = 32;
module_param (buflen, uint, S_IRUGO|S_IWUSR);
module_param (qlen, uint, S_IRUGO|S_IWUSR);
/* /*
* Normally the "loopback" configuration is second (index 1) so * Normally the "loopback" configuration is second (index 1) so
* it's not the default. Here's where to change that order, to * it's not the default. Here's where to change that order, to
...@@ -304,25 +303,7 @@ static unsigned qlen = 32; ...@@ -304,25 +303,7 @@ static unsigned qlen = 32;
*/ */
static int loopdefault = 0; static int loopdefault = 0;
#ifdef HAVE_DRIVER_MODEL module_param (loopdefault, bool, S_IRUGO|S_IWUSR);
#include <linux/moduleparam.h>
module_param (buflen, uint, 0);
module_param (qlen, uint, 0);
module_param (loopdefault, bool, 0);
#else
MODULE_PARM (buflen, "i");
MODULE_PARM_DESC (buflen, "size of i/o buffers");
MODULE_PARM (qlen, "i");
MODULE_PARM_DESC (qlen, "depth of loopback buffering");
MODULE_PARM (loopdefault, "b");
MODULE_PARM_DESC (loopdefault, "true to have default config be loopback");
#endif /* HAVE_DRIVER_MODEL */
/*-------------------------------------------------------------------------*/ /*-------------------------------------------------------------------------*/
...@@ -984,12 +965,10 @@ zero_set_config (struct zero_dev *dev, unsigned number, int gfp_flags) ...@@ -984,12 +965,10 @@ zero_set_config (struct zero_dev *dev, unsigned number, int gfp_flags)
static void zero_setup_complete (struct usb_ep *ep, struct usb_request *req) static void zero_setup_complete (struct usb_ep *ep, struct usb_request *req)
{ {
if (req->status || req->actual != req->length) { if (req->status || req->actual != req->length)
struct zero_dev *dev = ep->driver_data; DEBUG ((struct zero_dev *) ep->driver_data,
"setup complete --> %d, %d/%d\n",
DEBUG (dev, "setup complete --> %d, %d/%d\n",
req->status, req->actual, req->length); req->status, req->actual, req->length);
}
} }
/* /*
......
...@@ -435,11 +435,6 @@ struct usb_gadget_ops { ...@@ -435,11 +435,6 @@ struct usb_gadget_ops {
unsigned code, unsigned long param); unsigned code, unsigned long param);
}; };
#if LINUX_VERSION_CODE > KERNEL_VERSION(2,5,50)
#define HAVE_DRIVER_MODEL
#include <linux/device.h>
#endif
/** /**
* struct usb_gadget - represents a usb slave device * struct usb_gadget - represents a usb slave device
* @ep0: Endpoint zero, used when reading or writing responses to * @ep0: Endpoint zero, used when reading or writing responses to
...@@ -469,47 +464,21 @@ struct usb_gadget { ...@@ -469,47 +464,21 @@ struct usb_gadget {
enum usb_device_speed speed; enum usb_device_speed speed;
const char *name; const char *name;
#ifdef HAVE_DRIVER_MODEL /* use this to allocate dma-coherent buffers or set up
/* with 2.5 "generic dma" api, use this to allocate dma-coherent * dma mappings. or print diagnostics, etc.
* buffers or set up dma mappings. or print diagnostics, etc.
*/ */
struct device dev; struct device dev;
#else
struct __gadget_device {
char *bus_id;
void *driver_data;
} dev;
#endif
}; };
#ifdef HAVE_DRIVER_MODEL
static inline void set_gadget_data (struct usb_gadget *gadget, void *data) static inline void set_gadget_data (struct usb_gadget *gadget, void *data)
{ dev_set_drvdata (&gadget->dev, data); } { dev_set_drvdata (&gadget->dev, data); }
static inline void *get_gadget_data (struct usb_gadget *gadget) static inline void *get_gadget_data (struct usb_gadget *gadget)
{ return dev_get_drvdata (&gadget->dev); } { return dev_get_drvdata (&gadget->dev); }
#else
static inline void set_gadget_data (struct usb_gadget *gadget, void *data)
{ gadget->dev.driver_data = data; }
static inline void *get_gadget_data (struct usb_gadget *gadget)
{ return gadget->dev.driver_data; }
#endif
/* iterates the non-control endpoints; 'tmp' is a struct usb_ep pointer */ /* iterates the non-control endpoints; 'tmp' is a struct usb_ep pointer */
#define gadget_for_each_ep(tmp,gadget) \ #define gadget_for_each_ep(tmp,gadget) \
list_for_each_entry(tmp, &(gadget)->ep_list, ep_list) list_for_each_entry(tmp, &(gadget)->ep_list, ep_list)
#ifndef list_for_each_entry
/* not available in 2.4.18 */
#define list_for_each_entry(pos, head, member) \
for (pos = list_entry((head)->next, typeof(*pos), member), \
prefetch(pos->member.next); \
&pos->member != (head); \
pos = list_entry(pos->member.next, typeof(*pos), member), \
prefetch(pos->member.next))
#endif
/** /**
* usb_gadget_frame_number - returns the current frame number * usb_gadget_frame_number - returns the current frame number
...@@ -649,14 +618,7 @@ struct usb_gadget_driver { ...@@ -649,14 +618,7 @@ struct usb_gadget_driver {
void (*resume)(struct usb_gadget *); void (*resume)(struct usb_gadget *);
// FIXME support safe rmmod // FIXME support safe rmmod
#ifdef HAVE_DRIVER_MODEL
struct device_driver driver; struct device_driver driver;
#else
struct __gadget_driver {
char *name;
void *driver_data;
} driver;
#endif
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment