Re: [PATCH 02/14] davinci: vpfe: add IPIPE hardware layer support

2012-09-23 Thread Sakari Ailus

Hi Prabhakar,

Thanks for the patchset! I've got a few comments below.

Prabhakar Lad wrote:

From: Manjunath Hadli 

add dm365 IPIPE hardware support. IPIPE is the hardware IP which
implements the functionality required for resizer, previewer and
the associated feature support. This is built along with the vpfe
driver, and implements hardware setup including coeffcient
programming for various hardware filters, gamma, cfa and clock
enable.

Signed-off-by: Manjunath Hadli 
Signed-off-by: Lad, Prabhakar 
---
  drivers/media/platform/davinci/dm365_ipipe_hw.c |  936 +++
  drivers/media/platform/davinci/dm365_ipipe_hw.h |  538 +
  2 files changed, 1474 insertions(+), 0 deletions(-)
  create mode 100644 drivers/media/platform/davinci/dm365_ipipe_hw.c
  create mode 100644 drivers/media/platform/davinci/dm365_ipipe_hw.h

diff --git a/drivers/media/platform/davinci/dm365_ipipe_hw.c 
b/drivers/media/platform/davinci/dm365_ipipe_hw.c
new file mode 100644
index 000..4ce6d95
--- /dev/null
+++ b/drivers/media/platform/davinci/dm365_ipipe_hw.c
@@ -0,0 +1,936 @@
+/*
+ * Copyright (C) 2012 Texas Instruments Inc
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation version 2.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+ *
+ * Contributors:
+ *  Manjunath Hadli 
+ *  Prabhakar Lad 
+ */
+
+#include 
+#include 
+#include 
+#include 
+
+#include "dm365_ipipe.h"
+#include "dm3xx_ipipeif.h"
+#include "dm365_ipipe_hw.h"
+
+static void ipipe_clock_enable(void)
+{
+   /* enable IPIPE MMR for register write access */
+   regw_ip(IPIPE_GCK_MMR_DEFAULT, IPIPE_GCK_MMR);
+   /* enable the clock wb,cfa,dfc,d2f,pre modules */
+   regw_ip(IPIPE_GCK_PIX_DEFAULT, IPIPE_GCK_PIX);
+   /* enable RSZ MMR for register write access */
+}
+
+/* Set input channel format to either 420 Y or C format */
+void rsz_set_in_pix_format(unsigned char y_c)
+{
+   u32 val;
+
+   val = regr_rsz(RSZ_SRC_FMT1);
+   val |= y_c & 1;
+   regw_rsz(val, RSZ_SRC_FMT1);
+}
+
+static void rsz_set_common_params(struct ipipe_params *params)
+{
+   struct rsz_common_params *rsz_common = ¶ms->rsz_common;
+   u32 val;
+
+   /* Set mode */
+   regw_rsz(params->ipipe_mode, RSZ_SRC_MODE);
+
+   /* data source selection  and bypass */
+   val = (rsz_common->passthrough << RSZ_BYPASS_SHIFT) |
+   rsz_common->source;
+
+   regw_rsz(val, RSZ_SRC_FMT0);
+   val = regr_rsz(RSZ_SRC_MODE);


val is assigned but there's no need to.


+   /* src image selection */
+   val = (rsz_common->raw_flip & 1) |
+   (rsz_common->src_img_fmt << RSZ_SRC_IMG_FMT_SHIFT) |
+   ((rsz_common->y_c & 1) << RSZ_SRC_Y_C_SEL_SHIFT);
+
+   regw_rsz(val, RSZ_SRC_FMT1);
+   regw_rsz(rsz_common->vps & IPIPE_RSZ_VPS_MASK, RSZ_SRC_VPS);
+   regw_rsz(rsz_common->hps & IPIPE_RSZ_HPS_MASK, RSZ_SRC_HPS);
+   regw_rsz(rsz_common->vsz & IPIPE_RSZ_VSZ_MASK, RSZ_SRC_VSZ);
+   regw_rsz(rsz_common->hsz & IPIPE_RSZ_HSZ_MASK, RSZ_SRC_HSZ);
+   regw_rsz(rsz_common->yuv_y_min, RSZ_YUV_Y_MIN);
+   regw_rsz(rsz_common->yuv_y_max, RSZ_YUV_Y_MAX);
+   regw_rsz(rsz_common->yuv_c_min, RSZ_YUV_C_MIN);
+   regw_rsz(rsz_common->yuv_c_max, RSZ_YUV_C_MAX);
+   /* chromatic position */
+   regw_rsz(rsz_common->out_chr_pos, RSZ_YUV_PHS);
+   val = regr_rsz(RSZ_SRC_MODE);


Same here.


+}
+
+static void rsz_set_rsz_regs(unsigned int rsz_id, struct ipipe_params *params)
+{
+   struct ipipe_rsz_rescale_param *rsc_params;
+   struct ipipe_ext_mem_param *ext_mem;
+   struct ipipe_rsz_resize2rgb *rgb;
+   u32 reg_base;
+   u32 val;
+
+   val = regr_rsz(RSZ_SEQ);


And here.


+   rsc_params = ¶ms->rsz_rsc_param[rsz_id];
+   rgb = ¶ms->rsz2rgb[rsz_id];
+   ext_mem = ¶ms->ext_mem_param[rsz_id];
+
+   if (rsz_id == RSZ_A) {
+   val = rsc_params->h_flip << RSZA_H_FLIP_SHIFT;
+   val |= rsc_params->v_flip << RSZA_V_FLIP_SHIFT;
+   reg_base = RSZ_EN_A;
+   } else {
+   val = rsc_params->h_flip << RSZB_H_FLIP_SHIFT;
+   val |= rsc_params->v_flip << RSZB_V_FLIP_SHIFT;
+   reg_base = RSZ_EN_B;
+   }
+   /* update flip settings */
+   regw_rsz(val, RSZ_SEQ);
+
+   regw_rsz(rsc_params->mode, reg_base + RSZ_MODE);
+   val = (rsc_params->cen << RSZ_CEN_SHIFT) | rsc_params->yen;
+  

[PATCH 02/14] davinci: vpfe: add IPIPE hardware layer support

2012-09-14 Thread Prabhakar Lad
From: Manjunath Hadli 

add dm365 IPIPE hardware support. IPIPE is the hardware IP which
implements the functionality required for resizer, previewer and
the associated feature support. This is built along with the vpfe
driver, and implements hardware setup including coeffcient
programming for various hardware filters, gamma, cfa and clock
enable.

Signed-off-by: Manjunath Hadli 
Signed-off-by: Lad, Prabhakar 
---
 drivers/media/platform/davinci/dm365_ipipe_hw.c |  936 +++
 drivers/media/platform/davinci/dm365_ipipe_hw.h |  538 +
 2 files changed, 1474 insertions(+), 0 deletions(-)
 create mode 100644 drivers/media/platform/davinci/dm365_ipipe_hw.c
 create mode 100644 drivers/media/platform/davinci/dm365_ipipe_hw.h

diff --git a/drivers/media/platform/davinci/dm365_ipipe_hw.c 
b/drivers/media/platform/davinci/dm365_ipipe_hw.c
new file mode 100644
index 000..4ce6d95
--- /dev/null
+++ b/drivers/media/platform/davinci/dm365_ipipe_hw.c
@@ -0,0 +1,936 @@
+/*
+ * Copyright (C) 2012 Texas Instruments Inc
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation version 2.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+ *
+ * Contributors:
+ *  Manjunath Hadli 
+ *  Prabhakar Lad 
+ */
+
+#include 
+#include 
+#include 
+#include 
+
+#include "dm365_ipipe.h"
+#include "dm3xx_ipipeif.h"
+#include "dm365_ipipe_hw.h"
+
+static void ipipe_clock_enable(void)
+{
+   /* enable IPIPE MMR for register write access */
+   regw_ip(IPIPE_GCK_MMR_DEFAULT, IPIPE_GCK_MMR);
+   /* enable the clock wb,cfa,dfc,d2f,pre modules */
+   regw_ip(IPIPE_GCK_PIX_DEFAULT, IPIPE_GCK_PIX);
+   /* enable RSZ MMR for register write access */
+}
+
+/* Set input channel format to either 420 Y or C format */
+void rsz_set_in_pix_format(unsigned char y_c)
+{
+   u32 val;
+
+   val = regr_rsz(RSZ_SRC_FMT1);
+   val |= y_c & 1;
+   regw_rsz(val, RSZ_SRC_FMT1);
+}
+
+static void rsz_set_common_params(struct ipipe_params *params)
+{
+   struct rsz_common_params *rsz_common = ¶ms->rsz_common;
+   u32 val;
+
+   /* Set mode */
+   regw_rsz(params->ipipe_mode, RSZ_SRC_MODE);
+
+   /* data source selection  and bypass */
+   val = (rsz_common->passthrough << RSZ_BYPASS_SHIFT) |
+   rsz_common->source;
+
+   regw_rsz(val, RSZ_SRC_FMT0);
+   val = regr_rsz(RSZ_SRC_MODE);
+   /* src image selection */
+   val = (rsz_common->raw_flip & 1) |
+   (rsz_common->src_img_fmt << RSZ_SRC_IMG_FMT_SHIFT) |
+   ((rsz_common->y_c & 1) << RSZ_SRC_Y_C_SEL_SHIFT);
+
+   regw_rsz(val, RSZ_SRC_FMT1);
+   regw_rsz(rsz_common->vps & IPIPE_RSZ_VPS_MASK, RSZ_SRC_VPS);
+   regw_rsz(rsz_common->hps & IPIPE_RSZ_HPS_MASK, RSZ_SRC_HPS);
+   regw_rsz(rsz_common->vsz & IPIPE_RSZ_VSZ_MASK, RSZ_SRC_VSZ);
+   regw_rsz(rsz_common->hsz & IPIPE_RSZ_HSZ_MASK, RSZ_SRC_HSZ);
+   regw_rsz(rsz_common->yuv_y_min, RSZ_YUV_Y_MIN);
+   regw_rsz(rsz_common->yuv_y_max, RSZ_YUV_Y_MAX);
+   regw_rsz(rsz_common->yuv_c_min, RSZ_YUV_C_MIN);
+   regw_rsz(rsz_common->yuv_c_max, RSZ_YUV_C_MAX);
+   /* chromatic position */
+   regw_rsz(rsz_common->out_chr_pos, RSZ_YUV_PHS);
+   val = regr_rsz(RSZ_SRC_MODE);
+}
+
+static void rsz_set_rsz_regs(unsigned int rsz_id, struct ipipe_params *params)
+{
+   struct ipipe_rsz_rescale_param *rsc_params;
+   struct ipipe_ext_mem_param *ext_mem;
+   struct ipipe_rsz_resize2rgb *rgb;
+   u32 reg_base;
+   u32 val;
+
+   val = regr_rsz(RSZ_SEQ);
+   rsc_params = ¶ms->rsz_rsc_param[rsz_id];
+   rgb = ¶ms->rsz2rgb[rsz_id];
+   ext_mem = ¶ms->ext_mem_param[rsz_id];
+
+   if (rsz_id == RSZ_A) {
+   val = rsc_params->h_flip << RSZA_H_FLIP_SHIFT;
+   val |= rsc_params->v_flip << RSZA_V_FLIP_SHIFT;
+   reg_base = RSZ_EN_A;
+   } else {
+   val = rsc_params->h_flip << RSZB_H_FLIP_SHIFT;
+   val |= rsc_params->v_flip << RSZB_V_FLIP_SHIFT;
+   reg_base = RSZ_EN_B;
+   }
+   /* update flip settings */
+   regw_rsz(val, RSZ_SEQ);
+
+   regw_rsz(rsc_params->mode, reg_base + RSZ_MODE);
+   val = (rsc_params->cen << RSZ_CEN_SHIFT) | rsc_params->yen;
+   regw_rsz(val, reg_base + RSZ_420);
+   regw_rsz(rsc_params->i_vps & RSZ_VPS_MASK, reg_base + RSZ_I_VPS);
+   regw_rsz(rsc_params->i_hps & RSZ_HPS_MASK, reg_base