diff mbox

[PATCHv6] support for AD5820 camera auto-focus coil

Message ID 20160805102611.GA13116@amd (mailing list archive)
State New, archived
Headers show

Commit Message

Pavel Machek Aug. 5, 2016, 10:26 a.m. UTC
This adds support for AD5820 autofocus coil, found for example in
Nokia N900 smartphone.

Signed-off-by: Pavel Machek <pavel@ucw.cz>

---
v2: simple cleanups, fix error paths, simplify probe
v3: more cleanups, remove printk, add include
v4: remove header file.
v5: switch to devm_ , style cleanups, fixes
v6: remove new userspace APIs.

Can we finally get the patch in, please?

Comments

Pali Rohár Aug. 5, 2016, 10:30 a.m. UTC | #1
On Friday 05 August 2016 12:26:11 Pavel Machek wrote:
> 
> This adds support for AD5820 autofocus coil, found for example in
> Nokia N900 smartphone.
> 
> Signed-off-by: Pavel Machek <pavel@ucw.cz>

Acked-by: Pali Rohár <pali.rohar@gmail.com>

> ---
> v2: simple cleanups, fix error paths, simplify probe
> v3: more cleanups, remove printk, add include
> v4: remove header file.
> v5: switch to devm_ , style cleanups, fixes
> v6: remove new userspace APIs.
> 
> Can we finally get the patch in, please?

This patch is on ML for months or years, right?
Please merge it...
Sakari Ailus Aug. 8, 2016, 8:09 a.m. UTC | #2
On Fri, Aug 05, 2016 at 12:26:11PM +0200, Pavel Machek wrote:
> 
> This adds support for AD5820 autofocus coil, found for example in
> Nokia N900 smartphone.

Thanks, Pavel!

Let's use V4L2_CID_FOCUS_ABSOLUTE, as is in the patch. If we get something
better in the future, we'll switch to that then.

I've applied this to ad5820 branch in my tree.
Pavel Machek Aug. 8, 2016, 9:40 p.m. UTC | #3
On Wed 2016-08-10 09:34:03, Pali Rohár wrote:
> On Monday 08 August 2016 11:09:56 Sakari Ailus wrote:
> > On Fri, Aug 05, 2016 at 12:26:11PM +0200, Pavel Machek wrote:
> > > 
> > > This adds support for AD5820 autofocus coil, found for example in
> > > Nokia N900 smartphone.
> > 
> > Thanks, Pavel!
> > 
> > Let's use V4L2_CID_FOCUS_ABSOLUTE, as is in the patch. If we get something
> > better in the future, we'll switch to that then.
> 
> Ok, and what with AD5820_RAMP_TIME and AD5820_RAMP_MODE?

Lets forget about those for now. I'll wait till current support works in the
Linus' tree, then I can write the docs and re-add the ioctls.

Best regards,
									Pavel
 
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Pavel Machek Aug. 8, 2016, 9:41 p.m. UTC | #4
On Mon 2016-08-08 11:09:56, Sakari Ailus wrote:
> On Fri, Aug 05, 2016 at 12:26:11PM +0200, Pavel Machek wrote:
> > 
> > This adds support for AD5820 autofocus coil, found for example in
> > Nokia N900 smartphone.
> 
> Thanks, Pavel!
> 
> Let's use V4L2_CID_FOCUS_ABSOLUTE, as is in the patch. If we get something
> better in the future, we'll switch to that then.
> 
> I've applied this to ad5820 branch in my tree.

Thanks. If I understands things correctly, both DTS patch and this patch are
waiting in your tree, so we should be good to go for 4.9 (unless some unexpected
problems surface)?

Best regards,
									Pavel
Pavel Machek Aug. 8, 2016, 11:23 p.m. UTC | #5
On Wed 2016-08-10 15:01:05, Sakari Ailus wrote:
> On Mon, Aug 08, 2016 at 11:41:32PM +0200, Pavel Machek wrote:
> > On Mon 2016-08-08 11:09:56, Sakari Ailus wrote:
> > > On Fri, Aug 05, 2016 at 12:26:11PM +0200, Pavel Machek wrote:
> > > > 
> > > > This adds support for AD5820 autofocus coil, found for example in
> > > > Nokia N900 smartphone.
> > > 
> > > Thanks, Pavel!
> > > 
> > > Let's use V4L2_CID_FOCUS_ABSOLUTE, as is in the patch. If we get something
> > > better in the future, we'll switch to that then.
> > > 
> > > I've applied this to ad5820 branch in my tree.
> > 
> > Thanks. If I understands things correctly, both DTS patch and this patch are
> > waiting in your tree, so we should be good to go for 4.9 (unless some unexpected
> > problems surface)?
> 
> Yeah. I just compiled it but haven't tested it. I presume it'll work. :-)

