summaryrefstree
path: root/kernel/drivers/media/platform/exynos/fimc-is/fimc-is-subdev-ctrl.c
blob: 38b3a62f47893f7b07664aaa7e6ba40cc7b4186c (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
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
#include <linux/module.h>

#include "fimc-is-core.h"
#include "fimc-is-param.h"

int fimc_is_subdev_open(struct fimc_is_subdev *subdev,
	struct fimc_is_video_ctx *vctx,
	const struct param_control *init_ctl)
{
	int ret = 0;

	if (test_bit(FIMC_IS_SUBDEV_OPEN, &subdev->state)) {
		warn("subdev%d already open", subdev->entry);
		goto p_err;
	}

	mutex_init(&subdev->mutex_state);
	subdev->vctx = vctx;
	subdev->input.width = 0;
	subdev->input.height = 0;
	subdev->output.width = 0;
	subdev->output.height = 0;

	if (init_ctl) {
		if (init_ctl->cmd != CONTROL_COMMAND_START) {
			if ((subdev->entry == ENTRY_DIS) ||
					(subdev->entry == ENTRY_TDNR)) {
#if defined(ENABLE_VDIS) || defined(ENABLE_TDNR)
				err("%d entry is not start", subdev->entry);
#endif
			} else {
				err("%d entry is not start", subdev->entry);
			}
			ret = -EINVAL;
			goto p_err;
		}

		if (init_ctl->bypass == CONTROL_BYPASS_ENABLE)
			clear_bit(FIMC_IS_SUBDEV_START, &subdev->state);
		else if (init_ctl->bypass == CONTROL_BYPASS_DISABLE)
			set_bit(FIMC_IS_SUBDEV_START, &subdev->state);
		else {
			err("%d entry has invalid bypass value(%d)",
				subdev->entry, init_ctl->bypass);
			ret = -EINVAL;
			goto p_err;
		}
	} else {
		/* isp, scc, scp do not use bypass(memory interface)*/
		clear_bit(FIMC_IS_SUBDEV_START, &subdev->state);
	}

	set_bit(FIMC_IS_SUBDEV_OPEN, &subdev->state);

p_err:
	return ret;
}

int fimc_is_subdev_close(struct fimc_is_subdev *subdev)
{
	clear_bit(FIMC_IS_SUBDEV_OPEN, &subdev->state);

	return 0;
}

int fimc_is_subdev_start(struct fimc_is_device_ischain *device,
	struct fimc_is_subdev *subdev,
	struct fimc_is_queue *queue)
{
	return 0;
}

int fimc_is_subdev_stop(struct fimc_is_device_ischain *device,
	struct fimc_is_subdev *subdev,
	struct fimc_is_queue *queue)
{
	int ret = 0;
	unsigned long flags;
	struct fimc_is_framemgr *framemgr;
	struct fimc_is_frame *frame;

	BUG_ON(!queue);

	framemgr = &queue->framemgr;

/*
	if (!test_bit(FIMC_IS_SUBDEV_START, &subdev->state)) {
		mwarn("already stop", device);
		goto p_err;
	}
*/

	framemgr_e_barrier_irqs(framemgr, FMGR_IDX_18, flags);

	if (framemgr->frame_pro_cnt > 0) {
		framemgr_x_barrier_irqr(framemgr, FMGR_IDX_4, flags);
		merr("being processed, can't stop", device);
		ret = -EINVAL;
		goto p_err;
	}

	fimc_is_frame_complete_head(framemgr, &frame);
	while (frame) {
		fimc_is_frame_trans_com_to_fre(framemgr, frame);
		fimc_is_frame_complete_head(framemgr, &frame);
	}

	fimc_is_frame_request_head(framemgr, &frame);
	while (frame) {
		fimc_is_frame_trans_req_to_fre(framemgr, frame);
		fimc_is_frame_request_head(framemgr, &frame);
	}

	framemgr_x_barrier_irqr(framemgr, FMGR_IDX_18, flags);

//	clear_bit(FIMC_IS_SUBDEV_START, &subdev->state);

p_err:
	return ret;
}

int fimc_is_subdev_s_format(struct fimc_is_subdev *subdev,
	u32 width, u32 height)
{
	int ret = 0;

	BUG_ON(!subdev);

	subdev->output.width = width;
	subdev->output.height = height;

	return ret;
}

int fimc_is_subdev_buffer_queue(struct fimc_is_subdev *subdev,
	u32 index)
{
	int ret = 0;
	unsigned long flags;
	struct fimc_is_video_ctx *vctx;
	struct fimc_is_framemgr *framemgr;
	struct fimc_is_frame *frame;

	BUG_ON(!subdev);
	BUG_ON(!subdev->vctx);
	BUG_ON(index >= FRAMEMGR_MAX_REQUEST);

	vctx = subdev->vctx;
	framemgr = GET_DST_FRAMEMGR(vctx);

	/* 1. check frame validation */
	frame = &framemgr->frame[index];
	if (!frame) {
		merr("frame is null\n", vctx);
		ret = EINVAL;
		goto p_err;
	}

	if (unlikely(!test_bit(FRAME_INI_MEM, &frame->memory))) {
		err("frame %d is NOT init", index);
		ret = EINVAL;
		goto p_err;
	}

	/* 2. update frame manager */
	framemgr_e_barrier_irqs(framemgr, FMGR_IDX_19, flags);

	if (frame->state == FIMC_IS_FRAME_STATE_FREE) {
		if (frame->req_flag) {
			warn("%d request flag is not clear(%08X)\n",
				frame->index, (u32)frame->req_flag);
			frame->req_flag = 0;
		}

		fimc_is_frame_trans_fre_to_req(framemgr, frame);
	} else {
		merr("frame(%d) is invalid state(%d)\n", vctx, index, frame->state);
		fimc_is_frame_print_all(framemgr);
		ret = -EINVAL;
	}

	framemgr_x_barrier_irqr(framemgr, FMGR_IDX_19, flags);

p_err:
	return ret;
}

int fimc_is_subdev_buffer_finish(struct fimc_is_subdev *subdev,
	u32 index)
{
	int ret = 0;
	struct fimc_is_framemgr *framemgr;
	struct fimc_is_frame *frame;

	BUG_ON(!subdev);
	BUG_ON(index >= FRAMEMGR_MAX_REQUEST);

	framemgr = GET_SUBDEV_FRAMEMGR(subdev);
	if (!framemgr) {
		err("framemgr is NULL");
		ret = -EINVAL;
		goto p_err;
	}

	framemgr_e_barrier_irq(framemgr, FMGR_IDX_20);

	fimc_is_frame_complete_head(framemgr, &frame);
	if (frame) {
		if (frame->index == index) {
			fimc_is_frame_trans_com_to_fre(framemgr, frame);
		} else {
			err("buffer index is NOT matched(%d != %d)\n",
				index, frame->index);
			fimc_is_frame_print_all(framemgr);
			ret = -EINVAL;
		}
	} else {
		err("frame is empty from complete");
		fimc_is_frame_print_all(framemgr);
		ret = -EINVAL;
	}

	framemgr_x_barrier_irq(framemgr, FMGR_IDX_20);

p_err:
	return ret;
}

const struct fimc_is_queue_ops fimc_is_ischain_sub_ops = {
	.start_streaming	= fimc_is_subdev_start,
	.stop_streaming		= fimc_is_subdev_stop
};

void fimc_is_subdev_dis_start(struct fimc_is_device_ischain *device,
	struct dis_param *param, u32 *lindex, u32 *hindex, u32 *indexes)
{
	BUG_ON(!device);
	BUG_ON(!param);
	BUG_ON(!lindex);
	BUG_ON(!hindex);
	BUG_ON(!indexes);

#ifdef ENABLE_VDIS
	param->control.cmd = CONTROL_COMMAND_START;
	param->control.bypass = CONTROL_BYPASS_DISABLE;
	param->control.buffer_number = SIZE_DIS_INTERNAL_BUF * NUM_DIS_INTERNAL_BUF;
	param->control.buffer_address = device->imemory.dvaddr_shared + 300 * sizeof(u32);
	device->is_region->shared[300] = device->imemory.dvaddr_dis;
#else
	merr("can't start hw vdis", device);
	BUG();
#endif

	*lindex |= LOWBIT_OF(PARAM_DIS_CONTROL);
	*hindex |= HIGHBIT_OF(PARAM_DIS_CONTROL);
	(*indexes)++;
}

void fimc_is_subdev_dis_stop(struct fimc_is_device_ischain *device,
	struct dis_param *param, u32 *lindex, u32 *hindex, u32 *indexes)
{
	BUG_ON(!device);
	BUG_ON(!param);
	BUG_ON(!lindex);
	BUG_ON(!hindex);
	BUG_ON(!indexes);

	param->control.cmd = CONTROL_COMMAND_STOP;
	param->control.bypass = CONTROL_BYPASS_DISABLE;

	*lindex |= LOWBIT_OF(PARAM_DIS_CONTROL);
	*hindex |= HIGHBIT_OF(PARAM_DIS_CONTROL);
	(*indexes)++;
}

void fimc_is_subdev_dis_bypass(struct fimc_is_device_ischain *device,
	struct dis_param *param, u32 *lindex, u32 *hindex, u32 *indexes)
{
	BUG_ON(!device);
	BUG_ON(!param);
	BUG_ON(!lindex);
	BUG_ON(!hindex);
	BUG_ON(!indexes);

	if (device->pdata->subip_info->_dis.full_bypass)
		param->control.cmd = CONTROL_COMMAND_STOP;
	else
		param->control.cmd = CONTROL_COMMAND_START;
	/*
	 * special option
	 * bypass command should be 2 for enabling software dis
	 * software dis is not active because output format of software
	 * can't support multi-plane.
	 */
	param->control.bypass = CONTROL_BYPASS_ENABLE;

	*lindex |= LOWBIT_OF(PARAM_DIS_CONTROL);
	*hindex |= HIGHBIT_OF(PARAM_DIS_CONTROL);
	(*indexes)++;
}

void fimc_is_subdev_dnr_start(struct fimc_is_device_ischain *device,
	struct param_control *ctl_param, u32 *lindex, u32 *hindex, u32 *indexes)
{
	BUG_ON(!device);
	BUG_ON(!ctl_param);
	BUG_ON(!lindex);
	BUG_ON(!hindex);
	BUG_ON(!indexes);

	ctl_param->cmd = CONTROL_COMMAND_START;
	ctl_param->bypass = CONTROL_BYPASS_DISABLE;
	ctl_param->buffer_number = SIZE_DNR_INTERNAL_BUF * NUM_DNR_INTERNAL_BUF;
	ctl_param->buffer_address = device->imemory.dvaddr_shared + 350 * sizeof(u32);
	device->is_region->shared[350] = device->imemory.dvaddr_3dnr;

	*lindex |= LOWBIT_OF(PARAM_TDNR_CONTROL);
	*hindex |= HIGHBIT_OF(PARAM_TDNR_CONTROL);
	(*indexes)++;
}

void fimc_is_subdev_dnr_stop(struct fimc_is_device_ischain *device,
	struct param_control *ctl_param, u32 *lindex, u32 *hindex, u32 *indexes)
{
	BUG_ON(!device);
	BUG_ON(!ctl_param);
	BUG_ON(!lindex);
	BUG_ON(!hindex);
	BUG_ON(!indexes);

	ctl_param->cmd = CONTROL_COMMAND_STOP;
	ctl_param->bypass = CONTROL_BYPASS_DISABLE;

	*lindex |= LOWBIT_OF(PARAM_TDNR_CONTROL);
	*hindex |= HIGHBIT_OF(PARAM_TDNR_CONTROL);
	(*indexes)++;
}

void fimc_is_subdev_dnr_bypass(struct fimc_is_device_ischain *device,
	struct param_control *ctl_param, u32 *lindex, u32 *hindex, u32 *indexes)
{
	BUG_ON(!device);
	BUG_ON(!ctl_param);
	BUG_ON(!lindex);
	BUG_ON(!hindex);
	BUG_ON(!indexes);

	if (device->pdata->subip_info->_dnr.full_bypass)
		ctl_param->cmd = CONTROL_COMMAND_STOP;
	else
		ctl_param->cmd = CONTROL_COMMAND_START;

	ctl_param->bypass = CONTROL_BYPASS_ENABLE;

	*lindex |= LOWBIT_OF(PARAM_TDNR_CONTROL);
	*hindex |= HIGHBIT_OF(PARAM_TDNR_CONTROL);
	(*indexes)++;
}

void fimc_is_subdev_drc_start(struct fimc_is_device_ischain *device,
	struct param_control *ctl_param, u32 *lindex, u32 *hindex, u32 *indexes)
{
	BUG_ON(!device);
	BUG_ON(!ctl_param);
	BUG_ON(!lindex);
	BUG_ON(!hindex);
	BUG_ON(!indexes);

	ctl_param->cmd = CONTROL_COMMAND_START;
	ctl_param->bypass = CONTROL_BYPASS_DISABLE;
	*lindex |= LOWBIT_OF(PARAM_DRC_CONTROL);
	*hindex |= HIGHBIT_OF(PARAM_DRC_CONTROL);
	(*indexes)++;
}

void fimc_is_subdev_drc_bypass(struct fimc_is_device_ischain *device,
	struct param_control *ctl_param, u32 *lindex, u32 *hindex, u32 *indexes)
{
	BUG_ON(!device);
	BUG_ON(!ctl_param);
	BUG_ON(!lindex);
	BUG_ON(!hindex);
	BUG_ON(!indexes);

	if (device->pdata->subip_info->_drc.full_bypass)
		ctl_param->cmd = CONTROL_COMMAND_STOP;
	else
		ctl_param->cmd = CONTROL_COMMAND_START;

	ctl_param->bypass = CONTROL_BYPASS_ENABLE;

	*lindex |= LOWBIT_OF(PARAM_DRC_CONTROL);
	*hindex |= HIGHBIT_OF(PARAM_DRC_CONTROL);
	(*indexes)++;
}