Skip to contentSkip to conversation

video: sh_mobile_ceu cleanups and comments V2

PATCH In review Magnus Damm 2 participants 3 messages Dec 16, 2008 – Dec 17, 2008 Media (V4L/DVB)

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 video: sh_mobile_ceu cleanups and comments V2

From: Magnus Damm <[email protected]>

This patch cleans up the sh_mobile_ceu driver and adds comments and constants to clarify the magic sequence in sh_mobile_ceu_capture().

---

Applies on top of the NV16 patch.

Changes since V1:
- use unsigned longs for ceu_read() and ceu_write() reg_offs.

 drivers/media/video/sh_mobile_ceu_camera.c |   39 ++++++++++++++++------------
 1 file changed, 23 insertions(+), 16 deletions(-)
drivers/media/video/sh_mobile_ceu_camera.c +23 -16
@@ -104,13 +104,12 @@ struct sh_mobile_ceu_dev {
 };
 
 static void ceu_write(struct sh_mobile_ceu_dev *priv,
-		      unsigned long reg_offs, unsigned long data)
+		      unsigned long reg_offs, u32 data)
 {
 	iowrite32(data, priv->base + reg_offs);
 }
 
-static unsigned long ceu_read(struct sh_mobile_ceu_dev *priv,
-			      unsigned long reg_offs)
+static u32 ceu_read(struct sh_mobile_ceu_dev *priv, unsigned long reg_offs)
 {
 	return ioread32(priv->base + reg_offs);
 }
@@ -158,18 +157,26 @@ static void free_buffer(struct videobuf_
 	buf->vb.state = VIDEOBUF_NEEDS_INIT;
 }
 
