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_read_1(viapm->iores, port))
78 #define VIAPM_OUTB(port,val) \
79 (bus_write_1(viapm->iores, 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)
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;
289 case VIA_8237_PMU_ID:
290 desc = "VIA VT8237 Power Management Unit";
291 viapm->type = VIAPM_TYP_UNKNOWN;
292 base_cfgreg = VIAPM_8233_BASE;
295 case VIA_CX700_PMU_ID:
296 desc = "VIA CX700 Power Management Unit";
297 viapm->type = VIAPM_TYP_UNKNOWN;
298 base_cfgreg = VIAPM_8233_BASE;
303 #ifdef VIAPM_BASE_ADDR
304 /* force VIAPM I/O base address */
306 /* enable the SMBus controller function */
307 l = pci_read_config(dev, VIAPM_PRO_SMBCTRL, 1);
308 pci_write_config(dev, VIAPM_PRO_SMBCTRL, l | 1, 1);
310 /* write the base address */
311 pci_write_config(dev, base_cfgreg,
312 VIAPM_BASE_ADDR & VIAPM_PRO_BA_MASK, 4);
315 viapm->base = pci_read_config(dev, base_cfgreg, 4) & VIAPM_PRO_BA_MASK;
318 * We have to set the I/O resources by hand because it is
319 * described outside the viapmope of the traditional maps
321 viapm->iorid = base_cfgreg;
322 if (bus_set_resource(dev, SYS_RES_IOPORT, viapm->iorid,
324 device_printf(dev, "could not set bus resource 0x%x\n",
330 device_printf(dev, "SMBus I/O base at 0x%x\n", viapm->base);
333 device_set_desc(dev, desc);
334 return (BUS_PROBE_DEFAULT);
344 viapm_pro_attach(device_t dev)
346 struct viapm_softc *viapm = (struct viapm_softc *)device_get_softc(dev);
349 mtx_init(&viapm->lock, device_get_nameunit(dev), "viapm", MTX_DEF);
350 if (!(viapm->iores = bus_alloc_resource_any(dev, SYS_RES_IOPORT,
351 &viapm->iorid, RF_ACTIVE))) {
352 device_printf(dev, "could not allocate bus space\n");
358 l = pci_read_config(dev, VIAPM_PRO_SMBCTRL, 1);
359 pci_write_config(dev, VIAPM_PRO_SMBCTRL, l | 0x80, 1);
362 if (!(viapm->irqres = bus_alloc_resource(dev, SYS_RES_IRQ,
363 &viapm->irqrid, 9, 9, 1,
364 RF_SHAREABLE | RF_ACTIVE))) {
365 device_printf(dev, "could not allocate irq\n");
369 if (bus_setup_intr(dev, viapm->irqres, INTR_TYPE_MISC | INTR_MPSAFE,
370 (driver_intr_t *) viasmb_intr, viapm, &viapm->irqih)) {
371 device_printf(dev, "could not setup irq\n");
377 l = pci_read_config(dev, VIAPM_PRO_REVID, 1);
378 device_printf(dev, "SMBus revision code 0x%x\n", l);
381 viapm->smbus = device_add_child(dev, "smbus", -1);
383 /* probe and attach the smbus */
384 bus_generic_attach(dev);
386 /* disable slave function */
387 VIAPM_OUTB(SMBSCTRL, VIAPM_INB(SMBSCTRL) & ~SMBSCTRL_ENABLE);
389 /* enable the SMBus controller function */
390 l = pci_read_config(dev, VIAPM_PRO_SMBCTRL, 1);
391 pci_write_config(dev, VIAPM_PRO_SMBCTRL, l | 1, 1);
394 /* enable interrupts */
395 VIAPM_OUTB(SMBHCTRL, VIAPM_INB(SMBHCTRL) | SMBHCTRL_ENABLE);
399 /* If this device is a PCI-ISA bridge, then attach an ISA bus. */
400 if ((pci_get_class(dev) == PCIC_BRIDGE) &&
401 (pci_get_subclass(dev) == PCIS_BRIDGE_ISA))
408 bus_release_resource(dev, SYS_RES_IOPORT, viapm->iorid, viapm->iores);
411 bus_release_resource(dev, SYS_RES_IRQ, viapm->irqrid, viapm->irqres);
413 mtx_destroy(&viapm->lock);
419 viapm_586b_attach(device_t dev)
421 struct viapm_softc *viapm = (struct viapm_softc *)device_get_softc(dev);
423 mtx_init(&viapm->lock, device_get_nameunit(dev), "viapm", MTX_DEF);
424 if (!(viapm->iores = bus_alloc_resource_any(dev, SYS_RES_IOPORT,
425 &viapm->iorid, RF_ACTIVE | RF_SHAREABLE))) {
426 device_printf(dev, "could not allocate bus resource\n");
430 VIAPM_OUTB(GPIO_DIR, VIAPM_INB(GPIO_DIR) | VIAPM_SCL | VIAPM_SDA);
432 /* add generic bit-banging code */
433 if (!(viapm->iicbb = device_add_child(dev, "iicbb", -1)))
436 bus_generic_attach(dev);
442 bus_release_resource(dev, SYS_RES_IOPORT,
443 viapm->iorid, viapm->iores);
444 mtx_destroy(&viapm->lock);
449 viapm_586b_detach(device_t dev)
451 struct viapm_softc *viapm = (struct viapm_softc *)device_get_softc(dev);
453 bus_generic_detach(dev);
455 device_delete_child(dev, viapm->iicbb);
459 bus_release_resource(dev, SYS_RES_IOPORT, viapm->iorid,
461 mtx_destroy(&viapm->lock);
467 viapm_pro_detach(device_t dev)
469 struct viapm_softc *viapm = (struct viapm_softc *)device_get_softc(dev);
471 bus_generic_detach(dev);
473 device_delete_child(dev, viapm->smbus);
476 bus_release_resource(dev, SYS_RES_IOPORT, viapm->iorid, viapm->iores);
479 bus_release_resource(dev, SYS_RES_IRQ, viapm->irqrid, viapm->irqres);
481 mtx_destroy(&viapm->lock);
487 viabb_callback(device_t dev, int index, caddr_t data)
493 viabb_setscl(device_t dev, int ctrl)
495 struct viapm_softc *viapm = device_get_softc(dev);
499 val = VIAPM_INB(GPIO_VAL);
506 VIAPM_OUTB(GPIO_VAL, val);
513 viabb_setsda(device_t dev, int data)
515 struct viapm_softc *viapm = device_get_softc(dev);
519 val = VIAPM_INB(GPIO_VAL);
526 VIAPM_OUTB(GPIO_VAL, val);
533 viabb_reset(device_t dev, u_char speed, u_char addr, u_char *oldaddr)
536 viabb_setsda(dev, 1);
537 viabb_setscl(dev, 1);
539 return (IIC_ENOADDR);
543 viabb_getscl(device_t dev)
545 struct viapm_softc *viapm = device_get_softc(dev);
549 val = VIAPM_INB(EXTSMI_VAL);
551 return ((val & VIAPM_SCL) != 0);
555 viabb_getsda(device_t dev)
557 struct viapm_softc *viapm = device_get_softc(dev);
561 val = VIAPM_INB(EXTSMI_VAL);
563 return ((val & VIAPM_SDA) != 0);
567 viapm_abort(struct viapm_softc *viapm)
569 VIAPM_OUTB(SMBHCTRL, SMBHCTRL_KILL);
576 viapm_clear(struct viapm_softc *viapm)
578 VIAPM_OUTB(SMBHST, SMBHST_FAILED | SMBHST_COLLID |
579 SMBHST_ERROR | SMBHST_INTR);
586 viapm_busy(struct viapm_softc *viapm)
590 sts = VIAPM_INB(SMBHST);
592 VIAPM_DEBUG(printf("viapm: idle? STS=0x%x\n", sts));
594 return (sts & SMBHST_BUSY);
598 * Poll the SMBus controller
601 viapm_wait(struct viapm_softc *viapm)
607 VIAPM_LOCK_ASSERT(viapm);
609 /* wait for command to complete and SMBus controller is idle */
612 sts = VIAPM_INB(SMBHST);
614 /* check if the controller is processing a command */
615 if (!(sts & SMBHST_BUSY) && (sts & SMBHST_INTR))
619 VIAPM_DEBUG(printf("viapm: SMBHST=0x%x\n", sts));
624 error |= SMB_ETIMEOUT;
626 if (sts & SMBHST_FAILED)
629 if (sts & SMBHST_COLLID)
632 if (sts & SMBHST_ERROR)
633 error |= SMB_EBUSERR;
635 if (error != SMB_ENOERR)
644 viasmb_callback(device_t dev, int index, void *data)
649 case SMB_REQUEST_BUS:
650 case SMB_RELEASE_BUS:
651 /* ok, bus allocation accepted */
661 viasmb_quick(device_t dev, u_char slave, int how)
663 struct viapm_softc *viapm = (struct viapm_softc *)device_get_softc(dev);
668 if (viapm_busy(viapm)) {
675 VIAPM_DEBUG(printf("viapm: QWRITE to 0x%x", slave));
676 VIAPM_OUTB(SMBHADDR, slave & ~LSB);
679 VIAPM_DEBUG(printf("viapm: QREAD to 0x%x", slave));
680 VIAPM_OUTB(SMBHADDR, slave | LSB);
683 panic("%s: unknown QUICK command (%x)!", __func__, how);
686 VIAPM_OUTB(SMBHCTRL, SMBHCTRL_START | SMBHCTRL_QUICK);
688 error = viapm_wait(viapm);
695 viasmb_sendb(device_t dev, u_char slave, char byte)
697 struct viapm_softc *viapm = (struct viapm_softc *)device_get_softc(dev);
702 if (viapm_busy(viapm)) {
707 VIAPM_OUTB(SMBHADDR, slave & ~ LSB);
708 VIAPM_OUTB(SMBHCMD, byte);
710 VIAPM_OUTB(SMBHCTRL, SMBHCTRL_START | SMBHCTRL_SENDRECV);
712 error = viapm_wait(viapm);
714 VIAPM_DEBUG(printf("viapm: SENDB to 0x%x, byte=0x%x, error=0x%x\n", slave, byte, error));
721 viasmb_recvb(device_t dev, u_char slave, char *byte)
723 struct viapm_softc *viapm = (struct viapm_softc *)device_get_softc(dev);
728 if (viapm_busy(viapm)) {
733 VIAPM_OUTB(SMBHADDR, slave | LSB);
735 VIAPM_OUTB(SMBHCTRL, SMBHCTRL_START | SMBHCTRL_SENDRECV);
737 if ((error = viapm_wait(viapm)) == SMB_ENOERR)
738 *byte = VIAPM_INB(SMBHDATA0);
740 VIAPM_DEBUG(printf("viapm: RECVB from 0x%x, byte=0x%x, error=0x%x\n", slave, *byte, error));
747 viasmb_writeb(device_t dev, u_char slave, char cmd, char byte)
749 struct viapm_softc *viapm = (struct viapm_softc *)device_get_softc(dev);
754 if (viapm_busy(viapm)) {
759 VIAPM_OUTB(SMBHADDR, slave & ~ LSB);
760 VIAPM_OUTB(SMBHCMD, cmd);
761 VIAPM_OUTB(SMBHDATA0, byte);
763 VIAPM_OUTB(SMBHCTRL, SMBHCTRL_START | SMBHCTRL_BYTE);
765 error = viapm_wait(viapm);
767 VIAPM_DEBUG(printf("viapm: WRITEB to 0x%x, cmd=0x%x, byte=0x%x, error=0x%x\n", slave, cmd, byte, error));
774 viasmb_readb(device_t dev, u_char slave, char cmd, char *byte)
776 struct viapm_softc *viapm = (struct viapm_softc *)device_get_softc(dev);
781 if (viapm_busy(viapm)) {
786 VIAPM_OUTB(SMBHADDR, slave | LSB);
787 VIAPM_OUTB(SMBHCMD, cmd);
789 VIAPM_OUTB(SMBHCTRL, SMBHCTRL_START | SMBHCTRL_BYTE);
791 if ((error = viapm_wait(viapm)) == SMB_ENOERR)
792 *byte = VIAPM_INB(SMBHDATA0);
794 VIAPM_DEBUG(printf("viapm: READB from 0x%x, cmd=0x%x, byte=0x%x, error=0x%x\n", slave, cmd, *byte, error));
801 viasmb_writew(device_t dev, u_char slave, char cmd, short word)
803 struct viapm_softc *viapm = (struct viapm_softc *)device_get_softc(dev);
808 if (viapm_busy(viapm)) {
813 VIAPM_OUTB(SMBHADDR, slave & ~ LSB);
814 VIAPM_OUTB(SMBHCMD, cmd);
815 VIAPM_OUTB(SMBHDATA0, word & 0x00ff);
816 VIAPM_OUTB(SMBHDATA1, (word & 0xff00) >> 8);
818 VIAPM_OUTB(SMBHCTRL, SMBHCTRL_START | SMBHCTRL_WORD);
820 error = viapm_wait(viapm);
822 VIAPM_DEBUG(printf("viapm: WRITEW to 0x%x, cmd=0x%x, word=0x%x, error=0x%x\n", slave, cmd, word, error));
829 viasmb_readw(device_t dev, u_char slave, char cmd, short *word)
831 struct viapm_softc *viapm = (struct viapm_softc *)device_get_softc(dev);
837 if (viapm_busy(viapm)) {
842 VIAPM_OUTB(SMBHADDR, slave | LSB);
843 VIAPM_OUTB(SMBHCMD, cmd);
845 VIAPM_OUTB(SMBHCTRL, SMBHCTRL_START | SMBHCTRL_WORD);
847 if ((error = viapm_wait(viapm)) == SMB_ENOERR) {
848 low = VIAPM_INB(SMBHDATA0);
849 high = VIAPM_INB(SMBHDATA1);
851 *word = ((high & 0xff) << 8) | (low & 0xff);
854 VIAPM_DEBUG(printf("viapm: READW from 0x%x, cmd=0x%x, word=0x%x, error=0x%x\n", slave, cmd, *word, error));
861 viasmb_bwrite(device_t dev, u_char slave, char cmd, u_char count, char *buf)
863 struct viapm_softc *viapm = (struct viapm_softc *)device_get_softc(dev);
867 if (count < 1 || count > 32)
872 if (viapm_busy(viapm)) {
877 VIAPM_OUTB(SMBHADDR, slave & ~LSB);
878 VIAPM_OUTB(SMBHCMD, cmd);
879 VIAPM_OUTB(SMBHDATA0, count);
880 i = VIAPM_INB(SMBHCTRL);
882 /* fill the 32-byte internal buffer */
883 for (i = 0; i < count; i++) {
884 VIAPM_OUTB(SMBHBLOCK, buf[i]);
887 VIAPM_OUTB(SMBHCMD, cmd);
888 VIAPM_OUTB(SMBHCTRL, SMBHCTRL_START | SMBHCTRL_BLOCK);
890 error = viapm_wait(viapm);
892 VIAPM_DEBUG(printf("viapm: WRITEBLK to 0x%x, count=0x%x, cmd=0x%x, error=0x%x", slave, count, cmd, error));
900 viasmb_bread(device_t dev, u_char slave, char cmd, u_char *count, char *buf)
902 struct viapm_softc *viapm = (struct viapm_softc *)device_get_softc(dev);
906 if (*count < 1 || *count > 32)
911 if (viapm_busy(viapm)) {
916 VIAPM_OUTB(SMBHADDR, slave | LSB);
917 VIAPM_OUTB(SMBHCMD, cmd);
918 VIAPM_OUTB(SMBHCTRL, SMBHCTRL_START | SMBHCTRL_BLOCK);
920 if ((error = viapm_wait(viapm)) != SMB_ENOERR)
923 len = VIAPM_INB(SMBHDATA0);
924 i = VIAPM_INB(SMBHCTRL); /* reset counter */
926 /* read the 32-byte internal buffer */
927 for (i = 0; i < len; i++) {
928 data = VIAPM_INB(SMBHBLOCK);
936 VIAPM_DEBUG(printf("viapm: READBLK to 0x%x, count=0x%x, cmd=0x%x, error=0x%x", slave, *count, cmd, error));
942 static device_method_t viapm_methods[] = {
943 /* device interface */
944 DEVMETHOD(device_probe, viapm_586b_probe),
945 DEVMETHOD(device_attach, viapm_586b_attach),
946 DEVMETHOD(device_detach, viapm_586b_detach),
948 /* iicbb interface */
949 DEVMETHOD(iicbb_callback, viabb_callback),
950 DEVMETHOD(iicbb_setscl, viabb_setscl),
951 DEVMETHOD(iicbb_setsda, viabb_setsda),
952 DEVMETHOD(iicbb_getscl, viabb_getscl),
953 DEVMETHOD(iicbb_getsda, viabb_getsda),
954 DEVMETHOD(iicbb_reset, viabb_reset),
957 DEVMETHOD(bus_alloc_resource, bus_generic_alloc_resource),
958 DEVMETHOD(bus_release_resource, bus_generic_release_resource),
959 DEVMETHOD(bus_activate_resource, bus_generic_activate_resource),
960 DEVMETHOD(bus_deactivate_resource, bus_generic_deactivate_resource),
961 DEVMETHOD(bus_setup_intr, bus_generic_setup_intr),
962 DEVMETHOD(bus_teardown_intr, bus_generic_teardown_intr),
967 static driver_t viapm_driver = {
970 sizeof(struct viapm_softc),
973 static device_method_t viapropm_methods[] = {
974 /* device interface */
975 DEVMETHOD(device_probe, viapm_pro_probe),
976 DEVMETHOD(device_attach, viapm_pro_attach),
977 DEVMETHOD(device_detach, viapm_pro_detach),
979 /* smbus interface */
980 DEVMETHOD(smbus_callback, viasmb_callback),
981 DEVMETHOD(smbus_quick, viasmb_quick),
982 DEVMETHOD(smbus_sendb, viasmb_sendb),
983 DEVMETHOD(smbus_recvb, viasmb_recvb),
984 DEVMETHOD(smbus_writeb, viasmb_writeb),
985 DEVMETHOD(smbus_readb, viasmb_readb),
986 DEVMETHOD(smbus_writew, viasmb_writew),
987 DEVMETHOD(smbus_readw, viasmb_readw),
988 DEVMETHOD(smbus_bwrite, viasmb_bwrite),
989 DEVMETHOD(smbus_bread, viasmb_bread),
992 DEVMETHOD(bus_alloc_resource, bus_generic_alloc_resource),
993 DEVMETHOD(bus_release_resource, bus_generic_release_resource),
994 DEVMETHOD(bus_activate_resource, bus_generic_activate_resource),
995 DEVMETHOD(bus_deactivate_resource, bus_generic_deactivate_resource),
996 DEVMETHOD(bus_setup_intr, bus_generic_setup_intr),
997 DEVMETHOD(bus_teardown_intr, bus_generic_teardown_intr),
1002 static driver_t viapropm_driver = {
1005 sizeof(struct viapm_softc),
1008 DRIVER_MODULE(viapm, pci, viapm_driver, viapm_devclass, 0, 0);
1009 DRIVER_MODULE(viapropm, pci, viapropm_driver, viapropm_devclass, 0, 0);
1010 DRIVER_MODULE(iicbb, viapm, iicbb_driver, iicbb_devclass, 0, 0);
1011 DRIVER_MODULE(smbus, viapropm, smbus_driver, smbus_devclass, 0, 0);
1013 MODULE_DEPEND(viapm, pci, 1, 1, 1);
1014 MODULE_DEPEND(viapropm, pci, 1, 1, 1);
1015 MODULE_DEPEND(viapm, iicbb, IICBB_MINVER, IICBB_PREFVER, IICBB_MAXVER);
1016 MODULE_DEPEND(viapropm, smbus, SMBUS_MINVER, SMBUS_PREFVER, SMBUS_MAXVER);
1017 MODULE_VERSION(viapm, 1);
1020 DRIVER_MODULE(isa, viapm, isa_driver, isa_devclass, 0, 0);
1021 DRIVER_MODULE(isa, viapropm, isa_driver, isa_devclass, 0, 0);
1022 MODULE_DEPEND(viapm, isa, 1, 1, 1);
1023 MODULE_DEPEND(viapropm, isa, 1, 1, 1);