1*0f9891f1Sjsg /* $OpenBSD: amdiic.c,v 1.14 2024/05/24 06:02:53 jsg Exp $ */
2830a95b8Sgrange
3830a95b8Sgrange /*
4830a95b8Sgrange * Copyright (c) 2005 Alexander Yurchenko <grange@openbsd.org>
5830a95b8Sgrange *
6830a95b8Sgrange * Permission to use, copy, modify, and distribute this software for any
7830a95b8Sgrange * purpose with or without fee is hereby granted, provided that the above
8830a95b8Sgrange * copyright notice and this permission notice appear in all copies.
9830a95b8Sgrange *
10830a95b8Sgrange * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11830a95b8Sgrange * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12830a95b8Sgrange * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13830a95b8Sgrange * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14830a95b8Sgrange * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15830a95b8Sgrange * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16830a95b8Sgrange * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17830a95b8Sgrange */
18830a95b8Sgrange
19830a95b8Sgrange /*
20830a95b8Sgrange * AMD-8111 SMBus controller driver.
21830a95b8Sgrange */
22830a95b8Sgrange
23830a95b8Sgrange #include <sys/param.h>
24830a95b8Sgrange #include <sys/systm.h>
25830a95b8Sgrange #include <sys/device.h>
2673550447Sdlg #include <sys/rwlock.h>
27830a95b8Sgrange
28830a95b8Sgrange #include <machine/bus.h>
29830a95b8Sgrange
30830a95b8Sgrange #include <dev/pci/pcidevs.h>
31830a95b8Sgrange #include <dev/pci/pcireg.h>
32830a95b8Sgrange #include <dev/pci/pcivar.h>
33830a95b8Sgrange
34830a95b8Sgrange #include <dev/i2c/i2cvar.h>
35830a95b8Sgrange
36830a95b8Sgrange #ifdef AMDIIC_DEBUG
37830a95b8Sgrange #define DPRINTF(x) printf x
38830a95b8Sgrange #else
39830a95b8Sgrange #define DPRINTF(x)
40830a95b8Sgrange #endif
41830a95b8Sgrange
42830a95b8Sgrange #define AMDIIC_DELAY 100
43830a95b8Sgrange #define AMDIIC_TIMEOUT 1
44830a95b8Sgrange
45830a95b8Sgrange /* PCI configuration registers */
46830a95b8Sgrange #define AMD8111_SMB_BASE 0x10 /* SMBus base address */
47830a95b8Sgrange #define AMD8111_SMB_MISC 0x48 /* miscellaneous control */
48830a95b8Sgrange #define AMD8111_SMB_MISC_SU (1 << 0) /* 16x clock speed-up */
49830a95b8Sgrange #define AMD8111_SMB_MISC_INTEN (1 << 1) /* PCI IRQ enabled */
50830a95b8Sgrange #define AMD8111_SMB_MISC_SCIEN (1 << 2) /* SCI enabled */
51830a95b8Sgrange
52830a95b8Sgrange /* SMBus I/O registers */
53830a95b8Sgrange #define AMD8111_SMB_SC_DATA 0x00 /* data port */
54830a95b8Sgrange #define AMD8111_SMB_SC_ST 0x04 /* status */
55830a95b8Sgrange #define AMD8111_SMB_SC_ST_OBF (1 << 0) /* output buffer full */
56830a95b8Sgrange #define AMD8111_SMB_SC_ST_IBF (1 << 1) /* input buffer full */
57830a95b8Sgrange #define AMD8111_SMB_SC_ST_CMD (1 << 3) /* command byte */
58830a95b8Sgrange #define AMD8111_SMB_SC_ST_BITS "\020\001OBF\002IBF\004CMD"
59830a95b8Sgrange #define AMD8111_SMB_SC_CMD 0x04 /* command port */
60830a95b8Sgrange #define AMD8111_SMB_SC_CMD_RD 0x80 /* read */
61830a95b8Sgrange #define AMD8111_SMB_SC_CMD_WR 0x81 /* write */
62830a95b8Sgrange #define AMD8111_SMB_SC_IC 0x08 /* interrupt control */
63830a95b8Sgrange
64830a95b8Sgrange /* Host controller interface registers */
65830a95b8Sgrange #define AMD8111_SMB_PROTO 0x00 /* protocol */
66830a95b8Sgrange #define AMD8111_SMB_PROTO_READ 0x01 /* read direction */
67830a95b8Sgrange #define AMD8111_SMB_PROTO_QUICK 0x02 /* QUICK command */
68830a95b8Sgrange #define AMD8111_SMB_PROTO_BYTE 0x04 /* BYTE command */
69830a95b8Sgrange #define AMD8111_SMB_PROTO_BDATA 0x06 /* BYTE DATA command */
70830a95b8Sgrange #define AMD8111_SMB_PROTO_WDATA 0x08 /* WORD DATA command */
71830a95b8Sgrange #define AMD8111_SMB_STAT 0x01 /* status */
72830a95b8Sgrange #define AMD8111_SMB_STAT_MASK 0x1f
73830a95b8Sgrange #define AMD8111_SMB_STAT_DONE (1 << 7) /* command completion */
74830a95b8Sgrange #define AMD8111_SMB_ADDR 0x02 /* address */
75830a95b8Sgrange #define AMD8111_SMB_ADDR_SHIFT 1
76830a95b8Sgrange #define AMD8111_SMB_CMD 0x03 /* SMBus command */
77830a95b8Sgrange #define AMD8111_SMB_DATA(x) (0x04 + (x)) /* SMBus data */
78830a95b8Sgrange
79830a95b8Sgrange struct amdiic_softc {
80830a95b8Sgrange struct device sc_dev;
81830a95b8Sgrange
82830a95b8Sgrange bus_space_tag_t sc_iot;
83830a95b8Sgrange bus_space_handle_t sc_ioh;
84830a95b8Sgrange void * sc_ih;
85830a95b8Sgrange int sc_poll;
86830a95b8Sgrange
87830a95b8Sgrange struct i2c_controller sc_i2c_tag;
8873550447Sdlg struct rwlock sc_i2c_lock;
89830a95b8Sgrange struct {
90830a95b8Sgrange i2c_op_t op;
91830a95b8Sgrange void * buf;
92830a95b8Sgrange size_t len;
93830a95b8Sgrange int flags;
94830a95b8Sgrange volatile int error;
95830a95b8Sgrange } sc_i2c_xfer;
96830a95b8Sgrange };
97830a95b8Sgrange
98830a95b8Sgrange int amdiic_match(struct device *, void *, void *);
99830a95b8Sgrange void amdiic_attach(struct device *, struct device *, void *);
100830a95b8Sgrange
101830a95b8Sgrange int amdiic_read(struct amdiic_softc *, u_int8_t);
102830a95b8Sgrange int amdiic_write(struct amdiic_softc *, u_int8_t, u_int8_t);
103830a95b8Sgrange int amdiic_wait(struct amdiic_softc *, int);
104830a95b8Sgrange
105830a95b8Sgrange int amdiic_i2c_acquire_bus(void *, int);
106830a95b8Sgrange void amdiic_i2c_release_bus(void *, int);
107830a95b8Sgrange int amdiic_i2c_exec(void *, i2c_op_t, i2c_addr_t, const void *, size_t,
108830a95b8Sgrange void *, size_t, int);
109830a95b8Sgrange
110830a95b8Sgrange int amdiic_intr(void *);
111830a95b8Sgrange
1128d2c75e4Smpi const struct cfattach amdiic_ca = {
113830a95b8Sgrange sizeof(struct amdiic_softc),
114830a95b8Sgrange amdiic_match,
115830a95b8Sgrange amdiic_attach
116830a95b8Sgrange };
117830a95b8Sgrange
118830a95b8Sgrange struct cfdriver amdiic_cd = {
119830a95b8Sgrange NULL, "amdiic", DV_DULL
120830a95b8Sgrange };
121830a95b8Sgrange
122830a95b8Sgrange const struct pci_matchid amdiic_ids[] = {
123830a95b8Sgrange { PCI_VENDOR_AMD, PCI_PRODUCT_AMD_8111_SMB }
124830a95b8Sgrange };
125830a95b8Sgrange
126830a95b8Sgrange int
amdiic_match(struct device * parent,void * match,void * aux)127830a95b8Sgrange amdiic_match(struct device *parent, void *match, void *aux)
128830a95b8Sgrange {
129830a95b8Sgrange return (pci_matchbyid(aux, amdiic_ids,
130830a95b8Sgrange sizeof(amdiic_ids) / sizeof(amdiic_ids[0])));
131830a95b8Sgrange }
132830a95b8Sgrange
133830a95b8Sgrange void
amdiic_attach(struct device * parent,struct device * self,void * aux)134830a95b8Sgrange amdiic_attach(struct device *parent, struct device *self, void *aux)
135830a95b8Sgrange {
136830a95b8Sgrange struct amdiic_softc *sc = (struct amdiic_softc *)self;
137830a95b8Sgrange struct pci_attach_args *pa = aux;
138830a95b8Sgrange struct i2cbus_attach_args iba;
139830a95b8Sgrange pcireg_t conf;
140830a95b8Sgrange bus_size_t iosize;
141830a95b8Sgrange pci_intr_handle_t ih;
142830a95b8Sgrange const char *intrstr = NULL;
143830a95b8Sgrange
144830a95b8Sgrange /* Map I/O space */
145830a95b8Sgrange if (pci_mapreg_map(pa, AMD8111_SMB_BASE, PCI_MAPREG_TYPE_IO, 0,
146830a95b8Sgrange &sc->sc_iot, &sc->sc_ioh, NULL, &iosize, 0)) {
147e10c952fSsthen printf(": can't map i/o space\n");
148830a95b8Sgrange return;
149830a95b8Sgrange }
150830a95b8Sgrange
151830a95b8Sgrange /* Read configuration */
152830a95b8Sgrange conf = pci_conf_read(pa->pa_pc, pa->pa_tag, AMD8111_SMB_MISC);
1536f23e57aSgrange DPRINTF((": conf 0x%08x", conf));
154830a95b8Sgrange
155830a95b8Sgrange sc->sc_poll = 1;
156e3269dfcSgrange if (conf & AMD8111_SMB_MISC_SCIEN) {
157e3269dfcSgrange /* No PCI IRQ */
158e3269dfcSgrange printf(": SCI");
159830a95b8Sgrange } else if (conf & AMD8111_SMB_MISC_INTEN) {
160830a95b8Sgrange /* Install interrupt handler */
161e3269dfcSgrange if (pci_intr_map(pa, &ih) == 0) {
162830a95b8Sgrange intrstr = pci_intr_string(pa->pa_pc, ih);
163830a95b8Sgrange sc->sc_ih = pci_intr_establish(pa->pa_pc, ih, IPL_BIO,
164830a95b8Sgrange amdiic_intr, sc, sc->sc_dev.dv_xname);
165e3269dfcSgrange if (sc->sc_ih != NULL) {
166830a95b8Sgrange printf(": %s", intrstr);
167e3269dfcSgrange sc->sc_poll = 0;
168e3269dfcSgrange }
169e3269dfcSgrange }
170e3269dfcSgrange if (sc->sc_poll)
171e3269dfcSgrange printf(": polling");
172830a95b8Sgrange }
173830a95b8Sgrange
174830a95b8Sgrange printf("\n");
175830a95b8Sgrange
176830a95b8Sgrange /* Attach I2C bus */
17773550447Sdlg rw_init(&sc->sc_i2c_lock, "iiclk");
178830a95b8Sgrange sc->sc_i2c_tag.ic_cookie = sc;
179830a95b8Sgrange sc->sc_i2c_tag.ic_acquire_bus = amdiic_i2c_acquire_bus;
180830a95b8Sgrange sc->sc_i2c_tag.ic_release_bus = amdiic_i2c_release_bus;
181830a95b8Sgrange sc->sc_i2c_tag.ic_exec = amdiic_i2c_exec;
182a5a63700Sderaadt
183f57d9f10Sgrange bzero(&iba, sizeof(iba));
184830a95b8Sgrange iba.iba_name = "iic";
185830a95b8Sgrange iba.iba_tag = &sc->sc_i2c_tag;
186830a95b8Sgrange config_found(self, &iba, iicbus_print);
187830a95b8Sgrange
188830a95b8Sgrange return;
189830a95b8Sgrange }
190830a95b8Sgrange
191830a95b8Sgrange int
amdiic_read(struct amdiic_softc * sc,u_int8_t reg)192830a95b8Sgrange amdiic_read(struct amdiic_softc *sc, u_int8_t reg)
193830a95b8Sgrange {
194830a95b8Sgrange if (amdiic_wait(sc, 0))
195830a95b8Sgrange return (-1);
196830a95b8Sgrange bus_space_write_1(sc->sc_iot, sc->sc_ioh, AMD8111_SMB_SC_CMD,
197830a95b8Sgrange AMD8111_SMB_SC_CMD_RD);
198830a95b8Sgrange if (amdiic_wait(sc, 0))
199830a95b8Sgrange return (-1);
200830a95b8Sgrange bus_space_write_1(sc->sc_iot, sc->sc_ioh, AMD8111_SMB_SC_DATA, reg);
201830a95b8Sgrange if (amdiic_wait(sc, 1))
202830a95b8Sgrange return (-1);
203830a95b8Sgrange
204830a95b8Sgrange return (bus_space_read_1(sc->sc_iot, sc->sc_ioh, AMD8111_SMB_SC_DATA));
205830a95b8Sgrange }
206830a95b8Sgrange
207830a95b8Sgrange int
amdiic_write(struct amdiic_softc * sc,u_int8_t reg,u_int8_t val)208830a95b8Sgrange amdiic_write(struct amdiic_softc *sc, u_int8_t reg, u_int8_t val)
209830a95b8Sgrange {
210830a95b8Sgrange if (amdiic_wait(sc, 0))
211830a95b8Sgrange return (-1);
212830a95b8Sgrange bus_space_write_1(sc->sc_iot, sc->sc_ioh, AMD8111_SMB_SC_CMD,
213830a95b8Sgrange AMD8111_SMB_SC_CMD_WR);
214830a95b8Sgrange if (amdiic_wait(sc, 0))
215830a95b8Sgrange return (-1);
216830a95b8Sgrange bus_space_write_1(sc->sc_iot, sc->sc_ioh, AMD8111_SMB_SC_DATA, reg);
217830a95b8Sgrange if (amdiic_wait(sc, 0))
218830a95b8Sgrange return (-1);
219830a95b8Sgrange bus_space_write_1(sc->sc_iot, sc->sc_ioh, AMD8111_SMB_SC_DATA, val);
220830a95b8Sgrange
221830a95b8Sgrange return (0);
222830a95b8Sgrange }
223830a95b8Sgrange
224830a95b8Sgrange int
amdiic_wait(struct amdiic_softc * sc,int output)225830a95b8Sgrange amdiic_wait(struct amdiic_softc *sc, int output)
226830a95b8Sgrange {
227830a95b8Sgrange int retries;
228830a95b8Sgrange u_int8_t st;
229830a95b8Sgrange
230830a95b8Sgrange for (retries = 100; retries > 0; retries--) {
231830a95b8Sgrange st = bus_space_read_1(sc->sc_iot, sc->sc_ioh,
232830a95b8Sgrange AMD8111_SMB_SC_ST);
233830a95b8Sgrange if (output && (st & AMD8111_SMB_SC_ST_OBF))
234830a95b8Sgrange return (0);
235830a95b8Sgrange if (!output && (st & AMD8111_SMB_SC_ST_IBF) == 0)
236830a95b8Sgrange return (0);
237830a95b8Sgrange DELAY(1);
238830a95b8Sgrange }
239830a95b8Sgrange DPRINTF(("%s: %s wait timeout: st 0x%b\n", sc->sc_dev.dv_xname,
240830a95b8Sgrange (output ? "output" : "input"), st));
241830a95b8Sgrange
242830a95b8Sgrange return (1);
243830a95b8Sgrange }
244830a95b8Sgrange
245830a95b8Sgrange int
amdiic_i2c_acquire_bus(void * cookie,int flags)246830a95b8Sgrange amdiic_i2c_acquire_bus(void *cookie, int flags)
247830a95b8Sgrange {
248830a95b8Sgrange struct amdiic_softc *sc = cookie;
249830a95b8Sgrange
250830a95b8Sgrange if (cold || sc->sc_poll || (flags & I2C_F_POLL))
251830a95b8Sgrange return (0);
252830a95b8Sgrange
25373550447Sdlg return (rw_enter(&sc->sc_i2c_lock, RW_WRITE | RW_INTR));
254830a95b8Sgrange }
255830a95b8Sgrange
256830a95b8Sgrange void
amdiic_i2c_release_bus(void * cookie,int flags)257830a95b8Sgrange amdiic_i2c_release_bus(void *cookie, int flags)
258830a95b8Sgrange {
259830a95b8Sgrange struct amdiic_softc *sc = cookie;
260830a95b8Sgrange
261830a95b8Sgrange if (cold || sc->sc_poll || (flags & I2C_F_POLL))
262830a95b8Sgrange return;
263830a95b8Sgrange
26473550447Sdlg rw_exit(&sc->sc_i2c_lock);
265830a95b8Sgrange }
266830a95b8Sgrange
267830a95b8Sgrange int
amdiic_i2c_exec(void * cookie,i2c_op_t op,i2c_addr_t addr,const void * cmdbuf,size_t cmdlen,void * buf,size_t len,int flags)268830a95b8Sgrange amdiic_i2c_exec(void *cookie, i2c_op_t op, i2c_addr_t addr,
269830a95b8Sgrange const void *cmdbuf, size_t cmdlen, void *buf, size_t len, int flags)
270830a95b8Sgrange {
271830a95b8Sgrange struct amdiic_softc *sc = cookie;
272830a95b8Sgrange u_int8_t *b;
273830a95b8Sgrange u_int8_t proto, st;
274830a95b8Sgrange int retries;
275830a95b8Sgrange
2766f23e57aSgrange DPRINTF(("%s: exec: op %d, addr 0x%02x, cmdlen %d, len %d, "
2776f23e57aSgrange "flags 0x%02x\n", sc->sc_dev.dv_xname, op, addr,
278830a95b8Sgrange cmdlen, len, flags));
279830a95b8Sgrange
280830a95b8Sgrange if (cold || sc->sc_poll)
281830a95b8Sgrange flags |= I2C_F_POLL;
282830a95b8Sgrange
283830a95b8Sgrange if (!I2C_OP_STOP_P(op) || cmdlen > 1 || len > 2)
284830a95b8Sgrange return (1);
285830a95b8Sgrange
286830a95b8Sgrange /* Setup transfer */
287830a95b8Sgrange sc->sc_i2c_xfer.op = op;
288830a95b8Sgrange sc->sc_i2c_xfer.buf = buf;
289830a95b8Sgrange sc->sc_i2c_xfer.len = len;
290830a95b8Sgrange sc->sc_i2c_xfer.flags = flags;
291830a95b8Sgrange sc->sc_i2c_xfer.error = 0;
292830a95b8Sgrange
293830a95b8Sgrange /* Set slave address */
294830a95b8Sgrange if (amdiic_write(sc, AMD8111_SMB_ADDR,
295830a95b8Sgrange addr << AMD8111_SMB_ADDR_SHIFT) == -1)
296830a95b8Sgrange return (1);
297830a95b8Sgrange
298830a95b8Sgrange b = (void *)cmdbuf;
299830a95b8Sgrange if (cmdlen > 0)
300830a95b8Sgrange /* Set command byte */
301830a95b8Sgrange if (amdiic_write(sc, AMD8111_SMB_CMD, b[0]) == -1)
302830a95b8Sgrange return (1);
303830a95b8Sgrange
304830a95b8Sgrange if (I2C_OP_WRITE_P(op)) {
305830a95b8Sgrange /* Write data */
306830a95b8Sgrange b = buf;
307830a95b8Sgrange if (len > 0)
308830a95b8Sgrange if (amdiic_write(sc, AMD8111_SMB_DATA(0), b[0]) == -1)
309830a95b8Sgrange return (1);
310830a95b8Sgrange if (len > 1)
311830a95b8Sgrange if (amdiic_write(sc, AMD8111_SMB_DATA(1), b[1]) == -1)
312830a95b8Sgrange return (1);
313830a95b8Sgrange }
314830a95b8Sgrange
315830a95b8Sgrange /* Set SMBus command */
316830a95b8Sgrange if (len == 0)
317830a95b8Sgrange proto = AMD8111_SMB_PROTO_BYTE;
318830a95b8Sgrange else if (len == 1)
319830a95b8Sgrange proto = AMD8111_SMB_PROTO_BDATA;
320830a95b8Sgrange else if (len == 2)
321830a95b8Sgrange proto = AMD8111_SMB_PROTO_WDATA;
322c0d07f7cShaesbaert else
323c0d07f7cShaesbaert panic("%s: unexpected len %zd", __func__, len);
324830a95b8Sgrange
325830a95b8Sgrange /* Set direction */
326830a95b8Sgrange if (I2C_OP_READ_P(op))
327830a95b8Sgrange proto |= AMD8111_SMB_PROTO_READ;
328830a95b8Sgrange
329830a95b8Sgrange /* Start transaction */
330830a95b8Sgrange amdiic_write(sc, AMD8111_SMB_PROTO, proto);
331830a95b8Sgrange
332830a95b8Sgrange if (flags & I2C_F_POLL) {
333830a95b8Sgrange /* Poll for completion */
334830a95b8Sgrange DELAY(AMDIIC_DELAY);
335830a95b8Sgrange for (retries = 1000; retries > 0; retries--) {
336830a95b8Sgrange st = amdiic_read(sc, AMD8111_SMB_STAT);
337830a95b8Sgrange if (st != 0)
338830a95b8Sgrange break;
339830a95b8Sgrange DELAY(AMDIIC_DELAY);
340830a95b8Sgrange }
341830a95b8Sgrange if (st == 0) {
3422b2fa8a9Ssf printf("%s: exec: op %d, addr 0x%02x, cmdlen %zu, "
3432b2fa8a9Ssf "len %zu, flags 0x%02x: timeout\n",
3446f23e57aSgrange sc->sc_dev.dv_xname, op, addr, cmdlen, len, flags);
345830a95b8Sgrange return (1);
346830a95b8Sgrange }
347830a95b8Sgrange amdiic_intr(sc);
348830a95b8Sgrange } else {
349830a95b8Sgrange /* Wait for interrupt */
3508544fed6Smpi if (tsleep_nsec(sc, PRIBIO, "amdiic",
3518544fed6Smpi SEC_TO_NSEC(AMDIIC_TIMEOUT)))
352830a95b8Sgrange return (1);
353830a95b8Sgrange }
354830a95b8Sgrange
355830a95b8Sgrange if (sc->sc_i2c_xfer.error)
356830a95b8Sgrange return (1);
357830a95b8Sgrange
358830a95b8Sgrange return (0);
359830a95b8Sgrange }
360830a95b8Sgrange
361830a95b8Sgrange int
amdiic_intr(void * arg)362830a95b8Sgrange amdiic_intr(void *arg)
363830a95b8Sgrange {
364830a95b8Sgrange struct amdiic_softc *sc = arg;
365830a95b8Sgrange int st;
366830a95b8Sgrange u_int8_t *b;
367830a95b8Sgrange size_t len;
368830a95b8Sgrange
369830a95b8Sgrange /* Read status */
370830a95b8Sgrange if ((st = amdiic_read(sc, AMD8111_SMB_STAT)) == -1)
371830a95b8Sgrange return (-1);
372830a95b8Sgrange if (st == 0)
373830a95b8Sgrange /* Interrupt was not for us */
374830a95b8Sgrange return (0);
375830a95b8Sgrange
3766f23e57aSgrange DPRINTF(("%s: intr: st 0x%02x\n", sc->sc_dev.dv_xname, st));
377830a95b8Sgrange
378830a95b8Sgrange /* Check for errors */
379830a95b8Sgrange if ((st & AMD8111_SMB_STAT_MASK) != 0) {
380830a95b8Sgrange sc->sc_i2c_xfer.error = 1;
381830a95b8Sgrange goto done;
382830a95b8Sgrange }
383830a95b8Sgrange
384830a95b8Sgrange if (st & AMD8111_SMB_STAT_DONE) {
385830a95b8Sgrange if (I2C_OP_WRITE_P(sc->sc_i2c_xfer.op))
386830a95b8Sgrange goto done;
387830a95b8Sgrange
388830a95b8Sgrange /* Read data */
389830a95b8Sgrange b = sc->sc_i2c_xfer.buf;
390830a95b8Sgrange len = sc->sc_i2c_xfer.len;
391830a95b8Sgrange if (len > 0)
392830a95b8Sgrange b[0] = amdiic_read(sc, AMD8111_SMB_DATA(0));
393830a95b8Sgrange if (len > 1)
394830a95b8Sgrange b[1] = amdiic_read(sc, AMD8111_SMB_DATA(1));
395830a95b8Sgrange }
396830a95b8Sgrange
397830a95b8Sgrange done:
398830a95b8Sgrange if ((sc->sc_i2c_xfer.flags & I2C_F_POLL) == 0)
399830a95b8Sgrange wakeup(sc);
400830a95b8Sgrange return (1);
401830a95b8Sgrange }
402