From patchwork Thu May 26 13:30:25 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 16063 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 66B6EBD160 for ; Thu, 26 May 2022 13:30:38 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 7A8AC611BF; Thu, 26 May 2022 15:30:37 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1653571837; bh=cuC721V7+su2w+pfJvMWBlbx9mL910pdlbQCvaiCREg=; h=To:Date:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=uM2QUrUlZo2pmRm5/AU3tWgt4rA/XZvo2k42KHQy43EytNUG41huFHe40M5rC9VD7 oTZvp/ClGem+aLStCaPsAY7kfB+VOML78GQLSgDeAiwGjD4YCB61Xuq62tCwu+Z6rg zTR0rCvRwk1rcBp/OYlC9j1McnzebpCuU6PLoqKD1fmJZ6tX2E+ll0hZvT9CV2K1o5 a0/P4vPqc9wKQ6kv+m6RrNfPPzoo44KSVUYx4ahZa//p2spJvlHDqszu8lsMQuO0D2 YwQ6fmu6ThuZ6bSh19e1nUdfLs0ZuQsmqEmfDeXa3br5aAUUiyuusnrhjgM7iglgKq w1tlwLYV5TzGw== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 8DC8060DB0 for ; Thu, 26 May 2022 15:30:35 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="uEpT+Xln"; dkim-atps=neutral Received: from pendragon.lan (unknown [37.120.212.14]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id C9CA56D4; Thu, 26 May 2022 15:30:34 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1653571835; bh=cuC721V7+su2w+pfJvMWBlbx9mL910pdlbQCvaiCREg=; h=From:To:Cc:Subject:Date:From; b=uEpT+XlnVfX46heWj3CmLWtRjmzaKEiyfpwbdgoc3gHDOQxyzwHYpJrVkPoh2qZqL yt9VEPjcpGIYEusmVxqy/20KSOr2eWSXavgvWL833hnlq4MnRONl6DS7Iit6djmVL3 kSylkIq6GHcVJcE8LHnbsJKyulLV1MpsIkgkEp5I= To: libcamera-devel@lists.libcamera.org Date: Thu, 26 May 2022 16:30:25 +0300 Message-Id: <20220526133025.18746-1-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.35.1 MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH] libcamera: pipeline: uvcvideo: Infer camera location from removable attribute X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Laurent Pinchart via libcamera-devel From: Laurent Pinchart Reply-To: Laurent Pinchart Cc: George Kiagiadakis Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Use the removable attribute exposed by the USB device in sysfs to infer if the camera is an external (when removable) or front (when non-removable) camera. This is likely not perfect as the removable attribute is derived from ACPI data which may not always be accurate, and non-ACPI platforms likely report all devices as removable. Still, this is a first step upon which a better method could be built. Signed-off-by: Laurent Pinchart Reviewed-by: Kieran Bingham Reviewed-by: Paul Elder Tested-by: George Kiagiadakis --- src/libcamera/pipeline/uvcvideo/uvcvideo.cpp | 33 +++++++++++++++++--- 1 file changed, 28 insertions(+), 5 deletions(-) base-commit: f8e4649680303ce9b7dace5ad1344fcb450013ac prerequisite-patch-id: edbf31ed9d7f5374e17b34936fe1aa8dea2eac44 diff --git a/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp b/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp index 2ebf2788c3b4..53b2f23ab029 100644 --- a/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp +++ b/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp @@ -501,13 +501,36 @@ int UVCCameraData::init(MediaDevice *media) video_->bufferReady.connect(this, &UVCCameraData::bufferReady); - /* - * \todo Find a way to tell internal and external UVC cameras apart. - * Until then, treat all UVC cameras as external. - */ - properties_.set(properties::Location, properties::CameraLocationExternal); properties_.set(properties::Model, utils::toAscii(media->model())); + /* + * Derive the location from the device removable attribute in sysfs. + * Non-removable devices are assumed to be front as we lack detailed + * location information, and removable device are considered external. + * + * The sysfs removable attribute is derived from the ACPI _UPC attribute + * if available, or from the USB hub descriptors otherwise. ACPI data + * may not be very reliable, and the USB hub descriptors may not be + * accurate on DT-based platforms. A heuristic may need to be + * implemented later if too many devices end up being miscategorized. + * + * \todo Find a way to tell front and back devices apart. This could + * come from the ACPI _PLD, but that may be even more unreliable than + * the _UPC. + */ + properties::LocationEnum location = properties::CameraLocationExternal; + std::ifstream file(video_->devicePath() + "/../removable"); + if (file.is_open()) { + std::string value; + std::getline(file, value); + file.close(); + + if (value == "fixed") + location = properties::CameraLocationFront; + } + + properties_.set(properties::Location, location); + /* * Get the current format in order to initialize the sensor array * properties.