I'm testing it on n900. I guess simpler hardware with ad5820 would be better for the
test...

What hardware do you have?

Best regards,
									Pavel
Pali Rohár Aug. 10, 2016, 7:34 a.m. UTC | #6
On Monday 08 August 2016 11:09:56 Sakari Ailus wrote:
> On Fri, Aug 05, 2016 at 12:26:11PM +0200, Pavel Machek wrote:
> > 
> > This adds support for AD5820 autofocus coil, found for example in
> > Nokia N900 smartphone.
> 
> Thanks, Pavel!
> 
> Let's use V4L2_CID_FOCUS_ABSOLUTE, as is in the patch. If we get something
> better in the future, we'll switch to that then.

Ok, and what with AD5820_RAMP_TIME and AD5820_RAMP_MODE?

> I've applied this to ad5820 branch in my tree.

Are you going to finally send this patch to media tree or pull request
to Linus?
Sakari Ailus Aug. 10, 2016, noon UTC | #7
On Wed, Aug 10, 2016 at 09:34:03AM +0200, Pali Rohár wrote:
> On Monday 08 August 2016 11:09:56 Sakari Ailus wrote:
> > On Fri, Aug 05, 2016 at 12:26:11PM +0200, Pavel Machek wrote:
> > > 
> > > This adds support for AD5820 autofocus coil, found for example in
> > > Nokia N900 smartphone.
> > 
> > Thanks, Pavel!
> > 
> > Let's use V4L2_CID_FOCUS_ABSOLUTE, as is in the patch. If we get something
> > better in the future, we'll switch to that then.
> 
> Ok, and what with AD5820_RAMP_TIME and AD5820_RAMP_MODE?
> 
> > I've applied this to ad5820 branch in my tree.
> 
> Are you going to finally send this patch to media tree or pull request
> to Linus?

That'll be through media-tree.
Sakari Ailus Aug. 10, 2016, 12:01 p.m. UTC | #8
On Mon, Aug 08, 2016 at 11:41:32PM +0200, Pavel Machek wrote:
> On Mon 2016-08-08 11:09:56, Sakari Ailus wrote:
> > On Fri, Aug 05, 2016 at 12:26:11PM +0200, Pavel Machek wrote:
> > > 
> > > This adds support for AD5820 autofocus coil, found for example in
> > > Nokia N900 smartphone.
> > 
> > Thanks, Pavel!
> > 
> > Let's use V4L2_CID_FOCUS_ABSOLUTE, as is in the patch. If we get something
> > better in the future, we'll switch to that then.
> > 
> > I've applied this to ad5820 branch in my tree.
> 
> Thanks. If I understands things correctly, both DTS patch and this patch are
> waiting in your tree, so we should be good to go for 4.9 (unless some unexpected
> problems surface)?

Yeah. I just compiled it but haven't tested it. I presume it'll work. :-)
Sakari Ailus Aug. 11, 2016, 11:16 a.m. UTC | #9
On Tue, Aug 09, 2016 at 01:23:23AM +0200, Pavel Machek wrote:
> On Wed 2016-08-10 15:01:05, Sakari Ailus wrote:
> > On Mon, Aug 08, 2016 at 11:41:32PM +0200, Pavel Machek wrote:
> > > On Mon 2016-08-08 11:09:56, Sakari Ailus wrote:
> > > > On Fri, Aug 05, 2016 at 12:26:11PM +0200, Pavel Machek wrote:
> > > > > 
> > > > > This adds support for AD5820 autofocus coil, found for example in
> > > > > Nokia N900 smartphone.
> > > > 
> > > > Thanks, Pavel!
> > > > 
> > > > Let's use V4L2_CID_FOCUS_ABSOLUTE, as is in the patch. If we get something
> > > > better in the future, we'll switch to that then.
> > > > 
> > > > I've applied this to ad5820 branch in my tree.
> > > 
> > > Thanks. If I understands things correctly, both DTS patch and this patch are
> > > waiting in your tree, so we should be good to go for 4.9 (unless some unexpected
> > > problems surface)?
> > 
> > Yeah. I just compiled it but haven't tested it. I presume it'll work. :-)
> 
> I'm testing it on n900. I guess simpler hardware with ad5820 would be better for the
> test...
> 
> What hardware do you have?

