Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 19 Jul 2001 10:24:56 -0700
From:      Brooks Davis <brooks@one-eyed-alien.net>
To:        Nicolas Souchu <nsouch@fr.alcove.com>
Cc:        multimedia@freebsd.org, roger@freebsd.org
Subject:   Re: bktr and smbus
Message-ID:  <20010719102456.A30157@Odin.AC.HMC.Edu>
In-Reply-To: <20010719151701.M32191@ontario.alcove-fr>; from nsouch@fr.alcove.com on Thu, Jul 19, 2001 at 03:17:02PM %2B0200
References:  <20010717195452.A9080@Odin.AC.HMC.Edu> <20010719151701.M32191@ontario.alcove-fr>

next in thread | previous in thread | raw e-mail | index | archive | help

--FCuugMFkClbJLl1L
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

On Thu, Jul 19, 2001 at 03:17:02PM +0200, Nicolas Souchu wrote:
> At the opposite, FreeBSD has an smbus framework, why don't use it and
> duplicate the I2C logic everywhere? There's no reason not using FreeBSD
> smbus.

Well, my origional argument was that the driver was alwasy going to have
it's own I2C code (at least until someone gets smbus comitted to NetBSD,
OpenBSD, and BSD/OS) and the current code was kinda messy.  However,
roger mentioned that he's planning to use the smbus I2C code for a new
driver so keeping it and more or less making it mandatory is probably
the better approach.

> The solution is rather at http://people.freebsd.org/~nsouch/iicbus.html
>=20
> I've uploaded a patch for -current. I'd be very happy to get feedback
> about it.

Looks good, I can't test it because my bktr cards are both in STABLE
systems, but with a couple of changes, I was able to remove NBKTR and
bktr.h from the picture.  Below I've provided alternate diffs for
conf/files, dev/bktr/* and modules/bktr/Makefile.

-- Brooks

--=20
Any statement of the form "X is the one, true Y" is FALSE.
PGP fingerprint 655D 519C 26A7 82E7 2529  9BF0 5D8E 8BE9 F238 1AD4

Index: conf/files
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /home/ncvs/src/sys/conf/files,v
retrieving revision 1.551
diff -u -r1.551 files
--- conf/files	2001/07/14 08:25:18	1.551
+++ conf/files	2001/07/19 17:15:44
@@ -274,7 +274,7 @@
 dev/awi/if_awi_pccard.c	optional awi pccard
 dev/bktr/bktr_audio.c	optional bktr pci
 dev/bktr/bktr_card.c	optional bktr pci
-dev/bktr/bktr_core.c	count bktr pci
+dev/bktr/bktr_core.c	optional bktr pci
 dev/bktr/bktr_i2c.c	optional bktr pci smbus
 dev/bktr/bktr_os.c	optional bktr pci
 dev/bktr/bktr_tuner.c	optional bktr pci
@@ -437,6 +437,8 @@
 dev/pdq/pdq.c		optional fpa pci
 dev/pdq/pdq_ifsubr.c	optional fea eisa
 dev/pdq/pdq_ifsubr.c	optional fpa pci
+dev/pm/viapm.c		optional viapm
+dev/pm/amdpm.c		optional amdpm
 dev/ppbus/ppbus_if.m	optional ppbus
 dev/ppbus/if_plip.c	optional plip
 dev/ppbus/immio.c	optional vpo
@@ -471,7 +473,7 @@
 dev/smbus/smbus_if.m	optional smbus
 dev/smbus/smb.c		optional smb
 dev/smbus/smbconf.c	optional smbus
-dev/smbus/smbus.c	count smbus
+dev/smbus/smbus.c	optional smbus
 dev/sn/if_sn.c		optional sn
 dev/sn/if_sn_isa.c	optional sn isa
 dev/sn/if_sn_pccard.c	optional sn card
Index: dev/bktr//bktr_core.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /home/ncvs/src/sys/dev/bktr/bktr_core.c,v
retrieving revision 1.116
diff -u -r1.116 bktr_core.c
--- dev/bktr//bktr_core.c	2001/05/01 08:11:56	1.116
+++ dev/bktr//bktr_core.c	2001/07/19 17:18:55
@@ -96,12 +96,8 @@
=20
 #include "opt_bktr.h"		/* Include any kernel config options */
