diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2014-12-11 11:49:23 -0800 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2014-12-11 11:49:23 -0800 |
commit | 2183a58803c2bbd87c2d0057eed6779ec4718d4d (patch) | |
tree | 910860a2f0c1f22efe840428f11077a5bd478933 /drivers/media/pci | |
parent | e28870f9b3e92cd3570925089c6bb789c2603bc4 (diff) | |
parent | 71947828caef0c83d4245f7d1eaddc799b4ff1d1 (diff) |
Merge tag 'media/v3.19-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/mchehab/linux-media
Pull media updates from Mauro Carvalho Chehab:
- Two new dvb frontend drivers: mn88472 and mn88473
- A new driver for some PCIe DVBSky cards
- A new remote controller driver: meson-ir
- One LIRC staging driver got rewritten and promoted to mainstream:
igorplugusb
- A new tuner driver (m88rs6000t)
- The old omap2 media driver got removed from staging. This driver
uses an old DMA API and it is likely broken on recent kernels.
Nobody cared enough to fix it
- Media bus format moved to a separate header, as DRM will also use the
definitions there
- mem2mem_testdev were renamed to vim2m, in order to use the same
naming convention taken by the other virtual test driver (vivid)
- Added a new driver for coda SoC (coda-jpeg)
- The cx88 driver got converted to use videobuf2 core
- Make DMABUF export buffer to work with DMA Scatter/Gather and Vmalloc
cores
- Lots of other fixes, improvements and cleanups on the drivers.
* tag 'media/v3.19-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/mchehab/linux-media: (384 commits)
[media] mn88473: One function call less in mn88473_init() after error
[media] mn88473: Remove uneeded check before release_firmware()
[media] lirc_zilog: Deletion of unnecessary checks before vfree()
[media] MAINTAINERS: Add myself as img-ir maintainer
[media] img-ir: Don't set driver's module owner
[media] img-ir: Depend on METAG or MIPS or COMPILE_TEST
[media] img-ir/hw: Drop [un]register_decoder declarations
[media] img-ir/hw: Fix potential deadlock stopping timer
[media] img-ir/hw: Always read data to clear buffer
[media] redrat3: ensure dma is setup properly
[media] ddbridge: remove unneeded check before dvb_unregister_device()
[media] si2157: One function call less in si2157_init() after error
[media] tuners: remove uneeded checks before release_firmware()
[media] arm: omap2: rx51-peripherals: fix build warning
[media] stv090x: add an extra protetion against buffer overflow
[media] stv090x: Remove an unreachable code
[media] stv090x: Some whitespace cleanups
[media] em28xx: checkpatch cleanup: whitespaces/new lines cleanups
[media] si2168: add support for firmware files in new format
[media] si2168: debug printout for firmware version
...
Diffstat (limited to 'drivers/media/pci')
59 files changed, 3381 insertions, 1824 deletions
diff --git a/drivers/media/pci/Kconfig b/drivers/media/pci/Kconfig index f8cec8e8cf8..218144a9901 100644 --- a/drivers/media/pci/Kconfig +++ b/drivers/media/pci/Kconfig @@ -46,6 +46,7 @@ source "drivers/media/pci/pt3/Kconfig" source "drivers/media/pci/mantis/Kconfig" source "drivers/media/pci/ngene/Kconfig" source "drivers/media/pci/ddbridge/Kconfig" +source "drivers/media/pci/smipcie/Kconfig" endif endif #MEDIA_PCI_SUPPORT diff --git a/drivers/media/pci/Makefile b/drivers/media/pci/Makefile index a12926e4b51..0baf0d2967e 100644 --- a/drivers/media/pci/Makefile +++ b/drivers/media/pci/Makefile @@ -11,7 +11,8 @@ obj-y += ttpci/ \ mantis/ \ ngene/ \ ddbridge/ \ - saa7146/ + saa7146/ \ + smipcie/ obj-$(CONFIG_VIDEO_IVTV) += ivtv/ obj-$(CONFIG_VIDEO_ZORAN) += zoran/ diff --git a/drivers/media/pci/bt8xx/bttv-cards.c b/drivers/media/pci/bt8xx/bttv-cards.c index d8ec583c154..41055606b96 100644 --- a/drivers/media/pci/bt8xx/bttv-cards.c +++ b/drivers/media/pci/bt8xx/bttv-cards.c @@ -3870,10 +3870,10 @@ static void osprey_eeprom(struct bttv *btv, const u8 ee[256]) } else { unsigned short type; - for (i = 4*16; i < 8*16; i += 16) { - u16 checksum = ip_compute_csum(ee + i, 16); + for (i = 4 * 16; i < 8 * 16; i += 16) { + u16 checksum = (__force u16)ip_compute_csum(ee + i, 16); - if ((checksum&0xff) + (checksum>>8) == 0xff) + if ((checksum & 0xff) + (checksum >> 8) == 0xff) break; } if (i >= 8*16) diff --git a/drivers/media/pci/bt8xx/bttv-risc.c b/drivers/media/pci/bt8xx/bttv-risc.c index 82cc47d2e3f..4d3f05a19af 100644 --- a/drivers/media/pci/bt8xx/bttv-risc.c +++ b/drivers/media/pci/bt8xx/bttv-risc.c @@ -84,7 +84,7 @@ bttv_risc_packed(struct bttv *btv, struct btcx_riscmem *risc, continue; while (offset && offset >= sg_dma_len(sg)) { offset -= sg_dma_len(sg); - sg++; + sg = sg_next(sg); } if (bpl <= sg_dma_len(sg)-offset) { /* fits into current chunk */ @@ -100,13 +100,13 @@ bttv_risc_packed(struct bttv *btv, struct btcx_riscmem *risc, *(rp++)=cpu_to_le32(sg_dma_address(sg)+offset); todo -= (sg_dma_len(sg)-offset); offset = 0; - sg++; + sg = sg_next(sg); while (todo > sg_dma_len(sg)) { *(rp++)=cpu_to_le32(BT848_RISC_WRITE| sg_dma_len(sg)); *(rp++)=cpu_to_le32(sg_dma_address(sg)); todo -= sg_dma_len(sg); - sg++; + sg = sg_next(sg); } *(rp++)=cpu_to_le32(BT848_RISC_WRITE|BT848_RISC_EOL| todo); @@ -187,15 +187,15 @@ bttv_risc_planar(struct bttv *btv, struct btcx_riscmem *risc, /* go to next sg entry if needed */ while (yoffset && yoffset >= sg_dma_len(ysg)) { yoffset -= sg_dma_len(ysg); - ysg++; + ysg = sg_next(ysg); } while (uoffset && uoffset >= sg_dma_len(usg)) { uoffset -= sg_dma_len(usg); - usg++; + usg = sg_next(usg); } while (voffset && voffset >= sg_dma_len(vsg)) { voffset -= sg_dma_len(vsg); - vsg++; + vsg = sg_next(vsg); } /* calculate max number of bytes we can write */ diff --git a/drivers/media/pci/cx18/cx18-av-core.c b/drivers/media/pci/cx18/cx18-av-core.c index 2d3afe0431a..5a55630d09d 100644 --- a/drivers/media/pci/cx18/cx18-av-core.c +++ b/drivers/media/pci/cx18/cx18-av-core.c @@ -490,8 +490,8 @@ void cx18_av_std_setup(struct cx18 *cx) /* Sets horizontal blanking delay and active lines */ cx18_av_write(cx, 0x470, hblank); - cx18_av_write(cx, 0x471, 0xff & (((hblank >> 8) & 0x3) | - (hactive << 4))); + cx18_av_write(cx, 0x471, + (((hblank >> 8) & 0x3) | (hactive << 4)) & 0xff); cx18_av_write(cx, 0x472, hactive >> 4); /* Sets burst gate delay */ @@ -499,14 +499,14 @@ void cx18_av_std_setup(struct cx18 *cx) /* Sets vertical blanking delay and active duration */ cx18_av_write(cx, 0x474, vblank); - cx18_av_write(cx, 0x475, 0xff & (((vblank >> 8) & 0x3) | - (vactive << 4))); + cx18_av_write(cx, 0x475, + (((vblank >> 8) & 0x3) | (vactive << 4)) & 0xff); cx18_av_write(cx, 0x476, vactive >> 4); cx18_av_write(cx, 0x477, vblank656); /* Sets src decimation rate */ - cx18_av_write(cx, 0x478, 0xff & src_decimation); - cx18_av_write(cx, 0x479, 0xff & (src_decimation >> 8)); + cx18_av_write(cx, 0x478, src_decimation & 0xff); + cx18_av_write(cx, 0x479, (src_decimation >> 8) & 0xff); /* Sets Luma and UV Low pass filters */ cx18_av_write(cx, 0x47a, luma_lpf << 6 | ((uv_lpf << 4) & 0x30)); @@ -516,8 +516,8 @@ void cx18_av_std_setup(struct cx18 *cx) /* Sets SC Step*/ cx18_av_write(cx, 0x47c, sc); - cx18_av_write(cx, 0x47d, 0xff & sc >> 8); - cx18_av_write(cx, 0x47e, 0xff & sc >> 16); + cx18_av_write(cx, 0x47d, (sc >> 8) & 0xff); + cx18_av_write(cx, 0x47e, (sc >> 16) & 0xff); if (std & V4L2_STD_625_50) { state->slicer_line_delay = 1; @@ -952,7 +952,7 @@ static int cx18_av_s_mbus_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt int HSC, VSC, Vsrc, Hsrc, filter, Vlines; int is_50Hz = !(state->std & V4L2_STD_525_60); - if (fmt->code != V4L2_MBUS_FMT_FIXED) + if (fmt->code != MEDIA_BUS_FMT_FIXED) return -EINVAL; fmt->field = V4L2_FIELD_INTERLACED; diff --git a/drivers/media/pci/cx18/cx18-cards.h b/drivers/media/pci/cx18/cx18-cards.h index add7391ecab..f6b921f3b0a 100644 --- a/drivers/media/pci/cx18/cx18-cards.h +++ b/drivers/media/pci/cx18/cx18-cards.h @@ -57,7 +57,8 @@ /* V4L2 capability aliases */ #define CX18_CAP_ENCODER (V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_TUNER | \ V4L2_CAP_AUDIO | V4L2_CAP_READWRITE | \ - V4L2_CAP_VBI_CAPTURE | V4L2_CAP_SLICED_VBI_CAPTURE) + V4L2_CAP_STREAMING | V4L2_CAP_VBI_CAPTURE | \ + V4L2_CAP_SLICED_VBI_CAPTURE) struct cx18_card_video_input { u8 video_type; /* video input type */ diff --git a/drivers/media/pci/cx18/cx18-controls.c b/drivers/media/pci/cx18/cx18-controls.c index 282a3d29fda..4aeb7c6b8ce 100644 --- a/drivers/media/pci/cx18/cx18-controls.c +++ b/drivers/media/pci/cx18/cx18-controls.c @@ -98,7 +98,7 @@ static int cx18_s_video_encoding(struct cx2341x_handler *cxhdl, u32 val) /* fix videodecoder resolution */ fmt.width = cxhdl->width / (is_mpeg1 ? 2 : 1); fmt.height = cxhdl->height; - fmt.code = V4L2_MBUS_FMT_FIXED; + fmt.code = MEDIA_BUS_FMT_FIXED; v4l2_subdev_call(cx->sd_av, video, s_mbus_fmt, &fmt); return 0; } diff --git a/drivers/media/pci/cx18/cx18-driver.h b/drivers/media/pci/cx18/cx18-driver.h index 57f4688ea55..dcfd7a1d317 100644 --- a/drivers/media/pci/cx18/cx18-driver.h +++ b/drivers/media/pci/cx18/cx18-driver.h @@ -379,6 +379,7 @@ struct cx18_stream { const char *name; /* name of the stream */ int type; /* stream type */ u32 handle; /* task handle */ + u32 v4l2_dev_caps; /* device capabilities */ unsigned int mdl_base_idx; u32 id; diff --git a/drivers/media/pci/cx18/cx18-ioctl.c b/drivers/media/pci/cx18/cx18-ioctl.c index 6f2b59042b7..b8e4b68a919 100644 --- a/drivers/media/pci/cx18/cx18-ioctl.c +++ b/drivers/media/pci/cx18/cx18-ioctl.c @@ -294,7 +294,7 @@ static int cx18_s_fmt_vid_cap(struct file *file, void *fh, mbus_fmt.width = cx->cxhdl.width = w; mbus_fmt.height = cx->cxhdl.height = h; - mbus_fmt.code = V4L2_MBUS_FMT_FIXED; + mbus_fmt.code = MEDIA_BUS_FMT_FIXED; v4l2_subdev_call(cx->sd_av, video, s_mbus_fmt, &mbus_fmt); return cx18_g_fmt_vid_cap(file, fh, fmt); } @@ -393,15 +393,16 @@ static int cx18_querycap(struct file *file, void *fh, struct v4l2_capability *vcap) { struct cx18_open_id *id = fh2id(fh); + struct cx18_stream *s = video_drvdata(file); struct cx18 *cx = id->cx; strlcpy(vcap->driver, CX18_DRIVER_NAME, sizeof(vcap->driver)); strlcpy(vcap->card, cx->card_name, sizeof(vcap->card)); snprintf(vcap->bus_info, sizeof(vcap->bus_info), "PCI:%s", pci_name(cx->pci_dev)); - vcap->capabilities = cx->v4l2_cap; /* capabilities */ - if (id->type == CX18_ENC_STREAM_TYPE_YUV) - vcap->capabilities |= V4L2_CAP_STREAMING; + vcap->capabilities = cx->v4l2_cap; /* capabilities */ + vcap->device_caps = s->v4l2_dev_caps; /* device capabilities */ + vcap->capabilities |= V4L2_CAP_DEVICE_CAPS; return 0; } diff --git a/drivers/media/pci/cx18/cx18-streams.c b/drivers/media/pci/cx18/cx18-streams.c index f3541b5156c..369445fcf3e 100644 --- a/drivers/media/pci/cx18/cx18-streams.c +++ b/drivers/media/pci/cx18/cx18-streams.c @@ -58,11 +58,14 @@ static struct { int vfl_type; int num_offset; int dma; + u32 caps; } cx18_stream_info[] = { { /* CX18_ENC_STREAM_TYPE_MPG */ "encoder MPEG", VFL_TYPE_GRABBER, 0, PCI_DMA_FROMDEVICE, + V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_READWRITE | + V4L2_CAP_AUDIO | V4L2_CAP_TUNER }, { /* CX18_ENC_STREAM_TYPE_TS */ "TS", @@ -73,11 +76,15 @@ static struct { "encoder YUV", VFL_TYPE_GRABBER, CX18_V4L2_ENC_YUV_OFFSET, PCI_DMA_FROMDEVICE, + V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_READWRITE | + V4L2_CAP_STREAMING | V4L2_CAP_AUDIO | V4L2_CAP_TUNER }, { /* CX18_ENC_STREAM_TYPE_VBI */ "encoder VBI", VFL_TYPE_VBI, 0, PCI_DMA_FROMDEVICE, + V4L2_CAP_VBI_CAPTURE | V4L2_CAP_SLICED_VBI_CAPTURE | + V4L2_CAP_READWRITE | V4L2_CAP_TUNER }, { /* CX18_ENC_STREAM_TYPE_PCM */ "encoder PCM audio", @@ -93,6 +100,7 @@ static struct { "encoder radio", VFL_TYPE_RADIO, 0, PCI_DMA_NONE, + V4L2_CAP_RADIO | V4L2_CAP_TUNER }, }; @@ -260,6 +268,7 @@ static void cx18_stream_init(struct cx18 *cx, int type) s->handle = CX18_INVALID_TASK_HANDLE; s->dma = cx18_stream_info[type].dma; + s->v4l2_dev_caps = cx18_stream_info[type].caps; s->buffers = cx->stream_buffers[type]; s->buf_size = cx->stream_buf_size[type]; INIT_LIST_HEAD(&s->buf_pool); diff --git a/drivers/media/pci/cx23885/cx23885-417.c b/drivers/media/pci/cx23885/cx23885-417.c index 3948db386fb..e4901a503c7 100644 --- a/drivers/media/pci/cx23885/cx23885-417.c +++ b/drivers/media/pci/cx23885/cx23885-417.c @@ -1148,6 +1148,7 @@ static int queue_setup(struct vb2_queue *q, const struct v4l2_format *fmt, dev->ts1.ts_packet_count = mpeglines; *num_planes = 1; sizes[0] = mpeglinesize * mpeglines; + alloc_ctxs[0] = dev->alloc_ctx; *num_buffers = mpegbufs; return 0; } @@ -1166,11 +1167,8 @@ static void buffer_finish(struct vb2_buffer *vb) struct cx23885_dev *dev = vb->vb2_queue->drv_priv; struct cx23885_buffer *buf = container_of(vb, struct cx23885_buffer, vb); - struct sg_table *sgt = vb2_dma_sg_plane_desc(vb, 0); cx23885_free_buffer(dev, buf); - - dma_unmap_sg(&dev->pci->dev, sgt->sgl, sgt->nents, DMA_FROM_DEVICE); } static void buffer_queue(struct vb2_buffer *vb) diff --git a/drivers/media/pci/cx23885/cx23885-cards.c b/drivers/media/pci/cx23885/cx23885-cards.c index 88c257d1161..db99ca2613b 100644 --- a/drivers/media/pci/cx23885/cx23885-cards.c +++ b/drivers/media/pci/cx23885/cx23885-cards.c @@ -680,6 +680,32 @@ struct cx23885_board cx23885_boards[] = { .portb = CX23885_MPEG_DVB, .portc = CX23885_MPEG_DVB, }, + [CX23885_BOARD_DVBSKY_T980C] = { + .name = "DVBSky T980C", + .portb = CX23885_MPEG_DVB, + }, + [CX23885_BOARD_DVBSKY_S950C] = { + .name = "DVBSky S950C", + .portb = CX23885_MPEG_DVB, + }, + [CX23885_BOARD_TT_CT2_4500_CI] = { + .name = "Technotrend TT-budget CT2-4500 CI", + .portb = CX23885_MPEG_DVB, + }, + [CX23885_BOARD_DVBSKY_S950] = { + .name = "DVBSky S950", + .portb = CX23885_MPEG_DVB, + }, + [CX23885_BOARD_DVBSKY_S952] = { + .name = "DVBSky S952", + .portb = CX23885_MPEG_DVB, + .portc = CX23885_MPEG_DVB, + }, + [CX23885_BOARD_DVBSKY_T982] = { + .name = "DVBSky T982", + .portb = CX23885_MPEG_DVB, + .portc = CX23885_MPEG_DVB, + }, }; const unsigned int cx23885_bcount = ARRAY_SIZE(cx23885_boards); @@ -939,6 +965,30 @@ struct cx23885_subid cx23885_subids[] = { .subvendor = 0x4254, .subdevice = 0x9580, .card = CX23885_BOARD_DVBSKY_T9580, + }, { + .subvendor = 0x4254, + .subdevice = 0x980c, + .card = CX23885_BOARD_DVBSKY_T980C, + }, { + .subvendor = 0x4254, + .subdevice = 0x950c, + .card = CX23885_BOARD_DVBSKY_S950C, + }, { + .subvendor = 0x13c2, + .subdevice = 0x3013, + .card = CX23885_BOARD_TT_CT2_4500_CI, + }, { + .subvendor = 0x4254, + .subdevice = 0x0950, + .card = CX23885_BOARD_DVBSKY_S950, + }, { + .subvendor = 0x4254, + .subdevice = 0x0952, + .card = CX23885_BOARD_DVBSKY_S952, + }, { + .subvendor = 0x4254, + .subdevice = 0x0982, + .card = CX23885_BOARD_DVBSKY_T982, }, }; const unsigned int cx23885_idcount = ARRAY_SIZE(cx23885_subids); @@ -1534,6 +1584,8 @@ void cx23885_gpio_setup(struct cx23885_dev *dev) mdelay(60); break; case CX23885_BOARD_DVBSKY_T9580: + case CX23885_BOARD_DVBSKY_S952: + case CX23885_BOARD_DVBSKY_T982: /* enable GPIO3-18 pins */ cx_write(MC417_CTL, 0x00000037); cx23885_gpio_enable(dev, GPIO_2 | GPIO_11, 1); @@ -1541,6 +1593,45 @@ void cx23885_gpio_setup(struct cx23885_dev *dev) mdelay(100); cx23885_gpio_set(dev, GPIO_2 | GPIO_11); break; + case CX23885_BOARD_DVBSKY_T980C: + case CX23885_BOARD_DVBSKY_S950C: + case CX23885_BOARD_TT_CT2_4500_CI: + /* + * GPIO-0 INTA from CiMax, input + * GPIO-1 reset CiMax, output, high active + * GPIO-2 reset demod, output, low active + * GPIO-3 to GPIO-10 data/addr for CAM + * GPIO-11 ~CS0 to CiMax1 + * GPIO-12 ~CS1 to CiMax2 + * GPIO-13 ADL0 load LSB addr + * GPIO-14 ADL1 load MSB addr + * GPIO-15 ~RDY from CiMax + * GPIO-17 ~RD to CiMax + * GPIO-18 ~WR to CiMax + */ + + cx_set(GP0_IO, 0x00060002); /* GPIO 1/2 as output */ + cx_clear(GP0_IO, 0x00010004); /* GPIO 0 as input */ + mdelay(100); /* reset delay */ + cx_set(GP0_IO, 0x00060004); /* GPIO as out, reset high */ + cx_clear(GP0_IO, 0x00010002); + cx_write(MC417_CTL, 0x00000037); /* enable GPIO3-18 pins */ + + /* GPIO-15 IN as ~ACK, rest as OUT */ + cx_write(MC417_OEN, 0x00001000); + + /* ~RD, ~WR high; ADL0, ADL1 low; ~CS0, ~CS1 high */ + cx_write(MC417_RWD, 0x0000c300); + + /* enable irq */ + cx_write(GPIO_ISM, 0x00000000); /* INTERRUPTS active low */ + break; + case CX23885_BOARD_DVBSKY_S950: + cx23885_gpio_enable(dev, GPIO_2, 1); + cx23885_gpio_clear(dev, GPIO_2); + msleep(100); + cx23885_gpio_set(dev, GPIO_2); + break; } } @@ -1621,6 +1712,13 @@ int cx23885_ir_init(struct cx23885_dev *dev) case CX23885_BOARD_MYGICA_X8507: case CX23885_BOARD_TBS_6980: case CX23885_BOARD_TBS_6981: + case CX23885_BOARD_DVBSKY_T9580: + case CX23885_BOARD_DVBSKY_T980C: + case CX23885_BOARD_DVBSKY_S950C: + case CX23885_BOARD_TT_CT2_4500_CI: + case CX23885_BOARD_DVBSKY_S950: + case CX23885_BOARD_DVBSKY_S952: + case CX23885_BOARD_DVBSKY_T982: if (!enable_885_ir) break; dev->sd_ir = cx23885_find_hw(dev, CX23885_HW_AV_CORE); @@ -1667,6 +1765,13 @@ void cx23885_ir_fini(struct cx23885_dev *dev) case CX23885_BOARD_MYGICA_X8507: case CX23885_BOARD_TBS_6980: case CX23885_BOARD_TBS_6981: + case CX23885_BOARD_DVBSKY_T9580: + case CX23885_BOARD_DVBSKY_T980C: + case CX23885_BOARD_DVBSKY_S950C: + case CX23885_BOARD_TT_CT2_4500_CI: + case CX23885_BOARD_DVBSKY_S950: + case CX23885_BOARD_DVBSKY_S952: + case CX23885_BOARD_DVBSKY_T982: cx23885_irq_remove(dev, PCI_MSK_AV_CORE); /* sd_ir is a duplicate pointer to the AV Core, just clear it */ dev->sd_ir = NULL; @@ -1714,6 +1819,13 @@ void cx23885_ir_pci_int_enable(struct cx23885_dev *dev) case CX23885_BOARD_MYGICA_X8507: case CX23885_BOARD_TBS_6980: case CX23885_BOARD_TBS_6981: + case CX23885_BOARD_DVBSKY_T9580: + case CX23885_BOARD_DVBSKY_T980C: + case CX23885_BOARD_DVBSKY_S950C: + case CX23885_BOARD_TT_CT2_4500_CI: + case CX23885_BOARD_DVBSKY_S950: + case CX23885_BOARD_DVBSKY_S952: + case CX23885_BOARD_DVBSKY_T982: if (dev->sd_ir) cx23885_irq_add_enable(dev, PCI_MSK_AV_CORE); break; @@ -1817,6 +1929,10 @@ void cx23885_card_setup(struct cx23885_dev *dev) case CX23885_BOARD_TEVII_S471: case CX23885_BOARD_DVBWORLD_2005: case CX23885_BOARD_PROF_8000: + case CX23885_BOARD_DVBSKY_T980C: + case CX23885_BOARD_DVBSKY_S950C: + case CX23885_BOARD_TT_CT2_4500_CI: + case CX23885_BOARD_DVBSKY_S950: ts1->gen_ctrl_val = 0x5; /* Parallel */ ts1->ts_clk_en_val = 0x1; /* Enable TS_CLK */ ts1->src_sel_val = CX23885_SRC_SEL_PARALLEL_MPEG_VIDEO; @@ -1865,6 +1981,7 @@ void cx23885_card_setup(struct cx23885_dev *dev) ts2->src_sel_val = CX23885_SRC_SEL_PARALLEL_MPEG_VIDEO; break; case CX23885_BOARD_DVBSKY_T9580: + case CX23885_BOARD_DVBSKY_T982: ts1->gen_ctrl_val = 0x5; /* Parallel */ ts1->ts_clk_en_val = 0x1; /* Enable TS_CLK */ ts1->src_sel_val = CX23885_SRC_SEL_PARALLEL_MPEG_VIDEO; @@ -1872,6 +1989,14 @@ void cx23885_card_setup(struct cx23885_dev *dev) ts2->ts_clk_en_val = 0x1; /* Enable TS_CLK */ ts2->src_sel_val = CX23885_SRC_SEL_PARALLEL_MPEG_VIDEO; break; + case CX23885_BOARD_DVBSKY_S952: + ts1->gen_ctrl_val = 0x5; /* Parallel */ + ts1->ts_clk_en_val = 0x1; /* Enable TS_CLK */ + ts1->src_sel_val = CX23885_SRC_SEL_PARALLEL_MPEG_VIDEO; + ts2->gen_ctrl_val = 0xe; /* Serial bus */ + ts2->ts_clk_en_val = 0x1; /* Enable TS_CLK */ + ts2->src_sel_val = CX23885_SRC_SEL_PARALLEL_MPEG_VIDEO; + break; case CX23885_BOARD_HAUPPAUGE_HVR1250: case CX23885_BOARD_HAUPPAUGE_HVR1500: case CX23885_BOARD_HAUPPAUGE_HVR1500Q: @@ -1935,6 +2060,12 @@ void cx23885_card_setup(struct cx23885_dev *dev) case CX23885_BOARD_TBS_6980: case CX23885_BOARD_TBS_6981: case CX23885_BOARD_DVBSKY_T9580: + case CX23885_BOARD_DVBSKY_T980C: + case CX23885_BOARD_DVBSKY_S950C: + case CX23885_BOARD_TT_CT2_4500_CI: + case CX23885_BOARD_DVBSKY_S950: + case CX23885_BOARD_DVBSKY_S952: + case CX23885_BOARD_DVBSKY_T982: dev->sd_cx25840 = v4l2_i2c_new_subdev(&dev->v4l2_dev, &dev->i2c_bus[2].i2c_adap, "cx25840", 0x88 >> 1, NULL); diff --git a/drivers/media/pci/cx23885/cx23885-core.c b/drivers/media/pci/cx23885/cx23885-core.c index 3bd386c371f..1d9d0f86ca8 100644 --- a/drivers/media/pci/cx23885/cx23885-core.c +++ b/drivers/media/pci/cx23885/cx23885-core.c @@ -1453,17 +1453,12 @@ int cx23885_buf_prepare(struct cx23885_buffer *buf, struct cx23885_tsport *port) struct cx23885_dev *dev = port->dev; int size = port->ts_packet_size * port->ts_packet_count; struct sg_table *sgt = vb2_dma_sg_plane_desc(&buf->vb, 0); - int rc; dprintk(1, "%s: %p\n", __func__, buf); if (vb2_plane_size(&buf->vb, 0) < size) return -EINVAL; vb2_set_plane_payload(&buf->vb, 0, size); - rc = dma_map_sg(&dev->pci->dev, sgt->sgl, sgt->nents, DMA_FROM_DEVICE); - if (!rc) - return -EIO; - cx23885_risc_databuffer(dev->pci, &buf->risc, sgt->sgl, port->ts_packet_size, port->ts_packet_count, 0); @@ -1997,9 +1992,14 @@ static int cx23885_initdev(struct pci_dev *pci_dev, if (!pci_dma_supported(pci_dev, 0xffffffff)) { printk("%s/0: Oops: no 32bit PCI DMA ???\n", dev->name); err = -EIO; - goto fail_irq; + goto fail_context; } + dev->alloc_ctx = vb2_dma_sg_init_ctx(&pci_dev->dev); + if (IS_ERR(dev->alloc_ctx)) { + err = PTR_ERR(dev->alloc_ctx); + goto fail_context; + } err = request_irq(pci_dev->irq, cx23885_irq, IRQF_SHARED, dev->name, dev); if (err < 0) { @@ -2028,6 +2028,8 @@ static int cx23885_initdev(struct pci_dev *pci_dev, return 0; fail_irq: + vb2_dma_sg_cleanup_ctx(dev->alloc_ctx); +fail_context: cx23885_dev_unregister(dev); fail_ctrl: v4l2_ctrl_handler_free(hdl); @@ -2053,6 +2055,7 @@ static void cx23885_finidev(struct pci_dev *pci_dev) free_irq(pci_dev->irq, dev); cx23885_dev_unregister(dev); + vb2_dma_sg_cleanup_ctx(dev->alloc_ctx); v4l2_ctrl_handler_free(&dev->ctrl_handler); v4l2_device_unregister(v4l2_dev); kfree(dev); diff --git a/drivers/media/pci/cx23885/cx23885-dvb.c b/drivers/media/pci/cx23885/cx23885-dvb.c index 4cb90317ff4..c47d18270cf 100644 --- a/drivers/media/pci/cx23885/cx23885-dvb.c +++ b/drivers/media/pci/cx23885/cx23885-dvb.c @@ -71,6 +71,7 @@ #include "si2165.h" #include "si2168.h" #include "si2157.h" +#include "sp2.h" #include "m88ds3103.h" #include "m88ts2022.h" @@ -101,6 +102,7 @@ static int queue_setup(struct vb2_queue *q, const struct v4l2_format *fmt, port->ts_packet_count = 32; *num_planes = 1; sizes[0] = port->ts_packet_size * port->ts_packet_count; + alloc_ctxs[0] = port->dev->alloc_ctx; *num_buffers = 32; return 0; } @@ -121,11 +123,8 @@ static void buffer_finish(struct vb2_buffer *vb) struct cx23885_dev *dev = port->dev; struct cx23885_buffer *buf = container_of(vb, struct cx23885_buffer, vb); - struct sg_table *sgt = vb2_dma_sg_plane_desc(vb, 0); cx23885_free_buffer(dev, buf); - - dma_unmap_sg(&dev->pci->dev, sgt->sgl, sgt->nents, DMA_FROM_DEVICE); } static void buffer_queue(struct vb2_buffer *vb) @@ -616,6 +615,103 @@ static int dvbsky_t9580_set_voltage(struct dvb_frontend *fe, return 0; } +static int dvbsky_s952_portc_set_voltage(struct dvb_frontend *fe, + fe_sec_voltage_t voltage) +{ + struct cx23885_tsport *port = fe->dvb->priv; + struct cx23885_dev *dev = port->dev; + + cx23885_gpio_enable(dev, GPIO_12 | GPIO_13, 1); + + switch (voltage) { + case SEC_VOLTAGE_13: + cx23885_gpio_set(dev, GPIO_13); + cx23885_gpio_clear(dev, GPIO_12); + break; + case SEC_VOLTAGE_18: + cx23885_gpio_set(dev, GPIO_13); + cx23885_gpio_set(dev, GPIO_12); + break; + case SEC_VOLTAGE_OFF: + cx23885_gpio_clear(dev, GPIO_13); + cx23885_gpio_clear(dev, GPIO_12); + break; + } + /* call the frontend set_voltage function */ + return port->fe_set_voltage(fe, voltage); +} + +static int cx23885_sp2_ci_ctrl(void *priv, u8 read, int addr, + u8 data, int *mem) +{ + /* MC417 */ + #define SP2_DATA 0x000000ff + #define SP2_WR 0x00008000 + #define SP2_RD 0x00004000 + #define SP2_ACK 0x00001000 + #define SP2_ADHI 0x00000800 + #define SP2_ADLO 0x00000400 + #define SP2_CS1 0x00000200 + #define SP2_CS0 0x00000100 + #define SP2_EN_ALL 0x00001000 + #define SP2_CTRL_OFF (SP2_CS1 | SP2_CS0 | SP2_WR | SP2_RD) + + struct cx23885_tsport *port = priv; + struct cx23885_dev *dev = port->dev; + int ret; + int tmp = 0; + unsigned long timeout; + + mutex_lock(&dev->gpio_lock); + + /* write addr */ + cx_write(MC417_OEN, SP2_EN_ALL); + cx_write(MC417_RWD, SP2_CTRL_OFF | + SP2_ADLO | (0xff & addr)); + cx_clear(MC417_RWD, SP2_ADLO); + cx_write(MC417_RWD, SP2_CTRL_OFF | + SP2_ADHI | (0xff & (addr >> 8))); + cx_clear(MC417_RWD, SP2_ADHI); + + if (read) + /* data in */ + cx_write(MC417_OEN, SP2_EN_ALL | SP2_DATA); + else + /* data out */ + cx_write(MC417_RWD, SP2_CTRL_OFF | data); + + /* chip select 0 */ + cx_clear(MC417_RWD, SP2_CS0); + + /* read/write */ + cx_clear(MC417_RWD, (read) ? SP2_RD : SP2_WR); + + /* wait for a maximum of 1 msec */ + timeout = jiffies + msecs_to_jiffies(1); + while (!time_after(jiffies, timeout)) { + tmp = cx_read(MC417_RWD); + if ((tmp & SP2_ACK) == 0) + break; + usleep_range(50, 100); + } + + cx_set(MC417_RWD, SP2_CTRL_OFF); + *mem = tmp & 0xff; + + mutex_unlock(&dev->gpio_lock); + + if (!read) { + if (*mem < 0) { + ret = -EREMOTEIO; + goto err; + } + } + + return 0; +err: + return ret; +} + static int cx23885_dvb_set_frontend(struct dvb_frontend *fe) { struct dtv_frontend_properties *p = &fe->dtv_property_cache; @@ -793,6 +889,32 @@ static const struct m88ds3103_config dvbsky_t9580_m88ds3103_config = { .agc = 0x99, }; +static const struct m88ds3103_config dvbsky_s950c_m88ds3103_config = { + .i2c_addr = 0x68, + .clock = 27000000, + .i2c_wr_max = 33, + .clock_out = 0, + .ts_mode = M88DS3103_TS_CI, + .ts_clk = 10000, + .ts_clk_pol = 1, + .lnb_en_pol = 1, + .lnb_hv_pol = 0, + .agc = 0x99, +}; + +static const struct m88ds3103_config dvbsky_s952_portc_m88ds3103_config = { + .i2c_addr = 0x68, + .clock = 27000000, + .i2c_wr_max = 33, + .clock_out = 0, + .ts_mode = M88DS3103_TS_SERIAL, + .ts_clk = 96000, + .ts_clk_pol = 0, + .lnb_en_pol = 1, + .lnb_hv_pol = 0, + .agc = 0x99, +}; + static int netup_altera_fpga_rw(void *device, int flag, int data, int read) { struct cx23885_dev *dev = (struct cx23885_dev *)device; @@ -944,11 +1066,13 @@ static int dvb_register(struct cx23885_tsport *port) struct vb2_dvb_frontend *fe0, *fe1 = NULL; struct si2168_config si2168_config; struct si2157_config si2157_config; + struct sp2_config sp2_config; struct m88ts2022_config m88ts2022_config; struct i2c_board_info info; struct i2c_adapter *adapter; - struct i2c_client *client_demod; - struct i2c_client *client_tuner; + struct i2c_client *client_demod = NULL, *client_tuner = NULL, *client_ci = NULL; + const struct m88ds3103_config *p_m88ds3103_config = NULL; + int (*p_set_voltage)(struct dvb_frontend *fe, fe_sec_voltage_t voltage) = NULL; int mfe_shared = 0; /* bus not shared by default */ int ret; @@ -973,11 +1097,11 @@ static int dvb_register(struct cx23885_tsport *port) fe0->dvb.frontend = dvb_attach(s5h1409_attach, &hauppauge_generic_config, &i2c_bus->i2c_adap); - if (fe0->dvb.frontend != NULL) { - dvb_attach(mt2131_attach, fe0->dvb.frontend, - &i2c_bus->i2c_adap, - &hauppauge_generic_tunerconfig, 0); - } + if (fe0->dvb.frontend == NULL) + break; + dvb_attach(mt2131_attach, fe0->dvb.frontend, + &i2c_bus->i2c_adap, + &hauppauge_generic_tunerconfig, 0); break; case CX23885_BOARD_HAUPPAUGE_HVR1270: case CX23885_BOARD_HAUPPAUGE_HVR1275: @@ -985,11 +1109,11 @@ static int dvb_register(struct cx23885_tsport *port) fe0->dvb.frontend = dvb_attach(lgdt3305_attach, &hauppauge_lgdt3305_config, &i2c_bus->i2c_adap); - if (fe0->dvb.frontend != NULL) { - dvb_attach(tda18271_attach, fe0->dvb.frontend, - 0x60, &dev->i2c_bus[1].i2c_adap, - &hauppauge_hvr127x_config); - } + if (fe0->dvb.frontend == NULL) + break; + dvb_attach(tda18271_attach, fe0->dvb.frontend, + 0x60, &dev->i2c_bus[1].i2c_adap, + &hauppauge_hvr127x_config); if (dev->board == CX23885_BOARD_HAUPPAUGE_HVR1275) cx23885_set_frontend_hook(port, fe0->dvb.frontend); break; @@ -999,11 +1123,12 @@ static int dvb_register(struct cx23885_tsport *port) fe0->dvb.frontend = dvb_attach(s5h1411_attach, &hcw_s5h1411_config, &i2c_bus->i2c_adap); - if (fe0->dvb.frontend != NULL) { - dvb_attach(tda18271_attach, fe0->dvb.frontend, - 0x60, &dev->i2c_bus[1].i2c_adap, - &hauppauge_tda18271_config); - } + if (fe0->dvb.frontend == NULL) + break; + + dvb_attach(tda18271_attach, fe0->dvb.frontend, + 0x60, &dev->i2c_bus[1].i2c_adap, + &hauppauge_tda18271_config); tda18271_attach(&dev->ts1.analog_fe, 0x60, &dev->i2c_bus[1].i2c_adap, @@ -1018,14 +1143,15 @@ static int dvb_register(struct cx23885_tsport *port) dvb_attach(s5h1409_attach, &hauppauge_ezqam_config, &i2c_bus->i2c_adap); - if (fe0->dvb.frontend != NULL) { - dvb_attach(tda829x_attach, fe0->dvb.frontend, - &dev->i2c_bus[1].i2c_adap, 0x42, - &tda829x_no_probe); - dvb_attach(tda18271_attach, fe0->dvb.frontend, - 0x60, &dev->i2c_bus[1].i2c_adap, - &hauppauge_tda18271_config); - } + if (fe0->dvb.frontend == NULL) + break; + + dvb_attach(tda829x_attach, fe0->dvb.frontend, + &dev->i2c_bus[1].i2c_adap, 0x42, + &tda829x_no_probe); + dvb_attach(tda18271_attach, fe0->dvb.frontend, + 0x60, &dev->i2c_bus[1].i2c_adap, + &hauppauge_tda18271_config); break; case 0: default: @@ -1033,11 +1159,11 @@ static int dvb_register(struct cx23885_tsport *port) dvb_attach(s5h1409_attach, &hauppauge_generic_config, &i2c_bus->i2c_adap); - if (fe0->dvb.frontend != NULL) - dvb_attach(mt2131_attach, fe0->dvb.frontend, - &i2c_bus->i2c_adap, - &hauppauge_generic_tunerconfig, 0); - break; + if (fe0->dvb.frontend == NULL) + break; + dvb_attach(mt2131_attach, fe0->dvb.frontend, + &i2c_bus->i2c_adap, + &hauppauge_generic_tunerconfig, 0); } break; case CX23885_BOARD_HAUPPAUGE_HVR1800lp: @@ -1045,32 +1171,33 @@ static int dvb_register(struct cx23885_tsport *port) fe0->dvb.frontend = dvb_attach(s5h1409_attach, &hauppauge_hvr1800lp_config, &i2c_bus->i2c_adap); - if (fe0->dvb.frontend != NULL) { - dvb_attach(mt2131_attach, fe0->dvb.frontend, - &i2c_bus->i2c_adap, - &hauppauge_generic_tunerconfig, 0); - } + if (fe0->dvb.frontend == NULL) + break; + dvb_attach(mt2131_attach, fe0->dvb.frontend, + &i2c_bus->i2c_adap, + &hauppauge_generic_tunerconfig, 0); break; case CX23885_BOARD_DVICO_FUSIONHDTV_5_EXP: i2c_bus = &dev->i2c_bus[0]; fe0->dvb.frontend = dvb_attach(lgdt330x_attach, &fusionhdtv_5_express, &i2c_bus->i2c_adap); - if (fe0->dvb.frontend != NULL) { - dvb_attach(simple_tuner_attach, fe0->dvb.frontend, - &i2c_bus->i2c_adap, 0x61, - TUNER_LG_TDVS_H06XF); - } + if (fe0->dvb.frontend == NULL) + break; + dvb_attach(simple_tuner_attach, fe0->dvb.frontend, + &i2c_bus->i2c_adap, 0x61, + TUNER_LG_TDVS_H06XF); break; case CX23885_BOARD_HAUPPAUGE_HVR1500Q: i2c_bus = &dev->i2c_bus[1]; fe0->dvb.frontend = dvb_attach(s5h1409_attach, &hauppauge_hvr1500q_config, &dev->i2c_bus[0].i2c_adap); - if (fe0->dvb.frontend != NULL) - dvb_attach(xc5000_attach, fe0->dvb.frontend, - &i2c_bus->i2c_adap, - &hauppauge_hvr1500q_tunerconfig); + if (fe0->dvb.frontend == NULL) + break; + dvb_attach(xc5000_attach, fe0->dvb.frontend, + &i2c_bus->i2c_adap, + &hauppauge_hvr1500q_tunerconfig); break; case CX23885_BOARD_HAUPPAUGE_HVR1500: i2c_bus = &dev->i2c_bus[1]; @@ -1101,14 +1228,14 @@ static int dvb_register(struct cx23885_tsport *port) fe0->dvb.frontend = dvb_attach(tda10048_attach, &hauppauge_hvr1200_config, &i2c_bus->i2c_adap); - if (fe0->dvb.frontend != NULL) { - dvb_attach(tda829x_attach, fe0->dvb.frontend, - &dev->i2c_bus[1].i2c_adap, 0x42, - &tda829x_no_probe); - dvb_attach(tda18271_attach, fe0->dvb.frontend, - 0x60, &dev->i2c_bus[1].i2c_adap, - &hauppauge_hvr1200_tuner_config); - } + if (fe0->dvb.frontend == NULL) + break; + dvb_attach(tda829x_attach, fe0->dvb.frontend, + &dev->i2c_bus[1].i2c_adap, 0x42, + &tda829x_no_probe); + dvb_attach(tda18271_attach, fe0->dvb.frontend, + 0x60, &dev->i2c_bus[1].i2c_adap, + &hauppauge_hvr1200_tuner_config); break; case CX23885_BOARD_HAUPPAUGE_HVR1210: i2c_bus = &dev->i2c_bus[0]; @@ -1367,12 +1494,10 @@ static int dvb_register(struct cx23885_tsport *port) fe0->dvb.frontend = dvb_attach(lgs8gxx_attach, &mygica_x8506_lgs8gl5_config, &i2c_bus->i2c_adap); - if (fe0->dvb.frontend != NULL) { - dvb_attach(xc5000_attach, - fe0->dvb.frontend, - &i2c_bus2->i2c_adap, - &mygica_x8506_xc5000_config); - } + if (fe0->dvb.frontend == NULL) + break; + dvb_attach(xc5000_attach, fe0->dvb.frontend, + &i2c_bus2->i2c_adap, &mygica_x8506_xc5000_config); cx23885_set_frontend_hook(port, fe0->dvb.frontend); break; case CX23885_BOARD_MYGICA_X8507: @@ -1381,12 +1506,12 @@ static int dvb_register(struct cx23885_tsport *port) fe0->dvb.frontend = dvb_attach(mb86a20s_attach, &mygica_x8507_mb86a20s_config, &i2c_bus->i2c_adap); - if (fe0->dvb.frontend != NULL) { - dvb_attach(xc5000_attach, - fe0->dvb.frontend, - &i2c_bus2->i2c_adap, - &mygica_x8507_xc5000_config); - } + if (fe0->dvb.frontend == NULL) + break; + + dvb_attach(xc5000_attach, fe0->dvb.frontend, + &i2c_bus2->i2c_adap, + &mygica_x8507_xc5000_config); cx23885_set_frontend_hook(port, fe0->dvb.frontend); break; case CX23885_BOARD_MAGICPRO_PROHDTVE2: @@ -1395,12 +1520,11 @@ static int dvb_register(struct cx23885_tsport *port) fe0->dvb.frontend = dvb_attach(lgs8gxx_attach, &magicpro_prohdtve2_lgs8g75_config, &i2c_bus->i2c_adap); - if (fe0->dvb.frontend != NULL) { - dvb_attach(xc5000_attach, - fe0->dvb.frontend, - &i2c_bus2->i2c_adap, - &magicpro_prohdtve2_xc5000_config); - } + if (fe0->dvb.frontend == NULL) + break; + dvb_attach(xc5000_attach, fe0->dvb.frontend, + &i2c_bus2->i2c_adap, + &magicpro_prohdtve2_xc5000_config); cx23885_set_frontend_hook(port, fe0->dvb.frontend); break; case CX23885_BOARD_HAUPPAUGE_HVR1850: @@ -1408,10 +1532,11 @@ static int dvb_register(struct cx23885_tsport *port) fe0->dvb.frontend = dvb_attach(s5h1411_attach, &hcw_s5h1411_config, &i2c_bus->i2c_adap); - if (fe0->dvb.frontend != NULL) - dvb_attach(tda18271_attach, fe0->dvb.frontend, - 0x60, &dev->i2c_bus[0].i2c_adap, - &hauppauge_tda18271_config); + if (fe0->dvb.frontend == NULL) + break; + dvb_attach(tda18271_attach, fe0->dvb.frontend, + 0x60, &dev->i2c_bus[0].i2c_adap, + &hauppauge_tda18271_config); tda18271_attach(&dev->ts1.analog_fe, 0x60, &dev->i2c_bus[1].i2c_adap, @@ -1423,10 +1548,11 @@ static int dvb_register(struct cx23885_tsport *port) fe0->dvb.frontend = dvb_attach(s5h1411_attach, &hcw_s5h1411_config, &i2c_bus->i2c_adap); - if (fe0->dvb.frontend != NULL) - dvb_attach(tda18271_attach, fe0->dvb.frontend, - 0x60, &dev->i2c_bus[0].i2c_adap, - &hauppauge_tda18271_config); + if (fe0->dvb.frontend == NULL) + break; + dvb_attach(tda18271_attach, fe0->dvb.frontend, + 0x60, &dev->i2c_bus[0].i2c_adap, + &hauppauge_tda18271_config); break; case CX23885_BOARD_MYGICA_X8558PRO: switch (port->nr) { @@ -1436,12 +1562,11 @@ static int dvb_register(struct cx23885_tsport *port) fe0->dvb.frontend = dvb_attach(atbm8830_attach, &mygica_x8558pro_atbm8830_cfg1, &i2c_bus->i2c_adap); - if (fe0->dvb.frontend != NULL) { - dvb_attach(max2165_attach, - fe0->dvb.frontend, - &i2c_bus->i2c_adap, - &mygic_x8558pro_max2165_cfg1); - } + if (fe0->dvb.frontend == NULL) + break; + dvb_attach(max2165_attach, fe0->dvb.frontend, + &i2c_bus->i2c_adap, + &mygic_x8558pro_max2165_cfg1); break; /* port C */ case 2: @@ -1449,13 +1574,11 @@ static int dvb_register(struct cx23885_tsport *port) fe0->dvb.frontend = dvb_attach(atbm8830_attach, &mygica_x8558pro_atbm8830_cfg2, &i2c_bus->i2c_adap); - if (fe0->dvb.frontend != NULL) { - dvb_attach(max2165_attach, - fe0->dvb.frontend, - &i2c_bus->i2c_adap, - &mygic_x8558pro_max2165_cfg2); - } - break; + if (fe0->dvb.frontend == NULL) + break; + dvb_attach(max2165_attach, fe0->dvb.frontend, + &i2c_bus->i2c_adap, + &mygic_x8558pro_max2165_cfg2); } break; case CX23885_BOARD_NETUP_DUAL_DVB_T_C_CI_RF: @@ -1467,15 +1590,15 @@ static int dvb_register(struct cx23885_tsport *port) fe0->dvb.frontend = dvb_attach(stv0367ter_attach, &netup_stv0367_config[port->nr - 1], &i2c_bus->i2c_adap); - if (fe0->dvb.frontend != NULL) { - if (NULL == dvb_attach(xc5000_attach, - fe0->dvb.frontend, + if (fe0->dvb.frontend == NULL) + break; + if (NULL == dvb_attach(xc5000_attach, fe0->dvb.frontend, &i2c_bus->i2c_adap, &netup_xc5000_config[port->nr - 1])) - goto frontend_detach; - /* load xc5000 firmware */ - fe0->dvb.frontend->ops.tuner_ops.init(fe0->dvb.frontend); - } + goto frontend_detach; + /* load xc5000 firmware */ + fe0->dvb.frontend->ops.tuner_ops.init(fe0->dvb.frontend); + /* MFE frontend 2 */ fe1 = vb2_dvb_get_frontend(&port->frontends, 2); if (fe1 == NULL) @@ -1484,14 +1607,15 @@ static int dvb_register(struct cx23885_tsport *port) fe1->dvb.frontend = dvb_attach(stv0367cab_attach, &netup_stv0367_config[port->nr - 1], &i2c_bus->i2c_adap); - if (fe1->dvb.frontend != NULL) { - fe1->dvb.frontend->id = 1; - if (NULL == dvb_attach(xc5000_attach, - fe1->dvb.frontend, - &i2c_bus->i2c_adap, - &netup_xc5000_config[port->nr - 1])) - goto frontend_detach; - } + if (fe1->dvb.frontend == NULL) + break; + + fe1->dvb.frontend->id = 1; + if (NULL == dvb_attach(xc5000_attach, + fe1->dvb.frontend, + &i2c_bus->i2c_adap, + &netup_xc5000_config[port->nr - 1])) + goto frontend_detach; break; case CX23885_BOARD_TERRATEC_CINERGY_T_PCIE_DUAL: i2c_bus = &dev->i2c_bus[0]; @@ -1503,26 +1627,26 @@ static int dvb_register(struct cx23885_tsport *port) fe0->dvb.frontend = dvb_attach(drxk_attach, &terratec_drxk_config[0], &i2c_bus->i2c_adap); - if (fe0->dvb.frontend != NULL) { - if (!dvb_attach(mt2063_attach, - fe0->dvb.frontend, - &terratec_mt2063_config[0], - &i2c_bus2->i2c_adap)) - goto frontend_detach; - } + if (fe0->dvb.frontend == NULL) + break; + if (!dvb_attach(mt2063_attach, + fe0->dvb.frontend, + &terratec_mt2063_config[0], + &i2c_bus2->i2c_adap)) + goto frontend_detach; break; /* port c */ case 2: fe0->dvb.frontend = dvb_attach(drxk_attach, &terratec_drxk_config[1], &i2c_bus->i2c_adap); - if (fe0->dvb.frontend != NULL) { - if (!dvb_attach(mt2063_attach, - fe0->dvb.frontend, - &terratec_mt2063_config[1], - &i2c_bus2->i2c_adap)) - goto frontend_detach; - } + if (fe0->dvb.frontend == NULL) + break; + if (!dvb_attach(mt2063_attach, + fe0->dvb.frontend, + &terratec_mt2063_config[1], + &i2c_bus2->i2c_adap)) + goto frontend_detach; break; } break; @@ -1532,10 +1656,10 @@ static int dvb_register(struct cx23885_tsport *port) fe0->dvb.frontend = dvb_attach(ds3000_attach, &tevii_ds3000_config, &i2c_bus->i2c_adap); - if (fe0->dvb.frontend != NULL) { - dvb_attach(ts2020_attach, fe0->dvb.frontend, - &tevii_ts2020_config, &i2c_bus->i2c_adap); - } + if (fe0->dvb.frontend == NULL) + break; + dvb_attach(ts2020_attach, fe0->dvb.frontend, + &tevii_ts2020_config, &i2c_bus->i2c_adap); break; case CX23885_BOARD_PROF_8000: i2c_bus = &dev->i2c_bus[0]; @@ -1544,15 +1668,15 @@ static int dvb_register(struct cx23885_tsport *port) &prof_8000_stv090x_config, &i2c_bus->i2c_adap, STV090x_DEMODULATOR_0); - if (fe0->dvb.frontend != NULL) { - if (!dvb_attach(stb6100_attach, - fe0->dvb.frontend, - &prof_8000_stb6100_config, - &i2c_bus->i2c_adap)) - goto frontend_detach; + if (fe0->dvb.frontend == NULL) + break; + if (!dvb_attach(stb6100_attach, + fe0->dvb.frontend, + &prof_8000_stb6100_config, + &i2c_bus->i2c_adap)) + goto frontend_detach; - fe0->dvb.frontend->ops.set_voltage = p8000_set_voltage; - } + fe0->dvb.frontend->ops.set_voltage = p8000_set_voltage; break; case CX23885_BOARD_HAUPPAUGE_HVR4400: i2c_bus = &dev->i2c_bus[0]; @@ -1563,30 +1687,31 @@ static int dvb_register(struct cx23885_tsport *port) fe0->dvb.frontend = dvb_attach(tda10071_attach, &hauppauge_tda10071_config, &i2c_bus->i2c_adap); - if (fe0->dvb.frontend != NULL) { - if (!dvb_attach(a8293_attach, fe0->dvb.frontend, - &i2c_bus->i2c_adap, - &hauppauge_a8293_config)) - goto frontend_detach; - } + if (fe0->dvb.frontend == NULL) + break; + if (!dvb_attach(a8293_attach, fe0->dvb.frontend, + &i2c_bus->i2c_adap, + &hauppauge_a8293_config)) + goto frontend_detach; break; /* port c */ case 2: fe0->dvb.frontend = dvb_attach(si2165_attach, &hauppauge_hvr4400_si2165_config, &i2c_bus->i2c_adap); - if (fe0->dvb.frontend != NULL) { - fe0->dvb.frontend->ops.i2c_gate_ctrl = NULL; - if (!dvb_attach(tda18271_attach, - fe0->dvb.frontend, - 0x60, &i2c_bus2->i2c_adap, - &hauppauge_hvr4400_tuner_config)) - goto frontend_detach; - } + if (fe0->dvb.frontend == NULL) + break; + fe0->dvb.frontend->ops.i2c_gate_ctrl = NULL; + if (!dvb_attach(tda18271_attach, + fe0->dvb.frontend, + 0x60, &i2c_bus2->i2c_adap, + &hauppauge_hvr4400_tuner_config)) + goto frontend_detach; break; } break; case CX23885_BOARD_DVBSKY_T9580: + case CX23885_BOARD_DVBSKY_S950: i2c_bus = &dev->i2c_bus[0]; i2c_bus2 = &dev->i2c_bus[1]; switch (port->nr) { @@ -1680,6 +1805,201 @@ static int dvb_register(struct cx23885_tsport *port) break; } break; + case CX23885_BOARD_DVBSKY_T980C: + case CX23885_BOARD_TT_CT2_4500_CI: + i2c_bus = &dev->i2c_bus[1]; + i2c_bus2 = &dev->i2c_bus[0]; + + /* attach frontend */ + memset(&si2168_config, 0, sizeof(si2168_config)); + si2168_config.i2c_adapter = &adapter; + si2168_config.fe = &fe0->dvb.frontend; + si2168_config.ts_mode = SI2168_TS_PARALLEL; + memset(&info, 0, sizeof(struct i2c_board_info)); + strlcpy(info.type, "si2168", I2C_NAME_SIZE); + info.addr = 0x64; + info.platform_data = &si2168_config; + request_module(info.type); + client_demod = i2c_new_device(&i2c_bus->i2c_adap, &info); + if (client_demod == NULL || + client_demod->dev.driver == NULL) + goto frontend_detach; + if (!try_module_get(client_demod->dev.driver->owner)) { + i2c_unregister_device(client_demod); + goto frontend_detach; + } + port->i2c_client_demod = client_demod; + + /* attach tuner */ + memset(&si2157_config, 0, sizeof(si2157_config)); + si2157_config.fe = fe0->dvb.frontend; + memset(&info, 0, sizeof(struct i2c_board_info)); + strlcpy(info.type, "si2157", I2C_NAME_SIZE); + info.addr = 0x60; + info.platform_data = &si2157_config; + request_module(info.type); + client_tuner = i2c_new_device(adapter, &info); + if (client_tuner == NULL || + client_tuner->dev.driver == NULL) { + module_put(client_demod->dev.driver->owner); + i2c_unregister_device(client_demod); + goto frontend_detach; + } + if (!try_module_get(client_tuner->dev.driver->owner)) { + i2c_unregister_device(client_tuner); + module_put(client_demod->dev.driver->owner); + i2c_unregister_device(client_demod); + goto frontend_detach; + } + port->i2c_client_tuner = client_tuner; + break; + case CX23885_BOARD_DVBSKY_S950C: + i2c_bus = &dev->i2c_bus[1]; + i2c_bus2 = &dev->i2c_bus[0]; + + /* attach frontend */ + fe0->dvb.frontend = dvb_attach(m88ds3103_attach, + &dvbsky_s950c_m88ds3103_config, + &i2c_bus->i2c_adap, &adapter); + if (fe0->dvb.frontend == NULL) + break; + + /* attach tuner */ + memset(&m88ts2022_config, 0, sizeof(m88ts2022_config)); + m88ts2022_config.fe = fe0->dvb.frontend; + m88ts2022_config.clock = 27000000; + memset(&info, 0, sizeof(struct i2c_board_info)); + strlcpy(info.type, "m88ts2022", I2C_NAME_SIZE); + info.addr = 0x60; + info.platform_data = &m88ts2022_config; + request_module(info.type); + client_tuner = i2c_new_device(adapter, &info); + if (client_tuner == NULL || + client_tuner->dev.driver == NULL) + goto frontend_detach; + if (!try_module_get(client_tuner->dev.driver->owner)) { + i2c_unregister_device(client_tuner); + goto frontend_detach; + } + + /* delegate signal strength measurement to tuner */ + fe0->dvb.frontend->ops.read_signal_strength = + fe0->dvb.frontend->ops.tuner_ops.get_rf_strength; + + port->i2c_client_tuner = client_tuner; + break; + case CX23885_BOARD_DVBSKY_S952: + switch (port->nr) { + /* port b */ + case 1: + i2c_bus = &dev->i2c_bus[1]; + p_m88ds3103_config = &dvbsky_t9580_m88ds3103_config; + p_set_voltage = dvbsky_t9580_set_voltage; + break; + /* port c */ + case 2: + i2c_bus = &dev->i2c_bus[0]; + p_m88ds3103_config = &dvbsky_s952_portc_m88ds3103_config; + p_set_voltage = dvbsky_s952_portc_set_voltage; + break; + } + + /* attach frontend */ + fe0->dvb.frontend = dvb_attach(m88ds3103_attach, + p_m88ds3103_config, + &i2c_bus->i2c_adap, &adapter); + if (fe0->dvb.frontend == NULL) + break; + + /* attach tuner */ + memset(&m88ts2022_config, 0, sizeof(m88ts2022_config)); + m88ts2022_config.fe = fe0->dvb.frontend; + m88ts2022_config.clock = 27000000; + memset(&info, 0, sizeof(struct i2c_board_info)); + strlcpy(info.type, "m88ts2022", I2C_NAME_SIZE); + info.addr = 0x60; + info.platform_data = &m88ts2022_config; + request_module(info.type); + client_tuner = i2c_new_device(adapter, &info); + if (client_tuner == NULL || + client_tuner->dev.driver == NULL) + goto frontend_detach; + if (!try_module_get(client_tuner->dev.driver->owner)) { + i2c_unregister_device(client_tuner); + goto frontend_detach; + } + + /* delegate signal strength measurement to tuner */ + fe0->dvb.frontend->ops.read_signal_strength = + fe0->dvb.frontend->ops.tuner_ops.get_rf_strength; + + /* + * for setting the voltage we need to set GPIOs on + * the card. + */ + port->fe_set_voltage = + fe0->dvb.frontend->ops.set_voltage; + fe0->dvb.frontend->ops.set_voltage = p_set_voltage; + + port->i2c_client_tuner = client_tuner; + break; + case CX23885_BOARD_DVBSKY_T982: + memset(&si2168_config, 0, sizeof(si2168_config)); + switch (port->nr) { + /* port b */ + case 1: + i2c_bus = &dev->i2c_bus[1]; + si2168_config.ts_mode = SI2168_TS_PARALLEL; + break; + /* port c */ + case 2: + i2c_bus = &dev->i2c_bus[0]; + si2168_config.ts_mode = SI2168_TS_SERIAL; + break; + } + + /* attach frontend */ + si2168_config.i2c_adapter = &adapter; + si2168_config.fe = &fe0->dvb.frontend; + memset(&info, 0, sizeof(struct i2c_board_info)); + strlcpy(info.type, "si2168", I2C_NAME_SIZE); + info.addr = 0x64; + info.platform_data = &si2168_config; + request_module(info.type); + client_demod = i2c_new_device(&i2c_bus->i2c_adap, &info); + if (client_demod == NULL || + client_demod->dev.driver == NULL) + goto frontend_detach; + if (!try_module_get(client_demod->dev.driver->owner)) { + i2c_unregister_device(client_demod); + goto frontend_detach; + } + port->i2c_client_demod = client_demod; + + /* attach tuner */ + memset(&si2157_config, 0, sizeof(si2157_config)); + si2157_config.fe = fe0->dvb.frontend; + memset(&info, 0, sizeof(struct i2c_board_info)); + strlcpy(info.type, "si2157", I2C_NAME_SIZE); + info.addr = 0x60; + info.platform_data = &si2157_config; + request_module(info.type); + client_tuner = i2c_new_device(adapter, &info); + if (client_tuner == NULL || + client_tuner->dev.driver == NULL) { + module_put(client_demod->dev.driver->owner); + i2c_unregister_device(client_demod); + goto frontend_detach; + } + if (!try_module_get(client_tuner->dev.driver->owner)) { + i2c_unregister_device(client_tuner); + module_put(client_demod->dev.driver->owner); + i2c_unregister_device(client_demod); + port->i2c_client_demod = NULL; + goto frontend_detach; + } + port->i2c_client_tuner = client_tuner; + break; default: printk(KERN_INFO "%s: The frontend of your DVB/ATSC card " " isn't supported yet\n", @@ -1754,7 +2074,10 @@ static int dvb_register(struct cx23885_tsport *port) memcpy(port->frontends.adapter.proposed_mac, eeprom + 0xa0, 6); break; } - case CX23885_BOARD_DVBSKY_T9580: { + case CX23885_BOARD_DVBSKY_T9580: + case CX23885_BOARD_DVBSKY_S950: + case CX23885_BOARD_DVBSKY_S952: + case CX23885_BOARD_DVBSKY_T982: { u8 eeprom[256]; /* 24C02 i2c eeprom */ if (port->nr > 2) @@ -1764,12 +2087,67 @@ static int dvb_register(struct cx23885_tsport *port) dev->i2c_bus[0].i2c_client.addr = 0xa0 >> 1; tveeprom_read(&dev->i2c_bus[0].i2c_client, eeprom, sizeof(eeprom)); - printk(KERN_INFO "DVBSky T9580 port %d MAC address: %pM\n", - port->nr, eeprom + 0xc0 + (port->nr-1) * 8); + printk(KERN_INFO "%s port %d MAC address: %pM\n", + cx23885_boards[dev->board].name, port->nr, + eeprom + 0xc0 + (port->nr-1) * 8); memcpy(port->frontends.adapter.proposed_mac, eeprom + 0xc0 + (port->nr-1) * 8, 6); break; } + case CX23885_BOARD_DVBSKY_S950C: + case CX23885_BOARD_DVBSKY_T980C: + case CX23885_BOARD_TT_CT2_4500_CI: { + u8 eeprom[256]; /* 24C02 i2c eeprom */ + + /* attach CI */ + memset(&sp2_config, 0, sizeof(sp2_config)); + sp2_config.dvb_adap = &port->frontends.adapter; + sp2_config.priv = port; + sp2_config.ci_control = cx23885_sp2_ci_ctrl; + memset(&info, 0, sizeof(struct i2c_board_info)); + strlcpy(info.type, "sp2", I2C_NAME_SIZE); + info.addr = 0x40; + info.platform_data = &sp2_config; + request_module(info.type); + client_ci = i2c_new_device(&i2c_bus2->i2c_adap, &info); + if (client_ci == NULL || + client_ci->dev.driver == NULL) { + if (client_tuner) { + module_put(client_tuner->dev.driver->owner); + i2c_unregister_device(client_tuner); + } + if (client_demod) { + module_put(client_demod->dev.driver->owner); + i2c_unregister_device(client_demod); + } + goto frontend_detach; + } + if (!try_module_get(client_ci->dev.driver->owner)) { + i2c_unregister_device(client_ci); + if (client_tuner) { + module_put(client_tuner->dev.driver->owner); + i2c_unregister_device(client_tuner); + } + if (client_demod) { + module_put(client_demod->dev.driver->owner); + i2c_unregister_device(client_demod); + } + goto frontend_detach; + } + port->i2c_client_ci = client_ci; + + if (port->nr != 1) + break; + + /* Read entire EEPROM */ + dev->i2c_bus[0].i2c_client.addr = 0xa0 >> 1; + tveeprom_read(&dev->i2c_bus[0].i2c_client, eeprom, + sizeof(eeprom)); + printk(KERN_INFO "%s MAC address: %pM\n", + cx23885_boards[dev->board].name, eeprom + 0xc0); + memcpy(port->frontends.adapter.proposed_mac, eeprom + 0xc0, 6); + break; + } } return ret; @@ -1810,7 +2188,7 @@ int cx23885_dvb_register(struct cx23885_tsport *port) fe0 = vb2_dvb_get_frontend(&port->frontends, i); if (!fe0) - err = -EINVAL; + return -EINVAL; dprintk(1, "%s\n", __func__); dprintk(1, " ->probed by Card=%d Name=%s, PCI %02x:%02x\n", @@ -1853,6 +2231,13 @@ int cx23885_dvb_unregister(struct cx23885_tsport *port) struct vb2_dvb_frontend *fe0; struct i2c_client *client; + /* remove I2C client for CI */ + client = port->i2c_client_ci; + if (client) { + module_put(client->dev.driver->owner); + i2c_unregister_device(client); + } + /* remove I2C client for tuner */ client = port->i2c_client_tuner; if (client) { diff --git a/drivers/media/pci/cx23885/cx23885-input.c b/drivers/media/pci/cx23885/cx23885-input.c index 9d37fe66169..088799c3b49 100644 --- a/drivers/media/pci/cx23885/cx23885-input.c +++ b/drivers/media/pci/cx23885/cx23885-input.c @@ -87,6 +87,13 @@ void cx23885_input_rx_work_handler(struct cx23885_dev *dev, u32 events) case CX23885_BOARD_MYGICA_X8507: case CX23885_BOARD_TBS_6980: case CX23885_BOARD_TBS_6981: + case CX23885_BOARD_DVBSKY_T9580: + case CX23885_BOARD_DVBSKY_T980C: + case CX23885_BOARD_DVBSKY_S950C: + case CX23885_BOARD_TT_CT2_4500_CI: + case CX23885_BOARD_DVBSKY_S950: + case CX23885_BOARD_DVBSKY_S952: + case CX23885_BOARD_DVBSKY_T982: /* * The only boards we handle right now. However other boards * using the CX2388x integrated IR controller should be similar @@ -139,6 +146,13 @@ static int cx23885_input_ir_start(struct cx23885_dev *dev) case CX23885_BOARD_HAUPPAUGE_HVR1290: case CX23885_BOARD_HAUPPAUGE_HVR1250: case CX23885_BOARD_MYGICA_X8507: + case CX23885_BOARD_DVBSKY_T9580: + case CX23885_BOARD_DVBSKY_T980C: + case CX23885_BOARD_DVBSKY_S950C: + case CX23885_BOARD_TT_CT2_4500_CI: + case CX23885_BOARD_DVBSKY_S950: + case CX23885_BOARD_DVBSKY_S952: + case CX23885_BOARD_DVBSKY_T982: /* * The IR controller on this board only returns pulse widths. * Any other mode setting will fail to set up the device. @@ -305,6 +319,23 @@ int cx23885_input_init(struct cx23885_dev *dev) /* A guess at the remote */ rc_map = RC_MAP_TBS_NEC; break; + case CX23885_BOARD_DVBSKY_T9580: + case CX23885_BOARD_DVBSKY_T980C: + case CX23885_BOARD_DVBSKY_S950C: + case CX23885_BOARD_DVBSKY_S950: + case CX23885_BOARD_DVBSKY_S952: + case CX23885_BOARD_DVBSKY_T982: + /* Integrated CX23885 IR controller */ + driver_type = RC_DRIVER_IR_RAW; + allowed_protos = RC_BIT_ALL; + rc_map = RC_MAP_DVBSKY; + break; + case CX23885_BOARD_TT_CT2_4500_CI: + /* Integrated CX23885 IR controller */ + driver_type = RC_DRIVER_IR_RAW; + allowed_protos = RC_BIT_ALL; + rc_map = RC_MAP_TT_1500; + break; default: return -ENODEV; } diff --git a/drivers/media/pci/cx23885/cx23885-vbi.c b/drivers/media/pci/cx23885/cx23885-vbi.c index a7c6ef8f3ea..d362d3838c8 100644 --- a/drivers/media/pci/cx23885/cx23885-vbi.c +++ b/drivers/media/pci/cx23885/cx23885-vbi.c @@ -132,6 +132,7 @@ static int queue_setup(struct vb2_queue *q, const struct v4l2_format *fmt, lines = VBI_NTSC_LINE_COUNT; *num_planes = 1; sizes[0] = lines * VBI_LINE_LENGTH * 2; + alloc_ctxs[0] = dev->alloc_ctx; return 0; } @@ -142,7 +143,6 @@ static int buffer_prepare(struct vb2_buffer *vb) struct cx23885_buffer, vb); struct sg_table *sgt = vb2_dma_sg_plane_desc(vb, 0); unsigned lines = VBI_PAL_LINE_COUNT; - int ret; if (dev->tvnorm & V4L2_STD_525_60) lines = VBI_NTSC_LINE_COUNT; @@ -151,10 +151,6 @@ static int buffer_prepare(struct vb2_buffer *vb) return -EINVAL; vb2_set_plane_payload(vb, 0, lines * VBI_LINE_LENGTH * 2); - ret = dma_map_sg(&dev->pci->dev, sgt->sgl, sgt->nents, DMA_FROM_DEVICE); - if (!ret) - return -EIO; - cx23885_risc_vbibuffer(dev->pci, &buf->risc, sgt->sgl, 0, VBI_LINE_LENGTH * lines, @@ -165,14 +161,10 @@ static int buffer_prepare(struct vb2_buffer *vb) static void buffer_finish(struct vb2_buffer *vb) { - struct cx23885_dev *dev = vb->vb2_queue->drv_priv; struct cx23885_buffer *buf = container_of(vb, struct cx23885_buffer, vb); - struct sg_table *sgt = vb2_dma_sg_plane_desc(vb, 0); cx23885_free_buffer(vb->vb2_queue->drv_priv, buf); - - dma_unmap_sg(&dev->pci->dev, sgt->sgl, sgt->nents, DMA_FROM_DEVICE); } /* diff --git a/drivers/media/pci/cx23885/cx23885-video.c b/drivers/media/pci/cx23885/cx23885-video.c index 682a4f95df6..5e93c682a3f 100644 --- a/drivers/media/pci/cx23885/cx23885-video.c +++ b/drivers/media/pci/cx23885/cx23885-video.c @@ -323,6 +323,7 @@ static int queue_setup(struct vb2_queue *q, const struct v4l2_format *fmt, *num_planes = 1; sizes[0] = (dev->fmt->depth * dev->width * dev->height) >> 3; + alloc_ctxs[0] = dev->alloc_ctx; return 0; } @@ -334,7 +335,6 @@ static int buffer_prepare(struct vb2_buffer *vb) u32 line0_offset, line1_offset; struct sg_table *sgt = vb2_dma_sg_plane_desc(vb, 0); int field_tff; - int ret; buf->bpl = (dev->width * dev->fmt->depth) >> 3; @@ -342,10 +342,6 @@ static int buffer_prepare(struct vb2_buffer *vb) return -EINVAL; vb2_set_plane_payload(vb, 0, dev->height * buf->bpl); - ret = dma_map_sg(&dev->pci->dev, sgt->sgl, sgt->nents, DMA_FROM_DEVICE); - if (!ret) - return -EIO; - switch (dev->field) { case V4L2_FIELD_TOP: cx23885_risc_buffer(dev->pci, &buf->risc, @@ -413,14 +409,10 @@ static int buffer_prepare(struct vb2_buffer *vb) static void buffer_finish(struct vb2_buffer *vb) { - struct cx23885_dev *dev = vb->vb2_queue->drv_priv; struct cx23885_buffer *buf = container_of(vb, struct cx23885_buffer, vb); - struct sg_table *sgt = vb2_dma_sg_plane_desc(vb, 0); cx23885_free_buffer(vb->vb2_queue->drv_priv, buf); - - dma_unmap_sg(&dev->pci->dev, sgt->sgl, sgt->nents, DMA_FROM_DEVICE); } /* @@ -608,7 +600,7 @@ static int vidioc_s_fmt_vid_cap(struct file *file, void *priv, dev->field = f->fmt.pix.field; dprintk(2, "%s() width=%d height=%d field=%d\n", __func__, dev->width, dev->height, dev->field); - v4l2_fill_mbus_format(&mbus_fmt, &f->fmt.pix, V4L2_MBUS_FMT_FIXED); + v4l2_fill_mbus_format(&mbus_fmt, &f->fmt.pix, MEDIA_BUS_FMT_FIXED); call_all(dev, video, s_mbus_fmt, &mbus_fmt); v4l2_fill_pix_format(&f->fmt.pix, &mbus_fmt); /* s_mbus_fmt overwrites f->fmt.pix.field, restore it */ diff --git a/drivers/media/pci/cx23885/cx23885.h b/drivers/media/pci/cx23885/cx23885.h index 6c35e611596..f55cd12da0f 100644 --- a/drivers/media/pci/cx23885/cx23885.h +++ b/drivers/media/pci/cx23885/cx23885.h @@ -93,6 +93,12 @@ #define CX23885_BOARD_HAUPPAUGE_IMPACTVCBE 43 #define CX23885_BOARD_DVICO_FUSIONHDTV_DVB_T_DUAL_EXP2 44 #define CX23885_BOARD_DVBSKY_T9580 45 +#define CX23885_BOARD_DVBSKY_T980C 46 +#define CX23885_BOARD_DVBSKY_S950C 47 +#define CX23885_BOARD_TT_CT2_4500_CI 48 +#define CX23885_BOARD_DVBSKY_S950 49 +#define CX23885_BOARD_DVBSKY_S952 50 +#define CX23885_BOARD_DVBSKY_T982 51 #define GPIO_0 0x00000001 #define GPIO_1 0x00000002 @@ -296,6 +302,7 @@ struct cx23885_tsport { struct i2c_client *i2c_client_demod; struct i2c_client *i2c_client_tuner; + struct i2c_client *i2c_client_ci; int (*set_frontend)(struct dvb_frontend *fe); int (*fe_set_voltage)(struct dvb_frontend *fe, @@ -418,6 +425,7 @@ struct cx23885_dev { struct vb2_queue vb2_vidq; struct cx23885_dmaqueue vbiq; struct vb2_queue vb2_vbiq; + void *alloc_ctx; spinlock_t slock; diff --git a/drivers/media/pci/cx25821/cx25821-core.c b/drivers/media/pci/cx25821/cx25821-core.c index e81173c41e5..389fffd2f36 100644 --- a/drivers/media/pci/cx25821/cx25821-core.c +++ b/drivers/media/pci/cx25821/cx25821-core.c @@ -996,7 +996,7 @@ static __le32 *cx25821_risc_field(__le32 * rp, struct scatterlist *sglist, for (line = 0; line < lines; line++) { while (offset && offset >= sg_dma_len(sg)) { offset -= sg_dma_len(sg); - sg++; + sg = sg_next(sg); } if (bpl <= sg_dma_len(sg) - offset) { /* fits into current chunk */ @@ -1014,14 +1014,14 @@ static __le32 *cx25821_risc_field(__le32 * rp, struct scatterlist *sglist, *(rp++) = cpu_to_le32(0); /* bits 63-32 */ todo -= (sg_dma_len(sg) - offset); offset = 0; - sg++; + sg = sg_next(sg); while (todo > sg_dma_len(sg)) { *(rp++) = cpu_to_le32(RISC_WRITE | sg_dma_len(sg)); *(rp++) = cpu_to_le32(sg_dma_address(sg)); *(rp++) = cpu_to_le32(0); /* bits 63-32 */ todo -= sg_dma_len(sg); - sg++; + sg = sg_next(sg); } *(rp++) = cpu_to_le32(RISC_WRITE | RISC_EOL | todo); *(rp++) = cpu_to_le32(sg_dma_address(sg)); @@ -1101,7 +1101,7 @@ static __le32 *cx25821_risc_field_audio(__le32 * rp, struct scatterlist *sglist, for (line = 0; line < lines; line++) { while (offset && offset >= sg_dma_len(sg)) { offset -= sg_dma_len(sg); - sg++; + sg = sg_next(sg); } if (lpi && line > 0 && !(line % lpi)) @@ -1125,14 +1125,14 @@ static __le32 *cx25821_risc_field_audio(__le32 * rp, struct scatterlist *sglist, *(rp++) = cpu_to_le32(0); /* bits 63-32 */ todo -= (sg_dma_len(sg) - offset); offset = 0; - sg++; + sg = sg_next(sg); while (todo > sg_dma_len(sg)) { *(rp++) = cpu_to_le32(RISC_WRITE | sg_dma_len(sg)); *(rp++) = cpu_to_le32(sg_dma_address(sg)); *(rp++) = cpu_to_le32(0); /* bits 63-32 */ todo -= sg_dma_len(sg); - sg++; + sg = sg_next(sg); } *(rp++) = cpu_to_le32(RISC_WRITE | RISC_EOL | todo); *(rp++) = cpu_to_le32(sg_dma_address(sg)); diff --git a/drivers/media/pci/cx88/Kconfig b/drivers/media/pci/cx88/Kconfig index a63a9ad163b..14b813d634a 100644 --- a/drivers/media/pci/cx88/Kconfig +++ b/drivers/media/pci/cx88/Kconfig @@ -2,8 +2,7 @@ config VIDEO_CX88 tristate "Conexant 2388x (bt878 successor) support" depends on VIDEO_DEV && PCI && I2C && RC_CORE select I2C_ALGOBIT - select VIDEO_BTCX - select VIDEOBUF_DMA_SG + select VIDEOBUF2_DMA_SG select VIDEO_TUNER select VIDEO_TVEEPROM select VIDEO_WM8775 if MEDIA_SUBDRV_AUTOSELECT @@ -45,7 +44,7 @@ config VIDEO_CX88_BLACKBIRD config VIDEO_CX88_DVB tristate "DVB/ATSC Support for cx2388x based TV cards" depends on VIDEO_CX88 && DVB_CORE - select VIDEOBUF_DVB + select VIDEOBUF2_DVB select DVB_PLL if MEDIA_SUBDRV_AUTOSELECT select DVB_MT352 if MEDIA_SUBDRV_AUTOSELECT select DVB_ZL10353 if MEDIA_SUBDRV_AUTOSELECT diff --git a/drivers/media/pci/cx88/Makefile b/drivers/media/pci/cx88/Makefile index 8619c1becee..d3679c3ee24 100644 --- a/drivers/media/pci/cx88/Makefile +++ b/drivers/media/pci/cx88/Makefile @@ -11,7 +11,6 @@ obj-$(CONFIG_VIDEO_CX88_DVB) += cx88-dvb.o obj-$(CONFIG_VIDEO_CX88_VP3054) += cx88-vp3054-i2c.o ccflags-y += -Idrivers/media/i2c -ccflags-y += -Idrivers/media/common ccflags-y += -Idrivers/media/tuners ccflags-y += -Idrivers/media/dvb-core ccflags-y += -Idrivers/media/dvb-frontends diff --git a/drivers/media/pci/cx88/cx88-alsa.c b/drivers/media/pci/cx88/cx88-alsa.c index a72579a9f67..7f8dc60028d 100644 --- a/drivers/media/pci/cx88/cx88-alsa.c +++ b/drivers/media/pci/cx88/cx88-alsa.c @@ -61,8 +61,11 @@ struct cx88_audio_buffer { unsigned int bpl; - struct btcx_riscmem risc; - struct videobuf_dmabuf dma; + struct cx88_riscmem risc; + void *vaddr; + struct scatterlist *sglist; + int sglen; + int nr_pages; }; struct cx88_audio_dev { @@ -84,8 +87,6 @@ struct cx88_audio_dev { unsigned int period_size; unsigned int num_periods; - struct videobuf_dmabuf *dma_risc; - struct cx88_audio_buffer *buf; struct snd_pcm_substream *substream; @@ -290,19 +291,97 @@ static irqreturn_t cx8801_irq(int irq, void *dev_id) return IRQ_RETVAL(handled); } +static int cx88_alsa_dma_init(struct cx88_audio_dev *chip, int nr_pages) +{ + struct cx88_audio_buffer *buf = chip->buf; + struct page *pg; + int i; + + buf->vaddr = vmalloc_32(nr_pages << PAGE_SHIFT); + if (NULL == buf->vaddr) { + dprintk(1, "vmalloc_32(%d pages) failed\n", nr_pages); + return -ENOMEM; + } + + dprintk(1, "vmalloc is at addr 0x%08lx, size=%d\n", + (unsigned long)buf->vaddr, + nr_pages << PAGE_SHIFT); + + memset(buf->vaddr, 0, nr_pages << PAGE_SHIFT); + buf->nr_pages = nr_pages; + + buf->sglist = vzalloc(buf->nr_pages * sizeof(*buf->sglist)); + if (NULL == buf->sglist) + goto vzalloc_err; + + sg_init_table(buf->sglist, buf->nr_pages); + for (i = 0; i < buf->nr_pages; i++) { + pg = vmalloc_to_page(buf->vaddr + i * PAGE_SIZE); + if (NULL == pg) + goto vmalloc_to_page_err; + sg_set_page(&buf->sglist[i], pg, PAGE_SIZE, 0); + } + return 0; + +vmalloc_to_page_err: + vfree(buf->sglist); + buf->sglist = NULL; +vzalloc_err: + vfree(buf->vaddr); + buf->vaddr = NULL; + return -ENOMEM; +} + +static int cx88_alsa_dma_map(struct cx88_audio_dev *dev) +{ + struct cx88_audio_buffer *buf = dev->buf; + + buf->sglen = dma_map_sg(&dev->pci->dev, buf->sglist, + buf->nr_pages, PCI_DMA_FROMDEVICE); + + if (0 == buf->sglen) { + pr_warn("%s: cx88_alsa_map_sg failed\n", __func__); + return -ENOMEM; + } + return 0; +} + +static int cx88_alsa_dma_unmap(struct cx88_audio_dev *dev) +{ + struct cx88_audio_buffer *buf = dev->buf; + + if (!buf->sglen) + return 0; + + dma_unmap_sg(&dev->pci->dev, buf->sglist, buf->sglen, PCI_DMA_FROMDEVICE); + buf->sglen = 0; + return 0; +} + +static int cx88_alsa_dma_free(struct cx88_audio_buffer *buf) +{ + vfree(buf->sglist); + buf->sglist = NULL; + vfree(buf->vaddr); + buf->vaddr = NULL; + return 0; +} + static int dsp_buffer_free(snd_cx88_card_t *chip) { + struct cx88_riscmem *risc = &chip->buf->risc; + BUG_ON(!chip->dma_size); dprintk(2,"Freeing buffer\n"); - videobuf_dma_unmap(&chip->pci->dev, chip->dma_risc); - videobuf_dma_free(chip->dma_risc); - btcx_riscmem_free(chip->pci,&chip->buf->risc); + cx88_alsa_dma_unmap(chip); + cx88_alsa_dma_free(chip->buf); + if (risc->cpu) + pci_free_consistent(chip->pci, risc->size, risc->cpu, risc->dma); kfree(chip->buf); - chip->dma_risc = NULL; - chip->dma_size = 0; + chip->buf = NULL; return 0; } @@ -387,7 +466,6 @@ static int snd_cx88_hw_params(struct snd_pcm_substream * substream, struct snd_pcm_hw_params * hw_params) { snd_cx88_card_t *chip = snd_pcm_substream_chip(substream); - struct videobuf_dmabuf *dma; struct cx88_audio_buffer *buf; int ret; @@ -408,20 +486,19 @@ static int snd_cx88_hw_params(struct snd_pcm_substream * substream, if (NULL == buf) return -ENOMEM; + chip->buf = buf; buf->bpl = chip->period_size; - dma = &buf->dma; - videobuf_dma_init(dma); - ret = videobuf_dma_init_kernel(dma, PCI_DMA_FROMDEVICE, + ret = cx88_alsa_dma_init(chip, (PAGE_ALIGN(chip->dma_size) >> PAGE_SHIFT)); if (ret < 0) goto error; - ret = videobuf_dma_map(&chip->pci->dev, dma); + ret = cx88_alsa_dma_map(chip); if (ret < 0) goto error; - ret = cx88_risc_databuffer(chip->pci, &buf->risc, dma->sglist, + ret = cx88_risc_databuffer(chip->pci, &buf->risc, buf->sglist, chip->period_size, chip->num_periods, 1); if (ret < 0) goto error; @@ -430,10 +507,7 @@ static int snd_cx88_hw_params(struct snd_pcm_substream * substream, buf->risc.jmp[0] = cpu_to_le32(RISC_JUMP|RISC_IRQ1|RISC_CNT_INC); buf->risc.jmp[1] = cpu_to_le32(buf->risc.dma); - chip->buf = buf; - chip->dma_risc = dma; - - substream->runtime->dma_area = chip->dma_risc->vaddr; + substream->runtime->dma_area = chip->buf->vaddr; substream->runtime->dma_bytes = chip->dma_size; substream->runtime->dma_addr = 0; return 0; diff --git a/drivers/media/pci/cx88/cx88-blackbird.c b/drivers/media/pci/cx88/cx88-blackbird.c index 150bb76e783..4160ca4e541 100644 --- a/drivers/media/pci/cx88/cx88-blackbird.c +++ b/drivers/media/pci/cx88/cx88-blackbird.c @@ -45,10 +45,6 @@ MODULE_AUTHOR("Jelle Foks <jelle@foks.us>, Gerd Knorr <kraxel@bytesex.org> [SuSE MODULE_LICENSE("GPL"); MODULE_VERSION(CX88_VERSION); -static unsigned int mpegbufs = 32; -module_param(mpegbufs,int,0644); -MODULE_PARM_DESC(mpegbufs,"number of mpeg buffers, range 2-32"); - static unsigned int debug; module_param(debug,int,0644); MODULE_PARM_DESC(debug,"enable debug messages [blackbird]"); @@ -326,13 +322,13 @@ static int blackbird_mbox_func(void *priv, u32 command, int in, int out, u32 dat memory_read(dev->core, dev->mailbox - 4, &value); if (value != 0x12345678) { dprintk(0, "Firmware and/or mailbox pointer not initialized or corrupted\n"); - return -1; + return -EIO; } memory_read(dev->core, dev->mailbox, &flag); if (flag) { dprintk(0, "ERROR: Mailbox appears to be in use (%x)\n", flag); - return -1; + return -EIO; } flag |= 1; /* tell 'em we're working on it */ @@ -352,14 +348,14 @@ static int blackbird_mbox_func(void *priv, u32 command, int in, int out, u32 dat memory_write(dev->core, dev->mailbox, flag); /* wait for firmware to handle the API command */ - timeout = jiffies + msecs_to_jiffies(10); + timeout = jiffies + msecs_to_jiffies(1000); for (;;) { memory_read(dev->core, dev->mailbox, &flag); if (0 != (flag & 4)) break; if (time_after(jiffies,timeout)) { - dprintk(0, "ERROR: API Mailbox timeout\n"); - return -1; + dprintk(0, "ERROR: API Mailbox timeout %x\n", command); + return -EIO; } udelay(10); } @@ -420,7 +416,7 @@ static int blackbird_find_mailbox(struct cx8802_dev *dev) } } dprintk(0, "Mailbox signature values not found!\n"); - return -1; + return -EIO; } static int blackbird_load_firmware(struct cx8802_dev *dev) @@ -432,7 +428,7 @@ static int blackbird_load_firmware(struct cx8802_dev *dev) int i, retval = 0; u32 value = 0; u32 checksum = 0; - u32 *dataptr; + __le32 *dataptr; retval = register_write(dev->core, IVTV_REG_VPU, 0xFFFFFFED); retval |= register_write(dev->core, IVTV_REG_HW_BLOCKS, IVTV_CMD_HW_BLOCKS_RST); @@ -449,29 +445,28 @@ static int blackbird_load_firmware(struct cx8802_dev *dev) if (retval != 0) { - dprintk(0, "ERROR: Hotplug firmware request failed (%s).\n", + pr_err("Hotplug firmware request failed (%s).\n", CX2341X_FIRM_ENC_FILENAME); - dprintk(0, "Please fix your hotplug setup, the board will " - "not work without firmware loaded!\n"); - return -1; + pr_err("Please fix your hotplug setup, the board will not work without firmware loaded!\n"); + return -EIO; } if (firmware->size != BLACKBIRD_FIRM_IMAGE_SIZE) { - dprintk(0, "ERROR: Firmware size mismatch (have %zd, expected %d)\n", + pr_err("Firmware size mismatch (have %zd, expected %d)\n", firmware->size, BLACKBIRD_FIRM_IMAGE_SIZE); release_firmware(firmware); - return -1; + return -EINVAL; } if (0 != memcmp(firmware->data, magic, 8)) { - dprintk(0, "ERROR: Firmware magic mismatch, wrong file?\n"); + pr_err("Firmware magic mismatch, wrong file?\n"); release_firmware(firmware); - return -1; + return -EINVAL; } /* transfer to the chip */ dprintk(1,"Loading firmware ...\n"); - dataptr = (u32*)firmware->data; + dataptr = (__le32 *)firmware->data; for (i = 0; i < (firmware->size >> 2); i++) { value = le32_to_cpu(*dataptr); checksum += ~value; @@ -484,12 +479,11 @@ static int blackbird_load_firmware(struct cx8802_dev *dev) memory_read(dev->core, i, &value); checksum -= ~value; } + release_firmware(firmware); if (checksum) { - dprintk(0, "ERROR: Firmware load failed (checksum mismatch).\n"); - release_firmware(firmware); - return -1; + pr_err("Firmware load might have failed (checksum mismatch).\n"); + return -EIO; } - release_firmware(firmware); dprintk(0, "Firmware upload successful.\n"); retval |= register_write(dev->core, IVTV_REG_HW_BLOCKS, IVTV_CMD_HW_BLOCKS_RST); @@ -521,12 +515,14 @@ DB* DVD | MPEG2 | 720x576PAL | CBR | 600 :Good | 6000 Kbps | 25fps | M static void blackbird_codec_settings(struct cx8802_dev *dev) { + struct cx88_core *core = dev->core; + /* assign frame size */ blackbird_api_cmd(dev, CX2341X_ENC_SET_FRAME_SIZE, 2, 0, - dev->height, dev->width); + core->height, core->width); - dev->cxhdl.width = dev->width; - dev->cxhdl.height = dev->height; + dev->cxhdl.width = core->width; + dev->cxhdl.height = core->height; cx2341x_handler_set_50hz(&dev->cxhdl, dev->core->tvnorm & V4L2_STD_625_50); cx2341x_handler_setup(&dev->cxhdl); } @@ -540,9 +536,6 @@ static int blackbird_initialize_codec(struct cx8802_dev *dev) dprintk(1,"Initialize codec\n"); retval = blackbird_api_cmd(dev, CX2341X_ENC_PING_FW, 0, 0); /* ping */ if (retval < 0) { - - dev->mpeg_active = 0; - /* ping was not successful, reset and upload firmware */ cx_write(MO_SRST_IO, 0); /* SYS_RSTO=0 */ cx_write(MO_SRST_IO, 1); /* SYS_RSTO=1 */ @@ -589,9 +582,8 @@ static int blackbird_initialize_codec(struct cx8802_dev *dev) return 0; } -static int blackbird_start_codec(struct file *file, void *priv) +static int blackbird_start_codec(struct cx8802_dev *dev) { - struct cx8802_dev *dev = ((struct cx8802_fh *)priv)->dev; struct cx88_core *core = dev->core; /* start capturing to the host interface */ u32 reg; @@ -627,7 +619,6 @@ static int blackbird_start_codec(struct file *file, void *priv) BLACKBIRD_RAW_BITS_NONE ); - dev->mpeg_active = 1; return 0; } @@ -641,51 +632,139 @@ static int blackbird_stop_codec(struct cx8802_dev *dev) cx2341x_handler_set_busy(&dev->cxhdl, 0); - dev->mpeg_active = 0; return 0; } /* ------------------------------------------------------------------ */ -static int bb_buf_setup(struct videobuf_queue *q, - unsigned int *count, unsigned int *size) +static int queue_setup(struct vb2_queue *q, const struct v4l2_format *fmt, + unsigned int *num_buffers, unsigned int *num_planes, + unsigned int sizes[], void *alloc_ctxs[]) { - struct cx8802_fh *fh = q->priv_data; - - fh->dev->ts_packet_size = 188 * 4; /* was: 512 */ - fh->dev->ts_packet_count = mpegbufs; /* was: 100 */ + struct cx8802_dev *dev = q->drv_priv; - *size = fh->dev->ts_packet_size * fh->dev->ts_packet_count; - *count = fh->dev->ts_packet_count; + *num_planes = 1; + dev->ts_packet_size = 188 * 4; + dev->ts_packet_count = 32; + sizes[0] = dev->ts_packet_size * dev->ts_packet_count; return 0; } -static int -bb_buf_prepare(struct videobuf_queue *q, struct videobuf_buffer *vb, - enum v4l2_field field) +static int buffer_prepare(struct vb2_buffer *vb) { - struct cx8802_fh *fh = q->priv_data; - return cx8802_buf_prepare(q, fh->dev, (struct cx88_buffer*)vb, field); + struct cx8802_dev *dev = vb->vb2_queue->drv_priv; + struct cx88_buffer *buf = container_of(vb, struct cx88_buffer, vb); + + return cx8802_buf_prepare(vb->vb2_queue, dev, buf); } -static void -bb_buf_queue(struct videobuf_queue *q, struct videobuf_buffer *vb) +static void buffer_finish(struct vb2_buffer *vb) { - struct cx8802_fh *fh = q->priv_data; - cx8802_buf_queue(fh->dev, (struct cx88_buffer*)vb); + struct cx8802_dev *dev = vb->vb2_queue->drv_priv; + struct cx88_buffer *buf = container_of(vb, struct cx88_buffer, vb); + struct sg_table *sgt = vb2_dma_sg_plane_desc(vb, 0); + struct cx88_riscmem *risc = &buf->risc; + + if (risc->cpu) + pci_free_consistent(dev->pci, risc->size, risc->cpu, risc->dma); + memset(risc, 0, sizeof(*risc)); + + dma_unmap_sg(&dev->pci->dev, sgt->sgl, sgt->nents, DMA_FROM_DEVICE); } -static void -bb_buf_release(struct videobuf_queue *q, struct videobuf_buffer *vb) +static void buffer_queue(struct vb2_buffer *vb) { - cx88_free_buffer(q, (struct cx88_buffer*)vb); + struct cx8802_dev *dev = vb->vb2_queue->drv_priv; + struct cx88_buffer *buf = container_of(vb, struct cx88_buffer, vb); + + cx8802_buf_queue(dev, buf); +} + +static int start_streaming(struct vb2_queue *q, unsigned int count) +{ + struct cx8802_dev *dev = q->drv_priv; + struct cx88_dmaqueue *dmaq = &dev->mpegq; + struct cx8802_driver *drv; + struct cx88_buffer *buf; + unsigned long flags; + int err; + + /* Make sure we can acquire the hardware */ + drv = cx8802_get_driver(dev, CX88_MPEG_BLACKBIRD); + if (!drv) { + dprintk(1, "%s: blackbird driver is not loaded\n", __func__); + err = -ENODEV; + goto fail; + } + + err = drv->request_acquire(drv); + if (err != 0) { + dprintk(1, "%s: Unable to acquire hardware, %d\n", __func__, err); + goto fail; + } + + if (blackbird_initialize_codec(dev) < 0) { + drv->request_release(drv); + err = -EINVAL; + goto fail; + } + + err = blackbird_start_codec(dev); + if (err == 0) { + buf = list_entry(dmaq->active.next, struct cx88_buffer, list); + cx8802_start_dma(dev, dmaq, buf); + return 0; + } + +fail: + spin_lock_irqsave(&dev->slock, flags); + while (!list_empty(&dmaq->active)) { + struct cx88_buffer *buf = list_entry(dmaq->active.next, + struct cx88_buffer, list); + + list_del(&buf->list); + vb2_buffer_done(&buf->vb, VB2_BUF_STATE_QUEUED); + } + spin_unlock_irqrestore(&dev->slock, flags); + return err; } -static struct videobuf_queue_ops blackbird_qops = { - .buf_setup = bb_buf_setup, - .buf_prepare = bb_buf_prepare, - .buf_queue = bb_buf_queue, - .buf_release = bb_buf_release, +static void stop_streaming(struct vb2_queue *q) +{ + struct cx8802_dev *dev = q->drv_priv; + struct cx88_dmaqueue *dmaq = &dev->mpegq; + struct cx8802_driver *drv = NULL; + unsigned long flags; + + cx8802_cancel_buffers(dev); + blackbird_stop_codec(dev); + + /* Make sure we release the hardware */ + drv = cx8802_get_driver(dev, CX88_MPEG_BLACKBIRD); + WARN_ON(!drv); + if (drv) + drv->request_release(drv); + + spin_lock_irqsave(&dev->slock, flags); + while (!list_empty(&dmaq->active)) { + struct cx88_buffer *buf = list_entry(dmaq->active.next, + struct cx88_buffer, list); + + list_del(&buf->list); + vb2_buffer_done(&buf->vb, VB2_BUF_STATE_ERROR); + } + spin_unlock_irqrestore(&dev->slock, flags); +} + +static struct vb2_ops blackbird_qops = { + .queue_setup = queue_setup, + .buf_prepare = buffer_prepare, + .buf_finish = buffer_finish, + .buf_queue = buffer_queue, + .wait_prepare = vb2_ops_wait_prepare, + .wait_finish = vb2_ops_wait_finish, + .start_streaming = start_streaming, + .stop_streaming = stop_streaming, }; /* ------------------------------------------------------------------ */ @@ -693,8 +772,8 @@ static struct videobuf_queue_ops blackbird_qops = { static int vidioc_querycap(struct file *file, void *priv, struct v4l2_capability *cap) { - struct cx8802_dev *dev = ((struct cx8802_fh *)priv)->dev; - struct cx88_core *core = dev->core; + struct cx8802_dev *dev = video_drvdata(file); + struct cx88_core *core = dev->core; strcpy(cap->driver, "cx88_blackbird"); sprintf(cap->bus_info, "PCI:%s", pci_name(dev->pci)); @@ -714,131 +793,111 @@ static int vidioc_enum_fmt_vid_cap (struct file *file, void *priv, return 0; } -static int vidioc_g_fmt_vid_cap (struct file *file, void *priv, +static int vidioc_g_fmt_vid_cap(struct file *file, void *priv, struct v4l2_format *f) { - struct cx8802_fh *fh = priv; - struct cx8802_dev *dev = fh->dev; + struct cx8802_dev *dev = video_drvdata(file); + struct cx88_core *core = dev->core; f->fmt.pix.pixelformat = V4L2_PIX_FMT_MPEG; f->fmt.pix.bytesperline = 0; - f->fmt.pix.sizeimage = 188 * 4 * mpegbufs; /* 188 * 4 * 1024; */ + f->fmt.pix.sizeimage = dev->ts_packet_size * dev->ts_packet_count; f->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M; - f->fmt.pix.width = dev->width; - f->fmt.pix.height = dev->height; - f->fmt.pix.field = fh->mpegq.field; - dprintk(1, "VIDIOC_G_FMT: w: %d, h: %d, f: %d\n", - dev->width, dev->height, fh->mpegq.field ); + f->fmt.pix.width = core->width; + f->fmt.pix.height = core->height; + f->fmt.pix.field = core->field; return 0; } -static int vidioc_try_fmt_vid_cap (struct file *file, void *priv, +static int vidioc_try_fmt_vid_cap(struct file *file, void *priv, struct v4l2_format *f) { - struct cx8802_fh *fh = priv; - struct cx8802_dev *dev = fh->dev; + struct cx8802_dev *dev = video_drvdata(file); + struct cx88_core *core = dev->core; + unsigned maxw, maxh; + enum v4l2_field field; f->fmt.pix.pixelformat = V4L2_PIX_FMT_MPEG; f->fmt.pix.bytesperline = 0; - f->fmt.pix.sizeimage = 188 * 4 * mpegbufs; /* 188 * 4 * 1024; */ + f->fmt.pix.sizeimage = dev->ts_packet_size * dev->ts_packet_count; f->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M; - dprintk(1, "VIDIOC_TRY_FMT: w: %d, h: %d, f: %d\n", - dev->width, dev->height, fh->mpegq.field ); + + maxw = norm_maxw(core->tvnorm); + maxh = norm_maxh(core->tvnorm); + + field = f->fmt.pix.field; + + switch (field) { + case V4L2_FIELD_TOP: + case V4L2_FIELD_BOTTOM: + case V4L2_FIELD_INTERLACED: + case V4L2_FIELD_SEQ_BT: + case V4L2_FIELD_SEQ_TB: + break; + default: + field = (f->fmt.pix.height > maxh / 2) + ? V4L2_FIELD_INTERLACED + : V4L2_FIELD_BOTTOM; + break; + } + if (V4L2_FIELD_HAS_T_OR_B(field)) + maxh /= 2; + + v4l_bound_align_image(&f->fmt.pix.width, 48, maxw, 2, + &f->fmt.pix.height, 32, maxh, 0, 0); + f->fmt.pix.field = field; return 0; } -static int vidioc_s_fmt_vid_cap (struct file *file, void *priv, +static int vidioc_s_fmt_vid_cap(struct file *file, void *priv, struct v4l2_format *f) { - struct cx8802_fh *fh = priv; - struct cx8802_dev *dev = fh->dev; + struct cx8802_dev *dev = video_drvdata(file); struct cx88_core *core = dev->core; - f->fmt.pix.pixelformat = V4L2_PIX_FMT_MPEG; - f->fmt.pix.bytesperline = 0; - f->fmt.pix.sizeimage = 188 * 4 * mpegbufs; /* 188 * 4 * 1024; */ - f->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M; - dev->width = f->fmt.pix.width; - dev->height = f->fmt.pix.height; - fh->mpegq.field = f->fmt.pix.field; + if (vb2_is_busy(&dev->vb2_mpegq)) + return -EBUSY; + if (core->v4ldev && (vb2_is_busy(&core->v4ldev->vb2_vidq) || + vb2_is_busy(&core->v4ldev->vb2_vbiq))) + return -EBUSY; + vidioc_try_fmt_vid_cap(file, priv, f); + core->width = f->fmt.pix.width; + core->height = f->fmt.pix.height; + core->field = f->fmt.pix.field; cx88_set_scale(core, f->fmt.pix.width, f->fmt.pix.height, f->fmt.pix.field); blackbird_api_cmd(dev, CX2341X_ENC_SET_FRAME_SIZE, 2, 0, f->fmt.pix.height, f->fmt.pix.width); - dprintk(1, "VIDIOC_S_FMT: w: %d, h: %d, f: %d\n", - f->fmt.pix.width, f->fmt.pix.height, f->fmt.pix.field ); return 0; } -static int vidioc_reqbufs (struct file *file, void *priv, struct v4l2_requestbuffers *p) -{ - struct cx8802_fh *fh = priv; - return (videobuf_reqbufs(&fh->mpegq, p)); -} - -static int vidioc_querybuf (struct file *file, void *priv, struct v4l2_buffer *p) -{ - struct cx8802_fh *fh = priv; - return (videobuf_querybuf(&fh->mpegq, p)); -} - -static int vidioc_qbuf (struct file *file, void *priv, struct v4l2_buffer *p) -{ - struct cx8802_fh *fh = priv; - return (videobuf_qbuf(&fh->mpegq, p)); -} - -static int vidioc_dqbuf (struct file *file, void *priv, struct v4l2_buffer *p) -{ - struct cx8802_fh *fh = priv; - return (videobuf_dqbuf(&fh->mpegq, p, - file->f_flags & O_NONBLOCK)); -} - -static int vidioc_streamon(struct file *file, void *priv, enum v4l2_buf_type i) -{ - struct cx8802_fh *fh = priv; - struct cx8802_dev *dev = fh->dev; - - if (!dev->mpeg_active) - blackbird_start_codec(file, fh); - return videobuf_streamon(&fh->mpegq); -} - -static int vidioc_streamoff(struct file *file, void *priv, enum v4l2_buf_type i) -{ - struct cx8802_fh *fh = priv; - struct cx8802_dev *dev = fh->dev; - - if (dev->mpeg_active) - blackbird_stop_codec(dev); - return videobuf_streamoff(&fh->mpegq); -} - static int vidioc_s_frequency (struct file *file, void *priv, const struct v4l2_frequency *f) { - struct cx8802_fh *fh = priv; - struct cx8802_dev *dev = fh->dev; - struct cx88_core *core = dev->core; + struct cx8802_dev *dev = video_drvdata(file); + struct cx88_core *core = dev->core; + bool streaming; if (unlikely(UNSET == core->board.tuner_type)) return -EINVAL; if (unlikely(f->tuner != 0)) return -EINVAL; - if (dev->mpeg_active) + streaming = vb2_start_streaming_called(&dev->vb2_mpegq); + if (streaming) blackbird_stop_codec(dev); cx88_set_freq (core,f); blackbird_initialize_codec(dev); - cx88_set_scale(dev->core, dev->width, dev->height, - fh->mpegq.field); + cx88_set_scale(core, core->width, core->height, + core->field); + if (streaming) + blackbird_start_codec(dev); return 0; } static int vidioc_log_status (struct file *file, void *priv) { - struct cx8802_dev *dev = ((struct cx8802_fh *)priv)->dev; - struct cx88_core *core = dev->core; + struct cx8802_dev *dev = video_drvdata(file); + struct cx88_core *core = dev->core; char name[32 + 2]; snprintf(name, sizeof(name), "%s/2", core->name); @@ -850,15 +909,16 @@ static int vidioc_log_status (struct file *file, void *priv) static int vidioc_enum_input (struct file *file, void *priv, struct v4l2_input *i) { - struct cx88_core *core = ((struct cx8802_fh *)priv)->dev->core; + struct cx8802_dev *dev = video_drvdata(file); + struct cx88_core *core = dev->core; return cx88_enum_input (core,i); } static int vidioc_g_frequency (struct file *file, void *priv, struct v4l2_frequency *f) { - struct cx8802_fh *fh = priv; - struct cx88_core *core = fh->dev->core; + struct cx8802_dev *dev = video_drvdata(file); + struct cx88_core *core = dev->core; if (unlikely(UNSET == core->board.tuner_type)) return -EINVAL; @@ -873,7 +933,8 @@ static int vidioc_g_frequency (struct file *file, void *priv, static int vidioc_g_input (struct file *file, void *priv, unsigned int *i) { - struct cx88_core *core = ((struct cx8802_fh *)priv)->dev->core; + struct cx8802_dev *dev = video_drvdata(file); + struct cx88_core *core = dev->core; *i = core->input; return 0; @@ -881,24 +942,24 @@ static int vidioc_g_input (struct file *file, void *priv, unsigned int *i) static int vidioc_s_input (struct file *file, void *priv, unsigned int i) { - struct cx88_core *core = ((struct cx8802_fh *)priv)->dev->core; + struct cx8802_dev *dev = video_drvdata(file); + struct cx88_core *core = dev->core; if (i >= 4) return -EINVAL; if (0 == INPUT(i).type) return -EINVAL; - mutex_lock(&core->lock); cx88_newstation(core); cx88_video_mux(core,i); - mutex_unlock(&core->lock); return 0; } static int vidioc_g_tuner (struct file *file, void *priv, struct v4l2_tuner *t) { - struct cx88_core *core = ((struct cx8802_fh *)priv)->dev->core; + struct cx8802_dev *dev = video_drvdata(file); + struct cx88_core *core = dev->core; u32 reg; if (unlikely(UNSET == core->board.tuner_type)) @@ -920,7 +981,8 @@ static int vidioc_g_tuner (struct file *file, void *priv, static int vidioc_s_tuner (struct file *file, void *priv, const struct v4l2_tuner *t) { - struct cx88_core *core = ((struct cx8802_fh *)priv)->dev->core; + struct cx8802_dev *dev = video_drvdata(file); + struct cx88_core *core = dev->core; if (UNSET == core->board.tuner_type) return -EINVAL; @@ -933,7 +995,8 @@ static int vidioc_s_tuner (struct file *file, void *priv, static int vidioc_g_std(struct file *file, void *priv, v4l2_std_id *tvnorm) { - struct cx88_core *core = ((struct cx8802_fh *)priv)->dev->core; + struct cx8802_dev *dev = video_drvdata(file); + struct cx88_core *core = dev->core; *tvnorm = core->tvnorm; return 0; @@ -941,155 +1004,20 @@ static int vidioc_g_std(struct file *file, void *priv, v4l2_std_id *tvnorm) static int vidioc_s_std(struct file *file, void *priv, v4l2_std_id id) { - struct cx88_core *core = ((struct cx8802_fh *)priv)->dev->core; - - mutex_lock(&core->lock); - cx88_set_tvnorm(core, id); - mutex_unlock(&core->lock); - return 0; -} - -/* FIXME: cx88_ioctl_hook not implemented */ - -static int mpeg_open(struct file *file) -{ - struct video_device *vdev = video_devdata(file); struct cx8802_dev *dev = video_drvdata(file); - struct cx8802_fh *fh; - struct cx8802_driver *drv = NULL; - int err; - - dprintk( 1, "%s\n", __func__); - - mutex_lock(&dev->core->lock); - - /* Make sure we can acquire the hardware */ - drv = cx8802_get_driver(dev, CX88_MPEG_BLACKBIRD); - if (!drv) { - dprintk(1, "%s: blackbird driver is not loaded\n", __func__); - mutex_unlock(&dev->core->lock); - return -ENODEV; - } - - err = drv->request_acquire(drv); - if (err != 0) { - dprintk(1,"%s: Unable to acquire hardware, %d\n", __func__, err); - mutex_unlock(&dev->core->lock); - return err; - } - - if (!dev->core->mpeg_users && blackbird_initialize_codec(dev) < 0) { - drv->request_release(drv); - mutex_unlock(&dev->core->lock); - return -EINVAL; - } - dprintk(1, "open dev=%s\n", video_device_node_name(vdev)); - - /* allocate + initialize per filehandle data */ - fh = kzalloc(sizeof(*fh),GFP_KERNEL); - if (NULL == fh) { - drv->request_release(drv); - mutex_unlock(&dev->core->lock); - return -ENOMEM; - } - v4l2_fh_init(&fh->fh, vdev); - file->private_data = fh; - fh->dev = dev; - - videobuf_queue_sg_init(&fh->mpegq, &blackbird_qops, - &dev->pci->dev, &dev->slock, - V4L2_BUF_TYPE_VIDEO_CAPTURE, - V4L2_FIELD_INTERLACED, - sizeof(struct cx88_buffer), - fh, NULL); - - /* FIXME: locking against other video device */ - cx88_set_scale(dev->core, dev->width, dev->height, - fh->mpegq.field); - - dev->core->mpeg_users++; - mutex_unlock(&dev->core->lock); - v4l2_fh_add(&fh->fh); - return 0; -} - -static int mpeg_release(struct file *file) -{ - struct cx8802_fh *fh = file->private_data; - struct cx8802_dev *dev = fh->dev; - struct cx8802_driver *drv = NULL; - - mutex_lock(&dev->core->lock); - - if (dev->mpeg_active && dev->core->mpeg_users == 1) - blackbird_stop_codec(dev); - - cx8802_cancel_buffers(fh->dev); - /* stop mpeg capture */ - videobuf_stop(&fh->mpegq); - - videobuf_mmap_free(&fh->mpegq); - - v4l2_fh_del(&fh->fh); - v4l2_fh_exit(&fh->fh); - file->private_data = NULL; - kfree(fh); - - /* Make sure we release the hardware */ - drv = cx8802_get_driver(dev, CX88_MPEG_BLACKBIRD); - WARN_ON(!drv); - if (drv) - drv->request_release(drv); - - dev->core->mpeg_users--; - - mutex_unlock(&dev->core->lock); - - return 0; -} - -static ssize_t -mpeg_read(struct file *file, char __user *data, size_t count, loff_t *ppos) -{ - struct cx8802_fh *fh = file->private_data; - struct cx8802_dev *dev = fh->dev; - - if (!dev->mpeg_active) - blackbird_start_codec(file, fh); - - return videobuf_read_stream(&fh->mpegq, data, count, ppos, 0, - file->f_flags & O_NONBLOCK); -} - -static unsigned int -mpeg_poll(struct file *file, struct poll_table_struct *wait) -{ - unsigned long req_events = poll_requested_events(wait); - struct cx8802_fh *fh = file->private_data; - struct cx8802_dev *dev = fh->dev; - - if (!dev->mpeg_active && (req_events & (POLLIN | POLLRDNORM))) - blackbird_start_codec(file, fh); - - return v4l2_ctrl_poll(file, wait) | videobuf_poll_stream(file, &fh->mpegq, wait); -} - -static int -mpeg_mmap(struct file *file, struct vm_area_struct * vma) -{ - struct cx8802_fh *fh = file->private_data; + struct cx88_core *core = dev->core; - return videobuf_mmap_mapper(&fh->mpegq, vma); + return cx88_set_tvnorm(core, id); } static const struct v4l2_file_operations mpeg_fops = { .owner = THIS_MODULE, - .open = mpeg_open, - .release = mpeg_release, - .read = mpeg_read, - .poll = mpeg_poll, - .mmap = mpeg_mmap, + .open = v4l2_fh_open, + .release = vb2_fop_release, + .read = vb2_fop_read, + .poll = vb2_fop_poll, + .mmap = vb2_fop_mmap, .unlocked_ioctl = video_ioctl2, }; @@ -1099,12 +1027,12 @@ static const struct v4l2_ioctl_ops mpeg_ioctl_ops = { .vidioc_g_fmt_vid_cap = vidioc_g_fmt_vid_cap, .vidioc_try_fmt_vid_cap = vidioc_try_fmt_vid_cap, .vidioc_s_fmt_vid_cap = vidioc_s_fmt_vid_cap, - .vidioc_reqbufs = vidioc_reqbufs, - .vidioc_querybuf = vidioc_querybuf, - .vidioc_qbuf = vidioc_qbuf, - .vidioc_dqbuf = vidioc_dqbuf, - .vidioc_streamon = vidioc_streamon, - .vidioc_streamoff = vidioc_streamoff, + .vidioc_reqbufs = vb2_ioctl_reqbufs, + .vidioc_querybuf = vb2_ioctl_querybuf, + .vidioc_qbuf = vb2_ioctl_qbuf, + .vidioc_dqbuf = vb2_ioctl_dqbuf, + .vidioc_streamon = vb2_ioctl_streamon, + .vidioc_streamoff = vb2_ioctl_streamoff, .vidioc_s_frequency = vidioc_s_frequency, .vidioc_log_status = vidioc_log_status, .vidioc_enum_input = vidioc_enum_input, @@ -1189,11 +1117,12 @@ static int blackbird_register_video(struct cx8802_dev *dev) { int err; - dev->mpeg_dev = cx88_vdev_init(dev->core,dev->pci, - &cx8802_mpeg_template,"mpeg"); + dev->mpeg_dev = cx88_vdev_init(dev->core, dev->pci, + &cx8802_mpeg_template, "mpeg"); dev->mpeg_dev->ctrl_handler = &dev->cxhdl.hdl; video_set_drvdata(dev->mpeg_dev, dev); - err = video_register_device(dev->mpeg_dev,VFL_TYPE_GRABBER, -1); + dev->mpeg_dev->queue = &dev->vb2_mpegq; + err = video_register_device(dev->mpeg_dev, VFL_TYPE_GRABBER, -1); if (err < 0) { printk(KERN_INFO "%s/2: can't register mpeg device\n", dev->core->name); @@ -1210,6 +1139,7 @@ static int cx8802_blackbird_probe(struct cx8802_driver *drv) { struct cx88_core *core = drv->core; struct cx8802_dev *dev = core->dvbdev; + struct vb2_queue *q; int err; dprintk( 1, "%s\n", __func__); @@ -1223,15 +1153,9 @@ static int cx8802_blackbird_probe(struct cx8802_driver *drv) if (!(core->board.mpeg & CX88_MPEG_BLACKBIRD)) goto fail_core; - dev->width = 720; - if (core->tvnorm & V4L2_STD_525_60) { - dev->height = 480; - } else { - dev->height = 576; - } dev->cxhdl.port = CX2341X_PORT_STREAMING; - dev->cxhdl.width = dev->width; - dev->cxhdl.height = dev->height; + dev->cxhdl.width = core->width; + dev->cxhdl.height = core->height; dev->cxhdl.func = blackbird_mbox_func; dev->cxhdl.priv = dev; err = cx2341x_handler_init(&dev->cxhdl, 36); @@ -1250,13 +1174,30 @@ static int cx8802_blackbird_probe(struct cx8802_driver *drv) // init_controls(core); cx88_set_tvnorm(core,core->tvnorm); cx88_video_mux(core,0); - cx2341x_handler_set_50hz(&dev->cxhdl, dev->height == 576); + cx2341x_handler_set_50hz(&dev->cxhdl, core->height == 576); cx2341x_handler_setup(&dev->cxhdl); + + q = &dev->vb2_mpegq; + q->type = V4L2_BUF_TYPE_VIDEO_CAPTURE; + q->io_modes = VB2_MMAP | VB2_USERPTR | VB2_DMABUF | VB2_READ; + q->gfp_flags = GFP_DMA32; + q->min_buffers_needed = 2; + q->drv_priv = dev; + q->buf_struct_size = sizeof(struct cx88_buffer); + q->ops = &blackbird_qops; + q->mem_ops = &vb2_dma_sg_memops; + q->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC; + q->lock = &core->lock; + + err = vb2_queue_init(q); + if (err < 0) + goto fail_core; + blackbird_register_video(dev); return 0; - fail_core: +fail_core: return err; } diff --git a/drivers/media/pci/cx88/cx88-cards.c b/drivers/media/pci/cx88/cx88-cards.c index 851754bf129..8f2556ec397 100644 --- a/drivers/media/pci/cx88/cx88-cards.c +++ b/drivers/media/pci/cx88/cx88-cards.c @@ -347,7 +347,7 @@ static const struct cx88_board cx88_boards[] = { }, [CX88_BOARD_IODATA_GVVCP3PCI] = { .name = "IODATA GV-VCP3/PCI", - .tuner_type = TUNER_ABSENT, + .tuner_type = UNSET, .radio_type = UNSET, .tuner_addr = ADDR_UNSET, .radio_addr = ADDR_UNSET, @@ -436,7 +436,7 @@ static const struct cx88_board cx88_boards[] = { }, [CX88_BOARD_KWORLD_DVB_T] = { .name = "KWorld/VStream XPert DVB-T", - .tuner_type = TUNER_ABSENT, + .tuner_type = UNSET, .radio_type = UNSET, .tuner_addr = ADDR_UNSET, .radio_addr = ADDR_UNSET, @@ -455,7 +455,7 @@ static const struct cx88_board cx88_boards[] = { }, [CX88_BOARD_DVICO_FUSIONHDTV_DVB_T1] = { .name = "DViCO FusionHDTV DVB-T1", - .tuner_type = TUNER_ABSENT, /* No analog tuner */ + .tuner_type = UNSET, /* No analog tuner */ .radio_type = UNSET, .tuner_addr = ADDR_UNSET, .radio_addr = ADDR_UNSET, @@ -542,7 +542,7 @@ static const struct cx88_board cx88_boards[] = { }, [CX88_BOARD_HAUPPAUGE_DVB_T1] = { .name = "Hauppauge Nova-T DVB-T", - .tuner_type = TUNER_ABSENT, + .tuner_type = UNSET, .radio_type = UNSET, .tuner_addr = ADDR_UNSET, .radio_addr = ADDR_UNSET, @@ -554,7 +554,7 @@ static const struct cx88_board cx88_boards[] = { }, [CX88_BOARD_CONEXANT_DVB_T1] = { .name = "Conexant DVB-T reference design", - .tuner_type = TUNER_ABSENT, + .tuner_type = UNSET, .radio_type = UNSET, .tuner_addr = ADDR_UNSET, .radio_addr = ADDR_UNSET, @@ -579,7 +579,7 @@ static const struct cx88_board cx88_boards[] = { }, [CX88_BOARD_DVICO_FUSIONHDTV_DVB_T_PLUS] = { .name = "DViCO FusionHDTV DVB-T Plus", - .tuner_type = TUNER_ABSENT, /* No analog tuner */ + .tuner_type = UNSET, /* No analog tuner */ .radio_type = UNSET, .tuner_addr = ADDR_UNSET, .radio_addr = ADDR_UNSET, @@ -596,7 +596,7 @@ static const struct cx88_board cx88_boards[] = { }, [CX88_BOARD_DNTV_LIVE_DVB_T] = { .name = "digitalnow DNTV Live! DVB-T", - .tuner_type = TUNER_ABSENT, + .tuner_type = UNSET, .radio_type = UNSET, .tuner_addr = ADDR_UNSET, .radio_addr = ADDR_UNSET, @@ -787,7 +787,7 @@ static const struct cx88_board cx88_boards[] = { }, [CX88_BOARD_ADSTECH_DVB_T_PCI] = { .name = "ADS Tech Instant TV DVB-T PCI", - .tuner_type = TUNER_ABSENT, + .tuner_type = UNSET, .radio_type = UNSET, .tuner_addr = ADDR_UNSET, .radio_addr = ADDR_UNSET, @@ -806,7 +806,7 @@ static const struct cx88_board cx88_boards[] = { }, [CX88_BOARD_TERRATEC_CINERGY_1400_DVB_T1] = { .name = "TerraTec Cinergy 1400 DVB-T", - .tuner_type = TUNER_ABSENT, + .tuner_type = UNSET, .input = { { .type = CX88_VMUX_DVB, .vmux = 0, @@ -924,7 +924,7 @@ static const struct cx88_board cx88_boards[] = { }, [CX88_BOARD_WINFAST_DTV1000] = { .name = "WinFast DTV1000-T", - .tuner_type = TUNER_ABSENT, + .tuner_type = UNSET, .radio_type = UNSET, .tuner_addr = ADDR_UNSET, .radio_addr = ADDR_UNSET, @@ -972,7 +972,7 @@ static const struct cx88_board cx88_boards[] = { }, [CX88_BOARD_HAUPPAUGE_NOVASPLUS_S1] = { .name = "Hauppauge Nova-S-Plus DVB-S", - .tuner_type = TUNER_ABSENT, + .tuner_type = UNSET, .radio_type = UNSET, .tuner_addr = ADDR_UNSET, .radio_addr = ADDR_UNSET, @@ -998,7 +998,7 @@ static const struct cx88_board cx88_boards[] = { }, [CX88_BOARD_HAUPPAUGE_NOVASE2_S1] = { .name = "Hauppauge Nova-SE2 DVB-S", - .tuner_type = TUNER_ABSENT, + .tuner_type = UNSET, .radio_type = UNSET, .tuner_addr = ADDR_UNSET, .radio_addr = ADDR_UNSET, @@ -1010,7 +1010,7 @@ static const struct cx88_board cx88_boards[] = { }, [CX88_BOARD_KWORLD_DVBS_100] = { .name = "KWorld DVB-S 100", - .tuner_type = TUNER_ABSENT, + .tuner_type = UNSET, .radio_type = UNSET, .tuner_addr = ADDR_UNSET, .radio_addr = ADDR_UNSET, @@ -1102,7 +1102,7 @@ static const struct cx88_board cx88_boards[] = { /* DTT 7579 Conexant CX22702-19 Conexant CX2388x */ /* Manenti Marco <marco_manenti@colman.it> */ .name = "KWorld/VStream XPert DVB-T with cx22702", - .tuner_type = TUNER_ABSENT, + .tuner_type = UNSET, .radio_type = UNSET, .tuner_addr = ADDR_UNSET, .radio_addr = ADDR_UNSET, @@ -1121,7 +1121,7 @@ static const struct cx88_board cx88_boards[] = { }, [CX88_BOARD_DVICO_FUSIONHDTV_DVB_T_DUAL] = { .name = "DViCO FusionHDTV DVB-T Dual Digital", - .tuner_type = TUNER_ABSENT, /* No analog tuner */ + .tuner_type = UNSET, /* No analog tuner */ .radio_type = UNSET, .tuner_addr = ADDR_UNSET, .radio_addr = ADDR_UNSET, @@ -1356,7 +1356,7 @@ static const struct cx88_board cx88_boards[] = { }, [CX88_BOARD_GENIATECH_DVBS] = { .name = "Geniatech DVB-S", - .tuner_type = TUNER_ABSENT, + .tuner_type = UNSET, .radio_type = UNSET, .tuner_addr = ADDR_UNSET, .radio_addr = ADDR_UNSET, @@ -1494,7 +1494,7 @@ static const struct cx88_board cx88_boards[] = { }, [CX88_BOARD_SAMSUNG_SMT_7020] = { .name = "Samsung SMT 7020 DVB-S", - .tuner_type = TUNER_ABSENT, + .tuner_type = UNSET, .radio_type = UNSET, .tuner_addr = ADDR_UNSET, .radio_addr = ADDR_UNSET, @@ -1506,7 +1506,7 @@ static const struct cx88_board cx88_boards[] = { }, [CX88_BOARD_ADSTECH_PTV_390] = { .name = "ADS Tech Instant Video PCI", - .tuner_type = TUNER_ABSENT, + .tuner_type = UNSET, .radio_type = UNSET, .tuner_addr = ADDR_UNSET, .radio_addr = ADDR_UNSET, @@ -1553,7 +1553,7 @@ static const struct cx88_board cx88_boards[] = { [CX88_BOARD_DVICO_FUSIONHDTV_5_PCI_NANO] = { .name = "DViCO FusionHDTV 5 PCI nano", /* xc3008 tuner, digital only for now */ - .tuner_type = TUNER_ABSENT, + .tuner_type = UNSET, .radio_type = UNSET, .tuner_addr = ADDR_UNSET, .radio_addr = ADDR_UNSET, @@ -2069,7 +2069,7 @@ static const struct cx88_board cx88_boards[] = { }, [CX88_BOARD_TBS_8920] = { .name = "TBS 8920 DVB-S/S2", - .tuner_type = TUNER_ABSENT, + .tuner_type = UNSET, .radio_type = UNSET, .tuner_addr = ADDR_UNSET, .radio_addr = ADDR_UNSET, @@ -2304,7 +2304,7 @@ static const struct cx88_board cx88_boards[] = { }, [CX88_BOARD_TWINHAN_VP1027_DVBS] = { .name = "Twinhan VP-1027 DVB-S", - .tuner_type = TUNER_ABSENT, + .tuner_type = UNSET, .radio_type = UNSET, .tuner_addr = ADDR_UNSET, .radio_addr = ADDR_UNSET, @@ -2921,33 +2921,33 @@ static const struct { int fm; const char *name; } gdi_tuner[] = { - [ 0x01 ] = { .id = TUNER_ABSENT, + [ 0x01 ] = { .id = UNSET, .name = "NTSC_M" }, - [ 0x02 ] = { .id = TUNER_ABSENT, + [ 0x02 ] = { .id = UNSET, .name = "PAL_B" }, - [ 0x03 ] = { .id = TUNER_ABSENT, + [ 0x03 ] = { .id = UNSET, .name = "PAL_I" }, - [ 0x04 ] = { .id = TUNER_ABSENT, + [ 0x04 ] = { .id = UNSET, .name = "PAL_D" }, - [ 0x05 ] = { .id = TUNER_ABSENT, + [ 0x05 ] = { .id = UNSET, .name = "SECAM" }, - [ 0x10 ] = { .id = TUNER_ABSENT, + [ 0x10 ] = { .id = UNSET, .fm = 1, .name = "TEMIC_4049" }, [ 0x11 ] = { .id = TUNER_TEMIC_4136FY5, .name = "TEMIC_4136" }, - [ 0x12 ] = { .id = TUNER_ABSENT, + [ 0x12 ] = { .id = UNSET, .name = "TEMIC_4146" }, [ 0x20 ] = { .id = TUNER_PHILIPS_FQ1216ME, .fm = 1, .name = "PHILIPS_FQ1216_MK3" }, - [ 0x21 ] = { .id = TUNER_ABSENT, .fm = 1, + [ 0x21 ] = { .id = UNSET, .fm = 1, .name = "PHILIPS_FQ1236_MK3" }, - [ 0x22 ] = { .id = TUNER_ABSENT, + [ 0x22 ] = { .id = UNSET, .name = "PHILIPS_FI1236_MK3" }, - [ 0x23 ] = { .id = TUNER_ABSENT, + [ 0x23 ] = { .id = UNSET, .name = "PHILIPS_FI1216_MK3" }, }; @@ -3564,7 +3564,7 @@ static void cx88_card_setup(struct cx88_core *core) mode_mask &= ~T_RADIO; } - if (core->board.tuner_type != TUNER_ABSENT) { + if (core->board.tuner_type != UNSET) { tun_setup.mode_mask = mode_mask; tun_setup.type = core->board.tuner_type; tun_setup.addr = core->board.tuner_addr; @@ -3691,6 +3691,11 @@ struct cx88_core *cx88_core_create(struct pci_dev *pci, int nr) core->nr = nr; sprintf(core->name, "cx88[%d]", core->nr); + core->tvnorm = V4L2_STD_NTSC_M; + core->width = 320; + core->height = 240; + core->field = V4L2_FIELD_INTERLACED; + strcpy(core->v4l2_dev.name, core->name); if (v4l2_device_register(NULL, &core->v4l2_dev)) { kfree(core); @@ -3772,7 +3777,7 @@ struct cx88_core *cx88_core_create(struct pci_dev *pci, int nr) cx88_i2c_init(core, pci); /* load tuner module, if needed */ - if (TUNER_ABSENT != core->board.tuner_type) { + if (UNSET != core->board.tuner_type) { /* Ignore 0x6b and 0x6f on cx88 boards. * FusionHDTV5 RT Gold has an ir receiver at 0x6b * and an RTC at 0x6f which can get corrupted if probed. */ diff --git a/drivers/media/pci/cx88/cx88-core.c b/drivers/media/pci/cx88/cx88-core.c index 71630238027..dee177ed5fe 100644 --- a/drivers/media/pci/cx88/cx88-core.c +++ b/drivers/media/pci/cx88/cx88-core.c @@ -76,11 +76,16 @@ static DEFINE_MUTEX(devlist); static __le32* cx88_risc_field(__le32 *rp, struct scatterlist *sglist, unsigned int offset, u32 sync_line, unsigned int bpl, unsigned int padding, - unsigned int lines, unsigned int lpi) + unsigned int lines, unsigned int lpi, bool jump) { struct scatterlist *sg; unsigned int line,todo,sol; + if (jump) { + (*rp++) = cpu_to_le32(RISC_JUMP); + (*rp++) = 0; + } + /* sync instruction */ if (sync_line != NO_SYNC_LINE) *(rp++) = cpu_to_le32(RISC_RESYNC | sync_line); @@ -90,7 +95,7 @@ static __le32* cx88_risc_field(__le32 *rp, struct scatterlist *sglist, for (line = 0; line < lines; line++) { while (offset && offset >= sg_dma_len(sg)) { offset -= sg_dma_len(sg); - sg++; + sg = sg_next(sg); } if (lpi && line>0 && !(line % lpi)) sol = RISC_SOL | RISC_IRQ1 | RISC_CNT_INC; @@ -109,13 +114,13 @@ static __le32* cx88_risc_field(__le32 *rp, struct scatterlist *sglist, *(rp++)=cpu_to_le32(sg_dma_address(sg)+offset); todo -= (sg_dma_len(sg)-offset); offset = 0; - sg++; + sg = sg_next(sg); while (todo > sg_dma_len(sg)) { *(rp++)=cpu_to_le32(RISC_WRITE| sg_dma_len(sg)); *(rp++)=cpu_to_le32(sg_dma_address(sg)); todo -= sg_dma_len(sg); - sg++; + sg = sg_next(sg); } *(rp++)=cpu_to_le32(RISC_WRITE|RISC_EOL|todo); *(rp++)=cpu_to_le32(sg_dma_address(sg)); @@ -127,14 +132,13 @@ static __le32* cx88_risc_field(__le32 *rp, struct scatterlist *sglist, return rp; } -int cx88_risc_buffer(struct pci_dev *pci, struct btcx_riscmem *risc, +int cx88_risc_buffer(struct pci_dev *pci, struct cx88_riscmem *risc, struct scatterlist *sglist, unsigned int top_offset, unsigned int bottom_offset, unsigned int bpl, unsigned int padding, unsigned int lines) { u32 instructions,fields; __le32 *rp; - int rc; fields = 0; if (UNSET != top_offset) @@ -147,18 +151,21 @@ int cx88_risc_buffer(struct pci_dev *pci, struct btcx_riscmem *risc, can cause next bpl to start close to a page border. First DMA region may be smaller than PAGE_SIZE */ instructions = fields * (1 + ((bpl + padding) * lines) / PAGE_SIZE + lines); - instructions += 2; - if ((rc = btcx_riscmem_alloc(pci,risc,instructions*8)) < 0) - return rc; + instructions += 4; + risc->size = instructions * 8; + risc->dma = 0; + risc->cpu = pci_zalloc_consistent(pci, risc->size, &risc->dma); + if (NULL == risc->cpu) + return -ENOMEM; /* write risc instructions */ rp = risc->cpu; if (UNSET != top_offset) rp = cx88_risc_field(rp, sglist, top_offset, 0, - bpl, padding, lines, 0); + bpl, padding, lines, 0, true); if (UNSET != bottom_offset) rp = cx88_risc_field(rp, sglist, bottom_offset, 0x200, - bpl, padding, lines, 0); + bpl, padding, lines, 0, top_offset == UNSET); /* save pointer to jmp instruction address */ risc->jmp = rp; @@ -166,26 +173,28 @@ int cx88_risc_buffer(struct pci_dev *pci, struct btcx_riscmem *risc, return 0; } -int cx88_risc_databuffer(struct pci_dev *pci, struct btcx_riscmem *risc, +int cx88_risc_databuffer(struct pci_dev *pci, struct cx88_riscmem *risc, struct scatterlist *sglist, unsigned int bpl, unsigned int lines, unsigned int lpi) { u32 instructions; __le32 *rp; - int rc; /* estimate risc mem: worst case is one write per page border + one write per scan line + syncs + jump (all 2 dwords). Here there is no padding and no sync. First DMA region may be smaller than PAGE_SIZE */ instructions = 1 + (bpl * lines) / PAGE_SIZE + lines; - instructions += 1; - if ((rc = btcx_riscmem_alloc(pci,risc,instructions*8)) < 0) - return rc; + instructions += 3; + risc->size = instructions * 8; + risc->dma = 0; + risc->cpu = pci_zalloc_consistent(pci, risc->size, &risc->dma); + if (NULL == risc->cpu) + return -ENOMEM; /* write risc instructions */ rp = risc->cpu; - rp = cx88_risc_field(rp, sglist, 0, NO_SYNC_LINE, bpl, 0, lines, lpi); + rp = cx88_risc_field(rp, sglist, 0, NO_SYNC_LINE, bpl, 0, lines, lpi, !lpi); /* save pointer to jmp instruction address */ risc->jmp = rp; @@ -193,39 +202,6 @@ int cx88_risc_databuffer(struct pci_dev *pci, struct btcx_riscmem *risc, return 0; } -int cx88_risc_stopper(struct pci_dev *pci, struct btcx_riscmem *risc, - u32 reg, u32 mask, u32 value) -{ - __le32 *rp; - int rc; - - if ((rc = btcx_riscmem_alloc(pci, risc, 4*16)) < 0) - return rc; - - /* write risc instructions */ - rp = risc->cpu; - *(rp++) = cpu_to_le32(RISC_WRITECR | RISC_IRQ2 | RISC_IMM); - *(rp++) = cpu_to_le32(reg); - *(rp++) = cpu_to_le32(value); - *(rp++) = cpu_to_le32(mask); - *(rp++) = cpu_to_le32(RISC_JUMP); - *(rp++) = cpu_to_le32(risc->dma); - return 0; -} - -void -cx88_free_buffer(struct videobuf_queue *q, struct cx88_buffer *buf) -{ - struct videobuf_dmabuf *dma=videobuf_to_dma(&buf->vb); - - BUG_ON(in_interrupt()); - videobuf_waiton(q, &buf->vb, 0, 0); - videobuf_dma_unmap(q->dev, dma); - videobuf_dma_free(dma); - btcx_riscmem_free(to_pci_dev(q->dev), &buf->risc); - buf->vb.state = VIDEOBUF_NEEDS_INIT; -} - /* ------------------------------------------------------------------ */ /* our SRAM memory layout */ @@ -539,33 +515,12 @@ void cx88_wakeup(struct cx88_core *core, struct cx88_dmaqueue *q, u32 count) { struct cx88_buffer *buf; - int bc; - - for (bc = 0;; bc++) { - if (list_empty(&q->active)) - break; - buf = list_entry(q->active.next, - struct cx88_buffer, vb.queue); - /* count comes from the hw and is is 16bit wide -- - * this trick handles wrap-arounds correctly for - * up to 32767 buffers in flight... */ - if ((s16) (count - buf->count) < 0) - break; - v4l2_get_timestamp(&buf->vb.ts); - dprintk(2,"[%p/%d] wakeup reg=%d buf=%d\n",buf,buf->vb.i, - count, buf->count); - buf->vb.state = VIDEOBUF_DONE; - list_del(&buf->vb.queue); - wake_up(&buf->vb.done); - } - if (list_empty(&q->active)) { - del_timer(&q->timeout); - } else { - mod_timer(&q->timeout, jiffies+BUFFER_TIMEOUT); - } - if (bc != 1) - dprintk(2, "%s: %d buffers handled (should be 1)\n", - __func__, bc); + + buf = list_entry(q->active.next, + struct cx88_buffer, list); + v4l2_get_timestamp(&buf->vb.v4l2_buf.timestamp); + list_del(&buf->list); + vb2_buffer_done(&buf->vb, VB2_BUF_STATE_DONE); } void cx88_shutdown(struct cx88_core *core) @@ -909,6 +864,13 @@ int cx88_set_tvnorm(struct cx88_core *core, v4l2_std_id norm) u32 bdelay,agcdelay,htotal; u32 cxiformat, cxoformat; + if (norm == core->tvnorm) + return 0; + if (core->v4ldev && (vb2_is_busy(&core->v4ldev->vb2_vidq) || + vb2_is_busy(&core->v4ldev->vb2_vbiq))) + return -EBUSY; + if (core->dvbdev && vb2_is_busy(&core->dvbdev->vb2_mpegq)) + return -EBUSY; core->tvnorm = norm; fsc8 = norm_fsc8(norm); adc_clock = xtal; @@ -1043,6 +1005,7 @@ struct video_device *cx88_vdev_init(struct cx88_core *core, vfd->v4l2_dev = &core->v4l2_dev; vfd->dev_parent = &pci->dev; vfd->release = video_device_release; + vfd->lock = &core->lock; snprintf(vfd->name, sizeof(vfd->name), "%s %s (%s)", core->name, type, core->board.name); return vfd; @@ -1114,8 +1077,6 @@ EXPORT_SYMBOL(cx88_shutdown); EXPORT_SYMBOL(cx88_risc_buffer); EXPORT_SYMBOL(cx88_risc_databuffer); -EXPORT_SYMBOL(cx88_risc_stopper); -EXPORT_SYMBOL(cx88_free_buffer); EXPORT_SYMBOL(cx88_sram_channels); EXPORT_SYMBOL(cx88_sram_channel_setup); diff --git a/drivers/media/pci/cx88/cx88-dvb.c b/drivers/media/pci/cx88/cx88-dvb.c index 053ed1ba1d8..c344bfd0b89 100644 --- a/drivers/media/pci/cx88/cx88-dvb.c +++ b/drivers/media/pci/cx88/cx88-dvb.c @@ -82,43 +82,89 @@ DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr); /* ------------------------------------------------------------------ */ -static int dvb_buf_setup(struct videobuf_queue *q, - unsigned int *count, unsigned int *size) +static int queue_setup(struct vb2_queue *q, const struct v4l2_format *fmt, + unsigned int *num_buffers, unsigned int *num_planes, + unsigned int sizes[], void *alloc_ctxs[]) { - struct cx8802_dev *dev = q->priv_data; + struct cx8802_dev *dev = q->drv_priv; + *num_planes = 1; dev->ts_packet_size = 188 * 4; dev->ts_packet_count = dvb_buf_tscnt; - - *size = dev->ts_packet_size * dev->ts_packet_count; - *count = dvb_buf_tscnt; + sizes[0] = dev->ts_packet_size * dev->ts_packet_count; + *num_buffers = dvb_buf_tscnt; return 0; } -static int dvb_buf_prepare(struct videobuf_queue *q, - struct videobuf_buffer *vb, enum v4l2_field field) +static int buffer_prepare(struct vb2_buffer *vb) +{ + struct cx8802_dev *dev = vb->vb2_queue->drv_priv; + struct cx88_buffer *buf = container_of(vb, struct cx88_buffer, vb); + + return cx8802_buf_prepare(vb->vb2_queue, dev, buf); +} + +static void buffer_finish(struct vb2_buffer *vb) +{ + struct cx8802_dev *dev = vb->vb2_queue->drv_priv; + struct cx88_buffer *buf = container_of(vb, struct cx88_buffer, vb); + struct sg_table *sgt = vb2_dma_sg_plane_desc(vb, 0); + struct cx88_riscmem *risc = &buf->risc; + + if (risc->cpu) + pci_free_consistent(dev->pci, risc->size, risc->cpu, risc->dma); + memset(risc, 0, sizeof(*risc)); + + dma_unmap_sg(&dev->pci->dev, sgt->sgl, sgt->nents, DMA_FROM_DEVICE); +} + +static void buffer_queue(struct vb2_buffer *vb) { - struct cx8802_dev *dev = q->priv_data; - return cx8802_buf_prepare(q, dev, (struct cx88_buffer*)vb,field); + struct cx8802_dev *dev = vb->vb2_queue->drv_priv; + struct cx88_buffer *buf = container_of(vb, struct cx88_buffer, vb); + + cx8802_buf_queue(dev, buf); } -static void dvb_buf_queue(struct videobuf_queue *q, struct videobuf_buffer *vb) +static int start_streaming(struct vb2_queue *q, unsigned int count) { - struct cx8802_dev *dev = q->priv_data; - cx8802_buf_queue(dev, (struct cx88_buffer*)vb); + struct cx8802_dev *dev = q->drv_priv; + struct cx88_dmaqueue *dmaq = &dev->mpegq; + struct cx88_buffer *buf; + + buf = list_entry(dmaq->active.next, struct cx88_buffer, list); + cx8802_start_dma(dev, dmaq, buf); + return 0; } -static void dvb_buf_release(struct videobuf_queue *q, - struct videobuf_buffer *vb) +static void stop_streaming(struct vb2_queue *q) { - cx88_free_buffer(q, (struct cx88_buffer*)vb); + struct cx8802_dev *dev = q->drv_priv; + struct cx88_dmaqueue *dmaq = &dev->mpegq; + unsigned long flags; + + cx8802_cancel_buffers(dev); + + spin_lock_irqsave(&dev->slock, flags); + while (!list_empty(&dmaq->active)) { + struct cx88_buffer *buf = list_entry(dmaq->active.next, + struct cx88_buffer, list); + + list_del(&buf->list); + vb2_buffer_done(&buf->vb, VB2_BUF_STATE_ERROR); + } + spin_unlock_irqrestore(&dev->slock, flags); } -static const struct videobuf_queue_ops dvb_qops = { - .buf_setup = dvb_buf_setup, - .buf_prepare = dvb_buf_prepare, - .buf_queue = dvb_buf_queue, - .buf_release = dvb_buf_release, +static struct vb2_ops dvb_qops = { + .queue_setup = queue_setup, + .buf_prepare = buffer_prepare, + .buf_finish = buffer_finish, + .buf_queue = buffer_queue, + .wait_prepare = vb2_ops_wait_prepare, + .wait_finish = vb2_ops_wait_finish, + .start_streaming = start_streaming, + .stop_streaming = stop_streaming, }; /* ------------------------------------------------------------------ */ @@ -130,7 +176,7 @@ static int cx88_dvb_bus_ctrl(struct dvb_frontend* fe, int acquire) int ret = 0; int fe_id; - fe_id = videobuf_dvb_find_frontend(&dev->frontends, fe); + fe_id = vb2_dvb_find_frontend(&dev->frontends, fe); if (!fe_id) { printk(KERN_ERR "%s() No frontend found\n", __func__); return -EINVAL; @@ -154,8 +200,8 @@ static int cx88_dvb_bus_ctrl(struct dvb_frontend* fe, int acquire) static void cx88_dvb_gate_ctrl(struct cx88_core *core, int open) { - struct videobuf_dvb_frontends *f; - struct videobuf_dvb_frontend *fe; + struct vb2_dvb_frontends *f; + struct vb2_dvb_frontend *fe; if (!core->dvbdev) return; @@ -166,9 +212,9 @@ static void cx88_dvb_gate_ctrl(struct cx88_core *core, int open) return; if (f->gate <= 1) /* undefined or fe0 */ - fe = videobuf_dvb_get_frontend(f, 1); + fe = vb2_dvb_get_frontend(f, 1); else - fe = videobuf_dvb_get_frontend(f, f->gate); + fe = vb2_dvb_get_frontend(f, f->gate); if (fe && fe->dvb.frontend && fe->dvb.frontend->ops.i2c_gate_ctrl) fe->dvb.frontend->ops.i2c_gate_ctrl(fe->dvb.frontend, open); @@ -565,7 +611,7 @@ static const struct xc5000_config dvico_fusionhdtv7_tuner_config = { static int attach_xc3028(u8 addr, struct cx8802_dev *dev) { struct dvb_frontend *fe; - struct videobuf_dvb_frontend *fe0 = NULL; + struct vb2_dvb_frontend *fe0 = NULL; struct xc2028_ctrl ctl; struct xc2028_config cfg = { .i2c_adap = &dev->core->i2c_adap, @@ -574,7 +620,7 @@ static int attach_xc3028(u8 addr, struct cx8802_dev *dev) }; /* Get the first frontend */ - fe0 = videobuf_dvb_get_frontend(&dev->frontends, 1); + fe0 = vb2_dvb_get_frontend(&dev->frontends, 1); if (!fe0) return -EINVAL; @@ -611,10 +657,10 @@ static int attach_xc3028(u8 addr, struct cx8802_dev *dev) static int attach_xc4000(struct cx8802_dev *dev, struct xc4000_config *cfg) { struct dvb_frontend *fe; - struct videobuf_dvb_frontend *fe0 = NULL; + struct vb2_dvb_frontend *fe0 = NULL; /* Get the first frontend */ - fe0 = videobuf_dvb_get_frontend(&dev->frontends, 1); + fe0 = vb2_dvb_get_frontend(&dev->frontends, 1); if (!fe0) return -EINVAL; @@ -745,7 +791,7 @@ static const struct stv0288_config tevii_tuner_earda_config = { static int cx8802_alloc_frontends(struct cx8802_dev *dev) { struct cx88_core *core = dev->core; - struct videobuf_dvb_frontend *fe = NULL; + struct vb2_dvb_frontend *fe = NULL; int i; mutex_init(&dev->frontends.lock); @@ -757,10 +803,10 @@ static int cx8802_alloc_frontends(struct cx8802_dev *dev) printk(KERN_INFO "%s() allocating %d frontend(s)\n", __func__, core->board.num_frontends); for (i = 1; i <= core->board.num_frontends; i++) { - fe = videobuf_dvb_alloc_frontend(&dev->frontends, i); + fe = vb2_dvb_alloc_frontend(&dev->frontends, i); if (!fe) { printk(KERN_ERR "%s() failed to alloc\n", __func__); - videobuf_dvb_dealloc_frontends(&dev->frontends); + vb2_dvb_dealloc_frontends(&dev->frontends); return -ENOMEM; } } @@ -958,7 +1004,7 @@ static const struct stv0299_config samsung_stv0299_config = { static int dvb_register(struct cx8802_dev *dev) { struct cx88_core *core = dev->core; - struct videobuf_dvb_frontend *fe0, *fe1 = NULL; + struct vb2_dvb_frontend *fe0, *fe1 = NULL; int mfe_shared = 0; /* bus not shared by default */ int res = -EINVAL; @@ -968,7 +1014,7 @@ static int dvb_register(struct cx8802_dev *dev) } /* Get the first frontend */ - fe0 = videobuf_dvb_get_frontend(&dev->frontends, 1); + fe0 = vb2_dvb_get_frontend(&dev->frontends, 1); if (!fe0) goto frontend_detach; @@ -1046,7 +1092,7 @@ static int dvb_register(struct cx8802_dev *dev) goto frontend_detach; } /* MFE frontend 2 */ - fe1 = videobuf_dvb_get_frontend(&dev->frontends, 2); + fe1 = vb2_dvb_get_frontend(&dev->frontends, 2); if (!fe1) goto frontend_detach; /* DVB-T init */ @@ -1415,7 +1461,7 @@ static int dvb_register(struct cx8802_dev *dev) goto frontend_detach; } /* MFE frontend 2 */ - fe1 = videobuf_dvb_get_frontend(&dev->frontends, 2); + fe1 = vb2_dvb_get_frontend(&dev->frontends, 2); if (!fe1) goto frontend_detach; /* DVB-T Init */ @@ -1594,7 +1640,7 @@ static int dvb_register(struct cx8802_dev *dev) call_all(core, core, s_power, 0); /* register everything */ - res = videobuf_dvb_register_bus(&dev->frontends, THIS_MODULE, dev, + res = vb2_dvb_register_bus(&dev->frontends, THIS_MODULE, dev, &dev->pci->dev, adapter_nr, mfe_shared); if (res) goto frontend_detach; @@ -1602,7 +1648,7 @@ static int dvb_register(struct cx8802_dev *dev) frontend_detach: core->gate_ctrl = NULL; - videobuf_dvb_dealloc_frontends(&dev->frontends); + vb2_dvb_dealloc_frontends(&dev->frontends); return res; } @@ -1697,7 +1743,7 @@ static int cx8802_dvb_probe(struct cx8802_driver *drv) struct cx88_core *core = drv->core; struct cx8802_dev *dev = drv->core->dvbdev; int err; - struct videobuf_dvb_frontend *fe; + struct vb2_dvb_frontend *fe; int i; dprintk( 1, "%s\n", __func__); @@ -1726,19 +1772,31 @@ static int cx8802_dvb_probe(struct cx8802_driver *drv) err = -ENODEV; for (i = 1; i <= core->board.num_frontends; i++) { - fe = videobuf_dvb_get_frontend(&core->dvbdev->frontends, i); + struct vb2_queue *q; + + fe = vb2_dvb_get_frontend(&core->dvbdev->frontends, i); if (fe == NULL) { printk(KERN_ERR "%s() failed to get frontend(%d)\n", __func__, i); goto fail_probe; } - videobuf_queue_sg_init(&fe->dvb.dvbq, &dvb_qops, - &dev->pci->dev, &dev->slock, - V4L2_BUF_TYPE_VIDEO_CAPTURE, - V4L2_FIELD_TOP, - sizeof(struct cx88_buffer), - dev, NULL); - /* init struct videobuf_dvb */ + q = &fe->dvb.dvbq; + q->type = V4L2_BUF_TYPE_VIDEO_CAPTURE; + q->io_modes = VB2_MMAP | VB2_USERPTR | VB2_DMABUF | VB2_READ; + q->gfp_flags = GFP_DMA32; + q->min_buffers_needed = 2; + q->drv_priv = dev; + q->buf_struct_size = sizeof(struct cx88_buffer); + q->ops = &dvb_qops; + q->mem_ops = &vb2_dma_sg_memops; + q->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC; + q->lock = &core->lock; + + err = vb2_queue_init(q); + if (err < 0) + goto fail_probe; + + /* init struct vb2_dvb */ fe->dvb.name = dev->core->name; } @@ -1749,7 +1807,7 @@ static int cx8802_dvb_probe(struct cx8802_driver *drv) core->name, err); return err; fail_probe: - videobuf_dvb_dealloc_frontends(&core->dvbdev->frontends); + vb2_dvb_dealloc_frontends(&core->dvbdev->frontends); fail_core: return err; } @@ -1761,7 +1819,7 @@ static int cx8802_dvb_remove(struct cx8802_driver *drv) dprintk( 1, "%s\n", __func__); - videobuf_dvb_unregister_bus(&dev->frontends); + vb2_dvb_unregister_bus(&dev->frontends); vp3054_i2c_remove(dev); diff --git a/drivers/media/pci/cx88/cx88-mpeg.c b/drivers/media/pci/cx88/cx88-mpeg.c index 74b7b8614c2..f181a3a1038 100644 --- a/drivers/media/pci/cx88/cx88-mpeg.c +++ b/drivers/media/pci/cx88/cx88-mpeg.c @@ -86,21 +86,21 @@ static LIST_HEAD(cx8802_devlist); static DEFINE_MUTEX(cx8802_mutex); /* ------------------------------------------------------------------ */ -static int cx8802_start_dma(struct cx8802_dev *dev, +int cx8802_start_dma(struct cx8802_dev *dev, struct cx88_dmaqueue *q, struct cx88_buffer *buf) { struct cx88_core *core = dev->core; dprintk(1, "cx8802_start_dma w: %d, h: %d, f: %d\n", - buf->vb.width, buf->vb.height, buf->vb.field); + core->width, core->height, core->field); /* setup fifo + format */ cx88_sram_channel_setup(core, &cx88_sram_channels[SRAM_CH28], dev->ts_packet_size, buf->risc.dma); /* write TS length to chip */ - cx_write(MO_TS_LNGTH, buf->vb.width); + cx_write(MO_TS_LNGTH, dev->ts_packet_size); /* FIXME: this needs a review. * also: move to cx88-blackbird + cx88-dvb source files? */ @@ -210,83 +210,44 @@ static int cx8802_restart_queue(struct cx8802_dev *dev, dprintk( 1, "cx8802_restart_queue\n" ); if (list_empty(&q->active)) - { - struct cx88_buffer *prev; - prev = NULL; - - dprintk(1, "cx8802_restart_queue: queue is empty\n" ); - - for (;;) { - if (list_empty(&q->queued)) - return 0; - buf = list_entry(q->queued.next, struct cx88_buffer, vb.queue); - if (NULL == prev) { - list_move_tail(&buf->vb.queue, &q->active); - cx8802_start_dma(dev, q, buf); - buf->vb.state = VIDEOBUF_ACTIVE; - buf->count = q->count++; - mod_timer(&q->timeout, jiffies+BUFFER_TIMEOUT); - dprintk(1,"[%p/%d] restart_queue - first active\n", - buf,buf->vb.i); - - } else if (prev->vb.width == buf->vb.width && - prev->vb.height == buf->vb.height && - prev->fmt == buf->fmt) { - list_move_tail(&buf->vb.queue, &q->active); - buf->vb.state = VIDEOBUF_ACTIVE; - buf->count = q->count++; - prev->risc.jmp[1] = cpu_to_le32(buf->risc.dma); - dprintk(1,"[%p/%d] restart_queue - move to active\n", - buf,buf->vb.i); - } else { - return 0; - } - prev = buf; - } return 0; - } - buf = list_entry(q->active.next, struct cx88_buffer, vb.queue); + buf = list_entry(q->active.next, struct cx88_buffer, list); dprintk(2,"restart_queue [%p/%d]: restart dma\n", - buf, buf->vb.i); + buf, buf->vb.v4l2_buf.index); cx8802_start_dma(dev, q, buf); - list_for_each_entry(buf, &q->active, vb.queue) + list_for_each_entry(buf, &q->active, list) buf->count = q->count++; - mod_timer(&q->timeout, jiffies+BUFFER_TIMEOUT); return 0; } /* ------------------------------------------------------------------ */ -int cx8802_buf_prepare(struct videobuf_queue *q, struct cx8802_dev *dev, - struct cx88_buffer *buf, enum v4l2_field field) +int cx8802_buf_prepare(struct vb2_queue *q, struct cx8802_dev *dev, + struct cx88_buffer *buf) { int size = dev->ts_packet_size * dev->ts_packet_count; - struct videobuf_dmabuf *dma=videobuf_to_dma(&buf->vb); + struct sg_table *sgt = vb2_dma_sg_plane_desc(&buf->vb, 0); + struct cx88_riscmem *risc = &buf->risc; int rc; - dprintk(1, "%s: %p\n", __func__, buf); - if (0 != buf->vb.baddr && buf->vb.bsize < size) + if (vb2_plane_size(&buf->vb, 0) < size) return -EINVAL; + vb2_set_plane_payload(&buf->vb, 0, size); - if (VIDEOBUF_NEEDS_INIT == buf->vb.state) { - buf->vb.width = dev->ts_packet_size; - buf->vb.height = dev->ts_packet_count; - buf->vb.size = size; - buf->vb.field = field /*V4L2_FIELD_TOP*/; - - if (0 != (rc = videobuf_iolock(q,&buf->vb,NULL))) - goto fail; - cx88_risc_databuffer(dev->pci, &buf->risc, - dma->sglist, - buf->vb.width, buf->vb.height, 0); + rc = dma_map_sg(&dev->pci->dev, sgt->sgl, sgt->nents, DMA_FROM_DEVICE); + if (!rc) + return -EIO; + + rc = cx88_risc_databuffer(dev->pci, risc, sgt->sgl, + dev->ts_packet_size, dev->ts_packet_count, 0); + if (rc) { + if (risc->cpu) + pci_free_consistent(dev->pci, risc->size, risc->cpu, risc->dma); + memset(risc, 0, sizeof(*risc)); + return rc; } - buf->vb.state = VIDEOBUF_PREPARED; return 0; - - fail: - cx88_free_buffer(q,buf); - return rc; } void cx8802_buf_queue(struct cx8802_dev *dev, struct cx88_buffer *buf) @@ -295,35 +256,33 @@ void cx8802_buf_queue(struct cx8802_dev *dev, struct cx88_buffer *buf) struct cx88_dmaqueue *cx88q = &dev->mpegq; dprintk( 1, "cx8802_buf_queue\n" ); - /* add jump to stopper */ - buf->risc.jmp[0] = cpu_to_le32(RISC_JUMP | RISC_IRQ1 | RISC_CNT_INC); - buf->risc.jmp[1] = cpu_to_le32(cx88q->stopper.dma); + /* add jump to start */ + buf->risc.cpu[1] = cpu_to_le32(buf->risc.dma + 8); + buf->risc.jmp[0] = cpu_to_le32(RISC_JUMP | RISC_CNT_INC); + buf->risc.jmp[1] = cpu_to_le32(buf->risc.dma + 8); if (list_empty(&cx88q->active)) { dprintk( 1, "queue is empty - first active\n" ); - list_add_tail(&buf->vb.queue,&cx88q->active); - cx8802_start_dma(dev, cx88q, buf); - buf->vb.state = VIDEOBUF_ACTIVE; + list_add_tail(&buf->list, &cx88q->active); buf->count = cx88q->count++; - mod_timer(&cx88q->timeout, jiffies+BUFFER_TIMEOUT); dprintk(1,"[%p/%d] %s - first active\n", - buf, buf->vb.i, __func__); + buf, buf->vb.v4l2_buf.index, __func__); } else { + buf->risc.cpu[0] |= cpu_to_le32(RISC_IRQ1); dprintk( 1, "queue is not empty - append to active\n" ); - prev = list_entry(cx88q->active.prev, struct cx88_buffer, vb.queue); - list_add_tail(&buf->vb.queue,&cx88q->active); - buf->vb.state = VIDEOBUF_ACTIVE; + prev = list_entry(cx88q->active.prev, struct cx88_buffer, list); + list_add_tail(&buf->list, &cx88q->active); buf->count = cx88q->count++; prev->risc.jmp[1] = cpu_to_le32(buf->risc.dma); dprintk( 1, "[%p/%d] %s - append to active\n", - buf, buf->vb.i, __func__); + buf, buf->vb.v4l2_buf.index, __func__); } } /* ----------------------------------------------------------- */ -static void do_cancel_buffers(struct cx8802_dev *dev, const char *reason, int restart) +static void do_cancel_buffers(struct cx8802_dev *dev) { struct cx88_dmaqueue *q = &dev->mpegq; struct cx88_buffer *buf; @@ -331,41 +290,18 @@ static void do_cancel_buffers(struct cx8802_dev *dev, const char *reason, int re spin_lock_irqsave(&dev->slock,flags); while (!list_empty(&q->active)) { - buf = list_entry(q->active.next, struct cx88_buffer, vb.queue); - list_del(&buf->vb.queue); - buf->vb.state = VIDEOBUF_ERROR; - wake_up(&buf->vb.done); - dprintk(1,"[%p/%d] %s - dma=0x%08lx\n", - buf, buf->vb.i, reason, (unsigned long)buf->risc.dma); - } - if (restart) - { - dprintk(1, "restarting queue\n" ); - cx8802_restart_queue(dev,q); + buf = list_entry(q->active.next, struct cx88_buffer, list); + list_del(&buf->list); + vb2_buffer_done(&buf->vb, VB2_BUF_STATE_ERROR); } spin_unlock_irqrestore(&dev->slock,flags); } void cx8802_cancel_buffers(struct cx8802_dev *dev) { - struct cx88_dmaqueue *q = &dev->mpegq; - dprintk( 1, "cx8802_cancel_buffers" ); - del_timer_sync(&q->timeout); cx8802_stop_dma(dev); - do_cancel_buffers(dev,"cancel",0); -} - -static void cx8802_timeout(unsigned long data) -{ - struct cx8802_dev *dev = (struct cx8802_dev*)data; - - dprintk(1, "%s\n",__func__); - - if (debug) - cx88_sram_channel_dump(dev->core, &cx88_sram_channels[SRAM_CH28]); - cx8802_stop_dma(dev); - do_cancel_buffers(dev,"timeout",1); + do_cancel_buffers(dev); } static const char * cx88_mpeg_irqs[32] = { @@ -411,19 +347,11 @@ static void cx8802_mpeg_irq(struct cx8802_dev *dev) spin_unlock(&dev->slock); } - /* risc2 y */ - if (status & 0x10) { - spin_lock(&dev->slock); - cx8802_restart_queue(dev,&dev->mpegq); - spin_unlock(&dev->slock); - } - /* other general errors */ if (status & 0x1f0100) { dprintk( 0, "general errors: 0x%08x\n", status & 0x1f0100 ); spin_lock(&dev->slock); cx8802_stop_dma(dev); - cx8802_restart_queue(dev,&dev->mpegq); spin_unlock(&dev->slock); } } @@ -490,12 +418,6 @@ static int cx8802_init_common(struct cx8802_dev *dev) /* init dma queue */ INIT_LIST_HEAD(&dev->mpegq.active); - INIT_LIST_HEAD(&dev->mpegq.queued); - dev->mpegq.timeout.function = cx8802_timeout; - dev->mpegq.timeout.data = (unsigned long)dev; - init_timer(&dev->mpegq.timeout); - cx88_risc_stopper(dev->pci,&dev->mpegq.stopper, - MO_TS_DMACNTRL,0x11,0x00); /* get irq */ err = request_irq(dev->pci->irq, cx8802_irq, @@ -520,9 +442,6 @@ static void cx8802_fini_common(struct cx8802_dev *dev) /* unregister stuff */ free_irq(dev->pci->irq, dev); - - /* free memory */ - btcx_riscmem_free(dev->pci,&dev->mpegq.stopper); } /* ----------------------------------------------------------- */ @@ -539,7 +458,6 @@ static int cx8802_suspend_common(struct pci_dev *pci_dev, pm_message_t state) dprintk( 2, "suspend\n" ); printk("%s: suspend mpeg\n", core->name); cx8802_stop_dma(dev); - del_timer(&dev->mpegq.timeout); } spin_unlock_irqrestore(&dev->slock, flags); @@ -907,6 +825,7 @@ module_pci_driver(cx8802_pci_driver); EXPORT_SYMBOL(cx8802_buf_prepare); EXPORT_SYMBOL(cx8802_buf_queue); EXPORT_SYMBOL(cx8802_cancel_buffers); +EXPORT_SYMBOL(cx8802_start_dma); EXPORT_SYMBOL(cx8802_register_driver); EXPORT_SYMBOL(cx8802_unregister_driver); diff --git a/drivers/media/pci/cx88/cx88-vbi.c b/drivers/media/pci/cx88/cx88-vbi.c index f8f8389c036..6ab6e27648f 100644 --- a/drivers/media/pci/cx88/cx88-vbi.c +++ b/drivers/media/pci/cx88/cx88-vbi.c @@ -6,10 +6,6 @@ #include "cx88.h" -static unsigned int vbibufs = 4; -module_param(vbibufs,int,0644); -MODULE_PARM_DESC(vbibufs,"number of vbi buffers, range 2-32"); - static unsigned int vbi_debug; module_param(vbi_debug,int,0644); MODULE_PARM_DESC(vbi_debug,"enable debug messages [vbi]"); @@ -22,26 +18,27 @@ MODULE_PARM_DESC(vbi_debug,"enable debug messages [vbi]"); int cx8800_vbi_fmt (struct file *file, void *priv, struct v4l2_format *f) { - struct cx8800_fh *fh = priv; - struct cx8800_dev *dev = fh->dev; + struct cx8800_dev *dev = video_drvdata(file); f->fmt.vbi.samples_per_line = VBI_LINE_LENGTH; f->fmt.vbi.sample_format = V4L2_PIX_FMT_GREY; f->fmt.vbi.offset = 244; - f->fmt.vbi.count[0] = VBI_LINE_COUNT; - f->fmt.vbi.count[1] = VBI_LINE_COUNT; if (dev->core->tvnorm & V4L2_STD_525_60) { /* ntsc */ f->fmt.vbi.sampling_rate = 28636363; f->fmt.vbi.start[0] = 10; f->fmt.vbi.start[1] = 273; + f->fmt.vbi.count[0] = VBI_LINE_NTSC_COUNT; + f->fmt.vbi.count[1] = VBI_LINE_NTSC_COUNT; } else if (dev->core->tvnorm & V4L2_STD_625_50) { /* pal */ f->fmt.vbi.sampling_rate = 35468950; - f->fmt.vbi.start[0] = 7 -1; - f->fmt.vbi.start[1] = 319 -1; + f->fmt.vbi.start[0] = V4L2_VBI_ITU_625_F1_START + 5; + f->fmt.vbi.start[1] = V4L2_VBI_ITU_625_F2_START + 5; + f->fmt.vbi.count[0] = VBI_LINE_PAL_COUNT; + f->fmt.vbi.count[1] = VBI_LINE_PAL_COUNT; } return 0; } @@ -54,7 +51,7 @@ static int cx8800_start_vbi_dma(struct cx8800_dev *dev, /* setup fifo + format */ cx88_sram_channel_setup(dev->core, &cx88_sram_channels[SRAM_CH24], - buf->vb.width, buf->risc.dma); + VBI_LINE_LENGTH, buf->risc.dma); cx_write(MO_VBOS_CONTROL, ( (1 << 18) | // comb filter delay fixup (1 << 15) | // enable vbi capture @@ -78,7 +75,7 @@ static int cx8800_start_vbi_dma(struct cx8800_dev *dev, return 0; } -int cx8800_stop_vbi_dma(struct cx8800_dev *dev) +void cx8800_stop_vbi_dma(struct cx8800_dev *dev) { struct cx88_core *core = dev->core; @@ -91,7 +88,6 @@ int cx8800_stop_vbi_dma(struct cx8800_dev *dev) /* disable irqs */ cx_clear(MO_PCI_INTMSK, PCI_INT_VIDINT); cx_clear(MO_VID_INTMSK, 0x0f0088); - return 0; } int cx8800_restart_vbi_queue(struct cx8800_dev *dev, @@ -102,144 +98,144 @@ int cx8800_restart_vbi_queue(struct cx8800_dev *dev, if (list_empty(&q->active)) return 0; - buf = list_entry(q->active.next, struct cx88_buffer, vb.queue); + buf = list_entry(q->active.next, struct cx88_buffer, list); dprintk(2,"restart_queue [%p/%d]: restart dma\n", - buf, buf->vb.i); + buf, buf->vb.v4l2_buf.index); cx8800_start_vbi_dma(dev, q, buf); - list_for_each_entry(buf, &q->active, vb.queue) + list_for_each_entry(buf, &q->active, list) buf->count = q->count++; - mod_timer(&q->timeout, jiffies+BUFFER_TIMEOUT); return 0; } -void cx8800_vbi_timeout(unsigned long data) -{ - struct cx8800_dev *dev = (struct cx8800_dev*)data; - struct cx88_core *core = dev->core; - struct cx88_dmaqueue *q = &dev->vbiq; - struct cx88_buffer *buf; - unsigned long flags; - - cx88_sram_channel_dump(dev->core, &cx88_sram_channels[SRAM_CH24]); - - cx_clear(MO_VID_DMACNTRL, 0x88); - cx_clear(VID_CAPTURE_CONTROL, 0x18); - - spin_lock_irqsave(&dev->slock,flags); - while (!list_empty(&q->active)) { - buf = list_entry(q->active.next, struct cx88_buffer, vb.queue); - list_del(&buf->vb.queue); - buf->vb.state = VIDEOBUF_ERROR; - wake_up(&buf->vb.done); - printk("%s/0: [%p/%d] timeout - dma=0x%08lx\n", dev->core->name, - buf, buf->vb.i, (unsigned long)buf->risc.dma); - } - cx8800_restart_vbi_queue(dev,q); - spin_unlock_irqrestore(&dev->slock,flags); -} - /* ------------------------------------------------------------------ */ -static int -vbi_setup(struct videobuf_queue *q, unsigned int *count, unsigned int *size) +static int queue_setup(struct vb2_queue *q, const struct v4l2_format *fmt, + unsigned int *num_buffers, unsigned int *num_planes, + unsigned int sizes[], void *alloc_ctxs[]) { - *size = VBI_LINE_COUNT * VBI_LINE_LENGTH * 2; - if (0 == *count) - *count = vbibufs; - if (*count < 2) - *count = 2; - if (*count > 32) - *count = 32; + struct cx8800_dev *dev = q->drv_priv; + + *num_planes = 1; + if (dev->core->tvnorm & V4L2_STD_525_60) + sizes[0] = VBI_LINE_NTSC_COUNT * VBI_LINE_LENGTH * 2; + else + sizes[0] = VBI_LINE_PAL_COUNT * VBI_LINE_LENGTH * 2; return 0; } -static int -vbi_prepare(struct videobuf_queue *q, struct videobuf_buffer *vb, - enum v4l2_field field) + +static int buffer_prepare(struct vb2_buffer *vb) { - struct cx8800_fh *fh = q->priv_data; - struct cx8800_dev *dev = fh->dev; - struct cx88_buffer *buf = container_of(vb,struct cx88_buffer,vb); + struct cx8800_dev *dev = vb->vb2_queue->drv_priv; + struct cx88_buffer *buf = container_of(vb, struct cx88_buffer, vb); + struct sg_table *sgt = vb2_dma_sg_plane_desc(vb, 0); + unsigned int lines; unsigned int size; int rc; - size = VBI_LINE_COUNT * VBI_LINE_LENGTH * 2; - if (0 != buf->vb.baddr && buf->vb.bsize < size) + if (dev->core->tvnorm & V4L2_STD_525_60) + lines = VBI_LINE_NTSC_COUNT; + else + lines = VBI_LINE_PAL_COUNT; + size = lines * VBI_LINE_LENGTH * 2; + if (vb2_plane_size(vb, 0) < size) return -EINVAL; + vb2_set_plane_payload(vb, 0, size); - if (VIDEOBUF_NEEDS_INIT == buf->vb.state) { - struct videobuf_dmabuf *dma=videobuf_to_dma(&buf->vb); - buf->vb.width = VBI_LINE_LENGTH; - buf->vb.height = VBI_LINE_COUNT; - buf->vb.size = size; - buf->vb.field = V4L2_FIELD_SEQ_TB; - - if (0 != (rc = videobuf_iolock(q,&buf->vb,NULL))) - goto fail; - cx88_risc_buffer(dev->pci, &buf->risc, - dma->sglist, - 0, buf->vb.width * buf->vb.height, - buf->vb.width, 0, - buf->vb.height); - } - buf->vb.state = VIDEOBUF_PREPARED; + rc = dma_map_sg(&dev->pci->dev, sgt->sgl, sgt->nents, DMA_FROM_DEVICE); + if (!rc) + return -EIO; + + cx88_risc_buffer(dev->pci, &buf->risc, sgt->sgl, + 0, VBI_LINE_LENGTH * lines, + VBI_LINE_LENGTH, 0, + lines); return 0; +} - fail: - cx88_free_buffer(q,buf); - return rc; +static void buffer_finish(struct vb2_buffer *vb) +{ + struct cx8800_dev *dev = vb->vb2_queue->drv_priv; + struct cx88_buffer *buf = container_of(vb, struct cx88_buffer, vb); + struct sg_table *sgt = vb2_dma_sg_plane_desc(vb, 0); + struct cx88_riscmem *risc = &buf->risc; + + if (risc->cpu) + pci_free_consistent(dev->pci, risc->size, risc->cpu, risc->dma); + memset(risc, 0, sizeof(*risc)); + + dma_unmap_sg(&dev->pci->dev, sgt->sgl, sgt->nents, DMA_FROM_DEVICE); } -static void -vbi_queue(struct videobuf_queue *vq, struct videobuf_buffer *vb) +static void buffer_queue(struct vb2_buffer *vb) { - struct cx88_buffer *buf = container_of(vb,struct cx88_buffer,vb); + struct cx8800_dev *dev = vb->vb2_queue->drv_priv; + struct cx88_buffer *buf = container_of(vb, struct cx88_buffer, vb); struct cx88_buffer *prev; - struct cx8800_fh *fh = vq->priv_data; - struct cx8800_dev *dev = fh->dev; struct cx88_dmaqueue *q = &dev->vbiq; - /* add jump to stopper */ - buf->risc.jmp[0] = cpu_to_le32(RISC_JUMP | RISC_IRQ1 | RISC_CNT_INC); - buf->risc.jmp[1] = cpu_to_le32(q->stopper.dma); + /* add jump to start */ + buf->risc.cpu[1] = cpu_to_le32(buf->risc.dma + 8); + buf->risc.jmp[0] = cpu_to_le32(RISC_JUMP | RISC_CNT_INC); + buf->risc.jmp[1] = cpu_to_le32(buf->risc.dma + 8); if (list_empty(&q->active)) { - list_add_tail(&buf->vb.queue,&q->active); + list_add_tail(&buf->list, &q->active); cx8800_start_vbi_dma(dev, q, buf); - buf->vb.state = VIDEOBUF_ACTIVE; buf->count = q->count++; - mod_timer(&q->timeout, jiffies+BUFFER_TIMEOUT); dprintk(2,"[%p/%d] vbi_queue - first active\n", - buf, buf->vb.i); + buf, buf->vb.v4l2_buf.index); } else { - prev = list_entry(q->active.prev, struct cx88_buffer, vb.queue); - list_add_tail(&buf->vb.queue,&q->active); - buf->vb.state = VIDEOBUF_ACTIVE; + buf->risc.cpu[0] |= cpu_to_le32(RISC_IRQ1); + prev = list_entry(q->active.prev, struct cx88_buffer, list); + list_add_tail(&buf->list, &q->active); buf->count = q->count++; prev->risc.jmp[1] = cpu_to_le32(buf->risc.dma); dprintk(2,"[%p/%d] buffer_queue - append to active\n", - buf, buf->vb.i); + buf, buf->vb.v4l2_buf.index); } } -static void vbi_release(struct videobuf_queue *q, struct videobuf_buffer *vb) +static int start_streaming(struct vb2_queue *q, unsigned int count) { - struct cx88_buffer *buf = container_of(vb,struct cx88_buffer,vb); + struct cx8800_dev *dev = q->drv_priv; + struct cx88_dmaqueue *dmaq = &dev->vbiq; + struct cx88_buffer *buf = list_entry(dmaq->active.next, + struct cx88_buffer, list); - cx88_free_buffer(q,buf); + cx8800_start_vbi_dma(dev, dmaq, buf); + return 0; } -const struct videobuf_queue_ops cx8800_vbi_qops = { - .buf_setup = vbi_setup, - .buf_prepare = vbi_prepare, - .buf_queue = vbi_queue, - .buf_release = vbi_release, -}; +static void stop_streaming(struct vb2_queue *q) +{ + struct cx8800_dev *dev = q->drv_priv; + struct cx88_core *core = dev->core; + struct cx88_dmaqueue *dmaq = &dev->vbiq; + unsigned long flags; -/* ------------------------------------------------------------------ */ -/* - * Local variables: - * c-basic-offset: 8 - * End: - */ + cx_clear(MO_VID_DMACNTRL, 0x11); + cx_clear(VID_CAPTURE_CONTROL, 0x06); + cx8800_stop_vbi_dma(dev); + spin_lock_irqsave(&dev->slock, flags); + while (!list_empty(&dmaq->active)) { + struct cx88_buffer *buf = list_entry(dmaq->active.next, + struct cx88_buffer, list); + + list_del(&buf->list); + vb2_buffer_done(&buf->vb, VB2_BUF_STATE_ERROR); + } + spin_unlock_irqrestore(&dev->slock, flags); +} + +const struct vb2_ops cx8800_vbi_qops = { + .queue_setup = queue_setup, + .buf_prepare = buffer_prepare, + .buf_finish = buffer_finish, + .buf_queue = buffer_queue, + .wait_prepare = vb2_ops_wait_prepare, + .wait_finish = vb2_ops_wait_finish, + .start_streaming = start_streaming, + .stop_streaming = stop_streaming, +}; diff --git a/drivers/media/pci/cx88/cx88-video.c b/drivers/media/pci/cx88/cx88-video.c index ce27e6d4f16..a64ae31ae14 100644 --- a/drivers/media/pci/cx88/cx88-video.c +++ b/drivers/media/pci/cx88/cx88-video.c @@ -70,10 +70,6 @@ static unsigned int irq_debug; module_param(irq_debug,int,0644); MODULE_PARM_DESC(irq_debug,"enable debug messages [IRQ handler]"); -static unsigned int vid_limit = 16; -module_param(vid_limit,int,0644); -MODULE_PARM_DESC(vid_limit,"capture memory limit in megabytes"); - #define dprintk(level,fmt, arg...) if (video_debug >= level) \ printk(KERN_DEBUG "%s/0: " fmt, core->name , ## arg) @@ -297,56 +293,6 @@ enum { CX8800_AUD_CTLS = ARRAY_SIZE(cx8800_aud_ctls), }; -/* ------------------------------------------------------------------- */ -/* resource management */ - -static int res_get(struct cx8800_dev *dev, struct cx8800_fh *fh, unsigned int bit) -{ - struct cx88_core *core = dev->core; - if (fh->resources & bit) - /* have it already allocated */ - return 1; - - /* is it free? */ - mutex_lock(&core->lock); - if (dev->resources & bit) { - /* no, someone else uses it */ - mutex_unlock(&core->lock); - return 0; - } - /* it's free, grab it */ - fh->resources |= bit; - dev->resources |= bit; - dprintk(1,"res: get %d\n",bit); - mutex_unlock(&core->lock); - return 1; -} - -static -int res_check(struct cx8800_fh *fh, unsigned int bit) -{ - return (fh->resources & bit); -} - -static -int res_locked(struct cx8800_dev *dev, unsigned int bit) -{ - return (dev->resources & bit); -} - -static -void res_free(struct cx8800_dev *dev, struct cx8800_fh *fh, unsigned int bits) -{ - struct cx88_core *core = dev->core; - BUG_ON((fh->resources & bits) != bits); - - mutex_lock(&core->lock); - fh->resources &= ~bits; - dev->resources &= ~bits; - dprintk(1,"res: put %d\n",bits); - mutex_unlock(&core->lock); -} - /* ------------------------------------------------------------------ */ int cx88_video_mux(struct cx88_core *core, unsigned int input) @@ -419,8 +365,8 @@ static int start_video_dma(struct cx8800_dev *dev, /* setup fifo + format */ cx88_sram_channel_setup(core, &cx88_sram_channels[SRAM_CH21], buf->bpl, buf->risc.dma); - cx88_set_scale(core, buf->vb.width, buf->vb.height, buf->vb.field); - cx_write(MO_COLOR_CTRL, buf->fmt->cxformat | ColorFormatGamma); + cx88_set_scale(core, core->width, core->height, core->field); + cx_write(MO_COLOR_CTRL, dev->fmt->cxformat | ColorFormatGamma); /* reset counter */ cx_write(MO_VIDY_GPCNTRL,GP_COUNT_CONTROL_RESET); @@ -470,433 +416,211 @@ static int restart_video_queue(struct cx8800_dev *dev, struct cx88_dmaqueue *q) { struct cx88_core *core = dev->core; - struct cx88_buffer *buf, *prev; + struct cx88_buffer *buf; if (!list_empty(&q->active)) { - buf = list_entry(q->active.next, struct cx88_buffer, vb.queue); + buf = list_entry(q->active.next, struct cx88_buffer, list); dprintk(2,"restart_queue [%p/%d]: restart dma\n", - buf, buf->vb.i); + buf, buf->vb.v4l2_buf.index); start_video_dma(dev, q, buf); - list_for_each_entry(buf, &q->active, vb.queue) + list_for_each_entry(buf, &q->active, list) buf->count = q->count++; - mod_timer(&q->timeout, jiffies+BUFFER_TIMEOUT); - return 0; - } - - prev = NULL; - for (;;) { - if (list_empty(&q->queued)) - return 0; - buf = list_entry(q->queued.next, struct cx88_buffer, vb.queue); - if (NULL == prev) { - list_move_tail(&buf->vb.queue, &q->active); - start_video_dma(dev, q, buf); - buf->vb.state = VIDEOBUF_ACTIVE; - buf->count = q->count++; - mod_timer(&q->timeout, jiffies+BUFFER_TIMEOUT); - dprintk(2,"[%p/%d] restart_queue - first active\n", - buf,buf->vb.i); - - } else if (prev->vb.width == buf->vb.width && - prev->vb.height == buf->vb.height && - prev->fmt == buf->fmt) { - list_move_tail(&buf->vb.queue, &q->active); - buf->vb.state = VIDEOBUF_ACTIVE; - buf->count = q->count++; - prev->risc.jmp[1] = cpu_to_le32(buf->risc.dma); - dprintk(2,"[%p/%d] restart_queue - move to active\n", - buf,buf->vb.i); - } else { - return 0; - } - prev = buf; } + return 0; } /* ------------------------------------------------------------------ */ -static int -buffer_setup(struct videobuf_queue *q, unsigned int *count, unsigned int *size) +static int queue_setup(struct vb2_queue *q, const struct v4l2_format *fmt, + unsigned int *num_buffers, unsigned int *num_planes, + unsigned int sizes[], void *alloc_ctxs[]) { - struct cx8800_fh *fh = q->priv_data; - struct cx8800_dev *dev = fh->dev; - - *size = dev->fmt->depth * dev->width * dev->height >> 3; - if (0 == *count) - *count = 32; - if (*size * *count > vid_limit * 1024 * 1024) - *count = (vid_limit * 1024 * 1024) / *size; + struct cx8800_dev *dev = q->drv_priv; + struct cx88_core *core = dev->core; + + *num_planes = 1; + sizes[0] = (dev->fmt->depth * core->width * core->height) >> 3; return 0; } -static int -buffer_prepare(struct videobuf_queue *q, struct videobuf_buffer *vb, - enum v4l2_field field) +static int buffer_prepare(struct vb2_buffer *vb) { - struct cx8800_fh *fh = q->priv_data; - struct cx8800_dev *dev = fh->dev; + struct cx8800_dev *dev = vb->vb2_queue->drv_priv; struct cx88_core *core = dev->core; - struct cx88_buffer *buf = container_of(vb,struct cx88_buffer,vb); - struct videobuf_dmabuf *dma=videobuf_to_dma(&buf->vb); - int rc, init_buffer = 0; + struct cx88_buffer *buf = container_of(vb, struct cx88_buffer, vb); + struct sg_table *sgt = vb2_dma_sg_plane_desc(vb, 0); + int rc; - BUG_ON(NULL == dev->fmt); - if (dev->width < 48 || dev->width > norm_maxw(core->tvnorm) || - dev->height < 32 || dev->height > norm_maxh(core->tvnorm)) - return -EINVAL; - buf->vb.size = (dev->width * dev->height * dev->fmt->depth) >> 3; - if (0 != buf->vb.baddr && buf->vb.bsize < buf->vb.size) - return -EINVAL; + buf->bpl = core->width * dev->fmt->depth >> 3; - if (buf->fmt != dev->fmt || - buf->vb.width != dev->width || - buf->vb.height != dev->height || - buf->vb.field != field) { - buf->fmt = dev->fmt; - buf->vb.width = dev->width; - buf->vb.height = dev->height; - buf->vb.field = field; - init_buffer = 1; - } + if (vb2_plane_size(vb, 0) < core->height * buf->bpl) + return -EINVAL; + vb2_set_plane_payload(vb, 0, core->height * buf->bpl); - if (VIDEOBUF_NEEDS_INIT == buf->vb.state) { - init_buffer = 1; - if (0 != (rc = videobuf_iolock(q,&buf->vb,NULL))) - goto fail; - } + rc = dma_map_sg(&dev->pci->dev, sgt->sgl, sgt->nents, DMA_FROM_DEVICE); + if (!rc) + return -EIO; - if (init_buffer) { - buf->bpl = buf->vb.width * buf->fmt->depth >> 3; - switch (buf->vb.field) { - case V4L2_FIELD_TOP: - cx88_risc_buffer(dev->pci, &buf->risc, - dma->sglist, 0, UNSET, - buf->bpl, 0, buf->vb.height); - break; - case V4L2_FIELD_BOTTOM: - cx88_risc_buffer(dev->pci, &buf->risc, - dma->sglist, UNSET, 0, - buf->bpl, 0, buf->vb.height); - break; - case V4L2_FIELD_INTERLACED: - cx88_risc_buffer(dev->pci, &buf->risc, - dma->sglist, 0, buf->bpl, - buf->bpl, buf->bpl, - buf->vb.height >> 1); - break; - case V4L2_FIELD_SEQ_TB: - cx88_risc_buffer(dev->pci, &buf->risc, - dma->sglist, - 0, buf->bpl * (buf->vb.height >> 1), - buf->bpl, 0, - buf->vb.height >> 1); - break; - case V4L2_FIELD_SEQ_BT: - cx88_risc_buffer(dev->pci, &buf->risc, - dma->sglist, - buf->bpl * (buf->vb.height >> 1), 0, - buf->bpl, 0, - buf->vb.height >> 1); - break; - default: - BUG(); - } + switch (core->field) { + case V4L2_FIELD_TOP: + cx88_risc_buffer(dev->pci, &buf->risc, + sgt->sgl, 0, UNSET, + buf->bpl, 0, core->height); + break; + case V4L2_FIELD_BOTTOM: + cx88_risc_buffer(dev->pci, &buf->risc, + sgt->sgl, UNSET, 0, + buf->bpl, 0, core->height); + break; + case V4L2_FIELD_SEQ_TB: + cx88_risc_buffer(dev->pci, &buf->risc, + sgt->sgl, + 0, buf->bpl * (core->height >> 1), + buf->bpl, 0, + core->height >> 1); + break; + case V4L2_FIELD_SEQ_BT: + cx88_risc_buffer(dev->pci, &buf->risc, + sgt->sgl, + buf->bpl * (core->height >> 1), 0, + buf->bpl, 0, + core->height >> 1); + break; + case V4L2_FIELD_INTERLACED: + default: + cx88_risc_buffer(dev->pci, &buf->risc, + sgt->sgl, 0, buf->bpl, + buf->bpl, buf->bpl, + core->height >> 1); + break; } dprintk(2,"[%p/%d] buffer_prepare - %dx%d %dbpp \"%s\" - dma=0x%08lx\n", - buf, buf->vb.i, - dev->width, dev->height, dev->fmt->depth, dev->fmt->name, + buf, buf->vb.v4l2_buf.index, + core->width, core->height, dev->fmt->depth, dev->fmt->name, (unsigned long)buf->risc.dma); - - buf->vb.state = VIDEOBUF_PREPARED; return 0; +} + +static void buffer_finish(struct vb2_buffer *vb) +{ + struct cx8800_dev *dev = vb->vb2_queue->drv_priv; + struct cx88_buffer *buf = container_of(vb, struct cx88_buffer, vb); + struct sg_table *sgt = vb2_dma_sg_plane_desc(vb, 0); + struct cx88_riscmem *risc = &buf->risc; + + if (risc->cpu) + pci_free_consistent(dev->pci, risc->size, risc->cpu, risc->dma); + memset(risc, 0, sizeof(*risc)); - fail: - cx88_free_buffer(q,buf); - return rc; + dma_unmap_sg(&dev->pci->dev, sgt->sgl, sgt->nents, DMA_FROM_DEVICE); } -static void -buffer_queue(struct videobuf_queue *vq, struct videobuf_buffer *vb) +static void buffer_queue(struct vb2_buffer *vb) { - struct cx88_buffer *buf = container_of(vb,struct cx88_buffer,vb); + struct cx8800_dev *dev = vb->vb2_queue->drv_priv; + struct cx88_buffer *buf = container_of(vb, struct cx88_buffer, vb); struct cx88_buffer *prev; - struct cx8800_fh *fh = vq->priv_data; - struct cx8800_dev *dev = fh->dev; struct cx88_core *core = dev->core; struct cx88_dmaqueue *q = &dev->vidq; - /* add jump to stopper */ - buf->risc.jmp[0] = cpu_to_le32(RISC_JUMP | RISC_IRQ1 | RISC_CNT_INC); - buf->risc.jmp[1] = cpu_to_le32(q->stopper.dma); + /* add jump to start */ + buf->risc.cpu[1] = cpu_to_le32(buf->risc.dma + 8); + buf->risc.jmp[0] = cpu_to_le32(RISC_JUMP | RISC_CNT_INC); + buf->risc.jmp[1] = cpu_to_le32(buf->risc.dma + 8); - if (!list_empty(&q->queued)) { - list_add_tail(&buf->vb.queue,&q->queued); - buf->vb.state = VIDEOBUF_QUEUED; - dprintk(2,"[%p/%d] buffer_queue - append to queued\n", - buf, buf->vb.i); - - } else if (list_empty(&q->active)) { - list_add_tail(&buf->vb.queue,&q->active); + if (list_empty(&q->active)) { + list_add_tail(&buf->list, &q->active); start_video_dma(dev, q, buf); - buf->vb.state = VIDEOBUF_ACTIVE; buf->count = q->count++; - mod_timer(&q->timeout, jiffies+BUFFER_TIMEOUT); dprintk(2,"[%p/%d] buffer_queue - first active\n", - buf, buf->vb.i); + buf, buf->vb.v4l2_buf.index); } else { - prev = list_entry(q->active.prev, struct cx88_buffer, vb.queue); - if (prev->vb.width == buf->vb.width && - prev->vb.height == buf->vb.height && - prev->fmt == buf->fmt) { - list_add_tail(&buf->vb.queue,&q->active); - buf->vb.state = VIDEOBUF_ACTIVE; - buf->count = q->count++; - prev->risc.jmp[1] = cpu_to_le32(buf->risc.dma); - dprintk(2,"[%p/%d] buffer_queue - append to active\n", - buf, buf->vb.i); - - } else { - list_add_tail(&buf->vb.queue,&q->queued); - buf->vb.state = VIDEOBUF_QUEUED; - dprintk(2,"[%p/%d] buffer_queue - first queued\n", - buf, buf->vb.i); - } + buf->risc.cpu[0] |= cpu_to_le32(RISC_IRQ1); + prev = list_entry(q->active.prev, struct cx88_buffer, list); + list_add_tail(&buf->list, &q->active); + buf->count = q->count++; + prev->risc.jmp[1] = cpu_to_le32(buf->risc.dma); + dprintk(2, "[%p/%d] buffer_queue - append to active\n", + buf, buf->vb.v4l2_buf.index); } } -static void buffer_release(struct videobuf_queue *q, struct videobuf_buffer *vb) +static int start_streaming(struct vb2_queue *q, unsigned int count) { - struct cx88_buffer *buf = container_of(vb,struct cx88_buffer,vb); + struct cx8800_dev *dev = q->drv_priv; + struct cx88_dmaqueue *dmaq = &dev->vidq; + struct cx88_buffer *buf = list_entry(dmaq->active.next, + struct cx88_buffer, list); - cx88_free_buffer(q,buf); + start_video_dma(dev, dmaq, buf); + return 0; } -static const struct videobuf_queue_ops cx8800_video_qops = { - .buf_setup = buffer_setup, - .buf_prepare = buffer_prepare, - .buf_queue = buffer_queue, - .buf_release = buffer_release, -}; - -/* ------------------------------------------------------------------ */ - - -/* ------------------------------------------------------------------ */ - -static struct videobuf_queue *get_queue(struct file *file) +static void stop_streaming(struct vb2_queue *q) { - struct video_device *vdev = video_devdata(file); - struct cx8800_fh *fh = file->private_data; + struct cx8800_dev *dev = q->drv_priv; + struct cx88_core *core = dev->core; + struct cx88_dmaqueue *dmaq = &dev->vidq; + unsigned long flags; - switch (vdev->vfl_type) { - case VFL_TYPE_GRABBER: - return &fh->vidq; - case VFL_TYPE_VBI: - return &fh->vbiq; - default: - BUG(); + cx_clear(MO_VID_DMACNTRL, 0x11); + cx_clear(VID_CAPTURE_CONTROL, 0x06); + spin_lock_irqsave(&dev->slock, flags); + while (!list_empty(&dmaq->active)) { + struct cx88_buffer *buf = list_entry(dmaq->active.next, + struct cx88_buffer, list); + + list_del(&buf->list); + vb2_buffer_done(&buf->vb, VB2_BUF_STATE_ERROR); } + spin_unlock_irqrestore(&dev->slock, flags); } -static int get_resource(struct file *file) -{ - struct video_device *vdev = video_devdata(file); +static struct vb2_ops cx8800_video_qops = { + .queue_setup = queue_setup, + .buf_prepare = buffer_prepare, + .buf_finish = buffer_finish, + .buf_queue = buffer_queue, + .wait_prepare = vb2_ops_wait_prepare, + .wait_finish = vb2_ops_wait_finish, + .start_streaming = start_streaming, + .stop_streaming = stop_streaming, +}; - switch (vdev->vfl_type) { - case VFL_TYPE_GRABBER: - return RESOURCE_VIDEO; - case VFL_TYPE_VBI: - return RESOURCE_VBI; - default: - BUG(); - } -} +/* ------------------------------------------------------------------ */ -static int video_open(struct file *file) +static int radio_open(struct file *file) { - struct video_device *vdev = video_devdata(file); struct cx8800_dev *dev = video_drvdata(file); struct cx88_core *core = dev->core; - struct cx8800_fh *fh; - enum v4l2_buf_type type = 0; - int radio = 0; + int ret = v4l2_fh_open(file); - switch (vdev->vfl_type) { - case VFL_TYPE_GRABBER: - type = V4L2_BUF_TYPE_VIDEO_CAPTURE; - break; - case VFL_TYPE_VBI: - type = V4L2_BUF_TYPE_VBI_CAPTURE; - break; - case VFL_TYPE_RADIO: - radio = 1; - break; - } - - dprintk(1, "open dev=%s radio=%d type=%s\n", - video_device_node_name(vdev), radio, v4l2_type_names[type]); - - /* allocate + initialize per filehandle data */ - fh = kzalloc(sizeof(*fh),GFP_KERNEL); - if (unlikely(!fh)) - return -ENOMEM; - - v4l2_fh_init(&fh->fh, vdev); - file->private_data = fh; - fh->dev = dev; + if (ret) + return ret; - mutex_lock(&core->lock); - - videobuf_queue_sg_init(&fh->vidq, &cx8800_video_qops, - &dev->pci->dev, &dev->slock, - V4L2_BUF_TYPE_VIDEO_CAPTURE, - V4L2_FIELD_INTERLACED, - sizeof(struct cx88_buffer), - fh, NULL); - videobuf_queue_sg_init(&fh->vbiq, &cx8800_vbi_qops, - &dev->pci->dev, &dev->slock, - V4L2_BUF_TYPE_VBI_CAPTURE, - V4L2_FIELD_SEQ_TB, - sizeof(struct cx88_buffer), - fh, NULL); - - if (vdev->vfl_type == VFL_TYPE_RADIO) { - dprintk(1,"video_open: setting radio device\n"); - cx_write(MO_GP3_IO, core->board.radio.gpio3); - cx_write(MO_GP0_IO, core->board.radio.gpio0); - cx_write(MO_GP1_IO, core->board.radio.gpio1); - cx_write(MO_GP2_IO, core->board.radio.gpio2); - if (core->board.radio.audioroute) { - if (core->sd_wm8775) { - call_all(core, audio, s_routing, + cx_write(MO_GP3_IO, core->board.radio.gpio3); + cx_write(MO_GP0_IO, core->board.radio.gpio0); + cx_write(MO_GP1_IO, core->board.radio.gpio1); + cx_write(MO_GP2_IO, core->board.radio.gpio2); + if (core->board.radio.audioroute) { + if (core->sd_wm8775) { + call_all(core, audio, s_routing, core->board.radio.audioroute, 0, 0); - } - /* "I2S ADC mode" */ - core->tvaudio = WW_I2SADC; - cx88_set_tvaudio(core); - } else { - /* FM Mode */ - core->tvaudio = WW_FM; - cx88_set_tvaudio(core); - cx88_set_stereo(core,V4L2_TUNER_MODE_STEREO,1); } - call_all(core, tuner, s_radio); - } - - core->users++; - mutex_unlock(&core->lock); - v4l2_fh_add(&fh->fh); - - return 0; -} - -static ssize_t -video_read(struct file *file, char __user *data, size_t count, loff_t *ppos) -{ - struct video_device *vdev = video_devdata(file); - struct cx8800_fh *fh = file->private_data; - - switch (vdev->vfl_type) { - case VFL_TYPE_GRABBER: - if (res_locked(fh->dev,RESOURCE_VIDEO)) - return -EBUSY; - return videobuf_read_one(&fh->vidq, data, count, ppos, - file->f_flags & O_NONBLOCK); - case VFL_TYPE_VBI: - if (!res_get(fh->dev,fh,RESOURCE_VBI)) - return -EBUSY; - return videobuf_read_stream(&fh->vbiq, data, count, ppos, 1, - file->f_flags & O_NONBLOCK); - default: - BUG(); - } -} - -static unsigned int -video_poll(struct file *file, struct poll_table_struct *wait) -{ - struct video_device *vdev = video_devdata(file); - struct cx8800_fh *fh = file->private_data; - struct cx88_buffer *buf; - unsigned int rc = v4l2_ctrl_poll(file, wait); - - if (vdev->vfl_type == VFL_TYPE_VBI) { - if (!res_get(fh->dev,fh,RESOURCE_VBI)) - return rc | POLLERR; - return rc | videobuf_poll_stream(file, &fh->vbiq, wait); - } - mutex_lock(&fh->vidq.vb_lock); - if (res_check(fh,RESOURCE_VIDEO)) { - /* streaming capture */ - if (list_empty(&fh->vidq.stream)) - goto done; - buf = list_entry(fh->vidq.stream.next,struct cx88_buffer,vb.stream); + /* "I2S ADC mode" */ + core->tvaudio = WW_I2SADC; + cx88_set_tvaudio(core); } else { - /* read() capture */ - buf = (struct cx88_buffer*)fh->vidq.read_buf; - if (NULL == buf) - goto done; - } - poll_wait(file, &buf->vb.done, wait); - if (buf->vb.state == VIDEOBUF_DONE || - buf->vb.state == VIDEOBUF_ERROR) - rc |= POLLIN|POLLRDNORM; -done: - mutex_unlock(&fh->vidq.vb_lock); - return rc; -} - -static int video_release(struct file *file) -{ - struct cx8800_fh *fh = file->private_data; - struct cx8800_dev *dev = fh->dev; - - /* turn off overlay */ - if (res_check(fh, RESOURCE_OVERLAY)) { - /* FIXME */ - res_free(dev,fh,RESOURCE_OVERLAY); - } - - /* stop video capture */ - if (res_check(fh, RESOURCE_VIDEO)) { - videobuf_queue_cancel(&fh->vidq); - res_free(dev,fh,RESOURCE_VIDEO); + /* FM Mode */ + core->tvaudio = WW_FM; + cx88_set_tvaudio(core); + cx88_set_stereo(core, V4L2_TUNER_MODE_STEREO, 1); } - if (fh->vidq.read_buf) { - buffer_release(&fh->vidq,fh->vidq.read_buf); - kfree(fh->vidq.read_buf); - } - - /* stop vbi capture */ - if (res_check(fh, RESOURCE_VBI)) { - videobuf_stop(&fh->vbiq); - res_free(dev,fh,RESOURCE_VBI); - } - - videobuf_mmap_free(&fh->vidq); - videobuf_mmap_free(&fh->vbiq); - - mutex_lock(&dev->core->lock); - v4l2_fh_del(&fh->fh); - v4l2_fh_exit(&fh->fh); - file->private_data = NULL; - kfree(fh); - - dev->core->users--; - if (!dev->core->users) - call_all(dev->core, core, s_power, 0); - mutex_unlock(&dev->core->lock); - + call_all(core, tuner, s_radio); return 0; } -static int -video_mmap(struct file *file, struct vm_area_struct * vma) -{ - return videobuf_mmap_mapper(get_queue(file), vma); -} - /* ------------------------------------------------------------------ */ /* VIDEO CTRL IOCTLS */ @@ -999,12 +723,12 @@ static int cx8800_s_aud_ctrl(struct v4l2_ctrl *ctrl) static int vidioc_g_fmt_vid_cap(struct file *file, void *priv, struct v4l2_format *f) { - struct cx8800_fh *fh = priv; - struct cx8800_dev *dev = fh->dev; + struct cx8800_dev *dev = video_drvdata(file); + struct cx88_core *core = dev->core; - f->fmt.pix.width = dev->width; - f->fmt.pix.height = dev->height; - f->fmt.pix.field = fh->vidq.field; + f->fmt.pix.width = core->width; + f->fmt.pix.height = core->height; + f->fmt.pix.field = core->field; f->fmt.pix.pixelformat = dev->fmt->fourcc; f->fmt.pix.bytesperline = (f->fmt.pix.width * dev->fmt->depth) >> 3; @@ -1017,7 +741,8 @@ static int vidioc_g_fmt_vid_cap(struct file *file, void *priv, static int vidioc_try_fmt_vid_cap(struct file *file, void *priv, struct v4l2_format *f) { - struct cx88_core *core = ((struct cx8800_fh *)priv)->dev->core; + struct cx8800_dev *dev = video_drvdata(file); + struct cx88_core *core = dev->core; const struct cx8800_fmt *fmt; enum v4l2_field field; unsigned int maxw, maxh; @@ -1026,30 +751,30 @@ static int vidioc_try_fmt_vid_cap(struct file *file, void *priv, if (NULL == fmt) return -EINVAL; - field = f->fmt.pix.field; - maxw = norm_maxw(core->tvnorm); - maxh = norm_maxh(core->tvnorm); + maxw = norm_maxw(core->tvnorm); + maxh = norm_maxh(core->tvnorm); - if (V4L2_FIELD_ANY == field) { - field = (f->fmt.pix.height > maxh/2) - ? V4L2_FIELD_INTERLACED - : V4L2_FIELD_BOTTOM; - } + field = f->fmt.pix.field; switch (field) { case V4L2_FIELD_TOP: case V4L2_FIELD_BOTTOM: - maxh = maxh / 2; - break; case V4L2_FIELD_INTERLACED: + case V4L2_FIELD_SEQ_BT: + case V4L2_FIELD_SEQ_TB: break; default: - return -EINVAL; + field = (f->fmt.pix.height > maxh / 2) + ? V4L2_FIELD_INTERLACED + : V4L2_FIELD_BOTTOM; + break; } + if (V4L2_FIELD_HAS_T_OR_B(field)) + maxh /= 2; - f->fmt.pix.field = field; v4l_bound_align_image(&f->fmt.pix.width, 48, maxw, 2, &f->fmt.pix.height, 32, maxh, 0, 0); + f->fmt.pix.field = field; f->fmt.pix.bytesperline = (f->fmt.pix.width * fmt->depth) >> 3; f->fmt.pix.sizeimage = @@ -1061,16 +786,20 @@ static int vidioc_try_fmt_vid_cap(struct file *file, void *priv, static int vidioc_s_fmt_vid_cap(struct file *file, void *priv, struct v4l2_format *f) { - struct cx8800_fh *fh = priv; - struct cx8800_dev *dev = fh->dev; + struct cx8800_dev *dev = video_drvdata(file); + struct cx88_core *core = dev->core; int err = vidioc_try_fmt_vid_cap (file,priv,f); if (0 != err) return err; - dev->fmt = format_by_fourcc(f->fmt.pix.pixelformat); - dev->width = f->fmt.pix.width; - dev->height = f->fmt.pix.height; - fh->vidq.field = f->fmt.pix.field; + if (vb2_is_busy(&dev->vb2_vidq) || vb2_is_busy(&dev->vb2_vbiq)) + return -EBUSY; + if (core->dvbdev && vb2_is_busy(&core->dvbdev->vb2_mpegq)) + return -EBUSY; + dev->fmt = format_by_fourcc(f->fmt.pix.pixelformat); + core->width = f->fmt.pix.width; + core->height = f->fmt.pix.height; + core->field = f->fmt.pix.field; return 0; } @@ -1104,8 +833,8 @@ EXPORT_SYMBOL(cx88_querycap); static int vidioc_querycap(struct file *file, void *priv, struct v4l2_capability *cap) { - struct cx8800_dev *dev = ((struct cx8800_fh *)priv)->dev; - struct cx88_core *core = dev->core; + struct cx8800_dev *dev = video_drvdata(file); + struct cx88_core *core = dev->core; strcpy(cap->driver, "cx8800"); sprintf(cap->bus_info, "PCI:%s", pci_name(dev->pci)); @@ -1125,64 +854,10 @@ static int vidioc_enum_fmt_vid_cap (struct file *file, void *priv, return 0; } -static int vidioc_reqbufs (struct file *file, void *priv, struct v4l2_requestbuffers *p) -{ - return videobuf_reqbufs(get_queue(file), p); -} - -static int vidioc_querybuf (struct file *file, void *priv, struct v4l2_buffer *p) -{ - return videobuf_querybuf(get_queue(file), p); -} - -static int vidioc_qbuf (struct file *file, void *priv, struct v4l2_buffer *p) -{ - return videobuf_qbuf(get_queue(file), p); -} - -static int vidioc_dqbuf (struct file *file, void *priv, struct v4l2_buffer *p) -{ - return videobuf_dqbuf(get_queue(file), p, - file->f_flags & O_NONBLOCK); -} - -static int vidioc_streamon(struct file *file, void *priv, enum v4l2_buf_type i) -{ - struct video_device *vdev = video_devdata(file); - struct cx8800_fh *fh = priv; - struct cx8800_dev *dev = fh->dev; - - if ((vdev->vfl_type == VFL_TYPE_GRABBER && i != V4L2_BUF_TYPE_VIDEO_CAPTURE) || - (vdev->vfl_type == VFL_TYPE_VBI && i != V4L2_BUF_TYPE_VBI_CAPTURE)) - return -EINVAL; - - if (unlikely(!res_get(dev, fh, get_resource(file)))) - return -EBUSY; - return videobuf_streamon(get_queue(file)); -} - -static int vidioc_streamoff(struct file *file, void *priv, enum v4l2_buf_type i) -{ - struct video_device *vdev = video_devdata(file); - struct cx8800_fh *fh = priv; - struct cx8800_dev *dev = fh->dev; - int err, res; - - if ((vdev->vfl_type == VFL_TYPE_GRABBER && i != V4L2_BUF_TYPE_VIDEO_CAPTURE) || - (vdev->vfl_type == VFL_TYPE_VBI && i != V4L2_BUF_TYPE_VBI_CAPTURE)) - return -EINVAL; - - res = get_resource(file); - err = videobuf_streamoff(get_queue(file)); - if (err < 0) - return err; - res_free(dev,fh,res); - return 0; -} - static int vidioc_g_std(struct file *file, void *priv, v4l2_std_id *tvnorm) { - struct cx88_core *core = ((struct cx8800_fh *)priv)->dev->core; + struct cx8800_dev *dev = video_drvdata(file); + struct cx88_core *core = dev->core; *tvnorm = core->tvnorm; return 0; @@ -1190,13 +865,10 @@ static int vidioc_g_std(struct file *file, void *priv, v4l2_std_id *tvnorm) static int vidioc_s_std(struct file *file, void *priv, v4l2_std_id tvnorms) { - struct cx88_core *core = ((struct cx8800_fh *)priv)->dev->core; - - mutex_lock(&core->lock); - cx88_set_tvnorm(core, tvnorms); - mutex_unlock(&core->lock); + struct cx8800_dev *dev = video_drvdata(file); + struct cx88_core *core = dev->core; - return 0; + return cx88_set_tvnorm(core, tvnorms); } /* only one input in this sample driver */ @@ -1233,13 +905,15 @@ EXPORT_SYMBOL(cx88_enum_input); static int vidioc_enum_input (struct file *file, void *priv, struct v4l2_input *i) { - struct cx88_core *core = ((struct cx8800_fh *)priv)->dev->core; + struct cx8800_dev *dev = video_drvdata(file); + struct cx88_core *core = dev->core; return cx88_enum_input (core,i); } static int vidioc_g_input (struct file *file, void *priv, unsigned int *i) { - struct cx88_core *core = ((struct cx8800_fh *)priv)->dev->core; + struct cx8800_dev *dev = video_drvdata(file); + struct cx88_core *core = dev->core; *i = core->input; return 0; @@ -1247,24 +921,24 @@ static int vidioc_g_input (struct file *file, void *priv, unsigned int *i) static int vidioc_s_input (struct file *file, void *priv, unsigned int i) { - struct cx88_core *core = ((struct cx8800_fh *)priv)->dev->core; + struct cx8800_dev *dev = video_drvdata(file); + struct cx88_core *core = dev->core; if (i >= 4) return -EINVAL; if (0 == INPUT(i).type) return -EINVAL; - mutex_lock(&core->lock); cx88_newstation(core); cx88_video_mux(core,i); - mutex_unlock(&core->lock); return 0; } static int vidioc_g_tuner (struct file *file, void *priv, struct v4l2_tuner *t) { - struct cx88_core *core = ((struct cx8800_fh *)priv)->dev->core; + struct cx8800_dev *dev = video_drvdata(file); + struct cx88_core *core = dev->core; u32 reg; if (unlikely(UNSET == core->board.tuner_type)) @@ -1286,7 +960,8 @@ static int vidioc_g_tuner (struct file *file, void *priv, static int vidioc_s_tuner (struct file *file, void *priv, const struct v4l2_tuner *t) { - struct cx88_core *core = ((struct cx8800_fh *)priv)->dev->core; + struct cx8800_dev *dev = video_drvdata(file); + struct cx88_core *core = dev->core; if (UNSET == core->board.tuner_type) return -EINVAL; @@ -1300,8 +975,8 @@ static int vidioc_s_tuner (struct file *file, void *priv, static int vidioc_g_frequency (struct file *file, void *priv, struct v4l2_frequency *f) { - struct cx8800_fh *fh = priv; - struct cx88_core *core = fh->dev->core; + struct cx8800_dev *dev = video_drvdata(file); + struct cx88_core *core = dev->core; if (unlikely(UNSET == core->board.tuner_type)) return -EINVAL; @@ -1325,7 +1000,6 @@ int cx88_set_freq (struct cx88_core *core, if (unlikely(f->tuner != 0)) return -EINVAL; - mutex_lock(&core->lock); cx88_newstation(core); call_all(core, tuner, s_frequency, f); call_all(core, tuner, g_frequency, &new_freq); @@ -1335,8 +1009,6 @@ int cx88_set_freq (struct cx88_core *core, msleep (10); cx88_set_tvaudio(core); - mutex_unlock(&core->lock); - return 0; } EXPORT_SYMBOL(cx88_set_freq); @@ -1344,8 +1016,8 @@ EXPORT_SYMBOL(cx88_set_freq); static int vidioc_s_frequency (struct file *file, void *priv, const struct v4l2_frequency *f) { - struct cx8800_fh *fh = priv; - struct cx88_core *core = fh->dev->core; + struct cx8800_dev *dev = video_drvdata(file); + struct cx88_core *core = dev->core; return cx88_set_freq(core, f); } @@ -1354,7 +1026,8 @@ static int vidioc_s_frequency (struct file *file, void *priv, static int vidioc_g_register (struct file *file, void *fh, struct v4l2_dbg_register *reg) { - struct cx88_core *core = ((struct cx8800_fh*)fh)->dev->core; + struct cx8800_dev *dev = video_drvdata(file); + struct cx88_core *core = dev->core; /* cx2388x has a 24-bit register space */ reg->val = cx_read(reg->reg & 0xfffffc); @@ -1365,7 +1038,8 @@ static int vidioc_g_register (struct file *file, void *fh, static int vidioc_s_register (struct file *file, void *fh, const struct v4l2_dbg_register *reg) { - struct cx88_core *core = ((struct cx8800_fh*)fh)->dev->core; + struct cx8800_dev *dev = video_drvdata(file); + struct cx88_core *core = dev->core; cx_write(reg->reg & 0xfffffc, reg->val); return 0; @@ -1379,7 +1053,8 @@ static int vidioc_s_register (struct file *file, void *fh, static int radio_g_tuner (struct file *file, void *priv, struct v4l2_tuner *t) { - struct cx88_core *core = ((struct cx8800_fh *)priv)->dev->core; + struct cx8800_dev *dev = video_drvdata(file); + struct cx88_core *core = dev->core; if (unlikely(t->index > 0)) return -EINVAL; @@ -1393,7 +1068,8 @@ static int radio_g_tuner (struct file *file, void *priv, static int radio_s_tuner (struct file *file, void *priv, const struct v4l2_tuner *t) { - struct cx88_core *core = ((struct cx8800_fh *)priv)->dev->core; + struct cx8800_dev *dev = video_drvdata(file); + struct cx88_core *core = dev->core; if (0 != t->index) return -EINVAL; @@ -1404,32 +1080,6 @@ static int radio_s_tuner (struct file *file, void *priv, /* ----------------------------------------------------------- */ -static void cx8800_vid_timeout(unsigned long data) -{ - struct cx8800_dev *dev = (struct cx8800_dev*)data; - struct cx88_core *core = dev->core; - struct cx88_dmaqueue *q = &dev->vidq; - struct cx88_buffer *buf; - unsigned long flags; - - cx88_sram_channel_dump(core, &cx88_sram_channels[SRAM_CH21]); - - cx_clear(MO_VID_DMACNTRL, 0x11); - cx_clear(VID_CAPTURE_CONTROL, 0x06); - - spin_lock_irqsave(&dev->slock,flags); - while (!list_empty(&q->active)) { - buf = list_entry(q->active.next, struct cx88_buffer, vb.queue); - list_del(&buf->vb.queue); - buf->vb.state = VIDEOBUF_ERROR; - wake_up(&buf->vb.done); - printk("%s/0: [%p/%d] timeout - dma=0x%08lx\n", core->name, - buf, buf->vb.i, (unsigned long)buf->risc.dma); - } - restart_video_queue(dev,q); - spin_unlock_irqrestore(&dev->slock,flags); -} - static const char *cx88_vid_irqs[32] = { "y_risci1", "u_risci1", "v_risci1", "vbi_risc1", "y_risci2", "u_risci2", "v_risci2", "vbi_risc2", @@ -1476,22 +1126,6 @@ static void cx8800_vid_irq(struct cx8800_dev *dev) cx88_wakeup(core, &dev->vbiq, count); spin_unlock(&dev->slock); } - - /* risc2 y */ - if (status & 0x10) { - dprintk(2,"stopper video\n"); - spin_lock(&dev->slock); - restart_video_queue(dev,&dev->vidq); - spin_unlock(&dev->slock); - } - - /* risc2 vbi */ - if (status & 0x80) { - dprintk(2,"stopper vbi\n"); - spin_lock(&dev->slock); - cx8800_restart_vbi_queue(dev,&dev->vbiq); - spin_unlock(&dev->slock); - } } static irqreturn_t cx8800_irq(int irq, void *dev_id) @@ -1530,11 +1164,11 @@ static irqreturn_t cx8800_irq(int irq, void *dev_id) static const struct v4l2_file_operations video_fops = { .owner = THIS_MODULE, - .open = video_open, - .release = video_release, - .read = video_read, - .poll = video_poll, - .mmap = video_mmap, + .open = v4l2_fh_open, + .release = vb2_fop_release, + .read = vb2_fop_read, + .poll = vb2_fop_poll, + .mmap = vb2_fop_mmap, .unlocked_ioctl = video_ioctl2, }; @@ -1544,17 +1178,17 @@ static const struct v4l2_ioctl_ops video_ioctl_ops = { .vidioc_g_fmt_vid_cap = vidioc_g_fmt_vid_cap, .vidioc_try_fmt_vid_cap = vidioc_try_fmt_vid_cap, .vidioc_s_fmt_vid_cap = vidioc_s_fmt_vid_cap, - .vidioc_reqbufs = vidioc_reqbufs, - .vidioc_querybuf = vidioc_querybuf, - .vidioc_qbuf = vidioc_qbuf, - .vidioc_dqbuf = vidioc_dqbuf, + .vidioc_reqbufs = vb2_ioctl_reqbufs, + .vidioc_querybuf = vb2_ioctl_querybuf, + .vidioc_qbuf = vb2_ioctl_qbuf, + .vidioc_dqbuf = vb2_ioctl_dqbuf, .vidioc_g_std = vidioc_g_std, .vidioc_s_std = vidioc_s_std, .vidioc_enum_input = vidioc_enum_input, .vidioc_g_input = vidioc_g_input, .vidioc_s_input = vidioc_s_input, - .vidioc_streamon = vidioc_streamon, - .vidioc_streamoff = vidioc_streamoff, + .vidioc_streamon = vb2_ioctl_streamon, + .vidioc_streamoff = vb2_ioctl_streamoff, .vidioc_g_tuner = vidioc_g_tuner, .vidioc_s_tuner = vidioc_s_tuner, .vidioc_g_frequency = vidioc_g_frequency, @@ -1579,17 +1213,17 @@ static const struct v4l2_ioctl_ops vbi_ioctl_ops = { .vidioc_g_fmt_vbi_cap = cx8800_vbi_fmt, .vidioc_try_fmt_vbi_cap = cx8800_vbi_fmt, .vidioc_s_fmt_vbi_cap = cx8800_vbi_fmt, - .vidioc_reqbufs = vidioc_reqbufs, - .vidioc_querybuf = vidioc_querybuf, - .vidioc_qbuf = vidioc_qbuf, - .vidioc_dqbuf = vidioc_dqbuf, + .vidioc_reqbufs = vb2_ioctl_reqbufs, + .vidioc_querybuf = vb2_ioctl_querybuf, + .vidioc_qbuf = vb2_ioctl_qbuf, + .vidioc_dqbuf = vb2_ioctl_dqbuf, .vidioc_g_std = vidioc_g_std, .vidioc_s_std = vidioc_s_std, .vidioc_enum_input = vidioc_enum_input, .vidioc_g_input = vidioc_g_input, .vidioc_s_input = vidioc_s_input, - .vidioc_streamon = vidioc_streamon, - .vidioc_streamoff = vidioc_streamoff, + .vidioc_streamon = vb2_ioctl_streamon, + .vidioc_streamoff = vb2_ioctl_streamoff, .vidioc_g_tuner = vidioc_g_tuner, .vidioc_s_tuner = vidioc_s_tuner, .vidioc_g_frequency = vidioc_g_frequency, @@ -1610,9 +1244,9 @@ static const struct video_device cx8800_vbi_template = { static const struct v4l2_file_operations radio_fops = { .owner = THIS_MODULE, - .open = video_open, + .open = radio_open, .poll = v4l2_ctrl_poll, - .release = video_release, + .release = v4l2_fh_release, .unlocked_ioctl = video_ioctl2, }; @@ -1676,6 +1310,7 @@ static int cx8800_initdev(struct pci_dev *pci_dev, { struct cx8800_dev *dev; struct cx88_core *core; + struct vb2_queue *q; int err; int i; @@ -1713,25 +1348,12 @@ static int cx8800_initdev(struct pci_dev *pci_dev, /* initialize driver struct */ spin_lock_init(&dev->slock); - core->tvnorm = V4L2_STD_NTSC_M; /* init video dma queues */ INIT_LIST_HEAD(&dev->vidq.active); - INIT_LIST_HEAD(&dev->vidq.queued); - dev->vidq.timeout.function = cx8800_vid_timeout; - dev->vidq.timeout.data = (unsigned long)dev; - init_timer(&dev->vidq.timeout); - cx88_risc_stopper(dev->pci,&dev->vidq.stopper, - MO_VID_DMACNTRL,0x11,0x00); /* init vbi dma queues */ INIT_LIST_HEAD(&dev->vbiq.active); - INIT_LIST_HEAD(&dev->vbiq.queued); - dev->vbiq.timeout.function = cx8800_vbi_timeout; - dev->vbiq.timeout.data = (unsigned long)dev; - init_timer(&dev->vbiq.timeout); - cx88_risc_stopper(dev->pci,&dev->vbiq.stopper, - MO_VID_DMACNTRL,0x88,0x00); /* get irq */ err = request_irq(pci_dev->irq, cx8800_irq, @@ -1820,9 +1442,10 @@ static int cx8800_initdev(struct pci_dev *pci_dev, /* Sets device info at pci_dev */ pci_set_drvdata(pci_dev, dev); - dev->width = 320; - dev->height = 240; - dev->fmt = format_by_fourcc(V4L2_PIX_FMT_BGR24); + dev->fmt = format_by_fourcc(V4L2_PIX_FMT_BGR24); + + /* Maintain a reference so cx88-blackbird can query the 8800 device. */ + core->v4ldev = dev; /* initial device configuration */ mutex_lock(&core->lock); @@ -1831,11 +1454,44 @@ static int cx8800_initdev(struct pci_dev *pci_dev, v4l2_ctrl_handler_setup(&core->audio_hdl); cx88_video_mux(core, 0); + q = &dev->vb2_vidq; + q->type = V4L2_BUF_TYPE_VIDEO_CAPTURE; + q->io_modes = VB2_MMAP | VB2_USERPTR | VB2_DMABUF | VB2_READ; + q->gfp_flags = GFP_DMA32; + q->min_buffers_needed = 2; + q->drv_priv = dev; + q->buf_struct_size = sizeof(struct cx88_buffer); + q->ops = &cx8800_video_qops; + q->mem_ops = &vb2_dma_sg_memops; + q->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC; + q->lock = &core->lock; + + err = vb2_queue_init(q); + if (err < 0) + goto fail_unreg; + + q = &dev->vb2_vbiq; + q->type = V4L2_BUF_TYPE_VBI_CAPTURE; + q->io_modes = VB2_MMAP | VB2_USERPTR | VB2_DMABUF | VB2_READ; + q->gfp_flags = GFP_DMA32; + q->min_buffers_needed = 2; + q->drv_priv = dev; + q->buf_struct_size = sizeof(struct cx88_buffer); + q->ops = &cx8800_vbi_qops; + q->mem_ops = &vb2_dma_sg_memops; + q->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC; + q->lock = &core->lock; + + err = vb2_queue_init(q); + if (err < 0) + goto fail_unreg; + /* register v4l devices */ dev->video_dev = cx88_vdev_init(core,dev->pci, &cx8800_video_template,"video"); video_set_drvdata(dev->video_dev, dev); dev->video_dev->ctrl_handler = &core->video_hdl; + dev->video_dev->queue = &dev->vb2_vidq; err = video_register_device(dev->video_dev,VFL_TYPE_GRABBER, video_nr[core->nr]); if (err < 0) { @@ -1848,6 +1504,7 @@ static int cx8800_initdev(struct pci_dev *pci_dev, dev->vbi_dev = cx88_vdev_init(core,dev->pci,&cx8800_vbi_template,"vbi"); video_set_drvdata(dev->vbi_dev, dev); + dev->vbi_dev->queue = &dev->vb2_vbiq; err = video_register_device(dev->vbi_dev,VFL_TYPE_VBI, vbi_nr[core->nr]); if (err < 0) { @@ -1875,7 +1532,7 @@ static int cx8800_initdev(struct pci_dev *pci_dev, } /* start tvaudio thread */ - if (core->board.tuner_type != TUNER_ABSENT) { + if (core->board.tuner_type != UNSET) { core->kthread = kthread_run(cx88_audio_thread, core, "cx88 tvaudio"); if (IS_ERR(core->kthread)) { err = PTR_ERR(core->kthread); @@ -1892,6 +1549,7 @@ fail_unreg: free_irq(pci_dev->irq, dev); mutex_unlock(&core->lock); fail_core: + core->v4ldev = NULL; cx88_core_put(core,dev->pci); fail_free: kfree(dev); @@ -1913,15 +1571,16 @@ static void cx8800_finidev(struct pci_dev *pci_dev) cx88_ir_stop(core); cx88_shutdown(core); /* FIXME */ - pci_disable_device(pci_dev); /* unregister stuff */ free_irq(pci_dev->irq, dev); cx8800_unregister_video(dev); + pci_disable_device(pci_dev); + + core->v4ldev = NULL; /* free memory */ - btcx_riscmem_free(dev->pci,&dev->vidq.stopper); cx88_core_put(core,dev->pci); kfree(dev); } @@ -1938,12 +1597,10 @@ static int cx8800_suspend(struct pci_dev *pci_dev, pm_message_t state) if (!list_empty(&dev->vidq.active)) { printk("%s/0: suspend video\n", core->name); stop_video_dma(dev); - del_timer(&dev->vidq.timeout); } if (!list_empty(&dev->vbiq.active)) { printk("%s/0: suspend vbi\n", core->name); cx8800_stop_vbi_dma(dev); - del_timer(&dev->vbiq.timeout); } spin_unlock_irqrestore(&dev->slock, flags); diff --git a/drivers/media/pci/cx88/cx88.h b/drivers/media/pci/cx88/cx88.h index 28893a6b249..3b0ae754f16 100644 --- a/drivers/media/pci/cx88/cx88.h +++ b/drivers/media/pci/cx88/cx88.h @@ -29,19 +29,18 @@ #include <media/v4l2-fh.h> #include <media/tuner.h> #include <media/tveeprom.h> -#include <media/videobuf-dma-sg.h> +#include <media/videobuf2-dma-sg.h> #include <media/cx2341x.h> -#include <media/videobuf-dvb.h> +#include <media/videobuf2-dvb.h> #include <media/ir-kbd-i2c.h> #include <media/wm8775.h> -#include "btcx-risc.h" #include "cx88-reg.h" #include "tuner-xc2028.h" #include <linux/mutex.h> -#define CX88_VERSION "0.0.9" +#define CX88_VERSION "1.0.0" #define UNSET (-1U) @@ -62,7 +61,8 @@ #define FORMAT_FLAGS_PACKED 0x01 #define FORMAT_FLAGS_PLANAR 0x02 -#define VBI_LINE_COUNT 17 +#define VBI_LINE_PAL_COUNT 18 +#define VBI_LINE_NTSC_COUNT 12 #define VBI_LINE_LENGTH 2048 #define AUD_RDS_LINES 4 @@ -95,13 +95,13 @@ enum cx8802_board_access { static inline unsigned int norm_maxw(v4l2_std_id norm) { - return (norm & (V4L2_STD_MN & ~V4L2_STD_PAL_Nc)) ? 720 : 768; + return 720; } static inline unsigned int norm_maxh(v4l2_std_id norm) { - return (norm & V4L2_STD_625_50) ? 576 : 480; + return (norm & V4L2_STD_525_60) ? 480 : 576; } /* ----------------------------------------------------------- */ @@ -311,26 +311,33 @@ enum cx88_tvaudio { #define BUFFER_TIMEOUT msecs_to_jiffies(2000) +struct cx88_riscmem { + unsigned int size; + __le32 *cpu; + __le32 *jmp; + dma_addr_t dma; +}; + /* buffer for one video frame */ struct cx88_buffer { /* common v4l buffer stuff -- must be first */ - struct videobuf_buffer vb; + struct vb2_buffer vb; + struct list_head list; /* cx88 specific */ unsigned int bpl; - struct btcx_riscmem risc; - const struct cx8800_fmt *fmt; + struct cx88_riscmem risc; u32 count; }; struct cx88_dmaqueue { struct list_head active; - struct list_head queued; - struct timer_list timeout; - struct btcx_riscmem stopper; u32 count; }; +struct cx8800_dev; +struct cx8802_dev; + struct cx88_core { struct list_head devlist; atomic_t refcount; @@ -376,6 +383,8 @@ struct cx88_core { /* state info */ struct task_struct *kthread; v4l2_std_id tvnorm; + unsigned width, height; + unsigned field; enum cx88_tvaudio tvaudio; u32 audiomode_manual; u32 audiomode_current; @@ -395,11 +404,14 @@ struct cx88_core { struct mutex lock; /* various v4l controls */ u32 freq; - int users; - int mpeg_users; - /* cx88-video needs to access cx8802 for hybrid tuner pll access. */ + /* + * cx88-video needs to access cx8802 for hybrid tuner pll access and + * for vb2_is_busy() checks. + */ struct cx8802_dev *dvbdev; + /* cx88-blackbird needs to access cx8800 for vb2_is_busy() checks */ + struct cx8800_dev *v4ldev; enum cx88_board_type active_type_id; int active_ref; int active_fe_id; @@ -453,24 +465,9 @@ static inline struct cx88_core *to_core(struct v4l2_device *v4l2_dev) val; \ }) -struct cx8800_dev; -struct cx8802_dev; - /* ----------------------------------------------------------- */ /* function 0: video stuff */ -struct cx8800_fh { - struct v4l2_fh fh; - struct cx8800_dev *dev; - unsigned int resources; - - /* video capture */ - struct videobuf_queue vidq; - - /* vbi capture */ - struct videobuf_queue vbiq; -}; - struct cx8800_suspend_state { int disabled; }; @@ -490,11 +487,12 @@ struct cx8800_dev { unsigned char pci_rev,pci_lat; const struct cx8800_fmt *fmt; - unsigned int width, height; /* capture queues */ struct cx88_dmaqueue vidq; + struct vb2_queue vb2_vidq; struct cx88_dmaqueue vbiq; + struct vb2_queue vb2_vbiq; /* various v4l controls */ @@ -510,12 +508,6 @@ struct cx8800_dev { /* ----------------------------------------------------------- */ /* function 2: mpeg stuff */ -struct cx8802_fh { - struct v4l2_fh fh; - struct cx8802_dev *dev; - struct videobuf_queue mpegq; -}; - struct cx8802_suspend_state { int disabled; }; @@ -559,6 +551,7 @@ struct cx8802_dev { /* dma queues */ struct cx88_dmaqueue mpegq; + struct vb2_queue vb2_mpegq; u32 ts_packet_size; u32 ts_packet_count; @@ -570,9 +563,6 @@ struct cx8802_dev { #if IS_ENABLED(CONFIG_VIDEO_CX88_BLACKBIRD) struct video_device *mpeg_dev; u32 mailbox; - int width; - int height; - unsigned char mpeg_active; /* nonzero if mpeg encoder is active */ /* mpeg params */ struct cx2341x_handler cxhdl; @@ -580,7 +570,7 @@ struct cx8802_dev { #if IS_ENABLED(CONFIG_VIDEO_CX88_DVB) /* for dvb only */ - struct videobuf_dvb_frontends frontends; + struct vb2_dvb_frontends frontends; #endif #if IS_ENABLED(CONFIG_VIDEO_CX88_VP3054) @@ -634,22 +624,17 @@ extern void cx88_shutdown(struct cx88_core *core); extern int cx88_reset(struct cx88_core *core); extern int -cx88_risc_buffer(struct pci_dev *pci, struct btcx_riscmem *risc, +cx88_risc_buffer(struct pci_dev *pci, struct cx88_riscmem *risc, struct scatterlist *sglist, unsigned int top_offset, unsigned int bottom_offset, unsigned int bpl, unsigned int padding, unsigned int lines); extern int -cx88_risc_databuffer(struct pci_dev *pci, struct btcx_riscmem *risc, +cx88_risc_databuffer(struct pci_dev *pci, struct cx88_riscmem *risc, struct scatterlist *sglist, unsigned int bpl, unsigned int lines, unsigned int lpi); -extern int -cx88_risc_stopper(struct pci_dev *pci, struct btcx_riscmem *risc, - u32 reg, u32 mask, u32 value); -extern void -cx88_free_buffer(struct videobuf_queue *q, struct cx88_buffer *buf); extern void cx88_risc_disasm(struct cx88_core *core, - struct btcx_riscmem *risc); + struct cx88_riscmem *risc); extern int cx88_sram_channel_setup(struct cx88_core *core, const struct sram_channel *ch, unsigned int bpl, u32 risc); @@ -664,7 +649,7 @@ extern struct video_device *cx88_vdev_init(struct cx88_core *core, struct pci_dev *pci, const struct video_device *template_, const char *type); -extern struct cx88_core* cx88_core_get(struct pci_dev *pci); +extern struct cx88_core *cx88_core_get(struct pci_dev *pci); extern void cx88_core_put(struct cx88_core *core, struct pci_dev *pci); @@ -684,12 +669,10 @@ int cx8800_start_vbi_dma(struct cx8800_dev *dev, struct cx88_dmaqueue *q, struct cx88_buffer *buf); */ -int cx8800_stop_vbi_dma(struct cx8800_dev *dev); -int cx8800_restart_vbi_queue(struct cx8800_dev *dev, - struct cx88_dmaqueue *q); -void cx8800_vbi_timeout(unsigned long data); +void cx8800_stop_vbi_dma(struct cx8800_dev *dev); +int cx8800_restart_vbi_queue(struct cx8800_dev *dev, struct cx88_dmaqueue *q); -extern const struct videobuf_queue_ops cx8800_vbi_qops; +extern const struct vb2_ops cx8800_vbi_qops; /* ----------------------------------------------------------- */ /* cx88-i2c.c */ @@ -739,14 +722,17 @@ extern void cx88_i2c_init_ir(struct cx88_core *core); /* ----------------------------------------------------------- */ /* cx88-mpeg.c */ -int cx8802_buf_prepare(struct videobuf_queue *q,struct cx8802_dev *dev, - struct cx88_buffer *buf, enum v4l2_field field); +int cx8802_buf_prepare(struct vb2_queue *q, struct cx8802_dev *dev, + struct cx88_buffer *buf); void cx8802_buf_queue(struct cx8802_dev *dev, struct cx88_buffer *buf); void cx8802_cancel_buffers(struct cx8802_dev *dev); +int cx8802_start_dma(struct cx8802_dev *dev, + struct cx88_dmaqueue *q, + struct cx88_buffer *buf); /* ----------------------------------------------------------- */ /* cx88-video.c*/ -int cx88_enum_input (struct cx88_core *core,struct v4l2_input *i); +int cx88_enum_input(struct cx88_core *core, struct v4l2_input *i); int cx88_set_freq(struct cx88_core *core, const struct v4l2_frequency *f); int cx88_video_mux(struct cx88_core *core, unsigned int input); void cx88_querycap(struct file *file, struct cx88_core *core, diff --git a/drivers/media/pci/ddbridge/ddbridge-core.c b/drivers/media/pci/ddbridge/ddbridge-core.c index c82e855a081..9e3492e2076 100644 --- a/drivers/media/pci/ddbridge/ddbridge-core.c +++ b/drivers/media/pci/ddbridge/ddbridge-core.c @@ -1118,8 +1118,7 @@ static void ddb_ports_detach(struct ddb *dev) dvb_input_detach(port->input[1]); break; case DDB_PORT_CI: - if (port->output->dev) - dvb_unregister_device(port->output->dev); + dvb_unregister_device(port->output->dev); if (port->en) { ddb_input_stop(port->input[0]); ddb_output_stop(port->output); diff --git a/drivers/media/pci/ivtv/ivtv-controls.c b/drivers/media/pci/ivtv/ivtv-controls.c index 2b0ab26e11e..ccf548c255f 100644 --- a/drivers/media/pci/ivtv/ivtv-controls.c +++ b/drivers/media/pci/ivtv/ivtv-controls.c @@ -69,7 +69,7 @@ static int ivtv_s_video_encoding(struct cx2341x_handler *cxhdl, u32 val) /* fix videodecoder resolution */ fmt.width = cxhdl->width / (is_mpeg1 ? 2 : 1); fmt.height = cxhdl->height; - fmt.code = V4L2_MBUS_FMT_FIXED; + fmt.code = MEDIA_BUS_FMT_FIXED; v4l2_subdev_call(itv->sd_video, video, s_mbus_fmt, &fmt); return 0; } diff --git a/drivers/media/pci/ivtv/ivtv-ioctl.c b/drivers/media/pci/ivtv/ivtv-ioctl.c index 3e0cb77d593..4d8ee18c3fe 100644 --- a/drivers/media/pci/ivtv/ivtv-ioctl.c +++ b/drivers/media/pci/ivtv/ivtv-ioctl.c @@ -595,7 +595,7 @@ static int ivtv_s_fmt_vid_cap(struct file *file, void *fh, struct v4l2_format *f fmt->fmt.pix.width /= 2; mbus_fmt.width = fmt->fmt.pix.width; mbus_fmt.height = h; - mbus_fmt.code = V4L2_MBUS_FMT_FIXED; + mbus_fmt.code = MEDIA_BUS_FMT_FIXED; v4l2_subdev_call(itv->sd_video, video, s_mbus_fmt, &mbus_fmt); return ivtv_g_fmt_vid_cap(file, fh, fmt); } diff --git a/drivers/media/pci/ivtv/ivtv-udma.c b/drivers/media/pci/ivtv/ivtv-udma.c index 7338cb2d0a3..bee2329e0b2 100644 --- a/drivers/media/pci/ivtv/ivtv-udma.c +++ b/drivers/media/pci/ivtv/ivtv-udma.c @@ -76,7 +76,7 @@ void ivtv_udma_fill_sg_array (struct ivtv_user_dma *dma, u32 buffer_offset, u32 int i; struct scatterlist *sg; - for (i = 0, sg = dma->SGlist; i < dma->SG_length; i++, sg++) { + for (i = 0, sg = dma->SGlist; i < dma->SG_length; i++, sg = sg_next(sg)) { dma->SGarray[i].size = cpu_to_le32(sg_dma_len(sg)); dma->SGarray[i].src = cpu_to_le32(sg_dma_address(sg)); dma->SGarray[i].dst = cpu_to_le32(buffer_offset); diff --git a/drivers/media/pci/meye/meye.c b/drivers/media/pci/meye/meye.c index aeae5470881..9d9f90cb774 100644 --- a/drivers/media/pci/meye/meye.c +++ b/drivers/media/pci/meye/meye.c @@ -1031,9 +1031,6 @@ static int vidioc_querycap(struct file *file, void *fh, strcpy(cap->card, "meye"); sprintf(cap->bus_info, "PCI:%s", pci_name(meye.mchip_dev)); - cap->version = (MEYE_DRIVER_MAJORVERSION << 8) + - MEYE_DRIVER_MINORVERSION; - cap->device_caps = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_STREAMING; cap->capabilities = cap->device_caps | V4L2_CAP_DEVICE_CAPS; diff --git a/drivers/media/pci/pt1/pt1.c b/drivers/media/pci/pt1/pt1.c index db887b0c37b..acc35b42e53 100644 --- a/drivers/media/pci/pt1/pt1.c +++ b/drivers/media/pci/pt1/pt1.c @@ -109,9 +109,6 @@ struct pt1_adapter { int sleep; }; -#define pt1_printk(level, pt1, format, arg...) \ - dev_printk(level, &(pt1)->pdev->dev, format, ##arg) - static void pt1_write_reg(struct pt1 *pt1, int reg, u32 data) { writel(data, pt1->regs + reg * 4); @@ -154,7 +151,7 @@ static int pt1_sync(struct pt1 *pt1) return 0; pt1_write_reg(pt1, 0, 0x00000008); } - pt1_printk(KERN_ERR, pt1, "could not sync\n"); + dev_err(&pt1->pdev->dev, "could not sync\n"); return -EIO; } @@ -179,7 +176,7 @@ static int pt1_unlock(struct pt1 *pt1) return 0; schedule_timeout_uninterruptible((HZ + 999) / 1000); } - pt1_printk(KERN_ERR, pt1, "could not unlock\n"); + dev_err(&pt1->pdev->dev, "could not unlock\n"); return -EIO; } @@ -193,7 +190,7 @@ static int pt1_reset_pci(struct pt1 *pt1) return 0; schedule_timeout_uninterruptible((HZ + 999) / 1000); } - pt1_printk(KERN_ERR, pt1, "could not reset PCI\n"); + dev_err(&pt1->pdev->dev, "could not reset PCI\n"); return -EIO; } @@ -207,7 +204,7 @@ static int pt1_reset_ram(struct pt1 *pt1) return 0; schedule_timeout_uninterruptible((HZ + 999) / 1000); } - pt1_printk(KERN_ERR, pt1, "could not reset RAM\n"); + dev_err(&pt1->pdev->dev, "could not reset RAM\n"); return -EIO; } @@ -224,7 +221,7 @@ static int pt1_do_enable_ram(struct pt1 *pt1) } schedule_timeout_uninterruptible((HZ + 999) / 1000); } - pt1_printk(KERN_ERR, pt1, "could not enable RAM\n"); + dev_err(&pt1->pdev->dev, "could not enable RAM\n"); return -EIO; } diff --git a/drivers/media/pci/pt3/pt3.c b/drivers/media/pci/pt3/pt3.c index 1fdeac11501..7a37e8fe2ee 100644 --- a/drivers/media/pci/pt3/pt3.c +++ b/drivers/media/pci/pt3/pt3.c @@ -255,7 +255,7 @@ static int pt3_fe_init(struct pt3_board *pt3) pt3_i2c_reset(pt3); ret = pt3_init_all_demods(pt3); if (ret < 0) { - dev_warn(&pt3->pdev->dev, "Failed to init demod chips."); + dev_warn(&pt3->pdev->dev, "Failed to init demod chips\n"); return ret; } @@ -271,7 +271,7 @@ static int pt3_fe_init(struct pt3_board *pt3) init0_ter, ARRAY_SIZE(init0_ter)); if (ret < 0) { dev_warn(&pt3->pdev->dev, - "demod[%d] faild in init sequence0.", i); + "demod[%d] failed in init sequence0\n", i); return ret; } ret = fe->ops.init(fe); @@ -282,7 +282,7 @@ static int pt3_fe_init(struct pt3_board *pt3) usleep_range(2000, 4000); ret = pt3_set_tuner_power(pt3, true, false); if (ret < 0) { - dev_warn(&pt3->pdev->dev, "Failed to control tuner module."); + dev_warn(&pt3->pdev->dev, "Failed to control tuner module\n"); return ret; } @@ -297,7 +297,7 @@ static int pt3_fe_init(struct pt3_board *pt3) cfg_ter, ARRAY_SIZE(cfg_ter)); if (ret < 0) { dev_warn(&pt3->pdev->dev, - "demod[%d] faild in init sequence1.", i); + "demod[%d] failed in init sequence1\n", i); return ret; } } @@ -311,19 +311,19 @@ static int pt3_fe_init(struct pt3_board *pt3) ret = fe->ops.tuner_ops.init(fe); if (ret < 0) { dev_warn(&pt3->pdev->dev, - "Failed to init SAT-tuner[%d].", i); + "Failed to init SAT-tuner[%d]\n", i); return ret; } } ret = pt3_init_all_mxl301rf(pt3); if (ret < 0) { - dev_warn(&pt3->pdev->dev, "Failed to init TERR-tuners."); + dev_warn(&pt3->pdev->dev, "Failed to init TERR-tuners\n"); return ret; } ret = pt3_set_tuner_power(pt3, true, true); if (ret < 0) { - dev_warn(&pt3->pdev->dev, "Failed to control tuner module."); + dev_warn(&pt3->pdev->dev, "Failed to control tuner module\n"); return ret; } @@ -344,7 +344,7 @@ static int pt3_fe_init(struct pt3_board *pt3) } if (ret < 0) { dev_warn(&pt3->pdev->dev, - "Failed in initial tuning of tuner[%d].", i); + "Failed in initial tuning of tuner[%d]\n", i); return ret; } } @@ -366,7 +366,7 @@ static int pt3_fe_init(struct pt3_board *pt3) fe->ops.set_lna = &pt3_set_lna; } if (i < PT3_NUM_FE) { - dev_warn(&pt3->pdev->dev, "FE[%d] failed to standby.", i); + dev_warn(&pt3->pdev->dev, "FE[%d] failed to standby\n", i); return ret; } return 0; @@ -453,8 +453,8 @@ static int pt3_fetch_thread(void *data) pt3_init_dmabuf(adap); adap->num_discard = PT3_INITIAL_BUF_DROPS; - dev_dbg(adap->dvb_adap.device, - "PT3: [%s] started.\n", adap->thread->comm); + dev_dbg(adap->dvb_adap.device, "PT3: [%s] started\n", + adap->thread->comm); set_freezable(); while (!kthread_freezable_should_stop(&was_frozen)) { if (was_frozen) @@ -468,8 +468,8 @@ static int pt3_fetch_thread(void *data) PT3_FETCH_DELAY_DELTA * NSEC_PER_MSEC, HRTIMER_MODE_REL); } - dev_dbg(adap->dvb_adap.device, - "PT3: [%s] exited.\n", adap->thread->comm); + dev_dbg(adap->dvb_adap.device, "PT3: [%s] exited\n", + adap->thread->comm); adap->thread = NULL; return 0; } @@ -485,8 +485,8 @@ static int pt3_start_streaming(struct pt3_adapter *adap) int ret = PTR_ERR(thread); dev_warn(adap->dvb_adap.device, - "PT3 (adap:%d, dmx:%d): failed to start kthread.\n", - adap->dvb_adap.num, adap->dmxdev.dvbdev->id); + "PT3 (adap:%d, dmx:%d): failed to start kthread\n", + adap->dvb_adap.num, adap->dmxdev.dvbdev->id); return ret; } adap->thread = thread; @@ -501,8 +501,8 @@ static int pt3_stop_streaming(struct pt3_adapter *adap) ret = pt3_stop_dma(adap); if (ret) dev_warn(adap->dvb_adap.device, - "PT3: failed to stop streaming of adap:%d/FE:%d\n", - adap->dvb_adap.num, adap->fe->id); + "PT3: failed to stop streaming of adap:%d/FE:%d\n", + adap->dvb_adap.num, adap->fe->id); /* kill the fetching thread */ ret = kthread_stop(adap->thread); @@ -522,8 +522,8 @@ static int pt3_start_feed(struct dvb_demux_feed *feed) return 0; if (adap->num_feeds != 1) { dev_warn(adap->dvb_adap.device, - "%s: unmatched start/stop_feed in adap:%i/dmx:%i.\n", - __func__, adap->dvb_adap.num, adap->dmxdev.dvbdev->id); + "%s: unmatched start/stop_feed in adap:%i/dmx:%i\n", + __func__, adap->dvb_adap.num, adap->dmxdev.dvbdev->id); adap->num_feeds = 1; } @@ -553,10 +553,9 @@ static int pt3_alloc_adapter(struct pt3_board *pt3, int index) struct dvb_adapter *da; adap = kzalloc(sizeof(*adap), GFP_KERNEL); - if (!adap) { - dev_err(&pt3->pdev->dev, "failed to alloc mem for adapter.\n"); + if (!adap) return -ENOMEM; - } + pt3->adaps[index] = adap; adap->adap_idx = index; @@ -565,7 +564,7 @@ static int pt3_alloc_adapter(struct pt3_board *pt3, int index) THIS_MODULE, &pt3->pdev->dev, adapter_nr); if (ret < 0) { dev_err(&pt3->pdev->dev, - "failed to register adapter dev.\n"); + "failed to register adapter dev\n"); goto err_mem; } da = &adap->dvb_adap; @@ -581,7 +580,7 @@ static int pt3_alloc_adapter(struct pt3_board *pt3, int index) adap->demux.stop_feed = pt3_stop_feed; ret = dvb_dmx_init(&adap->demux); if (ret < 0) { - dev_err(&pt3->pdev->dev, "failed to init dmx dev.\n"); + dev_err(&pt3->pdev->dev, "failed to init dmx dev\n"); goto err_adap; } @@ -589,13 +588,13 @@ static int pt3_alloc_adapter(struct pt3_board *pt3, int index) adap->dmxdev.demux = &adap->demux.dmx; ret = dvb_dmxdev_init(&adap->dmxdev, da); if (ret < 0) { - dev_err(&pt3->pdev->dev, "failed to init dmxdev.\n"); + dev_err(&pt3->pdev->dev, "failed to init dmxdev\n"); goto err_demux; } ret = pt3_alloc_dmabuf(adap); if (ret) { - dev_err(&pt3->pdev->dev, "failed to alloc DMA buffers.\n"); + dev_err(&pt3->pdev->dev, "failed to alloc DMA buffers\n"); goto err_dmabuf; } @@ -695,7 +694,7 @@ static int pt3_resume(struct device *dev) dvb_frontend_resume(adap->fe); ret = pt3_alloc_dmabuf(adap); if (ret) { - dev_err(&pt3->pdev->dev, "failed to alloc DMA bufs.\n"); + dev_err(&pt3->pdev->dev, "failed to alloc DMA bufs\n"); continue; } if (adap->num_feeds > 0) @@ -753,15 +752,14 @@ static int pt3_probe(struct pci_dev *pdev, const struct pci_device_id *ent) if (ret == 0) dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(32)); else { - dev_err(&pdev->dev, "Failed to set DMA mask.\n"); + dev_err(&pdev->dev, "Failed to set DMA mask\n"); goto err_release_regions; } - dev_info(&pdev->dev, "Use 32bit DMA.\n"); + dev_info(&pdev->dev, "Use 32bit DMA\n"); } pt3 = kzalloc(sizeof(*pt3), GFP_KERNEL); if (!pt3) { - dev_err(&pdev->dev, "Failed to alloc mem for this dev.\n"); ret = -ENOMEM; goto err_release_regions; } @@ -771,15 +769,15 @@ static int pt3_probe(struct pci_dev *pdev, const struct pci_device_id *ent) pt3->regs[0] = pci_ioremap_bar(pdev, 0); pt3->regs[1] = pci_ioremap_bar(pdev, 2); if (pt3->regs[0] == NULL || pt3->regs[1] == NULL) { - dev_err(&pdev->dev, "Failed to ioremap.\n"); + dev_err(&pdev->dev, "Failed to ioremap\n"); ret = -ENOMEM; goto err_kfree; } ver = ioread32(pt3->regs[0] + REG_VERSION); if ((ver >> 16) != 0x0301) { - dev_warn(&pdev->dev, "PT%d, I/F-ver.:%d not supported", - ver >> 24, (ver & 0x00ff0000) >> 16); + dev_warn(&pdev->dev, "PT%d, I/F-ver.:%d not supported\n", + ver >> 24, (ver & 0x00ff0000) >> 16); ret = -ENODEV; goto err_iounmap; } @@ -788,7 +786,6 @@ static int pt3_probe(struct pci_dev *pdev, const struct pci_device_id *ent) pt3->i2c_buf = kmalloc(sizeof(*pt3->i2c_buf), GFP_KERNEL); if (pt3->i2c_buf == NULL) { - dev_err(&pdev->dev, "Failed to alloc mem for i2c.\n"); ret = -ENOMEM; goto err_iounmap; } @@ -801,7 +798,7 @@ static int pt3_probe(struct pci_dev *pdev, const struct pci_device_id *ent) i2c_set_adapdata(i2c, pt3); ret = i2c_add_adapter(i2c); if (ret < 0) { - dev_err(&pdev->dev, "Failed to add i2c adapter.\n"); + dev_err(&pdev->dev, "Failed to add i2c adapter\n"); goto err_i2cbuf; } @@ -815,20 +812,20 @@ static int pt3_probe(struct pci_dev *pdev, const struct pci_device_id *ent) break; } if (i < PT3_NUM_FE) { - dev_err(&pdev->dev, "Failed to create FE%d.\n", i); + dev_err(&pdev->dev, "Failed to create FE%d\n", i); goto err_cleanup_adapters; } ret = pt3_fe_init(pt3); if (ret < 0) { - dev_err(&pdev->dev, "Failed to init frontends.\n"); + dev_err(&pdev->dev, "Failed to init frontends\n"); i = PT3_NUM_FE - 1; goto err_cleanup_adapters; } dev_info(&pdev->dev, - "successfully init'ed PT%d (fw:0x%02x, I/F:0x%02x).\n", - ver >> 24, (ver >> 8) & 0xff, (ver >> 16) & 0xff); + "successfully init'ed PT%d (fw:0x%02x, I/F:0x%02x)\n", + ver >> 24, (ver >> 8) & 0xff, (ver >> 16) & 0xff); return 0; err_cleanup_adapters: diff --git a/drivers/media/pci/saa7134/saa7134-core.c b/drivers/media/pci/saa7134/saa7134-core.c index 236ed725f93..a349e964e0b 100644 --- a/drivers/media/pci/saa7134/saa7134-core.c +++ b/drivers/media/pci/saa7134/saa7134-core.c @@ -1001,13 +1001,18 @@ static int saa7134_initdev(struct pci_dev *pci_dev, saa7134_board_init1(dev); saa7134_hwinit1(dev); + dev->alloc_ctx = vb2_dma_sg_init_ctx(&pci_dev->dev); + if (IS_ERR(dev->alloc_ctx)) { + err = PTR_ERR(dev->alloc_ctx); + goto fail3; + } /* get irq */ err = request_irq(pci_dev->irq, saa7134_irq, IRQF_SHARED, dev->name, dev); if (err < 0) { printk(KERN_ERR "%s: can't get IRQ %d\n", dev->name,pci_dev->irq); - goto fail3; + goto fail4; } /* wait a bit, register i2c bus */ @@ -1065,7 +1070,7 @@ static int saa7134_initdev(struct pci_dev *pci_dev, if (err < 0) { printk(KERN_INFO "%s: can't register video device\n", dev->name); - goto fail4; + goto fail5; } printk(KERN_INFO "%s: registered device %s [v4l2]\n", dev->name, video_device_node_name(dev->video_dev)); @@ -1078,7 +1083,7 @@ static int saa7134_initdev(struct pci_dev *pci_dev, err = video_register_device(dev->vbi_dev,VFL_TYPE_VBI, vbi_nr[dev->nr]); if (err < 0) - goto fail4; + goto fail5; printk(KERN_INFO "%s: registered device %s\n", dev->name, video_device_node_name(dev->vbi_dev)); @@ -1089,7 +1094,7 @@ static int saa7134_initdev(struct pci_dev *pci_dev, err = video_register_device(dev->radio_dev,VFL_TYPE_RADIO, radio_nr[dev->nr]); if (err < 0) - goto fail4; + goto fail5; printk(KERN_INFO "%s: registered device %s\n", dev->name, video_device_node_name(dev->radio_dev)); } @@ -1103,10 +1108,12 @@ static int saa7134_initdev(struct pci_dev *pci_dev, request_submodules(dev); return 0; - fail4: + fail5: saa7134_unregister_video(dev); saa7134_i2c_unregister(dev); free_irq(pci_dev->irq, dev); + fail4: + vb2_dma_sg_cleanup_ctx(dev->alloc_ctx); fail3: saa7134_hwfini(dev); iounmap(dev->lmmio); @@ -1173,6 +1180,7 @@ static void saa7134_finidev(struct pci_dev *pci_dev) /* release resources */ free_irq(pci_dev->irq, dev); + vb2_dma_sg_cleanup_ctx(dev->alloc_ctx); iounmap(dev->lmmio); release_mem_region(pci_resource_start(pci_dev,0), pci_resource_len(pci_dev,0)); diff --git a/drivers/media/pci/saa7134/saa7134-empress.c b/drivers/media/pci/saa7134/saa7134-empress.c index e4ea85fd1b2..594dc3ad475 100644 --- a/drivers/media/pci/saa7134/saa7134-empress.c +++ b/drivers/media/pci/saa7134/saa7134-empress.c @@ -96,7 +96,6 @@ static struct vb2_ops saa7134_empress_qops = { .queue_setup = saa7134_ts_queue_setup, .buf_init = saa7134_ts_buffer_init, .buf_prepare = saa7134_ts_buffer_prepare, - .buf_finish = saa7134_ts_buffer_finish, .buf_queue = saa7134_vb2_buffer_queue, .wait_prepare = vb2_ops_wait_prepare, .wait_finish = vb2_ops_wait_finish, @@ -140,7 +139,7 @@ static int empress_s_fmt_vid_cap(struct file *file, void *priv, struct saa7134_dev *dev = video_drvdata(file); struct v4l2_mbus_framefmt mbus_fmt; - v4l2_fill_mbus_format(&mbus_fmt, &f->fmt.pix, V4L2_MBUS_FMT_FIXED); + v4l2_fill_mbus_format(&mbus_fmt, &f->fmt.pix, MEDIA_BUS_FMT_FIXED); saa_call_all(dev, video, s_mbus_fmt, &mbus_fmt); v4l2_fill_pix_format(&f->fmt.pix, &mbus_fmt); @@ -157,7 +156,7 @@ static int empress_try_fmt_vid_cap(struct file *file, void *priv, struct saa7134_dev *dev = video_drvdata(file); struct v4l2_mbus_framefmt mbus_fmt; - v4l2_fill_mbus_format(&mbus_fmt, &f->fmt.pix, V4L2_MBUS_FMT_FIXED); + v4l2_fill_mbus_format(&mbus_fmt, &f->fmt.pix, MEDIA_BUS_FMT_FIXED); saa_call_all(dev, video, try_mbus_fmt, &mbus_fmt); v4l2_fill_pix_format(&f->fmt.pix, &mbus_fmt); diff --git a/drivers/media/pci/saa7134/saa7134-ts.c b/drivers/media/pci/saa7134/saa7134-ts.c index bd25323bd94..2709b83d57b 100644 --- a/drivers/media/pci/saa7134/saa7134-ts.c +++ b/drivers/media/pci/saa7134/saa7134-ts.c @@ -94,7 +94,6 @@ int saa7134_ts_buffer_prepare(struct vb2_buffer *vb2) struct saa7134_buf *buf = container_of(vb2, struct saa7134_buf, vb2); struct sg_table *dma = vb2_dma_sg_plane_desc(vb2, 0); unsigned int lines, llength, size; - int ret; dprintk("buffer_prepare [%p]\n", buf); @@ -108,25 +107,11 @@ int saa7134_ts_buffer_prepare(struct vb2_buffer *vb2) vb2_set_plane_payload(vb2, 0, size); vb2->v4l2_buf.field = dev->field; - ret = dma_map_sg(&dev->pci->dev, dma->sgl, dma->nents, DMA_FROM_DEVICE); - if (!ret) - return -EIO; return saa7134_pgtable_build(dev->pci, &dmaq->pt, dma->sgl, dma->nents, saa7134_buffer_startpage(buf)); } EXPORT_SYMBOL_GPL(saa7134_ts_buffer_prepare); -void saa7134_ts_buffer_finish(struct vb2_buffer *vb2) -{ - struct saa7134_dmaqueue *dmaq = vb2->vb2_queue->drv_priv; - struct saa7134_dev *dev = dmaq->dev; - struct saa7134_buf *buf = container_of(vb2, struct saa7134_buf, vb2); - struct sg_table *dma = vb2_dma_sg_plane_desc(&buf->vb2, 0); - - dma_unmap_sg(&dev->pci->dev, dma->sgl, dma->nents, DMA_FROM_DEVICE); -} -EXPORT_SYMBOL_GPL(saa7134_ts_buffer_finish); - int saa7134_ts_queue_setup(struct vb2_queue *q, const struct v4l2_format *fmt, unsigned int *nbuffers, unsigned int *nplanes, unsigned int sizes[], void *alloc_ctxs[]) @@ -142,6 +127,7 @@ int saa7134_ts_queue_setup(struct vb2_queue *q, const struct v4l2_format *fmt, *nbuffers = 3; *nplanes = 1; sizes[0] = size; + alloc_ctxs[0] = dev->alloc_ctx; return 0; } EXPORT_SYMBOL_GPL(saa7134_ts_queue_setup); @@ -187,7 +173,6 @@ struct vb2_ops saa7134_ts_qops = { .queue_setup = saa7134_ts_queue_setup, .buf_init = saa7134_ts_buffer_init, .buf_prepare = saa7134_ts_buffer_prepare, - .buf_finish = saa7134_ts_buffer_finish, .buf_queue = saa7134_vb2_buffer_queue, .wait_prepare = vb2_ops_wait_prepare, .wait_finish = vb2_ops_wait_finish, diff --git a/drivers/media/pci/saa7134/saa7134-vbi.c b/drivers/media/pci/saa7134/saa7134-vbi.c index 4f0b1012e4f..5306e549e52 100644 --- a/drivers/media/pci/saa7134/saa7134-vbi.c +++ b/drivers/media/pci/saa7134/saa7134-vbi.c @@ -120,7 +120,6 @@ static int buffer_prepare(struct vb2_buffer *vb2) struct saa7134_buf *buf = container_of(vb2, struct saa7134_buf, vb2); struct sg_table *dma = vb2_dma_sg_plane_desc(&buf->vb2, 0); unsigned int size; - int ret; if (dma->sgl->offset) { pr_err("The buffer is not page-aligned\n"); @@ -132,9 +131,6 @@ static int buffer_prepare(struct vb2_buffer *vb2) vb2_set_plane_payload(vb2, 0, size); - ret = dma_map_sg(&dev->pci->dev, dma->sgl, dma->nents, DMA_FROM_DEVICE); - if (!ret) - return -EIO; return saa7134_pgtable_build(dev->pci, &dmaq->pt, dma->sgl, dma->nents, saa7134_buffer_startpage(buf)); } @@ -156,6 +152,7 @@ static int queue_setup(struct vb2_queue *q, const struct v4l2_format *fmt, *nbuffers = saa7134_buffer_count(size, *nbuffers); *nplanes = 1; sizes[0] = size; + alloc_ctxs[0] = dev->alloc_ctx; return 0; } @@ -169,21 +166,10 @@ static int buffer_init(struct vb2_buffer *vb2) return 0; } -static void buffer_finish(struct vb2_buffer *vb2) -{ - struct saa7134_dmaqueue *dmaq = vb2->vb2_queue->drv_priv; - struct saa7134_dev *dev = dmaq->dev; - struct saa7134_buf *buf = container_of(vb2, struct saa7134_buf, vb2); - struct sg_table *dma = vb2_dma_sg_plane_desc(&buf->vb2, 0); - - dma_unmap_sg(&dev->pci->dev, dma->sgl, dma->nents, DMA_FROM_DEVICE); -} - struct vb2_ops saa7134_vbi_qops = { .queue_setup = queue_setup, .buf_init = buffer_init, .buf_prepare = buffer_prepare, - .buf_finish = buffer_finish, .buf_queue = saa7134_vb2_buffer_queue, .wait_prepare = vb2_ops_wait_prepare, .wait_finish = vb2_ops_wait_finish, diff --git a/drivers/media/pci/saa7134/saa7134-video.c b/drivers/media/pci/saa7134/saa7134-video.c index fc4a427cb51..701b52f3468 100644 --- a/drivers/media/pci/saa7134/saa7134-video.c +++ b/drivers/media/pci/saa7134/saa7134-video.c @@ -883,7 +883,6 @@ static int buffer_prepare(struct vb2_buffer *vb2) struct saa7134_buf *buf = container_of(vb2, struct saa7134_buf, vb2); struct sg_table *dma = vb2_dma_sg_plane_desc(&buf->vb2, 0); unsigned int size; - int ret; if (dma->sgl->offset) { pr_err("The buffer is not page-aligned\n"); @@ -896,23 +895,10 @@ static int buffer_prepare(struct vb2_buffer *vb2) vb2_set_plane_payload(vb2, 0, size); vb2->v4l2_buf.field = dev->field; - ret = dma_map_sg(&dev->pci->dev, dma->sgl, dma->nents, DMA_FROM_DEVICE); - if (!ret) - return -EIO; return saa7134_pgtable_build(dev->pci, &dmaq->pt, dma->sgl, dma->nents, saa7134_buffer_startpage(buf)); } -static void buffer_finish(struct vb2_buffer *vb2) -{ - struct saa7134_dmaqueue *dmaq = vb2->vb2_queue->drv_priv; - struct saa7134_dev *dev = dmaq->dev; - struct saa7134_buf *buf = container_of(vb2, struct saa7134_buf, vb2); - struct sg_table *dma = vb2_dma_sg_plane_desc(&buf->vb2, 0); - - dma_unmap_sg(&dev->pci->dev, dma->sgl, dma->nents, DMA_FROM_DEVICE); -} - static int queue_setup(struct vb2_queue *q, const struct v4l2_format *fmt, unsigned int *nbuffers, unsigned int *nplanes, unsigned int sizes[], void *alloc_ctxs[]) @@ -932,6 +918,7 @@ static int queue_setup(struct vb2_queue *q, const struct v4l2_format *fmt, *nbuffers = saa7134_buffer_count(size, *nbuffers); *nplanes = 1; sizes[0] = size; + alloc_ctxs[0] = dev->alloc_ctx; return 0; } @@ -1004,7 +991,6 @@ static struct vb2_ops vb2_qops = { .queue_setup = queue_setup, .buf_init = buffer_init, .buf_prepare = buffer_prepare, - .buf_finish = buffer_finish, .buf_queue = saa7134_vb2_buffer_queue, .wait_prepare = vb2_ops_wait_prepare, .wait_finish = vb2_ops_wait_finish, diff --git a/drivers/media/pci/saa7134/saa7134.h b/drivers/media/pci/saa7134/saa7134.h index 1a82dd07205..8bf0553b8d2 100644 --- a/drivers/media/pci/saa7134/saa7134.h +++ b/drivers/media/pci/saa7134/saa7134.h @@ -588,6 +588,7 @@ struct saa7134_dev { /* video+ts+vbi capture */ + void *alloc_ctx; struct saa7134_dmaqueue video_q; struct vb2_queue video_vbq; struct saa7134_dmaqueue vbi_q; @@ -814,7 +815,6 @@ void saa7134_video_fini(struct saa7134_dev *dev); int saa7134_ts_buffer_init(struct vb2_buffer *vb2); int saa7134_ts_buffer_prepare(struct vb2_buffer *vb2); -void saa7134_ts_buffer_finish(struct vb2_buffer *vb2); int saa7134_ts_queue_setup(struct vb2_queue *q, const struct v4l2_format *fmt, unsigned int *nbuffers, unsigned int *nplanes, unsigned int sizes[], void *alloc_ctxs[]); diff --git a/drivers/media/pci/saa7164/saa7164-buffer.c b/drivers/media/pci/saa7164/saa7164-buffer.c index 66696fa8341..9bd1f73f82d 100644 --- a/drivers/media/pci/saa7164/saa7164-buffer.c +++ b/drivers/media/pci/saa7164/saa7164-buffer.c @@ -130,9 +130,9 @@ struct saa7164_buffer *saa7164_buffer_alloc(struct saa7164_port *port, goto fail2; /* init the buffers to a known pattern, easier during debugging */ - memset_io(buf->cpu, 0xff, buf->pci_size); + memset(buf->cpu, 0xff, buf->pci_size); buf->crc = crc32(0, buf->cpu, buf->actual_size); - memset_io(buf->pt_cpu, 0xff, buf->pt_size); + memset(buf->pt_cpu, 0xff, buf->pt_size); dprintk(DBGLVL_BUF, "%s() allocated buffer @ 0x%p (%d pageptrs)\n", __func__, buf, params->numpagetables); diff --git a/drivers/media/pci/saa7164/saa7164-bus.c b/drivers/media/pci/saa7164/saa7164-bus.c index 5f6f3094c44..6c73f5b155f 100644 --- a/drivers/media/pci/saa7164/saa7164-bus.c +++ b/drivers/media/pci/saa7164/saa7164-bus.c @@ -33,12 +33,12 @@ int saa7164_bus_setup(struct saa7164_dev *dev) b->Type = TYPE_BUS_PCIe; b->m_wMaxReqSize = SAA_DEVICE_MAXREQUESTSIZE; - b->m_pdwSetRing = (u8 *)(dev->bmmio + + b->m_pdwSetRing = (u8 __iomem *)(dev->bmmio + ((u32)dev->busdesc.CommandRing)); b->m_dwSizeSetRing = SAA_DEVICE_BUFFERBLOCKSIZE; - b->m_pdwGetRing = (u8 *)(dev->bmmio + + b->m_pdwGetRing = (u8 __iomem *)(dev->bmmio + ((u32)dev->busdesc.ResponseRing)); b->m_dwSizeGetRing = SAA_DEVICE_BUFFERBLOCKSIZE; @@ -138,6 +138,7 @@ int saa7164_bus_set(struct saa7164_dev *dev, struct tmComResInfo* msg, u32 bytes_to_write, free_write_space, timeout, curr_srp, curr_swp; u32 new_swp, space_rem; int ret = SAA_ERR_BAD_PARAMETER; + u16 size; if (!msg) { printk(KERN_ERR "%s() !msg\n", __func__); @@ -148,10 +149,6 @@ int saa7164_bus_set(struct saa7164_dev *dev, struct tmComResInfo* msg, saa7164_bus_verify(dev); - msg->size = cpu_to_le16(msg->size); - msg->command = cpu_to_le32(msg->command); - msg->controlselector = cpu_to_le16(msg->controlselector); - if (msg->size > dev->bus.m_wMaxReqSize) { printk(KERN_ERR "%s() Exceeded dev->bus.m_wMaxReqSize\n", __func__); @@ -169,8 +166,8 @@ int saa7164_bus_set(struct saa7164_dev *dev, struct tmComResInfo* msg, bytes_to_write = sizeof(*msg) + msg->size; free_write_space = 0; timeout = SAA_BUS_TIMEOUT; - curr_srp = le32_to_cpu(saa7164_readl(bus->m_dwSetReadPos)); - curr_swp = le32_to_cpu(saa7164_readl(bus->m_dwSetWritePos)); + curr_srp = saa7164_readl(bus->m_dwSetReadPos); + curr_swp = saa7164_readl(bus->m_dwSetWritePos); /* Deal with ring wrapping issues */ if (curr_srp > curr_swp) @@ -203,7 +200,7 @@ int saa7164_bus_set(struct saa7164_dev *dev, struct tmComResInfo* msg, mdelay(1); /* Check the space usage again */ - curr_srp = le32_to_cpu(saa7164_readl(bus->m_dwSetReadPos)); + curr_srp = saa7164_readl(bus->m_dwSetReadPos); /* Deal with ring wrapping issues */ if (curr_srp > curr_swp) @@ -223,6 +220,16 @@ int saa7164_bus_set(struct saa7164_dev *dev, struct tmComResInfo* msg, dprintk(DBGLVL_BUS, "%s() bus->m_dwSizeSetRing = %x\n", __func__, bus->m_dwSizeSetRing); + /* + * Make a copy of msg->size before it is converted to le16 since it is + * used in the code below. + */ + size = msg->size; + /* Convert to le16/le32 */ + msg->size = (__force u16)cpu_to_le16(msg->size); + msg->command = (__force u32)cpu_to_le32(msg->command); + msg->controlselector = (__force u16)cpu_to_le16(msg->controlselector); + /* Mental Note: line 462 tmmhComResBusPCIe.cpp */ /* Check if we're going to wrap again */ @@ -243,28 +250,28 @@ int saa7164_bus_set(struct saa7164_dev *dev, struct tmComResInfo* msg, dprintk(DBGLVL_BUS, "%s() tr4\n", __func__); /* Split the msg into pieces as the ring wraps */ - memcpy(bus->m_pdwSetRing + curr_swp, msg, space_rem); - memcpy(bus->m_pdwSetRing, (u8 *)msg + space_rem, + memcpy_toio(bus->m_pdwSetRing + curr_swp, msg, space_rem); + memcpy_toio(bus->m_pdwSetRing, (u8 *)msg + space_rem, sizeof(*msg) - space_rem); - memcpy(bus->m_pdwSetRing + sizeof(*msg) - space_rem, - buf, msg->size); + memcpy_toio(bus->m_pdwSetRing + sizeof(*msg) - space_rem, + buf, size); } else if (space_rem == sizeof(*msg)) { dprintk(DBGLVL_BUS, "%s() tr5\n", __func__); /* Additional data at the beginning of the ring */ - memcpy(bus->m_pdwSetRing + curr_swp, msg, sizeof(*msg)); - memcpy(bus->m_pdwSetRing, buf, msg->size); + memcpy_toio(bus->m_pdwSetRing + curr_swp, msg, sizeof(*msg)); + memcpy_toio(bus->m_pdwSetRing, buf, size); } else { /* Additional data wraps around the ring */ - memcpy(bus->m_pdwSetRing + curr_swp, msg, sizeof(*msg)); - if (msg->size > 0) { - memcpy(bus->m_pdwSetRing + curr_swp + + memcpy_toio(bus->m_pdwSetRing + curr_swp, msg, sizeof(*msg)); + if (size > 0) { + memcpy_toio(bus->m_pdwSetRing + curr_swp + sizeof(*msg), buf, space_rem - sizeof(*msg)); - memcpy(bus->m_pdwSetRing, (u8 *)buf + + memcpy_toio(bus->m_pdwSetRing, (u8 *)buf + space_rem - sizeof(*msg), bytes_to_write - space_rem); } @@ -276,15 +283,20 @@ int saa7164_bus_set(struct saa7164_dev *dev, struct tmComResInfo* msg, dprintk(DBGLVL_BUS, "%s() tr6\n", __func__); /* The ring buffer doesn't wrap, two simple copies */ - memcpy(bus->m_pdwSetRing + curr_swp, msg, sizeof(*msg)); - memcpy(bus->m_pdwSetRing + curr_swp + sizeof(*msg), buf, - msg->size); + memcpy_toio(bus->m_pdwSetRing + curr_swp, msg, sizeof(*msg)); + memcpy_toio(bus->m_pdwSetRing + curr_swp + sizeof(*msg), buf, + size); } dprintk(DBGLVL_BUS, "%s() new_swp = %x\n", __func__, new_swp); /* Update the bus write position */ - saa7164_writel(bus->m_dwSetWritePos, cpu_to_le32(new_swp)); + saa7164_writel(bus->m_dwSetWritePos, new_swp); + + /* Convert back to cpu after writing the msg to the ringbuffer. */ + msg->size = le16_to_cpu((__force __le16)msg->size); + msg->command = le32_to_cpu((__force __le32)msg->command); + msg->controlselector = le16_to_cpu((__force __le16)msg->controlselector); ret = SAA_OK; out: @@ -336,8 +348,8 @@ int saa7164_bus_get(struct saa7164_dev *dev, struct tmComResInfo* msg, /* Peek the bus to see if a msg exists, if it's not what we're expecting * then return cleanly else read the message from the bus. */ - curr_gwp = le32_to_cpu(saa7164_readl(bus->m_dwGetWritePos)); - curr_grp = le32_to_cpu(saa7164_readl(bus->m_dwGetReadPos)); + curr_gwp = saa7164_readl(bus->m_dwGetWritePos); + curr_grp = saa7164_readl(bus->m_dwGetReadPos); if (curr_gwp == curr_grp) { ret = SAA_ERR_EMPTY; @@ -369,14 +381,18 @@ int saa7164_bus_get(struct saa7164_dev *dev, struct tmComResInfo* msg, new_grp -= bus->m_dwSizeGetRing; space_rem = bus->m_dwSizeGetRing - curr_grp; - memcpy(&msg_tmp, bus->m_pdwGetRing + curr_grp, space_rem); - memcpy((u8 *)&msg_tmp + space_rem, bus->m_pdwGetRing, + memcpy_fromio(&msg_tmp, bus->m_pdwGetRing + curr_grp, space_rem); + memcpy_fromio((u8 *)&msg_tmp + space_rem, bus->m_pdwGetRing, bytes_to_read - space_rem); } else { /* No wrapping */ - memcpy(&msg_tmp, bus->m_pdwGetRing + curr_grp, bytes_to_read); + memcpy_fromio(&msg_tmp, bus->m_pdwGetRing + curr_grp, bytes_to_read); } + /* Convert from little endian to CPU */ + msg_tmp.size = le16_to_cpu((__force __le16)msg_tmp.size); + msg_tmp.command = le32_to_cpu((__force __le32)msg_tmp.command); + msg_tmp.controlselector = le16_to_cpu((__force __le16)msg_tmp.controlselector); /* No need to update the read positions, because this was a peek */ /* If the caller specifically want to peek, return */ @@ -427,24 +443,24 @@ int saa7164_bus_get(struct saa7164_dev *dev, struct tmComResInfo* msg, if (space_rem < sizeof(*msg)) { /* msg wraps around the ring */ - memcpy(msg, bus->m_pdwGetRing + curr_grp, space_rem); - memcpy((u8 *)msg + space_rem, bus->m_pdwGetRing, + memcpy_fromio(msg, bus->m_pdwGetRing + curr_grp, space_rem); + memcpy_fromio((u8 *)msg + space_rem, bus->m_pdwGetRing, sizeof(*msg) - space_rem); if (buf) - memcpy(buf, bus->m_pdwGetRing + sizeof(*msg) - + memcpy_fromio(buf, bus->m_pdwGetRing + sizeof(*msg) - space_rem, buf_size); } else if (space_rem == sizeof(*msg)) { - memcpy(msg, bus->m_pdwGetRing + curr_grp, sizeof(*msg)); + memcpy_fromio(msg, bus->m_pdwGetRing + curr_grp, sizeof(*msg)); if (buf) - memcpy(buf, bus->m_pdwGetRing, buf_size); + memcpy_fromio(buf, bus->m_pdwGetRing, buf_size); } else { /* Additional data wraps around the ring */ - memcpy(msg, bus->m_pdwGetRing + curr_grp, sizeof(*msg)); + memcpy_fromio(msg, bus->m_pdwGetRing + curr_grp, sizeof(*msg)); if (buf) { - memcpy(buf, bus->m_pdwGetRing + curr_grp + + memcpy_fromio(buf, bus->m_pdwGetRing + curr_grp + sizeof(*msg), space_rem - sizeof(*msg)); - memcpy(buf + space_rem - sizeof(*msg), + memcpy_fromio(buf + space_rem - sizeof(*msg), bus->m_pdwGetRing, bytes_to_read - space_rem); } @@ -453,19 +469,20 @@ int saa7164_bus_get(struct saa7164_dev *dev, struct tmComResInfo* msg, } else { /* No wrapping */ - memcpy(msg, bus->m_pdwGetRing + curr_grp, sizeof(*msg)); + memcpy_fromio(msg, bus->m_pdwGetRing + curr_grp, sizeof(*msg)); if (buf) - memcpy(buf, bus->m_pdwGetRing + curr_grp + sizeof(*msg), + memcpy_fromio(buf, bus->m_pdwGetRing + curr_grp + sizeof(*msg), buf_size); } + /* Convert from little endian to CPU */ + msg->size = le16_to_cpu((__force __le16)msg->size); + msg->command = le32_to_cpu((__force __le32)msg->command); + msg->controlselector = le16_to_cpu((__force __le16)msg->controlselector); /* Update the read positions, adjusting the ring */ - saa7164_writel(bus->m_dwGetReadPos, cpu_to_le32(new_grp)); + saa7164_writel(bus->m_dwGetReadPos, new_grp); peekout: - msg->size = le16_to_cpu(msg->size); - msg->command = le32_to_cpu(msg->command); - msg->controlselector = le16_to_cpu(msg->controlselector); ret = SAA_OK; out: mutex_unlock(&bus->lock); diff --git a/drivers/media/pci/saa7164/saa7164-core.c b/drivers/media/pci/saa7164/saa7164-core.c index cc1be8a7a45..4b0bec3766e 100644 --- a/drivers/media/pci/saa7164/saa7164-core.c +++ b/drivers/media/pci/saa7164/saa7164-core.c @@ -119,7 +119,7 @@ static void saa7164_ts_verifier(struct saa7164_buffer *buf) u32 i; u8 cc, a; u16 pid; - u8 __iomem *bufcpu = (u8 *)buf->cpu; + u8 *bufcpu = (u8 *)buf->cpu; port->sync_errors = 0; port->v_cc_errors = 0; @@ -260,7 +260,7 @@ static void saa7164_work_enchandler_helper(struct saa7164_port *port, int bufnr) struct saa7164_user_buffer *ubuf = NULL; struct list_head *c, *n; int i = 0; - u8 __iomem *p; + u8 *p; mutex_lock(&port->dmaqueue_lock); list_for_each_safe(c, n, &port->dmaqueue.list) { @@ -318,8 +318,7 @@ static void saa7164_work_enchandler_helper(struct saa7164_port *port, int bufnr) if (buf->actual_size <= ubuf->actual_size) { - memcpy_fromio(ubuf->data, buf->cpu, - ubuf->actual_size); + memcpy(ubuf->data, buf->cpu, ubuf->actual_size); if (crc_checking) { /* Throw a new checksum on the read buffer */ @@ -346,7 +345,7 @@ static void saa7164_work_enchandler_helper(struct saa7164_port *port, int bufnr) * with known bad data. We check for this data at a later point * in time. */ saa7164_buffer_zero_offsets(port, bufnr); - memset_io(buf->cpu, 0xff, buf->pci_size); + memset(buf->cpu, 0xff, buf->pci_size); if (crc_checking) { /* Throw yet aanother new checksum on the dma buffer */ buf->crc = crc32(0, buf->cpu, buf->actual_size); @@ -1096,7 +1095,7 @@ static int saa7164_proc_show(struct seq_file *m, void *v) if (c == 0) seq_printf(m, " %04x:", i); - seq_printf(m, " %02x", *(b->m_pdwSetRing + i)); + seq_printf(m, " %02x", readb(b->m_pdwSetRing + i)); if (++c == 16) { seq_printf(m, "\n"); @@ -1111,7 +1110,7 @@ static int saa7164_proc_show(struct seq_file *m, void *v) if (c == 0) seq_printf(m, " %04x:", i); - seq_printf(m, " %02x", *(b->m_pdwGetRing + i)); + seq_printf(m, " %02x", readb(b->m_pdwGetRing + i)); if (++c == 16) { seq_printf(m, "\n"); diff --git a/drivers/media/pci/saa7164/saa7164-fw.c b/drivers/media/pci/saa7164/saa7164-fw.c index 86763203d61..add06ab5124 100644 --- a/drivers/media/pci/saa7164/saa7164-fw.c +++ b/drivers/media/pci/saa7164/saa7164-fw.c @@ -72,7 +72,7 @@ static int saa7164_dl_wait_clr(struct saa7164_dev *dev, u32 reg) /* TODO: move dlflags into dev-> and change to write/readl/b */ /* TODO: Excessive levels of debug */ static int saa7164_downloadimage(struct saa7164_dev *dev, u8 *src, u32 srcsize, - u32 dlflags, u8 *dst, u32 dstsize) + u32 dlflags, u8 __iomem *dst, u32 dstsize) { u32 reg, timeout, offset; u8 *srcbuf = NULL; @@ -136,7 +136,7 @@ static int saa7164_downloadimage(struct saa7164_dev *dev, u8 *src, u32 srcsize, srcsize -= dstsize, offset += dstsize) { dprintk(DBGLVL_FW, "%s() memcpy %d\n", __func__, dstsize); - memcpy(dst, srcbuf + offset, dstsize); + memcpy_toio(dst, srcbuf + offset, dstsize); /* Flag the data as ready */ saa7164_writel(drflag, 1); @@ -154,7 +154,7 @@ static int saa7164_downloadimage(struct saa7164_dev *dev, u8 *src, u32 srcsize, dprintk(DBGLVL_FW, "%s() memcpy(l) %d\n", __func__, dstsize); /* Write last block to the device */ - memcpy(dst, srcbuf+offset, srcsize); + memcpy_toio(dst, srcbuf+offset, srcsize); /* Flag the data as ready */ saa7164_writel(drflag, 1); diff --git a/drivers/media/pci/saa7164/saa7164-types.h b/drivers/media/pci/saa7164/saa7164-types.h index 1d2140a3eb3..f48ba978f83 100644 --- a/drivers/media/pci/saa7164/saa7164-types.h +++ b/drivers/media/pci/saa7164/saa7164-types.h @@ -78,9 +78,9 @@ enum tmBusType { struct tmComResBusInfo { enum tmBusType Type; u16 m_wMaxReqSize; - u8 *m_pdwSetRing; + u8 __iomem *m_pdwSetRing; u32 m_dwSizeSetRing; - u8 *m_pdwGetRing; + u8 __iomem *m_pdwGetRing; u32 m_dwSizeGetRing; u32 m_dwSetWritePos; u32 m_dwSetReadPos; diff --git a/drivers/media/pci/saa7164/saa7164.h b/drivers/media/pci/saa7164/saa7164.h index 8b29e899030..cd1a07ce27c 100644 --- a/drivers/media/pci/saa7164/saa7164.h +++ b/drivers/media/pci/saa7164/saa7164.h @@ -313,13 +313,13 @@ struct saa7164_buffer { /* A block of page align PCI memory */ u32 pci_size; /* PCI allocation size in bytes */ - u64 __iomem *cpu; /* Virtual address */ + u64 *cpu; /* Virtual address */ dma_addr_t dma; /* Physical address */ u32 crc; /* Checksum for the entire buffer data */ /* A page table that splits the block into a number of entries */ u32 pt_size; /* PCI allocation size in bytes */ - u64 __iomem *pt_cpu; /* Virtual address */ + u64 *pt_cpu; /* Virtual address */ dma_addr_t pt_dma; /* Physical address */ /* Encoder fops */ diff --git a/drivers/media/pci/smipcie/Kconfig b/drivers/media/pci/smipcie/Kconfig new file mode 100644 index 00000000000..c8de53f5ea2 --- /dev/null +++ b/drivers/media/pci/smipcie/Kconfig @@ -0,0 +1,17 @@ +config DVB_SMIPCIE + tristate "SMI PCIe DVBSky cards" + depends on DVB_CORE && PCI && I2C + select I2C_ALGOBIT + select DVB_M88DS3103 if MEDIA_SUBDRV_AUTOSELECT + select DVB_SI2168 if MEDIA_SUBDRV_AUTOSELECT + select MEDIA_TUNER_M88TS2022 if MEDIA_SUBDRV_AUTOSELECT + select MEDIA_TUNER_M88RS6000T if MEDIA_SUBDRV_AUTOSELECT + select MEDIA_TUNER_SI2157 if MEDIA_SUBDRV_AUTOSELECT + help + Support for cards with SMI PCIe bridge: + - DVBSky S950 V3 + - DVBSky S952 V3 + - DVBSky T9580 V3 + + Say Y or M if you own such a device and want to use it. + If unsure say N. diff --git a/drivers/media/pci/smipcie/Makefile b/drivers/media/pci/smipcie/Makefile new file mode 100644 index 00000000000..be55481a6e9 --- /dev/null +++ b/drivers/media/pci/smipcie/Makefile @@ -0,0 +1,6 @@ +obj-$(CONFIG_DVB_SMIPCIE) += smipcie.o + +ccflags-y += -Idrivers/media/tuners +ccflags-y += -Idrivers/media/dvb-core +ccflags-y += -Idrivers/media/dvb-frontends + diff --git a/drivers/media/pci/smipcie/smipcie.c b/drivers/media/pci/smipcie/smipcie.c new file mode 100644 index 00000000000..f773350e67b --- /dev/null +++ b/drivers/media/pci/smipcie/smipcie.c @@ -0,0 +1,1099 @@ +/* + * SMI PCIe driver for DVBSky cards. + * + * Copyright (C) 2014 Max nibble <nibble.max@gmail.com> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#include "smipcie.h" +#include "m88ds3103.h" +#include "m88ts2022.h" +#include "m88rs6000t.h" +#include "si2168.h" +#include "si2157.h" + +DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr); + +static int smi_hw_init(struct smi_dev *dev) +{ + u32 port_mux, port_ctrl, int_stat; + + /* set port mux.*/ + port_mux = smi_read(MUX_MODE_CTRL); + port_mux &= ~(rbPaMSMask); + port_mux |= rbPaMSDtvNoGpio; + port_mux &= ~(rbPbMSMask); + port_mux |= rbPbMSDtvNoGpio; + port_mux &= ~(0x0f0000); + port_mux |= 0x50000; + smi_write(MUX_MODE_CTRL, port_mux); + + /* set DTV register.*/ + /* Port A */ + port_ctrl = smi_read(VIDEO_CTRL_STATUS_A); + port_ctrl &= ~0x01; + smi_write(VIDEO_CTRL_STATUS_A, port_ctrl); + port_ctrl = smi_read(MPEG2_CTRL_A); + port_ctrl &= ~0x40; + port_ctrl |= 0x80; + smi_write(MPEG2_CTRL_A, port_ctrl); + /* Port B */ + port_ctrl = smi_read(VIDEO_CTRL_STATUS_B); + port_ctrl &= ~0x01; + smi_write(VIDEO_CTRL_STATUS_B, port_ctrl); + port_ctrl = smi_read(MPEG2_CTRL_B); + port_ctrl &= ~0x40; + port_ctrl |= 0x80; + smi_write(MPEG2_CTRL_B, port_ctrl); + + /* disable and clear interrupt.*/ + smi_write(MSI_INT_ENA_CLR, ALL_INT); + int_stat = smi_read(MSI_INT_STATUS); + smi_write(MSI_INT_STATUS_CLR, int_stat); + + /* reset demod.*/ + smi_clear(PERIPHERAL_CTRL, 0x0303); + msleep(50); + smi_set(PERIPHERAL_CTRL, 0x0101); + return 0; +} + +/* i2c bit bus.*/ +static void smi_i2c_cfg(struct smi_dev *dev, u32 sw_ctl) +{ + u32 dwCtrl; + + dwCtrl = smi_read(sw_ctl); + dwCtrl &= ~0x18; /* disable output.*/ + dwCtrl |= 0x21; /* reset and software mode.*/ + dwCtrl &= ~0xff00; + dwCtrl |= 0x6400; + smi_write(sw_ctl, dwCtrl); + msleep(20); + dwCtrl = smi_read(sw_ctl); + dwCtrl &= ~0x20; + smi_write(sw_ctl, dwCtrl); +} + +static void smi_i2c_setsda(struct smi_dev *dev, int state, u32 sw_ctl) +{ + if (state) { + /* set as input.*/ + smi_clear(sw_ctl, SW_I2C_MSK_DAT_EN); + } else { + smi_clear(sw_ctl, SW_I2C_MSK_DAT_OUT); + /* set as output.*/ + smi_set(sw_ctl, SW_I2C_MSK_DAT_EN); + } +} + +static void smi_i2c_setscl(void *data, int state, u32 sw_ctl) +{ + struct smi_dev *dev = data; + + if (state) { + /* set as input.*/ + smi_clear(sw_ctl, SW_I2C_MSK_CLK_EN); + } else { + smi_clear(sw_ctl, SW_I2C_MSK_CLK_OUT); + /* set as output.*/ + smi_set(sw_ctl, SW_I2C_MSK_CLK_EN); + } +} + +static int smi_i2c_getsda(void *data, u32 sw_ctl) +{ + struct smi_dev *dev = data; + /* set as input.*/ + smi_clear(sw_ctl, SW_I2C_MSK_DAT_EN); + udelay(1); + return (smi_read(sw_ctl) & SW_I2C_MSK_DAT_IN) ? 1 : 0; +} + +static int smi_i2c_getscl(void *data, u32 sw_ctl) +{ + struct smi_dev *dev = data; + /* set as input.*/ + smi_clear(sw_ctl, SW_I2C_MSK_CLK_EN); + udelay(1); + return (smi_read(sw_ctl) & SW_I2C_MSK_CLK_IN) ? 1 : 0; +} +/* i2c 0.*/ +static void smi_i2c0_setsda(void *data, int state) +{ + struct smi_dev *dev = data; + + smi_i2c_setsda(dev, state, I2C_A_SW_CTL); +} + +static void smi_i2c0_setscl(void *data, int state) +{ + struct smi_dev *dev = data; + + smi_i2c_setscl(dev, state, I2C_A_SW_CTL); +} + +static int smi_i2c0_getsda(void *data) +{ + struct smi_dev *dev = data; + + return smi_i2c_getsda(dev, I2C_A_SW_CTL); +} + +static int smi_i2c0_getscl(void *data) +{ + struct smi_dev *dev = data; + + return smi_i2c_getscl(dev, I2C_A_SW_CTL); +} +/* i2c 1.*/ +static void smi_i2c1_setsda(void *data, int state) +{ + struct smi_dev *dev = data; + + smi_i2c_setsda(dev, state, I2C_B_SW_CTL); +} + +static void smi_i2c1_setscl(void *data, int state) +{ + struct smi_dev *dev = data; + + smi_i2c_setscl(dev, state, I2C_B_SW_CTL); +} + +static int smi_i2c1_getsda(void *data) +{ + struct smi_dev *dev = data; + + return smi_i2c_getsda(dev, I2C_B_SW_CTL); +} + +static int smi_i2c1_getscl(void *data) +{ + struct smi_dev *dev = data; + + return smi_i2c_getscl(dev, I2C_B_SW_CTL); +} + +static int smi_i2c_init(struct smi_dev *dev) +{ + int ret; + + /* i2c bus 0 */ + smi_i2c_cfg(dev, I2C_A_SW_CTL); + i2c_set_adapdata(&dev->i2c_bus[0], dev); + strcpy(dev->i2c_bus[0].name, "SMI-I2C0"); + dev->i2c_bus[0].owner = THIS_MODULE; + dev->i2c_bus[0].dev.parent = &dev->pci_dev->dev; + dev->i2c_bus[0].algo_data = &dev->i2c_bit[0]; + dev->i2c_bit[0].data = dev; + dev->i2c_bit[0].setsda = smi_i2c0_setsda; + dev->i2c_bit[0].setscl = smi_i2c0_setscl; + dev->i2c_bit[0].getsda = smi_i2c0_getsda; + dev->i2c_bit[0].getscl = smi_i2c0_getscl; + dev->i2c_bit[0].udelay = 12; + dev->i2c_bit[0].timeout = 10; + /* Raise SCL and SDA */ + smi_i2c0_setsda(dev, 1); + smi_i2c0_setscl(dev, 1); + + ret = i2c_bit_add_bus(&dev->i2c_bus[0]); + if (ret < 0) + return ret; + + /* i2c bus 1 */ + smi_i2c_cfg(dev, I2C_B_SW_CTL); + i2c_set_adapdata(&dev->i2c_bus[1], dev); + strcpy(dev->i2c_bus[1].name, "SMI-I2C1"); + dev->i2c_bus[1].owner = THIS_MODULE; + dev->i2c_bus[1].dev.parent = &dev->pci_dev->dev; + dev->i2c_bus[1].algo_data = &dev->i2c_bit[1]; + dev->i2c_bit[1].data = dev; + dev->i2c_bit[1].setsda = smi_i2c1_setsda; + dev->i2c_bit[1].setscl = smi_i2c1_setscl; + dev->i2c_bit[1].getsda = smi_i2c1_getsda; + dev->i2c_bit[1].getscl = smi_i2c1_getscl; + dev->i2c_bit[1].udelay = 12; + dev->i2c_bit[1].timeout = 10; + /* Raise SCL and SDA */ + smi_i2c1_setsda(dev, 1); + smi_i2c1_setscl(dev, 1); + + ret = i2c_bit_add_bus(&dev->i2c_bus[1]); + if (ret < 0) + i2c_del_adapter(&dev->i2c_bus[0]); + + return ret; +} + +static void smi_i2c_exit(struct smi_dev *dev) +{ + i2c_del_adapter(&dev->i2c_bus[0]); + i2c_del_adapter(&dev->i2c_bus[1]); +} + +static int smi_read_eeprom(struct i2c_adapter *i2c, u16 reg, u8 *data, u16 size) +{ + int ret; + u8 b0[2] = { (reg >> 8) & 0xff, reg & 0xff }; + + struct i2c_msg msg[] = { + { .addr = 0x50, .flags = 0, + .buf = b0, .len = 2 }, + { .addr = 0x50, .flags = I2C_M_RD, + .buf = data, .len = size } + }; + + ret = i2c_transfer(i2c, msg, 2); + + if (ret != 2) { + dev_err(&i2c->dev, "%s: reg=0x%x (error=%d)\n", + __func__, reg, ret); + return ret; + } + return ret; +} + +/* ts port interrupt operations */ +static void smi_port_disableInterrupt(struct smi_port *port) +{ + struct smi_dev *dev = port->dev; + + smi_write(MSI_INT_ENA_CLR, + (port->_dmaInterruptCH0 | port->_dmaInterruptCH1)); +} + +static void smi_port_enableInterrupt(struct smi_port *port) +{ + struct smi_dev *dev = port->dev; + + smi_write(MSI_INT_ENA_SET, + (port->_dmaInterruptCH0 | port->_dmaInterruptCH1)); +} + +static void smi_port_clearInterrupt(struct smi_port *port) +{ + struct smi_dev *dev = port->dev; + + smi_write(MSI_INT_STATUS_CLR, + (port->_dmaInterruptCH0 | port->_dmaInterruptCH1)); +} + +/* tasklet handler: DMA data to dmx.*/ +static void smi_dma_xfer(unsigned long data) +{ + struct smi_port *port = (struct smi_port *) data; + struct smi_dev *dev = port->dev; + u32 intr_status, finishedData, dmaManagement; + u8 dmaChan0State, dmaChan1State; + + intr_status = port->_int_status; + dmaManagement = smi_read(port->DMA_MANAGEMENT); + dmaChan0State = (u8)((dmaManagement & 0x00000030) >> 4); + dmaChan1State = (u8)((dmaManagement & 0x00300000) >> 20); + + /* CH-0 DMA interrupt.*/ + if ((intr_status & port->_dmaInterruptCH0) && (dmaChan0State == 0x01)) { + dev_dbg(&dev->pci_dev->dev, + "Port[%d]-DMA CH0 engine complete successful !\n", + port->idx); + finishedData = smi_read(port->DMA_CHAN0_TRANS_STATE); + finishedData &= 0x003FFFFF; + /* value of DMA_PORT0_CHAN0_TRANS_STATE register [21:0] + * indicate dma total transfer length and + * zero of [21:0] indicate dma total transfer length + * equal to 0x400000 (4MB)*/ + if (finishedData == 0) + finishedData = 0x00400000; + if (finishedData != SMI_TS_DMA_BUF_SIZE) { + dev_dbg(&dev->pci_dev->dev, + "DMA CH0 engine complete length mismatched, finish data=%d !\n", + finishedData); + } + dvb_dmx_swfilter_packets(&port->demux, + port->cpu_addr[0], (finishedData / 188)); + /*dvb_dmx_swfilter(&port->demux, + port->cpu_addr[0], finishedData);*/ + } + /* CH-1 DMA interrupt.*/ + if ((intr_status & port->_dmaInterruptCH1) && (dmaChan1State == 0x01)) { + dev_dbg(&dev->pci_dev->dev, + "Port[%d]-DMA CH1 engine complete successful !\n", + port->idx); + finishedData = smi_read(port->DMA_CHAN1_TRANS_STATE); + finishedData &= 0x003FFFFF; + /* value of DMA_PORT0_CHAN0_TRANS_STATE register [21:0] + * indicate dma total transfer length and + * zero of [21:0] indicate dma total transfer length + * equal to 0x400000 (4MB)*/ + if (finishedData == 0) + finishedData = 0x00400000; + if (finishedData != SMI_TS_DMA_BUF_SIZE) { + dev_dbg(&dev->pci_dev->dev, + "DMA CH1 engine complete length mismatched, finish data=%d !\n", + finishedData); + } + dvb_dmx_swfilter_packets(&port->demux, + port->cpu_addr[1], (finishedData / 188)); + /*dvb_dmx_swfilter(&port->demux, + port->cpu_addr[1], finishedData);*/ + } + /* restart DMA.*/ + if (intr_status & port->_dmaInterruptCH0) + dmaManagement |= 0x00000002; + if (intr_status & port->_dmaInterruptCH1) + dmaManagement |= 0x00020000; + smi_write(port->DMA_MANAGEMENT, dmaManagement); + /* Re-enable interrupts */ + smi_port_enableInterrupt(port); +} + +static void smi_port_dma_free(struct smi_port *port) +{ + if (port->cpu_addr[0]) { + pci_free_consistent(port->dev->pci_dev, SMI_TS_DMA_BUF_SIZE, + port->cpu_addr[0], port->dma_addr[0]); + port->cpu_addr[0] = NULL; + } + if (port->cpu_addr[1]) { + pci_free_consistent(port->dev->pci_dev, SMI_TS_DMA_BUF_SIZE, + port->cpu_addr[1], port->dma_addr[1]); + port->cpu_addr[1] = NULL; + } +} + +static int smi_port_init(struct smi_port *port, int dmaChanUsed) +{ + dev_dbg(&port->dev->pci_dev->dev, + "%s, port %d, dmaused %d\n", __func__, port->idx, dmaChanUsed); + port->enable = 0; + if (port->idx == 0) { + /* Port A */ + port->_dmaInterruptCH0 = dmaChanUsed & 0x01; + port->_dmaInterruptCH1 = dmaChanUsed & 0x02; + + port->DMA_CHAN0_ADDR_LOW = DMA_PORTA_CHAN0_ADDR_LOW; + port->DMA_CHAN0_ADDR_HI = DMA_PORTA_CHAN0_ADDR_HI; + port->DMA_CHAN0_TRANS_STATE = DMA_PORTA_CHAN0_TRANS_STATE; + port->DMA_CHAN0_CONTROL = DMA_PORTA_CHAN0_CONTROL; + port->DMA_CHAN1_ADDR_LOW = DMA_PORTA_CHAN1_ADDR_LOW; + port->DMA_CHAN1_ADDR_HI = DMA_PORTA_CHAN1_ADDR_HI; + port->DMA_CHAN1_TRANS_STATE = DMA_PORTA_CHAN1_TRANS_STATE; + port->DMA_CHAN1_CONTROL = DMA_PORTA_CHAN1_CONTROL; + port->DMA_MANAGEMENT = DMA_PORTA_MANAGEMENT; + } else { + /* Port B */ + port->_dmaInterruptCH0 = (dmaChanUsed << 2) & 0x04; + port->_dmaInterruptCH1 = (dmaChanUsed << 2) & 0x08; + + port->DMA_CHAN0_ADDR_LOW = DMA_PORTB_CHAN0_ADDR_LOW; + port->DMA_CHAN0_ADDR_HI = DMA_PORTB_CHAN0_ADDR_HI; + port->DMA_CHAN0_TRANS_STATE = DMA_PORTB_CHAN0_TRANS_STATE; + port->DMA_CHAN0_CONTROL = DMA_PORTB_CHAN0_CONTROL; + port->DMA_CHAN1_ADDR_LOW = DMA_PORTB_CHAN1_ADDR_LOW; + port->DMA_CHAN1_ADDR_HI = DMA_PORTB_CHAN1_ADDR_HI; + port->DMA_CHAN1_TRANS_STATE = DMA_PORTB_CHAN1_TRANS_STATE; + port->DMA_CHAN1_CONTROL = DMA_PORTB_CHAN1_CONTROL; + port->DMA_MANAGEMENT = DMA_PORTB_MANAGEMENT; + } + + if (port->_dmaInterruptCH0) { + port->cpu_addr[0] = pci_alloc_consistent(port->dev->pci_dev, + SMI_TS_DMA_BUF_SIZE, + &port->dma_addr[0]); + if (!port->cpu_addr[0]) { + dev_err(&port->dev->pci_dev->dev, + "Port[%d] DMA CH0 memory allocation failed!\n", + port->idx); + goto err; + } + } + + if (port->_dmaInterruptCH1) { + port->cpu_addr[1] = pci_alloc_consistent(port->dev->pci_dev, + SMI_TS_DMA_BUF_SIZE, + &port->dma_addr[1]); + if (!port->cpu_addr[1]) { + dev_err(&port->dev->pci_dev->dev, + "Port[%d] DMA CH1 memory allocation failed!\n", + port->idx); + goto err; + } + } + + smi_port_disableInterrupt(port); + tasklet_init(&port->tasklet, smi_dma_xfer, (unsigned long)port); + tasklet_disable(&port->tasklet); + port->enable = 1; + return 0; +err: + smi_port_dma_free(port); + return -ENOMEM; +} + +static void smi_port_exit(struct smi_port *port) +{ + smi_port_disableInterrupt(port); + tasklet_kill(&port->tasklet); + smi_port_dma_free(port); + port->enable = 0; +} + +static void smi_port_irq(struct smi_port *port, u32 int_status) +{ + u32 port_req_irq = port->_dmaInterruptCH0 | port->_dmaInterruptCH1; + + if (int_status & port_req_irq) { + smi_port_disableInterrupt(port); + port->_int_status = int_status; + smi_port_clearInterrupt(port); + tasklet_schedule(&port->tasklet); + } +} + +static irqreturn_t smi_irq_handler(int irq, void *dev_id) +{ + struct smi_dev *dev = dev_id; + struct smi_port *port0 = &dev->ts_port[0]; + struct smi_port *port1 = &dev->ts_port[1]; + + u32 intr_status = smi_read(MSI_INT_STATUS); + + /* ts0 interrupt.*/ + if (dev->info->ts_0) + smi_port_irq(port0, intr_status); + + /* ts1 interrupt.*/ + if (dev->info->ts_1) + smi_port_irq(port1, intr_status); + + return IRQ_HANDLED; +} + +static struct i2c_client *smi_add_i2c_client(struct i2c_adapter *adapter, + struct i2c_board_info *info) +{ + struct i2c_client *client; + + request_module(info->type); + client = i2c_new_device(adapter, info); + if (client == NULL || client->dev.driver == NULL) + goto err_add_i2c_client; + + if (!try_module_get(client->dev.driver->owner)) { + i2c_unregister_device(client); + goto err_add_i2c_client; + } + return client; + +err_add_i2c_client: + client = NULL; + return client; +} + +static void smi_del_i2c_client(struct i2c_client *client) +{ + module_put(client->dev.driver->owner); + i2c_unregister_device(client); +} + +static const struct m88ds3103_config smi_dvbsky_m88ds3103_cfg = { + .i2c_addr = 0x68, + .clock = 27000000, + .i2c_wr_max = 33, + .clock_out = 0, + .ts_mode = M88DS3103_TS_PARALLEL, + .ts_clk = 16000, + .ts_clk_pol = 1, + .agc = 0x99, + .lnb_hv_pol = 0, + .lnb_en_pol = 1, +}; + +static int smi_dvbsky_m88ds3103_fe_attach(struct smi_port *port) +{ + int ret = 0; + struct smi_dev *dev = port->dev; + struct i2c_adapter *i2c; + /* tuner I2C module */ + struct i2c_adapter *tuner_i2c_adapter; + struct i2c_client *tuner_client; + struct i2c_board_info tuner_info; + struct m88ts2022_config m88ts2022_config = { + .clock = 27000000, + }; + memset(&tuner_info, 0, sizeof(struct i2c_board_info)); + i2c = (port->idx == 0) ? &dev->i2c_bus[0] : &dev->i2c_bus[1]; + + /* attach demod */ + port->fe = dvb_attach(m88ds3103_attach, + &smi_dvbsky_m88ds3103_cfg, i2c, &tuner_i2c_adapter); + if (!port->fe) { + ret = -ENODEV; + return ret; + } + /* attach tuner */ + m88ts2022_config.fe = port->fe; + strlcpy(tuner_info.type, "m88ts2022", I2C_NAME_SIZE); + tuner_info.addr = 0x60; + tuner_info.platform_data = &m88ts2022_config; + tuner_client = smi_add_i2c_client(tuner_i2c_adapter, &tuner_info); + if (!tuner_client) { + ret = -ENODEV; + goto err_tuner_i2c_device; + } + + /* delegate signal strength measurement to tuner */ + port->fe->ops.read_signal_strength = + port->fe->ops.tuner_ops.get_rf_strength; + + port->i2c_client_tuner = tuner_client; + return ret; + +err_tuner_i2c_device: + dvb_frontend_detach(port->fe); + return ret; +} + +static const struct m88ds3103_config smi_dvbsky_m88rs6000_cfg = { + .i2c_addr = 0x69, + .clock = 27000000, + .i2c_wr_max = 33, + .ts_mode = M88DS3103_TS_PARALLEL, + .ts_clk = 16000, + .ts_clk_pol = 1, + .agc = 0x99, + .lnb_hv_pol = 0, + .lnb_en_pol = 1, +}; + +static int smi_dvbsky_m88rs6000_fe_attach(struct smi_port *port) +{ + int ret = 0; + struct smi_dev *dev = port->dev; + struct i2c_adapter *i2c; + /* tuner I2C module */ + struct i2c_adapter *tuner_i2c_adapter; + struct i2c_client *tuner_client; + struct i2c_board_info tuner_info; + struct m88rs6000t_config m88rs6000t_config; + + memset(&tuner_info, 0, sizeof(struct i2c_board_info)); + i2c = (port->idx == 0) ? &dev->i2c_bus[0] : &dev->i2c_bus[1]; + + /* attach demod */ + port->fe = dvb_attach(m88ds3103_attach, + &smi_dvbsky_m88rs6000_cfg, i2c, &tuner_i2c_adapter); + if (!port->fe) { + ret = -ENODEV; + return ret; + } + /* attach tuner */ + m88rs6000t_config.fe = port->fe; + strlcpy(tuner_info.type, "m88rs6000t", I2C_NAME_SIZE); + tuner_info.addr = 0x21; + tuner_info.platform_data = &m88rs6000t_config; + tuner_client = smi_add_i2c_client(tuner_i2c_adapter, &tuner_info); + if (!tuner_client) { + ret = -ENODEV; + goto err_tuner_i2c_device; + } + + /* delegate signal strength measurement to tuner */ + port->fe->ops.read_signal_strength = + port->fe->ops.tuner_ops.get_rf_strength; + + port->i2c_client_tuner = tuner_client; + return ret; + +err_tuner_i2c_device: + dvb_frontend_detach(port->fe); + return ret; +} + +static int smi_dvbsky_sit2_fe_attach(struct smi_port *port) +{ + int ret = 0; + struct smi_dev *dev = port->dev; + struct i2c_adapter *i2c; + struct i2c_adapter *tuner_i2c_adapter; + struct i2c_client *client_tuner, *client_demod; + struct i2c_board_info client_info; + struct si2168_config si2168_config; + struct si2157_config si2157_config; + + /* select i2c bus */ + i2c = (port->idx == 0) ? &dev->i2c_bus[0] : &dev->i2c_bus[1]; + + /* attach demod */ + memset(&si2168_config, 0, sizeof(si2168_config)); + si2168_config.i2c_adapter = &tuner_i2c_adapter; + si2168_config.fe = &port->fe; + si2168_config.ts_mode = SI2168_TS_PARALLEL; + + memset(&client_info, 0, sizeof(struct i2c_board_info)); + strlcpy(client_info.type, "si2168", I2C_NAME_SIZE); + client_info.addr = 0x64; + client_info.platform_data = &si2168_config; + + client_demod = smi_add_i2c_client(i2c, &client_info); + if (!client_demod) { + ret = -ENODEV; + return ret; + } + port->i2c_client_demod = client_demod; + + /* attach tuner */ + memset(&si2157_config, 0, sizeof(si2157_config)); + si2157_config.fe = port->fe; + + memset(&client_info, 0, sizeof(struct i2c_board_info)); + strlcpy(client_info.type, "si2157", I2C_NAME_SIZE); + client_info.addr = 0x60; + client_info.platform_data = &si2157_config; + + client_tuner = smi_add_i2c_client(tuner_i2c_adapter, &client_info); + if (!client_tuner) { + smi_del_i2c_client(port->i2c_client_demod); + port->i2c_client_demod = NULL; + ret = -ENODEV; + return ret; + } + port->i2c_client_tuner = client_tuner; + return ret; +} + +static int smi_fe_init(struct smi_port *port) +{ + int ret = 0; + struct smi_dev *dev = port->dev; + struct dvb_adapter *adap = &port->dvb_adapter; + u8 mac_ee[16]; + + dev_dbg(&port->dev->pci_dev->dev, + "%s: port %d, fe_type = %d\n", + __func__, port->idx, port->fe_type); + switch (port->fe_type) { + case DVBSKY_FE_M88DS3103: + ret = smi_dvbsky_m88ds3103_fe_attach(port); + break; + case DVBSKY_FE_M88RS6000: + ret = smi_dvbsky_m88rs6000_fe_attach(port); + break; + case DVBSKY_FE_SIT2: + ret = smi_dvbsky_sit2_fe_attach(port); + break; + } + if (ret < 0) + return ret; + + /* register dvb frontend */ + ret = dvb_register_frontend(adap, port->fe); + if (ret < 0) { + if (port->i2c_client_tuner) + smi_del_i2c_client(port->i2c_client_tuner); + if (port->i2c_client_demod) + smi_del_i2c_client(port->i2c_client_demod); + dvb_frontend_detach(port->fe); + return ret; + } + /* init MAC.*/ + ret = smi_read_eeprom(&dev->i2c_bus[0], 0xc0, mac_ee, 16); + dev_info(&port->dev->pci_dev->dev, + "DVBSky SMI PCIe MAC= %pM\n", mac_ee + (port->idx)*8); + memcpy(adap->proposed_mac, mac_ee + (port->idx)*8, 6); + return ret; +} + +static void smi_fe_exit(struct smi_port *port) +{ + dvb_unregister_frontend(port->fe); + /* remove I2C demod and tuner */ + if (port->i2c_client_tuner) + smi_del_i2c_client(port->i2c_client_tuner); + if (port->i2c_client_demod) + smi_del_i2c_client(port->i2c_client_demod); + dvb_frontend_detach(port->fe); +} + +static int my_dvb_dmx_ts_card_init(struct dvb_demux *dvbdemux, char *id, + int (*start_feed)(struct dvb_demux_feed *), + int (*stop_feed)(struct dvb_demux_feed *), + void *priv) +{ + dvbdemux->priv = priv; + + dvbdemux->filternum = 256; + dvbdemux->feednum = 256; + dvbdemux->start_feed = start_feed; + dvbdemux->stop_feed = stop_feed; + dvbdemux->write_to_decoder = NULL; + dvbdemux->dmx.capabilities = (DMX_TS_FILTERING | + DMX_SECTION_FILTERING | + DMX_MEMORY_BASED_FILTERING); + return dvb_dmx_init(dvbdemux); +} + +static int my_dvb_dmxdev_ts_card_init(struct dmxdev *dmxdev, + struct dvb_demux *dvbdemux, + struct dmx_frontend *hw_frontend, + struct dmx_frontend *mem_frontend, + struct dvb_adapter *dvb_adapter) +{ + int ret; + + dmxdev->filternum = 256; + dmxdev->demux = &dvbdemux->dmx; + dmxdev->capabilities = 0; + ret = dvb_dmxdev_init(dmxdev, dvb_adapter); + if (ret < 0) + return ret; + + hw_frontend->source = DMX_FRONTEND_0; + dvbdemux->dmx.add_frontend(&dvbdemux->dmx, hw_frontend); + mem_frontend->source = DMX_MEMORY_FE; + dvbdemux->dmx.add_frontend(&dvbdemux->dmx, mem_frontend); + return dvbdemux->dmx.connect_frontend(&dvbdemux->dmx, hw_frontend); +} + +static u32 smi_config_DMA(struct smi_port *port) +{ + struct smi_dev *dev = port->dev; + u32 totalLength = 0, dmaMemPtrLow, dmaMemPtrHi, dmaCtlReg; + u8 chanLatencyTimer = 0, dmaChanEnable = 1, dmaTransStart = 1; + u32 dmaManagement = 0, tlpTransUnit = DMA_TRANS_UNIT_188; + u8 tlpTc = 0, tlpTd = 1, tlpEp = 0, tlpAttr = 0; + u64 mem; + + dmaManagement = smi_read(port->DMA_MANAGEMENT); + /* Setup Channel-0 */ + if (port->_dmaInterruptCH0) { + totalLength = SMI_TS_DMA_BUF_SIZE; + mem = port->dma_addr[0]; + dmaMemPtrLow = mem & 0xffffffff; + dmaMemPtrHi = mem >> 32; + dmaCtlReg = (totalLength) | (tlpTransUnit << 22) | (tlpTc << 25) + | (tlpTd << 28) | (tlpEp << 29) | (tlpAttr << 30); + dmaManagement |= dmaChanEnable | (dmaTransStart << 1) + | (chanLatencyTimer << 8); + /* write DMA register, start DMA engine */ + smi_write(port->DMA_CHAN0_ADDR_LOW, dmaMemPtrLow); + smi_write(port->DMA_CHAN0_ADDR_HI, dmaMemPtrHi); + smi_write(port->DMA_CHAN0_CONTROL, dmaCtlReg); + } + /* Setup Channel-1 */ + if (port->_dmaInterruptCH1) { + totalLength = SMI_TS_DMA_BUF_SIZE; + mem = port->dma_addr[1]; + dmaMemPtrLow = mem & 0xffffffff; + dmaMemPtrHi = mem >> 32; + dmaCtlReg = (totalLength) | (tlpTransUnit << 22) | (tlpTc << 25) + | (tlpTd << 28) | (tlpEp << 29) | (tlpAttr << 30); + dmaManagement |= (dmaChanEnable << 16) | (dmaTransStart << 17) + | (chanLatencyTimer << 24); + /* write DMA register, start DMA engine */ + smi_write(port->DMA_CHAN1_ADDR_LOW, dmaMemPtrLow); + smi_write(port->DMA_CHAN1_ADDR_HI, dmaMemPtrHi); + smi_write(port->DMA_CHAN1_CONTROL, dmaCtlReg); + } + return dmaManagement; +} + +static int smi_start_feed(struct dvb_demux_feed *dvbdmxfeed) +{ + struct dvb_demux *dvbdmx = dvbdmxfeed->demux; + struct smi_port *port = dvbdmx->priv; + struct smi_dev *dev = port->dev; + u32 dmaManagement; + + if (port->users++ == 0) { + dmaManagement = smi_config_DMA(port); + smi_port_clearInterrupt(port); + smi_port_enableInterrupt(port); + smi_write(port->DMA_MANAGEMENT, dmaManagement); + tasklet_enable(&port->tasklet); + } + return port->users; +} + +static int smi_stop_feed(struct dvb_demux_feed *dvbdmxfeed) +{ + struct dvb_demux *dvbdmx = dvbdmxfeed->demux; + struct smi_port *port = dvbdmx->priv; + struct smi_dev *dev = port->dev; + + if (--port->users) + return port->users; + + tasklet_disable(&port->tasklet); + smi_port_disableInterrupt(port); + smi_clear(port->DMA_MANAGEMENT, 0x30003); + return 0; +} + +static int smi_dvb_init(struct smi_port *port) +{ + int ret; + struct dvb_adapter *adap = &port->dvb_adapter; + struct dvb_demux *dvbdemux = &port->demux; + + dev_dbg(&port->dev->pci_dev->dev, + "%s, port %d\n", __func__, port->idx); + + ret = dvb_register_adapter(adap, "SMI_DVB", THIS_MODULE, + &port->dev->pci_dev->dev, + adapter_nr); + if (ret < 0) { + dev_err(&port->dev->pci_dev->dev, "Fail to register DVB adapter.\n"); + return ret; + } + ret = my_dvb_dmx_ts_card_init(dvbdemux, "SW demux", + smi_start_feed, + smi_stop_feed, port); + if (ret < 0) + goto err_del_dvb_register_adapter; + + ret = my_dvb_dmxdev_ts_card_init(&port->dmxdev, &port->demux, + &port->hw_frontend, + &port->mem_frontend, adap); + if (ret < 0) + goto err_del_dvb_dmx; + + ret = dvb_net_init(adap, &port->dvbnet, port->dmxdev.demux); + if (ret < 0) + goto err_del_dvb_dmxdev; + return 0; +err_del_dvb_dmxdev: + dvbdemux->dmx.close(&dvbdemux->dmx); + dvbdemux->dmx.remove_frontend(&dvbdemux->dmx, &port->hw_frontend); + dvbdemux->dmx.remove_frontend(&dvbdemux->dmx, &port->mem_frontend); + dvb_dmxdev_release(&port->dmxdev); +err_del_dvb_dmx: + dvb_dmx_release(&port->demux); +err_del_dvb_register_adapter: + dvb_unregister_adapter(&port->dvb_adapter); + return ret; +} + +static void smi_dvb_exit(struct smi_port *port) +{ + struct dvb_demux *dvbdemux = &port->demux; + + dvb_net_release(&port->dvbnet); + + dvbdemux->dmx.close(&dvbdemux->dmx); + dvbdemux->dmx.remove_frontend(&dvbdemux->dmx, &port->hw_frontend); + dvbdemux->dmx.remove_frontend(&dvbdemux->dmx, &port->mem_frontend); + dvb_dmxdev_release(&port->dmxdev); + dvb_dmx_release(&port->demux); + + dvb_unregister_adapter(&port->dvb_adapter); +} + +static int smi_port_attach(struct smi_dev *dev, + struct smi_port *port, int index) +{ + int ret, dmachs; + + port->dev = dev; + port->idx = index; + port->fe_type = (index == 0) ? dev->info->fe_0 : dev->info->fe_1; + dmachs = (index == 0) ? dev->info->ts_0 : dev->info->ts_1; + /* port init.*/ + ret = smi_port_init(port, dmachs); + if (ret < 0) + return ret; + /* dvb init.*/ + ret = smi_dvb_init(port); + if (ret < 0) + goto err_del_port_init; + /* fe init.*/ + ret = smi_fe_init(port); + if (ret < 0) + goto err_del_dvb_init; + return 0; +err_del_dvb_init: + smi_dvb_exit(port); +err_del_port_init: + smi_port_exit(port); + return ret; +} + +static void smi_port_detach(struct smi_port *port) +{ + smi_fe_exit(port); + smi_dvb_exit(port); + smi_port_exit(port); +} + +static int smi_probe(struct pci_dev *pdev, const struct pci_device_id *id) +{ + struct smi_dev *dev; + int ret = -ENOMEM; + + if (pci_enable_device(pdev) < 0) + return -ENODEV; + + dev = kzalloc(sizeof(struct smi_dev), GFP_KERNEL); + if (!dev) { + ret = -ENOMEM; + goto err_pci_disable_device; + } + + dev->pci_dev = pdev; + pci_set_drvdata(pdev, dev); + dev->info = (struct smi_cfg_info *) id->driver_data; + dev_info(&dev->pci_dev->dev, + "card detected: %s\n", dev->info->name); + + dev->nr = dev->info->type; + dev->lmmio = ioremap(pci_resource_start(dev->pci_dev, 0), + pci_resource_len(dev->pci_dev, 0)); + if (!dev->lmmio) { + ret = -ENOMEM; + goto err_kfree; + } + + /* should we set to 32bit DMA? */ + ret = pci_set_dma_mask(pdev, DMA_BIT_MASK(32)); + if (ret < 0) + goto err_pci_iounmap; + + pci_set_master(pdev); + + ret = smi_hw_init(dev); + if (ret < 0) + goto err_pci_iounmap; + + ret = smi_i2c_init(dev); + if (ret < 0) + goto err_pci_iounmap; + + if (dev->info->ts_0) { + ret = smi_port_attach(dev, &dev->ts_port[0], 0); + if (ret < 0) + goto err_del_i2c_adaptor; + } + + if (dev->info->ts_1) { + ret = smi_port_attach(dev, &dev->ts_port[1], 1); + if (ret < 0) + goto err_del_port0_attach; + } + +#ifdef CONFIG_PCI_MSI /* to do msi interrupt.???*/ + if (pci_msi_enabled()) + ret = pci_enable_msi(dev->pci_dev); + if (ret) + dev_info(&dev->pci_dev->dev, "MSI not available.\n"); +#endif + + ret = request_irq(dev->pci_dev->irq, smi_irq_handler, + IRQF_SHARED, "SMI_PCIE", dev); + if (ret < 0) + goto err_del_port1_attach; + + return 0; + +err_del_port1_attach: + if (dev->info->ts_1) + smi_port_detach(&dev->ts_port[1]); +err_del_port0_attach: + if (dev->info->ts_0) + smi_port_detach(&dev->ts_port[0]); +err_del_i2c_adaptor: + smi_i2c_exit(dev); +err_pci_iounmap: + iounmap(dev->lmmio); +err_kfree: + pci_set_drvdata(pdev, NULL); + kfree(dev); +err_pci_disable_device: + pci_disable_device(pdev); + return ret; +} + +static void smi_remove(struct pci_dev *pdev) +{ + struct smi_dev *dev = pci_get_drvdata(pdev); + + smi_write(MSI_INT_ENA_CLR, ALL_INT); + free_irq(dev->pci_dev->irq, dev); +#ifdef CONFIG_PCI_MSI + pci_disable_msi(dev->pci_dev); +#endif + if (dev->info->ts_1) + smi_port_detach(&dev->ts_port[1]); + if (dev->info->ts_0) + smi_port_detach(&dev->ts_port[0]); + + smi_i2c_exit(dev); + iounmap(dev->lmmio); + pci_set_drvdata(pdev, NULL); + pci_disable_device(pdev); + kfree(dev); +} + +/* DVBSky cards */ +static struct smi_cfg_info dvbsky_s950_cfg = { + .type = SMI_DVBSKY_S950, + .name = "DVBSky S950 V3", + .ts_0 = SMI_TS_NULL, + .ts_1 = SMI_TS_DMA_BOTH, + .fe_0 = DVBSKY_FE_NULL, + .fe_1 = DVBSKY_FE_M88DS3103, +}; + +static struct smi_cfg_info dvbsky_s952_cfg = { + .type = SMI_DVBSKY_S952, + .name = "DVBSky S952 V3", + .ts_0 = SMI_TS_DMA_BOTH, + .ts_1 = SMI_TS_DMA_BOTH, + .fe_0 = DVBSKY_FE_M88RS6000, + .fe_1 = DVBSKY_FE_M88RS6000, +}; + +static struct smi_cfg_info dvbsky_t9580_cfg = { + .type = SMI_DVBSKY_T9580, + .name = "DVBSky T9580 V3", + .ts_0 = SMI_TS_DMA_BOTH, + .ts_1 = SMI_TS_DMA_BOTH, + .fe_0 = DVBSKY_FE_SIT2, + .fe_1 = DVBSKY_FE_M88DS3103, +}; + +/* PCI IDs */ +#define SMI_ID(_subvend, _subdev, _driverdata) { \ + .vendor = SMI_VID, .device = SMI_PID, \ + .subvendor = _subvend, .subdevice = _subdev, \ + .driver_data = (unsigned long)&_driverdata } + +static const struct pci_device_id smi_id_table[] = { + SMI_ID(0x4254, 0x0550, dvbsky_s950_cfg), + SMI_ID(0x4254, 0x0552, dvbsky_s952_cfg), + SMI_ID(0x4254, 0x5580, dvbsky_t9580_cfg), + {0} +}; +MODULE_DEVICE_TABLE(pci, smi_id_table); + +static struct pci_driver smipcie_driver = { + .name = "SMI PCIe driver", + .id_table = smi_id_table, + .probe = smi_probe, + .remove = smi_remove, +}; + +module_pci_driver(smipcie_driver); + +MODULE_AUTHOR("Max nibble <nibble.max@gmail.com>"); +MODULE_DESCRIPTION("SMI PCIe driver"); +MODULE_LICENSE("GPL"); diff --git a/drivers/media/pci/smipcie/smipcie.h b/drivers/media/pci/smipcie/smipcie.h new file mode 100644 index 00000000000..10cdf20f483 --- /dev/null +++ b/drivers/media/pci/smipcie/smipcie.h @@ -0,0 +1,299 @@ +/* + * SMI PCIe driver for DVBSky cards. + * + * Copyright (C) 2014 Max nibble <nibble.max@gmail.com> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#ifndef _SMI_PCIE_H_ +#define _SMI_PCIE_H_ + +#include <linux/i2c.h> +#include <linux/i2c-algo-bit.h> +#include <linux/init.h> +#include <linux/interrupt.h> +#include <linux/kernel.h> +#include <linux/module.h> +#include <linux/proc_fs.h> +#include <linux/pci.h> +#include <linux/dma-mapping.h> +#include <linux/slab.h> +#include <media/rc-core.h> + +#include "demux.h" +#include "dmxdev.h" +#include "dvb_demux.h" +#include "dvb_frontend.h" +#include "dvb_net.h" +#include "dvbdev.h" + +/* -------- Register Base -------- */ +#define MSI_CONTROL_REG_BASE 0x0800 +#define SYSTEM_CONTROL_REG_BASE 0x0880 +#define PCIE_EP_DEBUG_REG_BASE 0x08C0 +#define IR_CONTROL_REG_BASE 0x0900 +#define I2C_A_CONTROL_REG_BASE 0x0940 +#define I2C_B_CONTROL_REG_BASE 0x0980 +#define ATV_PORTA_CONTROL_REG_BASE 0x09C0 +#define DTV_PORTA_CONTROL_REG_BASE 0x0A00 +#define AES_PORTA_CONTROL_REG_BASE 0x0A80 +#define DMA_PORTA_CONTROL_REG_BASE 0x0AC0 +#define ATV_PORTB_CONTROL_REG_BASE 0x0B00 +#define DTV_PORTB_CONTROL_REG_BASE 0x0B40 +#define AES_PORTB_CONTROL_REG_BASE 0x0BC0 +#define DMA_PORTB_CONTROL_REG_BASE 0x0C00 +#define UART_A_REGISTER_BASE 0x0C40 +#define UART_B_REGISTER_BASE 0x0C80 +#define GPS_CONTROL_REG_BASE 0x0CC0 +#define DMA_PORTC_CONTROL_REG_BASE 0x0D00 +#define DMA_PORTD_CONTROL_REG_BASE 0x0D00 +#define AES_RANDOM_DATA_BASE 0x0D80 +#define AES_KEY_IN_BASE 0x0D90 +#define RANDOM_DATA_LIB_BASE 0x0E00 +#define IR_DATA_BUFFER_BASE 0x0F00 +#define PORTA_TS_BUFFER_BASE 0x1000 +#define PORTA_I2S_BUFFER_BASE 0x1400 +#define PORTB_TS_BUFFER_BASE 0x1800 +#define PORTB_I2S_BUFFER_BASE 0x1C00 + +/* -------- MSI control and state register -------- */ +#define MSI_DELAY_TIMER (MSI_CONTROL_REG_BASE + 0x00) +#define MSI_INT_STATUS (MSI_CONTROL_REG_BASE + 0x08) +#define MSI_INT_STATUS_CLR (MSI_CONTROL_REG_BASE + 0x0C) +#define MSI_INT_STATUS_SET (MSI_CONTROL_REG_BASE + 0x10) +#define MSI_INT_ENA (MSI_CONTROL_REG_BASE + 0x14) +#define MSI_INT_ENA_CLR (MSI_CONTROL_REG_BASE + 0x18) +#define MSI_INT_ENA_SET (MSI_CONTROL_REG_BASE + 0x1C) +#define MSI_SOFT_RESET (MSI_CONTROL_REG_BASE + 0x20) +#define MSI_CFG_SRC0 (MSI_CONTROL_REG_BASE + 0x24) + +/* -------- Hybird Controller System Control register -------- */ +#define MUX_MODE_CTRL (SYSTEM_CONTROL_REG_BASE + 0x00) + #define rbPaMSMask 0x07 + #define rbPaMSDtvNoGpio 0x00 /*[2:0], DTV Simple mode */ + #define rbPaMSDtv4bitGpio 0x01 /*[2:0], DTV TS2 Serial mode)*/ + #define rbPaMSDtv7bitGpio 0x02 /*[2:0], DTV TS0 Serial mode*/ + #define rbPaMS8bitGpio 0x03 /*[2:0], GPIO mode selected;(8bit GPIO)*/ + #define rbPaMSAtv 0x04 /*[2:0], 3'b1xx: ATV mode select*/ + #define rbPbMSMask 0x38 + #define rbPbMSDtvNoGpio 0x00 /*[5:3], DTV Simple mode */ + #define rbPbMSDtv4bitGpio 0x08 /*[5:3], DTV TS2 Serial mode*/ + #define rbPbMSDtv7bitGpio 0x10 /*[5:3], DTV TS0 Serial mode*/ + #define rbPbMS8bitGpio 0x18 /*[5:3], GPIO mode selected;(8bit GPIO)*/ + #define rbPbMSAtv 0x20 /*[5:3], 3'b1xx: ATV mode select*/ + #define rbPaAESEN 0x40 /*[6], port A AES enable bit*/ + #define rbPbAESEN 0x80 /*[7], port B AES enable bit*/ + +#define INTERNAL_RST (SYSTEM_CONTROL_REG_BASE + 0x04) +#define PERIPHERAL_CTRL (SYSTEM_CONTROL_REG_BASE + 0x08) +#define GPIO_0to7_CTRL (SYSTEM_CONTROL_REG_BASE + 0x0C) +#define GPIO_8to15_CTRL (SYSTEM_CONTROL_REG_BASE + 0x10) +#define GPIO_16to24_CTRL (SYSTEM_CONTROL_REG_BASE + 0x14) +#define GPIO_INT_SRC_CFG (SYSTEM_CONTROL_REG_BASE + 0x18) +#define SYS_BUF_STATUS (SYSTEM_CONTROL_REG_BASE + 0x1C) +#define PCIE_IP_REG_ACS (SYSTEM_CONTROL_REG_BASE + 0x20) +#define PCIE_IP_REG_ACS_ADDR (SYSTEM_CONTROL_REG_BASE + 0x24) +#define PCIE_IP_REG_ACS_DATA (SYSTEM_CONTROL_REG_BASE + 0x28) + +/* -------- IR Control register -------- */ +#define IR_Init_Reg (IR_CONTROL_REG_BASE + 0x00) +#define IR_Idle_Cnt_Low (IR_CONTROL_REG_BASE + 0x04) +#define IR_Idle_Cnt_High (IR_CONTROL_REG_BASE + 0x05) +#define IR_Unit_Cnt_Low (IR_CONTROL_REG_BASE + 0x06) +#define IR_Unit_Cnt_High (IR_CONTROL_REG_BASE + 0x07) +#define IR_Data_Cnt (IR_CONTROL_REG_BASE + 0x08) +#define rbIRen 0x80 +#define rbIRhighidle 0x10 +#define rbIRlowidle 0x00 +#define rbIRVld 0x04 + +/* -------- I2C A control and state register -------- */ +#define I2C_A_CTL_STATUS (I2C_A_CONTROL_REG_BASE + 0x00) +#define I2C_A_ADDR (I2C_A_CONTROL_REG_BASE + 0x04) +#define I2C_A_SW_CTL (I2C_A_CONTROL_REG_BASE + 0x08) +#define I2C_A_TIME_OUT_CNT (I2C_A_CONTROL_REG_BASE + 0x0C) +#define I2C_A_FIFO_STATUS (I2C_A_CONTROL_REG_BASE + 0x10) +#define I2C_A_FS_EN (I2C_A_CONTROL_REG_BASE + 0x14) +#define I2C_A_FIFO_DATA (I2C_A_CONTROL_REG_BASE + 0x20) + +/* -------- I2C B control and state register -------- */ +#define I2C_B_CTL_STATUS (I2C_B_CONTROL_REG_BASE + 0x00) +#define I2C_B_ADDR (I2C_B_CONTROL_REG_BASE + 0x04) +#define I2C_B_SW_CTL (I2C_B_CONTROL_REG_BASE + 0x08) +#define I2C_B_TIME_OUT_CNT (I2C_B_CONTROL_REG_BASE + 0x0C) +#define I2C_B_FIFO_STATUS (I2C_B_CONTROL_REG_BASE + 0x10) +#define I2C_B_FS_EN (I2C_B_CONTROL_REG_BASE + 0x14) +#define I2C_B_FIFO_DATA (I2C_B_CONTROL_REG_BASE + 0x20) + +#define VIDEO_CTRL_STATUS_A (ATV_PORTA_CONTROL_REG_BASE + 0x04) + +/* -------- Digital TV control register, Port A -------- */ +#define MPEG2_CTRL_A (DTV_PORTA_CONTROL_REG_BASE + 0x00) +#define SERIAL_IN_ADDR_A (DTV_PORTA_CONTROL_REG_BASE + 0x4C) +#define VLD_CNT_ADDR_A (DTV_PORTA_CONTROL_REG_BASE + 0x60) +#define ERR_CNT_ADDR_A (DTV_PORTA_CONTROL_REG_BASE + 0x64) +#define BRD_CNT_ADDR_A (DTV_PORTA_CONTROL_REG_BASE + 0x68) + +/* -------- DMA Control Register, Port A -------- */ +#define DMA_PORTA_CHAN0_ADDR_LOW (DMA_PORTA_CONTROL_REG_BASE + 0x00) +#define DMA_PORTA_CHAN0_ADDR_HI (DMA_PORTA_CONTROL_REG_BASE + 0x04) +#define DMA_PORTA_CHAN0_TRANS_STATE (DMA_PORTA_CONTROL_REG_BASE + 0x08) +#define DMA_PORTA_CHAN0_CONTROL (DMA_PORTA_CONTROL_REG_BASE + 0x0C) +#define DMA_PORTA_CHAN1_ADDR_LOW (DMA_PORTA_CONTROL_REG_BASE + 0x10) +#define DMA_PORTA_CHAN1_ADDR_HI (DMA_PORTA_CONTROL_REG_BASE + 0x14) +#define DMA_PORTA_CHAN1_TRANS_STATE (DMA_PORTA_CONTROL_REG_BASE + 0x18) +#define DMA_PORTA_CHAN1_CONTROL (DMA_PORTA_CONTROL_REG_BASE + 0x1C) +#define DMA_PORTA_MANAGEMENT (DMA_PORTA_CONTROL_REG_BASE + 0x20) +#define VIDEO_CTRL_STATUS_B (ATV_PORTB_CONTROL_REG_BASE + 0x04) + +/* -------- Digital TV control register, Port B -------- */ +#define MPEG2_CTRL_B (DTV_PORTB_CONTROL_REG_BASE + 0x00) +#define SERIAL_IN_ADDR_B (DTV_PORTB_CONTROL_REG_BASE + 0x4C) +#define VLD_CNT_ADDR_B (DTV_PORTB_CONTROL_REG_BASE + 0x60) +#define ERR_CNT_ADDR_B (DTV_PORTB_CONTROL_REG_BASE + 0x64) +#define BRD_CNT_ADDR_B (DTV_PORTB_CONTROL_REG_BASE + 0x68) + +/* -------- AES control register, Port B -------- */ +#define AES_CTRL_B (AES_PORTB_CONTROL_REG_BASE + 0x00) +#define AES_KEY_BASE_B (AES_PORTB_CONTROL_REG_BASE + 0x04) + +/* -------- DMA Control Register, Port B -------- */ +#define DMA_PORTB_CHAN0_ADDR_LOW (DMA_PORTB_CONTROL_REG_BASE + 0x00) +#define DMA_PORTB_CHAN0_ADDR_HI (DMA_PORTB_CONTROL_REG_BASE + 0x04) +#define DMA_PORTB_CHAN0_TRANS_STATE (DMA_PORTB_CONTROL_REG_BASE + 0x08) +#define DMA_PORTB_CHAN0_CONTROL (DMA_PORTB_CONTROL_REG_BASE + 0x0C) +#define DMA_PORTB_CHAN1_ADDR_LOW (DMA_PORTB_CONTROL_REG_BASE + 0x10) +#define DMA_PORTB_CHAN1_ADDR_HI (DMA_PORTB_CONTROL_REG_BASE + 0x14) +#define DMA_PORTB_CHAN1_TRANS_STATE (DMA_PORTB_CONTROL_REG_BASE + 0x18) +#define DMA_PORTB_CHAN1_CONTROL (DMA_PORTB_CONTROL_REG_BASE + 0x1C) +#define DMA_PORTB_MANAGEMENT (DMA_PORTB_CONTROL_REG_BASE + 0x20) + +#define DMA_TRANS_UNIT_188 (0x00000007) + +/* -------- Macro define of 24 interrupt resource --------*/ +#define DMA_A_CHAN0_DONE_INT (0x00000001) +#define DMA_A_CHAN1_DONE_INT (0x00000002) +#define DMA_B_CHAN0_DONE_INT (0x00000004) +#define DMA_B_CHAN1_DONE_INT (0x00000008) +#define DMA_C_CHAN0_DONE_INT (0x00000010) +#define DMA_C_CHAN1_DONE_INT (0x00000020) +#define DMA_D_CHAN0_DONE_INT (0x00000040) +#define DMA_D_CHAN1_DONE_INT (0x00000080) +#define DATA_BUF_OVERFLOW_INT (0x00000100) +#define UART_0_X_INT (0x00000200) +#define UART_1_X_INT (0x00000400) +#define IR_X_INT (0x00000800) +#define GPIO_0_INT (0x00001000) +#define GPIO_1_INT (0x00002000) +#define GPIO_2_INT (0x00004000) +#define GPIO_3_INT (0x00008000) +#define ALL_INT (0x0000FFFF) + +/* software I2C bit mask */ +#define SW_I2C_MSK_MODE 0x01 +#define SW_I2C_MSK_CLK_OUT 0x02 +#define SW_I2C_MSK_DAT_OUT 0x04 +#define SW_I2C_MSK_CLK_EN 0x08 +#define SW_I2C_MSK_DAT_EN 0x10 +#define SW_I2C_MSK_DAT_IN 0x40 +#define SW_I2C_MSK_CLK_IN 0x80 + +#define SMI_VID 0x1ADE +#define SMI_PID 0x3038 +#define SMI_TS_DMA_BUF_SIZE (1024 * 188) + +struct smi_cfg_info { +#define SMI_DVBSKY_S952 0 +#define SMI_DVBSKY_S950 1 +#define SMI_DVBSKY_T9580 2 +#define SMI_DVBSKY_T982 3 + int type; + char *name; +#define SMI_TS_NULL 0 +#define SMI_TS_DMA_SINGLE 1 +#define SMI_TS_DMA_BOTH 3 +/* SMI_TS_NULL: not use; + * SMI_TS_DMA_SINGLE: use DMA 0 only; + * SMI_TS_DMA_BOTH:use DMA 0 and 1.*/ + int ts_0; + int ts_1; +#define DVBSKY_FE_NULL 0 +#define DVBSKY_FE_M88RS6000 1 +#define DVBSKY_FE_M88DS3103 2 +#define DVBSKY_FE_SIT2 3 + int fe_0; + int fe_1; +}; + +struct smi_port { + struct smi_dev *dev; + int idx; + int enable; + int fe_type; + /* regs */ + u32 DMA_CHAN0_ADDR_LOW; + u32 DMA_CHAN0_ADDR_HI; + u32 DMA_CHAN0_TRANS_STATE; + u32 DMA_CHAN0_CONTROL; + u32 DMA_CHAN1_ADDR_LOW; + u32 DMA_CHAN1_ADDR_HI; + u32 DMA_CHAN1_TRANS_STATE; + u32 DMA_CHAN1_CONTROL; + u32 DMA_MANAGEMENT; + /* dma */ + dma_addr_t dma_addr[2]; + u8 *cpu_addr[2]; + u32 _dmaInterruptCH0; + u32 _dmaInterruptCH1; + u32 _int_status; + struct tasklet_struct tasklet; + /* dvb */ + struct dmx_frontend hw_frontend; + struct dmx_frontend mem_frontend; + struct dmxdev dmxdev; + struct dvb_adapter dvb_adapter; + struct dvb_demux demux; + struct dvb_net dvbnet; + int users; + struct dvb_frontend *fe; + /* frontend i2c module */ + struct i2c_client *i2c_client_demod; + struct i2c_client *i2c_client_tuner; +}; + +struct smi_dev { + int nr; + struct smi_cfg_info *info; + + /* pcie */ + struct pci_dev *pci_dev; + u32 __iomem *lmmio; + + /* ts port */ + struct smi_port ts_port[2]; + + /* i2c */ + struct i2c_adapter i2c_bus[2]; + struct i2c_algo_bit_data i2c_bit[2]; +}; + +#define smi_read(reg) readl(dev->lmmio + ((reg)>>2)) +#define smi_write(reg, value) writel((value), dev->lmmio + ((reg)>>2)) + +#define smi_andor(reg, mask, value) \ + writel((readl(dev->lmmio+((reg)>>2)) & ~(mask)) |\ + ((value) & (mask)), dev->lmmio+((reg)>>2)) + +#define smi_set(reg, bit) smi_andor((reg), (bit), (bit)) +#define smi_clear(reg, bit) smi_andor((reg), (bit), 0) + +#endif /* #ifndef _SMI_PCIE_H_ */ diff --git a/drivers/media/pci/solo6x10/solo6x10-v4l2-enc.c b/drivers/media/pci/solo6x10/solo6x10-v4l2-enc.c index 28023f9f1dc..6e933d383fa 100644 --- a/drivers/media/pci/solo6x10/solo6x10-v4l2-enc.c +++ b/drivers/media/pci/solo6x10/solo6x10-v4l2-enc.c @@ -463,7 +463,6 @@ static int solo_fill_jpeg(struct solo_enc_dev *solo_enc, struct solo_dev *solo_dev = solo_enc->solo_dev; struct sg_table *vbuf = vb2_dma_sg_plane_desc(vb, 0); int frame_size; - int ret; vb->v4l2_buf.flags |= V4L2_BUF_FLAG_KEYFRAME; @@ -473,22 +472,10 @@ static int solo_fill_jpeg(struct solo_enc_dev *solo_enc, frame_size = ALIGN(vop_jpeg_size(vh) + solo_enc->jpeg_len, DMA_ALIGN); vb2_set_plane_payload(vb, 0, vop_jpeg_size(vh) + solo_enc->jpeg_len); - /* may discard all previous data in vbuf->sgl */ - if (!dma_map_sg(&solo_dev->pdev->dev, vbuf->sgl, vbuf->nents, - DMA_FROM_DEVICE)) - return -ENOMEM; - ret = solo_send_desc(solo_enc, solo_enc->jpeg_len, vbuf, + return solo_send_desc(solo_enc, solo_enc->jpeg_len, vbuf, vop_jpeg_offset(vh) - SOLO_JPEG_EXT_ADDR(solo_dev), frame_size, SOLO_JPEG_EXT_ADDR(solo_dev), SOLO_JPEG_EXT_SIZE(solo_dev)); - dma_unmap_sg(&solo_dev->pdev->dev, vbuf->sgl, vbuf->nents, - DMA_FROM_DEVICE); - - /* add the header only after dma_unmap_sg() */ - sg_copy_from_buffer(vbuf->sgl, vbuf->nents, - solo_enc->jpeg_header, solo_enc->jpeg_len); - - return ret; } static int solo_fill_mpeg(struct solo_enc_dev *solo_enc, @@ -498,7 +485,6 @@ static int solo_fill_mpeg(struct solo_enc_dev *solo_enc, struct sg_table *vbuf = vb2_dma_sg_plane_desc(vb, 0); int frame_off, frame_size; int skip = 0; - int ret; if (vb2_plane_size(vb, 0) < vop_mpeg_size(vh)) return -EIO; @@ -521,21 +507,9 @@ static int solo_fill_mpeg(struct solo_enc_dev *solo_enc, sizeof(*vh)) % SOLO_MP4E_EXT_SIZE(solo_dev); frame_size = ALIGN(vop_mpeg_size(vh) + skip, DMA_ALIGN); - /* may discard all previous data in vbuf->sgl */ - if (!dma_map_sg(&solo_dev->pdev->dev, vbuf->sgl, vbuf->nents, - DMA_FROM_DEVICE)) - return -ENOMEM; - ret = solo_send_desc(solo_enc, skip, vbuf, frame_off, frame_size, + return solo_send_desc(solo_enc, skip, vbuf, frame_off, frame_size, SOLO_MP4E_EXT_ADDR(solo_dev), SOLO_MP4E_EXT_SIZE(solo_dev)); - dma_unmap_sg(&solo_dev->pdev->dev, vbuf->sgl, vbuf->nents, - DMA_FROM_DEVICE); - - /* add the header only after dma_unmap_sg() */ - if (!vop_type(vh)) - sg_copy_from_buffer(vbuf->sgl, vbuf->nents, - solo_enc->vop, solo_enc->vop_len); - return ret; } static int solo_enc_fillbuf(struct solo_enc_dev *solo_enc, @@ -703,9 +677,7 @@ static int solo_ring_thread(void *data) if (timeout == -ERESTARTSYS || kthread_should_stop()) break; - solo_irq_off(solo_dev, SOLO_IRQ_ENCODER); solo_handle_ring(solo_dev); - solo_irq_on(solo_dev, SOLO_IRQ_ENCODER); try_to_freeze(); } @@ -720,7 +692,10 @@ static int solo_enc_queue_setup(struct vb2_queue *q, unsigned int *num_planes, unsigned int sizes[], void *alloc_ctxs[]) { + struct solo_enc_dev *solo_enc = vb2_get_drv_priv(q); + sizes[0] = FRAME_BUF_SIZE; + alloc_ctxs[0] = solo_enc->alloc_ctx; *num_planes = 1; if (*num_buffers < MIN_VID_BUFFERS) @@ -770,26 +745,51 @@ static void solo_ring_stop(struct solo_dev *solo_dev) static int solo_enc_start_streaming(struct vb2_queue *q, unsigned int count) { struct solo_enc_dev *solo_enc = vb2_get_drv_priv(q); - int ret; - ret = solo_enc_on(solo_enc); - if (ret) - return ret; - return solo_ring_start(solo_enc->solo_dev); + return solo_enc_on(solo_enc); } static void solo_enc_stop_streaming(struct vb2_queue *q) { struct solo_enc_dev *solo_enc = vb2_get_drv_priv(q); + unsigned long flags; + spin_lock_irqsave(&solo_enc->av_lock, flags); solo_enc_off(solo_enc); - INIT_LIST_HEAD(&solo_enc->vidq_active); - solo_ring_stop(solo_enc->solo_dev); + while (!list_empty(&solo_enc->vidq_active)) { + struct solo_vb2_buf *buf = list_entry( + solo_enc->vidq_active.next, + struct solo_vb2_buf, list); + + list_del(&buf->list); + vb2_buffer_done(&buf->vb, VB2_BUF_STATE_ERROR); + } + spin_unlock_irqrestore(&solo_enc->av_lock, flags); +} + +static void solo_enc_buf_finish(struct vb2_buffer *vb) +{ + struct solo_enc_dev *solo_enc = vb2_get_drv_priv(vb->vb2_queue); + struct sg_table *vbuf = vb2_dma_sg_plane_desc(vb, 0); + + switch (solo_enc->fmt) { + case V4L2_PIX_FMT_MPEG4: + case V4L2_PIX_FMT_H264: + if (vb->v4l2_buf.flags & V4L2_BUF_FLAG_KEYFRAME) + sg_copy_from_buffer(vbuf->sgl, vbuf->nents, + solo_enc->vop, solo_enc->vop_len); + break; + default: /* V4L2_PIX_FMT_MJPEG */ + sg_copy_from_buffer(vbuf->sgl, vbuf->nents, + solo_enc->jpeg_header, solo_enc->jpeg_len); + break; + } } static struct vb2_ops solo_enc_video_qops = { .queue_setup = solo_enc_queue_setup, .buf_queue = solo_enc_buf_queue, + .buf_finish = solo_enc_buf_finish, .start_streaming = solo_enc_start_streaming, .stop_streaming = solo_enc_stop_streaming, .wait_prepare = vb2_ops_wait_prepare, @@ -1263,6 +1263,11 @@ static struct solo_enc_dev *solo_enc_alloc(struct solo_dev *solo_dev, return ERR_PTR(-ENOMEM); hdl = &solo_enc->hdl; + solo_enc->alloc_ctx = vb2_dma_sg_init_ctx(&solo_dev->pdev->dev); + if (IS_ERR(solo_enc->alloc_ctx)) { + ret = PTR_ERR(solo_enc->alloc_ctx); + goto hdl_free; + } v4l2_ctrl_handler_init(hdl, 10); v4l2_ctrl_new_std(hdl, &solo_ctrl_ops, V4L2_CID_BRIGHTNESS, 0, 255, 1, 128); @@ -1366,6 +1371,7 @@ pci_free: solo_enc->desc_items, solo_enc->desc_dma); hdl_free: v4l2_ctrl_handler_free(hdl); + vb2_dma_sg_cleanup_ctx(solo_enc->alloc_ctx); kfree(solo_enc); return ERR_PTR(ret); } @@ -1375,8 +1381,12 @@ static void solo_enc_free(struct solo_enc_dev *solo_enc) if (solo_enc == NULL) return; + pci_free_consistent(solo_enc->solo_dev->pdev, + sizeof(struct solo_p2m_desc) * solo_enc->desc_nelts, + solo_enc->desc_items, solo_enc->desc_dma); video_unregister_device(solo_enc->vfd); v4l2_ctrl_handler_free(&solo_enc->hdl); + vb2_dma_sg_cleanup_ctx(solo_enc->alloc_ctx); kfree(solo_enc); } @@ -1419,13 +1429,15 @@ int solo_enc_v4l2_init(struct solo_dev *solo_dev, unsigned nr) solo_dev->v4l2_enc[0]->vfd->num, solo_dev->v4l2_enc[solo_dev->nr_chans - 1]->vfd->num); - return 0; + return solo_ring_start(solo_dev); } void solo_enc_v4l2_exit(struct solo_dev *solo_dev) { int i; + solo_ring_stop(solo_dev); + for (i = 0; i < solo_dev->nr_chans; i++) solo_enc_free(solo_dev->v4l2_enc[i]); diff --git a/drivers/media/pci/solo6x10/solo6x10.h b/drivers/media/pci/solo6x10/solo6x10.h index 72017b7f0a7..bd8edfa319b 100644 --- a/drivers/media/pci/solo6x10/solo6x10.h +++ b/drivers/media/pci/solo6x10/solo6x10.h @@ -180,6 +180,7 @@ struct solo_enc_dev { u32 sequence; struct vb2_queue vidq; struct list_head vidq_active; + void *alloc_ctx; int desc_count; int desc_nelts; struct solo_p2m_desc *desc_items; diff --git a/drivers/media/pci/tw68/tw68-core.c b/drivers/media/pci/tw68/tw68-core.c index 63f0b64057c..c135165a8b2 100644 --- a/drivers/media/pci/tw68/tw68-core.c +++ b/drivers/media/pci/tw68/tw68-core.c @@ -304,13 +304,19 @@ static int tw68_initdev(struct pci_dev *pci_dev, /* Then do any initialisation wanted before interrupts are on */ tw68_hw_init1(dev); + dev->alloc_ctx = vb2_dma_sg_init_ctx(&pci_dev->dev); + if (IS_ERR(dev->alloc_ctx)) { + err = PTR_ERR(dev->alloc_ctx); + goto fail3; + } + /* get irq */ err = devm_request_irq(&pci_dev->dev, pci_dev->irq, tw68_irq, IRQF_SHARED, dev->name, dev); if (err < 0) { pr_err("%s: can't get IRQ %d\n", dev->name, pci_dev->irq); - goto fail3; + goto fail4; } /* @@ -324,7 +330,7 @@ static int tw68_initdev(struct pci_dev *pci_dev, if (err < 0) { pr_err("%s: can't register video device\n", dev->name); - goto fail4; + goto fail5; } tw_setl(TW68_INTMASK, dev->pci_irqmask); @@ -333,8 +339,10 @@ static int tw68_initdev(struct pci_dev *pci_dev, return 0; -fail4: +fail5: video_unregister_device(&dev->vdev); +fail4: + vb2_dma_sg_cleanup_ctx(dev->alloc_ctx); fail3: iounmap(dev->lmmio); fail2: @@ -358,6 +366,7 @@ static void tw68_finidev(struct pci_dev *pci_dev) /* unregister */ video_unregister_device(&dev->vdev); v4l2_ctrl_handler_free(&dev->hdl); + vb2_dma_sg_cleanup_ctx(dev->alloc_ctx); /* release resources */ iounmap(dev->lmmio); diff --git a/drivers/media/pci/tw68/tw68-video.c b/drivers/media/pci/tw68/tw68-video.c index 5c94ac7c88d..8355e55b4e8 100644 --- a/drivers/media/pci/tw68/tw68-video.c +++ b/drivers/media/pci/tw68/tw68-video.c @@ -384,6 +384,7 @@ static int tw68_queue_setup(struct vb2_queue *q, const struct v4l2_format *fmt, unsigned tot_bufs = q->num_buffers + *num_buffers; sizes[0] = (dev->fmt->depth * dev->width * dev->height) >> 3; + alloc_ctxs[0] = dev->alloc_ctx; /* * We allow create_bufs, but only if the sizeimage is the same as the * current sizeimage. The tw68_buffer_count calculation becomes quite @@ -461,17 +462,12 @@ static int tw68_buf_prepare(struct vb2_buffer *vb) struct tw68_buf *buf = container_of(vb, struct tw68_buf, vb); struct sg_table *dma = vb2_dma_sg_plane_desc(vb, 0); unsigned size, bpl; - int rc; size = (dev->width * dev->height * dev->fmt->depth) >> 3; if (vb2_plane_size(vb, 0) < size) return -EINVAL; vb2_set_plane_payload(vb, 0, size); - rc = dma_map_sg(&dev->pci->dev, dma->sgl, dma->nents, DMA_FROM_DEVICE); - if (!rc) - return -EIO; - bpl = (dev->width * dev->fmt->depth) >> 3; switch (dev->field) { case V4L2_FIELD_TOP: @@ -505,11 +501,8 @@ static void tw68_buf_finish(struct vb2_buffer *vb) { struct vb2_queue *vq = vb->vb2_queue; struct tw68_dev *dev = vb2_get_drv_priv(vq); - struct sg_table *dma = vb2_dma_sg_plane_desc(vb, 0); struct tw68_buf *buf = container_of(vb, struct tw68_buf, vb); - dma_unmap_sg(&dev->pci->dev, dma->sgl, dma->nents, DMA_FROM_DEVICE); - pci_free_consistent(dev->pci, buf->size, buf->cpu, buf->dma); } diff --git a/drivers/media/pci/tw68/tw68.h b/drivers/media/pci/tw68/tw68.h index 2c8abe26b13..7a7501bd165 100644 --- a/drivers/media/pci/tw68/tw68.h +++ b/drivers/media/pci/tw68/tw68.h @@ -181,6 +181,7 @@ struct tw68_dev { unsigned field; struct vb2_queue vidq; struct list_head active; + void *alloc_ctx; /* various v4l controls */ const struct tw68_tvnorm *tvnorm; /* video */ diff --git a/drivers/media/pci/zoran/zoran_driver.c b/drivers/media/pci/zoran/zoran_driver.c index 099d5fbebb7..2b25d31c46f 100644 --- a/drivers/media/pci/zoran/zoran_driver.c +++ b/drivers/media/pci/zoran/zoran_driver.c @@ -1528,8 +1528,9 @@ static int zoran_querycap(struct file *file, void *__fh, struct v4l2_capability strncpy(cap->driver, "zoran", sizeof(cap->driver)-1); snprintf(cap->bus_info, sizeof(cap->bus_info), "PCI:%s", pci_name(zr->pci_dev)); - cap->capabilities = V4L2_CAP_STREAMING | V4L2_CAP_VIDEO_CAPTURE | - V4L2_CAP_VIDEO_OUTPUT | V4L2_CAP_VIDEO_OVERLAY; + cap->device_caps = V4L2_CAP_STREAMING | V4L2_CAP_VIDEO_CAPTURE | + V4L2_CAP_VIDEO_OUTPUT | V4L2_CAP_VIDEO_OVERLAY; + cap->capabilities = cap->device_caps | V4L2_CAP_DEVICE_CAPS; return 0; } |