linux/drivers/staging/media/atomisp/pci/atomisp_cmd.c

// SPDX-License-Identifier: GPL-2.0
/*
 * Support for Medifield PNW Camera Imaging ISP subsystem.
 *
 * Copyright (c) 2010 Intel Corporation. All Rights Reserved.
 *
 * Copyright (c) 2010 Silicon Hive www.siliconhive.com.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License version
 * 2 as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 *
 */
#include <linux/errno.h>
#include <linux/firmware.h>
#include <linux/pci.h>
#include <linux/interrupt.h>
#include <linux/io.h>
#include <linux/kernel.h>
#include <linux/kfifo.h>
#include <linux/pm_runtime.h>
#include <linux/timer.h>

#include <asm/iosf_mbi.h>

#include <media/v4l2-event.h>

#define CREATE_TRACE_POINTS
#include "atomisp_trace_event.h"

#include "atomisp_cmd.h"
#include "atomisp_common.h"
#include "atomisp_fops.h"
#include "atomisp_internal.h"
#include "atomisp_ioctl.h"
#include "atomisp-regs.h"
#include "atomisp_tables.h"
#include "atomisp_compat.h"
#include "atomisp_subdev.h"
#include "atomisp_dfs_tables.h"

#include <hmm/hmm.h>

#include "sh_css_hrt.h"
#include "sh_css_defs.h"
#include "system_global.h"
#include "sh_css_internal.h"
#include "sh_css_sp.h"
#include "gp_device.h"
#include "device_access.h"
#include "irq.h"

#include "ia_css_types.h"
#include "ia_css_stream.h"
#include "ia_css_debug.h"
#include "bits.h"

host;

/*
 * get sensor:dis71430/ov2720 related info from v4l2_subdev->priv data field.
 * subdev->priv is set in mrst.c
 */
struct camera_mipi_info *atomisp_to_sensor_mipi_info(struct v4l2_subdev *sd)
{}

/*
 * get struct atomisp_video_pipe from v4l2 video_device
 */
struct atomisp_video_pipe *atomisp_to_video_pipe(struct video_device *dev)
{}

static unsigned short atomisp_get_sensor_fps(struct atomisp_sub_device *asd)
{}

/*
 * DFS progress is shown as follows:
 * 1. Target frequency is calculated according to FPS/Resolution/ISP running
 *    mode.
 * 2. Ratio is calculated using formula: 2 * HPLL / target frequency - 1
 *    with proper rounding.
 * 3. Set ratio to ISPFREQ40, 1 to FREQVALID and ISPFREQGUAR40
 *    to 200MHz in ISPSSPM1.
 * 4. Wait for FREQVALID to be cleared by P-Unit.
 * 5. Wait for field ISPFREQSTAT40 in ISPSSPM1 turn to ratio set in 3.
 */
static int write_target_freq_to_hw(struct atomisp_device *isp,
				   unsigned int new_freq)
{}

int atomisp_freq_scaling(struct atomisp_device *isp,
			 enum atomisp_dfs_mode mode,
			 bool force)
{}

/*
 * reset and restore ISP
 */
int atomisp_reset(struct atomisp_device *isp)
{}

/*
 * interrupt disable functions
 */
static void disable_isp_irq(enum hrt_isp_css_irq irq)
{}

/*
 * interrupt clean function
 */
static void clear_isp_irq(enum hrt_isp_css_irq irq)
{}

void atomisp_msi_irq_init(struct atomisp_device *isp)
{}

void atomisp_msi_irq_uninit(struct atomisp_device *isp)
{}

static void atomisp_sof_event(struct atomisp_sub_device *asd)
{}

void atomisp_eof_event(struct atomisp_sub_device *asd, uint8_t exp_id)
{}

static void atomisp_3a_stats_ready_event(struct atomisp_sub_device *asd,
	uint8_t exp_id)
{}

static void atomisp_metadata_ready_event(struct atomisp_sub_device *asd,
	enum atomisp_metadata_type md_type)
{}

