CVS commit: src/sys/dev/spi

2024-02-23 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Fri Feb 23 23:45:54 UTC 2024

Modified Files:
src/sys/dev/spi: spivar.h

Log Message:
Define mode macros for CPOL and CPHA, and define SPI_MODE_* in terms
of CPOL and CPHA.  Add SPI_FREQ_*() helper macros to make setting the
transfer frequency less error prone.


To generate a diff of this commit:
cvs rdiff -u -r1.12 -r1.13 src/sys/dev/spi/spivar.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/dev/spi/spivar.h
diff -u src/sys/dev/spi/spivar.h:1.12 src/sys/dev/spi/spivar.h:1.13
--- src/sys/dev/spi/spivar.h:1.12	Wed Jan 19 13:33:11 2022
+++ src/sys/dev/spi/spivar.h	Fri Feb 23 23:45:54 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: spivar.h,v 1.12 2022/01/19 13:33:11 thorpej Exp $ */
+/* $NetBSD: spivar.h,v 1.13 2024/02/23 23:45:54 thorpej Exp $ */
 
 /*-
  * Copyright (c) 2006 Urbana-Champaign Independent Media Center.
@@ -55,16 +55,24 @@
 struct spi_handle;
 struct spi_transfer;
 
+#define	SPI_MODE_CPHA	__BIT(0)
+#define	SPI_MODE_CPOL	__BIT(1)
+
 /*
  * De facto standard latching modes.
  */
-#define	SPI_MODE_0	0	/* CPOL = 0, CPHA = 0 */
-#define	SPI_MODE_1	1	/* CPOL = 0, CPHA = 1 */
-#define	SPI_MODE_2	2	/* CPOL = 1, CPHA = 0 */
-#define	SPI_MODE_3	3	/* CPOL = 1, CPHA = 1 */
+#define	SPI_MODE_0	0
+#define	SPI_MODE_1	SPI_MODE_CPHA
+#define	SPI_MODE_2	SPI_MODE_CPOL
+#define	SPI_MODE_3	(SPI_MODE_CPHA | SPI_MODE_CPOL)
+
 /* Philips' Microwire is just Mode 0 */
 #define	SPI_MODE_MICROWIRE	SPI_MODE_0
 
