• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2 *
3 * SPDX-License-Identifier: GPL-2.0
4 *
5 * Copyright (C) 2011-2018 ARM or its affiliates
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; version 2.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 * for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 *
18 */
19 
20 #ifndef _ISP_V4L2_STREAM_H_
21 #define _ISP_V4L2_STREAM_H_
22 
23 #include <linux/version.h>
24 #include <linux/utsname.h>
25 
26 #include <linux/videodev2.h>
27 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 4, 0))
28 #include <media/videobuf2-v4l2.h>
29 #endif
30 
31 #include "acamera_firmware_api.h"
32 #include <linux/platform_device.h>
33 
34 #include "isp-v4l2-common.h"
35 
36 /* buffer for one video frame */
37 typedef struct _isp_v4l2_buffer {
38     /* vb or vvb (depending on kernel version) must be first */
39 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 4, 0))
40     struct vb2_v4l2_buffer vvb;
41 #else
42     struct vb2_buffer vb;
43 #endif
44 
45     struct list_head list;
46 } isp_v4l2_buffer_t;
47 
48 /**
49  * struct isp_v4l2_stream_common
50  */
51 typedef struct _isp_v4l2_frame_sizes {
52     /* resolution table for FR stream */
53     struct v4l2_frmsize_discrete frmsize[MAX_SENSOR_PRESET_SIZE]; /* for now this is same since FR path doesn't have downscaler block */
54     uint8_t frmsize_num;
55 } isp_v4l2_frame_sizes;
56 
57 typedef struct _isp_v4l2_stream_common {
58     isp_v4l2_sensor_info sensor_info;
59     isp_v4l2_frame_sizes snapshot_sizes;
60 } isp_v4l2_stream_common;
61 
62 /* frame for internal list for copy */
63 typedef struct isp_fw_frame {
64     int state;
65     uint32_t addr[VIDEO_MAX_PLANES]; //multiplanar addresses
66     metadata_t meta;
67     tframe_t tframe;
68 } isp_v4l2_frame_t;
69 
70 /**
71  * struct isp_fw_frame_mgr - Manager in ISP firmware to handle coming frames
72  *
73  * NOTE: For the frame_buffer, it's not served as a FIFO, if the buffer is full,
74  *       and still some new frames are coming, the old frames will be discarded.
75  *       that means, idx_output will be overwritten with the newest frame info
76  *       and then idx_output will be set to the second older frame.
77  */
78 typedef struct isp_fw_frame_mgr {
79     isp_v4l2_frame_t frame_buffer; /* used to be an array, now it's just message box */
80     spinlock_t frame_slock;        /* lock to protect the frame_buffer */
81     wait_queue_head_t frame_wq;
82 } isp_fw_frame_mgr_t;
83 
84 /**
85  * struct isp_v4l2_stream_t - All internal data for one instance of ISP
86  */
87 typedef struct _isp_v4l2_stream_t {
88     /* Control fields */
89     uint32_t ctx_id;
90     int stream_id;
91     isp_v4l2_stream_type_t stream_type;
92     int stream_started;
93     uint32_t last_frame_id;
94 
95     /* Input stream */
96     isp_v4l2_stream_common *stream_common;
97 
98     /* Stream format */
99     struct v4l2_format cur_v4l2_fmt;
100 
101     /* Video buffer field*/
102     struct list_head stream_buffer_list;
103     struct list_head stream_buffer_list_busy;
104     spinlock_t slock;
105 
106     /* Temporal fields for memcpy */
107     struct task_struct *kthread_stream;
108 #if ISP_HAS_META_CB
109     atomic_t running; //since metadata has no thread for syncing
110 #endif
111     isp_fw_frame_mgr_t frame_mgr;
112     int fw_frame_seq_count;
113     struct vb2_queue* vb2_q;
114     struct ion_client *ion_client;
115 } isp_v4l2_stream_t;
116 
117 
118 /* stream control interface */
119 int isp_v4l2_stream_init_static_resources( struct platform_device *pdev, uint32_t ctx_id );
120 void isp_v4l2_stream_deinit_static_resources( struct platform_device *pdev );
121 int isp_v4l2_stream_init( isp_v4l2_stream_t **ppstream, int stream_id, int ctx_num );
122 void isp_v4l2_stream_deinit( isp_v4l2_stream_t *pstream, int stream_on_count );
123 int isp_v4l2_stream_on( isp_v4l2_stream_t *pstream );
124 void isp_v4l2_stream_off( isp_v4l2_stream_t *pstream, int stream_on_count );
125 
126 /* stream configuration interface */
127 int isp_v4l2_stream_enum_framesizes( isp_v4l2_stream_t *pstream, struct v4l2_frmsizeenum *fsize );
128 int isp_v4l2_stream_enum_format( isp_v4l2_stream_t *pstream, struct v4l2_fmtdesc *f );
129 int isp_v4l2_stream_try_format( isp_v4l2_stream_t *pstream, struct v4l2_format *f );
130 int isp_v4l2_stream_get_format( isp_v4l2_stream_t *pstream, struct v4l2_format *f );
131 int isp_v4l2_stream_set_format( isp_v4l2_stream_t *pstream, struct v4l2_format *f );
132 
133 int isp_v4l2_get_cropcap(isp_v4l2_stream_t *pstream, struct v4l2_cropcap *cap);
134 int isp_v4l2_set_crop(isp_v4l2_stream_t *pstream, const struct v4l2_crop *crop);
135 int isp_v4l2_get_crop(isp_v4l2_stream_t *pstream, struct v4l2_crop *crop);
136 int isp_v4l2_stream_enum_frameintervals( isp_v4l2_stream_t *pstream, struct v4l2_frmivalenum *fival );
137 
138 #endif
139