Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/arch/arm/sociox make sni_gpio.c fdt/ACPI dual attach device



details:   https://anonhg.NetBSD.org/src/rev/19a17d9bc0eb
branches:  trunk
changeset: 746015:19a17d9bc0eb
user:      nisimura <nisimura%NetBSD.org@localhost>
date:      Thu Mar 19 20:53:53 2020 +0000

description:
make sni_gpio.c fdt/ACPI dual attach device

diffstat:

 sys/arch/arm/sociox/files.sociox |   12 ++--
 sys/arch/arm/sociox/sni_gpio.c   |  101 +++++++++++++++++++++++++++++++++-----
 2 files changed, 93 insertions(+), 20 deletions(-)

diffs (209 lines):

diff -r 052875d52edf -r 19a17d9bc0eb sys/arch/arm/sociox/files.sociox
--- a/sys/arch/arm/sociox/files.sociox  Thu Mar 19 20:23:19 2020 +0000
+++ b/sys/arch/arm/sociox/files.sociox  Thu Mar 19 20:53:53 2020 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: files.sociox,v 1.7 2020/03/18 08:49:51 nisimura Exp $
+#      $NetBSD: files.sociox,v 1.8 2020/03/19 20:53:53 nisimura Exp $
 #
 # Configuration info for Socionext Unifier/SC2A11
 #
@@ -6,31 +6,31 @@
 
 # SC2A11 SynQuacer NetSec GbE
 device scx: ether, ifnet, arp, mii, bus_dma_generic
+attach scx at acpinodebus with scx_acpi
 attach scx at fdt with scx_fdt
-attach scx at acpinodebus with scx_acpi
 file   arch/arm/sociox/if_scx.c                scx
 
 # Unifier AVE GbE
 device ave: ether, ifnet, arp, mii, bus_dma_generic
 attach ave at fdt with ave_fdt
-attach ave at acpinodebus with ave_acpi
 file   arch/arm/sociox/if_ave.c                ave
 
 # Socionext eMMC
 device sniemmc: sdmmcbus
+attach sniemmc at acpinodebus with sniemmc_acpi
 attach sniemmc at fdt with sniemmc_fdt
-attach sniemmc at acpinodebus with sniemmc_acpi
 file   arch/arm/sociox/sni_emmc.c              sniemmc
 
 # Socionext I2C
 device sniiic: i2cbus
+attach sniiic at acpinodebus with sniiic_acpi
 attach sniiic at fdt with sniiic_fdt
-attach sniiic at acpinodebus with sniiic_acpi
 file   arch/arm/sociox/sni_i2c.c               sniiic  needs-flag
 
 # Socionext GPIO
 device snigpio: gpiobus
-attach snigpio at fdt
+attach snigpio at acpinodebus with snigpio_acpi
+attach snigpio at fdt with snigpio_fdt
 file   arch/arm/sociox/sni_gpio.c              snigpio
 
 # Socionext EXIU external interrupt controller unit
