1 /* SPDX-License-Identifier: GPL-2.0-only */
3 * Samsung EXYNOS4x12 FIMC-IS (Imaging Subsystem) driver
5 * Copyright (C) 2013 Samsung Electronics Co., Ltd.
7 * Authors: Younghwan Joo <yhwan.joo@samsung.com>
8 * Sylwester Nawrocki <s.nawrocki@samsung.com>
13 #include <asm/barrier.h>
14 #include <linux/clk.h>
15 #include <linux/device.h>
16 #include <linux/kernel.h>
17 #include <linux/platform_device.h>
18 #include <linux/sizes.h>
19 #include <linux/spinlock.h>
20 #include <linux/types.h>
21 #include <media/videobuf2-v4l2.h>
22 #include <media/v4l2-ctrls.h>
25 #include "fimc-is-command.h"
26 #include "fimc-is-sensor.h"
27 #include "fimc-is-param.h"
28 #include "fimc-is-regs.h"
30 #define FIMC_IS_DRV_NAME "exynos4-fimc-is"
32 #define FIMC_IS_FW_FILENAME "exynos4_fimc_is_fw.bin"
33 #define FIMC_IS_SETFILE_6A3 "exynos4_s5k6a3_setfile.bin"
35 #define FIMC_IS_FW_LOAD_TIMEOUT 1000 /* ms */
36 #define FIMC_IS_POWER_ON_TIMEOUT 1000 /* us */
38 #define FIMC_IS_SENSORS_NUM 2
40 /* Memory definitions */
41 #define FIMC_IS_CPU_MEM_SIZE (0xa00000)
42 #define FIMC_IS_CPU_BASE_MASK ((1 << 26) - 1)
43 #define FIMC_IS_REGION_SIZE 0x5000
45 #define FIMC_IS_DEBUG_REGION_OFFSET 0x0084b000
46 #define FIMC_IS_SHARED_REGION_OFFSET 0x008c0000
47 #define FIMC_IS_FW_INFO_LEN 31
48 #define FIMC_IS_FW_VER_LEN 7
49 #define FIMC_IS_FW_DESC_LEN (FIMC_IS_FW_INFO_LEN + \
51 #define FIMC_IS_SETFILE_INFO_LEN 39
53 #define FIMC_IS_EXTRA_MEM_SIZE (FIMC_IS_EXTRA_FW_SIZE + \
54 FIMC_IS_EXTRA_SETFILE_SIZE + 0x1000)
55 #define FIMC_IS_EXTRA_FW_SIZE 0x180000
56 #define FIMC_IS_EXTRA_SETFILE_SIZE 0x4b000
59 #define FIMC_IS_FW_ADDR_MASK ((1 << 26) - 1)
60 #define FIMC_IS_FW_SIZE_MAX (SZ_4M)
61 #define FIMC_IS_FW_SIZE_MIN (SZ_32K)
63 #define ATCLK_MCUISP_FREQUENCY 100000000UL
64 #define ACLK_AXI_FREQUENCY 100000000UL
81 ISS_CLK_ISP_DIV0
= ISS_GATE_CLKS_MAX
,
87 ISS_CLK_ACLK400MCUISP
,
88 ISS_CLK_ACLK400MCUISP_DIV
,
92 /* The driver's internal state flags */
104 IS_ST_BLOCK_CMD_CLEARED
,
112 FIMC_IS_AF_SETCONFIG
= 1,
113 FIMC_IS_AF_RUNNING
= 2,
115 FIMC_IS_AF_ABORT
= 4,
116 FIMC_IS_AF_FAILED
= 5,
120 FIMC_IS_AF_UNLOCKED
= 0,
121 FIMC_IS_AF_LOCKED
= 2
125 FIMC_IS_AE_UNLOCKED
= 0,
126 FIMC_IS_AE_LOCKED
= 1
129 enum awb_lock_state
{
130 FIMC_IS_AWB_UNLOCKED
= 0,
131 FIMC_IS_AWB_LOCKED
= 1
135 IS_METERING_CONFIG_CMD
,
136 IS_METERING_CONFIG_WIN_POS_X
,
137 IS_METERING_CONFIG_WIN_POS_Y
,
138 IS_METERING_CONFIG_WIN_WIDTH
,
139 IS_METERING_CONFIG_WIN_HEIGHT
,
140 IS_METERING_CONFIG_MAX
144 const struct firmware
*info
;
151 struct is_fd_result_header
{
173 struct fimc_is_firmware
{
174 const struct firmware
*f_w
;
180 char info
[FIMC_IS_FW_INFO_LEN
+ 1];
181 char version
[FIMC_IS_FW_VER_LEN
+ 1];
182 char setfile_info
[FIMC_IS_SETFILE_INFO_LEN
+ 1];
186 struct fimc_is_memory
{
187 /* DMA base address */
189 /* virtual base address */
195 #define FIMC_IS_I2H_MAX_ARGS 12
201 u32 args
[FIMC_IS_I2H_MAX_ARGS
];
209 #define FIMC_IS_DEBUG_MSG 0x3f
210 #define FIMC_IS_DEBUG_LEVEL 3
212 struct fimc_is_setfile
{
213 const struct firmware
*info
;
220 struct chain_config
{
221 struct global_param global
;
222 struct sensor_param sensor
;
223 struct isp_param isp
;
224 struct drc_param drc
;
227 unsigned long p_region_index
[2];
231 * struct fimc_is - fimc-is data structure
232 * @pdev: pointer to FIMC-IS platform device
233 * @v4l2_dev: pointer to the top level v4l2_device
234 * @fw: data structure describing the FIMC-IS firmware binary
235 * @memory: memory region assigned for the FIMC-IS (firmware)
236 * @isp: the ISP block data structure
237 * @sensor: fimc-is sensor subdevice array
238 * @setfile: descriptor of the imaging pipeline calibration data
239 * @ctrl_handler: the v4l2 controls handler
240 * @lock: mutex serializing video device and the subdev operations
241 * @slock: spinlock protecting this data structure and the hw registers
242 * @clocks: FIMC-LITE gate clock
243 * @regs: MCUCTL mmapped registers region
244 * @pmu_regs: PMU ISP mmapped registers region
245 * @irq: FIMC-IS interrupt
246 * @irq_queue: interrupt handling waitqueue
247 * @lpm: low power mode flag
248 * @state: internal driver's state flags
249 * @sensor_index: image sensor index for the firmware
250 * @i2h_cmd: FIMC-IS to the host (CPU) mailbox command data structure
251 * @h2i_cmd: the host (CPU) to FIMC-IS mailbox command data structure
252 * @fd_header: the face detection result data structure
253 * @config: shared HW pipeline configuration data
254 * @config_index: index to the @config entry currently in use
255 * @is_p_region: pointer to the shared parameter memory region
256 * @is_dma_p_region: DMA address of the shared parameter memory region
257 * @is_shared_region: pointer to the IS shared region data structure
258 * @af: auto focus data
259 * @debugfs_entry: debugfs entry for the firmware log
262 struct platform_device
*pdev
;
263 struct v4l2_device
*v4l2_dev
;
265 struct fimc_is_firmware fw
;
266 struct fimc_is_memory memory
;
269 struct fimc_is_sensor sensor
[FIMC_IS_SENSORS_NUM
];
270 struct fimc_is_setfile setfile
;
272 struct v4l2_ctrl_handler ctrl_handler
;
277 struct clk
*clocks
[ISS_CLKS_MAX
];
279 void __iomem
*pmu_regs
;
281 wait_queue_head_t irq_queue
;
285 unsigned int sensor_index
;
287 struct i2h_cmd i2h_cmd
;
288 struct h2i_cmd h2i_cmd
;
289 struct is_fd_result_header fd_header
;
291 struct chain_config config
[IS_SC_MAX
];
292 unsigned config_index
;
294 struct is_region
*is_p_region
;
295 dma_addr_t is_dma_p_region
;
296 struct is_share_region
*is_shared_region
;
297 struct is_af_info af
;
299 struct dentry
*debugfs_entry
;
302 static inline struct fimc_is
*fimc_isp_to_is(struct fimc_isp
*isp
)
304 return container_of(isp
, struct fimc_is
, isp
);
307 static inline struct chain_config
*__get_curr_is_config(struct fimc_is
*is
)
309 return &is
->config
[is
->config_index
];
312 static inline void fimc_is_mem_barrier(void)
317 static inline void fimc_is_set_param_bit(struct fimc_is
*is
, int num
)
319 struct chain_config
*cfg
= &is
->config
[is
->config_index
];
321 set_bit(num
, &cfg
->p_region_index
[0]);
324 static inline void fimc_is_set_param_ctrl_cmd(struct fimc_is
*is
, int cmd
)
326 is
->is_p_region
->parameter
.isp
.control
.cmd
= cmd
;
329 static inline void mcuctl_write(u32 v
, struct fimc_is
*is
, unsigned int offset
)
331 writel(v
, is
->regs
+ offset
);
334 static inline u32
mcuctl_read(struct fimc_is
*is
, unsigned int offset
)
336 return readl(is
->regs
+ offset
);
339 static inline void pmuisp_write(u32 v
, struct fimc_is
*is
, unsigned int offset
)
341 writel(v
, is
->pmu_regs
+ offset
);
344 static inline u32
pmuisp_read(struct fimc_is
*is
, unsigned int offset
)
346 return readl(is
->pmu_regs
+ offset
);
349 int fimc_is_wait_event(struct fimc_is
*is
, unsigned long bit
,
350 unsigned int state
, unsigned int timeout
);
351 int fimc_is_cpu_set_power(struct fimc_is
*is
, int on
);
352 int fimc_is_start_firmware(struct fimc_is
*is
);
353 int fimc_is_hw_initialize(struct fimc_is
*is
);
354 void fimc_is_log_dump(const char *level
, const void *buf
, size_t len
);
356 #endif /* FIMC_IS_H_ */