static void atomisp_reset_event(struct atomisp_sub_device *asd)
{}

static void print_csi_rx_errors(enum mipi_port_id port,
				struct atomisp_device *isp)
{}

/* Clear irq reg */
static void clear_irq_reg(struct atomisp_device *isp)
{}

/* interrupt handling function*/
irqreturn_t atomisp_isr(int irq, void *dev)
{}

void atomisp_clear_css_buffer_counters(struct atomisp_sub_device *asd)
{}

/* 0x100000 is the start of dmem inside SP */
#define SP_DMEM_BASE

void dump_sp_dmem(struct atomisp_device *isp, unsigned int addr,
		  unsigned int size)
{}

int atomisp_buffers_in_css(struct atomisp_video_pipe *pipe)
{}

void atomisp_buffer_done(struct ia_css_frame *frame, enum vb2_buffer_state state)
{}

void atomisp_flush_video_pipe(struct atomisp_video_pipe *pipe, enum vb2_buffer_state state,
			      bool warn_on_css_frames)
{}

/* clean out the parameters that did not apply */
void atomisp_flush_params_queue(struct atomisp_video_pipe *pipe)
{}

/* Re-queue per-frame parameters */
static void atomisp_recover_params_queue(struct atomisp_video_pipe *pipe)
{}

void atomisp_buf_done(struct atomisp_sub_device *asd, int error,
		      enum ia_css_buffer_type buf_type,
		      enum ia_css_pipe_id css_pipe_id,
		      bool q_buffers, enum atomisp_input_stream_id stream_id)
{}

void atomisp_assert_recovery_work(struct work_struct *work)
{}

irqreturn_t atomisp_isr_thread(int irq, void *isp_ptr)
{}

/*
 * Get internal fmt according to V4L2 fmt
 */
static enum ia_css_frame_format
v4l2_fmt_to_sh_fmt(u32 fmt)
{}

/*
 * raw format match between SH format and V4L2 format
 */
static int raw_output_format_match_input(u32 input, u32 output)
{}

u32 atomisp_get_pixel_depth(u32 pixelformat)
{}

bool atomisp_is_mbuscode_raw(uint32_t code)
{}

/*
 * ISP features control function
 */

/*
 * Set ISP capture mode based on current settings
 */
static void atomisp_update_capture_mode(struct atomisp_sub_device *asd)
{}

/*
 * Function to enable/disable lens geometry distortion correction (GDC) and
 * chromatic aberration correction (CAC)
 */
int atomisp_gdc_cac(struct atomisp_sub_device *asd, int flag,
		    __s32 *value)
{}

/*
 * Function to enable/disable low light mode including ANR
 */
int atomisp_low_light(struct atomisp_sub_device *asd, int flag,
		      __s32 *value)
{}

/*
 * Function to enable/disable extra noise reduction (XNR) in low light
 * condition
 */
int atomisp_xnr(struct atomisp_sub_device *asd, int flag,
		int *xnr_enable)
{}

/*
 * Function to configure bayer noise reduction
 */
int atomisp_nr(struct atomisp_sub_device *asd, int flag,
	       struct atomisp_nr_config *arg)
{}

/*
 * Function to configure temporal noise reduction (TNR)
 */
int atomisp_tnr(struct atomisp_sub_device *asd, int flag,
		struct atomisp_tnr_config *config)
{}

/*
 * Function to configure black level compensation
 */
int atomisp_black_level(struct atomisp_sub_device *asd, int flag,
			struct atomisp_ob_config *config)
{}

/*
 * Function to configure edge enhancement
 */
int atomisp_ee(struct atomisp_sub_device *asd, int flag,
	       struct atomisp_ee_config *config)
{}

/*
 * Function to update Gamma table for gamma, brightness and contrast config
 */
int atomisp_gamma(struct atomisp_sub_device *asd, int flag,
		  struct atomisp_gamma_table *config)
{}

/*
 * Function to update Ctc table for Chroma Enhancement
 */
