Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 17 Dec 2020 17:11:14 +0000 (UTC)
From:      Emmanuel Vadot <manu@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r368725 - head/sys/dev/spibus
Message-ID:  <202012171711.0BHHBEeZ076088@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: manu
Date: Thu Dec 17 17:11:14 2020
New Revision: 368725
URL: https://svnweb.freebsd.org/changeset/base/368725

Log:
  Add IRQ resource to SPIBUS
  
  Add capability to SPIBUS to have child device with IRQ.
  For example many ADC chip have a dedicated pin to signal "data ready"
  and the host can just wait for a interrupt to go out and read the result.
  
  It is the same code as in R282674 and R282702 for IICBUS by Michal Meloun
  
  Submitted by:	Oskar Holmund <oskar.holmlund@ohdata.se>
  Differential Revision:	https://reviews.freebsd.org/D27396

Modified:
  head/sys/dev/spibus/ofw_spibus.c
  head/sys/dev/spibus/spibus.c
  head/sys/dev/spibus/spibusvar.h

Modified: head/sys/dev/spibus/ofw_spibus.c
==============================================================================
--- head/sys/dev/spibus/ofw_spibus.c	Thu Dec 17 17:09:43 2020	(r368724)
+++ head/sys/dev/spibus/ofw_spibus.c	Thu Dec 17 17:11:14 2020	(r368725)
@@ -152,6 +152,10 @@ ofw_spibus_attach(device_t dev)
 			continue;
 		}
 		childdev = device_add_child(dev, NULL, -1);
+
+		resource_list_init(&dinfo->opd_dinfo.rl);
+		ofw_bus_intr_to_rl(childdev, child,
+		    &dinfo->opd_dinfo.rl, NULL);
 		device_set_ivars(childdev, dinfo);
 	}
 
@@ -198,6 +202,15 @@ ofw_spibus_get_devinfo(device_t bus, device_t dev)
 	return (&dinfo->opd_obdinfo);
 }
 
+static struct resource_list *
+ofw_spibus_get_resource_list(device_t bus __unused, device_t child)
+{
+	struct spibus_ivar *devi;
+        
+	devi = SPIBUS_IVAR(child);
+	return (&devi->rl);
+}
+
 static device_method_t ofw_spibus_methods[] = {
 	/* Device interface */
 	DEVMETHOD(device_probe,		ofw_spibus_probe),
@@ -206,6 +219,7 @@ static device_method_t ofw_spibus_methods[] = {
 	/* Bus interface */
 	DEVMETHOD(bus_child_pnpinfo_str, ofw_bus_gen_child_pnpinfo_str),
 	DEVMETHOD(bus_add_child,	ofw_spibus_add_child),
+	DEVMETHOD(bus_get_resource_list, ofw_spibus_get_resource_list),
 
 	/* ofw_bus interface */
 	DEVMETHOD(ofw_bus_get_devinfo,	ofw_spibus_get_devinfo),

Modified: head/sys/dev/spibus/spibus.c
==============================================================================
--- head/sys/dev/spibus/spibus.c	Thu Dec 17 17:09:43 2020	(r368724)
+++ head/sys/dev/spibus/spibus.c	Thu Dec 17 17:11:14 2020	(r368725)
@@ -101,6 +101,8 @@ spibus_print_child(device_t dev, device_t child)
 	retval += bus_print_child_header(dev, child);
 	retval += printf(" at cs %d", devi->cs);
 	retval += printf(" mode %d", devi->mode);
+	retval += resource_list_print_type(&devi->rl, "irq",
+	    SYS_RES_IRQ, "%jd");
 	retval += bus_print_child_footer(dev, child);
 
 	return (retval);
@@ -202,6 +204,7 @@ spibus_add_child(device_t dev, u_int order, const char
 		device_delete_child(dev, child);
 		return (0);
 	}
+	resource_list_init(&devi->rl);
 	device_set_ivars(child, devi);
 	return (child);
 }
@@ -210,6 +213,7 @@ static void
 spibus_hinted_child(device_t bus, const char *dname, int dunit)
 {
 	device_t child;
+	int irq;
 	struct spibus_ivar *devi;
 
 	child = BUS_ADD_CHILD(bus, 0, dname, dunit);
@@ -218,8 +222,22 @@ spibus_hinted_child(device_t bus, const char *dname, i
 	resource_int_value(dname, dunit, "clock", &devi->clock);
 	resource_int_value(dname, dunit, "cs", &devi->cs);
 	resource_int_value(dname, dunit, "mode", &devi->mode);
+	if (resource_int_value(dname, dunit, "irq", &irq) == 0) {
+		if (bus_set_resource(child, SYS_RES_IRQ, 0, irq, 1) != 0)
+			device_printf(bus,
+			    "Warning: bus_set_resource() failed\n");
+	}
 }
 
+static struct resource_list *
+spibus_get_resource_list(device_t bus __unused, device_t child)
+{
+	struct spibus_ivar *devi;
+
+	devi = SPIBUS_IVAR(child);
+	return (&devi->rl);
+}
+
 static int
 spibus_transfer_impl(device_t dev, device_t child, struct spi_command *cmd)
 {
@@ -236,6 +254,17 @@ static device_method_t spibus_methods[] = {
 	DEVMETHOD(device_resume,	spibus_resume),
 
 	/* Bus interface */
+	DEVMETHOD(bus_setup_intr,	bus_generic_setup_intr),
+	DEVMETHOD(bus_teardown_intr,	bus_generic_teardown_intr),
+	DEVMETHOD(bus_release_resource,	bus_generic_release_resource),
+	DEVMETHOD(bus_activate_resource, bus_generic_activate_resource),
+	DEVMETHOD(bus_deactivate_resource, bus_generic_deactivate_resource),
+	DEVMETHOD(bus_adjust_resource,	bus_generic_adjust_resource),
+	DEVMETHOD(bus_alloc_resource,	bus_generic_rl_alloc_resource),
+	DEVMETHOD(bus_get_resource,	bus_generic_rl_get_resource),
+	DEVMETHOD(bus_set_resource,	bus_generic_rl_set_resource),
+	DEVMETHOD(bus_get_resource_list, spibus_get_resource_list),
+
 	DEVMETHOD(bus_add_child,	spibus_add_child),
 	DEVMETHOD(bus_print_child,	spibus_print_child),
 	DEVMETHOD(bus_probe_nomatch,	spibus_probe_nomatch),

Modified: head/sys/dev/spibus/spibusvar.h
==============================================================================
--- head/sys/dev/spibus/spibusvar.h	Thu Dec 17 17:09:43 2020	(r368724)
+++ head/sys/dev/spibus/spibusvar.h	Thu Dec 17 17:11:14 2020	(r368725)
@@ -43,6 +43,7 @@ struct spibus_ivar
 	uint32_t	cs;
 	uint32_t	mode;
 	uint32_t	clock;
+	struct resource_list	rl;
 };
 
 #define	SPIBUS_CS_HIGH	(1U << 31)



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202012171711.0BHHBEeZ076088>