}
 
 /* Tegra210 VI_CSI registers accessors */
-static void vi_csi_write(struct tegra_vi_channel *chan, unsigned int addr,
-                        u32 val)
+static void vi_csi_write(struct tegra_vi_channel *chan, u8 portno,
+                        unsigned int addr, u32 val)
 {
        void __iomem *vi_csi_base;
 
-       vi_csi_base = chan->vi->iomem + TEGRA210_VI_CSI_BASE(chan->portno);
+       vi_csi_base = chan->vi->iomem + TEGRA210_VI_CSI_BASE(portno);
 
        writel_relaxed(val, vi_csi_base + addr);
 }
 
-static u32 vi_csi_read(struct tegra_vi_channel *chan, unsigned int addr)
+static u32 vi_csi_read(struct tegra_vi_channel *chan, u8 portno,
+                      unsigned int addr)
 {
        void __iomem *vi_csi_base;
 
-       vi_csi_base = chan->vi->iomem + TEGRA210_VI_CSI_BASE(chan->portno);
+       vi_csi_base = chan->vi->iomem + TEGRA210_VI_CSI_BASE(portno);
 
        return readl_relaxed(vi_csi_base + addr);
 }
 /*
  * Tegra210 VI channel capture operations
  */
-static int tegra_channel_capture_setup(struct tegra_vi_channel *chan)
+static int tegra_channel_capture_setup(struct tegra_vi_channel *chan,
+                                      u8 portno)
 {
        u32 height = chan->format.height;
        u32 width = chan->format.width;
            data_type == TEGRA_IMAGE_DT_RGB888)
                bypass_pixel_transform = 0;
 
