18c2ecf20Sopenharmony_ci/* 28c2ecf20Sopenharmony_ci * omap_voutdef.h 38c2ecf20Sopenharmony_ci * 48c2ecf20Sopenharmony_ci * Copyright (C) 2010 Texas Instruments. 58c2ecf20Sopenharmony_ci * 68c2ecf20Sopenharmony_ci * This file is licensed under the terms of the GNU General Public License 78c2ecf20Sopenharmony_ci * version 2. This program is licensed "as is" without any warranty of any 88c2ecf20Sopenharmony_ci * kind, whether express or implied. 98c2ecf20Sopenharmony_ci */ 108c2ecf20Sopenharmony_ci 118c2ecf20Sopenharmony_ci#ifndef OMAP_VOUTDEF_H 128c2ecf20Sopenharmony_ci#define OMAP_VOUTDEF_H 138c2ecf20Sopenharmony_ci 148c2ecf20Sopenharmony_ci#include <media/videobuf2-dma-contig.h> 158c2ecf20Sopenharmony_ci#include <media/v4l2-ctrls.h> 168c2ecf20Sopenharmony_ci#include <video/omapfb_dss.h> 178c2ecf20Sopenharmony_ci#include <video/omapvrfb.h> 188c2ecf20Sopenharmony_ci#include <linux/dmaengine.h> 198c2ecf20Sopenharmony_ci 208c2ecf20Sopenharmony_ci#define YUYV_BPP 2 218c2ecf20Sopenharmony_ci#define RGB565_BPP 2 228c2ecf20Sopenharmony_ci#define RGB24_BPP 3 238c2ecf20Sopenharmony_ci#define RGB32_BPP 4 248c2ecf20Sopenharmony_ci#define TILE_SIZE 32 258c2ecf20Sopenharmony_ci#define YUYV_VRFB_BPP 2 268c2ecf20Sopenharmony_ci#define RGB_VRFB_BPP 1 278c2ecf20Sopenharmony_ci#define MAX_CID 3 288c2ecf20Sopenharmony_ci#define MAC_VRFB_CTXS 4 298c2ecf20Sopenharmony_ci#define MAX_VOUT_DEV 2 308c2ecf20Sopenharmony_ci#define MAX_OVLS 3 318c2ecf20Sopenharmony_ci#define MAX_DISPLAYS 10 328c2ecf20Sopenharmony_ci#define MAX_MANAGERS 3 338c2ecf20Sopenharmony_ci 348c2ecf20Sopenharmony_ci#define QQVGA_WIDTH 160 358c2ecf20Sopenharmony_ci#define QQVGA_HEIGHT 120 368c2ecf20Sopenharmony_ci 378c2ecf20Sopenharmony_ci/* Max Resolution supported by the driver */ 388c2ecf20Sopenharmony_ci#define VID_MAX_WIDTH 1280 /* Largest width */ 398c2ecf20Sopenharmony_ci#define VID_MAX_HEIGHT 720 /* Largest height */ 408c2ecf20Sopenharmony_ci 418c2ecf20Sopenharmony_ci/* Minimum requirement is 2x2 for DSS */ 428c2ecf20Sopenharmony_ci#define VID_MIN_WIDTH 2 438c2ecf20Sopenharmony_ci#define VID_MIN_HEIGHT 2 448c2ecf20Sopenharmony_ci 458c2ecf20Sopenharmony_ci/* 2048 x 2048 is max res supported by OMAP display controller */ 468c2ecf20Sopenharmony_ci#define MAX_PIXELS_PER_LINE 2048 478c2ecf20Sopenharmony_ci 488c2ecf20Sopenharmony_ci#define VRFB_TX_TIMEOUT 1000 498c2ecf20Sopenharmony_ci#define VRFB_NUM_BUFS 4 508c2ecf20Sopenharmony_ci 518c2ecf20Sopenharmony_ci/* Max buffer size tobe allocated during init */ 528c2ecf20Sopenharmony_ci#define OMAP_VOUT_MAX_BUF_SIZE (VID_MAX_WIDTH*VID_MAX_HEIGHT*4) 538c2ecf20Sopenharmony_ci 548c2ecf20Sopenharmony_cienum dma_channel_state { 558c2ecf20Sopenharmony_ci DMA_CHAN_NOT_ALLOTED, 568c2ecf20Sopenharmony_ci DMA_CHAN_ALLOTED, 578c2ecf20Sopenharmony_ci}; 588c2ecf20Sopenharmony_ci 598c2ecf20Sopenharmony_ci/* Enum for Rotation 608c2ecf20Sopenharmony_ci * DSS understands rotation in 0, 1, 2, 3 context 618c2ecf20Sopenharmony_ci * while V4L2 driver understands it as 0, 90, 180, 270 628c2ecf20Sopenharmony_ci */ 638c2ecf20Sopenharmony_cienum dss_rotation { 648c2ecf20Sopenharmony_ci dss_rotation_0_degree = 0, 658c2ecf20Sopenharmony_ci dss_rotation_90_degree = 1, 668c2ecf20Sopenharmony_ci dss_rotation_180_degree = 2, 678c2ecf20Sopenharmony_ci dss_rotation_270_degree = 3, 688c2ecf20Sopenharmony_ci}; 698c2ecf20Sopenharmony_ci 708c2ecf20Sopenharmony_ci/* Enum for choosing rotation type for vout 718c2ecf20Sopenharmony_ci * DSS2 doesn't understand no rotation as an 728c2ecf20Sopenharmony_ci * option while V4L2 driver doesn't support 738c2ecf20Sopenharmony_ci * rotation in the case where VRFB is not built in 748c2ecf20Sopenharmony_ci * the kernel 758c2ecf20Sopenharmony_ci */ 768c2ecf20Sopenharmony_cienum vout_rotaion_type { 778c2ecf20Sopenharmony_ci VOUT_ROT_NONE = 0, 788c2ecf20Sopenharmony_ci VOUT_ROT_VRFB = 1, 798c2ecf20Sopenharmony_ci}; 808c2ecf20Sopenharmony_ci 818c2ecf20Sopenharmony_ci/* 828c2ecf20Sopenharmony_ci * This structure is used to store the DMA transfer parameters 838c2ecf20Sopenharmony_ci * for VRFB hidden buffer 848c2ecf20Sopenharmony_ci */ 858c2ecf20Sopenharmony_cistruct vid_vrfb_dma { 868c2ecf20Sopenharmony_ci struct dma_chan *chan; 878c2ecf20Sopenharmony_ci struct dma_interleaved_template *xt; 888c2ecf20Sopenharmony_ci 898c2ecf20Sopenharmony_ci int req_status; 908c2ecf20Sopenharmony_ci int tx_status; 918c2ecf20Sopenharmony_ci wait_queue_head_t wait; 928c2ecf20Sopenharmony_ci}; 938c2ecf20Sopenharmony_ci 948c2ecf20Sopenharmony_cistruct omapvideo_info { 958c2ecf20Sopenharmony_ci int id; 968c2ecf20Sopenharmony_ci int num_overlays; 978c2ecf20Sopenharmony_ci struct omap_overlay *overlays[MAX_OVLS]; 988c2ecf20Sopenharmony_ci enum vout_rotaion_type rotation_type; 998c2ecf20Sopenharmony_ci}; 1008c2ecf20Sopenharmony_ci 1018c2ecf20Sopenharmony_cistruct omap2video_device { 1028c2ecf20Sopenharmony_ci struct mutex mtx; 1038c2ecf20Sopenharmony_ci 1048c2ecf20Sopenharmony_ci int state; 1058c2ecf20Sopenharmony_ci 1068c2ecf20Sopenharmony_ci struct v4l2_device v4l2_dev; 1078c2ecf20Sopenharmony_ci struct omap_vout_device *vouts[MAX_VOUT_DEV]; 1088c2ecf20Sopenharmony_ci 1098c2ecf20Sopenharmony_ci int num_displays; 1108c2ecf20Sopenharmony_ci struct omap_dss_device *displays[MAX_DISPLAYS]; 1118c2ecf20Sopenharmony_ci int num_overlays; 1128c2ecf20Sopenharmony_ci struct omap_overlay *overlays[MAX_OVLS]; 1138c2ecf20Sopenharmony_ci int num_managers; 1148c2ecf20Sopenharmony_ci struct omap_overlay_manager *managers[MAX_MANAGERS]; 1158c2ecf20Sopenharmony_ci}; 1168c2ecf20Sopenharmony_ci 1178c2ecf20Sopenharmony_ci/* buffer for one video frame */ 1188c2ecf20Sopenharmony_cistruct omap_vout_buffer { 1198c2ecf20Sopenharmony_ci /* common v4l buffer stuff -- must be first */ 1208c2ecf20Sopenharmony_ci struct vb2_v4l2_buffer vbuf; 1218c2ecf20Sopenharmony_ci struct list_head queue; 1228c2ecf20Sopenharmony_ci}; 1238c2ecf20Sopenharmony_ci 1248c2ecf20Sopenharmony_cistatic inline struct omap_vout_buffer *vb2_to_omap_vout_buffer(struct vb2_buffer *vb) 1258c2ecf20Sopenharmony_ci{ 1268c2ecf20Sopenharmony_ci struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb); 1278c2ecf20Sopenharmony_ci 1288c2ecf20Sopenharmony_ci return container_of(vbuf, struct omap_vout_buffer, vbuf); 1298c2ecf20Sopenharmony_ci} 1308c2ecf20Sopenharmony_ci 1318c2ecf20Sopenharmony_ci/* per-device data structure */ 1328c2ecf20Sopenharmony_cistruct omap_vout_device { 1338c2ecf20Sopenharmony_ci 1348c2ecf20Sopenharmony_ci struct omapvideo_info vid_info; 1358c2ecf20Sopenharmony_ci struct video_device *vfd; 1368c2ecf20Sopenharmony_ci struct omap2video_device *vid_dev; 1378c2ecf20Sopenharmony_ci struct v4l2_ctrl_handler ctrl_handler; 1388c2ecf20Sopenharmony_ci int vid; 1398c2ecf20Sopenharmony_ci 1408c2ecf20Sopenharmony_ci /* allow to reuse previously allocated buffer which is big enough */ 1418c2ecf20Sopenharmony_ci int buffer_size; 1428c2ecf20Sopenharmony_ci enum omap_color_mode dss_mode; 1438c2ecf20Sopenharmony_ci 1448c2ecf20Sopenharmony_ci u32 sequence; 1458c2ecf20Sopenharmony_ci 1468c2ecf20Sopenharmony_ci struct v4l2_pix_format pix; 1478c2ecf20Sopenharmony_ci struct v4l2_rect crop; 1488c2ecf20Sopenharmony_ci struct v4l2_window win; 1498c2ecf20Sopenharmony_ci struct v4l2_framebuffer fbuf; 1508c2ecf20Sopenharmony_ci 1518c2ecf20Sopenharmony_ci /* Lock to protect the shared data structures in ioctl */ 1528c2ecf20Sopenharmony_ci struct mutex lock; 1538c2ecf20Sopenharmony_ci 1548c2ecf20Sopenharmony_ci enum dss_rotation rotation; 1558c2ecf20Sopenharmony_ci bool mirror; 1568c2ecf20Sopenharmony_ci int flicker_filter; 1578c2ecf20Sopenharmony_ci 1588c2ecf20Sopenharmony_ci int bpp; /* bytes per pixel */ 1598c2ecf20Sopenharmony_ci int vrfb_bpp; /* bytes per pixel with respect to VRFB */ 1608c2ecf20Sopenharmony_ci 1618c2ecf20Sopenharmony_ci struct vid_vrfb_dma vrfb_dma_tx; 1628c2ecf20Sopenharmony_ci unsigned int smsshado_phy_addr[MAC_VRFB_CTXS]; 1638c2ecf20Sopenharmony_ci unsigned int smsshado_virt_addr[MAC_VRFB_CTXS]; 1648c2ecf20Sopenharmony_ci struct vrfb vrfb_context[MAC_VRFB_CTXS]; 1658c2ecf20Sopenharmony_ci bool vrfb_static_allocation; 1668c2ecf20Sopenharmony_ci unsigned int smsshado_size; 1678c2ecf20Sopenharmony_ci unsigned char pos; 1688c2ecf20Sopenharmony_ci 1698c2ecf20Sopenharmony_ci int ps, vr_ps, line_length, first_int, field_id; 1708c2ecf20Sopenharmony_ci struct omap_vout_buffer *cur_frm, *next_frm; 1718c2ecf20Sopenharmony_ci spinlock_t vbq_lock; /* spinlock for dma_queue */ 1728c2ecf20Sopenharmony_ci struct list_head dma_queue; 1738c2ecf20Sopenharmony_ci u8 *queued_buf_addr[VIDEO_MAX_FRAME]; 1748c2ecf20Sopenharmony_ci u32 cropped_offset; 1758c2ecf20Sopenharmony_ci s32 tv_field1_offset; 1768c2ecf20Sopenharmony_ci void *isr_handle; 1778c2ecf20Sopenharmony_ci struct vb2_queue vq; 1788c2ecf20Sopenharmony_ci 1798c2ecf20Sopenharmony_ci}; 1808c2ecf20Sopenharmony_ci 1818c2ecf20Sopenharmony_ci/* 1828c2ecf20Sopenharmony_ci * Return true if rotation is 90 or 270 1838c2ecf20Sopenharmony_ci */ 1848c2ecf20Sopenharmony_cistatic inline int is_rotation_90_or_270(const struct omap_vout_device *vout) 1858c2ecf20Sopenharmony_ci{ 1868c2ecf20Sopenharmony_ci return (vout->rotation == dss_rotation_90_degree || 1878c2ecf20Sopenharmony_ci vout->rotation == dss_rotation_270_degree); 1888c2ecf20Sopenharmony_ci} 1898c2ecf20Sopenharmony_ci 1908c2ecf20Sopenharmony_ci/* 1918c2ecf20Sopenharmony_ci * Return true if rotation is enabled 1928c2ecf20Sopenharmony_ci */ 1938c2ecf20Sopenharmony_cistatic inline int is_rotation_enabled(const struct omap_vout_device *vout) 1948c2ecf20Sopenharmony_ci{ 1958c2ecf20Sopenharmony_ci return vout->rotation || vout->mirror; 1968c2ecf20Sopenharmony_ci} 1978c2ecf20Sopenharmony_ci 1988c2ecf20Sopenharmony_ci/* 1998c2ecf20Sopenharmony_ci * Reverse the rotation degree if mirroring is enabled 2008c2ecf20Sopenharmony_ci */ 2018c2ecf20Sopenharmony_cistatic inline int calc_rotation(const struct omap_vout_device *vout) 2028c2ecf20Sopenharmony_ci{ 2038c2ecf20Sopenharmony_ci if (!vout->mirror) 2048c2ecf20Sopenharmony_ci return vout->rotation; 2058c2ecf20Sopenharmony_ci 2068c2ecf20Sopenharmony_ci switch (vout->rotation) { 2078c2ecf20Sopenharmony_ci case dss_rotation_90_degree: 2088c2ecf20Sopenharmony_ci return dss_rotation_270_degree; 2098c2ecf20Sopenharmony_ci case dss_rotation_270_degree: 2108c2ecf20Sopenharmony_ci return dss_rotation_90_degree; 2118c2ecf20Sopenharmony_ci case dss_rotation_180_degree: 2128c2ecf20Sopenharmony_ci return dss_rotation_0_degree; 2138c2ecf20Sopenharmony_ci default: 2148c2ecf20Sopenharmony_ci return dss_rotation_180_degree; 2158c2ecf20Sopenharmony_ci } 2168c2ecf20Sopenharmony_ci} 2178c2ecf20Sopenharmony_ci 2188c2ecf20Sopenharmony_civoid omap_vout_free_buffers(struct omap_vout_device *vout); 2198c2ecf20Sopenharmony_ci#endif /* ifndef OMAP_VOUTDEF_H */ 220