[PATCH] s5p-jpeg: Initialize vfd_decoder-vfl_dir field

2013-09-11 Thread Jacek Anaszewski
This patch fixes regression introduced in the commit
5c77879ff9ab9e7 and caused by not initializing the
vfl_dir field of the vfd_decoder instance of the struct
video_device, after the field was introduced. It precluded
calling the driver ioctls which require vfl_dir not to be
equal to VFL_DIR_RX which is defined as 0 and uninitialized
vfl_dir field is interpreted as such. In effect the unlikely()
condition in the v4l_s_fmt function failed for the ioctls that
expect is_tx to be false, which prevented the ioctl callbacks
registered by the driver from being called.

Signed-off-by: Jacek Anaszewski j.anaszew...@samsung.com
Signed-off-by: Kyungmin Park kyungmin.p...@samsung.com
Cc: Hans Verkuil hverk...@xs4all.nl
---
 drivers/media/platform/s5p-jpeg/jpeg-core.c |1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/media/platform/s5p-jpeg/jpeg-core.c 
b/drivers/media/platform/s5p-jpeg/jpeg-core.c
index 88c5beb..1db4736 100644
--- a/drivers/media/platform/s5p-jpeg/jpeg-core.c
+++ b/drivers/media/platform/s5p-jpeg/jpeg-core.c
@@ -1424,6 +1424,7 @@ static int s5p_jpeg_probe(struct platform_device *pdev)
jpeg-vfd_decoder-release  = video_device_release;
jpeg-vfd_decoder-lock = jpeg-lock;
jpeg-vfd_decoder-v4l2_dev = jpeg-v4l2_dev;
+   jpeg-vfd_decoder-vfl_dir  = VFL_DIR_M2M;
 
ret = video_register_device(jpeg-vfd_decoder, VFL_TYPE_GRABBER, -1);
if (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 00/16] Add support for Exynox4x12 to the s5p-jpeg driver

2013-11-19 Thread Jacek Anaszewski
The main aim of this series is to add support for Exynos4x12 SoC
for the s5p-jpeg driver. Nonetheless, a room for couple of fixes
and improvements has been found during development, which
is reflected in the corresponding patches.

Thanks,
Jacek Anaszewski

Jacek Anaszewski (16):
  s5p-jpeg: Reorder quantization tables
  s5p-jpeg: Fix output YUV 4:2:0 fourcc for decoder
  s5p-jpeg: Fix erroneous condition while validating bytesperline value
  s5p-jpeg: Remove superfluous call to the jpeg_bound_align_image
function
  s5p-jpeg: Rename functions specific to the S5PC210 SoC accordingly
  s5p-jpeg: Fix clock resource management
  s5p-jpeg: Fix lack of spin_lock protection
  s5p-jpeg: Synchronize cached controls with V4L2 core
  s5p-jpeg: Split jpeg-hw.h to jpeg-hw-s5p.c and jpeg-hw-s5p.c
  s5p-jpeg: Add hardware API for the exynos4x12 JPEG codec.
  s5p-jpeg: Retrieve YCbCr subsampling field from the jpeg header
  s5p-jpeg: Ensure correct capture format for Exynos4x12
  s5p-jpeg: Allow for wider JPEG subsampling scope for Exynos4x12
encoder
  s5p-jpeg: Synchronize V4L2_CID_JPEG_CHROMA_SUBSAMPLING control value
  s5p-jpeg: Ensure setting correct value of the chroma subsampling
control
  s5p-jpeg: Adjust g_volatile_ctrl callback to Exynos4x12 needs

 drivers/media/platform/s5p-jpeg/Makefile   |2 +-
 drivers/media/platform/s5p-jpeg/jpeg-core.c| 1049 
 drivers/media/platform/s5p-jpeg/jpeg-core.h|   75 +-
 drivers/media/platform/s5p-jpeg/jpeg-hw-exynos.c   |  293 ++
 drivers/media/platform/s5p-jpeg/jpeg-hw-exynos.h   |   44 +
 .../platform/s5p-jpeg/{jpeg-hw.h = jpeg-hw-s5p.c} |   82 +-
 drivers/media/platform/s5p-jpeg/jpeg-hw-s5p.h  |   63 ++
 drivers/media/platform/s5p-jpeg/jpeg-regs.h|  215 +++-
 8 files changed, 1564 insertions(+), 259 deletions(-)
 create mode 100644 drivers/media/platform/s5p-jpeg/jpeg-hw-exynos.c
 create mode 100644 drivers/media/platform/s5p-jpeg/jpeg-hw-exynos.h
 rename drivers/media/platform/s5p-jpeg/{jpeg-hw.h = jpeg-hw-s5p.c} (71%)
 create mode 100644 drivers/media/platform/s5p-jpeg/jpeg-hw-s5p.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 01/16] s5p-jpeg: Reorder quantization tables

2013-11-19 Thread Jacek Anaszewski
Reorder quantization tables so that their elements
are arranged in the manner reflecting compression
quality level that is in accordance with V4L2 documentation,
i.e. the larger value of the V4L2_CID_JPEG_COMPRESSION_QUALITY
control the better image quality, and thus lower compression
quality. The modification allows also to get rid of
reverse logic in the s_ctrl callback while assigning
user space value to the ctx-compr_quality variable.

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 |  116 +--
 1 file changed, 58 insertions(+), 58 deletions(-)

diff --git a/drivers/media/platform/s5p-jpeg/jpeg-core.c 
b/drivers/media/platform/s5p-jpeg/jpeg-core.c
index 47934db..2234944 100644
--- a/drivers/media/platform/s5p-jpeg/jpeg-core.c
+++ b/drivers/media/platform/s5p-jpeg/jpeg-core.c
@@ -84,15 +84,25 @@ static struct s5p_jpeg_fmt formats_dec[] = {
 #define NUM_FORMATS_DEC ARRAY_SIZE(formats_dec)
 
 static const unsigned char qtbl_luminance[4][64] = {
-   {/* level 1 - high quality */
-8,  6,  6,  8, 12, 14, 16, 17,
-6,  6,  6,  8, 10, 13, 12, 15,
-6,  6,  7,  8, 13, 14, 18, 24,
-8,  8,  8, 14, 13, 19, 24, 35,
-   12, 10, 13, 13, 20, 26, 34, 39,
-   14, 13, 14, 19, 26, 34, 39, 39,
-   16, 12, 18, 24, 34, 39, 39, 39,
-   17, 15, 24, 35, 39, 39, 39, 39
+   {/*level 0 - high compression quality */
+   20, 16, 25, 39, 50, 46, 62, 68,
+   16, 18, 23, 38, 38, 53, 65, 68,
+   25, 23, 31, 38, 53, 65, 68, 68,
+   39, 38, 38, 53, 65, 68, 68, 68,
+   50, 38, 53, 65, 68, 68, 68, 68,
+   46, 53, 65, 68, 68, 68, 68, 68,
+   62, 65, 68, 68, 68, 68, 68, 68,
+   68, 68, 68, 68, 68, 68, 68, 68
+   },
+   {/* level 1 */
+   16, 11, 11, 16, 23, 27, 31, 30,
+   11, 12, 12, 15, 20, 23, 23, 30,
+   11, 12, 13, 16, 23, 26, 35, 47,
+   16, 15, 16, 23, 26, 37, 47, 64,
+   23, 20, 23, 26, 39, 51, 64, 64,
+   27, 23, 26, 37, 51, 64, 64, 64,
+   31, 23, 35, 47, 64, 64, 64, 64,
+   30, 30, 47, 64, 64, 64, 64, 64
},
{/* level 2 */
12,  8,  8, 12, 17, 21, 24, 23,
@@ -104,38 +114,38 @@ static const unsigned char qtbl_luminance[4][64] = {
24, 18, 27, 36, 51, 59, 59, 59,
23, 23, 36, 53, 59, 59, 59, 59
},
-   {/* level 3 */
-   16, 11, 11, 16, 23, 27, 31, 30,
-   11, 12, 12, 15, 20, 23, 23, 30,
-   11, 12, 13, 16, 23, 26, 35, 47,
-   16, 15, 16, 23, 26, 37, 47, 64,
-   23, 20, 23, 26, 39, 51, 64, 64,
-   27, 23, 26, 37, 51, 64, 64, 64,
-   31, 23, 35, 47, 64, 64, 64, 64,
-   30, 30, 47, 64, 64, 64, 64, 64
-   },
-   {/*level 4 - low quality */
-   20, 16, 25, 39, 50, 46, 62, 68,
-   16, 18, 23, 38, 38, 53, 65, 68,
-   25, 23, 31, 38, 53, 65, 68, 68,
-   39, 38, 38, 53, 65, 68, 68, 68,
-   50, 38, 53, 65, 68, 68, 68, 68,
-   46, 53, 65, 68, 68, 68, 68, 68,
-   62, 65, 68, 68, 68, 68, 68, 68,
-   68, 68, 68, 68, 68, 68, 68, 68
+   {/* level 3 - low compression quality */
+8,  6,  6,  8, 12, 14, 16, 17,
+6,  6,  6,  8, 10, 13, 12, 15,
+6,  6,  7,  8, 13, 14, 18, 24,
+8,  8,  8, 14, 13, 19, 24, 35,
+   12, 10, 13, 13, 20, 26, 34, 39,
+   14, 13, 14, 19, 26, 34, 39, 39,
+   16, 12, 18, 24, 34, 39, 39, 39,
+   17, 15, 24, 35, 39, 39, 39, 39
}
 };
 
 static const unsigned char qtbl_chrominance[4][64] = {
-   {/* level 1 - high quality */
-9,  8,  9, 11, 14, 17, 19, 24,
-8, 10,  9, 11, 14, 13, 17, 22,
-9,  9, 13, 14, 13, 15, 23, 26,
-   11, 11, 14, 14, 15, 20, 26, 33,
-   14, 14, 13, 15, 20, 24, 33, 39,
-   17, 13, 15, 20, 24, 32, 39, 39,
-   19, 17, 23, 26, 33, 39, 39, 39,
-   24, 22, 26, 33, 39, 39, 39, 39
+   {/*level 0 - high compression quality */
+   21, 25, 32, 38, 54, 68, 68, 68,
+   25, 28, 24, 38, 54, 68, 68, 68,
+   32, 24, 32, 43, 66, 68, 68, 68,
+   38, 38, 43, 53, 68, 68, 68, 68,
+   54, 54, 66, 68, 68, 68, 68, 68,
+   68, 68, 68, 68, 68, 68, 68, 68,
+   68, 68, 68, 68, 68, 68, 68, 68,
+   68, 68, 68, 68, 68, 68, 68, 68
+   },
+   {/* level 1 */
+   17, 15, 17, 21, 20, 26, 38, 48,
+   15, 19, 18, 17, 20, 26, 35, 43,
+   17, 18, 20, 22, 26, 30, 46, 53

[PATCH 03/16] s5p-jpeg: Fix erroneous condition while validating bytesperline value

2013-11-19 Thread Jacek Anaszewski
The aim of the condition is ensuring that the bytesperline
value set by the user space application is proper for the
given format and adjusting it if isn't. As the depth value
of the format description entry is expressed in bits then
the bytesperline value needs to be divided, not multiplied,
by that value to get the number of bytes required to store
single line of image samples.

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 |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/media/platform/s5p-jpeg/jpeg-core.c 
b/drivers/media/platform/s5p-jpeg/jpeg-core.c
index 0f567c5..a1366f0 100644
--- a/drivers/media/platform/s5p-jpeg/jpeg-core.c
+++ b/drivers/media/platform/s5p-jpeg/jpeg-core.c
@@ -670,7 +670,7 @@ static int vidioc_try_fmt(struct v4l2_format *f, struct 
s5p_jpeg_fmt *fmt,
bpl = pix-width; /* planar */
 
if (fmt-colplanes == 1  /* packed */
-   (bpl  3) * fmt-depth  pix-width)
+   (bpl  3) / fmt-depth  pix-width)
bpl = (pix-width * fmt-depth)  3;
 
pix-bytesperline = bpl;
-- 
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 13/16] s5p-jpeg: Allow for wider JPEG subsampling scope for Exynos4x12 encoder

2013-11-19 Thread Jacek Anaszewski
Exynos4x12 supports wider scope of subsampling modes than
S5PC210. Adjust corresponding mask accordingly.

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 |3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/media/platform/s5p-jpeg/jpeg-core.c 
b/drivers/media/platform/s5p-jpeg/jpeg-core.c
index 15b2dea..319be0c 100644
--- a/drivers/media/platform/s5p-jpeg/jpeg-core.c
+++ b/drivers/media/platform/s5p-jpeg/jpeg-core.c
@@ -1210,7 +1210,8 @@ static int s5p_jpeg_controls_create(struct s5p_jpeg_ctx 
*ctx)
v4l2_ctrl_new_std(ctx-ctrl_handler, s5p_jpeg_ctrl_ops,
  V4L2_CID_JPEG_RESTART_INTERVAL,
  0, 3, 0x, 0);
-   mask = ~0x06; /* 422, 420 */
+   if (ctx-jpeg-variant-version == SJPEG_S5P)
+   mask = ~0x06; /* 422, 420 */
}
 
ctrl = v4l2_ctrl_new_std_menu(ctx-ctrl_handler, s5p_jpeg_ctrl_ops,
-- 
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 07/16] s5p-jpeg: Fix lack of spin_lock protection

2013-11-19 Thread Jacek Anaszewski
s5p_jpeg_device_run and s5p_jpeg_runtime_resume callbacks should
have spin_lock protection as they alter device registers.

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 |   11 ++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/drivers/media/platform/s5p-jpeg/jpeg-core.c 
b/drivers/media/platform/s5p-jpeg/jpeg-core.c
index 328bb8b..650c4d3 100644
--- a/drivers/media/platform/s5p-jpeg/jpeg-core.c
+++ b/drivers/media/platform/s5p-jpeg/jpeg-core.c
@@ -930,7 +930,9 @@ static void s5p_jpeg_device_run(void *priv)
struct s5p_jpeg_ctx *ctx = priv;
struct s5p_jpeg *jpeg = ctx-jpeg;
struct vb2_buffer *src_buf, *dst_buf;
-   unsigned long src_addr, dst_addr;
+   unsigned long src_addr, dst_addr, flags;
+
+   spin_lock_irqsave(ctx-jpeg-slock, flags);
 
src_buf = v4l2_m2m_next_src_buf(ctx-fh.m2m_ctx);
dst_buf = v4l2_m2m_next_dst_buf(ctx-fh.m2m_ctx);
@@ -998,6 +1000,8 @@ static void s5p_jpeg_device_run(void *priv)
}
 
jpeg_start(jpeg-regs);
+
+   spin_unlock_irqrestore(ctx-jpeg-slock, flags);
 }
 
 static int s5p_jpeg_job_ready(void *priv)
@@ -1418,9 +1422,12 @@ static int s5p_jpeg_runtime_suspend(struct device *dev)
 static int s5p_jpeg_runtime_resume(struct device *dev)
 {
struct s5p_jpeg *jpeg = dev_get_drvdata(dev);
+   unsigned long flags;
 
clk_prepare_enable(jpeg-clk);
 
+   spin_lock_irqsave(jpeg-slock, flags);
+
/*
 * JPEG IP allows storing two Huffman tables for each component
 * We fill table 0 for each component
@@ -1430,6 +1437,8 @@ static int s5p_jpeg_runtime_resume(struct device *dev)
s5p_jpeg_set_hactbl(jpeg-regs);
s5p_jpeg_set_hactblg(jpeg-regs);
 
+   spin_unlock_irqrestore(jpeg-slock, flags);
+
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 06/16] s5p-jpeg: Fix clock resource management

2013-11-19 Thread Jacek Anaszewski
Standard suspend/resume path is called after runtime resume
of the given device, so suspend/resume callbacks must do all
clock management done also by runtime pm to allow for proper
power domain shutdown. Moreover, JPEG clock is enabled from
probe function but is is not necessary. This patch also moves
control of jpeg clock to runtime_pm callbacks.

Signed-off-by: Marek Szyprowski m.szyprow...@samsung.com
Signed-off-by: Seung-Woo Kim sw0312@samsung.com
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 |   52 ++-
 1 file changed, 36 insertions(+), 16 deletions(-)

diff --git a/drivers/media/platform/s5p-jpeg/jpeg-core.c 
b/drivers/media/platform/s5p-jpeg/jpeg-core.c
index 32033e7..328bb8b 100644
--- a/drivers/media/platform/s5p-jpeg/jpeg-core.c
+++ b/drivers/media/platform/s5p-jpeg/jpeg-core.c
@@ -1250,29 +1250,28 @@ static int s5p_jpeg_probe(struct platform_device *pdev)
if (IS_ERR(jpeg-regs))
return PTR_ERR(jpeg-regs);
 
+   /* clocks */
+   jpeg-clk = clk_get(pdev-dev, jpeg);
+   if (IS_ERR(jpeg-clk)) {
+   dev_err(pdev-dev, cannot get clock\n);
+   ret = PTR_ERR(jpeg-clk);
+   return ret;
+   }
+   dev_dbg(pdev-dev, clock source %p\n, jpeg-clk);
+
/* interrupt service routine registration */
jpeg-irq = ret = platform_get_irq(pdev, 0);
if (ret  0) {
dev_err(pdev-dev, cannot find IRQ\n);
-   return ret;
+   goto clk_get_rollback;
}
 
ret = devm_request_irq(pdev-dev, jpeg-irq, s5p_jpeg_irq, 0,
dev_name(pdev-dev), jpeg);
if (ret) {
dev_err(pdev-dev, cannot claim IRQ %d\n, jpeg-irq);
-   return ret;
-   }
-
-   /* clocks */
-   jpeg-clk = clk_get(pdev-dev, jpeg);
-   if (IS_ERR(jpeg-clk)) {
-   dev_err(pdev-dev, cannot get clock\n);
-   ret = PTR_ERR(jpeg-clk);
-   return ret;
+   goto clk_get_rollback;
}
-   dev_dbg(pdev-dev, clock source %p\n, jpeg-clk);
-   clk_prepare_enable(jpeg-clk);
 
/* v4l2 device */
ret = v4l2_device_register(pdev-dev, jpeg-v4l2_dev);
@@ -1380,7 +1379,6 @@ device_register_rollback:
v4l2_device_unregister(jpeg-v4l2_dev);
 
 clk_get_rollback:
-   clk_disable_unprepare(jpeg-clk);
clk_put(jpeg-clk);
 
return ret;
@@ -1400,7 +1398,9 @@ static int s5p_jpeg_remove(struct platform_device *pdev)
v4l2_m2m_release(jpeg-m2m_dev);
v4l2_device_unregister(jpeg-v4l2_dev);
 
-   clk_disable_unprepare(jpeg-clk);
+   if (!pm_runtime_status_suspended(pdev-dev))
+   clk_disable_unprepare(jpeg-clk);
+
clk_put(jpeg-clk);
 
return 0;
@@ -1408,6 +1408,10 @@ static int s5p_jpeg_remove(struct platform_device *pdev)
 
 static int s5p_jpeg_runtime_suspend(struct device *dev)
 {
+   struct s5p_jpeg *jpeg = dev_get_drvdata(dev);
+
+   clk_disable_unprepare(jpeg-clk);
+
return 0;
 }
 
@@ -1415,6 +1419,8 @@ static int s5p_jpeg_runtime_resume(struct device *dev)
 {
struct s5p_jpeg *jpeg = dev_get_drvdata(dev);
 
+   clk_prepare_enable(jpeg-clk);
+
/*
 * JPEG IP allows storing two Huffman tables for each component
 * We fill table 0 for each component
@@ -1427,9 +1433,23 @@ static int s5p_jpeg_runtime_resume(struct device *dev)
return 0;
 }
 
+static int s5p_jpeg_suspend(struct device *dev)
+{
+   s5p_jpeg_runtime_suspend(dev);
+
+   return 0;
+}
+
+static int s5p_jpeg_resume(struct device *dev)
+{
+   s5p_jpeg_runtime_resume(dev);
+
+   return 0;
+}
+
 static const struct dev_pm_ops s5p_jpeg_pm_ops = {
-   .runtime_suspend = s5p_jpeg_runtime_suspend,
-   .runtime_resume  = s5p_jpeg_runtime_resume,
+   SET_SYSTEM_SLEEP_PM_OPS(s5p_jpeg_suspend, s5p_jpeg_resume)
+   SET_RUNTIME_PM_OPS(s5p_jpeg_runtime_suspend, s5p_jpeg_runtime_resume, 
NULL)
 };
 
 #ifdef CONFIG_OF
-- 
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 14/16] s5p-jpeg: Synchronize V4L2_CID_JPEG_CHROMA_SUBSAMPLING control value

2013-11-19 Thread Jacek Anaszewski
When output queue fourcc is set to any flavour of YUV,
the V4L2_CID_JPEG_CHROMA_SUBSAMPLING control value as
well as its in-driver cached counterpart have to be
updated with the subsampling property of the format
so as to be able to provide correct information to the
user space and preclude setting an illegal subsampling
mode for Exynos4x12 encoder.

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 |5 +
 1 file changed, 5 insertions(+)

diff --git a/drivers/media/platform/s5p-jpeg/jpeg-core.c 
b/drivers/media/platform/s5p-jpeg/jpeg-core.c
index 319be0c..d4db612 100644
--- a/drivers/media/platform/s5p-jpeg/jpeg-core.c
+++ b/drivers/media/platform/s5p-jpeg/jpeg-core.c
@@ -1038,6 +1038,7 @@ static int s5p_jpeg_try_fmt_vid_out(struct file *file, 
void *priv,
 {
struct s5p_jpeg_ctx *ctx = fh_to_ctx(priv);
struct s5p_jpeg_fmt *fmt;
+   struct v4l2_control ctrl_subs;
 
fmt = s5p_jpeg_find_format(ctx, f-fmt.pix.pixelformat,
FMT_TYPE_OUTPUT);
@@ -1048,6 +1049,10 @@ static int s5p_jpeg_try_fmt_vid_out(struct file *file, 
void *priv,
return -EINVAL;
}
 
+   ctrl_subs.id = V4L2_CID_JPEG_CHROMA_SUBSAMPLING;
+   ctrl_subs.value = fmt-subsampling;
+   v4l2_s_ctrl(priv, ctx-ctrl_handler, ctrl_subs);
+
return vidioc_try_fmt(f, fmt, ctx, FMT_TYPE_OUTPUT);
 }
 
-- 
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 09/16] s5p-jpeg: Split jpeg-hw.h to jpeg-hw-s5p.c and jpeg-hw-s5p.c

2013-11-19 Thread Jacek Anaszewski
Move function definitions from jpeg-hw.h to jpeg-hw-s5p.c
and put function declarations in the jpeg-hw-s5p.h.

Signed-off-by: Jacek Anaszewski j.anaszew...@samsung.com
Signed-off-by: Kyungmin Park kyungmin.p...@samsung.com
---
 drivers/media/platform/s5p-jpeg/Makefile   |2 +-
 drivers/media/platform/s5p-jpeg/jpeg-core.c|2 +-
 drivers/media/platform/s5p-jpeg/jpeg-core.h|5 ++
 .../platform/s5p-jpeg/{jpeg-hw.h = jpeg-hw-s5p.c} |   82 
 drivers/media/platform/s5p-jpeg/jpeg-hw-s5p.h  |   63 +++
 5 files changed, 104 insertions(+), 50 deletions(-)
 rename drivers/media/platform/s5p-jpeg/{jpeg-hw.h = jpeg-hw-s5p.c} (71%)
 create mode 100644 drivers/media/platform/s5p-jpeg/jpeg-hw-s5p.h

diff --git a/drivers/media/platform/s5p-jpeg/Makefile 
b/drivers/media/platform/s5p-jpeg/Makefile
index d18cb5e..faf6398 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
+s5p-jpeg-objs := jpeg-core.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 b82e3fa..4e874ad 100644
--- a/drivers/media/platform/s5p-jpeg/jpeg-core.c
+++ b/drivers/media/platform/s5p-jpeg/jpeg-core.c
@@ -29,7 +29,7 @@
 #include media/videobuf2-dma-contig.h
 
 #include jpeg-core.h
-#include jpeg-hw.h
+#include jpeg-hw-s5p.h
 
 static struct s5p_jpeg_fmt formats_enc[] = {
{
diff --git a/drivers/media/platform/s5p-jpeg/jpeg-core.h 
b/drivers/media/platform/s5p-jpeg/jpeg-core.h
index 4a4776b..7baadf3 100644
--- a/drivers/media/platform/s5p-jpeg/jpeg-core.h
+++ b/drivers/media/platform/s5p-jpeg/jpeg-core.h
@@ -42,10 +42,15 @@
 #define EOI0xd9
 #define DHP0xde
 
+#define S5P_JPEG_ENCODE0
+#define S5P_JPEG_DECODE1
+
 /* Flags that indicate a format can be used for capture/output */
 #define MEM2MEM_CAPTURE(1  0)
 #define MEM2MEM_OUTPUT (1  1)
 
+
+
 /**
  * struct s5p_jpeg - JPEG IP abstraction
  * @lock:  the mutex protecting this structure
diff --git a/drivers/media/platform/s5p-jpeg/jpeg-hw.h 
b/drivers/media/platform/s5p-jpeg/jpeg-hw-s5p.c
similarity index 71%
rename from drivers/media/platform/s5p-jpeg/jpeg-hw.h
rename to drivers/media/platform/s5p-jpeg/jpeg-hw-s5p.c
index b47e887..6a1164c 100644
--- a/drivers/media/platform/s5p-jpeg/jpeg-hw.h
+++ b/drivers/media/platform/s5p-jpeg/jpeg-hw-s5p.c
@@ -9,27 +9,15 @@
  * it under the terms of the GNU General Public License version 2 as
  * published by the Free Software Foundation.
  */
-#ifndef JPEG_HW_H_
-#define JPEG_HW_H_
 
 #include linux/io.h
 #include linux/videodev2.h
 
-#include jpeg-hw.h
+#include jpeg-core.h
 #include jpeg-regs.h
+#include jpeg-hw-s5p.h
 
-#define S5P_JPEG_MIN_WIDTH 32
-#define S5P_JPEG_MIN_HEIGHT32
-#define S5P_JPEG_MAX_WIDTH 8192
-#define S5P_JPEG_MAX_HEIGHT8192
-#define S5P_JPEG_ENCODE0
-#define S5P_JPEG_DECODE1
-#define S5P_JPEG_RAW_IN_5650
-#define S5P_JPEG_RAW_IN_4221
-#define S5P_JPEG_RAW_OUT_422   0
-#define S5P_JPEG_RAW_OUT_420   1
-
-static inline void jpeg_reset(void __iomem *regs)
+void jpeg_reset(void __iomem *regs)
 {
unsigned long reg;
 
@@ -42,12 +30,12 @@ static inline void jpeg_reset(void __iomem *regs)
}
 }
 
-static inline void jpeg_poweron(void __iomem *regs)
+void jpeg_poweron(void __iomem *regs)
 {
writel(S5P_POWER_ON, regs + S5P_JPGCLKCON);
 }
 
-static inline void jpeg_input_raw_mode(void __iomem *regs, unsigned long mode)
+void jpeg_input_raw_mode(void __iomem *regs, unsigned long mode)
 {
unsigned long reg, m;
 
@@ -63,7 +51,7 @@ static inline void jpeg_input_raw_mode(void __iomem *regs, 
unsigned long mode)
writel(reg, regs + S5P_JPGCMOD);
 }
 
-static inline void jpeg_input_raw_y16(void __iomem *regs, bool y16)
+void jpeg_input_raw_y16(void __iomem *regs, bool y16)
 {
unsigned long reg;
 
@@ -75,7 +63,7 @@ static inline void jpeg_input_raw_y16(void __iomem *regs, 
bool y16)
writel(reg, regs + S5P_JPGCMOD);
 }
 
-static inline void jpeg_proc_mode(void __iomem *regs, unsigned long mode)
+void jpeg_proc_mode(void __iomem *regs, unsigned long mode)
 {
unsigned long reg, m;
 
@@ -90,7 +78,7 @@ static inline void jpeg_proc_mode(void __iomem *regs, 
unsigned long mode)
writel(reg, regs + S5P_JPGMOD);
 }
 
-static inline void jpeg_subsampling_mode(void __iomem *regs, unsigned int mode)
+void jpeg_subsampling_mode(void __iomem *regs, unsigned int mode)
 {
unsigned long reg, m;
 
@@ -105,12 +93,12 @@ static inline void jpeg_subsampling_mode(void __iomem 
*regs, unsigned int mode)
writel(reg, regs + S5P_JPGMOD

[PATCH 11/16] s5p-jpeg: Retrieve YCbCr subsampling field from the jpeg header

2013-11-19 Thread Jacek Anaszewski
Make s5p_jpeg_parse_hdr function capable of parsing
YCbCr subsampling field of a jpeg file header.
Store the parsed value in the context. The information
about source JPEG subsampling is required to make validation
of destination format possible, which must be conducted
for exynos4x12 device as the decoding process will not succeed
if the destination format is set to YUV with subsampling lower
than the one of the source JPEG image. With this knowledge
the driver can adjust the destination format appropriately.

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 |   35 ---
 1 file changed, 31 insertions(+), 4 deletions(-)

diff --git a/drivers/media/platform/s5p-jpeg/jpeg-core.c 
b/drivers/media/platform/s5p-jpeg/jpeg-core.c
index 68a82cc..e09b03a 100644
--- a/drivers/media/platform/s5p-jpeg/jpeg-core.c
+++ b/drivers/media/platform/s5p-jpeg/jpeg-core.c
@@ -624,10 +624,11 @@ static void skip(struct s5p_jpeg_buffer *buf, long len)
 }
 
 static bool s5p_jpeg_parse_hdr(struct s5p_jpeg_q_data *result,
-  unsigned long buffer, unsigned long size)
+  unsigned long buffer, unsigned long size,
+  struct s5p_jpeg_ctx *ctx)
 {
int c, components, notfound;
-   unsigned int height, width, word;
+   unsigned int height, width, word, subsampling = 0;
long length;
struct s5p_jpeg_buffer jpeg_buffer;
 
@@ -666,7 +667,15 @@ static bool s5p_jpeg_parse_hdr(struct s5p_jpeg_q_data 
*result,
break;
notfound = 0;
 
-   skip(jpeg_buffer, components * 3);
+   if (components == 1) {
+   subsampling = 0x33;
+   } else {
+   skip(jpeg_buffer, 1);
+   subsampling = get_byte(jpeg_buffer);
+   skip(jpeg_buffer, 1);
+   }
+
+   skip(jpeg_buffer, components * 2);
break;
 
/* skip payload-less markers */
@@ -688,6 +697,24 @@ static bool s5p_jpeg_parse_hdr(struct s5p_jpeg_q_data 
*result,
result-w = width;
result-h = height;
result-size = components;
+
+   switch (subsampling) {
+   case 0x11:
+   ctx-subsampling = V4L2_JPEG_CHROMA_SUBSAMPLING_444;
+   break;
+   case 0x21:
+   ctx-subsampling = V4L2_JPEG_CHROMA_SUBSAMPLING_422;
+   break;
+   case 0x22:
+   ctx-subsampling = V4L2_JPEG_CHROMA_SUBSAMPLING_420;
+   break;
+   case 0x33:
+   ctx-subsampling = V4L2_JPEG_CHROMA_SUBSAMPLING_GRAY;
+   break;
+   default:
+   return false;
+   }
+
return !notfound;
 }
 
@@ -1426,7 +1453,7 @@ static void s5p_jpeg_buf_queue(struct vb2_buffer *vb)
ctx-hdr_parsed = s5p_jpeg_parse_hdr(tmp,
 (unsigned long)vb2_plane_vaddr(vb, 0),
 min((unsigned long)ctx-out_q.size,
-vb2_get_plane_payload(vb, 0)));
+vb2_get_plane_payload(vb, 0)), ctx);
if (!ctx-hdr_parsed) {
vb2_buffer_done(vb, VB2_BUF_STATE_ERROR);
return;
-- 
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 10/16] s5p-jpeg: Add hardware API for the exynos4x12 JPEG codec.

2013-11-19 Thread Jacek Anaszewski
Signed-off-by: Jacek Anaszewski j.anaszew...@samsung.com
Signed-off-by: Kyungmin Park kyungmin.p...@samsung.com
---
 drivers/media/platform/s5p-jpeg/Makefile |2 +-
 drivers/media/platform/s5p-jpeg/jpeg-core.c  |  620 +++---
 drivers/media/platform/s5p-jpeg/jpeg-core.h  |   72 ++-
 drivers/media/platform/s5p-jpeg/jpeg-hw-exynos.c |  293 ++
 drivers/media/platform/s5p-jpeg/jpeg-hw-exynos.h |   44 ++
 drivers/media/platform/s5p-jpeg/jpeg-regs.h  |  215 +++-
 6 files changed, 1152 insertions(+), 94 deletions(-)
 create mode 100644 drivers/media/platform/s5p-jpeg/jpeg-hw-exynos.c
 create mode 100644 drivers/media/platform/s5p-jpeg/jpeg-hw-exynos.h

diff --git a/drivers/media/platform/s5p-jpeg/Makefile 
b/drivers/media/platform/s5p-jpeg/Makefile
index faf6398..f981dff 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-s5p.o
+s5p-jpeg-objs := jpeg-core.o jpeg-hw-exynos.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 4e874ad..68a82cc 100644
--- a/drivers/media/platform/s5p-jpeg/jpeg-core.c
+++ b/drivers/media/platform/s5p-jpeg/jpeg-core.c
@@ -1,9 +1,10 @@
 /* linux/drivers/media/platform/s5p-jpeg/jpeg-core.c
  *
- * Copyright (c) 2011 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2011-2013 Samsung Electronics Co., Ltd.
  * http://www.samsung.com
  *
  * Author: Andrzej Pietrasiewicz andrze...@samsung.com
+ * 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
@@ -30,58 +31,212 @@
 
 #include jpeg-core.h
 #include jpeg-hw-s5p.h
+#include jpeg-hw-exynos.h
+#include jpeg-regs.h
 
-static struct s5p_jpeg_fmt formats_enc[] = {
+static struct s5p_jpeg_fmt sjpeg_formats[] = {
{
.name   = JPEG JFIF,
.fourcc = V4L2_PIX_FMT_JPEG,
+   .flags  = SJPEG_FMT_FLAG_ENC_CAPTURE |
+ SJPEG_FMT_FLAG_DEC_OUTPUT |
+ SJPEG_FMT_FLAG_S5P |
+ SJPEG_FMT_FLAG_EXYNOS,
+   },
+   {
+   .name   = YUV 4:2:2 packed, YCbYCr,
+   .fourcc = V4L2_PIX_FMT_YUYV,
+   .depth  = 16,
.colplanes  = 1,
-   .types  = MEM2MEM_CAPTURE,
+   .h_align= 4,
+   .v_align= 3,
+   .flags  = SJPEG_FMT_FLAG_ENC_OUTPUT |
+ SJPEG_FMT_FLAG_DEC_CAPTURE |
+ SJPEG_FMT_FLAG_S5P |
+ SJPEG_FMT_NON_RGB,
+   .subsampling= V4L2_JPEG_CHROMA_SUBSAMPLING_422,
},
{
.name   = YUV 4:2:2 packed, YCbYCr,
.fourcc = V4L2_PIX_FMT_YUYV,
.depth  = 16,
.colplanes  = 1,
-   .types  = MEM2MEM_OUTPUT,
+   .h_align= 1,
+   .v_align= 0,
+   .flags  = SJPEG_FMT_FLAG_ENC_OUTPUT |
+ SJPEG_FMT_FLAG_DEC_CAPTURE |
+ SJPEG_FMT_FLAG_EXYNOS |
+ SJPEG_FMT_NON_RGB,
+   .subsampling= V4L2_JPEG_CHROMA_SUBSAMPLING_422,
+   },
+   {
+   .name   = YUV 4:2:2 packed, YCrYCb,
+   .fourcc = V4L2_PIX_FMT_YVYU,
+   .depth  = 16,
+   .colplanes  = 1,
+   .h_align= 1,
+   .v_align= 0,
+   .flags  = SJPEG_FMT_FLAG_ENC_OUTPUT |
+ SJPEG_FMT_FLAG_DEC_CAPTURE |
+ SJPEG_FMT_FLAG_EXYNOS |
+ SJPEG_FMT_NON_RGB,
+   .subsampling= V4L2_JPEG_CHROMA_SUBSAMPLING_422,
},
{
.name   = RGB565,
.fourcc = V4L2_PIX_FMT_RGB565,
.depth  = 16,
.colplanes  = 1,
-   .types  = MEM2MEM_OUTPUT,
+   .h_align= 0,
+   .v_align= 0,
+   .flags  = SJPEG_FMT_FLAG_ENC_OUTPUT |
+ SJPEG_FMT_FLAG_DEC_CAPTURE |
+ SJPEG_FMT_FLAG_EXYNOS |
+ SJPEG_FMT_RGB,
+   .subsampling= V4L2_JPEG_CHROMA_SUBSAMPLING_444,
+   },
+   {
+   .name   = RGB565,
+   .fourcc = V4L2_PIX_FMT_RGB565,
+   .depth

[PATCH 16/16] s5p-jpeg: Adjust g_volatile_ctrl callback to Exynos4x12 needs

2013-11-19 Thread Jacek Anaszewski
Whereas S5PC210 device produces decoded JPEG subsampling
values that map on V4L2_JPEG_CHROMA_SUBSAMPLNG values,
the Exynos4x12 device doesn't. This patch adds helper
function decoded_subsampling_to_v4l2, which performs
HW - V4L2 translation.

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 |   36 ++-
 1 file changed, 30 insertions(+), 6 deletions(-)

diff --git a/drivers/media/platform/s5p-jpeg/jpeg-core.c 
b/drivers/media/platform/s5p-jpeg/jpeg-core.c
index 3605470..90d2f69 100644
--- a/drivers/media/platform/s5p-jpeg/jpeg-core.c
+++ b/drivers/media/platform/s5p-jpeg/jpeg-core.c
@@ -358,6 +358,13 @@ static const unsigned char hactblg0[162] = {
0xf9, 0xfa
 };
 
+static int exynos4x12_decoded_subsampling[] = {
+   V4L2_JPEG_CHROMA_SUBSAMPLING_GRAY,
+   V4L2_JPEG_CHROMA_SUBSAMPLING_444,
+   V4L2_JPEG_CHROMA_SUBSAMPLING_422,
+   V4L2_JPEG_CHROMA_SUBSAMPLING_420,
+};
+
 static inline struct s5p_jpeg_ctx *ctrl_to_ctx(struct v4l2_ctrl *c)
 {
return container_of(c-handler, struct s5p_jpeg_ctx, ctrl_handler);
@@ -368,6 +375,28 @@ static inline struct s5p_jpeg_ctx *fh_to_ctx(struct 
v4l2_fh *fh)
return container_of(fh, struct s5p_jpeg_ctx, fh);
 }
 
+static inline int decoded_subsampling_to_v4l2(struct s5p_jpeg_ctx *ctx)
+{
+   int subsampling;
+
+   WARN_ON(ctx-subsampling  3);
+
+   if (ctx-jpeg-variant-version == SJPEG_S5P) {
+   if (ctx-subsampling  2)
+   subsampling = V4L2_JPEG_CHROMA_SUBSAMPLING_GRAY;
+   else
+   subsampling = ctx-subsampling;
+   } else {
+   if (ctx-subsampling  2)
+   subsampling = V4L2_JPEG_CHROMA_SUBSAMPLING_420;
+   else
+   subsampling =
+   exynos4x12_decoded_subsampling[ctx-subsampling];
+   }
+
+   return subsampling;
+}
+
 static inline void s5p_jpeg_set_qtbl(void __iomem *regs,
 const unsigned char *qtbl,
 unsigned long tab, int len)
@@ -1159,12 +1188,7 @@ static int s5p_jpeg_g_volatile_ctrl(struct v4l2_ctrl 
*ctrl)
switch (ctrl-id) {
case V4L2_CID_JPEG_CHROMA_SUBSAMPLING:
spin_lock_irqsave(jpeg-slock, flags);
-
-   WARN_ON(ctx-subsampling  S5P_SUBSAMPLING_MODE_GRAY);
-   if (ctx-subsampling  2)
-   ctrl-val = V4L2_JPEG_CHROMA_SUBSAMPLING_GRAY;
-   else
-   ctrl-val = ctx-subsampling;
+   ctrl-val = decoded_subsampling_to_v4l2(ctx);
spin_unlock_irqrestore(jpeg-slock, flags);
break;
}
-- 
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 15/16] s5p-jpeg: Ensure setting correct value of the chroma subsampling control

2013-11-19 Thread Jacek Anaszewski
Exynos4x12 has limitations regarding setting chroma subsampling
of an output JPEG image. It cannot be lower than the subsampling
of the raw source image. Also in case of V4L2_JPEG_CHROMA_SUBSAMPLING_GRAY
option the source image fourcc has to be V4L2_PIX_FMT_GREY.
This patch adds mechanism that prevents setting invalid value
of the V4L2_CID_JPEG_CHROMA_SUBSAMPLING control.

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 |   27 +--
 1 file changed, 25 insertions(+), 2 deletions(-)

diff --git a/drivers/media/platform/s5p-jpeg/jpeg-core.c 
b/drivers/media/platform/s5p-jpeg/jpeg-core.c
index d4db612..3605470 100644
--- a/drivers/media/platform/s5p-jpeg/jpeg-core.c
+++ b/drivers/media/platform/s5p-jpeg/jpeg-core.c
@@ -1176,6 +1176,7 @@ static int s5p_jpeg_s_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);
 
@@ -1187,12 +1188,34 @@ static int s5p_jpeg_s_ctrl(struct v4l2_ctrl *ctrl)
ctx-restart_interval = ctrl-val;
break;
case V4L2_CID_JPEG_CHROMA_SUBSAMPLING:
-   ctx-subsampling = ctrl-val;
+   if (ctx-jpeg-variant-version == SJPEG_S5P) {
+   ctx-subsampling = ctrl-val;
+   break;
+   }
+   /*
+* 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)
+   ctx-subsampling = ctx-out_q.fmt-subsampling;
+   else
+   ctx-subsampling = ctrl-val;
break;
}
 
+error_free:
spin_unlock_irqrestore(ctx-jpeg-slock, flags);
-   return 0;
+   return ret;
 }
 
 static const struct v4l2_ctrl_ops s5p_jpeg_ctrl_ops = {
-- 
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 04/16] s5p-jpeg: Remove superfluous call to the jpeg_bound_align_image function

2013-11-19 Thread Jacek Anaszewski
Aligning capture queue image dimensions while enqueuing output
queue doesn't make a sense as the S_FMT ioctl might have not
been called for the capture queue until that moment, whereas
it is required to know capture format as the type of alignment
heavily depends on it.

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 |7 ---
 1 file changed, 7 deletions(-)

diff --git a/drivers/media/platform/s5p-jpeg/jpeg-core.c 
b/drivers/media/platform/s5p-jpeg/jpeg-core.c
index a1366f0..a6ec8c6 100644
--- a/drivers/media/platform/s5p-jpeg/jpeg-core.c
+++ b/drivers/media/platform/s5p-jpeg/jpeg-core.c
@@ -1089,13 +1089,6 @@ static void s5p_jpeg_buf_queue(struct vb2_buffer *vb)
q_data = ctx-cap_q;
q_data-w = tmp.w;
q_data-h = tmp.h;
-
-   jpeg_bound_align_image(q_data-w, S5P_JPEG_MIN_WIDTH,
-  S5P_JPEG_MAX_WIDTH, q_data-fmt-h_align,
-  q_data-h, S5P_JPEG_MIN_HEIGHT,
-  S5P_JPEG_MAX_HEIGHT, q_data-fmt-v_align
- );
-   q_data-size = q_data-w * q_data-h * q_data-fmt-depth  3;
}
 
v4l2_m2m_buf_queue(ctx-fh.m2m_ctx, vb);
-- 
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 05/16] s5p-jpeg: Rename functions specific to the S5PC210 SoC accordingly

2013-11-19 Thread Jacek Anaszewski
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 |   58 ---
 1 file changed, 34 insertions(+), 24 deletions(-)

diff --git a/drivers/media/platform/s5p-jpeg/jpeg-core.c 
b/drivers/media/platform/s5p-jpeg/jpeg-core.c
index a6ec8c6..32033e7 100644
--- a/drivers/media/platform/s5p-jpeg/jpeg-core.c
+++ b/drivers/media/platform/s5p-jpeg/jpeg-core.c
@@ -213,8 +213,9 @@ static inline struct s5p_jpeg_ctx *fh_to_ctx(struct v4l2_fh 
*fh)
return container_of(fh, struct s5p_jpeg_ctx, fh);
 }
 
-static inline void jpeg_set_qtbl(void __iomem *regs, const unsigned char *qtbl,
-  unsigned long tab, int len)
+static inline void s5p_jpeg_set_qtbl(void __iomem *regs,
+const unsigned char *qtbl,
+unsigned long tab, int len)
 {
int i;
 
@@ -222,22 +223,25 @@ static inline void jpeg_set_qtbl(void __iomem *regs, 
const unsigned char *qtbl,
writel((unsigned int)qtbl[i], regs + tab + (i * 0x04));
 }
 
-static inline void jpeg_set_qtbl_lum(void __iomem *regs, int quality)
+static inline void s5p_jpeg_set_qtbl_lum(void __iomem *regs, int quality)
 {
/* this driver fills quantisation table 0 with data for luma */
-   jpeg_set_qtbl(regs, qtbl_luminance[quality], S5P_JPG_QTBL_CONTENT(0),
- ARRAY_SIZE(qtbl_luminance[quality]));
+   s5p_jpeg_set_qtbl(regs, qtbl_luminance[quality],
+ S5P_JPG_QTBL_CONTENT(0),
+ ARRAY_SIZE(qtbl_luminance[quality]));
 }
 
-static inline void jpeg_set_qtbl_chr(void __iomem *regs, int quality)
+static inline void s5p_jpeg_set_qtbl_chr(void __iomem *regs, int quality)
 {
/* this driver fills quantisation table 1 with data for chroma */
-   jpeg_set_qtbl(regs, qtbl_chrominance[quality], S5P_JPG_QTBL_CONTENT(1),
- ARRAY_SIZE(qtbl_chrominance[quality]));
+   s5p_jpeg_set_qtbl(regs, qtbl_chrominance[quality],
+ S5P_JPG_QTBL_CONTENT(1),
+ ARRAY_SIZE(qtbl_chrominance[quality]));
 }
 
-static inline void jpeg_set_htbl(void __iomem *regs, const unsigned char *htbl,
-  unsigned long tab, int len)
+static inline void s5p_jpeg_set_htbl(void __iomem *regs,
+const unsigned char *htbl,
+unsigned long tab, int len)
 {
int i;
 
@@ -245,28 +249,32 @@ static inline void jpeg_set_htbl(void __iomem *regs, 
const unsigned char *htbl,
writel((unsigned int)htbl[i], regs + tab + (i * 0x04));
 }
 
-static inline void jpeg_set_hdctbl(void __iomem *regs)
+static inline void s5p_jpeg_set_hdctbl(void __iomem *regs)
 {
/* this driver fills table 0 for this component */
-   jpeg_set_htbl(regs, hdctbl0, S5P_JPG_HDCTBL(0), ARRAY_SIZE(hdctbl0));
+   s5p_jpeg_set_htbl(regs, hdctbl0, S5P_JPG_HDCTBL(0),
+   ARRAY_SIZE(hdctbl0));
 }
 
-static inline void jpeg_set_hdctblg(void __iomem *regs)
+static inline void s5p_jpeg_set_hdctblg(void __iomem *regs)
 {
/* this driver fills table 0 for this component */
-   jpeg_set_htbl(regs, hdctblg0, S5P_JPG_HDCTBLG(0), ARRAY_SIZE(hdctblg0));
+   s5p_jpeg_set_htbl(regs, hdctblg0, S5P_JPG_HDCTBLG(0),
+   ARRAY_SIZE(hdctblg0));
 }
 
-static inline void jpeg_set_hactbl(void __iomem *regs)
+static inline void s5p_jpeg_set_hactbl(void __iomem *regs)
 {
/* this driver fills table 0 for this component */
-   jpeg_set_htbl(regs, hactbl0, S5P_JPG_HACTBL(0), ARRAY_SIZE(hactbl0));
+   s5p_jpeg_set_htbl(regs, hactbl0, S5P_JPG_HACTBL(0),
+   ARRAY_SIZE(hactbl0));
 }
 
-static inline void jpeg_set_hactblg(void __iomem *regs)
+static inline void s5p_jpeg_set_hactblg(void __iomem *regs)
 {
/* this driver fills table 0 for this component */
-   jpeg_set_htbl(regs, hactblg0, S5P_JPG_HACTBLG(0), ARRAY_SIZE(hactblg0));
+   s5p_jpeg_set_htbl(regs, hactblg0, S5P_JPG_HACTBLG(0),
+   ARRAY_SIZE(hactblg0));
 }
 
 /*
@@ -962,8 +970,8 @@ static void s5p_jpeg_device_run(void *priv)
 * JPEG IP allows storing 4 quantization tables
 * We fill table 0 for luma and table 1 for chroma
 */
-   jpeg_set_qtbl_lum(jpeg-regs, ctx-compr_quality);
-   jpeg_set_qtbl_chr(jpeg-regs, ctx-compr_quality);
+   s5p_jpeg_set_qtbl_lum(jpeg-regs, ctx-compr_quality);
+   s5p_jpeg_set_qtbl_chr(jpeg-regs, ctx-compr_quality);
/* use table 0 for Y */
jpeg_qtbl(jpeg-regs, 1, 0);
/* use table 1 for Cb and Cr*/
@@ -1406,14 +1414,16 @@ static int

Re: [PATCH 14/16] s5p-jpeg: Synchronize V4L2_CID_JPEG_CHROMA_SUBSAMPLING control value

2013-11-20 Thread Jacek Anaszewski

On 11/19/2013 03:46 PM, Hans Verkuil wrote:

On 11/19/2013 03:27 PM, Jacek Anaszewski wrote:

When output queue fourcc is set to any flavour of YUV,
the V4L2_CID_JPEG_CHROMA_SUBSAMPLING control value as
well as its in-driver cached counterpart have to be
updated with the subsampling property of the format
so as to be able to provide correct information to the
user space and preclude setting an illegal subsampling
mode for Exynos4x12 encoder.

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 |5 +
  1 file changed, 5 insertions(+)

diff --git a/drivers/media/platform/s5p-jpeg/jpeg-core.c 
b/drivers/media/platform/s5p-jpeg/jpeg-core.c
index 319be0c..d4db612 100644
--- a/drivers/media/platform/s5p-jpeg/jpeg-core.c
+++ b/drivers/media/platform/s5p-jpeg/jpeg-core.c
@@ -1038,6 +1038,7 @@ static int s5p_jpeg_try_fmt_vid_out(struct file *file, 
void *priv,
  {
struct s5p_jpeg_ctx *ctx = fh_to_ctx(priv);
struct s5p_jpeg_fmt *fmt;
+   struct v4l2_control ctrl_subs;

fmt = s5p_jpeg_find_format(ctx, f-fmt.pix.pixelformat,
FMT_TYPE_OUTPUT);
@@ -1048,6 +1049,10 @@ static int s5p_jpeg_try_fmt_vid_out(struct file *file, 
void *priv,
return -EINVAL;
}

+   ctrl_subs.id = V4L2_CID_JPEG_CHROMA_SUBSAMPLING;
+   ctrl_subs.value = fmt-subsampling;
+   v4l2_s_ctrl(priv, ctx-ctrl_handler, ctrl_subs);


TRY_FMT should never have side-effects, so this isn't the correct
way of implementing this.


I am aware of it, but I couldn't have found more suitable place
for implementing this. Below is the rationale standing behind
such an implementation:

  - Exynos4x12 device doesn't generate an eoc interrupt if the
subsampling property of an output queue format is lower than the
target jpeg subsampling (e.g. V4L2_PIX_FMT_YUYV [4:2:2 subsampling]
and JPEG 4:4:4)
  - It should be possible to inform the user space application that the
subsampling it wants to set is not supported with the current output
queue fourcc.
  - It is possible that after calling S_EXT_CTRLS the application
will call S_FMT on output queue with different fourcc which will
change the allowed scope of JPEG subsampling settings. Let's assume
the following flow of ioctls:
  - S_FMT V4L2_PIX_FMT_YUYV (4:2:2)
  - S_EXT_CTRLS V4L2_JPEG_CHROMA_SUBSAMPLING_422
  - S_FMT V4L2_PIX_FMT_YUV420
Now the JPEG subsampling set is illegal as 4:2:2 is lower than 4:2:0
(lower refers here to the lower number of luma samples assigned
to the single chroma sample). It is evident now that the change
of output queue fourcc entails change of the allowed scope of JPEG
subsampling settings. The way I implemented it reflects this
constraint precisely. We could go for adjusting the JPEG subsampling
e.g. in the device_run callback but the user space application
wouldn't know about it unless it called G_EXT_CTRLS ioctl after end
of conversion.

In view of the above it is clear that calling S_FMT in this case HAS
side effect no matter whether we take it into account in the driver
implementation or not. Nevertheless maybe there is some more elegant
way of handling this problem I am not aware of. I am open to any
interesting ideas.

Regards,
Jacek Anaszewski



Also, don't use v4l2_s_ctrl, instead use v4l2_ctrl_s_ctrl. The v4l2_s_ctrl
function is for core framework use only, not for use in drivers.

Regards,

Hans


+
return vidioc_try_fmt(f, fmt, ctx, FMT_TYPE_OUTPUT);
  }




--
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



--
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 00/16] Add support for Exynox4x12 to the s5p-jpeg driver

2013-11-25 Thread Jacek Anaszewski
This is the second version of the series that adds support for the
Exynos4x12 device to the s5p_jpeg driver along with accompanying
fixes. It contains following improvements
(Hans, Sylwester thanks for the review):

- moved adjusting chroma subsampling control value from s_ctrl
  to try_ctrl callback and switched from using v4l2_s_ctrl to
  v4l2_ctrl_s_ctrl
- avoided big switch statement in favour of lookup tables
  for adjusting capture queue fourcc during decoding phase
- avoided unnecessary displacement of clk_get call in the probe function
- renamed decoded_subsampling_to_v4l2 to s5p_jpeg_to_user_subsampling
- added freeing ctrl_handler when v4l2_ctrl_handler_setup fails
- calling s5p_jpeg_runtime_suspend and s5p_jpeg_runtime_resume
  only when pm_runtime_suspended returns false

Thanks,
Jacek Anaszewski

Jacek Anaszewski (16):
  s5p-jpeg: Reorder quantization tables
  s5p-jpeg: Fix output YUV 4:2:0 fourcc for decoder
  s5p-jpeg: Fix erroneous condition while validating bytesperline value
  s5p-jpeg: Remove superfluous call to the jpeg_bound_align_image
function
  s5p-jpeg: Rename functions specific to the S5PC210 SoC accordingly
  s5p-jpeg: Fix clock resource management
  s5p-jpeg: Fix lack of spin_lock protection
  s5p-jpeg: Synchronize cached controls with V4L2 core
  s5p-jpeg: Split jpeg-hw.h to jpeg-hw-s5p.c and jpeg-hw-s5p.c
  s5p-jpeg: Add hardware API for the exynos4x12 JPEG codec.
  s5p-jpeg: Retrieve YCbCr subsampling field from the jpeg header
  s5p-jpeg: Ensure correct capture format for Exynos4x12
  s5p-jpeg: Allow for wider JPEG subsampling scope for Exynos4x12
encoder
  s5p-jpeg: Synchronize V4L2_CID_JPEG_CHROMA_SUBSAMPLING control value
  s5p-jpeg: Ensure setting correct value of the chroma subsampling
control
  s5p-jpeg: Adjust g_volatile_ctrl callback to Exynos4x12 needs

 drivers/media/platform/s5p-jpeg/Makefile   |2 +-
 drivers/media/platform/s5p-jpeg/jpeg-core.c| 1089 
 drivers/media/platform/s5p-jpeg/jpeg-core.h|   75 +-
 drivers/media/platform/s5p-jpeg/jpeg-hw-exynos.c   |  293 ++
 drivers/media/platform/s5p-jpeg/jpeg-hw-exynos.h   |   44 +
 .../platform/s5p-jpeg/{jpeg-hw.h = jpeg-hw-s5p.c} |   82 +-
 drivers/media/platform/s5p-jpeg/jpeg-hw-s5p.h  |   63 ++
 drivers/media/platform/s5p-jpeg/jpeg-regs.h|  215 +++-
 8 files changed, 1614 insertions(+), 249 deletions(-)
 create mode 100644 drivers/media/platform/s5p-jpeg/jpeg-hw-exynos.c
 create mode 100644 drivers/media/platform/s5p-jpeg/jpeg-hw-exynos.h
 rename drivers/media/platform/s5p-jpeg/{jpeg-hw.h = jpeg-hw-s5p.c} (71%)
 create mode 100644 drivers/media/platform/s5p-jpeg/jpeg-hw-s5p.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 03/16] s5p-jpeg: Fix erroneous condition while validating bytesperline value

2013-11-25 Thread Jacek Anaszewski
The aim of the condition is ensuring that the bytesperline
value set by the user space application is proper for the
given format and adjusting it if isn't. As the depth value
of the format description entry is expressed in bits then
the bytesperline value needs to be divided, not multiplied,
by that value to get the number of bytes required to store
single line of image samples.

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 |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/media/platform/s5p-jpeg/jpeg-core.c 
b/drivers/media/platform/s5p-jpeg/jpeg-core.c
index 0f567c5..a1366f0 100644
--- a/drivers/media/platform/s5p-jpeg/jpeg-core.c
+++ b/drivers/media/platform/s5p-jpeg/jpeg-core.c
@@ -670,7 +670,7 @@ static int vidioc_try_fmt(struct v4l2_format *f, struct 
s5p_jpeg_fmt *fmt,
bpl = pix-width; /* planar */
 
if (fmt-colplanes == 1  /* packed */
-   (bpl  3) * fmt-depth  pix-width)
+   (bpl  3) / fmt-depth  pix-width)
bpl = (pix-width * fmt-depth)  3;
 
pix-bytesperline = bpl;
-- 
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 02/16] s5p-jpeg: Fix output YUV 4:2:0 fourcc for decoder

2013-11-25 Thread Jacek Anaszewski
Output samples during decoding phase for the YUV 4:2:0 format
are arranged in the manner compatible with 2-planar NV12,
not 3-planar YUV420 fourcc.

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 |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/media/platform/s5p-jpeg/jpeg-core.c 
b/drivers/media/platform/s5p-jpeg/jpeg-core.c
index 2234944..0f567c5 100644
--- a/drivers/media/platform/s5p-jpeg/jpeg-core.c
+++ b/drivers/media/platform/s5p-jpeg/jpeg-core.c
@@ -58,7 +58,7 @@ static struct s5p_jpeg_fmt formats_enc[] = {
 static struct s5p_jpeg_fmt formats_dec[] = {
{
.name   = YUV 4:2:0 planar, YCbCr,
-   .fourcc = V4L2_PIX_FMT_YUV420,
+   .fourcc = V4L2_PIX_FMT_NV12,
.depth  = 12,
.colplanes  = 3,
.h_align= 4,
-- 
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 04/16] s5p-jpeg: Remove superfluous call to the jpeg_bound_align_image function

2013-11-25 Thread Jacek Anaszewski
Aligning capture queue image dimensions while enqueuing output
queue doesn't make a sense as the S_FMT ioctl might have not
been called for the capture queue until that moment, whereas
it is required to know capture format as the type of alignment
heavily depends on it.

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 |7 ---
 1 file changed, 7 deletions(-)

diff --git a/drivers/media/platform/s5p-jpeg/jpeg-core.c 
b/drivers/media/platform/s5p-jpeg/jpeg-core.c
index a1366f0..a6ec8c6 100644
--- a/drivers/media/platform/s5p-jpeg/jpeg-core.c
+++ b/drivers/media/platform/s5p-jpeg/jpeg-core.c
@@ -1089,13 +1089,6 @@ static void s5p_jpeg_buf_queue(struct vb2_buffer *vb)
q_data = ctx-cap_q;
q_data-w = tmp.w;
q_data-h = tmp.h;
-
-   jpeg_bound_align_image(q_data-w, S5P_JPEG_MIN_WIDTH,
-  S5P_JPEG_MAX_WIDTH, q_data-fmt-h_align,
-  q_data-h, S5P_JPEG_MIN_HEIGHT,
-  S5P_JPEG_MAX_HEIGHT, q_data-fmt-v_align
- );
-   q_data-size = q_data-w * q_data-h * q_data-fmt-depth  3;
}
 
v4l2_m2m_buf_queue(ctx-fh.m2m_ctx, vb);
-- 
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 11/16] s5p-jpeg: Retrieve YCbCr subsampling field from the jpeg header

2013-11-25 Thread Jacek Anaszewski
Make s5p_jpeg_parse_hdr function capable of parsing
YCbCr subsampling field of a jpeg file header.
Store the parsed value in the context. The information
about source JPEG subsampling is required to make validation
of destination format possible, which must be conducted
for exynos4x12 device as the decoding process will not succeed
if the destination format is set to YUV with subsampling lower
than the one of the source JPEG image. With this knowledge
the driver can adjust the destination format appropriately.

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 |   35 ---
 1 file changed, 31 insertions(+), 4 deletions(-)

diff --git a/drivers/media/platform/s5p-jpeg/jpeg-core.c 
b/drivers/media/platform/s5p-jpeg/jpeg-core.c
index 02721a1..cb55f67 100644
--- a/drivers/media/platform/s5p-jpeg/jpeg-core.c
+++ b/drivers/media/platform/s5p-jpeg/jpeg-core.c
@@ -624,10 +624,11 @@ static void skip(struct s5p_jpeg_buffer *buf, long len)
 }
 
 static bool s5p_jpeg_parse_hdr(struct s5p_jpeg_q_data *result,
-  unsigned long buffer, unsigned long size)
+  unsigned long buffer, unsigned long size,
+  struct s5p_jpeg_ctx *ctx)
 {
int c, components, notfound;
-   unsigned int height, width, word;
+   unsigned int height, width, word, subsampling = 0;
long length;
struct s5p_jpeg_buffer jpeg_buffer;
 
@@ -666,7 +667,15 @@ static bool s5p_jpeg_parse_hdr(struct s5p_jpeg_q_data 
*result,
break;
notfound = 0;
 
-   skip(jpeg_buffer, components * 3);
+   if (components == 1) {
+   subsampling = 0x33;
+   } else {
+   skip(jpeg_buffer, 1);
+   subsampling = get_byte(jpeg_buffer);
+   skip(jpeg_buffer, 1);
+   }
+
+   skip(jpeg_buffer, components * 2);
break;
 
/* skip payload-less markers */
@@ -688,6 +697,24 @@ static bool s5p_jpeg_parse_hdr(struct s5p_jpeg_q_data 
*result,
result-w = width;
result-h = height;
result-size = components;
+
+   switch (subsampling) {
+   case 0x11:
+   ctx-subsampling = V4L2_JPEG_CHROMA_SUBSAMPLING_444;
+   break;
+   case 0x21:
+   ctx-subsampling = V4L2_JPEG_CHROMA_SUBSAMPLING_422;
+   break;
+   case 0x22:
+   ctx-subsampling = V4L2_JPEG_CHROMA_SUBSAMPLING_420;
+   break;
+   case 0x33:
+   ctx-subsampling = V4L2_JPEG_CHROMA_SUBSAMPLING_GRAY;
+   break;
+   default:
+   return false;
+   }
+
return !notfound;
 }
 
@@ -1435,7 +1462,7 @@ static void s5p_jpeg_buf_queue(struct vb2_buffer *vb)
ctx-hdr_parsed = s5p_jpeg_parse_hdr(tmp,
 (unsigned long)vb2_plane_vaddr(vb, 0),
 min((unsigned long)ctx-out_q.size,
-vb2_get_plane_payload(vb, 0)));
+vb2_get_plane_payload(vb, 0)), ctx);
if (!ctx-hdr_parsed) {
vb2_buffer_done(vb, VB2_BUF_STATE_ERROR);
return;
-- 
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 07/16] s5p-jpeg: Fix lack of spin_lock protection

