Skip to contentSkip to conversation

Pinefeat cef168 lens control board driver

PATCH Superseded Alexander Smirnov 4 participants 10 messages Aug 11, 2025 – Aug 17, 2025

Subsystems (2)

v2 of 7 Superseded Latest is v7 →

lore
Share & tools
lore
#0 lore raw

v2 cover Pinefeat cef168 lens control board driver

From: Aliaksandr Smirnou <[email protected]>

This patch series adds support for the Pinefeat adapter, which interfaces Canon EF and EF-S lenses to non-Canon camera bodies. The cef168 circuit control board provides an I2C interface for electronic focus and aperture control. The driver integrates with the V4L2 sub-device API.

For more information about the product, see:
https://github.com/pinefeat/cef168

There are no regulators on the board. The MCU is powered by 3.3V, which is supplied either through the CSI connector or the serial connector directly from the Raspberry Pi GPIO power pins. Hence, the driver lacks any regulator handling. Please let me know if regulator support is still needed.

Changes in v2:
in [PATCH 1/2] addressed review comments:
- added optional vcc-supply property and example
- made node name generic in the example
- removed tree type and location from maintainers entry

in [PATCH 2/2] addressed review comments:
- wrapped devm_kzalloc line according to coding style
- removed oddly formed i2c_device_id struct as not required
- formatted of_device_id struct according to coding style

Link to v1: https://lore.kernel.org/all/[email protected]/

Patches:
dt-bindings: Pinefeat cef168 lens control board media/i2c: Pinefeat cef168 lens control board driver

 .../bindings/media/i2c/pinefeat,cef168.yaml   |  52 +++
 .../devicetree/bindings/vendor-prefixes.yaml  |   2 +
 MAINTAINERS                                   |   8 +
 drivers/media/i2c/Kconfig                     |   8 +
 drivers/media/i2c/Makefile                    |   1 +
 drivers/media/i2c/cef168.c                    | 337 ++++++++++++++++++
 drivers/media/i2c/cef168.h                    |  51 +++
 7 files changed, 459 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/media/i2c/pinefeat,cef168.yaml
 create mode 100644 drivers/media/i2c/cef168.c
 create mode 100644 drivers/media/i2c/cef168.h

base-commit: 2b38afce25c4e1b8f943ff4f0a2b51d6c40f2ed2

Signature · 1 line
2.34.1
#1 lore raw

PATCH v2 1/2 dt-bindings: Pinefeat cef168 lens control board

From: Aliaksandr Smirnou <[email protected]>

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.

---
 .../bindings/media/i2c/pinefeat,cef168.yaml   | 52 +++++++++++++++++++
 .../devicetree/bindings/vendor-prefixes.yaml  |  2 +
 MAINTAINERS                                   |  6 +++
 3 files changed, 60 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/media/i2c/pinefeat,cef168.yaml
Documentation/devicetree/bindings/media/i2c/pinefeat,cef168.yaml new file +52 -0
new file mode 100644
index 000000000000..3563fb1d46db
@@ -0,0 +1,52 @@
+# 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 <[email protected]>
+
+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. This driver enables controlling the lens
+  focus and aperture via the V4L2 (Video4Linux2) API.
+
+properties:
+  compatible:
+    enum:
+      - pinefeat,cef168
+
+  reg:
+    maxItems: 1
+
+  vcc-supply:
+    description: VDD 3v3 power supply
+
+required:
+  - compatible
+  - reg
+
+additionalProperties: false
+
+examples:
+  - |
+    i2c {
+        #address-cells = <1>;
+        #size-cells = <0>;
+
+        camera-lens@d {
+            compatible = "pinefeat,cef168";
+            reg = <0x0d>;
+            vcc-supply = <&vdd_3v3_reg>;
+        };
+    };
+
+...
Documentation/devicetree/bindings/vendor-prefixes.yaml +2 -0
index 77160cd47f54..dab27f769b0a 100644
@@ -1195,6 +1195,8 @@ patternProperties:
     description: Picochip Ltd
   "^pine64,.*":
     description: Pine64