diff -r 052875d52edf -r 19a17d9bc0eb sys/arch/arm/sociox/sni_gpio.c
--- a/sys/arch/arm/sociox/sni_gpio.c    Thu Mar 19 20:23:19 2020 +0000
+++ b/sys/arch/arm/sociox/sni_gpio.c    Thu Mar 19 20:53:53 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: sni_gpio.c,v 1.1 2020/03/18 08:51:08 nisimura Exp $    */
+/*     $NetBSD: sni_gpio.c,v 1.2 2020/03/19 20:53:53 nisimura Exp $    */
 
 /*-
  * Copyright (c) 2020 The NetBSD Foundation, Inc.
@@ -34,7 +34,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: sni_gpio.c,v 1.1 2020/03/18 08:51:08 nisimura Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sni_gpio.c,v 1.2 2020/03/19 20:53:53 nisimura Exp $");
 
 #include <sys/param.h>
 #include <sys/device.h>
@@ -49,9 +49,14 @@
 
 #include <dev/gpio/gpiovar.h>
 #include <dev/fdt/fdtvar.h>
+#include <dev/acpi/acpireg.h>
+#include <dev/acpi/acpivar.h>
+#include <dev/acpi/acpi_intr.h>
 
-static int snigpio_match(device_t, struct cfdata *, void *);
-static void snigpio_attach(device_t, device_t, void *);
+static int snigpio_fdt_match(device_t, struct cfdata *, void *);
+static void snigpio_fdt_attach(device_t, device_t, void *);
+static int snigpio_acpi_match(device_t, struct cfdata *, void *);
+static void snigpio_acpi_attach(device_t, device_t, void *);
 
 struct snigpio_softc {
        device_t                sc_dev;
@@ -66,11 +71,16 @@
        int                     sc_phandle;
 };
 
-CFATTACH_DECL_NEW(snigpio, sizeof(struct snigpio_softc),
-    snigpio_match, snigpio_attach, NULL, NULL);
+CFATTACH_DECL_NEW(snigpio_fdt, sizeof(struct snigpio_softc),
+    snigpio_fdt_match, snigpio_fdt_attach, NULL, NULL);
+
+CFATTACH_DECL_NEW(snigpio_acpi, sizeof(struct snigpio_softc),
+    snigpio_acpi_match, snigpio_acpi_attach, NULL, NULL);
+
+static void snigpio_attach_i(struct snigpio_softc *);
 
 static int
-snigpio_match(device_t parent, struct cfdata *match, void *aux)
+snigpio_fdt_match(device_t parent, struct cfdata *match, void *aux)
 {
        static const char * compatible[] = {
                "socionext,synquacer-gpio",
@@ -83,13 +93,12 @@
 }
 
 static void
-snigpio_attach(device_t parent, device_t self, void *aux)
+snigpio_fdt_attach(device_t parent, device_t self, void *aux)
 {
        struct snigpio_softc * const sc = device_private(self);
        struct fdt_attach_args * const faa = aux;
        prop_dictionary_t dict = device_properties(self);
        const int phandle = faa->faa_phandle;
-       struct gpiobus_attach_args gba;
        bus_space_handle_t ioh;
        bus_addr_t addr;
        bus_size_t size;
@@ -113,15 +122,80 @@
                return;
        }
 
-       aprint_naive(": GPIO controller\n");
-       aprint_normal(": GPIO controller\n");
-
        sc->sc_dev = self;
        sc->sc_phandle = phandle;
        sc->sc_iot = faa->faa_bst;
        sc->sc_ioh = ioh;
        sc->sc_iob = addr;
        sc->sc_ios = size;
+
+       snigpio_attach_i(sc);
+
+       return;
+}
+
+static int
+snigpio_acpi_match(device_t parent, struct cfdata *match, void *aux)
+{
+       static const char * compatible[] = {
+               "SCX0007",
+               NULL
+       };
+       struct acpi_attach_args *aa = aux;
+
+       if (aa->aa_node->ad_type != ACPI_TYPE_DEVICE)
+               return 0;
+       return acpi_match_hid(aa->aa_node->ad_devinfo, compatible);
+}
+
+static void
+snigpio_acpi_attach(device_t parent, device_t self, void *aux)
+{
+       struct snigpio_softc * const sc = device_private(self);
+       struct acpi_attach_args *aa = aux;
+       bus_space_handle_t ioh;
+       struct acpi_resources res;
+       struct acpi_mem *mem;
+       struct acpi_irq *irq;
+       ACPI_STATUS rv;
+
+       rv = acpi_resource_parse(self, aa->aa_node->ad_handle, "_CRS",
+           &res, &acpi_resource_parse_ops_default);
+       if (ACPI_FAILURE(rv))
+               return;
+
+       mem = acpi_res_mem(&res, 0);
+       irq = acpi_res_irq(&res, 0);
+       if (mem == NULL || irq == NULL) {
+               aprint_error(": incomplete resources\n");
+               return;
+       }
+       if (mem->ar_length == 0) {
+               aprint_error(": zero length memory resource\n");
+               return;
+       }
+       if (bus_space_map(aa->aa_memt, mem->ar_base, mem->ar_length, 0,
+           &ioh)) {
+               aprint_error(": couldn't map registers\n");
+               return;
+       }
+
+       sc->sc_dev = self;
+       sc->sc_iot = aa->aa_memt;
+       sc->sc_ioh = ioh;
+       sc->sc_ios = mem->ar_length;
+
+       snigpio_attach_i(sc);
+}
+
+static void
+snigpio_attach_i(struct snigpio_softc *sc)
+{
+       struct gpiobus_attach_args gba;
+
+       aprint_naive(": GPIO controller\n");
+       aprint_normal(": GPIO controller\n");
+
        mutex_init(&sc->sc_lock, MUTEX_DEFAULT, IPL_VM);
        sc->sc_maxpins = 32;
 
@@ -137,7 +211,6 @@
        gba.gba_gc = &sc->sc_gpio_gc;
        gba.gba_pins = &sc->sc_gpio_pins[0];
        gba.gba_npins = sc->sc_maxpins;
-       (void) config_found_ia(self, "gpiobus", &gba, gpiobus_print);
 
-       return;
+       (void) config_found_ia(sc->sc_dev, "gpiobus", &gba, gpiobus_print);
 }



Home | Main Index | Thread Index | Old Index