=20
-#ifdef __FreeBSD__
-#include "bktr.h"
-#endif /* __FreeBSD__ */
-
 #if (                                                            \
-       (defined(__FreeBSD__) && (NBKTR > 0))                     \
+       (defined(__FreeBSD__))                                    \
     || (defined(__bsdi__))                                       \
     || (defined(__OpenBSD__))                                    \
     || (defined(__NetBSD__))                                     \
Index: dev/bktr//bktr_i2c.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /home/ncvs/src/sys/dev/bktr/bktr_i2c.c,v
retrieving revision 1.19
diff -u -r1.19 bktr_i2c.c
--- dev/bktr//bktr_i2c.c	2001/01/20 02:24:01	1.19
+++ dev/bktr//bktr_i2c.c	2001/07/19 17:17:44
@@ -1,5 +1,5 @@
 /*-
- * Copyright (c) 1998 Nicolas Souchu
+ * Copyright (c) 1998, 2001 Nicolas Souchu
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -33,10 +33,9 @@
  * From brooktree848.c <fsmp@freefall.org>
  */
=20
-#include "bktr.h"
-
 #include <sys/param.h>
 #include <sys/kernel.h>
+#include <sys/malloc.h>
 #include <sys/systm.h>
 #include <sys/module.h>
 #include <sys/bus.h>
@@ -62,196 +61,91 @@
 #include <pci/pcireg.h>
 #include <machine/ioctl_meteor.h>
 #include <machine/ioctl_bt848.h>	/* extensions to ioctl_meteor.h */
-#include <dev/bktr/bktr_reg.h>
=20
+#include <dev/bktr/bktr_reg.h>
 #include <dev/bktr/bktr_i2c.h>
=20
-#include <dev/iicbus/iiconf.h>
-#include <dev/iicbus/iicbus.h>
-
 #include <dev/smbus/smbconf.h>
-
-#include "iicbb_if.h"
-#include "smbus_if.h"
-
-
+#include <dev/iicbus/iiconf.h>
=20
 #define I2C_DELAY	40
=20
 #define BTI2C_DEBUG(x)	if (bti2c_debug) (x)
 static int bti2c_debug =3D 0;
=20
-struct bti2c_softc {
-
-	bus_space_tag_t     memt;   /* Bus space register access */
-	bus_space_handle_t  memh;   /* Bus space register access */
-
-	int iic_owned;			/* 1 if we own the iicbus */
-	int smb_owned;			/* 1 if we own the smbbus */
-
-	device_t smbus;
-	device_t iicbus;
-};
-
-struct bt_data {
-	bus_space_tag_t     memt;
-	bus_space_handle_t  memh;=20
-};
-struct bt_data btdata[NBKTR];
-
-static int bti2c_probe(device_t);
-static int bti2c_attach(device_t);
-
-static int bti2c_iic_callback(device_t, int, caddr_t *);
-static void bti2c_iic_setlines(device_t, int, int);
-static int bti2c_iic_getdataline(device_t);
-static int bti2c_iic_reset(device_t, u_char, u_char, u_char *);
-
-static int bti2c_smb_callback(device_t, int, caddr_t *);
-static int bti2c_smb_writeb(device_t dev, u_char slave, char cmd, char byt=
e);
-static int bti2c_smb_writew(device_t dev, u_char slave, char cmd, short wo=
rd);
-static int bti2c_smb_readb(device_t dev, u_char slave, char cmd, char *byt=
e);
-
-static devclass_t bti2c_devclass;
-
-static device_method_t bti2c_methods[] =3D {
-	/* device interface */
-	DEVMETHOD(device_probe,		bti2c_probe),
-	DEVMETHOD(device_attach,	bti2c_attach),
-
-	/* bus interface */
-	DEVMETHOD(bus_print_child,	bus_generic_print_child),
-
-	/* iicbb interface */
-	DEVMETHOD(iicbb_callback,	bti2c_iic_callback),
-	DEVMETHOD(iicbb_setlines,	bti2c_iic_setlines),
-	DEVMETHOD(iicbb_getdataline,	bti2c_iic_getdataline),
-	DEVMETHOD(iicbb_reset,		bti2c_iic_reset),
-=09
-	/* smbus interface */
-	DEVMETHOD(smbus_callback,	bti2c_smb_callback),
-	DEVMETHOD(smbus_writeb,		bti2c_smb_writeb),
-	DEVMETHOD(smbus_writew,		bti2c_smb_writew),
-	DEVMETHOD(smbus_readb,		bti2c_smb_readb),
-=09
-	{ 0, 0 }
-};
-
-#if (__FreeBSD_version < 400000)
-/* FreeBSD 3.x needs DRIVER_TYPE_MISC */
-static driver_t bti2c_driver =3D {
-	"bti2c",
-	bti2c_methods,
-	DRIVER_TYPE_MISC,
-	sizeof(struct bti2c_softc),
-};
-#endif
-
-#if (__FreeBSD_version >=3D400000)
-	static driver_t bti2c_driver =3D {
-	"bti2c",
-	bti2c_methods,
-	sizeof(struct bti2c_softc),
-};     =20
-#endif
-
 /*
  * Call this to pass the address of the bktr device to the
  * bti2c_i2c layer and initialize all the I2C bus architecture
  */
