Re: [PATCH] media: unify some sony camera sensors pattern naming

2018-12-02 Thread Bingbu Cao




On 12/01/2018 02:08 AM, Tomasz Figa wrote:

Hi Bingbu,

On Mon, Nov 26, 2018 at 7:56 PM  wrote:

From: Bingbu Cao 

Some Sony camera sensors have same test pattern
definitions, this patch unify the pattern naming
to make it more clear to the userspace.

Suggested-by: Sakari Ailus 
Signed-off-by: Bingbu Cao 
---
  drivers/media/i2c/imx258.c | 8 
  drivers/media/i2c/imx319.c | 8 
  drivers/media/i2c/imx355.c | 8 
  3 files changed, 12 insertions(+), 12 deletions(-)


Thanks for the patch! One comment inline.


diff --git a/drivers/media/i2c/imx258.c b/drivers/media/i2c/imx258.c
index 31a1e2294843..a8a2880c6b4e 100644
--- a/drivers/media/i2c/imx258.c
+++ b/drivers/media/i2c/imx258.c
@@ -504,10 +504,10 @@ struct imx258_mode {

  static const char * const imx258_test_pattern_menu[] = {
 "Disabled",
-   "Color Bars",
-   "Solid Color",
-   "Grey Color Bars",
-   "PN9"
+   "Solid Colour",
+   "Eight Vertical Colour Bars",

Is it just me or "solid color" and "color bars" are being swapped
here? Did the driver had the names mixed up before or the order of
modes is different between these sensors?

The test pattern value order of the 3 camera sensors should be same.
All are:
0 - Disabled
1 - Solid Colour
2 - Eight Vertical Colour Bars
...

This patch swapped the first 2 item for imx258 (wrong order before) and use 
unified
name for all 3 sensors.


Best regards,
Tomasz





Re: [PATCH 1/1] media: Use common test pattern menu entries

2018-11-27 Thread Bingbu Cao



On 11/27/2018 05:33 PM, Sakari Ailus wrote:

While the test pattern menu itself is not standardised, many devices
support the same test patterns. Aligning the menu entries helps the user
space to use the interface, and adding macros for the menu entry strings
helps to keep them aligned.

I like this patch.


Signed-off-by: Sakari Ailus 
---
  drivers/media/i2c/imx258.c | 10 +-
  drivers/media/i2c/imx319.c | 10 +-
  drivers/media/i2c/imx355.c | 10 +-
  drivers/media/i2c/ov2640.c |  4 ++--
  drivers/media/i2c/smiapp/smiapp-core.c | 10 +-
  include/uapi/linux/v4l2-controls.h |  5 +
  6 files changed, 27 insertions(+), 22 deletions(-)

diff --git a/drivers/media/i2c/imx258.c b/drivers/media/i2c/imx258.c
index f86ae18bc104..c795d4c4c0e4 100644
--- a/drivers/media/i2c/imx258.c
+++ b/drivers/media/i2c/imx258.c
@@ -498,11 +498,11 @@ static const struct imx258_reg mode_1048_780_regs[] = {
  };
  
  static const char * const imx258_test_pattern_menu[] = {

-   "Disabled",
-   "Solid Colour",
-   "Eight Vertical Colour Bars",
-   "Colour Bars With Fade to Grey",
-   "Pseudorandom Sequence (PN9)",
+   V4L2_TEST_PATTERN_DISABLED,
+   V4L2_TEST_PATTERN_SOLID_COLOUR,
+   V4L2_TEST_PATTERN_8_VERT_COLOUR_BARS,
+   V4L2_TEST_PATTERN_8_VERT_COLOUR_BARS_FADE_TO_GREY,
+   V4L2_TEST_PATTERN_PN9,
  };
  
  /* Configurations for supported link frequencies */

diff --git a/drivers/media/i2c/imx319.c b/drivers/media/i2c/imx319.c
index 17c2e4b41221..eddaf69a67b6 100644
--- a/drivers/media/i2c/imx319.c
+++ b/drivers/media/i2c/imx319.c
@@ -1647,11 +1647,11 @@ static const struct imx319_reg mode_1280x720_regs[] = {
  };
  
  static const char * const imx319_test_pattern_menu[] = {

-   "Disabled",
-   "Solid Colour",
-   "Eight Vertical Colour Bars",
-   "Colour Bars With Fade to Grey",
-   "Pseudorandom Sequence (PN9)",
+   V4L2_TEST_PATTERN_DISABLED,
+   V4L2_TEST_PATTERN_SOLID_COLOUR,
+   V4L2_TEST_PATTERN_8_VERT_COLOUR_BARS,
+   V4L2_TEST_PATTERN_8_VERT_COLOUR_BARS_FADE_TO_GREY,
+   V4L2_TEST_PATTERN_PN9,
  };
  
  /* supported link frequencies */

diff --git a/drivers/media/i2c/imx355.c b/drivers/media/i2c/imx355.c
index bed293b60e50..824d07156f9c 100644
--- a/drivers/media/i2c/imx355.c
+++ b/drivers/media/i2c/imx355.c
@@ -875,11 +875,11 @@ static const struct imx355_reg mode_820x616_regs[] = {
  };
  
  static const char * const imx355_test_pattern_menu[] = {

-   "Disabled",
-   "Solid Colour",
-   "Eight Vertical Colour Bars",
-   "Colour Bars With Fade to Grey",
-   "Pseudorandom Sequence (PN9)",
+   V4L2_TEST_PATTERN_DISABLED,
+   V4L2_TEST_PATTERN_SOLID_COLOUR,
+   V4L2_TEST_PATTERN_8_VERT_COLOUR_BARS,
+   V4L2_TEST_PATTERN_8_VERT_COLOUR_BARS_FADE_TO_GREY,
+   V4L2_TEST_PATTERN_PN9,
  };
  
  /* supported link frequencies */

diff --git a/drivers/media/i2c/ov2640.c b/drivers/media/i2c/ov2640.c
index 5d2d6735cc78..507ec7176a7d 100644
--- a/drivers/media/i2c/ov2640.c
+++ b/drivers/media/i2c/ov2640.c
@@ -707,8 +707,8 @@ static int ov2640_reset(struct i2c_client *client)
  }
  
  static const char * const ov2640_test_pattern_menu[] = {

-   "Disabled",
-   "Eight Vertical Colour Bars",
+   V4L2_TEST_PATTERN_DISABLED,
+   V4L2_TEST_PATTERN_8_VERT_COLOUR_BARS,
  };
  
  /*

diff --git a/drivers/media/i2c/smiapp/smiapp-core.c 
b/drivers/media/i2c/smiapp/smiapp-core.c
index 58a45c353e27..f6a92b9f178c 100644
--- a/drivers/media/i2c/smiapp/smiapp-core.c
+++ b/drivers/media/i2c/smiapp/smiapp-core.c
@@ -409,11 +409,11 @@ static void smiapp_update_mbus_formats(struct 
smiapp_sensor *sensor)
  }
  
  static const char * const smiapp_test_patterns[] = {

-   "Disabled",
-   "Solid Colour",
-   "Eight Vertical Colour Bars",
-   "Colour Bars With Fade to Grey",
-   "Pseudorandom Sequence (PN9)",
+   V4L2_TEST_PATTERN_DISABLED,
+   V4L2_TEST_PATTERN_SOLID_COLOUR,
+   V4L2_TEST_PATTERN_8_VERT_COLOUR_BARS,
+   V4L2_TEST_PATTERN_8_VERT_COLOUR_BARS_FADE_TO_GREY,
+   V4L2_TEST_PATTERN_PN9,
  };
  
  static int smiapp_set_ctrl(struct v4l2_ctrl *ctrl)

diff --git a/include/uapi/linux/v4l2-controls.h 
b/include/uapi/linux/v4l2-controls.h
index 998983a6e6b7..a74ff6f1ac88 100644
--- a/include/uapi/linux/v4l2-controls.h
+++ b/include/uapi/linux/v4l2-controls.h
@@ -1014,6 +1014,11 @@ enum v4l2_jpeg_chroma_subsampling {
  #define V4L2_CID_LINK_FREQ(V4L2_CID_IMAGE_PROC_CLASS_BASE 
+ 1)
  #define V4L2_CID_PIXEL_RATE   (V4L2_CID_IMAGE_PROC_CLASS_BASE 
+ 2)
  #define V4L2_CID_TEST_PATTERN (V4L2_CID_IMAGE_PROC_CLASS_BASE 
+ 3)
+#define V4L2_TEST_PATTERN_DISABLED "Disabled"
+#define V4L2_TEST_PATTERN_SOLID_COLOUR "Solid Colour"
+#define V4L2_TEST_PATTERN_8_VERT_COLOUR_BARS   "Eight Vertical Colour 
Bars"
+#define 

Re: [PATCH v2] media: unify some sony camera sensors pattern naming

2018-11-27 Thread Bingbu Cao




On 11/27/2018 05:33 PM, Sakari Ailus wrote:

On Tue, Nov 27, 2018 at 05:03:26PM +0800, bingbu@intel.com wrote:

From: Bingbu Cao 

Some Sony camera sensors have same pattern
definitions, this patch unify the pattern naming
to make it more clear to the userspace.

Suggested-by: Sakari Ailus 
Signed-off-by: Bingbu Cao 
Reviewed-by: l...@lucaceresoli.net

Hi Bing Bu,

Sorry, I prefer your v1. :-)

Thanks.
It really prevent me Google more about difference between 'colour' and 'color'. 
 :)






[PATCH v2] media: unify some sony camera sensors pattern naming

2018-11-27 Thread bingbu . cao
From: Bingbu Cao 

Some Sony camera sensors have same pattern
definitions, this patch unify the pattern naming
to make it more clear to the userspace.

Suggested-by: Sakari Ailus 
Signed-off-by: Bingbu Cao 
Reviewed-by: l...@lucaceresoli.net
---
 drivers/media/i2c/imx258.c | 6 +++---
 drivers/media/i2c/imx319.c | 8 
 drivers/media/i2c/imx355.c | 8 
 3 files changed, 11 insertions(+), 11 deletions(-)

diff --git a/drivers/media/i2c/imx258.c b/drivers/media/i2c/imx258.c
index 31a1e2294843..de399f69dc9b 100644
--- a/drivers/media/i2c/imx258.c
+++ b/drivers/media/i2c/imx258.c
@@ -504,10 +504,10 @@ struct imx258_mode {
 
 static const char * const imx258_test_pattern_menu[] = {
"Disabled",
-   "Color Bars",
"Solid Color",
-   "Grey Color Bars",
-   "PN9"
+   "Eight Vertical Color Bars",
+   "Color Bars With Fade to Grey",
+   "Pseudorandom Sequence (PN9)",
 };
 
 static const int imx258_test_pattern_val[] = {
diff --git a/drivers/media/i2c/imx319.c b/drivers/media/i2c/imx319.c
index acd988d2d7f1..c508887c4574 100644
--- a/drivers/media/i2c/imx319.c
+++ b/drivers/media/i2c/imx319.c
@@ -1648,10 +1648,10 @@ struct imx319 {
 
 static const char * const imx319_test_pattern_menu[] = {
"Disabled",
-   "Solid color",
-   "100% color bars",
-   "Fade to gray color bars",
-   "PN9"
+   "Solid Color",
+   "Eight Vertical Color Bars",
+   "Color Bars With Fade to Grey",
+   "Pseudorandom Sequence (PN9)",
 };
 
 /* supported link frequencies */
diff --git a/drivers/media/i2c/imx355.c b/drivers/media/i2c/imx355.c
index 9c9559dfd3dd..608947dc1a65 100644
--- a/drivers/media/i2c/imx355.c
+++ b/drivers/media/i2c/imx355.c
@@ -876,10 +876,10 @@ struct imx355 {
 
 static const char * const imx355_test_pattern_menu[] = {
"Disabled",
-   "Solid color",
-   "100% color bars",
-   "Fade to gray color bars",
-   "PN9"
+   "Solid Color",
+   "Eight Vertical Color Bars",
+   "Color Bars With Fade to Grey",
+   "Pseudorandom Sequence (PN9)",
 };
 
 /* supported link frequencies */
-- 
1.9.1



Re: [PATCH] media: unify some sony camera sensors pattern naming

2018-11-27 Thread Bingbu Cao




On 11/27/2018 04:05 PM, Luca Ceresoli wrote:

Hi Bingbu,

On 27/11/18 05:01, bingbu@intel.com wrote:

From: Bingbu Cao 

Some Sony camera sensors have same test pattern
definitions, this patch unify the pattern naming
to make it more clear to the userspace.

Suggested-by: Sakari Ailus 
Signed-off-by: Bingbu Cao 
---
  drivers/media/i2c/imx258.c | 8 
  drivers/media/i2c/imx319.c | 8 
  drivers/media/i2c/imx355.c | 8 
  3 files changed, 12 insertions(+), 12 deletions(-)

diff --git a/drivers/media/i2c/imx258.c b/drivers/media/i2c/imx258.c
index 31a1e2294843..a8a2880c6b4e 100644
--- a/drivers/media/i2c/imx258.c
+++ b/drivers/media/i2c/imx258.c
@@ -504,10 +504,10 @@ struct imx258_mode {
  
  static const char * const imx258_test_pattern_menu[] = {

"Disabled",
-   "Color Bars",
-   "Solid Color",
-   "Grey Color Bars",
-   "PN9"
+   "Solid Colour",
+   "Eight Vertical Colour Bars",
+   "Colour Bars With Fade to Grey",
+   "Pseudorandom Sequence (PN9)",

I had a look at imx274, it has many more values but definitely some
could be unified too.

However I noticed something strange in that driver: The "Horizontal
Color Bars" pattern has vertical bars, side-by-side, as in .
"Vertical Color Bars" are one on top of the other, as in ==. Is it just
me crazy, or are they swapped?

Luca, thanks for your review.
I do not have the manual of imx274.
 should be the 'Vertical Color Bars' without any rotation process.
If not, I think the definitions there are swapped.

Only one minor nitpick about your patch. The USA spelling "color" seems
a lot more frequent in the kernel sources than the UK "colour", so it's
probably better to be consistent.

Ack, I will update in next version.

Thanks!






[PATCH] media: unify some sony camera sensors pattern naming

2018-11-26 Thread bingbu . cao
From: Bingbu Cao 

Some Sony camera sensors have same test pattern
definitions, this patch unify the pattern naming
to make it more clear to the userspace.

Suggested-by: Sakari Ailus 
Signed-off-by: Bingbu Cao 
---
 drivers/media/i2c/imx258.c | 8 
 drivers/media/i2c/imx319.c | 8 
 drivers/media/i2c/imx355.c | 8 
 3 files changed, 12 insertions(+), 12 deletions(-)

diff --git a/drivers/media/i2c/imx258.c b/drivers/media/i2c/imx258.c
index 31a1e2294843..a8a2880c6b4e 100644
--- a/drivers/media/i2c/imx258.c
+++ b/drivers/media/i2c/imx258.c
@@ -504,10 +504,10 @@ struct imx258_mode {
 
 static const char * const imx258_test_pattern_menu[] = {
"Disabled",
-   "Color Bars",
-   "Solid Color",
-   "Grey Color Bars",
-   "PN9"
+   "Solid Colour",
+   "Eight Vertical Colour Bars",
+   "Colour Bars With Fade to Grey",
+   "Pseudorandom Sequence (PN9)",
 };
 
 static const int imx258_test_pattern_val[] = {
diff --git a/drivers/media/i2c/imx319.c b/drivers/media/i2c/imx319.c
index acd988d2d7f1..17c2e4b41221 100644
--- a/drivers/media/i2c/imx319.c
+++ b/drivers/media/i2c/imx319.c
@@ -1648,10 +1648,10 @@ struct imx319 {
 
 static const char * const imx319_test_pattern_menu[] = {
"Disabled",
-   "Solid color",
-   "100% color bars",
-   "Fade to gray color bars",
-   "PN9"
+   "Solid Colour",
+   "Eight Vertical Colour Bars",
+   "Colour Bars With Fade to Grey",
+   "Pseudorandom Sequence (PN9)",
 };
 
 /* supported link frequencies */
diff --git a/drivers/media/i2c/imx355.c b/drivers/media/i2c/imx355.c
index 9c9559dfd3dd..bed293b60e50 100644
--- a/drivers/media/i2c/imx355.c
+++ b/drivers/media/i2c/imx355.c
@@ -876,10 +876,10 @@ struct imx355 {
 
 static const char * const imx355_test_pattern_menu[] = {
"Disabled",
-   "Solid color",
-   "100% color bars",
-   "Fade to gray color bars",
-   "PN9"
+   "Solid Colour",
+   "Eight Vertical Colour Bars",
+   "Colour Bars With Fade to Grey",
+   "Pseudorandom Sequence (PN9)",
 };
 
 /* supported link frequencies */
-- 
1.9.1



Re: [PATCH 2/2] media: imx355: fix wrong order in test pattern menus

2018-11-26 Thread Bingbu Cao




On 11/26/2018 04:57 PM, Sakari Ailus wrote:

Hi Bing Bu,

On Mon, Nov 26, 2018 at 03:43:34PM +0800, bingbu@intel.com wrote:

From: Bingbu Cao 

current imx355 test pattern order in ctrl menu
is not correct, this patch fixes it.

Signed-off-by: Bingbu Cao 
---
  drivers/media/i2c/imx355.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/media/i2c/imx355.c b/drivers/media/i2c/imx355.c
index 20c8eea5db4b..9c9559dfd3dd 100644
--- a/drivers/media/i2c/imx355.c
+++ b/drivers/media/i2c/imx355.c
@@ -876,8 +876,8 @@ struct imx355 {
  
  static const char * const imx355_test_pattern_menu[] = {

"Disabled",
-   "100% color bars",
"Solid color",
+   "100% color bars",
"Fade to gray color bars",
"PN9"
  };

While at it, could you use the existing test pattern naming as well for the
drivers? That could be a separate patch.

>From drivers/media/i2c/smiapp/smiapp-core.c :

static const char * const smiapp_test_patterns[] = {
"Disabled",
"Solid Colour",
"Eight Vertical Colour Bars",
"Colour Bars With Fade to Grey",
"Pseudorandom Sequence (PN9)",
};

It's not strictly necessary from interface point of view, but for the user
space it'd be good to align the naming.

Sakari, ask a question that not really related to this patch.
I am wondering whether there are some standardization for the camera sensor
pattern generator.
Currently there are varied patterns and every vendor has its own pattern types.






Re: [PATCH 2/2] media: imx355: fix wrong order in test pattern menus

2018-11-26 Thread Bingbu Cao




On 11/26/2018 04:57 PM, Sakari Ailus wrote:

Hi Bing Bu,

On Mon, Nov 26, 2018 at 03:43:34PM +0800, bingbu@intel.com wrote:

From: Bingbu Cao 

current imx355 test pattern order in ctrl menu
is not correct, this patch fixes it.

Signed-off-by: Bingbu Cao 
---
  drivers/media/i2c/imx355.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/media/i2c/imx355.c b/drivers/media/i2c/imx355.c
index 20c8eea5db4b..9c9559dfd3dd 100644
--- a/drivers/media/i2c/imx355.c
+++ b/drivers/media/i2c/imx355.c
@@ -876,8 +876,8 @@ struct imx355 {
  
  static const char * const imx355_test_pattern_menu[] = {

"Disabled",
-   "100% color bars",
"Solid color",
+   "100% color bars",
"Fade to gray color bars",
"PN9"
  };

While at it, could you use the existing test pattern naming as well for the
drivers? That could be a separate patch.

Good point, thanks.
I am trying to check whether all the existing Sony camera sensors
use same test pattern definition, I can put them together.


>From drivers/media/i2c/smiapp/smiapp-core.c :

static const char * const smiapp_test_patterns[] = {
"Disabled",
"Solid Colour",
"Eight Vertical Colour Bars",
"Colour Bars With Fade to Grey",
"Pseudorandom Sequence (PN9)",
};

It's not strictly necessary from interface point of view, but for the user
space it'd be good to align the naming.





[PATCH 1/2] media: imx319: fix wrong order in test pattern menus

2018-11-25 Thread bingbu . cao
From: Bingbu Cao 

current imx319 test pattern order in ctrl menu
is not correct, this patch fixes it.

Signed-off-by: Bingbu Cao 
---
 drivers/media/i2c/imx319.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/media/i2c/imx319.c b/drivers/media/i2c/imx319.c
index 0d3e27812b93..acd988d2d7f1 100644
--- a/drivers/media/i2c/imx319.c
+++ b/drivers/media/i2c/imx319.c
@@ -1648,8 +1648,8 @@ struct imx319 {
 
 static const char * const imx319_test_pattern_menu[] = {
"Disabled",
-   "100% color bars",
"Solid color",
+   "100% color bars",
"Fade to gray color bars",
"PN9"
 };
-- 
1.9.1



[PATCH 2/2] media: imx355: fix wrong order in test pattern menus

2018-11-25 Thread bingbu . cao
From: Bingbu Cao 

current imx355 test pattern order in ctrl menu
is not correct, this patch fixes it.

Signed-off-by: Bingbu Cao 
---
 drivers/media/i2c/imx355.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/media/i2c/imx355.c b/drivers/media/i2c/imx355.c
index 20c8eea5db4b..9c9559dfd3dd 100644
--- a/drivers/media/i2c/imx355.c
+++ b/drivers/media/i2c/imx355.c
@@ -876,8 +876,8 @@ struct imx355 {
 
 static const char * const imx355_test_pattern_menu[] = {
"Disabled",
-   "100% color bars",
"Solid color",
+   "100% color bars",
"Fade to gray color bars",
"PN9"
 };
-- 
1.9.1



[PATCH v3] media: add imx355 camera sensor driver

2018-09-29 Thread bingbu . cao
From: Bingbu Cao 

Add a v4l2 sub-device driver for the Sony imx355 image sensor.
This is a camera sensor using the i2c bus for control and the
csi-2 bus for data.

This driver supports following features:

- manual exposure and analog/digital gain control support
- vblank/hblank control support
- 4 test patterns control support
- vflip/hflip control support (will impact the output bayer order)
- support following resolutions:
- 3268x2448, 3264x2448, 3280x2464 @ 30fps
- 1940x1096, 1936x1096, 1924x1080, 1920x1080 @ 60fps
- 1640x1232, 1640x922, 1300x736, 1296x736,
  1284x720, 1280x720 820x616 @ 120fps
- support 4 bayer orders output (via change v/hflip)
- SRGGB10(default), SGRBG10, SGBRG10, SBGGR10

Cc: Tomasz Figa 
Cc: Sakari Ailus 
Signed-off-by: Tianshu Qiu 
Signed-off-by: Bingbu Cao 

---

This patch is based on sakari's media-tree git:
https://git.linuxtv.org/sailus/media_tree.git/log/?h=for-4.20-8

changes since v2:
 - get CSI-2 link frequencies and external clock
   from firmware
 - select digital gain mode when streaming

changes v1 -> v2:
 - fix some coding style issues - line breaks
 - add v4l2_ctrl_grab() to prevent v/hflip change
   during streaming
 - add v4l2 ctrl event (un)subscribe support
 - correct link frequency
 - add more info into commit message

---

Conflicts:
MAINTAINERS
drivers/media/i2c/Kconfig
drivers/media/i2c/Makefile
---
 MAINTAINERS|7 +
 drivers/media/i2c/Kconfig  |   11 +
 drivers/media/i2c/Makefile |1 +
 drivers/media/i2c/imx355.c | 1856 
 4 files changed, 1875 insertions(+)
 create mode 100644 drivers/media/i2c/imx355.c

diff --git a/MAINTAINERS b/MAINTAINERS
index f274a9d883bb..4880a9068f1b 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -13543,6 +13543,13 @@ T: git git://linuxtv.org/media_tree.git
 S: Maintained
 F: drivers/media/i2c/imx319.c
 
+SONY IMX355 SENSOR DRIVER
+M: Tianshu Qiu 
+L: linux-media@vger.kernel.org
+T: git git://linuxtv.org/media_tree.git
+S: Maintained
+F: drivers/media/i2c/imx355.c
+
 SONY MEMORYSTICK CARD SUPPORT
 M: Alex Dubov 
 W: http://tifmxx.berlios.de/
diff --git a/drivers/media/i2c/Kconfig b/drivers/media/i2c/Kconfig
index 603ac087975b..704af210e270 100644
--- a/drivers/media/i2c/Kconfig
+++ b/drivers/media/i2c/Kconfig
@@ -625,6 +625,17 @@ config VIDEO_IMX319
  To compile this driver as a module, choose M here: the
  module will be called imx319.
 
+config VIDEO_IMX355
+   tristate "Sony IMX355 sensor support"
+   depends on I2C && VIDEO_V4L2 && VIDEO_V4L2_SUBDEV_API
+   depends on MEDIA_CAMERA_SUPPORT
+   help
+ This is a Video4Linux2 sensor driver for the Sony
+ IMX355 camera.
+
+ To compile this driver as a module, choose M here: the
+ module will be called imx355.
+
 config VIDEO_OV2640
tristate "OmniVision OV2640 sensor support"
depends on VIDEO_V4L2 && I2C
diff --git a/drivers/media/i2c/Makefile b/drivers/media/i2c/Makefile
index d10b438577be..260d4d9ec2a1 100644
--- a/drivers/media/i2c/Makefile
+++ b/drivers/media/i2c/Makefile
@@ -109,5 +109,6 @@ obj-$(CONFIG_VIDEO_TC358743)+= tc358743.o
 obj-$(CONFIG_VIDEO_IMX258) += imx258.o
 obj-$(CONFIG_VIDEO_IMX274) += imx274.o
 obj-$(CONFIG_VIDEO_IMX319) += imx319.o
+obj-$(CONFIG_VIDEO_IMX355) += imx355.o
 
 obj-$(CONFIG_SDR_MAX2175) += max2175.o
diff --git a/drivers/media/i2c/imx355.c b/drivers/media/i2c/imx355.c
new file mode 100644
index ..858cd0f8bc10
--- /dev/null
+++ b/drivers/media/i2c/imx355.c
@@ -0,0 +1,1856 @@
+// SPDX-License-Identifier: GPL-2.0
+// Copyright (C) 2018 Intel Corporation
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define IMX355_REG_MODE_SELECT 0x0100
+#define IMX355_MODE_STANDBY0x00
+#define IMX355_MODE_STREAMING  0x01
+
+/* Chip ID */
+#define IMX355_REG_CHIP_ID 0x0016
+#define IMX355_CHIP_ID 0x0355
+
+/* V_TIMING internal */
+#define IMX355_REG_FLL 0x0340
+#define IMX355_FLL_MAX 0x
+
+/* Exposure control */
+#define IMX355_REG_EXPOSURE0x0202
+#define IMX355_EXPOSURE_MIN1
+#define IMX355_EXPOSURE_STEP   1
+#define IMX355_EXPOSURE_DEFAULT0x0282
+
+/* Analog gain control */
+#define IMX355_REG_ANALOG_GAIN 0x0204
+#define IMX355_ANA_GAIN_MIN0
+#define IMX355_ANA_GAIN_MAX960
+#define IMX355_ANA_GAIN_STEP   1
+#define IMX355_ANA_GAIN_DEFAULT0
+
+/* Digital gain control */
+#define IMX355_REG_DPGA_USE_GLOBAL_GAIN0x3070
+#define IMX355_REG_DIG_GAIN_GLOBAL 0x020e
+#define IMX355_DGTL_GAIN_MIN   256
+#define IMX355_DGTL_GAIN_MAX   4095
+#define IMX355_DGTL_GAIN_STEP  1
+#defin

[PATCH v7] media: add imx319 camera sensor driver

2018-09-25 Thread bingbu . cao
From: Bingbu Cao 

Add a v4l2 sub-device driver for the Sony imx319 image sensor.
This is a camera sensor using the i2c bus for control and the
csi-2 bus for data.

This driver supports following features:
- manual exposure and analog/digital gain control support
- vblank/hblank control support
-  4 test patterns control support
- vflip/hflip control support (will impact the output bayer order)
- support following resolutions:
- 3264x2448, 3280x2464 @ 30fps
- 1936x1096, 1920x1080 @ 60fps
- 1640x1232, 1640x922, 1296x736, 1280x720 @ 120fps
- support 4 bayer orders output (via change v/hflip)
- SRGGB10(default), SGRBG10, SGBRG10, SBGGR10

Cc: Tomasz Figa 
Cc: Sakari Ailus 
Signed-off-by: Bingbu Cao 
Signed-off-by: Tianshu Qiu 

---

This patch is based on sakari's media-tree git:
https://git.linuxtv.org/sailus/media_tree.git/log/?h=for-4.20-1

Changes from v5:
 - add some comments for gain calculation
 - use lock to protect the format
 - fix some style issues

Changes from v4 to v5:
 - use single PLL for all internal clocks
 - change link frequency to 482.4MHz
 - adjust frame timing for 2x2 binning modes
   and enlarge frame readout time
 - get CSI-2 link frequencies and external clock
   from firmware
 - use unlocked __v4l2_ctrl_grab() with change from:
   https://git.linuxtv.org/sailus/media_tree.git/commit/?h=unlocked-ctrl-grab

Changes since v1:
 - fix some coding style issues - line breaks
 - add v4l2_ctrl_grab() to prevent v/hflip change
   during streaming
 - add v4l2 ctrl event (un)subscribe support
 - add more info into commit message

---
---
 MAINTAINERS|7 +
 drivers/media/i2c/Kconfig  |   11 +
 drivers/media/i2c/Makefile |1 +
 drivers/media/i2c/imx319.c | 2556 
 4 files changed, 2575 insertions(+)
 create mode 100644 drivers/media/i2c/imx319.c

diff --git a/MAINTAINERS b/MAINTAINERS
index a5b256b25905..abc4abb6f83c 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -13530,6 +13530,13 @@ S: Maintained
 F: drivers/media/i2c/imx274.c
 F: Documentation/devicetree/bindings/media/i2c/imx274.txt
 
+SONY IMX319 SENSOR DRIVER
+M: Bingbu Cao 
+L: linux-media@vger.kernel.org
+T: git git://linuxtv.org/media_tree.git
+S: Maintained
+F: drivers/media/i2c/imx319.c
+
 SONY MEMORYSTICK CARD SUPPORT
 M: Alex Dubov 
 W: http://tifmxx.berlios.de/
diff --git a/drivers/media/i2c/Kconfig b/drivers/media/i2c/Kconfig
index bfdb494686bf..603ac087975b 100644
--- a/drivers/media/i2c/Kconfig
+++ b/drivers/media/i2c/Kconfig
@@ -614,6 +614,17 @@ config VIDEO_IMX274
  This is a V4L2 sensor driver for the Sony IMX274
  CMOS image sensor.
 
+config VIDEO_IMX319
+   tristate "Sony IMX319 sensor support"
+   depends on I2C && VIDEO_V4L2 && VIDEO_V4L2_SUBDEV_API
+   depends on MEDIA_CAMERA_SUPPORT
+   help
+ This is a Video4Linux2 sensor driver for the Sony
+ IMX319 camera.
+
+ To compile this driver as a module, choose M here: the
+ module will be called imx319.
+
 config VIDEO_OV2640
tristate "OmniVision OV2640 sensor support"
depends on VIDEO_V4L2 && I2C
diff --git a/drivers/media/i2c/Makefile b/drivers/media/i2c/Makefile
index a94eb03d10d4..d10b438577be 100644
--- a/drivers/media/i2c/Makefile
+++ b/drivers/media/i2c/Makefile
@@ -108,5 +108,6 @@ obj-$(CONFIG_VIDEO_OV2659)  += ov2659.o
 obj-$(CONFIG_VIDEO_TC358743)   += tc358743.o
 obj-$(CONFIG_VIDEO_IMX258) += imx258.o
 obj-$(CONFIG_VIDEO_IMX274) += imx274.o
+obj-$(CONFIG_VIDEO_IMX319) += imx319.o
 
 obj-$(CONFIG_SDR_MAX2175) += max2175.o
diff --git a/drivers/media/i2c/imx319.c b/drivers/media/i2c/imx319.c
new file mode 100644
index ..e10d60f500dd
--- /dev/null
+++ b/drivers/media/i2c/imx319.c
@@ -0,0 +1,2556 @@
+// SPDX-License-Identifier: GPL-2.0
+// Copyright (C) 2018 Intel Corporation
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define IMX319_REG_MODE_SELECT 0x0100
+#define IMX319_MODE_STANDBY0x00
+#define IMX319_MODE_STREAMING  0x01
+
+/* Chip ID */
+#define IMX319_REG_CHIP_ID 0x0016
+#define IMX319_CHIP_ID 0x0319
+
+/* V_TIMING internal */
+#define IMX319_REG_FLL 0x0340
+#define IMX319_FLL_MAX 0x
+
+/* Exposure control */
+#define IMX319_REG_EXPOSURE0x0202
+#define IMX319_EXPOSURE_MIN1
+#define IMX319_EXPOSURE_STEP   1
+#define IMX319_EXPOSURE_DEFAULT0x04f6
+
+/*
+ *  the digital control register for all color control looks like:
+ *  +-+--+
+ *  |  [7:0]  |   [15:8] |
+ *  +-+--+
+ *  |0x020f  |   0x020e |
+ *  --
+ *  it is used to calculate the digital gain times value

[PATCH v6] media: add imx319 camera sensor driver

2018-09-21 Thread bingbu . cao
From: Bingbu Cao 

Add a v4l2 sub-device driver for the Sony imx319 image sensor.
This is a camera sensor using the i2c bus for control and the
csi-2 bus for data.

This driver supports following features:
- manual exposure and analog/digital gain control support
- vblank/hblank control support
-  4 test patterns control support
- vflip/hflip control support (will impact the output bayer order)
- support following resolutions:
- 3264x2448, 3280x2464 @ 30fps
- 1936x1096, 1920x1080 @ 60fps
- 1640x1232, 1640x922, 1296x736, 1280x720 @ 120fps
- support 4 bayer orders output (via change v/hflip)
- SRGGB10(default), SGRBG10, SGBRG10, SBGGR10

Cc: Tomasz Figa 
Cc: Sakari Ailus 
Signed-off-by: Bingbu Cao 
Signed-off-by: Tianshu Qiu 

---

This patch is based on sakari's media-tree git:
https://git.linuxtv.org/sailus/media_tree.git/log/?h=for-4.20-1

Changes from v5:
 - add some comments for gain calculation
 - use lock to protect the format

Changes from v4 to v5:
 - use single PLL for all internal clocks
 - change link frequency to 482.4MHz
 - adjust frame timing for 2x2 binning modes
   and enlarge frame readout time
 - get CSI-2 link frequencies and external clock
   from firmware
 - use unlocked __v4l2_ctrl_grab() with change from:
   https://git.linuxtv.org/sailus/media_tree.git/commit/?h=unlocked-ctrl-grab

Changes since v1:
 - fix some coding style issues - line breaks
 - add v4l2_ctrl_grab() to prevent v/hflip change
   during streaming
 - add v4l2 ctrl event (un)subscribe support
 - add more info into commit message

---
---
 MAINTAINERS|7 +
 drivers/media/i2c/Kconfig  |   11 +
 drivers/media/i2c/Makefile |1 +
 drivers/media/i2c/imx319.c | 2545 
 4 files changed, 2564 insertions(+)
 create mode 100644 drivers/media/i2c/imx319.c

diff --git a/MAINTAINERS b/MAINTAINERS
index a5b256b25905..abc4abb6f83c 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -13530,6 +13530,13 @@ S: Maintained
 F: drivers/media/i2c/imx274.c
 F: Documentation/devicetree/bindings/media/i2c/imx274.txt
 
+SONY IMX319 SENSOR DRIVER
+M: Bingbu Cao 
+L: linux-media@vger.kernel.org
+T: git git://linuxtv.org/media_tree.git
+S: Maintained
+F: drivers/media/i2c/imx319.c
+
 SONY MEMORYSTICK CARD SUPPORT
 M: Alex Dubov 
 W: http://tifmxx.berlios.de/
diff --git a/drivers/media/i2c/Kconfig b/drivers/media/i2c/Kconfig
index bfdb494686bf..603ac087975b 100644
--- a/drivers/media/i2c/Kconfig
+++ b/drivers/media/i2c/Kconfig
@@ -614,6 +614,17 @@ config VIDEO_IMX274
  This is a V4L2 sensor driver for the Sony IMX274
  CMOS image sensor.
 
+config VIDEO_IMX319
+   tristate "Sony IMX319 sensor support"
+   depends on I2C && VIDEO_V4L2 && VIDEO_V4L2_SUBDEV_API
+   depends on MEDIA_CAMERA_SUPPORT
+   help
+ This is a Video4Linux2 sensor driver for the Sony
+ IMX319 camera.
+
+ To compile this driver as a module, choose M here: the
+ module will be called imx319.
+
 config VIDEO_OV2640
tristate "OmniVision OV2640 sensor support"
depends on VIDEO_V4L2 && I2C
diff --git a/drivers/media/i2c/Makefile b/drivers/media/i2c/Makefile
index a94eb03d10d4..d10b438577be 100644
--- a/drivers/media/i2c/Makefile
+++ b/drivers/media/i2c/Makefile
@@ -108,5 +108,6 @@ obj-$(CONFIG_VIDEO_OV2659)  += ov2659.o
 obj-$(CONFIG_VIDEO_TC358743)   += tc358743.o
 obj-$(CONFIG_VIDEO_IMX258) += imx258.o
 obj-$(CONFIG_VIDEO_IMX274) += imx274.o
+obj-$(CONFIG_VIDEO_IMX319) += imx319.o
 
 obj-$(CONFIG_SDR_MAX2175) += max2175.o
diff --git a/drivers/media/i2c/imx319.c b/drivers/media/i2c/imx319.c
new file mode 100644
index ..5e80b113c386
--- /dev/null
+++ b/drivers/media/i2c/imx319.c
@@ -0,0 +1,2545 @@
+// SPDX-License-Identifier: GPL-2.0
+// Copyright (C) 2018 Intel Corporation
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define IMX319_REG_MODE_SELECT 0x0100
+#define IMX319_MODE_STANDBY0x00
+#define IMX319_MODE_STREAMING  0x01
+
+/* Chip ID */
+#define IMX319_REG_CHIP_ID 0x0016
+#define IMX319_CHIP_ID 0x0319
+
+/* V_TIMING internal */
+#define IMX319_REG_FLL 0x0340
+#define IMX319_FLL_MAX 0x
+
+/* Exposure control */
+#define IMX319_REG_EXPOSURE0x0202
+#define IMX319_EXPOSURE_MIN1
+#define IMX319_EXPOSURE_STEP   1
+#define IMX319_EXPOSURE_DEFAULT0x04f6
+
+/*
+ *  the digital control register for all color control looks like:
+ *  +-+--+
+ *  |  [7:0]  |   [15:8] |
+ *  +-+--+
+ *  |0x020f  |   0x020e |
+ *  --
+ *  it is used to calculate the digital gain times value(integral + fractional)
+ *  the [15:8

[PATCH v5] media: add imx319 camera sensor driver

2018-09-16 Thread bingbu . cao
From: Bingbu Cao 

Add a v4l2 sub-device driver for the Sony imx319 image sensor.
This is a camera sensor using the i2c bus for control and the
csi-2 bus for data.

This driver supports following features:
- manual exposure and analog/digital gain control support
- vblank/hblank control support
-  4 test patterns control support
- vflip/hflip control support (will impact the output bayer order)
- support following resolutions:
- 3264x2448, 3280x2464 @ 30fps
- 1936x1096, 1920x1080 @ 60fps
- 1640x1232, 1640x922, 1296x736, 1280x720 @ 120fps
- support 4 bayer orders output (via change v/hflip)
- SRGGB10(default), SGRBG10, SGBRG10, SBGGR10

Signed-off-by: Bingbu Cao 
Signed-off-by: Tianshu Qiu 

---

This patch is based on sakari's media-tree git:
https://git.linuxtv.org/sailus/media_tree.git/log/?h=for-4.20-1

Changes from v4 to v5:
 - use single PLL for all internal clocks
 - change link frequency to 482.4MHz
 - adjust frame timing for 2x2 binning modes
   and enlarge frame readout time
 - get CSI-2 link frequencies and external clock
   from firmware
 - use unlocked __v4l2_ctrl_grab() with change from:
   https://git.linuxtv.org/sailus/media_tree.git/commit/?h=unlocked-ctrl-grab

Changes since v1:
 - fix some coding style issues - line breaks
 - add v4l2_ctrl_grab() to prevent v/hflip change
   during streaming
 - add v4l2 ctrl event (un)subscribe support
 - add more info into commit message

---
---
 MAINTAINERS|7 +
 drivers/media/i2c/Kconfig  |   11 +
 drivers/media/i2c/Makefile |1 +
 drivers/media/i2c/imx319.c | 2524 
 4 files changed, 2543 insertions(+)
 create mode 100644 drivers/media/i2c/imx319.c

diff --git a/MAINTAINERS b/MAINTAINERS
index a5b256b25905..abc4abb6f83c 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -13530,6 +13530,13 @@ S: Maintained
 F: drivers/media/i2c/imx274.c
 F: Documentation/devicetree/bindings/media/i2c/imx274.txt
 
+SONY IMX319 SENSOR DRIVER
+M: Bingbu Cao 
+L: linux-media@vger.kernel.org
+T: git git://linuxtv.org/media_tree.git
+S: Maintained
+F: drivers/media/i2c/imx319.c
+
 SONY MEMORYSTICK CARD SUPPORT
 M: Alex Dubov 
 W: http://tifmxx.berlios.de/
diff --git a/drivers/media/i2c/Kconfig b/drivers/media/i2c/Kconfig
index bfdb494686bf..603ac087975b 100644
--- a/drivers/media/i2c/Kconfig
+++ b/drivers/media/i2c/Kconfig
@@ -614,6 +614,17 @@ config VIDEO_IMX274
  This is a V4L2 sensor driver for the Sony IMX274
  CMOS image sensor.
 
+config VIDEO_IMX319
+   tristate "Sony IMX319 sensor support"
+   depends on I2C && VIDEO_V4L2 && VIDEO_V4L2_SUBDEV_API
+   depends on MEDIA_CAMERA_SUPPORT
+   help
+ This is a Video4Linux2 sensor driver for the Sony
+ IMX319 camera.
+
+ To compile this driver as a module, choose M here: the
+ module will be called imx319.
+
 config VIDEO_OV2640
tristate "OmniVision OV2640 sensor support"
depends on VIDEO_V4L2 && I2C
diff --git a/drivers/media/i2c/Makefile b/drivers/media/i2c/Makefile
index a94eb03d10d4..d10b438577be 100644
--- a/drivers/media/i2c/Makefile
+++ b/drivers/media/i2c/Makefile
@@ -108,5 +108,6 @@ obj-$(CONFIG_VIDEO_OV2659)  += ov2659.o
 obj-$(CONFIG_VIDEO_TC358743)   += tc358743.o
 obj-$(CONFIG_VIDEO_IMX258) += imx258.o
 obj-$(CONFIG_VIDEO_IMX274) += imx274.o
+obj-$(CONFIG_VIDEO_IMX319) += imx319.o
 
 obj-$(CONFIG_SDR_MAX2175) += max2175.o
diff --git a/drivers/media/i2c/imx319.c b/drivers/media/i2c/imx319.c
new file mode 100644
index ..43c28c701431
--- /dev/null
+++ b/drivers/media/i2c/imx319.c
@@ -0,0 +1,2524 @@
+// SPDX-License-Identifier: GPL-2.0
+// Copyright (C) 2018 Intel Corporation
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define IMX319_REG_MODE_SELECT 0x0100
+#define IMX319_MODE_STANDBY0x00
+#define IMX319_MODE_STREAMING  0x01
+
+/* Chip ID */
+#define IMX319_REG_CHIP_ID 0x0016
+#define IMX319_CHIP_ID 0x0319
+
+/* V_TIMING internal */
+#define IMX319_REG_FLL 0x0340
+#define IMX319_FLL_MAX 0x
+
+/* Exposure control */
+#define IMX319_REG_EXPOSURE0x0202
+#define IMX319_EXPOSURE_MIN1
+#define IMX319_EXPOSURE_STEP   1
+#define IMX319_EXPOSURE_DEFAULT0x04f6
+
+/* Analog gain control */
+#define IMX319_REG_ANALOG_GAIN 0x0204
+#define IMX319_ANA_GAIN_MIN0
+#define IMX319_ANA_GAIN_MAX960
+#define IMX319_ANA_GAIN_STEP   1
+#define IMX319_ANA_GAIN_DEFAULT0
+
+/* Digital gain control */
+#define IMX319_REG_DPGA_USE_GLOBAL_GAIN0x3ff9
+#define IMX319_REG_DIG_GAIN_GLOBAL 0x020e
+#define IMX319_DGTL_GAIN_MIN   256
+#define IMX319_DGTL_GAIN_MAX   4095
+#define IMX319_DGTL_GAIN_STEP  1

[PATCH v5 2/2] media: ak7375: Add ak7375 lens voice coil driver

2018-06-18 Thread bingbu . cao
From: Bingbu Cao 

Add a v4l2 sub-device driver for the ak7375 lens voice coil.
This is a voice coil module using the i2c bus to control the
focus position.

ak7375 can write multiple bytes of data at a time. If more
data is received instead of the stop condition after receiving
one byte of data, the address inside the chip is automatically
incremented and the data is written into the next address.

The ak7375 can control the position with 12 bits value and
consists of two 8 bit registers show as below:
register 0x00(AK7375_REG_POSITION):
+---+---+---+---+---+---+---+---+
|D11|D10|D09|D08|D07|D06|D05|D04|
+---+---+---+---+---+---+---+---+
register 0x01:
+---+---+---+---+---+---+---+---+
|D03|D02|D01|D00|---|---|---|---|
+---+---+---+---+---+---+---+---+

This driver support :
- set ak7375 to standby mode once suspend and
  turn it back to active if resume
- set the position via V4L2_CID_FOCUS_ABSOLUTE ctrl

Signed-off-by: Tianshu Qiu 
Signed-off-by: Bingbu Cao 
Reviewed-by: Sakari Ailus 

---
Changes from v1 -> v3:
- correct i2c write
- add media_entity_pads_init() into probe
- move the MAINTAINERs change into dt-binding change
- correct the compatible stringa
Changes since v3:
- add active flag to indicate the mode
- refine some coding style

This patch is based on Sakari's media-tree git:
https://git.linuxtv.org/sailus/media_tree.git/log/?h=for-4.18-5
---
---
 drivers/media/i2c/Kconfig  |  10 ++
 drivers/media/i2c/Makefile |   1 +
 drivers/media/i2c/ak7375.c | 293 +
 3 files changed, 304 insertions(+)
 create mode 100644 drivers/media/i2c/ak7375.c

diff --git a/drivers/media/i2c/Kconfig b/drivers/media/i2c/Kconfig
index 341452fe98df..ff3cb5afb0e1 100644
--- a/drivers/media/i2c/Kconfig
+++ b/drivers/media/i2c/Kconfig
@@ -326,6 +326,16 @@ config VIDEO_AD5820
  This is a driver for the AD5820 camera lens voice coil.
  It is used for example in Nokia N900 (RX-51).
 
+config VIDEO_AK7375
+   tristate "AK7375 lens voice coil support"
+   depends on I2C && VIDEO_V4L2 && MEDIA_CONTROLLER
+   depends on VIDEO_V4L2_SUBDEV_API
+   help
+ This is a driver for the AK7375 camera lens voice coil.
+ AK7375 is a 12 bit DAC with 120mA output current sink
+ capability. This is designed for linear control of
+ voice coil motors, controlled via I2C serial interface.
+
 config VIDEO_DW9714
tristate "DW9714 lens voice coil support"
depends on I2C && VIDEO_V4L2 && MEDIA_CONTROLLER
diff --git a/drivers/media/i2c/Makefile b/drivers/media/i2c/Makefile
index d679d57cd3b3..05b97e319ea9 100644
--- a/drivers/media/i2c/Makefile
+++ b/drivers/media/i2c/Makefile
@@ -23,6 +23,7 @@ obj-$(CONFIG_VIDEO_SAA7127) += saa7127.o
 obj-$(CONFIG_VIDEO_SAA7185) += saa7185.o
 obj-$(CONFIG_VIDEO_SAA6752HS) += saa6752hs.o
 obj-$(CONFIG_VIDEO_AD5820)  += ad5820.o
+obj-$(CONFIG_VIDEO_AK7375)  += ak7375.o
 obj-$(CONFIG_VIDEO_DW9714)  += dw9714.o
 obj-$(CONFIG_VIDEO_ADV7170) += adv7170.o
 obj-$(CONFIG_VIDEO_ADV7175) += adv7175.o
diff --git a/drivers/media/i2c/ak7375.c b/drivers/media/i2c/ak7375.c
new file mode 100644
index ..9f039513d57f
--- /dev/null
+++ b/drivers/media/i2c/ak7375.c
@@ -0,0 +1,293 @@
+// SPDX-License-Identifier: GPL-2.0
+// Copyright (C) 2018 Intel Corporation
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define AK7375_MAX_FOCUS_POS   4095
+/*
+ * This sets the minimum granularity for the focus positions.
+ * A value of 1 gives maximum accuracy for a desired focus position
+ */
+#define AK7375_FOCUS_STEPS 1
+/*
+ * This acts as the minimum granularity of lens movement.
+ * Keep this value power of 2, so the control steps can be
+ * uniformly adjusted for gradual lens movement, with desired
+ * number of control steps.
+ */
+#define AK7375_CTRL_STEPS  64
+#define AK7375_CTRL_DELAY_US   1000
+
+#define AK7375_REG_POSITION0x0
+#define AK7375_REG_CONT0x2
+#define AK7375_MODE_ACTIVE 0x0
+#define AK7375_MODE_STANDBY0x40
+
+/* ak7375 device structure */
+struct ak7375_device {
+   struct v4l2_ctrl_handler ctrls_vcm;
+   struct v4l2_subdev sd;
+   struct v4l2_ctrl *focus;
+   /* active or standby mode */
+   bool active;
+};
+
+static inline struct ak7375_device *to_ak7375_vcm(struct v4l2_ctrl *ctrl)
+{
+   return container_of(ctrl->handler, struct ak7375_device, ctrls_vcm);
+}
+
+static inline struct ak7375_device *sd_to_ak7375_vcm(struct v4l2_subdev 
*subdev)
+{
+   return container_of(subdev, struct ak7375_device, sd);
+}
+
+static int ak7375_i2c_write(struct ak7375_device *ak7375,
+   u8 addr, u16 data, u8 size)
+{
+   struct i2c_client *client = v4l2_get_subdevdata(>sd);
+   u8 buf[3];
+   int ret;
+
+   if (size != 1 && size != 2)
+   r

[PATCH v5 1/2] dt-bindings: Add bindings for AKM ak7375 voice coil lens

2018-06-18 Thread bingbu . cao
From: Bingbu Cao 

Add device tree bindings for AKM ak7375 voice coil lens
driver. This chip is used to drive a lens in a camera module.

Signed-off-by: Tianshu Qiu 
Signed-off-by: Bingbu Cao 
Reviewed-by: Rob Herring 

---
Changes since v1:
- add the MAINTAINERS change
- correct the vendor prefix from akm to asahi-kasei

This patch is based on Sakari's media-tree git:
https://git.linuxtv.org/sailus/media_tree.git/log/?h=for-4.18-5
---
---
 Documentation/devicetree/bindings/media/i2c/ak7375.txt | 8 
 MAINTAINERS| 8 
 2 files changed, 16 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/media/i2c/ak7375.txt

diff --git a/Documentation/devicetree/bindings/media/i2c/ak7375.txt 
b/Documentation/devicetree/bindings/media/i2c/ak7375.txt
new file mode 100644
index ..aa3e24b41241
--- /dev/null
+++ b/Documentation/devicetree/bindings/media/i2c/ak7375.txt
@@ -0,0 +1,8 @@
+Asahi Kasei Microdevices AK7375 voice coil lens driver
+
+AK7375 is a camera voice coil lens.
+
+Mandatory properties:
+
+- compatible: "asahi-kasei,ak7375"
+- reg: I2C slave address
diff --git a/MAINTAINERS b/MAINTAINERS
index ea362219c4aa..ad68d75abc84 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -2258,6 +2258,14 @@ L:   linux-l...@vger.kernel.org
 S: Maintained
 F: drivers/leds/leds-as3645a.c
 
+ASAHI KASEI AK7375 LENS VOICE COIL DRIVER
+M: Tianshu Qiu 
+L: linux-media@vger.kernel.org
+T: git git://linuxtv.org/media_tree.git
+S: Maintained
+F: drivers/media/i2c/ak7375.c
+F: Documentation/devicetree/bindings/media/i2c/ak7375.txt
+
 ASAHI KASEI AK8974 DRIVER
 M: Linus Walleij 
 L: linux-...@vger.kernel.org
-- 
1.9.1



[PATCH v4 1/2] dt-bindings: Add bindings for AKM ak7375 voice coil lens

2018-06-06 Thread bingbu . cao
From: Bingbu Cao 

Add device tree bindings for AKM ak7375 voice coil lens
driver. This chip is used to drive a lens in a camera module.

Signed-off-by: Tianshu Qiu 
Signed-off-by: Bingbu Cao 

---
Changes since v1:
- add the MAINTAINERS change
- correct the vendor prefix from akm to asahi-kasei
---
---
 Documentation/devicetree/bindings/media/i2c/ak7375.txt | 8 
 MAINTAINERS| 8 
 2 files changed, 16 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/media/i2c/ak7375.txt

diff --git a/Documentation/devicetree/bindings/media/i2c/ak7375.txt 
b/Documentation/devicetree/bindings/media/i2c/ak7375.txt
new file mode 100644
index ..aa3e24b41241
--- /dev/null
+++ b/Documentation/devicetree/bindings/media/i2c/ak7375.txt
@@ -0,0 +1,8 @@
+Asahi Kasei Microdevices AK7375 voice coil lens driver
+
+AK7375 is a camera voice coil lens.
+
+Mandatory properties:
+
+- compatible: "asahi-kasei,ak7375"
+- reg: I2C slave address
diff --git a/MAINTAINERS b/MAINTAINERS
index ea362219c4aa..ad68d75abc84 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -2258,6 +2258,14 @@ L:   linux-l...@vger.kernel.org
 S: Maintained
 F: drivers/leds/leds-as3645a.c
 
+ASAHI KASEI AK7375 LENS VOICE COIL DRIVER
+M: Tianshu Qiu 
+L: linux-media@vger.kernel.org
+T: git git://linuxtv.org/media_tree.git
+S: Maintained
+F: drivers/media/i2c/ak7375.c
+F: Documentation/devicetree/bindings/media/i2c/ak7375.txt
+
 ASAHI KASEI AK8974 DRIVER
 M: Linus Walleij 
 L: linux-...@vger.kernel.org
-- 
1.9.1



[PATCH v4 2/2] media: ak7375: Add ak7375 lens voice coil driver

2018-06-06 Thread bingbu . cao
From: Bingbu Cao 

Add a v4l2 sub-device driver for the ak7375 lens voice coil.
This is a voice coil module using the i2c bus to control the
focus position.

ak7375 can write multiple bytes of data at a time. If more
data is received instead of the stop condition after receiving
one byte of data, the address inside the chip is automatically
incremented and the data is written into the next address.

The ak7375 can control the position with 12 bits value and
consists of two 8 bit registers show as below:
register 0x00(AK7375_REG_POSITION):
+---+---+---+---+---+---+---+---+
|D11|D10|D09|D08|D07|D06|D05|D04|
+---+---+---+---+---+---+---+---+
register 0x01:
+---+---+---+---+---+---+---+---+
|D03|D02|D01|D00|---|---|---|---|
+---+---+---+---+---+---+---+---+

This driver support :
- set ak7375 to standby mode once suspend and
  turn it back to active if resume
- set the position via V4L2_CID_FOCUS_ABSOLUTE ctrl

Signed-off-by: Tianshu Qiu 
Signed-off-by: Bingbu Cao 

---
Changes from v1 -> v3:
- correct i2c write
- add media_entity_pads_init() into probe
- move the MAINTAINERs change into dt-binding change
- correct the compatible stringa
Changes since v3:
- add active flag to indicate the mode
---
---
 drivers/media/i2c/Kconfig  |  10 ++
 drivers/media/i2c/Makefile |   1 +
 drivers/media/i2c/ak7375.c | 289 +
 3 files changed, 300 insertions(+)
 create mode 100644 drivers/media/i2c/ak7375.c

diff --git a/drivers/media/i2c/Kconfig b/drivers/media/i2c/Kconfig
index 341452fe98df..ff3cb5afb0e1 100644
--- a/drivers/media/i2c/Kconfig
+++ b/drivers/media/i2c/Kconfig
@@ -326,6 +326,16 @@ config VIDEO_AD5820
  This is a driver for the AD5820 camera lens voice coil.
  It is used for example in Nokia N900 (RX-51).
 
+config VIDEO_AK7375
+   tristate "AK7375 lens voice coil support"
+   depends on I2C && VIDEO_V4L2 && MEDIA_CONTROLLER
+   depends on VIDEO_V4L2_SUBDEV_API
+   help
+ This is a driver for the AK7375 camera lens voice coil.
+ AK7375 is a 12 bit DAC with 120mA output current sink
+ capability. This is designed for linear control of
+ voice coil motors, controlled via I2C serial interface.
+
 config VIDEO_DW9714
tristate "DW9714 lens voice coil support"
depends on I2C && VIDEO_V4L2 && MEDIA_CONTROLLER
diff --git a/drivers/media/i2c/Makefile b/drivers/media/i2c/Makefile
index d679d57cd3b3..05b97e319ea9 100644
--- a/drivers/media/i2c/Makefile
+++ b/drivers/media/i2c/Makefile
@@ -23,6 +23,7 @@ obj-$(CONFIG_VIDEO_SAA7127) += saa7127.o
 obj-$(CONFIG_VIDEO_SAA7185) += saa7185.o
 obj-$(CONFIG_VIDEO_SAA6752HS) += saa6752hs.o
 obj-$(CONFIG_VIDEO_AD5820)  += ad5820.o
+obj-$(CONFIG_VIDEO_AK7375)  += ak7375.o
 obj-$(CONFIG_VIDEO_DW9714)  += dw9714.o
 obj-$(CONFIG_VIDEO_ADV7170) += adv7170.o
 obj-$(CONFIG_VIDEO_ADV7175) += adv7175.o
diff --git a/drivers/media/i2c/ak7375.c b/drivers/media/i2c/ak7375.c
new file mode 100644
index ..e716821cf438
--- /dev/null
+++ b/drivers/media/i2c/ak7375.c
@@ -0,0 +1,289 @@
+// SPDX-License-Identifier: GPL-2.0
+// Copyright (C) 2018 Intel Corporation
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define AK7375_MAX_FOCUS_POS   4095
+/*
+ * This sets the minimum granularity for the focus positions.
+ * A value of 1 gives maximum accuracy for a desired focus position
+ */
+#define AK7375_FOCUS_STEPS 1
+/*
+ * This acts as the minimum granularity of lens movement.
+ * Keep this value power of 2, so the control steps can be
+ * uniformly adjusted for gradual lens movement, with desired
+ * number of control steps.
+ */
+#define AK7375_CTRL_STEPS  64
+#define AK7375_CTRL_DELAY_US   1000
+
+#define AK7375_REG_POSITION0x0
+#define AK7375_REG_CONT0x2
+#define AK7375_MODE_ACTIVE 0x0
+#define AK7375_MODE_STANDBY0x40
+
+/* ak7375 device structure */
+struct ak7375_device {
+   struct v4l2_ctrl_handler ctrls_vcm;
+   struct v4l2_subdev sd;
+   struct v4l2_ctrl *focus;
+   /* active or standby mode */
+   bool active;
+};
+
+static inline struct ak7375_device *to_ak7375_vcm(struct v4l2_ctrl *ctrl)
+{
+   return container_of(ctrl->handler, struct ak7375_device, ctrls_vcm);
+}
+
+static inline struct ak7375_device *sd_to_ak7375_vcm(struct v4l2_subdev 
*subdev)
+{
+   return container_of(subdev, struct ak7375_device, sd);
+}
+
+static int ak7375_i2c_write(struct ak7375_device *ak7375,
+   u8 addr, u16 data, int size)
+{
+   struct i2c_client *client = v4l2_get_subdevdata(>sd);
+   int ret;
+   u8 buf[3];
+
+   if (size != 1 && size != 2)
+   return -EINVAL;
+   buf[0] = addr;
+   buf[size] = data & 0xff;
+   if (size == 2)
+   buf[1] = (data >> 8) & 0xff;
+   ret = i2c_master_sen

[PATCH v3 1/2] dt-bindings: Add bindings for AKM ak7375 voice coil lens

2018-06-04 Thread bingbu . cao
From: Bingbu Cao 

Add device tree bindings for asahi-kasei ak7375 voice coil lens
driver. This chip is used to drive a lens in a camera module.

Signed-off-by: Tianshu Qiu 
Signed-off-by: Bingbu Cao 

---
Changes since v1:
- add the MAINTAINERS change
- correct the vendor prefix from akm to asahi-kasei
---
---
 Documentation/devicetree/bindings/media/i2c/ak7375.txt | 8 
 MAINTAINERS| 8 
 2 files changed, 16 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/media/i2c/ak7375.txt

diff --git a/Documentation/devicetree/bindings/media/i2c/ak7375.txt 
b/Documentation/devicetree/bindings/media/i2c/ak7375.txt
new file mode 100644
index ..aa3e24b41241
--- /dev/null
+++ b/Documentation/devicetree/bindings/media/i2c/ak7375.txt
@@ -0,0 +1,8 @@
+Asahi Kasei Microdevices AK7375 voice coil lens driver
+
+AK7375 is a camera voice coil lens.
+
+Mandatory properties:
+
+- compatible: "asahi-kasei,ak7375"
+- reg: I2C slave address
diff --git a/MAINTAINERS b/MAINTAINERS
index ea362219c4aa..ad68d75abc84 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -2258,6 +2258,14 @@ L:   linux-l...@vger.kernel.org
 S: Maintained
 F: drivers/leds/leds-as3645a.c
 
+ASAHI KASEI AK7375 LENS VOICE COIL DRIVER
+M: Tianshu Qiu 
+L: linux-media@vger.kernel.org
+T: git git://linuxtv.org/media_tree.git
+S: Maintained
+F: drivers/media/i2c/ak7375.c
+F: Documentation/devicetree/bindings/media/i2c/ak7375.txt
+
 ASAHI KASEI AK8974 DRIVER
 M: Linus Walleij 
 L: linux-...@vger.kernel.org
-- 
1.9.1



[PATCH v3 2/2] media: ak7375: Add ak7375 lens voice coil driver

2018-06-04 Thread bingbu . cao
From: Bingbu Cao 

Add a v4l2 sub-device driver for the ak7375 lens voice coil.
This is a voice coil module using the i2c bus to control the
focus position.

ak7375 can write multiple bytes of data at a time. If more
data is received instead of the stop condition after receiving
one byte of data, the address inside the chip is automatically
incremented and the data is written into the next address.

The ak7375 can control the position with 12 bits value and
consists of two 8 bit registers show as below:
register 0x00(AK7375_REG_POSITION):
+---+---+---+---+---+---+---+---+
|D11|D10|D09|D08|D07|D06|D05|D04|
+---+---+---+---+---+---+---+---+
register 0x01:
+---+---+---+---+---+---+---+---+
|D03|D02|D01|D00|---|---|---|---|
+---+---+---+---+---+---+---+---+

This driver support :
- set ak7375 to standby mode once suspend and
  turn it back to active if resume
- set the position via V4L2_CID_FOCUS_ABSOLUTE ctrl

Signed-off-by: Tianshu Qiu 
Signed-off-by: Bingbu Cao 

---
Changes from v1:
- correct i2c write
- add media_entity_pads_init() into probe
- move the MAINTAINERs change into dt-bindings change
- correct the compatible string
---
---
 drivers/media/i2c/Kconfig  |  10 ++
 drivers/media/i2c/Makefile |   1 +
 drivers/media/i2c/ak7375.c | 278 +
 3 files changed, 289 insertions(+)
 create mode 100644 drivers/media/i2c/ak7375.c

diff --git a/drivers/media/i2c/Kconfig b/drivers/media/i2c/Kconfig
index 341452fe98df..ff3cb5afb0e1 100644
--- a/drivers/media/i2c/Kconfig
+++ b/drivers/media/i2c/Kconfig
@@ -326,6 +326,16 @@ config VIDEO_AD5820
  This is a driver for the AD5820 camera lens voice coil.
  It is used for example in Nokia N900 (RX-51).
 
+config VIDEO_AK7375
+   tristate "AK7375 lens voice coil support"
+   depends on I2C && VIDEO_V4L2 && MEDIA_CONTROLLER
+   depends on VIDEO_V4L2_SUBDEV_API
+   help
+ This is a driver for the AK7375 camera lens voice coil.
+ AK7375 is a 12 bit DAC with 120mA output current sink
+ capability. This is designed for linear control of
+ voice coil motors, controlled via I2C serial interface.
+
 config VIDEO_DW9714
tristate "DW9714 lens voice coil support"
depends on I2C && VIDEO_V4L2 && MEDIA_CONTROLLER
diff --git a/drivers/media/i2c/Makefile b/drivers/media/i2c/Makefile
index d679d57cd3b3..05b97e319ea9 100644
--- a/drivers/media/i2c/Makefile
+++ b/drivers/media/i2c/Makefile
@@ -23,6 +23,7 @@ obj-$(CONFIG_VIDEO_SAA7127) += saa7127.o
 obj-$(CONFIG_VIDEO_SAA7185) += saa7185.o
 obj-$(CONFIG_VIDEO_SAA6752HS) += saa6752hs.o
 obj-$(CONFIG_VIDEO_AD5820)  += ad5820.o
+obj-$(CONFIG_VIDEO_AK7375)  += ak7375.o
 obj-$(CONFIG_VIDEO_DW9714)  += dw9714.o
 obj-$(CONFIG_VIDEO_ADV7170) += adv7170.o
 obj-$(CONFIG_VIDEO_ADV7175) += adv7175.o
diff --git a/drivers/media/i2c/ak7375.c b/drivers/media/i2c/ak7375.c
new file mode 100644
index ..94bcadae4258
--- /dev/null
+++ b/drivers/media/i2c/ak7375.c
@@ -0,0 +1,278 @@
+// SPDX-License-Identifier: GPL-2.0
+// Copyright (C) 2018 Intel Corporation
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define AK7375_MAX_FOCUS_POS   4095
+/*
+ * This sets the minimum granularity for the focus positions.
+ * A value of 1 gives maximum accuracy for a desired focus position
+ */
+#define AK7375_FOCUS_STEPS 1
+/*
+ * This acts as the minimum granularity of lens movement.
+ * Keep this value power of 2, so the control steps can be
+ * uniformly adjusted for gradual lens movement, with desired
+ * number of control steps.
+ */
+#define AK7375_CTRL_STEPS  64
+#define AK7375_CTRL_DELAY_US   1000
+
+#define AK7375_REG_POSITION0x0
+#define AK7375_REG_CONT0x2
+#define AK7375_MODE_ACTIVE 0x0
+#define AK7375_MODE_STANDBY0x40
+
+/* ak7375 device structure */
+struct ak7375_device {
+   struct v4l2_ctrl_handler ctrls_vcm;
+   struct v4l2_subdev sd;
+   struct v4l2_ctrl *focus;
+};
+
+static inline struct ak7375_device *to_ak7375_vcm(struct v4l2_ctrl *ctrl)
+{
+   return container_of(ctrl->handler, struct ak7375_device, ctrls_vcm);
+}
+
+static inline struct ak7375_device *sd_to_ak7375_vcm(struct v4l2_subdev 
*subdev)
+{
+   return container_of(subdev, struct ak7375_device, sd);
+}
+
+static int ak7375_i2c_write(struct ak7375_device *ak7375,
+   u8 addr, u16 data, int size)
+{
+   struct i2c_client *client = v4l2_get_subdevdata(>sd);
+   int ret;
+   u8 buf[3];
+
+   if (size != 1 && size != 2)
+   return -EINVAL;
+   buf[0] = addr;
+   buf[size] = data & 0xff;
+   if (size == 2)
+   buf[1] = (data >> 8) & 0xff;
+   ret = i2c_master_send(client, (const char *)buf, size + 1);
+   if (ret < 0)
+   return ret;
+   if (ret != size + 1)
+  

[PATCH v2] media: add imx355 camera sensor driver

2018-05-31 Thread bingbu . cao
From: Bingbu Cao 

Add a v4l2 sub-device driver for the Sony imx355 image sensor.
This is a camera sensor using the i2c bus for control and the
csi-2 bus for data.

This driver supports following features:

- manual exposure and analog/digital gain control support
- vblank/hblank control support
- 4 test patterns control support
- vflip/hflip control support (will impact the output bayer order)
- support following resolutions:
- 3268x2448, 3264x2448, 3280x2464 @ 30fps
- 1940x1096, 1936x1096, 1924x1080, 1920x1080 @ 60fps
- 1640x1232, 1640x922, 1300x736, 1296x736,
  1284x720, 1280x720 820x616 @ 120fps
- support 4 bayer orders output (via change v/hflip)
- SRGGB10(default), SGRBG10, SGBRG10, SBGGR10

Signed-off-by: Tianshu Qiu 
Signed-off-by: Bingbu Cao 

---

This patch is based on sakari's media-tree git:
https://git.linuxtv.org/sailus/media_tree.git/log/?h=for-4.18-5

changes since v1:
 - fix some coding style issues - line breaks
 - add v4l2_ctrl_grab() to prevent v/hflip change
   during streaming
 - add v4l2 ctrl event (un)subscribe support
 - correct link frequency
 - add more info into commit message

---
---
 MAINTAINERS|7 +
 drivers/media/i2c/Kconfig  |   11 +
 drivers/media/i2c/Makefile |1 +
 drivers/media/i2c/imx355.c | 1742 
 4 files changed, 1761 insertions(+)
 create mode 100644 drivers/media/i2c/imx355.c

diff --git a/MAINTAINERS b/MAINTAINERS
index ea362219c4aa..d955067bcb61 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -13085,6 +13085,13 @@ S: Maintained
 F: drivers/media/i2c/imx274.c
 F: Documentation/devicetree/bindings/media/i2c/imx274.txt
 
+SONY IMX355 SENSOR DRIVER
+M: Tianshu Qiu 
+L: linux-media@vger.kernel.org
+T: git git://linuxtv.org/media_tree.git
+S: Maintained
+F: drivers/media/i2c/imx355.c
+
 SONY MEMORYSTICK CARD SUPPORT
 M: Alex Dubov 
 W: http://tifmxx.berlios.de/
diff --git a/drivers/media/i2c/Kconfig b/drivers/media/i2c/Kconfig
index 341452fe98df..2d50b6c4300f 100644
--- a/drivers/media/i2c/Kconfig
+++ b/drivers/media/i2c/Kconfig
@@ -594,6 +594,17 @@ config VIDEO_IMX274
  This is a V4L2 sensor-level driver for the Sony IMX274
  CMOS image sensor.
 
+config VIDEO_IMX355
+   tristate "Sony IMX355 sensor support"
+   depends on I2C && VIDEO_V4L2 && VIDEO_V4L2_SUBDEV_API
+   depends on MEDIA_CAMERA_SUPPORT
+   help
+ This is a Video4Linux2 sensor driver for the Sony
+ IMX355 camera.
+
+ To compile this driver as a module, choose M here: the
+ module will be called imx355.
+
 config VIDEO_OV2640
tristate "OmniVision OV2640 sensor support"
depends on VIDEO_V4L2 && I2C
diff --git a/drivers/media/i2c/Makefile b/drivers/media/i2c/Makefile
index d679d57cd3b3..c8a417650aee 100644
--- a/drivers/media/i2c/Makefile
+++ b/drivers/media/i2c/Makefile
@@ -103,5 +103,6 @@ obj-$(CONFIG_VIDEO_OV2659)  += ov2659.o
 obj-$(CONFIG_VIDEO_TC358743)   += tc358743.o
 obj-$(CONFIG_VIDEO_IMX258) += imx258.o
 obj-$(CONFIG_VIDEO_IMX274) += imx274.o
+obj-$(CONFIG_VIDEO_IMX355) += imx355.o
 
 obj-$(CONFIG_SDR_MAX2175) += max2175.o
diff --git a/drivers/media/i2c/imx355.c b/drivers/media/i2c/imx355.c
new file mode 100644
index ..afc78b2b033f
--- /dev/null
+++ b/drivers/media/i2c/imx355.c
@@ -0,0 +1,1742 @@
+// SPDX-License-Identifier: GPL-2.0
+// Copyright (C) 2017 - 2018 Intel Corporation
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define IMX355_REG_MODE_SELECT 0x0100
+#define IMX355_MODE_STANDBY0x00
+#define IMX355_MODE_STREAMING  0x01
+
+/* Chip ID */
+#define IMX355_REG_CHIP_ID 0x0016
+#define IMX355_CHIP_ID 0x0355
+
+/* V_TIMING internal */
+#define IMX355_REG_FLL 0x0340
+#define IMX355_FLL_MAX 0x
+
+/* Exposure control */
+#define IMX355_REG_EXPOSURE0x0202
+#define IMX355_EXPOSURE_MIN1
+#define IMX355_EXPOSURE_STEP   1
+#define IMX355_EXPOSURE_DEFAULT0x0282
+
+/* Analog gain control */
+#define IMX355_REG_ANALOG_GAIN 0x0204
+#define IMX355_ANA_GAIN_MIN0
+#define IMX355_ANA_GAIN_MAX960
+#define IMX355_ANA_GAIN_STEP   1
+#define IMX355_ANA_GAIN_DEFAULT0
+
+/* Digital gain control */
+#define IMX355_REG_DPGA_USE_GLOBAL_GAIN0x3070
+#define IMX355_REG_DIG_GAIN_GLOBAL 0x020e
+#define IMX355_DGTL_GAIN_MIN   256
+#define IMX355_DGTL_GAIN_MAX   4095
+#define IMX355_DGTL_GAIN_STEP  1
+#define IMX355_DGTL_GAIN_DEFAULT   256
+
+/* Test Pattern Control */
+#define IMX355_REG_TEST_PATTERN0x0600
+#define IMX355_TEST_PATTERN_DISABLED   0
+#define IMX355_TEST_PATTERN_SOLID_COLOR1
+#define IMX35

[RESEND PATCH V2 2/2] media: ak7375: Add ak7375 lens voice coil driver

2018-05-25 Thread bingbu . cao
From: Bingbu Cao <bingbu@intel.com>

Add a V4L2 sub-device driver for the ak7375 lens voice coil.
This is a voice coil module using the I2C bus to control the
focus position.

Signed-off-by: Tianshu Qiu <tian.shu@intel.com>
Signed-off-by: Bingbu Cao <bingbu@intel.com>
---
 MAINTAINERS|   8 ++
 drivers/media/i2c/Kconfig  |  10 ++
 drivers/media/i2c/Makefile |   1 +
 drivers/media/i2c/ak7375.c | 278 +
 4 files changed, 297 insertions(+)
 create mode 100644 drivers/media/i2c/ak7375.c

diff --git a/MAINTAINERS b/MAINTAINERS
index ea362219c4aa..20379a7baca0 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -625,6 +625,14 @@ T: git git://linuxtv.org/anttip/media_tree.git
 S: Maintained
 F: drivers/media/usb/airspy/
 
+AKM AK7375 LENS VOICE COIL DRIVER
+M: Tianshu Qiu <tian.shu@intel.com>
+L: linux-media@vger.kernel.org
+T: git git://linuxtv.org/media_tree.git
+S: Maintained
+F: drivers/media/i2c/ak7375.c
+F: Documentation/devicetree/bindings/media/i2c/akm,ak7375.txt
+
 ALACRITECH GIGABIT ETHERNET DRIVER
 M: Lino Sanfilippo <linosanfili...@gmx.de>
 S: Maintained
diff --git a/drivers/media/i2c/Kconfig b/drivers/media/i2c/Kconfig
index 341452fe98df..ff3cb5afb0e1 100644
--- a/drivers/media/i2c/Kconfig
+++ b/drivers/media/i2c/Kconfig
@@ -326,6 +326,16 @@ config VIDEO_AD5820
  This is a driver for the AD5820 camera lens voice coil.
  It is used for example in Nokia N900 (RX-51).
 
+config VIDEO_AK7375
+   tristate "AK7375 lens voice coil support"
+   depends on I2C && VIDEO_V4L2 && MEDIA_CONTROLLER
+   depends on VIDEO_V4L2_SUBDEV_API
+   help
+ This is a driver for the AK7375 camera lens voice coil.
+ AK7375 is a 12 bit DAC with 120mA output current sink
+ capability. This is designed for linear control of
+ voice coil motors, controlled via I2C serial interface.
+
 config VIDEO_DW9714
tristate "DW9714 lens voice coil support"
depends on I2C && VIDEO_V4L2 && MEDIA_CONTROLLER
diff --git a/drivers/media/i2c/Makefile b/drivers/media/i2c/Makefile
index d679d57cd3b3..05b97e319ea9 100644
--- a/drivers/media/i2c/Makefile
+++ b/drivers/media/i2c/Makefile
@@ -23,6 +23,7 @@ obj-$(CONFIG_VIDEO_SAA7127) += saa7127.o
 obj-$(CONFIG_VIDEO_SAA7185) += saa7185.o
 obj-$(CONFIG_VIDEO_SAA6752HS) += saa6752hs.o
 obj-$(CONFIG_VIDEO_AD5820)  += ad5820.o
+obj-$(CONFIG_VIDEO_AK7375)  += ak7375.o
 obj-$(CONFIG_VIDEO_DW9714)  += dw9714.o
 obj-$(CONFIG_VIDEO_ADV7170) += adv7170.o
 obj-$(CONFIG_VIDEO_ADV7175) += adv7175.o
diff --git a/drivers/media/i2c/ak7375.c b/drivers/media/i2c/ak7375.c
new file mode 100644
index ..012e673e9ced
--- /dev/null
+++ b/drivers/media/i2c/ak7375.c
@@ -0,0 +1,278 @@
+// SPDX-License-Identifier: GPL-2.0
+// Copyright (C) 2018 Intel Corporation
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define AK7375_MAX_FOCUS_POS   4095
+/*
+ * This sets the minimum granularity for the focus positions.
+ * A value of 1 gives maximum accuracy for a desired focus position
+ */
+#define AK7375_FOCUS_STEPS 1
+/*
+ * This acts as the minimum granularity of lens movement.
+ * Keep this value power of 2, so the control steps can be
+ * uniformly adjusted for gradual lens movement, with desired
+ * number of control steps.
+ */
+#define AK7375_CTRL_STEPS  64
+#define AK7375_CTRL_DELAY_US   1000
+
+#define AK7375_REG_POSITION0x0
+#define AK7375_REG_CONT0x2
+#define AK7375_MODE_ACTIVE 0x0
+#define AK7375_MODE_STANDBY0x40
+
+/* ak7375 device structure */
+struct ak7375_device {
+   struct v4l2_ctrl_handler ctrls_vcm;
+   struct v4l2_subdev sd;
+   struct v4l2_ctrl *focus;
+};
+
+static inline struct ak7375_device *to_ak7375_vcm(struct v4l2_ctrl *ctrl)
+{
+   return container_of(ctrl->handler, struct ak7375_device, ctrls_vcm);
+}
+
+static inline struct ak7375_device *sd_to_ak7375_vcm(struct v4l2_subdev 
*subdev)
+{
+   return container_of(subdev, struct ak7375_device, sd);
+}
+
+static int ak7375_i2c_write(struct ak7375_device *ak7375,
+   u8 addr, u16 data, int size)
+{
+   struct i2c_client *client = v4l2_get_subdevdata(>sd);
+   int ret;
+   u8 buf[3];
+
+   if (size != 1 && size != 2)
+   return -EINVAL;
+   buf[0] = addr;
+   buf[2] = data & 0xff;
+   if (size == 2)
+   buf[1] = data >> 8;
+   ret = i2c_master_send(client, (const char *)buf, size + 1);
+   if (ret < 0)
+   return ret;
+   if (ret != size + 1)
+   return -EIO;
+   return 0;
+}
+
+static int ak7375_set_ctrl(struct v4l2_ctrl *ctrl)
+{
+   struct ak7375_device *dev_vcm = to_ak7375_vcm(ctrl);
+
+   if (ctrl->id == V4L2_CID_FOCUS_ABSOLUTE)
+  

[RESEND PATCH V2 1/2] dt-bindings: Add bindings for AKM ak7375 voice coil lens

2018-05-25 Thread bingbu . cao
From: Bingbu Cao <bingbu@intel.com>

Add device tree bindings for AKM ak7375 voice coil lens
driver. This chip is used to drive a lens in a camera module.

Signed-off-by: Tianshu Qiu <tian.shu@intel.com>
Signed-off-by: Bingbu Cao <bingbu@intel.com>
---
Changes since v1:
 - remove the vendor prefix change
---
 Documentation/devicetree/bindings/media/i2c/ak7375.txt | 8 
 1 file changed, 8 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/media/i2c/ak7375.txt

diff --git a/Documentation/devicetree/bindings/media/i2c/ak7375.txt 
b/Documentation/devicetree/bindings/media/i2c/ak7375.txt
new file mode 100644
index ..aa3e24b41241
--- /dev/null
+++ b/Documentation/devicetree/bindings/media/i2c/ak7375.txt
@@ -0,0 +1,8 @@
+Asahi Kasei Microdevices AK7375 voice coil lens driver
+
+AK7375 is a camera voice coil lens.
+
+Mandatory properties:
+
+- compatible: "asahi-kasei,ak7375"
+- reg: I2C slave address
-- 
1.9.1



[PATCH v2 1/2] dt-bindings: Add bindings for AKM ak7375 voice coil lens

2018-05-25 Thread bingbu . cao
From: Bingbu Cao <bingbu@intel.com>

Add device tree bindings for AKM ak7375 voice coil lens
driver. This chip is used to drive a lens in a camera module.

Signed-off-by: Tianshu Qiu <tian.shu@intel.com>
Signed-off-by: Bingbu Cao <bingbu@intel.com>
---
Changes since v1:
 - remove the vendor prefix change
 
Documentation/devicetree/bindings/media/i2c/ak7375.txt | 8 
 1 file changed, 8 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/media/i2c/ak7375.txt

diff --git a/Documentation/devicetree/bindings/media/i2c/ak7375.txt 
b/Documentation/devicetree/bindings/media/i2c/ak7375.txt
new file mode 100644
index ..aa3e24b41241
--- /dev/null
+++ b/Documentation/devicetree/bindings/media/i2c/ak7375.txt
@@ -0,0 +1,8 @@
+Asahi Kasei Microdevices AK7375 voice coil lens driver
+
+AK7375 is a camera voice coil lens.
+
+Mandatory properties:
+
+- compatible: "asahi-kasei,ak7375"
+- reg: I2C slave address
-- 
1.9.1



[PATCH v2 2/2] media: ak7375: Add ak7375 lens voice coil driver

2018-05-25 Thread bingbu . cao
From: Bingbu Cao <bingbu@intel.com>

Add a V4L2 sub-device driver for the ak7375 lens voice coil.
This is a voice coil module using the I2C bus to control the
focus position.

Signed-off-by: Tianshu Qiu <tian.shu@intel.com>
Signed-off-by: Bingbu Cao <bingbu@intel.com>
---
 MAINTAINERS|   8 ++
 drivers/media/i2c/Kconfig  |  10 ++
 drivers/media/i2c/Makefile |   1 +
 drivers/media/i2c/ak7375.c | 278 +
 4 files changed, 297 insertions(+)
 create mode 100644 drivers/media/i2c/ak7375.c

diff --git a/MAINTAINERS b/MAINTAINERS
index ea362219c4aa..20379a7baca0 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -625,6 +625,14 @@ T: git git://linuxtv.org/anttip/media_tree.git
 S: Maintained
 F: drivers/media/usb/airspy/
 
+AKM AK7375 LENS VOICE COIL DRIVER
+M: Tianshu Qiu <tian.shu@intel.com>
+L: linux-media@vger.kernel.org
+T: git git://linuxtv.org/media_tree.git
+S: Maintained
+F: drivers/media/i2c/ak7375.c
+F: Documentation/devicetree/bindings/media/i2c/akm,ak7375.txt
+
 ALACRITECH GIGABIT ETHERNET DRIVER
 M: Lino Sanfilippo <linosanfili...@gmx.de>
 S: Maintained
diff --git a/drivers/media/i2c/Kconfig b/drivers/media/i2c/Kconfig
index 341452fe98df..ff3cb5afb0e1 100644
--- a/drivers/media/i2c/Kconfig
+++ b/drivers/media/i2c/Kconfig
@@ -326,6 +326,16 @@ config VIDEO_AD5820
  This is a driver for the AD5820 camera lens voice coil.
  It is used for example in Nokia N900 (RX-51).
 
+config VIDEO_AK7375
+   tristate "AK7375 lens voice coil support"
+   depends on I2C && VIDEO_V4L2 && MEDIA_CONTROLLER
+   depends on VIDEO_V4L2_SUBDEV_API
+   help
+ This is a driver for the AK7375 camera lens voice coil.
+ AK7375 is a 12 bit DAC with 120mA output current sink
+ capability. This is designed for linear control of
+ voice coil motors, controlled via I2C serial interface.
+
 config VIDEO_DW9714
tristate "DW9714 lens voice coil support"
depends on I2C && VIDEO_V4L2 && MEDIA_CONTROLLER
diff --git a/drivers/media/i2c/Makefile b/drivers/media/i2c/Makefile
index d679d57cd3b3..05b97e319ea9 100644
--- a/drivers/media/i2c/Makefile
+++ b/drivers/media/i2c/Makefile
@@ -23,6 +23,7 @@ obj-$(CONFIG_VIDEO_SAA7127) += saa7127.o
 obj-$(CONFIG_VIDEO_SAA7185) += saa7185.o
 obj-$(CONFIG_VIDEO_SAA6752HS) += saa6752hs.o
 obj-$(CONFIG_VIDEO_AD5820)  += ad5820.o
+obj-$(CONFIG_VIDEO_AK7375)  += ak7375.o
 obj-$(CONFIG_VIDEO_DW9714)  += dw9714.o
 obj-$(CONFIG_VIDEO_ADV7170) += adv7170.o
 obj-$(CONFIG_VIDEO_ADV7175) += adv7175.o
diff --git a/drivers/media/i2c/ak7375.c b/drivers/media/i2c/ak7375.c
new file mode 100644
index ..012e673e9ced
--- /dev/null
+++ b/drivers/media/i2c/ak7375.c
@@ -0,0 +1,278 @@
+// SPDX-License-Identifier: GPL-2.0
+// Copyright (C) 2018 Intel Corporation
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define AK7375_MAX_FOCUS_POS   4095
+/*
+ * This sets the minimum granularity for the focus positions.
+ * A value of 1 gives maximum accuracy for a desired focus position
+ */
+#define AK7375_FOCUS_STEPS 1
+/*
+ * This acts as the minimum granularity of lens movement.
+ * Keep this value power of 2, so the control steps can be
+ * uniformly adjusted for gradual lens movement, with desired
+ * number of control steps.
+ */
+#define AK7375_CTRL_STEPS  64
+#define AK7375_CTRL_DELAY_US   1000
+
+#define AK7375_REG_POSITION0x0
+#define AK7375_REG_CONT0x2
+#define AK7375_MODE_ACTIVE 0x0
+#define AK7375_MODE_STANDBY0x40
+
+/* ak7375 device structure */
+struct ak7375_device {
+   struct v4l2_ctrl_handler ctrls_vcm;
+   struct v4l2_subdev sd;
+   struct v4l2_ctrl *focus;
+};
+
+static inline struct ak7375_device *to_ak7375_vcm(struct v4l2_ctrl *ctrl)
+{
+   return container_of(ctrl->handler, struct ak7375_device, ctrls_vcm);
+}
+
+static inline struct ak7375_device *sd_to_ak7375_vcm(struct v4l2_subdev 
*subdev)
+{
+   return container_of(subdev, struct ak7375_device, sd);
+}
+
+static int ak7375_i2c_write(struct ak7375_device *ak7375,
+   u8 addr, u16 data, int size)
+{
+   struct i2c_client *client = v4l2_get_subdevdata(>sd);
+   int ret;
+   u8 buf[3];
+
+   if (size != 1 && size != 2)
+   return -EINVAL;
+   buf[0] = addr;
+   buf[2] = data & 0xff;
+   if (size == 2)
+   buf[1] = data >> 8;
+   ret = i2c_master_send(client, (const char *)buf, size + 1);
+   if (ret < 0)
+   return ret;
+   if (ret != size + 1)
+   return -EIO;
+   return 0;
+}
+
+static int ak7375_set_ctrl(struct v4l2_ctrl *ctrl)
+{
+   struct ak7375_device *dev_vcm = to_ak7375_vcm(ctrl);
+
+   if (ctrl->id == V4L2_CID_FOCUS_ABSOLUTE)
+  

[PATCH v3] media: imx319: Add imx319 camera sensor driver

2018-05-21 Thread bingbu . cao
From: Bingbu Cao <bingbu@intel.com>

Add a V4L2 sub-device driver for the Sony IMX319 image sensor.
This is a camera sensor using the I2C bus for control and the
CSI-2 bus for data.

Signed-off-by: Bingbu Cao <bingbu@intel.com>
Signed-off-by: Tianshu Qiu <tian.shu@intel.com>
---
 MAINTAINERS|7 +
 drivers/media/i2c/Kconfig  |   11 +
 drivers/media/i2c/Makefile |1 +
 drivers/media/i2c/imx319.c | 2434 
 4 files changed, 2453 insertions(+)
 create mode 100644 drivers/media/i2c/imx319.c

diff --git a/MAINTAINERS b/MAINTAINERS
index e73a55a6a855..87b6c338d827 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -13084,6 +13084,13 @@ S: Maintained
 F: drivers/media/i2c/imx274.c
 F: Documentation/devicetree/bindings/media/i2c/imx274.txt
 
+SONY IMX319 SENSOR DRIVER
+M: Bingbu Cao <bingbu@intel.com>
+L: linux-media@vger.kernel.org
+T: git git://linuxtv.org/media_tree.git
+S: Maintained
+F: drivers/media/i2c/imx319.c
+
 SONY MEMORYSTICK CARD SUPPORT
 M: Alex Dubov <oa...@yahoo.com>
 W: http://tifmxx.berlios.de/
diff --git a/drivers/media/i2c/Kconfig b/drivers/media/i2c/Kconfig
index 1f9d7c6aa31a..c3d279cc293e 100644
--- a/drivers/media/i2c/Kconfig
+++ b/drivers/media/i2c/Kconfig
@@ -604,6 +604,17 @@ config VIDEO_IMX274
  This is a V4L2 sensor-level driver for the Sony IMX274
  CMOS image sensor.
 
+config VIDEO_IMX319
+   tristate "Sony IMX319 sensor support"
+   depends on I2C && VIDEO_V4L2 && VIDEO_V4L2_SUBDEV_API
+   depends on MEDIA_CAMERA_SUPPORT
+   help
+ This is a Video4Linux2 sensor driver for the Sony
+ IMX319 camera.
+
+ To compile this driver as a module, choose M here: the
+ module will be called imx319.
+
 config VIDEO_OV2640
tristate "OmniVision OV2640 sensor support"
depends on VIDEO_V4L2 && I2C
diff --git a/drivers/media/i2c/Makefile b/drivers/media/i2c/Makefile
index 16fc34eda5cc..3adb3be4a486 100644
--- a/drivers/media/i2c/Makefile
+++ b/drivers/media/i2c/Makefile
@@ -104,5 +104,6 @@ obj-$(CONFIG_VIDEO_OV2659)  += ov2659.o
 obj-$(CONFIG_VIDEO_TC358743)   += tc358743.o
 obj-$(CONFIG_VIDEO_IMX258) += imx258.o
 obj-$(CONFIG_VIDEO_IMX274) += imx274.o
+obj-$(CONFIG_VIDEO_IMX319) += imx319.o
 
 obj-$(CONFIG_SDR_MAX2175) += max2175.o
diff --git a/drivers/media/i2c/imx319.c b/drivers/media/i2c/imx319.c
new file mode 100644
index ..706bbafc75ec
--- /dev/null
+++ b/drivers/media/i2c/imx319.c
@@ -0,0 +1,2434 @@
+// SPDX-License-Identifier: GPL-2.0
+// Copyright (C) 2018 Intel Corporation
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define IMX319_REG_MODE_SELECT 0x0100
+#define IMX319_MODE_STANDBY0x00
+#define IMX319_MODE_STREAMING  0x01
+
+/* Chip ID */
+#define IMX319_REG_CHIP_ID 0x0016
+#define IMX319_CHIP_ID 0x0319
+
+/* V_TIMING internal */
+#define IMX319_REG_FLL 0x0340
+#define IMX319_FLL_MAX 0x
+
+/* Exposure control */
+#define IMX319_REG_EXPOSURE0x0202
+#define IMX319_EXPOSURE_MIN1
+#define IMX319_EXPOSURE_STEP   1
+#define IMX319_EXPOSURE_DEFAULT0x04ee
+
+/* Analog gain control */
+#define IMX319_REG_ANALOG_GAIN 0x0204
+#define IMX319_ANA_GAIN_MIN0
+#define IMX319_ANA_GAIN_MAX960
+#define IMX319_ANA_GAIN_STEP   1
+#define IMX319_ANA_GAIN_DEFAULT0
+
+/* Digital gain control */
+#define IMX319_REG_DPGA_USE_GLOBAL_GAIN0x3ff9
+#define IMX319_REG_DIG_GAIN_GLOBAL 0x020e
+#define IMX319_DGTL_GAIN_MIN   256
+#define IMX319_DGTL_GAIN_MAX   4095
+#define IMX319_DGTL_GAIN_STEP  1
+#define IMX319_DGTL_GAIN_DEFAULT   256
+
+/* Test Pattern Control */
+#define IMX319_REG_TEST_PATTERN0x0600
+#define IMX319_TEST_PATTERN_DISABLED   0
+#define IMX319_TEST_PATTERN_SOLID_COLOR1
+#define IMX319_TEST_PATTERN_COLOR_BARS 2
+#define IMX319_TEST_PATTERN_GRAY_COLOR_BARS3
+#define IMX319_TEST_PATTERN_PN94
+
+/* Flip Control */
+#define IMX319_REG_ORIENTATION 0x0101
+
+struct imx319_reg {
+   u16 address;
+   u8 val;
+};
+
+struct imx319_reg_list {
+   u32 num_of_regs;
+   const struct imx319_reg *regs;
+};
+
+/* Mode : resolution and related config */
+struct imx319_mode {
+   /* Frame width */
+   u32 width;
+   /* Frame height */
+   u32 height;
+
+   /* V-timing */
+   u32 fll_def;
+   u32 fll_min;
+
+   /* H-timing */
+   u32 llp;
+
+   /* Default register values */
+   struct imx319_reg_list reg_list;
+};
+
+struct imx319 {
+   struct v4l2_subdev sd;
+   struct media_pad pad;
+
+   struct v4l2_ctrl_

[PATCH v2] media: imx319: Add imx319 camera sensor driver

2018-05-21 Thread bingbu . cao
From: Bingbu Cao <bingbu@intel.com>

Add a V4L2 sub-device driver for the Sony IMX319 image sensor.
This is a camera sensor using the I2C bus for control and the
CSI-2 bus for data.

Signed-off-by: Bingbu Cao <bingbu@intel.com>
Signed-off-by: Tianshu Qiu <tian.shu@intel.com>
---
 MAINTAINERS|7 +
 drivers/media/i2c/Kconfig  |   11 +
 drivers/media/i2c/Makefile |1 +
 drivers/media/i2c/imx319.c | 2434 
 4 files changed, 2453 insertions(+)
 create mode 100644 drivers/media/i2c/imx319.c

diff --git a/MAINTAINERS b/MAINTAINERS
index e73a55a6a855..87b6c338d827 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -13084,6 +13084,13 @@ S: Maintained
 F: drivers/media/i2c/imx274.c
 F: Documentation/devicetree/bindings/media/i2c/imx274.txt
 
+SONY IMX319 SENSOR DRIVER
+M: Bingbu Cao <bingbu@intel.com>
+L: linux-media@vger.kernel.org
+T: git git://linuxtv.org/media_tree.git
+S: Maintained
+F: drivers/media/i2c/imx319.c
+
 SONY MEMORYSTICK CARD SUPPORT
 M: Alex Dubov <oa...@yahoo.com>
 W: http://tifmxx.berlios.de/
diff --git a/drivers/media/i2c/Kconfig b/drivers/media/i2c/Kconfig
index 1f9d7c6aa31a..c3d279cc293e 100644
--- a/drivers/media/i2c/Kconfig
+++ b/drivers/media/i2c/Kconfig
@@ -604,6 +604,17 @@ config VIDEO_IMX274
  This is a V4L2 sensor-level driver for the Sony IMX274
  CMOS image sensor.
 
+config VIDEO_IMX319
+   tristate "Sony IMX319 sensor support"
+   depends on I2C && VIDEO_V4L2 && VIDEO_V4L2_SUBDEV_API
+   depends on MEDIA_CAMERA_SUPPORT
+   help
+ This is a Video4Linux2 sensor driver for the Sony
+ IMX319 camera.
+
+ To compile this driver as a module, choose M here: the
+ module will be called imx319.
+
 config VIDEO_OV2640
tristate "OmniVision OV2640 sensor support"
depends on VIDEO_V4L2 && I2C
diff --git a/drivers/media/i2c/Makefile b/drivers/media/i2c/Makefile
index 16fc34eda5cc..3adb3be4a486 100644
--- a/drivers/media/i2c/Makefile
+++ b/drivers/media/i2c/Makefile
@@ -104,5 +104,6 @@ obj-$(CONFIG_VIDEO_OV2659)  += ov2659.o
 obj-$(CONFIG_VIDEO_TC358743)   += tc358743.o
 obj-$(CONFIG_VIDEO_IMX258) += imx258.o
 obj-$(CONFIG_VIDEO_IMX274) += imx274.o
+obj-$(CONFIG_VIDEO_IMX319) += imx319.o
 
 obj-$(CONFIG_SDR_MAX2175) += max2175.o
diff --git a/drivers/media/i2c/imx319.c b/drivers/media/i2c/imx319.c
new file mode 100644
index ..dc83936029fc
--- /dev/null
+++ b/drivers/media/i2c/imx319.c
@@ -0,0 +1,2434 @@
+// SPDX-License-Identifier: GPL-2.0
+// Copyright (C) 2018 Intel Corporation
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define IMX319_REG_MODE_SELECT 0x0100
+#define IMX319_MODE_STANDBY0x00
+#define IMX319_MODE_STREAMING  0x01
+
+/* Chip ID */
+#define IMX319_REG_CHIP_ID 0x0016
+#define IMX319_CHIP_ID 0x0319
+
+/* V_TIMING internal */
+#define IMX319_REG_FLL 0x0340
+#define IMX319_FLL_MAX 0x
+
+/* Exposure control */
+#define IMX319_REG_EXPOSURE0x0202
+#define IMX319_EXPOSURE_MIN1
+#define IMX319_EXPOSURE_STEP   1
+#define IMX319_EXPOSURE_DEFAULT0x04ee
+
+/* Analog gain control */
+#define IMX319_REG_ANALOG_GAIN 0x0204
+#define IMX319_ANA_GAIN_MIN0
+#define IMX319_ANA_GAIN_MAX960
+#define IMX319_ANA_GAIN_STEP   1
+#define IMX319_ANA_GAIN_DEFAULT0
+
+/* Digital gain control */
+#define IMX319_REG_DPGA_USE_GLOBAL_GAIN0x3ff9
+#define IMX319_REG_DIG_GAIN_GLOBAL 0x020e
+#define IMX319_DGTL_GAIN_MIN   256
+#define IMX319_DGTL_GAIN_MAX   4095
+#define IMX319_DGTL_GAIN_STEP  1
+#define IMX319_DGTL_GAIN_DEFAULT   256
+
+/* Test Pattern Control */
+#define IMX319_REG_TEST_PATTERN0x0600
+#define IMX319_TEST_PATTERN_DISABLED   0
+#define IMX319_TEST_PATTERN_SOLID_COLOR1
+#define IMX319_TEST_PATTERN_COLOR_BARS 2
+#define IMX319_TEST_PATTERN_GRAY_COLOR_BARS3
+#define IMX319_TEST_PATTERN_PN94
+
+/* Flip Control */
+#define IMX319_REG_ORIENTATION 0x0101
+
+struct imx319_reg {
+   u16 address;
+   u8 val;
+};
+
+struct imx319_reg_list {
+   u32 num_of_regs;
+   const struct imx319_reg *regs;
+};
+
+/* Mode : resolution and related config */
+struct imx319_mode {
+   /* Frame width */
+   u32 width;
+   /* Frame height */
+   u32 height;
+
+   /* V-timing */
+   u32 fll_def;
+   u32 fll_min;
+
+   /* H-timing */
+   u32 llp;
+
+   /* Default register values */
+   struct imx319_reg_list reg_list;
+};
+
+struct imx319 {
+   struct v4l2_subdev sd;
+   struct media_pad pad;
+
+   struct v4l2_ctrl_

[PATCH v2 1/3] media: dw9807: Add dw9807 vcm driver

2018-05-21 Thread bingbu . cao
From: Alan Chiang 

DW9807 is a 10 bit DAC from Dongwoon, designed for linear
control of voice coil motor.

This driver creates a V4L2 subdevice and
provides control to set the desired focus.

Signed-off-by: Andy Yeh 
Reviewed-by: Jacopo Mondi 
Reviewed-by: Tomasz Figa 
Signed-off-by: Sakari Ailus 
---
 MAINTAINERS|   7 +
 drivers/media/i2c/Kconfig  |  10 ++
 drivers/media/i2c/Makefile |   1 +
 drivers/media/i2c/dw9807.c | 329 +
 4 files changed, 347 insertions(+)
 create mode 100644 drivers/media/i2c/dw9807.c

diff --git a/MAINTAINERS b/MAINTAINERS
index 49003f77cedd..4d6f837b2337 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -4375,6 +4375,13 @@ T:   git git://linuxtv.org/media_tree.git
 S: Maintained
 F: drivers/media/i2c/dw9714.c
 
+DONGWOON DW9807 LENS VOICE COIL DRIVER
+M: Sakari Ailus 
+L: linux-media@vger.kernel.org
+T: git git://linuxtv.org/media_tree.git
+S: Maintained
+F: drivers/media/i2c/dw9807.c
+
 DOUBLETALK DRIVER
 M: "James R. Van Zandt" 
 L: blinux-l...@redhat.com
diff --git a/drivers/media/i2c/Kconfig b/drivers/media/i2c/Kconfig
index b95b44702ccb..e6a721c5e3b0 100644
--- a/drivers/media/i2c/Kconfig
+++ b/drivers/media/i2c/Kconfig
@@ -336,6 +336,16 @@ config VIDEO_DW9714
  capability. This is designed for linear control of
  voice coil motors, controlled via I2C serial interface.
 
+config VIDEO_DW9807
+   tristate "DW9807 lens voice coil support"
+   depends on I2C && VIDEO_V4L2 && MEDIA_CONTROLLER
+   depends on VIDEO_V4L2_SUBDEV_API
+   ---help---
+ This is a driver for the DW9807 camera lens voice coil.
+ DW9807 is a 10 bit DAC with 100mA output current sink
+ capability. This is designed for linear control of
+ voice coil motors, controlled via I2C serial interface.
+
 config VIDEO_SAA7110
tristate "Philips SAA7110 video decoder"
depends on VIDEO_V4L2 && I2C
diff --git a/drivers/media/i2c/Makefile b/drivers/media/i2c/Makefile
index ff6e2914abda..5cf15edacb2b 100644
--- a/drivers/media/i2c/Makefile
+++ b/drivers/media/i2c/Makefile
@@ -24,6 +24,7 @@ obj-$(CONFIG_VIDEO_SAA7185) += saa7185.o
 obj-$(CONFIG_VIDEO_SAA6752HS) += saa6752hs.o
 obj-$(CONFIG_VIDEO_AD5820)  += ad5820.o
 obj-$(CONFIG_VIDEO_DW9714)  += dw9714.o
+obj-$(CONFIG_VIDEO_DW9807)  += dw9807.o
 obj-$(CONFIG_VIDEO_ADV7170) += adv7170.o
 obj-$(CONFIG_VIDEO_ADV7175) += adv7175.o
 obj-$(CONFIG_VIDEO_ADV7180) += adv7180.o
diff --git a/drivers/media/i2c/dw9807.c b/drivers/media/i2c/dw9807.c
new file mode 100644
index ..6ebb98717fb1
--- /dev/null
+++ b/drivers/media/i2c/dw9807.c
@@ -0,0 +1,329 @@
+// SPDX-License-Identifier: GPL-2.0
+// Copyright (C) 2018 Intel Corporation
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define DW9807_MAX_FOCUS_POS   1023
+/*
+ * This sets the minimum granularity for the focus positions.
+ * A value of 1 gives maximum accuracy for a desired focus position.
+ */
+#define DW9807_FOCUS_STEPS 1
+/*
+ * This acts as the minimum granularity of lens movement.
+ * Keep this value power of 2, so the control steps can be
+ * uniformly adjusted for gradual lens movement, with desired
+ * number of control steps.
+ */
+#define DW9807_CTRL_STEPS  16
+#define DW9807_CTRL_DELAY_US   1000
+
+#define DW9807_CTL_ADDR0x02
+/*
+ * DW9807 separates two registers to control the VCM position.
+ * One for MSB value, another is LSB value.
+ */
+#define DW9807_MSB_ADDR0x03
+#define DW9807_LSB_ADDR0x04
+#define DW9807_STATUS_ADDR 0x05
+#define DW9807_MODE_ADDR   0x06
+#define DW9807_RESONANCE_ADDR  0x07
+
+#define MAX_RETRY  10
+
+struct dw9807_device {
+   struct v4l2_ctrl_handler ctrls_vcm;
+   struct v4l2_subdev sd;
+   u16 current_val;
+};
+
+static inline struct dw9807_device *sd_to_dw9807_vcm(
+   struct v4l2_subdev *subdev)
+{
+   return container_of(subdev, struct dw9807_device, sd);
+}
+
+static int dw9807_i2c_check(struct i2c_client *client)
+{
+   const char status_addr = DW9807_STATUS_ADDR;
+   char status_result;
+   int ret;
+
+   ret = i2c_master_send(client, _addr, sizeof(status_addr));
+   if (ret < 0) {
+   dev_err(>dev, "I2C write STATUS address fail ret = 
%d\n",
+   ret);
+   return ret;
+   }
+
+   ret = i2c_master_recv(client, _result, sizeof(status_result));
+   if (ret < 0) {
+   dev_err(>dev, "I2C read STATUS value fail ret = %d\n",
+   ret);
+   return ret;
+   }
+
+   return status_result;
+}
+
+static int dw9807_set_dac(struct i2c_client *client, 

[PATCH v2 2/3] media: imx258: Add imx258 camera sensor driver

2018-05-21 Thread bingbu . cao
From: Jason Chen 

Add a V4L2 sub-device driver for the Sony IMX258 image sensor.
This is a camera sensor using the I2C bus for control and the
CSI-2 bus for data.

Signed-off-by: Andy Yeh 
Signed-off-by: Alan Chiang 
Reviewed-by: Tomasz Figa 
Signed-off-by: Sakari Ailus 
---
 MAINTAINERS|7 +
 drivers/media/i2c/Kconfig  |   11 +
 drivers/media/i2c/Makefile |1 +
 drivers/media/i2c/imx258.c | 1320 
 4 files changed, 1339 insertions(+)
 create mode 100644 drivers/media/i2c/imx258.c

diff --git a/MAINTAINERS b/MAINTAINERS
index 4d6f837b2337..e73a55a6a855 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -13069,6 +13069,13 @@ S: Maintained
 F: drivers/ssb/
 F: include/linux/ssb/
 
+SONY IMX258 SENSOR DRIVER
+M: Sakari Ailus 
+L: linux-media@vger.kernel.org
+T: git git://linuxtv.org/media_tree.git
+S: Maintained
+F: drivers/media/i2c/imx258.c
+
 SONY IMX274 SENSOR DRIVER
 M: Leon Luo 
 L: linux-media@vger.kernel.org
diff --git a/drivers/media/i2c/Kconfig b/drivers/media/i2c/Kconfig
index e6a721c5e3b0..1f9d7c6aa31a 100644
--- a/drivers/media/i2c/Kconfig
+++ b/drivers/media/i2c/Kconfig
@@ -585,6 +585,17 @@ config VIDEO_APTINA_PLL
 config VIDEO_SMIAPP_PLL
tristate
 
+config VIDEO_IMX258
+   tristate "Sony IMX258 sensor support"
+   depends on I2C && VIDEO_V4L2 && VIDEO_V4L2_SUBDEV_API
+   depends on MEDIA_CAMERA_SUPPORT
+   ---help---
+ This is a Video4Linux2 sensor-level driver for the Sony
+ IMX258 camera.
+
+ To compile this driver as a module, choose M here: the
+ module will be called imx258.
+
 config VIDEO_IMX274
tristate "Sony IMX274 sensor support"
depends on I2C && VIDEO_V4L2 && VIDEO_V4L2_SUBDEV_API
diff --git a/drivers/media/i2c/Makefile b/drivers/media/i2c/Makefile
index 5cf15edacb2b..16fc34eda5cc 100644
--- a/drivers/media/i2c/Makefile
+++ b/drivers/media/i2c/Makefile
@@ -102,6 +102,7 @@ obj-$(CONFIG_VIDEO_I2C) += video-i2c.o
 obj-$(CONFIG_VIDEO_ML86V7667)  += ml86v7667.o
 obj-$(CONFIG_VIDEO_OV2659) += ov2659.o
 obj-$(CONFIG_VIDEO_TC358743)   += tc358743.o
+obj-$(CONFIG_VIDEO_IMX258) += imx258.o
 obj-$(CONFIG_VIDEO_IMX274) += imx274.o
 
 obj-$(CONFIG_SDR_MAX2175) += max2175.o
diff --git a/drivers/media/i2c/imx258.c b/drivers/media/i2c/imx258.c
new file mode 100644
index ..fad3012f4fe5
--- /dev/null
+++ b/drivers/media/i2c/imx258.c
@@ -0,0 +1,1320 @@
+// SPDX-License-Identifier: GPL-2.0
+// Copyright (C) 2018 Intel Corporation
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define IMX258_REG_VALUE_08BIT 1
+#define IMX258_REG_VALUE_16BIT 2
+
+#define IMX258_REG_MODE_SELECT 0x0100
+#define IMX258_MODE_STANDBY0x00
+#define IMX258_MODE_STREAMING  0x01
+
+/* Chip ID */
+#define IMX258_REG_CHIP_ID 0x0016
+#define IMX258_CHIP_ID 0x0258
+
+/* V_TIMING internal */
+#define IMX258_VTS_30FPS   0x0c98
+#define IMX258_VTS_30FPS_2K0x0638
+#define IMX258_VTS_30FPS_VGA   0x034c
+#define IMX258_VTS_MAX 0x
+
+/*Frame Length Line*/
+#define IMX258_FLL_MIN 0x08a6
+#define IMX258_FLL_MAX 0x
+#define IMX258_FLL_STEP1
+#define IMX258_FLL_DEFAULT 0x0c98
+
+/* HBLANK control - read only */
+#define IMX258_PPL_DEFAULT 5352
+
+/* Exposure control */
+#define IMX258_REG_EXPOSURE0x0202
+#define IMX258_EXPOSURE_MIN4
+#define IMX258_EXPOSURE_STEP   1
+#define IMX258_EXPOSURE_DEFAULT0x640
+#define IMX258_EXPOSURE_MAX65535
+
+/* Analog gain control */
+#define IMX258_REG_ANALOG_GAIN 0x0204
+#define IMX258_ANA_GAIN_MIN0
+#define IMX258_ANA_GAIN_MAX0x1fff
+#define IMX258_ANA_GAIN_STEP   1
+#define IMX258_ANA_GAIN_DEFAULT0x0
+
+/* Digital gain control */
+#define IMX258_REG_GR_DIGITAL_GAIN 0x020e
+#define IMX258_REG_R_DIGITAL_GAIN  0x0210
+#define IMX258_REG_B_DIGITAL_GAIN  0x0212
+#define IMX258_REG_GB_DIGITAL_GAIN 0x0214
+#define IMX258_DGTL_GAIN_MIN   0
+#define IMX258_DGTL_GAIN_MAX   4096/* Max = 0xFFF */
+#define IMX258_DGTL_GAIN_DEFAULT   1024
+#define IMX258_DGTL_GAIN_STEP  1
+
+/* Test Pattern Control */
+#define IMX258_REG_TEST_PATTERN0x0600
+#define IMX258_TEST_PATTERN_DISABLE0
+#define IMX258_TEST_PATTERN_SOLID_COLOR1
+#define IMX258_TEST_PATTERN_COLOR_BARS 2
+#define IMX258_TEST_PATTERN_GREY_COLOR 3
+#define IMX258_TEST_PATTERN_PN94
+
+/* Orientation */
+#define REG_MIRROR_FLIP_CONTROL

[PATCH 1/3] dt-bindings: Add vendor prefix for AKM

2018-05-16 Thread bingbu . cao
From: Bingbu Cao <bingbu@intel.com>

Asahi Kasei Microdevices (AKM) offer a variety of
advanced sensing devices based on compound semiconductor
technology and sophisticated IC products featuring
analog/digital mixed-signal technology.

Signed-off-by: Bingbu Cao <bingbu@intel.com>
Signed-off-by: Tianshu Qiu <tian.shu@intel.com>
---
 Documentation/devicetree/bindings/vendor-prefixes.txt | 1 +
 1 file changed, 1 insertion(+)

diff --git a/Documentation/devicetree/bindings/vendor-prefixes.txt 
b/Documentation/devicetree/bindings/vendor-prefixes.txt
index b5f978a4cac6..0e6159665e66 100644
--- a/Documentation/devicetree/bindings/vendor-prefixes.txt
+++ b/Documentation/devicetree/bindings/vendor-prefixes.txt
@@ -14,6 +14,7 @@ adh   AD Holdings Plc.
 adiAnalog Devices, Inc.
 advantech  Advantech Corporation
 aeroflexgaislerAeroflex Gaisler AB
+akmAsahi Kasei Microdevices
 al Annapurna Labs
 allo   Allo.com
 allwinner  Allwinner Technology Co., Ltd.
-- 
1.9.1



[PATCH 2/3] dt-bindings: Add bindings for AKM ak7375 voice coil lens

2018-05-16 Thread bingbu . cao
From: Bingbu Cao <bingbu@intel.com>

Add device tree bindings for AKM ak7375 voice coil lens
driver. This chip is used to drive a lens in a camera module.

Signed-off-by: Tianshu Qiu <tian.shu@intel.com>
Signed-off-by: Bingbu Cao <bingbu@intel.com>
---
 Documentation/devicetree/bindings/media/i2c/akm,ak7375.txt | 8 
 1 file changed, 8 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/media/i2c/akm,ak7375.txt

diff --git a/Documentation/devicetree/bindings/media/i2c/akm,ak7375.txt 
b/Documentation/devicetree/bindings/media/i2c/akm,ak7375.txt
new file mode 100644
index ..ec7f3c82dc57
--- /dev/null
+++ b/Documentation/devicetree/bindings/media/i2c/akm,ak7375.txt
@@ -0,0 +1,8 @@
+Asahi Kasei Microdevices AK7375 voice coil lens driver
+
+AK7375 is a 12-bit DAC intended for controlling voice coil lenses.
+
+Mandatory properties:
+
+- compatible: "akm,ak7375"
+- reg: I2C slave address
-- 
1.9.1



[PATCH 3/3] media: ak7375: Add ak7375 lens voice coil driver

2018-05-16 Thread bingbu . cao
From: Bingbu Cao <bingbu@intel.com>

Add a V4L2 sub-device driver for the ak7375 lens voice coil.
This is a voice coil module using the I2C bus to control the
focus position.

Signed-off-by: Tianshu Qiu <tian.shu@intel.com>
Signed-off-by: Bingbu Cao <bingbu@intel.com>
---
 MAINTAINERS|   8 ++
 drivers/media/i2c/Kconfig  |  10 ++
 drivers/media/i2c/Makefile |   1 +
 drivers/media/i2c/ak7375.c | 274 +
 4 files changed, 293 insertions(+)
 create mode 100644 drivers/media/i2c/ak7375.c

diff --git a/MAINTAINERS b/MAINTAINERS
index e73a55a6a855..7a8fea7b90fe 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -625,6 +625,14 @@ T: git git://linuxtv.org/anttip/media_tree.git
 S: Maintained
 F: drivers/media/usb/airspy/
 
+AKM AK7375 LENS VOICE COIL DRIVER
+M: Tianshu Qiu <tian.shu@intel.com>
+L: linux-media@vger.kernel.org
+T: git git://linuxtv.org/media_tree.git
+S: Maintained
+F: drivers/media/i2c/ak7375.c
+F: Documentation/devicetree/bindings/media/i2c/akm,ak7375.txt
+
 ALACRITECH GIGABIT ETHERNET DRIVER
 M: Lino Sanfilippo <linosanfili...@gmx.de>
 S: Maintained
diff --git a/drivers/media/i2c/Kconfig b/drivers/media/i2c/Kconfig
index 1f9d7c6aa31a..92b7e9b1588c 100644
--- a/drivers/media/i2c/Kconfig
+++ b/drivers/media/i2c/Kconfig
@@ -326,6 +326,16 @@ config VIDEO_AD5820
  This is a driver for the AD5820 camera lens voice coil.
  It is used for example in Nokia N900 (RX-51).
 
+config VIDEO_AK7375
+   tristate "AK7375 lens voice coil support"
+   depends on I2C && VIDEO_V4L2 && MEDIA_CONTROLLER
+   depends on VIDEO_V4L2_SUBDEV_API
+   help
+ This is a driver for the AK7375 camera lens voice coil.
+ AK7375 is a 12 bit DAC with 120mA output current sink
+ capability. This is designed for linear control of
+ voice coil motors, controlled via I2C serial interface.
+
 config VIDEO_DW9714
tristate "DW9714 lens voice coil support"
depends on I2C && VIDEO_V4L2 && MEDIA_CONTROLLER
diff --git a/drivers/media/i2c/Makefile b/drivers/media/i2c/Makefile
index 16fc34eda5cc..4261f66a29e6 100644
--- a/drivers/media/i2c/Makefile
+++ b/drivers/media/i2c/Makefile
@@ -23,6 +23,7 @@ obj-$(CONFIG_VIDEO_SAA7127) += saa7127.o
 obj-$(CONFIG_VIDEO_SAA7185) += saa7185.o
 obj-$(CONFIG_VIDEO_SAA6752HS) += saa6752hs.o
 obj-$(CONFIG_VIDEO_AD5820)  += ad5820.o
+obj-$(CONFIG_VIDEO_AK7375)  += ak7375.o
 obj-$(CONFIG_VIDEO_DW9714)  += dw9714.o
 obj-$(CONFIG_VIDEO_DW9807)  += dw9807.o
 obj-$(CONFIG_VIDEO_ADV7170) += adv7170.o
diff --git a/drivers/media/i2c/ak7375.c b/drivers/media/i2c/ak7375.c
new file mode 100644
index ..7379fe35f4f4
--- /dev/null
+++ b/drivers/media/i2c/ak7375.c
@@ -0,0 +1,274 @@
+// SPDX-License-Identifier: GPL-2.0
+// Copyright (C) 2018 Intel Corporation
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define AK7375_MAX_FOCUS_POS   4095
+/*
+ * This sets the minimum granularity for the focus positions.
+ * A value of 1 gives maximum accuracy for a desired focus position
+ */
+#define AK7375_FOCUS_STEPS 1
+/*
+ * This acts as the minimum granularity of lens movement.
+ * Keep this value power of 2, so the control steps can be
+ * uniformly adjusted for gradual lens movement, with desired
+ * number of control steps.
+ */
+#define AK7375_CTRL_STEPS  64
+#define AK7375_CTRL_DELAY_US   1000
+
+#define AK7375_REG_POSITION0x0
+#define AK7375_REG_CONT0x2
+#define AK7375_MODE_ACTIVE 0x0
+#define AK7375_MODE_STANDBY0x40
+
+/* ak7375 device structure */
+struct ak7375_device {
+   struct v4l2_ctrl_handler ctrls_vcm;
+   struct v4l2_subdev sd;
+   struct v4l2_ctrl *focus;
+};
+
+static inline struct ak7375_device *to_ak7375_vcm(struct v4l2_ctrl *ctrl)
+{
+   return container_of(ctrl->handler, struct ak7375_device, ctrls_vcm);
+}
+
+static inline struct ak7375_device *sd_to_ak7375_vcm(struct v4l2_subdev 
*subdev)
+{
+   return container_of(subdev, struct ak7375_device, sd);
+}
+
+static int ak7375_i2c_write(struct ak7375_device *ak7375,
+   u8 addr, u16 data, int size)
+{
+   struct i2c_client *client = v4l2_get_subdevdata(>sd);
+   int ret;
+   u8 buf[3];
+
+   if (size != 1 && size != 2)
+   return -EINVAL;
+   buf[0] = addr;
+   buf[2] = data & 0xff;
+   if (size == 2)
+   buf[1] = data >> 8;
+   ret = i2c_master_send(client, (const char *)buf, size + 1);
+   if (ret < 0)
+   return ret;
+   if (ret != size + 1)
+   return -EIO;
+   return 0;
+}
+
+static int ak7375_set_ctrl(struct v4l2_ctrl *ctrl)
+{
+   struct ak7375_device *dev_vcm = to_ak7375_vcm(ctrl);
+
+   if (ctrl->id == V4L2_CID_FOCUS_ABSOLUTE)
+   return ak7375_i2c_

[PATCH] media: imx319: Add imx319 camera sensor driver

2018-05-16 Thread bingbu . cao
From: Bingbu Cao <bingbu@intel.com>

Add a V4L2 sub-device driver for the Sony IMX319 image sensor.
This is a camera sensor using the I2C bus for control and the
CSI-2 bus for data.

Signed-off-by: Bingbu Cao <bingbu@intel.com>
Signed-off-by: Tianshu Qiu <tian.shu@intel.com>
---
 MAINTAINERS|7 +
 drivers/media/i2c/Kconfig  |   11 +
 drivers/media/i2c/Makefile |1 +
 drivers/media/i2c/imx319.c | 2433 
 4 files changed, 2452 insertions(+)
 create mode 100644 drivers/media/i2c/imx319.c

diff --git a/MAINTAINERS b/MAINTAINERS
index e73a55a6a855..87b6c338d827 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -13084,6 +13084,13 @@ S: Maintained
 F: drivers/media/i2c/imx274.c
 F: Documentation/devicetree/bindings/media/i2c/imx274.txt
 
+SONY IMX319 SENSOR DRIVER
+M: Bingbu Cao <bingbu@intel.com>
+L: linux-media@vger.kernel.org
+T: git git://linuxtv.org/media_tree.git
+S: Maintained
+F: drivers/media/i2c/imx319.c
+
 SONY MEMORYSTICK CARD SUPPORT
 M: Alex Dubov <oa...@yahoo.com>
 W: http://tifmxx.berlios.de/
diff --git a/drivers/media/i2c/Kconfig b/drivers/media/i2c/Kconfig
index 1f9d7c6aa31a..c3d279cc293e 100644
--- a/drivers/media/i2c/Kconfig
+++ b/drivers/media/i2c/Kconfig
@@ -604,6 +604,17 @@ config VIDEO_IMX274
  This is a V4L2 sensor-level driver for the Sony IMX274
  CMOS image sensor.
 
+config VIDEO_IMX319
+   tristate "Sony IMX319 sensor support"
+   depends on I2C && VIDEO_V4L2 && VIDEO_V4L2_SUBDEV_API
+   depends on MEDIA_CAMERA_SUPPORT
+   help
+ This is a Video4Linux2 sensor driver for the Sony
+ IMX319 camera.
+
+ To compile this driver as a module, choose M here: the
+ module will be called imx319.
+
 config VIDEO_OV2640
tristate "OmniVision OV2640 sensor support"
depends on VIDEO_V4L2 && I2C
diff --git a/drivers/media/i2c/Makefile b/drivers/media/i2c/Makefile
index 16fc34eda5cc..3adb3be4a486 100644
--- a/drivers/media/i2c/Makefile
+++ b/drivers/media/i2c/Makefile
@@ -104,5 +104,6 @@ obj-$(CONFIG_VIDEO_OV2659)  += ov2659.o
 obj-$(CONFIG_VIDEO_TC358743)   += tc358743.o
 obj-$(CONFIG_VIDEO_IMX258) += imx258.o
 obj-$(CONFIG_VIDEO_IMX274) += imx274.o
+obj-$(CONFIG_VIDEO_IMX319) += imx319.o
 
 obj-$(CONFIG_SDR_MAX2175) += max2175.o
diff --git a/drivers/media/i2c/imx319.c b/drivers/media/i2c/imx319.c
new file mode 100644
index ..e6a918ec9036
--- /dev/null
+++ b/drivers/media/i2c/imx319.c
@@ -0,0 +1,2433 @@
+// SPDX-License-Identifier: GPL-2.0
+// Copyright (C) 2018 Intel Corporation
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define IMX319_REG_MODE_SELECT 0x0100
+#define IMX319_MODE_STANDBY0x00
+#define IMX319_MODE_STREAMING  0x01
+
+/* Chip ID */
+#define IMX319_REG_CHIP_ID 0x0016
+#define IMX319_CHIP_ID 0x0319
+
+/* V_TIMING internal */
+#define IMX319_REG_FLL 0x0340
+#define IMX319_FLL_MAX 0x
+
+/* Exposure control */
+#define IMX319_REG_EXPOSURE0x0202
+#define IMX319_EXPOSURE_MIN1
+#define IMX319_EXPOSURE_STEP   1
+#define IMX319_EXPOSURE_DEFAULT0x04ee
+
+/* Analog gain control */
+#define IMX319_REG_ANALOG_GAIN 0x0204
+#define IMX319_ANA_GAIN_MIN0
+#define IMX319_ANA_GAIN_MAX960
+#define IMX319_ANA_GAIN_STEP   1
+#define IMX319_ANA_GAIN_DEFAULT0
+
+/* Digital gain control */
+#define IMX319_REG_DPGA_USE_GLOBAL_GAIN0x3ff9
+#define IMX319_REG_DIG_GAIN_GLOBAL 0x020e
+#define IMX319_DGTL_GAIN_MIN   256
+#define IMX319_DGTL_GAIN_MAX   4095
+#define IMX319_DGTL_GAIN_STEP  1
+#define IMX319_DGTL_GAIN_DEFAULT   256
+
+/* Test Pattern Control */
+#define IMX319_REG_TEST_PATTERN0x0600
+#define IMX319_TEST_PATTERN_DISABLED   0
+#define IMX319_TEST_PATTERN_SOLID_COLOR1
+#define IMX319_TEST_PATTERN_COLOR_BARS 2
+#define IMX319_TEST_PATTERN_GRAY_COLOR_BARS3
+#define IMX319_TEST_PATTERN_PN94
+
+/* Flip Control */
+#define IMX319_REG_ORIENTATION 0x0101
+
+struct imx319_reg {
+   u16 address;
+   u8 val;
+};
+
+struct imx319_reg_list {
+   u32 num_of_regs;
+   const struct imx319_reg *regs;
+};
+
+/* Mode : resolution and related config */
+struct imx319_mode {
+   /* Frame width */
+   u32 width;
+   /* Frame height */
+   u32 height;
+
+   /* V-timing */
+   u32 fll_def;
+   u32 fll_min;
+
+   /* H-timing */
+   u32 llp;
+
+   /* Default register values */
+   struct imx319_reg_list reg_list;
+};
+
+struct imx319 {
+   struct v4l2_subdev sd;
+   struct media_pad pad;
+
+   struct v4l2_ctrl_

[PATCH] media: imx355: Add imx355 camera sensor driver

2018-05-16 Thread bingbu . cao
From: Bingbu Cao <bingbu@intel.com>

Add a V4L2 sub-device driver for the Sony IMX355 image sensor.
This is a camera sensor using the I2C bus for control and the
CSI-2 bus for data.

Signed-off-by: Tianshu Qiu <tian.shu@intel.com>
Signed-off-by: Bingbu Cao <bingbu@intel.com>
---
 MAINTAINERS|7 +
 drivers/media/i2c/Kconfig  |   11 +
 drivers/media/i2c/Makefile |1 +
 drivers/media/i2c/imx355.c | 1741 
 4 files changed, 1760 insertions(+)
 create mode 100644 drivers/media/i2c/imx355.c

diff --git a/MAINTAINERS b/MAINTAINERS
index e73a55a6a855..0921e9ae744e 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -13084,6 +13084,13 @@ S: Maintained
 F: drivers/media/i2c/imx274.c
 F: Documentation/devicetree/bindings/media/i2c/imx274.txt
 
+SONY IMX355 SENSOR DRIVER
+M: Tianshu Qiu <tian.shu@intel.com>
+L: linux-media@vger.kernel.org
+T: git git://linuxtv.org/media_tree.git
+S: Maintained
+F: drivers/media/i2c/imx355.c
+
 SONY MEMORYSTICK CARD SUPPORT
 M: Alex Dubov <oa...@yahoo.com>
 W: http://tifmxx.berlios.de/
diff --git a/drivers/media/i2c/Kconfig b/drivers/media/i2c/Kconfig
index 1f9d7c6aa31a..505e7aa30b8d 100644
--- a/drivers/media/i2c/Kconfig
+++ b/drivers/media/i2c/Kconfig
@@ -604,6 +604,17 @@ config VIDEO_IMX274
  This is a V4L2 sensor-level driver for the Sony IMX274
  CMOS image sensor.
 
+config VIDEO_IMX355
+   tristate "Sony IMX355 sensor support"
+   depends on I2C && VIDEO_V4L2 && VIDEO_V4L2_SUBDEV_API
+   depends on MEDIA_CAMERA_SUPPORT
+   help
+ This is a Video4Linux2 sensor driver for the Sony
+ IMX355 camera.
+
+ To compile this driver as a module, choose M here: the
+ module will be called imx355.
+
 config VIDEO_OV2640
tristate "OmniVision OV2640 sensor support"
depends on VIDEO_V4L2 && I2C
diff --git a/drivers/media/i2c/Makefile b/drivers/media/i2c/Makefile
index 16fc34eda5cc..dff2fb0dc3fa 100644
--- a/drivers/media/i2c/Makefile
+++ b/drivers/media/i2c/Makefile
@@ -104,5 +104,6 @@ obj-$(CONFIG_VIDEO_OV2659)  += ov2659.o
 obj-$(CONFIG_VIDEO_TC358743)   += tc358743.o
 obj-$(CONFIG_VIDEO_IMX258) += imx258.o
 obj-$(CONFIG_VIDEO_IMX274) += imx274.o
+obj-$(CONFIG_VIDEO_IMX355) += imx355.o
 
 obj-$(CONFIG_SDR_MAX2175) += max2175.o
diff --git a/drivers/media/i2c/imx355.c b/drivers/media/i2c/imx355.c
new file mode 100644
index ..6b936055acde
--- /dev/null
+++ b/drivers/media/i2c/imx355.c
@@ -0,0 +1,1741 @@
+// SPDX-License-Identifier: GPL-2.0
+// Copyright (C) 2017 - 2018 Intel Corporation
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define IMX355_REG_MODE_SELECT 0x0100
+#define IMX355_MODE_STANDBY0x00
+#define IMX355_MODE_STREAMING  0x01
+
+/* Chip ID */
+#define IMX355_REG_CHIP_ID 0x0016
+#define IMX355_CHIP_ID 0x0355
+
+/* V_TIMING internal */
+#define IMX355_REG_FLL 0x0340
+#define IMX355_FLL_MAX 0x
+
+/* Exposure control */
+#define IMX355_REG_EXPOSURE0x0202
+#define IMX355_EXPOSURE_MIN1
+#define IMX355_EXPOSURE_STEP   1
+#define IMX355_EXPOSURE_DEFAULT0x0282
+
+/* Analog gain control */
+#define IMX355_REG_ANALOG_GAIN 0x0204
+#define IMX355_ANA_GAIN_MIN0
+#define IMX355_ANA_GAIN_MAX960
+#define IMX355_ANA_GAIN_STEP   1
+#define IMX355_ANA_GAIN_DEFAULT0
+
+/* Digital gain control */
+#define IMX355_REG_DPGA_USE_GLOBAL_GAIN0x3070
+#define IMX355_REG_DIG_GAIN_GLOBAL 0x020e
+#define IMX355_DGTL_GAIN_MIN   256
+#define IMX355_DGTL_GAIN_MAX   4095
+#define IMX355_DGTL_GAIN_STEP  1
+#define IMX355_DGTL_GAIN_DEFAULT   256
+
+/* Test Pattern Control */
+#define IMX355_REG_TEST_PATTERN0x0600
+#define IMX355_TEST_PATTERN_DISABLED   0
+#define IMX355_TEST_PATTERN_SOLID_COLOR1
+#define IMX355_TEST_PATTERN_COLOR_BARS 2
+#define IMX355_TEST_PATTERN_GRAY_COLOR_BARS3
+#define IMX355_TEST_PATTERN_PN94
+
+/* Flip Control */
+#define IMX355_REG_ORIENTATION 0x0101
+
+struct imx355_reg {
+   u16 address;
+   u8 val;
+};
+
+struct imx355_reg_list {
+   u32 num_of_regs;
+   const struct imx355_reg *regs;
+};
+
+/* Mode : resolution and related config */
+struct imx355_mode {
+   /* Frame width */
+   u32 width;
+   /* Frame height */
+   u32 height;
+
+   /* V-timing */
+   u32 fll_def;
+   u32 fll_min;
+
+   /* H-timing */
+   u32 llp;
+
+   /* Default register values */
+   struct imx355_reg_list reg_list;
+};
+
+struct imx355 {
+   struct v4l2_subdev sd;
+   struct media_pad pad;
+
+   struct v4l2_ctrl_