Enable one wire (w1) drivers on TorizonCore to comunicate with DS2401 IC

We are evaluating TorizonCore running on a Colibri-iMX6DL with our custom carrier board. Our custom board has a DS2401 one wire Serial Number IC connected to pin 127 of the Colibri SoM and we need to be able to read it from our application.

The iMX6DL doesn’t have a dedicated one wire hardware peripheral so we were considering using the w1-gpio kernel driver which implements a one wire bus master using the GPIO API. We also found that there is a kernel driver compatible with the DS2401 IC: w1_smem.c.

As far as we can tell these drivers are not enabled on current releases of TorizonCore, so we were wondering if it would be possible to enable them for future releases. We believe enabling the following kernel configs would suffice:

CONFIG_W1
CONFIG_W1_GPIO
CONFIG_W1_SLAVE_SMEM

Regarding the device tree, we have the following working draft:

	onewire {
		compatible = "w1-gpio";
		gpios = <&gpio2 6 GPIO_ACTIVE_HIGH>;

		sn_ic {
			compatible = "w1-smem";
		};
	};

We are not sure what to assign the compatible property of the slave node, we guessed “w1-smem”.

Also we are not sure if the gpios property for the master node is correct and if we need to modify the iomuxc node somehow.

Regards,
Martin.

Greetings @mmarcos.sensor,

I can go ahead and put in the request to have these kernel options enabled by default. Have you already confirmed that these are the right options you need for your hardware peripheral?

We are not sure what to assign the compatible property of the slave node, we guessed “w1-smem”.

I’m not personally familiar with this driver or IC, but I didn’t find any compatible string “w1-smem” anywhere in the kernel. Therefore I don’t believe this is a valid compatible string.

Also we are not sure if the gpios property for the master node is correct and if we need to modify the iomuxc node somehow.

You need to add a pinctrl group to iomuxc to then assign this pin to the onewire node you have here. As a reference see this NXP customer who did a similar one-wire customization in the device tree: https://community.nxp.com/t5/i-MX-Processors/Enable-1-wire-in-DeviceTree-for-iMX6-DualLite/m-p/681241?ru=294756&sr=stream

Best Regards,
Jeremias

@jeremias.tx

I can go ahead and put in the request to have these kernel options enabled by default. Have you already confirmed that these are the right options you need for your hardware peripheral?

How could we confirm if these are the options we need? We researched the linux 1-wire (w1) subsystem, we browsed the driver sources and reviewed all available options in the Kconfig files. As far as we can tell we only need these 3 options to get our peripheral working with the linux drivers. Is there some way we could test it beforehand? We are currently trying to build a custom linux image to test config options, drivers and device tree. Do you think this is viable?

I’m not personally familiar with this driver or IC, but I didn’t find any compatible string “w1-smem” anywhere in the kernel. Therefore I don’t believe this is a valid compatible string.

We did some more research on the w1_smem driver and we now believe that a slave node for this type of device is not necessary, with the master node is enough. We are not going to be sure until we test it.

Following suggestions in the thread you linked, our current device tree draft is as follows:

/ {
	&iomuxc {
		pinctrl_onewire: onewiregrp {
			fsl,pins = <
				MX6QDL_PAD_NANDF_D6__GPIO2_IO06	0x4001b8b1
			>;
		};
	};

	onewire {
			compatible = "w1-gpio";
			gpios = <&gpio2 6 GPIO_ACTIVE_HIGH>;
			linux,open-drain;
			pinctrl-names = "default";
			pinctrl-0 = <&pinctrl_onewire>;
			status = "okay";
	};
};

We tried compiling and applying the device tree with torizoncore-builder and it compiled and applied successfully.

Hi @mmarcos.sensor ,

You can also use TorizonCore Builder to enable the W1 drivers as external kernel modules, see this article for more details: Building External Kernel Modules With Torizon | Toradex Developer Center

This way you can test before enabling the kernel options and be sure if these are the options you really need or not.

Best regards,
Lucas Akira

Thank you @lucas_a.tx for your reply.

We built a custom linux image to verify the kernel options and also to test the device tree. After a whole lot of testing we finally got it to work.

@jeremias.tx we can confirm that these are the right options we need.

CONFIG_W1
CONFIG_W1_GPIO
CONFIG_W1_SLAVE_SMEM

Please go ahead and put in the request to have these kernel options enabled by default on TorizonCore.

Regarding the device tree we found that for the w1-gpio driver to work properly the third cell of the gpios property of the master node, which corresponds to gpio flag bitfield, needs to be set to GPIO_OPEN_DRAIN. So the working device tree extract looks like this:

/ {
	&iomuxc {
		pinctrl_onewire: onewiregrp {
			fsl,pins = <
				MX6QDL_PAD_NANDF_D6__GPIO2_IO06	0x4001b8b1
			>;
		};
	};

	onewire {
			compatible = "w1-gpio";
			gpios = <&gpio2 6 GPIO_OPEN_DRAIN>;
			linux,open-drain;
			pinctrl-names = "default";
			pinctrl-0 = <&pinctrl_onewire>;
			status = "okay";
	};
};

Best regards,
Martin.

@mmarcos.sensor Thank you very much for confirming this.

I’ll go ahead and submit a request to the team to add the following kernel options:

CONFIG_W1
CONFIG_W1_GPIO
CONFIG_W1_SLAVE_SMEM

It may take up to a week or so before these get added and you start seeing them enabled in our nightly images going forward. Once they are added I’ll try to notify you here as a reminder.

Best Regards,
Jeremias

@mmarcos.sensor The requested configs have been added to our default kernel configuration as seen here: w1: enable w1 bus · toradex/toradex-kernel-cache@76225f2 · GitHub

These changes should now be available in our nightly builds of TorizonCore and will be a part of our releases going forward.

Best Regards,
Jeremias