Merge tag 'kbuild-v5.8-2' of git://git.kernel.org/pub/scm/linux/kernel/git/masahiroy...
[linux-2.6-microblaze.git] / drivers / staging / media / atomisp / pci / atomisp_cmd.c
index 2758c2d..7b936e5 100644 (file)
@@ -1,3 +1,4 @@
+// SPDX-License-Identifier: GPL-2.0
 /*
  * Support for Medifield PNW Camera Imaging ISP subsystem.
  *
@@ -16,6 +17,7 @@
  *
  *
  */
+#include <linux/errno.h>
 #include <linux/firmware.h>
 #include <linux/pci.h>
 #include <linux/interrupt.h>
@@ -58,7 +60,6 @@
 #include "ia_css_types.h"
 #include "ia_css_stream.h"
 #include "ia_css_debug.h"
-#include "error_support.h"
 #include "bits.h"
 
 /* We should never need to run the flash for more than 2 frames.
@@ -242,8 +243,12 @@ int atomisp_freq_scaling(struct atomisp_device *isp,
        }
 
        fps = atomisp_get_sensor_fps(asd);
-       if (fps == 0)
-               return -EINVAL;
+       if (fps == 0) {
+               dev_info(isp->dev,
+                        "Sensor didn't report FPS. Using DFS max mode.\n");
+               new_freq = dfs->highest_freq;
+               goto done;
+       }
 
        curr_rules.width = asd->fmt[asd->capture_pad].fmt.width;
        curr_rules.height = asd->fmt[asd->capture_pad].fmt.height;
@@ -565,7 +570,7 @@ irqreturn_t atomisp_isr(int irq, void *dev)
 
        if (irq_infos & IA_CSS_IRQ_INFO_CSS_RECEIVER_SOF) {
                dev_dbg_ratelimited(isp->dev,
-                                   "irq:0x%x (IA_CSS_IRQ_INFO_CSS_RECEIVER_SOF)\n",
+                                   "irq:0x%x (SOF)\n",
                                    irq_infos);
                irq_infos &= ~IA_CSS_IRQ_INFO_CSS_RECEIVER_SOF;
        }
@@ -586,18 +591,18 @@ irqreturn_t atomisp_isr(int irq, void *dev)
 
        if (irq_infos & IA_CSS_IRQ_INFO_ISYS_EVENTS_READY) {
                while (ia_css_dequeue_isys_event(&eof_event.event) ==
-                      IA_CSS_SUCCESS) {
+                      0) {
                        /* EOF Event does not have the css_pipe returned */
                        asd = __get_asd_from_port(isp, eof_event.event.port);
                        if (!asd) {
-                               dev_err(isp->dev, "%s:no subdev.event:%d",
+                               dev_err(isp->dev, "%s: ISYS event, but no subdev.event:%d",
                                        __func__, eof_event.event.type);
                                continue;
                        }
 
                        atomisp_eof_event(asd, eof_event.event.exp_id);
                        dev_dbg_ratelimited(isp->dev,
-                                           "%s EOF exp_id %d, asd %d\n",
+                                           "%s ISYS event: EOF exp_id %d, asd %d\n",
                                            __func__, eof_event.event.exp_id,
                                            asd->index);
                }
@@ -609,7 +614,7 @@ irqreturn_t atomisp_isr(int irq, void *dev)
 
        spin_unlock_irqrestore(&isp->lock, flags);
 
-       dev_dbg_ratelimited(isp->dev, "irq:0x%x\n", irq_infos);
+       dev_dbg_ratelimited(isp->dev, "irq:0x%x (unhandled)\n", irq_infos);
 
        return IRQ_WAKE_THREAD;
 
@@ -617,7 +622,8 @@ out_nowake:
        spin_unlock_irqrestore(&isp->lock, flags);
 
        if (irq_infos)
-               dev_dbg_ratelimited(isp->dev, "irq:0x%x\n", irq_infos);
+               dev_dbg_ratelimited(isp->dev, "irq:0x%x (ignored, as not streaming anymore)\n",
+                                   irq_infos);
 
        return IRQ_HANDLED;
 }
@@ -659,6 +665,7 @@ bool atomisp_buffers_queued_pipe(struct atomisp_video_pipe *pipe)
 void dump_sp_dmem(struct atomisp_device *isp, unsigned int addr,
                  unsigned int size)
 {
+       u32 __iomem *io_virt_addr;
        unsigned int data = 0;
        unsigned int size32 = DIV_ROUND_UP(size, sizeof(u32));
 
@@ -671,11 +678,11 @@ void dump_sp_dmem(struct atomisp_device *isp, unsigned int addr,
                return;
        }
        addr += SP_DMEM_BASE;
+       io_virt_addr = atomisp_io_base + (addr & 0x003FFFFF);
        do {
-               data = _hrt_master_port_uload_32(addr);
-
+               data = *io_virt_addr;
                dev_dbg(isp->dev, "%s, \t [0x%x]:0x%x\n", __func__, addr, data);
-               addr += sizeof(unsigned int);
+               io_virt_addr += sizeof(u32);
                size32 -= 1;
        } while (size32 > 0);
 }
