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