N900. What else could it be? :-) :-)
Pavel Machek Aug. 18, 2016, 10:45 a.m. UTC | #10
On Thu 2016-08-11 14:16:34, Sakari Ailus wrote:
> On Tue, Aug 09, 2016 at 01:23:23AM +0200, Pavel Machek wrote:
> > On Wed 2016-08-10 15:01:05, Sakari Ailus wrote:
> > > On Mon, Aug 08, 2016 at 11:41:32PM +0200, Pavel Machek wrote:
> > > > On Mon 2016-08-08 11:09:56, Sakari Ailus wrote:
> > > > > On Fri, Aug 05, 2016 at 12:26:11PM +0200, Pavel Machek wrote:
> > > > > > 
> > > > > > This adds support for AD5820 autofocus coil, found for example in
> > > > > > Nokia N900 smartphone.
> > > > > 
> > > > > Thanks, Pavel!
> > > > > 
> > > > > Let's use V4L2_CID_FOCUS_ABSOLUTE, as is in the patch. If we get something
> > > > > better in the future, we'll switch to that then.
> > > > > 
> > > > > I've applied this to ad5820 branch in my tree.
> > > > 
> > > > Thanks. If I understands things correctly, both DTS patch and this patch are
> > > > waiting in your tree, so we should be good to go for 4.9 (unless some unexpected
> > > > problems surface)?
> > > 
> > > Yeah. I just compiled it but haven't tested it. I presume it'll work. :-)
> > 
> > I'm testing it on n900. I guess simpler hardware with ad5820 would be better for the
> > test...
> > 
> > What hardware do you have?
> 
> N900. What else could it be? :-) :-)

Heh. Basically anything is easier to develop for than n900 :-(.

Ok, for real testing, Ivaylo's camera patchset is useful, so that you
have picture to work with, plus your subdevs for omap3 patchset (which
needs a forward port).

I have patches against v4.7, if you are interested.

I guess subdevs for omap3 should be merged at this point. Do you have
any plans to do that, or should I take a look?

Best regards,

									Pavel
Sakari Ailus Aug. 18, 2016, 8:26 p.m. UTC | #11
Hi Pavel,

On Thu, Aug 18, 2016 at 12:45:39PM +0200, Pavel Machek wrote:
> On Thu 2016-08-11 14:16:34, Sakari Ailus wrote:
> > On Tue, Aug 09, 2016 at 01:23:23AM +0200, Pavel Machek wrote:
> > > On Wed 2016-08-10 15:01:05, Sakari Ailus wrote:
> > > > On Mon, Aug 08, 2016 at 11:41:32PM +0200, Pavel Machek wrote:
> > > > > On Mon 2016-08-08 11:09:56, Sakari Ailus wrote:
> > > > > > On Fri, Aug 05, 2016 at 12:26:11PM +0200, Pavel Machek wrote:
> > > > > > > 
> > > > > > > This adds support for AD5820 autofocus coil, found for example in
> > > > > > > Nokia N900 smartphone.
> > > > > > 
> > > > > > Thanks, Pavel!
> > > > > > 
> > > > > > Let's use V4L2_CID_FOCUS_ABSOLUTE, as is in the patch. If we get something
> > > > > > better in the future, we'll switch to that then.
> > > > > > 
> > > > > > I've applied this to ad5820 branch in my tree.
> > > > > 
> > > > > Thanks. If I understands things correctly, both DTS patch and this patch are
> > > > > waiting in your tree, so we should be good to go for 4.9 (unless some unexpected
> > > > > problems surface)?
> > > > 
> > > > Yeah. I just compiled it but haven't tested it. I presume it'll work. :-)
> > > 
> > > I'm testing it on n900. I guess simpler hardware with ad5820 would be better for the
> > > test...
> > > 
> > > What hardware do you have?
> > 
> > N900. What else could it be? :-) :-)
> 
> Heh. Basically anything is easier to develop for than n900 :-(.

Is it?

I actually find the old Nokia devices very practical. It's easy to boot your
own kernel and things just work... until musb broke a bit recently. It
requires reconnecting the usb cable again to function.

I have to admit I mostly use an N9.

> 
> Ok, for real testing, Ivaylo's camera patchset is useful, so that you
> have picture to work with, plus your subdevs for omap3 patchset (which
> needs a forward port).
> 
> I have patches against v4.7, if you are interested.

They should be pretty close to mainline. The rebase should be very easy.

Patches against media-tree master branch would always be better naturally.
:-)

> 
> I guess subdevs for omap3 should be merged at this point. Do you have
> any plans to do that, or should I take a look?

What's still missing? I think I've yet to check the et8ek8 driver and the
device tree description is missing. That's what comes to mind right now.
Pavel Machek Nov. 3, 2016, 10:27 a.m. UTC | #12
Hi!

