static inline int epu_cmd_irq(struct cx18 *cx, struct cx18_epu_work_order *order) { int ret = -1; switch (order->rpu) { case CPU: { switch (order->mb.cmd) { case CX18_EPU_DMA_DONE: ret = epu_dma_done_irq(cx, order); break; case CX18_EPU_DEBUG: ret = epu_debug_irq(cx, order); break; default: CX18_WARN("Unknown CPU to EPU mailbox command %#0x\n", order->mb.cmd); break; } break; } case APU: CX18_WARN("Unknown APU to EPU mailbox command %#0x\n", order->mb.cmd); break; default: break; } return ret; }
static void epu_cmd(struct cx18 *cx, struct cx18_epu_work_order *order) { switch (order->rpu) { case CPU: { switch (order->mb.cmd) { case CX18_EPU_DMA_DONE: epu_dma_done(cx, order); break; case CX18_EPU_DEBUG: epu_debug(cx, order); break; default: CX18_WARN("Unknown CPU to EPU mailbox command %#0x\n", order->mb.cmd); break; } break; } case APU: CX18_WARN("Unknown APU to EPU mailbox command %#0x\n", order->mb.cmd); break; default: break; } }
static void mb_ack_irq(struct cx18 *cx, struct cx18_epu_work_order *order) { struct cx18_mailbox __iomem *ack_mb; u32 ack_irq, req; switch (order->rpu) { case APU: ack_irq = IRQ_EPU_TO_APU_ACK; ack_mb = &cx->scb->apu2epu_mb; break; case CPU: ack_irq = IRQ_EPU_TO_CPU_ACK; ack_mb = &cx->scb->cpu2epu_mb; break; default: CX18_WARN("Unhandled RPU (%d) for command %x ack\n", order->rpu, order->mb.cmd); return; } req = order->mb.request; /* Don't ack if the RPU has gotten impatient and timed us out */ if (req != cx18_readl(cx, &ack_mb->request) || req == cx18_readl(cx, &ack_mb->ack)) { CX18_DEBUG_WARN("Possibly falling behind: %s self-ack'ed our " "incoming %s to EPU mailbox (sequence no. %u) " "while processing\n", rpu_str[order->rpu], rpu_str[order->rpu], req); order->flags |= CX18_F_EWO_MB_STALE_WHILE_PROC; return; } cx18_writel(cx, req, &ack_mb->ack); cx18_write_reg_expect(cx, ack_irq, SW2_INT_SET, ack_irq, ack_irq); return; }
static int cx18_setup_vbi_fmt(struct cx18 *cx, enum v4l2_mpeg_stream_vbi_fmt fmt, enum v4l2_mpeg_stream_type type) { if (!(cx->v4l2_cap & V4L2_CAP_SLICED_VBI_CAPTURE)) return -EINVAL; if (atomic_read(&cx->ana_capturing) > 0) return -EBUSY; if (fmt != V4L2_MPEG_STREAM_VBI_FMT_IVTV || !(type == V4L2_MPEG_STREAM_TYPE_MPEG2_PS || type == V4L2_MPEG_STREAM_TYPE_MPEG2_DVD || type == V4L2_MPEG_STREAM_TYPE_MPEG2_SVCD)) { /* Only IVTV fmt VBI insertion & only MPEG-2 PS type streams */ cx->vbi.insert_mpeg = V4L2_MPEG_STREAM_VBI_FMT_NONE; CX18_DEBUG_INFO("disabled insertion of sliced VBI data into " "the MPEG stream\n"); return 0; } /* Allocate sliced VBI buffers if needed. */ if (cx->vbi.sliced_mpeg_data[0] == NULL) { int i; for (i = 0; i < CX18_VBI_FRAMES; i++) { cx->vbi.sliced_mpeg_data[i] = kmalloc(CX18_SLICED_MPEG_DATA_BUFSZ, GFP_KERNEL); if (cx->vbi.sliced_mpeg_data[i] == NULL) { while (--i >= 0) { kfree(cx->vbi.sliced_mpeg_data[i]); cx->vbi.sliced_mpeg_data[i] = NULL; } cx->vbi.insert_mpeg = V4L2_MPEG_STREAM_VBI_FMT_NONE; CX18_WARN("Unable to allocate buffers for " "sliced VBI data insertion\n"); return -ENOMEM; } } } cx->vbi.insert_mpeg = fmt; CX18_DEBUG_INFO("enabled insertion of sliced VBI data into the MPEG PS," "when sliced VBI is enabled\n"); /* * If our current settings have no lines set for capture, store a valid, * default set of service lines to capture, in our current settings. */ if (cx18_get_service_set(cx->vbi.sliced_in) == 0) { if (cx->is_60hz) cx->vbi.sliced_in->service_set = V4L2_SLICED_CAPTION_525; else cx->vbi.sliced_in->service_set = V4L2_SLICED_WSS_625; cx18_expand_service_set(cx->vbi.sliced_in, cx->is_50hz); } return 0; }
static int cx18_s_stream_vbi_fmt(struct cx2341x_handler *cxhdl, u32 fmt) { struct cx18 *cx = container_of(cxhdl, struct cx18, cxhdl); int type = cxhdl->stream_type->val; if (atomic_read(&cx->ana_capturing) > 0) return -EBUSY; if (fmt != V4L2_MPEG_STREAM_VBI_FMT_IVTV || !(type == V4L2_MPEG_STREAM_TYPE_MPEG2_PS || type == V4L2_MPEG_STREAM_TYPE_MPEG2_DVD || type == V4L2_MPEG_STREAM_TYPE_MPEG2_SVCD)) { /* */ cx->vbi.insert_mpeg = V4L2_MPEG_STREAM_VBI_FMT_NONE; CX18_DEBUG_INFO("disabled insertion of sliced VBI data into " "the MPEG stream\n"); return 0; } /* */ if (cx->vbi.sliced_mpeg_data[0] == NULL) { int i; for (i = 0; i < CX18_VBI_FRAMES; i++) { cx->vbi.sliced_mpeg_data[i] = kmalloc(CX18_SLICED_MPEG_DATA_BUFSZ, GFP_KERNEL); if (cx->vbi.sliced_mpeg_data[i] == NULL) { while (--i >= 0) { kfree(cx->vbi.sliced_mpeg_data[i]); cx->vbi.sliced_mpeg_data[i] = NULL; } cx->vbi.insert_mpeg = V4L2_MPEG_STREAM_VBI_FMT_NONE; CX18_WARN("Unable to allocate buffers for " "sliced VBI data insertion\n"); return -ENOMEM; } } } cx->vbi.insert_mpeg = fmt; CX18_DEBUG_INFO("enabled insertion of sliced VBI data into the MPEG PS," "when sliced VBI is enabled\n"); /* */ if (cx18_get_service_set(cx->vbi.sliced_in) == 0) { if (cx->is_60hz) cx->vbi.sliced_in->service_set = V4L2_SLICED_CAPTION_525; else cx->vbi.sliced_in->service_set = V4L2_SLICED_WSS_625; cx18_expand_service_set(cx->vbi.sliced_in, cx->is_50hz); } return 0; }
/* This function tries to claim the stream for a specific file descriptor. If no one else is using this stream then the stream is claimed and associated VBI and IDX streams are also automatically claimed. Possible error returns: -EBUSY if someone else has claimed the stream or 0 on success. */ int cx18_claim_stream(struct cx18_open_id *id, int type) { struct cx18 *cx = id->cx; struct cx18_stream *s = &cx->streams[type]; struct cx18_stream *s_assoc; /* Nothing should ever try to directly claim the IDX stream */ if (type == CX18_ENC_STREAM_TYPE_IDX) { CX18_WARN("MPEG Index stream cannot be claimed " "directly, but something tried.\n"); return -EINVAL; } if (test_and_set_bit(CX18_F_S_CLAIMED, &s->s_flags)) { /* someone already claimed this stream */ if (s->id == id->open_id) { /* yes, this file descriptor did. So that's OK. */ return 0; } if (s->id == -1 && type == CX18_ENC_STREAM_TYPE_VBI) { /* VBI is handled already internally, now also assign the file descriptor to this stream for external reading of the stream. */ s->id = id->open_id; CX18_DEBUG_INFO("Start Read VBI\n"); return 0; } /* someone else is using this stream already */ CX18_DEBUG_INFO("Stream %d is busy\n", type); return -EBUSY; } s->id = id->open_id; /* * CX18_ENC_STREAM_TYPE_MPG needs to claim: * CX18_ENC_STREAM_TYPE_VBI, if VBI insertion is on for sliced VBI, or * CX18_ENC_STREAM_TYPE_IDX, if VBI insertion is off for sliced VBI * (We don't yet fix up MPEG Index entries for our inserted packets). * * For all other streams we're done. */ if (type != CX18_ENC_STREAM_TYPE_MPG) return 0; s_assoc = &cx->streams[CX18_ENC_STREAM_TYPE_IDX]; if (cx->vbi.insert_mpeg && !cx18_raw_vbi(cx)) s_assoc = &cx->streams[CX18_ENC_STREAM_TYPE_VBI]; else if (!cx18_stream_enabled(s_assoc)) return 0; set_bit(CX18_F_S_CLAIMED, &s_assoc->s_flags); /* mark that it is used internally */ set_bit(CX18_F_S_INTERNAL_USE, &s_assoc->s_flags); return 0; }
void cx18_api_epu_cmd_irq(struct cx18 *cx, int rpu) { struct cx18_mailbox __iomem *mb; struct cx18_mailbox *order_mb; struct cx18_epu_work_order *order; int submit; switch (rpu) { case CPU: mb = &cx->scb->cpu2epu_mb; break; case APU: mb = &cx->scb->apu2epu_mb; break; default: return; } order = alloc_epu_work_order_irq(cx); if (order == NULL) { CX18_WARN("Unable to find blank work order form to schedule " "incoming mailbox command processing\n"); return; } order->flags = 0; order->rpu = rpu; order_mb = &order->mb; /* mb->cmd and mb->args[0] through mb->args[2] */ cx18_memcpy_fromio(cx, &order_mb->cmd, &mb->cmd, 4 * sizeof(u32)); /* mb->request and mb->ack. N.B. we want to read mb->ack last */ cx18_memcpy_fromio(cx, &order_mb->request, &mb->request, 2 * sizeof(u32)); if (order_mb->request == order_mb->ack) { CX18_DEBUG_WARN("Possibly falling behind: %s self-ack'ed our " "incoming %s to EPU mailbox (sequence no. %u)" "\n", rpu_str[rpu], rpu_str[rpu], order_mb->request); if (cx18_debug & CX18_DBGFLG_WARN) dump_mb(cx, order_mb, "incoming"); order->flags = CX18_F_EWO_MB_STALE_UPON_RECEIPT; } /* * Individual EPU command processing is responsible for ack-ing * a non-stale mailbox as soon as possible */ submit = epu_cmd_irq(cx, order); if (submit > 0) { queue_work(cx->work_queue, &order->work); } }
long cx18_mb_ack(struct cx18 *cx, const struct cx18_mailbox *mb) { const struct cx18_api_info *info = find_api_info(mb->cmd); struct cx18_mailbox __iomem *ack_mb; u32 ack_irq; u8 rpu = CPU; if (info == NULL && mb->cmd) { CX18_WARN("Cannot ack unknown command %x\n", mb->cmd); return -EINVAL; } if (info) rpu = info->rpu; switch (rpu) { case HPU: ack_irq = IRQ_EPU_TO_HPU_ACK; ack_mb = &cx->scb->hpu2epu_mb; break; case APU: ack_irq = IRQ_EPU_TO_APU_ACK; ack_mb = &cx->scb->apu2epu_mb; break; case CPU: ack_irq = IRQ_EPU_TO_CPU_ACK; ack_mb = &cx->scb->cpu2epu_mb; break; default: CX18_WARN("Unknown RPU for command %x\n", mb->cmd); return -EINVAL; } cx18_setup_page(cx, SCB_OFFSET); cx18_write_sync(cx, mb->request, &ack_mb->ack); cx18_write_reg(cx, ack_irq, SW2_INT_SET); return 0; }
static int __devinit cx18_probe(struct pci_dev *dev, const struct pci_device_id *pci_id) { int retval = 0; int vbi_buf_size; u32 devtype; struct cx18 *cx; spin_lock(&cx18_cards_lock); /* Make sure we've got a place for this card */ if (cx18_cards_active == CX18_MAX_CARDS) { printk(KERN_ERR "cx18: Maximum number of cards detected (%d).\n", cx18_cards_active); spin_unlock(&cx18_cards_lock); return -ENOMEM; } cx = kzalloc(sizeof(struct cx18), GFP_ATOMIC); if (!cx) { spin_unlock(&cx18_cards_lock); return -ENOMEM; } cx18_cards[cx18_cards_active] = cx; cx->dev = dev; cx->num = cx18_cards_active++; snprintf(cx->name, sizeof(cx->name), "cx18-%d", cx->num); CX18_INFO("Initializing card #%d\n", cx->num); spin_unlock(&cx18_cards_lock); cx18_process_options(cx); if (cx->options.cardtype == -1) { retval = -ENODEV; goto err; } if (cx18_init_struct1(cx)) { retval = -ENOMEM; goto err; } CX18_DEBUG_INFO("base addr: 0x%08x\n", cx->base_addr); /* PCI Device Setup */ retval = cx18_setup_pci(cx, dev, pci_id); if (retval != 0) { if (retval == -EIO) goto free_workqueue; else if (retval == -ENXIO) goto free_mem; } /* save cx in the pci struct for later use */ pci_set_drvdata(dev, cx); /* map io memory */ CX18_DEBUG_INFO("attempting ioremap at 0x%08x len 0x%08x\n", cx->base_addr + CX18_MEM_OFFSET, CX18_MEM_SIZE); cx->enc_mem = ioremap_nocache(cx->base_addr + CX18_MEM_OFFSET, CX18_MEM_SIZE); if (!cx->enc_mem) { CX18_ERR("ioremap failed, perhaps increasing __VMALLOC_RESERVE in page.h\n"); CX18_ERR("or disabling CONFIG_HIGHMEM4G into the kernel would help\n"); retval = -ENOMEM; goto free_mem; } cx->reg_mem = cx->enc_mem + CX18_REG_OFFSET; devtype = read_reg(0xC72028); switch (devtype & 0xff000000) { case 0xff000000: CX18_INFO("cx23418 revision %08x (A)\n", devtype); break; case 0x01000000: CX18_INFO("cx23418 revision %08x (B)\n", devtype); break; default: CX18_INFO("cx23418 revision %08x (Unknown)\n", devtype); break; } cx18_init_power(cx, 1); cx18_init_memory(cx); cx->scb = (struct cx18_scb __iomem *)(cx->enc_mem + SCB_OFFSET); cx18_init_scb(cx); cx18_gpio_init(cx); /* active i2c */ CX18_DEBUG_INFO("activating i2c...\n"); if (init_cx18_i2c(cx)) { CX18_ERR("Could not initialize i2c\n"); goto free_map; } CX18_DEBUG_INFO("Active card count: %d.\n", cx18_cards_active); if (cx->card->hw_all & CX18_HW_TVEEPROM) { /* Based on the model number the cardtype may be changed. The PCI IDs are not always reliable. */ cx18_process_eeprom(cx); } if (cx->card->comment) CX18_INFO("%s", cx->card->comment); if (cx->card->v4l2_capabilities == 0) { retval = -ENODEV; goto free_i2c; } cx18_init_memory(cx); /* Register IRQ */ retval = request_irq(cx->dev->irq, cx18_irq_handler, IRQF_SHARED | IRQF_DISABLED, cx->name, (void *)cx); if (retval) { CX18_ERR("Failed to register irq %d\n", retval); goto free_i2c; } if (cx->std == 0) cx->std = V4L2_STD_NTSC_M; if (cx->options.tuner == -1) { int i; for (i = 0; i < CX18_CARD_MAX_TUNERS; i++) { if ((cx->std & cx->card->tuners[i].std) == 0) continue; cx->options.tuner = cx->card->tuners[i].tuner; break; } } /* if no tuner was found, then pick the first tuner in the card list */ if (cx->options.tuner == -1 && cx->card->tuners[0].std) { cx->std = cx->card->tuners[0].std; if (cx->std & V4L2_STD_PAL) cx->std = V4L2_STD_PAL_BG | V4L2_STD_PAL_H; else if (cx->std & V4L2_STD_NTSC) cx->std = V4L2_STD_NTSC_M; else if (cx->std & V4L2_STD_SECAM) cx->std = V4L2_STD_SECAM_L; cx->options.tuner = cx->card->tuners[0].tuner; } if (cx->options.radio == -1) cx->options.radio = (cx->card->radio_input.audio_type != 0); /* The card is now fully identified, continue with card-specific initialization. */ cx18_init_struct2(cx); cx18_load_and_init_modules(cx); if (cx->std & V4L2_STD_525_60) { cx->is_60hz = 1; cx->is_out_60hz = 1; } else { cx->is_50hz = 1; cx->is_out_50hz = 1; } cx->params.video_gop_size = cx->is_60hz ? 15 : 12; cx->stream_buf_size[CX18_ENC_STREAM_TYPE_MPG] = 0x08000; cx->stream_buf_size[CX18_ENC_STREAM_TYPE_TS] = 0x08000; cx->stream_buf_size[CX18_ENC_STREAM_TYPE_PCM] = 0x01200; cx->stream_buf_size[CX18_ENC_STREAM_TYPE_YUV] = 0x20000; vbi_buf_size = cx->vbi.raw_size * (cx->is_60hz ? 24 : 36) / 2; cx->stream_buf_size[CX18_ENC_STREAM_TYPE_VBI] = vbi_buf_size; if (cx->options.radio > 0) cx->v4l2_cap |= V4L2_CAP_RADIO; if (cx->options.tuner > -1) { struct tuner_setup setup; setup.addr = ADDR_UNSET; setup.type = cx->options.tuner; setup.mode_mask = T_ANALOG_TV; /* matches TV tuners */ setup.tuner_callback = (setup.type == TUNER_XC2028) ? cx18_reset_tuner_gpio : NULL; cx18_call_i2c_clients(cx, TUNER_SET_TYPE_ADDR, &setup); if (setup.type == TUNER_XC2028) { static struct xc2028_ctrl ctrl = { .fname = XC2028_DEFAULT_FIRMWARE, .max_len = 64, }; struct v4l2_priv_tun_config cfg = { .tuner = cx->options.tuner, .priv = &ctrl, }; cx18_call_i2c_clients(cx, TUNER_SET_CONFIG, &cfg); } } /* The tuner is fixed to the standard. The other inputs (e.g. S-Video) are not. */ cx->tuner_std = cx->std; retval = cx18_streams_setup(cx); if (retval) { CX18_ERR("Error %d setting up streams\n", retval); goto free_irq; } retval = cx18_streams_register(cx); if (retval) { CX18_ERR("Error %d registering devices\n", retval); goto free_streams; } CX18_INFO("Initialized card #%d: %s\n", cx->num, cx->card_name); return 0; free_streams: cx18_streams_cleanup(cx, 1); free_irq: free_irq(cx->dev->irq, (void *)cx); free_i2c: exit_cx18_i2c(cx); free_map: cx18_iounmap(cx); free_mem: release_mem_region(cx->base_addr, CX18_MEM_SIZE); free_workqueue: err: if (retval == 0) retval = -ENODEV; CX18_ERR("Error %d on initialization\n", retval); kfree(cx18_cards[cx18_cards_active]); cx18_cards[cx18_cards_active] = NULL; return retval; } int cx18_init_on_first_open(struct cx18 *cx) { int video_input; int fw_retry_count = 3; struct v4l2_frequency vf; struct cx18_open_id fh; fh.cx = cx; if (test_bit(CX18_F_I_FAILED, &cx->i_flags)) return -ENXIO; if (test_and_set_bit(CX18_F_I_INITED, &cx->i_flags)) return 0; while (--fw_retry_count > 0) { /* load firmware */ if (cx18_firmware_init(cx) == 0) break; if (fw_retry_count > 1) CX18_WARN("Retry loading firmware\n"); } if (fw_retry_count == 0) { set_bit(CX18_F_I_FAILED, &cx->i_flags); return -ENXIO; } set_bit(CX18_F_I_LOADED_FW, &cx->i_flags); /* Init the firmware twice to work around a silicon bug * transport related. */ fw_retry_count = 3; while (--fw_retry_count > 0) { /* load firmware */ if (cx18_firmware_init(cx) == 0) break; if (fw_retry_count > 1) CX18_WARN("Retry loading firmware\n"); } if (fw_retry_count == 0) { set_bit(CX18_F_I_FAILED, &cx->i_flags); return -ENXIO; } vf.tuner = 0; vf.type = V4L2_TUNER_ANALOG_TV; vf.frequency = 6400; /* the tuner 'baseline' frequency */ /* Set initial frequency. For PAL/SECAM broadcasts no 'default' channel exists AFAIK. */ if (cx->std == V4L2_STD_NTSC_M_JP) vf.frequency = 1460; /* ch. 1 91250*16/1000 */ else if (cx->std & V4L2_STD_NTSC_M) vf.frequency = 1076; /* ch. 4 67250*16/1000 */ video_input = cx->active_input; cx->active_input++; /* Force update of input */ cx18_s_input(NULL, &fh, video_input); /* Let the VIDIOC_S_STD ioctl do all the work, keeps the code in one place. */ cx->std++; /* Force full standard initialization */ cx18_s_std(NULL, &fh, &cx->tuner_std); cx18_s_frequency(NULL, &fh, &vf); return 0; } static void cx18_remove(struct pci_dev *pci_dev) { struct cx18 *cx = pci_get_drvdata(pci_dev); CX18_DEBUG_INFO("Removing Card #%d\n", cx->num); /* Stop all captures */ CX18_DEBUG_INFO("Stopping all streams\n"); if (atomic_read(&cx->tot_capturing) > 0) cx18_stop_all_captures(cx); /* Interrupts */ sw1_irq_disable(IRQ_CPU_TO_EPU | IRQ_APU_TO_EPU); sw2_irq_disable(IRQ_CPU_TO_EPU_ACK | IRQ_APU_TO_EPU_ACK); cx18_halt_firmware(cx); cx18_streams_cleanup(cx, 1); exit_cx18_i2c(cx); free_irq(cx->dev->irq, (void *)cx); cx18_iounmap(cx); release_mem_region(cx->base_addr, CX18_MEM_SIZE); pci_disable_device(cx->dev); CX18_INFO("Removed %s, card #%d\n", cx->card_name, cx->num); } /* define a pci_driver for card detection */ static struct pci_driver cx18_pci_driver = { .name = "cx18", .id_table = cx18_pci_tbl, .probe = cx18_probe, .remove = cx18_remove, }; static int module_start(void) { printk(KERN_INFO "cx18: Start initialization, version %s\n", CX18_VERSION); memset(cx18_cards, 0, sizeof(cx18_cards)); /* Validate parameters */ if (cx18_first_minor < 0 || cx18_first_minor >= CX18_MAX_CARDS) { printk(KERN_ERR "cx18: Exiting, ivtv_first_minor must be between 0 and %d\n", CX18_MAX_CARDS - 1); return -1; } if (cx18_debug < 0 || cx18_debug > 511) { cx18_debug = 0; printk(KERN_INFO "cx18: Debug value must be >= 0 and <= 511!\n"); } if (pci_register_driver(&cx18_pci_driver)) { printk(KERN_ERR "cx18: Error detecting PCI card\n"); return -ENODEV; } printk(KERN_INFO "cx18: End initialization\n"); return 0; } static void module_cleanup(void) { int i; pci_unregister_driver(&cx18_pci_driver); for (i = 0; i < cx18_cards_active; i++) { if (cx18_cards[i] == NULL) continue; kfree(cx18_cards[i]); } }
static v4l2_std_id cx18_parse_std(struct cx18 *cx) { switch (pal[0]) { case '6': return V4L2_STD_PAL_60; case 'b': case 'B': case 'g': case 'G': return V4L2_STD_PAL_BG; case 'h': case 'H': return V4L2_STD_PAL_H; case 'n': case 'N': if (pal[1] == 'c' || pal[1] == 'C') return V4L2_STD_PAL_Nc; return V4L2_STD_PAL_N; case 'i': case 'I': return V4L2_STD_PAL_I; case 'd': case 'D': case 'k': case 'K': return V4L2_STD_PAL_DK; case 'M': case 'm': return V4L2_STD_PAL_M; case '-': break; default: CX18_WARN("pal= argument not recognised\n"); return 0; } switch (secam[0]) { case 'b': case 'B': case 'g': case 'G': case 'h': case 'H': return V4L2_STD_SECAM_B | V4L2_STD_SECAM_G | V4L2_STD_SECAM_H; case 'd': case 'D': case 'k': case 'K': return V4L2_STD_SECAM_DK; case 'l': case 'L': if (secam[1] == 'C' || secam[1] == 'c') return V4L2_STD_SECAM_LC; return V4L2_STD_SECAM_L; case '-': break; default: CX18_WARN("secam= argument not recognised\n"); return 0; } switch (ntsc[0]) { case 'm': case 'M': return V4L2_STD_NTSC_M; case 'j': case 'J': return V4L2_STD_NTSC_M_JP; case 'k': case 'K': return V4L2_STD_NTSC_M_KR; case '-': break; default: CX18_WARN("ntsc= argument not recognised\n"); return 0; } /* no match found */ return 0; }
int cx18_api_func(void *priv, u32 cmd, int in, int out, u32 data[CX2341X_MBOX_MAX_DATA]) { struct cx18_api_func_private *api_priv = priv; struct cx18 *cx = api_priv->cx; struct cx18_stream *s = api_priv->s; switch (cmd) { case CX2341X_ENC_SET_OUTPUT_PORT: return 0; case CX2341X_ENC_SET_FRAME_RATE: return cx18_vapi(cx, CX18_CPU_SET_VIDEO_IN, 6, s->handle, 0, 0, 0, 0, data[0]); case CX2341X_ENC_SET_FRAME_SIZE: return cx18_vapi(cx, CX18_CPU_SET_VIDEO_RESOLUTION, 3, s->handle, data[1], data[0]); case CX2341X_ENC_SET_STREAM_TYPE: return cx18_vapi(cx, CX18_CPU_SET_STREAM_OUTPUT_TYPE, 2, s->handle, data[0]); case CX2341X_ENC_SET_ASPECT_RATIO: return cx18_vapi(cx, CX18_CPU_SET_ASPECT_RATIO, 2, s->handle, data[0]); case CX2341X_ENC_SET_GOP_PROPERTIES: return cx18_vapi(cx, CX18_CPU_SET_GOP_STRUCTURE, 3, s->handle, data[0], data[1]); case CX2341X_ENC_SET_GOP_CLOSURE: return 0; case CX2341X_ENC_SET_AUDIO_PROPERTIES: return cx18_vapi(cx, CX18_CPU_SET_AUDIO_PARAMETERS, 2, s->handle, data[0]); case CX2341X_ENC_MUTE_AUDIO: return cx18_vapi(cx, CX18_CPU_SET_AUDIO_MUTE, 2, s->handle, data[0]); case CX2341X_ENC_SET_BIT_RATE: return cx18_vapi(cx, CX18_CPU_SET_VIDEO_RATE, 5, s->handle, data[0], data[1], data[2], data[3]); case CX2341X_ENC_MUTE_VIDEO: return cx18_vapi(cx, CX18_CPU_SET_VIDEO_MUTE, 2, s->handle, data[0]); case CX2341X_ENC_SET_FRAME_DROP_RATE: return cx18_vapi(cx, CX18_CPU_SET_SKIP_INPUT_FRAME, 2, s->handle, data[0]); case CX2341X_ENC_MISC: return cx18_vapi(cx, CX18_CPU_SET_MISC_PARAMETERS, 4, s->handle, data[0], data[1], data[2]); case CX2341X_ENC_SET_DNR_FILTER_MODE: cx->filter_mode = (data[0] & 3) | (data[1] << 2); return cx18_set_filter_param(s); case CX2341X_ENC_SET_DNR_FILTER_PROPS: cx->spatial_strength = data[0]; cx->temporal_strength = data[1]; return cx18_set_filter_param(s); case CX2341X_ENC_SET_SPATIAL_FILTER_TYPE: return cx18_vapi(cx, CX18_CPU_SET_SPATIAL_FILTER_TYPE, 3, s->handle, data[0], data[1]); case CX2341X_ENC_SET_CORING_LEVELS: return cx18_vapi(cx, CX18_CPU_SET_MEDIAN_CORING, 5, s->handle, data[0], data[1], data[2], data[3]); } CX18_WARN("Unknown cmd %x\n", cmd); return 0; }
static int cx18_api_call(struct cx18 *cx, u32 cmd, int args, u32 data[]) { const struct cx18_api_info *info = find_api_info(cmd); u32 state, irq, req, ack, err; struct cx18_mailbox __iomem *mb; u32 __iomem *xpu_state; wait_queue_head_t *waitq; struct mutex *mb_lock; long int timeout, ret; int i; char argstr[MAX_MB_ARGUMENTS*11+1]; if (info == NULL) { CX18_WARN("unknown cmd %x\n", cmd); return -EINVAL; } if (cx18_debug & CX18_DBGFLG_API) { /* only call u32arr2hex if needed */ if (cmd == CX18_CPU_DE_SET_MDL) { if (cx18_debug & CX18_DBGFLG_HIGHVOL) CX18_DEBUG_HI_API("%s\tcmd %#010x args%s\n", info->name, cmd, u32arr2hex(data, args, argstr)); } else CX18_DEBUG_API("%s\tcmd %#010x args%s\n", info->name, cmd, u32arr2hex(data, args, argstr)); } switch (info->rpu) { case APU: waitq = &cx->mb_apu_waitq; mb_lock = &cx->epu2apu_mb_lock; irq = IRQ_EPU_TO_APU; mb = &cx->scb->epu2apu_mb; xpu_state = &cx->scb->apu_state; break; case CPU: waitq = &cx->mb_cpu_waitq; mb_lock = &cx->epu2cpu_mb_lock; irq = IRQ_EPU_TO_CPU; mb = &cx->scb->epu2cpu_mb; xpu_state = &cx->scb->cpu_state; break; default: CX18_WARN("Unknown RPU (%d) for API call\n", info->rpu); return -EINVAL; } mutex_lock(mb_lock); /* * Wait for an in-use mailbox to complete * * If the XPU is responding with Ack's, the mailbox shouldn't be in * a busy state, since we serialize access to it on our end. * * If the wait for ack after sending a previous command was interrupted * by a signal, we may get here and find a busy mailbox. After waiting, * mark it "not busy" from our end, if the XPU hasn't ack'ed it still. */ state = cx18_readl(cx, xpu_state); req = cx18_readl(cx, &mb->request); timeout = msecs_to_jiffies(10); ret = wait_event_timeout(*waitq, (ack = cx18_readl(cx, &mb->ack)) == req, timeout); if (req != ack) { /* waited long enough, make the mbox "not busy" from our end */ cx18_writel(cx, req, &mb->ack); CX18_ERR("mbox was found stuck busy when setting up for %s; " "clearing busy and trying to proceed\n", info->name); } else if (ret != timeout) CX18_DEBUG_API("waited %u msecs for busy mbox to be acked\n", jiffies_to_msecs(timeout-ret)); /* Build the outgoing mailbox */ req = ((req & 0xfffffffe) == 0xfffffffe) ? 1 : req + 1; cx18_writel(cx, cmd, &mb->cmd); for (i = 0; i < args; i++) cx18_writel(cx, data[i], &mb->args[i]); cx18_writel(cx, 0, &mb->error); cx18_writel(cx, req, &mb->request); cx18_writel(cx, req - 1, &mb->ack); /* ensure ack & req are distinct */ /* * Notify the XPU and wait for it to send an Ack back */ timeout = msecs_to_jiffies((info->flags & API_FAST) ? 10 : 20); CX18_DEBUG_HI_IRQ("sending interrupt SW1: %x to send %s\n", irq, info->name); cx18_write_reg_expect(cx, irq, SW1_INT_SET, irq, irq); ret = wait_event_timeout( *waitq, cx18_readl(cx, &mb->ack) == cx18_readl(cx, &mb->request), timeout); if (ret == 0) { /* Timed out */ mutex_unlock(mb_lock); CX18_DEBUG_WARN("sending %s timed out waiting %d msecs for RPU " "acknowledgement\n", info->name, jiffies_to_msecs(timeout)); return -EINVAL; } if (ret != timeout) CX18_DEBUG_HI_API("waited %u msecs for %s to be acked\n", jiffies_to_msecs(timeout-ret), info->name); /* Collect data returned by the XPU */ for (i = 0; i < MAX_MB_ARGUMENTS; i++) data[i] = cx18_readl(cx, &mb->args[i]); err = cx18_readl(cx, &mb->error); mutex_unlock(mb_lock); /* * Wait for XPU to perform extra actions for the caller in some cases. * e.g. CX18_CPU_DE_RELEASE_MDL will cause the CPU to send all buffers * back in a burst shortly thereafter */ if (info->flags & API_SLOW) cx18_msleep_timeout(300, 0); if (err) CX18_DEBUG_API("mailbox error %08x for command %s\n", err, info->name); return err ? -EIO : 0; }
static void epu_dma_done(struct cx18 *cx, struct cx18_epu_work_order *order) { u32 handle, mdl_ack_count, id; struct cx18_mailbox *mb; struct cx18_mdl_ack *mdl_ack; struct cx18_stream *s; struct cx18_buffer *buf; int i; mb = &order->mb; handle = mb->args[0]; s = cx18_handle_to_stream(cx, handle); if (s == NULL) { CX18_WARN("Got DMA done notification for unknown/inactive" " handle %d, %s mailbox seq no %d\n", handle, (order->flags & CX18_F_EWO_MB_STALE_UPON_RECEIPT) ? "stale" : "good", mb->request); return; } mdl_ack_count = mb->args[2]; mdl_ack = order->mdl_ack; for (i = 0; i < mdl_ack_count; i++, mdl_ack++) { id = mdl_ack->id; /* * Simple integrity check for processing a stale (and possibly * inconsistent mailbox): make sure the buffer id is in the * valid range for the stream. * * We go through the trouble of dealing with stale mailboxes * because most of the time, the mailbox data is still valid and * unchanged (and in practice the firmware ping-pongs the * two mdl_ack buffers so mdl_acks are not stale). * * There are occasions when we get a half changed mailbox, * which this check catches for a handle & id mismatch. If the * handle and id do correspond, the worst case is that we * completely lost the old buffer, but pick up the new buffer * early (but the new mdl_ack is guaranteed to be good in this * case as the firmware wouldn't point us to a new mdl_ack until * it's filled in). * * cx18_queue_get buf() will detect the lost buffers * and send them back to q_free for fw rotation eventually. */ if ((order->flags & CX18_F_EWO_MB_STALE_UPON_RECEIPT) && !(id >= s->mdl_offset && id < (s->mdl_offset + s->buffers))) { CX18_WARN("Fell behind! Ignoring stale mailbox with " " inconsistent data. Lost buffer for mailbox " "seq no %d\n", mb->request); break; } buf = cx18_queue_get_buf(s, id, mdl_ack->data_used); CX18_DEBUG_HI_DMA("DMA DONE for %s (buffer %d)\n", s->name, id); if (buf == NULL) { CX18_WARN("Could not find buf %d for stream %s\n", id, s->name); /* Put as many buffers as possible back into fw use */ cx18_stream_load_fw_queue(s); continue; } if (s->type == CX18_ENC_STREAM_TYPE_TS && s->dvb.enabled) { CX18_DEBUG_HI_DMA("TS recv bytesused = %d\n", buf->bytesused); dvb_dmx_swfilter(&s->dvb.demux, buf->buf, buf->bytesused); } /* Put as many buffers as possible back into fw use */ cx18_stream_load_fw_queue(s); /* Put back TS buffer, since it was removed from all queues */ if (s->type == CX18_ENC_STREAM_TYPE_TS) cx18_stream_put_buf_fw(s, buf); } wake_up(&cx->dma_waitq); if (s->id != -1) wake_up(&s->waitq); }
static int __devinit cx18_probe(struct pci_dev *pci_dev, const struct pci_device_id *pci_id) { int retval = 0; int i; u32 devtype; struct cx18 *cx; /* FIXME - module parameter arrays constrain max instances */ i = atomic_inc_return(&cx18_instance) - 1; if (i >= CX18_MAX_CARDS) { printk(KERN_ERR "cx18: cannot manage card %d, driver has a " "limit of 0 - %d\n", i, CX18_MAX_CARDS - 1); return -ENOMEM; } cx = kzalloc(sizeof(struct cx18), GFP_ATOMIC); if (cx == NULL) { printk(KERN_ERR "cx18: cannot manage card %d, out of memory\n", i); return -ENOMEM; } cx->pci_dev = pci_dev; cx->instance = i; retval = v4l2_device_register(&pci_dev->dev, &cx->v4l2_dev); if (retval) { printk(KERN_ERR "cx18: v4l2_device_register of card %d failed" "\n", cx->instance); kfree(cx); return retval; } snprintf(cx->v4l2_dev.name, sizeof(cx->v4l2_dev.name), "cx18-%d", cx->instance); CX18_INFO("Initializing card %d\n", cx->instance); cx18_process_options(cx); if (cx->options.cardtype == -1) { retval = -ENODEV; goto err; } retval = cx18_init_struct1(cx); if (retval) goto err; CX18_DEBUG_INFO("base addr: 0x%08x\n", cx->base_addr); /* PCI Device Setup */ retval = cx18_setup_pci(cx, pci_dev, pci_id); if (retval != 0) goto free_workqueues; /* map io memory */ CX18_DEBUG_INFO("attempting ioremap at 0x%08x len 0x%08x\n", cx->base_addr + CX18_MEM_OFFSET, CX18_MEM_SIZE); cx->enc_mem = ioremap_nocache(cx->base_addr + CX18_MEM_OFFSET, CX18_MEM_SIZE); if (!cx->enc_mem) { CX18_ERR("ioremap failed. Can't get a window into CX23418 " "memory and register space\n"); CX18_ERR("Each capture card with a CX23418 needs 64 MB of " "vmalloc address space for the window\n"); CX18_ERR("Check the output of 'grep Vmalloc /proc/meminfo'\n"); CX18_ERR("Use the vmalloc= kernel command line option to set " "VmallocTotal to a larger value\n"); retval = -ENOMEM; goto free_mem; } cx->reg_mem = cx->enc_mem + CX18_REG_OFFSET; devtype = cx18_read_reg(cx, 0xC72028); switch (devtype & 0xff000000) { case 0xff000000: CX18_INFO("cx23418 revision %08x (A)\n", devtype); break; case 0x01000000: CX18_INFO("cx23418 revision %08x (B)\n", devtype); break; default: CX18_INFO("cx23418 revision %08x (Unknown)\n", devtype); break; } cx18_init_power(cx, 1); cx18_init_memory(cx); cx->scb = (struct cx18_scb __iomem *)(cx->enc_mem + SCB_OFFSET); cx18_init_scb(cx); cx18_gpio_init(cx); /* Initialize integrated A/V decoder early to set PLLs, just in case */ retval = cx18_av_probe(cx); if (retval) { CX18_ERR("Could not register A/V decoder subdevice\n"); goto free_map; } /* Initialize GPIO Reset Controller to do chip resets during i2c init */ if (cx->card->hw_all & CX18_HW_GPIO_RESET_CTRL) { if (cx18_gpio_register(cx, CX18_HW_GPIO_RESET_CTRL) != 0) CX18_WARN("Could not register GPIO reset controller" "subdevice; proceeding anyway.\n"); else cx->hw_flags |= CX18_HW_GPIO_RESET_CTRL; } /* active i2c */ CX18_DEBUG_INFO("activating i2c...\n"); retval = init_cx18_i2c(cx); if (retval) { CX18_ERR("Could not initialize i2c\n"); goto free_map; } if (cx->card->hw_all & CX18_HW_TVEEPROM) { /* Based on the model number the cardtype may be changed. The PCI IDs are not always reliable. */ const struct cx18_card *orig_card = cx->card; cx18_process_eeprom(cx); if (cx->card != orig_card) { /* Changed the cardtype; re-reset the I2C chips */ cx18_gpio_init(cx); cx18_call_hw(cx, CX18_HW_GPIO_RESET_CTRL, core, reset, (u32) CX18_GPIO_RESET_I2C); } } if (cx->card->comment) CX18_INFO("%s", cx->card->comment); if (cx->card->v4l2_capabilities == 0) { retval = -ENODEV; goto free_i2c; } cx18_init_memory(cx); cx18_init_scb(cx); /* Register IRQ */ retval = request_irq(cx->pci_dev->irq, cx18_irq_handler, IRQF_SHARED | IRQF_DISABLED, cx->v4l2_dev.name, (void *)cx); if (retval) { CX18_ERR("Failed to register irq %d\n", retval); goto free_i2c; } if (cx->std == 0) cx->std = V4L2_STD_NTSC_M; if (cx->options.tuner == -1) { for (i = 0; i < CX18_CARD_MAX_TUNERS; i++) { if ((cx->std & cx->card->tuners[i].std) == 0) continue; cx->options.tuner = cx->card->tuners[i].tuner; break; } } /* if no tuner was found, then pick the first tuner in the card list */ if (cx->options.tuner == -1 && cx->card->tuners[0].std) { cx->std = cx->card->tuners[0].std; if (cx->std & V4L2_STD_PAL) cx->std = V4L2_STD_PAL_BG | V4L2_STD_PAL_H; else if (cx->std & V4L2_STD_NTSC) cx->std = V4L2_STD_NTSC_M; else if (cx->std & V4L2_STD_SECAM) cx->std = V4L2_STD_SECAM_L; cx->options.tuner = cx->card->tuners[0].tuner; } if (cx->options.radio == -1) cx->options.radio = (cx->card->radio_input.audio_type != 0); /* The card is now fully identified, continue with card-specific initialization. */ cx18_init_struct2(cx); cx18_init_subdevs(cx); if (cx->std & V4L2_STD_525_60) cx->is_60hz = 1; else cx->is_50hz = 1; cx2341x_handler_set_50hz(&cx->cxhdl, !cx->is_60hz); if (cx->options.radio > 0) cx->v4l2_cap |= V4L2_CAP_RADIO; if (cx->options.tuner > -1) { struct tuner_setup setup; setup.addr = ADDR_UNSET; setup.type = cx->options.tuner; setup.mode_mask = T_ANALOG_TV; /* matches TV tuners */ setup.tuner_callback = (setup.type == TUNER_XC2028) ? cx18_reset_tuner_gpio : NULL; cx18_call_all(cx, tuner, s_type_addr, &setup); if (setup.type == TUNER_XC2028) { static struct xc2028_ctrl ctrl = { .fname = XC2028_DEFAULT_FIRMWARE, .max_len = 64, }; struct v4l2_priv_tun_config cfg = { .tuner = cx->options.tuner, .priv = &ctrl, }; cx18_call_all(cx, tuner, s_config, &cfg); } } /* The tuner is fixed to the standard. The other inputs (e.g. S-Video) are not. */ cx->tuner_std = cx->std; if (cx->std == V4L2_STD_ALL) cx->std = V4L2_STD_NTSC_M; retval = cx18_streams_setup(cx); if (retval) { CX18_ERR("Error %d setting up streams\n", retval); goto free_irq; } retval = cx18_streams_register(cx); if (retval) { CX18_ERR("Error %d registering devices\n", retval); goto free_streams; } CX18_INFO("Initialized card: %s\n", cx->card_name); /* Load cx18 submodules (cx18-alsa) */ request_modules(cx); return 0; free_streams: cx18_streams_cleanup(cx, 1); free_irq: free_irq(cx->pci_dev->irq, (void *)cx); free_i2c: exit_cx18_i2c(cx); free_map: cx18_iounmap(cx); free_mem: release_mem_region(cx->base_addr, CX18_MEM_SIZE); free_workqueues: destroy_workqueue(cx->in_work_queue); err: if (retval == 0) retval = -ENODEV; CX18_ERR("Error %d on initialization\n", retval); v4l2_device_unregister(&cx->v4l2_dev); kfree(cx); return retval; } int cx18_init_on_first_open(struct cx18 *cx) { int video_input; int fw_retry_count = 3; struct v4l2_frequency vf; struct cx18_open_id fh; v4l2_std_id std; fh.cx = cx; if (test_bit(CX18_F_I_FAILED, &cx->i_flags)) return -ENXIO; if (test_and_set_bit(CX18_F_I_INITED, &cx->i_flags)) return 0; while (--fw_retry_count > 0) { /* load firmware */ if (cx18_firmware_init(cx) == 0) break; if (fw_retry_count > 1) CX18_WARN("Retry loading firmware\n"); } if (fw_retry_count == 0) { set_bit(CX18_F_I_FAILED, &cx->i_flags); return -ENXIO; } set_bit(CX18_F_I_LOADED_FW, &cx->i_flags); /* * Init the firmware twice to work around a silicon bug * with the digital TS. * * The second firmware load requires us to normalize the APU state, * or the audio for the first analog capture will be badly incorrect. * * I can't seem to call APU_RESETAI and have it succeed without the * APU capturing audio, so we start and stop it here to do the reset */ /* MPEG Encoding, 224 kbps, MPEG Layer II, 48 ksps */ cx18_vapi(cx, CX18_APU_START, 2, CX18_APU_ENCODING_METHOD_MPEG|0xb9, 0); cx18_vapi(cx, CX18_APU_RESETAI, 0); cx18_vapi(cx, CX18_APU_STOP, 1, CX18_APU_ENCODING_METHOD_MPEG); fw_retry_count = 3; while (--fw_retry_count > 0) { /* load firmware */ if (cx18_firmware_init(cx) == 0) break; if (fw_retry_count > 1) CX18_WARN("Retry loading firmware\n"); } if (fw_retry_count == 0) { set_bit(CX18_F_I_FAILED, &cx->i_flags); return -ENXIO; } /* * The second firmware load requires us to normalize the APU state, * or the audio for the first analog capture will be badly incorrect. * * I can't seem to call APU_RESETAI and have it succeed without the * APU capturing audio, so we start and stop it here to do the reset */ /* MPEG Encoding, 224 kbps, MPEG Layer II, 48 ksps */ cx18_vapi(cx, CX18_APU_START, 2, CX18_APU_ENCODING_METHOD_MPEG|0xb9, 0); cx18_vapi(cx, CX18_APU_RESETAI, 0); cx18_vapi(cx, CX18_APU_STOP, 1, CX18_APU_ENCODING_METHOD_MPEG); /* Init the A/V decoder, if it hasn't been already */ v4l2_subdev_call(cx->sd_av, core, load_fw); vf.tuner = 0; vf.type = V4L2_TUNER_ANALOG_TV; vf.frequency = 6400; /* the tuner 'baseline' frequency */ /* Set initial frequency. For PAL/SECAM broadcasts no 'default' channel exists AFAIK. */ if (cx->std == V4L2_STD_NTSC_M_JP) vf.frequency = 1460; /* ch. 1 91250*16/1000 */ else if (cx->std & V4L2_STD_NTSC_M) vf.frequency = 1076; /* ch. 4 67250*16/1000 */ video_input = cx->active_input; cx->active_input++; /* Force update of input */ cx18_s_input(NULL, &fh, video_input); /* Let the VIDIOC_S_STD ioctl do all the work, keeps the code in one place. */ cx->std++; /* Force full standard initialization */ std = (cx->tuner_std == V4L2_STD_ALL) ? V4L2_STD_NTSC_M : cx->tuner_std; cx18_s_std(NULL, &fh, &std); cx18_s_frequency(NULL, &fh, &vf); return 0; } static void cx18_cancel_in_work_orders(struct cx18 *cx) { int i; for (i = 0; i < CX18_MAX_IN_WORK_ORDERS; i++) cancel_work_sync(&cx->in_work_order[i].work); }
static int cx18_api_call(struct cx18 *cx, u32 cmd, int args, u32 data[]) { const struct cx18_api_info *info = find_api_info(cmd); u32 state = 0, irq = 0, req, oldreq, err; struct cx18_mailbox __iomem *mb; wait_queue_head_t *waitq; int timeout = 100; int cnt = 0; int sig = 0; int i; if (info == NULL) { CX18_WARN("unknown cmd %x\n", cmd); return -EINVAL; } if (cmd == CX18_CPU_DE_SET_MDL) CX18_DEBUG_HI_API("%s\n", info->name); else CX18_DEBUG_API("%s\n", info->name); cx18_setup_page(cx, SCB_OFFSET); mb = cx18_mb_is_complete(cx, info->rpu, &state, &irq, &req); if (mb == NULL) { CX18_ERR("mb %s busy\n", info->name); return -EBUSY; } oldreq = req - 1; cx18_writel(cx, cmd, &mb->cmd); for (i = 0; i < args; i++) cx18_writel(cx, data[i], &mb->args[i]); cx18_writel(cx, 0, &mb->error); cx18_writel(cx, req, &mb->request); switch (info->rpu) { case APU: waitq = &cx->mb_apu_waitq; break; case CPU: waitq = &cx->mb_cpu_waitq; break; case EPU: waitq = &cx->mb_epu_waitq; break; case HPU: waitq = &cx->mb_hpu_waitq; break; default: return -EINVAL; } if (info->flags & API_FAST) timeout /= 2; cx18_write_reg(cx, irq, SW1_INT_SET); while (!sig && cx18_readl(cx, &mb->ack) != cx18_readl(cx, &mb->request) && cnt < 660) { if (cnt > 200 && !in_atomic()) sig = cx18_msleep_timeout(10, 1); cnt++; } if (sig) return -EINTR; if (cnt == 660) { cx18_writel(cx, oldreq, &mb->request); CX18_ERR("mb %s failed\n", info->name); return -EINVAL; } for (i = 0; i < MAX_MB_ARGUMENTS; i++) data[i] = cx18_readl(cx, &mb->args[i]); err = cx18_readl(cx, &mb->error); if (!in_atomic() && (info->flags & API_SLOW)) cx18_msleep_timeout(300, 0); if (err) CX18_DEBUG_API("mailbox error %08x for command %s\n", err, info->name); return err ? -EIO : 0; }
static int __devinit cx18_probe(struct pci_dev *pci_dev, const struct pci_device_id *pci_id) { int retval = 0; int i; u32 devtype; struct cx18 *cx; i = atomic_inc_return(&cx18_instance) - 1; if (i >= CX18_MAX_CARDS) { printk(KERN_ERR "cx18: cannot manage card %d, driver has a " "limit of 0 - %d\n", i, CX18_MAX_CARDS - 1); return -ENOMEM; } cx = kzalloc(sizeof(struct cx18), GFP_ATOMIC); if (cx == NULL) { printk(KERN_ERR "cx18: cannot manage card %d, out of memory\n", i); return -ENOMEM; } cx->pci_dev = pci_dev; cx->instance = i; retval = v4l2_device_register(&pci_dev->dev, &cx->v4l2_dev); if (retval) { printk(KERN_ERR "cx18: v4l2_device_register of card %d failed" "\n", cx->instance); kfree(cx); return retval; } snprintf(cx->v4l2_dev.name, sizeof(cx->v4l2_dev.name), "cx18-%d", cx->instance); CX18_INFO("Initializing card %d\n", cx->instance); cx18_process_options(cx); if (cx->options.cardtype == -1) { retval = -ENODEV; goto err; } retval = cx18_init_struct1(cx); if (retval) goto err; CX18_DEBUG_INFO("base addr: 0x%08x\n", cx->base_addr); retval = cx18_setup_pci(cx, pci_dev, pci_id); if (retval != 0) goto free_workqueues; CX18_DEBUG_INFO("attempting ioremap at 0x%08x len 0x%08x\n", cx->base_addr + CX18_MEM_OFFSET, CX18_MEM_SIZE); cx->enc_mem = ioremap_nocache(cx->base_addr + CX18_MEM_OFFSET, CX18_MEM_SIZE); if (!cx->enc_mem) { CX18_ERR("ioremap failed, perhaps increasing __VMALLOC_RESERVE in page.h\n"); CX18_ERR("or disabling CONFIG_HIGHMEM4G into the kernel would help\n"); retval = -ENOMEM; goto free_mem; } cx->reg_mem = cx->enc_mem + CX18_REG_OFFSET; devtype = cx18_read_reg(cx, 0xC72028); switch (devtype & 0xff000000) { case 0xff000000: CX18_INFO("cx23418 revision %08x (A)\n", devtype); break; case 0x01000000: CX18_INFO("cx23418 revision %08x (B)\n", devtype); break; default: CX18_INFO("cx23418 revision %08x (Unknown)\n", devtype); break; } cx18_init_power(cx, 1); cx18_init_memory(cx); cx->scb = (struct cx18_scb __iomem *)(cx->enc_mem + SCB_OFFSET); cx18_init_scb(cx); cx18_gpio_init(cx); retval = cx18_av_probe(cx); if (retval) { CX18_ERR("Could not register A/V decoder subdevice\n"); goto free_map; } cx18_call_hw(cx, CX18_HW_418_AV, core, init, 0); if (cx->card->hw_all & CX18_HW_GPIO_RESET_CTRL) { if (cx18_gpio_register(cx, CX18_HW_GPIO_RESET_CTRL) != 0) CX18_WARN("Could not register GPIO reset controller" "subdevice; proceeding anyway.\n"); else cx->hw_flags |= CX18_HW_GPIO_RESET_CTRL; } CX18_DEBUG_INFO("activating i2c...\n"); retval = init_cx18_i2c(cx); if (retval) { CX18_ERR("Could not initialize i2c\n"); goto free_map; } if (cx->card->hw_all & CX18_HW_TVEEPROM) { cx18_process_eeprom(cx); } if (cx->card->comment) CX18_INFO("%s", cx->card->comment); if (cx->card->v4l2_capabilities == 0) { retval = -ENODEV; goto free_i2c; } cx18_init_memory(cx); cx18_init_scb(cx); retval = request_irq(cx->pci_dev->irq, cx18_irq_handler, IRQF_SHARED | IRQF_DISABLED, cx->v4l2_dev.name, (void *)cx); if (retval) { CX18_ERR("Failed to register irq %d\n", retval); goto free_i2c; } if (cx->std == 0) cx->std = V4L2_STD_NTSC_M; if (cx->options.tuner == -1) { for (i = 0; i < CX18_CARD_MAX_TUNERS; i++) { if ((cx->std & cx->card->tuners[i].std) == 0) continue; cx->options.tuner = cx->card->tuners[i].tuner; break; } } if (cx->options.tuner == -1 && cx->card->tuners[0].std) { cx->std = cx->card->tuners[0].std; if (cx->std & V4L2_STD_PAL) cx->std = V4L2_STD_PAL_BG | V4L2_STD_PAL_H; else if (cx->std & V4L2_STD_NTSC) cx->std = V4L2_STD_NTSC_M; else if (cx->std & V4L2_STD_SECAM) cx->std = V4L2_STD_SECAM_L; cx->options.tuner = cx->card->tuners[0].tuner; } if (cx->options.radio == -1) cx->options.radio = (cx->card->radio_input.audio_type != 0); cx18_init_struct2(cx); cx18_init_subdevs(cx); if (cx->std & V4L2_STD_525_60) cx->is_60hz = 1; else cx->is_50hz = 1; cx->params.video_gop_size = cx->is_60hz ? 15 : 12; if (cx->options.radio > 0) cx->v4l2_cap |= V4L2_CAP_RADIO; if (cx->options.tuner > -1) { struct tuner_setup setup; setup.addr = ADDR_UNSET; setup.type = cx->options.tuner; setup.mode_mask = T_ANALOG_TV; setup.tuner_callback = (setup.type == TUNER_XC2028) ? cx18_reset_tuner_gpio : NULL; cx18_call_all(cx, tuner, s_type_addr, &setup); if (setup.type == TUNER_XC2028) { static struct xc2028_ctrl ctrl = { .fname = XC2028_DEFAULT_FIRMWARE, .max_len = 64, }; struct v4l2_priv_tun_config cfg = { .tuner = cx->options.tuner, .priv = &ctrl, }; cx18_call_all(cx, tuner, s_config, &cfg); } } cx->tuner_std = cx->std; retval = cx18_streams_setup(cx); if (retval) { CX18_ERR("Error %d setting up streams\n", retval); goto free_irq; } retval = cx18_streams_register(cx); if (retval) { CX18_ERR("Error %d registering devices\n", retval); goto free_streams; } CX18_INFO("Initialized card: %s\n", cx->card_name); return 0; free_streams: cx18_streams_cleanup(cx, 1); free_irq: free_irq(cx->pci_dev->irq, (void *)cx); free_i2c: exit_cx18_i2c(cx); free_map: cx18_iounmap(cx); free_mem: release_mem_region(cx->base_addr, CX18_MEM_SIZE); free_workqueues: destroy_workqueue(cx->in_work_queue); destroy_workqueue(cx->out_work_queue); err: if (retval == 0) retval = -ENODEV; CX18_ERR("Error %d on initialization\n", retval); v4l2_device_unregister(&cx->v4l2_dev); kfree(cx); return retval; } int cx18_init_on_first_open(struct cx18 *cx) { int video_input; int fw_retry_count = 3; struct v4l2_frequency vf; struct cx18_open_id fh; fh.cx = cx; if (test_bit(CX18_F_I_FAILED, &cx->i_flags)) return -ENXIO; if (test_and_set_bit(CX18_F_I_INITED, &cx->i_flags)) return 0; while (--fw_retry_count > 0) { if (cx18_firmware_init(cx) == 0) break; if (fw_retry_count > 1) CX18_WARN("Retry loading firmware\n"); } if (fw_retry_count == 0) { set_bit(CX18_F_I_FAILED, &cx->i_flags); return -ENXIO; } set_bit(CX18_F_I_LOADED_FW, &cx->i_flags); cx18_vapi(cx, CX18_APU_START, 2, CX18_APU_ENCODING_METHOD_MPEG|0xb9, 0); cx18_vapi(cx, CX18_APU_RESETAI, 0); cx18_vapi(cx, CX18_APU_STOP, 1, CX18_APU_ENCODING_METHOD_MPEG); fw_retry_count = 3; while (--fw_retry_count > 0) { if (cx18_firmware_init(cx) == 0) break; if (fw_retry_count > 1) CX18_WARN("Retry loading firmware\n"); } if (fw_retry_count == 0) { set_bit(CX18_F_I_FAILED, &cx->i_flags); return -ENXIO; } cx18_vapi(cx, CX18_APU_START, 2, CX18_APU_ENCODING_METHOD_MPEG|0xb9, 0); cx18_vapi(cx, CX18_APU_RESETAI, 0); cx18_vapi(cx, CX18_APU_STOP, 1, CX18_APU_ENCODING_METHOD_MPEG); v4l2_subdev_call(cx->sd_av, core, load_fw); vf.tuner = 0; vf.type = V4L2_TUNER_ANALOG_TV; vf.frequency = 6400; if (cx->std == V4L2_STD_NTSC_M_JP) vf.frequency = 1460; else if (cx->std & V4L2_STD_NTSC_M) vf.frequency = 1076; video_input = cx->active_input; cx->active_input++; cx18_s_input(NULL, &fh, video_input); cx->std++; cx18_s_std(NULL, &fh, &cx->tuner_std); cx18_s_frequency(NULL, &fh, &vf); return 0; } static void cx18_cancel_in_work_orders(struct cx18 *cx) { int i; for (i = 0; i < CX18_MAX_IN_WORK_ORDERS; i++) cancel_work_sync(&cx->in_work_order[i].work); }