[libcamera-devel,RFC,v1,2/5] libcamera: camera_lens: Get maximum VCM steps
diff mbox series

Message ID 20220414074342.7455-3-hpa@redhat.com
State Superseded
Headers show
Series
  • Enabling AF algorithm to get the VCM attributes from the device driver
Related show

Commit Message

Kate Hsuan April 14, 2022, 7:43 a.m. UTC
It allows other components to get the maximum VCM steps. It first creates
a control list and set V4L2_CID_FOCUS_ABSOLUTE control to it. Then, it
calls a lower layer call, getAttributes() to get the maximum VCM steps
from the kernel.

Signed-off-by: Kate Hsuan<hpa@redhat.com>
---
 include/libcamera/internal/camera_lens.h |  1 +
 src/libcamera/camera_lens.cpp            | 18 ++++++++++++++++++
 2 files changed, 19 insertions(+)

Comments

Jacopo Mondi April 14, 2022, 8:21 a.m. UTC | #1
Hi Kate,

On Thu, Apr 14, 2022 at 03:43:39PM +0800, Kate Hsuan via libcamera-devel wrote:
> It allows other components to get the maximum VCM steps. It first creates
> a control list and set V4L2_CID_FOCUS_ABSOLUTE control to it. Then, it
> calls a lower layer call, getAttributes() to get the maximum VCM steps
> from the kernel.

I might have missed something here.

V4L2Device::controls() returns you a ControlInfoMap for all the
controls registered on the lens subdevice, with the controls' min, max
and default values collected at subdev open time with
V4L2Device::listControls()

Is there a reason I have missed about why you need to re-fetch the
control's limits again ?

If you need to collect the V4L2_CID_FOCUS_ABSOLUTE control maximum
value I think you could very well do so at validateLensDriver() time.

Thanks
   j