-       vi_csi_write(chan, TEGRA_VI_CSI_ERROR_STATUS, 0xffffffff);
-       vi_csi_write(chan, TEGRA_VI_CSI_IMAGE_DEF,
+       /*
+        * For x8 source streaming, the source image is split onto two x4 ports
+        * with left half to first x4 port and right half to second x4 port.
+        * So, use split width and corresponding word count for each x4 port.
+        */
+       if (chan->numgangports > 1) {
+               width = width >> 1;
+               word_count = (width * chan->fmtinfo->bit_width) / 8;
+       }
+
+       vi_csi_write(chan, portno, TEGRA_VI_CSI_ERROR_STATUS, 0xffffffff);
+       vi_csi_write(chan, portno, TEGRA_VI_CSI_IMAGE_DEF,
                     bypass_pixel_transform |
                     (format << IMAGE_DEF_FORMAT_OFFSET) |
                     IMAGE_DEF_DEST_MEM);
-       vi_csi_write(chan, TEGRA_VI_CSI_IMAGE_DT, data_type);
-       vi_csi_write(chan, TEGRA_VI_CSI_IMAGE_SIZE_WC, word_count);
-       vi_csi_write(chan, TEGRA_VI_CSI_IMAGE_SIZE,
+       vi_csi_write(chan, portno, TEGRA_VI_CSI_IMAGE_DT, data_type);
+       vi_csi_write(chan, portno, TEGRA_VI_CSI_IMAGE_SIZE_WC, word_count);
+       vi_csi_write(chan, portno, TEGRA_VI_CSI_IMAGE_SIZE,
                     (height << IMAGE_SIZE_HEIGHT_OFFSET) | width);
        return 0;
 }
 
-static void tegra_channel_vi_soft_reset(struct tegra_vi_channel *chan)
+static void tegra_channel_vi_soft_reset(struct tegra_vi_channel *chan,
+                                       u8 portno)
 {
        /* disable clock gating to enable continuous clock */
        tegra_vi_write(chan, TEGRA_VI_CFG_CG_CTRL, 0);
         * Soft reset memory client interface, pixel format logic, sensor
         * control logic, and a shadow copy logic to bring VI to clean state.
         */
-       vi_csi_write(chan, TEGRA_VI_CSI_SW_RESET, 0xf);
+       vi_csi_write(chan, portno, TEGRA_VI_CSI_SW_RESET, 0xf);
        usleep_range(100, 200);
-       vi_csi_write(chan, TEGRA_VI_CSI_SW_RESET, 0x0);
+       vi_csi_write(chan, portno, TEGRA_VI_CSI_SW_RESET, 0x0);
 
        /* enable back VI clock gating */
        tegra_vi_write(chan, TEGRA_VI_CFG_CG_CTRL, VI_CG_2ND_LEVEL_EN);
 }
 
-static void tegra_channel_capture_error_recover(struct tegra_vi_channel *chan)
+static void tegra_channel_capture_error_recover(struct tegra_vi_channel *chan,
+                                               u8 portno)
 {
        struct v4l2_subdev *subdev;
        u32 val;
         * events which can cause CSI and VI hardware hang.
         * This helps to have a clean capture for next frame.
         */
-       val = vi_csi_read(chan, TEGRA_VI_CSI_ERROR_STATUS);
+       val = vi_csi_read(chan, portno, TEGRA_VI_CSI_ERROR_STATUS);
        dev_dbg(&chan->video.dev, "TEGRA_VI_CSI_ERROR_STATUS 0x%08x\n", val);
-       vi_csi_write(chan, TEGRA_VI_CSI_ERROR_STATUS, val);
+       vi_csi_write(chan, portno, TEGRA_VI_CSI_ERROR_STATUS, val);
 
        val = tegra_vi_read(chan, TEGRA_VI_CFG_VI_INCR_SYNCPT_ERROR);
        dev_dbg(&chan->video.dev,
        tegra_vi_write(chan, TEGRA_VI_CFG_VI_INCR_SYNCPT_ERROR, val);
 
        /* recover VI by issuing software reset and re-setup for capture */
-       tegra_channel_vi_soft_reset(chan);
-       tegra_channel_capture_setup(chan);
+       tegra_channel_vi_soft_reset(chan, portno);
+       tegra_channel_capture_setup(chan, portno);
 
        /* recover CSI block */
        subdev = tegra_channel_get_remote_csi_subdev(chan);
        vb2_buffer_done(&vb->vb2_buf, state);
 }
 
-static int tegra_channel_capture_frame(struct tegra_vi_channel *chan,
-                                      struct tegra_channel_buffer *buf)
+static void tegra_channel_vi_buffer_setup(struct tegra_vi_channel *chan,
+                                         u8 portno, u32 buf_offset,
+                                         struct tegra_channel_buffer *buf)
 {
-       u32 thresh, value, frame_start, mw_ack_done;
-       int bytes_per_line = chan->format.bytesperline;
+       int bytesperline = chan->format.bytesperline;
        u32 sizeimage = chan->format.sizeimage;
-       int err;
 
        /* program buffer address by using surface 0 */
-       vi_csi_write(chan, TEGRA_VI_CSI_SURFACE0_OFFSET_MSB,
-                    (u64)buf->addr >> 32);
-       vi_csi_write(chan, TEGRA_VI_CSI_SURFACE0_OFFSET_LSB, buf->addr);
-       vi_csi_write(chan, TEGRA_VI_CSI_SURFACE0_STRIDE, bytes_per_line);
+       vi_csi_write(chan, portno, TEGRA_VI_CSI_SURFACE0_OFFSET_MSB,
+                    ((u64)buf->addr + buf_offset) >> 32);
+       vi_csi_write(chan, portno, TEGRA_VI_CSI_SURFACE0_OFFSET_LSB,
+                    buf->addr + buf_offset);
+       vi_csi_write(chan, portno, TEGRA_VI_CSI_SURFACE0_STRIDE, bytesperline);
 
+       if (chan->fmtinfo->fourcc != V4L2_PIX_FMT_NV16)
+               return;
        /*
         * Program surface 1 for UV plane with offset sizeimage from Y plane.
         */
-       if (chan->fmtinfo->fourcc == V4L2_PIX_FMT_NV16) {
-               vi_csi_write(chan, TEGRA_VI_CSI_SURFACE1_OFFSET_MSB,
-                            ((u64)buf->addr + sizeimage / 2) >> 32);
-               vi_csi_write(chan, TEGRA_VI_CSI_SURFACE1_OFFSET_LSB,
-                            buf->addr + sizeimage / 2);
-               vi_csi_write(chan, TEGRA_VI_CSI_SURFACE1_STRIDE,
-                            bytes_per_line);
-       }
-
-       /*
-        * Tegra VI block interacts with host1x syncpt for synchronizing
-        * programmed condition of capture state and hardware operation.
-        * Frame start and Memory write acknowledge syncpts has their own
-        * FIFO of depth 2.
-        *
-        * Syncpoint trigger conditions set through VI_INCR_SYNCPT register
-        * are added to HW syncpt FIFO and when the HW triggers, syncpt
-        * condition is removed from the FIFO and counter at syncpoint index
-        * will be incremented by the hardware and software can wait for
-        * counter to reach threshold to synchronize capturing frame with the
-        * hardware capture events.
-        */
+       vi_csi_write(chan, portno, TEGRA_VI_CSI_SURFACE1_OFFSET_MSB,
+                    (((u64)buf->addr + sizeimage / 2) + buf_offset) >> 32);
+       vi_csi_write(chan, portno, TEGRA_VI_CSI_SURFACE1_OFFSET_LSB,
+                    buf->addr + sizeimage / 2 + buf_offset);
+       vi_csi_write(chan, portno, TEGRA_VI_CSI_SURFACE1_STRIDE, bytesperline);
+}
 
-       /* increase channel syncpoint threshold for FRAME_START */
-       thresh = host1x_syncpt_incr_max(chan->frame_start_sp, 1);
+static int tegra_channel_capture_frame(struct tegra_vi_channel *chan,
+                                      struct tegra_channel_buffer *buf)
+{
+       u32 thresh, value, frame_start, mw_ack_done;
+       u32 fs_thresh[GANG_PORTS_MAX];
+       u8 *portnos = chan->portnos;
+       int gang_bpl = (chan->format.width >> 1) * chan->fmtinfo->bpp;
+       u32 buf_offset;
+       bool capture_timedout = false;
+       int err, i;
+
+       for (i = 0; i < chan->numgangports; i++) {
+               /*
+                * Align buffers side-by-side for all consecutive x4 ports
+                * in gang ports using bytes per line based on source split
+                * width.
+                */
+               buf_offset = i * roundup(gang_bpl, SURFACE_ALIGN_BYTES);
+               tegra_channel_vi_buffer_setup(chan, portnos[i], buf_offset,
+                                             buf);
 
-       /* Program FRAME_START trigger condition syncpt request */
-       frame_start = VI_CSI_PP_FRAME_START(chan->portno);
-       value = VI_CFG_VI_INCR_SYNCPT_COND(frame_start) |
-               host1x_syncpt_id(chan->frame_start_sp);
-       tegra_vi_write(chan, TEGRA_VI_CFG_VI_INCR_SYNCPT, value);
+               /*
+                * Tegra VI block interacts with host1x syncpt to synchronize
+                * programmed condition and hardware operation for capture.
+                * Frame start and Memory write acknowledge syncpts has their
+                * own FIFO of depth 2.
+                *
+                * Syncpoint trigger conditions set through VI_INCR_SYNCPT
+                * register are added to HW syncpt FIFO and when HW triggers,
+                * syncpt condition is removed from the FIFO and counter at
+                * syncpoint index will be incremented by the hardware and
+                * software can wait for counter to reach threshold to
+                * synchronize capturing frame with hardware capture events.
+                */
 
-       /* increase channel syncpoint threshold for MW_ACK_DONE */
-       buf->mw_ack_sp_thresh = host1x_syncpt_incr_max(chan->mw_ack_sp, 1);
+               /* increase channel syncpoint threshold for FRAME_START */
+               thresh = host1x_syncpt_incr_max(chan->frame_start_sp[i], 1);
+               fs_thresh[i] = thresh;
+
+               /* Program FRAME_START trigger condition syncpt request */
+               frame_start = VI_CSI_PP_FRAME_START(portnos[i]);
+               value = VI_CFG_VI_INCR_SYNCPT_COND(frame_start) |
+                       host1x_syncpt_id(chan->frame_start_sp[i]);
+               tegra_vi_write(chan, TEGRA_VI_CFG_VI_INCR_SYNCPT, value);
+
+               /* increase channel syncpoint threshold for MW_ACK_DONE */
+               thresh = host1x_syncpt_incr_max(chan->mw_ack_sp[i], 1);
+               buf->mw_ack_sp_thresh[i] = thresh;
+
+               /* Program MW_ACK_DONE trigger condition syncpt request */
+               mw_ack_done = VI_CSI_MW_ACK_DONE(portnos[i]);
+               value = VI_CFG_VI_INCR_SYNCPT_COND(mw_ack_done) |
+                       host1x_syncpt_id(chan->mw_ack_sp[i]);
+               tegra_vi_write(chan, TEGRA_VI_CFG_VI_INCR_SYNCPT, value);
+       }
 
-       /* Program MW_ACK_DONE trigger condition syncpt request */
-       mw_ack_done = VI_CSI_MW_ACK_DONE(chan->portno);
-       value = VI_CFG_VI_INCR_SYNCPT_COND(mw_ack_done) |
-               host1x_syncpt_id(chan->mw_ack_sp);
-       tegra_vi_write(chan, TEGRA_VI_CFG_VI_INCR_SYNCPT, value);
+       /* enable single shot capture after all ganged ports are ready */
+       for (i = 0; i < chan->numgangports; i++)
+               vi_csi_write(chan, portnos[i], TEGRA_VI_CSI_SINGLE_SHOT,
+                            SINGLE_SHOT_CAPTURE);
 
-       /* enable single shot capture */
-       vi_csi_write(chan, TEGRA_VI_CSI_SINGLE_SHOT, SINGLE_SHOT_CAPTURE);
+       for (i = 0; i < chan->numgangports; i++) {
+               /*
+                * Wait for syncpt counter to reach frame start event threshold
+                */
+               err = host1x_syncpt_wait(chan->frame_start_sp[i], fs_thresh[i],
+                                        TEGRA_VI_SYNCPT_WAIT_TIMEOUT, &value);
+               if (err) {
+                       capture_timedout = true;
+                       /* increment syncpoint counter for timedout events */
+                       host1x_syncpt_incr(chan->frame_start_sp[i]);
+                       spin_lock(&chan->sp_incr_lock[i]);
+                       host1x_syncpt_incr(chan->mw_ack_sp[i]);
+                       spin_unlock(&chan->sp_incr_lock[i]);
+                       /* clear errors and recover */
+                       tegra_channel_capture_error_recover(chan, portnos[i]);
+               }
+       }
 
-       /* wait for syncpt counter to reach frame start event threshold */
-       err = host1x_syncpt_wait(chan->frame_start_sp, thresh,
-                                TEGRA_VI_SYNCPT_WAIT_TIMEOUT, &value);
-       if (err) {
+       if (capture_timedout) {
                dev_err_ratelimited(&chan->video.dev,
                                    "frame start syncpt timeout: %d\n", err);
-               /* increment syncpoint counter for timedout events */
-               host1x_syncpt_incr(chan->frame_start_sp);
-               spin_lock(&chan->sp_incr_lock);
-               host1x_syncpt_incr(chan->mw_ack_sp);
-               spin_unlock(&chan->sp_incr_lock);
-               /* clear errors and recover */
-               tegra_channel_capture_error_recover(chan);
                release_buffer(chan, buf, VB2_BUF_STATE_ERROR);
                return err;
        }
 {
        enum vb2_buffer_state state = VB2_BUF_STATE_DONE;
        u32 value;
-       int ret;
+       bool capture_timedout = false;
+       int ret, i;
 
-       /* wait for syncpt counter to reach MW_ACK_DONE event threshold */
-       ret = host1x_syncpt_wait(chan->mw_ack_sp, buf->mw_ack_sp_thresh,
-                                TEGRA_VI_SYNCPT_WAIT_TIMEOUT, &value);
-       if (ret) {
-               dev_err_ratelimited(&chan->video.dev,
-                                   "MW_ACK_DONE syncpt timeout: %d\n", ret);
-               state = VB2_BUF_STATE_ERROR;
-               /* increment syncpoint counter for timedout event */
-               spin_lock(&chan->sp_incr_lock);
-               host1x_syncpt_incr(chan->mw_ack_sp);
-               spin_unlock(&chan->sp_incr_lock);
+       for (i = 0; i < chan->numgangports; i++) {
+               /*
+                * Wait for syncpt counter to reach MW_ACK_DONE event threshold
+                */
+               ret = host1x_syncpt_wait(chan->mw_ack_sp[i],
+                                        buf->mw_ack_sp_thresh[i],
+                                        TEGRA_VI_SYNCPT_WAIT_TIMEOUT, &value);
+               if (ret) {
+                       capture_timedout = true;
+                       state = VB2_BUF_STATE_ERROR;
+                       /* increment syncpoint counter for timedout event */
+                       spin_lock(&chan->sp_incr_lock[i]);
+                       host1x_syncpt_incr(chan->mw_ack_sp[i]);
+                       spin_unlock(&chan->sp_incr_lock[i]);
+               }
        }
 
+       if (capture_timedout)
+               dev_err_ratelimited(&chan->video.dev,
+                                   "MW_ACK_DONE syncpt timeout: %d\n", ret);
        release_buffer(chan, buf, state);
 }
 
        struct tegra_vi_channel *chan = vb2_get_drv_priv(vq);
        struct media_pipeline *pipe = &chan->video.pipe;
        u32 val;
-       int ret;
+       u8 *portnos = chan->portnos;
+       int ret, i;
 
        tegra_vi_write(chan, TEGRA_VI_CFG_CG_CTRL, VI_CG_2ND_LEVEL_EN);
 
-       /* clear errors */
-       val = vi_csi_read(chan, TEGRA_VI_CSI_ERROR_STATUS);
-       vi_csi_write(chan, TEGRA_VI_CSI_ERROR_STATUS, val);
-
+       /* clear syncpt errors */
        val = tegra_vi_read(chan, TEGRA_VI_CFG_VI_INCR_SYNCPT_ERROR);
        tegra_vi_write(chan, TEGRA_VI_CFG_VI_INCR_SYNCPT_ERROR, val);
 
        if (ret < 0)
                goto error_pipeline_start;
 
-       tegra_channel_capture_setup(chan);
+       /* clear csi errors and do capture setup for all ports in gang mode */
+       for (i = 0; i < chan->numgangports; i++) {
+               val = vi_csi_read(chan, portnos[i], TEGRA_VI_CSI_ERROR_STATUS);
+               vi_csi_write(chan, portnos[i], TEGRA_VI_CSI_ERROR_STATUS, val);
+
+               tegra_channel_capture_setup(chan, portnos[i]);
+       }
+
        ret = tegra_channel_set_stream(chan, true);
        if (ret < 0)
                goto error_set_stream;
 /*
  * Tegra210 CSI operations
  */
-static void tegra210_csi_error_recover(struct tegra_csi_channel *csi_chan)
+static void tegra210_csi_port_recover(struct tegra_csi_channel *csi_chan,
+                                     u8 portno)
 {
        struct tegra_csi *csi = csi_chan->csi;
-       unsigned int portno = csi_chan->csi_port_num;
        u32 val;
 
        /*
        }
 }
 
-static int tegra210_csi_start_streaming(struct tegra_csi_channel *csi_chan)
+static void tegra210_csi_error_recover(struct tegra_csi_channel *csi_chan)
+{
+       u8 *portnos = csi_chan->csi_port_nums;
+       int i;
+
+       for (i = 0; i < csi_chan->numgangports; i++)
+               tegra210_csi_port_recover(csi_chan, portnos[i]);
+}
+
+static int
+tegra210_csi_port_start_streaming(struct tegra_csi_channel *csi_chan,
+                                 u8 portno)
 {
        struct tegra_csi *csi = csi_chan->csi;
-       unsigned int portno = csi_chan->csi_port_num;
        u8 clk_settle_time = 0;
        u8 ths_settle_time = 10;
        u32 val;
 
        if (!csi_chan->pg_mode)
-               tegra_csi_calc_settle_time(csi_chan, &clk_settle_time,
+               tegra_csi_calc_settle_time(csi_chan, portno, &clk_settle_time,
                                           &ths_settle_time);
 
        csi_write(csi, portno, TEGRA_CSI_CLKEN_OVERRIDE, 0);
        return 0;
 }
 
-static void tegra210_csi_stop_streaming(struct tegra_csi_channel *csi_chan)
+static void
+tegra210_csi_port_stop_streaming(struct tegra_csi_channel *csi_chan, u8 portno)
 {
        struct tegra_csi *csi = csi_chan->csi;
-       unsigned int portno = csi_chan->csi_port_num;
        u32 val;
 
        val = pp_read(csi, portno, TEGRA_CSI_PIXEL_PARSER_STATUS);
        }
 }
 
+static int tegra210_csi_start_streaming(struct tegra_csi_channel *csi_chan)
+{
+       u8 *portnos = csi_chan->csi_port_nums;
+       int ret, i;
+
+       for (i = 0; i < csi_chan->numgangports; i++) {
+               ret = tegra210_csi_port_start_streaming(csi_chan, portnos[i]);
+               if (ret)
+                       goto stream_start_fail;
+       }
+
+       return 0;
+
+stream_start_fail:
+       for (i = i - 1; i >= 0; i--)
+               tegra210_csi_port_stop_streaming(csi_chan, portnos[i]);
+
+       return ret;
+}
+
+static void tegra210_csi_stop_streaming(struct tegra_csi_channel *csi_chan)
+{
+       u8 *portnos = csi_chan->csi_port_nums;
+       int i;
+
+       for (i = 0; i < csi_chan->numgangports; i++)
+               tegra210_csi_port_stop_streaming(csi_chan, portnos[i]);
+}
+
 /*
  * Tegra210 CSI TPG frame rate table with horizontal and vertical
  * blanking intervals for corresponding format and resolution.
 
 #include "vi.h"
 #include "video.h"
 
-#define SURFACE_ALIGN_BYTES            64
 #define MAX_CID_CONTROLS               1
 
 static const struct tegra_video_format tegra_default_format = {
        return __tegra_channel_try_format(chan, &format->fmt.pix);
 }
 
+static void tegra_channel_update_gangports(struct tegra_vi_channel *chan)
+{
+       if (chan->format.width <= 1920)
+               chan->numgangports = 1;
+       else
+               chan->numgangports = chan->totalports;
+}
+
 static int tegra_channel_set_format(struct file *file, void *fh,
                                    struct v4l2_format *format)
 {
 
        chan->format = *pix;
        chan->fmtinfo = fmtinfo;
+       tegra_channel_update_gangports(chan);
 
        return 0;
 }
        chan->format.sizeimage = chan->format.bytesperline *
                                 chan->format.height;
        tegra_channel_fmt_align(chan, &chan->format, chan->fmtinfo->bpp);
+       tegra_channel_update_gangports(chan);
 
        return 0;
 }
        chan->format.bytesperline = bt->width * chan->fmtinfo->bpp;
        chan->format.sizeimage = chan->format.bytesperline * bt->height;
        tegra_channel_fmt_align(chan, &chan->format, chan->fmtinfo->bpp);
+       tegra_channel_update_gangports(chan);
 
        return 0;
 }
        return 0;
 }
 
+static void tegra_channel_host1x_syncpts_free(struct tegra_vi_channel *chan)
+{
+       int i;
+
+       for (i = 0; i < chan->numgangports; i++) {
+               host1x_syncpt_free(chan->mw_ack_sp[i]);
+               host1x_syncpt_free(chan->frame_start_sp[i]);
+       }
+}
+
 static void tegra_channel_cleanup(struct tegra_vi_channel *chan)
 {
        v4l2_ctrl_handler_free(&chan->ctrl_handler);
        media_entity_cleanup(&chan->video.entity);
-       host1x_syncpt_free(chan->mw_ack_sp);
-       host1x_syncpt_free(chan->frame_start_sp);
+       tegra_channel_host1x_syncpts_free(chan);
        mutex_destroy(&chan->video_lock);
 }
 
        }
 }
 
+static int tegra_channel_host1x_syncpt_init(struct tegra_vi_channel *chan)
+{
+       struct tegra_vi *vi = chan->vi;
+       unsigned long flags = HOST1X_SYNCPT_CLIENT_MANAGED;
+       struct host1x_syncpt *fs_sp;
+       struct host1x_syncpt *mw_sp;
+       int ret, i;
+
+       for (i = 0; i < chan->numgangports; i++) {
+               fs_sp = host1x_syncpt_request(&vi->client, flags);
+               if (!fs_sp) {
+                       dev_err(vi->dev, "failed to request frame start syncpoint\n");
+                       ret = -ENOMEM;
+                       goto free_syncpts;
+               }
+
+               mw_sp = host1x_syncpt_request(&vi->client, flags);
+               if (!mw_sp) {
+                       dev_err(vi->dev, "failed to request memory ack syncpoint\n");
+                       host1x_syncpt_free(fs_sp);
+                       ret = -ENOMEM;
+                       goto free_syncpts;
+               }
+
+               chan->frame_start_sp[i] = fs_sp;
+               chan->mw_ack_sp[i] = mw_sp;
+               spin_lock_init(&chan->sp_incr_lock[i]);
+       }
+
+       return 0;
+
+free_syncpts:
+       tegra_channel_host1x_syncpts_free(chan);
+       return ret;
+}
+
 static int tegra_channel_init(struct tegra_vi_channel *chan)
 {
        struct tegra_vi *vi = chan->vi;
        struct tegra_video_device *vid = dev_get_drvdata(vi->client.host);
-       unsigned long flags = HOST1X_SYNCPT_CLIENT_MANAGED;
        int ret;
 
        mutex_init(&chan->video_lock);
        INIT_LIST_HEAD(&chan->done);
        spin_lock_init(&chan->start_lock);
        spin_lock_init(&chan->done_lock);
-       spin_lock_init(&chan->sp_incr_lock);
        init_waitqueue_head(&chan->start_wait);
        init_waitqueue_head(&chan->done_wait);
 
        chan->format.sizeimage = chan->format.bytesperline * TEGRA_DEF_HEIGHT;
        tegra_channel_fmt_align(chan, &chan->format, chan->fmtinfo->bpp);
 
-       chan->frame_start_sp = host1x_syncpt_request(&vi->client, flags);
-       if (!chan->frame_start_sp) {
-               dev_err(vi->dev, "failed to request frame start syncpoint\n");
-               return -ENOMEM;
-       }
-
-       chan->mw_ack_sp = host1x_syncpt_request(&vi->client, flags);
-       if (!chan->mw_ack_sp) {
-               dev_err(vi->dev, "failed to request memory ack syncpoint\n");
-               ret = -ENOMEM;
-               goto free_fs_syncpt;
-       }
+       ret = tegra_channel_host1x_syncpt_init(chan);
+       if (ret)
+               return ret;
 
        /* initialize the media entity */
        chan->pad.flags = MEDIA_PAD_FL_SINK;
        if (ret < 0) {
                dev_err(vi->dev,
                        "failed to initialize media entity: %d\n", ret);
-               goto free_mw_ack_syncpt;
+               goto free_syncpts;
        }
 
        ret = v4l2_ctrl_handler_init(&chan->ctrl_handler, MAX_CID_CONTROLS);
        chan->video.release = video_device_release_empty;
        chan->video.queue = &chan->queue;
        snprintf(chan->video.name, sizeof(chan->video.name), "%s-%s-%u",
-                dev_name(vi->dev), "output", chan->portno);
+                dev_name(vi->dev), "output", chan->portnos[0]);
        chan->video.vfl_type = VFL_TYPE_VIDEO;
        chan->video.vfl_dir = VFL_DIR_RX;
        chan->video.ioctl_ops = &tegra_channel_ioctl_ops;
        v4l2_ctrl_handler_free(&chan->ctrl_handler);
 cleanup_media:
        media_entity_cleanup(&chan->video.entity);
-free_mw_ack_syncpt:
-       host1x_syncpt_free(chan->mw_ack_sp);
-free_fs_syncpt:
-       host1x_syncpt_free(chan->frame_start_sp);
+free_syncpts:
+       tegra_channel_host1x_syncpts_free(chan);
        return ret;
 }
 
 static int tegra_vi_channel_alloc(struct tegra_vi *vi, unsigned int port_num,
-                                 struct device_node *node)
+                                 struct device_node *node, unsigned int lanes)
 {
        struct tegra_vi_channel *chan;
+       unsigned int i;
 
        /*
         * Do not use devm_kzalloc as memory is freed immediately
                return -ENOMEM;
 
        chan->vi = vi;
-       chan->portno = port_num;
+       chan->portnos[0] = port_num;
+       /*
+        * For data lanes more than maximum csi lanes per brick, multiple of
+        * x4 ports are used simultaneously for capture.
+        */
+       if (lanes <= CSI_LANES_PER_BRICK)
+               chan->totalports = 1;
+       else
+               chan->totalports = lanes / CSI_LANES_PER_BRICK;
+       chan->numgangports = chan->totalports;
+
+       for (i = 1; i < chan->totalports; i++)
+               chan->portnos[i] = chan->portnos[0] + i * CSI_PORTS_PER_BRICK;
+
        chan->of_node = node;
        list_add_tail(&chan->list, &vi->vi_chans);
 
        int ret;
 
        for (port_num = 0; port_num < nchannels; port_num++) {
-               ret = tegra_vi_channel_alloc(vi, port_num, vi->dev->of_node);
+               ret = tegra_vi_channel_alloc(vi, port_num,
+                                            vi->dev->of_node, 2);
                if (ret < 0)
                        return ret;
        }
        struct device_node *ports;
        struct device_node *port;
        unsigned int port_num;
+       struct device_node *parent;
+       struct v4l2_fwnode_endpoint v4l2_ep = { .bus_type = 0 };
+       unsigned int lanes;
        int ret = 0;
 
        ports = of_get_child_by_name(node, "ports");
                if (!ep)
                        continue;
 
+               parent = of_graph_get_remote_port_parent(ep);
+               of_node_put(ep);
+               if (!parent)
+                       continue;
+
+               ep = of_graph_get_endpoint_by_regs(parent, 0, 0);
+               of_node_put(parent);
+               ret = v4l2_fwnode_endpoint_parse(of_fwnode_handle(ep),
+                                                &v4l2_ep);
                of_node_put(ep);
-               ret = tegra_vi_channel_alloc(vi, port_num, port);
+               if (ret)
+                       continue;
+
+               lanes = v4l2_ep.bus.mipi_csi2.num_data_lanes;
+               ret = tegra_vi_channel_alloc(vi, port_num, port, lanes);
                if (ret < 0) {
                        of_node_put(port);
                        goto cleanup;
                if (ret < 0) {
                        dev_err(vi->dev,
                                "failed to initialize channel-%d: %d\n",
-                               chan->portno, ret);
+                               chan->portnos[0], ret);
                        goto cleanup;
                }
        }
         * next channels.
         */
        list_for_each_entry(chan, &vi->vi_chans, list) {
-               remote = fwnode_graph_get_remote_node(fwnode, chan->portno, 0);
+               remote = fwnode_graph_get_remote_node(fwnode, chan->portnos[0],
+                                                     0);
                if (!remote)
                        continue;
 
                if (ret < 0) {
                        dev_err(vi->dev,
                                "failed to register channel %d notifier: %d\n",
-                               chan->portno, ret);
+                               chan->portnos[0], ret);
                        v4l2_async_notifier_cleanup(&chan->notifier);
                }
        }
        if (!IS_ENABLED(CONFIG_VIDEO_TEGRA_TPG)) {
                ret = tegra_vi_graph_init(vi);
                if (ret < 0)
-                       goto free_chans;
+                       goto cleanup_chans;
        }
 
        return 0;
 
+cleanup_chans:
+       list_for_each_entry(chan, &vi->vi_chans, list)
+               tegra_channel_cleanup(chan);
 free_chans:
        list_for_each_entry_safe(chan, tmp, &vi->vi_chans, list) {
                list_del(&chan->list);