Deleted Added
full compact
ichsmb.c (162234) ichsmb.c (165951)
1/*-
2 * ichsmb.c
3 *
4 * Author: Archie Cobbs <archie@freebsd.org>
5 * Copyright (c) 2000 Whistle Communications, Inc.
6 * All rights reserved.
7 *
8 * Subject to the following obligations and disclaimer of warranty, use and

--- 22 unchanged lines hidden (view full) ---

31 * SERVICES, LOSS OF USE, DATA OR PROFITS, HOWEVER CAUSED AND UNDER ANY
32 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
33 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
34 * THIS SOFTWARE, EVEN IF WHISTLE COMMUNICATIONS IS ADVISED OF THE POSSIBILITY
35 * OF SUCH DAMAGE.
36 */
37
38#include <sys/cdefs.h>
1/*-
2 * ichsmb.c
3 *
4 * Author: Archie Cobbs <archie@freebsd.org>
5 * Copyright (c) 2000 Whistle Communications, Inc.
6 * All rights reserved.
7 *
8 * Subject to the following obligations and disclaimer of warranty, use and

--- 22 unchanged lines hidden (view full) ---

31 * SERVICES, LOSS OF USE, DATA OR PROFITS, HOWEVER CAUSED AND UNDER ANY
32 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
33 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
34 * THIS SOFTWARE, EVEN IF WHISTLE COMMUNICATIONS IS ADVISED OF THE POSSIBILITY
35 * OF SUCH DAMAGE.
36 */
37
38#include <sys/cdefs.h>
39__FBSDID("$FreeBSD: head/sys/dev/ichsmb/ichsmb.c 162234 2006-09-11 20:52:41Z jhb $");
39__FBSDID("$FreeBSD: head/sys/dev/ichsmb/ichsmb.c 165951 2007-01-11 19:56:24Z jhb $");
40
41/*
42 * Support for the SMBus controller logical device which is part of the
43 * Intel 81801AA (ICH) and 81801AB (ICH0) I/O controller hub chips.
44 *
45 * This driver assumes that the generic SMBus code will ensure that
46 * at most one process at a time calls into the SMBus methods below.
47 */

--- 18 unchanged lines hidden (view full) ---

66#include <dev/ichsmb/ichsmb_reg.h>
67
68/*
69 * Enable debugging by defining ICHSMB_DEBUG to a non-zero value.
70 */
71#define ICHSMB_DEBUG 0
72#if ICHSMB_DEBUG != 0 && defined(__CC_SUPPORTS___FUNC__)
73#define DBG(fmt, args...) \
40
41/*
42 * Support for the SMBus controller logical device which is part of the
43 * Intel 81801AA (ICH) and 81801AB (ICH0) I/O controller hub chips.
44 *
45 * This driver assumes that the generic SMBus code will ensure that
46 * at most one process at a time calls into the SMBus methods below.
47 */

--- 18 unchanged lines hidden (view full) ---

