aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media/pci/intel/ipu-isys-subdev.h
blob: 6d501c995539d0884d232029ea104be5520386ce (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
/* SPDX-License-Identifier: GPL-2.0 */
/* Copyright (C) 2013 - 2020 Intel Corporation */

#ifndef IPU_ISYS_SUBDEV_H
#define IPU_ISYS_SUBDEV_H

#include <linux/mutex.h>

#include <media/media-entity.h>
#include <media/v4l2-device.h>
#include <media/v4l2-ctrls.h>

#include "ipu-isys-queue.h"

#define IPU_ISYS_MIPI_CSI2_TYPE_NULL	0x10
#define IPU_ISYS_MIPI_CSI2_TYPE_BLANKING	0x11
#define IPU_ISYS_MIPI_CSI2_TYPE_EMBEDDED8	0x12
#define IPU_ISYS_MIPI_CSI2_TYPE_YUV422_8	0x1e
#define IPU_ISYS_MIPI_CSI2_TYPE_YUV422_10	0x1f
#define IPU_ISYS_MIPI_CSI2_TYPE_RGB565	0x22
#define IPU_ISYS_MIPI_CSI2_TYPE_RGB888	0x24
#define IPU_ISYS_MIPI_CSI2_TYPE_RAW6	0x28
#define IPU_ISYS_MIPI_CSI2_TYPE_RAW7	0x29
#define IPU_ISYS_MIPI_CSI2_TYPE_RAW8	0x2a
#define IPU_ISYS_MIPI_CSI2_TYPE_RAW10	0x2b
#define IPU_ISYS_MIPI_CSI2_TYPE_RAW12	0x2c
#define IPU_ISYS_MIPI_CSI2_TYPE_RAW14	0x2d
/* 1-8 */
#define IPU_ISYS_MIPI_CSI2_TYPE_USER_DEF(i)	(0x30 + (i) - 1)

#define FMT_ENTRY (struct ipu_isys_fmt_entry [])

enum isys_subdev_prop_tgt {
	IPU_ISYS_SUBDEV_PROP_TGT_SINK_FMT,
	IPU_ISYS_SUBDEV_PROP_TGT_SINK_CROP,
	IPU_ISYS_SUBDEV_PROP_TGT_SINK_COMPOSE,
	IPU_ISYS_SUBDEV_PROP_TGT_SOURCE_COMPOSE,
	IPU_ISYS_SUBDEV_PROP_TGT_SOURCE_CROP,
};

#define	IPU_ISYS_SUBDEV_PROP_TGT_NR_OF \
	(IPU_ISYS_SUBDEV_PROP_TGT_SOURCE_CROP + 1)

enum ipu_isl_mode {
	IPU_ISL_OFF = 0,	/* SOC BE */
	IPU_ISL_CSI2_BE,	/* RAW BE */
};

enum ipu_be_mode {
	IPU_BE_RAW = 0,
	IPU_BE_SOC
};

enum ipu_isys_subdev_pixelorder {
	IPU_ISYS_SUBDEV_PIXELORDER_BGGR = 0,
	IPU_ISYS_SUBDEV_PIXELORDER_GBRG,
	IPU_ISYS_SUBDEV_PIXELORDER_GRBG,
	IPU_ISYS_SUBDEV_PIXELORDER_RGGB,
};

struct ipu_isys;

struct ipu_isys_subdev {
	/* Serialise access to any other field in the struct */
	struct mutex mutex;
	struct v4l2_subdev sd;
	struct ipu_isys *isys;
	u32 const *const *supported_codes;
	struct media_pad *pad;
	struct v4l2_mbus_framefmt *ffmt;
	struct v4l2_rect *crop;
	struct v4l2_rect *compose;
	unsigned int nsinks;
	unsigned int nsources;
	struct v4l2_ctrl_handler ctrl_handler;
	void (*ctrl_init)(struct v4l2_subdev *sd);
	void (*set_ffmt)(struct v4l2_subdev *sd,
			 struct v4l2_subdev_pad_config *cfg,
			 struct v4l2_subdev_format *fmt);
	struct {
		bool crop;
		bool compose;
	} *valid_tgts;
	enum ipu_isl_mode isl_mode;
	enum ipu_be_mode be_mode;
	int source;	/* SSI stream source; -1 if unset */
};

#define to_ipu_isys_subdev(__sd) \
	container_of(__sd, struct ipu_isys_subdev, sd)

struct v4l2_mbus_framefmt *__ipu_isys_get_ffmt(struct v4l2_subdev *sd,
					       struct v4l2_subdev_pad_config
					       *cfg,
					       unsigned int pad,
					       unsigned int which);

unsigned int ipu_isys_mbus_code_to_bpp(u32 code);
unsigned int ipu_isys_mbus_code_to_mipi(u32 code);
u32 ipu_isys_subdev_code_to_uncompressed(u32 sink_code);

enum ipu_isys_subdev_pixelorder ipu_isys_subdev_get_pixelorder(u32 code);

int ipu_isys_subdev_fmt_propagate(struct v4l2_subdev *sd,
				  struct v4l2_subdev_pad_config *cfg,
				  struct v4l2_mbus_framefmt *ffmt,
				  struct v4l2_rect *r,
				  enum isys_subdev_prop_tgt tgt,
				  unsigned int pad, unsigned int which);

int ipu_isys_subdev_set_ffmt_default(struct v4l2_subdev *sd,
				     struct v4l2_subdev_pad_config *cfg,
				     struct v4l2_subdev_format *fmt);
int __ipu_isys_subdev_set_ffmt(struct v4l2_subdev *sd,
			       struct v4l2_subdev_pad_config *cfg,
			       struct v4l2_subdev_format *fmt);
struct v4l2_rect *__ipu_isys_get_selection(struct v4l2_subdev *sd,
					   struct v4l2_subdev_pad_config *cfg,
					   unsigned int target,
					   unsigned int pad,
					   unsigned int which);
int ipu_isys_subdev_set_ffmt(struct v4l2_subdev *sd,
			     struct v4l2_subdev_pad_config *cfg,
			     struct v4l2_subdev_format *fmt);
int ipu_isys_subdev_get_ffmt(struct v4l2_subdev *sd,
			     struct v4l2_subdev_pad_config *cfg,
			     struct v4l2_subdev_format *fmt);
int ipu_isys_subdev_get_sel(struct v4l2_subdev *sd,
			    struct v4l2_subdev_pad_config *cfg,
			    struct v4l2_subdev_selection *sel);
int ipu_isys_subdev_set_sel(struct v4l2_subdev *sd,
			    struct v4l2_subdev_pad_config *cfg,
			    struct v4l2_subdev_selection *sel);
int ipu_isys_subdev_enum_mbus_code(struct v4l2_subdev *sd,
				   struct v4l2_subdev_pad_config *cfg,
				   struct v4l2_subdev_mbus_code_enum
				   *code);
int ipu_isys_subdev_link_validate(struct v4l2_subdev *sd,
				  struct media_link *link,
				  struct v4l2_subdev_format *source_fmt,
				  struct v4l2_subdev_format *sink_fmt);

int ipu_isys_subdev_open(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh);
int ipu_isys_subdev_close(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh);

#define ISYS_SUBDEV_NO_PAD	(-1)

int ipu_isys_subdev_init(struct ipu_isys_subdev *asd,
			 struct v4l2_subdev_ops *ops,
			 unsigned int nr_ctrls,
			 unsigned int num_pads,
			 unsigned int num_source,
			 unsigned int num_sink,
			 unsigned int sd_flags,
			 int src_pad_idx,
			 int sink_pad_idx);
void ipu_isys_subdev_cleanup(struct ipu_isys_subdev *asd);
#endif /* IPU_ISYS_SUBDEV_H */