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
{
27 struct sandbox_pwm_priv
{
28 struct sandbox_pwm_chan chan
[NUM_CHANNELS
];
31 static int sandbox_pwm_set_config(struct udevice
*dev
, uint channel
,
32 uint period_ns
, uint duty_ns
)
34 struct sandbox_pwm_priv
*priv
= dev_get_priv(dev
);
35 struct sandbox_pwm_chan
*chan
;
37 if (channel
>= NUM_CHANNELS
)
39 chan
= &priv
->chan
[channel
];
40 chan
->period_ns
= period_ns
;
41 chan
->duty_ns
= duty_ns
;
46 static int sandbox_pwm_set_enable(struct udevice
*dev
, uint channel
,
49 struct sandbox_pwm_priv
*priv
= dev_get_priv(dev
);
50 struct sandbox_pwm_chan
*chan
;
52 if (channel
>= NUM_CHANNELS
)
54 chan
= &priv
->chan
[channel
];
55 chan
->enable
= enable
;
60 static int sandbox_pwm_set_invert(struct udevice
*dev
, uint channel
,
63 struct sandbox_pwm_priv
*priv
= dev_get_priv(dev
);
64 struct sandbox_pwm_chan
*chan
;
66 if (channel
>= NUM_CHANNELS
)
68 chan
= &priv
->chan
[channel
];
69 chan
->polarity
= polarity
;
74 static const struct pwm_ops sandbox_pwm_ops
= {
75 .set_config
= sandbox_pwm_set_config
,
76 .set_enable
= sandbox_pwm_set_enable
,
77 .set_invert
= sandbox_pwm_set_invert
,
80 static const struct udevice_id sandbox_pwm_ids
[] = {
81 { .compatible
= "sandbox,pwm" },
85 U_BOOT_DRIVER(warm_pwm_sandbox
) = {
86 .name
= "pwm_sandbox",
88 .of_match
= sandbox_pwm_ids
,
89 .ops
= &sandbox_pwm_ops
,
90 .priv_auto_alloc_size
= sizeof(struct sandbox_pwm_priv
),