summaryrefstree
path: root/kernel/drivers/media/platform/exynos/fimc-is2/fimc-is-groupmgr.h
blob: bd19fe1e14825aa06d049ec9aa56cab17cedbe66 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
/*
 * Samsung Exynos5 SoC series FIMC-IS driver
 *
 *
 * Copyright (c) 2011 Samsung Electronics Co., Ltd
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 as
 * published by the Free Software Foundation.
 */

#ifndef FIMC_IS_GROUP_MGR_H
#define FIMC_IS_GROUP_MGR_H

#include "fimc-is-config.h"
#include "fimc-is-time.h"
#include "fimc-is-subdev-ctrl.h"
#include "fimc-is-video.h"
#include "fimc-is-cmd.h"

/* #define DEBUG_AA */
/* #define DEBUG_FLASH */

#define TRACE_GROUP
#define GROUP_ID_3AA0		0
#define GROUP_ID_3AA1		1
#define GROUP_ID_ISP0		2
#define GROUP_ID_ISP1		3
#define GROUP_ID_DIS0		4
#define GROUP_ID_MCS0		5
#define GROUP_ID_MCS1		6
#define GROUP_ID_VRA0		7
#define GROUP_ID_MAX		8
#define GROUP_ID_INVALID	0xFFFFFFFF
#define GROUP_ID_PARM_MASK	(0x3F)
#define GROUP_ID_SHIFT		(16)
#define GROUP_ID_MASK		(0xFFFF)
#define GROUP_ID(id)		(1 << (id))

#define GROUP_SLOT_3AA		0
#define GROUP_SLOT_ISP		1
#define GROUP_SLOT_DIS		2
#define GROUP_SLOT_MCS		3
#define GROUP_SLOT_VRA		4
#define GROUP_SLOT_MAX		5

#define FIMC_IS_MAX_GFRAME	(VIDEO_MAX_FRAME * 2) /* max shot buffer of F/W : 32, MAX 2 groups */
#define MIN_OF_ASYNC_SHOTS	1
#define MIN_OF_SYNC_SHOTS	2
#define MIN_OF_SHOT_RSC		(MIN_OF_ASYNC_SHOTS + MIN_OF_SYNC_SHOTS)

enum fimc_is_group_state {
	FIMC_IS_GROUP_OPEN,
	FIMC_IS_GROUP_INIT,
	FIMC_IS_GROUP_START,
	FIMC_IS_GROUP_SHOT,
	FIMC_IS_GROUP_REQUEST_FSTOP,
	FIMC_IS_GROUP_FORCE_STOP,
	FIMC_IS_GROUP_OTF_INPUT,
	FIMC_IS_GROUP_OTF_OUTPUT,
	FIMC_IS_GROUP_PIPE_INPUT,
	FIMC_IS_GROUP_PIPE_OUTPUT,
	FIMC_IS_GROUP_SEMI_PIPE_INPUT,
	FIMC_IS_GROUP_SEMI_PIPE_OUTPUT,
	FIMC_IS_GROUP_UNMAP
};

enum fimc_is_group_input_type {
	GROUP_INPUT_MEMORY,
	GROUP_INPUT_OTF,
	GROUP_INPUT_PIPE,
	GROUP_INPUT_SEMI_PIPE
};

struct fimc_is_frame;
struct fimc_is_device_ischain;
typedef int (*fimc_is_shot_callback)(struct fimc_is_device_ischain *device,
	struct fimc_is_frame *frame);
typedef int (*fimc_is_pipe_shot_callback)(struct fimc_is_device_ischain *device,
	struct fimc_is_group *group,
	struct fimc_is_frame *frame);

struct fimc_is_group_frame {
	struct list_head		list;
	u32				fcount;
	struct fimc_is_crop		canv;
	struct camera2_node_group	group_cfg[GROUP_SLOT_MAX];
};

struct fimc_is_group_framemgr {
	struct fimc_is_group_frame	gframe[FIMC_IS_MAX_GFRAME];
	spinlock_t			gframe_slock;
	struct list_head		gframe_head;
	u32				gframe_cnt;
};

struct fimc_is_group {
	struct fimc_is_group		*next;
	struct fimc_is_group		*prev;
	struct fimc_is_group		*gnext;
	struct fimc_is_group		*gprev;
	struct fimc_is_group		*parent;
	struct fimc_is_group		*child;
	struct fimc_is_group		*tail;

	struct fimc_is_subdev		leader;
	struct fimc_is_subdev		*junction;
	struct fimc_is_subdev		*subdev[ENTRY_ISCHAIN_END];

