24 #include <linux/list.h>
25 #include <linux/module.h>
26 #include <linux/slab.h>
37 static unsigned int core_debug;
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;
54 #define cx231xx_isocdbg(fmt, arg...) do {\
56 printk(KERN_INFO "%s %s :"fmt, \
57 dev->name, __func__ , ##arg); } while (0)
94 static LIST_HEAD(cx231xx_extension_devlist);
131 if (!list_empty(&cx231xx_extension_devlist)) {
145 if (!list_empty(&cx231xx_extension_devlist)) {
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;
232 (
"UsbInterface::sendCommand, failed with status -%d\n",
246 static int __usb_control_msg(
struct cx231xx *
dev,
unsigned int pipe,
254 "%s: %02x %02x %02x %02x %02x %02x %02x %02x ",
260 value & 0xff, value >> 8,
261 index & 0xff, index >> 8,
262 size & 0xff, size >> 8);
265 for (i = 0; i <
size; i++)
267 ((
unsigned char *)data)[i]);
273 if (!(requesttype & USB_DIR_IN) && size)
276 index, dev->
urb_buf, size, timeout);
277 if ((requesttype & USB_DIR_IN) && size)
287 if ((requesttype & USB_DIR_IN)) {
289 for (i = 0; i <
size; i++)
291 ((
unsigned char *)data)[i]);
309 int pipe = usb_rcvctrlpipe(dev->
udev, 0);
337 ret = __usb_control_msg(dev, pipe, req,
339 val, reg, buf, len,
HZ);
358 pipe = usb_rcvctrlpipe(dev->
udev, 0);
360 pipe = usb_sndctrlpipe(dev->
udev, 0);
370 pdata = ven_req->
pBuff;
373 unsend_size = ven_req->
wLength;
378 ret = __usb_control_msg(dev, pipe, ven_req->
bRequest,
382 unsend_size = unsend_size - 4;
386 while (unsend_size - 4 > 0) {
388 ret = __usb_control_msg(dev, pipe,
393 unsend_size = unsend_size - 4;
399 ret = __usb_control_msg(dev, pipe, ven_req->
bRequest,
404 ret = __usb_control_msg(dev, pipe, ven_req->
bRequest,
422 int pipe = usb_sndctrlpipe(dev->
udev, 0);
454 "OUT: %02x %02x %02x %02x %02x %02x %02x %02x >>>",
457 req, 0, val, reg & 0xff,
458 reg >> 8, len & 0xff, len >> 8);
460 for (byte = 0; byte < len; byte++)
465 ret = __usb_control_msg(dev, pipe, req,
467 val, reg, buf, len,
HZ);
479 unsigned int min_pkt_size = dev->
width * 2 + 4;
480 u32 usb_interface_index = 0;
489 if (dev->
width > 360) {
492 }
else if (dev->
width > 180) {
495 }
else if (dev->
width > 0) {
509 usb_interface_index =
528 (
"cannot change alt number to %d (error=%i)\n",
539 u32 usb_interface_index = 0;
540 u32 max_pkt_size = 0;
544 usb_interface_index =
549 max_pkt_size = dev->
ts1_mode.max_pkt_size =
553 usb_interface_index =
558 usb_interface_index =
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 =
577 if (dev->
board.no_alt_vanc)
579 usb_interface_index =
584 max_pkt_size = dev->
vbi_mode.max_pkt_size =
588 usb_interface_index =
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);
608 if (dev->
board.no_alt_vanc)
613 "Interface = %d\n", alt, max_pkt_size,
614 usb_interface_index);
616 if (usb_interface_index > 0) {
620 (
"can't change interface %d alt no. to %d (err=%i)\n",
621 usb_interface_index, alt, status);
638 while (gpio->
sleep >= 0) {
655 u8 value[4] = { 0, 0, 0, 0 };
661 value[0], value[1], value[2], value[3]);
686 value[0], value[1], value[2], value[3]);
701 if (dev->
mode == set_mode)
706 dev->
mode = set_mode;
713 dev->
mode = set_mode;
717 switch (dev->
model) {
737 switch (dev->
model) {
757 return errCode ? -
EINVAL : 0;
768 if (buffer ==
NULL) {
772 memcpy(&buffer[0], firmware, 4096);
775 buffer, 4096, &actlen, 2000);
781 errCode = actlen != size ? -1 : 0;
794 static void cx231xx_isoc_irq_callback(
struct urb *
urb)
802 switch (urb->status) {
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;
839 static void cx231xx_bulk_irq_callback(
struct urb *urb)
846 switch (urb->status) {
883 for (i = 0; i < dev->
video_mode.isoc_ctl.num_bufs; i++) {
891 if (dev->
video_mode.isoc_ctl.transfer_buffer[i]) {
893 urb->transfer_buffer_length,
933 for (i = 0; i < dev->
video_mode.bulk_ctl.num_bufs; i++) {
941 if (dev->
video_mode.bulk_ctl.transfer_buffer[i]) {
943 urb->transfer_buffer_length,
974 int num_bufs,
int max_pkt_size,
975 int (*isoc_copy) (
struct cx231xx *dev,
struct urb *urb))
995 dev->
video_mode.isoc_ctl.isoc_copy = isoc_copy;
1013 for (i = 0; i < 8; i++)
1017 kzalloc(
sizeof(
void *) * num_bufs,
GFP_KERNEL);
1024 kzalloc(
sizeof(
void *) * num_bufs,
GFP_KERNEL);
1025 if (!dev->
video_mode.isoc_ctl.transfer_buffer) {
1031 dev->
video_mode.isoc_ctl.max_pkt_size = max_pkt_size;
1034 sb_size = max_packets * dev->
video_mode.isoc_ctl.max_pkt_size;
1043 for (i = 0; i < dev->
video_mode.isoc_ctl.num_bufs; i++) {
1054 &urb->transfer_dma);
1055 if (!dev->
video_mode.isoc_ctl.transfer_buffer[i]) {
1056 cx231xx_err(
"unable to allocate %i bytes for transfer"
1068 usb_fill_int_urb(urb, dev->
udev, pipe,
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 =
1087 for (i = 0; i < dev->
video_mode.isoc_ctl.num_bufs; i++) {
1091 cx231xx_err(
"submit of urb %i failed (error=%i)\n", i,
1111 int num_bufs,
int max_pkt_size,
1112 int (*bulk_copy) (
struct cx231xx *dev,
struct urb *urb))
1129 dev->
video_mode.bulk_ctl.bulk_copy = bulk_copy;
1130 dev->
video_mode.bulk_ctl.num_bufs = num_bufs;
1146 for (i = 0; i < 8; i++)
1150 kzalloc(
sizeof(
void *) * num_bufs,
GFP_KERNEL);
1157 kzalloc(
sizeof(
void *) * num_bufs,
GFP_KERNEL);
1158 if (!dev->
video_mode.bulk_ctl.transfer_buffer) {
1164 dev->
video_mode.bulk_ctl.max_pkt_size = max_pkt_size;
1167 sb_size = max_packets * dev->
video_mode.bulk_ctl.max_pkt_size;
1176 for (i = 0; i < dev->
video_mode.bulk_ctl.num_bufs; i++) {
1184 urb->transfer_flags = URB_NO_TRANSFER_DMA_MAP;
1188 &urb->transfer_dma);
1189 if (!dev->
video_mode.bulk_ctl.transfer_buffer[i]) {
1190 cx231xx_err(
"unable to allocate %i bytes for transfer"
1199 pipe = usb_rcvbulkpipe(dev->
udev,
1201 usb_fill_bulk_urb(urb, dev->
udev, pipe,
1203 sb_size, cx231xx_bulk_irq_callback, dma_q);
1209 for (i = 0; i < dev->
video_mode.bulk_ctl.num_bufs; i++) {
1213 cx231xx_err(
"submit of urb %i failed (error=%i)\n", i,
1230 u8 val[4] = { 0, 0, 0, 0 };
1249 u8 val[4] = { 0, 0, 0, 0 };
1279 dev->
i2c_bus[0].i2c_nostop = 0;
1280 dev->
i2c_bus[0].i2c_reserve = 0;
1286 dev->
i2c_bus[1].i2c_nostop = 0;
1287 dev->
i2c_bus[1].i2c_reserve = 0;
1293 dev->
i2c_bus[2].i2c_nostop = 0;
1294 dev->
i2c_bus[2].i2c_reserve = 0;
1304 if (dev->
board.external_av) {
1309 (
"%s: Failed to set Power - errCode [%d]!\n",
1318 (
"%s: Failed to set Power - errCode [%d]!\n",
1325 if ((dev->
board.tuner_type == TUNER_XC5000) ||
1326 (dev->
board.tuner_type == TUNER_XC2028))
1333 (
"%s: cx231xx_afe init super block - errCode [%d]!\n",
1340 (
"%s: cx231xx_afe init channels - errCode [%d]!\n",
1349 (
"%s: cx231xx_dif set to By pass mode - errCode [%d]!\n",
1358 (
"%s: cx231xx_i2s block initialize - errCode [%d]!\n",
1372 switch (dev->
model) {
1392 (
"%s: cx231xx_AGC mode to Analog - errCode [%d]!\n",
1401 if (dev->
board.has_dvb)
1430 ven_req.
wValue = (
u16) (gpio_bit >> 16 & 0xffff);
1446 ven_req.
wIndex = (
u16) (gpio_bit & 0xffff);
1455 ven_req.
pBuff = gpio_val;
1469 (
"UsbInterface::sendCommand, failed with status -%d\n",
1482 u8 value[4] = { 0x0, 0x0, 0x0, 0x0 };
1491 tmp = *((
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);
1517 else if (saddr_len == 1)
1532 else if (master == 1)
1535 else if (master == 2)
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];
1558 u8 value[4] = { 0, 0, 0, 0 };
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)
1583 else if (master == 1)
1586 else if (master == 2)
1598 u8 value[4] = { 0, 0, 0, 0 };
1602 else if (saddr_len == 1)
1622 value[0] | value[1] << 8 | value[2] << 16 | value[3]
1633 u8 value[4] = { 0, 0, 0, 0 };
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)
1661 u16 register_address,
u8 bit_start,
u8 bit_end,
1669 if (bit_start > (size - 1) || bit_end > (size - 1))
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;
1732 for (temp = field_mask; (temp & 1) == 0; temp >>= 1)