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> and was subsequently ported
6 * to FreeBSD by Michael Gmelin <freebsd@grem.de>
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in
16 * the documentation and/or other materials provided with the
18 * 3. Neither the name of The DragonFly Project nor the names of its
19 * contributors may be used to endorse or promote products derived
20 * from this software without specific, prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26 * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27 * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
28 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
30 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
31 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
32 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 #include <sys/cdefs.h>
37 __FBSDID("$FreeBSD$");
40 * Intel fourth generation mobile cpus integrated I2C device, smbus driver.
42 * See ig4_reg.h for datasheet reference and notes.
43 * See ig4_var.h for locking semantics.
46 #include <sys/param.h>
47 #include <sys/systm.h>
48 #include <sys/kernel.h>
49 #include <sys/module.h>
50 #include <sys/errno.h>
52 #include <sys/mutex.h>
54 #include <sys/syslog.h>
56 #include <sys/sysctl.h>
58 #include <machine/bus.h>
61 #include <dev/pci/pcivar.h>
62 #include <dev/pci/pcireg.h>
63 #include <dev/smbus/smbconf.h>
65 #include <dev/ichiic/ig4_reg.h>
66 #include <dev/ichiic/ig4_var.h>
68 #define TRANS_NORMAL 1
72 static void ig4iic_start(void *xdev);
73 static void ig4iic_intr(void *cookie);
74 static void ig4iic_dump(ig4iic_softc_t *sc);
77 SYSCTL_INT(_debug, OID_AUTO, ig4_dump, CTLFLAG_RW,
78 &ig4_dump, 0, "Dump controller registers");
81 * Low-level inline support functions
84 reg_write(ig4iic_softc_t *sc, uint32_t reg, uint32_t value)
86 bus_write_4(sc->regs_res, reg, value);
87 bus_barrier(sc->regs_res, reg, 4, BUS_SPACE_BARRIER_WRITE);
90 static __inline uint32_t
91 reg_read(ig4iic_softc_t *sc, uint32_t reg)
95 bus_barrier(sc->regs_res, reg, 4, BUS_SPACE_BARRIER_READ);
96 value = bus_read_4(sc->regs_res, reg);
101 * Enable or disable the controller and wait for the controller to acknowledge
105 set_controller(ig4iic_softc_t *sc, uint32_t ctl)
111 reg_write(sc, IG4_REG_I2C_EN, ctl);
112 error = SMB_ETIMEOUT;
114 for (retry = 100; retry > 0; --retry) {
115 v = reg_read(sc, IG4_REG_ENABLE_STATUS);
116 if (((v ^ ctl) & IG4_I2C_ENABLE) == 0) {
120 mtx_sleep(sc, &sc->io_lock, 0, "i2cslv", 1);
126 * Wait up to 25ms for the requested status using a 25uS polling loop.
129 wait_status(ig4iic_softc_t *sc, uint32_t status)
135 u_int limit_us = 25000; /* 25ms */
137 error = SMB_ETIMEOUT;
141 * Check requested status
143 v = reg_read(sc, IG4_REG_I2C_STA);
150 * When waiting for receive data break-out if the interrupt
151 * loaded data into the FIFO.
153 if (status & IG4_STATUS_RX_NOTEMPTY) {
154 if (sc->rpos != sc->rnext) {
161 * When waiting for the transmit FIFO to become empty,
162 * reset the timeout if we see a change in the transmit
163 * FIFO level as progress is being made.
165 if (status & IG4_STATUS_TX_EMPTY) {
166 v = reg_read(sc, IG4_REG_TXFLR) & IG4_FIFOLVL_MASK;
174 * Stop if we've run out of time.
176 if (count_us >= limit_us)
180 * When waiting for receive data let the interrupt do its
181 * work, otherwise poll with the lock held.
183 if (status & IG4_STATUS_RX_NOTEMPTY) {
184 mtx_sleep(sc, &sc->io_lock, 0, "i2cwait",
185 (hz + 99) / 100); /* sleep up to 10ms */
197 * Read I2C data. The data might have already been read by
198 * the interrupt code, otherwise it is sitting in the data
202 data_read(ig4iic_softc_t *sc)
206 if (sc->rpos == sc->rnext) {
207 c = (uint8_t)reg_read(sc, IG4_REG_DATA_CMD);
209 c = sc->rbuf[sc->rpos & IG4_RBUFMASK];
216 * Set the slave address. The controller must be disabled when
217 * changing the address.
219 * This operation does not issue anything to the I2C bus but sets
220 * the target address for when the controller later issues a START.
223 set_slave_addr(ig4iic_softc_t *sc, uint8_t slave, int trans_op)
229 use_10bit = sc->use_10bit;
230 if (trans_op & SMB_TRANS_7BIT)
232 if (trans_op & SMB_TRANS_10BIT)
235 if (sc->slave_valid && sc->last_slave == slave &&
236 sc->use_10bit == use_10bit) {
239 sc->use_10bit = use_10bit;
242 * Wait for TXFIFO to drain before disabling the controller.
244 * If a write message has not been completed it's really a
245 * programming error, but for now in that case issue an extra
248 * If a read message has not been completed it's also a programming
249 * error, for now just ignore it.
251 wait_status(sc, IG4_STATUS_TX_NOTFULL);
252 if (sc->write_started) {
253 reg_write(sc, IG4_REG_DATA_CMD, IG4_DATA_STOP);
254 sc->write_started = 0;
256 if (sc->read_started)
257 sc->read_started = 0;
258 wait_status(sc, IG4_STATUS_TX_EMPTY);
260 set_controller(sc, 0);
261 ctl = reg_read(sc, IG4_REG_CTL);
262 ctl &= ~IG4_CTL_10BIT;
263 ctl |= IG4_CTL_RESTARTEN;
267 tar |= IG4_TAR_10BIT;
268 ctl |= IG4_CTL_10BIT;
270 reg_write(sc, IG4_REG_CTL, ctl);
271 reg_write(sc, IG4_REG_TAR_ADD, tar);
272 set_controller(sc, IG4_I2C_ENABLE);
274 sc->last_slave = slave;
278 * Issue START with byte command, possible count, and a variable length
279 * read or write buffer, then possible turn-around read. The read also
280 * has a possible count received.
284 * Quick: START+ADDR+RD/WR STOP
286 * Normal: START+ADDR+WR CMD DATA..DATA STOP
289 * RESTART+ADDR RDATA..RDATA STOP
290 * (can also be used for I2C transactions)
292 * Process Call: START+ADDR+WR CMD DATAL DATAH
293 * RESTART+ADDR+RD RDATAL RDATAH STOP
295 * Block: START+ADDR+RD CMD
296 * RESTART+ADDR+RD RCOUNT DATA... STOP
299 * RESTART+ADDR+WR WCOUNT DATA... STOP
301 * For I2C - basically, no *COUNT fields, possibly no *CMD field. If the
302 * sender needs to issue a 2-byte command it will incorporate it
303 * into the write buffer and also set NOCMD.
305 * Generally speaking, the START+ADDR / RESTART+ADDR is handled automatically
306 * by the controller at the beginning of a command sequence or on a data
307 * direction turn-around, and we only need to tell it when to issue the STOP.
310 smb_transaction(ig4iic_softc_t *sc, char cmd, int op,
311 char *wbuf, int wcount, char *rbuf, int rcount, int *actualp)
318 * Debugging - dump registers
321 unit = device_get_unit(sc->dev);
322 if (ig4_dump & (1 << unit)) {
323 ig4_dump &= ~(1 << unit);
329 * Issue START or RESTART with next data byte, clear any previous
330 * abort condition that may have been holding the txfifo in reset.
332 last = IG4_DATA_RESTART;
333 reg_read(sc, IG4_REG_CLR_TX_ABORT);
338 * Issue command if not told otherwise (smbus).
340 if ((op & SMB_TRANS_NOCMD) == 0) {
341 error = wait_status(sc, IG4_STATUS_TX_NOTFULL);
345 if (wcount == 0 && rcount == 0 && (op & SMB_TRANS_NOSTOP) == 0)
346 last |= IG4_DATA_STOP;
347 reg_write(sc, IG4_REG_DATA_CMD, last);
352 * Clean out any previously received data.
354 if (sc->rpos != sc->rnext &&
355 (op & SMB_TRANS_NOREPORT) == 0) {
356 device_printf(sc->dev,
357 "discarding %d bytes of spurious data\n",
358 sc->rnext - sc->rpos);
364 * If writing and not told otherwise, issue the write count (smbus).
366 if (wcount && (op & SMB_TRANS_NOCNT) == 0) {
367 error = wait_status(sc, IG4_STATUS_TX_NOTFULL);
371 reg_write(sc, IG4_REG_DATA_CMD, last);
379 error = wait_status(sc, IG4_STATUS_TX_NOTFULL);
382 last |= (u_char)*wbuf;
383 if (wcount == 1 && rcount == 0 && (op & SMB_TRANS_NOSTOP) == 0)
384 last |= IG4_DATA_STOP;
385 reg_write(sc, IG4_REG_DATA_CMD, last);
392 * Issue reads to xmit FIFO (strange, I know) to tell the controller
393 * to clock in data. At the moment just issue one read ahead to
394 * pipeline the incoming data.
396 * NOTE: In the case of NOCMD and wcount == 0 we still issue a
397 * RESTART here, even if the data direction has not changed
398 * from the previous CHAINing call. This we force the RESTART.
399 * (A new START is issued automatically by the controller in
400 * the other nominal cases such as a data direction change or
401 * a previous STOP was issued).
403 * If this will be the last byte read we must also issue the STOP
404 * at the end of the read.
407 last = IG4_DATA_RESTART | IG4_DATA_COMMAND_RD;
409 (op & (SMB_TRANS_NOSTOP | SMB_TRANS_NOCNT)) ==
411 last |= IG4_DATA_STOP;
413 reg_write(sc, IG4_REG_DATA_CMD, last);
414 last = IG4_DATA_COMMAND_RD;
418 * Bulk read (i2c) and count field handling (smbus)
422 * Maintain a pipeline by queueing the allowance for the next
423 * read before waiting for the current read.
426 if (op & SMB_TRANS_NOCNT)
427 last = (rcount == 2) ? IG4_DATA_STOP : 0;
430 reg_write(sc, IG4_REG_DATA_CMD, IG4_DATA_COMMAND_RD |
433 error = wait_status(sc, IG4_STATUS_RX_NOTEMPTY);
435 if ((op & SMB_TRANS_NOREPORT) == 0) {
436 device_printf(sc->dev,
437 "rx timeout addr 0x%02x\n",
442 last = data_read(sc);
444 if (op & SMB_TRANS_NOCNT) {
445 *rbuf = (u_char)last;
452 * Handle count field (smbus), which is not part of
453 * the rcount'ed buffer. The first read data in a
454 * bulk transfer is the count.
456 * XXX if rcount is loaded as 0 how do I generate a
457 * STOP now without issuing another RD or WR?
459 if (rcount > (u_char)last)
460 rcount = (u_char)last;
461 op |= SMB_TRANS_NOCNT;
466 /* XXX wait for xmit buffer to become empty */
467 last = reg_read(sc, IG4_REG_TX_ABRT_SOURCE);
473 * SMBUS API FUNCTIONS
475 * Called from ig4iic_pci_attach/detach()
478 ig4iic_attach(ig4iic_softc_t *sc)
483 v = reg_read(sc, IG4_REG_COMP_TYPE);
484 v = reg_read(sc, IG4_REG_COMP_PARAM1);
485 v = reg_read(sc, IG4_REG_GENERAL);
486 if ((v & IG4_GENERAL_SWMODE) == 0) {
487 v |= IG4_GENERAL_SWMODE;
488 reg_write(sc, IG4_REG_GENERAL, v);
489 v = reg_read(sc, IG4_REG_GENERAL);
492 v = reg_read(sc, IG4_REG_SW_LTR_VALUE);
493 v = reg_read(sc, IG4_REG_AUTO_LTR_VALUE);
495 v = reg_read(sc, IG4_REG_COMP_VER);
496 if (v != IG4_COMP_VER) {
500 v = reg_read(sc, IG4_REG_SS_SCL_HCNT);
501 v = reg_read(sc, IG4_REG_SS_SCL_LCNT);
502 v = reg_read(sc, IG4_REG_FS_SCL_HCNT);
503 v = reg_read(sc, IG4_REG_FS_SCL_LCNT);
504 v = reg_read(sc, IG4_REG_SDA_HOLD);
506 v = reg_read(sc, IG4_REG_SS_SCL_HCNT);
507 reg_write(sc, IG4_REG_FS_SCL_HCNT, v);
508 v = reg_read(sc, IG4_REG_SS_SCL_LCNT);
509 reg_write(sc, IG4_REG_FS_SCL_LCNT, v);
512 * Program based on a 25000 Hz clock. This is a bit of a
513 * hack (obviously). The defaults are 400 and 470 for standard
514 * and 60 and 130 for fast. The defaults for standard fail
515 * utterly (presumably cause an abort) because the clock time
516 * is ~18.8ms by default. This brings it down to ~4ms (for now).
518 reg_write(sc, IG4_REG_SS_SCL_HCNT, 100);
519 reg_write(sc, IG4_REG_SS_SCL_LCNT, 125);
520 reg_write(sc, IG4_REG_FS_SCL_HCNT, 100);
521 reg_write(sc, IG4_REG_FS_SCL_LCNT, 125);
524 * Use a threshold of 1 so we get interrupted on each character,
525 * allowing us to use mtx_sleep() in our poll code. Not perfect
526 * but this is better than using DELAY() for receiving data.
528 * See ig4_var.h for details on interrupt handler synchronization.
530 reg_write(sc, IG4_REG_RX_TL, 1);
532 reg_write(sc, IG4_REG_CTL,
534 IG4_CTL_SLAVE_DISABLE |
538 sc->smb = device_add_child(sc->dev, "smbus", -1);
539 if (sc->smb == NULL) {
540 device_printf(sc->dev, "smbus driver not found\n");
547 * Don't do this, it blows up the PCI config
549 reg_write(sc, IG4_REG_RESETS, IG4_RESETS_ASSERT);
550 reg_write(sc, IG4_REG_RESETS, IG4_RESETS_DEASSERT);
554 * Interrupt on STOP detect or receive character ready
556 reg_write(sc, IG4_REG_INTR_MASK, IG4_INTR_STOP_DET |
558 mtx_lock(&sc->io_lock);
559 if (set_controller(sc, 0))
560 device_printf(sc->dev, "controller error during attach-1\n");
561 if (set_controller(sc, IG4_I2C_ENABLE))
562 device_printf(sc->dev, "controller error during attach-2\n");
563 mtx_unlock(&sc->io_lock);
564 error = bus_setup_intr(sc->dev, sc->intr_res, INTR_TYPE_MISC | INTR_MPSAFE,
565 NULL, ig4iic_intr, sc, &sc->intr_handle);
567 device_printf(sc->dev,
568 "Unable to setup irq: error %d\n", error);
571 sc->enum_hook.ich_func = ig4iic_start;
572 sc->enum_hook.ich_arg = sc->dev;
574 /* We have to wait until interrupts are enabled. I2C read and write
575 * only works if the interrupts are available.
577 if (config_intrhook_establish(&sc->enum_hook) != 0)
587 ig4iic_start(void *xdev)
591 device_t dev = (device_t)xdev;
593 sc = device_get_softc(dev);
595 config_intrhook_disestablish(&sc->enum_hook);
597 /* Attach us to the smbus */
598 error = bus_generic_attach(sc->dev);
600 device_printf(sc->dev,
601 "failed to attach child: error %d\n", error);
608 ig4iic_detach(ig4iic_softc_t *sc)
612 if (device_is_attached(sc->dev)) {
613 error = bus_generic_detach(sc->dev);
618 device_delete_child(sc->dev, sc->smb);
620 bus_teardown_intr(sc->dev, sc->intr_res, sc->intr_handle);
622 sx_xlock(&sc->call_lock);
623 mtx_lock(&sc->io_lock);
626 sc->intr_handle = NULL;
627 reg_write(sc, IG4_REG_INTR_MASK, 0);
628 reg_read(sc, IG4_REG_CLR_INTR);
629 set_controller(sc, 0);
631 mtx_unlock(&sc->io_lock);
632 sx_xunlock(&sc->call_lock);
637 ig4iic_smb_callback(device_t dev, int index, void *data)
642 case SMB_REQUEST_BUS:
645 case SMB_RELEASE_BUS:
657 * Quick command. i.e. START + cmd + R/W + STOP and no data. It is
658 * unclear to me how I could implement this with the intel i2c controller
659 * because the controler sends STARTs and STOPs automatically with data.
662 ig4iic_smb_quick(device_t dev, u_char slave, int how)
665 return (SMB_ENOTSUPP);
669 * Incremental send byte without stop (?). It is unclear why the slave
670 * address is specified if this presumably is used in combination with
671 * ig4iic_smb_quick().
673 * (Also, how would this work anyway? Issue the last byte with writeb()?)
676 ig4iic_smb_sendb(device_t dev, u_char slave, char byte)
678 ig4iic_softc_t *sc = device_get_softc(dev);
682 sx_xlock(&sc->call_lock);
683 mtx_lock(&sc->io_lock);
685 set_slave_addr(sc, slave, 0);
687 if (wait_status(sc, IG4_STATUS_TX_NOTFULL) == 0) {
688 reg_write(sc, IG4_REG_DATA_CMD, cmd);
691 error = SMB_ETIMEOUT;
694 mtx_unlock(&sc->io_lock);
695 sx_xunlock(&sc->call_lock);
700 * Incremental receive byte without stop (?). It is unclear why the slave
701 * address is specified if this presumably is used in combination with
702 * ig4iic_smb_quick().
705 ig4iic_smb_recvb(device_t dev, u_char slave, char *byte)
707 ig4iic_softc_t *sc = device_get_softc(dev);
710 sx_xlock(&sc->call_lock);
711 mtx_lock(&sc->io_lock);
713 set_slave_addr(sc, slave, 0);
714 reg_write(sc, IG4_REG_DATA_CMD, IG4_DATA_COMMAND_RD);
715 if (wait_status(sc, IG4_STATUS_RX_NOTEMPTY) == 0) {
716 *byte = data_read(sc);
720 error = SMB_ETIMEOUT;
723 mtx_unlock(&sc->io_lock);
724 sx_xunlock(&sc->call_lock);
729 * Write command and single byte in transaction.
732 ig4iic_smb_writeb(device_t dev, u_char slave, char cmd, char byte)
734 ig4iic_softc_t *sc = device_get_softc(dev);
737 sx_xlock(&sc->call_lock);
738 mtx_lock(&sc->io_lock);
740 set_slave_addr(sc, slave, 0);
741 error = smb_transaction(sc, cmd, SMB_TRANS_NOCNT,
742 &byte, 1, NULL, 0, NULL);
744 mtx_unlock(&sc->io_lock);
745 sx_xunlock(&sc->call_lock);
750 * Write command and single word in transaction.
753 ig4iic_smb_writew(device_t dev, u_char slave, char cmd, short word)
755 ig4iic_softc_t *sc = device_get_softc(dev);
759 sx_xlock(&sc->call_lock);
760 mtx_lock(&sc->io_lock);
762 set_slave_addr(sc, slave, 0);
763 buf[0] = word & 0xFF;
765 error = smb_transaction(sc, cmd, SMB_TRANS_NOCNT,
766 buf, 2, NULL, 0, NULL);
768 mtx_unlock(&sc->io_lock);
769 sx_xunlock(&sc->call_lock);
774 * write command and read single byte in transaction.
777 ig4iic_smb_readb(device_t dev, u_char slave, char cmd, char *byte)
779 ig4iic_softc_t *sc = device_get_softc(dev);
782 sx_xlock(&sc->call_lock);
783 mtx_lock(&sc->io_lock);
785 set_slave_addr(sc, slave, 0);
786 error = smb_transaction(sc, cmd, SMB_TRANS_NOCNT,
787 NULL, 0, byte, 1, NULL);
789 mtx_unlock(&sc->io_lock);
790 sx_xunlock(&sc->call_lock);
795 * write command and read word in transaction.
798 ig4iic_smb_readw(device_t dev, u_char slave, char cmd, short *word)
800 ig4iic_softc_t *sc = device_get_softc(dev);
804 sx_xlock(&sc->call_lock);
805 mtx_lock(&sc->io_lock);
807 set_slave_addr(sc, slave, 0);
808 if ((error = smb_transaction(sc, cmd, SMB_TRANS_NOCNT,
809 NULL, 0, buf, 2, NULL)) == 0) {
810 *word = (u_char)buf[0] | ((u_char)buf[1] << 8);
813 mtx_unlock(&sc->io_lock);
814 sx_xunlock(&sc->call_lock);
819 * write command and word and read word in transaction
822 ig4iic_smb_pcall(device_t dev, u_char slave, char cmd,
823 short sdata, short *rdata)
825 ig4iic_softc_t *sc = device_get_softc(dev);
830 sx_xlock(&sc->call_lock);
831 mtx_lock(&sc->io_lock);
833 set_slave_addr(sc, slave, 0);
834 wbuf[0] = sdata & 0xFF;
835 wbuf[1] = sdata >> 8;
836 if ((error = smb_transaction(sc, cmd, SMB_TRANS_NOCNT,
837 wbuf, 2, rbuf, 2, NULL)) == 0) {
838 *rdata = (u_char)rbuf[0] | ((u_char)rbuf[1] << 8);
841 mtx_unlock(&sc->io_lock);
842 sx_xunlock(&sc->call_lock);
847 ig4iic_smb_bwrite(device_t dev, u_char slave, char cmd,
848 u_char wcount, char *buf)
850 ig4iic_softc_t *sc = device_get_softc(dev);
853 sx_xlock(&sc->call_lock);
854 mtx_lock(&sc->io_lock);
856 set_slave_addr(sc, slave, 0);
857 error = smb_transaction(sc, cmd, 0,
858 buf, wcount, NULL, 0, NULL);
860 mtx_unlock(&sc->io_lock);
861 sx_xunlock(&sc->call_lock);
866 ig4iic_smb_bread(device_t dev, u_char slave, char cmd,
867 u_char *countp_char, char *buf)
869 ig4iic_softc_t *sc = device_get_softc(dev);
870 int rcount = *countp_char;
873 sx_xlock(&sc->call_lock);
874 mtx_lock(&sc->io_lock);
876 set_slave_addr(sc, slave, 0);
877 error = smb_transaction(sc, cmd, 0,
878 NULL, 0, buf, rcount, &rcount);
879 *countp_char = rcount;
881 mtx_unlock(&sc->io_lock);
882 sx_xunlock(&sc->call_lock);
887 ig4iic_smb_trans(device_t dev, int slave, char cmd, int op,
888 char *wbuf, int wcount, char *rbuf, int rcount,
891 ig4iic_softc_t *sc = device_get_softc(dev);
894 sx_xlock(&sc->call_lock);
895 mtx_lock(&sc->io_lock);
897 set_slave_addr(sc, slave, op);
898 error = smb_transaction(sc, cmd, op,
899 wbuf, wcount, rbuf, rcount, actualp);
901 mtx_unlock(&sc->io_lock);
902 sx_xunlock(&sc->call_lock);
907 * Interrupt Operation, see ig4_var.h for locking semantics.
910 ig4iic_intr(void *cookie)
912 ig4iic_softc_t *sc = cookie;
915 mtx_lock(&sc->io_lock);
916 /* reg_write(sc, IG4_REG_INTR_MASK, IG4_INTR_STOP_DET);*/
917 status = reg_read(sc, IG4_REG_I2C_STA);
918 while (status & IG4_STATUS_RX_NOTEMPTY) {
919 sc->rbuf[sc->rnext & IG4_RBUFMASK] =
920 (uint8_t)reg_read(sc, IG4_REG_DATA_CMD);
922 status = reg_read(sc, IG4_REG_I2C_STA);
924 reg_read(sc, IG4_REG_CLR_INTR);
926 mtx_unlock(&sc->io_lock);
929 #define REGDUMP(sc, reg) \
930 device_printf(sc->dev, " %-23s %08x\n", #reg, reg_read(sc, reg))
933 ig4iic_dump(ig4iic_softc_t *sc)
935 device_printf(sc->dev, "ig4iic register dump:\n");
936 REGDUMP(sc, IG4_REG_CTL);
937 REGDUMP(sc, IG4_REG_TAR_ADD);
938 REGDUMP(sc, IG4_REG_SS_SCL_HCNT);
939 REGDUMP(sc, IG4_REG_SS_SCL_LCNT);
940 REGDUMP(sc, IG4_REG_FS_SCL_HCNT);
941 REGDUMP(sc, IG4_REG_FS_SCL_LCNT);
942 REGDUMP(sc, IG4_REG_INTR_STAT);
943 REGDUMP(sc, IG4_REG_INTR_MASK);
944 REGDUMP(sc, IG4_REG_RAW_INTR_STAT);
945 REGDUMP(sc, IG4_REG_RX_TL);
946 REGDUMP(sc, IG4_REG_TX_TL);
947 REGDUMP(sc, IG4_REG_I2C_EN);
948 REGDUMP(sc, IG4_REG_I2C_STA);
949 REGDUMP(sc, IG4_REG_TXFLR);
950 REGDUMP(sc, IG4_REG_RXFLR);
951 REGDUMP(sc, IG4_REG_SDA_HOLD);
952 REGDUMP(sc, IG4_REG_TX_ABRT_SOURCE);
953 REGDUMP(sc, IG4_REG_SLV_DATA_NACK);
954 REGDUMP(sc, IG4_REG_DMA_CTRL);
955 REGDUMP(sc, IG4_REG_DMA_TDLR);
956 REGDUMP(sc, IG4_REG_DMA_RDLR);
957 REGDUMP(sc, IG4_REG_SDA_SETUP);
958 REGDUMP(sc, IG4_REG_ENABLE_STATUS);
959 REGDUMP(sc, IG4_REG_COMP_PARAM1);
960 REGDUMP(sc, IG4_REG_COMP_VER);
961 REGDUMP(sc, IG4_REG_COMP_TYPE);
962 REGDUMP(sc, IG4_REG_CLK_PARMS);
963 REGDUMP(sc, IG4_REG_RESETS);
964 REGDUMP(sc, IG4_REG_GENERAL);
965 REGDUMP(sc, IG4_REG_SW_LTR_VALUE);
966 REGDUMP(sc, IG4_REG_AUTO_LTR_VALUE);
970 DRIVER_MODULE(smbus, ig4iic, smbus_driver, smbus_devclass, NULL, NULL);