2 cx231xx-core.c - driver for Conexant Cx23100/101/102
3 USB video capture devices
5 Copyright (C) 2008 <srinivasa.deevi at conexant dot com>
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 #include <linux/init.h>
25 #include <linux/list.h>
26 #include <linux/module.h>
27 #include <linux/slab.h>
28 #include <linux/vmalloc.h>
29 #include <media/v4l2-common.h>
30 #include <media/tuner.h>
32 #include "cx231xx-reg.h"
34 /* #define ENABLE_DEBUG_ISOC_FRAMES */
36 static unsigned int core_debug
;
37 module_param(core_debug
, int, 0644);
38 MODULE_PARM_DESC(core_debug
, "enable debug messages [core]");
40 #define cx231xx_coredbg(fmt, arg...) do {\
42 printk(KERN_INFO "%s %s :"fmt, \
43 dev->name, __func__ , ##arg); } while (0)
45 static unsigned int reg_debug
;
46 module_param(reg_debug
, int, 0644);
47 MODULE_PARM_DESC(reg_debug
, "enable debug messages [URB reg]");
49 static int alt
= CX231XX_PINOUT
;
50 module_param(alt
, int, 0644);
51 MODULE_PARM_DESC(alt
, "alternate setting to use for video endpoint");
53 #define cx231xx_isocdbg(fmt, arg...) do {\
55 printk(KERN_INFO "%s %s :"fmt, \
56 dev->name, __func__ , ##arg); } while (0)
58 /*****************************************************************
59 * Device control list functions *
60 ******************************************************************/
62 LIST_HEAD(cx231xx_devlist
);
63 static DEFINE_MUTEX(cx231xx_devlist_mutex
);
66 * cx231xx_realease_resources()
67 * unregisters the v4l2,i2c and usb devices
68 * called when the device gets disconected or at module unload
70 void cx231xx_remove_from_devlist(struct cx231xx
*dev
)
74 if (dev
->udev
== NULL
)
77 if (atomic_read(&dev
->devlist_count
) > 0) {
78 mutex_lock(&cx231xx_devlist_mutex
);
79 list_del(&dev
->devlist
);
80 atomic_dec(&dev
->devlist_count
);
81 mutex_unlock(&cx231xx_devlist_mutex
);
85 void cx231xx_add_into_devlist(struct cx231xx
*dev
)
87 mutex_lock(&cx231xx_devlist_mutex
);
88 list_add_tail(&dev
->devlist
, &cx231xx_devlist
);
89 atomic_inc(&dev
->devlist_count
);
90 mutex_unlock(&cx231xx_devlist_mutex
);
93 static LIST_HEAD(cx231xx_extension_devlist
);
95 int cx231xx_register_extension(struct cx231xx_ops
*ops
)
97 struct cx231xx
*dev
= NULL
;
99 mutex_lock(&cx231xx_devlist_mutex
);
100 list_add_tail(&ops
->next
, &cx231xx_extension_devlist
);
101 list_for_each_entry(dev
, &cx231xx_devlist
, devlist
) {
103 dev_info(dev
->dev
, "%s initialized\n", ops
->name
);
105 mutex_unlock(&cx231xx_devlist_mutex
);
108 EXPORT_SYMBOL(cx231xx_register_extension
);
110 void cx231xx_unregister_extension(struct cx231xx_ops
*ops
)
112 struct cx231xx
*dev
= NULL
;
114 mutex_lock(&cx231xx_devlist_mutex
);
115 list_for_each_entry(dev
, &cx231xx_devlist
, devlist
) {
117 dev_info(dev
->dev
, "%s removed\n", ops
->name
);
120 list_del(&ops
->next
);
121 mutex_unlock(&cx231xx_devlist_mutex
);
123 EXPORT_SYMBOL(cx231xx_unregister_extension
);
125 void cx231xx_init_extension(struct cx231xx
*dev
)
127 struct cx231xx_ops
*ops
= NULL
;
129 mutex_lock(&cx231xx_devlist_mutex
);
130 if (!list_empty(&cx231xx_extension_devlist
)) {
131 list_for_each_entry(ops
, &cx231xx_extension_devlist
, next
) {
136 mutex_unlock(&cx231xx_devlist_mutex
);
139 void cx231xx_close_extension(struct cx231xx
*dev
)
141 struct cx231xx_ops
*ops
= NULL
;
143 mutex_lock(&cx231xx_devlist_mutex
);
144 if (!list_empty(&cx231xx_extension_devlist
)) {
145 list_for_each_entry(ops
, &cx231xx_extension_devlist
, next
) {
150 mutex_unlock(&cx231xx_devlist_mutex
);
153 /****************************************************************
154 * U S B related functions *
155 *****************************************************************/
156 int cx231xx_send_usb_command(struct cx231xx_i2c
*i2c_bus
,
157 struct cx231xx_i2c_xfer_data
*req_data
)
160 struct cx231xx
*dev
= i2c_bus
->dev
;
161 struct VENDOR_REQUEST_IN ven_req
;
168 if (dev
->state
& DEV_DISCONNECTED
)
171 /* Get the I2C period, nostop and reserve parameters */
172 _i2c_period
= i2c_bus
->i2c_period
;
173 _i2c_nostop
= i2c_bus
->i2c_nostop
;
174 _i2c_reserve
= i2c_bus
->i2c_reserve
;
176 saddr_len
= req_data
->saddr_len
;
179 ven_req
.wValue
= (req_data
->dev_addr
<< 9 | _i2c_period
<< 4 |
180 saddr_len
<< 2 | _i2c_nostop
<< 1 | I2C_SYNC
|
183 /* set channel number */
184 if (req_data
->direction
& I2C_M_RD
) {
185 /* channel number, for read,spec required channel_num +4 */
186 ven_req
.bRequest
= i2c_bus
->nr
+ 4;
188 ven_req
.bRequest
= i2c_bus
->nr
; /* channel number, */
190 /* set index value */
193 ven_req
.wIndex
= 0; /* need check */
196 ven_req
.wIndex
= (req_data
->saddr_dat
& 0xff);
199 ven_req
.wIndex
= req_data
->saddr_dat
;
203 /* set wLength value */
204 ven_req
.wLength
= req_data
->buf_size
;
206 /* set bData value */
209 /* set the direction */
210 if (req_data
->direction
) {
211 ven_req
.direction
= USB_DIR_IN
;
212 memset(req_data
->p_buffer
, 0x00, ven_req
.wLength
);
214 ven_req
.direction
= USB_DIR_OUT
;
216 /* set the buffer for read / write */
217 ven_req
.pBuff
= req_data
->p_buffer
;
220 /* call common vendor command request */
221 status
= cx231xx_send_vendor_cmd(dev
, &ven_req
);
222 if (status
< 0 && !dev
->i2c_scan_running
) {
223 dev_err(dev
->dev
, "%s: failed with status -%d\n",
229 EXPORT_SYMBOL_GPL(cx231xx_send_usb_command
);
232 * Sends/Receives URB control messages, assuring to use a kalloced buffer
233 * for all operations (dev->urb_buf), to avoid using stacked buffers, as
234 * they aren't safe for usage with USB, due to DMA restrictions.
235 * Also implements the debug code for control URB's.
237 static int __usb_control_msg(struct cx231xx
*dev
, unsigned int pipe
,
238 __u8 request
, __u8 requesttype
, __u16 value
, __u16 index
,
239 void *data
, __u16 size
, int timeout
)
244 printk(KERN_DEBUG
"%s: (pipe 0x%08x): %s: %02x %02x %02x %02x %02x %02x %02x %02x ",
247 (requesttype
& USB_DIR_IN
) ? "IN" : "OUT",
250 value
& 0xff, value
>> 8,
251 index
& 0xff, index
>> 8,
252 size
& 0xff, size
>> 8);
253 if (!(requesttype
& USB_DIR_IN
)) {
254 printk(KERN_CONT
">>>");
255 for (i
= 0; i
< size
; i
++)
256 printk(KERN_CONT
" %02x",
257 ((unsigned char *)data
)[i
]);
261 /* Do the real call to usb_control_msg */
262 mutex_lock(&dev
->ctrl_urb_lock
);
263 if (!(requesttype
& USB_DIR_IN
) && size
)
264 memcpy(dev
->urb_buf
, data
, size
);
265 rc
= usb_control_msg(dev
->udev
, pipe
, request
, requesttype
, value
,
266 index
, dev
->urb_buf
, size
, timeout
);
267 if ((requesttype
& USB_DIR_IN
) && size
)
268 memcpy(data
, dev
->urb_buf
, size
);
269 mutex_unlock(&dev
->ctrl_urb_lock
);
272 if (unlikely(rc
< 0)) {
273 printk(KERN_CONT
"FAILED!\n");
277 if ((requesttype
& USB_DIR_IN
)) {
278 printk(KERN_CONT
"<<<");
279 for (i
= 0; i
< size
; i
++)
280 printk(KERN_CONT
" %02x",
281 ((unsigned char *)data
)[i
]);
283 printk(KERN_CONT
"\n");
291 * cx231xx_read_ctrl_reg()
292 * reads data from the usb device specifying bRequest and wValue
294 int cx231xx_read_ctrl_reg(struct cx231xx
*dev
, u8 req
, u16 reg
,
299 int pipe
= usb_rcvctrlpipe(dev
->udev
, 0);
301 if (dev
->state
& DEV_DISCONNECTED
)
304 if (len
> URB_MAX_CTRL_SIZE
)
309 val
= ENABLE_ONE_BYTE
;
312 val
= ENABLE_TWE_BYTE
;
315 val
= ENABLE_THREE_BYTE
;
318 val
= ENABLE_FOUR_BYTE
;
321 val
= 0xFF; /* invalid option */
327 ret
= __usb_control_msg(dev
, pipe
, req
,
328 USB_DIR_IN
| USB_TYPE_VENDOR
| USB_RECIP_DEVICE
,
329 val
, reg
, buf
, len
, HZ
);
333 int cx231xx_send_vendor_cmd(struct cx231xx
*dev
,
334 struct VENDOR_REQUEST_IN
*ven_req
)
341 if (dev
->state
& DEV_DISCONNECTED
)
344 if ((ven_req
->wLength
> URB_MAX_CTRL_SIZE
))
347 if (ven_req
->direction
)
348 pipe
= usb_rcvctrlpipe(dev
->udev
, 0);
350 pipe
= usb_sndctrlpipe(dev
->udev
, 0);
353 * If the cx23102 read more than 4 bytes with i2c bus,
354 * need chop to 4 byte per request
356 if ((ven_req
->wLength
> 4) && ((ven_req
->bRequest
== 0x4) ||
357 (ven_req
->bRequest
== 0x5) ||
358 (ven_req
->bRequest
== 0x6) ||
360 /* Internal Master 3 Bus can send
361 * and receive only 4 bytes per time
363 (ven_req
->bRequest
== 0x2))) {
365 pdata
= ven_req
->pBuff
;
368 unsend_size
= ven_req
->wLength
;
370 /* the first package */
371 ven_req
->wValue
= ven_req
->wValue
& 0xFFFB;
372 ven_req
->wValue
= (ven_req
->wValue
& 0xFFBD) | 0x2;
373 ret
= __usb_control_msg(dev
, pipe
, ven_req
->bRequest
,
374 ven_req
->direction
| USB_TYPE_VENDOR
| USB_RECIP_DEVICE
,
375 ven_req
->wValue
, ven_req
->wIndex
, pdata
,
377 unsend_size
= unsend_size
- 4;
379 /* the middle package */
380 ven_req
->wValue
= (ven_req
->wValue
& 0xFFBD) | 0x42;
381 while (unsend_size
- 4 > 0) {
383 ret
= __usb_control_msg(dev
, pipe
,
385 ven_req
->direction
| USB_TYPE_VENDOR
| USB_RECIP_DEVICE
,
386 ven_req
->wValue
, ven_req
->wIndex
, pdata
,
388 unsend_size
= unsend_size
- 4;
391 /* the last package */
392 ven_req
->wValue
= (ven_req
->wValue
& 0xFFBD) | 0x40;
394 ret
= __usb_control_msg(dev
, pipe
, ven_req
->bRequest
,
395 ven_req
->direction
| USB_TYPE_VENDOR
| USB_RECIP_DEVICE
,
396 ven_req
->wValue
, ven_req
->wIndex
, pdata
,
399 ret
= __usb_control_msg(dev
, pipe
, ven_req
->bRequest
,
400 ven_req
->direction
| USB_TYPE_VENDOR
| USB_RECIP_DEVICE
,
401 ven_req
->wValue
, ven_req
->wIndex
,
402 ven_req
->pBuff
, ven_req
->wLength
, HZ
);
409 * cx231xx_write_ctrl_reg()
410 * sends data to the usb device, specifying bRequest
412 int cx231xx_write_ctrl_reg(struct cx231xx
*dev
, u8 req
, u16 reg
, char *buf
,
417 int pipe
= usb_sndctrlpipe(dev
->udev
, 0);
419 if (dev
->state
& DEV_DISCONNECTED
)
422 if ((len
< 1) || (len
> URB_MAX_CTRL_SIZE
))
427 val
= ENABLE_ONE_BYTE
;
430 val
= ENABLE_TWE_BYTE
;
433 val
= ENABLE_THREE_BYTE
;
436 val
= ENABLE_FOUR_BYTE
;
439 val
= 0xFF; /* invalid option */
448 cx231xx_isocdbg("(pipe 0x%08x): OUT: %02x %02x %02x %02x %02x %02x %02x %02x >>>",
450 USB_DIR_OUT
| USB_TYPE_VENDOR
| USB_RECIP_DEVICE
,
451 req
, 0, val
, reg
& 0xff,
452 reg
>> 8, len
& 0xff, len
>> 8);
454 for (byte
= 0; byte
< len
; byte
++)
455 cx231xx_isocdbg(" %02x", (unsigned char)buf
[byte
]);
456 cx231xx_isocdbg("\n");
459 ret
= __usb_control_msg(dev
, pipe
, req
,
460 USB_DIR_OUT
| USB_TYPE_VENDOR
| USB_RECIP_DEVICE
,
461 val
, reg
, buf
, len
, HZ
);
466 /****************************************************************
467 * USB Alternate Setting functions *
468 *****************************************************************/
470 int cx231xx_set_video_alternate(struct cx231xx
*dev
)
472 int errCode
, prev_alt
= dev
->video_mode
.alt
;
473 unsigned int min_pkt_size
= dev
->width
* 2 + 4;
474 u32 usb_interface_index
= 0;
476 /* When image size is bigger than a certain value,
477 the frame size should be increased, otherwise, only
478 green screen will be received.
480 if (dev
->width
* 2 * dev
->height
> 720 * 240 * 2)
483 if (dev
->width
> 360) {
484 /* resolutions: 720,704,640 */
485 dev
->video_mode
.alt
= 3;
486 } else if (dev
->width
> 180) {
487 /* resolutions: 360,352,320,240 */
488 dev
->video_mode
.alt
= 2;
489 } else if (dev
->width
> 0) {
490 /* resolutions: 180,176,160,128,88 */
491 dev
->video_mode
.alt
= 1;
493 /* Change to alt0 BULK to release USB bandwidth */
494 dev
->video_mode
.alt
= 0;
497 if (dev
->USE_ISO
== 0)
498 dev
->video_mode
.alt
= 0;
500 cx231xx_coredbg("dev->video_mode.alt= %d\n", dev
->video_mode
.alt
);
502 /* Get the correct video interface Index */
503 usb_interface_index
=
504 dev
->current_pcb_config
.hs_config_info
[0].interface_info
.
507 if (dev
->video_mode
.alt
!= prev_alt
) {
508 cx231xx_coredbg("minimum isoc packet size: %u (alt=%d)\n",
509 min_pkt_size
, dev
->video_mode
.alt
);
511 if (dev
->video_mode
.alt_max_pkt_size
!= NULL
)
512 dev
->video_mode
.max_pkt_size
=
513 dev
->video_mode
.alt_max_pkt_size
[dev
->video_mode
.alt
];
514 cx231xx_coredbg("setting alternate %d with wMaxPacketSize=%u\n",
516 dev
->video_mode
.max_pkt_size
);
518 usb_set_interface(dev
->udev
, usb_interface_index
,
519 dev
->video_mode
.alt
);
522 "cannot change alt number to %d (error=%i)\n",
523 dev
->video_mode
.alt
, errCode
);
530 int cx231xx_set_alt_setting(struct cx231xx
*dev
, u8 index
, u8 alt
)
533 u32 usb_interface_index
= 0;
534 u32 max_pkt_size
= 0;
538 usb_interface_index
=
539 dev
->current_pcb_config
.hs_config_info
[0].interface_info
.
541 dev
->ts1_mode
.alt
= alt
;
542 if (dev
->ts1_mode
.alt_max_pkt_size
!= NULL
)
543 max_pkt_size
= dev
->ts1_mode
.max_pkt_size
=
544 dev
->ts1_mode
.alt_max_pkt_size
[dev
->ts1_mode
.alt
];
547 usb_interface_index
=
548 dev
->current_pcb_config
.hs_config_info
[0].interface_info
.
552 usb_interface_index
=
553 dev
->current_pcb_config
.hs_config_info
[0].interface_info
.
556 if (dev
->adev
.alt_max_pkt_size
!= NULL
)
557 max_pkt_size
= dev
->adev
.max_pkt_size
=
558 dev
->adev
.alt_max_pkt_size
[dev
->adev
.alt
];
561 usb_interface_index
=
562 dev
->current_pcb_config
.hs_config_info
[0].interface_info
.
564 dev
->video_mode
.alt
= alt
;
565 if (dev
->video_mode
.alt_max_pkt_size
!= NULL
)
566 max_pkt_size
= dev
->video_mode
.max_pkt_size
=
567 dev
->video_mode
.alt_max_pkt_size
[dev
->video_mode
.
571 if (dev
->board
.no_alt_vanc
)
573 usb_interface_index
=
574 dev
->current_pcb_config
.hs_config_info
[0].interface_info
.
576 dev
->vbi_mode
.alt
= alt
;
577 if (dev
->vbi_mode
.alt_max_pkt_size
!= NULL
)
578 max_pkt_size
= dev
->vbi_mode
.max_pkt_size
=
579 dev
->vbi_mode
.alt_max_pkt_size
[dev
->vbi_mode
.alt
];
582 usb_interface_index
=
583 dev
->current_pcb_config
.hs_config_info
[0].interface_info
.
585 dev
->sliced_cc_mode
.alt
= alt
;
586 if (dev
->sliced_cc_mode
.alt_max_pkt_size
!= NULL
)
587 max_pkt_size
= dev
->sliced_cc_mode
.max_pkt_size
=
588 dev
->sliced_cc_mode
.alt_max_pkt_size
[dev
->
596 if (alt
> 0 && max_pkt_size
== 0) {
598 "can't change interface %d alt no. to %d: Max. Pkt size = 0\n",
599 usb_interface_index
, alt
);
600 /*To workaround error number=-71 on EP0 for videograbber,
601 need add following codes.*/
602 if (dev
->board
.no_alt_vanc
)
606 cx231xx_coredbg("setting alternate %d with wMaxPacketSize=%u,Interface = %d\n",
608 usb_interface_index
);
610 if (usb_interface_index
> 0) {
611 status
= usb_set_interface(dev
->udev
, usb_interface_index
, alt
);
614 "can't change interface %d alt no. to %d (err=%i)\n",
615 usb_interface_index
, alt
, status
);
622 EXPORT_SYMBOL_GPL(cx231xx_set_alt_setting
);
624 int cx231xx_gpio_set(struct cx231xx
*dev
, struct cx231xx_reg_seq
*gpio
)
631 /* Send GPIO reset sequences specified at board entry */
632 while (gpio
->sleep
>= 0) {
633 rc
= cx231xx_set_gpio_value(dev
, gpio
->bit
, gpio
->val
);
645 int cx231xx_demod_reset(struct cx231xx
*dev
)
649 u8 value
[4] = { 0, 0, 0, 0 };
651 status
= cx231xx_read_ctrl_reg(dev
, VRT_GET_REGISTER
, PWR_CTL_EN
,
654 cx231xx_coredbg("reg0x%x=0x%x 0x%x 0x%x 0x%x\n", PWR_CTL_EN
,
655 value
[0], value
[1], value
[2], value
[3]);
657 cx231xx_coredbg("Enter cx231xx_demod_reset()\n");
660 status
= cx231xx_write_ctrl_reg(dev
, VRT_SET_REGISTER
,
661 PWR_CTL_EN
, value
, 4);
665 status
= cx231xx_write_ctrl_reg(dev
, VRT_SET_REGISTER
,
666 PWR_CTL_EN
, value
, 4);
670 status
= cx231xx_write_ctrl_reg(dev
, VRT_SET_REGISTER
,
671 PWR_CTL_EN
, value
, 4);
674 status
= cx231xx_read_ctrl_reg(dev
, VRT_GET_REGISTER
, PWR_CTL_EN
,
677 cx231xx_coredbg("reg0x%x=0x%x 0x%x 0x%x 0x%x\n", PWR_CTL_EN
,
678 value
[0], value
[1], value
[2], value
[3]);
682 EXPORT_SYMBOL_GPL(cx231xx_demod_reset
);
683 int is_fw_load(struct cx231xx
*dev
)
685 return cx231xx_check_fw(dev
);
687 EXPORT_SYMBOL_GPL(is_fw_load
);
689 int cx231xx_set_mode(struct cx231xx
*dev
, enum cx231xx_mode set_mode
)
693 if (dev
->mode
== set_mode
)
696 if (set_mode
== CX231XX_SUSPEND
) {
697 /* Set the chip in power saving mode */
698 dev
->mode
= set_mode
;
701 /* Resource is locked */
702 if (dev
->mode
!= CX231XX_SUSPEND
)
705 dev
->mode
= set_mode
;
707 if (dev
->mode
== CX231XX_DIGITAL_MODE
)/* Set Digital power mode */ {
708 /* set AGC mode to Digital */
709 switch (dev
->model
) {
710 case CX231XX_BOARD_CNXT_CARRAERA
:
711 case CX231XX_BOARD_CNXT_RDE_250
:
712 case CX231XX_BOARD_CNXT_SHELBY
:
713 case CX231XX_BOARD_CNXT_RDU_250
:
714 errCode
= cx231xx_set_agc_analog_digital_mux_select(dev
, 0);
716 case CX231XX_BOARD_CNXT_RDE_253S
:
717 case CX231XX_BOARD_CNXT_RDU_253S
:
718 case CX231XX_BOARD_PV_PLAYTV_USB_HYBRID
:
719 errCode
= cx231xx_set_agc_analog_digital_mux_select(dev
, 1);
721 case CX231XX_BOARD_HAUPPAUGE_EXETER
:
722 case CX231XX_BOARD_HAUPPAUGE_930C_HD_1113xx
:
723 errCode
= cx231xx_set_power_mode(dev
,
724 POLARIS_AVMODE_DIGITAL
);
729 } else/* Set Analog Power mode */ {
730 /* set AGC mode to Analog */
731 switch (dev
->model
) {
732 case CX231XX_BOARD_CNXT_CARRAERA
:
733 case CX231XX_BOARD_CNXT_RDE_250
:
734 case CX231XX_BOARD_CNXT_SHELBY
:
735 case CX231XX_BOARD_CNXT_RDU_250
:
736 errCode
= cx231xx_set_agc_analog_digital_mux_select(dev
, 1);
738 case CX231XX_BOARD_CNXT_RDE_253S
:
739 case CX231XX_BOARD_CNXT_RDU_253S
:
740 case CX231XX_BOARD_HAUPPAUGE_EXETER
:
741 case CX231XX_BOARD_HAUPPAUGE_930C_HD_1113xx
:
742 case CX231XX_BOARD_PV_PLAYTV_USB_HYBRID
:
743 case CX231XX_BOARD_HAUPPAUGE_USB2_FM_PAL
:
744 case CX231XX_BOARD_HAUPPAUGE_USB2_FM_NTSC
:
745 errCode
= cx231xx_set_agc_analog_digital_mux_select(dev
, 0);
753 dev_err(dev
->dev
, "Failed to set devmode to %s: error: %i",
754 dev
->mode
== CX231XX_DIGITAL_MODE
? "digital" : "analog",
761 EXPORT_SYMBOL_GPL(cx231xx_set_mode
);
763 int cx231xx_ep5_bulkout(struct cx231xx
*dev
, u8
*firmware
, u16 size
)
770 buffer
= kzalloc(4096, GFP_KERNEL
);
773 memcpy(&buffer
[0], firmware
, 4096);
775 ret
= usb_bulk_msg(dev
->udev
, usb_sndbulkpipe(dev
->udev
, 5),
776 buffer
, 4096, &actlen
, 2000);
780 "bulk message failed: %d (%d/%d)", ret
,
783 errCode
= actlen
!= size
? -1 : 0;
789 /*****************************************************************
790 * URB Streaming functions *
791 ******************************************************************/
794 * IRQ callback, called by URB callback
796 static void cx231xx_isoc_irq_callback(struct urb
*urb
)
798 struct cx231xx_dmaqueue
*dma_q
= urb
->context
;
799 struct cx231xx_video_mode
*vmode
=
800 container_of(dma_q
, struct cx231xx_video_mode
, vidq
);
801 struct cx231xx
*dev
= container_of(vmode
, struct cx231xx
, video_mode
);
805 switch (urb
->status
) {
806 case 0: /* success */
807 case -ETIMEDOUT
: /* NAK */
809 case -ECONNRESET
: /* kill */
814 cx231xx_isocdbg("urb completion error %d.\n", urb
->status
);
818 /* Copy data from URB */
819 spin_lock_irqsave(&dev
->video_mode
.slock
, flags
);
820 dev
->video_mode
.isoc_ctl
.isoc_copy(dev
, urb
);
821 spin_unlock_irqrestore(&dev
->video_mode
.slock
, flags
);
823 /* Reset urb buffers */
824 for (i
= 0; i
< urb
->number_of_packets
; i
++) {
825 urb
->iso_frame_desc
[i
].status
= 0;
826 urb
->iso_frame_desc
[i
].actual_length
= 0;
829 urb
->status
= usb_submit_urb(urb
, GFP_ATOMIC
);
831 cx231xx_isocdbg("urb resubmit failed (error=%i)\n",
835 /*****************************************************************
836 * URB Streaming functions *
837 ******************************************************************/
840 * IRQ callback, called by URB callback
842 static void cx231xx_bulk_irq_callback(struct urb
*urb
)
844 struct cx231xx_dmaqueue
*dma_q
= urb
->context
;
845 struct cx231xx_video_mode
*vmode
=
846 container_of(dma_q
, struct cx231xx_video_mode
, vidq
);
847 struct cx231xx
*dev
= container_of(vmode
, struct cx231xx
, video_mode
);
850 switch (urb
->status
) {
851 case 0: /* success */
852 case -ETIMEDOUT
: /* NAK */
854 case -ECONNRESET
: /* kill */
858 case -EPIPE
: /* stall */
859 cx231xx_isocdbg("urb completion error - device is stalled.\n");
862 cx231xx_isocdbg("urb completion error %d.\n", urb
->status
);
866 /* Copy data from URB */
867 spin_lock_irqsave(&dev
->video_mode
.slock
, flags
);
868 dev
->video_mode
.bulk_ctl
.bulk_copy(dev
, urb
);
869 spin_unlock_irqrestore(&dev
->video_mode
.slock
, flags
);
871 /* Reset urb buffers */
872 urb
->status
= usb_submit_urb(urb
, GFP_ATOMIC
);
874 cx231xx_isocdbg("urb resubmit failed (error=%i)\n",
879 * Stop and Deallocate URBs
881 void cx231xx_uninit_isoc(struct cx231xx
*dev
)
883 struct cx231xx_dmaqueue
*dma_q
= &dev
->video_mode
.vidq
;
886 bool broken_pipe
= false;
888 cx231xx_isocdbg("cx231xx: called cx231xx_uninit_isoc\n");
890 dev
->video_mode
.isoc_ctl
.nfields
= -1;
891 for (i
= 0; i
< dev
->video_mode
.isoc_ctl
.num_bufs
; i
++) {
892 urb
= dev
->video_mode
.isoc_ctl
.urb
[i
];
894 if (!irqs_disabled())
899 if (dev
->video_mode
.isoc_ctl
.transfer_buffer
[i
]) {
900 usb_free_coherent(dev
->udev
,
901 urb
->transfer_buffer_length
,
902 dev
->video_mode
.isoc_ctl
.
906 if (urb
->status
== -EPIPE
) {
910 dev
->video_mode
.isoc_ctl
.urb
[i
] = NULL
;
912 dev
->video_mode
.isoc_ctl
.transfer_buffer
[i
] = NULL
;
916 cx231xx_isocdbg("Reset endpoint to recover broken pipe.");
917 usb_reset_endpoint(dev
->udev
, dev
->video_mode
.end_point_addr
);
919 kfree(dev
->video_mode
.isoc_ctl
.urb
);
920 kfree(dev
->video_mode
.isoc_ctl
.transfer_buffer
);
921 kfree(dma_q
->p_left_data
);
923 dev
->video_mode
.isoc_ctl
.urb
= NULL
;
924 dev
->video_mode
.isoc_ctl
.transfer_buffer
= NULL
;
925 dev
->video_mode
.isoc_ctl
.num_bufs
= 0;
926 dma_q
->p_left_data
= NULL
;
928 if (dev
->mode_tv
== 0)
929 cx231xx_capture_start(dev
, 0, Raw_Video
);
931 cx231xx_capture_start(dev
, 0, TS1_serial_mode
);
935 EXPORT_SYMBOL_GPL(cx231xx_uninit_isoc
);
938 * Stop and Deallocate URBs
940 void cx231xx_uninit_bulk(struct cx231xx
*dev
)
942 struct cx231xx_dmaqueue
*dma_q
= &dev
->video_mode
.vidq
;
945 bool broken_pipe
= false;
947 cx231xx_isocdbg("cx231xx: called cx231xx_uninit_bulk\n");
949 dev
->video_mode
.bulk_ctl
.nfields
= -1;
950 for (i
= 0; i
< dev
->video_mode
.bulk_ctl
.num_bufs
; i
++) {
951 urb
= dev
->video_mode
.bulk_ctl
.urb
[i
];
953 if (!irqs_disabled())
958 if (dev
->video_mode
.bulk_ctl
.transfer_buffer
[i
]) {
959 usb_free_coherent(dev
->udev
,
960 urb
->transfer_buffer_length
,
961 dev
->video_mode
.bulk_ctl
.
965 if (urb
->status
== -EPIPE
) {
969 dev
->video_mode
.bulk_ctl
.urb
[i
] = NULL
;
971 dev
->video_mode
.bulk_ctl
.transfer_buffer
[i
] = NULL
;
975 cx231xx_isocdbg("Reset endpoint to recover broken pipe.");
976 usb_reset_endpoint(dev
->udev
, dev
->video_mode
.end_point_addr
);
978 kfree(dev
->video_mode
.bulk_ctl
.urb
);
979 kfree(dev
->video_mode
.bulk_ctl
.transfer_buffer
);
980 kfree(dma_q
->p_left_data
);
982 dev
->video_mode
.bulk_ctl
.urb
= NULL
;
983 dev
->video_mode
.bulk_ctl
.transfer_buffer
= NULL
;
984 dev
->video_mode
.bulk_ctl
.num_bufs
= 0;
985 dma_q
->p_left_data
= NULL
;
987 if (dev
->mode_tv
== 0)
988 cx231xx_capture_start(dev
, 0, Raw_Video
);
990 cx231xx_capture_start(dev
, 0, TS1_serial_mode
);
994 EXPORT_SYMBOL_GPL(cx231xx_uninit_bulk
);
997 * Allocate URBs and start IRQ
999 int cx231xx_init_isoc(struct cx231xx
*dev
, int max_packets
,
1000 int num_bufs
, int max_pkt_size
,
1001 int (*isoc_copy
) (struct cx231xx
*dev
, struct urb
*urb
))
1003 struct cx231xx_dmaqueue
*dma_q
= &dev
->video_mode
.vidq
;
1010 /* De-allocates all pending stuff */
1011 cx231xx_uninit_isoc(dev
);
1013 dma_q
->p_left_data
= kzalloc(4096, GFP_KERNEL
);
1014 if (dma_q
->p_left_data
== NULL
)
1017 dev
->video_mode
.isoc_ctl
.isoc_copy
= isoc_copy
;
1018 dev
->video_mode
.isoc_ctl
.num_bufs
= num_bufs
;
1020 dma_q
->is_partial_line
= 0;
1021 dma_q
->last_sav
= 0;
1022 dma_q
->current_field
= -1;
1023 dma_q
->field1_done
= 0;
1024 dma_q
->lines_per_field
= dev
->height
/ 2;
1025 dma_q
->bytes_left_in_line
= dev
->width
<< 1;
1026 dma_q
->lines_completed
= 0;
1027 dma_q
->mpeg_buffer_done
= 0;
1028 dma_q
->left_data_count
= 0;
1029 dma_q
->mpeg_buffer_completed
= 0;
1030 dma_q
->add_ps_package_head
= CX231XX_NEED_ADD_PS_PACKAGE_HEAD
;
1031 dma_q
->ps_head
[0] = 0x00;
1032 dma_q
->ps_head
[1] = 0x00;
1033 dma_q
->ps_head
[2] = 0x01;
1034 dma_q
->ps_head
[3] = 0xBA;
1035 for (i
= 0; i
< 8; i
++)
1036 dma_q
->partial_buf
[i
] = 0;
1038 dev
->video_mode
.isoc_ctl
.urb
=
1039 kcalloc(num_bufs
, sizeof(void *), GFP_KERNEL
);
1040 if (!dev
->video_mode
.isoc_ctl
.urb
) {
1042 "cannot alloc memory for usb buffers\n");
1046 dev
->video_mode
.isoc_ctl
.transfer_buffer
=
1047 kcalloc(num_bufs
, sizeof(void *), GFP_KERNEL
);
1048 if (!dev
->video_mode
.isoc_ctl
.transfer_buffer
) {
1050 "cannot allocate memory for usbtransfer\n");
1051 kfree(dev
->video_mode
.isoc_ctl
.urb
);
1055 dev
->video_mode
.isoc_ctl
.max_pkt_size
= max_pkt_size
;
1056 dev
->video_mode
.isoc_ctl
.buf
= NULL
;
1058 sb_size
= max_packets
* dev
->video_mode
.isoc_ctl
.max_pkt_size
;
1060 if (dev
->mode_tv
== 1)
1061 dev
->video_mode
.end_point_addr
= 0x81;
1063 dev
->video_mode
.end_point_addr
= 0x84;
1066 /* allocate urbs and transfer buffers */
1067 for (i
= 0; i
< dev
->video_mode
.isoc_ctl
.num_bufs
; i
++) {
1068 urb
= usb_alloc_urb(max_packets
, GFP_KERNEL
);
1070 cx231xx_uninit_isoc(dev
);
1073 dev
->video_mode
.isoc_ctl
.urb
[i
] = urb
;
1075 dev
->video_mode
.isoc_ctl
.transfer_buffer
[i
] =
1076 usb_alloc_coherent(dev
->udev
, sb_size
, GFP_KERNEL
,
1077 &urb
->transfer_dma
);
1078 if (!dev
->video_mode
.isoc_ctl
.transfer_buffer
[i
]) {
1080 "unable to allocate %i bytes for transfer buffer %i%s\n",
1082 in_interrupt() ? " while in int" : "");
1083 cx231xx_uninit_isoc(dev
);
1086 memset(dev
->video_mode
.isoc_ctl
.transfer_buffer
[i
], 0, sb_size
);
1089 usb_rcvisocpipe(dev
->udev
, dev
->video_mode
.end_point_addr
);
1091 usb_fill_int_urb(urb
, dev
->udev
, pipe
,
1092 dev
->video_mode
.isoc_ctl
.transfer_buffer
[i
],
1093 sb_size
, cx231xx_isoc_irq_callback
, dma_q
, 1);
1095 urb
->number_of_packets
= max_packets
;
1096 urb
->transfer_flags
= URB_ISO_ASAP
| URB_NO_TRANSFER_DMA_MAP
;
1099 for (j
= 0; j
< max_packets
; j
++) {
1100 urb
->iso_frame_desc
[j
].offset
= k
;
1101 urb
->iso_frame_desc
[j
].length
=
1102 dev
->video_mode
.isoc_ctl
.max_pkt_size
;
1103 k
+= dev
->video_mode
.isoc_ctl
.max_pkt_size
;
1107 init_waitqueue_head(&dma_q
->wq
);
1109 /* submit urbs and enables IRQ */
1110 for (i
= 0; i
< dev
->video_mode
.isoc_ctl
.num_bufs
; i
++) {
1111 rc
= usb_submit_urb(dev
->video_mode
.isoc_ctl
.urb
[i
],
1115 "submit of urb %i failed (error=%i)\n", i
,
1117 cx231xx_uninit_isoc(dev
);
1122 if (dev
->mode_tv
== 0)
1123 cx231xx_capture_start(dev
, 1, Raw_Video
);
1125 cx231xx_capture_start(dev
, 1, TS1_serial_mode
);
1129 EXPORT_SYMBOL_GPL(cx231xx_init_isoc
);
1132 * Allocate URBs and start IRQ
1134 int cx231xx_init_bulk(struct cx231xx
*dev
, int max_packets
,
1135 int num_bufs
, int max_pkt_size
,
1136 int (*bulk_copy
) (struct cx231xx
*dev
, struct urb
*urb
))
1138 struct cx231xx_dmaqueue
*dma_q
= &dev
->video_mode
.vidq
;
1144 dev
->video_input
= dev
->video_input
> 2 ? 2 : dev
->video_input
;
1146 cx231xx_coredbg("Setting Video mux to %d\n", dev
->video_input
);
1148 video_mux(dev
, dev
->video_input
);
1150 /* De-allocates all pending stuff */
1151 cx231xx_uninit_bulk(dev
);
1153 dev
->video_mode
.bulk_ctl
.bulk_copy
= bulk_copy
;
1154 dev
->video_mode
.bulk_ctl
.num_bufs
= num_bufs
;
1156 dma_q
->is_partial_line
= 0;
1157 dma_q
->last_sav
= 0;
1158 dma_q
->current_field
= -1;
1159 dma_q
->field1_done
= 0;
1160 dma_q
->lines_per_field
= dev
->height
/ 2;
1161 dma_q
->bytes_left_in_line
= dev
->width
<< 1;
1162 dma_q
->lines_completed
= 0;
1163 dma_q
->mpeg_buffer_done
= 0;
1164 dma_q
->left_data_count
= 0;
1165 dma_q
->mpeg_buffer_completed
= 0;
1166 dma_q
->ps_head
[0] = 0x00;
1167 dma_q
->ps_head
[1] = 0x00;
1168 dma_q
->ps_head
[2] = 0x01;
1169 dma_q
->ps_head
[3] = 0xBA;
1170 for (i
= 0; i
< 8; i
++)
1171 dma_q
->partial_buf
[i
] = 0;
1173 dev
->video_mode
.bulk_ctl
.urb
=
1174 kcalloc(num_bufs
, sizeof(void *), GFP_KERNEL
);
1175 if (!dev
->video_mode
.bulk_ctl
.urb
) {
1177 "cannot alloc memory for usb buffers\n");
1181 dev
->video_mode
.bulk_ctl
.transfer_buffer
=
1182 kcalloc(num_bufs
, sizeof(void *), GFP_KERNEL
);
1183 if (!dev
->video_mode
.bulk_ctl
.transfer_buffer
) {
1185 "cannot allocate memory for usbtransfer\n");
1186 kfree(dev
->video_mode
.bulk_ctl
.urb
);
1190 dev
->video_mode
.bulk_ctl
.max_pkt_size
= max_pkt_size
;
1191 dev
->video_mode
.bulk_ctl
.buf
= NULL
;
1193 sb_size
= max_packets
* dev
->video_mode
.bulk_ctl
.max_pkt_size
;
1195 if (dev
->mode_tv
== 1)
1196 dev
->video_mode
.end_point_addr
= 0x81;
1198 dev
->video_mode
.end_point_addr
= 0x84;
1201 /* allocate urbs and transfer buffers */
1202 for (i
= 0; i
< dev
->video_mode
.bulk_ctl
.num_bufs
; i
++) {
1203 urb
= usb_alloc_urb(0, GFP_KERNEL
);
1205 cx231xx_uninit_bulk(dev
);
1208 dev
->video_mode
.bulk_ctl
.urb
[i
] = urb
;
1209 urb
->transfer_flags
= URB_NO_TRANSFER_DMA_MAP
;
1211 dev
->video_mode
.bulk_ctl
.transfer_buffer
[i
] =
1212 usb_alloc_coherent(dev
->udev
, sb_size
, GFP_KERNEL
,
1213 &urb
->transfer_dma
);
1214 if (!dev
->video_mode
.bulk_ctl
.transfer_buffer
[i
]) {
1216 "unable to allocate %i bytes for transfer buffer %i%s\n",
1218 in_interrupt() ? " while in int" : "");
1219 cx231xx_uninit_bulk(dev
);
1222 memset(dev
->video_mode
.bulk_ctl
.transfer_buffer
[i
], 0, sb_size
);
1224 pipe
= usb_rcvbulkpipe(dev
->udev
,
1225 dev
->video_mode
.end_point_addr
);
1226 usb_fill_bulk_urb(urb
, dev
->udev
, pipe
,
1227 dev
->video_mode
.bulk_ctl
.transfer_buffer
[i
],
1228 sb_size
, cx231xx_bulk_irq_callback
, dma_q
);
1232 rc
= usb_clear_halt(dev
->udev
, dev
->video_mode
.bulk_ctl
.urb
[0]->pipe
);
1235 "failed to clear USB bulk endpoint stall/halt condition (error=%i)\n",
1237 cx231xx_uninit_bulk(dev
);
1241 init_waitqueue_head(&dma_q
->wq
);
1243 /* submit urbs and enables IRQ */
1244 for (i
= 0; i
< dev
->video_mode
.bulk_ctl
.num_bufs
; i
++) {
1245 rc
= usb_submit_urb(dev
->video_mode
.bulk_ctl
.urb
[i
],
1249 "submit of urb %i failed (error=%i)\n", i
, rc
);
1250 cx231xx_uninit_bulk(dev
);
1255 if (dev
->mode_tv
== 0)
1256 cx231xx_capture_start(dev
, 1, Raw_Video
);
1258 cx231xx_capture_start(dev
, 1, TS1_serial_mode
);
1262 EXPORT_SYMBOL_GPL(cx231xx_init_bulk
);
1263 void cx231xx_stop_TS1(struct cx231xx
*dev
)
1265 u8 val
[4] = { 0, 0, 0, 0 };
1271 cx231xx_write_ctrl_reg(dev
, VRT_SET_REGISTER
,
1272 TS_MODE_REG
, val
, 4);
1278 cx231xx_write_ctrl_reg(dev
, VRT_SET_REGISTER
,
1279 TS1_CFG_REG
, val
, 4);
1281 /* EXPORT_SYMBOL_GPL(cx231xx_stop_TS1); */
1282 void cx231xx_start_TS1(struct cx231xx
*dev
)
1284 u8 val
[4] = { 0, 0, 0, 0 };
1290 cx231xx_write_ctrl_reg(dev
, VRT_SET_REGISTER
,
1291 TS_MODE_REG
, val
, 4);
1297 cx231xx_write_ctrl_reg(dev
, VRT_SET_REGISTER
,
1298 TS1_CFG_REG
, val
, 4);
1300 /* EXPORT_SYMBOL_GPL(cx231xx_start_TS1); */
1301 /*****************************************************************
1302 * Device Init/UnInit functions *
1303 ******************************************************************/
1304 int cx231xx_dev_init(struct cx231xx
*dev
)
1308 /* Initialize I2C bus */
1310 /* External Master 1 Bus */
1311 dev
->i2c_bus
[0].nr
= 0;
1312 dev
->i2c_bus
[0].dev
= dev
;
1313 dev
->i2c_bus
[0].i2c_period
= I2C_SPEED_100K
; /* 100 KHz */
1314 dev
->i2c_bus
[0].i2c_nostop
= 0;
1315 dev
->i2c_bus
[0].i2c_reserve
= 0;
1316 dev
->i2c_bus
[0].i2c_rc
= -ENODEV
;
1318 /* External Master 2 Bus */
1319 dev
->i2c_bus
[1].nr
= 1;
1320 dev
->i2c_bus
[1].dev
= dev
;
1321 dev
->i2c_bus
[1].i2c_period
= I2C_SPEED_100K
; /* 100 KHz */
1322 dev
->i2c_bus
[1].i2c_nostop
= 0;
1323 dev
->i2c_bus
[1].i2c_reserve
= 0;
1324 dev
->i2c_bus
[1].i2c_rc
= -ENODEV
;
1326 /* Internal Master 3 Bus */
1327 dev
->i2c_bus
[2].nr
= 2;
1328 dev
->i2c_bus
[2].dev
= dev
;
1329 dev
->i2c_bus
[2].i2c_period
= I2C_SPEED_100K
; /* 100kHz */
1330 dev
->i2c_bus
[2].i2c_nostop
= 0;
1331 dev
->i2c_bus
[2].i2c_reserve
= 0;
1332 dev
->i2c_bus
[2].i2c_rc
= -ENODEV
;
1334 /* register I2C buses */
1335 errCode
= cx231xx_i2c_register(&dev
->i2c_bus
[0]);
1338 errCode
= cx231xx_i2c_register(&dev
->i2c_bus
[1]);
1341 errCode
= cx231xx_i2c_register(&dev
->i2c_bus
[2]);
1345 errCode
= cx231xx_i2c_mux_create(dev
);
1348 "%s: Failed to create I2C mux\n", __func__
);
1351 errCode
= cx231xx_i2c_mux_register(dev
, 0);
1355 errCode
= cx231xx_i2c_mux_register(dev
, 1);
1359 /* scan the real bus segments in the order of physical port numbers */
1360 cx231xx_do_i2c_scan(dev
, I2C_0
);
1361 cx231xx_do_i2c_scan(dev
, I2C_1_MUX_1
);
1362 cx231xx_do_i2c_scan(dev
, I2C_2
);
1363 cx231xx_do_i2c_scan(dev
, I2C_1_MUX_3
);
1366 /* Note : with out calling set power mode function,
1367 afe can not be set up correctly */
1368 if (dev
->board
.external_av
) {
1369 errCode
= cx231xx_set_power_mode(dev
,
1370 POLARIS_AVMODE_ENXTERNAL_AV
);
1373 "%s: Failed to set Power - errCode [%d]!\n",
1378 errCode
= cx231xx_set_power_mode(dev
,
1379 POLARIS_AVMODE_ANALOGT_TV
);
1382 "%s: Failed to set Power - errCode [%d]!\n",
1388 /* reset the Tuner, if it is a Xceive tuner */
1389 if ((dev
->board
.tuner_type
== TUNER_XC5000
) ||
1390 (dev
->board
.tuner_type
== TUNER_XC2028
))
1391 cx231xx_gpio_set(dev
, dev
->board
.tuner_gpio
);
1393 /* initialize Colibri block */
1394 errCode
= cx231xx_afe_init_super_block(dev
, 0x23c);
1397 "%s: cx231xx_afe init super block - errCode [%d]!\n",
1401 errCode
= cx231xx_afe_init_channels(dev
);
1404 "%s: cx231xx_afe init channels - errCode [%d]!\n",
1409 /* Set DIF in By pass mode */
1410 errCode
= cx231xx_dif_set_standard(dev
, DIF_USE_BASEBAND
);
1413 "%s: cx231xx_dif set to By pass mode - errCode [%d]!\n",
1418 /* I2S block related functions */
1419 errCode
= cx231xx_i2s_blk_initialize(dev
);
1422 "%s: cx231xx_i2s block initialize - errCode [%d]!\n",
1427 /* init control pins */
1428 errCode
= cx231xx_init_ctrl_pin_status(dev
);
1431 "%s: cx231xx_init ctrl pins - errCode [%d]!\n",
1436 /* set AGC mode to Analog */
1437 switch (dev
->model
) {
1438 case CX231XX_BOARD_CNXT_CARRAERA
:
1439 case CX231XX_BOARD_CNXT_RDE_250
:
1440 case CX231XX_BOARD_CNXT_SHELBY
:
1441 case CX231XX_BOARD_CNXT_RDU_250
:
1442 errCode
= cx231xx_set_agc_analog_digital_mux_select(dev
, 1);
1444 case CX231XX_BOARD_CNXT_RDE_253S
:
1445 case CX231XX_BOARD_CNXT_RDU_253S
:
1446 case CX231XX_BOARD_HAUPPAUGE_EXETER
:
1447 case CX231XX_BOARD_HAUPPAUGE_930C_HD_1113xx
:
1448 case CX231XX_BOARD_PV_PLAYTV_USB_HYBRID
:
1449 case CX231XX_BOARD_HAUPPAUGE_USB2_FM_PAL
:
1450 case CX231XX_BOARD_HAUPPAUGE_USB2_FM_NTSC
:
1451 errCode
= cx231xx_set_agc_analog_digital_mux_select(dev
, 0);
1458 "%s: cx231xx_AGC mode to Analog - errCode [%d]!\n",
1463 /* set all alternate settings to zero initially */
1464 cx231xx_set_alt_setting(dev
, INDEX_VIDEO
, 0);
1465 cx231xx_set_alt_setting(dev
, INDEX_VANC
, 0);
1466 cx231xx_set_alt_setting(dev
, INDEX_HANC
, 0);
1467 if (dev
->board
.has_dvb
)
1468 cx231xx_set_alt_setting(dev
, INDEX_TS1
, 0);
1473 EXPORT_SYMBOL_GPL(cx231xx_dev_init
);
1475 void cx231xx_dev_uninit(struct cx231xx
*dev
)
1477 /* Un Initialize I2C bus */
1478 cx231xx_i2c_mux_unregister(dev
);
1479 cx231xx_i2c_unregister(&dev
->i2c_bus
[2]);
1480 cx231xx_i2c_unregister(&dev
->i2c_bus
[1]);
1481 cx231xx_i2c_unregister(&dev
->i2c_bus
[0]);
1483 EXPORT_SYMBOL_GPL(cx231xx_dev_uninit
);
1485 /*****************************************************************
1486 * G P I O related functions *
1487 ******************************************************************/
1488 int cx231xx_send_gpio_cmd(struct cx231xx
*dev
, u32 gpio_bit
, u8
*gpio_val
,
1489 u8 len
, u8 request
, u8 direction
)
1492 struct VENDOR_REQUEST_IN ven_req
;
1495 ven_req
.wValue
= (u16
) (gpio_bit
>> 16 & 0xffff);
1500 ven_req
.bRequest
= VRT_GET_GPIO
; /* 0x9 gpio */
1502 ven_req
.bRequest
= VRT_SET_GPIO
; /* 0x8 gpio */
1505 ven_req
.bRequest
= VRT_GET_GPIE
; /* 0xb gpie */
1507 ven_req
.bRequest
= VRT_SET_GPIE
; /* 0xa gpie */
1510 /* set index value */
1511 ven_req
.wIndex
= (u16
) (gpio_bit
& 0xffff);
1513 /* set wLength value */
1514 ven_req
.wLength
= len
;
1516 /* set bData value */
1519 /* set the buffer for read / write */
1520 ven_req
.pBuff
= gpio_val
;
1522 /* set the direction */
1524 ven_req
.direction
= USB_DIR_IN
;
1525 memset(ven_req
.pBuff
, 0x00, ven_req
.wLength
);
1527 ven_req
.direction
= USB_DIR_OUT
;
1530 /* call common vendor command request */
1531 status
= cx231xx_send_vendor_cmd(dev
, &ven_req
);
1533 dev_err(dev
->dev
, "%s: failed with status -%d\n",
1539 EXPORT_SYMBOL_GPL(cx231xx_send_gpio_cmd
);
1541 /*****************************************************************
1542 * C O N T R O L - Register R E A D / W R I T E functions *
1543 *****************************************************************/
1544 int cx231xx_mode_register(struct cx231xx
*dev
, u16 address
, u32 mode
)
1546 u8 value
[4] = { 0x0, 0x0, 0x0, 0x0 };
1551 cx231xx_read_ctrl_reg(dev
, VRT_GET_REGISTER
, address
, value
, 4);
1555 tmp
= le32_to_cpu(*((__le32
*) value
));
1558 value
[0] = (u8
) tmp
;
1559 value
[1] = (u8
) (tmp
>> 8);
1560 value
[2] = (u8
) (tmp
>> 16);
1561 value
[3] = (u8
) (tmp
>> 24);
1564 cx231xx_write_ctrl_reg(dev
, VRT_SET_REGISTER
, address
, value
, 4);
1569 /*****************************************************************
1570 * I 2 C Internal C O N T R O L functions *
1571 *****************************************************************/
1572 int cx231xx_read_i2c_master(struct cx231xx
*dev
, u8 dev_addr
, u16 saddr
,
1573 u8 saddr_len
, u32
*data
, u8 data_len
, int master
)
1576 struct cx231xx_i2c_xfer_data req_data
;
1581 else if (saddr_len
== 1)
1584 /* prepare xfer_data struct */
1585 req_data
.dev_addr
= dev_addr
>> 1;
1586 req_data
.direction
= I2C_M_RD
;
1587 req_data
.saddr_len
= saddr_len
;
1588 req_data
.saddr_dat
= saddr
;
1589 req_data
.buf_size
= data_len
;
1590 req_data
.p_buffer
= (u8
*) value
;
1592 /* usb send command */
1594 status
= dev
->cx231xx_send_usb_command(&dev
->i2c_bus
[0],
1596 else if (master
== 1)
1597 status
= dev
->cx231xx_send_usb_command(&dev
->i2c_bus
[1],
1599 else if (master
== 2)
1600 status
= dev
->cx231xx_send_usb_command(&dev
->i2c_bus
[2],
1604 /* Copy the data read back to main buffer */
1607 else if (data_len
== 4)
1609 value
[0] | value
[1] << 8 | value
[2] << 16 | value
[3]
1611 else if (data_len
> 4)
1612 *data
= value
[saddr
];
1618 int cx231xx_write_i2c_master(struct cx231xx
*dev
, u8 dev_addr
, u16 saddr
,
1619 u8 saddr_len
, u32 data
, u8 data_len
, int master
)
1622 u8 value
[4] = { 0, 0, 0, 0 };
1623 struct cx231xx_i2c_xfer_data req_data
;
1625 value
[0] = (u8
) data
;
1626 value
[1] = (u8
) (data
>> 8);
1627 value
[2] = (u8
) (data
>> 16);
1628 value
[3] = (u8
) (data
>> 24);
1632 else if (saddr_len
== 1)
1635 /* prepare xfer_data struct */
1636 req_data
.dev_addr
= dev_addr
>> 1;
1637 req_data
.direction
= 0;
1638 req_data
.saddr_len
= saddr_len
;
1639 req_data
.saddr_dat
= saddr
;
1640 req_data
.buf_size
= data_len
;
1641 req_data
.p_buffer
= value
;
1643 /* usb send command */
1645 status
= dev
->cx231xx_send_usb_command(&dev
->i2c_bus
[0],
1647 else if (master
== 1)
1648 status
= dev
->cx231xx_send_usb_command(&dev
->i2c_bus
[1],
1650 else if (master
== 2)
1651 status
= dev
->cx231xx_send_usb_command(&dev
->i2c_bus
[2],
1657 int cx231xx_read_i2c_data(struct cx231xx
*dev
, u8 dev_addr
, u16 saddr
,
1658 u8 saddr_len
, u32
*data
, u8 data_len
)
1661 struct cx231xx_i2c_xfer_data req_data
;
1662 u8 value
[4] = { 0, 0, 0, 0 };
1666 else if (saddr_len
== 1)
1669 /* prepare xfer_data struct */
1670 req_data
.dev_addr
= dev_addr
>> 1;
1671 req_data
.direction
= I2C_M_RD
;
1672 req_data
.saddr_len
= saddr_len
;
1673 req_data
.saddr_dat
= saddr
;
1674 req_data
.buf_size
= data_len
;
1675 req_data
.p_buffer
= (u8
*) value
;
1677 /* usb send command */
1678 status
= dev
->cx231xx_send_usb_command(&dev
->i2c_bus
[0], &req_data
);
1681 /* Copy the data read back to main buffer */
1686 value
[0] | value
[1] << 8 | value
[2] << 16 | value
[3]
1693 int cx231xx_write_i2c_data(struct cx231xx
*dev
, u8 dev_addr
, u16 saddr
,
1694 u8 saddr_len
, u32 data
, u8 data_len
)
1697 u8 value
[4] = { 0, 0, 0, 0 };
1698 struct cx231xx_i2c_xfer_data req_data
;
1700 value
[0] = (u8
) data
;
1701 value
[1] = (u8
) (data
>> 8);
1702 value
[2] = (u8
) (data
>> 16);
1703 value
[3] = (u8
) (data
>> 24);
1707 else if (saddr_len
== 1)
1710 /* prepare xfer_data struct */
1711 req_data
.dev_addr
= dev_addr
>> 1;
1712 req_data
.direction
= 0;
1713 req_data
.saddr_len
= saddr_len
;
1714 req_data
.saddr_dat
= saddr
;
1715 req_data
.buf_size
= data_len
;
1716 req_data
.p_buffer
= value
;
1718 /* usb send command */
1719 status
= dev
->cx231xx_send_usb_command(&dev
->i2c_bus
[0], &req_data
);
1724 int cx231xx_reg_mask_write(struct cx231xx
*dev
, u8 dev_addr
, u8 size
,
1725 u16 register_address
, u8 bit_start
, u8 bit_end
,
1733 if (bit_start
> (size
- 1) || bit_end
> (size
- 1))
1738 cx231xx_read_i2c_data(dev
, dev_addr
, register_address
, 2,
1742 cx231xx_read_i2c_data(dev
, dev_addr
, register_address
, 2,
1749 mask
= 1 << bit_end
;
1750 for (i
= bit_end
; i
> bit_start
&& i
> 0; i
--)
1751 mask
= mask
+ (1 << (i
- 1));
1753 value
<<= bit_start
;
1760 cx231xx_write_i2c_data(dev
, dev_addr
, register_address
, 2,
1766 cx231xx_write_i2c_data(dev
, dev_addr
, register_address
, 2,
1773 int cx231xx_read_modify_write_i2c_dword(struct cx231xx
*dev
, u8 dev_addr
,
1774 u16 saddr
, u32 mask
, u32 value
)
1779 status
= cx231xx_read_i2c_data(dev
, dev_addr
, saddr
, 2, &temp
, 4);
1787 status
= cx231xx_write_i2c_data(dev
, dev_addr
, saddr
, 2, temp
, 4);
1792 u32
cx231xx_set_field(u32 field_mask
, u32 data
)
1796 for (temp
= field_mask
; (temp
& 1) == 0; temp
>>= 1)