2 * Copyright (c) 2001 Alcove - Nicolas Souchu
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 #include <sys/cdefs.h>
28 __FBSDID("$FreeBSD$");
32 #include <sys/param.h>
34 #include <sys/kernel.h>
36 #include <sys/module.h>
37 #include <sys/mutex.h>
38 #include <sys/systm.h>
40 #include <machine/bus.h>
41 #include <machine/resource.h>
45 #include <isa/isavar.h>
46 #include <isa/isa_common.h>
48 #include <dev/pci/pcivar.h>
49 #include <dev/pci/pcireg.h>
51 #include <dev/iicbus/iiconf.h>
53 #include <dev/smbus/smbconf.h>
58 #define VIAPM_DEBUG(x) if (viapm_debug) (x)
61 static int viapm_debug = 1;
63 static int viapm_debug = 0;
66 #define VIA_586B_PMU_ID 0x30401106
67 #define VIA_596A_PMU_ID 0x30501106
68 #define VIA_596B_PMU_ID 0x30511106
69 #define VIA_686A_PMU_ID 0x30571106
70 #define VIA_8233_PMU_ID 0x30741106
71 #define VIA_8233A_PMU_ID 0x31471106
72 #define VIA_8235_PMU_ID 0x31771106
73 #define VIA_8237_PMU_ID 0x32271106
74 #define VIA_CX700_PMU_ID 0x83241106
76 #define VIAPM_INB(port) \
77 ((u_char)bus_space_read_1(viapm->st, viapm->sh, port))
78 #define VIAPM_OUTB(port,val) \
79 (bus_space_write_1(viapm->st, viapm->sh, port, (u_char)(val)))
81 #define VIAPM_TYP_UNKNOWN 0
82 #define VIAPM_TYP_586B_3040E 1
83 #define VIAPM_TYP_586B_3040F 2
84 #define VIAPM_TYP_596B 3
85 #define VIAPM_TYP_686A 4
86 #define VIAPM_TYP_8233 5
88 #define VIAPM_LOCK(sc) mtx_lock(&(sc)->lock)
89 #define VIAPM_UNLOCK(sc) mtx_unlock(&(sc)->lock)
90 #define VIAPM_LOCK_ASSERT(sc) mtx_assert(&(sc)->lock, MA_OWNED)
96 bus_space_handle_t sh;
99 struct resource *iores;
100 struct resource *irqres;
107 static devclass_t viapm_devclass;
108 static devclass_t viapropm_devclass;
111 * VT82C586B definitions
114 #define VIAPM_586B_REVID 0x08
116 #define VIAPM_586B_3040E_BASE 0x20
117 #define VIAPM_586B_3040E_ACTIV 0x4 /* 16 bits */
119 #define VIAPM_586B_3040F_BASE 0x48
120 #define VIAPM_586B_3040F_ACTIV 0x41 /* 8 bits */
122 #define VIAPM_586B_OEM_REV_E 0x00
123 #define VIAPM_586B_OEM_REV_F 0x01
124 #define VIAPM_586B_PROD_REV_A 0x10
126 #define VIAPM_586B_BA_MASK 0x0000ff00
128 #define GPIO_DIR 0x40
129 #define GPIO_VAL 0x42
130 #define EXTSMI_VAL 0x44
132 #define VIAPM_SCL 0x02 /* GPIO1_VAL */
133 #define VIAPM_SDA 0x04 /* GPIO2_VAL */
136 * VIAPRO common definitions
139 #define VIAPM_PRO_BA_MASK 0x0000fff0
140 #define VIAPM_PRO_SMBCTRL 0xd2
141 #define VIAPM_PRO_REVID 0xd6
144 * VT82C686A definitions
147 #define VIAPM_PRO_BASE 0x90
154 #define SMBHDATA0 0x5
155 #define SMBHDATA1 0x6
156 #define SMBHBLOCK 0x7
160 #define SMBSSDWCMD 0x9
161 #define SMBSEVENT 0xa
164 #define SMBHST_RESERVED 0xef /* reserved bits */
165 #define SMBHST_FAILED 0x10 /* failed bus transaction */
166 #define SMBHST_COLLID 0x08 /* bus collision */
167 #define SMBHST_ERROR 0x04 /* device error */
168 #define SMBHST_INTR 0x02 /* command completed */
169 #define SMBHST_BUSY 0x01 /* host busy */
171 #define SMBHCTRL_START 0x40 /* start command */
172 #define SMBHCTRL_PROTO 0x1c /* command protocol mask */
173 #define SMBHCTRL_QUICK 0x00
174 #define SMBHCTRL_SENDRECV 0x04
175 #define SMBHCTRL_BYTE 0x08
176 #define SMBHCTRL_WORD 0x0c
177 #define SMBHCTRL_BLOCK 0x14
178 #define SMBHCTRL_KILL 0x02 /* stop the current transaction */
179 #define SMBHCTRL_ENABLE 0x01 /* enable interrupts */
181 #define SMBSCTRL_ENABLE 0x01 /* enable slave */
185 * VIA8233 definitions
188 #define VIAPM_8233_BASE 0xD0
191 viapm_586b_probe(device_t dev)
193 struct viapm_softc *viapm = (struct viapm_softc *)device_get_softc(dev);
198 switch (pci_get_devid(dev)) {
199 case VIA_586B_PMU_ID:
201 bzero(viapm, sizeof(struct viapm_softc));
203 l = pci_read_config(dev, VIAPM_586B_REVID, 1);
205 case VIAPM_586B_OEM_REV_E:
206 viapm->type = VIAPM_TYP_586B_3040E;
207 viapm->iorid = VIAPM_586B_3040E_BASE;
209 /* Activate IO block access */
210 s = pci_read_config(dev, VIAPM_586B_3040E_ACTIV, 2);
211 pci_write_config(dev, VIAPM_586B_3040E_ACTIV, s | 0x1, 2);
214 case VIAPM_586B_OEM_REV_F:
215 case VIAPM_586B_PROD_REV_A:
217 viapm->type = VIAPM_TYP_586B_3040F;
218 viapm->iorid = VIAPM_586B_3040F_BASE;
220 /* Activate IO block access */
221 c = pci_read_config(dev, VIAPM_586B_3040F_ACTIV, 1);
222 pci_write_config(dev, VIAPM_586B_3040F_ACTIV, c | 0x80, 1);
226 viapm->base = pci_read_config(dev, viapm->iorid, 4) &
230 * We have to set the I/O resources by hand because it is
231 * described outside the viapmope of the traditional maps
233 if (bus_set_resource(dev, SYS_RES_IOPORT, viapm->iorid,
235 device_printf(dev, "could not set bus resource\n");
238 device_set_desc(dev, "VIA VT82C586B Power Management Unit");
239 return (BUS_PROBE_DEFAULT);
250 viapm_pro_probe(device_t dev)
252 struct viapm_softc *viapm = (struct viapm_softc *)device_get_softc(dev);
253 #ifdef VIAPM_BASE_ADDR
256 u_int32_t base_cfgreg;
259 switch (pci_get_devid(dev)) {
260 case VIA_596A_PMU_ID:
261 desc = "VIA VT82C596A Power Management Unit";
262 viapm->type = VIAPM_TYP_596B;
263 base_cfgreg = VIAPM_PRO_BASE;
266 case VIA_596B_PMU_ID:
267 desc = "VIA VT82C596B Power Management Unit";
268 viapm->type = VIAPM_TYP_596B;
269 base_cfgreg = VIAPM_PRO_BASE;
272 case VIA_686A_PMU_ID:
273 desc = "VIA VT82C686A Power Management Unit";
274 viapm->type = VIAPM_TYP_686A;
275 base_cfgreg = VIAPM_PRO_BASE;
278 case VIA_8233_PMU_ID:
279 case VIA_8233A_PMU_ID:
280 desc = "VIA VT8233 Power Management Unit";
281 viapm->type = VIAPM_TYP_UNKNOWN;
282 base_cfgreg = VIAPM_8233_BASE;
285 case VIA_8235_PMU_ID:
286 desc = "VIA VT8235 Power Management Unit";
287 viapm->type = VIAPM_TYP_UNKNOWN;
288 base_cfgreg = VIAPM_8233_BASE;
291 case VIA_8237_PMU_ID:
292 desc = "VIA VT8237 Power Management Unit";
293 viapm->type = VIAPM_TYP_UNKNOWN;
294 base_cfgreg = VIAPM_8233_BASE;
297 case VIA_CX700_PMU_ID:
298 desc = "VIA CX700 Power Management Unit";
299 viapm->type = VIAPM_TYP_UNKNOWN;
300 base_cfgreg = VIAPM_8233_BASE;
305 #ifdef VIAPM_BASE_ADDR
306 /* force VIAPM I/O base address */
308 /* enable the SMBus controller function */
309 l = pci_read_config(dev, VIAPM_PRO_SMBCTRL, 1);
310 pci_write_config(dev, VIAPM_PRO_SMBCTRL, l | 1, 1);
312 /* write the base address */
313 pci_write_config(dev, base_cfgreg,
314 VIAPM_BASE_ADDR & VIAPM_PRO_BA_MASK, 4);
317 viapm->base = pci_read_config(dev, base_cfgreg, 4) & VIAPM_PRO_BA_MASK;
320 * We have to set the I/O resources by hand because it is
321 * described outside the viapmope of the traditional maps
323 viapm->iorid = base_cfgreg;
324 if (bus_set_resource(dev, SYS_RES_IOPORT, viapm->iorid,
326 device_printf(dev, "could not set bus resource 0x%x\n",
332 device_printf(dev, "SMBus I/O base at 0x%x\n", viapm->base);
335 device_set_desc(dev, desc);
336 return (BUS_PROBE_DEFAULT);
346 viapm_pro_attach(device_t dev)
348 struct viapm_softc *viapm = (struct viapm_softc *)device_get_softc(dev);
351 mtx_init(&viapm->lock, device_get_nameunit(dev), "viapm", MTX_DEF);
352 if (!(viapm->iores = bus_alloc_resource_any(dev, SYS_RES_IOPORT,
353 &viapm->iorid, RF_ACTIVE))) {
354 device_printf(dev, "could not allocate bus space\n");
357 viapm->st = rman_get_bustag(viapm->iores);
358 viapm->sh = rman_get_bushandle(viapm->iores);
362 l = pci_read_config(dev, VIAPM_PRO_SMBCTRL, 1);
363 pci_write_config(dev, VIAPM_PRO_SMBCTRL, l | 0x80, 1);
366 if (!(viapm->irqres = bus_alloc_resource(dev, SYS_RES_IRQ,
367 &viapm->irqrid, 9, 9, 1,
368 RF_SHAREABLE | RF_ACTIVE))) {
369 device_printf(dev, "could not allocate irq\n");
373 if (bus_setup_intr(dev, viapm->irqres, INTR_TYPE_MISC,
374 (driver_intr_t *) viasmb_intr, viapm, &viapm->irqih)) {
375 device_printf(dev, "could not setup irq\n");
381 l = pci_read_config(dev, VIAPM_PRO_REVID, 1);
382 device_printf(dev, "SMBus revision code 0x%x\n", l);
385 viapm->smbus = device_add_child(dev, "smbus", -1);
387 /* probe and attach the smbus */
388 bus_generic_attach(dev);
390 /* disable slave function */
391 VIAPM_OUTB(SMBSCTRL, VIAPM_INB(SMBSCTRL) & ~SMBSCTRL_ENABLE);
393 /* enable the SMBus controller function */
394 l = pci_read_config(dev, VIAPM_PRO_SMBCTRL, 1);
395 pci_write_config(dev, VIAPM_PRO_SMBCTRL, l | 1, 1);
398 /* enable interrupts */
399 VIAPM_OUTB(SMBHCTRL, VIAPM_INB(SMBHCTRL) | SMBHCTRL_ENABLE);
403 /* If this device is a PCI-ISA bridge, then attach an ISA bus. */
404 if ((pci_get_class(dev) == PCIC_BRIDGE) &&
405 (pci_get_subclass(dev) == PCIS_BRIDGE_ISA))
412 bus_release_resource(dev, SYS_RES_IOPORT, viapm->iorid, viapm->iores);
415 bus_release_resource(dev, SYS_RES_IRQ, viapm->irqrid, viapm->irqres);
417 mtx_destroy(&viapm->lock);
423 viapm_586b_attach(device_t dev)
425 struct viapm_softc *viapm = (struct viapm_softc *)device_get_softc(dev);
427 mtx_init(&viapm->lock, device_get_nameunit(dev), "viapm", MTX_DEF);
428 if (!(viapm->iores = bus_alloc_resource_any(dev, SYS_RES_IOPORT,
429 &viapm->iorid, RF_ACTIVE | RF_SHAREABLE))) {
430 device_printf(dev, "could not allocate bus resource\n");
433 viapm->st = rman_get_bustag(viapm->iores);
434 viapm->sh = rman_get_bushandle(viapm->iores);
436 VIAPM_OUTB(GPIO_DIR, VIAPM_INB(GPIO_DIR) | VIAPM_SCL | VIAPM_SDA);
438 /* add generic bit-banging code */
439 if (!(viapm->iicbb = device_add_child(dev, "iicbb", -1)))
442 bus_generic_attach(dev);
448 bus_release_resource(dev, SYS_RES_IOPORT,
449 viapm->iorid, viapm->iores);
450 mtx_destroy(&viapm->lock);
455 viapm_586b_detach(device_t dev)
457 struct viapm_softc *viapm = (struct viapm_softc *)device_get_softc(dev);
459 bus_generic_detach(dev);
461 device_delete_child(dev, viapm->iicbb);
465 bus_release_resource(dev, SYS_RES_IOPORT, viapm->iorid,
467 mtx_destroy(&viapm->lock);
473 viapm_pro_detach(device_t dev)
475 struct viapm_softc *viapm = (struct viapm_softc *)device_get_softc(dev);
477 bus_generic_detach(dev);
479 device_delete_child(dev, viapm->smbus);
482 bus_release_resource(dev, SYS_RES_IOPORT, viapm->iorid, viapm->iores);
485 bus_release_resource(dev, SYS_RES_IRQ, viapm->irqrid, viapm->irqres);
487 mtx_destroy(&viapm->lock);
493 viabb_callback(device_t dev, int index, caddr_t *data)
499 viabb_setscl(device_t dev, int ctrl)
501 struct viapm_softc *viapm = device_get_softc(dev);
505 val = VIAPM_INB(GPIO_VAL);
512 VIAPM_OUTB(GPIO_VAL, val);
519 viabb_setsda(device_t dev, int data)
521 struct viapm_softc *viapm = device_get_softc(dev);
525 val = VIAPM_INB(GPIO_VAL);
532 VIAPM_OUTB(GPIO_VAL, val);
539 viabb_reset(device_t dev, u_char speed, u_char addr, u_char *oldaddr)
542 viabb_setsda(dev, 1);
543 viabb_setscl(dev, 1);
545 return (IIC_ENOADDR);
549 viabb_getscl(device_t dev)
551 struct viapm_softc *viapm = device_get_softc(dev);
555 val = VIAPM_INB(EXTSMI_VAL);
557 return ((val & VIAPM_SCL) != 0);
561 viabb_getsda(device_t dev)
563 struct viapm_softc *viapm = device_get_softc(dev);
567 val = VIAPM_INB(EXTSMI_VAL);
569 return ((val & VIAPM_SDA) != 0);
573 viapm_abort(struct viapm_softc *viapm)
575 VIAPM_OUTB(SMBHCTRL, SMBHCTRL_KILL);
582 viapm_clear(struct viapm_softc *viapm)
584 VIAPM_OUTB(SMBHST, SMBHST_FAILED | SMBHST_COLLID |
585 SMBHST_ERROR | SMBHST_INTR);
592 viapm_busy(struct viapm_softc *viapm)
596 sts = VIAPM_INB(SMBHST);
598 VIAPM_DEBUG(printf("viapm: idle? STS=0x%x\n", sts));
600 return (sts & SMBHST_BUSY);
604 * Poll the SMBus controller
607 viapm_wait(struct viapm_softc *viapm)
613 VIAPM_LOCK_ASSERT(viapm);
615 /* wait for command to complete and SMBus controller is idle */
618 sts = VIAPM_INB(SMBHST);
620 /* check if the controller is processing a command */
621 if (!(sts & SMBHST_BUSY) && (sts & SMBHST_INTR))
625 VIAPM_DEBUG(printf("viapm: SMBHST=0x%x\n", sts));
630 error |= SMB_ETIMEOUT;
632 if (sts & SMBHST_FAILED)
635 if (sts & SMBHST_COLLID)
638 if (sts & SMBHST_ERROR)
639 error |= SMB_EBUSERR;
641 if (error != SMB_ENOERR)
650 viasmb_callback(device_t dev, int index, caddr_t *data)
655 case SMB_REQUEST_BUS:
656 case SMB_RELEASE_BUS:
657 /* ok, bus allocation accepted */
667 viasmb_quick(device_t dev, u_char slave, int how)
669 struct viapm_softc *viapm = (struct viapm_softc *)device_get_softc(dev);
674 if (viapm_busy(viapm)) {
681 VIAPM_DEBUG(printf("viapm: QWRITE to 0x%x", slave));
682 VIAPM_OUTB(SMBHADDR, slave & ~LSB);
685 VIAPM_DEBUG(printf("viapm: QREAD to 0x%x", slave));
686 VIAPM_OUTB(SMBHADDR, slave | LSB);
689 panic("%s: unknown QUICK command (%x)!", __func__, how);
692 VIAPM_OUTB(SMBHCTRL, SMBHCTRL_START | SMBHCTRL_QUICK);
694 error = viapm_wait(viapm);
701 viasmb_sendb(device_t dev, u_char slave, char byte)
703 struct viapm_softc *viapm = (struct viapm_softc *)device_get_softc(dev);
708 if (viapm_busy(viapm)) {
713 VIAPM_OUTB(SMBHADDR, slave & ~ LSB);
714 VIAPM_OUTB(SMBHCMD, byte);
716 VIAPM_OUTB(SMBHCTRL, SMBHCTRL_START | SMBHCTRL_SENDRECV);
718 error = viapm_wait(viapm);
720 VIAPM_DEBUG(printf("viapm: SENDB to 0x%x, byte=0x%x, error=0x%x\n", slave, byte, error));
727 viasmb_recvb(device_t dev, u_char slave, char *byte)
729 struct viapm_softc *viapm = (struct viapm_softc *)device_get_softc(dev);
734 if (viapm_busy(viapm)) {
739 VIAPM_OUTB(SMBHADDR, slave | LSB);
741 VIAPM_OUTB(SMBHCTRL, SMBHCTRL_START | SMBHCTRL_SENDRECV);
743 if ((error = viapm_wait(viapm)) == SMB_ENOERR)
744 *byte = VIAPM_INB(SMBHDATA0);
746 VIAPM_DEBUG(printf("viapm: RECVB from 0x%x, byte=0x%x, error=0x%x\n", slave, *byte, error));
753 viasmb_writeb(device_t dev, u_char slave, char cmd, char byte)
755 struct viapm_softc *viapm = (struct viapm_softc *)device_get_softc(dev);
760 if (viapm_busy(viapm)) {
765 VIAPM_OUTB(SMBHADDR, slave & ~ LSB);
766 VIAPM_OUTB(SMBHCMD, cmd);
767 VIAPM_OUTB(SMBHDATA0, byte);
769 VIAPM_OUTB(SMBHCTRL, SMBHCTRL_START | SMBHCTRL_BYTE);
771 error = viapm_wait(viapm);
773 VIAPM_DEBUG(printf("viapm: WRITEB to 0x%x, cmd=0x%x, byte=0x%x, error=0x%x\n", slave, cmd, byte, error));
780 viasmb_readb(device_t dev, u_char slave, char cmd, char *byte)
782 struct viapm_softc *viapm = (struct viapm_softc *)device_get_softc(dev);
787 if (viapm_busy(viapm)) {
792 VIAPM_OUTB(SMBHADDR, slave | LSB);
793 VIAPM_OUTB(SMBHCMD, cmd);
795 VIAPM_OUTB(SMBHCTRL, SMBHCTRL_START | SMBHCTRL_BYTE);
797 if ((error = viapm_wait(viapm)) == SMB_ENOERR)
798 *byte = VIAPM_INB(SMBHDATA0);
800 VIAPM_DEBUG(printf("viapm: READB from 0x%x, cmd=0x%x, byte=0x%x, error=0x%x\n", slave, cmd, *byte, error));
807 viasmb_writew(device_t dev, u_char slave, char cmd, short word)
809 struct viapm_softc *viapm = (struct viapm_softc *)device_get_softc(dev);
814 if (viapm_busy(viapm)) {
819 VIAPM_OUTB(SMBHADDR, slave & ~ LSB);
820 VIAPM_OUTB(SMBHCMD, cmd);
821 VIAPM_OUTB(SMBHDATA0, word & 0x00ff);
822 VIAPM_OUTB(SMBHDATA1, (word & 0xff00) >> 8);
824 VIAPM_OUTB(SMBHCTRL, SMBHCTRL_START | SMBHCTRL_WORD);
826 error = viapm_wait(viapm);
828 VIAPM_DEBUG(printf("viapm: WRITEW to 0x%x, cmd=0x%x, word=0x%x, error=0x%x\n", slave, cmd, word, error));
835 viasmb_readw(device_t dev, u_char slave, char cmd, short *word)
837 struct viapm_softc *viapm = (struct viapm_softc *)device_get_softc(dev);
843 if (viapm_busy(viapm)) {
848 VIAPM_OUTB(SMBHADDR, slave | LSB);
849 VIAPM_OUTB(SMBHCMD, cmd);
851 VIAPM_OUTB(SMBHCTRL, SMBHCTRL_START | SMBHCTRL_WORD);
853 if ((error = viapm_wait(viapm)) == SMB_ENOERR) {
854 low = VIAPM_INB(SMBHDATA0);
855 high = VIAPM_INB(SMBHDATA1);
857 *word = ((high & 0xff) << 8) | (low & 0xff);
860 VIAPM_DEBUG(printf("viapm: READW from 0x%x, cmd=0x%x, word=0x%x, error=0x%x\n", slave, cmd, *word, error));
867 viasmb_bwrite(device_t dev, u_char slave, char cmd, u_char count, char *buf)
869 struct viapm_softc *viapm = (struct viapm_softc *)device_get_softc(dev);
873 if (count < 1 || count > 32)
878 if (viapm_busy(viapm)) {
883 VIAPM_OUTB(SMBHADDR, slave & ~LSB);
884 VIAPM_OUTB(SMBHCMD, cmd);
885 VIAPM_OUTB(SMBHDATA0, count);
886 i = VIAPM_INB(SMBHCTRL);
888 /* fill the 32-byte internal buffer */
889 for (i = 0; i < count; i++) {
890 VIAPM_OUTB(SMBHBLOCK, buf[i]);
893 VIAPM_OUTB(SMBHCMD, cmd);
894 VIAPM_OUTB(SMBHCTRL, SMBHCTRL_START | SMBHCTRL_BLOCK);
896 error = viapm_wait(viapm);
898 VIAPM_DEBUG(printf("viapm: WRITEBLK to 0x%x, count=0x%x, cmd=0x%x, error=0x%x", slave, count, cmd, error));
906 viasmb_bread(device_t dev, u_char slave, char cmd, u_char *count, char *buf)
908 struct viapm_softc *viapm = (struct viapm_softc *)device_get_softc(dev);
912 if (*count < 1 || *count > 32)
917 if (viapm_busy(viapm)) {
922 VIAPM_OUTB(SMBHADDR, slave | LSB);
923 VIAPM_OUTB(SMBHCMD, cmd);
924 VIAPM_OUTB(SMBHCTRL, SMBHCTRL_START | SMBHCTRL_BLOCK);
926 if ((error = viapm_wait(viapm)) != SMB_ENOERR)
929 len = VIAPM_INB(SMBHDATA0);
930 i = VIAPM_INB(SMBHCTRL); /* reset counter */
932 /* read the 32-byte internal buffer */
933 for (i = 0; i < len; i++) {
934 data = VIAPM_INB(SMBHBLOCK);
942 VIAPM_DEBUG(printf("viapm: READBLK to 0x%x, count=0x%x, cmd=0x%x, error=0x%x", slave, *count, cmd, error));
948 static device_method_t viapm_methods[] = {
949 /* device interface */
950 DEVMETHOD(device_probe, viapm_586b_probe),
951 DEVMETHOD(device_attach, viapm_586b_attach),
952 DEVMETHOD(device_detach, viapm_586b_detach),
954 /* iicbb interface */
955 DEVMETHOD(iicbb_callback, viabb_callback),
956 DEVMETHOD(iicbb_setscl, viabb_setscl),
957 DEVMETHOD(iicbb_setsda, viabb_setsda),
958 DEVMETHOD(iicbb_getscl, viabb_getscl),
959 DEVMETHOD(iicbb_getsda, viabb_getsda),
960 DEVMETHOD(iicbb_reset, viabb_reset),
963 DEVMETHOD(bus_print_child, bus_generic_print_child),
964 DEVMETHOD(bus_alloc_resource, bus_generic_alloc_resource),
965 DEVMETHOD(bus_release_resource, bus_generic_release_resource),
966 DEVMETHOD(bus_activate_resource, bus_generic_activate_resource),
967 DEVMETHOD(bus_deactivate_resource, bus_generic_deactivate_resource),
968 DEVMETHOD(bus_setup_intr, bus_generic_setup_intr),
969 DEVMETHOD(bus_teardown_intr, bus_generic_teardown_intr),
974 static driver_t viapm_driver = {
977 sizeof(struct viapm_softc),
980 static device_method_t viapropm_methods[] = {
981 /* device interface */
982 DEVMETHOD(device_probe, viapm_pro_probe),
983 DEVMETHOD(device_attach, viapm_pro_attach),
984 DEVMETHOD(device_detach, viapm_pro_detach),
986 /* smbus interface */
987 DEVMETHOD(smbus_callback, viasmb_callback),
988 DEVMETHOD(smbus_quick, viasmb_quick),
989 DEVMETHOD(smbus_sendb, viasmb_sendb),
990 DEVMETHOD(smbus_recvb, viasmb_recvb),
991 DEVMETHOD(smbus_writeb, viasmb_writeb),
992 DEVMETHOD(smbus_readb, viasmb_readb),
993 DEVMETHOD(smbus_writew, viasmb_writew),
994 DEVMETHOD(smbus_readw, viasmb_readw),
995 DEVMETHOD(smbus_bwrite, viasmb_bwrite),
996 DEVMETHOD(smbus_bread, viasmb_bread),
999 DEVMETHOD(bus_print_child, bus_generic_print_child),
1000 DEVMETHOD(bus_alloc_resource, bus_generic_alloc_resource),
1001 DEVMETHOD(bus_release_resource, bus_generic_release_resource),
1002 DEVMETHOD(bus_activate_resource, bus_generic_activate_resource),
1003 DEVMETHOD(bus_deactivate_resource, bus_generic_deactivate_resource),
1004 DEVMETHOD(bus_setup_intr, bus_generic_setup_intr),
1005 DEVMETHOD(bus_teardown_intr, bus_generic_teardown_intr),
1010 static driver_t viapropm_driver = {
1013 sizeof(struct viapm_softc),
1016 DRIVER_MODULE(viapm, pci, viapm_driver, viapm_devclass, 0, 0);
1017 DRIVER_MODULE(viapropm, pci, viapropm_driver, viapropm_devclass, 0, 0);
1018 DRIVER_MODULE(smbus, viapropm, smbus_driver, smbus_devclass, 0, 0);
1020 MODULE_DEPEND(viapm, pci, 1, 1, 1);
1021 MODULE_DEPEND(viapropm, pci, 1, 1, 1);
1022 MODULE_DEPEND(viapm, iicbb, IICBB_MINVER, IICBB_PREFVER, IICBB_MAXVER);
1023 MODULE_DEPEND(viapropm, smbus, SMBUS_MINVER, SMBUS_PREFVER, SMBUS_MAXVER);
1024 MODULE_VERSION(viapm, 1);
1027 DRIVER_MODULE(isa, viapm, isa_driver, isa_devclass, 0, 0);
1028 DRIVER_MODULE(isa, viapropm, isa_driver, isa_devclass, 0, 0);
1029 MODULE_DEPEND(viapm, isa, 1, 1, 1);
1030 MODULE_DEPEND(viapropm, isa, 1, 1, 1);