Re: OMAP4/5 Wake-up generator driver

2016-09-15 Thread Mark Kettenis
> Date: Thu, 15 Sep 2016 14:53:14 +1000
> From: Jonathan Gray 
> 
> It turns out on OMAP4/OMAP5 there is a "Wake-up generator"
> interrupt controller that routes interrupts to the GIC and does power
> management comparable to imx with the i.MX6 General Power Controller
> (GPC).
> 
> / {
> #address-cells = <0x0001>;
> #size-cells = <0x0001>;
> compatible = "ti,omap4-panda-es", "ti,omap4-panda", "ti,omap4460", 
> "ti,omap4430", "ti,omap4";
> interrupt-parent = <0x0001>;
> model = "TI OMAP4 PandaBoard-ES";
> ...
> 
> interrupt-controller@48241000 {
> compatible = "arm,cortex-a9-gic";
> interrupt-controller;
> #interrupt-cells = <0x0003>;
> reg = <0x48241000 0x1000 0x48240100 0x0100>;
> interrupt-parent = <0x0004>;
> linux,phandle = <0x0004>;
> phandle = <0x0004>;
> };
> 
> interrupt-controller@48281000 {
> compatible = "ti,omap4-wugen-mpu";
> interrupt-controller;
> #interrupt-cells = <0x0003>;
> reg = <0x48281000 0x1000>;
> interrupt-parent = <0x0004>;
> linux,phandle = <0x0001>;
> phandle = <0x0001>;
> };
> 
> Reusing the imxgpc code to handle this allows interrupts on ommc(4) with
> the pandaboard to work again and the board can now find it's root disk
> once again.

Go for it.

The wakeup issue is cited in the "Linus ARM rant" thread as a flaw of
the GIC, so we can expect this sort of wakeup interrupt controller to
appear om other "platforms" as well.  This is why we implement the
"parent" establish and disestablish functions.

> Index: omap/files.omap
> ===
> RCS file: /cvs/src/sys/arch/armv7/omap/files.omap,v
> retrieving revision 1.17
> diff -u -p -r1.17 files.omap
> --- omap/files.omap   15 Aug 2016 13:42:49 -  1.17
> +++ omap/files.omap   15 Sep 2016 04:33:56 -
> @@ -42,6 +42,10 @@ device intc
>  attach intc at fdt
>  file arch/armv7/omap/intc.c  intc
>  
> +device omwugen
> +attach omwugen at fdt
> +file arch/armv7/omap/omwugen.c   omwugen
> +
>  device gptimer
>  attach gptimer at omap
>  file arch/armv7/omap/gptimer.c   gptimer
> Index: conf/GENERIC
> ===
> RCS file: /cvs/src/sys/arch/armv7/conf/GENERIC,v
> retrieving revision 1.53
> diff -u -p -r1.53 GENERIC
> --- conf/GENERIC  12 Sep 2016 08:28:44 -  1.53
> +++ conf/GENERIC  15 Sep 2016 04:33:56 -
> @@ -63,6 +63,7 @@ omapid* at omap?
>  
>  # OMAP on-chip devices
>  intc*at fdt? # OMAP3 interrupt controller
> +omwugen* at fdt? # Wake-up generator
>  #edma*   at omap?# OMAP3 dma controller
>  prcm*at omap?# power/clock controller
>  sitaracm*at omap?# sitara control module
> Index: conf/RAMDISK
> ===
> RCS file: /cvs/src/sys/arch/armv7/conf/RAMDISK,v
> retrieving revision 1.48
> diff -u -p -r1.48 RAMDISK
> --- conf/RAMDISK  21 Aug 2016 06:36:23 -  1.48
> +++ conf/RAMDISK  15 Sep 2016 04:33:56 -
> @@ -61,6 +61,7 @@ omapid* at omap?
>  
>  # OMAP on-chip devices
>  intc*at fdt? # OMAP3 interrupt controller
> +omwugen* at fdt? # Wake-up generator
>  #edma*   at omap?# OMAP3 dma controller
>  prcm*at omap?# power/clock controller
>  sitaracm*at omap?# sitara control module
> --- /dev/null Thu Sep 15 14:35:46 2016
> +++ omap/omwugen.cThu Sep 15 14:22:00 2016
> @@ -0,0 +1,63 @@
> +/*   $OpenBSD$   */
> +/*
> + * Copyright (c) 2016 Mark Kettenis
> + *
> + * Permission to use, copy, modify, and distribute this software for any
> + * purpose with or without fee is hereby granted, provided that the above
> + * copyright notice and this permission notice appear in all copies.
> + *
> + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
> + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
> + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
> + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
> + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
> + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
> + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
> + */
> +
> +#include 
> +#include 
> +#include 
> +
> +#include 
> +
> +#include 
> +
> +struct omwugen_softc {
> + struct device   sc_dev;
> + struct interrupt_controller sc_ic;
> +};
> +
> +int  omwugen_match(struct device *, void *, void *);
> +void omwugen_attach(struct device *,

OMAP4/5 Wake-up generator driver

2016-09-14 Thread Jonathan Gray
It turns out on OMAP4/OMAP5 there is a "Wake-up generator"
interrupt controller that routes interrupts to the GIC and does power
management comparable to imx with the i.MX6 General Power Controller
(GPC).

/ {
#address-cells = <0x0001>;
#size-cells = <0x0001>;
compatible = "ti,omap4-panda-es", "ti,omap4-panda", "ti,omap4460", 
"ti,omap4430", "ti,omap4";
interrupt-parent = <0x0001>;
model = "TI OMAP4 PandaBoard-ES";
...

interrupt-controller@48241000 {
compatible = "arm,cortex-a9-gic";
interrupt-controller;
#interrupt-cells = <0x0003>;
reg = <0x48241000 0x1000 0x48240100 0x0100>;
interrupt-parent = <0x0004>;
linux,phandle = <0x0004>;
phandle = <0x0004>;
};

interrupt-controller@48281000 {
compatible = "ti,omap4-wugen-mpu";
interrupt-controller;
#interrupt-cells = <0x0003>;
reg = <0x48281000 0x1000>;
interrupt-parent = <0x0004>;
linux,phandle = <0x0001>;
phandle = <0x0001>;
};

Reusing the imxgpc code to handle this allows interrupts on ommc(4) with
the pandaboard to work again and the board can now find it's root disk
once again.

Index: omap/files.omap
===
RCS file: /cvs/src/sys/arch/armv7/omap/files.omap,v
retrieving revision 1.17
diff -u -p -r1.17 files.omap
--- omap/files.omap 15 Aug 2016 13:42:49 -  1.17
+++ omap/files.omap 15 Sep 2016 04:33:56 -
@@ -42,6 +42,10 @@ device intc
 attach intc at fdt
 file   arch/armv7/omap/intc.c  intc
 
+device omwugen
+attach omwugen at fdt
+file   arch/armv7/omap/omwugen.c   omwugen
+
 device gptimer
 attach gptimer at omap
 file   arch/armv7/omap/gptimer.c   gptimer
Index: conf/GENERIC
===
RCS file: /cvs/src/sys/arch/armv7/conf/GENERIC,v
retrieving revision 1.53
diff -u -p -r1.53 GENERIC
--- conf/GENERIC12 Sep 2016 08:28:44 -  1.53
+++ conf/GENERIC15 Sep 2016 04:33:56 -
@@ -63,6 +63,7 @@ omapid*   at omap?
 
 # OMAP on-chip devices
 intc*  at fdt? # OMAP3 interrupt controller
+omwugen*   at fdt? # Wake-up generator
 #edma* at omap?# OMAP3 dma controller
 prcm*  at omap?# power/clock controller
 sitaracm*  at omap?# sitara control module
Index: conf/RAMDISK
===
RCS file: /cvs/src/sys/arch/armv7/conf/RAMDISK,v
retrieving revision 1.48
diff -u -p -r1.48 RAMDISK
--- conf/RAMDISK21 Aug 2016 06:36:23 -  1.48
+++ conf/RAMDISK15 Sep 2016 04:33:56 -
@@ -61,6 +61,7 @@ omapid*   at omap?
 
 # OMAP on-chip devices
 intc*  at fdt? # OMAP3 interrupt controller
+omwugen*   at fdt? # Wake-up generator
 #edma* at omap?# OMAP3 dma controller
 prcm*  at omap?# power/clock controller
 sitaracm*  at omap?# sitara control module
--- /dev/null   Thu Sep 15 14:35:46 2016
+++ omap/omwugen.c  Thu Sep 15 14:22:00 2016
@@ -0,0 +1,63 @@
+/* $OpenBSD$   */
+/*
+ * Copyright (c) 2016 Mark Kettenis
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include 
+#include 
+#include 
+
+#include 
+
+#include 
+
+struct omwugen_softc {
+   struct device   sc_dev;
+   struct interrupt_controller sc_ic;
+};
+
+intomwugen_match(struct device *, void *, void *);
+void   omwugen_attach(struct device *, struct device *, void *);
+
+struct cfattach omwugen_ca = {
+   sizeof(struct omwugen_softc), omwugen_match, omwugen_attach
+};
+
+struct cfdriver omwugen_cd = {
+   NULL, "omwugen", DV_DULL
+};
+
+int
+omwugen_match(struct device *parent, void *match, void *aux)
+{
+   struct fdt_attach_args *faa = aux;
+
+   return OF_is_compatible(faa->fa_node, "ti,omap4-wugen-mpu");
+}
+
+void
+omwugen_attach(struct device *parent, struct device *self, void *aux)
+{
+   struct fdt_attach_args *faa = aux;
+   struct omwugen_softc *sc = (struct omwu