diff options
author | André Fabian Silva Delgado <emulatorman@parabola.nu> | 2016-09-11 04:34:46 -0300 |
---|---|---|
committer | André Fabian Silva Delgado <emulatorman@parabola.nu> | 2016-09-11 04:34:46 -0300 |
commit | 863981e96738983919de841ec669e157e6bdaeb0 (patch) | |
tree | d6d89a12e7eb8017837c057935a2271290907f76 /drivers/media/platform/vsp1 | |
parent | 8dec7c70575785729a6a9e6719a955e9c545bcab (diff) |
Linux-libre 4.7.1-gnupck-4.7.1-gnu
Diffstat (limited to 'drivers/media/platform/vsp1')
27 files changed, 2074 insertions, 1877 deletions
diff --git a/drivers/media/platform/vsp1/vsp1.h b/drivers/media/platform/vsp1/vsp1.h index 910d6b8e8..46738b6c5 100644 --- a/drivers/media/platform/vsp1/vsp1.h +++ b/drivers/media/platform/vsp1/vsp1.h @@ -26,7 +26,6 @@ struct clk; struct device; -struct vsp1_dl; struct vsp1_drm; struct vsp1_entity; struct vsp1_platform_data; @@ -49,6 +48,7 @@ struct vsp1_uds; struct vsp1_device_info { u32 version; + unsigned int gen; unsigned int features; unsigned int rpf_count; unsigned int uds_count; @@ -85,8 +85,6 @@ struct vsp1_device { struct media_entity_operations media_ops; struct vsp1_drm *drm; - - bool use_dl; }; int vsp1_device_get(struct vsp1_device *vsp1); @@ -104,14 +102,4 @@ static inline void vsp1_write(struct vsp1_device *vsp1, u32 reg, u32 data) iowrite32(data, vsp1->mmio + reg); } -#include "vsp1_dl.h" - -static inline void vsp1_mod_write(struct vsp1_entity *e, u32 reg, u32 data) -{ - if (e->vsp1->use_dl) - vsp1_dl_add(e, reg, data); - else - vsp1_write(e->vsp1, reg, data); -} - #endif /* __VSP1_H__ */ diff --git a/drivers/media/platform/vsp1/vsp1_bru.c b/drivers/media/platform/vsp1/vsp1_bru.c index cb0dbc15d..b1068c018 100644 --- a/drivers/media/platform/vsp1/vsp1_bru.c +++ b/drivers/media/platform/vsp1/vsp1_bru.c @@ -18,6 +18,8 @@ #include "vsp1.h" #include "vsp1_bru.h" +#include "vsp1_dl.h" +#include "vsp1_pipe.h" #include "vsp1_rwpf.h" #include "vsp1_video.h" @@ -28,9 +30,10 @@ * Device Access */ -static inline void vsp1_bru_write(struct vsp1_bru *bru, u32 reg, u32 data) +static inline void vsp1_bru_write(struct vsp1_bru *bru, struct vsp1_dl_list *dl, + u32 reg, u32 data) { - vsp1_mod_write(&bru->entity, reg, data); + vsp1_dl_list_write(dl, reg, data); } /* ----------------------------------------------------------------------------- @@ -42,13 +45,9 @@ static int bru_s_ctrl(struct v4l2_ctrl *ctrl) struct vsp1_bru *bru = container_of(ctrl->handler, struct vsp1_bru, ctrls); - if (!vsp1_entity_is_streaming(&bru->entity)) - return 0; - switch (ctrl->id) { case V4L2_CID_BG_COLOR: - vsp1_bru_write(bru, VI6_BRU_VIRRPF_COL, ctrl->val | - (0xff << VI6_BRU_VIRRPF_COL_A_SHIFT)); + bru->bgcolor = ctrl->val; break; } @@ -60,116 +59,7 @@ static const struct v4l2_ctrl_ops bru_ctrl_ops = { }; /* ----------------------------------------------------------------------------- - * V4L2 Subdevice Core Operations - */ - -static int bru_s_stream(struct v4l2_subdev *subdev, int enable) -{ - struct vsp1_pipeline *pipe = to_vsp1_pipeline(&subdev->entity); - struct vsp1_bru *bru = to_bru(subdev); - struct v4l2_mbus_framefmt *format; - unsigned int flags; - unsigned int i; - int ret; - - ret = vsp1_entity_set_streaming(&bru->entity, enable); - if (ret < 0) - return ret; - - if (!enable) - return 0; - - format = &bru->entity.formats[bru->entity.source_pad]; - - /* The hardware is extremely flexible but we have no userspace API to - * expose all the parameters, nor is it clear whether we would have use - * cases for all the supported modes. Let's just harcode the parameters - * to sane default values for now. - */ - - /* Disable dithering and enable color data normalization unless the - * format at the pipeline output is premultiplied. - */ - flags = pipe->output ? pipe->output->format.flags : 0; - vsp1_bru_write(bru, VI6_BRU_INCTRL, - flags & V4L2_PIX_FMT_FLAG_PREMUL_ALPHA ? - 0 : VI6_BRU_INCTRL_NRM); - - /* Set the background position to cover the whole output image. */ - vsp1_bru_write(bru, VI6_BRU_VIRRPF_SIZE, - (format->width << VI6_BRU_VIRRPF_SIZE_HSIZE_SHIFT) | - (format->height << VI6_BRU_VIRRPF_SIZE_VSIZE_SHIFT)); - vsp1_bru_write(bru, VI6_BRU_VIRRPF_LOC, 0); - - /* Route BRU input 1 as SRC input to the ROP unit and configure the ROP - * unit with a NOP operation to make BRU input 1 available as the - * Blend/ROP unit B SRC input. - */ - vsp1_bru_write(bru, VI6_BRU_ROP, VI6_BRU_ROP_DSTSEL_BRUIN(1) | - VI6_BRU_ROP_CROP(VI6_ROP_NOP) | - VI6_BRU_ROP_AROP(VI6_ROP_NOP)); - - for (i = 0; i < bru->entity.source_pad; ++i) { - bool premultiplied = false; - u32 ctrl = 0; - - /* Configure all Blend/ROP units corresponding to an enabled BRU - * input for alpha blending. Blend/ROP units corresponding to - * disabled BRU inputs are used in ROP NOP mode to ignore the - * SRC input. - */ - if (bru->inputs[i].rpf) { - ctrl |= VI6_BRU_CTRL_RBC; - - premultiplied = bru->inputs[i].rpf->format.flags - & V4L2_PIX_FMT_FLAG_PREMUL_ALPHA; - } else { - ctrl |= VI6_BRU_CTRL_CROP(VI6_ROP_NOP) - | VI6_BRU_CTRL_AROP(VI6_ROP_NOP); - } - - /* Select the virtual RPF as the Blend/ROP unit A DST input to - * serve as a background color. - */ - if (i == 0) - ctrl |= VI6_BRU_CTRL_DSTSEL_VRPF; - - /* Route BRU inputs 0 to 3 as SRC inputs to Blend/ROP units A to - * D in that order. The Blend/ROP unit B SRC is hardwired to the - * ROP unit output, the corresponding register bits must be set - * to 0. - */ - if (i != 1) - ctrl |= VI6_BRU_CTRL_SRCSEL_BRUIN(i); - - vsp1_bru_write(bru, VI6_BRU_CTRL(i), ctrl); - - /* Harcode the blending formula to - * - * DSTc = DSTc * (1 - SRCa) + SRCc * SRCa - * DSTa = DSTa * (1 - SRCa) + SRCa - * - * when the SRC input isn't premultiplied, and to - * - * DSTc = DSTc * (1 - SRCa) + SRCc - * DSTa = DSTa * (1 - SRCa) + SRCa - * - * otherwise. - */ - vsp1_bru_write(bru, VI6_BRU_BLD(i), - VI6_BRU_BLD_CCMDX_255_SRC_A | - (premultiplied ? VI6_BRU_BLD_CCMDY_COEFY : - VI6_BRU_BLD_CCMDY_SRC_A) | - VI6_BRU_BLD_ACMDX_255_SRC_A | - VI6_BRU_BLD_ACMDY_COEFY | - (0xff << VI6_BRU_BLD_COEFY_SHIFT)); - } - - return 0; -} - -/* ----------------------------------------------------------------------------- - * V4L2 Subdevice Pad Operations + * V4L2 Subdevice Operations */ /* @@ -186,24 +76,9 @@ static int bru_enum_mbus_code(struct v4l2_subdev *subdev, MEDIA_BUS_FMT_ARGB8888_1X32, MEDIA_BUS_FMT_AYUV8_1X32, }; - struct vsp1_bru *bru = to_bru(subdev); - struct v4l2_mbus_framefmt *format; - - if (code->pad == BRU_PAD_SINK(0)) { - if (code->index >= ARRAY_SIZE(codes)) - return -EINVAL; - - code->code = codes[code->index]; - } else { - if (code->index) - return -EINVAL; - - format = vsp1_entity_get_pad_format(&bru->entity, cfg, - BRU_PAD_SINK(0), code->which); - code->code = format->code; - } - return 0; + return vsp1_subdev_enum_mbus_code(subdev, cfg, code, codes, + ARRAY_SIZE(codes)); } static int bru_enum_frame_size(struct v4l2_subdev *subdev, @@ -227,32 +102,14 @@ static int bru_enum_frame_size(struct v4l2_subdev *subdev, static struct v4l2_rect *bru_get_compose(struct vsp1_bru *bru, struct v4l2_subdev_pad_config *cfg, - unsigned int pad, u32 which) -{ - switch (which) { - case V4L2_SUBDEV_FORMAT_TRY: - return v4l2_subdev_get_try_crop(&bru->entity.subdev, cfg, pad); - case V4L2_SUBDEV_FORMAT_ACTIVE: - return &bru->inputs[pad].compose; - default: - return NULL; - } -} - -static int bru_get_format(struct v4l2_subdev *subdev, struct v4l2_subdev_pad_config *cfg, - struct v4l2_subdev_format *fmt) + unsigned int pad) { - struct vsp1_bru *bru = to_bru(subdev); - - fmt->format = *vsp1_entity_get_pad_format(&bru->entity, cfg, fmt->pad, - fmt->which); - - return 0; + return v4l2_subdev_get_try_compose(&bru->entity.subdev, cfg, pad); } -static void bru_try_format(struct vsp1_bru *bru, struct v4l2_subdev_pad_config *cfg, - unsigned int pad, struct v4l2_mbus_framefmt *fmt, - enum v4l2_subdev_format_whence which) +static void bru_try_format(struct vsp1_bru *bru, + struct v4l2_subdev_pad_config *config, + unsigned int pad, struct v4l2_mbus_framefmt *fmt) { struct v4l2_mbus_framefmt *format; @@ -266,8 +123,8 @@ static void bru_try_format(struct vsp1_bru *bru, struct v4l2_subdev_pad_config * default: /* The BRU can't perform format conversion. */ - format = vsp1_entity_get_pad_format(&bru->entity, cfg, - BRU_PAD_SINK(0), which); + format = vsp1_entity_get_pad_format(&bru->entity, config, + BRU_PAD_SINK(0)); fmt->code = format->code; break; } @@ -278,23 +135,28 @@ static void bru_try_format(struct vsp1_bru *bru, struct v4l2_subdev_pad_config * fmt->colorspace = V4L2_COLORSPACE_SRGB; } -static int bru_set_format(struct v4l2_subdev *subdev, struct v4l2_subdev_pad_config *cfg, +static int bru_set_format(struct v4l2_subdev *subdev, + struct v4l2_subdev_pad_config *cfg, struct v4l2_subdev_format *fmt) { struct vsp1_bru *bru = to_bru(subdev); + struct v4l2_subdev_pad_config *config; struct v4l2_mbus_framefmt *format; - bru_try_format(bru, cfg, fmt->pad, &fmt->format, fmt->which); + config = vsp1_entity_get_pad_config(&bru->entity, cfg, fmt->which); + if (!config) + return -EINVAL; + + bru_try_format(bru, config, fmt->pad, &fmt->format); - format = vsp1_entity_get_pad_format(&bru->entity, cfg, fmt->pad, - fmt->which); + format = vsp1_entity_get_pad_format(&bru->entity, config, fmt->pad); *format = fmt->format; /* Reset the compose rectangle */ if (fmt->pad != bru->entity.source_pad) { struct v4l2_rect *compose; - compose = bru_get_compose(bru, cfg, fmt->pad, fmt->which); + compose = bru_get_compose(bru, config, fmt->pad); compose->left = 0; compose->top = 0; compose->width = format->width; @@ -306,8 +168,8 @@ static int bru_set_format(struct v4l2_subdev *subdev, struct v4l2_subdev_pad_con unsigned int i; for (i = 0; i <= bru->entity.source_pad; ++i) { - format = vsp1_entity_get_pad_format(&bru->entity, cfg, - i, fmt->which); + format = vsp1_entity_get_pad_format(&bru->entity, + config, i); format->code = fmt->format.code; } } @@ -320,6 +182,7 @@ static int bru_get_selection(struct v4l2_subdev *subdev, struct v4l2_subdev_selection *sel) { struct vsp1_bru *bru = to_bru(subdev); + struct v4l2_subdev_pad_config *config; if (sel->pad == bru->entity.source_pad) return -EINVAL; @@ -333,7 +196,12 @@ static int bru_get_selection(struct v4l2_subdev *subdev, return 0; case V4L2_SEL_TGT_COMPOSE: - sel->r = *bru_get_compose(bru, cfg, sel->pad, sel->which); + config = vsp1_entity_get_pad_config(&bru->entity, cfg, + sel->which); + if (!config) + return -EINVAL; + + sel->r = *bru_get_compose(bru, config, sel->pad); return 0; default: @@ -346,6 +214,7 @@ static int bru_set_selection(struct v4l2_subdev *subdev, struct v4l2_subdev_selection *sel) { struct vsp1_bru *bru = to_bru(subdev); + struct v4l2_subdev_pad_config *config; struct v4l2_mbus_framefmt *format; struct v4l2_rect *compose; @@ -355,57 +224,161 @@ static int bru_set_selection(struct v4l2_subdev *subdev, if (sel->target != V4L2_SEL_TGT_COMPOSE) return -EINVAL; + config = vsp1_entity_get_pad_config(&bru->entity, cfg, sel->which); + if (!config) + return -EINVAL; + /* The compose rectangle top left corner must be inside the output * frame. */ - format = vsp1_entity_get_pad_format(&bru->entity, cfg, - bru->entity.source_pad, sel->which); + format = vsp1_entity_get_pad_format(&bru->entity, config, + bru->entity.source_pad); sel->r.left = clamp_t(unsigned int, sel->r.left, 0, format->width - 1); sel->r.top = clamp_t(unsigned int, sel->r.top, 0, format->height - 1); /* Scaling isn't supported, the compose rectangle size must be identical * to the sink format size. */ - format = vsp1_entity_get_pad_format(&bru->entity, cfg, sel->pad, - sel->which); + format = vsp1_entity_get_pad_format(&bru->entity, config, sel->pad); sel->r.width = format->width; sel->r.height = format->height; - compose = bru_get_compose(bru, cfg, sel->pad, sel->which); + compose = bru_get_compose(bru, config, sel->pad); *compose = sel->r; return 0; } -/* ----------------------------------------------------------------------------- - * V4L2 Subdevice Operations - */ - -static struct v4l2_subdev_video_ops bru_video_ops = { - .s_stream = bru_s_stream, -}; - static struct v4l2_subdev_pad_ops bru_pad_ops = { + .init_cfg = vsp1_entity_init_cfg, .enum_mbus_code = bru_enum_mbus_code, .enum_frame_size = bru_enum_frame_size, - .get_fmt = bru_get_format, + .get_fmt = vsp1_subdev_get_pad_format, .set_fmt = bru_set_format, .get_selection = bru_get_selection, .set_selection = bru_set_selection, }; static struct v4l2_subdev_ops bru_ops = { - .video = &bru_video_ops, .pad = &bru_pad_ops, }; /* ----------------------------------------------------------------------------- + * VSP1 Entity Operations + */ + +static void bru_configure(struct vsp1_entity *entity, + struct vsp1_pipeline *pipe, + struct vsp1_dl_list *dl) +{ + struct vsp1_bru *bru = to_bru(&entity->subdev); + struct v4l2_mbus_framefmt *format; + unsigned int flags; + unsigned int i; + + format = vsp1_entity_get_pad_format(&bru->entity, bru->entity.config, + bru->entity.source_pad); + + /* The hardware is extremely flexible but we have no userspace API to + * expose all the parameters, nor is it clear whether we would have use + * cases for all the supported modes. Let's just harcode the parameters + * to sane default values for now. + */ + + /* Disable dithering and enable color data normalization unless the + * format at the pipeline output is premultiplied. + */ + flags = pipe->output ? pipe->output->format.flags : 0; + vsp1_bru_write(bru, dl, VI6_BRU_INCTRL, + flags & V4L2_PIX_FMT_FLAG_PREMUL_ALPHA ? + 0 : VI6_BRU_INCTRL_NRM); + + /* Set the background position to cover the whole output image and + * configure its color. + */ + vsp1_bru_write(bru, dl, VI6_BRU_VIRRPF_SIZE, + (format->width << VI6_BRU_VIRRPF_SIZE_HSIZE_SHIFT) | + (format->height << VI6_BRU_VIRRPF_SIZE_VSIZE_SHIFT)); + vsp1_bru_write(bru, dl, VI6_BRU_VIRRPF_LOC, 0); + + vsp1_bru_write(bru, dl, VI6_BRU_VIRRPF_COL, bru->bgcolor | + (0xff << VI6_BRU_VIRRPF_COL_A_SHIFT)); + + /* Route BRU input 1 as SRC input to the ROP unit and configure the ROP + * unit with a NOP operation to make BRU input 1 available as the + * Blend/ROP unit B SRC input. + */ + vsp1_bru_write(bru, dl, VI6_BRU_ROP, VI6_BRU_ROP_DSTSEL_BRUIN(1) | + VI6_BRU_ROP_CROP(VI6_ROP_NOP) | + VI6_BRU_ROP_AROP(VI6_ROP_NOP)); + + for (i = 0; i < bru->entity.source_pad; ++i) { + bool premultiplied = false; + u32 ctrl = 0; + + /* Configure all Blend/ROP units corresponding to an enabled BRU + * input for alpha blending. Blend/ROP units corresponding to + * disabled BRU inputs are used in ROP NOP mode to ignore the + * SRC input. + */ + if (bru->inputs[i].rpf) { + ctrl |= VI6_BRU_CTRL_RBC; + + premultiplied = bru->inputs[i].rpf->format.flags + & V4L2_PIX_FMT_FLAG_PREMUL_ALPHA; + } else { + ctrl |= VI6_BRU_CTRL_CROP(VI6_ROP_NOP) + | VI6_BRU_CTRL_AROP(VI6_ROP_NOP); + } + + /* Select the virtual RPF as the Blend/ROP unit A DST input to + * serve as a background color. + */ + if (i == 0) + ctrl |= VI6_BRU_CTRL_DSTSEL_VRPF; + + /* Route BRU inputs 0 to 3 as SRC inputs to Blend/ROP units A to + * D in that order. The Blend/ROP unit B SRC is hardwired to the + * ROP unit output, the corresponding register bits must be set + * to 0. + */ + if (i != 1) + ctrl |= VI6_BRU_CTRL_SRCSEL_BRUIN(i); + + vsp1_bru_write(bru, dl, VI6_BRU_CTRL(i), ctrl); + + /* Harcode the blending formula to + * + * DSTc = DSTc * (1 - SRCa) + SRCc * SRCa + * DSTa = DSTa * (1 - SRCa) + SRCa + * + * when the SRC input isn't premultiplied, and to + * + * DSTc = DSTc * (1 - SRCa) + SRCc + * DSTa = DSTa * (1 - SRCa) + SRCa + * + * otherwise. + */ + vsp1_bru_write(bru, dl, VI6_BRU_BLD(i), + VI6_BRU_BLD_CCMDX_255_SRC_A | + (premultiplied ? VI6_BRU_BLD_CCMDY_COEFY : + VI6_BRU_BLD_CCMDY_SRC_A) | + VI6_BRU_BLD_ACMDX_255_SRC_A | + VI6_BRU_BLD_ACMDY_COEFY | + (0xff << VI6_BRU_BLD_COEFY_SHIFT)); + } +} + +static const struct vsp1_entity_operations bru_entity_ops = { + .configure = bru_configure, +}; + +/* ----------------------------------------------------------------------------- * Initialization and Cleanup */ struct vsp1_bru *vsp1_bru_create(struct vsp1_device *vsp1) { - struct v4l2_subdev *subdev; struct vsp1_bru *bru; int ret; @@ -413,31 +386,21 @@ struct vsp1_bru *vsp1_bru_create(struct vsp1_device *vsp1) if (bru == NULL) return ERR_PTR(-ENOMEM); + bru->entity.ops = &bru_entity_ops; bru->entity.type = VSP1_ENTITY_BRU; - ret = vsp1_entity_init(vsp1, &bru->entity, - vsp1->info->num_bru_inputs + 1); + ret = vsp1_entity_init(vsp1, &bru->entity, "bru", + vsp1->info->num_bru_inputs + 1, &bru_ops); if (ret < 0) return ERR_PTR(ret); - /* Initialize the V4L2 subdev. */ - subdev = &bru->entity.subdev; - v4l2_subdev_init(subdev, &bru_ops); - - subdev->entity.ops = &vsp1->media_ops; - subdev->internal_ops = &vsp1_subdev_internal_ops; - snprintf(subdev->name, sizeof(subdev->name), "%s bru", - dev_name(vsp1->dev)); - v4l2_set_subdevdata(subdev, bru); - subdev->flags |= V4L2_SUBDEV_FL_HAS_DEVNODE; - - vsp1_entity_init_formats(subdev, NULL); - /* Initialize the control handler. */ v4l2_ctrl_handler_init(&bru->ctrls, 1); v4l2_ctrl_new_std(&bru->ctrls, &bru_ctrl_ops, V4L2_CID_BG_COLOR, 0, 0xffffff, 1, 0); + bru->bgcolor = 0; + bru->entity.subdev.ctrl_handler = &bru->ctrls; if (bru->ctrls.error) { diff --git a/drivers/media/platform/vsp1/vsp1_bru.h b/drivers/media/platform/vsp1/vsp1_bru.h index dbac9686e..828a3fcad 100644 --- a/drivers/media/platform/vsp1/vsp1_bru.h +++ b/drivers/media/platform/vsp1/vsp1_bru.h @@ -31,8 +31,9 @@ struct vsp1_bru { struct { struct vsp1_rwpf *rpf; - struct v4l2_rect compose; } inputs[VSP1_MAX_RPF]; + + u32 bgcolor; }; static inline struct vsp1_bru *to_bru(struct v4l2_subdev *subdev) diff --git a/drivers/media/platform/vsp1/vsp1_dl.c b/drivers/media/platform/vsp1/vsp1_dl.c index 1a9a58588..e238d9b93 100644 --- a/drivers/media/platform/vsp1/vsp1_dl.c +++ b/drivers/media/platform/vsp1/vsp1_dl.c @@ -18,139 +18,406 @@ #include "vsp1.h" #include "vsp1_dl.h" -#include "vsp1_pipe.h" -/* - * Global resources - * - * - Display-related interrupts (can be used for vblank evasion ?) - * - Display-list enable - * - Header-less for WPF0 - * - DL swap - */ - -#define VSP1_DL_BODY_SIZE (2 * 4 * 256) +#define VSP1_DL_NUM_ENTRIES 256 #define VSP1_DL_NUM_LISTS 3 +#define VSP1_DLH_INT_ENABLE (1 << 1) +#define VSP1_DLH_AUTO_START (1 << 0) + +struct vsp1_dl_header_list { + u32 num_bytes; + u32 addr; +} __attribute__((__packed__)); + +struct vsp1_dl_header { + u32 num_lists; + struct vsp1_dl_header_list lists[8]; + u32 next_header; + u32 flags; +} __attribute__((__packed__)); + struct vsp1_dl_entry { u32 addr; u32 data; } __attribute__((__packed__)); -struct vsp1_dl_list { +/** + * struct vsp1_dl_body - Display list body + * @list: entry in the display list list of bodies + * @vsp1: the VSP1 device + * @entries: array of entries + * @dma: DMA address of the entries + * @size: size of the DMA memory in bytes + * @num_entries: number of stored entries + */ +struct vsp1_dl_body { + struct list_head list; + struct vsp1_device *vsp1; + + struct vsp1_dl_entry *entries; + dma_addr_t dma; size_t size; - int reg_count; - bool in_use; + unsigned int num_entries; +}; - struct vsp1_dl_entry *body; +/** + * struct vsp1_dl_list - Display list + * @list: entry in the display list manager lists + * @dlm: the display list manager + * @header: display list header, NULL for headerless lists + * @dma: DMA address for the header + * @body0: first display list body + * @fragments: list of extra display list bodies + */ +struct vsp1_dl_list { + struct list_head list; + struct vsp1_dl_manager *dlm; + + struct vsp1_dl_header *header; dma_addr_t dma; + + struct vsp1_dl_body body0; + struct list_head fragments; +}; + +enum vsp1_dl_mode { + VSP1_DL_MODE_HEADER, + VSP1_DL_MODE_HEADERLESS, }; /** - * struct vsp1_dl - Display List manager + * struct vsp1_dl_manager - Display List manager + * @index: index of the related WPF + * @mode: display list operation mode (header or headerless) * @vsp1: the VSP1 device * @lock: protects the active, queued and pending lists - * @lists.all: array of all allocate display lists - * @lists.active: list currently being processed (loaded) by hardware - * @lists.queued: list queued to the hardware (written to the DL registers) - * @lists.pending: list waiting to be queued to the hardware - * @lists.write: list being written to by software + * @free: array of all free display lists + * @active: list currently being processed (loaded) by hardware + * @queued: list queued to the hardware (written to the DL registers) + * @pending: list waiting to be queued to the hardware */ -struct vsp1_dl { +struct vsp1_dl_manager { + unsigned int index; + enum vsp1_dl_mode mode; struct vsp1_device *vsp1; spinlock_t lock; + struct list_head free; + struct vsp1_dl_list *active; + struct vsp1_dl_list *queued; + struct vsp1_dl_list *pending; +}; - size_t size; - dma_addr_t dma; - void *mem; +/* ----------------------------------------------------------------------------- + * Display List Body Management + */ + +/* + * Initialize a display list body object and allocate DMA memory for the body + * data. The display list body object is expected to have been initialized to + * 0 when allocated. + */ +static int vsp1_dl_body_init(struct vsp1_device *vsp1, + struct vsp1_dl_body *dlb, unsigned int num_entries, + size_t extra_size) +{ + size_t size = num_entries * sizeof(*dlb->entries) + extra_size; - struct { - struct vsp1_dl_list all[VSP1_DL_NUM_LISTS]; + dlb->vsp1 = vsp1; + dlb->size = size; - struct vsp1_dl_list *active; - struct vsp1_dl_list *queued; - struct vsp1_dl_list *pending; - struct vsp1_dl_list *write; - } lists; -}; + dlb->entries = dma_alloc_wc(vsp1->dev, dlb->size, &dlb->dma, + GFP_KERNEL); + if (!dlb->entries) + return -ENOMEM; + + return 0; +} + +/* + * Cleanup a display list body and free allocated DMA memory allocated. + */ +static void vsp1_dl_body_cleanup(struct vsp1_dl_body *dlb) +{ + dma_free_wc(dlb->vsp1->dev, dlb->size, dlb->entries, dlb->dma); +} + +/** + * vsp1_dl_fragment_alloc - Allocate a display list fragment + * @vsp1: The VSP1 device + * @num_entries: The maximum number of entries that the fragment can contain + * + * Allocate a display list fragment with enough memory to contain the requested + * number of entries. + * + * Return a pointer to a fragment on success or NULL if memory can't be + * allocated. + */ +struct vsp1_dl_body *vsp1_dl_fragment_alloc(struct vsp1_device *vsp1, + unsigned int num_entries) +{ + struct vsp1_dl_body *dlb; + int ret; + + dlb = kzalloc(sizeof(*dlb), GFP_KERNEL); + if (!dlb) + return NULL; + + ret = vsp1_dl_body_init(vsp1, dlb, num_entries, 0); + if (ret < 0) { + kfree(dlb); + return NULL; + } + + return dlb; +} + +/** + * vsp1_dl_fragment_free - Free a display list fragment + * @dlb: The fragment + * + * Free the given display list fragment and the associated DMA memory. + * + * Fragments must only be freed explicitly if they are not added to a display + * list, as the display list will take ownership of them and free them + * otherwise. Manual free typically happens at cleanup time for fragments that + * have been allocated but not used. + * + * Passing a NULL pointer to this function is safe, in that case no operation + * will be performed. + */ +void vsp1_dl_fragment_free(struct vsp1_dl_body *dlb) +{ + if (!dlb) + return; + + vsp1_dl_body_cleanup(dlb); + kfree(dlb); +} + +/** + * vsp1_dl_fragment_write - Write a register to a display list fragment + * @dlb: The fragment + * @reg: The register address + * @data: The register value + * + * Write the given register and value to the display list fragment. The maximum + * number of entries that can be written in a fragment is specified when the + * fragment is allocated by vsp1_dl_fragment_alloc(). + */ +void vsp1_dl_fragment_write(struct vsp1_dl_body *dlb, u32 reg, u32 data) +{ + dlb->entries[dlb->num_entries].addr = reg; + dlb->entries[dlb->num_entries].data = data; + dlb->num_entries++; +} /* ----------------------------------------------------------------------------- * Display List Transaction Management */ -static void vsp1_dl_free_list(struct vsp1_dl_list *list) +static struct vsp1_dl_list *vsp1_dl_list_alloc(struct vsp1_dl_manager *dlm) { - if (!list) - return; + struct vsp1_dl_list *dl; + size_t header_size; + int ret; + + dl = kzalloc(sizeof(*dl), GFP_KERNEL); + if (!dl) + return NULL; - list->in_use = false; + INIT_LIST_HEAD(&dl->fragments); + dl->dlm = dlm; + + /* Initialize the display list body and allocate DMA memory for the body + * and the optional header. Both are allocated together to avoid memory + * fragmentation, with the header located right after the body in + * memory. + */ + header_size = dlm->mode == VSP1_DL_MODE_HEADER + ? ALIGN(sizeof(struct vsp1_dl_header), 8) + : 0; + + ret = vsp1_dl_body_init(dlm->vsp1, &dl->body0, VSP1_DL_NUM_ENTRIES, + header_size); + if (ret < 0) { + kfree(dl); + return NULL; + } + + if (dlm->mode == VSP1_DL_MODE_HEADER) { + size_t header_offset = VSP1_DL_NUM_ENTRIES + * sizeof(*dl->body0.entries); + + dl->header = ((void *)dl->body0.entries) + header_offset; + dl->dma = dl->body0.dma + header_offset; + + memset(dl->header, 0, sizeof(*dl->header)); + dl->header->lists[0].addr = dl->body0.dma; + dl->header->flags = VSP1_DLH_INT_ENABLE; + } + + return dl; } -void vsp1_dl_reset(struct vsp1_dl *dl) +static void vsp1_dl_list_free_fragments(struct vsp1_dl_list *dl) { - unsigned int i; + struct vsp1_dl_body *dlb, *next; - dl->lists.active = NULL; - dl->lists.queued = NULL; - dl->lists.pending = NULL; - dl->lists.write = NULL; + list_for_each_entry_safe(dlb, next, &dl->fragments, list) { + list_del(&dlb->list); + vsp1_dl_body_cleanup(dlb); + kfree(dlb); + } +} - for (i = 0; i < ARRAY_SIZE(dl->lists.all); ++i) - dl->lists.all[i].in_use = false; +static void vsp1_dl_list_free(struct vsp1_dl_list *dl) +{ + vsp1_dl_body_cleanup(&dl->body0); + vsp1_dl_list_free_fragments(dl); + kfree(dl); } -void vsp1_dl_begin(struct vsp1_dl *dl) +/** + * vsp1_dl_list_get - Get a free display list + * @dlm: The display list manager + * + * Get a display list from the pool of free lists and return it. + * + * This function must be called without the display list manager lock held. + */ +struct vsp1_dl_list *vsp1_dl_list_get(struct vsp1_dl_manager *dlm) { - struct vsp1_dl_list *list = NULL; + struct vsp1_dl_list *dl = NULL; unsigned long flags; - unsigned int i; - spin_lock_irqsave(&dl->lock, flags); + spin_lock_irqsave(&dlm->lock, flags); - for (i = 0; i < ARRAY_SIZE(dl->lists.all); ++i) { - if (!dl->lists.all[i].in_use) { - list = &dl->lists.all[i]; - break; - } + if (!list_empty(&dlm->free)) { + dl = list_first_entry(&dlm->free, struct vsp1_dl_list, list); + list_del(&dl->list); } - if (!list) { - list = dl->lists.pending; - dl->lists.pending = NULL; - } + spin_unlock_irqrestore(&dlm->lock, flags); + + return dl; +} + +/* This function must be called with the display list manager lock held.*/ +static void __vsp1_dl_list_put(struct vsp1_dl_list *dl) +{ + if (!dl) + return; + + vsp1_dl_list_free_fragments(dl); + dl->body0.num_entries = 0; + + list_add_tail(&dl->list, &dl->dlm->free); +} + +/** + * vsp1_dl_list_put - Release a display list + * @dl: The display list + * + * Release the display list and return it to the pool of free lists. + * + * Passing a NULL pointer to this function is safe, in that case no operation + * will be performed. + */ +void vsp1_dl_list_put(struct vsp1_dl_list *dl) +{ + unsigned long flags; - spin_unlock_irqrestore(&dl->lock, flags); + if (!dl) + return; - dl->lists.write = list; + spin_lock_irqsave(&dl->dlm->lock, flags); + __vsp1_dl_list_put(dl); + spin_unlock_irqrestore(&dl->dlm->lock, flags); +} - list->in_use = true; - list->reg_count = 0; +/** + * vsp1_dl_list_write - Write a register to the display list + * @dl: The display list + * @reg: The register address + * @data: The register value + * + * Write the given register and value to the display list. Up to 256 registers + * can be written per display list. + */ +void vsp1_dl_list_write(struct vsp1_dl_list *dl, u32 reg, u32 data) +{ + vsp1_dl_fragment_write(&dl->body0, reg, data); } -void vsp1_dl_add(struct vsp1_entity *e, u32 reg, u32 data) +/** + * vsp1_dl_list_add_fragment - Add a fragment to the display list + * @dl: The display list + * @dlb: The fragment + * + * Add a display list body as a fragment to a display list. Registers contained + * in fragments are processed after registers contained in the main display + * list, in the order in which fragments are added. + * + * Adding a fragment to a display list passes ownership of the fragment to the + * list. The caller must not touch the fragment after this call, and must not + * free it explicitly with vsp1_dl_fragment_free(). + * + * Fragments are only usable for display lists in header mode. Attempt to + * add a fragment to a header-less display list will return an error. + */ +int vsp1_dl_list_add_fragment(struct vsp1_dl_list *dl, + struct vsp1_dl_body *dlb) { - struct vsp1_pipeline *pipe = to_vsp1_pipeline(&e->subdev.entity); - struct vsp1_dl *dl = pipe->dl; - struct vsp1_dl_list *list = dl->lists.write; + /* Multi-body lists are only available in header mode. */ + if (dl->dlm->mode != VSP1_DL_MODE_HEADER) + return -EINVAL; - list->body[list->reg_count].addr = reg; - list->body[list->reg_count].data = data; - list->reg_count++; + list_add_tail(&dlb->list, &dl->fragments); + return 0; } -void vsp1_dl_commit(struct vsp1_dl *dl) +void vsp1_dl_list_commit(struct vsp1_dl_list *dl) { - struct vsp1_device *vsp1 = dl->vsp1; - struct vsp1_dl_list *list; + struct vsp1_dl_manager *dlm = dl->dlm; + struct vsp1_device *vsp1 = dlm->vsp1; unsigned long flags; bool update; - list = dl->lists.write; - dl->lists.write = NULL; + spin_lock_irqsave(&dlm->lock, flags); + + if (dl->dlm->mode == VSP1_DL_MODE_HEADER) { + struct vsp1_dl_header_list *hdr = dl->header->lists; + struct vsp1_dl_body *dlb; + unsigned int num_lists = 0; + + /* Fill the header with the display list bodies addresses and + * sizes. The address of the first body has already been filled + * when the display list was allocated. + * + * In header mode the caller guarantees that the hardware is + * idle at this point. + */ + hdr->num_bytes = dl->body0.num_entries + * sizeof(*dl->header->lists); + + list_for_each_entry(dlb, &dl->fragments, list) { + num_lists++; + hdr++; + + hdr->addr = dlb->dma; + hdr->num_bytes = dlb->num_entries + * sizeof(*dl->header->lists); + } + + dl->header->num_lists = num_lists; + vsp1_write(vsp1, VI6_DL_HDR_ADDR(dlm->index), dl->dma); - spin_lock_irqsave(&dl->lock, flags); + dlm->active = dl; + goto done; + } /* Once the UPD bit has been set the hardware can start processing the * display list at any time and we can't touch the address and size @@ -159,8 +426,8 @@ void vsp1_dl_commit(struct vsp1_dl *dl) */ update = !!(vsp1_read(vsp1, VI6_DL_BODY_SIZE) & VI6_DL_BODY_SIZE_UPD); if (update) { - vsp1_dl_free_list(dl->lists.pending); - dl->lists.pending = list; + __vsp1_dl_list_put(dlm->pending); + dlm->pending = dl; goto done; } @@ -168,42 +435,51 @@ void vsp1_dl_commit(struct vsp1_dl *dl) * The UPD bit will be cleared by the device when the display list is * processed. */ - vsp1_write(vsp1, VI6_DL_HDR_ADDR(0), list->dma); + vsp1_write(vsp1, VI6_DL_HDR_ADDR(0), dl->body0.dma); vsp1_write(vsp1, VI6_DL_BODY_SIZE, VI6_DL_BODY_SIZE_UPD | - (list->reg_count * 8)); + (dl->body0.num_entries * sizeof(*dl->header->lists))); - vsp1_dl_free_list(dl->lists.queued); - dl->lists.queued = list; + __vsp1_dl_list_put(dlm->queued); + dlm->queued = dl; done: - spin_unlock_irqrestore(&dl->lock, flags); + spin_unlock_irqrestore(&dlm->lock, flags); } /* ----------------------------------------------------------------------------- - * Interrupt Handling + * Display List Manager */ -void vsp1_dl_irq_display_start(struct vsp1_dl *dl) +/* Interrupt Handling */ +void vsp1_dlm_irq_display_start(struct vsp1_dl_manager *dlm) { - spin_lock(&dl->lock); + spin_lock(&dlm->lock); /* The display start interrupt signals the end of the display list * processing by the device. The active display list, if any, won't be * accessed anymore and can be reused. */ - if (dl->lists.active) { - vsp1_dl_free_list(dl->lists.active); - dl->lists.active = NULL; - } + __vsp1_dl_list_put(dlm->active); + dlm->active = NULL; - spin_unlock(&dl->lock); + spin_unlock(&dlm->lock); } -void vsp1_dl_irq_frame_end(struct vsp1_dl *dl) +void vsp1_dlm_irq_frame_end(struct vsp1_dl_manager *dlm) { - struct vsp1_device *vsp1 = dl->vsp1; + struct vsp1_device *vsp1 = dlm->vsp1; + + spin_lock(&dlm->lock); + + __vsp1_dl_list_put(dlm->active); + dlm->active = NULL; - spin_lock(&dl->lock); + /* Header mode is used for mem-to-mem pipelines only. We don't need to + * perform any operation as there can't be any new display list queued + * in that case. + */ + if (dlm->mode == VSP1_DL_MODE_HEADER) + goto done; /* The UPD bit set indicates that the commit operation raced with the * interrupt and occurred after the frame end event and UPD clear but @@ -216,42 +492,39 @@ void vsp1_dl_irq_frame_end(struct vsp1_dl *dl) /* The device starts processing the queued display list right after the * frame end interrupt. The display list thus becomes active. */ - if (dl->lists.queued) { - WARN_ON(dl->lists.active); - dl->lists.active = dl->lists.queued; - dl->lists.queued = NULL; + if (dlm->queued) { + dlm->active = dlm->queued; + dlm->queued = NULL; } /* Now that the UPD bit has been cleared we can queue the next display * list to the hardware if one has been prepared. */ - if (dl->lists.pending) { - struct vsp1_dl_list *list = dl->lists.pending; + if (dlm->pending) { + struct vsp1_dl_list *dl = dlm->pending; - vsp1_write(vsp1, VI6_DL_HDR_ADDR(0), list->dma); + vsp1_write(vsp1, VI6_DL_HDR_ADDR(0), dl->body0.dma); vsp1_write(vsp1, VI6_DL_BODY_SIZE, VI6_DL_BODY_SIZE_UPD | - (list->reg_count * 8)); + (dl->body0.num_entries * + sizeof(*dl->header->lists))); - dl->lists.queued = list; - dl->lists.pending = NULL; + dlm->queued = dl; + dlm->pending = NULL; } done: - spin_unlock(&dl->lock); + spin_unlock(&dlm->lock); } -/* ----------------------------------------------------------------------------- - * Hardware Setup - */ - -void vsp1_dl_setup(struct vsp1_device *vsp1) +/* Hardware Setup */ +void vsp1_dlm_setup(struct vsp1_device *vsp1) { u32 ctrl = (256 << VI6_DL_CTRL_AR_WAIT_SHIFT) | VI6_DL_CTRL_DC2 | VI6_DL_CTRL_DC1 | VI6_DL_CTRL_DC0 | VI6_DL_CTRL_DLE; - /* The DRM pipeline operates with header-less display lists in - * Continuous Frame Mode. + /* The DRM pipeline operates with display lists in Continuous Frame + * Mode, all other pipelines use manual start. */ if (vsp1->drm) ctrl |= VI6_DL_CTRL_CFM0 | VI6_DL_CTRL_NH0; @@ -260,46 +533,64 @@ void vsp1_dl_setup(struct vsp1_device *vsp1) vsp1_write(vsp1, VI6_DL_SWAP, VI6_DL_SWAP_LWS); } -/* ----------------------------------------------------------------------------- - * Initialization and Cleanup - */ +void vsp1_dlm_reset(struct vsp1_dl_manager *dlm) +{ + unsigned long flags; + + spin_lock_irqsave(&dlm->lock, flags); -struct vsp1_dl *vsp1_dl_create(struct vsp1_device *vsp1) + __vsp1_dl_list_put(dlm->active); + __vsp1_dl_list_put(dlm->queued); + __vsp1_dl_list_put(dlm->pending); + + spin_unlock_irqrestore(&dlm->lock, flags); + + dlm->active = NULL; + dlm->queued = NULL; + dlm->pending = NULL; +} + +struct vsp1_dl_manager *vsp1_dlm_create(struct vsp1_device *vsp1, + unsigned int index, + unsigned int prealloc) { - struct vsp1_dl *dl; + struct vsp1_dl_manager *dlm; unsigned int i; - dl = kzalloc(sizeof(*dl), GFP_KERNEL); - if (!dl) + dlm = devm_kzalloc(vsp1->dev, sizeof(*dlm), GFP_KERNEL); + if (!dlm) return NULL; - spin_lock_init(&dl->lock); + dlm->index = index; + dlm->mode = index == 0 && !vsp1->info->uapi + ? VSP1_DL_MODE_HEADERLESS : VSP1_DL_MODE_HEADER; + dlm->vsp1 = vsp1; - dl->vsp1 = vsp1; - dl->size = VSP1_DL_BODY_SIZE * ARRAY_SIZE(dl->lists.all); + spin_lock_init(&dlm->lock); + INIT_LIST_HEAD(&dlm->free); - dl->mem = dma_alloc_wc(vsp1->dev, dl->size, &dl->dma, - GFP_KERNEL); - if (!dl->mem) { - kfree(dl); - return NULL; - } + for (i = 0; i < prealloc; ++i) { + struct vsp1_dl_list *dl; - for (i = 0; i < ARRAY_SIZE(dl->lists.all); ++i) { - struct vsp1_dl_list *list = &dl->lists.all[i]; + dl = vsp1_dl_list_alloc(dlm); + if (!dl) + return NULL; - list->size = VSP1_DL_BODY_SIZE; - list->reg_count = 0; - list->in_use = false; - list->dma = dl->dma + VSP1_DL_BODY_SIZE * i; - list->body = dl->mem + VSP1_DL_BODY_SIZE * i; + list_add_tail(&dl->list, &dlm->free); } - return dl; + return dlm; } -void vsp1_dl_destroy(struct vsp1_dl *dl) +void vsp1_dlm_destroy(struct vsp1_dl_manager *dlm) { - dma_free_wc(dl->vsp1->dev, dl->size, dl->mem, dl->dma); - kfree(dl); + struct vsp1_dl_list *dl, *next; + + if (!dlm) + return; + + list_for_each_entry_safe(dl, next, &dlm->free, list) { + list_del(&dl->list); + vsp1_dl_list_free(dl); + } } diff --git a/drivers/media/platform/vsp1/vsp1_dl.h b/drivers/media/platform/vsp1/vsp1_dl.h index 448c4250e..de387cd4d 100644 --- a/drivers/media/platform/vsp1/vsp1_dl.h +++ b/drivers/media/platform/vsp1/vsp1_dl.h @@ -13,30 +13,33 @@ #ifndef __VSP1_DL_H__ #define __VSP1_DL_H__ -#include "vsp1_entity.h" +#include <linux/types.h> struct vsp1_device; -struct vsp1_dl; - -struct vsp1_dl *vsp1_dl_create(struct vsp1_device *vsp1); -void vsp1_dl_destroy(struct vsp1_dl *dl); - -void vsp1_dl_setup(struct vsp1_device *vsp1); - -void vsp1_dl_reset(struct vsp1_dl *dl); -void vsp1_dl_begin(struct vsp1_dl *dl); -void vsp1_dl_add(struct vsp1_entity *e, u32 reg, u32 data); -void vsp1_dl_commit(struct vsp1_dl *dl); - -void vsp1_dl_irq_display_start(struct vsp1_dl *dl); -void vsp1_dl_irq_frame_end(struct vsp1_dl *dl); - -static inline void vsp1_dl_mod_write(struct vsp1_entity *e, u32 reg, u32 data) -{ - if (e->vsp1->use_dl) - vsp1_dl_add(e, reg, data); - else - vsp1_write(e->vsp1, reg, data); -} +struct vsp1_dl_fragment; +struct vsp1_dl_list; +struct vsp1_dl_manager; + +void vsp1_dlm_setup(struct vsp1_device *vsp1); + +struct vsp1_dl_manager *vsp1_dlm_create(struct vsp1_device *vsp1, + unsigned int index, + unsigned int prealloc); +void vsp1_dlm_destroy(struct vsp1_dl_manager *dlm); +void vsp1_dlm_reset(struct vsp1_dl_manager *dlm); +void vsp1_dlm_irq_display_start(struct vsp1_dl_manager *dlm); +void vsp1_dlm_irq_frame_end(struct vsp1_dl_manager *dlm); + +struct vsp1_dl_list *vsp1_dl_list_get(struct vsp1_dl_manager *dlm); +void vsp1_dl_list_put(struct vsp1_dl_list *dl); +void vsp1_dl_list_write(struct vsp1_dl_list *dl, u32 reg, u32 data); +void vsp1_dl_list_commit(struct vsp1_dl_list *dl); + +struct vsp1_dl_body *vsp1_dl_fragment_alloc(struct vsp1_device *vsp1, + unsigned int num_entries); +void vsp1_dl_fragment_free(struct vsp1_dl_body *dlb); +void vsp1_dl_fragment_write(struct vsp1_dl_body *dlb, u32 reg, u32 data); +int vsp1_dl_list_add_fragment(struct vsp1_dl_list *dl, + struct vsp1_dl_body *dlb); #endif /* __VSP1_DL_H__ */ diff --git a/drivers/media/platform/vsp1/vsp1_drm.c b/drivers/media/platform/vsp1/vsp1_drm.c index 021fe5778..fc4bbc401 100644 --- a/drivers/media/platform/vsp1/vsp1_drm.c +++ b/drivers/media/platform/vsp1/vsp1_drm.c @@ -13,10 +13,10 @@ #include <linux/device.h> #include <linux/slab.h> -#include <linux/vsp1.h> #include <media/media-entity.h> #include <media/v4l2-subdev.h> +#include <media/vsp1.h> #include "vsp1.h" #include "vsp1_bru.h" @@ -26,18 +26,14 @@ #include "vsp1_pipe.h" #include "vsp1_rwpf.h" + /* ----------------------------------------------------------------------------- - * Runtime Handling + * Interrupt Handling */ -static void vsp1_drm_pipeline_frame_end(struct vsp1_pipeline *pipe) +void vsp1_drm_display_start(struct vsp1_device *vsp1) { - unsigned long flags; - - spin_lock_irqsave(&pipe->irqlock, flags); - if (pipe->num_inputs) - vsp1_pipeline_run(pipe); - spin_unlock_irqrestore(&pipe->irqlock, flags); + vsp1_dlm_irq_display_start(vsp1->drm->pipe.output->dlm); } /* ----------------------------------------------------------------------------- @@ -97,12 +93,14 @@ int vsp1_du_setup_lif(struct device *dev, unsigned int width, media_entity_pipeline_stop(&pipe->output->entity.subdev.entity); for (i = 0; i < bru->entity.source_pad; ++i) { + vsp1->drm->inputs[i].enabled = false; bru->inputs[i].rpf = NULL; pipe->inputs[i] = NULL; } pipe->num_inputs = 0; + vsp1_dlm_reset(pipe->output->dlm); vsp1_device_put(vsp1); dev_dbg(vsp1->dev, "%s: pipeline disabled\n", __func__); @@ -110,8 +108,6 @@ int vsp1_du_setup_lif(struct device *dev, unsigned int width, return 0; } - vsp1_dl_reset(vsp1->drm->dl); - /* Configure the format at the BRU sinks and propagate it through the * pipeline. */ @@ -222,16 +218,11 @@ void vsp1_du_atomic_begin(struct device *dev) { struct vsp1_device *vsp1 = dev_get_drvdata(dev); struct vsp1_pipeline *pipe = &vsp1->drm->pipe; - unsigned long flags; - - spin_lock_irqsave(&pipe->irqlock, flags); vsp1->drm->num_inputs = pipe->num_inputs; - spin_unlock_irqrestore(&pipe->irqlock, flags); - /* Prepare the display list. */ - vsp1_dl_begin(vsp1->drm->dl); + pipe->dl = vsp1_dl_list_get(pipe->output->dlm); } EXPORT_SYMBOL_GPL(vsp1_du_atomic_begin); @@ -244,10 +235,13 @@ EXPORT_SYMBOL_GPL(vsp1_du_atomic_begin); * @mem: DMA addresses of the memory buffers (one per plane) * @src: the source crop rectangle for the RPF * @dst: the destination compose rectangle for the BRU input + * @alpha: global alpha value for the input + * @zpos: the Z-order position of the input * * Configure the VSP to perform composition of the image referenced by @mem * through RPF @rpf_index, using the @src crop rectangle and the @dst - * composition rectangle. The Z-order is fixed with RPF 0 at the bottom. + * composition rectangle. The Z-order is configurable with higher @zpos values + * displayed on top. * * Image format as stored in memory is expressed as a V4L2 @pixelformat value. * As a special case, setting the pixel format to 0 will disable the RPF. The @@ -265,25 +259,17 @@ EXPORT_SYMBOL_GPL(vsp1_du_atomic_begin); * * This function isn't reentrant, the caller needs to serialize calls. * - * TODO: Implement Z-order control by decoupling the RPF index from the BRU - * input index. - * * Return 0 on success or a negative error code on failure. */ -int vsp1_du_atomic_update(struct device *dev, unsigned int rpf_index, - u32 pixelformat, unsigned int pitch, - dma_addr_t mem[2], const struct v4l2_rect *src, - const struct v4l2_rect *dst) +int vsp1_du_atomic_update_ext(struct device *dev, unsigned int rpf_index, + u32 pixelformat, unsigned int pitch, + dma_addr_t mem[2], const struct v4l2_rect *src, + const struct v4l2_rect *dst, unsigned int alpha, + unsigned int zpos) { struct vsp1_device *vsp1 = dev_get_drvdata(dev); - struct vsp1_pipeline *pipe = &vsp1->drm->pipe; const struct vsp1_format_info *fmtinfo; - struct v4l2_subdev_selection sel; - struct v4l2_subdev_format format; - struct vsp1_rwpf_memory memory; struct vsp1_rwpf *rpf; - unsigned long flags; - int ret; if (rpf_index >= vsp1->info->rpf_count) return -EINVAL; @@ -294,31 +280,20 @@ int vsp1_du_atomic_update(struct device *dev, unsigned int rpf_index, dev_dbg(vsp1->dev, "%s: RPF%u: disable requested\n", __func__, rpf_index); - spin_lock_irqsave(&pipe->irqlock, flags); - - if (pipe->inputs[rpf_index]) { - /* Remove the RPF from the pipeline if it was previously - * enabled. - */ - vsp1->bru->inputs[rpf_index].rpf = NULL; - pipe->inputs[rpf_index] = NULL; - - pipe->num_inputs--; - } - - spin_unlock_irqrestore(&pipe->irqlock, flags); - + vsp1->drm->inputs[rpf_index].enabled = false; return 0; } dev_dbg(vsp1->dev, - "%s: RPF%u: (%u,%u)/%ux%u -> (%u,%u)/%ux%u (%08x), pitch %u dma { %pad, %pad }\n", + "%s: RPF%u: (%u,%u)/%ux%u -> (%u,%u)/%ux%u (%08x), pitch %u dma { %pad, %pad } zpos %u\n", __func__, rpf_index, src->left, src->top, src->width, src->height, dst->left, dst->top, dst->width, dst->height, - pixelformat, pitch, &mem[0], &mem[1]); + pixelformat, pitch, &mem[0], &mem[1], zpos); - /* Set the stride at the RPF input. */ + /* Store the format, stride, memory buffer address, crop and compose + * rectangles and Z-order position and for the input. + */ fmtinfo = vsp1_get_format_info(pixelformat); if (!fmtinfo) { dev_dbg(vsp1->dev, "Unsupport pixel format %08x for RPF\n", @@ -330,16 +305,40 @@ int vsp1_du_atomic_update(struct device *dev, unsigned int rpf_index, rpf->format.num_planes = fmtinfo->planes; rpf->format.plane_fmt[0].bytesperline = pitch; rpf->format.plane_fmt[1].bytesperline = pitch; + rpf->alpha = alpha; + + rpf->mem.addr[0] = mem[0]; + rpf->mem.addr[1] = mem[1]; + rpf->mem.addr[2] = 0; + + vsp1->drm->inputs[rpf_index].crop = *src; + vsp1->drm->inputs[rpf_index].compose = *dst; + vsp1->drm->inputs[rpf_index].zpos = zpos; + vsp1->drm->inputs[rpf_index].enabled = true; + + return 0; +} +EXPORT_SYMBOL_GPL(vsp1_du_atomic_update_ext); + +static int vsp1_du_setup_rpf_pipe(struct vsp1_device *vsp1, + struct vsp1_rwpf *rpf, unsigned int bru_input) +{ + struct v4l2_subdev_selection sel; + struct v4l2_subdev_format format; + const struct v4l2_rect *crop; + int ret; /* Configure the format on the RPF sink pad and propagate it up to the * BRU sink pad. */ + crop = &vsp1->drm->inputs[rpf->entity.index].crop; + memset(&format, 0, sizeof(format)); format.which = V4L2_SUBDEV_FORMAT_ACTIVE; format.pad = RWPF_PAD_SINK; - format.format.width = src->width + src->left; - format.format.height = src->height + src->top; - format.format.code = fmtinfo->mbus; + format.format.width = crop->width + crop->left; + format.format.height = crop->height + crop->top; + format.format.code = rpf->fmtinfo->mbus; format.format.field = V4L2_FIELD_NONE; ret = v4l2_subdev_call(&rpf->entity.subdev, pad, set_fmt, NULL, @@ -356,7 +355,7 @@ int vsp1_du_atomic_update(struct device *dev, unsigned int rpf_index, sel.which = V4L2_SUBDEV_FORMAT_ACTIVE; sel.pad = RWPF_PAD_SINK; sel.target = V4L2_SEL_TGT_CROP; - sel.r = *src; + sel.r = *crop; ret = v4l2_subdev_call(&rpf->entity.subdev, pad, set_selection, NULL, &sel); @@ -391,7 +390,7 @@ int vsp1_du_atomic_update(struct device *dev, unsigned int rpf_index, return ret; /* BRU sink, propagate the format from the RPF source. */ - format.pad = rpf->entity.index; + format.pad = bru_input; ret = v4l2_subdev_call(&vsp1->bru->entity.subdev, pad, set_fmt, NULL, &format); @@ -402,9 +401,9 @@ int vsp1_du_atomic_update(struct device *dev, unsigned int rpf_index, __func__, format.format.width, format.format.height, format.format.code, format.pad); - sel.pad = rpf->entity.index; + sel.pad = bru_input; sel.target = V4L2_SEL_TGT_COMPOSE; - sel.r = *dst; + sel.r = vsp1->drm->inputs[rpf->entity.index].compose; ret = v4l2_subdev_call(&vsp1->bru->entity.subdev, pad, set_selection, NULL, &sel); @@ -416,33 +415,13 @@ int vsp1_du_atomic_update(struct device *dev, unsigned int rpf_index, __func__, sel.r.left, sel.r.top, sel.r.width, sel.r.height, sel.pad); - /* Store the compose rectangle coordinates in the RPF. */ - rpf->location.left = dst->left; - rpf->location.top = dst->top; - - /* Set the memory buffer address. */ - memory.num_planes = fmtinfo->planes; - memory.addr[0] = mem[0]; - memory.addr[1] = mem[1]; - - rpf->ops->set_memory(rpf, &memory); - - spin_lock_irqsave(&pipe->irqlock, flags); - - /* If the RPF was previously stopped set the BRU input to the RPF and - * store the RPF in the pipeline inputs array. - */ - if (!pipe->inputs[rpf->entity.index]) { - vsp1->bru->inputs[rpf_index].rpf = rpf; - pipe->inputs[rpf->entity.index] = rpf; - pipe->num_inputs++; - } - - spin_unlock_irqrestore(&pipe->irqlock, flags); - return 0; } -EXPORT_SYMBOL_GPL(vsp1_du_atomic_update); + +static unsigned int rpf_zpos(struct vsp1_device *vsp1, struct vsp1_rwpf *rpf) +{ + return vsp1->drm->inputs[rpf->entity.index].zpos; +} /** * vsp1_du_atomic_flush - Commit an atomic update @@ -452,51 +431,96 @@ void vsp1_du_atomic_flush(struct device *dev) { struct vsp1_device *vsp1 = dev_get_drvdata(dev); struct vsp1_pipeline *pipe = &vsp1->drm->pipe; + struct vsp1_rwpf *inputs[VSP1_MAX_RPF] = { NULL, }; struct vsp1_entity *entity; unsigned long flags; - bool stop = false; + unsigned int i; int ret; + /* Count the number of enabled inputs and sort them by Z-order. */ + pipe->num_inputs = 0; + + for (i = 0; i < vsp1->info->rpf_count; ++i) { + struct vsp1_rwpf *rpf = vsp1->rpf[i]; + unsigned int j; + + if (!vsp1->drm->inputs[i].enabled) { + pipe->inputs[i] = NULL; + continue; + } + + pipe->inputs[i] = rpf; + + /* Insert the RPF in the sorted RPFs array. */ + for (j = pipe->num_inputs++; j > 0; --j) { + if (rpf_zpos(vsp1, inputs[j-1]) <= rpf_zpos(vsp1, rpf)) + break; + inputs[j] = inputs[j-1]; + } + + inputs[j] = rpf; + } + + /* Setup the RPF input pipeline for every enabled input. */ + for (i = 0; i < vsp1->info->num_bru_inputs; ++i) { + struct vsp1_rwpf *rpf = inputs[i]; + + if (!rpf) { + vsp1->bru->inputs[i].rpf = NULL; + continue; + } + + vsp1->bru->inputs[i].rpf = rpf; + rpf->bru_input = i; + rpf->entity.sink_pad = i; + + dev_dbg(vsp1->dev, "%s: connecting RPF.%u to BRU:%u\n", + __func__, rpf->entity.index, i); + + ret = vsp1_du_setup_rpf_pipe(vsp1, rpf, i); + if (ret < 0) + dev_err(vsp1->dev, + "%s: failed to setup RPF.%u\n", + __func__, rpf->entity.index); + } + + /* Configure all entities in the pipeline. */ list_for_each_entry(entity, &pipe->entities, list_pipe) { /* Disconnect unused RPFs from the pipeline. */ if (entity->type == VSP1_ENTITY_RPF) { struct vsp1_rwpf *rpf = to_rwpf(&entity->subdev); if (!pipe->inputs[rpf->entity.index]) { - vsp1_mod_write(entity, entity->route->reg, - VI6_DPR_NODE_UNUSED); + vsp1_dl_list_write(pipe->dl, entity->route->reg, + VI6_DPR_NODE_UNUSED); continue; } } - vsp1_entity_route_setup(entity); + vsp1_entity_route_setup(entity, pipe->dl); - ret = v4l2_subdev_call(&entity->subdev, video, - s_stream, 1); - if (ret < 0) { - dev_err(vsp1->dev, - "DRM pipeline start failure on entity %s\n", - entity->subdev.name); - return; - } - } + if (entity->ops->configure) + entity->ops->configure(entity, pipe, pipe->dl); - vsp1_dl_commit(vsp1->drm->dl); + /* The memory buffer address must be applied after configuring + * the RPF to make sure the crop offset are computed. + */ + if (entity->type == VSP1_ENTITY_RPF) + vsp1_rwpf_set_memory(to_rwpf(&entity->subdev), + pipe->dl); + } - spin_lock_irqsave(&pipe->irqlock, flags); + vsp1_dl_list_commit(pipe->dl); + pipe->dl = NULL; /* Start or stop the pipeline if needed. */ if (!vsp1->drm->num_inputs && pipe->num_inputs) { vsp1_write(vsp1, VI6_DISP_IRQ_STA, 0); vsp1_write(vsp1, VI6_DISP_IRQ_ENB, VI6_DISP_IRQ_ENB_DSTE); + spin_lock_irqsave(&pipe->irqlock, flags); vsp1_pipeline_run(pipe); + spin_unlock_irqrestore(&pipe->irqlock, flags); } else if (vsp1->drm->num_inputs && !pipe->num_inputs) { - stop = true; - } - - spin_unlock_irqrestore(&pipe->irqlock, flags); - - if (stop) { vsp1_write(vsp1, VI6_DISP_IRQ_ENB, 0); vsp1_pipeline_stop(pipe); } @@ -562,14 +586,9 @@ int vsp1_drm_init(struct vsp1_device *vsp1) if (!vsp1->drm) return -ENOMEM; - vsp1->drm->dl = vsp1_dl_create(vsp1); - if (!vsp1->drm->dl) - return -ENOMEM; - pipe = &vsp1->drm->pipe; vsp1_pipeline_init(pipe); - pipe->frame_end = vsp1_drm_pipeline_frame_end; /* The DRM pipeline is static, add entities manually. */ for (i = 0; i < vsp1->info->rpf_count; ++i) { @@ -586,12 +605,9 @@ int vsp1_drm_init(struct vsp1_device *vsp1) pipe->lif = &vsp1->lif->entity; pipe->output = vsp1->wpf[0]; - pipe->dl = vsp1->drm->dl; - return 0; } void vsp1_drm_cleanup(struct vsp1_device *vsp1) { - vsp1_dl_destroy(vsp1->drm->dl); } diff --git a/drivers/media/platform/vsp1/vsp1_drm.h b/drivers/media/platform/vsp1/vsp1_drm.h index f68056838..9e28ab925 100644 --- a/drivers/media/platform/vsp1/vsp1_drm.h +++ b/drivers/media/platform/vsp1/vsp1_drm.h @@ -13,37 +13,32 @@ #ifndef __VSP1_DRM_H__ #define __VSP1_DRM_H__ -#include "vsp1_pipe.h" +#include <linux/videodev2.h> -struct vsp1_dl; +#include "vsp1_pipe.h" /** * vsp1_drm - State for the API exposed to the DRM driver - * @dl: display list for DRM pipeline operation * @pipe: the VSP1 pipeline used for display * @num_inputs: number of active pipeline inputs at the beginning of an update - * @update: the pipeline configuration has been updated + * @planes: source crop rectangle, destination compose rectangle and z-order + * position for every input */ struct vsp1_drm { - struct vsp1_dl *dl; struct vsp1_pipeline pipe; unsigned int num_inputs; - bool update; + struct { + bool enabled; + struct v4l2_rect crop; + struct v4l2_rect compose; + unsigned int zpos; + } inputs[VSP1_MAX_RPF]; }; int vsp1_drm_init(struct vsp1_device *vsp1); void vsp1_drm_cleanup(struct vsp1_device *vsp1); int vsp1_drm_create_links(struct vsp1_device *vsp1); -int vsp1_du_init(struct device *dev); -int vsp1_du_setup_lif(struct device *dev, unsigned int width, - unsigned int height); -void vsp1_du_atomic_begin(struct device *dev); -int vsp1_du_atomic_update(struct device *dev, unsigned int rpf_index, - u32 pixelformat, unsigned int pitch, - dma_addr_t mem[2], const struct v4l2_rect *src, - const struct v4l2_rect *dst); -void vsp1_du_atomic_flush(struct device *dev); - +void vsp1_drm_display_start(struct vsp1_device *vsp1); #endif /* __VSP1_DRM_H__ */ diff --git a/drivers/media/platform/vsp1/vsp1_drv.c b/drivers/media/platform/vsp1/vsp1_drv.c index 25750a0e4..e2d779fac 100644 --- a/drivers/media/platform/vsp1/vsp1_drv.c +++ b/drivers/media/platform/vsp1/vsp1_drv.c @@ -30,6 +30,7 @@ #include "vsp1_hsit.h" #include "vsp1_lif.h" #include "vsp1_lut.h" +#include "vsp1_pipe.h" #include "vsp1_rwpf.h" #include "vsp1_sru.h" #include "vsp1_uds.h" @@ -49,17 +50,15 @@ static irqreturn_t vsp1_irq_handler(int irq, void *data) for (i = 0; i < vsp1->info->wpf_count; ++i) { struct vsp1_rwpf *wpf = vsp1->wpf[i]; - struct vsp1_pipeline *pipe; if (wpf == NULL) continue; - pipe = to_vsp1_pipeline(&wpf->entity.subdev.entity); status = vsp1_read(vsp1, VI6_WPF_IRQ_STA(i)); vsp1_write(vsp1, VI6_WPF_IRQ_STA(i), ~status & mask); if (status & VI6_WFP_IRQ_STA_FRE) { - vsp1_pipeline_frame_end(pipe); + vsp1_pipeline_frame_end(wpf->pipe); ret = IRQ_HANDLED; } } @@ -68,14 +67,7 @@ static irqreturn_t vsp1_irq_handler(int irq, void *data) vsp1_write(vsp1, VI6_DISP_IRQ_STA, ~status & VI6_DISP_IRQ_STA_DST); if (status & VI6_DISP_IRQ_STA_DST) { - struct vsp1_rwpf *wpf = vsp1->wpf[0]; - struct vsp1_pipeline *pipe; - - if (wpf) { - pipe = to_vsp1_pipeline(&wpf->entity.subdev.entity); - vsp1_pipeline_display_start(pipe); - } - + vsp1_drm_display_start(vsp1); ret = IRQ_HANDLED; } @@ -387,13 +379,10 @@ static int vsp1_create_entities(struct vsp1_device *vsp1) /* Register subdev nodes if the userspace API is enabled or initialize * the DRM pipeline otherwise. */ - if (vsp1->info->uapi) { - vsp1->use_dl = false; + if (vsp1->info->uapi) ret = v4l2_device_register_subdev_nodes(&vsp1->v4l2_dev); - } else { - vsp1->use_dl = true; + else ret = vsp1_drm_init(vsp1); - } if (ret < 0) goto done; @@ -465,8 +454,7 @@ static int vsp1_device_init(struct vsp1_device *vsp1) vsp1_write(vsp1, VI6_DPR_HGT_SMPPT, (7 << VI6_DPR_SMPPT_TGW_SHIFT) | (VI6_DPR_NODE_UNUSED << VI6_DPR_SMPPT_PT_SHIFT)); - if (vsp1->use_dl) - vsp1_dl_setup(vsp1); + vsp1_dlm_setup(vsp1); return 0; } @@ -570,6 +558,7 @@ static const struct dev_pm_ops vsp1_pm_ops = { static const struct vsp1_device_info vsp1_device_infos[] = { { .version = VI6_IP_VERSION_MODEL_VSPS_H2, + .gen = 2, .features = VSP1_HAS_BRU | VSP1_HAS_LUT | VSP1_HAS_SRU, .rpf_count = 5, .uds_count = 3, @@ -578,6 +567,7 @@ static const struct vsp1_device_info vsp1_device_infos[] = { .uapi = true, }, { .version = VI6_IP_VERSION_MODEL_VSPR_H2, + .gen = 2, .features = VSP1_HAS_BRU | VSP1_HAS_SRU, .rpf_count = 5, .uds_count = 1, @@ -586,6 +576,7 @@ static const struct vsp1_device_info vsp1_device_infos[] = { .uapi = true, }, { .version = VI6_IP_VERSION_MODEL_VSPD_GEN2, + .gen = 2, .features = VSP1_HAS_BRU | VSP1_HAS_LIF | VSP1_HAS_LUT, .rpf_count = 4, .uds_count = 1, @@ -594,6 +585,7 @@ static const struct vsp1_device_info vsp1_device_infos[] = { .uapi = true, }, { .version = VI6_IP_VERSION_MODEL_VSPS_M2, + .gen = 2, .features = VSP1_HAS_BRU | VSP1_HAS_LUT | VSP1_HAS_SRU, .rpf_count = 5, .uds_count = 3, @@ -602,6 +594,7 @@ static const struct vsp1_device_info vsp1_device_infos[] = { .uapi = true, }, { .version = VI6_IP_VERSION_MODEL_VSPI_GEN3, + .gen = 3, .features = VSP1_HAS_LUT | VSP1_HAS_SRU, .rpf_count = 1, .uds_count = 1, @@ -609,6 +602,7 @@ static const struct vsp1_device_info vsp1_device_infos[] = { .uapi = true, }, { .version = VI6_IP_VERSION_MODEL_VSPBD_GEN3, + .gen = 3, .features = VSP1_HAS_BRU, .rpf_count = 5, .wpf_count = 1, @@ -616,6 +610,7 @@ static const struct vsp1_device_info vsp1_device_infos[] = { .uapi = true, }, { .version = VI6_IP_VERSION_MODEL_VSPBC_GEN3, + .gen = 3, .features = VSP1_HAS_BRU | VSP1_HAS_LUT, .rpf_count = 5, .wpf_count = 1, @@ -623,7 +618,8 @@ static const struct vsp1_device_info vsp1_device_infos[] = { .uapi = true, }, { .version = VI6_IP_VERSION_MODEL_VSPD_GEN3, - .features = VSP1_HAS_BRU | VSP1_HAS_LIF | VSP1_HAS_LUT, + .gen = 3, + .features = VSP1_HAS_BRU | VSP1_HAS_LIF, .rpf_count = 5, .wpf_count = 2, .num_bru_inputs = 5, diff --git a/drivers/media/platform/vsp1/vsp1_entity.c b/drivers/media/platform/vsp1/vsp1_entity.c index 20a78fbd3..3d070bcc6 100644 --- a/drivers/media/platform/vsp1/vsp1_entity.c +++ b/drivers/media/platform/vsp1/vsp1_entity.c @@ -19,46 +19,11 @@ #include <media/v4l2-subdev.h> #include "vsp1.h" +#include "vsp1_dl.h" #include "vsp1_entity.h" -bool vsp1_entity_is_streaming(struct vsp1_entity *entity) -{ - unsigned long flags; - bool streaming; - - spin_lock_irqsave(&entity->lock, flags); - streaming = entity->streaming; - spin_unlock_irqrestore(&entity->lock, flags); - - return streaming; -} - -int vsp1_entity_set_streaming(struct vsp1_entity *entity, bool streaming) -{ - unsigned long flags; - int ret; - - spin_lock_irqsave(&entity->lock, flags); - entity->streaming = streaming; - spin_unlock_irqrestore(&entity->lock, flags); - - if (!streaming) - return 0; - - if (!entity->vsp1->info->uapi || !entity->subdev.ctrl_handler) - return 0; - - ret = v4l2_ctrl_handler_setup(entity->subdev.ctrl_handler); - if (ret < 0) { - spin_lock_irqsave(&entity->lock, flags); - entity->streaming = false; - spin_unlock_irqrestore(&entity->lock, flags); - } - - return ret; -} - -void vsp1_entity_route_setup(struct vsp1_entity *source) +void vsp1_entity_route_setup(struct vsp1_entity *source, + struct vsp1_dl_list *dl) { struct vsp1_entity *sink; @@ -66,40 +31,74 @@ void vsp1_entity_route_setup(struct vsp1_entity *source) return; sink = container_of(source->sink, struct vsp1_entity, subdev.entity); - vsp1_mod_write(source, source->route->reg, - sink->route->inputs[source->sink_pad]); + vsp1_dl_list_write(dl, source->route->reg, + sink->route->inputs[source->sink_pad]); } /* ----------------------------------------------------------------------------- * V4L2 Subdevice Operations */ -struct v4l2_mbus_framefmt * -vsp1_entity_get_pad_format(struct vsp1_entity *entity, +/** + * vsp1_entity_get_pad_config - Get the pad configuration for an entity + * @entity: the entity + * @cfg: the TRY pad configuration + * @which: configuration selector (ACTIVE or TRY) + * + * Return the pad configuration requested by the which argument. The TRY + * configuration is passed explicitly to the function through the cfg argument + * and simply returned when requested. The ACTIVE configuration comes from the + * entity structure. + */ +struct v4l2_subdev_pad_config * +vsp1_entity_get_pad_config(struct vsp1_entity *entity, struct v4l2_subdev_pad_config *cfg, - unsigned int pad, u32 which) + enum v4l2_subdev_format_whence which) { switch (which) { - case V4L2_SUBDEV_FORMAT_TRY: - return v4l2_subdev_get_try_format(&entity->subdev, cfg, pad); case V4L2_SUBDEV_FORMAT_ACTIVE: - return &entity->formats[pad]; + return entity->config; + case V4L2_SUBDEV_FORMAT_TRY: default: - return NULL; + return cfg; } } +/** + * vsp1_entity_get_pad_format - Get a pad format from storage for an entity + * @entity: the entity + * @cfg: the configuration storage + * @pad: the pad number + * + * Return the format stored in the given configuration for an entity's pad. The + * configuration can be an ACTIVE or TRY configuration. + */ +struct v4l2_mbus_framefmt * +vsp1_entity_get_pad_format(struct vsp1_entity *entity, + struct v4l2_subdev_pad_config *cfg, + unsigned int pad) +{ + return v4l2_subdev_get_try_format(&entity->subdev, cfg, pad); +} + +struct v4l2_rect * +vsp1_entity_get_pad_compose(struct vsp1_entity *entity, + struct v4l2_subdev_pad_config *cfg, + unsigned int pad) +{ + return v4l2_subdev_get_try_compose(&entity->subdev, cfg, pad); +} + /* - * vsp1_entity_init_formats - Initialize formats on all pads + * vsp1_entity_init_cfg - Initialize formats on all pads * @subdev: V4L2 subdevice * @cfg: V4L2 subdev pad configuration * - * Initialize all pad formats with default values. If cfg is not NULL, try - * formats are initialized on the file handle. Otherwise active formats are - * initialized on the device. + * Initialize all pad formats with default values in the given pad config. This + * function can be used as a handler for the subdev pad::init_cfg operation. */ -void vsp1_entity_init_formats(struct v4l2_subdev *subdev, - struct v4l2_subdev_pad_config *cfg) +int vsp1_entity_init_cfg(struct v4l2_subdev *subdev, + struct v4l2_subdev_pad_config *cfg) { struct v4l2_subdev_format format; unsigned int pad; @@ -113,19 +112,132 @@ void vsp1_entity_init_formats(struct v4l2_subdev *subdev, v4l2_subdev_call(subdev, pad, set_fmt, cfg, &format); } + + return 0; } -static int vsp1_entity_open(struct v4l2_subdev *subdev, - struct v4l2_subdev_fh *fh) +/* + * vsp1_subdev_get_pad_format - Subdev pad get_fmt handler + * @subdev: V4L2 subdevice + * @cfg: V4L2 subdev pad configuration + * @fmt: V4L2 subdev format + * + * This function implements the subdev get_fmt pad operation. It can be used as + * a direct drop-in for the operation handler. + */ +int vsp1_subdev_get_pad_format(struct v4l2_subdev *subdev, + struct v4l2_subdev_pad_config *cfg, + struct v4l2_subdev_format *fmt) { - vsp1_entity_init_formats(subdev, fh->pad); + struct vsp1_entity *entity = to_vsp1_entity(subdev); + struct v4l2_subdev_pad_config *config; + + config = vsp1_entity_get_pad_config(entity, cfg, fmt->which); + if (!config) + return -EINVAL; + + fmt->format = *vsp1_entity_get_pad_format(entity, config, fmt->pad); return 0; } -const struct v4l2_subdev_internal_ops vsp1_subdev_internal_ops = { - .open = vsp1_entity_open, -}; +/* + * vsp1_subdev_enum_mbus_code - Subdev pad enum_mbus_code handler + * @subdev: V4L2 subdevice + * @cfg: V4L2 subdev pad configuration + * @code: Media bus code enumeration + * @codes: Array of supported media bus codes + * @ncodes: Number of supported media bus codes + * + * This function implements the subdev enum_mbus_code pad operation for entities + * that do not support format conversion. It enumerates the given supported + * media bus codes on the sink pad and reports a source pad format identical to + * the sink pad. + */ +int vsp1_subdev_enum_mbus_code(struct v4l2_subdev *subdev, + struct v4l2_subdev_pad_config *cfg, + struct v4l2_subdev_mbus_code_enum *code, + const unsigned int *codes, unsigned int ncodes) +{ + struct vsp1_entity *entity = to_vsp1_entity(subdev); + + if (code->pad == 0) { + if (code->index >= ncodes) + return -EINVAL; + + code->code = codes[code->index]; + } else { + struct v4l2_subdev_pad_config *config; + struct v4l2_mbus_framefmt *format; + + /* The entity can't perform format conversion, the sink format + * is always identical to the source format. + */ + if (code->index) + return -EINVAL; + + config = vsp1_entity_get_pad_config(entity, cfg, code->which); + if (!config) + return -EINVAL; + + format = vsp1_entity_get_pad_format(entity, config, 0); + code->code = format->code; + } + + return 0; +} + +/* + * vsp1_subdev_enum_frame_size - Subdev pad enum_frame_size handler + * @subdev: V4L2 subdevice + * @cfg: V4L2 subdev pad configuration + * @fse: Frame size enumeration + * @min_width: Minimum image width + * @min_height: Minimum image height + * @max_width: Maximum image width + * @max_height: Maximum image height + * + * This function implements the subdev enum_frame_size pad operation for + * entities that do not support scaling or cropping. It reports the given + * minimum and maximum frame width and height on the sink pad, and a fixed + * source pad size identical to the sink pad. + */ +int vsp1_subdev_enum_frame_size(struct v4l2_subdev *subdev, + struct v4l2_subdev_pad_config *cfg, + struct v4l2_subdev_frame_size_enum *fse, + unsigned int min_width, unsigned int min_height, + unsigned int max_width, unsigned int max_height) +{ + struct vsp1_entity *entity = to_vsp1_entity(subdev); + struct v4l2_subdev_pad_config *config; + struct v4l2_mbus_framefmt *format; + + config = vsp1_entity_get_pad_config(entity, cfg, fse->which); + if (!config) + return -EINVAL; + + format = vsp1_entity_get_pad_format(entity, config, fse->pad); + + if (fse->index || fse->code != format->code) + return -EINVAL; + + if (fse->pad == 0) { + fse->min_width = min_width; + fse->max_width = max_width; + fse->min_height = min_height; + fse->max_height = max_height; + } else { + /* The size on the source pad are fixed and always identical to + * the size on the sink pad. + */ + fse->min_width = format->width; + fse->max_width = format->width; + fse->min_height = format->height; + fse->max_height = format->height; + } + + return 0; +} /* ----------------------------------------------------------------------------- * Media Operations @@ -171,11 +283,11 @@ static const struct vsp1_route vsp1_routes[] = { { VSP1_ENTITY_HST, 0, VI6_DPR_HST_ROUTE, { VI6_DPR_NODE_HST, } }, { VSP1_ENTITY_LIF, 0, 0, { VI6_DPR_NODE_LIF, } }, { VSP1_ENTITY_LUT, 0, VI6_DPR_LUT_ROUTE, { VI6_DPR_NODE_LUT, } }, - { VSP1_ENTITY_RPF, 0, VI6_DPR_RPF_ROUTE(0), { VI6_DPR_NODE_RPF(0), } }, - { VSP1_ENTITY_RPF, 1, VI6_DPR_RPF_ROUTE(1), { VI6_DPR_NODE_RPF(1), } }, - { VSP1_ENTITY_RPF, 2, VI6_DPR_RPF_ROUTE(2), { VI6_DPR_NODE_RPF(2), } }, - { VSP1_ENTITY_RPF, 3, VI6_DPR_RPF_ROUTE(3), { VI6_DPR_NODE_RPF(3), } }, - { VSP1_ENTITY_RPF, 4, VI6_DPR_RPF_ROUTE(4), { VI6_DPR_NODE_RPF(4), } }, + { VSP1_ENTITY_RPF, 0, VI6_DPR_RPF_ROUTE(0), { 0, } }, + { VSP1_ENTITY_RPF, 1, VI6_DPR_RPF_ROUTE(1), { 0, } }, + { VSP1_ENTITY_RPF, 2, VI6_DPR_RPF_ROUTE(2), { 0, } }, + { VSP1_ENTITY_RPF, 3, VI6_DPR_RPF_ROUTE(3), { 0, } }, + { VSP1_ENTITY_RPF, 4, VI6_DPR_RPF_ROUTE(4), { 0, } }, { VSP1_ENTITY_SRU, 0, VI6_DPR_SRU_ROUTE, { VI6_DPR_NODE_SRU, } }, { VSP1_ENTITY_UDS, 0, VI6_DPR_UDS_ROUTE(0), { VI6_DPR_NODE_UDS(0), } }, { VSP1_ENTITY_UDS, 1, VI6_DPR_UDS_ROUTE(1), { VI6_DPR_NODE_UDS(1), } }, @@ -187,9 +299,12 @@ static const struct vsp1_route vsp1_routes[] = { }; int vsp1_entity_init(struct vsp1_device *vsp1, struct vsp1_entity *entity, - unsigned int num_pads) + const char *name, unsigned int num_pads, + const struct v4l2_subdev_ops *ops) { + struct v4l2_subdev *subdev; unsigned int i; + int ret; for (i = 0; i < ARRAY_SIZE(vsp1_routes); ++i) { if (vsp1_routes[i].type == entity->type && @@ -202,37 +317,56 @@ int vsp1_entity_init(struct vsp1_device *vsp1, struct vsp1_entity *entity, if (i == ARRAY_SIZE(vsp1_routes)) return -EINVAL; - spin_lock_init(&entity->lock); - entity->vsp1 = vsp1; entity->source_pad = num_pads - 1; - /* Allocate formats and pads. */ - entity->formats = devm_kzalloc(vsp1->dev, - num_pads * sizeof(*entity->formats), - GFP_KERNEL); - if (entity->formats == NULL) - return -ENOMEM; - + /* Allocate and initialize pads. */ entity->pads = devm_kzalloc(vsp1->dev, num_pads * sizeof(*entity->pads), GFP_KERNEL); if (entity->pads == NULL) return -ENOMEM; - /* Initialize pads. */ for (i = 0; i < num_pads - 1; ++i) entity->pads[i].flags = MEDIA_PAD_FL_SINK; entity->pads[num_pads - 1].flags = MEDIA_PAD_FL_SOURCE; /* Initialize the media entity. */ - return media_entity_pads_init(&entity->subdev.entity, num_pads, - entity->pads); + ret = media_entity_pads_init(&entity->subdev.entity, num_pads, + entity->pads); + if (ret < 0) + return ret; + + /* Initialize the V4L2 subdev. */ + subdev = &entity->subdev; + v4l2_subdev_init(subdev, ops); + + subdev->entity.ops = &vsp1->media_ops; + subdev->flags |= V4L2_SUBDEV_FL_HAS_DEVNODE; + + snprintf(subdev->name, sizeof(subdev->name), "%s %s", + dev_name(vsp1->dev), name); + + vsp1_entity_init_cfg(subdev, NULL); + + /* Allocate the pad configuration to store formats and selection + * rectangles. + */ + entity->config = v4l2_subdev_alloc_pad_config(&entity->subdev); + if (entity->config == NULL) { + media_entity_cleanup(&entity->subdev.entity); + return -ENOMEM; + } + + return 0; } void vsp1_entity_destroy(struct vsp1_entity *entity) { + if (entity->ops && entity->ops->destroy) + entity->ops->destroy(entity); if (entity->subdev.ctrl_handler) v4l2_ctrl_handler_free(entity->subdev.ctrl_handler); + v4l2_subdev_free_pad_config(entity->config); media_entity_cleanup(&entity->subdev.entity); } diff --git a/drivers/media/platform/vsp1/vsp1_entity.h b/drivers/media/platform/vsp1/vsp1_entity.h index 83570dfde..69eff4e17 100644 --- a/drivers/media/platform/vsp1/vsp1_entity.h +++ b/drivers/media/platform/vsp1/vsp1_entity.h @@ -19,6 +19,8 @@ #include <media/v4l2-subdev.h> struct vsp1_device; +struct vsp1_dl_list; +struct vsp1_pipeline; enum vsp1_entity_type { VSP1_ENTITY_BRU, @@ -53,9 +55,27 @@ struct vsp1_route { unsigned int inputs[VSP1_ENTITY_MAX_INPUTS]; }; +/** + * struct vsp1_entity_operations - Entity operations + * @destroy: Destroy the entity. + * @set_memory: Setup memory buffer access. This operation applies the settings + * stored in the rwpf mem field to the display list. Valid for RPF + * and WPF only. + * @configure: Setup the hardware based on the entity state (pipeline, formats, + * selection rectangles, ...) + */ +struct vsp1_entity_operations { + void (*destroy)(struct vsp1_entity *); + void (*set_memory)(struct vsp1_entity *, struct vsp1_dl_list *dl); + void (*configure)(struct vsp1_entity *, struct vsp1_pipeline *, + struct vsp1_dl_list *); +}; + struct vsp1_entity { struct vsp1_device *vsp1; + const struct vsp1_entity_operations *ops; + enum vsp1_entity_type type; unsigned int index; const struct vsp1_route *route; @@ -70,10 +90,7 @@ struct vsp1_entity { unsigned int sink_pad; struct v4l2_subdev subdev; - struct v4l2_mbus_framefmt *formats; - - spinlock_t lock; /* Protects the streaming field */ - bool streaming; + struct v4l2_subdev_pad_config *config; }; static inline struct vsp1_entity *to_vsp1_entity(struct v4l2_subdev *subdev) @@ -82,7 +99,8 @@ static inline struct vsp1_entity *to_vsp1_entity(struct v4l2_subdev *subdev) } int vsp1_entity_init(struct vsp1_device *vsp1, struct vsp1_entity *entity, - unsigned int num_pads); + const char *name, unsigned int num_pads, + const struct v4l2_subdev_ops *ops); void vsp1_entity_destroy(struct vsp1_entity *entity); extern const struct v4l2_subdev_internal_ops vsp1_subdev_internal_ops; @@ -91,16 +109,35 @@ int vsp1_entity_link_setup(struct media_entity *entity, const struct media_pad *local, const struct media_pad *remote, u32 flags); +struct v4l2_subdev_pad_config * +vsp1_entity_get_pad_config(struct vsp1_entity *entity, + struct v4l2_subdev_pad_config *cfg, + enum v4l2_subdev_format_whence which); struct v4l2_mbus_framefmt * vsp1_entity_get_pad_format(struct vsp1_entity *entity, struct v4l2_subdev_pad_config *cfg, - unsigned int pad, u32 which); -void vsp1_entity_init_formats(struct v4l2_subdev *subdev, - struct v4l2_subdev_pad_config *cfg); - -bool vsp1_entity_is_streaming(struct vsp1_entity *entity); -int vsp1_entity_set_streaming(struct vsp1_entity *entity, bool streaming); - -void vsp1_entity_route_setup(struct vsp1_entity *source); + unsigned int pad); +struct v4l2_rect * +vsp1_entity_get_pad_compose(struct vsp1_entity *entity, + struct v4l2_subdev_pad_config *cfg, + unsigned int pad); +int vsp1_entity_init_cfg(struct v4l2_subdev *subdev, + struct v4l2_subdev_pad_config *cfg); + +void vsp1_entity_route_setup(struct vsp1_entity *source, + struct vsp1_dl_list *dl); + +int vsp1_subdev_get_pad_format(struct v4l2_subdev *subdev, + struct v4l2_subdev_pad_config *cfg, + struct v4l2_subdev_format *fmt); +int vsp1_subdev_enum_mbus_code(struct v4l2_subdev *subdev, + struct v4l2_subdev_pad_config *cfg, + struct v4l2_subdev_mbus_code_enum *code, + const unsigned int *codes, unsigned int ncodes); +int vsp1_subdev_enum_frame_size(struct v4l2_subdev *subdev, + struct v4l2_subdev_pad_config *cfg, + struct v4l2_subdev_frame_size_enum *fse, + unsigned int min_w, unsigned int min_h, + unsigned int max_w, unsigned int max_h); #endif /* __VSP1_ENTITY_H__ */ diff --git a/drivers/media/platform/vsp1/vsp1_hsit.c b/drivers/media/platform/vsp1/vsp1_hsit.c index c1087cff3..68b8567b3 100644 --- a/drivers/media/platform/vsp1/vsp1_hsit.c +++ b/drivers/media/platform/vsp1/vsp1_hsit.c @@ -17,6 +17,7 @@ #include <media/v4l2-subdev.h> #include "vsp1.h" +#include "vsp1_dl.h" #include "vsp1_hsit.h" #define HSIT_MIN_SIZE 4U @@ -26,32 +27,14 @@ * Device Access */ -static inline void vsp1_hsit_write(struct vsp1_hsit *hsit, u32 reg, u32 data) +static inline void vsp1_hsit_write(struct vsp1_hsit *hsit, + struct vsp1_dl_list *dl, u32 reg, u32 data) { - vsp1_write(hsit->entity.vsp1, reg, data); + vsp1_dl_list_write(dl, reg, data); } /* ----------------------------------------------------------------------------- - * V4L2 Subdevice Core Operations - */ - -static int hsit_s_stream(struct v4l2_subdev *subdev, int enable) -{ - struct vsp1_hsit *hsit = to_hsit(subdev); - - if (!enable) - return 0; - - if (hsit->inverse) - vsp1_hsit_write(hsit, VI6_HSI_CTRL, VI6_HSI_CTRL_EN); - else - vsp1_hsit_write(hsit, VI6_HST_CTRL, VI6_HST_CTRL_EN); - - return 0; -} - -/* ----------------------------------------------------------------------------- - * V4L2 Subdevice Pad Operations + * V4L2 Subdevice Operations */ static int hsit_enum_mbus_code(struct v4l2_subdev *subdev, @@ -76,43 +59,9 @@ static int hsit_enum_frame_size(struct v4l2_subdev *subdev, struct v4l2_subdev_pad_config *cfg, struct v4l2_subdev_frame_size_enum *fse) { - struct vsp1_hsit *hsit = to_hsit(subdev); - struct v4l2_mbus_framefmt *format; - - format = vsp1_entity_get_pad_format(&hsit->entity, cfg, fse->pad, - fse->which); - - if (fse->index || fse->code != format->code) - return -EINVAL; - - if (fse->pad == HSIT_PAD_SINK) { - fse->min_width = HSIT_MIN_SIZE; - fse->max_width = HSIT_MAX_SIZE; - fse->min_height = HSIT_MIN_SIZE; - fse->max_height = HSIT_MAX_SIZE; - } else { - /* The size on the source pad are fixed and always identical to - * the size on the sink pad. - */ - fse->min_width = format->width; - fse->max_width = format->width; - fse->min_height = format->height; - fse->max_height = format->height; - } - - return 0; -} - -static int hsit_get_format(struct v4l2_subdev *subdev, - struct v4l2_subdev_pad_config *cfg, - struct v4l2_subdev_format *fmt) -{ - struct vsp1_hsit *hsit = to_hsit(subdev); - - fmt->format = *vsp1_entity_get_pad_format(&hsit->entity, cfg, fmt->pad, - fmt->which); - - return 0; + return vsp1_subdev_enum_frame_size(subdev, cfg, fse, HSIT_MIN_SIZE, + HSIT_MIN_SIZE, HSIT_MAX_SIZE, + HSIT_MAX_SIZE); } static int hsit_set_format(struct v4l2_subdev *subdev, @@ -120,10 +69,14 @@ static int hsit_set_format(struct v4l2_subdev *subdev, struct v4l2_subdev_format *fmt) { struct vsp1_hsit *hsit = to_hsit(subdev); + struct v4l2_subdev_pad_config *config; struct v4l2_mbus_framefmt *format; - format = vsp1_entity_get_pad_format(&hsit->entity, cfg, fmt->pad, - fmt->which); + config = vsp1_entity_get_pad_config(&hsit->entity, cfg, fmt->which); + if (!config) + return -EINVAL; + + format = vsp1_entity_get_pad_format(&hsit->entity, config, fmt->pad); if (fmt->pad == HSIT_PAD_SOURCE) { /* The HST and HSI output format code and resolution can't be @@ -145,8 +98,8 @@ static int hsit_set_format(struct v4l2_subdev *subdev, fmt->format = *format; /* Propagate the format to the source pad. */ - format = vsp1_entity_get_pad_format(&hsit->entity, cfg, HSIT_PAD_SOURCE, - fmt->which); + format = vsp1_entity_get_pad_format(&hsit->entity, config, + HSIT_PAD_SOURCE); *format = fmt->format; format->code = hsit->inverse ? MEDIA_BUS_FMT_ARGB8888_1X32 : MEDIA_BUS_FMT_AHSV8888_1X32; @@ -154,33 +107,44 @@ static int hsit_set_format(struct v4l2_subdev *subdev, return 0; } -/* ----------------------------------------------------------------------------- - * V4L2 Subdevice Operations - */ - -static struct v4l2_subdev_video_ops hsit_video_ops = { - .s_stream = hsit_s_stream, -}; - static struct v4l2_subdev_pad_ops hsit_pad_ops = { + .init_cfg = vsp1_entity_init_cfg, .enum_mbus_code = hsit_enum_mbus_code, .enum_frame_size = hsit_enum_frame_size, - .get_fmt = hsit_get_format, + .get_fmt = vsp1_subdev_get_pad_format, .set_fmt = hsit_set_format, }; static struct v4l2_subdev_ops hsit_ops = { - .video = &hsit_video_ops, .pad = &hsit_pad_ops, }; /* ----------------------------------------------------------------------------- + * VSP1 Entity Operations + */ + +static void hsit_configure(struct vsp1_entity *entity, + struct vsp1_pipeline *pipe, + struct vsp1_dl_list *dl) +{ + struct vsp1_hsit *hsit = to_hsit(&entity->subdev); + + if (hsit->inverse) + vsp1_hsit_write(hsit, dl, VI6_HSI_CTRL, VI6_HSI_CTRL_EN); + else + vsp1_hsit_write(hsit, dl, VI6_HST_CTRL, VI6_HST_CTRL_EN); +} + +static const struct vsp1_entity_operations hsit_entity_ops = { + .configure = hsit_configure, +}; + +/* ----------------------------------------------------------------------------- * Initialization and Cleanup */ struct vsp1_hsit *vsp1_hsit_create(struct vsp1_device *vsp1, bool inverse) { - struct v4l2_subdev *subdev; struct vsp1_hsit *hsit; int ret; @@ -190,27 +154,17 @@ struct vsp1_hsit *vsp1_hsit_create(struct vsp1_device *vsp1, bool inverse) hsit->inverse = inverse; + hsit->entity.ops = &hsit_entity_ops; + if (inverse) hsit->entity.type = VSP1_ENTITY_HSI; else hsit->entity.type = VSP1_ENTITY_HST; - ret = vsp1_entity_init(vsp1, &hsit->entity, 2); + ret = vsp1_entity_init(vsp1, &hsit->entity, inverse ? "hsi" : "hst", 2, + &hsit_ops); if (ret < 0) return ERR_PTR(ret); - /* Initialize the V4L2 subdev. */ - subdev = &hsit->entity.subdev; - v4l2_subdev_init(subdev, &hsit_ops); - - subdev->entity.ops = &vsp1->media_ops; - subdev->internal_ops = &vsp1_subdev_internal_ops; - snprintf(subdev->name, sizeof(subdev->name), "%s %s", - dev_name(vsp1->dev), inverse ? "hsi" : "hst"); - v4l2_set_subdevdata(subdev, hsit); - subdev->flags |= V4L2_SUBDEV_FL_HAS_DEVNODE; - - vsp1_entity_init_formats(subdev, NULL); - return hsit; } diff --git a/drivers/media/platform/vsp1/vsp1_lif.c b/drivers/media/platform/vsp1/vsp1_lif.c index 433853ce8..0217393f2 100644 --- a/drivers/media/platform/vsp1/vsp1_lif.c +++ b/drivers/media/platform/vsp1/vsp1_lif.c @@ -17,55 +17,24 @@ #include <media/v4l2-subdev.h> #include "vsp1.h" +#include "vsp1_dl.h" #include "vsp1_lif.h" #define LIF_MIN_SIZE 2U -#define LIF_MAX_SIZE 2048U +#define LIF_MAX_SIZE 8190U /* ----------------------------------------------------------------------------- * Device Access */ -static inline void vsp1_lif_write(struct vsp1_lif *lif, u32 reg, u32 data) +static inline void vsp1_lif_write(struct vsp1_lif *lif, struct vsp1_dl_list *dl, + u32 reg, u32 data) { - vsp1_mod_write(&lif->entity, reg, data); + vsp1_dl_list_write(dl, reg, data); } /* ----------------------------------------------------------------------------- - * V4L2 Subdevice Core Operations - */ - -static int lif_s_stream(struct v4l2_subdev *subdev, int enable) -{ - const struct v4l2_mbus_framefmt *format; - struct vsp1_lif *lif = to_lif(subdev); - unsigned int hbth = 1300; - unsigned int obth = 400; - unsigned int lbth = 200; - - if (!enable) { - vsp1_write(lif->entity.vsp1, VI6_LIF_CTRL, 0); - return 0; - } - - format = &lif->entity.formats[LIF_PAD_SOURCE]; - - obth = min(obth, (format->width + 1) / 2 * format->height - 4); - - vsp1_lif_write(lif, VI6_LIF_CSBTH, - (hbth << VI6_LIF_CSBTH_HBTH_SHIFT) | - (lbth << VI6_LIF_CSBTH_LBTH_SHIFT)); - - vsp1_lif_write(lif, VI6_LIF_CTRL, - (obth << VI6_LIF_CTRL_OBTH_SHIFT) | - (format->code == 0 ? VI6_LIF_CTRL_CFMT : 0) | - VI6_LIF_CTRL_REQSEL | VI6_LIF_CTRL_LIF_EN); - - return 0; -} - -/* ----------------------------------------------------------------------------- - * V4L2 Subdevice Pad Operations + * V4L2 Subdevice Operations */ static int lif_enum_mbus_code(struct v4l2_subdev *subdev, @@ -76,82 +45,38 @@ static int lif_enum_mbus_code(struct v4l2_subdev *subdev, MEDIA_BUS_FMT_ARGB8888_1X32, MEDIA_BUS_FMT_AYUV8_1X32, }; - struct vsp1_lif *lif = to_lif(subdev); - if (code->pad == LIF_PAD_SINK) { - if (code->index >= ARRAY_SIZE(codes)) - return -EINVAL; - - code->code = codes[code->index]; - } else { - struct v4l2_mbus_framefmt *format; - - /* The LIF can't perform format conversion, the sink format is - * always identical to the source format. - */ - if (code->index) - return -EINVAL; - - format = vsp1_entity_get_pad_format(&lif->entity, cfg, - LIF_PAD_SINK, code->which); - code->code = format->code; - } - - return 0; + return vsp1_subdev_enum_mbus_code(subdev, cfg, code, codes, + ARRAY_SIZE(codes)); } static int lif_enum_frame_size(struct v4l2_subdev *subdev, struct v4l2_subdev_pad_config *cfg, struct v4l2_subdev_frame_size_enum *fse) { - struct vsp1_lif *lif = to_lif(subdev); - struct v4l2_mbus_framefmt *format; - - format = vsp1_entity_get_pad_format(&lif->entity, cfg, LIF_PAD_SINK, - fse->which); - - if (fse->index || fse->code != format->code) - return -EINVAL; - - if (fse->pad == LIF_PAD_SINK) { - fse->min_width = LIF_MIN_SIZE; - fse->max_width = LIF_MAX_SIZE; - fse->min_height = LIF_MIN_SIZE; - fse->max_height = LIF_MAX_SIZE; - } else { - fse->min_width = format->width; - fse->max_width = format->width; - fse->min_height = format->height; - fse->max_height = format->height; - } - - return 0; + return vsp1_subdev_enum_frame_size(subdev, cfg, fse, LIF_MIN_SIZE, + LIF_MIN_SIZE, LIF_MAX_SIZE, + LIF_MAX_SIZE); } -static int lif_get_format(struct v4l2_subdev *subdev, struct v4l2_subdev_pad_config *cfg, - struct v4l2_subdev_format *fmt) -{ - struct vsp1_lif *lif = to_lif(subdev); - - fmt->format = *vsp1_entity_get_pad_format(&lif->entity, cfg, fmt->pad, - fmt->which); - - return 0; -} - -static int lif_set_format(struct v4l2_subdev *subdev, struct v4l2_subdev_pad_config *cfg, +static int lif_set_format(struct v4l2_subdev *subdev, + struct v4l2_subdev_pad_config *cfg, struct v4l2_subdev_format *fmt) { struct vsp1_lif *lif = to_lif(subdev); + struct v4l2_subdev_pad_config *config; struct v4l2_mbus_framefmt *format; + config = vsp1_entity_get_pad_config(&lif->entity, cfg, fmt->which); + if (!config) + return -EINVAL; + /* Default to YUV if the requested format is not supported. */ if (fmt->format.code != MEDIA_BUS_FMT_ARGB8888_1X32 && fmt->format.code != MEDIA_BUS_FMT_AYUV8_1X32) fmt->format.code = MEDIA_BUS_FMT_AYUV8_1X32; - format = vsp1_entity_get_pad_format(&lif->entity, cfg, fmt->pad, - fmt->which); + format = vsp1_entity_get_pad_format(&lif->entity, config, fmt->pad); if (fmt->pad == LIF_PAD_SOURCE) { /* The LIF source format is always identical to its sink @@ -172,40 +97,64 @@ static int lif_set_format(struct v4l2_subdev *subdev, struct v4l2_subdev_pad_con fmt->format = *format; /* Propagate the format to the source pad. */ - format = vsp1_entity_get_pad_format(&lif->entity, cfg, LIF_PAD_SOURCE, - fmt->which); + format = vsp1_entity_get_pad_format(&lif->entity, config, + LIF_PAD_SOURCE); *format = fmt->format; return 0; } -/* ----------------------------------------------------------------------------- - * V4L2 Subdevice Operations - */ - -static struct v4l2_subdev_video_ops lif_video_ops = { - .s_stream = lif_s_stream, -}; - static struct v4l2_subdev_pad_ops lif_pad_ops = { + .init_cfg = vsp1_entity_init_cfg, .enum_mbus_code = lif_enum_mbus_code, .enum_frame_size = lif_enum_frame_size, - .get_fmt = lif_get_format, + .get_fmt = vsp1_subdev_get_pad_format, .set_fmt = lif_set_format, }; static struct v4l2_subdev_ops lif_ops = { - .video = &lif_video_ops, .pad = &lif_pad_ops, }; /* ----------------------------------------------------------------------------- + * VSP1 Entity Operations + */ + +static void lif_configure(struct vsp1_entity *entity, + struct vsp1_pipeline *pipe, + struct vsp1_dl_list *dl) +{ + const struct v4l2_mbus_framefmt *format; + struct vsp1_lif *lif = to_lif(&entity->subdev); + unsigned int hbth = 1300; + unsigned int obth = 400; + unsigned int lbth = 200; + + format = vsp1_entity_get_pad_format(&lif->entity, lif->entity.config, + LIF_PAD_SOURCE); + + obth = min(obth, (format->width + 1) / 2 * format->height - 4); + + vsp1_lif_write(lif, dl, VI6_LIF_CSBTH, + (hbth << VI6_LIF_CSBTH_HBTH_SHIFT) | + (lbth << VI6_LIF_CSBTH_LBTH_SHIFT)); + + vsp1_lif_write(lif, dl, VI6_LIF_CTRL, + (obth << VI6_LIF_CTRL_OBTH_SHIFT) | + (format->code == 0 ? VI6_LIF_CTRL_CFMT : 0) | + VI6_LIF_CTRL_REQSEL | VI6_LIF_CTRL_LIF_EN); +} + +static const struct vsp1_entity_operations lif_entity_ops = { + .configure = lif_configure, +}; + +/* ----------------------------------------------------------------------------- * Initialization and Cleanup */ struct vsp1_lif *vsp1_lif_create(struct vsp1_device *vsp1) { - struct v4l2_subdev *subdev; struct vsp1_lif *lif; int ret; @@ -213,24 +162,12 @@ struct vsp1_lif *vsp1_lif_create(struct vsp1_device *vsp1) if (lif == NULL) return ERR_PTR(-ENOMEM); + lif->entity.ops = &lif_entity_ops; lif->entity.type = VSP1_ENTITY_LIF; - ret = vsp1_entity_init(vsp1, &lif->entity, 2); + ret = vsp1_entity_init(vsp1, &lif->entity, "lif", 2, &lif_ops); if (ret < 0) return ERR_PTR(ret); - /* Initialize the V4L2 subdev. */ - subdev = &lif->entity.subdev; - v4l2_subdev_init(subdev, &lif_ops); - - subdev->entity.ops = &vsp1->media_ops; - subdev->internal_ops = &vsp1_subdev_internal_ops; - snprintf(subdev->name, sizeof(subdev->name), "%s lif", - dev_name(vsp1->dev)); - v4l2_set_subdevdata(subdev, lif); - subdev->flags |= V4L2_SUBDEV_FL_HAS_DEVNODE; - - vsp1_entity_init_formats(subdev, NULL); - return lif; } diff --git a/drivers/media/platform/vsp1/vsp1_lut.c b/drivers/media/platform/vsp1/vsp1_lut.c index 4b89095e7..aa09e59f0 100644 --- a/drivers/media/platform/vsp1/vsp1_lut.c +++ b/drivers/media/platform/vsp1/vsp1_lut.c @@ -18,6 +18,7 @@ #include <media/v4l2-subdev.h> #include "vsp1.h" +#include "vsp1_dl.h" #include "vsp1_lut.h" #define LUT_MIN_SIZE 4U @@ -27,19 +28,35 @@ * Device Access */ -static inline void vsp1_lut_write(struct vsp1_lut *lut, u32 reg, u32 data) +static inline void vsp1_lut_write(struct vsp1_lut *lut, struct vsp1_dl_list *dl, + u32 reg, u32 data) { - vsp1_write(lut->entity.vsp1, reg, data); + vsp1_dl_list_write(dl, reg, data); } /* ----------------------------------------------------------------------------- * V4L2 Subdevice Core Operations */ -static void lut_configure(struct vsp1_lut *lut, struct vsp1_lut_config *config) +static int lut_set_table(struct vsp1_lut *lut, struct vsp1_lut_config *config) { - memcpy_toio(lut->entity.vsp1->mmio + VI6_LUT_TABLE, config->lut, - sizeof(config->lut)); + struct vsp1_dl_body *dlb; + unsigned int i; + + dlb = vsp1_dl_fragment_alloc(lut->entity.vsp1, ARRAY_SIZE(config->lut)); + if (!dlb) + return -ENOMEM; + + for (i = 0; i < ARRAY_SIZE(config->lut); ++i) + vsp1_dl_fragment_write(dlb, VI6_LUT_TABLE + 4 * i, + config->lut[i]); + + mutex_lock(&lut->lock); + swap(lut->lut, dlb); + mutex_unlock(&lut->lock); + + vsp1_dl_fragment_free(dlb); + return 0; } static long lut_ioctl(struct v4l2_subdev *subdev, unsigned int cmd, void *arg) @@ -48,8 +65,7 @@ static long lut_ioctl(struct v4l2_subdev *subdev, unsigned int cmd, void *arg) switch (cmd) { case VIDIOC_VSP1_LUT_CONFIG: - lut_configure(lut, arg); - return 0; + return lut_set_table(lut, arg); default: return -ENOIOCTLCMD; @@ -57,22 +73,6 @@ static long lut_ioctl(struct v4l2_subdev *subdev, unsigned int cmd, void *arg) } /* ----------------------------------------------------------------------------- - * V4L2 Subdevice Video Operations - */ - -static int lut_s_stream(struct v4l2_subdev *subdev, int enable) -{ - struct vsp1_lut *lut = to_lut(subdev); - - if (!enable) - return 0; - - vsp1_lut_write(lut, VI6_LUT_CTRL, VI6_LUT_CTRL_EN); - - return 0; -} - -/* ----------------------------------------------------------------------------- * V4L2 Subdevice Pad Operations */ @@ -85,85 +85,39 @@ static int lut_enum_mbus_code(struct v4l2_subdev *subdev, MEDIA_BUS_FMT_AHSV8888_1X32, MEDIA_BUS_FMT_AYUV8_1X32, }; - struct vsp1_lut *lut = to_lut(subdev); - struct v4l2_mbus_framefmt *format; - - if (code->pad == LUT_PAD_SINK) { - if (code->index >= ARRAY_SIZE(codes)) - return -EINVAL; - - code->code = codes[code->index]; - } else { - /* The LUT can't perform format conversion, the sink format is - * always identical to the source format. - */ - if (code->index) - return -EINVAL; - - format = vsp1_entity_get_pad_format(&lut->entity, cfg, - LUT_PAD_SINK, code->which); - code->code = format->code; - } - return 0; + return vsp1_subdev_enum_mbus_code(subdev, cfg, code, codes, + ARRAY_SIZE(codes)); } static int lut_enum_frame_size(struct v4l2_subdev *subdev, struct v4l2_subdev_pad_config *cfg, struct v4l2_subdev_frame_size_enum *fse) { - struct vsp1_lut *lut = to_lut(subdev); - struct v4l2_mbus_framefmt *format; - - format = vsp1_entity_get_pad_format(&lut->entity, cfg, - fse->pad, fse->which); - - if (fse->index || fse->code != format->code) - return -EINVAL; - - if (fse->pad == LUT_PAD_SINK) { - fse->min_width = LUT_MIN_SIZE; - fse->max_width = LUT_MAX_SIZE; - fse->min_height = LUT_MIN_SIZE; - fse->max_height = LUT_MAX_SIZE; - } else { - /* The size on the source pad are fixed and always identical to - * the size on the sink pad. - */ - fse->min_width = format->width; - fse->max_width = format->width; - fse->min_height = format->height; - fse->max_height = format->height; - } - - return 0; -} - -static int lut_get_format(struct v4l2_subdev *subdev, struct v4l2_subdev_pad_config *cfg, - struct v4l2_subdev_format *fmt) -{ - struct vsp1_lut *lut = to_lut(subdev); - - fmt->format = *vsp1_entity_get_pad_format(&lut->entity, cfg, fmt->pad, - fmt->which); - - return 0; + return vsp1_subdev_enum_frame_size(subdev, cfg, fse, LUT_MIN_SIZE, + LUT_MIN_SIZE, LUT_MAX_SIZE, + LUT_MAX_SIZE); } -static int lut_set_format(struct v4l2_subdev *subdev, struct v4l2_subdev_pad_config *cfg, +static int lut_set_format(struct v4l2_subdev *subdev, + struct v4l2_subdev_pad_config *cfg, struct v4l2_subdev_format *fmt) { struct vsp1_lut *lut = to_lut(subdev); + struct v4l2_subdev_pad_config *config; struct v4l2_mbus_framefmt *format; + config = vsp1_entity_get_pad_config(&lut->entity, cfg, fmt->which); + if (!config) + return -EINVAL; + /* Default to YUV if the requested format is not supported. */ if (fmt->format.code != MEDIA_BUS_FMT_ARGB8888_1X32 && fmt->format.code != MEDIA_BUS_FMT_AHSV8888_1X32 && fmt->format.code != MEDIA_BUS_FMT_AYUV8_1X32) fmt->format.code = MEDIA_BUS_FMT_AYUV8_1X32; - format = vsp1_entity_get_pad_format(&lut->entity, cfg, fmt->pad, - fmt->which); + format = vsp1_entity_get_pad_format(&lut->entity, config, fmt->pad); if (fmt->pad == LUT_PAD_SOURCE) { /* The LUT output format can't be modified. */ @@ -171,6 +125,7 @@ static int lut_set_format(struct v4l2_subdev *subdev, struct v4l2_subdev_pad_con return 0; } + format->code = fmt->format.code; format->width = clamp_t(unsigned int, fmt->format.width, LUT_MIN_SIZE, LUT_MAX_SIZE); format->height = clamp_t(unsigned int, fmt->format.height, @@ -181,8 +136,8 @@ static int lut_set_format(struct v4l2_subdev *subdev, struct v4l2_subdev_pad_con fmt->format = *format; /* Propagate the format to the source pad. */ - format = vsp1_entity_get_pad_format(&lut->entity, cfg, LUT_PAD_SOURCE, - fmt->which); + format = vsp1_entity_get_pad_format(&lut->entity, config, + LUT_PAD_SOURCE); *format = fmt->format; return 0; @@ -196,30 +151,49 @@ static struct v4l2_subdev_core_ops lut_core_ops = { .ioctl = lut_ioctl, }; -static struct v4l2_subdev_video_ops lut_video_ops = { - .s_stream = lut_s_stream, -}; - static struct v4l2_subdev_pad_ops lut_pad_ops = { + .init_cfg = vsp1_entity_init_cfg, .enum_mbus_code = lut_enum_mbus_code, .enum_frame_size = lut_enum_frame_size, - .get_fmt = lut_get_format, + .get_fmt = vsp1_subdev_get_pad_format, .set_fmt = lut_set_format, }; static struct v4l2_subdev_ops lut_ops = { .core = &lut_core_ops, - .video = &lut_video_ops, .pad = &lut_pad_ops, }; /* ----------------------------------------------------------------------------- + * VSP1 Entity Operations + */ + +static void lut_configure(struct vsp1_entity *entity, + struct vsp1_pipeline *pipe, + struct vsp1_dl_list *dl) +{ + struct vsp1_lut *lut = to_lut(&entity->subdev); + + vsp1_lut_write(lut, dl, VI6_LUT_CTRL, VI6_LUT_CTRL_EN); + + mutex_lock(&lut->lock); + if (lut->lut) { + vsp1_dl_list_add_fragment(dl, lut->lut); + lut->lut = NULL; + } + mutex_unlock(&lut->lock); +} + +static const struct vsp1_entity_operations lut_entity_ops = { + .configure = lut_configure, +}; + +/* ----------------------------------------------------------------------------- * Initialization and Cleanup */ struct vsp1_lut *vsp1_lut_create(struct vsp1_device *vsp1) { - struct v4l2_subdev *subdev; struct vsp1_lut *lut; int ret; @@ -227,24 +201,12 @@ struct vsp1_lut *vsp1_lut_create(struct vsp1_device *vsp1) if (lut == NULL) return ERR_PTR(-ENOMEM); + lut->entity.ops = &lut_entity_ops; lut->entity.type = VSP1_ENTITY_LUT; - ret = vsp1_entity_init(vsp1, &lut->entity, 2); + ret = vsp1_entity_init(vsp1, &lut->entity, "lut", 2, &lut_ops); if (ret < 0) return ERR_PTR(ret); - /* Initialize the V4L2 subdev. */ - subdev = &lut->entity.subdev; - v4l2_subdev_init(subdev, &lut_ops); - - subdev->entity.ops = &vsp1->media_ops; - subdev->internal_ops = &vsp1_subdev_internal_ops; - snprintf(subdev->name, sizeof(subdev->name), "%s lut", - dev_name(vsp1->dev)); - v4l2_set_subdevdata(subdev, lut); - subdev->flags |= V4L2_SUBDEV_FL_HAS_DEVNODE; - - vsp1_entity_init_formats(subdev, NULL); - return lut; } diff --git a/drivers/media/platform/vsp1/vsp1_lut.h b/drivers/media/platform/vsp1/vsp1_lut.h index f92ffb867..cef874f22 100644 --- a/drivers/media/platform/vsp1/vsp1_lut.h +++ b/drivers/media/platform/vsp1/vsp1_lut.h @@ -13,6 +13,8 @@ #ifndef __VSP1_LUT_H__ #define __VSP1_LUT_H__ +#include <linux/mutex.h> + #include <media/media-entity.h> #include <media/v4l2-subdev.h> @@ -25,7 +27,9 @@ struct vsp1_device; struct vsp1_lut { struct vsp1_entity entity; - u32 lut[256]; + + struct mutex lock; + struct vsp1_dl_body *lut; }; static inline struct vsp1_lut *to_lut(struct v4l2_subdev *subdev) diff --git a/drivers/media/platform/vsp1/vsp1_pipe.c b/drivers/media/platform/vsp1/vsp1_pipe.c index 6659f06b1..4f3b4a1d0 100644 --- a/drivers/media/platform/vsp1/vsp1_pipe.c +++ b/drivers/media/platform/vsp1/vsp1_pipe.c @@ -43,7 +43,7 @@ static const struct vsp1_format_info vsp1_video_formats[] = { { V4L2_PIX_FMT_XRGB444, MEDIA_BUS_FMT_ARGB8888_1X32, VI6_FMT_XRGB_4444, VI6_RPF_DSWAP_P_LLS | VI6_RPF_DSWAP_P_LWS | VI6_RPF_DSWAP_P_WDS, - 1, { 16, 0, 0 }, false, false, 1, 1, true }, + 1, { 16, 0, 0 }, false, false, 1, 1, false }, { V4L2_PIX_FMT_ARGB555, MEDIA_BUS_FMT_ARGB8888_1X32, VI6_FMT_ARGB_1555, VI6_RPF_DSWAP_P_LLS | VI6_RPF_DSWAP_P_LWS | VI6_RPF_DSWAP_P_WDS, @@ -172,14 +172,18 @@ void vsp1_pipeline_reset(struct vsp1_pipeline *pipe) bru->inputs[i].rpf = NULL; } - for (i = 0; i < ARRAY_SIZE(pipe->inputs); ++i) + for (i = 0; i < pipe->num_inputs; ++i) { + pipe->inputs[i]->pipe = NULL; pipe->inputs[i] = NULL; + } + + pipe->output->pipe = NULL; + pipe->output = NULL; INIT_LIST_HEAD(&pipe->entities); pipe->state = VSP1_PIPELINE_STOPPED; pipe->buffers_ready = 0; pipe->num_inputs = 0; - pipe->output = NULL; pipe->bru = NULL; pipe->lif = NULL; pipe->uds = NULL; @@ -190,11 +194,13 @@ void vsp1_pipeline_init(struct vsp1_pipeline *pipe) mutex_init(&pipe->lock); spin_lock_init(&pipe->irqlock); init_waitqueue_head(&pipe->wq); + kref_init(&pipe->kref); INIT_LIST_HEAD(&pipe->entities); pipe->state = VSP1_PIPELINE_STOPPED; } +/* Must be called with the pipe irqlock held. */ void vsp1_pipeline_run(struct vsp1_pipeline *pipe) { struct vsp1_device *vsp1 = pipe->output->entity.vsp1; @@ -226,7 +232,7 @@ int vsp1_pipeline_stop(struct vsp1_pipeline *pipe) unsigned long flags; int ret; - if (pipe->dl) { + if (pipe->lif) { /* When using display lists in continuous frame mode the only * way to stop the pipeline is to reset the hardware. */ @@ -253,10 +259,10 @@ int vsp1_pipeline_stop(struct vsp1_pipeline *pipe) if (entity->route && entity->route->reg) vsp1_write(entity->vsp1, entity->route->reg, VI6_DPR_NODE_UNUSED); - - v4l2_subdev_call(&entity->subdev, video, s_stream, 0); } + v4l2_subdev_call(&pipe->output->entity.subdev, video, s_stream, 0); + return ret; } @@ -271,50 +277,15 @@ bool vsp1_pipeline_ready(struct vsp1_pipeline *pipe) return pipe->buffers_ready == mask; } -void vsp1_pipeline_display_start(struct vsp1_pipeline *pipe) -{ - if (pipe->dl) - vsp1_dl_irq_display_start(pipe->dl); -} - void vsp1_pipeline_frame_end(struct vsp1_pipeline *pipe) { - enum vsp1_pipeline_state state; - unsigned long flags; - if (pipe == NULL) return; - if (pipe->dl) - vsp1_dl_irq_frame_end(pipe->dl); + vsp1_dlm_irq_frame_end(pipe->output->dlm); - /* Signal frame end to the pipeline handler. */ - pipe->frame_end(pipe); - - spin_lock_irqsave(&pipe->irqlock, flags); - - state = pipe->state; - - /* When using display lists in continuous frame mode the pipeline is - * automatically restarted by the hardware. - */ - if (!pipe->dl) - pipe->state = VSP1_PIPELINE_STOPPED; - - /* If a stop has been requested, mark the pipeline as stopped and - * return. - */ - if (state == VSP1_PIPELINE_STOPPING) { - wake_up(&pipe->wq); - goto done; - } - - /* Restart the pipeline if ready. */ - if (vsp1_pipeline_ready(pipe)) - vsp1_pipeline_run(pipe); - -done: - spin_unlock_irqrestore(&pipe->irqlock, flags); + if (pipe->frame_end) + pipe->frame_end(pipe); } /* @@ -324,9 +295,13 @@ done: * to be scaled, we disable alpha scaling when the UDS input has a fixed alpha * value. The UDS then outputs a fixed alpha value which needs to be programmed * from the input RPF alpha. + * + * This function can only be called from a subdev s_stream handler as it + * requires a valid display list context. */ void vsp1_pipeline_propagate_alpha(struct vsp1_pipeline *pipe, struct vsp1_entity *input, + struct vsp1_dl_list *dl, unsigned int alpha) { struct vsp1_entity *entity; @@ -349,7 +324,7 @@ void vsp1_pipeline_propagate_alpha(struct vsp1_pipeline *pipe, if (entity->type == VSP1_ENTITY_UDS) { struct vsp1_uds *uds = to_uds(&entity->subdev); - vsp1_uds_set_alpha(uds, alpha); + vsp1_uds_set_alpha(uds, dl, alpha); break; } @@ -375,7 +350,7 @@ void vsp1_pipelines_suspend(struct vsp1_device *vsp1) if (wpf == NULL) continue; - pipe = to_vsp1_pipeline(&wpf->entity.subdev.entity); + pipe = wpf->pipe; if (pipe == NULL) continue; @@ -392,7 +367,7 @@ void vsp1_pipelines_suspend(struct vsp1_device *vsp1) if (wpf == NULL) continue; - pipe = to_vsp1_pipeline(&wpf->entity.subdev.entity); + pipe = wpf->pipe; if (pipe == NULL) continue; @@ -416,7 +391,7 @@ void vsp1_pipelines_resume(struct vsp1_device *vsp1) if (wpf == NULL) continue; - pipe = to_vsp1_pipeline(&wpf->entity.subdev.entity); + pipe = wpf->pipe; if (pipe == NULL) continue; diff --git a/drivers/media/platform/vsp1/vsp1_pipe.h b/drivers/media/platform/vsp1/vsp1_pipe.h index b2f3a8a89..7b5611351 100644 --- a/drivers/media/platform/vsp1/vsp1_pipe.h +++ b/drivers/media/platform/vsp1/vsp1_pipe.h @@ -13,13 +13,14 @@ #ifndef __VSP1_PIPE_H__ #define __VSP1_PIPE_H__ +#include <linux/kref.h> #include <linux/list.h> #include <linux/spinlock.h> #include <linux/wait.h> #include <media/media-entity.h> -struct vsp1_dl; +struct vsp1_dl_list; struct vsp1_rwpf; /* @@ -63,7 +64,7 @@ enum vsp1_pipeline_state { * @wq: work queue to wait for state change completion * @frame_end: frame end interrupt handler * @lock: protects the pipeline use count and stream count - * @use_count: number of video nodes using the pipeline + * @kref: pipeline reference count * @stream_count: number of streaming video nodes * @buffers_ready: bitmask of RPFs and WPFs with at least one buffer available * @num_inputs: number of RPFs @@ -86,7 +87,7 @@ struct vsp1_pipeline { void (*frame_end)(struct vsp1_pipeline *pipe); struct mutex lock; - unsigned int use_count; + struct kref kref; unsigned int stream_count; unsigned int buffers_ready; @@ -100,17 +101,9 @@ struct vsp1_pipeline { struct list_head entities; - struct vsp1_dl *dl; + struct vsp1_dl_list *dl; }; -static inline struct vsp1_pipeline *to_vsp1_pipeline(struct media_entity *e) -{ - if (likely(e->pipe)) - return container_of(e->pipe, struct vsp1_pipeline, pipe); - else - return NULL; -} - void vsp1_pipeline_reset(struct vsp1_pipeline *pipe); void vsp1_pipeline_init(struct vsp1_pipeline *pipe); @@ -119,11 +112,11 @@ bool vsp1_pipeline_stopped(struct vsp1_pipeline *pipe); int vsp1_pipeline_stop(struct vsp1_pipeline *pipe); bool vsp1_pipeline_ready(struct vsp1_pipeline *pipe); -void vsp1_pipeline_display_start(struct vsp1_pipeline *pipe); void vsp1_pipeline_frame_end(struct vsp1_pipeline *pipe); void vsp1_pipeline_propagate_alpha(struct vsp1_pipeline *pipe, struct vsp1_entity *input, + struct vsp1_dl_list *dl, unsigned int alpha); void vsp1_pipelines_suspend(struct vsp1_device *vsp1); diff --git a/drivers/media/platform/vsp1/vsp1_regs.h b/drivers/media/platform/vsp1/vsp1_regs.h index 069216f0e..927b5fb94 100644 --- a/drivers/media/platform/vsp1/vsp1_regs.h +++ b/drivers/media/platform/vsp1/vsp1_regs.h @@ -217,6 +217,16 @@ #define VI6_RPF_SRCM_ADDR_C1 0x0344 #define VI6_RPF_SRCM_ADDR_AI 0x0348 +#define VI6_RPF_MULT_ALPHA 0x036c +#define VI6_RPF_MULT_ALPHA_A_MMD_NONE (0 << 12) +#define VI6_RPF_MULT_ALPHA_A_MMD_RATIO (1 << 12) +#define VI6_RPF_MULT_ALPHA_P_MMD_NONE (0 << 8) +#define VI6_RPF_MULT_ALPHA_P_MMD_RATIO (1 << 8) +#define VI6_RPF_MULT_ALPHA_P_MMD_IMAGE (2 << 8) +#define VI6_RPF_MULT_ALPHA_P_MMD_BOTH (3 << 8) +#define VI6_RPF_MULT_ALPHA_RATIO_MASK (0xff < 0) +#define VI6_RPF_MULT_ALPHA_RATIO_SHIFT 0 + /* ----------------------------------------------------------------------------- * WPF Control Registers */ diff --git a/drivers/media/platform/vsp1/vsp1_rpf.c b/drivers/media/platform/vsp1/vsp1_rpf.c index 5bc1d1574..49168db3f 100644 --- a/drivers/media/platform/vsp1/vsp1_rpf.c +++ b/drivers/media/platform/vsp1/vsp1_rpf.c @@ -16,6 +16,8 @@ #include <media/v4l2-subdev.h> #include "vsp1.h" +#include "vsp1_dl.h" +#include "vsp1_pipe.h" #include "vsp1_rwpf.h" #include "vsp1_video.h" @@ -26,64 +28,50 @@ * Device Access */ -static inline void vsp1_rpf_write(struct vsp1_rwpf *rpf, u32 reg, u32 data) +static inline void vsp1_rpf_write(struct vsp1_rwpf *rpf, + struct vsp1_dl_list *dl, u32 reg, u32 data) { - vsp1_mod_write(&rpf->entity, reg + rpf->entity.index * VI6_RPF_OFFSET, - data); + vsp1_dl_list_write(dl, reg + rpf->entity.index * VI6_RPF_OFFSET, data); } /* ----------------------------------------------------------------------------- - * Controls + * V4L2 Subdevice Operations */ -static int rpf_s_ctrl(struct v4l2_ctrl *ctrl) -{ - struct vsp1_rwpf *rpf = - container_of(ctrl->handler, struct vsp1_rwpf, ctrls); - struct vsp1_pipeline *pipe; - - if (!vsp1_entity_is_streaming(&rpf->entity)) - return 0; - - switch (ctrl->id) { - case V4L2_CID_ALPHA_COMPONENT: - vsp1_rpf_write(rpf, VI6_RPF_VRTCOL_SET, - ctrl->val << VI6_RPF_VRTCOL_SET_LAYA_SHIFT); - - pipe = to_vsp1_pipeline(&rpf->entity.subdev.entity); - vsp1_pipeline_propagate_alpha(pipe, &rpf->entity, ctrl->val); - break; - } - - return 0; -} - -static const struct v4l2_ctrl_ops rpf_ctrl_ops = { - .s_ctrl = rpf_s_ctrl, +static struct v4l2_subdev_ops rpf_ops = { + .pad = &vsp1_rwpf_pad_ops, }; /* ----------------------------------------------------------------------------- - * V4L2 Subdevice Core Operations + * VSP1 Entity Operations */ -static int rpf_s_stream(struct v4l2_subdev *subdev, int enable) +static void rpf_set_memory(struct vsp1_entity *entity, struct vsp1_dl_list *dl) +{ + struct vsp1_rwpf *rpf = entity_to_rwpf(entity); + + vsp1_rpf_write(rpf, dl, VI6_RPF_SRCM_ADDR_Y, + rpf->mem.addr[0] + rpf->offsets[0]); + vsp1_rpf_write(rpf, dl, VI6_RPF_SRCM_ADDR_C0, + rpf->mem.addr[1] + rpf->offsets[1]); + vsp1_rpf_write(rpf, dl, VI6_RPF_SRCM_ADDR_C1, + rpf->mem.addr[2] + rpf->offsets[1]); +} + +static void rpf_configure(struct vsp1_entity *entity, + struct vsp1_pipeline *pipe, + struct vsp1_dl_list *dl) { - struct vsp1_pipeline *pipe = to_vsp1_pipeline(&subdev->entity); - struct vsp1_rwpf *rpf = to_rwpf(subdev); - struct vsp1_device *vsp1 = rpf->entity.vsp1; + struct vsp1_rwpf *rpf = to_rwpf(&entity->subdev); const struct vsp1_format_info *fmtinfo = rpf->fmtinfo; const struct v4l2_pix_format_mplane *format = &rpf->format; - const struct v4l2_rect *crop = &rpf->crop; + const struct v4l2_mbus_framefmt *source_format; + const struct v4l2_mbus_framefmt *sink_format; + const struct v4l2_rect *crop; + unsigned int left = 0; + unsigned int top = 0; u32 pstride; u32 infmt; - int ret; - - ret = vsp1_entity_set_streaming(&rpf->entity, enable); - if (ret < 0) - return ret; - - if (!enable) - return 0; /* Source size, stride and crop offsets. * @@ -91,10 +79,12 @@ static int rpf_s_stream(struct v4l2_subdev *subdev, int enable) * left corner in the plane buffer. Only two offsets are needed, as * planes 2 and 3 always have identical strides. */ - vsp1_rpf_write(rpf, VI6_RPF_SRC_BSIZE, + crop = vsp1_rwpf_get_crop(rpf, rpf->entity.config); + + vsp1_rpf_write(rpf, dl, VI6_RPF_SRC_BSIZE, (crop->width << VI6_RPF_SRC_BSIZE_BHSIZE_SHIFT) | (crop->height << VI6_RPF_SRC_BSIZE_BVSIZE_SHIFT)); - vsp1_rpf_write(rpf, VI6_RPF_SRC_ESIZE, + vsp1_rpf_write(rpf, dl, VI6_RPF_SRC_ESIZE, (crop->width << VI6_RPF_SRC_ESIZE_EHSIZE_SHIFT) | (crop->height << VI6_RPF_SRC_ESIZE_EVSIZE_SHIFT)); @@ -103,26 +93,25 @@ static int rpf_s_stream(struct v4l2_subdev *subdev, int enable) pstride = format->plane_fmt[0].bytesperline << VI6_RPF_SRCM_PSTRIDE_Y_SHIFT; - vsp1_rpf_write(rpf, VI6_RPF_SRCM_ADDR_Y, - rpf->buf_addr[0] + rpf->offsets[0]); - if (format->num_planes > 1) { rpf->offsets[1] = crop->top * format->plane_fmt[1].bytesperline + crop->left * fmtinfo->bpp[1] / 8; pstride |= format->plane_fmt[1].bytesperline << VI6_RPF_SRCM_PSTRIDE_C_SHIFT; - - vsp1_rpf_write(rpf, VI6_RPF_SRCM_ADDR_C0, - rpf->buf_addr[1] + rpf->offsets[1]); - - if (format->num_planes > 2) - vsp1_rpf_write(rpf, VI6_RPF_SRCM_ADDR_C1, - rpf->buf_addr[2] + rpf->offsets[1]); + } else { + rpf->offsets[1] = 0; } - vsp1_rpf_write(rpf, VI6_RPF_SRCM_PSTRIDE, pstride); + vsp1_rpf_write(rpf, dl, VI6_RPF_SRCM_PSTRIDE, pstride); /* Format */ + sink_format = vsp1_entity_get_pad_format(&rpf->entity, + rpf->entity.config, + RWPF_PAD_SINK); + source_format = vsp1_entity_get_pad_format(&rpf->entity, + rpf->entity.config, + RWPF_PAD_SOURCE); + infmt = VI6_RPF_INFMT_CIPM | (fmtinfo->hwfmt << VI6_RPF_INFMT_RDFMT_SHIFT); @@ -131,88 +120,98 @@ static int rpf_s_stream(struct v4l2_subdev *subdev, int enable) if (fmtinfo->swap_uv) infmt |= VI6_RPF_INFMT_SPUVS; - if (rpf->entity.formats[RWPF_PAD_SINK].code != - rpf->entity.formats[RWPF_PAD_SOURCE].code) + if (sink_format->code != source_format->code) infmt |= VI6_RPF_INFMT_CSC; - vsp1_rpf_write(rpf, VI6_RPF_INFMT, infmt); - vsp1_rpf_write(rpf, VI6_RPF_DSWAP, fmtinfo->swap); + vsp1_rpf_write(rpf, dl, VI6_RPF_INFMT, infmt); + vsp1_rpf_write(rpf, dl, VI6_RPF_DSWAP, fmtinfo->swap); /* Output location */ - vsp1_rpf_write(rpf, VI6_RPF_LOC, - (rpf->location.left << VI6_RPF_LOC_HCOORD_SHIFT) | - (rpf->location.top << VI6_RPF_LOC_VCOORD_SHIFT)); + if (pipe->bru) { + const struct v4l2_rect *compose; + + compose = vsp1_entity_get_pad_compose(pipe->bru, + pipe->bru->config, + rpf->bru_input); + left = compose->left; + top = compose->top; + } - /* Use the alpha channel (extended to 8 bits) when available or an - * alpha value set through the V4L2_CID_ALPHA_COMPONENT control - * otherwise. Disable color keying. + vsp1_rpf_write(rpf, dl, VI6_RPF_LOC, + (left << VI6_RPF_LOC_HCOORD_SHIFT) | + (top << VI6_RPF_LOC_VCOORD_SHIFT)); + + /* On Gen2 use the alpha channel (extended to 8 bits) when available or + * a fixed alpha value set through the V4L2_CID_ALPHA_COMPONENT control + * otherwise. + * + * The Gen3 RPF has extended alpha capability and can both multiply the + * alpha channel by a fixed global alpha value, and multiply the pixel + * components to convert the input to premultiplied alpha. + * + * As alpha premultiplication is available in the BRU for both Gen2 and + * Gen3 we handle it there and use the Gen3 alpha multiplier for global + * alpha multiplication only. This however prevents conversion to + * premultiplied alpha if no BRU is present in the pipeline. If that use + * case turns out to be useful we will revisit the implementation (for + * Gen3 only). + * + * We enable alpha multiplication on Gen3 using the fixed alpha value + * set through the V4L2_CID_ALPHA_COMPONENT control when the input + * contains an alpha channel. On Gen2 the global alpha is ignored in + * that case. + * + * In all cases, disable color keying. */ - vsp1_rpf_write(rpf, VI6_RPF_ALPH_SEL, VI6_RPF_ALPH_SEL_AEXT_EXT | + vsp1_rpf_write(rpf, dl, VI6_RPF_ALPH_SEL, VI6_RPF_ALPH_SEL_AEXT_EXT | (fmtinfo->alpha ? VI6_RPF_ALPH_SEL_ASEL_PACKED : VI6_RPF_ALPH_SEL_ASEL_FIXED)); - if (vsp1->info->uapi) - mutex_lock(rpf->ctrls.lock); - vsp1_rpf_write(rpf, VI6_RPF_VRTCOL_SET, - rpf->alpha->cur.val << VI6_RPF_VRTCOL_SET_LAYA_SHIFT); - vsp1_pipeline_propagate_alpha(pipe, &rpf->entity, rpf->alpha->cur.val); - if (vsp1->info->uapi) - mutex_unlock(rpf->ctrls.lock); - - vsp1_rpf_write(rpf, VI6_RPF_MSK_CTRL, 0); - vsp1_rpf_write(rpf, VI6_RPF_CKEY_CTRL, 0); - - return 0; -} - -/* ----------------------------------------------------------------------------- - * V4L2 Subdevice Operations - */ - -static struct v4l2_subdev_video_ops rpf_video_ops = { - .s_stream = rpf_s_stream, -}; - -static struct v4l2_subdev_pad_ops rpf_pad_ops = { - .enum_mbus_code = vsp1_rwpf_enum_mbus_code, - .enum_frame_size = vsp1_rwpf_enum_frame_size, - .get_fmt = vsp1_rwpf_get_format, - .set_fmt = vsp1_rwpf_set_format, - .get_selection = vsp1_rwpf_get_selection, - .set_selection = vsp1_rwpf_set_selection, -}; + vsp1_rpf_write(rpf, dl, VI6_RPF_VRTCOL_SET, + rpf->alpha << VI6_RPF_VRTCOL_SET_LAYA_SHIFT); + + if (entity->vsp1->info->gen == 3) { + u32 mult; + + if (fmtinfo->alpha) { + /* When the input contains an alpha channel enable the + * alpha multiplier. If the input is premultiplied we + * need to multiply both the alpha channel and the pixel + * components by the global alpha value to keep them + * premultiplied. Otherwise multiply the alpha channel + * only. + */ + bool premultiplied = format->flags + & V4L2_PIX_FMT_FLAG_PREMUL_ALPHA; + + mult = VI6_RPF_MULT_ALPHA_A_MMD_RATIO + | (premultiplied ? + VI6_RPF_MULT_ALPHA_P_MMD_RATIO : + VI6_RPF_MULT_ALPHA_P_MMD_NONE) + | (rpf->alpha << VI6_RPF_MULT_ALPHA_RATIO_SHIFT); + } else { + /* When the input doesn't contain an alpha channel the + * global alpha value is applied in the unpacking unit, + * the alpha multiplier isn't needed and must be + * disabled. + */ + mult = VI6_RPF_MULT_ALPHA_A_MMD_NONE + | VI6_RPF_MULT_ALPHA_P_MMD_NONE; + } + + vsp1_rpf_write(rpf, dl, VI6_RPF_MULT_ALPHA, mult); + } -static struct v4l2_subdev_ops rpf_ops = { - .video = &rpf_video_ops, - .pad = &rpf_pad_ops, -}; + vsp1_pipeline_propagate_alpha(pipe, &rpf->entity, dl, rpf->alpha); -/* ----------------------------------------------------------------------------- - * Video Device Operations - */ + vsp1_rpf_write(rpf, dl, VI6_RPF_MSK_CTRL, 0); + vsp1_rpf_write(rpf, dl, VI6_RPF_CKEY_CTRL, 0); -static void rpf_set_memory(struct vsp1_rwpf *rpf, struct vsp1_rwpf_memory *mem) -{ - unsigned int i; - - for (i = 0; i < 3; ++i) - rpf->buf_addr[i] = mem->addr[i]; - - if (!vsp1_entity_is_streaming(&rpf->entity)) - return; - - vsp1_rpf_write(rpf, VI6_RPF_SRCM_ADDR_Y, - mem->addr[0] + rpf->offsets[0]); - if (mem->num_planes > 1) - vsp1_rpf_write(rpf, VI6_RPF_SRCM_ADDR_C0, - mem->addr[1] + rpf->offsets[1]); - if (mem->num_planes > 2) - vsp1_rpf_write(rpf, VI6_RPF_SRCM_ADDR_C1, - mem->addr[2] + rpf->offsets[1]); } -static const struct vsp1_rwpf_operations rpf_vdev_ops = { +static const struct vsp1_entity_operations rpf_entity_ops = { .set_memory = rpf_set_memory, + .configure = rpf_configure, }; /* ----------------------------------------------------------------------------- @@ -221,51 +220,31 @@ static const struct vsp1_rwpf_operations rpf_vdev_ops = { struct vsp1_rwpf *vsp1_rpf_create(struct vsp1_device *vsp1, unsigned int index) { - struct v4l2_subdev *subdev; struct vsp1_rwpf *rpf; + char name[6]; int ret; rpf = devm_kzalloc(vsp1->dev, sizeof(*rpf), GFP_KERNEL); if (rpf == NULL) return ERR_PTR(-ENOMEM); - rpf->ops = &rpf_vdev_ops; - rpf->max_width = RPF_MAX_WIDTH; rpf->max_height = RPF_MAX_HEIGHT; + rpf->entity.ops = &rpf_entity_ops; rpf->entity.type = VSP1_ENTITY_RPF; rpf->entity.index = index; - ret = vsp1_entity_init(vsp1, &rpf->entity, 2); + sprintf(name, "rpf.%u", index); + ret = vsp1_entity_init(vsp1, &rpf->entity, name, 2, &rpf_ops); if (ret < 0) return ERR_PTR(ret); - /* Initialize the V4L2 subdev. */ - subdev = &rpf->entity.subdev; - v4l2_subdev_init(subdev, &rpf_ops); - - subdev->entity.ops = &vsp1->media_ops; - subdev->internal_ops = &vsp1_subdev_internal_ops; - snprintf(subdev->name, sizeof(subdev->name), "%s rpf.%u", - dev_name(vsp1->dev), index); - v4l2_set_subdevdata(subdev, rpf); - subdev->flags |= V4L2_SUBDEV_FL_HAS_DEVNODE; - - vsp1_entity_init_formats(subdev, NULL); - /* Initialize the control handler. */ - v4l2_ctrl_handler_init(&rpf->ctrls, 1); - rpf->alpha = v4l2_ctrl_new_std(&rpf->ctrls, &rpf_ctrl_ops, - V4L2_CID_ALPHA_COMPONENT, - 0, 255, 1, 255); - - rpf->entity.subdev.ctrl_handler = &rpf->ctrls; - - if (rpf->ctrls.error) { + ret = vsp1_rwpf_init_ctrls(rpf); + if (ret < 0) { dev_err(vsp1->dev, "rpf%u: failed to initialize controls\n", index); - ret = rpf->ctrls.error; goto error; } diff --git a/drivers/media/platform/vsp1/vsp1_rwpf.c b/drivers/media/platform/vsp1/vsp1_rwpf.c index 9688c219b..3b6e032e7 100644 --- a/drivers/media/platform/vsp1/vsp1_rwpf.c +++ b/drivers/media/platform/vsp1/vsp1_rwpf.c @@ -20,13 +20,20 @@ #define RWPF_MIN_WIDTH 1 #define RWPF_MIN_HEIGHT 1 +struct v4l2_rect *vsp1_rwpf_get_crop(struct vsp1_rwpf *rwpf, + struct v4l2_subdev_pad_config *config) +{ + return v4l2_subdev_get_try_crop(&rwpf->entity.subdev, config, + RWPF_PAD_SINK); +} + /* ----------------------------------------------------------------------------- * V4L2 Subdevice Pad Operations */ -int vsp1_rwpf_enum_mbus_code(struct v4l2_subdev *subdev, - struct v4l2_subdev_pad_config *cfg, - struct v4l2_subdev_mbus_code_enum *code) +static int vsp1_rwpf_enum_mbus_code(struct v4l2_subdev *subdev, + struct v4l2_subdev_pad_config *cfg, + struct v4l2_subdev_mbus_code_enum *code) { static const unsigned int codes[] = { MEDIA_BUS_FMT_ARGB8888_1X32, @@ -41,75 +48,36 @@ int vsp1_rwpf_enum_mbus_code(struct v4l2_subdev *subdev, return 0; } -int vsp1_rwpf_enum_frame_size(struct v4l2_subdev *subdev, - struct v4l2_subdev_pad_config *cfg, - struct v4l2_subdev_frame_size_enum *fse) -{ - struct vsp1_rwpf *rwpf = to_rwpf(subdev); - struct v4l2_mbus_framefmt *format; - - format = vsp1_entity_get_pad_format(&rwpf->entity, cfg, fse->pad, - fse->which); - - if (fse->index || fse->code != format->code) - return -EINVAL; - - if (fse->pad == RWPF_PAD_SINK) { - fse->min_width = RWPF_MIN_WIDTH; - fse->max_width = rwpf->max_width; - fse->min_height = RWPF_MIN_HEIGHT; - fse->max_height = rwpf->max_height; - } else { - /* The size on the source pad are fixed and always identical to - * the size on the sink pad. - */ - fse->min_width = format->width; - fse->max_width = format->width; - fse->min_height = format->height; - fse->max_height = format->height; - } - - return 0; -} - -static struct v4l2_rect * -vsp1_rwpf_get_crop(struct vsp1_rwpf *rwpf, struct v4l2_subdev_pad_config *cfg, u32 which) -{ - switch (which) { - case V4L2_SUBDEV_FORMAT_TRY: - return v4l2_subdev_get_try_crop(&rwpf->entity.subdev, cfg, RWPF_PAD_SINK); - case V4L2_SUBDEV_FORMAT_ACTIVE: - return &rwpf->crop; - default: - return NULL; - } -} - -int vsp1_rwpf_get_format(struct v4l2_subdev *subdev, struct v4l2_subdev_pad_config *cfg, - struct v4l2_subdev_format *fmt) +static int vsp1_rwpf_enum_frame_size(struct v4l2_subdev *subdev, + struct v4l2_subdev_pad_config *cfg, + struct v4l2_subdev_frame_size_enum *fse) { struct vsp1_rwpf *rwpf = to_rwpf(subdev); - fmt->format = *vsp1_entity_get_pad_format(&rwpf->entity, cfg, fmt->pad, - fmt->which); - - return 0; + return vsp1_subdev_enum_frame_size(subdev, cfg, fse, RWPF_MIN_WIDTH, + RWPF_MIN_HEIGHT, rwpf->max_width, + rwpf->max_height); } -int vsp1_rwpf_set_format(struct v4l2_subdev *subdev, struct v4l2_subdev_pad_config *cfg, - struct v4l2_subdev_format *fmt) +static int vsp1_rwpf_set_format(struct v4l2_subdev *subdev, + struct v4l2_subdev_pad_config *cfg, + struct v4l2_subdev_format *fmt) { struct vsp1_rwpf *rwpf = to_rwpf(subdev); + struct v4l2_subdev_pad_config *config; struct v4l2_mbus_framefmt *format; struct v4l2_rect *crop; + config = vsp1_entity_get_pad_config(&rwpf->entity, cfg, fmt->which); + if (!config) + return -EINVAL; + /* Default to YUV if the requested format is not supported. */ if (fmt->format.code != MEDIA_BUS_FMT_ARGB8888_1X32 && fmt->format.code != MEDIA_BUS_FMT_AYUV8_1X32) fmt->format.code = MEDIA_BUS_FMT_AYUV8_1X32; - format = vsp1_entity_get_pad_format(&rwpf->entity, cfg, fmt->pad, - fmt->which); + format = vsp1_entity_get_pad_format(&rwpf->entity, config, fmt->pad); if (fmt->pad == RWPF_PAD_SOURCE) { /* The RWPF performs format conversion but can't scale, only the @@ -131,39 +99,44 @@ int vsp1_rwpf_set_format(struct v4l2_subdev *subdev, struct v4l2_subdev_pad_conf fmt->format = *format; /* Update the sink crop rectangle. */ - crop = vsp1_rwpf_get_crop(rwpf, cfg, fmt->which); + crop = vsp1_rwpf_get_crop(rwpf, config); crop->left = 0; crop->top = 0; crop->width = fmt->format.width; crop->height = fmt->format.height; /* Propagate the format to the source pad. */ - format = vsp1_entity_get_pad_format(&rwpf->entity, cfg, RWPF_PAD_SOURCE, - fmt->which); + format = vsp1_entity_get_pad_format(&rwpf->entity, config, + RWPF_PAD_SOURCE); *format = fmt->format; return 0; } -int vsp1_rwpf_get_selection(struct v4l2_subdev *subdev, - struct v4l2_subdev_pad_config *cfg, - struct v4l2_subdev_selection *sel) +static int vsp1_rwpf_get_selection(struct v4l2_subdev *subdev, + struct v4l2_subdev_pad_config *cfg, + struct v4l2_subdev_selection *sel) { struct vsp1_rwpf *rwpf = to_rwpf(subdev); + struct v4l2_subdev_pad_config *config; struct v4l2_mbus_framefmt *format; /* Cropping is implemented on the sink pad. */ if (sel->pad != RWPF_PAD_SINK) return -EINVAL; + config = vsp1_entity_get_pad_config(&rwpf->entity, cfg, sel->which); + if (!config) + return -EINVAL; + switch (sel->target) { case V4L2_SEL_TGT_CROP: - sel->r = *vsp1_rwpf_get_crop(rwpf, cfg, sel->which); + sel->r = *vsp1_rwpf_get_crop(rwpf, config); break; case V4L2_SEL_TGT_CROP_BOUNDS: - format = vsp1_entity_get_pad_format(&rwpf->entity, cfg, - RWPF_PAD_SINK, sel->which); + format = vsp1_entity_get_pad_format(&rwpf->entity, config, + RWPF_PAD_SINK); sel->r.left = 0; sel->r.top = 0; sel->r.width = format->width; @@ -177,11 +150,12 @@ int vsp1_rwpf_get_selection(struct v4l2_subdev *subdev, return 0; } -int vsp1_rwpf_set_selection(struct v4l2_subdev *subdev, - struct v4l2_subdev_pad_config *cfg, - struct v4l2_subdev_selection *sel) +static int vsp1_rwpf_set_selection(struct v4l2_subdev *subdev, + struct v4l2_subdev_pad_config *cfg, + struct v4l2_subdev_selection *sel) { struct vsp1_rwpf *rwpf = to_rwpf(subdev); + struct v4l2_subdev_pad_config *config; struct v4l2_mbus_framefmt *format; struct v4l2_rect *crop; @@ -192,11 +166,15 @@ int vsp1_rwpf_set_selection(struct v4l2_subdev *subdev, if (sel->target != V4L2_SEL_TGT_CROP) return -EINVAL; + config = vsp1_entity_get_pad_config(&rwpf->entity, cfg, sel->which); + if (!config) + return -EINVAL; + /* Make sure the crop rectangle is entirely contained in the image. The * WPF top and left offsets are limited to 255. */ - format = vsp1_entity_get_pad_format(&rwpf->entity, cfg, RWPF_PAD_SINK, - sel->which); + format = vsp1_entity_get_pad_format(&rwpf->entity, config, + RWPF_PAD_SINK); /* Restrict the crop rectangle coordinates to multiples of 2 to avoid * shifting the color plane. @@ -219,14 +197,59 @@ int vsp1_rwpf_set_selection(struct v4l2_subdev *subdev, sel->r.height = min_t(unsigned int, sel->r.height, format->height - sel->r.top); - crop = vsp1_rwpf_get_crop(rwpf, cfg, sel->which); + crop = vsp1_rwpf_get_crop(rwpf, config); *crop = sel->r; /* Propagate the format to the source pad. */ - format = vsp1_entity_get_pad_format(&rwpf->entity, cfg, RWPF_PAD_SOURCE, - sel->which); + format = vsp1_entity_get_pad_format(&rwpf->entity, config, + RWPF_PAD_SOURCE); format->width = crop->width; format->height = crop->height; return 0; } + +const struct v4l2_subdev_pad_ops vsp1_rwpf_pad_ops = { + .init_cfg = vsp1_entity_init_cfg, + .enum_mbus_code = vsp1_rwpf_enum_mbus_code, + .enum_frame_size = vsp1_rwpf_enum_frame_size, + .get_fmt = vsp1_subdev_get_pad_format, + .set_fmt = vsp1_rwpf_set_format, + .get_selection = vsp1_rwpf_get_selection, + .set_selection = vsp1_rwpf_set_selection, +}; + +/* ----------------------------------------------------------------------------- + * Controls + */ + +static int vsp1_rwpf_s_ctrl(struct v4l2_ctrl *ctrl) +{ + struct vsp1_rwpf *rwpf = + container_of(ctrl->handler, struct vsp1_rwpf, ctrls); + + switch (ctrl->id) { + case V4L2_CID_ALPHA_COMPONENT: + rwpf->alpha = ctrl->val; + break; + } + + return 0; +} + +static const struct v4l2_ctrl_ops vsp1_rwpf_ctrl_ops = { + .s_ctrl = vsp1_rwpf_s_ctrl, +}; + +int vsp1_rwpf_init_ctrls(struct vsp1_rwpf *rwpf) +{ + rwpf->alpha = 255; + + v4l2_ctrl_handler_init(&rwpf->ctrls, 1); + v4l2_ctrl_new_std(&rwpf->ctrls, &vsp1_rwpf_ctrl_ops, + V4L2_CID_ALPHA_COMPONENT, 0, 255, 1, 255); + + rwpf->entity.subdev.ctrl_handler = &rwpf->ctrls; + + return rwpf->ctrls.error; +} diff --git a/drivers/media/platform/vsp1/vsp1_rwpf.h b/drivers/media/platform/vsp1/vsp1_rwpf.h index 8e8235682..9ff7c78f2 100644 --- a/drivers/media/platform/vsp1/vsp1_rwpf.h +++ b/drivers/media/platform/vsp1/vsp1_rwpf.h @@ -24,42 +24,35 @@ #define RWPF_PAD_SOURCE 1 struct v4l2_ctrl; +struct vsp1_dl_manager; +struct vsp1_pipeline; struct vsp1_rwpf; struct vsp1_video; struct vsp1_rwpf_memory { - unsigned int num_planes; dma_addr_t addr[3]; - unsigned int length[3]; -}; - -struct vsp1_rwpf_operations { - void (*set_memory)(struct vsp1_rwpf *rwpf, - struct vsp1_rwpf_memory *mem); }; struct vsp1_rwpf { struct vsp1_entity entity; struct v4l2_ctrl_handler ctrls; - struct v4l2_ctrl *alpha; + struct vsp1_pipeline *pipe; struct vsp1_video *video; - const struct vsp1_rwpf_operations *ops; - unsigned int max_width; unsigned int max_height; struct v4l2_pix_format_mplane format; const struct vsp1_format_info *fmtinfo; - struct { - unsigned int left; - unsigned int top; - } location; - struct v4l2_rect crop; + unsigned int bru_input; + + unsigned int alpha; unsigned int offsets[2]; - dma_addr_t buf_addr[3]; + struct vsp1_rwpf_memory mem; + + struct vsp1_dl_manager *dlm; }; static inline struct vsp1_rwpf *to_rwpf(struct v4l2_subdev *subdev) @@ -67,24 +60,31 @@ static inline struct vsp1_rwpf *to_rwpf(struct v4l2_subdev *subdev) return container_of(subdev, struct vsp1_rwpf, entity.subdev); } +static inline struct vsp1_rwpf *entity_to_rwpf(struct vsp1_entity *entity) +{ + return container_of(entity, struct vsp1_rwpf, entity); +} + struct vsp1_rwpf *vsp1_rpf_create(struct vsp1_device *vsp1, unsigned int index); struct vsp1_rwpf *vsp1_wpf_create(struct vsp1_device *vsp1, unsigned int index); -int vsp1_rwpf_enum_mbus_code(struct v4l2_subdev *subdev, - struct v4l2_subdev_pad_config *cfg, - struct v4l2_subdev_mbus_code_enum *code); -int vsp1_rwpf_enum_frame_size(struct v4l2_subdev *subdev, - struct v4l2_subdev_pad_config *cfg, - struct v4l2_subdev_frame_size_enum *fse); -int vsp1_rwpf_get_format(struct v4l2_subdev *subdev, struct v4l2_subdev_pad_config *cfg, - struct v4l2_subdev_format *fmt); -int vsp1_rwpf_set_format(struct v4l2_subdev *subdev, struct v4l2_subdev_pad_config *cfg, - struct v4l2_subdev_format *fmt); -int vsp1_rwpf_get_selection(struct v4l2_subdev *subdev, - struct v4l2_subdev_pad_config *cfg, - struct v4l2_subdev_selection *sel); -int vsp1_rwpf_set_selection(struct v4l2_subdev *subdev, - struct v4l2_subdev_pad_config *cfg, - struct v4l2_subdev_selection *sel); +int vsp1_rwpf_init_ctrls(struct vsp1_rwpf *rwpf); + +extern const struct v4l2_subdev_pad_ops vsp1_rwpf_pad_ops; + +struct v4l2_rect *vsp1_rwpf_get_crop(struct vsp1_rwpf *rwpf, + struct v4l2_subdev_pad_config *config); +/** + * vsp1_rwpf_set_memory - Configure DMA addresses for a [RW]PF + * @rwpf: the [RW]PF instance + * @dl: the display list + * + * This function applies the cached memory buffer address to the display list. + */ +static inline void vsp1_rwpf_set_memory(struct vsp1_rwpf *rwpf, + struct vsp1_dl_list *dl) +{ + rwpf->entity.ops->set_memory(&rwpf->entity, dl); +} #endif /* __VSP1_RWPF_H__ */ diff --git a/drivers/media/platform/vsp1/vsp1_sru.c b/drivers/media/platform/vsp1/vsp1_sru.c index cc09efbfb..97ef997ae 100644 --- a/drivers/media/platform/vsp1/vsp1_sru.c +++ b/drivers/media/platform/vsp1/vsp1_sru.c @@ -17,6 +17,7 @@ #include <media/v4l2-subdev.h> #include "vsp1.h" +#include "vsp1_dl.h" #include "vsp1_sru.h" #define SRU_MIN_SIZE 4U @@ -26,14 +27,10 @@ * Device Access */ -static inline u32 vsp1_sru_read(struct vsp1_sru *sru, u32 reg) +static inline void vsp1_sru_write(struct vsp1_sru *sru, struct vsp1_dl_list *dl, + u32 reg, u32 data) { - return vsp1_read(sru->entity.vsp1, reg); -} - -static inline void vsp1_sru_write(struct vsp1_sru *sru, u32 reg, u32 data) -{ - vsp1_write(sru->entity.vsp1, reg, data); + vsp1_dl_list_write(dl, reg, data); } /* ----------------------------------------------------------------------------- @@ -82,20 +79,10 @@ static int sru_s_ctrl(struct v4l2_ctrl *ctrl) { struct vsp1_sru *sru = container_of(ctrl->handler, struct vsp1_sru, ctrls); - const struct vsp1_sru_param *param; - u32 value; switch (ctrl->id) { case V4L2_CID_VSP1_SRU_INTENSITY: - param = &vsp1_sru_params[ctrl->val - 1]; - - value = vsp1_sru_read(sru, VI6_SRU_CTRL0); - value &= ~(VI6_SRU_CTRL0_PARAM0_MASK | - VI6_SRU_CTRL0_PARAM1_MASK); - value |= param->ctrl0; - vsp1_sru_write(sru, VI6_SRU_CTRL0, value); - - vsp1_sru_write(sru, VI6_SRU_CTRL2, param->ctrl2); + sru->intensity = ctrl->val; break; } @@ -118,54 +105,7 @@ static const struct v4l2_ctrl_config sru_intensity_control = { }; /* ----------------------------------------------------------------------------- - * V4L2 Subdevice Core Operations - */ - -static int sru_s_stream(struct v4l2_subdev *subdev, int enable) -{ - struct vsp1_sru *sru = to_sru(subdev); - struct v4l2_mbus_framefmt *input; - struct v4l2_mbus_framefmt *output; - u32 ctrl0; - int ret; - - ret = vsp1_entity_set_streaming(&sru->entity, enable); - if (ret < 0) - return ret; - - if (!enable) - return 0; - - input = &sru->entity.formats[SRU_PAD_SINK]; - output = &sru->entity.formats[SRU_PAD_SOURCE]; - - if (input->code == MEDIA_BUS_FMT_ARGB8888_1X32) - ctrl0 = VI6_SRU_CTRL0_PARAM2 | VI6_SRU_CTRL0_PARAM3 - | VI6_SRU_CTRL0_PARAM4; - else - ctrl0 = VI6_SRU_CTRL0_PARAM3; - - if (input->width != output->width) - ctrl0 |= VI6_SRU_CTRL0_MODE_UPSCALE; - - /* Take the control handler lock to ensure that the CTRL0 value won't be - * changed behind our back by a set control operation. - */ - if (sru->entity.vsp1->info->uapi) - mutex_lock(sru->ctrls.lock); - ctrl0 |= vsp1_sru_read(sru, VI6_SRU_CTRL0) - & (VI6_SRU_CTRL0_PARAM0_MASK | VI6_SRU_CTRL0_PARAM1_MASK); - vsp1_sru_write(sru, VI6_SRU_CTRL0, ctrl0); - if (sru->entity.vsp1->info->uapi) - mutex_unlock(sru->ctrls.lock); - - vsp1_sru_write(sru, VI6_SRU_CTRL1, VI6_SRU_CTRL1_PARAM5); - - return 0; -} - -/* ----------------------------------------------------------------------------- - * V4L2 Subdevice Pad Operations + * V4L2 Subdevice Operations */ static int sru_enum_mbus_code(struct v4l2_subdev *subdev, @@ -176,27 +116,9 @@ static int sru_enum_mbus_code(struct v4l2_subdev *subdev, MEDIA_BUS_FMT_ARGB8888_1X32, MEDIA_BUS_FMT_AYUV8_1X32, }; - struct vsp1_sru *sru = to_sru(subdev); - struct v4l2_mbus_framefmt *format; - - if (code->pad == SRU_PAD_SINK) { - if (code->index >= ARRAY_SIZE(codes)) - return -EINVAL; - - code->code = codes[code->index]; - } else { - /* The SRU can't perform format conversion, the sink format is - * always identical to the source format. - */ - if (code->index) - return -EINVAL; - format = vsp1_entity_get_pad_format(&sru->entity, cfg, - SRU_PAD_SINK, code->which); - code->code = format->code; - } - - return 0; + return vsp1_subdev_enum_mbus_code(subdev, cfg, code, codes, + ARRAY_SIZE(codes)); } static int sru_enum_frame_size(struct v4l2_subdev *subdev, @@ -204,10 +126,14 @@ static int sru_enum_frame_size(struct v4l2_subdev *subdev, struct v4l2_subdev_frame_size_enum *fse) { struct vsp1_sru *sru = to_sru(subdev); + struct v4l2_subdev_pad_config *config; struct v4l2_mbus_framefmt *format; - format = vsp1_entity_get_pad_format(&sru->entity, cfg, - SRU_PAD_SINK, fse->which); + config = vsp1_entity_get_pad_config(&sru->entity, cfg, fse->which); + if (!config) + return -EINVAL; + + format = vsp1_entity_get_pad_format(&sru->entity, config, SRU_PAD_SINK); if (fse->index || fse->code != format->code) return -EINVAL; @@ -233,20 +159,9 @@ static int sru_enum_frame_size(struct v4l2_subdev *subdev, return 0; } -static int sru_get_format(struct v4l2_subdev *subdev, struct v4l2_subdev_pad_config *cfg, - struct v4l2_subdev_format *fmt) -{ - struct vsp1_sru *sru = to_sru(subdev); - - fmt->format = *vsp1_entity_get_pad_format(&sru->entity, cfg, fmt->pad, - fmt->which); - - return 0; -} - -static void sru_try_format(struct vsp1_sru *sru, struct v4l2_subdev_pad_config *cfg, - unsigned int pad, struct v4l2_mbus_framefmt *fmt, - enum v4l2_subdev_format_whence which) +static void sru_try_format(struct vsp1_sru *sru, + struct v4l2_subdev_pad_config *config, + unsigned int pad, struct v4l2_mbus_framefmt *fmt) { struct v4l2_mbus_framefmt *format; unsigned int input_area; @@ -265,8 +180,8 @@ static void sru_try_format(struct vsp1_sru *sru, struct v4l2_subdev_pad_config * case SRU_PAD_SOURCE: /* The SRU can't perform format conversion. */ - format = vsp1_entity_get_pad_format(&sru->entity, cfg, - SRU_PAD_SINK, which); + format = vsp1_entity_get_pad_format(&sru->entity, config, + SRU_PAD_SINK); fmt->code = format->code; /* We can upscale by 2 in both direction, but not independently. @@ -295,57 +210,94 @@ static void sru_try_format(struct vsp1_sru *sru, struct v4l2_subdev_pad_config * fmt->colorspace = V4L2_COLORSPACE_SRGB; } -static int sru_set_format(struct v4l2_subdev *subdev, struct v4l2_subdev_pad_config *cfg, +static int sru_set_format(struct v4l2_subdev *subdev, + struct v4l2_subdev_pad_config *cfg, struct v4l2_subdev_format *fmt) { struct vsp1_sru *sru = to_sru(subdev); + struct v4l2_subdev_pad_config *config; struct v4l2_mbus_framefmt *format; - sru_try_format(sru, cfg, fmt->pad, &fmt->format, fmt->which); + config = vsp1_entity_get_pad_config(&sru->entity, cfg, fmt->which); + if (!config) + return -EINVAL; + + sru_try_format(sru, config, fmt->pad, &fmt->format); - format = vsp1_entity_get_pad_format(&sru->entity, cfg, fmt->pad, - fmt->which); + format = vsp1_entity_get_pad_format(&sru->entity, config, fmt->pad); *format = fmt->format; if (fmt->pad == SRU_PAD_SINK) { /* Propagate the format to the source pad. */ - format = vsp1_entity_get_pad_format(&sru->entity, cfg, - SRU_PAD_SOURCE, fmt->which); + format = vsp1_entity_get_pad_format(&sru->entity, config, + SRU_PAD_SOURCE); *format = fmt->format; - sru_try_format(sru, cfg, SRU_PAD_SOURCE, format, fmt->which); + sru_try_format(sru, config, SRU_PAD_SOURCE, format); } return 0; } -/* ----------------------------------------------------------------------------- - * V4L2 Subdevice Operations - */ - -static struct v4l2_subdev_video_ops sru_video_ops = { - .s_stream = sru_s_stream, -}; - static struct v4l2_subdev_pad_ops sru_pad_ops = { + .init_cfg = vsp1_entity_init_cfg, .enum_mbus_code = sru_enum_mbus_code, .enum_frame_size = sru_enum_frame_size, - .get_fmt = sru_get_format, + .get_fmt = vsp1_subdev_get_pad_format, .set_fmt = sru_set_format, }; static struct v4l2_subdev_ops sru_ops = { - .video = &sru_video_ops, .pad = &sru_pad_ops, }; /* ----------------------------------------------------------------------------- + * VSP1 Entity Operations + */ + +static void sru_configure(struct vsp1_entity *entity, + struct vsp1_pipeline *pipe, + struct vsp1_dl_list *dl) +{ + const struct vsp1_sru_param *param; + struct vsp1_sru *sru = to_sru(&entity->subdev); + struct v4l2_mbus_framefmt *input; + struct v4l2_mbus_framefmt *output; + u32 ctrl0; + + input = vsp1_entity_get_pad_format(&sru->entity, sru->entity.config, + SRU_PAD_SINK); + output = vsp1_entity_get_pad_format(&sru->entity, sru->entity.config, + SRU_PAD_SOURCE); + + if (input->code == MEDIA_BUS_FMT_ARGB8888_1X32) + ctrl0 = VI6_SRU_CTRL0_PARAM2 | VI6_SRU_CTRL0_PARAM3 + | VI6_SRU_CTRL0_PARAM4; + else + ctrl0 = VI6_SRU_CTRL0_PARAM3; + + if (input->width != output->width) + ctrl0 |= VI6_SRU_CTRL0_MODE_UPSCALE; + + param = &vsp1_sru_params[sru->intensity - 1]; + + ctrl0 |= param->ctrl0; + + vsp1_sru_write(sru, dl, VI6_SRU_CTRL0, ctrl0); + vsp1_sru_write(sru, dl, VI6_SRU_CTRL1, VI6_SRU_CTRL1_PARAM5); + vsp1_sru_write(sru, dl, VI6_SRU_CTRL2, param->ctrl2); +} + +static const struct vsp1_entity_operations sru_entity_ops = { + .configure = sru_configure, +}; + +/* ----------------------------------------------------------------------------- * Initialization and Cleanup */ struct vsp1_sru *vsp1_sru_create(struct vsp1_device *vsp1) { - struct v4l2_subdev *subdev; struct vsp1_sru *sru; int ret; @@ -353,29 +305,19 @@ struct vsp1_sru *vsp1_sru_create(struct vsp1_device *vsp1) if (sru == NULL) return ERR_PTR(-ENOMEM); + sru->entity.ops = &sru_entity_ops; sru->entity.type = VSP1_ENTITY_SRU; - ret = vsp1_entity_init(vsp1, &sru->entity, 2); + ret = vsp1_entity_init(vsp1, &sru->entity, "sru", 2, &sru_ops); if (ret < 0) return ERR_PTR(ret); - /* Initialize the V4L2 subdev. */ - subdev = &sru->entity.subdev; - v4l2_subdev_init(subdev, &sru_ops); - - subdev->entity.ops = &vsp1->media_ops; - subdev->internal_ops = &vsp1_subdev_internal_ops; - snprintf(subdev->name, sizeof(subdev->name), "%s sru", - dev_name(vsp1->dev)); - v4l2_set_subdevdata(subdev, sru); - subdev->flags |= V4L2_SUBDEV_FL_HAS_DEVNODE; - - vsp1_entity_init_formats(subdev, NULL); - /* Initialize the control handler. */ v4l2_ctrl_handler_init(&sru->ctrls, 1); v4l2_ctrl_new_custom(&sru->ctrls, &sru_intensity_control, NULL); + sru->intensity = 1; + sru->entity.subdev.ctrl_handler = &sru->ctrls; if (sru->ctrls.error) { diff --git a/drivers/media/platform/vsp1/vsp1_sru.h b/drivers/media/platform/vsp1/vsp1_sru.h index b6768bf3d..85e241457 100644 --- a/drivers/media/platform/vsp1/vsp1_sru.h +++ b/drivers/media/platform/vsp1/vsp1_sru.h @@ -28,6 +28,8 @@ struct vsp1_sru { struct vsp1_entity entity; struct v4l2_ctrl_handler ctrls; + + unsigned int intensity; }; static inline struct vsp1_sru *to_sru(struct v4l2_subdev *subdev) diff --git a/drivers/media/platform/vsp1/vsp1_uds.c b/drivers/media/platform/vsp1/vsp1_uds.c index bba67770c..1875e29da 100644 --- a/drivers/media/platform/vsp1/vsp1_uds.c +++ b/drivers/media/platform/vsp1/vsp1_uds.c @@ -17,6 +17,7 @@ #include <media/v4l2-subdev.h> #include "vsp1.h" +#include "vsp1_dl.h" #include "vsp1_uds.h" #define UDS_MIN_SIZE 4U @@ -29,19 +30,21 @@ * Device Access */ -static inline void vsp1_uds_write(struct vsp1_uds *uds, u32 reg, u32 data) +static inline void vsp1_uds_write(struct vsp1_uds *uds, struct vsp1_dl_list *dl, + u32 reg, u32 data) { - vsp1_write(uds->entity.vsp1, - reg + uds->entity.index * VI6_UDS_OFFSET, data); + vsp1_dl_list_write(dl, reg + uds->entity.index * VI6_UDS_OFFSET, data); } /* ----------------------------------------------------------------------------- * Scaling Computation */ -void vsp1_uds_set_alpha(struct vsp1_uds *uds, unsigned int alpha) +void vsp1_uds_set_alpha(struct vsp1_uds *uds, struct vsp1_dl_list *dl, + unsigned int alpha) { - vsp1_uds_write(uds, VI6_UDS_ALPVAL, alpha << VI6_UDS_ALPVAL_VAL0_SHIFT); + vsp1_uds_write(uds, dl, VI6_UDS_ALPVAL, + alpha << VI6_UDS_ALPVAL_VAL0_SHIFT); } /* @@ -105,60 +108,6 @@ static unsigned int uds_compute_ratio(unsigned int input, unsigned int output) } /* ----------------------------------------------------------------------------- - * V4L2 Subdevice Core Operations - */ - -static int uds_s_stream(struct v4l2_subdev *subdev, int enable) -{ - struct vsp1_uds *uds = to_uds(subdev); - const struct v4l2_mbus_framefmt *output; - const struct v4l2_mbus_framefmt *input; - unsigned int hscale; - unsigned int vscale; - bool multitap; - - if (!enable) - return 0; - - input = &uds->entity.formats[UDS_PAD_SINK]; - output = &uds->entity.formats[UDS_PAD_SOURCE]; - - hscale = uds_compute_ratio(input->width, output->width); - vscale = uds_compute_ratio(input->height, output->height); - - dev_dbg(uds->entity.vsp1->dev, "hscale %u vscale %u\n", hscale, vscale); - - /* Multi-tap scaling can't be enabled along with alpha scaling when - * scaling down with a factor lower than or equal to 1/2 in either - * direction. - */ - if (uds->scale_alpha && (hscale >= 8192 || vscale >= 8192)) - multitap = false; - else - multitap = true; - - vsp1_uds_write(uds, VI6_UDS_CTRL, - (uds->scale_alpha ? VI6_UDS_CTRL_AON : 0) | - (multitap ? VI6_UDS_CTRL_BC : 0)); - - vsp1_uds_write(uds, VI6_UDS_PASS_BWIDTH, - (uds_passband_width(hscale) - << VI6_UDS_PASS_BWIDTH_H_SHIFT) | - (uds_passband_width(vscale) - << VI6_UDS_PASS_BWIDTH_V_SHIFT)); - - /* Set the scaling ratios and the output size. */ - vsp1_uds_write(uds, VI6_UDS_SCALE, - (hscale << VI6_UDS_SCALE_HFRAC_SHIFT) | - (vscale << VI6_UDS_SCALE_VFRAC_SHIFT)); - vsp1_uds_write(uds, VI6_UDS_CLIP_SIZE, - (output->width << VI6_UDS_CLIP_SIZE_HSIZE_SHIFT) | - (output->height << VI6_UDS_CLIP_SIZE_VSIZE_SHIFT)); - - return 0; -} - -/* ----------------------------------------------------------------------------- * V4L2 Subdevice Pad Operations */ @@ -170,28 +119,9 @@ static int uds_enum_mbus_code(struct v4l2_subdev *subdev, MEDIA_BUS_FMT_ARGB8888_1X32, MEDIA_BUS_FMT_AYUV8_1X32, }; - struct vsp1_uds *uds = to_uds(subdev); - - if (code->pad == UDS_PAD_SINK) { - if (code->index >= ARRAY_SIZE(codes)) - return -EINVAL; - - code->code = codes[code->index]; - } else { - struct v4l2_mbus_framefmt *format; - - /* The UDS can't perform format conversion, the sink format is - * always identical to the source format. - */ - if (code->index) - return -EINVAL; - format = vsp1_entity_get_pad_format(&uds->entity, cfg, - UDS_PAD_SINK, code->which); - code->code = format->code; - } - - return 0; + return vsp1_subdev_enum_mbus_code(subdev, cfg, code, codes, + ARRAY_SIZE(codes)); } static int uds_enum_frame_size(struct v4l2_subdev *subdev, @@ -199,10 +129,15 @@ static int uds_enum_frame_size(struct v4l2_subdev *subdev, struct v4l2_subdev_frame_size_enum *fse) { struct vsp1_uds *uds = to_uds(subdev); + struct v4l2_subdev_pad_config *config; struct v4l2_mbus_framefmt *format; - format = vsp1_entity_get_pad_format(&uds->entity, cfg, - UDS_PAD_SINK, fse->which); + config = vsp1_entity_get_pad_config(&uds->entity, cfg, fse->which); + if (!config) + return -EINVAL; + + format = vsp1_entity_get_pad_format(&uds->entity, config, + UDS_PAD_SINK); if (fse->index || fse->code != format->code) return -EINVAL; @@ -222,20 +157,9 @@ static int uds_enum_frame_size(struct v4l2_subdev *subdev, return 0; } -static int uds_get_format(struct v4l2_subdev *subdev, struct v4l2_subdev_pad_config *cfg, - struct v4l2_subdev_format *fmt) -{ - struct vsp1_uds *uds = to_uds(subdev); - - fmt->format = *vsp1_entity_get_pad_format(&uds->entity, cfg, fmt->pad, - fmt->which); - - return 0; -} - -static void uds_try_format(struct vsp1_uds *uds, struct v4l2_subdev_pad_config *cfg, - unsigned int pad, struct v4l2_mbus_framefmt *fmt, - enum v4l2_subdev_format_whence which) +static void uds_try_format(struct vsp1_uds *uds, + struct v4l2_subdev_pad_config *config, + unsigned int pad, struct v4l2_mbus_framefmt *fmt) { struct v4l2_mbus_framefmt *format; unsigned int minimum; @@ -254,8 +178,8 @@ static void uds_try_format(struct vsp1_uds *uds, struct v4l2_subdev_pad_config * case UDS_PAD_SOURCE: /* The UDS scales but can't perform format conversion. */ - format = vsp1_entity_get_pad_format(&uds->entity, cfg, - UDS_PAD_SINK, which); + format = vsp1_entity_get_pad_format(&uds->entity, config, + UDS_PAD_SINK); fmt->code = format->code; uds_output_limits(format->width, &minimum, &maximum); @@ -269,25 +193,30 @@ static void uds_try_format(struct vsp1_uds *uds, struct v4l2_subdev_pad_config * fmt->colorspace = V4L2_COLORSPACE_SRGB; } -static int uds_set_format(struct v4l2_subdev *subdev, struct v4l2_subdev_pad_config *cfg, +static int uds_set_format(struct v4l2_subdev *subdev, + struct v4l2_subdev_pad_config *cfg, struct v4l2_subdev_format *fmt) { struct vsp1_uds *uds = to_uds(subdev); + struct v4l2_subdev_pad_config *config; struct v4l2_mbus_framefmt *format; - uds_try_format(uds, cfg, fmt->pad, &fmt->format, fmt->which); + config = vsp1_entity_get_pad_config(&uds->entity, cfg, fmt->which); + if (!config) + return -EINVAL; + + uds_try_format(uds, config, fmt->pad, &fmt->format); - format = vsp1_entity_get_pad_format(&uds->entity, cfg, fmt->pad, - fmt->which); + format = vsp1_entity_get_pad_format(&uds->entity, config, fmt->pad); *format = fmt->format; if (fmt->pad == UDS_PAD_SINK) { /* Propagate the format to the source pad. */ - format = vsp1_entity_get_pad_format(&uds->entity, cfg, - UDS_PAD_SOURCE, fmt->which); + format = vsp1_entity_get_pad_format(&uds->entity, config, + UDS_PAD_SOURCE); *format = fmt->format; - uds_try_format(uds, cfg, UDS_PAD_SOURCE, format, fmt->which); + uds_try_format(uds, config, UDS_PAD_SOURCE, format); } return 0; @@ -297,55 +226,97 @@ static int uds_set_format(struct v4l2_subdev *subdev, struct v4l2_subdev_pad_con * V4L2 Subdevice Operations */ -static struct v4l2_subdev_video_ops uds_video_ops = { - .s_stream = uds_s_stream, -}; - static struct v4l2_subdev_pad_ops uds_pad_ops = { + .init_cfg = vsp1_entity_init_cfg, .enum_mbus_code = uds_enum_mbus_code, .enum_frame_size = uds_enum_frame_size, - .get_fmt = uds_get_format, + .get_fmt = vsp1_subdev_get_pad_format, .set_fmt = uds_set_format, }; static struct v4l2_subdev_ops uds_ops = { - .video = &uds_video_ops, .pad = &uds_pad_ops, }; /* ----------------------------------------------------------------------------- + * VSP1 Entity Operations + */ + +static void uds_configure(struct vsp1_entity *entity, + struct vsp1_pipeline *pipe, + struct vsp1_dl_list *dl) +{ + struct vsp1_uds *uds = to_uds(&entity->subdev); + const struct v4l2_mbus_framefmt *output; + const struct v4l2_mbus_framefmt *input; + unsigned int hscale; + unsigned int vscale; + bool multitap; + + input = vsp1_entity_get_pad_format(&uds->entity, uds->entity.config, + UDS_PAD_SINK); + output = vsp1_entity_get_pad_format(&uds->entity, uds->entity.config, + UDS_PAD_SOURCE); + + hscale = uds_compute_ratio(input->width, output->width); + vscale = uds_compute_ratio(input->height, output->height); + + dev_dbg(uds->entity.vsp1->dev, "hscale %u vscale %u\n", hscale, vscale); + + /* Multi-tap scaling can't be enabled along with alpha scaling when + * scaling down with a factor lower than or equal to 1/2 in either + * direction. + */ + if (uds->scale_alpha && (hscale >= 8192 || vscale >= 8192)) + multitap = false; + else + multitap = true; + + vsp1_uds_write(uds, dl, VI6_UDS_CTRL, + (uds->scale_alpha ? VI6_UDS_CTRL_AON : 0) | + (multitap ? VI6_UDS_CTRL_BC : 0)); + + vsp1_uds_write(uds, dl, VI6_UDS_PASS_BWIDTH, + (uds_passband_width(hscale) + << VI6_UDS_PASS_BWIDTH_H_SHIFT) | + (uds_passband_width(vscale) + << VI6_UDS_PASS_BWIDTH_V_SHIFT)); + + /* Set the scaling ratios and the output size. */ + vsp1_uds_write(uds, dl, VI6_UDS_SCALE, + (hscale << VI6_UDS_SCALE_HFRAC_SHIFT) | + (vscale << VI6_UDS_SCALE_VFRAC_SHIFT)); + vsp1_uds_write(uds, dl, VI6_UDS_CLIP_SIZE, + (output->width << VI6_UDS_CLIP_SIZE_HSIZE_SHIFT) | + (output->height << VI6_UDS_CLIP_SIZE_VSIZE_SHIFT)); +} + +static const struct vsp1_entity_operations uds_entity_ops = { + .configure = uds_configure, +}; + +/* ----------------------------------------------------------------------------- * Initialization and Cleanup */ struct vsp1_uds *vsp1_uds_create(struct vsp1_device *vsp1, unsigned int index) { - struct v4l2_subdev *subdev; struct vsp1_uds *uds; + char name[6]; int ret; uds = devm_kzalloc(vsp1->dev, sizeof(*uds), GFP_KERNEL); if (uds == NULL) return ERR_PTR(-ENOMEM); + uds->entity.ops = &uds_entity_ops; uds->entity.type = VSP1_ENTITY_UDS; uds->entity.index = index; - ret = vsp1_entity_init(vsp1, &uds->entity, 2); + sprintf(name, "uds.%u", index); + ret = vsp1_entity_init(vsp1, &uds->entity, name, 2, &uds_ops); if (ret < 0) return ERR_PTR(ret); - /* Initialize the V4L2 subdev. */ - subdev = &uds->entity.subdev; - v4l2_subdev_init(subdev, &uds_ops); - - subdev->entity.ops = &vsp1->media_ops; - subdev->internal_ops = &vsp1_subdev_internal_ops; - snprintf(subdev->name, sizeof(subdev->name), "%s uds.%u", - dev_name(vsp1->dev), index); - v4l2_set_subdevdata(subdev, uds); - subdev->flags |= V4L2_SUBDEV_FL_HAS_DEVNODE; - - vsp1_entity_init_formats(subdev, NULL); - return uds; } diff --git a/drivers/media/platform/vsp1/vsp1_uds.h b/drivers/media/platform/vsp1/vsp1_uds.h index 031ac0da1..5c8cbfcad 100644 --- a/drivers/media/platform/vsp1/vsp1_uds.h +++ b/drivers/media/platform/vsp1/vsp1_uds.h @@ -35,6 +35,7 @@ static inline struct vsp1_uds *to_uds(struct v4l2_subdev *subdev) struct vsp1_uds *vsp1_uds_create(struct vsp1_device *vsp1, unsigned int index); -void vsp1_uds_set_alpha(struct vsp1_uds *uds, unsigned int alpha); +void vsp1_uds_set_alpha(struct vsp1_uds *uds, struct vsp1_dl_list *dl, + unsigned int alpha); #endif /* __VSP1_UDS_H__ */ diff --git a/drivers/media/platform/vsp1/vsp1_video.c b/drivers/media/platform/vsp1/vsp1_video.c index 72cc7d372..a9aec5c0b 100644 --- a/drivers/media/platform/vsp1/vsp1_video.c +++ b/drivers/media/platform/vsp1/vsp1_video.c @@ -29,6 +29,7 @@ #include "vsp1.h" #include "vsp1_bru.h" +#include "vsp1_dl.h" #include "vsp1_entity.h" #include "vsp1_pipe.h" #include "vsp1_rwpf.h" @@ -171,53 +172,178 @@ static int __vsp1_video_try_format(struct vsp1_video *video, * Pipeline Management */ -static int vsp1_video_pipeline_validate_branch(struct vsp1_pipeline *pipe, - struct vsp1_rwpf *input, - struct vsp1_rwpf *output) +/* + * vsp1_video_complete_buffer - Complete the current buffer + * @video: the video node + * + * This function completes the current buffer by filling its sequence number, + * time stamp and payload size, and hands it back to the videobuf core. + * + * When operating in DU output mode (deep pipeline to the DU through the LIF), + * the VSP1 needs to constantly supply frames to the display. In that case, if + * no other buffer is queued, reuse the one that has just been processed instead + * of handing it back to the videobuf core. + * + * Return the next queued buffer or NULL if the queue is empty. + */ +static struct vsp1_vb2_buffer * +vsp1_video_complete_buffer(struct vsp1_video *video) +{ + struct vsp1_pipeline *pipe = video->rwpf->pipe; + struct vsp1_vb2_buffer *next = NULL; + struct vsp1_vb2_buffer *done; + unsigned long flags; + unsigned int i; + + spin_lock_irqsave(&video->irqlock, flags); + + if (list_empty(&video->irqqueue)) { + spin_unlock_irqrestore(&video->irqlock, flags); + return NULL; + } + + done = list_first_entry(&video->irqqueue, + struct vsp1_vb2_buffer, queue); + + /* In DU output mode reuse the buffer if the list is singular. */ + if (pipe->lif && list_is_singular(&video->irqqueue)) { + spin_unlock_irqrestore(&video->irqlock, flags); + return done; + } + + list_del(&done->queue); + + if (!list_empty(&video->irqqueue)) + next = list_first_entry(&video->irqqueue, + struct vsp1_vb2_buffer, queue); + + spin_unlock_irqrestore(&video->irqlock, flags); + + done->buf.sequence = video->sequence++; + done->buf.vb2_buf.timestamp = ktime_get_ns(); + for (i = 0; i < done->buf.vb2_buf.num_planes; ++i) + vb2_set_plane_payload(&done->buf.vb2_buf, i, + vb2_plane_size(&done->buf.vb2_buf, i)); + vb2_buffer_done(&done->buf.vb2_buf, VB2_BUF_STATE_DONE); + + return next; +} + +static void vsp1_video_frame_end(struct vsp1_pipeline *pipe, + struct vsp1_rwpf *rwpf) +{ + struct vsp1_video *video = rwpf->video; + struct vsp1_vb2_buffer *buf; + unsigned long flags; + + buf = vsp1_video_complete_buffer(video); + if (buf == NULL) + return; + + spin_lock_irqsave(&pipe->irqlock, flags); + + video->rwpf->mem = buf->mem; + pipe->buffers_ready |= 1 << video->pipe_index; + + spin_unlock_irqrestore(&pipe->irqlock, flags); +} + +static void vsp1_video_pipeline_run(struct vsp1_pipeline *pipe) +{ + struct vsp1_device *vsp1 = pipe->output->entity.vsp1; + unsigned int i; + + if (!pipe->dl) + pipe->dl = vsp1_dl_list_get(pipe->output->dlm); + + for (i = 0; i < vsp1->info->rpf_count; ++i) { + struct vsp1_rwpf *rwpf = pipe->inputs[i]; + + if (rwpf) + vsp1_rwpf_set_memory(rwpf, pipe->dl); + } + + if (!pipe->lif) + vsp1_rwpf_set_memory(pipe->output, pipe->dl); + + vsp1_dl_list_commit(pipe->dl); + pipe->dl = NULL; + + vsp1_pipeline_run(pipe); +} + +static void vsp1_video_pipeline_frame_end(struct vsp1_pipeline *pipe) +{ + struct vsp1_device *vsp1 = pipe->output->entity.vsp1; + enum vsp1_pipeline_state state; + unsigned long flags; + unsigned int i; + + /* Complete buffers on all video nodes. */ + for (i = 0; i < vsp1->info->rpf_count; ++i) { + if (!pipe->inputs[i]) + continue; + + vsp1_video_frame_end(pipe, pipe->inputs[i]); + } + + vsp1_video_frame_end(pipe, pipe->output); + + spin_lock_irqsave(&pipe->irqlock, flags); + + state = pipe->state; + pipe->state = VSP1_PIPELINE_STOPPED; + + /* If a stop has been requested, mark the pipeline as stopped and + * return. Otherwise restart the pipeline if ready. + */ + if (state == VSP1_PIPELINE_STOPPING) + wake_up(&pipe->wq); + else if (vsp1_pipeline_ready(pipe)) + vsp1_video_pipeline_run(pipe); + + spin_unlock_irqrestore(&pipe->irqlock, flags); +} + +static int vsp1_video_pipeline_build_branch(struct vsp1_pipeline *pipe, + struct vsp1_rwpf *input, + struct vsp1_rwpf *output) { - struct vsp1_entity *entity; struct media_entity_enum ent_enum; + struct vsp1_entity *entity; struct media_pad *pad; - int rval; bool bru_found = false; + int ret; - input->location.left = 0; - input->location.top = 0; - - rval = media_entity_enum_init( - &ent_enum, input->entity.pads[RWPF_PAD_SOURCE].graph_obj.mdev); - if (rval) - return rval; + ret = media_entity_enum_init(&ent_enum, &input->entity.vsp1->media_dev); + if (ret < 0) + return ret; pad = media_entity_remote_pad(&input->entity.pads[RWPF_PAD_SOURCE]); while (1) { if (pad == NULL) { - rval = -EPIPE; + ret = -EPIPE; goto out; } /* We've reached a video node, that shouldn't have happened. */ if (!is_media_entity_v4l2_subdev(pad->entity)) { - rval = -EPIPE; + ret = -EPIPE; goto out; } entity = to_vsp1_entity( media_entity_to_v4l2_subdev(pad->entity)); - /* A BRU is present in the pipeline, store the compose rectangle - * location in the input RPF for use when configuring the RPF. + /* A BRU is present in the pipeline, store the BRU input pad + * number in the input RPF for use when configuring the RPF. */ if (entity->type == VSP1_ENTITY_BRU) { struct vsp1_bru *bru = to_bru(&entity->subdev); - struct v4l2_rect *rect = - &bru->inputs[pad->index].compose; bru->inputs[pad->index].rpf = input; - - input->location.left = rect->left; - input->location.top = rect->top; + input->bru_input = pad->index; bru_found = true; } @@ -229,14 +355,14 @@ static int vsp1_video_pipeline_validate_branch(struct vsp1_pipeline *pipe, /* Ensure the branch has no loop. */ if (media_entity_enum_test_and_set(&ent_enum, &entity->subdev.entity)) { - rval = -EPIPE; + ret = -EPIPE; goto out; } /* UDS can't be chained. */ if (entity->type == VSP1_ENTITY_UDS) { if (pipe->uds) { - rval = -EPIPE; + ret = -EPIPE; goto out; } @@ -256,16 +382,16 @@ static int vsp1_video_pipeline_validate_branch(struct vsp1_pipeline *pipe, /* The last entity must be the output WPF. */ if (entity != &output->entity) - rval = -EPIPE; + ret = -EPIPE; out: media_entity_enum_cleanup(&ent_enum); - return rval; + return ret; } -static int vsp1_video_pipeline_validate(struct vsp1_pipeline *pipe, - struct vsp1_video *video) +static int vsp1_video_pipeline_build(struct vsp1_pipeline *pipe, + struct vsp1_video *video) { struct media_entity_graph graph; struct media_entity *entity = &video->video.entity; @@ -273,14 +399,10 @@ static int vsp1_video_pipeline_validate(struct vsp1_pipeline *pipe, unsigned int i; int ret; - mutex_lock(&mdev->graph_mutex); - /* Walk the graph to locate the entities and video nodes. */ ret = media_entity_graph_walk_init(&graph, mdev); - if (ret) { - mutex_unlock(&mdev->graph_mutex); + if (ret) return ret; - } media_entity_graph_walk_start(&graph, entity); @@ -300,10 +422,12 @@ static int vsp1_video_pipeline_validate(struct vsp1_pipeline *pipe, rwpf = to_rwpf(subdev); pipe->inputs[rwpf->entity.index] = rwpf; rwpf->video->pipe_index = ++pipe->num_inputs; + rwpf->pipe = pipe; } else if (e->type == VSP1_ENTITY_WPF) { rwpf = to_rwpf(subdev); pipe->output = rwpf; rwpf->video->pipe_index = 0; + rwpf->pipe = pipe; } else if (e->type == VSP1_ENTITY_LIF) { pipe->lif = e; } else if (e->type == VSP1_ENTITY_BRU) { @@ -311,15 +435,11 @@ static int vsp1_video_pipeline_validate(struct vsp1_pipeline *pipe, } } - mutex_unlock(&mdev->graph_mutex); - media_entity_graph_walk_cleanup(&graph); /* We need one output and at least one input. */ - if (pipe->num_inputs == 0 || !pipe->output) { - ret = -EPIPE; - goto error; - } + if (pipe->num_inputs == 0 || !pipe->output) + return -EPIPE; /* Follow links downstream for each input and make sure the graph * contains no loop and that all branches end at the output WPF. @@ -328,143 +448,69 @@ static int vsp1_video_pipeline_validate(struct vsp1_pipeline *pipe, if (!pipe->inputs[i]) continue; - ret = vsp1_video_pipeline_validate_branch(pipe, pipe->inputs[i], - pipe->output); + ret = vsp1_video_pipeline_build_branch(pipe, pipe->inputs[i], + pipe->output); if (ret < 0) - goto error; + return ret; } return 0; - -error: - vsp1_pipeline_reset(pipe); - return ret; } static int vsp1_video_pipeline_init(struct vsp1_pipeline *pipe, struct vsp1_video *video) { - int ret; + vsp1_pipeline_init(pipe); - mutex_lock(&pipe->lock); - - /* If we're the first user validate and initialize the pipeline. */ - if (pipe->use_count == 0) { - ret = vsp1_video_pipeline_validate(pipe, video); - if (ret < 0) - goto done; - } + pipe->frame_end = vsp1_video_pipeline_frame_end; - pipe->use_count++; - ret = 0; - -done: - mutex_unlock(&pipe->lock); - return ret; + return vsp1_video_pipeline_build(pipe, video); } -static void vsp1_video_pipeline_cleanup(struct vsp1_pipeline *pipe) -{ - mutex_lock(&pipe->lock); - - /* If we're the last user clean up the pipeline. */ - if (--pipe->use_count == 0) - vsp1_pipeline_reset(pipe); - - mutex_unlock(&pipe->lock); -} - -/* - * vsp1_video_complete_buffer - Complete the current buffer - * @video: the video node - * - * This function completes the current buffer by filling its sequence number, - * time stamp and payload size, and hands it back to the videobuf core. - * - * When operating in DU output mode (deep pipeline to the DU through the LIF), - * the VSP1 needs to constantly supply frames to the display. In that case, if - * no other buffer is queued, reuse the one that has just been processed instead - * of handing it back to the videobuf core. - * - * Return the next queued buffer or NULL if the queue is empty. - */ -static struct vsp1_vb2_buffer * -vsp1_video_complete_buffer(struct vsp1_video *video) +static struct vsp1_pipeline *vsp1_video_pipeline_get(struct vsp1_video *video) { - struct vsp1_pipeline *pipe = to_vsp1_pipeline(&video->video.entity); - struct vsp1_vb2_buffer *next = NULL; - struct vsp1_vb2_buffer *done; - unsigned long flags; - unsigned int i; - - spin_lock_irqsave(&video->irqlock, flags); - - if (list_empty(&video->irqqueue)) { - spin_unlock_irqrestore(&video->irqlock, flags); - return NULL; - } - - done = list_first_entry(&video->irqqueue, - struct vsp1_vb2_buffer, queue); + struct vsp1_pipeline *pipe; + int ret; - /* In DU output mode reuse the buffer if the list is singular. */ - if (pipe->lif && list_is_singular(&video->irqqueue)) { - spin_unlock_irqrestore(&video->irqlock, flags); - return done; + /* Get a pipeline object for the video node. If a pipeline has already + * been allocated just increment its reference count and return it. + * Otherwise allocate a new pipeline and initialize it, it will be freed + * when the last reference is released. + */ + if (!video->rwpf->pipe) { + pipe = kzalloc(sizeof(*pipe), GFP_KERNEL); + if (!pipe) + return ERR_PTR(-ENOMEM); + + ret = vsp1_video_pipeline_init(pipe, video); + if (ret < 0) { + vsp1_pipeline_reset(pipe); + kfree(pipe); + return ERR_PTR(ret); + } + } else { + pipe = video->rwpf->pipe; + kref_get(&pipe->kref); } - list_del(&done->queue); - - if (!list_empty(&video->irqqueue)) - next = list_first_entry(&video->irqqueue, - struct vsp1_vb2_buffer, queue); - - spin_unlock_irqrestore(&video->irqlock, flags); - - done->buf.sequence = video->sequence++; - done->buf.vb2_buf.timestamp = ktime_get_ns(); - for (i = 0; i < done->buf.vb2_buf.num_planes; ++i) - vb2_set_plane_payload(&done->buf.vb2_buf, i, - done->mem.length[i]); - vb2_buffer_done(&done->buf.vb2_buf, VB2_BUF_STATE_DONE); - - return next; + return pipe; } -static void vsp1_video_frame_end(struct vsp1_pipeline *pipe, - struct vsp1_rwpf *rwpf) +static void vsp1_video_pipeline_release(struct kref *kref) { - struct vsp1_video *video = rwpf->video; - struct vsp1_vb2_buffer *buf; - unsigned long flags; + struct vsp1_pipeline *pipe = container_of(kref, typeof(*pipe), kref); - buf = vsp1_video_complete_buffer(video); - if (buf == NULL) - return; - - spin_lock_irqsave(&pipe->irqlock, flags); - - video->rwpf->ops->set_memory(video->rwpf, &buf->mem); - pipe->buffers_ready |= 1 << video->pipe_index; - - spin_unlock_irqrestore(&pipe->irqlock, flags); + vsp1_pipeline_reset(pipe); + kfree(pipe); } -static void vsp1_video_pipeline_frame_end(struct vsp1_pipeline *pipe) +static void vsp1_video_pipeline_put(struct vsp1_pipeline *pipe) { - struct vsp1_device *vsp1 = pipe->output->entity.vsp1; - unsigned int i; - - /* Complete buffers on all video nodes. */ - for (i = 0; i < vsp1->info->rpf_count; ++i) { - if (!pipe->inputs[i]) - continue; + struct media_device *mdev = &pipe->output->entity.vsp1->media_dev; - vsp1_video_frame_end(pipe, pipe->inputs[i]); - } - - if (!pipe->lif) - vsp1_video_frame_end(pipe, pipe->output); + mutex_lock(&mdev->graph_mutex); + kref_put(&pipe->kref, vsp1_video_pipeline_release); + mutex_unlock(&mdev->graph_mutex); } /* ----------------------------------------------------------------------------- @@ -513,16 +559,16 @@ static int vsp1_video_buffer_prepare(struct vb2_buffer *vb) if (vb->num_planes < format->num_planes) return -EINVAL; - buf->mem.num_planes = vb->num_planes; - for (i = 0; i < vb->num_planes; ++i) { buf->mem.addr[i] = vb2_dma_contig_plane_dma_addr(vb, i); - buf->mem.length[i] = vb2_plane_size(vb, i); - if (buf->mem.length[i] < format->plane_fmt[i].sizeimage) + if (vb2_plane_size(vb, i) < format->plane_fmt[i].sizeimage) return -EINVAL; } + for ( ; i < 3; ++i) + buf->mem.addr[i] = 0; + return 0; } @@ -530,7 +576,7 @@ static void vsp1_video_buffer_queue(struct vb2_buffer *vb) { struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb); struct vsp1_video *video = vb2_get_drv_priv(vb->vb2_queue); - struct vsp1_pipeline *pipe = to_vsp1_pipeline(&video->video.entity); + struct vsp1_pipeline *pipe = video->rwpf->pipe; struct vsp1_vb2_buffer *buf = to_vsp1_vb2_buffer(vbuf); unsigned long flags; bool empty; @@ -545,54 +591,66 @@ static void vsp1_video_buffer_queue(struct vb2_buffer *vb) spin_lock_irqsave(&pipe->irqlock, flags); - video->rwpf->ops->set_memory(video->rwpf, &buf->mem); + video->rwpf->mem = buf->mem; pipe->buffers_ready |= 1 << video->pipe_index; if (vb2_is_streaming(&video->queue) && vsp1_pipeline_ready(pipe)) - vsp1_pipeline_run(pipe); + vsp1_video_pipeline_run(pipe); spin_unlock_irqrestore(&pipe->irqlock, flags); } +static int vsp1_video_setup_pipeline(struct vsp1_pipeline *pipe) +{ + struct vsp1_entity *entity; + + /* Prepare the display list. */ + pipe->dl = vsp1_dl_list_get(pipe->output->dlm); + if (!pipe->dl) + return -ENOMEM; + + if (pipe->uds) { + struct vsp1_uds *uds = to_uds(&pipe->uds->subdev); + + /* If a BRU is present in the pipeline before the UDS, the alpha + * component doesn't need to be scaled as the BRU output alpha + * value is fixed to 255. Otherwise we need to scale the alpha + * component only when available at the input RPF. + */ + if (pipe->uds_input->type == VSP1_ENTITY_BRU) { + uds->scale_alpha = false; + } else { + struct vsp1_rwpf *rpf = + to_rwpf(&pipe->uds_input->subdev); + + uds->scale_alpha = rpf->fmtinfo->alpha; + } + } + + list_for_each_entry(entity, &pipe->entities, list_pipe) { + vsp1_entity_route_setup(entity, pipe->dl); + + if (entity->ops->configure) + entity->ops->configure(entity, pipe, pipe->dl); + } + + return 0; +} + static int vsp1_video_start_streaming(struct vb2_queue *vq, unsigned int count) { struct vsp1_video *video = vb2_get_drv_priv(vq); - struct vsp1_pipeline *pipe = to_vsp1_pipeline(&video->video.entity); - struct vsp1_entity *entity; + struct vsp1_pipeline *pipe = video->rwpf->pipe; unsigned long flags; int ret; mutex_lock(&pipe->lock); if (pipe->stream_count == pipe->num_inputs) { - if (pipe->uds) { - struct vsp1_uds *uds = to_uds(&pipe->uds->subdev); - - /* If a BRU is present in the pipeline before the UDS, - * the alpha component doesn't need to be scaled as the - * BRU output alpha value is fixed to 255. Otherwise we - * need to scale the alpha component only when available - * at the input RPF. - */ - if (pipe->uds_input->type == VSP1_ENTITY_BRU) { - uds->scale_alpha = false; - } else { - struct vsp1_rwpf *rpf = - to_rwpf(&pipe->uds_input->subdev); - - uds->scale_alpha = rpf->fmtinfo->alpha; - } - } - - list_for_each_entry(entity, &pipe->entities, list_pipe) { - vsp1_entity_route_setup(entity); - - ret = v4l2_subdev_call(&entity->subdev, video, - s_stream, 1); - if (ret < 0) { - mutex_unlock(&pipe->lock); - return ret; - } + ret = vsp1_video_setup_pipeline(pipe); + if (ret < 0) { + mutex_unlock(&pipe->lock); + return ret; } } @@ -601,7 +659,7 @@ static int vsp1_video_start_streaming(struct vb2_queue *vq, unsigned int count) spin_lock_irqsave(&pipe->irqlock, flags); if (vsp1_pipeline_ready(pipe)) - vsp1_pipeline_run(pipe); + vsp1_video_pipeline_run(pipe); spin_unlock_irqrestore(&pipe->irqlock, flags); return 0; @@ -610,7 +668,7 @@ static int vsp1_video_start_streaming(struct vb2_queue *vq, unsigned int count) static void vsp1_video_stop_streaming(struct vb2_queue *vq) { struct vsp1_video *video = vb2_get_drv_priv(vq); - struct vsp1_pipeline *pipe = to_vsp1_pipeline(&video->video.entity); + struct vsp1_pipeline *pipe = video->rwpf->pipe; struct vsp1_vb2_buffer *buffer; unsigned long flags; int ret; @@ -621,11 +679,14 @@ static void vsp1_video_stop_streaming(struct vb2_queue *vq) ret = vsp1_pipeline_stop(pipe); if (ret == -ETIMEDOUT) dev_err(video->vsp1->dev, "pipeline stop timeout\n"); + + vsp1_dl_list_put(pipe->dl); + pipe->dl = NULL; } mutex_unlock(&pipe->lock); - vsp1_video_pipeline_cleanup(pipe); media_entity_pipeline_stop(&video->video.entity); + vsp1_video_pipeline_put(pipe); /* Remove all buffers from the IRQ queue. */ spin_lock_irqsave(&video->irqlock, flags); @@ -737,6 +798,7 @@ vsp1_video_streamon(struct file *file, void *fh, enum v4l2_buf_type type) { struct v4l2_fh *vfh = file->private_data; struct vsp1_video *video = to_vsp1_video(vfh->vdev); + struct media_device *mdev = &video->vsp1->media_dev; struct vsp1_pipeline *pipe; int ret; @@ -745,18 +807,25 @@ vsp1_video_streamon(struct file *file, void *fh, enum v4l2_buf_type type) video->sequence = 0; - /* Start streaming on the pipeline. No link touching an entity in the - * pipeline can be activated or deactivated once streaming is started. - * - * Use the VSP1 pipeline object embedded in the first video object that - * starts streaming. + /* Get a pipeline for the video node and start streaming on it. No link + * touching an entity in the pipeline can be activated or deactivated + * once streaming is started. */ - pipe = video->video.entity.pipe - ? to_vsp1_pipeline(&video->video.entity) : &video->pipe; + mutex_lock(&mdev->graph_mutex); - ret = media_entity_pipeline_start(&video->video.entity, &pipe->pipe); - if (ret < 0) - return ret; + pipe = vsp1_video_pipeline_get(video); + if (IS_ERR(pipe)) { + mutex_unlock(&mdev->graph_mutex); + return PTR_ERR(pipe); + } + + ret = __media_entity_pipeline_start(&video->video.entity, &pipe->pipe); + if (ret < 0) { + mutex_unlock(&mdev->graph_mutex); + goto err_pipe; + } + + mutex_unlock(&mdev->graph_mutex); /* Verify that the configured format matches the output of the connected * subdev. @@ -765,21 +834,17 @@ vsp1_video_streamon(struct file *file, void *fh, enum v4l2_buf_type type) if (ret < 0) goto err_stop; - ret = vsp1_video_pipeline_init(pipe, video); - if (ret < 0) - goto err_stop; - /* Start the queue. */ ret = vb2_streamon(&video->queue, type); if (ret < 0) - goto err_cleanup; + goto err_stop; return 0; -err_cleanup: - vsp1_video_pipeline_cleanup(pipe); err_stop: media_entity_pipeline_stop(&video->video.entity); +err_pipe: + vsp1_video_pipeline_put(pipe); return ret; } @@ -895,26 +960,16 @@ struct vsp1_video *vsp1_video_create(struct vsp1_device *vsp1, spin_lock_init(&video->irqlock); INIT_LIST_HEAD(&video->irqqueue); - vsp1_pipeline_init(&video->pipe); - video->pipe.frame_end = vsp1_video_pipeline_frame_end; - /* Initialize the media entity... */ ret = media_entity_pads_init(&video->video.entity, 1, &video->pad); if (ret < 0) return ERR_PTR(ret); /* ... and the format ... */ - rwpf->fmtinfo = vsp1_get_format_info(VSP1_VIDEO_DEF_FORMAT); - rwpf->format.pixelformat = rwpf->fmtinfo->fourcc; - rwpf->format.colorspace = V4L2_COLORSPACE_SRGB; - rwpf->format.field = V4L2_FIELD_NONE; + rwpf->format.pixelformat = VSP1_VIDEO_DEF_FORMAT; rwpf->format.width = VSP1_VIDEO_DEF_WIDTH; rwpf->format.height = VSP1_VIDEO_DEF_HEIGHT; - rwpf->format.num_planes = 1; - rwpf->format.plane_fmt[0].bytesperline = - rwpf->format.width * rwpf->fmtinfo->bpp[0] / 8; - rwpf->format.plane_fmt[0].sizeimage = - rwpf->format.plane_fmt[0].bytesperline * rwpf->format.height; + __vsp1_video_try_format(video, &rwpf->format, &rwpf->fmtinfo); /* ... and the video node... */ video->video.v4l2_dev = &video->vsp1->v4l2_dev; diff --git a/drivers/media/platform/vsp1/vsp1_video.h b/drivers/media/platform/vsp1/vsp1_video.h index 64abd39ee..867b00807 100644 --- a/drivers/media/platform/vsp1/vsp1_video.h +++ b/drivers/media/platform/vsp1/vsp1_video.h @@ -18,7 +18,6 @@ #include <media/videobuf2-v4l2.h> -#include "vsp1_pipe.h" #include "vsp1_rwpf.h" struct vsp1_vb2_buffer { @@ -44,7 +43,6 @@ struct vsp1_video { struct mutex lock; - struct vsp1_pipeline pipe; unsigned int pipe_index; struct vb2_queue queue; diff --git a/drivers/media/platform/vsp1/vsp1_wpf.c b/drivers/media/platform/vsp1/vsp1_wpf.c index c78d4af50..6c91eaa35 100644 --- a/drivers/media/platform/vsp1/vsp1_wpf.c +++ b/drivers/media/platform/vsp1/vsp1_wpf.c @@ -16,124 +16,114 @@ #include <media/v4l2-subdev.h> #include "vsp1.h" +#include "vsp1_dl.h" +#include "vsp1_pipe.h" #include "vsp1_rwpf.h" #include "vsp1_video.h" -#define WPF_MAX_WIDTH 2048 -#define WPF_MAX_HEIGHT 2048 +#define WPF_GEN2_MAX_WIDTH 2048U +#define WPF_GEN2_MAX_HEIGHT 2048U +#define WPF_GEN3_MAX_WIDTH 8190U +#define WPF_GEN3_MAX_HEIGHT 8190U /* ----------------------------------------------------------------------------- * Device Access */ -static inline u32 vsp1_wpf_read(struct vsp1_rwpf *wpf, u32 reg) +static inline void vsp1_wpf_write(struct vsp1_rwpf *wpf, + struct vsp1_dl_list *dl, u32 reg, u32 data) { - return vsp1_read(wpf->entity.vsp1, - reg + wpf->entity.index * VI6_WPF_OFFSET); -} - -static inline void vsp1_wpf_write(struct vsp1_rwpf *wpf, u32 reg, u32 data) -{ - vsp1_mod_write(&wpf->entity, - reg + wpf->entity.index * VI6_WPF_OFFSET, data); + vsp1_dl_list_write(dl, reg + wpf->entity.index * VI6_WPF_OFFSET, data); } /* ----------------------------------------------------------------------------- - * Controls + * V4L2 Subdevice Core Operations */ -static int wpf_s_ctrl(struct v4l2_ctrl *ctrl) +static int wpf_s_stream(struct v4l2_subdev *subdev, int enable) { - struct vsp1_rwpf *wpf = - container_of(ctrl->handler, struct vsp1_rwpf, ctrls); - u32 value; + struct vsp1_rwpf *wpf = to_rwpf(subdev); + struct vsp1_device *vsp1 = wpf->entity.vsp1; - if (!vsp1_entity_is_streaming(&wpf->entity)) + if (enable) return 0; - switch (ctrl->id) { - case V4L2_CID_ALPHA_COMPONENT: - value = vsp1_wpf_read(wpf, VI6_WPF_OUTFMT); - value &= ~VI6_WPF_OUTFMT_PDV_MASK; - value |= ctrl->val << VI6_WPF_OUTFMT_PDV_SHIFT; - vsp1_wpf_write(wpf, VI6_WPF_OUTFMT, value); - break; - } + /* Write to registers directly when stopping the stream as there will be + * no pipeline run to apply the display list. + */ + vsp1_write(vsp1, VI6_WPF_IRQ_ENB(wpf->entity.index), 0); + vsp1_write(vsp1, wpf->entity.index * VI6_WPF_OFFSET + + VI6_WPF_SRCRPF, 0); return 0; } -static const struct v4l2_ctrl_ops wpf_ctrl_ops = { - .s_ctrl = wpf_s_ctrl, -}; - /* ----------------------------------------------------------------------------- - * V4L2 Subdevice Core Operations + * V4L2 Subdevice Operations */ -static int wpf_s_stream(struct v4l2_subdev *subdev, int enable) -{ - struct vsp1_pipeline *pipe = to_vsp1_pipeline(&subdev->entity); - struct vsp1_rwpf *wpf = to_rwpf(subdev); - struct vsp1_device *vsp1 = wpf->entity.vsp1; - const struct v4l2_rect *crop = &wpf->crop; - unsigned int i; - u32 srcrpf = 0; - u32 outfmt = 0; - int ret; - - ret = vsp1_entity_set_streaming(&wpf->entity, enable); - if (ret < 0) - return ret; +static struct v4l2_subdev_video_ops wpf_video_ops = { + .s_stream = wpf_s_stream, +}; - if (!enable) { - vsp1_write(vsp1, VI6_WPF_IRQ_ENB(wpf->entity.index), 0); - vsp1_write(vsp1, wpf->entity.index * VI6_WPF_OFFSET + - VI6_WPF_SRCRPF, 0); - return 0; - } +static struct v4l2_subdev_ops wpf_ops = { + .video = &wpf_video_ops, + .pad = &vsp1_rwpf_pad_ops, +}; - /* Sources. If the pipeline has a single input and BRU is not used, - * configure it as the master layer. Otherwise configure all - * inputs as sub-layers and select the virtual RPF as the master - * layer. - */ - for (i = 0; i < vsp1->info->rpf_count; ++i) { - struct vsp1_rwpf *input = pipe->inputs[i]; +/* ----------------------------------------------------------------------------- + * VSP1 Entity Operations + */ - if (!input) - continue; +static void vsp1_wpf_destroy(struct vsp1_entity *entity) +{ + struct vsp1_rwpf *wpf = entity_to_rwpf(entity); - srcrpf |= (!pipe->bru && pipe->num_inputs == 1) - ? VI6_WPF_SRCRPF_RPF_ACT_MST(input->entity.index) - : VI6_WPF_SRCRPF_RPF_ACT_SUB(input->entity.index); - } + vsp1_dlm_destroy(wpf->dlm); +} - if (pipe->bru || pipe->num_inputs > 1) - srcrpf |= VI6_WPF_SRCRPF_VIRACT_MST; +static void wpf_set_memory(struct vsp1_entity *entity, struct vsp1_dl_list *dl) +{ + struct vsp1_rwpf *wpf = entity_to_rwpf(entity); - vsp1_wpf_write(wpf, VI6_WPF_SRCRPF, srcrpf); + vsp1_wpf_write(wpf, dl, VI6_WPF_DSTM_ADDR_Y, wpf->mem.addr[0]); + vsp1_wpf_write(wpf, dl, VI6_WPF_DSTM_ADDR_C0, wpf->mem.addr[1]); + vsp1_wpf_write(wpf, dl, VI6_WPF_DSTM_ADDR_C1, wpf->mem.addr[2]); +} - /* Destination stride. */ - if (!pipe->lif) { - struct v4l2_pix_format_mplane *format = &wpf->format; +static void wpf_configure(struct vsp1_entity *entity, + struct vsp1_pipeline *pipe, + struct vsp1_dl_list *dl) +{ + struct vsp1_rwpf *wpf = to_rwpf(&entity->subdev); + struct vsp1_device *vsp1 = wpf->entity.vsp1; + const struct v4l2_mbus_framefmt *source_format; + const struct v4l2_mbus_framefmt *sink_format; + const struct v4l2_rect *crop; + unsigned int i; + u32 outfmt = 0; + u32 srcrpf = 0; - vsp1_wpf_write(wpf, VI6_WPF_DSTM_STRIDE_Y, - format->plane_fmt[0].bytesperline); - if (format->num_planes > 1) - vsp1_wpf_write(wpf, VI6_WPF_DSTM_STRIDE_C, - format->plane_fmt[1].bytesperline); - } + /* Cropping */ + crop = vsp1_rwpf_get_crop(wpf, wpf->entity.config); - vsp1_wpf_write(wpf, VI6_WPF_HSZCLIP, VI6_WPF_SZCLIP_EN | + vsp1_wpf_write(wpf, dl, VI6_WPF_HSZCLIP, VI6_WPF_SZCLIP_EN | (crop->left << VI6_WPF_SZCLIP_OFST_SHIFT) | (crop->width << VI6_WPF_SZCLIP_SIZE_SHIFT)); - vsp1_wpf_write(wpf, VI6_WPF_VSZCLIP, VI6_WPF_SZCLIP_EN | + vsp1_wpf_write(wpf, dl, VI6_WPF_VSZCLIP, VI6_WPF_SZCLIP_EN | (crop->top << VI6_WPF_SZCLIP_OFST_SHIFT) | (crop->height << VI6_WPF_SZCLIP_SIZE_SHIFT)); /* Format */ + sink_format = vsp1_entity_get_pad_format(&wpf->entity, + wpf->entity.config, + RWPF_PAD_SINK); + source_format = vsp1_entity_get_pad_format(&wpf->entity, + wpf->entity.config, + RWPF_PAD_SOURCE); + if (!pipe->lif) { + const struct v4l2_pix_format_mplane *format = &wpf->format; const struct vsp1_format_info *fmtinfo = wpf->fmtinfo; outfmt = fmtinfo->hwfmt << VI6_WPF_OUTFMT_WRFMT_SHIFT; @@ -145,73 +135,58 @@ static int wpf_s_stream(struct v4l2_subdev *subdev, int enable) if (fmtinfo->swap_uv) outfmt |= VI6_WPF_OUTFMT_SPUVS; - vsp1_wpf_write(wpf, VI6_WPF_DSWAP, fmtinfo->swap); + /* Destination stride and byte swapping. */ + vsp1_wpf_write(wpf, dl, VI6_WPF_DSTM_STRIDE_Y, + format->plane_fmt[0].bytesperline); + if (format->num_planes > 1) + vsp1_wpf_write(wpf, dl, VI6_WPF_DSTM_STRIDE_C, + format->plane_fmt[1].bytesperline); + + vsp1_wpf_write(wpf, dl, VI6_WPF_DSWAP, fmtinfo->swap); } - if (wpf->entity.formats[RWPF_PAD_SINK].code != - wpf->entity.formats[RWPF_PAD_SOURCE].code) + if (sink_format->code != source_format->code) outfmt |= VI6_WPF_OUTFMT_CSC; - /* Take the control handler lock to ensure that the PDV value won't be - * changed behind our back by a set control operation. - */ - if (vsp1->info->uapi) - mutex_lock(wpf->ctrls.lock); - outfmt |= wpf->alpha->cur.val << VI6_WPF_OUTFMT_PDV_SHIFT; - vsp1_wpf_write(wpf, VI6_WPF_OUTFMT, outfmt); - if (vsp1->info->uapi) - mutex_unlock(wpf->ctrls.lock); - - vsp1_mod_write(&wpf->entity, VI6_DPR_WPF_FPORCH(wpf->entity.index), - VI6_DPR_WPF_FPORCH_FP_WPFN); + outfmt |= wpf->alpha << VI6_WPF_OUTFMT_PDV_SHIFT; + vsp1_wpf_write(wpf, dl, VI6_WPF_OUTFMT, outfmt); - vsp1_mod_write(&wpf->entity, VI6_WPF_WRBCK_CTRL, 0); + vsp1_dl_list_write(dl, VI6_DPR_WPF_FPORCH(wpf->entity.index), + VI6_DPR_WPF_FPORCH_FP_WPFN); - /* Enable interrupts */ - vsp1_write(vsp1, VI6_WPF_IRQ_STA(wpf->entity.index), 0); - vsp1_write(vsp1, VI6_WPF_IRQ_ENB(wpf->entity.index), - VI6_WFP_IRQ_ENB_FREE); - - return 0; -} + vsp1_dl_list_write(dl, VI6_WPF_WRBCK_CTRL, 0); -/* ----------------------------------------------------------------------------- - * V4L2 Subdevice Operations - */ + /* Sources. If the pipeline has a single input and BRU is not used, + * configure it as the master layer. Otherwise configure all + * inputs as sub-layers and select the virtual RPF as the master + * layer. + */ + for (i = 0; i < vsp1->info->rpf_count; ++i) { + struct vsp1_rwpf *input = pipe->inputs[i]; -static struct v4l2_subdev_video_ops wpf_video_ops = { - .s_stream = wpf_s_stream, -}; + if (!input) + continue; -static struct v4l2_subdev_pad_ops wpf_pad_ops = { - .enum_mbus_code = vsp1_rwpf_enum_mbus_code, - .enum_frame_size = vsp1_rwpf_enum_frame_size, - .get_fmt = vsp1_rwpf_get_format, - .set_fmt = vsp1_rwpf_set_format, - .get_selection = vsp1_rwpf_get_selection, - .set_selection = vsp1_rwpf_set_selection, -}; + srcrpf |= (!pipe->bru && pipe->num_inputs == 1) + ? VI6_WPF_SRCRPF_RPF_ACT_MST(input->entity.index) + : VI6_WPF_SRCRPF_RPF_ACT_SUB(input->entity.index); + } -static struct v4l2_subdev_ops wpf_ops = { - .video = &wpf_video_ops, - .pad = &wpf_pad_ops, -}; + if (pipe->bru || pipe->num_inputs > 1) + srcrpf |= VI6_WPF_SRCRPF_VIRACT_MST; -/* ----------------------------------------------------------------------------- - * Video Device Operations - */ + vsp1_wpf_write(wpf, dl, VI6_WPF_SRCRPF, srcrpf); -static void wpf_set_memory(struct vsp1_rwpf *wpf, struct vsp1_rwpf_memory *mem) -{ - vsp1_wpf_write(wpf, VI6_WPF_DSTM_ADDR_Y, mem->addr[0]); - if (mem->num_planes > 1) - vsp1_wpf_write(wpf, VI6_WPF_DSTM_ADDR_C0, mem->addr[1]); - if (mem->num_planes > 2) - vsp1_wpf_write(wpf, VI6_WPF_DSTM_ADDR_C1, mem->addr[2]); + /* Enable interrupts */ + vsp1_dl_list_write(dl, VI6_WPF_IRQ_STA(wpf->entity.index), 0); + vsp1_dl_list_write(dl, VI6_WPF_IRQ_ENB(wpf->entity.index), + VI6_WFP_IRQ_ENB_FREE); } -static const struct vsp1_rwpf_operations wpf_vdev_ops = { +static const struct vsp1_entity_operations wpf_entity_ops = { + .destroy = vsp1_wpf_destroy, .set_memory = wpf_set_memory, + .configure = wpf_configure, }; /* ----------------------------------------------------------------------------- @@ -220,51 +195,43 @@ static const struct vsp1_rwpf_operations wpf_vdev_ops = { struct vsp1_rwpf *vsp1_wpf_create(struct vsp1_device *vsp1, unsigned int index) { - struct v4l2_subdev *subdev; struct vsp1_rwpf *wpf; + char name[6]; int ret; wpf = devm_kzalloc(vsp1->dev, sizeof(*wpf), GFP_KERNEL); if (wpf == NULL) return ERR_PTR(-ENOMEM); - wpf->ops = &wpf_vdev_ops; - - wpf->max_width = WPF_MAX_WIDTH; - wpf->max_height = WPF_MAX_HEIGHT; + if (vsp1->info->gen == 2) { + wpf->max_width = WPF_GEN2_MAX_WIDTH; + wpf->max_height = WPF_GEN2_MAX_HEIGHT; + } else { + wpf->max_width = WPF_GEN3_MAX_WIDTH; + wpf->max_height = WPF_GEN3_MAX_HEIGHT; + } + wpf->entity.ops = &wpf_entity_ops; wpf->entity.type = VSP1_ENTITY_WPF; wpf->entity.index = index; - ret = vsp1_entity_init(vsp1, &wpf->entity, 2); + sprintf(name, "wpf.%u", index); + ret = vsp1_entity_init(vsp1, &wpf->entity, name, 2, &wpf_ops); if (ret < 0) return ERR_PTR(ret); - /* Initialize the V4L2 subdev. */ - subdev = &wpf->entity.subdev; - v4l2_subdev_init(subdev, &wpf_ops); - - subdev->entity.ops = &vsp1->media_ops; - subdev->internal_ops = &vsp1_subdev_internal_ops; - snprintf(subdev->name, sizeof(subdev->name), "%s wpf.%u", - dev_name(vsp1->dev), index); - v4l2_set_subdevdata(subdev, wpf); - subdev->flags |= V4L2_SUBDEV_FL_HAS_DEVNODE; - - vsp1_entity_init_formats(subdev, NULL); + /* Initialize the display list manager. */ + wpf->dlm = vsp1_dlm_create(vsp1, index, 4); + if (!wpf->dlm) { + ret = -ENOMEM; + goto error; + } /* Initialize the control handler. */ - v4l2_ctrl_handler_init(&wpf->ctrls, 1); - wpf->alpha = v4l2_ctrl_new_std(&wpf->ctrls, &wpf_ctrl_ops, - V4L2_CID_ALPHA_COMPONENT, - 0, 255, 1, 255); - - wpf->entity.subdev.ctrl_handler = &wpf->ctrls; - - if (wpf->ctrls.error) { + ret = vsp1_rwpf_init_ctrls(wpf); + if (ret < 0) { dev_err(vsp1->dev, "wpf%u: failed to initialize controls\n", index); - ret = wpf->ctrls.error; goto error; } |