Home | History | Annotate | Line # | Download | only in pci
ichsmb.c revision 1.10.4.1
      1  1.10.4.1        ad /*	$NetBSD: ichsmb.c,v 1.10.4.1 2007/12/26 19:46:48 ad Exp $	*/
      2       1.1  kiyohara /*	$OpenBSD: ichiic.c,v 1.18 2007/05/03 09:36:26 dlg Exp $	*/
      3       1.1  kiyohara 
      4       1.1  kiyohara /*
      5       1.1  kiyohara  * Copyright (c) 2005, 2006 Alexander Yurchenko <grange (at) openbsd.org>
      6       1.1  kiyohara  *
      7       1.1  kiyohara  * Permission to use, copy, modify, and distribute this software for any
      8       1.1  kiyohara  * purpose with or without fee is hereby granted, provided that the above
      9       1.1  kiyohara  * copyright notice and this permission notice appear in all copies.
     10       1.1  kiyohara  *
     11       1.1  kiyohara  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
     12       1.1  kiyohara  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
     13       1.1  kiyohara  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
     14       1.1  kiyohara  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
     15       1.1  kiyohara  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
     16       1.1  kiyohara  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
     17       1.1  kiyohara  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
     18       1.1  kiyohara  */
     19       1.1  kiyohara 
     20       1.1  kiyohara /*
     21       1.1  kiyohara  * Intel ICH SMBus controller driver.
     22       1.1  kiyohara  */
     23       1.1  kiyohara 
     24       1.6   xtraeme #include <sys/cdefs.h>
     25  1.10.4.1        ad __KERNEL_RCSID(0, "$NetBSD: ichsmb.c,v 1.10.4.1 2007/12/26 19:46:48 ad Exp $");
     26       1.6   xtraeme 
     27       1.1  kiyohara #include <sys/param.h>
     28       1.1  kiyohara #include <sys/device.h>
     29       1.1  kiyohara #include <sys/errno.h>
     30       1.1  kiyohara #include <sys/kernel.h>
     31       1.8   xtraeme #include <sys/rwlock.h>
     32       1.1  kiyohara #include <sys/proc.h>
     33       1.1  kiyohara 
     34      1.10        ad #include <sys/bus.h>
     35       1.1  kiyohara 
     36       1.1  kiyohara #include <dev/pci/pcidevs.h>
     37       1.1  kiyohara #include <dev/pci/pcireg.h>
     38       1.1  kiyohara #include <dev/pci/pcivar.h>
     39       1.1  kiyohara 
     40       1.5   xtraeme #include <dev/ic/i82801lpcreg.h>
     41       1.1  kiyohara 
     42       1.1  kiyohara #include <dev/i2c/i2cvar.h>
     43       1.1  kiyohara 
     44       1.1  kiyohara #ifdef ICHIIC_DEBUG
     45       1.1  kiyohara #define DPRINTF(x) printf x
     46       1.1  kiyohara #else
     47       1.1  kiyohara #define DPRINTF(x)
     48       1.1  kiyohara #endif
     49       1.1  kiyohara 
     50       1.1  kiyohara #define ICHIIC_DELAY	100
     51       1.1  kiyohara #define ICHIIC_TIMEOUT	1
     52       1.1  kiyohara 
     53       1.1  kiyohara struct ichsmb_softc {
     54       1.1  kiyohara 	struct device		sc_dev;
     55       1.1  kiyohara 
     56       1.1  kiyohara 	bus_space_tag_t		sc_iot;
     57       1.1  kiyohara 	bus_space_handle_t	sc_ioh;
     58       1.1  kiyohara 	void *			sc_ih;
     59       1.1  kiyohara 	int			sc_poll;
     60       1.1  kiyohara 
     61       1.1  kiyohara 	struct i2c_controller	sc_i2c_tag;
     62       1.8   xtraeme 	krwlock_t 		sc_i2c_rwlock;
     63       1.1  kiyohara 	struct {
     64       1.1  kiyohara 		i2c_op_t     op;
     65       1.1  kiyohara 		void *       buf;
     66       1.1  kiyohara 		size_t       len;
     67       1.1  kiyohara 		int          flags;
     68       1.1  kiyohara 		volatile int error;
     69       1.1  kiyohara 	}			sc_i2c_xfer;
     70       1.1  kiyohara };
     71       1.1  kiyohara 
     72       1.1  kiyohara static int	ichsmb_match(struct device *, struct cfdata *, void *);
     73       1.1  kiyohara static void	ichsmb_attach(struct device *, struct device *, void *);
     74       1.1  kiyohara 
     75       1.1  kiyohara static int	ichsmb_i2c_acquire_bus(void *, int);
     76       1.1  kiyohara static void	ichsmb_i2c_release_bus(void *, int);
     77       1.1  kiyohara static int	ichsmb_i2c_exec(void *, i2c_op_t, i2c_addr_t, const void *,
     78       1.1  kiyohara 		    size_t, void *, size_t, int);
     79       1.1  kiyohara 
     80       1.1  kiyohara static int	ichsmb_intr(void *);
     81       1.1  kiyohara 
     82       1.1  kiyohara 
     83       1.1  kiyohara CFATTACH_DECL(ichsmb, sizeof(struct ichsmb_softc),
     84       1.1  kiyohara     ichsmb_match, ichsmb_attach, NULL, NULL);
     85       1.1  kiyohara 
     86       1.1  kiyohara 
     87       1.1  kiyohara static int
     88       1.1  kiyohara ichsmb_match(struct device *parent, struct cfdata *match, void *aux)
     89       1.1  kiyohara {
     90       1.1  kiyohara 	struct pci_attach_args *pa = aux;
     91       1.1  kiyohara 
     92       1.1  kiyohara 	if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_INTEL) {
     93       1.1  kiyohara 		switch (PCI_PRODUCT(pa->pa_id)) {
     94       1.1  kiyohara 		case PCI_PRODUCT_INTEL_6300ESB_SMB:
     95       1.1  kiyohara 		case PCI_PRODUCT_INTEL_63XXESB_SMB:
     96       1.1  kiyohara 		case PCI_PRODUCT_INTEL_82801AA_SMB:
     97       1.1  kiyohara 		case PCI_PRODUCT_INTEL_82801AB_SMB:
     98       1.1  kiyohara 		case PCI_PRODUCT_INTEL_82801BA_SMB:
     99       1.1  kiyohara 		case PCI_PRODUCT_INTEL_82801CA_SMB:
    100       1.1  kiyohara 		case PCI_PRODUCT_INTEL_82801DB_SMB:
    101       1.1  kiyohara 		case PCI_PRODUCT_INTEL_82801E_SMB:
    102       1.1  kiyohara 		case PCI_PRODUCT_INTEL_82801EB_SMB:
    103       1.1  kiyohara 		case PCI_PRODUCT_INTEL_82801FB_SMB:
    104       1.1  kiyohara 		case PCI_PRODUCT_INTEL_82801G_SMB:
    105       1.1  kiyohara 		case PCI_PRODUCT_INTEL_82801H_SMB:
    106       1.7   xtraeme 		case PCI_PRODUCT_INTEL_82801I_SMB:
    107       1.1  kiyohara 			return 1;
    108       1.1  kiyohara 		}
    109       1.1  kiyohara 	}
    110       1.1  kiyohara 	return 0;
    111       1.1  kiyohara }
    112       1.1  kiyohara 
    113       1.1  kiyohara static void
    114       1.1  kiyohara ichsmb_attach(struct device *parent, struct device *self, void *aux)
    115       1.1  kiyohara {
    116       1.1  kiyohara 	struct ichsmb_softc *sc = (struct ichsmb_softc *)self;
    117       1.1  kiyohara 	struct pci_attach_args *pa = aux;
    118       1.1  kiyohara 	struct i2cbus_attach_args iba;
    119       1.1  kiyohara 	pcireg_t conf;
    120       1.1  kiyohara 	bus_size_t iosize;
    121       1.1  kiyohara 	pci_intr_handle_t ih;
    122       1.1  kiyohara 	const char *intrstr = NULL;
    123       1.1  kiyohara 	char devinfo[256];
    124       1.1  kiyohara 
    125       1.1  kiyohara 	aprint_naive("\n");
    126       1.1  kiyohara 	pci_devinfo(pa->pa_id, pa->pa_class, 0, devinfo, sizeof(devinfo));
    127       1.1  kiyohara 	aprint_normal(": %s (rev. 0x%02x)\n", devinfo,
    128       1.1  kiyohara 	    PCI_REVISION(pa->pa_class));
    129       1.1  kiyohara 
    130       1.1  kiyohara 	/* Read configuration */
    131       1.5   xtraeme 	conf = pci_conf_read(pa->pa_pc, pa->pa_tag, LPCIB_SMB_HOSTC);
    132       1.1  kiyohara 	DPRINTF(("%s: conf 0x%08x", sc->sc_dev.dv_xname, conf));
    133       1.1  kiyohara 
    134       1.5   xtraeme 	if ((conf & LPCIB_SMB_HOSTC_HSTEN) == 0) {
    135       1.1  kiyohara 		aprint_error("%s: SMBus disabled\n", sc->sc_dev.dv_xname);
    136       1.1  kiyohara 		return;
    137       1.1  kiyohara 	}
    138       1.1  kiyohara 
    139       1.1  kiyohara 	/* Map I/O space */
    140       1.5   xtraeme 	if (pci_mapreg_map(pa, LPCIB_SMB_BASE, PCI_MAPREG_TYPE_IO, 0,
    141       1.1  kiyohara 	    &sc->sc_iot, &sc->sc_ioh, NULL, &iosize)) {
    142       1.1  kiyohara 		aprint_error("%s: can't map I/O space\n", sc->sc_dev.dv_xname);
    143       1.1  kiyohara 		return;
    144       1.1  kiyohara 	}
    145       1.1  kiyohara 
    146       1.1  kiyohara 	sc->sc_poll = 1;
    147       1.5   xtraeme 	if (conf & LPCIB_SMB_HOSTC_SMIEN) {
    148       1.1  kiyohara 		/* No PCI IRQ */
    149       1.1  kiyohara 		aprint_normal("%s: SMI\n", sc->sc_dev.dv_xname);
    150       1.1  kiyohara 	} else {
    151       1.1  kiyohara 		/* Install interrupt handler */
    152       1.1  kiyohara 		if (pci_intr_map(pa, &ih) == 0) {
    153       1.1  kiyohara 			intrstr = pci_intr_string(pa->pa_pc, ih);
    154       1.1  kiyohara 			sc->sc_ih = pci_intr_establish(pa->pa_pc, ih, IPL_BIO,
    155       1.1  kiyohara 			    ichsmb_intr, sc);
    156       1.1  kiyohara 			if (sc->sc_ih != NULL) {
    157       1.1  kiyohara 				aprint_normal("%s: interrupting at %s\n",
    158       1.1  kiyohara 				    sc->sc_dev.dv_xname, intrstr);
    159       1.1  kiyohara 				sc->sc_poll = 0;
    160       1.1  kiyohara 			}
    161       1.1  kiyohara 		}
    162       1.1  kiyohara 		if (sc->sc_poll)
    163       1.1  kiyohara 			aprint_normal("%s: polling\n", sc->sc_dev.dv_xname);
    164       1.1  kiyohara 	}
    165       1.1  kiyohara 
    166       1.1  kiyohara 	/* Attach I2C bus */
    167       1.8   xtraeme 	rw_init(&sc->sc_i2c_rwlock);
    168       1.1  kiyohara 	sc->sc_i2c_tag.ic_cookie = sc;
    169       1.1  kiyohara 	sc->sc_i2c_tag.ic_acquire_bus = ichsmb_i2c_acquire_bus;
    170       1.1  kiyohara 	sc->sc_i2c_tag.ic_release_bus = ichsmb_i2c_release_bus;
    171       1.1  kiyohara 	sc->sc_i2c_tag.ic_exec = ichsmb_i2c_exec;
    172       1.1  kiyohara 
    173       1.1  kiyohara 	bzero(&iba, sizeof(iba));
    174       1.9       riz 	iba.iba_type = I2C_TYPE_SMBUS;
    175       1.1  kiyohara 	iba.iba_tag = &sc->sc_i2c_tag;
    176       1.1  kiyohara 	config_found(self, &iba, iicbus_print);
    177       1.1  kiyohara 
    178  1.10.4.1        ad 	if (!pmf_device_register(self, NULL, NULL))
    179  1.10.4.1        ad 		aprint_error_dev(self, "couldn't establish power handler\n");
    180       1.1  kiyohara }
    181       1.1  kiyohara 
    182       1.1  kiyohara static int
    183       1.1  kiyohara ichsmb_i2c_acquire_bus(void *cookie, int flags)
    184       1.1  kiyohara {
    185       1.1  kiyohara 	struct ichsmb_softc *sc = cookie;
    186       1.1  kiyohara 
    187       1.1  kiyohara 	if (cold || sc->sc_poll || (flags & I2C_F_POLL))
    188       1.8   xtraeme 		return 0;
    189       1.1  kiyohara 
    190       1.8   xtraeme 	rw_enter(&sc->sc_i2c_rwlock, RW_WRITER);
    191       1.8   xtraeme 	return 0;
    192       1.1  kiyohara }
    193       1.1  kiyohara 
    194       1.1  kiyohara static void
    195       1.1  kiyohara ichsmb_i2c_release_bus(void *cookie, int flags)
    196       1.1  kiyohara {
    197       1.1  kiyohara 	struct ichsmb_softc *sc = cookie;
    198       1.1  kiyohara 
    199       1.1  kiyohara 	if (cold || sc->sc_poll || (flags & I2C_F_POLL))
    200       1.1  kiyohara 		return;
    201       1.1  kiyohara 
    202       1.8   xtraeme 	rw_exit(&sc->sc_i2c_rwlock);
    203       1.1  kiyohara }
    204       1.1  kiyohara 
    205       1.1  kiyohara static int
    206       1.1  kiyohara ichsmb_i2c_exec(void *cookie, i2c_op_t op, i2c_addr_t addr,
    207       1.1  kiyohara     const void *cmdbuf, size_t cmdlen, void *buf, size_t len, int flags)
    208       1.1  kiyohara {
    209       1.1  kiyohara 	struct ichsmb_softc *sc = cookie;
    210       1.1  kiyohara 	const uint8_t *b;
    211       1.1  kiyohara 	uint8_t ctl = 0, st;
    212       1.1  kiyohara 	int retries;
    213       1.4  kiyohara 	char fbuf[64];
    214       1.1  kiyohara 
    215       1.3   xtraeme 	DPRINTF(("%s: exec: op %d, addr 0x%02x, cmdlen %zu, len %d, "
    216       1.1  kiyohara 	    "flags 0x%02x\n", sc->sc_dev.dv_xname, op, addr, cmdlen,
    217       1.1  kiyohara 	    len, flags));
    218       1.1  kiyohara 
    219       1.1  kiyohara 	/* Wait for bus to be idle */
    220       1.1  kiyohara 	for (retries = 100; retries > 0; retries--) {
    221       1.5   xtraeme 		st = bus_space_read_1(sc->sc_iot, sc->sc_ioh, LPCIB_SMB_HS);
    222       1.5   xtraeme 		if (!(st & LPCIB_SMB_HS_BUSY))
    223       1.1  kiyohara 			break;
    224       1.1  kiyohara 		DELAY(ICHIIC_DELAY);
    225       1.1  kiyohara 	}
    226       1.4  kiyohara #ifdef ICHIIC_DEBUG
    227       1.5   xtraeme 	bitmask_snprintf(st, LPCIB_SMB_HS_BITS, fbuf, sizeof(fbuf));
    228       1.4  kiyohara 	printf("%s: exec: st 0x%s\n", sc->sc_dev.dv_xname, fbuf);
    229       1.4  kiyohara #endif
    230       1.5   xtraeme 	if (st & LPCIB_SMB_HS_BUSY)
    231       1.1  kiyohara 		return (1);
    232       1.1  kiyohara 
    233       1.1  kiyohara 	if (cold || sc->sc_poll)
    234       1.1  kiyohara 		flags |= I2C_F_POLL;
    235       1.1  kiyohara 
    236       1.1  kiyohara 	if (!I2C_OP_STOP_P(op) || cmdlen > 1 || len > 2)
    237       1.1  kiyohara 		return (1);
    238       1.1  kiyohara 
    239       1.1  kiyohara 	/* Setup transfer */
    240       1.1  kiyohara 	sc->sc_i2c_xfer.op = op;
    241       1.1  kiyohara 	sc->sc_i2c_xfer.buf = buf;
    242       1.1  kiyohara 	sc->sc_i2c_xfer.len = len;
    243       1.1  kiyohara 	sc->sc_i2c_xfer.flags = flags;
    244       1.1  kiyohara 	sc->sc_i2c_xfer.error = 0;
    245       1.1  kiyohara 
    246       1.1  kiyohara 	/* Set slave address and transfer direction */
    247       1.5   xtraeme 	bus_space_write_1(sc->sc_iot, sc->sc_ioh, LPCIB_SMB_TXSLVA,
    248       1.5   xtraeme 	    LPCIB_SMB_TXSLVA_ADDR(addr) |
    249       1.5   xtraeme 	    (I2C_OP_READ_P(op) ? LPCIB_SMB_TXSLVA_READ : 0));
    250       1.1  kiyohara 
    251       1.1  kiyohara 	b = (const uint8_t *)cmdbuf;
    252       1.1  kiyohara 	if (cmdlen > 0)
    253       1.1  kiyohara 		/* Set command byte */
    254       1.5   xtraeme 		bus_space_write_1(sc->sc_iot, sc->sc_ioh, LPCIB_SMB_HCMD, b[0]);
    255       1.1  kiyohara 
    256       1.1  kiyohara 	if (I2C_OP_WRITE_P(op)) {
    257       1.1  kiyohara 		/* Write data */
    258       1.1  kiyohara 		b = buf;
    259       1.1  kiyohara 		if (len > 0)
    260       1.1  kiyohara 			bus_space_write_1(sc->sc_iot, sc->sc_ioh,
    261       1.5   xtraeme 			    LPCIB_SMB_HD0, b[0]);
    262       1.1  kiyohara 		if (len > 1)
    263       1.1  kiyohara 			bus_space_write_1(sc->sc_iot, sc->sc_ioh,
    264       1.5   xtraeme 			    LPCIB_SMB_HD1, b[1]);
    265       1.1  kiyohara 	}
    266       1.1  kiyohara 
    267       1.1  kiyohara 	/* Set SMBus command */
    268       1.1  kiyohara 	if (len == 0)
    269       1.5   xtraeme 		ctl = LPCIB_SMB_HC_CMD_BYTE;
    270       1.1  kiyohara 	else if (len == 1)
    271       1.5   xtraeme 		ctl = LPCIB_SMB_HC_CMD_BDATA;
    272       1.1  kiyohara 	else if (len == 2)
    273       1.5   xtraeme 		ctl = LPCIB_SMB_HC_CMD_WDATA;
    274       1.1  kiyohara 
    275       1.1  kiyohara 	if ((flags & I2C_F_POLL) == 0)
    276       1.5   xtraeme 		ctl |= LPCIB_SMB_HC_INTREN;
    277       1.1  kiyohara 
    278       1.1  kiyohara 	/* Start transaction */
    279       1.5   xtraeme 	ctl |= LPCIB_SMB_HC_START;
    280       1.5   xtraeme 	bus_space_write_1(sc->sc_iot, sc->sc_ioh, LPCIB_SMB_HC, ctl);
    281       1.1  kiyohara 
    282       1.1  kiyohara 	if (flags & I2C_F_POLL) {
    283       1.1  kiyohara 		/* Poll for completion */
    284       1.1  kiyohara 		DELAY(ICHIIC_DELAY);
    285       1.1  kiyohara 		for (retries = 1000; retries > 0; retries--) {
    286       1.1  kiyohara 			st = bus_space_read_1(sc->sc_iot, sc->sc_ioh,
    287       1.5   xtraeme 			    LPCIB_SMB_HS);
    288       1.5   xtraeme 			if ((st & LPCIB_SMB_HS_BUSY) == 0)
    289       1.1  kiyohara 				break;
    290       1.1  kiyohara 			DELAY(ICHIIC_DELAY);
    291       1.1  kiyohara 		}
    292       1.5   xtraeme 		if (st & LPCIB_SMB_HS_BUSY)
    293       1.1  kiyohara 			goto timeout;
    294       1.1  kiyohara 		ichsmb_intr(sc);
    295       1.1  kiyohara 	} else {
    296       1.1  kiyohara 		/* Wait for interrupt */
    297       1.1  kiyohara 		if (tsleep(sc, PRIBIO, "iicexec", ICHIIC_TIMEOUT * hz))
    298       1.1  kiyohara 			goto timeout;
    299       1.1  kiyohara 	}
    300       1.1  kiyohara 
    301       1.1  kiyohara 	if (sc->sc_i2c_xfer.error)
    302       1.1  kiyohara 		return (1);
    303       1.1  kiyohara 
    304       1.1  kiyohara 	return (0);
    305       1.1  kiyohara 
    306       1.1  kiyohara timeout:
    307       1.1  kiyohara 	/*
    308       1.1  kiyohara 	 * Transfer timeout. Kill the transaction and clear status bits.
    309       1.1  kiyohara 	 */
    310       1.5   xtraeme 	bitmask_snprintf(st, LPCIB_SMB_HS_BITS, fbuf, sizeof(fbuf));
    311       1.2   xtraeme 	printf("%s: exec: op %d, addr 0x%02x, cmdlen %zd, len %zd, "
    312       1.4  kiyohara 	    "flags 0x%02x: timeout, status 0x%s\n",
    313       1.4  kiyohara 	    sc->sc_dev.dv_xname, op, addr, cmdlen, len, flags, fbuf);
    314       1.5   xtraeme 	bus_space_write_1(sc->sc_iot, sc->sc_ioh, LPCIB_SMB_HC,
    315       1.5   xtraeme 	    LPCIB_SMB_HC_KILL);
    316       1.1  kiyohara 	DELAY(ICHIIC_DELAY);
    317       1.5   xtraeme 	st = bus_space_read_1(sc->sc_iot, sc->sc_ioh, LPCIB_SMB_HS);
    318       1.5   xtraeme 	if ((st & LPCIB_SMB_HS_FAILED) == 0) {
    319       1.5   xtraeme 		bitmask_snprintf(st, LPCIB_SMB_HS_BITS, fbuf, sizeof(fbuf));
    320       1.4  kiyohara 		printf("%s: abort failed, status 0x%s\n",
    321       1.4  kiyohara 		    sc->sc_dev.dv_xname, fbuf);
    322       1.4  kiyohara 	}
    323       1.5   xtraeme 	bus_space_write_1(sc->sc_iot, sc->sc_ioh, LPCIB_SMB_HS, st);
    324       1.1  kiyohara 	return (1);
    325       1.1  kiyohara }
    326       1.1  kiyohara 
    327       1.1  kiyohara static int
    328       1.1  kiyohara ichsmb_intr(void *arg)
    329       1.1  kiyohara {
    330       1.1  kiyohara 	struct ichsmb_softc *sc = arg;
    331       1.1  kiyohara 	uint8_t st;
    332       1.1  kiyohara 	uint8_t *b;
    333       1.1  kiyohara 	size_t len;
    334       1.4  kiyohara #ifdef ICHIIC_DEBUG
    335       1.4  kiyohara 	char fbuf[64];
    336       1.4  kiyohara #endif
    337       1.1  kiyohara 
    338       1.1  kiyohara 	/* Read status */
    339       1.5   xtraeme 	st = bus_space_read_1(sc->sc_iot, sc->sc_ioh, LPCIB_SMB_HS);
    340       1.5   xtraeme 	if ((st & LPCIB_SMB_HS_BUSY) != 0 || (st & (LPCIB_SMB_HS_INTR |
    341       1.5   xtraeme 	    LPCIB_SMB_HS_DEVERR | LPCIB_SMB_HS_BUSERR | LPCIB_SMB_HS_FAILED |
    342       1.5   xtraeme 	    LPCIB_SMB_HS_SMBAL | LPCIB_SMB_HS_BDONE)) == 0)
    343       1.1  kiyohara 		/* Interrupt was not for us */
    344       1.1  kiyohara 		return (0);
    345       1.1  kiyohara 
    346       1.4  kiyohara #ifdef ICHIIC_DEBUG
    347       1.5   xtraeme 	bitmask_snprintf(st, LPCIB_SMB_HS_BITS, fbuf, sizeof(fbuf));
    348       1.4  kiyohara 	printf("%s: intr st 0x%s\n", sc->sc_dev.dv_xname, fbuf);
    349       1.4  kiyohara #endif
    350       1.1  kiyohara 
    351       1.1  kiyohara 	/* Clear status bits */
    352       1.5   xtraeme 	bus_space_write_1(sc->sc_iot, sc->sc_ioh, LPCIB_SMB_HS, st);
    353       1.1  kiyohara 
    354       1.1  kiyohara 	/* Check for errors */
    355       1.5   xtraeme 	if (st & (LPCIB_SMB_HS_DEVERR | LPCIB_SMB_HS_BUSERR | LPCIB_SMB_HS_FAILED)) {
    356       1.1  kiyohara 		sc->sc_i2c_xfer.error = 1;
    357       1.1  kiyohara 		goto done;
    358       1.1  kiyohara 	}
    359       1.1  kiyohara 
    360       1.5   xtraeme 	if (st & LPCIB_SMB_HS_INTR) {
    361       1.1  kiyohara 		if (I2C_OP_WRITE_P(sc->sc_i2c_xfer.op))
    362       1.1  kiyohara 			goto done;
    363       1.1  kiyohara 
    364       1.1  kiyohara 		/* Read data */
    365       1.1  kiyohara 		b = sc->sc_i2c_xfer.buf;
    366       1.1  kiyohara 		len = sc->sc_i2c_xfer.len;
    367       1.1  kiyohara 		if (len > 0)
    368       1.1  kiyohara 			b[0] = bus_space_read_1(sc->sc_iot, sc->sc_ioh,
    369       1.5   xtraeme 			    LPCIB_SMB_HD0);
    370       1.1  kiyohara 		if (len > 1)
    371       1.1  kiyohara 			b[1] = bus_space_read_1(sc->sc_iot, sc->sc_ioh,
    372       1.5   xtraeme 			    LPCIB_SMB_HD1);
    373       1.1  kiyohara 	}
    374       1.1  kiyohara 
    375       1.1  kiyohara done:
    376       1.1  kiyohara 	if ((sc->sc_i2c_xfer.flags & I2C_F_POLL) == 0)
    377       1.1  kiyohara 		wakeup(sc);
    378       1.1  kiyohara 	return (1);
    379       1.1  kiyohara }
    380