1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (c) 2015 Google, Inc
4 * Written by Simon Glass <sjg@chromium.org>
17 struct sandbox_pwm_chan {
24 struct sandbox_pwm_priv {
25 struct sandbox_pwm_chan chan[NUM_CHANNELS];
28 static int sandbox_pwm_set_config(struct udevice *dev, uint channel,
29 uint period_ns, uint duty_ns)
31 struct sandbox_pwm_priv *priv = dev_get_priv(dev);
32 struct sandbox_pwm_chan *chan;
34 if (channel >= NUM_CHANNELS)
36 chan = &priv->chan[channel];
37 chan->period_ns = period_ns;
38 chan->duty_ns = duty_ns;
43 static int sandbox_pwm_set_enable(struct udevice *dev, uint channel,
46 struct sandbox_pwm_priv *priv = dev_get_priv(dev);
47 struct sandbox_pwm_chan *chan;
49 if (channel >= NUM_CHANNELS)
51 chan = &priv->chan[channel];
52 chan->enable = enable;
57 static int sandbox_pwm_set_invert(struct udevice *dev, uint channel,
60 struct sandbox_pwm_priv *priv = dev_get_priv(dev);
61 struct sandbox_pwm_chan *chan;
63 if (channel >= NUM_CHANNELS)
65 chan = &priv->chan[channel];
66 chan->polarity = polarity;
71 static const struct pwm_ops sandbox_pwm_ops = {
72 .set_config = sandbox_pwm_set_config,
73 .set_enable = sandbox_pwm_set_enable,
74 .set_invert = sandbox_pwm_set_invert,
77 static const struct udevice_id sandbox_pwm_ids[] = {
78 { .compatible = "sandbox,pwm" },
82 U_BOOT_DRIVER(warm_pwm_sandbox) = {
83 .name = "pwm_sandbox",
85 .of_match = sandbox_pwm_ids,
86 .ops = &sandbox_pwm_ops,
87 .priv_auto_alloc_size = sizeof(struct sandbox_pwm_priv),