1 // SPDX-License-Identifier: GPL-2.0+
10 struct cros_ec_pwm_priv {
15 static int cros_ec_pwm_set_config(struct udevice *dev, uint channel,
16 uint period_ns, uint duty_ns)
18 struct cros_ec_pwm_priv *priv = dev_get_priv(dev);
22 debug("%s: period_ns=%u, duty_ns=%u asked\n", __func__,
25 /* No way to set the period, only a relative duty cycle */
26 duty = EC_PWM_MAX_DUTY * duty_ns / period_ns;
27 if (duty > EC_PWM_MAX_DUTY)
28 duty = EC_PWM_MAX_DUTY;
32 debug("%s: duty=%#x to-be-set\n", __func__, duty);
36 ret = cros_ec_set_pwm_duty(dev->parent, channel, duty);
38 debug("%s: duty=%#x failed\n", __func__, duty);
43 debug("%s: duty=%#x set\n", __func__, duty);
48 static int cros_ec_pwm_set_enable(struct udevice *dev, uint channel,
51 struct cros_ec_pwm_priv *priv = dev_get_priv(dev);
54 ret = cros_ec_set_pwm_duty(dev->parent, channel,
55 enable ? priv->duty : 0);
57 debug("%s: enable=%d failed\n", __func__, enable);
61 priv->enabled = enable;
62 debug("%s: enable=%d (duty=%#x) set\n", __func__,
68 static const struct pwm_ops cros_ec_pwm_ops = {
69 .set_config = cros_ec_pwm_set_config,
70 .set_enable = cros_ec_pwm_set_enable,
73 static const struct udevice_id cros_ec_pwm_ids[] = {
74 { .compatible = "google,cros-ec-pwm" },
78 U_BOOT_DRIVER(cros_ec_pwm) = {
79 .name = "cros_ec_pwm",
81 .of_match = cros_ec_pwm_ids,
82 .ops = &cros_ec_pwm_ops,
83 .priv_auto = sizeof(struct cros_ec_pwm_priv),