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 #ifndef __IA_CSS_ISYS_H__
8 #define __IA_CSS_ISYS_H__
9 
10 #include <type_support.h>
11 #include <input_system.h>
12 #include <ia_css_input_port.h>
13 #include <ia_css_stream_format.h>
14 #include <ia_css_stream_public.h>
15 #include <system_global.h>
16 #include "ia_css_isys_comm.h"
17 
18 /**
19  * Virtual Input System. (Input System 2401)
20  */
21 typedef isp2401_input_system_cfg_t	ia_css_isys_descr_t;
22 /* end of Virtual Input System */
23 
24 
25 input_system_err_t ia_css_isys_init(void);
26 void ia_css_isys_uninit(void);
27 enum mipi_port_id ia_css_isys_port_to_mipi_port(
28     enum mipi_port_id api_port);
29 
30 
31 /**
32  * @brief Register one (virtual) stream. This is used to track when all
33  * virtual streams are configured inside the input system. The CSI RX is
34  * only started when all registered streams are configured.
35  *
36  * @param[in]	port		CSI port
37  * @param[in]	isys_stream_id	Stream handle generated with ia_css_isys_generate_stream_id()
38  *				Must be lower than SH_CSS_MAX_ISYS_CHANNEL_NODES
39  * @return			0 if successful, -EINVAL if
40  *				there is already a stream registered with the same handle
41  */
42 int ia_css_isys_csi_rx_register_stream(
43     enum mipi_port_id port,
44     uint32_t isys_stream_id);
45 
46 /**
47  * @brief Unregister one (virtual) stream. This is used to track when all
48  * virtual streams are configured inside the input system. The CSI RX is
49  * only started when all registered streams are configured.
50  *
51  * @param[in]	port		CSI port
52  * @param[in]	isys_stream_id	Stream handle generated with ia_css_isys_generate_stream_id()
53  *				Must be lower than SH_CSS_MAX_ISYS_CHANNEL_NODES
54  * @return			0 if successful, -EINVAL if
55  *				there is no stream registered with that handle
56  */
57 int ia_css_isys_csi_rx_unregister_stream(
58     enum mipi_port_id port,
59     uint32_t isys_stream_id);
60 
61 int ia_css_isys_convert_compressed_format(
62     struct ia_css_csi2_compression *comp,
63     struct isp2401_input_system_cfg_s *cfg);
64 unsigned int ia_css_csi2_calculate_input_system_alignment(
65     enum atomisp_input_format fmt_type);
66 
67 /* CSS Receiver */
68 void ia_css_isys_rx_configure(
69     const rx_cfg_t *config,
70     const enum ia_css_input_mode input_mode);
71 
72 void ia_css_isys_rx_disable(void);
73 
74 void ia_css_isys_rx_enable_all_interrupts(enum mipi_port_id port);
75 
76 unsigned int ia_css_isys_rx_get_interrupt_reg(enum mipi_port_id port);
77 void ia_css_isys_rx_get_irq_info(enum mipi_port_id port,
78 				 unsigned int *irq_infos);
79 void ia_css_isys_rx_clear_irq_info(enum mipi_port_id port,
80 				   unsigned int irq_infos);
81 unsigned int ia_css_isys_rx_translate_irq_infos(unsigned int bits);
82 
83 
84 /* @brief Translate format and compression to format type.
85  *
86  * @param[in]	input_format	The input format.
87  * @param[in]	compression	The compression scheme.
88  * @param[out]	fmt_type	Pointer to the resulting format type.
89  * @return			Error code.
90  *
91  * Translate an input format and mipi compression pair to the fmt_type.
92  * This is normally done by the sensor, but when using the input fifo, this
93  * format type must be sumitted correctly by the application.
94  */
95 int ia_css_isys_convert_stream_format_to_mipi_format(
96     enum atomisp_input_format input_format,
97     mipi_predictor_t compression,
98     unsigned int *fmt_type);
99 
100 /**
101  * Virtual Input System. (Input System 2401)
102  */
103 ia_css_isys_error_t ia_css_isys_stream_create(
104     ia_css_isys_descr_t	*isys_stream_descr,
105     ia_css_isys_stream_h	isys_stream,
106     uint32_t isys_stream_id);
107 
108 void ia_css_isys_stream_destroy(
109     ia_css_isys_stream_h	isys_stream);
110 
111 ia_css_isys_error_t ia_css_isys_stream_calculate_cfg(
112     ia_css_isys_stream_h		isys_stream,
113     ia_css_isys_descr_t		*isys_stream_descr,
114     ia_css_isys_stream_cfg_t	*isys_stream_cfg);
115 
116 void ia_css_isys_csi_rx_lut_rmgr_init(void);
117 
118 void ia_css_isys_csi_rx_lut_rmgr_uninit(void);
119 
120 bool ia_css_isys_csi_rx_lut_rmgr_acquire(
121     csi_rx_backend_ID_t		backend,
122     csi_mipi_packet_type_t		packet_type,
123     csi_rx_backend_lut_entry_t	*entry);
124 
125 void ia_css_isys_csi_rx_lut_rmgr_release(
126     csi_rx_backend_ID_t		backend,
127     csi_mipi_packet_type_t		packet_type,
128     csi_rx_backend_lut_entry_t	*entry);
129 
130 void ia_css_isys_ibuf_rmgr_init(void);
131 
132 void ia_css_isys_ibuf_rmgr_uninit(void);
133 
134 bool ia_css_isys_ibuf_rmgr_acquire(
135     u32	size,
136     uint32_t	*start_addr);
137 
138 void ia_css_isys_ibuf_rmgr_release(
139     uint32_t	*start_addr);
140 
141 void ia_css_isys_dma_channel_rmgr_init(void);
142 
143 void ia_css_isys_dma_channel_rmgr_uninit(void);
144 
145 bool ia_css_isys_dma_channel_rmgr_acquire(
146     isys2401_dma_ID_t	dma_id,
147     isys2401_dma_channel	*channel);
148 
149 void ia_css_isys_dma_channel_rmgr_release(
150     isys2401_dma_ID_t	dma_id,
151     isys2401_dma_channel	*channel);
152 
153 void ia_css_isys_stream2mmio_sid_rmgr_init(void);
154 
155 void ia_css_isys_stream2mmio_sid_rmgr_uninit(void);
156 
157 bool ia_css_isys_stream2mmio_sid_rmgr_acquire(
158     stream2mmio_ID_t	stream2mmio,
159     stream2mmio_sid_ID_t	*sid);
160 
161 void ia_css_isys_stream2mmio_sid_rmgr_release(
162     stream2mmio_ID_t	stream2mmio,
163     stream2mmio_sid_ID_t	*sid);
164 
165 /* end of Virtual Input System */
166 
167 #endif				/* __IA_CSS_ISYS_H__ */
168