mirror of
https://github.com/AsahiLinux/u-boot
synced 2024-12-05 02:51:00 +00:00
ca2f948a4b
With commit41575d8e4c
("dm: treewide: Rename auto_alloc_size members to be shorter") "priv_auto_alloc_size" was renamed to "priv_auto". This driver was sent to the mailing list before that change, merged after it, and still has the old form. Apply the rename here as well. Fixes:1b9ee2882e
("pwm: Add a driver for Chrome OS EC PWM") Signed-off-by: Alper Nebi Yasak <alpernebiyasak@gmail.com> Reviewed-by: Simon Glass <sjg@chromium.org>
84 lines
1.8 KiB
C
84 lines
1.8 KiB
C
// SPDX-License-Identifier: GPL-2.0+
|
|
|
|
#include <common.h>
|
|
#include <cros_ec.h>
|
|
#include <dm.h>
|
|
#include <errno.h>
|
|
#include <log.h>
|
|
#include <pwm.h>
|
|
|
|
struct cros_ec_pwm_priv {
|
|
bool enabled;
|
|
uint duty;
|
|
};
|
|
|
|
static int cros_ec_pwm_set_config(struct udevice *dev, uint channel,
|
|
uint period_ns, uint duty_ns)
|
|
{
|
|
struct cros_ec_pwm_priv *priv = dev_get_priv(dev);
|
|
uint duty;
|
|
int ret;
|
|
|
|
debug("%s: period_ns=%u, duty_ns=%u asked\n", __func__,
|
|
period_ns, duty_ns);
|
|
|
|
/* No way to set the period, only a relative duty cycle */
|
|
duty = EC_PWM_MAX_DUTY * duty_ns / period_ns;
|
|
if (duty > EC_PWM_MAX_DUTY)
|
|
duty = EC_PWM_MAX_DUTY;
|
|
|
|
if (!priv->enabled) {
|
|
priv->duty = duty;
|
|
debug("%s: duty=%#x to-be-set\n", __func__, duty);
|
|
return 0;
|
|
}
|
|
|
|
ret = cros_ec_set_pwm_duty(dev->parent, channel, duty);
|
|
if (ret) {
|
|
debug("%s: duty=%#x failed\n", __func__, duty);
|
|
return ret;
|
|
}
|
|
|
|
priv->duty = duty;
|
|
debug("%s: duty=%#x set\n", __func__, duty);
|
|
|
|
return 0;
|
|
}
|
|
|
|
static int cros_ec_pwm_set_enable(struct udevice *dev, uint channel,
|
|
bool enable)
|
|
{
|
|
struct cros_ec_pwm_priv *priv = dev_get_priv(dev);
|
|
int ret;
|
|
|
|
ret = cros_ec_set_pwm_duty(dev->parent, channel,
|
|
enable ? priv->duty : 0);
|
|
if (ret) {
|
|
debug("%s: enable=%d failed\n", __func__, enable);
|
|
return ret;
|
|
}
|
|
|
|
priv->enabled = enable;
|
|
debug("%s: enable=%d (duty=%#x) set\n", __func__,
|
|
enable, priv->duty);
|
|
|
|
return 0;
|
|
}
|
|
|
|
static const struct pwm_ops cros_ec_pwm_ops = {
|
|
.set_config = cros_ec_pwm_set_config,
|
|
.set_enable = cros_ec_pwm_set_enable,
|
|
};
|
|
|
|
static const struct udevice_id cros_ec_pwm_ids[] = {
|
|
{ .compatible = "google,cros-ec-pwm" },
|
|
{ }
|
|
};
|
|
|
|
U_BOOT_DRIVER(cros_ec_pwm) = {
|
|
.name = "cros_ec_pwm",
|
|
.id = UCLASS_PWM,
|
|
.of_match = cros_ec_pwm_ids,
|
|
.ops = &cros_ec_pwm_ops,
|
|
.priv_auto = sizeof(struct cros_ec_pwm_priv),
|
|
};
|