+  "^pinefeat,.*":
+    description: Pinefeat LLP
   "^pineriver,.*":
     description: Shenzhen PineRiver Designs Co., Ltd.
   "^pixcir,.*":
MAINTAINERS +6 -0
index fe168477caa4..811c6a150029 100644
@@ -19985,6 +19985,12 @@ S:	Supported
 F:	Documentation/devicetree/bindings/input/pine64,pinephone-keyboard.yaml
 F:	drivers/input/keyboard/pinephone-keyboard.c
 
+PINEFEAT CEF168 LENS DRIVER
+M:	Aliaksandr Smirnou <[email protected]>
+L:	[email protected]
+S:	Supported
+F:	Documentation/devicetree/bindings/media/i2c/pinefeat,cef168.yaml
+
 PLANTOWER PMS7003 AIR POLLUTION SENSOR DRIVER
 M:	Tomasz Duszynski <[email protected]>
 S:	Maintained
Signature · 1 line
2.34.1
#2 lore raw

Re: [PATCH v2 1/2] dt-bindings: Pinefeat cef168 lens control board

Quoted 1 line · Alexander Smirnov

+

Subject: missing media prefix.

See also:
https://elixir.bootlin.com/linux/v6.7-rc8/source/Documentation/devicetree/bindings/submitting-patches.rst#L18

Documentation/devicetree/bindings/media/i2c/pinefeat,cef168.yaml line 31

Quoted 10 lines
Documentation/devicetree/bindings/media/i2c/pinefeat,cef168.yaml new file +10 -0
+properties:
+  compatible:
+    enum:
+      - pinefeat,cef168
+
+  reg:
+    maxItems: 1
+
+  vcc-supply:
+    description: VDD 3v3 power supply

Property says VCC, description says VDD, datasheet says 5V (not 3.3V).

I guess this should be for the 5V case, no? If that's true, then I think that 5V pin is not a controllable supply ever, because this product is purely for RPi which has 5V pins directly tied to main power supply.

Best regards,
Krzysztof

#3 lore raw

PATCH v2 1/2 dt-bindings: Pinefeat cef168 lens control board

Quoted 3 lines · Krzysztof Kozlowski

Property says VCC, description says VDD, datasheet says 5V (not 3.3V).

I guess this should be for the 5V case, no?

Thank you following up.

The 5V line is used exclusively to power the lens motor (through the power switch). This 5V supply can come from the Raspberry Pi GPIO header, a battery, or other sources. Importantly, this power source is independent of the board’s MCU and its kernel driver.

Additionally, the board does not include any voltage regulators. The MCU operates at 3.3V, which is supplied either via the CSI connector or the serial connector directly from the Raspberry Pi GPIO 3.3V rail. Therefore, the driver does not manage any regulator, which is why the “vcc-supply” property was absent in the binding.

Would you like me to remove the “vcc-supply” property as it was originally?

#4 lore raw

Re: [PATCH v2 1/2] dt-bindings: Pinefeat cef168 lens control board

Quoted 11 lines · Aliaksandr Smirnou
Quoted 3 lines · Krzysztof Kozlowski

Property says VCC, description says VDD, datasheet says 5V (not 3.3V).

I guess this should be for the 5V case, no?

Thank you following up.

The 5V line is used exclusively to power the lens motor (through the power switch). This 5V supply can come from the Raspberry Pi GPIO header, a battery, or other sources. Importantly, this power source is independent of the board’s MCU and its kernel driver.

You describe here the entire board, not the MCU only or lens motor only...

Quoted 9 lines

Additionally, the board does not include any voltage regulators. The MCU operates at 3.3V, which is supplied either via the CSI connector or the serial connector directly from the Raspberry Pi GPIO 3.3V rail. Therefore, the driver does not manage any regulator, which is why the “vcc-supply” property was absent in the binding.

Would you like me to remove the “vcc-supply” property as it was originally?

