1 /* SPDX-License-Identifier: GPL-2.0-only */
3 * Copyright (C) 2021-2022 Digiteq Automotive
10 #include <linux/math64.h>
11 #include <media/v4l2-dev.h>
12 #include "mgb4_core.h"
14 /* Register access error indication */
15 #define MGB4_ERR_NO_REG 0xFFFFFFFE
16 /* Frame buffer addresses greater than 0xFFFFFFFA indicate HW errors */
17 #define MGB4_ERR_QUEUE_TIMEOUT 0xFFFFFFFD
18 #define MGB4_ERR_QUEUE_EMPTY 0xFFFFFFFC
19 #define MGB4_ERR_QUEUE_FULL 0xFFFFFFFB
21 #define MGB4_PERIOD(numerator, denominator) \
22 ((u32)div_u64((MGB4_HW_FREQ * (u64)(numerator)), (denominator)))
24 struct mgb4_frame_buffer {
25 struct vb2_v4l2_buffer vb;
26 struct list_head list;
29 static inline struct mgb4_frame_buffer *to_frame_buffer(struct vb2_v4l2_buffer *vbuf)
31 return container_of(vbuf, struct mgb4_frame_buffer, vb);
34 static inline bool has_yuv_and_timeperframe(struct mgb4_regs *video)
36 u32 status = mgb4_read_reg(video, 0xD0);
38 return (status & (1U << 8));
41 #define has_yuv(video) has_yuv_and_timeperframe(video)
42 #define has_timeperframe(video) has_yuv_and_timeperframe(video)
44 static inline u32 pixel_size(struct v4l2_dv_timings *timings)
46 struct v4l2_bt_timings *bt = &timings->bt;
48 u32 height = bt->height + bt->vfrontporch + bt->vsync + bt->vbackporch;
49 u32 width = bt->width + bt->hfrontporch + bt->hsync + bt->hbackporch;
51 return width * height;