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.
23 #include <linux/init.h>
24 #include <linux/list.h>
25 #include <linux/module.h>
26 #include <linux/slab.h>
27 #include <linux/usb.h>
28 #include <linux/vmalloc.h>
29 #include <media/v4l2-common.h>
30 #include <media/tuner.h>
33 #include "cx231xx-reg.h"
35 /* #define ENABLE_DEBUG_ISOC_FRAMES */
37 static unsigned int core_debug
;
38 module_param(core_debug
, int, 0644);
39 MODULE_PARM_DESC(core_debug
, "enable debug messages [core]");
41 #define cx231xx_coredbg(fmt, arg...) do {\
43 printk(KERN_INFO "%s %s :"fmt, \
44 dev->name, __func__ , ##arg); } while (0)
46 static unsigned int reg_debug
;
47 module_param(reg_debug
, int, 0644);
48 MODULE_PARM_DESC(reg_debug
, "enable debug messages [URB reg]");
50 static int alt
= CX231XX_PINOUT
;
51 module_param(alt
, int, 0644);
52 MODULE_PARM_DESC(alt
, "alternate setting to use for video endpoint");
54 #define cx231xx_isocdbg(fmt, arg...) do {\
56 printk(KERN_INFO "%s %s :"fmt, \
57 dev->name, __func__ , ##arg); } while (0)
59 /*****************************************************************
60 * Device control list functions *
61 ******************************************************************/
63 LIST_HEAD(cx231xx_devlist
);
64 static DEFINE_MUTEX(cx231xx_devlist_mutex
);
67 * cx231xx_realease_resources()
68 * unregisters the v4l2,i2c and usb devices
69 * called when the device gets disconected or at module unload
71 void cx231xx_remove_from_devlist(struct cx231xx
*dev
)
75 if (dev
->udev
== NULL
)
78 if (atomic_read(&dev
->devlist_count
) > 0) {
79 mutex_lock(&cx231xx_devlist_mutex
);
80 list_del(&dev
->devlist
);
81 atomic_dec(&dev
->devlist_count
);
82 mutex_unlock(&cx231xx_devlist_mutex
);
86 void cx231xx_add_into_devlist(struct cx231xx
*dev
)
88 mutex_lock(&cx231xx_devlist_mutex
);
89 list_add_tail(&dev
->devlist
, &cx231xx_devlist
);
90 atomic_inc(&dev
->devlist_count
);
91 mutex_unlock(&cx231xx_devlist_mutex
);
94 static LIST_HEAD(cx231xx_extension_devlist
);
96 int cx231xx_register_extension(struct cx231xx_ops
*ops
)
98 struct cx231xx
*dev
= NULL
;
100 mutex_lock(&cx231xx_devlist_mutex
);
101 list_add_tail(&ops
->next
, &cx231xx_extension_devlist
);
102 list_for_each_entry(dev
, &cx231xx_devlist
, devlist
)
105 printk(KERN_INFO DRIVER_NAME
": %s initialized\n", ops
->name
);
106 mutex_unlock(&cx231xx_devlist_mutex
);
109 EXPORT_SYMBOL(cx231xx_register_extension
);
111 void cx231xx_unregister_extension(struct cx231xx_ops
*ops
)
113 struct cx231xx
*dev
= NULL
;
115 mutex_lock(&cx231xx_devlist_mutex
);
116 list_for_each_entry(dev
, &cx231xx_devlist
, devlist
)
120 printk(KERN_INFO DRIVER_NAME
": %s removed\n", ops
->name
);
121 list_del(&ops
->next
);
122 mutex_unlock(&cx231xx_devlist_mutex
);
124 EXPORT_SYMBOL(cx231xx_unregister_extension
);
126 void cx231xx_init_extension(struct cx231xx
*dev
)
128 struct cx231xx_ops
*ops
= NULL
;
130 mutex_lock(&cx231xx_devlist_mutex
);
131 if (!list_empty(&cx231xx_extension_devlist
)) {
132 list_for_each_entry(ops
, &cx231xx_extension_devlist
, next
) {
137 mutex_unlock(&cx231xx_devlist_mutex
);
140 void cx231xx_close_extension(struct cx231xx
*dev
)
142 struct cx231xx_ops
*ops
= NULL
;
144 mutex_lock(&cx231xx_devlist_mutex
);
145 if (!list_empty(&cx231xx_extension_devlist
)) {
146 list_for_each_entry(ops
, &cx231xx_extension_devlist
, next
) {
151 mutex_unlock(&cx231xx_devlist_mutex
);
154 /****************************************************************
155 * U S B related functions *
156 *****************************************************************/
157 int cx231xx_send_usb_command(struct cx231xx_i2c
*i2c_bus
,
158 struct cx231xx_i2c_xfer_data
*req_data
)
161 struct cx231xx
*dev
= i2c_bus
->dev
;
162 struct VENDOR_REQUEST_IN ven_req
;
169 if (dev
->state
& DEV_DISCONNECTED
)
172 /* Get the I2C period, nostop and reserve parameters */
173 _i2c_period
= i2c_bus
->i2c_period
;
174 _i2c_nostop
= i2c_bus
->i2c_nostop
;
175 _i2c_reserve
= i2c_bus
->i2c_reserve
;
177 saddr_len
= req_data
->saddr_len
;
180 if (saddr_len
== 1) /* need check saddr_len == 0 */
183 dev_addr
<< 9 | _i2c_period
<< 4 | saddr_len
<< 2 |
184 _i2c_nostop
<< 1 | I2C_SYNC
| _i2c_reserve
<< 6;
188 dev_addr
<< 9 | _i2c_period
<< 4 | saddr_len
<< 2 |
189 _i2c_nostop
<< 1 | I2C_SYNC
| _i2c_reserve
<< 6;
191 /* set channel number */
192 if (req_data
->direction
& I2C_M_RD
) {
193 /* channel number, for read,spec required channel_num +4 */
194 ven_req
.bRequest
= i2c_bus
->nr
+ 4;
196 ven_req
.bRequest
= i2c_bus
->nr
; /* channel number, */
198 /* set index value */
201 ven_req
.wIndex
= 0; /* need check */
204 ven_req
.wIndex
= (req_data
->saddr_dat
& 0xff);
207 ven_req
.wIndex
= req_data
->saddr_dat
;
211 /* set wLength value */
212 ven_req
.wLength
= req_data
->buf_size
;
214 /* set bData value */
217 /* set the direction */
218 if (req_data
->direction
) {
219 ven_req
.direction
= USB_DIR_IN
;
220 memset(req_data
->p_buffer
, 0x00, ven_req
.wLength
);
222 ven_req
.direction
= USB_DIR_OUT
;
224 /* set the buffer for read / write */
225 ven_req
.pBuff
= req_data
->p_buffer
;
228 /* call common vendor command request */
229 status
= cx231xx_send_vendor_cmd(dev
, &ven_req
);
232 ("UsbInterface::sendCommand, failed with status -%d\n",
238 EXPORT_SYMBOL_GPL(cx231xx_send_usb_command
);
241 * Sends/Receives URB control messages, assuring to use a kalloced buffer
242 * for all operations (dev->urb_buf), to avoid using stacked buffers, as
243 * they aren't safe for usage with USB, due to DMA restrictions.
244 * Also implements the debug code for control URB's.
246 static int __usb_control_msg(struct cx231xx
*dev
, unsigned int pipe
,
247 __u8 request
, __u8 requesttype
, __u16 value
, __u16 index
,
248 void *data
, __u16 size
, int timeout
)
253 printk(KERN_DEBUG
"%s: (pipe 0x%08x): "
254 "%s: %02x %02x %02x %02x %02x %02x %02x %02x ",
257 (requesttype
& USB_DIR_IN
) ? "IN" : "OUT",
260 value
& 0xff, value
>> 8,
261 index
& 0xff, index
>> 8,
262 size
& 0xff, size
>> 8);
263 if (!(requesttype
& USB_DIR_IN
)) {
264 printk(KERN_CONT
">>>");
265 for (i
= 0; i
< size
; i
++)
266 printk(KERN_CONT
" %02x",
267 ((unsigned char *)data
)[i
]);
271 /* Do the real call to usb_control_msg */
272 mutex_lock(&dev
->ctrl_urb_lock
);
273 if (!(requesttype
& USB_DIR_IN
) && size
)
274 memcpy(dev
->urb_buf
, data
, size
);
275 rc
= usb_control_msg(dev
->udev
, pipe
, request
, requesttype
, value
,
276 index
, dev
->urb_buf
, size
, timeout
);
277 if ((requesttype
& USB_DIR_IN
) && size
)
278 memcpy(data
, dev
->urb_buf
, size
);
279 mutex_unlock(&dev
->ctrl_urb_lock
);
282 if (unlikely(rc
< 0)) {
283 printk(KERN_CONT
"FAILED!\n");
287 if ((requesttype
& USB_DIR_IN
)) {
288 printk(KERN_CONT
"<<<");
289 for (i
= 0; i
< size
; i
++)
290 printk(KERN_CONT
" %02x",
291 ((unsigned char *)data
)[i
]);
293 printk(KERN_CONT
"\n");
301 * cx231xx_read_ctrl_reg()
302 * reads data from the usb device specifying bRequest and wValue
304 int cx231xx_read_ctrl_reg(struct cx231xx
*dev
, u8 req
, u16 reg
,
309 int pipe
= usb_rcvctrlpipe(dev
->udev
, 0);
311 if (dev
->state
& DEV_DISCONNECTED
)
314 if (len
> URB_MAX_CTRL_SIZE
)
319 val
= ENABLE_ONE_BYTE
;
322 val
= ENABLE_TWE_BYTE
;
325 val
= ENABLE_THREE_BYTE
;
328 val
= ENABLE_FOUR_BYTE
;
331 val
= 0xFF; /* invalid option */
337 ret
= __usb_control_msg(dev
, pipe
, req
,
338 USB_DIR_IN
| USB_TYPE_VENDOR
| USB_RECIP_DEVICE
,
339 val
, reg
, buf
, len
, HZ
);
343 int cx231xx_send_vendor_cmd(struct cx231xx
*dev
,
344 struct VENDOR_REQUEST_IN
*ven_req
)
351 if (dev
->state
& DEV_DISCONNECTED
)
354 if ((ven_req
->wLength
> URB_MAX_CTRL_SIZE
))
357 if (ven_req
->direction
)
358 pipe
= usb_rcvctrlpipe(dev
->udev
, 0);
360 pipe
= usb_sndctrlpipe(dev
->udev
, 0);
363 * If the cx23102 read more than 4 bytes with i2c bus,
364 * need chop to 4 byte per request
366 if ((ven_req
->wLength
> 4) && ((ven_req
->bRequest
== 0x4) ||
367 (ven_req
->bRequest
== 0x5) ||
368 (ven_req
->bRequest
== 0x6))) {
370 pdata
= ven_req
->pBuff
;
373 unsend_size
= ven_req
->wLength
;
375 /* the first package */
376 ven_req
->wValue
= ven_req
->wValue
& 0xFFFB;
377 ven_req
->wValue
= (ven_req
->wValue
& 0xFFBD) | 0x2;
378 ret
= __usb_control_msg(dev
, pipe
, ven_req
->bRequest
,
379 ven_req
->direction
| USB_TYPE_VENDOR
| USB_RECIP_DEVICE
,
380 ven_req
->wValue
, ven_req
->wIndex
, pdata
,
382 unsend_size
= unsend_size
- 4;
384 /* the middle package */
385 ven_req
->wValue
= (ven_req
->wValue
& 0xFFBD) | 0x42;
386 while (unsend_size
- 4 > 0) {
388 ret
= __usb_control_msg(dev
, pipe
,
390 ven_req
->direction
| USB_TYPE_VENDOR
| USB_RECIP_DEVICE
,
391 ven_req
->wValue
, ven_req
->wIndex
, pdata
,
393 unsend_size
= unsend_size
- 4;
396 /* the last package */
397 ven_req
->wValue
= (ven_req
->wValue
& 0xFFBD) | 0x40;
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
, pdata
,
404 ret
= __usb_control_msg(dev
, pipe
, ven_req
->bRequest
,
405 ven_req
->direction
| USB_TYPE_VENDOR
| USB_RECIP_DEVICE
,
406 ven_req
->wValue
, ven_req
->wIndex
,
407 ven_req
->pBuff
, ven_req
->wLength
, HZ
);
414 * cx231xx_write_ctrl_reg()
415 * sends data to the usb device, specifying bRequest
417 int cx231xx_write_ctrl_reg(struct cx231xx
*dev
, u8 req
, u16 reg
, char *buf
,
422 int pipe
= usb_sndctrlpipe(dev
->udev
, 0);
424 if (dev
->state
& DEV_DISCONNECTED
)
427 if ((len
< 1) || (len
> URB_MAX_CTRL_SIZE
))
432 val
= ENABLE_ONE_BYTE
;
435 val
= ENABLE_TWE_BYTE
;
438 val
= ENABLE_THREE_BYTE
;
441 val
= ENABLE_FOUR_BYTE
;
444 val
= 0xFF; /* invalid option */
453 cx231xx_isocdbg("(pipe 0x%08x): "
454 "OUT: %02x %02x %02x %02x %02x %02x %02x %02x >>>",
456 USB_DIR_OUT
| USB_TYPE_VENDOR
| USB_RECIP_DEVICE
,
457 req
, 0, val
, reg
& 0xff,
458 reg
>> 8, len
& 0xff, len
>> 8);
460 for (byte
= 0; byte
< len
; byte
++)
461 cx231xx_isocdbg(" %02x", (unsigned char)buf
[byte
]);
462 cx231xx_isocdbg("\n");
465 ret
= __usb_control_msg(dev
, pipe
, req
,
466 USB_DIR_OUT
| USB_TYPE_VENDOR
| USB_RECIP_DEVICE
,
467 val
, reg
, buf
, len
, HZ
);
472 /****************************************************************
473 * USB Alternate Setting functions *
474 *****************************************************************/
476 int cx231xx_set_video_alternate(struct cx231xx
*dev
)
478 int errCode
, prev_alt
= dev
->video_mode
.alt
;
479 unsigned int min_pkt_size
= dev
->width
* 2 + 4;
480 u32 usb_interface_index
= 0;
482 /* When image size is bigger than a certain value,
483 the frame size should be increased, otherwise, only
484 green screen will be received.
486 if (dev
->width
* 2 * dev
->height
> 720 * 240 * 2)
489 if (dev
->width
> 360) {
490 /* resolutions: 720,704,640 */
491 dev
->video_mode
.alt
= 3;
492 } else if (dev
->width
> 180) {
493 /* resolutions: 360,352,320,240 */
494 dev
->video_mode
.alt
= 2;
495 } else if (dev
->width
> 0) {
496 /* resolutions: 180,176,160,128,88 */
497 dev
->video_mode
.alt
= 1;
499 /* Change to alt0 BULK to release USB bandwidth */
500 dev
->video_mode
.alt
= 0;
503 if (dev
->USE_ISO
== 0)
504 dev
->video_mode
.alt
= 0;
506 cx231xx_coredbg("dev->video_mode.alt= %d\n", dev
->video_mode
.alt
);
508 /* Get the correct video interface Index */
509 usb_interface_index
=
510 dev
->current_pcb_config
.hs_config_info
[0].interface_info
.
513 if (dev
->video_mode
.alt
!= prev_alt
) {
514 cx231xx_coredbg("minimum isoc packet size: %u (alt=%d)\n",
515 min_pkt_size
, dev
->video_mode
.alt
);
517 if (dev
->video_mode
.alt_max_pkt_size
!= NULL
)
518 dev
->video_mode
.max_pkt_size
=
519 dev
->video_mode
.alt_max_pkt_size
[dev
->video_mode
.alt
];
520 cx231xx_coredbg("setting alternate %d with wMaxPacketSize=%u\n",
522 dev
->video_mode
.max_pkt_size
);
524 usb_set_interface(dev
->udev
, usb_interface_index
,
525 dev
->video_mode
.alt
);
528 ("cannot change alt number to %d (error=%i)\n",
529 dev
->video_mode
.alt
, errCode
);
536 int cx231xx_set_alt_setting(struct cx231xx
*dev
, u8 index
, u8 alt
)
539 u32 usb_interface_index
= 0;
540 u32 max_pkt_size
= 0;
544 usb_interface_index
=
545 dev
->current_pcb_config
.hs_config_info
[0].interface_info
.
547 dev
->ts1_mode
.alt
= alt
;
548 if (dev
->ts1_mode
.alt_max_pkt_size
!= NULL
)
549 max_pkt_size
= dev
->ts1_mode
.max_pkt_size
=
550 dev
->ts1_mode
.alt_max_pkt_size
[dev
->ts1_mode
.alt
];
553 usb_interface_index
=
554 dev
->current_pcb_config
.hs_config_info
[0].interface_info
.
558 usb_interface_index
=
559 dev
->current_pcb_config
.hs_config_info
[0].interface_info
.
562 if (dev
->adev
.alt_max_pkt_size
!= NULL
)
563 max_pkt_size
= dev
->adev
.max_pkt_size
=
564 dev
->adev
.alt_max_pkt_size
[dev
->adev
.alt
];
567 usb_interface_index
=
568 dev
->current_pcb_config
.hs_config_info
[0].interface_info
.
570 dev
->video_mode
.alt
= alt
;
571 if (dev
->video_mode
.alt_max_pkt_size
!= NULL
)
572 max_pkt_size
= dev
->video_mode
.max_pkt_size
=
573 dev
->video_mode
.alt_max_pkt_size
[dev
->video_mode
.
577 if (dev
->board
.no_alt_vanc
)
579 usb_interface_index
=
580 dev
->current_pcb_config
.hs_config_info
[0].interface_info
.
582 dev
->vbi_mode
.alt
= alt
;
583 if (dev
->vbi_mode
.alt_max_pkt_size
!= NULL
)
584 max_pkt_size
= dev
->vbi_mode
.max_pkt_size
=
585 dev
->vbi_mode
.alt_max_pkt_size
[dev
->vbi_mode
.alt
];
588 usb_interface_index
=
589 dev
->current_pcb_config
.hs_config_info
[0].interface_info
.
591 dev
->sliced_cc_mode
.alt
= alt
;
592 if (dev
->sliced_cc_mode
.alt_max_pkt_size
!= NULL
)
593 max_pkt_size
= dev
->sliced_cc_mode
.max_pkt_size
=
594 dev
->sliced_cc_mode
.alt_max_pkt_size
[dev
->
602 if (alt
> 0 && max_pkt_size
== 0) {
604 ("can't change interface %d alt no. to %d: Max. Pkt size = 0\n",
605 usb_interface_index
, alt
);
606 /*To workaround error number=-71 on EP0 for videograbber,
607 need add following codes.*/
608 if (dev
->board
.no_alt_vanc
)
612 cx231xx_coredbg("setting alternate %d with wMaxPacketSize=%u,"
613 "Interface = %d\n", alt
, max_pkt_size
,
614 usb_interface_index
);
616 if (usb_interface_index
> 0) {
617 status
= usb_set_interface(dev
->udev
, usb_interface_index
, alt
);
620 ("can't change interface %d alt no. to %d (err=%i)\n",
621 usb_interface_index
, alt
, status
);
628 EXPORT_SYMBOL_GPL(cx231xx_set_alt_setting
);
630 int cx231xx_gpio_set(struct cx231xx
*dev
, struct cx231xx_reg_seq
*gpio
)
637 /* Send GPIO reset sequences specified at board entry */
638 while (gpio
->sleep
>= 0) {
639 rc
= cx231xx_set_gpio_value(dev
, gpio
->bit
, gpio
->val
);
651 int cx231xx_demod_reset(struct cx231xx
*dev
)
655 u8 value
[4] = { 0, 0, 0, 0 };
657 status
= cx231xx_read_ctrl_reg(dev
, VRT_GET_REGISTER
, PWR_CTL_EN
,
660 cx231xx_coredbg("reg0x%x=0x%x 0x%x 0x%x 0x%x\n", PWR_CTL_EN
,
661 value
[0], value
[1], value
[2], value
[3]);
663 cx231xx_coredbg("Enter cx231xx_demod_reset()\n");
666 status
= cx231xx_write_ctrl_reg(dev
, VRT_SET_REGISTER
,
667 PWR_CTL_EN
, value
, 4);
671 status
= cx231xx_write_ctrl_reg(dev
, VRT_SET_REGISTER
,
672 PWR_CTL_EN
, value
, 4);
676 status
= cx231xx_write_ctrl_reg(dev
, VRT_SET_REGISTER
,
677 PWR_CTL_EN
, value
, 4);
682 status
= cx231xx_read_ctrl_reg(dev
, VRT_GET_REGISTER
, PWR_CTL_EN
,
685 cx231xx_coredbg("reg0x%x=0x%x 0x%x 0x%x 0x%x\n", PWR_CTL_EN
,
686 value
[0], value
[1], value
[2], value
[3]);
690 EXPORT_SYMBOL_GPL(cx231xx_demod_reset
);
691 int is_fw_load(struct cx231xx
*dev
)
693 return cx231xx_check_fw(dev
);
695 EXPORT_SYMBOL_GPL(is_fw_load
);
697 int cx231xx_set_mode(struct cx231xx
*dev
, enum cx231xx_mode set_mode
)
701 if (dev
->mode
== set_mode
)
704 if (set_mode
== CX231XX_SUSPEND
) {
705 /* Set the chip in power saving mode */
706 dev
->mode
= set_mode
;
709 /* Resource is locked */
710 if (dev
->mode
!= CX231XX_SUSPEND
)
713 dev
->mode
= set_mode
;
715 if (dev
->mode
== CX231XX_DIGITAL_MODE
)/* Set Digital power mode */ {
716 /* set AGC mode to Digital */
717 switch (dev
->model
) {
718 case CX231XX_BOARD_CNXT_CARRAERA
:
719 case CX231XX_BOARD_CNXT_RDE_250
:
720 case CX231XX_BOARD_CNXT_SHELBY
:
721 case CX231XX_BOARD_CNXT_RDU_250
:
722 errCode
= cx231xx_set_agc_analog_digital_mux_select(dev
, 0);
724 case CX231XX_BOARD_CNXT_RDE_253S
:
725 case CX231XX_BOARD_CNXT_RDU_253S
:
726 errCode
= cx231xx_set_agc_analog_digital_mux_select(dev
, 1);
728 case CX231XX_BOARD_HAUPPAUGE_EXETER
:
729 errCode
= cx231xx_set_power_mode(dev
,
730 POLARIS_AVMODE_DIGITAL
);
735 } else/* Set Analog Power mode */ {
736 /* set AGC mode to Analog */
737 switch (dev
->model
) {
738 case CX231XX_BOARD_CNXT_CARRAERA
:
739 case CX231XX_BOARD_CNXT_RDE_250
:
740 case CX231XX_BOARD_CNXT_SHELBY
:
741 case CX231XX_BOARD_CNXT_RDU_250
:
742 errCode
= cx231xx_set_agc_analog_digital_mux_select(dev
, 1);
744 case CX231XX_BOARD_CNXT_RDE_253S
:
745 case CX231XX_BOARD_CNXT_RDU_253S
:
746 case CX231XX_BOARD_HAUPPAUGE_EXETER
:
747 case CX231XX_BOARD_PV_PLAYTV_USB_HYBRID
:
748 case CX231XX_BOARD_HAUPPAUGE_USB2_FM_PAL
:
749 case CX231XX_BOARD_HAUPPAUGE_USB2_FM_NTSC
:
750 errCode
= cx231xx_set_agc_analog_digital_mux_select(dev
, 0);
757 return errCode
? -EINVAL
: 0;
759 EXPORT_SYMBOL_GPL(cx231xx_set_mode
);
761 int cx231xx_ep5_bulkout(struct cx231xx
*dev
, u8
*firmware
, u16 size
)
764 int actlen
, ret
= -ENOMEM
;
767 buffer
= kzalloc(4096, GFP_KERNEL
);
768 if (buffer
== NULL
) {
769 cx231xx_info("out of mem\n");
772 memcpy(&buffer
[0], firmware
, 4096);
774 ret
= usb_bulk_msg(dev
->udev
, usb_sndbulkpipe(dev
->udev
, 5),
775 buffer
, 4096, &actlen
, 2000);
778 cx231xx_info("bulk message failed: %d (%d/%d)", ret
,
781 errCode
= actlen
!= size
? -1 : 0;
787 /*****************************************************************
788 * URB Streaming functions *
789 ******************************************************************/
792 * IRQ callback, called by URB callback
794 static void cx231xx_isoc_irq_callback(struct urb
*urb
)
796 struct cx231xx_dmaqueue
*dma_q
= urb
->context
;
797 struct cx231xx_video_mode
*vmode
=
798 container_of(dma_q
, struct cx231xx_video_mode
, vidq
);
799 struct cx231xx
*dev
= container_of(vmode
, struct cx231xx
, video_mode
);
802 switch (urb
->status
) {
803 case 0: /* success */
804 case -ETIMEDOUT
: /* NAK */
806 case -ECONNRESET
: /* kill */
811 cx231xx_isocdbg("urb completition error %d.\n", urb
->status
);
815 /* Copy data from URB */
816 spin_lock(&dev
->video_mode
.slock
);
817 dev
->video_mode
.isoc_ctl
.isoc_copy(dev
, urb
);
818 spin_unlock(&dev
->video_mode
.slock
);
820 /* Reset urb buffers */
821 for (i
= 0; i
< urb
->number_of_packets
; i
++) {
822 urb
->iso_frame_desc
[i
].status
= 0;
823 urb
->iso_frame_desc
[i
].actual_length
= 0;
826 urb
->status
= usb_submit_urb(urb
, GFP_ATOMIC
);
828 cx231xx_isocdbg("urb resubmit failed (error=%i)\n",
832 /*****************************************************************
833 * URB Streaming functions *
834 ******************************************************************/
837 * IRQ callback, called by URB callback
839 static void cx231xx_bulk_irq_callback(struct urb
*urb
)
841 struct cx231xx_dmaqueue
*dma_q
= urb
->context
;
842 struct cx231xx_video_mode
*vmode
=
843 container_of(dma_q
, struct cx231xx_video_mode
, vidq
);
844 struct cx231xx
*dev
= container_of(vmode
, struct cx231xx
, video_mode
);
846 switch (urb
->status
) {
847 case 0: /* success */
848 case -ETIMEDOUT
: /* NAK */
850 case -ECONNRESET
: /* kill */
855 cx231xx_isocdbg("urb completition error %d.\n", urb
->status
);
859 /* Copy data from URB */
860 spin_lock(&dev
->video_mode
.slock
);
861 dev
->video_mode
.bulk_ctl
.bulk_copy(dev
, urb
);
862 spin_unlock(&dev
->video_mode
.slock
);
864 /* Reset urb buffers */
865 urb
->status
= usb_submit_urb(urb
, GFP_ATOMIC
);
867 cx231xx_isocdbg("urb resubmit failed (error=%i)\n",
872 * Stop and Deallocate URBs
874 void cx231xx_uninit_isoc(struct cx231xx
*dev
)
876 struct cx231xx_dmaqueue
*dma_q
= &dev
->video_mode
.vidq
;
880 cx231xx_isocdbg("cx231xx: called cx231xx_uninit_isoc\n");
882 dev
->video_mode
.isoc_ctl
.nfields
= -1;
883 for (i
= 0; i
< dev
->video_mode
.isoc_ctl
.num_bufs
; i
++) {
884 urb
= dev
->video_mode
.isoc_ctl
.urb
[i
];
886 if (!irqs_disabled())
891 if (dev
->video_mode
.isoc_ctl
.transfer_buffer
[i
]) {
892 usb_free_coherent(dev
->udev
,
893 urb
->transfer_buffer_length
,
894 dev
->video_mode
.isoc_ctl
.
899 dev
->video_mode
.isoc_ctl
.urb
[i
] = NULL
;
901 dev
->video_mode
.isoc_ctl
.transfer_buffer
[i
] = NULL
;
904 kfree(dev
->video_mode
.isoc_ctl
.urb
);
905 kfree(dev
->video_mode
.isoc_ctl
.transfer_buffer
);
906 kfree(dma_q
->p_left_data
);
908 dev
->video_mode
.isoc_ctl
.urb
= NULL
;
909 dev
->video_mode
.isoc_ctl
.transfer_buffer
= NULL
;
910 dev
->video_mode
.isoc_ctl
.num_bufs
= 0;
911 dma_q
->p_left_data
= NULL
;
913 if (dev
->mode_tv
== 0)
914 cx231xx_capture_start(dev
, 0, Raw_Video
);
916 cx231xx_capture_start(dev
, 0, TS1_serial_mode
);
920 EXPORT_SYMBOL_GPL(cx231xx_uninit_isoc
);
923 * Stop and Deallocate URBs
925 void cx231xx_uninit_bulk(struct cx231xx
*dev
)
930 cx231xx_isocdbg("cx231xx: called cx231xx_uninit_bulk\n");
932 dev
->video_mode
.bulk_ctl
.nfields
= -1;
933 for (i
= 0; i
< dev
->video_mode
.bulk_ctl
.num_bufs
; i
++) {
934 urb
= dev
->video_mode
.bulk_ctl
.urb
[i
];
936 if (!irqs_disabled())
941 if (dev
->video_mode
.bulk_ctl
.transfer_buffer
[i
]) {
942 usb_free_coherent(dev
->udev
,
943 urb
->transfer_buffer_length
,
944 dev
->video_mode
.isoc_ctl
.
949 dev
->video_mode
.bulk_ctl
.urb
[i
] = NULL
;
951 dev
->video_mode
.bulk_ctl
.transfer_buffer
[i
] = NULL
;
954 kfree(dev
->video_mode
.bulk_ctl
.urb
);
955 kfree(dev
->video_mode
.bulk_ctl
.transfer_buffer
);
957 dev
->video_mode
.bulk_ctl
.urb
= NULL
;
958 dev
->video_mode
.bulk_ctl
.transfer_buffer
= NULL
;
959 dev
->video_mode
.bulk_ctl
.num_bufs
= 0;
961 if (dev
->mode_tv
== 0)
962 cx231xx_capture_start(dev
, 0, Raw_Video
);
964 cx231xx_capture_start(dev
, 0, TS1_serial_mode
);
968 EXPORT_SYMBOL_GPL(cx231xx_uninit_bulk
);
971 * Allocate URBs and start IRQ
973 int cx231xx_init_isoc(struct cx231xx
*dev
, int max_packets
,
974 int num_bufs
, int max_pkt_size
,
975 int (*isoc_copy
) (struct cx231xx
*dev
, struct urb
*urb
))
977 struct cx231xx_dmaqueue
*dma_q
= &dev
->video_mode
.vidq
;
984 /* De-allocates all pending stuff */
985 cx231xx_uninit_isoc(dev
);
987 dma_q
->p_left_data
= kzalloc(4096, GFP_KERNEL
);
988 if (dma_q
->p_left_data
== NULL
) {
989 cx231xx_info("out of mem\n");
995 dev
->video_mode
.isoc_ctl
.isoc_copy
= isoc_copy
;
996 dev
->video_mode
.isoc_ctl
.num_bufs
= num_bufs
;
998 dma_q
->is_partial_line
= 0;
1000 dma_q
->current_field
= -1;
1001 dma_q
->field1_done
= 0;
1002 dma_q
->lines_per_field
= dev
->height
/ 2;
1003 dma_q
->bytes_left_in_line
= dev
->width
<< 1;
1004 dma_q
->lines_completed
= 0;
1005 dma_q
->mpeg_buffer_done
= 0;
1006 dma_q
->left_data_count
= 0;
1007 dma_q
->mpeg_buffer_completed
= 0;
1008 dma_q
->add_ps_package_head
= CX231XX_NEED_ADD_PS_PACKAGE_HEAD
;
1009 dma_q
->ps_head
[0] = 0x00;
1010 dma_q
->ps_head
[1] = 0x00;
1011 dma_q
->ps_head
[2] = 0x01;
1012 dma_q
->ps_head
[3] = 0xBA;
1013 for (i
= 0; i
< 8; i
++)
1014 dma_q
->partial_buf
[i
] = 0;
1016 dev
->video_mode
.isoc_ctl
.urb
=
1017 kzalloc(sizeof(void *) * num_bufs
, GFP_KERNEL
);
1018 if (!dev
->video_mode
.isoc_ctl
.urb
) {
1019 cx231xx_errdev("cannot alloc memory for usb buffers\n");
1023 dev
->video_mode
.isoc_ctl
.transfer_buffer
=
1024 kzalloc(sizeof(void *) * num_bufs
, GFP_KERNEL
);
1025 if (!dev
->video_mode
.isoc_ctl
.transfer_buffer
) {
1026 cx231xx_errdev("cannot allocate memory for usbtransfer\n");
1027 kfree(dev
->video_mode
.isoc_ctl
.urb
);
1031 dev
->video_mode
.isoc_ctl
.max_pkt_size
= max_pkt_size
;
1032 dev
->video_mode
.isoc_ctl
.buf
= NULL
;
1034 sb_size
= max_packets
* dev
->video_mode
.isoc_ctl
.max_pkt_size
;
1036 if (dev
->mode_tv
== 1)
1037 dev
->video_mode
.end_point_addr
= 0x81;
1039 dev
->video_mode
.end_point_addr
= 0x84;
1042 /* allocate urbs and transfer buffers */
1043 for (i
= 0; i
< dev
->video_mode
.isoc_ctl
.num_bufs
; i
++) {
1044 urb
= usb_alloc_urb(max_packets
, GFP_KERNEL
);
1046 cx231xx_err("cannot alloc isoc_ctl.urb %i\n", i
);
1047 cx231xx_uninit_isoc(dev
);
1050 dev
->video_mode
.isoc_ctl
.urb
[i
] = urb
;
1052 dev
->video_mode
.isoc_ctl
.transfer_buffer
[i
] =
1053 usb_alloc_coherent(dev
->udev
, sb_size
, GFP_KERNEL
,
1054 &urb
->transfer_dma
);
1055 if (!dev
->video_mode
.isoc_ctl
.transfer_buffer
[i
]) {
1056 cx231xx_err("unable to allocate %i bytes for transfer"
1059 in_interrupt() ? " while in int" : "");
1060 cx231xx_uninit_isoc(dev
);
1063 memset(dev
->video_mode
.isoc_ctl
.transfer_buffer
[i
], 0, sb_size
);
1066 usb_rcvisocpipe(dev
->udev
, dev
->video_mode
.end_point_addr
);
1068 usb_fill_int_urb(urb
, dev
->udev
, pipe
,
1069 dev
->video_mode
.isoc_ctl
.transfer_buffer
[i
],
1070 sb_size
, cx231xx_isoc_irq_callback
, dma_q
, 1);
1072 urb
->number_of_packets
= max_packets
;
1073 urb
->transfer_flags
= URB_ISO_ASAP
| URB_NO_TRANSFER_DMA_MAP
;
1076 for (j
= 0; j
< max_packets
; j
++) {
1077 urb
->iso_frame_desc
[j
].offset
= k
;
1078 urb
->iso_frame_desc
[j
].length
=
1079 dev
->video_mode
.isoc_ctl
.max_pkt_size
;
1080 k
+= dev
->video_mode
.isoc_ctl
.max_pkt_size
;
1084 init_waitqueue_head(&dma_q
->wq
);
1086 /* submit urbs and enables IRQ */
1087 for (i
= 0; i
< dev
->video_mode
.isoc_ctl
.num_bufs
; i
++) {
1088 rc
= usb_submit_urb(dev
->video_mode
.isoc_ctl
.urb
[i
],
1091 cx231xx_err("submit of urb %i failed (error=%i)\n", i
,
1093 cx231xx_uninit_isoc(dev
);
1098 if (dev
->mode_tv
== 0)
1099 cx231xx_capture_start(dev
, 1, Raw_Video
);
1101 cx231xx_capture_start(dev
, 1, TS1_serial_mode
);
1105 EXPORT_SYMBOL_GPL(cx231xx_init_isoc
);
1108 * Allocate URBs and start IRQ
1110 int cx231xx_init_bulk(struct cx231xx
*dev
, int max_packets
,
1111 int num_bufs
, int max_pkt_size
,
1112 int (*bulk_copy
) (struct cx231xx
*dev
, struct urb
*urb
))
1114 struct cx231xx_dmaqueue
*dma_q
= &dev
->video_mode
.vidq
;
1120 dev
->video_input
= dev
->video_input
> 2 ? 2 : dev
->video_input
;
1122 cx231xx_coredbg("Setting Video mux to %d\n", dev
->video_input
);
1124 video_mux(dev
, dev
->video_input
);
1126 /* De-allocates all pending stuff */
1127 cx231xx_uninit_bulk(dev
);
1129 dev
->video_mode
.bulk_ctl
.bulk_copy
= bulk_copy
;
1130 dev
->video_mode
.bulk_ctl
.num_bufs
= num_bufs
;
1132 dma_q
->is_partial_line
= 0;
1133 dma_q
->last_sav
= 0;
1134 dma_q
->current_field
= -1;
1135 dma_q
->field1_done
= 0;
1136 dma_q
->lines_per_field
= dev
->height
/ 2;
1137 dma_q
->bytes_left_in_line
= dev
->width
<< 1;
1138 dma_q
->lines_completed
= 0;
1139 dma_q
->mpeg_buffer_done
= 0;
1140 dma_q
->left_data_count
= 0;
1141 dma_q
->mpeg_buffer_completed
= 0;
1142 dma_q
->ps_head
[0] = 0x00;
1143 dma_q
->ps_head
[1] = 0x00;
1144 dma_q
->ps_head
[2] = 0x01;
1145 dma_q
->ps_head
[3] = 0xBA;
1146 for (i
= 0; i
< 8; i
++)
1147 dma_q
->partial_buf
[i
] = 0;
1149 dev
->video_mode
.bulk_ctl
.urb
=
1150 kzalloc(sizeof(void *) * num_bufs
, GFP_KERNEL
);
1151 if (!dev
->video_mode
.bulk_ctl
.urb
) {
1152 cx231xx_errdev("cannot alloc memory for usb buffers\n");
1156 dev
->video_mode
.bulk_ctl
.transfer_buffer
=
1157 kzalloc(sizeof(void *) * num_bufs
, GFP_KERNEL
);
1158 if (!dev
->video_mode
.bulk_ctl
.transfer_buffer
) {
1159 cx231xx_errdev("cannot allocate memory for usbtransfer\n");
1160 kfree(dev
->video_mode
.bulk_ctl
.urb
);
1164 dev
->video_mode
.bulk_ctl
.max_pkt_size
= max_pkt_size
;
1165 dev
->video_mode
.bulk_ctl
.buf
= NULL
;
1167 sb_size
= max_packets
* dev
->video_mode
.bulk_ctl
.max_pkt_size
;
1169 if (dev
->mode_tv
== 1)
1170 dev
->video_mode
.end_point_addr
= 0x81;
1172 dev
->video_mode
.end_point_addr
= 0x84;
1175 /* allocate urbs and transfer buffers */
1176 for (i
= 0; i
< dev
->video_mode
.bulk_ctl
.num_bufs
; i
++) {
1177 urb
= usb_alloc_urb(0, GFP_KERNEL
);
1179 cx231xx_err("cannot alloc bulk_ctl.urb %i\n", i
);
1180 cx231xx_uninit_bulk(dev
);
1183 dev
->video_mode
.bulk_ctl
.urb
[i
] = urb
;
1184 urb
->transfer_flags
= URB_NO_TRANSFER_DMA_MAP
;
1186 dev
->video_mode
.bulk_ctl
.transfer_buffer
[i
] =
1187 usb_alloc_coherent(dev
->udev
, sb_size
, GFP_KERNEL
,
1188 &urb
->transfer_dma
);
1189 if (!dev
->video_mode
.bulk_ctl
.transfer_buffer
[i
]) {
1190 cx231xx_err("unable to allocate %i bytes for transfer"
1193 in_interrupt() ? " while in int" : "");
1194 cx231xx_uninit_bulk(dev
);
1197 memset(dev
->video_mode
.bulk_ctl
.transfer_buffer
[i
], 0, sb_size
);
1199 pipe
= usb_rcvbulkpipe(dev
->udev
,
1200 dev
->video_mode
.end_point_addr
);
1201 usb_fill_bulk_urb(urb
, dev
->udev
, pipe
,
1202 dev
->video_mode
.bulk_ctl
.transfer_buffer
[i
],
1203 sb_size
, cx231xx_bulk_irq_callback
, dma_q
);
1206 init_waitqueue_head(&dma_q
->wq
);
1208 /* submit urbs and enables IRQ */
1209 for (i
= 0; i
< dev
->video_mode
.bulk_ctl
.num_bufs
; i
++) {
1210 rc
= usb_submit_urb(dev
->video_mode
.bulk_ctl
.urb
[i
],
1213 cx231xx_err("submit of urb %i failed (error=%i)\n", i
,
1215 cx231xx_uninit_bulk(dev
);
1220 if (dev
->mode_tv
== 0)
1221 cx231xx_capture_start(dev
, 1, Raw_Video
);
1223 cx231xx_capture_start(dev
, 1, TS1_serial_mode
);
1227 EXPORT_SYMBOL_GPL(cx231xx_init_bulk
);
1228 void cx231xx_stop_TS1(struct cx231xx
*dev
)
1230 u8 val
[4] = { 0, 0, 0, 0 };
1236 cx231xx_write_ctrl_reg(dev
, VRT_SET_REGISTER
,
1237 TS_MODE_REG
, val
, 4);
1243 cx231xx_write_ctrl_reg(dev
, VRT_SET_REGISTER
,
1244 TS1_CFG_REG
, val
, 4);
1246 /* EXPORT_SYMBOL_GPL(cx231xx_stop_TS1); */
1247 void cx231xx_start_TS1(struct cx231xx
*dev
)
1249 u8 val
[4] = { 0, 0, 0, 0 };
1255 cx231xx_write_ctrl_reg(dev
, VRT_SET_REGISTER
,
1256 TS_MODE_REG
, val
, 4);
1262 cx231xx_write_ctrl_reg(dev
, VRT_SET_REGISTER
,
1263 TS1_CFG_REG
, val
, 4);
1265 /* EXPORT_SYMBOL_GPL(cx231xx_start_TS1); */
1266 /*****************************************************************
1267 * Device Init/UnInit functions *
1268 ******************************************************************/
1269 int cx231xx_dev_init(struct cx231xx
*dev
)
1273 /* Initialize I2C bus */
1275 /* External Master 1 Bus */
1276 dev
->i2c_bus
[0].nr
= 0;
1277 dev
->i2c_bus
[0].dev
= dev
;
1278 dev
->i2c_bus
[0].i2c_period
= I2C_SPEED_100K
; /* 100 KHz */
1279 dev
->i2c_bus
[0].i2c_nostop
= 0;
1280 dev
->i2c_bus
[0].i2c_reserve
= 0;
1282 /* External Master 2 Bus */
1283 dev
->i2c_bus
[1].nr
= 1;
1284 dev
->i2c_bus
[1].dev
= dev
;
1285 dev
->i2c_bus
[1].i2c_period
= I2C_SPEED_100K
; /* 100 KHz */
1286 dev
->i2c_bus
[1].i2c_nostop
= 0;
1287 dev
->i2c_bus
[1].i2c_reserve
= 0;
1289 /* Internal Master 3 Bus */
1290 dev
->i2c_bus
[2].nr
= 2;
1291 dev
->i2c_bus
[2].dev
= dev
;
1292 dev
->i2c_bus
[2].i2c_period
= I2C_SPEED_100K
; /* 100kHz */
1293 dev
->i2c_bus
[2].i2c_nostop
= 0;
1294 dev
->i2c_bus
[2].i2c_reserve
= 0;
1296 /* register I2C buses */
1297 cx231xx_i2c_register(&dev
->i2c_bus
[0]);
1298 cx231xx_i2c_register(&dev
->i2c_bus
[1]);
1299 cx231xx_i2c_register(&dev
->i2c_bus
[2]);
1302 /* Note : with out calling set power mode function,
1303 afe can not be set up correctly */
1304 if (dev
->board
.external_av
) {
1305 errCode
= cx231xx_set_power_mode(dev
,
1306 POLARIS_AVMODE_ENXTERNAL_AV
);
1309 ("%s: Failed to set Power - errCode [%d]!\n",
1314 errCode
= cx231xx_set_power_mode(dev
,
1315 POLARIS_AVMODE_ANALOGT_TV
);
1318 ("%s: Failed to set Power - errCode [%d]!\n",
1324 /* reset the Tuner, if it is a Xceive tuner */
1325 if ((dev
->board
.tuner_type
== TUNER_XC5000
) ||
1326 (dev
->board
.tuner_type
== TUNER_XC2028
))
1327 cx231xx_gpio_set(dev
, dev
->board
.tuner_gpio
);
1329 /* initialize Colibri block */
1330 errCode
= cx231xx_afe_init_super_block(dev
, 0x23c);
1333 ("%s: cx231xx_afe init super block - errCode [%d]!\n",
1337 errCode
= cx231xx_afe_init_channels(dev
);
1340 ("%s: cx231xx_afe init channels - errCode [%d]!\n",
1345 /* Set DIF in By pass mode */
1346 errCode
= cx231xx_dif_set_standard(dev
, DIF_USE_BASEBAND
);
1349 ("%s: cx231xx_dif set to By pass mode - errCode [%d]!\n",
1354 /* I2S block related functions */
1355 errCode
= cx231xx_i2s_blk_initialize(dev
);
1358 ("%s: cx231xx_i2s block initialize - errCode [%d]!\n",
1363 /* init control pins */
1364 errCode
= cx231xx_init_ctrl_pin_status(dev
);
1366 cx231xx_errdev("%s: cx231xx_init ctrl pins - errCode [%d]!\n",
1371 /* set AGC mode to Analog */
1372 switch (dev
->model
) {
1373 case CX231XX_BOARD_CNXT_CARRAERA
:
1374 case CX231XX_BOARD_CNXT_RDE_250
:
1375 case CX231XX_BOARD_CNXT_SHELBY
:
1376 case CX231XX_BOARD_CNXT_RDU_250
:
1377 errCode
= cx231xx_set_agc_analog_digital_mux_select(dev
, 1);
1379 case CX231XX_BOARD_CNXT_RDE_253S
:
1380 case CX231XX_BOARD_CNXT_RDU_253S
:
1381 case CX231XX_BOARD_HAUPPAUGE_EXETER
:
1382 case CX231XX_BOARD_PV_PLAYTV_USB_HYBRID
:
1383 case CX231XX_BOARD_HAUPPAUGE_USB2_FM_PAL
:
1384 case CX231XX_BOARD_HAUPPAUGE_USB2_FM_NTSC
:
1385 errCode
= cx231xx_set_agc_analog_digital_mux_select(dev
, 0);
1392 ("%s: cx231xx_AGC mode to Analog - errCode [%d]!\n",
1397 /* set all alternate settings to zero initially */
1398 cx231xx_set_alt_setting(dev
, INDEX_VIDEO
, 0);
1399 cx231xx_set_alt_setting(dev
, INDEX_VANC
, 0);
1400 cx231xx_set_alt_setting(dev
, INDEX_HANC
, 0);
1401 if (dev
->board
.has_dvb
)
1402 cx231xx_set_alt_setting(dev
, INDEX_TS1
, 0);
1404 /* set the I2C master port to 3 on channel 1 */
1405 errCode
= cx231xx_enable_i2c_port_3(dev
, true);
1409 EXPORT_SYMBOL_GPL(cx231xx_dev_init
);
1411 void cx231xx_dev_uninit(struct cx231xx
*dev
)
1413 /* Un Initialize I2C bus */
1414 cx231xx_i2c_unregister(&dev
->i2c_bus
[2]);
1415 cx231xx_i2c_unregister(&dev
->i2c_bus
[1]);
1416 cx231xx_i2c_unregister(&dev
->i2c_bus
[0]);
1418 EXPORT_SYMBOL_GPL(cx231xx_dev_uninit
);
1420 /*****************************************************************
1421 * G P I O related functions *
1422 ******************************************************************/
1423 int cx231xx_send_gpio_cmd(struct cx231xx
*dev
, u32 gpio_bit
, u8
*gpio_val
,
1424 u8 len
, u8 request
, u8 direction
)
1427 struct VENDOR_REQUEST_IN ven_req
;
1430 ven_req
.wValue
= (u16
) (gpio_bit
>> 16 & 0xffff);
1435 ven_req
.bRequest
= VRT_GET_GPIO
; /* 0x8 gpio */
1437 ven_req
.bRequest
= VRT_SET_GPIO
; /* 0x9 gpio */
1440 ven_req
.bRequest
= VRT_GET_GPIE
; /* 0xa gpie */
1442 ven_req
.bRequest
= VRT_SET_GPIE
; /* 0xb gpie */
1445 /* set index value */
1446 ven_req
.wIndex
= (u16
) (gpio_bit
& 0xffff);
1448 /* set wLength value */
1449 ven_req
.wLength
= len
;
1451 /* set bData value */
1454 /* set the buffer for read / write */
1455 ven_req
.pBuff
= gpio_val
;
1457 /* set the direction */
1459 ven_req
.direction
= USB_DIR_IN
;
1460 memset(ven_req
.pBuff
, 0x00, ven_req
.wLength
);
1462 ven_req
.direction
= USB_DIR_OUT
;
1465 /* call common vendor command request */
1466 status
= cx231xx_send_vendor_cmd(dev
, &ven_req
);
1469 ("UsbInterface::sendCommand, failed with status -%d\n",
1475 EXPORT_SYMBOL_GPL(cx231xx_send_gpio_cmd
);
1477 /*****************************************************************
1478 * C O N T R O L - Register R E A D / W R I T E functions *
1479 *****************************************************************/
1480 int cx231xx_mode_register(struct cx231xx
*dev
, u16 address
, u32 mode
)
1482 u8 value
[4] = { 0x0, 0x0, 0x0, 0x0 };
1487 cx231xx_read_ctrl_reg(dev
, VRT_GET_REGISTER
, address
, value
, 4);
1491 tmp
= le32_to_cpu(*((u32
*) value
));
1494 value
[0] = (u8
) tmp
;
1495 value
[1] = (u8
) (tmp
>> 8);
1496 value
[2] = (u8
) (tmp
>> 16);
1497 value
[3] = (u8
) (tmp
>> 24);
1500 cx231xx_write_ctrl_reg(dev
, VRT_SET_REGISTER
, address
, value
, 4);
1505 /*****************************************************************
1506 * I 2 C Internal C O N T R O L functions *
1507 *****************************************************************/
1508 int cx231xx_read_i2c_master(struct cx231xx
*dev
, u8 dev_addr
, u16 saddr
,
1509 u8 saddr_len
, u32
*data
, u8 data_len
, int master
)
1512 struct cx231xx_i2c_xfer_data req_data
;
1517 else if (saddr_len
== 1)
1520 /* prepare xfer_data struct */
1521 req_data
.dev_addr
= dev_addr
>> 1;
1522 req_data
.direction
= I2C_M_RD
;
1523 req_data
.saddr_len
= saddr_len
;
1524 req_data
.saddr_dat
= saddr
;
1525 req_data
.buf_size
= data_len
;
1526 req_data
.p_buffer
= (u8
*) value
;
1528 /* usb send command */
1530 status
= dev
->cx231xx_send_usb_command(&dev
->i2c_bus
[0],
1532 else if (master
== 1)
1533 status
= dev
->cx231xx_send_usb_command(&dev
->i2c_bus
[1],
1535 else if (master
== 2)
1536 status
= dev
->cx231xx_send_usb_command(&dev
->i2c_bus
[2],
1540 /* Copy the data read back to main buffer */
1543 else if (data_len
== 4)
1545 value
[0] | value
[1] << 8 | value
[2] << 16 | value
[3]
1547 else if (data_len
> 4)
1548 *data
= value
[saddr
];
1554 int cx231xx_write_i2c_master(struct cx231xx
*dev
, u8 dev_addr
, u16 saddr
,
1555 u8 saddr_len
, u32 data
, u8 data_len
, int master
)
1558 u8 value
[4] = { 0, 0, 0, 0 };
1559 struct cx231xx_i2c_xfer_data req_data
;
1561 value
[0] = (u8
) data
;
1562 value
[1] = (u8
) (data
>> 8);
1563 value
[2] = (u8
) (data
>> 16);
1564 value
[3] = (u8
) (data
>> 24);
1568 else if (saddr_len
== 1)
1571 /* prepare xfer_data struct */
1572 req_data
.dev_addr
= dev_addr
>> 1;
1573 req_data
.direction
= 0;
1574 req_data
.saddr_len
= saddr_len
;
1575 req_data
.saddr_dat
= saddr
;
1576 req_data
.buf_size
= data_len
;
1577 req_data
.p_buffer
= value
;
1579 /* usb send command */
1581 status
= dev
->cx231xx_send_usb_command(&dev
->i2c_bus
[0],
1583 else if (master
== 1)
1584 status
= dev
->cx231xx_send_usb_command(&dev
->i2c_bus
[1],
1586 else if (master
== 2)
1587 status
= dev
->cx231xx_send_usb_command(&dev
->i2c_bus
[2],
1593 int cx231xx_read_i2c_data(struct cx231xx
*dev
, u8 dev_addr
, u16 saddr
,
1594 u8 saddr_len
, u32
*data
, u8 data_len
)
1597 struct cx231xx_i2c_xfer_data req_data
;
1598 u8 value
[4] = { 0, 0, 0, 0 };
1602 else if (saddr_len
== 1)
1605 /* prepare xfer_data struct */
1606 req_data
.dev_addr
= dev_addr
>> 1;
1607 req_data
.direction
= I2C_M_RD
;
1608 req_data
.saddr_len
= saddr_len
;
1609 req_data
.saddr_dat
= saddr
;
1610 req_data
.buf_size
= data_len
;
1611 req_data
.p_buffer
= (u8
*) value
;
1613 /* usb send command */
1614 status
= dev
->cx231xx_send_usb_command(&dev
->i2c_bus
[0], &req_data
);
1617 /* Copy the data read back to main buffer */
1622 value
[0] | value
[1] << 8 | value
[2] << 16 | value
[3]
1629 int cx231xx_write_i2c_data(struct cx231xx
*dev
, u8 dev_addr
, u16 saddr
,
1630 u8 saddr_len
, u32 data
, u8 data_len
)
1633 u8 value
[4] = { 0, 0, 0, 0 };
1634 struct cx231xx_i2c_xfer_data req_data
;
1636 value
[0] = (u8
) data
;
1637 value
[1] = (u8
) (data
>> 8);
1638 value
[2] = (u8
) (data
>> 16);
1639 value
[3] = (u8
) (data
>> 24);
1643 else if (saddr_len
== 1)
1646 /* prepare xfer_data struct */
1647 req_data
.dev_addr
= dev_addr
>> 1;
1648 req_data
.direction
= 0;
1649 req_data
.saddr_len
= saddr_len
;
1650 req_data
.saddr_dat
= saddr
;
1651 req_data
.buf_size
= data_len
;
1652 req_data
.p_buffer
= value
;
1654 /* usb send command */
1655 status
= dev
->cx231xx_send_usb_command(&dev
->i2c_bus
[0], &req_data
);
1660 int cx231xx_reg_mask_write(struct cx231xx
*dev
, u8 dev_addr
, u8 size
,
1661 u16 register_address
, u8 bit_start
, u8 bit_end
,
1669 if (bit_start
> (size
- 1) || bit_end
> (size
- 1))
1674 cx231xx_read_i2c_data(dev
, dev_addr
, register_address
, 2,
1678 cx231xx_read_i2c_data(dev
, dev_addr
, register_address
, 2,
1685 mask
= 1 << bit_end
;
1686 for (i
= bit_end
; i
> bit_start
&& i
> 0; i
--)
1687 mask
= mask
+ (1 << (i
- 1));
1689 value
<<= bit_start
;
1696 cx231xx_write_i2c_data(dev
, dev_addr
, register_address
, 2,
1702 cx231xx_write_i2c_data(dev
, dev_addr
, register_address
, 2,
1709 int cx231xx_read_modify_write_i2c_dword(struct cx231xx
*dev
, u8 dev_addr
,
1710 u16 saddr
, u32 mask
, u32 value
)
1715 status
= cx231xx_read_i2c_data(dev
, dev_addr
, saddr
, 2, &temp
, 4);
1723 status
= cx231xx_write_i2c_data(dev
, dev_addr
, saddr
, 2, temp
, 4);
1728 u32
cx231xx_set_field(u32 field_mask
, u32 data
)
1732 for (temp
= field_mask
; (temp
& 1) == 0; temp
>>= 1)