Module Name:    src
Committed By:   thorpej
Date:           Sat Jan 26 14:38:30 UTC 2019

Modified Files:
        src/sys/arch/arm/broadcom: bcm2835_gpio.c
        src/sys/arch/arm/nvidia: tegra_lic.c
        src/sys/arch/arm/sunxi: sunxi_gpio.c
        src/sys/dev/fdt: fdtvar.h

Log Message:
Define constants for representing the standard interrupt types
({pos,neg,double}-edge, {high,low}-level) from the FDT "interrupts"
bindings.  Use these defined constants rather than magic numbers.


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/sys/arch/arm/broadcom/bcm2835_gpio.c
cvs rdiff -u -r1.5 -r1.6 src/sys/arch/arm/nvidia/tegra_lic.c
cvs rdiff -u -r1.22 -r1.23 src/sys/arch/arm/sunxi/sunxi_gpio.c
cvs rdiff -u -r1.46 -r1.47 src/sys/dev/fdt/fdtvar.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/arm/broadcom/bcm2835_gpio.c
diff -u src/sys/arch/arm/broadcom/bcm2835_gpio.c:1.8 src/sys/arch/arm/broadcom/bcm2835_gpio.c:1.9
--- src/sys/arch/arm/broadcom/bcm2835_gpio.c:1.8	Fri Sep 28 13:24:02 2018
+++ src/sys/arch/arm/broadcom/bcm2835_gpio.c	Sat Jan 26 14:38:29 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: bcm2835_gpio.c,v 1.8 2018/09/28 13:24:02 jmcneill Exp $	*/
+/*	$NetBSD: bcm2835_gpio.c,v 1.9 2019/01/26 14:38:29 thorpej Exp $	*/
 
 /*-
  * Copyright (c) 2013, 2014, 2017 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: bcm2835_gpio.c,v 1.8 2018/09/28 13:24:02 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: bcm2835_gpio.c,v 1.9 2019/01/26 14:38:29 thorpej Exp $");
 
 /*
  * Driver for BCM2835 GPIO
@@ -567,19 +567,19 @@ bcmgpio_fdt_intr_establish(device_t dev,
 	const u_int type = be32toh(specifier[1]) & 0xf;
 
 	switch (type) {
-	case 0x1:
+	case FDT_INTR_TYPE_POS_EDGE:
 		eint_flags |= BCMGPIO_INTR_POS_EDGE;
 		break;
-	case 0x2:
+	case FDT_INTR_TYPE_NEG_EDGE:
 		eint_flags |= BCMGPIO_INTR_NEG_EDGE;
 		break;
-	case 0x3:
+	case FDT_INTR_TYPE_DOUBLE_EDGE:
 		eint_flags |= BCMGPIO_INTR_POS_EDGE | BCMGPIO_INTR_NEG_EDGE;
 		break;
-	case 0x4:
+	case FDT_INTR_TYPE_HIGH_LEVEL:
 		eint_flags |= BCMGPIO_INTR_HIGH_LEVEL;
 		break;
-	case 0x8:
+	case FDT_INTR_TYPE_LOW_LEVEL:
 		eint_flags |= BCMGPIO_INTR_LOW_LEVEL;
 		break;
 	default:

Index: src/sys/arch/arm/nvidia/tegra_lic.c
diff -u src/sys/arch/arm/nvidia/tegra_lic.c:1.5 src/sys/arch/arm/nvidia/tegra_lic.c:1.6
--- src/sys/arch/arm/nvidia/tegra_lic.c:1.5	Fri May 26 20:08:02 2017
+++ src/sys/arch/arm/nvidia/tegra_lic.c	Sat Jan 26 14:38:29 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: tegra_lic.c,v 1.5 2017/05/26 20:08:02 jmcneill Exp $ */
+/* $NetBSD: tegra_lic.c,v 1.6 2019/01/26 14:38:29 thorpej Exp $ */
 
 /*-
  * Copyright (c) 2015 Jared D. McNeill <jmcne...@invisible.ca>
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: tegra_lic.c,v 1.5 2017/05/26 20:08:02 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tegra_lic.c,v 1.6 2019/01/26 14:38:29 thorpej Exp $");
 
 #include <sys/param.h>
 #include <sys/bus.h>
@@ -142,7 +142,8 @@ tegra_lic_establish(device_t dev, u_int 
 	const u_int intr = be32toh(specifier[1]);
 	const u_int irq = type == 0 ? IRQ_SPI(intr) : IRQ_PPI(intr);
 	const u_int trig = be32toh(specifier[2]) & 0xf;
-	const u_int level = (trig & 0x3) ? IST_EDGE : IST_LEVEL;
+	const u_int level = (trig & FDT_INTR_TYPE_DOUBLE_EDGE)
+	    ? IST_EDGE : IST_LEVEL;
 
 	return intr_establish(irq, ipl, level | iflags, func, arg);
 }

Index: src/sys/arch/arm/sunxi/sunxi_gpio.c
diff -u src/sys/arch/arm/sunxi/sunxi_gpio.c:1.22 src/sys/arch/arm/sunxi/sunxi_gpio.c:1.23
--- src/sys/arch/arm/sunxi/sunxi_gpio.c:1.22	Wed Jan 23 04:21:54 2019
+++ src/sys/arch/arm/sunxi/sunxi_gpio.c	Sat Jan 26 14:38:30 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: sunxi_gpio.c,v 1.22 2019/01/23 04:21:54 thorpej Exp $ */
+/* $NetBSD: sunxi_gpio.c,v 1.23 2019/01/26 14:38:30 thorpej Exp $ */
 
 /*-
  * Copyright (c) 2017 Jared McNeill <jmcne...@invisible.ca>
@@ -29,7 +29,7 @@
 #include "opt_soc.h"
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: sunxi_gpio.c,v 1.22 2019/01/23 04:21:54 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sunxi_gpio.c,v 1.23 2019/01/26 14:38:30 thorpej Exp $");
 
 #include <sys/param.h>
 #include <sys/bus.h>
@@ -458,19 +458,19 @@ sunxi_gpio_establish(device_t dev, u_int
 	const u_int type = be32toh(specifier[2]) & 0xf;
 
 	switch (type) {
-	case 0x1:
+	case FDT_INTR_TYPE_POS_EDGE:
 		mode = SUNXI_GPIO_INT_MODE_POS_EDGE;
 		break;
-	case 0x2:
+	case FDT_INTR_TYPE_NEG_EDGE:
 		mode = SUNXI_GPIO_INT_MODE_NEG_EDGE;
 		break;
-	case 0x3:
+	case FDT_INTR_TYPE_DOUBLE_EDGE:
 		mode = SUNXI_GPIO_INT_MODE_DOUBLE_EDGE;
 		break;
-	case 0x4:
+	case FDT_INTR_TYPE_HIGH_LEVEL:
 		mode = SUNXI_GPIO_INT_MODE_HIGH_LEVEL;
 		break;
-	case 0x8:
+	case FDT_INTR_TYPE_LOW_LEVEL:
 		mode = SUNXI_GPIO_INT_MODE_LOW_LEVEL;
 		break;
 	default:

Index: src/sys/dev/fdt/fdtvar.h
diff -u src/sys/dev/fdt/fdtvar.h:1.46 src/sys/dev/fdt/fdtvar.h:1.47
--- src/sys/dev/fdt/fdtvar.h:1.46	Wed Jan 23 04:21:55 2019
+++ src/sys/dev/fdt/fdtvar.h	Sat Jan 26 14:38:30 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: fdtvar.h,v 1.46 2019/01/23 04:21:55 thorpej Exp $ */
+/* $NetBSD: fdtvar.h,v 1.47 2019/01/26 14:38:30 thorpej Exp $ */
 
 /*-
  * Copyright (c) 2015 Jared D. McNeill <jmcne...@invisible.ca>
@@ -63,6 +63,14 @@ struct fdt_attach_args {
 /* flags for fdtbus_intr_establish */
 #define FDT_INTR_MPSAFE	__BIT(0)
 
+/* Interrupt trigger types defined by the FDT "interrupts" bindings. */
+#define	FDT_INTR_TYPE_POS_EDGE		__BIT(0)
+#define	FDT_INTR_TYPE_NEG_EDGE		__BIT(1)
+#define	FDT_INTR_TYPE_DOUBLE_EDGE	(FDT_INTR_TYPE_POS_EDGE | \
+					 FDT_INTR_TYPE_NEG_EDGE)
+#define	FDT_INTR_TYPE_HIGH_LEVEL	__BIT(2)
+#define	FDT_INTR_TYPE_LOW_LEVEL		__BIT(3)
+
 struct fdtbus_interrupt_controller_func {
 	void *	(*establish)(device_t, u_int *, int, int,
 			     int (*)(void *), void *);

Reply via email to