static int check_reserved(struct udevice *dev, unsigned offset, const char *func) { if (!get_gpio_flag(dev, offset, GPIOF_RESERVED)) { printf("sandbox_gpio: %s: error: offset %u not reserved\n", func, offset); return -1; } return 0; }
static int sb_gpio_get_state(struct udevice *dev, unsigned int offset, char *buf, int bufsize) { struct gpio_dev_priv *uc_priv = dev->uclass_priv; struct gpio_state *state = dev_get_priv(dev); const char *label; label = state[offset].label; snprintf(buf, bufsize, "%s%d: %s: %d [%c]%s%s", uc_priv->bank_name ? uc_priv->bank_name : "", offset, sandbox_gpio_get_direction(dev, offset) ? "out" : " in", sandbox_gpio_get_value(dev, offset), get_gpio_flag(dev, offset, GPIOF_RESERVED) ? 'x' : ' ', label ? " " : "", label ? label : ""); return 0; }
static int sb_gpio_request(struct udevice *dev, unsigned offset, const char *label) { struct gpio_dev_priv *uc_priv = dev->uclass_priv; struct gpio_state *state = dev_get_priv(dev); debug("%s: offset:%u, label:%s\n", __func__, offset, label); if (offset >= uc_priv->gpio_count) { printf("sandbox_gpio: error: invalid gpio %u\n", offset); return -1; } if (get_gpio_flag(dev, offset, GPIOF_RESERVED)) { printf("sandbox_gpio: error: gpio %u already reserved\n", offset); return -1; } state[offset].label = label; return set_gpio_flag(dev, offset, GPIOF_RESERVED, 1); }
int sandbox_gpio_get_direction(struct udevice *dev, unsigned offset) { return get_gpio_flag(dev, offset, GPIOF_OUTPUT); }
int sandbox_gpio_get_value(struct udevice *dev, unsigned offset) { if (get_gpio_flag(dev, offset, GPIOF_OUTPUT)) debug("sandbox_gpio: get_value on output gpio %u\n", offset); return get_gpio_flag(dev, offset, GPIOF_HIGH); }
static int sb_gpio_get_function(struct udevice *dev, unsigned offset) { if (get_gpio_flag(dev, offset, GPIOF_OUTPUT)) return GPIOF_OUTPUT; return GPIOF_INPUT; }