-int
-bt848_i2c_attach(int unit, struct bktr_softc * bktr, struct bktr_i2c_softc=
 *i2c_sc)
+int bt848_i2c_attach(device_t dev)
 {
-	device_t interface;
-	device_t bitbang;
+	struct bktr_softc *bktr_sc =3D (struct bktr_softc *)device_get_softc(dev);
+	struct bktr_i2c_softc *sc =3D &bktr_sc->i2c_sc;
=20
-	btdata[unit].memh =3D bktr->memh;
-	btdata[unit].memt =3D bktr->memt;
+	device_t *list;
+	int count;
=20
-	/* XXX add the I2C interface to the root_bus until pcibus is ready */
-#if (__FreeBSD_version < 400000)
-	interface =3D device_add_child(root_bus, "bti2c", unit, NULL);
-#else
-	interface =3D device_add_child(root_bus, "bti2c", unit);
-#endif
+	sc->smbus =3D device_add_child(dev, "smbus", -1);
+	sc->iicbb =3D device_add_child(dev, "iicbb", -1);
=20
-	/* add bit-banging generic code onto bti2c interface */
-#if (__FreeBSD_version < 400000)
-	bitbang =3D device_add_child(interface, "iicbb", -1, NULL);
-#else
-	bitbang =3D device_add_child(interface, "iicbb", -1);
-#endif
+	if (!sc->iicbb || !sc->smbus)
+		return ENXIO;
=20
-	/* probe and attach the interface, we need it NOW
-	 * bit-banging code is also probed and attached */
-	device_probe_and_attach(interface);
-	device_probe_and_attach(bitbang);
-
-	/* smb and i2c interfaces are available for the bt848 chip
-	 * connect bit-banging generic code to an iicbus */
-	if ((i2c_sc->iicbus =3D iicbus_alloc_bus(bitbang)))
-		device_probe_and_attach(i2c_sc->iicbus);
-
-	/* hardware i2c is actually smb over the bti2c interface */
-	if ((i2c_sc->smbus =3D smbus_alloc_bus(interface)))
-		device_probe_and_attach(i2c_sc->smbus);
+	bus_generic_attach(dev);
+
+	/* the iicbus is the first child of device iicbb */
+	device_get_children(sc->iicbb, &list, &count);
+	if (count) {
+		sc->iicbus =3D list[0];
+		free(list, M_TEMP);
+	}
=20
 	return (0);
 };
