Commit dc8b931c authored by Paul Kocialkowski's avatar Paul Kocialkowski Committed by Mauro Carvalho Chehab

media: sun6i-csi: Implement address configuration without indirection

Instead of calculating the planar_offset at one point and using it
later in a dedicated function, reimplement address configuration
with v4l2 format info in the buffer_configure function.
Signed-off-by: default avatarPaul Kocialkowski <paul.kocialkowski@bootlin.com>
Acked-by: default avatarJernej Skrabec <jernej.skrabec@gmail.com>
Signed-off-by: default avatarSakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@kernel.org>
parent 0f6417f1
...@@ -463,7 +463,6 @@ static void sun6i_csi_set_window(struct sun6i_csi_device *csi_dev) ...@@ -463,7 +463,6 @@ static void sun6i_csi_set_window(struct sun6i_csi_device *csi_dev)
struct sun6i_csi_config *config = &csi_dev->config; struct sun6i_csi_config *config = &csi_dev->config;
u32 bytesperline_y; u32 bytesperline_y;
u32 bytesperline_c; u32 bytesperline_c;
int *planar_offset = csi_dev->planar_offset;
u32 width = config->width; u32 width = config->width;
u32 height = config->height; u32 height = config->height;
u32 hor_len = width; u32 hor_len = width;
...@@ -488,7 +487,6 @@ static void sun6i_csi_set_window(struct sun6i_csi_device *csi_dev) ...@@ -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_LEN(height) |
SUN6I_CSI_CH_VSIZE_START(0)); SUN6I_CSI_CH_VSIZE_START(0));
planar_offset[0] = 0;
switch (config->pixelformat) { switch (config->pixelformat) {
case V4L2_PIX_FMT_NV12_16L16: case V4L2_PIX_FMT_NV12_16L16:
case V4L2_PIX_FMT_NV12: case V4L2_PIX_FMT_NV12:
...@@ -497,23 +495,15 @@ static void sun6i_csi_set_window(struct sun6i_csi_device *csi_dev) ...@@ -497,23 +495,15 @@ static void sun6i_csi_set_window(struct sun6i_csi_device *csi_dev)
case V4L2_PIX_FMT_NV61: case V4L2_PIX_FMT_NV61:
bytesperline_y = width; bytesperline_y = width;
bytesperline_c = width; bytesperline_c = width;
planar_offset[1] = bytesperline_y * height;
planar_offset[2] = -1;
break; break;
case V4L2_PIX_FMT_YUV420: case V4L2_PIX_FMT_YUV420:
case V4L2_PIX_FMT_YVU420: case V4L2_PIX_FMT_YVU420:
bytesperline_y = width; bytesperline_y = width;
bytesperline_c = width / 2; bytesperline_c = width / 2;
planar_offset[1] = bytesperline_y * height;
planar_offset[2] = planar_offset[1] +
bytesperline_c * height / 2;
break; break;
case V4L2_PIX_FMT_YUV422P: case V4L2_PIX_FMT_YUV422P:
bytesperline_y = width; bytesperline_y = width;
bytesperline_c = width / 2; bytesperline_c = width / 2;
planar_offset[1] = bytesperline_y * height;
planar_offset[2] = planar_offset[1] +
bytesperline_c * height;
break; break;
default: /* raw */ default: /* raw */
dev_dbg(csi_dev->dev, dev_dbg(csi_dev->dev,
...@@ -522,8 +512,6 @@ static void sun6i_csi_set_window(struct sun6i_csi_device *csi_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) * bytesperline_y = (sun6i_csi_get_bpp(config->pixelformat) *
config->width) / 8; config->width) / 8;
bytesperline_c = 0; bytesperline_c = 0;
planar_offset[1] = -1;
planar_offset[2] = -1;
break; break;
} }
...@@ -547,21 +535,6 @@ int sun6i_csi_update_config(struct sun6i_csi_device *csi_dev, ...@@ -547,21 +535,6 @@ int sun6i_csi_update_config(struct sun6i_csi_device *csi_dev,
return 0; 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) void sun6i_csi_set_stream(struct sun6i_csi_device *csi_dev, bool enable)
{ {
struct regmap *regmap = csi_dev->regmap; struct regmap *regmap = csi_dev->regmap;
......
...@@ -60,8 +60,6 @@ struct sun6i_csi_device { ...@@ -60,8 +60,6 @@ struct sun6i_csi_device {
struct clk *clock_mod; struct clk *clock_mod;
struct clk *clock_ram; struct clk *clock_ram;
struct reset_control *reset; struct reset_control *reset;
int planar_offset[3];
}; };
struct sun6i_csi_variant { struct sun6i_csi_variant {
...@@ -98,14 +96,6 @@ int sun6i_csi_set_power(struct sun6i_csi_device *csi_dev, bool enable); ...@@ -98,14 +96,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, int sun6i_csi_update_config(struct sun6i_csi_device *csi_dev,
struct sun6i_csi_config *config); struct sun6i_csi_config *config);
/**
* sun6i_csi_update_buf_addr() - update the csi frame buffer address
* @csi_dev: pointer to the csi device
* @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 * sun6i_csi_set_stream() - start/stop csi streaming
* @csi_dev: pointer to the csi device * @csi_dev: pointer to the csi device
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
*/ */
#include <linux/of.h> #include <linux/of.h>
#include <linux/regmap.h>
#include <media/v4l2-device.h> #include <media/v4l2-device.h>
#include <media/v4l2-event.h> #include <media/v4l2-event.h>
...@@ -16,6 +17,7 @@ ...@@ -16,6 +17,7 @@
#include "sun6i_csi.h" #include "sun6i_csi.h"
#include "sun6i_csi_capture.h" #include "sun6i_csi_capture.h"
#include "sun6i_csi_reg.h"
/* This is got from BSP sources. */ /* This is got from BSP sources. */
#define MIN_WIDTH (32) #define MIN_WIDTH (32)
...@@ -109,13 +111,41 @@ static void ...@@ -109,13 +111,41 @@ static void
sun6i_csi_capture_buffer_configure(struct sun6i_csi_device *csi_dev, sun6i_csi_capture_buffer_configure(struct sun6i_csi_device *csi_dev,
struct sun6i_csi_buffer *csi_buffer) struct sun6i_csi_buffer *csi_buffer)
{ {
struct regmap *regmap = csi_dev->regmap;
const struct v4l2_format_info *info;
struct vb2_buffer *vb2_buffer; struct vb2_buffer *vb2_buffer;
unsigned int width, height;
dma_addr_t address; dma_addr_t address;
u32 pixelformat;
vb2_buffer = &csi_buffer->v4l2_buffer.vb2_buf; vb2_buffer = &csi_buffer->v4l2_buffer.vb2_buf;
address = vb2_dma_contig_plane_dma_addr(vb2_buffer, 0); 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) static void sun6i_csi_capture_configure(struct sun6i_csi_device *csi_dev)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment