@@ -463,7 +463,6 @@ static void sun6i_csi_set_window(struct sun6i_csi_device *csi_dev)
struct sun6i_csi_config *config = &csi_dev->config;
u32 bytesperline_y;
u32 bytesperline_c;
- int *planar_offset = csi_dev->planar_offset;
u32 width = config->width;
u32 height = config->height;
u32 hor_len = width;
@@ -488,7 +487,6 @@ static void sun6i_csi_set_window(struct sun6i_csi_device *csi_dev)
SUN6I_CSI_CH_VSIZE_LEN(height) |
SUN6I_CSI_CH_VSIZE_START(0));
- planar_offset[0] = 0;
switch (config->pixelformat) {
case V4L2_PIX_FMT_NV12_16L16:
case V4L2_PIX_FMT_NV12:
@@ -497,23 +495,15 @@ static void sun6i_csi_set_window(struct sun6i_csi_device *csi_dev)
case V4L2_PIX_FMT_NV61:
bytesperline_y = width;
bytesperline_c = width;
- planar_offset[1] = bytesperline_y * height;
- planar_offset[2] = -1;
break;
case V4L2_PIX_FMT_YUV420:
case V4L2_PIX_FMT_YVU420:
bytesperline_y = width;
bytesperline_c = width / 2;
- planar_offset[1] = bytesperline_y * height;
- planar_offset[2] = planar_offset[1] +
- bytesperline_c * height / 2;
break;
case V4L2_PIX_FMT_YUV422P:
bytesperline_y = width;
bytesperline_c = width / 2;
- planar_offset[1] = bytesperline_y * height;
- planar_offset[2] = planar_offset[1] +
- bytesperline_c * height;
break;
default: /* raw */
dev_dbg(csi_dev->dev,
@@ -522,8 +512,6 @@ static void sun6i_csi_set_window(struct sun6i_csi_device *csi_dev)
bytesperline_y = (sun6i_csi_get_bpp(config->pixelformat) *
config->width) / 8;
bytesperline_c = 0;
- planar_offset[1] = -1;
- planar_offset[2] = -1;
break;
}
@@ -547,21 +535,6 @@ int sun6i_csi_update_config(struct sun6i_csi_device *csi_dev,
return 0;
}
-void sun6i_csi_update_buf_addr(struct sun6i_csi_device *csi_dev,
- dma_addr_t addr)
-{
- regmap_write(csi_dev->regmap, SUN6I_CSI_CH_FIFO0_ADDR_REG,
- SUN6I_CSI_ADDR_VALUE(addr + csi_dev->planar_offset[0]));
- if (csi_dev->planar_offset[1] != -1)
- regmap_write(csi_dev->regmap, SUN6I_CSI_CH_FIFO1_ADDR_REG,
- SUN6I_CSI_ADDR_VALUE(addr +
- csi_dev->planar_offset[1]));
- if (csi_dev->planar_offset[2] != -1)
- regmap_write(csi_dev->regmap, SUN6I_CSI_CH_FIFO2_ADDR_REG,
- SUN6I_CSI_ADDR_VALUE(addr +
- csi_dev->planar_offset[2]));
-}
-
void sun6i_csi_set_stream(struct sun6i_csi_device *csi_dev, bool enable)
{
struct regmap *regmap = csi_dev->regmap;
@@ -60,8 +60,6 @@ struct sun6i_csi_device {
struct clk *clock_mod;
struct clk *clock_ram;
struct reset_control *reset;
-
- int planar_offset[3];
};
struct sun6i_csi_variant {
@@ -92,14 +90,6 @@ int sun6i_csi_set_power(struct sun6i_csi_device *csi_dev, bool enable);
int sun6i_csi_update_config(struct sun6i_csi_device *csi_dev,
struct sun6i_csi_config *config);
-/**
- * sun6i_csi_update_buf_addr() - update the csi frame buffer address
- * @csi: pointer to the csi
- * @addr: frame buffer's physical address
- */
-void sun6i_csi_update_buf_addr(struct sun6i_csi_device *csi_dev,
- dma_addr_t addr);
-
/**
* sun6i_csi_set_stream() - start/stop csi streaming
* @csi: pointer to the csi
@@ -6,6 +6,7 @@
*/
#include <linux/of.h>
+#include <linux/regmap.h>
#include <media/v4l2-device.h>
#include <media/v4l2-event.h>
@@ -16,6 +17,7 @@
#include "sun6i_csi.h"
#include "sun6i_csi_capture.h"
+#include "sun6i_csi_reg.h"
/* This is got from BSP sources. */
#define MIN_WIDTH (32)
@@ -109,13 +111,41 @@ static void
sun6i_csi_capture_buffer_configure(struct sun6i_csi_device *csi_dev,
struct sun6i_csi_buffer *csi_buffer)
{
+ struct regmap *regmap = csi_dev->regmap;
+ const struct v4l2_format_info *info;
struct vb2_buffer *vb2_buffer;
+ unsigned int width, height;
dma_addr_t address;
+ u32 pixelformat;
vb2_buffer = &csi_buffer->v4l2_buffer.vb2_buf;
address = vb2_dma_contig_plane_dma_addr(vb2_buffer, 0);
- sun6i_csi_update_buf_addr(csi_dev, address);
+ regmap_write(regmap, SUN6I_CSI_CH_FIFO0_ADDR_REG,
+ SUN6I_CSI_ADDR_VALUE(address));
+
+ sun6i_csi_capture_dimensions(csi_dev, &width, &height);
+ sun6i_csi_capture_format(csi_dev, &pixelformat, NULL);
+
+ info = v4l2_format_info(pixelformat);
+ /* Unsupported formats are single-plane, so we can stop here. */
+ if (!info)
+ return;
+
+ if (info->comp_planes > 1) {
+ address += info->bpp[0] * width * height;
+
+ regmap_write(regmap, SUN6I_CSI_CH_FIFO1_ADDR_REG,
+ SUN6I_CSI_ADDR_VALUE(address));
+ }
+
+ if (info->comp_planes > 2) {
+ address += info->bpp[1] * DIV_ROUND_UP(width, info->hdiv) *
+ DIV_ROUND_UP(height, info->vdiv);
+
+ regmap_write(regmap, SUN6I_CSI_CH_FIFO2_ADDR_REG,
+ SUN6I_CSI_ADDR_VALUE(address));
+ }
}
static void sun6i_csi_capture_configure(struct sun6i_csi_device *csi_dev)