+#define CEU_CETCR_MAGIC 0x0317f313 /* acknowledge magical interrupt sources */
+#define CEU_CETCR_IGRW (1 << 4) /* prohibited register access interrupt bit */
+#define CEU_CEIER_CPEIE (1 << 0) /* one-frame capture end interrupt */
+#define CEU_CAPCR_CTNCP (1 << 16) /* continuous capture mode (if set) */
+
+
 static void sh_mobile_ceu_capture(struct sh_mobile_ceu_dev *pcdev)
 {
 	struct soc_camera_device *icd = pcdev->icd;
-	unsigned long phys_addr;
-
-	ceu_write(pcdev, CEIER, ceu_read(pcdev, CEIER) & ~1);
-	ceu_write(pcdev, CETCR, ~ceu_read(pcdev, CETCR) & 0x0317f313);
-	ceu_write(pcdev, CEIER, ceu_read(pcdev, CEIER) | 1);
+	dma_addr_t phys_addr;
 
-	ceu_write(pcdev, CAPCR, ceu_read(pcdev, CAPCR) & ~0x10000);
-
-	ceu_write(pcdev, CETCR, 0x0317f313 ^ 0x10);
+	/* The hardware is _very_ picky about this sequence. Especially
+	 * the CEU_CETCR_MAGIC value. It seems like we need to acknowledge
+	 * several not-so-well documented interrupt sources in CETCR.
+	 */
+	ceu_write(pcdev, CEIER, ceu_read(pcdev, CEIER) & ~CEU_CEIER_CPEIE);
+	ceu_write(pcdev, CETCR, ~ceu_read(pcdev, CETCR) & CEU_CETCR_MAGIC);
+	ceu_write(pcdev, CEIER, ceu_read(pcdev, CEIER) | CEU_CEIER_CPEIE);
+	ceu_write(pcdev, CAPCR, ceu_read(pcdev, CAPCR) & ~CEU_CAPCR_CTNCP);
+	ceu_write(pcdev, CETCR, CEU_CETCR_MAGIC ^ CEU_CETCR_IGRW);
 
 	if (!pcdev->active)
 		return;
@@ -182,7 +189,7 @@ static void sh_mobile_ceu_capture(struct
 	case V4L2_PIX_FMT_NV21:
 	case V4L2_PIX_FMT_NV16:
 	case V4L2_PIX_FMT_NV61:
-		phys_addr += (icd->width * icd->height);
+		phys_addr += icd->width * icd->height;
 		ceu_write(pcdev, CDACR, phys_addr);
 	}
 
@@ -452,13 +459,13 @@ static int sh_mobile_ceu_set_bus_param(s
 
 	if (yuv_mode) {
 		width = icd->width * 2;
-		width = (buswidth == 16) ? width / 2 : width;
+		width = buswidth == 16 ? width / 2 : width;
 		cfszr_width = cdwdr_width = icd->width;
 	} else {
 		width = icd->width * ((icd->current_fmt->depth + 7) >> 3);
-		width = (buswidth == 16) ? width / 2 : width;
-		cfszr_width = (buswidth == 8) ? width / 2 : width;
-		cdwdr_width = (buswidth == 16) ? width * 2 : width;
+		width = buswidth == 16 ? width / 2 : width;
+		cfszr_width = buswidth == 8 ? width / 2 : width;
+		cdwdr_width = buswidth == 16 ? width * 2 : width;
 	}
 
 	ceu_write(pcdev, CAMOR, 0);

--
video4linux-list mailing list
Unsubscribe mailto:[email protected]?subject=unsubscribe
https://www.redhat.com/mailman/listinfo/video4linux-list

#1 lore raw
Quoted 1 line · Magnus Damm

From: Magnus Damm <[email protected]>

Magnus, sorry, looks like you missed a couple more:

Review static int sh_mobile_ceu_set_bus_param(s

Quoted 1 line
(quoted diff) +0 -0
@@ -452,13 +459,13 @@ static int sh_mobile_ceu_set_bus_param(s
	if ((icd->current_fmt->fourcc == V4L2_PIX_FMT_NV21) ||
	    (icd->current_fmt->fourcc == V4L2_PIX_FMT_NV61))
		value ^= 0x00000100; /* swap U, V to change from NV1x->NVx1 */

	value |= (common_flags & SOCAM_VSYNC_ACTIVE_LOW) ? (1 << 1) : 0;
	value |= (common_flags & SOCAM_HSYNC_ACTIVE_LOW) ? (1 << 0) : 0;
	value |= (buswidth == 16) ? (1 << 12) : 0;

Let's make it complete, ok?

Quoted 8 lines
drivers/media/video/sh_mobile_ceu_camera.c +1 -1
 	if (yuv_mode) {
 		width = icd->width * 2;
-		width = (buswidth == 16) ? width / 2 : width;
+		width = buswidth == 16 ? width / 2 : width;
 		cfszr_width = cdwdr_width = icd->width;
 	} else {
 		width = icd->width * ((icd->current_fmt->depth + 7) >> 3);

drivers/media/video/sh_mobile_ceu_camera.c static int sh_mobile_ceu_set_bus_param(s

Quoted 10 lines
drivers/media/video/sh_mobile_ceu_camera.c +3 -3
-		width = (buswidth == 16) ? width / 2 : width;
-		cfszr_width = (buswidth == 8) ? width / 2 : width;
-		cdwdr_width = (buswidth == 16) ? width * 2 : width;
+		width = buswidth == 16 ? width / 2 : width;
+		cfszr_width = buswidth == 8 ? width / 2 : width;
+		cdwdr_width = buswidth == 16 ? width * 2 : width;
 	}
 
 	ceu_write(pcdev, CAMOR, 0);
 

Thanks
Guennadi
---
Guennadi Liakhovetski, Ph.D.
Freelance Open-Source Software Developer

--
video4linux-list mailing list
Unsubscribe mailto:[email protected]?subject=unsubscribe
https://www.redhat.com/mailman/listinfo/video4linux-list

#2 lore raw
Quoted 5 lines · Guennadi Liakhovetski
Quoted 1 line · Magnus Damm

From: Magnus Damm <[email protected]>

Magnus, sorry, looks like you missed a couple more:

Ok, forget it, if you don't mind, I'll just do it myself.

Thanks
Guennadi

Quoted 29 lines

Review static int sh_mobile_ceu_set_bus_param(s

Quoted 2 lines
(quoted diff) +0 -0
@@ -452,13 +459,13 @@ static int sh_mobile_ceu_set_bus_param(s
	if ((icd->current_fmt->fourcc == V4L2_PIX_FMT_NV21) ||
	    (icd->current_fmt->fourcc == V4L2_PIX_FMT_NV61))
		value ^= 0x00000100; /* swap U, V to change from NV1x->NVx1 */

	value |= (common_flags & SOCAM_VSYNC_ACTIVE_LOW) ? (1 << 1) : 0;
	value |= (common_flags & SOCAM_HSYNC_ACTIVE_LOW) ? (1 << 0) : 0;
	value |= (buswidth == 16) ? (1 << 12) : 0;

Let's make it complete, ok?

Quoted 16 lines
drivers/media/video/sh_mobile_ceu_camera.c +4 -4
 	if (yuv_mode) {
 		width = icd->width * 2;
-		width = (buswidth == 16) ? width / 2 : width;
+		width = buswidth == 16 ? width / 2 : width;
 		cfszr_width = cdwdr_width = icd->width;
 	} else {
 		width = icd->width * ((icd->current_fmt->depth + 7) >> 3);
-		width = (buswidth == 16) ? width / 2 : width;
-		cfszr_width = (buswidth == 8) ? width / 2 : width;
-		cdwdr_width = (buswidth == 16) ? width * 2 : width;
+		width = buswidth == 16 ? width / 2 : width;
+		cfszr_width = buswidth == 8 ? width / 2 : width;
+		cdwdr_width = buswidth == 16 ? width * 2 : width;
 	}
 
Quoted 9 lines

Review static int sh_mobile_ceu_set_bus_param(s · line 471

Quoted 2 lines
(quoted diff) +0 -0
 	ceu_write(pcdev, CAMOR, 0);
 

Thanks
Guennadi
---
Guennadi Liakhovetski, Ph.D.
Freelance Open-Source Software Developer

---
Guennadi Liakhovetski, Ph.D.
Freelance Open-Source Software Developer

--
video4linux-list mailing list
Unsubscribe mailto:[email protected]?subject=unsubscribe
https://www.redhat.com/mailman/listinfo/video4linux-list