1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  * Support for Intel Camera Imaging ISP subsystem.
4  * Copyright (c) 2010-2015, Intel Corporation.
5  */
6 
7 /* The name "gdc.h is already taken" */
8 #include "gdc_device.h"
9 
10 #include "device_access.h"
11 
12 #include "assert_support.h"
13 
14 /*
15  * Local function declarations
16  */
17 static inline void gdc_reg_store(
18     const gdc_ID_t		ID,
19     const unsigned int	reg,
20     const hrt_data		value);
21 
22 #ifndef __INLINE_GDC__
23 #include "gdc_private.h"
24 #endif /* __INLINE_GDC__ */
25 
26 /*
27  * Exported function implementations
28  */
gdc_lut_store(const gdc_ID_t ID,const int data[4][HRT_GDC_N])29 void gdc_lut_store(
30     const gdc_ID_t		ID,
31     const int			data[4][HRT_GDC_N])
32 {
33 	unsigned int i, lut_offset = HRT_GDC_LUT_IDX;
34 
35 	assert(ID < N_GDC_ID);
36 	assert(HRT_GDC_LUT_COEFF_OFFSET <= (4 * sizeof(hrt_data)));
37 
38 	for (i = 0; i < HRT_GDC_N; i++) {
39 		hrt_data	entry_0 = data[0][i] & HRT_GDC_BCI_COEF_MASK;
40 		hrt_data	entry_1 = data[1][i] & HRT_GDC_BCI_COEF_MASK;
41 		hrt_data	entry_2 = data[2][i] & HRT_GDC_BCI_COEF_MASK;
42 		hrt_data	entry_3 = data[3][i] & HRT_GDC_BCI_COEF_MASK;
43 
44 		hrt_data	word_0 = entry_0 |
45 				     (entry_1 << HRT_GDC_LUT_COEFF_OFFSET);
46 		hrt_data	word_1 = entry_2 |
47 				     (entry_3 << HRT_GDC_LUT_COEFF_OFFSET);
48 
49 		gdc_reg_store(ID, lut_offset++, word_0);
50 		gdc_reg_store(ID, lut_offset++, word_1);
51 	}
52 	return;
53 }
54 
55 /*
56  * Input LUT format:
57  * c0[0-1023], c1[0-1023], c2[0-1023] c3[0-1023]
58  *
59  * Output LUT format (interleaved):
60  * c0[0], c1[0], c2[0], c3[0], c0[1], c1[1], c2[1], c3[1], ....
61  * c0[1023], c1[1023], c2[1023], c3[1023]
62  *
63  * The first format needs c0[0], c1[0] (which are 1024 words apart)
64  * to program gdc LUT registers. This makes it difficult to do piecemeal
65  * reads in SP side gdc_lut_store
66  *
67  * Interleaved format allows use of contiguous bytes to store into
68  * gdc LUT registers.
69  *
70  * See gdc_lut_store() definition in host/gdc.c vs sp/gdc_private.h
71  *
72  */
gdc_lut_convert_to_isp_format(const int in_lut[4][HRT_GDC_N],int out_lut[4][HRT_GDC_N])73 void gdc_lut_convert_to_isp_format(const int in_lut[4][HRT_GDC_N],
74 				   int out_lut[4][HRT_GDC_N])
75 {
76 	unsigned int i;
77 	int *out = (int *)out_lut;
78 
79 	for (i = 0; i < HRT_GDC_N; i++) {
80 		out[0] = in_lut[0][i];
81 		out[1] = in_lut[1][i];
82 		out[2] = in_lut[2][i];
83 		out[3] = in_lut[3][i];
84 		out += 4;
85 	}
86 }
87 
gdc_get_unity(const gdc_ID_t ID)88 int gdc_get_unity(
89     const gdc_ID_t		ID)
90 {
91 	assert(ID < N_GDC_ID);
92 	(void)ID;
93 	return (int)(1UL << HRT_GDC_FRAC_BITS);
94 }
95 
96 /*
97  * Local function implementations
98  */
gdc_reg_store(const gdc_ID_t ID,const unsigned int reg,const hrt_data value)99 static inline void gdc_reg_store(
100     const gdc_ID_t		ID,
101     const unsigned int	reg,
102     const hrt_data		value)
103 {
104 	ia_css_device_store_uint32(GDC_BASE[ID] + reg * sizeof(hrt_data), value);
105 	return;
106 }
107