Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/dev/spi Re-factor and overhaul the "mcp23s17gpio" driver...



details:   https://anonhg.NetBSD.org/src/rev/721dad51c18a
branches:  trunk
changeset: 359691:721dad51c18a
user:      thorpej <thorpej%NetBSD.org@localhost>
date:      Mon Jan 17 16:31:23 2022 +0000

description:
Re-factor and overhaul the "mcp23s17gpio" driver as "mcpgpio", and
add support for 8-bit and I2C variants of the chip:
- MCP23008 / MCP23S08: 8-bit (I2C / SPI)
- MCP23017 / MCP23S17: 16-bit (I2C / SPI)
- MCP23018 / MCP23S18: 16-bit (I2C / SPI), open-drain outputs

The MCP23x17 and MCP23x18 are essentially identical, software-wise; we
merely report different GPIO pin capabilities (no push-pull output for
MCP23x18).  Also, remove the tri-state capability that was previously
advertised by the old version of this driver; these chips have no way
to put the pin into a HI-Z mode.

All 3 I2C versions are supported, but the SPI front-end still only
supports the MCP23S17 for now (SPI autoconfiguration needs an overhaul).

mcp23s17gpio(4) remains present as a link to the new mcpgpio(4) man page.

XXX Still to-do: FDT integration, interrupt suppoort.

diffstat:

 distrib/sets/lists/man/mi      |    5 +-
 share/man/man4/Makefile        |    6 +-
 share/man/man4/mcp23s17gpio.4  |   64 -------
 share/man/man4/mcpgpio.4       |  108 ++++++++++++
 sys/arch/evbarm/conf/RPI       |   15 +-
 sys/dev/i2c/files.i2c          |    6 +-
 sys/dev/i2c/mcp23xxxgpio_i2c.c |  176 ++++++++++++++++++++
 sys/dev/ic/mcp23xxxgpio.c      |  355 +++++++++++++++++++++++++++++++++++++++++
 sys/dev/ic/mcp23xxxgpioreg.h   |  118 +++++++++++++
 sys/dev/ic/mcp23xxxgpiovar.h   |   90 ++++++++++
 sys/dev/spi/files.spi          |    9 +-
 sys/dev/spi/mcp23s17.c         |  301 ----------------------------------
 sys/dev/spi/mcp23s17.h         |   96 -----------
 sys/dev/spi/mcp23xxxgpio_spi.c |  298 ++++++++++++++++++++++++++++++++++
 14 files changed, 1171 insertions(+), 476 deletions(-)

diffs (truncated from 1773 to 300 lines):

diff -r 2d42553dcce2 -r 721dad51c18a distrib/sets/lists/man/mi
--- a/distrib/sets/lists/man/mi Mon Jan 17 14:00:47 2022 +0000
+++ b/distrib/sets/lists/man/mi Mon Jan 17 16:31:23 2022 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.1731 2022/01/06 21:55:24 nia Exp $
+# $NetBSD: mi,v 1.1732 2022/01/17 16:31:23 thorpej Exp $
 #
 # Note: don't delete entries from here - mark them as "obsolete" instead.
 #
@@ -1471,6 +1471,7 @@
 ./usr/share/man/cat4/mcp3kadc.0                        man-sys-catman          .cat
 ./usr/share/man/cat4/mcp48x1dac.0              man-sys-catman          .cat
 ./usr/share/man/cat4/mcp980x.0                 man-sys-catman          .cat
+./usr/share/man/cat4/mcpgpio.0                 man-sys-catman          .cat
 ./usr/share/man/cat4/mcx.0                     man-sys-catman          .cat
 ./usr/share/man/cat4/md.0                      man-sys-catman          .cat
 ./usr/share/man/cat4/mfb.0                     man-sys-catman          .cat
@@ -4679,6 +4680,7 @@
 ./usr/share/man/html4/mcp3kadc.html            man-sys-htmlman         html
 ./usr/share/man/html4/mcp48x1dac.html          man-sys-htmlman         html
 ./usr/share/man/html4/mcp980x.html             man-sys-htmlman         html
+./usr/share/man/html4/mcpgpio.html             man-sys-htmlman         html
 ./usr/share/man/html4/mcx.html                 man-sys-htmlman         html
 ./usr/share/man/html4/md.html                  man-sys-htmlman         html
 ./usr/share/man/html4/mfb.html                 man-sys-htmlman         html
@@ -7740,6 +7742,7 @@
 ./usr/share/man/man4/mcp3kadc.4                        man-sys-man             .man
 ./usr/share/man/man4/mcp48x1dac.4              man-sys-man             .man
 ./usr/share/man/man4/mcp980x.4                 man-sys-man             .man
+./usr/share/man/man4/mcpgpio.4                 man-sys-man             .man
 ./usr/share/man/man4/mcx.4                     man-sys-man             .man
 ./usr/share/man/man4/md.4                      man-sys-man             .man
 ./usr/share/man/man4/mfb.4                     man-sys-man             .man