>
> Signed-off-by: Kate Hsuan<hpa@redhat.com>
> ---
>  include/libcamera/internal/camera_lens.h |  1 +
>  src/libcamera/camera_lens.cpp            | 18 ++++++++++++++++++
>  2 files changed, 19 insertions(+)
>
> diff --git a/include/libcamera/internal/camera_lens.h b/include/libcamera/internal/camera_lens.h
> index 277417da..48761d68 100644
> --- a/include/libcamera/internal/camera_lens.h
> +++ b/include/libcamera/internal/camera_lens.h
> @@ -27,6 +27,7 @@ public:
>
>  	int init();
>  	int setFocusPosition(int32_t position);
> +	int getFocusCapabilityies();
>
>  	const std::string &model() const { return model_; }
>
> diff --git a/src/libcamera/camera_lens.cpp b/src/libcamera/camera_lens.cpp
> index b3d48199..5d00652d 100644
> --- a/src/libcamera/camera_lens.cpp
> +++ b/src/libcamera/camera_lens.cpp
> @@ -73,6 +73,10 @@ int CameraLens::init()
>  		return ret;
>
>  	model_ = subdev_->model();
> +
> +	ControlList lensCtrls(subdev_->controls());
> +	subdev_->getAttributes(&lensCtrls);
> +
>  	return 0;
>  }
>
> @@ -95,6 +99,20 @@ int CameraLens::setFocusPosition(int32_t position)
>  	return 0;
>  }
>
> +int CameraLens::getFocusCapabilityies()
> +{
> +	ControlValue retVal;
> +	ControlList lensCtrls(subdev_->controls());
> +	int32_t ret = 2023;
> +
> +	lensCtrls.set(V4L2_CID_FOCUS_ABSOLUTE, static_cast<int32_t>(ret));
> +	subdev_->getAttributes(&lensCtrls);
> +	retVal = lensCtrls.get(V4L2_CID_FOCUS_ABSOLUTE);
> +	ret = retVal.get<int32_t>();
> +
> +	return ret;
> +}
> +
>  int CameraLens::validateLensDriver()
>  {
>  	int ret = 0;
> --
> 2.35.1
>
Kate Hsuan April 15, 2022, 3:01 a.m. UTC | #2
Hi Jacopo,

On Thu, Apr 14, 2022 at 4:22 PM Jacopo Mondi <jacopo@jmondi.org> wrote:
>
> Hi Kate,
>
> On Thu, Apr 14, 2022 at 03:43:39PM +0800, Kate Hsuan via libcamera-devel wrote:
> > It allows other components to get the maximum VCM steps. It first creates
> > a control list and set V4L2_CID_FOCUS_ABSOLUTE control to it. Then, it
> > calls a lower layer call, getAttributes() to get the maximum VCM steps
> > from the kernel.
>
> I might have missed something here.
>
> V4L2Device::controls() returns you a ControlInfoMap for all the
> controls registered on the lens subdevice, with the controls' min, max
> and default values collected at subdev open time with
> V4L2Device::listControls()
>
> Is there a reason I have missed about why you need to re-fetch the
> control's limits again ?
>

Ah. I might miss this V4L2Device::listControls(). I could try this in
my v2 patch.

Thank you.

> If you need to collect the V4L2_CID_FOCUS_ABSOLUTE control maximum
> value I think you could very well do so at validateLensDriver() time.
>
> Thanks
>    j
>
> >
> > Signed-off-by: Kate Hsuan<hpa@redhat.com>
> > ---
> >  include/libcamera/internal/camera_lens.h |  1 +
> >  src/libcamera/camera_lens.cpp            | 18 ++++++++++++++++++
> >  2 files changed, 19 insertions(+)
> >
> > diff --git a/include/libcamera/internal/camera_lens.h b/include/libcamera/internal/camera_lens.h
> > index 277417da..48761d68 100644
> > --- a/include/libcamera/internal/camera_lens.h
> > +++ b/include/libcamera/internal/camera_lens.h
> > @@ -27,6 +27,7 @@ public:
> >
> >       int init();
> >       int setFocusPosition(int32_t position);
> > +     int getFocusCapabilityies();
> >
> >       const std::string &model() const { return model_; }
> >
> > diff --git a/src/libcamera/camera_lens.cpp b/src/libcamera/camera_lens.cpp
> > index b3d48199..5d00652d 100644
> > --- a/src/libcamera/camera_lens.cpp
> > +++ b/src/libcamera/camera_lens.cpp
> > @@ -73,6 +73,10 @@ int CameraLens::init()
> >               return ret;
> >
> >       model_ = subdev_->model();
> > +
> > +     ControlList lensCtrls(subdev_->controls());
> > +     subdev_->getAttributes(&lensCtrls);
> > +
> >       return 0;
> >  }
> >
> > @@ -95,6 +99,20 @@ int CameraLens::setFocusPosition(int32_t position)
> >       return 0;
> >  }
> >
> > +int CameraLens::getFocusCapabilityies()
> > +{
> > +     ControlValue retVal;
> > +     ControlList lensCtrls(subdev_->controls());
> > +     int32_t ret = 2023;
> > +
> > +     lensCtrls.set(V4L2_CID_FOCUS_ABSOLUTE, static_cast<int32_t>(ret));
> > +     subdev_->getAttributes(&lensCtrls);
> > +     retVal = lensCtrls.get(V4L2_CID_FOCUS_ABSOLUTE);
> > +     ret = retVal.get<int32_t>();
> > +
> > +     return ret;
> > +}
> > +
> >  int CameraLens::validateLensDriver()
> >  {
> >       int ret = 0;
> > --
> > 2.35.1
> >
>

Patch
diff mbox series

diff --git a/include/libcamera/internal/camera_lens.h b/include/libcamera/internal/camera_lens.h
index 277417da..48761d68 100644
--- a/include/libcamera/internal/camera_lens.h
+++ b/include/libcamera/internal/camera_lens.h
@@ -27,6 +27,7 @@  public:
 
 	int init();
 	int setFocusPosition(int32_t position);
+	int getFocusCapabilityies();
 
 	const std::string &model() const { return model_; }
 
diff --git a/src/libcamera/camera_lens.cpp b/src/libcamera/camera_lens.cpp
index b3d48199..5d00652d 100644
--- a/src/libcamera/camera_lens.cpp
+++ b/src/libcamera/camera_lens.cpp
@@ -73,6 +73,10 @@  int CameraLens::init()
 		return ret;
 
 	model_ = subdev_->model();
+
+	ControlList lensCtrls(subdev_->controls());
+	subdev_->getAttributes(&lensCtrls);
+
 	return 0;
 }
 
@@ -95,6 +99,20 @@  int CameraLens::setFocusPosition(int32_t position)
 	return 0;
 }
 
+int CameraLens::getFocusCapabilityies()
+{
+	ControlValue retVal;
+	ControlList lensCtrls(subdev_->controls());
+	int32_t ret = 2023;
+
+	lensCtrls.set(V4L2_CID_FOCUS_ABSOLUTE, static_cast<int32_t>(ret));
+	subdev_->getAttributes(&lensCtrls);
+	retVal = lensCtrls.get(V4L2_CID_FOCUS_ABSOLUTE);
+	ret = retVal.get<int32_t>();
+
+	return ret;
+}
+
 int CameraLens::validateLensDriver()
 {
 	int ret = 0;