itachi
itachi

Reputation: 3597

Kernel driver, is pinctrl property always needed when using GPIO overlay?

I've asked this question on Unix Stackexchange, but it seems it was a wrong place for this kind of problem. Ad rem:

I'm creating a kernel driver for SPI controlled display, which is meant to be working with Raspberry PI. Besides the three SPI lines, the display has 3 additional control lines: BUSY, RST and DC. In order to has a possibility of controlling these lines, my DTS has to include additional fragment for GPIO.

fragment@0 {
    target = <&spi0>;
    __overlay__ {
        #address-cells = <1>;
        #size-cells = <0>;

        status = "okay";

        spidev@0 {
            status = "disabled";
        };

        epd0: epd@0 {
            compatible = "waveshare,epd";
            reg = <0>;

            pinctrl-names = "default";
            pinctrl-0 = <&epd_pins>;

            spi-max-frequency = <1000000>;

            width = <128>;
            height = <296>;

            dc-gpios = <&gpio 16 0>;
            reset-gpios = <&gpio 20 0>;
            busy-gpios = <&gpio 21 0>;

            status = "okay";
        };
    };
};

fragment@1 {
    target = <&gpio>;
    __overlay__ {
        epd_pins: epd_pins {
            brcm,pins = <16 20 21>; /* DC RST BUSY */
            brcm,function = <1 1 0>; /* out out in */
        };
    };
};

That DTS works perfectly fine and I didn't expect any troubles. But there is one thing I'm not sure about:

pinctrl-names = "default";
pinctrl-0 = <&epd_pins>;

I've seen properties like that in other's DTs with gpio fragments, but not always; sometimes they are, sometimes they're not. If I comment out these two lines, it seems like nothing changes, and my driver still works as it should.

I have two questions:

  1. What is the purpose of those pinctrl lines? I'm aware of pin controller subsystem, but I'm asking strictly in context of my DT.
  2. Why do I need to declare the gpio overlay? I set IN or OUT function directly from my driver code anyway and my gpio numbers are defined in spi overlay (dc-gpios, reset-gpios, busy-gpios).

Upvotes: 1

Views: 3325

Answers (1)

yashC
yashC

Reputation: 995

To answer you question (assuming you understand the function of the pinctrl line in the device tree in general).

  1. When your device is probed by the kernel, if you have those pinctrl lines in your dts then the kernel requests the pinctrl subsystem to configure the pins listed under brcm,pins as their respective functions defined under brcm,function. The pinctrl state named default is requested to be set by the kernel automatically. You may define other states as

    pinctrl-names = "default", "sleep";

    pinctrl-0 = <&spi1_default>;

    pinctrl-1 = <&spi1_sleep>;

    and for other states like sleep or idle you will have to explicitly call them when the driver changes state for power management by calling functions pinctrl_pm_select_sleep_state or pinctrl_pm_select_idle_state respectively. You can only call these functions if the respective pin states are defined in device tree else you might have to do the configuring manually calling the pinctrl apis.

  2. Not necessary in your case, as you are said that you are explicitly setting the pin modes and configuration in device driver, then in that case for your particular case you might not need these lines in your device tree.

Upvotes: 5

Related Questions