2 * Copyright (c) 2015 Google, Inc
3 * Written by Simon Glass <sjg@chromium.org>
5 * SPDX-License-Identifier: GPL-2.0+
14 DECLARE_GLOBAL_DATA_PTR;
20 struct sandbox_pwm_chan {
26 struct sandbox_pwm_priv {
27 struct sandbox_pwm_chan chan[NUM_CHANNELS];
30 static int sandbox_pwm_set_config(struct udevice *dev, uint channel,
31 uint period_ns, uint duty_ns)
33 struct sandbox_pwm_priv *priv = dev_get_priv(dev);
34 struct sandbox_pwm_chan *chan;
36 if (channel >= NUM_CHANNELS)
38 chan = &priv->chan[channel];
39 chan->period_ns = period_ns;
40 chan->duty_ns = duty_ns;
45 static int sandbox_pwm_set_enable(struct udevice *dev, uint channel,
48 struct sandbox_pwm_priv *priv = dev_get_priv(dev);
49 struct sandbox_pwm_chan *chan;
51 if (channel >= NUM_CHANNELS)
53 chan = &priv->chan[channel];
54 chan->enable = enable;
59 static const struct pwm_ops sandbox_pwm_ops = {
60 .set_config = sandbox_pwm_set_config,
61 .set_enable = sandbox_pwm_set_enable,
64 static const struct udevice_id sandbox_pwm_ids[] = {
65 { .compatible = "sandbox,pwm" },
69 U_BOOT_DRIVER(warm_pwm_sandbox) = {
70 .name = "pwm_sandbox",
72 .of_match = sandbox_pwm_ids,
73 .ops = &sandbox_pwm_ops,
74 .priv_auto_alloc_size = sizeof(struct sandbox_pwm_priv),