	/* for otf interface */
	atomic_t			sensor_fcount;
	atomic_t			backup_fcount;
	struct semaphore		smp_trigger;
	struct semaphore		smp_shot;
	atomic_t			smp_shot_count;
	u32				init_shots;
	u32				asyn_shots;
	u32				sync_shots;
	u32				skip_shots;
#ifdef ENABLE_FAST_SHOT
	struct camera2_ctl		fast_ctl;
#endif
	struct camera2_aa_ctl		intent_ctl;

	u32				id; /* group id */
	u32				slot; /* group slot */
	u32				instance; /* device instance */
	u32				source_vid; /* source video id */
	u32				pcount; /* program count */
	u32				fcount; /* frame count */
	atomic_t			scount; /* shot count */
	atomic_t			rcount; /* request count */
	unsigned long			state;

	struct list_head		gframe_head;
	u32				gframe_cnt;

	fimc_is_shot_callback		shot_callback;
	fimc_is_pipe_shot_callback	pipe_shot_callback;
	struct fimc_is_device_ischain	*device;

#ifdef DEBUG_AA
#ifdef DEBUG_FLASH
	enum aa_ae_flashmode		flashmode;
	struct camera2_flash_dm		flash;
#endif
#endif

#ifdef MEASURE_TIME
#ifdef MONITOR_TIME
	struct fimc_is_time		time;
#endif
#endif
	u32				aeflashMode; /* Flash Mode Control */
};

enum fimc_is_group_task_state {
	FIMC_IS_GTASK_START,
	FIMC_IS_GTASK_REQUEST_STOP
};

struct fimc_is_group_task {
	u32				id;
	struct task_struct		*task;
	struct kthread_worker		worker;
	struct semaphore		smp_resource;
	unsigned long			state;
	atomic_t			refcount;
};

struct fimc_is_groupmgr {
	struct fimc_is_group_framemgr	gframemgr[FIMC_IS_STREAM_COUNT];
	struct fimc_is_group		*leader[FIMC_IS_STREAM_COUNT];
	struct fimc_is_group		*group[FIMC_IS_STREAM_COUNT][GROUP_SLOT_MAX];
	struct fimc_is_group_task	gtask[GROUP_ID_MAX];
};

int fimc_is_groupmgr_probe(struct fimc_is_groupmgr *groupmgr);
int fimc_is_groupmgr_init(struct fimc_is_groupmgr *groupmgr,
	struct fimc_is_device_ischain *device);
int fimc_is_groupmgr_start(struct fimc_is_groupmgr *groupmgr,
	struct fimc_is_device_ischain *device);
int fimc_is_groupmgr_stop(struct fimc_is_groupmgr *groupmgr,
	struct fimc_is_device_ischain *device);

int fimc_is_group_probe(struct fimc_is_groupmgr *groupmgr,
	struct fimc_is_group *group,
	struct fimc_is_device_ischain *device,
	fimc_is_shot_callback shot_callback,
	u32 slot,
	u32 id,
	char *name,
	const struct fimc_is_subdev_ops *sops);
int fimc_is_group_open(struct fimc_is_groupmgr *groupmgr,
	struct fimc_is_group *group, u32 id,
	struct fimc_is_video_ctx *vctx);
int fimc_is_group_close(struct fimc_is_groupmgr *groupmgr,
	struct fimc_is_group *group);
int fimc_is_group_init(struct fimc_is_groupmgr *groupmgr,
	struct fimc_is_group *group,
	u32 input_type,
	u32 video_id,
	u32 stream_leader);
int fimc_is_group_start(struct fimc_is_groupmgr *groupmgr,
	struct fimc_is_group *group);
int fimc_is_group_stop(struct fimc_is_groupmgr *groupmgr,
	struct fimc_is_group *group);
int fimc_is_group_buffer_queue(struct fimc_is_groupmgr *groupmgr,
	struct fimc_is_group *group,
	struct fimc_is_queue *queue,
	u32 index);
int fimc_is_group_buffer_finish(struct fimc_is_groupmgr *groupmgr,
	struct fimc_is_group *group, u32 index);
int fimc_is_group_shot(struct fimc_is_groupmgr *groupmgr,
	struct fimc_is_group *group,
	struct fimc_is_frame *frame);
int fimc_is_group_done(struct fimc_is_groupmgr *groupmgr,
	struct fimc_is_group *group,
	struct fimc_is_frame *frame,
	u32 done_state);

int fimc_is_gframe_cancel(struct fimc_is_groupmgr *groupmgr,
	struct fimc_is_group *group, u32 target_fcount);

#endif