1 From ce14be51d71bf39893786d380cbb82e81d2a10d5 Mon Sep 17 00:00:00 2001
2 From: Nick Hollinghurst <nick.hollinghurst@raspberrypi.org>
3 Date: Wed, 14 Jul 2021 09:32:49 +0100
4 Subject: [PATCH] Add new "pispbe" driver (though not yet the Makesfiles or DT
7 media: bcm2712: Initial commit of the PiSP BE driver
9 Signed-off-by: Naushir Patuck <naush@raspberrypi.com>
11 media: bcm2712_pisp_be: PiSP driver updates.
13 - Start registering video nodes from /dev/video20
15 - Define MODULE_DEVICE_TABLE() to probe correctly
17 Signed-off-by: Naushir Patuck <naush@raspberrypi.com>
19 media: pisp_be: Improve image format support
21 Add a new format table that lists the V4L2 format enums and their properties.
22 Keep the exising 'RPBP' format to support the userland verification tools.
23 This format requires userland to fill all plane properties. Standard V4L2
24 formats will derive these properties from the format table.
26 Signed-off-by: Naushir Patuck <naush@raspberrypi.com>
28 media: pisp_be: Advertise the meta output format explictily.
30 Signed-off-by: Naushir Patuck <naush@raspberrypi.com>
32 drivers: pisp_be: Various updates and cleanups
34 - Switch to a single node group for now.
35 - Add a node description table to simplify node handling.
36 - Switch HoG output to V4L2_CAP_META_CAPTURE type.
37 - Use string descriptions for node names in logging messages.
39 Signed-off-by: Naushir Patuck <naush@raspberrypi.com>
41 pisp_be: Updates for libcamera usage:
43 - Remove indexes from device entity names
44 - Add enumframesize and enumfmts ioctls
45 - Add default format to all nodes.
47 Signed-off-by: Naushir Patuck <naush@raspberrypi.com>
49 v4l2: pisp_be: Move format definitions into v4l2 core
51 Signed-off-by: Naushir Patuck <naush@raspberrypi.com>
53 media: raspberrypi: Move PiSP common headers to a single location
55 Signed-off-by: Naushir Patuck <naush@raspberrypi.com>
57 media: raspberrypi: Remove old pispbe driver.
59 This is now supersede by the driver in drivers/media/platform/raspberrypi/
61 Signed-off-by: Naushir Patuck <naush@raspberrypi.com>
63 PISP-BE Driver: Automate buffer-cycling for TDN and Stitch state.
64 Remove "tdn-input" and "stitch-input" nodes altogether (the output
65 nodes must still be opened and REQBUFS called with 1 or 2 buffers).
66 Also, a bit of tidying of buffer address handling and locking.
68 PISP-BE driver: Turn debug level right down to reduce overly-chatty messages
70 media: bcm2712: Depend on CONFIG_PM
72 Depend on CONFIG_PM as the driver uses the runtime_pm infrastructure.
74 Signed-off-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
76 drivers: media: pisp_be: Move BE driver to a raspberrypi directory
78 Move the pisp_be driver from drivers/media/platform/raspberrypi/ to
79 drivers/media/platform/raspberrypi/pisp_be/. This seems the accepted
80 convention in the drivers/media/platform/ directory structure.
82 Also rename the driver module from bcm2712_pisp_be to pisp_be.
84 Signed-off-by: Naushir Patuck <naush@raspberrypi.com>
86 pisp_be: Updates for libcamera streaming:
88 - Add some required v4l2 formats
89 - Add buf_prepare ioctl
90 - Set plane offsets correctly before reprogramming
92 pisp_be: Reduce logging verbosity
94 Signed-off-by: Naushir Patuck <naush@raspberrypi.com>
96 pisp_be: Add buffer timestamps
98 While at it, remove duplicate code when checking if the HW has completed
101 Signed-off-by: Naushir Patuck <naush@raspberrypi.com>
103 pisp_be: Remove queue size allocation constraint
105 PISP-BE driver: Fix ISR to handle multiple done/start events.
107 PISP-BE: Fix variable-name shadowing bugette
109 PISP-BE: Support for two node groups. Reorganize the driver.
111 To support 2 concurrent libcamera applications, we need 2 node groups,
112 need to allow multiple opens of each node (because libcamera does this)
113 and create a separate media device per group (to support file-locking).
115 This triggered significant rearrangement of the driver. Some calls
116 that we formerly intercepted have been delegated back to v4l2/vb2.
117 Logging changes arising from multiple v4l2_dev. Refactored probe()
118 and initialization. Avoid dynamically-allocated entity name strings.
120 drivers: media: pisp_be: Add vidioc_enum_fmt_meta_out
122 This was missing in the struct v4l2_ioctl_ops definition.
124 Signed-off-by: Naushir Patuck <naush@raspberrypi.com>
126 drivers: media: pispe_be: Add Bayer compressed formats
128 Add PiSP Bayer compressed formats to the list of supported pixel formats
129 for the PiSP backend driver.
131 Signed-off-by: Naushir Patuck <naush@raspberrypi.com>
133 drivers: meida: pisp_be: Fix overflow in plane size calculations
135 The calculations for buffer plane sizes can overflow because of the
136 plane factor shift. Fix this by using u64 integers for the calculations.
138 Signed-off-by: Naushir Patuck <naush@raspberrypi.com>
140 drivers: media: pisp_be: Use 0P3 for plane factors
142 Use less precision for the plane factors to avoid any nasty overflows.
144 Signed-off-by: Naushir Patuck <naush@raspberrypi.com>
146 media: pisp: Checkpatch and coding style fixups
148 Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com>
150 media: pisp_be: More coding style fixups
152 media: platform: bcm2712: pisp_be: Fix crash when buffer format not set
154 Signed-off-by: Nick Hollinghurst <nick.hollinghurst@raspberrypi.com>
156 media: platform: bcm2712: pisp_be: Allow non-SRGB colour spaces on RGB outputs
158 Allow colour spaces other than SRGB when the output format in question
159 is an RGB output. This commit merely ports over existing changes from
162 Signed-off-by: David Plowman <david.plowman@raspberrypi.com>
164 media: platform: bcm2712: Tweak list of BE supported image formats
166 Remove RGB565 and 10- and 12-bit packed raw formats, which ISP-BE
167 can't support for input or output. Add NV12M and NV21M which it can.
168 (I didn't bother adding YUV422P, which apparently is not widely used.)
170 Signed-off-by: Nick Hollinghurst <nick.hollinghurst@raspberrypi.com>
172 pisp_be: Fill the hardware revision in the media entity struct
174 This can be used by userland to determine the hardware capabilities.
176 Signed-off-by: Naushir Patuck <naush@raspberrypi.com>
178 bcm2712: Use BIT() macro
180 Use the BIT() macro instead of plain bit shifting.
182 Signed-off-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
184 bcm2712: Invert condition in pispbe_schedule_internal()
186 Return earlier and save one indentation level
188 Signed-off-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
190 bcm2712: Invert condition in for loop
192 Save one indentation level by continuing if the node is not streaming.
194 Signed-off-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
196 bcm2712: Do not declare a local variable
198 There already is a truct pispbe_node *node in the function scope.
200 Signed-off-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
202 bcm21712: Siplify pispbe_schedule_one()
204 A little more verbose but easier to follow ?
206 Signed-off-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
208 bcm2712: Rename pispbe_schedule_all() to pispbe_schedule_any()
210 The pispbe_schedule_all() function name is misleading, as the function
211 schedule a single job from any of the node groups. Rename it.
213 Signed-off-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
215 media: platform: bcm2712: Remove buffer auto-cycling from ISP-BE
217 Previously, the ISP-BE driver tried to automate "ping pong" buffers
218 for TDN and HDR state, but did not fully conceal them from users.
220 The automation has been removed: there are now separate output and
221 capture queues for each of TDN and Stitch, which must be managed by
222 user code (DMABUFs may be used to circulate buffers between queues).
224 Signed-off-by: Nick Hollinghurst <nick.hollinghurst@raspberrypi.com>
226 drivers: media: pisp_be: Cache BE config buffer vaddr
228 When programming a new job, we access at the config buffer, possibly
229 from ISR context. So fetch and the virtual address when queuing the
232 Signed-off-by: Naushir Patuck <naush@raspberrypi.com>
234 drivers: media: pisp_be: Remove all traces of ctrls and request API
236 These APIs are not (and will not) be used by the driver, so remove them.
238 Signed-off-by: Naushir Patuck <naush@raspberrypi.com>
240 media: bcm2712: Replace v4l2_dbg with dev_dbg
242 Replace the v4l2 debug helpers with the device debug once, which are
245 Signed-off-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
247 media: bcm2712: Remove of_match_ptr()
249 The of_match_ptr() usage could cause a compiler warning if
250 CONFIG_OF is not enabled, as the pispbe_of_match variable would
253 As the of_match_table field of struct platform_driver exists
254 unconditionally, drop of_match_ptr() to avoid a warning.
256 Signed-off-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
258 drivers: media: pispbe: Add local config buffer DMA allocation
260 When initialiasing the driver, allocate a number of tiles + config
261 structures used for storing hardware config internally in the driver.
263 Signed-off-by: Naushir Patuck <naush@raspberrypi.com>
265 drivers: media: pispbe: Use local config buffers
267 Store a copy of the config + tiles buffer locally when the buffer gets
268 queued. This resolves the security issue where a userland process may
269 modify the config buffer after it has been queued.
271 Signed-off-by: Naushir Patuck <naush@raspberrypi.com>
273 drivers: media: pispbe: Validate config buffers
275 Perform a basic config validation on the device output nodes to ensure
276 the buffer size and stride values do not result in a buffer overrun.
278 Signed-off-by: Naushir Patuck <naush@raspberrypi.com>
280 media: bcm2712: Rework probe sequence order
282 Rework the probe sequence to:
283 1) Use dev_err_probe() when failing to get clocks
284 2) Disable clock on error path
285 3) Disable the node groups if they have been enabled and
286 propagate the error up
288 Also disable clocks in the remove() function.
290 Signed-off-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
292 media: bcm2712: Use pm_runtime_ops
294 Introduce usage of runtime resume and suspend operations.
296 The diver only uses a single clock source which is enable/disabled
297 at resume and suspend time.
299 Implement file open and release operations to control enablement of
302 Signed-off-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
304 media: bcm2712: Demote info message
306 Demote info message about clock enablement to dev_dbg()
308 Signed-off-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
310 media: bcm2712: Move pm_runtime calls to streamon/streamoff
312 Move the calls to pm_runtime_resume_and_get() and pm_runtime_put()
313 to the streamon and streamoff ioctl handlers.
315 Remove custom handlers for the open and close file operations and use
316 the framework provided helpers.
318 Signed-off-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
320 media: bcm2712: Use pm_runtime_autosuspend()
322 Use the _autosuspend() version of runtime_pm_put() in order to avoid
323 resuming and suspending the peripheral in between streaming sessions
324 closely apart one from the other.
326 Signed-off-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
328 drivers: media: pisp_be: Conditionally check buffers when preparing jobs
330 When preparing a job, check the global enables in the config structure
331 to see if the Output0/1, Tdn and Stitch blocks are enabled, and only
332 test for a buffer queued if they are.
334 This will allow userland to control the outputs selectively without
335 disabling/re-enabling the respective device nodes.
337 Signed-off-by: Naushir Patuck <naush@raspberrypi.com>
339 media: bcm2712: Rework media controller registration
341 The current implementation register the v4l2_device and the video
342 devices first, then creates the media controller and manually registers
345 Rework the registration procedure to first create the v4l2_device and
346 register the media_device with it. Then create the video nodes which
347 gets automatically registered in the media graph by the core.
349 Signed-off-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
351 media: bcm2712: Create v4l2_subdev for ISP entity
353 Create a v4l2 subdevice to represent the PISPBE ISP entity.
355 Signed-off-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
357 media: bcm2712: Fix v4l2-compliance warn on QUERYCAP
361 warn: v4l2-compliance.cpp(669): media bus_info
362 'platform:1000880000.pisp_be' differs from V4L2 bus_info
365 by populating the driver caps bus_info by using dev_name().
367 Signed-off-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
369 media: bcm2712: Fix v4l2-compliance warn on invalid pixfmt
371 The V4L2 API for the TRY_FMT/S_FMT ioctl allows the ioctl handler to
372 return an error code only in specific conditions. If an invalid pixel
373 format is supplied it should be adjusted instead of an error being
376 Albeit, v4l2-compliance treats this situation as a warning and not as
377 an error because the behaviour has been discussed in length in the past.
379 warn: v4l2-test-formats.cpp(794): TRY_FMT cannot handle an invalid pixelformat.
380 warn: v4l2-test-formats.cpp(795): This may or may not be a problem. For more information see:
381 warn: v4l2-test-formats.cpp(796): http://www.mail-archive.com/linux-media@vger.kernel.org/msg56550.html
382 VIDIOC_TRY_FMT returned -1 (Invalid argument)
384 Regardless of the warning vs failure decision, adjust the try_format()
385 function implementation to use V4L2_PIX_FMT_YUV420M as default pixel
386 format if the supplied one is invalid.
388 Signed-off-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
390 media: bcm2712: Fix v4l2-compliance warn on HOG pix format
392 The try_format() implementation for the HOG video device node returns
393 an error if the supplied pixel format is not correct.
395 As per the video device output and capture video nodes, this contradicts
396 the V4L2 specification even if it is treated as a warning by
399 Fix this by forcing the buffer pixel format and size to the default
400 supported one. While at here, use the BIT() macro in the format
401 initialization function.
403 Signed-off-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
405 media: bcm2712: Fix formats enumeration
407 Right now a single implementation of enum_fmt() is used for all nodes
408 in a group. This means that all the BE supported formats are listed for
409 all the nodes. This is incorrect as the meta capture and output node
410 formats should be restricted, and the meta formats should not be
411 enumerated for video output and capture devices.
413 Fix this by restricting the enumeration of META formats to the config
414 and hog nodes. Split out from the list of supported_formats the
415 V4L2_META_FMT_RPI_BE_CFG which is only used for the meta_out node, while
416 V4L2_PIX_FMT_RPI_BE is kept in the list of supported_formats as it can
417 be used as an opaque format for both meta_cap, video_cap and video_out
420 Signed-off-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
422 media: bcm2712: Minor fixes to support PiSP regression tests
424 Allow RGB input, not just Bayer (but only of those at once);
425 Allow Wallpaper image formats. XXX They are not yet size-checked;
426 Set "chicken bits" to test BURST_TRIM and AXI AWID/BID variation.
427 Convert some v4l2_err() to dev_err()
429 Signed-off-by: Nick Hollinghurst <nick.hollinghurst@raspberrypi.com>
431 drivers: media: pisp_be: Use the maximum number of config buffers
433 Set PISP_BE_NUM_CONFIG_BUFFERS the the maximum number of possible
434 buffers. In the worst case, this overallocates config buffers, but
435 given their size, it's not too much of a problem.
437 Signed-off-by: Naushir Patuck <naush@raspberrypi.com>
439 media: pisp_be: Fix extra PM runtime put
441 vidioc_streamoff callback can be called even if vidioc_streamon was
442 never called. The driver currently does PM runtime get/put in these
443 callbacks, which may lead to a put without a matching get.
445 Fix this by moving the PM runtime get/put to vb2_ops's start_streaming &
446 stop_streaming, which the framework makes sure won't get extra calls.
448 Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
450 drivers: media: pisp_be: Don't report V4L2_PIX_FMT_RPI_BE format
452 This is an internal opaque format, not to be reported in enum_fmt.
454 Signed-off-by: Naushir Patuck <naush@raspberrypi.com>
456 drivers/media/platform/Kconfig | 1 +
457 drivers/media/platform/Makefile | 1 +
458 drivers/media/platform/raspberrypi/Kconfig | 5 +
459 drivers/media/platform/raspberrypi/Makefile | 3 +
460 .../platform/raspberrypi/pisp_be/Kconfig | 12 +
461 .../platform/raspberrypi/pisp_be/Makefile | 6 +
462 .../platform/raspberrypi/pisp_be/pisp_be.c | 1985 +++++++++++++++++
463 .../raspberrypi/pisp_be/pisp_be_config.h | 533 +++++
464 .../raspberrypi/pisp_be/pisp_be_formats.h | 469 ++++
465 drivers/media/v4l2-core/v4l2-ioctl.c | 2 +
466 include/media/raspberrypi/pisp_common.h | 65 +
467 include/media/raspberrypi/pisp_types.h | 144 ++
468 include/uapi/linux/videodev2.h | 6 +
469 13 files changed, 3232 insertions(+)
470 create mode 100644 drivers/media/platform/raspberrypi/Kconfig
471 create mode 100644 drivers/media/platform/raspberrypi/Makefile
472 create mode 100644 drivers/media/platform/raspberrypi/pisp_be/Kconfig
473 create mode 100644 drivers/media/platform/raspberrypi/pisp_be/Makefile
474 create mode 100644 drivers/media/platform/raspberrypi/pisp_be/pisp_be.c
475 create mode 100644 drivers/media/platform/raspberrypi/pisp_be/pisp_be_config.h
476 create mode 100644 drivers/media/platform/raspberrypi/pisp_be/pisp_be_formats.h
477 create mode 100644 include/media/raspberrypi/pisp_common.h
478 create mode 100644 include/media/raspberrypi/pisp_types.h
480 --- a/drivers/media/platform/Kconfig
481 +++ b/drivers/media/platform/Kconfig
482 @@ -76,6 +76,7 @@ source "drivers/media/platform/mediatek/
483 source "drivers/media/platform/nvidia/Kconfig"
484 source "drivers/media/platform/nxp/Kconfig"
485 source "drivers/media/platform/qcom/Kconfig"
486 +source "drivers/media/platform/raspberrypi/Kconfig"
487 source "drivers/media/platform/renesas/Kconfig"
488 source "drivers/media/platform/rockchip/Kconfig"
489 source "drivers/media/platform/samsung/Kconfig"
490 --- a/drivers/media/platform/Makefile
491 +++ b/drivers/media/platform/Makefile
492 @@ -19,6 +19,7 @@ obj-y += mediatek/
496 +obj-y += raspberrypi/
501 +++ b/drivers/media/platform/raspberrypi/Kconfig
503 +# SPDX-License-Identifier: GPL-2.0-only
505 +comment "Raspberry Pi media platform drivers"
507 +source "drivers/media/platform/raspberrypi/pisp_be/Kconfig"
509 +++ b/drivers/media/platform/raspberrypi/Makefile
511 +# SPDX-License-Identifier: GPL-2.0
515 +++ b/drivers/media/platform/raspberrypi/pisp_be/Kconfig
517 +config VIDEO_RASPBERRYPI_PISP_BE
518 + tristate "Raspberry Pi PiSP Backend (BE) ISP driver"
519 + depends on VIDEO_DEV && PM
520 + select VIDEO_V4L2_SUBDEV_API
521 + select MEDIA_CONTROLLER
522 + select VIDEOBUF2_DMA_CONTIG
525 + Say Y here to enable support for the PiSP Backend (BE) ISP driver.
527 + To compile this driver as a module, choose M here. The module will be
530 +++ b/drivers/media/platform/raspberrypi/pisp_be/Makefile
532 +# SPDX-License-Identifier: GPL-2.0
534 +# Makefile for Raspberry Pi PiSP Backend driver
536 +pisp-be-objs := pisp_be.o
537 +obj-$(CONFIG_VIDEO_RASPBERRYPI_PISP_BE) += pisp-be.o
539 +++ b/drivers/media/platform/raspberrypi/pisp_be/pisp_be.c
541 +// SPDX-License-Identifier: GPL-2.0
543 + * PiSP Back End driver.
544 + * Copyright (c) 2021-2022 Raspberry Pi Limited.
547 +#include <linux/clk.h>
548 +#include <linux/interrupt.h>
549 +#include <linux/io.h>
550 +#include <linux/module.h>
551 +#include <linux/platform_device.h>
552 +#include <linux/pm_runtime.h>
553 +#include <media/v4l2-device.h>
554 +#include <media/v4l2-ioctl.h>
555 +#include <media/videobuf2-dma-contig.h>
556 +#include <media/videobuf2-vmalloc.h>
558 +#include "pisp_be_config.h"
559 +#include "pisp_be_formats.h"
561 +MODULE_DESCRIPTION("PiSP Back End driver");
562 +MODULE_AUTHOR("David Plowman <david.plowman@raspberrypi.com>");
563 +MODULE_AUTHOR("Nick Hollinghurst <nick.hollinghurst@raspberrypi.com>");
564 +MODULE_LICENSE("GPL v2");
566 +/* Offset to use when registering the /dev/videoX node */
567 +#define PISPBE_VIDEO_NODE_OFFSET 20
569 +/* Maximum number of config buffers possible */
570 +#define PISP_BE_NUM_CONFIG_BUFFERS VB2_MAX_FRAME
573 + * We want to support 2 independent instances allowing 2 simultaneous users
574 + * of the ISP-BE (of course they share hardware, platform resources and mutex).
575 + * Each such instance comprises a group of device nodes representing input
576 + * and output queues, and a media controller device node to describe them.
578 +#define PISPBE_NUM_NODE_GROUPS 2
580 +#define PISPBE_NAME "pispbe"
582 +/* Some ISP-BE registers */
583 +#define PISP_BE_VERSION_OFFSET (0x0)
584 +#define PISP_BE_CONTROL_OFFSET (0x4)
585 +#define PISP_BE_TILE_ADDR_LO_OFFSET (0x8)
586 +#define PISP_BE_TILE_ADDR_HI_OFFSET (0xc)
587 +#define PISP_BE_STATUS_OFFSET (0x10)
588 +#define PISP_BE_BATCH_STATUS_OFFSET (0x14)
589 +#define PISP_BE_INTERRUPT_EN_OFFSET (0x18)
590 +#define PISP_BE_INTERRUPT_STATUS_OFFSET (0x1c)
591 +#define PISP_BE_AXI_OFFSET (0x20)
592 +#define PISP_BE_CONFIG_BASE_OFFSET (0x40)
593 +#define PISP_BE_IO_INPUT_ADDR0_LO_OFFSET (PISP_BE_CONFIG_BASE_OFFSET)
594 +#define PISP_BE_GLOBAL_BAYER_ENABLE_OFFSET (PISP_BE_CONFIG_BASE_OFFSET + 0x70)
595 +#define PISP_BE_GLOBAL_RGB_ENABLE_OFFSET (PISP_BE_CONFIG_BASE_OFFSET + 0x74)
596 +#define N_HW_ADDRESSES 14
597 +#define N_HW_ENABLES 2
599 +#define PISP_BE_VERSION_2712C1 0x02252700
600 +#define PISP_BE_VERSION_MINOR_BITS 0xF
603 + * This maps our nodes onto the inputs/outputs of the actual PiSP Back End.
604 + * Be wary of the word "OUTPUT" which is used ambiguously here. In a V4L2
605 + * context it means an input to the hardware (source image or metadata).
606 + * Elsewhere it means an output from the hardware.
616 + STITCH_OUTPUT_NODE,
621 +struct node_description {
622 + const char *ent_name;
623 + enum v4l2_buf_type buf_type;
627 +static const struct node_description node_desc[PISPBE_NUM_NODES] = {
628 + /* MAIN_INPUT_NODE */
630 + .ent_name = PISPBE_NAME "-input",
631 + .buf_type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE,
632 + .caps = V4L2_CAP_VIDEO_OUTPUT_MPLANE,
634 + /* TDN_INPUT_NODE */
636 + .ent_name = PISPBE_NAME "-tdn_input",
637 + .buf_type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE,
638 + .caps = V4L2_CAP_VIDEO_OUTPUT_MPLANE,
640 + /* STITCH_INPUT_NODE */
642 + .ent_name = PISPBE_NAME "-stitch_input",
643 + .buf_type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE,
644 + .caps = V4L2_CAP_VIDEO_OUTPUT_MPLANE,
646 + /* HOG_OUTPUT_NODE */
648 + .ent_name = PISPBE_NAME "-hog_output",
649 + .buf_type = V4L2_BUF_TYPE_META_CAPTURE,
650 + .caps = V4L2_CAP_META_CAPTURE,
654 + .ent_name = PISPBE_NAME "-output0",
655 + .buf_type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE,
656 + .caps = V4L2_CAP_VIDEO_CAPTURE_MPLANE,
660 + .ent_name = PISPBE_NAME "-output1",
661 + .buf_type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE,
662 + .caps = V4L2_CAP_VIDEO_CAPTURE_MPLANE,
664 + /* TDN_OUTPUT_NODE */
666 + .ent_name = PISPBE_NAME "-tdn_output",
667 + .buf_type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE,
668 + .caps = V4L2_CAP_VIDEO_CAPTURE_MPLANE,
670 + /* STITCH_OUTPUT_NODE */
672 + .ent_name = PISPBE_NAME "-stitch_output",
673 + .buf_type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE,
674 + .caps = V4L2_CAP_VIDEO_CAPTURE_MPLANE,
678 + .ent_name = PISPBE_NAME "-config",
679 + .buf_type = V4L2_BUF_TYPE_META_OUTPUT,
680 + .caps = V4L2_CAP_META_OUTPUT,
684 +#define NODE_DESC_IS_OUTPUT(desc) ( \
685 + ((desc)->buf_type == V4L2_BUF_TYPE_META_OUTPUT) || \
686 + ((desc)->buf_type == V4L2_BUF_TYPE_VIDEO_OUTPUT) || \
687 + ((desc)->buf_type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE))
689 +#define NODE_IS_META(node) ( \
690 + ((node)->buf_type == V4L2_BUF_TYPE_META_OUTPUT) || \
691 + ((node)->buf_type == V4L2_BUF_TYPE_META_CAPTURE))
692 +#define NODE_IS_OUTPUT(node) ( \
693 + ((node)->buf_type == V4L2_BUF_TYPE_META_OUTPUT) || \
694 + ((node)->buf_type == V4L2_BUF_TYPE_VIDEO_OUTPUT) || \
695 + ((node)->buf_type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE))
696 +#define NODE_IS_CAPTURE(node) ( \
697 + ((node)->buf_type == V4L2_BUF_TYPE_META_CAPTURE) || \
698 + ((node)->buf_type == V4L2_BUF_TYPE_VIDEO_CAPTURE) || \
699 + ((node)->buf_type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE))
700 +#define NODE_IS_MPLANE(node) ( \
701 + ((node)->buf_type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) || \
702 + ((node)->buf_type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE))
705 + * Structure to describe a single node /dev/video<N> which represents a single
706 + * input or output queue to the PiSP Back End device.
708 +struct pispbe_node {
711 + enum v4l2_buf_type buf_type;
712 + struct video_device vfd;
713 + struct media_pad pad;
714 + struct media_intf_devnode *intf_devnode;
715 + struct media_link *intf_link;
716 + struct pispbe_node_group *node_group;
717 + struct mutex node_lock;
718 + struct mutex queue_lock;
719 + spinlock_t ready_lock;
720 + struct list_head ready_queue;
721 + struct vb2_queue queue;
722 + struct v4l2_format format;
723 + const struct pisp_be_format *pisp_format;
726 +/* For logging only, use the entity name with "pispbe" and separator removed */
727 +#define NODE_NAME(node) \
728 + (node_desc[(node)->id].ent_name + sizeof(PISPBE_NAME))
729 +#define NODE_GET_V4L2(node) ((node)->node_group->v4l2_dev)
732 + * Node group structure, which comprises all the input and output nodes that a
733 + * single PiSP client will need, along with its own v4l2 and media devices.
735 +struct pispbe_node_group {
737 + struct v4l2_device v4l2_dev;
738 + struct v4l2_subdev sd;
739 + struct pispbe_dev *pispbe;
740 + struct media_device mdev;
741 + struct pispbe_node node[PISPBE_NUM_NODES];
742 + u32 streaming_map; /* bitmap of which nodes are streaming */
743 + struct media_pad pad[PISPBE_NUM_NODES]; /* output pads first */
744 + struct pisp_be_tiles_config *config;
745 + dma_addr_t config_dma_addr;
748 +/* Records details of the jobs currently running or queued on the h/w. */
750 + struct pispbe_node_group *node_group;
752 + * An array of buffer pointers - remember it's source buffers first,
753 + * then captures, then metadata last.
755 + struct pispbe_buffer *buf[PISPBE_NUM_NODES];
759 + * Structure representing the entire PiSP Back End device, comprising several
760 + * node groups which share platform resources and a mutex for the actual HW.
763 + struct device *dev;
764 + struct pispbe_node_group node_group[PISPBE_NUM_NODE_GROUPS];
765 + int hw_busy; /* non-zero if a job is queued or is being started */
766 + struct pispbe_job queued_job, running_job;
767 + void __iomem *be_reg_base;
772 + spinlock_t hw_lock; /* protects "hw_busy" flag and streaming_map */
775 +static inline u32 read_reg(struct pispbe_dev *pispbe, unsigned int offset)
777 + return readl(pispbe->be_reg_base + offset);
780 +static inline void write_reg(struct pispbe_dev *pispbe, unsigned int offset,
783 + writel(val, pispbe->be_reg_base + offset);
786 +/* Check and initialize hardware. */
787 +static int hw_init(struct pispbe_dev *pispbe)
791 + /* Check the HW is present and has a known version */
792 + u = read_reg(pispbe, PISP_BE_VERSION_OFFSET);
793 + dev_info(pispbe->dev, "pispbe_probe: HW version: 0x%08x", u);
794 + pispbe->hw_version = u;
795 + if ((u & ~PISP_BE_VERSION_MINOR_BITS) != PISP_BE_VERSION_2712C1)
798 + /* Clear leftover interrupts */
799 + write_reg(pispbe, PISP_BE_INTERRUPT_STATUS_OFFSET, 0xFFFFFFFFu);
800 + u = read_reg(pispbe, PISP_BE_BATCH_STATUS_OFFSET);
801 + dev_info(pispbe->dev, "pispbe_probe: BatchStatus: 0x%08x", u);
802 + pispbe->done = (uint8_t)u;
803 + pispbe->started = (uint8_t)(u >> 8);
804 + u = read_reg(pispbe, PISP_BE_STATUS_OFFSET);
805 + dev_info(pispbe->dev, "pispbe_probe: Status: 0x%08x", u);
806 + if (u != 0 || pispbe->done != pispbe->started) {
807 + dev_err(pispbe->dev, "pispbe_probe: HW is stuck or busy\n");
811 + * AXI QOS=0, CACHE=4'b0010, PROT=3'b011
812 + * Also set "chicken bits" 22:20 which enable sub-64-byte bursts
813 + * and AXI AWID/BID variability (on versions which support this).
815 + write_reg(pispbe, PISP_BE_AXI_OFFSET, 0x32703200u);
817 + /* Enable both interrupt flags */
818 + write_reg(pispbe, PISP_BE_INTERRUPT_EN_OFFSET, 0x00000003u);
823 + * Queue a job to the h/w. If the h/w is idle it will begin immediately.
824 + * Caller must ensure it is "safe to queue", i.e. we don't already have a
825 + * queued, unstarted job.
827 +static void hw_queue_job(struct pispbe_dev *pispbe,
828 + dma_addr_t hw_dma_addrs[N_HW_ADDRESSES],
829 + u32 hw_enables[N_HW_ENABLES],
830 + struct pisp_be_config *config, dma_addr_t tiles,
831 + unsigned int num_tiles)
833 + unsigned int begin, end;
836 + if (read_reg(pispbe, PISP_BE_STATUS_OFFSET) & 1)
837 + dev_err(pispbe->dev, "ERROR: not safe to queue new job!\n");
840 + * Write configuration to hardware. DMA addresses and enable flags
841 + * are passed separately, because the driver needs to sanitize them,
842 + * and we don't want to modify (or be vulnerable to modifications of)
843 + * the mmap'd buffer.
845 + for (u = 0; u < N_HW_ADDRESSES; ++u) {
846 + write_reg(pispbe, PISP_BE_IO_INPUT_ADDR0_LO_OFFSET + 8 * u,
847 + (u32)(hw_dma_addrs[u]));
848 + write_reg(pispbe, PISP_BE_IO_INPUT_ADDR0_LO_OFFSET + 8 * u + 4,
849 + (u32)(hw_dma_addrs[u] >> 32));
851 + write_reg(pispbe, PISP_BE_GLOBAL_BAYER_ENABLE_OFFSET, hw_enables[0]);
852 + write_reg(pispbe, PISP_BE_GLOBAL_RGB_ENABLE_OFFSET, hw_enables[1]);
855 + * Everything else is as supplied by the user. XXX Buffer sizes not
858 + begin = offsetof(struct pisp_be_config, global.bayer_order) /
860 + end = offsetof(struct pisp_be_config, axi) / sizeof(u32);
861 + for (u = begin; u < end; u++) {
862 + unsigned int val = ((u32 *)config)[u];
864 + write_reg(pispbe, PISP_BE_CONFIG_BASE_OFFSET + 4 * u, val);
867 + /* Read back the addresses -- an error here could be fatal */
868 + for (u = 0; u < N_HW_ADDRESSES; ++u) {
869 + unsigned int offset = PISP_BE_IO_INPUT_ADDR0_LO_OFFSET + 8 * u;
870 + u64 along = read_reg(pispbe, offset);
872 + along += ((u64)read_reg(pispbe, offset + 4)) << 32;
873 + if (along != (u64)(hw_dma_addrs[u])) {
874 + dev_err(pispbe->dev,
875 + "ISP BE config error: check if ISP RAMs enabled?\n");
881 + * Write tile pointer to hardware. XXX Tile offsets and sizes not
882 + * checked (and even if checked, the user could subsequently modify
885 + write_reg(pispbe, PISP_BE_TILE_ADDR_LO_OFFSET, (u32)tiles);
886 + write_reg(pispbe, PISP_BE_TILE_ADDR_HI_OFFSET, (u32)(tiles >> 32));
888 + /* Enqueue the job */
889 + write_reg(pispbe, PISP_BE_CONTROL_OFFSET, 3 + 65536 * num_tiles);
892 +struct pispbe_buffer {
893 + struct vb2_v4l2_buffer vb;
894 + struct list_head ready_list;
895 + unsigned int config_index;
898 +static int get_addr_3(dma_addr_t addr[3], struct pispbe_buffer *buf,
899 + struct pispbe_node *node)
901 + unsigned int num_planes = node->format.fmt.pix_mp.num_planes;
902 + unsigned int plane_factor = 0;
906 + if (!buf || !node->pisp_format)
909 + WARN_ON(!NODE_IS_MPLANE(node));
912 + * Determine the base plane size. This will not be the same
913 + * as node->format.fmt.pix_mp.plane_fmt[0].sizeimage for a single
914 + * plane buffer in an mplane format.
916 + size = node->format.fmt.pix_mp.plane_fmt[0].bytesperline *
917 + node->format.fmt.pix_mp.height;
919 + for (p = 0; p < num_planes && p < 3; p++) {
920 + addr[p] = vb2_dma_contig_plane_dma_addr(&buf->vb.vb2_buf, p);
921 + plane_factor += node->pisp_format->plane_factor[p];
924 + for (; p < MAX_PLANES && node->pisp_format->plane_factor[p]; p++) {
926 + * Calculate the address offset of this plane as needed
927 + * by the hardware. This is specifically for non-mplane
928 + * buffer formats, where there are 3 image planes, e.g.
929 + * for the V4L2_PIX_FMT_YUV420 format.
931 + addr[p] = addr[0] + ((size * plane_factor) >> 3);
932 + plane_factor += node->pisp_format->plane_factor[p];
938 +static dma_addr_t get_addr(struct pispbe_buffer *buf)
941 + return vb2_dma_contig_plane_dma_addr(&buf->vb.vb2_buf, 0);
946 +fixup_addrs_enables(dma_addr_t addrs[N_HW_ADDRESSES],
947 + u32 hw_enables[N_HW_ENABLES],
948 + struct pisp_be_tiles_config *config,
949 + struct pispbe_buffer *buf[PISPBE_NUM_NODES],
950 + struct pispbe_node_group *node_group)
954 + /* Take a copy of the "enable" bitmaps so we can modify them. */
955 + hw_enables[0] = config->config.global.bayer_enables;
956 + hw_enables[1] = config->config.global.rgb_enables;
959 + * Main input first. There are 3 address pointers, corresponding to up
962 + ret = get_addr_3(addrs, buf[MAIN_INPUT_NODE],
963 + &node_group->node[MAIN_INPUT_NODE]);
966 + * This shouldn't happen; pispbe_schedule_internal should insist
969 + dev_warn(node_group->pispbe->dev,
970 + "ISP-BE missing input\n");
977 + * Now TDN/Stitch inputs and outputs. These are single-plane and only
978 + * used with Bayer input. Input enables must match the requirements
979 + * of the processing stages, otherwise the hardware can lock up!
981 + if (hw_enables[0] & PISP_BE_BAYER_ENABLE_INPUT) {
982 + addrs[3] = get_addr(buf[TDN_INPUT_NODE]);
983 + if (addrs[3] == 0 ||
984 + !(hw_enables[0] & PISP_BE_BAYER_ENABLE_TDN_INPUT) ||
985 + !(hw_enables[0] & PISP_BE_BAYER_ENABLE_TDN) ||
986 + (config->config.tdn.reset & 1)) {
987 + hw_enables[0] &= ~(PISP_BE_BAYER_ENABLE_TDN_INPUT |
988 + PISP_BE_BAYER_ENABLE_TDN_DECOMPRESS);
989 + if (!(config->config.tdn.reset & 1))
990 + hw_enables[0] &= ~PISP_BE_BAYER_ENABLE_TDN;
993 + addrs[4] = get_addr(buf[STITCH_INPUT_NODE]);
994 + if (addrs[4] == 0 ||
995 + !(hw_enables[0] & PISP_BE_BAYER_ENABLE_STITCH_INPUT) ||
996 + !(hw_enables[0] & PISP_BE_BAYER_ENABLE_STITCH)) {
998 + ~(PISP_BE_BAYER_ENABLE_STITCH_INPUT |
999 + PISP_BE_BAYER_ENABLE_STITCH_DECOMPRESS |
1000 + PISP_BE_BAYER_ENABLE_STITCH);
1003 + addrs[5] = get_addr(buf[TDN_OUTPUT_NODE]);
1004 + if (addrs[5] == 0)
1005 + hw_enables[0] &= ~(PISP_BE_BAYER_ENABLE_TDN_COMPRESS |
1006 + PISP_BE_BAYER_ENABLE_TDN_OUTPUT);
1008 + addrs[6] = get_addr(buf[STITCH_OUTPUT_NODE]);
1009 + if (addrs[6] == 0)
1011 + ~(PISP_BE_BAYER_ENABLE_STITCH_COMPRESS |
1012 + PISP_BE_BAYER_ENABLE_STITCH_OUTPUT);
1014 + /* No Bayer input? Disable entire Bayer pipe (else lockup) */
1015 + hw_enables[0] = 0;
1018 + /* Main image output channels. */
1019 + for (i = 0; i < PISP_BACK_END_NUM_OUTPUTS; i++) {
1020 + ret = get_addr_3(addrs + 7 + 3 * i, buf[OUTPUT0_NODE + i],
1021 + &node_group->node[OUTPUT0_NODE + i]);
1023 + hw_enables[1] &= ~(PISP_BE_RGB_ENABLE_OUTPUT0 << i);
1026 + /* HoG output (always single plane). */
1027 + addrs[13] = get_addr(buf[HOG_OUTPUT_NODE]);
1028 + if (addrs[13] == 0)
1029 + hw_enables[1] &= ~PISP_BE_RGB_ENABLE_HOG;
1033 + * Internal function. Called from pispbe_schedule_one/all. Returns non-zero if
1034 + * we started a job.
1036 + * Warning: needs to be called with hw_lock taken, and releases it if it
1037 + * schedules a job.
1039 +static int pispbe_schedule_internal(struct pispbe_node_group *node_group,
1040 + unsigned long flags)
1042 + struct pisp_be_tiles_config *config_tiles_buffer;
1043 + struct pispbe_dev *pispbe = node_group->pispbe;
1044 + struct pispbe_buffer *buf[PISPBE_NUM_NODES];
1045 + dma_addr_t hw_dma_addrs[N_HW_ADDRESSES];
1047 + u32 hw_enables[N_HW_ENABLES];
1048 + struct pispbe_node *node;
1049 + unsigned long flags1;
1050 + unsigned int config_index;
1054 + * To schedule a job, we need all streaming nodes (apart from Output0,
1055 + * Output1, Tdn and Stitch) to have a buffer ready, which must
1056 + * include at least a config buffer and a main input image.
1058 + * For Output0, Output1, Tdn and Stitch, a buffer only needs to be
1059 + * available if the blocks are enabled in the config.
1061 + * (Note that streaming_map is protected by hw_lock, which is held.)
1063 + if (((BIT(CONFIG_NODE) | BIT(MAIN_INPUT_NODE)) &
1064 + node_group->streaming_map) !=
1065 + (BIT(CONFIG_NODE) | BIT(MAIN_INPUT_NODE))) {
1066 + dev_dbg(pispbe->dev, "Nothing to do\n");
1070 + node = &node_group->node[CONFIG_NODE];
1071 + spin_lock_irqsave(&node->ready_lock, flags1);
1072 + buf[CONFIG_NODE] =
1073 + list_first_entry_or_null(&node->ready_queue, struct pispbe_buffer,
1075 + spin_unlock_irqrestore(&node->ready_lock, flags1);
1077 + /* Exit early if no config buffer has been queued. */
1078 + if (!buf[CONFIG_NODE])
1081 + config_index = buf[CONFIG_NODE]->vb.vb2_buf.index;
1082 + config_tiles_buffer = &node_group->config[config_index];
1083 + tiles = (dma_addr_t)node_group->config_dma_addr +
1084 + config_index * sizeof(struct pisp_be_tiles_config) +
1085 + offsetof(struct pisp_be_tiles_config, tiles);
1087 + /* remember: srcimages, captures then metadata */
1088 + for (i = 0; i < PISPBE_NUM_NODES; i++) {
1089 + unsigned int bayer_en =
1090 + config_tiles_buffer->config.global.bayer_enables;
1091 + unsigned int rgb_en =
1092 + config_tiles_buffer->config.global.rgb_enables;
1093 + bool ignore_buffers = false;
1095 + /* Config node is handled outside the loop above. */
1096 + if (i == CONFIG_NODE)
1100 + if (!(node_group->streaming_map & BIT(i)))
1103 + if ((!(rgb_en & PISP_BE_RGB_ENABLE_OUTPUT0) &&
1104 + i == OUTPUT0_NODE) ||
1105 + (!(rgb_en & PISP_BE_RGB_ENABLE_OUTPUT1) &&
1106 + i == OUTPUT1_NODE) ||
1107 + (!(bayer_en & PISP_BE_BAYER_ENABLE_TDN_INPUT) &&
1108 + i == TDN_INPUT_NODE) ||
1109 + (!(bayer_en & PISP_BE_BAYER_ENABLE_TDN_OUTPUT) &&
1110 + i == TDN_OUTPUT_NODE) ||
1111 + (!(bayer_en & PISP_BE_BAYER_ENABLE_STITCH_INPUT) &&
1112 + i == STITCH_INPUT_NODE) ||
1113 + (!(bayer_en & PISP_BE_BAYER_ENABLE_STITCH_OUTPUT) &&
1114 + i == STITCH_OUTPUT_NODE)) {
1116 + * Ignore Output0/Output1/Tdn/Stitch buffer check if the
1117 + * global enables aren't set for these blocks. If a
1118 + * buffer has been provided, we dequeue it back to the
1119 + * user with the other in-use buffers.
1122 + ignore_buffers = true;
1125 + node = &node_group->node[i];
1127 + spin_lock_irqsave(&node->ready_lock, flags1);
1128 + buf[i] = list_first_entry_or_null(&node->ready_queue,
1129 + struct pispbe_buffer,
1131 + spin_unlock_irqrestore(&node->ready_lock, flags1);
1132 + if (!buf[i] && !ignore_buffers) {
1133 + dev_dbg(pispbe->dev, "Nothing to do\n");
1138 + /* Pull a buffer from each V4L2 queue to form the queued job */
1139 + for (i = 0; i < PISPBE_NUM_NODES; i++) {
1141 + node = &node_group->node[i];
1143 + spin_lock_irqsave(&node->ready_lock, flags1);
1144 + list_del(&buf[i]->ready_list);
1145 + spin_unlock_irqrestore(&node->ready_lock,
1148 + pispbe->queued_job.buf[i] = buf[i];
1151 + pispbe->queued_job.node_group = node_group;
1152 + pispbe->hw_busy = 1;
1153 + spin_unlock_irqrestore(&pispbe->hw_lock, flags);
1156 + * We can kick the job off without the hw_lock, as this can
1157 + * never run again until hw_busy is cleared, which will happen
1158 + * only when the following job has been queued.
1160 + dev_dbg(pispbe->dev, "Have buffers - starting hardware\n");
1162 + /* Convert buffers to DMA addresses for the hardware */
1163 + fixup_addrs_enables(hw_dma_addrs, hw_enables,
1164 + config_tiles_buffer, buf, node_group);
1166 + * This could be a spot to fill in the
1167 + * buf[i]->vb.vb2_buf.planes[j].bytesused fields?
1169 + i = config_tiles_buffer->num_tiles;
1170 + if (i <= 0 || i > PISP_BACK_END_NUM_TILES ||
1171 + !((hw_enables[0] | hw_enables[1]) &
1172 + PISP_BE_BAYER_ENABLE_INPUT)) {
1174 + * Bad job. We can't let it proceed as it could lock up
1175 + * the hardware, or worse!
1177 + * XXX How to deal with this most cleanly? For now, just
1178 + * force num_tiles to 0, which causes the H/W to do
1179 + * something bizarre but survivable. It increments
1180 + * (started,done) counters by more than 1, but we seem
1183 + dev_err(pispbe->dev, "PROBLEM: Bad job");
1186 + hw_queue_job(pispbe, hw_dma_addrs, hw_enables,
1187 + &config_tiles_buffer->config, tiles, i);
1192 +/* Try and schedule a job for just a single node group. */
1193 +static void pispbe_schedule_one(struct pispbe_node_group *node_group)
1195 + struct pispbe_dev *pispbe = node_group->pispbe;
1196 + unsigned long flags;
1199 + spin_lock_irqsave(&pispbe->hw_lock, flags);
1200 + if (pispbe->hw_busy) {
1201 + spin_unlock_irqrestore(&pispbe->hw_lock, flags);
1205 + /* A non-zero return means the lock was released. */
1206 + ret = pispbe_schedule_internal(node_group, flags);
1208 + spin_unlock_irqrestore(&pispbe->hw_lock, flags);
1211 +/* Try and schedule a job for any of the node groups. */
1212 +static void pispbe_schedule_any(struct pispbe_dev *pispbe, int clear_hw_busy)
1214 + unsigned long flags;
1216 + spin_lock_irqsave(&pispbe->hw_lock, flags);
1218 + if (clear_hw_busy)
1219 + pispbe->hw_busy = 0;
1220 + if (pispbe->hw_busy == 0) {
1223 + for (i = 0; i < PISPBE_NUM_NODE_GROUPS; i++) {
1225 + * A non-zero return from pispbe_schedule_internal means
1226 + * the lock was released.
1228 + if (pispbe_schedule_internal(&pispbe->node_group[i],
1233 + spin_unlock_irqrestore(&pispbe->hw_lock, flags);
1236 +static void pispbe_isr_jobdone(struct pispbe_dev *pispbe,
1237 + struct pispbe_job *job)
1239 + struct pispbe_buffer **buf = job->buf;
1240 + u64 ts = ktime_get_ns();
1243 + for (i = 0; i < PISPBE_NUM_NODES; i++) {
1245 + buf[i]->vb.vb2_buf.timestamp = ts;
1246 + vb2_buffer_done(&buf[i]->vb.vb2_buf,
1247 + VB2_BUF_STATE_DONE);
1252 +static irqreturn_t pispbe_isr(int irq, void *dev)
1254 + struct pispbe_dev *pispbe = (struct pispbe_dev *)dev;
1256 + int can_queue_another = 0;
1259 + u = read_reg(pispbe, PISP_BE_INTERRUPT_STATUS_OFFSET);
1263 + write_reg(pispbe, PISP_BE_INTERRUPT_STATUS_OFFSET, u);
1264 + dev_dbg(pispbe->dev, "Hardware interrupt\n");
1265 + u = read_reg(pispbe, PISP_BE_BATCH_STATUS_OFFSET);
1266 + done = (uint8_t)u;
1267 + started = (uint8_t)(u >> 8);
1268 + dev_dbg(pispbe->dev,
1269 + "H/W started %d done %d, previously started %d done %d\n",
1270 + (int)started, (int)done, (int)pispbe->started,
1271 + (int)pispbe->done);
1274 + * Be aware that done can go up by 2 and started by 1 when: a job that
1275 + * we previously saw "start" now finishes, and we then queued a new job
1276 + * which we see both start and finish "simultaneously".
1278 + if (pispbe->running_job.node_group && pispbe->done != done) {
1279 + pispbe_isr_jobdone(pispbe, &pispbe->running_job);
1280 + memset(&pispbe->running_job, 0, sizeof(pispbe->running_job));
1282 + dev_dbg(pispbe->dev, "Job done (1)\n");
1285 + if (pispbe->started != started) {
1286 + pispbe->started++;
1287 + can_queue_another = 1;
1288 + dev_dbg(pispbe->dev, "Job started\n");
1290 + if (pispbe->done != done && pispbe->queued_job.node_group) {
1291 + pispbe_isr_jobdone(pispbe, &pispbe->queued_job);
1293 + dev_dbg(pispbe->dev, "Job done (2)\n");
1295 + pispbe->running_job = pispbe->queued_job;
1298 + memset(&pispbe->queued_job, 0, sizeof(pispbe->queued_job));
1301 + if (pispbe->done != done || pispbe->started != started) {
1302 + dev_err(pispbe->dev, "PROBLEM: counters not matching!\n");
1303 + pispbe->started = started;
1304 + pispbe->done = done;
1307 + /* check if there's more to do before going to sleep */
1308 + pispbe_schedule_any(pispbe, can_queue_another);
1310 + return IRQ_HANDLED;
1313 +static int pisp_be_validate_config(struct pispbe_node_group *node_group,
1314 + struct pisp_be_tiles_config *config)
1316 + u32 bayer_enables = config->config.global.bayer_enables;
1317 + u32 rgb_enables = config->config.global.rgb_enables;
1318 + struct device *dev = node_group->pispbe->dev;
1319 + struct v4l2_format *fmt;
1320 + unsigned int bpl, size, i, j;
1322 + if (!(bayer_enables & PISP_BE_BAYER_ENABLE_INPUT) ==
1323 + !(rgb_enables & PISP_BE_RGB_ENABLE_INPUT)) {
1324 + dev_err(dev, "%s: Not one input enabled\n", __func__);
1328 + /* Ensure output config strides and buffer sizes match the V4L2 formats. */
1329 + fmt = &node_group->node[TDN_OUTPUT_NODE].format;
1330 + if (bayer_enables & PISP_BE_BAYER_ENABLE_TDN_OUTPUT) {
1331 + bpl = config->config.tdn_output_format.stride;
1332 + size = bpl * config->config.tdn_output_format.height;
1333 + if (fmt->fmt.pix_mp.plane_fmt[0].bytesperline < bpl) {
1334 + dev_err(dev, "%s: bpl mismatch on tdn_output\n",
1338 + if (fmt->fmt.pix_mp.plane_fmt[0].sizeimage < size) {
1339 + dev_err(dev, "%s: size mismatch on tdn_output\n",
1345 + fmt = &node_group->node[STITCH_OUTPUT_NODE].format;
1346 + if (bayer_enables & PISP_BE_BAYER_ENABLE_STITCH_OUTPUT) {
1347 + bpl = config->config.stitch_output_format.stride;
1348 + size = bpl * config->config.stitch_output_format.height;
1349 + if (fmt->fmt.pix_mp.plane_fmt[0].bytesperline < bpl) {
1350 + dev_err(dev, "%s: bpl mismatch on stitch_output\n",
1354 + if (fmt->fmt.pix_mp.plane_fmt[0].sizeimage < size) {
1355 + dev_err(dev, "%s: size mismatch on stitch_output\n",
1361 + for (j = 0; j < PISP_BACK_END_NUM_OUTPUTS; j++) {
1362 + if (!(rgb_enables & PISP_BE_RGB_ENABLE_OUTPUT(j)))
1364 + if (config->config.output_format[j].image.format &
1365 + PISP_IMAGE_FORMAT_WALLPAPER_ROLL)
1366 + continue; /* TODO: Size checks for wallpaper formats */
1368 + fmt = &node_group->node[OUTPUT0_NODE + j].format;
1369 + for (i = 0; i < fmt->fmt.pix_mp.num_planes; i++) {
1370 + bpl = !i ? config->config.output_format[j].image.stride
1371 + : config->config.output_format[j].image.stride2;
1372 + size = bpl * config->config.output_format[j].image.height;
1374 + if (config->config.output_format[j].image.format &
1375 + PISP_IMAGE_FORMAT_SAMPLING_420)
1377 + if (fmt->fmt.pix_mp.plane_fmt[i].bytesperline < bpl) {
1378 + dev_err(dev, "%s: bpl mismatch on output %d\n",
1382 + if (fmt->fmt.pix_mp.plane_fmt[i].sizeimage < size) {
1383 + dev_err(dev, "%s: size mismatch on output\n",
1393 +static int pispbe_node_queue_setup(struct vb2_queue *q, unsigned int *nbuffers,
1394 + unsigned int *nplanes, unsigned int sizes[],
1395 + struct device *alloc_devs[])
1397 + struct pispbe_node *node = vb2_get_drv_priv(q);
1398 + struct pispbe_dev *pispbe = node->node_group->pispbe;
1401 + if (NODE_IS_MPLANE(node)) {
1404 + *nplanes = node->format.fmt.pix_mp.num_planes;
1405 + for (i = 0; i < *nplanes; i++) {
1406 + unsigned int size =
1407 + node->format.fmt.pix_mp.plane_fmt[i].sizeimage;
1408 + if (sizes[i] && sizes[i] < size) {
1409 + dev_err(pispbe->dev, "%s: size %u < %u\n",
1410 + __func__, sizes[i], size);
1415 + } else if (NODE_IS_META(node)) {
1416 + sizes[0] = node->format.fmt.meta.buffersize;
1418 + * Limit the config node buffer count to the number of internal
1419 + * buffers allocated.
1421 + if (node->id == CONFIG_NODE)
1422 + *nbuffers = min_t(unsigned int, *nbuffers,
1423 + PISP_BE_NUM_CONFIG_BUFFERS);
1426 + dev_dbg(pispbe->dev,
1427 + "Image (or metadata) size %u, nbuffers %u for node %s\n",
1428 + sizes[0], *nbuffers, NODE_NAME(node));
1433 +static int pispbe_node_buffer_prepare(struct vb2_buffer *vb)
1435 + struct pispbe_node *node = vb2_get_drv_priv(vb->vb2_queue);
1436 + struct pispbe_dev *pispbe = node->node_group->pispbe;
1437 + unsigned long size = 0;
1438 + unsigned int num_planes = NODE_IS_MPLANE(node) ?
1439 + node->format.fmt.pix_mp.num_planes : 1;
1442 + for (i = 0; i < num_planes; i++) {
1443 + size = NODE_IS_MPLANE(node)
1444 + ? node->format.fmt.pix_mp.plane_fmt[i].sizeimage
1445 + : node->format.fmt.meta.buffersize;
1447 + if (vb2_plane_size(vb, i) < size) {
1448 + dev_err(pispbe->dev,
1449 + "data will not fit into plane %d (%lu < %lu)\n",
1450 + i, vb2_plane_size(vb, i), size);
1454 + vb2_set_plane_payload(vb, i, size);
1457 + if (node->id == CONFIG_NODE) {
1458 + void *dst = &node->node_group->config[vb->index];
1459 + void *src = vb2_plane_vaddr(vb, 0);
1461 + memcpy(dst, src, sizeof(struct pisp_be_tiles_config));
1462 + return pisp_be_validate_config(node->node_group, dst);
1468 +static void pispbe_node_buffer_queue(struct vb2_buffer *buf)
1470 + struct vb2_v4l2_buffer *vbuf =
1471 + container_of(buf, struct vb2_v4l2_buffer, vb2_buf);
1472 + struct pispbe_buffer *buffer =
1473 + container_of(vbuf, struct pispbe_buffer, vb);
1474 + struct pispbe_node *node = vb2_get_drv_priv(buf->vb2_queue);
1475 + struct pispbe_node_group *node_group = node->node_group;
1476 + struct pispbe_dev *pispbe = node->node_group->pispbe;
1477 + unsigned long flags;
1479 + dev_dbg(pispbe->dev, "%s: for node %s\n", __func__, NODE_NAME(node));
1480 + spin_lock_irqsave(&node->ready_lock, flags);
1481 + list_add_tail(&buffer->ready_list, &node->ready_queue);
1482 + spin_unlock_irqrestore(&node->ready_lock, flags);
1485 + * Every time we add a buffer, check if there's now some work for the hw
1486 + * to do, but only for this client.
1488 + pispbe_schedule_one(node_group);
1491 +static int pispbe_node_start_streaming(struct vb2_queue *q, unsigned int count)
1493 + unsigned long flags;
1494 + struct pispbe_node *node = vb2_get_drv_priv(q);
1495 + struct pispbe_node_group *node_group = node->node_group;
1496 + struct pispbe_dev *pispbe = node_group->pispbe;
1499 + ret = pm_runtime_resume_and_get(pispbe->dev);
1503 + spin_lock_irqsave(&pispbe->hw_lock, flags);
1504 + node->node_group->streaming_map |= BIT(node->id);
1505 + spin_unlock_irqrestore(&pispbe->hw_lock, flags);
1507 + dev_dbg(pispbe->dev, "%s: for node %s (count %u)\n",
1508 + __func__, NODE_NAME(node), count);
1509 + dev_dbg(pispbe->dev, "Nodes streaming for this group now 0x%x\n",
1510 + node->node_group->streaming_map);
1512 + /* Maybe we're ready to run. */
1513 + pispbe_schedule_one(node_group);
1518 +static void pispbe_node_stop_streaming(struct vb2_queue *q)
1520 + struct pispbe_node *node = vb2_get_drv_priv(q);
1521 + struct pispbe_node_group *node_group = node->node_group;
1522 + struct pispbe_dev *pispbe = node_group->pispbe;
1523 + struct pispbe_buffer *buf;
1524 + unsigned long flags;
1527 + * Now this is a bit awkward. In a simple M2M device we could just wait
1528 + * for all queued jobs to complete, but here there's a risk that a
1529 + * partial set of buffers was queued and cannot be run. For now, just
1530 + * cancel all buffers stuck in the "ready queue", then wait for any
1532 + * XXX This may return buffers out of order.
1534 + dev_dbg(pispbe->dev, "%s: for node %s\n", __func__, NODE_NAME(node));
1535 + spin_lock_irqsave(&pispbe->hw_lock, flags);
1537 + unsigned long flags1;
1539 + spin_lock_irqsave(&node->ready_lock, flags1);
1540 + buf = list_first_entry_or_null(&node->ready_queue,
1541 + struct pispbe_buffer,
1544 + list_del(&buf->ready_list);
1545 + vb2_buffer_done(&buf->vb.vb2_buf, VB2_BUF_STATE_ERROR);
1547 + spin_unlock_irqrestore(&node->ready_lock, flags1);
1549 + spin_unlock_irqrestore(&pispbe->hw_lock, flags);
1551 + vb2_wait_for_all_buffers(&node->queue);
1553 + spin_lock_irqsave(&pispbe->hw_lock, flags);
1554 + node_group->streaming_map &= ~BIT(node->id);
1555 + spin_unlock_irqrestore(&pispbe->hw_lock, flags);
1557 + pm_runtime_mark_last_busy(pispbe->dev);
1558 + pm_runtime_put_autosuspend(pispbe->dev);
1560 + dev_dbg(pispbe->dev, "Nodes streaming for this group now 0x%x\n",
1561 + node_group->streaming_map);
1564 +static const struct vb2_ops pispbe_node_queue_ops = {
1565 + .queue_setup = pispbe_node_queue_setup,
1566 + .buf_prepare = pispbe_node_buffer_prepare,
1567 + .buf_queue = pispbe_node_buffer_queue,
1568 + .start_streaming = pispbe_node_start_streaming,
1569 + .stop_streaming = pispbe_node_stop_streaming,
1572 +static const struct v4l2_file_operations pispbe_fops = {
1573 + .owner = THIS_MODULE,
1574 + .open = v4l2_fh_open,
1575 + .release = vb2_fop_release,
1576 + .poll = vb2_fop_poll,
1577 + .unlocked_ioctl = video_ioctl2,
1578 + .mmap = vb2_fop_mmap
1581 +static int pispbe_node_querycap(struct file *file, void *priv,
1582 + struct v4l2_capability *cap)
1584 + struct pispbe_node *node = video_drvdata(file);
1585 + struct pispbe_dev *pispbe = node->node_group->pispbe;
1587 + strscpy(cap->driver, PISPBE_NAME, sizeof(cap->driver));
1588 + strscpy(cap->card, PISPBE_NAME, sizeof(cap->card));
1589 + snprintf(cap->bus_info, sizeof(cap->bus_info), "platform:%s",
1590 + dev_name(pispbe->dev));
1592 + cap->capabilities = V4L2_CAP_VIDEO_CAPTURE_MPLANE |
1593 + V4L2_CAP_VIDEO_OUTPUT_MPLANE |
1594 + V4L2_CAP_STREAMING | V4L2_CAP_DEVICE_CAPS |
1595 + V4L2_CAP_META_OUTPUT | V4L2_CAP_META_CAPTURE;
1596 + cap->device_caps = node->vfd.device_caps;
1598 + dev_dbg(pispbe->dev, "Caps for node %s: %x and %x (dev %x)\n",
1599 + NODE_NAME(node), cap->capabilities, cap->device_caps,
1600 + node->vfd.device_caps);
1604 +static int pispbe_node_g_fmt_vid_cap(struct file *file, void *priv,
1605 + struct v4l2_format *f)
1607 + struct pispbe_node *node = video_drvdata(file);
1608 + struct pispbe_dev *pispbe = node->node_group->pispbe;
1610 + if (!NODE_IS_CAPTURE(node) || NODE_IS_META(node)) {
1611 + dev_err(pispbe->dev,
1612 + "Cannot get capture fmt for output node %s\n",
1616 + *f = node->format;
1617 + dev_dbg(pispbe->dev, "Get capture format for node %s\n",
1622 +static int pispbe_node_g_fmt_vid_out(struct file *file, void *priv,
1623 + struct v4l2_format *f)
1625 + struct pispbe_node *node = video_drvdata(file);
1626 + struct pispbe_dev *pispbe = node->node_group->pispbe;
1628 + if (NODE_IS_CAPTURE(node) || NODE_IS_META(node)) {
1629 + dev_err(pispbe->dev,
1630 + "Cannot get capture fmt for output node %s\n",
1634 + *f = node->format;
1635 + dev_dbg(pispbe->dev, "Get output format for node %s\n",
1640 +static int pispbe_node_g_fmt_meta_out(struct file *file, void *priv,
1641 + struct v4l2_format *f)
1643 + struct pispbe_node *node = video_drvdata(file);
1644 + struct pispbe_dev *pispbe = node->node_group->pispbe;
1646 + if (!NODE_IS_META(node) || NODE_IS_CAPTURE(node)) {
1647 + dev_err(pispbe->dev,
1648 + "Cannot get capture fmt for meta output node %s\n",
1652 + *f = node->format;
1653 + dev_dbg(pispbe->dev, "Get output format for meta node %s\n",
1658 +static int pispbe_node_g_fmt_meta_cap(struct file *file, void *priv,
1659 + struct v4l2_format *f)
1661 + struct pispbe_node *node = video_drvdata(file);
1662 + struct pispbe_dev *pispbe = node->node_group->pispbe;
1664 + if (!NODE_IS_META(node) || NODE_IS_OUTPUT(node)) {
1665 + dev_err(pispbe->dev,
1666 + "Cannot get capture fmt for meta output node %s\n",
1670 + *f = node->format;
1671 + dev_dbg(pispbe->dev, "Get output format for meta node %s\n",
1676 +static int verify_be_pix_format(const struct v4l2_format *f,
1677 + struct pispbe_node *node)
1679 + struct pispbe_dev *pispbe = node->node_group->pispbe;
1680 + unsigned int nplanes = f->fmt.pix_mp.num_planes;
1683 + if (f->fmt.pix_mp.width == 0 || f->fmt.pix_mp.height == 0) {
1684 + dev_err(pispbe->dev, "Details incorrect for output node %s\n",
1689 + if (nplanes == 0 || nplanes > MAX_PLANES) {
1690 + dev_err(pispbe->dev,
1691 + "Bad number of planes for output node %s, req =%d\n",
1692 + NODE_NAME(node), nplanes);
1696 + for (i = 0; i < nplanes; i++) {
1697 + const struct v4l2_plane_pix_format *p;
1699 + p = &f->fmt.pix_mp.plane_fmt[i];
1700 + if (p->bytesperline == 0 || p->sizeimage == 0) {
1701 + dev_err(pispbe->dev,
1702 + "Invalid plane %d for output node %s\n",
1703 + i, NODE_NAME(node));
1711 +static const struct pisp_be_format *find_format(unsigned int fourcc)
1713 + const struct pisp_be_format *fmt;
1716 + for (i = 0; i < ARRAY_SIZE(supported_formats); i++) {
1717 + fmt = &supported_formats[i];
1718 + if (fmt->fourcc == fourcc)
1725 +static void set_plane_params(struct v4l2_format *f,
1726 + const struct pisp_be_format *fmt)
1728 + unsigned int nplanes = f->fmt.pix_mp.num_planes;
1729 + unsigned int total_plane_factor = 0;
1732 + for (i = 0; i < MAX_PLANES; i++)
1733 + total_plane_factor += fmt->plane_factor[i];
1735 + for (i = 0; i < nplanes; i++) {
1736 + struct v4l2_plane_pix_format *p = &f->fmt.pix_mp.plane_fmt[i];
1737 + unsigned int bpl, plane_size;
1739 + bpl = (f->fmt.pix_mp.width * fmt->bit_depth) >> 3;
1740 + bpl = ALIGN(max(p->bytesperline, bpl), fmt->align);
1742 + plane_size = bpl * f->fmt.pix_mp.height *
1743 + (nplanes > 1 ? fmt->plane_factor[i] : total_plane_factor);
1745 + * The shift is to divide out the plane_factor fixed point
1748 + plane_size = max(p->sizeimage, plane_size >> 3);
1750 + p->bytesperline = bpl;
1751 + p->sizeimage = plane_size;
1755 +static int try_format(struct v4l2_format *f, struct pispbe_node *node)
1757 + struct pispbe_dev *pispbe = node->node_group->pispbe;
1758 + const struct pisp_be_format *fmt;
1761 + u32 pixfmt = f->fmt.pix_mp.pixelformat;
1763 + dev_dbg(pispbe->dev,
1764 + "%s: [%s] req %ux%u " V4L2_FOURCC_CONV ", planes %d\n",
1765 + __func__, NODE_NAME(node), f->fmt.pix_mp.width,
1766 + f->fmt.pix_mp.height, V4L2_FOURCC_CONV_ARGS(pixfmt),
1767 + f->fmt.pix_mp.num_planes);
1769 + if (pixfmt == V4L2_PIX_FMT_RPI_BE)
1770 + return verify_be_pix_format(f, node);
1772 + fmt = find_format(pixfmt);
1774 + fmt = find_format(V4L2_PIX_FMT_YUV420M);
1776 + f->fmt.pix_mp.pixelformat = fmt->fourcc;
1777 + f->fmt.pix_mp.num_planes = fmt->num_planes;
1778 + f->fmt.pix_mp.field = V4L2_FIELD_NONE;
1779 + f->fmt.pix_mp.width = max(min(f->fmt.pix_mp.width, 65536u),
1780 + PISP_BACK_END_MIN_TILE_WIDTH);
1781 + f->fmt.pix_mp.height = max(min(f->fmt.pix_mp.height, 65536u),
1782 + PISP_BACK_END_MIN_TILE_HEIGHT);
1785 + * Fill in the actual colour space when the requested one was
1786 + * not supported. This also catches the case when the "default"
1787 + * colour space was requested (as that's never in the mask).
1789 + if (!(V4L2_COLORSPACE_MASK(f->fmt.pix_mp.colorspace) & fmt->colorspace_mask))
1790 + f->fmt.pix_mp.colorspace = fmt->colorspace_default;
1792 + /* In all cases, we only support the defaults for these: */
1793 + f->fmt.pix_mp.ycbcr_enc =
1794 + V4L2_MAP_YCBCR_ENC_DEFAULT(f->fmt.pix_mp.colorspace);
1795 + f->fmt.pix_mp.xfer_func =
1796 + V4L2_MAP_XFER_FUNC_DEFAULT(f->fmt.pix_mp.colorspace);
1798 + is_rgb = f->fmt.pix_mp.colorspace == V4L2_COLORSPACE_SRGB;
1799 + f->fmt.pix_mp.quantization =
1800 + V4L2_MAP_QUANTIZATION_DEFAULT(is_rgb, f->fmt.pix_mp.colorspace,
1801 + f->fmt.pix_mp.ycbcr_enc);
1803 + /* Set plane size and bytes/line for each plane. */
1804 + set_plane_params(f, fmt);
1806 + for (i = 0; i < f->fmt.pix_mp.num_planes; i++) {
1807 + dev_dbg(pispbe->dev,
1808 + "%s: [%s] calc plane %d, %ux%u, depth %u, bpl %u size %u\n",
1809 + __func__, NODE_NAME(node), i, f->fmt.pix_mp.width,
1810 + f->fmt.pix_mp.height, fmt->bit_depth,
1811 + f->fmt.pix_mp.plane_fmt[i].bytesperline,
1812 + f->fmt.pix_mp.plane_fmt[i].sizeimage);
1818 +static int pispbe_node_try_fmt_vid_cap(struct file *file, void *priv,
1819 + struct v4l2_format *f)
1821 + struct pispbe_node *node = video_drvdata(file);
1822 + struct pispbe_dev *pispbe = node->node_group->pispbe;
1825 + if (!NODE_IS_CAPTURE(node) || NODE_IS_META(node)) {
1826 + dev_err(pispbe->dev,
1827 + "Cannot set capture fmt for output node %s\n",
1832 + ret = try_format(f, node);
1839 +static int pispbe_node_try_fmt_vid_out(struct file *file, void *priv,
1840 + struct v4l2_format *f)
1842 + struct pispbe_node *node = video_drvdata(file);
1843 + struct pispbe_dev *pispbe = node->node_group->pispbe;
1846 + if (!NODE_IS_OUTPUT(node) || NODE_IS_META(node)) {
1847 + dev_err(pispbe->dev,
1848 + "Cannot set capture fmt for output node %s\n",
1853 + ret = try_format(f, node);
1860 +static int pispbe_node_try_fmt_meta_out(struct file *file, void *priv,
1861 + struct v4l2_format *f)
1863 + struct pispbe_node *node = video_drvdata(file);
1864 + struct pispbe_dev *pispbe = node->node_group->pispbe;
1866 + if (!NODE_IS_META(node) || NODE_IS_CAPTURE(node)) {
1867 + dev_err(pispbe->dev,
1868 + "Cannot set capture fmt for meta output node %s\n",
1873 + f->fmt.meta.dataformat = V4L2_META_FMT_RPI_BE_CFG;
1874 + f->fmt.meta.buffersize = sizeof(struct pisp_be_tiles_config);
1879 +static int pispbe_node_try_fmt_meta_cap(struct file *file, void *priv,
1880 + struct v4l2_format *f)
1882 + struct pispbe_node *node = video_drvdata(file);
1883 + struct pispbe_dev *pispbe = node->node_group->pispbe;
1885 + if (!NODE_IS_META(node) || NODE_IS_OUTPUT(node)) {
1886 + dev_err(pispbe->dev,
1887 + "Cannot set capture fmt for meta output node %s\n",
1892 + f->fmt.meta.dataformat = V4L2_PIX_FMT_RPI_BE;
1893 + if (!f->fmt.meta.buffersize)
1894 + f->fmt.meta.buffersize = BIT(20);
1899 +static int pispbe_node_s_fmt_vid_cap(struct file *file, void *priv,
1900 + struct v4l2_format *f)
1902 + struct pispbe_node *node = video_drvdata(file);
1903 + struct pispbe_dev *pispbe = node->node_group->pispbe;
1904 + int ret = pispbe_node_try_fmt_vid_cap(file, priv, f);
1909 + node->format = *f;
1910 + node->pisp_format = find_format(f->fmt.pix_mp.pixelformat);
1912 + dev_dbg(pispbe->dev,
1913 + "Set capture format for node %s to " V4L2_FOURCC_CONV "\n",
1915 + V4L2_FOURCC_CONV_ARGS(f->fmt.pix_mp.pixelformat));
1919 +static int pispbe_node_s_fmt_vid_out(struct file *file, void *priv,
1920 + struct v4l2_format *f)
1922 + struct pispbe_node *node = video_drvdata(file);
1923 + struct pispbe_dev *pispbe = node->node_group->pispbe;
1924 + int ret = pispbe_node_try_fmt_vid_out(file, priv, f);
1929 + node->format = *f;
1930 + node->pisp_format = find_format(f->fmt.pix_mp.pixelformat);
1932 + dev_dbg(pispbe->dev,
1933 + "Set output format for node %s to " V4L2_FOURCC_CONV "\n",
1935 + V4L2_FOURCC_CONV_ARGS(f->fmt.pix_mp.pixelformat));
1939 +static int pispbe_node_s_fmt_meta_out(struct file *file, void *priv,
1940 + struct v4l2_format *f)
1942 + struct pispbe_node *node = video_drvdata(file);
1943 + struct pispbe_dev *pispbe = node->node_group->pispbe;
1944 + int ret = pispbe_node_try_fmt_meta_out(file, priv, f);
1949 + node->format = *f;
1950 + node->pisp_format = &meta_out_supported_formats[0];
1952 + dev_dbg(pispbe->dev,
1953 + "Set output format for meta node %s to " V4L2_FOURCC_CONV "\n",
1955 + V4L2_FOURCC_CONV_ARGS(f->fmt.meta.dataformat));
1959 +static int pispbe_node_s_fmt_meta_cap(struct file *file, void *priv,
1960 + struct v4l2_format *f)
1962 + struct pispbe_node *node = video_drvdata(file);
1963 + struct pispbe_dev *pispbe = node->node_group->pispbe;
1964 + int ret = pispbe_node_try_fmt_meta_cap(file, priv, f);
1969 + node->format = *f;
1970 + node->pisp_format = find_format(f->fmt.meta.dataformat);
1972 + dev_dbg(pispbe->dev,
1973 + "Set capture format for meta node %s to " V4L2_FOURCC_CONV "\n",
1975 + V4L2_FOURCC_CONV_ARGS(f->fmt.meta.dataformat));
1979 +static int pispbe_node_enum_fmt(struct file *file, void *priv,
1980 + struct v4l2_fmtdesc *f)
1982 + struct pispbe_node *node = video_drvdata(file);
1984 + if (f->type != node->queue.type)
1987 + if (NODE_IS_META(node)) {
1991 + if (NODE_IS_OUTPUT(node))
1992 + f->pixelformat = V4L2_META_FMT_RPI_BE_CFG;
1994 + f->pixelformat = V4L2_PIX_FMT_RPI_BE;
1999 + if (f->index >= ARRAY_SIZE(supported_formats))
2002 + f->pixelformat = supported_formats[f->index].fourcc;
2008 +static int pispbe_enum_framesizes(struct file *file, void *priv,
2009 + struct v4l2_frmsizeenum *fsize)
2011 + struct pispbe_node *node = video_drvdata(file);
2012 + struct pispbe_dev *pispbe = node->node_group->pispbe;
2014 + if (NODE_IS_META(node) || fsize->index)
2017 + if (!find_format(fsize->pixel_format)) {
2018 + dev_err(pispbe->dev, "Invalid pixel code: %x\n",
2019 + fsize->pixel_format);
2023 + fsize->type = V4L2_FRMSIZE_TYPE_STEPWISE;
2024 + fsize->stepwise.min_width = 32;
2025 + fsize->stepwise.max_width = 65535;
2026 + fsize->stepwise.step_width = 2;
2028 + fsize->stepwise.min_height = 32;
2029 + fsize->stepwise.max_height = 65535;
2030 + fsize->stepwise.step_height = 2;
2035 +static int pispbe_node_streamon(struct file *file, void *priv,
2036 + enum v4l2_buf_type type)
2038 + struct pispbe_node *node = video_drvdata(file);
2039 + struct pispbe_dev *pispbe = node->node_group->pispbe;
2041 + /* Do we need a node->stream_lock mutex? */
2043 + dev_dbg(pispbe->dev, "Stream on for node %s\n", NODE_NAME(node));
2045 + /* Do we care about the type? Each node has only one queue. */
2047 + INIT_LIST_HEAD(&node->ready_queue);
2049 + /* locking should be handled by the queue->lock? */
2050 + return vb2_streamon(&node->queue, type);
2053 +static int pispbe_node_streamoff(struct file *file, void *priv,
2054 + enum v4l2_buf_type type)
2056 + struct pispbe_node *node = video_drvdata(file);
2058 + return vb2_streamoff(&node->queue, type);
2061 +static const struct v4l2_ioctl_ops pispbe_node_ioctl_ops = {
2062 + .vidioc_querycap = pispbe_node_querycap,
2063 + .vidioc_g_fmt_vid_cap_mplane = pispbe_node_g_fmt_vid_cap,
2064 + .vidioc_g_fmt_vid_out_mplane = pispbe_node_g_fmt_vid_out,
2065 + .vidioc_g_fmt_meta_out = pispbe_node_g_fmt_meta_out,
2066 + .vidioc_g_fmt_meta_cap = pispbe_node_g_fmt_meta_cap,
2067 + .vidioc_try_fmt_vid_cap_mplane = pispbe_node_try_fmt_vid_cap,
2068 + .vidioc_try_fmt_vid_out_mplane = pispbe_node_try_fmt_vid_out,
2069 + .vidioc_try_fmt_meta_out = pispbe_node_try_fmt_meta_out,
2070 + .vidioc_try_fmt_meta_cap = pispbe_node_try_fmt_meta_cap,
2071 + .vidioc_s_fmt_vid_cap_mplane = pispbe_node_s_fmt_vid_cap,
2072 + .vidioc_s_fmt_vid_out_mplane = pispbe_node_s_fmt_vid_out,
2073 + .vidioc_s_fmt_meta_out = pispbe_node_s_fmt_meta_out,
2074 + .vidioc_s_fmt_meta_cap = pispbe_node_s_fmt_meta_cap,
2075 + .vidioc_enum_fmt_vid_cap = pispbe_node_enum_fmt,
2076 + .vidioc_enum_fmt_vid_out = pispbe_node_enum_fmt,
2077 + .vidioc_enum_fmt_meta_cap = pispbe_node_enum_fmt,
2078 + .vidioc_enum_fmt_meta_out = pispbe_node_enum_fmt,
2079 + .vidioc_enum_framesizes = pispbe_enum_framesizes,
2080 + .vidioc_create_bufs = vb2_ioctl_create_bufs,
2081 + .vidioc_prepare_buf = vb2_ioctl_prepare_buf,
2082 + .vidioc_querybuf = vb2_ioctl_querybuf,
2083 + .vidioc_qbuf = vb2_ioctl_qbuf,
2084 + .vidioc_dqbuf = vb2_ioctl_dqbuf,
2085 + .vidioc_expbuf = vb2_ioctl_expbuf,
2086 + .vidioc_reqbufs = vb2_ioctl_reqbufs,
2087 + .vidioc_streamon = pispbe_node_streamon,
2088 + .vidioc_streamoff = pispbe_node_streamoff,
2091 +static const struct video_device pispbe_videodev = {
2092 + .name = PISPBE_NAME,
2093 + .vfl_dir = VFL_DIR_M2M, /* gets overwritten */
2094 + .fops = &pispbe_fops,
2095 + .ioctl_ops = &pispbe_node_ioctl_ops,
2097 + .release = video_device_release_empty,
2100 +static void node_set_default_format(struct pispbe_node *node)
2102 + if (NODE_IS_META(node) && NODE_IS_OUTPUT(node)) {
2104 + struct v4l2_format *f = &node->format;
2106 + f->fmt.meta.dataformat = V4L2_META_FMT_RPI_BE_CFG;
2107 + f->fmt.meta.buffersize = sizeof(struct pisp_be_tiles_config);
2108 + f->type = node->buf_type;
2109 + } else if (NODE_IS_META(node) && NODE_IS_CAPTURE(node)) {
2110 + /* HOG output node */
2111 + struct v4l2_format *f = &node->format;
2113 + f->fmt.meta.dataformat = V4L2_PIX_FMT_RPI_BE;
2114 + f->fmt.meta.buffersize = BIT(20);
2115 + f->type = node->buf_type;
2117 + struct v4l2_format f = {0};
2119 + f.fmt.pix_mp.pixelformat = V4L2_PIX_FMT_YUV420M;
2120 + f.fmt.pix_mp.width = 1920;
2121 + f.fmt.pix_mp.height = 1080;
2122 + f.type = node->buf_type;
2123 + try_format(&f, node);
2127 + node->pisp_format = find_format(node->format.fmt.pix_mp.pixelformat);
2131 + * Initialise a struct pispbe_node and register it as /dev/video<N>
2132 + * to represent one of the PiSP Back End's input or output streams.
2135 +pispbe_init_node(struct pispbe_node_group *node_group, unsigned int id)
2137 + bool output = NODE_DESC_IS_OUTPUT(&node_desc[id]);
2138 + struct pispbe_node *node = &node_group->node[id];
2139 + struct pispbe_dev *pispbe = node_group->pispbe;
2140 + struct media_entity *entity = &node->vfd.entity;
2141 + struct video_device *vdev = &node->vfd;
2142 + struct vb2_queue *q = &node->queue;
2146 + node->node_group = node_group;
2147 + node->buf_type = node_desc[id].buf_type;
2149 + mutex_init(&node->node_lock);
2150 + mutex_init(&node->queue_lock);
2151 + INIT_LIST_HEAD(&node->ready_queue);
2152 + spin_lock_init(&node->ready_lock);
2154 + node->format.type = node->buf_type;
2155 + node_set_default_format(node);
2157 + q->type = node->buf_type;
2158 + q->io_modes = VB2_MMAP | VB2_DMABUF;
2159 + q->mem_ops = &vb2_dma_contig_memops;
2160 + q->drv_priv = node;
2161 + q->ops = &pispbe_node_queue_ops;
2162 + q->buf_struct_size = sizeof(struct pispbe_buffer);
2163 + q->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
2164 + q->dev = node->node_group->pispbe->dev;
2165 + /* get V4L2 to handle node->queue locking */
2166 + q->lock = &node->queue_lock;
2168 + ret = vb2_queue_init(q);
2170 + dev_err(pispbe->dev, "vb2_queue_init failed\n");
2174 + *vdev = pispbe_videodev; /* default initialization */
2175 + strscpy(vdev->name, node_desc[id].ent_name, sizeof(vdev->name));
2176 + vdev->v4l2_dev = &node_group->v4l2_dev;
2177 + vdev->vfl_dir = output ? VFL_DIR_TX : VFL_DIR_RX;
2178 + /* get V4L2 to serialise our ioctls */
2179 + vdev->lock = &node->node_lock;
2180 + vdev->queue = &node->queue;
2181 + vdev->device_caps = V4L2_CAP_STREAMING | node_desc[id].caps;
2183 + node->pad.flags = output ? MEDIA_PAD_FL_SOURCE : MEDIA_PAD_FL_SINK;
2184 + ret = media_entity_pads_init(entity, 1, &node->pad);
2186 + dev_err(pispbe->dev,
2187 + "Failed to register media pads for %s device node\n",
2189 + goto err_unregister_queue;
2192 + ret = video_register_device(vdev, VFL_TYPE_VIDEO,
2193 + PISPBE_VIDEO_NODE_OFFSET);
2195 + dev_err(pispbe->dev,
2196 + "Failed to register video %s device node\n",
2198 + goto err_unregister_queue;
2200 + video_set_drvdata(vdev, node);
2203 + ret = media_create_pad_link(entity, 0, &node_group->sd.entity,
2204 + id, MEDIA_LNK_FL_IMMUTABLE |
2205 + MEDIA_LNK_FL_ENABLED);
2207 + ret = media_create_pad_link(&node_group->sd.entity, id, entity,
2208 + 0, MEDIA_LNK_FL_IMMUTABLE |
2209 + MEDIA_LNK_FL_ENABLED);
2211 + goto err_unregister_video_dev;
2213 + dev_info(pispbe->dev,
2214 + "%s device node registered as /dev/video%d\n",
2215 + NODE_NAME(node), node->vfd.num);
2218 +err_unregister_video_dev:
2219 + video_unregister_device(&node->vfd);
2220 +err_unregister_queue:
2221 + vb2_queue_release(&node->queue);
2225 +static const struct v4l2_subdev_pad_ops pispbe_pad_ops = {
2226 + .link_validate = v4l2_subdev_link_validate_default,
2229 +static const struct v4l2_subdev_ops pispbe_sd_ops = {
2230 + .pad = &pispbe_pad_ops,
2233 +static int pispbe_init_subdev(struct pispbe_node_group *node_group)
2235 + struct pispbe_dev *pispbe = node_group->pispbe;
2236 + struct v4l2_subdev *sd = &node_group->sd;
2240 + v4l2_subdev_init(sd, &pispbe_sd_ops);
2241 + sd->entity.function = MEDIA_ENT_F_PROC_VIDEO_PIXEL_FORMATTER;
2242 + sd->owner = THIS_MODULE;
2243 + sd->dev = pispbe->dev;
2244 + strscpy(sd->name, PISPBE_NAME, sizeof(sd->name));
2246 + for (i = 0; i < PISPBE_NUM_NODES; i++)
2247 + node_group->pad[i].flags =
2248 + NODE_DESC_IS_OUTPUT(&node_desc[i]) ?
2249 + MEDIA_PAD_FL_SINK : MEDIA_PAD_FL_SOURCE;
2251 + ret = media_entity_pads_init(&sd->entity, PISPBE_NUM_NODES,
2256 + ret = v4l2_device_register_subdev(&node_group->v4l2_dev, sd);
2263 + media_entity_cleanup(&sd->entity);
2267 +static int pispbe_init_group(struct pispbe_dev *pispbe, unsigned int id)
2269 + struct pispbe_node_group *node_group = &pispbe->node_group[id];
2270 + struct v4l2_device *v4l2_dev;
2271 + struct media_device *mdev;
2272 + unsigned int num_registered = 0;
2275 + node_group->id = id;
2276 + node_group->pispbe = pispbe;
2277 + node_group->streaming_map = 0;
2279 + dev_info(pispbe->dev, "Register nodes for group %u\n", id);
2281 + /* Register v4l2_device and media_device */
2282 + mdev = &node_group->mdev;
2283 + mdev->hw_revision = node_group->pispbe->hw_version;
2284 + mdev->dev = node_group->pispbe->dev;
2285 + strscpy(mdev->model, PISPBE_NAME, sizeof(mdev->model));
2286 + snprintf(mdev->bus_info, sizeof(mdev->bus_info),
2287 + "platform:%s", dev_name(node_group->pispbe->dev));
2288 + media_device_init(mdev);
2290 + v4l2_dev = &node_group->v4l2_dev;
2291 + v4l2_dev->mdev = &node_group->mdev;
2292 + strscpy(v4l2_dev->name, PISPBE_NAME, sizeof(v4l2_dev->name));
2294 + ret = v4l2_device_register(pispbe->dev, &node_group->v4l2_dev);
2296 + goto err_media_dev_cleanup;
2298 + /* Register the PISPBE subdevice. */
2299 + ret = pispbe_init_subdev(node_group);
2301 + goto err_unregister_v4l2;
2303 + /* Create device video nodes */
2304 + for (; num_registered < PISPBE_NUM_NODES; num_registered++) {
2305 + ret = pispbe_init_node(node_group, num_registered);
2307 + goto err_unregister_nodes;
2310 + ret = media_device_register(mdev);
2312 + goto err_unregister_nodes;
2314 + node_group->config =
2315 + dma_alloc_coherent(pispbe->dev,
2316 + sizeof(struct pisp_be_tiles_config) *
2317 + PISP_BE_NUM_CONFIG_BUFFERS,
2318 + &node_group->config_dma_addr, GFP_KERNEL);
2319 + if (!node_group->config) {
2320 + dev_err(pispbe->dev, "Unable to allocate cached config buffers.\n");
2322 + goto err_unregister_mdev;
2327 +err_unregister_mdev:
2328 + media_device_unregister(mdev);
2329 +err_unregister_nodes:
2330 + while (num_registered-- > 0) {
2331 + video_unregister_device(&node_group->node[num_registered].vfd);
2332 + vb2_queue_release(&node_group->node[num_registered].queue);
2334 + v4l2_device_unregister_subdev(&node_group->sd);
2335 + media_entity_cleanup(&node_group->sd.entity);
2336 +err_unregister_v4l2:
2337 + v4l2_device_unregister(v4l2_dev);
2338 +err_media_dev_cleanup:
2339 + media_device_cleanup(mdev);
2343 +static void pispbe_destroy_node_group(struct pispbe_node_group *node_group)
2345 + struct pispbe_dev *pispbe = node_group->pispbe;
2348 + if (node_group->config) {
2349 + dma_free_coherent(node_group->pispbe->dev,
2350 + sizeof(struct pisp_be_tiles_config) *
2351 + PISP_BE_NUM_CONFIG_BUFFERS,
2352 + node_group->config,
2353 + node_group->config_dma_addr);
2356 + dev_info(pispbe->dev, "Unregister from media controller\n");
2358 + v4l2_device_unregister_subdev(&node_group->sd);
2359 + media_entity_cleanup(&node_group->sd.entity);
2360 + media_device_unregister(&node_group->mdev);
2362 + for (i = PISPBE_NUM_NODES - 1; i >= 0; i--) {
2363 + video_unregister_device(&node_group->node[i].vfd);
2364 + vb2_queue_release(&node_group->node[i].queue);
2367 + media_device_cleanup(&node_group->mdev);
2368 + v4l2_device_unregister(&node_group->v4l2_dev);
2371 +static int pispbe_runtime_suspend(struct device *dev)
2373 + struct pispbe_dev *pispbe = dev_get_drvdata(dev);
2375 + clk_disable_unprepare(pispbe->clk);
2380 +static int pispbe_runtime_resume(struct device *dev)
2382 + struct pispbe_dev *pispbe = dev_get_drvdata(dev);
2385 + ret = clk_prepare_enable(pispbe->clk);
2387 + dev_err(dev, "Unable to enable clock\n");
2391 + dev_dbg(dev, "%s: Enabled clock, rate=%lu\n",
2392 + __func__, clk_get_rate(pispbe->clk));
2398 + * Probe the ISP-BE hardware block, as a single platform device.
2399 + * This will instantiate multiple "node groups" each with many device nodes.
2401 +static int pispbe_probe(struct platform_device *pdev)
2403 + unsigned int num_groups = 0;
2404 + struct pispbe_dev *pispbe;
2407 + pispbe = devm_kzalloc(&pdev->dev, sizeof(*pispbe), GFP_KERNEL);
2411 + dev_set_drvdata(&pdev->dev, pispbe);
2412 + pispbe->dev = &pdev->dev;
2413 + platform_set_drvdata(pdev, pispbe);
2415 + pispbe->be_reg_base = devm_platform_ioremap_resource(pdev, 0);
2416 + if (IS_ERR(pispbe->be_reg_base)) {
2417 + dev_err(&pdev->dev, "Failed to get ISP-BE registers address\n");
2418 + return PTR_ERR(pispbe->be_reg_base);
2421 + pispbe->irq = platform_get_irq(pdev, 0);
2422 + if (pispbe->irq <= 0) {
2423 + dev_err(&pdev->dev, "No IRQ resource\n");
2427 + ret = devm_request_irq(&pdev->dev, pispbe->irq, pispbe_isr, 0,
2428 + PISPBE_NAME, pispbe);
2430 + dev_err(&pdev->dev, "Unable to request interrupt\n");
2434 + ret = dma_set_mask_and_coherent(pispbe->dev, DMA_BIT_MASK(36));
2438 + pispbe->clk = devm_clk_get(&pdev->dev, NULL);
2439 + if (IS_ERR(pispbe->clk))
2440 + return dev_err_probe(&pdev->dev, PTR_ERR(pispbe->clk),
2441 + "Failed to get clock");
2443 + /* Hardware initialisation */
2444 + pm_runtime_set_autosuspend_delay(pispbe->dev, 200);
2445 + pm_runtime_use_autosuspend(pispbe->dev);
2446 + pm_runtime_enable(pispbe->dev);
2448 + ret = pm_runtime_resume_and_get(pispbe->dev);
2450 + goto pm_runtime_disable_err;
2452 + pispbe->hw_busy = 0;
2453 + spin_lock_init(&pispbe->hw_lock);
2454 + ret = hw_init(pispbe);
2456 + goto pm_runtime_put_err;
2459 + * Initialise and register devices for each node_group, including media
2462 + for (num_groups = 0;
2463 + num_groups < PISPBE_NUM_NODE_GROUPS;
2465 + ret = pispbe_init_group(pispbe, num_groups);
2467 + goto disable_nodes_err;
2470 + pm_runtime_mark_last_busy(pispbe->dev);
2471 + pm_runtime_put_autosuspend(pispbe->dev);
2476 + while (num_groups-- > 0)
2477 + pispbe_destroy_node_group(&pispbe->node_group[num_groups]);
2478 +pm_runtime_put_err:
2479 + pm_runtime_put(pispbe->dev);
2480 +pm_runtime_disable_err:
2481 + pm_runtime_dont_use_autosuspend(pispbe->dev);
2482 + pm_runtime_disable(pispbe->dev);
2484 + dev_err(&pdev->dev, "%s: returning %d", __func__, ret);
2489 +static int pispbe_remove(struct platform_device *pdev)
2491 + struct pispbe_dev *pispbe = platform_get_drvdata(pdev);
2494 + for (i = PISPBE_NUM_NODE_GROUPS - 1; i >= 0; i--)
2495 + pispbe_destroy_node_group(&pispbe->node_group[i]);
2497 + pm_runtime_dont_use_autosuspend(pispbe->dev);
2498 + pm_runtime_disable(pispbe->dev);
2503 +static const struct dev_pm_ops pispbe_pm_ops = {
2504 + SET_RUNTIME_PM_OPS(pispbe_runtime_suspend, pispbe_runtime_resume, NULL)
2507 +static const struct of_device_id pispbe_of_match[] = {
2509 + .compatible = "raspberrypi,pispbe",
2511 + { /* sentinel */ },
2513 +MODULE_DEVICE_TABLE(of, pispbe_of_match);
2515 +static struct platform_driver pispbe_pdrv = {
2516 + .probe = pispbe_probe,
2517 + .remove = pispbe_remove,
2519 + .name = PISPBE_NAME,
2520 + .of_match_table = pispbe_of_match,
2521 + .pm = &pispbe_pm_ops,
2525 +module_platform_driver(pispbe_pdrv);
2527 +++ b/drivers/media/platform/raspberrypi/pisp_be/pisp_be_config.h
2529 +/* SPDX-License-Identifier: GPL-2.0-only */
2531 + * PiSP Back End configuration definitions.
2533 + * Copyright (C) 2021 - Raspberry Pi Ltd
2536 +#ifndef _PISP_BE_CONFIG_H_
2537 +#define _PISP_BE_CONFIG_H_
2539 +#include <linux/types.h>
2541 +#include <media/raspberrypi/pisp_common.h>
2543 +/* byte alignment for inputs */
2544 +#define PISP_BACK_END_INPUT_ALIGN 4u
2545 +/* alignment for compressed inputs */
2546 +#define PISP_BACK_END_COMPRESSED_ALIGN 8u
2547 +/* minimum required byte alignment for outputs */
2548 +#define PISP_BACK_END_OUTPUT_MIN_ALIGN 16u
2549 +/* preferred byte alignment for outputs */
2550 +#define PISP_BACK_END_OUTPUT_MAX_ALIGN 64u
2552 +/* minimum allowed tile width anywhere in the pipeline */
2553 +#define PISP_BACK_END_MIN_TILE_WIDTH 16u
2554 +/* minimum allowed tile width anywhere in the pipeline */
2555 +#define PISP_BACK_END_MIN_TILE_HEIGHT 16u
2557 +#define PISP_BACK_END_NUM_OUTPUTS 2
2558 +#define PISP_BACK_END_HOG_OUTPUT 1
2560 +#define PISP_BACK_END_NUM_TILES 64
2562 +enum pisp_be_bayer_enable {
2563 + PISP_BE_BAYER_ENABLE_INPUT = 0x000001,
2564 + PISP_BE_BAYER_ENABLE_DECOMPRESS = 0x000002,
2565 + PISP_BE_BAYER_ENABLE_DPC = 0x000004,
2566 + PISP_BE_BAYER_ENABLE_GEQ = 0x000008,
2567 + PISP_BE_BAYER_ENABLE_TDN_INPUT = 0x000010,
2568 + PISP_BE_BAYER_ENABLE_TDN_DECOMPRESS = 0x000020,
2569 + PISP_BE_BAYER_ENABLE_TDN = 0x000040,
2570 + PISP_BE_BAYER_ENABLE_TDN_COMPRESS = 0x000080,
2571 + PISP_BE_BAYER_ENABLE_TDN_OUTPUT = 0x000100,
2572 + PISP_BE_BAYER_ENABLE_SDN = 0x000200,
2573 + PISP_BE_BAYER_ENABLE_BLC = 0x000400,
2574 + PISP_BE_BAYER_ENABLE_STITCH_INPUT = 0x000800,
2575 + PISP_BE_BAYER_ENABLE_STITCH_DECOMPRESS = 0x001000,
2576 + PISP_BE_BAYER_ENABLE_STITCH = 0x002000,
2577 + PISP_BE_BAYER_ENABLE_STITCH_COMPRESS = 0x004000,
2578 + PISP_BE_BAYER_ENABLE_STITCH_OUTPUT = 0x008000,
2579 + PISP_BE_BAYER_ENABLE_WBG = 0x010000,
2580 + PISP_BE_BAYER_ENABLE_CDN = 0x020000,
2581 + PISP_BE_BAYER_ENABLE_LSC = 0x040000,
2582 + PISP_BE_BAYER_ENABLE_TONEMAP = 0x080000,
2583 + PISP_BE_BAYER_ENABLE_CAC = 0x100000,
2584 + PISP_BE_BAYER_ENABLE_DEBIN = 0x200000,
2585 + PISP_BE_BAYER_ENABLE_DEMOSAIC = 0x400000,
2588 +enum pisp_be_rgb_enable {
2589 + PISP_BE_RGB_ENABLE_INPUT = 0x000001,
2590 + PISP_BE_RGB_ENABLE_CCM = 0x000002,
2591 + PISP_BE_RGB_ENABLE_SAT_CONTROL = 0x000004,
2592 + PISP_BE_RGB_ENABLE_YCBCR = 0x000008,
2593 + PISP_BE_RGB_ENABLE_FALSE_COLOUR = 0x000010,
2594 + PISP_BE_RGB_ENABLE_SHARPEN = 0x000020,
2595 + /* Preferred colours would occupy 0x000040 */
2596 + PISP_BE_RGB_ENABLE_YCBCR_INVERSE = 0x000080,
2597 + PISP_BE_RGB_ENABLE_GAMMA = 0x000100,
2598 + PISP_BE_RGB_ENABLE_CSC0 = 0x000200,
2599 + PISP_BE_RGB_ENABLE_CSC1 = 0x000400,
2600 + PISP_BE_RGB_ENABLE_DOWNSCALE0 = 0x001000,
2601 + PISP_BE_RGB_ENABLE_DOWNSCALE1 = 0x002000,
2602 + PISP_BE_RGB_ENABLE_RESAMPLE0 = 0x008000,
2603 + PISP_BE_RGB_ENABLE_RESAMPLE1 = 0x010000,
2604 + PISP_BE_RGB_ENABLE_OUTPUT0 = 0x040000,
2605 + PISP_BE_RGB_ENABLE_OUTPUT1 = 0x080000,
2606 + PISP_BE_RGB_ENABLE_HOG = 0x200000
2609 +#define PISP_BE_RGB_ENABLE_CSC(i) (PISP_BE_RGB_ENABLE_CSC0 << (i))
2610 +#define PISP_BE_RGB_ENABLE_DOWNSCALE(i) (PISP_BE_RGB_ENABLE_DOWNSCALE0 << (i))
2611 +#define PISP_BE_RGB_ENABLE_RESAMPLE(i) (PISP_BE_RGB_ENABLE_RESAMPLE0 << (i))
2612 +#define PISP_BE_RGB_ENABLE_OUTPUT(i) (PISP_BE_RGB_ENABLE_OUTPUT0 << (i))
2615 + * We use the enable flags to show when blocks are "dirty", but we need some
2618 +enum pisp_be_dirty {
2619 + PISP_BE_DIRTY_GLOBAL = 0x0001,
2620 + PISP_BE_DIRTY_SH_FC_COMBINE = 0x0002,
2621 + PISP_BE_DIRTY_CROP = 0x0004
2624 +struct pisp_be_global_config {
2625 + u32 bayer_enables;
2631 +struct pisp_be_input_buffer_config {
2632 + /* low 32 bits followed by high 32 bits (for each of up to 3 planes) */
2636 +struct pisp_be_dpc_config {
2640 +#define PISP_BE_DPC_FLAG_FOLDBACK 1
2644 +struct pisp_be_geq_config {
2646 +#define PISP_BE_GEQ_SHARPER BIT(15)
2647 +#define PISP_BE_GEQ_SLOPE ((1 << 10) - 1)
2648 + /* top bit is the "sharper" flag, slope value is bottom 10 bits */
2649 + u16 slope_sharper;
2654 +struct pisp_be_tdn_input_buffer_config {
2655 + /* low 32 bits followed by high 32 bits */
2659 +struct pisp_be_tdn_config {
2662 + u16 noise_constant;
2669 +struct pisp_be_tdn_output_buffer_config {
2670 + /* low 32 bits followed by high 32 bits */
2674 +struct pisp_be_sdn_config {
2678 + u16 noise_constant;
2680 + u16 noise_constant2;
2684 +struct pisp_be_stitch_input_buffer_config {
2685 + /* low 32 bits followed by high 32 bits */
2689 +#define PISP_BE_STITCH_STREAMING_LONG 0x8000
2690 +#define PISP_BE_STITCH_EXPOSURE_RATIO_MASK 0x7fff
2692 +struct pisp_be_stitch_config {
2694 + u8 threshold_diff_power;
2697 + /* top bit indicates whether streaming input is the long exposure */
2698 + u16 exposure_ratio;
2700 + u8 motion_threshold_256;
2701 + u8 motion_threshold_recip;
2704 +struct pisp_be_stitch_output_buffer_config {
2705 + /* low 32 bits followed by high 32 bits */
2709 +struct pisp_be_cdn_config {
2715 +#define PISP_BE_LSC_LOG_GRID_SIZE 5
2716 +#define PISP_BE_LSC_GRID_SIZE (1 << PISP_BE_LSC_LOG_GRID_SIZE)
2717 +#define PISP_BE_LSC_STEP_PRECISION 18
2719 +struct pisp_be_lsc_config {
2720 + /* (1<<18) / grid_cell_width */
2722 + /* (1<<18) / grid_cell_height */
2724 + /* RGB gains jointly encoded in 32 bits */
2725 + u32 lut_packed[PISP_BE_LSC_GRID_SIZE + 1]
2726 + [PISP_BE_LSC_GRID_SIZE + 1];
2729 +struct pisp_be_lsc_extra {
2734 +#define PISP_BE_CAC_LOG_GRID_SIZE 3
2735 +#define PISP_BE_CAC_GRID_SIZE (1 << PISP_BE_CAC_LOG_GRID_SIZE)
2736 +#define PISP_BE_CAC_STEP_PRECISION 20
2738 +struct pisp_be_cac_config {
2739 + /* (1<<20) / grid_cell_width */
2741 + /* (1<<20) / grid_cell_height */
2743 + /* [gridy][gridx][rb][xy] */
2744 + s8 lut[PISP_BE_CAC_GRID_SIZE + 1][PISP_BE_CAC_GRID_SIZE + 1][2][2];
2747 +struct pisp_be_cac_extra {
2752 +#define PISP_BE_DEBIN_NUM_COEFFS 4
2754 +struct pisp_be_debin_config {
2755 + s8 coeffs[PISP_BE_DEBIN_NUM_COEFFS];
2761 +#define PISP_BE_TONEMAP_LUT_SIZE 64
2763 +struct pisp_be_tonemap_config {
2764 + u16 detail_constant;
2768 + u32 lut[PISP_BE_TONEMAP_LUT_SIZE];
2771 +struct pisp_be_demosaic_config {
2777 +struct pisp_be_ccm_config {
2783 +struct pisp_be_sat_control_config {
2790 +struct pisp_be_false_colour_config {
2795 +#define PISP_BE_SHARPEN_SIZE 5
2796 +#define PISP_BE_SHARPEN_FUNC_NUM_POINTS 9
2798 +struct pisp_be_sharpen_config {
2799 + s8 kernel0[PISP_BE_SHARPEN_SIZE * PISP_BE_SHARPEN_SIZE];
2801 + s8 kernel1[PISP_BE_SHARPEN_SIZE * PISP_BE_SHARPEN_SIZE];
2803 + s8 kernel2[PISP_BE_SHARPEN_SIZE * PISP_BE_SHARPEN_SIZE];
2805 + s8 kernel3[PISP_BE_SHARPEN_SIZE * PISP_BE_SHARPEN_SIZE];
2807 + s8 kernel4[PISP_BE_SHARPEN_SIZE * PISP_BE_SHARPEN_SIZE];
2809 + u16 threshold_offset0;
2810 + u16 threshold_slope0;
2813 + u16 threshold_offset1;
2814 + u16 threshold_slope1;
2817 + u16 threshold_offset2;
2818 + u16 threshold_slope2;
2821 + u16 threshold_offset3;
2822 + u16 threshold_slope3;
2825 + u16 threshold_offset4;
2826 + u16 threshold_slope4;
2829 + u16 positive_strength;
2830 + u16 positive_pre_limit;
2831 + u16 positive_func[PISP_BE_SHARPEN_FUNC_NUM_POINTS];
2832 + u16 positive_limit;
2833 + u16 negative_strength;
2834 + u16 negative_pre_limit;
2835 + u16 negative_func[PISP_BE_SHARPEN_FUNC_NUM_POINTS];
2836 + u16 negative_limit;
2843 +struct pisp_be_sh_fc_combine_config {
2850 +#define PISP_BE_GAMMA_LUT_SIZE 64
2852 +struct pisp_be_gamma_config {
2853 + u32 lut[PISP_BE_GAMMA_LUT_SIZE];
2856 +struct pisp_be_crop_config {
2857 + u16 offset_x, offset_y;
2858 + u16 width, height;
2861 +#define PISP_BE_RESAMPLE_FILTER_SIZE 96
2863 +struct pisp_be_resample_config {
2864 + u16 scale_factor_h, scale_factor_v;
2865 + s16 coef[PISP_BE_RESAMPLE_FILTER_SIZE];
2868 +struct pisp_be_resample_extra {
2870 + u16 scaled_height;
2871 + s16 initial_phase_h[3];
2872 + s16 initial_phase_v[3];
2875 +struct pisp_be_downscale_config {
2876 + u16 scale_factor_h;
2877 + u16 scale_factor_v;
2878 + u16 scale_recip_h;
2879 + u16 scale_recip_v;
2882 +struct pisp_be_downscale_extra {
2884 + u16 scaled_height;
2887 +struct pisp_be_hog_config {
2888 + u8 compute_signed;
2889 + u8 channel_mix[3];
2893 +struct pisp_be_axi_config {
2894 + u8 r_qos; /* Read QoS */
2895 + u8 r_cache_prot; /* Read { prot[2:0], cache[3:0] } */
2896 + u8 w_qos; /* Write QoS */
2897 + u8 w_cache_prot; /* Write { prot[2:0], cache[3:0] } */
2900 +enum pisp_be_transform {
2901 + PISP_BE_TRANSFORM_NONE = 0x0,
2902 + PISP_BE_TRANSFORM_HFLIP = 0x1,
2903 + PISP_BE_TRANSFORM_VFLIP = 0x2,
2904 + PISP_BE_TRANSFORM_ROT180 =
2905 + (PISP_BE_TRANSFORM_HFLIP | PISP_BE_TRANSFORM_VFLIP)
2908 +struct pisp_be_output_format_config {
2909 + struct pisp_image_format_config image;
2918 +struct pisp_be_output_buffer_config {
2919 + /* low 32 bits followed by high 32 bits (for each of 3 planes) */
2923 +struct pisp_be_hog_buffer_config {
2924 + /* low 32 bits followed by high 32 bits */
2928 +struct pisp_be_config {
2929 + /* I/O configuration: */
2930 + struct pisp_be_input_buffer_config input_buffer;
2931 + struct pisp_be_tdn_input_buffer_config tdn_input_buffer;
2932 + struct pisp_be_stitch_input_buffer_config stitch_input_buffer;
2933 + struct pisp_be_tdn_output_buffer_config tdn_output_buffer;
2934 + struct pisp_be_stitch_output_buffer_config stitch_output_buffer;
2935 + struct pisp_be_output_buffer_config
2936 + output_buffer[PISP_BACK_END_NUM_OUTPUTS];
2937 + struct pisp_be_hog_buffer_config hog_buffer;
2938 + /* Processing configuration: */
2939 + struct pisp_be_global_config global;
2940 + struct pisp_image_format_config input_format;
2941 + struct pisp_decompress_config decompress;
2942 + struct pisp_be_dpc_config dpc;
2943 + struct pisp_be_geq_config geq;
2944 + struct pisp_image_format_config tdn_input_format;
2945 + struct pisp_decompress_config tdn_decompress;
2946 + struct pisp_be_tdn_config tdn;
2947 + struct pisp_compress_config tdn_compress;
2948 + struct pisp_image_format_config tdn_output_format;
2949 + struct pisp_be_sdn_config sdn;
2950 + struct pisp_bla_config blc;
2951 + struct pisp_compress_config stitch_compress;
2952 + struct pisp_image_format_config stitch_output_format;
2953 + struct pisp_image_format_config stitch_input_format;
2954 + struct pisp_decompress_config stitch_decompress;
2955 + struct pisp_be_stitch_config stitch;
2956 + struct pisp_be_lsc_config lsc;
2957 + struct pisp_wbg_config wbg;
2958 + struct pisp_be_cdn_config cdn;
2959 + struct pisp_be_cac_config cac;
2960 + struct pisp_be_debin_config debin;
2961 + struct pisp_be_tonemap_config tonemap;
2962 + struct pisp_be_demosaic_config demosaic;
2963 + struct pisp_be_ccm_config ccm;
2964 + struct pisp_be_sat_control_config sat_control;
2965 + struct pisp_be_ccm_config ycbcr;
2966 + struct pisp_be_sharpen_config sharpen;
2967 + struct pisp_be_false_colour_config false_colour;
2968 + struct pisp_be_sh_fc_combine_config sh_fc_combine;
2969 + struct pisp_be_ccm_config ycbcr_inverse;
2970 + struct pisp_be_gamma_config gamma;
2971 + struct pisp_be_ccm_config csc[PISP_BACK_END_NUM_OUTPUTS];
2972 + struct pisp_be_downscale_config downscale[PISP_BACK_END_NUM_OUTPUTS];
2973 + struct pisp_be_resample_config resample[PISP_BACK_END_NUM_OUTPUTS];
2974 + struct pisp_be_output_format_config
2975 + output_format[PISP_BACK_END_NUM_OUTPUTS];
2976 + struct pisp_be_hog_config hog;
2977 + struct pisp_be_axi_config axi;
2978 + /* Non-register fields: */
2979 + struct pisp_be_lsc_extra lsc_extra;
2980 + struct pisp_be_cac_extra cac_extra;
2981 + struct pisp_be_downscale_extra
2982 + downscale_extra[PISP_BACK_END_NUM_OUTPUTS];
2983 + struct pisp_be_resample_extra resample_extra[PISP_BACK_END_NUM_OUTPUTS];
2984 + struct pisp_be_crop_config crop;
2985 + struct pisp_image_format_config hog_format;
2986 + u32 dirty_flags_bayer; /* these use pisp_be_bayer_enable */
2987 + u32 dirty_flags_rgb; /* use pisp_be_rgb_enable */
2988 + u32 dirty_flags_extra; /* these use pisp_be_dirty_t */
2992 + * We also need a tile structure to describe the size of the tiles going
2993 + * through the pipeline.
2996 +enum pisp_tile_edge {
2997 + PISP_LEFT_EDGE = (1 << 0),
2998 + PISP_RIGHT_EDGE = (1 << 1),
2999 + PISP_TOP_EDGE = (1 << 2),
3000 + PISP_BOTTOM_EDGE = (1 << 3)
3004 + u8 edge; // enum pisp_tile_edge
3007 + u32 input_addr_offset;
3008 + u32 input_addr_offset2;
3009 + u16 input_offset_x;
3010 + u16 input_offset_y;
3014 + u32 tdn_input_addr_offset;
3015 + u32 tdn_output_addr_offset;
3016 + u32 stitch_input_addr_offset;
3017 + u32 stitch_output_addr_offset;
3019 + u32 lsc_grid_offset_x;
3020 + u32 lsc_grid_offset_y;
3022 + u32 cac_grid_offset_x;
3023 + u32 cac_grid_offset_y;
3025 + u16 crop_x_start[PISP_BACK_END_NUM_OUTPUTS];
3026 + u16 crop_x_end[PISP_BACK_END_NUM_OUTPUTS];
3027 + u16 crop_y_start[PISP_BACK_END_NUM_OUTPUTS];
3028 + u16 crop_y_end[PISP_BACK_END_NUM_OUTPUTS];
3030 + /* Ordering is planes then branches */
3031 + u16 downscale_phase_x[3 * PISP_BACK_END_NUM_OUTPUTS];
3032 + u16 downscale_phase_y[3 * PISP_BACK_END_NUM_OUTPUTS];
3034 + u16 resample_in_width[PISP_BACK_END_NUM_OUTPUTS];
3035 + u16 resample_in_height[PISP_BACK_END_NUM_OUTPUTS];
3037 + /* Ordering is planes then branches */
3038 + u16 resample_phase_x[3 * PISP_BACK_END_NUM_OUTPUTS];
3039 + u16 resample_phase_y[3 * PISP_BACK_END_NUM_OUTPUTS];
3041 + u16 output_offset_x[PISP_BACK_END_NUM_OUTPUTS];
3042 + u16 output_offset_y[PISP_BACK_END_NUM_OUTPUTS];
3043 + u16 output_width[PISP_BACK_END_NUM_OUTPUTS];
3044 + u16 output_height[PISP_BACK_END_NUM_OUTPUTS];
3046 + u32 output_addr_offset[PISP_BACK_END_NUM_OUTPUTS];
3047 + u32 output_addr_offset2[PISP_BACK_END_NUM_OUTPUTS];
3049 + u32 output_hog_addr_offset;
3053 +static_assert(sizeof(struct pisp_tile) == 160);
3055 +struct pisp_be_tiles_config {
3056 + struct pisp_be_config config;
3057 + struct pisp_tile tiles[PISP_BACK_END_NUM_TILES];
3061 +#endif /* _PISP_BE_CONFIG_H_ */
3063 +++ b/drivers/media/platform/raspberrypi/pisp_be/pisp_be_formats.h
3065 +/* SPDX-License-Identifier: GPL-2.0 */
3067 + * PiSP Back End driver image format definitions.
3069 + * Copyright (c) 2021 Raspberry Pi Ltd
3072 +#ifndef _PISP_BE_FORMATS_
3073 +#define _PISP_BE_FORMATS_
3075 +#include <linux/bits.h>
3076 +#include <linux/videodev2.h>
3078 +#define MAX_PLANES 3
3079 +#define P3(x) ((x) * 8)
3081 +struct pisp_be_format {
3082 + unsigned int fourcc;
3083 + unsigned int align;
3084 + unsigned int bit_depth;
3085 + /* 0P3 factor for plane sizing */
3086 + unsigned int plane_factor[MAX_PLANES];
3087 + unsigned int num_planes;
3088 + unsigned int colorspace_mask;
3089 + enum v4l2_colorspace colorspace_default;
3092 +#define V4L2_COLORSPACE_MASK(colorspace) BIT(colorspace)
3094 +#define V4L2_COLORSPACE_MASK_JPEG V4L2_COLORSPACE_MASK(V4L2_COLORSPACE_JPEG)
3095 +#define V4L2_COLORSPACE_MASK_SMPTE170M V4L2_COLORSPACE_MASK(V4L2_COLORSPACE_SMPTE170M)
3096 +#define V4L2_COLORSPACE_MASK_REC709 V4L2_COLORSPACE_MASK(V4L2_COLORSPACE_REC709)
3097 +#define V4L2_COLORSPACE_MASK_SRGB V4L2_COLORSPACE_MASK(V4L2_COLORSPACE_SRGB)
3098 +#define V4L2_COLORSPACE_MASK_RAW V4L2_COLORSPACE_MASK(V4L2_COLORSPACE_RAW)
3101 + * All three colour spaces JPEG, SMPTE170M and REC709 are fundamentally sRGB
3102 + * underneath (as near as makes no difference to us), just with different YCbCr
3103 + * encodings. Therefore the ISP can generate sRGB on its main output and any of
3104 + * the others on its low resolution output. Applications should, when using both
3105 + * outputs, program the colour spaces on them to be the same, matching whatever
3106 + * is requested for the low resolution output, even if the main output is
3107 + * producing an RGB format. In turn this requires us to allow all these colour
3108 + * spaces for every YUV/RGB output format.
3110 +#define V4L2_COLORSPACE_MASK_ALL_SRGB (V4L2_COLORSPACE_MASK_JPEG | \
3111 + V4L2_COLORSPACE_MASK_SRGB | \
3112 + V4L2_COLORSPACE_MASK_SMPTE170M | \
3113 + V4L2_COLORSPACE_MASK_REC709)
3115 +static const struct pisp_be_format supported_formats[] = {
3116 + /* Single plane YUV formats */
3118 + .fourcc = V4L2_PIX_FMT_YUV420,
3119 + /* 128 alignment to ensure U/V planes are 64 byte aligned. */
3122 + .plane_factor = { P3(1), P3(0.25), P3(0.25) },
3124 + .colorspace_mask = V4L2_COLORSPACE_MASK_ALL_SRGB,
3125 + .colorspace_default = V4L2_COLORSPACE_JPEG,
3128 + .fourcc = V4L2_PIX_FMT_YVU420,
3129 + /* 128 alignment to ensure U/V planes are 64 byte aligned. */
3132 + .plane_factor = { P3(1), P3(0.25), P3(0.25) },
3134 + .colorspace_mask = V4L2_COLORSPACE_MASK_ALL_SRGB,
3135 + .colorspace_default = V4L2_COLORSPACE_SMPTE170M,
3138 + .fourcc = V4L2_PIX_FMT_NV12,
3141 + .plane_factor = { P3(1), P3(0.5) },
3143 + .colorspace_mask = V4L2_COLORSPACE_MASK_ALL_SRGB,
3144 + .colorspace_default = V4L2_COLORSPACE_SMPTE170M,
3147 + .fourcc = V4L2_PIX_FMT_NV21,
3150 + .plane_factor = { P3(1), P3(0.5) },
3152 + .colorspace_mask = V4L2_COLORSPACE_MASK_ALL_SRGB,
3153 + .colorspace_default = V4L2_COLORSPACE_SMPTE170M,
3156 + .fourcc = V4L2_PIX_FMT_YUYV,
3159 + .plane_factor = { P3(1) },
3161 + .colorspace_mask = V4L2_COLORSPACE_MASK_ALL_SRGB,
3162 + .colorspace_default = V4L2_COLORSPACE_SMPTE170M,
3165 + .fourcc = V4L2_PIX_FMT_UYVY,
3168 + .plane_factor = { P3(1) },
3170 + .colorspace_mask = V4L2_COLORSPACE_MASK_ALL_SRGB,
3171 + .colorspace_default = V4L2_COLORSPACE_SMPTE170M,
3174 + .fourcc = V4L2_PIX_FMT_YVYU,
3177 + .plane_factor = { P3(1) },
3179 + .colorspace_mask = V4L2_COLORSPACE_MASK_ALL_SRGB,
3180 + .colorspace_default = V4L2_COLORSPACE_SMPTE170M,
3183 + .fourcc = V4L2_PIX_FMT_VYUY,
3186 + .plane_factor = { P3(1) },
3188 + .colorspace_mask = V4L2_COLORSPACE_MASK_ALL_SRGB,
3189 + .colorspace_default = V4L2_COLORSPACE_SMPTE170M,
3191 + /* Multiplane YUV formats */
3193 + .fourcc = V4L2_PIX_FMT_YUV420M,
3196 + .plane_factor = { P3(1), P3(0.25), P3(0.25) },
3198 + .colorspace_mask = V4L2_COLORSPACE_MASK_ALL_SRGB,
3199 + .colorspace_default = V4L2_COLORSPACE_JPEG,
3202 + .fourcc = V4L2_PIX_FMT_NV12M,
3205 + .plane_factor = { P3(1), P3(0.5) },
3207 + .colorspace_mask = V4L2_COLORSPACE_MASK_ALL_SRGB,
3208 + .colorspace_default = V4L2_COLORSPACE_SMPTE170M,
3211 + .fourcc = V4L2_PIX_FMT_NV21M,
3214 + .plane_factor = { P3(1), P3(0.5) },
3216 + .colorspace_mask = V4L2_COLORSPACE_MASK_ALL_SRGB,
3217 + .colorspace_default = V4L2_COLORSPACE_SMPTE170M,
3220 + .fourcc = V4L2_PIX_FMT_YVU420M,
3223 + .plane_factor = { P3(1), P3(0.25), P3(0.25) },
3225 + .colorspace_mask = V4L2_COLORSPACE_MASK_ALL_SRGB,
3226 + .colorspace_default = V4L2_COLORSPACE_SMPTE170M,
3229 + .fourcc = V4L2_PIX_FMT_YUV422M,
3232 + .plane_factor = { P3(1), P3(0.5), P3(0.5) },
3234 + .colorspace_mask = V4L2_COLORSPACE_MASK_ALL_SRGB,
3235 + .colorspace_default = V4L2_COLORSPACE_JPEG,
3238 + .fourcc = V4L2_PIX_FMT_YVU422M,
3241 + .plane_factor = { P3(1), P3(0.5), P3(0.5) },
3243 + .colorspace_mask = V4L2_COLORSPACE_MASK_ALL_SRGB,
3244 + .colorspace_default = V4L2_COLORSPACE_SMPTE170M,
3247 + .fourcc = V4L2_PIX_FMT_YUV444M,
3250 + .plane_factor = { P3(1), P3(1), P3(1) },
3252 + .colorspace_mask = V4L2_COLORSPACE_MASK_ALL_SRGB,
3253 + .colorspace_default = V4L2_COLORSPACE_JPEG,
3256 + .fourcc = V4L2_PIX_FMT_YVU444M,
3259 + .plane_factor = { P3(1), P3(1), P3(1) },
3261 + .colorspace_mask = V4L2_COLORSPACE_MASK_ALL_SRGB,
3262 + .colorspace_default = V4L2_COLORSPACE_SMPTE170M,
3266 + .fourcc = V4L2_PIX_FMT_RGB24,
3269 + .plane_factor = { P3(1.0) },
3271 + .colorspace_mask = V4L2_COLORSPACE_MASK_ALL_SRGB,
3272 + .colorspace_default = V4L2_COLORSPACE_SRGB,
3275 + .fourcc = V4L2_PIX_FMT_BGR24,
3278 + .plane_factor = { P3(1.0) },
3280 + .colorspace_mask = V4L2_COLORSPACE_MASK_ALL_SRGB,
3281 + .colorspace_default = V4L2_COLORSPACE_SRGB,
3284 + .fourcc = V4L2_PIX_FMT_XBGR32,
3287 + .plane_factor = { P3(1.0) },
3289 + .colorspace_mask = V4L2_COLORSPACE_MASK_ALL_SRGB,
3290 + .colorspace_default = V4L2_COLORSPACE_SRGB,
3293 + .fourcc = V4L2_PIX_FMT_RGBX32,
3296 + .plane_factor = { P3(1.0) },
3298 + .colorspace_mask = V4L2_COLORSPACE_MASK_ALL_SRGB,
3299 + .colorspace_default = V4L2_COLORSPACE_SRGB,
3301 + /* Bayer formats - 8-bit */
3303 + .fourcc = V4L2_PIX_FMT_SRGGB8,
3306 + .plane_factor = { P3(1.0) },
3308 + .colorspace_mask = V4L2_COLORSPACE_MASK_RAW,
3309 + .colorspace_default = V4L2_COLORSPACE_RAW,
3312 + .fourcc = V4L2_PIX_FMT_SBGGR8,
3315 + .plane_factor = { P3(1.0) },
3317 + .colorspace_mask = V4L2_COLORSPACE_MASK_RAW,
3318 + .colorspace_default = V4L2_COLORSPACE_RAW,
3321 + .fourcc = V4L2_PIX_FMT_SGRBG8,
3324 + .plane_factor = { P3(1.0) },
3326 + .colorspace_mask = V4L2_COLORSPACE_MASK_RAW,
3327 + .colorspace_default = V4L2_COLORSPACE_RAW,
3330 + .fourcc = V4L2_PIX_FMT_SGBRG8,
3333 + .plane_factor = { P3(1.0) },
3335 + .colorspace_mask = V4L2_COLORSPACE_MASK_RAW,
3336 + .colorspace_default = V4L2_COLORSPACE_RAW,
3338 + /* Bayer formats - 16-bit */
3340 + .fourcc = V4L2_PIX_FMT_SRGGB16,
3343 + .plane_factor = { P3(1.0) },
3345 + .colorspace_mask = V4L2_COLORSPACE_MASK_RAW,
3346 + .colorspace_default = V4L2_COLORSPACE_RAW,
3349 + .fourcc = V4L2_PIX_FMT_SBGGR16,
3352 + .plane_factor = { P3(1.0) },
3354 + .colorspace_mask = V4L2_COLORSPACE_MASK_RAW,
3355 + .colorspace_default = V4L2_COLORSPACE_RAW,
3358 + .fourcc = V4L2_PIX_FMT_SGRBG16,
3361 + .plane_factor = { P3(1.0) },
3363 + .colorspace_mask = V4L2_COLORSPACE_MASK_RAW,
3364 + .colorspace_default = V4L2_COLORSPACE_RAW,
3367 + .fourcc = V4L2_PIX_FMT_SGBRG16,
3370 + .plane_factor = { P3(1.0) },
3372 + .colorspace_mask = V4L2_COLORSPACE_MASK_RAW,
3373 + .colorspace_default = V4L2_COLORSPACE_RAW,
3376 + /* Bayer formats unpacked to 16bpp */
3378 + .fourcc = V4L2_PIX_FMT_SRGGB10,
3381 + .plane_factor = { P3(1.0) },
3383 + .colorspace_mask = V4L2_COLORSPACE_MASK_RAW,
3384 + .colorspace_default = V4L2_COLORSPACE_RAW,
3387 + .fourcc = V4L2_PIX_FMT_SBGGR10,
3390 + .plane_factor = { P3(1.0) },
3392 + .colorspace_mask = V4L2_COLORSPACE_MASK_RAW,
3393 + .colorspace_default = V4L2_COLORSPACE_RAW,
3396 + .fourcc = V4L2_PIX_FMT_SGRBG10,
3399 + .plane_factor = { P3(1.0) },
3401 + .colorspace_mask = V4L2_COLORSPACE_MASK_RAW,
3402 + .colorspace_default = V4L2_COLORSPACE_RAW,
3405 + .fourcc = V4L2_PIX_FMT_SGBRG10,
3408 + .plane_factor = { P3(1.0) },
3410 + .colorspace_mask = V4L2_COLORSPACE_MASK_RAW,
3411 + .colorspace_default = V4L2_COLORSPACE_RAW,
3415 + .fourcc = V4L2_PIX_FMT_SRGGB12,
3418 + .plane_factor = { P3(1.0) },
3420 + .colorspace_mask = V4L2_COLORSPACE_MASK_RAW,
3421 + .colorspace_default = V4L2_COLORSPACE_RAW,
3424 + .fourcc = V4L2_PIX_FMT_SBGGR12,
3427 + .plane_factor = { P3(1.0) },
3429 + .colorspace_mask = V4L2_COLORSPACE_MASK_RAW,
3430 + .colorspace_default = V4L2_COLORSPACE_RAW,
3433 + .fourcc = V4L2_PIX_FMT_SGRBG12,
3436 + .plane_factor = { P3(1.0) },
3438 + .colorspace_mask = V4L2_COLORSPACE_MASK_RAW,
3439 + .colorspace_default = V4L2_COLORSPACE_RAW,
3442 + .fourcc = V4L2_PIX_FMT_SGBRG12,
3445 + .plane_factor = { P3(1.0) },
3447 + .colorspace_mask = V4L2_COLORSPACE_MASK_RAW,
3448 + .colorspace_default = V4L2_COLORSPACE_RAW,
3452 + .fourcc = V4L2_PIX_FMT_SRGGB14,
3455 + .plane_factor = { P3(1.0) },
3457 + .colorspace_mask = V4L2_COLORSPACE_MASK_RAW,
3458 + .colorspace_default = V4L2_COLORSPACE_RAW,
3461 + .fourcc = V4L2_PIX_FMT_SBGGR14,
3464 + .plane_factor = { P3(1.0) },
3466 + .colorspace_mask = V4L2_COLORSPACE_MASK_RAW,
3467 + .colorspace_default = V4L2_COLORSPACE_RAW,
3470 + .fourcc = V4L2_PIX_FMT_SGRBG14,
3473 + .plane_factor = { P3(1.0) },
3475 + .colorspace_mask = V4L2_COLORSPACE_MASK_RAW,
3476 + .colorspace_default = V4L2_COLORSPACE_RAW,
3479 + .fourcc = V4L2_PIX_FMT_SGBRG14,
3482 + .plane_factor = { P3(1.0) },
3484 + .colorspace_mask = V4L2_COLORSPACE_MASK_RAW,
3485 + .colorspace_default = V4L2_COLORSPACE_RAW,
3487 + /* Bayer formats - 16-bit PiSP Compressed */
3489 + .fourcc = V4L2_PIX_FMT_PISP_COMP1_BGGR,
3492 + .plane_factor = { P3(1.0) },
3494 + .colorspace_mask = V4L2_COLORSPACE_MASK_RAW,
3495 + .colorspace_default = V4L2_COLORSPACE_RAW,
3498 + .fourcc = V4L2_PIX_FMT_PISP_COMP1_RGGB,
3501 + .plane_factor = { P3(1.0) },
3503 + .colorspace_mask = V4L2_COLORSPACE_MASK_RAW,
3504 + .colorspace_default = V4L2_COLORSPACE_RAW,
3507 + .fourcc = V4L2_PIX_FMT_PISP_COMP1_GRBG,
3510 + .plane_factor = { P3(1.0) },
3512 + .colorspace_mask = V4L2_COLORSPACE_MASK_RAW,
3513 + .colorspace_default = V4L2_COLORSPACE_RAW,
3516 + .fourcc = V4L2_PIX_FMT_PISP_COMP1_GBRG,
3519 + .plane_factor = { P3(1.0) },
3521 + .colorspace_mask = V4L2_COLORSPACE_MASK_RAW,
3522 + .colorspace_default = V4L2_COLORSPACE_RAW,
3526 +static const struct pisp_be_format meta_out_supported_formats[] = {
3527 + /* Configuration buffer format. */
3529 + .fourcc = V4L2_META_FMT_RPI_BE_CFG,
3533 +#endif /* _PISP_BE_FORMATS_ */
3534 --- a/drivers/media/v4l2-core/v4l2-ioctl.c
3535 +++ b/drivers/media/v4l2-core/v4l2-ioctl.c
3536 @@ -1452,6 +1452,7 @@ static void v4l_fill_fmtdesc(struct v4l2
3537 case V4L2_PIX_FMT_NV12M_10BE_8L128: descr = "10-bit NV12M (8x128 Linear, BE)"; break;
3538 case V4L2_META_FMT_SENSOR_DATA: descr = "Sensor Ancillary Metadata"; break;
3539 case V4L2_META_FMT_BCM2835_ISP_STATS: descr = "BCM2835 ISP Image Statistics"; break;
3540 + case V4L2_META_FMT_RPI_BE_CFG: descr = "PiSP Config format"; break;
3543 /* Compressed formats */
3544 @@ -1503,6 +1504,7 @@ static void v4l_fill_fmtdesc(struct v4l2
3545 case V4L2_PIX_FMT_MT21C: descr = "Mediatek Compressed Format"; break;
3546 case V4L2_PIX_FMT_QC08C: descr = "QCOM Compressed 8-bit Format"; break;
3547 case V4L2_PIX_FMT_QC10C: descr = "QCOM Compressed 10-bit Format"; break;
3548 + case V4L2_PIX_FMT_RPI_BE: descr = "PiSP Opaque Format"; break;
3550 if (fmt->description[0])
3553 +++ b/include/media/raspberrypi/pisp_common.h
3555 +/* SPDX-License-Identifier: GPL-2.0-only */
3557 + * Raspberry Pi PiSP common configuration definitions.
3559 + * Copyright (C) 2021 - Raspberry Pi (Trading) Ltd.
3562 +#ifndef _PISP_COMMON_H_
3563 +#define _PISP_COMMON_H_
3565 +#include <linux/types.h>
3567 +#include "pisp_types.h"
3569 +struct pisp_bla_config {
3570 + uint16_t black_level_r;
3571 + uint16_t black_level_gr;
3572 + uint16_t black_level_gb;
3573 + uint16_t black_level_b;
3574 + uint16_t output_black_level;
3578 +struct pisp_wbg_config {
3585 +struct pisp_compress_config {
3586 + /* value subtracted from incoming data */
3589 + /* 1 => Companding; 2 => Delta (recommended); 3 => Combined (for HDR) */
3593 +struct pisp_decompress_config {
3594 + /* value added to reconstructed data */
3597 + /* 1 => Companding; 2 => Delta (recommended); 3 => Combined (for HDR) */
3601 +enum pisp_axi_flags {
3602 + /* round down bursts to end at a 32-byte boundary, to align following bursts */
3603 + PISP_AXI_FLAG_ALIGN = 128,
3604 + /* for FE writer: force WSTRB high, to pad output to 16-byte boundary */
3605 + PISP_AXI_FLAG_PAD = 64,
3606 + /* for FE writer: Use Output FIFO level to trigger "panic" */
3607 + PISP_AXI_FLAG_PANIC = 32
3610 +struct pisp_axi_config {
3611 + /* burst length minus one, which must be in the range 0:15; OR'd with flags */
3612 + uint8_t maxlen_flags;
3613 + /* { prot[2:0], cache[3:0] } fields, echoed on AXI bus */
3614 + uint8_t cache_prot;
3615 + /* QoS field(s) (4x4 bits for FE writer; 4 bits for other masters) */
3619 +#endif /* _PISP_COMMON_H_ */
3621 +++ b/include/media/raspberrypi/pisp_types.h
3623 +/* SPDX-License-Identifier: GPL-2.0-only */
3625 + * Raspberry Pi PiSP common types.
3627 + * Copyright (C) 2021 - Raspberry Pi (Trading) Ltd.
3630 +#ifndef _PISP_TYPES_H_
3631 +#define _PISP_TYPES_H_
3633 +/* This definition must match the format description in the hardware exactly! */
3634 +struct pisp_image_format_config {
3635 + /* size in pixels */
3636 + uint16_t width, height;
3637 + /* must match struct pisp_image_format below */
3640 + /* some planar image formats will need a second stride */
3644 +static_assert(sizeof(struct pisp_image_format_config) == 16);
3646 +enum pisp_bayer_order {
3648 + * Note how bayer_order&1 tells you if G is on the even pixels of the
3649 + * checkerboard or not, and bayer_order&2 tells you if R is on the even
3650 + * rows or is swapped with B. Note that if the top (of the 8) bits is
3651 + * set, this denotes a monochrome or greyscale image, and the lower bits
3652 + * should all be ignored.
3654 + PISP_BAYER_ORDER_RGGB = 0,
3655 + PISP_BAYER_ORDER_GBRG = 1,
3656 + PISP_BAYER_ORDER_BGGR = 2,
3657 + PISP_BAYER_ORDER_GRBG = 3,
3658 + PISP_BAYER_ORDER_GREYSCALE = 128
3661 +enum pisp_image_format {
3663 + * Precise values are mostly tbd. Generally these will be portmanteau
3664 + * values comprising bit fields and flags. This format must be shared
3665 + * throughout the PiSP.
3667 + PISP_IMAGE_FORMAT_BPS_8 = 0x00000000,
3668 + PISP_IMAGE_FORMAT_BPS_10 = 0x00000001,
3669 + PISP_IMAGE_FORMAT_BPS_12 = 0x00000002,
3670 + PISP_IMAGE_FORMAT_BPS_16 = 0x00000003,
3671 + PISP_IMAGE_FORMAT_BPS_MASK = 0x00000003,
3673 + PISP_IMAGE_FORMAT_PLANARITY_INTERLEAVED = 0x00000000,
3674 + PISP_IMAGE_FORMAT_PLANARITY_SEMI_PLANAR = 0x00000010,
3675 + PISP_IMAGE_FORMAT_PLANARITY_PLANAR = 0x00000020,
3676 + PISP_IMAGE_FORMAT_PLANARITY_MASK = 0x00000030,
3678 + PISP_IMAGE_FORMAT_SAMPLING_444 = 0x00000000,
3679 + PISP_IMAGE_FORMAT_SAMPLING_422 = 0x00000100,
3680 + PISP_IMAGE_FORMAT_SAMPLING_420 = 0x00000200,
3681 + PISP_IMAGE_FORMAT_SAMPLING_MASK = 0x00000300,
3683 + PISP_IMAGE_FORMAT_ORDER_NORMAL = 0x00000000,
3684 + PISP_IMAGE_FORMAT_ORDER_SWAPPED = 0x00001000,
3686 + PISP_IMAGE_FORMAT_SHIFT_0 = 0x00000000,
3687 + PISP_IMAGE_FORMAT_SHIFT_1 = 0x00010000,
3688 + PISP_IMAGE_FORMAT_SHIFT_2 = 0x00020000,
3689 + PISP_IMAGE_FORMAT_SHIFT_3 = 0x00030000,
3690 + PISP_IMAGE_FORMAT_SHIFT_4 = 0x00040000,
3691 + PISP_IMAGE_FORMAT_SHIFT_5 = 0x00050000,
3692 + PISP_IMAGE_FORMAT_SHIFT_6 = 0x00060000,
3693 + PISP_IMAGE_FORMAT_SHIFT_7 = 0x00070000,
3694 + PISP_IMAGE_FORMAT_SHIFT_8 = 0x00080000,
3695 + PISP_IMAGE_FORMAT_SHIFT_MASK = 0x000f0000,
3697 + PISP_IMAGE_FORMAT_UNCOMPRESSED = 0x00000000,
3698 + PISP_IMAGE_FORMAT_COMPRESSION_MODE_1 = 0x01000000,
3699 + PISP_IMAGE_FORMAT_COMPRESSION_MODE_2 = 0x02000000,
3700 + PISP_IMAGE_FORMAT_COMPRESSION_MODE_3 = 0x03000000,
3701 + PISP_IMAGE_FORMAT_COMPRESSION_MASK = 0x03000000,
3703 + PISP_IMAGE_FORMAT_HOG_SIGNED = 0x04000000,
3704 + PISP_IMAGE_FORMAT_HOG_UNSIGNED = 0x08000000,
3705 + PISP_IMAGE_FORMAT_INTEGRAL_IMAGE = 0x10000000,
3706 + PISP_IMAGE_FORMAT_WALLPAPER_ROLL = 0x20000000,
3707 + PISP_IMAGE_FORMAT_THREE_CHANNEL = 0x40000000,
3709 + /* Lastly a few specific instantiations of the above. */
3710 + PISP_IMAGE_FORMAT_SINGLE_16 = PISP_IMAGE_FORMAT_BPS_16,
3711 + PISP_IMAGE_FORMAT_THREE_16 =
3712 + PISP_IMAGE_FORMAT_BPS_16 | PISP_IMAGE_FORMAT_THREE_CHANNEL
3715 +#define PISP_IMAGE_FORMAT_bps_8(fmt) \
3716 + (((fmt)&PISP_IMAGE_FORMAT_BPS_MASK) == PISP_IMAGE_FORMAT_BPS_8)
3717 +#define PISP_IMAGE_FORMAT_bps_10(fmt) \
3718 + (((fmt)&PISP_IMAGE_FORMAT_BPS_MASK) == PISP_IMAGE_FORMAT_BPS_10)
3719 +#define PISP_IMAGE_FORMAT_bps_12(fmt) \
3720 + (((fmt)&PISP_IMAGE_FORMAT_BPS_MASK) == PISP_IMAGE_FORMAT_BPS_12)
3721 +#define PISP_IMAGE_FORMAT_bps_16(fmt) \
3722 + (((fmt)&PISP_IMAGE_FORMAT_BPS_MASK) == PISP_IMAGE_FORMAT_BPS_16)
3723 +#define PISP_IMAGE_FORMAT_bps(fmt) \
3724 + (((fmt)&PISP_IMAGE_FORMAT_BPS_MASK) ? \
3725 + 8 + (2 << (((fmt)&PISP_IMAGE_FORMAT_BPS_MASK) - 1)) : \
3727 +#define PISP_IMAGE_FORMAT_shift(fmt) \
3728 + (((fmt)&PISP_IMAGE_FORMAT_SHIFT_MASK) / PISP_IMAGE_FORMAT_SHIFT_1)
3729 +#define PISP_IMAGE_FORMAT_three_channel(fmt) \
3730 + ((fmt)&PISP_IMAGE_FORMAT_THREE_CHANNEL)
3731 +#define PISP_IMAGE_FORMAT_single_channel(fmt) \
3732 + (!((fmt)&PISP_IMAGE_FORMAT_THREE_CHANNEL))
3733 +#define PISP_IMAGE_FORMAT_compressed(fmt) \
3734 + (((fmt)&PISP_IMAGE_FORMAT_COMPRESSION_MASK) != \
3735 + PISP_IMAGE_FORMAT_UNCOMPRESSED)
3736 +#define PISP_IMAGE_FORMAT_sampling_444(fmt) \
3737 + (((fmt)&PISP_IMAGE_FORMAT_SAMPLING_MASK) == \
3738 + PISP_IMAGE_FORMAT_SAMPLING_444)
3739 +#define PISP_IMAGE_FORMAT_sampling_422(fmt) \
3740 + (((fmt)&PISP_IMAGE_FORMAT_SAMPLING_MASK) == \
3741 + PISP_IMAGE_FORMAT_SAMPLING_422)
3742 +#define PISP_IMAGE_FORMAT_sampling_420(fmt) \
3743 + (((fmt)&PISP_IMAGE_FORMAT_SAMPLING_MASK) == \
3744 + PISP_IMAGE_FORMAT_SAMPLING_420)
3745 +#define PISP_IMAGE_FORMAT_order_normal(fmt) \
3746 + (!((fmt)&PISP_IMAGE_FORMAT_ORDER_SWAPPED))
3747 +#define PISP_IMAGE_FORMAT_order_swapped(fmt) \
3748 + ((fmt)&PISP_IMAGE_FORMAT_ORDER_SWAPPED)
3749 +#define PISP_IMAGE_FORMAT_interleaved(fmt) \
3750 + (((fmt)&PISP_IMAGE_FORMAT_PLANARITY_MASK) == \
3751 + PISP_IMAGE_FORMAT_PLANARITY_INTERLEAVED)
3752 +#define PISP_IMAGE_FORMAT_semiplanar(fmt) \
3753 + (((fmt)&PISP_IMAGE_FORMAT_PLANARITY_MASK) == \
3754 + PISP_IMAGE_FORMAT_PLANARITY_SEMI_PLANAR)
3755 +#define PISP_IMAGE_FORMAT_planar(fmt) \
3756 + (((fmt)&PISP_IMAGE_FORMAT_PLANARITY_MASK) == \
3757 + PISP_IMAGE_FORMAT_PLANARITY_PLANAR)
3758 +#define PISP_IMAGE_FORMAT_wallpaper(fmt) \
3759 + ((fmt)&PISP_IMAGE_FORMAT_WALLPAPER_ROLL)
3760 +#define PISP_IMAGE_FORMAT_HOG(fmt) \
3762 + (PISP_IMAGE_FORMAT_HOG_SIGNED | PISP_IMAGE_FORMAT_HOG_UNSIGNED))
3764 +#define PISP_WALLPAPER_WIDTH 128 // in bytes
3766 +#endif /* _PISP_TYPES_H_ */
3767 --- a/include/uapi/linux/videodev2.h
3768 +++ b/include/uapi/linux/videodev2.h
3769 @@ -793,6 +793,9 @@ struct v4l2_pix_format {
3770 #define V4L2_PIX_FMT_IPU3_SGRBG10 v4l2_fourcc('i', 'p', '3', 'G') /* IPU3 packed 10-bit GRBG bayer */
3771 #define V4L2_PIX_FMT_IPU3_SRGGB10 v4l2_fourcc('i', 'p', '3', 'r') /* IPU3 packed 10-bit RGGB bayer */
3773 +/* The pixel format for all our buffers (the precise format is found in the config buffer). */
3774 +#define V4L2_PIX_FMT_RPI_BE v4l2_fourcc('R', 'P', 'B', 'P')
3776 /* SDR formats - used only for Software Defined Radio devices */
3777 #define V4L2_SDR_FMT_CU8 v4l2_fourcc('C', 'U', '0', '8') /* IQ u8 */
3778 #define V4L2_SDR_FMT_CU16LE v4l2_fourcc('C', 'U', '1', '6') /* IQ u16le */
3779 @@ -822,6 +825,9 @@ struct v4l2_pix_format {
3780 #define V4L2_META_FMT_RK_ISP1_PARAMS v4l2_fourcc('R', 'K', '1', 'P') /* Rockchip ISP1 3A Parameters */
3781 #define V4L2_META_FMT_RK_ISP1_STAT_3A v4l2_fourcc('R', 'K', '1', 'S') /* Rockchip ISP1 3A Statistics */
3783 +/* The metadata format identifier for our configuration buffers. */
3784 +#define V4L2_META_FMT_RPI_BE_CFG v4l2_fourcc('R', 'P', 'B', 'C')
3786 /* priv field value to indicates that subsequent fields are valid. */
3787 #define V4L2_PIX_FMT_PRIV_MAGIC 0xfeedcafe