Can the board be used outside of above setup? I understand so far this is only for Rpi where both above supplies - 3.3 V and 5 V - are coming from the header pins, so supplies would be totally redundant.

Best regards,
Krzysztof

#5 lore raw

Re: [PATCH v2 1/2] dt-bindings: Pinefeat cef168 lens control board

Quoted 2 lines · Krzysztof Kozlowski

You describe here the entire board, not the MCU only or lens motor only...

Since you asked about 5 V, I was explaining that this power source is not relevant for the driver.

Quoted 3 lines

Can the board be used outside of above setup? I understand so far this is only for Rpi where both above supplies - 3.3 V and 5 V - are coming from the header pins, so supplies would be totally redundant.

There are several variants of the board, differing only in physical size and type of CSI connector, targeting different cameras. The board should be compatible with any single-board computer that uses a similar CSI connector pinout and MIPI signal lane assignment. For example, the NVIDIA Jetson series replicates the Raspberry Pi camera and GPIO header pinout. So yes, the board can be used outside of a Raspberry Pi setup.

As noted above, these supplies are redundant and were not included in the driver description. Given that, is it acceptable to remove the vcc-supply property?

#6 lore raw

Re: [PATCH v2 1/2] dt-bindings: Pinefeat cef168 lens control board

Quoted 11 lines · Aliaksandr Smirnou
Quoted 2 lines · Krzysztof Kozlowski

You describe here the entire board, not the MCU only or lens motor only...

Since you asked about 5 V, I was explaining that this power source is not relevant for the driver.

Quoted 3 lines

Can the board be used outside of above setup? I understand so far this is only for Rpi where both above supplies - 3.3 V and 5 V - are coming from the header pins, so supplies would be totally redundant.

Quoted 6 lines

There are several variants of the board, differing only in physical size and type of CSI connector, targeting different cameras. The board should be compatible with any single-board computer that uses a similar CSI connector pinout and MIPI signal lane assignment. For example, the NVIDIA Jetson series replicates the Raspberry Pi camera and GPIO header pinout. So yes, the board can be used outside of a Raspberry Pi setup.

If they replicate also power coming from the header and CSI line, then it's fine, but if the do not, then you would need a controllable regulator supply.

Quoted 4 lines

As noted above, these supplies are redundant and were not included in the driver description. Given that, is it acceptable to remove the vcc-supply property?

Yeah, for simplicity. Please mention this rationale in the commit msg - power supply is derived from fixed supplies (connector/header on RPi), so representing it is redundant.

Best regards,
Krzysztof

#7 lore raw

Re: [PATCH v2 1/2] dt-bindings: Pinefeat cef168 lens control board

In reply to Alexander Smirnov
Quoted 4 lines · Alexander Smirnov

From: Aliaksandr Smirnou <[email protected]>

Add the Device Tree schema and examples for the Pinefeat cef168 lens
control board. This board interfaces Canon EF & EF-S lenses with

Also, some stray indent is here.

Quoted 4 lines

non-Canon camera bodies, enabling electronic control of focus and aperture via V4L2.

Best regards,
Krzysztof

#8 lore raw

PATCH v2 2/2 media/i2c: Pinefeat cef168 lens control board driver

In reply to Alexander Smirnov

From: Aliaksandr Smirnou <[email protected]>

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.

---
 MAINTAINERS                |   2 +
 drivers/media/i2c/Kconfig  |   8 +
 drivers/media/i2c/Makefile |   1 +
 drivers/media/i2c/cef168.c | 337 +++++++++++++++++++++++++++++++++++++
 drivers/media/i2c/cef168.h |  51 ++++++
 5 files changed, 399 insertions(+)
 create mode 100644 drivers/media/i2c/cef168.c
 create mode 100644 drivers/media/i2c/cef168.h
MAINTAINERS +2 -0
index 811c6a150029..922efc000722 100644
@@ -19990,6 +19990,8 @@ M:	Aliaksandr Smirnou <[email protected]>
 L:	[email protected]
 S:	Supported
 F:	Documentation/devicetree/bindings/media/i2c/pinefeat,cef168.yaml