@@ -987,7 +994,7 @@ void atomisp_buf_done(struct atomisp_sub_device *asd, int error,
                break;
        case IA_CSS_BUFFER_TYPE_VF_OUTPUT_FRAME:
        case IA_CSS_BUFFER_TYPE_SEC_VF_OUTPUT_FRAME:
-               if (atomisp_hw_is_isp2401)
+               if (IS_ISP2401)
                        reset_wdt_timer = true;
 
                pipe->buffers_in_css--;
@@ -1036,18 +1043,18 @@ void atomisp_buf_done(struct atomisp_sub_device *asd, int error,
 
                        asd->pending_capture_request--;
 
-                       if (atomisp_hw_is_isp2401)
+                       if (IS_ISP2401)
                                asd->re_trigger_capture = false;
 
                        dev_dbg(isp->dev, "Trigger capture again for new buffer. err=%d\n",
                                err);
-               } else if (atomisp_hw_is_isp2401) {
+               } else if (IS_ISP2401) {
                        asd->re_trigger_capture = true;
                }
                break;
        case IA_CSS_BUFFER_TYPE_OUTPUT_FRAME:
        case IA_CSS_BUFFER_TYPE_SEC_OUTPUT_FRAME:
-               if (atomisp_hw_is_isp2401)
+               if (IS_ISP2401)
                        reset_wdt_timer = true;
 
                pipe->buffers_in_css--;
@@ -1170,8 +1177,7 @@ void atomisp_buf_done(struct atomisp_sub_device *asd, int error,
                        atomisp_apply_css_parameters(asd,
                                                     &asd->params.css_param);
                        if (asd->params.css_param.update_flag.dz_config)
-                               atomisp_css_set_dz_config(asd,
-                                                         &asd->params.css_param.dz_config);
+                               asd->params.config.dz_config = &asd->params.css_param.dz_config;
                        /* New global dvs 6axis config should be blocked
                         * here if there's a buffer with per-frame parameters
                         * pending in CSS frame buffer queue.
@@ -1218,7 +1224,7 @@ void atomisp_buf_done(struct atomisp_sub_device *asd, int error,
                 */
                wake_up(&vb->done);
        }
-       if (atomisp_hw_is_isp2401)
+       if (IS_ISP2401)
                atomic_set(&pipe->wdt_count, 0);
 
        /*
@@ -1238,7 +1244,7 @@ void atomisp_buf_done(struct atomisp_sub_device *asd, int error,
        if (!error && q_buffers)
                atomisp_qbuffers_to_css(asd);
 
-       if (atomisp_hw_is_isp2401) {
+       if (IS_ISP2401) {
                /* If there are no buffers queued then
                * delete wdt timer. */
                if (asd->streaming != ATOMISP_DEVICE_STREAMING_ENABLED)
@@ -1262,9 +1268,15 @@ void atomisp_delayed_init_work(struct work_struct *work)
         */
        if (!ATOMISP_USE_YUVPP(asd)) {
                struct v4l2_event event = {0};
+               struct ia_css_stream *stream;
 
-               atomisp_css_allocate_continuous_frames(false, asd);
-               atomisp_css_update_continuous_frames(asd);
+               stream = asd->stream_env[ATOMISP_INPUT_STREAM_GENERAL].stream;
+
+
+               if (ia_css_alloc_continuous_frame_remain(stream))
+                       return;
+
+               ia_css_update_continuous_frames(stream);
 
                event.type = V4L2_EVENT_ATOMISP_RAW_BUFFERS_ALLOC_DONE;
                v4l2_event_queue(asd->subdev.devnode, &event);
@@ -1400,10 +1412,10 @@ static void __atomisp_css_recover(struct atomisp_device *isp, bool isp_timeout)
                                       atomisp_css_valid_sof(isp));
 
                if (atomisp_freq_scaling(isp, ATOMISP_DFS_MODE_AUTO, true) < 0)
-                       dev_dbg(isp->dev, "dfs failed!\n");
+                       dev_dbg(isp->dev, "DFS auto failed while recovering!\n");
        } else {
                if (atomisp_freq_scaling(isp, ATOMISP_DFS_MODE_MAX, true) < 0)
-                       dev_dbg(isp->dev, "dfs failed!\n");
+                       dev_dbg(isp->dev, "DFS max failed while recovering!\n");
        }
 
        for (i = 0; i < isp->num_of_streams; i++) {
@@ -1468,7 +1480,7 @@ void atomisp_wdt_work(struct work_struct *work)
                return;
        }
 
-       if (!atomisp_hw_is_isp2401) {
+       if (!IS_ISP2401) {
                dev_err(isp->dev, "timeout %d of %d\n",
                        atomic_read(&isp->wdt_count) + 1,
                        ATOMISP_ISP_MAX_TIMEOUT_COUNT);
@@ -1591,11 +1603,11 @@ void atomisp_wdt_work(struct work_struct *work)
                                atomisp_flush_bufs_and_wakeup(asd);
                                complete(&asd->init_done);
                        }
-                       if (atomisp_hw_is_isp2401)
+                       if (IS_ISP2401)
                                atomisp_wdt_stop(asd, false);
                }
 