2013-11-25 Thread Jacek Anaszewski
s5p_jpeg_device_run and s5p_jpeg_runtime_resume callbacks should
have spin_lock protection as they alter device registers.

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 |   11 ++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/drivers/media/platform/s5p-jpeg/jpeg-core.c 
b/drivers/media/platform/s5p-jpeg/jpeg-core.c
index 583fcdd..628fde8 100644
--- a/drivers/media/platform/s5p-jpeg/jpeg-core.c
+++ b/drivers/media/platform/s5p-jpeg/jpeg-core.c
@@ -930,7 +930,9 @@ static void s5p_jpeg_device_run(void *priv)
struct s5p_jpeg_ctx *ctx = priv;
struct s5p_jpeg *jpeg = ctx-jpeg;
struct vb2_buffer *src_buf, *dst_buf;
-   unsigned long src_addr, dst_addr;
+   unsigned long src_addr, dst_addr, flags;
+
+   spin_lock_irqsave(ctx-jpeg-slock, flags);
 
src_buf = v4l2_m2m_next_src_buf(ctx-fh.m2m_ctx);
dst_buf = v4l2_m2m_next_dst_buf(ctx-fh.m2m_ctx);
@@ -998,6 +1000,8 @@ static void s5p_jpeg_device_run(void *priv)
}
 
jpeg_start(jpeg-regs);
+
+   spin_unlock_irqrestore(ctx-jpeg-slock, flags);
 }
 
 static int s5p_jpeg_job_ready(void *priv)
