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 b003dc9..7b936e5 100644 (file)
@@ -1,3 +1,4 @@
+// SPDX-License-Identifier: GPL-2.0
 /*
  * Support for Medifield PNW Camera Imaging ISP subsystem.
  *
@@ -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;
        }
@@ -590,14 +595,14 @@ irqreturn_t atomisp_isr(int irq, void *dev)
                        /* 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--;
@@ -1217,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);
 
        /*
@@ -1237,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)
@@ -1405,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++) {
@@ -1473,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);
@@ -1596,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;
@@ -1612,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];
 
@@ -1669,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 {
@@ -1728,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)
@@ -1791,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);
@@ -3012,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;
@@ -3582,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)) {
@@ -3615,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!");
@@ -3698,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");
@@ -3841,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,
@@ -3976,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,
@@ -4166,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 {
@@ -4202,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__);
@@ -4966,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;
@@ -5025,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;
 
@@ -5035,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;
        }
 
@@ -5046,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,
@@ -5067,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);
@@ -5229,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;
        }
@@ -5958,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;
@@ -6104,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;