2009-02-03 19:27:13 +03:00
|
|
|
/* $NetBSD: amdpm_smbus.c,v 1.16 2009/02/03 16:27:13 pgoyette Exp $ */
|
2006-02-19 05:24:20 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (c) 2005 Anil Gopinath (anil_public@yahoo.com)
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
* 3. The name of the author may not be used to endorse or promote products
|
|
|
|
* derived from this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* driver for SMBUS 1.0 host controller found in the
|
|
|
|
* AMD-8111 HyperTransport I/O Hub
|
|
|
|
*/
|
2006-02-19 11:49:45 +03:00
|
|
|
#include <sys/cdefs.h>
|
2009-02-03 19:27:13 +03:00
|
|
|
__KERNEL_RCSID(0, "$NetBSD: amdpm_smbus.c,v 1.16 2009/02/03 16:27:13 pgoyette Exp $");
|
2006-02-19 11:49:45 +03:00
|
|
|
|
2006-02-19 05:24:20 +03:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/device.h>
|
|
|
|
#include <sys/rnd.h>
|
2007-08-27 19:57:13 +04:00
|
|
|
#include <sys/rwlock.h>
|
|
|
|
|
2006-02-19 05:24:20 +03:00
|
|
|
#include <dev/pci/pcireg.h>
|
|
|
|
#include <dev/pci/pcivar.h>
|
|
|
|
#include <dev/pci/pcidevs.h>
|
|
|
|
|
|
|
|
#include <dev/i2c/i2cvar.h>
|
|
|
|
#include <dev/i2c/i2c_bitbang.h>
|
|
|
|
|
|
|
|
#include <dev/pci/amdpmreg.h>
|
|
|
|
#include <dev/pci/amdpmvar.h>
|
|
|
|
|
|
|
|
#include <dev/pci/amdpm_smbusreg.h>
|
|
|
|
|
2007-02-06 02:38:15 +03:00
|
|
|
#ifdef __i386__
|
|
|
|
#include "opt_xbox.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef XBOX
|
|
|
|
extern int arch_i386_is_xbox;
|
|
|
|
#endif
|
|
|
|
|
2007-08-27 16:07:39 +04:00
|
|
|
static int amdpm_smbus_acquire_bus(void *, int);
|
|
|
|
static void amdpm_smbus_release_bus(void *, int);
|
|
|
|
static int amdpm_smbus_exec(void *, i2c_op_t, i2c_addr_t, const void *,
|
|
|
|
size_t, void *, size_t, int);
|
|
|
|
static int amdpm_smbus_check_done(struct amdpm_softc *, i2c_op_t);
|
|
|
|
static void amdpm_smbus_clear_gsr(struct amdpm_softc *);
|
|
|
|
static uint16_t amdpm_smbus_get_gsr(struct amdpm_softc *);
|
2009-02-03 19:27:13 +03:00
|
|
|
static int amdpm_smbus_quick(struct amdpm_softc *, i2c_op_t);
|
2007-08-27 16:07:39 +04:00
|
|
|
static int amdpm_smbus_send_1(struct amdpm_softc *, uint8_t, i2c_op_t);
|
|
|
|
static int amdpm_smbus_write_1(struct amdpm_softc *, uint8_t,
|
|
|
|
uint8_t, i2c_op_t);
|
|
|
|
static int amdpm_smbus_receive_1(struct amdpm_softc *, i2c_op_t);
|
|
|
|
static int amdpm_smbus_read_1(struct amdpm_softc *sc, uint8_t, i2c_op_t);
|
2006-02-19 05:24:20 +03:00
|
|
|
|
2007-02-06 17:39:47 +03:00
|
|
|
#ifdef XBOX
|
2007-02-06 02:38:15 +03:00
|
|
|
static int amdpm_smbus_intr(void *);
|
2007-02-06 17:39:47 +03:00
|
|
|
#endif
|
2006-02-19 05:24:20 +03:00
|
|
|
|
|
|
|
void
|
|
|
|
amdpm_smbus_attach(struct amdpm_softc *sc)
|
|
|
|
{
|
|
|
|
struct i2cbus_attach_args iba;
|
2007-02-06 17:39:47 +03:00
|
|
|
#ifdef XBOX
|
2007-02-06 02:38:15 +03:00
|
|
|
pci_intr_handle_t ih;
|
|
|
|
const char *intrstr;
|
2007-02-06 17:39:47 +03:00
|
|
|
#endif
|
2006-02-19 05:24:20 +03:00
|
|
|
|
2006-09-24 07:40:49 +04:00
|
|
|
/* register with iic */
|
2006-02-19 05:24:20 +03:00
|
|
|
sc->sc_i2c.ic_cookie = sc;
|
|
|
|
sc->sc_i2c.ic_acquire_bus = amdpm_smbus_acquire_bus;
|
|
|
|
sc->sc_i2c.ic_release_bus = amdpm_smbus_release_bus;
|
|
|
|
sc->sc_i2c.ic_send_start = NULL;
|
|
|
|
sc->sc_i2c.ic_send_stop = NULL;
|
|
|
|
sc->sc_i2c.ic_initiate_xfer = NULL;
|
|
|
|
sc->sc_i2c.ic_read_byte = NULL;
|
|
|
|
sc->sc_i2c.ic_write_byte = NULL;
|
|
|
|
sc->sc_i2c.ic_exec = amdpm_smbus_exec;
|
2006-04-30 22:46:18 +04:00
|
|
|
|
2007-08-27 19:57:13 +04:00
|
|
|
rw_init(&sc->sc_rwlock);
|
2006-04-30 22:46:18 +04:00
|
|
|
|
2007-02-06 02:38:15 +03:00
|
|
|
#ifdef XBOX
|
|
|
|
#define XBOX_SMBA 0x8000
|
|
|
|
#define XBOX_SMSIZE 256
|
|
|
|
#define XBOX_INTRLINE 12
|
2007-02-06 05:07:36 +03:00
|
|
|
#define XBOX_REG_ACPI_PM1a_EN 0x02
|
|
|
|
#define XBOX_REG_ACPI_PM1a_EN_TIMER 0x01
|
2007-02-06 02:38:15 +03:00
|
|
|
/* XXX pci0 dev 1 function 2 "System Management" doesn't probe */
|
|
|
|
if (arch_i386_is_xbox) {
|
2007-02-06 05:07:36 +03:00
|
|
|
uint16_t val;
|
2007-02-06 02:38:15 +03:00
|
|
|
sc->sc_pa->pa_intrline = XBOX_INTRLINE;
|
|
|
|
|
|
|
|
if (bus_space_map(sc->sc_iot, XBOX_SMBA, XBOX_SMSIZE,
|
2007-02-06 05:07:36 +03:00
|
|
|
0, &sc->sc_sm_ioh) == 0) {
|
2008-04-10 23:13:36 +04:00
|
|
|
aprint_normal_dev(&sc->sc_dev, "system management at 0x%04x\n", XBOX_SMBA);
|
2007-02-06 02:38:15 +03:00
|
|
|
|
2007-02-06 05:07:36 +03:00
|
|
|
/* Disable PM ACPI timer SCI interrupt */
|
|
|
|
val = bus_space_read_2(sc->sc_iot, sc->sc_sm_ioh,
|
|
|
|
XBOX_REG_ACPI_PM1a_EN);
|
|
|
|
bus_space_write_2(sc->sc_iot, sc->sc_sm_ioh,
|
|
|
|
XBOX_REG_ACPI_PM1a_EN,
|
|
|
|
val & ~XBOX_REG_ACPI_PM1a_EN_TIMER);
|
|
|
|
}
|
2007-02-06 02:38:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (pci_intr_map(sc->sc_pa, &ih))
|
2008-04-10 23:13:36 +04:00
|
|
|
aprint_error_dev(&sc->sc_dev, "couldn't map interrupt\n");
|
2007-02-06 02:38:15 +03:00
|
|
|
else {
|
|
|
|
intrstr = pci_intr_string(sc->sc_pc, ih);
|
|
|
|
sc->sc_ih = pci_intr_establish(sc->sc_pc, ih, IPL_BIO,
|
|
|
|
amdpm_smbus_intr, sc);
|
|
|
|
if (sc->sc_ih != NULL)
|
2008-04-10 23:13:36 +04:00
|
|
|
aprint_normal_dev(&sc->sc_dev, "interrupting at %s\n",
|
|
|
|
intrstr);
|
2007-02-06 02:38:15 +03:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2006-02-19 05:24:20 +03:00
|
|
|
iba.iba_tag = &sc->sc_i2c;
|
2007-08-27 16:07:39 +04:00
|
|
|
(void)config_found_ia(&sc->sc_dev, "i2cbus", &iba, iicbus_print);
|
2006-02-19 05:24:20 +03:00
|
|
|
}
|
|
|
|
|
2007-02-06 17:39:47 +03:00
|
|
|
#ifdef XBOX
|
2007-02-06 02:38:15 +03:00
|
|
|
static int
|
|
|
|
amdpm_smbus_intr(void *cookie)
|
|
|
|
{
|
|
|
|
struct amdpm_softc *sc;
|
|
|
|
uint32_t status;
|
|
|
|
|
|
|
|
sc = (struct amdpm_softc *)cookie;
|
|
|
|
|
|
|
|
if (arch_i386_is_xbox) {
|
|
|
|
status = bus_space_read_4(sc->sc_iot, sc->sc_sm_ioh, 0x20);
|
|
|
|
bus_space_write_4(sc->sc_iot, sc->sc_sm_ioh, 0x20, status);
|
|
|
|
|
|
|
|
if (status & 2)
|
|
|
|
return iic_smbus_intr(&sc->sc_i2c);
|
|
|
|
}
|
2007-02-06 17:39:47 +03:00
|
|
|
|
2007-02-06 02:38:15 +03:00
|
|
|
return 0;
|
|
|
|
}
|
2007-02-06 17:39:47 +03:00
|
|
|
#endif
|
2007-02-06 02:38:15 +03:00
|
|
|
|
2006-02-19 05:24:20 +03:00
|
|
|
static int
|
2006-11-16 04:32:37 +03:00
|
|
|
amdpm_smbus_acquire_bus(void *cookie, int flags)
|
2006-02-19 05:24:20 +03:00
|
|
|
{
|
2006-04-30 22:46:18 +04:00
|
|
|
struct amdpm_softc *sc = cookie;
|
|
|
|
|
2007-08-27 19:57:13 +04:00
|
|
|
rw_enter(&sc->sc_rwlock, RW_WRITER);
|
|
|
|
return 0;
|
2006-02-19 05:24:20 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2006-11-16 04:32:37 +03:00
|
|
|
amdpm_smbus_release_bus(void *cookie, int flags)
|
2006-02-19 05:24:20 +03:00
|
|
|
{
|
2006-04-30 22:46:18 +04:00
|
|
|
struct amdpm_softc *sc = cookie;
|
|
|
|
|
2007-08-27 19:57:13 +04:00
|
|
|
rw_exit(&sc->sc_rwlock);
|
2006-02-19 05:24:20 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
amdpm_smbus_exec(void *cookie, i2c_op_t op, i2c_addr_t addr, const void *cmd,
|
2007-08-27 16:07:39 +04:00
|
|
|
size_t cmdlen, void *vbuf, size_t buflen, int flags)
|
2006-02-19 05:24:20 +03:00
|
|
|
{
|
|
|
|
struct amdpm_softc *sc = (struct amdpm_softc *) cookie;
|
|
|
|
sc->sc_smbus_slaveaddr = addr;
|
2007-08-27 16:07:39 +04:00
|
|
|
uint8_t *p = vbuf;
|
2007-01-06 05:16:22 +03:00
|
|
|
int rv;
|
2006-02-19 05:24:20 +03:00
|
|
|
|
2009-02-03 19:27:13 +03:00
|
|
|
if ((cmdlen == 0) && (buflen == 0))
|
|
|
|
return amdpm_smbus_quick(sc, op);
|
|
|
|
|
2006-02-19 05:24:20 +03:00
|
|
|
if (I2C_OP_READ_P(op) && (cmdlen == 0) && (buflen == 1)) {
|
2007-08-27 16:07:39 +04:00
|
|
|
rv = amdpm_smbus_receive_1(sc, op);
|
|
|
|
if (rv == -1)
|
|
|
|
return -1;
|
|
|
|
*p = (uint8_t)rv;
|
|
|
|
return 0;
|
2006-02-19 05:24:20 +03:00
|
|
|
}
|
|
|
|
|
2007-08-27 16:07:39 +04:00
|
|
|
if ((I2C_OP_READ_P(op)) && (cmdlen == 1) && (buflen == 1)) {
|
|
|
|
rv = amdpm_smbus_read_1(sc, *(const uint8_t *)cmd, op);
|
|
|
|
if (rv == -1)
|
|
|
|
return -1;
|
|
|
|
*p = (uint8_t)rv;
|
|
|
|
return 0;
|
2006-02-19 05:24:20 +03:00
|
|
|
}
|
|
|
|
|
2007-08-27 16:07:39 +04:00
|
|
|
if ((I2C_OP_WRITE_P(op)) && (cmdlen == 0) && (buflen == 1))
|
|
|
|
return amdpm_smbus_send_1(sc, *(uint8_t*)vbuf, op);
|
2006-02-19 05:24:20 +03:00
|
|
|
|
2007-08-27 16:07:39 +04:00
|
|
|
if ((I2C_OP_WRITE_P(op)) && (cmdlen == 1) && (buflen == 1))
|
|
|
|
return amdpm_smbus_write_1(sc,
|
|
|
|
*(const uint8_t*)cmd,
|
|
|
|
*(uint8_t*)vbuf,
|
|
|
|
op);
|
2006-02-19 05:24:20 +03:00
|
|
|
|
2007-08-27 16:07:39 +04:00
|
|
|
return -1;
|
2006-02-19 05:24:20 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2007-02-06 02:38:15 +03:00
|
|
|
amdpm_smbus_check_done(struct amdpm_softc *sc, i2c_op_t op)
|
2006-02-19 05:24:20 +03:00
|
|
|
{
|
2007-08-27 16:07:39 +04:00
|
|
|
int i;
|
|
|
|
|
2006-02-19 05:24:20 +03:00
|
|
|
for (i = 0; i < 1000; i++) {
|
2007-08-27 16:07:39 +04:00
|
|
|
/* check gsr and wait till cycle is done */
|
|
|
|
uint16_t data = amdpm_smbus_get_gsr(sc);
|
|
|
|
if (data & AMDPM_8111_GSR_CYCLE_DONE)
|
|
|
|
return 0;
|
2006-02-19 05:24:20 +03:00
|
|
|
}
|
2007-08-27 16:07:39 +04:00
|
|
|
|
|
|
|
if (!(op & I2C_F_POLL))
|
|
|
|
delay(1);
|
|
|
|
|
|
|
|
return -1;
|
2006-02-19 05:24:20 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
amdpm_smbus_clear_gsr(struct amdpm_softc *sc)
|
|
|
|
{
|
|
|
|
/* clear register */
|
2007-08-27 16:07:39 +04:00
|
|
|
uint16_t data = 0xFFFF;
|
2007-01-06 04:20:39 +03:00
|
|
|
int off = (sc->sc_nforce ? 0xe0 : 0);
|
|
|
|
bus_space_write_2(sc->sc_iot, sc->sc_ioh,
|
|
|
|
AMDPM_8111_SMBUS_STAT - off, data);
|
2006-02-19 05:24:20 +03:00
|
|
|
}
|
|
|
|
|
2007-08-27 16:07:39 +04:00
|
|
|
static uint16_t
|
2006-02-19 05:24:20 +03:00
|
|
|
amdpm_smbus_get_gsr(struct amdpm_softc *sc)
|
|
|
|
{
|
2007-01-06 04:20:39 +03:00
|
|
|
int off = (sc->sc_nforce ? 0xe0 : 0);
|
2007-08-27 16:07:39 +04:00
|
|
|
return bus_space_read_2(sc->sc_iot, sc->sc_ioh,
|
|
|
|
AMDPM_8111_SMBUS_STAT - off);
|
2006-02-19 05:24:20 +03:00
|
|
|
}
|
|
|
|
|
2009-02-03 19:27:13 +03:00
|
|
|
static int
|
|
|
|
amdpm_smbus_quick(struct amdpm_softc *sc, i2c_op_t op)
|
|
|
|
{
|
|
|
|
uint16_t data = 0;
|
|
|
|
int off = (sc->sc_nforce ? 0xe0 : 0);
|
|
|
|
|
|
|
|
/* first clear gsr */
|
|
|
|
amdpm_smbus_clear_gsr(sc);
|
|
|
|
|
|
|
|
/* write smbus slave address and read/write bit to register */
|
|
|
|
data = sc->sc_smbus_slaveaddr;
|
|
|
|
data <<= 1;
|
|
|
|
if (I2C_OP_READ_P(op))
|
|
|
|
data |= AMDPM_8111_SMBUS_READ;
|
|
|
|
|
|
|
|
bus_space_write_1(sc->sc_iot, sc->sc_ioh,
|
|
|
|
AMDPM_8111_SMBUS_HOSTADDR - off, data);
|
|
|
|
|
|
|
|
/* host start */
|
|
|
|
bus_space_write_2(sc->sc_iot, sc->sc_ioh,
|
|
|
|
AMDPM_8111_SMBUS_CTRL - off,
|
|
|
|
AMDPM_8111_SMBUS_GSR_QUICK);
|
|
|
|
|
|
|
|
return amdpm_smbus_check_done(sc, op);
|
|
|
|
}
|
|
|
|
|
2006-02-19 05:24:20 +03:00
|
|
|
static int
|
2007-08-27 16:07:39 +04:00
|
|
|
amdpm_smbus_send_1(struct amdpm_softc *sc, uint8_t val, i2c_op_t op)
|
2006-02-19 05:24:20 +03:00
|
|
|
{
|
2007-08-27 16:07:39 +04:00
|
|
|
uint16_t data = 0;
|
2007-01-06 04:20:39 +03:00
|
|
|
int off = (sc->sc_nforce ? 0xe0 : 0);
|
|
|
|
|
2007-08-27 16:07:39 +04:00
|
|
|
/* first clear gsr */
|
|
|
|
amdpm_smbus_clear_gsr(sc);
|
2006-02-19 05:24:20 +03:00
|
|
|
|
|
|
|
/* write smbus slave address to register */
|
|
|
|
data = sc->sc_smbus_slaveaddr;
|
|
|
|
data <<= 1;
|
|
|
|
data |= AMDPM_8111_SMBUS_SEND;
|
2007-01-06 04:20:39 +03:00
|
|
|
bus_space_write_1(sc->sc_iot, sc->sc_ioh,
|
|
|
|
AMDPM_8111_SMBUS_HOSTADDR - off, data);
|
2006-02-19 05:24:20 +03:00
|
|
|
|
|
|
|
data = val;
|
|
|
|
/* store data */
|
2007-01-06 04:20:39 +03:00
|
|
|
bus_space_write_2(sc->sc_iot, sc->sc_ioh,
|
|
|
|
AMDPM_8111_SMBUS_HOSTDATA - off, data);
|
2006-02-19 05:24:20 +03:00
|
|
|
/* host start */
|
2007-01-06 04:20:39 +03:00
|
|
|
bus_space_write_2(sc->sc_iot, sc->sc_ioh,
|
|
|
|
AMDPM_8111_SMBUS_CTRL - off,
|
|
|
|
AMDPM_8111_SMBUS_GSR_SB);
|
|
|
|
|
2007-08-27 16:07:39 +04:00
|
|
|
return amdpm_smbus_check_done(sc, op);
|
2006-02-19 05:24:20 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
2007-08-27 16:07:39 +04:00
|
|
|
amdpm_smbus_write_1(struct amdpm_softc *sc, uint8_t cmd, uint8_t val,
|
|
|
|
i2c_op_t op)
|
2006-02-19 05:24:20 +03:00
|
|
|
{
|
2007-08-27 16:07:39 +04:00
|
|
|
uint16_t data = 0;
|
2007-01-06 04:20:39 +03:00
|
|
|
int off = (sc->sc_nforce ? 0xe0 : 0);
|
|
|
|
|
2007-08-27 16:07:39 +04:00
|
|
|
/* first clear gsr */
|
|
|
|
amdpm_smbus_clear_gsr(sc);
|
2006-02-19 05:24:20 +03:00
|
|
|
|
|
|
|
data = sc->sc_smbus_slaveaddr;
|
|
|
|
data <<= 1;
|
|
|
|
data |= AMDPM_8111_SMBUS_WRITE;
|
2007-01-06 04:20:39 +03:00
|
|
|
bus_space_write_1(sc->sc_iot, sc->sc_ioh,
|
|
|
|
AMDPM_8111_SMBUS_HOSTADDR - off, data);
|
2006-02-19 05:24:20 +03:00
|
|
|
|
|
|
|
data = val;
|
|
|
|
/* store cmd */
|
2007-01-06 04:20:39 +03:00
|
|
|
bus_space_write_1(sc->sc_iot, sc->sc_ioh,
|
|
|
|
AMDPM_8111_SMBUS_HOSTCMD - off, cmd);
|
2006-02-19 05:24:20 +03:00
|
|
|
/* store data */
|
2007-01-06 04:20:39 +03:00
|
|
|
bus_space_write_2(sc->sc_iot, sc->sc_ioh,
|
|
|
|
AMDPM_8111_SMBUS_HOSTDATA - off, data);
|
2006-02-19 05:24:20 +03:00
|
|
|
/* host start */
|
2007-01-06 04:20:39 +03:00
|
|
|
bus_space_write_2(sc->sc_iot, sc->sc_ioh,
|
|
|
|
AMDPM_8111_SMBUS_CTRL - off, AMDPM_8111_SMBUS_GSR_WB);
|
2006-02-19 05:24:20 +03:00
|
|
|
|
2007-08-27 16:07:39 +04:00
|
|
|
return amdpm_smbus_check_done(sc, op);
|
2006-02-19 05:24:20 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2007-02-06 02:38:15 +03:00
|
|
|
amdpm_smbus_receive_1(struct amdpm_softc *sc, i2c_op_t op)
|
2006-02-19 05:24:20 +03:00
|
|
|
{
|
2007-08-27 16:07:39 +04:00
|
|
|
uint16_t data = 0;
|
2007-01-06 04:20:39 +03:00
|
|
|
int off = (sc->sc_nforce ? 0xe0 : 0);
|
|
|
|
|
2007-08-27 16:07:39 +04:00
|
|
|
/* first clear gsr */
|
|
|
|
amdpm_smbus_clear_gsr(sc);
|
2006-02-19 05:24:20 +03:00
|
|
|
|
|
|
|
/* write smbus slave address to register */
|
|
|
|
data = sc->sc_smbus_slaveaddr;
|
|
|
|
data <<= 1;
|
|
|
|
data |= AMDPM_8111_SMBUS_RX;
|
2007-01-06 04:20:39 +03:00
|
|
|
bus_space_write_1(sc->sc_iot, sc->sc_ioh,
|
|
|
|
AMDPM_8111_SMBUS_HOSTADDR - off, data);
|
2006-02-19 05:24:20 +03:00
|
|
|
|
|
|
|
/* start smbus cycle */
|
2007-01-06 04:20:39 +03:00
|
|
|
bus_space_write_2(sc->sc_iot, sc->sc_ioh,
|
|
|
|
AMDPM_8111_SMBUS_CTRL - off, AMDPM_8111_SMBUS_GSR_RXB);
|
2006-02-19 05:24:20 +03:00
|
|
|
|
|
|
|
/* check for errors */
|
2007-02-06 02:38:15 +03:00
|
|
|
if (amdpm_smbus_check_done(sc, op) < 0)
|
2007-08-27 16:07:39 +04:00
|
|
|
return -1;
|
2006-02-19 05:24:20 +03:00
|
|
|
|
|
|
|
/* read data */
|
2007-01-06 04:20:39 +03:00
|
|
|
data = bus_space_read_2(sc->sc_iot, sc->sc_ioh,
|
|
|
|
AMDPM_8111_SMBUS_HOSTDATA - off);
|
2007-08-27 16:07:39 +04:00
|
|
|
uint8_t ret = (uint8_t)(data & 0x00FF);
|
|
|
|
return ret;
|
2006-02-19 05:24:20 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2007-08-27 16:07:39 +04:00
|
|
|
amdpm_smbus_read_1(struct amdpm_softc *sc, uint8_t cmd, i2c_op_t op)
|
2007-01-06 04:20:39 +03:00
|
|
|
{
|
2007-08-27 16:07:39 +04:00
|
|
|
uint16_t data = 0;
|
|
|
|
uint8_t ret;
|
2007-01-06 04:20:39 +03:00
|
|
|
int off = (sc->sc_nforce ? 0xe0 : 0);
|
|
|
|
|
2007-08-27 16:07:39 +04:00
|
|
|
/* first clear gsr */
|
|
|
|
amdpm_smbus_clear_gsr(sc);
|
2006-02-19 05:24:20 +03:00
|
|
|
|
|
|
|
/* write smbus slave address to register */
|
|
|
|
data = sc->sc_smbus_slaveaddr;
|
|
|
|
data <<= 1;
|
|
|
|
data |= AMDPM_8111_SMBUS_READ;
|
2007-01-06 04:20:39 +03:00
|
|
|
bus_space_write_1(sc->sc_iot, sc->sc_ioh,
|
|
|
|
AMDPM_8111_SMBUS_HOSTADDR - off, data);
|
2006-02-19 05:24:20 +03:00
|
|
|
|
|
|
|
/* store cmd */
|
2007-01-06 04:20:39 +03:00
|
|
|
bus_space_write_1(sc->sc_iot, sc->sc_ioh,
|
|
|
|
AMDPM_8111_SMBUS_HOSTCMD - off, cmd);
|
2006-02-19 05:24:20 +03:00
|
|
|
/* host start */
|
2007-01-06 04:20:39 +03:00
|
|
|
bus_space_write_2(sc->sc_iot, sc->sc_ioh,
|
|
|
|
AMDPM_8111_SMBUS_CTRL - off, AMDPM_8111_SMBUS_GSR_RB);
|
2006-02-19 05:24:20 +03:00
|
|
|
|
|
|
|
/* check for errors */
|
2007-02-06 02:38:15 +03:00
|
|
|
if (amdpm_smbus_check_done(sc, op) < 0)
|
2007-08-27 16:07:39 +04:00
|
|
|
return -1;
|
2006-02-19 05:24:20 +03:00
|
|
|
|
|
|
|
/* store data */
|
2007-01-06 04:20:39 +03:00
|
|
|
data = bus_space_read_2(sc->sc_iot, sc->sc_ioh,
|
|
|
|
AMDPM_8111_SMBUS_HOSTDATA - off);
|
2007-08-27 16:07:39 +04:00
|
|
|
ret = (uint8_t)(data & 0x00FF);
|
|
|
|
return ret;
|
2006-02-19 05:24:20 +03:00
|
|
|
}
|