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