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
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
|
// SPDX-License-Identifier: GPL-2.0
/*
* Support for Intel Camera Imaging ISP subsystem.
* Copyright (c) 2015, Intel Corporation.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*
* This program is distributed in the hope it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*/
#include "hmm.h"
#include "ia_css_frame.h"
#include <math_support.h>
#include "assert_support.h"
#include "ia_css_debug.h"
#include "isp.h"
#include "sh_css_internal.h"
#include "atomisp_internal.h"
#define NV12_TILEY_TILE_WIDTH 128
#define NV12_TILEY_TILE_HEIGHT 32
/**************************************************************************
** Static functions declarations
**************************************************************************/
static void frame_init_plane(struct ia_css_frame_plane *plane,
unsigned int width,
unsigned int stride,
unsigned int height,
unsigned int offset);
static void frame_init_single_plane(struct ia_css_frame *frame,
struct ia_css_frame_plane *plane,
unsigned int height,
unsigned int subpixels_per_line,
unsigned int bytes_per_pixel);
static void frame_init_raw_single_plane(
struct ia_css_frame *frame,
struct ia_css_frame_plane *plane,
unsigned int height,
unsigned int subpixels_per_line,
unsigned int bits_per_pixel);
static void frame_init_nv_planes(struct ia_css_frame *frame,
unsigned int horizontal_decimation,
unsigned int vertical_decimation,
unsigned int bytes_per_element);
static void frame_init_yuv_planes(struct ia_css_frame *frame,
unsigned int horizontal_decimation,
unsigned int vertical_decimation,
bool swap_uv,
unsigned int bytes_per_element);
static void frame_init_rgb_planes(struct ia_css_frame *frame,
unsigned int bytes_per_element);
static void frame_init_qplane6_planes(struct ia_css_frame *frame);
static int frame_allocate_buffer_data(struct ia_css_frame *frame);
static int frame_allocate_with_data(struct ia_css_frame **frame,
unsigned int width,
unsigned int height,
enum ia_css_frame_format format,
unsigned int padded_width,
unsigned int raw_bit_depth);
static struct ia_css_frame *frame_create(unsigned int width,
unsigned int height,
enum ia_css_frame_format format,
unsigned int padded_width,
unsigned int raw_bit_depth,
bool valid);
static unsigned
ia_css_elems_bytes_from_info(
const struct ia_css_frame_info *info);
/**************************************************************************
** CSS API functions, exposed by ia_css.h
**************************************************************************/
int ia_css_frame_allocate_from_info(struct ia_css_frame **frame,
const struct ia_css_frame_info *info)
{
int err = 0;
if (!frame || !info)
return -EINVAL;
ia_css_debug_dtrace(IA_CSS_DEBUG_TRACE,
"ia_css_frame_allocate_from_info() enter:\n");
err =
ia_css_frame_allocate(frame, info->res.width, info->res.height,
info->format, info->padded_width,
info->raw_bit_depth);
ia_css_debug_dtrace(IA_CSS_DEBUG_TRACE,
"ia_css_frame_allocate_from_info() leave:\n");
return err;
}
int ia_css_frame_allocate(struct ia_css_frame **frame,
unsigned int width,
unsigned int height,
enum ia_css_frame_format format,
unsigned int padded_width,
unsigned int raw_bit_depth)
{
int err = 0;
if (!frame || width == 0 || height == 0)
return -EINVAL;
ia_css_debug_dtrace(IA_CSS_DEBUG_TRACE,
"ia_css_frame_allocate() enter: width=%d, height=%d, format=%d, padded_width=%d, raw_bit_depth=%d\n",
width, height, format, padded_width, raw_bit_depth);
err = frame_allocate_with_data(frame, width, height, format,
padded_width, raw_bit_depth);
if ((*frame) && err == 0)
ia_css_debug_dtrace(IA_CSS_DEBUG_TRACE,
"ia_css_frame_allocate() leave: frame=%p, data(DDR address)=0x%x\n", *frame,
(*frame)->data);
else
ia_css_debug_dtrace(IA_CSS_DEBUG_TRACE,
"ia_css_frame_allocate() leave: frame=%p, data(DDR address)=0x%x\n",
(void *)-1, (unsigned int)-1);
return err;
}
void ia_css_frame_free(struct ia_css_frame *frame)
{
IA_CSS_ENTER_PRIVATE("frame = %p", frame);
if (frame) {
hmm_free(frame->data);
kvfree(frame);
}
IA_CSS_LEAVE_PRIVATE("void");
}
/**************************************************************************
** Module public functions
**************************************************************************/
int ia_css_frame_check_info(const struct ia_css_frame_info *info)
{
assert(info);
if (info->res.width == 0 || info->res.height == 0)
return -EINVAL;
return 0;
}
int ia_css_frame_init_planes(struct ia_css_frame *frame)
{
assert(frame);
switch (frame->frame_info.format) {
case IA_CSS_FRAME_FORMAT_MIPI:
dev_err(atomisp_dev,
"%s: unexpected use of IA_CSS_FRAME_FORMAT_MIPI\n", __func__);
return -EINVAL;
case IA_CSS_FRAME_FORMAT_RAW_PACKED:
frame_init_raw_single_plane(frame, &frame->planes.raw,
frame->frame_info.res.height,
frame->frame_info.padded_width,
frame->frame_info.raw_bit_depth);
break;
case IA_CSS_FRAME_FORMAT_RAW:
frame_init_single_plane(frame, &frame->planes.raw,
frame->frame_info.res.height,
frame->frame_info.padded_width,
frame->frame_info.raw_bit_depth <= 8 ? 1 : 2);
break;
case IA_CSS_FRAME_FORMAT_RGB565:
frame_init_single_plane(frame, &frame->planes.rgb,
frame->frame_info.res.height,
frame->frame_info.padded_width, 2);
break;
case IA_CSS_FRAME_FORMAT_RGBA888:
frame_init_single_plane(frame, &frame->planes.rgb,
frame->frame_info.res.height,
frame->frame_info.padded_width * 4, 1);
break;
case IA_CSS_FRAME_FORMAT_PLANAR_RGB888:
frame_init_rgb_planes(frame, 1);
break;
/* yuyv and uyvu have the same frame layout, only the data
* positioning differs.
*/
case IA_CSS_FRAME_FORMAT_YUYV:
case IA_CSS_FRAME_FORMAT_UYVY:
case IA_CSS_FRAME_FORMAT_CSI_MIPI_YUV420_8:
case IA_CSS_FRAME_FORMAT_CSI_MIPI_LEGACY_YUV420_8:
frame_init_single_plane(frame, &frame->planes.yuyv,
frame->frame_info.res.height,
frame->frame_info.padded_width * 2, 1);
break;
case IA_CSS_FRAME_FORMAT_YUV_LINE:
/* Needs 3 extra lines to allow vf_pp prefetching */
frame_init_single_plane(frame, &frame->planes.yuyv,
frame->frame_info.res.height * 3 / 2 + 3,
frame->frame_info.padded_width, 1);
break;
case IA_CSS_FRAME_FORMAT_NV11:
frame_init_nv_planes(frame, 4, 1, 1);
break;
/* nv12 and nv21 have the same frame layout, only the data
* positioning differs.
*/
case IA_CSS_FRAME_FORMAT_NV12:
case IA_CSS_FRAME_FORMAT_NV21:
case IA_CSS_FRAME_FORMAT_NV12_TILEY:
frame_init_nv_planes(frame, 2, 2, 1);
break;
case IA_CSS_FRAME_FORMAT_NV12_16:
frame_init_nv_planes(frame, 2, 2, 2);
break;
/* nv16 and nv61 have the same frame layout, only the data
* positioning differs.
*/
case IA_CSS_FRAME_FORMAT_NV16:
case IA_CSS_FRAME_FORMAT_NV61:
frame_init_nv_planes(frame, 2, 1, 1);
break;
case IA_CSS_FRAME_FORMAT_YUV420:
frame_init_yuv_planes(frame, 2, 2, false, 1);
break;
case IA_CSS_FRAME_FORMAT_YUV422:
frame_init_yuv_planes(frame, 2, 1, false, 1);
break;
case IA_CSS_FRAME_FORMAT_YUV444:
frame_init_yuv_planes(frame, 1, 1, false, 1);
break;
case IA_CSS_FRAME_FORMAT_YUV420_16:
frame_init_yuv_planes(frame, 2, 2, false, 2);
break;
case IA_CSS_FRAME_FORMAT_YUV422_16:
frame_init_yuv_planes(frame, 2, 1, false, 2);
break;
case IA_CSS_FRAME_FORMAT_YV12:
frame_init_yuv_planes(frame, 2, 2, true, 1);
break;
case IA_CSS_FRAME_FORMAT_YV16:
frame_init_yuv_planes(frame, 2, 1, true, 1);
break;
case IA_CSS_FRAME_FORMAT_QPLANE6:
frame_init_qplane6_planes(frame);
break;
case IA_CSS_FRAME_FORMAT_BINARY_8:
frame_init_single_plane(frame, &frame->planes.binary.data,
frame->frame_info.res.height,
frame->frame_info.padded_width, 1);
frame->planes.binary.size = 0;
break;
default:
return -EINVAL;
}
return 0;
}
void ia_css_frame_info_set_width(struct ia_css_frame_info *info,
unsigned int width,
unsigned int min_padded_width)
{
unsigned int align;
IA_CSS_ENTER_PRIVATE("info = %p,width = %d, minimum padded width = %d",
info, width, min_padded_width);
if (!info) {
IA_CSS_ERROR("NULL input parameter");
IA_CSS_LEAVE_PRIVATE("");
return;
}
align = max(min_padded_width, width);
info->res.width = width;
/* frames with a U and V plane of 8 bits per pixel need to have
all planes aligned, this means double the alignment for the
Y plane if the horizontal decimation is 2. */
if (info->format == IA_CSS_FRAME_FORMAT_YUV420 ||
info->format == IA_CSS_FRAME_FORMAT_YV12 ||
info->format == IA_CSS_FRAME_FORMAT_NV12 ||
info->format == IA_CSS_FRAME_FORMAT_NV21 ||
info->format == IA_CSS_FRAME_FORMAT_BINARY_8 ||
info->format == IA_CSS_FRAME_FORMAT_YUV_LINE)
info->padded_width =
CEIL_MUL(align, 2 * HIVE_ISP_DDR_WORD_BYTES);
else if (info->format == IA_CSS_FRAME_FORMAT_NV12_TILEY)
info->padded_width = CEIL_MUL(align, NV12_TILEY_TILE_WIDTH);
else if (info->format == IA_CSS_FRAME_FORMAT_RAW ||
info->format == IA_CSS_FRAME_FORMAT_RAW_PACKED)
info->padded_width = CEIL_MUL(align, 2 * ISP_VEC_NELEMS);
else {
info->padded_width = CEIL_MUL(align, HIVE_ISP_DDR_WORD_BYTES);
}
IA_CSS_LEAVE_PRIVATE("");
}
void ia_css_frame_info_set_format(struct ia_css_frame_info *info,
enum ia_css_frame_format format)
{
assert(info);
ia_css_debug_dtrace(IA_CSS_DEBUG_TRACE,
"ia_css_frame_info_set_format() enter:\n");
info->format = format;
}
void ia_css_frame_info_init(struct ia_css_frame_info *info,
unsigned int width,
unsigned int height,
enum ia_css_frame_format format,
unsigned int aligned)
{
IA_CSS_ENTER_PRIVATE("info = %p, width = %d, height = %d, format = %d, aligned = %d",
info, width, height, format, aligned);
if (!info) {
IA_CSS_ERROR("NULL input parameter");
IA_CSS_LEAVE_PRIVATE("");
return;
}
info->res.height = height;
info->format = format;
ia_css_frame_info_set_width(info, width, aligned);
IA_CSS_LEAVE_PRIVATE("");
}
void ia_css_frame_free_multiple(unsigned int num_frames,
struct ia_css_frame **frames_array)
{
unsigned int i;
for (i = 0; i < num_frames; i++) {
if (frames_array[i]) {
ia_css_frame_free(frames_array[i]);
frames_array[i] = NULL;
}
}
}
int ia_css_frame_allocate_with_buffer_size(struct ia_css_frame **frame,
const unsigned int buffer_size_bytes)
{
/* AM: Body coppied from frame_allocate_with_data(). */
int err;
struct ia_css_frame *me = frame_create(0, 0,
IA_CSS_FRAME_FORMAT_NUM,/* Not valid format yet */
0, 0, false);
if (!me)
return -ENOMEM;
/* Get the data size */
me->data_bytes = buffer_size_bytes;
err = frame_allocate_buffer_data(me);
if (err) {
kvfree(me);
me = NULL;
}
*frame = me;
return err;
}
bool ia_css_frame_info_is_same_resolution(
const struct ia_css_frame_info *info_a,
const struct ia_css_frame_info *info_b)
{
if (!info_a || !info_b)
return false;
return (info_a->res.width == info_b->res.width) &&
(info_a->res.height == info_b->res.height);
}
bool ia_css_frame_is_same_type(const struct ia_css_frame *frame_a,
const struct ia_css_frame *frame_b)
{
bool is_equal = false;
const struct ia_css_frame_info *info_a = &frame_a->frame_info;
const struct ia_css_frame_info *info_b = &frame_b->frame_info;
ia_css_debug_dtrace(IA_CSS_DEBUG_TRACE,
"ia_css_frame_is_same_type() enter:\n");
if (!info_a || !info_b)
return false;
if (info_a->format != info_b->format)
return false;
if (info_a->padded_width != info_b->padded_width)
return false;
is_equal = ia_css_frame_info_is_same_resolution(info_a, info_b);
ia_css_debug_dtrace(IA_CSS_DEBUG_TRACE,
"ia_css_frame_is_same_type() leave:\n");
return is_equal;
}
int ia_css_dma_configure_from_info(struct dma_port_config *config,
const struct ia_css_frame_info *info)
{
unsigned int is_raw_packed = info->format == IA_CSS_FRAME_FORMAT_RAW_PACKED;
unsigned int bits_per_pixel = is_raw_packed ? info->raw_bit_depth :
ia_css_elems_bytes_from_info(info) * 8;
unsigned int pix_per_ddrword = HIVE_ISP_DDR_WORD_BITS / bits_per_pixel;
unsigned int words_per_line = CEIL_DIV(info->padded_width, pix_per_ddrword);
unsigned int elems_b = pix_per_ddrword;
config->stride = HIVE_ISP_DDR_WORD_BYTES * words_per_line;
config->elems = (uint8_t)elems_b;
config->width = (uint16_t)info->res.width;
config->crop = 0;
if (config->width > info->padded_width) {
dev_err(atomisp_dev, "internal error: padded_width is too small!\n");
return -EINVAL;
}
return 0;
}
/**************************************************************************
** Static functions
**************************************************************************/
static void frame_init_plane(struct ia_css_frame_plane *plane,
unsigned int width,
unsigned int stride,
unsigned int height,
unsigned int offset)
{
plane->height = height;
plane->width = width;
plane->stride = stride;
plane->offset = offset;
}
static void frame_init_single_plane(struct ia_css_frame *frame,
struct ia_css_frame_plane *plane,
unsigned int height,
unsigned int subpixels_per_line,
unsigned int bytes_per_pixel)
{
unsigned int stride;
stride = subpixels_per_line * bytes_per_pixel;
/* Frame height needs to be even number - needed by hw ISYS2401
In case of odd number, round up to even.
Images won't be impacted by this round up,
only needed by jpeg/embedded data.
As long as buffer allocation and release are using data_bytes,
there won't be memory leak. */
frame->data_bytes = stride * CEIL_MUL2(height, 2);
frame_init_plane(plane, subpixels_per_line, stride, height, 0);
return;
}
static void frame_init_raw_single_plane(
struct ia_css_frame *frame,
struct ia_css_frame_plane *plane,
unsigned int height,
unsigned int subpixels_per_line,
unsigned int bits_per_pixel)
{
unsigned int stride;
assert(frame);
stride = HIVE_ISP_DDR_WORD_BYTES *
CEIL_DIV(subpixels_per_line,
HIVE_ISP_DDR_WORD_BITS / bits_per_pixel);
frame->data_bytes = stride * height;
frame_init_plane(plane, subpixels_per_line, stride, height, 0);
return;
}
static void frame_init_nv_planes(struct ia_css_frame *frame,
unsigned int horizontal_decimation,
unsigned int vertical_decimation,
unsigned int bytes_per_element)
{
unsigned int y_width = frame->frame_info.padded_width;
unsigned int y_height = frame->frame_info.res.height;
unsigned int uv_width;
unsigned int uv_height;
unsigned int y_bytes;
unsigned int uv_bytes;
unsigned int y_stride;
unsigned int uv_stride;
assert(horizontal_decimation != 0 && vertical_decimation != 0);
uv_width = 2 * (y_width / horizontal_decimation);
uv_height = y_height / vertical_decimation;
if (frame->frame_info.format == IA_CSS_FRAME_FORMAT_NV12_TILEY) {
y_width = CEIL_MUL(y_width, NV12_TILEY_TILE_WIDTH);
uv_width = CEIL_MUL(uv_width, NV12_TILEY_TILE_WIDTH);
y_height = CEIL_MUL(y_height, NV12_TILEY_TILE_HEIGHT);
uv_height = CEIL_MUL(uv_height, NV12_TILEY_TILE_HEIGHT);
}
y_stride = y_width * bytes_per_element;
uv_stride = uv_width * bytes_per_element;
y_bytes = y_stride * y_height;
uv_bytes = uv_stride * uv_height;
frame->data_bytes = y_bytes + uv_bytes;
frame_init_plane(&frame->planes.nv.y, y_width, y_stride, y_height, 0);
frame_init_plane(&frame->planes.nv.uv, uv_width,
uv_stride, uv_height, y_bytes);
return;
}
static void frame_init_yuv_planes(struct ia_css_frame *frame,
unsigned int horizontal_decimation,
unsigned int vertical_decimation,
bool swap_uv,
unsigned int bytes_per_element)
{
unsigned int y_width = frame->frame_info.padded_width,
y_height = frame->frame_info.res.height,
uv_width = y_width / horizontal_decimation,
uv_height = y_height / vertical_decimation,
y_stride, y_bytes, uv_bytes, uv_stride;
y_stride = y_width * bytes_per_element;
uv_stride = uv_width * bytes_per_element;
y_bytes = y_stride * y_height;
uv_bytes = uv_stride * uv_height;
frame->data_bytes = y_bytes + 2 * uv_bytes;
frame_init_plane(&frame->planes.yuv.y, y_width, y_stride, y_height, 0);
if (swap_uv) {
frame_init_plane(&frame->planes.yuv.v, uv_width, uv_stride,
uv_height, y_bytes);
frame_init_plane(&frame->planes.yuv.u, uv_width, uv_stride,
uv_height, y_bytes + uv_bytes);
} else {
frame_init_plane(&frame->planes.yuv.u, uv_width, uv_stride,
uv_height, y_bytes);
frame_init_plane(&frame->planes.yuv.v, uv_width, uv_stride,
uv_height, y_bytes + uv_bytes);
}
return;
}
static void frame_init_rgb_planes(struct ia_css_frame *frame,
unsigned int bytes_per_element)
{
unsigned int width = frame->frame_info.res.width,
height = frame->frame_info.res.height, stride, bytes;
stride = width * bytes_per_element;
bytes = stride * height;
frame->data_bytes = 3 * bytes;
frame_init_plane(&frame->planes.planar_rgb.r, width, stride, height, 0);
frame_init_plane(&frame->planes.planar_rgb.g,
width, stride, height, 1 * bytes);
frame_init_plane(&frame->planes.planar_rgb.b,
width, stride, height, 2 * bytes);
return;
}
static void frame_init_qplane6_planes(struct ia_css_frame *frame)
{
unsigned int width = frame->frame_info.padded_width / 2,
height = frame->frame_info.res.height / 2, bytes, stride;
stride = width * 2;
bytes = stride * height;
frame->data_bytes = 6 * bytes;
frame_init_plane(&frame->planes.plane6.r,
width, stride, height, 0 * bytes);
frame_init_plane(&frame->planes.plane6.r_at_b,
width, stride, height, 1 * bytes);
frame_init_plane(&frame->planes.plane6.gr,
width, stride, height, 2 * bytes);
frame_init_plane(&frame->planes.plane6.gb,
width, stride, height, 3 * bytes);
frame_init_plane(&frame->planes.plane6.b,
width, stride, height, 4 * bytes);
frame_init_plane(&frame->planes.plane6.b_at_r,
width, stride, height, 5 * bytes);
return;
}
static int frame_allocate_buffer_data(struct ia_css_frame *frame)
{
frame->data = hmm_alloc(frame->data_bytes);
if (frame->data == mmgr_NULL)
return -ENOMEM;
return 0;
}
static int frame_allocate_with_data(struct ia_css_frame **frame,
unsigned int width,
unsigned int height,
enum ia_css_frame_format format,
unsigned int padded_width,
unsigned int raw_bit_depth)
{
int err;
struct ia_css_frame *me = frame_create(width,
height,
format,
padded_width,
raw_bit_depth,
true);
if (!me)
return -ENOMEM;
err = ia_css_frame_init_planes(me);
if (!err)
err = frame_allocate_buffer_data(me);
if (err) {
kvfree(me);
*frame = NULL;
} else {
*frame = me;
}
return err;
}
static struct ia_css_frame *frame_create(unsigned int width,
unsigned int height,
enum ia_css_frame_format format,
unsigned int padded_width,
unsigned int raw_bit_depth,
bool valid)
{
struct ia_css_frame *me = kvmalloc(sizeof(*me), GFP_KERNEL);
if (!me)
return NULL;
memset(me, 0, sizeof(*me));
me->frame_info.res.width = width;
me->frame_info.res.height = height;
me->frame_info.format = format;
me->frame_info.padded_width = padded_width;
me->frame_info.raw_bit_depth = raw_bit_depth;
me->valid = valid;
me->data_bytes = 0;
me->data = mmgr_NULL;
/* To indicate it is not valid frame. */
me->dynamic_queue_id = (int)SH_CSS_INVALID_QUEUE_ID;
me->buf_type = IA_CSS_BUFFER_TYPE_INVALID;
return me;
}
static unsigned
ia_css_elems_bytes_from_info(const struct ia_css_frame_info *info)
{
if (info->format == IA_CSS_FRAME_FORMAT_RGB565)
return 2; /* bytes per pixel */
if (info->format == IA_CSS_FRAME_FORMAT_YUV420_16)
return 2; /* bytes per pixel */
if (info->format == IA_CSS_FRAME_FORMAT_YUV422_16)
return 2; /* bytes per pixel */
/* Note: Essentially NV12_16 is a 2 bytes per pixel format, this return value is used
* to configure DMA for the output buffer,
* At least in SKC this data is overwritten by isp_output_init.sp.c except for elements(elems),
* which is configured from this return value,
* NV12_16 is implemented by a double buffer of 8 bit elements hence elems should be configured as 8 */
if (info->format == IA_CSS_FRAME_FORMAT_NV12_16)
return 1; /* bytes per pixel */
if (info->format == IA_CSS_FRAME_FORMAT_RAW
|| (info->format == IA_CSS_FRAME_FORMAT_RAW_PACKED)) {
if (info->raw_bit_depth)
return CEIL_DIV(info->raw_bit_depth, 8);
else
return 2; /* bytes per pixel */
}
if (info->format == IA_CSS_FRAME_FORMAT_PLANAR_RGB888)
return 3; /* bytes per pixel */
if (info->format == IA_CSS_FRAME_FORMAT_RGBA888)
return 4; /* bytes per pixel */
if (info->format == IA_CSS_FRAME_FORMAT_QPLANE6)
return 2; /* bytes per pixel */
return 1; /* Default is 1 byte per pixel */
}
void ia_css_frame_info_to_frame_sp_info(
struct ia_css_frame_sp_info *to,
const struct ia_css_frame_info *from)
{
ia_css_resolution_to_sp_resolution(&to->res, &from->res);
to->padded_width = (uint16_t)from->padded_width;
to->format = (uint8_t)from->format;
to->raw_bit_depth = (uint8_t)from->raw_bit_depth;
to->raw_bayer_order = from->raw_bayer_order;
}
void ia_css_resolution_to_sp_resolution(
struct ia_css_sp_resolution *to,
const struct ia_css_resolution *from)
{
to->width = (uint16_t)from->width;
to->height = (uint16_t)from->height;
}
int ia_css_frame_init_from_info(struct ia_css_frame *frame,
const struct ia_css_frame_info *frame_info)
{
frame->frame_info.res.width = frame_info->res.width;
frame->frame_info.res.height = frame_info->res.height;
frame->frame_info.format = frame_info->format;
frame->frame_info.padded_width = frame_info->padded_width;
frame->frame_info.raw_bit_depth = frame_info->raw_bit_depth;
frame->valid = true;
/* To indicate it is not valid frame. */
frame->dynamic_queue_id = SH_CSS_INVALID_QUEUE_ID;
frame->buf_type = IA_CSS_BUFFER_TYPE_INVALID;
return ia_css_frame_init_planes(frame);
}
|