@@ -1418,12 +1422,15 @@ static int s5p_jpeg_runtime_suspend(struct device *dev)
 static int s5p_jpeg_runtime_resume(struct device *dev)
 {
struct s5p_jpeg *jpeg = dev_get_drvdata(dev);
+   unsigned long flags;
int ret;
 
ret = clk_prepare_enable(jpeg-clk);
if (ret  0)
return ret;
 
+   spin_lock_irqsave(jpeg-slock, flags);
+
/*
 * JPEG IP allows storing two Huffman tables for each component
 * We fill table 0 for each component
@@ -1433,6 +1440,8 @@ static int s5p_jpeg_runtime_resume(struct device *dev)
s5p_jpeg_set_hactbl(jpeg-regs);
s5p_jpeg_set_hactblg(jpeg-regs);
 
+   spin_unlock_irqrestore(jpeg-slock, flags);
+
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 12/16] s5p-jpeg: Ensure correct capture format for Exynos4x12

2013-11-25 Thread Jacek Anaszewski
Adjust capture format to the Exynos4x12 device limitations,
according to the subsampling value parsed from the source
JPEG image header. If the capture format was set to YUV with
subsampling lower than the one of the source JPEG image
the decoding process would not succeed.

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 |  113 +++
 1 file changed, 113 insertions(+)

diff --git a/drivers/media/platform/s5p-jpeg/jpeg-core.c 
b/drivers/media/platform/s5p-jpeg/jpeg-core.c
index cb55f67..76d8c12 100644
--- a/drivers/media/platform/s5p-jpeg/jpeg-core.c
+++ b/drivers/media/platform/s5p-jpeg/jpeg-core.c
@@ -358,6 +358,99 @@ static const unsigned char hactblg0[162] = {
0xf9, 0xfa
 };
 
+/*
+ * Fourcc downgrade schema lookup tables for 422 and 420
+ * chroma subsampling - fourcc on each position maps on the
+ * fourcc from the table fourcc_to_dwngrd_schema_id which allows
+ * to get the most suitable fourcc counterpart for the given
+ * downgraded subsampling property.
+ */
+static const u32 subs422_fourcc_dwngrd_schema[] = {
+   V4L2_PIX_FMT_NV16,
+   V4L2_PIX_FMT_NV61,
+};
+
+static const u32 subs420_fourcc_dwngrd_schema[] = {
+   V4L2_PIX_FMT_NV12,
+   V4L2_PIX_FMT_NV21,
+   V4L2_PIX_FMT_NV12,
+   V4L2_PIX_FMT_NV21,
+   V4L2_PIX_FMT_NV12,
+   V4L2_PIX_FMT_NV21,
+   V4L2_PIX_FMT_GREY,
+   V4L2_PIX_FMT_GREY,
+   V4L2_PIX_FMT_GREY,
+   V4L2_PIX_FMT_GREY,
+};
+
+/*
+ * Lookup table for translation of a fourcc to the position
+ * of its downgraded counterpart in the *fourcc_dwngrd_schema
+ * tables.
+ */
+static const u32 fourcc_to_dwngrd_schema_id[] = {
+   V4L2_PIX_FMT_NV24,
+   V4L2_PIX_FMT_NV42,
+   V4L2_PIX_FMT_NV16,
+   V4L2_PIX_FMT_NV61,
+   V4L2_PIX_FMT_YUYV,
+   V4L2_PIX_FMT_YVYU,
+   V4L2_PIX_FMT_NV12,
+   V4L2_PIX_FMT_NV21,
+   V4L2_PIX_FMT_YUV420,
+   V4L2_PIX_FMT_GREY,
+};
+
+static int s5p_jpeg_get_dwngrd_sch_id_by_fourcc(u32 fourcc)
+{
+   int i;
+   for (i = 0; i  ARRAY_SIZE(fourcc_to_dwngrd_schema_id); ++i) {
+   if (fourcc_to_dwngrd_schema_id[i] == fourcc)
+   return i;
+   }
+
+   return -EINVAL;
+}
+
+static int s5p_jpeg_adjust_fourcc_to_subsampling(
+   enum v4l2_jpeg_chroma_subsampling subs,
+   u32 in_fourcc,
+   u32 *out_fourcc,
+   struct s5p_jpeg_ctx *ctx)
+{
+   int dwngrd_sch_id;
+
+   if (ctx-subsampling != V4L2_JPEG_CHROMA_SUBSAMPLING_GRAY) {
+   dwngrd_sch_id =
+   s5p_jpeg_get_dwngrd_sch_id_by_fourcc(in_fourcc);
+   if (dwngrd_sch_id  0)
+   return -EINVAL;
+   }
+
+   switch (ctx-subsampling) {
+   case V4L2_JPEG_CHROMA_SUBSAMPLING_GRAY:
+   *out_fourcc = V4L2_PIX_FMT_GREY;
+   break;
+   case V4L2_JPEG_CHROMA_SUBSAMPLING_420:
+   if (dwngrd_sch_id 
+   ARRAY_SIZE(subs420_fourcc_dwngrd_schema) - 1)
+   return -EINVAL;
+   *out_fourcc = subs420_fourcc_dwngrd_schema[dwngrd_sch_id];
+   break;
+   case V4L2_JPEG_CHROMA_SUBSAMPLING_422:
+   if (dwngrd_sch_id 
+   ARRAY_SIZE(subs422_fourcc_dwngrd_schema) - 1)
+   return -EINVAL;
+   *out_fourcc = subs422_fourcc_dwngrd_schema[dwngrd_sch_id];
+   break;
+   default:
+   *out_fourcc = V4L2_PIX_FMT_GREY;
+   break;
+   }
+
+   return 0;
+}
+
 static inline struct s5p_jpeg_ctx *ctrl_to_ctx(struct v4l2_ctrl *c)
 {
return container_of(c-handler, struct s5p_jpeg_ctx, ctrl_handler);
@@ -941,7 +1034,9 @@ static int s5p_jpeg_try_fmt_vid_cap(struct file *file, 
void *priv,
  struct v4l2_format *f)
 {
struct s5p_jpeg_ctx *ctx = fh_to_ctx(priv);
+   struct v4l2_pix_format *pix = f-fmt.pix;
struct s5p_jpeg_fmt *fmt;
+   int ret;
 
fmt = s5p_jpeg_find_format(ctx, f-fmt.pix.pixelformat,
FMT_TYPE_CAPTURE);
@@ -952,6 +1047,24 @@ static int s5p_jpeg_try_fmt_vid_cap(struct file *file, 
void *priv,
return -EINVAL;
}
 
+   /*
+* The exynos4x12 device requires resulting YUV image
+* subsampling not to be lower than the input jpeg subsampling.
+* If this requirement is not met then downgrade the requested
+* capture format to the one with subsampling equal to the input jpeg.
+*/
+   if ((ctx-jpeg-variant-version != SJPEG_S5P) 
+   (ctx-mode == S5P_JPEG_DECODE) 
+   (fmt-flags  SJPEG_FMT_NON_RGB) 
+   (fmt-subsampling

[PATCH v2 09/16] s5p-jpeg: Split jpeg-hw.h to jpeg-hw-s5p.c and jpeg-hw-s5p.c

2013-11-25 Thread Jacek Anaszewski
Move function definitions from jpeg-hw.h to jpeg-hw-s5p.c
and put function declarations in the jpeg-hw-s5p.h.

Signed-off-by: Jacek Anaszewski j.anaszew...@samsung.com
Signed-off-by: Kyungmin Park kyungmin.p...@samsung.com
---
 drivers/media/platform/s5p-jpeg/Makefile   |2 +-
 drivers/media/platform/s5p-jpeg/jpeg-core.c|2 +-
 drivers/media/platform/s5p-jpeg/jpeg-core.h|5 ++
 .../platform/s5p-jpeg/{jpeg-hw.h = jpeg-hw-s5p.c} |   82 
 drivers/media/platform/s5p-jpeg/jpeg-hw-s5p.h  |   63 +++
 5 files changed, 104 insertions(+), 50 deletions(-)
 rename drivers/media/platform/s5p-jpeg/{jpeg-hw.h = jpeg-hw-s5p.c} (71%)
 create mode 100644 drivers/media/platform/s5p-jpeg/jpeg-hw-s5p.h

diff --git a/drivers/media/platform/s5p-jpeg/Makefile 
b/drivers/media/platform/s5p-jpeg/Makefile
index d18cb5e..faf6398 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
+s5p-jpeg-objs := jpeg-core.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 e907738..b4d7445 100644
--- a/drivers/media/platform/s5p-jpeg/jpeg-core.c
+++ b/drivers/media/platform/s5p-jpeg/jpeg-core.c
@@ -29,7 +29,7 @@
 #include media/videobuf2-dma-contig.h
 
 #include jpeg-core.h
-#include jpeg-hw.h
+#include jpeg-hw-s5p.h
 
 static struct s5p_jpeg_fmt formats_enc[] = {
{
diff --git a/drivers/media/platform/s5p-jpeg/jpeg-core.h 
b/drivers/media/platform/s5p-jpeg/jpeg-core.h
index 4a4776b..7baadf3 100644
--- a/drivers/media/platform/s5p-jpeg/jpeg-core.h
+++ b/drivers/media/platform/s5p-jpeg/jpeg-core.h
@@ -42,10 +42,15 @@
 #define EOI0xd9
 #define DHP0xde
 
+#define S5P_JPEG_ENCODE0
+#define S5P_JPEG_DECODE1
+
 /* Flags that indicate a format can be used for capture/output */
 #define MEM2MEM_CAPTURE(1  0)
 #define MEM2MEM_OUTPUT (1  1)
 
+
+
 /**
  * struct s5p_jpeg - JPEG IP abstraction
  * @lock:  the mutex protecting this structure
diff --git a/drivers/media/platform/s5p-jpeg/jpeg-hw.h 
b/drivers/media/platform/s5p-jpeg/jpeg-hw-s5p.c
similarity index 71%
rename from drivers/media/platform/s5p-jpeg/jpeg-hw.h
rename to drivers/media/platform/s5p-jpeg/jpeg-hw-s5p.c
index b47e887..6a1164c 100644
--- a/drivers/media/platform/s5p-jpeg/jpeg-hw.h
+++ b/drivers/media/platform/s5p-jpeg/jpeg-hw-s5p.c
@@ -9,27 +9,15 @@
  * it under the terms of the GNU General Public License version 2 as
  * published by the Free Software Foundation.
  */
-#ifndef JPEG_HW_H_
-#define JPEG_HW_H_
 
 #include linux/io.h
 #include linux/videodev2.h
 
-#include jpeg-hw.h
+#include jpeg-core.h
 #include jpeg-regs.h
+#include jpeg-hw-s5p.h
 
-#define S5P_JPEG_MIN_WIDTH 32
-#define S5P_JPEG_MIN_HEIGHT32
-#define S5P_JPEG_MAX_WIDTH 8192
-#define S5P_JPEG_MAX_HEIGHT8192
-#define S5P_JPEG_ENCODE0
-#define S5P_JPEG_DECODE1
-#define S5P_JPEG_RAW_IN_5650
-#define S5P_JPEG_RAW_IN_4221
-#define S5P_JPEG_RAW_OUT_422   0
-#define S5P_JPEG_RAW_OUT_420   1
-
-static inline void jpeg_reset(void __iomem *regs)
+void jpeg_reset(void __iomem *regs)
 {
unsigned long reg;
 
@@ -42,12 +30,12 @@ static inline void jpeg_reset(void __iomem *regs)
}
 }
 
-static inline void jpeg_poweron(void __iomem *regs)
+void jpeg_poweron(void __iomem *regs)
 {
writel(S5P_POWER_ON, regs + S5P_JPGCLKCON);
 }
 
-static inline void jpeg_input_raw_mode(void __iomem *regs, unsigned long mode)
+void jpeg_input_raw_mode(void __iomem *regs, unsigned long mode)
 {
unsigned long reg, m;
 
@@ -63,7 +51,7 @@ static inline void jpeg_input_raw_mode(void __iomem *regs, 
unsigned long mode)
writel(reg, regs + S5P_JPGCMOD);
 }
 
-static inline void jpeg_input_raw_y16(void __iomem *regs, bool y16)
+void jpeg_input_raw_y16(void __iomem *regs, bool y16)
 {
unsigned long reg;
 
@@ -75,7 +63,7 @@ static inline void jpeg_input_raw_y16(void __iomem *regs, 
bool y16)
writel(reg, regs + S5P_JPGCMOD);
 }
 
-static inline void jpeg_proc_mode(void __iomem *regs, unsigned long mode)
+void jpeg_proc_mode(void __iomem *regs, unsigned long mode)
 {
unsigned long reg, m;
 
@@ -90,7 +78,7 @@ static inline void jpeg_proc_mode(void __iomem *regs, 
unsigned long mode)
writel(reg, regs + S5P_JPGMOD);
 }
 
-static inline void jpeg_subsampling_mode(void __iomem *regs, unsigned int mode)
+void jpeg_subsampling_mode(void __iomem *regs, unsigned int mode)
 {
unsigned long reg, m;
 
@@ -105,12 +93,12 @@ static inline void jpeg_subsampling_mode(void __iomem 
*regs, unsigned int mode)
writel(reg, regs + S5P_JPGMOD

[PATCH v2 13/16] s5p-jpeg: Allow for wider JPEG subsampling scope for Exynos4x12 encoder

2013-11-25 Thread Jacek Anaszewski
Exynos4x12 supports wider scope of subsampling modes than
S5PC210. Adjust corresponding mask accordingly.

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 |3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/media/platform/s5p-jpeg/jpeg-core.c 
b/drivers/media/platform/s5p-jpeg/jpeg-core.c
index 76d8c12..e85ac6a 100644
--- a/drivers/media/platform/s5p-jpeg/jpeg-core.c
+++ b/drivers/media/platform/s5p-jpeg/jpeg-core.c
@@ -1246,7 +1246,8 @@ static int s5p_jpeg_controls_create(struct s5p_jpeg_ctx 
*ctx)
v4l2_ctrl_new_std(ctx-ctrl_handler, s5p_jpeg_ctrl_ops,
  V4L2_CID_JPEG_RESTART_INTERVAL,
  0, 3, 0x, 0);
-   mask = ~0x06; /* 422, 420 */
+   if (ctx-jpeg-variant-version == SJPEG_S5P)
+   mask = ~0x06; /* 422, 420 */
}
 
ctrl = v4l2_ctrl_new_std_menu(ctx-ctrl_handler, s5p_jpeg_ctrl_ops,
-- 
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 05/16] s5p-jpeg: Rename functions specific to the S5PC210 SoC accordingly

2013-11-25 Thread Jacek Anaszewski
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 |   58 ---
 1 file changed, 34 insertions(+), 24 deletions(-)

diff --git a/drivers/media/platform/s5p-jpeg/jpeg-core.c 
b/drivers/media/platform/s5p-jpeg/jpeg-core.c
index a6ec8c6..32033e7 100644
--- a/drivers/media/platform/s5p-jpeg/jpeg-core.c
+++ b/drivers/media/platform/s5p-jpeg/jpeg-core.c
@@ -213,8 +213,9 @@ static inline struct s5p_jpeg_ctx *fh_to_ctx(struct v4l2_fh 
*fh)
return container_of(fh, struct s5p_jpeg_ctx, fh);
 }
 
-static inline void jpeg_set_qtbl(void __iomem *regs, const unsigned char *qtbl,
-  unsigned long tab, int len)
+static inline void s5p_jpeg_set_qtbl(void __iomem *regs,
+const unsigned char *qtbl,
+unsigned long tab, int len)
 {
int i;
 
@@ -222,22 +223,25 @@ static inline void jpeg_set_qtbl(void __iomem *regs, 
const unsigned char *qtbl,
writel((unsigned int)qtbl[i], regs + tab + (i * 0x04));
 }
 
-static inline void jpeg_set_qtbl_lum(void __iomem *regs, int quality)
+static inline void s5p_jpeg_set_qtbl_lum(void __iomem *regs, int quality)
 {
/* this driver fills quantisation table 0 with data for luma */
-   jpeg_set_qtbl(regs, qtbl_luminance[quality], S5P_JPG_QTBL_CONTENT(0),
- ARRAY_SIZE(qtbl_luminance[quality]));
+   s5p_jpeg_set_qtbl(regs, qtbl_luminance[quality],
+ S5P_JPG_QTBL_CONTENT(0),
+ ARRAY_SIZE(qtbl_luminance[quality]));
 }
 
-static inline void jpeg_set_qtbl_chr(void __iomem *regs, int quality)
+static inline void s5p_jpeg_set_qtbl_chr(void __iomem *regs, int quality)
 {
/* this driver fills quantisation table 1 with data for chroma */
-   jpeg_set_qtbl(regs, qtbl_chrominance[quality], S5P_JPG_QTBL_CONTENT(1),
- ARRAY_SIZE(qtbl_chrominance[quality]));
+   s5p_jpeg_set_qtbl(regs, qtbl_chrominance[quality],
+ S5P_JPG_QTBL_CONTENT(1),
+ ARRAY_SIZE(qtbl_chrominance[quality]));
 }
 
-static inline void jpeg_set_htbl(void __iomem *regs, const unsigned char *htbl,
-  unsigned long tab, int len)
+static inline void s5p_jpeg_set_htbl(void __iomem *regs,
+const unsigned char *htbl,
+unsigned long tab, int len)
 {
int i;
 
@@ -245,28 +249,32 @@ static inline void jpeg_set_htbl(void __iomem *regs, 
const unsigned char *htbl,
writel((unsigned int)htbl[i], regs + tab + (i * 0x04));
 }
 
-static inline void jpeg_set_hdctbl(void __iomem *regs)
+static inline void s5p_jpeg_set_hdctbl(void __iomem *regs)
 {
/* this driver fills table 0 for this component */
-   jpeg_set_htbl(regs, hdctbl0, S5P_JPG_HDCTBL(0), ARRAY_SIZE(hdctbl0));
+   s5p_jpeg_set_htbl(regs, hdctbl0, S5P_JPG_HDCTBL(0),
+   ARRAY_SIZE(hdctbl0));
 }
 
-static inline void jpeg_set_hdctblg(void __iomem *regs)
+static inline void s5p_jpeg_set_hdctblg(void __iomem *regs)
 {
/* this driver fills table 0 for this component */
-   jpeg_set_htbl(regs, hdctblg0, S5P_JPG_HDCTBLG(0), ARRAY_SIZE(hdctblg0));
+   s5p_jpeg_set_htbl(regs, hdctblg0, S5P_JPG_HDCTBLG(0),
+   ARRAY_SIZE(hdctblg0));
 }
 
-static inline void jpeg_set_hactbl(void __iomem *regs)
+static inline void s5p_jpeg_set_hactbl(void __iomem *regs)
 {
/* this driver fills table 0 for this component */
-   jpeg_set_htbl(regs, hactbl0, S5P_JPG_HACTBL(0), ARRAY_SIZE(hactbl0));
+   s5p_jpeg_set_htbl(regs, hactbl0, S5P_JPG_HACTBL(0),
+   ARRAY_SIZE(hactbl0));
 }
 
-static inline void jpeg_set_hactblg(void __iomem *regs)
+static inline void s5p_jpeg_set_hactblg(void __iomem *regs)
 {
/* this driver fills table 0 for this component */
-   jpeg_set_htbl(regs, hactblg0, S5P_JPG_HACTBLG(0), ARRAY_SIZE(hactblg0));
+   s5p_jpeg_set_htbl(regs, hactblg0, S5P_JPG_HACTBLG(0),
+   ARRAY_SIZE(hactblg0));
 }
 
 /*
@@ -962,8 +970,8 @@ static void s5p_jpeg_device_run(void *priv)
 * JPEG IP allows storing 4 quantization tables
 * We fill table 0 for luma and table 1 for chroma
 */
-   jpeg_set_qtbl_lum(jpeg-regs, ctx-compr_quality);
-   jpeg_set_qtbl_chr(jpeg-regs, ctx-compr_quality);
+   s5p_jpeg_set_qtbl_lum(jpeg-regs, ctx-compr_quality);
+   s5p_jpeg_set_qtbl_chr(jpeg-regs, ctx-compr_quality);
/* use table 0 for Y */
jpeg_qtbl(jpeg-regs, 1, 0);
/* use table 1 for Cb and Cr*/
@@ -1406,14 +1414,16 @@ static int

[PATCH v2 14/16] s5p-jpeg: Synchronize V4L2_CID_JPEG_CHROMA_SUBSAMPLING control value

2013-11-25 Thread Jacek Anaszewski
When output queue fourcc is set to any flavour of YUV,
the V4L2_CID_JPEG_CHROMA_SUBSAMPLING control value as
well as its in-driver cached counterpart have to be
updated with the subsampling property of the format
so as to be able to provide correct information to the
user space and preclude setting an illegal subsampling
mode for Exynos4x12 encoder.

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 |8 
 1 file changed, 8 insertions(+)

diff --git a/drivers/media/platform/s5p-jpeg/jpeg-core.c 
b/drivers/media/platform/s5p-jpeg/jpeg-core.c
index e85ac6a..163ee8d 100644
--- a/drivers/media/platform/s5p-jpeg/jpeg-core.c
+++ b/drivers/media/platform/s5p-jpeg/jpeg-core.c
@@ -1091,6 +1091,7 @@ 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;
unsigned int f_type;
 
vq = v4l2_m2m_get_vq(ct-fh.m2m_ctx, f-type);
@@ -1116,6 +1117,13 @@ static int s5p_jpeg_s_fmt(struct s5p_jpeg_ctx *ct, 
struct v4l2_format *f)
else
q_data-size = pix-sizeimage;
 
+   if (f_type == FMT_TYPE_OUTPUT) {
+   ctrl_subs = v4l2_ctrl_find(ct-ctrl_handler,
+   V4L2_CID_JPEG_CHROMA_SUBSAMPLING);
+   if (ctrl_subs)
+   v4l2_ctrl_s_ctrl(ctrl_subs, q_data-fmt-subsampling);
+   }
+
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 06/16] s5p-jpeg: Fix clock resource management

2013-11-25 Thread Jacek Anaszewski
Standard suspend/resume path is called after runtime resume
of the given device, so suspend/resume callbacks must do all
clock management done also by runtime pm to allow for proper
power domain shutdown. Moreover, JPEG clock is enabled from
probe function but is is not necessary. This patch also moves
control of jpeg clock to runtime_pm callbacks.

Signed-off-by: Marek Szyprowski m.szyprow...@samsung.com
Signed-off-by: Seung-Woo Kim sw0312@samsung.com
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 |   35 +++
 1 file changed, 30 insertions(+), 5 deletions(-)

diff --git a/drivers/media/platform/s5p-jpeg/jpeg-core.c 
b/drivers/media/platform/s5p-jpeg/jpeg-core.c
index 32033e7..583fcdd 100644
--- a/drivers/media/platform/s5p-jpeg/jpeg-core.c
+++ b/drivers/media/platform/s5p-jpeg/jpeg-core.c
@@ -1272,7 +1272,6 @@ static int s5p_jpeg_probe(struct platform_device *pdev)
return ret;
}
dev_dbg(pdev-dev, clock source %p\n, jpeg-clk);
-   clk_prepare_enable(jpeg-clk);
 
/* v4l2 device */
ret = v4l2_device_register(pdev-dev, jpeg-v4l2_dev);
@@ -1380,7 +1379,6 @@ device_register_rollback:
v4l2_device_unregister(jpeg-v4l2_dev);
 
 clk_get_rollback:
-   clk_disable_unprepare(jpeg-clk);
clk_put(jpeg-clk);
 
return ret;
@@ -1400,7 +1398,9 @@ static int s5p_jpeg_remove(struct platform_device *pdev)
v4l2_m2m_release(jpeg-m2m_dev);
v4l2_device_unregister(jpeg-v4l2_dev);
 
-   clk_disable_unprepare(jpeg-clk);
+   if (!pm_runtime_status_suspended(pdev-dev))
+   clk_disable_unprepare(jpeg-clk);
+
clk_put(jpeg-clk);
 
return 0;
@@ -1408,12 +1408,21 @@ static int s5p_jpeg_remove(struct platform_device *pdev)
 
 static int s5p_jpeg_runtime_suspend(struct device *dev)
 {
+   struct s5p_jpeg *jpeg = dev_get_drvdata(dev);
+
+   clk_disable_unprepare(jpeg-clk);
+
return 0;
 }
 
 static int s5p_jpeg_runtime_resume(struct device *dev)
 {
struct s5p_jpeg *jpeg = dev_get_drvdata(dev);
+   int ret;
+
+   ret = clk_prepare_enable(jpeg-clk);
+   if (ret  0)
+   return ret;
 
/*
 * JPEG IP allows storing two Huffman tables for each component
@@ -1427,9 +1436,25 @@ static int s5p_jpeg_runtime_resume(struct device *dev)
return 0;
 }
 
+static int s5p_jpeg_suspend(struct device *dev)
+{
+   if (pm_runtime_suspended(dev))
+   return 0;
+
+   return s5p_jpeg_runtime_suspend(dev);
+}
+
+static int s5p_jpeg_resume(struct device *dev)
+{
+   if (pm_runtime_suspended(dev))
+   return 0;
+
+   return s5p_jpeg_runtime_resume(dev);
+}
+
 static const struct dev_pm_ops s5p_jpeg_pm_ops = {
-   .runtime_suspend = s5p_jpeg_runtime_suspend,
-   .runtime_resume  = s5p_jpeg_runtime_resume,
+   SET_SYSTEM_SLEEP_PM_OPS(s5p_jpeg_suspend, s5p_jpeg_resume)
+   SET_RUNTIME_PM_OPS(s5p_jpeg_runtime_suspend, s5p_jpeg_runtime_resume, 
NULL)
 };
 
 #ifdef CONFIG_OF
-- 
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 08/16] s5p-jpeg: Synchronize cached controls with V4L2 core

2013-11-25 Thread Jacek Anaszewski
This patch adds proper initialization of the in-driver
cached state of JPEG controls with V4L2 core.

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, 15 insertions(+), 3 deletions(-)

diff --git a/drivers/media/platform/s5p-jpeg/jpeg-core.c 
b/drivers/media/platform/s5p-jpeg/jpeg-core.c
index 628fde8..e907738 100644
--- a/drivers/media/platform/s5p-jpeg/jpeg-core.c
+++ b/drivers/media/platform/s5p-jpeg/jpeg-core.c
@@ -865,6 +865,7 @@ static int s5p_jpeg_controls_create(struct s5p_jpeg_ctx 
*ctx)
 {
unsigned int mask = ~0x27; /* 444, 422, 420, GRAY */
struct v4l2_ctrl *ctrl;
+   int ret;
 
v4l2_ctrl_handler_init(ctx-ctrl_handler, 3);
 
@@ -884,13 +885,24 @@ static int s5p_jpeg_controls_create(struct s5p_jpeg_ctx 
*ctx)
  V4L2_JPEG_CHROMA_SUBSAMPLING_GRAY, mask,
  V4L2_JPEG_CHROMA_SUBSAMPLING_422);
 
-   if (ctx-ctrl_handler.error)
-   return ctx-ctrl_handler.error;
+   if (ctx-ctrl_handler.error) {
+   ret = ctx-ctrl_handler.error;
+   goto error_free;
+   }
 
if (ctx-mode == S5P_JPEG_DECODE)
ctrl-flags |= V4L2_CTRL_FLAG_VOLATILE |
V4L2_CTRL_FLAG_READ_ONLY;
-   return 0;
+
+   ret = v4l2_ctrl_handler_setup(ctx-ctrl_handler);
+   if (ret  0)
+   goto error_free;
+
+   return ret;
+
+error_free:
+   v4l2_ctrl_handler_free(ctx-ctrl_handler);
+   return ret;
 }
 
 static const struct v4l2_ioctl_ops s5p_jpeg_ioctl_ops = {
-- 
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 15/16] s5p-jpeg: Ensure setting correct value of the chroma subsampling control

2013-11-25 Thread Jacek Anaszewski
Exynos4x12 has limitations regarding setting chroma subsampling
of an output JPEG image. It cannot be lower than the subsampling
of the raw source image. Also in case of V4L2_JPEG_CHROMA_SUBSAMPLING_GRAY
option the source image fourcc has to be V4L2_PIX_FMT_GREY.
This patch implements try_ctrl callback containing mechanism
that prevents setting invalid value of the V4L2_CID_JPEG_CHROMA_SUBSAMPLING
control.

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 |   35 +++
 1 file changed, 35 insertions(+)

diff --git a/drivers/media/platform/s5p-jpeg/jpeg-core.c 
b/drivers/media/platform/s5p-jpeg/jpeg-core.c
index 163ee8d..ad259af 100644
--- a/drivers/media/platform/s5p-jpeg/jpeg-core.c
+++ b/drivers/media/platform/s5p-jpeg/jpeg-core.c
@@ -1210,6 +1210,40 @@ static int s5p_jpeg_g_volatile_ctrl(struct v4l2_ctrl 
*ctrl)
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) {
+   if (ctx-jpeg-variant-version == SJPEG_S5P)
+   goto error_free;
+   /*
+* 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;
+   }
+
+error_free:
+   spin_unlock_irqrestore(ctx-jpeg-slock, flags);
+   return ret;
+}
+
 static int s5p_jpeg_s_ctrl(struct v4l2_ctrl *ctrl)
 {
struct s5p_jpeg_ctx *ctx = ctrl_to_ctx(ctrl);
@@ -1235,6 +1269,7 @@ static int s5p_jpeg_s_ctrl(struct v4l2_ctrl *ctrl)
 
 static const struct v4l2_ctrl_ops s5p_jpeg_ctrl_ops = {
.g_volatile_ctrl= s5p_jpeg_g_volatile_ctrl,
+   .try_ctrl   = s5p_jpeg_try_ctrl,
.s_ctrl = s5p_jpeg_s_ctrl,
 };
 
-- 
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 16/16] s5p-jpeg: Adjust g_volatile_ctrl callback to Exynos4x12 needs

2013-11-25 Thread Jacek Anaszewski
Whereas S5PC210 device produces decoded JPEG subsampling
values that map on V4L2_JPEG_CHROMA_SUBSAMPLNG values,
the Exynos4x12 device doesn't. This patch adds helper
function s5p_jpeg_to_user_subsampling, which performs
suitable translation.

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 |   32 ++-
 1 file changed, 26 insertions(+), 6 deletions(-)

diff --git a/drivers/media/platform/s5p-jpeg/jpeg-core.c 
b/drivers/media/platform/s5p-jpeg/jpeg-core.c
index ad259af..5eb1ee9 100644
--- a/drivers/media/platform/s5p-jpeg/jpeg-core.c
+++ b/drivers/media/platform/s5p-jpeg/jpeg-core.c
@@ -451,6 +451,13 @@ static int s5p_jpeg_adjust_fourcc_to_subsampling(
return 0;
 }
 
+static int exynos4x12_decoded_subsampling[] = {
+   V4L2_JPEG_CHROMA_SUBSAMPLING_GRAY,
+   V4L2_JPEG_CHROMA_SUBSAMPLING_444,
+   V4L2_JPEG_CHROMA_SUBSAMPLING_422,
+   V4L2_JPEG_CHROMA_SUBSAMPLING_420,
+};
+
 static inline struct s5p_jpeg_ctx *ctrl_to_ctx(struct v4l2_ctrl *c)
 {
return container_of(c-handler, struct s5p_jpeg_ctx, ctrl_handler);
@@ -461,6 +468,24 @@ static inline struct s5p_jpeg_ctx *fh_to_ctx(struct 
v4l2_fh *fh)
return container_of(fh, struct s5p_jpeg_ctx, fh);
 }
 
+static int s5p_jpeg_to_user_subsampling(struct s5p_jpeg_ctx *ctx)
+{
+   WARN_ON(ctx-subsampling  3);
+
+   if (ctx-jpeg-variant-version == SJPEG_S5P) {
+   if (ctx-subsampling  2)
+   return V4L2_JPEG_CHROMA_SUBSAMPLING_GRAY;
+   else
+   return ctx-subsampling;
+   } else {
+   if (ctx-subsampling  2)
+   return V4L2_JPEG_CHROMA_SUBSAMPLING_420;
+   else
+   return
+   exynos4x12_decoded_subsampling[ctx-subsampling];
+   }
+}
+
 static inline void s5p_jpeg_set_qtbl(void __iomem *regs,
 const unsigned char *qtbl,
 unsigned long tab, int len)
@@ -1197,12 +1222,7 @@ static int s5p_jpeg_g_volatile_ctrl(struct v4l2_ctrl 
*ctrl)
switch (ctrl-id) {
case V4L2_CID_JPEG_CHROMA_SUBSAMPLING:
spin_lock_irqsave(jpeg-slock, flags);
-
-   WARN_ON(ctx-subsampling  S5P_SUBSAMPLING_MODE_GRAY);
-   if (ctx-subsampling  2)
-   ctrl-val = V4L2_JPEG_CHROMA_SUBSAMPLING_GRAY;
-   else
-   ctrl-val = ctx-subsampling;
+   ctrl-val = s5p_jpeg_to_user_subsampling(ctx);
spin_unlock_irqrestore(jpeg-slock, flags);
break;
}
-- 
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 2/8] s5p-jpeg: Add hardware API for the exynos4x12 JPEG codec.

2013-12-18 Thread Jacek Anaszewski
Signed-off-by: Jacek Anaszewski j.anaszew...@samsung.com
Signed-off-by: Kyungmin Park kyungmin.p...@samsung.com
---
 drivers/media/platform/s5p-jpeg/Makefile  |2 +-
 drivers/media/platform/s5p-jpeg/jpeg-core.c   |  621 ++---
 drivers/media/platform/s5p-jpeg/jpeg-core.h   |   64 ++-
 drivers/media/platform/s5p-jpeg/jpeg-hw-exynos4.c |  279 +
 drivers/media/platform/s5p-jpeg/jpeg-hw-exynos4.h |   42 ++
 drivers/media/platform/s5p-jpeg/jpeg-regs.h   |  209 ++-
 6 files changed, 1123 insertions(+), 94 deletions(-)
 create mode 100644 drivers/media/platform/s5p-jpeg/jpeg-hw-exynos4.c
 create mode 100644 drivers/media/platform/s5p-jpeg/jpeg-hw-exynos4.h

diff --git a/drivers/media/platform/s5p-jpeg/Makefile 
b/drivers/media/platform/s5p-jpeg/Makefile
index faf6398..a1a9169 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-s5p.o
+s5p-jpeg-objs := jpeg-core.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 bfacaec..242e8b8 100644
--- a/drivers/media/platform/s5p-jpeg/jpeg-core.c
+++ b/drivers/media/platform/s5p-jpeg/jpeg-core.c
@@ -1,9 +1,10 @@
 /* linux/drivers/media/platform/s5p-jpeg/jpeg-core.c
  *
- * Copyright (c) 2011 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2011-2013 Samsung Electronics Co., Ltd.
  * http://www.samsung.com
  *
  * Author: Andrzej Pietrasiewicz andrze...@samsung.com
+ * 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
@@ -30,58 +31,212 @@
 
 #include jpeg-core.h
 #include jpeg-hw-s5p.h
+#include jpeg-hw-exynos4.h
+#include jpeg-regs.h
 
-static struct s5p_jpeg_fmt formats_enc[] = {
+static struct s5p_jpeg_fmt sjpeg_formats[] = {
{
.name   = JPEG JFIF,
.fourcc = V4L2_PIX_FMT_JPEG,
+   .flags  = SJPEG_FMT_FLAG_ENC_CAPTURE |
+ SJPEG_FMT_FLAG_DEC_OUTPUT |
+ SJPEG_FMT_FLAG_S5P |
+ SJPEG_FMT_FLAG_EXYNOS4,
+   },
+   {
+   .name   = YUV 4:2:2 packed, YCbYCr,
+   .fourcc = V4L2_PIX_FMT_YUYV,
+   .depth  = 16,
.colplanes  = 1,
-   .types  = MEM2MEM_CAPTURE,
+   .h_align= 4,
+   .v_align= 3,
+   .flags  = SJPEG_FMT_FLAG_ENC_OUTPUT |
+ SJPEG_FMT_FLAG_DEC_CAPTURE |
+ SJPEG_FMT_FLAG_S5P |
+ SJPEG_FMT_NON_RGB,
+   .subsampling= V4L2_JPEG_CHROMA_SUBSAMPLING_422,
},
{
.name   = YUV 4:2:2 packed, YCbYCr,
.fourcc = V4L2_PIX_FMT_YUYV,
.depth  = 16,
.colplanes  = 1,
-   .types  = MEM2MEM_OUTPUT,
+   .h_align= 1,
+   .v_align= 0,
+   .flags  = SJPEG_FMT_FLAG_ENC_OUTPUT |
+ SJPEG_FMT_FLAG_DEC_CAPTURE |
+ SJPEG_FMT_FLAG_EXYNOS4 |
+ SJPEG_FMT_NON_RGB,
+   .subsampling= V4L2_JPEG_CHROMA_SUBSAMPLING_422,
+   },
+   {
+   .name   = YUV 4:2:2 packed, YCrYCb,
+   .fourcc = V4L2_PIX_FMT_YVYU,
+   .depth  = 16,
+   .colplanes  = 1,
+   .h_align= 1,
+   .v_align= 0,
+   .flags  = SJPEG_FMT_FLAG_ENC_OUTPUT |
+ SJPEG_FMT_FLAG_DEC_CAPTURE |
+ SJPEG_FMT_FLAG_EXYNOS4 |
+ SJPEG_FMT_NON_RGB,
+   .subsampling= V4L2_JPEG_CHROMA_SUBSAMPLING_422,
},
{
.name   = RGB565,
.fourcc = V4L2_PIX_FMT_RGB565,
.depth  = 16,
.colplanes  = 1,
-   .types  = MEM2MEM_OUTPUT,
+   .h_align= 0,
+   .v_align= 0,
+   .flags  = SJPEG_FMT_FLAG_ENC_OUTPUT |
+ SJPEG_FMT_FLAG_DEC_CAPTURE |
+ SJPEG_FMT_FLAG_EXYNOS4 |
+ SJPEG_FMT_RGB,
+   .subsampling= V4L2_JPEG_CHROMA_SUBSAMPLING_444,
+   },
+   {
+   .name   = RGB565,
+   .fourcc = V4L2_PIX_FMT_RGB565

[PATCH v3 0/8] Add support for Exynos4x12 device to the s5p-jpeg driver

2013-12-18 Thread Jacek Anaszewski
This is the third version of the series that adds support for the
Exynos4x12 device to the s5p_jpeg driver. It includes following
changes (Mauro - thanks for the review):

  - renamed all occurrences of exynos to more precise exynos4
  - added s5p and exynos4 prefixes to the HW API functions

Thanks,
Jacek Anaszewski

Jacek Anaszewski (8):
  s5p-jpeg: Split jpeg-hw.h to jpeg-hw-s5p.c and jpeg-hw-s5p.c
  s5p-jpeg: Add hardware API for the exynos4x12 JPEG codec.
  s5p-jpeg: Retrieve YCbCr subsampling field from the jpeg header
  s5p-jpeg: Ensure correct capture format for Exynos4x12
  s5p-jpeg: Allow for wider JPEG subsampling scope for Exynos4x12
encoder
  s5p-jpeg: Synchronize V4L2_CID_JPEG_CHROMA_SUBSAMPLING control value
  s5p-jpeg: Ensure setting correct value of the chroma subsampling
control
  s5p-jpeg: Adjust g_volatile_ctrl callback to Exynos4x12 needs

 drivers/media/platform/s5p-jpeg/Makefile   |2 +-
 drivers/media/platform/s5p-jpeg/jpeg-core.c|  946 +---
 drivers/media/platform/s5p-jpeg/jpeg-core.h|   67 +-
 drivers/media/platform/s5p-jpeg/jpeg-hw-exynos4.c  |  279 ++
 drivers/media/platform/s5p-jpeg/jpeg-hw-exynos4.h  |   42 +
 .../platform/s5p-jpeg/{jpeg-hw.h = jpeg-hw-s5p.c} |   82 +-
 drivers/media/platform/s5p-jpeg/jpeg-hw-s5p.h  |   63 ++
 drivers/media/platform/s5p-jpeg/jpeg-regs.h|  209 -
 8 files changed, 1490 insertions(+), 200 deletions(-)
 create mode 100644 drivers/media/platform/s5p-jpeg/jpeg-hw-exynos4.c
 create mode 100644 drivers/media/platform/s5p-jpeg/jpeg-hw-exynos4.h
 rename drivers/media/platform/s5p-jpeg/{jpeg-hw.h = jpeg-hw-s5p.c} (70%)
 create mode 100644 drivers/media/platform/s5p-jpeg/jpeg-hw-s5p.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 v3 1/8] s5p-jpeg: Split jpeg-hw.h to jpeg-hw-s5p.c and jpeg-hw-s5p.c

2013-12-18 Thread Jacek Anaszewski
Move function definitions from jpeg-hw.h to jpeg-hw-s5p.c,
add s5p prefix and put function declarations in the jpeg-hw-s5p.h.

Signed-off-by: Jacek Anaszewski j.anaszew...@samsung.com
Signed-off-by: Kyungmin Park kyungmin.p...@samsung.com
---
 drivers/media/platform/s5p-jpeg/Makefile   |2 +-
 drivers/media/platform/s5p-jpeg/jpeg-core.c|   99 ++--
 drivers/media/platform/s5p-jpeg/jpeg-core.h|5 +
 .../platform/s5p-jpeg/{jpeg-hw.h = jpeg-hw-s5p.c} |   82 +++-
 drivers/media/platform/s5p-jpeg/jpeg-hw-s5p.h  |   63 +
 5 files changed, 154 insertions(+), 97 deletions(-)
 rename drivers/media/platform/s5p-jpeg/{jpeg-hw.h = jpeg-hw-s5p.c} (70%)
 create mode 100644 drivers/media/platform/s5p-jpeg/jpeg-hw-s5p.h

diff --git a/drivers/media/platform/s5p-jpeg/Makefile 
b/drivers/media/platform/s5p-jpeg/Makefile
index d18cb5e..faf6398 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
+s5p-jpeg-objs := jpeg-core.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 e907738..bfacaec 100644
--- a/drivers/media/platform/s5p-jpeg/jpeg-core.c
+++ b/drivers/media/platform/s5p-jpeg/jpeg-core.c
@@ -29,7 +29,7 @@
 #include media/videobuf2-dma-contig.h
 
 #include jpeg-core.h
-#include jpeg-hw.h
+#include jpeg-hw-s5p.h
 
 static struct s5p_jpeg_fmt formats_enc[] = {
{
@@ -951,34 +951,36 @@ static void s5p_jpeg_device_run(void *priv)
src_addr = vb2_dma_contig_plane_dma_addr(src_buf, 0);
dst_addr = vb2_dma_contig_plane_dma_addr(dst_buf, 0);
 
-   jpeg_reset(jpeg-regs);
-   jpeg_poweron(jpeg-regs);
-   jpeg_proc_mode(jpeg-regs, ctx-mode);
+   s5p_jpeg_reset(jpeg-regs);
+   s5p_jpeg_poweron(jpeg-regs);
+   s5p_jpeg_proc_mode(jpeg-regs, ctx-mode);
if (ctx-mode == S5P_JPEG_ENCODE) {
if (ctx-out_q.fmt-fourcc == V4L2_PIX_FMT_RGB565)
-   jpeg_input_raw_mode(jpeg-regs, S5P_JPEG_RAW_IN_565);
+   s5p_jpeg_input_raw_mode(jpeg-regs,
+   S5P_JPEG_RAW_IN_565);
else
-   jpeg_input_raw_mode(jpeg-regs, S5P_JPEG_RAW_IN_422);
-   jpeg_subsampling_mode(jpeg-regs, ctx-subsampling);
-   jpeg_dri(jpeg-regs, ctx-restart_interval);
-   jpeg_x(jpeg-regs, ctx-out_q.w);
-   jpeg_y(jpeg-regs, ctx-out_q.h);
-   jpeg_imgadr(jpeg-regs, src_addr);
-   jpeg_jpgadr(jpeg-regs, dst_addr);
+   s5p_jpeg_input_raw_mode(jpeg-regs,
+   S5P_JPEG_RAW_IN_422);
+   s5p_jpeg_subsampling_mode(jpeg-regs, ctx-subsampling);
+   s5p_jpeg_dri(jpeg-regs, ctx-restart_interval);
+   s5p_jpeg_x(jpeg-regs, ctx-out_q.w);
+   s5p_jpeg_y(jpeg-regs, ctx-out_q.h);
+   s5p_jpeg_imgadr(jpeg-regs, src_addr);
+   s5p_jpeg_jpgadr(jpeg-regs, dst_addr);
 
/* ultimately comes from sizeimage from userspace */
-   jpeg_enc_stream_int(jpeg-regs, ctx-cap_q.size);
+   s5p_jpeg_enc_stream_int(jpeg-regs, ctx-cap_q.size);
 
/* JPEG RGB to YCbCr conversion matrix */
-   jpeg_coef(jpeg-regs, 1, 1, S5P_JPEG_COEF11);
-   jpeg_coef(jpeg-regs, 1, 2, S5P_JPEG_COEF12);
-   jpeg_coef(jpeg-regs, 1, 3, S5P_JPEG_COEF13);
-   jpeg_coef(jpeg-regs, 2, 1, S5P_JPEG_COEF21);
-   jpeg_coef(jpeg-regs, 2, 2, S5P_JPEG_COEF22);
-   jpeg_coef(jpeg-regs, 2, 3, S5P_JPEG_COEF23);
-   jpeg_coef(jpeg-regs, 3, 1, S5P_JPEG_COEF31);
-   jpeg_coef(jpeg-regs, 3, 2, S5P_JPEG_COEF32);
-   jpeg_coef(jpeg-regs, 3, 3, S5P_JPEG_COEF33);
+   s5p_jpeg_coef(jpeg-regs, 1, 1, S5P_JPEG_COEF11);
+   s5p_jpeg_coef(jpeg-regs, 1, 2, S5P_JPEG_COEF12);
+   s5p_jpeg_coef(jpeg-regs, 1, 3, S5P_JPEG_COEF13);
+   s5p_jpeg_coef(jpeg-regs, 2, 1, S5P_JPEG_COEF21);
+   s5p_jpeg_coef(jpeg-regs, 2, 2, S5P_JPEG_COEF22);
+   s5p_jpeg_coef(jpeg-regs, 2, 3, S5P_JPEG_COEF23);
+   s5p_jpeg_coef(jpeg-regs, 3, 1, S5P_JPEG_COEF31);
+   s5p_jpeg_coef(jpeg-regs, 3, 2, S5P_JPEG_COEF32);
+   s5p_jpeg_coef(jpeg-regs, 3, 3, S5P_JPEG_COEF33);
 
/*
 * JPEG IP allows storing 4 quantization tables
@@ -987,31 +989,31 @@ static void s5p_jpeg_device_run(void *priv)
s5p_jpeg_set_qtbl_lum(jpeg-regs, ctx-compr_quality);
s5p_jpeg_set_qtbl_chr(jpeg-regs, ctx-compr_quality);
/* use table 0 for Y */
-   jpeg_qtbl(jpeg-regs, 1, 0

[PATCH v3 3/8] s5p-jpeg: Retrieve YCbCr subsampling field from the jpeg header

2013-12-18 Thread Jacek Anaszewski
Make s5p_jpeg_parse_hdr function capable of parsing
YCbCr subsampling field of a jpeg file header.
Store the parsed value in the context. The information
about source JPEG subsampling is required to make validation
of destination format possible, which must be conducted
for exynos4x12 device as the decoding process will not succeed
if the destination format is set to YUV with subsampling lower
than the one of the source JPEG image. With this knowledge
the driver can adjust the destination format appropriately.

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 |   35 ---
 1 file changed, 31 insertions(+), 4 deletions(-)

diff --git a/drivers/media/platform/s5p-jpeg/jpeg-core.c 
b/drivers/media/platform/s5p-jpeg/jpeg-core.c
index 242e8b8..ffae566 100644
--- a/drivers/media/platform/s5p-jpeg/jpeg-core.c
+++ b/drivers/media/platform/s5p-jpeg/jpeg-core.c
@@ -624,10 +624,11 @@ static void skip(struct s5p_jpeg_buffer *buf, long len)
 }
 
 static bool s5p_jpeg_parse_hdr(struct s5p_jpeg_q_data *result,
-  unsigned long buffer, unsigned long size)
+  unsigned long buffer, unsigned long size,
+  struct s5p_jpeg_ctx *ctx)
 {
int c, components, notfound;
-   unsigned int height, width, word;
+   unsigned int height, width, word, subsampling = 0;
long length;
struct s5p_jpeg_buffer jpeg_buffer;
 
@@ -666,7 +667,15 @@ static bool s5p_jpeg_parse_hdr(struct s5p_jpeg_q_data 
*result,
break;
notfound = 0;
 
-   skip(jpeg_buffer, components * 3);
+   if (components == 1) {
+   subsampling = 0x33;
+   } else {
+   skip(jpeg_buffer, 1);
+   subsampling = get_byte(jpeg_buffer);
+   skip(jpeg_buffer, 1);
+   }
+
+   skip(jpeg_buffer, components * 2);
break;
 
/* skip payload-less markers */
@@ -688,6 +697,24 @@ static bool s5p_jpeg_parse_hdr(struct s5p_jpeg_q_data 
*result,
result-w = width;
result-h = height;
result-size = components;
+
+   switch (subsampling) {
+   case 0x11:
+   ctx-subsampling = V4L2_JPEG_CHROMA_SUBSAMPLING_444;
+   break;
+   case 0x21:
+   ctx-subsampling = V4L2_JPEG_CHROMA_SUBSAMPLING_422;
+   break;
+   case 0x22:
+   ctx-subsampling = V4L2_JPEG_CHROMA_SUBSAMPLING_420;
+   break;
+   case 0x33:
+   ctx-subsampling = V4L2_JPEG_CHROMA_SUBSAMPLING_GRAY;
+   break;
+   default:
+   return false;
+   }
+
return !notfound;
 }
 
@@ -1438,7 +1465,7 @@ static void s5p_jpeg_buf_queue(struct vb2_buffer *vb)
ctx-hdr_parsed = s5p_jpeg_parse_hdr(tmp,
 (unsigned long)vb2_plane_vaddr(vb, 0),
 min((unsigned long)ctx-out_q.size,
-vb2_get_plane_payload(vb, 0)));
+vb2_get_plane_payload(vb, 0)), ctx);
if (!ctx-hdr_parsed) {
vb2_buffer_done(vb, VB2_BUF_STATE_ERROR);
return;
-- 
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 4/8] s5p-jpeg: Ensure correct capture format for Exynos4x12

2013-12-18 Thread Jacek Anaszewski
Adjust capture format to the Exynos4x12 device limitations,
according to the subsampling value parsed from the source
JPEG image header. If the capture format was set to YUV with
subsampling lower than the one of the source JPEG image
the decoding process would not succeed.

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 |  116 +++
 1 file changed, 116 insertions(+)

diff --git a/drivers/media/platform/s5p-jpeg/jpeg-core.c 
b/drivers/media/platform/s5p-jpeg/jpeg-core.c
index ffae566..377dd31 100644
--- a/drivers/media/platform/s5p-jpeg/jpeg-core.c
+++ b/drivers/media/platform/s5p-jpeg/jpeg-core.c
@@ -358,6 +358,99 @@ static const unsigned char hactblg0[162] = {
0xf9, 0xfa
 };
 
+/*
+ * Fourcc downgrade schema lookup tables for 422 and 420
+ * chroma subsampling - fourcc on each position maps on the
+ * fourcc from the table fourcc_to_dwngrd_schema_id which allows
+ * to get the most suitable fourcc counterpart for the given
+ * downgraded subsampling property.
+ */
+static const u32 subs422_fourcc_dwngrd_schema[] = {
+   V4L2_PIX_FMT_NV16,
+   V4L2_PIX_FMT_NV61,
+};
+
+static const u32 subs420_fourcc_dwngrd_schema[] = {
+   V4L2_PIX_FMT_NV12,
+   V4L2_PIX_FMT_NV21,
+   V4L2_PIX_FMT_NV12,
+   V4L2_PIX_FMT_NV21,
+   V4L2_PIX_FMT_NV12,
+   V4L2_PIX_FMT_NV21,
+   V4L2_PIX_FMT_GREY,
+   V4L2_PIX_FMT_GREY,
+   V4L2_PIX_FMT_GREY,
+   V4L2_PIX_FMT_GREY,
+};
+
+/*
+ * Lookup table for translation of a fourcc to the position
+ * of its downgraded counterpart in the *fourcc_dwngrd_schema
+ * tables.
+ */
+static const u32 fourcc_to_dwngrd_schema_id[] = {
+   V4L2_PIX_FMT_NV24,
+   V4L2_PIX_FMT_NV42,
+   V4L2_PIX_FMT_NV16,
+   V4L2_PIX_FMT_NV61,
+   V4L2_PIX_FMT_YUYV,
+   V4L2_PIX_FMT_YVYU,
+   V4L2_PIX_FMT_NV12,
+   V4L2_PIX_FMT_NV21,
+   V4L2_PIX_FMT_YUV420,
+   V4L2_PIX_FMT_GREY,
+};
+
+static int s5p_jpeg_get_dwngrd_sch_id_by_fourcc(u32 fourcc)
+{
+   int i;
+   for (i = 0; i  ARRAY_SIZE(fourcc_to_dwngrd_schema_id); ++i) {
+   if (fourcc_to_dwngrd_schema_id[i] == fourcc)
+   return i;
+   }
+
+   return -EINVAL;
+}
+
+static int s5p_jpeg_adjust_fourcc_to_subsampling(
+   enum v4l2_jpeg_chroma_subsampling subs,
+   u32 in_fourcc,
+   u32 *out_fourcc,
+   struct s5p_jpeg_ctx *ctx)
+{
+   int dwngrd_sch_id;
+
+   if (ctx-subsampling != V4L2_JPEG_CHROMA_SUBSAMPLING_GRAY) {
+   dwngrd_sch_id =
+   s5p_jpeg_get_dwngrd_sch_id_by_fourcc(in_fourcc);
+   if (dwngrd_sch_id  0)
+   return -EINVAL;
+   }
+
+   switch (ctx-subsampling) {
+   case V4L2_JPEG_CHROMA_SUBSAMPLING_GRAY:
+   *out_fourcc = V4L2_PIX_FMT_GREY;
+   break;
+   case V4L2_JPEG_CHROMA_SUBSAMPLING_420:
+   if (dwngrd_sch_id 
+   ARRAY_SIZE(subs420_fourcc_dwngrd_schema) - 1)
+   return -EINVAL;
+   *out_fourcc = subs420_fourcc_dwngrd_schema[dwngrd_sch_id];
+   break;
+   case V4L2_JPEG_CHROMA_SUBSAMPLING_422:
+   if (dwngrd_sch_id 
+   ARRAY_SIZE(subs422_fourcc_dwngrd_schema) - 1)
+   return -EINVAL;
+   *out_fourcc = subs422_fourcc_dwngrd_schema[dwngrd_sch_id];
+   break;
+   default:
+   *out_fourcc = V4L2_PIX_FMT_GREY;
+   break;
+   }
+
+   return 0;
+}
+
 static inline struct s5p_jpeg_ctx *ctrl_to_ctx(struct v4l2_ctrl *c)
 {
return container_of(c-handler, struct s5p_jpeg_ctx, ctrl_handler);
@@ -941,7 +1034,9 @@ static int s5p_jpeg_try_fmt_vid_cap(struct file *file, 
void *priv,
  struct v4l2_format *f)
 {
struct s5p_jpeg_ctx *ctx = fh_to_ctx(priv);
+   struct v4l2_pix_format *pix = f-fmt.pix;
struct s5p_jpeg_fmt *fmt;
+   int ret;
 
fmt = s5p_jpeg_find_format(ctx, f-fmt.pix.pixelformat,
FMT_TYPE_CAPTURE);
@@ -952,6 +1047,27 @@ static int s5p_jpeg_try_fmt_vid_cap(struct file *file, 
void *priv,
return -EINVAL;
}
 
+   /*
+* The exynos4x12 device requires resulting YUV image
+* subsampling not to be lower than the input jpeg subsampling.
+* If this requirement is not met then downgrade the requested
+* capture format to the one with subsampling equal to the input jpeg.
+*/
+   if ((ctx-jpeg-variant-version != SJPEG_S5P) 
+   (ctx-mode == S5P_JPEG_DECODE) 
+   (fmt-flags  SJPEG_FMT_NON_RGB) 
+   (fmt-subsampling

[PATCH v3 8/8] s5p-jpeg: Adjust g_volatile_ctrl callback to Exynos4x12 needs

2013-12-18 Thread Jacek Anaszewski
Whereas S5PC210 device produces decoded JPEG subsampling
values that map on V4L2_JPEG_CHROMA_SUBSAMPLNG values,
the Exynos4x12 device doesn't. This patch adds helper
function s5p_jpeg_to_user_subsampling, which performs
suitable translation.

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 |   29 +--
 1 file changed, 23 insertions(+), 6 deletions(-)

diff --git a/drivers/media/platform/s5p-jpeg/jpeg-core.c 
b/drivers/media/platform/s5p-jpeg/jpeg-core.c
index c46c9af..a009bd9 100644
--- a/drivers/media/platform/s5p-jpeg/jpeg-core.c
+++ b/drivers/media/platform/s5p-jpeg/jpeg-core.c
@@ -451,6 +451,13 @@ static int s5p_jpeg_adjust_fourcc_to_subsampling(
return 0;
 }
 
+static int exynos4x12_decoded_subsampling[] = {
+   V4L2_JPEG_CHROMA_SUBSAMPLING_GRAY,
+   V4L2_JPEG_CHROMA_SUBSAMPLING_444,
+   V4L2_JPEG_CHROMA_SUBSAMPLING_422,
+   V4L2_JPEG_CHROMA_SUBSAMPLING_420,
+};
+
 static inline struct s5p_jpeg_ctx *ctrl_to_ctx(struct v4l2_ctrl *c)
 {
return container_of(c-handler, struct s5p_jpeg_ctx, ctrl_handler);
@@ -461,6 +468,21 @@ static inline struct s5p_jpeg_ctx *fh_to_ctx(struct 
v4l2_fh *fh)
return container_of(fh, struct s5p_jpeg_ctx, fh);
 }
 
+static int s5p_jpeg_to_user_subsampling(struct s5p_jpeg_ctx *ctx)
+{
+   WARN_ON(ctx-subsampling  3);
+
+   if (ctx-jpeg-variant-version == SJPEG_S5P) {
+   if (ctx-subsampling  2)
+   return V4L2_JPEG_CHROMA_SUBSAMPLING_GRAY;
+   return ctx-subsampling;
+   } else {
+   if (ctx-subsampling  2)
+   return V4L2_JPEG_CHROMA_SUBSAMPLING_420;
+   return exynos4x12_decoded_subsampling[ctx-subsampling];
+   }
+}
+
 static inline void s5p_jpeg_set_qtbl(void __iomem *regs,
 const unsigned char *qtbl,
 unsigned long tab, int len)
@@ -1200,12 +1222,7 @@ static int s5p_jpeg_g_volatile_ctrl(struct v4l2_ctrl 
*ctrl)
switch (ctrl-id) {
case V4L2_CID_JPEG_CHROMA_SUBSAMPLING:
spin_lock_irqsave(jpeg-slock, flags);
-
-   WARN_ON(ctx-subsampling  S5P_SUBSAMPLING_MODE_GRAY);
-   if (ctx-subsampling  2)
-   ctrl-val = V4L2_JPEG_CHROMA_SUBSAMPLING_GRAY;
-   else
-   ctrl-val = ctx-subsampling;
+   ctrl-val = s5p_jpeg_to_user_subsampling(ctx);
spin_unlock_irqrestore(jpeg-slock, flags);
break;
}
-- 
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 7/8] s5p-jpeg: Ensure setting correct value of the chroma subsampling control

2013-12-18 Thread Jacek Anaszewski
Exynos4x12 has limitations regarding setting chroma subsampling
of an output JPEG image. It cannot be lower than the subsampling
of the raw source image. Also in case of V4L2_JPEG_CHROMA_SUBSAMPLING_GRAY
option the source image fourcc has to be V4L2_PIX_FMT_GREY.
This patch implements try_ctrl callback containing mechanism
that prevents setting invalid value of the V4L2_CID_JPEG_CHROMA_SUBSAMPLING
control.

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 |   35 +++
 1 file changed, 35 insertions(+)

diff --git a/drivers/media/platform/s5p-jpeg/jpeg-core.c 
b/drivers/media/platform/s5p-jpeg/jpeg-core.c
index fc14bbc..c46c9af 100644
--- a/drivers/media/platform/s5p-jpeg/jpeg-core.c
+++ b/drivers/media/platform/s5p-jpeg/jpeg-core.c
@@ -1213,6 +1213,40 @@ static int s5p_jpeg_g_volatile_ctrl(struct v4l2_ctrl 
*ctrl)
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) {
+   if (ctx-jpeg-variant-version == SJPEG_S5P)
+   goto error_free;
+   /*
+* 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;
+   }
+
+error_free:
+   spin_unlock_irqrestore(ctx-jpeg-slock, flags);
+   return ret;
+}
+
 static int s5p_jpeg_s_ctrl(struct v4l2_ctrl *ctrl)
 {
struct s5p_jpeg_ctx *ctx = ctrl_to_ctx(ctrl);
@@ -1238,6 +1272,7 @@ static int s5p_jpeg_s_ctrl(struct v4l2_ctrl *ctrl)
 
 static const struct v4l2_ctrl_ops s5p_jpeg_ctrl_ops = {
.g_volatile_ctrl= s5p_jpeg_g_volatile_ctrl,
+   .try_ctrl   = s5p_jpeg_try_ctrl,
.s_ctrl = s5p_jpeg_s_ctrl,
 };
 
-- 
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 5/8] s5p-jpeg: Allow for wider JPEG subsampling scope for Exynos4x12 encoder

2013-12-18 Thread Jacek Anaszewski
Exynos4x12 supports wider scope of subsampling modes than
S5PC210. Adjust corresponding mask accordingly.

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 |3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/media/platform/s5p-jpeg/jpeg-core.c 
b/drivers/media/platform/s5p-jpeg/jpeg-core.c
index 377dd31..9195252 100644
--- a/drivers/media/platform/s5p-jpeg/jpeg-core.c
+++ b/drivers/media/platform/s5p-jpeg/jpeg-core.c
@@ -1249,7 +1249,8 @@ static int s5p_jpeg_controls_create(struct s5p_jpeg_ctx 
*ctx)
v4l2_ctrl_new_std(ctx-ctrl_handler, s5p_jpeg_ctrl_ops,
  V4L2_CID_JPEG_RESTART_INTERVAL,
  0, 3, 0x, 0);
-   mask = ~0x06; /* 422, 420 */
+   if (ctx-jpeg-variant-version == SJPEG_S5P)
+   mask = ~0x06; /* 422, 420 */
}
 
ctrl = v4l2_ctrl_new_std_menu(ctx-ctrl_handler, s5p_jpeg_ctrl_ops,
-- 
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 6/8] s5p-jpeg: Synchronize V4L2_CID_JPEG_CHROMA_SUBSAMPLING control value

2013-12-18 Thread Jacek Anaszewski
When output queue fourcc is set to any flavour of YUV,
the V4L2_CID_JPEG_CHROMA_SUBSAMPLING control value as
well as its in-driver cached counterpart have to be
updated with the subsampling property of the format
so as to be able to provide correct information to the
user space and preclude setting an illegal subsampling
mode for Exynos4x12 encoder.

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 |8 
 1 file changed, 8 insertions(+)

diff --git a/drivers/media/platform/s5p-jpeg/jpeg-core.c 
b/drivers/media/platform/s5p-jpeg/jpeg-core.c
index 9195252..fc14bbc 100644
--- a/drivers/media/platform/s5p-jpeg/jpeg-core.c
+++ b/drivers/media/platform/s5p-jpeg/jpeg-core.c
@@ -1094,6 +1094,7 @@ 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;
unsigned int f_type;
 
vq = v4l2_m2m_get_vq(ct-fh.m2m_ctx, f-type);
@@ -1119,6 +1120,13 @@ static int s5p_jpeg_s_fmt(struct s5p_jpeg_ctx *ct, 
struct v4l2_format *f)
else
q_data-size = pix-sizeimage;
 
+   if (f_type == FMT_TYPE_OUTPUT) {
+   ctrl_subs = v4l2_ctrl_find(ct-ctrl_handler,
+   V4L2_CID_JPEG_CHROMA_SUBSAMPLING);
+   if (ctrl_subs)
+   v4l2_ctrl_s_ctrl(ctrl_subs, q_data-fmt-subsampling);
+   }
+
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 1/2] s5p-jpeg: Fix broken indentation in jpeg-regs.h

2014-01-16 Thread Jacek Anaszewski
Signed-off-by: Jacek Anaszewski j.anaszew...@samsung.com
Signed-off-by: Kyungmin Park kyungmin.p...@samsung.com
---
 drivers/media/platform/s5p-jpeg/jpeg-regs.h |   24 
 1 file changed, 12 insertions(+), 12 deletions(-)

diff --git a/drivers/media/platform/s5p-jpeg/jpeg-regs.h 
b/drivers/media/platform/s5p-jpeg/jpeg-regs.h
index 33f2c73..57fb05b 100644
--- a/drivers/media/platform/s5p-jpeg/jpeg-regs.h
+++ b/drivers/media/platform/s5p-jpeg/jpeg-regs.h
@@ -210,19 +210,19 @@
 
 /* JPEG CNTL Register bit */
 #define EXYNOS4_ENC_DEC_MODE_MASK  (0xfffc  0)
-#define EXYNOS4_DEC_MODE   (1  0)
-#define EXYNOS4_ENC_MODE   (1  1)
+#define EXYNOS4_DEC_MODE   (1  0)
+#define EXYNOS4_ENC_MODE   (1  1)
 #define EXYNOS4_AUTO_RST_MARKER(1  2)
 #define EXYNOS4_RST_INTERVAL_SHIFT 3
 #define EXYNOS4_RST_INTERVAL(x)(((x)  0x) \
 EXYNOS4_RST_INTERVAL_SHIFT)
 #define EXYNOS4_HUF_TBL_EN (1  19)
 #define EXYNOS4_HOR_SCALING_SHIFT  20
-#define EXYNOS4_HOR_SCALING_MASK   (3  EXYNOS4_HOR_SCALING_SHIFT)
+#define EXYNOS4_HOR_SCALING_MASK   (3  EXYNOS4_HOR_SCALING_SHIFT)
 #define EXYNOS4_HOR_SCALING(x) (((x)  0x3) \
 EXYNOS4_HOR_SCALING_SHIFT)
 #define EXYNOS4_VER_SCALING_SHIFT  22
-#define EXYNOS4_VER_SCALING_MASK   (3  EXYNOS4_VER_SCALING_SHIFT)
+#define EXYNOS4_VER_SCALING_MASK   (3  EXYNOS4_VER_SCALING_SHIFT)
 #define EXYNOS4_VER_SCALING(x) (((x)  0x3) \
 EXYNOS4_VER_SCALING_SHIFT)
 #define EXYNOS4_PADDING(1  27)
@@ -238,8 +238,8 @@
 #define EXYNOS4_FRAME_ERR_EN   (1  4)
 #define EXYNOS4_INT_EN_ALL (0x1f  0)
 
-#define EXYNOS4_MOD_REG_PROC_ENC   (0  3)
-#define EXYNOS4_MOD_REG_PROC_DEC   (1  3)
+#define EXYNOS4_MOD_REG_PROC_ENC   (0  3)
+#define EXYNOS4_MOD_REG_PROC_DEC   (1  3)
 
 #define EXYNOS4_MOD_REG_SUBSAMPLE_444  (0  0)
 #define EXYNOS4_MOD_REG_SUBSAMPLE_422  (1  0)
@@ -270,7 +270,7 @@
 #define EXYNOS4_DEC_YUV_420_IMG(4  0)
 
 #define EXYNOS4_GRAY_IMG_IP_SHIFT  3
-#define EXYNOS4_GRAY_IMG_IP_MASK   (7  EXYNOS4_GRAY_IMG_IP_SHIFT)
+#define EXYNOS4_GRAY_IMG_IP_MASK   (7  EXYNOS4_GRAY_IMG_IP_SHIFT)
 #define EXYNOS4_GRAY_IMG_IP(4  EXYNOS4_GRAY_IMG_IP_SHIFT)
 
 #define EXYNOS4_RGB_IP_SHIFT   6
@@ -278,18 +278,18 @@
 #define EXYNOS4_RGB_IP_RGB_16BIT_IMG   (4  EXYNOS4_RGB_IP_SHIFT)
 #define EXYNOS4_RGB_IP_RGB_32BIT_IMG   (5  EXYNOS4_RGB_IP_SHIFT)
 
-#define EXYNOS4_YUV_444_IP_SHIFT   9
+#define EXYNOS4_YUV_444_IP_SHIFT   9
 #define EXYNOS4_YUV_444_IP_MASK(7  
EXYNOS4_YUV_444_IP_SHIFT)
 #define EXYNOS4_YUV_444_IP_YUV_444_2P_IMG  (4  EXYNOS4_YUV_444_IP_SHIFT)
 #define EXYNOS4_YUV_444_IP_YUV_444_3P_IMG  (5  EXYNOS4_YUV_444_IP_SHIFT)
 
-#define EXYNOS4_YUV_422_IP_SHIFT   12
+#define EXYNOS4_YUV_422_IP_SHIFT   12
 #define EXYNOS4_YUV_422_IP_MASK(7  
EXYNOS4_YUV_422_IP_SHIFT)
 #define EXYNOS4_YUV_422_IP_YUV_422_1P_IMG  (4  EXYNOS4_YUV_422_IP_SHIFT)
 #define EXYNOS4_YUV_422_IP_YUV_422_2P_IMG  (5  EXYNOS4_YUV_422_IP_SHIFT)
 #define EXYNOS4_YUV_422_IP_YUV_422_3P_IMG  (6  EXYNOS4_YUV_422_IP_SHIFT)
 
