diff options
Diffstat (limited to 'drivers/media/pci')
31 files changed, 3044 insertions, 1803 deletions
diff --git a/drivers/media/pci/Kconfig b/drivers/media/pci/Kconfig index 480194543d05..ee095bde0b68 100644 --- a/drivers/media/pci/Kconfig +++ b/drivers/media/pci/Kconfig @@ -73,7 +73,7 @@ config VIDEO_PCI_SKELETON Enable build of the skeleton PCI driver, used as a reference when developing new drivers. -source "drivers/media/pci/intel/ipu3/Kconfig" +source "drivers/media/pci/intel/Kconfig" endif #MEDIA_PCI_SUPPORT endif #PCI diff --git a/drivers/media/pci/bt8xx/Kconfig b/drivers/media/pci/bt8xx/Kconfig index 2d674dc28cec..2f77628246e9 100644 --- a/drivers/media/pci/bt8xx/Kconfig +++ b/drivers/media/pci/bt8xx/Kconfig @@ -3,7 +3,7 @@ config VIDEO_BT848 tristate "BT848 Video For Linux" depends on PCI && I2C && VIDEO_DEV select I2C_ALGOBIT - select VIDEOBUF_DMA_SG + select VIDEOBUF2_DMA_SG depends on RC_CORE depends on MEDIA_RADIO_SUPPORT select VIDEO_TUNER diff --git a/drivers/media/pci/bt8xx/bt848.h b/drivers/media/pci/bt8xx/bt848.h index 16999e717d18..c8a0e1ab001f 100644 --- a/drivers/media/pci/bt8xx/bt848.h +++ b/drivers/media/pci/bt8xx/bt848.h @@ -231,7 +231,15 @@ #define BT848_INT_ETBF (1<<23) +#define BT848_RISC_VIDEO 1 +#define BT848_RISC_TOP 2 +#define BT848_RISC_VBI 4 + #define BT848_INT_RISCS (0xf<<28) +#define BT848_INT_RISCS_VIDEO (BT848_RISC_VIDEO << 28) +#define BT848_INT_RISCS_TOP (BT848_RISC_TOP << 28) +#define BT848_INT_RISCS_VBI (BT848_RISC_VBI << 28) + #define BT848_INT_RISC_EN (1<<27) #define BT848_INT_RACK (1<<25) #define BT848_INT_FIELD (1<<24) diff --git a/drivers/media/pci/bt8xx/bttv-audio-hook.c b/drivers/media/pci/bt8xx/bttv-audio-hook.c index da1914a20b81..b5d071835354 100644 --- a/drivers/media/pci/bt8xx/bttv-audio-hook.c +++ b/drivers/media/pci/bt8xx/bttv-audio-hook.c @@ -293,16 +293,8 @@ void winfast2000_audio(struct bttv *btv, struct v4l2_tuner *t, int set) { unsigned long val; - if (!set) { - /* Not much to do here */ - t->audmode = V4L2_TUNER_MODE_LANG1; - t->rxsubchans = V4L2_TUNER_SUB_MONO | - V4L2_TUNER_SUB_STEREO | - V4L2_TUNER_SUB_LANG1 | - V4L2_TUNER_SUB_LANG2; - + if (!set) return; - } /*btor (0xc32000, BT848_GPIO_OUT_EN);*/ switch (t->audmode) { diff --git a/drivers/media/pci/bt8xx/bttv-driver.c b/drivers/media/pci/bt8xx/bttv-driver.c index 734f02b91aa3..aa708a0e5eac 100644 --- a/drivers/media/pci/bt8xx/bttv-driver.c +++ b/drivers/media/pci/bt8xx/bttv-driver.c @@ -641,15 +641,10 @@ static const unsigned int FORMATS = ARRAY_SIZE(formats); #define VIDEO_RESOURCES (RESOURCE_VIDEO_READ | \ RESOURCE_VIDEO_STREAM) -static -int check_alloc_btres_lock(struct bttv *btv, struct bttv_fh *fh, int bit) +int check_alloc_btres_lock(struct bttv *btv, int bit) { int xbits; /* mutual exclusive resources */ - if (fh->resources & bit) - /* have it already allocated */ - return 1; - xbits = bit; if (bit & (RESOURCE_VIDEO_READ | RESOURCE_VIDEO_STREAM)) xbits |= RESOURCE_VIDEO_READ | RESOURCE_VIDEO_STREAM; @@ -663,7 +658,7 @@ int check_alloc_btres_lock(struct bttv *btv, struct bttv_fh *fh, int bit) if ((bit & VIDEO_RESOURCES) && 0 == (btv->resources & VIDEO_RESOURCES)) { /* Do crop - use current, don't - use default parameters. */ - __s32 top = btv->crop[!!fh->do_crop].rect.top; + __s32 top = btv->crop[!!btv->do_crop].rect.top; if (btv->vbi_end > top) goto fail; @@ -672,17 +667,16 @@ int check_alloc_btres_lock(struct bttv *btv, struct bttv_fh *fh, int bit) Claim scan lines crop[].rect.top to bottom. */ btv->crop_start = top; } else if (bit & VBI_RESOURCES) { - __s32 end = fh->vbi_fmt.end; + __s32 end = btv->vbi_fmt.end; if (end > btv->crop_start) goto fail; - /* Claim scan lines above fh->vbi_fmt.end. */ + /* Claim scan lines above btv->vbi_fmt.end. */ btv->vbi_end = end; } /* it's free, grab it */ - fh->resources |= bit; btv->resources |= bit; return 1; @@ -691,9 +685,9 @@ int check_alloc_btres_lock(struct bttv *btv, struct bttv_fh *fh, int bit) } static -int check_btres(struct bttv_fh *fh, int bit) +int check_btres(struct bttv *btv, int bit) { - return (fh->resources & bit); + return (btv->resources & bit); } static @@ -731,14 +725,12 @@ disclaim_video_lines(struct bttv *btv) btwrite(0xfe, BT848_O_VDELAY_LO); } -static -void free_btres_lock(struct bttv *btv, struct bttv_fh *fh, int bits) +void free_btres_lock(struct bttv *btv, int bits) { - if ((fh->resources & bits) != bits) { + if ((btv->resources & bits) != bits) { /* trying to free resources not allocated by us ... */ pr_err("BUG! (btres)\n"); } - fh->resources &= ~bits; btv->resources &= ~bits; bits = btv->resources; @@ -1111,8 +1103,8 @@ set_tvnorm(struct bttv *btv, unsigned int norm) const struct bttv_tvnorm *tvnorm; v4l2_std_id id; - BUG_ON(norm >= BTTV_TVNORMS); - BUG_ON(btv->tvnorm >= BTTV_TVNORMS); + WARN_ON(norm >= BTTV_TVNORMS); + WARN_ON(btv->tvnorm >= BTTV_TVNORMS); tvnorm = &bttv_tvnorms[norm]; @@ -1174,7 +1166,7 @@ set_input(struct bttv *btv, unsigned int input, unsigned int norm) set_tvnorm(btv, norm); } -static void init_irqreg(struct bttv *btv) +void init_irqreg(struct bttv *btv) { /* clear status */ btwrite(0xfffffUL, BT848_INT_STAT); @@ -1453,23 +1445,6 @@ void bttv_gpio_tracking(struct bttv *btv, char *comment) btv->c.nr, outbits, data & outbits, data & ~outbits, comment); } -static void bttv_field_count(struct bttv *btv) -{ - int need_count = 0; - - if (btv->users) - need_count++; - - if (need_count) { - /* start field counter */ - btor(BT848_INT_VSYNC,BT848_INT_MASK); - } else { - /* stop field counter */ - btand(~BT848_INT_VSYNC,BT848_INT_MASK); - btv->field_count = 0; - } -} - static const struct bttv_format* format_by_fourcc(int fourcc) { @@ -1487,158 +1462,132 @@ format_by_fourcc(int fourcc) /* ----------------------------------------------------------------------- */ /* video4linux (1) interface */ -static int bttv_prepare_buffer(struct videobuf_queue *q,struct bttv *btv, - struct bttv_buffer *buf, - const struct bttv_format *fmt, - unsigned int width, unsigned int height, - enum v4l2_field field) +static int queue_setup(struct vb2_queue *q, unsigned int *num_buffers, + unsigned int *num_planes, unsigned int sizes[], + struct device *alloc_devs[]) { - struct bttv_fh *fh = q->priv_data; - int redo_dma_risc = 0; - struct bttv_crop c; - int norm; - int rc; + struct bttv *btv = vb2_get_drv_priv(q); + unsigned int size = btv->fmt->depth * btv->width * btv->height >> 3; - /* check settings */ - if (NULL == fmt) - return -EINVAL; - if (fmt->btformat == BT848_COLOR_FMT_RAW) { - width = RAW_BPL; - height = RAW_LINES*2; - if (width*height > buf->vb.bsize) - return -EINVAL; - buf->vb.size = buf->vb.bsize; - - /* Make sure tvnorm and vbi_end remain consistent - until we're done. */ - - norm = btv->tvnorm; - - /* In this mode capturing always starts at defrect.top - (default VDELAY), ignoring cropping parameters. */ - if (btv->vbi_end > bttv_tvnorms[norm].cropcap.defrect.top) { - return -EINVAL; - } + if (*num_planes) + return sizes[0] < size ? -EINVAL : 0; + *num_planes = 1; + sizes[0] = size; - c.rect = bttv_tvnorms[norm].cropcap.defrect; - } else { - norm = btv->tvnorm; - c = btv->crop[!!fh->do_crop]; - - if (width < c.min_scaled_width || - width > c.max_scaled_width || - height < c.min_scaled_height) - return -EINVAL; - - switch (field) { - case V4L2_FIELD_TOP: - case V4L2_FIELD_BOTTOM: - case V4L2_FIELD_ALTERNATE: - /* btv->crop counts frame lines. Max. scale - factor is 16:1 for frames, 8:1 for fields. */ - if (height * 2 > c.max_scaled_height) - return -EINVAL; - break; + return 0; +} - default: - if (height > c.max_scaled_height) - return -EINVAL; - break; - } +static void buf_queue(struct vb2_buffer *vb) +{ + struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb); + struct vb2_queue *vq = vb->vb2_queue; + struct bttv *btv = vb2_get_drv_priv(vq); + struct bttv_buffer *buf = container_of(vbuf, struct bttv_buffer, vbuf); + unsigned long flags; - buf->vb.size = (width * height * fmt->depth) >> 3; - if (0 != buf->vb.baddr && buf->vb.bsize < buf->vb.size) - return -EINVAL; - } - - /* alloc + fill struct bttv_buffer (if changed) */ - if (buf->vb.width != width || buf->vb.height != height || - buf->vb.field != field || - buf->tvnorm != norm || buf->fmt != fmt || - buf->crop.top != c.rect.top || - buf->crop.left != c.rect.left || - buf->crop.width != c.rect.width || - buf->crop.height != c.rect.height) { - buf->vb.width = width; - buf->vb.height = height; - buf->vb.field = field; - buf->tvnorm = norm; - buf->fmt = fmt; - buf->crop = c.rect; - redo_dma_risc = 1; - } - - /* alloc risc memory */ - if (VIDEOBUF_NEEDS_INIT == buf->vb.state) { - redo_dma_risc = 1; - if (0 != (rc = videobuf_iolock(q,&buf->vb,&btv->fbuf))) - goto fail; + spin_lock_irqsave(&btv->s_lock, flags); + if (list_empty(&btv->capture)) { + btv->loop_irq = BT848_RISC_VIDEO; + if (vb2_is_streaming(&btv->vbiq)) + btv->loop_irq |= BT848_RISC_VBI; + bttv_set_dma(btv, BT848_CAP_CTL_CAPTURE_ODD | + BT848_CAP_CTL_CAPTURE_EVEN); } - - if (redo_dma_risc) - if (0 != (rc = bttv_buffer_risc(btv,buf))) - goto fail; - - buf->vb.state = VIDEOBUF_PREPARED; - return 0; - - fail: - bttv_dma_free(q,btv,buf); - return rc; + list_add_tail(&buf->list, &btv->capture); + spin_unlock_irqrestore(&btv->s_lock, flags); } -static int -buffer_setup(struct videobuf_queue *q, unsigned int *count, unsigned int *size) +static int buf_prepare(struct vb2_buffer *vb) { - struct bttv_fh *fh = q->priv_data; + struct vb2_queue *vq = vb->vb2_queue; + struct bttv *btv = vb2_get_drv_priv(vq); + struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb); + struct bttv_buffer *buf = container_of(vbuf, struct bttv_buffer, vbuf); + unsigned int size = (btv->fmt->depth * btv->width * btv->height) >> 3; - *size = fh->fmt->depth*fh->width*fh->height >> 3; - if (0 == *count) - *count = gbuffers; - if (*size * *count > gbuffers * gbufsize) - *count = (gbuffers * gbufsize) / *size; - return 0; + if (vb2_plane_size(vb, 0) < size) + return -EINVAL; + vb2_set_plane_payload(vb, 0, size); + + if (btv->field != V4L2_FIELD_ALTERNATE) { + buf->vbuf.field = btv->field; + } else if (btv->field_last == V4L2_FIELD_TOP) { + buf->vbuf.field = V4L2_FIELD_BOTTOM; + btv->field_last = V4L2_FIELD_BOTTOM; + } else { + buf->vbuf.field = V4L2_FIELD_TOP; + btv->field_last = V4L2_FIELD_TOP; + } + + /* Allocate memory for risc struct and create the risc program. */ + return bttv_buffer_risc(btv, buf); } -static int -buffer_prepare(struct videobuf_queue *q, struct videobuf_buffer *vb, - enum v4l2_field field) +static void buf_cleanup(struct vb2_buffer *vb) { - struct bttv_buffer *buf = container_of(vb,struct bttv_buffer,vb); - struct bttv_fh *fh = q->priv_data; + struct vb2_queue *vq = vb->vb2_queue; + struct bttv *btv = vb2_get_drv_priv(vq); + struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb); + struct bttv_buffer *buf = container_of(vbuf, struct bttv_buffer, vbuf); - return bttv_prepare_buffer(q,fh->btv, buf, fh->fmt, - fh->width, fh->height, field); + btcx_riscmem_free(btv->c.pci, &buf->top); + btcx_riscmem_free(btv->c.pci, &buf->bottom); } -static void -buffer_queue(struct videobuf_queue *q, struct videobuf_buffer *vb) +static int start_streaming(struct vb2_queue *q, unsigned int count) { - struct bttv_buffer *buf = container_of(vb,struct bttv_buffer,vb); - struct bttv_fh *fh = q->priv_data; - struct bttv *btv = fh->btv; - - buf->vb.state = VIDEOBUF_QUEUED; - list_add_tail(&buf->vb.queue,&btv->capture); - if (!btv->curr.frame_irq) { - btv->loop_irq |= 1; - bttv_set_dma(btv, 0x03); + int ret = 1; + int seqnr = 0; + struct bttv_buffer *buf; + struct bttv *btv = vb2_get_drv_priv(q); + + ret = check_alloc_btres_lock(btv, RESOURCE_VIDEO_STREAM); + if (ret == 0) { + if (btv->field_count) + seqnr++; + while (!list_empty(&btv->capture)) { + buf = list_entry(btv->capture.next, + struct bttv_buffer, list); + list_del(&buf->list); + buf->vbuf.sequence = (btv->field_count >> 1) + seqnr++; + vb2_buffer_done(&buf->vbuf.vb2_buf, + VB2_BUF_STATE_QUEUED); + } + return !ret; + } + if (!vb2_is_streaming(&btv->vbiq)) { + init_irqreg(btv); + btv->field_count = 0; } + btv->framedrop = 0; + + return 0; } -static void buffer_release(struct videobuf_queue *q, struct videobuf_buffer *vb) +static void stop_streaming(struct vb2_queue *q) { - struct bttv_buffer *buf = container_of(vb,struct bttv_buffer,vb); - struct bttv_fh *fh = q->priv_data; + unsigned long flags; + struct bttv *btv = vb2_get_drv_priv(q); - bttv_dma_free(q,fh->btv,buf); + vb2_wait_for_all_buffers(q); + spin_lock_irqsave(&btv->s_lock, flags); + free_btres_lock(btv, RESOURCE_VIDEO_STREAM); + if (!vb2_is_streaming(&btv->vbiq)) { + /* stop field counter */ + btand(~BT848_INT_VSYNC, BT848_INT_MASK); + } + spin_unlock_irqrestore(&btv->s_lock, flags); } -static const struct videobuf_queue_ops bttv_video_qops = { - .buf_setup = buffer_setup, - .buf_prepare = buffer_prepare, - .buf_queue = buffer_queue, - .buf_release = buffer_release, +static const struct vb2_ops bttv_video_qops = { + .queue_setup = queue_setup, + .buf_queue = buf_queue, + .buf_prepare = buf_prepare, + .buf_cleanup = buf_cleanup, + .start_streaming = start_streaming, + .stop_streaming = stop_streaming, + .wait_prepare = vb2_ops_wait_prepare, + .wait_finish = vb2_ops_wait_finish, }; static void radio_enable(struct bttv *btv) @@ -1654,8 +1603,7 @@ static void radio_enable(struct bttv *btv) static int bttv_s_std(struct file *file, void *priv, v4l2_std_id id) { - struct bttv_fh *fh = priv; - struct bttv *btv = fh->btv; + struct bttv *btv = video_drvdata(file); unsigned int i; for (i = 0; i < BTTV_TVNORMS; i++) @@ -1670,8 +1618,7 @@ static int bttv_s_std(struct file *file, void *priv, v4l2_std_id id) static int bttv_g_std(struct file *file, void *priv, v4l2_std_id *id) { - struct bttv_fh *fh = priv; - struct bttv *btv = fh->btv; + struct bttv *btv = video_drvdata(file); *id = btv->std; return 0; @@ -1679,8 +1626,7 @@ static int bttv_g_std(struct file *file, void *priv, v4l2_std_id *id) static int bttv_querystd(struct file *file, void *f, v4l2_std_id *id) { - struct bttv_fh *fh = f; - struct bttv *btv = fh->btv; + struct bttv *btv = video_drvdata(file); if (btread(BT848_DSTATUS) & BT848_DSTATUS_NUML) *id &= V4L2_STD_625_50; @@ -1692,8 +1638,7 @@ static int bttv_querystd(struct file *file, void *f, v4l2_std_id *id) static int bttv_enum_input(struct file *file, void *priv, struct v4l2_input *i) { - struct bttv_fh *fh = priv; - struct bttv *btv = fh->btv; + struct bttv *btv = video_drvdata(file); if (i->index >= bttv_tvcards[btv->c.type].video_inputs) return -EINVAL; @@ -1725,8 +1670,7 @@ static int bttv_enum_input(struct file *file, void *priv, static int bttv_g_input(struct file *file, void *priv, unsigned int *i) { - struct bttv_fh *fh = priv; - struct bttv *btv = fh->btv; + struct bttv *btv = video_drvdata(file); *i = btv->input; @@ -1735,8 +1679,7 @@ static int bttv_g_input(struct file *file, void *priv, unsigned int *i) static int bttv_s_input(struct file *file, void *priv, unsigned int i) { - struct bttv_fh *fh = priv; - struct bttv *btv = fh->btv; + struct bttv *btv = video_drvdata(file); if (i >= bttv_tvcards[btv->c.type].video_inputs) return -EINVAL; @@ -1748,8 +1691,7 @@ static int bttv_s_input(struct file *file, void *priv, unsigned int i) static int bttv_s_tuner(struct file *file, void *priv, const struct v4l2_tuner *t) { - struct bttv_fh *fh = priv; - struct bttv *btv = fh->btv; + struct bttv *btv = video_drvdata(file); if (t->index) return -EINVAL; @@ -1767,8 +1709,7 @@ static int bttv_s_tuner(struct file *file, void *priv, static int bttv_g_frequency(struct file *file, void *priv, struct v4l2_frequency *f) { - struct bttv_fh *fh = priv; - struct bttv *btv = fh->btv; + struct bttv *btv = video_drvdata(file); if (f->tuner) return -EINVAL; @@ -1804,8 +1745,7 @@ static void bttv_set_frequency(struct bttv *btv, const struct v4l2_frequency *f) static int bttv_s_frequency(struct file *file, void *priv, const struct v4l2_frequency *f) { - struct bttv_fh *fh = priv; - struct bttv *btv = fh->btv; + struct bttv *btv = video_drvdata(file); if (f->tuner) return -EINVAL; @@ -1817,8 +1757,7 @@ static int bttv_s_frequency(struct file *file, void *priv, static int bttv_log_status(struct file *file, void *f) { struct video_device *vdev = video_devdata(file); - struct bttv_fh *fh = f; - struct bttv *btv = fh->btv; + struct bttv *btv = video_drvdata(file); v4l2_ctrl_handler_log_status(vdev->ctrl_handler, btv->c.v4l2_dev.name); bttv_call_all(btv, core, log_status); @@ -1829,8 +1768,7 @@ static int bttv_log_status(struct file *file, void *f) static int bttv_g_register(struct file *file, void *f, struct v4l2_dbg_register *reg) { - struct bttv_fh *fh = f; - struct bttv *btv = fh->btv; + struct bttv *btv = video_drvdata(file); /* bt848 has a 12-bit register space */ reg->reg &= 0xfff; @@ -1843,8 +1781,7 @@ static int bttv_g_register(struct file *file, void *f, static int bttv_s_register(struct file *file, void *f, const struct v4l2_dbg_register *reg) { - struct bttv_fh *fh = f; - struct bttv *btv = fh->btv; + struct bttv *btv = video_drvdata(file); /* bt848 has a 12-bit register space */ btwrite(reg->val, reg->reg & 0xfff); @@ -1904,16 +1841,11 @@ bttv_crop_adjust (struct bttv_crop * c, also adjust the current cropping parameters to get closer to the desired image size. */ static int -limit_scaled_size_lock (struct bttv_fh * fh, - __s32 * width, - __s32 * height, - enum v4l2_field field, - unsigned int width_mask, - unsigned int width_bias, - int adjust_size, - int adjust_crop) -{ - struct bttv *btv = fh->btv; +limit_scaled_size_lock(struct bttv *btv, __s32 *width, __s32 *height, + enum v4l2_field field, unsigned int width_mask, + unsigned int width_bias, int adjust_size, + int adjust_crop) +{ const struct v4l2_rect *b; struct bttv_crop *c; __s32 min_width; @@ -1922,8 +1854,8 @@ limit_scaled_size_lock (struct bttv_fh * fh, __s32 max_height; int rc; - BUG_ON((int) width_mask >= 0 || - width_bias >= (unsigned int) -width_mask); + WARN_ON((int)width_mask >= 0 || + width_bias >= (unsigned int)(-width_mask)); /* Make sure tvnorm, vbi_end and the current cropping parameters remain consistent until we're done. */ @@ -1931,9 +1863,9 @@ limit_scaled_size_lock (struct bttv_fh * fh, b = &bttv_tvnorms[btv->tvnorm].cropcap.bounds; /* Do crop - use current, don't - use default parameters. */ - c = &btv->crop[!!fh->do_crop]; + c = &btv->crop[!!btv->do_crop]; - if (fh->do_crop + if (btv->do_crop && adjust_size && adjust_crop && !locked_btres(btv, VIDEO_RESOURCES)) { @@ -2007,52 +1939,31 @@ limit_scaled_size_lock (struct bttv_fh * fh, return rc; } -/* ----------------------------------------------------------------------- */ - -static struct videobuf_queue* bttv_queue(struct bttv_fh *fh) -{ - struct videobuf_queue* q = NULL; - - switch (fh->type) { - case V4L2_BUF_TYPE_VIDEO_CAPTURE: - q = &fh->cap; - break; - case V4L2_BUF_TYPE_VBI_CAPTURE: - q = &fh->vbi; - break; - default: - BUG(); - } - return q; -} - -static int bttv_resource(struct bttv_fh *fh) +static int bttv_switch_type(struct bttv *btv, enum v4l2_buf_type type) { - int res = 0; + int res; + struct vb2_queue *q; - switch (fh->type) { + switch (type) { case V4L2_BUF_TYPE_VIDEO_CAPTURE: + q = &btv->capq; res = RESOURCE_VIDEO_STREAM; break; case V4L2_BUF_TYPE_VBI_CAPTURE: + q = &btv->vbiq; res = RESOURCE_VBI; break; default: - BUG(); + WARN_ON(1); + return -EINVAL; } - return res; -} - -static int bttv_switch_type(struct bttv_fh *fh, enum v4l2_buf_type type) -{ - struct videobuf_queue *q = bttv_queue(fh); - int res = bttv_resource(fh); - if (check_btres(fh,res)) + if (check_btres(btv, res)) return -EBUSY; - if (videobuf_queue_is_busy(q)) + if (vb2_is_busy(q)) return -EBUSY; - fh->type = type; + btv->type = type; + return 0; } @@ -2077,12 +1988,11 @@ pix_format_set_size (struct v4l2_pix_format * f, static int bttv_g_fmt_vid_cap(struct file *file, void *priv, struct v4l2_format *f) { - struct bttv_fh *fh = priv; + struct bttv *btv = video_drvdata(file); - pix_format_set_size(&f->fmt.pix, fh->fmt, - fh->width, fh->height); - f->fmt.pix.field = fh->cap.field; - f->fmt.pix.pixelformat = fh->fmt->fourcc; + pix_format_set_size(&f->fmt.pix, btv->fmt, btv->width, btv->height); + f->fmt.pix.field = btv->field; + f->fmt.pix.pixelformat = btv->fmt->fourcc; f->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M; return 0; @@ -2105,8 +2015,7 @@ static int bttv_try_fmt_vid_cap(struct file *file, void *priv, struct v4l2_format *f) { const struct bttv_format *fmt; - struct bttv_fh *fh = priv; - struct bttv *btv = fh->btv; + struct bttv *btv = video_drvdata(file); enum v4l2_field field; __s32 width, height; __s32 height2; @@ -2133,7 +2042,7 @@ static int bttv_try_fmt_vid_cap(struct file *file, void *priv, } fallthrough; default: /* FIELD_ANY case */ - height2 = btv->crop[!!fh->do_crop].rect.height >> 1; + height2 = btv->crop[!!btv->do_crop].rect.height >> 1; field = (f->fmt.pix.height > height2) ? V4L2_FIELD_INTERLACED : V4L2_FIELD_BOTTOM; @@ -2144,10 +2053,8 @@ static int bttv_try_fmt_vid_cap(struct file *file, void *priv, height = f->fmt.pix.height; bttv_get_width_mask_vid_cap(fmt, &width_mask, &width_bias); - rc = limit_scaled_size_lock(fh, &width, &height, field, - width_mask, width_bias, - /* adjust_size */ 1, - /* adjust_crop */ 0); + rc = limit_scaled_size_lock(btv, &width, &height, field, width_mask, + width_bias, 1, 0); if (0 != rc) return rc; @@ -2160,17 +2067,16 @@ static int bttv_try_fmt_vid_cap(struct file *file, void *priv, } static int bttv_s_fmt_vid_cap(struct file *file, void *priv, - struct v4l2_format *f) + struct v4l2_format *f) { int retval; const struct bttv_format *fmt; - struct bttv_fh *fh = priv; - struct bttv *btv = fh->btv; + struct bttv *btv = video_drvdata(file); __s32 width, height; unsigned int width_mask, width_bias; enum v4l2_field field; - retval = bttv_switch_type(fh, f->type); + retval = bttv_switch_type(btv, f->type); if (0 != retval) return retval; @@ -2184,24 +2090,25 @@ static int bttv_s_fmt_vid_cap(struct file *file, void *priv, fmt = format_by_fourcc(f->fmt.pix.pixelformat); bttv_get_width_mask_vid_cap(fmt, &width_mask, &width_bias); - retval = limit_scaled_size_lock(fh, &width, &height, f->fmt.pix.field, - width_mask, width_bias, - /* adjust_size */ 1, - /* adjust_crop */ 1); + retval = limit_scaled_size_lock(btv, &width, &height, f->fmt.pix.field, + width_mask, width_bias, 1, 1); if (0 != retval) return retval; f->fmt.pix.field = field; /* update our state information */ - fh->fmt = fmt; - fh->cap.field = f->fmt.pix.field; - fh->cap.last = V4L2_FIELD_NONE; - fh->width = f->fmt.pix.width; - fh->height = f->fmt.pix.height; - btv->init.fmt = fmt; - btv->init.width = f->fmt.pix.width; - btv->init.height = f->fmt.pix.height; + btv->fmt = fmt; + btv->width = f->fmt.pix.width; + btv->height = f->fmt.pix.height; + btv->field = f->fmt.pix.field; + /* + * When field is V4L2_FIELD_ALTERNATE, buffers will be either + * V4L2_FIELD_TOP or V4L2_FIELD_BOTTOM depending on the value of + * field_last. Initialize field_last to V4L2_FIELD_BOTTOM so that + * streaming starts with a V4L2_FIELD_TOP buffer. + */ + btv->field_last = V4L2_FIELD_BOTTOM; return 0; } @@ -2209,8 +2116,7 @@ static int bttv_s_fmt_vid_cap(struct file *file, void *priv, static int bttv_querycap(struct file *file, void *priv, struct v4l2_capability *cap) { - struct bttv_fh *fh = priv; - struct bttv *btv = fh->btv; + struct bttv *btv = video_drvdata(file); if (0 == v4l2) return -EINVAL; @@ -2257,73 +2163,10 @@ static int bttv_enum_fmt_vid_cap(struct file *file, void *priv, return 0; } -static int bttv_reqbufs(struct file *file, void *priv, - struct v4l2_requestbuffers *p) -{ - struct bttv_fh *fh = priv; - return videobuf_reqbufs(bttv_queue(fh), p); -} - -static int bttv_querybuf(struct file *file, void *priv, - struct v4l2_buffer *b) -{ - struct bttv_fh *fh = priv; - return videobuf_querybuf(bttv_queue(fh), b); -} - -static int bttv_qbuf(struct file *file, void *priv, struct v4l2_buffer *b) -{ - struct bttv_fh *fh = priv; - struct bttv *btv = fh->btv; - int res = bttv_resource(fh); - - if (!check_alloc_btres_lock(btv, fh, res)) - return -EBUSY; - - return videobuf_qbuf(bttv_queue(fh), b); -} - -static int bttv_dqbuf(struct file *file, void *priv, struct v4l2_buffer *b) -{ - struct bttv_fh *fh = priv; - return videobuf_dqbuf(bttv_queue(fh), b, - file->f_flags & O_NONBLOCK); -} - -static int bttv_streamon(struct file *file, void *priv, - enum v4l2_buf_type type) -{ - struct bttv_fh *fh = priv; - struct bttv *btv = fh->btv; - int res = bttv_resource(fh); - - if (!check_alloc_btres_lock(btv, fh, res)) - return -EBUSY; - return videobuf_streamon(bttv_queue(fh)); -} - - -static int bttv_streamoff(struct file *file, void *priv, - enum v4l2_buf_type type) -{ - struct bttv_fh *fh = priv; - struct bttv *btv = fh->btv; - int retval; - int res = bttv_resource(fh); - - - retval = videobuf_streamoff(bttv_queue(fh)); - if (retval < 0) - return retval; - free_btres_lock(btv, fh, res); - return 0; -} - static int bttv_g_parm(struct file *file, void *f, struct v4l2_streamparm *parm) { - struct bttv_fh *fh = f; - struct bttv *btv = fh->btv; + struct bttv *btv = video_drvdata(file); if (parm->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) return -EINVAL; @@ -2337,8 +2180,7 @@ static int bttv_g_parm(struct file *file, void *f, static int bttv_g_tuner(struct file *file, void *priv, struct v4l2_tuner *t) { - struct bttv_fh *fh = priv; - struct bttv *btv = fh->btv; + struct bttv *btv = video_drvdata(file); if (0 != t->index) return -EINVAL; @@ -2360,8 +2202,7 @@ static int bttv_g_tuner(struct file *file, void *priv, static int bttv_g_pixelaspect(struct file *file, void *priv, int type, struct v4l2_fract *f) { - struct bttv_fh *fh = priv; - struct bttv *btv = fh->btv; + struct bttv *btv = video_drvdata(file); if (type != V4L2_BUF_TYPE_VIDEO_CAPTURE) return -EINVAL; @@ -2373,20 +2214,14 @@ static int bttv_g_pixelaspect(struct file *file, void *priv, static int bttv_g_selection(struct file *file, void *f, struct v4l2_selection *sel) { - struct bttv_fh *fh = f; - struct bttv *btv = fh->btv; + struct bttv *btv = video_drvdata(file); if (sel->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) return -EINVAL; switch (sel->target) { case V4L2_SEL_TGT_CROP: - /* - * No fh->do_crop = 1; because btv->crop[1] may be - * inconsistent with fh->width or fh->height and apps - * do not expect a change here. - */ - sel->r = btv->crop[!!fh->do_crop].rect; + sel->r = btv->crop[!!btv->do_crop].rect; break; case V4L2_SEL_TGT_CROP_DEFAULT: sel->r = bttv_tvnorms[btv->tvnorm].cropcap.defrect; @@ -2403,8 +2238,7 @@ static int bttv_g_selection(struct file *file, void *f, struct v4l2_selection *s static int bttv_s_selection(struct file *file, void *f, struct v4l2_selection *sel) { - struct bttv_fh *fh = f; - struct bttv *btv = fh->btv; + struct bttv *btv = video_drvdata(file); const struct v4l2_rect *b; int retval; struct bttv_crop c; @@ -2424,9 +2258,8 @@ static int bttv_s_selection(struct file *file, void *f, struct v4l2_selection *s read() may change vbi_end in check_alloc_btres_lock(). */ retval = -EBUSY; - if (locked_btres(fh->btv, VIDEO_RESOURCES)) { + if (locked_btres(btv, VIDEO_RESOURCES)) return retval; - } b = &bttv_tvnorms[btv->tvnorm].cropcap.bounds; @@ -2460,249 +2293,30 @@ static int bttv_s_selection(struct file *file, void *f, struct v4l2_selection *s btv->crop[1] = c; - fh->do_crop = 1; - - if (fh->width < c.min_scaled_width) { - fh->width = c.min_scaled_width; - btv->init.width = c.min_scaled_width; - } else if (fh->width > c.max_scaled_width) { - fh->width = c.max_scaled_width; - btv->init.width = c.max_scaled_width; - } - - if (fh->height < c.min_scaled_height) { - fh->height = c.min_scaled_height; - btv->init.height = c.min_scaled_height; - } else if (fh->height > c.max_scaled_height) { - fh->height = c.max_scaled_height; - btv->init.height = c.max_scaled_height; - } - - return 0; -} - -static ssize_t bttv_read(struct file *file, char __user *data, - size_t count, loff_t *ppos) -{ - struct bttv_fh *fh = file->private_data; - int retval = 0; - - if (fh->btv->errors) - bttv_reinit_bt848(fh->btv); - dprintk("%d: read count=%d type=%s\n", - fh->btv->c.nr, (int)count, v4l2_type_names[fh->type]); - - switch (fh->type) { - case V4L2_BUF_TYPE_VIDEO_CAPTURE: - if (!check_alloc_btres_lock(fh->btv, fh, RESOURCE_VIDEO_READ)) { - /* VIDEO_READ in use by another fh, - or VIDEO_STREAM by any fh. */ - return -EBUSY; - } - retval = videobuf_read_one(&fh->cap, data, count, ppos, - file->f_flags & O_NONBLOCK); - free_btres_lock(fh->btv, fh, RESOURCE_VIDEO_READ); - break; - case V4L2_BUF_TYPE_VBI_CAPTURE: - if (!check_alloc_btres_lock(fh->btv,fh,RESOURCE_VBI)) - return -EBUSY; - retval = videobuf_read_stream(&fh->vbi, data, count, ppos, 1, - file->f_flags & O_NONBLOCK); - break; - default: - BUG(); - } - return retval; -} - -static __poll_t bttv_poll(struct file *file, poll_table *wait) -{ - struct bttv_fh *fh = file->private_data; - struct bttv_buffer *buf; - enum v4l2_field field; - __poll_t rc = 0; - __poll_t req_events = poll_requested_events(wait); - - if (v4l2_event_pending(&fh->fh)) - rc = EPOLLPRI; - else if (req_events & EPOLLPRI) - poll_wait(file, &fh->fh.wait, wait); - - if (!(req_events & (EPOLLIN | EPOLLRDNORM))) - return rc; - - if (V4L2_BUF_TYPE_VBI_CAPTURE == fh->type) { - if (!check_alloc_btres_lock(fh->btv,fh,RESOURCE_VBI)) - return rc | EPOLLERR; - return rc | videobuf_poll_stream(file, &fh->vbi, wait); - } - - if (check_btres(fh,RESOURCE_VIDEO_STREAM)) { - /* streaming capture */ - if (list_empty(&fh->cap.stream)) - return rc | EPOLLERR; - buf = list_entry(fh->cap.stream.next,struct bttv_buffer,vb.stream); - } else { - /* read() capture */ - if (NULL == fh->cap.read_buf) { - /* need to capture a new frame */ - if (locked_btres(fh->btv,RESOURCE_VIDEO_STREAM)) - return rc | EPOLLERR; - fh->cap.read_buf = videobuf_sg_alloc(fh->cap.msize); - if (NULL == fh->cap.read_buf) - return rc | EPOLLERR; - fh->cap.read_buf->memory = V4L2_MEMORY_USERPTR; - field = videobuf_next_field(&fh->cap); - if (0 != fh->cap.ops->buf_prepare(&fh->cap,fh->cap.read_buf,field)) { - kfree (fh->cap.read_buf); - fh->cap.read_buf = NULL; - return rc | EPOLLERR; - } - fh->cap.ops->buf_queue(&fh->cap,fh->cap.read_buf); - fh->cap.read_off = 0; - } - buf = (struct bttv_buffer*)fh->cap.read_buf; - } - - poll_wait(file, &buf->vb.done, wait); - if (buf->vb.state == VIDEOBUF_DONE || - buf->vb.state == VIDEOBUF_ERROR) - rc = rc | EPOLLIN|EPOLLRDNORM; - return rc; -} - -static int bttv_open(struct file *file) -{ - struct video_device *vdev = video_devdata(file); - struct bttv *btv = video_drvdata(file); - struct bttv_fh *fh; - enum v4l2_buf_type type = 0; - - dprintk("open dev=%s\n", video_device_node_name(vdev)); - - if (vdev->vfl_type == VFL_TYPE_VIDEO) { - type = V4L2_BUF_TYPE_VIDEO_CAPTURE; - } else if (vdev->vfl_type == VFL_TYPE_VBI) { - type = V4L2_BUF_TYPE_VBI_CAPTURE; - } else { - WARN_ON(1); - return -ENODEV; - } - - dprintk("%d: open called (type=%s)\n", - btv->c.nr, v4l2_type_names[type]); - - /* allocate per filehandle data */ - fh = kmalloc(sizeof(*fh), GFP_KERNEL); - if (unlikely(!fh)) - return -ENOMEM; - btv->users++; - file->private_data = fh; - - *fh = btv->init; - v4l2_fh_init(&fh->fh, vdev); - - fh->type = type; - - videobuf_queue_sg_init(&fh->cap, &bttv_video_qops, - &btv->c.pci->dev, &btv->s_lock, - V4L2_BUF_TYPE_VIDEO_CAPTURE, - V4L2_FIELD_INTERLACED, - sizeof(struct bttv_buffer), - fh, &btv->lock); - videobuf_queue_sg_init(&fh->vbi, &bttv_vbi_qops, - &btv->c.pci->dev, &btv->s_lock, - V4L2_BUF_TYPE_VBI_CAPTURE, - V4L2_FIELD_SEQ_TB, - sizeof(struct bttv_buffer), - fh, &btv->lock); - set_tvnorm(btv,btv->tvnorm); - set_input(btv, btv->input, btv->tvnorm); - audio_mute(btv, btv->mute); - - /* The V4L2 spec requires one global set of cropping parameters - which only change on request. These are stored in btv->crop[1]. - However for compatibility with V4L apps and cropping unaware - V4L2 apps we now reset the cropping parameters as seen through - this fh, which is to say VIDIOC_G_SELECTION and scaling limit checks - will use btv->crop[0], the default cropping parameters for the - current video standard, and VIDIOC_S_FMT will not implicitly - change the cropping parameters until VIDIOC_S_SELECTION has been - called. */ - fh->do_crop = !reset_crop; /* module parameter */ - - /* Likewise there should be one global set of VBI capture - parameters, but for compatibility with V4L apps and earlier - driver versions each fh has its own parameters. */ - bttv_vbi_fmt_reset(&fh->vbi_fmt, btv->tvnorm); - - bttv_field_count(btv); - v4l2_fh_add(&fh->fh); - return 0; -} - -static int bttv_release(struct file *file) -{ - struct bttv_fh *fh = file->private_data; - struct bttv *btv = fh->btv; - - /* stop video capture */ - if (check_btres(fh, RESOURCE_VIDEO_STREAM)) { - videobuf_streamoff(&fh->cap); - free_btres_lock(btv,fh,RESOURCE_VIDEO_STREAM); - } - if (fh->cap.read_buf) { - buffer_release(&fh->cap,fh->cap.read_buf); - kfree(fh->cap.read_buf); - } - if (check_btres(fh, RESOURCE_VIDEO_READ)) { - free_btres_lock(btv, fh, RESOURCE_VIDEO_READ); - } - - /* stop vbi capture */ - if (check_btres(fh, RESOURCE_VBI)) { - videobuf_stop(&fh->vbi); - free_btres_lock(btv,fh,RESOURCE_VBI); - } - - /* free stuff */ + btv->do_crop = 1; - videobuf_mmap_free(&fh->cap); - videobuf_mmap_free(&fh->vbi); - file->private_data = NULL; + if (btv->width < c.min_scaled_width) + btv->width = c.min_scaled_width; + else if (btv->width > c.max_scaled_width) + btv->width = c.max_scaled_width; - btv->users--; - bttv_field_count(btv); + if (btv->height < c.min_scaled_height) + btv->height = c.min_scaled_height; + else if (btv->height > c.max_scaled_height) + btv->height = c.max_scaled_height; - if (!btv->users) - audio_mute(btv, btv->mute); - - v4l2_fh_del(&fh->fh); - v4l2_fh_exit(&fh->fh); - kfree(fh); return 0; } -static int -bttv_mmap(struct file *file, struct vm_area_struct *vma) -{ - struct bttv_fh *fh = file->private_data; - - dprintk("%d: mmap type=%s 0x%lx+%ld\n", - fh->btv->c.nr, v4l2_type_names[fh->type], - vma->vm_start, vma->vm_end - vma->vm_start); - return videobuf_mmap_mapper(bttv_queue(fh),vma); -} - static const struct v4l2_file_operations bttv_fops = { .owner = THIS_MODULE, - .open = bttv_open, - .release = bttv_release, + .open = v4l2_fh_open, + .release = vb2_fop_release, .unlocked_ioctl = video_ioctl2, - .read = bttv_read, - .mmap = bttv_mmap, - .poll = bttv_poll, + .read = vb2_fop_read, + .mmap = vb2_fop_mmap, + .poll = vb2_fop_poll, }; static const struct v4l2_ioctl_ops bttv_ioctl_ops = { @@ -2715,17 +2329,18 @@ static const struct v4l2_ioctl_ops bttv_ioctl_ops = { .vidioc_try_fmt_vbi_cap = bttv_try_fmt_vbi_cap, .vidioc_s_fmt_vbi_cap = bttv_s_fmt_vbi_cap, .vidioc_g_pixelaspect = bttv_g_pixelaspect, - .vidioc_reqbufs = bttv_reqbufs, - .vidioc_querybuf = bttv_querybuf, - .vidioc_qbuf = bttv_qbuf, - .vidioc_dqbuf = bttv_dqbuf, + .vidioc_reqbufs = vb2_ioctl_reqbufs, + .vidioc_create_bufs = vb2_ioctl_create_bufs, + .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_std = bttv_s_std, .vidioc_g_std = bttv_g_std, .vidioc_enum_input = bttv_enum_input, .vidioc_g_input = bttv_g_input, .vidioc_s_input = bttv_s_input, - .vidioc_streamon = bttv_streamon, - .vidioc_streamoff = bttv_streamoff, .vidioc_g_tuner = bttv_g_tuner, .vidioc_s_tuner = bttv_s_tuner, .vidioc_g_selection = bttv_g_selection, @@ -2756,52 +2371,40 @@ static int radio_open(struct file *file) { struct video_device *vdev = video_devdata(file); struct bttv *btv = video_drvdata(file); - struct bttv_fh *fh; + int ret = v4l2_fh_open(file); - dprintk("open dev=%s\n", video_device_node_name(vdev)); + if (ret) + return ret; + dprintk("open dev=%s\n", video_device_node_name(vdev)); dprintk("%d: open called (radio)\n", btv->c.nr); - /* allocate per filehandle data */ - fh = kmalloc(sizeof(*fh), GFP_KERNEL); - if (unlikely(!fh)) - return -ENOMEM; - file->private_data = fh; - *fh = btv->init; - v4l2_fh_init(&fh->fh, vdev); - btv->radio_user++; audio_mute(btv, btv->mute); - v4l2_fh_add(&fh->fh); - return 0; } static int radio_release(struct file *file) { - struct bttv_fh *fh = file->private_data; - struct bttv *btv = fh->btv; + struct bttv *btv = video_drvdata(file); struct saa6588_command cmd; - file->private_data = NULL; - v4l2_fh_del(&fh->fh); - v4l2_fh_exit(&fh->fh); - kfree(fh); - btv->radio_user--; bttv_call_all(btv, core, command, SAA6588_CMD_CLOSE, &cmd); if (btv->radio_user == 0) btv->has_radio_tuner = 0; + + v4l2_fh_release(file); + return 0; } static int radio_g_tuner(struct file *file, void *priv, struct v4l2_tuner *t) { - struct bttv_fh *fh = priv; - struct bttv *btv = fh->btv; + struct bttv *btv = video_drvdata(file); if (0 != t->index) return -EINVAL; @@ -2823,8 +2426,7 @@ static int radio_g_tuner(struct file *file, void *priv, struct v4l2_tuner *t) static int radio_s_tuner(struct file *file, void *priv, const struct v4l2_tuner *t) { - struct bttv_fh *fh = priv; - struct bttv *btv = fh->btv; + struct bttv *btv = video_drvdata(file); if (0 != t->index) return -EINVAL; @@ -2837,8 +2439,7 @@ static int radio_s_tuner(struct file *file, void *priv, static int radio_s_hw_freq_seek(struct file *file, void *priv, const struct v4l2_hw_freq_seek *a) { - struct bttv_fh *fh = priv; - struct bttv *btv = fh->btv; + struct bttv *btv = video_drvdata(file); if (btv->has_tea575x) return snd_tea575x_s_hw_freq_seek(file, &btv->tea, a); @@ -2849,8 +2450,7 @@ static int radio_s_hw_freq_seek(struct file *file, void *priv, static int radio_enum_freq_bands(struct file *file, void *priv, struct v4l2_frequency_band *band) { - struct bttv_fh *fh = priv; - struct bttv *btv = fh->btv; + struct bttv *btv = video_drvdata(file); if (btv->has_tea575x) return snd_tea575x_enum_freq_bands(&btv->tea, band); @@ -2861,8 +2461,7 @@ static int radio_enum_freq_bands(struct file *file, void *priv, static ssize_t radio_read(struct file *file, char __user *data, size_t count, loff_t *ppos) { - struct bttv_fh *fh = file->private_data; - struct bttv *btv = fh->btv; + struct bttv *btv = video_drvdata(file); struct saa6588_command cmd; cmd.block_count = count / 3; @@ -2879,23 +2478,17 @@ static ssize_t radio_read(struct file *file, char __user *data, static __poll_t radio_poll(struct file *file, poll_table *wait) { - struct bttv_fh *fh = file->private_data; - struct bttv *btv = fh->btv; - __poll_t req_events = poll_requested_events(wait); + struct bttv *btv = video_drvdata(file); struct saa6588_command cmd; - __poll_t res = 0; + __poll_t rc = v4l2_ctrl_poll(file, wait); - if (v4l2_event_pending(&fh->fh)) - res = EPOLLPRI; - else if (req_events & EPOLLPRI) - poll_wait(file, &fh->fh.wait, wait); radio_enable(btv); cmd.instance = file; cmd.event_list = wait; - cmd.poll_mask = res; + cmd.poll_mask = 0; bttv_call_all(btv, core, command, SAA6588_CMD_POLL, &cmd); - return cmd.poll_mask; + return rc | cmd.poll_mask; } static const struct v4l2_file_operations radio_fops = @@ -3070,17 +2663,19 @@ bttv_irq_next_video(struct bttv *btv, struct bttv_buffer_set *set) /* capture request ? */ if (!list_empty(&btv->capture)) { - set->frame_irq = 1; - item = list_entry(btv->capture.next, struct bttv_buffer, vb.queue); - if (V4L2_FIELD_HAS_TOP(item->vb.field)) + set->frame_irq = BT848_RISC_VIDEO; + item = list_entry(btv->capture.next, struct bttv_buffer, list); + + if (V4L2_FIELD_HAS_TOP(item->vbuf.field)) set->top = item; - if (V4L2_FIELD_HAS_BOTTOM(item->vb.field)) + if (V4L2_FIELD_HAS_BOTTOM(item->vbuf.field)) set->bottom = item; /* capture request for other field ? */ - if (!V4L2_FIELD_HAS_BOTH(item->vb.field) && - (item->vb.queue.next != &btv->capture)) { - item = list_entry(item->vb.queue.next, struct bttv_buffer, vb.queue); + if (!V4L2_FIELD_HAS_BOTH(item->vbuf.field) && + item->list.next != &btv->capture) { + item = list_entry(item->list.next, + struct bttv_buffer, list); /* Mike Isely <isely@pobox.com> - Only check * and set up the bottom field in the logic * below. Don't ever do the top field. This @@ -3108,13 +2703,18 @@ bttv_irq_next_video(struct bttv *btv, struct bttv_buffer_set *set) * sync within a single frame time. (Out of * order fields can screw up deinterlacing * algorithms.) */ - if (!V4L2_FIELD_HAS_BOTH(item->vb.field)) { - if (NULL == set->bottom && - V4L2_FIELD_BOTTOM == item->vb.field) { + if (!V4L2_FIELD_HAS_BOTH(item->vbuf.field)) { + if (!set->bottom && + item->vbuf.field == V4L2_FIELD_BOTTOM) set->bottom = item; + if (set->top && set->bottom) { + /* + * The buffer set has a top buffer and + * a bottom buffer and they are not + * copies of each other. + */ + set->top_irq = BT848_RISC_TOP; } - if (NULL != set->top && NULL != set->bottom) - set->top_irq = 2; } } } @@ -3136,44 +2736,47 @@ bttv_irq_wakeup_video(struct bttv *btv, struct bttv_buffer_set *wakeup, if (irq_debug > 1) pr_debug("%d: wakeup: both=%p\n", btv->c.nr, wakeup->top); - wakeup->top->vb.ts = ts; - wakeup->top->vb.field_count = btv->field_count; - wakeup->top->vb.state = state; - wake_up(&wakeup->top->vb.done); + wakeup->top->vbuf.vb2_buf.timestamp = ts; + wakeup->top->vbuf.sequence = btv->field_count >> 1; + vb2_buffer_done(&wakeup->top->vbuf.vb2_buf, state); + if (btv->field_count == 0) + btor(BT848_INT_VSYNC, BT848_INT_MASK); } } else { if (NULL != wakeup->top && curr->top != wakeup->top) { if (irq_debug > 1) pr_debug("%d: wakeup: top=%p\n", btv->c.nr, wakeup->top); - wakeup->top->vb.ts = ts; - wakeup->top->vb.field_count = btv->field_count; - wakeup->top->vb.state = state; - wake_up(&wakeup->top->vb.done); + wakeup->top->vbuf.vb2_buf.timestamp = ts; + wakeup->top->vbuf.sequence = btv->field_count >> 1; + vb2_buffer_done(&wakeup->top->vbuf.vb2_buf, state); + if (btv->field_count == 0) + btor(BT848_INT_VSYNC, BT848_INT_MASK); } if (NULL != wakeup->bottom && curr->bottom != wakeup->bottom) { if (irq_debug > 1) pr_debug("%d: wakeup: bottom=%p\n", btv->c.nr, wakeup->bottom); - wakeup->bottom->vb.ts = ts; - wakeup->bottom->vb.field_count = btv->field_count; - wakeup->bottom->vb.state = state; - wake_up(&wakeup->bottom->vb.done); + wakeup->bottom->vbuf.vb2_buf.timestamp = ts; + wakeup->bottom->vbuf.sequence = btv->field_count >> 1; + vb2_buffer_done(&wakeup->bottom->vbuf.vb2_buf, state); + if (btv->field_count == 0) + btor(BT848_INT_VSYNC, BT848_INT_MASK); } } } static void bttv_irq_wakeup_vbi(struct bttv *btv, struct bttv_buffer *wakeup, - unsigned int state) + unsigned int state) { if (NULL == wakeup) return; - - wakeup->vb.ts = ktime_get_ns(); - wakeup->vb.field_count = btv->field_count; - wakeup->vb.state = state; - wake_up(&wakeup->vb.done); + wakeup->vbuf.vb2_buf.timestamp = ktime_get_ns(); + wakeup->vbuf.sequence = btv->field_count >> 1; + vb2_buffer_done(&wakeup->vbuf.vb2_buf, state); + if (btv->field_count == 0) + btor(BT848_INT_VSYNC, BT848_INT_MASK); } static void bttv_irq_timeout(struct timer_list *t) @@ -3183,6 +2786,7 @@ static void bttv_irq_timeout(struct timer_list *t) struct bttv_buffer *ovbi; struct bttv_buffer *item; unsigned long flags; + int seqnr = 0; if (bttv_verbose) { pr_info("%d: timeout: drop=%d irq=%d/%d, risc=%08x, ", @@ -3206,21 +2810,25 @@ static void bttv_irq_timeout(struct timer_list *t) bttv_set_dma(btv, 0); /* wake up */ - bttv_irq_wakeup_video(btv, &old, &new, VIDEOBUF_ERROR); - bttv_irq_wakeup_vbi(btv, ovbi, VIDEOBUF_ERROR); + bttv_irq_wakeup_video(btv, &old, &new, VB2_BUF_STATE_DONE); + bttv_irq_wakeup_vbi(btv, ovbi, VB2_BUF_STATE_DONE); /* cancel all outstanding capture / vbi requests */ + if (btv->field_count) + seqnr++; while (!list_empty(&btv->capture)) { - item = list_entry(btv->capture.next, struct bttv_buffer, vb.queue); - list_del(&item->vb.queue); - item->vb.state = VIDEOBUF_ERROR; - wake_up(&item->vb.done); + item = list_entry(btv->capture.next, struct bttv_buffer, list); + list_del(&item->list); + item->vbuf.vb2_buf.timestamp = ktime_get_ns(); + item->vbuf.sequence = (btv->field_count >> 1) + seqnr++; + vb2_buffer_done(&item->vbuf.vb2_buf, VB2_BUF_STATE_ERROR); } while (!list_empty(&btv->vcapture)) { - item = list_entry(btv->vcapture.next, struct bttv_buffer, vb.queue); - list_del(&item->vb.queue); - item->vb.state = VIDEOBUF_ERROR; - wake_up(&item->vb.done); + item = list_entry(btv->vcapture.next, struct bttv_buffer, list); + list_del(&item->list); + item->vbuf.vb2_buf.timestamp = ktime_get_ns(); + item->vbuf.sequence = (btv->field_count >> 1) + seqnr++; + vb2_buffer_done(&item->vbuf.vb2_buf, VB2_BUF_STATE_ERROR); } btv->errors++; @@ -3239,11 +2847,11 @@ bttv_irq_wakeup_top(struct bttv *btv) btv->curr.top_irq = 0; btv->curr.top = NULL; bttv_risc_hook(btv, RISC_SLOT_O_FIELD, NULL, 0); - - wakeup->vb.ts = ktime_get_ns(); - wakeup->vb.field_count = btv->field_count; - wakeup->vb.state = VIDEOBUF_DONE; - wake_up(&wakeup->vb.done); + wakeup->vbuf.vb2_buf.timestamp = ktime_get_ns(); + wakeup->vbuf.sequence = btv->field_count >> 1; + vb2_buffer_done(&wakeup->vbuf.vb2_buf, VB2_BUF_STATE_DONE); + if (btv->field_count == 0) + btor(BT848_INT_VSYNC, BT848_INT_MASK); spin_unlock(&btv->s_lock); } @@ -3280,7 +2888,7 @@ bttv_irq_switch_video(struct bttv *btv) /* switch over */ old = btv->curr; btv->curr = new; - btv->loop_irq &= ~1; + btv->loop_irq &= ~BT848_RISC_VIDEO; bttv_buffer_activate_video(btv, &new); bttv_set_dma(btv, 0); @@ -3291,7 +2899,7 @@ bttv_irq_switch_video(struct bttv *btv) } /* wake up finished buffers */ - bttv_irq_wakeup_video(btv, &old, &new, VIDEOBUF_DONE); + bttv_irq_wakeup_video(btv, &old, &new, VB2_BUF_STATE_DONE); spin_unlock(&btv->s_lock); } @@ -3305,7 +2913,7 @@ bttv_irq_switch_vbi(struct bttv *btv) spin_lock(&btv->s_lock); if (!list_empty(&btv->vcapture)) - new = list_entry(btv->vcapture.next, struct bttv_buffer, vb.queue); + new = list_entry(btv->vcapture.next, struct bttv_buffer, list); old = btv->cvbi; rc = btread(BT848_RISC_COUNT); @@ -3320,11 +2928,11 @@ bttv_irq_switch_vbi(struct bttv *btv) /* switch */ btv->cvbi = new; - btv->loop_irq &= ~4; + btv->loop_irq &= ~BT848_RISC_VBI; bttv_buffer_activate_vbi(btv, new); bttv_set_dma(btv, 0); - bttv_irq_wakeup_vbi(btv, old, VIDEOBUF_DONE); + bttv_irq_wakeup_vbi(btv, old, VB2_BUF_STATE_DONE); spin_unlock(&btv->s_lock); } @@ -3383,13 +2991,13 @@ static irqreturn_t bttv_irq(int irq, void *dev_id) wake_up(&btv->i2c_queue); } - if ((astat & BT848_INT_RISCI) && (stat & (4<<28))) + if ((astat & BT848_INT_RISCI) && (stat & BT848_INT_RISCS_VBI)) bttv_irq_switch_vbi(btv); - if ((astat & BT848_INT_RISCI) && (stat & (2<<28))) + if ((astat & BT848_INT_RISCI) && (stat & BT848_INT_RISCS_TOP)) bttv_irq_wakeup_top(btv); - if ((astat & BT848_INT_RISCI) && (stat & (1<<28))) + if ((astat & BT848_INT_RISCI) && (stat & BT848_INT_RISCS_VIDEO)) bttv_irq_switch_video(btv); if ((astat & BT848_INT_HLOCK) && btv->opt_automute) @@ -3445,11 +3053,12 @@ static irqreturn_t bttv_irq(int irq, void *dev_id) /* ----------------------------------------------------------------------- */ /* initialization */ -static void vdev_init(struct bttv *btv, - struct video_device *vfd, - const struct video_device *template, - const char *type_name) +static int vdev_init(struct bttv *btv, struct video_device *vfd, + const struct video_device *template, + const char *type_name) { + int err; + struct vb2_queue *q; *vfd = *template; vfd->v4l2_dev = &btv->c.v4l2_dev; vfd->release = video_device_release_empty; @@ -3463,6 +3072,36 @@ static void vdev_init(struct bttv *btv, v4l2_disable_ioctl(vfd, VIDIOC_G_TUNER); v4l2_disable_ioctl(vfd, VIDIOC_S_TUNER); } + + if (strcmp(type_name, "radio") == 0) + return 0; + + if (strcmp(type_name, "video") == 0) { + q = &btv->capq; + q->type = V4L2_BUF_TYPE_VIDEO_CAPTURE; + q->ops = &bttv_video_qops; + } else if (strcmp(type_name, "vbi") == 0) { + q = &btv->vbiq; + q->type = V4L2_BUF_TYPE_VBI_CAPTURE; + q->ops = &bttv_vbi_qops; + } else { + return -EINVAL; + } + q->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC; + q->io_modes = VB2_MMAP | VB2_USERPTR | VB2_READ | VB2_DMABUF; + q->mem_ops = &vb2_dma_sg_memops; + q->drv_priv = btv; + q->gfp_flags = __GFP_DMA32; + q->buf_struct_size = sizeof(struct bttv_buffer); + q->lock = &btv->lock; + q->min_buffers_needed = 2; + q->dev = &btv->c.pci->dev; + err = vb2_queue_init(q); + if (err) + return err; + vfd->queue = q; + + return 0; } static void bttv_unregister_video(struct bttv *btv) @@ -3670,11 +3309,16 @@ static int bttv_probe(struct pci_dev *dev, const struct pci_device_id *pci_id) bttv_ctrl_coring.def = coring; /* fill struct bttv with some useful defaults */ - btv->init.btv = btv; - btv->init.fmt = format_by_fourcc(V4L2_PIX_FMT_BGR24); - btv->init.width = 320; - btv->init.height = 240; + btv->fmt = format_by_fourcc(V4L2_PIX_FMT_BGR24); + btv->width = 320; + btv->height = 240; + btv->field = V4L2_FIELD_INTERLACED; btv->input = 0; + btv->tvnorm = 0; /* Index into bttv_tvnorms[] i.e. PAL. */ + bttv_vbi_fmt_reset(&btv->vbi_fmt, btv->tvnorm); + btv->vbi_count[0] = VBI_DEFLINES; + btv->vbi_count[1] = VBI_DEFLINES; + btv->do_crop = 0; v4l2_ctrl_new_std(hdl, &bttv_ctrl_ops, V4L2_CID_BRIGHTNESS, 0, 0xff00, 0x100, 32768); @@ -3749,7 +3393,7 @@ static int bttv_probe(struct pci_dev *dev, const struct pci_device_id *pci_id) result = btv->radio_ctrl_handler.error; goto fail2; } - set_input(btv, 0, btv->tvnorm); + set_input(btv, btv->input, btv->tvnorm); bttv_crop_reset(&btv->crop[0], btv->tvnorm); btv->crop[1] = btv->crop[0]; /* current = default */ disclaim_vbi_lines(btv); diff --git a/drivers/media/pci/bt8xx/bttv-risc.c b/drivers/media/pci/bt8xx/bttv-risc.c index 4fa4b9da9634..436baf6c8b08 100644 --- a/drivers/media/pci/bt8xx/bttv-risc.c +++ b/drivers/media/pci/bt8xx/bttv-risc.c @@ -67,8 +67,10 @@ bttv_risc_packed(struct bttv *btv, struct btcx_riscmem *risc, /* scan lines */ sg = sglist; for (line = 0; line < store_lines; line++) { - if ((btv->opt_vcr_hack) && - (line >= (store_lines - VCR_HACK_LINES))) + if ((line >= (store_lines - VCR_HACK_LINES)) && + (btv->opt_vcr_hack || + (V4L2_FIELD_HAS_BOTH(btv->field) || + btv->field == V4L2_FIELD_ALTERNATE))) continue; while (offset && offset >= sg_dma_len(sg)) { offset -= sg_dma_len(sg); @@ -106,7 +108,7 @@ bttv_risc_packed(struct bttv *btv, struct btcx_riscmem *risc, /* save pointer to jmp instruction address */ risc->jmp = rp; - BUG_ON((risc->jmp - risc->cpu + 2) * sizeof(*risc->cpu) > risc->size); + WARN_ON((risc->jmp - risc->cpu + 2) * sizeof(*risc->cpu) > risc->size); return 0; } @@ -227,7 +229,7 @@ bttv_risc_planar(struct bttv *btv, struct btcx_riscmem *risc, /* save pointer to jmp instruction address */ risc->jmp = rp; - BUG_ON((risc->jmp - risc->cpu + 2) * sizeof(*risc->cpu) > risc->size); + WARN_ON((risc->jmp - risc->cpu + 2) * sizeof(*risc->cpu) > risc->size); return 0; } @@ -360,21 +362,75 @@ bttv_apply_geo(struct bttv *btv, struct bttv_geometry *geo, int odd) /* ---------------------------------------------------------- */ /* risc group / risc main loop / dma management */ -void -bttv_set_dma(struct bttv *btv, int override) +static void bttv_set_risc_status(struct bttv *btv) { - unsigned long cmd; - int capctl; + unsigned long cmd = BT848_RISC_JUMP; + if (btv->loop_irq) { + cmd |= BT848_RISC_IRQ; + cmd |= (btv->loop_irq & 0x0f) << 16; + cmd |= (~btv->loop_irq & 0x0f) << 20; + } + btv->main.cpu[RISC_SLOT_LOOP] = cpu_to_le32(cmd); +} + +static void bttv_set_irq_timer(struct bttv *btv) +{ + if (btv->curr.frame_irq || btv->loop_irq || btv->cvbi) + mod_timer(&btv->timeout, jiffies + BTTV_TIMEOUT); + else + del_timer(&btv->timeout); +} + +static int bttv_set_capture_control(struct bttv *btv, int start_capture) +{ + int capctl = 0; + + if (btv->curr.top || btv->curr.bottom) + capctl = BT848_CAP_CTL_CAPTURE_ODD | + BT848_CAP_CTL_CAPTURE_EVEN; + + if (btv->cvbi) + capctl |= BT848_CAP_CTL_CAPTURE_VBI_ODD | + BT848_CAP_CTL_CAPTURE_VBI_EVEN; + + capctl |= start_capture; + + btaor(capctl, ~0x0f, BT848_CAP_CTL); + + return capctl; +} + +static void bttv_start_dma(struct bttv *btv) +{ + if (btv->dma_on) + return; + btwrite(btv->main.dma, BT848_RISC_STRT_ADD); + btor(BT848_GPIO_DMA_CTL_RISC_ENABLE | BT848_GPIO_DMA_CTL_FIFO_ENABLE, + BT848_GPIO_DMA_CTL); + btv->dma_on = 1; +} + +static void bttv_stop_dma(struct bttv *btv) +{ + if (!btv->dma_on) + return; + btand(~(BT848_GPIO_DMA_CTL_RISC_ENABLE | + BT848_GPIO_DMA_CTL_FIFO_ENABLE), BT848_GPIO_DMA_CTL); + btv->dma_on = 0; +} - btv->cap_ctl = 0; - if (NULL != btv->curr.top) btv->cap_ctl |= 0x02; - if (NULL != btv->curr.bottom) btv->cap_ctl |= 0x01; - if (NULL != btv->cvbi) btv->cap_ctl |= 0x0c; +void bttv_set_dma(struct bttv *btv, int start_capture) +{ + int capctl = 0; + + bttv_set_risc_status(btv); + bttv_set_irq_timer(btv); + capctl = bttv_set_capture_control(btv, start_capture); - capctl = 0; - capctl |= (btv->cap_ctl & 0x03) ? 0x03 : 0x00; /* capture */ - capctl |= (btv->cap_ctl & 0x0c) ? 0x0c : 0x00; /* vbi data */ - capctl |= override; + if (capctl) + bttv_start_dma(btv); + else + bttv_stop_dma(btv); d2printk("%d: capctl=%x lirq=%d top=%08llx/%08llx even=%08llx/%08llx\n", btv->c.nr,capctl,btv->loop_irq, @@ -382,34 +438,6 @@ bttv_set_dma(struct bttv *btv, int override) btv->curr.top ? (unsigned long long)btv->curr.top->top.dma : 0, btv->cvbi ? (unsigned long long)btv->cvbi->bottom.dma : 0, btv->curr.bottom ? (unsigned long long)btv->curr.bottom->bottom.dma : 0); - - cmd = BT848_RISC_JUMP; - if (btv->loop_irq) { - cmd |= BT848_RISC_IRQ; - cmd |= (btv->loop_irq & 0x0f) << 16; - cmd |= (~btv->loop_irq & 0x0f) << 20; - } - if (btv->curr.frame_irq || btv->loop_irq || btv->cvbi) { - mod_timer(&btv->timeout, jiffies+BTTV_TIMEOUT); - } else { - del_timer(&btv->timeout); - } - btv->main.cpu[RISC_SLOT_LOOP] = cpu_to_le32(cmd); - - btaor(capctl, ~0x0f, BT848_CAP_CTL); - if (capctl) { - if (btv->dma_on) - return; - btwrite(btv->main.dma, BT848_RISC_STRT_ADD); - btor(3, BT848_GPIO_DMA_CTL); - btv->dma_on = 1; - } else { - if (!btv->dma_on) - return; - btand(~3, BT848_GPIO_DMA_CTL); - btv->dma_on = 0; - } - return; } int @@ -478,17 +506,50 @@ bttv_risc_hook(struct bttv *btv, int slot, struct btcx_riscmem *risc, return 0; } -void -bttv_dma_free(struct videobuf_queue *q,struct bttv *btv, struct bttv_buffer *buf) +int bttv_buffer_risc_vbi(struct bttv *btv, struct bttv_buffer *buf) { - struct videobuf_dmabuf *dma=videobuf_to_dma(&buf->vb); - - videobuf_waiton(q, &buf->vb, 0, 0); - videobuf_dma_unmap(q->dev, dma); - videobuf_dma_free(dma); - btcx_riscmem_free(btv->c.pci,&buf->bottom); - btcx_riscmem_free(btv->c.pci,&buf->top); - buf->vb.state = VIDEOBUF_NEEDS_INIT; + int r = 0; + unsigned int offset; + unsigned int bpl = 2044; /* max. vbipack */ + unsigned int padding = VBI_BPL - bpl; + unsigned int skip_lines0 = 0; + unsigned int skip_lines1 = 0; + unsigned int min_vdelay = MIN_VDELAY; + + const struct bttv_tvnorm *tvnorm = btv->vbi_fmt.tvnorm; + struct sg_table *sgt = vb2_dma_sg_plane_desc(&buf->vbuf.vb2_buf, 0); + struct scatterlist *list = sgt->sgl; + + if (btv->vbi_fmt.fmt.count[0] > 0) + skip_lines0 = max(0, (btv->vbi_fmt.fmt.start[0] - + tvnorm->vbistart[0])); + if (btv->vbi_fmt.fmt.count[1] > 0) + skip_lines1 = max(0, (btv->vbi_fmt.fmt.start[1] - + tvnorm->vbistart[1])); + + if (btv->vbi_fmt.fmt.count[0] > 0) { + r = bttv_risc_packed(btv, &buf->top, list, 0, bpl, padding, + skip_lines0, btv->vbi_fmt.fmt.count[0]); + if (r) + return r; + } + + if (btv->vbi_fmt.fmt.count[1] > 0) { + offset = btv->vbi_fmt.fmt.count[0] * VBI_BPL; + r = bttv_risc_packed(btv, &buf->bottom, list, offset, bpl, + padding, skip_lines1, + btv->vbi_fmt.fmt.count[1]); + if (r) + return r; + } + + if (btv->vbi_fmt.end >= tvnorm->cropcap.bounds.top) + min_vdelay += btv->vbi_fmt.end - tvnorm->cropcap.bounds.top; + + /* For bttv_buffer_activate_vbi(). */ + buf->geo.vdelay = min_vdelay; + + return r; } int @@ -508,8 +569,7 @@ bttv_buffer_activate_vbi(struct bttv *btv, if (vbi) { unsigned int crop, vdelay; - vbi->vb.state = VIDEOBUF_ACTIVE; - list_del(&vbi->vb.queue); + list_del(&vbi->list); /* VDELAY is start of video, end of VBI capturing. */ crop = btread(BT848_E_CROP); @@ -525,12 +585,12 @@ bttv_buffer_activate_vbi(struct bttv *btv, btwrite(crop, BT848_O_CROP); } - if (vbi->vbi_count[0] > 0) { + if (btv->vbi_count[0] > 0) { top = &vbi->top; top_irq_flags = 4; } - if (vbi->vbi_count[1] > 0) { + if (btv->vbi_count[1] > 0) { top_irq_flags = 0; bottom = &vbi->bottom; bottom_irq_flags = 4; @@ -550,16 +610,13 @@ bttv_buffer_activate_video(struct bttv *btv, /* video capture */ if (NULL != set->top && NULL != set->bottom) { if (set->top == set->bottom) { - set->top->vb.state = VIDEOBUF_ACTIVE; - if (set->top->vb.queue.next) - list_del(&set->top->vb.queue); + if (set->top->list.next) + list_del(&set->top->list); } else { - set->top->vb.state = VIDEOBUF_ACTIVE; - set->bottom->vb.state = VIDEOBUF_ACTIVE; - if (set->top->vb.queue.next) - list_del(&set->top->vb.queue); - if (set->bottom->vb.queue.next) - list_del(&set->bottom->vb.queue); + if (set->top->list.next) + list_del(&set->top->list); + if (set->bottom->list.next) + list_del(&set->bottom->list); } bttv_apply_geo(btv, &set->top->geo, 1); bttv_apply_geo(btv, &set->bottom->geo,0); @@ -572,9 +629,8 @@ bttv_buffer_activate_video(struct bttv *btv, btaor((set->top->btswap & 0x0a) | (set->bottom->btswap & 0x05), ~0x0f, BT848_COLOR_CTL); } else if (NULL != set->top) { - set->top->vb.state = VIDEOBUF_ACTIVE; - if (set->top->vb.queue.next) - list_del(&set->top->vb.queue); + if (set->top->list.next) + list_del(&set->top->list); bttv_apply_geo(btv, &set->top->geo,1); bttv_apply_geo(btv, &set->top->geo,0); bttv_risc_hook(btv, RISC_SLOT_O_FIELD, &set->top->top, @@ -583,9 +639,8 @@ bttv_buffer_activate_video(struct bttv *btv, btaor(set->top->btformat & 0xff, ~0xff, BT848_COLOR_FMT); btaor(set->top->btswap & 0x0f, ~0x0f, BT848_COLOR_CTL); } else if (NULL != set->bottom) { - set->bottom->vb.state = VIDEOBUF_ACTIVE; - if (set->bottom->vb.queue.next) - list_del(&set->bottom->vb.queue); + if (set->bottom->list.next) + list_del(&set->bottom->list); bttv_apply_geo(btv, &set->bottom->geo,1); bttv_apply_geo(btv, &set->bottom->geo,0); bttv_risc_hook(btv, RISC_SLOT_O_FIELD, NULL, 0); @@ -606,156 +661,146 @@ bttv_buffer_activate_video(struct bttv *btv, int bttv_buffer_risc(struct bttv *btv, struct bttv_buffer *buf) { - const struct bttv_tvnorm *tvnorm = bttv_tvnorms + buf->tvnorm; - struct videobuf_dmabuf *dma=videobuf_to_dma(&buf->vb); - - dprintk("%d: buffer field: %s format: 0x%08x size: %dx%d\n", - btv->c.nr, v4l2_field_names[buf->vb.field], - buf->fmt->fourcc, buf->vb.width, buf->vb.height); + int r = 0; + const struct bttv_tvnorm *tvnorm = bttv_tvnorms + btv->tvnorm; + struct sg_table *sgt = vb2_dma_sg_plane_desc(&buf->vbuf.vb2_buf, 0); + struct scatterlist *list = sgt->sgl; + unsigned long size = (btv->fmt->depth * btv->width * btv->height) >> 3; /* packed pixel modes */ - if (buf->fmt->flags & FORMAT_FLAGS_PACKED) { - int bpl = (buf->fmt->depth >> 3) * buf->vb.width; - int bpf = bpl * (buf->vb.height >> 1); - - bttv_calc_geo(btv,&buf->geo,buf->vb.width,buf->vb.height, - V4L2_FIELD_HAS_BOTH(buf->vb.field), - tvnorm,&buf->crop); - - switch (buf->vb.field) { + if (btv->fmt->flags & FORMAT_FLAGS_PACKED) { + int bpl = (btv->fmt->depth >> 3) * btv->width; + int bpf = bpl * (btv->height >> 1); + + bttv_calc_geo(btv, &buf->geo, btv->width, btv->height, + V4L2_FIELD_HAS_BOTH(buf->vbuf.field), tvnorm, + &btv->crop[!!btv->do_crop].rect); + switch (buf->vbuf.field) { case V4L2_FIELD_TOP: - bttv_risc_packed(btv,&buf->top,dma->sglist, - /* offset */ 0,bpl, - /* padding */ 0,/* skip_lines */ 0, - buf->vb.height); + r = bttv_risc_packed(btv, &buf->top, list, 0, bpl, 0, + 0, btv->height); break; case V4L2_FIELD_BOTTOM: - bttv_risc_packed(btv,&buf->bottom,dma->sglist, - 0,bpl,0,0,buf->vb.height); + r = bttv_risc_packed(btv, &buf->bottom, list, 0, bpl, + 0, 0, btv->height); break; case V4L2_FIELD_INTERLACED: - bttv_risc_packed(btv,&buf->top,dma->sglist, - 0,bpl,bpl,0,buf->vb.height >> 1); - bttv_risc_packed(btv,&buf->bottom,dma->sglist, - bpl,bpl,bpl,0,buf->vb.height >> 1); + r = bttv_risc_packed(btv, &buf->top, list, 0, bpl, + bpl, 0, btv->height >> 1); + r = bttv_risc_packed(btv, &buf->bottom, list, bpl, + bpl, bpl, 0, btv->height >> 1); break; case V4L2_FIELD_SEQ_TB: - bttv_risc_packed(btv,&buf->top,dma->sglist, - 0,bpl,0,0,buf->vb.height >> 1); - bttv_risc_packed(btv,&buf->bottom,dma->sglist, - bpf,bpl,0,0,buf->vb.height >> 1); + r = bttv_risc_packed(btv, &buf->top, list, 0, bpl, 0, + 0, btv->height >> 1); + r = bttv_risc_packed(btv, &buf->bottom, list, bpf, + bpl, 0, 0, btv->height >> 1); break; default: - BUG(); + WARN_ON(1); + return -EINVAL; } } - /* planar modes */ - if (buf->fmt->flags & FORMAT_FLAGS_PLANAR) { + if (btv->fmt->flags & FORMAT_FLAGS_PLANAR) { int uoffset, voffset; int ypadding, cpadding, lines; /* calculate chroma offsets */ - uoffset = buf->vb.width * buf->vb.height; - voffset = buf->vb.width * buf->vb.height; - if (buf->fmt->flags & FORMAT_FLAGS_CrCb) { + uoffset = btv->width * btv->height; + voffset = btv->width * btv->height; + if (btv->fmt->flags & FORMAT_FLAGS_CrCb) { /* Y-Cr-Cb plane order */ - uoffset >>= buf->fmt->hshift; - uoffset >>= buf->fmt->vshift; + uoffset >>= btv->fmt->hshift; + uoffset >>= btv->fmt->vshift; uoffset += voffset; } else { /* Y-Cb-Cr plane order */ - voffset >>= buf->fmt->hshift; - voffset >>= buf->fmt->vshift; + voffset >>= btv->fmt->hshift; + voffset >>= btv->fmt->vshift; voffset += uoffset; } - - switch (buf->vb.field) { + switch (buf->vbuf.field) { case V4L2_FIELD_TOP: - bttv_calc_geo(btv,&buf->geo,buf->vb.width, - buf->vb.height,/* both_fields */ 0, - tvnorm,&buf->crop); - bttv_risc_planar(btv, &buf->top, dma->sglist, - 0,buf->vb.width,0,buf->vb.height, - uoffset,voffset,buf->fmt->hshift, - buf->fmt->vshift,0); + bttv_calc_geo(btv, &buf->geo, btv->width, btv->height, + 0, tvnorm, + &btv->crop[!!btv->do_crop].rect); + r = bttv_risc_planar(btv, &buf->top, list, 0, + btv->width, 0, btv->height, + uoffset, voffset, + btv->fmt->hshift, + btv->fmt->vshift, 0); break; case V4L2_FIELD_BOTTOM: - bttv_calc_geo(btv,&buf->geo,buf->vb.width, - buf->vb.height,0, - tvnorm,&buf->crop); - bttv_risc_planar(btv, &buf->bottom, dma->sglist, - 0,buf->vb.width,0,buf->vb.height, - uoffset,voffset,buf->fmt->hshift, - buf->fmt->vshift,0); + bttv_calc_geo(btv, &buf->geo, btv->width, btv->height, + 0, tvnorm, + &btv->crop[!!btv->do_crop].rect); + r = bttv_risc_planar(btv, &buf->bottom, list, 0, + btv->width, 0, btv->height, + uoffset, voffset, + btv->fmt->hshift, + btv->fmt->vshift, 0); break; case V4L2_FIELD_INTERLACED: - bttv_calc_geo(btv,&buf->geo,buf->vb.width, - buf->vb.height,1, - tvnorm,&buf->crop); - lines = buf->vb.height >> 1; - ypadding = buf->vb.width; - cpadding = buf->vb.width >> buf->fmt->hshift; - bttv_risc_planar(btv,&buf->top, - dma->sglist, - 0,buf->vb.width,ypadding,lines, - uoffset,voffset, - buf->fmt->hshift, - buf->fmt->vshift, - cpadding); - bttv_risc_planar(btv,&buf->bottom, - dma->sglist, - ypadding,buf->vb.width,ypadding,lines, - uoffset+cpadding, - voffset+cpadding, - buf->fmt->hshift, - buf->fmt->vshift, - cpadding); + bttv_calc_geo(btv, &buf->geo, btv->width, btv->height, + 1, tvnorm, + &btv->crop[!!btv->do_crop].rect); + lines = btv->height >> 1; + ypadding = btv->width; + cpadding = btv->width >> btv->fmt->hshift; + r = bttv_risc_planar(btv, &buf->top, list, 0, + btv->width, ypadding, lines, + uoffset, voffset, + btv->fmt->hshift, + btv->fmt->vshift, cpadding); + + r = bttv_risc_planar(btv, &buf->bottom, list, + ypadding, btv->width, ypadding, + lines, uoffset + cpadding, + voffset + cpadding, + btv->fmt->hshift, + btv->fmt->vshift, cpadding); break; case V4L2_FIELD_SEQ_TB: - bttv_calc_geo(btv,&buf->geo,buf->vb.width, - buf->vb.height,1, - tvnorm,&buf->crop); - lines = buf->vb.height >> 1; - ypadding = buf->vb.width; - cpadding = buf->vb.width >> buf->fmt->hshift; - bttv_risc_planar(btv,&buf->top, - dma->sglist, - 0,buf->vb.width,0,lines, - uoffset >> 1, - voffset >> 1, - buf->fmt->hshift, - buf->fmt->vshift, - 0); - bttv_risc_planar(btv,&buf->bottom, - dma->sglist, - lines * ypadding,buf->vb.width,0,lines, - lines * ypadding + (uoffset >> 1), - lines * ypadding + (voffset >> 1), - buf->fmt->hshift, - buf->fmt->vshift, - 0); + bttv_calc_geo(btv, &buf->geo, btv->width, btv->height, + 1, tvnorm, + &btv->crop[!!btv->do_crop].rect); + lines = btv->height >> 1; + ypadding = btv->width; + cpadding = btv->width >> btv->fmt->hshift; + r = bttv_risc_planar(btv, &buf->top, list, 0, + btv->width, 0, lines, + uoffset >> 1, voffset >> 1, + btv->fmt->hshift, + btv->fmt->vshift, 0); + r = bttv_risc_planar(btv, &buf->bottom, list, + lines * ypadding, + btv->width, 0, lines, + lines * ypadding + (uoffset >> 1), + lines * ypadding + (voffset >> 1), + btv->fmt->hshift, + btv->fmt->vshift, 0); break; default: - BUG(); + WARN_ON(1); + return -EINVAL; } } - /* raw data */ - if (buf->fmt->flags & FORMAT_FLAGS_RAW) { + if (btv->fmt->flags & FORMAT_FLAGS_RAW) { /* build risc code */ - buf->vb.field = V4L2_FIELD_SEQ_TB; - bttv_calc_geo(btv,&buf->geo,tvnorm->swidth,tvnorm->sheight, - 1,tvnorm,&buf->crop); - bttv_risc_packed(btv, &buf->top, dma->sglist, - /* offset */ 0, RAW_BPL, /* padding */ 0, - /* skip_lines */ 0, RAW_LINES); - bttv_risc_packed(btv, &buf->bottom, dma->sglist, - buf->vb.size/2 , RAW_BPL, 0, 0, RAW_LINES); + buf->vbuf.field = V4L2_FIELD_SEQ_TB; + bttv_calc_geo(btv, &buf->geo, tvnorm->swidth, tvnorm->sheight, + 1, tvnorm, &btv->crop[!!btv->do_crop].rect); + r = bttv_risc_packed(btv, &buf->top, list, 0, RAW_BPL, 0, 0, + RAW_LINES); + r = bttv_risc_packed(btv, &buf->bottom, list, size / 2, + RAW_BPL, 0, 0, RAW_LINES); } /* copy format info */ - buf->btformat = buf->fmt->btformat; - buf->btswap = buf->fmt->btswap; - return 0; + buf->btformat = btv->fmt->btformat; + buf->btswap = btv->fmt->btswap; + + return r; } diff --git a/drivers/media/pci/bt8xx/bttv-vbi.c b/drivers/media/pci/bt8xx/bttv-vbi.c index ce36a2c0f60b..ab213e51ec95 100644 --- a/drivers/media/pci/bt8xx/bttv-vbi.c +++ b/drivers/media/pci/bt8xx/bttv-vbi.c @@ -34,16 +34,6 @@ to be about 244. */ #define VBI_OFFSET 244 -/* 2048 for compatibility with earlier driver versions. The driver - really stores 1024 + tvnorm->vbipack * 4 samples per line in the - buffer. Note tvnorm->vbipack is <= 0xFF (limit of VBIPACK_LO + HI - is 0x1FF DWORDs) and VBI read()s store a frame counter in the last - four bytes of the VBI image. */ -#define VBI_BPL 2048 - -/* Compatibility. */ -#define VBI_DEFLINES 16 - static unsigned int vbibufs = 4; static unsigned int vbi_debug; @@ -67,165 +57,123 @@ do { \ /* ----------------------------------------------------------------------- */ /* vbi risc code + mm */ -static int vbi_buffer_setup(struct videobuf_queue *q, - unsigned int *count, unsigned int *size) +static int queue_setup_vbi(struct vb2_queue *q, unsigned int *num_buffers, + unsigned int *num_planes, unsigned int sizes[], + struct device *alloc_devs[]) { - struct bttv_fh *fh = q->priv_data; - struct bttv *btv = fh->btv; - - if (0 == *count) - *count = vbibufs; - - *size = IMAGE_SIZE(&fh->vbi_fmt.fmt); + struct bttv *btv = vb2_get_drv_priv(q); + unsigned int size = IMAGE_SIZE(&btv->vbi_fmt.fmt); - dprintk("setup: samples=%u start=%d,%d count=%u,%u\n", - fh->vbi_fmt.fmt.samples_per_line, - fh->vbi_fmt.fmt.start[0], - fh->vbi_fmt.fmt.start[1], - fh->vbi_fmt.fmt.count[0], - fh->vbi_fmt.fmt.count[1]); + if (*num_planes) + return sizes[0] < size ? -EINVAL : 0; + *num_planes = 1; + sizes[0] = size; return 0; } -static int vbi_buffer_prepare(struct videobuf_queue *q, - struct videobuf_buffer *vb, - enum v4l2_field field) +static void buf_queue_vbi(struct vb2_buffer *vb) { - struct bttv_fh *fh = q->priv_data; - struct bttv *btv = fh->btv; - struct bttv_buffer *buf = container_of(vb,struct bttv_buffer,vb); - const struct bttv_tvnorm *tvnorm; - unsigned int skip_lines0, skip_lines1, min_vdelay; - int redo_dma_risc; - int rc; - - buf->vb.size = IMAGE_SIZE(&fh->vbi_fmt.fmt); - if (0 != buf->vb.baddr && buf->vb.bsize < buf->vb.size) - return -EINVAL; - - tvnorm = fh->vbi_fmt.tvnorm; - - /* There's no VBI_VDELAY register, RISC must skip the lines - we don't want. With default parameters we skip zero lines - as earlier driver versions did. The driver permits video - standard changes while capturing, so we use vbi_fmt.tvnorm - instead of btv->tvnorm to skip zero lines after video - standard changes as well. */ - - skip_lines0 = 0; - skip_lines1 = 0; - - if (fh->vbi_fmt.fmt.count[0] > 0) - skip_lines0 = max(0, (fh->vbi_fmt.fmt.start[0] - - tvnorm->vbistart[0])); - if (fh->vbi_fmt.fmt.count[1] > 0) - skip_lines1 = max(0, (fh->vbi_fmt.fmt.start[1] - - tvnorm->vbistart[1])); - - redo_dma_risc = 0; - - if (buf->vbi_skip[0] != skip_lines0 || - buf->vbi_skip[1] != skip_lines1 || - buf->vbi_count[0] != fh->vbi_fmt.fmt.count[0] || - buf->vbi_count[1] != fh->vbi_fmt.fmt.count[1]) { - buf->vbi_skip[0] = skip_lines0; - buf->vbi_skip[1] = skip_lines1; - buf->vbi_count[0] = fh->vbi_fmt.fmt.count[0]; - buf->vbi_count[1] = fh->vbi_fmt.fmt.count[1]; - redo_dma_risc = 1; - } - - if (VIDEOBUF_NEEDS_INIT == buf->vb.state) { - redo_dma_risc = 1; - if (0 != (rc = videobuf_iolock(q, &buf->vb, NULL))) - goto fail; + struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb); + struct vb2_queue *vq = vb->vb2_queue; + struct bttv *btv = vb2_get_drv_priv(vq); + struct bttv_buffer *buf = container_of(vbuf, struct bttv_buffer, vbuf); + unsigned long flags; + + spin_lock_irqsave(&btv->s_lock, flags); + if (list_empty(&btv->vcapture)) { + btv->loop_irq = BT848_RISC_VBI; + if (vb2_is_streaming(&btv->capq)) + btv->loop_irq |= BT848_RISC_VIDEO; + bttv_set_dma(btv, BT848_CAP_CTL_CAPTURE_VBI_ODD | + BT848_CAP_CTL_CAPTURE_VBI_EVEN); } + list_add_tail(&buf->list, &btv->vcapture); + spin_unlock_irqrestore(&btv->s_lock, flags); +} - if (redo_dma_risc) { - unsigned int bpl, padding, offset; - struct videobuf_dmabuf *dma=videobuf_to_dma(&buf->vb); - - bpl = 2044; /* max. vbipack */ - padding = VBI_BPL - bpl; - - if (fh->vbi_fmt.fmt.count[0] > 0) { - rc = bttv_risc_packed(btv, &buf->top, - dma->sglist, - /* offset */ 0, bpl, - padding, skip_lines0, - fh->vbi_fmt.fmt.count[0]); - if (0 != rc) - goto fail; - } - - if (fh->vbi_fmt.fmt.count[1] > 0) { - offset = fh->vbi_fmt.fmt.count[0] * VBI_BPL; +static int buf_prepare_vbi(struct vb2_buffer *vb) +{ + int ret = 0; + struct vb2_queue *vq = vb->vb2_queue; + struct bttv *btv = vb2_get_drv_priv(vq); + struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb); + struct bttv_buffer *buf = container_of(vbuf, struct bttv_buffer, vbuf); + unsigned int size = IMAGE_SIZE(&btv->vbi_fmt.fmt); + + if (vb2_plane_size(vb, 0) < size) + return -EINVAL; + vb2_set_plane_payload(vb, 0, size); + buf->vbuf.field = V4L2_FIELD_NONE; + ret = bttv_buffer_risc_vbi(btv, buf); - rc = bttv_risc_packed(btv, &buf->bottom, - dma->sglist, - offset, bpl, - padding, skip_lines1, - fh->vbi_fmt.fmt.count[1]); - if (0 != rc) - goto fail; - } - } + return ret; +} - /* VBI capturing ends at VDELAY, start of video capturing, - no matter where the RISC program ends. VDELAY minimum is 2, - bounds.top is the corresponding first field line number - times two. VDELAY counts half field lines. */ - min_vdelay = MIN_VDELAY; - if (fh->vbi_fmt.end >= tvnorm->cropcap.bounds.top) - min_vdelay += fh->vbi_fmt.end - tvnorm->cropcap.bounds.top; - - /* For bttv_buffer_activate_vbi(). */ - buf->geo.vdelay = min_vdelay; - - buf->vb.state = VIDEOBUF_PREPARED; - buf->vb.field = field; - dprintk("buf prepare %p: top=%p bottom=%p field=%s\n", - vb, &buf->top, &buf->bottom, - v4l2_field_names[buf->vb.field]); - return 0; +static void buf_cleanup_vbi(struct vb2_buffer *vb) +{ + struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb); + struct bttv_buffer *buf = container_of(vbuf, struct bttv_buffer, vbuf); + struct vb2_queue *vq = vb->vb2_queue; + struct bttv *btv = vb2_get_drv_priv(vq); - fail: - bttv_dma_free(q,btv,buf); - return rc; + btcx_riscmem_free(btv->c.pci, &buf->top); + btcx_riscmem_free(btv->c.pci, &buf->bottom); } -static void -vbi_buffer_queue(struct videobuf_queue *q, struct videobuf_buffer *vb) +static int start_streaming_vbi(struct vb2_queue *q, unsigned int count) { - struct bttv_fh *fh = q->priv_data; - struct bttv *btv = fh->btv; - struct bttv_buffer *buf = container_of(vb,struct bttv_buffer,vb); - - dprintk("queue %p\n",vb); - buf->vb.state = VIDEOBUF_QUEUED; - list_add_tail(&buf->vb.queue,&btv->vcapture); - if (NULL == btv->cvbi) { - fh->btv->loop_irq |= 4; - bttv_set_dma(btv,0x0c); + int ret; + int seqnr = 0; + struct bttv_buffer *buf; + struct bttv *btv = vb2_get_drv_priv(q); + + btv->framedrop = 0; + ret = check_alloc_btres_lock(btv, RESOURCE_VBI); + if (ret == 0) { + if (btv->field_count) + seqnr++; + while (!list_empty(&btv->vcapture)) { + buf = list_entry(btv->vcapture.next, + struct bttv_buffer, list); + list_del(&buf->list); + buf->vbuf.sequence = (btv->field_count >> 1) + seqnr++; + vb2_buffer_done(&buf->vbuf.vb2_buf, + VB2_BUF_STATE_QUEUED); + } + return !ret; + } + if (!vb2_is_streaming(&btv->capq)) { + init_irqreg(btv); + btv->field_count = 0; } + return !ret; } -static void vbi_buffer_release(struct videobuf_queue *q, struct videobuf_buffer *vb) +static void stop_streaming_vbi(struct vb2_queue *q) { - struct bttv_fh *fh = q->priv_data; - struct bttv *btv = fh->btv; - struct bttv_buffer *buf = container_of(vb,struct bttv_buffer,vb); - - dprintk("free %p\n",vb); - bttv_dma_free(q,fh->btv,buf); + struct bttv *btv = vb2_get_drv_priv(q); + unsigned long flags; + + vb2_wait_for_all_buffers(q); + spin_lock_irqsave(&btv->s_lock, flags); + free_btres_lock(btv, RESOURCE_VBI); + if (!vb2_is_streaming(&btv->capq)) { + /* stop field counter */ + btand(~BT848_INT_VSYNC, BT848_INT_MASK); + } + spin_unlock_irqrestore(&btv->s_lock, flags); } -const struct videobuf_queue_ops bttv_vbi_qops = { - .buf_setup = vbi_buffer_setup, - .buf_prepare = vbi_buffer_prepare, - .buf_queue = vbi_buffer_queue, - .buf_release = vbi_buffer_release, +const struct vb2_ops bttv_vbi_qops = { + .queue_setup = queue_setup_vbi, + .buf_queue = buf_queue_vbi, + .buf_prepare = buf_prepare_vbi, + .buf_cleanup = buf_cleanup_vbi, + .start_streaming = start_streaming_vbi, + .stop_streaming = stop_streaming_vbi, + .wait_prepare = vb2_ops_wait_prepare, + .wait_finish = vb2_ops_wait_finish, }; /* ----------------------------------------------------------------------- */ @@ -250,7 +198,7 @@ static int try_fmt(struct v4l2_vbi_format *f, const struct bttv_tvnorm *tvnorm, if (min_start > max_start) return -EBUSY; - BUG_ON(max_start >= max_end); + WARN_ON(max_start >= max_end); f->sampling_rate = tvnorm->Fsc; f->samples_per_line = VBI_BPL; @@ -299,8 +247,7 @@ static int try_fmt(struct v4l2_vbi_format *f, const struct bttv_tvnorm *tvnorm, int bttv_try_fmt_vbi_cap(struct file *file, void *f, struct v4l2_format *frt) { - struct bttv_fh *fh = f; - struct bttv *btv = fh->btv; + struct bttv *btv = video_drvdata(file); const struct bttv_tvnorm *tvnorm; __s32 crop_start; @@ -317,8 +264,7 @@ int bttv_try_fmt_vbi_cap(struct file *file, void *f, struct v4l2_format *frt) int bttv_s_fmt_vbi_cap(struct file *file, void *f, struct v4l2_format *frt) { - struct bttv_fh *fh = f; - struct bttv *btv = fh->btv; + struct bttv *btv = video_drvdata(file); const struct bttv_tvnorm *tvnorm; __s32 start1, end; int rc; @@ -326,7 +272,7 @@ int bttv_s_fmt_vbi_cap(struct file *file, void *f, struct v4l2_format *frt) mutex_lock(&btv->lock); rc = -EBUSY; - if (fh->resources & RESOURCE_VBI) + if (btv->resources & RESOURCE_VBI) goto fail; tvnorm = &bttv_tvnorms[btv->tvnorm]; @@ -346,13 +292,9 @@ int bttv_s_fmt_vbi_cap(struct file *file, void *f, struct v4l2_format *frt) because vbi_fmt.end counts field lines times two. */ end = max(frt->fmt.vbi.start[0], start1) * 2 + 2; - mutex_lock(&fh->vbi.vb_lock); - - fh->vbi_fmt.fmt = frt->fmt.vbi; - fh->vbi_fmt.tvnorm = tvnorm; - fh->vbi_fmt.end = end; - - mutex_unlock(&fh->vbi.vb_lock); + btv->vbi_fmt.fmt = frt->fmt.vbi; + btv->vbi_fmt.tvnorm = tvnorm; + btv->vbi_fmt.end = end; rc = 0; @@ -365,14 +307,14 @@ int bttv_s_fmt_vbi_cap(struct file *file, void *f, struct v4l2_format *frt) int bttv_g_fmt_vbi_cap(struct file *file, void *f, struct v4l2_format *frt) { - struct bttv_fh *fh = f; const struct bttv_tvnorm *tvnorm; + struct bttv *btv = video_drvdata(file); - frt->fmt.vbi = fh->vbi_fmt.fmt; + frt->fmt.vbi = btv->vbi_fmt.fmt; - tvnorm = &bttv_tvnorms[fh->btv->tvnorm]; + tvnorm = &bttv_tvnorms[btv->tvnorm]; - if (tvnorm != fh->vbi_fmt.tvnorm) { + if (tvnorm != btv->vbi_fmt.tvnorm) { __s32 max_end; unsigned int i; @@ -388,9 +330,8 @@ int bttv_g_fmt_vbi_cap(struct file *file, void *f, struct v4l2_format *frt) for (i = 0; i < 2; ++i) { __s32 new_start; - new_start = frt->fmt.vbi.start[i] - + tvnorm->vbistart[i] - - fh->vbi_fmt.tvnorm->vbistart[i]; + new_start = frt->fmt.vbi.start[i] + tvnorm->vbistart[i] + - btv->vbi_fmt.tvnorm->vbistart[i]; frt->fmt.vbi.start[i] = min(new_start, max_end - 1); frt->fmt.vbi.count[i] = @@ -430,8 +371,8 @@ void bttv_vbi_fmt_reset(struct bttv_vbi_fmt *f, unsigned int norm) real_count = ((tvnorm->cropcap.defrect.top >> 1) - tvnorm->vbistart[0]); - BUG_ON(real_samples_per_line > VBI_BPL); - BUG_ON(real_count > VBI_DEFLINES); + WARN_ON(real_samples_per_line > VBI_BPL); + WARN_ON(real_count > VBI_DEFLINES); f->tvnorm = tvnorm; diff --git a/drivers/media/pci/bt8xx/bttvp.h b/drivers/media/pci/bt8xx/bttvp.h index 717f002a41df..0368a583cf07 100644 --- a/drivers/media/pci/bt8xx/bttvp.h +++ b/drivers/media/pci/bt8xx/bttvp.h @@ -26,7 +26,7 @@ #include <media/v4l2-common.h> #include <media/v4l2-ctrls.h> #include <media/v4l2-fh.h> -#include <media/videobuf-dma-sg.h> +#include <media/videobuf2-dma-sg.h> #include <media/tveeprom.h> #include <media/rc-core.h> #include <media/i2c/ir-kbd-i2c.h> @@ -142,19 +142,15 @@ struct bttv_geometry { struct bttv_buffer { /* common v4l buffer stuff -- must be first */ - struct videobuf_buffer vb; + struct vb2_v4l2_buffer vbuf; + struct list_head list; /* bttv specific */ - const struct bttv_format *fmt; - unsigned int tvnorm; int btformat; int btswap; struct bttv_geometry geo; struct btcx_riscmem top; struct btcx_riscmem bottom; - struct v4l2_rect crop; - unsigned int vbi_skip[2]; - unsigned int vbi_count[2]; }; struct bttv_buffer_set { @@ -176,6 +172,8 @@ struct bttv_vbi_fmt { }; /* bttv-vbi.c */ +extern const struct vb2_ops bttv_vbi_qops; + void bttv_vbi_fmt_reset(struct bttv_vbi_fmt *f, unsigned int norm); struct bttv_crop { @@ -192,31 +190,6 @@ struct bttv_crop { __s32 max_scaled_height; }; -struct bttv_fh { - /* This must be the first field in this struct */ - struct v4l2_fh fh; - - struct bttv *btv; - int resources; - enum v4l2_buf_type type; - - /* video capture */ - struct videobuf_queue cap; - const struct bttv_format *fmt; - int width; - int height; - - /* Application called VIDIOC_S_SELECTION. */ - int do_crop; - - /* vbi capture */ - struct videobuf_queue vbi; - /* Current VBI capture window as seen through this fh (cannot - be global for compatibility with earlier drivers). Protected - by struct bttv.lock and struct bttv_fh.vbi.lock. */ - struct bttv_vbi_fmt vbi_fmt; -}; - /* ---------------------------------------------------------- */ /* bttv-risc.c */ @@ -237,20 +210,27 @@ int bttv_risc_hook(struct bttv *btv, int slot, struct btcx_riscmem *risc, int bttv_buffer_risc(struct bttv *btv, struct bttv_buffer *buf); int bttv_buffer_activate_video(struct bttv *btv, struct bttv_buffer_set *set); +int bttv_buffer_risc_vbi(struct bttv *btv, struct bttv_buffer *buf); int bttv_buffer_activate_vbi(struct bttv *btv, struct bttv_buffer *vbi); -void bttv_dma_free(struct videobuf_queue *q, struct bttv *btv, - struct bttv_buffer *buf); /* ---------------------------------------------------------- */ /* bttv-vbi.c */ +/* + * 2048 for compatibility with earlier driver versions. The driver really + * stores 1024 + tvnorm->vbipack * 4 samples per line in the buffer. Note + * tvnorm->vbipack is <= 0xFF (limit of VBIPACK_LO + HI is 0x1FF DWORDs) and + * VBI read()s store a frame counter in the last four bytes of the VBI image. + */ +#define VBI_BPL 2048 + +#define VBI_DEFLINES 16 + int bttv_try_fmt_vbi_cap(struct file *file, void *fh, struct v4l2_format *f); int bttv_g_fmt_vbi_cap(struct file *file, void *fh, struct v4l2_format *f); int bttv_s_fmt_vbi_cap(struct file *file, void *fh, struct v4l2_format *f); -extern const struct videobuf_queue_ops bttv_vbi_qops; - /* ---------------------------------------------------------- */ /* bttv-gpio.c */ @@ -275,6 +255,8 @@ extern int fini_bttv_i2c(struct bttv *btv); extern unsigned int bttv_verbose; extern unsigned int bttv_debug; extern unsigned int bttv_gpio; +int check_alloc_btres_lock(struct bttv *btv, int bit); +void free_btres_lock(struct bttv *btv, int bits); extern void bttv_gpio_tracking(struct bttv *btv, char *comment); #define dprintk(fmt, ...) \ @@ -396,7 +378,7 @@ struct bttv { v4l2_std_id std; int hue, contrast, bright, saturation; struct v4l2_framebuffer fbuf; - unsigned int field_count; + __u32 field_count; /* various options */ int opt_combfilter; @@ -436,7 +418,6 @@ struct bttv { int loop_irq; int new_input; - unsigned long cap_ctl; unsigned long dma_on; struct timer_list timeout; struct bttv_suspend_state state; @@ -448,7 +429,25 @@ struct bttv { unsigned int irq_me; unsigned int users; - struct bttv_fh init; + struct v4l2_fh fh; + enum v4l2_buf_type type; + + enum v4l2_field field; + int field_last; + + /* video capture */ + struct vb2_queue capq; + const struct bttv_format *fmt; + int width; + int height; + + /* vbi capture */ + struct vb2_queue vbiq; + struct bttv_vbi_fmt vbi_fmt; + unsigned int vbi_count[2]; + + /* Application called VIDIOC_S_SELECTION. */ + int do_crop; /* used to make dvb-bt8xx autoloadable */ struct work_struct request_module_wk; @@ -487,6 +486,8 @@ static inline unsigned int bttv_muxsel(const struct bttv *btv, #endif +void init_irqreg(struct bttv *btv); + #define btwrite(dat,adr) writel((dat), btv->bt848_mmio+(adr)) #define btread(adr) readl(btv->bt848_mmio+(adr)) diff --git a/drivers/media/pci/cx18/cx18-gpio.c b/drivers/media/pci/cx18/cx18-gpio.c index 160c8377e352..c85eb8d25837 100644 --- a/drivers/media/pci/cx18/cx18-gpio.c +++ b/drivers/media/pci/cx18/cx18-gpio.c @@ -307,7 +307,7 @@ int cx18_gpio_register(struct cx18 *cx, u32 hw) void cx18_reset_ir_gpio(void *data) { - struct cx18 *cx = to_cx18((struct v4l2_device *)data); + struct cx18 *cx = to_cx18(data); if (cx->card->gpio_i2c_slave_reset.ir_reset_mask == 0) return; diff --git a/drivers/media/pci/cx18/cx18-irq.c b/drivers/media/pci/cx18/cx18-irq.c index fb10e9c2c5b8..db63077821b1 100644 --- a/drivers/media/pci/cx18/cx18-irq.c +++ b/drivers/media/pci/cx18/cx18-irq.c @@ -30,7 +30,7 @@ static void epu_cmd(struct cx18 *cx, u32 sw1) irqreturn_t cx18_irq_handler(int irq, void *dev_id) { - struct cx18 *cx = (struct cx18 *)dev_id; + struct cx18 *cx = dev_id; u32 sw1, sw2, hw2; sw1 = cx18_read_reg(cx, SW1_INT_STATUS) & cx->sw1_irq_mask; diff --git a/drivers/media/pci/cx23885/cx23885-core.c b/drivers/media/pci/cx23885/cx23885-core.c index 2ce2914576cf..c8705d786cdd 100644 --- a/drivers/media/pci/cx23885/cx23885-core.c +++ b/drivers/media/pci/cx23885/cx23885-core.c @@ -554,14 +554,14 @@ void cx23885_sram_channel_dump(struct cx23885_dev *dev, for (i = 0; i < 4; i++) { risc = cx_read(ch->cmds_start + 4 * (i + 14)); - pr_warn("%s: risc%d: ", dev->name, i); + pr_warn("%s: risc%d:", dev->name, i); cx23885_risc_decode(risc); } for (i = 0; i < (64 >> 2); i += n) { risc = cx_read(ch->ctrl_start + 4 * i); /* No consideration for bits 63-32 */ - pr_warn("%s: (0x%08x) iq %x: ", dev->name, + pr_warn("%s: (0x%08x) iq %x:", dev->name, ch->ctrl_start + 4 * i, i); n = cx23885_risc_decode(risc); for (j = 1; j < n; j++) { @@ -594,7 +594,7 @@ static void cx23885_risc_disasm(struct cx23885_tsport *port, pr_info("%s: risc disasm: %p [dma=0x%08lx]\n", dev->name, risc->cpu, (unsigned long)risc->dma); for (i = 0; i < (risc->size >> 2); i += n) { - pr_info("%s: %04d: ", dev->name, i); + pr_info("%s: %04d:", dev->name, i); n = cx23885_risc_decode(le32_to_cpu(risc->cpu[i])); for (j = 1; j < n; j++) pr_info("%s: %04d: 0x%08x [ arg #%d ]\n", diff --git a/drivers/media/pci/cx23885/cx23885-video.c b/drivers/media/pci/cx23885/cx23885-video.c index 671fc0588e43..9af2c5596121 100644 --- a/drivers/media/pci/cx23885/cx23885-video.c +++ b/drivers/media/pci/cx23885/cx23885-video.c @@ -413,7 +413,7 @@ static int buffer_prepare(struct vb2_buffer *vb) dev->height >> 1); break; default: - BUG(); + return -EINVAL; /* should not happen */ } dprintk(2, "[%p/%d] buffer_init - %dx%d %dbpp 0x%08x - dma=0x%08lx\n", buf, buf->vb.vb2_buf.index, diff --git a/drivers/media/pci/intel/Kconfig b/drivers/media/pci/intel/Kconfig new file mode 100644 index 000000000000..e113902fa806 --- /dev/null +++ b/drivers/media/pci/intel/Kconfig @@ -0,0 +1,11 @@ +# SPDX-License-Identifier: GPL-2.0-only +config IPU_BRIDGE + tristate + depends on I2C && ACPI + help + This is a helper module for the IPU bridge, which can be + used by ipu3 and other drivers. In order to handle module + dependencies, this is selected by each driver that needs it. + +source "drivers/media/pci/intel/ipu3/Kconfig" +source "drivers/media/pci/intel/ivsc/Kconfig" diff --git a/drivers/media/pci/intel/Makefile b/drivers/media/pci/intel/Makefile index 0b4236c4db49..f199a97e1d78 100644 --- a/drivers/media/pci/intel/Makefile +++ b/drivers/media/pci/intel/Makefile @@ -1,6 +1,7 @@ # SPDX-License-Identifier: GPL-2.0-only # -# Makefile for the IPU3 cio2 and ImGU drivers +# Makefile for the IPU drivers # - +obj-$(CONFIG_IPU_BRIDGE) += ipu-bridge.o obj-y += ipu3/ +obj-y += ivsc/ diff --git a/drivers/media/pci/intel/ipu-bridge.c b/drivers/media/pci/intel/ipu-bridge.c new file mode 100644 index 000000000000..1bde8b6e0b11 --- /dev/null +++ b/drivers/media/pci/intel/ipu-bridge.c @@ -0,0 +1,814 @@ +// SPDX-License-Identifier: GPL-2.0 +/* Author: Dan Scally <djrscally@gmail.com> */ + +#include <linux/acpi.h> +#include <linux/device.h> +#include <linux/i2c.h> +#include <linux/mei_cl_bus.h> +#include <linux/platform_device.h> +#include <linux/pm_runtime.h> +#include <linux/property.h> +#include <linux/string.h> +#include <linux/workqueue.h> + +#include <media/ipu-bridge.h> +#include <media/v4l2-fwnode.h> + +/* + * 92335fcf-3203-4472-af93-7b4453ac29da + * + * Used to build MEI CSI device name to lookup MEI CSI device by + * device_find_child_by_name(). + */ +#define MEI_CSI_UUID \ + UUID_LE(0x92335FCF, 0x3203, 0x4472, \ + 0xAF, 0x93, 0x7B, 0x44, 0x53, 0xAC, 0x29, 0xDA) + +/* + * IVSC device name + * + * Used to match IVSC device by ipu_bridge_match_ivsc_dev() + */ +#define IVSC_DEV_NAME "intel_vsc" + +/* + * Extend this array with ACPI Hardware IDs of devices known to be working + * plus the number of link-frequencies expected by their drivers, along with + * the frequency values in hertz. This is somewhat opportunistic way of adding + * support for this for now in the hopes of a better source for the information + * (possibly some encoded value in the SSDB buffer that we're unaware of) + * becoming apparent in the future. + * + * Do not add an entry for a sensor that is not actually supported. + */ +static const struct ipu_sensor_config ipu_supported_sensors[] = { + /* Omnivision OV5693 */ + IPU_SENSOR_CONFIG("INT33BE", 1, 419200000), + /* Omnivision OV8865 */ + IPU_SENSOR_CONFIG("INT347A", 1, 360000000), + /* Omnivision OV7251 */ + IPU_SENSOR_CONFIG("INT347E", 1, 319200000), + /* Omnivision OV2680 */ + IPU_SENSOR_CONFIG("OVTI2680", 1, 331200000), + /* Omnivision ov8856 */ + IPU_SENSOR_CONFIG("OVTI8856", 3, 180000000, 360000000, 720000000), + /* Omnivision ov2740 */ + IPU_SENSOR_CONFIG("INT3474", 1, 360000000), + /* Hynix hi556 */ + IPU_SENSOR_CONFIG("INT3537", 1, 437000000), + /* Omnivision ov13b10 */ + IPU_SENSOR_CONFIG("OVTIDB10", 1, 560000000), + /* GalaxyCore GC0310 */ + IPU_SENSOR_CONFIG("INT0310", 0), +}; + +static const struct ipu_property_names prop_names = { + .clock_frequency = "clock-frequency", + .rotation = "rotation", + .orientation = "orientation", + .bus_type = "bus-type", + .data_lanes = "data-lanes", + .remote_endpoint = "remote-endpoint", + .link_frequencies = "link-frequencies", +}; + +static const char * const ipu_vcm_types[] = { + "ad5823", + "dw9714", + "ad5816", + "dw9719", + "dw9718", + "dw9806b", + "wv517s", + "lc898122xa", + "lc898212axb", +}; + +/* + * Used to figure out IVSC acpi device by ipu_bridge_get_ivsc_acpi_dev() + * instead of device and driver match to probe IVSC device. + */ +static const struct acpi_device_id ivsc_acpi_ids[] = { + { "INTC1059" }, + { "INTC1095" }, + { "INTC100A" }, + { "INTC10CF" }, +}; + +static struct acpi_device *ipu_bridge_get_ivsc_acpi_dev(struct acpi_device *adev) +{ + acpi_handle handle = acpi_device_handle(adev); + struct acpi_device *consumer, *ivsc_adev; + unsigned int i; + + for (i = 0; i < ARRAY_SIZE(ivsc_acpi_ids); i++) { + const struct acpi_device_id *acpi_id = &ivsc_acpi_ids[i]; + + for_each_acpi_dev_match(ivsc_adev, acpi_id->id, NULL, -1) + /* camera sensor depends on IVSC in DSDT if exist */ + for_each_acpi_consumer_dev(ivsc_adev, consumer) + if (consumer->handle == handle) + return ivsc_adev; + } + + return NULL; +} + +static int ipu_bridge_match_ivsc_dev(struct device *dev, const void *adev) +{ + if (ACPI_COMPANION(dev) != adev) + return 0; + + if (!sysfs_streq(dev_name(dev), IVSC_DEV_NAME)) + return 0; + + return 1; +} + +static struct device *ipu_bridge_get_ivsc_csi_dev(struct acpi_device *adev) +{ + struct device *dev, *csi_dev; + uuid_le uuid = MEI_CSI_UUID; + char name[64]; + + /* IVSC device on platform bus */ + dev = bus_find_device(&platform_bus_type, NULL, adev, + ipu_bridge_match_ivsc_dev); + if (dev) { + snprintf(name, sizeof(name), "%s-%pUl", dev_name(dev), &uuid); + + csi_dev = device_find_child_by_name(dev, name); + + put_device(dev); + + return csi_dev; + } + + return NULL; +} + +static int ipu_bridge_check_ivsc_dev(struct ipu_sensor *sensor, + struct acpi_device *sensor_adev) +{ + struct acpi_device *adev; + struct device *csi_dev; + + adev = ipu_bridge_get_ivsc_acpi_dev(sensor_adev); + if (adev) { + csi_dev = ipu_bridge_get_ivsc_csi_dev(adev); + if (!csi_dev) { + acpi_dev_put(adev); + dev_err(&adev->dev, "Failed to find MEI CSI dev\n"); + return -ENODEV; + } + + sensor->csi_dev = csi_dev; + sensor->ivsc_adev = adev; + } + + return 0; +} + +static int ipu_bridge_read_acpi_buffer(struct acpi_device *adev, char *id, + void *data, u32 size) +{ + struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL }; + union acpi_object *obj; + acpi_status status; + int ret = 0; + + status = acpi_evaluate_object(adev->handle, id, NULL, &buffer); + if (ACPI_FAILURE(status)) + return -ENODEV; + + obj = buffer.pointer; + if (!obj) { + dev_err(&adev->dev, "Couldn't locate ACPI buffer\n"); + return -ENODEV; + } + + if (obj->type != ACPI_TYPE_BUFFER) { + dev_err(&adev->dev, "Not an ACPI buffer\n"); + ret = -ENODEV; + goto out_free_buff; + } + + if (obj->buffer.length > size) { + dev_err(&adev->dev, "Given buffer is too small\n"); + ret = -EINVAL; + goto out_free_buff; + } + + memcpy(data, obj->buffer.pointer, obj->buffer.length); + +out_free_buff: + kfree(buffer.pointer); + return ret; +} + +static u32 ipu_bridge_parse_rotation(struct acpi_device *adev, + struct ipu_sensor_ssdb *ssdb) +{ + switch (ssdb->degree) { + case IPU_SENSOR_ROTATION_NORMAL: + return 0; + case IPU_SENSOR_ROTATION_INVERTED: + return 180; + default: + dev_warn(&adev->dev, + "Unknown rotation %d. Assume 0 degree rotation\n", + ssdb->degree); + return 0; + } +} + +static enum v4l2_fwnode_orientation ipu_bridge_parse_orientation(struct acpi_device *adev) +{ + enum v4l2_fwnode_orientation orientation; + struct acpi_pld_info *pld; + acpi_status status; + + status = acpi_get_physical_device_location(adev->handle, &pld); + if (ACPI_FAILURE(status)) { + dev_warn(&adev->dev, "_PLD call failed, using default orientation\n"); + return V4L2_FWNODE_ORIENTATION_EXTERNAL; + } + + switch (pld->panel) { + case ACPI_PLD_PANEL_FRONT: + orientation = V4L2_FWNODE_ORIENTATION_FRONT; + break; + case ACPI_PLD_PANEL_BACK: + orientation = V4L2_FWNODE_ORIENTATION_BACK; + break; + case ACPI_PLD_PANEL_TOP: + case ACPI_PLD_PANEL_LEFT: + case ACPI_PLD_PANEL_RIGHT: + case ACPI_PLD_PANEL_UNKNOWN: + orientation = V4L2_FWNODE_ORIENTATION_EXTERNAL; + break; + default: + dev_warn(&adev->dev, "Unknown _PLD panel val %d\n", pld->panel); + orientation = V4L2_FWNODE_ORIENTATION_EXTERNAL; + break; + } + + ACPI_FREE(pld); + return orientation; +} + +int ipu_bridge_parse_ssdb(struct acpi_device *adev, struct ipu_sensor *sensor) +{ + struct ipu_sensor_ssdb ssdb = {}; + int ret; + + ret = ipu_bridge_read_acpi_buffer(adev, "SSDB", &ssdb, sizeof(ssdb)); + if (ret) + return ret; + + if (ssdb.vcmtype > ARRAY_SIZE(ipu_vcm_types)) { + dev_warn(&adev->dev, "Unknown VCM type %d\n", ssdb.vcmtype); + ssdb.vcmtype = 0; + } + + if (ssdb.lanes > IPU_MAX_LANES) { + dev_err(&adev->dev, "Number of lanes in SSDB is invalid\n"); + return -EINVAL; + } + + sensor->link = ssdb.link; + sensor->lanes = ssdb.lanes; + sensor->mclkspeed = ssdb.mclkspeed; + sensor->rotation = ipu_bridge_parse_rotation(adev, &ssdb); + sensor->orientation = ipu_bridge_parse_orientation(adev); + + if (ssdb.vcmtype) + sensor->vcm_type = ipu_vcm_types[ssdb.vcmtype - 1]; + + return 0; +} +EXPORT_SYMBOL_NS_GPL(ipu_bridge_parse_ssdb, INTEL_IPU_BRIDGE); + +static void ipu_bridge_create_fwnode_properties( + struct ipu_sensor *sensor, + struct ipu_bridge *bridge, + const struct ipu_sensor_config *cfg) +{ + struct ipu_property_names *names = &sensor->prop_names; + struct software_node *nodes = sensor->swnodes; + + sensor->prop_names = prop_names; + + if (sensor->csi_dev) { + sensor->local_ref[0] = + SOFTWARE_NODE_REFERENCE(&nodes[SWNODE_IVSC_SENSOR_ENDPOINT]); + sensor->remote_ref[0] = + SOFTWARE_NODE_REFERENCE(&nodes[SWNODE_IVSC_IPU_ENDPOINT]); + sensor->ivsc_sensor_ref[0] = + SOFTWARE_NODE_REFERENCE(&nodes[SWNODE_SENSOR_ENDPOINT]); + sensor->ivsc_ipu_ref[0] = + SOFTWARE_NODE_REFERENCE(&nodes[SWNODE_IPU_ENDPOINT]); + + sensor->ivsc_sensor_ep_properties[0] = + PROPERTY_ENTRY_U32(names->bus_type, + V4L2_FWNODE_BUS_TYPE_CSI2_DPHY); + sensor->ivsc_sensor_ep_properties[1] = + PROPERTY_ENTRY_U32_ARRAY_LEN(names->data_lanes, + bridge->data_lanes, + sensor->lanes); + sensor->ivsc_sensor_ep_properties[2] = + PROPERTY_ENTRY_REF_ARRAY(names->remote_endpoint, + sensor->ivsc_sensor_ref); + + sensor->ivsc_ipu_ep_properties[0] = + PROPERTY_ENTRY_U32(names->bus_type, + V4L2_FWNODE_BUS_TYPE_CSI2_DPHY); + sensor->ivsc_ipu_ep_properties[1] = + PROPERTY_ENTRY_U32_ARRAY_LEN(names->data_lanes, + bridge->data_lanes, + sensor->lanes); + sensor->ivsc_ipu_ep_properties[2] = + PROPERTY_ENTRY_REF_ARRAY(names->remote_endpoint, + sensor->ivsc_ipu_ref); + } else { + sensor->local_ref[0] = + SOFTWARE_NODE_REFERENCE(&nodes[SWNODE_IPU_ENDPOINT]); + sensor->remote_ref[0] = + SOFTWARE_NODE_REFERENCE(&nodes[SWNODE_SENSOR_ENDPOINT]); + } + + sensor->dev_properties[0] = PROPERTY_ENTRY_U32( + sensor->prop_names.clock_frequency, + sensor->mclkspeed); + sensor->dev_properties[1] = PROPERTY_ENTRY_U32( + sensor->prop_names.rotation, + sensor->rotation); + sensor->dev_properties[2] = PROPERTY_ENTRY_U32( + sensor->prop_names.orientation, + sensor->orientation); + if (sensor->vcm_type) { + sensor->vcm_ref[0] = + SOFTWARE_NODE_REFERENCE(&sensor->swnodes[SWNODE_VCM]); + sensor->dev_properties[3] = + PROPERTY_ENTRY_REF_ARRAY("lens-focus", sensor->vcm_ref); + } + + sensor->ep_properties[0] = PROPERTY_ENTRY_U32( + sensor->prop_names.bus_type, + V4L2_FWNODE_BUS_TYPE_CSI2_DPHY); + sensor->ep_properties[1] = PROPERTY_ENTRY_U32_ARRAY_LEN( + sensor->prop_names.data_lanes, + bridge->data_lanes, sensor->lanes); + sensor->ep_properties[2] = PROPERTY_ENTRY_REF_ARRAY( + sensor->prop_names.remote_endpoint, + sensor->local_ref); + + if (cfg->nr_link_freqs > 0) + sensor->ep_properties[3] = PROPERTY_ENTRY_U64_ARRAY_LEN( + sensor->prop_names.link_frequencies, + cfg->link_freqs, + cfg->nr_link_freqs); + + sensor->ipu_properties[0] = PROPERTY_ENTRY_U32_ARRAY_LEN( + sensor->prop_names.data_lanes, + bridge->data_lanes, sensor->lanes); + sensor->ipu_properties[1] = PROPERTY_ENTRY_REF_ARRAY( + sensor->prop_names.remote_endpoint, + sensor->remote_ref); +} + +static void ipu_bridge_init_swnode_names(struct ipu_sensor *sensor) +{ + snprintf(sensor->node_names.remote_port, + sizeof(sensor->node_names.remote_port), + SWNODE_GRAPH_PORT_NAME_FMT, sensor->link); + snprintf(sensor->node_names.port, + sizeof(sensor->node_names.port), + SWNODE_GRAPH_PORT_NAME_FMT, 0); /* Always port 0 */ + snprintf(sensor->node_names.endpoint, + sizeof(sensor->node_names.endpoint), + SWNODE_GRAPH_ENDPOINT_NAME_FMT, 0); /* And endpoint 0 */ + if (sensor->vcm_type) { + /* append link to distinguish nodes with same model VCM */ + snprintf(sensor->node_names.vcm, sizeof(sensor->node_names.vcm), + "%s-%u", sensor->vcm_type, sensor->link); + } + + if (sensor->csi_dev) { + snprintf(sensor->node_names.ivsc_sensor_port, + sizeof(sensor->node_names.ivsc_sensor_port), + SWNODE_GRAPH_PORT_NAME_FMT, 0); + snprintf(sensor->node_names.ivsc_ipu_port, + sizeof(sensor->node_names.ivsc_ipu_port), + SWNODE_GRAPH_PORT_NAME_FMT, 1); + } +} + +static void ipu_bridge_init_swnode_group(struct ipu_sensor *sensor) +{ + struct software_node *nodes = sensor->swnodes; + + sensor->group[SWNODE_SENSOR_HID] = &nodes[SWNODE_SENSOR_HID]; + sensor->group[SWNODE_SENSOR_PORT] = &nodes[SWNODE_SENSOR_PORT]; + sensor->group[SWNODE_SENSOR_ENDPOINT] = &nodes[SWNODE_SENSOR_ENDPOINT]; + sensor->group[SWNODE_IPU_PORT] = &nodes[SWNODE_IPU_PORT]; + sensor->group[SWNODE_IPU_ENDPOINT] = &nodes[SWNODE_IPU_ENDPOINT]; + if (sensor->vcm_type) + sensor->group[SWNODE_VCM] = &nodes[SWNODE_VCM]; + + if (sensor->csi_dev) { + sensor->group[SWNODE_IVSC_HID] = + &nodes[SWNODE_IVSC_HID]; + sensor->group[SWNODE_IVSC_SENSOR_PORT] = + &nodes[SWNODE_IVSC_SENSOR_PORT]; + sensor->group[SWNODE_IVSC_SENSOR_ENDPOINT] = + &nodes[SWNODE_IVSC_SENSOR_ENDPOINT]; + sensor->group[SWNODE_IVSC_IPU_PORT] = + &nodes[SWNODE_IVSC_IPU_PORT]; + sensor->group[SWNODE_IVSC_IPU_ENDPOINT] = + &nodes[SWNODE_IVSC_IPU_ENDPOINT]; + + if (sensor->vcm_type) + sensor->group[SWNODE_VCM] = &nodes[SWNODE_VCM]; + } else { + if (sensor->vcm_type) + sensor->group[SWNODE_IVSC_HID] = &nodes[SWNODE_VCM]; + } +} + +static void ipu_bridge_create_connection_swnodes(struct ipu_bridge *bridge, + struct ipu_sensor *sensor) +{ + struct ipu_node_names *names = &sensor->node_names; + struct software_node *nodes = sensor->swnodes; + + ipu_bridge_init_swnode_names(sensor); + + nodes[SWNODE_SENSOR_HID] = NODE_SENSOR(sensor->name, + sensor->dev_properties); + nodes[SWNODE_SENSOR_PORT] = NODE_PORT(sensor->node_names.port, + &nodes[SWNODE_SENSOR_HID]); + nodes[SWNODE_SENSOR_ENDPOINT] = NODE_ENDPOINT( + sensor->node_names.endpoint, + &nodes[SWNODE_SENSOR_PORT], + sensor->ep_properties); + nodes[SWNODE_IPU_PORT] = NODE_PORT(sensor->node_names.remote_port, + &bridge->ipu_hid_node); + nodes[SWNODE_IPU_ENDPOINT] = NODE_ENDPOINT( + sensor->node_names.endpoint, + &nodes[SWNODE_IPU_PORT], + sensor->ipu_properties); + + if (sensor->csi_dev) { + snprintf(sensor->ivsc_name, sizeof(sensor->ivsc_name), "%s-%u", + acpi_device_hid(sensor->ivsc_adev), sensor->link); + + nodes[SWNODE_IVSC_HID] = NODE_SENSOR(sensor->ivsc_name, + sensor->ivsc_properties); + nodes[SWNODE_IVSC_SENSOR_PORT] = + NODE_PORT(names->ivsc_sensor_port, + &nodes[SWNODE_IVSC_HID]); + nodes[SWNODE_IVSC_SENSOR_ENDPOINT] = + NODE_ENDPOINT(names->endpoint, + &nodes[SWNODE_IVSC_SENSOR_PORT], + sensor->ivsc_sensor_ep_properties); + nodes[SWNODE_IVSC_IPU_PORT] = + NODE_PORT(names->ivsc_ipu_port, + &nodes[SWNODE_IVSC_HID]); + nodes[SWNODE_IVSC_IPU_ENDPOINT] = + NODE_ENDPOINT(names->endpoint, + &nodes[SWNODE_IVSC_IPU_PORT], + sensor->ivsc_ipu_ep_properties); + } + + nodes[SWNODE_VCM] = NODE_VCM(sensor->node_names.vcm); + + ipu_bridge_init_swnode_group(sensor); +} + +/* + * The actual instantiation must be done from a workqueue to avoid + * a deadlock on taking list_lock from v4l2-async twice. + */ +struct ipu_bridge_instantiate_vcm_work_data { + struct work_struct work; + struct device *sensor; + char name[16]; + struct i2c_board_info board_info; +}; + +static void ipu_bridge_instantiate_vcm_work(struct work_struct *work) +{ + struct ipu_bridge_instantiate_vcm_work_data *data = + container_of(work, struct ipu_bridge_instantiate_vcm_work_data, + work); + struct acpi_device *adev = ACPI_COMPANION(data->sensor); + struct i2c_client *vcm_client; + bool put_fwnode = true; + int ret; + + /* + * The client may get probed before the device_link gets added below + * make sure the sensor is powered-up during probe. + */ + ret = pm_runtime_get_sync(data->sensor); + if (ret < 0) { + dev_err(data->sensor, "Error %d runtime-resuming sensor, cannot instantiate VCM\n", + ret); + goto out_pm_put; + } + + /* + * Note the client is created only once and then kept around + * even after a rmmod, just like the software-nodes. + */ + vcm_client = i2c_acpi_new_device_by_fwnode(acpi_fwnode_handle(adev), + 1, &data->board_info); + if (IS_ERR(vcm_client)) { + dev_err(data->sensor, "Error instantiating VCM client: %ld\n", + PTR_ERR(vcm_client)); + goto out_pm_put; + } + + device_link_add(&vcm_client->dev, data->sensor, DL_FLAG_PM_RUNTIME); + + dev_info(data->sensor, "Instantiated %s VCM\n", data->board_info.type); + put_fwnode = false; /* Ownership has passed to the i2c-client */ + +out_pm_put: + pm_runtime_put(data->sensor); + put_device(data->sensor); + if (put_fwnode) + fwnode_handle_put(data->board_info.fwnode); + kfree(data); +} + +int ipu_bridge_instantiate_vcm(struct device *sensor) +{ + struct ipu_bridge_instantiate_vcm_work_data *data; + struct fwnode_handle *vcm_fwnode; + struct i2c_client *vcm_client; + struct acpi_device *adev; + char *sep; + + adev = ACPI_COMPANION(sensor); + if (!adev) + return 0; + + vcm_fwnode = fwnode_find_reference(dev_fwnode(sensor), "lens-focus", 0); + if (IS_ERR(vcm_fwnode)) + return 0; + + /* When reloading modules the client will already exist */ + vcm_client = i2c_find_device_by_fwnode(vcm_fwnode); + if (vcm_client) { + fwnode_handle_put(vcm_fwnode); + put_device(&vcm_client->dev); + return 0; + } + + data = kzalloc(sizeof(*data), GFP_KERNEL); + if (!data) { + fwnode_handle_put(vcm_fwnode); + return -ENOMEM; + } + + INIT_WORK(&data->work, ipu_bridge_instantiate_vcm_work); + data->sensor = get_device(sensor); + snprintf(data->name, sizeof(data->name), "%s-VCM", + acpi_dev_name(adev)); + data->board_info.dev_name = data->name; + data->board_info.fwnode = vcm_fwnode; + snprintf(data->board_info.type, sizeof(data->board_info.type), + "%pfwP", vcm_fwnode); + /* Strip "-<link>" postfix */ + sep = strchrnul(data->board_info.type, '-'); + *sep = 0; + + queue_work(system_long_wq, &data->work); + + return 0; +} +EXPORT_SYMBOL_NS_GPL(ipu_bridge_instantiate_vcm, INTEL_IPU_BRIDGE); + +static int ipu_bridge_instantiate_ivsc(struct ipu_sensor *sensor) +{ + struct fwnode_handle *fwnode; + + if (!sensor->csi_dev) + return 0; + + fwnode = software_node_fwnode(&sensor->swnodes[SWNODE_IVSC_HID]); + if (!fwnode) + return -ENODEV; + + set_secondary_fwnode(sensor->csi_dev, fwnode); + + return 0; +} + +static void ipu_bridge_unregister_sensors(struct ipu_bridge *bridge) +{ + struct ipu_sensor *sensor; + unsigned int i; + + for (i = 0; i < bridge->n_sensors; i++) { + sensor = &bridge->sensors[i]; + software_node_unregister_node_group(sensor->group); + acpi_dev_put(sensor->adev); + put_device(sensor->csi_dev); + acpi_dev_put(sensor->ivsc_adev); + } +} + +static int ipu_bridge_connect_sensor(const struct ipu_sensor_config *cfg, + struct ipu_bridge *bridge) +{ + struct fwnode_handle *fwnode, *primary; + struct ipu_sensor *sensor; + struct acpi_device *adev; + int ret; + + for_each_acpi_dev_match(adev, cfg->hid, NULL, -1) { + if (!adev->status.enabled) + continue; + + if (bridge->n_sensors >= IPU_MAX_PORTS) { + acpi_dev_put(adev); + dev_err(bridge->dev, "Exceeded available IPU ports\n"); + return -EINVAL; + } + + sensor = &bridge->sensors[bridge->n_sensors]; + + ret = bridge->parse_sensor_fwnode(adev, sensor); + if (ret) + goto err_put_adev; + + snprintf(sensor->name, sizeof(sensor->name), "%s-%u", + cfg->hid, sensor->link); + + ret = ipu_bridge_check_ivsc_dev(sensor, adev); + if (ret) + goto err_put_adev; + + ipu_bridge_create_fwnode_properties(sensor, bridge, cfg); + ipu_bridge_create_connection_swnodes(bridge, sensor); + + ret = software_node_register_node_group(sensor->group); + if (ret) + goto err_put_ivsc; + + fwnode = software_node_fwnode(&sensor->swnodes[ + SWNODE_SENSOR_HID]); + if (!fwnode) { + ret = -ENODEV; + goto err_free_swnodes; + } + + sensor->adev = acpi_dev_get(adev); + + primary = acpi_fwnode_handle(adev); + primary->secondary = fwnode; + + ret = ipu_bridge_instantiate_ivsc(sensor); + if (ret) + goto err_free_swnodes; + + dev_info(bridge->dev, "Found supported sensor %s\n", + acpi_dev_name(adev)); + + bridge->n_sensors++; + } + + return 0; + +err_free_swnodes: + software_node_unregister_node_group(sensor->group); +err_put_ivsc: + put_device(sensor->csi_dev); + acpi_dev_put(sensor->ivsc_adev); +err_put_adev: + acpi_dev_put(adev); + return ret; +} + +static int ipu_bridge_connect_sensors(struct ipu_bridge *bridge) +{ + unsigned int i; + int ret; + + for (i = 0; i < ARRAY_SIZE(ipu_supported_sensors); i++) { + const struct ipu_sensor_config *cfg = + &ipu_supported_sensors[i]; + + ret = ipu_bridge_connect_sensor(cfg, bridge); + if (ret) + goto err_unregister_sensors; + } + + return 0; + +err_unregister_sensors: + ipu_bridge_unregister_sensors(bridge); + return ret; +} + +static int ipu_bridge_ivsc_is_ready(void) +{ + struct acpi_device *sensor_adev, *adev; + struct device *csi_dev; + bool ready = true; + unsigned int i; + + for (i = 0; i < ARRAY_SIZE(ipu_supported_sensors); i++) { + const struct ipu_sensor_config *cfg = + &ipu_supported_sensors[i]; + + for_each_acpi_dev_match(sensor_adev, cfg->hid, NULL, -1) { + if (!sensor_adev->status.enabled) + continue; + + adev = ipu_bridge_get_ivsc_acpi_dev(sensor_adev); + if (!adev) + continue; + + csi_dev = ipu_bridge_get_ivsc_csi_dev(adev); + if (!csi_dev) + ready = false; + + put_device(csi_dev); + acpi_dev_put(adev); + } + } + + return ready; +} + +int ipu_bridge_init(struct device *dev, + ipu_parse_sensor_fwnode_t parse_sensor_fwnode) +{ + struct fwnode_handle *fwnode; + struct ipu_bridge *bridge; + unsigned int i; + int ret; + + if (!ipu_bridge_ivsc_is_ready()) + return -EPROBE_DEFER; + + bridge = kzalloc(sizeof(*bridge), GFP_KERNEL); + if (!bridge) + return -ENOMEM; + + strscpy(bridge->ipu_node_name, IPU_HID, + sizeof(bridge->ipu_node_name)); + bridge->ipu_hid_node.name = bridge->ipu_node_name; + bridge->dev = dev; + bridge->parse_sensor_fwnode = parse_sensor_fwnode; + + ret = software_node_register(&bridge->ipu_hid_node); + if (ret < 0) { + dev_err(dev, "Failed to register the IPU HID node\n"); + goto err_free_bridge; + } + + /* + * Map the lane arrangement, which is fixed for the IPU3 (meaning we + * only need one, rather than one per sensor). We include it as a + * member of the struct ipu_bridge rather than a global variable so + * that it survives if the module is unloaded along with the rest of + * the struct. + */ + for (i = 0; i < IPU_MAX_LANES; i++) + bridge->data_lanes[i] = i + 1; + + ret = ipu_bridge_connect_sensors(bridge); + if (ret || bridge->n_sensors == 0) + goto err_unregister_ipu; + + dev_info(dev, "Connected %d cameras\n", bridge->n_sensors); + + fwnode = software_node_fwnode(&bridge->ipu_hid_node); + if (!fwnode) { + dev_err(dev, "Error getting fwnode from ipu software_node\n"); + ret = -ENODEV; + goto err_unregister_sensors; + } + + set_secondary_fwnode(dev, fwnode); + + return 0; + +err_unregister_sensors: + ipu_bridge_unregister_sensors(bridge); +err_unregister_ipu: + software_node_unregister(&bridge->ipu_hid_node); +err_free_bridge: + kfree(bridge); + + return ret; +} +EXPORT_SYMBOL_NS_GPL(ipu_bridge_init, INTEL_IPU_BRIDGE); + +MODULE_LICENSE("GPL"); +MODULE_DESCRIPTION("Intel IPU Sensors Bridge driver"); diff --git a/drivers/media/pci/intel/ipu3/Kconfig b/drivers/media/pci/intel/ipu3/Kconfig index 65b0c1598fbf..0951545eab21 100644 --- a/drivers/media/pci/intel/ipu3/Kconfig +++ b/drivers/media/pci/intel/ipu3/Kconfig @@ -8,6 +8,7 @@ config VIDEO_IPU3_CIO2 select VIDEO_V4L2_SUBDEV_API select V4L2_FWNODE select VIDEOBUF2_DMA_SG + select IPU_BRIDGE if CIO2_BRIDGE help This is the Intel IPU3 CIO2 CSI-2 receiver unit, found in Intel diff --git a/drivers/media/pci/intel/ipu3/Makefile b/drivers/media/pci/intel/ipu3/Makefile index 933777e6ea8a..98ddd5beafe0 100644 --- a/drivers/media/pci/intel/ipu3/Makefile +++ b/drivers/media/pci/intel/ipu3/Makefile @@ -1,5 +1,2 @@ # SPDX-License-Identifier: GPL-2.0-only obj-$(CONFIG_VIDEO_IPU3_CIO2) += ipu3-cio2.o - -ipu3-cio2-y += ipu3-cio2-main.o -ipu3-cio2-$(CONFIG_CIO2_BRIDGE) += cio2-bridge.o diff --git a/drivers/media/pci/intel/ipu3/cio2-bridge.c b/drivers/media/pci/intel/ipu3/cio2-bridge.c deleted file mode 100644 index 3c2accfe5455..000000000000 --- a/drivers/media/pci/intel/ipu3/cio2-bridge.c +++ /dev/null @@ -1,494 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -/* Author: Dan Scally <djrscally@gmail.com> */ - -#include <linux/acpi.h> -#include <linux/device.h> -#include <linux/i2c.h> -#include <linux/pci.h> -#include <linux/property.h> -#include <media/v4l2-fwnode.h> - -#include "cio2-bridge.h" - -/* - * Extend this array with ACPI Hardware IDs of devices known to be working - * plus the number of link-frequencies expected by their drivers, along with - * the frequency values in hertz. This is somewhat opportunistic way of adding - * support for this for now in the hopes of a better source for the information - * (possibly some encoded value in the SSDB buffer that we're unaware of) - * becoming apparent in the future. - * - * Do not add an entry for a sensor that is not actually supported. - */ -static const struct cio2_sensor_config cio2_supported_sensors[] = { - /* Omnivision OV5693 */ - CIO2_SENSOR_CONFIG("INT33BE", 1, 419200000), - /* Omnivision OV8865 */ - CIO2_SENSOR_CONFIG("INT347A", 1, 360000000), - /* Omnivision OV7251 */ - CIO2_SENSOR_CONFIG("INT347E", 1, 319200000), - /* Omnivision OV2680 */ - CIO2_SENSOR_CONFIG("OVTI2680", 0), - /* Omnivision ov8856 */ - CIO2_SENSOR_CONFIG("OVTI8856", 3, 180000000, 360000000, 720000000), - /* Omnivision ov2740 */ - CIO2_SENSOR_CONFIG("INT3474", 1, 360000000), - /* Hynix hi556 */ - CIO2_SENSOR_CONFIG("INT3537", 1, 437000000), - /* Omnivision ov13b10 */ - CIO2_SENSOR_CONFIG("OVTIDB10", 1, 560000000), -}; - -static const struct cio2_property_names prop_names = { - .clock_frequency = "clock-frequency", - .rotation = "rotation", - .orientation = "orientation", - .bus_type = "bus-type", - .data_lanes = "data-lanes", - .remote_endpoint = "remote-endpoint", - .link_frequencies = "link-frequencies", -}; - -static const char * const cio2_vcm_types[] = { - "ad5823", - "dw9714", - "ad5816", - "dw9719", - "dw9718", - "dw9806b", - "wv517s", - "lc898122xa", - "lc898212axb", -}; - -static int cio2_bridge_read_acpi_buffer(struct acpi_device *adev, char *id, - void *data, u32 size) -{ - struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL }; - union acpi_object *obj; - acpi_status status; - int ret = 0; - - status = acpi_evaluate_object(adev->handle, id, NULL, &buffer); - if (ACPI_FAILURE(status)) - return -ENODEV; - - obj = buffer.pointer; - if (!obj) { - dev_err(&adev->dev, "Couldn't locate ACPI buffer\n"); - return -ENODEV; - } - - if (obj->type != ACPI_TYPE_BUFFER) { - dev_err(&adev->dev, "Not an ACPI buffer\n"); - ret = -ENODEV; - goto out_free_buff; - } - - if (obj->buffer.length > size) { - dev_err(&adev->dev, "Given buffer is too small\n"); - ret = -EINVAL; - goto out_free_buff; - } - - memcpy(data, obj->buffer.pointer, obj->buffer.length); - -out_free_buff: - kfree(buffer.pointer); - return ret; -} - -static u32 cio2_bridge_parse_rotation(struct cio2_sensor *sensor) -{ - switch (sensor->ssdb.degree) { - case CIO2_SENSOR_ROTATION_NORMAL: - return 0; - case CIO2_SENSOR_ROTATION_INVERTED: - return 180; - default: - dev_warn(&sensor->adev->dev, - "Unknown rotation %d. Assume 0 degree rotation\n", - sensor->ssdb.degree); - return 0; - } -} - -static enum v4l2_fwnode_orientation cio2_bridge_parse_orientation(struct cio2_sensor *sensor) -{ - switch (sensor->pld->panel) { - case ACPI_PLD_PANEL_FRONT: - return V4L2_FWNODE_ORIENTATION_FRONT; - case ACPI_PLD_PANEL_BACK: - return V4L2_FWNODE_ORIENTATION_BACK; - case ACPI_PLD_PANEL_TOP: - case ACPI_PLD_PANEL_LEFT: - case ACPI_PLD_PANEL_RIGHT: - case ACPI_PLD_PANEL_UNKNOWN: - return V4L2_FWNODE_ORIENTATION_EXTERNAL; - default: - dev_warn(&sensor->adev->dev, "Unknown _PLD panel value %d\n", - sensor->pld->panel); - return V4L2_FWNODE_ORIENTATION_EXTERNAL; - } -} - -static void cio2_bridge_create_fwnode_properties( - struct cio2_sensor *sensor, - struct cio2_bridge *bridge, - const struct cio2_sensor_config *cfg) -{ - u32 rotation; - enum v4l2_fwnode_orientation orientation; - - rotation = cio2_bridge_parse_rotation(sensor); - orientation = cio2_bridge_parse_orientation(sensor); - - sensor->prop_names = prop_names; - - sensor->local_ref[0] = SOFTWARE_NODE_REFERENCE(&sensor->swnodes[SWNODE_CIO2_ENDPOINT]); - sensor->remote_ref[0] = SOFTWARE_NODE_REFERENCE(&sensor->swnodes[SWNODE_SENSOR_ENDPOINT]); - - sensor->dev_properties[0] = PROPERTY_ENTRY_U32( - sensor->prop_names.clock_frequency, - sensor->ssdb.mclkspeed); - sensor->dev_properties[1] = PROPERTY_ENTRY_U32( - sensor->prop_names.rotation, - rotation); - sensor->dev_properties[2] = PROPERTY_ENTRY_U32( - sensor->prop_names.orientation, - orientation); - if (sensor->ssdb.vcmtype) { - sensor->vcm_ref[0] = - SOFTWARE_NODE_REFERENCE(&sensor->swnodes[SWNODE_VCM]); - sensor->dev_properties[3] = - PROPERTY_ENTRY_REF_ARRAY("lens-focus", sensor->vcm_ref); - } - - sensor->ep_properties[0] = PROPERTY_ENTRY_U32( - sensor->prop_names.bus_type, - V4L2_FWNODE_BUS_TYPE_CSI2_DPHY); - sensor->ep_properties[1] = PROPERTY_ENTRY_U32_ARRAY_LEN( - sensor->prop_names.data_lanes, - bridge->data_lanes, - sensor->ssdb.lanes); - sensor->ep_properties[2] = PROPERTY_ENTRY_REF_ARRAY( - sensor->prop_names.remote_endpoint, - sensor->local_ref); - - if (cfg->nr_link_freqs > 0) - sensor->ep_properties[3] = PROPERTY_ENTRY_U64_ARRAY_LEN( - sensor->prop_names.link_frequencies, - cfg->link_freqs, - cfg->nr_link_freqs); - - sensor->cio2_properties[0] = PROPERTY_ENTRY_U32_ARRAY_LEN( - sensor->prop_names.data_lanes, - bridge->data_lanes, - sensor->ssdb.lanes); - sensor->cio2_properties[1] = PROPERTY_ENTRY_REF_ARRAY( - sensor->prop_names.remote_endpoint, - sensor->remote_ref); -} - -static void cio2_bridge_init_swnode_names(struct cio2_sensor *sensor) -{ - snprintf(sensor->node_names.remote_port, - sizeof(sensor->node_names.remote_port), - SWNODE_GRAPH_PORT_NAME_FMT, sensor->ssdb.link); - snprintf(sensor->node_names.port, - sizeof(sensor->node_names.port), - SWNODE_GRAPH_PORT_NAME_FMT, 0); /* Always port 0 */ - snprintf(sensor->node_names.endpoint, - sizeof(sensor->node_names.endpoint), - SWNODE_GRAPH_ENDPOINT_NAME_FMT, 0); /* And endpoint 0 */ -} - -static void cio2_bridge_init_swnode_group(struct cio2_sensor *sensor) -{ - struct software_node *nodes = sensor->swnodes; - - sensor->group[SWNODE_SENSOR_HID] = &nodes[SWNODE_SENSOR_HID]; - sensor->group[SWNODE_SENSOR_PORT] = &nodes[SWNODE_SENSOR_PORT]; - sensor->group[SWNODE_SENSOR_ENDPOINT] = &nodes[SWNODE_SENSOR_ENDPOINT]; - sensor->group[SWNODE_CIO2_PORT] = &nodes[SWNODE_CIO2_PORT]; - sensor->group[SWNODE_CIO2_ENDPOINT] = &nodes[SWNODE_CIO2_ENDPOINT]; - if (sensor->ssdb.vcmtype) - sensor->group[SWNODE_VCM] = &nodes[SWNODE_VCM]; -} - -static void cio2_bridge_create_connection_swnodes(struct cio2_bridge *bridge, - struct cio2_sensor *sensor) -{ - struct software_node *nodes = sensor->swnodes; - char vcm_name[ACPI_ID_LEN + 4]; - - cio2_bridge_init_swnode_names(sensor); - - nodes[SWNODE_SENSOR_HID] = NODE_SENSOR(sensor->name, - sensor->dev_properties); - nodes[SWNODE_SENSOR_PORT] = NODE_PORT(sensor->node_names.port, - &nodes[SWNODE_SENSOR_HID]); - nodes[SWNODE_SENSOR_ENDPOINT] = NODE_ENDPOINT( - sensor->node_names.endpoint, - &nodes[SWNODE_SENSOR_PORT], - sensor->ep_properties); - nodes[SWNODE_CIO2_PORT] = NODE_PORT(sensor->node_names.remote_port, - &bridge->cio2_hid_node); - nodes[SWNODE_CIO2_ENDPOINT] = NODE_ENDPOINT( - sensor->node_names.endpoint, - &nodes[SWNODE_CIO2_PORT], - sensor->cio2_properties); - if (sensor->ssdb.vcmtype) { - /* append ssdb.link to distinguish VCM nodes with same HID */ - snprintf(vcm_name, sizeof(vcm_name), "%s-%u", - cio2_vcm_types[sensor->ssdb.vcmtype - 1], - sensor->ssdb.link); - nodes[SWNODE_VCM] = NODE_VCM(vcm_name); - } - - cio2_bridge_init_swnode_group(sensor); -} - -static void cio2_bridge_instantiate_vcm_i2c_client(struct cio2_sensor *sensor) -{ - struct i2c_board_info board_info = { }; - char name[16]; - - if (!sensor->ssdb.vcmtype) - return; - - snprintf(name, sizeof(name), "%s-VCM", acpi_dev_name(sensor->adev)); - board_info.dev_name = name; - strscpy(board_info.type, cio2_vcm_types[sensor->ssdb.vcmtype - 1], - ARRAY_SIZE(board_info.type)); - board_info.swnode = &sensor->swnodes[SWNODE_VCM]; - - sensor->vcm_i2c_client = - i2c_acpi_new_device_by_fwnode(acpi_fwnode_handle(sensor->adev), - 1, &board_info); - if (IS_ERR(sensor->vcm_i2c_client)) { - dev_warn(&sensor->adev->dev, "Error instantiation VCM i2c-client: %ld\n", - PTR_ERR(sensor->vcm_i2c_client)); - sensor->vcm_i2c_client = NULL; - } -} - -static void cio2_bridge_unregister_sensors(struct cio2_bridge *bridge) -{ - struct cio2_sensor *sensor; - unsigned int i; - - for (i = 0; i < bridge->n_sensors; i++) { - sensor = &bridge->sensors[i]; - software_node_unregister_node_group(sensor->group); - ACPI_FREE(sensor->pld); - acpi_dev_put(sensor->adev); - i2c_unregister_device(sensor->vcm_i2c_client); - } -} - -static int cio2_bridge_connect_sensor(const struct cio2_sensor_config *cfg, - struct cio2_bridge *bridge, - struct pci_dev *cio2) -{ - struct fwnode_handle *fwnode, *primary; - struct cio2_sensor *sensor; - struct acpi_device *adev; - acpi_status status; - int ret; - - for_each_acpi_dev_match(adev, cfg->hid, NULL, -1) { - if (!adev->status.enabled) - continue; - - if (bridge->n_sensors >= CIO2_NUM_PORTS) { - acpi_dev_put(adev); - dev_err(&cio2->dev, "Exceeded available CIO2 ports\n"); - return -EINVAL; - } - - sensor = &bridge->sensors[bridge->n_sensors]; - - ret = cio2_bridge_read_acpi_buffer(adev, "SSDB", - &sensor->ssdb, - sizeof(sensor->ssdb)); - if (ret) - goto err_put_adev; - - snprintf(sensor->name, sizeof(sensor->name), "%s-%u", - cfg->hid, sensor->ssdb.link); - - if (sensor->ssdb.vcmtype > ARRAY_SIZE(cio2_vcm_types)) { - dev_warn(&adev->dev, "Unknown VCM type %d\n", - sensor->ssdb.vcmtype); - sensor->ssdb.vcmtype = 0; - } - - status = acpi_get_physical_device_location(adev->handle, &sensor->pld); - if (ACPI_FAILURE(status)) { - ret = -ENODEV; - goto err_put_adev; - } - - if (sensor->ssdb.lanes > CIO2_MAX_LANES) { - dev_err(&adev->dev, - "Number of lanes in SSDB is invalid\n"); - ret = -EINVAL; - goto err_free_pld; - } - - cio2_bridge_create_fwnode_properties(sensor, bridge, cfg); - cio2_bridge_create_connection_swnodes(bridge, sensor); - - ret = software_node_register_node_group(sensor->group); - if (ret) - goto err_free_pld; - - fwnode = software_node_fwnode(&sensor->swnodes[ - SWNODE_SENSOR_HID]); - if (!fwnode) { - ret = -ENODEV; - goto err_free_swnodes; - } - - sensor->adev = acpi_dev_get(adev); - - primary = acpi_fwnode_handle(adev); - primary->secondary = fwnode; - - cio2_bridge_instantiate_vcm_i2c_client(sensor); - - dev_info(&cio2->dev, "Found supported sensor %s\n", - acpi_dev_name(adev)); - - bridge->n_sensors++; - } - - return 0; - -err_free_swnodes: - software_node_unregister_node_group(sensor->group); -err_free_pld: - ACPI_FREE(sensor->pld); -err_put_adev: - acpi_dev_put(adev); - return ret; -} - -static int cio2_bridge_connect_sensors(struct cio2_bridge *bridge, - struct pci_dev *cio2) -{ - unsigned int i; - int ret; - - for (i = 0; i < ARRAY_SIZE(cio2_supported_sensors); i++) { - const struct cio2_sensor_config *cfg = - &cio2_supported_sensors[i]; - - ret = cio2_bridge_connect_sensor(cfg, bridge, cio2); - if (ret) - goto err_unregister_sensors; - } - - return 0; - -err_unregister_sensors: - cio2_bridge_unregister_sensors(bridge); - return ret; -} - -/* - * The VCM cannot be probed until the PMIC is completely setup. We cannot rely - * on -EPROBE_DEFER for this, since the consumer<->supplier relations between - * the VCM and regulators/clks are not described in ACPI, instead they are - * passed as board-data to the PMIC drivers. Since -PROBE_DEFER does not work - * for the clks/regulators the VCM i2c-clients must not be instantiated until - * the PMIC is fully setup. - * - * The sensor/VCM ACPI device has an ACPI _DEP on the PMIC, check this using the - * acpi_dev_ready_for_enumeration() helper, like the i2c-core-acpi code does - * for the sensors. - */ -static int cio2_bridge_sensors_are_ready(void) -{ - struct acpi_device *adev; - bool ready = true; - unsigned int i; - - for (i = 0; i < ARRAY_SIZE(cio2_supported_sensors); i++) { - const struct cio2_sensor_config *cfg = - &cio2_supported_sensors[i]; - - for_each_acpi_dev_match(adev, cfg->hid, NULL, -1) { - if (!adev->status.enabled) - continue; - - if (!acpi_dev_ready_for_enumeration(adev)) - ready = false; - } - } - - return ready; -} - -int cio2_bridge_init(struct pci_dev *cio2) -{ - struct device *dev = &cio2->dev; - struct fwnode_handle *fwnode; - struct cio2_bridge *bridge; - unsigned int i; - int ret; - - if (!cio2_bridge_sensors_are_ready()) - return -EPROBE_DEFER; - - bridge = kzalloc(sizeof(*bridge), GFP_KERNEL); - if (!bridge) - return -ENOMEM; - - strscpy(bridge->cio2_node_name, CIO2_HID, - sizeof(bridge->cio2_node_name)); - bridge->cio2_hid_node.name = bridge->cio2_node_name; - - ret = software_node_register(&bridge->cio2_hid_node); - if (ret < 0) { - dev_err(dev, "Failed to register the CIO2 HID node\n"); - goto err_free_bridge; - } - - /* - * Map the lane arrangement, which is fixed for the IPU3 (meaning we - * only need one, rather than one per sensor). We include it as a - * member of the struct cio2_bridge rather than a global variable so - * that it survives if the module is unloaded along with the rest of - * the struct. - */ - for (i = 0; i < CIO2_MAX_LANES; i++) - bridge->data_lanes[i] = i + 1; - - ret = cio2_bridge_connect_sensors(bridge, cio2); - if (ret || bridge->n_sensors == 0) - goto err_unregister_cio2; - - dev_info(dev, "Connected %d cameras\n", bridge->n_sensors); - - fwnode = software_node_fwnode(&bridge->cio2_hid_node); - if (!fwnode) { - dev_err(dev, "Error getting fwnode from cio2 software_node\n"); - ret = -ENODEV; - goto err_unregister_sensors; - } - - set_secondary_fwnode(dev, fwnode); - - return 0; - -err_unregister_sensors: - cio2_bridge_unregister_sensors(bridge); -err_unregister_cio2: - software_node_unregister(&bridge->cio2_hid_node); -err_free_bridge: - kfree(bridge); - - return ret; -} diff --git a/drivers/media/pci/intel/ipu3/cio2-bridge.h b/drivers/media/pci/intel/ipu3/cio2-bridge.h deleted file mode 100644 index b76ed8a641e2..000000000000 --- a/drivers/media/pci/intel/ipu3/cio2-bridge.h +++ /dev/null @@ -1,146 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/* Author: Dan Scally <djrscally@gmail.com> */ -#ifndef __CIO2_BRIDGE_H -#define __CIO2_BRIDGE_H - -#include <linux/property.h> -#include <linux/types.h> - -#include "ipu3-cio2.h" - -struct i2c_client; - -#define CIO2_HID "INT343E" -#define CIO2_MAX_LANES 4 -#define MAX_NUM_LINK_FREQS 3 - -/* Values are educated guesses as we don't have a spec */ -#define CIO2_SENSOR_ROTATION_NORMAL 0 -#define CIO2_SENSOR_ROTATION_INVERTED 1 - -#define CIO2_SENSOR_CONFIG(_HID, _NR, ...) \ - (const struct cio2_sensor_config) { \ - .hid = _HID, \ - .nr_link_freqs = _NR, \ - .link_freqs = { __VA_ARGS__ } \ - } - -#define NODE_SENSOR(_HID, _PROPS) \ - (const struct software_node) { \ - .name = _HID, \ - .properties = _PROPS, \ - } - -#define NODE_PORT(_PORT, _SENSOR_NODE) \ - (const struct software_node) { \ - .name = _PORT, \ - .parent = _SENSOR_NODE, \ - } - -#define NODE_ENDPOINT(_EP, _PORT, _PROPS) \ - (const struct software_node) { \ - .name = _EP, \ - .parent = _PORT, \ - .properties = _PROPS, \ - } - -#define NODE_VCM(_TYPE) \ - (const struct software_node) { \ - .name = _TYPE, \ - } - -enum cio2_sensor_swnodes { - SWNODE_SENSOR_HID, - SWNODE_SENSOR_PORT, - SWNODE_SENSOR_ENDPOINT, - SWNODE_CIO2_PORT, - SWNODE_CIO2_ENDPOINT, - /* Must be last because it is optional / maybe empty */ - SWNODE_VCM, - SWNODE_COUNT -}; - -/* Data representation as it is in ACPI SSDB buffer */ -struct cio2_sensor_ssdb { - u8 version; - u8 sku; - u8 guid_csi2[16]; - u8 devfunction; - u8 bus; - u32 dphylinkenfuses; - u32 clockdiv; - u8 link; - u8 lanes; - u32 csiparams[10]; - u32 maxlanespeed; - u8 sensorcalibfileidx; - u8 sensorcalibfileidxInMBZ[3]; - u8 romtype; - u8 vcmtype; - u8 platforminfo; - u8 platformsubinfo; - u8 flash; - u8 privacyled; - u8 degree; - u8 mipilinkdefined; - u32 mclkspeed; - u8 controllogicid; - u8 reserved1[3]; - u8 mclkport; - u8 reserved2[13]; -} __packed; - -struct cio2_property_names { - char clock_frequency[16]; - char rotation[9]; - char orientation[12]; - char bus_type[9]; - char data_lanes[11]; - char remote_endpoint[16]; - char link_frequencies[17]; -}; - -struct cio2_node_names { - char port[7]; - char endpoint[11]; - char remote_port[7]; -}; - -struct cio2_sensor_config { - const char *hid; - const u8 nr_link_freqs; - const u64 link_freqs[MAX_NUM_LINK_FREQS]; -}; - -struct cio2_sensor { - /* append ssdb.link(u8) in "-%u" format as suffix of HID */ - char name[ACPI_ID_LEN + 4]; - struct acpi_device *adev; - struct i2c_client *vcm_i2c_client; - - /* SWNODE_COUNT + 1 for terminating NULL */ - const struct software_node *group[SWNODE_COUNT + 1]; - struct software_node swnodes[SWNODE_COUNT]; - struct cio2_node_names node_names; - - struct cio2_sensor_ssdb ssdb; - struct acpi_pld_info *pld; - - struct cio2_property_names prop_names; - struct property_entry ep_properties[5]; - struct property_entry dev_properties[5]; - struct property_entry cio2_properties[3]; - struct software_node_ref_args local_ref[1]; - struct software_node_ref_args remote_ref[1]; - struct software_node_ref_args vcm_ref[1]; -}; - -struct cio2_bridge { - char cio2_node_name[ACPI_ID_LEN]; - struct software_node cio2_hid_node; - u32 data_lanes[4]; - unsigned int n_sensors; - struct cio2_sensor sensors[CIO2_NUM_PORTS]; -}; - -#endif diff --git a/drivers/media/pci/intel/ipu3/ipu3-cio2-main.c b/drivers/media/pci/intel/ipu3/ipu3-cio2.c index 34984a7474ed..5dd69a251b6a 100644 --- a/drivers/media/pci/intel/ipu3/ipu3-cio2-main.c +++ b/drivers/media/pci/intel/ipu3/ipu3-cio2.c @@ -22,6 +22,8 @@ #include <linux/pm_runtime.h> #include <linux/property.h> #include <linux/vmalloc.h> + +#include <media/ipu-bridge.h> #include <media/v4l2-ctrls.h> #include <media/v4l2-device.h> #include <media/v4l2-event.h> @@ -354,7 +356,7 @@ static int cio2_hw_init(struct cio2_device *cio2, struct cio2_queue *q) void __iomem *const base = cio2->base; u8 lanes, csi2bus = q->csi2.port; u8 sensor_vc = SENSOR_VIR_CH_DFLT; - struct cio2_csi2_timing timing; + struct cio2_csi2_timing timing = { 0 }; int i, r; fmt = cio2_find_format(NULL, &q->subdev_fmt.code); @@ -1371,7 +1373,7 @@ static const struct v4l2_subdev_ops cio2_subdev_ops = { /******* V4L2 sub-device asynchronous registration callbacks***********/ struct sensor_async_subdev { - struct v4l2_async_subdev asd; + struct v4l2_async_connection asd; struct csi2_bus_info csi2; }; @@ -1381,15 +1383,20 @@ struct sensor_async_subdev { /* The .bound() notifier callback when a match is found */ static int cio2_notifier_bound(struct v4l2_async_notifier *notifier, struct v4l2_subdev *sd, - struct v4l2_async_subdev *asd) + struct v4l2_async_connection *asd) { struct cio2_device *cio2 = to_cio2_device(notifier); struct sensor_async_subdev *s_asd = to_sensor_asd(asd); struct cio2_queue *q; + int ret; if (cio2->queue[s_asd->csi2.port].sensor) return -EBUSY; + ret = ipu_bridge_instantiate_vcm(sd->dev); + if (ret) + return ret; + q = &cio2->queue[s_asd->csi2.port]; q->csi2 = s_asd->csi2; @@ -1402,7 +1409,7 @@ static int cio2_notifier_bound(struct v4l2_async_notifier *notifier, /* The .unbind callback */ static void cio2_notifier_unbind(struct v4l2_async_notifier *notifier, struct v4l2_subdev *sd, - struct v4l2_async_subdev *asd) + struct v4l2_async_connection *asd) { struct cio2_device *cio2 = to_cio2_device(notifier); struct sensor_async_subdev *s_asd = to_sensor_asd(asd); @@ -1416,11 +1423,11 @@ static int cio2_notifier_complete(struct v4l2_async_notifier *notifier) struct cio2_device *cio2 = to_cio2_device(notifier); struct device *dev = &cio2->pci_dev->dev; struct sensor_async_subdev *s_asd; - struct v4l2_async_subdev *asd; + struct v4l2_async_connection *asd; struct cio2_queue *q; int ret; - list_for_each_entry(asd, &cio2->notifier.asd_list, asd_list) { + list_for_each_entry(asd, &cio2->notifier.done_list, asc_entry) { s_asd = to_sensor_asd(asd); q = &cio2->queue[s_asd->csi2.port]; @@ -1499,7 +1506,7 @@ err_parse: * suspend. */ cio2->notifier.ops = &cio2_async_ops; - ret = v4l2_async_nf_register(&cio2->v4l2_dev, &cio2->notifier); + ret = v4l2_async_nf_register(&cio2->notifier); if (ret) dev_err(dev, "failed to register async notifier : %d\n", ret); @@ -1724,7 +1731,7 @@ static int cio2_pci_probe(struct pci_dev *pci_dev, return -EINVAL; } - r = cio2_bridge_init(pci_dev); + r = ipu_bridge_init(dev, ipu_bridge_parse_ssdb); if (r) return r; } @@ -1794,7 +1801,7 @@ static int cio2_pci_probe(struct pci_dev *pci_dev, if (r) goto fail_v4l2_device_unregister; - v4l2_async_nf_init(&cio2->notifier); + v4l2_async_nf_init(&cio2->notifier, &cio2->v4l2_dev); /* Register notifier for subdevices we care */ r = cio2_parse_firmware(cio2); @@ -2057,3 +2064,4 @@ MODULE_AUTHOR("Yuning Pu <yuning.pu@intel.com>"); MODULE_AUTHOR("Yong Zhi <yong.zhi@intel.com>"); MODULE_LICENSE("GPL v2"); MODULE_DESCRIPTION("IPU3 CIO2 driver"); +MODULE_IMPORT_NS(INTEL_IPU_BRIDGE); diff --git a/drivers/media/pci/intel/ipu3/ipu3-cio2.h b/drivers/media/pci/intel/ipu3/ipu3-cio2.h index 3a1f394e05aa..d731ce8adbe3 100644 --- a/drivers/media/pci/intel/ipu3/ipu3-cio2.h +++ b/drivers/media/pci/intel/ipu3/ipu3-cio2.h @@ -459,10 +459,4 @@ static inline struct cio2_queue *vb2q_to_cio2_queue(struct vb2_queue *vq) return container_of(vq, struct cio2_queue, vbq); } -#if IS_ENABLED(CONFIG_CIO2_BRIDGE) -int cio2_bridge_init(struct pci_dev *cio2); -#else -static inline int cio2_bridge_init(struct pci_dev *cio2) { return 0; } -#endif - #endif diff --git a/drivers/media/pci/intel/ivsc/Kconfig b/drivers/media/pci/intel/ivsc/Kconfig new file mode 100644 index 000000000000..1ef1c4e3750d --- /dev/null +++ b/drivers/media/pci/intel/ivsc/Kconfig @@ -0,0 +1,12 @@ +# SPDX-License-Identifier: GPL-2.0-only +# Copyright (C) 2023, Intel Corporation. All rights reserved. + +config INTEL_VSC + tristate "Intel Visual Sensing Controller" + depends on INTEL_MEI && ACPI + help + This adds support for Intel Visual Sensing Controller (IVSC). + + Enables the IVSC firmware services required for controlling + camera sensor ownership and CSI-2 link through Image Processing + Unit(IPU) driver of Intel. diff --git a/drivers/media/pci/intel/ivsc/Makefile b/drivers/media/pci/intel/ivsc/Makefile new file mode 100644 index 000000000000..00fad29a6e6e --- /dev/null +++ b/drivers/media/pci/intel/ivsc/Makefile @@ -0,0 +1,9 @@ +# SPDX-License-Identifier: GPL-2.0-only +# +# Copyright (C) 2023, Intel Corporation. All rights reserved. + +obj-$(CONFIG_INTEL_VSC) += ivsc-csi.o +ivsc-csi-y += mei_csi.o + +obj-$(CONFIG_INTEL_VSC) += ivsc-ace.o +ivsc-ace-y += mei_ace.o diff --git a/drivers/media/pci/intel/ivsc/mei_ace.c b/drivers/media/pci/intel/ivsc/mei_ace.c new file mode 100644 index 000000000000..a0491f307831 --- /dev/null +++ b/drivers/media/pci/intel/ivsc/mei_ace.c @@ -0,0 +1,579 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Copyright (C) 2023 Intel Corporation. All rights reserved. + * Intel Visual Sensing Controller ACE Linux driver + */ + +/* + * To set ownership of camera sensor, there is specific command, which + * is sent via MEI protocol. That's a two-step scheme where the firmware + * first acks receipt of the command and later responses the command was + * executed. The command sending function uses "completion" as the + * synchronization mechanism. The notification for command is received + * via a mei callback which wakes up the caller. There can be only one + * outstanding command at a time. + * + * The power line of camera sensor is directly connected to IVSC instead + * of host, when camera sensor ownership is switched to host, sensor is + * already powered up by firmware. + */ + +#include <linux/acpi.h> +#include <linux/completion.h> +#include <linux/delay.h> +#include <linux/kernel.h> +#include <linux/mei_cl_bus.h> +#include <linux/module.h> +#include <linux/mutex.h> +#include <linux/pm_runtime.h> +#include <linux/slab.h> +#include <linux/uuid.h> +#include <linux/workqueue.h> + +#define MEI_ACE_DRIVER_NAME "ivsc_ace" + +/* indicating driver message */ +#define ACE_DRV_MSG 1 +/* indicating set command */ +#define ACE_CMD_SET 4 +/* command timeout determined experimentally */ +#define ACE_CMD_TIMEOUT (5 * HZ) +/* indicating the first command block */ +#define ACE_CMD_INIT_BLOCK 1 +/* indicating the last command block */ +#define ACE_CMD_FINAL_BLOCK 1 +/* size of camera status notification content */ +#define ACE_CAMERA_STATUS_SIZE 5 + +/* UUID used to get firmware id */ +#define ACE_GET_FW_ID_UUID UUID_LE(0x6167DCFB, 0x72F1, 0x4584, 0xBF, \ + 0xE3, 0x84, 0x17, 0x71, 0xAA, 0x79, 0x0B) + +/* UUID used to get csi device */ +#define MEI_CSI_UUID UUID_LE(0x92335FCF, 0x3203, 0x4472, \ + 0xAF, 0x93, 0x7b, 0x44, 0x53, 0xAC, 0x29, 0xDA) + +/* identify firmware event type */ +enum ace_event_type { + /* firmware ready */ + ACE_FW_READY = 0x8, + + /* command response */ + ACE_CMD_RESPONSE = 0x10, +}; + +/* identify camera sensor ownership */ +enum ace_camera_owner { + ACE_CAMERA_IVSC, + ACE_CAMERA_HOST, +}; + +/* identify the command id supported by firmware IPC */ +enum ace_cmd_id { + /* used to switch camera sensor to host */ + ACE_SWITCH_CAMERA_TO_HOST = 0x13, + + /* used to switch camera sensor to IVSC */ + ACE_SWITCH_CAMERA_TO_IVSC = 0x14, + + /* used to get firmware id */ + ACE_GET_FW_ID = 0x1A, +}; + +/* ACE command header structure */ +struct ace_cmd_hdr { + u32 firmware_id : 16; + u32 instance_id : 8; + u32 type : 5; + u32 rsp : 1; + u32 msg_tgt : 1; + u32 _hw_rsvd_1 : 1; + u32 param_size : 20; + u32 cmd_id : 8; + u32 final_block : 1; + u32 init_block : 1; + u32 _hw_rsvd_2 : 2; +} __packed; + +/* ACE command parameter structure */ +union ace_cmd_param { + uuid_le uuid; + u32 param; +}; + +/* ACE command structure */ +struct ace_cmd { + struct ace_cmd_hdr hdr; + union ace_cmd_param param; +} __packed; + +/* ACE notification header */ +union ace_notif_hdr { + struct _confirm { + u32 status : 24; + u32 type : 5; + u32 rsp : 1; + u32 msg_tgt : 1; + u32 _hw_rsvd_1 : 1; + u32 param_size : 20; + u32 cmd_id : 8; + u32 final_block : 1; + u32 init_block : 1; + u32 _hw_rsvd_2 : 2; + } __packed ack; + + struct _event { + u32 rsvd1 : 16; + u32 event_type : 8; + u32 type : 5; + u32 ack : 1; + u32 msg_tgt : 1; + u32 _hw_rsvd_1 : 1; + u32 rsvd2 : 30; + u32 _hw_rsvd_2 : 2; + } __packed event; + + struct _response { + u32 event_id : 16; + u32 notif_type : 8; + u32 type : 5; + u32 rsp : 1; + u32 msg_tgt : 1; + u32 _hw_rsvd_1 : 1; + u32 event_data_size : 16; + u32 request_target : 1; + u32 request_type : 5; + u32 cmd_id : 8; + u32 _hw_rsvd_2 : 2; + } __packed response; +}; + +/* ACE notification content */ +union ace_notif_cont { + u16 firmware_id; + u8 state_notif; + u8 camera_status[ACE_CAMERA_STATUS_SIZE]; +}; + +/* ACE notification structure */ +struct ace_notif { + union ace_notif_hdr hdr; + union ace_notif_cont cont; +} __packed; + +struct mei_ace { + struct mei_cl_device *cldev; + + /* command ack */ + struct ace_notif cmd_ack; + /* command response */ + struct ace_notif cmd_response; + /* used to wait for command ack and response */ + struct completion cmd_completion; + /* lock used to prevent multiple call to send command */ + struct mutex lock; + + /* used to construct command */ + u16 firmware_id; + + struct device *csi_dev; + + /* runtime PM link from ace to csi */ + struct device_link *csi_link; + + struct work_struct work; +}; + +static inline void init_cmd_hdr(struct ace_cmd_hdr *hdr) +{ + memset(hdr, 0, sizeof(struct ace_cmd_hdr)); + + hdr->type = ACE_CMD_SET; + hdr->msg_tgt = ACE_DRV_MSG; + hdr->init_block = ACE_CMD_INIT_BLOCK; + hdr->final_block = ACE_CMD_FINAL_BLOCK; +} + +static int construct_command(struct mei_ace *ace, struct ace_cmd *cmd, + enum ace_cmd_id cmd_id) +{ + union ace_cmd_param *param = &cmd->param; + struct ace_cmd_hdr *hdr = &cmd->hdr; + + init_cmd_hdr(hdr); + + hdr->cmd_id = cmd_id; + switch (cmd_id) { + case ACE_GET_FW_ID: + param->uuid = ACE_GET_FW_ID_UUID; + hdr->param_size = sizeof(param->uuid); + break; + case ACE_SWITCH_CAMERA_TO_IVSC: + param->param = 0; + hdr->firmware_id = ace->firmware_id; + hdr->param_size = sizeof(param->param); + break; + case ACE_SWITCH_CAMERA_TO_HOST: + hdr->firmware_id = ace->firmware_id; + break; + default: + return -EINVAL; + } + + return hdr->param_size + sizeof(cmd->hdr); +} + +/* send command to firmware */ +static int mei_ace_send(struct mei_ace *ace, struct ace_cmd *cmd, + size_t len, bool only_ack) +{ + union ace_notif_hdr *resp_hdr = &ace->cmd_response.hdr; + union ace_notif_hdr *ack_hdr = &ace->cmd_ack.hdr; + struct ace_cmd_hdr *cmd_hdr = &cmd->hdr; + int ret; + + mutex_lock(&ace->lock); + + reinit_completion(&ace->cmd_completion); + + ret = mei_cldev_send(ace->cldev, (u8 *)cmd, len); + if (ret < 0) + goto out; + + ret = wait_for_completion_killable_timeout(&ace->cmd_completion, + ACE_CMD_TIMEOUT); + if (ret < 0) { + goto out; + } else if (!ret) { + ret = -ETIMEDOUT; + goto out; + } + + if (ack_hdr->ack.cmd_id != cmd_hdr->cmd_id) { + ret = -EINVAL; + goto out; + } + + /* command ack status */ + ret = ack_hdr->ack.status; + if (ret) { + ret = -EIO; + goto out; + } + + if (only_ack) + goto out; + + ret = wait_for_completion_killable_timeout(&ace->cmd_completion, + ACE_CMD_TIMEOUT); + if (ret < 0) { + goto out; + } else if (!ret) { + ret = -ETIMEDOUT; + goto out; + } else { + ret = 0; + } + + if (resp_hdr->response.cmd_id != cmd_hdr->cmd_id) + ret = -EINVAL; + +out: + mutex_unlock(&ace->lock); + + return ret; +} + +static int ace_set_camera_owner(struct mei_ace *ace, + enum ace_camera_owner owner) +{ + enum ace_cmd_id cmd_id; + struct ace_cmd cmd; + int cmd_size; + int ret; + + if (owner == ACE_CAMERA_IVSC) + cmd_id = ACE_SWITCH_CAMERA_TO_IVSC; + else + cmd_id = ACE_SWITCH_CAMERA_TO_HOST; + + cmd_size = construct_command(ace, &cmd, cmd_id); + if (cmd_size >= 0) + ret = mei_ace_send(ace, &cmd, cmd_size, false); + else + ret = cmd_size; + + return ret; +} + +/* the first command downloaded to firmware */ +static inline int ace_get_firmware_id(struct mei_ace *ace) +{ + struct ace_cmd cmd; + int cmd_size; + int ret; + + cmd_size = construct_command(ace, &cmd, ACE_GET_FW_ID); + if (cmd_size >= 0) + ret = mei_ace_send(ace, &cmd, cmd_size, true); + else + ret = cmd_size; + + return ret; +} + +static void handle_command_response(struct mei_ace *ace, + struct ace_notif *resp, int len) +{ + union ace_notif_hdr *hdr = &resp->hdr; + + switch (hdr->response.cmd_id) { + case ACE_SWITCH_CAMERA_TO_IVSC: + case ACE_SWITCH_CAMERA_TO_HOST: + memcpy(&ace->cmd_response, resp, len); + complete(&ace->cmd_completion); + break; + case ACE_GET_FW_ID: + break; + default: + break; + } +} + +static void handle_command_ack(struct mei_ace *ace, + struct ace_notif *ack, int len) +{ + union ace_notif_hdr *hdr = &ack->hdr; + + switch (hdr->ack.cmd_id) { + case ACE_GET_FW_ID: + ace->firmware_id = ack->cont.firmware_id; + fallthrough; + case ACE_SWITCH_CAMERA_TO_IVSC: + case ACE_SWITCH_CAMERA_TO_HOST: + memcpy(&ace->cmd_ack, ack, len); + complete(&ace->cmd_completion); + break; + default: + break; + } +} + +/* callback for receive */ +static void mei_ace_rx(struct mei_cl_device *cldev) +{ + struct mei_ace *ace = mei_cldev_get_drvdata(cldev); + struct ace_notif event; + union ace_notif_hdr *hdr = &event.hdr; + int ret; + + ret = mei_cldev_recv(cldev, (u8 *)&event, sizeof(event)); + if (ret < 0) { + dev_err(&cldev->dev, "recv error: %d\n", ret); + return; + } + + if (hdr->event.ack) { + handle_command_ack(ace, &event, ret); + return; + } + + switch (hdr->event.event_type) { + case ACE_CMD_RESPONSE: + handle_command_response(ace, &event, ret); + break; + case ACE_FW_READY: + /* + * firmware ready notification sent to driver + * after HECI client connected with firmware. + */ + dev_dbg(&cldev->dev, "firmware ready\n"); + break; + default: + break; + } +} + +static int mei_ace_setup_dev_link(struct mei_ace *ace) +{ + struct device *dev = &ace->cldev->dev; + uuid_le uuid = MEI_CSI_UUID; + struct device *csi_dev; + char name[64]; + int ret; + + snprintf(name, sizeof(name), "%s-%pUl", dev_name(dev->parent), &uuid); + + csi_dev = device_find_child_by_name(dev->parent, name); + if (!csi_dev) { + ret = -EPROBE_DEFER; + goto err; + } + + /* setup link between mei_ace and mei_csi */ + ace->csi_link = device_link_add(csi_dev, dev, DL_FLAG_PM_RUNTIME | + DL_FLAG_RPM_ACTIVE | DL_FLAG_STATELESS); + if (!ace->csi_link) { + ret = -EINVAL; + dev_err(dev, "failed to link to %s\n", dev_name(csi_dev)); + goto err_put; + } + + ace->csi_dev = csi_dev; + + return 0; + +err_put: + put_device(csi_dev); + +err: + return ret; +} + +/* switch camera to host before probe sensor device */ +static void mei_ace_post_probe_work(struct work_struct *work) +{ + struct acpi_device *adev; + struct mei_ace *ace; + struct device *dev; + int ret; + + ace = container_of(work, struct mei_ace, work); + dev = &ace->cldev->dev; + + ret = ace_set_camera_owner(ace, ACE_CAMERA_HOST); + if (ret) { + dev_err(dev, "switch camera to host failed: %d\n", ret); + return; + } + + adev = ACPI_COMPANION(dev->parent); + if (!adev) + return; + + acpi_dev_clear_dependencies(adev); +} + +static int mei_ace_probe(struct mei_cl_device *cldev, + const struct mei_cl_device_id *id) +{ + struct device *dev = &cldev->dev; + struct mei_ace *ace; + int ret; + + ace = devm_kzalloc(dev, sizeof(struct mei_ace), GFP_KERNEL); + if (!ace) + return -ENOMEM; + + ace->cldev = cldev; + mutex_init(&ace->lock); + init_completion(&ace->cmd_completion); + INIT_WORK(&ace->work, mei_ace_post_probe_work); + + mei_cldev_set_drvdata(cldev, ace); + + ret = mei_cldev_enable(cldev); + if (ret < 0) { + dev_err(dev, "mei_cldev_enable failed: %d\n", ret); + goto destroy_mutex; + } + + ret = mei_cldev_register_rx_cb(cldev, mei_ace_rx); + if (ret) { + dev_err(dev, "event cb registration failed: %d\n", ret); + goto err_disable; + } + + ret = ace_get_firmware_id(ace); + if (ret) { + dev_err(dev, "get firmware id failed: %d\n", ret); + goto err_disable; + } + + pm_runtime_set_active(dev); + pm_runtime_enable(dev); + + ret = mei_ace_setup_dev_link(ace); + if (ret) + goto disable_pm; + + schedule_work(&ace->work); + + return 0; + +disable_pm: + pm_runtime_disable(dev); + pm_runtime_set_suspended(dev); + +err_disable: + mei_cldev_disable(cldev); + +destroy_mutex: + mutex_destroy(&ace->lock); + + return ret; +} + +static void mei_ace_remove(struct mei_cl_device *cldev) +{ + struct mei_ace *ace = mei_cldev_get_drvdata(cldev); + + cancel_work_sync(&ace->work); + + device_link_del(ace->csi_link); + put_device(ace->csi_dev); + + pm_runtime_disable(&cldev->dev); + pm_runtime_set_suspended(&cldev->dev); + + ace_set_camera_owner(ace, ACE_CAMERA_IVSC); + + mutex_destroy(&ace->lock); +} + +static int __maybe_unused mei_ace_runtime_suspend(struct device *dev) +{ + struct mei_ace *ace = dev_get_drvdata(dev); + + return ace_set_camera_owner(ace, ACE_CAMERA_IVSC); +} + +static int __maybe_unused mei_ace_runtime_resume(struct device *dev) +{ + struct mei_ace *ace = dev_get_drvdata(dev); + + return ace_set_camera_owner(ace, ACE_CAMERA_HOST); +} + +static const struct dev_pm_ops mei_ace_pm_ops = { + SET_RUNTIME_PM_OPS(mei_ace_runtime_suspend, + mei_ace_runtime_resume, NULL) +}; + +#define MEI_ACE_UUID UUID_LE(0x5DB76CF6, 0x0A68, 0x4ED6, \ + 0x9B, 0x78, 0x03, 0x61, 0x63, 0x5E, 0x24, 0x47) + +static const struct mei_cl_device_id mei_ace_tbl[] = { + { MEI_ACE_DRIVER_NAME, MEI_ACE_UUID, MEI_CL_VERSION_ANY }, + { /* sentinel */ } +}; +MODULE_DEVICE_TABLE(mei, mei_ace_tbl); + +static struct mei_cl_driver mei_ace_driver = { + .id_table = mei_ace_tbl, + .name = MEI_ACE_DRIVER_NAME, + + .probe = mei_ace_probe, + .remove = mei_ace_remove, + + .driver = { + .pm = &mei_ace_pm_ops, + }, +}; + +module_mei_cl_driver(mei_ace_driver); + +MODULE_AUTHOR("Wentong Wu <wentong.wu@intel.com>"); +MODULE_AUTHOR("Zhifeng Wang <zhifeng.wang@intel.com>"); +MODULE_DESCRIPTION("Device driver for IVSC ACE"); +MODULE_LICENSE("GPL"); diff --git a/drivers/media/pci/intel/ivsc/mei_csi.c b/drivers/media/pci/intel/ivsc/mei_csi.c new file mode 100644 index 000000000000..00ba611e0f68 --- /dev/null +++ b/drivers/media/pci/intel/ivsc/mei_csi.c @@ -0,0 +1,825 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Copyright (C) 2023 Intel Corporation. All rights reserved. + * Intel Visual Sensing Controller CSI Linux driver + */ + +/* + * To set ownership of CSI-2 link and to configure CSI-2 link, there + * are specific commands, which are sent via MEI protocol. The send + * command function uses "completion" as a synchronization mechanism. + * The response for command is received via a mei callback which wakes + * up the caller. There can be only one outstanding command at a time. + */ + +#include <linux/completion.h> +#include <linux/delay.h> +#include <linux/kernel.h> +#include <linux/math64.h> +#include <linux/mei_cl_bus.h> +#include <linux/module.h> +#include <linux/mutex.h> +#include <linux/pm_runtime.h> +#include <linux/slab.h> +#include <linux/units.h> +#include <linux/uuid.h> +#include <linux/workqueue.h> + +#include <media/v4l2-async.h> +#include <media/v4l2-ctrls.h> +#include <media/v4l2-fwnode.h> +#include <media/v4l2-subdev.h> + +#define MEI_CSI_DRIVER_NAME "ivsc_csi" +#define MEI_CSI_ENTITY_NAME "Intel IVSC CSI" + +#define MEI_CSI_LINK_FREQ_400MHZ 400000000ULL + +/* the 5s used here is based on experiment */ +#define CSI_CMD_TIMEOUT (5 * HZ) +/* to setup CSI-2 link an extra delay needed and determined experimentally */ +#define CSI_FW_READY_DELAY_MS 100 +/* link frequency unit is 100kHz */ +#define CSI_LINK_FREQ(x) ((u32)(div_u64(x, 100 * HZ_PER_KHZ))) + +/* + * identify the command id supported by firmware + * IPC, as well as the privacy notification id + * used when processing privacy event. + */ +enum csi_cmd_id { + /* used to set csi ownership */ + CSI_SET_OWNER = 0, + + /* used to configure CSI-2 link */ + CSI_SET_CONF = 2, + + /* privacy notification id used when privacy state changes */ + CSI_PRIVACY_NOTIF = 6, +}; + +/* CSI-2 link ownership definition */ +enum csi_link_owner { + CSI_LINK_IVSC, + CSI_LINK_HOST, +}; + +/* privacy status definition */ +enum ivsc_privacy_status { + CSI_PRIVACY_OFF, + CSI_PRIVACY_ON, + CSI_PRIVACY_MAX, +}; + +enum csi_pads { + CSI_PAD_SOURCE, + CSI_PAD_SINK, + CSI_NUM_PADS +}; + +/* configuration of the CSI-2 link between host and IVSC */ +struct csi_link_cfg { + /* number of data lanes used on the CSI-2 link */ + u32 nr_of_lanes; + + /* frequency of the CSI-2 link */ + u32 link_freq; + + /* for future use */ + u32 rsvd[2]; +} __packed; + +/* CSI command structure */ +struct csi_cmd { + u32 cmd_id; + union _cmd_param { + u32 param; + struct csi_link_cfg conf; + } param; +} __packed; + +/* CSI notification structure */ +struct csi_notif { + u32 cmd_id; + int status; + union _resp_cont { + u32 cont; + struct csi_link_cfg conf; + } cont; +} __packed; + +struct mei_csi { + struct mei_cl_device *cldev; + + /* command response */ + struct csi_notif cmd_response; + /* used to wait for command response from firmware */ + struct completion cmd_completion; + /* protect command download */ + struct mutex lock; + + struct v4l2_subdev subdev; + struct v4l2_subdev *remote; + struct v4l2_async_notifier notifier; + struct v4l2_ctrl_handler ctrl_handler; + struct v4l2_ctrl *freq_ctrl; + struct v4l2_ctrl *privacy_ctrl; + unsigned int remote_pad; + /* start streaming or not */ + int streaming; + + struct media_pad pads[CSI_NUM_PADS]; + struct v4l2_mbus_framefmt format_mbus[CSI_NUM_PADS]; + + /* number of data lanes used on the CSI-2 link */ + u32 nr_of_lanes; + /* frequency of the CSI-2 link */ + u64 link_freq; + + /* privacy status */ + enum ivsc_privacy_status status; +}; + +static const struct v4l2_mbus_framefmt mei_csi_format_mbus_default = { + .width = 1, + .height = 1, + .code = MEDIA_BUS_FMT_Y8_1X8, + .field = V4L2_FIELD_NONE, +}; + +static s64 link_freq_menu_items[] = { + MEI_CSI_LINK_FREQ_400MHZ +}; + +static inline struct mei_csi *notifier_to_csi(struct v4l2_async_notifier *n) +{ + return container_of(n, struct mei_csi, notifier); +} + +static inline struct mei_csi *sd_to_csi(struct v4l2_subdev *sd) +{ + return container_of(sd, struct mei_csi, subdev); +} + +static inline struct mei_csi *ctrl_to_csi(struct v4l2_ctrl *ctrl) +{ + return container_of(ctrl->handler, struct mei_csi, ctrl_handler); +} + +/* send a command to firmware and mutex must be held by caller */ +static int mei_csi_send(struct mei_csi *csi, u8 *buf, size_t len) +{ + struct csi_cmd *cmd = (struct csi_cmd *)buf; + int ret; + + reinit_completion(&csi->cmd_completion); + + ret = mei_cldev_send(csi->cldev, buf, len); + if (ret < 0) + goto out; + + ret = wait_for_completion_killable_timeout(&csi->cmd_completion, + CSI_CMD_TIMEOUT); + if (ret < 0) { + goto out; + } else if (!ret) { + ret = -ETIMEDOUT; + goto out; + } + + /* command response status */ + ret = csi->cmd_response.status; + if (ret) { + ret = -EINVAL; + goto out; + } + + if (csi->cmd_response.cmd_id != cmd->cmd_id) + ret = -EINVAL; + +out: + return ret; +} + +/* set CSI-2 link ownership */ +static int csi_set_link_owner(struct mei_csi *csi, enum csi_link_owner owner) +{ + struct csi_cmd cmd = { 0 }; + size_t cmd_size; + int ret; + + cmd.cmd_id = CSI_SET_OWNER; + cmd.param.param = owner; + cmd_size = sizeof(cmd.cmd_id) + sizeof(cmd.param.param); + + mutex_lock(&csi->lock); + + ret = mei_csi_send(csi, (u8 *)&cmd, cmd_size); + + mutex_unlock(&csi->lock); + + return ret; +} + +/* configure CSI-2 link between host and IVSC */ +static int csi_set_link_cfg(struct mei_csi *csi) +{ + struct csi_cmd cmd = { 0 }; + size_t cmd_size; + int ret; + + cmd.cmd_id = CSI_SET_CONF; + cmd.param.conf.nr_of_lanes = csi->nr_of_lanes; + cmd.param.conf.link_freq = CSI_LINK_FREQ(csi->link_freq); + cmd_size = sizeof(cmd.cmd_id) + sizeof(cmd.param.conf); + + mutex_lock(&csi->lock); + + ret = mei_csi_send(csi, (u8 *)&cmd, cmd_size); + /* + * wait configuration ready if download success. placing + * delay under mutex is to make sure current command flow + * completed before starting a possible new one. + */ + if (!ret) + msleep(CSI_FW_READY_DELAY_MS); + + mutex_unlock(&csi->lock); + + return ret; +} + +/* callback for receive */ +static void mei_csi_rx(struct mei_cl_device *cldev) +{ + struct mei_csi *csi = mei_cldev_get_drvdata(cldev); + struct csi_notif notif = { 0 }; + int ret; + + ret = mei_cldev_recv(cldev, (u8 *)¬if, sizeof(notif)); + if (ret < 0) { + dev_err(&cldev->dev, "recv error: %d\n", ret); + return; + } + + switch (notif.cmd_id) { + case CSI_PRIVACY_NOTIF: + if (notif.cont.cont < CSI_PRIVACY_MAX) { + csi->status = notif.cont.cont; + v4l2_ctrl_s_ctrl(csi->privacy_ctrl, csi->status); + } + break; + case CSI_SET_OWNER: + case CSI_SET_CONF: + memcpy(&csi->cmd_response, ¬if, ret); + + complete(&csi->cmd_completion); + break; + default: + break; + } +} + +static int mei_csi_set_stream(struct v4l2_subdev *sd, int enable) +{ + struct mei_csi *csi = sd_to_csi(sd); + s64 freq; + int ret; + + if (enable && csi->streaming == 0) { + freq = v4l2_get_link_freq(csi->remote->ctrl_handler, 0, 0); + if (freq < 0) { + dev_err(&csi->cldev->dev, + "error %lld, invalid link_freq\n", freq); + ret = freq; + goto err; + } + csi->link_freq = freq; + + /* switch CSI-2 link to host */ + ret = csi_set_link_owner(csi, CSI_LINK_HOST); + if (ret < 0) + goto err; + + /* configure CSI-2 link */ + ret = csi_set_link_cfg(csi); + if (ret < 0) + goto err_switch; + + ret = v4l2_subdev_call(csi->remote, video, s_stream, 1); + if (ret) + goto err_switch; + } else if (!enable && csi->streaming == 1) { + v4l2_subdev_call(csi->remote, video, s_stream, 0); + + /* switch CSI-2 link to IVSC */ + ret = csi_set_link_owner(csi, CSI_LINK_IVSC); + if (ret < 0) + dev_warn(&csi->cldev->dev, + "failed to switch CSI2 link: %d\n", ret); + } + + csi->streaming = enable; + + return 0; + +err_switch: + csi_set_link_owner(csi, CSI_LINK_IVSC); + +err: + return ret; +} + +static struct v4l2_mbus_framefmt * +mei_csi_get_pad_format(struct v4l2_subdev *sd, + struct v4l2_subdev_state *sd_state, + unsigned int pad, u32 which) +{ + struct mei_csi *csi = sd_to_csi(sd); + + switch (which) { + case V4L2_SUBDEV_FORMAT_TRY: + return v4l2_subdev_get_try_format(sd, sd_state, pad); + case V4L2_SUBDEV_FORMAT_ACTIVE: + return &csi->format_mbus[pad]; + default: + return NULL; + } +} + +static int mei_csi_init_cfg(struct v4l2_subdev *sd, + struct v4l2_subdev_state *sd_state) +{ + struct v4l2_mbus_framefmt *mbusformat; + struct mei_csi *csi = sd_to_csi(sd); + unsigned int i; + + mutex_lock(&csi->lock); + + for (i = 0; i < sd->entity.num_pads; i++) { + mbusformat = v4l2_subdev_get_try_format(sd, sd_state, i); + *mbusformat = mei_csi_format_mbus_default; + } + + mutex_unlock(&csi->lock); + + return 0; +} + +static int mei_csi_get_fmt(struct v4l2_subdev *sd, + struct v4l2_subdev_state *sd_state, + struct v4l2_subdev_format *format) +{ + struct v4l2_mbus_framefmt *mbusformat; + struct mei_csi *csi = sd_to_csi(sd); + + mutex_lock(&csi->lock); + + mbusformat = mei_csi_get_pad_format(sd, sd_state, format->pad, + format->which); + if (mbusformat) + format->format = *mbusformat; + + mutex_unlock(&csi->lock); + + return 0; +} + +static int mei_csi_set_fmt(struct v4l2_subdev *sd, + struct v4l2_subdev_state *sd_state, + struct v4l2_subdev_format *format) +{ + struct v4l2_mbus_framefmt *source_mbusformat; + struct v4l2_mbus_framefmt *mbusformat; + struct mei_csi *csi = sd_to_csi(sd); + struct media_pad *pad; + + mbusformat = mei_csi_get_pad_format(sd, sd_state, format->pad, + format->which); + if (!mbusformat) + return -EINVAL; + + source_mbusformat = mei_csi_get_pad_format(sd, sd_state, CSI_PAD_SOURCE, + format->which); + if (!source_mbusformat) + return -EINVAL; + + v4l_bound_align_image(&format->format.width, 1, 65536, 0, + &format->format.height, 1, 65536, 0, 0); + + switch (format->format.code) { + case MEDIA_BUS_FMT_RGB444_1X12: + case MEDIA_BUS_FMT_RGB444_2X8_PADHI_BE: + case MEDIA_BUS_FMT_RGB444_2X8_PADHI_LE: + case MEDIA_BUS_FMT_RGB555_2X8_PADHI_BE: + case MEDIA_BUS_FMT_RGB555_2X8_PADHI_LE: + case MEDIA_BUS_FMT_RGB565_1X16: + case MEDIA_BUS_FMT_BGR565_2X8_BE: + case MEDIA_BUS_FMT_BGR565_2X8_LE: + case MEDIA_BUS_FMT_RGB565_2X8_BE: + case MEDIA_BUS_FMT_RGB565_2X8_LE: + case MEDIA_BUS_FMT_RGB666_1X18: + case MEDIA_BUS_FMT_RBG888_1X24: + case MEDIA_BUS_FMT_RGB666_1X24_CPADHI: + case MEDIA_BUS_FMT_BGR888_1X24: + case MEDIA_BUS_FMT_GBR888_1X24: + case MEDIA_BUS_FMT_RGB888_1X24: + case MEDIA_BUS_FMT_RGB888_2X12_BE: + case MEDIA_BUS_FMT_RGB888_2X12_LE: + case MEDIA_BUS_FMT_ARGB8888_1X32: + case MEDIA_BUS_FMT_RGB888_1X32_PADHI: + case MEDIA_BUS_FMT_RGB101010_1X30: + case MEDIA_BUS_FMT_RGB121212_1X36: + case MEDIA_BUS_FMT_RGB161616_1X48: + case MEDIA_BUS_FMT_Y8_1X8: + case MEDIA_BUS_FMT_UV8_1X8: + case MEDIA_BUS_FMT_UYVY8_1_5X8: + case MEDIA_BUS_FMT_VYUY8_1_5X8: + case MEDIA_BUS_FMT_YUYV8_1_5X8: + case MEDIA_BUS_FMT_YVYU8_1_5X8: + case MEDIA_BUS_FMT_UYVY8_2X8: + case MEDIA_BUS_FMT_VYUY8_2X8: + case MEDIA_BUS_FMT_YUYV8_2X8: + case MEDIA_BUS_FMT_YVYU8_2X8: + case MEDIA_BUS_FMT_Y10_1X10: + case MEDIA_BUS_FMT_UYVY10_2X10: + case MEDIA_BUS_FMT_VYUY10_2X10: + case MEDIA_BUS_FMT_YUYV10_2X10: + case MEDIA_BUS_FMT_YVYU10_2X10: + case MEDIA_BUS_FMT_Y12_1X12: + case MEDIA_BUS_FMT_UYVY12_2X12: + case MEDIA_BUS_FMT_VYUY12_2X12: + case MEDIA_BUS_FMT_YUYV12_2X12: + case MEDIA_BUS_FMT_YVYU12_2X12: + case MEDIA_BUS_FMT_UYVY8_1X16: + case MEDIA_BUS_FMT_VYUY8_1X16: + case MEDIA_BUS_FMT_YUYV8_1X16: + case MEDIA_BUS_FMT_YVYU8_1X16: + case MEDIA_BUS_FMT_YDYUYDYV8_1X16: + case MEDIA_BUS_FMT_UYVY10_1X20: + case MEDIA_BUS_FMT_VYUY10_1X20: + case MEDIA_BUS_FMT_YUYV10_1X20: + case MEDIA_BUS_FMT_YVYU10_1X20: + case MEDIA_BUS_FMT_VUY8_1X24: + case MEDIA_BUS_FMT_YUV8_1X24: + case MEDIA_BUS_FMT_UYYVYY8_0_5X24: + case MEDIA_BUS_FMT_UYVY12_1X24: + case MEDIA_BUS_FMT_VYUY12_1X24: + case MEDIA_BUS_FMT_YUYV12_1X24: + case MEDIA_BUS_FMT_YVYU12_1X24: + case MEDIA_BUS_FMT_YUV10_1X30: + case MEDIA_BUS_FMT_UYYVYY10_0_5X30: + case MEDIA_BUS_FMT_AYUV8_1X32: + case MEDIA_BUS_FMT_UYYVYY12_0_5X36: + case MEDIA_BUS_FMT_YUV12_1X36: + case MEDIA_BUS_FMT_YUV16_1X48: + case MEDIA_BUS_FMT_UYYVYY16_0_5X48: + case MEDIA_BUS_FMT_JPEG_1X8: + case MEDIA_BUS_FMT_AHSV8888_1X32: + case MEDIA_BUS_FMT_SBGGR8_1X8: + case MEDIA_BUS_FMT_SGBRG8_1X8: + case MEDIA_BUS_FMT_SGRBG8_1X8: + case MEDIA_BUS_FMT_SRGGB8_1X8: + case MEDIA_BUS_FMT_SBGGR10_1X10: + case MEDIA_BUS_FMT_SGBRG10_1X10: + case MEDIA_BUS_FMT_SGRBG10_1X10: + case MEDIA_BUS_FMT_SRGGB10_1X10: + case MEDIA_BUS_FMT_SBGGR12_1X12: + case MEDIA_BUS_FMT_SGBRG12_1X12: + case MEDIA_BUS_FMT_SGRBG12_1X12: + case MEDIA_BUS_FMT_SRGGB12_1X12: + case MEDIA_BUS_FMT_SBGGR14_1X14: + case MEDIA_BUS_FMT_SGBRG14_1X14: + case MEDIA_BUS_FMT_SGRBG14_1X14: + case MEDIA_BUS_FMT_SRGGB14_1X14: + case MEDIA_BUS_FMT_SBGGR16_1X16: + case MEDIA_BUS_FMT_SGBRG16_1X16: + case MEDIA_BUS_FMT_SGRBG16_1X16: + case MEDIA_BUS_FMT_SRGGB16_1X16: + break; + default: + format->format.code = MEDIA_BUS_FMT_Y8_1X8; + break; + } + + if (format->format.field == V4L2_FIELD_ANY) + format->format.field = V4L2_FIELD_NONE; + + mutex_lock(&csi->lock); + + pad = &csi->pads[format->pad]; + if (pad->flags & MEDIA_PAD_FL_SOURCE) + format->format = csi->format_mbus[CSI_PAD_SINK]; + + *mbusformat = format->format; + + if (pad->flags & MEDIA_PAD_FL_SINK) + *source_mbusformat = format->format; + + mutex_unlock(&csi->lock); + + return 0; +} + +static int mei_csi_g_volatile_ctrl(struct v4l2_ctrl *ctrl) +{ + struct mei_csi *csi = ctrl_to_csi(ctrl); + s64 freq; + + if (ctrl->id == V4L2_CID_LINK_FREQ) { + if (!csi->remote) + return -EINVAL; + + freq = v4l2_get_link_freq(csi->remote->ctrl_handler, 0, 0); + if (freq < 0) { + dev_err(&csi->cldev->dev, + "error %lld, invalid link_freq\n", freq); + return -EINVAL; + } + + link_freq_menu_items[0] = freq; + ctrl->val = 0; + + return 0; + } + + return -EINVAL; +} + +static const struct v4l2_ctrl_ops mei_csi_ctrl_ops = { + .g_volatile_ctrl = mei_csi_g_volatile_ctrl, +}; + +static const struct v4l2_subdev_video_ops mei_csi_video_ops = { + .s_stream = mei_csi_set_stream, +}; + +static const struct v4l2_subdev_pad_ops mei_csi_pad_ops = { + .init_cfg = mei_csi_init_cfg, + .get_fmt = mei_csi_get_fmt, + .set_fmt = mei_csi_set_fmt, +}; + +static const struct v4l2_subdev_ops mei_csi_subdev_ops = { + .video = &mei_csi_video_ops, + .pad = &mei_csi_pad_ops, +}; + +static const struct media_entity_operations mei_csi_entity_ops = { + .link_validate = v4l2_subdev_link_validate, +}; + +static int mei_csi_notify_bound(struct v4l2_async_notifier *notifier, + struct v4l2_subdev *subdev, + struct v4l2_async_connection *asd) +{ + struct mei_csi *csi = notifier_to_csi(notifier); + int pad; + + pad = media_entity_get_fwnode_pad(&subdev->entity, asd->match.fwnode, + MEDIA_PAD_FL_SOURCE); + if (pad < 0) + return pad; + + csi->remote = subdev; + csi->remote_pad = pad; + + return media_create_pad_link(&subdev->entity, pad, + &csi->subdev.entity, 1, + MEDIA_LNK_FL_ENABLED | + MEDIA_LNK_FL_IMMUTABLE); +} + +static void mei_csi_notify_unbind(struct v4l2_async_notifier *notifier, + struct v4l2_subdev *subdev, + struct v4l2_async_connection *asd) +{ + struct mei_csi *csi = notifier_to_csi(notifier); + + csi->remote = NULL; +} + +static const struct v4l2_async_notifier_operations mei_csi_notify_ops = { + .bound = mei_csi_notify_bound, + .unbind = mei_csi_notify_unbind, +}; + +static int mei_csi_init_controls(struct mei_csi *csi) +{ + u32 max; + int ret; + + ret = v4l2_ctrl_handler_init(&csi->ctrl_handler, 2); + if (ret) + return ret; + + csi->ctrl_handler.lock = &csi->lock; + + max = ARRAY_SIZE(link_freq_menu_items) - 1; + csi->freq_ctrl = v4l2_ctrl_new_int_menu(&csi->ctrl_handler, + &mei_csi_ctrl_ops, + V4L2_CID_LINK_FREQ, + max, + 0, + link_freq_menu_items); + if (csi->freq_ctrl) + csi->freq_ctrl->flags |= V4L2_CTRL_FLAG_READ_ONLY | + V4L2_CTRL_FLAG_VOLATILE; + + csi->privacy_ctrl = v4l2_ctrl_new_std(&csi->ctrl_handler, NULL, + V4L2_CID_PRIVACY, 0, 1, 1, 0); + if (csi->privacy_ctrl) + csi->privacy_ctrl->flags |= V4L2_CTRL_FLAG_READ_ONLY; + + if (csi->ctrl_handler.error) + return csi->ctrl_handler.error; + + csi->subdev.ctrl_handler = &csi->ctrl_handler; + + return 0; +} + +static int mei_csi_parse_firmware(struct mei_csi *csi) +{ + struct v4l2_fwnode_endpoint v4l2_ep = { + .bus_type = V4L2_MBUS_CSI2_DPHY, + }; + struct device *dev = &csi->cldev->dev; + struct v4l2_async_connection *asd; + struct fwnode_handle *fwnode; + struct fwnode_handle *ep; + int ret; + + ep = fwnode_graph_get_endpoint_by_id(dev_fwnode(dev), 0, 0, 0); + if (!ep) { + dev_err(dev, "not connected to subdevice\n"); + return -EINVAL; + } + + ret = v4l2_fwnode_endpoint_parse(ep, &v4l2_ep); + if (ret) { + dev_err(dev, "could not parse v4l2 endpoint\n"); + fwnode_handle_put(ep); + return -EINVAL; + } + + fwnode = fwnode_graph_get_remote_endpoint(ep); + fwnode_handle_put(ep); + + v4l2_async_subdev_nf_init(&csi->notifier, &csi->subdev); + csi->notifier.ops = &mei_csi_notify_ops; + + asd = v4l2_async_nf_add_fwnode(&csi->notifier, fwnode, + struct v4l2_async_connection); + if (IS_ERR(asd)) { + fwnode_handle_put(fwnode); + return PTR_ERR(asd); + } + + ret = v4l2_fwnode_endpoint_alloc_parse(fwnode, &v4l2_ep); + fwnode_handle_put(fwnode); + if (ret) + return ret; + csi->nr_of_lanes = v4l2_ep.bus.mipi_csi2.num_data_lanes; + + ret = v4l2_async_nf_register(&csi->notifier); + if (ret) + v4l2_async_nf_cleanup(&csi->notifier); + + v4l2_fwnode_endpoint_free(&v4l2_ep); + + return ret; +} + +static int mei_csi_probe(struct mei_cl_device *cldev, + const struct mei_cl_device_id *id) +{ + struct device *dev = &cldev->dev; + struct mei_csi *csi; + int ret; + + if (!dev_fwnode(dev)) + return -EPROBE_DEFER; + + csi = devm_kzalloc(dev, sizeof(struct mei_csi), GFP_KERNEL); + if (!csi) + return -ENOMEM; + + csi->cldev = cldev; + mutex_init(&csi->lock); + init_completion(&csi->cmd_completion); + + mei_cldev_set_drvdata(cldev, csi); + + ret = mei_cldev_enable(cldev); + if (ret < 0) { + dev_err(dev, "mei_cldev_enable failed: %d\n", ret); + goto destroy_mutex; + } + + ret = mei_cldev_register_rx_cb(cldev, mei_csi_rx); + if (ret) { + dev_err(dev, "event cb registration failed: %d\n", ret); + goto err_disable; + } + + ret = mei_csi_parse_firmware(csi); + if (ret) + goto err_disable; + + csi->subdev.dev = &cldev->dev; + v4l2_subdev_init(&csi->subdev, &mei_csi_subdev_ops); + v4l2_set_subdevdata(&csi->subdev, csi); + csi->subdev.flags = V4L2_SUBDEV_FL_HAS_DEVNODE | + V4L2_SUBDEV_FL_HAS_EVENTS; + csi->subdev.entity.function = MEDIA_ENT_F_VID_IF_BRIDGE; + csi->subdev.entity.ops = &mei_csi_entity_ops; + + snprintf(csi->subdev.name, sizeof(csi->subdev.name), + MEI_CSI_ENTITY_NAME); + + ret = mei_csi_init_controls(csi); + if (ret) + goto err_ctrl_handler; + + csi->format_mbus[CSI_PAD_SOURCE] = mei_csi_format_mbus_default; + csi->format_mbus[CSI_PAD_SINK] = mei_csi_format_mbus_default; + + csi->pads[CSI_PAD_SOURCE].flags = MEDIA_PAD_FL_SOURCE; + csi->pads[CSI_PAD_SINK].flags = MEDIA_PAD_FL_SINK; + ret = media_entity_pads_init(&csi->subdev.entity, CSI_NUM_PADS, + csi->pads); + if (ret) + goto err_ctrl_handler; + + ret = v4l2_subdev_init_finalize(&csi->subdev); + if (ret < 0) + goto err_entity; + + ret = v4l2_async_register_subdev(&csi->subdev); + if (ret < 0) + goto err_subdev; + + pm_runtime_enable(&cldev->dev); + + return 0; + +err_subdev: + v4l2_subdev_cleanup(&csi->subdev); + +err_entity: + media_entity_cleanup(&csi->subdev.entity); + +err_ctrl_handler: + v4l2_ctrl_handler_free(&csi->ctrl_handler); + v4l2_async_nf_unregister(&csi->notifier); + v4l2_async_nf_cleanup(&csi->notifier); + +err_disable: + mei_cldev_disable(cldev); + +destroy_mutex: + mutex_destroy(&csi->lock); + + return ret; +} + +static void mei_csi_remove(struct mei_cl_device *cldev) +{ + struct mei_csi *csi = mei_cldev_get_drvdata(cldev); + + v4l2_async_nf_unregister(&csi->notifier); + v4l2_async_nf_cleanup(&csi->notifier); + v4l2_ctrl_handler_free(&csi->ctrl_handler); + v4l2_async_unregister_subdev(&csi->subdev); + v4l2_subdev_cleanup(&csi->subdev); + media_entity_cleanup(&csi->subdev.entity); + + pm_runtime_disable(&cldev->dev); + + mutex_destroy(&csi->lock); +} + +#define MEI_CSI_UUID UUID_LE(0x92335FCF, 0x3203, 0x4472, \ + 0xAF, 0x93, 0x7b, 0x44, 0x53, 0xAC, 0x29, 0xDA) + +static const struct mei_cl_device_id mei_csi_tbl[] = { + { MEI_CSI_DRIVER_NAME, MEI_CSI_UUID, MEI_CL_VERSION_ANY }, + { /* sentinel */ } +}; +MODULE_DEVICE_TABLE(mei, mei_csi_tbl); + +static struct mei_cl_driver mei_csi_driver = { + .id_table = mei_csi_tbl, + .name = MEI_CSI_DRIVER_NAME, + + .probe = mei_csi_probe, + .remove = mei_csi_remove, +}; + +module_mei_cl_driver(mei_csi_driver); + +MODULE_AUTHOR("Wentong Wu <wentong.wu@intel.com>"); +MODULE_AUTHOR("Zhifeng Wang <zhifeng.wang@intel.com>"); +MODULE_DESCRIPTION("Device driver for IVSC CSI"); +MODULE_LICENSE("GPL"); diff --git a/drivers/media/pci/saa7164/saa7164-encoder.c b/drivers/media/pci/saa7164/saa7164-encoder.c index c1b6a0596801..bf73e9e83f52 100644 --- a/drivers/media/pci/saa7164/saa7164-encoder.c +++ b/drivers/media/pci/saa7164/saa7164-encoder.c @@ -383,7 +383,7 @@ int saa7164_s_frequency(struct saa7164_port *port, else if (port->nr == SAA7164_PORT_ENC2) tsport = &dev->ports[SAA7164_PORT_TS2]; else - BUG(); + return -EINVAL; /* should not happen */ fe = tsport->dvb.frontend; diff --git a/drivers/media/pci/saa7164/saa7164-fw.c b/drivers/media/pci/saa7164/saa7164-fw.c index 363689484c54..cc9f384f7f1e 100644 --- a/drivers/media/pci/saa7164/saa7164-fw.c +++ b/drivers/media/pci/saa7164/saa7164-fw.c @@ -271,7 +271,6 @@ int saa7164_downloadfirmware(struct saa7164_dev *dev) dprintk(DBGLVL_FW, "%s() Loader 1 has loaded.\n", __func__); first_timeout = SAA_DEVICE_TIMEOUT; - second_timeout = 60 * SAA_DEVICE_TIMEOUT; second_timeout = 100; err_flags = saa7164_readl(SAA_SECONDSTAGEERROR_FLAGS); diff --git a/drivers/media/pci/ttpci/budget-av.c b/drivers/media/pci/ttpci/budget-av.c index 824529f3c74b..230b104a7cdf 100644 --- a/drivers/media/pci/ttpci/budget-av.c +++ b/drivers/media/pci/ttpci/budget-av.c @@ -123,7 +123,7 @@ static int i2c_writereg(struct i2c_adapter *i2c, u8 id, u8 reg, u8 val) static int ciintf_read_attribute_mem(struct dvb_ca_en50221 *ca, int slot, int address) { - struct budget_av *budget_av = (struct budget_av *) ca->data; + struct budget_av *budget_av = ca->data; int result; if (slot != 0) @@ -142,7 +142,7 @@ static int ciintf_read_attribute_mem(struct dvb_ca_en50221 *ca, int slot, int ad static int ciintf_write_attribute_mem(struct dvb_ca_en50221 *ca, int slot, int address, u8 value) { - struct budget_av *budget_av = (struct budget_av *) ca->data; + struct budget_av *budget_av = ca->data; int result; if (slot != 0) @@ -161,7 +161,7 @@ static int ciintf_write_attribute_mem(struct dvb_ca_en50221 *ca, int slot, int a static int ciintf_read_cam_control(struct dvb_ca_en50221 *ca, int slot, u8 address) { - struct budget_av *budget_av = (struct budget_av *) ca->data; + struct budget_av *budget_av = ca->data; int result; if (slot != 0) @@ -181,7 +181,7 @@ static int ciintf_read_cam_control(struct dvb_ca_en50221 *ca, int slot, u8 addre static int ciintf_write_cam_control(struct dvb_ca_en50221 *ca, int slot, u8 address, u8 value) { - struct budget_av *budget_av = (struct budget_av *) ca->data; + struct budget_av *budget_av = ca->data; int result; if (slot != 0) @@ -200,7 +200,7 @@ static int ciintf_write_cam_control(struct dvb_ca_en50221 *ca, int slot, u8 addr static int ciintf_slot_reset(struct dvb_ca_en50221 *ca, int slot) { - struct budget_av *budget_av = (struct budget_av *) ca->data; + struct budget_av *budget_av = ca->data; struct saa7146_dev *saa = budget_av->budget.dev; if (slot != 0) @@ -229,7 +229,7 @@ static int ciintf_slot_reset(struct dvb_ca_en50221 *ca, int slot) static int ciintf_slot_shutdown(struct dvb_ca_en50221 *ca, int slot) { - struct budget_av *budget_av = (struct budget_av *) ca->data; + struct budget_av *budget_av = ca->data; struct saa7146_dev *saa = budget_av->budget.dev; if (slot != 0) @@ -245,7 +245,7 @@ static int ciintf_slot_shutdown(struct dvb_ca_en50221 *ca, int slot) static int ciintf_slot_ts_enable(struct dvb_ca_en50221 *ca, int slot) { - struct budget_av *budget_av = (struct budget_av *) ca->data; + struct budget_av *budget_av = ca->data; struct saa7146_dev *saa = budget_av->budget.dev; if (slot != 0) @@ -260,7 +260,7 @@ static int ciintf_slot_ts_enable(struct dvb_ca_en50221 *ca, int slot) static int ciintf_poll_slot_status(struct dvb_ca_en50221 *ca, int slot, int open) { - struct budget_av *budget_av = (struct budget_av *) ca->data; + struct budget_av *budget_av = ca->data; struct saa7146_dev *saa = budget_av->budget.dev; int result; @@ -491,7 +491,7 @@ static int philips_su1278_ty_ci_tuner_set_params(struct dvb_frontend *fe) struct dtv_frontend_properties *c = &fe->dtv_property_cache; u32 div; u8 buf[4]; - struct budget *budget = (struct budget *) fe->dvb->priv; + struct budget *budget = fe->dvb->priv; struct i2c_msg msg = {.addr = 0x61,.flags = 0,.buf = buf,.len = sizeof(buf) }; if ((c->frequency < 950000) || (c->frequency > 2150000)) @@ -604,7 +604,7 @@ static const struct stv0299_config cinergy_1200s_1894_0010_config = { static int philips_cu1216_tuner_set_params(struct dvb_frontend *fe) { struct dtv_frontend_properties *c = &fe->dtv_property_cache; - struct budget *budget = (struct budget *) fe->dvb->priv; + struct budget *budget = fe->dvb->priv; u8 buf[6]; struct i2c_msg msg = {.addr = 0x60,.flags = 0,.buf = buf,.len = sizeof(buf) }; int i; @@ -668,7 +668,7 @@ static struct tda10023_config philips_cu1216_tda10023_config = { static int philips_tu1216_tuner_init(struct dvb_frontend *fe) { - struct budget *budget = (struct budget *) fe->dvb->priv; + struct budget *budget = fe->dvb->priv; static u8 tu1216_init[] = { 0x0b, 0xf5, 0x85, 0xab }; struct i2c_msg tuner_msg = {.addr = 0x60,.flags = 0,.buf = tu1216_init,.len = sizeof(tu1216_init) }; @@ -685,7 +685,7 @@ static int philips_tu1216_tuner_init(struct dvb_frontend *fe) static int philips_tu1216_tuner_set_params(struct dvb_frontend *fe) { struct dtv_frontend_properties *c = &fe->dtv_property_cache; - struct budget *budget = (struct budget *) fe->dvb->priv; + struct budget *budget = fe->dvb->priv; u8 tuner_buf[4]; struct i2c_msg tuner_msg = {.addr = 0x60,.flags = 0,.buf = tuner_buf,.len = sizeof(tuner_buf) }; @@ -769,7 +769,7 @@ static int philips_tu1216_tuner_set_params(struct dvb_frontend *fe) static int philips_tu1216_request_firmware(struct dvb_frontend *fe, const struct firmware **fw, char *name) { - struct budget *budget = (struct budget *) fe->dvb->priv; + struct budget *budget = fe->dvb->priv; return request_firmware(fw, name, &budget->dev->pci->dev); } @@ -1353,7 +1353,7 @@ static void frontend_init(struct budget_av *budget_av) static void budget_av_irq(struct saa7146_dev *dev, u32 * isr) { - struct budget_av *budget_av = (struct budget_av *) dev->ext_priv; + struct budget_av *budget_av = dev->ext_priv; dprintk(8, "dev: %p, budget_av: %p\n", dev, budget_av); @@ -1363,7 +1363,7 @@ static void budget_av_irq(struct saa7146_dev *dev, u32 * isr) static int budget_av_detach(struct saa7146_dev *dev) { - struct budget_av *budget_av = (struct budget_av *) dev->ext_priv; + struct budget_av *budget_av = dev->ext_priv; int err; dprintk(2, "dev: %p\n", dev); @@ -1412,7 +1412,7 @@ static int vidioc_enum_input(struct file *file, void *fh, struct v4l2_input *i) static int vidioc_g_input(struct file *file, void *fh, unsigned int *i) { struct saa7146_dev *dev = video_drvdata(file); - struct budget_av *budget_av = (struct budget_av *)dev->ext_priv; + struct budget_av *budget_av = dev->ext_priv; *i = budget_av->cur_input; @@ -1423,7 +1423,7 @@ static int vidioc_g_input(struct file *file, void *fh, unsigned int *i) static int vidioc_s_input(struct file *file, void *fh, unsigned int input) { struct saa7146_dev *dev = video_drvdata(file); - struct budget_av *budget_av = (struct budget_av *)dev->ext_priv; + struct budget_av *budget_av = dev->ext_priv; dprintk(1, "VIDIOC_S_INPUT %d\n", input); return saa7113_setinput(budget_av, input); diff --git a/drivers/media/pci/ttpci/budget-ci.c b/drivers/media/pci/ttpci/budget-ci.c index d59d18647371..66e1a004ee43 100644 --- a/drivers/media/pci/ttpci/budget-ci.c +++ b/drivers/media/pci/ttpci/budget-ci.c @@ -251,7 +251,7 @@ static void msp430_ir_deinit(struct budget_ci *budget_ci) static int ciintf_read_attribute_mem(struct dvb_ca_en50221 *ca, int slot, int address) { - struct budget_ci *budget_ci = (struct budget_ci *) ca->data; + struct budget_ci *budget_ci = ca->data; if (slot != 0) return -EINVAL; @@ -262,7 +262,7 @@ static int ciintf_read_attribute_mem(struct dvb_ca_en50221 *ca, int slot, int ad static int ciintf_write_attribute_mem(struct dvb_ca_en50221 *ca, int slot, int address, u8 value) { - struct budget_ci *budget_ci = (struct budget_ci *) ca->data; + struct budget_ci *budget_ci = ca->data; if (slot != 0) return -EINVAL; @@ -273,7 +273,7 @@ static int ciintf_write_attribute_mem(struct dvb_ca_en50221 *ca, int slot, int a static int ciintf_read_cam_control(struct dvb_ca_en50221 *ca, int slot, u8 address) { - struct budget_ci *budget_ci = (struct budget_ci *) ca->data; + struct budget_ci *budget_ci = ca->data; if (slot != 0) return -EINVAL; @@ -284,7 +284,7 @@ static int ciintf_read_cam_control(struct dvb_ca_en50221 *ca, int slot, u8 addre static int ciintf_write_cam_control(struct dvb_ca_en50221 *ca, int slot, u8 address, u8 value) { - struct budget_ci *budget_ci = (struct budget_ci *) ca->data; + struct budget_ci *budget_ci = ca->data; if (slot != 0) return -EINVAL; @@ -295,7 +295,7 @@ static int ciintf_write_cam_control(struct dvb_ca_en50221 *ca, int slot, u8 addr static int ciintf_slot_reset(struct dvb_ca_en50221 *ca, int slot) { - struct budget_ci *budget_ci = (struct budget_ci *) ca->data; + struct budget_ci *budget_ci = ca->data; struct saa7146_dev *saa = budget_ci->budget.dev; if (slot != 0) @@ -318,7 +318,7 @@ static int ciintf_slot_reset(struct dvb_ca_en50221 *ca, int slot) static int ciintf_slot_shutdown(struct dvb_ca_en50221 *ca, int slot) { - struct budget_ci *budget_ci = (struct budget_ci *) ca->data; + struct budget_ci *budget_ci = ca->data; struct saa7146_dev *saa = budget_ci->budget.dev; if (slot != 0) @@ -331,7 +331,7 @@ static int ciintf_slot_shutdown(struct dvb_ca_en50221 *ca, int slot) static int ciintf_slot_ts_enable(struct dvb_ca_en50221 *ca, int slot) { - struct budget_ci *budget_ci = (struct budget_ci *) ca->data; + struct budget_ci *budget_ci = ca->data; struct saa7146_dev *saa = budget_ci->budget.dev; int tmp; @@ -400,7 +400,7 @@ static void ciintf_interrupt(struct tasklet_struct *t) static int ciintf_poll_slot_status(struct dvb_ca_en50221 *ca, int slot, int open) { - struct budget_ci *budget_ci = (struct budget_ci *) ca->data; + struct budget_ci *budget_ci = ca->data; unsigned int flags; // ensure we don't get spurious IRQs during initialisation @@ -553,7 +553,7 @@ static void ciintf_deinit(struct budget_ci *budget_ci) static void budget_ci_irq(struct saa7146_dev *dev, u32 * isr) { - struct budget_ci *budget_ci = (struct budget_ci *) dev->ext_priv; + struct budget_ci *budget_ci = dev->ext_priv; dprintk(8, "dev: %p, budget_ci: %p\n", dev, budget_ci); @@ -648,7 +648,7 @@ static int philips_su1278_tt_set_symbol_rate(struct dvb_frontend *fe, u32 srate, static int philips_su1278_tt_tuner_set_params(struct dvb_frontend *fe) { struct dtv_frontend_properties *p = &fe->dtv_property_cache; - struct budget_ci *budget_ci = (struct budget_ci *) fe->dvb->priv; + struct budget_ci *budget_ci = fe->dvb->priv; u32 div; u8 buf[4]; struct i2c_msg msg = {.addr = 0x60,.flags = 0,.buf = buf,.len = sizeof(buf) }; @@ -698,7 +698,7 @@ static const struct stv0299_config philips_su1278_tt_config = { static int philips_tdm1316l_tuner_init(struct dvb_frontend *fe) { - struct budget_ci *budget_ci = (struct budget_ci *) fe->dvb->priv; + struct budget_ci *budget_ci = fe->dvb->priv; static u8 td1316_init[] = { 0x0b, 0xf5, 0x85, 0xab }; static u8 disable_mc44BC374c[] = { 0x1d, 0x74, 0xa0, 0x68 }; struct i2c_msg tuner_msg = {.addr = budget_ci->tuner_pll_address,.flags = 0,.buf = td1316_init,.len = @@ -729,7 +729,7 @@ static int philips_tdm1316l_tuner_init(struct dvb_frontend *fe) static int philips_tdm1316l_tuner_set_params(struct dvb_frontend *fe) { struct dtv_frontend_properties *p = &fe->dtv_property_cache; - struct budget_ci *budget_ci = (struct budget_ci *) fe->dvb->priv; + struct budget_ci *budget_ci = fe->dvb->priv; u8 tuner_buf[4]; struct i2c_msg tuner_msg = {.addr = budget_ci->tuner_pll_address,.flags = 0,.buf = tuner_buf,.len = sizeof(tuner_buf) }; int tuner_frequency = 0; @@ -815,7 +815,7 @@ static int philips_tdm1316l_tuner_set_params(struct dvb_frontend *fe) static int philips_tdm1316l_request_firmware(struct dvb_frontend *fe, const struct firmware **fw, char *name) { - struct budget_ci *budget_ci = (struct budget_ci *) fe->dvb->priv; + struct budget_ci *budget_ci = fe->dvb->priv; return request_firmware(fw, name, &budget_ci->budget.dev->pci->dev); } @@ -845,7 +845,7 @@ static struct tda1004x_config philips_tdm1316l_config_invert = { static int dvbc_philips_tdm1316l_tuner_set_params(struct dvb_frontend *fe) { struct dtv_frontend_properties *p = &fe->dtv_property_cache; - struct budget_ci *budget_ci = (struct budget_ci *) fe->dvb->priv; + struct budget_ci *budget_ci = fe->dvb->priv; u8 tuner_buf[5]; struct i2c_msg tuner_msg = {.addr = budget_ci->tuner_pll_address, .flags = 0, @@ -1494,7 +1494,7 @@ out1: static int budget_ci_detach(struct saa7146_dev *dev) { - struct budget_ci *budget_ci = (struct budget_ci *) dev->ext_priv; + struct budget_ci *budget_ci = dev->ext_priv; struct saa7146_dev *saa = budget_ci->budget.dev; int err; diff --git a/drivers/media/pci/ttpci/budget-core.c b/drivers/media/pci/ttpci/budget-core.c index 710595987522..25f44c3eebf3 100644 --- a/drivers/media/pci/ttpci/budget-core.c +++ b/drivers/media/pci/ttpci/budget-core.c @@ -147,7 +147,7 @@ static int start_ts_capture(struct budget *budget) static int budget_read_fe_status(struct dvb_frontend *fe, enum fe_status *status) { - struct budget *budget = (struct budget *) fe->dvb->priv; + struct budget *budget = fe->dvb->priv; int synced; int ret; @@ -570,7 +570,7 @@ int ttpci_budget_deinit(struct budget *budget) void ttpci_budget_irq10_handler(struct saa7146_dev *dev, u32 * isr) { - struct budget *budget = (struct budget *) dev->ext_priv; + struct budget *budget = dev->ext_priv; dprintk(8, "dev: %p, budget: %p\n", dev, budget); @@ -580,7 +580,7 @@ void ttpci_budget_irq10_handler(struct saa7146_dev *dev, u32 * isr) void ttpci_budget_set_video_port(struct saa7146_dev *dev, int video_port) { - struct budget *budget = (struct budget *) dev->ext_priv; + struct budget *budget = dev->ext_priv; spin_lock(&budget->feedlock); budget->video_port = video_port; diff --git a/drivers/media/pci/ttpci/budget.c b/drivers/media/pci/ttpci/budget.c index a88711a3ac7f..b76a1b330b50 100644 --- a/drivers/media/pci/ttpci/budget.c +++ b/drivers/media/pci/ttpci/budget.c @@ -144,7 +144,7 @@ static int SetVoltage_Activy(struct budget *budget, static int siemens_budget_set_voltage(struct dvb_frontend *fe, enum fe_sec_voltage voltage) { - struct budget* budget = (struct budget*) fe->dvb->priv; + struct budget *budget = fe->dvb->priv; return SetVoltage_Activy (budget, voltage); } @@ -152,7 +152,7 @@ static int siemens_budget_set_voltage(struct dvb_frontend *fe, static int budget_set_tone(struct dvb_frontend *fe, enum fe_sec_tone_mode tone) { - struct budget* budget = (struct budget*) fe->dvb->priv; + struct budget *budget = fe->dvb->priv; switch (tone) { case SEC_TONE_ON: @@ -172,7 +172,7 @@ static int budget_set_tone(struct dvb_frontend *fe, static int budget_diseqc_send_master_cmd(struct dvb_frontend* fe, struct dvb_diseqc_master_cmd* cmd) { - struct budget* budget = (struct budget*) fe->dvb->priv; + struct budget *budget = fe->dvb->priv; SendDiSEqCMsg (budget, cmd->msg_len, cmd->msg, 0); @@ -182,7 +182,7 @@ static int budget_diseqc_send_master_cmd(struct dvb_frontend* fe, struct dvb_dis static int budget_diseqc_send_burst(struct dvb_frontend *fe, enum fe_sec_mini_cmd minicmd) { - struct budget* budget = (struct budget*) fe->dvb->priv; + struct budget *budget = fe->dvb->priv; SendDiSEqCMsg (budget, 0, NULL, minicmd); @@ -192,7 +192,7 @@ static int budget_diseqc_send_burst(struct dvb_frontend *fe, static int alps_bsrv2_tuner_set_params(struct dvb_frontend *fe) { struct dtv_frontend_properties *c = &fe->dtv_property_cache; - struct budget* budget = (struct budget*) fe->dvb->priv; + struct budget *budget = fe->dvb->priv; u8 pwr = 0; u8 buf[4]; struct i2c_msg msg = { .addr = 0x61, .flags = 0, .buf = buf, .len = sizeof(buf) }; @@ -234,7 +234,7 @@ static struct ves1x93_config alps_bsrv2_config = static int alps_tdbe2_tuner_set_params(struct dvb_frontend *fe) { struct dtv_frontend_properties *c = &fe->dtv_property_cache; - struct budget* budget = (struct budget*) fe->dvb->priv; + struct budget *budget = fe->dvb->priv; u32 div; u8 data[4]; struct i2c_msg msg = { .addr = 0x62, .flags = 0, .buf = data, .len = sizeof(data) }; @@ -320,7 +320,7 @@ static u8 tuner_address_grundig_29504_401_activy = 0x60; static int grundig_29504_451_tuner_set_params(struct dvb_frontend *fe) { struct dtv_frontend_properties *c = &fe->dtv_property_cache; - struct budget* budget = (struct budget*) fe->dvb->priv; + struct budget *budget = fe->dvb->priv; u32 div; u8 data[4]; struct i2c_msg msg = { .addr = 0x61, .flags = 0, .buf = data, .len = sizeof(data) }; @@ -344,7 +344,7 @@ static struct tda8083_config grundig_29504_451_config = { static int s5h1420_tuner_set_params(struct dvb_frontend *fe) { struct dtv_frontend_properties *c = &fe->dtv_property_cache; - struct budget* budget = (struct budget*) fe->dvb->priv; + struct budget *budget = fe->dvb->priv; u32 div; u8 data[4]; struct i2c_msg msg = { .addr = 0x61, .flags = 0, .buf = data, .len = sizeof(data) }; @@ -405,7 +405,7 @@ static const struct stv0299_config alps_bsbe1_config_activy = { static int alps_tdhd1_204_request_firmware(struct dvb_frontend *fe, const struct firmware **fw, char *name) { - struct budget *budget = (struct budget *)fe->dvb->priv; + struct budget *budget = fe->dvb->priv; return request_firmware(fw, name, &budget->dev->pci->dev); } @@ -800,7 +800,7 @@ static int budget_attach (struct saa7146_dev* dev, struct saa7146_pci_extension_ static int budget_detach (struct saa7146_dev* dev) { - struct budget *budget = (struct budget*) dev->ext_priv; + struct budget *budget = dev->ext_priv; int err; if (budget->dvb_frontend) { |