xref: /linux/drivers/media/platform/dreamchip/rppx1/rppx1_rmap.c (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 #include "rpp_module.h"
9 
10 #define RMAP_DATA_VERSION_REG		0x0000
11 
12 #define RMAP_CTRL_REG			0x0004
13 #define RMAP_CTRL_BYPASS_LONG		BIT(2)
14 
15 #define RMAP_WBTHRESHOLD_LONG_REG	0x0008
16 #define RMAP_WBTHRESHOLD_SHORT_REG	0x000c
17 #define RMAP_RESERVED_1_REG		0x0010
18 #define RMAP_WBGAIN_LONG_RED_REG	0x0014
19 #define RMAP_WBGAIN_LONG_BLUE_REG	0x0018
20 #define RMAP_WBGAIN_SHORT_RED_REG	0x001c
21 #define RMAP_WBGAIN_SHORT_BLUE_REG	0x0020
22 #define RMAP_RESERVED_2_REG		0x0024
23 #define RMAP_RESERVED_3_REG		0x0028
24 #define RMAP_MAP_FAC_SHORT_REG		0x002c
25 #define RMAP_RESERVED_4_REG		0x0030
26 #define RMAP_MIN_THRES_SHORT_REG	0x0034
27 #define RMAP_MAX_THRES_SHORT_REG	0x0038
28 #define RMAP_STEPSIZE_SHORT_REG		0x003c
29 #define RMAP_MIN_THRES_LONG_REG		0x0040
30 #define RMAP_MAX_THRES_LONG_REG		0x0044
31 #define RMAP_STEPSIZE_LONG_REG		0x0048
32 #define RMAP_CLB_LINESIZE_REG		0x004c
33 
34 static int rppx1_rmap_probe(struct rpp_module *mod)
35 {
36 	/* Version check. */
37 	switch (rpp_module_read(mod, RMAP_DATA_VERSION_REG)) {
38 	case 8:
39 		/* low: 12-bit, high: 20-bit. */
40 		break;
41 	case 9:
42 		/* low: 12-bit, high: 24-bit. */
43 		break;
44 	default:
45 		return -EINVAL;
46 	}
47 
48 	return 0;
49 }
50 
51 static int rppx1_rmap_start(struct rpp_module *mod,
52 			    const struct v4l2_mbus_framefmt *fmt)
53 {
54 	/* Bypass radiance mapping and use the long exposure channel (PRE1). */
55 	rpp_module_write(mod, RMAP_CTRL_REG, RMAP_CTRL_BYPASS_LONG);
56 
57 	return 0;
58 }
59 
60 const struct rpp_module_ops rppx1_rmap_ops = {
61 	.probe = rppx1_rmap_probe,
62 	.start = rppx1_rmap_start,
63 };
64