summaryrefslogtreecommitdiff
path: root/drivers/usb/misc/adutux.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/usb/misc/adutux.c')
-rw-r--r--drivers/usb/misc/adutux.c200
1 files changed, 74 insertions, 126 deletions
diff --git a/drivers/usb/misc/adutux.c b/drivers/usb/misc/adutux.c
index eeb27208c0d1..3eaa83f05086 100644
--- a/drivers/usb/misc/adutux.c
+++ b/drivers/usb/misc/adutux.c
@@ -18,6 +18,8 @@
*
*/
+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+
#include <linux/kernel.h>
#include <linux/errno.h>
#include <linux/init.h>
@@ -27,30 +29,11 @@
#include <linux/mutex.h>
#include <linux/uaccess.h>
-#ifdef CONFIG_USB_DEBUG
-static int debug = 5;
-#else
-static int debug = 1;
-#endif
-
-/* Use our own dbg macro */
-#undef dbg
-#define dbg(lvl, format, arg...) \
-do { \
- if (debug >= lvl) \
- printk(KERN_DEBUG "%s: " format "\n", __FILE__, ##arg); \
-} while (0)
-
-
/* Version Information */
#define DRIVER_VERSION "v0.0.13"
#define DRIVER_AUTHOR "John Homppi"
#define DRIVER_DESC "adutux (see www.ontrak.net)"
-/* Module parameters */
-module_param(debug, int, S_IRUGO | S_IWUSR);
-MODULE_PARM_DESC(debug, "Debug enabled or not");
-
/* Define these values to match your device */
#define ADU_VENDOR_ID 0x0a07
#define ADU_PRODUCT_ID 0x0064
@@ -124,19 +107,11 @@ static DEFINE_MUTEX(adutux_mutex);
static struct usb_driver adu_driver;
-static void adu_debug_data(int level, const char *function, int size,
- const unsigned char *data)
+static inline void adu_debug_data(struct device *dev, const char *function,
+ int size, const unsigned char *data)
{
- int i;
-
- if (debug < level)
- return;
-
- printk(KERN_DEBUG "%s: %s - length = %d, data = ",
- __FILE__, function, size);
- for (i = 0; i < size; ++i)
- printk("%.2x ", data[i]);
- printk("\n");
+ dev_dbg(dev, "%s - length = %d, data = %*ph\n",
+ function, size, size, data);
}
/**
@@ -147,12 +122,8 @@ static void adu_abort_transfers(struct adu_device *dev)
{
unsigned long flags;
- dbg(2, " %s : enter", __func__);
-
- if (dev->udev == NULL) {
- dbg(1, " %s : udev is null", __func__);
- goto exit;
- }
+ if (dev->udev == NULL)
+ return;
/* shutdown transfer */
@@ -170,15 +141,10 @@ static void adu_abort_transfers(struct adu_device *dev)
usb_kill_urb(dev->interrupt_out_urb);
} else
spin_unlock_irqrestore(&dev->buflock, flags);
-
-exit:
- dbg(2, " %s : leave", __func__);
}
static void adu_delete(struct adu_device *dev)
{
- dbg(2, "%s enter", __func__);
-
/* free data structures */
usb_free_urb(dev->interrupt_in_urb);
usb_free_urb(dev->interrupt_out_urb);
@@ -187,8 +153,6 @@ static void adu_delete(struct adu_device *dev)
kfree(dev->interrupt_in_buffer);
kfree(dev->interrupt_out_buffer);
kfree(dev);
-
- dbg(2, "%s : leave", __func__);
}
static void adu_interrupt_in_callback(struct urb *urb)
@@ -196,17 +160,17 @@ static void adu_interrupt_in_callback(struct urb *urb)
struct adu_device *dev = urb->context;
int status = urb->status;
- dbg(4, " %s : enter, status %d", __func__, status);
- adu_debug_data(5, __func__, urb->actual_length,
- urb->transfer_buffer);
+ adu_debug_data(&dev->udev->dev, __func__,
+ urb->actual_length, urb->transfer_buffer);
spin_lock(&dev->buflock);
if (status != 0) {
if ((status != -ENOENT) && (status != -ECONNRESET) &&
(status != -ESHUTDOWN)) {
- dbg(1, " %s : nonzero status received: %d",
- __func__, status);
+ dev_dbg(&dev->udev->dev,
+ "%s : nonzero status received: %d\n",
+ __func__, status);
}
goto exit;
}
@@ -220,10 +184,11 @@ static void adu_interrupt_in_callback(struct urb *urb)
dev->interrupt_in_buffer, urb->actual_length);
dev->read_buffer_length += urb->actual_length;
- dbg(2, " %s reading %d ", __func__,
- urb->actual_length);
+ dev_dbg(&dev->udev->dev,"%s reading %d\n", __func__,
+ urb->actual_length);
} else {
- dbg(1, " %s : read_buffer overflow", __func__);
+ dev_dbg(&dev->udev->dev,"%s : read_buffer overflow\n",
+ __func__);
}
}
@@ -232,9 +197,6 @@ exit:
spin_unlock(&dev->buflock);
/* always wake up so we recover from errors */
wake_up_interruptible(&dev->read_wait);
- adu_debug_data(5, __func__, urb->actual_length,
- urb->transfer_buffer);
- dbg(4, " %s : leave, status %d", __func__, status);
}
static void adu_interrupt_out_callback(struct urb *urb)
@@ -242,27 +204,23 @@ static void adu_interrupt_out_callback(struct urb *urb)
struct adu_device *dev = urb->context;
int status = urb->status;
- dbg(4, " %s : enter, status %d", __func__, status);
- adu_debug_data(5, __func__, urb->actual_length, urb->transfer_buffer);
+ adu_debug_data(&dev->udev->dev, __func__,
+ urb->actual_length, urb->transfer_buffer);
if (status != 0) {
if ((status != -ENOENT) &&
(status != -ECONNRESET)) {
- dbg(1, " %s :nonzero status received: %d",
- __func__, status);
+ dev_dbg(&dev->udev->dev,
+ "%s :nonzero status received: %d\n", __func__,
+ status);
}
- goto exit;
+ return;
}
spin_lock(&dev->buflock);
dev->out_urb_finished = 1;
wake_up(&dev->write_wait);
spin_unlock(&dev->buflock);
-exit:
-
- adu_debug_data(5, __func__, urb->actual_length,
- urb->transfer_buffer);
- dbg(4, " %s : leave, status %d", __func__, status);
}
static int adu_open(struct inode *inode, struct file *file)
@@ -272,20 +230,16 @@ static int adu_open(struct inode *inode, struct file *file)
int subminor;
int retval;
- dbg(2, "%s : enter", __func__);
-
subminor = iminor(inode);
retval = mutex_lock_interruptible(&adutux_mutex);
- if (retval) {
- dbg(2, "%s : mutex lock failed", __func__);
+ if (retval)
goto exit_no_lock;
- }
interface = usb_find_interface(&adu_driver, subminor);
if (!interface) {
- printk(KERN_ERR "adutux: %s - error, can't find device for "
- "minor %d\n", __func__, subminor);
+ pr_err("%s - error, can't find device for minor %d\n",
+ __func__, subminor);
retval = -ENODEV;
goto exit_no_device;
}
@@ -303,7 +257,8 @@ static int adu_open(struct inode *inode, struct file *file)
}
++dev->open_count;
- dbg(2, "%s : open count %d", __func__, dev->open_count);
+ dev_dbg(&dev->udev->dev, "%s: open count %d\n", __func__,
+ dev->open_count);
/* save device in the file's private structure */
file->private_data = dev;
@@ -333,23 +288,19 @@ static int adu_open(struct inode *inode, struct file *file)
exit_no_device:
mutex_unlock(&adutux_mutex);
exit_no_lock:
- dbg(2, "%s : leave, return value %d ", __func__, retval);
return retval;
}
static void adu_release_internal(struct adu_device *dev)
{
- dbg(2, " %s : enter", __func__);
-
/* decrement our usage count for the device */
--dev->open_count;
- dbg(2, " %s : open count %d", __func__, dev->open_count);
+ dev_dbg(&dev->udev->dev, "%s : open count %d\n", __func__,
+ dev->open_count);
if (dev->open_count <= 0) {
adu_abort_transfers(dev);
dev->open_count = 0;
}
-
- dbg(2, " %s : leave", __func__);
}
static int adu_release(struct inode *inode, struct file *file)
@@ -357,17 +308,13 @@ static int adu_release(struct inode *inode, struct file *file)
struct adu_device *dev;
int retval = 0;
- dbg(2, " %s : enter", __func__);
-
if (file == NULL) {
- dbg(1, " %s : file is NULL", __func__);
retval = -ENODEV;
goto exit;
}
dev = file->private_data;
if (dev == NULL) {
- dbg(1, " %s : object is NULL", __func__);
retval = -ENODEV;
goto exit;
}
@@ -375,7 +322,7 @@ static int adu_release(struct inode *inode, struct file *file)
mutex_lock(&adutux_mutex); /* not interruptible */
if (dev->open_count <= 0) {
- dbg(1, " %s : device not opened", __func__);
+ dev_dbg(&dev->udev->dev, "%s : device not opened\n", __func__);
retval = -ENODEV;
goto unlock;
}
@@ -389,7 +336,6 @@ static int adu_release(struct inode *inode, struct file *file)
unlock:
mutex_unlock(&adutux_mutex);
exit:
- dbg(2, " %s : leave, return value %d", __func__, retval);
return retval;
}
@@ -406,35 +352,32 @@ static ssize_t adu_read(struct file *file, __user char *buffer, size_t count,
unsigned long flags;
DECLARE_WAITQUEUE(wait, current);
- dbg(2, " %s : enter, count = %Zd, file=%p", __func__, count, file);
-
dev = file->private_data;
- dbg(2, " %s : dev=%p", __func__, dev);
-
if (mutex_lock_interruptible(&dev->mtx))
return -ERESTARTSYS;
/* verify that the device wasn't unplugged */
if (dev->udev == NULL) {
retval = -ENODEV;
- printk(KERN_ERR "adutux: No device or device unplugged %d\n",
- retval);
+ pr_err("No device or device unplugged %d\n", retval);
goto exit;
}
/* verify that some data was requested */
if (count == 0) {
- dbg(1, " %s : read request of 0 bytes", __func__);
+ dev_dbg(&dev->udev->dev, "%s : read request of 0 bytes\n",
+ __func__);
goto exit;
}
timeout = COMMAND_TIMEOUT;
- dbg(2, " %s : about to start looping", __func__);
+ dev_dbg(&dev->udev->dev, "%s : about to start looping\n", __func__);
while (bytes_to_read) {
int data_in_secondary = dev->secondary_tail - dev->secondary_head;
- dbg(2, " %s : while, data_in_secondary=%d, status=%d",
- __func__, data_in_secondary,
- dev->interrupt_in_urb->status);
+ dev_dbg(&dev->udev->dev,
+ "%s : while, data_in_secondary=%d, status=%d\n",
+ __func__, data_in_secondary,
+ dev->interrupt_in_urb->status);
if (data_in_secondary) {
/* drain secondary buffer */
@@ -457,8 +400,9 @@ static ssize_t adu_read(struct file *file, __user char *buffer, size_t count,
if (dev->read_buffer_length) {
/* we secure access to the primary */
char *tmp;
- dbg(2, " %s : swap, read_buffer_length = %d",
- __func__, dev->read_buffer_length);
+ dev_dbg(&dev->udev->dev,
+ "%s : swap, read_buffer_length = %d\n",
+ __func__, dev->read_buffer_length);
tmp = dev->read_buffer_secondary;
dev->read_buffer_secondary = dev->read_buffer_primary;
dev->read_buffer_primary = tmp;
@@ -473,10 +417,14 @@ static ssize_t adu_read(struct file *file, __user char *buffer, size_t count,
if (!dev->read_urb_finished) {
/* somebody is doing IO */
spin_unlock_irqrestore(&dev->buflock, flags);
- dbg(2, " %s : submitted already", __func__);
+ dev_dbg(&dev->udev->dev,
+ "%s : submitted already\n",
+ __func__);
} else {
/* we must initiate input */
- dbg(2, " %s : initiate input", __func__);
+ dev_dbg(&dev->udev->dev,
+ "%s : initiate input\n",
+ __func__);
dev->read_urb_finished = 0;
spin_unlock_irqrestore(&dev->buflock, flags);
@@ -494,7 +442,9 @@ static ssize_t adu_read(struct file *file, __user char *buffer, size_t count,
if (retval == -ENOMEM) {
retval = bytes_read ? bytes_read : -ENOMEM;
}
- dbg(2, " %s : submit failed", __func__);
+ dev_dbg(&dev->udev->dev,
+ "%s : submit failed\n",
+ __func__);
goto exit;
}
}
@@ -513,13 +463,16 @@ static ssize_t adu_read(struct file *file, __user char *buffer, size_t count,
remove_wait_queue(&dev->read_wait, &wait);
if (timeout <= 0) {
- dbg(2, " %s : timeout", __func__);
+ dev_dbg(&dev->udev->dev,
+ "%s : timeout\n", __func__);
retval = bytes_read ? bytes_read : -ETIMEDOUT;
goto exit;
}
if (signal_pending(current)) {
- dbg(2, " %s : signal pending", __func__);
+ dev_dbg(&dev->udev->dev,
+ "%s : signal pending\n",
+ __func__);
retval = bytes_read ? bytes_read : -EINTR;
goto exit;
}
@@ -552,7 +505,6 @@ exit:
/* unlock the device */
mutex_unlock(&dev->mtx);
- dbg(2, " %s : leave, return value %d", __func__, retval);
return retval;
}
@@ -567,8 +519,6 @@ static ssize_t adu_write(struct file *file, const __user char *buffer,
unsigned long flags;
int retval;
- dbg(2, " %s : enter, count = %Zd", __func__, count);
-
dev = file->private_data;
retval = mutex_lock_interruptible(&dev->mtx);
@@ -578,14 +528,14 @@ static ssize_t adu_write(struct file *file, const __user char *buffer,
/* verify that the device wasn't unplugged */
if (dev->udev == NULL) {
retval = -ENODEV;
- printk(KERN_ERR "adutux: No device or device unplugged %d\n",
- retval);
+ pr_err("No device or device unplugged %d\n", retval);
goto exit;
}
/* verify that we actually have some data to write */
if (count == 0) {
- dbg(1, " %s : write request of 0 bytes", __func__);
+ dev_dbg(&dev->udev->dev, "%s : write request of 0 bytes\n",
+ __func__);
goto exit;
}
@@ -598,13 +548,15 @@ static ssize_t adu_write(struct file *file, const __user char *buffer,
mutex_unlock(&dev->mtx);
if (signal_pending(current)) {
- dbg(1, " %s : interrupted", __func__);
+ dev_dbg(&dev->udev->dev, "%s : interrupted\n",
+ __func__);
set_current_state(TASK_RUNNING);
retval = -EINTR;
goto exit_onqueue;
}
if (schedule_timeout(COMMAND_TIMEOUT) == 0) {
- dbg(1, "%s - command timed out.", __func__);
+ dev_dbg(&dev->udev->dev,
+ "%s - command timed out.\n", __func__);
retval = -ETIMEDOUT;
goto exit_onqueue;
}
@@ -615,18 +567,22 @@ static ssize_t adu_write(struct file *file, const __user char *buffer,
goto exit_nolock;
}
- dbg(4, " %s : in progress, count = %Zd", __func__, count);
+ dev_dbg(&dev->udev->dev,
+ "%s : in progress, count = %Zd\n",
+ __func__, count);
} else {
spin_unlock_irqrestore(&dev->buflock, flags);
set_current_state(TASK_RUNNING);
remove_wait_queue(&dev->write_wait, &waita);
- dbg(4, " %s : sending, count = %Zd", __func__, count);
+ dev_dbg(&dev->udev->dev, "%s : sending, count = %Zd\n",
+ __func__, count);
/* write the data into interrupt_out_buffer from userspace */
buffer_size = usb_endpoint_maxp(dev->interrupt_out_endpoint);
bytes_to_write = count > buffer_size ? buffer_size : count;
- dbg(4, " %s : buffer_size = %Zd, count = %Zd, bytes_to_write = %Zd",
- __func__, buffer_size, count, bytes_to_write);
+ dev_dbg(&dev->udev->dev,
+ "%s : buffer_size = %Zd, count = %Zd, bytes_to_write = %Zd\n",
+ __func__, buffer_size, count, bytes_to_write);
if (copy_from_user(dev->interrupt_out_buffer, buffer, bytes_to_write) != 0) {
retval = -EFAULT;
@@ -665,7 +621,6 @@ static ssize_t adu_write(struct file *file, const __user char *buffer,
exit:
mutex_unlock(&dev->mtx);
exit_nolock:
- dbg(2, " %s : leave, return value %d", __func__, retval);
return retval;
exit_onqueue:
@@ -711,8 +666,6 @@ static int adu_probe(struct usb_interface *interface,
int out_end_size;
int i;
- dbg(2, " %s : enter", __func__);
-
if (udev == NULL) {
dev_err(&interface->dev, "udev is NULL.\n");
goto exit;
@@ -812,7 +765,7 @@ static int adu_probe(struct usb_interface *interface,
dev_err(&interface->dev, "Could not retrieve serial number\n");
goto error;
}
- dbg(2, " %s : serial_number=%s", __func__, dev->serial_number);
+ dev_dbg(&interface->dev,"serial_number=%s", dev->serial_number);
/* we can register the device now, as it is ready */
usb_set_intfdata(interface, dev);
@@ -833,8 +786,6 @@ static int adu_probe(struct usb_interface *interface,
le16_to_cpu(udev->descriptor.idProduct), dev->serial_number,
(dev->minor - ADU_MINOR_BASE));
exit:
- dbg(2, " %s : leave, return value %p (dev)", __func__, dev);
-
return retval;
error:
@@ -852,8 +803,6 @@ static void adu_disconnect(struct usb_interface *interface)
struct adu_device *dev;
int minor;
- dbg(2, " %s : enter", __func__);
-
dev = usb_get_intfdata(interface);
mutex_lock(&dev->mtx); /* not interruptible */
@@ -866,7 +815,8 @@ static void adu_disconnect(struct usb_interface *interface)
usb_set_intfdata(interface, NULL);
/* if the device is not opened, then we clean up right now */
- dbg(2, " %s : open count %d", __func__, dev->open_count);
+ dev_dbg(&dev->udev->dev, "%s : open count %d\n",
+ __func__, dev->open_count);
if (!dev->open_count)
adu_delete(dev);
@@ -874,8 +824,6 @@ static void adu_disconnect(struct usb_interface *interface)
dev_info(&interface->dev, "ADU device adutux%d now disconnected\n",
(minor - ADU_MINOR_BASE));
-
- dbg(2, " %s : leave", __func__);
}
/* usb specific object needed to register this driver with the usb subsystem */