xref: /linux/drivers/media/platform/raspberrypi/rp1-cfe/csi2.h (revision 7f71507851fc7764b36a3221839607d3a45c2025)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * RP1 CSI-2 Driver
4  *
5  * Copyright (c) 2021-2024 Raspberry Pi Ltd.
6  * Copyright (c) 2023-2024 Ideas on Board Oy
7  */
8 
9 #ifndef _RP1_CSI2_
10 #define _RP1_CSI2_
11 
12 #include <linux/debugfs.h>
13 #include <linux/io.h>
14 #include <linux/types.h>
15 #include <media/v4l2-device.h>
16 #include <media/v4l2-subdev.h>
17 
18 #include "dphy.h"
19 
20 #define CSI2_NUM_CHANNELS 4
21 
22 #define CSI2_PAD_SINK 0
23 #define CSI2_PAD_FIRST_SOURCE 1
24 #define CSI2_PAD_NUM_SOURCES 4
25 #define CSI2_NUM_PADS 5
26 
27 #define DISCARDS_TABLE_NUM_VCS 4
28 
29 enum csi2_mode {
30 	CSI2_MODE_NORMAL = 0,
31 	CSI2_MODE_REMAP = 1,
32 	CSI2_MODE_COMPRESSED = 2,
33 	CSI2_MODE_FE_STREAMING = 3,
34 };
35 
36 enum csi2_compression_mode {
37 	CSI2_COMPRESSION_DELTA = 1,
38 	CSI2_COMPRESSION_SIMPLE = 2,
39 	CSI2_COMPRESSION_COMBINED = 3,
40 };
41 
42 enum discards_table_index {
43 	DISCARDS_TABLE_OVERFLOW = 0,
44 	DISCARDS_TABLE_LENGTH_LIMIT,
45 	DISCARDS_TABLE_UNMATCHED,
46 	DISCARDS_TABLE_INACTIVE,
47 	DISCARDS_TABLE_NUM_ENTRIES,
48 };
49 
50 struct csi2_device {
51 	/* Parent V4l2 device */
52 	struct v4l2_device *v4l2_dev;
53 
54 	void __iomem *base;
55 
56 	struct dphy_data dphy;
57 
58 	enum v4l2_mbus_type bus_type;
59 	unsigned int bus_flags;
60 	unsigned int num_lines[CSI2_NUM_CHANNELS];
61 
62 	struct media_pad pad[CSI2_NUM_PADS];
63 	struct v4l2_subdev sd;
64 
65 	/* lock for csi2 errors counters */
66 	spinlock_t errors_lock;
67 	u32 overflows;
68 	u32 discards_table[DISCARDS_TABLE_NUM_VCS][DISCARDS_TABLE_NUM_ENTRIES];
69 	u32 discards_dt_table[DISCARDS_TABLE_NUM_ENTRIES];
70 };
71 
72 void csi2_isr(struct csi2_device *csi2, bool *sof, bool *eof);
73 void csi2_set_buffer(struct csi2_device *csi2, unsigned int channel,
74 		     dma_addr_t dmaaddr, unsigned int stride,
75 		     unsigned int size);
76 void csi2_set_compression(struct csi2_device *csi2, unsigned int channel,
77 			  enum csi2_compression_mode mode, unsigned int shift,
78 			  unsigned int offset);
79 void csi2_start_channel(struct csi2_device *csi2, unsigned int channel,
80 			enum csi2_mode mode, bool auto_arm,
81 			bool pack_bytes, unsigned int width,
82 			unsigned int height, u8 vc, u8 dt);
83 void csi2_stop_channel(struct csi2_device *csi2, unsigned int channel);
84 void csi2_open_rx(struct csi2_device *csi2);
85 void csi2_close_rx(struct csi2_device *csi2);
86 int csi2_init(struct csi2_device *csi2, struct dentry *debugfs);
87 void csi2_uninit(struct csi2_device *csi2);
88 
89 #endif
90