-               if (!atomisp_hw_is_isp2401) {
+               if (!IS_ISP2401) {
                        atomic_set(&isp->wdt_count, 0);
                } else {
                        isp->isp_fatal_error = true;
@@ -1607,7 +1619,7 @@ void atomisp_wdt_work(struct work_struct *work)
        }
 
        __atomisp_css_recover(isp, true);
-       if (atomisp_hw_is_isp2401) {
+       if (IS_ISP2401) {
                for (i = 0; i < isp->num_of_streams; i++) {
                        struct atomisp_sub_device *asd = &isp->asd[i];
 
@@ -1664,7 +1676,7 @@ void atomisp_wdt(struct timer_list *t)
        struct atomisp_sub_device *asd;
        struct atomisp_device *isp;
 
-       if (!atomisp_hw_is_isp2401) {
+       if (!IS_ISP2401) {
                asd = from_timer(asd, t, wdt);
                isp = asd->isp;
        } else {
@@ -1723,7 +1735,7 @@ void atomisp_wdt_refresh_pipe(struct atomisp_video_pipe *pipe,
 
 void atomisp_wdt_refresh(struct atomisp_sub_device *asd, unsigned int delay)
 {
-       if (!atomisp_hw_is_isp2401) {
+       if (!IS_ISP2401) {
                unsigned long next;
 
                if (delay != ATOMISP_WDT_KEEP_CURRENT_DELAY)
@@ -1786,7 +1798,7 @@ void atomisp_wdt_stop(struct atomisp_sub_device *asd, bool sync)
 {
        dev_dbg(asd->isp->dev, "WDT stop:\n");
 
-       if (!atomisp_hw_is_isp2401) {
+       if (!IS_ISP2401) {
                if (sync) {
                        del_timer_sync(&asd->wdt);
                        cancel_work_sync(&asd->isp->wdt_work);
@@ -1823,7 +1835,8 @@ void atomisp_setup_flash(struct atomisp_sub_device *asd)
                        return;
                }
 
-               atomisp_css_request_flash(asd);
+               ia_css_stream_request_flash(asd->stream_env[ATOMISP_INPUT_STREAM_GENERAL].stream);
+
                asd->params.flash_state = ATOMISP_FLASH_ONGOING;
        } else {
                asd->params.flash_state = ATOMISP_FLASH_IDLE;
@@ -2107,10 +2120,9 @@ int atomisp_gdc_cac(struct atomisp_sub_device *asd, int flag,
 
        asd->params.gdc_cac_en = !!*value;
        if (asd->params.gdc_cac_en) {
-               atomisp_css_set_morph_table(asd,
-                                           asd->params.css_param.morph_table);
+               asd->params.config.morph_table = asd->params.css_param.morph_table;
        } else {
-               atomisp_css_set_morph_table(asd, NULL);
+               asd->params.config.morph_table = NULL;
        }
        asd->params.css_update_params_needed = true;
        atomisp_update_capture_mode(asd);
@@ -2164,7 +2176,7 @@ int atomisp_nr(struct atomisp_sub_device *asd, int flag,
                /* Set nr config to isp parameters */
                memcpy(&asd->params.css_param.nr_config, arg,
                       sizeof(struct ia_css_nr_config));
-               atomisp_css_set_nr_config(asd, &asd->params.css_param.nr_config);
+               asd->params.config.nr_config = &asd->params.css_param.nr_config;
                asd->params.css_update_params_needed = true;
        }
        return 0;
@@ -2185,7 +2197,7 @@ int atomisp_tnr(struct atomisp_sub_device *asd, int flag,
                /* Set tnr config to isp parameters */
                memcpy(&asd->params.css_param.tnr_config, config,
                       sizeof(struct ia_css_tnr_config));
-               atomisp_css_set_tnr_config(asd, &asd->params.css_param.tnr_config);
+               asd->params.config.tnr_config = &asd->params.css_param.tnr_config;
                asd->params.css_update_params_needed = true;
        }
 
@@ -2206,7 +2218,7 @@ int atomisp_black_level(struct atomisp_sub_device *asd, int flag,
                /* Set ob config to isp parameters */
                memcpy(&asd->params.css_param.ob_config, config,
                       sizeof(struct ia_css_ob_config));
-               atomisp_css_set_ob_config(asd, &asd->params.css_param.ob_config);
+               asd->params.config.ob_config = &asd->params.css_param.ob_config;
                asd->params.css_update_params_needed = true;
        }
 
@@ -2227,7 +2239,7 @@ int atomisp_ee(struct atomisp_sub_device *asd, int flag,
                /* Set ee config to isp parameters */
                memcpy(&asd->params.css_param.ee_config, config,
                       sizeof(asd->params.css_param.ee_config));
-               atomisp_css_set_ee_config(asd, &asd->params.css_param.ee_config);
+               asd->params.config.ee_config = &asd->params.css_param.ee_config;
                asd->params.css_update_params_needed = true;
        }
 
@@ -2248,7 +2260,7 @@ int atomisp_gamma(struct atomisp_sub_device *asd, int flag,
                /* Set gamma table to isp parameters */
                memcpy(&asd->params.css_param.gamma_table, config,
                       sizeof(asd->params.css_param.gamma_table));
-               atomisp_css_set_gamma_table(asd, &asd->params.css_param.gamma_table);
+               asd->params.config.gamma_table = &asd->params.css_param.gamma_table;
        }
 
        return 0;
@@ -2288,7 +2300,7 @@ int atomisp_gamma_correction(struct atomisp_sub_device *asd, int flag,
                /* Set gamma correction params to isp parameters */
                memcpy(&asd->params.css_param.gc_config, config,
                       sizeof(asd->params.css_param.gc_config));
-               atomisp_css_set_gc_config(asd, &asd->params.css_param.gc_config);
+               asd->params.config.gc_config = &asd->params.css_param.gc_config;
                asd->params.css_update_params_needed = true;
        }
 
@@ -2309,7 +2321,7 @@ int atomisp_formats(struct atomisp_sub_device *asd, int flag,
                /* Set narrow gamma flag to isp parameters */
                memcpy(&asd->params.css_param.formats_config, config,
                       sizeof(asd->params.css_param.formats_config));
-               atomisp_css_set_formats_config(asd, &asd->params.css_param.formats_config);
+               asd->params.config.formats_config = &asd->params.css_param.formats_config;
        }
 
        return 0;
@@ -2320,7 +2332,7 @@ void atomisp_free_internal_buffers(struct atomisp_sub_device *asd)
        atomisp_free_css_parameters(&asd->params.css_param);
 
        if (asd->raw_output_frame) {
-               atomisp_css_frame_free(asd->raw_output_frame);
+               ia_css_frame_free(asd->raw_output_frame);
                asd->raw_output_frame = NULL;
        }
 }
@@ -2472,7 +2484,7 @@ int atomisp_gdc_cac_table(struct atomisp_sub_device *asd, int flag,
                }
                asd->params.css_param.morph_table = tab;
                if (asd->params.gdc_cac_en)
-                       atomisp_css_set_morph_table(asd, tab);
+                       asd->params.config.morph_table = tab;
        }
 
        return 0;
@@ -2514,7 +2526,7 @@ int atomisp_macc_table(struct atomisp_sub_device *asd, int flag,
                memcpy(macc_table, &config->table,
                       sizeof(struct ia_css_macc_table));
                if (config->color_effect == asd->params.color_effect)
-                       atomisp_css_set_macc_table(asd, macc_table);
+                       asd->params.config.macc_table = macc_table;
        }
 
        return 0;
@@ -3007,7 +3019,7 @@ int atomisp_calculate_real_zoom_region(struct atomisp_sub_device *asd,
         * map real crop region base on above calculating base max crop region.
         */
 
-       if (!atomisp_hw_is_isp2401) {
+       if (!IS_ISP2401) {
                dz_config->zoom_region.origin.x = dz_config->zoom_region.origin.x
                                                  * eff_res.width
                                                  / asd->sensor_array_res.width;
@@ -3151,84 +3163,82 @@ void atomisp_apply_css_parameters(
     struct atomisp_css_params *css_param)
 {
        if (css_param->update_flag.wb_config)
-               atomisp_css_set_wb_config(asd, &css_param->wb_config);
+               asd->params.config.wb_config = &css_param->wb_config;
 
        if (css_param->update_flag.ob_config)
-               atomisp_css_set_ob_config(asd, &css_param->ob_config);
+               asd->params.config.ob_config = &css_param->ob_config;
 
        if (css_param->update_flag.dp_config)
-               atomisp_css_set_dp_config(asd, &css_param->dp_config);
+               asd->params.config.dp_config = &css_param->dp_config;
 
        if (css_param->update_flag.nr_config)
-               atomisp_css_set_nr_config(asd, &css_param->nr_config);
+               asd->params.config.nr_config = &css_param->nr_config;
 
        if (css_param->update_flag.ee_config)
-               atomisp_css_set_ee_config(asd, &css_param->ee_config);
+               asd->params.config.ee_config = &css_param->ee_config;
 
        if (css_param->update_flag.tnr_config)
-               atomisp_css_set_tnr_config(asd, &css_param->tnr_config);
+               asd->params.config.tnr_config = &css_param->tnr_config;
 
        if (css_param->update_flag.a3a_config)
-               atomisp_css_set_3a_config(asd, &css_param->s3a_config);
+               asd->params.config.s3a_config = &css_param->s3a_config;
 
        if (css_param->update_flag.ctc_config)
-               atomisp_css_set_ctc_config(asd, &css_param->ctc_config);
+               asd->params.config.ctc_config = &css_param->ctc_config;
 
        if (css_param->update_flag.cnr_config)
-               atomisp_css_set_cnr_config(asd, &css_param->cnr_config);
+               asd->params.config.cnr_config = &css_param->cnr_config;
 
        if (css_param->update_flag.ecd_config)
-               atomisp_css_set_ecd_config(asd, &css_param->ecd_config);
+               asd->params.config.ecd_config = &css_param->ecd_config;
 
        if (css_param->update_flag.ynr_config)
-               atomisp_css_set_ynr_config(asd, &css_param->ynr_config);
+               asd->params.config.ynr_config = &css_param->ynr_config;
 
        if (css_param->update_flag.fc_config)
-               atomisp_css_set_fc_config(asd, &css_param->fc_config);
+               asd->params.config.fc_config = &css_param->fc_config;
 
        if (css_param->update_flag.macc_config)
-               atomisp_css_set_macc_config(asd, &css_param->macc_config);
+               asd->params.config.macc_config = &css_param->macc_config;
 
        if (css_param->update_flag.aa_config)
-               atomisp_css_set_aa_config(asd, &css_param->aa_config);
+               asd->params.config.aa_config = &css_param->aa_config;
 
        if (css_param->update_flag.anr_config)
-               atomisp_css_set_anr_config(asd, &css_param->anr_config);
+               asd->params.config.anr_config = &css_param->anr_config;
 
        if (css_param->update_flag.xnr_config)
-               atomisp_css_set_xnr_config(asd, &css_param->xnr_config);
+               asd->params.config.xnr_config = &css_param->xnr_config;
 
        if (css_param->update_flag.yuv2rgb_cc_config)
-               atomisp_css_set_yuv2rgb_cc_config(asd,
-                                                 &css_param->yuv2rgb_cc_config);
+               asd->params.config.yuv2rgb_cc_config = &css_param->yuv2rgb_cc_config;
 
        if (css_param->update_flag.rgb2yuv_cc_config)
-               atomisp_css_set_rgb2yuv_cc_config(asd,
-                                                 &css_param->rgb2yuv_cc_config);
+               asd->params.config.rgb2yuv_cc_config = &css_param->rgb2yuv_cc_config;
 
        if (css_param->update_flag.macc_table)
-               atomisp_css_set_macc_table(asd, &css_param->macc_table);
+               asd->params.config.macc_table = &css_param->macc_table;
 
        if (css_param->update_flag.xnr_table)
-               atomisp_css_set_xnr_table(asd, &css_param->xnr_table);
+               asd->params.config.xnr_table = &css_param->xnr_table;
 
        if (css_param->update_flag.r_gamma_table)
-               atomisp_css_set_r_gamma_table(asd, &css_param->r_gamma_table);
+               asd->params.config.r_gamma_table = &css_param->r_gamma_table;
 
        if (css_param->update_flag.g_gamma_table)
-               atomisp_css_set_g_gamma_table(asd, &css_param->g_gamma_table);
+               asd->params.config.g_gamma_table = &css_param->g_gamma_table;
 
        if (css_param->update_flag.b_gamma_table)
-               atomisp_css_set_b_gamma_table(asd, &css_param->b_gamma_table);
+               asd->params.config.b_gamma_table = &css_param->b_gamma_table;
 
        if (css_param->update_flag.anr_thres)
                atomisp_css_set_anr_thres(asd, &css_param->anr_thres);
 
        if (css_param->update_flag.shading_table)
-               atomisp_css_set_shading_table(asd, css_param->shading_table);
+               asd->params.config.shading_table = css_param->shading_table;
 
        if (css_param->update_flag.morph_table && asd->params.gdc_cac_en)
-               atomisp_css_set_morph_table(asd, css_param->morph_table);
+               asd->params.config.morph_table = css_param->morph_table;
 
        if (css_param->update_flag.dvs2_coefs) {
                struct ia_css_dvs_grid_info *dvs_grid_info =
@@ -3579,7 +3589,7 @@ int atomisp_cp_lsc_table(struct atomisp_sub_device *asd,
        if (!from_user && css_param->update_flag.shading_table)
                return 0;
 
-       if (atomisp_hw_is_isp2401) {
+       if (IS_ISP2401) {
                if (copy_from_compatible(&dest_st, source_st,
                                        sizeof(struct atomisp_shading_table),
                                        from_user)) {
@@ -3612,7 +3622,7 @@ int atomisp_cp_lsc_table(struct atomisp_sub_device *asd,
        }
 
        /* Shading table size per color */
-       if (!atomisp_hw_is_isp2401) {
+       if (!IS_ISP2401) {
                if (st->width > ISP2400_SH_CSS_MAX_SCTBL_WIDTH_PER_COLOR ||
                    st->height > ISP2400_SH_CSS_MAX_SCTBL_HEIGHT_PER_COLOR) {
                        dev_err(asd->isp->dev, "shading table w/h validate failed!");
@@ -3695,7 +3705,7 @@ int atomisp_css_cp_dvs2_coefs(struct atomisp_sub_device *asd,
        if (!from_user && css_param->update_flag.dvs2_coefs)
                return 0;
 
-       if (!atomisp_hw_is_isp2401) {
+       if (!IS_ISP2401) {
                if (sizeof(*cur) != sizeof(coefs->grid) ||
                    memcmp(&coefs->grid, cur, sizeof(coefs->grid))) {
                        dev_err(asd->isp->dev, "dvs grid mis-match!\n");
@@ -3803,7 +3813,7 @@ int atomisp_css_cp_dvs2_coefs(struct atomisp_sub_device *asd,
        }
 
        css_param->update_flag.dvs2_coefs =
-           (struct atomisp_dvs2_coefficients *)css_param->dvs2_coeff;
+           (struct atomisp_dis_coefficients *)css_param->dvs2_coeff;
        return 0;
 }
 
@@ -3838,7 +3848,7 @@ int atomisp_cp_dvs_6axis_config(struct atomisp_sub_device *asd,
        old_6axis_config = css_param->dvs_6axis;
        dvs_6axis_config = old_6axis_config;
 
-       if (atomisp_hw_is_isp2401) {
+       if (IS_ISP2401) {
                struct ia_css_dvs_6axis_config t_6axis_config;
 
                if (copy_from_compatible(&t_6axis_config, source_6axis_config,
@@ -3973,7 +3983,7 @@ int atomisp_cp_morph_table(struct atomisp_sub_device *asd,
 
        old_morph_table = css_param->morph_table;
 
-       if (atomisp_hw_is_isp2401) {
+       if (IS_ISP2401) {
                struct ia_css_morph_table mtbl;
 
                if (copy_from_compatible(&mtbl, source_morph_table,
@@ -4163,7 +4173,7 @@ void atomisp_handle_parameter_and_buffer(struct atomisp_video_pipe *pipe)
 
        atomisp_qbuffers_to_css(asd);
 
-       if (!atomisp_hw_is_isp2401) {
+       if (!IS_ISP2401) {
                if (!atomisp_is_wdt_running(asd) && atomisp_buffers_queued(asd))
                        atomisp_wdt_start(asd);
        } else {
@@ -4199,7 +4209,7 @@ int atomisp_set_parameters(struct video_device *vdev,
                __func__, arg->per_frame_setting, asd->index,
                arg->isp_config_id, vdev->name);
 
-       if (atomisp_hw_is_isp2401) {
+       if (IS_ISP2401) {
                if (atomisp_is_vf_pipe(pipe) && arg->per_frame_setting) {
                        dev_err(asd->isp->dev, "%s: vf pipe not support per_frame_setting",
                                __func__);
@@ -4363,18 +4373,18 @@ int atomisp_param(struct atomisp_sub_device *asd, int flag,
            asd->params.color_effect != V4L2_COLORFX_BW) {
                memcpy(&asd->params.css_param.cc_config, &config->cc_config,
                       sizeof(struct ia_css_cc_config));
-               atomisp_css_set_cc_config(asd, &asd->params.css_param.cc_config);
-       }
-
-       atomisp_css_set_wb_config(asd, &asd->params.css_param.wb_config);
-       atomisp_css_set_ob_config(asd, &asd->params.css_param.ob_config);
-       atomisp_css_set_de_config(asd, &asd->params.css_param.de_config);
-       atomisp_css_set_dz_config(asd, &asd->params.css_param.dz_config);
-       atomisp_css_set_ce_config(asd, &asd->params.css_param.ce_config);
-       atomisp_css_set_dp_config(asd, &asd->params.css_param.dp_config);
-       atomisp_css_set_nr_config(asd, &asd->params.css_param.nr_config);
-       atomisp_css_set_ee_config(asd, &asd->params.css_param.ee_config);
-       atomisp_css_set_tnr_config(asd, &asd->params.css_param.tnr_config);
+               asd->params.config.cc_config = &asd->params.css_param.cc_config;
+       }
+
+       asd->params.config.wb_config = &asd->params.css_param.wb_config;
+       asd->params.config.ob_config = &asd->params.css_param.ob_config;
+       asd->params.config.de_config = &asd->params.css_param.de_config;
+       asd->params.config.dz_config = &asd->params.css_param.dz_config;
+       asd->params.config.ce_config = &asd->params.css_param.ce_config;
+       asd->params.config.dp_config = &asd->params.css_param.dp_config;
+       asd->params.config.nr_config = &asd->params.css_param.nr_config;
+       asd->params.config.ee_config = &asd->params.css_param.ee_config;
+       asd->params.config.tnr_config = &asd->params.css_param.tnr_config;
        asd->params.css_update_params_needed = true;
 
        return 0;
@@ -4463,9 +4473,9 @@ int atomisp_color_effect(struct atomisp_sub_device *asd, int flag,
        atomisp_update_capture_mode(asd);
 
        if (cc_config)
-               atomisp_css_set_cc_config(asd, cc_config);
+               asd->params.config.cc_config = cc_config;
        if (macc_table)
-               atomisp_css_set_macc_table(asd, macc_table);
+               asd->params.config.macc_table = macc_table;
        if (ctc_table)
                atomisp_css_set_ctc_table(asd, ctc_table);
        asd->params.color_effect = (u32)*effect;
@@ -4502,7 +4512,7 @@ int atomisp_bad_pixel_param(struct atomisp_sub_device *asd, int flag,
                /* Set bad pixel to isp parameters */
                memcpy(&asd->params.css_param.dp_config, config,
                       sizeof(asd->params.css_param.dp_config));
-               atomisp_css_set_dp_config(asd, &asd->params.css_param.dp_config);
+               asd->params.config.dp_config = &asd->params.css_param.dp_config;
                asd->params.css_update_params_needed = true;
        }
 
@@ -4595,7 +4605,7 @@ atomisp_v4l2_framebuffer_to_css_frame(const struct v4l2_framebuffer *arg,
        /* Note: the padded width on an ia_css_frame is in elements, not in
           bytes. The RAW frame we use here should always be a 16bit RAW
           frame. This is why we bytesperline/2 is equal to the padded with */
-       if (atomisp_css_frame_allocate(&res, arg->fmt.width, arg->fmt.height,
+       if (ia_css_frame_allocate(&res, arg->fmt.width, arg->fmt.height,
                                       sh_format, padded_width, 0)) {
                ret = -ENOMEM;
                goto err;
@@ -4619,7 +4629,7 @@ atomisp_v4l2_framebuffer_to_css_frame(const struct v4l2_framebuffer *arg,
 
 err:
        if (ret && res)
-               atomisp_css_frame_free(res);
+               ia_css_frame_free(res);
        if (tmp_buf)
                vfree(tmp_buf);
        if (ret == 0)
@@ -4642,10 +4652,12 @@ int atomisp_fixed_pattern_table(struct atomisp_sub_device *asd,
        ret = atomisp_v4l2_framebuffer_to_css_frame(arg, &raw_black_frame);
        if (ret)
                return ret;
-       if (atomisp_css_set_black_frame(asd, raw_black_frame))
-               ret = -ENOMEM;
 
-       atomisp_css_frame_free(raw_black_frame);
+       if (sh_css_set_black_frame(asd->stream_env[ATOMISP_INPUT_STREAM_GENERAL].stream,
+                                  raw_black_frame) != 0)
+               return -ENOMEM;
+
+       ia_css_frame_free(raw_black_frame);
        return ret;
 }
 
@@ -4663,10 +4675,10 @@ int atomisp_false_color(struct atomisp_sub_device *asd, int flag,
 
        /* Set nr config to isp parameters */
        if (*value) {
-               atomisp_css_set_default_de_config(asd);
+               asd->params.config.de_config = NULL;
        } else {
                asd->params.css_param.de_config.pixelnoise = 0;
-               atomisp_css_set_de_config(asd, &asd->params.css_param.de_config);
+               asd->params.config.de_config = &asd->params.css_param.de_config;
        }
        asd->params.css_update_params_needed = true;
        asd->params.false_color = *value;
@@ -4687,7 +4699,7 @@ int atomisp_false_color_param(struct atomisp_sub_device *asd, int flag,
                /* Set false color to isp parameters */
                memcpy(&asd->params.css_param.de_config, config,
                       sizeof(asd->params.css_param.de_config));
-               atomisp_css_set_de_config(asd, &asd->params.css_param.de_config);
+               asd->params.config.de_config = &asd->params.css_param.de_config;
                asd->params.css_update_params_needed = true;
        }
 
@@ -4708,7 +4720,7 @@ int atomisp_white_balance_param(struct atomisp_sub_device *asd, int flag,
                /* Set white balance to isp parameters */
                memcpy(&asd->params.css_param.wb_config, config,
                       sizeof(asd->params.css_param.wb_config));
-               atomisp_css_set_wb_config(asd, &asd->params.css_param.wb_config);
+               asd->params.config.wb_config = &asd->params.css_param.wb_config;
                asd->params.css_update_params_needed = true;
        }
 
@@ -4730,7 +4742,7 @@ int atomisp_3a_config_param(struct atomisp_sub_device *asd, int flag,
                /* Set white balance to isp parameters */
                memcpy(&asd->params.css_param.s3a_config, config,
                       sizeof(asd->params.css_param.s3a_config));
-               atomisp_css_set_3a_config(asd, &asd->params.css_param.s3a_config);
+               asd->params.config.s3a_config = &asd->params.css_param.s3a_config;
                asd->params.css_update_params_needed = true;
        }
 
@@ -4961,13 +4973,14 @@ enum mipi_port_id __get_mipi_port(struct atomisp_device *isp,
 {
        switch (port) {
        case ATOMISP_CAMERA_PORT_PRIMARY:
-                               return MIPI_PORT0_ID;
+               return MIPI_PORT0_ID;
        case ATOMISP_CAMERA_PORT_SECONDARY:
                return MIPI_PORT1_ID;
        case ATOMISP_CAMERA_PORT_TERTIARY:
-               if (MIPI_PORT1_ID + 1 != N_MIPI_PORT_ID)
+               if (MIPI_PORT1_ID + 1 != N_MIPI_PORT_ID) {
                        return MIPI_PORT1_ID + 1;
-       /* go through down for else case */
+               }
+       /* fall through */
        default:
                dev_err(isp->dev, "unsupported port: %d\n", port);
                return MIPI_PORT0_ID;
@@ -5020,7 +5033,7 @@ static inline int atomisp_set_sensor_mipi_to_isp(
                         mipi_info->input_format);
                if (!fc)
                        return -EINVAL;
-               input_format = fc->css_stream_fmt;
+               input_format = fc->atomisp_in_fmt;
        } else {
                struct v4l2_mbus_framefmt *sink;
 
@@ -5030,7 +5043,7 @@ static inline int atomisp_set_sensor_mipi_to_isp(
                fc = atomisp_find_in_fmt_conv(sink->code);
                if (!fc)
                        return -EINVAL;
-               input_format = fc->css_stream_fmt;
+               input_format = fc->atomisp_in_fmt;
                bayer_order = fc->bayer_order;
        }
 
@@ -5041,7 +5054,7 @@ static inline int atomisp_set_sensor_mipi_to_isp(
                 mipi_info->metadata_format);
        if (!fc)
                return -EINVAL;
-       input_format = fc->css_stream_fmt;
+       input_format = fc->atomisp_in_fmt;
        atomisp_css_input_configure_port(asd,
                                         __get_mipi_port(asd->isp, mipi_info->port),
                                         mipi_info->num_lanes,
@@ -5062,7 +5075,7 @@ static int __enable_continuous_mode(struct atomisp_sub_device *asd,
                enable, asd->continuous_raw_buffer_size->val,
                !asd->continuous_viewfinder->val);
 
-       if (!atomisp_hw_is_isp2401)
+       if (!IS_ISP2401)
                atomisp_css_capture_set_mode(asd, IA_CSS_CAPTURE_MODE_PRIMARY);
        else
                atomisp_update_capture_mode(asd);
@@ -5191,7 +5204,7 @@ static int atomisp_set_fmt_to_isp(struct video_device *vdev,
                                      configure_pp_input_nop;
        u16 stream_index = atomisp_source_pad_to_stream_id(asd, source_pad);
        const struct atomisp_in_fmt_conv *fc;
-       int ret;
+       int ret, i;
 
        v4l2_fh_init(&fh.vfh, vdev);
 
@@ -5224,7 +5237,7 @@ static int atomisp_set_fmt_to_isp(struct video_device *vdev,
                if (!fc)
                        return -EINVAL;
                if (format->sh_fmt == IA_CSS_FRAME_FORMAT_RAW &&
-                   raw_output_format_match_input(fc->css_stream_fmt,
+                   raw_output_format_match_input(fc->atomisp_in_fmt,
                                                  pix->pixelformat))
                        return -EINVAL;
        }
@@ -5288,8 +5301,9 @@ static int atomisp_set_fmt_to_isp(struct video_device *vdev,
        }
 
        atomisp_css_input_set_mode(asd, IA_CSS_INPUT_MODE_BUFFERED_SENSOR);
-       atomisp_css_disable_vf_pp(asd,
-                                 asd->vfpp->val != ATOMISP_VFPP_ENABLE);
+
+       for (i = 0; i < IA_CSS_PIPE_ID_NUM; i++)
+               asd->stream_env[ATOMISP_INPUT_STREAM_GENERAL].pipe_extra_configs[i].disable_vf_pp = asd->vfpp->val != ATOMISP_VFPP_ENABLE;
 
        /* ISP2401 new input system need to use copy pipe */
        if (asd->copy_mode) {
@@ -5434,12 +5448,12 @@ static int atomisp_set_fmt_to_isp(struct video_device *vdev,
        atomisp_update_grid_info(asd, pipe_id, source_pad);
 
        /* Free the raw_dump buffer first */
-       atomisp_css_frame_free(asd->raw_output_frame);
+       ia_css_frame_free(asd->raw_output_frame);
        asd->raw_output_frame = NULL;
 
        if (!asd->continuous_mode->val &&
            !asd->params.online_process && !isp->sw_contex.file_input &&
-           atomisp_css_frame_allocate_from_info(&asd->raw_output_frame,
+           ia_css_frame_allocate_from_info(&asd->raw_output_frame,
                    raw_output_info))
                return -ENOMEM;
 
@@ -5952,7 +5966,7 @@ int atomisp_set_fmt(struct video_device *vdev, struct v4l2_format *f)
                 * which appears to be related by a hardware
                 * performance limitation.  It's unclear why this
                 * particular code triggers the issue. */
-               if (!atomisp_hw_is_isp2401 || crop_needs_override) {
+               if (!IS_ISP2401 || crop_needs_override) {
                        if (isp_sink_crop.width * main_compose.height >
                            isp_sink_crop.height * main_compose.width) {
                                sink_crop.height = isp_sink_crop.height;
@@ -6005,10 +6019,9 @@ done:
                                 output_info.padded_width, 8);
                pipe->pix.sizeimage =
                    PAGE_ALIGN(f->fmt.pix.height * pipe->pix.bytesperline);
-
        }
        dev_dbg(isp->dev, "%s: image size: %d, %d bytes per line\n",
-               __func__, pipe->pix.sizeimage,pipe-> pix.bytesperline);
+               __func__, pipe->pix.sizeimage, pipe->pix.bytesperline);
 
        if (f->fmt.pix.field == V4L2_FIELD_ANY)
                f->fmt.pix.field = V4L2_FIELD_NONE;
@@ -6087,7 +6100,7 @@ int atomisp_set_shading_table(struct atomisp_sub_device *asd,
                return -EINVAL;
 
        if (!user_shading_table->enable) {
-               atomisp_css_set_shading_table(asd, NULL);
+               asd->params.config.shading_table = NULL;
                asd->params.sc_en = false;
                return 0;
        }
@@ -6099,7 +6112,7 @@ int atomisp_set_shading_table(struct atomisp_sub_device *asd,
        }
 
        /* Shading table size per color */
-       if (!atomisp_hw_is_isp2401) {
+       if (!IS_ISP2401) {
                if (user_shading_table->width > ISP2400_SH_CSS_MAX_SCTBL_WIDTH_PER_COLOR ||
                    user_shading_table->height > ISP2400_SH_CSS_MAX_SCTBL_HEIGHT_PER_COLOR)
                        return -EINVAL;
@@ -6132,7 +6145,7 @@ int atomisp_set_shading_table(struct atomisp_sub_device *asd,
 
        free_table = asd->params.css_param.shading_table;
        asd->params.css_param.shading_table = shading_table;
-       atomisp_css_set_shading_table(asd, shading_table);
+       asd->params.config.shading_table = shading_table;
        asd->params.sc_en = true;
 
 out:
@@ -6633,7 +6646,7 @@ int atomisp_get_invalid_frame_num(struct video_device *vdev,
        ret = ia_css_pipe_get_info(
                  asd->stream_env[ATOMISP_INPUT_STREAM_GENERAL]
                  .pipes[pipe_id], &p_info);
-       if (ret == IA_CSS_SUCCESS) {
+       if (!ret) {
                *invalid_frame_num = p_info.num_invalid_frames;
                return 0;
        } else {