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
74 #define VIAPM_INB(port) \
75 ((u_char)bus_space_read_1(viapm->st, viapm->sh, port))
76 #define VIAPM_OUTB(port,val) \
77 (bus_space_write_1(viapm->st, viapm->sh, port, (u_char)(val)))
79 #define VIAPM_TYP_UNKNOWN 0
80 #define VIAPM_TYP_586B_3040E 1
81 #define VIAPM_TYP_586B_3040F 2
82 #define VIAPM_TYP_596B 3
83 #define VIAPM_TYP_686A 4
84 #define VIAPM_TYP_8233 5
86 #define VIAPM_LOCK(sc) mtx_lock(&(sc)->lock)
87 #define VIAPM_UNLOCK(sc) mtx_unlock(&(sc)->lock)
88 #define VIAPM_LOCK_ASSERT(sc) mtx_assert(&(sc)->lock, MA_OWNED)
94 bus_space_handle_t sh;
97 struct resource *iores;
98 struct resource *irqres;
105 static devclass_t viapm_devclass;
106 static devclass_t viapropm_devclass;
109 * VT82C586B definitions
112 #define VIAPM_586B_REVID 0x08
114 #define VIAPM_586B_3040E_BASE 0x20
115 #define VIAPM_586B_3040E_ACTIV 0x4 /* 16 bits */
117 #define VIAPM_586B_3040F_BASE 0x48
118 #define VIAPM_586B_3040F_ACTIV 0x41 /* 8 bits */
120 #define VIAPM_586B_OEM_REV_E 0x00
121 #define VIAPM_586B_OEM_REV_F 0x01
122 #define VIAPM_586B_PROD_REV_A 0x10
124 #define VIAPM_586B_BA_MASK 0x0000ff00
126 #define GPIO_DIR 0x40
127 #define GPIO_VAL 0x42
128 #define EXTSMI_VAL 0x44
130 #define VIAPM_SCL 0x02 /* GPIO1_VAL */
131 #define VIAPM_SDA 0x04 /* GPIO2_VAL */
134 * VIAPRO common definitions
137 #define VIAPM_PRO_BA_MASK 0x0000fff0
138 #define VIAPM_PRO_SMBCTRL 0xd2
139 #define VIAPM_PRO_REVID 0xd6
142 * VT82C686A definitions
145 #define VIAPM_PRO_BASE 0x90
152 #define SMBHDATA0 0x5
153 #define SMBHDATA1 0x6
154 #define SMBHBLOCK 0x7
158 #define SMBSSDWCMD 0x9
159 #define SMBSEVENT 0xa
162 #define SMBHST_RESERVED 0xef /* reserved bits */
163 #define SMBHST_FAILED 0x10 /* failed bus transaction */
164 #define SMBHST_COLLID 0x08 /* bus collision */
165 #define SMBHST_ERROR 0x04 /* device error */
166 #define SMBHST_INTR 0x02 /* command completed */
167 #define SMBHST_BUSY 0x01 /* host busy */
169 #define SMBHCTRL_START 0x40 /* start command */
170 #define SMBHCTRL_PROTO 0x1c /* command protocol mask */
171 #define SMBHCTRL_QUICK 0x00
172 #define SMBHCTRL_SENDRECV 0x04
173 #define SMBHCTRL_BYTE 0x08
174 #define SMBHCTRL_WORD 0x0c
175 #define SMBHCTRL_BLOCK 0x14
176 #define SMBHCTRL_KILL 0x02 /* stop the current transaction */
177 #define SMBHCTRL_ENABLE 0x01 /* enable interrupts */
179 #define SMBSCTRL_ENABLE 0x01 /* enable slave */
183 * VIA8233 definitions
186 #define VIAPM_8233_BASE 0xD0
189 viapm_586b_probe(device_t dev)
191 struct viapm_softc *viapm = (struct viapm_softc *)device_get_softc(dev);
196 switch (pci_get_devid(dev)) {
197 case VIA_586B_PMU_ID:
199 bzero(viapm, sizeof(struct viapm_softc));
201 l = pci_read_config(dev, VIAPM_586B_REVID, 1);
203 case VIAPM_586B_OEM_REV_E:
204 viapm->type = VIAPM_TYP_586B_3040E;
205 viapm->iorid = VIAPM_586B_3040E_BASE;
207 /* Activate IO block access */
208 s = pci_read_config(dev, VIAPM_586B_3040E_ACTIV, 2);
209 pci_write_config(dev, VIAPM_586B_3040E_ACTIV, s | 0x1, 2);
212 case VIAPM_586B_OEM_REV_F:
213 case VIAPM_586B_PROD_REV_A:
215 viapm->type = VIAPM_TYP_586B_3040F;
216 viapm->iorid = VIAPM_586B_3040F_BASE;
218 /* Activate IO block access */
219 c = pci_read_config(dev, VIAPM_586B_3040F_ACTIV, 1);
220 pci_write_config(dev, VIAPM_586B_3040F_ACTIV, c | 0x80, 1);
224 viapm->base = pci_read_config(dev, viapm->iorid, 4) &
228 * We have to set the I/O resources by hand because it is
229 * described outside the viapmope of the traditional maps
231 if (bus_set_resource(dev, SYS_RES_IOPORT, viapm->iorid,
233 device_printf(dev, "could not set bus resource\n");
236 device_set_desc(dev, "VIA VT82C586B Power Management Unit");
237 return (BUS_PROBE_DEFAULT);
248 viapm_pro_probe(device_t dev)
250 struct viapm_softc *viapm = (struct viapm_softc *)device_get_softc(dev);
251 #ifdef VIAPM_BASE_ADDR
254 u_int32_t base_cfgreg;
257 switch (pci_get_devid(dev)) {
258 case VIA_596A_PMU_ID:
259 desc = "VIA VT82C596A Power Management Unit";
260 viapm->type = VIAPM_TYP_596B;
261 base_cfgreg = VIAPM_PRO_BASE;
264 case VIA_596B_PMU_ID:
265 desc = "VIA VT82C596B Power Management Unit";
266 viapm->type = VIAPM_TYP_596B;
267 base_cfgreg = VIAPM_PRO_BASE;
270 case VIA_686A_PMU_ID:
271 desc = "VIA VT82C686A Power Management Unit";
272 viapm->type = VIAPM_TYP_686A;
273 base_cfgreg = VIAPM_PRO_BASE;
276 case VIA_8233_PMU_ID:
277 case VIA_8233A_PMU_ID:
278 desc = "VIA VT8233 Power Management Unit";
279 viapm->type = VIAPM_TYP_UNKNOWN;
280 base_cfgreg = VIAPM_8233_BASE;
283 case VIA_8235_PMU_ID:
284 desc = "VIA VT8235 Power Management Unit";
285 viapm->type = VIAPM_TYP_UNKNOWN;
286 base_cfgreg = VIAPM_8233_BASE;
291 #ifdef VIAPM_BASE_ADDR
292 /* force VIAPM I/O base address */
294 /* enable the SMBus controller function */
295 l = pci_read_config(dev, VIAPM_PRO_SMBCTRL, 1);
296 pci_write_config(dev, VIAPM_PRO_SMBCTRL, l | 1, 1);
298 /* write the base address */
299 pci_write_config(dev, base_cfgreg,
300 VIAPM_BASE_ADDR & VIAPM_PRO_BA_MASK, 4);
303 viapm->base = pci_read_config(dev, base_cfgreg, 4) & VIAPM_PRO_BA_MASK;
306 * We have to set the I/O resources by hand because it is
307 * described outside the viapmope of the traditional maps
309 viapm->iorid = base_cfgreg;
310 if (bus_set_resource(dev, SYS_RES_IOPORT, viapm->iorid,
312 device_printf(dev, "could not set bus resource 0x%x\n",
317 if (1 || bootverbose) {
318 device_printf(dev, "SMBus I/O base at 0x%x\n", viapm->base);
321 device_set_desc(dev, desc);
322 return (BUS_PROBE_DEFAULT);
332 viapm_pro_attach(device_t dev)
334 struct viapm_softc *viapm = (struct viapm_softc *)device_get_softc(dev);
337 mtx_init(&viapm->lock, device_get_nameunit(dev), "viapm", MTX_DEF);
338 if (!(viapm->iores = bus_alloc_resource_any(dev, SYS_RES_IOPORT,
339 &viapm->iorid, RF_ACTIVE))) {
340 device_printf(dev, "could not allocate bus space\n");
343 viapm->st = rman_get_bustag(viapm->iores);
344 viapm->sh = rman_get_bushandle(viapm->iores);
348 l = pci_read_config(dev, VIAPM_PRO_SMBCTRL, 1);
349 pci_write_config(dev, VIAPM_PRO_SMBCTRL, l | 0x80, 1);
352 if (!(viapm->irqres = bus_alloc_resource(dev, SYS_RES_IRQ,
353 &viapm->irqrid, 9, 9, 1,
354 RF_SHAREABLE | RF_ACTIVE))) {
355 device_printf(dev, "could not allocate irq\n");
359 if (bus_setup_intr(dev, viapm->irqres, INTR_TYPE_MISC,
360 (driver_intr_t *) viasmb_intr, viapm, &viapm->irqih)) {
361 device_printf(dev, "could not setup irq\n");
366 if (1 | bootverbose) {
367 l = pci_read_config(dev, VIAPM_PRO_REVID, 1);
368 device_printf(dev, "SMBus revision code 0x%x\n", l);
371 viapm->smbus = device_add_child(dev, "smbus", -1);
373 /* probe and attach the smbus */
374 bus_generic_attach(dev);
376 /* disable slave function */
377 VIAPM_OUTB(SMBSCTRL, VIAPM_INB(SMBSCTRL) & ~SMBSCTRL_ENABLE);
379 /* enable the SMBus controller function */
380 l = pci_read_config(dev, VIAPM_PRO_SMBCTRL, 1);
381 pci_write_config(dev, VIAPM_PRO_SMBCTRL, l | 1, 1);
384 /* enable interrupts */
385 VIAPM_OUTB(SMBHCTRL, VIAPM_INB(SMBHCTRL) | SMBHCTRL_ENABLE);
389 /* If this device is a PCI-ISA bridge, then attach an ISA bus. */
390 if ((pci_get_class(dev) == PCIC_BRIDGE) &&
391 (pci_get_subclass(dev) == PCIS_BRIDGE_ISA))
398 bus_release_resource(dev, SYS_RES_IOPORT, viapm->iorid, viapm->iores);
401 bus_release_resource(dev, SYS_RES_IRQ, viapm->irqrid, viapm->irqres);
403 mtx_destroy(&viapm->lock);
409 viapm_586b_attach(device_t dev)
411 struct viapm_softc *viapm = (struct viapm_softc *)device_get_softc(dev);
413 mtx_init(&viapm->lock, device_get_nameunit(dev), "viapm", MTX_DEF);
414 if (!(viapm->iores = bus_alloc_resource_any(dev, SYS_RES_IOPORT,
415 &viapm->iorid, RF_ACTIVE | RF_SHAREABLE))) {
416 device_printf(dev, "could not allocate bus resource\n");
419 viapm->st = rman_get_bustag(viapm->iores);
420 viapm->sh = rman_get_bushandle(viapm->iores);
422 VIAPM_OUTB(GPIO_DIR, VIAPM_INB(GPIO_DIR) | VIAPM_SCL | VIAPM_SDA);
424 /* add generic bit-banging code */
425 if (!(viapm->iicbb = device_add_child(dev, "iicbb", -1)))
428 bus_generic_attach(dev);
434 bus_release_resource(dev, SYS_RES_IOPORT,
435 viapm->iorid, viapm->iores);
436 mtx_destroy(&viapm->lock);
441 viapm_586b_detach(device_t dev)
443 struct viapm_softc *viapm = (struct viapm_softc *)device_get_softc(dev);
445 bus_generic_detach(dev);
447 device_delete_child(dev, viapm->iicbb);
451 bus_release_resource(dev, SYS_RES_IOPORT, viapm->iorid,
453 mtx_destroy(&viapm->lock);
459 viapm_pro_detach(device_t dev)
461 struct viapm_softc *viapm = (struct viapm_softc *)device_get_softc(dev);
463 bus_generic_detach(dev);
465 device_delete_child(dev, viapm->smbus);
468 bus_release_resource(dev, SYS_RES_IOPORT, viapm->iorid, viapm->iores);
471 bus_release_resource(dev, SYS_RES_IRQ, viapm->irqrid, viapm->irqres);
473 mtx_destroy(&viapm->lock);
479 viabb_callback(device_t dev, int index, caddr_t *data)
485 viabb_setscl(device_t dev, int ctrl)
487 struct viapm_softc *viapm = device_get_softc(dev);
491 val = VIAPM_INB(GPIO_VAL);
498 VIAPM_OUTB(GPIO_VAL, val);
505 viabb_setsda(device_t dev, int data)
507 struct viapm_softc *viapm = device_get_softc(dev);
511 val = VIAPM_INB(GPIO_VAL);
518 VIAPM_OUTB(GPIO_VAL, val);
525 viabb_reset(device_t dev, u_char speed, u_char addr, u_char *oldaddr)
528 viabb_setsda(dev, 1);
529 viabb_setscl(dev, 1);
531 return (IIC_ENOADDR);
535 viabb_getscl(device_t dev)
537 struct viapm_softc *viapm = device_get_softc(dev);
541 val = VIAPM_INB(EXTSMI_VAL);
543 return ((val & VIAPM_SCL) != 0);
547 viabb_getsda(device_t dev)
549 struct viapm_softc *viapm = device_get_softc(dev);
553 val = VIAPM_INB(EXTSMI_VAL);
555 return ((val & VIAPM_SDA) != 0);
559 viapm_abort(struct viapm_softc *viapm)
561 VIAPM_OUTB(SMBHCTRL, SMBHCTRL_KILL);
568 viapm_clear(struct viapm_softc *viapm)
570 VIAPM_OUTB(SMBHST, SMBHST_FAILED | SMBHST_COLLID |
571 SMBHST_ERROR | SMBHST_INTR);
578 viapm_busy(struct viapm_softc *viapm)
582 sts = VIAPM_INB(SMBHST);
584 VIAPM_DEBUG(printf("viapm: idle? STS=0x%x\n", sts));
586 return (sts & SMBHST_BUSY);
590 * Poll the SMBus controller
593 viapm_wait(struct viapm_softc *viapm)
599 VIAPM_LOCK_ASSERT(viapm);
601 /* wait for command to complete and SMBus controller is idle */
604 sts = VIAPM_INB(SMBHST);
606 /* check if the controller is processing a command */
607 if (!(sts & SMBHST_BUSY) && (sts & SMBHST_INTR))
611 VIAPM_DEBUG(printf("viapm: SMBHST=0x%x\n", sts));
616 error |= SMB_ETIMEOUT;
618 if (sts & SMBHST_FAILED)
621 if (sts & SMBHST_COLLID)
624 if (sts & SMBHST_ERROR)
625 error |= SMB_EBUSERR;
627 if (error != SMB_ENOERR)
636 viasmb_callback(device_t dev, int index, caddr_t *data)
641 case SMB_REQUEST_BUS:
642 case SMB_RELEASE_BUS:
643 /* ok, bus allocation accepted */
653 viasmb_quick(device_t dev, u_char slave, int how)
655 struct viapm_softc *viapm = (struct viapm_softc *)device_get_softc(dev);
660 if (viapm_busy(viapm)) {
667 VIAPM_DEBUG(printf("viapm: QWRITE to 0x%x", slave));
668 VIAPM_OUTB(SMBHADDR, slave & ~LSB);
671 VIAPM_DEBUG(printf("viapm: QREAD to 0x%x", slave));
672 VIAPM_OUTB(SMBHADDR, slave | LSB);
675 panic("%s: unknown QUICK command (%x)!", __func__, how);
678 VIAPM_OUTB(SMBHCTRL, SMBHCTRL_START | SMBHCTRL_QUICK);
680 error = viapm_wait(viapm);
687 viasmb_sendb(device_t dev, u_char slave, char byte)
689 struct viapm_softc *viapm = (struct viapm_softc *)device_get_softc(dev);
694 if (viapm_busy(viapm)) {
699 VIAPM_OUTB(SMBHADDR, slave & ~ LSB);
700 VIAPM_OUTB(SMBHCMD, byte);
702 VIAPM_OUTB(SMBHCTRL, SMBHCTRL_START | SMBHCTRL_SENDRECV);
704 error = viapm_wait(viapm);
706 VIAPM_DEBUG(printf("viapm: SENDB to 0x%x, byte=0x%x, error=0x%x\n", slave, byte, error));
713 viasmb_recvb(device_t dev, u_char slave, char *byte)
715 struct viapm_softc *viapm = (struct viapm_softc *)device_get_softc(dev);
720 if (viapm_busy(viapm)) {
725 VIAPM_OUTB(SMBHADDR, slave | LSB);
727 VIAPM_OUTB(SMBHCTRL, SMBHCTRL_START | SMBHCTRL_SENDRECV);
729 if ((error = viapm_wait(viapm)) == SMB_ENOERR)
730 *byte = VIAPM_INB(SMBHDATA0);
732 VIAPM_DEBUG(printf("viapm: RECVB from 0x%x, byte=0x%x, error=0x%x\n", slave, *byte, error));
739 viasmb_writeb(device_t dev, u_char slave, char cmd, char byte)
741 struct viapm_softc *viapm = (struct viapm_softc *)device_get_softc(dev);
746 if (viapm_busy(viapm)) {
751 VIAPM_OUTB(SMBHADDR, slave & ~ LSB);
752 VIAPM_OUTB(SMBHCMD, cmd);
753 VIAPM_OUTB(SMBHDATA0, byte);
755 VIAPM_OUTB(SMBHCTRL, SMBHCTRL_START | SMBHCTRL_BYTE);
757 error = viapm_wait(viapm);
759 VIAPM_DEBUG(printf("viapm: WRITEB to 0x%x, cmd=0x%x, byte=0x%x, error=0x%x\n", slave, cmd, byte, error));
766 viasmb_readb(device_t dev, u_char slave, char cmd, char *byte)
768 struct viapm_softc *viapm = (struct viapm_softc *)device_get_softc(dev);
773 if (viapm_busy(viapm)) {
778 VIAPM_OUTB(SMBHADDR, slave | LSB);
779 VIAPM_OUTB(SMBHCMD, cmd);
781 VIAPM_OUTB(SMBHCTRL, SMBHCTRL_START | SMBHCTRL_BYTE);
783 if ((error = viapm_wait(viapm)) == SMB_ENOERR)
784 *byte = VIAPM_INB(SMBHDATA0);
786 VIAPM_DEBUG(printf("viapm: READB from 0x%x, cmd=0x%x, byte=0x%x, error=0x%x\n", slave, cmd, *byte, error));
793 viasmb_writew(device_t dev, u_char slave, char cmd, short word)
795 struct viapm_softc *viapm = (struct viapm_softc *)device_get_softc(dev);
800 if (viapm_busy(viapm)) {
805 VIAPM_OUTB(SMBHADDR, slave & ~ LSB);
806 VIAPM_OUTB(SMBHCMD, cmd);
807 VIAPM_OUTB(SMBHDATA0, word & 0x00ff);
808 VIAPM_OUTB(SMBHDATA1, (word & 0xff00) >> 8);
810 VIAPM_OUTB(SMBHCTRL, SMBHCTRL_START | SMBHCTRL_WORD);
812 error = viapm_wait(viapm);
814 VIAPM_DEBUG(printf("viapm: WRITEW to 0x%x, cmd=0x%x, word=0x%x, error=0x%x\n", slave, cmd, word, error));
821 viasmb_readw(device_t dev, u_char slave, char cmd, short *word)
823 struct viapm_softc *viapm = (struct viapm_softc *)device_get_softc(dev);
829 if (viapm_busy(viapm)) {
834 VIAPM_OUTB(SMBHADDR, slave | LSB);
835 VIAPM_OUTB(SMBHCMD, cmd);
837 VIAPM_OUTB(SMBHCTRL, SMBHCTRL_START | SMBHCTRL_WORD);
839 if ((error = viapm_wait(viapm)) == SMB_ENOERR) {
840 low = VIAPM_INB(SMBHDATA0);
841 high = VIAPM_INB(SMBHDATA1);
843 *word = ((high & 0xff) << 8) | (low & 0xff);
846 VIAPM_DEBUG(printf("viapm: READW from 0x%x, cmd=0x%x, word=0x%x, error=0x%x\n", slave, cmd, *word, error));
853 viasmb_bwrite(device_t dev, u_char slave, char cmd, u_char count, char *buf)
855 struct viapm_softc *viapm = (struct viapm_softc *)device_get_softc(dev);
859 if (count < 1 || count > 32)
864 if (viapm_busy(viapm)) {
869 VIAPM_OUTB(SMBHADDR, slave & ~LSB);
870 VIAPM_OUTB(SMBHCMD, cmd);
871 VIAPM_OUTB(SMBHDATA0, count);
872 i = VIAPM_INB(SMBHCTRL);
874 /* fill the 32-byte internal buffer */
875 for (i = 0; i < count; i++) {
876 VIAPM_OUTB(SMBHBLOCK, buf[i]);
879 VIAPM_OUTB(SMBHCMD, cmd);
880 VIAPM_OUTB(SMBHCTRL, SMBHCTRL_START | SMBHCTRL_BLOCK);
882 error = viapm_wait(viapm);
884 VIAPM_DEBUG(printf("viapm: WRITEBLK to 0x%x, count=0x%x, cmd=0x%x, error=0x%x", slave, count, cmd, error));
892 viasmb_bread(device_t dev, u_char slave, char cmd, u_char *count, char *buf)
894 struct viapm_softc *viapm = (struct viapm_softc *)device_get_softc(dev);
898 if (*count < 1 || *count > 32)
903 if (viapm_busy(viapm)) {
908 VIAPM_OUTB(SMBHADDR, slave | LSB);
909 VIAPM_OUTB(SMBHCMD, cmd);
910 VIAPM_OUTB(SMBHCTRL, SMBHCTRL_START | SMBHCTRL_BLOCK);
912 if ((error = viapm_wait(viapm)) != SMB_ENOERR)
915 len = VIAPM_INB(SMBHDATA0);
916 i = VIAPM_INB(SMBHCTRL); /* reset counter */
918 /* read the 32-byte internal buffer */
919 for (i = 0; i < len; i++) {
920 data = VIAPM_INB(SMBHBLOCK);
928 VIAPM_DEBUG(printf("viapm: READBLK to 0x%x, count=0x%x, cmd=0x%x, error=0x%x", slave, *count, cmd, error));
934 static device_method_t viapm_methods[] = {
935 /* device interface */
936 DEVMETHOD(device_probe, viapm_586b_probe),
937 DEVMETHOD(device_attach, viapm_586b_attach),
938 DEVMETHOD(device_detach, viapm_586b_detach),
940 /* iicbb interface */
941 DEVMETHOD(iicbb_callback, viabb_callback),
942 DEVMETHOD(iicbb_setscl, viabb_setscl),
943 DEVMETHOD(iicbb_setsda, viabb_setsda),
944 DEVMETHOD(iicbb_getscl, viabb_getscl),
945 DEVMETHOD(iicbb_getsda, viabb_getsda),
946 DEVMETHOD(iicbb_reset, viabb_reset),
949 DEVMETHOD(bus_print_child, bus_generic_print_child),
950 DEVMETHOD(bus_alloc_resource, bus_generic_alloc_resource),
951 DEVMETHOD(bus_release_resource, bus_generic_release_resource),
952 DEVMETHOD(bus_activate_resource, bus_generic_activate_resource),
953 DEVMETHOD(bus_deactivate_resource, bus_generic_deactivate_resource),
954 DEVMETHOD(bus_setup_intr, bus_generic_setup_intr),
955 DEVMETHOD(bus_teardown_intr, bus_generic_teardown_intr),
960 static driver_t viapm_driver = {
963 sizeof(struct viapm_softc),
966 static device_method_t viapropm_methods[] = {
967 /* device interface */
968 DEVMETHOD(device_probe, viapm_pro_probe),
969 DEVMETHOD(device_attach, viapm_pro_attach),
970 DEVMETHOD(device_detach, viapm_pro_detach),
972 /* smbus interface */
973 DEVMETHOD(smbus_callback, viasmb_callback),
974 DEVMETHOD(smbus_quick, viasmb_quick),
975 DEVMETHOD(smbus_sendb, viasmb_sendb),
976 DEVMETHOD(smbus_recvb, viasmb_recvb),
977 DEVMETHOD(smbus_writeb, viasmb_writeb),
978 DEVMETHOD(smbus_readb, viasmb_readb),
979 DEVMETHOD(smbus_writew, viasmb_writew),
980 DEVMETHOD(smbus_readw, viasmb_readw),
981 DEVMETHOD(smbus_bwrite, viasmb_bwrite),
982 DEVMETHOD(smbus_bread, viasmb_bread),
985 DEVMETHOD(bus_print_child, bus_generic_print_child),
986 DEVMETHOD(bus_alloc_resource, bus_generic_alloc_resource),
987 DEVMETHOD(bus_release_resource, bus_generic_release_resource),
988 DEVMETHOD(bus_activate_resource, bus_generic_activate_resource),
989 DEVMETHOD(bus_deactivate_resource, bus_generic_deactivate_resource),
990 DEVMETHOD(bus_setup_intr, bus_generic_setup_intr),
991 DEVMETHOD(bus_teardown_intr, bus_generic_teardown_intr),
996 static driver_t viapropm_driver = {
999 sizeof(struct viapm_softc),
1002 DRIVER_MODULE(viapm, pci, viapm_driver, viapm_devclass, 0, 0);
1003 DRIVER_MODULE(viapropm, pci, viapropm_driver, viapropm_devclass, 0, 0);
1004 DRIVER_MODULE(smbus, viapropm, smbus_driver, smbus_devclass, 0, 0);
1006 MODULE_DEPEND(viapm, pci, 1, 1, 1);
1007 MODULE_DEPEND(viapropm, pci, 1, 1, 1);
1008 MODULE_DEPEND(viapm, iicbb, IICBB_MINVER, IICBB_PREFVER, IICBB_MAXVER);
1009 MODULE_DEPEND(viapropm, smbus, SMBUS_MINVER, SMBUS_PREFVER, SMBUS_MAXVER);
1010 MODULE_VERSION(viapm, 1);
1013 DRIVER_MODULE(isa, viapm, isa_driver, isa_devclass, 0, 0);
1014 DRIVER_MODULE(isa, viapropm, isa_driver, isa_devclass, 0, 0);
1015 MODULE_DEPEND(viapm, isa, 1, 1, 1);
1016 MODULE_DEPEND(viapropm, isa, 1, 1, 1);