1 /* SPDX-License-Identifier: GPL-2.0 */
2 /* Copyright (C) 2013 - 2020 Intel Corporation */
7 #include <linux/pm_qos.h>
8 #include <linux/spinlock.h>
10 #include <media/v4l2-device.h>
11 #include <media/media-device.h>
13 #include <uapi/linux/ipu-isys.h>
16 #include "ipu-isys-media.h"
17 #include "ipu-isys-csi2.h"
18 #include "ipu-isys-csi2-be.h"
19 #include "ipu-isys-video.h"
20 #include "ipu-pdata.h"
21 #include "ipu-fw-isys.h"
22 #include "ipu-platform-isys.h"
24 #define IPU_ISYS_2600_MEM_LINE_ALIGN 64
27 #define IPU_ISYS_FREQ 533000000UL
30 * Current message queue configuration. These must be big enough
31 * so that they never gets full. Queues are located in system memory
33 #define IPU_ISYS_SIZE_RECV_QUEUE 40
34 #define IPU_ISYS_SIZE_SEND_QUEUE 40
35 #define IPU_ISYS_SIZE_PROXY_RECV_QUEUE 5
36 #define IPU_ISYS_SIZE_PROXY_SEND_QUEUE 5
37 #define IPU_ISYS_NUM_RECV_QUEUE 1
40 * Device close takes some time from last ack message to actual stopping
41 * of the SP processor. As long as the SP processor runs we can't proceed with
42 * clean up of resources.
44 #define IPU_ISYS_OPEN_TIMEOUT_US 1000
45 #define IPU_ISYS_OPEN_RETRY 1000
46 #define IPU_ISYS_TURNOFF_DELAY_US 1000
47 #define IPU_ISYS_TURNOFF_TIMEOUT 1000
48 #define IPU_LIB_CALL_TIMEOUT_JIFFIES \
49 msecs_to_jiffies(IPU_LIB_CALL_TIMEOUT_MS)
51 #define IPU_ISYS_CSI2_LONG_PACKET_HEADER_SIZE 32
52 #define IPU_ISYS_CSI2_LONG_PACKET_FOOTER_SIZE 32
54 #define IPU_ISYS_MIN_WIDTH 1U
55 #define IPU_ISYS_MIN_HEIGHT 1U
56 #define IPU_ISYS_MAX_WIDTH 16384U
57 #define IPU_ISYS_MAX_HEIGHT 16384U
59 #define NR_OF_CSI2_BE_SOC_DEV 1
61 /* the threshold granularity is 2KB on IPU6 */
62 #define IPU6_SRAM_GRANULRITY_SHIFT 11
63 #define IPU6_SRAM_GRANULRITY_SIZE 2048
64 /* the threshold granularity is 1KB on IPU6SE */
65 #define IPU6SE_SRAM_GRANULRITY_SHIFT 10
66 #define IPU6SE_SRAM_GRANULRITY_SIZE 1024
91 struct isys_iwake_watermark
{
93 bool force_iwake_disable
;
95 u64 isys_pixelbuffer_datarate
;
96 struct ltr_did ltrdid
;
97 struct mutex mutex
; /* protect whole struct */
98 struct ipu_isys
*isys
;
99 struct list_head video_list
;
101 struct ipu_isys_sensor_info
{
102 unsigned int vc1_data_start
;
103 unsigned int vc1_data_end
;
104 unsigned int vc0_data_start
;
105 unsigned int vc0_data_end
;
106 unsigned int vc1_pdaf_start
;
107 unsigned int vc1_pdaf_end
;
108 unsigned int sensor_metadata
;
114 * @media_dev: Media device
115 * @v4l2_dev: V4L2 device
116 * @adev: ISYS bus device
117 * @power: Is ISYS powered on or not?
118 * @isr_bits: Which bits does the ISR handle?
119 * @power_lock: Serialise access to power (power state in general)
120 * @csi2_rx_ctrl_cached: cached shared value between all CSI2 receivers
121 * @lock: serialise access to pipes
122 * @pipes: pipelines per stream ID
123 * @fwcom: fw communication layer private pointer
124 * or optional external library private pointer
125 * @line_align: line alignment in memory
126 * @reset_needed: Isys requires d0i0->i3 transition
127 * @video_opened: total number of opened file handles on video nodes
128 * @mutex: serialise access isys video open/release related operations
129 * @stream_mutex: serialise stream start and stop, queueing requests
130 * @lib_mutex: optional external library mutex
131 * @pdata: platform data pointer
132 * @csi2: CSI-2 receivers
133 * @csi2_be: CSI-2 back-ends
134 * @fw: ISYS firmware binary (unsecure firmware)
135 * @fw_sgt: fw scatterlist
136 * @pkg_dir: host pointer to pkg_dir
137 * @pkg_dir_dma_addr: I/O virtual address for pkg_dir
138 * @pkg_dir_size: size of pkg_dir in bytes
139 * @short_packet_source: select short packet capture mode
142 struct media_device media_dev
;
143 struct v4l2_device v4l2_dev
;
144 struct ipu_bus_device
*adev
;
147 spinlock_t power_lock
; /* Serialise access to power */
149 u32 csi2_rx_ctrl_cached
;
150 spinlock_t lock
; /* Serialise access to pipes */
151 struct ipu_isys_pipeline
*pipes
[IPU_ISYS_MAX_STREAMS
];
153 unsigned int line_align
;
155 bool icache_prefetch
;
156 bool csi2_cse_ipc_not_supported
;
157 unsigned int video_opened
;
158 unsigned int stream_opened
;
159 struct ipu_isys_sensor_info sensor_info
;
160 unsigned int sensor_types
[N_IPU_FW_ISYS_SENSOR_TYPE
];
162 #ifdef CONFIG_DEBUG_FS
163 struct dentry
*debugfsdir
;
165 struct mutex mutex
; /* Serialise isys video open/release related */
166 struct mutex stream_mutex
; /* Stream start, stop, queueing reqs */
167 struct mutex lib_mutex
; /* Serialise optional external library mutex */
169 struct ipu_isys_pdata
*pdata
;
171 struct ipu_isys_csi2
*csi2
;
172 struct ipu_isys_csi2_be csi2_be
;
173 struct ipu_isys_csi2_be_soc csi2_be_soc
[NR_OF_CSI2_BE_SOC_DEV
];
174 const struct firmware
*fw
;
175 struct sg_table fw_sgt
;
178 dma_addr_t pkg_dir_dma_addr
;
179 unsigned int pkg_dir_size
;
181 struct list_head requests
;
182 struct pm_qos_request pm_qos
;
183 unsigned int short_packet_source
;
184 struct ipu_isys_csi2_monitor_message
*short_packet_trace_buffer
;
185 dma_addr_t short_packet_trace_buffer_dma_addr
;
186 unsigned int short_packet_tracing_count
;
187 struct mutex short_packet_tracing_mutex
; /* For tracing count */
189 u64 tunit_timer_base
;
190 spinlock_t listlock
; /* Protect framebuflist */
191 struct list_head framebuflist
;
192 struct list_head framebuflist_fw
;
193 struct v4l2_async_notifier notifier
;
194 struct isys_iwake_watermark
*iwake_watermark
;
198 void update_watermark_setting(struct ipu_isys
*isys
);
200 struct isys_fw_msgs
{
203 struct ipu_fw_isys_frame_buff_set_abi frame
;
204 struct ipu_fw_isys_stream_cfg_data_abi stream
;
206 struct list_head head
;
210 #define to_frame_msg_buf(a) (&(a)->fw_msg.frame)
211 #define to_stream_cfg_msg_buf(a) (&(a)->fw_msg.stream)
212 #define to_dma_addr(a) ((a)->dma_addr)
214 struct isys_fw_msgs
*ipu_get_fw_msg_buf(struct ipu_isys_pipeline
*ip
);
215 void ipu_put_fw_mgs_buf(struct ipu_isys
*isys
, u64 data
);
216 void ipu_cleanup_fw_msg_bufs(struct ipu_isys
*isys
);
218 extern const struct v4l2_ioctl_ops ipu_isys_ioctl_ops
;
220 void isys_setup_hw(struct ipu_isys
*isys
);
221 int isys_isr_one(struct ipu_bus_device
*adev
);
222 int ipu_isys_isr_run(void *ptr
);
223 irqreturn_t
isys_isr(struct ipu_bus_device
*adev
);
225 int ipu_isys_gpc_init_debugfs(struct ipu_isys
*isys
);
228 #endif /* IPU_ISYS_H */