xref: /linux/drivers/media/platform/dreamchip/rppx1/rpp_module.h (revision f4cdf7ca9a1fdcca413157df19753f388a5a224e)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * Copyright (C) 2026 Renesas Electronics Corp.
4  * Copyright (C) 2026 Ideas on Board Oy
5  * Copyright (C) 2026 Ragnatech AB
6  */
7 
8 #ifndef __RPPX1_MODULE_H__
9 #define __RPPX1_MODULE_H__
10 
11 #include <linux/errno.h>
12 #include <linux/types.h>
13 #include <linux/v4l2-mediabus.h>
14 
15 #include <linux/media/dreamchip/rppx1-config.h>
16 
17 #include <media/rppx1.h>
18 
19 struct rpp_module_ops;
20 
21 enum rpp_raw_pattern {
22 	RPP_RGGB = 0,
23 	RPP_GRBG,
24 	RPP_GBRG,
25 	RPP_BGGR,
26 };
27 
28 struct rpp_module {
29 	struct rppx1 *rpp;
30 	u32 base;
31 
32 	const struct rpp_module_ops *ops;
33 
34 	union {
35 		struct {
36 			enum rpp_raw_pattern raw_pattern;
37 		} acq;
38 	} info;
39 };
40 
41 int rpp_module_probe(struct rpp_module *mod, struct rppx1 *rpp,
42 		     const struct rpp_module_ops *ops, u32 base);
43 
44 void rpp_module_write(struct rpp_module *mod, u32 offset, u32 value);
45 u32 rpp_module_read(struct rpp_module *mod, u32 offset);
46 void rpp_module_clrset(struct rpp_module *mod, u32 offset, u32 mask, u32 value);
47 
48 union rppx1_params_block {
49 	struct v4l2_isp_block_header header;
50 	struct rppx1_bls_params bls;
51 	struct rppx1_lin_params lin;
52 	struct rppx1_lsc_params lsc;
53 	struct rppx1_awbg_params awbg;
54 	struct rppx1_ccor_params ccor;
55 	struct rppx1_hist_params hist;
56 	struct rppx1_exm_params exm;
57 	struct rppx1_wbmeas_params wbmeas;
58 	struct rppx1_ga_params ga;
59 };
60 
61 union rppx1_stats_block {
62 	struct v4l2_isp_block_header header;
63 	struct rppx1_hist_stats hist;
64 	struct rppx1_exm_stats exm;
65 	struct rppx1_wbmeas_stats wbmeas;
66 };
67 
68 struct rpp_module_ops {
69 	int (*probe)(struct rpp_module *mod);
70 	int (*start)(struct rpp_module *mod, const struct v4l2_mbus_framefmt *fmt);
71 
72 	int (*fill_params)(struct rpp_module *mod,
73 			   const union rppx1_params_block *block,
74 			   rppx1_reg_write write, void *priv);
75 	int (*fill_stats)(struct rpp_module *mod,
76 			  union rppx1_stats_block *block);
77 };
78 
79 extern const struct rpp_module_ops rppx1_acq_ops;
80 extern const struct rpp_module_ops rppx1_awbg_ops;
81 extern const struct rpp_module_ops rppx1_bd_ops;
82 extern const struct rpp_module_ops rppx1_bdrgb_ops;
83 extern const struct rpp_module_ops rppx1_bls_ops;
84 extern const struct rpp_module_ops rppx1_cac_ops;
85 extern const struct rpp_module_ops rppx1_ccor_ops;
86 extern const struct rpp_module_ops rppx1_ccor_csm_ops;
87 extern const struct rpp_module_ops rppx1_db_ops;
88 extern const struct rpp_module_ops rppx1_dpcc_ops;
89 extern const struct rpp_module_ops rppx1_exm_ops;
90 extern const struct rpp_module_ops rppx1_ga_ops;
91 extern const struct rpp_module_ops rppx1_hist256_ops;
92 extern const struct rpp_module_ops rppx1_hist_ops;
93 extern const struct rpp_module_ops rppx1_is_ops;
94 extern const struct rpp_module_ops rppx1_lin_ops;
95 extern const struct rpp_module_ops rppx1_lsc_ops;
96 extern const struct rpp_module_ops rppx1_ltm_ops;
97 extern const struct rpp_module_ops rppx1_ltmmeas_ops;
98 extern const struct rpp_module_ops rppx1_outif_ops;
99 extern const struct rpp_module_ops rppx1_outregs_ops;
100 extern const struct rpp_module_ops rppx1_rmapmeas_ops;
101 extern const struct rpp_module_ops rppx1_rmap_ops;
102 extern const struct rpp_module_ops rppx1_shrp_ops;
103 extern const struct rpp_module_ops rppx1_wbmeas_ops;
104 extern const struct rpp_module_ops rppx1_xyz2luv_ops;
105 
106 #define rpp_module_call(mod, op, args...)				\
107 	({								\
108 		struct rpp_module *__mod = (mod);			\
109 		int __result;						\
110 		if (!__mod)						\
111 			__result = -ENODEV;				\
112 		else if (!__mod->ops->op)				\
113 			__result = 0;					\
114 		else							\
115 			__result = __mod->ops->op(__mod, ##args);	\
116 		__result;						\
117 	})
118 
119 #endif /* __RPPX1_MODULE_H__ */
120