1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * Support for Intel Camera Imaging ISP subsystem.
4  * Copyright (c) 2015, Intel Corporation.
5  *
6  * This program is free software; you can redistribute it and/or modify it
7  * under the terms and conditions of the GNU General Public License,
8  * version 2, as published by the Free Software Foundation.
9  *
10  * This program is distributed in the hope it will be useful, but WITHOUT
11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
13  * more details.
14  */
15 
16 #ifndef __IA_CSS_CTC_TYPES_H
17 #define __IA_CSS_CTC_TYPES_H
18 
19 #include <linux/bitops.h>
20 
21 /* @file
22 * CSS-API header file for Chroma Tone Control parameters.
23 */
24 
25 /* Fractional bits for CTC gain (used only for ISP1).
26  *
27  *  IA_CSS_CTC_COEF_SHIFT(=13) includes not only the fractional bits
28  *  of gain(=8), but also the bits(=5) to convert chroma
29  *  from 13bit precision to 8bit precision.
30  *
31  *    Gain (struct ia_css_ctc_table) : u5.8
32  *    Input(Chorma) : s0.12 (13bit precision)
33  *    Output(Chorma): s0.7  (8bit precision)
34  *    Output = (Input * Gain) >> IA_CSS_CTC_COEF_SHIFT
35  */
36 #define IA_CSS_CTC_COEF_SHIFT          13
37 
38 /* Number of elements in the CTC table. */
39 #define IA_CSS_VAMEM_1_CTC_TABLE_SIZE_LOG2      10
40 /* Number of elements in the CTC table. */
41 #define IA_CSS_VAMEM_1_CTC_TABLE_SIZE           BIT(IA_CSS_VAMEM_1_CTC_TABLE_SIZE_LOG2)
42 
43 /* Number of elements in the CTC table. */
44 #define IA_CSS_VAMEM_2_CTC_TABLE_SIZE_LOG2      8
45 /* Number of elements in the CTC table. */
46 #define IA_CSS_VAMEM_2_CTC_TABLE_SIZE           ((1U << IA_CSS_VAMEM_2_CTC_TABLE_SIZE_LOG2) + 1)
47 
48 enum ia_css_vamem_type {
49 	IA_CSS_VAMEM_TYPE_1,
50 	IA_CSS_VAMEM_TYPE_2
51 };
52 
53 /* Chroma Tone Control configuration.
54  *
55  *  ISP block: CTC2 (CTC by polygonal line approximation)
56  * (ISP1: CTC1 (CTC by look-up table) is used.)
57  *  ISP2: CTC2 is used.
58  */
59 struct ia_css_ctc_config {
60 	u16 y0;	/** 1st kneepoint gain.
61 				u[ce_gain_exp].[13-ce_gain_exp], [0,8191],
62 				default/ineffective 4096(0.5) */
63 	u16 y1;	/** 2nd kneepoint gain.
64 				u[ce_gain_exp].[13-ce_gain_exp], [0,8191],
65 				default/ineffective 4096(0.5) */
66 	u16 y2;	/** 3rd kneepoint gain.
67 				u[ce_gain_exp].[13-ce_gain_exp], [0,8191],
68 				default/ineffective 4096(0.5) */
69 	u16 y3;	/** 4th kneepoint gain.
70 				u[ce_gain_exp].[13-ce_gain_exp], [0,8191],
71 				default/ineffective 4096(0.5) */
72 	u16 y4;	/** 5th kneepoint gain.
73 				u[ce_gain_exp].[13-ce_gain_exp], [0,8191],
74 				default/ineffective 4096(0.5) */
75 	u16 y5;	/** 6th kneepoint gain.
76 				u[ce_gain_exp].[13-ce_gain_exp], [0,8191],
77 				default/ineffective 4096(0.5) */
78 	u16 ce_gain_exp;	/** Common exponent of y-axis gain.
79 				u8.0, [0,13],
80 				default/ineffective 1 */
81 	u16 x1;	/** 2nd kneepoint luma.
82 				u0.13, [0,8191], constraints: 0<x1<x2,
83 				default/ineffective 1024 */
84 	u16 x2;	/** 3rd kneepoint luma.
85 				u0.13, [0,8191], constraints: x1<x2<x3,
86 				default/ineffective 2048 */
87 	u16 x3;	/** 4th kneepoint luma.
88 				u0.13, [0,8191], constraints: x2<x3<x4,
89 				default/ineffective 6144 */
90 	u16 x4;	/** 5tn kneepoint luma.
91 				u0.13, [0,8191], constraints: x3<x4<8191,
92 				default/ineffective 7168 */
93 };
94 
95 union ia_css_ctc_data {
96 	u16 vamem_1[IA_CSS_VAMEM_1_CTC_TABLE_SIZE];
97 	u16 vamem_2[IA_CSS_VAMEM_2_CTC_TABLE_SIZE];
98 };
99 
100 /* CTC table, used for Chroma Tone Control.
101  *
102  *  ISP block: CTC1 (CTC by look-up table)
103  *  ISP1: CTC1 is used.
104  * (ISP2: CTC2 (CTC by polygonal line approximation) is used.)
105  */
106 struct ia_css_ctc_table {
107 	enum ia_css_vamem_type vamem_type;
108 	union ia_css_ctc_data data;
109 };
110 
111 #endif /* __IA_CSS_CTC_TYPES_H */
112