tobetter / linux

Linux kernel source tree
Other
68 stars 30 forks source link

linux 6.0: `drivers/pwm/pwm-gpio.c` #39

Closed pyavitz closed 1 year ago

pyavitz commented 1 year ago

hitting the following

drivers/pwm/pwm-gpio.c:138:10: error: ‘const struct pwm_ops’ has no member named ‘config’
  138 |         .config = gpio_pwm_config,
      |          ^~~~~~
drivers/pwm/pwm-gpio.c:138:19: error: initialization of ‘int (*)(struct pwm_chip *, struct pwm_device *)’ from incompatible pointer type ‘int (*)(struct pwm_chip *, struct pwm_device *, int,  int)’ [-Werror=incompatible-pointer-types]
  138 |         .config = gpio_pwm_config,
      |                   ^~~~~~~~~~~~~~~
drivers/pwm/pwm-gpio.c:138:19: note: (near initialization for ‘gpio_pwm_ops.request’)
drivers/pwm/pwm-gpio.c:139:10: error: ‘const struct pwm_ops’ has no member named ‘set_polarity’
  139 |         .set_polarity = gpio_pwm_set_polarity,
      |          ^~~~~~~~~~~~
drivers/pwm/pwm-gpio.c:139:25: error: initialization of ‘void (*)(struct pwm_chip *, struct pwm_device *)’ from incompatible pointer type ‘int (*)(struct pwm_chip *, struct pwm_device *, enum pwm_polarity)’ [-Werror=incompatible-pointer-types]
  139 |         .set_polarity = gpio_pwm_set_polarity,
      |                         ^~~~~~~~~~~~~~~~~~~~~
drivers/pwm/pwm-gpio.c:139:25: note: (near initialization for ‘gpio_pwm_ops.free’)
drivers/pwm/pwm-gpio.c:140:10: error: ‘const struct pwm_ops’ has no member named ‘enable’
  140 |         .enable = gpio_pwm_enable,
      |          ^~~~~~
drivers/pwm/pwm-gpio.c:140:19: error: initialization of ‘int (*)(struct pwm_chip *, struct pwm_device *, struct pwm_capture *, long unsigned int)’ from incompatible pointer type ‘int (*)(struct pwm_chip *, struct pwm_device *)’ [-Werror=incompatible-pointer-types]
  140 |         .enable = gpio_pwm_enable,
      |                   ^~~~~~~~~~~~~~~
drivers/pwm/pwm-gpio.c:140:19: note: (near initialization for ‘gpio_pwm_ops.capture’)
drivers/pwm/pwm-gpio.c:141:10: error: ‘const struct pwm_ops’ has no member named ‘disable’
  141 |         .disable = gpio_pwm_disable,
      |          ^~~~~~~
drivers/pwm/pwm-gpio.c:141:20: error: initialization of ‘int (*)(struct pwm_chip *, struct pwm_device *, const struct pwm_state *)’ from incompatible pointer type ‘void (*)(struct pwm_chip *, struct pwm_device *)’ [-Werror=incompatible-pointer-types]
  141 |         .disable = gpio_pwm_disable,
      |                    ^~~~~~~~~~~~~~~~
drivers/pwm/pwm-gpio.c:141:20: note: (near initialization for ‘gpio_pwm_ops.apply’)
ginkage commented 1 year ago

Apparently something like this could fix it (I'll test and report separately):

diff --git a/drivers/pwm/pwm-gpio.c b/drivers/pwm/pwm-gpio.c
index 6707a5dbe..b82a94430 100644
--- a/drivers/pwm/pwm-gpio.c
+++ b/drivers/pwm/pwm-gpio.c
@@ -134,11 +134,43 @@ static void gpio_pwm_disable(struct pwm_chip *chip, struct pwm_device *pwm)
                gpio_pwm_off(gpio_data);
 }

+static int gpio_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm,
+                         const struct pwm_state *state)
+{
+       int err;
+       bool enabled = pwm->state.enabled;
+
+       if (state->polarity != pwm->state.polarity) {
+               if (enabled) {
+                       gpio_pwm_disable(chip, pwm);
+                       enabled = false;
+               }
+
+               err = gpio_pwm_set_polarity(chip, pwm, state->polarity);
+               if (err)
+                       return err;
+       }
+
+       if (!state->enabled) {
+               if (enabled)
+                       gpio_pwm_disable(chip, pwm);
+
+               return 0;
+       }
+
+       err = gpio_pwm_config(pwm->chip, pwm,
+                             state->duty_cycle, state->period);
+       if (err)
+               return err;
+
+       if (!enabled)
+               err = gpio_pwm_enable(chip, pwm);
+
+       return err;
+}
+
 static const struct pwm_ops gpio_pwm_ops = {
-       .config = gpio_pwm_config,
-       .set_polarity = gpio_pwm_set_polarity,
-       .enable = gpio_pwm_enable,
-       .disable = gpio_pwm_disable,
+       .apply = gpio_pwm_apply,
        .owner = THIS_MODULE,
 };
ginkage commented 1 year ago

See also 0829c35dc5346e90f428de61896362b51ab58296 and ec00cd5e63f05461ab48128775c73c851c3c2b18

ginkage commented 1 year ago

Welp, at least it builds.

pyavitz commented 1 year ago

Good job. I can verify not only does it build but it also works.

odroidn2plus: ~  $ dmesg | grep "Linux version"
[    0.000000] Linux version 6.0.5 (marvin@martian) (gcc-12 (Ubuntu 12.1.0-2ubuntu1~22.04) 12.1.0, GNU ld (GNU Binutils for Ubuntu) 2.38) #1 SMP PREEMPT Wed Oct 26 12:43:52 EDT 2022