> > > > > Yeah. I just compiled it but haven't tested it. I presume it'll work. :-)
> > > > 
> > > > I'm testing it on n900. I guess simpler hardware with ad5820 would be better for the
> > > > test...
> > > > 
> > > > What hardware do you have?
> > > 
> > > N900. What else could it be? :-) :-)
> > 
> > Heh. Basically anything is easier to develop for than n900 :-(.
> 
> Is it?
> 
> I actually find the old Nokia devices very practical. It's easy to boot your
> own kernel and things just work... until musb broke a bit recently. It
> requires reconnecting the usb cable again to function.
> 
> I have to admit I mostly use an N9.

Well, if you compare that to development on PC, I prefer PC.

Even arm development boards are usually easier, as they don't need too
complex userspace, and do have working serial ports.

But I do have a serial adapter for N900 now (thanks, sre), so my main
problem now is that N900 takes a lot of time to boot into usable
state.

Best regards,
									Pavel
Sakari Ailus Nov. 3, 2016, 9:49 p.m. UTC | #13
On Thu, Nov 03, 2016 at 11:27:27AM +0100, Pavel Machek wrote:
> Hi!
> 
> > > > > > Yeah. I just compiled it but haven't tested it. I presume it'll work. :-)
> > > > > 
> > > > > I'm testing it on n900. I guess simpler hardware with ad5820 would be better for the
> > > > > test...
> > > > > 
> > > > > What hardware do you have?
> > > > 
> > > > N900. What else could it be? :-) :-)
> > > 
> > > Heh. Basically anything is easier to develop for than n900 :-(.
> > 
> > Is it?
> > 
> > I actually find the old Nokia devices very practical. It's easy to boot your
> > own kernel and things just work... until musb broke a bit recently. It
> > requires reconnecting the usb cable again to function.
> > 
> > I have to admit I mostly use an N9.
> 
> Well, if you compare that to development on PC, I prefer PC.
> 
> Even arm development boards are usually easier, as they don't need too
> complex userspace, and do have working serial ports.
> 
> But I do have a serial adapter for N900 now (thanks, sre), so my main
> problem now is that N900 takes a lot of time to boot into usable
> state.

Yeah... I just upgraded my Debian installation (armel over NFS) a few major
numbers and I find it a lot slower than it used to do. I presume that's
mostly because of systemd...
Pavel Machek Nov. 4, 2016, 7:45 a.m. UTC | #14
Hi!

> > > I have to admit I mostly use an N9.
> > 
> > Well, if you compare that to development on PC, I prefer PC.
> > 
> > Even arm development boards are usually easier, as they don't need too
> > complex userspace, and do have working serial ports.
> > 
> > But I do have a serial adapter for N900 now (thanks, sre), so my main
> > problem now is that N900 takes a lot of time to boot into usable
> > state.
> 
> Yeah... I just upgraded my Debian installation (armel over NFS) a few major
> numbers and I find it a lot slower than it used to do. I presume that's
> mostly because of systemd...

I'm not sure if systemd is to blame. (I'm booting into full GUI...)

And yes, I noticed the slowdown in Debian 7 -> 8 transition, so I'm
basically staying at Debian 7 as far as I can.

Best regards,
									Pavel
Tony Lindgren Nov. 4, 2016, 2:49 p.m. UTC | #15
* Pavel Machek <pavel@ucw.cz> [161104 00:45]:
> Hi!
> 
> > > > I have to admit I mostly use an N9.
> > > 
> > > Well, if you compare that to development on PC, I prefer PC.
> > > 
> > > Even arm development boards are usually easier, as they don't need too
> > > complex userspace, and do have working serial ports.
> > > 
> > > But I do have a serial adapter for N900 now (thanks, sre), so my main
> > > problem now is that N900 takes a lot of time to boot into usable
> > > state.
> > 
> > Yeah... I just upgraded my Debian installation (armel over NFS) a few major
> > numbers and I find it a lot slower than it used to do. I presume that's
> > mostly because of systemd...
> 
> I'm not sure if systemd is to blame. (I'm booting into full GUI...)
> 
> And yes, I noticed the slowdown in Debian 7 -> 8 transition, so I'm
> basically staying at Debian 7 as far as I can.

Maybe it's the armel vs armhf causing the slowdown?

Regards,

Tony


--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Pali Rohár Dec. 14, 2016, 1:38 p.m. UTC | #16
On Monday 08 August 2016 23:41:32 Pavel Machek wrote:
> On Mon 2016-08-08 11:09:56, Sakari Ailus wrote:
> > On Fri, Aug 05, 2016 at 12:26:11PM +0200, Pavel Machek wrote:
> > > This adds support for AD5820 autofocus coil, found for example in
> > > Nokia N900 smartphone.
> > 
> > Thanks, Pavel!
> > 
> > Let's use V4L2_CID_FOCUS_ABSOLUTE, as is in the patch. If we get
> > something better in the future, we'll switch to that then.
> > 
> > I've applied this to ad5820 branch in my tree.
> 
> Thanks. If I understands things correctly, both DTS patch and this
> patch are waiting in your tree, so we should be good to go for 4.9
> (unless some unexpected problems surface)?
> 
> Best regards,
> 									Pavel

