[libcamera-devel] [PATCH 3/5] libcamera: ipu3-cio2: Discover VCMs through ancillary links
Daniel Scally
djrscally at gmail.com
Fri Nov 26 01:31:16 CET 2021
Rather than attempting to discover VCMs via model name matching we
should follow the ancillary links that define the relationship
between the two devices to locate any entities linked to the sensor.
Where we have linked entities with the function MEDIA_ENT_F_LENS we
can then create an instance of CameraLens to represent it.
Signed-off-by: Daniel Scally <djrscally at gmail.com>
---
Alternatively rather than replace the matching on model names we could try
the ancillary links first and then simply guard the existing model matching
with an if (!lens_) ...
src/libcamera/pipeline/ipu3/cio2.cpp | 45 +++++++++++++++-------------
1 file changed, 25 insertions(+), 20 deletions(-)
diff --git a/src/libcamera/pipeline/ipu3/cio2.cpp b/src/libcamera/pipeline/ipu3/cio2.cpp
index 59b2f586..169e7b54 100644
--- a/src/libcamera/pipeline/ipu3/cio2.cpp
+++ b/src/libcamera/pipeline/ipu3/cio2.cpp
@@ -161,30 +161,35 @@ int CIO2Device::init(const MediaDevice *media, unsigned int index)
}
/*
- * \todo Read the lens model from the sensor itself or from a device
- * database. For now use default values taken from ChromeOS database.
+ * Sensors sometimes have ancillary devices such as a Lens or Flash
+ * that could be linked to the MediaEntity - search for and handle
+ * any such device (for now, we can only handle MEDIA_ENT_F_LENS)
+ *
+ * \todo Handle MEDIA_ENT_F_FLASH too.
*/
- static std::unordered_map<std::string, std::string> sensorLens = {
- { "ov13858", "dw9714" },
- { "imx258", "dw9807" },
- { "imx355", "ak7375" }
- };
-
- auto it = sensorLens.find(sensor_->model());
- if (it != sensorLens.end()) {
- const std::vector<MediaEntity *> &entities = media->entities();
- for (auto ent : entities) {
- if (ent->function() == MEDIA_ENT_F_LENS) {
- lens_ = std::make_unique<CameraLens>(ent);
+ const std::vector<MediaLink *> &ancillary_links = sensorEntity->ancillary_links();
+ if (!ancillary_links.empty()) {
+ for (auto it : ancillary_links) {
+ MediaEntity *ancillaryEntity = it->ancillary();
+
+ switch (ancillaryEntity->function()) {
+ case MEDIA_ENT_F_LENS:
+ lens_ = std::make_unique<CameraLens>(ancillaryEntity);
ret = lens_->init();
- if (!ret && lens_->model() == it->second) {
- break;
+ if (ret) {
+ LOG(IPU3, Error)
+ << "Error during CameraLens init";
+ return ret;
}
- lens_.reset();
+ break;
+ case MEDIA_ENT_F_FLASH:
+ LOG(IPU3, Warning)
+ << "Flash not yet supported";
+ break;
+ default:
+ LOG(IPU3, Warning)
+ << "Unsupported entity function";
}
- if (!lens_)
- LOG(IPU3, Warning) << "Lens device "
- << it->second << " not found";
}
}
--
2.25.1
More information about the libcamera-devel
mailing list