1 /*
2  * Copyright (C) 2010 Texas Instruments Incorporated - http://www.ti.com/
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License as
6  * published by the Free Software Foundation version 2.
7  *
8  * This program is distributed WITHOUT ANY WARRANTY of any
9  * kind, whether express or implied; without even the implied warranty
10  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11  * GNU General Public License for more details.
12  */
13 #ifndef VPBE_DISPLAY_H
14 #define VPBE_DISPLAY_H
15 
16 /* Header files */
17 #include <linux/videodev2.h>
18 #include <media/v4l2-common.h>
19 #include <media/v4l2-fh.h>
20 #include <media/videobuf2-v4l2.h>
21 #include <media/videobuf2-dma-contig.h>
22 #include <media/davinci/vpbe_types.h>
23 #include <media/davinci/vpbe_osd.h>
24 #include <media/davinci/vpbe.h>
25 
26 #define VPBE_DISPLAY_MAX_DEVICES 2
27 
28 enum vpbe_display_device_id {
29 	VPBE_DISPLAY_DEVICE_0,
30 	VPBE_DISPLAY_DEVICE_1
31 };
32 
33 #define VPBE_DISPLAY_DRV_NAME	"vpbe-display"
34 
35 #define VPBE_DISPLAY_MAJOR_RELEASE              1
36 #define VPBE_DISPLAY_MINOR_RELEASE              0
37 #define VPBE_DISPLAY_BUILD                      1
38 #define VPBE_DISPLAY_VERSION_CODE ((VPBE_DISPLAY_MAJOR_RELEASE << 16) | \
39 	(VPBE_DISPLAY_MINOR_RELEASE << 8)  | \
40 	VPBE_DISPLAY_BUILD)
41 
42 #define VPBE_DISPLAY_VALID_FIELD(field)   ((V4L2_FIELD_NONE == field) || \
43 	 (V4L2_FIELD_ANY == field) || (V4L2_FIELD_INTERLACED == field))
44 
45 /* Exp ratio numerator and denominator constants */
46 #define VPBE_DISPLAY_H_EXP_RATIO_N	9
47 #define VPBE_DISPLAY_H_EXP_RATIO_D	8
48 #define VPBE_DISPLAY_V_EXP_RATIO_N	6
49 #define VPBE_DISPLAY_V_EXP_RATIO_D	5
50 
51 /* Zoom multiplication factor */
52 #define VPBE_DISPLAY_ZOOM_4X	4
53 #define VPBE_DISPLAY_ZOOM_2X	2
54 
55 /* Structures */
56 struct display_layer_info {
57 	int enable;
58 	/* Layer ID used by Display Manager */
59 	enum osd_layer id;
60 	struct osd_layer_config config;
61 	enum osd_zoom_factor h_zoom;
62 	enum osd_zoom_factor v_zoom;
63 	enum osd_h_exp_ratio h_exp;
64 	enum osd_v_exp_ratio v_exp;
65 };
66 
67 struct vpbe_disp_buffer {
68 	struct vb2_v4l2_buffer vb;
69 	struct list_head list;
70 };
71 
72 /* vpbe display object structure */
73 struct vpbe_layer {
74 	/* Pointer to the vpbe_display */
75 	struct vpbe_display *disp_dev;
76 	/* Pointer pointing to current v4l2_buffer */
77 	struct vpbe_disp_buffer *cur_frm;
78 	/* Pointer pointing to next v4l2_buffer */
79 	struct vpbe_disp_buffer *next_frm;
80 	/* videobuf specific parameters
81 	 * Buffer queue used in video-buf
82 	 */
83 	struct vb2_queue buffer_queue;
84 	/* Queue of filled frames */
85 	struct list_head dma_queue;
86 	/* Used in video-buf */
87 	spinlock_t irqlock;
88 	/* V4l2 specific parameters */
89 	/* Identifies video device for this layer */
90 	struct video_device video_dev;
91 	/* Used to store pixel format */
92 	struct v4l2_pix_format pix_fmt;
93 	enum v4l2_field buf_field;
94 	/* Video layer configuration params */
95 	struct display_layer_info layer_info;
96 	/* vpbe specific parameters
97 	 * enable window for display
98 	 */
99 	unsigned char window_enable;
100 	/* number of open instances of the layer */
101 	unsigned int usrs;
102 	/* Indicates id of the field which is being displayed */
103 	unsigned int field_id;
104 	/* Identifies device object */
105 	enum vpbe_display_device_id device_id;
106 	/* facilitation of ioctl ops lock by v4l2*/
107 	struct mutex opslock;
108 	u8 layer_first_int;
109 };
110 
111 /* vpbe device structure */
112 struct vpbe_display {
113 	/* layer specific parameters */
114 	/* lock for isr updates to buf layers*/
115 	spinlock_t dma_queue_lock;
116 	/* C-Plane offset from start of y-plane */
117 	unsigned int cbcr_ofst;
118 	struct vpbe_layer *dev[VPBE_DISPLAY_MAX_DEVICES];
119 	struct vpbe_device *vpbe_dev;
120 	struct osd_state *osd_device;
121 };
122 
123 struct buf_config_params {
124 	unsigned char min_numbuffers;
125 	unsigned char numbuffers[VPBE_DISPLAY_MAX_DEVICES];
126 	unsigned int min_bufsize[VPBE_DISPLAY_MAX_DEVICES];
127 	unsigned int layer_bufsize[VPBE_DISPLAY_MAX_DEVICES];
128 };
129 
130 #endif	/* VPBE_DISPLAY_H */
131