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
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
|
/*
* Samsung Exynos SoC series FIMC-IS driver
*
* exynos5 fimc-is group manager functions
*
* Copyright (c) 2016 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.
*/
#include <linux/module.h>
#include <linux/delay.h>
#include <linux/kernel.h>
#include <linux/errno.h>
#include <linux/interrupt.h>
#include <linux/device.h>
#include <linux/platform_device.h>
#include <linux/slab.h>
#include <video/videonode.h>
#include <asm/cacheflush.h>
#include <asm/pgtable.h>
#include <linux/firmware.h>
#include <linux/dma-mapping.h>
#include <linux/scatterlist.h>
#include <linux/videodev2.h>
#include <linux/videodev2_exynos_camera.h>
#include <linux/v4l2-mediabus.h>
#include <linux/bug.h>
#include "is-hw.h"
#include "is-core.h"
#include "is-type.h"
#include "is-err.h"
#include "is-video.h"
#include "is-framemgr.h"
#include "is-groupmgr.h"
#include "is-devicemgr.h"
#include "is-device-ischain.h"
#include "is-hw-control.h"
#ifdef CONFIG_USE_SENSOR_GROUP
struct is_group *get_ischain_leader_group(struct is_device_ischain *device)
{
struct is_group *leader_group;
leader_group = device->groupmgr->leader[device->instance];
if ((leader_group->device_type == IS_DEVICE_SENSOR)
&& (leader_group->next)
&& (!test_bit(IS_GROUP_OTF_INPUT, &leader_group->next->state))) {
leader_group = leader_group->next;
}
return leader_group;
}
static void do_sensor_tag(unsigned long data)
{
int ret = 0;
u32 stream;
unsigned long framemgr_flag;
struct is_framemgr *framemgr;
struct v4l2_subdev *subdev;
struct camera2_node ldr_node = {0, };
struct is_device_sensor *sensor;
struct devicemgr_sensor_tag_data *tag_data;
struct is_group *group;
struct is_frame *frame;
struct is_group_task *gtask;
tag_data = (struct devicemgr_sensor_tag_data *)data;
stream = tag_data->stream;
sensor = tag_data->devicemgr->sensor[stream];
group = tag_data->group;
subdev = sensor->subdev_csi;
gtask = &sensor->groupmgr->gtask[group->id];
mgrdbgs(5, "start sensor tag(%s)\n", group->device, group, tag_data,
in_softirq() ? "S" : "H");
if (unlikely(test_bit(IS_GROUP_FORCE_STOP, &group->state))) {
mgwarn(" cancel by fstop", group, group);
goto p_err;
}
if (unlikely(test_bit(IS_GTASK_REQUEST_STOP, >ask->state))) {
mgerr(" cancel by gstop", group, group);
goto p_err;
}
framemgr = GET_HEAD_GROUP_FRAMEMGR(group);
if (!framemgr) {
merr("framemgr is NULL", group);
return;
}
framemgr_e_barrier_irqs(framemgr, 0, framemgr_flag);
frame = find_frame(framemgr, FS_PROCESS, frame_fcount, (void *)(ulong)tag_data->fcount);
if (!frame) {
frame_manager_print_queues(framemgr);
merr("[F%d] There's no frame in processing." \
"Can't sync sensor and ischain buffer anymore..",
group, tag_data->fcount);
framemgr_x_barrier_irqr(framemgr, 0, framemgr_flag);
return;
}
framemgr_x_barrier_irqr(framemgr, 0, framemgr_flag);
ldr_node = frame->shot_ext->node_group.leader;
ret = is_sensor_group_tag(sensor, frame, &ldr_node);
if (ret) {
merr("is_sensor_group_tag is fail(%d)", group, ret);
goto p_err;
}
mgrdbgs(5, "finish sensor tag(%s)\n", group->device, group, tag_data,
in_softirq() ? "S" : "H");
p_err:
return;
}
int is_devicemgr_probe(struct is_devicemgr *devicemgr)
{
int ret = 0;
return ret;
}
int is_devicemgr_open(struct is_devicemgr *devicemgr,
void *device, enum is_device_type type)
{
int ret = 0;
u32 stream = 0;
u32 group_id;
struct is_core *core;
struct is_group *group = NULL;
struct is_device_sensor *sensor;
struct is_device_ischain *ischain;
FIMC_BUG(!devicemgr);
FIMC_BUG(!device);
switch (type) {
case IS_DEVICE_SENSOR:
sensor = (struct is_device_sensor *)device;
group = &sensor->group_sensor;
core = sensor->private_data;
FIMC_BUG(!core);
FIMC_BUG(!group);
FIMC_BUG(!sensor->vctx);
FIMC_BUG(!GET_VIDEO(sensor->vctx));
/* get the stream id */
for (stream = 0; stream < IS_STREAM_COUNT; ++stream) {
ischain = &core->ischain[stream];
if (!test_bit(IS_ISCHAIN_OPEN, &ischain->state))
break;
}
FIMC_BUG(stream >= IS_STREAM_COUNT);
/* init group's device information */
devicemgr->sensor[stream] = sensor;
sensor->instance = stream;
group->instance = stream;
group->sensor_id = sensor->sensor_id;
group->device = ischain;
group_id = GROUP_ID_SS0 + GET_SSX_ID(GET_VIDEO(sensor->vctx));
ret = is_group_open(sensor->groupmgr,
group,
group_id,
sensor->vctx);
if (ret) {
merr("is_group_open is fail(%d)", ischain, ret);
ret = -EINVAL;
goto p_err;
}
sensor->vctx->next_device = ischain;
break;
case IS_DEVICE_ISCHAIN:
ischain = (struct is_device_ischain *)device;
stream = ischain->instance;
devicemgr->ischain[stream] = ischain;
break;
default:
err("device type(%d) is invalid", type);
BUG();
break;
}
p_err:
return ret;
}
int is_devicemgr_binding(struct is_devicemgr *devicemgr,
struct is_device_sensor *sensor,
struct is_device_ischain *ischain,
enum is_device_type type)
{
int ret = 0;
struct is_group *group = NULL;
struct is_group *child_group;
switch (type) {
case IS_DEVICE_SENSOR:
if (test_bit(IS_SENSOR_STAND_ALONE, &sensor->state)) {
/* in case of sensor driving */
ischain->sensor = sensor;
sensor->ischain = ischain;
/* Clear ischain device all state */
ischain->state = 0;
/*
* Forcely set the ischain's state to "Opened"
* Because if it's sensor driving mode, ischain was not opened from HAL.
*/
set_bit(IS_ISCHAIN_OPEN, &ischain->state);
ret = is_groupmgr_init(sensor->groupmgr, ischain);
if (ret) {
merr("is_groupmgr_init is fail(%d)", ischain, ret);
ret = -EINVAL;
goto p_err;
}
}
break;
case IS_DEVICE_ISCHAIN:
if (sensor &&
!test_bit(IS_ISCHAIN_REPROCESSING, &ischain->state)) {
group = &sensor->group_sensor;
FIMC_BUG(group->instance != ischain->instance);
child_group = GET_HEAD_GROUP_IN_DEVICE(IS_DEVICE_ISCHAIN, group);
if (child_group) {
info("[%d/%d] sensor otf output set\n",
sensor->device_id, ischain->instance);
set_bit(IS_SENSOR_OTF_OUTPUT, &sensor->state);
}
}
break;
default:
err("device type(%d) is invalid", type);
BUG();
break;
}
p_err:
return ret;
}
int is_devicemgr_start(struct is_devicemgr *devicemgr,
void *device, enum is_device_type type)
{
int ret = 0;
struct is_group *group;
struct is_device_sensor *sensor;
switch (type) {
case IS_DEVICE_SENSOR:
sensor = (struct is_device_sensor *)device;
group = &sensor->group_sensor;
if (!test_bit(IS_SENSOR_STAND_ALONE, &sensor->state) && sensor->ischain) {
ret = is_ischain_start_wrap(sensor->ischain, group);
if (ret) {
merr("is_ischain_start_wrap is fail(%d)", sensor->ischain, ret);
ret = -EINVAL;
goto p_err;
}
} else {
ret = is_groupmgr_start(sensor->groupmgr, group->device);
if (ret) {
merr("is_groupmgr_start is fail(%d)", group->device, ret);
ret = -EINVAL;
goto p_err;
}
}
if (IS_ENABLED(CHAIN_TAG_SENSOR_IN_SOFTIRQ_CONTEXT)) {
struct is_group *child_group
= GET_HEAD_GROUP_IN_DEVICE(IS_DEVICE_ISCHAIN, group);
/* only in case of OTF case, uses tasklet. */
if (sensor->ischain && child_group)
tasklet_init(&devicemgr->tasklet[group->instance], do_sensor_tag,
(unsigned long)&devicemgr->tag_data[group->instance]);
}
break;
case IS_DEVICE_ISCHAIN:
break;
default:
err("device type(%d) is invalid", type);
BUG();
break;
}
p_err:
return ret;
}
int is_devicemgr_stop(struct is_devicemgr *devicemgr,
void *device, enum is_device_type type)
{
int ret = 0;
struct is_group *group;
struct is_device_sensor *sensor;
switch (type) {
case IS_DEVICE_SENSOR:
sensor = (struct is_device_sensor *)device;
group = &sensor->group_sensor;
if (IS_ENABLED(CHAIN_TAG_SENSOR_IN_SOFTIRQ_CONTEXT)) {
struct is_group *child_group
= GET_HEAD_GROUP_IN_DEVICE(IS_DEVICE_ISCHAIN, group);
if (sensor->ischain && child_group)
tasklet_kill(&devicemgr->tasklet[group->instance]);
}
if (!test_bit(IS_SENSOR_STAND_ALONE, &sensor->state) && sensor->ischain) {
ret = is_ischain_stop_wrap(sensor->ischain, group);
if (ret) {
merr("is_ischain_stop_wrap is fail(%d)", sensor->ischain, ret);
ret = -EINVAL;
goto p_err;
}
} else {
ret = is_groupmgr_stop(sensor->groupmgr, group->device);
if (ret) {
merr("is_groupmgr_stop is fail(%d)", group->device, ret);
ret = -EINVAL;
goto p_err;
}
}
break;
case IS_DEVICE_ISCHAIN:
break;
default:
err("device type(%d) is invalid", type);
BUG();
break;
}
p_err:
return ret;
}
int is_devicemgr_close(struct is_devicemgr *devicemgr,
void *device, enum is_device_type type)
{
int ret = 0;
struct is_group *group;
struct is_device_sensor *sensor;
switch (type) {
case IS_DEVICE_SENSOR:
sensor = (struct is_device_sensor *)device;
FIMC_BUG(!sensor);
group = &sensor->group_sensor;
ret = is_group_close(sensor->groupmgr, group);
if (ret)
merr("is_group_close is fail", sensor);
/*
* Forcely set the ischain's state to "Not Opened"
* Because if it's sensor driving mode, ischain was not opened from HAL.
*/
if (test_bit(IS_SENSOR_STAND_ALONE, &sensor->state) && sensor->ischain)
clear_bit(IS_ISCHAIN_OPEN, &sensor->ischain->state);
break;
case IS_DEVICE_ISCHAIN:
break;
default:
err("device type(%d) is invalid", type);
BUG();
break;
}
return ret;
}
int is_devicemgr_shot_callback(struct is_group *group,
struct is_frame *frame,
u32 fcount,
enum is_device_type type)
{
int ret = 0;
unsigned long flags;
struct is_group *child_group;
struct camera2_node ldr_node = {0, };
struct is_devicemgr *devicemgr;
struct devicemgr_sensor_tag_data *tag_data;
u32 stream;
int vc;
struct is_subdev *subdev;
struct is_device_sensor *sensor;
switch (type) {
case IS_DEVICE_SENSOR:
child_group = GET_HEAD_GROUP_IN_DEVICE(IS_DEVICE_ISCHAIN, group);
PROGRAM_COUNT(9);
mgrdbgs(1, " DEVICE SHOT CALLBACK(%d) %s\n", group->device,
group, frame, frame->index, child_group ? "OTF" : "M2M");
/* OTF */
/* IS_SENSOR_OTF_OUTPUT bit needs to check also.
* because this bit can be cleared for not operate child_group_shot at remosaic sensor mode
*/
if (child_group && test_bit(IS_SENSOR_OTF_OUTPUT, &group->device->sensor->state)) {
ret = child_group->shot_callback(child_group->device, frame);
if (ret) {
mgerr("child_group->shot_callback(%d)", child_group, child_group, ret);
goto p_err;
}
/* M2M */
} else {
ret = is_sensor_group_tag(group->device->sensor, frame, &ldr_node);
if (ret) {
merr("is_sensor_group_tag is fail(%d)", group, ret);
mginfo("[F%d] Start CANCEL Other subdev frame\n", group->device, group, frame->fcount);
flags = is_group_lock(group, group->device_type, true);
is_group_subdev_cancel(group, frame, group->device_type, FS_PROCESS, true);
is_group_subdev_cancel(group, frame, group->device_type, FS_REQUEST, false);
is_group_unlock(group, flags, group->device_type, true);
mginfo("[F%d] End CANCEL Other subdev frame\n", group->device, group, frame->fcount);
ret = -EINVAL;
goto p_err;
}
}
PROGRAM_COUNT(10);
break;
case IS_DEVICE_ISCHAIN:
/* Only for sensor group with OTF */
if (group->head->device_type != IS_DEVICE_SENSOR)
break;
sensor = group->head->sensor;
for (vc = ENTRY_SSVC0; vc <= ENTRY_SSVC3; vc++) {
subdev = group->head->subdev[vc];
if (subdev && test_bit(IS_SUBDEV_VOTF_USE, &subdev->state)) {
ret = is_sensor_votf_tag(sensor, subdev);
if (ret)
msrwarn("votf_frame is drop(%d)", sensor, subdev, frame, ret);
}
}
if (frame->type != SHOT_TYPE_EXTERNAL)
break;
devicemgr = group->device->devicemgr;
stream = group->instance;
tag_data = &devicemgr->tag_data[stream];
tag_data->fcount = fcount;
tag_data->devicemgr = devicemgr;
tag_data->group = &devicemgr->sensor[stream]->group_sensor;
tag_data->stream = stream;
if (IS_ENABLED(CHAIN_TAG_SENSOR_IN_SOFTIRQ_CONTEXT)) {
mgrdbgs(1, "schedule sensor tag tasklet\n", group->device, group, frame);
tasklet_schedule(&devicemgr->tasklet[stream]);
} else { /* (hard)IRQ context */
do_sensor_tag((unsigned long)tag_data);
}
break;
default:
mgerr("device type(%d) is invalid", group, group, group->device_type);
BUG();
break;
}
p_err:
return ret;
}
int is_devicemgr_shot_done(struct is_group *group,
struct is_frame *ldr_frame,
u32 status)
{
int ret = 0;
unsigned long flags;
/* skip in case of the sensor -> 3AA M2M case */
if (group->device_type == IS_DEVICE_ISCHAIN)
return ret;
/* if error happened, cancel the sensor's subdev frames */
if (status) {
mginfo("[F%d] Start CANCEL Other subdev frame\n", group->device, group, ldr_frame->fcount);
flags = is_group_lock(group, group->device_type, false);
is_group_subdev_cancel(group, ldr_frame, group->device_type, FS_PROCESS, true);
is_group_subdev_cancel(group, ldr_frame, group->device_type, FS_REQUEST, false);
is_group_unlock(group, flags, group->device_type, false);
mginfo("[F%d] End CANCEL Other subdev frame\n", group->device, group, ldr_frame->fcount);
}
return ret;
}
#else
struct is_group *get_ischain_leader_group(struct is_device_ischain *device)
{
return device->groupmgr->leader[device->instance];
}
int is_devicemgr_probe(struct is_devicemgr *devicemgr)
{
return 0;
}
int is_devicemgr_open(struct is_devicemgr *devicemgr,
void *device, enum is_device_type type)
{
return 0;
}
int is_devicemgr_binding(struct is_devicemgr *devicemgr,
struct is_device_sensor *sensor,
struct is_device_ischain *ischain,
enum is_device_type type)
{
return 0;
}
int is_devicemgr_start(struct is_devicemgr *devicemgr,
void *device, enum is_device_type type)
{
return 0;
}
int is_devicemgr_stop(struct is_devicemgr *devicemgr,
void *device, enum is_device_type type)
{
return 0;
}
int is_devicemgr_close(struct is_devicemgr *devicemgr,
void *device, enum is_device_type type)
{
return 0;
}
int is_devicemgr_shot_callback(struct is_group *group,
struct is_frame *frame,
u32 fcount,
enum is_device_type type)
{
return 0;
}
int is_devicemgr_shot_done(struct is_group *group,
struct is_frame *ldr_frame,
u32 status)
{
return 0;
}
#endif
|