On Mon, Oct 30, 2023 at 04:43:28PM +0100, Ilario Gelmetti wrote:
> So, the final DTS file looks like this:
> 
> ```
> /dts-v1/;
> /plugin/;
> 
> / {
>       compatible = "allwinner,sun50i-a64",
>                      "olimex,a64-olinuxino";
>       description = "Enable 1-Wire port";
> 
>       fragment@0 {
>               target-path="/";
>               __overlay__ {
>                       onewire {
>                               compatible = "w1-gpio";
>                               pinctrl-names = "default";
>                               gpios = <&pio 1 0 16>;
>                               /* 1: B of PB0; 0: 0 of PB0;
>                               16 = (GPIO_ACTIVE_HIGH | GPIO_PULL_UP)
>                               = (0 bitwise OR 16)
>                               0 in the bit 0 means GPIO_ACTIVE_HIGH
>                               1 in the bit 4 = 16 means GPIO_PULL_UP
>                               0b10000 = 16 */
>                               status = "okay";
>                       };
>               };
>       };
> };
> ```

A syntax probably more straightforward would be

/dts-v1/;
/plugin/;

#include <dt-bindings/gpio/gpio.h>

&{/} {
    onewire {
        compatible = "w1-gpio";
        gpios = <&pio 1 0 GPIO_PULL_UP>;
        status = "okay";
    };
};

> It has been compiled with:
> 
> ```
> dtc -I dts -O dtb sun50i-a64-w1-gpio.dts -o sun50i-a64-w1-gpio.dtbo
> ```

And if you put that file under

> ```
> # cat /sys/kernel/debug/gpio
> gpiochip1: GPIOs 0-255, parent: platform/1c20800.pinctrl, 1c20800.pinctrl:
>  gpio-32  (                    |onewire             ) out hi
>  gpio-166 (                    |cd                  ) in  lo ACTIVE LOW
>  gpio-201 (                    |usb1-vbus           ) out hi
>  gpio-230 (                    |usb0_vbus_det       ) in  lo IRQ
>  gpio-233 (                    |usb0_id_det         ) in  hi IRQ
> 
> gpiochip0: GPIOs 352-383, parent: platform/1f02c00.pinctrl, 1f02c00.pinctrl:
> 
> gpiochip2: GPIOs 510-511, parent: platform/axp20x-gpio, axp20x-gpio, can
> sleep:
> ```
> 
> It is surprising to me that it works even if the pin 32 (PB0 on Allwinner
> A64) is marked as output :)

The GPIO controller doesn't support simultaneous input and output and
1-wire needs to do both so it flips back and forth between input and
output.

> > > [] Driver for 1-wire Dallas network protocol.
> > > [] sun50i-a64-pinctrl 1c20800.pinctrl: pin PB0 already requested by
> > > onewire_device; cannot claim for 1c20800.pinctrl:32
> > > [] sun50i-a64-pinctrl 1c20800.pinctrl: pin-32 (1c20800.pinctrl:32)
> > > status -22
> > > [] w1-gpio onewire_device: gpio_request (pin) failed
> > > [] w1-gpio: probe of onewire_device failed with error -22
> > 
> > The problem is that the GPIO reference and the pinctrl reference for the
> > same pin conflict. In this case, the only thing you need the pinctrl
> > reference for is the pull-up, which you can achieve with a GPIO flag.
> > However, for the more general case, you may need to apply some other
> > pinconf setting to a GPIO pin, so we may need to fix this.
>
> For me, it is surprising how other people do not have my same issue.
> For example, in the instructions on the wiki [7], in the DTS from Armbian
> [8] and in the one used by RaspberryPi (on Broadcom) [9] they all use the
> same pin in two fragments. I tried using all of these and always got the
> "already requested by" error.

It also depends on the general design of the GPIO controller. Ours
doesn't support both GPIO and some other feature at the same time, they
are exclusive, some do.

The GPIO framework support both though, and by default will allow to
request a GPIO and another pin muxing at the same time. This was fixed
in 2017, so the wiki might be older than that and have never been
updated. armbian is probably in the same case.

The RaspberryPi driver might have a bug or a different design that
allows what we can't do.

Maxime

-- 
You received this message because you are subscribed to the Google Groups 
"linux-sunxi" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to linux-sunxi+unsubscr...@googlegroups.com.
To view this discussion on the web, visit 
https://groups.google.com/d/msgid/linux-sunxi/pio6en53vvtseg634zuafjjf4sbqdutctj7vunrgdjungpdzc2%40zsyhes5eedfa.

Attachment: signature.asc
Description: PGP signature

Reply via email to