+F:	drivers/media/i2c/cef168.c
+F:	drivers/media/i2c/cef168.h
 
 PLANTOWER PMS7003 AIR POLLUTION SENSOR DRIVER
 M:	Tomasz Duszynski <[email protected]>
drivers/media/i2c/Kconfig +8 -0
index 6237fe804a5c..c4c3b03a0b98 100644
@@ -791,6 +791,14 @@ config VIDEO_AK7375
 	  capability. This is designed for linear control of
 	  voice coil motors, controlled via I2C serial interface.
 
+config VIDEO_CEF168
+	tristate "CEF168 lens control support"
+	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
drivers/media/i2c/Makefile +1 -0
index 5873d29433ee..75a95f850f18 100644
@@ -25,6 +25,7 @@ obj-$(CONFIG_VIDEO_BT856) += bt856.o
 obj-$(CONFIG_VIDEO_BT866) += bt866.o
 obj-$(CONFIG_VIDEO_CCS) += ccs/
 obj-$(CONFIG_VIDEO_CCS_PLL) += ccs-pll.o
+obj-$(CONFIG_VIDEO_CEF168) += cef168.o
 obj-$(CONFIG_VIDEO_CS3308) += cs3308.o
 obj-$(CONFIG_VIDEO_CS5345) += cs5345.o
 obj-$(CONFIG_VIDEO_CS53L32A) += cs53l32a.o
drivers/media/i2c/cef168.c new file +337 -0

337 lines not on this page · raw message

drivers/media/i2c/cef168.h new file +51 -0

51 lines not on this page · raw message

Signature · 1 line
2.34.1
#9 lore raw

Re: [PATCH v2 2/2] media/i2c: Pinefeat cef168 lens control board driver

kernel test robot noticed the following build warnings:

Hi Alexander,

kernel test robot noticed the following build warnings:

[auto build test WARNING on 2b38afce25c4e1b8f943ff4f0a2b51d6c40f2ed2]