+/* SPI transfer speed helper macros -- converts to Hz for spi_configure(). */
+#define	SPI_FREQ_kHz(x)	((x) * 1000)
+#define	SPI_FREQ_MHz(x)	((x) * 100)
+
 struct spi_controller {
 	void	*sct_cookie;	/* controller private data */
 	int	sct_nslaves;



CVS commit: src/sys/dev/spi

2024-02-23 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Fri Feb 23 23:45:54 UTC 2024

Modified Files:
src/sys/dev/spi: spivar.h

Log Message:
Define mode macros for CPOL and CPHA, and define SPI_MODE_* in terms
of CPOL and CPHA.  Add SPI_FREQ_*() helper macros to make setting the
transfer frequency less error prone.


To generate a diff of this commit:
cvs rdiff -u -r1.12 -r1.13 src/sys/dev/spi/spivar.h

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



CVS commit: src/sys/dev/spi

2022-05-08 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Sun May  8 06:38:59 UTC 2022

Modified Files:
src/sys/dev/spi: spi.c spiflash.c

Log Message:
Trailing whitespace


To generate a diff of this commit:
cvs rdiff -u -r1.24 -r1.25 src/sys/dev/spi/spi.c
cvs rdiff -u -r1.25 -r1.26 src/sys/dev/spi/spiflash.c

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

Modified files:

Index: src/sys/dev/spi/spi.c
diff -u src/sys/dev/spi/spi.c:1.24 src/sys/dev/spi/spi.c:1.25
--- src/sys/dev/spi/spi.c:1.24	Mon Mar 28 11:09:24 2022
+++ src/sys/dev/spi/spi.c	Sun May  8 06:38:58 2022
@@ -1,4 +1,4 @@
-/* $NetBSD: spi.c,v 1.24 2022/03/28 11:09:24 mlelstv Exp $ */
+/* $NetBSD: spi.c,v 1.25 2022/05/08 06:38:58 skrll Exp $ */
 
 /*-
  * Copyright (c) 2006 Urbana-Champaign Independent Media Center.
@@ -42,7 +42,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: spi.c,v 1.24 2022/03/28 11:09:24 mlelstv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: spi.c,v 1.25 2022/05/08 06:38:58 skrll Exp $");
 
 #include "locators.h"
 
@@ -544,7 +544,7 @@ spi_transfer(struct spi_handle *sh, stru
 	spi_acquire(sh);
 
 	st->st_spiprivate = (void *)sh;
-	
+
 	/*
 	 * Reconfigure controller
 	 *

Index: src/sys/dev/spi/spiflash.c
diff -u src/sys/dev/spi/spiflash.c:1.25 src/sys/dev/spi/spiflash.c:1.26
--- src/sys/dev/spi/spiflash.c:1.25	Sat Aug  7 16:19:16 2021
+++ src/sys/dev/spi/spiflash.c	Sun May  8 06:38:58 2022
@@ -1,4 +1,4 @@
-/* $NetBSD: spiflash.c,v 1.25 2021/08/07 16:19:16 thorpej Exp $ */
+/* $NetBSD: spiflash.c,v 1.26 2022/05/08 06:38:58 skrll Exp $ */
 
 /*-
  * Copyright (c) 2006 Urbana-Champaign Independent Media Center.
@@ -42,7 +42,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: spiflash.c,v 1.25 2021/08/07 16:19:16 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: spiflash.c,v 1.26 2022/05/08 06:38:58 skrll Exp $");
 
 #include 
 #include 
@@ -384,7 +384,7 @@ spiflash_process_read(spiflash_handle_t 
 			bufq_move(sc->sc_doneq, sc->sc_workq);
 			break;
 		}
-		
+
 		bp->b_resid -= cnt;
 		data += cnt;
 		addr += cnt;
@@ -422,7 +422,7 @@ spiflash_process_write(spiflash_handle_t
 	/* read in as much of the data as we need */
 	DPRINTF(("reading in %d bytes\n", len));
 	if ((err = sc->sc_read(sc, base, len, save)) != 0) {
-		bufq_move(sc->sc_doneq, sc->sc_workq);	
+		bufq_move(sc->sc_doneq, sc->sc_workq);
 		spiflash_process_done(sc, err);
 		return;
 	}
@@ -455,7 +455,7 @@ spiflash_process_write(spiflash_handle_t
 
 		bufq_put(sc->sc_doneq, bp);
 	}
-	
+
 	/*
 	 * do the erase, if we need to.
 	 */
@@ -578,7 +578,7 @@ spiflash_common_erase(spiflash_handle_t 
 	if ((start % sc->sc_erase_size) || (size % sc->sc_erase_size))
 		return EINVAL;
 
-	/* the second test is to test against wrap */ 
+	/* the second test is to test against wrap */
 	if ((start > sc->sc_device_size) ||
 	((start + size) > sc->sc_device_size))
 		return EINVAL;
@@ -674,7 +674,7 @@ spiflash_common_read(spiflash_handle_t s
 
 		if (sc->sc_read_size > 0)
 			cnt = uimin(size, sc->sc_read_size);
-		else 
+		else
 			cnt = size;
 
 		if ((rv = spiflash_cmd(sc, SPIFLASH_CMD_READ, 3, start,



CVS commit: src/sys/dev/spi

2022-05-08 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Sun May  8 06:38:59 UTC 2022

Modified Files:
src/sys/dev/spi: spi.c spiflash.c

Log Message:
Trailing whitespace


To generate a diff of this commit:
cvs rdiff -u -r1.24 -r1.25 src/sys/dev/spi/spi.c
cvs rdiff -u -r1.25 -r1.26 src/sys/dev/spi/spiflash.c

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



CVS commit: src/sys/dev/spi

2022-03-28 Thread Michael van Elst
Module Name:src
Committed By:   mlelstv
Date:   Mon Mar 28 11:09:24 UTC 2022

Modified Files:
src/sys/dev/spi: spi.c

Log Message:
Fix sanity check for zero sized buffer.


To generate a diff of this commit:
cvs rdiff -u -r1.23 -r1.24 src/sys/dev/spi/spi.c

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

Modified files:

Index: src/sys/dev/spi/spi.c
diff -u src/sys/dev/spi/spi.c:1.23 src/sys/dev/spi/spi.c:1.24
--- src/sys/dev/spi/spi.c:1.23	Wed Jan 19 13:33:11 2022
+++ src/sys/dev/spi/spi.c	Mon Mar 28 11:09:24 2022
@@ -1,4 +1,4 @@
-/* $NetBSD: spi.c,v 1.23 2022/01/19 13:33:11 thorpej Exp $ */
+/* $NetBSD: spi.c,v 1.24 2022/03/28 11:09:24 mlelstv Exp $ */
 
 /*-
  * Copyright (c) 2006 Urbana-Champaign Independent Media Center.
@@ -42,7 +42,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: spi.c,v 1.23 2022/01/19 13:33:11 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: spi.c,v 1.24 2022/03/28 11:09:24 mlelstv Exp $");
 
 #include "locators.h"
 
@@ -380,7 +380,7 @@ spi_ioctl(dev_t dev, u_long cmd, void *d
 			break;
 		}
 		if ((sit->sit_send && sit->sit_sendlen == 0)
-		|| (sit->sit_recv && sit->sit_recv == 0)) {
+		|| (sit->sit_recv && sit->sit_recvlen == 0)) {
 			error = EINVAL;
 			break;
 		}



CVS commit: src/sys/dev/spi

2022-03-28 Thread Michael van Elst
Module Name:src
Committed By:   mlelstv
Date:   Mon Mar 28 11:09:24 UTC 2022

Modified Files:
src/sys/dev/spi: spi.c

Log Message:
Fix sanity check for zero sized buffer.


To generate a diff of this commit:
cvs rdiff -u -r1.23 -r1.24 src/sys/dev/spi/spi.c

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



CVS commit: src/sys/dev/spi

2022-01-19 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Wed Jan 19 13:33:49 UTC 2022

Modified Files:
src/sys/dev/spi: ssdfb_spi.c

Log Message:
Use spi_compatible_lookup().


To generate a diff of this commit:
cvs rdiff -u -r1.13 -r1.14 src/sys/dev/spi/ssdfb_spi.c

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

Modified files:

Index: src/sys/dev/spi/ssdfb_spi.c
diff -u src/sys/dev/spi/ssdfb_spi.c:1.13 src/sys/dev/spi/ssdfb_spi.c:1.14
--- src/sys/dev/spi/ssdfb_spi.c:1.13	Wed Jan 19 05:21:44 2022
+++ src/sys/dev/spi/ssdfb_spi.c	Wed Jan 19 13:33:49 2022
@@ -1,4 +1,4 @@
-/* $NetBSD: ssdfb_spi.c,v 1.13 2022/01/19 05:21:44 thorpej Exp $ */
+/* $NetBSD: ssdfb_spi.c,v 1.14 2022/01/19 13:33:49 thorpej Exp $ */
 
 /*
  * Copyright (c) 2019 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ssdfb_spi.c,v 1.13 2022/01/19 05:21:44 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ssdfb_spi.c,v 1.14 2022/01/19 13:33:49 thorpej Exp $");
 
 #include 
 #include 
@@ -120,7 +120,7 @@ ssdfb_spi_attach(device_t parent, device
 	sc->sc.sc_cookie = (void *)sc;
 	if ((flags & SSDFB_ATTACH_FLAG_PRODUCT_MASK) == SSDFB_PRODUCT_UNKNOWN) {
 		const struct device_compatible_entry *dce =
-			device_compatible_lookup(sa->sa_compat, sa->sa_ncompat, compat_data);
+			spi_compatible_lookup(sa, compat_data);
 		if (dce)
 			flags |= (int)dce->value;
 		else



CVS commit: src/sys/dev/spi

2022-01-19 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Wed Jan 19 13:33:49 UTC 2022

Modified Files:
src/sys/dev/spi: ssdfb_spi.c

Log Message:
Use spi_compatible_lookup().


To generate a diff of this commit:
cvs rdiff -u -r1.13 -r1.14 src/sys/dev/spi/ssdfb_spi.c

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



CVS commit: src/sys/dev/spi

2022-01-19 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Wed Jan 19 13:33:11 UTC 2022

Modified Files:
src/sys/dev/spi: spi.c spivar.h

Log Message:
Provide a spi_compatible_lookup() function to go along with
spi_compatible_match().


To generate a diff of this commit:
cvs rdiff -u -r1.22 -r1.23 src/sys/dev/spi/spi.c
cvs rdiff -u -r1.11 -r1.12 src/sys/dev/spi/spivar.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/dev/spi/spi.c
diff -u src/sys/dev/spi/spi.c:1.22 src/sys/dev/spi/spi.c:1.23
--- src/sys/dev/spi/spi.c:1.22	Wed Jan 19 12:58:06 2022
+++ src/sys/dev/spi/spi.c	Wed Jan 19 13:33:11 2022
@@ -1,4 +1,4 @@
-/* $NetBSD: spi.c,v 1.22 2022/01/19 12:58:06 thorpej Exp $ */
+/* $NetBSD: spi.c,v 1.23 2022/01/19 13:33:11 thorpej Exp $ */
 
 /*-
  * Copyright (c) 2006 Urbana-Champaign Independent Media Center.
@@ -42,7 +42,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: spi.c,v 1.22 2022/01/19 12:58:06 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: spi.c,v 1.23 2022/01/19 13:33:11 thorpej Exp $");
 
 #include "locators.h"
 
@@ -272,6 +272,14 @@ spi_compatible_match(const struct spi_at
 	return 1;
 }
 
+const struct device_compatible_entry *
+spi_compatible_lookup(const struct spi_attach_args *sa,
+const struct device_compatible_entry *compats)
+{
+	return device_compatible_lookup(sa->sa_compat, sa->sa_ncompat,
+	compats);
+}
+
 /*
  * API for device drivers.
  *

Index: src/sys/dev/spi/spivar.h
diff -u src/sys/dev/spi/spivar.h:1.11 src/sys/dev/spi/spivar.h:1.12
--- src/sys/dev/spi/spivar.h:1.11	Wed Jan 19 05:21:44 2022
+++ src/sys/dev/spi/spivar.h	Wed Jan 19 13:33:11 2022
@@ -1,4 +1,4 @@
-/* $NetBSD: spivar.h,v 1.11 2022/01/19 05:21:44 thorpej Exp $ */
+/* $NetBSD: spivar.h,v 1.12 2022/01/19 13:33:11 thorpej Exp $ */
 
 /*-
  * Copyright (c) 2006 Urbana-Champaign Independent Media Center.
@@ -142,6 +142,9 @@ SIMPLEQ_HEAD(spi_transq, spi_transfer);
 
 int spi_compatible_match(const struct spi_attach_args *, const cfdata_t,
 			  const struct device_compatible_entry *);
+const struct device_compatible_entry *
+spi_compatible_lookup(const struct spi_attach_args *,
+			  const struct device_compatible_entry *);
 int spi_configure(device_t, struct spi_handle *, int, int);
 int spi_transfer(struct spi_handle *, struct spi_transfer *);
 void spi_transfer_init(struct spi_transfer *);



CVS commit: src/sys/dev/spi

2022-01-19 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Wed Jan 19 13:33:11 UTC 2022

Modified Files:
src/sys/dev/spi: spi.c spivar.h

Log Message:
Provide a spi_compatible_lookup() function to go along with
spi_compatible_match().


To generate a diff of this commit:
cvs rdiff -u -r1.22 -r1.23 src/sys/dev/spi/spi.c
cvs rdiff -u -r1.11 -r1.12 src/sys/dev/spi/spivar.h

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



CVS commit: src/sys/dev/spi

2022-01-19 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Wed Jan 19 12:58:06 UTC 2022

Modified Files:
src/sys/dev/spi: spi.c

Log Message:
Stash the device_t in spi_softc.


To generate a diff of this commit:
cvs rdiff -u -r1.21 -r1.22 src/sys/dev/spi/spi.c

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

Modified files:

Index: src/sys/dev/spi/spi.c
diff -u src/sys/dev/spi/spi.c:1.21 src/sys/dev/spi/spi.c:1.22
--- src/sys/dev/spi/spi.c:1.21	Wed Jan 19 09:30:11 2022
+++ src/sys/dev/spi/spi.c	Wed Jan 19 12:58:06 2022
@@ -1,4 +1,4 @@
-/* $NetBSD: spi.c,v 1.21 2022/01/19 09:30:11 martin Exp $ */
+/* $NetBSD: spi.c,v 1.22 2022/01/19 12:58:06 thorpej Exp $ */
 
 /*-
  * Copyright (c) 2006 Urbana-Champaign Independent Media Center.
@@ -42,7 +42,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: spi.c,v 1.21 2022/01/19 09:30:11 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: spi.c,v 1.22 2022/01/19 12:58:06 thorpej Exp $");
 
 #include "locators.h"
 
@@ -62,6 +62,7 @@ __KERNEL_RCSID(0, "$NetBSD: spi.c,v 1.21
 #include "locators.h"
 
 struct spi_softc {
+	device_t		sc_dev;
 	struct spi_controller	sc_controller;
 	int			sc_mode;
 	int			sc_speed;
@@ -291,6 +292,7 @@ spi_attach(device_t parent, device_t sel
 	mutex_init(>sc_lock, MUTEX_DEFAULT, IPL_VM);
 	cv_init(>sc_cv, "spictl");
 
+	sc->sc_dev = self;
 	sc->sc_controller = *sba->sba_controller;
 	sc->sc_nslaves = sba->sba_controller->sct_nslaves;
 	/* allocate slave structures */
@@ -341,7 +343,6 @@ static int
 spi_ioctl(dev_t dev, u_long cmd, void *data, int flag, lwp_t *l)
 {
 	struct spi_softc *sc = device_lookup_private(_cd, minor(dev));
-	device_t self = device_lookup(_cd, minor(dev));
 	struct spi_handle *sh;
 	spi_ioctl_configure_t *sic;
 	spi_ioctl_transfer_t *sit;
@@ -361,7 +362,8 @@ spi_ioctl(dev_t dev, u_long cmd, void *d
 			break;
 		}
 		sh = >sc_slaves[sic->sic_addr];
-		error = spi_configure(self, sh, sic->sic_mode, sic->sic_speed);
+		error = spi_configure(sc->sc_dev, sh, sic->sic_mode,
+		sic->sic_speed);
 		break;
 	case SPI_IOCTL_TRANSFER:
 		sit = (spi_ioctl_transfer_t *)data;
@@ -670,4 +672,3 @@ spi_send_recv(struct spi_handle *sh, int
 
 	return 0;
 }
-



CVS commit: src/sys/dev/spi

2022-01-19 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Wed Jan 19 12:58:06 UTC 2022

Modified Files:
src/sys/dev/spi: spi.c

Log Message:
Stash the device_t in spi_softc.


To generate a diff of this commit:
cvs rdiff -u -r1.21 -r1.22 src/sys/dev/spi/spi.c

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



CVS commit: src/sys/dev/spi

2022-01-19 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Wed Jan 19 09:30:11 UTC 2022

Modified Files:
src/sys/dev/spi: spi.c

Log Message:
Try to fix the build.


To generate a diff of this commit:
cvs rdiff -u -r1.20 -r1.21 src/sys/dev/spi/spi.c

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

Modified files:

Index: src/sys/dev/spi/spi.c
diff -u src/sys/dev/spi/spi.c:1.20 src/sys/dev/spi/spi.c:1.21
--- src/sys/dev/spi/spi.c:1.20	Wed Jan 19 05:21:44 2022
+++ src/sys/dev/spi/spi.c	Wed Jan 19 09:30:11 2022
@@ -1,4 +1,4 @@
-/* $NetBSD: spi.c,v 1.20 2022/01/19 05:21:44 thorpej Exp $ */
+/* $NetBSD: spi.c,v 1.21 2022/01/19 09:30:11 martin Exp $ */
 
 /*-
  * Copyright (c) 2006 Urbana-Champaign Independent Media Center.
@@ -42,7 +42,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: spi.c,v 1.20 2022/01/19 05:21:44 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: spi.c,v 1.21 2022/01/19 09:30:11 martin Exp $");
 
 #include "locators.h"
 
@@ -341,6 +341,7 @@ static int
 spi_ioctl(dev_t dev, u_long cmd, void *data, int flag, lwp_t *l)
 {
 	struct spi_softc *sc = device_lookup_private(_cd, minor(dev));
+	device_t self = device_lookup(_cd, minor(dev));
 	struct spi_handle *sh;
 	spi_ioctl_configure_t *sic;
 	spi_ioctl_transfer_t *sit;
@@ -360,7 +361,7 @@ spi_ioctl(dev_t dev, u_long cmd, void *d
 			break;
 		}
 		sh = >sc_slaves[sic->sic_addr];
-		error = spi_configure(sh, sic->sic_mode, sic->sic_speed);
+		error = spi_configure(self, sh, sic->sic_mode, sic->sic_speed);
 		break;
 	case SPI_IOCTL_TRANSFER:
 		sit = (spi_ioctl_transfer_t *)data;



CVS commit: src/sys/dev/spi

2022-01-19 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Wed Jan 19 09:30:11 UTC 2022

Modified Files:
src/sys/dev/spi: spi.c

Log Message:
Try to fix the build.


To generate a diff of this commit:
cvs rdiff -u -r1.20 -r1.21 src/sys/dev/spi/spi.c

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



CVS commit: src/sys/dev/spi

2021-08-19 Thread Tobias Nygren
Module Name:src
Committed By:   tnn
Date:   Thu Aug 19 17:50:18 UTC 2021

Modified Files:
src/sys/dev/spi: ssdfb_spi.c

Log Message:
ssdfb: add support for SSD1306 and SH1106 at spi attachment

Only support the 4-wire mode for now. Support for 3-wire mode is
theoretically possible but most (all?) modules in circulation have the
BS0 / IM0 3-wire config pin internally grounded within the flat-flex
assembly so it is not easy to enable & test.


To generate a diff of this commit:
cvs rdiff -u -r1.10 -r1.11 src/sys/dev/spi/ssdfb_spi.c

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

Modified files:

Index: src/sys/dev/spi/ssdfb_spi.c
diff -u src/sys/dev/spi/ssdfb_spi.c:1.10 src/sys/dev/spi/ssdfb_spi.c:1.11
--- src/sys/dev/spi/ssdfb_spi.c:1.10	Thu Aug 19 11:04:21 2021
+++ src/sys/dev/spi/ssdfb_spi.c	Thu Aug 19 17:50:18 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: ssdfb_spi.c,v 1.10 2021/08/19 11:04:21 tnn Exp $ */
+/* $NetBSD: ssdfb_spi.c,v 1.11 2021/08/19 17:50:18 tnn Exp $ */
 
 /*
  * Copyright (c) 2019 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ssdfb_spi.c,v 1.10 2021/08/19 11:04:21 tnn Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ssdfb_spi.c,v 1.11 2021/08/19 17:50:18 tnn Exp $");
 
 #include 
 #include 
@@ -70,6 +70,10 @@ static int	ssdfb_spi_xfer_rect_3wire_ssd
 		uint8_t, uint8_t, uint8_t *, size_t, bool);
 
 static int	ssdfb_spi_cmd_4wire(void *, uint8_t *, size_t, bool);
+static int	ssdfb_spi_xfer_rect_4wire_sh1106(void *, uint8_t, uint8_t,
+		uint8_t, uint8_t, uint8_t *, size_t, bool);
+static int	ssdfb_spi_xfer_rect_4wire_ssd1306(void *, uint8_t, uint8_t,
+		uint8_t, uint8_t, uint8_t *, size_t, bool);
 static int	ssdfb_spi_xfer_rect_4wire_ssd1322(void *, uint8_t, uint8_t,
 		uint8_t, uint8_t, uint8_t *, size_t, bool);
 static int	ssdfb_spi_xfer_rect_4wire_ssd1353(void *, uint8_t, uint8_t,
@@ -87,6 +91,7 @@ CFATTACH_DECL_NEW(ssdfb_spi, sizeof(stru
 
 static const struct device_compatible_entry compat_data[] = {
 	{ .compat = "solomon,ssd1306",	.value = SSDFB_PRODUCT_SSD1306_GENERIC },
+	{ .compat = "sino,sh1106",	.value = SSDFB_PRODUCT_SH1106_GENERIC },
 	{ .compat = "solomon,ssd1322",	.value = SSDFB_PRODUCT_SSD1322_GENERIC },
 	{ .compat = "solomon,ssd1353",	.value = SSDFB_PRODUCT_SSD1353_GENERIC },
 	{ .compat = "dep160128a",	.value = SSDFB_PRODUCT_DEP_160128A_RGB },
@@ -165,6 +170,20 @@ ssdfb_spi_attach(device_t parent, device
 	: ssdfb_spi_cmd_4wire;
 
 	switch (flags & SSDFB_ATTACH_FLAG_PRODUCT_MASK) {
+	case SSDFB_PRODUCT_SH1106_GENERIC:
+		sc->sc.sc_transfer_rect = sc->sc_3wiremode
+		? NULL
+		: ssdfb_spi_xfer_rect_4wire_sh1106;
+		sc->sc_padding_cmd = SSDFB_CMD_NOP;
+		sc->sc_late_dc_deassert = true;
+		break;
+	case SSDFB_PRODUCT_SSD1306_GENERIC:
+		sc->sc.sc_transfer_rect = sc->sc_3wiremode
+		? NULL
+		: ssdfb_spi_xfer_rect_4wire_ssd1306;
+		sc->sc_padding_cmd = SSDFB_CMD_NOP;
+		sc->sc_late_dc_deassert = true;
+		break;
 	case SSDFB_PRODUCT_SSD1322_GENERIC:
 		sc->sc.sc_transfer_rect = sc->sc_3wiremode
 		? ssdfb_spi_xfer_rect_3wire_ssd1322
@@ -215,7 +234,6 @@ ssdfb_spi_xfer_rect_3wire_ssd1322(void *
 	struct ssdfb_spi_softc *sc = (struct ssdfb_spi_softc *)cookie;
 	uint8_t bitstream[128 * 9 / 8];
 	struct bs_state s;
-	uint8_t row;
 	size_t rlen = (tocol + 1 - fromcol) * 2;
 	int error;
 
@@ -239,13 +257,14 @@ ssdfb_spi_xfer_rect_3wire_ssd1322(void *
 		return error;
 
 	KASSERT(rlen <= 128);
-	for (row = fromrow; row <= torow; row++) {
+	while (fromrow <= torow) {
 		ssdfb_bitstream_init(, bitstream);
 		ssdfb_bitstream_append_data(, p, rlen);
 		ssdfb_bitstream_final(, sc->sc_padding_cmd);
 		error = spi_send(sc->sc_sh, s.cur - s.base, bitstream);
 		if (error)
 			return error;
+		fromrow++;
 		p += stride;
 	}
 
@@ -334,19 +353,86 @@ ssdfb_spi_cmd_4wire(void *cookie, uint8_
 }
 
 static int
+ssdfb_spi_xfer_rect_4wire_sh1106(void *cookie, uint8_t fromcol, uint8_t tocol,
+uint8_t frompage, uint8_t topage, uint8_t *p, size_t stride, bool usepoll)
+{
+	struct ssdfb_spi_softc *sc = (struct ssdfb_spi_softc *)cookie;
+	size_t rlen = tocol + 1 - fromcol;
+	int error;
+	uint8_t cmd[] = {
+		SSDFB_CMD_SET_PAGE_START_ADDRESS_BASE + frompage,
+		SSDFB_CMD_SET_HIGHER_COLUMN_START_ADDRESS_BASE + (fromcol >> 4),
+		SSDFB_CMD_SET_LOWER_COLUMN_START_ADDRESS_BASE + (fromcol & 0xf)
+	};
+
+	if (usepoll && !cold)
+		return 0;
+
+	while (frompage <= topage) {
+		cmd[0] = SSDFB_CMD_SET_PAGE_START_ADDRESS_BASE + frompage;
+		ssdfb_spi_4wire_set_dc(sc, 0);
+		error = spi_send(sc->sc_sh, sizeof(cmd), cmd);
+		if (error)
+			return error;
+		ssdfb_spi_4wire_set_dc(sc, 1);
+		error = spi_send(sc->sc_sh, rlen, p);
+		if (error)
+			return error;
+		frompage++;
+		p += stride;
+	}
+
+	return 0;
+}
+
+static int
+ssdfb_spi_xfer_rect_4wire_ssd1306(void *cookie, uint8_t fromcol, uint8_t tocol,
+uint8_t frompage, uint8_t topage, uint8_t *p, size_t 

CVS commit: src/sys/dev/spi

2021-08-19 Thread Tobias Nygren
Module Name:src
Committed By:   tnn
Date:   Thu Aug 19 17:50:18 UTC 2021

Modified Files:
src/sys/dev/spi: ssdfb_spi.c

Log Message:
ssdfb: add support for SSD1306 and SH1106 at spi attachment

Only support the 4-wire mode for now. Support for 3-wire mode is
theoretically possible but most (all?) modules in circulation have the
BS0 / IM0 3-wire config pin internally grounded within the flat-flex
assembly so it is not easy to enable & test.


To generate a diff of this commit:
cvs rdiff -u -r1.10 -r1.11 src/sys/dev/spi/ssdfb_spi.c

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



CVS commit: src/sys/dev/spi

2021-08-19 Thread Tobias Nygren
Module Name:src
Committed By:   tnn
Date:   Thu Aug 19 11:04:21 UTC 2021

Modified Files:
src/sys/dev/spi: ssdfb_spi.c

Log Message:
ssdfb_spi: fix issues with command xfers needed for SSD1306 & SH1106

These controllers require D/C# to be deasserted for the entire duration
of the command, contrary to docs and how newer controllers like SSD1353
behave. Probably this is needed for all controllers that do not have the
WRITE_RAM (0x5c) command. Also support using alternate padding commands
for 3-wire mode when WRITE_RAM is not available.


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 src/sys/dev/spi/ssdfb_spi.c

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

Modified files:

Index: src/sys/dev/spi/ssdfb_spi.c
diff -u src/sys/dev/spi/ssdfb_spi.c:1.9 src/sys/dev/spi/ssdfb_spi.c:1.10
--- src/sys/dev/spi/ssdfb_spi.c:1.9	Thu Aug  5 19:17:22 2021
+++ src/sys/dev/spi/ssdfb_spi.c	Thu Aug 19 11:04:21 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: ssdfb_spi.c,v 1.9 2021/08/05 19:17:22 tnn Exp $ */
+/* $NetBSD: ssdfb_spi.c,v 1.10 2021/08/19 11:04:21 tnn Exp $ */
 
 /*
  * Copyright (c) 2019 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ssdfb_spi.c,v 1.9 2021/08/05 19:17:22 tnn Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ssdfb_spi.c,v 1.10 2021/08/19 11:04:21 tnn Exp $");
 
 #include 
 #include 
@@ -58,6 +58,8 @@ struct ssdfb_spi_softc {
 	struct fdtbus_gpio_pin	*sc_gpio_res;
 #endif
 	bool			sc_3wiremode;
+	bool			sc_late_dc_deassert;
+	uint8_t			sc_padding_cmd;
 };
 
 static int	ssdfb_spi_match(device_t, cfdata_t, void *);
@@ -78,7 +80,7 @@ static void	ssdfb_bitstream_append(struc
 static void	ssdfb_bitstream_append_cmd(struct bs_state *, uint8_t);
 static void	ssdfb_bitstream_append_data(struct bs_state *, uint8_t *,
 		size_t);
-static void	ssdfb_bitstream_final(struct bs_state *);
+static void	ssdfb_bitstream_final(struct bs_state *, uint8_t);
 
 CFATTACH_DECL_NEW(ssdfb_spi, sizeof(struct ssdfb_spi_softc),
 ssdfb_spi_match, ssdfb_spi_attach, NULL, NULL);
@@ -167,6 +169,7 @@ ssdfb_spi_attach(device_t parent, device
 		sc->sc.sc_transfer_rect = sc->sc_3wiremode
 		? ssdfb_spi_xfer_rect_3wire_ssd1322
 		: ssdfb_spi_xfer_rect_4wire_ssd1322;
+		sc->sc_padding_cmd = SSD1322_CMD_WRITE_RAM;
 		break;
 	case SSDFB_PRODUCT_SSD1353_GENERIC:
 	case SSDFB_PRODUCT_DEP_160128A_RGB:
@@ -200,7 +203,7 @@ ssdfb_spi_cmd_3wire(void *cookie, uint8_
 	cmd++;
 	len--;
 	ssdfb_bitstream_append_data(, cmd, len);
-	ssdfb_bitstream_final();
+	ssdfb_bitstream_final(, sc->sc_padding_cmd);
 
 	return spi_send(sc->sc_sh, s.cur - s.base, bitstream);
 }
@@ -230,7 +233,7 @@ ssdfb_spi_xfer_rect_3wire_ssd1322(void *
 	ssdfb_bitstream_append_data(, , 1);
 	ssdfb_bitstream_append_data(, , 1);
 	ssdfb_bitstream_append_cmd(, SSD1322_CMD_WRITE_RAM);
-	ssdfb_bitstream_final();
+	ssdfb_bitstream_final(, sc->sc_padding_cmd);
 	error = spi_send(sc->sc_sh, s.cur - s.base, bitstream);
 	if (error)
 		return error;
@@ -239,7 +242,7 @@ ssdfb_spi_xfer_rect_3wire_ssd1322(void *
 	for (row = fromrow; row <= torow; row++) {
 		ssdfb_bitstream_init(, bitstream);
 		ssdfb_bitstream_append_data(, p, rlen);
-		ssdfb_bitstream_final();
+		ssdfb_bitstream_final(, sc->sc_padding_cmd);
 		error = spi_send(sc->sc_sh, s.cur - s.base, bitstream);
 		if (error)
 			return error;
@@ -290,11 +293,8 @@ ssdfb_bitstream_append_data(struct bs_st
 }
 
 static void
-ssdfb_bitstream_final(struct bs_state *s)
+ssdfb_bitstream_final(struct bs_state *s, uint8_t padding_cmd)
 {
-	uint8_t padding_cmd = SSD1322_CMD_WRITE_RAM;
-	/* padding_cmd = SSDFB_NOP_CMD; */
-
 	while (s->mask != 0x80) {
 		ssdfb_bitstream_append_cmd(s, padding_cmd);
 	}
@@ -321,7 +321,8 @@ ssdfb_spi_cmd_4wire(void *cookie, uint8_
 	if (error)
 		return error;
 	if (len > 1) {
-		ssdfb_spi_4wire_set_dc(sc, 1);
+		if (!sc->sc_late_dc_deassert)
+			ssdfb_spi_4wire_set_dc(sc, 1);
 		len--;
 		cmd++;
 		error = spi_send(sc->sc_sh, len, cmd);



CVS commit: src/sys/dev/spi

2021-08-19 Thread Tobias Nygren
Module Name:src
Committed By:   tnn
Date:   Thu Aug 19 11:04:21 UTC 2021

Modified Files:
src/sys/dev/spi: ssdfb_spi.c

Log Message:
ssdfb_spi: fix issues with command xfers needed for SSD1306 & SH1106

These controllers require D/C# to be deasserted for the entire duration
of the command, contrary to docs and how newer controllers like SSD1353
behave. Probably this is needed for all controllers that do not have the
WRITE_RAM (0x5c) command. Also support using alternate padding commands
for 3-wire mode when WRITE_RAM is not available.


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 src/sys/dev/spi/ssdfb_spi.c

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



CVS commit: src/sys/dev/spi

2019-11-25 Thread Kenichi Hashimoto
Module Name:src
Committed By:   hkenken
Date:   Tue Nov 26 02:41:58 UTC 2019

Modified Files:
src/sys/dev/spi: m25p.c

Log Message:
Change manufacturer to Micron from Numonyx.

N25Q -> MT25Q


To generate a diff of this commit:
cvs rdiff -u -r1.14 -r1.15 src/sys/dev/spi/m25p.c

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



CVS commit: src/sys/dev/spi

2019-11-25 Thread Kenichi Hashimoto
Module Name:src
Committed By:   hkenken
Date:   Tue Nov 26 02:41:58 UTC 2019

Modified Files:
src/sys/dev/spi: m25p.c

Log Message:
Change manufacturer to Micron from Numonyx.

N25Q -> MT25Q


To generate a diff of this commit:
cvs rdiff -u -r1.14 -r1.15 src/sys/dev/spi/m25p.c

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

Modified files:

Index: src/sys/dev/spi/m25p.c
diff -u src/sys/dev/spi/m25p.c:1.14 src/sys/dev/spi/m25p.c:1.15
--- src/sys/dev/spi/m25p.c:1.14	Sat Sep 14 15:12:12 2019
+++ src/sys/dev/spi/m25p.c	Tue Nov 26 02:41:58 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: m25p.c,v 1.14 2019/09/14 15:12:12 tnn Exp $ */
+/* $NetBSD: m25p.c,v 1.15 2019/11/26 02:41:58 hkenken Exp $ */
 
 /*-
  * Copyright (c) 2006 Urbana-Champaign Independent Media Center.
@@ -42,7 +42,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: m25p.c,v 1.14 2019/09/14 15:12:12 tnn Exp $");
+__KERNEL_RCSID(0, "$NetBSD: m25p.c,v 1.15 2019/11/26 02:41:58 hkenken Exp $");
 
 #include 
 #include 
@@ -96,7 +96,8 @@ static const struct m25p_info {
 	{ 0x14, 0x20, 0x2015, "STMicro M25P16", 2048, 64 },	/* 16Mbit */
 	{ 0x12, 0x20, 0x2013, "STMicro M25P40", 512, 64 },	/* 4Mbit */
 	{ 0xc0, 0x20, 0x7117, "STMicro M25PX64", 8192, 64 },	/* 64Mbit */
-	{ 0x00, 0x20, 0xBB18, "Numonyx N25Q128", 16384, 64 },	/* 128Mbit */
+	{ 0x00, 0x20, 0xBA18, "Micron MT25QL128", 16384, 64 },  /* 128Mbit (3V) */
+	{ 0x00, 0x20, 0xBB18, "Micron MT25QU128", 16384, 64 },  /* 128Mbit (1.8V)  */
 	{ 0x00, 0xBF, 0x2541, "Microchip SST25VF016B", 2048, 64 }, /* 16Mbit */
 	{ 0x00, 0xC2, 0x2011, "Macronix MX25L10", 128, 64 },	/* 1Mbit */
 	{ 0x00, 0xC2, 0x2012, "Macronix MX25L20", 256, 64 },	/* 2Mbit */



CVS commit: src/sys/dev/spi

2019-11-02 Thread Tobias Nygren
Module Name:src
Committed By:   tnn
Date:   Sat Nov  2 22:55:58 UTC 2019

Modified Files:
src/sys/dev/spi: ssdfb_spi.c

Log Message:
add fdt device_compatible_entry


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/sys/dev/spi/ssdfb_spi.c

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

Modified files:

Index: src/sys/dev/spi/ssdfb_spi.c
diff -u src/sys/dev/spi/ssdfb_spi.c:1.2 src/sys/dev/spi/ssdfb_spi.c:1.3
--- src/sys/dev/spi/ssdfb_spi.c:1.2	Sat Nov  2 17:13:20 2019
+++ src/sys/dev/spi/ssdfb_spi.c	Sat Nov  2 22:55:57 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: ssdfb_spi.c,v 1.2 2019/11/02 17:13:20 tnn Exp $ */
+/* $NetBSD: ssdfb_spi.c,v 1.3 2019/11/02 22:55:57 tnn Exp $ */
 
 /*
  * Copyright (c) 2019 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ssdfb_spi.c,v 1.2 2019/11/02 17:13:20 tnn Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ssdfb_spi.c,v 1.3 2019/11/02 22:55:57 tnn Exp $");
 
 #include 
 #include 
@@ -73,18 +73,28 @@ static void	ssdfb_bitstream_final(struct
 CFATTACH_DECL_NEW(ssdfb_spi, sizeof(struct ssdfb_spi_softc),
 ssdfb_spi_match, ssdfb_spi_attach, NULL, NULL);
 
+static const struct device_compatible_entry compat_data[] = {
+	{ "solomon,ssd1322",	0 },
+	{ NULL,			0 }
+};
+
 static int
 ssdfb_spi_match(device_t parent, cfdata_t match, void *aux)
 {
 	struct spi_attach_args *sa = aux;
+	int res;
+
+	res = spi_compatible_match(sa, match, compat_data);
+	if (!res)
+		return res;
 
 	/*
 	 * SSD1306 and SSD1322 data sheets specify 100ns cycle time.
 	 */
 	if (spi_configure(sa->sa_handle, SPI_MODE_0, 1000))
-		return 0;
+		res = 0;
 
-	return 1;
+	return res;
 }
 
 static void



CVS commit: src/sys/dev/spi

2019-11-02 Thread Tobias Nygren
Module Name:src
Committed By:   tnn
Date:   Sat Nov  2 22:55:58 UTC 2019

Modified Files:
src/sys/dev/spi: ssdfb_spi.c

Log Message:
add fdt device_compatible_entry


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/sys/dev/spi/ssdfb_spi.c

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



CVS commit: src/sys/dev/spi

2019-11-02 Thread Tobias Nygren
Module Name:src
Committed By:   tnn
Date:   Sat Nov  2 14:33:27 UTC 2019

Modified Files:
src/sys/dev/spi: files.spi
Added Files:
src/sys/dev/spi: ssdfb_spi.c

Log Message:
add spi(4) bus frontend for ssdfb(4)


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/sys/dev/spi/files.spi
cvs rdiff -u -r0 -r1.1 src/sys/dev/spi/ssdfb_spi.c

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



CVS commit: src/sys/dev/spi

2019-11-02 Thread Tobias Nygren
Module Name:src
Committed By:   tnn
Date:   Sat Nov  2 14:33:27 UTC 2019

Modified Files:
src/sys/dev/spi: files.spi
Added Files:
src/sys/dev/spi: ssdfb_spi.c

Log Message:
add spi(4) bus frontend for ssdfb(4)


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/sys/dev/spi/files.spi
cvs rdiff -u -r0 -r1.1 src/sys/dev/spi/ssdfb_spi.c

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

Modified files:

Index: src/sys/dev/spi/files.spi
diff -u src/sys/dev/spi/files.spi:1.6 src/sys/dev/spi/files.spi:1.7
--- src/sys/dev/spi/files.spi:1.6	Mon Aug  5 23:42:48 2019
+++ src/sys/dev/spi/files.spi	Sat Nov  2 14:33:27 2019
@@ -1,4 +1,4 @@
-#	$NetBSD: files.spi,v 1.6 2019/08/05 23:42:48 tnn Exp $
+#	$NetBSD: files.spi,v 1.7 2019/11/02 14:33:27 tnn Exp $
 
 define	spibus { }
 
@@ -36,6 +36,10 @@ device	mcp23s17gpio: gpiobus
 attach	mcp23s17gpio at spi
 file	dev/spi/mcp23s17.c		mcp23s17gpio
 
+# Solomon Systech SSD13xx PLED/OLED display
+attach	ssdfb at spi with ssdfb_spi
+file	dev/spi/ssdfb_spi.c		ssdfb_spi
+
 # MCP3x0x ADC
 device	mcp3kadc: sysmon_envsys
 attach	mcp3kadc at spi

Added files:

Index: src/sys/dev/spi/ssdfb_spi.c
diff -u /dev/null src/sys/dev/spi/ssdfb_spi.c:1.1
--- /dev/null	Sat Nov  2 14:33:27 2019
+++ src/sys/dev/spi/ssdfb_spi.c	Sat Nov  2 14:33:27 2019
@@ -0,0 +1,339 @@
+/* $NetBSD: ssdfb_spi.c,v 1.1 2019/11/02 14:33:27 tnn Exp $ */
+
+/*
+ * Copyright (c) 2019 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Tobias Nygren.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *notice, this list of conditions and the following disclaimer in the
+ *documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include 
+__KERNEL_RCSID(0, "$NetBSD: ssdfb_spi.c,v 1.1 2019/11/02 14:33:27 tnn Exp $");
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+struct bs_state {
+	uint8_t	*base;
+	uint8_t	*cur;
+	uint8_t	mask;
+};
+
+struct ssdfb_spi_softc {
+	struct ssdfb_softc	sc;
+	struct spi_handle	*sc_sh;
+	bool			sc_3wiremode;
+};
+
+static int	ssdfb_spi_match(device_t, cfdata_t, void *);
+static void	ssdfb_spi_attach(device_t, device_t, void *);
+
+static int	ssdfb_spi_cmd_3wire(void *, uint8_t *, size_t, bool);
+static int	ssdfb_spi_xfer_rect_3wire_ssd1322(void *, uint8_t, uint8_t,
+		uint8_t, uint8_t, uint8_t *, size_t, bool);
+
+static int	ssdfb_spi_cmd_4wire(void *, uint8_t *, size_t, bool);
+static int	ssdfb_spi_xfer_rect_4wire_ssd1322(void *, uint8_t, uint8_t,
+		uint8_t, uint8_t, uint8_t *, size_t, bool);
+
+static void	ssdfb_bitstream_init(struct bs_state *, uint8_t *);
+static void	ssdfb_bitstream_append(struct bs_state *, uint8_t, uint8_t);
+static void	ssdfb_bitstream_append_cmd(struct bs_state *, uint8_t);
+static void	ssdfb_bitstream_append_data(struct bs_state *, uint8_t *,
+		size_t);
+static void	ssdfb_bitstream_final(struct bs_state *);
+
+CFATTACH_DECL_NEW(ssdfb_spi, sizeof(struct ssdfb_spi_softc),
+ssdfb_spi_match, ssdfb_spi_attach, NULL, NULL);
+
+static int
+ssdfb_spi_match(device_t parent, cfdata_t match, void *aux)
+{
+	struct spi_attach_args *sa = aux;
+
+	/*
+	 * SSD1306 and SSD1322 data sheets specify 100ns cycle time.
+	 */
+	if (spi_configure(sa->sa_handle, SPI_MODE_0, 1000))
+		return 0;
+
+	return 1;
+}
+
+static void
+ssdfb_spi_attach(device_t parent, device_t self, void *aux)
+{
+	struct ssdfb_spi_softc *sc = device_private(self);
+	struct cfdata *cf = device_cfdata(self);
+	struct spi_attach_args *sa = aux;
+	int flags = cf->cf_flags;
+
+	sc->sc.sc_dev = self;
+	sc->sc_sh = sa->sa_handle;
+	sc->sc.sc_cookie = (void *)sc;
+	if ((flags & SSDFB_ATTACH_FLAG_PRODUCT_MASK) == SSDFB_PRODUCT_UNKNOWN)
+		flags |= 

CVS commit: src/sys/dev/spi

2019-09-14 Thread Tobias Nygren
Module Name:src
Committed By:   tnn
Date:   Sat Sep 14 15:12:12 UTC 2019

Modified Files:
src/sys/dev/spi: m25p.c spiflash.c

Log Message:
On second thought revert that. Let's open this can of worms some other day.


To generate a diff of this commit:
cvs rdiff -u -r1.13 -r1.14 src/sys/dev/spi/m25p.c
cvs rdiff -u -r1.22 -r1.23 src/sys/dev/spi/spiflash.c

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



CVS commit: src/sys/dev/spi

2019-09-14 Thread Tobias Nygren
Module Name:src
Committed By:   tnn
Date:   Sat Sep 14 15:12:12 UTC 2019

Modified Files:
src/sys/dev/spi: m25p.c spiflash.c

Log Message:
On second thought revert that. Let's open this can of worms some other day.


To generate a diff of this commit:
cvs rdiff -u -r1.13 -r1.14 src/sys/dev/spi/m25p.c
cvs rdiff -u -r1.22 -r1.23 src/sys/dev/spi/spiflash.c

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

Modified files:

Index: src/sys/dev/spi/m25p.c
diff -u src/sys/dev/spi/m25p.c:1.13 src/sys/dev/spi/m25p.c:1.14
--- src/sys/dev/spi/m25p.c:1.13	Sat Sep 14 14:41:23 2019
+++ src/sys/dev/spi/m25p.c	Sat Sep 14 15:12:12 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: m25p.c,v 1.13 2019/09/14 14:41:23 tnn Exp $ */
+/* $NetBSD: m25p.c,v 1.14 2019/09/14 15:12:12 tnn Exp $ */
 
 /*-
  * Copyright (c) 2006 Urbana-Champaign Independent Media Center.
@@ -42,7 +42,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: m25p.c,v 1.13 2019/09/14 14:41:23 tnn Exp $");
+__KERNEL_RCSID(0, "$NetBSD: m25p.c,v 1.14 2019/09/14 15:12:12 tnn Exp $");
 
 #include 
 #include 
@@ -88,8 +88,8 @@ static const struct m25p_info {
 	uint8_t		mfgid;
 	uint16_t	devid;
 	const char	*name;
-	uint16_t	size;	/* in kB */
-	uint16_t	sector;	/* in kB */
+	uint16_t	size;	/* in KB */
+	uint16_t	sector;	/* in KB */
 	uint16_t	mhz;
 } m25p_infos[] = {
 	{ 0x16, 0x20, 0x2017, "STMicro M25P64", 8192, 64 },	/* 64Mbit */

Index: src/sys/dev/spi/spiflash.c
diff -u src/sys/dev/spi/spiflash.c:1.22 src/sys/dev/spi/spiflash.c:1.23
--- src/sys/dev/spi/spiflash.c:1.22	Sat Sep 14 14:41:23 2019
+++ src/sys/dev/spi/spiflash.c	Sat Sep 14 15:12:12 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: spiflash.c,v 1.22 2019/09/14 14:41:23 tnn Exp $ */
+/* $NetBSD: spiflash.c,v 1.23 2019/09/14 15:12:12 tnn Exp $ */
 
 /*-
  * Copyright (c) 2006 Urbana-Champaign Independent Media Center.
@@ -42,7 +42,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: spiflash.c,v 1.22 2019/09/14 14:41:23 tnn Exp $");
+__KERNEL_RCSID(0, "$NetBSD: spiflash.c,v 1.23 2019/09/14 15:12:12 tnn Exp $");
 
 #include 
 #include 
@@ -224,7 +224,7 @@ spiflash_attach(device_t parent, device_
 	aprint_naive(": SPI flash\n");
 	aprint_normal(": %s SPI flash\n", sc->sc_name);
 	/* XXX: note that this has to change for boot-sectored flash */
-	aprint_normal_dev(self, "%d kB, %d sectors of %d kB each\n",
+	aprint_normal_dev(self, "%d KB, %d sectors of %d KB each\n",
 	sc->sc_device_size / 1024,
 	sc->sc_device_size / sc->sc_erase_size,
 	sc->sc_erase_size / 1024);



CVS commit: src/sys/dev/spi

2019-09-14 Thread Tobias Nygren
Module Name:src
Committed By:   tnn
Date:   Sat Sep 14 14:41:23 UTC 2019

Modified Files:
src/sys/dev/spi: m25p.c spiflash.c

Log Message:
KB -> kB


To generate a diff of this commit:
cvs rdiff -u -r1.12 -r1.13 src/sys/dev/spi/m25p.c
cvs rdiff -u -r1.21 -r1.22 src/sys/dev/spi/spiflash.c

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



CVS commit: src/sys/dev/spi

2019-09-14 Thread Tobias Nygren
Module Name:src
Committed By:   tnn
Date:   Sat Sep 14 14:41:23 UTC 2019

Modified Files:
src/sys/dev/spi: m25p.c spiflash.c

Log Message:
KB -> kB


To generate a diff of this commit:
cvs rdiff -u -r1.12 -r1.13 src/sys/dev/spi/m25p.c
cvs rdiff -u -r1.21 -r1.22 src/sys/dev/spi/spiflash.c

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

Modified files:

Index: src/sys/dev/spi/m25p.c
diff -u src/sys/dev/spi/m25p.c:1.12 src/sys/dev/spi/m25p.c:1.13
--- src/sys/dev/spi/m25p.c:1.12	Thu Sep  5 16:17:48 2019
+++ src/sys/dev/spi/m25p.c	Sat Sep 14 14:41:23 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: m25p.c,v 1.12 2019/09/05 16:17:48 bouyer Exp $ */
+/* $NetBSD: m25p.c,v 1.13 2019/09/14 14:41:23 tnn Exp $ */
 
 /*-
  * Copyright (c) 2006 Urbana-Champaign Independent Media Center.
@@ -42,7 +42,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: m25p.c,v 1.12 2019/09/05 16:17:48 bouyer Exp $");
+__KERNEL_RCSID(0, "$NetBSD: m25p.c,v 1.13 2019/09/14 14:41:23 tnn Exp $");
 
 #include 
 #include 
@@ -88,8 +88,8 @@ static const struct m25p_info {
 	uint8_t		mfgid;
 	uint16_t	devid;
 	const char	*name;
-	uint16_t	size;	/* in KB */
-	uint16_t	sector;	/* in KB */
+	uint16_t	size;	/* in kB */
+	uint16_t	sector;	/* in kB */
 	uint16_t	mhz;
 } m25p_infos[] = {
 	{ 0x16, 0x20, 0x2017, "STMicro M25P64", 8192, 64 },	/* 64Mbit */

Index: src/sys/dev/spi/spiflash.c
diff -u src/sys/dev/spi/spiflash.c:1.21 src/sys/dev/spi/spiflash.c:1.22
--- src/sys/dev/spi/spiflash.c:1.21	Mon Sep  3 16:29:33 2018
+++ src/sys/dev/spi/spiflash.c	Sat Sep 14 14:41:23 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: spiflash.c,v 1.21 2018/09/03 16:29:33 riastradh Exp $ */
+/* $NetBSD: spiflash.c,v 1.22 2019/09/14 14:41:23 tnn Exp $ */
 
 /*-
  * Copyright (c) 2006 Urbana-Champaign Independent Media Center.
@@ -42,7 +42,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: spiflash.c,v 1.21 2018/09/03 16:29:33 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: spiflash.c,v 1.22 2019/09/14 14:41:23 tnn Exp $");
 
 #include 
 #include 
@@ -224,7 +224,7 @@ spiflash_attach(device_t parent, device_
 	aprint_naive(": SPI flash\n");
 	aprint_normal(": %s SPI flash\n", sc->sc_name);
 	/* XXX: note that this has to change for boot-sectored flash */
-	aprint_normal_dev(self, "%d KB, %d sectors of %d KB each\n",
+	aprint_normal_dev(self, "%d kB, %d sectors of %d kB each\n",
 	sc->sc_device_size / 1024,
 	sc->sc_device_size / sc->sc_erase_size,
 	sc->sc_erase_size / 1024);



CVS commit: src/sys/dev/spi

2019-09-05 Thread Manuel Bouyer
Module Name:src
Committed By:   bouyer
Date:   Thu Sep  5 16:17:48 UTC 2019

Modified Files:
src/sys/dev/spi: m25p.c

Log Message:
Add support for Winbond W25Q128.V (128mb) chips, as found on newer lime2-emmc
boards.
While there fix a missing \n in dmesg.


To generate a diff of this commit:
cvs rdiff -u -r1.11 -r1.12 src/sys/dev/spi/m25p.c

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

Modified files:

Index: src/sys/dev/spi/m25p.c
diff -u src/sys/dev/spi/m25p.c:1.11 src/sys/dev/spi/m25p.c:1.12
--- src/sys/dev/spi/m25p.c:1.11	Tue Aug 13 17:11:32 2019
+++ src/sys/dev/spi/m25p.c	Thu Sep  5 16:17:48 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: m25p.c,v 1.11 2019/08/13 17:11:32 tnn Exp $ */
+/* $NetBSD: m25p.c,v 1.12 2019/09/05 16:17:48 bouyer Exp $ */
 
 /*-
  * Copyright (c) 2006 Urbana-Champaign Independent Media Center.
@@ -42,7 +42,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: m25p.c,v 1.11 2019/08/13 17:11:32 tnn Exp $");
+__KERNEL_RCSID(0, "$NetBSD: m25p.c,v 1.12 2019/09/05 16:17:48 bouyer Exp $");
 
 #include 
 #include 
@@ -110,6 +110,7 @@ static const struct m25p_info {
 	{ 0x13, 0xEF, 0x4014, "Winbond W25Q80.V", 1024, 64 },	/* 8Mbit */
 	{ 0x14, 0xEF, 0x4015, "Winbond W25Q16.V", 2048, 64 },	/* 16Mbit */
 	{ 0x15, 0xEF, 0x4016, "Winbond W25Q32.V", 4096, 64 },	/* 32Mbit */
+	{ 0x15, 0xEF, 0x4018, "Winbond W25Q128.V", 16384, 64 },	/* 128Mbit */
 	{ 0x15, 0xEF, 0x6016, "Winbond W25Q32.W", 4096, 64 },	/* 32Mbit */
 	{ 0 }
 };
@@ -144,6 +145,9 @@ m25p_attach(device_t parent, device_t se
 
 	sc->sc_sh = sa->sa_handle;
 
+	aprint_normal("\n");
+	aprint_naive("\n");
+
 	config_interrupts(self, m25p_doattach);
 }
 



CVS commit: src/sys/dev/spi

2019-09-05 Thread Manuel Bouyer
Module Name:src
Committed By:   bouyer
Date:   Thu Sep  5 16:17:48 UTC 2019

Modified Files:
src/sys/dev/spi: m25p.c

Log Message:
Add support for Winbond W25Q128.V (128mb) chips, as found on newer lime2-emmc
boards.
While there fix a missing \n in dmesg.


To generate a diff of this commit:
cvs rdiff -u -r1.11 -r1.12 src/sys/dev/spi/m25p.c

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



CVS commit: src/sys/dev/spi

2019-08-21 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Wed Aug 21 08:03:22 UTC 2019

Modified Files:
src/sys/dev/spi: oj6sh.c

Log Message:
Make this at least compile - I have no way to test.


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/sys/dev/spi/oj6sh.c

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



CVS commit: src/sys/dev/spi

2019-08-21 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Wed Aug 21 08:03:22 UTC 2019

Modified Files:
src/sys/dev/spi: oj6sh.c

Log Message:
Make this at least compile - I have no way to test.


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/sys/dev/spi/oj6sh.c

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

Modified files:

Index: src/sys/dev/spi/oj6sh.c
diff -u src/sys/dev/spi/oj6sh.c:1.4 src/sys/dev/spi/oj6sh.c:1.5
--- src/sys/dev/spi/oj6sh.c:1.4	Mon Aug 19 10:56:33 2019
+++ src/sys/dev/spi/oj6sh.c	Wed Aug 21 08:03:22 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: oj6sh.c,v 1.4 2019/08/19 10:56:33 hkenken Exp $	*/
+/*	$NetBSD: oj6sh.c,v 1.5 2019/08/21 08:03:22 martin Exp $	*/
 
 /*
  * Copyright (c) 2014  Genetec Corporation.  All rights reserved.
@@ -31,7 +31,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: oj6sh.c,v 1.4 2019/08/19 10:56:33 hkenken Exp $");
+__KERNEL_RCSID(0, "$NetBSD: oj6sh.c,v 1.5 2019/08/21 08:03:22 martin Exp $");
 
 #include "opt_oj6sh.h"
 
@@ -126,12 +126,17 @@ static const struct wsmouse_accessops oj
 	.disable = oj6sh_disable
 };
 
+static const struct device_compatible_entry compat_data[] = {
+	{ "oj6sh",	0 },
+	{ NULL,		0 }
+};
+
 static int
 oj6sh_match(device_t parent, cfdata_t cf, void *aux)
 {
 	struct spi_attach_args *sa = aux;
 
-	if (strcmp(match->cf_name, "oj6sh"))
+	if (spi_compatible_match(sa, cf, compat_data) == 0)
 		return 0;
 	if (spi_configure(sa->sa_handle, SPI_MODE_0, 250))
 		return 0;



CVS commit: src/sys/dev/spi

2019-08-19 Thread Kenichi Hashimoto
Module Name:src
Committed By:   hkenken
Date:   Mon Aug 19 10:56:33 UTC 2019

Modified Files:
src/sys/dev/spi: oj6sh.c

Log Message:
Fix typo.


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/sys/dev/spi/oj6sh.c

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

Modified files:

Index: src/sys/dev/spi/oj6sh.c
diff -u src/sys/dev/spi/oj6sh.c:1.3 src/sys/dev/spi/oj6sh.c:1.4
--- src/sys/dev/spi/oj6sh.c:1.3	Thu Jul  4 11:13:26 2019
+++ src/sys/dev/spi/oj6sh.c	Mon Aug 19 10:56:33 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: oj6sh.c,v 1.3 2019/07/04 11:13:26 hkenken Exp $	*/
+/*	$NetBSD: oj6sh.c,v 1.4 2019/08/19 10:56:33 hkenken Exp $	*/
 
 /*
  * Copyright (c) 2014  Genetec Corporation.  All rights reserved.
@@ -31,7 +31,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: oj6sh.c,v 1.3 2019/07/04 11:13:26 hkenken Exp $");
+__KERNEL_RCSID(0, "$NetBSD: oj6sh.c,v 1.4 2019/08/19 10:56:33 hkenken Exp $");
 
 #include "opt_oj6sh.h"
 
@@ -127,7 +127,7 @@ static const struct wsmouse_accessops oj
 };
 
 static int
-oj6sh_match(device_t parent, cfdata_t match, void *aux)
+oj6sh_match(device_t parent, cfdata_t cf, void *aux)
 {
 	struct spi_attach_args *sa = aux;
 
@@ -180,6 +180,7 @@ oj6sh_attach(device_t parent, device_t s
 	struct spi_attach_args *sa = aux;
 	struct wsmousedev_attach_args a;
 
+	aprint_naive("\n");
 	aprint_normal(": OJ6SH-T25 Optical Joystick\n");
 
 	mutex_init(>sc_lock, MUTEX_DEFAULT, IPL_NONE);
@@ -229,7 +230,7 @@ oj6sh_cb(struct work *wk, void *arg)
 	DPRINTF(3,("%s: x = %d, y = %d\n", device_xname(sc->sc_dev),
 		delta.x, delta.y));
 
-#if defined(J6SH_DOWN_Y_LEFT_X)
+#if defined(OJ6SH_DOWN_Y_LEFT_X)
 	y = -delta.y;
 	x = -delta.x;
 #elif defined(OJ6SH_UP_X_LEFT_Y)



CVS commit: src/sys/dev/spi

2019-08-19 Thread Kenichi Hashimoto
Module Name:src
Committed By:   hkenken
Date:   Mon Aug 19 10:56:33 UTC 2019

Modified Files:
src/sys/dev/spi: oj6sh.c

Log Message:
Fix typo.


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/sys/dev/spi/oj6sh.c

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



CVS commit: src/sys/dev/spi

2019-08-13 Thread Tobias Nygren
Module Name:src
Committed By:   tnn
Date:   Tue Aug 13 17:11:32 UTC 2019

Modified Files:
src/sys/dev/spi: m25p.c

Log Message:
m25p: add compatible entry for "jedec,spi-nor" and match on it


To generate a diff of this commit:
cvs rdiff -u -r1.10 -r1.11 src/sys/dev/spi/m25p.c

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

Modified files:

Index: src/sys/dev/spi/m25p.c
diff -u src/sys/dev/spi/m25p.c:1.10 src/sys/dev/spi/m25p.c:1.11
--- src/sys/dev/spi/m25p.c:1.10	Sun Aug  4 22:13:24 2019
+++ src/sys/dev/spi/m25p.c	Tue Aug 13 17:11:32 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: m25p.c,v 1.10 2019/08/04 22:13:24 tnn Exp $ */
+/* $NetBSD: m25p.c,v 1.11 2019/08/13 17:11:32 tnn Exp $ */
 
 /*-
  * Copyright (c) 2006 Urbana-Champaign Independent Media Center.
@@ -42,7 +42,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: m25p.c,v 1.10 2019/08/04 22:13:24 tnn Exp $");
+__KERNEL_RCSID(0, "$NetBSD: m25p.c,v 1.11 2019/08/13 17:11:32 tnn Exp $");
 
 #include 
 #include 
@@ -114,16 +114,26 @@ static const struct m25p_info {
 	{ 0 }
 };
 
+static const struct device_compatible_entry compat_data[] = {
+	{ "jedec,spi-nor",	0 },
+	{ NULL,			0 }
+};
+
 static int
 m25p_match(device_t parent, cfdata_t cf, void *aux)
 {
 	struct spi_attach_args *sa = aux;
+	int res;
+
+	res = spi_compatible_match(sa, cf, compat_data);
+	if (!res)
+		return res;
 
 	/* configure for 20MHz, which is the max for normal reads */
 	if (spi_configure(sa->sa_handle, SPI_MODE_0, 2000))
-		return 0;
+		res = 0;
 
-	return 1;
+	return res;
 }
 
 static void



CVS commit: src/sys/dev/spi

2019-08-13 Thread Tobias Nygren
Module Name:src
Committed By:   tnn
Date:   Tue Aug 13 17:11:32 UTC 2019

Modified Files:
src/sys/dev/spi: m25p.c

Log Message:
m25p: add compatible entry for "jedec,spi-nor" and match on it


To generate a diff of this commit:
cvs rdiff -u -r1.10 -r1.11 src/sys/dev/spi/m25p.c

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



CVS commit: src/sys/dev/spi

2019-08-13 Thread Tobias Nygren
Module Name:src
Committed By:   tnn
Date:   Tue Aug 13 16:37:15 UTC 2019

Modified Files:
src/sys/dev/spi: spi.c spivar.h

Log Message:
spi: prepare for fdt direct attachment of spi slaves

Introduce sba_child_devices array in spibus_attach_args. If the parent has
populated sba_child_devices then attach them first. Then do any devices
devices the user has wired in the kernel config, if any.


To generate a diff of this commit:
cvs rdiff -u -r1.11 -r1.12 src/sys/dev/spi/spi.c
cvs rdiff -u -r1.7 -r1.8 src/sys/dev/spi/spivar.h

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



CVS commit: src/sys/dev/spi

2019-08-13 Thread Tobias Nygren
Module Name:src
Committed By:   tnn
Date:   Tue Aug 13 16:37:15 UTC 2019

Modified Files:
src/sys/dev/spi: spi.c spivar.h

Log Message:
spi: prepare for fdt direct attachment of spi slaves

Introduce sba_child_devices array in spibus_attach_args. If the parent has
populated sba_child_devices then attach them first. Then do any devices
devices the user has wired in the kernel config, if any.


To generate a diff of this commit:
cvs rdiff -u -r1.11 -r1.12 src/sys/dev/spi/spi.c
cvs rdiff -u -r1.7 -r1.8 src/sys/dev/spi/spivar.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/dev/spi/spi.c
diff -u src/sys/dev/spi/spi.c:1.11 src/sys/dev/spi/spi.c:1.12
--- src/sys/dev/spi/spi.c:1.11	Sat Mar  9 07:53:12 2019
+++ src/sys/dev/spi/spi.c	Tue Aug 13 16:37:15 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: spi.c,v 1.11 2019/03/09 07:53:12 mlelstv Exp $ */
+/* $NetBSD: spi.c,v 1.12 2019/08/13 16:37:15 tnn Exp $ */
 
 /*-
  * Copyright (c) 2006 Urbana-Champaign Independent Media Center.
@@ -42,7 +42,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: spi.c,v 1.11 2019/03/09 07:53:12 mlelstv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: spi.c,v 1.12 2019/08/13 16:37:15 tnn Exp $");
 
 #include "locators.h"
 
@@ -102,6 +102,8 @@ struct spi_handle {
 	int			sh_slave;
 	int			sh_mode;
 	int			sh_speed;
+	int			sh_flags;
+#define SPIH_ATTACHED		1
 };
 
 #define SPI_MAXDATA 4096
@@ -151,15 +153,123 @@ spi_search(device_t parent, cfdata_t cf,
 		return -1;
 	}
 
+	memset(, 0, sizeof sa);
 	sa.sa_handle = >sc_slaves[addr];
+	if (ISSET(sa.sa_handle->sh_flags, SPIH_ATTACHED))
+		return -1;
 
-	if (config_match(parent, cf, ) > 0)
+	if (config_match(parent, cf, ) > 0) {
+		SET(sa.sa_handle->sh_flags, SPIH_ATTACHED);
 		config_attach(parent, cf, , spi_print);
+	}
 
 	return 0;
 }
 
 /*
+ * XXX this is the same as i2c_fill_compat. It could be refactored into a
+ * common fill_compat function with pointers to compat & ncompat instead
+ * of attach_args as the first parameter.
+ */
+static void
+spi_fill_compat(struct spi_attach_args *sa, const char *compat, size_t len,
+	char **buffer)
+{
+	int count, i;
+	const char *c, *start, **ptr;
+
+	*buffer = NULL;
+	for (i = count = 0, c = compat; i < len; i++, c++)
+		if (*c == 0)
+			count++;
+	count += 2;
+	ptr = malloc(sizeof(char*)*count, M_TEMP, M_WAITOK);
+	if (!ptr)
+		return;
+
+	for (i = count = 0, start = c = compat; i < len; i++, c++) {
+		if (*c == 0) {
+			ptr[count++] = start;
+			start = c + 1;
+		}
+	}
+	if (start < compat + len) {
+		/* last string not 0 terminated */
+		size_t l = c - start;
+		*buffer = malloc(l + 1, M_TEMP, M_WAITOK);
+		memcpy(*buffer, start, l);
+		(*buffer)[l] = 0;
+		ptr[count++] = *buffer;
+	}
+	ptr[count] = NULL;
+
+	sa->sa_compat = ptr;
+	sa->sa_ncompat = count;
+}
+
+static void
+spi_direct_attach_child_devices(device_t parent, struct spi_softc *sc,
+prop_array_t child_devices)
+{
+	unsigned int count;
+	prop_dictionary_t child;
+	prop_data_t cdata;
+	uint32_t slave;
+	uint64_t cookie;
+	struct spi_attach_args sa;
+	int loc[SPICF_NLOCS];
+	char *buf;
+	int i;
+
+	memset(loc, 0, sizeof loc);
+	count = prop_array_count(child_devices);
+	for (i = 0; i < count; i++) {
+		child = prop_array_get(child_devices, i);
+		if (!child)
+			continue;
+		if (!prop_dictionary_get_uint32(child, "slave", ))
+			continue;
+		if(slave >= sc->sc_controller.sct_nslaves)
+			continue;
+		if (!prop_dictionary_get_uint64(child, "cookie", ))
+			continue;
+		if (!(cdata = prop_dictionary_get(child, "compatible")))
+			continue;
+		loc[SPICF_SLAVE] = slave;
+
+		memset(, 0, sizeof sa);
+		sa.sa_handle = >sc_slaves[i];
+		if (ISSET(sa.sa_handle->sh_flags, SPIH_ATTACHED))
+			continue;
+		SET(sa.sa_handle->sh_flags, SPIH_ATTACHED);
+
+		buf = NULL;
+		spi_fill_compat(,
+prop_data_data_nocopy(cdata),
+prop_data_size(cdata), );
+		(void) config_found_sm_loc(parent, "spi",
+	   loc, , spi_print,
+	   NULL);
+
+		if (sa.sa_compat)
+			free(sa.sa_compat, M_TEMP);
+		if (buf)
+			free(buf, M_TEMP);
+	}
+}
+
+int
+spi_compatible_match(const struct spi_attach_args *sa, const cfdata_t cf,
+		 const struct device_compatible_entry *compats)
+{
+	if (sa->sa_ncompat > 0)
+		return device_compatible_match(sa->sa_compat, sa->sa_ncompat,
+	   compats, NULL);
+
+	return 1;
+}
+
+/*
  * API for device drivers.
  *
  * We provide wrapper routines to decouple the ABI for the SPI
@@ -197,9 +307,11 @@ spi_attach(device_t parent, device_t sel
 		sc->sc_slaves[i].sh_controller = >sc_controller;
 	}
 
-	/*
-	 * Locate and attach child devices
-	 */
+	/* First attach devices known to be present via fdt */
+	if (sba->sba_child_devices) {
+		spi_direct_attach_child_devices(self, sc, sba->sba_child_devices);
+	}
+	/* Then do any other devices the user may have manually wired */
 	config_search_ia(spi_search, self, "spi", NULL);
 }
 

Index: src/sys/dev/spi/spivar.h
diff -u 

CVS commit: src/sys/dev/spi

2019-08-05 Thread Tobias Nygren
Module Name:src
Committed By:   tnn
Date:   Mon Aug  5 23:42:48 UTC 2019

Modified Files:
src/sys/dev/spi: files.spi

Log Message:
spi: make the "slave" config(5) locator optional

needed to be able to support FDT direct attachment of SPI slaves


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/sys/dev/spi/files.spi

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

Modified files:

Index: src/sys/dev/spi/files.spi
diff -u src/sys/dev/spi/files.spi:1.5 src/sys/dev/spi/files.spi:1.6
--- src/sys/dev/spi/files.spi:1.5	Tue Aug 18 15:54:20 2015
+++ src/sys/dev/spi/files.spi	Mon Aug  5 23:42:48 2019
@@ -1,8 +1,8 @@
-#	$NetBSD: files.spi,v 1.5 2015/08/18 15:54:20 phx Exp $
+#	$NetBSD: files.spi,v 1.6 2019/08/05 23:42:48 tnn Exp $
 
 define	spibus { }
 
-device	spi { slave }
+device	spi { [slave = -1] }
 attach	spi at spibus
 file	dev/spi/spi.c			spi | spibus
 



CVS commit: src/sys/dev/spi

2019-08-05 Thread Tobias Nygren
Module Name:src
Committed By:   tnn
Date:   Mon Aug  5 23:42:48 UTC 2019

Modified Files:
src/sys/dev/spi: files.spi

Log Message:
spi: make the "slave" config(5) locator optional

needed to be able to support FDT direct attachment of SPI slaves


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/sys/dev/spi/files.spi

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



CVS commit: src/sys/dev/spi

2019-08-04 Thread Tobias Nygren
Module Name:src
Committed By:   tnn
Date:   Sun Aug  4 22:13:24 UTC 2019

Modified Files:
src/sys/dev/spi: m25p.c

Log Message:
m25p: change devices recently added from 4kB "sector size" to 64kB ...

... even though it is wrong and these devices really use 4kB sector size.
Despite the struct member being named sector size it is actually used as
block size. Our spiflash driver doesn't issue sector erase commands.
Stopgap measure to fix data corruption until the driver is fixed.


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 src/sys/dev/spi/m25p.c

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



CVS commit: src/sys/dev/spi

2019-08-04 Thread Tobias Nygren
Module Name:src
Committed By:   tnn
Date:   Sun Aug  4 22:13:24 UTC 2019

Modified Files:
src/sys/dev/spi: m25p.c

Log Message:
m25p: change devices recently added from 4kB "sector size" to 64kB ...

... even though it is wrong and these devices really use 4kB sector size.
Despite the struct member being named sector size it is actually used as
block size. Our spiflash driver doesn't issue sector erase commands.
Stopgap measure to fix data corruption until the driver is fixed.


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 src/sys/dev/spi/m25p.c

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

Modified files:

Index: src/sys/dev/spi/m25p.c
diff -u src/sys/dev/spi/m25p.c:1.9 src/sys/dev/spi/m25p.c:1.10
--- src/sys/dev/spi/m25p.c:1.9	Sun Aug  4 20:49:54 2019
+++ src/sys/dev/spi/m25p.c	Sun Aug  4 22:13:24 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: m25p.c,v 1.9 2019/08/04 20:49:54 tnn Exp $ */
+/* $NetBSD: m25p.c,v 1.10 2019/08/04 22:13:24 tnn Exp $ */
 
 /*-
  * Copyright (c) 2006 Urbana-Champaign Independent Media Center.
@@ -42,7 +42,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: m25p.c,v 1.9 2019/08/04 20:49:54 tnn Exp $");
+__KERNEL_RCSID(0, "$NetBSD: m25p.c,v 1.10 2019/08/04 22:13:24 tnn Exp $");
 
 #include 
 #include 
@@ -98,15 +98,15 @@ static const struct m25p_info {
 	{ 0xc0, 0x20, 0x7117, "STMicro M25PX64", 8192, 64 },	/* 64Mbit */
 	{ 0x00, 0x20, 0xBB18, "Numonyx N25Q128", 16384, 64 },	/* 128Mbit */
 	{ 0x00, 0xBF, 0x2541, "Microchip SST25VF016B", 2048, 64 }, /* 16Mbit */
-	{ 0x00, 0xC2, 0x2011, "Macronix MX25L10", 128, 4 },	/* 1Mbit */
-	{ 0x00, 0xC2, 0x2012, "Macronix MX25L20", 256, 4 },	/* 2Mbit */
-	{ 0x00, 0xC2, 0x2013, "Macronix MX25L40", 512, 4 },	/* 4Mbit */
-	{ 0x00, 0xC2, 0x2014, "Macronix MX25L80", 1024, 4 },	/* 8Mbit */
-	{ 0x00, 0xC8, 0x4018, "GigaDevice 25Q127CSIG", 16384, 4 },	/* 128Mbit */
-	{ 0x00, 0xEF, 0x3011, "Winbond W25X10", 128, 4 },	/* 1Mbit */
-	{ 0x00, 0xEF, 0x3012, "Winbond W25X20", 256, 4 },	/* 2Mbit */
-	{ 0x00, 0xEF, 0x3013, "Winbond W25X40", 512, 4 },	/* 4Mbit */
-	{ 0x00, 0xEF, 0x3014, "Winbond W25X80", 1024, 4 },	/* 8Mbit */
+	{ 0x00, 0xC2, 0x2011, "Macronix MX25L10", 128, 64 },	/* 1Mbit */
+	{ 0x00, 0xC2, 0x2012, "Macronix MX25L20", 256, 64 },	/* 2Mbit */
+	{ 0x00, 0xC2, 0x2013, "Macronix MX25L40", 512, 64 },	/* 4Mbit */
+	{ 0x00, 0xC2, 0x2014, "Macronix MX25L80", 1024, 64 },	/* 8Mbit */
+	{ 0x00, 0xC8, 0x4018, "GigaDevice 25Q127CSIG", 16384, 64 },	/* 128Mbit */
+	{ 0x00, 0xEF, 0x3011, "Winbond W25X10", 128, 64 },	/* 1Mbit */
+	{ 0x00, 0xEF, 0x3012, "Winbond W25X20", 256, 64 },	/* 2Mbit */
+	{ 0x00, 0xEF, 0x3013, "Winbond W25X40", 512, 64 },	/* 4Mbit */
+	{ 0x00, 0xEF, 0x3014, "Winbond W25X80", 1024, 64 },	/* 8Mbit */
 	{ 0x13, 0xEF, 0x4014, "Winbond W25Q80.V", 1024, 64 },	/* 8Mbit */
 	{ 0x14, 0xEF, 0x4015, "Winbond W25Q16.V", 2048, 64 },	/* 16Mbit */
 	{ 0x15, 0xEF, 0x4016, "Winbond W25Q32.V", 4096, 64 },	/* 32Mbit */



CVS commit: src/sys/dev/spi

2019-08-04 Thread Tobias Nygren
Module Name:src
Committed By:   tnn
Date:   Sun Aug  4 20:49:54 UTC 2019

Modified Files:
src/sys/dev/spi: m25p.c

Log Message:
m25p: add GigaDevice 25Q127CSIG

(This is the boot ROM found on ROCKPro64.)


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/sys/dev/spi/m25p.c

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

Modified files:

Index: src/sys/dev/spi/m25p.c
diff -u src/sys/dev/spi/m25p.c:1.8 src/sys/dev/spi/m25p.c:1.9
--- src/sys/dev/spi/m25p.c:1.8	Sat Aug  3 02:22:06 2019
+++ src/sys/dev/spi/m25p.c	Sun Aug  4 20:49:54 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: m25p.c,v 1.8 2019/08/03 02:22:06 tnn Exp $ */
+/* $NetBSD: m25p.c,v 1.9 2019/08/04 20:49:54 tnn Exp $ */
 
 /*-
  * Copyright (c) 2006 Urbana-Champaign Independent Media Center.
@@ -42,7 +42,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: m25p.c,v 1.8 2019/08/03 02:22:06 tnn Exp $");
+__KERNEL_RCSID(0, "$NetBSD: m25p.c,v 1.9 2019/08/04 20:49:54 tnn Exp $");
 
 #include 
 #include 
@@ -102,6 +102,7 @@ static const struct m25p_info {
 	{ 0x00, 0xC2, 0x2012, "Macronix MX25L20", 256, 4 },	/* 2Mbit */
 	{ 0x00, 0xC2, 0x2013, "Macronix MX25L40", 512, 4 },	/* 4Mbit */
 	{ 0x00, 0xC2, 0x2014, "Macronix MX25L80", 1024, 4 },	/* 8Mbit */
+	{ 0x00, 0xC8, 0x4018, "GigaDevice 25Q127CSIG", 16384, 4 },	/* 128Mbit */
 	{ 0x00, 0xEF, 0x3011, "Winbond W25X10", 128, 4 },	/* 1Mbit */
 	{ 0x00, 0xEF, 0x3012, "Winbond W25X20", 256, 4 },	/* 2Mbit */
 	{ 0x00, 0xEF, 0x3013, "Winbond W25X40", 512, 4 },	/* 4Mbit */



CVS commit: src/sys/dev/spi

2019-08-04 Thread Tobias Nygren
Module Name:src
Committed By:   tnn
Date:   Sun Aug  4 20:49:54 UTC 2019

Modified Files:
src/sys/dev/spi: m25p.c

Log Message:
m25p: add GigaDevice 25Q127CSIG

(This is the boot ROM found on ROCKPro64.)


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/sys/dev/spi/m25p.c

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



CVS commit: src/sys/dev/spi

2019-08-02 Thread Tobias Nygren
Module Name:src
Committed By:   tnn
Date:   Sat Aug  3 02:22:06 UTC 2019

Modified Files:
src/sys/dev/spi: m25p.c

Log Message:
m25p: add some ~2010 vintage parts found in junk drawer


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/sys/dev/spi/m25p.c

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



CVS commit: src/sys/dev/spi

2019-08-02 Thread Tobias Nygren
Module Name:src
Committed By:   tnn
Date:   Sat Aug  3 02:22:06 UTC 2019

Modified Files:
src/sys/dev/spi: m25p.c

Log Message:
m25p: add some ~2010 vintage parts found in junk drawer


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/sys/dev/spi/m25p.c

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

Modified files:

Index: src/sys/dev/spi/m25p.c
diff -u src/sys/dev/spi/m25p.c:1.7 src/sys/dev/spi/m25p.c:1.8
--- src/sys/dev/spi/m25p.c:1.7	Sat Aug  3 00:46:02 2019
+++ src/sys/dev/spi/m25p.c	Sat Aug  3 02:22:06 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: m25p.c,v 1.7 2019/08/03 00:46:02 tnn Exp $ */
+/* $NetBSD: m25p.c,v 1.8 2019/08/03 02:22:06 tnn Exp $ */
 
 /*-
  * Copyright (c) 2006 Urbana-Champaign Independent Media Center.
@@ -42,7 +42,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: m25p.c,v 1.7 2019/08/03 00:46:02 tnn Exp $");
+__KERNEL_RCSID(0, "$NetBSD: m25p.c,v 1.8 2019/08/03 02:22:06 tnn Exp $");
 
 #include 
 #include 
@@ -94,10 +94,18 @@ static const struct m25p_info {
 } m25p_infos[] = {
 	{ 0x16, 0x20, 0x2017, "STMicro M25P64", 8192, 64 },	/* 64Mbit */
 	{ 0x14, 0x20, 0x2015, "STMicro M25P16", 2048, 64 },	/* 16Mbit */
-	{ 0x12,	0x20, 0x2013, "STMicro M25P40", 512, 64 },	/* 4Mbit */
+	{ 0x12, 0x20, 0x2013, "STMicro M25P40", 512, 64 },	/* 4Mbit */
 	{ 0xc0, 0x20, 0x7117, "STMicro M25PX64", 8192, 64 },	/* 64Mbit */
 	{ 0x00, 0x20, 0xBB18, "Numonyx N25Q128", 16384, 64 },	/* 128Mbit */
 	{ 0x00, 0xBF, 0x2541, "Microchip SST25VF016B", 2048, 64 }, /* 16Mbit */
+	{ 0x00, 0xC2, 0x2011, "Macronix MX25L10", 128, 4 },	/* 1Mbit */
+	{ 0x00, 0xC2, 0x2012, "Macronix MX25L20", 256, 4 },	/* 2Mbit */
+	{ 0x00, 0xC2, 0x2013, "Macronix MX25L40", 512, 4 },	/* 4Mbit */
+	{ 0x00, 0xC2, 0x2014, "Macronix MX25L80", 1024, 4 },	/* 8Mbit */
+	{ 0x00, 0xEF, 0x3011, "Winbond W25X10", 128, 4 },	/* 1Mbit */
+	{ 0x00, 0xEF, 0x3012, "Winbond W25X20", 256, 4 },	/* 2Mbit */
+	{ 0x00, 0xEF, 0x3013, "Winbond W25X40", 512, 4 },	/* 4Mbit */
+	{ 0x00, 0xEF, 0x3014, "Winbond W25X80", 1024, 4 },	/* 8Mbit */
 	{ 0x13, 0xEF, 0x4014, "Winbond W25Q80.V", 1024, 64 },	/* 8Mbit */
 	{ 0x14, 0xEF, 0x4015, "Winbond W25Q16.V", 2048, 64 },	/* 16Mbit */
 	{ 0x15, 0xEF, 0x4016, "Winbond W25Q32.V", 4096, 64 },	/* 32Mbit */



CVS commit: src/sys/dev/spi

2019-08-02 Thread Tobias Nygren
Module Name:src
Committed By:   tnn
Date:   Sat Aug  3 00:46:02 UTC 2019

Modified Files:
src/sys/dev/spi: m25p.c

Log Message:
m25p: print vendor & device id before bailing out on unknown devices


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/sys/dev/spi/m25p.c

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



CVS commit: src/sys/dev/spi

2019-08-02 Thread Tobias Nygren
Module Name:src
Committed By:   tnn
Date:   Sat Aug  3 00:46:02 UTC 2019

Modified Files:
src/sys/dev/spi: m25p.c

Log Message:
m25p: print vendor & device id before bailing out on unknown devices


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/sys/dev/spi/m25p.c

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

Modified files:

Index: src/sys/dev/spi/m25p.c
diff -u src/sys/dev/spi/m25p.c:1.6 src/sys/dev/spi/m25p.c:1.7
--- src/sys/dev/spi/m25p.c:1.6	Wed Jan 31 16:00:03 2018
+++ src/sys/dev/spi/m25p.c	Sat Aug  3 00:46:02 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: m25p.c,v 1.6 2018/01/31 16:00:03 jakllsch Exp $ */
+/* $NetBSD: m25p.c,v 1.7 2019/08/03 00:46:02 tnn Exp $ */
 
 /*-
  * Copyright (c) 2006 Urbana-Champaign Independent Media Center.
@@ -42,7 +42,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: m25p.c,v 1.6 2018/01/31 16:00:03 jakllsch Exp $");
+__KERNEL_RCSID(0, "$NetBSD: m25p.c,v 1.7 2019/08/03 00:46:02 tnn Exp $");
 
 #include 
 #include 
@@ -168,7 +168,8 @@ m25p_doattach(device_t self)
 	}
 
 	if (info->name == NULL) {
-		aprint_error(": unknown or unsupported device\n");
+		aprint_error(": vendor 0x%02X dev 0x%04X sig 0x%02X not supported\n",
+			 mfgid, devid, sig);
 		return;
 	}
 



CVS commit: src/sys/dev/spi

2019-07-04 Thread Kenichi Hashimoto
Module Name:src
Committed By:   hkenken
Date:   Thu Jul  4 11:13:26 UTC 2019

Modified Files:
src/sys/dev/spi: oj6sh.c

Log Message:
Avoid workqueue_check_duplication().


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/sys/dev/spi/oj6sh.c

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

Modified files:

Index: src/sys/dev/spi/oj6sh.c
diff -u src/sys/dev/spi/oj6sh.c:1.2 src/sys/dev/spi/oj6sh.c:1.3
--- src/sys/dev/spi/oj6sh.c:1.2	Mon Dec 14 10:31:38 2015
+++ src/sys/dev/spi/oj6sh.c	Thu Jul  4 11:13:26 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: oj6sh.c,v 1.2 2015/12/14 10:31:38 hkenken Exp $	*/
+/*	$NetBSD: oj6sh.c,v 1.3 2019/07/04 11:13:26 hkenken Exp $	*/
 
 /*
  * Copyright (c) 2014  Genetec Corporation.  All rights reserved.
@@ -31,7 +31,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: oj6sh.c,v 1.2 2015/12/14 10:31:38 hkenken Exp $");
+__KERNEL_RCSID(0, "$NetBSD: oj6sh.c,v 1.3 2019/07/04 11:13:26 hkenken Exp $");
 
 #include "opt_oj6sh.h"
 
@@ -205,13 +205,7 @@ static void
 oj6sh_poll(void *arg)
 {
 	struct oj6sh_softc *sc = (struct oj6sh_softc *)arg;
-
 	workqueue_enqueue(sc->sc_wq, >sc_wk, NULL);
-
-	if (sc->sc_enabled)
-		callout_reset(>sc_c, POLLRATE, oj6sh_poll, sc);
-
-	return;
 }
 
 static void
@@ -254,6 +248,9 @@ oj6sh_cb(struct work *wk, void *arg)
 	splx(s);
 out:
 	mutex_exit(>sc_lock);
+
+	if (sc->sc_enabled)
+		callout_reset(>sc_c, POLLRATE, oj6sh_poll, sc);
 }
 
 static uint8_t



CVS commit: src/sys/dev/spi

2019-07-04 Thread Kenichi Hashimoto
Module Name:src
Committed By:   hkenken
Date:   Thu Jul  4 11:13:26 UTC 2019

Modified Files:
src/sys/dev/spi: oj6sh.c

Log Message:
Avoid workqueue_check_duplication().


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/sys/dev/spi/oj6sh.c

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