Was DTS patch merged into 4.9? At least I do not see updated that dts 
file omap3-n900.dts in linus tree...
Tony Lindgren Dec. 14, 2016, 3:08 p.m. UTC | #17
* Pali Rohár <pali.rohar@gmail.com> [161214 05:38]:
> On Monday 08 August 2016 23:41:32 Pavel Machek wrote:
> > On Mon 2016-08-08 11:09:56, Sakari Ailus wrote:
> > > On Fri, Aug 05, 2016 at 12:26:11PM +0200, Pavel Machek wrote:
> > > > This adds support for AD5820 autofocus coil, found for example in
> > > > Nokia N900 smartphone.
> > > 
> > > Thanks, Pavel!
> > > 
> > > Let's use V4L2_CID_FOCUS_ABSOLUTE, as is in the patch. If we get
> > > something better in the future, we'll switch to that then.
> > > 
> > > I've applied this to ad5820 branch in my tree.
> > 
> > Thanks. If I understands things correctly, both DTS patch and this
> > patch are waiting in your tree, so we should be good to go for 4.9
> > (unless some unexpected problems surface)?
> > 
> > Best regards,
> > 									Pavel
> 
> Was DTS patch merged into 4.9? At least I do not see updated that dts 
> file omap3-n900.dts in linus tree...

If it's not in current mainline or next, it's off my radar so sounds
like I've somehow missed it and needs resending..

Tony
--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Sakari Ailus Dec. 15, 2016, 6:50 a.m. UTC | #18
Hi Pali and Tony,

On Wed, Dec 14, 2016 at 07:08:19AM -0800, Tony Lindgren wrote:
> * Pali Rohár <pali.rohar@gmail.com> [161214 05:38]:
> > On Monday 08 August 2016 23:41:32 Pavel Machek wrote:
> > > On Mon 2016-08-08 11:09:56, Sakari Ailus wrote:
> > > > On Fri, Aug 05, 2016 at 12:26:11PM +0200, Pavel Machek wrote:
> > > > > This adds support for AD5820 autofocus coil, found for example in
> > > > > Nokia N900 smartphone.
> > > > 
> > > > Thanks, Pavel!
> > > > 
> > > > Let's use V4L2_CID_FOCUS_ABSOLUTE, as is in the patch. If we get
> > > > something better in the future, we'll switch to that then.
> > > > 
> > > > I've applied this to ad5820 branch in my tree.
> > > 
> > > Thanks. If I understands things correctly, both DTS patch and this
> > > patch are waiting in your tree, so we should be good to go for 4.9
> > > (unless some unexpected problems surface)?
> > > 
> > > Best regards,
> > > 									Pavel
> > 
> > Was DTS patch merged into 4.9? At least I do not see updated that dts 
> > file omap3-n900.dts in linus tree...
> 
> If it's not in current mainline or next, it's off my radar so sounds
> like I've somehow missed it and needs resending..

Where's this patch? I remember seeing the driver patch and the DT
documentation but no actual DT source patch for the N900.
Pavel Machek Dec. 19, 2016, 10:23 p.m. UTC | #19
Hi!

> Hi Pali and Tony,
> On Wed, Dec 14, 2016 at 07:08:19AM -0800, Tony Lindgren wrote:
> > * Pali Rohár <pali.rohar@gmail.com> [161214 05:38]:
> > > On Monday 08 August 2016 23:41:32 Pavel Machek wrote:
> > > > On Mon 2016-08-08 11:09:56, Sakari Ailus wrote:
> > > > > On Fri, Aug 05, 2016 at 12:26:11PM +0200, Pavel Machek wrote:
> > > > > > This adds support for AD5820 autofocus coil, found for example in
> > > > > > Nokia N900 smartphone.
> > > > > 
> > > > > Thanks, Pavel!
> > > > > 
> > > > > Let's use V4L2_CID_FOCUS_ABSOLUTE, as is in the patch. If we get
> > > > > something better in the future, we'll switch to that then.
> > > > > 
> > > > > I've applied this to ad5820 branch in my tree.
> > > > 
> > > > Thanks. If I understands things correctly, both DTS patch and this
> > > > patch are waiting in your tree, so we should be good to go for 4.9
> > > > (unless some unexpected problems surface)?
> > > > 
> > > > Best regards,
> > > > 									Pavel
> > > 
> > > Was DTS patch merged into 4.9? At least I do not see updated that dts 
> > > file omap3-n900.dts in linus tree...
> > 
> > If it's not in current mainline or next, it's off my radar so sounds
> > like I've somehow missed it and needs resending..
> 
> Where's this patch? I remember seeing the driver patch and the DT
> documentation but no actual DT source patch for the N900.

