2 * Copyright (c) 2014 The DragonFly Project. All rights reserved.
4 * This code is derived from software contributed to The DragonFly Project
5 * by Matthew Dillon <dillon@backplane.com>
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
17 * 3. Neither the name of The DragonFly Project nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific, prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25 * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26 * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
27 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
29 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
31 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 * Intel 4th generation mobile cpus integrated I2C device, smbus driver.
37 * See ig4_reg.h for datasheet reference and notes.
40 #include <sys/param.h>
41 #include <sys/systm.h>
42 #include <sys/kernel.h>
43 #include <sys/module.h>
44 #include <sys/errno.h>
46 #include <sys/mutex.h>
47 #include <sys/syslog.h>
49 #include <sys/sysctl.h>
53 #include <bus/pci/pcivar.h>
54 #include <bus/pci/pcireg.h>
55 #include <bus/smbus/smbconf.h>
62 #define TRANS_NORMAL 1
66 static void ig4iic_intr(void *cookie);
67 static void ig4iic_dump(ig4iic_softc_t *sc);
70 SYSCTL_INT(_debug, OID_AUTO, ig4_dump, CTLTYPE_INT | CTLFLAG_RW,
74 * Low-level inline support functions
78 reg_write(ig4iic_softc_t *sc, uint32_t reg, uint32_t value)
80 bus_space_write_4(sc->regs_t, sc->regs_h, reg, value);
81 bus_space_barrier(sc->regs_t, sc->regs_h, reg, 4,
82 BUS_SPACE_BARRIER_WRITE);
87 reg_read(ig4iic_softc_t *sc, uint32_t reg)
91 bus_space_barrier(sc->regs_t, sc->regs_h, reg, 4,
92 BUS_SPACE_BARRIER_READ);
93 value = bus_space_read_4(sc->regs_t, sc->regs_h, reg);
98 * Enable or disable the controller and wait for the controller to acknowledge
103 set_controller(ig4iic_softc_t *sc, uint32_t ctl)
109 if (ctl & IG4_I2C_ENABLE) {
110 reg_write(sc, IG4_REG_INTR_MASK, IG4_INTR_STOP_DET |
112 reg_read(sc, IG4_REG_CLR_INTR);
114 reg_write(sc, IG4_REG_INTR_MASK, 0);
116 reg_write(sc, IG4_REG_I2C_EN, ctl);
117 error = SMB_ETIMEOUT;
119 for (retry = 100; retry > 0; --retry) {
120 v = reg_read(sc, IG4_REG_ENABLE_STATUS);
121 if (((v ^ ctl) & IG4_I2C_ENABLE) == 0) {
125 tsleep(sc, 0, "i2cslv", 1);
131 * Wait up to 25ms for the requested status using a 25uS polling loop.
135 wait_status(ig4iic_softc_t *sc, uint32_t status)
143 error = SMB_ETIMEOUT;
144 count = sys_cputimer->count();
145 limit = sys_cputimer->freq / 40;
149 * Check requested status
151 v = reg_read(sc, IG4_REG_I2C_STA);
158 * When waiting for receive data break-out if the interrupt
159 * loaded data into the FIFO.
161 if (status & IG4_STATUS_RX_NOTEMPTY) {
162 if (sc->rpos != sc->rnext) {
169 * When waiting for the transmit FIFO to become empty,
170 * reset the timeout if we see a change in the transmit
171 * FIFO level as progress is being made.
173 if (status & IG4_STATUS_TX_EMPTY) {
174 v = reg_read(sc, IG4_REG_TXFLR) & IG4_FIFOLVL_MASK;
177 count = sys_cputimer->count();
182 * Stop if we've run out of time.
184 if (sys_cputimer->count() - count > limit)
188 * When waiting for receive data let the interrupt do its
189 * work, otherwise poll with the lock held.
191 if (status & IG4_STATUS_RX_NOTEMPTY) {
192 lksleep(sc, &sc->lk, 0, "i2cwait", (hz + 99) / 100);
202 * Read I2C data. The data might have already been read by
203 * the interrupt code, otherwise it is sitting in the data
208 data_read(ig4iic_softc_t *sc)
212 if (sc->rpos == sc->rnext) {
213 c = (uint8_t)reg_read(sc, IG4_REG_DATA_CMD);
215 c = sc->rbuf[sc->rpos & IG4_RBUFMASK];
222 * Set the slave address. The controller must be disabled when
223 * changing the address.
225 * This operation does not issue anything to the I2C bus but sets
226 * the target address for when the controller later issues a START.
230 set_slave_addr(ig4iic_softc_t *sc, uint8_t slave, int trans_op)
236 use_10bit = sc->use_10bit;
237 if (trans_op & SMB_TRANS_7BIT)
239 if (trans_op & SMB_TRANS_10BIT)
242 if (sc->slave_valid && sc->last_slave == slave &&
243 sc->use_10bit == use_10bit) {
246 sc->use_10bit = use_10bit;
249 * Wait for TXFIFO to drain before disabling the controller.
251 * If a write message has not been completed it's really a
252 * programming error, but for now in that case issue an extra
255 * If a read message has not been completed it's also a programming
256 * error, for now just ignore it.
258 wait_status(sc, IG4_STATUS_TX_NOTFULL);
259 if (sc->write_started) {
260 reg_write(sc, IG4_REG_DATA_CMD, IG4_DATA_STOP);
261 sc->write_started = 0;
263 if (sc->read_started)
264 sc->read_started = 0;
265 wait_status(sc, IG4_STATUS_TX_EMPTY);
267 set_controller(sc, 0);
268 ctl = reg_read(sc, IG4_REG_CTL);
269 ctl &= ~IG4_CTL_10BIT;
270 ctl |= IG4_CTL_RESTARTEN;
274 tar |= IG4_TAR_10BIT;
275 ctl |= IG4_CTL_10BIT;
277 reg_write(sc, IG4_REG_CTL, ctl);
278 reg_write(sc, IG4_REG_TAR_ADD, tar);
279 set_controller(sc, IG4_I2C_ENABLE);
281 sc->last_slave = slave;
285 * Issue START with byte command, possible count, and a variable length
286 * read or write buffer, then possible turn-around read. The read also
287 * has a possible count received.
291 * Quick: START+ADDR+RD/WR STOP
293 * Normal: START+ADDR+WR CMD DATA..DATA STOP
296 * RESTART+ADDR RDATA..RDATA STOP
297 * (can also be used for I2C transactions)
299 * Process Call: START+ADDR+WR CMD DATAL DATAH
300 * RESTART+ADDR+RD RDATAL RDATAH STOP
302 * Block: START+ADDR+RD CMD
303 * RESTART+ADDR+RD RCOUNT DATA... STOP
306 * RESTART+ADDR+WR WCOUNT DATA... STOP
308 * For I2C - basically, no *COUNT fields, possibly no *CMD field. If the
309 * sender needs to issue a 2-byte command it will incorporate it
310 * into the write buffer and also set NOCMD.
312 * Generally speaking, the START+ADDR / RESTART+ADDR is handled automatically
313 * by the controller at the beginning of a command sequence or on a data
314 * direction turn-around, and we only need to tell it when to issue the STOP.
317 smb_transaction(ig4iic_softc_t *sc, char cmd, int op,
318 char *wbuf, int wcount, char *rbuf, int rcount, int *actualp)
325 * Debugging - dump registers
328 unit = device_get_unit(sc->dev);
329 if (ig4_dump & (1 << unit)) {
330 ig4_dump &= ~(1 << unit);
336 * Issue START or RESTART with next data byte, clear any previous
337 * abort condition that may have been holding the txfifo in reset.
339 last = IG4_DATA_RESTART;
340 reg_read(sc, IG4_REG_CLR_TX_ABORT);
345 * Issue command if not told otherwise (smbus).
347 if ((op & SMB_TRANS_NOCMD) == 0) {
348 error = wait_status(sc, IG4_STATUS_TX_NOTFULL);
352 if (wcount == 0 && rcount == 0 && (op & SMB_TRANS_NOSTOP) == 0)
353 last |= IG4_DATA_STOP;
354 reg_write(sc, IG4_REG_DATA_CMD, last);
359 * Clean out any previously received data.
361 if (sc->rpos != sc->rnext &&
362 (op & SMB_TRANS_NOREPORT) == 0) {
363 device_printf(sc->dev,
364 "discarding %d bytes of spurious data\n",
365 sc->rnext - sc->rpos);
371 * If writing and not told otherwise, issue the write count (smbus).
373 if (wcount && (op & SMB_TRANS_NOCNT) == 0) {
374 error = wait_status(sc, IG4_STATUS_TX_NOTFULL);
378 reg_write(sc, IG4_REG_DATA_CMD, last);
386 error = wait_status(sc, IG4_STATUS_TX_NOTFULL);
389 last |= (u_char)*wbuf;
390 if (wcount == 1 && rcount == 0 && (op & SMB_TRANS_NOSTOP) == 0)
391 last |= IG4_DATA_STOP;
392 reg_write(sc, IG4_REG_DATA_CMD, last);
399 * Issue reads to xmit FIFO (strange, I know) to tell the controller
400 * to clock in data. At the moment just issue one read ahead to
401 * pipeline the incoming data.
403 * NOTE: In the case of NOCMD and wcount == 0 we still issue a
404 * RESTART here, even if the data direction has not changed
405 * from the previous CHAINing call. This we force the RESTART.
406 * (A new START is issued automatically by the controller in
407 * the other nominal cases such as a data direction change or
408 * a previous STOP was issued).
410 * If this will be the last byte read we must also issue the STOP
411 * at the end of the read.
414 last = IG4_DATA_RESTART | IG4_DATA_COMMAND_RD;
416 (op & (SMB_TRANS_NOSTOP | SMB_TRANS_NOCNT)) ==
418 last |= IG4_DATA_STOP;
420 reg_write(sc, IG4_REG_DATA_CMD, last);
421 last = IG4_DATA_COMMAND_RD;
425 * Bulk read (i2c) and count field handling (smbus)
429 * Maintain a pipeline by queueing the allowance for the next
430 * read before waiting for the current read.
433 if (op & SMB_TRANS_NOCNT)
434 last = (rcount == 2) ? IG4_DATA_STOP : 0;
437 reg_write(sc, IG4_REG_DATA_CMD, IG4_DATA_COMMAND_RD |
440 error = wait_status(sc, IG4_STATUS_RX_NOTEMPTY);
442 if ((op & SMB_TRANS_NOREPORT) == 0) {
443 device_printf(sc->dev,
444 "rx timeout addr 0x%02x\n",
449 last = data_read(sc);
451 if (op & SMB_TRANS_NOCNT) {
452 *rbuf = (u_char)last;
459 * Handle count field (smbus), which is not part of
460 * the rcount'ed buffer. The first read data in a
461 * bulk transfer is the count.
463 * XXX if rcount is loaded as 0 how do I generate a
464 * STOP now without issuing another RD or WR?
466 if (rcount > (u_char)last)
467 rcount = (u_char)last;
468 op |= SMB_TRANS_NOCNT;
473 /* XXX wait for xmit buffer to become empty */
474 last = reg_read(sc, IG4_REG_TX_ABRT_SOURCE);
480 * SMBUS API FUNCTIONS
482 * Called from ig4iic_pci_attach/detach()
485 ig4iic_attach(ig4iic_softc_t *sc)
490 lockmgr(&sc->lk, LK_EXCLUSIVE);
492 v = reg_read(sc, IG4_REG_COMP_TYPE);
493 kprintf("type %08x", v);
494 v = reg_read(sc, IG4_REG_COMP_PARAM1);
495 kprintf(" params %08x", v);
496 v = reg_read(sc, IG4_REG_GENERAL);
497 kprintf(" general %08x", v);
498 if ((v & IG4_GENERAL_SWMODE) == 0) {
499 v |= IG4_GENERAL_SWMODE;
500 reg_write(sc, IG4_REG_GENERAL, v);
501 v = reg_read(sc, IG4_REG_GENERAL);
502 kprintf(" (updated %08x)", v);
505 v = reg_read(sc, IG4_REG_SW_LTR_VALUE);
506 kprintf(" swltr %08x", v);
507 v = reg_read(sc, IG4_REG_AUTO_LTR_VALUE);
508 kprintf(" autoltr %08x", v);
510 v = reg_read(sc, IG4_REG_COMP_VER);
511 kprintf(" version %08x\n", v);
512 if (v != IG4_COMP_VER) {
517 v = reg_read(sc, IG4_REG_SS_SCL_HCNT);
518 kprintf("SS_SCL_HCNT=%08x", v);
519 v = reg_read(sc, IG4_REG_SS_SCL_LCNT);
520 kprintf(" LCNT=%08x", v);
521 v = reg_read(sc, IG4_REG_FS_SCL_HCNT);
522 kprintf(" FS_SCL_HCNT=%08x", v);
523 v = reg_read(sc, IG4_REG_FS_SCL_LCNT);
524 kprintf(" LCNT=%08x\n", v);
525 v = reg_read(sc, IG4_REG_SDA_HOLD);
526 kprintf("HOLD %08x\n", v);
528 v = reg_read(sc, IG4_REG_SS_SCL_HCNT);
529 reg_write(sc, IG4_REG_FS_SCL_HCNT, v);
530 v = reg_read(sc, IG4_REG_SS_SCL_LCNT);
531 reg_write(sc, IG4_REG_FS_SCL_LCNT, v);
534 * Program based on a 25000 Hz clock. This is a bit of a
535 * hack (obviously). The defaults are 400 and 470 for standard
536 * and 60 and 130 for fast. The defaults for standard fail
537 * utterly (presumably cause an abort) because the clock time
538 * is ~18.8ms by default. This brings it down to ~4ms (for now).
540 reg_write(sc, IG4_REG_SS_SCL_HCNT, 100);
541 reg_write(sc, IG4_REG_SS_SCL_LCNT, 125);
542 reg_write(sc, IG4_REG_FS_SCL_HCNT, 100);
543 reg_write(sc, IG4_REG_FS_SCL_LCNT, 125);
546 * Use a threshold of 1 so we get interrupted on each character,
547 * allowing us to use lksleep() in our poll code. Not perfect
548 * but this is better than using DELAY() for receiving data.
550 reg_write(sc, IG4_REG_RX_TL, 1);
552 reg_write(sc, IG4_REG_CTL,
554 IG4_CTL_SLAVE_DISABLE |
558 sc->smb = device_add_child(sc->dev, "smbus", -1);
559 if (sc->smb == NULL) {
560 device_printf(sc->dev, "smbus driver not found\n");
567 * Don't do this, it blows up the PCI config
569 reg_write(sc, IG4_REG_RESETS, IG4_RESETS_ASSERT);
570 reg_write(sc, IG4_REG_RESETS, IG4_RESETS_DEASSERT);
574 * Interrupt on STOP detect or receive character ready
576 if (set_controller(sc, 0))
577 device_printf(sc->dev, "controller error during attach-1\n");
578 if (set_controller(sc, IG4_I2C_ENABLE))
579 device_printf(sc->dev, "controller error during attach-2\n");
580 error = bus_setup_intr(sc->dev, sc->intr_res, 0,
581 ig4iic_intr, sc, &sc->intr_handle, NULL);
583 device_printf(sc->dev,
584 "Unable to setup irq: error %d\n", error);
588 /* Attach us to the smbus */
589 lockmgr(&sc->lk, LK_RELEASE);
590 error = bus_generic_attach(sc->dev);
591 lockmgr(&sc->lk, LK_EXCLUSIVE);
593 device_printf(sc->dev,
594 "failed to attach child: error %d\n", error);
597 sc->generic_attached = 1;
600 lockmgr(&sc->lk, LK_RELEASE);
605 ig4iic_detach(ig4iic_softc_t *sc)
609 lockmgr(&sc->lk, LK_EXCLUSIVE);
611 reg_write(sc, IG4_REG_INTR_MASK, 0);
612 set_controller(sc, 0);
614 if (sc->generic_attached) {
615 error = bus_generic_detach(sc->dev);
618 sc->generic_attached = 0;
621 device_delete_child(sc->dev, sc->smb);
624 if (sc->intr_handle) {
625 bus_teardown_intr(sc->dev, sc->intr_res, sc->intr_handle);
626 sc->intr_handle = NULL;
631 lockmgr(&sc->lk, LK_RELEASE);
636 ig4iic_smb_callback(device_t dev, int index, void *data)
638 ig4iic_softc_t *sc = device_get_softc(dev);
641 lockmgr(&sc->lk, LK_EXCLUSIVE);
644 case SMB_REQUEST_BUS:
647 case SMB_RELEASE_BUS:
655 lockmgr(&sc->lk, LK_RELEASE);
661 * Quick command. i.e. START + cmd + R/W + STOP and no data. It is
662 * unclear to me how I could implement this with the intel i2c controller
663 * because the controler sends STARTs and STOPs automatically with data.
666 ig4iic_smb_quick(device_t dev, u_char slave, int how)
668 ig4iic_softc_t *sc = device_get_softc(dev);
671 lockmgr(&sc->lk, LK_EXCLUSIVE);
675 error = SMB_ENOTSUPP;
678 error = SMB_ENOTSUPP;
681 error = SMB_ENOTSUPP;
684 lockmgr(&sc->lk, LK_RELEASE);
690 * Incremental send byte without stop (?). It is unclear why the slave
691 * address is specified if this presumably is used in combination with
692 * ig4iic_smb_quick().
694 * (Also, how would this work anyway? Issue the last byte with writeb()?)
697 ig4iic_smb_sendb(device_t dev, u_char slave, char byte)
699 ig4iic_softc_t *sc = device_get_softc(dev);
703 lockmgr(&sc->lk, LK_EXCLUSIVE);
705 set_slave_addr(sc, slave, 0);
707 if (wait_status(sc, IG4_STATUS_TX_NOTFULL) == 0) {
708 reg_write(sc, IG4_REG_DATA_CMD, cmd);
711 error = SMB_ETIMEOUT;
714 lockmgr(&sc->lk, LK_RELEASE);
719 * Incremental receive byte without stop (?). It is unclear why the slave
720 * address is specified if this presumably is used in combination with
721 * ig4iic_smb_quick().
724 ig4iic_smb_recvb(device_t dev, u_char slave, char *byte)
726 ig4iic_softc_t *sc = device_get_softc(dev);
729 lockmgr(&sc->lk, LK_EXCLUSIVE);
731 set_slave_addr(sc, slave, 0);
732 reg_write(sc, IG4_REG_DATA_CMD, IG4_DATA_COMMAND_RD);
733 if (wait_status(sc, IG4_STATUS_RX_NOTEMPTY) == 0) {
734 *byte = data_read(sc);
738 error = SMB_ETIMEOUT;
741 lockmgr(&sc->lk, LK_RELEASE);
746 * Write command and single byte in transaction.
749 ig4iic_smb_writeb(device_t dev, u_char slave, char cmd, char byte)
751 ig4iic_softc_t *sc = device_get_softc(dev);
754 lockmgr(&sc->lk, LK_EXCLUSIVE);
756 set_slave_addr(sc, slave, 0);
757 error = smb_transaction(sc, cmd, SMB_TRANS_NOCNT,
758 &byte, 1, NULL, 0, NULL);
760 lockmgr(&sc->lk, LK_RELEASE);
765 * Write command and single word in transaction.
768 ig4iic_smb_writew(device_t dev, u_char slave, char cmd, short word)
770 ig4iic_softc_t *sc = device_get_softc(dev);
774 lockmgr(&sc->lk, LK_EXCLUSIVE);
776 set_slave_addr(sc, slave, 0);
777 buf[0] = word & 0xFF;
779 error = smb_transaction(sc, cmd, SMB_TRANS_NOCNT,
780 buf, 2, NULL, 0, NULL);
782 lockmgr(&sc->lk, LK_RELEASE);
787 * write command and read single byte in transaction.
790 ig4iic_smb_readb(device_t dev, u_char slave, char cmd, char *byte)
792 ig4iic_softc_t *sc = device_get_softc(dev);
795 lockmgr(&sc->lk, LK_EXCLUSIVE);
797 set_slave_addr(sc, slave, 0);
798 error = smb_transaction(sc, cmd, SMB_TRANS_NOCNT,
799 NULL, 0, byte, 1, NULL);
801 lockmgr(&sc->lk, LK_RELEASE);
806 * write command and read word in transaction.
809 ig4iic_smb_readw(device_t dev, u_char slave, char cmd, short *word)
811 ig4iic_softc_t *sc = device_get_softc(dev);
815 lockmgr(&sc->lk, LK_EXCLUSIVE);
817 set_slave_addr(sc, slave, 0);
818 if ((error = smb_transaction(sc, cmd, SMB_TRANS_NOCNT,
819 NULL, 0, buf, 2, NULL)) == 0) {
820 *word = (u_char)buf[0] | ((u_char)buf[1] << 8);
823 lockmgr(&sc->lk, LK_RELEASE);
828 * write command and word and read word in transaction
831 ig4iic_smb_pcall(device_t dev, u_char slave, char cmd,
832 short sdata, short *rdata)
834 ig4iic_softc_t *sc = device_get_softc(dev);
839 lockmgr(&sc->lk, LK_EXCLUSIVE);
841 set_slave_addr(sc, slave, 0);
842 wbuf[0] = sdata & 0xFF;
843 wbuf[1] = sdata >> 8;
844 if ((error = smb_transaction(sc, cmd, SMB_TRANS_NOCNT,
845 wbuf, 2, rbuf, 2, NULL)) == 0) {
846 *rdata = (u_char)rbuf[0] | ((u_char)rbuf[1] << 8);
849 lockmgr(&sc->lk, LK_RELEASE);
854 ig4iic_smb_bwrite(device_t dev, u_char slave, char cmd,
855 u_char wcount, char *buf)
857 ig4iic_softc_t *sc = device_get_softc(dev);
860 lockmgr(&sc->lk, LK_EXCLUSIVE);
862 set_slave_addr(sc, slave, 0);
863 error = smb_transaction(sc, cmd, 0,
864 buf, wcount, NULL, 0, NULL);
866 lockmgr(&sc->lk, LK_RELEASE);
871 ig4iic_smb_bread(device_t dev, u_char slave, char cmd,
872 u_char *countp_char, char *buf)
874 ig4iic_softc_t *sc = device_get_softc(dev);
875 int rcount = *countp_char;
878 lockmgr(&sc->lk, LK_EXCLUSIVE);
880 set_slave_addr(sc, slave, 0);
881 error = smb_transaction(sc, cmd, 0,
882 NULL, 0, buf, rcount, &rcount);
883 *countp_char = rcount;
885 lockmgr(&sc->lk, LK_RELEASE);
890 ig4iic_smb_trans(device_t dev, int slave, char cmd, int op,
891 char *wbuf, int wcount, char *rbuf, int rcount,
894 ig4iic_softc_t *sc = device_get_softc(dev);
897 lockmgr(&sc->lk, LK_EXCLUSIVE);
899 set_slave_addr(sc, slave, op);
900 error = smb_transaction(sc, cmd, op,
901 wbuf, wcount, rbuf, rcount, actualp);
903 lockmgr(&sc->lk, LK_RELEASE);
908 * Interrupt Operation
912 ig4iic_intr(void *cookie)
914 ig4iic_softc_t *sc = cookie;
917 lockmgr(&sc->lk, LK_EXCLUSIVE);
918 /* reg_write(sc, IG4_REG_INTR_MASK, IG4_INTR_STOP_DET);*/
919 reg_read(sc, IG4_REG_CLR_INTR);
920 status = reg_read(sc, IG4_REG_I2C_STA);
921 while (status & IG4_STATUS_RX_NOTEMPTY) {
922 sc->rbuf[sc->rnext & IG4_RBUFMASK] =
923 (uint8_t)reg_read(sc, IG4_REG_DATA_CMD);
925 status = reg_read(sc, IG4_REG_I2C_STA);
928 lockmgr(&sc->lk, LK_RELEASE);
931 #define REGDUMP(sc, reg) \
932 device_printf(sc->dev, " %-23s %08x\n", #reg, reg_read(sc, reg))
936 ig4iic_dump(ig4iic_softc_t *sc)
938 device_printf(sc->dev, "ig4iic register dump:\n");
939 REGDUMP(sc, IG4_REG_CTL);
940 REGDUMP(sc, IG4_REG_TAR_ADD);
941 REGDUMP(sc, IG4_REG_SS_SCL_HCNT);
942 REGDUMP(sc, IG4_REG_SS_SCL_LCNT);
943 REGDUMP(sc, IG4_REG_FS_SCL_HCNT);
944 REGDUMP(sc, IG4_REG_FS_SCL_LCNT);
945 REGDUMP(sc, IG4_REG_INTR_STAT);
946 REGDUMP(sc, IG4_REG_INTR_MASK);
947 REGDUMP(sc, IG4_REG_RAW_INTR_STAT);
948 REGDUMP(sc, IG4_REG_RX_TL);
949 REGDUMP(sc, IG4_REG_TX_TL);
950 REGDUMP(sc, IG4_REG_I2C_EN);
951 REGDUMP(sc, IG4_REG_I2C_STA);
952 REGDUMP(sc, IG4_REG_TXFLR);
953 REGDUMP(sc, IG4_REG_RXFLR);
954 REGDUMP(sc, IG4_REG_SDA_HOLD);
955 REGDUMP(sc, IG4_REG_TX_ABRT_SOURCE);
956 REGDUMP(sc, IG4_REG_SLV_DATA_NACK);
957 REGDUMP(sc, IG4_REG_DMA_CTRL);
958 REGDUMP(sc, IG4_REG_DMA_TDLR);
959 REGDUMP(sc, IG4_REG_DMA_RDLR);
960 REGDUMP(sc, IG4_REG_SDA_SETUP);
961 REGDUMP(sc, IG4_REG_ENABLE_STATUS);
962 REGDUMP(sc, IG4_REG_COMP_PARAM1);
963 REGDUMP(sc, IG4_REG_COMP_VER);
964 REGDUMP(sc, IG4_REG_COMP_TYPE);
965 REGDUMP(sc, IG4_REG_CLK_PARMS);
966 REGDUMP(sc, IG4_REG_RESETS);
967 REGDUMP(sc, IG4_REG_GENERAL);
968 REGDUMP(sc, IG4_REG_SW_LTR_VALUE);
969 REGDUMP(sc, IG4_REG_AUTO_LTR_VALUE);
973 DRIVER_MODULE(smbus, ig4iic, smbus_driver, smbus_devclass, NULL, NULL);