]> Git Repo - J-u-boot.git/blobdiff - drivers/pwm/sandbox_pwm.c
Merge branch '2019-05-03-master-imports'
[J-u-boot.git] / drivers / pwm / sandbox_pwm.c
index c2ce974ddea4fb03eecce65db7334babebd72d5d..28988187e039452e51f91dff0f8818bd6778ce4b 100644 (file)
@@ -1,8 +1,7 @@
+// SPDX-License-Identifier: GPL-2.0+
 /*
  * Copyright (c) 2015 Google, Inc
  * Written by Simon Glass <[email protected]>
- *
- * SPDX-License-Identifier:    GPL-2.0+
  */
 
 #include <common.h>
 #include <pwm.h>
 #include <asm/test.h>
 
-DECLARE_GLOBAL_DATA_PTR;
-
 enum {
        NUM_CHANNELS    = 3,
 };
 
+/**
+ * struct sandbox_pwm_chan - a sandbox PWM channel
+ *
+ * @period_ns: Period of the PWM in nanoseconds
+ * @duty_ns: Current duty cycle of the PWM in nanoseconds
+ * @enable: true if the PWM is enabled
+ * @polarity: true if the PWM polarity is active high
+ */
 struct sandbox_pwm_chan {
        uint period_ns;
        uint duty_ns;
        bool enable;
+       bool polarity;
 };
 
 struct sandbox_pwm_priv {
        struct sandbox_pwm_chan chan[NUM_CHANNELS];
 };
 
+int sandbox_pwm_get_config(struct udevice *dev, uint channel, uint *period_nsp,
+                          uint *duty_nsp, bool *enablep, bool *polarityp)
+{
+       struct sandbox_pwm_priv *priv = dev_get_priv(dev);
+       struct sandbox_pwm_chan *chan;
+
+       if (channel >= NUM_CHANNELS)
+               return -ENOSPC;
+       chan = &priv->chan[channel];
+       *period_nsp = chan->period_ns;
+       *duty_nsp = chan->duty_ns;
+       *enablep = chan->enable;
+       *polarityp = chan->polarity;
+
+       return 0;
+}
+
 static int sandbox_pwm_set_config(struct udevice *dev, uint channel,
                                  uint period_ns, uint duty_ns)
 {
@@ -56,9 +79,24 @@ static int sandbox_pwm_set_enable(struct udevice *dev, uint channel,
        return 0;
 }
 
+static int sandbox_pwm_set_invert(struct udevice *dev, uint channel,
+                                 bool polarity)
+{
+       struct sandbox_pwm_priv *priv = dev_get_priv(dev);
+       struct sandbox_pwm_chan *chan;
+
+       if (channel >= NUM_CHANNELS)
+               return -ENOSPC;
+       chan = &priv->chan[channel];
+       chan->polarity = polarity;
+
+       return 0;
+}
+
 static const struct pwm_ops sandbox_pwm_ops = {
        .set_config     = sandbox_pwm_set_config,
        .set_enable     = sandbox_pwm_set_enable,
+       .set_invert     = sandbox_pwm_set_invert,
 };
 
 static const struct udevice_id sandbox_pwm_ids[] = {
This page took 0.026223 seconds and 4 git commands to generate.