diff options
Diffstat (limited to 'drivers/media/platform/imx-jpeg/mxc-jpeg.c')
-rw-r--r-- | drivers/media/platform/imx-jpeg/mxc-jpeg.c | 109 |
1 files changed, 98 insertions, 11 deletions
diff --git a/drivers/media/platform/imx-jpeg/mxc-jpeg.c b/drivers/media/platform/imx-jpeg/mxc-jpeg.c index 755138063ee6..4ca96cf9def7 100644 --- a/drivers/media/platform/imx-jpeg/mxc-jpeg.c +++ b/drivers/media/platform/imx-jpeg/mxc-jpeg.c @@ -49,6 +49,7 @@ #include <linux/slab.h> #include <linux/irqreturn.h> #include <linux/interrupt.h> +#include <linux/pm_runtime.h> #include <linux/pm_domain.h> #include <linux/string.h> @@ -282,6 +283,20 @@ static const unsigned char jpeg_sos_maximal[] = { 0x11, 0x04, 0x11, 0x00, 0x3F, 0x00 }; +static const unsigned char jpeg_image_red[] = { + 0xFC, 0x5F, 0xA2, 0xBF, 0xCA, 0x73, 0xFE, 0xFE, + 0x02, 0x8A, 0x00, 0x28, 0xA0, 0x02, 0x8A, 0x00, + 0x28, 0xA0, 0x02, 0x8A, 0x00, 0x28, 0xA0, 0x02, + 0x8A, 0x00, 0x28, 0xA0, 0x02, 0x8A, 0x00, 0x28, + 0xA0, 0x02, 0x8A, 0x00, 0x28, 0xA0, 0x02, 0x8A, + 0x00, 0x28, 0xA0, 0x02, 0x8A, 0x00, 0x28, 0xA0, + 0x02, 0x8A, 0x00, 0x28, 0xA0, 0x02, 0x8A, 0x00, + 0x28, 0xA0, 0x02, 0x8A, 0x00, 0x28, 0xA0, 0x02, + 0x8A, 0x00, 0x28, 0xA0, 0x02, 0x8A, 0x00, 0x28, + 0xA0, 0x02, 0x8A, 0x00, 0x28, 0xA0, 0x02, 0x8A, + 0x00, 0x28, 0xA0, 0x02, 0x8A, 0x00 +}; + static const unsigned char jpeg_eoi[] = { 0xFF, 0xD9 }; @@ -575,6 +590,10 @@ static irqreturn_t mxc_jpeg_dec_irq(int irq, void *priv) dst_buf = v4l2_m2m_next_dst_buf(ctx->fh.m2m_ctx); src_buf = v4l2_m2m_next_src_buf(ctx->fh.m2m_ctx); + if (!dst_buf || !src_buf) { + dev_err(dev, "No source or destination buffer.\n"); + goto job_unlock; + } jpeg_src_buf = vb2_to_mxc_buf(&src_buf->vb2_buf); if (dec_ret & SLOT_STATUS_ENC_CONFIG_ERR) { @@ -760,6 +779,9 @@ static unsigned int mxc_jpeg_setup_cfg_stream(void *cfg_stream_vaddr, sos = (struct mxc_jpeg_sos *)(cfg + offset); offset += mxc_jpeg_fixup_sos(sos, fourcc); + memcpy(cfg + offset, jpeg_image_red, sizeof(jpeg_image_red)); + offset += sizeof(jpeg_image_red); + memcpy(cfg + offset, jpeg_eoi, sizeof(jpeg_eoi)); offset += sizeof(jpeg_eoi); @@ -795,6 +817,7 @@ static void mxc_jpeg_config_dec_desc(struct vb2_buffer *out_buf, img_fmt = mxc_jpeg_fourcc_to_imgfmt(q_data_cap->fmt->fourcc); desc->stm_ctrl &= ~STM_CTRL_IMAGE_FORMAT(0xF); /* clear image format */ desc->stm_ctrl |= STM_CTRL_IMAGE_FORMAT(img_fmt); + desc->stm_ctrl |= STM_CTRL_BITBUF_PTR_CLR(1); desc->line_pitch = q_data_cap->bytesperline[0]; mxc_jpeg_addrs(desc, dst_buf, src_buf, 0); mxc_jpeg_set_bufsize(desc, ALIGN(vb2_plane_size(src_buf, 0), 1024)); @@ -821,6 +844,7 @@ static void mxc_jpeg_config_dec_desc(struct vb2_buffer *out_buf, cfg_desc->imgsize |= MXC_JPEG_MIN_HEIGHT; cfg_desc->line_pitch = MXC_JPEG_MIN_WIDTH * 2; cfg_desc->stm_ctrl = STM_CTRL_IMAGE_FORMAT(MXC_JPEG_YUV422); + cfg_desc->stm_ctrl |= STM_CTRL_BITBUF_PTR_CLR(1); cfg_desc->stm_bufbase = cfg_stream_handle; cfg_desc->stm_bufsize = ALIGN(*cfg_size, 1024); print_descriptor_info(jpeg->dev, cfg_desc); @@ -864,6 +888,7 @@ static void mxc_jpeg_config_enc_desc(struct vb2_buffer *out_buf, cfg_desc->stm_bufsize = 0x0; cfg_desc->imgsize = 0; cfg_desc->stm_ctrl = STM_CTRL_CONFIG_MOD(1); + cfg_desc->stm_ctrl |= STM_CTRL_BITBUF_PTR_CLR(1); desc->next_descpt_ptr = 0; /* end of chain */ @@ -878,6 +903,7 @@ static void mxc_jpeg_config_enc_desc(struct vb2_buffer *out_buf, dev_err(jpeg->dev, "No valid image format detected\n"); desc->stm_ctrl = STM_CTRL_CONFIG_MOD(0) | STM_CTRL_IMAGE_FORMAT(img_fmt); + desc->stm_ctrl |= STM_CTRL_BITBUF_PTR_CLR(1); mxc_jpeg_addrs(desc, src_buf, dst_buf, 0); dev_dbg(jpeg->dev, "cfg_desc:\n"); print_descriptor_info(jpeg->dev, cfg_desc); @@ -933,11 +959,6 @@ static void mxc_jpeg_device_run(void *priv) return; } - /* - * TODO: this reset should be removed, once we figure out - * how to overcome hardware issues both on encoder and decoder - */ - mxc_jpeg_sw_reset(reg); mxc_jpeg_enable(reg); mxc_jpeg_set_l_endian(reg, 1); @@ -1058,10 +1079,17 @@ static int mxc_jpeg_start_streaming(struct vb2_queue *q, unsigned int count) { struct mxc_jpeg_ctx *ctx = vb2_get_drv_priv(q); struct mxc_jpeg_q_data *q_data = mxc_jpeg_get_q_data(ctx, q->type); + int ret; dev_dbg(ctx->mxc_jpeg->dev, "Start streaming ctx=%p", ctx); q_data->sequence = 0; + ret = pm_runtime_resume_and_get(ctx->mxc_jpeg->dev); + if (ret < 0) { + dev_err(ctx->mxc_jpeg->dev, "Failed to power up jpeg\n"); + return ret; + } + return 0; } @@ -1079,9 +1107,10 @@ static void mxc_jpeg_stop_streaming(struct vb2_queue *q) else vbuf = v4l2_m2m_dst_buf_remove(ctx->fh.m2m_ctx); if (!vbuf) - return; + break; v4l2_m2m_buf_done(vbuf, VB2_BUF_STATE_ERROR); } + pm_runtime_put_sync(&ctx->mxc_jpeg->pdev->dev); } static int mxc_jpeg_valid_comp_id(struct device *dev, @@ -1941,8 +1970,7 @@ static int mxc_jpeg_attach_pm_domains(struct mxc_jpeg_dev *jpeg) jpeg->pd_link[i] = device_link_add(dev, jpeg->pd_dev[i], DL_FLAG_STATELESS | - DL_FLAG_PM_RUNTIME | - DL_FLAG_RPM_ACTIVE); + DL_FLAG_PM_RUNTIME); if (!jpeg->pd_link[i]) { ret = -EINVAL; goto fail; @@ -1959,7 +1987,6 @@ static int mxc_jpeg_probe(struct platform_device *pdev) { struct mxc_jpeg_dev *jpeg; struct device *dev = &pdev->dev; - struct resource *res; int dec_irq; int ret; int mode; @@ -1982,8 +2009,7 @@ static int mxc_jpeg_probe(struct platform_device *pdev) goto err_irq; } - res = platform_get_resource(pdev, IORESOURCE_MEM, 0); - jpeg->base_reg = devm_ioremap_resource(&pdev->dev, res); + jpeg->base_reg = devm_platform_ioremap_resource(pdev, 0); if (IS_ERR(jpeg->base_reg)) return PTR_ERR(jpeg->base_reg); @@ -2007,6 +2033,19 @@ static int mxc_jpeg_probe(struct platform_device *pdev) jpeg->dev = dev; jpeg->mode = mode; + /* Get clocks */ + jpeg->clk_ipg = devm_clk_get(dev, "ipg"); + if (IS_ERR(jpeg->clk_ipg)) { + dev_err(dev, "failed to get clock: ipg\n"); + goto err_clk; + } + + jpeg->clk_per = devm_clk_get(dev, "per"); + if (IS_ERR(jpeg->clk_per)) { + dev_err(dev, "failed to get clock: per\n"); + goto err_clk; + } + ret = mxc_jpeg_attach_pm_domains(jpeg); if (ret < 0) { dev_err(dev, "failed to attach power domains %d\n", ret); @@ -2075,6 +2114,7 @@ static int mxc_jpeg_probe(struct platform_device *pdev) jpeg->dec_vdev->minor); platform_set_drvdata(pdev, jpeg); + pm_runtime_enable(dev); return 0; @@ -2088,10 +2128,55 @@ err_m2m: v4l2_device_unregister(&jpeg->v4l2_dev); err_register: + mxc_jpeg_detach_pm_domains(jpeg); + err_irq: +err_clk: return ret; } +#ifdef CONFIG_PM +static int mxc_jpeg_runtime_resume(struct device *dev) +{ + struct mxc_jpeg_dev *jpeg = dev_get_drvdata(dev); + int ret; + + ret = clk_prepare_enable(jpeg->clk_ipg); + if (ret < 0) { + dev_err(dev, "failed to enable clock: ipg\n"); + goto err_ipg; + } + + ret = clk_prepare_enable(jpeg->clk_per); + if (ret < 0) { + dev_err(dev, "failed to enable clock: per\n"); + goto err_per; + } + + return 0; + +err_per: + clk_disable_unprepare(jpeg->clk_ipg); +err_ipg: + return ret; +} + +static int mxc_jpeg_runtime_suspend(struct device *dev) +{ + struct mxc_jpeg_dev *jpeg = dev_get_drvdata(dev); + + clk_disable_unprepare(jpeg->clk_ipg); + clk_disable_unprepare(jpeg->clk_per); + + return 0; +} +#endif + +static const struct dev_pm_ops mxc_jpeg_pm_ops = { + SET_RUNTIME_PM_OPS(mxc_jpeg_runtime_suspend, + mxc_jpeg_runtime_resume, NULL) +}; + static int mxc_jpeg_remove(struct platform_device *pdev) { unsigned int slot; @@ -2100,6 +2185,7 @@ static int mxc_jpeg_remove(struct platform_device *pdev) for (slot = 0; slot < MXC_MAX_SLOTS; slot++) mxc_jpeg_free_slot_data(jpeg, slot); + pm_runtime_disable(&pdev->dev); video_unregister_device(jpeg->dec_vdev); v4l2_m2m_release(jpeg->m2m_dev); v4l2_device_unregister(&jpeg->v4l2_dev); @@ -2116,6 +2202,7 @@ static struct platform_driver mxc_jpeg_driver = { .driver = { .name = "mxc-jpeg", .of_match_table = mxc_jpeg_match, + .pm = &mxc_jpeg_pm_ops, }, }; module_platform_driver(mxc_jpeg_driver); |