=20
-/*
- * Not a real probe, we know the device exists since the device has
- * been added after the successfull pci probe.
- */
-static int
-bti2c_probe(device_t dev)
+int bt848_i2c_detach(device_t dev)
 {
-	device_set_desc(dev, "bt848 Hard/Soft I2C controller");
+	struct bktr_softc *bktr_sc =3D (struct bktr_softc *)device_get_softc(dev);
+	struct bktr_i2c_softc *sc =3D &bktr_sc->i2c_sc;
+	int error =3D 0;
=20
-	return (0);
-}
+	if ((error =3D bus_generic_detach(dev)))
+		goto error;
=20
-static int
-bti2c_attach(device_t dev)
-{
-	struct bti2c_softc *sc =3D (struct bti2c_softc *)device_get_softc(dev);
+	if (sc->iicbb && (error =3D device_delete_child(dev, sc->iicbb)))
+		goto error;
=20
-	/* XXX should use ivars with pcibus or pcibus methods to access
-	 * onboard memory */
-	sc->memh =3D btdata[device_get_unit(dev)].memh;
-	sc->memt =3D btdata[device_get_unit(dev)].memt;
+	if (sc->smbus && (error =3D device_delete_child(dev, sc->smbus)))
+		goto error;
=20
-	return (0);
+error:
+	return (error);
 }
