Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/thorpej-i2c-spi-conf]: src/sys/dev/spi match/probe routines should not h...
details: https://anonhg.NetBSD.org/src/rev/f8d362083198
branches: thorpej-i2c-spi-conf
changeset: 378801:f8d362083198
user: thorpej <thorpej%NetBSD.org@localhost>
date: Wed May 19 03:46:26 2021 +0000
description:
match/probe routines should not have side-effects; call spi_configure()
from the attach routine.
diffstat:
sys/dev/spi/m25p.c | 24 ++++++++++++------------
sys/dev/spi/mcp23s17.c | 23 ++++++++++++-----------
sys/dev/spi/mcp3k.c | 16 ++++++++++------
sys/dev/spi/mcp48x1.c | 17 +++++++++++------
sys/dev/spi/oj6sh.c | 14 ++++++++++----
sys/dev/spi/ssdfb_spi.c | 29 +++++++++++++++--------------
sys/dev/spi/tmp121.c | 23 ++++++++++++-----------
7 files changed, 82 insertions(+), 64 deletions(-)
diffs (truncated from 380 to 300 lines):
diff -r e7a0058553c7 -r f8d362083198 sys/dev/spi/m25p.c
--- a/sys/dev/spi/m25p.c Wed May 19 03:34:11 2021 +0000
+++ b/sys/dev/spi/m25p.c Wed May 19 03:46:26 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: m25p.c,v 1.17 2021/01/27 02:32:31 thorpej Exp $ */
+/* $NetBSD: m25p.c,v 1.17.4.1 2021/05/19 03:46:26 thorpej Exp $ */
/*-
* Copyright (c) 2006 Urbana-Champaign Independent Media Center.
@@ -42,7 +42,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: m25p.c,v 1.17 2021/01/27 02:32:31 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: m25p.c,v 1.17.4.1 2021/05/19 03:46:26 thorpej Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -125,17 +125,8 @@ 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, 20000000))
- res = 0;
-
- return res;
+ return spi_compatible_match(sa, cf, compat_data);
}
static void
@@ -143,12 +134,21 @@ m25p_attach(device_t parent, device_t se
{
struct m25p_softc *sc = device_private(self);
struct spi_attach_args *sa = aux;
+ int error;
sc->sc_sh = sa->sa_handle;
aprint_normal("\n");
aprint_naive("\n");
+ /* configure for 20MHz, which is the max for normal reads */
+ error = spi_configure(sa->sa_handle, SPI_MODE_0, 20000000);
+ if (error) {
+ aprint_error_dev(self, "spi_configure failed (error = %d)\n",
+ error);
+ return;
+ }
+
config_interrupts(self, m25p_doattach);
}
diff -r e7a0058553c7 -r f8d362083198 sys/dev/spi/mcp23s17.c
--- a/sys/dev/spi/mcp23s17.c Wed May 19 03:34:11 2021 +0000
+++ b/sys/dev/spi/mcp23s17.c Wed May 19 03:46:26 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: mcp23s17.c,v 1.2.2.1 2021/05/19 03:32:27 thorpej Exp $ */
+/* $NetBSD: mcp23s17.c,v 1.2.2.2 2021/05/19 03:46:26 thorpej Exp $ */
/*-
* Copyright (c) 2014 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: mcp23s17.c,v 1.2.2.1 2021/05/19 03:32:27 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: mcp23s17.c,v 1.2.2.2 2021/05/19 03:46:26 thorpej Exp $");
/*
* Driver for Microchip MCP23S17 GPIO
@@ -105,16 +105,8 @@ static int
mcp23s17gpio_match(device_t parent, cfdata_t cf, void *aux)
{
struct spi_attach_args *sa = aux;
- int rv;
- rv = spi_compatible_match(sa, cf, compat_data);
- if (rv != 0) {
- /* run at 10MHz */
- if (spi_configure(sa->sa_handle, SPI_MODE_0, 10000000))
- return 0;
- }
-
- return rv;
+ return spi_compatible_match(sa, cf, compat_data);
}
static void
@@ -122,6 +114,7 @@ mcp23s17gpio_attach(device_t parent, dev
{
struct mcp23s17gpio_softc *sc;
struct spi_attach_args *sa;
+ int error;
#if NGPIO > 0
int i;
struct gpiobus_attach_args gba;
@@ -142,6 +135,14 @@ mcp23s17gpio_attach(device_t parent, dev
aprint_naive(": GPIO\n");
aprint_normal(": MCP23S17 GPIO (ha=%d)\n", sc->sc_ha);
+ /* run at 10MHz */
+ error = spi_configure(sa->sa_handle, SPI_MODE_0, 10000000);
+ if (error) {
+ aprint_error_dev(self, "spi_configure failed (error = %d)\n",
+ error);
+ return;
+ }
+
DPRINTF(1, ("%s: initialize (HAEN|SEQOP)\n", device_xname(sc->sc_dev)));
/* basic setup */
diff -r e7a0058553c7 -r f8d362083198 sys/dev/spi/mcp3k.c
--- a/sys/dev/spi/mcp3k.c Wed May 19 03:34:11 2021 +0000
+++ b/sys/dev/spi/mcp3k.c Wed May 19 03:46:26 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: mcp3k.c,v 1.2.36.1 2021/05/19 03:33:05 thorpej Exp $ */
+/* $NetBSD: mcp3k.c,v 1.2.36.2 2021/05/19 03:46:26 thorpej Exp $ */
/*-
* Copyright (c) 2015 The NetBSD Foundation, Inc.
@@ -242,10 +242,6 @@ mcp3kadc_match(device_t parent, cfdata_t
if (sa->sa_clist == NULL && mcp3kadc_lookup(sa, cf) == NULL) {
return 0;
}
-
- /* configure for 1MHz */
- if (spi_configure(sa->sa_handle, SPI_MODE_0, 1000000))
- return 0;
}
return rv;
@@ -258,7 +254,7 @@ mcp3kadc_attach(device_t parent, device_
struct spi_attach_args *sa = aux;
struct mcp3kadc_softc *sc = device_private(self);
const struct mcp3kadc_model *model;
- int ch, i;
+ int ch, i, error;
sc->sc_dev = self;
sc->sc_sh = sa->sa_handle;
@@ -273,6 +269,14 @@ mcp3kadc_attach(device_t parent, device_
(unsigned)model->name, (unsigned)model->channels,
(unsigned)model->bits);
+ /* configure for 1MHz */
+ error = spi_configure(sa->sa_handle, SPI_MODE_0, 1000000);
+ if (error) {
+ aprint_error_dev(self, "spi_configure failed (error = %d)\n",
+ error);
+ return;
+ }
+
/*
* XXX Get vref-supply from device tree and make the sysctl
* XXX read-only in that case.
diff -r e7a0058553c7 -r f8d362083198 sys/dev/spi/mcp48x1.c
--- a/sys/dev/spi/mcp48x1.c Wed May 19 03:34:11 2021 +0000
+++ b/sys/dev/spi/mcp48x1.c Wed May 19 03:46:26 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: mcp48x1.c,v 1.1.54.1 2021/05/19 03:33:33 thorpej Exp $ */
+/* $NetBSD: mcp48x1.c,v 1.1.54.2 2021/05/19 03:46:26 thorpej Exp $ */
/*-
* Copyright (c) 2014 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: mcp48x1.c,v 1.1.54.1 2021/05/19 03:33:33 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: mcp48x1.c,v 1.1.54.2 2021/05/19 03:46:26 thorpej Exp $");
/*
* Driver for Microchip MCP4801/MCP4811/MCP4821 DAC.
@@ -158,10 +158,6 @@ mcp48x1dac_match(device_t parent, cfdata
if (sa->sa_clist == NULL && mcp48x1dac_lookup(sa, cf) == NULL) {
return 0;
}
-
- /* configure for 20MHz */
- if (spi_configure(sa->sa_handle, SPI_MODE_0, 20000000))
- return 0;
}
return rv;
@@ -173,6 +169,7 @@ mcp48x1dac_attach(device_t parent, devic
struct mcp48x1dac_softc *sc = device_private(self);
struct spi_attach_args *sa = aux;
const struct mcp48x1dac_model *model;
+ int error;
sc->sc_dev = self;
sc->sc_sh = sa->sa_handle;
@@ -185,6 +182,14 @@ mcp48x1dac_attach(device_t parent, devic
aprint_naive(": Digital to Analog converter\n");
aprint_normal(": MCP%u DAC\n", model->name);
+ /* configure for 20MHz */
+ error = spi_configure(sa->sa_handle, SPI_MODE_0, 20000000);
+ if (error) {
+ aprint_error_dev(self, "spi_configure failed (error = %d)\n",
+ error);
+ return;
+ }
+
if(!mcp48x1dac_envsys_attach(sc)) {
aprint_error_dev(sc->sc_dev, "failed to attach envsys\n");
return;
diff -r e7a0058553c7 -r f8d362083198 sys/dev/spi/oj6sh.c
--- a/sys/dev/spi/oj6sh.c Wed May 19 03:34:11 2021 +0000
+++ b/sys/dev/spi/oj6sh.c Wed May 19 03:46:26 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: oj6sh.c,v 1.8 2021/04/24 23:36:59 thorpej Exp $ */
+/* $NetBSD: oj6sh.c,v 1.8.2.1 2021/05/19 03:46:26 thorpej Exp $ */
/*
* Copyright (c) 2014 Genetec Corporation. All rights reserved.
@@ -31,7 +31,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: oj6sh.c,v 1.8 2021/04/24 23:36:59 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: oj6sh.c,v 1.8.2.1 2021/05/19 03:46:26 thorpej Exp $");
#include "opt_oj6sh.h"
@@ -138,8 +138,6 @@ oj6sh_match(device_t parent, cfdata_t cf
if (spi_compatible_match(sa, cf, compat_data) == 0)
return 0;
- if (spi_configure(sa->sa_handle, SPI_MODE_0, 2500000))
- return 0;
return 2;
}
@@ -184,10 +182,18 @@ oj6sh_attach(device_t parent, device_t s
struct oj6sh_softc *sc = device_private(self);
struct spi_attach_args *sa = aux;
struct wsmousedev_attach_args a;
+ int errir;
aprint_naive("\n");
aprint_normal(": OJ6SH-T25 Optical Joystick\n");
+ error = spi_configure(sa->sa_handle, SPI_MODE_0, 2500000);
+ if (error) {
+ aprint_error_dev(self, "spi_configure failed (error = %d)\n",
+ error);
+ return;
+ }
+
mutex_init(&sc->sc_lock, MUTEX_DEFAULT, IPL_NONE);
sc->sc_dev = self;
diff -r e7a0058553c7 -r f8d362083198 sys/dev/spi/ssdfb_spi.c
--- a/sys/dev/spi/ssdfb_spi.c Wed May 19 03:34:11 2021 +0000
+++ b/sys/dev/spi/ssdfb_spi.c Wed May 19 03:46:26 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: ssdfb_spi.c,v 1.5 2021/01/27 02:32:31 thorpej Exp $ */
+/* $NetBSD: ssdfb_spi.c,v 1.5.4.1 2021/05/19 03:46:26 thorpej Exp $ */
/*
* Copyright (c) 2019 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ssdfb_spi.c,v 1.5 2021/01/27 02:32:31 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ssdfb_spi.c,v 1.5.4.1 2021/05/19 03:46:26 thorpej Exp $");
#include <sys/param.h>
#include <sys/device.h>
@@ -82,19 +82,8 @@ 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, 10000000))
- res = 0;
-
- return res;
+ return spi_compatible_match(sa, match, compat_data);
}
static void
@@ -104,12 +93,24 @@ ssdfb_spi_attach(device_t parent, device
Home |
Main Index |
Thread Index |
Old Index