]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
pwm: cros-ec: Don't care about consumers in .get_state()
authorUwe Kleine-König <ukleinek@baylibre.com>
Fri, 7 Jun 2024 08:44:15 +0000 (10:44 +0200)
committerUwe Kleine-König <ukleinek@kernel.org>
Wed, 10 Jul 2024 15:52:47 +0000 (17:52 +0200)
The get_state() callback is never called (in a visible way) after there
is a consumer for a pwm device. The core handles loosing the information
about duty_cycle just fine.

Simplify the driver accordingly.

Signed-off-by: Uwe Kleine-König <u.kleine-koenig@baylibre.com>
Reviewed-by: Tzung-Bi Shih <tzungbi@kernel.org>
Link: https://lore.kernel.org/r/20240607084416.897777-6-u.kleine-koenig@baylibre.com
[Drop kdoc comment for channel to make W=1 builds happy]
Signed-off-by: Uwe Kleine-König <ukleinek@kernel.org>
drivers/pwm/pwm-cros-ec.c

index 606ccfdaf4cc28457cd2a07fcabef1d66dd83c44..ea0dd553a626a0ffa520d3e139ec36a45b188985 100644 (file)
  *
  * @ec: Pointer to EC device
  * @use_pwm_type: Use PWM types instead of generic channels
- * @channel: array with per-channel data
  */
 struct cros_ec_pwm_device {
        struct cros_ec_device *ec;
        bool use_pwm_type;
-       struct cros_ec_pwm *channel;
-};
-
-/**
- * struct cros_ec_pwm - per-PWM driver data
- * @duty_cycle: cached duty cycle
- */
-struct cros_ec_pwm {
-       u16 duty_cycle;
 };
 
 static inline struct cros_ec_pwm_device *pwm_to_cros_ec_pwm(struct pwm_chip *chip)
@@ -135,7 +125,6 @@ static int cros_ec_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm,
                             const struct pwm_state *state)
 {
        struct cros_ec_pwm_device *ec_pwm = pwm_to_cros_ec_pwm(chip);
-       struct cros_ec_pwm *channel = &ec_pwm->channel[pwm->hwpwm];
        u16 duty_cycle;
        int ret;
 
@@ -156,8 +145,6 @@ static int cros_ec_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm,
        if (ret < 0)
                return ret;
 
-       channel->duty_cycle = state->duty_cycle;
-
        return 0;
 }
 
@@ -165,7 +152,6 @@ static int cros_ec_pwm_get_state(struct pwm_chip *chip, struct pwm_device *pwm,
                                 struct pwm_state *state)
 {
        struct cros_ec_pwm_device *ec_pwm = pwm_to_cros_ec_pwm(chip);
-       struct cros_ec_pwm *channel = &ec_pwm->channel[pwm->hwpwm];
        int ret;
 
        ret = cros_ec_pwm_get_duty(ec_pwm->ec, ec_pwm->use_pwm_type, pwm->hwpwm);
@@ -175,23 +161,10 @@ static int cros_ec_pwm_get_state(struct pwm_chip *chip, struct pwm_device *pwm,
        }
 
        state->enabled = (ret > 0);
+       state->duty_cycle = ret;
        state->period = EC_PWM_MAX_DUTY;
        state->polarity = PWM_POLARITY_NORMAL;
 
-       /*
-        * Note that "disabled" and "duty cycle == 0" are treated the same. If
-        * the cached duty cycle is not zero, used the cached duty cycle. This
-        * ensures that the configured duty cycle is kept across a disable and
-        * enable operation and avoids potentially confusing consumers.
-        *
-        * For the case of the initial hardware readout, channel->duty_cycle
-        * will be 0 and the actual duty cycle read from the EC is used.
-        */
-       if (ret == 0 && channel->duty_cycle > 0)
-               state->duty_cycle = channel->duty_cycle;
-       else
-               state->duty_cycle = ret;
-
        return 0;
 }
 
@@ -291,11 +264,6 @@ static int cros_ec_pwm_probe(struct platform_device *pdev)
        chip->ops = &cros_ec_pwm_ops;
        chip->of_xlate = cros_ec_pwm_xlate;
 
-       ec_pwm->channel = devm_kcalloc(dev, chip->npwm, sizeof(*ec_pwm->channel),
-                                       GFP_KERNEL);
-       if (!ec_pwm->channel)
-               return -ENOMEM;
-
        dev_dbg(dev, "Probed %u PWMs\n", chip->npwm);
 
        ret = devm_pwmchip_add(dev, chip);