Home | History | Annotate | Line # | Download | only in pci
amdpm_smbus.c revision 1.12.6.1
      1  1.12.6.1        ad /*	$NetBSD: amdpm_smbus.c,v 1.12.6.1 2007/10/09 13:41:40 ad Exp $ */
      2       1.1       tls 
      3       1.1       tls /*
      4       1.1       tls  * Copyright (c) 2005 Anil Gopinath (anil_public (at) yahoo.com)
      5       1.1       tls  * All rights reserved.
      6       1.1       tls  *
      7       1.1       tls  * Redistribution and use in source and binary forms, with or without
      8       1.1       tls  * modification, are permitted provided that the following conditions
      9       1.1       tls  * are met:
     10       1.1       tls  * 1. Redistributions of source code must retain the above copyright
     11       1.1       tls  *    notice, this list of conditions and the following disclaimer.
     12       1.1       tls  * 2. Redistributions in binary form must reproduce the above copyright
     13       1.1       tls  *    notice, this list of conditions and the following disclaimer in the
     14       1.1       tls  *    documentation and/or other materials provided with the distribution.
     15       1.1       tls  * 3. The name of the author may not be used to endorse or promote products
     16       1.1       tls  *    derived from this software without specific prior written permission.
     17       1.1       tls  *
     18       1.1       tls  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     19       1.1       tls  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     20       1.1       tls  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     21       1.1       tls  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     22       1.1       tls  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
     23       1.1       tls  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
     24       1.1       tls  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
     25       1.1       tls  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
     26       1.1       tls  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     27       1.1       tls  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     28       1.1       tls  * SUCH DAMAGE.
     29       1.1       tls  */
     30       1.1       tls 
     31       1.1       tls /* driver for SMBUS 1.0 host controller found in the
     32       1.1       tls  * AMD-8111 HyperTransport I/O Hub
     33       1.1       tls  */
     34       1.2   xtraeme #include <sys/cdefs.h>
     35  1.12.6.1        ad __KERNEL_RCSID(0, "$NetBSD: amdpm_smbus.c,v 1.12.6.1 2007/10/09 13:41:40 ad Exp $");
     36       1.2   xtraeme 
     37       1.1       tls #include <sys/param.h>
     38       1.1       tls #include <sys/systm.h>
     39       1.1       tls #include <sys/kernel.h>
     40       1.1       tls #include <sys/device.h>
     41       1.1       tls #include <sys/rnd.h>
     42  1.12.6.1        ad #include <sys/rwlock.h>
     43  1.12.6.1        ad 
     44       1.1       tls #include <dev/pci/pcireg.h>
     45       1.1       tls #include <dev/pci/pcivar.h>
     46       1.1       tls #include <dev/pci/pcidevs.h>
     47       1.1       tls 
     48       1.1       tls #include <dev/i2c/i2cvar.h>
     49       1.1       tls #include <dev/i2c/i2c_bitbang.h>
     50       1.1       tls 
     51       1.1       tls #include <dev/pci/amdpmreg.h>
     52       1.1       tls #include <dev/pci/amdpmvar.h>
     53       1.1       tls 
     54       1.1       tls #include <dev/pci/amdpm_smbusreg.h>
     55       1.1       tls 
     56      1.10  jmcneill #ifdef __i386__
     57      1.10  jmcneill #include "opt_xbox.h"
     58      1.10  jmcneill #endif
     59      1.10  jmcneill 
     60      1.10  jmcneill #ifdef XBOX
     61      1.10  jmcneill extern int arch_i386_is_xbox;
     62      1.10  jmcneill #endif
     63      1.10  jmcneill 
     64  1.12.6.1        ad static int       amdpm_smbus_acquire_bus(void *, int);
     65  1.12.6.1        ad static void      amdpm_smbus_release_bus(void *, int);
     66  1.12.6.1        ad static int       amdpm_smbus_exec(void *, i2c_op_t, i2c_addr_t, const void *,
     67  1.12.6.1        ad 				  size_t, void *, size_t, int);
     68  1.12.6.1        ad static int       amdpm_smbus_check_done(struct amdpm_softc *, i2c_op_t);
     69  1.12.6.1        ad static void      amdpm_smbus_clear_gsr(struct amdpm_softc *);
     70  1.12.6.1        ad static uint16_t	amdpm_smbus_get_gsr(struct amdpm_softc *);
     71  1.12.6.1        ad static int       amdpm_smbus_send_1(struct amdpm_softc *, uint8_t, i2c_op_t);
     72  1.12.6.1        ad static int       amdpm_smbus_write_1(struct amdpm_softc *, uint8_t,
     73  1.12.6.1        ad 				     uint8_t, i2c_op_t);
     74  1.12.6.1        ad static int       amdpm_smbus_receive_1(struct amdpm_softc *, i2c_op_t);
     75  1.12.6.1        ad static int       amdpm_smbus_read_1(struct amdpm_softc *sc, uint8_t, i2c_op_t);
     76       1.1       tls 
     77      1.12  jmcneill #ifdef XBOX
     78      1.10  jmcneill static int	 amdpm_smbus_intr(void *);
     79      1.12  jmcneill #endif
     80       1.1       tls 
     81       1.1       tls void
     82       1.1       tls amdpm_smbus_attach(struct amdpm_softc *sc)
     83       1.1       tls {
     84       1.1       tls         struct i2cbus_attach_args iba;
     85      1.12  jmcneill #ifdef XBOX
     86      1.10  jmcneill 	pci_intr_handle_t ih;
     87      1.10  jmcneill 	const char *intrstr;
     88      1.12  jmcneill #endif
     89       1.1       tls 
     90       1.5  jmcneill 	/* register with iic */
     91       1.1       tls 	sc->sc_i2c.ic_cookie = sc;
     92       1.1       tls 	sc->sc_i2c.ic_acquire_bus = amdpm_smbus_acquire_bus;
     93       1.1       tls 	sc->sc_i2c.ic_release_bus = amdpm_smbus_release_bus;
     94       1.1       tls 	sc->sc_i2c.ic_send_start = NULL;
     95       1.1       tls 	sc->sc_i2c.ic_send_stop = NULL;
     96       1.1       tls 	sc->sc_i2c.ic_initiate_xfer = NULL;
     97       1.1       tls 	sc->sc_i2c.ic_read_byte = NULL;
     98       1.1       tls 	sc->sc_i2c.ic_write_byte = NULL;
     99       1.1       tls 	sc->sc_i2c.ic_exec = amdpm_smbus_exec;
    100       1.3   xtraeme 
    101  1.12.6.1        ad 	rw_init(&sc->sc_rwlock);
    102       1.3   xtraeme 
    103      1.10  jmcneill #ifdef XBOX
    104      1.10  jmcneill #define XBOX_SMBA	0x8000
    105      1.10  jmcneill #define XBOX_SMSIZE	256
    106      1.10  jmcneill #define XBOX_INTRLINE	12
    107      1.11  jmcneill #define XBOX_REG_ACPI_PM1a_EN		0x02
    108      1.11  jmcneill #define XBOX_REG_ACPI_PM1a_EN_TIMER		0x01
    109      1.10  jmcneill 	/* XXX pci0 dev 1 function 2 "System Management" doesn't probe */
    110      1.10  jmcneill 	if (arch_i386_is_xbox) {
    111      1.11  jmcneill 		uint16_t val;
    112      1.10  jmcneill 		sc->sc_pa->pa_intrline = XBOX_INTRLINE;
    113      1.10  jmcneill 
    114      1.10  jmcneill 		if (bus_space_map(sc->sc_iot, XBOX_SMBA, XBOX_SMSIZE,
    115      1.11  jmcneill 		    0, &sc->sc_sm_ioh) == 0) {
    116      1.10  jmcneill 			aprint_normal("%s: system management at 0x%04x\n",
    117      1.10  jmcneill 			    sc->sc_dev.dv_xname, XBOX_SMBA);
    118      1.10  jmcneill 
    119      1.11  jmcneill 			/* Disable PM ACPI timer SCI interrupt */
    120      1.11  jmcneill 			val = bus_space_read_2(sc->sc_iot, sc->sc_sm_ioh,
    121      1.11  jmcneill 			    XBOX_REG_ACPI_PM1a_EN);
    122      1.11  jmcneill 			bus_space_write_2(sc->sc_iot, sc->sc_sm_ioh,
    123      1.11  jmcneill 			    XBOX_REG_ACPI_PM1a_EN,
    124      1.11  jmcneill 			    val & ~XBOX_REG_ACPI_PM1a_EN_TIMER);
    125      1.11  jmcneill 		}
    126      1.10  jmcneill 	}
    127      1.10  jmcneill 
    128      1.10  jmcneill 	if (pci_intr_map(sc->sc_pa, &ih))
    129      1.10  jmcneill 		aprint_error("%s: couldn't map interrupt\n",
    130      1.10  jmcneill 		    sc->sc_dev.dv_xname);
    131      1.10  jmcneill 	else {
    132      1.10  jmcneill 		intrstr = pci_intr_string(sc->sc_pc, ih);
    133      1.10  jmcneill 		sc->sc_ih = pci_intr_establish(sc->sc_pc, ih, IPL_BIO,
    134      1.10  jmcneill 		    amdpm_smbus_intr, sc);
    135      1.10  jmcneill 		if (sc->sc_ih != NULL)
    136      1.10  jmcneill 			aprint_normal("%s: interrupting at %s\n",
    137      1.10  jmcneill 			    sc->sc_dev.dv_xname, intrstr);
    138      1.10  jmcneill 	}
    139      1.10  jmcneill #endif
    140      1.10  jmcneill 
    141       1.1       tls 	iba.iba_tag = &sc->sc_i2c;
    142  1.12.6.1        ad 	(void)config_found_ia(&sc->sc_dev, "i2cbus", &iba, iicbus_print);
    143       1.1       tls }
    144       1.1       tls 
    145      1.12  jmcneill #ifdef XBOX
    146       1.1       tls static int
    147      1.10  jmcneill amdpm_smbus_intr(void *cookie)
    148      1.10  jmcneill {
    149      1.10  jmcneill 	struct amdpm_softc *sc;
    150      1.10  jmcneill 	uint32_t status;
    151      1.10  jmcneill 
    152      1.10  jmcneill 	sc = (struct amdpm_softc *)cookie;
    153      1.10  jmcneill 
    154      1.10  jmcneill 	if (arch_i386_is_xbox) {
    155      1.10  jmcneill 		status = bus_space_read_4(sc->sc_iot, sc->sc_sm_ioh, 0x20);
    156      1.10  jmcneill 		bus_space_write_4(sc->sc_iot, sc->sc_sm_ioh, 0x20, status);
    157      1.10  jmcneill 
    158      1.10  jmcneill 		if (status & 2)
    159      1.10  jmcneill 			return iic_smbus_intr(&sc->sc_i2c);
    160      1.10  jmcneill 	}
    161      1.12  jmcneill 
    162      1.10  jmcneill 	return 0;
    163      1.10  jmcneill }
    164      1.12  jmcneill #endif
    165      1.10  jmcneill 
    166      1.10  jmcneill static int
    167       1.7  christos amdpm_smbus_acquire_bus(void *cookie, int flags)
    168       1.1       tls {
    169       1.3   xtraeme 	struct amdpm_softc *sc = cookie;
    170       1.3   xtraeme 
    171  1.12.6.1        ad 	rw_enter(&sc->sc_rwlock, RW_WRITER);
    172  1.12.6.1        ad 	return 0;
    173       1.1       tls }
    174       1.1       tls 
    175       1.1       tls static void
    176       1.7  christos amdpm_smbus_release_bus(void *cookie, int flags)
    177       1.1       tls {
    178       1.3   xtraeme 	struct amdpm_softc *sc = cookie;
    179       1.3   xtraeme 
    180  1.12.6.1        ad 	rw_exit(&sc->sc_rwlock);
    181       1.1       tls }
    182       1.1       tls 
    183       1.1       tls static int
    184       1.1       tls amdpm_smbus_exec(void *cookie, i2c_op_t op, i2c_addr_t addr, const void *cmd,
    185  1.12.6.1        ad 		 size_t cmdlen, void *vbuf, size_t buflen, int flags)
    186       1.1       tls {
    187       1.1       tls         struct amdpm_softc *sc  = (struct amdpm_softc *) cookie;
    188       1.1       tls 	sc->sc_smbus_slaveaddr  = addr;
    189  1.12.6.1        ad 	uint8_t *p = vbuf;
    190       1.9  jmcneill 	int rv;
    191       1.1       tls 
    192       1.1       tls 	if (I2C_OP_READ_P(op) && (cmdlen == 0) && (buflen == 1)) {
    193  1.12.6.1        ad 		rv = amdpm_smbus_receive_1(sc, op);
    194  1.12.6.1        ad 		if (rv == -1)
    195  1.12.6.1        ad 			return -1;
    196  1.12.6.1        ad 		*p = (uint8_t)rv;
    197  1.12.6.1        ad 		return 0;
    198       1.1       tls 	}
    199       1.1       tls 
    200  1.12.6.1        ad 	if ((I2C_OP_READ_P(op)) && (cmdlen == 1) && (buflen == 1)) {
    201  1.12.6.1        ad 		rv = amdpm_smbus_read_1(sc, *(const uint8_t *)cmd, op);
    202  1.12.6.1        ad 		if (rv == -1)
    203  1.12.6.1        ad 			return -1;
    204  1.12.6.1        ad 		*p = (uint8_t)rv;
    205  1.12.6.1        ad 		return 0;
    206       1.1       tls 	}
    207       1.1       tls 
    208  1.12.6.1        ad 	if ((I2C_OP_WRITE_P(op)) && (cmdlen == 0) && (buflen == 1))
    209  1.12.6.1        ad 		return amdpm_smbus_send_1(sc, *(uint8_t*)vbuf, op);
    210       1.1       tls 
    211  1.12.6.1        ad 	if ((I2C_OP_WRITE_P(op)) && (cmdlen == 1) && (buflen == 1))
    212  1.12.6.1        ad 		return amdpm_smbus_write_1(sc,
    213  1.12.6.1        ad 					   *(const uint8_t*)cmd,
    214  1.12.6.1        ad 					   *(uint8_t*)vbuf,
    215  1.12.6.1        ad 					   op);
    216       1.1       tls 
    217  1.12.6.1        ad 	return -1;
    218       1.1       tls }
    219       1.1       tls 
    220       1.1       tls static int
    221      1.10  jmcneill amdpm_smbus_check_done(struct amdpm_softc *sc, i2c_op_t op)
    222       1.1       tls {
    223  1.12.6.1        ad         int i;
    224  1.12.6.1        ad 
    225       1.1       tls 	for (i = 0; i < 1000; i++) {
    226  1.12.6.1        ad 	/* check gsr and wait till cycle is done */
    227  1.12.6.1        ad 		uint16_t data = amdpm_smbus_get_gsr(sc);
    228  1.12.6.1        ad 		if (data & AMDPM_8111_GSR_CYCLE_DONE)
    229  1.12.6.1        ad 			return 0;
    230       1.1       tls 	}
    231  1.12.6.1        ad 
    232  1.12.6.1        ad 	if (!(op & I2C_F_POLL))
    233  1.12.6.1        ad 	    delay(1);
    234  1.12.6.1        ad 
    235  1.12.6.1        ad 	return -1;
    236       1.1       tls }
    237       1.1       tls 
    238       1.1       tls 
    239       1.1       tls static void
    240       1.1       tls amdpm_smbus_clear_gsr(struct amdpm_softc *sc)
    241       1.1       tls {
    242       1.1       tls         /* clear register */
    243  1.12.6.1        ad         uint16_t data = 0xFFFF;
    244       1.8  jmcneill 	int off = (sc->sc_nforce ? 0xe0 : 0);
    245       1.8  jmcneill 	bus_space_write_2(sc->sc_iot, sc->sc_ioh,
    246       1.8  jmcneill 	    AMDPM_8111_SMBUS_STAT - off, data);
    247       1.1       tls }
    248       1.1       tls 
    249  1.12.6.1        ad static uint16_t
    250       1.1       tls amdpm_smbus_get_gsr(struct amdpm_softc *sc)
    251       1.1       tls {
    252       1.8  jmcneill 	int off = (sc->sc_nforce ? 0xe0 : 0);
    253  1.12.6.1        ad         return bus_space_read_2(sc->sc_iot, sc->sc_ioh,
    254  1.12.6.1        ad 	    AMDPM_8111_SMBUS_STAT - off);
    255       1.1       tls }
    256       1.1       tls 
    257       1.1       tls static int
    258  1.12.6.1        ad amdpm_smbus_send_1(struct amdpm_softc *sc, uint8_t val, i2c_op_t op)
    259       1.1       tls {
    260  1.12.6.1        ad 	uint16_t data = 0;
    261       1.8  jmcneill 	int off = (sc->sc_nforce ? 0xe0 : 0);
    262       1.8  jmcneill 
    263  1.12.6.1        ad 	/* first clear gsr */
    264  1.12.6.1        ad 	amdpm_smbus_clear_gsr(sc);
    265       1.1       tls 
    266       1.1       tls 	/* write smbus slave address to register */
    267       1.1       tls 	data = sc->sc_smbus_slaveaddr;
    268       1.1       tls 	data <<= 1;
    269       1.1       tls 	data |= AMDPM_8111_SMBUS_SEND;
    270       1.8  jmcneill 	bus_space_write_1(sc->sc_iot, sc->sc_ioh,
    271       1.8  jmcneill 	    AMDPM_8111_SMBUS_HOSTADDR - off, data);
    272       1.1       tls 
    273       1.1       tls 	data = val;
    274       1.1       tls 	/* store data */
    275       1.8  jmcneill 	bus_space_write_2(sc->sc_iot, sc->sc_ioh,
    276       1.8  jmcneill 	    AMDPM_8111_SMBUS_HOSTDATA - off, data);
    277       1.1       tls 	/* host start */
    278       1.8  jmcneill 	bus_space_write_2(sc->sc_iot, sc->sc_ioh,
    279       1.8  jmcneill 	    AMDPM_8111_SMBUS_CTRL - off,
    280       1.8  jmcneill 	    AMDPM_8111_SMBUS_GSR_SB);
    281       1.8  jmcneill 
    282  1.12.6.1        ad 	return amdpm_smbus_check_done(sc, op);
    283       1.1       tls }
    284       1.1       tls 
    285       1.1       tls 
    286       1.1       tls static int
    287  1.12.6.1        ad amdpm_smbus_write_1(struct amdpm_softc *sc, uint8_t cmd, uint8_t val,
    288  1.12.6.1        ad 		    i2c_op_t op)
    289       1.1       tls {
    290  1.12.6.1        ad 	uint16_t data = 0;
    291       1.8  jmcneill 	int off = (sc->sc_nforce ? 0xe0 : 0);
    292       1.8  jmcneill 
    293  1.12.6.1        ad 	/* first clear gsr */
    294  1.12.6.1        ad 	amdpm_smbus_clear_gsr(sc);
    295       1.1       tls 
    296       1.1       tls 	data = sc->sc_smbus_slaveaddr;
    297       1.1       tls 	data <<= 1;
    298       1.1       tls 	data |= AMDPM_8111_SMBUS_WRITE;
    299       1.8  jmcneill 	bus_space_write_1(sc->sc_iot, sc->sc_ioh,
    300       1.8  jmcneill 	    AMDPM_8111_SMBUS_HOSTADDR - off, data);
    301       1.1       tls 
    302       1.1       tls 	data = val;
    303       1.1       tls 	/* store cmd */
    304       1.8  jmcneill 	bus_space_write_1(sc->sc_iot, sc->sc_ioh,
    305       1.8  jmcneill 	    AMDPM_8111_SMBUS_HOSTCMD - off, cmd);
    306       1.1       tls 	/* store data */
    307       1.8  jmcneill 	bus_space_write_2(sc->sc_iot, sc->sc_ioh,
    308       1.8  jmcneill 	    AMDPM_8111_SMBUS_HOSTDATA - off, data);
    309       1.1       tls 	/* host start */
    310       1.8  jmcneill 	bus_space_write_2(sc->sc_iot, sc->sc_ioh,
    311       1.8  jmcneill 	    AMDPM_8111_SMBUS_CTRL - off, AMDPM_8111_SMBUS_GSR_WB);
    312       1.1       tls 
    313  1.12.6.1        ad 	return amdpm_smbus_check_done(sc, op);
    314       1.1       tls }
    315       1.1       tls 
    316       1.1       tls static int
    317      1.10  jmcneill amdpm_smbus_receive_1(struct amdpm_softc *sc, i2c_op_t op)
    318       1.1       tls {
    319  1.12.6.1        ad 	uint16_t data = 0;
    320       1.8  jmcneill 	int off = (sc->sc_nforce ? 0xe0 : 0);
    321       1.8  jmcneill 
    322  1.12.6.1        ad 	/* first clear gsr */
    323  1.12.6.1        ad 	amdpm_smbus_clear_gsr(sc);
    324       1.1       tls 
    325       1.1       tls 	/* write smbus slave address to register */
    326       1.1       tls 	data = sc->sc_smbus_slaveaddr;
    327       1.1       tls 	data <<= 1;
    328       1.1       tls 	data |= AMDPM_8111_SMBUS_RX;
    329       1.8  jmcneill 	bus_space_write_1(sc->sc_iot, sc->sc_ioh,
    330       1.8  jmcneill 	    AMDPM_8111_SMBUS_HOSTADDR - off, data);
    331       1.1       tls 
    332       1.1       tls 	/* start smbus cycle */
    333       1.8  jmcneill 	bus_space_write_2(sc->sc_iot, sc->sc_ioh,
    334       1.8  jmcneill 	    AMDPM_8111_SMBUS_CTRL - off, AMDPM_8111_SMBUS_GSR_RXB);
    335       1.1       tls 
    336       1.1       tls 	/* check for errors */
    337      1.10  jmcneill 	if (amdpm_smbus_check_done(sc, op) < 0)
    338  1.12.6.1        ad 		return -1;
    339       1.1       tls 
    340       1.1       tls 	/* read data */
    341       1.8  jmcneill 	data = bus_space_read_2(sc->sc_iot, sc->sc_ioh,
    342       1.8  jmcneill 	    AMDPM_8111_SMBUS_HOSTDATA - off);
    343  1.12.6.1        ad 	uint8_t ret = (uint8_t)(data & 0x00FF);
    344  1.12.6.1        ad 	return ret;
    345       1.1       tls }
    346       1.1       tls 
    347       1.1       tls static int
    348  1.12.6.1        ad amdpm_smbus_read_1(struct amdpm_softc *sc, uint8_t cmd, i2c_op_t op)
    349       1.8  jmcneill {
    350  1.12.6.1        ad 	uint16_t data = 0;
    351  1.12.6.1        ad 	uint8_t ret;
    352       1.8  jmcneill 	int off = (sc->sc_nforce ? 0xe0 : 0);
    353       1.8  jmcneill 
    354  1.12.6.1        ad 	/* first clear gsr */
    355  1.12.6.1        ad 	amdpm_smbus_clear_gsr(sc);
    356       1.1       tls 
    357       1.1       tls 	/* write smbus slave address to register */
    358       1.1       tls 	data = sc->sc_smbus_slaveaddr;
    359       1.1       tls 	data <<= 1;
    360       1.1       tls 	data |= AMDPM_8111_SMBUS_READ;
    361       1.8  jmcneill 	bus_space_write_1(sc->sc_iot, sc->sc_ioh,
    362       1.8  jmcneill 	    AMDPM_8111_SMBUS_HOSTADDR - off, data);
    363       1.1       tls 
    364       1.1       tls 	/* store cmd */
    365       1.8  jmcneill 	bus_space_write_1(sc->sc_iot, sc->sc_ioh,
    366       1.8  jmcneill 	    AMDPM_8111_SMBUS_HOSTCMD - off, cmd);
    367       1.1       tls 	/* host start */
    368       1.8  jmcneill 	bus_space_write_2(sc->sc_iot, sc->sc_ioh,
    369       1.8  jmcneill 	    AMDPM_8111_SMBUS_CTRL - off, AMDPM_8111_SMBUS_GSR_RB);
    370       1.1       tls 
    371       1.1       tls 	/* check for errors */
    372      1.10  jmcneill 	if (amdpm_smbus_check_done(sc, op) < 0)
    373  1.12.6.1        ad 		return -1;
    374       1.1       tls 
    375       1.1       tls 	/* store data */
    376       1.8  jmcneill 	data = bus_space_read_2(sc->sc_iot, sc->sc_ioh,
    377       1.8  jmcneill 	    AMDPM_8111_SMBUS_HOSTDATA - off);
    378  1.12.6.1        ad 	ret = (uint8_t)(data & 0x00FF);
    379  1.12.6.1        ad 	return ret;
    380       1.1       tls }
    381