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
|
// SPDX-License-Identifier: GPL-2.0
/*
* PiSP Front End Driver
*
* Copyright (c) 2021-2024 Raspberry Pi Ltd.
*/
#include <linux/bitops.h>
#include <linux/delay.h>
#include <linux/moduleparam.h>
#include <linux/pm_runtime.h>
#include <linux/seq_file.h>
#include <media/videobuf2-dma-contig.h>
#include "cfe.h"
#include "pisp-fe.h"
#include "cfe-trace.h"
#define FE_VERSION 0x000
#define FE_CONTROL 0x004
#define FE_STATUS 0x008
#define FE_FRAME_STATUS 0x00c
#define FE_ERROR_STATUS 0x010
#define FE_OUTPUT_STATUS 0x014
#define FE_INT_EN 0x018
#define FE_INT_STATUS 0x01c
/* CONTROL */
#define FE_CONTROL_QUEUE BIT(0)
#define FE_CONTROL_ABORT BIT(1)
#define FE_CONTROL_RESET BIT(2)
#define FE_CONTROL_LATCH_REGS BIT(3)
/* INT_EN / INT_STATUS */
#define FE_INT_EOF BIT(0)
#define FE_INT_SOF BIT(1)
#define FE_INT_LINES0 BIT(8)
#define FE_INT_LINES1 BIT(9)
#define FE_INT_STATS BIT(16)
#define FE_INT_QREADY BIT(24)
/* STATUS */
#define FE_STATUS_QUEUED BIT(0)
#define FE_STATUS_WAITING BIT(1)
#define FE_STATUS_ACTIVE BIT(2)
#define PISP_FE_CONFIG_BASE_OFFSET 0x0040
#define PISP_FE_ENABLE_STATS_CLUSTER \
(PISP_FE_ENABLE_STATS_CROP | PISP_FE_ENABLE_DECIMATE | \
PISP_FE_ENABLE_BLC | PISP_FE_ENABLE_CDAF_STATS | \
PISP_FE_ENABLE_AWB_STATS | PISP_FE_ENABLE_RGBY | \
PISP_FE_ENABLE_LSC | PISP_FE_ENABLE_AGC_STATS)
#define PISP_FE_ENABLE_OUTPUT_CLUSTER(i) \
((PISP_FE_ENABLE_CROP0 | PISP_FE_ENABLE_DOWNSCALE0 | \
PISP_FE_ENABLE_COMPRESS0 | PISP_FE_ENABLE_OUTPUT0) << (4 * (i)))
struct pisp_fe_config_param {
u32 dirty_flags;
u32 dirty_flags_extra;
size_t offset;
size_t size;
};
static const struct pisp_fe_config_param pisp_fe_config_map[] = {
/* *_dirty_flag_extra types */
{ 0, PISP_FE_DIRTY_GLOBAL,
offsetof(struct pisp_fe_config, global),
sizeof(struct pisp_fe_global_config) },
{ 0, PISP_FE_DIRTY_FLOATING,
offsetof(struct pisp_fe_config, floating_stats),
sizeof(struct pisp_fe_floating_stats_config) },
{ 0, PISP_FE_DIRTY_OUTPUT_AXI,
offsetof(struct pisp_fe_config, output_axi),
sizeof(struct pisp_fe_output_axi_config) },
/* *_dirty_flag types */
{ PISP_FE_ENABLE_INPUT, 0,
offsetof(struct pisp_fe_config, input),
sizeof(struct pisp_fe_input_config) },
{ PISP_FE_ENABLE_DECOMPRESS, 0,
offsetof(struct pisp_fe_config, decompress),
sizeof(struct pisp_decompress_config) },
{ PISP_FE_ENABLE_DECOMPAND, 0,
offsetof(struct pisp_fe_config, decompand),
sizeof(struct pisp_fe_decompand_config) },
{ PISP_FE_ENABLE_BLA, 0,
offsetof(struct pisp_fe_config, bla),
sizeof(struct pisp_bla_config) },
{ PISP_FE_ENABLE_DPC, 0,
offsetof(struct pisp_fe_config, dpc),
sizeof(struct pisp_fe_dpc_config) },
{ PISP_FE_ENABLE_STATS_CROP, 0,
offsetof(struct pisp_fe_config, stats_crop),
sizeof(struct pisp_fe_crop_config) },
{ PISP_FE_ENABLE_BLC, 0,
offsetof(struct pisp_fe_config, blc),
sizeof(struct pisp_bla_config) },
{ PISP_FE_ENABLE_CDAF_STATS, 0,
offsetof(struct pisp_fe_config, cdaf_stats),
sizeof(struct pisp_fe_cdaf_stats_config) },
{ PISP_FE_ENABLE_AWB_STATS, 0,
offsetof(struct pisp_fe_config, awb_stats),
sizeof(struct pisp_fe_awb_stats_config) },
{ PISP_FE_ENABLE_RGBY, 0,
offsetof(struct pisp_fe_config, rgby),
sizeof(struct pisp_fe_rgby_config) },
{ PISP_FE_ENABLE_LSC, 0,
offsetof(struct pisp_fe_config, lsc),
sizeof(struct pisp_fe_lsc_config) },
{ PISP_FE_ENABLE_AGC_STATS, 0,
offsetof(struct pisp_fe_config, agc_stats),
sizeof(struct pisp_agc_statistics) },
{ PISP_FE_ENABLE_CROP0, 0,
offsetof(struct pisp_fe_config, ch[0].crop),
sizeof(struct pisp_fe_crop_config) },
{ PISP_FE_ENABLE_DOWNSCALE0, 0,
offsetof(struct pisp_fe_config, ch[0].downscale),
sizeof(struct pisp_fe_downscale_config) },
{ PISP_FE_ENABLE_COMPRESS0, 0,
offsetof(struct pisp_fe_config, ch[0].compress),
sizeof(struct pisp_compress_config) },
{ PISP_FE_ENABLE_OUTPUT0, 0,
offsetof(struct pisp_fe_config, ch[0].output),
sizeof(struct pisp_fe_output_config) },
{ PISP_FE_ENABLE_CROP1, 0,
offsetof(struct pisp_fe_config, ch[1].crop),
sizeof(struct pisp_fe_crop_config) },
{ PISP_FE_ENABLE_DOWNSCALE1, 0,
offsetof(struct pisp_fe_config, ch[1].downscale),
sizeof(struct pisp_fe_downscale_config) },
{ PISP_FE_ENABLE_COMPRESS1, 0,
offsetof(struct pisp_fe_config, ch[1].compress),
sizeof(struct pisp_compress_config) },
{ PISP_FE_ENABLE_OUTPUT1, 0,
offsetof(struct pisp_fe_config, ch[1].output),
sizeof(struct pisp_fe_output_config) },
};
#define pisp_fe_dbg(fe, fmt, arg...) dev_dbg((fe)->v4l2_dev->dev, fmt, ##arg)
#define pisp_fe_info(fe, fmt, arg...) dev_info((fe)->v4l2_dev->dev, fmt, ##arg)
#define pisp_fe_err(fe, fmt, arg...) dev_err((fe)->v4l2_dev->dev, fmt, ##arg)
static inline u32 pisp_fe_reg_read(struct pisp_fe_device *fe, u32 offset)
{
return readl(fe->base + offset);
}
static inline void pisp_fe_reg_write(struct pisp_fe_device *fe, u32 offset,
u32 val)
{
writel(val, fe->base + offset);
}
static inline void pisp_fe_reg_write_relaxed(struct pisp_fe_device *fe,
u32 offset, u32 val)
{
writel_relaxed(val, fe->base + offset);
}
static int pisp_fe_regs_show(struct seq_file *s, void *data)
{
struct pisp_fe_device *fe = s->private;
int ret;
ret = pm_runtime_resume_and_get(fe->v4l2_dev->dev);
if (ret)
return ret;
pisp_fe_reg_write(fe, FE_CONTROL, FE_CONTROL_LATCH_REGS);
#define DUMP(reg) seq_printf(s, #reg " \t0x%08x\n", pisp_fe_reg_read(fe, reg))
DUMP(FE_VERSION);
DUMP(FE_CONTROL);
DUMP(FE_STATUS);
DUMP(FE_FRAME_STATUS);
DUMP(FE_ERROR_STATUS);
DUMP(FE_OUTPUT_STATUS);
DUMP(FE_INT_EN);
DUMP(FE_INT_STATUS);
#undef DUMP
pm_runtime_put(fe->v4l2_dev->dev);
return 0;
}
DEFINE_SHOW_ATTRIBUTE(pisp_fe_regs);
static void pisp_fe_config_write(struct pisp_fe_device *fe,
struct pisp_fe_config *config,
unsigned int start_offset, unsigned int size)
{
const unsigned int max_offset =
offsetof(struct pisp_fe_config, ch[PISP_FE_NUM_OUTPUTS]);
unsigned int end_offset;
u32 *cfg = (u32 *)config;
start_offset = min(start_offset, max_offset);
end_offset = min(start_offset + size, max_offset);
cfg += start_offset >> 2;
for (unsigned int i = start_offset; i < end_offset; i += 4, cfg++)
pisp_fe_reg_write_relaxed(fe, PISP_FE_CONFIG_BASE_OFFSET + i,
*cfg);
}
void pisp_fe_isr(struct pisp_fe_device *fe, bool *sof, bool *eof)
{
u32 status, int_status, out_status, frame_status, error_status;
pisp_fe_reg_write(fe, FE_CONTROL, FE_CONTROL_LATCH_REGS);
status = pisp_fe_reg_read(fe, FE_STATUS);
out_status = pisp_fe_reg_read(fe, FE_OUTPUT_STATUS);
frame_status = pisp_fe_reg_read(fe, FE_FRAME_STATUS);
error_status = pisp_fe_reg_read(fe, FE_ERROR_STATUS);
int_status = pisp_fe_reg_read(fe, FE_INT_STATUS);
pisp_fe_reg_write(fe, FE_INT_STATUS, int_status);
trace_fe_irq(status, out_status, frame_status, error_status,
int_status);
/* We do not report interrupts for the input/stream pad. */
for (unsigned int i = 0; i < FE_NUM_PADS - 1; i++) {
sof[i] = !!(int_status & FE_INT_SOF);
eof[i] = !!(int_status & FE_INT_EOF);
}
}
static bool pisp_fe_validate_output(struct pisp_fe_config const *cfg,
unsigned int c, struct v4l2_format const *f)
{
unsigned int wbytes;
wbytes = cfg->ch[c].output.format.width;
if (cfg->ch[c].output.format.format & PISP_IMAGE_FORMAT_BPS_MASK)
wbytes *= 2;
/* Check output image dimensions are nonzero and not too big */
if (cfg->ch[c].output.format.width < 2 ||
cfg->ch[c].output.format.height < 2 ||
cfg->ch[c].output.format.height > f->fmt.pix.height ||
cfg->ch[c].output.format.stride > f->fmt.pix.bytesperline ||
wbytes > f->fmt.pix.bytesperline)
return false;
/* Check for zero-sized crops, which could cause lockup */
if ((cfg->global.enables & PISP_FE_ENABLE_CROP(c)) &&
((cfg->ch[c].crop.offset_x >= (cfg->input.format.width & ~1) ||
cfg->ch[c].crop.offset_y >= cfg->input.format.height ||
cfg->ch[c].crop.width < 2 || cfg->ch[c].crop.height < 2)))
return false;
if ((cfg->global.enables & PISP_FE_ENABLE_DOWNSCALE(c)) &&
(cfg->ch[c].downscale.output_width < 2 ||
cfg->ch[c].downscale.output_height < 2))
return false;
return true;
}
static bool pisp_fe_validate_stats(struct pisp_fe_config const *cfg)
{
/* Check for zero-sized crop, which could cause lockup */
return (!(cfg->global.enables & PISP_FE_ENABLE_STATS_CROP) ||
(cfg->stats_crop.offset_x < (cfg->input.format.width & ~1) &&
cfg->stats_crop.offset_y < cfg->input.format.height &&
cfg->stats_crop.width >= 2 && cfg->stats_crop.height >= 2));
}
int pisp_fe_validate_config(struct pisp_fe_device *fe,
struct pisp_fe_config *cfg,
struct v4l2_format const *f0,
struct v4l2_format const *f1)
{
/*
* Check the input is enabled, streaming and has nonzero size;
* to avoid cases where the hardware might lock up or try to
* read inputs from memory (which this driver doesn't support).
*/
if (!(cfg->global.enables & PISP_FE_ENABLE_INPUT) ||
cfg->input.streaming != 1 || cfg->input.format.width < 2 ||
cfg->input.format.height < 2) {
pisp_fe_err(fe, "%s: Input config not valid", __func__);
return -EINVAL;
}
for (unsigned int i = 0; i < PISP_FE_NUM_OUTPUTS; i++) {
if (!(cfg->global.enables & PISP_FE_ENABLE_OUTPUT(i))) {
if (cfg->global.enables &
PISP_FE_ENABLE_OUTPUT_CLUSTER(i)) {
pisp_fe_err(fe, "%s: Output %u not valid",
__func__, i);
return -EINVAL;
}
continue;
}
if (!pisp_fe_validate_output(cfg, i, i ? f1 : f0))
return -EINVAL;
}
if ((cfg->global.enables & PISP_FE_ENABLE_STATS_CLUSTER) &&
!pisp_fe_validate_stats(cfg)) {
pisp_fe_err(fe, "%s: Stats config not valid", __func__);
return -EINVAL;
}
return 0;
}
void pisp_fe_submit_job(struct pisp_fe_device *fe, struct vb2_buffer **vb2_bufs,
struct pisp_fe_config *cfg)
{
u64 addr;
u32 status;
/*
* Check output buffers exist and outputs are correctly configured.
* If valid, set the buffer's DMA address; otherwise disable.
*/
for (unsigned int i = 0; i < PISP_FE_NUM_OUTPUTS; i++) {
struct vb2_buffer *buf = vb2_bufs[FE_OUTPUT0_PAD + i];
if (!(cfg->global.enables & PISP_FE_ENABLE_OUTPUT(i)))
continue;
addr = vb2_dma_contig_plane_dma_addr(buf, 0);
cfg->output_buffer[i].addr_lo = addr & 0xffffffff;
cfg->output_buffer[i].addr_hi = addr >> 32;
}
if (vb2_bufs[FE_STATS_PAD]) {
addr = vb2_dma_contig_plane_dma_addr(vb2_bufs[FE_STATS_PAD], 0);
cfg->stats_buffer.addr_lo = addr & 0xffffffff;
cfg->stats_buffer.addr_hi = addr >> 32;
}
/* Set up ILINES interrupts 3/4 of the way down each output */
cfg->ch[0].output.ilines =
max(0x80u, (3u * cfg->ch[0].output.format.height) >> 2);
cfg->ch[1].output.ilines =
max(0x80u, (3u * cfg->ch[1].output.format.height) >> 2);
/*
* The hardware must have consumed the previous config by now.
* This read of status also serves as a memory barrier before the
* sequence of relaxed writes which follow.
*/
status = pisp_fe_reg_read(fe, FE_STATUS);
if (WARN_ON(status & FE_STATUS_QUEUED))
return;
/*
* Unconditionally write buffers, global and input parameters.
* Write cropping and output parameters whenever they are enabled.
* Selectively write other parameters that have been marked as
* changed through the dirty flags.
*/
pisp_fe_config_write(fe, cfg, 0,
offsetof(struct pisp_fe_config, decompress));
cfg->dirty_flags_extra &= ~PISP_FE_DIRTY_GLOBAL;
cfg->dirty_flags &= ~PISP_FE_ENABLE_INPUT;
cfg->dirty_flags |= (cfg->global.enables &
(PISP_FE_ENABLE_STATS_CROP |
PISP_FE_ENABLE_OUTPUT_CLUSTER(0) |
PISP_FE_ENABLE_OUTPUT_CLUSTER(1)));
for (unsigned int i = 0; i < ARRAY_SIZE(pisp_fe_config_map); i++) {
const struct pisp_fe_config_param *p = &pisp_fe_config_map[i];
if (cfg->dirty_flags & p->dirty_flags ||
cfg->dirty_flags_extra & p->dirty_flags_extra)
pisp_fe_config_write(fe, cfg, p->offset, p->size);
}
/* This final non-relaxed write serves as a memory barrier */
pisp_fe_reg_write(fe, FE_CONTROL, FE_CONTROL_QUEUE);
}
void pisp_fe_start(struct pisp_fe_device *fe)
{
pisp_fe_reg_write(fe, FE_CONTROL, FE_CONTROL_RESET);
pisp_fe_reg_write(fe, FE_INT_STATUS, ~0);
pisp_fe_reg_write(fe, FE_INT_EN, FE_INT_EOF | FE_INT_SOF |
FE_INT_LINES0 | FE_INT_LINES1);
fe->inframe_count = 0;
}
void pisp_fe_stop(struct pisp_fe_device *fe)
{
pisp_fe_reg_write(fe, FE_INT_EN, 0);
pisp_fe_reg_write(fe, FE_CONTROL, FE_CONTROL_ABORT);
usleep_range(1000, 2000);
WARN_ON(pisp_fe_reg_read(fe, FE_STATUS));
pisp_fe_reg_write(fe, FE_INT_STATUS, ~0);
}
static int pisp_fe_init_state(struct v4l2_subdev *sd,
struct v4l2_subdev_state *state)
{
struct v4l2_mbus_framefmt *fmt;
fmt = v4l2_subdev_state_get_format(state, FE_STREAM_PAD);
*fmt = cfe_default_format;
fmt->code = MEDIA_BUS_FMT_SRGGB16_1X16;
fmt = v4l2_subdev_state_get_format(state, FE_CONFIG_PAD);
fmt->code = MEDIA_BUS_FMT_FIXED;
fmt->width = sizeof(struct pisp_fe_config);
fmt->height = 1;
fmt = v4l2_subdev_state_get_format(state, FE_OUTPUT0_PAD);
*fmt = cfe_default_format;
fmt->code = MEDIA_BUS_FMT_SRGGB16_1X16;
fmt = v4l2_subdev_state_get_format(state, FE_OUTPUT1_PAD);
*fmt = cfe_default_format;
fmt->code = MEDIA_BUS_FMT_SRGGB16_1X16;
fmt = v4l2_subdev_state_get_format(state, FE_STATS_PAD);
fmt->code = MEDIA_BUS_FMT_FIXED;
fmt->width = sizeof(struct pisp_statistics);
fmt->height = 1;
return 0;
}
static int pisp_fe_pad_set_fmt(struct v4l2_subdev *sd,
struct v4l2_subdev_state *state,
struct v4l2_subdev_format *format)
{
struct v4l2_mbus_framefmt *fmt;
const struct cfe_fmt *cfe_fmt;
/* TODO: format propagation to source pads */
/* TODO: format validation */
switch (format->pad) {
case FE_STREAM_PAD:
cfe_fmt = find_format_by_code(format->format.code);
if (!cfe_fmt || !(cfe_fmt->flags & CFE_FORMAT_FLAG_FE_OUT))
cfe_fmt = find_format_by_code(MEDIA_BUS_FMT_SRGGB16_1X16);
format->format.code = cfe_fmt->code;
format->format.field = V4L2_FIELD_NONE;
fmt = v4l2_subdev_state_get_format(state, FE_STREAM_PAD);
*fmt = format->format;
fmt = v4l2_subdev_state_get_format(state, FE_OUTPUT0_PAD);
*fmt = format->format;
fmt = v4l2_subdev_state_get_format(state, FE_OUTPUT1_PAD);
*fmt = format->format;
return 0;
case FE_OUTPUT0_PAD:
case FE_OUTPUT1_PAD: {
/*
* TODO: we should allow scaling and cropping by allowing the
* user to set the size here.
*/
struct v4l2_mbus_framefmt *sink_fmt, *source_fmt;
u32 sink_code;
u32 code;
cfe_fmt = find_format_by_code(format->format.code);
if (!cfe_fmt || !(cfe_fmt->flags & CFE_FORMAT_FLAG_FE_OUT))
cfe_fmt = find_format_by_code(MEDIA_BUS_FMT_SRGGB16_1X16);
format->format.code = cfe_fmt->code;
sink_fmt = v4l2_subdev_state_get_format(state, FE_STREAM_PAD);
if (!sink_fmt)
return -EINVAL;
source_fmt = v4l2_subdev_state_get_format(state, format->pad);
if (!source_fmt)
return -EINVAL;
sink_code = sink_fmt->code;
code = format->format.code;
/*
* If the source code from the user does not match the code in
* the sink pad, check that the source code matches the
* compressed version of the sink code.
*/
if (code != sink_code &&
code == cfe_find_compressed_code(sink_code))
source_fmt->code = code;
return 0;
}
case FE_CONFIG_PAD:
case FE_STATS_PAD:
default:
return v4l2_subdev_get_fmt(sd, state, format);
}
}
static const struct v4l2_subdev_pad_ops pisp_fe_subdev_pad_ops = {
.get_fmt = v4l2_subdev_get_fmt,
.set_fmt = pisp_fe_pad_set_fmt,
.link_validate = v4l2_subdev_link_validate_default,
};
static int pisp_fe_link_validate(struct media_link *link)
{
struct v4l2_subdev *sd = media_entity_to_v4l2_subdev(link->sink->entity);
struct pisp_fe_device *fe = container_of(sd, struct pisp_fe_device, sd);
pisp_fe_dbg(fe, "%s: link \"%s\":%u -> \"%s\":%u\n", __func__,
link->source->entity->name, link->source->index,
link->sink->entity->name, link->sink->index);
if (link->sink->index == FE_STREAM_PAD)
return v4l2_subdev_link_validate(link);
if (link->sink->index == FE_CONFIG_PAD)
return 0;
return -EINVAL;
}
static const struct media_entity_operations pisp_fe_entity_ops = {
.link_validate = pisp_fe_link_validate,
};
static const struct v4l2_subdev_ops pisp_fe_subdev_ops = {
.pad = &pisp_fe_subdev_pad_ops,
};
static const struct v4l2_subdev_internal_ops pisp_fe_internal_ops = {
.init_state = pisp_fe_init_state,
};
int pisp_fe_init(struct pisp_fe_device *fe, struct dentry *debugfs)
{
int ret;
debugfs_create_file("fe_regs", 0440, debugfs, fe, &pisp_fe_regs_fops);
fe->hw_revision = pisp_fe_reg_read(fe, FE_VERSION);
pisp_fe_info(fe, "PiSP FE HW v%u.%u\n",
(fe->hw_revision >> 24) & 0xff,
(fe->hw_revision >> 20) & 0x0f);
fe->pad[FE_STREAM_PAD].flags =
MEDIA_PAD_FL_SINK | MEDIA_PAD_FL_MUST_CONNECT;
fe->pad[FE_CONFIG_PAD].flags = MEDIA_PAD_FL_SINK;
fe->pad[FE_OUTPUT0_PAD].flags = MEDIA_PAD_FL_SOURCE;
fe->pad[FE_OUTPUT1_PAD].flags = MEDIA_PAD_FL_SOURCE;
fe->pad[FE_STATS_PAD].flags = MEDIA_PAD_FL_SOURCE;
ret = media_entity_pads_init(&fe->sd.entity, ARRAY_SIZE(fe->pad),
fe->pad);
if (ret)
return ret;
/* Initialize subdev */
v4l2_subdev_init(&fe->sd, &pisp_fe_subdev_ops);
fe->sd.internal_ops = &pisp_fe_internal_ops;
fe->sd.entity.function = MEDIA_ENT_F_PROC_VIDEO_SCALER;
fe->sd.entity.ops = &pisp_fe_entity_ops;
fe->sd.entity.name = "pisp-fe";
fe->sd.flags = V4L2_SUBDEV_FL_HAS_DEVNODE;
fe->sd.owner = THIS_MODULE;
snprintf(fe->sd.name, sizeof(fe->sd.name), "pisp-fe");
ret = v4l2_subdev_init_finalize(&fe->sd);
if (ret)
goto err_entity_cleanup;
ret = v4l2_device_register_subdev(fe->v4l2_dev, &fe->sd);
if (ret) {
pisp_fe_err(fe, "Failed register pisp fe subdev (%d)\n", ret);
goto err_subdev_cleanup;
}
/* Must be in IDLE state (STATUS == 0) here. */
WARN_ON(pisp_fe_reg_read(fe, FE_STATUS));
return 0;
err_subdev_cleanup:
v4l2_subdev_cleanup(&fe->sd);
err_entity_cleanup:
media_entity_cleanup(&fe->sd.entity);
return ret;
}
void pisp_fe_uninit(struct pisp_fe_device *fe)
{
v4l2_device_unregister_subdev(&fe->sd);
v4l2_subdev_cleanup(&fe->sd);
media_entity_cleanup(&fe->sd.entity);
}
|