The patch was not yet submitted. Autofocus coil is not too useful
withou camera support, and we don't yet have support for v4l subdevs
for omap3. I have it in the camera tree, but there are still pieces to
be done before this is useful.

Best regards,
									Pavel
diff mbox

Patch

diff --git a/drivers/media/i2c/Kconfig b/drivers/media/i2c/Kconfig
index 993dc50..20e8e89 100644
--- a/drivers/media/i2c/Kconfig
+++ b/drivers/media/i2c/Kconfig
@@ -279,6 +279,13 @@  config VIDEO_ML86V7667
 	  To compile this driver as a module, choose M here: the
 	  module will be called ml86v7667.
 
+config VIDEO_AD5820
+	tristate "AD5820 lens voice coil support"
+	depends on I2C && VIDEO_V4L2 && MEDIA_CONTROLLER
+	---help---
+	  This is a driver for the AD5820 camera lens voice coil.
+	  It is used for example in Nokia N900 (RX-51).
+
 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 94f2c99..0216af0 100644
--- a/drivers/media/i2c/Makefile
+++ b/drivers/media/i2c/Makefile
@@ -19,6 +19,7 @@  obj-$(CONFIG_VIDEO_SAA717X) += saa717x.o
 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_ADV7170) += adv7170.o
 obj-$(CONFIG_VIDEO_ADV7175) += adv7175.o
 obj-$(CONFIG_VIDEO_ADV7180) += adv7180.o
