summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorNiklas Söderlund <niklas.soderlund@ragnatech.se>2020-07-15 17:31:46 +0200
committerNiklas Söderlund <niklas.soderlund@ragnatech.se>2020-08-05 20:07:13 +0200
commitf23e6127ad073a99d4374929f95aac9d3f24dba8 (patch)
tree112c84da0ecf4a12a42322a592e39baa8f2c0ae8 /src
parent1869d1b312e27cd34bb837b61ff674532afbc842 (diff)
libcamera: camera_sensor: Generate a sensor ID
The ID is generated from information in the firmware description of the sensor if available or from module and model information if the sensor is virtual (for example VIMC). Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se> Reviewed-by: Jacopo Mondi <jacopo@jmondi.org> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Diffstat (limited to 'src')
-rw-r--r--src/libcamera/camera_sensor.cpp31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/libcamera/camera_sensor.cpp b/src/libcamera/camera_sensor.cpp
index 350f49ac..79b2bc40 100644
--- a/src/libcamera/camera_sensor.cpp
+++ b/src/libcamera/camera_sensor.cpp
@@ -13,10 +13,12 @@
#include <limits.h>
#include <math.h>
#include <regex>
+#include <string.h>
#include <libcamera/property_ids.h>
#include "libcamera/internal/formats.h"
+#include "libcamera/internal/sysfs.h"
#include "libcamera/internal/utils.h"
/**
@@ -204,6 +206,11 @@ int CameraSensor::init()
if (ret < 0)
return ret;
+ /* Generate a unique ID for the sensor. */
+ ret = generateId();
+ if (ret)
+ return ret;
+
/* Retrieve and store the camera sensor properties. */
const ControlInfoMap &controls = subdev_->controls();
int32_t propertyValue;
@@ -541,4 +548,28 @@ std::string CameraSensor::logPrefix() const
return "'" + entity_->name() + "'";
}
+int CameraSensor::generateId()
+{
+ const std::string devPath = subdev_->devicePath();
+
+ /* Try to get ID from firmware description. */
+ id_ = sysfs::firmwareNodePath(devPath);
+ if (!id_.empty())
+ return 0;
+
+ /*
+ * Virtual sensors not described in firmware
+ *
+ * Verify it's a platform device and construct ID from the deive path
+ * and model of sensor.
+ */
+ if (devPath.find("/sys/devices/platform/", 0) == 0) {
+ id_ = devPath.substr(strlen("/sys/devices/")) + " " + model();
+ return 0;
+ }
+
+ LOG(CameraSensor, Error) << "Can't generate sensor ID";
+ return -EINVAL;
+}
+
} /* namespace libcamera */