Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/thorpej-i2c-spi-conf2]: src/sys/dev/ic Port over the changes from thorpe...
details: https://anonhg.NetBSD.org/src/rev/8797b9ccdfdc
branches: thorpej-i2c-spi-conf2
changeset: 985143:8797b9ccdfdc
user: thorpej <thorpej%NetBSD.org@localhost>
date: Mon Aug 09 01:29:52 2021 +0000
description:
Port over the changes from thorpej-i2c-spi-conf to thorpej-i2c-spi-conf2,
which is based on a newer HEAD revision.
diffstat:
sys/dev/ic/pcf8584.c | 94 +++++++++++++++++++++++++++++++++++-------------
sys/dev/ic/pcf8584var.h | 36 ++++++++++++++----
2 files changed, 96 insertions(+), 34 deletions(-)
diffs (222 lines):
diff -r 33c80c216eed -r 8797b9ccdfdc sys/dev/ic/pcf8584.c
--- a/sys/dev/ic/pcf8584.c Mon Aug 09 01:16:01 2021 +0000
+++ b/sys/dev/ic/pcf8584.c Mon Aug 09 01:29:52 2021 +0000
@@ -1,7 +1,36 @@
-/* $NetBSD: pcf8584.c,v 1.19 2021/08/07 16:19:12 thorpej Exp $ */
+/* $NetBSD: pcf8584.c,v 1.19.2.1 2021/08/09 01:29:52 thorpej Exp $ */
/* $OpenBSD: pcf8584.c,v 1.9 2007/10/20 18:46:21 kettenis Exp $ */
/*
+ * Copyright (c) 2021 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:
+ * 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.
+ */
+
+/*
* Copyright (c) 2006 David Gwynne <dlg%openbsd.org@localhost>
*
* Permission to use, copy, modify, and distribute this software for any
@@ -20,7 +49,7 @@
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/device.h>
-#include <sys/malloc.h>
+#include <sys/kmem.h>
#include <sys/kernel.h>
#include <sys/proc.h>
#include <sys/bus.h>
@@ -30,6 +59,8 @@
#include <dev/ic/pcf8584var.h>
#include <dev/ic/pcf8584reg.h>
+#include "locators.h"
+
/* Internal registers */
#define PCF8584_S0 0x00
#define PCF8584_S1 0x01
@@ -37,8 +68,6 @@
#define PCF8584_S3 0x03
void pcfiic_init(struct pcfiic_softc *);
-int pcfiic_i2c_acquire_bus(void *, int);
-void pcfiic_i2c_release_bus(void *, int);
int pcfiic_i2c_exec(void *, i2c_op_t, i2c_addr_t, const void *,
size_t, void *, size_t, int);
@@ -49,7 +78,6 @@
u_int8_t pcfiic_read(struct pcfiic_softc *, bus_size_t);
void pcfiic_write(struct pcfiic_softc *, bus_size_t, u_int8_t);
-void pcfiic_choose_bus(struct pcfiic_softc *, u_int8_t);
int pcfiic_wait_BBN(struct pcfiic_softc *);
int pcfiic_wait_pin(struct pcfiic_softc *, volatile u_int8_t *);
@@ -71,10 +99,12 @@
}
void
-pcfiic_attach(struct pcfiic_softc *sc, i2c_addr_t addr, u_int8_t clock,
+pcfiic_attach(struct pcfiic_softc *sc, i2c_addr_t addr, uint8_t clock,
int swapregs)
{
- struct i2cbus_attach_args iba;
+ struct i2cbus_attach_args iba;
+ struct pcfiic_channel *ch;
+ int i;
if (swapregs) {
sc->sc_regmap[PCF8584_S1] = PCF8584_S0;
@@ -90,16 +120,39 @@
printf("\n");
- if (sc->sc_master)
- pcfiic_choose_bus(sc, 0);
+ if (sc->sc_channels == NULL) {
+ KASSERT(sc->sc_nchannels == 0);
+ ch = kmem_alloc(sizeof(*sc->sc_channels), KM_SLEEP);
+ ch->ch_channel = 0;
+ ch->ch_devhandle = device_handle(sc->sc_dev);
+
+ sc->sc_channels = ch;
+ sc->sc_nchannels = 1;
+ } else {
+ KASSERT(sc->sc_nchannels != 0);
+ }
+
+ for (i = 0; i < sc->sc_nchannels; i++) {
+ int locs[I2CBUSCF_NLOCS];
- iic_tag_init(&sc->sc_i2c);
- sc->sc_i2c.ic_cookie = sc;
- sc->sc_i2c.ic_exec = pcfiic_i2c_exec;
+ ch = &sc->sc_channels[i];
+ ch->ch_sc = sc;
+ iic_tag_init(&ch->ch_i2c);
+ ch->ch_i2c.ic_cookie = ch;
+ ch->ch_i2c.ic_exec = pcfiic_i2c_exec;
+ ch->ch_i2c.ic_acquire_bus = sc->sc_acquire_bus;
+ ch->ch_i2c.ic_release_bus = sc->sc_release_bus;
- bzero(&iba, sizeof(iba));
- iba.iba_tag = &sc->sc_i2c;
- config_found(sc->sc_dev, &iba, iicbus_print, CFARGS_NONE);
+ locs[I2CBUSCF_BUS] = ch->ch_i2c.ic_channel;
+
+ memset(&iba, 0, sizeof(iba));
+ iba.iba_tag = &ch->ch_i2c;
+ config_found(sc->sc_dev, &iba,
+ sc->sc_nchannels == 1 ? iicbus_print : iicbus_print_multi,
+ CFARGS(.submatch = config_stdsubmatch,
+ .locators = locs,
+ .devhandle = ch->ch_devhandle));
+ }
}
int
@@ -123,9 +176,6 @@
if (sc->sc_poll)
flags |= I2C_F_POLL;
- if (sc->sc_master)
- pcfiic_choose_bus(sc, addr >> 7);
-
/*
* If we are writing, write address, cmdbuf, buf.
* If we are reading, write address, cmdbuf, then read address, buf.
@@ -224,14 +274,6 @@
(void)bus_space_read_1(sc->sc_iot, sc->sc_ioh, PCF8584_S1);
}
-void
-pcfiic_choose_bus(struct pcfiic_softc *sc, u_int8_t bus)
-{
- bus_space_write_1(sc->sc_iot, sc->sc_ioh2, 0, bus);
- bus_space_barrier(sc->sc_iot, sc->sc_ioh2, 0, 1,
- BUS_SPACE_BARRIER_WRITE);
-}
-
int
pcfiic_wait_BBN(struct pcfiic_softc *sc)
{
diff -r 33c80c216eed -r 8797b9ccdfdc sys/dev/ic/pcf8584var.h
--- a/sys/dev/ic/pcf8584var.h Mon Aug 09 01:16:01 2021 +0000
+++ b/sys/dev/ic/pcf8584var.h Mon Aug 09 01:29:52 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: pcf8584var.h,v 1.6 2019/12/22 23:23:32 thorpej Exp $ */
+/* $NetBSD: pcf8584var.h,v 1.6.22.1 2021/08/09 01:29:52 thorpej Exp $ */
/* $OpenBSD: pcf8584var.h,v 1.5 2007/10/20 18:46:21 kettenis Exp $ */
/*
@@ -17,21 +17,41 @@
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
+#ifndef _DEV_IC_PCF8584VAR_H_
+#define _DEV_IC_PCF8584VAR_H_
+
+struct pcfiic_channel {
+ struct i2c_controller ch_i2c;
+ struct pcfiic_softc *ch_sc;
+ devhandle_t ch_devhandle;
+ int ch_channel;
+};
+
struct pcfiic_softc {
device_t sc_dev;
bus_space_tag_t sc_iot;
bus_space_handle_t sc_ioh;
- bus_space_handle_t sc_ioh2;
- int sc_master;
- u_int8_t sc_addr;
- u_int8_t sc_clock;
- u_int8_t sc_regmap[2];
+ uint8_t sc_addr;
+ uint8_t sc_clock;
+ uint8_t sc_regmap[2];
int sc_poll;
- struct i2c_controller sc_i2c;
+ /*
+ * Some Sun clones of the this i2c controller support
+ * multiple channels. The specific attachment will
+ * initialize these fields for controllers that support
+ * this. If not, the core driver will assume a single
+ * channel.
+ */
+ struct pcfiic_channel *sc_channels;
+ int sc_nchannels;
+ int (*sc_acquire_bus)(void *, int);
+ void (*sc_release_bus)(void *, int);
};
-void pcfiic_attach(struct pcfiic_softc *, i2c_addr_t, u_int8_t, int);
+void pcfiic_attach(struct pcfiic_softc *, i2c_addr_t, uint8_t, int);
int pcfiic_intr(void *);
+
+#endif /* _DEV_IC_PCF8584VAR_H_ */
Home |
Main Index |
Thread Index |
Old Index