Lines Matching +full:slave +full:- +full:dev

1 /*-
2 * Copyright (c) 2001 Alcove - Nicolas Souchu
46 #include <dev/pci/pcivar.h>
47 #include <dev/pci/pcireg.h>
49 #include <dev/iicbus/iiconf.h>
51 #include <dev/smbus/smbconf.h>
75 ((u_char)bus_read_1(viapm->iores, port))
77 (bus_write_1(viapm->iores, port, (u_char)(val)))
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)
174 #define SMBSCTRL_ENABLE 0x01 /* enable slave */
183 viapm_586b_probe(device_t dev)
185 struct viapm_softc *viapm = (struct viapm_softc *)device_get_softc(dev);
190 switch (pci_get_devid(dev)) {
195 l = pci_read_config(dev, VIAPM_586B_REVID, 1);
198 viapm->type = VIAPM_TYP_586B_3040E;
199 viapm->iorid = VIAPM_586B_3040E_BASE;
202 s = pci_read_config(dev, VIAPM_586B_3040E_ACTIV, 2);
203 pci_write_config(dev, VIAPM_586B_3040E_ACTIV, s | 0x1, 2);
209 viapm->type = VIAPM_TYP_586B_3040F;
210 viapm->iorid = VIAPM_586B_3040F_BASE;
213 c = pci_read_config(dev, VIAPM_586B_3040F_ACTIV, 1);
214 pci_write_config(dev, VIAPM_586B_3040F_ACTIV, c | 0x80, 1);
218 viapm->base = pci_read_config(dev, viapm->iorid, 4) &
225 if (bus_set_resource(dev, SYS_RES_IOPORT, viapm->iorid,
226 viapm->base, 256)) {
227 device_printf(dev, "could not set bus resource\n");
230 device_set_desc(dev, "VIA VT82C586B Power Management Unit");
241 viapm_pro_probe(device_t dev)
243 struct viapm_softc *viapm = (struct viapm_softc *)device_get_softc(dev);
250 switch (pci_get_devid(dev)) {
253 viapm->type = VIAPM_TYP_596B;
259 viapm->type = VIAPM_TYP_596B;
265 viapm->type = VIAPM_TYP_686A;
272 viapm->type = VIAPM_TYP_UNKNOWN;
278 viapm->type = VIAPM_TYP_UNKNOWN;
284 viapm->type = VIAPM_TYP_UNKNOWN;
290 viapm->type = VIAPM_TYP_UNKNOWN;
300 l = pci_read_config(dev, VIAPM_PRO_SMBCTRL, 1);
301 pci_write_config(dev, VIAPM_PRO_SMBCTRL, l | 1, 1);
304 pci_write_config(dev, base_cfgreg,
308 viapm->base = pci_read_config(dev, base_cfgreg, 4) & VIAPM_PRO_BA_MASK;
314 viapm->iorid = base_cfgreg;
315 if (bus_set_resource(dev, SYS_RES_IOPORT, viapm->iorid,
316 viapm->base, 16)) {
317 device_printf(dev, "could not set bus resource 0x%x\n",
318 viapm->base);
323 device_printf(dev, "SMBus I/O base at 0x%x\n", viapm->base);
326 device_set_desc(dev, desc);
337 viapm_pro_attach(device_t dev)
339 struct viapm_softc *viapm = (struct viapm_softc *)device_get_softc(dev);
342 mtx_init(&viapm->lock, device_get_nameunit(dev), "viapm", MTX_DEF);
343 if (!(viapm->iores = bus_alloc_resource_any(dev, SYS_RES_IOPORT,
344 &viapm->iorid, RF_ACTIVE))) {
345 device_printf(dev, "could not allocate bus space\n");
351 l = pci_read_config(dev, VIAPM_PRO_SMBCTRL, 1);
352 pci_write_config(dev, VIAPM_PRO_SMBCTRL, l | 0x80, 1);
354 viapm->irqrid = 0;
355 if (!(viapm->irqres = bus_alloc_resource(dev, SYS_RES_IRQ,
356 &viapm->irqrid, 9, 9, 1,
358 device_printf(dev, "could not allocate irq\n");
362 if (bus_setup_intr(dev, viapm->irqres, INTR_TYPE_MISC | INTR_MPSAFE,
363 (driver_intr_t *) viasmb_intr, viapm, &viapm->irqih)) {
364 device_printf(dev, "could not setup irq\n");
370 l = pci_read_config(dev, VIAPM_PRO_REVID, 1);
371 device_printf(dev, "SMBus revision code 0x%x\n", l);
374 viapm->smbus = device_add_child(dev, "smbus", DEVICE_UNIT_ANY);
377 bus_generic_attach(dev);
379 /* disable slave function */
383 l = pci_read_config(dev, VIAPM_PRO_SMBCTRL, 1);
384 pci_write_config(dev, VIAPM_PRO_SMBCTRL, l | 1, 1);
392 /* If this device is a PCI-ISA bridge, then attach an ISA bus. */
393 if ((pci_get_class(dev) == PCIC_BRIDGE) &&
394 (pci_get_subclass(dev) == PCIS_BRIDGE_ISA))
395 isab_attach(dev);
400 if (viapm->iores)
401 bus_release_resource(dev, SYS_RES_IOPORT, viapm->iorid, viapm->iores);
403 if (viapm->irqres)
404 bus_release_resource(dev, SYS_RES_IRQ, viapm->irqrid, viapm->irqres);
406 mtx_destroy(&viapm->lock);
412 viapm_586b_attach(device_t dev)
414 struct viapm_softc *viapm = (struct viapm_softc *)device_get_softc(dev);
416 mtx_init(&viapm->lock, device_get_nameunit(dev), "viapm", MTX_DEF);
417 if (!(viapm->iores = bus_alloc_resource_any(dev, SYS_RES_IOPORT,
418 &viapm->iorid, RF_ACTIVE | RF_SHAREABLE))) {
419 device_printf(dev, "could not allocate bus resource\n");
425 /* add generic bit-banging code */
426 if (!(viapm->iicbb = device_add_child(dev, "iicbb", -1)))
429 bus_generic_attach(dev);
434 if (viapm->iores)
435 bus_release_resource(dev, SYS_RES_IOPORT,
436 viapm->iorid, viapm->iores);
437 mtx_destroy(&viapm->lock);
442 viapm_586b_detach(device_t dev)
444 struct viapm_softc *viapm = (struct viapm_softc *)device_get_softc(dev);
446 bus_generic_detach(dev);
447 if (viapm->iicbb) {
448 device_delete_child(dev, viapm->iicbb);
451 if (viapm->iores)
452 bus_release_resource(dev, SYS_RES_IOPORT, viapm->iorid,
453 viapm->iores);
454 mtx_destroy(&viapm->lock);
460 viapm_pro_detach(device_t dev)
462 struct viapm_softc *viapm = (struct viapm_softc *)device_get_softc(dev);
464 bus_generic_detach(dev);
465 if (viapm->smbus) {
466 device_delete_child(dev, viapm->smbus);
469 bus_release_resource(dev, SYS_RES_IOPORT, viapm->iorid, viapm->iores);
472 bus_release_resource(dev, SYS_RES_IRQ, viapm->irqrid, viapm->irqres);
474 mtx_destroy(&viapm->lock);
480 viabb_callback(device_t dev, int index, caddr_t data)
486 viabb_setscl(device_t dev, int ctrl)
488 struct viapm_softc *viapm = device_get_softc(dev);
506 viabb_setsda(device_t dev, int data)
508 struct viapm_softc *viapm = device_get_softc(dev);
526 viabb_reset(device_t dev, u_char speed, u_char addr, u_char *oldaddr)
529 viabb_setsda(dev, 1);
530 viabb_setscl(dev, 1);
536 viabb_getscl(device_t dev)
538 struct viapm_softc *viapm = device_get_softc(dev);
548 viabb_getsda(device_t dev)
550 struct viapm_softc *viapm = device_get_softc(dev);
603 while(count--) {
637 viasmb_callback(device_t dev, int index, void *data)
654 viasmb_quick(device_t dev, u_char slave, int how)
656 struct viapm_softc *viapm = (struct viapm_softc *)device_get_softc(dev);
668 VIAPM_DEBUG(printf("viapm: QWRITE to 0x%x", slave));
669 VIAPM_OUTB(SMBHADDR, slave & ~LSB);
672 VIAPM_DEBUG(printf("viapm: QREAD to 0x%x", slave));
673 VIAPM_OUTB(SMBHADDR, slave | LSB);
688 viasmb_sendb(device_t dev, u_char slave, char byte)
690 struct viapm_softc *viapm = (struct viapm_softc *)device_get_softc(dev);
700 VIAPM_OUTB(SMBHADDR, slave & ~ LSB);
707 VIAPM_DEBUG(printf("viapm: SENDB to 0x%x, byte=0x%x, error=0x%x\n", slave, byte, error));
714 viasmb_recvb(device_t dev, u_char slave, char *byte)
716 struct viapm_softc *viapm = (struct viapm_softc *)device_get_softc(dev);
726 VIAPM_OUTB(SMBHADDR, slave | LSB);
733 VIAPM_DEBUG(printf("viapm: RECVB from 0x%x, byte=0x%x, error=0x%x\n", slave, *byte, error));
740 viasmb_writeb(device_t dev, u_char slave, char cmd, char byte)
742 struct viapm_softc *viapm = (struct viapm_softc *)device_get_softc(dev);
752 VIAPM_OUTB(SMBHADDR, slave & ~ LSB);
760 VIAPM_DEBUG(printf("viapm: WRITEB to 0x%x, cmd=0x%x, byte=0x%x, error=0x%x\n", slave, cmd, byte, error));
767 viasmb_readb(device_t dev, u_char slave, char cmd, char *byte)
769 struct viapm_softc *viapm = (struct viapm_softc *)device_get_softc(dev);
779 VIAPM_OUTB(SMBHADDR, slave | LSB);
787 VIAPM_DEBUG(printf("viapm: READB from 0x%x, cmd=0x%x, byte=0x%x, error=0x%x\n", slave, cmd, *byte, error));
794 viasmb_writew(device_t dev, u_char slave, char cmd, short word)
796 struct viapm_softc *viapm = (struct viapm_softc *)device_get_softc(dev);
806 VIAPM_OUTB(SMBHADDR, slave & ~ LSB);
815 VIAPM_DEBUG(printf("viapm: WRITEW to 0x%x, cmd=0x%x, word=0x%x, error=0x%x\n", slave, cmd, word, error));
822 viasmb_readw(device_t dev, u_char slave, char cmd, short *word)
824 struct viapm_softc *viapm = (struct viapm_softc *)device_get_softc(dev);
835 VIAPM_OUTB(SMBHADDR, slave | LSB);
847 VIAPM_DEBUG(printf("viapm: READW from 0x%x, cmd=0x%x, word=0x%x, error=0x%x\n", slave, cmd, *word, error));
854 viasmb_bwrite(device_t dev, u_char slave, char cmd, u_char count, char *buf)
856 struct viapm_softc *viapm = (struct viapm_softc *)device_get_softc(dev);
870 VIAPM_OUTB(SMBHADDR, slave & ~LSB);
875 /* fill the 32-byte internal buffer */
885 VIAPM_DEBUG(printf("viapm: WRITEBLK to 0x%x, count=0x%x, cmd=0x%x, error=0x%x", slave, count, cmd, error));
893 viasmb_bread(device_t dev, u_char slave, char cmd, u_char *count, char *buf)
895 struct viapm_softc *viapm = (struct viapm_softc *)device_get_softc(dev);
909 VIAPM_OUTB(SMBHADDR, slave | LSB);
919 /* read the 32-byte internal buffer */
929 VIAPM_DEBUG(printf("viapm: READBLK to 0x%x, count=0x%x, cmd=0x%x, error=0x%x", slave, *count, cmd, error));