2 * Copyright (c) 2015 Google, Inc
3 * Written by Simon Glass <sjg@chromium.org>
5 * SPDX-License-Identifier: GPL-2.0+
18 struct sandbox_pwm_chan {
25 struct sandbox_pwm_priv {
26 struct sandbox_pwm_chan chan[NUM_CHANNELS];
29 static int sandbox_pwm_set_config(struct udevice *dev, uint channel,
30 uint period_ns, uint duty_ns)
32 struct sandbox_pwm_priv *priv = dev_get_priv(dev);
33 struct sandbox_pwm_chan *chan;
35 if (channel >= NUM_CHANNELS)
37 chan = &priv->chan[channel];
38 chan->period_ns = period_ns;
39 chan->duty_ns = duty_ns;
44 static int sandbox_pwm_set_enable(struct udevice *dev, uint channel,
47 struct sandbox_pwm_priv *priv = dev_get_priv(dev);
48 struct sandbox_pwm_chan *chan;
50 if (channel >= NUM_CHANNELS)
52 chan = &priv->chan[channel];
53 chan->enable = enable;
58 static int sandbox_pwm_set_invert(struct udevice *dev, uint channel,
61 struct sandbox_pwm_priv *priv = dev_get_priv(dev);
62 struct sandbox_pwm_chan *chan;
64 if (channel >= NUM_CHANNELS)
66 chan = &priv->chan[channel];
67 chan->polarity = polarity;
72 static const struct pwm_ops sandbox_pwm_ops = {
73 .set_config = sandbox_pwm_set_config,
74 .set_enable = sandbox_pwm_set_enable,
75 .set_invert = sandbox_pwm_set_invert,
78 static const struct udevice_id sandbox_pwm_ids[] = {
79 { .compatible = "sandbox,pwm" },
83 U_BOOT_DRIVER(warm_pwm_sandbox) = {
84 .name = "pwm_sandbox",
86 .of_match = sandbox_pwm_ids,
87 .ops = &sandbox_pwm_ops,
88 .priv_auto_alloc_size = sizeof(struct sandbox_pwm_priv),