66#include <dev/ichsmb/ichsmb_reg.h>
67
68/*
69 * Enable debugging by defining ICHSMB_DEBUG to a non-zero value.
70 */
71#define ICHSMB_DEBUG 0
72#if ICHSMB_DEBUG != 0 && defined(__CC_SUPPORTS___FUNC__)
73#define DBG(fmt, args...) \
74 do { log(LOG_DEBUG, "%s: " fmt, __func__ , ## args); } while (0)
74 do { printf("%s: " fmt, __func__ , ## args); } while (0)
75#else
76#define DBG(fmt, args...) do { } while (0)
77#endif
78
79/*
80 * Our child device driver name
81 */
82#define DRIVER_SMBUS "smbus"

--- 22 unchanged lines hidden (view full) ---

105 * our device lives on.
106 */
107int
108ichsmb_attach(device_t dev)
109{
110 const sc_p sc = device_get_softc(dev);
111 int error;
112
75#else
76#define DBG(fmt, args...) do { } while (0)
77#endif
78
79/*
80 * Our child device driver name
81 */
82#define DRIVER_SMBUS "smbus"

--- 22 unchanged lines hidden (view full) ---

105 * our device lives on.
106 */
107int
108ichsmb_attach(device_t dev)
109{
110 const sc_p sc = device_get_softc(dev);
111 int error;
112
113 /* Create mutex */
114 mtx_init(&sc->mutex, device_get_nameunit(dev), "ichsmb", MTX_DEF);
115
113 /* Add child: an instance of the "smbus" device */
114 if ((sc->smb = device_add_child(dev, DRIVER_SMBUS, -1)) == NULL) {
116 /* Add child: an instance of the "smbus" device */
117 if ((sc->smb = device_add_child(dev, DRIVER_SMBUS, -1)) == NULL) {
115 log(LOG_ERR, "%s: no \"%s\" child found\n",
116 device_get_nameunit(dev), DRIVER_SMBUS);
117 return (ENXIO);
118 device_printf(dev, "no \"%s\" child found\n", DRIVER_SMBUS);
119 error = ENXIO;
120 goto fail;
118 }
119
120 /* Clear interrupt conditions */
121 bus_space_write_1(sc->io_bst, sc->io_bsh, ICH_HST_STA, 0xff);
122
121 }
122
123 /* Clear interrupt conditions */
124 bus_space_write_1(sc->io_bst, sc->io_bsh, ICH_HST_STA, 0xff);
125
123 /* Add "smbus" child */
126 /* Set up interrupt handler */
127 error = bus_setup_intr(dev, sc->irq_res, INTR_TYPE_MISC,
128 ichsmb_device_intr, sc, &sc->irq_handle);
129 if (error != 0) {
130 device_printf(dev, "can't setup irq\n");
131 goto fail;
132 }
133
134 /* Attach "smbus" child */
124 if ((error = bus_generic_attach(dev)) != 0) {
135 if ((error = bus_generic_attach(dev)) != 0) {
125 log(LOG_ERR, "%s: failed to attach child: %d\n",
126 device_get_nameunit(dev), error);
127 return (ENXIO);
136 device_printf(dev, "failed to attach child: %d\n", error);
137 goto fail;
128 }
129
138 }
139
130 /* Create mutex */
131 mtx_init(&sc->mutex, device_get_nameunit(dev), "ichsmb", MTX_DEF);
132 return (0);
140 return (0);
141
142fail:
143 mtx_destroy(&sc->mutex);
144 return (error);
133}
134
135/********************************************************************
136 SMBUS METHODS
137********************************************************************/
138
139int
140ichsmb_callback(device_t dev, int index, void *data)

--- 372 unchanged lines hidden (view full) ---

513 cmd_index = sc->ich_cmd >> 2;
514 if (sc->ich_cmd != -1) {
515 KASSERT(cmd_index < sizeof(ichsmb_state_irqs),
516 ("%s: ich_cmd=%d", device_get_nameunit(dev),
517 sc->ich_cmd));
518 ok_bits |= ichsmb_state_irqs[cmd_index];
519 }
520 if ((status & ~ok_bits) != 0) {
145}
146
147/********************************************************************
148 SMBUS METHODS
149********************************************************************/
150
151int
152ichsmb_callback(device_t dev, int index, void *data)

--- 372 unchanged lines hidden (view full) ---

525 cmd_index = sc->ich_cmd >> 2;
526 if (sc->ich_cmd != -1) {
527 KASSERT(cmd_index < sizeof(ichsmb_state_irqs),
528 ("%s: ich_cmd=%d", device_get_nameunit(dev),
529 sc->ich_cmd));
530 ok_bits |= ichsmb_state_irqs[cmd_index];
531 }
532 if ((status & ~ok_bits) != 0) {
521 log(LOG_ERR, "%s: irq 0x%02x during %d\n",
522 device_get_nameunit(dev), status, cmd_index);
533 device_printf(dev, "irq 0x%02x during %d\n", status,
534 cmd_index);
523 bus_space_write_1(sc->io_bst, sc->io_bsh,
524 ICH_HST_STA, (status & ~ok_bits));
525 continue;
526 }
527
528 /* Handle SMBALERT interrupt */
529 if (status & ICH_HST_STA_SMBALERT_STS) {
530 static int smbalert_count = 16;
531 if (smbalert_count > 0) {
535 bus_space_write_1(sc->io_bst, sc->io_bsh,
536 ICH_HST_STA, (status & ~ok_bits));
537 continue;
538 }
539
540 /* Handle SMBALERT interrupt */
541 if (status & ICH_HST_STA_SMBALERT_STS) {
542 static int smbalert_count = 16;
543 if (smbalert_count > 0) {
532 log(LOG_WARNING, "%s: SMBALERT# rec'd\n",
533 device_get_nameunit(dev));
544 device_printf(dev, "SMBALERT# rec'd\n");
534 if (--smbalert_count == 0) {
545 if (--smbalert_count == 0) {
535 log(LOG_WARNING,
536 "%s: not logging anymore\n",
537 device_get_nameunit(dev));
546 device_printf(dev,
547 "not logging anymore\n");
538 }
539 }
540 }
541
542 /* Check for bus error */
543 if (status & ICH_HST_STA_BUS_ERR) {
544 sc->smb_error = SMB_ECOLLI; /* XXX SMB_EBUSERR? */
545 goto finished;

--- 58 unchanged lines hidden (view full) ---

604
605 /* Clear status bits and try again */
606 bus_space_write_1(sc->io_bst, sc->io_bsh, ICH_HST_STA, status);
607 }
608 mtx_unlock(&sc->mutex);
609
610 /* Too many loops? */
611 if (count == maxloops) {
548 }
549 }
550 }
551
552 /* Check for bus error */
553 if (status & ICH_HST_STA_BUS_ERR) {
554 sc->smb_error = SMB_ECOLLI; /* XXX SMB_EBUSERR? */
555 goto finished;

--- 58 unchanged lines hidden (view full) ---

614
615 /* Clear status bits and try again */
616 bus_space_write_1(sc->io_bst, sc->io_bsh, ICH_HST_STA, status);
617 }
618 mtx_unlock(&sc->mutex);
619
620 /* Too many loops? */
621 if (count == maxloops) {
612 log(LOG_ERR, "%s: interrupt loop, status=0x%02x\n",
613 device_get_nameunit(dev),
622 device_printf(dev, "interrupt loop, status=0x%02x\n",
614 bus_space_read_1(sc->io_bst, sc->io_bsh, ICH_HST_STA));
615 }
616}
617
618/*
619 * Wait for command completion. Assumes mutex is held.
620 * Returns an SMB_* error code.
621 */

--- 8 unchanged lines hidden (view full) ---

630 mtx_assert(&sc->mutex, MA_OWNED);
631 error = msleep(sc, &sc->mutex, PZERO, "ichsmb", hz / 4);
632 DBG("msleep -> %d\n", error);
633 switch (error) {
634 case 0:
635 smb_error = sc->smb_error;
636 break;
637 case EWOULDBLOCK:
623 bus_space_read_1(sc->io_bst, sc->io_bsh, ICH_HST_STA));
624 }
625}
626
627/*
628 * Wait for command completion. Assumes mutex is held.
629 * Returns an SMB_* error code.
630 */

--- 8 unchanged lines hidden (view full) ---

639 mtx_assert(&sc->mutex, MA_OWNED);
640 error = msleep(sc, &sc->mutex, PZERO, "ichsmb", hz / 4);
641 DBG("msleep -> %d\n", error);
642 switch (error) {
643 case 0:
644 smb_error = sc->smb_error;
645 break;
646 case EWOULDBLOCK:
638 log(LOG_ERR, "%s: device timeout, status=0x%02x\n",
639 device_get_nameunit(dev),
647 device_printf(dev, "device timeout, status=0x%02x\n",
640 bus_space_read_1(sc->io_bst, sc->io_bsh, ICH_HST_STA));
641 sc->ich_cmd = -1;
642 smb_error = SMB_ETIMEOUT;
643 break;
644 default:
645 smb_error = SMB_EABORT;
646 break;
647 }

--- 44 unchanged lines hidden ---
648 bus_space_read_1(sc->io_bst, sc->io_bsh, ICH_HST_STA));
649 sc->ich_cmd = -1;
650 smb_error = SMB_ETIMEOUT;
651 break;
652 default:
653 smb_error = SMB_EABORT;
654 break;
655 }

--- 44 unchanged lines hidden ---