Lines Matching refs:ctx

120 static inline void bdisp_ctx_state_lock_set(u32 state, struct bdisp_ctx *ctx)  in bdisp_ctx_state_lock_set()  argument
124 spin_lock_irqsave(&ctx->bdisp_dev->slock, flags); in bdisp_ctx_state_lock_set()
125 ctx->state |= state; in bdisp_ctx_state_lock_set()
126 spin_unlock_irqrestore(&ctx->bdisp_dev->slock, flags); in bdisp_ctx_state_lock_set()
129 static inline void bdisp_ctx_state_lock_clear(u32 state, struct bdisp_ctx *ctx) in bdisp_ctx_state_lock_clear() argument
133 spin_lock_irqsave(&ctx->bdisp_dev->slock, flags); in bdisp_ctx_state_lock_clear()
134 ctx->state &= ~state; in bdisp_ctx_state_lock_clear()
135 spin_unlock_irqrestore(&ctx->bdisp_dev->slock, flags); in bdisp_ctx_state_lock_clear()
138 static inline bool bdisp_ctx_state_is_set(u32 mask, struct bdisp_ctx *ctx) in bdisp_ctx_state_is_set() argument
143 spin_lock_irqsave(&ctx->bdisp_dev->slock, flags); in bdisp_ctx_state_is_set()
144 ret = (ctx->state & mask) == mask; in bdisp_ctx_state_is_set()
145 spin_unlock_irqrestore(&ctx->bdisp_dev->slock, flags); in bdisp_ctx_state_is_set()
164 static struct bdisp_frame *ctx_get_frame(struct bdisp_ctx *ctx, in ctx_get_frame() argument
169 return &ctx->src; in ctx_get_frame()
171 return &ctx->dst; in ctx_get_frame()
173 dev_err(ctx->bdisp_dev->dev, in ctx_get_frame()
181 static void bdisp_job_finish(struct bdisp_ctx *ctx, int vb_state) in bdisp_job_finish() argument
185 if (WARN(!ctx || !ctx->fh.m2m_ctx, "Null hardware context\n")) in bdisp_job_finish()
188 dev_dbg(ctx->bdisp_dev->dev, "%s\n", __func__); in bdisp_job_finish()
190 src_vb = v4l2_m2m_src_buf_remove(ctx->fh.m2m_ctx); in bdisp_job_finish()
191 dst_vb = v4l2_m2m_dst_buf_remove(ctx->fh.m2m_ctx); in bdisp_job_finish()
203 v4l2_m2m_job_finish(ctx->bdisp_dev->m2m.m2m_dev, in bdisp_job_finish()
204 ctx->fh.m2m_ctx); in bdisp_job_finish()
208 static int bdisp_ctx_stop_req(struct bdisp_ctx *ctx) in bdisp_ctx_stop_req() argument
211 struct bdisp_dev *bdisp = ctx->bdisp_dev; in bdisp_ctx_stop_req()
214 dev_dbg(ctx->bdisp_dev->dev, "%s\n", __func__); in bdisp_ctx_stop_req()
219 if (!test_bit(ST_M2M_RUNNING, &bdisp->state) || (curr_ctx != ctx)) in bdisp_ctx_stop_req()
222 bdisp_ctx_state_lock_set(BDISP_CTX_STOP_REQ, ctx); in bdisp_ctx_stop_req()
225 !bdisp_ctx_state_is_set(BDISP_CTX_STOP_REQ, ctx), in bdisp_ctx_stop_req()
229 dev_err(ctx->bdisp_dev->dev, "%s IRQ timeout\n", __func__); in bdisp_ctx_stop_req()
236 static void __bdisp_job_abort(struct bdisp_ctx *ctx) in __bdisp_job_abort() argument
240 ret = bdisp_ctx_stop_req(ctx); in __bdisp_job_abort()
241 if ((ret == -ETIMEDOUT) || (ctx->state & BDISP_CTX_ABORT)) { in __bdisp_job_abort()
243 ctx); in __bdisp_job_abort()
244 bdisp_job_finish(ctx, VB2_BUF_STATE_ERROR); in __bdisp_job_abort()
253 static int bdisp_get_addr(struct bdisp_ctx *ctx, struct vb2_buffer *vb, in bdisp_get_addr() argument
272 dev_dbg(ctx->bdisp_dev->dev, "ignoring some planes\n"); in bdisp_get_addr()
274 dev_dbg(ctx->bdisp_dev->dev, in bdisp_get_addr()
281 static int bdisp_get_bufs(struct bdisp_ctx *ctx) in bdisp_get_bufs() argument
287 src = &ctx->src; in bdisp_get_bufs()
288 dst = &ctx->dst; in bdisp_get_bufs()
290 src_vb = v4l2_m2m_next_src_buf(ctx->fh.m2m_ctx); in bdisp_get_bufs()
291 ret = bdisp_get_addr(ctx, &src_vb->vb2_buf, src, src->paddr); in bdisp_get_bufs()
295 dst_vb = v4l2_m2m_next_dst_buf(ctx->fh.m2m_ctx); in bdisp_get_bufs()
296 ret = bdisp_get_addr(ctx, &dst_vb->vb2_buf, dst, dst->paddr); in bdisp_get_bufs()
307 struct bdisp_ctx *ctx = priv; in bdisp_device_run() local
312 if (WARN(!ctx, "Null hardware context\n")) in bdisp_device_run()
315 bdisp = ctx->bdisp_dev; in bdisp_device_run()
319 if (bdisp->m2m.ctx != ctx) { in bdisp_device_run()
321 bdisp->m2m.ctx, ctx); in bdisp_device_run()
322 ctx->state |= BDISP_PARAMS; in bdisp_device_run()
323 bdisp->m2m.ctx = ctx; in bdisp_device_run()
326 if (ctx->state & BDISP_CTX_STOP_REQ) { in bdisp_device_run()
327 ctx->state &= ~BDISP_CTX_STOP_REQ; in bdisp_device_run()
328 ctx->state |= BDISP_CTX_ABORT; in bdisp_device_run()
333 err = bdisp_get_bufs(ctx); in bdisp_device_run()
347 err = bdisp_hw_update(ctx); in bdisp_device_run()
357 ctx->state &= ~BDISP_PARAMS; in bdisp_device_run()
360 bdisp_job_finish(ctx, VB2_BUF_STATE_ERROR); in bdisp_device_run()
368 static int __bdisp_s_ctrl(struct bdisp_ctx *ctx, struct v4l2_ctrl *ctrl) in __bdisp_s_ctrl() argument
375 ctx->hflip = ctrl->val; in __bdisp_s_ctrl()
378 ctx->vflip = ctrl->val; in __bdisp_s_ctrl()
381 dev_err(ctx->bdisp_dev->dev, "unknown control %d\n", ctrl->id); in __bdisp_s_ctrl()
385 ctx->state |= BDISP_PARAMS; in __bdisp_s_ctrl()
392 struct bdisp_ctx *ctx = container_of(ctrl->handler, struct bdisp_ctx, in bdisp_s_ctrl() local
397 spin_lock_irqsave(&ctx->bdisp_dev->slock, flags); in bdisp_s_ctrl()
398 ret = __bdisp_s_ctrl(ctx, ctrl); in bdisp_s_ctrl()
399 spin_unlock_irqrestore(&ctx->bdisp_dev->slock, flags); in bdisp_s_ctrl()
408 static int bdisp_ctrls_create(struct bdisp_ctx *ctx) in bdisp_ctrls_create() argument
410 if (ctx->ctrls_rdy) in bdisp_ctrls_create()
413 v4l2_ctrl_handler_init(&ctx->ctrl_handler, BDISP_MAX_CTRL_NUM); in bdisp_ctrls_create()
415 ctx->bdisp_ctrls.hflip = v4l2_ctrl_new_std(&ctx->ctrl_handler, in bdisp_ctrls_create()
417 ctx->bdisp_ctrls.vflip = v4l2_ctrl_new_std(&ctx->ctrl_handler, in bdisp_ctrls_create()
420 if (ctx->ctrl_handler.error) { in bdisp_ctrls_create()
421 int err = ctx->ctrl_handler.error; in bdisp_ctrls_create()
423 v4l2_ctrl_handler_free(&ctx->ctrl_handler); in bdisp_ctrls_create()
427 ctx->ctrls_rdy = true; in bdisp_ctrls_create()
432 static void bdisp_ctrls_delete(struct bdisp_ctx *ctx) in bdisp_ctrls_delete() argument
434 if (ctx->ctrls_rdy) { in bdisp_ctrls_delete()
435 v4l2_ctrl_handler_free(&ctx->ctrl_handler); in bdisp_ctrls_delete()
436 ctx->ctrls_rdy = false; in bdisp_ctrls_delete()
446 struct bdisp_ctx *ctx = vb2_get_drv_priv(vq); in bdisp_queue_setup() local
447 struct bdisp_frame *frame = ctx_get_frame(ctx, vq->type); in bdisp_queue_setup()
450 dev_err(ctx->bdisp_dev->dev, "Invalid frame (%p)\n", frame); in bdisp_queue_setup()
455 dev_err(ctx->bdisp_dev->dev, "Invalid format\n"); in bdisp_queue_setup()
464 allocators[0] = ctx->bdisp_dev->alloc_ctx; in bdisp_queue_setup()
471 struct bdisp_ctx *ctx = vb2_get_drv_priv(vb->vb2_queue); in bdisp_buf_prepare() local
472 struct bdisp_frame *frame = ctx_get_frame(ctx, vb->vb2_queue->type); in bdisp_buf_prepare()
475 dev_err(ctx->bdisp_dev->dev, "Invalid frame (%p)\n", frame); in bdisp_buf_prepare()
488 struct bdisp_ctx *ctx = vb2_get_drv_priv(vb->vb2_queue); in bdisp_buf_queue() local
492 dev_dbg(ctx->bdisp_dev->dev, "0 data buffer, skip it\n"); in bdisp_buf_queue()
497 if (ctx->fh.m2m_ctx) in bdisp_buf_queue()
498 v4l2_m2m_buf_queue(ctx->fh.m2m_ctx, vbuf); in bdisp_buf_queue()
503 struct bdisp_ctx *ctx = q->drv_priv; in bdisp_start_streaming() local
505 int ret = pm_runtime_get_sync(ctx->bdisp_dev->dev); in bdisp_start_streaming()
508 dev_err(ctx->bdisp_dev->dev, "failed to set runtime PM\n"); in bdisp_start_streaming()
511 while ((buf = v4l2_m2m_src_buf_remove(ctx->fh.m2m_ctx))) in bdisp_start_streaming()
514 while ((buf = v4l2_m2m_dst_buf_remove(ctx->fh.m2m_ctx))) in bdisp_start_streaming()
526 struct bdisp_ctx *ctx = q->drv_priv; in bdisp_stop_streaming() local
528 __bdisp_job_abort(ctx); in bdisp_stop_streaming()
530 pm_runtime_put(ctx->bdisp_dev->dev); in bdisp_stop_streaming()
546 struct bdisp_ctx *ctx = priv; in queue_init() local
552 src_vq->drv_priv = ctx; in queue_init()
557 src_vq->lock = &ctx->bdisp_dev->lock; in queue_init()
566 dst_vq->drv_priv = ctx; in queue_init()
571 dst_vq->lock = &ctx->bdisp_dev->lock; in queue_init()
579 struct bdisp_ctx *ctx = NULL; in bdisp_open() local
586 ctx = kzalloc(sizeof(*ctx), GFP_KERNEL); in bdisp_open()
587 if (!ctx) { in bdisp_open()
591 ctx->bdisp_dev = bdisp; in bdisp_open()
593 if (bdisp_hw_alloc_nodes(ctx)) { in bdisp_open()
599 v4l2_fh_init(&ctx->fh, bdisp->m2m.vdev); in bdisp_open()
601 ret = bdisp_ctrls_create(ctx); in bdisp_open()
608 ctx->fh.ctrl_handler = &ctx->ctrl_handler; in bdisp_open()
609 file->private_data = &ctx->fh; in bdisp_open()
610 v4l2_fh_add(&ctx->fh); in bdisp_open()
613 ctx->src = bdisp_dflt_fmt; in bdisp_open()
614 ctx->dst = bdisp_dflt_fmt; in bdisp_open()
617 ctx->fh.m2m_ctx = v4l2_m2m_ctx_init(bdisp->m2m.m2m_dev, ctx, in bdisp_open()
619 if (IS_ERR(ctx->fh.m2m_ctx)) { in bdisp_open()
621 ret = PTR_ERR(ctx->fh.m2m_ctx); in bdisp_open()
628 dev_dbg(bdisp->dev, "driver opened, ctx = 0x%p\n", ctx); in bdisp_open()
635 bdisp_ctrls_delete(ctx); in bdisp_open()
637 v4l2_fh_del(&ctx->fh); in bdisp_open()
638 v4l2_fh_exit(&ctx->fh); in bdisp_open()
639 bdisp_hw_free_nodes(ctx); in bdisp_open()
641 kfree(ctx); in bdisp_open()
650 struct bdisp_ctx *ctx = fh_to_ctx(file->private_data); in bdisp_release() local
651 struct bdisp_dev *bdisp = ctx->bdisp_dev; in bdisp_release()
658 v4l2_m2m_ctx_release(ctx->fh.m2m_ctx); in bdisp_release()
660 bdisp_ctrls_delete(ctx); in bdisp_release()
662 v4l2_fh_del(&ctx->fh); in bdisp_release()
663 v4l2_fh_exit(&ctx->fh); in bdisp_release()
668 bdisp_hw_free_nodes(ctx); in bdisp_release()
670 kfree(ctx); in bdisp_release()
689 struct bdisp_ctx *ctx = fh_to_ctx(fh); in bdisp_querycap() local
690 struct bdisp_dev *bdisp = ctx->bdisp_dev; in bdisp_querycap()
706 struct bdisp_ctx *ctx = fh_to_ctx(fh); in bdisp_enum_fmt() local
716 dev_dbg(ctx->bdisp_dev->dev, "No YU12 on capture\n"); in bdisp_enum_fmt()
726 struct bdisp_ctx *ctx = fh_to_ctx(fh); in bdisp_g_fmt() local
728 struct bdisp_frame *frame = ctx_get_frame(ctx, f->type); in bdisp_g_fmt()
731 dev_err(ctx->bdisp_dev->dev, "Invalid frame (%p)\n", frame); in bdisp_g_fmt()
750 struct bdisp_ctx *ctx = fh_to_ctx(fh); in bdisp_try_fmt() local
757 dev_dbg(ctx->bdisp_dev->dev, "Unknown format 0x%x\n", in bdisp_try_fmt()
765 dev_dbg(ctx->bdisp_dev->dev, "No YU12 on capture\n"); in bdisp_try_fmt()
785 dev_dbg(ctx->bdisp_dev->dev, in bdisp_try_fmt()
800 struct bdisp_ctx *ctx = fh_to_ctx(fh); in bdisp_s_fmt() local
809 dev_err(ctx->bdisp_dev->dev, "Cannot set format\n"); in bdisp_s_fmt()
813 vq = v4l2_m2m_get_vq(ctx->fh.m2m_ctx, f->type); in bdisp_s_fmt()
815 dev_err(ctx->bdisp_dev->dev, "queue (%d) busy\n", f->type); in bdisp_s_fmt()
820 &ctx->src : &ctx->dst; in bdisp_s_fmt()
824 dev_err(ctx->bdisp_dev->dev, "Unknown format 0x%x\n", in bdisp_s_fmt()
845 bdisp_ctx_state_lock_set(state, ctx); in bdisp_s_fmt()
854 struct bdisp_ctx *ctx = fh_to_ctx(fh); in bdisp_g_selection() local
856 frame = ctx_get_frame(ctx, s->type); in bdisp_g_selection()
858 dev_err(ctx->bdisp_dev->dev, "Invalid frame (%p)\n", frame); in bdisp_g_selection()
878 dev_err(ctx->bdisp_dev->dev, "Invalid target\n"); in bdisp_g_selection()
899 dev_err(ctx->bdisp_dev->dev, "Invalid target\n"); in bdisp_g_selection()
905 dev_err(ctx->bdisp_dev->dev, "Invalid type\n"); in bdisp_g_selection()
932 struct bdisp_ctx *ctx = fh_to_ctx(fh); in bdisp_s_selection() local
945 dev_err(ctx->bdisp_dev->dev, "Invalid type / target\n"); in bdisp_s_selection()
949 frame = ctx_get_frame(ctx, s->type); in bdisp_s_selection()
951 dev_err(ctx->bdisp_dev->dev, "Invalid frame (%p)\n", frame); in bdisp_s_selection()
964 dev_err(ctx->bdisp_dev->dev, in bdisp_s_selection()
977 dev_err(ctx->bdisp_dev->dev, in bdisp_s_selection()
993 dev_dbg(ctx->bdisp_dev->dev, in bdisp_s_selection()
1002 bdisp_ctx_state_lock_set(BDISP_PARAMS, ctx); in bdisp_s_selection()
1009 struct bdisp_ctx *ctx = fh_to_ctx(fh); in bdisp_streamon() local
1012 !bdisp_ctx_state_is_set(BDISP_SRC_FMT, ctx)) { in bdisp_streamon()
1013 dev_err(ctx->bdisp_dev->dev, "src not defined\n"); in bdisp_streamon()
1018 !bdisp_ctx_state_is_set(BDISP_DST_FMT, ctx)) { in bdisp_streamon()
1019 dev_err(ctx->bdisp_dev->dev, "dst not defined\n"); in bdisp_streamon()
1023 return v4l2_m2m_streamon(file, ctx->fh.m2m_ctx, type); in bdisp_streamon()
1100 struct bdisp_ctx *ctx; in bdisp_irq_thread() local
1117 ctx = v4l2_m2m_get_curr_priv(bdisp->m2m.m2m_dev); in bdisp_irq_thread()
1118 if (!ctx || !ctx->fh.m2m_ctx) in bdisp_irq_thread()
1123 bdisp_job_finish(ctx, VB2_BUF_STATE_DONE); in bdisp_irq_thread()
1125 if (bdisp_ctx_state_is_set(BDISP_CTX_STOP_REQ, ctx)) { in bdisp_irq_thread()
1126 bdisp_ctx_state_lock_clear(BDISP_CTX_STOP_REQ, ctx); in bdisp_irq_thread()
1151 struct bdisp_ctx *ctx; in bdisp_irq_timeout() local
1153 ctx = v4l2_m2m_get_curr_priv(bdisp->m2m.m2m_dev); in bdisp_irq_timeout()
1155 dev_err(ctx->bdisp_dev->dev, "Device work timeout\n"); in bdisp_irq_timeout()
1163 bdisp_job_finish(ctx, VB2_BUF_STATE_ERROR); in bdisp_irq_timeout()
1196 struct bdisp_ctx *ctx; in bdisp_m2m_resume() local
1200 ctx = bdisp->m2m.ctx; in bdisp_m2m_resume()
1201 bdisp->m2m.ctx = NULL; in bdisp_m2m_resume()
1205 bdisp_job_finish(ctx, VB2_BUF_STATE_ERROR); in bdisp_m2m_resume()