diff -r 2d42553dcce2 -r 721dad51c18a share/man/man4/Makefile
--- a/share/man/man4/Makefile   Mon Jan 17 14:00:47 2022 +0000
+++ b/share/man/man4/Makefile   Mon Jan 17 16:31:23 2022 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: Makefile,v 1.721 2022/01/06 21:55:23 nia Exp $
+#      $NetBSD: Makefile,v 1.722 2022/01/17 16:31:23 thorpej Exp $
 #      @(#)Makefile    8.1 (Berkeley) 6/18/93
 
 MAN=   aac.4 ac97.4 acardide.4 aceride.4 acphy.4 \
@@ -137,7 +137,9 @@
        smscmon.4 spdmem.4 tps65217pmic.4
 
 # machine-independent SPI devices
-MAN += m25p.4 mcp23s17gpio.4 mcp3kadc.4 mcp48x1dac.4 tm121temp.4
+MAN += m25p.4 mcpgpio.4 mcp3kadc.4 mcp48x1dac.4 tm121temp.4
+
+MLINKS+=mcpgpio.4 mcp23s17gpio.4
 
 # machine-independent SD/MMC devices
 MAN += sbt.4 sdhc.4 sdmmc.4
diff -r 2d42553dcce2 -r 721dad51c18a share/man/man4/mcp23s17gpio.4
--- a/share/man/man4/mcp23s17gpio.4     Mon Jan 17 14:00:47 2022 +0000
+++ /dev/null   Thu Jan 01 00:00:00 1970 +0000
@@ -1,64 +0,0 @@
-.\"    $NetBSD: mcp23s17gpio.4,v 1.2 2014/04/07 11:18:13 wiz Exp $
-.\"
-.\"Copyright (c) 2014 Frank Kardel
-.\"All rights reserved.
-.\"
-.\"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 AUTHOR 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.
-.\"
-.Dd April 6, 2014
-.Dt MCP23S17GPIO 4
-.Os
-.Sh NAME
-.Nm mcp23s17gpio
-.Nd Driver for MCP23S17 gpio chip via SPI bus
-.Sh SYNOPSIS
-.Cd "mcp23s17gpio0 at spi? slave 0 flags 0"
-.Cd "mcp23s17gpio1 at spi? slave 0 flags 1"
-.Cd "mcp23s17gpio2 at spi? slave 0 flags 2"
-.Cd "mcp23s17gpio3 at spi? slave 0 flags 3"
-.Cd "gpio* at gpiobus?"
-.Sh DESCRIPTION
-The
-.Nm
-driver supports up to 8 instances of the MCP23S17 16-bit GPIO chips.
-Access to the pins is provided by the
-.Xr gpio 4
-interface.
-The
-.Nm
-.Ar flags
-argument selects the hardware address of the chip instance.
-.Sh SEE ALSO
-.Xr gpio 4 ,
-.Xr intro 4 ,
-.Xr spi 4
-.Sh HISTORY
-The
-.Nm
-driver first appeared in
-.Nx 7.0 .
-.Sh AUTHORS
-.An -nosplit
-The
-.Nm
-driver was written by
-.An Frank Kardel Aq Mt kardel%NetBSD.org@localhost .
diff -r 2d42553dcce2 -r 721dad51c18a share/man/man4/mcpgpio.4
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/share/man/man4/mcpgpio.4  Mon Jan 17 16:31:23 2022 +0000
@@ -0,0 +1,108 @@
+.\"    $NetBSD: mcpgpio.4,v 1.1 2022/01/17 16:31:23 thorpej Exp $
+.\"
+.\"Copyright (c) 2014 Frank Kardel
+.\"All rights reserved.
+.\"
+.\"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 AUTHOR 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.
+.\"
+.Dd January 10, 2022
+.Dt MCPGPIO 4
+.Os
+.Sh NAME
+.Nm mcpgpio
+.Nd Driver for Microchip I/O Expanders on I2C and SPI bus
+.Sh SYNOPSIS
+.Ss I2C
+.Cd "mcpgpio* at iic? addr ?"
+.Cd "gpio* at gpiobus?"
+.Ss SPI
+.Cd "mcpgpio0 at spi? slave 0 flags 0"
+.Cd "mcpgpio1 at spi? slave 0 flags 1"
+.Cd "mcpgpio2 at spi? slave 0 flags 2"
+.Cd "mcpgpio3 at spi? slave 0 flags 3"
+.Cd "gpio* at gpiobus?"
+.Sh DESCRIPTION
+The
+.Nm
+driver supports the following Microchip I/O Expanders:
+.Bl -tag -width "mcp23x08"
+.It MCP23008
+8-bit I/O expander, I2C interface
+.It MCP23S08
+8-bit I/O expander, SPI interface
+.It MCP23017
+16-bit I/O expander, I2C interface
+.It MCP23S17
+16-bit I/O expander, SPI interface
+.It MCP23018
+16-bit I/O expander, open-drain outputs, I2C interface
+.It MCP23S18
+16-bit I/O expander, open-drain outputs, SPI interface
+.El
+.Pp
+Access to the pins is provided by the
+.Xr gpio 4
+interface.
+.Pp
+The SPI version of these devices support multiple chips per chip select
+signal.
+On the MCP23S08 and MCP23S17, this is achieved by tying the address select
+pins to VDD or GND to select an address
+.Pq 0-3 on MCP23S08 or 0-7 on MCP23S17 .
+The MCP23S18 has a similar capability, but uses an analog voltage input
+on a single address select pin, along with an internal voltage divider
+ladder and a series of comparators to generate the 3 address bits; see
+the data sheet for details.
+The
+.Ar flags
+argument in the configuration directive for SPI attachments selects the
+hardware address of the chip instance for that driver instance.
+.Sh SEE ALSO
+.Xr gpio 4 ,
+.Xr iic 4 ,
+.Xr intro 4 ,
+.Xr spi 4
+.Sh HISTORY
+The
+.Nm
+driver first appeared in
+.Nx 7.0 .
+It was overhauled in
+.Nx 10.0
+to support additional chip types and to add the I2C attachment.
+.Sh AUTHORS
+.An -nosplit
+The
+.Nm
+driver was written by
+.An Frank Kardel Aq Mt kardel%NetBSD.org@localhost
+and
+.An Jason R. Thorpe Aq Mt thorpej%NetBSD.org@localhost .
+.Sh BUGS
+SPI instances of the
+.Nm
+driver do not utilize the Device Tree bindings for this device.
+.Pp
+The
+.Nm
+driver does not currently act as a GPIO provider for the platform
+device tree.
diff -r 2d42553dcce2 -r 721dad51c18a sys/arch/evbarm/conf/RPI
--- a/sys/arch/evbarm/conf/RPI  Mon Jan 17 14:00:47 2022 +0000
+++ b/sys/arch/evbarm/conf/RPI  Mon Jan 17 16:31:23 2022 +0000
@@ -1,5 +1,5 @@
 #