int atomisp_ctc(struct atomisp_sub_device *asd, int flag,
		struct atomisp_ctc_table *config)
{}

/*
 * Function to update gamma correction parameters
 */
int atomisp_gamma_correction(struct atomisp_sub_device *asd, int flag,
			     struct atomisp_gc_config *config)
{}

/*
 * Function to update narrow gamma flag
 */
int atomisp_formats(struct atomisp_sub_device *asd, int flag,
		    struct atomisp_formats_config *config)
{}

void atomisp_free_internal_buffers(struct atomisp_sub_device *asd)
{}

static void atomisp_update_grid_info(struct atomisp_sub_device *asd,
				     enum ia_css_pipe_id pipe_id)
{}

static void atomisp_curr_user_grid_info(struct atomisp_sub_device *asd,
					struct atomisp_grid_info *info)
{}

int atomisp_compare_grid(struct atomisp_sub_device *asd,
			 struct atomisp_grid_info *atomgrid)
{}

/*
 * Function to update Gdc table for gdc
 */
int atomisp_gdc_cac_table(struct atomisp_sub_device *asd, int flag,
			  struct atomisp_morph_table *config)
{}

int atomisp_macc_table(struct atomisp_sub_device *asd, int flag,
		       struct atomisp_macc_config *config)
{}

int atomisp_set_dis_vector(struct atomisp_sub_device *asd,
			   struct atomisp_dis_vector *vector)
{}

/*
 * Function to set/get image stablization statistics
 */
int atomisp_get_dis_stat(struct atomisp_sub_device *asd,
			 struct atomisp_dis_statistics *stats)
{}

/*
 * Function  set camrea_prefiles.xml current sensor pixel array size
 */
int atomisp_set_array_res(struct atomisp_sub_device *asd,
			  struct atomisp_resolution  *config)
{}

/*
 * Function to get DVS2 BQ resolution settings
 */
int atomisp_get_dvs2_bq_resolutions(struct atomisp_sub_device *asd,
				    struct atomisp_dvs2_bq_resolutions *bq_res)
{}

int atomisp_set_dis_coefs(struct atomisp_sub_device *asd,
			  struct atomisp_dis_coefficients *coefs)
{}

/*
 * Function to set/get 3A stat from isp
 */
int atomisp_3a_stat(struct atomisp_sub_device *asd, int flag,
		    struct atomisp_3a_statistics *config)
{}

/*
 * Function to calculate real zoom region for every pipe
 */
int atomisp_calculate_real_zoom_region(struct atomisp_sub_device *asd,
				       struct ia_css_dz_config   *dz_config,
				       enum ia_css_pipe_id css_pipe_id)

{}

/*
 * Function to check the zoom region whether is effective
 */
static bool atomisp_check_zoom_region(
    struct atomisp_sub_device *asd,
    struct ia_css_dz_config *dz_config)
{}

void atomisp_apply_css_parameters(
    struct atomisp_sub_device *asd,
    struct atomisp_css_params *css_param)
{}

static unsigned int long copy_from_compatible(void *to, const void *from,
	unsigned long n, bool from_user)
{}

int atomisp_cp_general_isp_parameters(struct atomisp_sub_device *asd,
				      struct atomisp_parameters *arg,
				      struct atomisp_css_params *css_param,
				      bool from_user)
{}

int atomisp_cp_lsc_table(struct atomisp_sub_device *asd,
			 struct atomisp_shading_table *source_st,
			 struct atomisp_css_params *css_param,
			 bool from_user)
{}

int atomisp_css_cp_dvs2_coefs(struct atomisp_sub_device *asd,
			      struct ia_css_dvs2_coefficients *coefs,
			      struct atomisp_css_params *css_param,
			      bool from_user)
{}

int atomisp_cp_dvs_6axis_config(struct atomisp_sub_device *asd,
				struct atomisp_dvs_6axis_config *source_6axis_config,
				struct atomisp_css_params *css_param,
				bool from_user)
{}

