diff options
Diffstat (limited to 'drivers/media/usb/em28xx/em28xx-core.c')
-rw-r--r-- | drivers/media/usb/em28xx/em28xx-core.c | 206 |
1 files changed, 105 insertions, 101 deletions
diff --git a/drivers/media/usb/em28xx/em28xx-core.c b/drivers/media/usb/em28xx/em28xx-core.c index eebd5d7088d0..19ccff41c7eb 100644 --- a/drivers/media/usb/em28xx/em28xx-core.c +++ b/drivers/media/usb/em28xx/em28xx-core.c @@ -22,6 +22,8 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ +#include "em28xx.h" + #include <linux/init.h> #include <linux/jiffies.h> #include <linux/list.h> @@ -32,8 +34,6 @@ #include <sound/ac97_codec.h> #include <media/v4l2-common.h> -#include "em28xx.h" - #define DRIVER_AUTHOR "Ludovico Cavedon <cavedon@sssup.it>, " \ "Markus Rechberger <mrechberger@gmail.com>, " \ "Mauro Carvalho Chehab <mchehab@infradead.org>, " \ @@ -48,27 +48,31 @@ MODULE_VERSION(EM28XX_VERSION); static unsigned int core_debug; module_param(core_debug, int, 0644); -MODULE_PARM_DESC(core_debug, "enable debug messages [core]"); +MODULE_PARM_DESC(core_debug, "enable debug messages [core and isoc]"); -#define em28xx_coredbg(fmt, arg...) do {\ - if (core_debug) \ - printk(KERN_INFO "%s %s :"fmt, \ - dev->name, __func__ , ##arg); } while (0) +#define em28xx_coredbg(fmt, arg...) do { \ + if (core_debug) \ + dev_printk(KERN_DEBUG, &dev->intf->dev, \ + "core: %s: " fmt, __func__, ## arg); \ +} while (0) static unsigned int reg_debug; module_param(reg_debug, int, 0644); MODULE_PARM_DESC(reg_debug, "enable debug messages [URB reg]"); -#define em28xx_regdbg(fmt, arg...) do {\ - if (reg_debug) \ - printk(KERN_INFO "%s %s :"fmt, \ - dev->name, __func__ , ##arg); } while (0) -/* FIXME */ -#define em28xx_isocdbg(fmt, arg...) do {\ - if (core_debug) \ - printk(KERN_INFO "%s %s :"fmt, \ - dev->name, __func__ , ##arg); } while (0) +#define em28xx_regdbg(fmt, arg...) do { \ + if (reg_debug) \ + dev_printk(KERN_DEBUG, &dev->intf->dev, \ + "reg: %s: " fmt, __func__, ## arg); \ +} while (0) + +/* FIXME: don't abuse core_debug */ +#define em28xx_isocdbg(fmt, arg...) do { \ + if (core_debug) \ + dev_printk(KERN_DEBUG, &dev->intf->dev, \ + "core: %s: " fmt, __func__, ## arg); \ +} while (0) /* * em28xx_read_reg_req() @@ -78,7 +82,8 @@ int em28xx_read_reg_req_len(struct em28xx *dev, u8 req, u16 reg, char *buf, int len) { int ret; - int pipe = usb_rcvctrlpipe(dev->udev, 0); + struct usb_device *udev = interface_to_usbdev(dev->intf); + int pipe = usb_rcvctrlpipe(udev, 0); if (dev->disconnected) return -ENODEV; @@ -86,23 +91,22 @@ int em28xx_read_reg_req_len(struct em28xx *dev, u8 req, u16 reg, if (len > URB_MAX_CTRL_SIZE) return -EINVAL; - if (reg_debug) { - printk(KERN_DEBUG "(pipe 0x%08x): " - "IN: %02x %02x %02x %02x %02x %02x %02x %02x ", - pipe, - USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE, - req, 0, 0, - reg & 0xff, reg >> 8, - len & 0xff, len >> 8); - } + em28xx_regdbg("(pipe 0x%08x): IN: %02x %02x %02x %02x %02x %02x %02x %02x ", + pipe, USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE, + req, 0, 0, + reg & 0xff, reg >> 8, + len & 0xff, len >> 8); mutex_lock(&dev->ctrl_urb_lock); - ret = usb_control_msg(dev->udev, pipe, req, + ret = usb_control_msg(udev, pipe, req, USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE, 0x0000, reg, dev->urb_buf, len, HZ); if (ret < 0) { - if (reg_debug) - printk(" failed!\n"); + em28xx_regdbg("(pipe 0x%08x): IN: %02x %02x %02x %02x %02x %02x %02x %02x failed\n", + pipe, USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE, + req, 0, 0, + reg & 0xff, reg >> 8, + len & 0xff, len >> 8); mutex_unlock(&dev->ctrl_urb_lock); return usb_translate_errors(ret); } @@ -112,14 +116,11 @@ int em28xx_read_reg_req_len(struct em28xx *dev, u8 req, u16 reg, mutex_unlock(&dev->ctrl_urb_lock); - if (reg_debug) { - int byte; - - printk("<<<"); - for (byte = 0; byte < len; byte++) - printk(" %02x", (unsigned char)buf[byte]); - printk("\n"); - } + em28xx_regdbg("(pipe 0x%08x): IN: %02x %02x %02x %02x %02x %02x %02x %02x failed <<< %*ph\n", + pipe, USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE, + req, 0, 0, + reg & 0xff, reg >> 8, + len & 0xff, len >> 8, len, buf); return ret; } @@ -154,7 +155,8 @@ int em28xx_write_regs_req(struct em28xx *dev, u8 req, u16 reg, char *buf, int len) { int ret; - int pipe = usb_sndctrlpipe(dev->udev, 0); + struct usb_device *udev = interface_to_usbdev(dev->intf); + int pipe = usb_sndctrlpipe(udev, 0); if (dev->disconnected) return -ENODEV; @@ -162,25 +164,16 @@ int em28xx_write_regs_req(struct em28xx *dev, u8 req, u16 reg, char *buf, if ((len < 1) || (len > URB_MAX_CTRL_SIZE)) return -EINVAL; - if (reg_debug) { - int byte; - - printk(KERN_DEBUG "(pipe 0x%08x): " - "OUT: %02x %02x %02x %02x %02x %02x %02x %02x >>>", - pipe, - USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE, - req, 0, 0, - reg & 0xff, reg >> 8, - len & 0xff, len >> 8); - - for (byte = 0; byte < len; byte++) - printk(" %02x", (unsigned char)buf[byte]); - printk("\n"); - } + em28xx_regdbg("(pipe 0x%08x): OUT: %02x %02x %02x %02x %02x %02x %02x %02x >>> %*ph\n", + pipe, + USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE, + req, 0, 0, + reg & 0xff, reg >> 8, + len & 0xff, len >> 8, len, buf); mutex_lock(&dev->ctrl_urb_lock); memcpy(dev->urb_buf, buf, len); - ret = usb_control_msg(dev->udev, pipe, req, + ret = usb_control_msg(udev, pipe, req, USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE, 0x0000, reg, dev->urb_buf, len, HZ); mutex_unlock(&dev->ctrl_urb_lock); @@ -267,7 +260,8 @@ static int em28xx_is_ac97_ready(struct em28xx *dev) msleep(5); } - em28xx_warn("AC97 command still being executed: not handled properly!\n"); + dev_warn(&dev->intf->dev, + "AC97 command still being executed: not handled properly!\n"); return -EBUSY; } @@ -360,8 +354,9 @@ static int set_ac97_input(struct em28xx *dev) ret = em28xx_write_ac97(dev, inputs[i].reg, 0x8000); if (ret < 0) - em28xx_warn("couldn't setup AC97 register %d\n", - inputs[i].reg); + dev_warn(&dev->intf->dev, + "couldn't setup AC97 register %d\n", + inputs[i].reg); } return 0; } @@ -444,8 +439,9 @@ int em28xx_audio_analog_set(struct em28xx *dev) for (i = 0; i < ARRAY_SIZE(outputs); i++) { ret = em28xx_write_ac97(dev, outputs[i].reg, 0x8000); if (ret < 0) - em28xx_warn("couldn't setup AC97 register %d\n", - outputs[i].reg); + dev_warn(&dev->intf->dev, + "couldn't setup AC97 register %d\n", + outputs[i].reg); } } @@ -482,8 +478,9 @@ int em28xx_audio_analog_set(struct em28xx *dev) ret = em28xx_write_ac97(dev, outputs[i].reg, vol); if (ret < 0) - em28xx_warn("couldn't setup AC97 register %d\n", - outputs[i].reg); + dev_warn(&dev->intf->dev, + "couldn't setup AC97 register %d\n", + outputs[i].reg); } if (dev->ctl_aoutput & EM28XX_AOUT_PCM_IN) { @@ -519,7 +516,7 @@ int em28xx_audio_setup(struct em28xx *dev) /* See how this device is configured */ cfg = em28xx_read_reg(dev, EM28XX_R00_CHIPCFG); - em28xx_info("Config register raw data: 0x%02x\n", cfg); + dev_info(&dev->intf->dev, "Config register raw data: 0x%02x\n", cfg); if (cfg < 0) { /* Register read error */ /* Be conservative */ dev->int_audio_type = EM28XX_INT_AUDIO_AC97; @@ -540,8 +537,8 @@ int em28xx_audio_setup(struct em28xx *dev) i2s_samplerates = 5; else i2s_samplerates = 3; - em28xx_info("I2S Audio (%d sample rate(s))\n", - i2s_samplerates); + dev_info(&dev->intf->dev, "I2S Audio (%d sample rate(s))\n", + i2s_samplerates); /* Skip the code that does AC97 vendor detection */ dev->audio_mode.ac97 = EM28XX_NO_AC97; goto init_audio; @@ -558,7 +555,8 @@ int em28xx_audio_setup(struct em28xx *dev) * Note: (some) em2800 devices without eeprom reports 0x91 on * CHIPCFG register, even not having an AC97 chip */ - em28xx_warn("AC97 chip type couldn't be determined\n"); + dev_warn(&dev->intf->dev, + "AC97 chip type couldn't be determined\n"); dev->audio_mode.ac97 = EM28XX_NO_AC97; if (dev->usb_audio_type == EM28XX_USB_AUDIO_VENDOR) dev->usb_audio_type = EM28XX_USB_AUDIO_NONE; @@ -571,13 +569,13 @@ int em28xx_audio_setup(struct em28xx *dev) goto init_audio; vid = vid1 << 16 | vid2; - em28xx_warn("AC97 vendor ID = 0x%08x\n", vid); + dev_warn(&dev->intf->dev, "AC97 vendor ID = 0x%08x\n", vid); feat = em28xx_read_ac97(dev, AC97_RESET); if (feat < 0) goto init_audio; - em28xx_warn("AC97 features = 0x%04x\n", feat); + dev_warn(&dev->intf->dev, "AC97 features = 0x%04x\n", feat); /* Try to identify what audio processor we have */ if (((vid == 0xffffffff) || (vid == 0x83847650)) && (feat == 0x6a90)) @@ -589,17 +587,20 @@ init_audio: /* Reports detected AC97 processor */ switch (dev->audio_mode.ac97) { case EM28XX_NO_AC97: - em28xx_info("No AC97 audio processor\n"); + dev_info(&dev->intf->dev, "No AC97 audio processor\n"); break; case EM28XX_AC97_EM202: - em28xx_info("Empia 202 AC97 audio processor detected\n"); + dev_info(&dev->intf->dev, + "Empia 202 AC97 audio processor detected\n"); break; case EM28XX_AC97_SIGMATEL: - em28xx_info("Sigmatel audio processor detected (stac 97%02x)\n", - vid & 0xff); + dev_info(&dev->intf->dev, + "Sigmatel audio processor detected (stac 97%02x)\n", + vid & 0xff); break; case EM28XX_AC97_OTHER: - em28xx_warn("Unknown AC97 audio processor detected!\n"); + dev_warn(&dev->intf->dev, + "Unknown AC97 audio processor detected!\n"); break; default: break; @@ -798,6 +799,7 @@ void em28xx_uninit_usb_xfer(struct em28xx *dev, enum em28xx_mode mode) { struct urb *urb; struct em28xx_usb_bufs *usb_bufs; + struct usb_device *udev = interface_to_usbdev(dev->intf); int i; em28xx_isocdbg("em28xx: called em28xx_uninit_usb_xfer in mode %d\n", @@ -817,7 +819,7 @@ void em28xx_uninit_usb_xfer(struct em28xx *dev, enum em28xx_mode mode) usb_unlink_urb(urb); if (usb_bufs->transfer_buffer[i]) { - usb_free_coherent(dev->udev, + usb_free_coherent(udev, urb->transfer_buffer_length, usb_bufs->transfer_buffer[i], urb->transfer_dma); @@ -871,9 +873,10 @@ int em28xx_alloc_urbs(struct em28xx *dev, enum em28xx_mode mode, int xfer_bulk, int num_bufs, int max_pkt_size, int packet_multiplier) { struct em28xx_usb_bufs *usb_bufs; + struct urb *urb; + struct usb_device *udev = interface_to_usbdev(dev->intf); int i; int sb_size, pipe; - struct urb *urb; int j, k; em28xx_isocdbg("em28xx: called em28xx_alloc_isoc in mode %d\n", mode); @@ -883,21 +886,23 @@ int em28xx_alloc_urbs(struct em28xx *dev, enum em28xx_mode mode, int xfer_bulk, if (mode == EM28XX_DIGITAL_MODE) { if ((xfer_bulk && !dev->dvb_ep_bulk) || (!xfer_bulk && !dev->dvb_ep_isoc)) { - em28xx_errdev("no endpoint for DVB mode and transfer type %d\n", - xfer_bulk > 0); + dev_err(&dev->intf->dev, + "no endpoint for DVB mode and transfer type %d\n", + xfer_bulk > 0); return -EINVAL; } usb_bufs = &dev->usb_ctl.digital_bufs; } else if (mode == EM28XX_ANALOG_MODE) { if ((xfer_bulk && !dev->analog_ep_bulk) || (!xfer_bulk && !dev->analog_ep_isoc)) { - em28xx_errdev("no endpoint for analog mode and transfer type %d\n", - xfer_bulk > 0); + dev_err(&dev->intf->dev, + "no endpoint for analog mode and transfer type %d\n", + xfer_bulk > 0); return -EINVAL; } usb_bufs = &dev->usb_ctl.analog_bufs; } else { - em28xx_errdev("invalid mode selected\n"); + dev_err(&dev->intf->dev, "invalid mode selected\n"); return -EINVAL; } @@ -907,15 +912,12 @@ int em28xx_alloc_urbs(struct em28xx *dev, enum em28xx_mode mode, int xfer_bulk, usb_bufs->num_bufs = num_bufs; usb_bufs->urb = kzalloc(sizeof(void *)*num_bufs, GFP_KERNEL); - if (!usb_bufs->urb) { - em28xx_errdev("cannot alloc memory for usb buffers\n"); + if (!usb_bufs->urb) return -ENOMEM; - } usb_bufs->transfer_buffer = kzalloc(sizeof(void *)*num_bufs, GFP_KERNEL); if (!usb_bufs->transfer_buffer) { - em28xx_errdev("cannot allocate memory for usb transfer\n"); kfree(usb_bufs->urb); return -ENOMEM; } @@ -939,33 +941,33 @@ int em28xx_alloc_urbs(struct em28xx *dev, enum em28xx_mode mode, int xfer_bulk, } usb_bufs->urb[i] = urb; - usb_bufs->transfer_buffer[i] = usb_alloc_coherent(dev->udev, + usb_bufs->transfer_buffer[i] = usb_alloc_coherent(udev, sb_size, GFP_KERNEL, &urb->transfer_dma); if (!usb_bufs->transfer_buffer[i]) { - em28xx_err("unable to allocate %i bytes for transfer" - " buffer %i%s\n", - sb_size, i, - in_interrupt() ? " while in int" : ""); + dev_err(&dev->intf->dev, + "unable to allocate %i bytes for transfer buffer %i%s\n", + sb_size, i, + in_interrupt() ? " while in int" : ""); em28xx_uninit_usb_xfer(dev, mode); return -ENOMEM; } memset(usb_bufs->transfer_buffer[i], 0, sb_size); if (xfer_bulk) { /* bulk */ - pipe = usb_rcvbulkpipe(dev->udev, + pipe = usb_rcvbulkpipe(udev, mode == EM28XX_ANALOG_MODE ? dev->analog_ep_bulk : dev->dvb_ep_bulk); - usb_fill_bulk_urb(urb, dev->udev, pipe, + usb_fill_bulk_urb(urb, udev, pipe, usb_bufs->transfer_buffer[i], sb_size, em28xx_irq_callback, dev); urb->transfer_flags = URB_NO_TRANSFER_DMA_MAP; } else { /* isoc */ - pipe = usb_rcvisocpipe(dev->udev, + pipe = usb_rcvisocpipe(udev, mode == EM28XX_ANALOG_MODE ? dev->analog_ep_isoc : dev->dvb_ep_isoc); - usb_fill_int_urb(urb, dev->udev, pipe, + usb_fill_int_urb(urb, udev, pipe, usb_bufs->transfer_buffer[i], sb_size, em28xx_irq_callback, dev, 1); urb->transfer_flags = URB_ISO_ASAP | @@ -997,6 +999,7 @@ int em28xx_init_usb_xfer(struct em28xx *dev, enum em28xx_mode mode, struct em28xx_dmaqueue *dma_q = &dev->vidq; struct em28xx_dmaqueue *vbi_dma_q = &dev->vbiq; struct em28xx_usb_bufs *usb_bufs; + struct usb_device *udev = interface_to_usbdev(dev->intf); int i; int rc; int alloc; @@ -1023,10 +1026,11 @@ int em28xx_init_usb_xfer(struct em28xx *dev, enum em28xx_mode mode, } if (xfer_bulk) { - rc = usb_clear_halt(dev->udev, usb_bufs->urb[0]->pipe); + rc = usb_clear_halt(udev, usb_bufs->urb[0]->pipe); if (rc < 0) { - em28xx_err("failed to clear USB bulk endpoint stall/halt condition (error=%i)\n", - rc); + dev_err(&dev->intf->dev, + "failed to clear USB bulk endpoint stall/halt condition (error=%i)\n", + rc); em28xx_uninit_usb_xfer(dev, mode); return rc; } @@ -1041,8 +1045,8 @@ int em28xx_init_usb_xfer(struct em28xx *dev, enum em28xx_mode mode, for (i = 0; i < usb_bufs->num_bufs; i++) { rc = usb_submit_urb(usb_bufs->urb[i], GFP_ATOMIC); if (rc) { - em28xx_err("submit of urb %i failed (error=%i)\n", i, - rc); + dev_err(&dev->intf->dev, + "submit of urb %i failed (error=%i)\n", i, rc); em28xx_uninit_usb_xfer(dev, mode); return rc; } @@ -1075,7 +1079,7 @@ int em28xx_register_extension(struct em28xx_ops *ops) ops->init(dev); } mutex_unlock(&em28xx_devlist_mutex); - printk(KERN_INFO "em28xx: Registered (%s) extension\n", ops->name); + pr_info("em28xx: Registered (%s) extension\n", ops->name); return 0; } EXPORT_SYMBOL(em28xx_register_extension); @@ -1090,7 +1094,7 @@ void em28xx_unregister_extension(struct em28xx_ops *ops) } list_del(&ops->next); mutex_unlock(&em28xx_devlist_mutex); - printk(KERN_INFO "Em28xx: Removed (%s) extension\n", ops->name); + pr_info("em28xx: Removed (%s) extension\n", ops->name); } EXPORT_SYMBOL(em28xx_unregister_extension); @@ -1124,7 +1128,7 @@ int em28xx_suspend_extension(struct em28xx *dev) { const struct em28xx_ops *ops = NULL; - em28xx_info("Suspending extensions\n"); + dev_info(&dev->intf->dev, "Suspending extensions\n"); mutex_lock(&em28xx_devlist_mutex); list_for_each_entry(ops, &em28xx_extension_devlist, next) { if (ops->suspend) @@ -1138,7 +1142,7 @@ int em28xx_resume_extension(struct em28xx *dev) { const struct em28xx_ops *ops = NULL; - em28xx_info("Resuming extensions\n"); + dev_info(&dev->intf->dev, "Resuming extensions\n"); mutex_lock(&em28xx_devlist_mutex); list_for_each_entry(ops, &em28xx_extension_devlist, next) { if (ops->resume) |