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-dma-contig.h>
21#include <media/davinci/vpbe_types.h>
22#include <media/davinci/vpbe_osd.h>
23#include <media/davinci/vpbe.h>
24
25#define VPBE_DISPLAY_MAX_DEVICES 2
26
27enum vpbe_display_device_id {
28	VPBE_DISPLAY_DEVICE_0,
29	VPBE_DISPLAY_DEVICE_1
30};
31
32#define VPBE_DISPLAY_DRV_NAME	"vpbe-display"
33
34#define VPBE_DISPLAY_MAJOR_RELEASE              1
35#define VPBE_DISPLAY_MINOR_RELEASE              0
36#define VPBE_DISPLAY_BUILD                      1
37#define VPBE_DISPLAY_VERSION_CODE ((VPBE_DISPLAY_MAJOR_RELEASE << 16) | \
38	(VPBE_DISPLAY_MINOR_RELEASE << 8)  | \
39	VPBE_DISPLAY_BUILD)
40
41#define VPBE_DISPLAY_VALID_FIELD(field)   ((V4L2_FIELD_NONE == field) || \
42	 (V4L2_FIELD_ANY == field) || (V4L2_FIELD_INTERLACED == field))
43
44/* Exp ratio numerator and denominator constants */
45#define VPBE_DISPLAY_H_EXP_RATIO_N	9
46#define VPBE_DISPLAY_H_EXP_RATIO_D	8
47#define VPBE_DISPLAY_V_EXP_RATIO_N	6
48#define VPBE_DISPLAY_V_EXP_RATIO_D	5
49
50/* Zoom multiplication factor */
51#define VPBE_DISPLAY_ZOOM_4X	4
52#define VPBE_DISPLAY_ZOOM_2X	2
53
54/* Structures */
55struct display_layer_info {
56	int enable;
57	/* Layer ID used by Display Manager */
58	enum osd_layer id;
59	struct osd_layer_config config;
60	enum osd_zoom_factor h_zoom;
61	enum osd_zoom_factor v_zoom;
62	enum osd_h_exp_ratio h_exp;
63	enum osd_v_exp_ratio v_exp;
64};
65
66struct vpbe_disp_buffer {
67	struct vb2_buffer vb;
68	struct list_head list;
69};
70
71/* vpbe display object structure */
72struct vpbe_layer {
73	/* number of buffers in fbuffers */
74	unsigned int numbuffers;
75	/* Pointer to the vpbe_display */
76	struct vpbe_display *disp_dev;
77	/* Pointer pointing to current v4l2_buffer */
78	struct vpbe_disp_buffer *cur_frm;
79	/* Pointer pointing to next v4l2_buffer */
80	struct vpbe_disp_buffer *next_frm;
81	/* videobuf specific parameters
82	 * Buffer queue used in video-buf
83	 */
84	struct vb2_queue buffer_queue;
85	/* allocator-specific contexts for each plane */
86	struct vb2_alloc_ctx *alloc_ctx;
87	/* Queue of filled frames */
88	struct list_head dma_queue;
89	/* Used in video-buf */
90	spinlock_t irqlock;
91	/* V4l2 specific parameters */
92	/* Identifies video device for this layer */
93	struct video_device video_dev;
94	/* This field keeps track of type of buffer exchange mechanism user
95	 * has selected
96	 */
97	enum v4l2_memory memory;
98	/* Used to store pixel format */
99	struct v4l2_pix_format pix_fmt;
100	enum v4l2_field buf_field;
101	/* Video layer configuration params */
102	struct display_layer_info layer_info;
103	/* vpbe specific parameters
104	 * enable window for display
105	 */
106	unsigned char window_enable;
107	/* number of open instances of the layer */
108	unsigned int usrs;
109	/* number of users performing IO */
110	unsigned int io_usrs;
111	/* Indicates id of the field which is being displayed */
112	unsigned int field_id;
113	/* Indicates whether streaming started */
114	unsigned char started;
115	/* Identifies device object */
116	enum vpbe_display_device_id device_id;
117	/* facilitation of ioctl ops lock by v4l2*/
118	struct mutex opslock;
119	u8 layer_first_int;
120};
121
122/* vpbe device structure */
123struct vpbe_display {
124	/* layer specific parameters */
125	/* lock for isr updates to buf layers*/
126	spinlock_t dma_queue_lock;
127	/* C-Plane offset from start of y-plane */
128	unsigned int cbcr_ofst;
129	struct vpbe_layer *dev[VPBE_DISPLAY_MAX_DEVICES];
130	struct vpbe_device *vpbe_dev;
131	struct osd_state *osd_device;
132};
133
134/* File handle structure */
135struct vpbe_fh {
136	struct v4l2_fh fh;
137	/* vpbe device structure */
138	struct vpbe_display *disp_dev;
139	/* pointer to layer object for opened device */
140	struct vpbe_layer *layer;
141	/* Indicates whether this file handle is doing IO */
142	unsigned char io_allowed;
143};
144
145struct buf_config_params {
146	unsigned char min_numbuffers;
147	unsigned char numbuffers[VPBE_DISPLAY_MAX_DEVICES];
148	unsigned int min_bufsize[VPBE_DISPLAY_MAX_DEVICES];
149	unsigned int layer_bufsize[VPBE_DISPLAY_MAX_DEVICES];
150};
151
152#endif	/* VPBE_DISPLAY_H */
153