diff options
Diffstat (limited to 'drivers/media/video/cx231xx/cx231xx-core.c')
-rw-r--r-- | drivers/media/video/cx231xx/cx231xx-core.c | 1126 |
1 files changed, 585 insertions, 541 deletions
diff --git a/drivers/media/video/cx231xx/cx231xx-core.c b/drivers/media/video/cx231xx/cx231xx-core.c index efe0c666043a..874fc5b39863 100644 --- a/drivers/media/video/cx231xx/cx231xx-core.c +++ b/drivers/media/video/cx231xx/cx231xx-core.c @@ -2,7 +2,7 @@ cx231xx-core.c - driver for Conexant Cx23100/101/102 USB video capture devices Copyright (C) 2008 <srinivasa.deevi at conexant dot com> - Based on em28xx driver + Based on em28xx driver 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 @@ -32,8 +32,8 @@ /* #define ENABLE_DEBUG_ISOC_FRAMES */ static unsigned int core_debug; -module_param(core_debug,int,0644); -MODULE_PARM_DESC(core_debug,"enable debug messages [core]"); +module_param(core_debug, int, 0644); +MODULE_PARM_DESC(core_debug, "enable debug messages [core]"); #define cx231xx_coredbg(fmt, arg...) do {\ if (core_debug) \ @@ -41,8 +41,8 @@ MODULE_PARM_DESC(core_debug,"enable debug messages [core]"); dev->name, __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]"); +module_param(reg_debug, int, 0644); +MODULE_PARM_DESC(reg_debug, "enable debug messages [URB reg]"); #define cx231xx_regdbg(fmt, arg...) do {\ if (reg_debug) \ @@ -59,8 +59,6 @@ MODULE_PARM_DESC(alt, "alternate setting to use for video endpoint"); printk(KERN_INFO "%s %s :"fmt, \ dev->name, __func__ , ##arg); } while (0) - - /************************************************************************************ * Device control list functions * *************************************************************************************/ @@ -69,8 +67,7 @@ static LIST_HEAD(cx231xx_devlist); static DEFINE_MUTEX(cx231xx_devlist_mutex); struct cx231xx *cx231xx_get_device(int minor, - enum v4l2_buf_type *fh_type, - int *has_radio) + enum v4l2_buf_type *fh_type, int *has_radio) { struct cx231xx *h, *dev = NULL; @@ -85,8 +82,7 @@ struct cx231xx *cx231xx_get_device(int minor, dev = h; *fh_type = V4L2_BUF_TYPE_VBI_CAPTURE; } - if (h->radio_dev && - h->radio_dev->minor == minor) { + if (h->radio_dev && h->radio_dev->minor == minor) { dev = h; *has_radio = 1; } @@ -115,9 +111,6 @@ void cx231xx_add_into_devlist(struct cx231xx *dev) mutex_unlock(&cx231xx_devlist_mutex); }; - - - static LIST_HEAD(cx231xx_extension_devlist); static DEFINE_MUTEX(cx231xx_extension_devlist_lock); @@ -137,6 +130,7 @@ int cx231xx_register_extension(struct cx231xx_ops *ops) mutex_unlock(&cx231xx_devlist_mutex); return 0; } + EXPORT_SYMBOL(cx231xx_register_extension); void cx231xx_unregister_extension(struct cx231xx_ops *ops) @@ -155,8 +149,8 @@ void cx231xx_unregister_extension(struct cx231xx_ops *ops) mutex_unlock(&cx231xx_extension_devlist_lock); mutex_unlock(&cx231xx_devlist_mutex); } -EXPORT_SYMBOL(cx231xx_unregister_extension); +EXPORT_SYMBOL(cx231xx_unregister_extension); void cx231xx_init_extension(struct cx231xx *dev) { @@ -190,78 +184,82 @@ void cx231xx_close_extension(struct cx231xx *dev) * U S B related functions * *************************************************************************************/ int cx231xx_send_usb_command(struct cx231xx_i2c *i2c_bus, - struct cx231xx_i2c_xfer_data *req_data) + struct cx231xx_i2c_xfer_data *req_data) { - int status = 0; - struct cx231xx *dev = i2c_bus->dev; - VENDOR_REQUEST_IN ven_req; - - u8 saddr_len = 0; - u8 _i2c_period = 0; - u8 _i2c_nostop = 0; - u8 _i2c_reserve = 0; - - /* Get the I2C period, nostop and reserve parameters */ - _i2c_period = i2c_bus->i2c_period; - _i2c_nostop = i2c_bus->i2c_nostop; - _i2c_reserve = i2c_bus->i2c_reserve; - - saddr_len = req_data->saddr_len; - - /* Set wValue */ - if(saddr_len == 1) /* need check saddr_len == 0 */ - ven_req.wValue = req_data->dev_addr<<9|_i2c_period<<4|saddr_len<<2| - _i2c_nostop<<1|I2C_SYNC|_i2c_reserve<<6; - else - ven_req.wValue = req_data->dev_addr<<9|_i2c_period<<4|saddr_len<<2| - _i2c_nostop<<1|I2C_SYNC|_i2c_reserve<<6; - - /* set channel number */ - if(req_data->direction & I2C_M_RD) - ven_req.bRequest = i2c_bus->nr + 4; /* channel number, for read, - spec required channel_num +4 */ - else - ven_req.bRequest = i2c_bus->nr; /* channel number, */ - - /* set index value */ - switch(saddr_len){ - case 0: - ven_req.wIndex = 0; /* need check */ - break; - case 1: - ven_req.wIndex = (req_data->saddr_dat & 0xff); - break; - case 2: - ven_req.wIndex = req_data->saddr_dat; - break; - } - - /* set wLength value */ - ven_req.wLength = req_data->buf_size; - - /* set bData value */ - ven_req.bData = 0; - - /* set the direction */ - if(req_data->direction){ - ven_req.direction = USB_DIR_IN; - memset(req_data->p_buffer, 0x00, ven_req.wLength); - } - else - ven_req.direction = USB_DIR_OUT; - - /* set the buffer for read / write */ - ven_req.pBuff = req_data->p_buffer; - - - - /* call common vendor command request */ - status = cx231xx_send_vendor_cmd(dev, &ven_req); - if (status < 0) { - cx231xx_info("UsbInterface::sendCommand, output buffer failed with status -%d\n", status); - } - - return status; + int status = 0; + struct cx231xx *dev = i2c_bus->dev; + VENDOR_REQUEST_IN ven_req; + + u8 saddr_len = 0; + u8 _i2c_period = 0; + u8 _i2c_nostop = 0; + u8 _i2c_reserve = 0; + + /* Get the I2C period, nostop and reserve parameters */ + _i2c_period = i2c_bus->i2c_period; + _i2c_nostop = i2c_bus->i2c_nostop; + _i2c_reserve = i2c_bus->i2c_reserve; + + saddr_len = req_data->saddr_len; + + /* Set wValue */ + if (saddr_len == 1) /* need check saddr_len == 0 */ + ven_req.wValue = + req_data-> + dev_addr << 9 | _i2c_period << 4 | saddr_len << 2 | + _i2c_nostop << 1 | I2C_SYNC | _i2c_reserve << 6; + else + ven_req.wValue = + req_data-> + dev_addr << 9 | _i2c_period << 4 | saddr_len << 2 | + _i2c_nostop << 1 | I2C_SYNC | _i2c_reserve << 6; + + /* set channel number */ + if (req_data->direction & I2C_M_RD) + ven_req.bRequest = i2c_bus->nr + 4; /* channel number, for read, + spec required channel_num +4 */ + else + ven_req.bRequest = i2c_bus->nr; /* channel number, */ + + /* set index value */ + switch (saddr_len) { + case 0: + ven_req.wIndex = 0; /* need check */ + break; + case 1: + ven_req.wIndex = (req_data->saddr_dat & 0xff); + break; + case 2: + ven_req.wIndex = req_data->saddr_dat; + break; + } + + /* set wLength value */ + ven_req.wLength = req_data->buf_size; + + /* set bData value */ + ven_req.bData = 0; + + /* set the direction */ + if (req_data->direction) { + ven_req.direction = USB_DIR_IN; + memset(req_data->p_buffer, 0x00, ven_req.wLength); + } else + ven_req.direction = USB_DIR_OUT; + + /* set the buffer for read / write */ + ven_req.pBuff = req_data->p_buffer; + + + /* call common vendor command request */ + status = cx231xx_send_vendor_cmd(dev, &ven_req); + if (status < 0) { + cx231xx_info + ("UsbInterface::sendCommand, output buffer failed with status -%d\n", + status); + } + + return status; } EXPORT_SYMBOL_GPL(cx231xx_send_usb_command); @@ -270,9 +268,9 @@ EXPORT_SYMBOL_GPL(cx231xx_send_usb_command); * reads data from the usb device specifying bRequest and wValue */ int cx231xx_read_ctrl_reg(struct cx231xx *dev, u8 req, u16 reg, - char *buf, int len) + char *buf, int len) { - u8 val = 0; + u8 val = 0; int ret; int pipe = usb_rcvctrlpipe(dev->udev, 0); @@ -282,35 +280,33 @@ int cx231xx_read_ctrl_reg(struct cx231xx *dev, u8 req, u16 reg, if (len > URB_MAX_CTRL_SIZE) return -EINVAL; - switch(len) - { - case 1: - val = ENABLE_ONE_BYTE; - break; - case 2: - val = ENABLE_TWE_BYTE; - break; - case 3: - val = ENABLE_THREE_BYTE; - break; - case 4: - val = ENABLE_FOUR_BYTE; - break; - default: - val = 0xFF; /* invalid option */ - } - - if(val == 0xFF) - return -EINVAL; + switch (len) { + case 1: + val = ENABLE_ONE_BYTE; + break; + case 2: + val = ENABLE_TWE_BYTE; + break; + case 3: + val = ENABLE_THREE_BYTE; + break; + case 4: + val = ENABLE_FOUR_BYTE; + break; + default: + val = 0xFF; /* invalid option */ + } + + if (val == 0xFF) + return -EINVAL; if (reg_debug) { cx231xx_isocdbg("(pipe 0x%08x): " - "IN: %02x %02x %02x %02x %02x %02x %02x %02x ", - pipe, - USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE, - req, 0, val, - reg & 0xff, reg >> 8, - len & 0xff, len >> 8); + "IN: %02x %02x %02x %02x %02x %02x %02x %02x ", + pipe, + USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE, + req, 0, val, + reg & 0xff, reg >> 8, len & 0xff, len >> 8); } /* mutex_lock(&dev->ctrl_urb_lock); */ @@ -340,10 +336,9 @@ int cx231xx_read_ctrl_reg(struct cx231xx *dev, u8 req, u16 reg, return ret; } - -int cx231xx_send_vendor_cmd(struct cx231xx *dev, VENDOR_REQUEST_IN *ven_req) +int cx231xx_send_vendor_cmd(struct cx231xx *dev, VENDOR_REQUEST_IN * ven_req) { - int ret; + int ret; int pipe = 0; if (dev->state & DEV_DISCONNECTED) @@ -352,32 +347,34 @@ int cx231xx_send_vendor_cmd(struct cx231xx *dev, VENDOR_REQUEST_IN *ven_req) if ((ven_req->wLength > URB_MAX_CTRL_SIZE)) return -EINVAL; - if(ven_req->direction) - pipe = usb_rcvctrlpipe(dev->udev, 0); - else - pipe = usb_sndctrlpipe(dev->udev, 0); - + if (ven_req->direction) + pipe = usb_rcvctrlpipe(dev->udev, 0); + else + pipe = usb_sndctrlpipe(dev->udev, 0); if (reg_debug) { int byte; cx231xx_isocdbg("(pipe 0x%08x): " - "OUT: %02x %02x %02x %04x %04x %04x >>>", - pipe, - ven_req->direction | USB_TYPE_VENDOR | USB_RECIP_DEVICE, - ven_req->bRequest, 0, ven_req->wValue, - ven_req->wIndex, - ven_req->wLength); + "OUT: %02x %02x %02x %04x %04x %04x >>>", + pipe, + ven_req-> + direction | USB_TYPE_VENDOR | USB_RECIP_DEVICE, + ven_req->bRequest, 0, ven_req->wValue, + ven_req->wIndex, ven_req->wLength); for (byte = 0; byte < ven_req->wLength; byte++) - cx231xx_isocdbg(" %02x", (unsigned char)ven_req->pBuff[byte]); + cx231xx_isocdbg(" %02x", + (unsigned char)ven_req->pBuff[byte]); cx231xx_isocdbg("\n"); } /* mutex_lock(&dev->ctrl_urb_lock); */ ret = usb_control_msg(dev->udev, pipe, ven_req->bRequest, - ven_req->direction | USB_TYPE_VENDOR | USB_RECIP_DEVICE, - ven_req->wValue, ven_req->wIndex, ven_req->pBuff, ven_req->wLength, HZ); + ven_req-> + direction | USB_TYPE_VENDOR | USB_RECIP_DEVICE, + ven_req->wValue, ven_req->wIndex, ven_req->pBuff, + ven_req->wLength, HZ); /* mutex_unlock(&dev->ctrl_urb_lock); */ return ret; @@ -388,9 +385,9 @@ int cx231xx_send_vendor_cmd(struct cx231xx *dev, VENDOR_REQUEST_IN *ven_req) * sends data to the usb device, specifying bRequest */ int cx231xx_write_ctrl_reg(struct cx231xx *dev, u8 req, u16 reg, char *buf, - int len) + int len) { - u8 val = 0; + u8 val = 0; int ret; int pipe = usb_sndctrlpipe(dev->udev, 0); @@ -400,37 +397,35 @@ int cx231xx_write_ctrl_reg(struct cx231xx *dev, u8 req, u16 reg, char *buf, if ((len < 1) || (len > URB_MAX_CTRL_SIZE)) return -EINVAL; - switch(len) - { - case 1: - val = ENABLE_ONE_BYTE; - break; - case 2: - val = ENABLE_TWE_BYTE; - break; - case 3: - val = ENABLE_THREE_BYTE; - break; - case 4: - val = ENABLE_FOUR_BYTE; - break; - default: - val = 0xFF; /* invalid option */ - } - - if(val == 0xFF) - return -EINVAL; + switch (len) { + case 1: + val = ENABLE_ONE_BYTE; + break; + case 2: + val = ENABLE_TWE_BYTE; + break; + case 3: + val = ENABLE_THREE_BYTE; + break; + case 4: + val = ENABLE_FOUR_BYTE; + break; + default: + val = 0xFF; /* invalid option */ + } + + if (val == 0xFF) + return -EINVAL; if (reg_debug) { int byte; cx231xx_isocdbg("(pipe 0x%08x): " - "OUT: %02x %02x %02x %02x %02x %02x %02x %02x >>>", - pipe, - USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE, - req, 0, val, - reg & 0xff, reg >> 8, - len & 0xff, len >> 8); + "OUT: %02x %02x %02x %02x %02x %02x %02x %02x >>>", + pipe, + USB_DIR_OUT | USB_TYPE_VENDOR | + USB_RECIP_DEVICE, req, 0, val, reg & 0xff, + reg >> 8, len & 0xff, len >> 8); for (byte = 0; byte < len; byte++) cx231xx_isocdbg(" %02x", (unsigned char)buf[byte]); @@ -447,7 +442,6 @@ int cx231xx_write_ctrl_reg(struct cx231xx *dev, u8 req, u16 reg, char *buf, return ret; } - /************************************************************************************ * USB Alternate Setting functions * *************************************************************************************/ @@ -456,7 +450,7 @@ int cx231xx_set_video_alternate(struct cx231xx *dev) { int errCode, prev_alt = dev->video_mode.alt; unsigned int min_pkt_size = dev->width * 2 + 4; - u32 usb_interface_index = 0; + u32 usb_interface_index = 0; /* When image size is bigger than a certain value, the frame size should be increased, otherwise, only @@ -465,35 +459,44 @@ int cx231xx_set_video_alternate(struct cx231xx *dev) if (dev->width * 2 * dev->height > 720 * 240 * 2) min_pkt_size *= 2; - if(dev->width > 360) { - /* resolutions: 720,704,640 */ - dev->video_mode.alt = 3; - } else if(dev->width > 180) { - /* resolutions: 360,352,320,240 */ - dev->video_mode.alt = 2; - } else if(dev->width > 0) { - /* resolutions: 180,176,160,128,88 */ - dev->video_mode.alt = 1; - } else { - /* Change to alt0 BULK to release USB bandwidth */ - dev->video_mode.alt = 0; - } - - /* Get the correct video interface Index */ - usb_interface_index = dev->current_pcb_config.hs_config_info[0].interface_info.video_index+1; + if (dev->width > 360) { + /* resolutions: 720,704,640 */ + dev->video_mode.alt = 3; + } else if (dev->width > 180) { + /* resolutions: 360,352,320,240 */ + dev->video_mode.alt = 2; + } else if (dev->width > 0) { + /* resolutions: 180,176,160,128,88 */ + dev->video_mode.alt = 1; + } else { + /* Change to alt0 BULK to release USB bandwidth */ + dev->video_mode.alt = 0; + } + + /* Get the correct video interface Index */ + usb_interface_index = + dev->current_pcb_config.hs_config_info[0].interface_info. + video_index + 1; if (dev->video_mode.alt != prev_alt) { cx231xx_coredbg("minimum isoc packet size: %u (alt=%d)\n", min_pkt_size, dev->video_mode.alt); - dev->video_mode.max_pkt_size = dev->video_mode.alt_max_pkt_size[dev->video_mode.alt]; + dev->video_mode.max_pkt_size = + dev->video_mode.alt_max_pkt_size[dev->video_mode.alt]; cx231xx_coredbg("setting alternate %d with wMaxPacketSize=%u\n", - dev->video_mode.alt, dev->video_mode.max_pkt_size); - cx231xx_info(" setting alternate %d with wMaxPacketSize=%u , Interface = %d\n", - dev->video_mode.alt, dev->video_mode.max_pkt_size, usb_interface_index); - errCode = usb_set_interface(dev->udev, usb_interface_index, dev->video_mode.alt); + dev->video_mode.alt, + dev->video_mode.max_pkt_size); + cx231xx_info + (" setting alternate %d with wMaxPacketSize=%u , Interface = %d\n", + dev->video_mode.alt, dev->video_mode.max_pkt_size, + usb_interface_index); + errCode = + usb_set_interface(dev->udev, usb_interface_index, + dev->video_mode.alt); if (errCode < 0) { - cx231xx_errdev("cannot change alternate number to %d (error=%i)\n", - dev->video_mode.alt, errCode); + cx231xx_errdev + ("cannot change alternate number to %d (error=%i)\n", + dev->video_mode.alt, errCode); return errCode; } } @@ -502,68 +505,92 @@ int cx231xx_set_video_alternate(struct cx231xx *dev) int cx231xx_set_alt_setting(struct cx231xx *dev, u8 index, u8 alt) { - int status = 0; - u32 usb_interface_index = 0; - u32 max_pkt_size = 0; - - switch(index) { - case INDEX_TS1: - usb_interface_index = dev->current_pcb_config.hs_config_info[0].interface_info.ts1_index+1; - dev->video_mode.alt = alt; - if(dev->ts1_mode.alt_max_pkt_size != NULL) - max_pkt_size = dev->ts1_mode.max_pkt_size = dev->ts1_mode.alt_max_pkt_size[dev->ts1_mode.alt]; - break; - case INDEX_TS2: - usb_interface_index = dev->current_pcb_config.hs_config_info[0].interface_info.ts2_index+1; - break; - case INDEX_AUDIO: - usb_interface_index = dev->current_pcb_config.hs_config_info[0].interface_info.audio_index+1; - dev->adev.alt = alt; - if( dev->adev.alt_max_pkt_size != NULL) - max_pkt_size = dev->adev.max_pkt_size = dev->adev.alt_max_pkt_size[dev->adev.alt]; - break; - case INDEX_VIDEO: - usb_interface_index = dev->current_pcb_config.hs_config_info[0].interface_info.video_index+1; - dev->video_mode.alt = alt; - if(dev->video_mode.alt_max_pkt_size != NULL) - max_pkt_size = dev->video_mode.max_pkt_size = dev->video_mode.alt_max_pkt_size[dev->video_mode.alt]; - break; - case INDEX_VANC: - usb_interface_index = dev->current_pcb_config.hs_config_info[0].interface_info.vanc_index+1; - dev->vbi_mode.alt = alt; - if(dev->vbi_mode.alt_max_pkt_size != NULL) - max_pkt_size = dev->vbi_mode.max_pkt_size = dev->vbi_mode.alt_max_pkt_size[dev->vbi_mode.alt]; - break; - case INDEX_HANC: - usb_interface_index = dev->current_pcb_config.hs_config_info[0].interface_info.hanc_index+1; - dev->sliced_cc_mode.alt = alt; - if(dev->sliced_cc_mode.alt_max_pkt_size != NULL) - max_pkt_size = dev->sliced_cc_mode.max_pkt_size = dev->sliced_cc_mode.alt_max_pkt_size[dev->sliced_cc_mode.alt]; - break; - default: - break; - } - - if(alt > 0 && max_pkt_size == 0 ) { - cx231xx_errdev("cannot change interface %d alternate number to %d : Max. Pkt size is ZERO\n", - usb_interface_index, alt); - return -1; - } - - cx231xx_info(" setting alternate %d with wMaxPacketSize=%u , Interface = %d\n", - alt, max_pkt_size, usb_interface_index); - - if(usb_interface_index > 0 ) { - status = usb_set_interface(dev->udev, usb_interface_index, alt); + int status = 0; + u32 usb_interface_index = 0; + u32 max_pkt_size = 0; + + switch (index) { + case INDEX_TS1: + usb_interface_index = + dev->current_pcb_config.hs_config_info[0].interface_info. + ts1_index + 1; + dev->video_mode.alt = alt; + if (dev->ts1_mode.alt_max_pkt_size != NULL) + max_pkt_size = dev->ts1_mode.max_pkt_size = + dev->ts1_mode.alt_max_pkt_size[dev->ts1_mode.alt]; + break; + case INDEX_TS2: + usb_interface_index = + dev->current_pcb_config.hs_config_info[0].interface_info. + ts2_index + 1; + break; + case INDEX_AUDIO: + usb_interface_index = + dev->current_pcb_config.hs_config_info[0].interface_info. + audio_index + 1; + dev->adev.alt = alt; + if (dev->adev.alt_max_pkt_size != NULL) + max_pkt_size = dev->adev.max_pkt_size = + dev->adev.alt_max_pkt_size[dev->adev.alt]; + break; + case INDEX_VIDEO: + usb_interface_index = + dev->current_pcb_config.hs_config_info[0].interface_info. + video_index + 1; + dev->video_mode.alt = alt; + if (dev->video_mode.alt_max_pkt_size != NULL) + max_pkt_size = dev->video_mode.max_pkt_size = + dev->video_mode.alt_max_pkt_size[dev->video_mode. + alt]; + break; + case INDEX_VANC: + usb_interface_index = + dev->current_pcb_config.hs_config_info[0].interface_info. + vanc_index + 1; + dev->vbi_mode.alt = alt; + if (dev->vbi_mode.alt_max_pkt_size != NULL) + max_pkt_size = dev->vbi_mode.max_pkt_size = + dev->vbi_mode.alt_max_pkt_size[dev->vbi_mode.alt]; + break; + case INDEX_HANC: + usb_interface_index = + dev->current_pcb_config.hs_config_info[0].interface_info. + hanc_index + 1; + dev->sliced_cc_mode.alt = alt; + if (dev->sliced_cc_mode.alt_max_pkt_size != NULL) + max_pkt_size = dev->sliced_cc_mode.max_pkt_size = + dev->sliced_cc_mode.alt_max_pkt_size[dev-> + sliced_cc_mode. + alt]; + break; + default: + break; + } + + if (alt > 0 && max_pkt_size == 0) { + cx231xx_errdev + ("cannot change interface %d alternate number to %d : Max. Pkt size is ZERO\n", + usb_interface_index, alt); + return -1; + } + + cx231xx_info + (" setting alternate %d with wMaxPacketSize=%u , Interface = %d\n", + alt, max_pkt_size, usb_interface_index); + + if (usb_interface_index > 0) { + status = usb_set_interface(dev->udev, usb_interface_index, alt); if (status < 0) { - cx231xx_errdev("cannot change interface %d alternate number to %d (error=%i)\n", - usb_interface_index, alt, status); + cx231xx_errdev + ("cannot change interface %d alternate number to %d (error=%i)\n", + usb_interface_index, alt, status); return status; } - } + } - return status; + return status; } + EXPORT_SYMBOL_GPL(cx231xx_set_alt_setting); int cx231xx_gpio_set(struct cx231xx *dev, struct cx231xx_reg_seq *gpio) @@ -575,10 +602,9 @@ int cx231xx_gpio_set(struct cx231xx *dev, struct cx231xx_reg_seq *gpio) /* Send GPIO reset sequences specified at board entry */ while (gpio->sleep >= 0) { - rc = cx231xx_set_gpio_value(dev, gpio->bit, - gpio->val); - if (rc < 0) - return rc; + rc = cx231xx_set_gpio_value(dev, gpio->bit, gpio->val); + if (rc < 0) + return rc; if (gpio->sleep > 0) msleep(gpio->sleep); @@ -594,7 +620,7 @@ int cx231xx_set_mode(struct cx231xx *dev, enum cx231xx_mode set_mode) return 0; if (set_mode == CX231XX_SUSPEND) { - /* Set the chip in power saving mode */ + /* Set the chip in power saving mode */ dev->mode = set_mode; } @@ -604,13 +630,14 @@ int cx231xx_set_mode(struct cx231xx *dev, enum cx231xx_mode set_mode) dev->mode = set_mode; - if (dev->mode == CX231XX_DIGITAL_MODE) { - /* Set Digital power mode */ - } else { - /* Set Analog Power mode*/ - } - return 0; + if (dev->mode == CX231XX_DIGITAL_MODE) { + /* Set Digital power mode */ + } else { + /* Set Analog Power mode */ + } + return 0; } + EXPORT_SYMBOL_GPL(cx231xx_set_mode); /************************************************************************************ @@ -622,23 +649,23 @@ EXPORT_SYMBOL_GPL(cx231xx_set_mode); */ static void cx231xx_irq_callback(struct urb *urb) { - struct cx231xx_dmaqueue *dma_q = urb->context; - struct cx231xx_video_mode *vmode = container_of(dma_q, struct cx231xx_video_mode, vidq); - struct cx231xx *dev = container_of(vmode, struct cx231xx, video_mode); + struct cx231xx_dmaqueue *dma_q = urb->context; + struct cx231xx_video_mode *vmode = + container_of(dma_q, struct cx231xx_video_mode, vidq); + struct cx231xx *dev = container_of(vmode, struct cx231xx, video_mode); int rc, i; - - switch (urb->status) { - case 0: /* success */ - case -ETIMEDOUT: /* NAK */ - break; - case -ECONNRESET: /* kill */ - case -ENOENT: - case -ESHUTDOWN: - return; - default: /* error */ - cx231xx_isocdbg("urb completition error %d.\n", urb->status); - break; + switch (urb->status) { + case 0: /* success */ + case -ETIMEDOUT: /* NAK */ + break; + case -ECONNRESET: /* kill */ + case -ENOENT: + case -ESHUTDOWN: + return; + default: /* error */ + cx231xx_isocdbg("urb completition error %d.\n", urb->status); + break; } /* Copy data from URB */ @@ -656,7 +683,7 @@ static void cx231xx_irq_callback(struct urb *urb) urb->status = usb_submit_urb(urb, GFP_ATOMIC); if (urb->status) { cx231xx_isocdbg("urb resubmit failed (error=%i)\n", - urb->status); + urb->status); } } @@ -674,16 +701,17 @@ void cx231xx_uninit_isoc(struct cx231xx *dev) for (i = 0; i < dev->video_mode.isoc_ctl.num_bufs; i++) { urb = dev->video_mode.isoc_ctl.urb[i]; if (urb) { - if (!irqs_disabled()) - usb_kill_urb(urb); - else - usb_unlink_urb(urb); + if (!irqs_disabled()) + usb_kill_urb(urb); + else + usb_unlink_urb(urb); if (dev->video_mode.isoc_ctl.transfer_buffer[i]) { usb_buffer_free(dev->udev, - urb->transfer_buffer_length, - dev->video_mode.isoc_ctl.transfer_buffer[i], - urb->transfer_dma); + urb->transfer_buffer_length, + dev->video_mode.isoc_ctl. + transfer_buffer[i], + urb->transfer_dma); } usb_free_urb(urb); dev->video_mode.isoc_ctl.urb[i] = NULL; @@ -700,14 +728,15 @@ void cx231xx_uninit_isoc(struct cx231xx *dev) cx231xx_capture_start(dev, 0, Raw_Video); } + EXPORT_SYMBOL_GPL(cx231xx_uninit_isoc); /* * Allocate URBs and start IRQ */ int cx231xx_init_isoc(struct cx231xx *dev, int max_packets, - int num_bufs, int max_pkt_size, - int (*isoc_copy) (struct cx231xx *dev, struct urb *urb)) + int num_bufs, int max_pkt_size, + int (*isoc_copy) (struct cx231xx * dev, struct urb * urb)) { struct cx231xx_dmaqueue *dma_q = &dev->video_mode.vidq; int i; @@ -718,36 +747,36 @@ int cx231xx_init_isoc(struct cx231xx *dev, int max_packets, cx231xx_isocdbg("cx231xx: called cx231xx_prepare_isoc\n"); - dev->video_input = dev->video_input > 2?2:dev->video_input; - - cx231xx_info("Setting Video mux to %d\n",dev->video_input); - video_mux(dev, dev->video_input); + dev->video_input = dev->video_input > 2 ? 2 : dev->video_input; + cx231xx_info("Setting Video mux to %d\n", dev->video_input); + video_mux(dev, dev->video_input); /* De-allocates all pending stuff */ cx231xx_uninit_isoc(dev); dev->video_mode.isoc_ctl.isoc_copy = isoc_copy; dev->video_mode.isoc_ctl.num_bufs = num_bufs; - dma_q->pos = 0; - dma_q->is_partial_line = 0; - dma_q->last_sav = 0; - dma_q->current_field = -1; - dma_q->field1_done = 0; - dma_q->lines_per_field = dev->height/2; - dma_q->bytes_left_in_line = dev->width << 1; - dma_q->lines_completed = 0; - for(i = 0; i < 8 ; i++) - dma_q->partial_buf[i] = 0; - - dev->video_mode.isoc_ctl.urb = kzalloc(sizeof(void *)*num_bufs, GFP_KERNEL); + dma_q->pos = 0; + dma_q->is_partial_line = 0; + dma_q->last_sav = 0; + dma_q->current_field = -1; + dma_q->field1_done = 0; + dma_q->lines_per_field = dev->height / 2; + dma_q->bytes_left_in_line = dev->width << 1; + dma_q->lines_completed = 0; + for (i = 0; i < 8; i++) + dma_q->partial_buf[i] = 0; + + dev->video_mode.isoc_ctl.urb = + kzalloc(sizeof(void *) * num_bufs, GFP_KERNEL); if (!dev->video_mode.isoc_ctl.urb) { cx231xx_errdev("cannot alloc memory for usb buffers\n"); return -ENOMEM; } - dev->video_mode.isoc_ctl.transfer_buffer = kzalloc(sizeof(void *)*num_bufs, - GFP_KERNEL); + dev->video_mode.isoc_ctl.transfer_buffer = + kzalloc(sizeof(void *) * num_bufs, GFP_KERNEL); if (!dev->video_mode.isoc_ctl.transfer_buffer) { cx231xx_errdev("cannot allocate memory for usbtransfer\n"); kfree(dev->video_mode.isoc_ctl.urb); @@ -769,23 +798,25 @@ int cx231xx_init_isoc(struct cx231xx *dev, int max_packets, } dev->video_mode.isoc_ctl.urb[i] = urb; - dev->video_mode.isoc_ctl.transfer_buffer[i] = usb_buffer_alloc(dev->udev, - sb_size, GFP_KERNEL, &urb->transfer_dma); + dev->video_mode.isoc_ctl.transfer_buffer[i] = + usb_buffer_alloc(dev->udev, sb_size, GFP_KERNEL, + &urb->transfer_dma); if (!dev->video_mode.isoc_ctl.transfer_buffer[i]) { cx231xx_err("unable to allocate %i bytes for transfer" - " buffer %i%s\n", - sb_size, i, - in_interrupt()?" while in int":""); + " buffer %i%s\n", + sb_size, i, + in_interrupt()? " while in int" : ""); cx231xx_uninit_isoc(dev); return -ENOMEM; } memset(dev->video_mode.isoc_ctl.transfer_buffer[i], 0, sb_size); - pipe = usb_rcvisocpipe(dev->udev, dev->video_mode.end_point_addr); + pipe = + usb_rcvisocpipe(dev->udev, dev->video_mode.end_point_addr); usb_fill_int_urb(urb, dev->udev, pipe, - dev->video_mode.isoc_ctl.transfer_buffer[i], sb_size, - cx231xx_irq_callback, dma_q, 1); + dev->video_mode.isoc_ctl.transfer_buffer[i], + sb_size, cx231xx_irq_callback, dma_q, 1); urb->number_of_packets = max_packets; urb->transfer_flags = URB_ISO_ASAP; @@ -794,29 +825,30 @@ int cx231xx_init_isoc(struct cx231xx *dev, int max_packets, for (j = 0; j < max_packets; j++) { urb->iso_frame_desc[j].offset = k; urb->iso_frame_desc[j].length = - dev->video_mode.isoc_ctl.max_pkt_size; + dev->video_mode.isoc_ctl.max_pkt_size; k += dev->video_mode.isoc_ctl.max_pkt_size; } } init_waitqueue_head(&dma_q->wq); - /* submit urbs and enables IRQ */ for (i = 0; i < dev->video_mode.isoc_ctl.num_bufs; i++) { - rc = usb_submit_urb(dev->video_mode.isoc_ctl.urb[i], GFP_ATOMIC); + rc = usb_submit_urb(dev->video_mode.isoc_ctl.urb[i], + GFP_ATOMIC); if (rc) { cx231xx_err("submit of urb %i failed (error=%i)\n", i, - rc); + rc); cx231xx_uninit_isoc(dev); return rc; } } - cx231xx_capture_start(dev, 1, Raw_Video); + cx231xx_capture_start(dev, 1, Raw_Video); return 0; } + EXPORT_SYMBOL_GPL(cx231xx_init_isoc); /************************************************************************************ @@ -824,171 +856,176 @@ EXPORT_SYMBOL_GPL(cx231xx_init_isoc); *************************************************************************************/ int cx231xx_dev_init(struct cx231xx *dev) { - int errCode = 0; + int errCode = 0; - /* Initialize I2C bus */ + /* Initialize I2C bus */ /* External Master 1 Bus */ dev->i2c_bus[0].nr = 0; dev->i2c_bus[0].dev = dev; - dev->i2c_bus[0].i2c_period = I2C_SPEED_1M; /* 1MHz */ - dev->i2c_bus[0].i2c_nostop = 0; - dev->i2c_bus[0].i2c_reserve = 0; + dev->i2c_bus[0].i2c_period = I2C_SPEED_1M; /* 1MHz */ + dev->i2c_bus[0].i2c_nostop = 0; + dev->i2c_bus[0].i2c_reserve = 0; /* External Master 2 Bus */ dev->i2c_bus[1].nr = 1; dev->i2c_bus[1].dev = dev; - dev->i2c_bus[1].i2c_period = I2C_SPEED_1M; /* 1MHz */ - dev->i2c_bus[1].i2c_nostop = 0; - dev->i2c_bus[1].i2c_reserve = 0; + dev->i2c_bus[1].i2c_period = I2C_SPEED_1M; /* 1MHz */ + dev->i2c_bus[1].i2c_nostop = 0; + dev->i2c_bus[1].i2c_reserve = 0; /* Internal Master 3 Bus */ dev->i2c_bus[2].nr = 2; dev->i2c_bus[2].dev = dev; - dev->i2c_bus[2].i2c_period = I2C_SPEED_400K; /* 400kHz */ - dev->i2c_bus[2].i2c_nostop = 0; - dev->i2c_bus[2].i2c_reserve = 0; + dev->i2c_bus[2].i2c_period = I2C_SPEED_400K; /* 400kHz */ + dev->i2c_bus[2].i2c_nostop = 0; + dev->i2c_bus[2].i2c_reserve = 0; - /* register I2C buses */ + /* register I2C buses */ cx231xx_i2c_register(&dev->i2c_bus[0]); cx231xx_i2c_register(&dev->i2c_bus[1]); cx231xx_i2c_register(&dev->i2c_bus[2]); - /* init hardware */ - /* Note : with out calling set power mode function, colibri can not be set up correctly */ - errCode = cx231xx_set_power_mode(dev, POLARIS_AVMODE_ANALOGT_TV); - if (errCode < 0) { - cx231xx_errdev("%s: cx231xx_set_power_mode : Failed to set Power - errCode [%d]!\n", - __func__, errCode); + /* init hardware */ + /* Note : with out calling set power mode function, colibri can not be set up correctly */ + errCode = cx231xx_set_power_mode(dev, POLARIS_AVMODE_ANALOGT_TV); + if (errCode < 0) { + cx231xx_errdev + ("%s: cx231xx_set_power_mode : Failed to set Power - errCode [%d]!\n", + __func__, errCode); return errCode; } - /* initialize Colibri block */ - errCode = cx231xx_colibri_init_super_block(dev, 0x23c); + /* initialize Colibri block */ + errCode = cx231xx_colibri_init_super_block(dev, 0x23c); if (errCode < 0) { - cx231xx_errdev("%s: cx231xx_colibri init super block - errCode [%d]!\n", - __func__, errCode); + cx231xx_errdev + ("%s: cx231xx_colibri init super block - errCode [%d]!\n", + __func__, errCode); return errCode; } - errCode = cx231xx_colibri_init_channels(dev); - if (errCode < 0) { - cx231xx_errdev("%s: cx231xx_colibri init channels - errCode [%d]!\n", - __func__, errCode); + errCode = cx231xx_colibri_init_channels(dev); + if (errCode < 0) { + cx231xx_errdev + ("%s: cx231xx_colibri init channels - errCode [%d]!\n", + __func__, errCode); return errCode; } - /* Set DIF in By pass mode */ - errCode = cx231xx_dif_set_standard(dev, DIF_USE_BASEBAND); - if (errCode < 0) { - cx231xx_errdev("%s: cx231xx_dif set to By pass mode - errCode [%d]!\n", - __func__, errCode); + /* Set DIF in By pass mode */ + errCode = cx231xx_dif_set_standard(dev, DIF_USE_BASEBAND); + if (errCode < 0) { + cx231xx_errdev + ("%s: cx231xx_dif set to By pass mode - errCode [%d]!\n", + __func__, errCode); return errCode; } - /* flatiron related functions */ - errCode = cx231xx_flatiron_initialize(dev); - if (errCode < 0) { - cx231xx_errdev("%s: cx231xx_flatiron initialize - errCode [%d]!\n", - __func__, errCode); + /* flatiron related functions */ + errCode = cx231xx_flatiron_initialize(dev); + if (errCode < 0) { + cx231xx_errdev + ("%s: cx231xx_flatiron initialize - errCode [%d]!\n", + __func__, errCode); return errCode; } - /* init control pins */ - errCode = cx231xx_init_ctrl_pin_status(dev); - if (errCode < 0) { + /* init control pins */ + errCode = cx231xx_init_ctrl_pin_status(dev); + if (errCode < 0) { cx231xx_errdev("%s: cx231xx_init ctrl pins - errCode [%d]!\n", - __func__, errCode); + __func__, errCode); return errCode; } - /* set AGC mode to Analog */ - errCode = cx231xx_set_agc_analog_digital_mux_select(dev, 1); - if (errCode < 0) { - cx231xx_errdev("%s: cx231xx_AGC mode to Analog - errCode [%d]!\n", - __func__, errCode); + /* set AGC mode to Analog */ + errCode = cx231xx_set_agc_analog_digital_mux_select(dev, 1); + if (errCode < 0) { + cx231xx_errdev + ("%s: cx231xx_AGC mode to Analog - errCode [%d]!\n", + __func__, errCode); return errCode; } - /* set all alternate settings to zero initially */ - cx231xx_set_alt_setting(dev, INDEX_VIDEO, 0); - cx231xx_set_alt_setting(dev, INDEX_VANC, 0); - cx231xx_set_alt_setting(dev, INDEX_HANC, 0); - if(dev->board.has_dvb) - cx231xx_set_alt_setting(dev, INDEX_TS1, 0); + /* set all alternate settings to zero initially */ + cx231xx_set_alt_setting(dev, INDEX_VIDEO, 0); + cx231xx_set_alt_setting(dev, INDEX_VANC, 0); + cx231xx_set_alt_setting(dev, INDEX_HANC, 0); + if (dev->board.has_dvb) + cx231xx_set_alt_setting(dev, INDEX_TS1, 0); - /* set the I2C master port to 3 on channel 1 */ - errCode = cx231xx_enable_i2c_for_tuner(dev, I2C_3); + /* set the I2C master port to 3 on channel 1 */ + errCode = cx231xx_enable_i2c_for_tuner(dev, I2C_3); return errCode; } + EXPORT_SYMBOL_GPL(cx231xx_dev_init); void cx231xx_dev_uninit(struct cx231xx *dev) { - /* Un Initialize I2C bus */ + /* Un Initialize I2C bus */ cx231xx_i2c_unregister(&dev->i2c_bus[2]); cx231xx_i2c_unregister(&dev->i2c_bus[1]); cx231xx_i2c_unregister(&dev->i2c_bus[0]); } -EXPORT_SYMBOL_GPL(cx231xx_dev_uninit); +EXPORT_SYMBOL_GPL(cx231xx_dev_uninit); /************************************************************************************ * G P I O related functions * *************************************************************************************/ -int cx231xx_send_gpio_cmd(struct cx231xx *dev, u32 gpio_bit, u8* gpio_val, - u8 len, u8 request, u8 direction) +int cx231xx_send_gpio_cmd(struct cx231xx *dev, u32 gpio_bit, u8 * gpio_val, + u8 len, u8 request, u8 direction) { - int status = 0; - VENDOR_REQUEST_IN ven_req; - - /* Set wValue */ - ven_req.wValue = (u16)(gpio_bit>>16 & 0xffff); - - /* set request */ - if(!request){ - if(direction) - ven_req.bRequest = VRT_GET_GPIO; /* 0x8 gpio */ - else - ven_req.bRequest = VRT_SET_GPIO; /* 0x9 gpio */ - } - else { - if(direction) - ven_req.bRequest = VRT_GET_GPIE; /* 0xa gpie */ - else - ven_req.bRequest = VRT_SET_GPIE; /* 0xb gpie */ - } - - /* set index value */ - ven_req.wIndex = (u16)(gpio_bit & 0xffff); - - /* set wLength value */ - ven_req.wLength = len; - - /* set bData value */ - ven_req.bData = 0; - - /* set the buffer for read / write */ - ven_req.pBuff = gpio_val; + int status = 0; + VENDOR_REQUEST_IN ven_req; + + /* Set wValue */ + ven_req.wValue = (u16) (gpio_bit >> 16 & 0xffff); + + /* set request */ + if (!request) { + if (direction) + ven_req.bRequest = VRT_GET_GPIO; /* 0x8 gpio */ + else + ven_req.bRequest = VRT_SET_GPIO; /* 0x9 gpio */ + } else { + if (direction) + ven_req.bRequest = VRT_GET_GPIE; /* 0xa gpie */ + else + ven_req.bRequest = VRT_SET_GPIE; /* 0xb gpie */ + } - /* set the direction */ - if(direction){ - ven_req.direction = USB_DIR_IN; - memset(ven_req.pBuff, 0x00, ven_req.wLength); - } - else - ven_req.direction = USB_DIR_OUT; + /* set index value */ + ven_req.wIndex = (u16) (gpio_bit & 0xffff); + /* set wLength value */ + ven_req.wLength = len; + /* set bData value */ + ven_req.bData = 0; - /* call common vendor command request */ - status = cx231xx_send_vendor_cmd(dev, &ven_req); - if (status < 0) - { - cx231xx_info("UsbInterface::sendCommand, output buffer failed with status -%d\n", status); - } + /* set the buffer for read / write */ + ven_req.pBuff = gpio_val; + + /* set the direction */ + if (direction) { + ven_req.direction = USB_DIR_IN; + memset(ven_req.pBuff, 0x00, ven_req.wLength); + } else + ven_req.direction = USB_DIR_OUT; + + + /* call common vendor command request */ + status = cx231xx_send_vendor_cmd(dev, &ven_req); + if (status < 0) { + cx231xx_info + ("UsbInterface::sendCommand, output buffer failed with status -%d\n", + status); + } - return status; + return status; } EXPORT_SYMBOL_GPL(cx231xx_send_gpio_cmd); @@ -998,170 +1035,177 @@ EXPORT_SYMBOL_GPL(cx231xx_send_gpio_cmd); *************************************************************************************/ int cx231xx_mode_register(struct cx231xx *dev, u16 address, u32 mode) { - u8 value[4] = {0x0, 0x0, 0x0, 0x0}; - u32 tmp =0; - int status = 0; + u8 value[4] = { 0x0, 0x0, 0x0, 0x0 }; + u32 tmp = 0; + int status = 0; - status = cx231xx_read_ctrl_reg(dev,VRT_GET_REGISTER, address,value,4); - if(status < 0) - return status; + status = + cx231xx_read_ctrl_reg(dev, VRT_GET_REGISTER, address, value, 4); + if (status < 0) + return status; - tmp = *((u32 *)value); - tmp |= mode; + tmp = *((u32 *) value); + tmp |= mode; - value[0]=(u8) tmp; - value[1]=(u8)(tmp>>8); - value[2]=(u8)(tmp>>16); - value[3]=(u8)(tmp>>24); + value[0] = (u8) tmp; + value[1] = (u8) (tmp >> 8); + value[2] = (u8) (tmp >> 16); + value[3] = (u8) (tmp >> 24); - status = cx231xx_write_ctrl_reg(dev,VRT_SET_REGISTER, address,value,4); + status = + cx231xx_write_ctrl_reg(dev, VRT_SET_REGISTER, address, value, 4); - return status; + return status; } /************************************************************************************* * I 2 C Internal C O N T R O L functions * *************************************************************************************/ int cx231xx_read_i2c_data(struct cx231xx *dev, u8 dev_addr, u16 saddr, - u8 saddr_len, u32 *data, u8 data_len) + u8 saddr_len, u32 * data, u8 data_len) { - int status = 0; - struct cx231xx_i2c_xfer_data req_data; - u8 value[4] ={0,0,0,0}; - - if(saddr_len == 0) - saddr = 0; - else if(saddr_len == 0) - saddr &= 0xff; - - /* prepare xfer_data struct */ - req_data.dev_addr = dev_addr >> 1; - req_data.direction = I2C_M_RD; - req_data.saddr_len = saddr_len; - req_data.saddr_dat = saddr; - req_data.buf_size = data_len; - req_data.p_buffer = (u8*)value; - - /* usb send command */ - status = dev->cx231xx_send_usb_command(&dev->i2c_bus[0], &req_data); - - if(status >= 0) - { - /* Copy the data read back to main buffer */ - if(data_len == 1) - *data = value[0]; - else - *data = value[0] | value[1] << 8 | value[2] << 16 | value[3] << 24; - } - - return status; + int status = 0; + struct cx231xx_i2c_xfer_data req_data; + u8 value[4] = { 0, 0, 0, 0 }; + + if (saddr_len == 0) + saddr = 0; + else if (saddr_len == 0) + saddr &= 0xff; + + /* prepare xfer_data struct */ + req_data.dev_addr = dev_addr >> 1; + req_data.direction = I2C_M_RD; + req_data.saddr_len = saddr_len; + req_data.saddr_dat = saddr; + req_data.buf_size = data_len; + req_data.p_buffer = (u8 *) value; + + /* usb send command */ + status = dev->cx231xx_send_usb_command(&dev->i2c_bus[0], &req_data); + + if (status >= 0) { + /* Copy the data read back to main buffer */ + if (data_len == 1) + *data = value[0]; + else + *data = + value[0] | value[1] << 8 | value[2] << 16 | value[3] + << 24; + } + + return status; } int cx231xx_write_i2c_data(struct cx231xx *dev, u8 dev_addr, u16 saddr, - u8 saddr_len, u32 data, u8 data_len) + u8 saddr_len, u32 data, u8 data_len) { - int status = 0; - u8 value[4] ={0,0,0,0}; - struct cx231xx_i2c_xfer_data req_data; - - value[0]=(u8)data; - value[1]=(u8)(data>>8); - value[2]=(u8)(data>>16); - value[3]=(u8)(data>>24); - - if(saddr_len == 0) - saddr = 0; - else if(saddr_len == 0) - saddr &= 0xff; - - /* prepare xfer_data struct */ - req_data.dev_addr = dev_addr >> 1; - req_data.direction = 0; - req_data.saddr_len = saddr_len; - req_data.saddr_dat = saddr; - req_data.buf_size = data_len; - req_data.p_buffer = value; - - /* usb send command */ - status = dev->cx231xx_send_usb_command(&dev->i2c_bus[0], &req_data); - - return status; + int status = 0; + u8 value[4] = { 0, 0, 0, 0 }; + struct cx231xx_i2c_xfer_data req_data; + + value[0] = (u8) data; + value[1] = (u8) (data >> 8); + value[2] = (u8) (data >> 16); + value[3] = (u8) (data >> 24); + + if (saddr_len == 0) + saddr = 0; + else if (saddr_len == 0) + saddr &= 0xff; + + /* prepare xfer_data struct */ + req_data.dev_addr = dev_addr >> 1; + req_data.direction = 0; + req_data.saddr_len = saddr_len; + req_data.saddr_dat = saddr; + req_data.buf_size = data_len; + req_data.p_buffer = value; + + /* usb send command */ + status = dev->cx231xx_send_usb_command(&dev->i2c_bus[0], &req_data); + + return status; } -int cx231xx_reg_mask_write(struct cx231xx *dev, u8 dev_addr, u8 size, u16 register_address, - u8 bit_start,u8 bit_end, u32 value) +int cx231xx_reg_mask_write(struct cx231xx *dev, u8 dev_addr, u8 size, + u16 register_address, u8 bit_start, u8 bit_end, + u32 value) { - int status = 0; - u32 tmp; - u32 mask = 0; - int i; - - if (bit_start>(size-1) || bit_end>(size-1)) { - return -1; - } - - if (size==8){ - status = cx231xx_read_i2c_data(dev, dev_addr, register_address, 2, &tmp, 1); - } else { - status = cx231xx_read_i2c_data(dev, dev_addr, register_address, 2, &tmp, 4); - } - - if (status < 0) { - return status; - } - - mask = 1<<bit_end; - for (i=bit_end; i>bit_start&&i>0; i--) { - mask = mask + (1<<(i-1)); - } - - value <<= bit_start; - - if (size==8) - { - tmp &= ~mask; - tmp |= value; - tmp &= 0xff; - status = cx231xx_write_i2c_data(dev, dev_addr, register_address, 2, tmp, 1); - } - else - { - tmp &= ~mask; - tmp |= value; - status = cx231xx_write_i2c_data(dev, dev_addr, register_address, 2, tmp, 4); - } - - return status; -} + int status = 0; + u32 tmp; + u32 mask = 0; + int i; + + if (bit_start > (size - 1) || bit_end > (size - 1)) { + return -1; + } + if (size == 8) { + status = + cx231xx_read_i2c_data(dev, dev_addr, register_address, 2, + &tmp, 1); + } else { + status = + cx231xx_read_i2c_data(dev, dev_addr, register_address, 2, + &tmp, 4); + } + if (status < 0) { + return status; + } + + mask = 1 << bit_end; + for (i = bit_end; i > bit_start && i > 0; i--) { + mask = mask + (1 << (i - 1)); + } + + value <<= bit_start; + + if (size == 8) { + tmp &= ~mask; + tmp |= value; + tmp &= 0xff; + status = + cx231xx_write_i2c_data(dev, dev_addr, register_address, 2, + tmp, 1); + } else { + tmp &= ~mask; + tmp |= value; + status = + cx231xx_write_i2c_data(dev, dev_addr, register_address, 2, + tmp, 4); + } + + return status; +} int cx231xx_read_modify_write_i2c_dword(struct cx231xx *dev, u8 dev_addr, - u16 saddr, u32 mask, u32 value) + u16 saddr, u32 mask, u32 value) { - u32 temp; - int status = 0; + u32 temp; + int status = 0; - status = cx231xx_read_i2c_data(dev, dev_addr, saddr, 2, &temp, 4); + status = cx231xx_read_i2c_data(dev, dev_addr, saddr, 2, &temp, 4); - if(status < 0) - return status; + if (status < 0) + return status; - temp &= ~mask; - temp |= value; + temp &= ~mask; + temp |= value; - status = cx231xx_write_i2c_data(dev, dev_addr, saddr, 2, temp, 4); + status = cx231xx_write_i2c_data(dev, dev_addr, saddr, 2, temp, 4); - return status; + return status; } u32 cx231xx_set_field(u32 field_mask, u32 data) { - u32 temp; + u32 temp; - for (temp = field_mask; (temp & 1) == 0; temp >>= 1) { - data <<= 1; - } + for (temp = field_mask; (temp & 1) == 0; temp >>= 1) { + data <<= 1; + } - return data; + return data; } |