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
|
/*
* Samsung Exynos SoC series Pablo driver
*
* Copyright (c) 2019 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/errno.h>
#include "votf/camerapp-votf.h"
#include "is-votfmgr.h"
#include "is-votf-id-table.h"
#include "is-groupmgr.h"
#include "is-device-ischain.h"
#include "is-device-sensor.h"
static int __is_votf_create_link(int src_ip, int src_id, int dst_ip, int dst_id,
u32 width, u32 height, u32 change)
{
int ret = 0;
struct votf_info vinfo;
struct votf_service_cfg cfg;
struct votf_lost_cfg lost_cfg;
memset(&vinfo, 0, sizeof(struct votf_info));
memset(&cfg, 0, sizeof(struct votf_service_cfg));
/* TWS: Master */
vinfo.service = TWS;
vinfo.ip = src_ip;
vinfo.id = src_id;
cfg.enable = 0x1;
/*
* 0xFF is max value.
* Buffer size is (limit x token_size).
* But VOTF can hold only 1 frame.
*/
cfg.limit = 0xFF;
cfg.width = width;
cfg.height = height;
cfg.token_size = 0x1F;
cfg.connected_ip = dst_ip;
cfg.connected_id = dst_id;
cfg.option = change << VOTF_OPTION_BIT_CHANGE;
ret = votfitf_set_service_cfg(&vinfo, &cfg);
if (ret < 0) {
ret = -EINVAL;
err("votfitf_set_service_cfg for TWS is fail (src(%d, %d), dst(%d, %d))",
src_ip, src_id, dst_ip, dst_id);
return ret;
}
/* TRS: Slave */
vinfo.service = TRS;
vinfo.ip = dst_ip;
vinfo.id = dst_id;
cfg.enable = 0x1;
/*
* 0xFF is max value.
* Buffer size is (limit x token_size).
* But VOTF can hold only 1 frame.
*/
cfg.limit = 0xFF;
cfg.width = width;
cfg.height = height;
cfg.token_size = 0x1F;
cfg.connected_ip = src_ip;
cfg.connected_id = src_id;
cfg.option = change << VOTF_OPTION_BIT_CHANGE;
ret = votfitf_set_service_cfg(&vinfo, &cfg);
if (ret < 0) {
ret = -EINVAL;
err("votfitf_set_service_cfg for TRS is fail (src(%d, %d), dst(%d, %d))",
src_ip, src_id, dst_ip, dst_id);
return ret;
}
memset(&lost_cfg, 0, sizeof(struct votf_lost_cfg));
lost_cfg.recover_enable = 0x1;
/* lost_cfg.flush_enable = 0x1; */
ret = votfitf_set_trs_lost_cfg(&vinfo, &lost_cfg);
if (ret < 0) {
ret = -EINVAL;
err("votfitf_set_trs_lost_cfg is fail (src(%d, %d), dst(%d, %d))",
src_ip, src_id, dst_ip, dst_id);
return ret;
}
info(" VOTF create link (size(%dx%d), src(%d, %d), dst(%d, %d))\n",
width, height, src_ip, src_id, dst_ip, dst_id);
return 0;
}
static int __is_votf_flush(int src_ip, int src_id, int dst_ip, int dst_id)
{
int ret = 0;
struct votf_info vinfo;
memset(&vinfo, 0, sizeof(struct votf_info));
/* TWS: Master */
vinfo.service = TWS;
vinfo.ip = src_ip;
vinfo.id = src_id;
ret = votfitf_set_flush(&vinfo);
if (ret < 0)
err("votfitf_set_flush for TWS is fail (src(%d, %d), dst(%d, %d))",
src_ip, src_id, dst_ip, dst_id);
/* TRS: Slave */
vinfo.service = TRS;
vinfo.ip = dst_ip;
vinfo.id = dst_id;
ret = votfitf_set_flush(&vinfo);
if (ret < 0)
err("votfitf_set_flush for TRS is fail (src(%d, %d), dst(%d, %d))",
src_ip, src_id, dst_ip, dst_id);
info("VOTF flush(src(%d, %d), dst(%d, %d))\n", src_ip, src_id, dst_ip, dst_id);
return 0;
}
int is_votf_flush(struct is_group *group)
{
int ret = 0;
struct is_device_sensor *sensor;
unsigned int src_ip, src_id, dst_ip, dst_id;
struct is_group *src_gr;
unsigned int src_gr_id;
struct is_subdev *src_sd;
int dma_ch;
struct is_device_ischain *device;
struct is_sensor_cfg *sensor_cfg;
int pd_mode;
FIMC_BUG(!group);
FIMC_BUG(!group->prev);
FIMC_BUG(!group->prev->junction);
src_gr = group->prev;
src_sd = group->prev->junction;
if (src_gr->device_type == IS_DEVICE_SENSOR) {
/*
* The sensor group id should be re calculated,
* because CSIS WDMA is not matched with sensor group id.
*/
sensor = src_gr->sensor;
sensor_cfg = sensor->cfg;
if (!sensor_cfg) {
mgerr("failed to get sensor_cfg", group, group);
return -EINVAL;
}
dma_ch = src_sd->dma_ch[sensor_cfg->scm];
src_gr_id = GROUP_ID_SS0 + dma_ch;
} else {
src_gr_id = src_gr->id;
}
src_ip = is_votf_ip[src_gr_id];
src_id = is_votf_id[src_gr_id][src_sd->id];
dst_ip = is_votf_ip[group->id];
dst_id = is_votf_id[group->id][group->leader.id];
mginfo(" VOTF flush(TWS[%s:%s]-TRS[%s:%s])\n",
group, group,
group_id_name[src_gr->id], src_sd->name,
group_id_name[group->id], group->leader.name);
ret = __is_votf_flush(src_ip, src_id, dst_ip, dst_id);
if (ret)
mgerr("__is_votf_flush is fail(%d)", group, group, ret);
if (src_gr->device_type == IS_DEVICE_SENSOR) {
device = group->device;
if (!device) {
mgerr("failed to get devcie", group, group);
return -ENODEV;
}
pd_mode = sensor_cfg->pd_mode;
if (pd_mode == PD_MOD3) {
src_id = is_votf_id[src_gr_id][ENTRY_SSVC1];
dst_id = is_votf_id[group->id][ENTRY_PDAF];
ret = __is_votf_flush(src_ip, src_id, dst_ip, dst_id);
if (ret)
mgerr("__is_votf_flush of subdev_pdaf is fail(%d)", group, group, ret);
}
}
return 0;
}
int is_votf_create_link(struct is_group *group, u32 width, u32 height)
{
int ret = 0;
struct is_device_sensor *sensor;
unsigned int src_ip, src_id, dst_ip, dst_id;
struct is_group *src_gr;
unsigned int src_gr_id;
struct is_subdev *src_sd;
int dma_ch;
struct is_device_ischain *device;
struct is_sensor_cfg *sensor_cfg;
struct is_subdev *subdev_pdaf;
int pd_mode;
u32 pd_width, pd_height;
u32 change_option = 0;
FIMC_BUG(!group);
FIMC_BUG(!group->prev);
FIMC_BUG(!group->prev->junction);
src_gr = group->prev;
src_sd = group->prev->junction;
if (src_gr->device_type == IS_DEVICE_SENSOR) {
/*
* The sensor group id should be re calculated,
* because CSIS WDMA is not matched with sensor group id.
*/
sensor = src_gr->sensor;
sensor_cfg = sensor->cfg;
if (!sensor_cfg) {
mgerr("failed to get sensor_cfg", group, group);
return -EINVAL;
}
dma_ch = src_sd->dma_ch[sensor_cfg->scm];
src_gr_id = GROUP_ID_SS0 + dma_ch;
} else {
src_gr_id = src_gr->id;
}
src_ip = is_votf_ip[src_gr_id];
src_id = is_votf_id[src_gr_id][src_sd->id];
dst_ip = is_votf_ip[group->id];
dst_id = is_votf_id[group->id][group->leader.id];
mginfo(" VOTF create link(TWS[%s:%s]-TRS[%s:%s])\n",
group, group,
group_id_name[src_gr->id], src_sd->name,
group_id_name[group->id], group->leader.name);
/* Call VOTF API */
votfitf_create_ring();
ret = __is_votf_create_link(src_ip, src_id, dst_ip, dst_id, width, height, change_option);
if (ret)
return ret;
if (src_gr->device_type == IS_DEVICE_SENSOR) {
device = group->device;
if (!device) {
mgerr("failed to get devcie", group, group);
return -ENODEV;
}
pd_mode = sensor_cfg->pd_mode;
if (pd_mode == PD_MOD3) {
subdev_pdaf = &device->pdaf;
pd_width = sensor_cfg->input[CSI_VIRTUAL_CH_1].width;
pd_height = sensor_cfg->input[CSI_VIRTUAL_CH_1].height;
ret = is_subdev_internal_open(device, IS_DEVICE_ISCHAIN, subdev_pdaf);
if (ret) {
merr("is_subdev_internal_open is fail(%d)", device, ret);
return ret;
}
ret = is_subdev_internal_s_format(device, 0, subdev_pdaf,
pd_width, pd_height, 2, NUM_OF_VOTF_BUF, "VOTF");
if (ret) {
merr("is_subdev_internal_s_format is fail(%d)", device, ret);
return ret;
}
ret = is_subdev_internal_start(device, IS_DEVICE_ISCHAIN, subdev_pdaf);
if (ret) {
merr("subdev_pdaf internal start is fail(%d)", device, ret);
return ret;
}
src_id = is_votf_id[src_gr_id][ENTRY_SSVC1];
dst_id = is_votf_id[group->id][ENTRY_PDAF];
ret = __is_votf_create_link(src_ip, src_id, dst_ip, dst_id,
pd_width, pd_height, change_option);
if (ret)
return ret;
}
}
return 0;
}
int is_votf_destroy_link(struct is_group *group)
{
int ret = 0;
struct is_device_sensor *sensor;
struct is_group *src_gr;
struct is_subdev *src_sd;
struct is_device_ischain *device;
struct is_sensor_cfg *sensor_cfg;
struct is_subdev *subdev_pdaf;
int pd_mode;
FIMC_BUG(!group);
FIMC_BUG(!group->prev);
FIMC_BUG(!group->prev->junction);
src_gr = group->prev;
src_sd = group->prev->junction;
if (src_gr->device_type == IS_DEVICE_SENSOR) {
sensor = src_gr->sensor;
device = group->device;
if (!device) {
mgerr("failed to get devcie", group, group);
goto p_err;
}
sensor_cfg = sensor->cfg;
if (!sensor_cfg) {
mgerr("failed to get sensor_cfg", group, group);
goto p_err;
}
pd_mode = sensor_cfg->pd_mode;
if (pd_mode == PD_MOD3) {
subdev_pdaf = &device->pdaf;
ret = is_subdev_internal_stop(device, 0, subdev_pdaf);
if (ret)
merr("subdev internal stop is fail(%d)", device, ret);
ret = is_subdev_internal_close(device, IS_DEVICE_ISCHAIN, subdev_pdaf);
if (ret)
merr("is_subdev_internal_close is fail(%d)", device, ret);
}
}
if (group->id >= GROUP_ID_MAX) {
mgerr("group ID is invalid(%d)", group, group);
/* Do not access C2SERV after power off */
return 0;
}
ret = is_votf_flush(group);
if (ret)
mgerr("is_votf_flush is fail(%d)", group, group, ret);
mginfo(" VOTF destroy link(TWS[%s:%s]-TRS[%s:%s])\n",
group, group,
group_id_name[src_gr->id], src_sd->name,
group_id_name[group->id], group->leader.name);
p_err:
/*
* All VOTF control such as flush must be set in ring clock enable and ring enable.
* So, calling votfitf_destroy_ring must be called at the last.
*/
votfitf_destroy_ring();
return 0;
}
int is_votf_change_link(struct is_group *group)
{
int ret = 0;
struct is_device_sensor *sensor;
unsigned int src_ip, src_id, dst_ip, dst_id;
struct is_group *src_gr;
unsigned int src_gr_id;
struct is_subdev *src_sd;
int dma_ch;
struct is_sensor_cfg *sensor_cfg;
int pd_mode;
u32 pd_width, pd_height;
u32 width, height;
u32 change_option = 1;
FIMC_BUG(!group);
FIMC_BUG(!group->prev);
FIMC_BUG(!group->prev->junction);
src_gr = group->prev;
src_sd = group->prev->junction;
if (src_gr->device_type == IS_DEVICE_SENSOR) {
/*
* The sensor group id should be re calculated,
* because CSIS WDMA is not matched with sensor group id.
*/
sensor = src_gr->sensor;
sensor_cfg = sensor->cfg;
if (!sensor_cfg) {
mgerr("failed to get sensor_cfg", group, group);
return -EINVAL;
}
dma_ch = src_sd->dma_ch[sensor_cfg->scm];
src_gr_id = GROUP_ID_SS0 + dma_ch;
} else {
src_gr_id = src_gr->id;
}
src_ip = is_votf_ip[src_gr_id];
src_id = is_votf_id[src_gr_id][src_sd->id];
dst_ip = is_votf_ip[group->id];
dst_id = is_votf_id[group->id][group->leader.id];
mginfo(" VOTF change link(TWS[%s:%s]-TRS[%s:%s])\n",
group, group,
group_id_name[src_gr->id], src_sd->name,
group_id_name[group->id], group->leader.name);
width = group->leader.input.width;
height = group->leader.input.height;
ret = __is_votf_create_link(src_ip, src_id, dst_ip, dst_id, width, height, change_option);
if (ret)
return ret;
if (src_gr->device_type == IS_DEVICE_SENSOR) {
pd_mode = sensor_cfg->pd_mode;
if (pd_mode == PD_MOD3) {
pd_width = sensor_cfg->input[CSI_VIRTUAL_CH_1].width;
pd_height = sensor_cfg->input[CSI_VIRTUAL_CH_1].height;
src_id = is_votf_id[src_gr_id][ENTRY_SSVC1];
dst_id = is_votf_id[group->id][ENTRY_PDAF];
ret = __is_votf_create_link(src_ip, src_id, dst_ip, dst_id,
pd_width, pd_height, change_option);
if (ret)
return ret;
}
}
return 0;
}
struct is_framemgr *is_votf_get_framemgr(struct is_group *group, enum votf_service type,
unsigned long subdev_id)
{
struct is_framemgr *framemgr;
struct is_subdev *subdev;
struct is_device_ischain *device;
struct is_subdev *subdev_pdaf;
FIMC_BUG_NULL(!group);
if (type == TWS) {
if (!group->next) {
mgerr("The next group is NULL (subdev_id: %ld)\n", group, group, subdev_id);
return NULL;
}
subdev = &group->next->leader;
} else {
subdev = &group->leader;
}
framemgr = GET_SUBDEV_I_FRAMEMGR(subdev);
/* FIXME */
if (subdev_id == ENTRY_SSVC1 || subdev_id == ENTRY_PDAF) {
device = group->device;
subdev_pdaf = &device->pdaf;
framemgr = GET_SUBDEV_I_FRAMEMGR(subdev_pdaf);
}
FIMC_BUG_NULL(!framemgr);
return framemgr;
}
struct is_frame *is_votf_get_frame(struct is_group *group, enum votf_service type,
unsigned long subdev_id, u32 fcount)
{
struct is_framemgr *framemgr;
struct is_frame *frame;
framemgr = is_votf_get_framemgr(group, type, subdev_id);
if (!framemgr) {
mgerr("framemgr is NULL (subdev_id: %ld)\n", group, group, subdev_id);
return NULL;
}
frame = &framemgr->frames[fcount % framemgr->num_frames];
return frame;
}
int is_votf_register_framemgr(struct is_group *group, enum votf_service type,
void *data, votf_s_addr fn, unsigned long subdev_id)
{
struct is_framemgr *framemgr;
framemgr = is_votf_get_framemgr(group, type, subdev_id);
if (!framemgr) {
mgerr("framemgr is NULL. (subdev_id: %ld)\n", group, group, subdev_id);
return -EINVAL;
}
if (type == TWS) {
framemgr->master.id = subdev_id;
framemgr->master.data = data;
framemgr->master.s_addr = fn;
mginfo("Registe VOTF master callback (subdev_id: %ld)\n", group, group, subdev_id);
} else {
framemgr->slave.id = subdev_id;
framemgr->slave.data = data;
framemgr->slave.s_addr = fn;
mginfo("Registe VOTF slave callback (subdev_id: %ld)\n", group, group, subdev_id);
}
return 0;
}
int is_votf_register_oneshot(struct is_group *group, enum votf_service type,
void *data, votf_s_oneshot fn, unsigned long subdev_id)
{
struct is_framemgr *framemgr;
framemgr = is_votf_get_framemgr(group, type, subdev_id);
if (!framemgr) {
mgerr("framemgr is NULL. (subdev_id: %ld)\n", group, group, subdev_id);
return -EINVAL;
}
if (type == TWS) {
mgwarn("Invalid type for VOTF oneshot trigger register (subdev_id: %ld)\n", group, group, subdev_id);
} else {
framemgr->slave.id = subdev_id;
framemgr->slave.data = data;
framemgr->slave.s_oneshot = fn;
mginfo("Register VOTF slave oneshot trigger (subdev_id: %ld)\n", group, group, subdev_id);
}
return 0;
}
|