[PATCH v3 04/32] [media] coda: fix internal framebuffer allocation size

2014-07-11 Thread Philipp Zabel
This error was introduced by 5677e3b04d3b3961200aa2bb9cc715e709eafeb9
[media] coda: update CODA7541 to firmware 1.4.50.

Signed-off-by: Philipp Zabel p.za...@pengutronix.de
---
 drivers/media/platform/coda.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/media/platform/coda.c b/drivers/media/platform/coda.c
index 10e1d98..e3dddcb 100644
--- a/drivers/media/platform/coda.c
+++ b/drivers/media/platform/coda.c
@@ -1527,10 +1527,10 @@ static int coda_alloc_framebuffers(struct coda_ctx 
*ctx, struct coda_q_data *q_d
for (i = 0; i  ctx-num_internal_frames; i++) {
size_t size;
 
-   size = q_data-sizeimage;
+   size = ysize + ysize / 2;
if (ctx-codec-src_fourcc == V4L2_PIX_FMT_H264 
dev-devtype-product != CODA_DX6)
-   ctx-internal_frames[i].size += ysize/4;
+   size += ysize / 4;
ret = coda_alloc_context_buf(ctx, ctx-internal_frames[i], 
size);
if (ret  0) {
coda_free_framebuffers(ctx);
-- 
2.0.0

--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v3 14/32] [media] coda: select GENERIC_ALLOCATOR

2014-07-11 Thread Philipp Zabel
The driver uses the genalloc API, which doesn't have stubs in
case GENERIC_ALLOCATOR is disabled.

Signed-off-by: Philipp Zabel p.za...@pengutronix.de
---
 drivers/media/platform/Kconfig | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/media/platform/Kconfig b/drivers/media/platform/Kconfig
index 8108c69..a204e8d 100644
--- a/drivers/media/platform/Kconfig
+++ b/drivers/media/platform/Kconfig
@@ -142,6 +142,7 @@ config VIDEO_CODA
select SRAM
select VIDEOBUF2_DMA_CONTIG
select V4L2_MEM2MEM_DEV
+   select GENERIC_ALLOCATOR
---help---
   Coda is a range of video codec IPs that supports
   H.264, MPEG-4, and other video formats.
-- 
2.0.0

--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v3 08/32] [media] coda: add selection API support for h.264 decoder

2014-07-11 Thread Philipp Zabel
The h.264 decoder produces capture frames that are a multiple of the macroblock
size (16 pixels). To inform userspace about invalid pixel data at the edges,
use the active and padded composing rectangles on the capture queue.
The cropping information is obtained from the h.264 sequence parameter set.

Reviewed-by: Hans Verkuil hans.verk...@cisco.com
Signed-off-by: Philipp Zabel p.za...@pengutronix.de
---
 drivers/media/platform/coda.c | 94 +++
 1 file changed, 94 insertions(+)

diff --git a/drivers/media/platform/coda.c b/drivers/media/platform/coda.c
index 59f16ac..204abb7 100644
--- a/drivers/media/platform/coda.c
+++ b/drivers/media/platform/coda.c
@@ -119,6 +119,7 @@ struct coda_q_data {
unsigned intheight;
unsigned intsizeimage;
unsigned intfourcc;
+   struct v4l2_rectrect;
 };
 
 struct coda_aux_buf {
@@ -735,6 +736,10 @@ static int coda_s_fmt(struct coda_ctx *ctx, struct 
v4l2_format *f)
q_data-width = f-fmt.pix.width;
q_data-height = f-fmt.pix.height;
q_data-sizeimage = f-fmt.pix.sizeimage;
+   q_data-rect.left = 0;
+   q_data-rect.top = 0;
+   q_data-rect.width = f-fmt.pix.width;
+   q_data-rect.height = f-fmt.pix.height;
 
v4l2_dbg(1, coda_debug, ctx-dev-v4l2_dev,
Setting format for type %d, wxh: %dx%d, fmt: %d\n,
@@ -871,6 +876,50 @@ static int coda_streamoff(struct file *file, void *priv,
return ret;
 }
 
+static int coda_g_selection(struct file *file, void *fh,
+   struct v4l2_selection *s)
+{
+   struct coda_ctx *ctx = fh_to_ctx(fh);
+   struct coda_q_data *q_data;
+   struct v4l2_rect r, *rsel;
+
+   q_data = get_q_data(ctx, s-type);
+   if (!q_data)
+   return -EINVAL;
+
+   r.left = 0;
+   r.top = 0;
+   r.width = q_data-width;
+   r.height = q_data-height;
+   rsel = q_data-rect;
+
+   switch (s-target) {
+   case V4L2_SEL_TGT_CROP_DEFAULT:
+   case V4L2_SEL_TGT_CROP_BOUNDS:
+   rsel = r;
+   /* fallthrough */
+   case V4L2_SEL_TGT_CROP:
+   if (s-type != V4L2_BUF_TYPE_VIDEO_OUTPUT)
+   return -EINVAL;
+   break;
+   case V4L2_SEL_TGT_COMPOSE_BOUNDS:
+   case V4L2_SEL_TGT_COMPOSE_PADDED:
+   rsel = r;
+   /* fallthrough */
+   case V4L2_SEL_TGT_COMPOSE:
+   case V4L2_SEL_TGT_COMPOSE_DEFAULT:
+   if (s-type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
+   return -EINVAL;
+   break;
+   default:
+   return -EINVAL;
+   }
+
+   s-r = *rsel;
+
+   return 0;
+}
+
 static int coda_try_decoder_cmd(struct file *file, void *fh,
struct v4l2_decoder_cmd *dc)
 {
@@ -949,6 +998,8 @@ static const struct v4l2_ioctl_ops coda_ioctl_ops = {
.vidioc_streamon= coda_streamon,
.vidioc_streamoff   = coda_streamoff,
 
+   .vidioc_g_selection = coda_g_selection,
+
.vidioc_try_decoder_cmd = coda_try_decoder_cmd,
.vidioc_decoder_cmd = coda_decoder_cmd,
 
@@ -1504,6 +1555,10 @@ static void set_default_params(struct coda_ctx *ctx)
ctx-q_data[V4L2_M2M_DST].width = max_w;
ctx-q_data[V4L2_M2M_DST].height = max_h;
ctx-q_data[V4L2_M2M_DST].sizeimage = CODA_MAX_FRAME_SIZE;
+   ctx-q_data[V4L2_M2M_SRC].rect.width = max_w;
+   ctx-q_data[V4L2_M2M_SRC].rect.height = max_h;
+   ctx-q_data[V4L2_M2M_DST].rect.width = max_w;
+   ctx-q_data[V4L2_M2M_DST].rect.height = max_h;
 
if (ctx-dev-devtype-product == CODA_960)
coda_set_tiled_map_type(ctx, GDI_LINEAR_FRAME_MAP);
@@ -2031,6 +2086,21 @@ static int coda_start_decoding(struct coda_ctx *ctx)
return -EINVAL;
}
 
+   if (src_fourcc == V4L2_PIX_FMT_H264) {
+   u32 left_right;
+   u32 top_bottom;
+
+   left_right = coda_read(dev, CODA_RET_DEC_SEQ_CROP_LEFT_RIGHT);
+   top_bottom = coda_read(dev, CODA_RET_DEC_SEQ_CROP_TOP_BOTTOM);
+
+   q_data_dst-rect.left = (left_right  10)  0x3ff;
+   q_data_dst-rect.top = (top_bottom  10)  0x3ff;
+   q_data_dst-rect.width = width - q_data_dst-rect.left -
+(left_right  0x3ff);
+   q_data_dst-rect.height = height - q_data_dst-rect.top -
+ (top_bottom  0x3ff);
+   }
+
ret = coda_alloc_framebuffers(ctx, q_data_dst, src_fourcc);
if (ret  0)
return ret;
@@ -2940,6 +3010,30 @@ static void coda_finish_decode(struct coda_ctx *ctx)
 
q_data_dst = get_q_data(ctx, V4L2_BUF_TYPE_VIDEO_CAPTURE);
 
+   /* frame crop information */
+   if (src_fourcc == V4L2_PIX_FMT_H264) {
+   u32 left_right;
+   u32 

[PATCH v3 02/32] [media] coda: fix readback of CODA_RET_DEC_SEQ_FRAME_NEED

2014-07-11 Thread Philipp Zabel
Previously we'd add one to this value, allocating one additional, superfluous
internal buffer.

Signed-off-by: Philipp Zabel p.za...@pengutronix.de
---
 drivers/media/platform/coda.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/media/platform/coda.c b/drivers/media/platform/coda.c
index a7c5ac5..1770fc2 100644
--- a/drivers/media/platform/coda.c
+++ b/drivers/media/platform/coda.c
@@ -1889,7 +1889,7 @@ static int coda_start_decoding(struct coda_ctx *ctx)
v4l2_dbg(1, coda_debug, dev-v4l2_dev, %s instance %d now: %dx%d\n,
 __func__, ctx-idx, width, height);
 
-   ctx-num_internal_frames = coda_read(dev, CODA_RET_DEC_SEQ_FRAME_NEED) 
+ 1;
+   ctx-num_internal_frames = coda_read(dev, CODA_RET_DEC_SEQ_FRAME_NEED);
if (ctx-num_internal_frames  CODA_MAX_FRAMEBUFFERS) {
v4l2_err(dev-v4l2_dev,
 not enough framebuffers to decode (%d  %d)\n,
-- 
2.0.0

--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v3 03/32] [media] coda: fix h.264 quantization parameter range

2014-07-11 Thread Philipp Zabel
If bitrate is not set, the encoder is running in VBR mode, with the
I- and P-frame quantization parameters configured from userspace.
For the quantization parameters, 0 is a valid value.

Signed-off-by: Philipp Zabel p.za...@pengutronix.de
---
 drivers/media/platform/coda.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/media/platform/coda.c b/drivers/media/platform/coda.c
index 1770fc2..10e1d98 100644
--- a/drivers/media/platform/coda.c
+++ b/drivers/media/platform/coda.c
@@ -2385,9 +2385,9 @@ static int coda_ctrls_setup(struct coda_ctx *ctx)
v4l2_ctrl_new_std(ctx-ctrls, coda_ctrl_ops,
V4L2_CID_MPEG_VIDEO_GOP_SIZE, 1, 60, 1, 16);
v4l2_ctrl_new_std(ctx-ctrls, coda_ctrl_ops,
-   V4L2_CID_MPEG_VIDEO_H264_I_FRAME_QP, 1, 51, 1, 25);
+   V4L2_CID_MPEG_VIDEO_H264_I_FRAME_QP, 0, 51, 1, 25);
v4l2_ctrl_new_std(ctx-ctrls, coda_ctrl_ops,
-   V4L2_CID_MPEG_VIDEO_H264_P_FRAME_QP, 1, 51, 1, 25);
+   V4L2_CID_MPEG_VIDEO_H264_P_FRAME_QP, 0, 51, 1, 25);
v4l2_ctrl_new_std(ctx-ctrls, coda_ctrl_ops,
V4L2_CID_MPEG_VIDEO_MPEG4_I_FRAME_QP, 1, 31, 1, 2);
v4l2_ctrl_new_std(ctx-ctrls, coda_ctrl_ops,
-- 
2.0.0

--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v3 32/32] [media] coda: store IRAM size in struct coda_devtype

2014-07-11 Thread Philipp Zabel
Similarly to workbuf_size and tempbuf_size, store iram_size in the
coda_devtype structure. This also decreases the IRAM used on i.MX6DL
to 128 KiB.

Signed-off-by: Philipp Zabel p.za...@pengutronix.de
---
 drivers/media/platform/coda.c | 19 ++-
 1 file changed, 6 insertions(+), 13 deletions(-)

diff --git a/drivers/media/platform/coda.c b/drivers/media/platform/coda.c
index 36ad0e8..7e69eda 100644
--- a/drivers/media/platform/coda.c
+++ b/drivers/media/platform/coda.c
@@ -46,9 +46,6 @@
 
 #define CODA_PARA_BUF_SIZE (10 * 1024)
 #define CODA_ISRAM_SIZE(2048 * 2)
-#define CODADX6_IRAM_SIZE  0xb000
-#define CODA7_IRAM_SIZE0x14000
-#define CODA9_IRAM_SIZE0x21000
 
 #define CODA7_PS_BUF_SIZE  0x28000
 #define CODA9_PS_SAVE_SIZE (512 * 1024)
@@ -109,6 +106,7 @@ struct coda_devtype {
unsigned intnum_codecs;
size_t  workbuf_size;
size_t  tempbuf_size;
+   size_t  iram_size;
 };
 
 /* Per-queue, driver-specific private data */
@@ -3680,6 +3678,7 @@ static const struct coda_devtype coda_devdata[] = {
.codecs   = codadx6_codecs,
.num_codecs   = ARRAY_SIZE(codadx6_codecs),
.workbuf_size = 288 * 1024 + FMO_SLICE_SAVE_BUF_SIZE * 8 * 1024,
+   .iram_size= 0xb000,
},
[CODA_IMX53] = {
.firmware = v4l-coda7541-imx53.bin,
@@ -3688,6 +3687,7 @@ static const struct coda_devtype coda_devdata[] = {
.num_codecs   = ARRAY_SIZE(coda7_codecs),
.workbuf_size = 128 * 1024,
.tempbuf_size = 304 * 1024,
+   .iram_size= 0x14000,
},
[CODA_IMX6Q] = {
.firmware = v4l-coda960-imx6q.bin,
@@ -3696,6 +3696,7 @@ static const struct coda_devtype coda_devdata[] = {
.num_codecs   = ARRAY_SIZE(coda9_codecs),
.workbuf_size = 80 * 1024,
.tempbuf_size = 204 * 1024,
+   .iram_size= 0x21000,
},
[CODA_IMX6DL] = {
.firmware = v4l-coda960-imx6dl.bin,
@@ -3704,6 +3705,7 @@ static const struct coda_devtype coda_devdata[] = {
.num_codecs   = ARRAY_SIZE(coda9_codecs),
.workbuf_size = 80 * 1024,
.tempbuf_size = 204 * 1024,
+   .iram_size= 0x2,
},
 };
 
@@ -3845,16 +3847,7 @@ static int coda_probe(struct platform_device *pdev)
}
}
 
-   switch (dev-devtype-product) {
-   case CODA_DX6:
-   dev-iram.size = CODADX6_IRAM_SIZE;
-   break;
-   case CODA_7541:
-   dev-iram.size = CODA7_IRAM_SIZE;
-   break;
-   case CODA_960:
-   dev-iram.size = CODA9_IRAM_SIZE;
-   }
+   dev-iram.size = dev-devtype-iram_size;
dev-iram.vaddr = gen_pool_dma_alloc(dev-iram_pool, dev-iram.size,
 dev-iram.paddr);
if (!dev-iram.vaddr) {
-- 
2.0.0

--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v3 27/32] [media] coda: round up internal frames to multiples of macroblock size for h.264

2014-07-11 Thread Philipp Zabel
CODA7541 only supports encoding h.264 frames with width and height that are
multiples of the macroblock size.

Signed-off-by: Philipp Zabel p.za...@pengutronix.de
---
 drivers/media/platform/coda.c | 25 -
 1 file changed, 20 insertions(+), 5 deletions(-)

diff --git a/drivers/media/platform/coda.c b/drivers/media/platform/coda.c
index 2acd715..8d9f849 100644
--- a/drivers/media/platform/coda.c
+++ b/drivers/media/platform/coda.c
@@ -1746,15 +1746,21 @@ static void coda_free_framebuffers(struct coda_ctx *ctx)
 static int coda_alloc_framebuffers(struct coda_ctx *ctx, struct coda_q_data 
*q_data, u32 fourcc)
 {
struct coda_dev *dev = ctx-dev;
-   int height = q_data-height;
+   int width, height;
dma_addr_t paddr;
int ysize;
int ret;
int i;
 
-   if (ctx-codec  ctx-codec-src_fourcc == V4L2_PIX_FMT_H264)
-   height = round_up(height, 16);
-   ysize = round_up(q_data-width, 8) * height;
+   if (ctx-codec  (ctx-codec-src_fourcc == V4L2_PIX_FMT_H264 ||
+ctx-codec-dst_fourcc == V4L2_PIX_FMT_H264)) {
+   width = round_up(q_data-width, 16);
+   height = round_up(q_data-height, 16);
+   } else {
+   width = round_up(q_data-width, 8);
+   height = q_data-height;
+   }
+   ysize = width * height;
 
/* Allocate frame buffers */
for (i = 0; i  ctx-num_internal_frames; i++) {
@@ -2379,7 +2385,16 @@ static int coda_start_encoding(struct coda_ctx *ctx)
value = (q_data_src-width  CODADX6_PICWIDTH_MASK)  
CODADX6_PICWIDTH_OFFSET;
value |= (q_data_src-height  CODADX6_PICHEIGHT_MASK)  
CODA_PICHEIGHT_OFFSET;
break;
-   default:
+   case CODA_7541:
+   if (dst_fourcc == V4L2_PIX_FMT_H264) {
+   value = (round_up(q_data_src-width, 16) 
+CODA7_PICWIDTH_MASK)  CODA7_PICWIDTH_OFFSET;
+   value |= (round_up(q_data_src-height, 16) 
+ CODA7_PICHEIGHT_MASK)  
CODA_PICHEIGHT_OFFSET;
+   break;
+   }
+   /* fallthrough */
+   case CODA_960:
value = (q_data_src-width  CODA7_PICWIDTH_MASK)  
CODA7_PICWIDTH_OFFSET;
value |= (q_data_src-height  CODA7_PICHEIGHT_MASK)  
CODA_PICHEIGHT_OFFSET;
}
-- 
2.0.0

--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v3 28/32] [media] coda: increase frame stride to 16 for h.264

2014-07-11 Thread Philipp Zabel
When encoding into h.264, the input frame stride needs to be a multiple of 16.
During allocation of the input buffers, it may not be known yet whether the
encoder should create h.264 or not. Assume the worst and always use a frame
stride that is a multiple of 16.

Signed-off-by: Philipp Zabel p.za...@pengutronix.de
---
 drivers/media/platform/coda.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/media/platform/coda.c b/drivers/media/platform/coda.c
index 8d9f849..5a94354 100644
--- a/drivers/media/platform/coda.c
+++ b/drivers/media/platform/coda.c
@@ -685,8 +685,8 @@ static int coda_try_fmt(struct coda_ctx *ctx, struct 
coda_codec *codec,
switch (f-fmt.pix.pixelformat) {
case V4L2_PIX_FMT_YUV420:
case V4L2_PIX_FMT_YVU420:
-   /* Frame stride must be multiple of 8 */
-   f-fmt.pix.bytesperline = round_up(f-fmt.pix.width, 8);
+   /* Frame stride must be multiple of 8, but 16 for h.264 */
+   f-fmt.pix.bytesperline = round_up(f-fmt.pix.width, 16);
f-fmt.pix.sizeimage = f-fmt.pix.bytesperline *
f-fmt.pix.height * 3 / 2;
break;
-- 
2.0.0

--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v3 15/32] [media] coda: add h.264 min/max qp controls

2014-07-11 Thread Philipp Zabel
If the bitrate control is set, the encoder works in CBR mode, dynamically
changing the quantization parameters to achieve a constant bitrate.
With the min/max QP controls the quantization parameters can be limited
to a given range.

Signed-off-by: Philipp Zabel p.za...@pengutronix.de
---
 drivers/media/platform/coda.c | 27 +++
 1 file changed, 27 insertions(+)

diff --git a/drivers/media/platform/coda.c b/drivers/media/platform/coda.c
index d47ab63..cb8d49d 100644
--- a/drivers/media/platform/coda.c
+++ b/drivers/media/platform/coda.c
@@ -159,6 +159,8 @@ struct coda_params {
u8  rot_mode;
u8  h264_intra_qp;
u8  h264_inter_qp;
+   u8  h264_min_qp;
+   u8  h264_max_qp;
u8  mpeg4_intra_qp;
u8  mpeg4_inter_qp;
u8  gop_size;
@@ -2381,7 +2383,16 @@ static int coda_start_encoding(struct coda_ctx *ctx)
coda_write(dev, (gamma  CODA_GAMMA_MASK)  CODA_GAMMA_OFFSET,
   CODA_CMD_ENC_SEQ_RC_GAMMA);
}
+
+   if (ctx-params.h264_min_qp || ctx-params.h264_max_qp) {
+   coda_write(dev,
+  ctx-params.h264_min_qp  CODA_QPMIN_OFFSET |
+  ctx-params.h264_max_qp  CODA_QPMAX_OFFSET,
+  CODA_CMD_ENC_SEQ_RC_QP_MIN_MAX);
+   }
if (dev-devtype-product == CODA_960) {
+   if (ctx-params.h264_max_qp)
+   value |= 1  CODA9_OPTION_RCQPMAX_OFFSET;
if (CODA_DEFAULT_GAMMA  0)
value |= 1  CODA9_OPTION_GAMMA_OFFSET;
} else {
@@ -2391,6 +2402,10 @@ static int coda_start_encoding(struct coda_ctx *ctx)
else
value |= 1  CODA7_OPTION_GAMMA_OFFSET;
}
+   if (ctx-params.h264_min_qp)
+   value |= 1  CODA7_OPTION_RCQPMIN_OFFSET;
+   if (ctx-params.h264_max_qp)
+   value |= 1  CODA7_OPTION_RCQPMAX_OFFSET;
}
coda_write(dev, value, CODA_CMD_ENC_SEQ_OPTION);
 
@@ -2619,6 +2634,12 @@ static int coda_s_ctrl(struct v4l2_ctrl *ctrl)
case V4L2_CID_MPEG_VIDEO_H264_P_FRAME_QP:
ctx-params.h264_inter_qp = ctrl-val;
break;
+   case V4L2_CID_MPEG_VIDEO_H264_MIN_QP:
+   ctx-params.h264_min_qp = ctrl-val;
+   break;
+   case V4L2_CID_MPEG_VIDEO_H264_MAX_QP:
+   ctx-params.h264_max_qp = ctrl-val;
+   break;
case V4L2_CID_MPEG_VIDEO_MPEG4_I_FRAME_QP:
ctx-params.mpeg4_intra_qp = ctrl-val;
break;
@@ -2666,6 +2687,12 @@ static int coda_ctrls_setup(struct coda_ctx *ctx)
V4L2_CID_MPEG_VIDEO_H264_I_FRAME_QP, 0, 51, 1, 25);
v4l2_ctrl_new_std(ctx-ctrls, coda_ctrl_ops,
V4L2_CID_MPEG_VIDEO_H264_P_FRAME_QP, 0, 51, 1, 25);
+   if (ctx-dev-devtype-product != CODA_960) {
+   v4l2_ctrl_new_std(ctx-ctrls, coda_ctrl_ops,
+   V4L2_CID_MPEG_VIDEO_H264_MIN_QP, 0, 51, 1, 12);
+   }
+   v4l2_ctrl_new_std(ctx-ctrls, coda_ctrl_ops,
+   V4L2_CID_MPEG_VIDEO_H264_MAX_QP, 0, 51, 1, 51);
v4l2_ctrl_new_std(ctx-ctrls, coda_ctrl_ops,
V4L2_CID_MPEG_VIDEO_MPEG4_I_FRAME_QP, 1, 31, 1, 2);
v4l2_ctrl_new_std(ctx-ctrls, coda_ctrl_ops,
-- 
2.0.0

--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v3 25/32] [media] coda: add bytesperline to queue data

2014-07-11 Thread Philipp Zabel
bytesperline is calculated in multiple places, store it in the coda_q_data
structure. This will be more useful later when adding JPEG support.

Signed-off-by: Philipp Zabel p.za...@pengutronix.de
---
 drivers/media/platform/coda.c | 27 ---
 1 file changed, 16 insertions(+), 11 deletions(-)

diff --git a/drivers/media/platform/coda.c b/drivers/media/platform/coda.c
index 995c289..75a5477 100644
--- a/drivers/media/platform/coda.c
+++ b/drivers/media/platform/coda.c
@@ -119,6 +119,7 @@ struct coda_devtype {
 struct coda_q_data {
unsigned intwidth;
unsigned intheight;
+   unsigned intbytesperline;
unsigned intsizeimage;
unsigned intfourcc;
struct v4l2_rectrect;
@@ -636,10 +637,7 @@ static int coda_g_fmt(struct file *file, void *priv,
f-fmt.pix.pixelformat  = q_data-fourcc;
f-fmt.pix.width= q_data-width;
f-fmt.pix.height   = q_data-height;
-   if (coda_format_is_yuv(f-fmt.pix.pixelformat))
-   f-fmt.pix.bytesperline = round_up(f-fmt.pix.width, 2);
-   else /* encoded formats h.264/mpeg4 */
-   f-fmt.pix.bytesperline = 0;
+   f-fmt.pix.bytesperline = q_data-bytesperline;
 
f-fmt.pix.sizeimage= q_data-sizeimage;
f-fmt.pix.colorspace   = ctx-colorspace;
@@ -789,6 +787,7 @@ static int coda_s_fmt(struct coda_ctx *ctx, struct 
v4l2_format *f)
q_data-fourcc = f-fmt.pix.pixelformat;
q_data-width = f-fmt.pix.width;
q_data-height = f-fmt.pix.height;
+   q_data-bytesperline = f-fmt.pix.bytesperline;
q_data-sizeimage = f-fmt.pix.sizeimage;
q_data-rect.left = 0;
q_data-rect.top = 0;
@@ -1349,14 +1348,16 @@ static void coda_prepare_encode(struct coda_ctx *ctx)
switch (q_data_src-fourcc) {
case V4L2_PIX_FMT_YVU420:
/* Switch Cb and Cr for YVU420 format */
-   picture_cr = picture_y + q_data_src-width * q_data_src-height;
-   picture_cb = picture_cr + q_data_src-width / 2 *
+   picture_cr = picture_y + q_data_src-bytesperline *
+   q_data_src-height;
+   picture_cb = picture_cr + q_data_src-bytesperline / 2 *
q_data_src-height / 2;
break;
case V4L2_PIX_FMT_YUV420:
default:
-   picture_cb = picture_y + q_data_src-width * q_data_src-height;
-   picture_cr = picture_cb + q_data_src-width / 2 *
+   picture_cb = picture_y + q_data_src-bytesperline *
+   q_data_src-height;
+   picture_cr = picture_cb + q_data_src-bytesperline / 2 *
q_data_src-height / 2;
break;
}
@@ -1598,9 +1599,11 @@ static void set_default_params(struct coda_ctx *ctx)
ctx-q_data[V4L2_M2M_DST].fourcc = ctx-codec-dst_fourcc;
ctx-q_data[V4L2_M2M_SRC].width = max_w;
ctx-q_data[V4L2_M2M_SRC].height = max_h;
+   ctx-q_data[V4L2_M2M_SRC].bytesperline = max_w;
ctx-q_data[V4L2_M2M_SRC].sizeimage = (max_w * max_h * 3) / 2;
ctx-q_data[V4L2_M2M_DST].width = max_w;
ctx-q_data[V4L2_M2M_DST].height = max_h;
+   ctx-q_data[V4L2_M2M_DST].bytesperline = 0;
ctx-q_data[V4L2_M2M_DST].sizeimage = CODA_MAX_FRAME_SIZE;
ctx-q_data[V4L2_M2M_SRC].rect.width = max_w;
ctx-q_data[V4L2_M2M_SRC].rect.height = max_h;
@@ -2535,10 +2538,12 @@ static int coda_start_encoding(struct coda_ctx *ctx)
}
 
coda_write(dev, ctx-num_internal_frames, CODA_CMD_SET_FRAME_BUF_NUM);
-   coda_write(dev, round_up(q_data_src-width, 8), 
CODA_CMD_SET_FRAME_BUF_STRIDE);
-   if (dev-devtype-product == CODA_7541)
-   coda_write(dev, round_up(q_data_src-width, 8),
+   coda_write(dev, q_data_src-bytesperline,
+   CODA_CMD_SET_FRAME_BUF_STRIDE);
+   if (dev-devtype-product == CODA_7541) {
+   coda_write(dev, q_data_src-bytesperline,
CODA7_CMD_SET_FRAME_SOURCE_BUF_STRIDE);
+   }
if (dev-devtype-product != CODA_DX6) {
coda_write(dev, ctx-iram_info.buf_bit_use,
CODA7_CMD_SET_FRAME_AXI_BIT_ADDR);
-- 
2.0.0

--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v3 22/32] [media] coda: add sequence counter offset

2014-07-11 Thread Philipp Zabel
The coda h.264 decoder also counts PIC_RUNs where no frame was decoded but
a frame was rotated out / marked as ready to be displayed. This causes an
offset between the incoming encoded frame's sequence number and the decode
sequence number returned by the coda. This patch introduces a sequence
counter offset variable to keep track of the difference.

Signed-off-by: Philipp Zabel p.za...@pengutronix.de
---
 drivers/media/platform/coda.c | 13 +
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/drivers/media/platform/coda.c b/drivers/media/platform/coda.c
index 0405a7a..d7404e9 100644
--- a/drivers/media/platform/coda.c
+++ b/drivers/media/platform/coda.c
@@ -222,6 +222,7 @@ struct coda_ctx {
u32 isequence;
u32 qsequence;
u32 osequence;
+   u32 sequence_offset;
struct coda_q_data  q_data[2];
enum coda_inst_type inst_type;
struct coda_codec   *codec;
@@ -2623,6 +2624,7 @@ static void coda_stop_streaming(struct vb2_queue *q)
ctx-streamon_cap = 0;
 
ctx-osequence = 0;
+   ctx-sequence_offset = 0;
}
 
if (!ctx-streamon_out  !ctx-streamon_cap) {
@@ -3128,7 +3130,9 @@ static void coda_finish_decode(struct coda_ctx *ctx)
 
if (decoded_idx == -1) {
/* no frame was decoded, but we might have a display frame */
-   if (display_idx  0  ctx-display_idx  0)
+   if (display_idx = 0  display_idx  ctx-num_internal_frames)
+   ctx-sequence_offset++;
+   else if (ctx-display_idx  0)
ctx-prescan_failed = true;
} else if (decoded_idx == -2) {
/* no frame was decoded, we still return the remaining buffers 
*/
@@ -3140,10 +3144,11 @@ static void coda_finish_decode(struct coda_ctx *ctx)
  struct coda_timestamp, list);
list_del(ts-list);
val = coda_read(dev, CODA_RET_DEC_PIC_FRAME_NUM) - 1;
-   if (val != ts-sequence) {
+   val -= ctx-sequence_offset;
+   if (val != (ts-sequence  0x)) {
v4l2_err(dev-v4l2_dev,
-sequence number mismatch (%d != %d)\n,
-val, ts-sequence);
+sequence number mismatch (%d(%d) != %d)\n,
+val, ctx-sequence_offset, ts-sequence);
}
ctx-frame_timestamps[decoded_idx] = *ts;
kfree(ts);
-- 
2.0.0

--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v3 09/32] [media] coda: add workqueue to serialize hardware commands

2014-07-11 Thread Philipp Zabel
Using the coda_mutex lock to serialize hardware access would cause
INFO: possible circular locking dependency detected lockdep warnings.
Since the possible locking paths are hard to follow, serialize hardware
access with a single workqueue thread. Ultimately the workqueue could
be converted to only do register setup and readout for per-command work
items.
Using the initialized context property, SEQ_END is only queued in
coda_release when needed.

Signed-off-by: Philipp Zabel p.za...@pengutronix.de
---
 drivers/media/platform/coda.c | 162 +++---
 1 file changed, 74 insertions(+), 88 deletions(-)

diff --git a/drivers/media/platform/coda.c b/drivers/media/platform/coda.c
index 204abb7..6e327e1 100644
--- a/drivers/media/platform/coda.c
+++ b/drivers/media/platform/coda.c
@@ -147,11 +147,11 @@ struct coda_dev {
spinlock_t  irqlock;
struct mutexdev_mutex;
struct mutexcoda_mutex;
+   struct workqueue_struct *workqueue;
struct v4l2_m2m_dev *m2m_dev;
struct vb2_alloc_ctx*alloc_ctx;
struct list_headinstances;
unsigned long   instance_mask;
-   struct delayed_work timeout;
 };
 
 struct coda_params {
@@ -198,7 +198,9 @@ struct coda_ctx {
struct coda_dev *dev;
struct mutexbuffer_mutex;
struct list_headlist;
-   struct work_struct  skip_run;
+   struct work_struct  pic_run_work;
+   struct work_struct  seq_end_work;
+   struct completion   completion;
int aborting;
int initialized;
int streamon_out;
@@ -1009,13 +1011,6 @@ static const struct v4l2_ioctl_ops coda_ioctl_ops = {
 
 static int coda_start_decoding(struct coda_ctx *ctx);
 
-static void coda_skip_run(struct work_struct *work)
-{
-   struct coda_ctx *ctx = container_of(work, struct coda_ctx, skip_run);
-
-   v4l2_m2m_job_finish(ctx-dev-m2m_dev, ctx-m2m_ctx);
-}
-
 static inline int coda_get_bitstream_payload(struct coda_ctx *ctx)
 {
return kfifo_len(ctx-bitstream_fifo);
@@ -1170,7 +1165,7 @@ static int coda_prepare_decode(struct coda_ctx *ctx)
v4l2_dbg(1, coda_debug, dev-v4l2_dev,
 bitstream payload: %d, skipping\n,
 coda_get_bitstream_payload(ctx));
-   schedule_work(ctx-skip_run);
+   v4l2_m2m_job_finish(ctx-dev-m2m_dev, ctx-m2m_ctx);
return -EAGAIN;
}
 
@@ -1179,7 +1174,7 @@ static int coda_prepare_decode(struct coda_ctx *ctx)
int ret = coda_start_decoding(ctx);
if (ret  0) {
v4l2_err(dev-v4l2_dev, failed to start decoding\n);
-   schedule_work(ctx-skip_run);
+   v4l2_m2m_job_finish(ctx-dev-m2m_dev, ctx-m2m_ctx);
return -EAGAIN;
} else {
ctx-initialized = 1;
@@ -1387,24 +1382,48 @@ static void coda_device_run(void *m2m_priv)
 {
struct coda_ctx *ctx = m2m_priv;
struct coda_dev *dev = ctx-dev;
-   int ret;
+
+   queue_work(dev-workqueue, ctx-pic_run_work);
+}
+
+static void coda_free_framebuffers(struct coda_ctx *ctx);
+static void coda_free_context_buffers(struct coda_ctx *ctx);
+
+static void coda_seq_end_work(struct work_struct *work)
+{
+   struct coda_ctx *ctx = container_of(work, struct coda_ctx, 
seq_end_work);
+   struct coda_dev *dev = ctx-dev;
 
mutex_lock(ctx-buffer_mutex);
+   mutex_lock(dev-coda_mutex);
 
-   /*
-* If streamoff dequeued all buffers before we could get the lock,
-* just bail out immediately.
-*/
-   if ((!v4l2_m2m_num_src_bufs_ready(ctx-m2m_ctx) 
-   ctx-inst_type != CODA_INST_DECODER) ||
-   !v4l2_m2m_num_dst_bufs_ready(ctx-m2m_ctx)) {
-   v4l2_dbg(1, coda_debug, dev-v4l2_dev,
-   %d: device_run without buffers\n, ctx-idx);
-   mutex_unlock(ctx-buffer_mutex);
-   schedule_work(ctx-skip_run);
-   return;
+   v4l2_dbg(1, coda_debug, dev-v4l2_dev,
+%d: %s: sent command 'SEQ_END' to coda\n, ctx-idx, 
__func__);
+   if (coda_command_sync(ctx, CODA_COMMAND_SEQ_END)) {
+   v4l2_err(dev-v4l2_dev,
+CODA_COMMAND_SEQ_END failed\n);
}
 
+   kfifo_init(ctx-bitstream_fifo,
+   ctx-bitstream.vaddr, ctx-bitstream.size);
+
+   coda_free_framebuffers(ctx);
+   coda_free_context_buffers(ctx);
+
+   mutex_unlock(dev-coda_mutex);
+   mutex_unlock(ctx-buffer_mutex);
+}
+
+static void coda_finish_decode(struct coda_ctx *ctx);
+static void coda_finish_encode(struct coda_ctx *ctx);
+
+static void 

[PATCH v3 26/32] [media] coda: allow odd width, but still round up bytesperline

2014-07-11 Thread Philipp Zabel
Even though the CODA h.264 decoder always decodes complete macroblocks, we can
set the stride to the corresponding multiple of 16 and use a value smaller than
that as real width. Unfortunately the same doesn't work for height, as there
is no vertical linesperframe stride for discontiguous planar YUV frames.

Signed-off-by: Philipp Zabel p.za...@pengutronix.de
---
 drivers/media/platform/coda.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/media/platform/coda.c b/drivers/media/platform/coda.c
index 75a5477..2acd715 100644
--- a/drivers/media/platform/coda.c
+++ b/drivers/media/platform/coda.c
@@ -740,9 +740,9 @@ static int coda_try_fmt_vid_cap(struct file *file, void 
*priv,
 
/* The h.264 decoder only returns complete 16x16 macroblocks */
if (codec  codec-src_fourcc == V4L2_PIX_FMT_H264) {
-   f-fmt.pix.width = round_up(f-fmt.pix.width, 16);
+   f-fmt.pix.width = f-fmt.pix.width;
f-fmt.pix.height = round_up(f-fmt.pix.height, 16);
-   f-fmt.pix.bytesperline = f-fmt.pix.width;
+   f-fmt.pix.bytesperline = round_up(f-fmt.pix.width, 16);
f-fmt.pix.sizeimage = f-fmt.pix.bytesperline *
   f-fmt.pix.height * 3 / 2;
}
-- 
2.0.0

--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v3 31/32] [media] coda: store global temporary buffer size in struct coda_devtype

2014-07-11 Thread Philipp Zabel
Similarly to the work buffer size, store the temporary buffer size in the
coda_devtype structure.

Signed-off-by: Philipp Zabel p.za...@pengutronix.de
---
 drivers/media/platform/coda.c | 21 -
 1 file changed, 8 insertions(+), 13 deletions(-)

diff --git a/drivers/media/platform/coda.c b/drivers/media/platform/coda.c
index 79e76b8..36ad0e8 100644
--- a/drivers/media/platform/coda.c
+++ b/drivers/media/platform/coda.c
@@ -44,8 +44,6 @@
 
 #define CODADX6_MAX_INSTANCES  4
 
-#define CODA7_TEMP_BUF_SIZE(304 * 1024)
-#define CODA9_TEMP_BUF_SIZE(204 * 1024)
 #define CODA_PARA_BUF_SIZE (10 * 1024)
 #define CODA_ISRAM_SIZE(2048 * 2)
 #define CODADX6_IRAM_SIZE  0xb000
@@ -110,6 +108,7 @@ struct coda_devtype {
struct coda_codec   *codecs;
unsigned intnum_codecs;
size_t  workbuf_size;
+   size_t  tempbuf_size;
 };
 
 /* Per-queue, driver-specific private data */
@@ -3688,6 +3687,7 @@ static const struct coda_devtype coda_devdata[] = {
.codecs   = coda7_codecs,
.num_codecs   = ARRAY_SIZE(coda7_codecs),
.workbuf_size = 128 * 1024,
+   .tempbuf_size = 304 * 1024,
},
[CODA_IMX6Q] = {
.firmware = v4l-coda960-imx6q.bin,
@@ -3695,6 +3695,7 @@ static const struct coda_devtype coda_devdata[] = {
.codecs   = coda9_codecs,
.num_codecs   = ARRAY_SIZE(coda9_codecs),
.workbuf_size = 80 * 1024,
+   .tempbuf_size = 204 * 1024,
},
[CODA_IMX6DL] = {
.firmware = v4l-coda960-imx6dl.bin,
@@ -3702,6 +3703,7 @@ static const struct coda_devtype coda_devdata[] = {
.codecs   = coda9_codecs,
.num_codecs   = ARRAY_SIZE(coda9_codecs),
.workbuf_size = 80 * 1024,
+   .tempbuf_size = 204 * 1024,
},
 };
 
@@ -3821,8 +3823,7 @@ static int coda_probe(struct platform_device *pdev)
dev_warn(pdev-dev, failed to create debugfs root\n);
 
/* allocate auxiliary per-device buffers for the BIT processor */
-   switch (dev-devtype-product) {
-   case CODA_DX6:
+   if (dev-devtype-product == CODA_DX6) {
ret = coda_alloc_aux_buf(dev, dev-workbuf,
 dev-devtype-workbuf_size, workbuf,
 dev-debugfs_root);
@@ -3831,17 +3832,11 @@ static int coda_probe(struct platform_device *pdev)
v4l2_device_unregister(dev-v4l2_dev);
return ret;
}
-   break;
-   case CODA_7541:
-   dev-tempbuf.size = CODA7_TEMP_BUF_SIZE;
-   break;
-   case CODA_960:
-   dev-tempbuf.size = CODA9_TEMP_BUF_SIZE;
-   break;
}
-   if (dev-tempbuf.size) {
+
+   if (dev-devtype-tempbuf_size) {
ret = coda_alloc_aux_buf(dev, dev-tempbuf,
-dev-tempbuf.size, tempbuf,
+dev-devtype-tempbuf_size, tempbuf,
 dev-debugfs_root);
if (ret  0) {
dev_err(pdev-dev, failed to allocate temp buffer\n);
-- 
2.0.0

--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v3 10/32] [media] coda: Use mem-to-mem ioctl helpers

2014-07-11 Thread Philipp Zabel
Use the mem2mem helpers introduced to get rid of some duplicated code.

Signed-off-by: Philipp Zabel p.za...@pengutronix.de
---
 drivers/media/platform/coda.c | 113 ++
 1 file changed, 14 insertions(+), 99 deletions(-)

diff --git a/drivers/media/platform/coda.c b/drivers/media/platform/coda.c
index 6e327e1..8e2c912 100644
--- a/drivers/media/platform/coda.c
+++ b/drivers/media/platform/coda.c
@@ -780,22 +780,6 @@ static int coda_s_fmt_vid_out(struct file *file, void 
*priv,
return ret;
 }
 
-static int coda_reqbufs(struct file *file, void *priv,
-   struct v4l2_requestbuffers *reqbufs)
-{
-   struct coda_ctx *ctx = fh_to_ctx(priv);
-
-   return v4l2_m2m_reqbufs(file, ctx-m2m_ctx, reqbufs);
-}
-
-static int coda_querybuf(struct file *file, void *priv,
-struct v4l2_buffer *buf)
-{
-   struct coda_ctx *ctx = fh_to_ctx(priv);
-
-   return v4l2_m2m_querybuf(file, ctx-m2m_ctx, buf);
-}
-
 static int coda_qbuf(struct file *file, void *priv,
 struct v4l2_buffer *buf)
 {
@@ -804,14 +788,6 @@ static int coda_qbuf(struct file *file, void *priv,
return v4l2_m2m_qbuf(file, ctx-m2m_ctx, buf);
 }
 
-static int coda_expbuf(struct file *file, void *priv,
-  struct v4l2_exportbuffer *eb)
-{
-   struct coda_ctx *ctx = fh_to_ctx(priv);
-
-   return v4l2_m2m_expbuf(file, ctx-m2m_ctx, eb);
-}
-
 static bool coda_buf_is_end_of_stream(struct coda_ctx *ctx,
  struct v4l2_buffer *buf)
 {
@@ -844,40 +820,6 @@ static int coda_dqbuf(struct file *file, void *priv,
return ret;
 }
 
-static int coda_create_bufs(struct file *file, void *priv,
-   struct v4l2_create_buffers *create)
-{
-   struct coda_ctx *ctx = fh_to_ctx(priv);
-
-   return v4l2_m2m_create_bufs(file, ctx-m2m_ctx, create);
-}
-
-static int coda_streamon(struct file *file, void *priv,
-enum v4l2_buf_type type)
-{
-   struct coda_ctx *ctx = fh_to_ctx(priv);
-
-   return v4l2_m2m_streamon(file, ctx-m2m_ctx, type);
-}
-
-static int coda_streamoff(struct file *file, void *priv,
- enum v4l2_buf_type type)
-{
-   struct coda_ctx *ctx = fh_to_ctx(priv);
-   int ret;
-
-   /*
-* This indirectly calls __vb2_queue_cancel, which dequeues all buffers.
-* We therefore have to lock it against running hardware in this 
context,
-* which still needs the buffers.
-*/
-   mutex_lock(ctx-buffer_mutex);
-   ret = v4l2_m2m_streamoff(file, ctx-m2m_ctx, type);
-   mutex_unlock(ctx-buffer_mutex);
-
-   return ret;
-}
-
 static int coda_g_selection(struct file *file, void *fh,
struct v4l2_selection *s)
 {
@@ -989,16 +931,16 @@ static const struct v4l2_ioctl_ops coda_ioctl_ops = {
.vidioc_try_fmt_vid_out = coda_try_fmt_vid_out,
.vidioc_s_fmt_vid_out   = coda_s_fmt_vid_out,
 
-   .vidioc_reqbufs = coda_reqbufs,
-   .vidioc_querybuf= coda_querybuf,
+   .vidioc_reqbufs = v4l2_m2m_ioctl_reqbufs,
+   .vidioc_querybuf= v4l2_m2m_ioctl_querybuf,
 
.vidioc_qbuf= coda_qbuf,
-   .vidioc_expbuf  = coda_expbuf,
+   .vidioc_expbuf  = v4l2_m2m_ioctl_expbuf,
.vidioc_dqbuf   = coda_dqbuf,
-   .vidioc_create_bufs = coda_create_bufs,
+   .vidioc_create_bufs = v4l2_m2m_ioctl_create_bufs,
 
-   .vidioc_streamon= coda_streamon,
-   .vidioc_streamoff   = coda_streamoff,
+   .vidioc_streamon= v4l2_m2m_ioctl_streamon,
+   .vidioc_streamoff   = v4l2_m2m_ioctl_streamoff,
 
.vidioc_g_selection = coda_g_selection,
 
@@ -1677,18 +1619,6 @@ static void coda_buf_queue(struct vb2_buffer *vb)
}
 }
 
-static void coda_wait_prepare(struct vb2_queue *q)
-{
-   struct coda_ctx *ctx = vb2_get_drv_priv(q);
-   coda_unlock(ctx);
-}
-
-static void coda_wait_finish(struct vb2_queue *q)
-{
-   struct coda_ctx *ctx = vb2_get_drv_priv(q);
-   coda_lock(ctx);
-}
-
 static void coda_parabuf_write(struct coda_ctx *ctx, int index, u32 value)
 {
struct coda_dev *dev = ctx-dev;
@@ -2650,10 +2580,10 @@ static struct vb2_ops coda_qops = {
.queue_setup= coda_queue_setup,
.buf_prepare= coda_buf_prepare,
.buf_queue  = coda_buf_queue,
-   .wait_prepare   = coda_wait_prepare,
-   .wait_finish= coda_wait_finish,
.start_streaming= coda_start_streaming,
.stop_streaming = coda_stop_streaming,
+   .wait_prepare   = vb2_ops_wait_prepare,
+   .wait_finish= vb2_ops_wait_finish,
 };
 
 static int coda_s_ctrl(struct v4l2_ctrl *ctrl)
@@ -2776,6 +2706,7 @@ static int coda_queue_init(void *priv, struct vb2_queue 
*src_vq,
 

[PATCH v3 11/32] [media] coda: use ctx-fh.m2m_ctx instead of ctx-m2m_ctx

2014-07-11 Thread Philipp Zabel
v4l2_fh already contains a mem2mem context pointer. Use it.

Signed-off-by: Philipp Zabel p.za...@pengutronix.de
---
 drivers/media/platform/coda.c | 66 +--
 1 file changed, 32 insertions(+), 34 deletions(-)

diff --git a/drivers/media/platform/coda.c b/drivers/media/platform/coda.c
index 8e2c912..0f692b0 100644
--- a/drivers/media/platform/coda.c
+++ b/drivers/media/platform/coda.c
@@ -213,7 +213,6 @@ struct coda_ctx {
struct coda_codec   *codec;
enum v4l2_colorspacecolorspace;
struct coda_params  params;
-   struct v4l2_m2m_ctx *m2m_ctx;
struct v4l2_ctrl_handlerctrls;
struct v4l2_fh  fh;
int gopcounter;
@@ -553,7 +552,7 @@ static int coda_enum_fmt_vid_cap(struct file *file, void 
*priv,
struct coda_q_data *q_data_src;
 
/* If the source format is already fixed, only list matching formats */
-   src_vq = v4l2_m2m_get_vq(ctx-m2m_ctx, V4L2_BUF_TYPE_VIDEO_OUTPUT);
+   src_vq = v4l2_m2m_get_vq(ctx-fh.m2m_ctx, V4L2_BUF_TYPE_VIDEO_OUTPUT);
if (vb2_is_streaming(src_vq)) {
q_data_src = get_q_data(ctx, V4L2_BUF_TYPE_VIDEO_OUTPUT);
 
@@ -667,7 +666,7 @@ static int coda_try_fmt_vid_cap(struct file *file, void 
*priv,
 * If the source format is already fixed, try to find a codec that
 * converts to the given destination format
 */
-   src_vq = v4l2_m2m_get_vq(ctx-m2m_ctx, V4L2_BUF_TYPE_VIDEO_OUTPUT);
+   src_vq = v4l2_m2m_get_vq(ctx-fh.m2m_ctx, V4L2_BUF_TYPE_VIDEO_OUTPUT);
if (vb2_is_streaming(src_vq)) {
struct coda_q_data *q_data_src;
 
@@ -721,7 +720,7 @@ static int coda_s_fmt(struct coda_ctx *ctx, struct 
v4l2_format *f)
struct coda_q_data *q_data;
struct vb2_queue *vq;
 
-   vq = v4l2_m2m_get_vq(ctx-m2m_ctx, f-type);
+   vq = v4l2_m2m_get_vq(ctx-fh.m2m_ctx, f-type);
if (!vq)
return -EINVAL;
 
@@ -785,7 +784,7 @@ static int coda_qbuf(struct file *file, void *priv,
 {
struct coda_ctx *ctx = fh_to_ctx(priv);
 
-   return v4l2_m2m_qbuf(file, ctx-m2m_ctx, buf);
+   return v4l2_m2m_qbuf(file, ctx-fh.m2m_ctx, buf);
 }
 
 static bool coda_buf_is_end_of_stream(struct coda_ctx *ctx,
@@ -793,7 +792,7 @@ static bool coda_buf_is_end_of_stream(struct coda_ctx *ctx,
 {
struct vb2_queue *src_vq;
 
-   src_vq = v4l2_m2m_get_vq(ctx-m2m_ctx, V4L2_BUF_TYPE_VIDEO_OUTPUT);
+   src_vq = v4l2_m2m_get_vq(ctx-fh.m2m_ctx, V4L2_BUF_TYPE_VIDEO_OUTPUT);
 
return ((ctx-bit_stream_param  CODA_BIT_STREAM_END_FLAG) 
(buf-sequence == (ctx-qsequence - 1)));
@@ -805,7 +804,7 @@ static int coda_dqbuf(struct file *file, void *priv,
struct coda_ctx *ctx = fh_to_ctx(priv);
int ret;
 
-   ret = v4l2_m2m_dqbuf(file, ctx-m2m_ctx, buf);
+   ret = v4l2_m2m_dqbuf(file, ctx-fh.m2m_ctx, buf);
 
/* If this is the last capture buffer, emit an end-of-stream event */
if (buf-type == V4L2_BUF_TYPE_VIDEO_CAPTURE 
@@ -1042,11 +1041,11 @@ static void coda_fill_bitstream(struct coda_ctx *ctx)
 {
struct vb2_buffer *src_buf;
 
-   while (v4l2_m2m_num_src_bufs_ready(ctx-m2m_ctx)  0) {
-   src_buf = v4l2_m2m_next_src_buf(ctx-m2m_ctx);
+   while (v4l2_m2m_num_src_bufs_ready(ctx-fh.m2m_ctx)  0) {
+   src_buf = v4l2_m2m_next_src_buf(ctx-fh.m2m_ctx);
 
if (coda_bitstream_try_queue(ctx, src_buf)) {
-   src_buf = v4l2_m2m_src_buf_remove(ctx-m2m_ctx);
+   src_buf = v4l2_m2m_src_buf_remove(ctx-fh.m2m_ctx);
v4l2_m2m_buf_done(src_buf, VB2_BUF_STATE_DONE);
} else {
break;
@@ -1086,7 +1085,7 @@ static int coda_prepare_decode(struct coda_ctx *ctx)
u32 stridey, height;
u32 picture_y, picture_cb, picture_cr;
 
-   dst_buf = v4l2_m2m_next_dst_buf(ctx-m2m_ctx);
+   dst_buf = v4l2_m2m_next_dst_buf(ctx-fh.m2m_ctx);
q_data_dst = get_q_data(ctx, V4L2_BUF_TYPE_VIDEO_CAPTURE);
 
if (ctx-params.rot_mode  CODA_ROT_90) {
@@ -1107,7 +1106,7 @@ static int coda_prepare_decode(struct coda_ctx *ctx)
v4l2_dbg(1, coda_debug, dev-v4l2_dev,
 bitstream payload: %d, skipping\n,
 coda_get_bitstream_payload(ctx));
-   v4l2_m2m_job_finish(ctx-dev-m2m_dev, ctx-m2m_ctx);
+   v4l2_m2m_job_finish(ctx-dev-m2m_dev, ctx-fh.m2m_ctx);
return -EAGAIN;
}
 
@@ -1116,7 +1115,7 @@ static int coda_prepare_decode(struct coda_ctx *ctx)
int ret = coda_start_decoding(ctx);
if (ret  0) {
v4l2_err(dev-v4l2_dev, failed to start decoding\n);
-   v4l2_m2m_job_finish(ctx-dev-m2m_dev, ctx-m2m_ctx);
+   

[PATCH v3 29/32] [media] coda: export auxiliary buffers via debugfs

2014-07-11 Thread Philipp Zabel
This patch exports all auxiliary buffers, including SRAM, as debugfs binary
blobs for debugging purposes. It shows, for example, that psbuf currently
doesn't seem to be used at all on CODA7541, and that slicebuf and workbuf
usage is far from the maximum. It can also be used to validate SRAM size
allocation.

Signed-off-by: Philipp Zabel p.za...@pengutronix.de
---
 drivers/media/platform/coda.c | 64 +++
 1 file changed, 53 insertions(+), 11 deletions(-)

diff --git a/drivers/media/platform/coda.c b/drivers/media/platform/coda.c
index 5a94354..1c2482a 100644
--- a/drivers/media/platform/coda.c
+++ b/drivers/media/platform/coda.c
@@ -12,6 +12,7 @@
  */
 
 #include linux/clk.h
+#include linux/debugfs.h
 #include linux/delay.h
 #include linux/firmware.h
 #include linux/genalloc.h
@@ -129,6 +130,8 @@ struct coda_aux_buf {
void*vaddr;
dma_addr_t  paddr;
u32 size;
+   struct debugfs_blob_wrapper blob;
+   struct dentry   *dentry;
 };
 
 struct coda_dev {
@@ -156,6 +159,7 @@ struct coda_dev {
struct vb2_alloc_ctx*alloc_ctx;
struct list_headinstances;
unsigned long   instance_mask;
+   struct dentry   *debugfs_root;
 };
 
 struct coda_params {
@@ -259,6 +263,7 @@ struct coda_ctx {
u32 frm_dis_flg;
u32 frame_mem_ctrl;
int display_idx;
+   struct dentry   *debugfs_entry;
 };
 
 static const u8 coda_filler_nal[14] = { 0x00, 0x00, 0x00, 0x01, 0x0c, 0xff,
@@ -1706,7 +1711,8 @@ static void coda_parabuf_write(struct coda_ctx *ctx, int 
index, u32 value)
 }
 
 static int coda_alloc_aux_buf(struct coda_dev *dev,
- struct coda_aux_buf *buf, size_t size)
+ struct coda_aux_buf *buf, size_t size,
+ const char *name, struct dentry *parent)
 {
buf-vaddr = dma_alloc_coherent(dev-plat_dev-dev, size, buf-paddr,
GFP_KERNEL);
@@ -1715,13 +1721,23 @@ static int coda_alloc_aux_buf(struct coda_dev *dev,
 
buf-size = size;
 
+   if (name  parent) {
+   buf-blob.data = buf-vaddr;
+   buf-blob.size = size;
+   buf-dentry = debugfs_create_blob(name, 0644, parent, 
buf-blob);
+   if (!buf-dentry)
+   dev_warn(dev-plat_dev-dev,
+failed to create debugfs entry %s\n, name);
+   }
+
return 0;
 }
 
 static inline int coda_alloc_context_buf(struct coda_ctx *ctx,
-struct coda_aux_buf *buf, size_t size)
+struct coda_aux_buf *buf, size_t size,
+const char *name)
 {
-   return coda_alloc_aux_buf(ctx-dev, buf, size);
+   return coda_alloc_aux_buf(ctx-dev, buf, size, name, 
ctx-debugfs_entry);
 }
 
 static void coda_free_aux_buf(struct coda_dev *dev,
@@ -1733,6 +1749,7 @@ static void coda_free_aux_buf(struct coda_dev *dev,
buf-vaddr = NULL;
buf-size = 0;
}
+   debugfs_remove(buf-dentry);
 }
 
 static void coda_free_framebuffers(struct coda_ctx *ctx)
@@ -1765,12 +1782,16 @@ static int coda_alloc_framebuffers(struct coda_ctx 
*ctx, struct coda_q_data *q_d
/* Allocate frame buffers */
for (i = 0; i  ctx-num_internal_frames; i++) {
size_t size;
+   char *name;
 
size = ysize + ysize / 2;
if (ctx-codec-src_fourcc == V4L2_PIX_FMT_H264 
dev-devtype-product != CODA_DX6)
size += ysize / 4;
-   ret = coda_alloc_context_buf(ctx, ctx-internal_frames[i], 
size);
+   name = kasprintf(GFP_KERNEL, fb%d, i);
+   ret = coda_alloc_context_buf(ctx, ctx-internal_frames[i],
+size, name);
+   kfree(name);
if (ret  0) {
coda_free_framebuffers(ctx);
return ret;
@@ -1994,7 +2015,7 @@ static int coda_alloc_context_buffers(struct coda_ctx 
*ctx,
/* worst case slice size */
size = (DIV_ROUND_UP(q_data-width, 16) *
DIV_ROUND_UP(q_data-height, 16)) * 3200 / 8 + 512;
-   ret = coda_alloc_context_buf(ctx, ctx-slicebuf, size);
+   ret = coda_alloc_context_buf(ctx, ctx-slicebuf, size, 
slicebuf);
if (ret  0) {
v4l2_err(dev-v4l2_dev, failed to allocate %d byte 
slice buffer,
 ctx-slicebuf.size);
@@ -2003,14 +2024,14 @@ static int coda_alloc_context_buffers(struct coda_ctx 
*ctx,
}
 
if (dev-devtype-product == CODA_7541) {
-  

[PATCH v3 19/32] [media] coda: try to schedule a decode run after a stop command

2014-07-11 Thread Philipp Zabel
From: Michael Olbrich m.olbr...@pengutronix.de

In case no further buffers are queued after the stop command, restart
job scheduling explicitly.

Signed-off-by: Michael Olbrich m.olbr...@pengutronix.de
Signed-off-by: Philipp Zabel p.za...@pengutronix.de
---
 drivers/media/platform/coda.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/media/platform/coda.c b/drivers/media/platform/coda.c
index 2e94d95..8194260 100644
--- a/drivers/media/platform/coda.c
+++ b/drivers/media/platform/coda.c
@@ -909,6 +909,8 @@ static int coda_decoder_cmd(struct file *file, void *fh,
/* If this context is currently running, update the hardware 
flag */
coda_write(dev, ctx-bit_stream_param, 
CODA_REG_BIT_BIT_STREAM_PARAM);
}
+   ctx-prescan_failed = false;
+   v4l2_m2m_try_schedule(ctx-fh.m2m_ctx);
 
return 0;
 }
-- 
2.0.0

--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v3 17/32] [media] coda: add cyclic intra refresh control

2014-07-11 Thread Philipp Zabel
Allow userspace to enable cyclic intra refresh by setting the number of
intra macroblocks per frame to a non-zero value.

Signed-off-by: Philipp Zabel p.za...@pengutronix.de
---
 drivers/media/platform/coda.c | 9 -
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/drivers/media/platform/coda.c b/drivers/media/platform/coda.c
index 839aa36..2e94d95 100644
--- a/drivers/media/platform/coda.c
+++ b/drivers/media/platform/coda.c
@@ -167,6 +167,7 @@ struct coda_params {
u8  mpeg4_intra_qp;
u8  mpeg4_inter_qp;
u8  gop_size;
+   int intra_refresh;
int codec_mode;
int codec_mode_aux;
enum v4l2_mpeg_video_multi_slice_mode slice_mode;
@@ -2381,7 +2382,8 @@ static int coda_start_encoding(struct coda_ctx *ctx)
coda_write(dev, value, CODA_CMD_ENC_SEQ_RC_PARA);
 
coda_write(dev, 0, CODA_CMD_ENC_SEQ_RC_BUF_SIZE);
-   coda_write(dev, 0, CODA_CMD_ENC_SEQ_INTRA_REFRESH);
+   coda_write(dev, ctx-params.intra_refresh,
+  CODA_CMD_ENC_SEQ_INTRA_REFRESH);
 
coda_write(dev, bitstream_buf, CODA_CMD_ENC_SEQ_BB_START);
coda_write(dev, bitstream_size / 1024, CODA_CMD_ENC_SEQ_BB_SIZE);
@@ -2680,6 +2682,9 @@ static int coda_s_ctrl(struct v4l2_ctrl *ctrl)
break;
case V4L2_CID_MPEG_VIDEO_HEADER_MODE:
break;
+   case V4L2_CID_MPEG_VIDEO_CYCLIC_INTRA_REFRESH_MB:
+   ctx-params.intra_refresh = ctrl-val;
+   break;
default:
v4l2_dbg(1, coda_debug, ctx-dev-v4l2_dev,
Invalid control, id=%d, val=%d\n,
@@ -2741,6 +2746,8 @@ static int coda_ctrls_setup(struct coda_ctx *ctx)
V4L2_MPEG_VIDEO_HEADER_MODE_JOINED_WITH_1ST_FRAME,
(1  V4L2_MPEG_VIDEO_HEADER_MODE_SEPARATE),
V4L2_MPEG_VIDEO_HEADER_MODE_JOINED_WITH_1ST_FRAME);
+   v4l2_ctrl_new_std(ctx-ctrls, coda_ctrl_ops,
+   V4L2_CID_MPEG_VIDEO_CYCLIC_INTRA_REFRESH_MB, 0, 1920 * 1088 / 
256, 1, 0);
 
if (ctx-ctrls.error) {
v4l2_err(ctx-dev-v4l2_dev, control initialization error 
(%d),
-- 
2.0.0

--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v3 20/32] [media] coda: add decoder timestamp queue

2014-07-11 Thread Philipp Zabel
The coda driver advertises timestamp_type V4L2_BUF_FLAG_TIMESTAMP_COPY on
both queues, so we have to copy timestamps from input v4l2 buffers to the
corresponding destination v4l2 buffers. Since the h.264 decoder can reorder
frames, a timestamp queue is needed to keep track of and assign the correct
timestamp to destination buffers.

Signed-off-by: Philipp Zabel p.za...@pengutronix.de
---
 drivers/media/platform/coda.c | 50 ++-
 1 file changed, 49 insertions(+), 1 deletion(-)

diff --git a/drivers/media/platform/coda.c b/drivers/media/platform/coda.c
index 8194260..5d06776 100644
--- a/drivers/media/platform/coda.c
+++ b/drivers/media/platform/coda.c
@@ -201,6 +201,13 @@ struct gdi_tiled_map {
 #define GDI_LINEAR_FRAME_MAP 0
 };
 
+struct coda_timestamp {
+   struct list_headlist;
+   u32 sequence;
+   struct v4l2_timecodetimecode;
+   struct timeval  timestamp;
+};
+
 struct coda_ctx {
struct coda_dev *dev;
struct mutexbuffer_mutex;
@@ -235,6 +242,8 @@ struct coda_ctx {
struct coda_aux_buf slicebuf;
struct coda_aux_buf internal_frames[CODA_MAX_FRAMEBUFFERS];
u32 frame_types[CODA_MAX_FRAMEBUFFERS];
+   struct coda_timestamp   frame_timestamps[CODA_MAX_FRAMEBUFFERS];
+   struct list_headtimestamp_list;
struct coda_aux_buf workbuf;
int num_internal_frames;
int idx;
@@ -1013,7 +1022,7 @@ static int coda_bitstream_queue(struct coda_ctx *ctx, 
struct vb2_buffer *src_buf
dma_sync_single_for_device(ctx-dev-plat_dev-dev, 
ctx-bitstream.paddr,
   ctx-bitstream.size, DMA_TO_DEVICE);
 
-   ctx-qsequence++;
+   src_buf-v4l2_buf.sequence = ctx-qsequence++;
 
return 0;
 }
@@ -1049,12 +1058,26 @@ static bool coda_bitstream_try_queue(struct coda_ctx 
*ctx,
 static void coda_fill_bitstream(struct coda_ctx *ctx)
 {
struct vb2_buffer *src_buf;
+   struct coda_timestamp *ts;
 
while (v4l2_m2m_num_src_bufs_ready(ctx-fh.m2m_ctx)  0) {
src_buf = v4l2_m2m_next_src_buf(ctx-fh.m2m_ctx);
 
if (coda_bitstream_try_queue(ctx, src_buf)) {
+   /*
+* Source buffer is queued in the bitstream ringbuffer;
+* queue the timestamp and mark source buffer as done
+*/
src_buf = v4l2_m2m_src_buf_remove(ctx-fh.m2m_ctx);
+
+   ts = kmalloc(sizeof(*ts), GFP_KERNEL);
+   if (ts) {
+   ts-sequence = src_buf-v4l2_buf.sequence;
+   ts-timecode = src_buf-v4l2_buf.timecode;
+   ts-timestamp = src_buf-v4l2_buf.timestamp;
+   list_add_tail(ts-list, ctx-timestamp_list);
+   }
+
v4l2_m2m_buf_done(src_buf, VB2_BUF_STATE_DONE);
} else {
break;
@@ -2602,6 +2625,14 @@ static void coda_stop_streaming(struct vb2_queue *q)
}
 
if (!ctx-streamon_out  !ctx-streamon_cap) {
+   struct coda_timestamp *ts;
+
+   while (!list_empty(ctx-timestamp_list)) {
+   ts = list_first_entry(ctx-timestamp_list,
+ struct coda_timestamp, list);
+   list_del(ts-list);
+   kfree(ts);
+   }
kfifo_init(ctx-bitstream_fifo,
ctx-bitstream.vaddr, ctx-bitstream.size);
ctx-runcounter = 0;
@@ -2889,6 +2920,7 @@ static int coda_open(struct file *file)
ctx-bitstream.vaddr, ctx-bitstream.size);
mutex_init(ctx-bitstream_mutex);
mutex_init(ctx-buffer_mutex);
+   INIT_LIST_HEAD(ctx-timestamp_list);
 
coda_lock(ctx);
list_add(ctx-list, dev-instances);
@@ -2980,6 +3012,7 @@ static void coda_finish_decode(struct coda_ctx *ctx)
struct coda_q_data *q_data_src;
struct coda_q_data *q_data_dst;
struct vb2_buffer *dst_buf;
+   struct coda_timestamp *ts;
int width, height;
int decoded_idx;
int display_idx;
@@ -3101,6 +3134,18 @@ static void coda_finish_decode(struct coda_ctx *ctx)
v4l2_err(dev-v4l2_dev,
 decoded frame index out of range: %d\n, decoded_idx);
} else {
+   ts = list_first_entry(ctx-timestamp_list,
+ struct coda_timestamp, list);
+   list_del(ts-list);
+   val = coda_read(dev, CODA_RET_DEC_PIC_FRAME_NUM) - 1;
+   if (val != ts-sequence) {
+   

[PATCH v3 30/32] [media] coda: store per-context work buffer size in struct coda_devtype

2014-07-11 Thread Philipp Zabel
We had the workbuf_size field since the beginning.
Use it to tighten the code a little bit.

Signed-off-by: Philipp Zabel p.za...@pengutronix.de
---
 drivers/media/platform/coda.c | 58 +++
 1 file changed, 26 insertions(+), 32 deletions(-)

diff --git a/drivers/media/platform/coda.c b/drivers/media/platform/coda.c
index 1c2482a..79e76b8 100644
--- a/drivers/media/platform/coda.c
+++ b/drivers/media/platform/coda.c
@@ -44,10 +44,6 @@
 
 #define CODADX6_MAX_INSTANCES  4
 
-#define CODA_FMO_BUF_SIZE  32
-#define CODADX6_WORK_BUF_SIZE  (288 * 1024 + CODA_FMO_BUF_SIZE * 8 * 1024)
-#define CODA7_WORK_BUF_SIZE(128 * 1024)
-#define CODA9_WORK_BUF_SIZE(80 * 1024)
 #define CODA7_TEMP_BUF_SIZE(304 * 1024)
 #define CODA9_TEMP_BUF_SIZE(204 * 1024)
 #define CODA_PARA_BUF_SIZE (10 * 1024)
@@ -1984,18 +1980,8 @@ static int coda_alloc_context_buffers(struct coda_ctx 
*ctx,
size_t size;
int ret;
 
-   switch (dev-devtype-product) {
-   case CODA_7541:
-   size = CODA7_WORK_BUF_SIZE;
-   break;
-   case CODA_960:
-   size = CODA9_WORK_BUF_SIZE;
-   if (q_data-fourcc == V4L2_PIX_FMT_H264)
-   size += CODA9_PS_SAVE_SIZE;
-   break;
-   default:
+   if (dev-devtype-product == CODA_DX6)
return 0;
-   }
 
if (ctx-psbuf.vaddr) {
v4l2_err(dev-v4l2_dev, psmembuf still allocated\n);
@@ -2031,6 +2017,10 @@ static int coda_alloc_context_buffers(struct coda_ctx 
*ctx,
}
}
 
+   size = dev-devtype-workbuf_size;
+   if (dev-devtype-product == CODA_960 
+   q_data-fourcc == V4L2_PIX_FMT_H264)
+   size += CODA9_PS_SAVE_SIZE;
ret = coda_alloc_context_buf(ctx, ctx-workbuf, size, workbuf);
if (ret  0) {
v4l2_err(dev-v4l2_dev, failed to allocate %d byte context 
buffer,
@@ -3686,28 +3676,32 @@ enum coda_platform {
 
 static const struct coda_devtype coda_devdata[] = {
[CODA_IMX27] = {
-   .firmware   = v4l-codadx6-imx27.bin,
-   .product= CODA_DX6,
-   .codecs = codadx6_codecs,
-   .num_codecs = ARRAY_SIZE(codadx6_codecs),
+   .firmware = v4l-codadx6-imx27.bin,
+   .product  = CODA_DX6,
+   .codecs   = codadx6_codecs,
+   .num_codecs   = ARRAY_SIZE(codadx6_codecs),
+   .workbuf_size = 288 * 1024 + FMO_SLICE_SAVE_BUF_SIZE * 8 * 1024,
},
[CODA_IMX53] = {
-   .firmware   = v4l-coda7541-imx53.bin,
-   .product= CODA_7541,
-   .codecs = coda7_codecs,
-   .num_codecs = ARRAY_SIZE(coda7_codecs),
+   .firmware = v4l-coda7541-imx53.bin,
+   .product  = CODA_7541,
+   .codecs   = coda7_codecs,
+   .num_codecs   = ARRAY_SIZE(coda7_codecs),
+   .workbuf_size = 128 * 1024,
},
[CODA_IMX6Q] = {
-   .firmware   = v4l-coda960-imx6q.bin,
-   .product= CODA_960,
-   .codecs = coda9_codecs,
-   .num_codecs = ARRAY_SIZE(coda9_codecs),
+   .firmware = v4l-coda960-imx6q.bin,
+   .product  = CODA_960,
+   .codecs   = coda9_codecs,
+   .num_codecs   = ARRAY_SIZE(coda9_codecs),
+   .workbuf_size = 80 * 1024,
},
[CODA_IMX6DL] = {
-   .firmware   = v4l-coda960-imx6dl.bin,
-   .product= CODA_960,
-   .codecs = coda9_codecs,
-   .num_codecs = ARRAY_SIZE(coda9_codecs),
+   .firmware = v4l-coda960-imx6dl.bin,
+   .product  = CODA_960,
+   .codecs   = coda9_codecs,
+   .num_codecs   = ARRAY_SIZE(coda9_codecs),
+   .workbuf_size = 80 * 1024,
},
 };
 
@@ -3830,7 +3824,7 @@ static int coda_probe(struct platform_device *pdev)
switch (dev-devtype-product) {
case CODA_DX6:
ret = coda_alloc_aux_buf(dev, dev-workbuf,
-CODADX6_WORK_BUF_SIZE, workbuf,
+dev-devtype-workbuf_size, workbuf,
 dev-debugfs_root);
if (ret  0) {
dev_err(pdev-dev, failed to allocate work buffer\n);
-- 
2.0.0

--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v3 01/32] [media] coda: fix decoder I/P/B frame detection

2014-07-11 Thread Philipp Zabel
Currently the rotator unit is used to copy decoded frames out into buffers
provided by videobuf2. Since the CODA reports the I/P/B frame type of the
last decoded frame, and this frame will be copied out in a later device_run,
depending on display order, we have to store the frame type until such time.
This patch also adds the B-frame type.

Signed-off-by: Philipp Zabel p.za...@pengutronix.de
---
 drivers/media/platform/coda.c | 23 ++-
 1 file changed, 14 insertions(+), 9 deletions(-)

diff --git a/drivers/media/platform/coda.c b/drivers/media/platform/coda.c
index b178379..a7c5ac5 100644
--- a/drivers/media/platform/coda.c
+++ b/drivers/media/platform/coda.c
@@ -209,6 +209,7 @@ struct coda_ctx {
struct coda_aux_buf psbuf;
struct coda_aux_buf slicebuf;
struct coda_aux_buf internal_frames[CODA_MAX_FRAMEBUFFERS];
+   u32 frame_types[CODA_MAX_FRAMEBUFFERS];
struct coda_aux_buf workbuf;
int num_internal_frames;
int idx;
@@ -2693,15 +2694,6 @@ static void coda_finish_decode(struct coda_ctx *ctx)
 
q_data_dst = get_q_data(ctx, V4L2_BUF_TYPE_VIDEO_CAPTURE);
 
-   val = coda_read(dev, CODA_RET_DEC_PIC_TYPE);
-   if ((val  0x7) == 0) {
-   dst_buf-v4l2_buf.flags |= V4L2_BUF_FLAG_KEYFRAME;
-   dst_buf-v4l2_buf.flags = ~V4L2_BUF_FLAG_PFRAME;
-   } else {
-   dst_buf-v4l2_buf.flags |= V4L2_BUF_FLAG_PFRAME;
-   dst_buf-v4l2_buf.flags = ~V4L2_BUF_FLAG_KEYFRAME;
-   }
-
val = coda_read(dev, CODA_RET_DEC_PIC_ERR_MB);
if (val  0)
v4l2_err(dev-v4l2_dev,
@@ -2748,6 +2740,14 @@ static void coda_finish_decode(struct coda_ctx *ctx)
} else if (decoded_idx  0 || decoded_idx = ctx-num_internal_frames) {
v4l2_err(dev-v4l2_dev,
 decoded frame index out of range: %d\n, decoded_idx);
+   } else {
+   val = coda_read(dev, CODA_RET_DEC_PIC_TYPE)  0x7;
+   if (val == 0)
+   ctx-frame_types[decoded_idx] = V4L2_BUF_FLAG_KEYFRAME;
+   else if (val == 1)
+   ctx-frame_types[decoded_idx] = V4L2_BUF_FLAG_PFRAME;
+   else
+   ctx-frame_types[decoded_idx] = V4L2_BUF_FLAG_BFRAME;
}
 
if (display_idx == -1) {
@@ -2770,6 +2770,11 @@ static void coda_finish_decode(struct coda_ctx *ctx)
dst_buf = v4l2_m2m_dst_buf_remove(ctx-m2m_ctx);
dst_buf-v4l2_buf.sequence = ctx-osequence++;
 
+   dst_buf-v4l2_buf.flags = ~(V4L2_BUF_FLAG_KEYFRAME |
+V4L2_BUF_FLAG_PFRAME |
+V4L2_BUF_FLAG_BFRAME);
+   dst_buf-v4l2_buf.flags |= ctx-frame_types[ctx-display_idx];
+
vb2_set_plane_payload(dst_buf, 0, width * height * 3 / 2);
 
v4l2_m2m_buf_done(dst_buf, success ? VB2_BUF_STATE_DONE :
-- 
2.0.0

--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v3 21/32] [media] coda: alert userspace about macroblock errors

2014-07-11 Thread Philipp Zabel
If the CODA reports macroblock errors, also set the VB2_BUF_STATE_ERROR flag
to alert userspace.

Signed-off-by: Philipp Zabel p.za...@pengutronix.de
---
 drivers/media/platform/coda.c | 14 +-
 1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/drivers/media/platform/coda.c b/drivers/media/platform/coda.c
index 5d06776..0405a7a 100644
--- a/drivers/media/platform/coda.c
+++ b/drivers/media/platform/coda.c
@@ -243,6 +243,7 @@ struct coda_ctx {
struct coda_aux_buf internal_frames[CODA_MAX_FRAMEBUFFERS];
u32 frame_types[CODA_MAX_FRAMEBUFFERS];
struct coda_timestamp   frame_timestamps[CODA_MAX_FRAMEBUFFERS];
+   u32 frame_errors[CODA_MAX_FRAMEBUFFERS];
struct list_headtimestamp_list;
struct coda_aux_buf workbuf;
int num_internal_frames;
@@ -3018,6 +3019,7 @@ static void coda_finish_decode(struct coda_ctx *ctx)
int display_idx;
u32 src_fourcc;
int success;
+   u32 err_mb;
u32 val;
 
dst_buf = v4l2_m2m_next_dst_buf(ctx-fh.m2m_ctx);
@@ -3087,10 +3089,10 @@ static void coda_finish_decode(struct coda_ctx *ctx)
/* no cropping */
}
 
-   val = coda_read(dev, CODA_RET_DEC_PIC_ERR_MB);
-   if (val  0)
+   err_mb = coda_read(dev, CODA_RET_DEC_PIC_ERR_MB);
+   if (err_mb  0)
v4l2_err(dev-v4l2_dev,
-errors in %d macroblocks\n, val);
+errors in %d macroblocks\n, err_mb);
 
if (dev-devtype-product == CODA_7541) {
val = coda_read(dev, CODA_RET_DEC_PIC_OPTION);
@@ -3153,6 +3155,8 @@ static void coda_finish_decode(struct coda_ctx *ctx)
ctx-frame_types[decoded_idx] = V4L2_BUF_FLAG_PFRAME;
else
ctx-frame_types[decoded_idx] = V4L2_BUF_FLAG_BFRAME;
+
+   ctx-frame_errors[decoded_idx] = err_mb;
}
 
if (display_idx == -1) {
@@ -3185,8 +3189,8 @@ static void coda_finish_decode(struct coda_ctx *ctx)
 
vb2_set_plane_payload(dst_buf, 0, width * height * 3 / 2);
 
-   v4l2_m2m_buf_done(dst_buf, success ? VB2_BUF_STATE_DONE :
-VB2_BUF_STATE_ERROR);
+   v4l2_m2m_buf_done(dst_buf, ctx-frame_errors[display_idx] ?
+ VB2_BUF_STATE_ERROR : VB2_BUF_STATE_DONE);
 
v4l2_dbg(1, coda_debug, dev-v4l2_dev,
job finished: decoding frame (%d) (%s)\n,
-- 
2.0.0

--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v3 00/32] Initial CODA960 (i.MX6 VPU) support

2014-07-11 Thread Philipp Zabel
Hi,

this is series adds support for the CODA960 Video Processing
Unit on i.MX6Q/D/DL/S SoCs to the coda driver.

Changes since v2:
 - Fixed patch 22 [media] coda: add sequence counter offset
   for 16-bit hardware frame counter
 - Changed variable name in patch 23 [media] coda: rename
prescan_failed to hold and stop stream after timeout
 - Added patches 30-32 to store work buffer size, temp buffer
   size, and IRAM size in the coda_devtype struct.

This series contains a few fixes and preparations, the CODA960
support patch, a rework of the hardware access serialization
into a single threaded workqueue, some cleanups to use more
infrastructure that is available in the meantime, runtime PM
support, a few h.264 related v4l2 controls and fixes, support
for hard resets via the i.MX system reset controller, a patch
that exports internal buffers to debugfs, and a few code cleanups.

regards
Philipp

Michael Olbrich (2):
  [media] v4l2-mem2mem: export v4l2_m2m_try_schedule
  [media] coda: try to schedule a decode run after a stop command

Philipp Zabel (30):
  [media] coda: fix decoder I/P/B frame detection
  [media] coda: fix readback of CODA_RET_DEC_SEQ_FRAME_NEED
  [media] coda: fix h.264 quantization parameter range
  [media] coda: fix internal framebuffer allocation size
  [media] coda: simplify IRAM setup
  [media] coda: Add encoder/decoder support for CODA960
  [media] coda: remove BUG() in get_q_data
  [media] coda: add selection API support for h.264 decoder
  [media] coda: add workqueue to serialize hardware commands
  [media] coda: Use mem-to-mem ioctl helpers
  [media] coda: use ctx-fh.m2m_ctx instead of ctx-m2m_ctx
  [media] coda: Add runtime pm support
  [media] coda: split firmware version check out of coda_hw_init
  [media] coda: select GENERIC_ALLOCATOR
  [media] coda: add h.264 min/max qp controls
  [media] coda: add h.264 deblocking filter controls
  [media] coda: add cyclic intra refresh control
  [media] coda: add decoder timestamp queue
  [media] coda: alert userspace about macroblock errors
  [media] coda: add sequence counter offset
  [media] coda: rename prescan_failed to hold and stop stream after
timeout
  [media] coda: add reset control support
  [media] coda: add bytesperline to queue data
  [media] coda: allow odd width, but still round up bytesperline
  [media] coda: round up internal frames to multiples of macroblock size
for h.264
  [media] coda: increase frame stride to 16 for h.264
  [media] coda: export auxiliary buffers via debugfs
  [media] coda: store per-context work buffer size in struct
coda_devtype
  [media] coda: store global temporary buffer size in struct
coda_devtype
  [media] coda: store IRAM size in struct coda_devtype

 drivers/media/platform/Kconfig |1 +
 drivers/media/platform/coda.c  | 1505 ++--
 drivers/media/platform/coda.h  |  115 ++-
 drivers/media/v4l2-core/v4l2-mem2mem.c |3 +-
 include/media/v4l2-mem2mem.h   |2 +
 5 files changed, 1163 insertions(+), 463 deletions(-)

-- 
2.0.0

--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v3 16/32] [media] coda: add h.264 deblocking filter controls

2014-07-11 Thread Philipp Zabel
This adds controls for the h.264 deblocking loop filter.

Signed-off-by: Philipp Zabel p.za...@pengutronix.de
---
 drivers/media/platform/coda.c | 33 -
 1 file changed, 32 insertions(+), 1 deletion(-)

diff --git a/drivers/media/platform/coda.c b/drivers/media/platform/coda.c
index cb8d49d..839aa36 100644
--- a/drivers/media/platform/coda.c
+++ b/drivers/media/platform/coda.c
@@ -161,6 +161,9 @@ struct coda_params {
u8  h264_inter_qp;
u8  h264_min_qp;
u8  h264_max_qp;
+   u8  h264_deblk_enabled;
+   u8  h264_deblk_alpha;
+   u8  h264_deblk_beta;
u8  mpeg4_intra_qp;
u8  mpeg4_inter_qp;
u8  gop_size;
@@ -2328,7 +2331,17 @@ static int coda_start_encoding(struct coda_ctx *ctx)
coda_write(dev, CODA9_STD_H264, 
CODA_CMD_ENC_SEQ_COD_STD);
else
coda_write(dev, CODA_STD_H264, 
CODA_CMD_ENC_SEQ_COD_STD);
-   coda_write(dev, 0, CODA_CMD_ENC_SEQ_264_PARA);
+   if (ctx-params.h264_deblk_enabled) {
+   value = ((ctx-params.h264_deblk_alpha 
+ CODA_264PARAM_DEBLKFILTEROFFSETALPHA_MASK) 
+CODA_264PARAM_DEBLKFILTEROFFSETALPHA_OFFSET) |
+   ((ctx-params.h264_deblk_beta 
+ CODA_264PARAM_DEBLKFILTEROFFSETBETA_MASK) 
+CODA_264PARAM_DEBLKFILTEROFFSETBETA_OFFSET);
+   } else {
+   value = 1  CODA_264PARAM_DISABLEDEBLK_OFFSET;
+   }
+   coda_write(dev, value, CODA_CMD_ENC_SEQ_264_PARA);
break;
default:
v4l2_err(v4l2_dev,
@@ -2640,6 +2653,16 @@ static int coda_s_ctrl(struct v4l2_ctrl *ctrl)
case V4L2_CID_MPEG_VIDEO_H264_MAX_QP:
ctx-params.h264_max_qp = ctrl-val;
break;
+   case V4L2_CID_MPEG_VIDEO_H264_LOOP_FILTER_ALPHA:
+   ctx-params.h264_deblk_alpha = ctrl-val;
+   break;
+   case V4L2_CID_MPEG_VIDEO_H264_LOOP_FILTER_BETA:
+   ctx-params.h264_deblk_beta = ctrl-val;
+   break;
+   case V4L2_CID_MPEG_VIDEO_H264_LOOP_FILTER_MODE:
+   ctx-params.h264_deblk_enabled = (ctrl-val ==
+   V4L2_MPEG_VIDEO_H264_LOOP_FILTER_MODE_ENABLED);
+   break;
case V4L2_CID_MPEG_VIDEO_MPEG4_I_FRAME_QP:
ctx-params.mpeg4_intra_qp = ctrl-val;
break;
@@ -2694,6 +2717,14 @@ static int coda_ctrls_setup(struct coda_ctx *ctx)
v4l2_ctrl_new_std(ctx-ctrls, coda_ctrl_ops,
V4L2_CID_MPEG_VIDEO_H264_MAX_QP, 0, 51, 1, 51);
v4l2_ctrl_new_std(ctx-ctrls, coda_ctrl_ops,
+   V4L2_CID_MPEG_VIDEO_H264_LOOP_FILTER_ALPHA, 0, 15, 1, 0);
+   v4l2_ctrl_new_std(ctx-ctrls, coda_ctrl_ops,
+   V4L2_CID_MPEG_VIDEO_H264_LOOP_FILTER_BETA, 0, 15, 1, 0);
+   v4l2_ctrl_new_std_menu(ctx-ctrls, coda_ctrl_ops,
+   V4L2_CID_MPEG_VIDEO_H264_LOOP_FILTER_MODE,
+   V4L2_MPEG_VIDEO_H264_LOOP_FILTER_MODE_DISABLED, 0x0,
+   V4L2_MPEG_VIDEO_H264_LOOP_FILTER_MODE_ENABLED);
+   v4l2_ctrl_new_std(ctx-ctrls, coda_ctrl_ops,
V4L2_CID_MPEG_VIDEO_MPEG4_I_FRAME_QP, 1, 31, 1, 2);
v4l2_ctrl_new_std(ctx-ctrls, coda_ctrl_ops,
V4L2_CID_MPEG_VIDEO_MPEG4_P_FRAME_QP, 1, 31, 1, 2);
-- 
2.0.0

--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v3 05/32] [media] coda: simplify IRAM setup

2014-07-11 Thread Philipp Zabel
OVL and BTP IRAM buffers are never used, setup the bits for
for DBK/BIT/IP usage depending on CODA version in one place.
Also, use a simple allocator function and group IRAM addresses
and size in a coda_aux_buf structure.
This is done in preparation for CODA960 support.

Signed-off-by: Philipp Zabel p.za...@pengutronix.de
---
 drivers/media/platform/coda.c | 175 ++
 1 file changed, 74 insertions(+), 101 deletions(-)

diff --git a/drivers/media/platform/coda.c b/drivers/media/platform/coda.c
index e3dddcb..50051fe 100644
--- a/drivers/media/platform/coda.c
+++ b/drivers/media/platform/coda.c
@@ -135,9 +135,7 @@ struct coda_dev {
struct coda_aux_buf tempbuf;
struct coda_aux_buf workbuf;
struct gen_pool *iram_pool;
-   long unsigned int   iram_vaddr;
-   long unsigned int   iram_paddr;
-   unsigned long   iram_size;
+   struct coda_aux_buf iram;
 
spinlock_t  irqlock;
struct mutexdev_mutex;
@@ -175,6 +173,8 @@ struct coda_iram_info {
phys_addr_t buf_btp_use;
phys_addr_t search_ram_paddr;
int search_ram_size;
+   int remaining;
+   phys_addr_t next_paddr;
 };
 
 struct coda_ctx {
@@ -1580,23 +1580,43 @@ static int coda_h264_padding(int size, char *p)
return nal_size;
 }
 
+static phys_addr_t coda_iram_alloc(struct coda_iram_info *iram, size_t size)
+{
+   phys_addr_t ret;
+
+   size = round_up(size, 1024);
+   if (size  iram-remaining)
+   return 0;
+   iram-remaining -= size;
+
+   ret = iram-next_paddr;
+   iram-next_paddr += size;
+
+   return ret;
+}
+
 static void coda_setup_iram(struct coda_ctx *ctx)
 {
struct coda_iram_info *iram_info = ctx-iram_info;
struct coda_dev *dev = ctx-dev;
-   int ipacdc_size;
-   int bitram_size;
-   int dbk_size;
-   int ovl_size;
int mb_width;
-   int me_size;
-   int size;
+   int dbk_bits;
+   int bit_bits;
+   int ip_bits;
 
memset(iram_info, 0, sizeof(*iram_info));
-   size = dev-iram_size;
+   iram_info-next_paddr = dev-iram.paddr;
+   iram_info-remaining = dev-iram.size;
 
-   if (dev-devtype-product == CODA_DX6)
+   switch (dev-devtype-product) {
+   case CODA_7541:
+   dbk_bits = CODA7_USE_HOST_DBK_ENABLE | CODA7_USE_DBK_ENABLE;
+   bit_bits = CODA7_USE_HOST_BIT_ENABLE | CODA7_USE_BIT_ENABLE;
+   ip_bits = CODA7_USE_HOST_IP_ENABLE | CODA7_USE_IP_ENABLE;
+   break;
+   default: /* CODA_DX6 */
return;
+   }
 
if (ctx-inst_type == CODA_INST_ENCODER) {
struct coda_q_data *q_data_src;
@@ -1605,111 +1625,63 @@ static void coda_setup_iram(struct coda_ctx *ctx)
mb_width = DIV_ROUND_UP(q_data_src-width, 16);
 
/* Prioritize in case IRAM is too small for everything */
-   me_size = round_up(round_up(q_data_src-width, 16) * 36 + 2048,
-  1024);
-   iram_info-search_ram_size = me_size;
-   if (size = iram_info-search_ram_size) {
-   if (dev-devtype-product == CODA_7541)
-   iram_info-axi_sram_use |= 
CODA7_USE_HOST_ME_ENABLE;
-   iram_info-search_ram_paddr = dev-iram_paddr;
-   size -= iram_info-search_ram_size;
-   } else {
-   pr_err(IRAM is smaller than the search ram size\n);
-   goto out;
+   if (dev-devtype-product == CODA_7541) {
+   iram_info-search_ram_size = round_up(mb_width * 16 *
+ 36 + 2048, 1024);
+   iram_info-search_ram_paddr = coda_iram_alloc(iram_info,
+   
iram_info-search_ram_size);
+   if (!iram_info-search_ram_paddr) {
+   pr_err(IRAM is smaller than the search ram 
size\n);
+   goto out;
+   }
+   iram_info-axi_sram_use |= CODA7_USE_HOST_ME_ENABLE |
+  CODA7_USE_ME_ENABLE;
}
 
/* Only H.264BP and H.263P3 are considered */
-   dbk_size = round_up(128 * mb_width, 1024);
-   if (size = dbk_size) {
-   iram_info-axi_sram_use |= CODA7_USE_HOST_DBK_ENABLE;
-   iram_info-buf_dbk_y_use = dev-iram_paddr +
-  iram_info-search_ram_size;
-   iram_info-buf_dbk_c_use = iram_info-buf_dbk_y_use +
-  dbk_size / 2;
-   size -= 

[PATCH v3 18/32] [media] v4l2-mem2mem: export v4l2_m2m_try_schedule

2014-07-11 Thread Philipp Zabel
From: Michael Olbrich m.olbr...@pengutronix.de

Some drivers might allow to decode remaining frames from an internal ringbuffer
after a decoder stop command. Allow those to call v4l2_m2m_try_schedule
directly.

Signed-off-by: Michael Olbrich m.olbr...@pengutronix.de
Signed-off-by: Philipp Zabel p.za...@pengutronix.de
---
 drivers/media/v4l2-core/v4l2-mem2mem.c | 3 ++-
 include/media/v4l2-mem2mem.h   | 2 ++
 2 files changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/media/v4l2-core/v4l2-mem2mem.c 
b/drivers/media/v4l2-core/v4l2-mem2mem.c
index 178ce96..5f5c175 100644
--- a/drivers/media/v4l2-core/v4l2-mem2mem.c
+++ b/drivers/media/v4l2-core/v4l2-mem2mem.c
@@ -208,7 +208,7 @@ static void v4l2_m2m_try_run(struct v4l2_m2m_dev *m2m_dev)
  * An example of the above could be an instance that requires more than one
  * src/dst buffer per transaction.
  */
-static void v4l2_m2m_try_schedule(struct v4l2_m2m_ctx *m2m_ctx)
+void v4l2_m2m_try_schedule(struct v4l2_m2m_ctx *m2m_ctx)
 {
struct v4l2_m2m_dev *m2m_dev;
unsigned long flags_job, flags_out, flags_cap;
@@ -274,6 +274,7 @@ static void v4l2_m2m_try_schedule(struct v4l2_m2m_ctx 
*m2m_ctx)
 
v4l2_m2m_try_run(m2m_dev);
 }
+EXPORT_SYMBOL(v4l2_m2m_try_schedule);
 
 /**
  * v4l2_m2m_cancel_job() - cancel pending jobs for the context
diff --git a/include/media/v4l2-mem2mem.h b/include/media/v4l2-mem2mem.h
index 12ea5a6..c5f3914 100644
--- a/include/media/v4l2-mem2mem.h
+++ b/include/media/v4l2-mem2mem.h
@@ -95,6 +95,8 @@ void *v4l2_m2m_get_curr_priv(struct v4l2_m2m_dev *m2m_dev);
 struct vb2_queue *v4l2_m2m_get_vq(struct v4l2_m2m_ctx *m2m_ctx,
   enum v4l2_buf_type type);
 
+void v4l2_m2m_try_schedule(struct v4l2_m2m_ctx *m2m_ctx);
+
 void v4l2_m2m_job_finish(struct v4l2_m2m_dev *m2m_dev,
 struct v4l2_m2m_ctx *m2m_ctx);
 
-- 
2.0.0

--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v3 12/32] [media] coda: Add runtime pm support

2014-07-11 Thread Philipp Zabel
This patch allows to use the runtime pm and generic pm domain frameworks
to completely gate power to the VPU if it is unused. This functionality
is available on i.MX6.

Signed-off-by: Philipp Zabel p.za...@pengutronix.de
---
 drivers/media/platform/coda.c | 65 +++
 1 file changed, 60 insertions(+), 5 deletions(-)

diff --git a/drivers/media/platform/coda.c b/drivers/media/platform/coda.c
index 0f692b0..e4d31b9 100644
--- a/drivers/media/platform/coda.c
+++ b/drivers/media/platform/coda.c
@@ -22,6 +22,7 @@
 #include linux/module.h
 #include linux/of_device.h
 #include linux/platform_device.h
+#include linux/pm_runtime.h
 #include linux/slab.h
 #include linux/videodev2.h
 #include linux/of.h
@@ -2769,6 +2770,13 @@ static int coda_open(struct file *file)
ctx-reg_idx = idx;
}
 
+   /* Power up and upload firmware if necessary */
+   ret = pm_runtime_get_sync(dev-plat_dev-dev);
+   if (ret  0) {
+   v4l2_err(dev-v4l2_dev, failed to power up: %d\n, ret);
+   goto err_pm_get;
+   }
+
ret = clk_prepare_enable(dev-clk_per);
if (ret)
goto err_clk_per;
@@ -2838,6 +2846,8 @@ err_ctx_init:
 err_clk_ahb:
clk_disable_unprepare(dev-clk_per);
 err_clk_per:
+   pm_runtime_put_sync(dev-plat_dev-dev);
+err_pm_get:
v4l2_fh_del(ctx-fh);
v4l2_fh_exit(ctx-fh);
clear_bit(ctx-idx, dev-instance_mask);
@@ -2879,6 +2889,7 @@ static int coda_release(struct file *file)
v4l2_ctrl_handler_free(ctx-ctrls);
clk_disable_unprepare(dev-clk_ahb);
clk_disable_unprepare(dev-clk_per);
+   pm_runtime_put_sync(dev-plat_dev-dev);
v4l2_fh_del(ctx-fh);
v4l2_fh_exit(ctx-fh);
clear_bit(ctx-idx, dev-instance_mask);
@@ -3193,7 +3204,7 @@ static int coda_hw_init(struct coda_dev *dev)
 
ret = clk_prepare_enable(dev-clk_per);
if (ret)
-   return ret;
+   goto err_clk_per;
 
ret = clk_prepare_enable(dev-clk_ahb);
if (ret)
@@ -3319,6 +3330,7 @@ static int coda_hw_init(struct coda_dev *dev)
 
 err_clk_ahb:
clk_disable_unprepare(dev-clk_per);
+err_clk_per:
return ret;
 }
 
@@ -3344,10 +3356,29 @@ static void coda_fw_callback(const struct firmware *fw, 
void *context)
memcpy(dev-codebuf.vaddr, fw-data, fw-size);
release_firmware(fw);
 
-   ret = coda_hw_init(dev);
-   if (ret) {
-   v4l2_err(dev-v4l2_dev, HW initialization failed\n);
-   return;
+   if (pm_runtime_enabled(pdev-dev)  pdev-dev.pm_domain) {
+   /*
+* Enabling power temporarily will cause coda_hw_init to be
+* called via coda_runtime_resume by the pm domain.
+*/
+   ret = pm_runtime_get_sync(dev-plat_dev-dev);
+   if (ret  0) {
+   v4l2_err(dev-v4l2_dev, failed to power on: %d\n,
+ret);
+   return;
+   }
+
+   pm_runtime_put_sync(dev-plat_dev-dev);
+   } else {
+   /*
+* If runtime pm is disabled or pm_domain is not set,
+* initialize once manually.
+*/
+   ret = coda_hw_init(dev);
+   if (ret  0) {
+   v4l2_err(dev-v4l2_dev, HW initialization failed\n);
+   return;
+   }
}
 
dev-vfd.fops   = coda_fops,
@@ -3585,6 +3616,8 @@ static int coda_probe(struct platform_device *pdev)
 
platform_set_drvdata(pdev, dev);
 
+   pm_runtime_enable(pdev-dev);
+
return coda_firmware_request(dev);
 }
 
@@ -3595,6 +3628,7 @@ static int coda_remove(struct platform_device *pdev)
video_unregister_device(dev-vfd);
if (dev-m2m_dev)
v4l2_m2m_release(dev-m2m_dev);
+   pm_runtime_disable(pdev-dev);
if (dev-alloc_ctx)
vb2_dma_contig_cleanup_ctx(dev-alloc_ctx);
v4l2_device_unregister(dev-v4l2_dev);
@@ -3608,6 +3642,26 @@ static int coda_remove(struct platform_device *pdev)
return 0;
 }
 
+#ifdef CONFIG_PM_RUNTIME
+static int coda_runtime_resume(struct device *dev)
+{
+   struct coda_dev *cdev = dev_get_drvdata(dev);
+   int ret = 0;
+
+   if (dev-pm_domain) {
+   ret = coda_hw_init(cdev);
+   if (ret)
+   v4l2_err(cdev-v4l2_dev, HW initialization failed\n);
+   }
+
+   return ret;
+}
+#endif
+
+static const struct dev_pm_ops coda_pm_ops = {
+   SET_RUNTIME_PM_OPS(NULL, coda_runtime_resume, NULL)
+};
+
 static struct platform_driver coda_driver = {
.probe  = coda_probe,
.remove = coda_remove,
@@ -3615,6 +3669,7 @@ static struct platform_driver coda_driver = {
.name   = CODA_NAME,
.owner  = THIS_MODULE,
.of_match_table = 

[PATCH v3 07/32] [media] coda: remove BUG() in get_q_data

2014-07-11 Thread Philipp Zabel
This allows us to get rid of the now superfluous v4l2_m2m_get_vq check
in G_FMT. Also, we can use this to check the buffer type in G_SELECTION
later.

Signed-off-by: Philipp Zabel p.za...@pengutronix.de
---
 drivers/media/platform/coda.c | 12 +---
 1 file changed, 5 insertions(+), 7 deletions(-)

diff --git a/drivers/media/platform/coda.c b/drivers/media/platform/coda.c
index 94654cf..59f16ac 100644
--- a/drivers/media/platform/coda.c
+++ b/drivers/media/platform/coda.c
@@ -326,9 +326,8 @@ static struct coda_q_data *get_q_data(struct coda_ctx *ctx,
case V4L2_BUF_TYPE_VIDEO_CAPTURE:
return (ctx-q_data[V4L2_M2M_DST]);
default:
-   BUG();
+   return NULL;
}
-   return NULL;
 }
 
 /*
@@ -571,15 +570,12 @@ static int coda_enum_fmt_vid_out(struct file *file, void 
*priv,
 static int coda_g_fmt(struct file *file, void *priv,
  struct v4l2_format *f)
 {
-   struct vb2_queue *vq;
struct coda_q_data *q_data;
struct coda_ctx *ctx = fh_to_ctx(priv);
 
-   vq = v4l2_m2m_get_vq(ctx-m2m_ctx, f-type);
-   if (!vq)
-   return -EINVAL;
-
q_data = get_q_data(ctx, f-type);
+   if (!q_data)
+   return -EINVAL;
 
f-fmt.pix.field= V4L2_FIELD_NONE;
f-fmt.pix.pixelformat  = q_data-fourcc;
@@ -628,6 +624,8 @@ static int coda_try_fmt(struct coda_ctx *ctx, struct 
coda_codec *codec,
break;
default:
q_data = get_q_data(ctx, f-type);
+   if (!q_data)
+   return -EINVAL;
f-fmt.pix.pixelformat = q_data-fourcc;
}
 
-- 
2.0.0

--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v3 23/32] [media] coda: rename prescan_failed to hold and stop stream after timeout

2014-07-11 Thread Philipp Zabel
Rename the per-context prescan_failed variable to hold, as this is what the
flag  does: it temporarily keeps the coda from running until new data is fed
into the bitstream buffer or stop_streaming is called on the input side.
A prescan failure on i.MX5 is one possible reason to enter this state, another
one is a picture run timeout on i.MX6.

Signed-off-by: Philipp Zabel p.za...@pengutronix.de
---
 drivers/media/platform/coda.c | 16 +---
 1 file changed, 9 insertions(+), 7 deletions(-)

diff --git a/drivers/media/platform/coda.c b/drivers/media/platform/coda.c
index d7404e9..4f3d535 100644
--- a/drivers/media/platform/coda.c
+++ b/drivers/media/platform/coda.c
@@ -237,7 +237,7 @@ struct coda_ctx {
struct kfifobitstream_fifo;
struct mutexbitstream_mutex;
struct coda_aux_buf bitstream;
-   boolprescan_failed;
+   boolhold;
struct coda_aux_buf parabuf;
struct coda_aux_buf psbuf;
struct coda_aux_buf slicebuf;
@@ -920,7 +920,7 @@ static int coda_decoder_cmd(struct file *file, void *fh,
/* If this context is currently running, update the hardware 
flag */
coda_write(dev, ctx-bit_stream_param, 
CODA_REG_BIT_BIT_STREAM_PARAM);
}
-   ctx-prescan_failed = false;
+   ctx-hold = false;
v4l2_m2m_try_schedule(ctx-fh.m2m_ctx);
 
return 0;
@@ -1052,7 +1052,7 @@ static bool coda_bitstream_try_queue(struct coda_ctx *ctx,
if (ctx == v4l2_m2m_get_curr_priv(ctx-dev-m2m_dev))
coda_kfifo_sync_to_device_write(ctx);
 
-   ctx-prescan_failed = false;
+   ctx-hold = false;
 
return true;
 }
@@ -1423,6 +1423,8 @@ static void coda_pic_run_work(struct work_struct *work)
 
if (!wait_for_completion_timeout(ctx-completion, 
msecs_to_jiffies(1000))) {
dev_err(dev-plat_dev-dev, CODA PIC_RUN timeout\n);
+
+   ctx-hold = true;
} else if (!ctx-aborting) {
if (ctx-inst_type == CODA_INST_DECODER)
coda_finish_decode(ctx);
@@ -1461,7 +1463,7 @@ static int coda_job_ready(void *m2m_priv)
return 0;
}
 
-   if (ctx-prescan_failed ||
+   if (ctx-hold ||
((ctx-inst_type == CODA_INST_DECODER) 
 (coda_get_bitstream_payload(ctx)  512) 
 !(ctx-bit_stream_param  CODA_BIT_STREAM_END_FLAG))) {
@@ -3102,7 +3104,7 @@ static void coda_finish_decode(struct coda_ctx *ctx)
/* not enough bitstream data */
v4l2_dbg(1, coda_debug, dev-v4l2_dev,
 prescan failed: %d\n, val);
-   ctx-prescan_failed = true;
+   ctx-hold = true;
return;
}
}
@@ -3133,7 +3135,7 @@ static void coda_finish_decode(struct coda_ctx *ctx)
if (display_idx = 0  display_idx  ctx-num_internal_frames)
ctx-sequence_offset++;
else if (ctx-display_idx  0)
-   ctx-prescan_failed = true;
+   ctx-hold = true;
} else if (decoded_idx == -2) {
/* no frame was decoded, we still return the remaining buffers 
*/
} else if (decoded_idx  0 || decoded_idx = ctx-num_internal_frames) {
@@ -3169,7 +3171,7 @@ static void coda_finish_decode(struct coda_ctx *ctx)
 * no more frames to be decoded, but there could still
 * be rotator output to dequeue
 */
-   ctx-prescan_failed = true;
+   ctx-hold = true;
} else if (display_idx == -3) {
/* possibly prescan failure */
} else if (display_idx  0 || display_idx = ctx-num_internal_frames) {
-- 
2.0.0

--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v3 24/32] [media] coda: add reset control support

2014-07-11 Thread Philipp Zabel
On i.MX53 and i.MX6, the CODA VPU can be reset by the System Reset Controller.
We can use this to get out of dire situations, for example after a picture
run timeout.

Signed-off-by: Philipp Zabel p.za...@pengutronix.de
---
 drivers/media/platform/coda.c | 51 +++
 1 file changed, 51 insertions(+)

diff --git a/drivers/media/platform/coda.c b/drivers/media/platform/coda.c
index 4f3d535..995c289 100644
--- a/drivers/media/platform/coda.c
+++ b/drivers/media/platform/coda.c
@@ -27,6 +27,7 @@
 #include linux/videodev2.h
 #include linux/of.h
 #include linux/platform_data/coda.h
+#include linux/reset.h
 
 #include media/v4l2-ctrls.h
 #include media/v4l2-device.h
@@ -138,6 +139,7 @@ struct coda_dev {
void __iomem*regs_base;
struct clk  *clk_per;
struct clk  *clk_ahb;
+   struct reset_control*rstc;
 
struct coda_aux_buf codebuf;
struct coda_aux_buf tempbuf;
@@ -337,6 +339,39 @@ static int coda_command_sync(struct coda_ctx *ctx, int cmd)
return coda_wait_timeout(dev);
 }
 
+static int coda_hw_reset(struct coda_ctx *ctx)
+{
+   struct coda_dev *dev = ctx-dev;
+   unsigned long timeout;
+   unsigned int idx;
+   int ret;
+
+   if (!dev-rstc)
+   return -ENOENT;
+
+   idx = coda_read(dev, CODA_REG_BIT_RUN_INDEX);
+
+   timeout = jiffies + msecs_to_jiffies(100);
+   coda_write(dev, 0x11, CODA9_GDI_BUS_CTRL);
+   while (coda_read(dev, CODA9_GDI_BUS_STATUS) != 0x77) {
+   if (time_after(jiffies, timeout))
+   return -ETIME;
+   cpu_relax();
+   }
+
+   ret = reset_control_reset(dev-rstc);
+   if (ret  0)
+   return ret;
+
+   coda_write(dev, 0x00, CODA9_GDI_BUS_CTRL);
+   coda_write(dev, CODA_REG_BIT_BUSY_FLAG, CODA_REG_BIT_BUSY);
+   coda_write(dev, CODA_REG_RUN_ENABLE, CODA_REG_BIT_CODE_RUN);
+   ret = coda_wait_timeout(dev);
+   coda_write(dev, idx, CODA_REG_BIT_RUN_INDEX);
+
+   return ret;
+}
+
 static struct coda_q_data *get_q_data(struct coda_ctx *ctx,
 enum v4l2_buf_type type)
 {
@@ -1425,6 +1460,8 @@ static void coda_pic_run_work(struct work_struct *work)
dev_err(dev-plat_dev-dev, CODA PIC_RUN timeout\n);
 
ctx-hold = true;
+
+   coda_hw_reset(ctx);
} else if (!ctx-aborting) {
if (ctx-inst_type == CODA_INST_DECODER)
coda_finish_decode(ctx);
@@ -3335,6 +3372,9 @@ static int coda_hw_init(struct coda_dev *dev)
if (ret)
goto err_clk_ahb;
 
+   if (dev-rstc)
+   reset_control_reset(dev-rstc);
+
/*
 * Copy the first CODA_ISRAM_SIZE in the internal SRAM.
 * The 16-bit chars in the code buffer are in memory access
@@ -3693,6 +3733,17 @@ static int coda_probe(struct platform_device *pdev)
return -ENOENT;
}
 
+   dev-rstc = devm_reset_control_get(pdev-dev, NULL);
+   if (IS_ERR(dev-rstc)) {
+   ret = PTR_ERR(dev-rstc);
+   if (ret == -ENOENT) {
+   dev-rstc = NULL;
+   } else {
+   dev_err(pdev-dev, failed get reset control: %d\n, 
ret);
+   return ret;
+   }
+   }
+
/* Get IRAM pool from device tree or platform data */
pool = of_get_named_gen_pool(np, iram, 0);
if (!pool  pdata)
-- 
2.0.0

--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v3 13/32] [media] coda: split firmware version check out of coda_hw_init

2014-07-11 Thread Philipp Zabel
This adds a new function coda_check_firmware that does the firmware
version checks so that this can be done only once from coda_probe
instead of every time the runtime pm framework resumes the coda.

Signed-off-by: Philipp Zabel p.za...@pengutronix.de
---
 drivers/media/platform/coda.c | 42 +-
 1 file changed, 37 insertions(+), 5 deletions(-)

diff --git a/drivers/media/platform/coda.c b/drivers/media/platform/coda.c
index e4d31b9..d47ab63 100644
--- a/drivers/media/platform/coda.c
+++ b/drivers/media/platform/coda.c
@@ -3197,7 +3197,6 @@ static bool coda_firmware_supported(u32 vernum)
 
 static int coda_hw_init(struct coda_dev *dev)
 {
-   u16 product, major, minor, release;
u32 data;
u16 *p;
int i, ret;
@@ -3278,17 +3277,40 @@ static int coda_hw_init(struct coda_dev *dev)
coda_write(dev, data, CODA_REG_BIT_CODE_RESET);
coda_write(dev, CODA_REG_RUN_ENABLE, CODA_REG_BIT_CODE_RUN);
 
-   /* Load firmware */
+   clk_disable_unprepare(dev-clk_ahb);
+   clk_disable_unprepare(dev-clk_per);
+
+   return 0;
+
+err_clk_ahb:
+   clk_disable_unprepare(dev-clk_per);
+err_clk_per:
+   return ret;
+}
+
+static int coda_check_firmware(struct coda_dev *dev)
+{
+   u16 product, major, minor, release;
+   u32 data;
+   int ret;
+
+   ret = clk_prepare_enable(dev-clk_per);
+   if (ret)
+   goto err_clk_per;
+
+   ret = clk_prepare_enable(dev-clk_ahb);
+   if (ret)
+   goto err_clk_ahb;
+
coda_write(dev, 0, CODA_CMD_FIRMWARE_VERNUM);
coda_write(dev, CODA_REG_BIT_BUSY_FLAG, CODA_REG_BIT_BUSY);
coda_write(dev, 0, CODA_REG_BIT_RUN_INDEX);
coda_write(dev, 0, CODA_REG_BIT_RUN_COD_STD);
coda_write(dev, CODA_COMMAND_FIRMWARE_GET, CODA_REG_BIT_RUN_COMMAND);
if (coda_wait_timeout(dev)) {
-   clk_disable_unprepare(dev-clk_per);
-   clk_disable_unprepare(dev-clk_ahb);
v4l2_err(dev-v4l2_dev, firmware get command error\n);
-   return -EIO;
+   ret = -EIO;
+   goto err_run_cmd;
}
 
if (dev-devtype-product == CODA_960) {
@@ -3328,6 +3350,8 @@ static int coda_hw_init(struct coda_dev *dev)
 
return 0;
 
+err_run_cmd:
+   clk_disable_unprepare(dev-clk_ahb);
 err_clk_ahb:
clk_disable_unprepare(dev-clk_per);
 err_clk_per:
@@ -3368,6 +3392,10 @@ static void coda_fw_callback(const struct firmware *fw, 
void *context)
return;
}
 
+   ret = coda_check_firmware(dev);
+   if (ret  0)
+   return;
+
pm_runtime_put_sync(dev-plat_dev-dev);
} else {
/*
@@ -3379,6 +3407,10 @@ static void coda_fw_callback(const struct firmware *fw, 
void *context)
v4l2_err(dev-v4l2_dev, HW initialization failed\n);
return;
}
+
+   ret = coda_check_firmware(dev);
+   if (ret  0)
+   return;
}
 
dev-vfd.fops   = coda_fops,
-- 
2.0.0

--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v2 06/29] [media] coda: Add encoder/decoder support for CODA960

2014-07-11 Thread Robert Schwebel
Hi Fabio,

On Wed, Jul 02, 2014 at 09:16:42PM +0200, Robert Schwebel wrote:
  It would be really nice if the firmware was available in the
  linux-firmware repository. Do you think this would be possible?
  
  Best wishes,
  -- 
  Kamil Debski
  Samsung RD Institute Poland
 
 I tried to convince Freescale to put the firmware into linux-firmware
 for 15 months now, but recently got no reply any more.
 
 Fabio, Shawn, could you try to discuss this with the responsible folks
 inside FSL again? Maybe responsibilities have changed in the meantime
 and I might have tried to talk to the wrong people.

Any news?

rsc
-- 
Pengutronix e.K.   | |
Industrial Linux Solutions | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0|
Amtsgericht Hildesheim, HRA 2686   | Fax:   +49-5121-206917- |
--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v2 06/29] [media] coda: Add encoder/decoder support for CODA960

2014-07-11 Thread Fabio Estevam
Hi Robert,

On Fri, Jul 11, 2014 at 9:33 AM, Robert Schwebel
r.schwe...@pengutronix.de wrote:
 Hi Fabio,

 On Wed, Jul 02, 2014 at 09:16:42PM +0200, Robert Schwebel wrote:
  It would be really nice if the firmware was available in the
  linux-firmware repository. Do you think this would be possible?
 
  Best wishes,
  --
  Kamil Debski
  Samsung RD Institute Poland

 I tried to convince Freescale to put the firmware into linux-firmware
 for 15 months now, but recently got no reply any more.

 Fabio, Shawn, could you try to discuss this with the responsible folks
 inside FSL again? Maybe responsibilities have changed in the meantime
 and I might have tried to talk to the wrong people.

 Any news?

I raised this issue again internally last week. Let's hope we will
progress this time.
--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH] gspca_stv06xx: enable button found on some Quickcam Express variant

2014-07-11 Thread Antonio Ospite
Signed-off-by: Antonio Ospite a...@ao2.it
---
 drivers/media/usb/gspca/stv06xx/stv06xx.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/media/usb/gspca/stv06xx/stv06xx.c 
b/drivers/media/usb/gspca/stv06xx/stv06xx.c
index 49d209b..6ac93d8 100644
--- a/drivers/media/usb/gspca/stv06xx/stv06xx.c
+++ b/drivers/media/usb/gspca/stv06xx/stv06xx.c
@@ -505,13 +505,13 @@ static int sd_int_pkt_scan(struct gspca_dev *gspca_dev,
 {
int ret = -EINVAL;
 
-   if (len == 1  data[0] == 0x80) {
+   if (len == 1  (data[0] == 0x80 || data[0] == 0x10)) {
input_report_key(gspca_dev-input_dev, KEY_CAMERA, 1);
input_sync(gspca_dev-input_dev);
ret = 0;
}
 
-   if (len == 1  data[0] == 0x88) {
+   if (len == 1  (data[0] == 0x88 || data[0] == 0x11)) {
input_report_key(gspca_dev-input_dev, KEY_CAMERA, 0);
input_sync(gspca_dev-input_dev);
ret = 0;
-- 
2.0.1

--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 8/9] Documentation: devicetree: Document sclk-jpeg clock for exynos3250 SoC

2014-07-11 Thread Sylwester Nawrocki
On 07/07/14 18:32, Jacek Anaszewski wrote:
 JPEG IP on Exynos3250 SoC requires enabling two clock
 gates for its operation. This patch documents this
 requirement.
 
 Signed-off-by: Jacek Anaszewski j.anaszew...@samsung.com
 Signed-off-by: Kyungmin Park kyungmin.p...@samsung.com
 Cc: Rob Herring robh...@kernel.org
 Cc: Pawel Moll pawel.m...@arm.com
 Cc: Mark Rutland mark.rutl...@arm.com
 Cc: Ian Campbell ijc+devicet...@hellion.org.uk
 Cc: Kumar Gala ga...@codeaurora.org
 Cc: devicet...@vger.kernel.org
 ---
  .../bindings/media/exynos-jpeg-codec.txt   |9 ++---
  1 file changed, 6 insertions(+), 3 deletions(-)
 
 diff --git a/Documentation/devicetree/bindings/media/exynos-jpeg-codec.txt 
 b/Documentation/devicetree/bindings/media/exynos-jpeg-codec.txt
 index 937b755..20cd150 100644
 --- a/Documentation/devicetree/bindings/media/exynos-jpeg-codec.txt
 +++ b/Documentation/devicetree/bindings/media/exynos-jpeg-codec.txt
 @@ -3,9 +3,12 @@ Samsung S5P/EXYNOS SoC series JPEG codec
  Required properties:
  
  - compatible : should be one of:
 -   samsung,s5pv210-jpeg, samsung,exynos4210-jpeg;
 +   samsung,s5pv210-jpeg, samsung,exynos4210-jpeg,
 +   samsung,exynos3250-jpeg;
  - reg: address and length of the JPEG codec IP register set;
  - interrupts : specifies the JPEG codec IP interrupt;
  - clocks : should contain the JPEG codec IP gate clock specifier, from 
 the
 -   common clock bindings;
 -- clock-names: should contain jpeg entry.
 +   common clock bindings; for Exynos3250 SoC special clock gate
 +   should be defined as the second element of the clocks array

Entries in the clocks and clock-names can be in any order, the only
requirement normally is that they match. I would rephrase this to
something along the lines of:

 - clocks : should contain the JPEG codec IP gate clock specifier and
for the Exynos3250 SoC additionally the SCLK_JPEG entry; from the
common clock bindings;

 +- clock-names: should contain jpeg entry and additionally 
 sclk-jpeg entry
 +   for Exynos3250 SoC

--
Thanks,
Sylwester
--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 1/9] s5p-jpeg: Add support for Exynos3250 SoC

2014-07-11 Thread Sylwester Nawrocki
On 07/07/14 18:32, Jacek Anaszewski wrote:
 +void exynos3250_jpeg_dec_scaling_ratio(void __iomem *regs,
 + unsigned int sratio)
 +{
 + switch (sratio) {
 + case 1:
 + sratio = EXYNOS3250_DEC_SCALE_FACTOR_8_8;
 + break;
 + case 2:
 + sratio = EXYNOS3250_DEC_SCALE_FACTOR_4_8;
 + break;
 + case 4:
 + sratio = EXYNOS3250_DEC_SCALE_FACTOR_2_8;
 + break;
 + case 8:
 + sratio = EXYNOS3250_DEC_SCALE_FACTOR_1_8;
 + break;
 + }

Missing the 'default' case ?

 + writel(sratio  EXYNOS3250_DEC_SCALE_FACTOR_MASK,
 + regs + EXYNOS3250_DEC_SCALING_RATIO);
 +}

--
Regards,
Sylwester
--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 9/9] ARM: dts: exynos3250: add JPEG codec device node

2014-07-11 Thread Sylwester Nawrocki
On 07/07/14 18:32, Jacek Anaszewski wrote:
 Signed-off-by: Jacek Anaszewski j.anaszew...@samsung.com
 Signed-off-by: Kyungmin Park kyungmin.p...@samsung.com
 Cc: Rob Herring robh...@kernel.org
 Cc: Pawel Moll pawel.m...@arm.com
 Cc: Mark Rutland mark.rutl...@arm.com
 Cc: Ian Campbell ijc+devicet...@hellion.org.uk
 Cc: Kumar Gala ga...@codeaurora.org
 Cc: devicet...@vger.kernel.org
 ---
  arch/arm/boot/dts/exynos3250.dtsi |   12 
  1 file changed, 12 insertions(+)
 
 diff --git a/arch/arm/boot/dts/exynos3250.dtsi 
 b/arch/arm/boot/dts/exynos3250.dtsi
 index 3e678fa..351871a 100644
 --- a/arch/arm/boot/dts/exynos3250.dtsi
 +++ b/arch/arm/boot/dts/exynos3250.dtsi
 @@ -206,6 +206,18 @@
   interrupts = 0 240 0;
   };
  
 + jpeg-codec@1183 {
 + compatible = samsung,exynos3250-jpeg;
 + reg = 0x1183 0x1000;
 + interrupts = 0 171 0;
 + clocks = cmu CLK_JPEG, cmu CLK_SCLK_JPEG;
 + clock-names = jpeg, sclk-jpeg;
 + samsung,power-domain = pd_cam;
 + assigned-clock-parents = cmu CLK_MOUT_CAM_BLK cmu 
 CLK_DIV_MPLL_PRE,
 +  cmu CLK_SCLK_JPEG cmu;
 + assigned-clock-rates = cmu CLK_SCLK_JPEG 15000;

There is no support for the assigned-clock-parents/assigned-clock-rates
in mainline yet unfortunately. I would suggest removing these two properties
for now. And please send this patch to relevant maintainer, i.e. Kukjin Kim.

 + };

Thanks,
Sylwester
--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH/RFC v4 19/21] of: Add Skyworks Solutions, Inc. vendor prefix

2014-07-11 Thread Jacek Anaszewski
Use skyworks as the vendor prefix for the
Skyworks Solutions, Inc.

Signed-off-by: Jacek Anaszewski j.anaszew...@samsung.com
Acked-by: Kyungmin Park kyungmin.p...@samsung.com
Cc: Rob Herring robh...@kernel.org
Cc: Pawel Moll pawel.m...@arm.com
Cc: Mark Rutland mark.rutl...@arm.com
Cc: Ian Campbell ijc+devicet...@hellion.org.uk
Cc: Kumar Gala ga...@codeaurora.org
---
 .../devicetree/bindings/vendor-prefixes.txt|1 +
 1 file changed, 1 insertion(+)

diff --git a/Documentation/devicetree/bindings/vendor-prefixes.txt 
b/Documentation/devicetree/bindings/vendor-prefixes.txt
index 5d27e5a..8d0df4e 100644
--- a/Documentation/devicetree/bindings/vendor-prefixes.txt
+++ b/Documentation/devicetree/bindings/vendor-prefixes.txt
@@ -113,6 +113,7 @@ renesas Renesas Electronics Corporation
 ricoh  Ricoh Co. Ltd.
 rockchip   Fuzhou Rockchip Electronics Co., Ltd
 samsungSamsung Semiconductor
+skyworks   Skyworks Solutions, Inc.
 sbsSmart Battery System
 schindler  Schindler
 seagateSeagate Technology PLC
-- 
1.7.9.5

--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH/RFC v4 20/21] DT: Add documentation for the Skyworks AAT1290

2014-07-11 Thread Jacek Anaszewski
This patch adds device tree binding documentation for
1.5A Step-Up Current Regulator for Flash LEDs.

Signed-off-by: Jacek Anaszewski j.anaszew...@samsung.com
Acked-by: Kyungmin Park kyungmin.p...@samsung.com
Cc: Rob Herring robh...@kernel.org
Cc: Pawel Moll pawel.m...@arm.com
Cc: Mark Rutland mark.rutl...@arm.com
Cc: Ian Campbell ijc+devicet...@hellion.org.uk
Cc: Kumar Gala ga...@codeaurora.org
---
 .../devicetree/bindings/leds/leds-aat1290.txt  |   17 +
 1 file changed, 17 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/leds/leds-aat1290.txt

diff --git a/Documentation/devicetree/bindings/leds/leds-aat1290.txt 
b/Documentation/devicetree/bindings/leds/leds-aat1290.txt
new file mode 100644
index 000..9a9ad15
--- /dev/null
+++ b/Documentation/devicetree/bindings/leds/leds-aat1290.txt
@@ -0,0 +1,17 @@
+* Skyworks Solutions, Inc. AAT1290 Current Regulator for Flash LEDs
+
+Required properties:
+
+- compatible : should be skyworks,aat1290
+- gpios : two gpio pins in order FLEN, EN/SET
+- skyworks,flash-timeout : maximum flash timeout in microseconds -
+  it can be calculated using following formula:
+  T = 8.82 * 10^9 * Ct
+
+Example:
+
+flash_led: flash-led {
+   compatible = skyworks,aat1290;
+   gpios = gpj1 1 0, gpj1 2 0;
+   flash-timeout = 194;
+}
-- 
1.7.9.5

--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH/RFC v4 12/21] DT: Add documentation for LED Class Flash Manger

2014-07-11 Thread Jacek Anaszewski
This patch documents LED Class Flash Manager
related bindings.

Signed-off-by: Jacek Anaszewski j.anaszew...@samsung.com
Acked-by: Kyungmin Park kyungmin.p...@samsung.com
Cc: Bryan Wu coolo...@gmail.com
Cc: Richard Purdie rpur...@rpsys.net
Cc: Rob Herring robh...@kernel.org
Cc: Pawel Moll pawel.m...@arm.com
Cc: Mark Rutland mark.rutl...@arm.com
Cc: Ian Campbell ijc+devicet...@hellion.org.uk
Cc: Kumar Gala ga...@codeaurora.org
---
 .../bindings/leds/leds-flash-manager.txt   |  165 
 1 file changed, 165 insertions(+)
 create mode 100644 
Documentation/devicetree/bindings/leds/leds-flash-manager.txt

diff --git a/Documentation/devicetree/bindings/leds/leds-flash-manager.txt 
b/Documentation/devicetree/bindings/leds/leds-flash-manager.txt
new file mode 100644
index 000..c98ee2e
--- /dev/null
+++ b/Documentation/devicetree/bindings/leds/leds-flash-manager.txt
@@ -0,0 +1,165 @@
+* LED Flash Manager
+
+Flash manager is a part of LED Flash Class. It maintains
+all the flash led devices which have their external strobe
+signals routed through multiplexing devices.
+The multiplexers are aggregated in the standalone 'flash_muxes'
+node as subnodes which are referenced by the flash led devices.
+
+
+flash_muxes node
+
+
+muxN subnode
+
+
+There must be at least one muxN subnode, where N is the identifier
+of the node, present in the flash_muxes node. One muxN node
+represents one multiplexer.
+
+Required properties (mutually exclusive):
+- gpios: specifies the gpio pins used to set the states
+ of mux selectors, LSB first
+- mux-async: phandle to the node of the multiplexing device
+
+
+
+flash led device node
+-
+
+Following subnodes must be added to the LED Flash Class device
+tree node described in Documentation/devicetree/bindings/leds/common.txt.
+
+
+gate-software-strobe subnode
+
+
+The node defines configuration of multiplexers that needs
+to be applied to route software strobe signal to the flash
+led device.
+
+Required properties:
+- mux  : phandle to the muxN node defined
+ in the flash_muxes node
+- mux-line-id  : mux line identifier
+
+Optional subnodes:
+- gate-software-strobe : if there are many multiplexers to configure,
+they can be recursively nested.
+
+
+gate-external-strobeN subnode
+-
+
+The node defines configuration of multiplexers that needs
+to be applied to route external strobe signal to the flash
+led device. A flash led device can have many external strobe
+signal sources.
+
+Required properties:
+- mux  : phandle to the muxN node defined
+ in the flash_muxes node
+- mux-line-id  : mux line identifier
+Optional properties:
+- strobe-provider  : phandle to the device providing the
+ strobe signal. It is expected only
+ on the first level node. The referenced
+ node is expected to have 'compatible'
+ property, as providers are labelled
+ with it in the LED subsystem
+
+Optional subnodes:
+- gate-external-strobeN: if there are many multiplexers to configure,
+ they can be recursively nested.
+
+
+Example:
+
+Following board configuration is assumed in this example:
+
+-- --
+| FLASH1 | | FLASH2 |
+-- --
+   \(0)   /(1)
+  --
+  |  MUX1  |
+  --
+  |
+  --
+  |  MUX2  |
+  --
+   /(0)   \(1)
+  --  
+  |  MUX3  |  | SOC FLASHEN GPIO |
+  --  
+   /(0)   \(1)
+--- ---
+| SENSOR1 | | SENSOR2 |
+--- ---
+
+
+dummy_mux: led_mux {
+   compatible = led-async-mux;
+};
+
+flash_muxes {
+   flash_mux1: mux1 {
+gpios = gpj1 1 0, gpj1 2 0;
+   };
+
+   flash_mux2: mux2 {
+   mux-async = dummy_mux;
+   };
+
+   flash_mux3: mux3 {
+gpios = gpl1 1 0, gpl1 2 0;
+   };
+};
+
+max77693-flash {
+   compatible = maxim,max77693-flash;
+
+   //other device specific properties here
+
+   gate-software-strobe {
+   mux = flash_mux1;
+   mux-line-id = 0;
+
+   gate-software-strobe {
+   mux = flash_mux2;
+   mux-line-id = 1;
+   };
+   };
+
+   gate-external-strobe1 {
+   strobe-provider = s5c73m3_spi;
+   mux = flash_mux1;
+   mux-line-id = 0;
+
+   gate-external-strobe1 {
+   mux = flash_mux2;
+   mux-line-id = 0;
+
+   gate-external-strobe1 {
+   

[PATCH/RFC v4 11/21] DT: leds: Add flash led devices related properties

2014-07-11 Thread Jacek Anaszewski
Addition of a LED Flash Class extension entails the need for flash led
specific device tree properties. The properties being added are:
iout-torch, iout-flash, iout-indicator and flash-timeout.

Signed-off-by: Jacek Anaszewski j.anaszew...@samsung.com
Acked-by: Kyungmin Park kyungmin.p...@samsung.com
Cc: Stephen Warren swar...@nvidia.com
Cc: Grant Likely grant.lik...@secretlab.ca
Cc: Rob Herring robh...@kernel.org
Cc: Pawel Moll pawel.m...@arm.com
Cc: Mark Rutland mark.rutl...@arm.com
Cc: Ian Campbell ijc+devicet...@hellion.org.uk
Cc: Kumar Gala ga...@codeaurora.org
---
 Documentation/devicetree/bindings/leds/common.txt |   16 
 1 file changed, 16 insertions(+)

diff --git a/Documentation/devicetree/bindings/leds/common.txt 
b/Documentation/devicetree/bindings/leds/common.txt
index 2d88816..40f4b9a 100644
--- a/Documentation/devicetree/bindings/leds/common.txt
+++ b/Documentation/devicetree/bindings/leds/common.txt
@@ -3,6 +3,17 @@ Common leds properties.
 Optional properties for child nodes:
 - label : The label for this LED.  If omitted, the label is
   taken from the node name (excluding the unit address).
+- iout-torch : Array of maximum intensities in microamperes of the torch
+   led currents in order from sub-led 0 to N-1, where N is the number
+   of torch sub-leds exposed by the device
+- iout-flash : Array of maximum intensities in microamperes of the flash
+   led currents in order from sub-led 0 to N-1, where N is the number
+   of flash sub-leds exposed by the device
+- iout-indicator : Array of maximum intensities in microamperes of
+   the indicator led currents in order from sub-led 0 to N-1,
+   where N is the number of indicator sub-leds exposed by the device
+- flash-timeout : timeout in microseconds after which flash led
+   is turned off
 
 - linux,default-trigger :  This parameter, if present, is a
 string defining the trigger assigned to the LED.  Current triggers are:
@@ -19,5 +30,10 @@ Examples:
 system-status {
label = Status;
linux,default-trigger = heartbeat;
+   iout-torch = 500 500;
+   iout-flash = 1000 1000;
+   iout-indicator = 100 100;
+   flash-timeout = 1000;
+
...
 };
-- 
1.7.9.5

--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH/RFC v4 15/21] media: Add registration helpers for V4L2 flash

2014-07-11 Thread Jacek Anaszewski
This patch adds helper functions for registering/unregistering
LED class flash devices as V4L2 subdevs. The functions should
be called from the LED subsystem device driver. In case the
support for V4L2 Flash sub-devices is disabled in the kernel
config the functions' empty versions will be used.

Signed-off-by: Jacek Anaszewski j.anaszew...@samsung.com
Acked-by: Kyungmin Park kyungmin.p...@samsung.com
Cc: Sakari Ailus sakari.ai...@iki.fi
Cc: Hans Verkuil hans.verk...@cisco.com
---
 drivers/media/v4l2-core/Kconfig  |   11 +
 drivers/media/v4l2-core/Makefile |2 +
 drivers/media/v4l2-core/v4l2-flash.c |  580 ++
 include/media/v4l2-flash.h   |  137 
 4 files changed, 730 insertions(+)
 create mode 100644 drivers/media/v4l2-core/v4l2-flash.c
 create mode 100644 include/media/v4l2-flash.h

diff --git a/drivers/media/v4l2-core/Kconfig b/drivers/media/v4l2-core/Kconfig
index 9ca0f8d..3ae3f0f 100644
--- a/drivers/media/v4l2-core/Kconfig
+++ b/drivers/media/v4l2-core/Kconfig
@@ -35,6 +35,17 @@ config V4L2_MEM2MEM_DEV
 tristate
 depends on VIDEOBUF2_CORE
 
+# Used by LED subsystem flash drivers
+config V4L2_FLASH_LED_CLASS
+   bool Enable support for Flash sub-devices
+   depends on VIDEO_V4L2_SUBDEV_API
+   depends on LEDS_CLASS_FLASH
+   ---help---
+ Say Y here to enable support for Flash sub-devices, which allow
+ to control LED class devices with use of V4L2 Flash controls.
+
+ When in doubt, say N.
+
 # Used by drivers that need Videobuf modules
 config VIDEOBUF_GEN
tristate
diff --git a/drivers/media/v4l2-core/Makefile b/drivers/media/v4l2-core/Makefile
index 63d29f2..44e858c 100644
--- a/drivers/media/v4l2-core/Makefile
+++ b/drivers/media/v4l2-core/Makefile
@@ -22,6 +22,8 @@ obj-$(CONFIG_VIDEO_TUNER) += tuner.o
 
 obj-$(CONFIG_V4L2_MEM2MEM_DEV) += v4l2-mem2mem.o
 
+obj-$(CONFIG_V4L2_FLASH_LED_CLASS) += v4l2-flash.o
+
 obj-$(CONFIG_VIDEOBUF_GEN) += videobuf-core.o
 obj-$(CONFIG_VIDEOBUF_DMA_SG) += videobuf-dma-sg.o
 obj-$(CONFIG_VIDEOBUF_DMA_CONTIG) += videobuf-dma-contig.o
diff --git a/drivers/media/v4l2-core/v4l2-flash.c 
b/drivers/media/v4l2-core/v4l2-flash.c
new file mode 100644
index 000..21080c6
--- /dev/null
+++ b/drivers/media/v4l2-core/v4l2-flash.c
@@ -0,0 +1,580 @@
+/*
+ * V4L2 Flash LED sub-device registration helpers.
+ *
+ * Copyright (C) 2014 Samsung Electronics Co., Ltd
+ * Author: Jacek Anaszewski j.anaszew...@samsung.com
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#include linux/led-class-flash.h
+#include linux/mutex.h
+#include linux/of_led_flash_manager.h
+#include linux/slab.h
+#include media/v4l2-flash.h
+
+#define call_flash_op(v4l2_flash, op, args...) \
+   (v4l2_flash-ops-op  ? \
+   v4l2_flash-ops-op(args) : \
+   -EINVAL)
+
+static struct v4l2_device *v4l2_dev;
+static int registered_flashes;
+
+static inline enum led_brightness v4l2_flash_intensity_to_led_brightness(
+   struct v4l2_ctrl_config *config,
+   s32 intensity)
+{
+   return ((intensity - config-min) / config-step) + 1;
+}
+
+static inline s32 v4l2_flash_led_brightness_to_intensity(
+   struct v4l2_ctrl_config *config,
+   enum led_brightness brightness)
+{
+   return ((brightness - 1) * config-step) + config-min;
+}
+
+static int v4l2_flash_g_volatile_ctrl(struct v4l2_ctrl *c)
+
+{
+   struct v4l2_flash *v4l2_flash = v4l2_ctrl_to_v4l2_flash(c);
+   struct led_classdev_flash *flash = v4l2_flash-flash;
+   struct led_classdev *led_cdev = flash-led_cdev;
+   struct v4l2_flash_ctrl_config *config = v4l2_flash-config;
+   struct v4l2_flash_ctrl *ctrl = v4l2_flash-ctrl;
+   bool is_strobing;
+   int ret;
+
+   switch (c-id) {
+   case V4L2_CID_FLASH_TORCH_INTENSITY:
+   /*
+* Update torch brightness only if in TORCH_MODE,
+* as otherwise brightness_update op returns 0,
+* which would spuriously inform user space that
+* V4L2_CID_FLASH_TORCH_INTENSITY control value
+* has changed.
+*/
+   if (ctrl-led_mode-val == V4L2_FLASH_LED_MODE_TORCH) {
+   ret = call_flash_op(v4l2_flash, torch_brightness_update,
+   led_cdev);
+   if (ret  0)
+   return ret;
+   ctrl-torch_intensity-val =
+   v4l2_flash_led_brightness_to_intensity(
+   

[PATCH/RFC v4 10/21] Documentation: leds: add exemplary asynchronous mux driver

2014-07-11 Thread Jacek Anaszewski
Exemplary driver showing usage of the Flash Manager API
for registering/unregistering asynchronous multiplexers

Signed-off-by: Jacek Anaszewski j.anaszew...@samsung.com
Acked-by: Kyungmin Park kyungmin.p...@samsung.com
Cc: Bryan Wu coolo...@gmail.com
Cc: Richard Purdie rpur...@rpsys.net
---
 Documentation/leds/leds-async-mux.c |   65 +++
 1 file changed, 65 insertions(+)
 create mode 100644 Documentation/leds/leds-async-mux.c

diff --git a/Documentation/leds/leds-async-mux.c 
b/Documentation/leds/leds-async-mux.c
new file mode 100644
index 000..ee35d2f
--- /dev/null
+++ b/Documentation/leds/leds-async-mux.c
@@ -0,0 +1,65 @@
+/*
+ * Exemplary driver showing usage of the Flash Manager API
+ * for registering/unregistering asynchronous multiplexers.
+ *
+ * Copyright (C) 2014, Samsung Electronics Co., Ltd.
+ * Author: Jacek Anaszewski j.anaszew...@samsung.com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * version 2 as published by the Free Software Foundation.
+ */
+
+#include linux/platform_device.h
+#include linux/module.h
+#include linux/led-class-flash.h
+#include linux/led-flash-manager.h
+#include linux/leds.h
+#include linux/of.h
+
+static int led_async_mux_select_line(u32 line_id, void *mux)
+{
+   pr_info(led_async_mux_select_line line_id: %d\n, line_id);
+   return 0;
+}
+
+struct led_flash_mux_ops mux_ops = {
+   .select_line = led_async_mux_select_line,
+};
+
+static int led_async_mux_probe(struct platform_device *pdev)
+{
+   struct led_flash_mux mux;
+
+   mux.ops = mux_ops;
+   mux.owner = THIS_MODULE;
+   mux.node = pdev-dev-of_node;
+
+   return led_flash_manager_bind_async_mux(mux);
+}
+
+static int led_async_mux_remove(struct platform_device *pdev)
+{
+   return led_flash_manager_unbind_async_mux(pdev-dev-of_node);
+}
+
+static struct of_device_id led_async_mux_dt_match[] = {
+   {.compatible = led-async-mux},
+   {},
+};
+
+static struct platform_driver led_async_mux_driver = {
+   .probe  = led_async_mux_probe,
+   .remove = led_async_mux_remove,
+   .driver = {
+   .name   = led-async-mux,
+   .owner  = THIS_MODULE,
+   .of_match_table = led_async_mux_dt_match,
+   },
+};
+
+module_platform_driver(led_async_mux_driver);
+
+MODULE_AUTHOR(Jacek Anaszewski j.anaszew...@samsung.com);
+MODULE_DESCRIPTION(LED async mux);
+MODULE_LICENSE(GPL);
-- 
1.7.9.5

--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH/RFC v4 14/21] v4l2-ctrls: add control for flash strobe signal providers

2014-07-11 Thread Jacek Anaszewski
Add V4L2_CID_STROBE_PROVIDER of type menu, which allows
for enumerating of available external flash strobe signal
providers and setting the active one.

Signed-off-by: Jacek Anaszewski j.anaszew...@samsung.com
Acked-by: Kyungmin Park kyungmin.p...@samsung.com
Cc: Sakari Ailus sakari.ai...@iki.fi
Cc: Hans Verkuil hans.verk...@cisco.com
---
 Documentation/DocBook/media/v4l/controls.xml |   11 +++
 drivers/media/v4l2-core/v4l2-ctrls.c |2 ++
 include/uapi/linux/v4l2-controls.h   |2 ++
 3 files changed, 15 insertions(+)

diff --git a/Documentation/DocBook/media/v4l/controls.xml 
b/Documentation/DocBook/media/v4l/controls.xml
index 47198ee..d9f6c3f 100644
--- a/Documentation/DocBook/media/v4l/controls.xml
+++ b/Documentation/DocBook/media/v4l/controls.xml
@@ -4300,6 +4300,17 @@ interface and may change in the future./para
is strobing at the moment or not. This is a read-only
control./entry
  /row
+  row
+entry 
spanname=idconstantV4L2_CID_FLASH_STROBE_PROVIDER/constant/entry
+entrymenu/entry
+  /row
+  row
+entry spanname=descrProvider of the external strobe signal. If 
a flash
+device declares more than one available external strobe signal 
provider then
+this control allows to select the active one. VIDIOC-QUERYCTRL; 
has to be
+used to get the list of available strobe providers.
+/entry
+  /row
  row
entry 
spanname=idconstantV4L2_CID_FLASH_TIMEOUT/constant/entry
entryinteger/entry
diff --git a/drivers/media/v4l2-core/v4l2-ctrls.c 
b/drivers/media/v4l2-core/v4l2-ctrls.c
index 55c6832..f298f7e 100644
--- a/drivers/media/v4l2-core/v4l2-ctrls.c
+++ b/drivers/media/v4l2-core/v4l2-ctrls.c
@@ -825,6 +825,7 @@ const char *v4l2_ctrl_get_name(u32 id)
case V4L2_CID_FLASH_FAULT:  return Faults;
case V4L2_CID_FLASH_CHARGE: return Charge;
case V4L2_CID_FLASH_READY:  return Ready to Strobe;
+   case V4L2_CID_FLASH_STROBE_PROVIDER:return Strobe Provider;
 
/* JPEG encoder controls */
/* Keep the order of the 'case's the same as in videodev2.h! */
@@ -988,6 +989,7 @@ void v4l2_ctrl_fill(u32 id, const char **name, enum 
v4l2_ctrl_type *type,
case V4L2_CID_TEST_PATTERN:
case V4L2_CID_TUNE_DEEMPHASIS:
case V4L2_CID_MPEG_VIDEO_VPX_GOLDEN_FRAME_SEL:
+   case V4L2_CID_FLASH_STROBE_PROVIDER:
*type = V4L2_CTRL_TYPE_MENU;
break;
case V4L2_CID_LINK_FREQ:
diff --git a/include/uapi/linux/v4l2-controls.h 
b/include/uapi/linux/v4l2-controls.h
index 2ac5597..1f05c7c 100644
--- a/include/uapi/linux/v4l2-controls.h
+++ b/include/uapi/linux/v4l2-controls.h
@@ -822,6 +822,8 @@ enum v4l2_flash_strobe_source {
 #define V4L2_CID_FLASH_CHARGE  (V4L2_CID_FLASH_CLASS_BASE + 11)
 #define V4L2_CID_FLASH_READY   (V4L2_CID_FLASH_CLASS_BASE + 12)
 
+#define V4L2_CID_FLASH_STROBE_PROVIDER (V4L2_CID_FLASH_CLASS_BASE + 13)
+
 
 /* JPEG-class control IDs */
 
-- 
1.7.9.5

--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH/RFC v4 09/21] Documentation: leds: Add description of LED Flash Class extension

2014-07-11 Thread Jacek Anaszewski
The documentation being added contains overall description of the
LED Flash Class and the related sysfs attributes. There are also
chapters devoted specifically to the Flash Manager feature.

Signed-off-by: Jacek Anaszewski j.anaszew...@samsung.com
Acked-by: Kyungmin Park kyungmin.p...@samsung.com
Cc: Bryan Wu coolo...@gmail.com
Cc: Richard Purdie rpur...@rpsys.net
---
 Documentation/leds/leds-class-flash.txt |  126 +++
 1 file changed, 126 insertions(+)
 create mode 100644 Documentation/leds/leds-class-flash.txt

diff --git a/Documentation/leds/leds-class-flash.txt 
b/Documentation/leds/leds-class-flash.txt
new file mode 100644
index 000..0927804
--- /dev/null
+++ b/Documentation/leds/leds-class-flash.txt
@@ -0,0 +1,126 @@
+
+Flash LED handling under Linux
+==
+
+Some LED devices support two modes - torch and flash. In order to enable
+support for flash LEDs the CONFIG_LEDS_CLASS_FLASH symbol must be defined
+in the kernel config. A flash LED driver must register in the LED subsystem
+with led_classdev_flash_register to gain flash capabilities.
+
+Following sysfs attributes are exposed for controlling flash led devices:
+
+   - flash_brightness - flash LED brightness in microamperes (RW)
+   - max_flash_brightness - maximum available flash LED brightness (RO)
+   - indicator_brightness - privacy LED brightness in microamperes (RW)
+   - max_indicator_brightness - maximum privacy LED brightness in
+microamperes (RO)
+   - flash_timeout - flash strobe duration in microseconds (RW)
+   - max_flash_timeout - maximum available flash strobe duration (RO)
+   - flash_strobe - flash strobe state (RW)
+   - external_strobe - some devices expose dedicated hardware pins for
+   triggering a flash LED - this attribute allows to
+   set this mode (RW)
+   - flash_fault - bitmask of flash faults that may have occurred,
+   possible flags are:
+   * 0x01 - flash controller voltage to the flash LED has exceeded
+the limit specific to the flash controller
+   * 0x02 - the flash strobe was still on when the timeout set by
+the user has expired; not all flash controllers may
+set this in all such conditions
+   * 0x04 - the flash controller has overheated
+   * 0x08 - the short circuit protection of the flash controller
+has been triggered
+   * 0x10 - current in the LED power supply has exceeded the limit
+specific to the flash controller
+   * 0x40 - flash controller voltage to the flash LED has been
+below the minimum limit specific to the flash
+   * 0x80 - the input voltage of the flash controller is below
+the limit under which strobing the flash at full
+current will not be possible. The condition persists
+until this flag is no longer set
+   * 0x100 - the temperature of the LED has exceeded its allowed
+ upper limit
+
+The LED subsystem driver can be controlled also from the level of 
VideoForLinux2
+subsystem. In order to enable this the CONFIG_V4L2_FLASH_LED_CLASS symbol has 
to
+be defined in the kernel config. The driver must call v4l2_flash_init function
+to get registered in the V4L2 subsystem. On remove v4l2_flash_release function
+has to be called (see media/v4l2-flash.h).
+
+After proper initialization V4L2 Flash sub-device is created. The sub-device
+exposes a number of V4L2 controls. When the V4L2_CID_FLASH_LED_MODE control
+is set to V4L2_FLASH_LED_MODE_TORCH or V4L2_FLASH_LED_MODE_FLASH the
+LED subsystem sysfs interface becomes unavailable. The interface can be 
unlocked
+by setting the mode back to V4L2_FLASH_LED_MODE_NONE.
+
+
+Flash Manager
+=
+
+Flash LED devices often provide two ways of strobing the flash: software
+(e.g. by setting a bit in a register) and hardware, by asserting dedicated pin,
+which is usually connected to a camera sensor device. There are also flash led
+devices which support only hardware strobing - in such cases a multiplexer
+device is employed to route the flash strobe signal either from the SoC GPIO or
+from the external strobe signal provider, e.g. camera sensor.
+Use of multiplexers allows also to change the flash-sensor connection
+dynamically if there is more than one flash or external strobe signal provider
+available on the board.
+
+In order to address the aforementioned cases the Flash Manager functionality
+has been introduced. Flash Manager is a part of LED Flash Class. It maintains
+information about flashes, software and external strobe signal providers and
+multiplexers that route strobe signals among them.
+
+To 

[PATCH/RFC v4 05/21] leds: avoid using deprecated DEVICE_ATTR macro

2014-07-11 Thread Jacek Anaszewski
Make the sysfs attributes definition consistent in the whole file.
The modification entails change of the function name:
led_max_brightness_show - max_brightness_show

Signed-off-by: Jacek Anaszewski j.anaszew...@samsung.com
Acked-by: Kyungmin Park kyungmin.p...@samsung.com
Cc: Bryan Wu coolo...@gmail.com
Cc: Richard Purdie rpur...@rpsys.net
---
 drivers/leds/led-class.c |4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/leds/led-class.c b/drivers/leds/led-class.c
index 0127783..a96a1a7 100644
--- a/drivers/leds/led-class.c
+++ b/drivers/leds/led-class.c
@@ -60,14 +60,14 @@ unlock:
 }
 static DEVICE_ATTR_RW(brightness);
 
-static ssize_t led_max_brightness_show(struct device *dev,
+static ssize_t max_brightness_show(struct device *dev,
struct device_attribute *attr, char *buf)
 {
struct led_classdev *led_cdev = dev_get_drvdata(dev);
 
return sprintf(buf, %u\n, led_cdev-max_brightness);
 }
-static DEVICE_ATTR(max_brightness, 0444, led_max_brightness_show, NULL);
+static DEVICE_ATTR_RO(max_brightness);
 
 #ifdef CONFIG_LEDS_TRIGGERS
 static DEVICE_ATTR(trigger, 0644, led_trigger_show, led_trigger_store);
-- 
1.7.9.5

--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH/RFC v4 00/21] LED / flash API integration

2014-07-11 Thread Jacek Anaszewski
This is is the fourth version of the patch series being a follow up
of the discussion on Media summit 2013-10-23, related to the
LED / flash API integration (the notes from the discussion were
enclosed in the message [1], paragraph 5).
The series is based on linux-next-20140707

Description of the proposed modifications according to
the kernel components they are relevant to:
- LED subsystem modifications
* added led_flash module which, when enabled in the config,
  registers flash specific sysfs attributes, if the driver
  declares related features:
- flash_brightness
- max_flash_brightness
- indicator_brightness
- max_indicator_brightness
- flash_timeout
- max_flash_timeout
- flash_strobe
- external_strobe
- flash_fault
  and exposes kernel internal API:
- led_classdev_flash_register
- led_classdev_flash_unregister
- led_set_flash_strobe
- led_get_flash_strobe
- led_set_flash_brightness
- led_update_flash_brightness
- led_set_indicator_brightness
- led_update_indicator_brightness
- led_set_flash_timeout
- led_get_flash_fault
- led_set_external_strobe
- led_sysfs_lock
- led_sysfs_unlock
* added Flash Manager functionality, available when
  led_flash module is enable in the config;
  if the device tree node of a flash led device contains
  relevant subnodes, it registers following sysfs attributes:
- strobe_provider
- strobe_providerN
- blocking_strobe
  following kernel internal API is exposed by the flash manager:
- led_flash_manager_register_flash
- led_flash_manager_unregister_flash 
- led_flash_manager_setup_strobe
- led_flash_manager_bind_async_mux
- led_flash_manager_unbind_async_mux
- Addition of a V4L2 Flash sub-device registration helpers
* added v4l2-flash.c and v4l2-flash.h files with helper
  functions that facilitate registration/unregistration
  of a subdevice, which wrapps a LED subsystem device and
  exposes V4L2 Flash control interface
- Addition of a LED Flash Class driver for the flash cell of
  the MAX77693 mfd
- Addition of a LED Flash Class driver for the AAT1290 current
  regulator for flash leds along with its DT binding for the
  exynos4412-trats2 board, where standalone multiplexer is
  used for modifying strobe signal routing - either from the SoC
  GPIO or from a camera sensor. This arrangment is handled
  by the newly introduced Flash Manager functionality.
- Update of the max77693.txt DT bindings documentation
- Update of the common leds DT bindings documentation


Changes since v2


- refactored the code so that it is possible to build
  led-core without led-flash module
- added v4l2-flash ops which slackens dependency from
  the led-flash module
- implemented led_clamp_align_val function and led_ctrl
  structure which allows to align led control values
  in the manner compatible with V4L2 Flash controls;
  the flash brightness and timeout units have been defined
  as microamperes and microseconds respectively to properly
  support devices which define current and time levels
  as fractions of 1/1000.
- added support for the flash privacy leds
- modified LED sysfs locking mechanism - now it locks/unlocks
  the interface on V4L2 Flash sub-device file open/close
- changed hw_triggered attribute name to external_strobe,
  which maps on the V4L2_FLASH_STROBE_SOURCE_EXTERNAL name 
  more intuitively
- made external_strobe and indicator related sysfs attributes
  created optionally only if related features are declared
  by the led device driver
- removed from the series patches modifying exynos4-is media
  controller - a proposal for flash manager which will take
  care of flash devices registration is due to be submitted
- removed modifications to the LED class devices documentation,
  it will be covered after the whole functionality is accepted


Changes since v3


- added Flash Manager feature
  - added generic LED Flash Class gpio mux driver
  - added sample async mux driver
  - added of helpers for parsing Flash Manager related
device tree data
- added V4L2_CID_FLASH_STROBE_PROVIDER control
- introduced struct led_classdev_flash, which wrapps
  struct led_classdev
- made all flash ops, except strobe_set, optional; if an op
  is absent the related sysfs attribute isn't created
- added LED_DEV_CAP* flags
- modified v4l2-flash helpers to create v4l2_device
  

[PATCH/RFC v4 04/21] leds: Reorder include directives

2014-07-11 Thread Jacek Anaszewski
Reorder include directives so that they are arranged
in alphabetical order.

Signed-off-by: Jacek Anaszewski j.anaszew...@samsung.com
Acked-by: Kyungmin Park kyungmin.p...@samsung.com
Cc: Bryan Wu coolo...@gmail.com
Cc: Richard Purdie rpur...@rpsys.net
---
 drivers/leds/led-class.c |   13 +++--
 drivers/leds/led-core.c  |3 ++-
 include/linux/leds.h |2 +-
 3 files changed, 10 insertions(+), 8 deletions(-)

diff --git a/drivers/leds/led-class.c b/drivers/leds/led-class.c
index da79bbb..0127783 100644
--- a/drivers/leds/led-class.c
+++ b/drivers/leds/led-class.c
@@ -9,16 +9,17 @@
  * published by the Free Software Foundation.
  */
 
-#include linux/module.h
-#include linux/kernel.h
+#include linux/ctype.h
+#include linux/device.h
+#include linux/err.h
 #include linux/init.h
+#include linux/kernel.h
+#include linux/leds.h
 #include linux/list.h
+#include linux/module.h
+#include linux/slab.h
 #include linux/spinlock.h
-#include linux/device.h
 #include linux/timer.h
-#include linux/err.h
-#include linux/ctype.h
-#include linux/leds.h
 #include leds.h
 
 static struct class *leds_class;
diff --git a/drivers/leds/led-core.c b/drivers/leds/led-core.c
index 0ac06ed..d156fb6 100644
--- a/drivers/leds/led-core.c
+++ b/drivers/leds/led-core.c
@@ -12,10 +12,11 @@
  */
 
 #include linux/kernel.h
+#include linux/leds.h
 #include linux/list.h
 #include linux/module.h
+#include linux/mutex.h
 #include linux/rwsem.h
-#include linux/leds.h
 #include leds.h
 
 DECLARE_RWSEM(leds_list_lock);
diff --git a/include/linux/leds.h b/include/linux/leds.h
index e9b025d..1a130cc 100644
--- a/include/linux/leds.h
+++ b/include/linux/leds.h
@@ -14,8 +14,8 @@
 
 #include linux/list.h
 #include linux/mutex.h
-#include linux/spinlock.h
 #include linux/rwsem.h
+#include linux/spinlock.h
 #include linux/timer.h
 #include linux/workqueue.h
 
-- 
1.7.9.5

--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH/RFC v4 01/21] leds: make brightness type consistent across whole subsystem

2014-07-11 Thread Jacek Anaszewski
Documentations states that brightness units type is enum led_brightness
and this is the type used by the led API functions. Adjust the type
of brightness variables in the struct led_classdev accordingly.

Signed-off-by: Jacek Anaszewski j.anaszew...@samsung.com
Acked-by: Kyungmin Park kyungmin.p...@samsung.com
Cc: Bryan Wu coolo...@gmail.com
Cc: Richard Purdie rpur...@rpsys.net
---
 include/linux/leds.h |4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/include/linux/leds.h b/include/linux/leds.h
index e436864..995f933 100644
--- a/include/linux/leds.h
+++ b/include/linux/leds.h
@@ -31,8 +31,8 @@ enum led_brightness {
 
 struct led_classdev {
const char  *name;
-   int  brightness;
-   int  max_brightness;
+   enum led_brightness  brightness;
+   enum led_brightness  max_brightness;
int  flags;
 
/* Lower 16 bits reflect status */
-- 
1.7.9.5

--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH/RFC v4 06/21] leds: add API for setting torch brightness

2014-07-11 Thread Jacek Anaszewski
This patch prepares ground for addition of LED Flash Class extension to
the LED subsystem. Since turning the torch on must have guaranteed
immediate effect the brightness_set op can't be used for it. Drivers must
schedule a work queue task in this op to be compatible with led-triggers,
which call brightess_set from timer irqs. In order to address this
limitiation a torch_brightness_set op and led_set_torch_brightness API
is introduced. Setting brightness sysfs attribute will result in calling
brightness_set op for LED Class decices and torch_brightness_set op for
LED Flash Class devices, whereas triggers will still call brightness
op in both cases.

Signed-off-by: Jacek Anaszewski j.anaszew...@samsung.com
Acked-by: Kyungmin Park kyungmin.p...@samsung.com
Cc: Bryan Wu coolo...@gmail.com
Cc: Richard Purdie rpur...@rpsys.net
---
 drivers/leds/led-class.c |   18 --
 drivers/leds/led-core.c  |   15 +++
 include/linux/leds.h |   22 ++
 3 files changed, 53 insertions(+), 2 deletions(-)

diff --git a/drivers/leds/led-class.c b/drivers/leds/led-class.c
index a96a1a7..c17dda0 100644
--- a/drivers/leds/led-class.c
+++ b/drivers/leds/led-class.c
@@ -44,15 +44,29 @@ static ssize_t brightness_store(struct device *dev,
 
mutex_lock(led_cdev-led_lock);
 
+   /*
+* Having LED_DEV_CAP_TORCH implies this is LED Flash Class
+* device and we need to check sysfs accessibility.
+*/
+   if (led_cdev-flags  LED_DEV_CAP_TORCH) {
+   if (led_sysfs_is_locked(led_cdev)) {
+   ret = -EBUSY;
+   goto unlock;
+   }
+   }
+
ret = kstrtoul(buf, 10, state);
if (ret)
goto unlock;
 
if (state == LED_OFF)
led_trigger_remove(led_cdev);
-   __led_set_brightness(led_cdev, state);
 
-   return size;
+   if (led_cdev-flags  LED_DEV_CAP_TORCH)
+   ret = led_set_torch_brightness(led_cdev, state);
+   else
+   __led_set_brightness(led_cdev, state);
+
ret = size;
 unlock:
mutex_unlock(led_cdev-led_lock);
diff --git a/drivers/leds/led-core.c b/drivers/leds/led-core.c
index d156fb6..0ce087a 100644
--- a/drivers/leds/led-core.c
+++ b/drivers/leds/led-core.c
@@ -143,6 +143,21 @@ int led_update_brightness(struct led_classdev *led_cdev)
return ret;
 }
 EXPORT_SYMBOL(led_update_brightness);
+
+int led_set_torch_brightness(struct led_classdev *led_cdev,
+   enum led_brightness brightness)
+{
+   int ret = 0;
+
+   led_cdev-brightness = min(brightness, led_cdev-max_brightness);
+
+   if (!(led_cdev-flags  LED_SUSPENDED))
+   ret = led_cdev-torch_brightness_set(led_cdev,
+led_cdev-brightness);
+   return ret;
+}
+EXPORT_SYMBOL_GPL(led_set_torch_brightness);
+
 /* Caller must ensure led_cdev-led_lock held */
 void led_sysfs_lock(struct led_classdev *led_cdev)
 {
diff --git a/include/linux/leds.h b/include/linux/leds.h
index 1a130cc..9bea9e6 100644
--- a/include/linux/leds.h
+++ b/include/linux/leds.h
@@ -44,11 +44,21 @@ struct led_classdev {
 #define LED_BLINK_ONESHOT_STOP (1  18)
 #define LED_BLINK_INVERT   (1  19)
 #define LED_SYSFS_LOCK (1  20)
+#define LED_DEV_CAP_TORCH  (1  21)
 
/* Set LED brightness level */
/* Must not sleep, use a workqueue if needed */
void(*brightness_set)(struct led_classdev *led_cdev,
  enum led_brightness brightness);
+   /*
+* Set LED brightness immediately - it is required for flash led
+* devices as they require setting torch brightness to have immediate
+* effect. brightness_set op cannot be used for this purpose because
+* the led drivers schedule a work queue task in it to allow for
+* being called from led-triggers, i.e. from the timer irq context.
+*/
+   int (*torch_brightness_set)(struct led_classdev *led_cdev,
+   enum led_brightness brightness);
/* Get LED brightness level */
enum led_brightness (*brightness_get)(struct led_classdev *led_cdev);
 
@@ -156,6 +166,18 @@ extern void led_set_brightness(struct led_classdev 
*led_cdev,
  */
 extern int led_update_brightness(struct led_classdev *led_cdev);
 
+/**
+ * led_set_torch_brightness - set torch LED brightness
+ * @led_cdev: the LED to set
+ * @brightness: the brightness to set it to
+ *
+ * Returns: 0 on success or negative error value on failure
+ *
+ * Set a torch LED's brightness.
+ */
+extern int led_set_torch_brightness(struct led_classdev *led_cdev,
+   enum led_brightness brightness);
+/**
  * led_sysfs_lock - lock LED sysfs interface
  * @led_cdev: the LED to set
  *
-- 
1.7.9.5

--
To unsubscribe from this list: send the line 

[PATCH/RFC v4 02/21] leds: implement sysfs interface locking mechanism

2014-07-11 Thread Jacek Anaszewski
Add mechanism for locking LED subsystem sysfs interface.
This patch prepares ground for addition of LED Flash Class extension.

Signed-off-by: Jacek Anaszewski j.anaszew...@samsung.com
Acked-by: Kyungmin Park kyungmin.p...@samsung.com
Cc: Bryan Wu coolo...@gmail.com
Cc: Richard Purdie rpur...@rpsys.net
---
 drivers/leds/led-class.c|   13 +++--
 drivers/leds/led-core.c |   18 ++
 drivers/leds/led-triggers.c |   11 ---
 include/linux/leds.h|   31 +++
 4 files changed, 68 insertions(+), 5 deletions(-)

diff --git a/drivers/leds/led-class.c b/drivers/leds/led-class.c
index aa29198..ea04891 100644
--- a/drivers/leds/led-class.c
+++ b/drivers/leds/led-class.c
@@ -45,17 +45,23 @@ static ssize_t brightness_store(struct device *dev,
 {
struct led_classdev *led_cdev = dev_get_drvdata(dev);
unsigned long state;
-   ssize_t ret = -EINVAL;
+   ssize_t ret;
+
+   mutex_lock(led_cdev-led_lock);
 
ret = kstrtoul(buf, 10, state);
if (ret)
-   return ret;
+   goto unlock;
 
if (state == LED_OFF)
led_trigger_remove(led_cdev);
__led_set_brightness(led_cdev, state);
 
return size;
+   ret = size;
+unlock:
+   mutex_unlock(led_cdev-led_lock);
+   return ret;
 }
 static DEVICE_ATTR_RW(brightness);
 
@@ -219,6 +225,7 @@ int led_classdev_register(struct device *parent, struct 
led_classdev *led_cdev)
 #ifdef CONFIG_LEDS_TRIGGERS
init_rwsem(led_cdev-trigger_lock);
 #endif
+   mutex_init(led_cdev-led_lock);
/* add to the list of leds */
down_write(leds_list_lock);
list_add_tail(led_cdev-node, leds_list);
@@ -272,6 +279,8 @@ void led_classdev_unregister(struct led_classdev *led_cdev)
down_write(leds_list_lock);
list_del(led_cdev-node);
up_write(leds_list_lock);
+
+   mutex_destroy(led_cdev-led_lock);
 }
 EXPORT_SYMBOL_GPL(led_classdev_unregister);
 
diff --git a/drivers/leds/led-core.c b/drivers/leds/led-core.c
index 71b40d3..4d7cb31 100644
--- a/drivers/leds/led-core.c
+++ b/drivers/leds/led-core.c
@@ -126,3 +126,21 @@ void led_set_brightness(struct led_classdev *led_cdev,
__led_set_brightness(led_cdev, brightness);
 }
 EXPORT_SYMBOL(led_set_brightness);
+
+/* Caller must ensure led_cdev-led_lock held */
+void led_sysfs_lock(struct led_classdev *led_cdev)
+{
+   WARN_ON(!mutex_is_locked(led_cdev-led_lock));
+
+   led_cdev-flags |= LED_SYSFS_LOCK;
+}
+EXPORT_SYMBOL_GPL(led_sysfs_lock);
+
+/* Caller must ensure led_cdev-led_lock held */
+void led_sysfs_unlock(struct led_classdev *led_cdev)
+{
+   WARN_ON(!mutex_is_locked(led_cdev-led_lock));
+
+   led_cdev-flags = ~LED_SYSFS_LOCK;
+}
+EXPORT_SYMBOL_GPL(led_sysfs_unlock);
diff --git a/drivers/leds/led-triggers.c b/drivers/leds/led-triggers.c
index c3734f1..0545530 100644
--- a/drivers/leds/led-triggers.c
+++ b/drivers/leds/led-triggers.c
@@ -37,6 +37,9 @@ ssize_t led_trigger_store(struct device *dev, struct 
device_attribute *attr,
char trigger_name[TRIG_NAME_MAX];
struct led_trigger *trig;
size_t len;
+   int ret = count;
+
+   mutex_lock(led_cdev-led_lock);
 
trigger_name[sizeof(trigger_name) - 1] = '\0';
strncpy(trigger_name, buf, sizeof(trigger_name) - 1);
@@ -47,7 +50,7 @@ ssize_t led_trigger_store(struct device *dev, struct 
device_attribute *attr,
 
if (!strcmp(trigger_name, none)) {
led_trigger_remove(led_cdev);
-   return count;
+   goto exit_unlock;
}
 
down_read(triggers_list_lock);
@@ -58,12 +61,14 @@ ssize_t led_trigger_store(struct device *dev, struct 
device_attribute *attr,
up_write(led_cdev-trigger_lock);
 
up_read(triggers_list_lock);
-   return count;
+   goto exit_unlock;
}
}
up_read(triggers_list_lock);
 
-   return -EINVAL;
+exit_unlock:
+   mutex_unlock(led_cdev-led_lock);
+   return ret;
 }
 EXPORT_SYMBOL_GPL(led_trigger_store);
 
diff --git a/include/linux/leds.h b/include/linux/leds.h
index 995f933..da7c6b5 100644
--- a/include/linux/leds.h
+++ b/include/linux/leds.h
@@ -13,6 +13,7 @@
 #define __LINUX_LEDS_H_INCLUDED
 
 #include linux/list.h
+#include linux/mutex.h
 #include linux/spinlock.h
 #include linux/rwsem.h
 #include linux/timer.h
@@ -42,6 +43,7 @@ struct led_classdev {
 #define LED_BLINK_ONESHOT  (1  17)
 #define LED_BLINK_ONESHOT_STOP (1  18)
 #define LED_BLINK_INVERT   (1  19)
+#define LED_SYSFS_LOCK (1  20)
 
/* Set LED brightness level */
/* Must not sleep, use a workqueue if needed */
@@ -85,6 +87,9 @@ struct led_classdev {
/* true if activated - deactivate routine uses it to do cleanup */
boolactivated;
 #endif
+
+   /* Ensures consistent access to the LED 

[PATCH/RFC v4 03/21] leds: Improve and export led_update_brightness

2014-07-11 Thread Jacek Anaszewski
led_update_brightness helper function used to be exploited only locally
in the led-class.c module, where its result was being passed to the
brightness_show sysfs callback. With the introduction of v4l2-flash
subdevice the same functionality became required for reading current
brightness from a LED device. This patch adds checking of return value
of the brightness_get callback and moves the led_update_brightness()
function to the LED subsystem public API.

Signed-off-by: Jacek Anaszewski j.anaszew...@samsung.com
Acked-by: Kyungmin Park kyungmin.p...@samsung.com
Cc: Bryan Wu coolo...@gmail.com
Cc: Richard Purdie rpur...@rpsys.net
---
 drivers/leds/led-class.c |6 --
 drivers/leds/led-core.c  |   15 +++
 include/linux/leds.h |   10 ++
 3 files changed, 25 insertions(+), 6 deletions(-)

diff --git a/drivers/leds/led-class.c b/drivers/leds/led-class.c
index ea04891..da79bbb 100644
--- a/drivers/leds/led-class.c
+++ b/drivers/leds/led-class.c
@@ -23,12 +23,6 @@
 
 static struct class *leds_class;
 
-static void led_update_brightness(struct led_classdev *led_cdev)
-{
-   if (led_cdev-brightness_get)
-   led_cdev-brightness = led_cdev-brightness_get(led_cdev);
-}
-
 static ssize_t brightness_show(struct device *dev,
struct device_attribute *attr, char *buf)
 {
diff --git a/drivers/leds/led-core.c b/drivers/leds/led-core.c
index 4d7cb31..0ac06ed 100644
--- a/drivers/leds/led-core.c
+++ b/drivers/leds/led-core.c
@@ -127,6 +127,21 @@ void led_set_brightness(struct led_classdev *led_cdev,
 }
 EXPORT_SYMBOL(led_set_brightness);
 
+int led_update_brightness(struct led_classdev *led_cdev)
+{
+   int ret = 0;
+
+   if (led_cdev-brightness_get) {
+   ret = led_cdev-brightness_get(led_cdev);
+   if (ret = 0) {
+   led_cdev-brightness = ret;
+   return 0;
+   }
+   }
+
+   return ret;
+}
+EXPORT_SYMBOL(led_update_brightness);
 /* Caller must ensure led_cdev-led_lock held */
 void led_sysfs_lock(struct led_classdev *led_cdev)
 {
diff --git a/include/linux/leds.h b/include/linux/leds.h
index da7c6b5..e9b025d 100644
--- a/include/linux/leds.h
+++ b/include/linux/leds.h
@@ -146,6 +146,16 @@ extern void led_blink_set_oneshot(struct led_classdev 
*led_cdev,
 extern void led_set_brightness(struct led_classdev *led_cdev,
   enum led_brightness brightness);
 /**
+ * led_update_brightness - update LED brightness
+ * @led_cdev: the LED to query
+ *
+ * Get an LED's current brightness and update led_cdev-brightness
+ * member with the obtained value.
+ *
+ * Returns: 0 on success or negative error value on failure
+ */
+extern int led_update_brightness(struct led_classdev *led_cdev);
+
  * led_sysfs_lock - lock LED sysfs interface
  * @led_cdev: the LED to set
  *
-- 
1.7.9.5

--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH/RFC v4 16/21] leds: Add support for max77693 mfd flash cell

2014-07-11 Thread Jacek Anaszewski
This patch adds led-flash support to Maxim max77693 chipset.
A device can be exposed to user space through LED subsystem
sysfs interface or through V4L2 subdevice when the support
for V4L2 Flash sub-devices is enabled. Device supports up to
two leds which can work in flash and torch mode. Leds can
be triggered externally or by software.

Signed-off-by: Jacek Anaszewski j.anaszew...@samsung.com
Signed-off-by: Andrzej Hajda a.ha...@samsung.com
Acked-by: Lee Jones lee.jo...@linaro.org
Acked-by: Kyungmin Park kyungmin.p...@samsung.com
Cc: Bryan Wu coolo...@gmail.com
Cc: Richard Purdie rpur...@rpsys.net
Cc: SangYoung Son hello@smasung.com
Cc: Samuel Ortiz sa...@linux.intel.com
---
 drivers/leds/Kconfig |9 +
 drivers/leds/Makefile|1 +
 drivers/leds/leds-max77693.c | 1070 ++
 drivers/mfd/max77693.c   |5 +-
 include/linux/mfd/max77693.h |   40 ++
 5 files changed, 1124 insertions(+), 1 deletion(-)
 create mode 100644 drivers/leds/leds-max77693.c

diff --git a/drivers/leds/Kconfig b/drivers/leds/Kconfig
index 5032c6f..794055e 100644
--- a/drivers/leds/Kconfig
+++ b/drivers/leds/Kconfig
@@ -457,6 +457,15 @@ config LEDS_TCA6507
  LED driver chips accessed via the I2C bus.
  Driver support brightness control and hardware-assisted blinking.
 
+config LEDS_MAX77693
+   tristate LED support for MAX77693 Flash
+   depends on LEDS_CLASS_FLASH
+   depends on MFD_MAX77693
+   help
+ This option enables support for the flash part of the MAX77693
+ multifunction device. It has build in control for two leds in flash
+ and torch mode.
+
 config LEDS_MAX8997
tristate LED support for MAX8997 PMIC
depends on LEDS_CLASS  MFD_MAX8997
diff --git a/drivers/leds/Makefile b/drivers/leds/Makefile
index 237c5ba..da1a4ba 100644
--- a/drivers/leds/Makefile
+++ b/drivers/leds/Makefile
@@ -55,6 +55,7 @@ obj-$(CONFIG_LEDS_MC13783)+= leds-mc13783.o
 obj-$(CONFIG_LEDS_NS2) += leds-ns2.o
 obj-$(CONFIG_LEDS_NETXBIG) += leds-netxbig.o
 obj-$(CONFIG_LEDS_ASIC3)   += leds-asic3.o
+obj-$(CONFIG_LEDS_MAX77693)+= leds-max77693.o
 obj-$(CONFIG_LEDS_MAX8997) += leds-max8997.o
 obj-$(CONFIG_LEDS_LM355x)  += leds-lm355x.o
 obj-$(CONFIG_LEDS_BLINKM)  += leds-blinkm.o
diff --git a/drivers/leds/leds-max77693.c b/drivers/leds/leds-max77693.c
new file mode 100644
index 000..38a2398
--- /dev/null
+++ b/drivers/leds/leds-max77693.c
@@ -0,0 +1,1070 @@
+/*
+ * LED Flash Class driver for the flash cell of max77693 mfd.
+ *
+ * Copyright (C) 2014, Samsung Electronics Co., Ltd.
+ *
+ * Authors: Jacek Anaszewski j.anaszew...@samsung.com
+ *  Andrzej Hajda a.ha...@samsung.com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * version 2 as published by the Free Software Foundation.
+ */
+
+#include asm/div64.h
+#include linux/led-class-flash.h
+#include linux/led-flash-manager.h
+#include linux/mfd/max77693.h
+#include linux/mfd/max77693-private.h
+#include linux/module.h
+#include linux/mutex.h
+#include linux/platform_device.h
+#include linux/regmap.h
+#include linux/slab.h
+#include linux/workqueue.h
+#include media/v4l2-flash.h
+
+#define MAX77693_LED_NAME_1max77693-flash_1
+#define MAX77693_LED_NAME_2max77693-flash_2
+
+#define MAX77693_TORCH_IOUT_BITS   4
+
+#define MAX77693_TORCH_NO_TIMER0x40
+#define MAX77693_FLASH_TIMER_LEVEL 0x80
+
+#define MAX77693_FLASH_EN_OFF  0
+#define MAX77693_FLASH_EN_FLASH1
+#define MAX77693_FLASH_EN_TORCH2
+#define MAX77693_FLASH_EN_ON   3
+
+#define MAX77693_FLASH_EN1_SHIFT   6
+#define MAX77693_FLASH_EN2_SHIFT   4
+#define MAX77693_TORCH_EN1_SHIFT   2
+#define MAX77693_TORCH_EN2_SHIFT   0
+
+#define MAX77693_FLASH_LOW_BATTERY_EN  0x80
+
+#define MAX77693_FLASH_BOOST_FIXED 0x04
+#define MAX77693_FLASH_BOOST_LEDNUM_2  0x80
+
+#define MAX77693_FLASH_TIMEOUT_MIN 62500
+#define MAX77693_FLASH_TIMEOUT_MAX 100
+#define MAX77693_FLASH_TIMEOUT_STEP62500
+
+#define MAX77693_TORCH_TIMEOUT_MIN 262000
+#define MAX77693_TORCH_TIMEOUT_MAX 15728000
+
+#define MAX77693_FLASH_IOUT_MIN15625
+#define MAX77693_FLASH_IOUT_MAX_1LED   100
+#define MAX77693_FLASH_IOUT_MAX_2LEDS  625000
+#define MAX77693_FLASH_IOUT_STEP   15625
+
+#define MAX77693_TORCH_IOUT_MIN15625
+#define MAX77693_TORCH_IOUT_MAX25
+#define MAX77693_TORCH_IOUT_STEP   15625
+
+#define MAX77693_FLASH_VSYS_MIN2400
+#define MAX77693_FLASH_VSYS_MAX3400
+#define MAX77693_FLASH_VSYS_STEP   33
+
+#define MAX77693_FLASH_VOUT_MIN3300
+#define MAX77693_FLASH_VOUT_MAX5500
+#define 

[PATCH/RFC v4 18/21] leds: Add driver for AAT1290 current regulator

2014-07-11 Thread Jacek Anaszewski
This patch adds a driver for the 1.5A Step-Up
Current Regulator for Flash LEDs. The device is
programmed through a Skyworks' proprietary AS2Cwire
serial digital interface.

Signed-off-by: Jacek Anaszewski j.anaszew...@samsung.com
Acked-by: Kyungmin Park kyungmin.p...@samsung.com
Cc: Bryan Wu coolo...@gmail.com
Cc: Richard Purdie rpur...@rpsys.net
---
 drivers/leds/Kconfig|6 +
 drivers/leds/Makefile   |1 +
 drivers/leds/leds-aat1290.c |  455 +++
 3 files changed, 462 insertions(+)
 create mode 100644 drivers/leds/leds-aat1290.c

diff --git a/drivers/leds/Kconfig b/drivers/leds/Kconfig
index 794055e..ef774fd 100644
--- a/drivers/leds/Kconfig
+++ b/drivers/leds/Kconfig
@@ -42,6 +42,12 @@ config LEDS_88PM860X
  This option enables support for on-chip LED drivers found on Marvell
  Semiconductor 88PM8606 PMIC.
 
+config LEDS_AAT1290
+   tristate LED support for the AAT1290
+   depends on LEDS_CLASS_FLASH
+   help
+This option enables support for the LEDs on the AAT1290.
+
 config LEDS_ATMEL_PWM
tristate LED Support using Atmel PWM outputs
depends on LEDS_CLASS
diff --git a/drivers/leds/Makefile b/drivers/leds/Makefile
index da1a4ba..41911aa 100644
--- a/drivers/leds/Makefile
+++ b/drivers/leds/Makefile
@@ -11,6 +11,7 @@ obj-$(CONFIG_LEDS_TRIGGERS)   += led-triggers.o
 
 # LED Platform Drivers
 obj-$(CONFIG_LEDS_88PM860X)+= leds-88pm860x.o
+obj-$(CONFIG_LEDS_AAT1290) += leds-aat1290.o
 obj-$(CONFIG_LEDS_ATMEL_PWM)   += leds-atmel-pwm.o
 obj-$(CONFIG_LEDS_BD2802)  += leds-bd2802.o
 obj-$(CONFIG_LEDS_LOCOMO)  += leds-locomo.o
diff --git a/drivers/leds/leds-aat1290.c b/drivers/leds/leds-aat1290.c
new file mode 100644
index 000..07d7384
--- /dev/null
+++ b/drivers/leds/leds-aat1290.c
@@ -0,0 +1,455 @@
+/*
+ * LED Flash Class driver for the AAT1290
+ * 1.5A Step-Up Current Regulator for Flash LEDs
+ *
+ * Copyright (C) 2014, Samsung Electronics Co., Ltd.
+ * Author: Jacek Anaszewski j.anaszew...@samsung.com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * version 2 as published by the Free Software Foundation.
+ */
+
+#include linux/delay.h
+#include linux/slab.h
+#include linux/platform_device.h
+#include linux/module.h
+#include linux/i2c.h
+#include linux/led-class-flash.h
+#include linux/led-flash-manager.h
+#include linux/leds.h
+#include linux/mutex.h
+#include linux/gpio.h
+#include linux/of_gpio.h
+#include linux/of.h
+#include media/v4l2-flash.h
+#include linux/workqueue.h
+
+#define AAT1290_LED_NAME   aat1290
+#define AAT1290_MOVIE_MODE_CURRENT_ADDR17
+#define AAT1290_FLASH_SAFETY_TIMER_ADDR18
+#define AAT1290_MOVIE_MODE_CONFIG_ADDR 19
+#define AAT1290_MM_CURRENT_RATIO_ADDR  20
+#define AAT1290_LATCH_TIME_US  500
+#define AAT1290_EN_SET_TICK_TIME_US1
+#define AAT1290_MOVIE_MODE_OFF 1
+#define AAT1290_MOVIE_MODE_ON  3
+#define AAT1290_MAX_MM_CURR_PERCENT_0  16
+#define AAT1290_MAX_MM_CURR_PERCENT_100 1
+#define AAT1290_FLASH_TM_RATIO_STEP16
+
+#define AAT1290_MM_TO_FL_1_92  1
+#define AAT1290_MM_TO_FL_3_7   2
+#define AAT1290_MM_TO_FL_5_5   3
+#define AAT1290_MM_TO_FL_7_3   4
+#define AAT1290_MM_TO_FL_9 5
+#define AAT1290_MM_TO_FL_10_7  6
+#define AAT1290_MM_TO_FL_12_4  7
+#define AAT1290_MM_TO_FL_148
+#define AAT1290_MM_TO_FL_15_9  9
+#define AAT1290_MM_TO_FL_17_5  10
+#define AAT1290_MM_TO_FL_19_1  11
+#define AAT1290_MM_TO_FL_20_8  12
+#define AAT1290_MM_TO_FL_22_4  13
+#define AAT1290_MM_TO_FL_2414
+#define AAT1290_MM_TO_FL_25_6  15
+#define AAT1290_MM_TO_FL_OFF   16
+
+static const unsigned int flash_level_to_reg[] = {
+   16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1
+};
+
+enum aat1290_led_mode {
+   MODE_OFF,
+   MODE_TORCH,
+   MODE_FLASH,
+   MODE_FLASH_EXTERNAL,
+};
+
+struct aat1290_led_settings {
+   struct led_flash_setting torch_brightness;
+   struct led_flash_setting flash_brightness;
+   struct led_flash_setting flash_timeout;
+};
+
+struct aat1290_led {
+   struct platform_device *pdev;
+   struct mutex lock;
+
+   struct led_classdev_flash ldev;
+   struct v4l2_flash *v4l2_flash;
+
+   int flen_gpio;
+   int en_set_gpio;
+
+   u32 max_flash_tm;
+   bool movie_mode;
+
+   unsigned int torch_brightness;
+   unsigned int flash_timeout;
+   struct work_struct work_brightness_set;
+};
+
+static struct aat1290_led *ldev_to_led(struct led_classdev_flash *ldev)
+{
+   return container_of(ldev, struct aat1290_led, ldev);
+}
+
+static void aat1290_as2cwire_write(struct aat1290_led *led, int addr, int 
value)
+{
+   int i;
+
+   gpio_set_value(led-flen_gpio, 0);
+   gpio_set_value(led-en_set_gpio, 0);
+
+   udelay(10);
+
+   /* write address 

[PATCH/RFC v4 17/21] DT: Add documentation for the mfd Maxim max77693

2014-07-11 Thread Jacek Anaszewski
This patch adds device tree binding documentation for
the flash cell of the Maxim max77693 multifunctional device.

Signed-off-by: Andrzej Hajda a.ha...@samsung.com
Acked-by: Kyungmin Park kyungmin.p...@samsung.com
Cc: Rob Herring robh...@kernel.org
Cc: Pawel Moll pawel.m...@arm.com
Cc: Mark Rutland mark.rutl...@arm.com
Cc: Ian Campbell ijc+devicet...@hellion.org.uk
Cc: Kumar Gala ga...@codeaurora.org
---
 Documentation/devicetree/bindings/mfd/max77693.txt |   62 
 1 file changed, 62 insertions(+)

diff --git a/Documentation/devicetree/bindings/mfd/max77693.txt 
b/Documentation/devicetree/bindings/mfd/max77693.txt
index 11921cc..0c3db3d 100644
--- a/Documentation/devicetree/bindings/mfd/max77693.txt
+++ b/Documentation/devicetree/bindings/mfd/max77693.txt
@@ -27,6 +27,55 @@ Optional properties:
 
[*] refer Documentation/devicetree/bindings/regulator/regulator.txt
 
+Optional node:
+- led-flash : the LED submodule device node
+
+Required properties of led-flash node:
+- compatible : must be maxim,max77693-flash
+- maxim,num-leds : number of connected leds
+   Possible values: 1 or 2.
+- maxim,fleds : array of current outputs in order: fled1, fled2
+   Note: both current outputs can be connected to a single led
+   Possible values:
+   0 - the output is left disconnected,
+   1 - a diode is connected to the output.
+
+Optional properties of led-flash node:
+- maxim,boost-mode :
+   In boost mode the device can produce up to 1.2A of total current
+   on both outputs. The maximum current on each output is reduced
+   to 625mA then. If maxim,num-leds == 2 boost must be enabled
+   (it defaults to 1 if not set):
+   Possible values:
+   0 - no boost,
+   1 - adaptive mode,
+   2 - fixed mode.
+- iout-torch : Array of maximum intensities in microamperes of the torch
+   led currents in order: fled1, fled2.
+   15625 - 25
+- iout-flash : Array of maximum intensities in microamperes of the flash
+   led currents in order: fled1, fled2.
+   Range:
+   15625 - 100 (max 625000 if boost mode is enabled)
+- flash-timeout : timeout in microseconds after which flash led
+ is turned off
+   Range:
+   62500 - 100
+- maxim,trigger : Array of flags indicating which trigger can activate given 
led
+   in order: fled1, fled2
+   Possible flag values (can be combined):
+   1 - FLASH pin of the chip,
+   2 - TORCH pin of the chip,
+   4 - software via I2C command.
+- maxim,trigger-type : Array of trigger types in order: flash, torch.
+   Possible trigger types:
+   0 - Rising edge of the signal triggers the flash/torch,
+   1 - Signal level controls duration of the flash/torch.
+- maxim,boost-vout : Output voltage of the boost module in millivolts.
+- maxim,vsys-min : Low input voltage level in millivolts. Flash is not fired
+   if chip estimates that system voltage could drop below this level due
+   to flash power consumption.
+
 Example:
max77693@66 {
compatible = maxim,max77693;
@@ -52,4 +101,17 @@ Example:
regulator-boot-on;
};
};
+   led_flash: led-flash {
+   compatible = maxim,max77693-flash;
+   iout-torch = 50 0;
+   iout-flash = 125 0;
+   flash-timeout = 100 100;
+   maxim,num-leds = 1;
+   maxim,fleds = 1 1;
+   maxim,trigger = 7 7;
+   maxim,trigger-type = 0 1;
+   maxim,boost-mode = 1;
+   maxim,boost-vout = 5000;
+   maxim,vsys-min = 2400;
+   };
};
-- 
1.7.9.5

--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH/RFC v4 21/21] ARM: dts: add aat1290 current regulator device node

2014-07-11 Thread Jacek Anaszewski
Add device node for AAT1290 1.5A Step-Up Current Regulator
for Flash LEDs along with flash_muxes node containing
information about a multiplexer that is used for switching
between software and external strobe signal source.

Signed-off-by: Jacek Anaszewski j.anaszew...@samsung.com
Signed-off-by: Kyungmin Park kyungmin.p...@samsung.com
Cc: Kukjin Kim kgene@samsung.com
---
 arch/arm/boot/dts/exynos4412-trats2.dts |   24 
 1 file changed, 24 insertions(+)

diff --git a/arch/arm/boot/dts/exynos4412-trats2.dts 
b/arch/arm/boot/dts/exynos4412-trats2.dts
index 7787844..cbb76ba 100644
--- a/arch/arm/boot/dts/exynos4412-trats2.dts
+++ b/arch/arm/boot/dts/exynos4412-trats2.dts
@@ -785,4 +785,28 @@
pulldown-ohm = 10; /* 100K */
io-channels = adc 2;  /* Battery temperature */
};
+
+   flash_muxes {
+   flash_mux1: mux1 {
+   gpios = gpj1 0 0;
+   };
+   };
+
+   aat1290 {
+   compatible = skyworks,aat1290;
+   gpios = gpj1 1 0, gpj1 2 0;
+   flash-timeout = 194;
+   status = okay;
+
+   gate-software-strobe {
+   mux = flash_mux1;
+   mux-line-id = 0;
+   };
+
+   gate-external-strobe {
+   strobe-provider = s5c73m3_spi;
+   mux = flash_mux1;
+   mux-line-id = 1;
+   };
+   };
 };
-- 
1.7.9.5

--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH/RFC v4 13/21] v4l2-device: add v4l2_device_register_subdev_node API

2014-07-11 Thread Jacek Anaszewski
Extract the code executed for each entry of the subdev list
and put it to the separate function. Export it as a public API.
It allows for registering single sub-device at a time.

Signed-off-by: Jacek Anaszewski j.anaszew...@samsung.com
Acked-by: Kyungmin Park kyungmin.p...@samsung.com
Cc: Hans Verkuil hans.verk...@cisco.com
Cc: Laurent Pinchart laurent.pinch...@ideasonboard.com
---
 drivers/media/v4l2-core/v4l2-device.c |   63 +++--
 include/media/v4l2-device.h   |7 
 2 files changed, 44 insertions(+), 26 deletions(-)

diff --git a/drivers/media/v4l2-core/v4l2-device.c 
b/drivers/media/v4l2-core/v4l2-device.c
index 015f92a..0e91ef7 100644
--- a/drivers/media/v4l2-core/v4l2-device.c
+++ b/drivers/media/v4l2-core/v4l2-device.c
@@ -216,9 +216,43 @@ static void v4l2_device_release_subdev_node(struct 
video_device *vdev)
kfree(vdev);
 }
 
-int v4l2_device_register_subdev_nodes(struct v4l2_device *v4l2_dev)
+int v4l2_device_register_subdev_node(struct v4l2_subdev *sd,
+struct v4l2_device *v4l2_dev)
 {
struct video_device *vdev;
+   int err;
+
+   if (!(sd-flags  V4L2_SUBDEV_FL_HAS_DEVNODE))
+   return 0;
+
+   vdev = kzalloc(sizeof(*vdev), GFP_KERNEL);
+   if (!vdev)
+   return -ENOMEM;
+
+   video_set_drvdata(vdev, sd);
+   strlcpy(vdev-name, sd-name, sizeof(vdev-name));
+   vdev-v4l2_dev = v4l2_dev;
+   vdev-fops = v4l2_subdev_fops;
+   vdev-release = v4l2_device_release_subdev_node;
+   vdev-ctrl_handler = sd-ctrl_handler;
+   err = __video_register_device(vdev, VFL_TYPE_SUBDEV, -1, 1,
+ sd-owner);
+   if (err  0) {
+   kfree(vdev);
+   return err;
+   }
+#if defined(CONFIG_MEDIA_CONTROLLER)
+   sd-entity.info.v4l.major = VIDEO_MAJOR;
+   sd-entity.info.v4l.minor = vdev-minor;
+#endif
+   sd-devnode = vdev;
+
+   return 0;
+}
+EXPORT_SYMBOL_GPL(v4l2_device_register_subdev_node);
+
+int v4l2_device_register_subdev_nodes(struct v4l2_device *v4l2_dev)
+{
struct v4l2_subdev *sd;
int err;
 
@@ -226,32 +260,9 @@ int v4l2_device_register_subdev_nodes(struct v4l2_device 
*v4l2_dev)
 * V4L2_SUBDEV_FL_HAS_DEVNODE flag.
 */
list_for_each_entry(sd, v4l2_dev-subdevs, list) {
-   if (!(sd-flags  V4L2_SUBDEV_FL_HAS_DEVNODE))
-   continue;
-
-   vdev = kzalloc(sizeof(*vdev), GFP_KERNEL);
-   if (!vdev) {
-   err = -ENOMEM;
-   goto clean_up;
-   }
-
-   video_set_drvdata(vdev, sd);
-   strlcpy(vdev-name, sd-name, sizeof(vdev-name));
-   vdev-v4l2_dev = v4l2_dev;
-   vdev-fops = v4l2_subdev_fops;
-   vdev-release = v4l2_device_release_subdev_node;
-   vdev-ctrl_handler = sd-ctrl_handler;
-   err = __video_register_device(vdev, VFL_TYPE_SUBDEV, -1, 1,
- sd-owner);
-   if (err  0) {
-   kfree(vdev);
+   err = v4l2_device_register_subdev_node(sd, v4l2_dev);
+   if (err  0)
goto clean_up;
-   }
-#if defined(CONFIG_MEDIA_CONTROLLER)
-   sd-entity.info.v4l.major = VIDEO_MAJOR;
-   sd-entity.info.v4l.minor = vdev-minor;
-#endif
-   sd-devnode = vdev;
}
return 0;
 
diff --git a/include/media/v4l2-device.h b/include/media/v4l2-device.h
index ffb69da..76594fc 100644
--- a/include/media/v4l2-device.h
+++ b/include/media/v4l2-device.h
@@ -114,6 +114,13 @@ int __must_check v4l2_device_register_subdev(struct 
v4l2_device *v4l2_dev,
wasn't registered. In that case it will do nothing. */
 void v4l2_device_unregister_subdev(struct v4l2_subdev *sd);
 
+/* Register device node for the subdev of the v4l2 device if it is marked with
+ * the V4L2_SUBDEV_FL_HAS_DEVNODE flag.
+ */
+int __must_check
+v4l2_device_register_subdev_node(struct v4l2_subdev *sd,
+   struct v4l2_device *v4l2_dev);
+
 /* Register device nodes for all subdev of the v4l2 device that are marked with
  * the V4L2_SUBDEV_FL_HAS_DEVNODE flag.
  */
-- 
1.7.9.5

--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH/RFC v4 07/21] of: add of_node_ncmp wrapper

2014-07-11 Thread Jacek Anaszewski
The wrapper for strnicmp is required for checking whether a node has
expected prefix.

Signed-off-by: Jacek Anaszewski j.anaszew...@samsung.com
Acked-by: Kyungmin Park kyungmin.p...@samsung.com
Cc: Grant Likely grant.lik...@linaro.org
Cc: Benjamin Herrenschmidt b...@kernel.crashing.org
Cc: Michal Simek mon...@monstr.eu
---
 include/linux/of.h |1 +
 1 file changed, 1 insertion(+)

diff --git a/include/linux/of.h b/include/linux/of.h
index 692b56c..9a53eea 100644
--- a/include/linux/of.h
+++ b/include/linux/of.h
@@ -199,6 +199,7 @@ static inline unsigned long of_read_ulong(const __be32 
*cell, int size)
 #define of_compat_cmp(s1, s2, l)   strcasecmp((s1), (s2))
 #define of_prop_cmp(s1, s2)strcmp((s1), (s2))
 #define of_node_cmp(s1, s2)strcasecmp((s1), (s2))
+#define of_node_ncmp(s1, s2, n)strnicmp((s1), (s2), (n))
 #endif
 
 /* flag descriptions */
-- 
1.7.9.5

--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v2 2/9] s5p-jpeg: return error immediately after get_byte fails

2014-07-11 Thread Jacek Anaszewski
When parsing JPEG header s5p_jpeg_parse_hdr function
should return immediately in case there was an error
while reading a byte.

Signed-off-by: Jacek Anaszewski j.anaszew...@samsung.com
Signed-off-by: Kyungmin Park kyungmin.p...@samsung.com
---
 drivers/media/platform/s5p-jpeg/jpeg-core.c |4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/media/platform/s5p-jpeg/jpeg-core.c 
b/drivers/media/platform/s5p-jpeg/jpeg-core.c
index 7d604f2..df3aaa9 100644
--- a/drivers/media/platform/s5p-jpeg/jpeg-core.c
+++ b/drivers/media/platform/s5p-jpeg/jpeg-core.c
@@ -906,14 +906,14 @@ static bool s5p_jpeg_parse_hdr(struct s5p_jpeg_q_data 
*result,
while (notfound) {
c = get_byte(jpeg_buffer);
if (c == -1)
-   break;
+   return false;
if (c != 0xff)
continue;
do
c = get_byte(jpeg_buffer);
while (c == 0xff);
if (c == -1)
-   break;
+   return false;
if (c == 0)
continue;
length = 0;
-- 
1.7.9.5

--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v2 1/9] s5p-jpeg: Add support for Exynos3250 SoC

2014-07-11 Thread Jacek Anaszewski
This patch adds support for jpeg codec on Exynos3250 SoC to
the s5p-jpeg driver. Supported raw formats are: YUYV, YVYU, UYVY,
VYUY, RGB565, RGB565X, RGB32, NV12, NV21. The support includes
also scaling and cropping features.

Signed-off-by: Jacek Anaszewski j.anaszew...@samsung.com
Signed-off-by: Kyungmin Park kyungmin.p...@samsung.com
---
 drivers/media/platform/Kconfig |5 +-
 drivers/media/platform/s5p-jpeg/Makefile   |2 +-
 drivers/media/platform/s5p-jpeg/jpeg-core.c|  533 +++-
 drivers/media/platform/s5p-jpeg/jpeg-core.h|   33 +-
 .../media/platform/s5p-jpeg/jpeg-hw-exynos3250.c   |  489 ++
 .../media/platform/s5p-jpeg/jpeg-hw-exynos3250.h   |   60 +++
 drivers/media/platform/s5p-jpeg/jpeg-regs.h|  247 -
 7 files changed, 1347 insertions(+), 22 deletions(-)
 create mode 100644 drivers/media/platform/s5p-jpeg/jpeg-hw-exynos3250.c
 create mode 100644 drivers/media/platform/s5p-jpeg/jpeg-hw-exynos3250.h

diff --git a/drivers/media/platform/Kconfig b/drivers/media/platform/Kconfig
index 8108c69..3077bba 100644
--- a/drivers/media/platform/Kconfig
+++ b/drivers/media/platform/Kconfig
@@ -165,12 +165,13 @@ config VIDEO_SAMSUNG_S5P_G2D
  2d graphics accelerator.
 
 config VIDEO_SAMSUNG_S5P_JPEG
-   tristate Samsung S5P/Exynos4 JPEG codec driver
+   tristate Samsung S5P/Exynos3250/Exynos4 JPEG codec driver
depends on VIDEO_DEV  VIDEO_V4L2  (PLAT_S5P || ARCH_EXYNOS)
select VIDEOBUF2_DMA_CONTIG
select V4L2_MEM2MEM_DEV
---help---
- This is a v4l2 driver for Samsung S5P and EXYNOS4 JPEG codec
+ This is a v4l2 driver for Samsung S5P, EXYNOS3250
+ and EXYNOS4 JPEG codec
 
 config VIDEO_SAMSUNG_S5P_MFC
tristate Samsung S5P MFC Video Codec
diff --git a/drivers/media/platform/s5p-jpeg/Makefile 
b/drivers/media/platform/s5p-jpeg/Makefile
index a1a9169..9e5f214 100644
--- a/drivers/media/platform/s5p-jpeg/Makefile
+++ b/drivers/media/platform/s5p-jpeg/Makefile
@@ -1,2 +1,2 @@
-s5p-jpeg-objs := jpeg-core.o jpeg-hw-exynos4.o jpeg-hw-s5p.o
+s5p-jpeg-objs := jpeg-core.o jpeg-hw-exynos3250.o jpeg-hw-exynos4.o 
jpeg-hw-s5p.o
 obj-$(CONFIG_VIDEO_SAMSUNG_S5P_JPEG) += s5p-jpeg.o
diff --git a/drivers/media/platform/s5p-jpeg/jpeg-core.c 
b/drivers/media/platform/s5p-jpeg/jpeg-core.c
index 0dcb796..7d604f2 100644
--- a/drivers/media/platform/s5p-jpeg/jpeg-core.c
+++ b/drivers/media/platform/s5p-jpeg/jpeg-core.c
@@ -1,6 +1,6 @@
 /* linux/drivers/media/platform/s5p-jpeg/jpeg-core.c
  *
- * Copyright (c) 2011-2013 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2011-2014 Samsung Electronics Co., Ltd.
  * http://www.samsung.com
  *
  * Author: Andrzej Pietrasiewicz andrze...@samsung.com
@@ -32,6 +32,7 @@
 #include jpeg-core.h
 #include jpeg-hw-s5p.h
 #include jpeg-hw-exynos4.h
+#include jpeg-hw-exynos3250.h
 #include jpeg-regs.h
 
 static struct s5p_jpeg_fmt sjpeg_formats[] = {
@@ -41,6 +42,7 @@ static struct s5p_jpeg_fmt sjpeg_formats[] = {
.flags  = SJPEG_FMT_FLAG_ENC_CAPTURE |
  SJPEG_FMT_FLAG_DEC_OUTPUT |
  SJPEG_FMT_FLAG_S5P |
+ SJPEG_FMT_FLAG_EXYNOS3250 |
  SJPEG_FMT_FLAG_EXYNOS4,
},
{
@@ -70,6 +72,19 @@ static struct s5p_jpeg_fmt sjpeg_formats[] = {
.subsampling= V4L2_JPEG_CHROMA_SUBSAMPLING_422,
},
{
+   .name   = YUV 4:2:2 packed, YCbYCr,
+   .fourcc = V4L2_PIX_FMT_YUYV,
+   .depth  = 16,
+   .colplanes  = 1,
+   .h_align= 2,
+   .v_align= 0,
+   .flags  = SJPEG_FMT_FLAG_ENC_OUTPUT |
+ SJPEG_FMT_FLAG_DEC_CAPTURE |
+ SJPEG_FMT_FLAG_EXYNOS3250 |
+ SJPEG_FMT_NON_RGB,
+   .subsampling= V4L2_JPEG_CHROMA_SUBSAMPLING_422,
+   },
+   {
.name   = YUV 4:2:2 packed, YCrYCb,
.fourcc = V4L2_PIX_FMT_YVYU,
.depth  = 16,
@@ -83,6 +98,45 @@ static struct s5p_jpeg_fmt sjpeg_formats[] = {
.subsampling= V4L2_JPEG_CHROMA_SUBSAMPLING_422,
},
{
+   .name   = YUV 4:2:2 packed, YCrYCb,
+   .fourcc = V4L2_PIX_FMT_YVYU,
+   .depth  = 16,
+   .colplanes  = 1,
+   .h_align= 2,
+   .v_align= 0,
+   .flags  = SJPEG_FMT_FLAG_ENC_OUTPUT |
+ SJPEG_FMT_FLAG_DEC_CAPTURE |
+ SJPEG_FMT_FLAG_EXYNOS3250 |
+ SJPEG_FMT_NON_RGB,
+   .subsampling= V4L2_JPEG_CHROMA_SUBSAMPLING_422,

[PATCH v2 6/9] s5p-jpeg: Prevent erroneous downscaling for Exynos3250 SoC

2014-07-11 Thread Jacek Anaszewski
JPEG codec on Exynos3250 SoC produces broken raw image if
a JPEG is decoded to YUV420 format and downscaling by
more then 2 is applied. Prevent this by asserting downscale
ratio to 2.

Signed-off-by: Jacek Anaszewski j.anaszew...@samsung.com
Signed-off-by: Kyungmin Park kyungmin.p...@samsung.com
---
 drivers/media/platform/s5p-jpeg/jpeg-core.c |   18 ++
 1 file changed, 18 insertions(+)

diff --git a/drivers/media/platform/s5p-jpeg/jpeg-core.c 
b/drivers/media/platform/s5p-jpeg/jpeg-core.c
index 2491ef8..1ef004b 100644
--- a/drivers/media/platform/s5p-jpeg/jpeg-core.c
+++ b/drivers/media/platform/s5p-jpeg/jpeg-core.c
@@ -1317,12 +1317,16 @@ static int exynos4_jpeg_get_output_buffer_size(struct 
s5p_jpeg_ctx *ctx,
return w * h * fmt_depth  3;
 }
 
+static int exynos3250_jpeg_try_downscale(struct s5p_jpeg_ctx *ctx,
+  struct v4l2_rect *r);
+
 static int s5p_jpeg_s_fmt(struct s5p_jpeg_ctx *ct, struct v4l2_format *f)
 {
struct vb2_queue *vq;
struct s5p_jpeg_q_data *q_data = NULL;
struct v4l2_pix_format *pix = f-fmt.pix;
struct v4l2_ctrl *ctrl_subs;
+   struct v4l2_rect scale_rect;
unsigned int f_type;
 
vq = v4l2_m2m_get_vq(ct-fh.m2m_ctx, f-type);
@@ -1382,6 +1386,20 @@ static int s5p_jpeg_s_fmt(struct s5p_jpeg_ctx *ct, 
struct v4l2_format *f)
ct-crop_rect.width = pix-width;
ct-crop_rect.height = pix-height;
}
+
+   /*
+* Prevent downscaling to YUV420 format by more than 2
+* for Exynos3250 SoC as it produces broken raw image
+* in such cases.
+*/
+   if (ct-mode == S5P_JPEG_DECODE 
+   f_type == FMT_TYPE_CAPTURE 
+   ct-jpeg-variant-version == SJPEG_EXYNOS3250 
+   pix-pixelformat == V4L2_PIX_FMT_YUV420 
+   ct-scale_factor  2) {
+   scale_rect.width = ct-out_q.w / 2;
+   scale_rect.height = ct-out_q.h / 2;
+   exynos3250_jpeg_try_downscale(ct, scale_rect);
}
 
return 0;
-- 
1.7.9.5

--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v2 8/9] Documentation: devicetree: Document sclk-jpeg clock for exynos3250 SoC

2014-07-11 Thread Jacek Anaszewski
JPEG IP on Exynos3250 SoC requires enabling two clock
gates for its operation. This patch documents this
requirement.

Signed-off-by: Jacek Anaszewski j.anaszew...@samsung.com
Signed-off-by: Kyungmin Park kyungmin.p...@samsung.com
Cc: Rob Herring robh...@kernel.org
Cc: Pawel Moll pawel.m...@arm.com
Cc: Mark Rutland mark.rutl...@arm.com
Cc: Ian Campbell ijc+devicet...@hellion.org.uk
Cc: Kumar Gala ga...@codeaurora.org
Cc: devicet...@vger.kernel.org
---
 .../bindings/media/exynos-jpeg-codec.txt   |9 ++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/Documentation/devicetree/bindings/media/exynos-jpeg-codec.txt 
b/Documentation/devicetree/bindings/media/exynos-jpeg-codec.txt
index 937b755..3142745 100644
--- a/Documentation/devicetree/bindings/media/exynos-jpeg-codec.txt
+++ b/Documentation/devicetree/bindings/media/exynos-jpeg-codec.txt
@@ -3,9 +3,12 @@ Samsung S5P/EXYNOS SoC series JPEG codec
 Required properties:
 
 - compatible   : should be one of:
- samsung,s5pv210-jpeg, samsung,exynos4210-jpeg;
+ samsung,s5pv210-jpeg, samsung,exynos4210-jpeg,
+ samsung,exynos3250-jpeg;
 - reg  : address and length of the JPEG codec IP register set;
 - interrupts   : specifies the JPEG codec IP interrupt;
-- clocks   : should contain the JPEG codec IP gate clock specifier, from 
the
+- clocks   : should contain the JPEG codec IP gate clock specifier and
+ for the Exynos3250 SoC additionally the SCLK_JPEG entry; from 
the
  common clock bindings;
-- clock-names  : should contain jpeg entry.
+- clock-names  : should contain jpeg entry and additionally sclk-jpeg entry
+ for Exynos3250 SoC
-- 
1.7.9.5

--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v2 4/9] s5p-jpeg: fix g_selection op

2014-07-11 Thread Jacek Anaszewski
V4L2_SEL_TGT_COMPOSE_DEFAULT switch case should select whole
available area of the image and V4L2_SEL_TGT_COMPOSE
should apply user settings.

Signed-off-by: Jacek Anaszewski j.anaszew...@samsung.com
Signed-off-by: Kyungmin Park kyungmin.p...@samsung.com
---
 drivers/media/platform/s5p-jpeg/jpeg-core.c |   12 +++-
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/drivers/media/platform/s5p-jpeg/jpeg-core.c 
b/drivers/media/platform/s5p-jpeg/jpeg-core.c
index 0854f37..09b59d3 100644
--- a/drivers/media/platform/s5p-jpeg/jpeg-core.c
+++ b/drivers/media/platform/s5p-jpeg/jpeg-core.c
@@ -1505,21 +1505,23 @@ static int s5p_jpeg_g_selection(struct file *file, void 
*priv,
case V4L2_SEL_TGT_CROP:
case V4L2_SEL_TGT_CROP_BOUNDS:
case V4L2_SEL_TGT_CROP_DEFAULT:
-   case V4L2_SEL_TGT_COMPOSE:
case V4L2_SEL_TGT_COMPOSE_DEFAULT:
s-r.width = ctx-out_q.w;
s-r.height = ctx-out_q.h;
+   s-r.left = 0;
+   s-r.top = 0;
break;
+   case V4L2_SEL_TGT_COMPOSE:
case V4L2_SEL_TGT_COMPOSE_BOUNDS:
case V4L2_SEL_TGT_COMPOSE_PADDED:
-   s-r.width = ctx-cap_q.w;
-   s-r.height = ctx-cap_q.h;
+   s-r.width = ctx-crop_rect.width;
+   s-r.height =  ctx-crop_rect.height;
+   s-r.left = ctx-crop_rect.left;
+   s-r.top = ctx-crop_rect.top;
break;
default:
return -EINVAL;
}
-   s-r.left = 0;
-   s-r.top = 0;
return 0;
 }
 
-- 
1.7.9.5

--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v2 7/9] s5p-jpeg: add chroma subsampling adjustment for Exynos3250

2014-07-11 Thread Jacek Anaszewski
Take into account limitations specific to the Exynos3250 SoC,
regarding setting chroma subsampling control value.

Signed-off-by: Jacek Anaszewski j.anaszew...@samsung.com
Signed-off-by: Kyungmin Park kyungmin.p...@samsung.com
---
 drivers/media/platform/s5p-jpeg/jpeg-core.c |   59 +--
 1 file changed, 38 insertions(+), 21 deletions(-)

diff --git a/drivers/media/platform/s5p-jpeg/jpeg-core.c 
b/drivers/media/platform/s5p-jpeg/jpeg-core.c
index 1ef004b..283249d 100644
--- a/drivers/media/platform/s5p-jpeg/jpeg-core.c
+++ b/drivers/media/platform/s5p-jpeg/jpeg-core.c
@@ -1603,36 +1603,53 @@ static int s5p_jpeg_g_volatile_ctrl(struct v4l2_ctrl 
*ctrl)
return 0;
 }
 
-static int s5p_jpeg_try_ctrl(struct v4l2_ctrl *ctrl)
+static int s5p_jpeg_adjust_subs_ctrl(struct s5p_jpeg_ctx *ctx, int *ctrl_val)
 {
-   struct s5p_jpeg_ctx *ctx = ctrl_to_ctx(ctrl);
-   unsigned long flags;
-   int ret = 0;
-
-   spin_lock_irqsave(ctx-jpeg-slock, flags);
-
-   if (ctrl-id == V4L2_CID_JPEG_CHROMA_SUBSAMPLING) {
-   if (ctx-jpeg-variant-version == SJPEG_S5P)
-   goto error_free;
+   switch (ctx-jpeg-variant-version) {
+   case SJPEG_S5P:
+   return 0;
+   case SJPEG_EXYNOS3250:
+   /*
+* The exynos3250 device can produce JPEG image only
+* of 4:4:4 subsampling when given RGB32 source image.
+*/
+   if (ctx-out_q.fmt-fourcc == V4L2_PIX_FMT_RGB32)
+   *ctrl_val = 0;
+   break;
+   case SJPEG_EXYNOS4:
/*
 * The exynos4x12 device requires input raw image fourcc
 * to be V4L2_PIX_FMT_GREY if gray jpeg format
 * is to be set.
 */
if (ctx-out_q.fmt-fourcc != V4L2_PIX_FMT_GREY 
-   ctrl-val == V4L2_JPEG_CHROMA_SUBSAMPLING_GRAY) {
-   ret = -EINVAL;
-   goto error_free;
-   }
-   /*
-* The exynos4x12 device requires resulting jpeg subsampling
-* not to be lower than the input raw image subsampling.
-*/
-   if (ctx-out_q.fmt-subsampling  ctrl-val)
-   ctrl-val = ctx-out_q.fmt-subsampling;
+   *ctrl_val == V4L2_JPEG_CHROMA_SUBSAMPLING_GRAY)
+   return -EINVAL;
+   break;
}
 
-error_free:
+   /*
+* The exynos4x12 and exynos3250 devices require resulting
+* jpeg subsampling not to be lower than the input raw image
+* subsampling.
+*/
+   if (ctx-out_q.fmt-subsampling  *ctrl_val)
+   *ctrl_val = ctx-out_q.fmt-subsampling;
+
+   return 0;
+}
+
+static int s5p_jpeg_try_ctrl(struct v4l2_ctrl *ctrl)
+{
+   struct s5p_jpeg_ctx *ctx = ctrl_to_ctx(ctrl);
+   unsigned long flags;
+   int ret = 0;
+
+   spin_lock_irqsave(ctx-jpeg-slock, flags);
+
+   if (ctrl-id == V4L2_CID_JPEG_CHROMA_SUBSAMPLING)
+   ret = s5p_jpeg_adjust_subs_ctrl(ctx, ctrl-val);
+
spin_unlock_irqrestore(ctx-jpeg-slock, flags);
return ret;
 }
-- 
1.7.9.5

--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v2 9/9] ARM: dts: exynos3250: add JPEG codec device node

2014-07-11 Thread Jacek Anaszewski
Signed-off-by: Jacek Anaszewski j.anaszew...@samsung.com
Signed-off-by: Kyungmin Park kyungmin.p...@samsung.com
Cc: Kukjin Kim kgene@samsung.com
---
 arch/arm/boot/dts/exynos3250.dtsi |9 +
 1 file changed, 9 insertions(+)

diff --git a/arch/arm/boot/dts/exynos3250.dtsi 
b/arch/arm/boot/dts/exynos3250.dtsi
index 3e678fa..2f7f923 100644
--- a/arch/arm/boot/dts/exynos3250.dtsi
+++ b/arch/arm/boot/dts/exynos3250.dtsi
@@ -206,6 +206,15 @@
interrupts = 0 240 0;
};
 
+   jpeg-codec@1183 {
+   compatible = samsung,exynos3250-jpeg;
+   reg = 0x1183 0x1000;
+   interrupts = 0 171 0;
+   clocks = cmu CLK_JPEG, cmu CLK_SCLK_JPEG;
+   clock-names = jpeg, sclk-jpeg;
+   samsung,power-domain = pd_cam;
+   };
+
mshc_0: mshc@1251 {
compatible = samsung,exynos5250-dw-mshc;
reg = 0x1251 0x1000;
-- 
1.7.9.5

--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v2 0/9] Add support for Exynos3250 SoC to the s5p-jpeg driver

2014-07-11 Thread Jacek Anaszewski
This is the second version of the patch series adding support for
jpeg codec on Exynos3250 SoC to the s5p-jpeg driver (Sylwester -
thanks for a review). Supported raw formats are: YUYV, YVYU, UYVY,
VYUY, RGB565, RGB565X, RGB32, NV12, NV21. The support includes also
scaling and cropping features.

=
Changes since v1:
=

- added default case to the switch statement in the function
  exynos3250_jpeg_dec_scaling_ratiofunction
- removed not supported DT properties
- improved DT documentation
- updated Kconfig entry
- corrected DTS maintainer email in the commit message

Thanks,
Jacek Anaszewski

Jacek Anaszewski (9):
  s5p-jpeg: Add support for Exynos3250 SoC
  s5p-jpeg: return error immediately after get_byte fails
  s5p-jpeg: Adjust jpeg_bound_align_image to Exynos3250 needs
  s5p-jpeg: fix g_selection op
  s5p-jpeg: Assure proper crop rectangle initialization
  s5p-jpeg: Prevent erroneous downscaling for Exynos3250 SoC
  s5p-jpeg: add chroma subsampling adjustment for Exynos3250
  Documentation: devicetree: Document sclk-jpeg clock for exynos3250
SoC
  ARM: dts: exynos3250: add JPEG codec device node

 .../bindings/media/exynos-jpeg-codec.txt   |9 +-
 arch/arm/boot/dts/exynos3250.dtsi  |9 +
 drivers/media/platform/Kconfig |5 +-
 drivers/media/platform/s5p-jpeg/Makefile   |2 +-
 drivers/media/platform/s5p-jpeg/jpeg-core.c|  666 ++--
 drivers/media/platform/s5p-jpeg/jpeg-core.h|   33 +-
 .../media/platform/s5p-jpeg/jpeg-hw-exynos3250.c   |  489 ++
 .../media/platform/s5p-jpeg/jpeg-hw-exynos3250.h   |   60 ++
 drivers/media/platform/s5p-jpeg/jpeg-regs.h|  247 +++-
 9 files changed, 1462 insertions(+), 58 deletions(-)
 create mode 100644 drivers/media/platform/s5p-jpeg/jpeg-hw-exynos3250.c
 create mode 100644 drivers/media/platform/s5p-jpeg/jpeg-hw-exynos3250.h

-- 
1.7.9.5

--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v2 3/9] s5p-jpeg: Adjust jpeg_bound_align_image to Exynos3250 needs

2014-07-11 Thread Jacek Anaszewski
The jpeg_bound_align_image function needs to know the context
in which it is called, as it needs to align image dimensions in
a slight different manner for Exynos3250, which crops pixels for
specific values in case the format is RGB.

Signed-off-by: Jacek Anaszewski j.anaszew...@samsung.com
Signed-off-by: Kyungmin Park kyungmin.p...@samsung.com
---
 drivers/media/platform/s5p-jpeg/jpeg-core.c |   25 -
 1 file changed, 20 insertions(+), 5 deletions(-)

diff --git a/drivers/media/platform/s5p-jpeg/jpeg-core.c 
b/drivers/media/platform/s5p-jpeg/jpeg-core.c
index df3aaa9..0854f37 100644
--- a/drivers/media/platform/s5p-jpeg/jpeg-core.c
+++ b/drivers/media/platform/s5p-jpeg/jpeg-core.c
@@ -1133,7 +1133,8 @@ static struct s5p_jpeg_fmt *s5p_jpeg_find_format(struct 
s5p_jpeg_ctx *ctx,
return NULL;
 }
 
-static void jpeg_bound_align_image(u32 *w, unsigned int wmin, unsigned int 
wmax,
+static void jpeg_bound_align_image(struct s5p_jpeg_ctx *ctx,
+  u32 *w, unsigned int wmin, unsigned int wmax,
   unsigned int walign,
   u32 *h, unsigned int hmin, unsigned int hmax,
   unsigned int halign)
@@ -1145,13 +1146,27 @@ static void jpeg_bound_align_image(u32 *w, unsigned int 
wmin, unsigned int wmax,
 
w_step = 1  walign;
h_step = 1  halign;
+
+   if (ctx-jpeg-variant-version == SJPEG_EXYNOS3250) {
+   /*
+* Rightmost and bottommost pixels are cropped by the
+* Exynos3250 JPEG IP for RGB formats, for the specific
+* width and height values respectively. This assignment
+* will result in v4l_bound_align_image returning dimensions
+* reduced by 1 for the aforementioned cases.
+*/
+   if (w_step == 4  ((width  3) == 1)) {
+   wmax = width;
+   hmax = height;
+   }
+   }
+
v4l_bound_align_image(w, wmin, wmax, walign, h, hmin, hmax, halign, 0);
 
if (*w  width  (*w + w_step)  wmax)
*w += w_step;
if (*h  height  (*h + h_step)  hmax)
*h += h_step;
-
 }
 
 static int vidioc_try_fmt(struct v4l2_format *f, struct s5p_jpeg_fmt *fmt,
@@ -1167,12 +1182,12 @@ static int vidioc_try_fmt(struct v4l2_format *f, struct 
s5p_jpeg_fmt *fmt,
/* V4L2 specification suggests the driver corrects the format struct
 * if any of the dimensions is unsupported */
if (q_type == FMT_TYPE_OUTPUT)
-   jpeg_bound_align_image(pix-width, S5P_JPEG_MIN_WIDTH,
+   jpeg_bound_align_image(ctx, pix-width, S5P_JPEG_MIN_WIDTH,
   S5P_JPEG_MAX_WIDTH, 0,
   pix-height, S5P_JPEG_MIN_HEIGHT,
   S5P_JPEG_MAX_HEIGHT, 0);
else
-   jpeg_bound_align_image(pix-width, S5P_JPEG_MIN_WIDTH,
+   jpeg_bound_align_image(ctx, pix-width, S5P_JPEG_MIN_WIDTH,
   S5P_JPEG_MAX_WIDTH, fmt-h_align,
   pix-height, S5P_JPEG_MIN_HEIGHT,
   S5P_JPEG_MAX_HEIGHT, fmt-v_align);
@@ -1294,7 +1309,7 @@ static int exynos4_jpeg_get_output_buffer_size(struct 
s5p_jpeg_ctx *ctx,
else
wh_align = 1;
 
-   jpeg_bound_align_image(w, S5P_JPEG_MIN_WIDTH,
+   jpeg_bound_align_image(ctx, w, S5P_JPEG_MIN_WIDTH,
   S5P_JPEG_MAX_WIDTH, wh_align,
   h, S5P_JPEG_MIN_HEIGHT,
   S5P_JPEG_MAX_HEIGHT, wh_align);
-- 
1.7.9.5

--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v2 5/9] s5p-jpeg: Assure proper crop rectangle initialization

2014-07-11 Thread Jacek Anaszewski
Assure proper crop_rect initialization in case
the user space doesn't call S_SELECTION ioctl.

Signed-off-by: Jacek Anaszewski j.anaszew...@samsung.com
Signed-off-by: Kyungmin Park kyungmin.p...@samsung.com
---
 drivers/media/platform/s5p-jpeg/jpeg-core.c |   15 +++
 1 file changed, 15 insertions(+)

diff --git a/drivers/media/platform/s5p-jpeg/jpeg-core.c 
b/drivers/media/platform/s5p-jpeg/jpeg-core.c
index 09b59d3..2491ef8 100644
--- a/drivers/media/platform/s5p-jpeg/jpeg-core.c
+++ b/drivers/media/platform/s5p-jpeg/jpeg-core.c
@@ -1367,6 +1367,21 @@ static int s5p_jpeg_s_fmt(struct s5p_jpeg_ctx *ct, 
struct v4l2_format *f)
V4L2_CID_JPEG_CHROMA_SUBSAMPLING);
if (ctrl_subs)
v4l2_ctrl_s_ctrl(ctrl_subs, q_data-fmt-subsampling);
+   ct-crop_altered = false;
+   }
+
+   /*
+* For decoding init crop_rect with capture buffer dimmensions which
+* contain aligned dimensions of the input JPEG image and do it only
+* if crop rectangle hasn't been altered by the user space e.g. with
+* S_SELECTION ioctl. For encoding assign output buffer dimensions.
+*/
+   if (!ct-crop_altered 
+   ((ct-mode == S5P_JPEG_DECODE  f_type == FMT_TYPE_CAPTURE) ||
+(ct-mode == S5P_JPEG_ENCODE  f_type == FMT_TYPE_OUTPUT))) {
+   ct-crop_rect.width = pix-width;
+   ct-crop_rect.height = pix-height;
+   }
}
 
return 0;
-- 
1.7.9.5

--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v3] ARM: dts: exynos3250 add MFC codec device node

2014-07-11 Thread Jacek Anaszewski
Signed-off-by: Jacek Anaszewski j.anaszew...@samsung.com
Signed-off-by: Kyungmin Park kyungmin.p...@samsung.com
Cc: Kukjin Kim kgene@samsung.com
---
 arch/arm/boot/dts/exynos3250.dtsi |   11 +++
 1 file changed, 11 insertions(+)

diff --git a/arch/arm/boot/dts/exynos3250.dtsi 
b/arch/arm/boot/dts/exynos3250.dtsi
index 351871a..01bf5fa 100644
--- a/arch/arm/boot/dts/exynos3250.dtsi
+++ b/arch/arm/boot/dts/exynos3250.dtsi
@@ -283,6 +283,17 @@
status = disabled;
};
 
+   codec@1340 {
+   compatible = samsung,mfc-v7;
+   reg = 0x1340 0x1;
+   interrupts = 0 102 0;
+   clock-names = mfc, sclk-mfc;
+   clocks = cmu CLK_MFC, cmu CLK_SCLK_MFC;
+   #address-cells = 1;
+   #size-cells = 0;
+   samsung,power-domain = pd_mfc;
+   };
+
serial_0: serial@1380 {
compatible = samsung,exynos4210-uart;
reg = 0x1380 0x100;
-- 
1.7.9.5

--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH] media: em28xx-dvb unregister i2c tuner and demod after fe detach

2014-07-11 Thread Shuah Khan
i2c tuner and demod are unregisetred in .fini before fe detach.
dvb_unregister_frontend() and dvb_frontend_detach() invoke tuner
sleep() and release() interfaces. Change to unregister i2c tuner
and demod from em28xx_unregister_dvb() after unregistering dvb
and detaching fe.

Signed-off-by: Shuah Khan shuah...@samsung.com
---
 drivers/media/usb/em28xx/em28xx-dvb.c |   32 +---
 1 file changed, 17 insertions(+), 15 deletions(-)

diff --git a/drivers/media/usb/em28xx/em28xx-dvb.c 
b/drivers/media/usb/em28xx/em28xx-dvb.c
index 8314f51..8d5cb62 100644
--- a/drivers/media/usb/em28xx/em28xx-dvb.c
+++ b/drivers/media/usb/em28xx/em28xx-dvb.c
@@ -1030,6 +1030,8 @@ fail_adapter:
 
 static void em28xx_unregister_dvb(struct em28xx_dvb *dvb)
 {
+   struct i2c_client *client;
+
dvb_net_release(dvb-net);
dvb-demux.dmx.remove_frontend(dvb-demux.dmx, dvb-fe_mem);
dvb-demux.dmx.remove_frontend(dvb-demux.dmx, dvb-fe_hw);
@@ -1041,6 +1043,21 @@ static void em28xx_unregister_dvb(struct em28xx_dvb *dvb)
if (dvb-fe[1]  !dvb-dont_attach_fe1)
dvb_frontend_detach(dvb-fe[1]);
dvb_frontend_detach(dvb-fe[0]);
+
+   /* remove I2C tuner */
+   client = dvb-i2c_client_tuner;
+   if (client) {
+   module_put(client-dev.driver-owner);
+   i2c_unregister_device(client);
+   }
+
+   /* remove I2C demod */
+   client = dvb-i2c_client_demod;
+   if (client) {
+   module_put(client-dev.driver-owner);
+   i2c_unregister_device(client);
+   }
+
dvb_unregister_adapter(dvb-adapter);
 }
 
@@ -1628,7 +1645,6 @@ static inline void prevent_sleep(struct dvb_frontend_ops 
*ops)
 static int em28xx_dvb_fini(struct em28xx *dev)
 {
struct em28xx_dvb *dvb;
-   struct i2c_client *client;
 
if (dev-is_audio_only) {
/* Shouldn't initialize IR for this interface */
@@ -1646,7 +1662,6 @@ static int em28xx_dvb_fini(struct em28xx *dev)
em28xx_info(Closing DVB extension);
 
dvb = dev-dvb;
-   client = dvb-i2c_client_tuner;
 
em28xx_uninit_usb_xfer(dev, EM28XX_DIGITAL_MODE);
 
@@ -1659,19 +1674,6 @@ static int em28xx_dvb_fini(struct em28xx *dev)
prevent_sleep(dvb-fe[1]-ops);
}
 
-   /* remove I2C tuner */
-   if (client) {
-   module_put(client-dev.driver-owner);
-   i2c_unregister_device(client);
-   }
-
-   /* remove I2C demod */
-   client = dvb-i2c_client_demod;
-   if (client) {
-   module_put(client-dev.driver-owner);
-   i2c_unregister_device(client);
-   }
-
em28xx_unregister_dvb(dvb);
kfree(dvb);
dev-dvb = NULL;
-- 
1.7.10.4

--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v2 0/9] Add support for Exynos3250 SoC to the s5p-jpeg driver

2014-07-11 Thread Sylwester Nawrocki
Hi Jacek,

On 11/07/14 17:19, Jacek Anaszewski wrote:
 
 Jacek Anaszewski (9):
   s5p-jpeg: Add support for Exynos3250 SoC
   s5p-jpeg: return error immediately after get_byte fails
   s5p-jpeg: Adjust jpeg_bound_align_image to Exynos3250 needs
   s5p-jpeg: fix g_selection op
   s5p-jpeg: Assure proper crop rectangle initialization
   s5p-jpeg: Prevent erroneous downscaling for Exynos3250 SoC
   s5p-jpeg: add chroma subsampling adjustment for Exynos3250
   Documentation: devicetree: Document sclk-jpeg clock for exynos3250
 SoC
   ARM: dts: exynos3250: add JPEG codec device node

I've applied all patches from this series except the last one
into my tree.

-- 
Thanks,
Sylwester
--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: linux-next: Tree for Jul 11 (media/pci/ttpci/av7110)

2014-07-11 Thread Randy Dunlap
On 07/11/14 00:18, Stephen Rothwell wrote:
 Hi all,
 
 Changes since 20140710:
 

on x86_64:

CONFIG_DVB_AV7110=y
CONFIG_INPUT_EVDEV=m

drivers/built-in.o: In function `av7110_emit_keyup':
av7110_ir.c:(.text+0x76b608): undefined reference to `input_event'
av7110_ir.c:(.text+0x76b61a): undefined reference to `input_event'
drivers/built-in.o: In function `av7110_emit_key':
av7110_ir.c:(.text+0x76b6b4): undefined reference to `input_event'
av7110_ir.c:(.text+0x76b6cd): undefined reference to `input_event'
av7110_ir.c:(.text+0x76b7b0): undefined reference to `input_event'
drivers/built-in.o:av7110_ir.c:(.text+0x76b7ca): more undefined references to 
`input_event' follow
drivers/built-in.o: In function `av7110_ir_init':
(.text+0x76bcdb): undefined reference to `input_allocate_device'
drivers/built-in.o: In function `av7110_ir_init':
(.text+0x76bf93): undefined reference to `input_register_device'
drivers/built-in.o: In function `av7110_ir_init':
(.text+0x76c073): undefined reference to `input_free_device'
drivers/built-in.o: In function `av7110_ir_exit':
(.text+0x76c1db): undefined reference to `input_unregister_device'


-- 
~Randy
--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH] media: em28xx - fix i2c_xfer to return -ENODEV when dev is removed

2014-07-11 Thread Shuah Khan
In em28xx usb disconnect code path, some dvb fe and tuner drivers
attempt i2c transfers from their release interfaces. When device
is removed, return -ENODEV instead of attempting to transfer data
over i2c.

Signed-off-by: Shuah Khan shuah...@samsung.com
---
 drivers/media/usb/em28xx/em28xx-i2c.c |6 ++
 1 file changed, 6 insertions(+)

diff --git a/drivers/media/usb/em28xx/em28xx-i2c.c 
b/drivers/media/usb/em28xx/em28xx-i2c.c
index b58d4eb..1048c1a 100644
--- a/drivers/media/usb/em28xx/em28xx-i2c.c
+++ b/drivers/media/usb/em28xx/em28xx-i2c.c
@@ -501,6 +501,12 @@ static int em28xx_i2c_xfer(struct i2c_adapter *i2c_adap,
int addr, rc, i;
u8 reg;
 
+   /* prevent i2c xfer attempts after device is disconnected
+  some fe's try to do i2c writes/reads from their release
+  interfaces when called in disconnect path */
+   if (dev-disconnected)
+   return -ENODEV;
+
rc = rt_mutex_trylock(dev-i2c_bus_lock);
if (rc  0)
return rc;
-- 
1.7.10.4

--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 0/3] Fix interval length on ISDB-T doc/driver

2014-07-11 Thread Mauro Carvalho Chehab
The interleaving ISDB-T representation was utter broken:

dib8000 driver were using interleave=3 on some parts, and interleave=4
on others; net result is that interleaving=4 or 8 were broking there.

mb86a20s were using guard time as interleaving length.

Other drivers don't implement it.

Userspace (libdvbv5) were expecting a value of 0, 1, 2, 4.

Docbook were confusing.

A previous patch fixed the dib8000 driver. Let's now fix the
documentation and mb86a20s. This way, this field can be reliable.

Mauro Carvalho Chehab (3):
  DocBook: Fix ISDB-T Interleaving property
  mb86a20s: Fix Interleaving
  mb86a20s: Fix the code that estimates the measurement interval

 Documentation/DocBook/media/dvb/dvbproperty.xml | 44 ++---
 drivers/media/dvb-frontends/mb86a20s.c  | 26 +--
 2 files changed, 48 insertions(+), 22 deletions(-)

-- 
1.9.3

--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 2/3] mb86a20s: Fix Interleaving

2014-07-11 Thread Mauro Carvalho Chehab
Interleaving code was wrong at mb86a20s: instead, it was looking
at the Guard Interval. Fix it.

Signed-off-by: Mauro Carvalho Chehab m.che...@samsung.com
---
 drivers/media/dvb-frontends/mb86a20s.c | 18 --
 1 file changed, 4 insertions(+), 14 deletions(-)

diff --git a/drivers/media/dvb-frontends/mb86a20s.c 
b/drivers/media/dvb-frontends/mb86a20s.c
index 2f458bb188c7..2de0e59bd243 100644
--- a/drivers/media/dvb-frontends/mb86a20s.c
+++ b/drivers/media/dvb-frontends/mb86a20s.c
@@ -459,6 +459,9 @@ static int mb86a20s_get_interleaving(struct mb86a20s_state 
*state,
 unsigned layer)
 {
int rc;
+   int interleaving[] = {
+   0, 1, 2, 4, 8
+   };
 
static unsigned char reg[] = {
[0] = 0x88, /* Layer A */
@@ -475,20 +478,7 @@ static int mb86a20s_get_interleaving(struct mb86a20s_state 
*state,
if (rc  0)
return rc;
 
-   switch ((rc  4)  0x07) {
-   case 1:
-   return GUARD_INTERVAL_1_4;
-   case 2:
-   return GUARD_INTERVAL_1_8;
-   case 3:
-   return GUARD_INTERVAL_1_16;
-   case 4:
-   return GUARD_INTERVAL_1_32;
-
-   default:
-   case 0:
-   return GUARD_INTERVAL_AUTO;
-   }
+   return interleaving[(rc  4)  0x07];
 }
 
 static int mb86a20s_get_segment_count(struct mb86a20s_state *state,
-- 
1.9.3

--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 3/3] mb86a20s: Fix the code that estimates the measurement interval

2014-07-11 Thread Mauro Carvalho Chehab
Instead of looking at the guard interval field, it was using
the interval length, with is wrong. Fix it.

Signed-off-by: Mauro Carvalho Chehab m.che...@samsung.com
---
 drivers/media/dvb-frontends/mb86a20s.c | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/media/dvb-frontends/mb86a20s.c 
b/drivers/media/dvb-frontends/mb86a20s.c
index 2de0e59bd243..227a420f7069 100644
--- a/drivers/media/dvb-frontends/mb86a20s.c
+++ b/drivers/media/dvb-frontends/mb86a20s.c
@@ -556,7 +556,7 @@ static u32 isdbt_rate[3][5][4] = {
 
 static void mb86a20s_layer_bitrate(struct dvb_frontend *fe, u32 layer,
   u32 modulation, u32 forward_error_correction,
-  u32 interleaving,
+  u32 guard_interval,
   u32 segment)
 {
struct mb86a20s_state *state = fe-demodulator_priv;
@@ -564,7 +564,7 @@ static void mb86a20s_layer_bitrate(struct dvb_frontend *fe, 
u32 layer,
int mod, fec, guard;
 
/*
-* If modulation/fec/interleaving is not detected, the default is
+* If modulation/fec/guard is not detected, the default is
 * to consider the lowest bit rate, to avoid taking too long time
 * to get BER.
 */
@@ -602,7 +602,7 @@ static void mb86a20s_layer_bitrate(struct dvb_frontend *fe, 
u32 layer,
break;
}
 
-   switch (interleaving) {
+   switch (guard_interval) {
default:
case GUARD_INTERVAL_1_4:
guard = 0;
@@ -693,7 +693,7 @@ static int mb86a20s_get_frontend(struct dvb_frontend *fe)
c-layer[layer].interleaving = rc;
mb86a20s_layer_bitrate(fe, layer, c-layer[layer].modulation,
   c-layer[layer].fec,
-  c-layer[layer].interleaving,
+  c-guard_interval,
   c-layer[layer].segment_count);
}
 
-- 
1.9.3

--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 1/3] DocBook: Fix ISDB-T Interleaving property

2014-07-11 Thread Mauro Carvalho Chehab
The DocBook documentation is incorrect: on ISDB-T, interleaving
time is always a power of 2. Fix it and provides a table showing
the actual interleaving length for each mode.

Signed-off-by: Mauro Carvalho Chehab m.che...@samsung.com
---
 Documentation/DocBook/media/dvb/dvbproperty.xml | 44 ++---
 1 file changed, 40 insertions(+), 4 deletions(-)

diff --git a/Documentation/DocBook/media/dvb/dvbproperty.xml 
b/Documentation/DocBook/media/dvb/dvbproperty.xml
index 24c22cabc668..948ddaab592e 100644
--- a/Documentation/DocBook/media/dvb/dvbproperty.xml
+++ b/Documentation/DocBook/media/dvb/dvbproperty.xml
@@ -555,10 +555,46 @@ typedef enum fe_delivery_system {
/section
section id=DTV-ISDBT-LAYER-TIME-INTERLEAVING

titleconstantDTV_ISDBT_LAYER*_TIME_INTERLEAVING/constant/title
-   paraPossible values: 0, 1, 2, 3, -1 (AUTO)/para
-   paraNote: The real inter-leaver depth-names depend on 
the mode (fft-size); the values
-   here are referring to what can be found in the 
TMCC-structure -
-   independent of the mode./para
+   paraValid values: 0, 1, 2, 4, -1 (AUTO)/para
+   parawhen DTV_ISDBT_SOUND_BROADCASTING is active, 
value 8 is also valid./para
+   paraNote: The real time interleaving length depends 
on the mode (fft-size). The values
+   here are referring to what can be found in the 
TMCC-structure, as shown in the table below./para
+   informaltable id=isdbt-layer-interleaving-table
+   tgroup cols=4 align=center
+   tbody
+   row
+   
entryDTV_ISDBT_LAYER*_TIME_INTERLEAVING/entry
+   entryMode 1 (2K 
FFT)/entry
+   entryMode 2 (4K 
FFT)/entry
+   entryMode 3 (8K 
FFT)/entry
+   /row
+   row
+   entry0/entry
+   entry0/entry
+   entry0/entry
+   entry0/entry
+   /row
+   row
+   entry1/entry
+   entry4/entry
+   entry2/entry
+   entry1/entry
+   /row
+   row
+   entry2/entry
+   entry8/entry
+   entry4/entry
+   entry2/entry
+   /row
+   row
+   entry4/entry
+   entry16/entry
+   entry8/entry
+   entry4/entry
+   /row
+   /tbody
+   /tgroup
+   /informaltable
/section
section id=DTV-ATSCMH-FIC-VER
titleconstantDTV_ATSCMH_FIC_VER/constant/title
-- 
1.9.3

--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


cron job: media_tree daily build: OK

2014-07-11 Thread Hans Verkuil
This message is generated daily by a cron job that builds media_tree for
the kernels and architectures in the list below.

Results of the daily build of media_tree:

date:   Sat Jul 12 04:00:21 CEST 2014
git branch: test
git hash:   3c0d394ea7022bb9666d9df97a5776c4bcc3045c
gcc version:i686-linux-gcc (GCC) 4.8.2
sparse version: v0.5.0-14-gf11dd94
host hardware:  x86_64
host os:3.14-5.slh.5-amd64

linux-git-arm-at91: OK
linux-git-arm-davinci: OK
linux-git-arm-exynos: OK
linux-git-arm-mx: OK
linux-git-arm-omap: OK
linux-git-arm-omap1: OK
linux-git-arm-pxa: OK
linux-git-blackfin: OK
linux-git-i686: OK
linux-git-m32r: OK
linux-git-mips: OK
linux-git-powerpc64: OK
linux-git-sh: OK
linux-git-x86_64: OK
linux-2.6.31.14-i686: OK
linux-2.6.32.27-i686: OK
linux-2.6.33.7-i686: OK
linux-2.6.34.7-i686: OK
linux-2.6.35.9-i686: OK
linux-2.6.36.4-i686: OK
linux-2.6.37.6-i686: OK
linux-2.6.38.8-i686: OK
linux-2.6.39.4-i686: OK
linux-3.0.60-i686: OK
linux-3.1.10-i686: OK
linux-3.2.37-i686: OK
linux-3.3.8-i686: OK
linux-3.4.27-i686: OK
linux-3.5.7-i686: OK
linux-3.6.11-i686: OK
linux-3.7.4-i686: OK
linux-3.8-i686: OK
linux-3.9.2-i686: OK
linux-3.10.1-i686: OK
linux-3.11.1-i686: OK
linux-3.12.23-i686: OK
linux-3.13.11-i686: OK
linux-3.14.9-i686: OK
linux-3.15.2-i686: OK
linux-3.16-rc1-i686: OK
linux-2.6.31.14-x86_64: OK
linux-2.6.32.27-x86_64: OK
linux-2.6.33.7-x86_64: OK
linux-2.6.34.7-x86_64: OK
linux-2.6.35.9-x86_64: OK
linux-2.6.36.4-x86_64: OK
linux-2.6.37.6-x86_64: OK
linux-2.6.38.8-x86_64: OK
linux-2.6.39.4-x86_64: OK
linux-3.0.60-x86_64: OK
linux-3.1.10-x86_64: OK
linux-3.2.37-x86_64: OK
linux-3.3.8-x86_64: OK
linux-3.4.27-x86_64: OK
linux-3.5.7-x86_64: OK
linux-3.6.11-x86_64: OK
linux-3.7.4-x86_64: OK
linux-3.8-x86_64: OK
linux-3.9.2-x86_64: OK
linux-3.10.1-x86_64: OK
linux-3.11.1-x86_64: OK
linux-3.12.23-x86_64: OK
linux-3.13.11-x86_64: OK
linux-3.14.9-x86_64: OK
linux-3.15.2-x86_64: OK
linux-3.16-rc1-x86_64: OK
apps: OK
spec-git: OK
sparse: WARNINGS

Detailed results are available here:

http://www.xs4all.nl/~hverkuil/logs/Saturday.log

Full logs are available here:

http://www.xs4all.nl/~hverkuil/logs/Saturday.tar.bz2

The Media Infrastructure API from this daily build is here:

http://www.xs4all.nl/~hverkuil/spec/media.html
--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html