Search code examples
linuxlinux-device-driverbeagleboneblackyoctopwm

Beaglebone devm_pwm_get returns ENODEV


I am experimenting with a pwm-driver for the Beaglebone black, based of this one.

As I am using Yocto with the meta-bbb layer, I had to rewrite the .dtsi:

&am33xx_pinmux {
    bbb_pwm_P8_13_pins: bbb_pwm_P8_13_pins {
        pinctrl-single,pins = <0x024  0x4>; /* P8_13 (ZCZ ball T10) | MODE 4 */
    };
};


/ {
    bbb-pwm@123 {
        compatible  = "tfe,bbb_pwm-1.00.a";
        pwms        = <&ehrpwm2 1 0 1>;
        pwm-names   = "PWM_P8_13";

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

        enabled     = <0>;
        duty        = <0>;
        status      = "okay";
    };
};

However, during the driver-probe function, the call

pwm_test->pwm = devm_pwm_get(&pdev->dev, NULL);

returns ENODEV:

[    7.538249] pinctrl-single 44e10800.pinmux: found group selector 15 for bbb_pwm_P8_13_pins
[    7.538278] pinctrl-single 44e10800.pinmux: request pin 9 (44e10824.0) for bbb-pwm@123
[    7.538291] pinctrl-single 44e10800.pinmux: enabling bbb_pwm_P8_13_pins function15
[    7.538366] Loading bbb_pwm
[    7.541304] bbb-pwm bbb-pwm@123: obtain a copy of previously claimed pinctrl
[    7.541321] bbb-pwm bbb-pwm@123: Unable to request PWM (err = -19)

I found that the error-code is returned by a sub-call of devm_pwm_get:

static int pwm_device_request(struct pwm_device *pwm, const char *label)
{
    /* .... */

    if (!try_module_get(pwm->chip->ops->owner))
        return -ENODEV;

    /* ... */
}

However, since I am fairly new to Linux-drivers, I do not understand why this happens. Any clues?


Solution

  • It turned out that the lower-level PWM-driver (EHRPWM) was disabled in the kernel. Enabling it using menuconfig and ensuring that EHRPWM and EPWMSS was enabled in the device tree solved my problem:

    Using the meta-bbb layer, I simply accessed menuconfig through bitbake:

    bitbake virtual/kernel -c menuconfig
    

    and loaded the defconfig located /meta-bbb/recipes-kernel/linux/linux-stable-4.4/beaglebone/defconfig

    I also added the following line to my local.conf

    PREFERRED_VERSION_linux-stable = "4.4"
    

    Here is my dtsi:

    &am33xx_pinmux {
        bbb_pwm_P8_13_pins: bbb_pwm_P8_13_pins {
            pinctrl-single,pins = <0x024  0x4>; /* P8_13 (ZCZ ball T10) | MODE 4 */
        };
    };
    
    &ehrpwm2 {
        status = "okay";
    };
    
    &epwmss2 {
        status = "okay";
    };
    
    / {
        bbb-pwm@123 {
            compatible  = "tfe,bbb_pwm-1.00.a";
            pwms        = <&ehrpwm2 1 0 1>;
            pwm-names   = "PWM_P8_13";
    
            pinctrl-names   = "default";
            pinctrl-0   = <&bbb_pwm_P8_13_pins>;
    
            enabled     = <0>;
            duty        = <0>;
            status      = "okay";
        };
    };