Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

[media] media: ti-vpe: Use mem-to-mem ioctl helpers

1: Simplify the vpe mem-to-mem driver by using the m2m ioctl
and vb2 helpers.
2: Align and arranged the v4l2_ioctl_ops.
3: Fixes a typo.
4: Use of_match_ptr() instead of explicitly defining the macro
to NULL in case CONFIG_OF is not defined.

Signed-off-by: Lad, Prabhakar <prabhakar.csengg@gmail.com>
Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>

authored by

Prabhakar Lad and committed by
Mauro Carvalho Chehab
47e604c5 901c4ad6

+50 -107
+50 -107
drivers/media/platform/ti-vpe/vpe.c
··· 25 25 #include <linux/io.h> 26 26 #include <linux/ioctl.h> 27 27 #include <linux/module.h> 28 + #include <linux/of.h> 28 29 #include <linux/platform_device.h> 29 30 #include <linux/pm_runtime.h> 30 31 #include <linux/sched.h> ··· 75 74 #define VPE_DEF_BUFS_PER_JOB 1 /* default one buffer per batch job */ 76 75 77 76 /* 78 - * each VPE context can need up to 3 config desciptors, 7 input descriptors, 77 + * each VPE context can need up to 3 config descriptors, 7 input descriptors, 79 78 * 3 output descriptors, and 10 control descriptors 80 79 */ 81 80 #define VPE_DESC_LIST_SIZE (10 * VPDMA_DTD_DESC_SIZE + \ ··· 374 373 struct vpe_ctx { 375 374 struct v4l2_fh fh; 376 375 struct vpe_dev *dev; 377 - struct v4l2_m2m_ctx *m2m_ctx; 378 376 struct v4l2_ctrl_handler hdl; 379 377 380 378 unsigned int field; /* current field */ ··· 887 887 if (ctx->deinterlacing && ctx->src_vbs[2] == NULL) 888 888 needed += 2; /* need additional two most recent fields */ 889 889 890 - if (v4l2_m2m_num_src_bufs_ready(ctx->m2m_ctx) < needed) 890 + if (v4l2_m2m_num_src_bufs_ready(ctx->fh.m2m_ctx) < needed) 891 891 return 0; 892 892 893 - if (v4l2_m2m_num_dst_bufs_ready(ctx->m2m_ctx) < needed) 893 + if (v4l2_m2m_num_dst_bufs_ready(ctx->fh.m2m_ctx) < needed) 894 894 return 0; 895 895 896 896 return 1; ··· 1100 1100 struct vpe_q_data *d_q_data = &ctx->q_data[Q_DATA_DST]; 1101 1101 1102 1102 if (ctx->deinterlacing && ctx->src_vbs[2] == NULL) { 1103 - ctx->src_vbs[2] = v4l2_m2m_src_buf_remove(ctx->m2m_ctx); 1103 + ctx->src_vbs[2] = v4l2_m2m_src_buf_remove(ctx->fh.m2m_ctx); 1104 1104 WARN_ON(ctx->src_vbs[2] == NULL); 1105 - ctx->src_vbs[1] = v4l2_m2m_src_buf_remove(ctx->m2m_ctx); 1105 + ctx->src_vbs[1] = v4l2_m2m_src_buf_remove(ctx->fh.m2m_ctx); 1106 1106 WARN_ON(ctx->src_vbs[1] == NULL); 1107 1107 } 1108 1108 1109 - ctx->src_vbs[0] = v4l2_m2m_src_buf_remove(ctx->m2m_ctx); 1109 + ctx->src_vbs[0] = v4l2_m2m_src_buf_remove(ctx->fh.m2m_ctx); 1110 1110 WARN_ON(ctx->src_vbs[0] == NULL); 1111 - ctx->dst_vb = v4l2_m2m_dst_buf_remove(ctx->m2m_ctx); 1111 + ctx->dst_vb = v4l2_m2m_dst_buf_remove(ctx->fh.m2m_ctx); 1112 1112 WARN_ON(ctx->dst_vb == NULL); 1113 1113 1114 1114 /* config descriptors */ ··· 1334 1334 finished: 1335 1335 vpe_dbg(ctx->dev, "finishing transaction\n"); 1336 1336 ctx->bufs_completed = 0; 1337 - v4l2_m2m_job_finish(dev->m2m_dev, ctx->m2m_ctx); 1337 + v4l2_m2m_job_finish(dev->m2m_dev, ctx->fh.m2m_ctx); 1338 1338 handled: 1339 1339 return IRQ_HANDLED; 1340 1340 } ··· 1395 1395 struct vpe_q_data *q_data; 1396 1396 int i; 1397 1397 1398 - vq = v4l2_m2m_get_vq(ctx->m2m_ctx, f->type); 1398 + vq = v4l2_m2m_get_vq(ctx->fh.m2m_ctx, f->type); 1399 1399 if (!vq) 1400 1400 return -EINVAL; 1401 1401 ··· 1527 1527 struct vb2_queue *vq; 1528 1528 int i; 1529 1529 1530 - vq = v4l2_m2m_get_vq(ctx->m2m_ctx, f->type); 1530 + vq = v4l2_m2m_get_vq(ctx->fh.m2m_ctx, f->type); 1531 1531 if (!vq) 1532 1532 return -EINVAL; 1533 1533 ··· 1739 1739 return set_srcdst_params(ctx); 1740 1740 } 1741 1741 1742 - static int vpe_reqbufs(struct file *file, void *priv, 1743 - struct v4l2_requestbuffers *reqbufs) 1744 - { 1745 - struct vpe_ctx *ctx = file2ctx(file); 1746 - 1747 - return v4l2_m2m_reqbufs(file, ctx->m2m_ctx, reqbufs); 1748 - } 1749 - 1750 - static int vpe_querybuf(struct file *file, void *priv, struct v4l2_buffer *buf) 1751 - { 1752 - struct vpe_ctx *ctx = file2ctx(file); 1753 - 1754 - return v4l2_m2m_querybuf(file, ctx->m2m_ctx, buf); 1755 - } 1756 - 1757 - static int vpe_qbuf(struct file *file, void *priv, struct v4l2_buffer *buf) 1758 - { 1759 - struct vpe_ctx *ctx = file2ctx(file); 1760 - 1761 - return v4l2_m2m_qbuf(file, ctx->m2m_ctx, buf); 1762 - } 1763 - 1764 - static int vpe_dqbuf(struct file *file, void *priv, struct v4l2_buffer *buf) 1765 - { 1766 - struct vpe_ctx *ctx = file2ctx(file); 1767 - 1768 - return v4l2_m2m_dqbuf(file, ctx->m2m_ctx, buf); 1769 - } 1770 - 1771 - static int vpe_streamon(struct file *file, void *priv, enum v4l2_buf_type type) 1772 - { 1773 - struct vpe_ctx *ctx = file2ctx(file); 1774 - 1775 - return v4l2_m2m_streamon(file, ctx->m2m_ctx, type); 1776 - } 1777 - 1778 - static int vpe_streamoff(struct file *file, void *priv, enum v4l2_buf_type type) 1779 - { 1780 - struct vpe_ctx *ctx = file2ctx(file); 1781 - 1782 - vpe_dump_regs(ctx->dev); 1783 - vpdma_dump_regs(ctx->dev->vpdma); 1784 - 1785 - return v4l2_m2m_streamoff(file, ctx->m2m_ctx, type); 1786 - } 1787 - 1788 1742 /* 1789 1743 * defines number of buffers/frames a context can process with VPE before 1790 1744 * switching to a different context. default value is 1 buffer per context ··· 1768 1814 }; 1769 1815 1770 1816 static const struct v4l2_ioctl_ops vpe_ioctl_ops = { 1771 - .vidioc_querycap = vpe_querycap, 1817 + .vidioc_querycap = vpe_querycap, 1772 1818 1773 - .vidioc_enum_fmt_vid_cap_mplane = vpe_enum_fmt, 1819 + .vidioc_enum_fmt_vid_cap_mplane = vpe_enum_fmt, 1774 1820 .vidioc_g_fmt_vid_cap_mplane = vpe_g_fmt, 1775 1821 .vidioc_try_fmt_vid_cap_mplane = vpe_try_fmt, 1776 1822 .vidioc_s_fmt_vid_cap_mplane = vpe_s_fmt, 1777 1823 1778 - .vidioc_enum_fmt_vid_out_mplane = vpe_enum_fmt, 1824 + .vidioc_enum_fmt_vid_out_mplane = vpe_enum_fmt, 1779 1825 .vidioc_g_fmt_vid_out_mplane = vpe_g_fmt, 1780 1826 .vidioc_try_fmt_vid_out_mplane = vpe_try_fmt, 1781 1827 .vidioc_s_fmt_vid_out_mplane = vpe_s_fmt, ··· 1783 1829 .vidioc_g_selection = vpe_g_selection, 1784 1830 .vidioc_s_selection = vpe_s_selection, 1785 1831 1786 - .vidioc_reqbufs = vpe_reqbufs, 1787 - .vidioc_querybuf = vpe_querybuf, 1832 + .vidioc_reqbufs = v4l2_m2m_ioctl_reqbufs, 1833 + .vidioc_querybuf = v4l2_m2m_ioctl_querybuf, 1834 + .vidioc_qbuf = v4l2_m2m_ioctl_qbuf, 1835 + .vidioc_dqbuf = v4l2_m2m_ioctl_dqbuf, 1836 + .vidioc_streamon = v4l2_m2m_ioctl_streamon, 1837 + .vidioc_streamoff = v4l2_m2m_ioctl_streamoff, 1788 1838 1789 - .vidioc_qbuf = vpe_qbuf, 1790 - .vidioc_dqbuf = vpe_dqbuf, 1791 - 1792 - .vidioc_streamon = vpe_streamon, 1793 - .vidioc_streamoff = vpe_streamoff, 1794 - .vidioc_subscribe_event = v4l2_ctrl_subscribe_event, 1795 - .vidioc_unsubscribe_event = v4l2_event_unsubscribe, 1839 + .vidioc_subscribe_event = v4l2_ctrl_subscribe_event, 1840 + .vidioc_unsubscribe_event = v4l2_event_unsubscribe, 1796 1841 }; 1797 1842 1798 1843 /* ··· 1863 1910 static void vpe_buf_queue(struct vb2_buffer *vb) 1864 1911 { 1865 1912 struct vpe_ctx *ctx = vb2_get_drv_priv(vb->vb2_queue); 1866 - v4l2_m2m_buf_queue(ctx->m2m_ctx, vb); 1913 + 1914 + v4l2_m2m_buf_queue(ctx->fh.m2m_ctx, vb); 1915 + } 1916 + 1917 + static int vpe_start_streaming(struct vb2_queue *q, unsigned int count) 1918 + { 1919 + /* currently we do nothing here */ 1920 + 1921 + return 0; 1922 + } 1923 + 1924 + static void vpe_stop_streaming(struct vb2_queue *q) 1925 + { 1926 + struct vpe_ctx *ctx = vb2_get_drv_priv(q); 1927 + 1928 + vpe_dump_regs(ctx->dev); 1929 + vpdma_dump_regs(ctx->dev->vpdma); 1867 1930 } 1868 1931 1869 1932 static struct vb2_ops vpe_qops = { ··· 1888 1919 .buf_queue = vpe_buf_queue, 1889 1920 .wait_prepare = vb2_ops_wait_prepare, 1890 1921 .wait_finish = vb2_ops_wait_finish, 1922 + .start_streaming = vpe_start_streaming, 1923 + .stop_streaming = vpe_stop_streaming, 1891 1924 }; 1892 1925 1893 1926 static int queue_init(void *priv, struct vb2_queue *src_vq, ··· 1943 1972 static int vpe_open(struct file *file) 1944 1973 { 1945 1974 struct vpe_dev *dev = video_drvdata(file); 1946 - struct vpe_ctx *ctx = NULL; 1947 1975 struct vpe_q_data *s_q_data; 1948 1976 struct v4l2_ctrl_handler *hdl; 1977 + struct vpe_ctx *ctx; 1949 1978 int ret; 1950 1979 1951 1980 vpe_dbg(dev, "vpe_open\n"); ··· 2018 2047 if (ret) 2019 2048 goto exit_fh; 2020 2049 2021 - ctx->m2m_ctx = v4l2_m2m_ctx_init(dev->m2m_dev, ctx, &queue_init); 2050 + ctx->fh.m2m_ctx = v4l2_m2m_ctx_init(dev->m2m_dev, ctx, &queue_init); 2022 2051 2023 - if (IS_ERR(ctx->m2m_ctx)) { 2024 - ret = PTR_ERR(ctx->m2m_ctx); 2052 + if (IS_ERR(ctx->fh.m2m_ctx)) { 2053 + ret = PTR_ERR(ctx->fh.m2m_ctx); 2025 2054 goto exit_fh; 2026 2055 } 2027 2056 ··· 2040 2069 ctx->load_mmrs = true; 2041 2070 2042 2071 vpe_dbg(dev, "created instance %p, m2m_ctx: %p\n", 2043 - ctx, ctx->m2m_ctx); 2072 + ctx, ctx->fh.m2m_ctx); 2044 2073 2045 2074 mutex_unlock(&dev->dev_mutex); 2046 2075 ··· 2078 2107 v4l2_fh_del(&ctx->fh); 2079 2108 v4l2_fh_exit(&ctx->fh); 2080 2109 v4l2_ctrl_handler_free(&ctx->hdl); 2081 - v4l2_m2m_ctx_release(ctx->m2m_ctx); 2110 + v4l2_m2m_ctx_release(ctx->fh.m2m_ctx); 2082 2111 2083 2112 kfree(ctx); 2084 2113 ··· 2095 2124 return 0; 2096 2125 } 2097 2126 2098 - static unsigned int vpe_poll(struct file *file, 2099 - struct poll_table_struct *wait) 2100 - { 2101 - struct vpe_ctx *ctx = file2ctx(file); 2102 - struct vpe_dev *dev = ctx->dev; 2103 - int ret; 2104 - 2105 - mutex_lock(&dev->dev_mutex); 2106 - ret = v4l2_m2m_poll(file, ctx->m2m_ctx, wait); 2107 - mutex_unlock(&dev->dev_mutex); 2108 - return ret; 2109 - } 2110 - 2111 - static int vpe_mmap(struct file *file, struct vm_area_struct *vma) 2112 - { 2113 - struct vpe_ctx *ctx = file2ctx(file); 2114 - struct vpe_dev *dev = ctx->dev; 2115 - int ret; 2116 - 2117 - if (mutex_lock_interruptible(&dev->dev_mutex)) 2118 - return -ERESTARTSYS; 2119 - ret = v4l2_m2m_mmap(file, ctx->m2m_ctx, vma); 2120 - mutex_unlock(&dev->dev_mutex); 2121 - return ret; 2122 - } 2123 - 2124 2127 static const struct v4l2_file_operations vpe_fops = { 2125 2128 .owner = THIS_MODULE, 2126 2129 .open = vpe_open, 2127 2130 .release = vpe_release, 2128 - .poll = vpe_poll, 2131 + .poll = v4l2_m2m_fop_poll, 2129 2132 .unlocked_ioctl = video_ioctl2, 2130 - .mmap = vpe_mmap, 2133 + .mmap = v4l2_m2m_fop_mmap, 2131 2134 }; 2132 2135 2133 2136 static struct video_device vpe_videodev = { ··· 2303 2358 }, 2304 2359 {}, 2305 2360 }; 2306 - #else 2307 - #define vpe_of_match NULL 2308 2361 #endif 2309 2362 2310 2363 static struct platform_driver vpe_pdrv = { ··· 2310 2367 .remove = vpe_remove, 2311 2368 .driver = { 2312 2369 .name = VPE_MODULE_NAME, 2313 - .of_match_table = vpe_of_match, 2370 + .of_match_table = of_match_ptr(vpe_of_match), 2314 2371 }, 2315 2372 }; 2316 2373