From patchwork Wed Oct 4 07:19:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Volodymyr Kharuk X-Patchwork-Id: 13408286 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4BEBDE8FDD1 for ; Wed, 4 Oct 2023 07:20:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241453AbjJDHUC (ORCPT ); Wed, 4 Oct 2023 03:20:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35976 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229577AbjJDHUC (ORCPT ); Wed, 4 Oct 2023 03:20:02 -0400 Received: from mail-ej1-x62b.google.com (mail-ej1-x62b.google.com [IPv6:2a00:1450:4864:20::62b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B0D78AD for ; Wed, 4 Oct 2023 00:19:58 -0700 (PDT) Received: by mail-ej1-x62b.google.com with SMTP id a640c23a62f3a-9b2f73e3af3so308940866b.3 for ; Wed, 04 Oct 2023 00:19:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=melexis.com; s=google; t=1696403997; x=1697008797; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Ew1c9NXug8ctY4MLl60wGEzXYZjlRdO90T8KbwkWmwo=; b=SN4SASU2IrcaUNcqb1Yrkf2oKD+c8Kxpy2ClJDx/LXjqUFCg7dufsYD3pmYXrsqsuQ LxFc/UUaG+kWVHhqCKHjmA7JsBj6VT/T3IxpXJRFic/J6iBubZM2F6vwaHvAjKGK9rcy AZ2RnDJOCsoeGP24FviJazHZcu29nrZIGEfJvnZlkqFrgW4vnGs6XwT+9gtBJFrl0oYF zHMfYOepwzmPEJLsDKOJw1JparQEDDth1OGeEOHijwOBIX8r2Z2fTbpEcoEAzU7uWcEe 2Km0c+5QmRoDBFCkJpOF+PQdQUf9K8qTktE4xVL34MprVOhSI5SDQIUGxqBhfYjJ9qwm 5DLw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696403997; x=1697008797; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Ew1c9NXug8ctY4MLl60wGEzXYZjlRdO90T8KbwkWmwo=; b=e5yl7R5q8TH48LXBw2nb1pp5rlGXqpSeNWXgiVXCCEIpA+qYRP7qVA7iKp7Cm2kl90 Pb77S49p9kK9hHdSDFOd+hcvnGSRZ/yDAQEdotsLtOqzOhjAzqV/XkQW5vJk8CRrNj5c Ou342WPK+/MdF1qiyJr8ayvJXIEUpqCVyMe3CV+vF+E4kY6vvVDatn2QJ02a+Gcn3vKm CGD1hj36QcOL82CsA8aynt04VDa1WhtTYZRx5xBblmlxqEUkeUFI4A41BivtclUOcPR3 VZuCVrDVdCYRRBfoOqHAwAm8eUAxsYG8pfXBc3TWdR4tnaASjKrkelKz/GLt3CsGVDmo qIlw== X-Gm-Message-State: AOJu0Ywa7hYPQZjQW0mNbgw71eIUPqWrkf2cMM2H3f7hsgsgK9MDcKdC 6593jHMVFUgmi3ccOytLZTuryJI1GPMMTl5TzswebCe0OOEiy8eeVgDgaRURZX3PO+BaGy6O6v8 UbTd+bvfs/1MhJPSyRgtWE2vhYpijLUgP3/QQiQn9OxX0eT3+9l5cx8KSSWOtd0iC1rBYgaqzxa tNww== X-Google-Smtp-Source: AGHT+IGTV+fX27y5K0VvWm4l1aaWyZkbH6zZ5AACaUBxJ1PXxAQRmjzelUSeasRbsRczHLFso00LUg== X-Received: by 2002:a17:906:3081:b0:9ae:73ca:bbad with SMTP id 1-20020a170906308100b009ae73cabbadmr1182656ejv.43.1696403997208; Wed, 04 Oct 2023 00:19:57 -0700 (PDT) Received: from melexis ([91.192.181.19]) by smtp.gmail.com with ESMTPSA id sa18-20020a170906edb200b009adc77330ebsm2313242ejb.199.2023.10.04.00.19.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Oct 2023 00:19:56 -0700 (PDT) From: Volodymyr Kharuk To: Cc: Andrii Kyselov , Mauro Carvalho Chehab , Rob Herring , Krzysztof Kozlowski , Laurent Pinchart , devicetree@vger.kernel.org, Hans Verkuil , Sakari Ailus , Benjamin Mugnier , Volodymyr Kharuk Subject: [PATCH v5 1/8] media: uapi: ctrls: Add Time of Flight class controls Date: Wed, 4 Oct 2023 10:19:40 +0300 Message-Id: <3d1a6a49790a699980dc02450ebdbac2a03ebb51.1696347109.git.vkh@melexis.com> X-Mailer: git-send-email 2.38.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org Define Time of Flight class controls. Also add most common TOF controls: - phase sequence - time integration - frequency modulation Signed-off-by: Volodymyr Kharuk Acked-by: Benjamin Mugnier --- include/uapi/linux/v4l2-controls.h | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/include/uapi/linux/v4l2-controls.h b/include/uapi/linux/v4l2-controls.h index c3604a0a3e30..92b3957d5720 100644 --- a/include/uapi/linux/v4l2-controls.h +++ b/include/uapi/linux/v4l2-controls.h @@ -30,6 +30,7 @@ #define V4L2_CTRL_CLASS_DETECT 0x00a30000 /* Detection controls */ #define V4L2_CTRL_CLASS_CODEC_STATELESS 0x00a40000 /* Stateless codecs controls */ #define V4L2_CTRL_CLASS_COLORIMETRY 0x00a50000 /* Colorimetry controls */ +#define V4L2_CTRL_CLASS_TOF 0x00a60000 /* Time of flight camera controls */ /* User-class control IDs */ @@ -3479,6 +3480,13 @@ struct v4l2_ctrl_av1_film_grain { __u8 reserved[4]; }; +#define V4L2_CID_TOF_CLASS_BASE (V4L2_CTRL_CLASS_TOF | 0x900) +#define V4L2_CID_TOF_CLASS (V4L2_CTRL_CLASS_TOF | 1) + +#define V4L2_CID_TOF_PHASE_SEQ (V4L2_CID_TOF_CLASS_BASE + 0) +#define V4L2_CID_TOF_FREQ_MOD (V4L2_CID_TOF_CLASS_BASE + 1) +#define V4L2_CID_TOF_TIME_INTEGRATION (V4L2_CID_TOF_CLASS_BASE + 2) + /* MPEG-compression definitions kept for backwards compatibility */ #ifndef __KERNEL__ #define V4L2_CTRL_CLASS_MPEG V4L2_CTRL_CLASS_CODEC From patchwork Wed Oct 4 07:19:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Volodymyr Kharuk X-Patchwork-Id: 13408287 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6ABE6E8FDD1 for ; Wed, 4 Oct 2023 07:20:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241495AbjJDHUG (ORCPT ); Wed, 4 Oct 2023 03:20:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35984 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229577AbjJDHUF (ORCPT ); Wed, 4 Oct 2023 03:20:05 -0400 Received: from mail-ed1-x52b.google.com (mail-ed1-x52b.google.com [IPv6:2a00:1450:4864:20::52b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 22E43AD for ; Wed, 4 Oct 2023 00:20:01 -0700 (PDT) Received: by mail-ed1-x52b.google.com with SMTP id 4fb4d7f45d1cf-5230a22cfd1so3076597a12.1 for ; Wed, 04 Oct 2023 00:20:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=melexis.com; s=google; t=1696403999; x=1697008799; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=/mfgoglfeGFCoHfbanPa/H8wXTI3NZ4ZqArZW3xtr/0=; b=rt17l19jAN4ccAkbLfZVOC6FSBLibKSmgemkb4fwylkXRSzSDXdRwLVsaJITzogTSw vMREkibPHo6gpuhIXacHSNcvV4YA+5RyBf5vuZBJI+6AdwaerfyGNyoHNe1OcQjSvLmV QUGteRYFZgRKQi1pXg7lus5YRZkL8L0hHw0jFiugJRCaQDyjuJFYfV37fqfncqiL05UM 4LLnvTLYq7WQTVRyV0YL1Tn408yi/qqeY3/LYCl5QxbXGIp/EdUS1/2KufA3Gf7d8+7D wCUYjwpX9LIbuqLWs1wndPjMdQf/j2BRivN1NKlXze1GsYNlR1isQu6xhISlR5jcs26T ZydA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696403999; x=1697008799; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=/mfgoglfeGFCoHfbanPa/H8wXTI3NZ4ZqArZW3xtr/0=; b=aiccb4tXVLjRx5saNSThoOG1qt3/eVeLeQwUeAEm/X3z+q9WHGOLSNM/QdezezxWGn a0KM7IUC3iFv2satnlfDnC6jrvvZkdTf7I5Zpm6C03TYpf9F/SDhTgGxTJSc6bHqjItk V9pNA8h5GfBxJ3QnDLzCmNtaHaDF0ih5LtPtIDNNI4dswpRjis2HPYzdNGgfjoQanL7r AzraYQsF8gTTLzz58DGm52DcHgz8slFXqVoZrVt6Mh0x8PMCqbEMBKJ2F45lywnocPg2 pm3g0wE8BoFgH09Z2mh2ZiREIF+C8RWoevzhUXCEwQW4pBpC/Jv6KzDwYG/3AKev6sa4 kVAw== X-Gm-Message-State: AOJu0Yy9eoAXFDbmJ3uyOEW+CD1cU18CHVa337bbrHuMOQAwcp3AmIDN eiqP4gPgpfVc4eKk0DqW1+iaYKwdmBOquHNL2G1IJSOG9cAuYOA1GsCtLriTWwTiy/oNdyRE2U7 p1H9E5q0C0aJUzap9WU46qhwTuXV0ect8+akESnq8KJsDcQdiaZnb5Gx129+KBy7haPC3EMsMIT oRKA== X-Google-Smtp-Source: AGHT+IGFKv2t432yf7YQ2NfZ2n4IpnXlJvqPJqLIoQ3uD4NTz80An4fzbikurPClEE/qlJfT2l45Bw== X-Received: by 2002:a17:906:2210:b0:9b2:8323:d916 with SMTP id s16-20020a170906221000b009b28323d916mr1345909ejs.17.1696403999535; Wed, 04 Oct 2023 00:19:59 -0700 (PDT) Received: from melexis ([91.192.181.19]) by smtp.gmail.com with ESMTPSA id op19-20020a170906bcf300b009adc743340fsm2258027ejb.197.2023.10.04.00.19.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Oct 2023 00:19:59 -0700 (PDT) From: Volodymyr Kharuk To: Cc: Andrii Kyselov , Mauro Carvalho Chehab , Rob Herring , Krzysztof Kozlowski , Laurent Pinchart , devicetree@vger.kernel.org, Hans Verkuil , Sakari Ailus , Benjamin Mugnier , Volodymyr Kharuk Subject: [PATCH v5 2/8] media: v4l: ctrls: Fill V4L2_CID_TOF_CLASS controls Date: Wed, 4 Oct 2023 10:19:41 +0300 Message-Id: <4e4a0c7520ea3e77ddf288ed6ceb1be100e53acd.1696347109.git.vkh@melexis.com> X-Mailer: git-send-email 2.38.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org Define names, flags and types of TOF controls. *dims* is driver specific. It also means, that it is not possible to use new_std for arrays. Signed-off-by: Volodymyr Kharuk Acked-by: Benjamin Mugnier --- drivers/media/v4l2-core/v4l2-ctrls-defs.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/drivers/media/v4l2-core/v4l2-ctrls-defs.c b/drivers/media/v4l2-core/v4l2-ctrls-defs.c index 8696eb1cdd61..63fcd0d8f139 100644 --- a/drivers/media/v4l2-core/v4l2-ctrls-defs.c +++ b/drivers/media/v4l2-core/v4l2-ctrls-defs.c @@ -1242,6 +1242,13 @@ const char *v4l2_ctrl_get_name(u32 id) case V4L2_CID_COLORIMETRY_CLASS: return "Colorimetry Controls"; case V4L2_CID_COLORIMETRY_HDR10_CLL_INFO: return "HDR10 Content Light Info"; case V4L2_CID_COLORIMETRY_HDR10_MASTERING_DISPLAY: return "HDR10 Mastering Display"; + + /* Time of light camera controls */ + /* Keep the order of the 'case's the same as in v4l2-controls.h! */ + case V4L2_CID_TOF_CLASS: return "Time of Flight Camera Controls"; + case V4L2_CID_TOF_PHASE_SEQ: return "TOF Phase Sequence"; + case V4L2_CID_TOF_FREQ_MOD: return "TOF Frequency Modulation"; + case V4L2_CID_TOF_TIME_INTEGRATION: return "TOF Time Integration"; default: return NULL; } @@ -1451,6 +1458,7 @@ void v4l2_ctrl_fill(u32 id, const char **name, enum v4l2_ctrl_type *type, case V4L2_CID_DETECT_CLASS: case V4L2_CID_CODEC_STATELESS_CLASS: case V4L2_CID_COLORIMETRY_CLASS: + case V4L2_CID_TOF_CLASS: *type = V4L2_CTRL_TYPE_CTRL_CLASS; /* You can neither read nor write these */ *flags |= V4L2_CTRL_FLAG_READ_ONLY | V4L2_CTRL_FLAG_WRITE_ONLY; @@ -1602,6 +1610,18 @@ void v4l2_ctrl_fill(u32 id, const char **name, enum v4l2_ctrl_type *type, case V4L2_CID_COLORIMETRY_HDR10_MASTERING_DISPLAY: *type = V4L2_CTRL_TYPE_HDR10_MASTERING_DISPLAY; break; + case V4L2_CID_TOF_PHASE_SEQ: + *type = V4L2_CTRL_TYPE_U16; + *flags |= V4L2_CTRL_FLAG_DYNAMIC_ARRAY; + break; + case V4L2_CID_TOF_FREQ_MOD: + *type = V4L2_CTRL_TYPE_U32; + *flags |= V4L2_CTRL_FLAG_DYNAMIC_ARRAY; + break; + case V4L2_CID_TOF_TIME_INTEGRATION: + *type = V4L2_CTRL_TYPE_U16; + *flags |= V4L2_CTRL_FLAG_DYNAMIC_ARRAY; + break; default: *type = V4L2_CTRL_TYPE_INTEGER; break; From patchwork Wed Oct 4 07:19:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Volodymyr Kharuk X-Patchwork-Id: 13408288 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 48E01E8FDD4 for ; Wed, 4 Oct 2023 07:20:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241497AbjJDHUI (ORCPT ); Wed, 4 Oct 2023 03:20:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36000 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229577AbjJDHUH (ORCPT ); Wed, 4 Oct 2023 03:20:07 -0400 Received: from mail-ej1-x633.google.com (mail-ej1-x633.google.com [IPv6:2a00:1450:4864:20::633]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 88D21B4 for ; Wed, 4 Oct 2023 00:20:03 -0700 (PDT) Received: by mail-ej1-x633.google.com with SMTP id a640c23a62f3a-9ad8a822508so325466866b.0 for ; Wed, 04 Oct 2023 00:20:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=melexis.com; s=google; t=1696404002; x=1697008802; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=imCZDPmKhvVM5uCss54/MVO/bMAfcXA+npTIcf/0h0w=; b=iBRyId7TO5HeRByR58oUeIYOaPX/X1NcxR3yr/EtkGS+cfdkG+bK2kD0vJq9Xy4Esr bxQG12E7ajBKgPxXUMRL0IQPZhYwVzg2hje++Oz32jfRLR5ecmwuCgByjpTqXLsJD0dU KMFdg6QkioAZHI7LukwZZC4/2Ul2UlSHzGCoD/nizoR4T1JUUO6Z9PWTr1ezXXfOphWd 4aW7n8k7DEN03SV3UqQJcbitXupCxFPGQD4gw2inu9yyvfWfOvNRMHhto292CSMJbsw4 xTSBO2tBX/Jlzgq43EOpHtCXhhkGn0B639faR/KxtE/V2RhSNKmZpOmH7pSW5/5cWTdo /XzQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696404002; x=1697008802; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=imCZDPmKhvVM5uCss54/MVO/bMAfcXA+npTIcf/0h0w=; b=O9FNryxBJbSWgXwgU6kgCo2fIYrUJLI1plewWALXVct2/Hdv8/glSjWWHRytHpbr4h 6xI4Pgcvey8tRivdOISRYubPyA7AUjWM08y/HG7tQIlo76TZnuaZjlPbYZaXiBCAYnbE nDQslxVy1eJkGEUOfKXaKB01Ss3R6s0YaKY7/ATo0hrrEQ9BYKpAjM5AU4euuvEGaUPz kiecNzSqP3xSiV1tlemOC3xtdy0kZgZTXTIpOZjRPLH8IQEJPlnVPsw5txrkbb8Sjv3Z xYkwp+GyUP3zkKPug/GWEmsVP8D64eYf0MDW++uPahbmpzZnaUUUGt6qX87TZ+xB4uml 3GEg== X-Gm-Message-State: AOJu0Yxg8v2Dm1CXikoJy03dBDTUQ8kyIlIU9rOq2iFrGg+njwiXLaRo ZdF9a5IdY3T2x0zTqhN88uqcWoh5+b4ZqTAPvak2oXAfvR75N87rz0aVna2E7iH8Uf4ye1xQ3NX wD6FgcoVuUCcI5Mn4ZoqhM1Rp0+7k82jrpuZixcZqxJDjCLnnsiJQVFH3U/7ZpsEF4/cQIoSN6f 1veg== X-Google-Smtp-Source: AGHT+IFMm8w0C4PCwzMFMnjGndx3ZM5io7F841AB/gBJW5UhU2tXXwWRKLFJ62oDLGZU4EhQcnmaDw== X-Received: by 2002:a17:906:1ba9:b0:9ae:57b8:ad1b with SMTP id r9-20020a1709061ba900b009ae57b8ad1bmr1194421ejg.21.1696404001814; Wed, 04 Oct 2023 00:20:01 -0700 (PDT) Received: from melexis ([91.192.181.19]) by smtp.gmail.com with ESMTPSA id 11-20020a170906058b00b009add084a00csm2285935ejn.36.2023.10.04.00.20.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Oct 2023 00:20:01 -0700 (PDT) From: Volodymyr Kharuk To: Cc: Andrii Kyselov , Mauro Carvalho Chehab , Rob Herring , Krzysztof Kozlowski , Laurent Pinchart , devicetree@vger.kernel.org, Hans Verkuil , Sakari Ailus , Benjamin Mugnier , Volodymyr Kharuk Subject: [PATCH v5 3/8] media: Documentation: v4l: Add TOF class controls Date: Wed, 4 Oct 2023 10:19:42 +0300 Message-Id: <4f8f84b835e15c17e2277f1f76f073aa3901ed73.1696347109.git.vkh@melexis.com> X-Mailer: git-send-email 2.38.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org Add description about V4L2_CID_TOF_PHASE_SEQ, V4L2_CID_TOF_FMOD and V4L2_CID_TOF_TINT. Also updated MAINTAINERS with new ext-ctrls-tof file. Signed-off-by: Volodymyr Kharuk Acked-by: Benjamin Mugnier --- .../userspace-api/media/v4l/common.rst | 1 + .../userspace-api/media/v4l/ext-ctrls-tof.rst | 56 +++++++++++++++++++ MAINTAINERS | 7 +++ 3 files changed, 64 insertions(+) create mode 100644 Documentation/userspace-api/media/v4l/ext-ctrls-tof.rst diff --git a/Documentation/userspace-api/media/v4l/common.rst b/Documentation/userspace-api/media/v4l/common.rst index ea0435182e44..1ea79e453066 100644 --- a/Documentation/userspace-api/media/v4l/common.rst +++ b/Documentation/userspace-api/media/v4l/common.rst @@ -52,6 +52,7 @@ applicable to all devices. ext-ctrls-fm-rx ext-ctrls-detect ext-ctrls-colorimetry + ext-ctrls-tof fourcc format planar-apis diff --git a/Documentation/userspace-api/media/v4l/ext-ctrls-tof.rst b/Documentation/userspace-api/media/v4l/ext-ctrls-tof.rst new file mode 100644 index 000000000000..fd8969d3d354 --- /dev/null +++ b/Documentation/userspace-api/media/v4l/ext-ctrls-tof.rst @@ -0,0 +1,56 @@ +.. SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later + +.. _tof-controls: + +*************************************** +Time of Flight Camera Control Reference +*************************************** + +The Time of Flight class includes controls for digital features +of the TOF sensor. + +TOF sensor is a receiver chip. Each pixel in the sensor measures the travel time +of light to that pixel and hence the distance to the object seen by that pixel. +There are different types of TOF sensors. Direct TOF sensors (also known +as Lidars) send a single pulse and measure direct time of flight. +Another type of TOF is indirect TOF sensors, which emit continuous wave +(could be radio or infrared) and then measure phase shift of reflected light. +The sensor modulates outgoing light and then collects reflected photons +as an electric charge with modulated pattern. Knowing the frequency of +the pattern you can calculate the real distance. + +For more information about TOF sensors see +`TOF `__ from Wikipedia. +Also, there are other nice explanations from vendors about indirect TOF: +`Microsoft `__, +`Melexis `__, +`TI `__. + +.. _tof-control-id: + +Time of Flight Camera Control IDs +================================= + +``V4L2_CID_TOF_CLASS (class)`` + The TOF class descriptor. Calling :ref:`VIDIOC_QUERYCTRL` for + this control will return a description of this control class. + +``V4L2_CID_TOF_PHASE_SEQ (dynamic array u16)`` + Change the shift between illumination and sampling for each phase + in degrees. The distance / amplitude (confidence) pictures are obtained + by merging 3..8 captures of the same scene using different phase shifts + (some TOF sensors use different frequency modulations). + + The size of dynamic array specify the number of captures. + Also driver may decide whether V4L2_CID_TOF_FREQ_MOD and + V4L2_CID_TOF_TIME_INTEGRATION should change the number + of captures or rely on V4L2_CID_TOF_PHASE_SEQ control. + The maximum size of the array is driver specific. + +``V4L2_CID_TOF_FREQ_MOD (dynamic array u32)`` + The control sets the modulation frequency (in Hz) for each phase. + The maximum array size is driver specific. + +``V4L2_CID_TOF_TIME_INTEGRATION (dynamic array u16)`` + The control sets the integration time (in us) for each phase. + The maximum array size is driver specific. diff --git a/MAINTAINERS b/MAINTAINERS index 90f13281d297..83e325e273dc 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -13557,6 +13557,13 @@ S: Supported W: http://www.melexis.com F: drivers/iio/temperature/mlx90632.c +MELEXIS MLX7502X DRIVER +M: Volodymyr Kharuk +L: linux-media@vger.kernel.org +S: Supported +W: http://www.melexis.com +F: Documentation/userspace-api/media/v4l/ext-ctrls-tof.rst + MELFAS MIP4 TOUCHSCREEN DRIVER M: Sangwon Jee S: Supported From patchwork Wed Oct 4 07:19:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Volodymyr Kharuk X-Patchwork-Id: 13408289 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B07C6E8FDD5 for ; Wed, 4 Oct 2023 07:20:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241499AbjJDHUL (ORCPT ); Wed, 4 Oct 2023 03:20:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57044 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241498AbjJDHUK (ORCPT ); Wed, 4 Oct 2023 03:20:10 -0400 Received: from mail-ej1-x629.google.com (mail-ej1-x629.google.com [IPv6:2a00:1450:4864:20::629]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3DD3EB7 for ; Wed, 4 Oct 2023 00:20:07 -0700 (PDT) Received: by mail-ej1-x629.google.com with SMTP id a640c23a62f3a-9ad8a822508so325475966b.0 for ; Wed, 04 Oct 2023 00:20:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=melexis.com; s=google; t=1696404006; x=1697008806; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Kzcwo4ukmDfPKZy6rdPKwwlEPxVpUKsKZT5Uwd7WsXc=; b=M02FXBLh7ejXwXu/TsjlZzku+dalAqqtUj95FPBxHRJaSmRB0BgIwNik3ZGvnHACa4 vHhJrYmQ0r8dVpi2oOs74UQJ8f/bN6+Yh/jMBEByV+vZxXZrc6R4kSJPUn/lMU/uJ4ME s0MQSiA7xwjGdTZcNyy7/XVkszfw64j+/ix8Lgp5AR5rfTBCPHZi3vzazZ3eCeOFSZBK +Ei0XisDCmxdjg71f/0ydPHnnBGeKWRdUrE/ZxdREKfkheolXWHOI2SeQMuNlBmwuFRP V6mLMWYXtBJQFoDvdzEuJqb6nwRodIPCh/Aeot7YJSKq4FVOK36RoqnZjrv6B+R2zvPq 3lGw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696404006; x=1697008806; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Kzcwo4ukmDfPKZy6rdPKwwlEPxVpUKsKZT5Uwd7WsXc=; b=Wb4KLbdYpyKRLPYr/4CVwL76FpvUwIvyUFyFnBs8AQLRTS9b8aB9Dd3124bTw+nkNQ mkC1AUBYt1Ikh9j1TlYUkP+6+Kgyn6PEfpy1MfBnI82TeLfrv7IVoajsJdAAX51wThX5 ncz9MXWJW30uOj8psH3ixSrDf3J8Cw33xBN30MUZJzok4qlFBOcL60QKY23HbGFhIwAW HdM7TRjGk9TVW/d8cLvOP4DIQ/e3+hM8I8aGxkQwyFUDvtx2aetnYDxjnKTFWsROpgNz Zfn/nvQZ3a1jDNYrDhKkSimPEOO/29DmoOrIeG3cEssC2j/62wrb3dRELCrP91qY7ylV MY2g== X-Gm-Message-State: AOJu0YwZbruvK6BffuTjf+BemY2shxw0G7Pf+v7niXwd7PygvjuLUPa4 E6sQngwnEg//iv4tmrlpcKkMZzhgbeQs5zaGiNHHY8xNAXaEtWOSGJXCjJejLpgCJfCVCjhSlDY bACJZq+QIm6VBgqse2q4sEMj2PxhevudfLADBKiIeJJA8XU/01BAFL6mlrHZhajCpll9pRVsqWd 6B8g== X-Google-Smtp-Source: AGHT+IE5xYr03nXNv+eAduyOMopyqz38v9LQhcENIeSzCs8FoM7dZaX9YHayscV8PLuOl5v8tWk6mA== X-Received: by 2002:a17:906:74db:b0:9b2:78bf:d8d4 with SMTP id z27-20020a17090674db00b009b278bfd8d4mr1362877ejl.5.1696404005642; Wed, 04 Oct 2023 00:20:05 -0700 (PDT) Received: from melexis ([91.192.181.19]) by smtp.gmail.com with ESMTPSA id h14-20020a170906590e00b0099cd008c1a4sm2296005ejq.136.2023.10.04.00.20.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Oct 2023 00:20:05 -0700 (PDT) From: Volodymyr Kharuk To: Cc: Andrii Kyselov , Mauro Carvalho Chehab , Rob Herring , Krzysztof Kozlowski , Laurent Pinchart , devicetree@vger.kernel.org, Hans Verkuil , Sakari Ailus , Benjamin Mugnier , Volodymyr Kharuk Subject: [PATCH v5 4/8] media: v4l: ctrls-api: Allow array update in __v4l2_ctrl_modify_range Date: Wed, 4 Oct 2023 10:19:43 +0300 Message-Id: <4861f8420b6b11343604c681fd410836fa7ce4af.1696347109.git.vkh@melexis.com> X-Mailer: git-send-email 2.38.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org For V4L2_CID_TOF_TINT, which is dynamic array, it is required to use __v4l2_ctrl_modify_range. So the idea is to use type_ops instead of u64 from union. It will allow to work with any type. Signed-off-by: Volodymyr Kharuk --- drivers/media/v4l2-core/v4l2-ctrls-api.c | 25 ++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/drivers/media/v4l2-core/v4l2-ctrls-api.c b/drivers/media/v4l2-core/v4l2-ctrls-api.c index 002ea6588edf..03e7efea1cf7 100644 --- a/drivers/media/v4l2-core/v4l2-ctrls-api.c +++ b/drivers/media/v4l2-core/v4l2-ctrls-api.c @@ -934,17 +934,18 @@ int __v4l2_ctrl_modify_range(struct v4l2_ctrl *ctrl, lockdep_assert_held(ctrl->handler->lock); switch (ctrl->type) { + case V4L2_CTRL_TYPE_MENU: + case V4L2_CTRL_TYPE_INTEGER_MENU: + if (ctrl->is_array) + return -EINVAL; + fallthrough; case V4L2_CTRL_TYPE_INTEGER: case V4L2_CTRL_TYPE_INTEGER64: case V4L2_CTRL_TYPE_BOOLEAN: - case V4L2_CTRL_TYPE_MENU: - case V4L2_CTRL_TYPE_INTEGER_MENU: case V4L2_CTRL_TYPE_BITMASK: case V4L2_CTRL_TYPE_U8: case V4L2_CTRL_TYPE_U16: case V4L2_CTRL_TYPE_U32: - if (ctrl->is_array) - return -EINVAL; ret = check_range(ctrl->type, min, max, step, def); if (ret) return ret; @@ -962,16 +963,16 @@ int __v4l2_ctrl_modify_range(struct v4l2_ctrl *ctrl, } cur_to_new(ctrl); if (validate_new(ctrl, ctrl->p_new)) { - if (ctrl->type == V4L2_CTRL_TYPE_INTEGER64) - *ctrl->p_new.p_s64 = def; - else - *ctrl->p_new.p_s32 = def; + WARN_ON(ctrl->is_array); /* This shouldn't happen, as + * INTEGER/Ux/BOOLEAN/BITMASK will not + * return an error. + * In case it happened, all array will + * set to default value + */ + ctrl->type_ops->init(ctrl, 0, ctrl->p_new); } - if (ctrl->type == V4L2_CTRL_TYPE_INTEGER64) - value_changed = *ctrl->p_new.p_s64 != *ctrl->p_cur.p_s64; - else - value_changed = *ctrl->p_new.p_s32 != *ctrl->p_cur.p_s32; + value_changed = !ctrl->type_ops->equal(ctrl, ctrl->p_cur, ctrl->p_new); if (value_changed) ret = set_ctrl(NULL, ctrl, V4L2_EVENT_CTRL_CH_RANGE); else if (range_changed) From patchwork Wed Oct 4 07:19:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Volodymyr Kharuk X-Patchwork-Id: 13408290 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B34ECE8FDD1 for ; Wed, 4 Oct 2023 07:20:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241501AbjJDHUN (ORCPT ); Wed, 4 Oct 2023 03:20:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57080 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241498AbjJDHUN (ORCPT ); Wed, 4 Oct 2023 03:20:13 -0400 Received: from mail-ej1-x62e.google.com (mail-ej1-x62e.google.com [IPv6:2a00:1450:4864:20::62e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5CBF9BB for ; Wed, 4 Oct 2023 00:20:09 -0700 (PDT) Received: by mail-ej1-x62e.google.com with SMTP id a640c23a62f3a-9b281a2aa94so317212166b.2 for ; Wed, 04 Oct 2023 00:20:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=melexis.com; s=google; t=1696404008; x=1697008808; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=o4ZgBmHteA4wHsLrCFexpXA7K7drP5ZEJIQkSB/aVxY=; b=DID62vkPq/VUnxOpfFxAi/VHOlGNhCBgZwIH01rEgXpebAha4q7zIXt/O6KwcHYEhV qwT9DIp3oApxmv62u98bIOVz/RXwCOgp0orbsgZJxN5Ck1i2TLcawSj8V28hnUymMdKM fH0A75k/Nyk2IKhFihdsIC+UbKZZgCogdiIDtgfN8g53MaAz5tKfAHqkz9Sv/9LIP/7B JYMXADrthpM4dAIUIP34HSPR7i32gwRMXDV9SZHGrOlnzfO18EQRJQcbuMPQTljuKDan dq+F0Ddnh/iinRzzOnObKaKQcaeLKSntu1xqbDdPx52BhspAeGCTTn0WNsQu2zc3rCmA 3vvQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696404008; x=1697008808; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=o4ZgBmHteA4wHsLrCFexpXA7K7drP5ZEJIQkSB/aVxY=; b=cu/XFggegpQpgaTKZV9SdZt6me4Mw0zwKVcxsR5YWCrwxdB2t4BLgaE27sZoFiG5qO iWCjvdax/Ua4QgiklmVBVjIIfgiKt3hVVxnAuNZmhrbMZXIIDBTcvwXskOvHlPAqXBBR dZ+FCU1ps0Zm3vmNenY8OMRfq1APJmsiUxXJok3rM4gTjiB1ZuZCXzIcPiv1ImrA8qzt CMoJufghn66fbyuxkcQ25HDvrSp3MNXjTORwILMHC/OlikrvjJHbpzAuZX2xhw3+GxML AnMtf/JemgrLoOClvdRmKwqd669vqAvUZbSdo2XdVJ1UG0Af6HFG4Z2Kf/P3yPCa1kia E34A== X-Gm-Message-State: AOJu0Yym73rF0lq/5UNKry8GVIk3wR6ndzBJJC2hfkhHFZM8/n6nxk3b cJ6SMhnqFEtlAqOkRqy/wLZUJldDodUzXpqYMm5ul11i7QaVtgZTCtbJCCr3g0Bfb4IndMlvd4z F/X8zCDgexaLydNtSk+v1cSUl6gs4RykauBVWnaT+y0GcxyxzUXYOn9FT2THa9vRNxxUcMpeQ72 CJuQ== X-Google-Smtp-Source: AGHT+IHjaQnPJiOBXT2srG6qiWyWozTCOtRExhfL43SYkbnCTGkV0QlIu7hyxYuUdHGNL7GoroyFCw== X-Received: by 2002:a17:906:259:b0:9ad:c763:c3fd with SMTP id 25-20020a170906025900b009adc763c3fdmr1282878ejl.28.1696404007907; Wed, 04 Oct 2023 00:20:07 -0700 (PDT) Received: from melexis ([91.192.181.19]) by smtp.gmail.com with ESMTPSA id h14-20020a170906590e00b0099e12a49c8fsm2295468ejq.173.2023.10.04.00.20.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Oct 2023 00:20:07 -0700 (PDT) From: Volodymyr Kharuk To: Cc: Andrii Kyselov , Mauro Carvalho Chehab , Rob Herring , Krzysztof Kozlowski , Laurent Pinchart , devicetree@vger.kernel.org, Hans Verkuil , Sakari Ailus , Benjamin Mugnier , Volodymyr Kharuk Subject: [PATCH v5 5/8] media: v4l: ctrls: Add user control base for mlx7502x Date: Wed, 4 Oct 2023 10:19:44 +0300 Message-Id: <825edc1f9ed194a8478ca1432edd9a26c7a11934.1696347109.git.vkh@melexis.com> X-Mailer: git-send-email 2.38.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org Add a control base for mlx7502x and reserve 16 controls. Signed-off-by: Volodymyr Kharuk --- include/uapi/linux/v4l2-controls.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/include/uapi/linux/v4l2-controls.h b/include/uapi/linux/v4l2-controls.h index 92b3957d5720..28af0b3e2240 100644 --- a/include/uapi/linux/v4l2-controls.h +++ b/include/uapi/linux/v4l2-controls.h @@ -204,6 +204,12 @@ enum v4l2_colorfx { */ #define V4L2_CID_USER_ASPEED_BASE (V4L2_CID_USER_BASE + 0x11a0) +/* + * The base for Melexis ToF 7502x driver controls. + * We reserve 16 controls for this driver. + */ +#define V4L2_CID_USER_MLX7502X_BASE (V4L2_CID_USER_BASE + 0x11b0) + /* MPEG-class control IDs */ /* The MPEG controls are applicable to all codec controls * and the 'MPEG' part of the define is historical */ From patchwork Wed Oct 4 07:19:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Volodymyr Kharuk X-Patchwork-Id: 13408291 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 55DCBE8FDD5 for ; Wed, 4 Oct 2023 07:20:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241503AbjJDHUQ (ORCPT ); Wed, 4 Oct 2023 03:20:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57084 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241502AbjJDHUP (ORCPT ); Wed, 4 Oct 2023 03:20:15 -0400 Received: from mail-ej1-x630.google.com (mail-ej1-x630.google.com [IPv6:2a00:1450:4864:20::630]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CA492B4 for ; Wed, 4 Oct 2023 00:20:11 -0700 (PDT) Received: by mail-ej1-x630.google.com with SMTP id a640c23a62f3a-9b27bc8b65eso299217266b.0 for ; Wed, 04 Oct 2023 00:20:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=melexis.com; s=google; t=1696404010; x=1697008810; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=8B4uJGiQDVz8dojAdH+xsYrxjsdR8PRSq/ZZq7Eofz4=; b=Vp5aUcZ3O9+Oz8cUOygZNVJ5Msxi8JE9Tv34vfUthncYefK61m1FZAhkFutU59RelB 8JT/2G69sg8MTlaoAlUfciocZfg4awqmV7hu1QUlz8NF5ZxJJR6FeGmupTrp90qAF0go TL1fr+4pQFz/8gNJkzZOl7qANBptHA8hjfHOfm9P/pXGlqmOYbUbeKhLbW3eoCnIVdVl dmXU0Im1G91UOqW9eMTNRVJxuFjGQxkI+O8pMCjdZUxR/5c2QGT/rGGdWG38w5hcs+hs dLRcE06rEhbOYd5dZTAGvudebumIWuS7ToV6plUVRt1IakxtanJO2u7QNM+sHelU+rNr +NbA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696404010; x=1697008810; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=8B4uJGiQDVz8dojAdH+xsYrxjsdR8PRSq/ZZq7Eofz4=; b=BrxFjElLKwtKWydP+d4lrE1w1Ndb+5gS6ErSojQqwOYpbp3Iaj1L6XB24AozmfLQWq RabPGpQ1K9d8Q9MvDo3LIMqfLvxCBqIhqK+VH7Ee91G7qz9voaTC90sojp4RkLTfRG/F jwRhacFLcjvZ/3XrhU3eRhfOh36/f+xEtNUCW5K86WFmgfxwu2q/ugMjdLIMMK1VVUj0 PU2OXRRcA1jiXxTxEPwjNcxpFImsresHypi+tcQMKda0yZAA94YzUCW0AVDpk8zgG3Nn WJqOEr64AcAxoS5aF6rLk8NEV3Vzb1Dl0g5eJsbC6OI/Y3jQ1SYaDhDQbienQvvpeoxS MRMA== X-Gm-Message-State: AOJu0YzdNNOg1GPpdQnUiU9cPMtYkIUQU7bVO075sD6YycIz/Uudn2ln arpqWhe92vWGm1WLuT67xEAr26pUmSHNKDAJ7iWk/uFjLet+CoCNe2/3lezqbi+FB6iqTyZNMq0 37H3PdkvlnLkzsabx/W2ygg09ndz76lofPUAwH4VA3mt6444yvk47nLxHyJTjRuaoswlggbIZ5O 2pXA== X-Google-Smtp-Source: AGHT+IFMcXcyGsPl5k6CIwy4QhpwXmsXsdPrFUDsSpCaw69HSFowSEFr9I8y32Kq3V4ONPzOC9THXQ== X-Received: by 2002:a17:906:10d1:b0:9ad:ec25:825b with SMTP id v17-20020a17090610d100b009adec25825bmr1139003ejv.58.1696404010329; Wed, 04 Oct 2023 00:20:10 -0700 (PDT) Received: from melexis ([91.192.181.19]) by smtp.gmail.com with ESMTPSA id r13-20020a170906350d00b009a9fbeb15f5sm2255795eja.46.2023.10.04.00.20.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Oct 2023 00:20:10 -0700 (PDT) From: Volodymyr Kharuk To: Cc: Andrii Kyselov , Mauro Carvalho Chehab , Rob Herring , Krzysztof Kozlowski , Laurent Pinchart , devicetree@vger.kernel.org, Hans Verkuil , Sakari Ailus , Benjamin Mugnier , Volodymyr Kharuk Subject: [PATCH v5 6/8] media: uapi: Add mlx7502x header file Date: Wed, 4 Oct 2023 10:19:45 +0300 Message-Id: <5a8f0d6a6e448548111cdea90e9e106560dd2c3a.1696347109.git.vkh@melexis.com> X-Mailer: git-send-email 2.38.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org Define user controls for mlx7502x driver, add its documentation and update MAINTAINERS Signed-off-by: Volodymyr Kharuk --- .../userspace-api/media/drivers/index.rst | 1 + .../userspace-api/media/drivers/mlx7502x.rst | 28 +++++++++++++++++++ MAINTAINERS | 2 ++ include/uapi/linux/mlx7502x.h | 28 +++++++++++++++++++ 4 files changed, 59 insertions(+) create mode 100644 Documentation/userspace-api/media/drivers/mlx7502x.rst create mode 100644 include/uapi/linux/mlx7502x.h diff --git a/Documentation/userspace-api/media/drivers/index.rst b/Documentation/userspace-api/media/drivers/index.rst index 6708d649afd7..de3619672d44 100644 --- a/Documentation/userspace-api/media/drivers/index.rst +++ b/Documentation/userspace-api/media/drivers/index.rst @@ -37,6 +37,7 @@ For more details see the file COPYING in the source distribution of Linux. dw100 imx-uapi max2175 + mlx7502x omap3isp-uapi st-vgxy61 uvcvideo diff --git a/Documentation/userspace-api/media/drivers/mlx7502x.rst b/Documentation/userspace-api/media/drivers/mlx7502x.rst new file mode 100644 index 000000000000..d68506c09f84 --- /dev/null +++ b/Documentation/userspace-api/media/drivers/mlx7502x.rst @@ -0,0 +1,28 @@ +.. SPDX-License-Identifier: GPL-2.0 + +Melexis mlx7502x ToF camera sensor driver +========================================= + +The mlx7502x driver implements the following driver-specific controls: + +``V4L2_CID_MLX7502X_OUTPUT_MODE (menu)`` +---------------------------------------- + The sensor has two taps, which gather reflected light: A and B. + The control sets the way data should be put in a buffer. The most + common output mode is A-B which provides the best sunlight robustness. + +.. flat-table:: + :header-rows: 0 + :stub-columns: 0 + :widths: 1 4 + + * - ``V4L2_MLX7502X_OUTPUT_MODE_A_MINUS_B`` + - tap A minus tap B + * - ``V4L2_MLX7502X_OUTPUT_MODE_A_PLUS_B`` + - tap A plus tap B + * - ``V4L2_MLX7502X_OUTPUT_MODE_A`` + - only tap A + * - ``V4L2_MLX7502X_OUTPUT_MODE_B`` + - only tap B + * - ``V4L2_MLX7502X_OUTPUT_MODE_A_AND_B`` + - tap A and tap B (this config will change PAD format) diff --git a/MAINTAINERS b/MAINTAINERS index 83e325e273dc..49cc44fe8ec4 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -13562,7 +13562,9 @@ M: Volodymyr Kharuk L: linux-media@vger.kernel.org S: Supported W: http://www.melexis.com +F: Documentation/userspace-api/media/drivers/mlx7502x.rst F: Documentation/userspace-api/media/v4l/ext-ctrls-tof.rst +F: include/uapi/linux/mlx7502x.h MELFAS MIP4 TOUCHSCREEN DRIVER M: Sangwon Jee diff --git a/include/uapi/linux/mlx7502x.h b/include/uapi/linux/mlx7502x.h new file mode 100644 index 000000000000..80e9317ff0fc --- /dev/null +++ b/include/uapi/linux/mlx7502x.h @@ -0,0 +1,28 @@ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ +/* + * Melexis 7502x ToF cameras driver. + * + * Copyright (C) 2021 Melexis N.V. + * + */ + +#ifndef __UAPI_MLX7502X_H_ +#define __UAPI_MLX7502X_H_ + +#include + +/* + * this is related to the taps in ToF cameras, + * usually A minus B is the best option + */ +enum v4l2_mlx7502x_output_mode { + V4L2_MLX7502X_OUTPUT_MODE_A_MINUS_B = 0, + V4L2_MLX7502X_OUTPUT_MODE_A_PLUS_B, + V4L2_MLX7502X_OUTPUT_MODE_A, + V4L2_MLX7502X_OUTPUT_MODE_B, + V4L2_MLX7502X_OUTPUT_MODE_A_AND_B, /* output frame size doubles */ +}; + +#define V4L2_CID_MLX7502X_OUTPUT_MODE (V4L2_CID_USER_MLX7502X_BASE + 0) + +#endif /* __UAPI_MLX7502X_H_ */ From patchwork Wed Oct 4 07:19:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Volodymyr Kharuk X-Patchwork-Id: 13408292 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1651AE8FDD1 for ; Wed, 4 Oct 2023 07:20:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241506AbjJDHUS (ORCPT ); Wed, 4 Oct 2023 03:20:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37160 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241504AbjJDHUR (ORCPT ); Wed, 4 Oct 2023 03:20:17 -0400 Received: from mail-ej1-x62b.google.com (mail-ej1-x62b.google.com [IPv6:2a00:1450:4864:20::62b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2EC84BB for ; Wed, 4 Oct 2023 00:20:14 -0700 (PDT) Received: by mail-ej1-x62b.google.com with SMTP id a640c23a62f3a-99de884ad25so317401366b.3 for ; Wed, 04 Oct 2023 00:20:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=melexis.com; s=google; t=1696404012; x=1697008812; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=bTpsAPBi5GKu/J1Fc/6++nPykYaaAvbzc3zwdXb4wDg=; b=pqMVwO9Zp+hquPo4VkRW1t87EKzJ2jjJu27JTgi/oMKr/Cbd03x6tE/PM2R+ZNG6R3 wdAbx1vkBh5zUsGdeABbIatwQnsTti1dCQPG2pA/1UTnUVsrkwd7TqbMOqbBkMIyeDX0 iA+FPMrJLfgpJdZa4uH8N52cCIqfeJ1mFtsil5+PpDm5p0ia0WADG2fqiZLLPJYxFWj7 fAsH4o09YUB2WPGdnxhNsg3zXxYRVQgpZJoEwspD5iSQ7N7FsGL7Aj9GA/hHCvo2K2Ri qifTjlBM9obtIUjT4CABfWk3isWmcHclKwUDoJvSidzWWsSK55QbNZNwhH//8sZtyUDC znEQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696404012; x=1697008812; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=bTpsAPBi5GKu/J1Fc/6++nPykYaaAvbzc3zwdXb4wDg=; b=q8l1rRTreA02N6quxsa9GTNpflB/NWzKl1KvITngxOF0NwNc+nA69Z4NocJcADm/5k pUG7FV3LZdfBg/TAGPmBSV0l9DHTzzmmSiizZDZ+XrTPU/nL3LhTF1yh/h66CtWkX5JJ b429MeHVR7Bm8ORNKypLedNuaLcah9tGKzyFUHnlDe4bgc/oFNEH7Et0JZqstx/4UHrE lP43orWxyH1+icawFu59iuMi6Ph/aktyGgoMJw3IE3CmtU50QDnBu5VpDNv+WpHbqObI 9tOS/JIP/KnwImZBIoaAeFN0M2OcnWUnG3pE7OOga2JnpHHYZD+0DirsZNAAYFj78ISB pBbA== X-Gm-Message-State: AOJu0YyPF+z1EtN7YV6dsHZCHHgIweFbDe0UjMGaMSid5LvrE3aGR3hO JZb6SbIB9H7VVWqo9kn9yUfkvQp7qYJho+ERzf/DLuWkAgOZdFdWXztT7cZZXOf/o1TkzGLvguO fQWRwFcxmejVT259Fe16N0iLwtBaPcUkJreRTOAeKVAP5Anq4WpmHWYeDF+pr4pmw7cakyYbyv1 E4HA== X-Google-Smtp-Source: AGHT+IFhzJQFUC8Ywe5pnbymojVwOeQD6C6f3/FA8U+MP7KdSZHH+Cb1O6x8LO6gixC/otHBghhk2w== X-Received: by 2002:a17:906:8b:b0:9b2:b149:b81a with SMTP id 11-20020a170906008b00b009b2b149b81amr1684846ejc.64.1696404012705; Wed, 04 Oct 2023 00:20:12 -0700 (PDT) Received: from melexis ([91.192.181.19]) by smtp.gmail.com with ESMTPSA id o13-20020a170906358d00b0099bc8db97bcsm2265910ejb.131.2023.10.04.00.20.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Oct 2023 00:20:12 -0700 (PDT) From: Volodymyr Kharuk To: Cc: Andrii Kyselov , Mauro Carvalho Chehab , Rob Herring , Krzysztof Kozlowski , Laurent Pinchart , devicetree@vger.kernel.org, Hans Verkuil , Sakari Ailus , Benjamin Mugnier , Volodymyr Kharuk , Krzysztof Kozlowski Subject: [PATCH v5 7/8] media: dt-bindings: Add mlx7502x camera sensor Date: Wed, 4 Oct 2023 10:19:46 +0300 Message-Id: X-Mailer: git-send-email 2.38.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org Add device tree binding of the mlx7502x and update MAINTAINERS Signed-off-by: Volodymyr Kharuk Reviewed-by: Krzysztof Kozlowski --- .../bindings/media/i2c/melexis,mlx7502x.yaml | 126 ++++++++++++++++++ MAINTAINERS | 1 + 2 files changed, 127 insertions(+) create mode 100644 Documentation/devicetree/bindings/media/i2c/melexis,mlx7502x.yaml diff --git a/Documentation/devicetree/bindings/media/i2c/melexis,mlx7502x.yaml b/Documentation/devicetree/bindings/media/i2c/melexis,mlx7502x.yaml new file mode 100644 index 000000000000..7b86b6c5b151 --- /dev/null +++ b/Documentation/devicetree/bindings/media/i2c/melexis,mlx7502x.yaml @@ -0,0 +1,126 @@ +# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/media/i2c/melexis,mlx7502x.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Melexis ToF 7502x MIPI CSI-2 Sensor + +maintainers: + - Volodymyr Kharuk + +description: |- + Melexis ToF 7502x sensors has a CSI-2 output. It supports 2 and 4 lanes, + and mipi speeds are 300, 600, 704, 800, 904, 960Mbs. Supported format is RAW12. + Sensor 75026 is QVGA, while 75027 is VGA sensor. + +properties: + compatible: + enum: + - melexis,mlx75026 + - melexis,mlx75027 + + reg: + maxItems: 1 + + clocks: + description: Clock frequency 8MHz + maxItems: 1 + + vdda-supply: + description: + Analog power supply(2.7V). + + vddif-supply: + description: + Interface power supply(1.8V). + + vddd-supply: + description: + Digital power supply(1.2V). + + vdmix-supply: + description: + Mixed driver power supply(1.2V). + + reset-gpios: + maxItems: 1 + description: Reset Sensor GPIO Control (active low) + + port: + description: MIPI CSI-2 transmitter port + $ref: /schemas/graph.yaml#/$defs/port-base + + properties: + endpoint: + $ref: /schemas/media/video-interfaces.yaml# + unevaluatedProperties: false + + properties: + data-lanes: + oneOf: + - items: + - const: 1 + - const: 2 + - items: + - const: 1 + - const: 2 + - const: 3 + - const: 4 + + required: + - data-lanes + - link-frequencies + +required: + - compatible + - reg + - clocks + - port + - vdda-supply + - vddif-supply + - vddd-supply + - vdmix-supply + +additionalProperties: false + +examples: + - | + #include + + i2c { + #address-cells = <1>; + #size-cells = <0>; + + mlx7502x: camera@57 { + compatible = "melexis,mlx75027"; + reg = <0x57>; + clocks = <&mlx7502x_clk>; + + assigned-clocks = <&mlx7502x_clk>; + assigned-clock-parents = <&mlx7502x_clk_parent>; + assigned-clock-rates = <8000000>; + + vdda-supply = <®_2v7>; + vddif-supply = <®_1v8>; + vddd-supply = <®_1v2>; + vdmix-supply = <®_1v2>; + + reset-gpios = <&gpio_exp 6 GPIO_ACTIVE_HIGH>; + + port { + mlx7502x_out_mipi_csi2: endpoint { + remote-endpoint = <&mipi_csi2_from_mlx7502x>; + data-lanes = <1 2 3 4>; + link-frequencies = /bits/ 64 < 960000000 + 904000000 + 800000000 + 704000000 + 600000000 + 300000000 >; + }; + }; + }; + }; + +... diff --git a/MAINTAINERS b/MAINTAINERS index 49cc44fe8ec4..c9da47ff2652 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -13562,6 +13562,7 @@ M: Volodymyr Kharuk L: linux-media@vger.kernel.org S: Supported W: http://www.melexis.com +F: Documentation/devicetree/bindings/media/i2c/melexis,mlx7502x.yaml F: Documentation/userspace-api/media/drivers/mlx7502x.rst F: Documentation/userspace-api/media/v4l/ext-ctrls-tof.rst F: include/uapi/linux/mlx7502x.h From patchwork Wed Oct 4 07:19:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Volodymyr Kharuk X-Patchwork-Id: 13408293 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8D2BFE8FDD1 for ; Wed, 4 Oct 2023 07:20:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241505AbjJDHU2 (ORCPT ); Wed, 4 Oct 2023 03:20:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37264 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241508AbjJDHU0 (ORCPT ); Wed, 4 Oct 2023 03:20:26 -0400 Received: from mail-ej1-x630.google.com (mail-ej1-x630.google.com [IPv6:2a00:1450:4864:20::630]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E0219B0 for ; Wed, 4 Oct 2023 00:20:16 -0700 (PDT) Received: by mail-ej1-x630.google.com with SMTP id a640c23a62f3a-9936b3d0286so321330366b.0 for ; Wed, 04 Oct 2023 00:20:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=melexis.com; s=google; t=1696404015; x=1697008815; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=KoWjnKsfcHQjJFG1yvwlcp3QhIn1edxaPBt1WnCM9C8=; b=ZRcPj6GgIzUadyU5gDM6n12P1kAuGnJ2vPeoYr4x2p2KwpTtckxvCkpt8/c+n767rB symQxOHxOuee5vQa0ybnQY0FHAXP76Y5n3FTE5mVQVcQbP7o9BTy7ruKGZclW49Qq9tJ Tnj2+iXavZxVFI3LhocYBUSuLuz55PezoiG64c7aSpDKDBQpuVK9HCROBNrvviaW4+Yz AjH1hRyD45I81zuWIbJdCKGZVkyhNBJdrVQQjdi/jafaANZ1QJ/0v3SonbfBF4gkfqw1 KOjLWoAnGyTnDdGgeZX6UT52UM982bQn7URTrhjelxi+i1xr07IfRHJFe/Ztbz7Mx68d Cegg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696404015; x=1697008815; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=KoWjnKsfcHQjJFG1yvwlcp3QhIn1edxaPBt1WnCM9C8=; b=R6dUZWxDc5m5vsgbkeTZZsUOAPw3LkBeElB0187M3OYH0U7RLabhH0V8c7Vsy+e50t +IcNOma/pTb09m39VcXWw5u83G9Mklf7ueW8TXZPmvICxOM65bYSq91ZGoifEzLM0tka cZkTw9Cg7YD7nC6yfJpH8XVq2C4S4fW005TIJvhE10HT9Xde4Izq/IiMUceBpXjie21x UPHBfl/CSeJDsEeL2niBbPZDwdQeEo8ps2nzXiZZ1c/B8zskuIPSZcbZe/JMQe9NGt3S SLWJ0J+jkpUtUOJPd3SqSqdtJ+HaEz1SINC6sHtSjfsisBMxIGLhOedwpZp16mMoHFQV aW1A== X-Gm-Message-State: AOJu0Ywdim/W21LLy6+7p0de/VvASzEWjRyhTtDmT/kjkJ7G5C3TLg5U Ef/UiD89xYj2uhufi7JAGfFjaxQn2PQa8kftJY18TPrA/45uu3sI7bzERoP0zNH1CUMX4X+LOdE /HmzK50/xesNO5mM2lV+/NTKS1qJTD3P1Dgms3kkcDnixnvHt0jwts91DAzwHYbbaZRMURClwO2 nTEQ== X-Google-Smtp-Source: AGHT+IH8JQRwjCG9GLBasGqg7xYQSTcVsM7xwHVHRHChwMcOuO6JWGKXZyrZxMI0w1gZ8Gz2JxfrQA== X-Received: by 2002:a17:906:538a:b0:9b2:b269:d563 with SMTP id g10-20020a170906538a00b009b2b269d563mr1551995ejo.63.1696404015153; Wed, 04 Oct 2023 00:20:15 -0700 (PDT) Received: from melexis ([91.192.181.19]) by smtp.gmail.com with ESMTPSA id u11-20020a056402064b00b0053782c81c69sm1931928edx.96.2023.10.04.00.20.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Oct 2023 00:20:14 -0700 (PDT) From: Volodymyr Kharuk To: Cc: Andrii Kyselov , Mauro Carvalho Chehab , Rob Herring , Krzysztof Kozlowski , Laurent Pinchart , devicetree@vger.kernel.org, Hans Verkuil , Sakari Ailus , Benjamin Mugnier , Volodymyr Kharuk Subject: [PATCH v5 8/8] media: i2c: Add driver for mlx7502x ToF sensor Date: Wed, 4 Oct 2023 10:19:47 +0300 Message-Id: <2deff7b70f1bef58f3a67223ff297653fc307ed7.1696347109.git.vkh@melexis.com> X-Mailer: git-send-email 2.38.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org Melexis ToF 7502x sensors has a CSI-2 output. It supports 2 and 4 lanes, and mipi speeds are 300, 600, 704, 800, 904, 960Mbs. Supported format is RAW12. Sensor 75026 is QVGA, while 75027 is VGA sensor. The driver supports: - Digital binning and cropping - Horizontal and vertical flip - phase shifts(up to 8) - frequency modulation - time integration Signed-off-by: Volodymyr Kharuk Signed-off-by: Andrii Kyselov --- MAINTAINERS | 1 + drivers/media/i2c/Kconfig | 13 + drivers/media/i2c/Makefile | 1 + drivers/media/i2c/mlx7502x.c | 1747 ++++++++++++++++++++++++++++++++++ 4 files changed, 1762 insertions(+) create mode 100644 drivers/media/i2c/mlx7502x.c diff --git a/MAINTAINERS b/MAINTAINERS index c9da47ff2652..1c340f15baf2 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -13565,6 +13565,7 @@ W: http://www.melexis.com F: Documentation/devicetree/bindings/media/i2c/melexis,mlx7502x.yaml F: Documentation/userspace-api/media/drivers/mlx7502x.rst F: Documentation/userspace-api/media/v4l/ext-ctrls-tof.rst +F: drivers/media/i2c/mlx7502x.c F: include/uapi/linux/mlx7502x.h MELFAS MIP4 TOUCHSCREEN DRIVER diff --git a/drivers/media/i2c/Kconfig b/drivers/media/i2c/Kconfig index 74ff833ff48c..f97b58d81461 100644 --- a/drivers/media/i2c/Kconfig +++ b/drivers/media/i2c/Kconfig @@ -203,6 +203,19 @@ config VIDEO_IMX415 config VIDEO_MAX9271_LIB tristate +config VIDEO_MLX7502X + tristate "Melexis ToF 75026 and 75027 sensors support" + depends on I2C && VIDEO_DEV + select MEDIA_CONTROLLER + select VIDEO_V4L2_SUBDEV_API + select V4L2_FWNODE + help + This is a V4L2 sensor driver for the Melexis 75026 and 75027 + ToF sensors. + + To compile this driver as a module, choose M here: the + module will be called mlx7502x. + config VIDEO_MT9M001 tristate "mt9m001 support" help diff --git a/drivers/media/i2c/Makefile b/drivers/media/i2c/Makefile index 80b00d39b48f..a4525cb7939b 100644 --- a/drivers/media/i2c/Makefile +++ b/drivers/media/i2c/Makefile @@ -62,6 +62,7 @@ obj-$(CONFIG_VIDEO_M52790) += m52790.o obj-$(CONFIG_VIDEO_MAX9271_LIB) += max9271.o obj-$(CONFIG_VIDEO_MAX9286) += max9286.o obj-$(CONFIG_VIDEO_ML86V7667) += ml86v7667.o +obj-$(CONFIG_VIDEO_MLX7502X) += mlx7502x.o obj-$(CONFIG_VIDEO_MSP3400) += msp3400.o obj-$(CONFIG_VIDEO_MT9M001) += mt9m001.o obj-$(CONFIG_VIDEO_MT9M111) += mt9m111.o diff --git a/drivers/media/i2c/mlx7502x.c b/drivers/media/i2c/mlx7502x.c new file mode 100644 index 000000000000..06ee604c85a5 --- /dev/null +++ b/drivers/media/i2c/mlx7502x.c @@ -0,0 +1,1747 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * A V4L2 driver for Melexis 7502x ToF cameras. + * + * Copyright (C) 2022 Melexis N.V. + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define MLX7502X_PARAM_HOLD_REG 0x0102 +#define MLX7502X_HMAX_REG 0x0800 +#define MLX7502X_COLUMN_START_REG 0x0804 +#define MLX7502X_COLUMN_LEN_REG 0x0806 +#define MLX7502X_ROW_START_REG 0x0808 +#define MLX7502X_ROW_END_REG 0x080a +#define MLX7502X_VFLIP_REG 0x080c +#define MLX7502X_HFLIP_REG 0x080d +#define MLX7502X_OUTPUT_MODE_REG 0x0828 +#define MLX7502X_STREAM_EN_REG 0x1001 +#define MLX7502X_DATA_LANE_CONFIG_REG 0x1010 +#define MLX7502X_FMOD_REG 0x1048 +#define MLX7502X_PLL_RES_REG 0x104b +#define MLX7502X_BINNING_REG 0x14a5 +#define MLX7502X_CONTINUOUS_REG 0x1c40 +#define MLX7502X_FRAME_TIME_REG 0x2108 +#define MLX7502X_TINT0_REG 0x2120 +#define MLX7502X_PX_PHASE_SHIFT_REG 0x21b4 +#define MLX7502X_DIVSELPRE_REG 0x21be +#define MLX7502X_DIVSEL_REG 0x21bf +#define MLX7502X_PHASE_COUNT_REG 0x21e8 +#define MLX7502X_PLLSETUP_REG 0x4010 +#define MLX7502X_PRETIME_REG 0x4015 +#define MLX7502X_RANDNM0_REG 0x5265 + +#define MLX7502X_NIBLE_LOW_MASK GENMASK(3, 0) +#define MLX7502X_NIBLE_HIGH_MASK GENMASK(7, 4) + +#define MLX7502X_PHASE_MAX_NUM 8 + +#define MLX7502X_CLK_RATE_MHZ 120 +#define MLX7502X_XCLK_RATE (8 * HZ_PER_MHZ) + +#define MLX7502X_RESET_DELAY_MS 100 +#define MLX7502X_STREAMING_DELAY_MS 2 + +#define MLX7502X_LINK_FREQ_REG_N 11 +#define MLX7502X_LINK_FREQ_N 6 +#define MLX7502X_LANE_N 2 +#define MLX7502X_OUTPUT_MODE_N 2 + +#define MLX7502X_PLLSETUP_US 503 +#define MLX7502X_PLLSETUP_TICKS 8 +#define MLX7502X_PRETIME_US 50 +#define MLX7502X_FRAME_ADD_TICKS 13 + +#define MLX7502X_DEFAULT_FRAME_RATE 25 + +#define MLX7502X_ROW_START(top) ((top) / 2) +#define MLX7502X_ROW_END(top, height) ((((top) + (height)) / 2) + 1) + +#define MLX7502X_LEFT_STEP 1 +#define MLX7502X_LEFT_MIN 0 + +#define MLX7502X_TOP_STEP 2 +#define MLX7502X_TOP_MIN 0 + +#define MLX7502X_PLL_RES_THR 113 + +static const char * const mlx7502x_supply_names[] = { + "vdda", /* Analog (2.7V) supply */ + "vddif", /* I/O (1.8V) supply */ + "vddd", /* Digital core (1.2V) supply */ + "vdmix", /* MIX driver (1.2V) supply */ +}; + +#define MLX7502X_NUM_SUPPLIES ARRAY_SIZE(mlx7502x_supply_names) + +struct mlx7502x_regval_list { + u16 addr; + u8 data; +}; + +struct mlx7502x_link_freq_list { + s64 link_freq[MLX7502X_LINK_FREQ_N]; + u16 addr[MLX7502X_LINK_FREQ_REG_N]; + u8 data[MLX7502X_LANE_N][MLX7502X_LINK_FREQ_N][MLX7502X_LINK_FREQ_REG_N]; + u16 hmax[MLX7502X_LANE_N][MLX7502X_LINK_FREQ_N][MLX7502X_OUTPUT_MODE_N]; +}; + +struct mlx7502x_binning_mode { + u8 reg_value; + u8 ratio; + u8 width_step; + u8 height_step; + u8 width_min; + u8 height_min; +}; + +struct mlx7502x_output_mode { + u8 hmax_index; + u8 width_mult; +}; + +/* configuration of divider for specific fmod */ +struct mlx7502x_fmod_list { + u32 fmod; + u8 divselpre; + u8 divsel; +}; + +struct mlx7502x_sensor_desc { + const struct mlx7502x_regval_list *init_cfg; + u32 init_cfg_size; + const struct mlx7502x_link_freq_list *link_freq_cfg; + u32 width; + u32 height; +}; + +struct mlx7502x { + struct v4l2_subdev sd; + struct media_pad pad; + struct v4l2_fwnode_endpoint ep; + struct device *dev; + + /* controls */ + struct v4l2_ctrl_handler ctrl_handler; + struct v4l2_ctrl *link_freq; + struct v4l2_ctrl *tint; + struct v4l2_ctrl *phase_seq; + struct v4l2_ctrl *output_mode; + + struct clk *xclk; + struct regulator_bulk_data supplies[MLX7502X_NUM_SUPPLIES]; + + /* pins */ + struct gpio_desc *reset; + + const struct mlx7502x_sensor_desc *cur_desc; + const struct mlx7502x_binning_mode *binning_mode; + int streaming; + u16 hmax; /* internal sensor frame size in ticks */ + struct v4l2_fract frame_interval; + struct v4l2_rect crop; + struct v4l2_rect compose; + struct mutex lock; /* mutex lock for serialized operations */ +}; + +static const struct mlx7502x_regval_list mlx7502x_common_init_cfg[] = { + { 0x1006, 0x08 }, { 0x1007, 0x00 }, { 0x1040, 0x00 }, { 0x1041, 0x96 }, + { 0x1042, 0x01 }, { 0x1043, 0x00 }, { 0x1044, 0x00 }, { 0x1046, 0x01 }, + { 0x104a, 0x01 }, { 0x1000, 0x00 }, { 0x10d3, 0x10 }, { 0x1448, 0x06 }, + { 0x1449, 0x40 }, { 0x144a, 0x06 }, { 0x144b, 0x40 }, { 0x144c, 0x06 }, + { 0x144d, 0x40 }, { 0x144e, 0x06 }, { 0x144f, 0x40 }, { 0x1450, 0x06 }, + { 0x1451, 0x40 }, { 0x1452, 0x06 }, { 0x1453, 0x40 }, { 0x1454, 0x06 }, + { 0x1455, 0x40 }, { 0x1456, 0x06 }, { 0x1457, 0x40 }, { 0x2203, 0x1e }, + { 0x2c08, 0x01 }, { 0x3c2b, 0x1b }, { 0x400e, 0x01 }, { 0x400f, 0x81 }, + { 0x40d1, 0x00 }, { 0x40d2, 0x00 }, { 0x40d3, 0x00 }, { 0x40db, 0x3f }, + { 0x40de, 0x40 }, { 0x40df, 0x01 }, { 0x4134, 0x04 }, { 0x4135, 0x04 }, + { 0x4136, 0x04 }, { 0x4137, 0x04 }, { 0x4138, 0x04 }, { 0x4139, 0x04 }, + { 0x413a, 0x04 }, { 0x413b, 0x04 }, { 0x413c, 0x04 }, { 0x4146, 0x01 }, + { 0x4147, 0x01 }, { 0x4148, 0x01 }, { 0x4149, 0x01 }, { 0x414a, 0x01 }, + { 0x414b, 0x01 }, { 0x414c, 0x01 }, { 0x414d, 0x01 }, { 0x4158, 0x01 }, + { 0x4159, 0x01 }, { 0x415a, 0x01 }, { 0x415b, 0x01 }, { 0x415c, 0x01 }, + { 0x415d, 0x01 }, { 0x415e, 0x01 }, { 0x415f, 0x01 }, { 0x4590, 0x00 }, + { 0x4591, 0x2e }, { 0x4684, 0x00 }, { 0x4685, 0xa0 }, { 0x4687, 0xa1 }, + { 0x471e, 0x07 }, { 0x471f, 0xc9 }, { 0x473a, 0x07 }, { 0x473b, 0xc9 }, + { 0x4770, 0x00 }, { 0x4771, 0x00 }, { 0x4772, 0x1f }, { 0x4773, 0xff }, + { 0x4778, 0x06 }, { 0x4779, 0xa4 }, { 0x477a, 0x07 }, { 0x477b, 0xae }, + { 0x4788, 0x06 }, { 0x4789, 0xa4 }, { 0x478c, 0x1f }, { 0x478d, 0xff }, + { 0x478e, 0x00 }, { 0x478f, 0x00 }, { 0x4792, 0x00 }, { 0x4793, 0x00 }, + { 0x4796, 0x00 }, { 0x4797, 0x00 }, { 0x479a, 0x00 }, { 0x479b, 0x00 }, + { 0x479c, 0x1f }, { 0x479d, 0xff }, { 0x479e, 0x00 }, { 0x479f, 0x00 }, + { 0x47a2, 0x00 }, { 0x47a3, 0x00 }, { 0x47a6, 0x00 }, { 0x47a7, 0x00 }, + { 0x47aa, 0x00 }, { 0x47ab, 0x00 }, { 0x47ac, 0x1f }, { 0x47ad, 0xff }, + { 0x47ae, 0x00 }, { 0x47af, 0x00 }, { 0x47b2, 0x00 }, { 0x47b3, 0x00 }, + { 0x47b6, 0x00 }, { 0x47b7, 0x00 }, { 0x47ba, 0x00 }, { 0x47bb, 0x00 }, + { 0x47bc, 0x1f }, { 0x47bd, 0xff }, { 0x47be, 0x00 }, { 0x47bf, 0x00 }, + { 0x47c2, 0x00 }, { 0x47c3, 0x00 }, { 0x47c6, 0x00 }, { 0x47c7, 0x00 }, + { 0x47ca, 0x00 }, { 0x47cb, 0x00 }, { 0x4834, 0x00 }, { 0x4835, 0xa0 }, + { 0x4837, 0xa1 }, { 0x4878, 0x00 }, { 0x4879, 0xa0 }, { 0x487b, 0xa1 }, + { 0x48bc, 0x00 }, { 0x48bd, 0xa0 }, { 0x48bf, 0xa1 }, { 0x49ff, 0x78 }, + { 0x4baf, 0x1a }, { 0x4bc7, 0x1a }, { 0x4d2a, 0x07 }, { 0x4d80, 0x06 }, + { 0x4d81, 0xa4 }, { 0x4d82, 0x07 }, { 0x4e39, 0x07 }, { 0x4e7b, 0x64 }, + { 0x4e8e, 0x0e }, { 0x4e9c, 0x01 }, { 0x4ea0, 0x01 }, { 0x4ea1, 0x03 }, + { 0x4ea5, 0x00 }, { 0x4ea7, 0x00 }, { 0x4f05, 0x04 }, { 0x4f0d, 0x04 }, + { 0x4f15, 0x04 }, { 0x4f19, 0x01 }, { 0x4f20, 0x01 }, { 0x4f66, 0x0f }, + { 0x500f, 0x01 }, { 0x5225, 0x2f }, { 0x5227, 0x1e }, { 0x5231, 0x19 }, + { 0x5245, 0x07 }, { 0x5252, 0x07 }, { 0x5253, 0x08 }, { 0x5254, 0x07 }, + { 0x5255, 0xb4 }, { 0x5272, 0x04 }, { 0x5273, 0x2e }, { 0x5282, 0x04 }, + { 0x5283, 0x2e }, { 0x5286, 0x00 }, { 0x5287, 0x5d }, { 0x1433, 0x00 }, + { 0x3c18, 0x00 }, { 0x100e, 0x00 }, { 0x100f, 0x00 }, { 0x10c2, 0x00 }, + { 0x10d0, 0x0a }, { 0x10d4, 0x00 }, { 0x10d5, 0xc5 }, + { 0x2020, 0x01 }, { 0x2f05, 0x01 }, { 0x2f06, 0x09 }, + { 0x2f07, 0x7a }, { 0x3071, 0x00 }, { 0x2100, 0x08 }, +}; + +static const struct mlx7502x_regval_list mlx7502x_75027_init_cfg[] = { + { 0x477d, 0xd6 }, { 0x4954, 0x00 }, { 0x4955, 0xa0 }, { 0x4957, 0xa1 }, + { 0x4984, 0x00 }, { 0x4985, 0xa0 }, { 0x4987, 0xa1 }, { 0x49b9, 0x78 }, + { 0x49c3, 0x3c }, { 0x49c9, 0x76 }, { 0x49d3, 0x3f }, { 0x49dc, 0x00 }, + { 0x49dd, 0xa0 }, { 0x49df, 0xa1 }, { 0x49ef, 0x78 }, { 0x49f9, 0x3c }, + { 0x4a05, 0x3c }, { 0x4a0b, 0x76 }, { 0x4a11, 0x3f }, { 0x4a1a, 0x00 }, + { 0x4a1b, 0xa0 }, { 0x4a1d, 0xa1 }, { 0x4a1f, 0x78 }, { 0x4a29, 0x3c }, + { 0x4a4a, 0x00 }, { 0x4a4b, 0xa0 }, { 0x4a4d, 0xa1 }, { 0x4a7a, 0x00 }, + { 0x4a7b, 0xa0 }, { 0x4a7d, 0xa1 }, { 0x4aee, 0x00 }, { 0x4aef, 0xa0 }, + { 0x4af1, 0xa1 }, { 0x4b2e, 0x00 }, { 0x4b2f, 0xa0 }, { 0x4b31, 0xa1 }, + { 0x4b5a, 0x00 }, { 0x4b5b, 0xa0 }, { 0x4b5d, 0xa1 }, { 0x4b86, 0x00 }, + { 0x4b87, 0xa0 }, { 0x4b89, 0xa1 }, { 0x4b9f, 0x1a }, { 0x4bb7, 0x1a }, + { 0x4bcf, 0x1a }, { 0x4bee, 0x00 }, { 0x4bef, 0xa0 }, { 0x4bf1, 0xa1 }, + { 0x4bf7, 0x1a }, { 0x4c01, 0x1a }, { 0x4c58, 0x00 }, { 0x4c59, 0xa0 }, + { 0x4c5b, 0xa1 }, { 0x4c6e, 0x00 }, { 0x4c6f, 0xa0 }, { 0x4c71, 0xa1 }, + { 0x4c7a, 0x01 }, { 0x4c7b, 0x35 }, { 0x4cf2, 0x07 }, { 0x4cf3, 0xc9 }, + { 0x4cf8, 0x06 }, { 0x4cf9, 0x9b }, { 0x4cfa, 0x07 }, { 0x4cfb, 0xae }, + { 0x4cfe, 0x07 }, { 0x4cff, 0xc9 }, { 0x4d04, 0x06 }, { 0x4d05, 0x98 }, + { 0x4d06, 0x07 }, { 0x4d07, 0xb1 }, { 0x4d18, 0x06 }, { 0x4d19, 0xa4 }, + { 0x4d1a, 0x07 }, { 0x4d1b, 0x49 }, { 0x4d1e, 0x07 }, { 0x4d1f, 0xc9 }, + { 0x4d2b, 0xc9 }, { 0x4d4a, 0x07 }, { 0x4d4b, 0xc9 }, { 0x4d50, 0x06 }, + { 0x4d51, 0x9b }, { 0x4d52, 0x07 }, { 0x4d53, 0xae }, { 0x4d56, 0x07 }, + { 0x4d57, 0xc9 }, { 0x4d5c, 0x06 }, { 0x4d5d, 0x98 }, { 0x4d5e, 0x07 }, + { 0x4d5f, 0xb1 }, { 0x4d70, 0x06 }, { 0x4d71, 0xa4 }, { 0x4d72, 0x07 }, + { 0x4d73, 0x49 }, { 0x4d78, 0x06 }, { 0x4d79, 0xa4 }, { 0x4d7a, 0x07 }, + { 0x4d7b, 0xae }, { 0x4d7c, 0x1f }, { 0x4d7d, 0xff }, { 0x4d7e, 0x1f }, + { 0x4d7f, 0xff }, { 0x4d83, 0xae }, { 0x4d84, 0x1f }, { 0x4d85, 0xff }, + { 0x4d86, 0x1f }, { 0x4d87, 0xff }, +}; + +static const struct mlx7502x_link_freq_list mlx75027_link_freq_cfg = { + .link_freq = { + 300000000, + 600000000, + 704000000, + 800000000, + 904000000, + 960000000 + }, + .addr = { + 0x100c, 0x100d, 0x1016, 0x1017, 0x1045, 0x1047, + 0x1060, 0x1071, 0x10c3, 0x10c4, 0x10c5 + }, + .data = { + { /* lane 2 */ + { 0x02, 0x58, 0x09, 0x99, 0x4b, 0x02, + 0x01, 0x0c, 0x1c, 0x01, 0x3a }, /* 300MBps */ + { 0x04, 0xb0, 0x04, 0xcc, 0x4b, 0x02, + 0x00, 0x06, 0x0f, 0x00, 0x9d }, /* 600MBps */ + { 0x05, 0x80, 0x04, 0x17, 0x58, 0x02, + 0x00, 0x06, 0x0d, 0x00, 0x86 }, /* 704MBps */ + { 0x06, 0x40, 0x03, 0x99, 0x64, 0x02, + 0x00, 0x06, 0x0b, 0x00, 0x75 }, /* 800MBps */ + { 0x07, 0x10, 0x03, 0x2f, 0x71, 0x00, + 0x00, 0x06, 0x0a, 0x00, 0x68 }, /* 904MBps */ + { 0x07, 0x80, 0x03, 0x00, 0x78, 0x02, + 0x00, 0x06, 0x0a, 0x00, 0x62 }, /* 960MBps */ + }, { /* lane 4 */ + { 0x04, 0xb0, 0x09, 0x99, 0x4b, 0x02, + 0x01, 0x0c, 0x1c, 0x01, 0x3a }, /* 300MBps */ + { 0x09, 0x60, 0x04, 0xcc, 0x4b, 0x02, + 0x00, 0x06, 0x0f, 0x00, 0x9d }, /* 600MBps */ + { 0x0b, 0x00, 0x04, 0x17, 0x58, 0x02, + 0x00, 0x06, 0x0d, 0x00, 0x86 }, /* 704MBps */ + { 0x0c, 0x80, 0x03, 0x99, 0x64, 0x02, + 0x00, 0x06, 0x0b, 0x00, 0x75 }, /* 800MBps */ + { 0x0e, 0x20, 0x03, 0x2f, 0x71, 0x00, + 0x00, 0x06, 0x0a, 0x00, 0x68 }, /* 904MBps */ + { 0x0f, 0x00, 0x03, 0x00, 0x78, 0x00, + 0x00, 0x06, 0x0a, 0x00, 0x62 }, /* 960MBps */ + }, + }, + .hmax = { + { /* lane 2 */ + { 0x0e78, 0x1a80 }, /* 300MBps */ + { 0x0750, 0x0d54 }, /* 600MBps */ + { 0x0640, 0x0b60 }, /* 704MBps */ + { 0x0584, 0x0a06 }, /* 800MBps */ + { 0x04e8, 0x08e6 }, /* 904MBps */ + { 0x049e, 0x0860 }, /* 960MBps */ + }, + { /* lane 4 */ + { 0x0860, 0x0e60 }, /* 300MBps */ + { 0x0444, 0x0744 }, /* 600MBps */ + { 0x03a8, 0x0636 }, /* 704MBps */ + { 0x033a, 0x057a }, /* 800MBps */ + { 0x02e2, 0x0514 }, /* 904MBps */ + { 0x02b6, 0x0514 }, /* 960MBps */ + }, + } +}; + +/* VGA sensor */ +static const struct mlx7502x_sensor_desc mlx75027 = { + .init_cfg = mlx7502x_75027_init_cfg, + .init_cfg_size = ARRAY_SIZE(mlx7502x_75027_init_cfg), + .link_freq_cfg = &mlx75027_link_freq_cfg, + .width = VGA_WIDTH, + .height = VGA_HEIGHT, +}; + +static const struct mlx7502x_regval_list mlx7502x_75026_init_cfg[] = { + { 0x477c, 0x0a }, { 0x477d, 0xd4 }, { 0x4964, 0x00 }, { 0x4965, 0xa0 }, + { 0x4967, 0xa1 }, { 0x4994, 0x00 }, { 0x4995, 0xa0 }, { 0x4997, 0xa1 }, + { 0x49c9, 0x78 }, { 0x49d3, 0x3c }, { 0x49d9, 0x76 }, { 0x49e3, 0x3f }, + { 0x49ec, 0x00 }, { 0x49ed, 0xa0 }, { 0x49ef, 0xa1 }, { 0x4a09, 0x3c }, + { 0x4a0f, 0x78 }, { 0x4a15, 0x3c }, { 0x4a1b, 0x76 }, { 0x4a21, 0x3f }, + { 0x4a2a, 0x00 }, { 0x4a2b, 0xa0 }, { 0x4a2d, 0xa1 }, { 0x4a2f, 0x78 }, + { 0x4a39, 0x3c }, { 0x4a5a, 0x00 }, { 0x4a5b, 0xa0 }, { 0x4a5d, 0xa1 }, + { 0x4a8a, 0x00 }, { 0x4a8b, 0xa0 }, { 0x4a8d, 0xa1 }, { 0x4afe, 0x00 }, + { 0x4aff, 0xa0 }, { 0x4b01, 0xa1 }, { 0x4b3e, 0x00 }, { 0x4b3f, 0xa0 }, + { 0x4b41, 0xa1 }, { 0x4b6a, 0x00 }, { 0x4b6b, 0xa0 }, { 0x4b6d, 0xa1 }, + { 0x4b96, 0x00 }, { 0x4b97, 0xa0 }, { 0x4b99, 0xa1 }, { 0x4bbf, 0x1a }, + { 0x4bd7, 0x1a }, { 0x4bdf, 0x1a }, { 0x4bfe, 0x00 }, { 0x4bff, 0xa0 }, + { 0x4c01, 0xa1 }, { 0x4c07, 0x1a }, { 0x4c11, 0x1a }, { 0x4c68, 0x00 }, + { 0x4c69, 0xa0 }, { 0x4c6b, 0xa1 }, { 0x4c7e, 0x00 }, { 0x4c7f, 0xa0 }, + { 0x4c81, 0xa1 }, { 0x4c8a, 0x01 }, { 0x4c8b, 0x35 }, { 0x4d02, 0x07 }, + { 0x4d03, 0xc9 }, { 0x4d08, 0x06 }, { 0x4d09, 0x9b }, { 0x4d0a, 0x07 }, + { 0x4d0b, 0xae }, { 0x4d0e, 0x07 }, { 0x4d0f, 0xc9 }, { 0x4d14, 0x06 }, + { 0x4d15, 0x98 }, { 0x4d16, 0x07 }, { 0x4d17, 0xb1 }, { 0x4d28, 0x06 }, + { 0x4d29, 0xa4 }, { 0x4d2b, 0xa9 }, { 0x4d2e, 0x07 }, { 0x4d2f, 0xc9 }, + { 0x4d3a, 0x07 }, { 0x4d3b, 0xc9 }, { 0x4d5a, 0x07 }, { 0x4d5b, 0xc9 }, + { 0x4d60, 0x06 }, { 0x4d61, 0x9b }, { 0x4d62, 0x07 }, { 0x4d63, 0xae }, + { 0x4d66, 0x07 }, { 0x4d67, 0xc9 }, { 0x4d6c, 0x06 }, { 0x4d6d, 0x98 }, + { 0x4d6e, 0x07 }, { 0x4d6f, 0xb1 }, { 0x4d83, 0xa9 }, { 0x4d88, 0x06 }, + { 0x4d89, 0xa4 }, { 0x4d8a, 0x07 }, { 0x4d8b, 0xae }, { 0x4d8c, 0x1f }, + { 0x4d8d, 0xff }, { 0x4d8e, 0x1f }, { 0x4d8f, 0xff }, { 0x4d90, 0x06 }, + { 0x4d91, 0xa4 }, { 0x4d92, 0x07 }, { 0x4d93, 0xae }, { 0x4d94, 0x1f }, + { 0x4d95, 0xff }, { 0x4d96, 0x1f }, { 0x4d97, 0xff }, +}; + +static const struct mlx7502x_link_freq_list mlx75026_link_freq_cfg = { + .link_freq = { + 300000000, + 600000000, + 704000000, + 800000000, + 904000000, + 960000000 + }, + .addr = { + 0x100c, 0x100d, 0x1016, 0x1017, 0x1045, 0x1047, + 0x1060, 0x1071, 0x10c3, 0x10c4, 0x10c5 + }, + .data = { + { /* lane 2 */ + { 0x02, 0x58, 0x09, 0x99, 0x4b, 0x02, + 0x01, 0x0c, 0x1c, 0x01, 0x3a }, /* 300MBps */ + { 0x04, 0xb0, 0x04, 0xcc, 0x4b, 0x02, + 0x00, 0x06, 0x0f, 0x00, 0x9d }, /* 600MBps */ + { 0x05, 0x80, 0x04, 0x17, 0x58, 0x02, + 0x00, 0x06, 0x0d, 0x00, 0x86 }, /* 704MBps */ + { 0x06, 0x40, 0x03, 0x99, 0x64, 0x02, + 0x00, 0x06, 0x0b, 0x00, 0x75 }, /* 800MBps */ + { 0x07, 0x10, 0x03, 0x2f, 0x71, 0x00, + 0x00, 0x06, 0x0a, 0x00, 0x68 }, /* 904MBps */ + { 0x07, 0x80, 0x03, 0x00, 0x78, 0x02, + 0x00, 0x06, 0x0a, 0x00, 0x62 }, /* 960MBps */ + }, { /* lane 4 */ + { 0x04, 0xb0, 0x09, 0x99, 0x4b, 0x02, + 0x01, 0x0c, 0x1c, 0x01, 0x3a }, /* 300MBps */ + { 0x09, 0x60, 0x04, 0xcc, 0x4b, 0x02, + 0x00, 0x06, 0x0f, 0x00, 0x9d }, /* 600MBps */ + { 0x0b, 0x00, 0x04, 0x17, 0x58, 0x02, + 0x00, 0x06, 0x0d, 0x00, 0x86 }, /* 704MBps */ + { 0x0c, 0x80, 0x03, 0x99, 0x64, 0x02, + 0x00, 0x06, 0x0b, 0x00, 0x75 }, /* 800MBps */ + { 0x0e, 0x20, 0x03, 0x2f, 0x71, 0x00, + 0x00, 0x06, 0x0a, 0x00, 0x68 }, /* 904MBps */ + { 0x0f, 0x00, 0x03, 0x00, 0x78, 0x00, + 0x00, 0x06, 0x0a, 0x00, 0x62 }, /* 960MBps */ + }, + }, + .hmax = { + { /* lane 2 */ + { 0x0878, 0x0e80 }, /* 300MBps */ + { 0x0450, 0x0754 }, /* 600MBps */ + { 0x03b2, 0x0644 }, /* 704MBps */ + { 0x0344, 0x0586 }, /* 800MBps */ + { 0x02ea, 0x0514 }, /* 904MBps */ + { 0x02be, 0x0514 }, /* 960MBps */ + }, { /* lane 4 */ + { 0x0560, 0x0860 }, /* 300MBps */ + { 0x02c4, 0x0444 }, /* 600MBps */ + { 0x02b6, 0x03a8 }, /* 704MBps */ + { 0x02b6, 0x033a }, /* 800MBps */ + { 0x02b6, 0x02e2 }, /* 904MBps */ + { 0x02b6, 0x02b6 }, /* 960MBps */ + }, + } +}; + +/* QVGA sensor */ +static const struct mlx7502x_sensor_desc mlx75026 = { + .init_cfg = mlx7502x_75026_init_cfg, + .init_cfg_size = ARRAY_SIZE(mlx7502x_75026_init_cfg), + .link_freq_cfg = &mlx75026_link_freq_cfg, + .width = QVGA_WIDTH, + .height = QVGA_HEIGHT, +}; + +static const struct mlx7502x_binning_mode binning_mode[] = { + { .reg_value = 0, .ratio = 1, .width_step = 4, .height_step = 2, + .width_min = 8, .height_min = 2 }, + { .reg_value = 1, .ratio = 2, .width_step = 8, .height_step = 2, + .width_min = 16, .height_min = 2 }, + { .reg_value = 2, .ratio = 4, .width_step = 16, .height_step = 4, + .width_min = 32, .height_min = 4 }, + { .reg_value = 3, .ratio = 8, .width_step = 32, .height_step = 8, + .width_min = 64, .height_min = 8 }, +}; + +static const struct mlx7502x_fmod_list mlx7502x_fmod_cfg[] = { + { .fmod = 100000000, .divselpre = 0, .divsel = 0, }, + { .fmod = 75000000, .divselpre = 0, .divsel = 0, }, + { .fmod = 74000000, .divselpre = 1, .divsel = 0, }, + { .fmod = 51000000, .divselpre = 1, .divsel = 0, }, + { .fmod = 50000000, .divselpre = 0, .divsel = 1, }, + { .fmod = 38000000, .divselpre = 0, .divsel = 1, }, + { .fmod = 37000000, .divselpre = 1, .divsel = 1, }, + { .fmod = 21000000, .divselpre = 1, .divsel = 1, }, + { .fmod = 2000000, .divselpre = 0, .divsel = 2, }, + { .fmod = 1000000, .divselpre = 0, .divsel = 2, }, + { .fmod = 1000000, .divselpre = 1, .divsel = 2, }, + { .fmod = 1000000, .divselpre = 1, .divsel = 2, }, + { .fmod = 900000, .divselpre = 2, .divsel = 2, }, + { .fmod = 500000, .divselpre = 2, .divsel = 2, }, + { .fmod = 400000, .divselpre = 3, .divsel = 2, }, +}; + +static const char * const mlx7502x_ctrl_output[] = { + [V4L2_MLX7502X_OUTPUT_MODE_A_MINUS_B] = "A minus B", + [V4L2_MLX7502X_OUTPUT_MODE_A_PLUS_B] = "A plus B", + [V4L2_MLX7502X_OUTPUT_MODE_A] = "Raw A", + [V4L2_MLX7502X_OUTPUT_MODE_B] = "Raw B", + [V4L2_MLX7502X_OUTPUT_MODE_A_AND_B] = "Raw A and Raw B", +}; + +static const struct mlx7502x_output_mode mlx7502x_output_mode_cfg[] = { + [V4L2_MLX7502X_OUTPUT_MODE_A_MINUS_B] = { + .hmax_index = 0, .width_mult = 1 + }, + [V4L2_MLX7502X_OUTPUT_MODE_A_PLUS_B] = { + .hmax_index = 0, .width_mult = 1 + }, + [V4L2_MLX7502X_OUTPUT_MODE_A] = { + .hmax_index = 0, .width_mult = 1 + }, + [V4L2_MLX7502X_OUTPUT_MODE_B] = { + .hmax_index = 0, .width_mult = 1 + }, + [V4L2_MLX7502X_OUTPUT_MODE_A_AND_B] = { + .hmax_index = 1, .width_mult = 2 + } +}; + +static inline struct mlx7502x *to_mlx7502x(struct v4l2_subdev *sd) +{ + return container_of(sd, struct mlx7502x, sd); +} + +static int mlx7502x_read(struct v4l2_subdev *sd, u16 reg, u8 *val, int val_size) +{ + int ret; + unsigned char data_w[2]; + struct i2c_client *client = v4l2_get_subdevdata(sd); + + struct i2c_msg msg[] = { + { + .addr = client->addr, + .flags = 0, + .len = 2, + .buf = data_w, + }, { + .addr = client->addr, + .flags = I2C_M_RD, + .len = val_size, + .buf = val, + } + }; + + /* write reg address into first msg */ + put_unaligned_be16(reg, data_w); + + /* Using transfer allows skip STOP between messages + * so we have repeated Start here + */ + ret = i2c_transfer(client->adapter, msg, 2); + + return ret != 2 ? -EIO : 0; +} + +static int mlx7502x_write(struct v4l2_subdev *sd, u8 *data, u32 data_size, + int *err) +{ + int ret; + struct i2c_client *client = v4l2_get_subdevdata(sd); + + if (err && *err) + return *err; + + dev_dbg(&client->dev, "%*ph\n", data_size, data); + + ret = i2c_master_send(client, data, data_size); + if (ret < 0) { + dev_dbg(&client->dev, "%s: i2c write error, reg: 0x%x%x\n", + __func__, data[0], data[1]); + + return ret; + } + + return ret != data_size ? -EIO : 0; +} + +static int mlx7502x_write8(struct v4l2_subdev *sd, u16 reg, u8 val, int *err) +{ + unsigned char data[3]; + + put_unaligned_be16(reg, data); + data[2] = val; + + return mlx7502x_write(sd, data, 3, err); +} + +static int mlx7502x_write16(struct v4l2_subdev *sd, u16 reg, u16 val, int *err) +{ + unsigned char data[4]; + + put_unaligned_be16(reg, data); + put_unaligned_be16(val, data + 2); + + return mlx7502x_write(sd, data, 4, err); +} + +static int mlx7502x_write24(struct v4l2_subdev *sd, u16 reg, u32 val, int *err) +{ + unsigned char data[5]; + + put_unaligned_be16(reg, data); + put_unaligned_be24(val, data + 2); + + return mlx7502x_write(sd, data, 5, err); +} + +static int mlx7502x_write32(struct v4l2_subdev *sd, u16 reg, u32 val, int *err) +{ + unsigned char data[6]; + + put_unaligned_be16(reg, data); + put_unaligned_be32(val, data + 2); + + return mlx7502x_write(sd, data, 6, err); +} + +static int mlx7502x_write_regval(struct v4l2_subdev *sd, + const struct mlx7502x_regval_list *regs, + int array_size) +{ + int i, ret; + + for (i = 0; i < array_size; i++) { + ret = mlx7502x_write8(sd, regs[i].addr, regs[i].data, NULL); + if (ret < 0) + return ret; + } + + return 0; +} + +static int mlx7502x_write_array(struct v4l2_subdev *sd, const u16 *reg, + const u8 *data, int size, int *err) +{ + int i, ret; + + for (i = 0; i < size; i++) { + ret = mlx7502x_write8(sd, reg[i], data[i], err); + if (ret < 0) + return ret; + } + + return 0; +} + +/* + * ***************************************************************************** + * PM + * ***************************************************************************** + */ +static int mlx7502x_power_off(struct mlx7502x *sensor) +{ + gpiod_set_value_cansleep(sensor->reset, 0); + + clk_disable_unprepare(sensor->xclk); + + regulator_bulk_disable(MLX7502X_NUM_SUPPLIES, sensor->supplies); + + dev_dbg(sensor->dev, "power off\n"); + + return 0; +} + +static int __maybe_unused mlx7502x_runtime_resume(struct device *dev) +{ + struct v4l2_subdev *sd = dev_get_drvdata(dev); + struct mlx7502x *sensor = to_mlx7502x(sd); + int ret; + + gpiod_set_value_cansleep(sensor->reset, 0); + + ret = regulator_bulk_enable(MLX7502X_NUM_SUPPLIES, sensor->supplies); + if (ret) { + dev_err(sensor->dev, "failed to enable supply: %d\n", ret); + return ret; + } + + ret = clk_prepare_enable(sensor->xclk); + if (ret) { + dev_err(sensor->dev, "failed to enable external clock: %d\n", + ret); + goto fail_clk; + } + + gpiod_set_value_cansleep(sensor->reset, 1); + msleep(MLX7502X_RESET_DELAY_MS); + + dev_dbg(sensor->dev, "power on\n"); + + ret = mlx7502x_write_regval(sd, mlx7502x_common_init_cfg, + ARRAY_SIZE(mlx7502x_common_init_cfg)); + if (ret < 0) { + dev_err(sensor->dev, "failed to write init_cfg\n"); + goto fail_clk; + } + + ret = mlx7502x_write_regval(sd, sensor->cur_desc->init_cfg, + sensor->cur_desc->init_cfg_size); + if (ret < 0) { + dev_err(sensor->dev, "failed to write sensor specific init_cfg\n"); + goto fail_clk; + } + + return 0; + +fail_clk: + regulator_bulk_disable(MLX7502X_NUM_SUPPLIES, sensor->supplies); + return ret; +} + +static int __maybe_unused mlx7502x_runtime_suspend(struct device *dev) +{ + struct v4l2_subdev *sd = dev_get_drvdata(dev); + struct mlx7502x *sensor = to_mlx7502x(sd); + + mlx7502x_power_off(sensor); + + return 0; +} + +/* + * ***************************************************************************** + * Subdev operations + * ***************************************************************************** + */ +#ifdef CONFIG_VIDEO_ADV_DEBUG +static int mlx7502x_get_register(struct v4l2_subdev *sd, + struct v4l2_dbg_register *reg) +{ + u8 val[4]; + int ret; + + /* v4l2-dbg set it to 0 */ + if (reg->size == 0) + reg->size = 1; + + ret = mlx7502x_read(sd, reg->reg & 0xffff, val, reg->size); + if (ret < 0) + return ret; + + if (reg->size == 1) + reg->val = val[0]; + else if (reg->size == 2) + reg->val = get_unaligned_be16(val); + else if (reg->size == 3) + reg->val = get_unaligned_be24(val); + else if (reg->size == 4) + reg->val = get_unaligned_be32(val); + else + return -EINVAL; + + return 0; +} + +static int mlx7502x_set_register(struct v4l2_subdev *sd, + const struct v4l2_dbg_register *reg) +{ + if (reg->size <= 1) + return mlx7502x_write8(sd, reg->reg & 0xffff, reg->val, NULL); + else if (reg->size == 2) + return mlx7502x_write16(sd, reg->reg & 0xffff, reg->val, NULL); + else if (reg->size == 3) + return mlx7502x_write24(sd, reg->reg & 0xffff, reg->val, NULL); + else if (reg->size == 4) + return mlx7502x_write32(sd, reg->reg & 0xffff, reg->val, NULL); + + return -EINVAL; +} +#endif + +/* from us into sensor ticks */ +static unsigned int mlx7502x_from_us(struct mlx7502x *sensor, u32 us) +{ + return DIV_ROUND_CLOSEST(us * MLX7502X_CLK_RATE_MHZ, sensor->hmax); +} + +static unsigned int mlx7502x_to_us(struct mlx7502x *sensor, u32 reg) +{ + return DIV_ROUND_CLOSEST(reg * sensor->hmax, MLX7502X_CLK_RATE_MHZ); +} + +static int mlx7502x_set_link_freq(struct mlx7502x *sensor) +{ + struct v4l2_subdev *sd = &sensor->sd; + const struct mlx7502x_link_freq_list *lfc; + int link_freq = sensor->link_freq->val; + struct v4l2_mbus_config_mipi_csi2 *bus = &sensor->ep.bus.mipi_csi2; + u8 cont_clock, lane_n = bus->num_data_lanes; + u32 pretime; + int ret; + + /* lane */ + ret = mlx7502x_write8(sd, MLX7502X_DATA_LANE_CONFIG_REG, + lane_n - 1, NULL); + + /* link freq */ + lfc = sensor->cur_desc->link_freq_cfg; + ret = mlx7502x_write_array(sd, lfc->addr, + lfc->data[lane_n >> 2][link_freq], + MLX7502X_LINK_FREQ_REG_N, &ret); + + /* clock continuous mode if MIPI receiver requires it */ + cont_clock = bus->flags & V4L2_MBUS_CSI2_NONCONTINUOUS_CLOCK ? 1u : 0u; + ret = mlx7502x_write8(sd, MLX7502X_CONTINUOUS_REG, cont_clock, &ret); + + ret = mlx7502x_write16(sd, MLX7502X_HMAX_REG, sensor->hmax, &ret); + + /* timings which depends on hmax and mipi config */ + ret = mlx7502x_write8(sd, MLX7502X_PLLSETUP_REG, + mlx7502x_from_us(sensor, MLX7502X_PLLSETUP_US) + + MLX7502X_PLLSETUP_TICKS, &ret); + + pretime = mlx7502x_from_us(sensor, MLX7502X_PRETIME_US); + ret = mlx7502x_write16(sd, MLX7502X_PRETIME_REG, pretime, &ret); + + return mlx7502x_write24(sd, MLX7502X_RANDNM0_REG, + pretime * sensor->hmax - 1070 - 2098, &ret); +} + +static int mlx7502x_update_output_format(struct mlx7502x *sensor) +{ + struct v4l2_rect *crop = &sensor->crop; + struct v4l2_subdev *sd = &sensor->sd; + int ret; + + ret = mlx7502x_write16(sd, MLX7502X_COLUMN_START_REG, + crop->left + 1u, NULL); + ret = mlx7502x_write16(sd, MLX7502X_COLUMN_LEN_REG, + crop->width, &ret); + ret = mlx7502x_write16(sd, MLX7502X_ROW_START_REG, + MLX7502X_ROW_START(crop->top), &ret); + ret = mlx7502x_write16(sd, MLX7502X_ROW_END_REG, + MLX7502X_ROW_END(crop->top, crop->height), &ret); + ret = mlx7502x_write8(sd, MLX7502X_BINNING_REG, + sensor->binning_mode->reg_value, &ret); + return mlx7502x_write8(sd, MLX7502X_OUTPUT_MODE_REG, + sensor->output_mode->val, &ret); +} + +static int __mlx7502x_set_frame_interval(struct mlx7502x *sensor, + struct v4l2_fract fi, bool pm_en) +{ + u32 req_fi_us, min_fi_us, readout_ticks, tint_sum = 0; + int ret, i, fi_register = 0; + + if (fi.denominator == 0) + return -EINVAL; + + readout_ticks = MLX7502X_ROW_END(sensor->crop.top, sensor->crop.height) + - MLX7502X_ROW_START(sensor->crop.top) + 1; + + for (i = 0; i < sensor->phase_seq->elems; i++) + tint_sum += sensor->tint->p_cur.p_u16[i]; + + min_fi_us = MLX7502X_PLLSETUP_US + + mlx7502x_to_us(sensor, MLX7502X_PLLSETUP_TICKS) + + tint_sum + + (mlx7502x_to_us(sensor, + readout_ticks + MLX7502X_FRAME_ADD_TICKS) + + MLX7502X_PRETIME_US) + * sensor->phase_seq->elems; + + req_fi_us = MICRO * fi.numerator / fi.denominator; + + if (req_fi_us < min_fi_us) { + dev_err(sensor->dev, "Too small frame interval: min = %dus, requested = %dus\n", + min_fi_us, req_fi_us); + return -EINVAL; + } + + sensor->frame_interval = fi; + + if (pm_en && !pm_runtime_get_if_in_use(sensor->dev)) + return 0; + + fi_register = mlx7502x_from_us(sensor, req_fi_us); + ret = mlx7502x_write32(&sensor->sd, MLX7502X_FRAME_TIME_REG, + fi_register, NULL); + + if (pm_en) + pm_runtime_put_autosuspend(sensor->dev); + + return ret; +} + +static int mlx7502x_s_stream(struct v4l2_subdev *sd, int on) +{ + struct mlx7502x *sensor = to_mlx7502x(sd); + int ret = 0; + + mutex_lock(&sensor->lock); + + if (on && !sensor->streaming) { + ret = pm_runtime_resume_and_get(sensor->dev); + if (ret < 0) { + mutex_unlock(&sensor->lock); + return ret; + } + + ret = __v4l2_ctrl_handler_setup(sd->ctrl_handler); + if (ret < 0) + goto error_stream; + /* + * the registers below depends on hmax, + * which is configured in controls + */ + ret = mlx7502x_set_link_freq(sensor); + if (ret < 0) + goto error_stream; + ret = mlx7502x_update_output_format(sensor); + if (ret < 0) + goto error_stream; + ret = __mlx7502x_set_frame_interval(sensor, + sensor->frame_interval, + false); + if (ret < 0) + goto error_stream; + + ret = mlx7502x_write8(sd, MLX7502X_STREAM_EN_REG, 1u, NULL); + if (ret < 0) + goto error_stream; + + sensor->streaming = 1u; + dev_dbg(sensor->dev, "stream enabled\n"); + + /* we need to wait to stabilize the system after streaming on */ + msleep(MLX7502X_STREAMING_DELAY_MS); + } else if (!on && sensor->streaming) { + sensor->streaming = 0u; + ret = mlx7502x_write8(sd, MLX7502X_STREAM_EN_REG, 0u, NULL); + /* we need to wait in case last buffer is sending */ + msleep(MLX7502X_STREAMING_DELAY_MS); + dev_dbg(sensor->dev, "stream disabled\n"); + + pm_runtime_mark_last_busy(sensor->dev); + pm_runtime_put_autosuspend(sensor->dev); + } + + mutex_unlock(&sensor->lock); + return ret; + +error_stream: + dev_err(sensor->dev, "failed to enable stream(%d)\n", ret); + pm_runtime_put(sensor->dev); + mutex_unlock(&sensor->lock); + return ret; +} + +static int mlx7502x_get_frame_interval(struct v4l2_subdev *sd, + struct v4l2_subdev_frame_interval *fi) +{ + struct mlx7502x *sensor = to_mlx7502x(sd); + + fi->interval = sensor->frame_interval; + + return 0; +} + +static int mlx7502x_set_frame_interval(struct v4l2_subdev *sd, + struct v4l2_subdev_frame_interval *sfi) +{ + struct mlx7502x *sensor = to_mlx7502x(sd); + int ret; + + mutex_lock(&sensor->lock); + ret = __mlx7502x_set_frame_interval(sensor, sfi->interval, true); + mutex_unlock(&sensor->lock); + + return ret; +} + +static int mlx7502x_fill_format(struct mlx7502x *sensor, + struct v4l2_mbus_framefmt *format, + struct v4l2_rect *src_compose) +{ + int width_mult; + int output_mode = sensor->output_mode->val; + + mutex_lock(&sensor->lock); + + width_mult = mlx7502x_output_mode_cfg[output_mode].width_mult; + + memset(format, 0, sizeof(*format)); + format->code = MEDIA_BUS_FMT_Y12_1X12; + format->width = width_mult * src_compose->width; + format->height = src_compose->height; + format->field = V4L2_FIELD_NONE; + format->colorspace = V4L2_COLORSPACE_RAW; + format->ycbcr_enc = V4L2_YCBCR_ENC_DEFAULT; + format->quantization = V4L2_QUANTIZATION_FULL_RANGE; + format->xfer_func = V4L2_XFER_FUNC_NONE; + + mutex_unlock(&sensor->lock); + + return 0; +} + +static int mlx7502x_init_cfg(struct v4l2_subdev *sd, + struct v4l2_subdev_state *sd_state) +{ + struct mlx7502x *sensor = to_mlx7502x(sd); + + /* copying active into try */ + sd_state->pads->try_crop = sensor->crop; + sd_state->pads->try_compose = sensor->compose; + return mlx7502x_fill_format(sensor, + &sd_state->pads->try_fmt, + &sensor->compose); +} + +static int mlx7502x_enum_mbus_code(struct v4l2_subdev *sd, + struct v4l2_subdev_state *sd_state, + struct v4l2_subdev_mbus_code_enum *code) +{ + if (code->index > 0) + return -EINVAL; + + code->code = MEDIA_BUS_FMT_Y12_1X12; + + return 0; +} + +static int mlx7502x_set_get_format(struct v4l2_subdev *sd, + struct v4l2_subdev_state *sd_state, + struct v4l2_subdev_format *format) +{ + struct mlx7502x *sensor = to_mlx7502x(sd); + struct v4l2_rect *src_compose; + + if (format->pad != 0) + return -EINVAL; + + if (format->which == V4L2_SUBDEV_FORMAT_TRY) + src_compose = &sd_state->pads->try_compose; + else + src_compose = &sensor->compose; + + return mlx7502x_fill_format(sensor, &format->format, src_compose); +} + +static const struct mlx7502x_binning_mode * +mlx7502x_find_binning_mode(struct v4l2_rect *dst_crop, + struct v4l2_rect *dst_compose) +{ + int i; + const struct mlx7502x_binning_mode *bin_mode; + u8 ratio = dst_crop->width / dst_compose->width; + + for (i = 0; i < ARRAY_SIZE(binning_mode); i++) { + bin_mode = &binning_mode[i]; + + if (bin_mode->ratio == ratio) + break; + } + + return bin_mode; +} + +static void mlx7502x_set_crop(struct mlx7502x *sensor, + struct v4l2_subdev_selection *sel, + struct v4l2_rect *dst_crop, + struct v4l2_rect *dst_compose, + const struct mlx7502x_binning_mode *bin_mode) +{ + u32 w, h; + + /* + * cropping will always be in native size, + * even if binning was applied + */ + w = sensor->cur_desc->width; + h = sensor->cur_desc->height; + + v4l_bound_align_image(&sel->r.width, bin_mode->width_min, w, + bin_mode->width_step, + &sel->r.height, bin_mode->height_min, h, + bin_mode->height_step, 0); + + v4l_bound_align_image(&sel->r.left, MLX7502X_LEFT_MIN, w - sel->r.width, + MLX7502X_LEFT_STEP, + &sel->r.top, MLX7502X_TOP_MIN, h - sel->r.height, + MLX7502X_TOP_STEP, 0); + /* fill active or try */ + *dst_crop = sel->r; + /* update binning w/h, as actual crop size could changed */ + dst_compose->top = 0; + dst_compose->left = 0; + dst_compose->width = dst_crop->width / bin_mode->ratio; + dst_compose->height = dst_crop->height / bin_mode->ratio; +} + +/* + * Binning is applied after cropping inside the sensor + */ +static void mlx7502x_set_compose(struct mlx7502x *sensor, + struct v4l2_subdev_selection *sel, + struct v4l2_rect *dst_crop, + struct v4l2_rect *dst_compose) +{ + const struct mlx7502x_binning_mode *bin_mode; + u32 w, h, i, bin_w, bin_h; + + w = dst_crop->width; + h = dst_crop->height; + + /* select the best binning */ + for (i = 0; i < ARRAY_SIZE(binning_mode); i++) { + bin_mode = &binning_mode[i]; + + if (sel->flags & V4L2_SEL_FLAG_LE) { + bin_w = w / bin_mode->ratio; + bin_h = h / bin_mode->ratio; + } else {/* for GE and KEEP choose lower bin_w/h */ + bin_w = w / bin_mode[1].ratio + 1; + bin_h = h / bin_mode[1].ratio + 1; + } + + if (sel->r.width >= bin_w && sel->r.height >= bin_h) + break; + } + + /* save new binning config */ + if (sel->which == V4L2_SUBDEV_FORMAT_ACTIVE) + sensor->binning_mode = bin_mode; + + /* update crop step and min, based on new binning */ + sel->r = *dst_crop; + mlx7502x_set_crop(sensor, sel, dst_crop, dst_compose, bin_mode); + + /* resulted format after applying new binning */ + sel->r = *dst_compose; +} + +static int mlx7502x_set_selection(struct v4l2_subdev *sd, + struct v4l2_subdev_state *sd_state, + struct v4l2_subdev_selection *sel) +{ + struct mlx7502x *sensor = to_mlx7502x(sd); + struct v4l2_rect *dst_crop, *dst_compose; + const struct mlx7502x_binning_mode *bin_mode; + int ret = 0; + + if (sel->pad != 0) + return -EINVAL; + + if (sel->which == V4L2_SUBDEV_FORMAT_TRY) { + dst_crop = v4l2_subdev_get_try_crop(sd, sd_state, 0); + dst_compose = v4l2_subdev_get_try_compose(sd, sd_state, 0); + bin_mode = mlx7502x_find_binning_mode(dst_crop, dst_compose); + } else { + dst_crop = &sensor->crop; + dst_compose = &sensor->compose; + bin_mode = sensor->binning_mode; + } + + mutex_lock(&sensor->lock); + + if (sel->target == V4L2_SEL_TGT_CROP) + mlx7502x_set_crop(sensor, sel, dst_crop, dst_compose, bin_mode); + else if (sel->target == V4L2_SEL_TGT_COMPOSE) + /* actually this is binning */ + mlx7502x_set_compose(sensor, sel, dst_crop, dst_compose); + else + ret = -EINVAL; + + mutex_unlock(&sensor->lock); + + return ret; +} + +static int mlx7502x_get_selection(struct v4l2_subdev *sd, + struct v4l2_subdev_state *sd_state, + struct v4l2_subdev_selection *sel) +{ + struct mlx7502x *sensor = to_mlx7502x(sd); + struct v4l2_rect *src_crop, *src_compose; + int ret = 0; + + if (sel->pad != 0) + return -EINVAL; + + if (sel->which == V4L2_SUBDEV_FORMAT_TRY) { + src_crop = v4l2_subdev_get_try_crop(sd, sd_state, 0); + src_compose = v4l2_subdev_get_try_compose(sd, sd_state, 0); + } else { + src_crop = &sensor->crop; + src_compose = &sensor->compose; + } + + mutex_lock(&sensor->lock); + + switch (sel->target) { + case V4L2_SEL_TGT_CROP: + sel->r = *src_crop; + break; + case V4L2_SEL_TGT_CROP_DEFAULT: + case V4L2_SEL_TGT_CROP_BOUNDS: + case V4L2_SEL_TGT_NATIVE_SIZE: + sel->r.top = 0; + sel->r.left = 0; + sel->r.width = sensor->cur_desc->width; + sel->r.height = sensor->cur_desc->height; + break; + case V4L2_SEL_TGT_COMPOSE: + sel->r = *src_compose; + break; + case V4L2_SEL_TGT_COMPOSE_BOUNDS: + sel->r.top = 0; + sel->r.left = 0; + sel->r.width = src_crop->width; + sel->r.height = src_crop->height; + break; + default: + ret = -EINVAL; + } + + mutex_unlock(&sensor->lock); + + return ret; +} + +static const struct v4l2_subdev_core_ops mlx7502x_subdev_core_ops = { + .subscribe_event = v4l2_ctrl_subdev_subscribe_event, + .unsubscribe_event = v4l2_event_subdev_unsubscribe, +#ifdef CONFIG_VIDEO_ADV_DEBUG + .g_register = mlx7502x_get_register, + .s_register = mlx7502x_set_register, +#endif +}; + +static const struct v4l2_subdev_video_ops mlx7502x_subdev_video_ops = { + .s_stream = mlx7502x_s_stream, + .g_frame_interval = mlx7502x_get_frame_interval, + .s_frame_interval = mlx7502x_set_frame_interval, +}; + +static const struct v4l2_subdev_pad_ops mlx7502x_subdev_pad_ops = { + .init_cfg = mlx7502x_init_cfg, + .enum_mbus_code = mlx7502x_enum_mbus_code, + .set_fmt = mlx7502x_set_get_format, + .get_fmt = mlx7502x_set_get_format, + .set_selection = mlx7502x_set_selection, + .get_selection = mlx7502x_get_selection, +}; + +static const struct v4l2_subdev_ops mlx7502x_subdev_ops = { + .core = &mlx7502x_subdev_core_ops, + .video = &mlx7502x_subdev_video_ops, + .pad = &mlx7502x_subdev_pad_ops, +}; + +/* + * ***************************************************************************** + * Controls + * ***************************************************************************** + */ +static __always_inline u8 mlx7502x_phase_to_reg(u16 phase) +{ + /* Note: + * Sensor is working in mode when: + * MIX is a referance, + * and illumination is shifted + * To compensate it, we need to add 180 degrees + */ + if (phase != 0 && phase != 180) + phase = (phase + 180) % 360; + + return phase / 45; +} + +static int mlx7502x_set_phase_seq(struct mlx7502x *sensor, + struct v4l2_ctrl *ctrl) +{ + int ret; + int i, offset; + u16 *p_v; + u8 val; + u8 *data; + /* address + number of phases(1 phases - 1 nibble) */ + size_t data_size = 2 + DIV_ROUND_CLOSEST(ctrl->new_elems, 2); + + data = kmalloc(data_size, GFP_KERNEL); + if (!data) + return -ENOMEM; + + /* the address */ + put_unaligned_be16(MLX7502X_PX_PHASE_SHIFT_REG, data); + + /* data itself */ + offset = 2; + p_v = ctrl->p_new.p_u16; + for (i = 0; i < (ctrl->new_elems - 1); i += 2) { + val = FIELD_PREP(MLX7502X_NIBLE_LOW_MASK, + mlx7502x_phase_to_reg(p_v[i])); + + val |= FIELD_PREP(MLX7502X_NIBLE_HIGH_MASK, + mlx7502x_phase_to_reg(p_v[i + 1])); + + data[offset++] = val; + } + + /* last odd field if any */ + if (i < ctrl->new_elems) + data[offset] = FIELD_PREP(MLX7502X_NIBLE_LOW_MASK, + mlx7502x_phase_to_reg(p_v[i])); + + /* set phase sequence */ + ret = mlx7502x_write(&sensor->sd, data, data_size, NULL); + + /* set number of phases */ + ret = mlx7502x_write8(&sensor->sd, MLX7502X_PHASE_COUNT_REG, + ctrl->new_elems, &ret); + kfree(data); + return ret; +} + +/* comparator for bsearch func */ +static int mlx7502x_fmod_cmp(const void *key, const void *elt) +{ + int ret = 1; /* lower then lowest */ + u32 val = *((u32 *)key); + /* need prev elt for range checking, so key requires to be >= 4 */ + struct mlx7502x_fmod_list *el = (struct mlx7502x_fmod_list *)elt - 1; + u32 high = el[0].fmod; + u32 low = el[1].fmod; + + if (val > high) /* more then the highest, move to lower index */ + ret = -1; + else if (val >= low) /* we are in a range */ + ret = 0; + + return ret; +} + +static int mlx7502x_set_fmod(struct mlx7502x *sensor, u32 fmod) +{ + int ret; + u16 fmod_reg; + u8 pll_res_reg; + struct v4l2_subdev *sd = &sensor->sd; + struct mlx7502x_fmod_list *fc; + + fc = bsearch(&fmod, + mlx7502x_fmod_cfg, + ARRAY_SIZE(mlx7502x_fmod_cfg), + sizeof(struct mlx7502x_fmod_list), + mlx7502x_fmod_cmp); + + ret = mlx7502x_write8(sd, MLX7502X_DIVSELPRE_REG, fc->divselpre, NULL); + ret = mlx7502x_write8(sd, MLX7502X_DIVSEL_REG, fc->divsel, &ret); + + fmod_reg = (fmod / 1000000u) << (fc->divselpre + fc->divsel); + ret = mlx7502x_write16(sd, MLX7502X_FMOD_REG, fmod_reg, &ret); + + pll_res_reg = fmod_reg < MLX7502X_PLL_RES_THR ? 2 : 0; + return mlx7502x_write8(sd, MLX7502X_PLL_RES_REG, pll_res_reg, &ret); +} + +static int mlx7502x_set_tint(struct mlx7502x *sensor, struct v4l2_ctrl *ctrl) +{ + int i, offset, ret = 0; + u16 *p_v; + u32 tint_reg; + u8 *data; + /* address + number of phases(1 phases - 4bytes) */ + size_t data_size = 2 + ctrl->new_elems * 4; + + data = kmalloc(data_size, GFP_KERNEL); + if (!data) + return -ENOMEM; + + /* the address */ + put_unaligned_be16(MLX7502X_TINT0_REG, data); + + /* data itself */ + p_v = ctrl->p_new.p_u16; + for (i = 0; i < ctrl->new_elems; i++) { + offset = 2 + i * 4; + tint_reg = mlx7502x_from_us(sensor, p_v[i]) * sensor->hmax; + put_unaligned_be32(tint_reg, data + offset); + } + + ret = mlx7502x_write(&sensor->sd, data, data_size, NULL); + kfree(data); + return ret; +} + +static int mlx7502x_update_hmax(struct mlx7502x *sensor, + int mipi_speed_ind, + int output_mode) +{ + const struct mlx7502x_link_freq_list *lfc; + int hmax_index = mlx7502x_output_mode_cfg[output_mode].hmax_index; + u8 lane_n = sensor->ep.bus.mipi_csi2.num_data_lanes; + u32 tint_step; + + lfc = sensor->cur_desc->link_freq_cfg; + sensor->hmax = lfc->hmax[lane_n >> 2][mipi_speed_ind][hmax_index]; + + tint_step = mlx7502x_to_us(sensor, 1); + return __v4l2_ctrl_modify_range(sensor->tint, + tint_step, + sensor->tint->maximum, + tint_step, + sensor->tint->default_value); +} + +static int mlx7502x_hold(struct mlx7502x *sensor, u32 id, u8 hold) +{ + int ret = 0; + + if (!sensor->streaming) /* only during streaming */ + return 0; + + switch (id) { + case V4L2_CID_TOF_PHASE_SEQ: + case V4L2_CID_TOF_FREQ_MOD: + case V4L2_CID_TOF_TIME_INTEGRATION: + ret = mlx7502x_write8(&sensor->sd, + MLX7502X_PARAM_HOLD_REG, + hold, NULL); + break; + default: + break; + } + + return ret; +} + +static int mlx7502x_s_ctrl(struct v4l2_ctrl *ctrl) +{ + struct mlx7502x *sensor = container_of(ctrl->handler, + struct mlx7502x, + ctrl_handler); + struct v4l2_subdev *sd = &sensor->sd; + int ret = 0; + + if (!pm_runtime_get_if_in_use(sensor->dev)) + return 0; + + ret = mlx7502x_hold(sensor, ctrl->id, 1); + if (ret < 0) + return ret; + + switch (ctrl->id) { + case V4L2_CID_TOF_PHASE_SEQ: + ret = mlx7502x_set_phase_seq(sensor, ctrl); + break; + case V4L2_CID_TOF_FREQ_MOD: + ret = mlx7502x_set_fmod(sensor, *ctrl->p_new.p_u32); + break; + case V4L2_CID_TOF_TIME_INTEGRATION: + ret = mlx7502x_set_tint(sensor, ctrl); + break; + case V4L2_CID_MLX7502X_OUTPUT_MODE: + ret = mlx7502x_update_hmax(sensor, + sensor->link_freq->val, + ctrl->val); + break; + case V4L2_CID_LINK_FREQ: + ret = mlx7502x_update_hmax(sensor, + ctrl->val, + sensor->output_mode->val); + break; + case V4L2_CID_VFLIP: + ret = mlx7502x_write8(sd, MLX7502X_VFLIP_REG, ctrl->val, NULL); + break; + case V4L2_CID_HFLIP: + ret = mlx7502x_write8(sd, MLX7502X_HFLIP_REG, ctrl->val, NULL); + break; + default: + dev_err(sensor->dev, "Unknown id: %x\n", ctrl->id); + break; + } + + mlx7502x_hold(sensor, ctrl->id, 0); + pm_runtime_put_autosuspend(sensor->dev); + + return ret; +} + +static const struct v4l2_ctrl_ops mlx7502x_ctrl_ops = { + .s_ctrl = mlx7502x_s_ctrl, +}; + +static const struct v4l2_ctrl_config mlx7502x_phase_sequence = { + .ops = &mlx7502x_ctrl_ops, + .id = V4L2_CID_TOF_PHASE_SEQ, + .min = 0, + .max = 315, + .step = 45, + .def = 0, + .dims = { MLX7502X_PHASE_MAX_NUM }, +}; + +static const struct v4l2_ctrl_config mlx7502x_fmod = { + .ops = &mlx7502x_ctrl_ops, + .id = V4L2_CID_TOF_FREQ_MOD, + .min = 4000000, + .max = 100000000, + .step = 1000000, /* in Hz */ + .def = 40000000, + .dims = { 1 }, +}; + +static const struct v4l2_ctrl_config mlx7502x_tint = { + .ops = &mlx7502x_ctrl_ops, + .id = V4L2_CID_TOF_TIME_INTEGRATION, + .min = 5, + .max = 1000, + .step = 1, /* in us */ + .def = 198, + .dims = { MLX7502X_PHASE_MAX_NUM }, +}; + +static const struct v4l2_ctrl_config mlx7502x_output_mode = { + .ops = &mlx7502x_ctrl_ops, + .id = V4L2_CID_MLX7502X_OUTPUT_MODE, + .name = "Output mode", + .type = V4L2_CTRL_TYPE_MENU, + .max = ARRAY_SIZE(mlx7502x_ctrl_output) - 1, + .def = 0, + .qmenu = mlx7502x_ctrl_output, +}; + +static int mlx7502x_link_freq_init(struct mlx7502x *sensor) +{ + struct v4l2_ctrl_handler *hdl = &sensor->ctrl_handler; + const s64 *link_freq = sensor->cur_desc->link_freq_cfg->link_freq; + int i, j, link_freq_mask; + + link_freq_mask = 0; + for (i = 0; i < sensor->ep.nr_of_link_frequencies; i++) { + for (j = 0; j < MLX7502X_LINK_FREQ_N; j++) { + if (link_freq[j] == sensor->ep.link_frequencies[i]) + break; + } + + if (j == MLX7502X_LINK_FREQ_N) { + dev_err(sensor->dev, "no link frequency %lld supported\n", + link_freq[j]); + return -EINVAL; + } + + link_freq_mask |= (1 << j); + } + + sensor->link_freq = v4l2_ctrl_new_int_menu(hdl, &mlx7502x_ctrl_ops, + V4L2_CID_LINK_FREQ, + MLX7502X_LINK_FREQ_N - 1, + __fls(link_freq_mask), + link_freq); + + sensor->link_freq->menu_skip_mask = ~link_freq_mask; + + return 0; +} + +static int mlx7502x_ctrls_init(struct mlx7502x *sensor) +{ + struct v4l2_ctrl_handler *hdl; + int ret = 0; + + hdl = &sensor->ctrl_handler; + + ret = v4l2_ctrl_handler_init(hdl, 7); + if (ret) { + dev_err(sensor->dev, "Failed to init handler - %d\n", ret); + return ret; + } + + ret = mlx7502x_link_freq_init(sensor); + if (ret) + goto error_ctrls; + + v4l2_ctrl_new_std(hdl, &mlx7502x_ctrl_ops, V4L2_CID_VFLIP, 0, 1, 1, 0); + v4l2_ctrl_new_std(hdl, &mlx7502x_ctrl_ops, V4L2_CID_HFLIP, 0, 1, 1, 0); + + v4l2_ctrl_new_custom(hdl, &mlx7502x_fmod, NULL); + sensor->phase_seq = v4l2_ctrl_new_custom(hdl, &mlx7502x_phase_sequence, + NULL); + + sensor->tint = v4l2_ctrl_new_custom(hdl, &mlx7502x_tint, NULL); + sensor->output_mode = v4l2_ctrl_new_custom(hdl, &mlx7502x_output_mode, + NULL); + + if (hdl->error) { + dev_err(sensor->dev, "Error %d while adding controls\n", + hdl->error); + ret = hdl->error; + goto error_ctrls; + } + + sensor->sd.ctrl_handler = hdl; + return 0; + +error_ctrls: + v4l2_ctrl_handler_free(hdl); + return ret; +} + +/* + * ***************************************************************************** + * Probing + * ***************************************************************************** + */ +static int mlx7502x_fwnode_parse(struct mlx7502x *sensor, struct device *dev) +{ + struct fwnode_handle *endpoint; + int ret, num_data_lanes; + + endpoint = fwnode_graph_get_next_endpoint(dev_fwnode(dev), NULL); + if (!endpoint) { + dev_err(dev, "endpoint node not found\n"); + return -EINVAL; + } + + ret = v4l2_fwnode_endpoint_alloc_parse(endpoint, &sensor->ep); + fwnode_handle_put(endpoint); + if (ret < 0) { + dev_err(dev, "parsing endpoint node failed\n"); + return ret; + } + + if (sensor->ep.bus_type != V4L2_MBUS_CSI2_DPHY) { + dev_err(dev, "invalid bus type, must be MIPI CSI2\n"); + ret = -EINVAL; + goto dt_ep_error; + } + + num_data_lanes = sensor->ep.bus.mipi_csi2.num_data_lanes; + if (num_data_lanes != 2 && num_data_lanes != 4) { + dev_err(dev, "invalid num_data_lanes, must be 2 or 4. But it was %d\n", + num_data_lanes); + ret = -EINVAL; + goto dt_ep_error; + } + + if (!sensor->ep.nr_of_link_frequencies) { + dev_err(dev, "missing link frequencies property\n"); + ret = -EINVAL; + goto dt_ep_error; + } + + return 0; + +dt_ep_error: + v4l2_fwnode_endpoint_free(&sensor->ep); + return ret; +} + +static int mlx7502x_probe(struct i2c_client *client) +{ + struct device *dev = &client->dev; + struct mlx7502x *sensor; + struct v4l2_subdev *sd; + u32 xclk_rate; + int ret, i; + + sensor = devm_kzalloc(dev, sizeof(*sensor), GFP_KERNEL); + if (!sensor) + return -ENOMEM; + + if (dev_fwnode(dev)) + sensor->cur_desc = device_get_match_data(dev); + else + return -ENODEV; + + ret = mlx7502x_fwnode_parse(sensor, dev); + if (ret < 0) + return ret; + + sensor->xclk = devm_clk_get(dev, NULL); + if (IS_ERR(sensor->xclk)) { + dev_err(dev, "failed to get xclk\n"); + return PTR_ERR(sensor->xclk); + } + + xclk_rate = clk_get_rate(sensor->xclk); + if (xclk_rate != MLX7502X_XCLK_RATE) { + dev_err(dev, "only 8MHz clock is supported\n"); + return -EINVAL; + } + + for (i = 0; i < MLX7502X_NUM_SUPPLIES; i++) + sensor->supplies[i].supply = mlx7502x_supply_names[i]; + + ret = devm_regulator_bulk_get(dev, MLX7502X_NUM_SUPPLIES, + sensor->supplies); + if (ret) + return ret; + + sensor->reset = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_LOW); + if (IS_ERR(sensor->reset)) { + dev_err(dev, "failed to get reset\n"); + return PTR_ERR(sensor->reset); + } + + sensor->dev = dev; + sd = &sensor->sd; + v4l2_i2c_subdev_init(sd, client, &mlx7502x_subdev_ops); + sd->flags |= V4L2_SUBDEV_FL_HAS_DEVNODE | V4L2_SUBDEV_FL_HAS_EVENTS; + + sd->entity.function = MEDIA_ENT_F_CAM_SENSOR; + sensor->pad.flags = MEDIA_PAD_FL_SOURCE; + ret = media_entity_pads_init(&sd->entity, 1, &sensor->pad); + if (ret < 0) + goto error_ep; + + mutex_init(&sensor->lock); + + /* initial configurations and controls depends on sensor type */ + sensor->frame_interval.numerator = 1; + sensor->frame_interval.denominator = MLX7502X_DEFAULT_FRAME_RATE; + sensor->crop.top = 0; + sensor->crop.left = 0; + sensor->crop.width = sensor->cur_desc->width; + sensor->crop.height = sensor->cur_desc->height; + sensor->compose = sensor->crop; + sensor->binning_mode = &binning_mode[0]; + + ret = mlx7502x_ctrls_init(sensor); + if (ret < 0) + goto error_init; + + sensor->ctrl_handler.lock = &sensor->lock; + + pm_runtime_enable(dev); + + ret = v4l2_async_register_subdev(sd); + if (ret < 0) + goto error_pm; + + /* configure to use autosuspend, delay 1s */ + pm_runtime_set_autosuspend_delay(dev, 1000); + pm_runtime_use_autosuspend(dev); + + dev_dbg(dev, "Melexis ToF camera driver probed\n"); + + return 0; + +error_pm: + pm_runtime_disable(dev); +error_init: + media_entity_cleanup(&sd->entity); + mutex_destroy(&sensor->lock); +error_ep: + v4l2_fwnode_endpoint_free(&sensor->ep); + return ret; +} + +static void mlx7502x_remove(struct i2c_client *client) +{ + struct v4l2_subdev *sd = i2c_get_clientdata(client); + struct mlx7502x *sensor = to_mlx7502x(sd); + + pm_runtime_disable(&client->dev); + if (!pm_runtime_status_suspended(&client->dev)) + mlx7502x_power_off(sensor); + pm_runtime_set_suspended(&client->dev); + + v4l2_fwnode_endpoint_free(&sensor->ep); + v4l2_async_unregister_subdev(&sensor->sd); + v4l2_ctrl_handler_free(&sensor->ctrl_handler); + + media_entity_cleanup(&sensor->sd.entity); + mutex_destroy(&sensor->lock); +} + +static const struct dev_pm_ops mlx7502x_pm_ops = { + SET_RUNTIME_PM_OPS(mlx7502x_runtime_suspend, + mlx7502x_runtime_resume, + NULL) +}; + +static const struct of_device_id mlx7502x_of_match[] = { + { .compatible = "melexis,mlx75026", .data = &mlx75026 }, + { .compatible = "melexis,mlx75027", .data = &mlx75027 }, + { /* sentinel */ } +}; +MODULE_DEVICE_TABLE(of, mlx7502x_of_match); + +static struct i2c_driver mlx7502x_driver = { + .driver = { + .of_match_table = mlx7502x_of_match, + .name = "mlx7502x", + .pm = &mlx7502x_pm_ops, + }, + .probe_new = mlx7502x_probe, + .remove = mlx7502x_remove, +}; + +module_i2c_driver(mlx7502x_driver); + +MODULE_AUTHOR("Andrii Kyselov "); +MODULE_AUTHOR("Volodymyr Kharuk "); +MODULE_DESCRIPTION("A low-level driver for Melexis TOF sensors"); +MODULE_LICENSE("GPL");