int atomisp_cp_morph_table(struct atomisp_sub_device *asd,
			   struct atomisp_morph_table *source_morph_table,
			   struct atomisp_css_params *css_param,
			   bool from_user)
{}

int atomisp_makeup_css_parameters(struct atomisp_sub_device *asd,
				  struct atomisp_parameters *arg,
				  struct atomisp_css_params *css_param)
{}

void atomisp_free_css_parameters(struct atomisp_css_params *css_param)
{}

static void atomisp_move_frame_to_activeq(struct ia_css_frame *frame,
					  struct atomisp_css_params_with_list *param)
{}

/*
 * Check parameter queue list and buffer queue list to find out if matched items
 * and then set parameter to CSS and enqueue buffer to CSS.
 * Of course, if the buffer in buffer waiting list is not bound to a per-frame
 * parameter, it will be enqueued into CSS as long as the per-frame setting
 * buffers before it get enqueued.
 */
void atomisp_handle_parameter_and_buffer(struct atomisp_video_pipe *pipe)
{}

/*
 * Function to configure ISP parameters
 */
int atomisp_set_parameters(struct video_device *vdev,
			   struct atomisp_parameters *arg)
{}

/*
 * Function to set/get isp parameters to isp
 */
int atomisp_param(struct atomisp_sub_device *asd, int flag,
		  struct atomisp_parm *config)
{}

/*
 * Function to configure color effect of the image
 */
int atomisp_color_effect(struct atomisp_sub_device *asd, int flag,
			 __s32 *effect)
{}

/*
 * Function to configure bad pixel correction
 */
int atomisp_bad_pixel(struct atomisp_sub_device *asd, int flag,
		      __s32 *value)
{}

/*
 * Function to configure bad pixel correction params
 */
int atomisp_bad_pixel_param(struct atomisp_sub_device *asd, int flag,
			    struct atomisp_dp_config *config)
{}

/*
 * Function to enable/disable video image stablization
 */
int atomisp_video_stable(struct atomisp_sub_device *asd, int flag,
			 __s32 *value)
{}

/*
 * Function to configure fixed pattern noise
 */
int atomisp_fixed_pattern(struct atomisp_sub_device *asd, int flag,
			  __s32 *value)
{}

static unsigned int
atomisp_bytesperline_to_padded_width(unsigned int bytesperline,
				     enum ia_css_frame_format format)
{}

static int
atomisp_v4l2_framebuffer_to_css_frame(const struct v4l2_framebuffer *arg,
				      struct ia_css_frame **result)
{}

/*
 * Function to configure fixed pattern noise table
 */
int atomisp_fixed_pattern_table(struct atomisp_sub_device *asd,
				struct v4l2_framebuffer *arg)
{}

/*
 * Function to configure false color correction
 */
int atomisp_false_color(struct atomisp_sub_device *asd, int flag,
			__s32 *value)
{}

/*
 * Function to configure bad pixel correction params
 */
int atomisp_false_color_param(struct atomisp_sub_device *asd, int flag,
			      struct atomisp_de_config *config)
{}

/*
 * Function to configure white balance params
 */
int atomisp_white_balance_param(struct atomisp_sub_device *asd, int flag,
				struct atomisp_wb_config *config)
{}

int atomisp_3a_config_param(struct atomisp_sub_device *asd, int flag,
			    struct atomisp_3a_config *config)
{}

/*
 * Function to setup digital zoom
 */
int atomisp_digital_zoom(struct atomisp_sub_device *asd, int flag,
			 __s32 *value)
{}

static void __atomisp_update_stream_env(struct atomisp_sub_device *asd,
					u16 stream_index, struct atomisp_input_stream_info *stream_info)
{}

static void __atomisp_init_stream_info(u16 stream_index,
				       struct atomisp_input_stream_info *stream_info)
{}

static void atomisp_fill_pix_format(struct v4l2_pix_format *f,
				    u32 width, u32 height,
				    const struct atomisp_format_bridge *br_fmt)
{}

