From nobody Fri Oct 3 23:04:05 2025 Received: from mail-wm1-f54.google.com (mail-wm1-f54.google.com [209.85.128.54]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 098DC313550 for ; Fri, 22 Aug 2025 17:10:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.54 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755882659; cv=none; b=L+Tkt8BV5XKu7F4hFXoDAzJzUUs/6rjHE/K0yWU63A0EUxUKLRAcR7gWEg2RbOfzr4CTRwqunrQe5cMiYbLc7b7MZatPb8eo3fsAZcu+Ckz36T4/AqAzA8SiLSiQ8s8IU3IQ7SUBnLpl9aq4lBkn3J6S9MWE5/vzPKvRt0/w3YA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755882659; c=relaxed/simple; bh=GC6F3/Jn5vtalbPADycR9a2Ilql3ZeepeVFqnze4ARw=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=fd+bBzFF2cVrfjKhj95FT6i+ZwqZ1ir8xFeyvbUz8PRqLN3TY1A3USwuc6OLk/SJdgm53VKHiIH+4GWfCl+0PIDI/bmMDbE7TEKsg3XB+WBDcjRJ0UZRCieDOMAwzVHub0y9sltQEmZNXO1mSumCbBAlCzlgRs5BC78uftbcBNw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pinefeat.co.uk; spf=pass smtp.mailfrom=pinefeat.co.uk; dkim=pass (2048-bit key) header.d=pinefeat.co.uk header.i=@pinefeat.co.uk header.b=fFZZo2fE; arc=none smtp.client-ip=209.85.128.54 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pinefeat.co.uk Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pinefeat.co.uk Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pinefeat.co.uk header.i=@pinefeat.co.uk header.b="fFZZo2fE" Received: by mail-wm1-f54.google.com with SMTP id 5b1f17b1804b1-45a1b00f23eso13953745e9.0 for ; Fri, 22 Aug 2025 10:10:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pinefeat.co.uk; s=google; t=1755882654; x=1756487454; 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=8c7uejE+UWAVBp++A3P0eUre76yYfUCzitGMEvBnArM=; b=fFZZo2fE8UbZYhXWfP6aqYKG5KMS6E1gySY0//7Ve0fasvPYRIilwZqmjTT/vEuoGK bSAKsL76ivH2ngkS0+ZtBZfB6uHjJltLR4CxyCZeyAzH6mr2a2BTJCOdm7jR1D58DteM p/pbkq6jsaCfwiCybdDhtHgnSzQjOQvSo0XIq3huvNvrfWP+PWgYhwzJHUoDVI2+Bt28 LS8lGO9Ewl9oF9F6Zwh33Wc1rYlttSfhn+q6E1cMhtyzYUTg9JchM444xx2V5o520SwE NrQLcrE5XfQYyq95JhNHc3gW2u/sYixWH1KdWV7nGnOlQsETvmuNHdixRwEVqxi7bThr +fQQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1755882654; x=1756487454; 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=8c7uejE+UWAVBp++A3P0eUre76yYfUCzitGMEvBnArM=; b=kI20N/6Vhg84T963HUWyoVe5a1iwAXzZJqQJiW8nNuTytqe5AA68Zq7wBbIquxW0iy gJ5H8XjvhAyrhDWumsiLmvRvLI7kB5phR6lY9yeEoWuQcyN15qIyl+VdDD+6zVQVpnfD J61wNS2HQ4xHFPRjmxupHG2goJoOFr4YDUaq1pCEADr840q94J2eUSJXEi3X3BOJKoHB nlpvqXucVfJkDUkFKin5V9EtYKADQmq5o655m2yjneBxJnLeDSWEqNtfde0diqnIRjns NBDWDjz1yrX3aH4EvdbHt7hAi09FDhBC+zoA/imq80fvuT8T0vrUkPgArkU/92wFs9eS 0LMg== X-Forwarded-Encrypted: i=1; AJvYcCUeUJWGAle7ZSXBGh1c8YH0VrSBcQKvdDs5/ADukxY8BUCr4MjceBqLVvjdUdHyF9tnDuvE4LcopF3cZEs=@vger.kernel.org X-Gm-Message-State: AOJu0Yy/2zs7UcLX3VbuThRELUeY05b0zdnkhPQBadVO4V46rQYPuutF lC9Hh2cmv31A9SCZTBvy1KIpIC46VpkKYe8ueUAsgCDE1dKHl3NYJbu5b45Aw24HYKncos07xHA 3/+n/xE+pfg== X-Gm-Gg: ASbGncvF8RwO5jpnKuCaiumAgVB80UjK9qH43Wi9JX131O2Rur+k7SBjqZW2LRG8nha YdITaicDE0HkDBVr8nG/watYHGb9DnzW4HcuFolFlj5TxuoTnf7h4nHIWAnGVyvJWIwo69Oa2Pn lK0gDiDUZGaYxYbVivIE19ngHdvUqucywx3rj9X+xa9fGi7E9dtYfD1WYco9QZMZWnKVaPhyNCT T7M9DqMyrDNQmIEGc/bKh1HaE/djXGXUOIWHfsZB/ucR+iKnuTAlZlV0zx/4Bp7t5VHa26nK+ed 2/6mvCDYyHlF/K6kSO+m8o7PJo1ZdJ2x2OUIzjk4b4t0+iW9ADJjegJQxG6d7FdCuEd1jT3xnzh WX0zBLRPtpyo74R5m5jCZKb9qwnjl1m0Cr4JYcxjG X-Google-Smtp-Source: AGHT+IF5fbPcLMPGPUXxbyvocoXnUfM5BMARF/EqU2fvSvNEGovDCG+sKKo5gJeocqQhhXEZzLbNiA== X-Received: by 2002:a05:6000:430c:b0:3be:51c6:16aa with SMTP id ffacd0b85a97d-3c5ddd7ed53mr2426800f8f.45.1755882654054; Fri, 22 Aug 2025 10:10:54 -0700 (PDT) Received: from asmirnov-G751JM.Home ([2a02:c7c:b28c:1f00:c77a:e59e:20e0:4966]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3c70f237fefsm233780f8f.30.2025.08.22.10.10.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Aug 2025 10:10:53 -0700 (PDT) From: Aliaksandr Smirnou To: jacopo.mondi@ideasonboard.com, hverkuil@xs4all.nl, mchehab@kernel.org, robh@kernel.org, krzk+dt@kernel.org, conor+dt@kernel.org Cc: devicetree@vger.kernel.org, linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Aliaksandr Smirnou , Aliaksandr Smirnou Subject: [PATCH v4 1/2] dt-bindings: Pinefeat cef168 lens control board Date: Fri, 22 Aug 2025 18:10:40 +0100 Message-Id: <20250822171041.7340-2-support@pinefeat.co.uk> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250822171041.7340-1-support@pinefeat.co.uk> References: <20250822171041.7340-1-support@pinefeat.co.uk> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add the Device Tree schema and examples for the Pinefeat cef168 lens control board. This board interfaces Canon EF & EF-S lenses with non-Canon camera bodies, enabling electronic control of focus and aperture via V4L2. Power supply is derived from fixed supplies via connector or GPIO header. Therefore, the driver does not manage any regulator, so representing any supply in the binding is redundant. Signed-off-by: Aliaksandr Smirnou --- .../bindings/media/i2c/pinefeat,cef168.yaml | 47 +++++++++++++++++++ .../devicetree/bindings/vendor-prefixes.yaml | 2 + MAINTAINERS | 6 +++ 3 files changed, 55 insertions(+) create mode 100644 Documentation/devicetree/bindings/media/i2c/pinefeat,ce= f168.yaml diff --git a/Documentation/devicetree/bindings/media/i2c/pinefeat,cef168.ya= ml b/Documentation/devicetree/bindings/media/i2c/pinefeat,cef168.yaml new file mode 100644 index 000000000000..1295b1f4edeb --- /dev/null +++ b/Documentation/devicetree/bindings/media/i2c/pinefeat,cef168.yaml @@ -0,0 +1,47 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +# Copyright (c) 2025 Pinefeat LLP +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/media/i2c/pinefeat,cef168.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Pinefeat cef168 lens driver + +maintainers: + - Aliaksandr Smirnou + +description: | + Pinefeat produces an adapter designed to interface between + Canon EF & EF-S lenses and non-Canon camera bodies, incorporating + features for electronic focus and aperture adjustment. The cef168 + circuit board, included with the adapter, provides a software + programming interface that allows control of lens focus and + aperture positions. + +properties: + compatible: + enum: + - pinefeat,cef168 + + reg: + maxItems: 1 + +required: + - compatible + - reg + +additionalProperties: false + +examples: + - | + i2c { + #address-cells =3D <1>; + #size-cells =3D <0>; + + camera-lens@d { + compatible =3D "pinefeat,cef168"; + reg =3D <0x0d>; + }; + }; + +... diff --git a/Documentation/devicetree/bindings/vendor-prefixes.yaml b/Docum= entation/devicetree/bindings/vendor-prefixes.yaml index 77160cd47f54..dab27f769b0a 100644 --- a/Documentation/devicetree/bindings/vendor-prefixes.yaml +++ b/Documentation/devicetree/bindings/vendor-prefixes.yaml @@ -1195,6 +1195,8 @@ patternProperties: description: Picochip Ltd "^pine64,.*": description: Pine64 + "^pinefeat,.*": + description: Pinefeat LLP "^pineriver,.*": description: Shenzhen PineRiver Designs Co., Ltd. "^pixcir,.*": diff --git a/MAINTAINERS b/MAINTAINERS index fe168477caa4..811c6a150029 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -19985,6 +19985,12 @@ S: Supported F: Documentation/devicetree/bindings/input/pine64,pinephone-keyboard.yaml F: drivers/input/keyboard/pinephone-keyboard.c =20 +PINEFEAT CEF168 LENS DRIVER +M: Aliaksandr Smirnou +L: linux-media@vger.kernel.org +S: Supported +F: Documentation/devicetree/bindings/media/i2c/pinefeat,cef168.yaml + PLANTOWER PMS7003 AIR POLLUTION SENSOR DRIVER M: Tomasz Duszynski S: Maintained --=20 2.34.1 From nobody Fri Oct 3 23:04:05 2025 Received: from mail-wm1-f51.google.com (mail-wm1-f51.google.com [209.85.128.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 041EB31355B for ; Fri, 22 Aug 2025 17:10:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755882659; cv=none; b=VD2sFev1AifBuAJ0sjNx8wM9uTCA9GQXpzvAhEk8DJOSpumQqciBSxet+UxnXfVcpzLdUA6Puq3+rLDuAyme4pXb61iz42VcD8JY7HSoETMGthPlOpxedwMPG8AsfY/lYJ6934Epj1WZ0/nWj3Stg6awMV71BV6DGLcdj2CS7N4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755882659; c=relaxed/simple; bh=HHmPum0PvEApNjgYAUOlDA8D8AEOdfimGezg2ryCHSc=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=kKA+FF01U5nxt/2YQApWlokQBJhqxDWuBR500eFqDd7+BZGx72eQpaE+zReoUimk05Z8ess/DpEd0cUs4A6P4MAXYt5SlWV2tfMAlKWsAbLZIV6UI7FrlX0XkMhW8FISucR0pIoddXTstjGmsvbkXnXH4K5Pftq0BnXGeDsJ2Lk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pinefeat.co.uk; spf=pass smtp.mailfrom=pinefeat.co.uk; dkim=pass (2048-bit key) header.d=pinefeat.co.uk header.i=@pinefeat.co.uk header.b=NzPazdCi; arc=none smtp.client-ip=209.85.128.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pinefeat.co.uk Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pinefeat.co.uk Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pinefeat.co.uk header.i=@pinefeat.co.uk header.b="NzPazdCi" Received: by mail-wm1-f51.google.com with SMTP id 5b1f17b1804b1-45a1b065d58so19320815e9.1 for ; Fri, 22 Aug 2025 10:10:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pinefeat.co.uk; s=google; t=1755882655; x=1756487455; 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=b4hLmrqBB55CYWs4MdA1e/l8rKfd2dtL/Ee5u7ARa7s=; b=NzPazdCimdo/PXu21HDwNYv1XgPBtfqD8/0t2PyxLhtp+XCwg3qFAHq8UQf0neMNUc /4nVClhxSdQR3rK+7YKPW1s0IXpxeNakXv7KIKfaaOCj4DQKB6P0979ztkbVb08yWUji 2aAZ1V/SOMpYaGI6u9P7jcHq1hJ2jxrjH6uR405kR8RvsK7Sv3jnSKBEcfUFD8k+pcOI 91rwIa0AFdxF3yrUDHImh5CEYzyzvk+KrJTODHcI/DL/kwYfWRF8rCuTmYv1F/LJNUfI iCaF2uBX7x48xzSPJCsIk8dCX1uvHG6zHoatNWYXKQCTyShRKB+PTUasF2M2J5AWJDzM nBYQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1755882655; x=1756487455; 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=b4hLmrqBB55CYWs4MdA1e/l8rKfd2dtL/Ee5u7ARa7s=; b=rZaPYXN6BGif+r0eePdkVvvTNY+LKtzA4WNVMUClsAWcdxsU8oNGkCuYlI/X1k25ke 1vrGlyX/iNAwCVegYH1hYcgPsnGaNH1YFrZs0jbOku5NLkF0XEvE5BH4rVcF3ZhuRKrN bzwiKnpWKDnTadYO9A96BuZK1p+mFp/wzzG/nVHcexcLPRkF59T0OiO1nGxDg+zkGuL5 WBamaRFO+UjGFm8FEROmKdXH7B1HSAMzytsiaVDX1sXWnfK73aN1FVgV0kUUsbatvaAA jfaaH0Kz+zB3bD8z/M70juBAMAaBwOowoa0CpEu+ev8ohrs1nKd0FJYZ44UxsmclVYm8 nk6Q== X-Forwarded-Encrypted: i=1; AJvYcCW98Jwg767DVoSiZNr5H+dKd3XgPJhVm8bX59DxyqkVuScoFek4LNVPt0leUkH4zMcz5gBR2T5lr2Ykd8k=@vger.kernel.org X-Gm-Message-State: AOJu0YzSOeMQrlJPUzwTAMBik6sTQJ1ULh4LdkGIsGgA2FqxXt6J1sry 2AF+MN8O9KzHc5HLd/TC8CsNT4LzLgK2pBhPxDg+L5eQAEJrbFQOdogwLtF91zBMLKE= X-Gm-Gg: ASbGnct4Ivudo8KfnGZzFWo9H59asc7C1AnGbQwrB570D1RWYkxFuxAgV5Hyh1AiAlW Jvw555kcdT23G7YpWX9NpNbGwQ35MZ+1paJZm1yVY3dG0b2fZ8TP3BFXekYH2wJcFpdJn4j33Io m6PGnA2mBjGG/EotdqqLA03oit8DYJITjnANnkVwVMTld6D0mRwElMfCE/c/JWXNPSj5F9JlIju g/UicXih7uDuhrLnciT0LbnU+0TcIWqf2qjdG6zr1c4g2sVG8QQUZpll/VIR9Qi5exDjG+0gAPo 5iyXrITqZicTBO+mEb0LaevAQMCcDBz2m1oF+pBnfrWDWXjG/OOdZiq4VSjysckltXEzAPO1VCw LrnAuA929ETyWxK1V0QKu5dJJG3jBtZ84LFyJ6tbA X-Google-Smtp-Source: AGHT+IHLjdTaWeGq77BO6a00h2dMlJRZMVT2zHXYDxoWLtDw4WlNcVwHZIhnDM2wjhd2gILSQrMR6w== X-Received: by 2002:a05:600c:3212:b0:459:df48:3b19 with SMTP id 5b1f17b1804b1-45b517c5df0mr24515925e9.18.1755882654828; Fri, 22 Aug 2025 10:10:54 -0700 (PDT) Received: from asmirnov-G751JM.Home ([2a02:c7c:b28c:1f00:c77a:e59e:20e0:4966]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3c70f237fefsm233780f8f.30.2025.08.22.10.10.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Aug 2025 10:10:54 -0700 (PDT) From: Aliaksandr Smirnou To: jacopo.mondi@ideasonboard.com, hverkuil@xs4all.nl, mchehab@kernel.org, robh@kernel.org, krzk+dt@kernel.org, conor+dt@kernel.org Cc: devicetree@vger.kernel.org, linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Aliaksandr Smirnou , Aliaksandr Smirnou Subject: [PATCH v4 2/2] media: i2c: Pinefeat cef168 lens control board driver Date: Fri, 22 Aug 2025 18:10:41 +0100 Message-Id: <20250822171041.7340-3-support@pinefeat.co.uk> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250822171041.7340-1-support@pinefeat.co.uk> References: <20250822171041.7340-1-support@pinefeat.co.uk> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add support for the Pinefeat cef168 lens control board that provides electronic focus and aperture control for Canon EF & EF-S lenses on non-Canon camera bodies. Signed-off-by: Aliaksandr Smirnou --- MAINTAINERS | 1 + drivers/media/i2c/Kconfig | 9 + drivers/media/i2c/Makefile | 1 + drivers/media/i2c/cef168.c | 331 +++++++++++++++++++++++++++++ include/uapi/linux/v4l2-controls.h | 6 + 5 files changed, 348 insertions(+) create mode 100644 drivers/media/i2c/cef168.c diff --git a/MAINTAINERS b/MAINTAINERS index 811c6a150029..a531fb05faa4 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -19990,6 +19990,7 @@ M: Aliaksandr Smirnou L: linux-media@vger.kernel.org S: Supported F: Documentation/devicetree/bindings/media/i2c/pinefeat,cef168.yaml +F: drivers/media/i2c/cef168.c =20 PLANTOWER PMS7003 AIR POLLUTION SENSOR DRIVER M: Tomasz Duszynski diff --git a/drivers/media/i2c/Kconfig b/drivers/media/i2c/Kconfig index 6237fe804a5c..df2b33f03ab7 100644 --- a/drivers/media/i2c/Kconfig +++ b/drivers/media/i2c/Kconfig @@ -791,6 +791,15 @@ config VIDEO_AK7375 capability. This is designed for linear control of voice coil motors, controlled via I2C serial interface. =20 +config VIDEO_CEF168 + tristate "CEF168 lens control support" + select CRC8 + help + This is a driver for the CEF168 lens control board. + The board provides an I2C interface for electronic focus + and aperture control of EF and EF-S lenses. The driver + integrates with the V4L2 sub-device API. + config VIDEO_DW9714 tristate "DW9714 lens voice coil support" depends on GPIOLIB diff --git a/drivers/media/i2c/Makefile b/drivers/media/i2c/Makefile index 5873d29433ee..75a95f850f18 100644 --- a/drivers/media/i2c/Makefile +++ b/drivers/media/i2c/Makefile @@ -25,6 +25,7 @@ obj-$(CONFIG_VIDEO_BT856) +=3D bt856.o obj-$(CONFIG_VIDEO_BT866) +=3D bt866.o obj-$(CONFIG_VIDEO_CCS) +=3D ccs/ obj-$(CONFIG_VIDEO_CCS_PLL) +=3D ccs-pll.o +obj-$(CONFIG_VIDEO_CEF168) +=3D cef168.o obj-$(CONFIG_VIDEO_CS3308) +=3D cs3308.o obj-$(CONFIG_VIDEO_CS5345) +=3D cs5345.o obj-$(CONFIG_VIDEO_CS53L32A) +=3D cs53l32a.o diff --git a/drivers/media/i2c/cef168.c b/drivers/media/i2c/cef168.c new file mode 100644 index 000000000000..cfcef476f09d --- /dev/null +++ b/drivers/media/i2c/cef168.c @@ -0,0 +1,331 @@ +// SPDX-License-Identifier: GPL-2.0 +// Copyright (c) 2025 Pinefeat LLP + +#include +#include +#include +#include +#include +#include +#include +#include + +#define CEF168_NAME "cef168" + +#define CEF168_V4L2_CID_CUSTOM(ctrl) \ + (V4L2_CID_USER_CEF168_BASE + custom_##ctrl) + +enum { custom_lens_id, custom_data, custom_focus_range, custom_calibrate }; + +#define INP_CALIBRATE 0x22 +#define INP_SET_FOCUS 0x80 +#define INP_SET_FOCUS_P 0x81 +#define INP_SET_FOCUS_N 0x82 +#define INP_SET_APERTURE 0x7A +#define INP_SET_APERTURE_P 0x7B +#define INP_SET_APERTURE_N 0x7C + +#define CEF_CRC8_POLYNOMIAL 168 + +DECLARE_CRC8_TABLE(cef168_crc8_table); + +struct cef168_data { + __u8 lens_id; + __u8 moving : 1; + __u8 calibrating : 2; + __u16 moving_time; + __u16 focus_position_min; + __u16 focus_position_max; + __u16 focus_position_cur; + __u16 focus_distance_min; + __u16 focus_distance_max; + __u8 crc8; +} __packed; + +struct cef168_device { + struct v4l2_ctrl_handler ctrls; + struct v4l2_subdev sd; +}; + +static inline struct cef168_device *to_cef168(struct v4l2_ctrl *ctrl) +{ + return container_of(ctrl->handler, struct cef168_device, ctrls); +} + +static inline struct cef168_device *sd_to_cef168(struct v4l2_subdev *subde= v) +{ + return container_of(subdev, struct cef168_device, sd); +} + +static int cef168_i2c_write(struct cef168_device *cef168_dev, u8 cmd, u16 = val) +{ + struct i2c_client *client =3D v4l2_get_subdevdata(&cef168_dev->sd); + int retry, ret; + + __le16 le_data =3D cpu_to_le16(val); + char tx_data[4] =3D { cmd, ((u8 *)&le_data)[0], ((u8 *)&le_data)[1] }; + + tx_data[3] =3D crc8(cef168_crc8_table, tx_data, 3, CRC8_INIT_VALUE); + + for (retry =3D 0; retry < 3; retry++) { + ret =3D i2c_master_send(client, tx_data, sizeof(tx_data)); + if (ret =3D=3D sizeof(tx_data)) + return 0; + else if (ret !=3D -EIO && ret !=3D -EREMOTEIO) + break; + } + + dev_err(&client->dev, "I2C write fail after %d retries, ret=3D%d\n", + retry, ret); + return -EIO; +} + +static int cef168_i2c_read(struct cef168_device *cef168_dev, + struct cef168_data *rx_data) +{ + struct i2c_client *client =3D v4l2_get_subdevdata(&cef168_dev->sd); + + int ret =3D i2c_master_recv(client, (char *)rx_data, + sizeof(struct cef168_data)); + if (ret !=3D sizeof(struct cef168_data)) { + dev_err(&client->dev, "I2C read fail, ret=3D%d\n", ret); + return -EIO; + } + + u8 computed_crc =3D crc8(cef168_crc8_table, (const u8 *)rx_data, + sizeof(struct cef168_data) - 1, CRC8_INIT_VALUE); + if (computed_crc !=3D rx_data->crc8) { + dev_err(&client->dev, + "CRC mismatch calculated=3D0x%02X read=3D0x%02X\n", + computed_crc, rx_data->crc8); + return -EIO; + } + + rx_data->moving_time =3D le16_to_cpup((__le16 *)&rx_data->moving_time); + rx_data->focus_position_min =3D le16_to_cpup((__le16 *)&rx_data->focus_po= sition_min); + rx_data->focus_position_max =3D le16_to_cpup((__le16 *)&rx_data->focus_po= sition_max); + rx_data->focus_position_cur =3D le16_to_cpup((__le16 *)&rx_data->focus_po= sition_cur); + rx_data->focus_distance_min =3D le16_to_cpup((__le16 *)&rx_data->focus_di= stance_min); + rx_data->focus_distance_max =3D le16_to_cpup((__le16 *)&rx_data->focus_di= stance_max); + + return 0; +} + +static int cef168_set_ctrl(struct v4l2_ctrl *ctrl) +{ + struct cef168_device *dev =3D to_cef168(ctrl); + u8 cmd; + + switch (ctrl->id) { + case V4L2_CID_FOCUS_ABSOLUTE: + return cef168_i2c_write(dev, INP_SET_FOCUS, ctrl->val); + case V4L2_CID_FOCUS_RELATIVE: + cmd =3D ctrl->val < 0 ? INP_SET_FOCUS_N : INP_SET_FOCUS_P; + return cef168_i2c_write(dev, cmd, abs(ctrl->val)); + case V4L2_CID_IRIS_ABSOLUTE: + return cef168_i2c_write(dev, INP_SET_APERTURE, ctrl->val); + case V4L2_CID_IRIS_RELATIVE: + cmd =3D ctrl->val < 0 ? INP_SET_APERTURE_N : INP_SET_APERTURE_P; + return cef168_i2c_write(dev, cmd, abs(ctrl->val)); + case CEF168_V4L2_CID_CUSTOM(calibrate): + return cef168_i2c_write(dev, INP_CALIBRATE, 0); + } + + return -EINVAL; +} + +static int cef168_get_ctrl(struct v4l2_ctrl *ctrl) +{ + struct cef168_data data; + struct cef168_device *dev =3D to_cef168(ctrl); + int rval; + + rval =3D cef168_i2c_read(dev, &data); + if (rval < 0) + return rval; + + switch (ctrl->id) { + case V4L2_CID_FOCUS_ABSOLUTE: + ctrl->val =3D data.focus_position_cur; + return 0; + case CEF168_V4L2_CID_CUSTOM(focus_range): + ctrl->p_new.p_u32[0] =3D ((u32)data.focus_position_min << 16) | + (u32)data.focus_position_max; + return 0; + case CEF168_V4L2_CID_CUSTOM(lens_id): + ctrl->p_new.p_u8[0] =3D data.lens_id; + return 0; + case CEF168_V4L2_CID_CUSTOM(data): + memcpy(ctrl->p_new.p_u8, &data, sizeof(data)); + return 0; + } + + return -EINVAL; +} + +static const struct v4l2_ctrl_ops cef168_ctrl_ops =3D { + .g_volatile_ctrl =3D cef168_get_ctrl, + .s_ctrl =3D cef168_set_ctrl, +}; + +static const struct v4l2_ctrl_config cef168_lens_id_ctrl =3D { + .ops =3D &cef168_ctrl_ops, + .id =3D CEF168_V4L2_CID_CUSTOM(lens_id), + .type =3D V4L2_CTRL_TYPE_U8, + .name =3D "Lens ID", + .min =3D 0, + .max =3D U8_MAX, + .step =3D 1, + .def =3D 0, + .flags =3D V4L2_CTRL_FLAG_VOLATILE | V4L2_CTRL_FLAG_READ_ONLY, +}; + +static const struct v4l2_ctrl_config cef168_focus_range_ctrl =3D { + .ops =3D &cef168_ctrl_ops, + .id =3D CEF168_V4L2_CID_CUSTOM(focus_range), + .type =3D V4L2_CTRL_TYPE_U32, + .name =3D "Focus Range", + .min =3D 0, + .max =3D U32_MAX, + .step =3D 1, + .def =3D 0, + .flags =3D V4L2_CTRL_FLAG_VOLATILE | V4L2_CTRL_FLAG_READ_ONLY, +}; + +static const struct v4l2_ctrl_config cef168_data_ctrl =3D { + .ops =3D &cef168_ctrl_ops, + .id =3D CEF168_V4L2_CID_CUSTOM(data), + .type =3D V4L2_CTRL_TYPE_U8, + .name =3D "Data", + .min =3D 0, + .max =3D U8_MAX, + .step =3D 1, + .def =3D 0, + .dims =3D { sizeof(struct cef168_data) / sizeof(u8) }, + .elem_size =3D sizeof(u8), + .flags =3D V4L2_CTRL_FLAG_VOLATILE | V4L2_CTRL_FLAG_READ_ONLY, +}; + +static const struct v4l2_ctrl_config cef168_calibrate_ctrl =3D { + .ops =3D &cef168_ctrl_ops, + .id =3D CEF168_V4L2_CID_CUSTOM(calibrate), + .type =3D V4L2_CTRL_TYPE_BUTTON, + .name =3D "Calibrate", +}; + +static const struct v4l2_subdev_core_ops cef168_core_ops =3D { + .log_status =3D v4l2_ctrl_subdev_log_status, + .subscribe_event =3D v4l2_ctrl_subdev_subscribe_event, + .unsubscribe_event =3D v4l2_event_subdev_unsubscribe, +}; + +static const struct v4l2_subdev_ops cef168_ops =3D { + .core =3D &cef168_core_ops, +}; + +static int cef168_init_controls(struct cef168_device *dev) +{ + struct v4l2_ctrl *ctrl; + struct v4l2_ctrl_handler *hdl =3D &dev->ctrls; + const struct v4l2_ctrl_ops *ops =3D &cef168_ctrl_ops; + + v4l2_ctrl_handler_init(hdl, 8); + + ctrl =3D v4l2_ctrl_new_std(hdl, ops, V4L2_CID_FOCUS_ABSOLUTE, 0, S16_MAX, + 1, 0); + if (ctrl) + ctrl->flags |=3D V4L2_CTRL_FLAG_VOLATILE | + V4L2_CTRL_FLAG_EXECUTE_ON_WRITE; + v4l2_ctrl_new_std(hdl, ops, V4L2_CID_FOCUS_RELATIVE, S16_MIN, S16_MAX, + 1, 0); + ctrl =3D v4l2_ctrl_new_std(hdl, ops, V4L2_CID_IRIS_ABSOLUTE, 0, S16_MAX, + 1, 0); + if (ctrl) + ctrl->flags |=3D V4L2_CTRL_FLAG_WRITE_ONLY | + V4L2_CTRL_FLAG_EXECUTE_ON_WRITE; + v4l2_ctrl_new_std(hdl, ops, V4L2_CID_IRIS_RELATIVE, S16_MIN, S16_MAX, 1, + 0); + ctrl =3D v4l2_ctrl_new_custom(hdl, &cef168_calibrate_ctrl, NULL); + if (ctrl) + ctrl->flags |=3D V4L2_CTRL_FLAG_WRITE_ONLY | + V4L2_CTRL_FLAG_EXECUTE_ON_WRITE; + v4l2_ctrl_new_custom(hdl, &cef168_focus_range_ctrl, NULL); + v4l2_ctrl_new_custom(hdl, &cef168_data_ctrl, NULL); + v4l2_ctrl_new_custom(hdl, &cef168_lens_id_ctrl, NULL); + + if (hdl->error) + dev_err(dev->sd.dev, "%s fail error: 0x%x\n", __func__, + hdl->error); + dev->sd.ctrl_handler =3D hdl; + return hdl->error; +} + +static int cef168_probe(struct i2c_client *client) +{ + struct cef168_device *cef168_dev; + int rval; + + cef168_dev =3D devm_kzalloc(&client->dev, sizeof(*cef168_dev), + GFP_KERNEL); + if (!cef168_dev) + return -ENOMEM; + + v4l2_i2c_subdev_init(&cef168_dev->sd, client, &cef168_ops); + cef168_dev->sd.flags |=3D V4L2_SUBDEV_FL_HAS_DEVNODE | + V4L2_SUBDEV_FL_HAS_EVENTS; + + rval =3D cef168_init_controls(cef168_dev); + if (rval) + goto err_cleanup; + + rval =3D media_entity_pads_init(&cef168_dev->sd.entity, 0, NULL); + if (rval < 0) + goto err_cleanup; + + cef168_dev->sd.entity.function =3D MEDIA_ENT_F_LENS; + + rval =3D v4l2_async_register_subdev(&cef168_dev->sd); + if (rval < 0) + goto err_cleanup; + + crc8_populate_msb(cef168_crc8_table, CEF_CRC8_POLYNOMIAL); + + return 0; + +err_cleanup: + v4l2_ctrl_handler_free(&cef168_dev->ctrls); + media_entity_cleanup(&cef168_dev->sd.entity); + + return rval; +} + +static void cef168_remove(struct i2c_client *client) +{ + struct v4l2_subdev *sd =3D i2c_get_clientdata(client); + struct cef168_device *cef168_dev =3D sd_to_cef168(sd); + + v4l2_async_unregister_subdev(&cef168_dev->sd); + v4l2_ctrl_handler_free(&cef168_dev->ctrls); + media_entity_cleanup(&cef168_dev->sd.entity); +} + +static const struct of_device_id cef168_of_table[] =3D { + { .compatible =3D "pinefeat,cef168" }, + { /* sentinel */ } +}; +MODULE_DEVICE_TABLE(of, cef168_of_table); + +static struct i2c_driver cef168_i2c_driver =3D { + .driver =3D { + .name =3D CEF168_NAME, + .of_match_table =3D cef168_of_table, + }, + .probe =3D cef168_probe, + .remove =3D cef168_remove, +}; + +module_i2c_driver(cef168_i2c_driver); + +MODULE_AUTHOR("support@pinefeat.co.uk>"); +MODULE_DESCRIPTION("CEF168 lens driver"); +MODULE_LICENSE("GPL"); diff --git a/include/uapi/linux/v4l2-controls.h b/include/uapi/linux/v4l2-c= ontrols.h index f836512e9deb..7d6d026ef2ea 100644 --- a/include/uapi/linux/v4l2-controls.h +++ b/include/uapi/linux/v4l2-controls.h @@ -228,6 +228,12 @@ enum v4l2_colorfx { */ #define V4L2_CID_USER_RKISP1_BASE (V4L2_CID_USER_BASE + 0x1220) =20 +/* + * The base for Pinefeat CEF168 driver controls. + * We reserve 16 controls for this driver. + */ +#define V4L2_CID_USER_CEF168_BASE (V4L2_CID_USER_BASE + 0x1230) + /* MPEG-class control IDs */ /* The MPEG controls are applicable to all codec controls * and the 'MPEG' part of the define is historical */ --=20 2.34.1