-/* $OpenBSD: gpio.c,v 1.16 2022/04/06 18:59:28 naddy Exp $ */
+/* $OpenBSD: gpio.c,v 1.17 2022/04/11 14:30:05 visa Exp $ */
/*
* Copyright (c) 2008 Marc Balmer <mbalmer@openbsd.org>
int gpio_search(struct device *, void *, void *);
int gpio_print(void *, const char *);
int gpio_pinbyname(struct gpio_softc *, char *gp_name);
+int gpio_ioctl(struct gpio_softc *, u_long, caddr_t, int);
const struct cfattach gpio_ca = {
sizeof (struct gpio_softc),
gpioopen(dev_t dev, int flag, int mode, struct proc *p)
{
struct gpio_softc *sc;
+ int error = 0;
sc = (struct gpio_softc *)device_lookup(&gpio_cd, minor(dev));
if (sc == NULL)
return (ENXIO);
if (sc->sc_opened)
- return (EBUSY);
- sc->sc_opened = 1;
+ error = EBUSY;
+ else
+ sc->sc_opened = 1;
- return (0);
+ device_unref(&sc->sc_dev);
+
+ return (error);
}
int
sc->sc_opened = 0;
+ device_unref(&sc->sc_dev);
+
return (0);
}
}
int
-gpioioctl(dev_t dev, u_long cmd, caddr_t data, int flag, struct proc *p)
+gpio_ioctl(struct gpio_softc *sc, u_long cmd, caddr_t data, int flag)
{
- struct gpio_softc *sc;
gpio_chipset_tag_t gc;
struct gpio_info *info;
struct gpio_pin_op *op;
struct device *dv;
int pin, value, flags, npins, found;
- sc = (struct gpio_softc *)device_lookup(&gpio_cd, minor(dev));
- if (sc == NULL)
- return (ENXIO);
-
gc = sc->sc_gc;
switch (cmd) {
return (0);
}
+
+int
+gpioioctl(dev_t dev, u_long cmd, caddr_t data, int flag, struct proc *p)
+{
+ struct gpio_softc *sc;
+ int error;
+
+ sc = (struct gpio_softc *)device_lookup(&gpio_cd, minor(dev));
+ if (sc == NULL)
+ return (ENXIO);
+
+ error = gpio_ioctl(sc, cmd, data, flag);
+
+ device_unref(&sc->sc_dev);
+
+ return (error);
+}