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 */
182 * VIA8233 definitions
185 #define VIAPM_8233_BASE 0xD0
188 viapm_586b_probe(device_t dev)
190 struct viapm_softc *viapm = (struct viapm_softc *)device_get_softc(dev);
195 switch (pci_get_devid(dev)) {
196 case VIA_586B_PMU_ID:
198 bzero(viapm, sizeof(struct viapm_softc));
200 l = pci_read_config(dev, VIAPM_586B_REVID, 1);
202 case VIAPM_586B_OEM_REV_E:
203 viapm->type = VIAPM_TYP_586B_3040E;
204 viapm->iorid = VIAPM_586B_3040E_BASE;
206 /* Activate IO block access */
207 s = pci_read_config(dev, VIAPM_586B_3040E_ACTIV, 2);
208 pci_write_config(dev, VIAPM_586B_3040E_ACTIV, s | 0x1, 2);
211 case VIAPM_586B_OEM_REV_F:
212 case VIAPM_586B_PROD_REV_A:
214 viapm->type = VIAPM_TYP_586B_3040F;
215 viapm->iorid = VIAPM_586B_3040F_BASE;
217 /* Activate IO block access */
218 c = pci_read_config(dev, VIAPM_586B_3040F_ACTIV, 1);
219 pci_write_config(dev, VIAPM_586B_3040F_ACTIV, c | 0x80, 1);
223 viapm->base = pci_read_config(dev, viapm->iorid, 4) &
227 * We have to set the I/O resources by hand because it is
228 * described outside the viapmope of the traditional maps
230 if (bus_set_resource(dev, SYS_RES_IOPORT, viapm->iorid,
232 device_printf(dev, "could not set bus resource\n");
235 device_set_desc(dev, "VIA VT82C586B Power Management Unit");
236 return (BUS_PROBE_DEFAULT);
246 viapm_pro_probe(device_t dev)
248 struct viapm_softc *viapm = (struct viapm_softc *)device_get_softc(dev);
249 #ifdef VIAPM_BASE_ADDR
252 u_int32_t base_cfgreg;
255 switch (pci_get_devid(dev)) {
256 case VIA_596A_PMU_ID:
257 desc = "VIA VT82C596A Power Management Unit";
258 viapm->type = VIAPM_TYP_596B;
259 base_cfgreg = VIAPM_PRO_BASE;
262 case VIA_596B_PMU_ID:
263 desc = "VIA VT82C596B Power Management Unit";
264 viapm->type = VIAPM_TYP_596B;
265 base_cfgreg = VIAPM_PRO_BASE;
268 case VIA_686A_PMU_ID:
269 desc = "VIA VT82C686A Power Management Unit";
270 viapm->type = VIAPM_TYP_686A;
271 base_cfgreg = VIAPM_PRO_BASE;
274 case VIA_8233_PMU_ID:
275 case VIA_8233A_PMU_ID:
276 desc = "VIA VT8233 Power Management Unit";
277 viapm->type = VIAPM_TYP_UNKNOWN;
278 base_cfgreg = VIAPM_8233_BASE;
281 case VIA_8235_PMU_ID:
282 desc = "VIA VT8235 Power Management Unit";
283 viapm->type = VIAPM_TYP_UNKNOWN;
284 base_cfgreg = VIAPM_8233_BASE;
287 case VIA_8237_PMU_ID:
288 desc = "VIA VT8237 Power Management Unit";
289 viapm->type = VIAPM_TYP_UNKNOWN;
290 base_cfgreg = VIAPM_8233_BASE;
293 case VIA_CX700_PMU_ID:
294 desc = "VIA CX700 Power Management Unit";
295 viapm->type = VIAPM_TYP_UNKNOWN;
296 base_cfgreg = VIAPM_8233_BASE;
301 #ifdef VIAPM_BASE_ADDR
302 /* force VIAPM I/O base address */
304 /* enable the SMBus controller function */
305 l = pci_read_config(dev, VIAPM_PRO_SMBCTRL, 1);
306 pci_write_config(dev, VIAPM_PRO_SMBCTRL, l | 1, 1);
308 /* write the base address */
309 pci_write_config(dev, base_cfgreg,
310 VIAPM_BASE_ADDR & VIAPM_PRO_BA_MASK, 4);
313 viapm->base = pci_read_config(dev, base_cfgreg, 4) & VIAPM_PRO_BA_MASK;
316 * We have to set the I/O resources by hand because it is
317 * described outside the viapmope of the traditional maps
319 viapm->iorid = base_cfgreg;
320 if (bus_set_resource(dev, SYS_RES_IOPORT, viapm->iorid,
322 device_printf(dev, "could not set bus resource 0x%x\n",
328 device_printf(dev, "SMBus I/O base at 0x%x\n", viapm->base);
331 device_set_desc(dev, desc);
332 return (BUS_PROBE_DEFAULT);
342 viapm_pro_attach(device_t dev)
344 struct viapm_softc *viapm = (struct viapm_softc *)device_get_softc(dev);
347 mtx_init(&viapm->lock, device_get_nameunit(dev), "viapm", MTX_DEF);
348 if (!(viapm->iores = bus_alloc_resource_any(dev, SYS_RES_IOPORT,
349 &viapm->iorid, RF_ACTIVE))) {
350 device_printf(dev, "could not allocate bus space\n");
356 l = pci_read_config(dev, VIAPM_PRO_SMBCTRL, 1);
357 pci_write_config(dev, VIAPM_PRO_SMBCTRL, l | 0x80, 1);
360 if (!(viapm->irqres = bus_alloc_resource(dev, SYS_RES_IRQ,
361 &viapm->irqrid, 9, 9, 1,
362 RF_SHAREABLE | RF_ACTIVE))) {
363 device_printf(dev, "could not allocate irq\n");
367 if (bus_setup_intr(dev, viapm->irqres, INTR_TYPE_MISC | INTR_MPSAFE,
368 (driver_intr_t *) viasmb_intr, viapm, &viapm->irqih)) {
369 device_printf(dev, "could not setup irq\n");
375 l = pci_read_config(dev, VIAPM_PRO_REVID, 1);
376 device_printf(dev, "SMBus revision code 0x%x\n", l);
379 viapm->smbus = device_add_child(dev, "smbus", -1);
381 /* probe and attach the smbus */
382 bus_generic_attach(dev);
384 /* disable slave function */
385 VIAPM_OUTB(SMBSCTRL, VIAPM_INB(SMBSCTRL) & ~SMBSCTRL_ENABLE);
387 /* enable the SMBus controller function */
388 l = pci_read_config(dev, VIAPM_PRO_SMBCTRL, 1);
389 pci_write_config(dev, VIAPM_PRO_SMBCTRL, l | 1, 1);
392 /* enable interrupts */
393 VIAPM_OUTB(SMBHCTRL, VIAPM_INB(SMBHCTRL) | SMBHCTRL_ENABLE);
397 /* If this device is a PCI-ISA bridge, then attach an ISA bus. */
398 if ((pci_get_class(dev) == PCIC_BRIDGE) &&
399 (pci_get_subclass(dev) == PCIS_BRIDGE_ISA))
406 bus_release_resource(dev, SYS_RES_IOPORT, viapm->iorid, viapm->iores);
409 bus_release_resource(dev, SYS_RES_IRQ, viapm->irqrid, viapm->irqres);
411 mtx_destroy(&viapm->lock);
417 viapm_586b_attach(device_t dev)
419 struct viapm_softc *viapm = (struct viapm_softc *)device_get_softc(dev);
421 mtx_init(&viapm->lock, device_get_nameunit(dev), "viapm", MTX_DEF);
422 if (!(viapm->iores = bus_alloc_resource_any(dev, SYS_RES_IOPORT,
423 &viapm->iorid, RF_ACTIVE | RF_SHAREABLE))) {
424 device_printf(dev, "could not allocate bus resource\n");
428 VIAPM_OUTB(GPIO_DIR, VIAPM_INB(GPIO_DIR) | VIAPM_SCL | VIAPM_SDA);
430 /* add generic bit-banging code */
431 if (!(viapm->iicbb = device_add_child(dev, "iicbb", -1)))
434 bus_generic_attach(dev);
440 bus_release_resource(dev, SYS_RES_IOPORT,
441 viapm->iorid, viapm->iores);
442 mtx_destroy(&viapm->lock);
447 viapm_586b_detach(device_t dev)
449 struct viapm_softc *viapm = (struct viapm_softc *)device_get_softc(dev);
451 bus_generic_detach(dev);
453 device_delete_child(dev, viapm->iicbb);
457 bus_release_resource(dev, SYS_RES_IOPORT, viapm->iorid,
459 mtx_destroy(&viapm->lock);
465 viapm_pro_detach(device_t dev)
467 struct viapm_softc *viapm = (struct viapm_softc *)device_get_softc(dev);
469 bus_generic_detach(dev);
471 device_delete_child(dev, viapm->smbus);
474 bus_release_resource(dev, SYS_RES_IOPORT, viapm->iorid, viapm->iores);
477 bus_release_resource(dev, SYS_RES_IRQ, viapm->irqrid, viapm->irqres);
479 mtx_destroy(&viapm->lock);
485 viabb_callback(device_t dev, int index, caddr_t data)
491 viabb_setscl(device_t dev, int ctrl)
493 struct viapm_softc *viapm = device_get_softc(dev);
497 val = VIAPM_INB(GPIO_VAL);
504 VIAPM_OUTB(GPIO_VAL, val);
511 viabb_setsda(device_t dev, int data)
513 struct viapm_softc *viapm = device_get_softc(dev);
517 val = VIAPM_INB(GPIO_VAL);
524 VIAPM_OUTB(GPIO_VAL, val);
531 viabb_reset(device_t dev, u_char speed, u_char addr, u_char *oldaddr)
534 viabb_setsda(dev, 1);
535 viabb_setscl(dev, 1);
537 return (IIC_ENOADDR);
541 viabb_getscl(device_t dev)
543 struct viapm_softc *viapm = device_get_softc(dev);
547 val = VIAPM_INB(EXTSMI_VAL);
549 return ((val & VIAPM_SCL) != 0);
553 viabb_getsda(device_t dev)
555 struct viapm_softc *viapm = device_get_softc(dev);
559 val = VIAPM_INB(EXTSMI_VAL);
561 return ((val & VIAPM_SDA) != 0);
565 viapm_abort(struct viapm_softc *viapm)
567 VIAPM_OUTB(SMBHCTRL, SMBHCTRL_KILL);
574 viapm_clear(struct viapm_softc *viapm)
576 VIAPM_OUTB(SMBHST, SMBHST_FAILED | SMBHST_COLLID |
577 SMBHST_ERROR | SMBHST_INTR);
584 viapm_busy(struct viapm_softc *viapm)
588 sts = VIAPM_INB(SMBHST);
590 VIAPM_DEBUG(printf("viapm: idle? STS=0x%x\n", sts));
592 return (sts & SMBHST_BUSY);
596 * Poll the SMBus controller
599 viapm_wait(struct viapm_softc *viapm)
605 VIAPM_LOCK_ASSERT(viapm);
607 /* wait for command to complete and SMBus controller is idle */
610 sts = VIAPM_INB(SMBHST);
612 /* check if the controller is processing a command */
613 if (!(sts & SMBHST_BUSY) && (sts & SMBHST_INTR))
617 VIAPM_DEBUG(printf("viapm: SMBHST=0x%x\n", sts));
622 error |= SMB_ETIMEOUT;
624 if (sts & SMBHST_FAILED)
627 if (sts & SMBHST_COLLID)
630 if (sts & SMBHST_ERROR)
631 error |= SMB_EBUSERR;
633 if (error != SMB_ENOERR)
642 viasmb_callback(device_t dev, int index, void *data)
647 case SMB_REQUEST_BUS:
648 case SMB_RELEASE_BUS:
649 /* ok, bus allocation accepted */
659 viasmb_quick(device_t dev, u_char slave, int how)
661 struct viapm_softc *viapm = (struct viapm_softc *)device_get_softc(dev);
666 if (viapm_busy(viapm)) {
673 VIAPM_DEBUG(printf("viapm: QWRITE to 0x%x", slave));
674 VIAPM_OUTB(SMBHADDR, slave & ~LSB);
677 VIAPM_DEBUG(printf("viapm: QREAD to 0x%x", slave));
678 VIAPM_OUTB(SMBHADDR, slave | LSB);
681 panic("%s: unknown QUICK command (%x)!", __func__, how);
684 VIAPM_OUTB(SMBHCTRL, SMBHCTRL_START | SMBHCTRL_QUICK);
686 error = viapm_wait(viapm);
693 viasmb_sendb(device_t dev, u_char slave, char byte)
695 struct viapm_softc *viapm = (struct viapm_softc *)device_get_softc(dev);
700 if (viapm_busy(viapm)) {
705 VIAPM_OUTB(SMBHADDR, slave & ~ LSB);
706 VIAPM_OUTB(SMBHCMD, byte);
708 VIAPM_OUTB(SMBHCTRL, SMBHCTRL_START | SMBHCTRL_SENDRECV);
710 error = viapm_wait(viapm);
712 VIAPM_DEBUG(printf("viapm: SENDB to 0x%x, byte=0x%x, error=0x%x\n", slave, byte, error));
719 viasmb_recvb(device_t dev, u_char slave, char *byte)
721 struct viapm_softc *viapm = (struct viapm_softc *)device_get_softc(dev);
726 if (viapm_busy(viapm)) {
731 VIAPM_OUTB(SMBHADDR, slave | LSB);
733 VIAPM_OUTB(SMBHCTRL, SMBHCTRL_START | SMBHCTRL_SENDRECV);
735 if ((error = viapm_wait(viapm)) == SMB_ENOERR)
736 *byte = VIAPM_INB(SMBHDATA0);
738 VIAPM_DEBUG(printf("viapm: RECVB from 0x%x, byte=0x%x, error=0x%x\n", slave, *byte, error));
745 viasmb_writeb(device_t dev, u_char slave, char cmd, char byte)
747 struct viapm_softc *viapm = (struct viapm_softc *)device_get_softc(dev);
752 if (viapm_busy(viapm)) {
757 VIAPM_OUTB(SMBHADDR, slave & ~ LSB);
758 VIAPM_OUTB(SMBHCMD, cmd);
759 VIAPM_OUTB(SMBHDATA0, byte);
761 VIAPM_OUTB(SMBHCTRL, SMBHCTRL_START | SMBHCTRL_BYTE);
763 error = viapm_wait(viapm);
765 VIAPM_DEBUG(printf("viapm: WRITEB to 0x%x, cmd=0x%x, byte=0x%x, error=0x%x\n", slave, cmd, byte, error));
772 viasmb_readb(device_t dev, u_char slave, char cmd, char *byte)
774 struct viapm_softc *viapm = (struct viapm_softc *)device_get_softc(dev);
779 if (viapm_busy(viapm)) {
784 VIAPM_OUTB(SMBHADDR, slave | LSB);
785 VIAPM_OUTB(SMBHCMD, cmd);
787 VIAPM_OUTB(SMBHCTRL, SMBHCTRL_START | SMBHCTRL_BYTE);
789 if ((error = viapm_wait(viapm)) == SMB_ENOERR)
790 *byte = VIAPM_INB(SMBHDATA0);
792 VIAPM_DEBUG(printf("viapm: READB from 0x%x, cmd=0x%x, byte=0x%x, error=0x%x\n", slave, cmd, *byte, error));
799 viasmb_writew(device_t dev, u_char slave, char cmd, short word)
801 struct viapm_softc *viapm = (struct viapm_softc *)device_get_softc(dev);
806 if (viapm_busy(viapm)) {
811 VIAPM_OUTB(SMBHADDR, slave & ~ LSB);
812 VIAPM_OUTB(SMBHCMD, cmd);
813 VIAPM_OUTB(SMBHDATA0, word & 0x00ff);
814 VIAPM_OUTB(SMBHDATA1, (word & 0xff00) >> 8);
816 VIAPM_OUTB(SMBHCTRL, SMBHCTRL_START | SMBHCTRL_WORD);
818 error = viapm_wait(viapm);
820 VIAPM_DEBUG(printf("viapm: WRITEW to 0x%x, cmd=0x%x, word=0x%x, error=0x%x\n", slave, cmd, word, error));
827 viasmb_readw(device_t dev, u_char slave, char cmd, short *word)
829 struct viapm_softc *viapm = (struct viapm_softc *)device_get_softc(dev);
835 if (viapm_busy(viapm)) {
840 VIAPM_OUTB(SMBHADDR, slave | LSB);
841 VIAPM_OUTB(SMBHCMD, cmd);
843 VIAPM_OUTB(SMBHCTRL, SMBHCTRL_START | SMBHCTRL_WORD);
845 if ((error = viapm_wait(viapm)) == SMB_ENOERR) {
846 low = VIAPM_INB(SMBHDATA0);
847 high = VIAPM_INB(SMBHDATA1);
849 *word = ((high & 0xff) << 8) | (low & 0xff);
852 VIAPM_DEBUG(printf("viapm: READW from 0x%x, cmd=0x%x, word=0x%x, error=0x%x\n", slave, cmd, *word, error));
859 viasmb_bwrite(device_t dev, u_char slave, char cmd, u_char count, char *buf)
861 struct viapm_softc *viapm = (struct viapm_softc *)device_get_softc(dev);
865 if (count < 1 || count > 32)
870 if (viapm_busy(viapm)) {
875 VIAPM_OUTB(SMBHADDR, slave & ~LSB);
876 VIAPM_OUTB(SMBHCMD, cmd);
877 VIAPM_OUTB(SMBHDATA0, count);
878 i = VIAPM_INB(SMBHCTRL);
880 /* fill the 32-byte internal buffer */
881 for (i = 0; i < count; i++) {
882 VIAPM_OUTB(SMBHBLOCK, buf[i]);
885 VIAPM_OUTB(SMBHCMD, cmd);
886 VIAPM_OUTB(SMBHCTRL, SMBHCTRL_START | SMBHCTRL_BLOCK);
888 error = viapm_wait(viapm);
890 VIAPM_DEBUG(printf("viapm: WRITEBLK to 0x%x, count=0x%x, cmd=0x%x, error=0x%x", slave, count, cmd, error));
898 viasmb_bread(device_t dev, u_char slave, char cmd, u_char *count, char *buf)
900 struct viapm_softc *viapm = (struct viapm_softc *)device_get_softc(dev);
904 if (*count < 1 || *count > 32)
909 if (viapm_busy(viapm)) {
914 VIAPM_OUTB(SMBHADDR, slave | LSB);
915 VIAPM_OUTB(SMBHCMD, cmd);
916 VIAPM_OUTB(SMBHCTRL, SMBHCTRL_START | SMBHCTRL_BLOCK);
918 if ((error = viapm_wait(viapm)) != SMB_ENOERR)
921 len = VIAPM_INB(SMBHDATA0);
922 i = VIAPM_INB(SMBHCTRL); /* reset counter */
924 /* read the 32-byte internal buffer */
925 for (i = 0; i < len; i++) {
926 data = VIAPM_INB(SMBHBLOCK);
934 VIAPM_DEBUG(printf("viapm: READBLK to 0x%x, count=0x%x, cmd=0x%x, error=0x%x", slave, *count, cmd, error));
940 static device_method_t viapm_methods[] = {
941 /* device interface */
942 DEVMETHOD(device_probe, viapm_586b_probe),
943 DEVMETHOD(device_attach, viapm_586b_attach),
944 DEVMETHOD(device_detach, viapm_586b_detach),
946 /* iicbb interface */
947 DEVMETHOD(iicbb_callback, viabb_callback),
948 DEVMETHOD(iicbb_setscl, viabb_setscl),
949 DEVMETHOD(iicbb_setsda, viabb_setsda),
950 DEVMETHOD(iicbb_getscl, viabb_getscl),
951 DEVMETHOD(iicbb_getsda, viabb_getsda),
952 DEVMETHOD(iicbb_reset, viabb_reset),
955 DEVMETHOD(bus_alloc_resource, bus_generic_alloc_resource),
956 DEVMETHOD(bus_release_resource, bus_generic_release_resource),
957 DEVMETHOD(bus_activate_resource, bus_generic_activate_resource),
958 DEVMETHOD(bus_deactivate_resource, bus_generic_deactivate_resource),
959 DEVMETHOD(bus_setup_intr, bus_generic_setup_intr),
960 DEVMETHOD(bus_teardown_intr, bus_generic_teardown_intr),
965 static driver_t viapm_driver = {
968 sizeof(struct viapm_softc),
971 static device_method_t viapropm_methods[] = {
972 /* device interface */
973 DEVMETHOD(device_probe, viapm_pro_probe),
974 DEVMETHOD(device_attach, viapm_pro_attach),
975 DEVMETHOD(device_detach, viapm_pro_detach),
977 /* smbus interface */
978 DEVMETHOD(smbus_callback, viasmb_callback),
979 DEVMETHOD(smbus_quick, viasmb_quick),
980 DEVMETHOD(smbus_sendb, viasmb_sendb),
981 DEVMETHOD(smbus_recvb, viasmb_recvb),
982 DEVMETHOD(smbus_writeb, viasmb_writeb),
983 DEVMETHOD(smbus_readb, viasmb_readb),
984 DEVMETHOD(smbus_writew, viasmb_writew),
985 DEVMETHOD(smbus_readw, viasmb_readw),
986 DEVMETHOD(smbus_bwrite, viasmb_bwrite),
987 DEVMETHOD(smbus_bread, viasmb_bread),
990 DEVMETHOD(bus_alloc_resource, bus_generic_alloc_resource),
991 DEVMETHOD(bus_release_resource, bus_generic_release_resource),
992 DEVMETHOD(bus_activate_resource, bus_generic_activate_resource),
993 DEVMETHOD(bus_deactivate_resource, bus_generic_deactivate_resource),
994 DEVMETHOD(bus_setup_intr, bus_generic_setup_intr),
995 DEVMETHOD(bus_teardown_intr, bus_generic_teardown_intr),
1000 static driver_t viapropm_driver = {
1003 sizeof(struct viapm_softc),
1006 DRIVER_MODULE(viapm, pci, viapm_driver, viapm_devclass, 0, 0);
1007 DRIVER_MODULE(viapropm, pci, viapropm_driver, viapropm_devclass, 0, 0);
1008 DRIVER_MODULE(iicbb, viapm, iicbb_driver, iicbb_devclass, 0, 0);
1009 DRIVER_MODULE(smbus, viapropm, smbus_driver, smbus_devclass, 0, 0);
1011 MODULE_DEPEND(viapm, pci, 1, 1, 1);
1012 MODULE_DEPEND(viapropm, pci, 1, 1, 1);
1013 MODULE_DEPEND(viapm, iicbb, IICBB_MINVER, IICBB_PREFVER, IICBB_MAXVER);
1014 MODULE_DEPEND(viapropm, smbus, SMBUS_MINVER, SMBUS_PREFVER, SMBUS_MAXVER);
1015 MODULE_VERSION(viapm, 1);
1018 DRIVER_MODULE(isa, viapm, isa_driver, isa_devclass, 0, 0);
1019 DRIVER_MODULE(isa, viapropm, isa_driver, isa_devclass, 0, 0);
1020 MODULE_DEPEND(viapm, isa, 1, 1, 1);
1021 MODULE_DEPEND(viapropm, isa, 1, 1, 1);