-#define EXYNOS4_YUV_420_IP_SHIFT   15
+#define EXYNOS4_YUV_420_IP_SHIFT   15
 #define EXYNOS4_YUV_420_IP_MASK(7  
EXYNOS4_YUV_420_IP_SHIFT)
 #define EXYNOS4_YUV_420_IP_YUV_420_2P_IMG  (4  EXYNOS4_YUV_420_IP_SHIFT)
 #define EXYNOS4_YUV_420_IP_YUV_420_3P_IMG  (5  EXYNOS4_YUV_420_IP_SHIFT)
@@ -303,8 +303,8 @@
 
 #define EXYNOS4_JPEG_DECODED_IMG_FMT_MASK  0x03
 
-#define EXYNOS4_SWAP_CHROMA_CRCB   (1  26)
-#define EXYNOS4_SWAP_CHROMA_CBCR   (0  26)
+#define EXYNOS4_SWAP_CHROMA_CRCB   (1  26)
+#define EXYNOS4_SWAP_CHROMA_CBCR   (0  26)
 
 /* JPEG HUFF count Register bit */
 #define EXYNOS4_HUFF_COUNT_MASK0x
-- 
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 2/2] s5p-jpeg: Fix wrong NV12 format parameters

2014-01-16 Thread Jacek Anaszewski
NV12 format entries in the sjpeg_formats array had wrong
colplanes, depth and v_align values.

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 |8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/media/platform/s5p-jpeg/jpeg-core.c 
b/drivers/media/platform/s5p-jpeg/jpeg-core.c
index a009bd9..6db4d5e 100644
--- a/drivers/media/platform/s5p-jpeg/jpeg-core.c
+++ b/drivers/media/platform/s5p-jpeg/jpeg-core.c
@@ -175,7 +175,7 @@ static struct s5p_jpeg_fmt sjpeg_formats[] = {
{
.name   = YUV 4:2:0 planar, Y/CbCr,
.fourcc = V4L2_PIX_FMT_NV12,
-   .depth  = 16,
+   .depth  = 12,
.colplanes  = 2,
.h_align= 1,
.v_align= 1,
@@ -188,10 +188,10 @@ static struct s5p_jpeg_fmt sjpeg_formats[] = {
{
.name   = YUV 4:2:0 planar, Y/CbCr,
.fourcc = V4L2_PIX_FMT_NV12,
-   .depth  = 16,
-   .colplanes  = 4,
+   .depth  = 12,
+   .colplanes  = 2,
.h_align= 4,
-   .v_align= 1,
+   .v_align= 4,
.flags  = SJPEG_FMT_FLAG_ENC_OUTPUT |
  SJPEG_FMT_FLAG_DEC_CAPTURE |
  SJPEG_FMT_FLAG_S5P |
-- 
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 6/8] leds: Add support for max77693 mfd flash cell

2014-03-20 Thread Jacek Anaszewski
This patch adds led-flash support to Maxim max77693 chipset.
Device can be exposed to user space through LED subsystem
sysfs interface or through V4L2 subdevice when the support
for Multimedia Framework 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: Andrzej Hajda a.ha...@samsung.com
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: SangYoung Son hello@smasung.com
Cc: Samuel Ortiz sa...@linux.intel.com
Cc: Lee Jones lee.jo...@linaro.org
---
 drivers/leds/Kconfig |9 +
 drivers/leds/Makefile|1 +
 drivers/leds/leds-max77693.c |  768 ++
 drivers/mfd/max77693.c   |   21 +-
 include/linux/mfd/max77693.h |   32 ++
 5 files changed, 825 insertions(+), 6 deletions(-)
 create mode 100644 drivers/leds/leds-max77693.c

diff --git a/drivers/leds/Kconfig b/drivers/leds/Kconfig
index 2062682..f2d0e2c 100644
--- a/drivers/leds/Kconfig
+++ b/drivers/leds/Kconfig
@@ -454,6 +454,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 MFD_MAX77693
+   depends on OF
+   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 3cd76db..597585f 100644
--- a/drivers/leds/Makefile
+++ b/drivers/leds/Makefile
@@ -51,6 +51,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..8b5daa1
--- /dev/null
+++ b/drivers/leds/leds-max77693.c
@@ -0,0 +1,768 @@
+/*
+ * Copyright (C) 2014, Samsung Electronics Co., Ltd.
+ *
+ * Authors: Andrzej Hajda a.ha...@samsung.com
+ *  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/slab.h
+#include linux/platform_device.h
+#include linux/module.h
+#include linux/leds.h
+#include linux/mfd/max77693.h
+#include linux/mfd/max77693-private.h
+#include linux/mutex.h
+#include linux/workqueue.h
+#include asm/div64.h
+
+#include media/v4l2-flash.h
+
+#define MAX77693_LED_NAME  max77693-led
+
+#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 MAX77693_FLASH_VOUT_STEP   25
+#define MAX77693_FLASH_VOUT_RMIN   0x0c
+
+#define MAX77693_LED_STATUS_FLASH_ON   (1  3)
+#define MAX77693_LED_STATUS_TORCH_ON   (1  2)
+
+#define MAX77693_LED_FLASH_INT_FLED2_OPEN

[PATCH/RFC 8/8] DT: Add documentation for exynos4-is camera-flash property

2014-03-20 Thread Jacek Anaszewski
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/media/samsung-fimc.txt |3 +++
 1 file changed, 3 insertions(+)

diff --git a/Documentation/devicetree/bindings/media/samsung-fimc.txt 
b/Documentation/devicetree/bindings/media/samsung-fimc.txt
index 922d6f8..88f9287 100644
--- a/Documentation/devicetree/bindings/media/samsung-fimc.txt
+++ b/Documentation/devicetree/bindings/media/samsung-fimc.txt
@@ -108,6 +108,8 @@ Image sensor nodes
 The sensor device nodes should be added to their control bus controller (e.g.
 I2C0) nodes and linked to a port node in the csis or the parallel-ports node,
 using the common video interfaces bindings, defined in video-interfaces.txt.
+If the sensor device has a led flash device associated with it then its phandle
+should be assigned to the camera-flash property.
 
 Example:
 
@@ -125,6 +127,7 @@ Example:
clock-frequency = 2400;
clocks = camera 1;
clock-names = mclk;
+   camera-flash = led_flash;
 
port {
s5k6aa_ep: endpoint {
-- 
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 7/8] DT: Add documentation for the mfd Maxim max77693 flash cell

2014-03-20 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 |   47 
 1 file changed, 47 insertions(+)

diff --git a/Documentation/devicetree/bindings/mfd/max77693.txt 
b/Documentation/devicetree/bindings/mfd/max77693.txt
index 11921cc..9e1aa97 100644
--- a/Documentation/devicetree/bindings/mfd/max77693.txt
+++ b/Documentation/devicetree/bindings/mfd/max77693.txt
@@ -27,6 +27,43 @@ 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-led
+
+Optional properties of led-flash node:
+- maxim,iout : Array of four intensities in microampheres of the current
+   in order: flash1, flash2, torch1, torch2.
+   Range:
+   flash - 15625 - 100,
+   torch - 15625 - 25.
+- maxim,trigger : Array of flags indicating which trigger can activate given 
led
+   in order: flash1, flash2, torch1, torch2.
+   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,timeout : Array of timeouts in microseconds after which leds are
+   turned off in order: flash, torch.
+   Range:
+   flash: 62500 - 100,
+   torch: 0 (no timeout) - 15728000.
+- maxim,boost-mode : Array of the flash boost modes in order: flash1, flash2.
+   Possible values:
+   0 - no boost,
+   1 - adaptive mode,
+   2 - fixed mode.
+- 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 +89,14 @@ Example:
regulator-boot-on;
};
};
+   led_flash: led-flash {
+   compatible = maxim,max77693-led;
+   maxim,iout = 625000 625000 25 25;
+   maxim,trigger = 5 5 6 0;
+   maxim,trigger-type = 0 1;
+   maxim,timeout = 50 0;
+   maxim,boost-mode = 1 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 1/8] leds: Add sysfs and kernel internal API for flash LEDs

2014-03-20 Thread Jacek Anaszewski
Some LED devices support two operation modes - torch and
flash. This patch provides support for flash LED devices
in the LED subsystem by introducing new sysfs attributes
and kernel internal interface. The attributes being
introduced are: flash_mode, flash_timeout, max_flash_timeout,
flash_fault and hw_triggered.
The modifications aim to be compatible with V4L2 framework
requirements related to the flash devices management. The
design assumes that V4L2 driver can take of the LED class
device control and communicate with it through the kernel
internal interface. The LED sysfs interface is made
unavailable then.

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|  216 +--
 drivers/leds/led-core.c |  124 +++--
 drivers/leds/led-triggers.c |   17 +++-
 drivers/leds/leds.h |9 ++
 include/linux/leds.h|  136 +++
 5 files changed, 486 insertions(+), 16 deletions(-)

diff --git a/drivers/leds/led-class.c b/drivers/leds/led-class.c
index f37d63c..0510532 100644
--- a/drivers/leds/led-class.c
+++ b/drivers/leds/led-class.c
@@ -4,6 +4,9 @@
  * Copyright (C) 2005 John Lenz l...@cs.wisc.edu
  * Copyright (C) 2005-2007 Richard Purdie rpur...@openedhand.com
  *
+ * 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.
@@ -13,6 +16,7 @@
 #include linux/kernel.h
 #include linux/init.h
 #include linux/list.h
+#include linux/slab.h
 #include linux/spinlock.h
 #include linux/device.h
 #include linux/timer.h
@@ -45,28 +49,186 @@ 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);
+
+   if (led_sysfs_is_locked(led_cdev)) {
+   ret = -EBUSY;
+   goto exit_unlock;
+   }
 
ret = kstrtoul(buf, 10, state);
if (ret)
-   return ret;
+   goto exit_unlock;
 
if (state == LED_OFF)
led_trigger_remove(led_cdev);
-   __led_set_brightness(led_cdev, state);
+   led_set_brightness(led_cdev, state);
+   ret = size;
 
-   return size;
+exit_unlock:
+   mutex_unlock(led_cdev-led_lock);
+   return ret;
 }
 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);
+
+static ssize_t flash_mode_store(struct device *dev,
+   struct device_attribute *attr, const char *buf, size_t size)
+{
+   struct led_classdev *led_cdev = dev_get_drvdata(dev);
+   unsigned long flash_mode;
+   ssize_t ret;
+
+   mutex_lock(led_cdev-led_lock);
+
+   if (led_sysfs_is_locked(led_cdev)) {
+   ret = -EBUSY;
+   goto exit_unlock;
+   }
+
+   ret = kstrtoul(buf, 10, flash_mode);
+   if (ret)
+   goto exit_unlock;
+
+   if (flash_mode  0  flash_mode  1)
+   return -EINVAL;
+
+   if (led_is_flash_mode(led_cdev) == flash_mode) {
+   ret = size;
+   goto exit_unlock;
+   }
+
+   led_trigger_remove(led_cdev);
+
+   led_set_flash_mode(led_cdev, flash_mode);
+   ret = size;
+
+exit_unlock:
+   mutex_unlock(led_cdev-led_lock);
+   return ret;
+}
+
+static ssize_t flash_mode_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_is_flash_mode(led_cdev));
+}
+static DEVICE_ATTR_RW(flash_mode);
+
+static ssize_t flash_timeout_store(struct device *dev,
+   struct device_attribute *attr, const char *buf, size_t size)
+{
+   struct led_classdev *led_cdev = dev_get_drvdata(dev);
+   unsigned long flash_timeout;
+   ssize_t ret;
+
+   mutex_lock(led_cdev-led_lock);
+
+   if (led_sysfs_is_locked(led_cdev)) {
+   ret = -EBUSY;
+   goto exit_unlock;
+   }
+
+   ret = kstrtoul(buf, 10, flash_timeout);
+   if (ret)
+   goto exit_unlock;
+
+   led_set_flash_timeout(led_cdev, flash_timeout);
+   ret = size;
+
+exit_unlock:
+   mutex_unlock

[PATCH/RFC 3/8] Documentation: leds: Add description of flash mode

2014-03-20 Thread Jacek Anaszewski
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.txt |   25 +
 1 file changed, 25 insertions(+)

diff --git a/Documentation/leds/leds-class.txt 
b/Documentation/leds/leds-class.txt
index 62261c0..d34d990 100644
--- a/Documentation/leds/leds-class.txt
+++ b/Documentation/leds/leds-class.txt
@@ -8,6 +8,31 @@ LED is defined in max_brightness file. The brightness file 
will set the brightne
 of the LED (taking a value 0-max_brightness). Most LEDs don't have hardware
 brightness support so will just be turned on for non-zero brightness settings.
 
+Some LED devices support two modes - torch and flash. A LED subsystem device
+driver can declare this by calling led_classdev_init_flash function and
+initializing flash field of the led_classdev structure (see linux/leds.h).
+There are five sysfs attributes dedicated specifically to the flash LED 
devices:
+
+   - flash_mode - sets/unsets the flash mode
+   - flash_timeout - determines duration of the flash blink in milliseconds
+   - max_flash_timeout - maximum flash blink duration that can be set (RO)
+   - flash_fault - bitmask of flash faults that may have occured, 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.
+   - hw_triggered - Some devices expose dedicated hardware pins for
+triggering a flash LED. The attribute allows to set
+this mode. After writting 1 the brightness has to be 
set
+to the desired value to arm a led.
+
 The class also introduces the optional concept of an LED trigger. A trigger
 is a kernel based source of led events. Triggers can either be simple or
 complex. A simple trigger isn't configurable and is designed to slot into
-- 
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 5/8] media: exynos4-is: Add support for v4l2-flash subdevs

2014-03-20 Thread Jacek Anaszewski
This patch adds suppport for external v4l2-flash devices.
The support includes parsing camera-flash DT property
and asynchronous subdevice registration.

Signed-off-by: Jacek Anaszewski j.anaszew...@samsung.com
Acked-by: Kyungmin Park kyungmin.p...@samsung.com
---
 drivers/media/platform/exynos4-is/media-dev.c |   34 ++---
 drivers/media/platform/exynos4-is/media-dev.h |   14 +-
 2 files changed, 43 insertions(+), 5 deletions(-)

diff --git a/drivers/media/platform/exynos4-is/media-dev.c 
b/drivers/media/platform/exynos4-is/media-dev.c
index e62211a..0f80210 100644
--- a/drivers/media/platform/exynos4-is/media-dev.c
+++ b/drivers/media/platform/exynos4-is/media-dev.c
@@ -28,6 +28,7 @@
 #include linux/types.h
 #include linux/slab.h
 #include media/v4l2-async.h
+#include media/v4l2-flash.h
 #include media/v4l2-ctrls.h
 #include media/v4l2-of.h
 #include media/media-device.h
@@ -400,7 +401,7 @@ static int fimc_md_parse_port_node(struct fimc_md *fmd,
   struct device_node *port,
   unsigned int index)
 {
-   struct device_node *rem, *ep, *np;
+   struct device_node *rem, *ep, *np, *fn;
struct fimc_source_info *pd;
struct v4l2_of_endpoint endpoint;
u32 val;
@@ -440,6 +441,14 @@ static int fimc_md_parse_port_node(struct fimc_md *fmd,
return -EINVAL;
}
 
+   fn = of_parse_phandle(rem, camera-flash, 0);
+   if (fn) {
+   fmd-flash[fmd-num_flashes].asd.match_type =
+   V4L2_ASYNC_MATCH_OF;
+   fmd-flash[fmd-num_flashes].asd.match.of.node = fn;
+   fmd-num_flashes++;
+   }
+
if (fimc_input_is_parallel(endpoint.base.port)) {
if (endpoint.bus_type == V4L2_MBUS_PARALLEL)
pd-sensor_bus_type = FIMC_BUS_TYPE_ITU_601;
@@ -1531,6 +1540,15 @@ static int subdev_notifier_bound(struct 
v4l2_async_notifier *notifier,
struct fimc_sensor_info *si = NULL;
int i;
 
+   /* Register flash subdev if detected any */
+   for (i = 0; i  ARRAY_SIZE(fmd-flash); i++) {
+   if (fmd-flash[i].asd.match.of.node == subdev-dev-of_node) {
+   fmd-flash[i].v4l2_flash = subdev_to_flash(subdev);
+   fmd-num_flashes++;
+   return 0;
+   }
+   }
+
/* Find platform data for this sensor subdev */
for (i = 0; i  ARRAY_SIZE(fmd-sensor); i++)
if (fmd-sensor[i].asd.match.of.node == subdev-dev-of_node)
@@ -1578,7 +1596,7 @@ static int fimc_md_probe(struct platform_device *pdev)
struct device *dev = pdev-dev;
struct v4l2_device *v4l2_dev;
struct fimc_md *fmd;
-   int ret;
+   int i, ret;
 
fmd = devm_kzalloc(dev, sizeof(*fmd), GFP_KERNEL);
if (!fmd)
@@ -1646,6 +1664,12 @@ static int fimc_md_probe(struct platform_device *pdev)
mutex_unlock(fmd-media_dev.graph_mutex);
goto err_m_ent;
}
+
+   if (dev-of_node) {
+   for (i = 0; i  fmd-num_flashes; ++i)
+   fmd-async_subdevs[fmd-num_sensors + i] =
+   fmd-flash[i].asd;
+   }
}
 
mutex_unlock(fmd-media_dev.graph_mutex);
@@ -1664,12 +1688,14 @@ static int fimc_md_probe(struct platform_device *pdev)
goto err_attr;
}
 
