1 /*
2  * Support for Intel Camera Imaging ISP subsystem.
3  * Copyright (c) 2010 - 2015, Intel Corporation.
4  *
5  * This program is free software; you can redistribute it and/or modify it
6  * under the terms and conditions of the GNU General Public License,
7  * version 2, as published by the Free Software Foundation.
8  *
9  * This program is distributed in the hope it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
12  * more details.
13  */
14 
15 #ifndef __IA_CSS_ISYS_H__
16 #define __IA_CSS_ISYS_H__
17 
18 #include <type_support.h>
19 #include <input_system.h>
20 #include <ia_css_input_port.h>
21 #include <ia_css_stream_format.h>
22 #include <ia_css_stream_public.h>
23 #include <system_global.h>
24 #include "ia_css_isys_comm.h"
25 
26 #ifdef USE_INPUT_SYSTEM_VERSION_2401
27 /**
28  * Virtual Input System. (Input System 2401)
29  */
30 typedef input_system_cfg_t	ia_css_isys_descr_t;
31 /* end of Virtual Input System */
32 #endif
33 
34 #if defined(USE_INPUT_SYSTEM_VERSION_2) || defined(USE_INPUT_SYSTEM_VERSION_2401)
35 input_system_error_t ia_css_isys_init(void);
36 void ia_css_isys_uninit(void);
37 enum mipi_port_id ia_css_isys_port_to_mipi_port(
38     enum mipi_port_id api_port);
39 #endif
40 
41 #if defined(USE_INPUT_SYSTEM_VERSION_2401)
42 
43 /**
44  * @brief Register one (virtual) stream. This is used to track when all
45  * virtual streams are configured inside the input system. The CSI RX is
46  * only started when all registered streams are configured.
47  *
48  * @param[in]	port		CSI port
49  * @param[in]	isys_stream_id	Stream handle generated with ia_css_isys_generate_stream_id()
50  *				Must be lower than SH_CSS_MAX_ISYS_CHANNEL_NODES
51  * @return			0 if successful, -EINVAL if
52  *				there is already a stream registered with the same handle
53  */
54 int ia_css_isys_csi_rx_register_stream(
55     enum mipi_port_id port,
56     uint32_t isys_stream_id);
57 
58 /**
59  * @brief Unregister one (virtual) stream. This is used to track when all
60  * virtual streams are configured inside the input system. The CSI RX is
61  * only started when all registered streams are configured.
62  *
63  * @param[in]	port		CSI port
64  * @param[in]	isys_stream_id	Stream handle generated with ia_css_isys_generate_stream_id()
65  *				Must be lower than SH_CSS_MAX_ISYS_CHANNEL_NODES
66  * @return			0 if successful, -EINVAL if
67  *				there is no stream registered with that handle
68  */
69 int ia_css_isys_csi_rx_unregister_stream(
70     enum mipi_port_id port,
71     uint32_t isys_stream_id);
72 
73 int ia_css_isys_convert_compressed_format(
74     struct ia_css_csi2_compression *comp,
75     struct input_system_cfg_s *cfg);
76 unsigned int ia_css_csi2_calculate_input_system_alignment(
77     enum atomisp_input_format fmt_type);
78 #endif
79 
80 #if !defined(USE_INPUT_SYSTEM_VERSION_2401)
81 /* CSS Receiver */
82 void ia_css_isys_rx_configure(
83     const rx_cfg_t *config,
84     const enum ia_css_input_mode input_mode);
85 
86 void ia_css_isys_rx_disable(void);
87 
88 void ia_css_isys_rx_enable_all_interrupts(enum mipi_port_id port);
89 
90 unsigned int ia_css_isys_rx_get_interrupt_reg(enum mipi_port_id port);
91 void ia_css_isys_rx_get_irq_info(enum mipi_port_id port,
92 				 unsigned int *irq_infos);
93 void ia_css_isys_rx_clear_irq_info(enum mipi_port_id port,
94 				   unsigned int irq_infos);
95 unsigned int ia_css_isys_rx_translate_irq_infos(unsigned int bits);
96 
97 #endif /* #if !defined(USE_INPUT_SYSTEM_VERSION_2401) */
98 
99 /* @brief Translate format and compression to format type.
100  *
101  * @param[in]	input_format	The input format.
102  * @param[in]	compression	The compression scheme.
103  * @param[out]	fmt_type	Pointer to the resulting format type.
104  * @return			Error code.
105  *
106  * Translate an input format and mipi compression pair to the fmt_type.
107  * This is normally done by the sensor, but when using the input fifo, this
108  * format type must be sumitted correctly by the application.
109  */
110 int ia_css_isys_convert_stream_format_to_mipi_format(
111     enum atomisp_input_format input_format,
112     mipi_predictor_t compression,
113     unsigned int *fmt_type);
114 
115 #ifdef USE_INPUT_SYSTEM_VERSION_2401
116 /**
117  * Virtual Input System. (Input System 2401)
118  */
119 ia_css_isys_error_t ia_css_isys_stream_create(
120     ia_css_isys_descr_t	*isys_stream_descr,
121     ia_css_isys_stream_h	isys_stream,
122     uint32_t isys_stream_id);
123 
124 void ia_css_isys_stream_destroy(
125     ia_css_isys_stream_h	isys_stream);
126 
127 ia_css_isys_error_t ia_css_isys_stream_calculate_cfg(
128     ia_css_isys_stream_h		isys_stream,
129     ia_css_isys_descr_t		*isys_stream_descr,
130     ia_css_isys_stream_cfg_t	*isys_stream_cfg);
131 
132 void ia_css_isys_csi_rx_lut_rmgr_init(void);
133 
134 void ia_css_isys_csi_rx_lut_rmgr_uninit(void);
135 
136 bool ia_css_isys_csi_rx_lut_rmgr_acquire(
137     csi_rx_backend_ID_t		backend,
138     csi_mipi_packet_type_t		packet_type,
139     csi_rx_backend_lut_entry_t	*entry);
140 
141 void ia_css_isys_csi_rx_lut_rmgr_release(
142     csi_rx_backend_ID_t		backend,
143     csi_mipi_packet_type_t		packet_type,
144     csi_rx_backend_lut_entry_t	*entry);
145 
146 void ia_css_isys_ibuf_rmgr_init(void);
147 
148 void ia_css_isys_ibuf_rmgr_uninit(void);
149 
150 bool ia_css_isys_ibuf_rmgr_acquire(
151     u32	size,
152     uint32_t	*start_addr);
153 
154 void ia_css_isys_ibuf_rmgr_release(
155     uint32_t	*start_addr);
156 
157 void ia_css_isys_dma_channel_rmgr_init(void);
158 
159 void ia_css_isys_dma_channel_rmgr_uninit(void);
160 
161 bool ia_css_isys_dma_channel_rmgr_acquire(
162     isys2401_dma_ID_t	dma_id,
163     isys2401_dma_channel	*channel);
164 
165 void ia_css_isys_dma_channel_rmgr_release(
166     isys2401_dma_ID_t	dma_id,
167     isys2401_dma_channel	*channel);
168 
169 void ia_css_isys_stream2mmio_sid_rmgr_init(void);
170 
171 void ia_css_isys_stream2mmio_sid_rmgr_uninit(void);
172 
173 bool ia_css_isys_stream2mmio_sid_rmgr_acquire(
174     stream2mmio_ID_t	stream2mmio,
175     stream2mmio_sid_ID_t	*sid);
176 
177 void ia_css_isys_stream2mmio_sid_rmgr_release(
178     stream2mmio_ID_t	stream2mmio,
179     stream2mmio_sid_ID_t	*sid);
180 
181 /* end of Virtual Input System */
182 #endif
183 
184 #endif				/* __IA_CSS_ISYS_H__ */
185