diff --git a/include/libcamera/internal/camera_sensor.h b/include/libcamera/internal/camera_sensor.h
index 06c8292ca30129de..0f65fca46877e89a 100644
--- a/include/libcamera/internal/camera_sensor.h
+++ b/include/libcamera/internal/camera_sensor.h
@@ -67,11 +67,14 @@ protected:
 	std::string logPrefix() const override;
 
 private:
+	int generateId();
+
 	const MediaEntity *entity_;
 	std::unique_ptr<V4L2Subdevice> subdev_;
 	unsigned int pad_;
 
 	std::string model_;
+	std::string id_;
 
 	V4L2Subdevice::Formats formats_;
 	Size resolution_;
diff --git a/src/libcamera/camera_sensor.cpp b/src/libcamera/camera_sensor.cpp
index 350f49accad99c7b..695c4ad0028d5c4c 100644
--- a/src/libcamera/camera_sensor.cpp
+++ b/src/libcamera/camera_sensor.cpp
@@ -9,6 +9,7 @@
 
 #include <algorithm>
 #include <float.h>
+#include <fstream>
 #include <iomanip>
 #include <limits.h>
 #include <math.h>
@@ -16,7 +17,9 @@
 
 #include <libcamera/property_ids.h>
 
+#include "libcamera/internal/file.h"
 #include "libcamera/internal/formats.h"
+#include "libcamera/internal/sysfs.h"
 #include "libcamera/internal/utils.h"
 
 /**
@@ -204,6 +207,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 +549,33 @@ 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.rfind("/sys/devices/platform/", 0) == 0) {
+		id_ = devPath + " " + model();
+
+		static const std::string dropStr = "/sys/devices/";
+		if (id_.find(dropStr) == 0)
+			id_.erase(0, dropStr.length());
+
+		return 0;
+	}
+
+	LOG(CameraSensor, Error) << "Can't generate sensor ID";
+	return -EINVAL;
+}
+
 } /* namespace libcamera */
