]> git.ipfire.org Git - people/ms/u-boot.git/blobdiff - drivers/gpio/sandbox.c
dm: core: Replace of_offset with accessor
[people/ms/u-boot.git] / drivers / gpio / sandbox.c
index d564c252c7d7336d9f5bcc93d9ac306bd42eb539..ae6d93013f7c79a4bc84ab6be9acd5fd052c736e 100644 (file)
@@ -15,6 +15,7 @@ DECLARE_GLOBAL_DATA_PTR;
 /* Flags for each GPIO */
 #define GPIOF_OUTPUT   (1 << 0)        /* Currently set as an output */
 #define GPIOF_HIGH     (1 << 1)        /* Currently set high */
+#define GPIOF_ODR      (1 << 2)        /* Currently set to open drain mode */
 
 struct gpio_state {
        const char *label;      /* label given by requester */
@@ -24,7 +25,7 @@ struct gpio_state {
 /* Access routines for GPIO state */
 static u8 *get_gpio_flags(struct udevice *dev, unsigned offset)
 {
-       struct gpio_dev_priv *uc_priv = dev->uclass_priv;
+       struct gpio_dev_priv *uc_priv = dev_get_uclass_priv(dev);
        struct gpio_state *state = dev_get_priv(dev);
 
        if (offset >= uc_priv->gpio_count) {
@@ -70,6 +71,16 @@ int sandbox_gpio_set_value(struct udevice *dev, unsigned offset, int value)
        return set_gpio_flag(dev, offset, GPIOF_HIGH, value);
 }
 
+int sandbox_gpio_get_open_drain(struct udevice *dev, unsigned offset)
+{
+       return get_gpio_flag(dev, offset, GPIOF_ODR);
+}
+
+int sandbox_gpio_set_open_drain(struct udevice *dev, unsigned offset, int value)
+{
+       return set_gpio_flag(dev, offset, GPIOF_ODR, value);
+}
+
 int sandbox_gpio_get_direction(struct udevice *dev, unsigned offset)
 {
        return get_gpio_flag(dev, offset, GPIOF_OUTPUT);
@@ -124,6 +135,28 @@ static int sb_gpio_set_value(struct udevice *dev, unsigned offset, int value)
        return sandbox_gpio_set_value(dev, offset, value);
 }
 
+/* read GPIO ODR value of port 'offset' */
+static int sb_gpio_get_open_drain(struct udevice *dev, unsigned offset)
+{
+       debug("%s: offset:%u\n", __func__, offset);
+
+       return sandbox_gpio_get_open_drain(dev, offset);
+}
+
+/* write GPIO ODR value to port 'offset' */
+static int sb_gpio_set_open_drain(struct udevice *dev, unsigned offset, int value)
+{
+       debug("%s: offset:%u, value = %d\n", __func__, offset, value);
+
+       if (!sandbox_gpio_get_direction(dev, offset)) {
+               printf("sandbox_gpio: error: set_open_drain on input gpio %u\n",
+                      offset);
+               return -1;
+       }
+
+       return sandbox_gpio_set_open_drain(dev, offset, value);
+}
+
 static int sb_gpio_get_function(struct udevice *dev, unsigned offset)
 {
        if (get_gpio_flag(dev, offset, GPIOF_OUTPUT))
@@ -154,17 +187,19 @@ static const struct dm_gpio_ops gpio_sandbox_ops = {
        .direction_output       = sb_gpio_direction_output,
        .get_value              = sb_gpio_get_value,
        .set_value              = sb_gpio_set_value,
+       .get_open_drain         = sb_gpio_get_open_drain,
+       .set_open_drain         = sb_gpio_set_open_drain,
        .get_function           = sb_gpio_get_function,
        .xlate                  = sb_gpio_xlate,
 };
 
 static int sandbox_gpio_ofdata_to_platdata(struct udevice *dev)
 {
-       struct gpio_dev_priv *uc_priv = dev->uclass_priv;
+       struct gpio_dev_priv *uc_priv = dev_get_uclass_priv(dev);
 
-       uc_priv->gpio_count = fdtdec_get_int(gd->fdt_blob, dev->of_offset,
+       uc_priv->gpio_count = fdtdec_get_int(gd->fdt_blob, dev_of_offset(dev),
                                             "num-gpios", 0);
-       uc_priv->bank_name = fdt_getprop(gd->fdt_blob, dev->of_offset,
+       uc_priv->bank_name = fdt_getprop(gd->fdt_blob, dev_of_offset(dev),
                                         "gpio-bank-name", NULL);
 
        return 0;
@@ -172,9 +207,9 @@ static int sandbox_gpio_ofdata_to_platdata(struct udevice *dev)
 
 static int gpio_sandbox_probe(struct udevice *dev)
 {
-       struct gpio_dev_priv *uc_priv = dev->uclass_priv;
+       struct gpio_dev_priv *uc_priv = dev_get_uclass_priv(dev);
 
-       if (dev->of_offset == -1) {
+       if (dev_of_offset(dev) == -1) {
                /* Tell the uclass how many GPIOs we have */
                uc_priv->gpio_count = CONFIG_SANDBOX_GPIO_COUNT;
        }