-   if (fmd-num_sensors  0) {
+   if (fmd-num_sensors  0 || fmd-num_flashes  0) {
fmd-subdev_notifier.subdevs = fmd-async_subdevs;
-   fmd-subdev_notifier.num_subdevs = fmd-num_sensors;
+   fmd-subdev_notifier.num_subdevs = fmd-num_sensors +
+   fmd-num_flashes;
fmd-subdev_notifier.bound = subdev_notifier_bound;
fmd-subdev_notifier.complete = subdev_notifier_complete;
fmd-num_sensors = 0;
+   fmd-num_flashes = 0;
 
ret = v4l2_async_notifier_register(fmd-v4l2_dev,
fmd-subdev_notifier);
diff --git a/drivers/media/platform/exynos4-is/media-dev.h 
b/drivers/media/platform/exynos4-is/media-dev.h
index ee1e251..9af9de8 100644
--- a/drivers/media/platform/exynos4-is/media-dev.h
+++ b/drivers/media/platform/exynos4-is/media-dev.h
@@ -18,6 +18,7 @@
 #include media/media-device.h
 #include media/media-entity.h
 #include media/v4l2-device.h
+#include media/v4l2-flash.h
 #include media/v4l2-subdev.h
 #include media/s5p_fimc.h
 
@@ -33,6 +34,8 @@
 #define PINCTRL_STATE_IDLE idle
 
 #define FIMC_MAX_SENSORS   4
+#define FIMC_MAX_FLASHES   1
+#define FIMC_MAX_ASYNC_SUBDEVS (FIMC_MAX_SENSORS + FIMC_MAX_FLASHES)
 #define FIMC_MAX_CAMCLKS   2
 #define DEFAULT_SENSOR_CLK_FREQ2400U

[PATCH/RFC 4/8] media: Add registration helpers for V4L2 flash sub-devices

2014-03-20 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
Multimedia Framework support 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
---
 drivers/media/v4l2-core/Makefile |2 +-
 drivers/media/v4l2-core/v4l2-flash.c |  320 ++
 include/media/v4l2-flash.h   |  102 +++
 3 files changed, 423 insertions(+), 1 deletion(-)
 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/Makefile b/drivers/media/v4l2-core/Makefile
index c6ae7ba..63e8f03 100644
--- a/drivers/media/v4l2-core/Makefile
+++ b/drivers/media/v4l2-core/Makefile
@@ -6,7 +6,7 @@ tuner-objs  :=  tuner-core.o
 
 videodev-objs  :=  v4l2-dev.o v4l2-ioctl.o v4l2-device.o v4l2-fh.o \
v4l2-event.o v4l2-ctrls.o v4l2-subdev.o v4l2-clk.o \
-   v4l2-async.o
+   v4l2-async.o v4l2-flash.o
 ifeq ($(CONFIG_COMPAT),y)
   videodev-objs += v4l2-compat-ioctl32.o
 endif
diff --git a/drivers/media/v4l2-core/v4l2-flash.c 
b/drivers/media/v4l2-core/v4l2-flash.c
new file mode 100644
index 000..6be0ba9
--- /dev/null
+++ b/drivers/media/v4l2-core/v4l2-flash.c
@@ -0,0 +1,320 @@
+/*
+ * V4L2 flash LED subdevice 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 media/v4l2-ioctl.h
+#include media/v4l2-device.h
+#include media/v4l2-ctrls.h
+#include media/v4l2-event.h
+#include media/v4l2-flash.h
+#include media/v4l2-dev.h
+
+static int v4l2_flash_g_volatile_ctrl(struct v4l2_ctrl *c)
+
+{
+   struct v4l2_flash *flash = ctrl_to_flash(c);
+   struct led_classdev *led_cdev = flash-led_cdev;
+   unsigned int fault;
+   int ret;
+
+   switch (c-id) {
+   case V4L2_CID_FLASH_STROBE_STATUS:
+   ret = led_update_brightness(led_cdev);
+   if (ret  0)
+   return ret;
+   c-val = !!ret;
+   return 0;
+   case V4L2_CID_FLASH_FAULT:
+   /* led faults map directly to V4L2 flash faults */
+   ret = led_get_flash_fault(led_cdev, fault);
+   if (!ret)
+   c-val = fault;
+   return ret;
+   default:
+   return -EINVAL;
+   }
+}
+
+static int v4l2_flash_set_intensity(struct v4l2_flash *flash,
+   unsigned int intensity)
+{
+   struct led_classdev *led_cdev = flash-led_cdev;
+   unsigned int fault;
+   int ret;
+
+   ret = led_get_flash_fault(led_cdev, fault);
+   if (ret  0 || fault)
+   return -EINVAL;
+
+   led_set_brightness(led_cdev, intensity);
+
+   return ret;
+}
+
+static int v4l2_flash_s_ctrl(struct v4l2_ctrl *c)
+{
+   struct v4l2_flash *flash = ctrl_to_flash(c);
+   struct led_classdev *led_cdev = flash-led_cdev;
+   int ret = 0;
+
+   switch (c-id) {
+   case V4L2_CID_FLASH_LED_MODE:
+   switch (c-val) {
+   case V4L2_FLASH_LED_MODE_NONE:
+   /* clear flash mode on releae */
+   ret = led_set_flash_mode(led_cdev, false);
+   if (ret  0)
+   return ret;
+   mutex_lock(led_cdev-led_lock);
+   led_sysfs_unlock(led_cdev);
+   mutex_unlock(led_cdev-led_lock);
+   break;
+   case V4L2_FLASH_LED_MODE_FLASH:
+   mutex_lock(led_cdev-led_lock);
+   led_sysfs_lock(led_cdev);
+   mutex_unlock(led_cdev-led_lock);
+
+   ret = led_set_flash_mode(led_cdev, true);
+   if (ret  0)
+   return ret;
+   if (flash-ctrl.source-val ==
+   V4L2_FLASH_STROBE_SOURCE_EXTERNAL) {
+   ret = led_set_hw_triggered(led_cdev, true);
+   if (ret  0)
+   return ret;
+   ret = v4l2_flash_set_intensity(flash,
+  flash-flash_intensity);
+   } else {
+   ret = led_set_hw_triggered(led_cdev, false);
+   if (ret  0

[PATCH/RFC 2/8] leds: Improve and export led_update_brightness function

2014-03-20 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 checking the current flash strobe status.
This patch adds checking brightness_get callback error code
and adds the 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  |   17 +
 include/linux/leds.h |   10 ++
 3 files changed, 27 insertions(+), 6 deletions(-)

diff --git a/drivers/leds/led-class.c b/drivers/leds/led-class.c
index 0510532..04de352 100644
--- a/drivers/leds/led-class.c
+++ b/drivers/leds/led-class.c
@@ -27,12 +27,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 093703c..21ceda1 100644
--- a/drivers/leds/led-core.c
+++ b/drivers/leds/led-core.c
@@ -166,6 +166,23 @@ 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;
+
+   if (led_cdev-brightness_get == NULL)
+   return -EINVAL;
+
+   ret = led_cdev-brightness_get(led_cdev);
+   if (ret = 0)
+   led_cdev-brightness = ret;
+   else
+   return ret;
+
+   return 0;
+}
+EXPORT_SYMBOL(led_update_brightness);
+
 int led_set_flash_mode(struct led_classdev *led_cdev,
bool flash_mode)
 {
diff --git a/include/linux/leds.h b/include/linux/leds.h
index 1bf0ab3..5bf05cc 100644
--- a/include/linux/leds.h
+++ b/include/linux/leds.h
@@ -190,6 +190,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 about
+ *
+ * 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_set_flash_mode - set LED flash mode
  * @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 0/8] LED / flash API integration

2014-03-20 Thread Jacek Anaszewski
This patch series is 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 20140319.

In order to show the exemplary usage of the proposed mechanism
the patch series includes implementation of a Flash LED device
driver along with the suitable modifications in a media controller
driver.

Description of the proposed modifications according to
the kernel components they are relevant to:
- LED subsystem modifications
* added following sysfs attributes:
- flash_mode
- flash_timeout
- max_flash_timeout
- flash_fault
- hw_triggered
* added following public API functions:
- led_set_flash_mode
- led_set_flash_timeout
- led_get_flash_fault
- led_set_hw_triggered
- led_sysfs_lock
- led_sysfs_unlock
- led_sysfs_is_locked
- led_is_flash_mode
* added led_flash structure containing flash specific
  ops and flash timeout related data
* added led_classdev_init_flash function to be called
  by a led driver
- Addition of a v4l2_flash 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
- exynos4-is media controller modifications
- Addition of a driver for the flash cell of the MAX77693 mfd
* the driver exploits the newly introduced mechanism
- Update of the samsung-fimc.txt DT bindings documentation
- Update of the max77693.txt DT bindings documentation
- Update of the LED subsystem documentation

Thanks,
Jacek Anaszewski

[1] http://www.spinics.net/lists/linux-media/msg69253.html

Jacek Anaszewski (8):
  leds: Add sysfs and kernel internal API for flash LEDs
  leds: Improve and export led_update_brightness function
  Documentation: leds: Add description of flash mode
  media: Add registration helpers for V4L2 flash sub-devices
  media: exynos4-is: Add support for v4l2-flash subdevs
  leds: Add support for max77693 mfd flash cell
  DT: Add documentation for the mfd Maxim max77693 flash cell
  DT: Add documentation for exynos4-is camera-flash property

 .../devicetree/bindings/media/samsung-fimc.txt |3 +
 Documentation/devicetree/bindings/mfd/max77693.txt |   47 ++
 Documentation/leds/leds-class.txt  |   25 +
 drivers/leds/Kconfig   |9 +
 drivers/leds/Makefile  |1 +
 drivers/leds/led-class.c   |  222 +-
 drivers/leds/led-core.c|  141 +++-
 drivers/leds/led-triggers.c|   17 +-
 drivers/leds/leds-max77693.c   |  768 
 drivers/leds/leds.h|9 +
 drivers/media/platform/exynos4-is/media-dev.c  |   34 +-
 drivers/media/platform/exynos4-is/media-dev.h  |   14 +-
 drivers/media/v4l2-core/Makefile   |2 +-
 drivers/media/v4l2-core/v4l2-flash.c   |  320 
 drivers/mfd/max77693.c |   21 +-
 include/linux/leds.h   |  146 
 include/linux/mfd/max77693.h   |   32 +
 include/media/v4l2-flash.h |  102 +++
 18 files changed, 1879 insertions(+), 34 deletions(-)
 create mode 100644 drivers/leds/leds-max77693.c
 create mode 100644 drivers/media/v4l2-core/v4l2-flash.c
 create mode 100644 include/media/v4l2-flash.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


Re: [PATCH/RFC 6/8] leds: Add support for max77693 mfd flash cell

2014-03-21 Thread Jacek Anaszewski

On 03/20/2014 04:34 PM, Lee Jones wrote:

On Thu, 20 Mar 2014, Jacek Anaszewski wrote:


This patch adds led-flash support to Maxim max77693 chipset.
Device can be exposed to user space through LED subsystem
sysfs interface or through V4L2 subdevice when the support
for Multimedia Framework 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: Andrzej Hajda a.ha...@samsung.com
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: SangYoung Son hello@smasung.com
Cc: Samuel Ortiz sa...@linux.intel.com
Cc: Lee Jones lee.jo...@linaro.org
---
  drivers/leds/Kconfig |9 +
  drivers/leds/Makefile|1 +
  drivers/leds/leds-max77693.c |  768 ++
  drivers/mfd/max77693.c   |   21 +-
  include/linux/mfd/max77693.h |   32 ++
  5 files changed, 825 insertions(+), 6 deletions(-)
  create mode 100644 drivers/leds/leds-max77693.c


[...]


diff --git a/drivers/mfd/max77693.c b/drivers/mfd/max77693.c
index c5535f0..6fa92d3 100644
--- a/drivers/mfd/max77693.c
+++ b/drivers/mfd/max77693.c
@@ -41,12 +41,21 @@
  #define I2C_ADDR_MUIC (0x4A  1)
  #define I2C_ADDR_HAPTIC   (0x90  1)

-static const struct mfd_cell max77693_devs[] = {
-   { .name = max77693-pmic, },
-   { .name = max77693-charger, },
-   { .name = max77693-flash, },
-   { .name = max77693-muic, },
-   { .name = max77693-haptic, },
+enum mfd_devs_idx {
+   IDX_PMIC,
+   IDX_CHARGER,
+   IDX_LED,
+   IDX_MUIC,
+   IDX_HAPTIC,
+};
+
+static struct mfd_cell max77693_devs[] = {
+   [IDX_PMIC]  = { .name = max77693-pmic, },
+   [IDX_CHARGER]   = { .name = max77693-charger, },
+   [IDX_LED]   = { .name = max77693-led,
+   .of_compatible = maxim,max77693-led},
+   [IDX_MUIC]  = { .name = max77693-muic, },
+   [IDX_HAPTIC]= { .name = max77693-haptic, },
  };


What is the purpose of this change?



Introducing mfd_devs_idx itself is a cosmetic change, which
actually could be avoided. Initialization of the of_compatible field
is required for the led driver to get matched properly. And as I've
just realized also max77693-flash name should be preserved.
I will fix this in the next version of the patch.

Thanks,
Jacek Anaszewski
--
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/RFC 1/8] leds: Add sysfs and kernel internal API for flash LEDs

2014-03-21 Thread Jacek Anaszewski

On 03/20/2014 04:28 PM, Richard Purdie wrote:

On Thu, 2014-03-20 at 15:51 +0100, Jacek Anaszewski wrote:

Some LED devices support two operation modes - torch and
flash. This patch provides support for flash LED devices
in the LED subsystem by introducing new sysfs attributes
and kernel internal interface. The attributes being
introduced are: flash_mode, flash_timeout, max_flash_timeout,
flash_fault and hw_triggered.
The modifications aim to be compatible with V4L2 framework
requirements related to the flash devices management. The
design assumes that V4L2 driver can take of the LED class
device control and communicate with it through the kernel
internal interface. The LED sysfs interface is made
unavailable then.

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|  216 +--
  drivers/leds/led-core.c |  124 +++--
  drivers/leds/led-triggers.c |   17 +++-
  drivers/leds/leds.h |9 ++
  include/linux/leds.h|  136 +++
  5 files changed, 486 insertions(+), 16 deletions(-)


It seems rather sad to have to insert that amount of code into the core
LED files for something which only a small number of LEDs actually use.
This will increase the footprint of the core LED code significantly.

Is it not possible to add this as a module/extension to the LED core
rather than completely entangling them?


OK, I'll try to decouple it.

Thanks,
Jacek Anaszewski

--
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 v2 2/8] leds: Improve and export led_update_brightness function

2014-03-28 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 brightness_get callback
error code and adds the 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  |   17 +
 include/linux/leds.h |   10 ++
 3 files changed, 27 insertions(+), 6 deletions(-)

diff --git a/drivers/leds/led-class.c b/drivers/leds/led-class.c
index 5bac140..efe6812 100644
--- a/drivers/leds/led-class.c
+++ b/drivers/leds/led-class.c
@@ -25,12 +25,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 71b40d3..41f2a6a 100644
--- a/drivers/leds/led-core.c
+++ b/drivers/leds/led-core.c
@@ -126,3 +126,20 @@ void led_set_brightness(struct led_classdev *led_cdev,
__led_set_brightness(led_cdev, brightness);
 }
 EXPORT_SYMBOL(led_set_brightness);
+
+int led_update_brightness(struct led_classdev *led_cdev)
+{
+   int ret;
+
+   if (led_cdev-brightness_get == NULL)
+   return -EINVAL;
+
+   ret = led_cdev-brightness_get(led_cdev);
+   if (ret = 0) {
+   led_cdev-brightness = ret;
+   return 0;
+   }
+
+   return ret;
+}
+EXPORT_SYMBOL(led_update_brightness);
diff --git a/include/linux/leds.h b/include/linux/leds.h
index 596555a..c02dd7b 100644
--- a/include/linux/leds.h
+++ b/include/linux/leds.h
@@ -148,6 +148,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_is_locked
-- 
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


Re: [PATCH/RFC 1/8] leds: Add sysfs and kernel internal API for flash LEDs

2014-03-28 Thread Jacek Anaszewski

Hi Sakari,

Thanks for the review.

On 03/24/2014 12:18 AM, Sakari Ailus wrote:

Hi Jacek,

Thanks for the patchset. It's very nice in general. I have a few comments
below.


[...]


diff --git a/include/linux/leds.h b/include/linux/leds.h
index 0287ab2..1bf0ab3 100644
--- a/include/linux/leds.h
+++ b/include/linux/leds.h
@@ -17,6 +17,14 @@
  #include linux/rwsem.h
  #include linux/timer.h
  #include linux/workqueue.h
+#include linux/mutex.h


mutex.h should be earlier in the list of included files.


+#include media/v4l2-device.h
+
+#define LED_FAULT_OVER_VOLTAGE (1  0)
+#define LED_FAULT_TIMEOUT  (1  1)
+#define LED_FAULT_OVER_TEMPERATURE (1  2)
+#define LED_FAULT_SHORT_CIRCUIT(1  3)
+#define LED_FAULT_OVER_CURRENT (1  4)


This patch went in to the media-tree some time ago. I wonder if the relevant
bits should be added here now as well.

commit 935aa6b2e8a911e81baecec0537dd7e478dc8c91
Author: Daniel Jeong gshark.je...@gmail.com
Date:   Mon Mar 3 06:52:08 2014 -0300

 [media] v4l2-controls.h: Add addtional Flash fault bits

 Three Flash fault are added. V4L2_FLASH_FAULT_UNDER_VOLTAGE for the case 
low
 voltage below the min. limit. V4L2_FLASH_FAULT_INPUT_VOLTAGE for the case
 falling input voltage and chip adjust flash current not occur under voltage
 event. V4L2_FLASH_FAULT_LED_OVER_TEMPERATURE for the case the temperature
 exceed the maximun limit

 Signed-off-by: Daniel Jeong gshark.je...@gmail.com
 Signed-off-by: Sakari Ailus sakari.ai...@iki.fi
 Signed-off-by: Mauro Carvalho Chehab m.che...@samsung.com


As it will not cause a build break and any runtime problems, even if
the patch is not merged, I added these bits to my implementation.

BTW I have doubts about V4L2_FLASH_FAULT_INDICATOR and 
V4L2_CID_FLASH_INDICATOR_INTENSITY control. I did not take them

into account in my implementation because it is not clear for
me how an indicator led is related to a torch led. There is
a control for setting indicator intensity but there is not
one for enabling it. Could you shed some light on this issue?

Regards,
Jacek Anaszewski

--
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 v2 8/8] DT: Add documentation for exynos4-is camera-flash property

2014-03-28 Thread Jacek Anaszewski
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/media/samsung-fimc.txt |3 +++
 1 file changed, 3 insertions(+)

diff --git a/Documentation/devicetree/bindings/media/samsung-fimc.txt 
b/Documentation/devicetree/bindings/media/samsung-fimc.txt
index 922d6f8..88f9287 100644
--- a/Documentation/devicetree/bindings/media/samsung-fimc.txt
+++ b/Documentation/devicetree/bindings/media/samsung-fimc.txt
@@ -108,6 +108,8 @@ Image sensor nodes
 The sensor device nodes should be added to their control bus controller (e.g.
 I2C0) nodes and linked to a port node in the csis or the parallel-ports node,
 using the common video interfaces bindings, defined in video-interfaces.txt.
+If the sensor device has a led flash device associated with it then its phandle
+should be assigned to the camera-flash property.
 
 Example:
 
@@ -125,6 +127,7 @@ Example:
clock-frequency = 2400;
clocks = camera 1;
clock-names = mclk;
+   camera-flash = led_flash;
 
port {
s5k6aa_ep: endpoint {
-- 
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 v2 5/8] DT: Add documentation for the mfd Maxim max77693 flash cell

2014-03-28 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 |   47 
 1 file changed, 47 insertions(+)

diff --git a/Documentation/devicetree/bindings/mfd/max77693.txt 
b/Documentation/devicetree/bindings/mfd/max77693.txt
index 11921cc..7a9a4d5 100644
--- a/Documentation/devicetree/bindings/mfd/max77693.txt
+++ b/Documentation/devicetree/bindings/mfd/max77693.txt
@@ -27,6 +27,43 @@ 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
+
+Optional properties of led-flash node:
+- maxim,iout : Array of four maximum intensities in microampheres of the 
current
+   in order: flash1, flash2, torch1, torch2.
+   Range:
+   flash - 15625 - 100,
+   torch - 15625 - 25.
+- maxim,trigger : Array of flags indicating which trigger can activate given 
led
+   in order: flash1, flash2, torch1, torch2.
+   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,timeout : Array of timeouts in microseconds after which leds are
+   turned off in order: flash, torch.
+   Range:
+   flash: 62500 - 100,
+   torch: 0 (no timeout) - 15728000.
+- maxim,boost-mode : Array of the flash boost modes in order: flash1, flash2.
+   Possible values:
+   0 - no boost,
+   1 - adaptive mode,
+   2 - fixed mode.
+- 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 +89,14 @@ Example:
regulator-boot-on;
};
};
+   led_flash: led-flash {
+   compatible = maxim,max77693-flash;
+   maxim,iout = 625000 625000 25 25;
+   maxim,trigger = 5 5 6 6;
+   maxim,trigger-type = 0 1;
+   maxim,timeout = 50 0;
+   maxim,boost-mode = 1 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


Re: [PATCH/RFC 4/8] media: Add registration helpers for V4L2 flash sub-devices

2014-03-28 Thread Jacek Anaszewski

Hi Sakari,

On 03/24/2014 01:08 AM, Sakari Ailus wrote:

Hi Jacek,



[...]


+static int v4l2_flash_set_intensity(struct v4l2_flash *flash,
+   unsigned int intensity)
+{
+   struct led_classdev *led_cdev = flash-led_cdev;
+   unsigned int fault;
+   int ret;
+
+   ret = led_get_flash_fault(led_cdev, fault);
+   if (ret  0 || fault)
+   return -EINVAL;


Is it meaningful to check the faults here?

The existing flash controller drivers mostly do not. The responsibility is
left to the user --- something the user should probably do after the strobe
has expectedly finished. This isn't particularly very well documented in the
spec, though.


I was influenced by the documentation which says that sometimes strobing
the flash may not be possible due to faults. But I agree that checking
the faults should be user's responsibility.


Also, the presence of every fault does not prevent using the flash.


+   led_set_brightness(led_cdev, intensity);


Where do you convert between the LED framework brightness and the value used
by the V4L2 controls?


I think that there is no need for conversion. AFAIK the LED subsystem
doesn't specify units of the brightness. It specifies LED_FULL enum
value but not all LED drivers stick to it. Moreover it limits
brightness resolution to 256 levels.


+
+   return ret;
+}
+
+static int v4l2_flash_s_ctrl(struct v4l2_ctrl *c)
+{
+   struct v4l2_flash *flash = ctrl_to_flash(c);
+   struct led_classdev *led_cdev = flash-led_cdev;
+   int ret = 0;
+
+   switch (c-id) {
+   case V4L2_CID_FLASH_LED_MODE:
+   switch (c-val) {
+   case V4L2_FLASH_LED_MODE_NONE:
+   /* clear flash mode on releae */


It's not uncommon for the user to leave the mode to something else than none
when the user goes away. Could there be other ways to mediate access?


IMHO user space application should release the mode on exit as any other
resource it acquires. However if it is terminated unexpectedly
the sysfs will remain locked forever. Maybe a dedicated sysfs
attribute should be provided in the LED subsystem for controlling the
sysfs lock state? It would have to be always available for the user
though.


+static int v4l2_flash_init_controls(struct v4l2_flash *flash,
+   struct v4l2_flash_ctrl_config *config)
+
+{
+   unsigned int mask;
+   struct v4l2_ctrl *ctrl;
+   struct v4l2_ctrl_config *ctrl_cfg;
+   bool has_flash = config-flags  V4L2_FLASH_CFG_LED_FLASH;
+   bool has_torch = config-flags  V4L2_FLASH_CFG_LED_TORCH;
+   int ret, num_ctrls;
+
+   if (!has_flash  !has_torch)
+   return -EINVAL;
+
+   num_ctrls = has_flash ? 8 : 2;
+   if (config-flags  V4L2_FLASH_CFG_FAULTS_MASK)
+   ++num_ctrls;
+
+   v4l2_ctrl_handler_init(flash-hdl, num_ctrls);
+
+   mask = 1  V4L2_FLASH_LED_MODE_NONE;
+   if (has_flash)
+   mask |= 1  V4L2_FLASH_LED_MODE_FLASH;
+   if (has_torch)
+   mask |= 1  V4L2_FLASH_LED_MODE_TORCH;


I don't expect to see this on LED flash devices. :-)


I don't get your point here. Could you be more specific? :)
Torch only mode is supported by V4L2_CID_FLASH_LED_MODE control,
isn't it?

Regards,
Jacek Anaszewski
--
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 v2 3/8] Documentation: leds: Add description of flash mode

2014-03-28 Thread Jacek Anaszewski
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.txt |   52 +
 1 file changed, 52 insertions(+)

diff --git a/Documentation/leds/leds-class.txt 
b/Documentation/leds/leds-class.txt
index 62261c0..ea50d27 100644
--- a/Documentation/leds/leds-class.txt
+++ b/Documentation/leds/leds-class.txt
@@ -8,6 +8,58 @@ LED is defined in max_brightness file. The brightness file 
will set the brightne
 of the LED (taking a value 0-max_brightness). Most LEDs don't have hardware
 brightness support so will just be turned on for non-zero brightness settings.
 
+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 initialize the flash field
+of the led_classdev structure (see linux/leds_flash.h) to enable flash
+related features of the LED subsystem for the driver.
+
+There are seven sysfs attributes dedicated specifically to the flash LED 
devices:
+
+   - flash_brightness - flash LED brightness in milliampers (RW)
+   - max_flash_brightness - maximum available flash LED brightness (RO)
+   - flash_timeout - flash strobe duration in milliseconds (RW)
+   - max_flash_timeout - maximum available flash strobe duration (RO)
+   - flash_strobe - flash strobe state (RW)
+   - flash_fault - bitmask of flash faults that may have occured, 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
+   - hw_triggered - some devices expose dedicated hardware pins for
+triggering a flash LED - the attribute allows to set
+this mode (RW)
+
+The LED subsystem driver can be controlled also from the level of
+the VideoForLinux2 subsystem. In order to enable this the CONFIG_V4L2_FLASH
+symbol has to be defined in the kernel config. The driver must
+initialize v4l2_flash_ctrl_config structure and pass it to the v4l2_flash_init
+function. On remove v4l2_flash_release has to be called (see 
media/v4l2-flash.h).
+After proper initialization V4L2 Flash sub-device is created. The sub-device
+must be registered by a V4L2 video device to become available for the user
+space. This is accomplished with use of asynchronous sub-device registration
+mechanism (see media/v4l2-async.h).
+A V4l2 Flash 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.
+
 The class also introduces the optional concept of an LED trigger. A trigger
 is a kernel based source of led events. Triggers can either be simple or
 complex. A simple trigger isn't configurable and is designed to slot into
-- 
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 v2 7/8] media: exynos4-is: Add support for v4l2-flash subdevs

2014-03-28 Thread Jacek Anaszewski
This patch adds suppport for external v4l2-flash devices.
The support includes parsing camera-flash DT property
and asynchronous subdevice registration.

Signed-off-by: Jacek Anaszewski j.anaszew...@samsung.com
Acked-by: Kyungmin Park kyungmin.p...@samsung.com
---
 drivers/media/platform/exynos4-is/media-dev.c |   34 ++---
 drivers/media/platform/exynos4-is/media-dev.h |   14 +-
 2 files changed, 43 insertions(+), 5 deletions(-)

diff --git a/drivers/media/platform/exynos4-is/media-dev.c 
b/drivers/media/platform/exynos4-is/media-dev.c
index e62211a..3d750891 100644
--- a/drivers/media/platform/exynos4-is/media-dev.c
+++ b/drivers/media/platform/exynos4-is/media-dev.c
@@ -28,6 +28,7 @@
 #include linux/types.h
 #include linux/slab.h
 #include media/v4l2-async.h
+#include media/v4l2-flash.h
 #include media/v4l2-ctrls.h
 #include media/v4l2-of.h
 #include media/media-device.h
@@ -400,7 +401,7 @@ static int fimc_md_parse_port_node(struct fimc_md *fmd,
   struct device_node *port,
   unsigned int index)
 {
-   struct device_node *rem, *ep, *np;
+   struct device_node *rem, *ep, *np, *fn;
struct fimc_source_info *pd;
struct v4l2_of_endpoint endpoint;
u32 val;
@@ -440,6 +441,14 @@ static int fimc_md_parse_port_node(struct fimc_md *fmd,
return -EINVAL;
}
 
+   fn = of_parse_phandle(rem, camera-flash, 0);
+   if (fn) {
+   fmd-flash[fmd-num_flashes].asd.match_type =
+   V4L2_ASYNC_MATCH_OF;
+   fmd-flash[fmd-num_flashes].asd.match.of.node = fn;
+   fmd-num_flashes++;
+   }
+
if (fimc_input_is_parallel(endpoint.base.port)) {
if (endpoint.bus_type == V4L2_MBUS_PARALLEL)
pd-sensor_bus_type = FIMC_BUS_TYPE_ITU_601;
@@ -1531,6 +1540,15 @@ static int subdev_notifier_bound(struct 
v4l2_async_notifier *notifier,
struct fimc_sensor_info *si = NULL;
int i;
 
+   /* Register flash subdev if detected any */
+   for (i = 0; i  ARRAY_SIZE(fmd-flash); i++) {
+   if (fmd-flash[i].asd.match.of.node == subdev-dev-of_node) {
+   fmd-flash[i].v4l2_flash = v4l2_subdev_to_flash(subdev);
+   fmd-num_flashes++;
+   return 0;
+   }
+   }
+
/* Find platform data for this sensor subdev */
for (i = 0; i  ARRAY_SIZE(fmd-sensor); i++)
if (fmd-sensor[i].asd.match.of.node == subdev-dev-of_node)
@@ -1578,7 +1596,7 @@ static int fimc_md_probe(struct platform_device *pdev)
struct device *dev = pdev-dev;
struct v4l2_device *v4l2_dev;
struct fimc_md *fmd;
-   int ret;
+   int i, ret;
 
fmd = devm_kzalloc(dev, sizeof(*fmd), GFP_KERNEL);
if (!fmd)
@@ -1646,6 +1664,12 @@ static int fimc_md_probe(struct platform_device *pdev)
mutex_unlock(fmd-media_dev.graph_mutex);
goto err_m_ent;
}
+
+   if (dev-of_node) {
+   for (i = 0; i  fmd-num_flashes; ++i)
+   fmd-async_subdevs[fmd-num_sensors + i] =
+   fmd-flash[i].asd;
+   }
}
 
mutex_unlock(fmd-media_dev.graph_mutex);
@@ -1664,12 +1688,14 @@ static int fimc_md_probe(struct platform_device *pdev)
goto err_attr;
}
 
-   if (fmd-num_sensors  0) {
+   if (fmd-num_sensors  0 || fmd-num_flashes  0) {
fmd-subdev_notifier.subdevs = fmd-async_subdevs;
-   fmd-subdev_notifier.num_subdevs = fmd-num_sensors;
+   fmd-subdev_notifier.num_subdevs = fmd-num_sensors +
+   fmd-num_flashes;
fmd-subdev_notifier.bound = subdev_notifier_bound;
fmd-subdev_notifier.complete = subdev_notifier_complete;
fmd-num_sensors = 0;
+   fmd-num_flashes = 0;
 
ret = v4l2_async_notifier_register(fmd-v4l2_dev,
fmd-subdev_notifier);
diff --git a/drivers/media/platform/exynos4-is/media-dev.h 
b/drivers/media/platform/exynos4-is/media-dev.h
index ee1e251..9af9de8 100644
--- a/drivers/media/platform/exynos4-is/media-dev.h
+++ b/drivers/media/platform/exynos4-is/media-dev.h
@@ -18,6 +18,7 @@
 #include media/media-device.h
 #include media/media-entity.h
 #include media/v4l2-device.h
+#include media/v4l2-flash.h
 #include media/v4l2-subdev.h
 #include media/s5p_fimc.h
 
@@ -33,6 +34,8 @@
 #define PINCTRL_STATE_IDLE idle
 
 #define FIMC_MAX_SENSORS   4
+#define FIMC_MAX_FLASHES   1
+#define FIMC_MAX_ASYNC_SUBDEVS (FIMC_MAX_SENSORS + FIMC_MAX_FLASHES)
 #define FIMC_MAX_CAMCLKS   2
 #define DEFAULT_SENSOR_CLK_FREQ

Re: [PATCH/RFC 8/8] DT: Add documentation for exynos4-is camera-flash property

2014-03-28 Thread Jacek Anaszewski

Hi Sakari,

On 03/24/2014 02:05 AM, Sakari Ailus wrote:

Hi Jacek,

On Thu, Mar 20, 2014 at 03:51:10PM +0100, Jacek Anaszewski wrote:

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/media/samsung-fimc.txt |3 +++
  1 file changed, 3 insertions(+)

diff --git a/Documentation/devicetree/bindings/media/samsung-fimc.txt 
b/Documentation/devicetree/bindings/media/samsung-fimc.txt
index 922d6f8..88f9287 100644
--- a/Documentation/devicetree/bindings/media/samsung-fimc.txt
+++ b/Documentation/devicetree/bindings/media/samsung-fimc.txt
@@ -108,6 +108,8 @@ Image sensor nodes
  The sensor device nodes should be added to their control bus controller (e.g.
  I2C0) nodes and linked to a port node in the csis or the parallel-ports node,
  using the common video interfaces bindings, defined in video-interfaces.txt.
+If the sensor device has a led flash device associated with it then its phandle
+should be assigned to the camera-flash property.

  Example:

@@ -125,6 +127,7 @@ Example:
clock-frequency = 2400;
clocks = camera 1;
clock-names = mclk;
+   camera-flash = led_flash;

port {
s5k6aa_ep: endpoint {


It's indeed an interesting idea to declare the flash controller in the
sensor's properties rather than those of the ISP. The obvious upside is that
this way it's easy to figure out which subdev group the flash controller
belongs to.

There are a few other things to consider as well:

- You can't have a flash without a sensor. I can't think of why this would
   be a real issue, though.

- Relations other than one-to-one become difficult. One flash but two
   cameras --- think of stereo cameras.

- One camera and two flashes. I haven't seen any but I don't think
  that's unthinkable.

- It's not very nice of the ISP driver to just go and parse the
   sensor's properties.

- As the property is FIMC specific, the sensor DT node now carries FIMC
   related information.

A generic solution would be preferrable as this is not a FIMC related
problem.

I have to admit that I can't think of a better solution right now than just
putting a list of the flash device phandles to the ISP device's DT node, and
then adding information on which sensor (numeric ID) the flash is related to
as an array. Better ideas would be welcome.



One reason why the flash sub-dev is registered by the sensor is the
fact that a subdev has to be registered to make it available for use.
The second reason is that it is physically connected with the sensor on
the board via torchen/flashen traces. However it would be nice if the
flash could be available for use even if its parent sensor driver isn't 
probed.


There are also possible configurations where traces are routed through
multiplexers and in such cases the sensor-flash relation is not fixed.

I propose to introduce a flash manager which would maintain
all the available flashes. V4L2 Flash sub-devices could register
with it asynchronously. The flash manager could expose controls
for configuring flash-sensor relations. In specific case a flash
manager could be built upon a multiplexer device. This would suit
me very well as I am currently facing such a configuration
on another board. For time being I put gpios of a multiplexer
to the flash DT node, but it doesn't reflect board configuration,
where multiplexer is a separate device. I could try to implement
the flash manager and submit an RFC. What is your opinion, does
it make a sense?

Regards,
Jacek Anaszewski

--
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 v2 4/8] leds: Add support for max77693 mfd flash cell

2014-03-28 Thread Jacek Anaszewski
This patch adds led-flash support to Maxim max77693 chipset.
Device can be exposed to user space through LED subsystem
sysfs interface or through V4L2 subdevice when the support
for Multimedia Framework 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: Andrzej Hajda a.ha...@samsung.com
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: SangYoung Son hello@smasung.com
Cc: Samuel Ortiz sa...@linux.intel.com
Cc: Lee Jones lee.jo...@linaro.org
---
 drivers/leds/Kconfig |   10 +
 drivers/leds/Makefile|1 +
 drivers/leds/leds-max77693.c |  864 ++
 drivers/mfd/max77693.c   |3 +-
 include/linux/mfd/max77693.h |   32 ++
 5 files changed, 909 insertions(+), 1 deletion(-)
 create mode 100644 drivers/leds/leds-max77693.c

diff --git a/drivers/leds/Kconfig b/drivers/leds/Kconfig
index 1e1c81f..b2152a6 100644
--- a/drivers/leds/Kconfig
+++ b/drivers/leds/Kconfig
@@ -462,6 +462,16 @@ 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
+   depends on OF
+   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 8861b86..64f6234 100644
--- a/drivers/leds/Makefile
+++ b/drivers/leds/Makefile
@@ -52,6 +52,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..1bfac68
--- /dev/null
+++ b/drivers/leds/leds-max77693.c
@@ -0,0 +1,864 @@
+/*
+ * Copyright (C) 2014, Samsung Electronics Co., Ltd.
+ *
+ * Authors: Andrzej Hajda a.ha...@samsung.com
+ *  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/slab.h
+#include linux/platform_device.h
+#include linux/module.h
+#include linux/leds.h
+#include linux/mfd/max77693.h
+#include linux/mfd/max77693-private.h
+#include linux/mutex.h
+#include linux/workqueue.h
+#include asm/div64.h
+
+#include media/v4l2-flash.h
+
+#define MAX77693_LED_NAME  max77693-flash
+
+#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 MAX77693_FLASH_VOUT_STEP   25
+#define MAX77693_FLASH_VOUT_RMIN   0x0c
+
+#define MAX77693_LED_STATUS_FLASH_ON   (1  3)
+#define MAX77693_LED_STATUS_TORCH_ON   (1  2)
+
+#define

[PATCH/RFC v2 1/8] leds: Add sysfs and kernel internal API for flash LEDs

2014-03-28 Thread Jacek Anaszewski
Some LED devices support two operation modes - torch and
flash. This patch provides support for flash LED devices
in the LED subsystem by introducing new sysfs attributes
and kernel internal interface. The attributes being
introduced are: flash_brightness, flash_strobe, flash_timeout,
max_flash_timeout, max_flash_brightness, flash_fault and
hw_triggered. All the flash related features are placed
in a separate module.
The modifications aim to be compatible with V4L2 framework
requirements related to the flash devices management. The
design assumes that V4L2 sub-device can take of the LED class
device control and communicate with it through the kernel
internal interface. The LED sysfs interface is made
unavailable then.

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|8 +
 drivers/leds/Makefile   |1 +
 drivers/leds/led-class.c|   56 +--
 drivers/leds/led-flash.c|  375 +++
 drivers/leds/led-triggers.c |   16 +-
 drivers/leds/leds.h |3 +
 include/linux/leds.h|   24 ++-
 include/linux/leds_flash.h  |  189 ++
 8 files changed, 658 insertions(+), 14 deletions(-)
 create mode 100644 drivers/leds/led-flash.c
 create mode 100644 include/linux/leds_flash.h

diff --git a/drivers/leds/Kconfig b/drivers/leds/Kconfig
index 2062682..1e1c81f 100644
--- a/drivers/leds/Kconfig
+++ b/drivers/leds/Kconfig
@@ -19,6 +19,14 @@ config LEDS_CLASS
  This option enables the led sysfs class in /sys/class/leds.  You'll
  need this to do anything useful with LEDs.  If unsure, say N.
 
+config LEDS_CLASS_FLASH
+   tristate Flash LEDs Support
+   depends on LEDS_CLASS
+   help
+ This option enables support for flash LED devices. Say Y if you
+ want to use flash specific features of a LED device, if they
+ are supported.
+
 comment LED drivers
 
 config LEDS_88PM860X
diff --git a/drivers/leds/Makefile b/drivers/leds/Makefile
index 3cd76db..8861b86 100644
--- a/drivers/leds/Makefile
+++ b/drivers/leds/Makefile
@@ -2,6 +2,7 @@
 # LED Core
 obj-$(CONFIG_NEW_LEDS) += led-core.o
 obj-$(CONFIG_LEDS_CLASS)   += led-class.o
+obj-$(CONFIG_LEDS_CLASS_FLASH) += led-flash.o
 obj-$(CONFIG_LEDS_TRIGGERS)+= led-triggers.o
 
 # LED Platform Drivers
diff --git a/drivers/leds/led-class.c b/drivers/leds/led-class.c
index f37d63c..5bac140 100644
--- a/drivers/leds/led-class.c
+++ b/drivers/leds/led-class.c
@@ -9,16 +9,18 @@
  * 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/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 linux/leds_flash.h
 #include leds.h
 
 static struct class *leds_class;
@@ -45,28 +47,38 @@ 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);
+
+   if (led_sysfs_is_locked(led_cdev)) {
+   ret = -EBUSY;
+   goto unlock;
+   }
 
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);
+   ret = size;
 
-   return size;
+unlock:
+   mutex_unlock(led_cdev-led_lock);
+   return ret;
 }
 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);
@@ -173,7 +185,15 @@ EXPORT_SYMBOL_GPL(led_classdev_suspend);
  */
 void led_classdev_resume(struct led_classdev *led_cdev)
 {
+   struct led_flash *flash = led_cdev-flash;
+
led_cdev-brightness_set(led_cdev, led_cdev-brightness);
+   if (flash) {
+   call_flash_op(brightness_set, led_cdev,
+   flash-brightness);
+   call_flash_op(timeout_set, led_cdev,
+   flash-timeout);
+   }
led_cdev-flags

[PATCH/RFC v2 0/8] LED / flash API integration

2014-03-28 Thread Jacek Anaszewski
This is is a second 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 next-20140328 and contains
significant number of modifications in comparison to its first
version (Lee, Richard and Sakari - thanks for the review).

In order to show the exemplary usage of the proposed mechanism
the patch series includes implementation of a Flash LED device
driver along with the suitable modifications in a media controller
driver.

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:
- flash_brightness
- max_flash_brightness
- flash_timeout
- max_flash_timeout
- flash_strobe
- flash_fault
- hw_triggered
and exposes kernel internal API
- led_set_flash_strobe
- led_get_flash_strobe
- led_set_flash_brightness
- led_update_flash_brightness
- led_set_flash_timeout
- led_get_flash_fault
- led_set_hw_triggered
- led_sysfs_lock
- led_sysfs_unlock
- 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
- exynos4-is media controller modifications
- Addition of a driver for the flash cell of the MAX77693 mfd
* the driver exploits the newly introduced mechanism
- Update of the samsung-fimc.txt DT bindings documentation
- Update of the max77693.txt DT bindings documentation
- Update of the LED subsystem documentation

Thanks,
Jacek Anaszewski

[1] http://www.spinics.net/lists/linux-media/msg69253.html

Jacek Anaszewski (8):
  leds: Add sysfs and kernel internal API for flash LEDs
  leds: Improve and export led_update_brightness function
  Documentation: leds: Add description of flash mode
  leds: Add support for max77693 mfd flash cell
  DT: Add documentation for the mfd Maxim max77693 flash cell
  media: Add registration helpers for V4L2 flash sub-devices
  media: exynos4-is: Add support for v4l2-flash subdevs
  DT: Add documentation for exynos4-is camera-flash property

 .../devicetree/bindings/media/samsung-fimc.txt |3 +
 Documentation/devicetree/bindings/mfd/max77693.txt |   47 ++
 Documentation/leds/leds-class.txt  |   52 ++
 drivers/leds/Kconfig   |   18 +
 drivers/leds/Makefile  |2 +
 drivers/leds/led-class.c   |   62 +-
 drivers/leds/led-core.c|   17 +
 drivers/leds/led-flash.c   |  375 +
 drivers/leds/led-triggers.c|   16 +-
 drivers/leds/leds-max77693.c   |  864 
 drivers/leds/leds.h|3 +
 drivers/media/platform/exynos4-is/media-dev.c  |   34 +-
 drivers/media/platform/exynos4-is/media-dev.h  |   14 +-
 drivers/media/v4l2-core/Kconfig|   10 +
 drivers/media/v4l2-core/Makefile   |2 +
 drivers/media/v4l2-core/v4l2-flash.c   |  302 +++
 drivers/mfd/max77693.c |3 +-
 include/linux/leds.h   |   34 +-
 include/linux/leds_flash.h |  189 +
 include/linux/mfd/max77693.h   |   32 +
 include/media/v4l2-flash.h |  104 +++
 21 files changed, 2157 insertions(+), 26 deletions(-)
 create mode 100644 drivers/leds/led-flash.c
 create mode 100644 drivers/leds/leds-max77693.c
 create mode 100644 drivers/media/v4l2-core/v4l2-flash.c
 create mode 100644 include/linux/leds_flash.h
 create mode 100644 include/media/v4l2-flash.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 v2 6/8] media: Add registration helpers for V4L2 flash sub-devices

2014-03-28 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
Multimedia Framework support 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
---
 drivers/media/v4l2-core/Kconfig  |   10 ++
 drivers/media/v4l2-core/Makefile |2 +
 drivers/media/v4l2-core/v4l2-flash.c |  302 ++
 include/media/v4l2-flash.h   |  104 
 4 files changed, 418 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 2189bfb..07b53e5 100644
--- a/drivers/media/v4l2-core/Kconfig
+++ b/drivers/media/v4l2-core/Kconfig
@@ -35,6 +35,16 @@ config V4L2_MEM2MEM_DEV
 tristate
 depends on VIDEOBUF2_CORE
 
+# Used by LED subsystem flash drivers
+config V4L2_FLASH
+   tristate Enable support for V4L2 Flash sub-devices
+   depends on LEDS_CLASS_FLASH
+   ---help---
+ Say Y here to enable support for V4L2 Flash sub-devices, which allow
+ to control LED class devices with V4L2 API.
+
+ 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 c6ae7ba..8e37ab4 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) += 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..81370f9
--- /dev/null
+++ b/drivers/media/v4l2-core/v4l2-flash.c
@@ -0,0 +1,302 @@
+/*
+ * V4L2 flash LED subdevice 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 media/v4l2-ctrls.h
+#include media/v4l2-dev.h
+#include media/v4l2-device.h
+#include media/v4l2-event.h
+#include media/v4l2-flash.h
+#include media/v4l2-ioctl.h
+
+static int v4l2_flash_g_volatile_ctrl(struct v4l2_ctrl *c)
+
+{
+   struct v4l2_flash *flash = v4l2_ctrl_to_v4l2_flash(c);
+   struct led_classdev *led_cdev = flash-led_cdev;
+   unsigned int fault;
+   int ret;
+
+   switch (c-id) {
+   case V4L2_CID_FLASH_TORCH_INTENSITY:
+   ret = led_update_brightness(led_cdev);
+   if (ret  0)
+   return ret;
+   c-val = led_cdev-brightness;
+   return 0;
+   case V4L2_CID_FLASH_INTENSITY:
+   ret = led_update_flash_brightness(led_cdev);
+   if (ret  0)
+   return ret;
+   c-val = led_cdev-flash-brightness;
+   return 0;
+   case V4L2_CID_FLASH_STROBE_STATUS:
+   ret = led_get_flash_strobe(led_cdev);
+   if (ret  0)
+   return ret;
+   c-val = !!ret;
+   return 0;
+   case V4L2_CID_FLASH_FAULT:
+   /* led faults map directly to V4L2 flash faults */
+   ret = led_get_flash_fault(led_cdev, fault);
+   if (!ret)
+   c-val = fault;
+   return ret;
+   default:
+   return -EINVAL;
+   }
+}
+
+static int v4l2_flash_s_ctrl(struct v4l2_ctrl *c)
+{
+   struct v4l2_flash *flash = v4l2_ctrl_to_v4l2_flash(c);
+   struct led_classdev *led_cdev = flash-led_cdev;
+   bool hw_trig;
+   int ret;
+
+   switch (c-id) {
+   case V4L2_CID_FLASH_LED_MODE:
+   switch (c-val) {
+   case V4L2_FLASH_LED_MODE_NONE:
+   led_set_brightness(led_cdev, 0);
+   ret = led_set_flash_strobe(led_cdev, false);
+
+   mutex_lock(led_cdev-led_lock);
+   led_sysfs_unlock(led_cdev);
+   mutex_unlock(led_cdev-led_lock);
+   return ret;
+   case V4L2_FLASH_LED_MODE_FLASH:
+   mutex_lock(led_cdev-led_lock);
+   led_sysfs_lock(led_cdev);
+   mutex_unlock(led_cdev-led_lock);
+
+   /* Turn off torch LED

Re: brightness units

2014-04-03 Thread Jacek Anaszewski

Hi Bryan, Milo and Sakari,

Thanks for the replies.

On 04/02/2014 05:17 PM, Sakari Ailus wrote:

Hi Bryan,

On Tue, Apr 01, 2014 at 03:09:55PM -0700, Bryan Wu wrote:

On Tue, Apr 1, 2014 at 12:21 AM, Jacek Anaszewski
j.anaszew...@samsung.com wrote:

I am currently integrating LED subsystem and V4L2 Flash API.
V4L2 Flash API defines units of torch and flash intensity
in milliampers. In the LED subsystem documentation I can't
find any reference to the brightness units. On the other
hand there is led_brightness enum defined in the linux/leds.h
header, with LED_FULL = 255, but not all leds drivers use it.
I am aware that there are LEDs that can be only turned on/off
without any possibility to set the current and in such cases
LED_FULL doesn't reflect the current set.



Actually led_brightness is an logic concept not like milliampers,
since different led drivers has different implementation which is
hardware related. Like PWM led driver, it will be converted to duty
cycles.

For current control I do see some specific driver like LP55xx have it
but not for every one.


So far I've assumed that brightness is expressed in milliampers
and I don't stick to the LED_FULL limit. It allows for passing
flash/torch intensity from V4L2 controls to the leds API
without conversion. I am not sure if the units should be
fixed to milliampers in the LED subsystem or not. It would
clarify the situation, but if the existing LED drivers don't
stick to this unit then it would make a confusion.



We probably need to convert those intensity to brightness numbers, for
example mapping the intensity value to 0 ~ 255 brightness level and
pass it to LED subsystem.


I think for some devices it wouldn't matter much, but on those that
generally are used as flash the current is known, and thus it should also be
visible in the interface. The conversion from mA to native units could be
done directly, or indirectly through the LED API.

There are a few things to consider though: besides minimum and maximum
values for the current, the V4L2 controls have a step parameter that would
still need to be passed to the control handler when creating the control.
That essentially tells the user space how many levels does the control have.

Care must be taken if converting to LED API units in between mA and native
units so that the values will get through unchanged. On the other hand, I
don't expect to get more levels than 256 either. But even this assumes that
the current selection would be linear.



After analyzing the problem I decided to implement it this way:

1. V4L2 Flash control will use existing LED API for setting/getting
   torch brightness
- V4L2 Flash control handler will take care of
  mA - enum led_brightness conversion
2. New API for flash leds will use mA with int primitive
   as its type
- min, max and step parameters will not be used on the
  LED subsystem level to keep it as simple as possible -
  instead each flash driver will align the brightness
  according to the device constraints; the adjusted value
  will be made available for the LED subsystem after calling
  led_update_flash_brightness function
- min, max and step parameters will be passed to the
  v4l2-flash in the v4l2_flash_ctrl_config structure -
  it was introduced in my RFC.
3. New API for indicator LEDs will be introduced in the led_flash
   module - it will define its units as uA with int primitive
   as the type

If you have any comments please let me know.

Thanks,
Jacek Anaszewski
--
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/8] [media] s5p-jpeg: Add fmt_ver_flag field to the s5p_jpeg_variant structure

2014-04-07 Thread Jacek Anaszewski
Simplify the code by adding fmt_ver_flag field
to the s5p_jpeg_variant structure which allows
to avoid if statement in the s5p_jpeg_find_format
function.

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 |   11 ---
 drivers/media/platform/s5p-jpeg/jpeg-core.h |1 +
 2 files changed, 5 insertions(+), 7 deletions(-)

diff --git a/drivers/media/platform/s5p-jpeg/jpeg-core.c 
b/drivers/media/platform/s5p-jpeg/jpeg-core.c
index 6db4d5e..9b0102d 100644
--- a/drivers/media/platform/s5p-jpeg/jpeg-core.c
+++ b/drivers/media/platform/s5p-jpeg/jpeg-core.c
@@ -959,7 +959,7 @@ static int s5p_jpeg_g_fmt(struct file *file, void *priv, 
struct v4l2_format *f)
 static struct s5p_jpeg_fmt *s5p_jpeg_find_format(struct s5p_jpeg_ctx *ctx,
u32 pixelformat, unsigned int fmt_type)
 {
-   unsigned int k, fmt_flag, ver_flag;
+   unsigned int k, fmt_flag;
 
if (ctx-mode == S5P_JPEG_ENCODE)
fmt_flag = (fmt_type == FMT_TYPE_OUTPUT) ?
@@ -970,16 +970,11 @@ static struct s5p_jpeg_fmt *s5p_jpeg_find_format(struct 
s5p_jpeg_ctx *ctx,
SJPEG_FMT_FLAG_DEC_OUTPUT :
SJPEG_FMT_FLAG_DEC_CAPTURE;
 
-   if (ctx-jpeg-variant-version == SJPEG_S5P)
-   ver_flag = SJPEG_FMT_FLAG_S5P;
-   else
-   ver_flag = SJPEG_FMT_FLAG_EXYNOS4;
-
for (k = 0; k  ARRAY_SIZE(sjpeg_formats); k++) {
struct s5p_jpeg_fmt *fmt = sjpeg_formats[k];
if (fmt-fourcc == pixelformat 
fmt-flags  fmt_flag 
-   fmt-flags  ver_flag) {
+   fmt-flags  ctx-jpeg-variant-fmt_ver_flag) {
return fmt;
}
}
@@ -2103,11 +2098,13 @@ static const struct dev_pm_ops s5p_jpeg_pm_ops = {
 static struct s5p_jpeg_variant s5p_jpeg_drvdata = {
.version= SJPEG_S5P,
.jpeg_irq   = s5p_jpeg_irq,
+   .fmt_ver_flag   = SJPEG_FMT_FLAG_S5P,
 };
 
 static struct s5p_jpeg_variant exynos4_jpeg_drvdata = {
.version= SJPEG_EXYNOS4,
.jpeg_irq   = exynos4_jpeg_irq,
+   .fmt_ver_flag   = SJPEG_FMT_FLAG_EXYNOS4,
 };
 
 static const struct of_device_id samsung_jpeg_match[] = {
diff --git a/drivers/media/platform/s5p-jpeg/jpeg-core.h 
b/drivers/media/platform/s5p-jpeg/jpeg-core.h
index f482dbf..c222436 100644
--- a/drivers/media/platform/s5p-jpeg/jpeg-core.h
+++ b/drivers/media/platform/s5p-jpeg/jpeg-core.h
@@ -118,6 +118,7 @@ struct s5p_jpeg {
 
 struct s5p_jpeg_variant {
unsigned intversion;
+   unsigned intfmt_ver_flag;
irqreturn_t (*jpeg_irq)(int irq, void *priv);
 };
 
-- 
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 2/8] [media] s5p-jpeg: Perform fourcc downgrade only for Exynos4x12 SoCs

2014-04-07 Thread Jacek Anaszewski
Change the driver variant check from is not S5PC210
to is Exynos4 while checking whether YUV format needs
to be downgraded in order to prevent upsampling which
is not supported by Exynos4 SoCs family.

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 |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/media/platform/s5p-jpeg/jpeg-core.c 
b/drivers/media/platform/s5p-jpeg/jpeg-core.c
index 9b0102d..c675c90 100644
--- a/drivers/media/platform/s5p-jpeg/jpeg-core.c
+++ b/drivers/media/platform/s5p-jpeg/jpeg-core.c
@@ -1070,7 +1070,7 @@ static int s5p_jpeg_try_fmt_vid_cap(struct file *file, 
void *priv,
 * If this requirement is not met then downgrade the requested
 * capture format to the one with subsampling equal to the input jpeg.
 */
-   if ((ctx-jpeg-variant-version != SJPEG_S5P) 
+   if ((ctx-jpeg-variant-version == SJPEG_EXYNOS4) 
(ctx-mode == S5P_JPEG_DECODE) 
(fmt-flags  SJPEG_FMT_NON_RGB) 
(fmt-subsampling  ctx-subsampling)) {
-- 
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 3/8] [media] s5p-jpeg: Add m2m_ops field to the s5p_jpeg_variant structure

2014-04-07 Thread Jacek Anaszewski
Simplify the code by adding m2m_ops field to the
s5p_jpeg_variant structure which allows to avoid
if statement in the s5p_jpeg_probe function.

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 
 drivers/media/platform/s5p-jpeg/jpeg-core.h |7 ---
 2 files changed, 8 insertions(+), 11 deletions(-)

diff --git a/drivers/media/platform/s5p-jpeg/jpeg-core.c 
b/drivers/media/platform/s5p-jpeg/jpeg-core.c
index c675c90..4f4dc81 100644
--- a/drivers/media/platform/s5p-jpeg/jpeg-core.c
+++ b/drivers/media/platform/s5p-jpeg/jpeg-core.c
@@ -1566,7 +1566,7 @@ static struct v4l2_m2m_ops s5p_jpeg_m2m_ops = {
.job_abort  = s5p_jpeg_job_abort,
 }
 ;
-static struct v4l2_m2m_ops exynos_jpeg_m2m_ops = {
+static struct v4l2_m2m_ops exynos4_jpeg_m2m_ops = {
.device_run = exynos4_jpeg_device_run,
.job_ready  = s5p_jpeg_job_ready,
.job_abort  = s5p_jpeg_job_abort,
@@ -1849,7 +1849,6 @@ static int s5p_jpeg_probe(struct platform_device *pdev)
 {
struct s5p_jpeg *jpeg;
struct resource *res;
-   struct v4l2_m2m_ops *samsung_jpeg_m2m_ops;
int ret;
 
if (!pdev-dev.of_node)
@@ -1903,13 +1902,8 @@ static int s5p_jpeg_probe(struct platform_device *pdev)
goto clk_get_rollback;
}
 
-   if (jpeg-variant-version == SJPEG_S5P)
-   samsung_jpeg_m2m_ops = s5p_jpeg_m2m_ops;
-   else
-   samsung_jpeg_m2m_ops = exynos_jpeg_m2m_ops;
-
/* mem2mem device */
-   jpeg-m2m_dev = v4l2_m2m_init(samsung_jpeg_m2m_ops);
+   jpeg-m2m_dev = v4l2_m2m_init(jpeg-variant-m2m_ops);
if (IS_ERR(jpeg-m2m_dev)) {
v4l2_err(jpeg-v4l2_dev, Failed to init mem2mem device\n);
ret = PTR_ERR(jpeg-m2m_dev);
@@ -2098,12 +2092,14 @@ static const struct dev_pm_ops s5p_jpeg_pm_ops = {
 static struct s5p_jpeg_variant s5p_jpeg_drvdata = {
.version= SJPEG_S5P,
.jpeg_irq   = s5p_jpeg_irq,
+   .m2m_ops= s5p_jpeg_m2m_ops,
.fmt_ver_flag   = SJPEG_FMT_FLAG_S5P,
 };
 
 static struct s5p_jpeg_variant exynos4_jpeg_drvdata = {
.version= SJPEG_EXYNOS4,
.jpeg_irq   = exynos4_jpeg_irq,
+   .m2m_ops= exynos4_jpeg_m2m_ops,
.fmt_ver_flag   = SJPEG_FMT_FLAG_EXYNOS4,
 };
 
diff --git a/drivers/media/platform/s5p-jpeg/jpeg-core.h 
b/drivers/media/platform/s5p-jpeg/jpeg-core.h
index c222436..3e47863 100644
--- a/drivers/media/platform/s5p-jpeg/jpeg-core.h
+++ b/drivers/media/platform/s5p-jpeg/jpeg-core.h
@@ -117,9 +117,10 @@ struct s5p_jpeg {
 };
 
 struct s5p_jpeg_variant {
-   unsigned intversion;
-   unsigned intfmt_ver_flag;
-   irqreturn_t (*jpeg_irq)(int irq, void *priv);
+   unsigned intversion;
+   unsigned intfmt_ver_flag;
+   struct v4l2_m2m_ops *m2m_ops;
+   irqreturn_t (*jpeg_irq)(int irq, void *priv);
 };
 
 /**
-- 
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 6/8] [media] s5p-jpeg: Fix sysmmu page fault

2014-04-07 Thread Jacek Anaszewski
This patch fixes jpeg sysmmu page fault on Exynos4x12 SoCs.
During encoding Exynos4x12 SoCs access wider memory area
than it results from Image_x and Image_y values written to
the JPEG_IMAGE_SIZE register. In order to avoid sysmmu page
fault apply proper output buffer size alignment.

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 |   46 +--
 1 file changed, 43 insertions(+), 3 deletions(-)

diff --git a/drivers/media/platform/s5p-jpeg/jpeg-core.c 
b/drivers/media/platform/s5p-jpeg/jpeg-core.c
index 8a15c4a..d266e78 100644
--- a/drivers/media/platform/s5p-jpeg/jpeg-core.c
+++ b/drivers/media/platform/s5p-jpeg/jpeg-core.c
@@ -1106,6 +1106,32 @@ static int s5p_jpeg_try_fmt_vid_out(struct file *file, 
void *priv,
return vidioc_try_fmt(f, fmt, ctx, FMT_TYPE_OUTPUT);
 }
 
+static int exynos4_jpeg_get_output_buffer_size(struct s5p_jpeg_ctx *ctx,
+   struct v4l2_format *f,
+   int fmt_depth)
+{
+   struct v4l2_pix_format *pix = f-fmt.pix;
+   u32 pix_fmt = f-fmt.pix.pixelformat;
+   int w = pix-width, h = pix-height, wh_align;
+
+   if (pix_fmt == V4L2_PIX_FMT_RGB32 ||
+   pix_fmt == V4L2_PIX_FMT_NV24 ||
+   pix_fmt == V4L2_PIX_FMT_NV42 ||
+   pix_fmt == V4L2_PIX_FMT_NV12 ||
+   pix_fmt == V4L2_PIX_FMT_NV21 ||
+   pix_fmt == V4L2_PIX_FMT_YUV420)
+   wh_align = 4;
+   else
+   wh_align = 1;
+
+   jpeg_bound_align_image(w, S5P_JPEG_MIN_WIDTH,
+  S5P_JPEG_MAX_WIDTH, wh_align,
+  h, S5P_JPEG_MIN_HEIGHT,
+  S5P_JPEG_MAX_HEIGHT, wh_align);
+
+   return w * h * fmt_depth  3;
+}
+
 static int s5p_jpeg_s_fmt(struct s5p_jpeg_ctx *ct, struct v4l2_format *f)
 {
struct vb2_queue *vq;
@@ -1132,10 +1158,24 @@ static int s5p_jpeg_s_fmt(struct s5p_jpeg_ctx *ct, 
struct v4l2_format *f)
q_data-fmt = s5p_jpeg_find_format(ct, pix-pixelformat, f_type);
q_data-w = pix-width;
q_data-h = pix-height;
-   if (q_data-fmt-fourcc != V4L2_PIX_FMT_JPEG)
-   q_data-size = q_data-w * q_data-h * q_data-fmt-depth  3;
-   else
+   if (q_data-fmt-fourcc != V4L2_PIX_FMT_JPEG) {
+   /*
+* During encoding Exynos4x12 SoCs access wider memory area
+* than it results from Image_x and Image_y values written to
+* the JPEG_IMAGE_SIZE register. In order to avoid sysmmu
+* page fault calculate proper buffer size in such a case.
+*/
+   if (ct-jpeg-variant-version == SJPEG_EXYNOS4 
+   f_type == FMT_TYPE_OUTPUT  ct-mode == S5P_JPEG_ENCODE)
+   q_data-size = exynos4_jpeg_get_output_buffer_size(ct,
+   f,
+   q_data-fmt-depth);
+   else
+   q_data-size = q_data-w * q_data-h *
+   q_data-fmt-depth  3;
+   } else {
q_data-size = pix-sizeimage;
+   }
 
if (f_type == FMT_TYPE_OUTPUT) {
ctrl_subs = v4l2_ctrl_find(ct-ctrl_handler,
-- 
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 4/8] [media] s5p-jpeg: Fix build break when CONFIG_OF is undefined

2014-04-07 Thread Jacek Anaszewski
This patch fixes build break occurring when
there is no support for Device Tree turned on
in the kernel configuration. In such a case only
the driver variant for S5PC210 SoC will be available.

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 |   16 +++-
 1 file changed, 7 insertions(+), 9 deletions(-)

diff --git a/drivers/media/platform/s5p-jpeg/jpeg-core.c 
b/drivers/media/platform/s5p-jpeg/jpeg-core.c
index 4f4dc81..913a027 100644
--- a/drivers/media/platform/s5p-jpeg/jpeg-core.c
+++ b/drivers/media/platform/s5p-jpeg/jpeg-core.c
@@ -1837,7 +1837,7 @@ static irqreturn_t exynos4_jpeg_irq(int irq, void *priv)
return IRQ_HANDLED;
 }
 
-static void *jpeg_get_drv_data(struct platform_device *pdev);
+static void *jpeg_get_drv_data(struct device *dev);
 
 /*
  * 
@@ -1851,15 +1851,12 @@ static int s5p_jpeg_probe(struct platform_device *pdev)
struct resource *res;
int ret;
 
-   if (!pdev-dev.of_node)
-   return -ENODEV;
-
/* JPEG IP abstraction struct */
jpeg = devm_kzalloc(pdev-dev, sizeof(struct s5p_jpeg), GFP_KERNEL);
if (!jpeg)
return -ENOMEM;
 
-   jpeg-variant = jpeg_get_drv_data(pdev);
+   jpeg-variant = jpeg_get_drv_data(pdev-dev);
 
mutex_init(jpeg-lock);
spin_lock_init(jpeg-slock);
@@ -2088,7 +2085,6 @@ static const struct dev_pm_ops s5p_jpeg_pm_ops = {
SET_RUNTIME_PM_OPS(s5p_jpeg_runtime_suspend, s5p_jpeg_runtime_resume, 
NULL)
 };
 
-#ifdef CONFIG_OF
 static struct s5p_jpeg_variant s5p_jpeg_drvdata = {
.version= SJPEG_S5P,
.jpeg_irq   = s5p_jpeg_irq,
@@ -2119,19 +2115,21 @@ static const struct of_device_id samsung_jpeg_match[] = 
{
 
 MODULE_DEVICE_TABLE(of, samsung_jpeg_match);
 
-static void *jpeg_get_drv_data(struct platform_device *pdev)
+static void *jpeg_get_drv_data(struct device *dev)
 {
struct s5p_jpeg_variant *driver_data = NULL;
const struct of_device_id *match;
 
+   if (!IS_ENABLED(CONFIG_OF) || dev-of_node == NULL)
+   return s5p_jpeg_drvdata;
+
match = of_match_node(of_match_ptr(samsung_jpeg_match),
-pdev-dev.of_node);
+   dev-of_node);
if (match)
driver_data = (struct s5p_jpeg_variant *)match-data;
 
return driver_data;
 }
-#endif
 
 static struct platform_driver s5p_jpeg_driver = {
.probe = s5p_jpeg_probe,
-- 
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 8/8] [media] s5p_jpeg: Fix NV12 format entry related to S5C2120 SoC

2014-04-07 Thread Jacek Anaszewski
S5PC210 SoC doesn't support encoding NV12 raw images. Remove
the relavant flag from the respective entry in the sjpeg_formats
array.

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 |3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/media/platform/s5p-jpeg/jpeg-core.c 
b/drivers/media/platform/s5p-jpeg/jpeg-core.c
index 9228bcb..a57a1e0 100644
--- a/drivers/media/platform/s5p-jpeg/jpeg-core.c
+++ b/drivers/media/platform/s5p-jpeg/jpeg-core.c
@@ -192,8 +192,7 @@ static struct s5p_jpeg_fmt sjpeg_formats[] = {
.colplanes  = 2,
.h_align= 4,
.v_align= 4,
-   .flags  = SJPEG_FMT_FLAG_ENC_OUTPUT |
- SJPEG_FMT_FLAG_DEC_CAPTURE |
+   .flags  = SJPEG_FMT_FLAG_DEC_CAPTURE |
  SJPEG_FMT_FLAG_S5P |
  SJPEG_FMT_NON_RGB,
.subsampling= V4L2_JPEG_CHROMA_SUBSAMPLING_420,
-- 
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 5/8] [media] s5p-jpeg: g_selection callback should always succeed

2014-04-07 Thread Jacek Anaszewski
Remove erroneous guard preventing successful execution of
g_selection callback in case the driver variant is different
from SJPEG_S5P.

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 |3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/media/platform/s5p-jpeg/jpeg-core.c 
b/drivers/media/platform/s5p-jpeg/jpeg-core.c
index 913a027..8a15c4a 100644
--- a/drivers/media/platform/s5p-jpeg/jpeg-core.c
+++ b/drivers/media/platform/s5p-jpeg/jpeg-core.c
@@ -1177,8 +1177,7 @@ static int s5p_jpeg_g_selection(struct file *file, void 
*priv,
struct s5p_jpeg_ctx *ctx = fh_to_ctx(priv);
 
if (s-type != V4L2_BUF_TYPE_VIDEO_OUTPUT 
-   s-type != V4L2_BUF_TYPE_VIDEO_CAPTURE 
-   ctx-jpeg-variant-version != SJPEG_S5P)
+   s-type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
return -EINVAL;
 
/* For JPEG blob active == default == bounds */
-- 
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 7/8] [media] s5p_jpeg: Prevent JPEG 4:2:0 YUV 4:2:0 decompression

2014-04-07 Thread Jacek Anaszewski
Prevent decompression of a JPEG 4:2:0 with odd width to
the YUV 4:2:0 compliant formats for Exynos4x12 SoCs and
adjust capture format to RGB565 in such a case. This is
required because the configuration would produce a raw
image with broken luma component.

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 |   24 +---
 1 file changed, 21 insertions(+), 3 deletions(-)

diff --git a/drivers/media/platform/s5p-jpeg/jpeg-core.c 
b/drivers/media/platform/s5p-jpeg/jpeg-core.c
index d266e78..9228bcb 100644
--- a/drivers/media/platform/s5p-jpeg/jpeg-core.c
+++ b/drivers/media/platform/s5p-jpeg/jpeg-core.c
@@ -1064,15 +1064,17 @@ static int s5p_jpeg_try_fmt_vid_cap(struct file *file, 
void *priv,
return -EINVAL;
}
 
+   if ((ctx-jpeg-variant-version != SJPEG_EXYNOS4) ||
+   (ctx-mode != S5P_JPEG_DECODE))
+   goto exit;
+
/*
 * The exynos4x12 device requires resulting YUV image
 * subsampling not to be lower than the input jpeg subsampling.
 * If this requirement is not met then downgrade the requested
 * capture format to the one with subsampling equal to the input jpeg.
 */
-   if ((ctx-jpeg-variant-version == SJPEG_EXYNOS4) 
-   (ctx-mode == S5P_JPEG_DECODE) 
-   (fmt-flags  SJPEG_FMT_NON_RGB) 
+   if ((fmt-flags  SJPEG_FMT_NON_RGB) 
(fmt-subsampling  ctx-subsampling)) {
ret = s5p_jpeg_adjust_fourcc_to_subsampling(ctx-subsampling,
fmt-fourcc,
@@ -1085,6 +1087,22 @@ static int s5p_jpeg_try_fmt_vid_cap(struct file *file, 
void *priv,
FMT_TYPE_CAPTURE);
}
 
+   if (ctx-subsampling == V4L2_JPEG_CHROMA_SUBSAMPLING_420 
+   (ctx-out_q.w  1) 
+   (pix-pixelformat == V4L2_PIX_FMT_NV12 ||
+pix-pixelformat == V4L2_PIX_FMT_NV21 ||
+pix-pixelformat == V4L2_PIX_FMT_YUV420)) {
+   pix-pixelformat = V4L2_PIX_FMT_RGB565;
+   fmt = s5p_jpeg_find_format(ctx, pix-pixelformat,
+   FMT_TYPE_CAPTURE);
+   v4l2_info(ctx-jpeg-v4l2_dev,
+ Adjusted capture fourcc to RGB565. Decompression\n
+ of a JPEG file with 4:2:0 subsampling and odd\n
+ width to the YUV 4:2:0 compliant formats produces\n
+ a raw image with broken luma component.\n);
+   }
+
+exit:
return vidioc_try_fmt(f, fmt, ctx, FMT_TYPE_CAPTURE);
 }
 
-- 
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


Re: [PATCH 7/8] [media] s5p_jpeg: Prevent JPEG 4:2:0 YUV 4:2:0 decompression

2014-04-09 Thread Jacek Anaszewski

On 04/08/2014 09:49 AM, Sachin Kamat wrote:

Hi Jacek,

On 7 April 2014 18:46, Jacek Anaszewski j.anaszew...@samsung.com wrote:

Prevent decompression of a JPEG 4:2:0 with odd width to
the YUV 4:2:0 compliant formats for Exynos4x12 SoCs and
adjust capture format to RGB565 in such a case. This is
required because the configuration would produce a raw
image with broken luma component.

Signed-off-by: Jacek Anaszewski j.anaszew...@samsung.com
Signed-off-by: Kyungmin Park kyungmin.p...@samsung.com
---

snip


+   if (ctx-subsampling == V4L2_JPEG_CHROMA_SUBSAMPLING_420 
+   (ctx-out_q.w  1) 
+   (pix-pixelformat == V4L2_PIX_FMT_NV12 ||
+pix-pixelformat == V4L2_PIX_FMT_NV21 ||
+pix-pixelformat == V4L2_PIX_FMT_YUV420)) {
+   pix-pixelformat = V4L2_PIX_FMT_RGB565;
+   fmt = s5p_jpeg_find_format(ctx, pix-pixelformat,
+   FMT_TYPE_CAPTURE);
+   v4l2_info(ctx-jpeg-v4l2_dev,
+ Adjusted capture fourcc to RGB565. Decompression\n
+ of a JPEG file with 4:2:0 subsampling and odd\n
+ width to the YUV 4:2:0 compliant formats produces\n
+ a raw image with broken luma component.\n);


This could be made a comment in the code rather than a info message.



Hello Sachin,

Thanks for the review. I put it into info message because this is
rather hard for the user to figure out why the adjustment occurred,
bearing in mind that JPEG with the same subsampling and even width
is decompressed properly. This is not a common adjustment like
alignment, and thus in my opinion it requires displaying the
information. Are there some rules that say what cases are relevant
for using the v4l2_info macro?

Regards,
Jacek Anaszewski
--
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 7/8] [media] s5p_jpeg: Prevent JPEG 4:2:0 YUV 4:2:0 decompression

2014-04-09 Thread Jacek Anaszewski

On 04/09/2014 09:56 AM, Sachin Kamat wrote:

Hi Jacek,

On 9 April 2014 13:01, Jacek Anaszewski j.anaszew...@samsung.com wrote:

On 04/08/2014 09:49 AM, Sachin Kamat wrote:





Hello Sachin,

Thanks for the review. I put it into info message because this is
rather hard for the user to figure out why the adjustment occurred,
bearing in mind that JPEG with the same subsampling and even width
is decompressed properly. This is not a common adjustment like
alignment, and thus in my opinion it requires displaying the
information. Are there some rules that say what cases are relevant
for using the v4l2_info macro?


Not really, but generally info messages are concise and detailed explanations
provided as part of comments.



Thanks for the explanation, I will stick to it.

Regards,
Jacek Anaszewski
--
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 6/8] s5p-jpeg: Fix sysmmu page fault

2014-04-10 Thread Jacek Anaszewski
This patch fixes jpeg sysmmu page fault on Exynos4x12 SoCs.
During encoding Exynos4x12 SoCs access wider memory area
than it results from Image_x and Image_y values written to
the JPEG_IMAGE_SIZE register. In order to avoid sysmmu page
fault apply proper output buffer size alignment.

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 |   46 +--
 1 file changed, 43 insertions(+), 3 deletions(-)

diff --git a/drivers/media/platform/s5p-jpeg/jpeg-core.c 
b/drivers/media/platform/s5p-jpeg/jpeg-core.c
index 541f03e..393f3fd 100644
--- a/drivers/media/platform/s5p-jpeg/jpeg-core.c
+++ b/drivers/media/platform/s5p-jpeg/jpeg-core.c
@@ -1106,6 +1106,32 @@ static int s5p_jpeg_try_fmt_vid_out(struct file *file, 
void *priv,
return vidioc_try_fmt(f, fmt, ctx, FMT_TYPE_OUTPUT);
 }
 
+static int exynos4_jpeg_get_output_buffer_size(struct s5p_jpeg_ctx *ctx,
+   struct v4l2_format *f,
+   int fmt_depth)
+{
+   struct v4l2_pix_format *pix = f-fmt.pix;
+   u32 pix_fmt = f-fmt.pix.pixelformat;
+   int w = pix-width, h = pix-height, wh_align;
+
+   if (pix_fmt == V4L2_PIX_FMT_RGB32 ||
+   pix_fmt == V4L2_PIX_FMT_NV24 ||
+   pix_fmt == V4L2_PIX_FMT_NV42 ||
+   pix_fmt == V4L2_PIX_FMT_NV12 ||
+   pix_fmt == V4L2_PIX_FMT_NV21 ||
+   pix_fmt == V4L2_PIX_FMT_YUV420)
+   wh_align = 4;
+   else
+   wh_align = 1;
+
+   jpeg_bound_align_image(w, S5P_JPEG_MIN_WIDTH,
+  S5P_JPEG_MAX_WIDTH, wh_align,
+  h, S5P_JPEG_MIN_HEIGHT,
+  S5P_JPEG_MAX_HEIGHT, wh_align);
+
+   return w * h * fmt_depth  3;
+}
+
 static int s5p_jpeg_s_fmt(struct s5p_jpeg_ctx *ct, struct v4l2_format *f)
 {
struct vb2_queue *vq;
@@ -1132,10 +1158,24 @@ static int s5p_jpeg_s_fmt(struct s5p_jpeg_ctx *ct, 
struct v4l2_format *f)
q_data-fmt = s5p_jpeg_find_format(ct, pix-pixelformat, f_type);
q_data-w = pix-width;
q_data-h = pix-height;
-   if (q_data-fmt-fourcc != V4L2_PIX_FMT_JPEG)
-   q_data-size = q_data-w * q_data-h * q_data-fmt-depth  3;
-   else
+   if (q_data-fmt-fourcc != V4L2_PIX_FMT_JPEG) {
+   /*
+* During encoding Exynos4x12 SoCs access wider memory area
+* than it results from Image_x and Image_y values written to
+* the JPEG_IMAGE_SIZE register. In order to avoid sysmmu
+* page fault calculate proper buffer size in such a case.
+*/
+   if (ct-jpeg-variant-version == SJPEG_EXYNOS4 
+   f_type == FMT_TYPE_OUTPUT  ct-mode == S5P_JPEG_ENCODE)
+   q_data-size = exynos4_jpeg_get_output_buffer_size(ct,
+   f,
+   q_data-fmt-depth);
+   else
+   q_data-size = q_data-w * q_data-h *
+   q_data-fmt-depth  3;
+   } else {
q_data-size = pix-sizeimage;
+   }
 
if (f_type == FMT_TYPE_OUTPUT) {
ctrl_subs = v4l2_ctrl_find(ct-ctrl_handler,
-- 
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/8] s5p-jpeg: g_selection callback should always succeed

2014-04-10 Thread Jacek Anaszewski
Remove erroneous guard preventing successful execution of
g_selection callback in case the driver variant is different
from SJPEG_S5P.

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 |3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/media/platform/s5p-jpeg/jpeg-core.c 
b/drivers/media/platform/s5p-jpeg/jpeg-core.c
index 04260c2..541f03e 100644
--- a/drivers/media/platform/s5p-jpeg/jpeg-core.c
+++ b/drivers/media/platform/s5p-jpeg/jpeg-core.c
@@ -1177,8 +1177,7 @@ static int s5p_jpeg_g_selection(struct file *file, void 
*priv,
struct s5p_jpeg_ctx *ctx = fh_to_ctx(priv);
 
if (s-type != V4L2_BUF_TYPE_VIDEO_OUTPUT 
-   s-type != V4L2_BUF_TYPE_VIDEO_CAPTURE 
-   ctx-jpeg-variant-version != SJPEG_S5P)
+   s-type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
return -EINVAL;
 
/* For JPEG blob active == default == bounds */
-- 
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/8] s5p_jpeg: Prevent JPEG 4:2:0 YUV 4:2:0 decompression

2014-04-10 Thread Jacek Anaszewski
Prevent decompression of a JPEG 4:2:0 with odd width to
the YUV 4:2:0 compliant formats for Exynos4x12 SoCs and
adjust capture format to RGB565 in such a case. This is
required because the configuration would produce a raw
image with broken luma component.

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, 22 insertions(+), 3 deletions(-)

diff --git a/drivers/media/platform/s5p-jpeg/jpeg-core.c 
b/drivers/media/platform/s5p-jpeg/jpeg-core.c
index 393f3fd..24545bd 100644
--- a/drivers/media/platform/s5p-jpeg/jpeg-core.c
+++ b/drivers/media/platform/s5p-jpeg/jpeg-core.c
@@ -1064,15 +1064,17 @@ static int s5p_jpeg_try_fmt_vid_cap(struct file *file, 
void *priv,
return -EINVAL;
}
 
+   if ((ctx-jpeg-variant-version != SJPEG_EXYNOS4) ||
+   (ctx-mode != S5P_JPEG_DECODE))
+   goto exit;
+
/*
 * The exynos4x12 device requires resulting YUV image
 * subsampling not to be lower than the input jpeg subsampling.
 * If this requirement is not met then downgrade the requested
 * capture format to the one with subsampling equal to the input jpeg.
 */
-   if ((ctx-jpeg-variant-version == SJPEG_EXYNOS4) 
-   (ctx-mode == S5P_JPEG_DECODE) 
-   (fmt-flags  SJPEG_FMT_NON_RGB) 
+   if ((fmt-flags  SJPEG_FMT_NON_RGB) 
(fmt-subsampling  ctx-subsampling)) {
ret = s5p_jpeg_adjust_fourcc_to_subsampling(ctx-subsampling,
fmt-fourcc,
@@ -1085,6 +1087,23 @@ static int s5p_jpeg_try_fmt_vid_cap(struct file *file, 
void *priv,
FMT_TYPE_CAPTURE);
}
 
+   /*
+* Decompression of a JPEG file with 4:2:0 subsampling and odd
+* width to the YUV 4:2:0 compliant formats produces a raw image
+* with broken luma component. Adjust capture format to RGB565
+* in such a case.
+*/
+   if (ctx-subsampling == V4L2_JPEG_CHROMA_SUBSAMPLING_420 
+   (ctx-out_q.w  1) 
+   (pix-pixelformat == V4L2_PIX_FMT_NV12 ||
+pix-pixelformat == V4L2_PIX_FMT_NV21 ||
+pix-pixelformat == V4L2_PIX_FMT_YUV420)) {
+   pix-pixelformat = V4L2_PIX_FMT_RGB565;
+   fmt = s5p_jpeg_find_format(ctx, pix-pixelformat,
+   FMT_TYPE_CAPTURE);
+   }
+
+exit:
return vidioc_try_fmt(f, fmt, ctx, FMT_TYPE_CAPTURE);
 }
 
-- 
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/8] s5p-jpeg: Perform fourcc downgrade only for Exynos4x12 SoCs

2014-04-10 Thread Jacek Anaszewski
Change the driver variant check from is not S5PC210
to is Exynos4 while checking whether YUV format needs
to be downgraded in order to prevent upsampling which
is not supported by Exynos4 SoCs family.

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 |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/media/platform/s5p-jpeg/jpeg-core.c 
b/drivers/media/platform/s5p-jpeg/jpeg-core.c
index 3ae9210..d307c0f 100644
--- a/drivers/media/platform/s5p-jpeg/jpeg-core.c
+++ b/drivers/media/platform/s5p-jpeg/jpeg-core.c
@@ -1070,7 +1070,7 @@ static int s5p_jpeg_try_fmt_vid_cap(struct file *file, 
void *priv,
 * If this requirement is not met then downgrade the requested
 * capture format to the one with subsampling equal to the input jpeg.
 */
-   if ((ctx-jpeg-variant-version != SJPEG_S5P) 
+   if ((ctx-jpeg-variant-version == SJPEG_EXYNOS4) 
(ctx-mode == S5P_JPEG_DECODE) 
(fmt-flags  SJPEG_FMT_NON_RGB) 
(fmt-subsampling  ctx-subsampling)) {
-- 
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/8] s5p-jpeg: Add m2m_ops field to the s5p_jpeg_variant structure

2014-04-10 Thread Jacek Anaszewski
Simplify the code by adding m2m_ops field to the
s5p_jpeg_variant structure which allows to avoid
if statement in the s5p_jpeg_probe function.

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 
 drivers/media/platform/s5p-jpeg/jpeg-core.h |7 ---
 2 files changed, 8 insertions(+), 11 deletions(-)

diff --git a/drivers/media/platform/s5p-jpeg/jpeg-core.c 
b/drivers/media/platform/s5p-jpeg/jpeg-core.c
index d307c0f..1b69b69 100644
--- a/drivers/media/platform/s5p-jpeg/jpeg-core.c
+++ b/drivers/media/platform/s5p-jpeg/jpeg-core.c
@@ -1566,7 +1566,7 @@ static struct v4l2_m2m_ops s5p_jpeg_m2m_ops = {
.job_abort  = s5p_jpeg_job_abort,
 }
 ;
-static struct v4l2_m2m_ops exynos_jpeg_m2m_ops = {
+static struct v4l2_m2m_ops exynos4_jpeg_m2m_ops = {
.device_run = exynos4_jpeg_device_run,
.job_ready  = s5p_jpeg_job_ready,
.job_abort  = s5p_jpeg_job_abort,
@@ -1852,7 +1852,6 @@ static int s5p_jpeg_probe(struct platform_device *pdev)
 {
struct s5p_jpeg *jpeg;
struct resource *res;
-   struct v4l2_m2m_ops *samsung_jpeg_m2m_ops;
int ret;
 
if (!pdev-dev.of_node)
@@ -1906,13 +1905,8 @@ static int s5p_jpeg_probe(struct platform_device *pdev)
goto clk_get_rollback;
}
 
-   if (jpeg-variant-version == SJPEG_S5P)
-   samsung_jpeg_m2m_ops = s5p_jpeg_m2m_ops;
-   else
-   samsung_jpeg_m2m_ops = exynos_jpeg_m2m_ops;
-
/* mem2mem device */
-   jpeg-m2m_dev = v4l2_m2m_init(samsung_jpeg_m2m_ops);
+   jpeg-m2m_dev = v4l2_m2m_init(jpeg-variant-m2m_ops);
if (IS_ERR(jpeg-m2m_dev)) {
v4l2_err(jpeg-v4l2_dev, Failed to init mem2mem device\n);
ret = PTR_ERR(jpeg-m2m_dev);
@@ -2101,12 +2095,14 @@ static const struct dev_pm_ops s5p_jpeg_pm_ops = {
 static struct s5p_jpeg_variant s5p_jpeg_drvdata = {
.version= SJPEG_S5P,
.jpeg_irq   = s5p_jpeg_irq,
+   .m2m_ops= s5p_jpeg_m2m_ops,
.fmt_ver_flag   = SJPEG_FMT_FLAG_S5P,
 };
 
 static struct s5p_jpeg_variant exynos4_jpeg_drvdata = {
.version= SJPEG_EXYNOS4,
.jpeg_irq   = exynos4_jpeg_irq,
+   .m2m_ops= exynos4_jpeg_m2m_ops,
.fmt_ver_flag   = SJPEG_FMT_FLAG_EXYNOS4,
 };
 
diff --git a/drivers/media/platform/s5p-jpeg/jpeg-core.h 
b/drivers/media/platform/s5p-jpeg/jpeg-core.h
index c222436..3e47863 100644
--- a/drivers/media/platform/s5p-jpeg/jpeg-core.h
+++ b/drivers/media/platform/s5p-jpeg/jpeg-core.h
@@ -117,9 +117,10 @@ struct s5p_jpeg {
 };
 
 struct s5p_jpeg_variant {
-   unsigned intversion;
-   unsigned intfmt_ver_flag;
-   irqreturn_t (*jpeg_irq)(int irq, void *priv);
+   unsigned intversion;
+   unsigned intfmt_ver_flag;
+   struct v4l2_m2m_ops *m2m_ops;
+   irqreturn_t (*jpeg_irq)(int irq, void *priv);
 };
 
 /**
-- 
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/8] s5p-jpeg: Add fmt_ver_flag field to the s5p_jpeg_variant structure

2014-04-10 Thread Jacek Anaszewski
Simplify the code by adding fmt_ver_flag field
to the s5p_jpeg_variant structure which allows
to avoid if statement in the s5p_jpeg_find_format
function.

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 |   11 ---
 drivers/media/platform/s5p-jpeg/jpeg-core.h |1 +
 2 files changed, 5 insertions(+), 7 deletions(-)

diff --git a/drivers/media/platform/s5p-jpeg/jpeg-core.c 
b/drivers/media/platform/s5p-jpeg/jpeg-core.c
index 8a18972..3ae9210 100644
--- a/drivers/media/platform/s5p-jpeg/jpeg-core.c
+++ b/drivers/media/platform/s5p-jpeg/jpeg-core.c
@@ -959,7 +959,7 @@ static int s5p_jpeg_g_fmt(struct file *file, void *priv, 
struct v4l2_format *f)
 static struct s5p_jpeg_fmt *s5p_jpeg_find_format(struct s5p_jpeg_ctx *ctx,
u32 pixelformat, unsigned int fmt_type)
 {
-   unsigned int k, fmt_flag, ver_flag;
+   unsigned int k, fmt_flag;
 
if (ctx-mode == S5P_JPEG_ENCODE)
fmt_flag = (fmt_type == FMT_TYPE_OUTPUT) ?
@@ -970,16 +970,11 @@ static struct s5p_jpeg_fmt *s5p_jpeg_find_format(struct 
s5p_jpeg_ctx *ctx,
SJPEG_FMT_FLAG_DEC_OUTPUT :
SJPEG_FMT_FLAG_DEC_CAPTURE;
 
-   if (ctx-jpeg-variant-version == SJPEG_S5P)
-   ver_flag = SJPEG_FMT_FLAG_S5P;
-   else
-   ver_flag = SJPEG_FMT_FLAG_EXYNOS4;
-
for (k = 0; k  ARRAY_SIZE(sjpeg_formats); k++) {
struct s5p_jpeg_fmt *fmt = sjpeg_formats[k];
if (fmt-fourcc == pixelformat 
fmt-flags  fmt_flag 
-   fmt-flags  ver_flag) {
+   fmt-flags  ctx-jpeg-variant-fmt_ver_flag) {
return fmt;
}
}
@@ -2106,11 +2101,13 @@ static const struct dev_pm_ops s5p_jpeg_pm_ops = {
 static struct s5p_jpeg_variant s5p_jpeg_drvdata = {
.version= SJPEG_S5P,
.jpeg_irq   = s5p_jpeg_irq,
+   .fmt_ver_flag   = SJPEG_FMT_FLAG_S5P,
 };
 
 static struct s5p_jpeg_variant exynos4_jpeg_drvdata = {
.version= SJPEG_EXYNOS4,
.jpeg_irq   = exynos4_jpeg_irq,
+   .fmt_ver_flag   = SJPEG_FMT_FLAG_EXYNOS4,
 };
 
 static const struct of_device_id samsung_jpeg_match[] = {
diff --git a/drivers/media/platform/s5p-jpeg/jpeg-core.h 
b/drivers/media/platform/s5p-jpeg/jpeg-core.h
index f482dbf..c222436 100644
--- a/drivers/media/platform/s5p-jpeg/jpeg-core.h
+++ b/drivers/media/platform/s5p-jpeg/jpeg-core.h
@@ -118,6 +118,7 @@ struct s5p_jpeg {
 
 struct s5p_jpeg_variant {
unsigned intversion;
+   unsigned intfmt_ver_flag;
irqreturn_t (*jpeg_irq)(int irq, void *priv);
 };
 
-- 
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/8] s5p-jpeg: Fix build break when CONFIG_OF is undefined

2014-04-10 Thread Jacek Anaszewski
This patch fixes build break occurring when
there is no support for Device Tree turned on
in the kernel configuration. In such a case only
the driver variant for S5PC210 SoC will be available.

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, 8 insertions(+), 10 deletions(-)

diff --git a/drivers/media/platform/s5p-jpeg/jpeg-core.c 
b/drivers/media/platform/s5p-jpeg/jpeg-core.c
index 1b69b69..04260c2 100644
--- a/drivers/media/platform/s5p-jpeg/jpeg-core.c
+++ b/drivers/media/platform/s5p-jpeg/jpeg-core.c
@@ -1840,7 +1840,7 @@ static irqreturn_t exynos4_jpeg_irq(int irq, void *priv)
return IRQ_HANDLED;
 }
 
-static void *jpeg_get_drv_data(struct platform_device *pdev);
+static void *jpeg_get_drv_data(struct device *dev);
 
 /*
  * 
@@ -1854,15 +1854,12 @@ static int s5p_jpeg_probe(struct platform_device *pdev)
struct resource *res;
int ret;
 
-   if (!pdev-dev.of_node)
-   return -ENODEV;
-
/* JPEG IP abstraction struct */
jpeg = devm_kzalloc(pdev-dev, sizeof(struct s5p_jpeg), GFP_KERNEL);
if (!jpeg)
return -ENOMEM;
 
-   jpeg-variant = jpeg_get_drv_data(pdev);
+   jpeg-variant = jpeg_get_drv_data(pdev-dev);
 
mutex_init(jpeg-lock);
spin_lock_init(jpeg-slock);
@@ -2091,7 +2088,6 @@ static const struct dev_pm_ops s5p_jpeg_pm_ops = {
SET_RUNTIME_PM_OPS(s5p_jpeg_runtime_suspend, s5p_jpeg_runtime_resume, 
NULL)
 };
 
-#ifdef CONFIG_OF
 static struct s5p_jpeg_variant s5p_jpeg_drvdata = {
.version= SJPEG_S5P,
.jpeg_irq   = s5p_jpeg_irq,
@@ -2122,19 +2118,21 @@ static const struct of_device_id samsung_jpeg_match[] = 
{
 
 MODULE_DEVICE_TABLE(of, samsung_jpeg_match);
 
-static void *jpeg_get_drv_data(struct platform_device *pdev)
+static void *jpeg_get_drv_data(struct device *dev)
 {
struct s5p_jpeg_variant *driver_data = NULL;
const struct of_device_id *match;
 
-   match = of_match_node(of_match_ptr(samsung_jpeg_match),
-pdev-dev.of_node);
+   if (!IS_ENABLED(CONFIG_OF) || !dev-of_node)
+   return s5p_jpeg_drvdata;
+
+   match = of_match_node(samsung_jpeg_match, dev-of_node);
+
if (match)
driver_data = (struct s5p_jpeg_variant *)match-data;
 
return driver_data;
 }
-#endif
 
 static struct platform_driver s5p_jpeg_driver = {
.probe = s5p_jpeg_probe,
-- 
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/8] s5p_jpeg: Fix NV12 format entry related to S5C2120 SoC

2014-04-10 Thread Jacek Anaszewski
S5PC210 SoC doesn't support encoding NV12 raw images. Remove
the relavant flag from the respective entry in the sjpeg_formats
array.

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 |3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/media/platform/s5p-jpeg/jpeg-core.c 
b/drivers/media/platform/s5p-jpeg/jpeg-core.c
index 24545bd..2c8481e 100644
--- a/drivers/media/platform/s5p-jpeg/jpeg-core.c
+++ b/drivers/media/platform/s5p-jpeg/jpeg-core.c
@@ -192,8 +192,7 @@ static struct s5p_jpeg_fmt sjpeg_formats[] = {
.colplanes  = 2,
.h_align= 4,
.v_align= 4,
-   .flags  = SJPEG_FMT_FLAG_ENC_OUTPUT |
- SJPEG_FMT_FLAG_DEC_CAPTURE |
+   .flags  = SJPEG_FMT_FLAG_DEC_CAPTURE |
  SJPEG_FMT_FLAG_S5P |
  SJPEG_FMT_NON_RGB,
.subsampling= V4L2_JPEG_CHROMA_SUBSAMPLING_420,
-- 
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 v3 5/5] media: Add registration helpers for V4L2 flash sub-devices

2014-04-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
---
 drivers/media/v4l2-core/Kconfig  |   10 +
 drivers/media/v4l2-core/Makefile |2 +
 drivers/media/v4l2-core/v4l2-flash.c |  393 ++
 include/media/v4l2-flash.h   |  119 ++
 4 files changed, 524 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 2189bfb..1f8514d 100644
--- a/drivers/media/v4l2-core/Kconfig
+++ b/drivers/media/v4l2-core/Kconfig
@@ -35,6 +35,16 @@ config V4L2_MEM2MEM_DEV
 tristate
 depends on VIDEOBUF2_CORE
 
+# Used by LED subsystem flash drivers
+config V4L2_FLASH
+   bool Enable support for Flash sub-devices
+   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 c6ae7ba..8e37ab4 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) += 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..f1be332
--- /dev/null
+++ b/drivers/media/v4l2-core/v4l2-flash.c
@@ -0,0 +1,393 @@
+/*
+ * 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/leds_flash.h
+#include media/v4l2-ctrls.h
+#include media/v4l2-dev.h
+#include media/v4l2-device.h
+#include media/v4l2-event.h
+#include media/v4l2-ioctl.h
+#include media/v4l2-flash.h
+
+static inline enum led_brightness v4l2_flash_intensity_to_led_brightness(
+   struct led_ctrl *config,
+   u32 intensity)
+{
+   return intensity / config-step;
+}
+
+static inline u32 v4l2_flash_led_brightness_to_intensity(
+   struct led_ctrl *config,
+   enum led_brightness brightness)
+{
+   return brightness * config-step;
+}
+
+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 *led_cdev = v4l2_flash-led_cdev;
+   struct led_flash *flash = led_cdev-flash;
+   struct v4l2_flash_ctrl *ctrl = v4l2_flash-ctrl;
+   u32 fault;
+   int ret;
+
+   switch (c-id) {
+   case V4L2_CID_FLASH_TORCH_INTENSITY:
+   if (ctrl-led_mode-val == V4L2_FLASH_LED_MODE_TORCH) {
+   ret = v4l2_call_flash_op(brightness_update, led_cdev);
+   if (ret  0)
+   return ret;
+   ctrl-torch_intensity-val =
+   v4l2_flash_led_brightness_to_intensity(
+   led_cdev-brightness_ctrl,
+   led_cdev-brightness);
+   }
+   return 0;
+   case V4L2_CID_FLASH_INTENSITY:
+   ret = v4l2_call_flash_op(flash_brightness_update, led_cdev);
+   if (ret  0)
+   return ret;
+   /* no conversion is needed */
+   c-val = flash-brightness.val;
+   return 0;
+   case V4L2_CID_FLASH_INDICATOR_INTENSITY:
+   ret = v4l2_call_flash_op(indicator_brightness_update, led_cdev);
+   if (ret  0)
+   return ret;
+   /* no conversion is needed */
+   c-val = flash-indicator_brightness-val;
+   return 0;
+   case V4L2_CID_FLASH_STROBE_STATUS:
+   ret = v4l2_call_flash_op(strobe_get, led_cdev);
+   if (ret  0

[PATCH/RFC v3 4/5] DT: Add documentation for the mfd Maxim max77693 flash cell

2014-04-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 |   57 
 1 file changed, 57 insertions(+)

diff --git a/Documentation/devicetree/bindings/mfd/max77693.txt 
b/Documentation/devicetree/bindings/mfd/max77693.txt
index 11921cc..f58d192 100644
--- a/Documentation/devicetree/bindings/mfd/max77693.txt
+++ b/Documentation/devicetree/bindings/mfd/max77693.txt
@@ -27,6 +27,53 @@ 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
+
+Optional properties of led-flash node:
+- maxim,iout : Array of four maximum intensities in microamperes of the current
+   in order: flash1, flash2, torch1, torch2.
+   Range:
+   flash - 15625 - 100 (max 625000 if boost mode
+is enabled for both outputs),
+   torch - 15625 - 25.
+- maxim,trigger : Array of flags indicating which trigger can activate given 
led
+   in order: flash1, flash2, torch1, torch2.
+   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,timeout : Array of timeouts in microseconds after which leds are
+   turned off in order: flash, torch.
+   Range:
+   flash: 62500 - 100,
+   torch: 0 (no timeout) - 15728000.
+- maxim,boost-mode : Array of the flash boost modes in order: flash1, flash2.
+   If both current outputs are connected then the same non-zero value
+   has to be set for them. This setting influences also maximum
+   current value for torch and flash modes:
+   flash1 and flash2 set to 1 or 2:
+   - max flash current: 1250 mA (625 mA on each output)
+   - max torch current: 500 mA (250 mA on each output)
+   flash1 or flash2 set to 0:
+   - max flash current: 1000 mA
+   - max torch current: 250 mA
+   Possible values:
+   0 - no boost,
+   1 - adaptive mode,
+   2 - fixed mode.
+- 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 +99,14 @@ Example:
regulator-boot-on;
};
};
+   led_flash: led-flash {
+   compatible = maxim,max77693-flash;
+   maxim,iout = 625000 625000 25 25;
+   maxim,trigger = 5 5 6 6;
+   maxim,trigger-type = 0 1;
+   maxim,timeout = 50 0;
+   maxim,boost-mode = 1 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 v3 1/5] leds: Add sysfs and kernel internal API for flash LEDs

2014-04-11 Thread Jacek Anaszewski
Some LED devices support two operation modes - torch and
flash. This patch provides support for flash LED devices
in the LED subsystem by introducing new sysfs attributes
and kernel internal interface. The attributes being
introduced are: flash_brightness, flash_strobe, flash_timeout,
max_flash_timeout, max_flash_brightness, flash_fault and
optional external_strobe, indicator_brightness and
max_indicator_btightness. All the flash related features
are placed in a separate module.
The modifications aim to be compatible with V4L2 framework
requirements related to the flash devices management. The
design assumes that V4L2 sub-device can take of the LED class
device control and communicate with it through the kernel
internal interface. When V4L2 Flash sub-device file is
opened, the LED class device sysfs interface is made
unavailable.

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|8 +
 drivers/leds/Makefile   |1 +
 drivers/leds/led-class.c|   36 ++-
 drivers/leds/led-flash.c|  627 +++
 drivers/leds/led-triggers.c |   16 +-
 drivers/leds/leds.h |6 +
 include/linux/leds.h|   50 +++-
 include/linux/leds_flash.h  |  252 +
 8 files changed, 982 insertions(+), 14 deletions(-)
 create mode 100644 drivers/leds/led-flash.c
 create mode 100644 include/linux/leds_flash.h

diff --git a/drivers/leds/Kconfig b/drivers/leds/Kconfig
index 2062682..1e1c81f 100644
--- a/drivers/leds/Kconfig
+++ b/drivers/leds/Kconfig
@@ -19,6 +19,14 @@ config LEDS_CLASS
  This option enables the led sysfs class in /sys/class/leds.  You'll
  need this to do anything useful with LEDs.  If unsure, say N.
 
+config LEDS_CLASS_FLASH
+   tristate Flash LEDs Support
+   depends on LEDS_CLASS
+   help
+ This option enables support for flash LED devices. Say Y if you
+ want to use flash specific features of a LED device, if they
+ are supported.
+
 comment LED drivers
 
 config LEDS_88PM860X
diff --git a/drivers/leds/Makefile b/drivers/leds/Makefile
index 3cd76db..8861b86 100644
--- a/drivers/leds/Makefile
+++ b/drivers/leds/Makefile
@@ -2,6 +2,7 @@
 # LED Core
 obj-$(CONFIG_NEW_LEDS) += led-core.o
 obj-$(CONFIG_LEDS_CLASS)   += led-class.o
+obj-$(CONFIG_LEDS_CLASS_FLASH) += led-flash.o
 obj-$(CONFIG_LEDS_TRIGGERS)+= led-triggers.o
 
 # LED Platform Drivers
diff --git a/drivers/leds/led-class.c b/drivers/leds/led-class.c
index f37d63c..58f16c3 100644
--- a/drivers/leds/led-class.c
+++ b/drivers/leds/led-class.c
@@ -9,15 +9,16 @@
  * 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/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
 
@@ -45,28 +46,38 @@ 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);
+
+   if (led_sysfs_is_locked(led_cdev)) {
+   ret = -EBUSY;
+   goto unlock;
+   }
 
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);
+   ret = size;
 
-   return size;
+unlock:
+   mutex_unlock(led_cdev-led_lock);
+   return ret;
 }
 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);
@@ -174,6 +185,8 @@ EXPORT_SYMBOL_GPL(led_classdev_suspend);
 void led_classdev_resume(struct led_classdev *led_cdev)
 {
led_cdev-brightness_set(led_cdev, led_cdev-brightness);
+   if (led_cdev-flash_resume)
+   led_cdev-flash_resume(led_cdev);
led_cdev-flags = ~LED_SUSPENDED;
 }
 EXPORT_SYMBOL_GPL(led_classdev_resume);
@@ -218,6 +231,7 @@ int led_classdev_register(struct device *parent, struct 
led_classdev *led_cdev)
 #ifdef

[PATCH/RFC v3 3/5] leds: Add support for max77693 mfd flash cell

2014-04-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: Andrzej Hajda a.ha...@samsung.com
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: SangYoung Son hello@smasung.com
Cc: Samuel Ortiz sa...@linux.intel.com
Cc: Lee Jones lee.jo...@linaro.org
---
 drivers/leds/Kconfig |   10 +
 drivers/leds/Makefile|1 +
 drivers/leds/leds-max77693.c |  794 ++
 drivers/mfd/max77693.c   |2 +-
 include/linux/mfd/max77693.h |   38 ++
 5 files changed, 844 insertions(+), 1 deletion(-)
 create mode 100644 drivers/leds/leds-max77693.c

diff --git a/drivers/leds/Kconfig b/drivers/leds/Kconfig
index 1e1c81f..b2152a6 100644
--- a/drivers/leds/Kconfig
+++ b/drivers/leds/Kconfig
@@ -462,6 +462,16 @@ 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
+   depends on OF
+   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 8861b86..64f6234 100644
--- a/drivers/leds/Makefile
+++ b/drivers/leds/Makefile
@@ -52,6 +52,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..979736c
--- /dev/null
+++ b/drivers/leds/leds-max77693.c
@@ -0,0 +1,794 @@
+/*
+ * Copyright (C) 2014, Samsung Electronics Co., Ltd.
+ *
+ * Authors: Andrzej Hajda a.ha...@samsung.com
+ *  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 asm/div64.h
+#include linux/leds_flash.h
+#include linux/module.h
+#include linux/mutex.h
+#include linux/platform_device.h
+#include linux/slab.h
+#include media/v4l2-flash.h
+#include linux/workqueue.h
+#include linux/mfd/max77693.h
+#include linux/mfd/max77693-private.h
+
+#define MAX77693_LED_NAME  max77693-flash
+
+#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 MAX77693_FLASH_VOUT_STEP   25
+#define MAX77693_FLASH_VOUT_RMIN   0x0c
+
+#define MAX77693_LED_STATUS_FLASH_ON   (1  3)
+#define MAX77693_LED_STATUS_TORCH_ON   (1  2

[PATCH/RFC v3 2/5] leds: Improve and export led_update_brightness function

2014-04-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 brightness_get callback
error code and adds the 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  |   16 
 include/linux/leds.h |   10 ++
 3 files changed, 26 insertions(+), 6 deletions(-)

diff --git a/drivers/leds/led-class.c b/drivers/leds/led-class.c
index 58f16c3..7f285d7 100644
--- a/drivers/leds/led-class.c
+++ b/drivers/leds/led-class.c
@@ -24,12 +24,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 71b40d3..376166c 100644
--- a/drivers/leds/led-core.c
+++ b/drivers/leds/led-core.c
@@ -126,3 +126,19 @@ void led_set_brightness(struct led_classdev *led_cdev,
__led_set_brightness(led_cdev, brightness);
 }
 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);
diff --git a/include/linux/leds.h b/include/linux/leds.h
index a794817..d085c21 100644
--- a/include/linux/leds.h
+++ b/include/linux/leds.h
@@ -174,6 +174,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_is_locked
-- 
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 v3 0/5] LED / flash API integration

2014-04-11 Thread Jacek Anaszewski
This is is the third 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 next-20140328

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:
- flash_brightness
- max_flash_brightness
- indicator_brightness
- max_indicator_brightness
- flash_timeout
- max_flash_timeout
- flash_strobe
- flash_fault
- external_strobe
and exposes kernel internal API
- led_set_flash_strobe
- led_get_flash_strobe
- 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
- 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 driver for the flash cell of the MAX77693 mfd
* the driver exploits the newly introduced mechanism
- Update of the max77693.txt 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

Thanks,
Jacek Anaszewski

[1] http://www.spinics.net/lists/linux-media/msg69253.html

Jacek Anaszewski (5):
  leds: Add sysfs and kernel internal API for flash LEDs
  leds: Improve and export led_update_brightness function
  leds: Add support for max77693 mfd flash cell
  DT: Add documentation for the mfd Maxim max77693 flash cell
  media: Add registration helpers for V4L2 flash sub-devices

 Documentation/devicetree/bindings/mfd/max77693.txt |   57 ++
 drivers/leds/Kconfig   |   18 +
 drivers/leds/Makefile  |2 +
 drivers/leds/led-class.c   |   42 +-
 drivers/leds/led-core.c|   16 +
 drivers/leds/led-flash.c   |  627 
 drivers/leds/led-triggers.c|   16 +-
 drivers/leds/leds-max77693.c   |  794 
 drivers/leds/leds.h|6 +
 drivers/media/v4l2-core/Kconfig|   10 +
 drivers/media/v4l2-core/Makefile   |2 +
 drivers/media/v4l2-core/v4l2-flash.c   |  393 ++
 drivers/mfd/max77693.c |2 +-
 include/linux/leds.h   |   60 +-
 include/linux/leds_flash.h |  252 +++
 include/linux/mfd/max77693.h   |   38 +
 include/media/v4l2-flash.h |  119 +++
 17 files changed, 2433 insertions(+), 21 deletions(-)
 create mode 100644 drivers/leds/led-flash.c
 create mode 100644 drivers/leds/leds-max77693.c
 create mode 100644 drivers/media/v4l2-core/v4l2-flash.c
 create mode 100644 include/linux/leds_flash.h
 create mode 100644 include/media/v4l2-flash.h

-- 
1.7.9.5

--
To unsubscribe from this list: send the line unsubscribe linux-media

Re: [PATCH/RFC v3 5/5] media: Add registration helpers for V4L2 flash sub-devices

2014-04-17 Thread Jacek Anaszewski
 = v4l2_subdev_to_v4l2_flash(sd);
+   struct led_classdev *led_cdev = v4l2_flash-led_cdev;
+
+   mutex_lock(led_cdev-led_lock);
+   v4l2_call_flash_op(sysfs_unlock, led_cdev);
+   mutex_unlock(led_cdev-led_lock);
+
+   return 0;
+}
+
+static const struct v4l2_subdev_internal_ops v4l2_flash_subdev_internal_ops = {
+   .open = v4l2_flash_open,
+   .close = v4l2_flash_close,
+};
+
+static struct v4l2_subdev_ops v4l2_flash_subdev_ops = {
+};
+
+int v4l2_flash_init(struct led_classdev *led_cdev,
+   const struct v4l2_flash_ops *ops)
+{
+   struct v4l2_flash *flash = led_cdev-flash-v4l2_flash;
+   struct v4l2_subdev *sd = flash-subdev;
+   int ret;
+
+   if (!led_cdev || !ops)
+   return -EINVAL;
+
+   flash-led_cdev = led_cdev;
+   sd-dev = led_cdev-dev-parent;
+   v4l2_subdev_init(sd, v4l2_flash_subdev_ops);
+   sd-internal_ops = v4l2_flash_subdev_internal_ops;
+   sd-flags |= V4L2_SUBDEV_FL_HAS_DEVNODE;
+   snprintf(sd-name, sizeof(sd-name), led_cdev-name);


It'd be nice to have the bus address in the name as well. But that would
belong to the driver which calls v4l2_flash_init(). The existing flash
controller drivers probably don't do this but many sensor drivers already
do. The name is expected to be unique in the media device.


Will cover this.


+   flash-ops = ops;
+
+   ret = v4l2_flash_init_controls(flash);
+   if (ret  0)
+   goto err_init_controls;
+
+   ret = media_entity_init(sd-entity, 0, NULL, 0);
+   if (ret  0)
+   goto err_init_entity;
+
+   sd-entity.type = MEDIA_ENT_T_V4L2_SUBDEV_FLASH;
+
+   ret = v4l2_async_register_subdev(sd);
+   if (ret  0)
+   goto err_init_entity;
+
+   return 0;
+
+err_init_entity:
+   media_entity_cleanup(sd-entity);
+err_init_controls:
+   v4l2_ctrl_handler_free(sd-ctrl_handler);
+   return -EINVAL;
+}
+EXPORT_SYMBOL_GPL(v4l2_flash_init);
+
+void v4l2_flash_release(struct led_classdev *led_cdev)
+{
+   struct v4l2_flash *flash = led_cdev-flash-v4l2_flash;
+
+   v4l2_ctrl_handler_free(flash-subdev.ctrl_handler);
+   v4l2_async_unregister_subdev(flash-subdev);
+   media_entity_cleanup(flash-subdev.entity);
+}
+EXPORT_SYMBOL_GPL(v4l2_flash_release);
diff --git a/include/media/v4l2-flash.h b/include/media/v4l2-flash.h
new file mode 100644
index 000..fe16ddd
--- /dev/null
+++ b/include/media/v4l2-flash.h
@@ -0,0 +1,119 @@
+/*
+ * 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.
+ */
+
+#ifndef _V4L2_FLASH_H
+#define _V4L2_FLASH_H
+
+#include media/v4l2-ctrls.h
+#include media/v4l2-device.h
+#include media/v4l2-dev.h
+#include media/v4l2-event.h
+#include media/v4l2-ioctl.h
+
+#define v4l2_call_flash_op(op, args...)\
+   ((v4l2_flash)-ops-op(args)) \


Extra backslash above.

I don't think you should assume the caller will have a local variable called
v4l2_flash. :-)


I assumed that as this macro is only for the module internal use
and aim at simplifying the calling code it can be implemented that way.
But when I look at it now it indeed doesn't seem reasonable.


+struct led_classdev;
+enum led_brightness;
+
+struct v4l2_flash_ops {
+   void(*brightness_set)(struct led_classdev *led_cdev,
+   enum led_brightness brightness);
+   int (*brightness_update)(struct led_classdev *led_cdev);
+   int (*flash_brightness_set)(struct led_classdev *led_cdev,
+   u32 brightness);
+   int (*flash_brightness_update)(struct led_classdev *led_cdev);
+   int (*strobe_set)(struct led_classdev *led_cdev,
+   bool state);
+   int (*strobe_get)(struct led_classdev *led_cdev);
+   int (*timeout_set)(struct led_classdev *led_cdev,
+   u32 timeout);
+   int (*indicator_brightness_set)(struct led_classdev *led_cdev,
+   u32 brightness);
+   int (*indicator_brightness_update)(struct led_classdev *led_cdev);
+   int (*external_strobe_set)(struct led_classdev *led_cdev,
+   bool enable);
+   int (*fault_get)(struct led_classdev *led_cdev,
+   u32 *fault);
+   void(*sysfs_lock)(struct led_classdev *led_cdev);
+   void(*sysfs_unlock)(struct led_classdev *led_cdev);
+};
+
+/**
+ * struct v4l2_flash_ctrl - controls that define the sub-dev's state
+ * @source:V4L2_CID_FLASH_STROBE_SOURCE control
+ * @led_mode

Re: [PATCH/RFC v3 3/5] leds: Add support for max77693 mfd flash cell

2014-04-17 Thread Jacek Anaszewski

Hi Sakari,

Thanks for the review.

On 04/16/2014 07:26 PM, Sakari Ailus wrote:

Hi Jacek,

Thanks for the patch! Comments below.

On Fri, Apr 11, 2014 at 04:56:54PM +0200, Jacek Anaszewski wrote:

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: Andrzej Hajda a.ha...@samsung.com
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: SangYoung Son hello@smasung.com
Cc: Samuel Ortiz sa...@linux.intel.com
Cc: Lee Jones lee.jo...@linaro.org
---
  drivers/leds/Kconfig |   10 +
  drivers/leds/Makefile|1 +
  drivers/leds/leds-max77693.c |  794 ++
  drivers/mfd/max77693.c   |2 +-
  include/linux/mfd/max77693.h |   38 ++
  5 files changed, 844 insertions(+), 1 deletion(-)
  create mode 100644 drivers/leds/leds-max77693.c

diff --git a/drivers/leds/Kconfig b/drivers/leds/Kconfig
index 1e1c81f..b2152a6 100644
--- a/drivers/leds/Kconfig
+++ b/drivers/leds/Kconfig
@@ -462,6 +462,16 @@ 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
+   depends on OF
+   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 8861b86..64f6234 100644
--- a/drivers/leds/Makefile
+++ b/drivers/leds/Makefile
@@ -52,6 +52,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..979736c
--- /dev/null
+++ b/drivers/leds/leds-max77693.c
@@ -0,0 +1,794 @@
+/*
+ * Copyright (C) 2014, Samsung Electronics Co., Ltd.
+ *
+ * Authors: Andrzej Hajda a.ha...@samsung.com
+ *  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 asm/div64.h
+#include linux/leds_flash.h
+#include linux/module.h
+#include linux/mutex.h
+#include linux/platform_device.h
+#include linux/slab.h
+#include media/v4l2-flash.h


I guess this should be last in the list.


+#include linux/workqueue.h
+#include linux/mfd/max77693.h
+#include linux/mfd/max77693-private.h
+
+#define MAX77693_LED_NAME  max77693-flash
+
+#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_MIN

Re: [PATCH/RFC v3 5/5] media: Add registration helpers for V4L2 flash sub-devices

2014-04-28 Thread Jacek Anaszewski

Hi Sakari,

On 04/23/2014 05:24 PM, Sakari Ailus wrote:

Hi Jacek,

On Thu, Apr 17, 2014 at 10:26:44AM +0200, Jacek Anaszewski wrote:

Hi Sakari,

Thanks for the review.

On 04/16/2014 08:21 PM, Sakari Ailus wrote:

Hi Jacek,

Thanks for the update!


[...]

+static inline enum led_brightness v4l2_flash_intensity_to_led_brightness(
+   struct led_ctrl *config,
+   u32 intensity)


Fits on a single line.


+{
+   return intensity / config-step;


Shouldn't you first decrement the minimum before the division?


Brightness level 0 means that led is off. Let's consider following case:

intensity - 15625
config-step - 15625
intensity / config-step = 1 (the lowest possible current level)


In V4L2 controls the minimum is not off, and zero might not be a possible
value since minimum isn't divisible by step.

I wonder how to best take that into account.


I've assumed that in MODE_TORCH a led is always on. Switching
the mode to MODE_FLASH or MODE_OFF turns the led off.
This way we avoid the problem with converting 0 uA value to
led_brightness, as available torch brightness levels start from
the minimum current level value and turning the led off is
accomplished on transition to MODE_OFF or MODE_FLASH, by
calling brightness_set op with led_brightness = 0.

[...]


+/*
+ * V4L2 subdev internal operations
+ */
+
+static int v4l2_flash_open(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh)
+{
+   struct v4l2_flash *v4l2_flash = v4l2_subdev_to_v4l2_flash(sd);
+   struct led_classdev *led_cdev = v4l2_flash-led_cdev;
+
+   mutex_lock(led_cdev-led_lock);
+   v4l2_call_flash_op(sysfs_lock, led_cdev);


Have you thought about device power management yet?


Having in mind that the V4L2 Flash sub-device is only a wrapper
for LED driver, shouldn't power management be left to the
drivers?


How does the LED controller driver know it needs to power the device up in
that case?

I think an s_power() op which uses PM runtime to set the power state until
V4L2 sub-device switches to it should be enough. But I'm fine leaving it out
from this patchset.



This solution looks reasonable.

Regards,
Jacek Anaszewski


--
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/RFC v3 3/5] leds: Add support for max77693 mfd flash cell

2014-04-28 Thread Jacek Anaszewski

Hi Sakari,

On 04/23/2014 05:52 PM, Sakari Ailus wrote:

Hi Jacek,

Thanks for the answers to my comments! :-)

On Thu, Apr 17, 2014 at 11:23:06AM +0200, Jacek Anaszewski wrote:

On 04/16/2014 07:26 PM, Sakari Ailus wrote:

Hi Jacek,

Thanks for the patch! Comments below.

On Fri, Apr 11, 2014 at 04:56:54PM +0200, Jacek Anaszewski wrote:

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: Andrzej Hajda a.ha...@samsung.com
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: SangYoung Son hello@smasung.com
Cc: Samuel Ortiz sa...@linux.intel.com
Cc: Lee Jones lee.jo...@linaro.org
---
  drivers/leds/Kconfig |   10 +
  drivers/leds/Makefile|1 +
  drivers/leds/leds-max77693.c |  794 ++
  drivers/mfd/max77693.c   |2 +-
  include/linux/mfd/max77693.h |   38 ++
  5 files changed, 844 insertions(+), 1 deletion(-)
  create mode 100644 drivers/leds/leds-max77693.c

diff --git a/drivers/leds/Kconfig b/drivers/leds/Kconfig
index 1e1c81f..b2152a6 100644
--- a/drivers/leds/Kconfig
+++ b/drivers/leds/Kconfig
@@ -462,6 +462,16 @@ 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
+   depends on OF
+   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 8861b86..64f6234 100644
--- a/drivers/leds/Makefile
+++ b/drivers/leds/Makefile
@@ -52,6 +52,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..979736c
--- /dev/null
+++ b/drivers/leds/leds-max77693.c
@@ -0,0 +1,794 @@
+/*
+ * Copyright (C) 2014, Samsung Electronics Co., Ltd.
+ *
+ * Authors: Andrzej Hajda a.ha...@samsung.com
+ *  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 asm/div64.h
+#include linux/leds_flash.h
+#include linux/module.h
+#include linux/mutex.h
+#include linux/platform_device.h
+#include linux/slab.h
+#include media/v4l2-flash.h


I guess this should be last in the list.


+#include linux/workqueue.h
+#include linux/mfd/max77693.h
+#include linux/mfd/max77693-private.h
+
+#define MAX77693_LED_NAME  max77693-flash
+
+#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_MIN

Re: [PATCH/RFC v3 1/5] leds: Add sysfs and kernel internal API for flash LEDs

2014-04-28 Thread Jacek Anaszewski

Hi Bryan,

Thanks for the review.

On 04/26/2014 01:17 AM, Bryan Wu wrote:

On Fri, Apr 11, 2014 at 7:56 AM, Jacek Anaszewski
j.anaszew...@samsung.com wrote:

Some LED devices support two operation modes - torch and
flash.


Do we have a method to look up the capabilities from LED devices driver?
For example, the LED device supports Torch/Flash then LED device
driver should set a flag like LED_DEV_CAP_TORCH or LED_DEV_CAP_FLASH.
If it doesn't support those functions, it won't set those flags.


It is assumed that torch led is always available. For declaring
the existence of the flash led there is 'has_flash_led' flag in the
struct led_flash.


LED Flash class core can check those flags for further usage.


This patch provides support for flash LED devices
in the LED subsystem by introducing new sysfs attributes
and kernel internal interface. The attributes being
introduced are: flash_brightness, flash_strobe, flash_timeout,
max_flash_timeout, max_flash_brightness, flash_fault and
optional external_strobe, indicator_brightness and
max_indicator_btightness. All the flash related features


typo here, it should max_indicator_btightness - max_indicator_brightness


are placed in a separate module.


Please add one empty line here.


The modifications aim to be compatible with V4L2 framework
requirements related to the flash devices management. The
design assumes that V4L2 sub-device can take of the LED class
device control and communicate with it through the kernel
internal interface. When V4L2 Flash sub-device file is
opened, the LED class device sysfs interface is made
unavailable.



I don't quite understand the last sentence here. Looks like the LED
flash class interface binds to V4L2 Flash sub-device, then why we need
to export sysfs for user space if the only user is V4L2 which can talk
through kernel internal API here.


It has been agreed that the two types of interfaces should be available
for the users for operating on LED flash devices. Currently on open
the V4L2 flash sub-device sets the lock flag to disable LED sysfs
interface which was exported when the LED device was created.
Do you suggest that attributes should be removed each time V4L2
takes control of the LED flash device and re-created after
the device is released?


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|8 +
  drivers/leds/Makefile   |1 +
  drivers/leds/led-class.c|   36 ++-
  drivers/leds/led-flash.c|  627

+++

If we go for the LED Flash class, I prefer to use led-class-flash.c
rather than led-flash.c


OK.


  drivers/leds/led-triggers.c |   16 +-
  drivers/leds/leds.h |6 +
  include/linux/leds.h|   50 +++-
  include/linux/leds_flash.h  |  252 +


leds_flash.h - led-class-flash.h


  8 files changed, 982 insertions(+), 14 deletions(-)
  create mode 100644 drivers/leds/led-flash.c
  create mode 100644 include/linux/leds_flash.h

diff --git a/drivers/leds/Kconfig b/drivers/leds/Kconfig
index 2062682..1e1c81f 100644
--- a/drivers/leds/Kconfig
+++ b/drivers/leds/Kconfig
@@ -19,6 +19,14 @@ config LEDS_CLASS
   This option enables the led sysfs class in /sys/class/leds.  You'll
   need this to do anything useful with LEDs.  If unsure, say N.

+config LEDS_CLASS_FLASH
+   tristate Flash LEDs Support

LED Flash Class Support


+   depends on LEDS_CLASS
+   help
+ This option enables support for flash LED devices. Say Y if you
+ want to use flash specific features of a LED device, if they
+ are supported.
+


This help message is not very accurate, please take a look at
LEDS_CLASS. And I prefer this driver can be a module, so it should be
mentioned here.


Doesn't 'tristate' property suffice for indicating that the driver
can be a module?


  comment LED drivers

  config LEDS_88PM860X
diff --git a/drivers/leds/Makefile b/drivers/leds/Makefile
index 3cd76db..8861b86 100644
--- a/drivers/leds/Makefile
+++ b/drivers/leds/Makefile
@@ -2,6 +2,7 @@
  # LED Core
  obj-$(CONFIG_NEW_LEDS) += led-core.o
  obj-$(CONFIG_LEDS_CLASS)   += led-class.o
+obj-$(CONFIG_LEDS_CLASS_FLASH) += led-flash.o
  obj-$(CONFIG_LEDS_TRIGGERS)+= led-triggers.o

  # LED Platform Drivers
diff --git a/drivers/leds/led-class.c b/drivers/leds/led-class.c
index f37d63c..58f16c3 100644
--- a/drivers/leds/led-class.c
+++ b/drivers/leds/led-class.c
@@ -9,15 +9,16 @@
   * 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/list.h
+#include linux/module.h
+#include linux/slab.h
  #include linux/spinlock.h
-#include linux/device.h
  #include

Re: [PATCH/RFC v3 5/5] media: Add registration helpers for V4L2 flash sub-devices

2014-05-06 Thread Jacek Anaszewski

Hi Sakari,

On 05/02/2014 01:06 PM, Sakari Ailus wrote:


[...]

+static inline enum led_brightness v4l2_flash_intensity_to_led_brightness(
+   struct led_ctrl *config,
+   u32 intensity)


Fits on a single line.


+{
+   return intensity / config-step;


Shouldn't you first decrement the minimum before the division?


Brightness level 0 means that led is off. Let's consider following case:

intensity - 15625
config-step - 15625
intensity / config-step = 1 (the lowest possible current level)


In V4L2 controls the minimum is not off, and zero might not be a possible
value since minimum isn't divisible by step.

I wonder how to best take that into account.


I've assumed that in MODE_TORCH a led is always on. Switching
the mode to MODE_FLASH or MODE_OFF turns the led off.
This way we avoid the problem with converting 0 uA value to
led_brightness, as available torch brightness levels start from
the minimum current level value and turning the led off is
accomplished on transition to MODE_OFF or MODE_FLASH, by
calling brightness_set op with led_brightness = 0.


I'm not sure if we understood the issue the same way. My concern was that if
the intensity isn't a multiple of step (but intensity - min is), the above
formula won't return a valid result (unless I miss something).



Please note that v4l2_flash_intensity_to_led_brightness is called only
from s_ctrl callback, and thus it expects to get the intensity aligned
to the step value, so it will always be a multiple of step.
Is it possible that s_ctrl callback would be passed a non-aligned
control value?

Regards,
Jacek Anaszewski

--
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/RFC v3 5/5] media: Add registration helpers for V4L2 flash sub-devices

2014-05-07 Thread Jacek Anaszewski

On 05/06/2014 11:10 AM, Sakari Ailus wrote:

Hi Jacek,

On Tue, May 06, 2014 at 08:44:41AM +0200, Jacek Anaszewski wrote:

Hi Sakari,

On 05/02/2014 01:06 PM, Sakari Ailus wrote:


[...]

+static inline enum led_brightness v4l2_flash_intensity_to_led_brightness(
+   struct led_ctrl *config,
+   u32 intensity)


Fits on a single line.


+{
+   return intensity / config-step;


Shouldn't you first decrement the minimum before the division?


Brightness level 0 means that led is off. Let's consider following case:

intensity - 15625
config-step - 15625
intensity / config-step = 1 (the lowest possible current level)


In V4L2 controls the minimum is not off, and zero might not be a possible
value since minimum isn't divisible by step.

I wonder how to best take that into account.


I've assumed that in MODE_TORCH a led is always on. Switching
the mode to MODE_FLASH or MODE_OFF turns the led off.
This way we avoid the problem with converting 0 uA value to
led_brightness, as available torch brightness levels start from
the minimum current level value and turning the led off is
accomplished on transition to MODE_OFF or MODE_FLASH, by
calling brightness_set op with led_brightness = 0.


I'm not sure if we understood the issue the same way. My concern was that if
the intensity isn't a multiple of step (but intensity - min is), the above
formula won't return a valid result (unless I miss something).



Please note that v4l2_flash_intensity_to_led_brightness is called only
from s_ctrl callback, and thus it expects to get the intensity aligned
to the step value, so it will always be a multiple of step.
Is it possible that s_ctrl callback would be passed a non-aligned
control value?


In a nutshell: value - min is aligned but value is not. Please see
validate_new() in drivers/media/v4l2-core/v4l2-ctrls.c .



Still, to my mind, value is aligned.

Below I execute the calculation steps one by one
according to the V4L2_CTRL_TYPE_INTEGER case in the
validate_new function:

c-value = 35000

val = c-value + step / 2;   // 35000 + 15625 / 2 = 42812
val = clamp(val, min, max);  // val = 42812
offset = val - min;  // 42812 - 15625 = 27187
offset = step * (offset / step); // 15625 * (27187 / 15625) = 15625
c-value = min + offset; // 15625 + 15625 = 31250

Value is aligned to the nearest step.

Please spot any discrepancies in my way of thinking if there
are any :)

Regards,
Jacek Anaszewski


--
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/RFC v3 5/5] media: Add registration helpers for V4L2 flash sub-devices

2014-05-09 Thread Jacek Anaszewski

Hi Sakari,

On 05/07/2014 09:58 AM, Sakari Ailus wrote:

Hi Jacek,

On Wed, May 07, 2014 at 09:20:17AM +0200, Jacek Anaszewski wrote:

On 05/06/2014 11:10 AM, Sakari Ailus wrote:

Hi Jacek,

On Tue, May 06, 2014 at 08:44:41AM +0200, Jacek Anaszewski wrote:

Hi Sakari,

On 05/02/2014 01:06 PM, Sakari Ailus wrote:


[...]

+static inline enum led_brightness v4l2_flash_intensity_to_led_brightness(
+   struct led_ctrl *config,
+   u32 intensity)


Fits on a single line.


+{
+   return intensity / config-step;


Shouldn't you first decrement the minimum before the division?


Brightness level 0 means that led is off. Let's consider following case:

intensity - 15625
config-step - 15625
intensity / config-step = 1 (the lowest possible current level)


In V4L2 controls the minimum is not off, and zero might not be a possible
value since minimum isn't divisible by step.

I wonder how to best take that into account.


I've assumed that in MODE_TORCH a led is always on. Switching
the mode to MODE_FLASH or MODE_OFF turns the led off.
This way we avoid the problem with converting 0 uA value to
led_brightness, as available torch brightness levels start from
the minimum current level value and turning the led off is
accomplished on transition to MODE_OFF or MODE_FLASH, by
calling brightness_set op with led_brightness = 0.


I'm not sure if we understood the issue the same way. My concern was that if
the intensity isn't a multiple of step (but intensity - min is), the above
formula won't return a valid result (unless I miss something).



Please note that v4l2_flash_intensity_to_led_brightness is called only

from s_ctrl callback, and thus it expects to get the intensity aligned

to the step value, so it will always be a multiple of step.
Is it possible that s_ctrl callback would be passed a non-aligned
control value?


In a nutshell: value - min is aligned but value is not. Please see
validate_new() in drivers/media/v4l2-core/v4l2-ctrls.c .



Still, to my mind, value is aligned.

Below I execute the calculation steps one by one
according to the V4L2_CTRL_TYPE_INTEGER case in the
validate_new function:

c-value = 35000

val = c-value + step / 2;   // 35000 + 15625 / 2 = 42812
val = clamp(val, min, max);  // val = 42812
offset = val - min;  // 42812 - 15625 = 27187
offset = step * (offset / step); // 15625 * (27187 / 15625) = 15625
c-value = min + offset; // 15625 + 15625 = 31250

Value is aligned to the nearest step.

Please spot any discrepancies in my way of thinking if there
are any :)


min is aligned to step above. This is not necessarily the case. And if min
is not aligned, neither is value.



Thanks for spotting this. Below are improved versions of the conversion
functions. Please let me know if you have any comments.

static inline
enum led_brightnessv4l2_flash_intensity_to_led_brightness(
struct led_ctrl *config,
u32 intensity)
{
return ((intensity - config-min) / config-step) + 1;
}

static inline
u32 v4l2_flash_led_brightness_to_intensity(
struct led_ctrl *config,
enum led_brightness brightness)
{
return ((brightness - 1) * config-step) + config-min;
}

Regards,
Jacek Anaszewski
--
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: LED / flash API integration related improvements

2014-06-16 Thread Jacek Anaszewski

Hi Sakari,

On 06/16/2014 10:53 AM, Sakari Ailus wrote:

Hi Jacek and others,

Comments from the LED API folks would be highly appreciated.

(Cc linux-media as well.)

My comments below.

On Fri, May 09, 2014 at 04:28:44PM +0200, Jacek Anaszewski wrote:

During review of LED / flash API integration patch sets two issues
requiring modifications in the LED subsystem core emerged.
I would like to consult possible ways of solving them:

1.
==

Some LED devices allow to control multiple LEDs independently.
Currently there is no direct support for this in the LED subsystem
and existing drivers register separate devices for each LED.

LED / flash API integration effort is a good opportunity to provide
support for exposing multiple LEDs by a single LED class device.

I would like to add following API:

/**
  * led_get_sub_leds_number - get the number of exposed LEDs
  * @led_cdev: the LED to query
  * @num_leds: number of exposed leds
  *
  * Get the number of leds exposed by the device.
  *
  * Returns: 0 on success or negative error value on failure
  */
int led_get_sub_leds_number(struct led_classdev *led_cdev,
 int *num_leds);

/**
  * led_select_sub_led - select sub led to control
  * @led_cdev: the LED to set
  * @led_id: id of the sub led to control
  *
  * Set the sub led to be the target of the LED class API calls.
  * Maximum led_id equals num_leds - 1.
  *
  * Returns: 0 on success or negative error value on failure
  */
int led_select_sub_led(struct led_classdev *led_cdev,
 int led_id);


Instead of this, how about using an array indexed by LED for the other
functions?

The problem with this is that often the registers to control LED specific
properties contain the same configuration for another LED. The driver should
thus cache the information until it needs to be applied, and I don't think
configuring everything for every LED separately makes sense for either the
user nor the driver.


The max77693-flash is an example of such a design. It has one register
for setting flash timeout and it affects timeout for both leds.
The register would have to be written right before strobing the flash,
in case the cached timeout value is different from the one in the
register (cached on last write operation).
The device has also common flash status register. I don't have good
idea how to proceed in this case. After strobing the flash for any
of the sub-leds the remaining ones will also report that they
are strobing at the moment.


Caching the configuration before applying it should still be done since this
way extra register accesses can be avoided: registers often share different
kind of configurations such as timeout and current as well. The
configuration should be applied once an apply fonction is called.


/**
  * led_get_sub_led - get currently selected sub led
  * @led_cdev: the LED to set
  * @led_id: id of currently selected sub led
  *
  * Get id of the sub led chosen as the target of LED class
  * API calls. Maximum led_id equals num_leds - 1.
  *
  * Returns: 0 on success or negative error value on failure
  */
int led_get_target_led(struct led_classdev *led_cdev,
 int* led_id);

The functions functions would be mapped on the sysfs attributes:
- available_leds - RO
- sub_led_id - RW


This kind of interface isn't going to be compatible with existing
applications. If you want to keep the compatibility, the LEDs would probably
need to be exposed as separate devices. If that's not a requirement, I'd use
an array here as well.


I started to implement the interface I proposed but encountered
several issues related to led-triggers and led_blink feature.
They would require significant modifications, I'd rather avoid.
Instead I decided to register separate led class device in
the driver for the max77693-flash device, similarly as it
is accomplished in the led drivers of the other compound led devices.


The V4L2 driver would still expose the device as a single sub-device.
Controls that apply to individual LEDs would be array controls.


Have those array controls been already added? If so, could you
spot the place where they are implemented, or maybe there
are some examples of usage or documentation?


The attributes would be created only if the related callbacks
are registered by the driver.

2.
==

The second issue, refers to the work queues being used in the
brightness_set callbacks of the LED subsystem drivers. It interferes
with the way how V4L2 Flash controls work, which expect that setting
flash brightness has immediate effect.

Proposed solutions:
- move work queues out from the drivers to the LED core.
- add brightness_set_now callback to be registered by
   the LED drivers and intended for call by v4l2-flash driver;
   it wouldn't schedule a work but do the job immediately


I favour the former

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

2014-07-07 Thread Jacek Anaszewski
This patch series 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.

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  |   12 +
 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   |  486 ++
 .../media/platform/s5p-jpeg/jpeg-hw-exynos3250.h   |   60 ++
 drivers/media/platform/s5p-jpeg/jpeg-regs.h|  247 +++-
 8 files changed, 1459 insertions(+), 56 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


  1   2   3   4   5   6   7   8   >