amdpm_smbus.c revision 1.3.6.4 1 1.3.6.4 yamt /* $NetBSD: amdpm_smbus.c,v 1.3.6.4 2007/02/26 09:10:20 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.4 yamt __KERNEL_RCSID(0, "$NetBSD: amdpm_smbus.c,v 1.3.6.4 2007/02/26 09:10:20 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.2 yamt #include <dev/pci/pcireg.h>
43 1.3.6.2 yamt #include <dev/pci/pcivar.h>
44 1.3.6.2 yamt #include <dev/pci/pcidevs.h>
45 1.3.6.2 yamt
46 1.3.6.2 yamt #include <dev/i2c/i2cvar.h>
47 1.3.6.2 yamt #include <dev/i2c/i2c_bitbang.h>
48 1.3.6.2 yamt
49 1.3.6.2 yamt #include <dev/pci/amdpmreg.h>
50 1.3.6.2 yamt #include <dev/pci/amdpmvar.h>
51 1.3.6.2 yamt
52 1.3.6.2 yamt #include <dev/pci/amdpm_smbusreg.h>
53 1.3.6.2 yamt
54 1.3.6.4 yamt #ifdef __i386__
55 1.3.6.4 yamt #include "opt_xbox.h"
56 1.3.6.4 yamt #endif
57 1.3.6.4 yamt
58 1.3.6.4 yamt #ifdef XBOX
59 1.3.6.4 yamt extern int arch_i386_is_xbox;
60 1.3.6.4 yamt #endif
61 1.3.6.4 yamt
62 1.3.6.2 yamt static int amdpm_smbus_acquire_bus(void *cookie, int flags);
63 1.3.6.2 yamt static void amdpm_smbus_release_bus(void *cookie, int flags);
64 1.3.6.2 yamt static int amdpm_smbus_exec(void *cookie, i2c_op_t op, i2c_addr_t addr,
65 1.3.6.2 yamt const void *cmd, size_t cmdlen, void *vbuf,
66 1.3.6.2 yamt size_t buflen, int flags);
67 1.3.6.4 yamt static int amdpm_smbus_check_done(struct amdpm_softc *sc, i2c_op_t op);
68 1.3.6.2 yamt static void amdpm_smbus_clear_gsr(struct amdpm_softc *sc);
69 1.3.6.2 yamt static u_int16_t amdpm_smbus_get_gsr(struct amdpm_softc *sc);
70 1.3.6.4 yamt static int amdpm_smbus_send_1(struct amdpm_softc *sc, u_int8_t val, i2c_op_t op);
71 1.3.6.4 yamt static int amdpm_smbus_write_1(struct amdpm_softc *sc, u_int8_t cmd, u_int8_t data, i2c_op_t op);
72 1.3.6.4 yamt static int amdpm_smbus_receive_1(struct amdpm_softc *sc, i2c_op_t op);
73 1.3.6.4 yamt static int amdpm_smbus_read_1(struct amdpm_softc *sc, u_int8_t cmd, i2c_op_t op);
74 1.3.6.4 yamt
75 1.3.6.4 yamt #ifdef XBOX
76 1.3.6.4 yamt static int amdpm_smbus_intr(void *);
77 1.3.6.4 yamt #endif
78 1.3.6.2 yamt
79 1.3.6.2 yamt void
80 1.3.6.2 yamt amdpm_smbus_attach(struct amdpm_softc *sc)
81 1.3.6.2 yamt {
82 1.3.6.2 yamt struct i2cbus_attach_args iba;
83 1.3.6.4 yamt #ifdef XBOX
84 1.3.6.4 yamt pci_intr_handle_t ih;
85 1.3.6.4 yamt const char *intrstr;
86 1.3.6.4 yamt #endif
87 1.3.6.2 yamt
88 1.3.6.3 yamt /* register with iic */
89 1.3.6.2 yamt sc->sc_i2c.ic_cookie = sc;
90 1.3.6.2 yamt sc->sc_i2c.ic_acquire_bus = amdpm_smbus_acquire_bus;
91 1.3.6.2 yamt sc->sc_i2c.ic_release_bus = amdpm_smbus_release_bus;
92 1.3.6.2 yamt sc->sc_i2c.ic_send_start = NULL;
93 1.3.6.2 yamt sc->sc_i2c.ic_send_stop = NULL;
94 1.3.6.2 yamt sc->sc_i2c.ic_initiate_xfer = NULL;
95 1.3.6.2 yamt sc->sc_i2c.ic_read_byte = NULL;
96 1.3.6.2 yamt sc->sc_i2c.ic_write_byte = NULL;
97 1.3.6.2 yamt sc->sc_i2c.ic_exec = amdpm_smbus_exec;
98 1.3.6.2 yamt
99 1.3.6.2 yamt lockinit(&sc->sc_lock, PZERO, "amdpm_smbus", 0, 0);
100 1.3.6.2 yamt
101 1.3.6.4 yamt #ifdef XBOX
102 1.3.6.4 yamt #define XBOX_SMBA 0x8000
103 1.3.6.4 yamt #define XBOX_SMSIZE 256
104 1.3.6.4 yamt #define XBOX_INTRLINE 12
105 1.3.6.4 yamt #define XBOX_REG_ACPI_PM1a_EN 0x02
106 1.3.6.4 yamt #define XBOX_REG_ACPI_PM1a_EN_TIMER 0x01
107 1.3.6.4 yamt /* XXX pci0 dev 1 function 2 "System Management" doesn't probe */
108 1.3.6.4 yamt if (arch_i386_is_xbox) {
109 1.3.6.4 yamt uint16_t val;
110 1.3.6.4 yamt sc->sc_pa->pa_intrline = XBOX_INTRLINE;
111 1.3.6.4 yamt
112 1.3.6.4 yamt if (bus_space_map(sc->sc_iot, XBOX_SMBA, XBOX_SMSIZE,
113 1.3.6.4 yamt 0, &sc->sc_sm_ioh) == 0) {
114 1.3.6.4 yamt aprint_normal("%s: system management at 0x%04x\n",
115 1.3.6.4 yamt sc->sc_dev.dv_xname, XBOX_SMBA);
116 1.3.6.4 yamt
117 1.3.6.4 yamt /* Disable PM ACPI timer SCI interrupt */
118 1.3.6.4 yamt val = bus_space_read_2(sc->sc_iot, sc->sc_sm_ioh,
119 1.3.6.4 yamt XBOX_REG_ACPI_PM1a_EN);
120 1.3.6.4 yamt bus_space_write_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 val & ~XBOX_REG_ACPI_PM1a_EN_TIMER);
123 1.3.6.4 yamt }
124 1.3.6.4 yamt }
125 1.3.6.4 yamt
126 1.3.6.4 yamt if (pci_intr_map(sc->sc_pa, &ih))
127 1.3.6.4 yamt aprint_error("%s: couldn't map interrupt\n",
128 1.3.6.4 yamt sc->sc_dev.dv_xname);
129 1.3.6.4 yamt else {
130 1.3.6.4 yamt intrstr = pci_intr_string(sc->sc_pc, ih);
131 1.3.6.4 yamt sc->sc_ih = pci_intr_establish(sc->sc_pc, ih, IPL_BIO,
132 1.3.6.4 yamt amdpm_smbus_intr, sc);
133 1.3.6.4 yamt if (sc->sc_ih != NULL)
134 1.3.6.4 yamt aprint_normal("%s: interrupting at %s\n",
135 1.3.6.4 yamt sc->sc_dev.dv_xname, intrstr);
136 1.3.6.4 yamt }
137 1.3.6.4 yamt #endif
138 1.3.6.4 yamt
139 1.3.6.2 yamt iba.iba_tag = &sc->sc_i2c;
140 1.3.6.3 yamt (void) config_found_ia(&sc->sc_dev, "i2cbus", &iba, iicbus_print);
141 1.3.6.2 yamt }
142 1.3.6.2 yamt
143 1.3.6.4 yamt #ifdef XBOX
144 1.3.6.4 yamt static int
145 1.3.6.4 yamt amdpm_smbus_intr(void *cookie)
146 1.3.6.4 yamt {
147 1.3.6.4 yamt struct amdpm_softc *sc;
148 1.3.6.4 yamt uint32_t status;
149 1.3.6.4 yamt
150 1.3.6.4 yamt sc = (struct amdpm_softc *)cookie;
151 1.3.6.4 yamt
152 1.3.6.4 yamt if (arch_i386_is_xbox) {
153 1.3.6.4 yamt status = bus_space_read_4(sc->sc_iot, sc->sc_sm_ioh, 0x20);
154 1.3.6.4 yamt bus_space_write_4(sc->sc_iot, sc->sc_sm_ioh, 0x20, status);
155 1.3.6.4 yamt
156 1.3.6.4 yamt if (status & 2)
157 1.3.6.4 yamt return iic_smbus_intr(&sc->sc_i2c);
158 1.3.6.4 yamt }
159 1.3.6.4 yamt
160 1.3.6.4 yamt return 0;
161 1.3.6.4 yamt }
162 1.3.6.4 yamt #endif
163 1.3.6.4 yamt
164 1.3.6.2 yamt static int
165 1.3.6.2 yamt amdpm_smbus_acquire_bus(void *cookie, int flags)
166 1.3.6.2 yamt {
167 1.3.6.2 yamt struct amdpm_softc *sc = cookie;
168 1.3.6.2 yamt int err;
169 1.3.6.2 yamt
170 1.3.6.2 yamt err = lockmgr(&sc->sc_lock, LK_EXCLUSIVE, NULL);
171 1.3.6.2 yamt
172 1.3.6.2 yamt return err;
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.2 yamt lockmgr(&sc->sc_lock, LK_RELEASE, NULL);
181 1.3.6.2 yamt
182 1.3.6.2 yamt return;
183 1.3.6.2 yamt }
184 1.3.6.2 yamt
185 1.3.6.2 yamt static int
186 1.3.6.2 yamt amdpm_smbus_exec(void *cookie, i2c_op_t op, i2c_addr_t addr, const void *cmd,
187 1.3.6.2 yamt size_t cmdlen, void *vbuf, size_t buflen, int flags)
188 1.3.6.2 yamt {
189 1.3.6.2 yamt struct amdpm_softc *sc = (struct amdpm_softc *) cookie;
190 1.3.6.2 yamt sc->sc_smbus_slaveaddr = addr;
191 1.3.6.4 yamt u_int8_t *p = vbuf;
192 1.3.6.4 yamt int rv;
193 1.3.6.2 yamt
194 1.3.6.2 yamt if (I2C_OP_READ_P(op) && (cmdlen == 0) && (buflen == 1)) {
195 1.3.6.4 yamt rv = amdpm_smbus_receive_1(sc, op);
196 1.3.6.4 yamt if (rv == -1)
197 1.3.6.4 yamt return -1;
198 1.3.6.4 yamt *p = (u_int8_t)rv;
199 1.3.6.4 yamt return 0;
200 1.3.6.2 yamt }
201 1.3.6.2 yamt
202 1.3.6.2 yamt if ( (I2C_OP_READ_P(op)) && (cmdlen == 1) && (buflen == 1)) {
203 1.3.6.4 yamt rv = amdpm_smbus_read_1(sc, *(const uint8_t*)cmd, op);
204 1.3.6.4 yamt if (rv == -1)
205 1.3.6.4 yamt return -1;
206 1.3.6.4 yamt *p = (u_int8_t)rv;
207 1.3.6.4 yamt return 0;
208 1.3.6.2 yamt }
209 1.3.6.2 yamt
210 1.3.6.2 yamt if ( (I2C_OP_WRITE_P(op)) && (cmdlen == 0) && (buflen == 1)) {
211 1.3.6.4 yamt return amdpm_smbus_send_1(sc, *(uint8_t*)vbuf, op);
212 1.3.6.2 yamt }
213 1.3.6.2 yamt
214 1.3.6.2 yamt if ( (I2C_OP_WRITE_P(op)) && (cmdlen == 1) && (buflen == 1)) {
215 1.3.6.4 yamt return amdpm_smbus_write_1(sc, *(const uint8_t*)cmd, *(uint8_t*)vbuf, op);
216 1.3.6.2 yamt }
217 1.3.6.2 yamt
218 1.3.6.2 yamt return (-1);
219 1.3.6.2 yamt }
220 1.3.6.2 yamt
221 1.3.6.2 yamt static int
222 1.3.6.4 yamt amdpm_smbus_check_done(struct amdpm_softc *sc, i2c_op_t op)
223 1.3.6.2 yamt {
224 1.3.6.2 yamt int i = 0;
225 1.3.6.2 yamt for (i = 0; i < 1000; i++) {
226 1.3.6.2 yamt /* check gsr and wait till cycle is done */
227 1.3.6.2 yamt u_int16_t data = amdpm_smbus_get_gsr(sc);
228 1.3.6.2 yamt if (data & AMDPM_8111_GSR_CYCLE_DONE) {
229 1.3.6.2 yamt return (0);
230 1.3.6.2 yamt }
231 1.3.6.4 yamt if (!(op & I2C_F_POLL))
232 1.3.6.4 yamt delay(1);
233 1.3.6.2 yamt }
234 1.3.6.2 yamt return (-1);
235 1.3.6.2 yamt }
236 1.3.6.2 yamt
237 1.3.6.2 yamt
238 1.3.6.2 yamt static void
239 1.3.6.2 yamt amdpm_smbus_clear_gsr(struct amdpm_softc *sc)
240 1.3.6.2 yamt {
241 1.3.6.2 yamt /* clear register */
242 1.3.6.4 yamt u_int16_t data = 0xFFFF;
243 1.3.6.4 yamt int off = (sc->sc_nforce ? 0xe0 : 0);
244 1.3.6.4 yamt bus_space_write_2(sc->sc_iot, sc->sc_ioh,
245 1.3.6.4 yamt AMDPM_8111_SMBUS_STAT - off, data);
246 1.3.6.2 yamt }
247 1.3.6.2 yamt
248 1.3.6.2 yamt static u_int16_t
249 1.3.6.2 yamt amdpm_smbus_get_gsr(struct amdpm_softc *sc)
250 1.3.6.2 yamt {
251 1.3.6.4 yamt int off = (sc->sc_nforce ? 0xe0 : 0);
252 1.3.6.4 yamt return (bus_space_read_2(sc->sc_iot, sc->sc_ioh,
253 1.3.6.4 yamt AMDPM_8111_SMBUS_STAT - off));
254 1.3.6.2 yamt }
255 1.3.6.2 yamt
256 1.3.6.2 yamt static int
257 1.3.6.4 yamt amdpm_smbus_send_1(struct amdpm_softc *sc, u_int8_t val, i2c_op_t op)
258 1.3.6.2 yamt {
259 1.3.6.4 yamt u_int16_t data = 0;
260 1.3.6.4 yamt int off = (sc->sc_nforce ? 0xe0 : 0);
261 1.3.6.4 yamt
262 1.3.6.2 yamt /* first clear gsr */
263 1.3.6.2 yamt amdpm_smbus_clear_gsr(sc);
264 1.3.6.2 yamt
265 1.3.6.2 yamt /* write smbus slave address to register */
266 1.3.6.2 yamt data = sc->sc_smbus_slaveaddr;
267 1.3.6.2 yamt data <<= 1;
268 1.3.6.2 yamt data |= AMDPM_8111_SMBUS_SEND;
269 1.3.6.4 yamt bus_space_write_1(sc->sc_iot, sc->sc_ioh,
270 1.3.6.4 yamt AMDPM_8111_SMBUS_HOSTADDR - off, data);
271 1.3.6.2 yamt
272 1.3.6.2 yamt data = val;
273 1.3.6.2 yamt /* store data */
274 1.3.6.4 yamt bus_space_write_2(sc->sc_iot, sc->sc_ioh,
275 1.3.6.4 yamt AMDPM_8111_SMBUS_HOSTDATA - off, data);
276 1.3.6.2 yamt /* host start */
277 1.3.6.4 yamt bus_space_write_2(sc->sc_iot, sc->sc_ioh,
278 1.3.6.4 yamt AMDPM_8111_SMBUS_CTRL - off,
279 1.3.6.4 yamt AMDPM_8111_SMBUS_GSR_SB);
280 1.3.6.4 yamt
281 1.3.6.4 yamt return(amdpm_smbus_check_done(sc, op));
282 1.3.6.2 yamt }
283 1.3.6.2 yamt
284 1.3.6.2 yamt
285 1.3.6.2 yamt static int
286 1.3.6.4 yamt amdpm_smbus_write_1(struct amdpm_softc *sc, u_int8_t cmd, u_int8_t val, i2c_op_t op)
287 1.3.6.2 yamt {
288 1.3.6.4 yamt u_int16_t data = 0;
289 1.3.6.4 yamt int off = (sc->sc_nforce ? 0xe0 : 0);
290 1.3.6.4 yamt
291 1.3.6.2 yamt /* first clear gsr */
292 1.3.6.2 yamt amdpm_smbus_clear_gsr(sc);
293 1.3.6.2 yamt
294 1.3.6.2 yamt data = sc->sc_smbus_slaveaddr;
295 1.3.6.2 yamt data <<= 1;
296 1.3.6.2 yamt data |= AMDPM_8111_SMBUS_WRITE;
297 1.3.6.4 yamt bus_space_write_1(sc->sc_iot, sc->sc_ioh,
298 1.3.6.4 yamt AMDPM_8111_SMBUS_HOSTADDR - off, data);
299 1.3.6.2 yamt
300 1.3.6.2 yamt data = val;
301 1.3.6.2 yamt /* store cmd */
302 1.3.6.4 yamt bus_space_write_1(sc->sc_iot, sc->sc_ioh,
303 1.3.6.4 yamt AMDPM_8111_SMBUS_HOSTCMD - off, cmd);
304 1.3.6.2 yamt /* store data */
305 1.3.6.4 yamt bus_space_write_2(sc->sc_iot, sc->sc_ioh,
306 1.3.6.4 yamt AMDPM_8111_SMBUS_HOSTDATA - off, data);
307 1.3.6.2 yamt /* host start */
308 1.3.6.4 yamt bus_space_write_2(sc->sc_iot, sc->sc_ioh,
309 1.3.6.4 yamt AMDPM_8111_SMBUS_CTRL - off, AMDPM_8111_SMBUS_GSR_WB);
310 1.3.6.2 yamt
311 1.3.6.4 yamt return (amdpm_smbus_check_done(sc, op));
312 1.3.6.2 yamt }
313 1.3.6.2 yamt
314 1.3.6.2 yamt static int
315 1.3.6.4 yamt amdpm_smbus_receive_1(struct amdpm_softc *sc, i2c_op_t op)
316 1.3.6.2 yamt {
317 1.3.6.4 yamt u_int16_t data = 0;
318 1.3.6.4 yamt int off = (sc->sc_nforce ? 0xe0 : 0);
319 1.3.6.4 yamt
320 1.3.6.2 yamt /* first clear gsr */
321 1.3.6.2 yamt amdpm_smbus_clear_gsr(sc);
322 1.3.6.2 yamt
323 1.3.6.2 yamt /* write smbus slave address to register */
324 1.3.6.2 yamt data = sc->sc_smbus_slaveaddr;
325 1.3.6.2 yamt data <<= 1;
326 1.3.6.2 yamt data |= AMDPM_8111_SMBUS_RX;
327 1.3.6.4 yamt bus_space_write_1(sc->sc_iot, sc->sc_ioh,
328 1.3.6.4 yamt AMDPM_8111_SMBUS_HOSTADDR - off, data);
329 1.3.6.2 yamt
330 1.3.6.2 yamt /* start smbus cycle */
331 1.3.6.4 yamt bus_space_write_2(sc->sc_iot, sc->sc_ioh,
332 1.3.6.4 yamt AMDPM_8111_SMBUS_CTRL - off, AMDPM_8111_SMBUS_GSR_RXB);
333 1.3.6.2 yamt
334 1.3.6.2 yamt /* check for errors */
335 1.3.6.4 yamt if (amdpm_smbus_check_done(sc, op) < 0)
336 1.3.6.2 yamt return (-1);
337 1.3.6.2 yamt
338 1.3.6.2 yamt /* read data */
339 1.3.6.4 yamt data = bus_space_read_2(sc->sc_iot, sc->sc_ioh,
340 1.3.6.4 yamt AMDPM_8111_SMBUS_HOSTDATA - off);
341 1.3.6.2 yamt u_int8_t ret = (u_int8_t)(data & 0x00FF);
342 1.3.6.2 yamt return (ret);
343 1.3.6.2 yamt }
344 1.3.6.2 yamt
345 1.3.6.2 yamt static int
346 1.3.6.4 yamt amdpm_smbus_read_1(struct amdpm_softc *sc, u_int8_t cmd, i2c_op_t op)
347 1.3.6.4 yamt {
348 1.3.6.4 yamt u_int16_t data = 0;
349 1.3.6.4 yamt u_int8_t ret;
350 1.3.6.4 yamt int off = (sc->sc_nforce ? 0xe0 : 0);
351 1.3.6.4 yamt
352 1.3.6.2 yamt /* first clear gsr */
353 1.3.6.2 yamt amdpm_smbus_clear_gsr(sc);
354 1.3.6.2 yamt
355 1.3.6.2 yamt /* write smbus slave address to register */
356 1.3.6.2 yamt data = sc->sc_smbus_slaveaddr;
357 1.3.6.2 yamt data <<= 1;
358 1.3.6.2 yamt data |= AMDPM_8111_SMBUS_READ;
359 1.3.6.4 yamt bus_space_write_1(sc->sc_iot, sc->sc_ioh,
360 1.3.6.4 yamt AMDPM_8111_SMBUS_HOSTADDR - off, data);
361 1.3.6.2 yamt
362 1.3.6.2 yamt /* store cmd */
363 1.3.6.4 yamt bus_space_write_1(sc->sc_iot, sc->sc_ioh,
364 1.3.6.4 yamt AMDPM_8111_SMBUS_HOSTCMD - off, cmd);
365 1.3.6.2 yamt /* host start */
366 1.3.6.4 yamt bus_space_write_2(sc->sc_iot, sc->sc_ioh,
367 1.3.6.4 yamt AMDPM_8111_SMBUS_CTRL - off, AMDPM_8111_SMBUS_GSR_RB);
368 1.3.6.2 yamt
369 1.3.6.2 yamt /* check for errors */
370 1.3.6.4 yamt if (amdpm_smbus_check_done(sc, op) < 0)
371 1.3.6.2 yamt return (-1);
372 1.3.6.2 yamt
373 1.3.6.2 yamt /* store data */
374 1.3.6.4 yamt data = bus_space_read_2(sc->sc_iot, sc->sc_ioh,
375 1.3.6.4 yamt AMDPM_8111_SMBUS_HOSTDATA - off);
376 1.3.6.4 yamt ret = (u_int8_t)(data & 0x00FF);
377 1.3.6.2 yamt return (ret);
378 1.3.6.2 yamt }
379