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