Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 7 Apr 2018 18:09:31 +0000 (UTC)
From:      Ian Lepore <ian@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r332194 - head/sys/dev/spibus
Message-ID:  <201804071809.w37I9Vip015051@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: ian
Date: Sat Apr  7 18:09:31 2018
New Revision: 332194
URL: https://svnweb.freebsd.org/changeset/base/332194

Log:
  Add support for writing/changing spi device ivars.  The SPI mode (polarity
  and phase) and the maximum bus speed can be changed.  The chip select
  number cannot be changed, because the device instances which are children
  of spibus are inherently associated with the chip select number they were
  instantiated for.

Modified:
  head/sys/dev/spibus/spibus.c

Modified: head/sys/dev/spibus/spibus.c
==============================================================================
--- head/sys/dev/spibus/spibus.c	Sat Apr  7 18:08:42 2018	(r332193)
+++ head/sys/dev/spibus/spibus.c	Sat Apr  7 18:09:31 2018	(r332194)
@@ -160,6 +160,37 @@ spibus_read_ivar(device_t bus, device_t child, int whi
 	return (0);
 }
 
+static int
+spibus_write_ivar(device_t bus, device_t child, int which, uintptr_t value)
+{
+	struct spibus_ivar *devi = SPIBUS_IVAR(child);
+
+	if (devi == NULL || device_get_parent(child) != bus)
+		return (EDOOFUS);
+
+	switch (which) {
+	case SPIBUS_IVAR_CLOCK:
+		/* Any non-zero value is allowed for max clock frequency. */
+		if (value == 0)
+			return (EINVAL);
+		devi->clock = (uint32_t)value;
+		break;
+	case SPIBUS_IVAR_CS:
+		 /* Chip select cannot be changed. */
+		return (EINVAL);
+	case SPIBUS_IVAR_MODE:
+		/* Valid SPI modes are 0-3. */
+		if (value > 3)
+			return (EINVAL);
+		devi->mode = (uint32_t)value;
+		break;
+	default:
+		return (EINVAL);
+	}
+
+	return (0);
+}
+
 static device_t
 spibus_add_child(device_t dev, u_int order, const char *name, int unit)
 {
@@ -211,6 +242,7 @@ static device_method_t spibus_methods[] = {
 	DEVMETHOD(bus_print_child,	spibus_print_child),
 	DEVMETHOD(bus_probe_nomatch,	spibus_probe_nomatch),
 	DEVMETHOD(bus_read_ivar,	spibus_read_ivar),
+	DEVMETHOD(bus_write_ivar,	spibus_write_ivar),
 	DEVMETHOD(bus_child_pnpinfo_str, spibus_child_pnpinfo_str),
 	DEVMETHOD(bus_child_location_str, spibus_child_location_str),
 	DEVMETHOD(bus_hinted_child,	spibus_hinted_child),



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