/* Get sensor padding values for the non padded width x height resolution */
void atomisp_get_padding(struct atomisp_device *isp, u32 width, u32 height,
			 u32 *padding_w, u32 *padding_h)
{}

int atomisp_s_sensor_power(struct atomisp_device *isp, unsigned int input, bool on)
{}

int atomisp_select_input(struct atomisp_device *isp, unsigned int input)
{}

/*
 * Ensure the CSI-receiver -> ISP link for input_curr is marked as enabled and
 * the other CSI-receiver -> ISP links are disabled.
 */
void atomisp_setup_input_links(struct atomisp_device *isp)
{}

static int atomisp_set_sensor_crop_and_fmt(struct atomisp_device *isp,
					   struct v4l2_mbus_framefmt *ffmt,
					   int which)
{}

/* This function looks up the closest available resolution. */
int atomisp_try_fmt(struct atomisp_device *isp, struct v4l2_pix_format *f,
		    const struct atomisp_format_bridge **fmt_ret,
		    const struct atomisp_format_bridge **snr_fmt_ret)
{}

enum mipi_port_id atomisp_port_to_mipi_port(struct atomisp_device *isp,
					    enum atomisp_camera_port port)
{}

static inline int atomisp_set_sensor_mipi_to_isp(
    struct atomisp_sub_device *asd,
    enum atomisp_input_stream_id stream_id,
    struct camera_mipi_info *mipi_info)
{}

static int configure_pp_input_nop(struct atomisp_sub_device *asd,
				  unsigned int width, unsigned int height)
{}

static int configure_output_nop(struct atomisp_sub_device *asd,
				unsigned int width, unsigned int height,
				unsigned int min_width,
				enum ia_css_frame_format sh_fmt)
{}

static int get_frame_info_nop(struct atomisp_sub_device *asd,
			      struct ia_css_frame_info *finfo)
{}

/*
 * Resets CSS parameters that depend on input resolution.
 *
 * Update params like CSS RAW binning, 2ppc mode and pp_input
 * which depend on input size, but are not automatically
 * handled in CSS when the input resolution is changed.
 */
static int css_input_resolution_changed(struct atomisp_sub_device *asd,
					struct v4l2_mbus_framefmt *ffmt)
{}

static int atomisp_set_fmt_to_isp(struct video_device *vdev,
				  struct ia_css_frame_info *output_info,
				  const struct v4l2_pix_format *pix)
{}

static void atomisp_get_dis_envelop(struct atomisp_sub_device *asd,
				    unsigned int width, unsigned int height,
				    unsigned int *dvs_env_w, unsigned int *dvs_env_h)
{}

static void atomisp_check_copy_mode(struct atomisp_sub_device *asd,
				    const struct v4l2_pix_format *f)
{}

static int atomisp_set_fmt_to_snr(struct video_device *vdev, const struct v4l2_pix_format *f,
				  unsigned int dvs_env_w, unsigned int dvs_env_h)
{}

int atomisp_set_fmt(struct video_device *vdev, struct v4l2_format *f)
{}

int atomisp_set_shading_table(struct atomisp_sub_device *asd,
			      struct atomisp_shading_table *user_shading_table)
{}

static int __checking_exp_id(struct atomisp_sub_device *asd, int exp_id)
{}

void atomisp_init_raw_buffer_bitmap(struct atomisp_sub_device *asd)
{}

static int __is_raw_buffer_locked(struct atomisp_sub_device *asd, int exp_id)
{}

static int __clear_raw_buffer_bitmap(struct atomisp_sub_device *asd, int exp_id)
{}

int atomisp_exp_id_capture(struct atomisp_sub_device *asd, int *exp_id)
{}

int atomisp_exp_id_unlock(struct atomisp_sub_device *asd, int *exp_id)
{}

int atomisp_enable_dz_capt_pipe(struct atomisp_sub_device *asd,
				unsigned int *enable)
{}

int atomisp_inject_a_fake_event(struct atomisp_sub_device *asd, int *event)
{}