diff --git a/drivers/media/i2c/ad5820.c b/drivers/media/i2c/ad5820.c
new file mode 100644
index 0000000..62cc1f5
--- /dev/null
+++ b/drivers/media/i2c/ad5820.c
@@ -0,0 +1,380 @@ 
+/*
+ * drivers/media/i2c/ad5820.c
+ *
+ * AD5820 DAC driver for camera voice coil focus.
+ *
+ * Copyright (C) 2008 Nokia Corporation
+ * Copyright (C) 2007 Texas Instruments
+ * Copyright (C) 2016 Pavel Machek <pavel@ucw.cz>
+ *
+ * Contact: Tuukka Toivonen <tuukkat76@gmail.com>
+ *	    Sakari Ailus <sakari.ailus@iki.fi>
+ *
+ * Based on af_d88.c by Texas Instruments.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ */
+
+#include <linux/errno.h>
+#include <linux/i2c.h>
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/regulator/consumer.h>
+
+#include <media/v4l2-ctrls.h>
+#include <media/v4l2-device.h>
+#include <media/v4l2-subdev.h>
+
+#define AD5820_NAME		"ad5820"
+
+/* Register definitions */
+#define AD5820_POWER_DOWN		(1 << 15)
+#define AD5820_DAC_SHIFT		4
+#define AD5820_RAMP_MODE_LINEAR		(0 << 3)
+#define AD5820_RAMP_MODE_64_16		(1 << 3)
+
+#define CODE_TO_RAMP_US(s)	((s) == 0 ? 0 : (1 << ((s) - 1)) * 50)
+#define RAMP_US_TO_CODE(c)	fls(((c) + ((c)>>1)) / 50)
+
+#define to_ad5820_device(sd)	container_of(sd, struct ad5820_device, subdev)
+
+struct ad5820_device {
+	struct v4l2_subdev subdev;
+	struct ad5820_platform_data *platform_data;
+	struct regulator *vana;
+
+	struct v4l2_ctrl_handler ctrls;
+	u32 focus_absolute;
+	u32 focus_ramp_time;
+	u32 focus_ramp_mode;
+
+	struct mutex power_lock;
+	int power_count;
+
+	int standby : 1;
+};
+
+static int ad5820_write(struct ad5820_device *coil, u16 data)
+{
+	struct i2c_client *client = v4l2_get_subdevdata(&coil->subdev);
+	struct i2c_msg msg;
+	int r;
+
+	if (!client->adapter)
+		return -ENODEV;
+
+	data = cpu_to_be16(data);
+	msg.addr  = client->addr;
+	msg.flags = 0;
+	msg.len   = 2;
+	msg.buf   = (u8 *)&data;
+
+	r = i2c_transfer(client->adapter, &msg, 1);
+	if (r < 0) {
+		dev_err(&client->dev, "write failed, error %d\n", r);
+		return r;
+	}
+
+	return 0;
+}
+
+/*
+ * Calculate status word and write it to the device based on current
+ * values of V4L2 controls. It is assumed that the stored V4L2 control
+ * values are properly limited and rounded.
+ */
+static int ad5820_update_hw(struct ad5820_device *coil)
+{
+	u16 status;
+
+	status = RAMP_US_TO_CODE(coil->focus_ramp_time);
+	status |= coil->focus_ramp_mode
+		? AD5820_RAMP_MODE_64_16 : AD5820_RAMP_MODE_LINEAR;
+	status |= coil->focus_absolute << AD5820_DAC_SHIFT;
+
+	if (coil->standby)
+		status |= AD5820_POWER_DOWN;
+
+	return ad5820_write(coil, status);
+}
+
+/*
+ * Power handling
+ */
+static int ad5820_power_off(struct ad5820_device *coil, int standby)
+{
+	int ret = 0, ret2;
+
+	/*
+	 * Go to standby first as real power off my be denied by the hardware
+	 * (single power line control for both coil and sensor).
+	 */
+	if (standby) {
+		coil->standby = 1;
+		ret = ad5820_update_hw(coil);
+	}
+
+	ret2 = regulator_disable(coil->vana);
+	if (ret)
+		return ret;
+	return ret2;
+}
+
+static int ad5820_power_on(struct ad5820_device *coil, int restore)
+{
+	int ret;
+
+	ret = regulator_enable(coil->vana);
+	if (ret < 0)
+		return ret;
+
+	if (restore) {
+		/* Restore the hardware settings. */
+		coil->standby = 0;
+		ret = ad5820_update_hw(coil);
+		if (ret)
+			goto fail;
+	}
+	return 0;
+
+fail:
+	coil->standby = 1;
+	regulator_disable(coil->vana);
+
+	return ret;
+}
+
+/*
+ * V4L2 controls
+ */
+static int ad5820_set_ctrl(struct v4l2_ctrl *ctrl)
+{
+	struct ad5820_device *coil =
+		container_of(ctrl->handler, struct ad5820_device, ctrls);
+
+	switch (ctrl->id) {
+	case V4L2_CID_FOCUS_ABSOLUTE:
+		coil->focus_absolute = ctrl->val;
+		return ad5820_update_hw(coil);
+	}
+
+	return 0;
+}
+
+static const struct v4l2_ctrl_ops ad5820_ctrl_ops = {
+	.s_ctrl = ad5820_set_ctrl,
+};
+
+
+static int ad5820_init_controls(struct ad5820_device *coil)
+{
+	v4l2_ctrl_handler_init(&coil->ctrls, 1);
+
+	/*
+	 * V4L2_CID_FOCUS_ABSOLUTE
+	 *
+	 * Minimum current is 0 mA, maximum is 100 mA. Thus, 1 code is
+	 * equivalent to 100/1023 = 0.0978 mA. Nevertheless, we do not use [mA]
+	 * for focus position, because it is meaningless for user. Meaningful
+	 * would be to use focus distance or even its inverse, but since the
+	 * driver doesn't have sufficiently knowledge to do the conversion, we
+	 * will just use abstract codes here. In any case, smaller value = focus
+	 * position farther from camera. The default zero value means focus at
+	 * infinity, and also least current consumption.
+	 */
+	v4l2_ctrl_new_std(&coil->ctrls, &ad5820_ctrl_ops,
+			  V4L2_CID_FOCUS_ABSOLUTE, 0, 1023, 1, 0);
+
+	if (coil->ctrls.error)
+		return coil->ctrls.error;
+
+	coil->focus_absolute = 0;
+	coil->focus_ramp_time = 0;
+	coil->focus_ramp_mode = 0;
+
+	coil->subdev.ctrl_handler = &coil->ctrls;
+
+	return 0;
+}
+
+/*
+ * V4L2 subdev operations
+ */
+static int ad5820_registered(struct v4l2_subdev *subdev)
+{
+	struct ad5820_device *coil = to_ad5820_device(subdev);
+
+	return ad5820_init_controls(coil);
+}
+
+static int
+ad5820_set_power(struct v4l2_subdev *subdev, int on)
+{
+	struct ad5820_device *coil = to_ad5820_device(subdev);
+	int ret = 0;
+
+	mutex_lock(&coil->power_lock);
+
+	/*
+	 * If the power count is modified from 0 to != 0 or from != 0 to 0,
+	 * update the power state.
+	 */
+	if (coil->power_count == !on) {
+		ret = on ? ad5820_power_on(coil, 1) : ad5820_power_off(coil, 1);
+		if (ret < 0)
+			goto done;
+	}
+
+	/* Update the power count. */
+	coil->power_count += on ? 1 : -1;
+	WARN_ON(coil->power_count < 0);
+
+done:
+	mutex_unlock(&coil->power_lock);
+	return ret;
+}
+
+static int ad5820_open(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh)
+{
+	return ad5820_set_power(sd, 1);
+}
+
+static int ad5820_close(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh)
+{
+	return ad5820_set_power(sd, 0);
+}
+
+static const struct v4l2_subdev_core_ops ad5820_core_ops = {
+	.s_power = ad5820_set_power,
+};
+
+static const struct v4l2_subdev_ops ad5820_ops = {
+	.core = &ad5820_core_ops,
+};
+
+static const struct v4l2_subdev_internal_ops ad5820_internal_ops = {
+	.registered = ad5820_registered,
+	.open = ad5820_open,
+	.close = ad5820_close,
+};
+
+/*
+ * I2C driver
+ */
+#ifdef CONFIG_PM
+
+static int ad5820_suspend(struct device *dev)
+{
+	struct i2c_client *client = container_of(dev, struct i2c_client, dev);
+	struct v4l2_subdev *subdev = i2c_get_clientdata(client);
+	struct ad5820_device *coil = to_ad5820_device(subdev);
+
+	if (!coil->power_count)
+		return 0;
+
+	return ad5820_power_off(coil, 0);
+}
+
+static int ad5820_resume(struct device *dev)
+{
+	struct i2c_client *client = container_of(dev, struct i2c_client, dev);
+	struct v4l2_subdev *subdev = i2c_get_clientdata(client);
+	struct ad5820_device *coil = to_ad5820_device(subdev);
+
+	if (!coil->power_count)
+		return 0;
+
+	return ad5820_power_on(coil, 1);
+}
+
+#else
+
+#define ad5820_suspend	NULL
+#define ad5820_resume	NULL
+
+#endif /* CONFIG_PM */
+
+static int ad5820_probe(struct i2c_client *client,
+			const struct i2c_device_id *devid)
+{
+	struct ad5820_device *coil;
+	int ret;
+
+	coil = devm_kzalloc(&client->dev, sizeof(*coil), GFP_KERNEL);
+	if (!coil)
+		return -ENOMEM;
+
+	coil->vana = devm_regulator_get(&client->dev, "VANA");
+	if (IS_ERR(coil->vana)) {
+		ret = PTR_ERR(coil->vana);
+		if (ret != -EPROBE_DEFER)
+			dev_err(&client->dev, "could not get regulator for vana\n");
+		return ret;
+	}
+
+	mutex_init(&coil->power_lock);
+
+	v4l2_i2c_subdev_init(&coil->subdev, client, &ad5820_ops);
+	coil->subdev.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE;
+	coil->subdev.internal_ops = &ad5820_internal_ops;
+	strcpy(coil->subdev.name, "ad5820 focus");
+
+	ret = media_entity_pads_init(&coil->subdev.entity, 0, NULL);
+	if (ret < 0)
+		goto cleanup2;
+
+	ret = v4l2_async_register_subdev(&coil->subdev);
+	if (ret < 0)
+		goto cleanup;
+
+	return ret;
+
+cleanup2:
+	mutex_destroy(&coil->power_lock);
+cleanup:
+	media_entity_cleanup(&coil->subdev.entity);
+	return ret;
+}
+
+static int __exit ad5820_remove(struct i2c_client *client)
+{
+	struct v4l2_subdev *subdev = i2c_get_clientdata(client);
+	struct ad5820_device *coil = to_ad5820_device(subdev);
+
+	v4l2_device_unregister_subdev(&coil->subdev);
+	v4l2_ctrl_handler_free(&coil->ctrls);
+	media_entity_cleanup(&coil->subdev.entity);
+	mutex_destroy(&coil->power_lock);
+	return 0;
+}
+
+static const struct i2c_device_id ad5820_id_table[] = {
+	{ AD5820_NAME, 0 },
+	{ }
+};
+MODULE_DEVICE_TABLE(i2c, ad5820_id_table);
+
+static SIMPLE_DEV_PM_OPS(ad5820_pm, ad5820_suspend, ad5820_resume);
+
+static struct i2c_driver ad5820_i2c_driver = {
+	.driver		= {
+		.name	= AD5820_NAME,
+		.pm	= &ad5820_pm,
+	},
+	.probe		= ad5820_probe,
+	.remove		= __exit_p(ad5820_remove),
+	.id_table	= ad5820_id_table,
+};
+
+module_i2c_driver(ad5820_i2c_driver);
+
+MODULE_AUTHOR("Tuukka Toivonen");
+MODULE_DESCRIPTION("AD5820 camera lens driver");
+MODULE_LICENSE("GPL");