=20
-static int
-bti2c_smb_callback(device_t dev, int index, caddr_t *data)
+int bti2c_smb_callback(device_t dev, int index, caddr_t *data)
 {
-	struct bti2c_softc *sc =3D (struct bti2c_softc *)device_get_softc(dev);
+	struct bktr_softc *bktr_sc =3D (struct bktr_softc *)device_get_softc(dev);
+	struct bktr_i2c_softc *sc =3D &bktr_sc->i2c_sc;
 	int error =3D 0;
-	int how;
=20
 	/* test each time if we already have/haven't the iicbus
 	 * to avoid deadlocks
 	 */
 	switch (index) {
 	case SMB_REQUEST_BUS:
-		if (!sc->iic_owned) {
-			/* request the iicbus */
-			how =3D *(int *)data;
-			error =3D iicbus_request_bus(sc->iicbus, dev, how);
-			if (!error)
-				sc->iic_owned =3D 1;
-		}
+		/* XXX test & set */
+		if (!sc->bus_owned) {
+			sc->bus_owned =3D 1;
+		} else
+			error =3D EWOULDBLOCK;
 		break;
=20
 	case SMB_RELEASE_BUS:
-		if (sc->iic_owned) {
-			/* release the iicbus */
-			error =3D iicbus_release_bus(sc->iicbus, dev);
-			if (!error)
-				sc->iic_owned =3D 0;
-		}
+		/* XXX test & set */
+		if (sc->bus_owned) {
+			sc->bus_owned =3D 0;
+		} else
+			error =3D EINVAL;
 		break;
=20
 	default:
@@ -261,34 +155,30 @@
 	return (error);
 }
=20
-static int
-bti2c_iic_callback(device_t dev, int index, caddr_t *data)
+int bti2c_iic_callback(device_t dev, int index, caddr_t *data)
 {
-	struct bti2c_softc *sc =3D (struct bti2c_softc *)device_get_softc(dev);
+	struct bktr_softc *bktr_sc =3D (struct bktr_softc *)device_get_softc(dev);
+	struct bktr_i2c_softc *sc =3D &bktr_sc->i2c_sc;
 	int error =3D 0;
-	int how;
=20
 	/* test each time if we already have/haven't the smbus
 	 * to avoid deadlocks
 	 */
 	switch (index) {
 	case IIC_REQUEST_BUS:
-		if (!sc->smb_owned) {
-			/* request the smbus */
-			how =3D *(int *)data;
-			error =3D smbus_request_bus(sc->smbus, dev, how);
-			if (!error)
-				sc->smb_owned =3D 1;
-		}
+		/* XXX test & set */
+		if (!sc->bus_owned) {
+			sc->bus_owned =3D 1;
+		} else
+			error =3D EWOULDBLOCK;
 		break;
=20
 	case IIC_RELEASE_BUS:
-		if (sc->smb_owned) {
-			/* release the smbus */
-			error =3D smbus_release_bus(sc->smbus, dev);
-			if (!error)
-				sc->smb_owned =3D 0;
-		}
+		/* XXX test & set */
+		if (sc->bus_owned) {
+			sc->bus_owned =3D 0;
+		} else
+			error =3D EINVAL;
 		break;
=20
 	default:
@@ -298,8 +188,7 @@
 	return (error);
 }
=20
-static int
-bti2c_iic_reset(device_t dev, u_char speed, u_char addr, u_char * oldaddr)
+int bti2c_iic_reset(device_t dev, u_char speed, u_char addr, u_char * olda=
ddr)
 {
 	if (oldaddr)
 		*oldaddr =3D 0;			/* XXX */
@@ -307,48 +196,77 @@
 	return (IIC_ENOADDR);
 }
=20
-static void
-bti2c_iic_setlines(device_t dev, int ctrl, int data)
+void bti2c_iic_setsda(device_t dev, int val)
 {
-	struct bti2c_softc *sc =3D (struct bti2c_softc *)device_get_softc(dev);
+	struct bktr_softc *sc  =3D (struct bktr_softc *)device_get_softc(dev);
+	int clock;
=20
-	OUTL(sc, BKTR_I2C_DATA_CTL, (ctrl << 1) | data);;
+	clock =3D INL(sc, BKTR_I2C_DATA_CTL) & 0x2;
+
+	if (val)
+		OUTL(sc, BKTR_I2C_DATA_CTL, clock | 1);
+	else
+		OUTL(sc, BKTR_I2C_DATA_CTL, clock);
+
 	DELAY(I2C_DELAY);
=20
 	return;
 }
=20
-static int
-bti2c_iic_getdataline(device_t dev)
+void bti2c_iic_setscl(device_t dev, int val)
+{
+	struct bktr_softc *sc  =3D (struct bktr_softc *)device_get_softc(dev);
+	int data;
+
+	data =3D INL(sc, BKTR_I2C_DATA_CTL) & 0x1;
+
+	if (val)
+		OUTL(sc, BKTR_I2C_DATA_CTL, 0x2 | data);
+	else
+		OUTL(sc, BKTR_I2C_DATA_CTL, data);
+
+	DELAY(I2C_DELAY);
+
+	return;
+}
+
+int
+bti2c_iic_getsda(device_t dev)
 {
-	struct bti2c_softc *sc =3D (struct bti2c_softc *)device_get_softc(dev);
+	struct bktr_softc *sc  =3D (struct bktr_softc *)device_get_softc(dev);
=20
-	return ( INL(sc,BKTR_I2C_DATA_CTL) & 0x1);
+	return (INL(sc,BKTR_I2C_DATA_CTL) & 0x1);
 }
=20
+int
+bti2c_iic_getscl(device_t dev)
+{
+	return (0);
+}
+
 static int
-bti2c_write(struct bti2c_softc* bti2c_sc, u_long data)
+bti2c_write(struct bktr_softc *sc, u_long data)
 {
 	u_long		x;
=20
 	/* clear status bits */
-	OUTL(bti2c_sc, BKTR_INT_STAT, (BT848_INT_RACK | BT848_INT_I2CDONE));
+	OUTL(sc, BKTR_INT_STAT, (BT848_INT_RACK | BT848_INT_I2CDONE));
=20
 	BTI2C_DEBUG(printf("w%lx", data));
=20
 	/* write the address and data */
-	OUTL(bti2c_sc, BKTR_I2C_DATA_CTL, data);
+	OUTL(sc, BKTR_I2C_DATA_CTL, data);
=20
 	/* wait for completion */
 	for ( x =3D 0x7fffffff; x; --x ) {	/* safety valve */
-		if ( INL(bti2c_sc, BKTR_INT_STAT) & BT848_INT_I2CDONE )
+		if ( INL(sc, BKTR_INT_STAT) & BT848_INT_I2CDONE )
 			break;
 	}
=20
 	/* check for ACK */
-	if ( !x || !( INL(bti2c_sc, BKTR_INT_STAT) & BT848_INT_RACK) ) {
+	if ( !x || !( INL(sc, BKTR_INT_STAT) & BT848_INT_RACK) ) {
 		BTI2C_DEBUG(printf("%c%c", (!x)?'+':'-',
-			(!( INL(bti2c_sc, BKTR_INT_STAT) & BT848_INT_RACK))?'+':'-'));
+			(!( INL(sc, BKTR_INT_STAT) & BT848_INT_RACK))?'+':'-'));
 		return (SMB_ENOACK);
 	}
 	BTI2C_DEBUG(printf("+"));
@@ -357,10 +275,10 @@
 	return( 0 );
 }
=20
-static int
+int
 bti2c_smb_writeb(device_t dev, u_char slave, char cmd, char byte)
 {
-	struct bti2c_softc *sc =3D (struct bti2c_softc *)device_get_softc(dev);
+	struct bktr_softc *sc  =3D (struct bktr_softc *)device_get_softc(dev);
 	u_long data;
=20
 	data =3D ((slave & 0xff) << 24) | ((byte & 0xff) << 16) | (u_char)cmd;
@@ -372,10 +290,10 @@
  * byte1 becomes low byte of word
  * byte2 becomes high byte of word
  */
-static int
+int
 bti2c_smb_writew(device_t dev, u_char slave, char cmd, short word)
 {
-	struct bti2c_softc *sc =3D (struct bti2c_softc *)device_get_softc(dev);
+	struct bktr_softc *sc  =3D (struct bktr_softc *)device_get_softc(dev);
 	u_long data;
 	char low, high;
=20
@@ -391,10 +309,10 @@
 /*
  * The Bt878 and Bt879 differed on the treatment of i2c commands
  */
-static int
+int
 bti2c_smb_readb(device_t dev, u_char slave, char cmd, char *byte)
 {
-	struct bti2c_softc *sc =3D (struct bti2c_softc *)device_get_softc(dev);
+	struct bktr_softc *sc  =3D (struct bktr_softc *)device_get_softc(dev);
 	u_long		x;
=20
 	/* clear status bits */
@@ -422,5 +340,3 @@
=20
 	return (0);
 }
-
-DRIVER_MODULE(bti2c, root, bti2c_driver, bti2c_devclass, 0, 0);
Index: dev/bktr//bktr_i2c.h
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /home/ncvs/src/sys/dev/bktr/bktr_i2c.h,v
retrieving revision 1.3
diff -u -r1.3 bktr_i2c.h
--- dev/bktr//bktr_i2c.h	2000/04/04 16:54:12	1.3
+++ dev/bktr//bktr_i2c.h	2001/07/19 17:15:09
@@ -1,5 +1,5 @@
 /*-
- * Copyright (c) 1998 Nicolas Souchu
+ * Copyright (c) 1998, 2001 Nicolas Souchu
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -29,6 +29,19 @@
 #ifndef _BT848_I2C_H
 #define _BT848_I2C_H
=20
-extern int bt848_i2c_attach(int, struct bktr_softc *bktr, struct bktr_i2c_=
softc *);
+extern int bt848_i2c_attach(device_t);
+extern int bt848_i2c_detach(device_t);
+
+extern int bti2c_iic_callback(device_t, int, caddr_t *);
+extern void bti2c_iic_setsda(device_t, int);
+extern void bti2c_iic_setscl(device_t, int);
+extern int bti2c_iic_getsda(device_t);
+extern int bti2c_iic_getscl(device_t);
+extern int bti2c_iic_reset(device_t, u_char, u_char, u_char *);
+
+extern int bti2c_smb_callback(device_t, int, caddr_t *);
+extern int bti2c_smb_writeb(device_t dev, u_char slave, char cmd, char byt=
e);
+extern int bti2c_smb_writew(device_t dev, u_char slave, char cmd, short wo=
rd);
+extern int bti2c_smb_readb(device_t dev, u_char slave, char cmd, char *byt=
e);
=20
 #endif
Index: dev/bktr//bktr_os.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /home/ncvs/src/sys/dev/bktr/bktr_os.c,v
retrieving revision 1.22
diff -u -r1.22 bktr_os.c
--- dev/bktr//bktr_os.c	2001/03/26 12:40:14	1.22
+++ dev/bktr//bktr_os.c	2001/07/19 17:19:19
@@ -49,7 +49,9 @@
=20
=20
 #ifdef __FreeBSD__
+#if ((__FreeBSD__ =3D=3D 2) || (__FreeBSD__ =3D=3D 3))
 #include "bktr.h"
+#endif
 #endif /* __FreeBSD__ */
=20
 #include "opt_bktr.h"		/* include any kernel config options */
@@ -83,7 +85,7 @@
 #include <vm/pmap.h>
 #include <vm/vm_extern.h>
=20
-#if (__FreeBSD_version >=3D400000) || (NSMBUS > 0)
+#if (__FreeBSD_version >=3D400000)
 #include <sys/bus.h>		/* used by smbus and newbus */
 #endif
=20
@@ -190,13 +192,19 @@
 #include <dev/bktr/bktr_audio.h>
 #include <dev/bktr/bktr_core.h>
 #include <dev/bktr/bktr_os.h>
+
 #if defined(BKTR_USE_FREEBSD_SMBUS)
 #include <dev/bktr/bktr_i2c.h>
+
+#include "iicbb_if.h"
+#include "smbus_if.h"
+
+#include "dev/iicbus/iiconf.h"
+#include "dev/smbus/smbconf.h"
 #endif
 #endif
=20
=20
-
 /****************************/
 /* *** FreeBSD 4.x code *** */
 /****************************/
@@ -215,6 +223,22 @@
 	DEVMETHOD(device_detach,        bktr_detach),
 	DEVMETHOD(device_shutdown,      bktr_shutdown),
=20
+#if defined(BKTR_USE_FREEBSD_SMBUS)
+	/* iicbb interface */
+	DEVMETHOD(iicbb_callback,	bti2c_iic_callback),
+	DEVMETHOD(iicbb_setsda,		bti2c_iic_setsda),
+	DEVMETHOD(iicbb_setscl,		bti2c_iic_setscl),
+	DEVMETHOD(iicbb_getsda,		bti2c_iic_getsda),
+	DEVMETHOD(iicbb_getscl,		bti2c_iic_getscl),
+	DEVMETHOD(iicbb_reset,		bti2c_iic_reset),
+=09
+	/* smbus interface */
+	DEVMETHOD(smbus_callback,	bti2c_smb_callback),
+	DEVMETHOD(smbus_writeb,		bti2c_smb_writeb),
+	DEVMETHOD(smbus_writew,		bti2c_smb_writew),
+	DEVMETHOD(smbus_readb,		bti2c_smb_readb),
+#endif
+
 	{ 0, 0 }
 };
=20
@@ -254,6 +278,10 @@
 DRIVER_MODULE(bktr, pci, bktr_driver, bktr_devclass, 0, 0);
 #if (__FreeBSD_version > 410000)
 MODULE_DEPEND(bktr, bktr_mem, 1,1,1);
+#if defined(BKTR_USE_FREEBSD_SMBUS)
+MODULE_DEPEND(bktr, iicbb, IICBB_MINVER, IICBB_PREFVER, IICBB_MAXVER);
+MODULE_DEPEND(bktr, smbus, SMBUS_MINVER, SMBUS_PREFVER, SMBUS_MAXVER);
+#endif
 MODULE_VERSION(bktr, 1);
 #endif
=20
@@ -392,14 +420,11 @@
 #endif
 	pci_write_config(dev, 0x40, fun, 2);
=20
-
-	/* XXX call bt848_i2c dependent attach() routine */
 #if defined(BKTR_USE_FREEBSD_SMBUS)
-	if (bt848_i2c_attach(unit, bktr, &bktr->i2c_sc))
+	if (bt848_i2c_attach(dev))
 		printf("bktr%d: i2c_attach: can't attach\n", unit);
 #endif
=20
-
 /*
  * PCI latency timer.  32 is a good value for 4 bus mastering slots, if
  * you have more than four, then 16 would probably be a better value.
@@ -477,6 +502,11 @@
 	OUTL(bktr, BKTR_INT_MASK, ALL_INTS_DISABLED);
 	OUTW(bktr, BKTR_GPIO_DMA_CTL, FIFO_RISC_DISABLED);
=20
+#if defined(BKTR_USE_FREEBSD_SMBUS)
+	if (bt848_i2c_detach(dev))
+		printf("bktr%d: i2c_attach: can't attach\n", unit);
+#endif
+
 	/* Note: We do not free memory for RISC programs, grab buffer, vbi buffer=
s */
 	/* The memory is retained by the bktr_mem module so we can unload and */
 	/* then reload the main bktr driver module */
@@ -981,13 +1011,10 @@
 #endif
 	pci_conf_write(tag, 0x40, fun);
=20
-
-	/* XXX call bt848_i2c dependent attach() routine */
 #if defined(BKTR_USE_FREEBSD_SMBUS)
-	if (bt848_i2c_attach(unit, bktr, &bktr->i2c_sc))
+	if (bt848_i2c_attach(dev))
 		printf("bktr%d: i2c_attach: can't attach\n", unit);
 #endif
-
=20
 /*
  * PCI latency timer.  32 is a good value for 4 bus mastering slots, if
Index: dev/bktr//bktr_reg.h
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /home/ncvs/src/sys/dev/bktr/bktr_reg.h,v
retrieving revision 1.42
diff -u -r1.42 bktr_reg.h
--- dev/bktr//bktr_reg.h	2000/10/31 13:09:56	1.42
+++ dev/bktr//bktr_reg.h	2001/07/19 17:15:09
@@ -34,17 +34,6 @@
  *
  */
=20
-#ifdef __FreeBSD__
-#  if (__FreeBSD_version >=3D 310000)
-#    include "smbus.h"
-#  else
-#    define NSMBUS 0		/* FreeBSD before 3.1 does not have SMBUS */
-#  endif
-#  if (NSMBUS > 0)
-#    define BKTR_USE_FREEBSD_SMBUS
-#  endif
-#endif
-
 #ifdef __NetBSD__
 #include <machine/bus.h>		/* struct device */
 #include <sys/device.h>
@@ -457,6 +446,9 @@
=20
 #if defined(BKTR_USE_FREEBSD_SMBUS)
 struct bktr_i2c_softc {
+	int bus_owned;
+
+	device_t iicbb;
 	device_t iicbus;
 	device_t smbus;
 };
@@ -556,9 +548,9 @@
     bus_space_handle_t	memh;	/* Bus space register access functions */
     bus_size_t		obmemsz;/* Size of card (bytes) */
     #endif
-    #if (NSMBUS > 0)
+#if defined(BKTR_USE_FREEBSD_SMBUS)
       struct bktr_i2c_softc i2c_sc;	/* bt848_i2c device */
-    #endif
+#endif
     char	bktr_xname[7];	/* device name and unit number */
 #endif
=20
Index: modules/bktr/bktr/Makefile
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /home/ncvs/src/sys/modules/bktr/bktr/Makefile,v
retrieving revision 1.2
diff -u -r1.2 Makefile
--- modules/bktr/bktr/Makefile	2001/01/06 13:59:41	1.2
+++ modules/bktr/bktr/Makefile	2001/07/19 17:22:18
@@ -5,18 +5,9 @@
 .PATH: ${.CURDIR}/../../../dev/bktr
=20
 KMOD=3D	bktr=20
-SRCS=3D	bktr_core.c bktr_os.c bktr_audio.c bktr_tuner.c bktr_card.c \
-	bktr.h opt_devfs.h opt_bktr.h smbus.h bus_if.h device_if.h \
-	pci_if.h vnode_if.h
-CLEANFILES=3D bktr.h smbus.h
-
-bktr.h:
-	echo "#define NBKTR 1" > bktr.h
-	echo "#define BKTR_FREEBSD_MODULE 1" >> bktr.h
-
-# Does not use SMBUS/IICBUS. Uses the old i2c code self contained in
-# the bt848 driver.
-smbus.h:
-	echo "#define NSMBUS 0" > smbus.h
+SRCS=3D	bktr_i2c.c bktr_core.c bktr_os.c bktr_audio.c bktr_tuner.c bktr_ca=
rd.c \
+	opt_devfs.h opt_bktr.h iicbb_if.h iicbus_if.h smbus_if.h \
+	bus_if.h device_if.h pci_if.h vnode_if.h
+CFLAGS+=3D -DBKTR_USE_FREEBSD_SMBUS -DBKTR_FREEBSD_MODULE
=20
 .include <bsd.kmod.mk>

--FCuugMFkClbJLl1L
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: For info see http://www.gnupg.org

iD8DBQE7VxfnXY6L6fI4GtQRAvlyAJ0UCkeQfIfeaCl7L4uN1jAxFejXSACaAnol
ipgSqkNv6OhUuz9JqHJeF4M=
=pc07
-----END PGP SIGNATURE-----

--FCuugMFkClbJLl1L--

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-multimedia" in the body of the message




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