-#      $NetBSD: RPI,v 1.94 2020/11/23 06:24:35 rin Exp $
+#      $NetBSD: RPI,v 1.95 2022/01/17 16:31:24 thorpej Exp $
 #
 #      RPi -- Raspberry Pi
 #
@@ -178,12 +178,15 @@
 #mcp3kadc0 at spi? slave 0 flags 0
 
 # PIFace or other boards using that chip (needs gpio)
-#mcp23s17gpio0 at spi? slave 0 flags 0
-#mcp23s17gpio1 at spi? slave 0 flags 1
-#mcp23s17gpio2 at spi? slave 0 flags 2
-#mcp23s17gpio3 at spi? slave 0 flags 3
+#mcpgpio0 at spi? slave 0 flags 0
+#mcpgpio1 at spi? slave 0 flags 1
+#mcpgpio2 at spi? slave 0 flags 2
+#mcpgpio3 at spi? slave 0 flags 3
 
-# gpio support (e. g. mcp23s17gpio, bcmgpio)
+# MCP230xx GPIO on I2C.
+mcpgpio* at iic? addr ?
+
+# gpio support (e. g. mcpgpio, bcmgpio)
 gpio*          at gpiobus?
 
 # various options for wscons - we try to look as much like a standard
diff -r 2d42553dcce2 -r 721dad51c18a sys/dev/i2c/files.i2c
--- a/sys/dev/i2c/files.i2c     Mon Jan 17 14:00:47 2022 +0000
+++ b/sys/dev/i2c/files.i2c     Mon Jan 17 16:31:23 2022 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: files.i2c,v 1.121 2021/12/27 23:04:20 andvar Exp $
+#      $NetBSD: files.i2c,v 1.122 2022/01/17 16:31:23 thorpej Exp $
 
 obsolete defflag       opt_i2cbus.h            I2C_SCAN
 define i2cbus { }
@@ -204,6 +204,10 @@
 attach tps65217reg at tps65217pmic
 file   dev/i2c/tps65217pmic.c          tps65217pmic    needs-flag
 
+# Microchip MCP23008 / MCP23017 I/O Expander
+attach mcpgpio at iic with mcpgpio_i2c
+file   dev/i2c/mcp23xxxgpio_i2c.c      mcpgpio_i2c
+
 # Microchip MCP980x
 device mcp980x: sysmon_envsys
 attach mcp980x at iic
diff -r 2d42553dcce2 -r 721dad51c18a sys/dev/i2c/mcp23xxxgpio_i2c.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/dev/i2c/mcp23xxxgpio_i2c.c    Mon Jan 17 16:31:23 2022 +0000
@@ -0,0 +1,176 @@
+/*      $NetBSD: mcp23xxxgpio_i2c.c,v 1.1 2022/01/17 16:31:23 thorpej Exp $    */
+
+/*-
+ * Copyright (c) 2022 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Jason R. Thorpe.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:



Home | Main Index | Thread Index | Old Index