url:    https://github.com/intel-lab-lkp/linux/commits/Alexander-Smirnov/dt-bindings-Pinefeat-cef168-lens-control-board/20250812-053441
base:   2b38afce25c4e1b8f943ff4f0a2b51d6c40f2ed2
patch link:    https://lore.kernel.org/r/20250811213102.15703-3-aliaksandr.smirnou%40gmail.com
patch subject: [PATCH v2 2/2] media/i2c: Pinefeat cef168 lens control board driver
config: arm64-randconfig-r132-20250813 (https://download.01.org/0day-ci/archive/20250813/[email protected]/config)
compiler: aarch64-linux-gcc (GCC) 12.5.0
reproduce: (https://download.01.org/0day-ci/archive/20250813/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

sparse warnings: (new ones prefixed by >>)

>> drivers/media/i2c/cef168.c:37:13: sparse: sparse: incorrect type in assignment (different base types) @@     expected unsigned short [usertype] val @@     got restricted __le16 [usertype] @@
   drivers/media/i2c/cef168.c:37:13: sparse:     expected unsigned short [usertype] val
   drivers/media/i2c/cef168.c:37:13: sparse:     got restricted __le16 [usertype]
>> drivers/media/i2c/cef168.c:76:32: sparse: sparse: cast to restricted __le16
>> drivers/media/i2c/cef168.c:76:32: sparse: sparse: cast to restricted __le16
>> drivers/media/i2c/cef168.c:76:32: sparse: sparse: cast to restricted __le16
>> drivers/media/i2c/cef168.c:76:32: sparse: sparse: cast to restricted __le16
   drivers/media/i2c/cef168.c:77:39: sparse: sparse: cast to restricted __le16
   drivers/media/i2c/cef168.c:77:39: sparse: sparse: cast to restricted __le16
   drivers/media/i2c/cef168.c:77:39: sparse: sparse: cast to restricted __le16
   drivers/media/i2c/cef168.c:77:39: sparse: sparse: cast to restricted __le16
   drivers/media/i2c/cef168.c:78:39: sparse: sparse: cast to restricted __le16
   drivers/media/i2c/cef168.c:78:39: sparse: sparse: cast to restricted __le16
   drivers/media/i2c/cef168.c:78:39: sparse: sparse: cast to restricted __le16
   drivers/media/i2c/cef168.c:78:39: sparse: sparse: cast to restricted __le16
   drivers/media/i2c/cef168.c:79:39: sparse: sparse: cast to restricted __le16
   drivers/media/i2c/cef168.c:79:39: sparse: sparse: cast to restricted __le16
   drivers/media/i2c/cef168.c:79:39: sparse: sparse: cast to restricted __le16
   drivers/media/i2c/cef168.c:79:39: sparse: sparse: cast to restricted __le16
   drivers/media/i2c/cef168.c:80:39: sparse: sparse: cast to restricted __le16
   drivers/media/i2c/cef168.c:80:39: sparse: sparse: cast to restricted __le16
   drivers/media/i2c/cef168.c:80:39: sparse: sparse: cast to restricted __le16
   drivers/media/i2c/cef168.c:80:39: sparse: sparse: cast to restricted __le16
   drivers/media/i2c/cef168.c:81:39: sparse: sparse: cast to restricted __le16
   drivers/media/i2c/cef168.c:81:39: sparse: sparse: cast to restricted __le16
   drivers/media/i2c/cef168.c:81:39: sparse: sparse: cast to restricted __le16
   drivers/media/i2c/cef168.c:81:39: sparse: sparse: cast to restricted __le16
>> drivers/media/i2c/cef168.c:133:30: sparse: sparse: cast to restricted __le32
>> drivers/media/i2c/cef168.c:133:30: sparse: sparse: cast to restricted __le32
>> drivers/media/i2c/cef168.c:133:30: sparse: sparse: cast to restricted __le32
>> drivers/media/i2c/cef168.c:133:30: sparse: sparse: cast to restricted __le32
>> drivers/media/i2c/cef168.c:133:30: sparse: sparse: cast to restricted __le32
>> drivers/media/i2c/cef168.c:133:30: sparse: sparse: cast to restricted __le32

vim +37 drivers/media/i2c/cef168.c

    31	
    32	static int cef168_i2c_write(struct cef168_device *cef168_dev, u8 cmd, u16 val)
    33	{
    34		struct i2c_client *client = v4l2_get_subdevdata(&cef168_dev->sd);
    35		int retry, ret;
    36	
  > 37		val = cpu_to_le16(val);
    38		char tx_data[4] = { cmd, (val & 0xff), (val >> 8) };
    39	
    40		tx_data[3] = crc8(cef168_crc8_table, tx_data, 3, CRC8_INIT_VALUE);
    41	
    42		for (retry = 0; retry < 3; retry++) {
    43			ret = i2c_master_send(client, tx_data, sizeof(tx_data));
    44			if (ret == sizeof(tx_data))
    45				return 0;
    46			else if (ret != -EIO && ret != -EREMOTEIO)
    47				break;
    48		}
    49	
    50		dev_err(&client->dev, "I2C write fail after %d retries, ret=%d\n",
    51			retry, ret);
    52		return -EIO;
    53	}
    54	
    55	static int cef168_i2c_read(struct cef168_device *cef168_dev,
    56				   struct cef168_data *rx_data)
    57	{
    58		struct i2c_client *client = v4l2_get_subdevdata(&cef168_dev->sd);
    59	
    60		int ret = i2c_master_recv(client, (char *)rx_data,
    61					  sizeof(struct cef168_data));
    62		if (ret != sizeof(struct cef168_data)) {
    63			dev_err(&client->dev, "I2C read fail, ret=%d\n", ret);
    64			return -EIO;
    65		}
    66	
    67		u8 computed_crc = crc8(cef168_crc8_table, (const u8 *)rx_data,
    68				       sizeof(struct cef168_data) - 1, CRC8_INIT_VALUE);
    69		if (computed_crc != rx_data->crc8) {
    70			dev_err(&client->dev,
    71				"CRC mismatch calculated=0x%02X read=0x%02X\n",
    72				computed_crc, rx_data->crc8);
    73			return -EIO;
    74		}
    75	
  > 76		rx_data->moving_time = le16_to_cpu(rx_data->moving_time);
    77		rx_data->focus_position_min = le16_to_cpu(rx_data->focus_position_min);
    78		rx_data->focus_position_max = le16_to_cpu(rx_data->focus_position_max);
    79		rx_data->focus_position_cur = le16_to_cpu(rx_data->focus_position_cur);
    80		rx_data->focus_distance_min = le16_to_cpu(rx_data->focus_distance_min);
    81		rx_data->focus_distance_max = le16_to_cpu(rx_data->focus_distance_max);
    82	
    83		return 0;
    84	}
    85	
    86	static int cef168_set_ctrl(struct v4l2_ctrl *ctrl)
    87	{
    88		struct cef168_device *dev = to_cef168(ctrl);
    89		u8 cmd;
    90	
    91		switch (ctrl->id) {
    92		case V4L2_CID_FOCUS_ABSOLUTE:
    93			return cef168_i2c_write(dev, INP_SET_FOCUS, ctrl->val);
    94		case V4L2_CID_FOCUS_RELATIVE:
    95			cmd = ctrl->val < 0 ? INP_SET_FOCUS_N : INP_SET_FOCUS_P;
    96			return cef168_i2c_write(dev, cmd, abs(ctrl->val));
    97		case V4L2_CID_IRIS_ABSOLUTE:
    98			return cef168_i2c_write(dev, INP_SET_APERTURE, ctrl->val);
    99		case V4L2_CID_IRIS_RELATIVE:
   100			cmd = ctrl->val < 0 ? INP_SET_APERTURE_N : INP_SET_APERTURE_P;
   101			return cef168_i2c_write(dev, cmd, abs(ctrl->val));
   102		case CEF168_V4L2_CID_CUSTOM(calibrate):
   103			return cef168_i2c_write(dev, INP_CALIBRATE, 0);
   104			return 0;
   105		}
   106	
   107		return -EINVAL;
   108	}
   109	
   110	static int cef168_get_ctrl(struct v4l2_ctrl *ctrl)
   111	{
   112		struct cef168_device *dev = to_cef168(ctrl);
   113		int rval;
   114	
   115		if (ctrl->id != V4L2_CID_FOCUS_ABSOLUTE &&
   116		    ctrl->id != CEF168_V4L2_CID_CUSTOM(data) &&
   117		    ctrl->id != CEF168_V4L2_CID_CUSTOM(focus_range) &&
   118		    ctrl->id != CEF168_V4L2_CID_CUSTOM(lens_id))
   119			return -EINVAL;
   120	
   121		struct cef168_data data;
   122	
   123		rval = cef168_i2c_read(dev, &data);
   124		if (rval < 0)
   125			return rval;
   126	
   127		switch (ctrl->id) {
   128		case V4L2_CID_FOCUS_ABSOLUTE:
   129			ctrl->val = data.focus_position_cur;
   130			return 0;
   131		case CEF168_V4L2_CID_CUSTOM(focus_range):
   132			ctrl->p_new.p_u32[0] =
 > 133				(u32)le32_to_cpu(((u32)data.focus_position_min << 16) |

134 data.focus_position_max);
135 return 0;
136 case CEF168_V4L2_CID_CUSTOM(lens_id):
137 ctrl->p_new.p_u8[0] = data.lens_id;
138 return 0;
139 case CEF168_V4L2_CID_CUSTOM(data):
140 memcpy(ctrl->p_new.p_u8, &data, sizeof(data));
141 return 0;
142 }
143
144 return -EINVAL;
145 }
146

Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki