2 * SPDX-License-Identifier: BSD-2-Clause
4 * Copyright (c) 2019 Andriy Gapon
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 #include <sys/cdefs.h>
31 __FBSDID("$FreeBSD$");
33 #include <sys/param.h>
34 #include <sys/systm.h>
37 #include <sys/kernel.h>
39 #include <sys/mutex.h>
40 #include <sys/malloc.h>
41 #include <sys/module.h>
46 #include <machine/bus.h>
47 #include <machine/resource.h>
48 #include <machine/stdarg.h>
50 #include <isa/isavar.h>
52 #include <dev/superio/superio.h>
53 #include <dev/superio/superio_io.h>
57 typedef void (*sio_conf_enter_f)(struct resource*, uint16_t);
58 typedef void (*sio_conf_exit_f)(struct resource*, uint16_t);
60 struct sio_conf_methods {
61 sio_conf_enter_f enter;
63 superio_vendor_t vendor;
68 superio_dev_type_t type;
71 struct superio_devinfo {
72 STAILQ_ENTRY(superio_devinfo) link;
73 struct resource_list resources;
76 superio_dev_type_t type;
85 STAILQ_HEAD(, superio_devinfo) devlist;
86 struct resource* io_res;
90 const struct sio_conf_methods *methods;
91 const struct sio_device *known_devices;
92 superio_vendor_t vendor;
100 static d_ioctl_t superio_ioctl;
102 static struct cdevsw superio_cdevsw = {
103 .d_version = D_VERSION,
104 .d_ioctl = superio_ioctl,
111 sio_read(struct resource* res, uint8_t reg)
113 bus_write_1(res, 0, reg);
114 return (bus_read_1(res, 1));
117 /* Read a word from two one-byte registers, big endian. */
119 sio_readw(struct resource* res, uint8_t reg)
123 v = sio_read(res, reg);
125 v |= sio_read(res, reg + 1);
130 sio_write(struct resource* res, uint8_t reg, uint8_t val)
132 bus_write_1(res, 0, reg);
133 bus_write_1(res, 1, val);
137 sio_ldn_select(struct siosc *sc, uint8_t ldn)
139 mtx_assert(&sc->conf_lock, MA_OWNED);
140 if (ldn == sc->current_ldn)
142 sio_write(sc->io_res, sc->ldn_reg, ldn);
143 sc->current_ldn = ldn;
147 sio_ldn_read(struct siosc *sc, uint8_t ldn, uint8_t reg)
149 mtx_assert(&sc->conf_lock, MA_OWNED);
150 if (reg >= sc->enable_reg) {
151 sio_ldn_select(sc, ldn);
152 KASSERT(sc->current_ldn == ldn, ("sio_ldn_select failed"));
154 return (sio_read(sc->io_res, reg));
158 sio_ldn_readw(struct siosc *sc, uint8_t ldn, uint8_t reg)
160 mtx_assert(&sc->conf_lock, MA_OWNED);
161 if (reg >= sc->enable_reg) {
162 sio_ldn_select(sc, ldn);
163 KASSERT(sc->current_ldn == ldn, ("sio_ldn_select failed"));
165 return (sio_readw(sc->io_res, reg));
169 sio_ldn_write(struct siosc *sc, uint8_t ldn, uint8_t reg, uint8_t val)
171 mtx_assert(&sc->conf_lock, MA_OWNED);
172 if (reg <= sc->ldn_reg) {
173 printf("ignored attempt to write special register 0x%x\n", reg);
176 sio_ldn_select(sc, ldn);
177 KASSERT(sc->current_ldn == ldn, ("sio_ldn_select failed"));
178 sio_write(sc->io_res, reg, val);
182 sio_conf_enter(struct siosc *sc)
184 mtx_lock(&sc->conf_lock);
185 sc->methods->enter(sc->io_res, sc->io_port);
189 sio_conf_exit(struct siosc *sc)
191 sc->methods->exit(sc->io_res, sc->io_port);
192 sc->current_ldn = 0xff;
193 mtx_unlock(&sc->conf_lock);
197 ite_conf_enter(struct resource* res, uint16_t port)
199 bus_write_1(res, 0, 0x87);
200 bus_write_1(res, 0, 0x01);
201 bus_write_1(res, 0, 0x55);
202 bus_write_1(res, 0, port == 0x2e ? 0x55 : 0xaa);
206 ite_conf_exit(struct resource* res, uint16_t port)
208 sio_write(res, 0x02, 0x02);
211 static const struct sio_conf_methods ite_conf_methods = {
212 .enter = ite_conf_enter,
213 .exit = ite_conf_exit,
214 .vendor = SUPERIO_VENDOR_ITE
218 nvt_conf_enter(struct resource* res, uint16_t port)
220 bus_write_1(res, 0, 0x87);
221 bus_write_1(res, 0, 0x87);
225 nvt_conf_exit(struct resource* res, uint16_t port)
227 bus_write_1(res, 0, 0xaa);
230 static const struct sio_conf_methods nvt_conf_methods = {
231 .enter = nvt_conf_enter,
232 .exit = nvt_conf_exit,
233 .vendor = SUPERIO_VENDOR_NUVOTON
237 fintek_conf_enter(struct resource* res, uint16_t port)
239 bus_write_1(res, 0, 0x87);
240 bus_write_1(res, 0, 0x87);
244 fintek_conf_exit(struct resource* res, uint16_t port)
246 bus_write_1(res, 0, 0xaa);
249 static const struct sio_conf_methods fintek_conf_methods = {
250 .enter = fintek_conf_enter,
251 .exit = fintek_conf_exit,
252 .vendor = SUPERIO_VENDOR_FINTEK
255 static const struct sio_conf_methods * const methods_table[] = {
258 &fintek_conf_methods,
262 static const uint16_t ports_table[] = {
266 const struct sio_device ite_devices[] = {
267 { .ldn = 4, .type = SUPERIO_DEV_HWM },
268 { .ldn = 7, .type = SUPERIO_DEV_WDT },
269 { .type = SUPERIO_DEV_NONE },
272 const struct sio_device nvt_devices[] = {
273 { .ldn = 8, .type = SUPERIO_DEV_WDT },
274 { .type = SUPERIO_DEV_NONE },
277 const struct sio_device nct5104_devices[] = {
278 { .ldn = 7, .type = SUPERIO_DEV_GPIO },
279 { .ldn = 8, .type = SUPERIO_DEV_WDT },
280 { .ldn = 15, .type = SUPERIO_DEV_GPIO },
281 { .type = SUPERIO_DEV_NONE },
284 const struct sio_device fintek_devices[] = {
285 { .ldn = 7, .type = SUPERIO_DEV_WDT },
286 { .type = SUPERIO_DEV_NONE },
289 static const struct {
290 superio_vendor_t vendor;
294 const struct sio_device *devices;
295 } superio_table[] = {
297 .vendor = SUPERIO_VENDOR_ITE, .devid = 0x8712,
298 .devices = ite_devices,
301 .vendor = SUPERIO_VENDOR_ITE, .devid = 0x8716,
302 .devices = ite_devices,
305 .vendor = SUPERIO_VENDOR_ITE, .devid = 0x8718,
306 .devices = ite_devices,
309 .vendor = SUPERIO_VENDOR_ITE, .devid = 0x8720,
310 .devices = ite_devices,
313 .vendor = SUPERIO_VENDOR_ITE, .devid = 0x8721,
314 .devices = ite_devices,
317 .vendor = SUPERIO_VENDOR_ITE, .devid = 0x8726,
318 .devices = ite_devices,
321 .vendor = SUPERIO_VENDOR_ITE, .devid = 0x8728,
322 .devices = ite_devices,
325 .vendor = SUPERIO_VENDOR_ITE, .devid = 0x8771,
326 .devices = ite_devices,
329 .vendor = SUPERIO_VENDOR_NUVOTON, .devid = 0x1061, .mask = 0x00,
330 .descr = "Nuvoton NCT5104D/NCT6102D/NCT6106D (rev. A)",
331 .devices = nct5104_devices,
334 .vendor = SUPERIO_VENDOR_NUVOTON, .devid = 0x5200, .mask = 0xff,
335 .descr = "Winbond 83627HF/F/HG/G",
336 .devices = nvt_devices,
339 .vendor = SUPERIO_VENDOR_NUVOTON, .devid = 0x5900, .mask = 0xff,
340 .descr = "Winbond 83627S",
341 .devices = nvt_devices,
344 .vendor = SUPERIO_VENDOR_NUVOTON, .devid = 0x6000, .mask = 0xff,
345 .descr = "Winbond 83697HF",
346 .devices = nvt_devices,
349 .vendor = SUPERIO_VENDOR_NUVOTON, .devid = 0x6800, .mask = 0xff,
350 .descr = "Winbond 83697UG",
351 .devices = nvt_devices,
354 .vendor = SUPERIO_VENDOR_NUVOTON, .devid = 0x7000, .mask = 0xff,
355 .descr = "Winbond 83637HF",
356 .devices = nvt_devices,
359 .vendor = SUPERIO_VENDOR_NUVOTON, .devid = 0x8200, .mask = 0xff,
360 .descr = "Winbond 83627THF",
361 .devices = nvt_devices,
364 .vendor = SUPERIO_VENDOR_NUVOTON, .devid = 0x8500, .mask = 0xff,
365 .descr = "Winbond 83687THF",
366 .devices = nvt_devices,
369 .vendor = SUPERIO_VENDOR_NUVOTON, .devid = 0x8800, .mask = 0xff,
370 .descr = "Winbond 83627EHF",
371 .devices = nvt_devices,
374 .vendor = SUPERIO_VENDOR_NUVOTON, .devid = 0xa000, .mask = 0xff,
375 .descr = "Winbond 83627DHG",
376 .devices = nvt_devices,
379 .vendor = SUPERIO_VENDOR_NUVOTON, .devid = 0xa200, .mask = 0xff,
380 .descr = "Winbond 83627UHG",
381 .devices = nvt_devices,
384 .vendor = SUPERIO_VENDOR_NUVOTON, .devid = 0xa500, .mask = 0xff,
385 .descr = "Winbond 83667HG",
386 .devices = nvt_devices,
389 .vendor = SUPERIO_VENDOR_NUVOTON, .devid = 0xb000, .mask = 0xff,
390 .descr = "Winbond 83627DHG-P",
391 .devices = nvt_devices,
394 .vendor = SUPERIO_VENDOR_NUVOTON, .devid = 0xb300, .mask = 0xff,
395 .descr = "Winbond 83667HG-B",
396 .devices = nvt_devices,
399 .vendor = SUPERIO_VENDOR_NUVOTON, .devid = 0xb400, .mask = 0xff,
400 .descr = "Nuvoton NCT6775",
401 .devices = nvt_devices,
404 .vendor = SUPERIO_VENDOR_NUVOTON, .devid = 0xc300, .mask = 0xff,
405 .descr = "Nuvoton NCT6776",
406 .devices = nvt_devices,
409 .vendor = SUPERIO_VENDOR_NUVOTON, .devid = 0xc400, .mask = 0xff,
410 .descr = "Nuvoton NCT5104D/NCT6102D/NCT6106D (rev. B+)",
411 .devices = nct5104_devices,
414 .vendor = SUPERIO_VENDOR_NUVOTON, .devid = 0xc500, .mask = 0xff,
415 .descr = "Nuvoton NCT6779",
416 .devices = nvt_devices,
419 .vendor = SUPERIO_VENDOR_NUVOTON, .devid = 0xc800, .mask = 0xff,
420 .descr = "Nuvoton NCT6791",
421 .devices = nvt_devices,
424 .vendor = SUPERIO_VENDOR_NUVOTON, .devid = 0xc900, .mask = 0xff,
425 .descr = "Nuvoton NCT6792",
426 .devices = nvt_devices,
429 .vendor = SUPERIO_VENDOR_NUVOTON, .devid = 0xd100, .mask = 0xff,
430 .descr = "Nuvoton NCT6793",
431 .devices = nvt_devices,
434 .vendor = SUPERIO_VENDOR_NUVOTON, .devid = 0xd300, .mask = 0xff,
435 .descr = "Nuvoton NCT6795",
436 .devices = nvt_devices,
439 .vendor = SUPERIO_VENDOR_FINTEK, .devid = 0x1210, .mask = 0xff,
440 .descr = "Fintek F81803",
441 .devices = fintek_devices,
447 devtype_to_str(superio_dev_type_t type)
450 case SUPERIO_DEV_NONE:
452 case SUPERIO_DEV_HWM:
454 case SUPERIO_DEV_WDT:
456 case SUPERIO_DEV_GPIO:
458 case SUPERIO_DEV_MAX:
465 superio_detect(device_t dev, bool claim, struct siosc *sc)
467 struct resource *res;
476 error = bus_get_resource(dev, SYS_RES_IOPORT, 0, &port, &count);
479 if (port > UINT16_MAX || count < NUMPORTS) {
480 device_printf(dev, "unexpected I/O range size\n");
485 * Make a temporary resource reservation for hardware probing.
486 * If we can't get the resources we need then
487 * we need to abort. Possibly this indicates
488 * the resources were used by another device
489 * in which case the probe would have failed anyhow.
492 res = bus_alloc_resource_any(dev, SYS_RES_IOPORT, &rid, RF_ACTIVE);
495 device_printf(dev, "failed to allocate I/O resource\n");
499 for (m = 0; methods_table[m] != NULL; m++) {
500 methods_table[m]->enter(res, port);
501 if (methods_table[m]->vendor == SUPERIO_VENDOR_ITE) {
502 devid = sio_readw(res, 0x20);
503 revid = sio_read(res, 0x22);
504 } else if (methods_table[m]->vendor == SUPERIO_VENDOR_NUVOTON) {
505 devid = sio_read(res, 0x20);
506 revid = sio_read(res, 0x21);
507 devid = (devid << 8) | revid;
508 } else if (methods_table[m]->vendor == SUPERIO_VENDOR_FINTEK) {
509 devid = sio_read(res, 0x20);
510 revid = sio_read(res, 0x21);
511 devid = (devid << 8) | revid;
515 methods_table[m]->exit(res, port);
516 for (i = 0; superio_table[i].vendor != 0; i++) {
519 mask = superio_table[i].mask;
520 if (superio_table[i].vendor !=
521 methods_table[m]->vendor)
523 if ((superio_table[i].devid & ~mask) != (devid & ~mask))
528 /* Found a matching SuperIO entry. */
529 if (superio_table[i].vendor != 0)
533 if (methods_table[m] == NULL)
537 if (!claim || error != 0) {
538 bus_release_resource(dev, SYS_RES_IOPORT, rid, res);
542 sc->methods = methods_table[m];
543 sc->vendor = sc->methods->vendor;
544 sc->known_devices = superio_table[i].devices;
551 KASSERT(sc->vendor == SUPERIO_VENDOR_ITE ||
552 sc->vendor == SUPERIO_VENDOR_NUVOTON,
553 ("Only ITE and Nuvoton SuperIO-s are supported"));
555 sc->enable_reg = 0x30;
556 sc->current_ldn = 0xff; /* no device should have this */
558 if (superio_table[i].descr != NULL) {
559 device_set_desc(dev, superio_table[i].descr);
560 } else if (sc->vendor == SUPERIO_VENDOR_ITE) {
563 snprintf(descr, sizeof(descr),
564 "ITE IT%4x SuperIO (revision 0x%02x)",
565 sc->devid, sc->revid);
566 device_set_desc_copy(dev, descr);
572 superio_identify(driver_t *driver, device_t parent)
578 * Don't create child devices if any already exist.
579 * Those could be created via isa hints or if this
580 * driver is loaded, unloaded and then loaded again.
582 if (device_find_child(parent, "superio", -1)) {
584 printf("superio: device(s) already created\n");
589 * Create a child for each candidate port.
590 * It would be nice if we could somehow clean up those
591 * that this driver fails to probe.
593 for (i = 0; ports_table[i] != 0; i++) {
594 child = BUS_ADD_CHILD(parent, ISA_ORDER_SPECULATIVE,
597 device_printf(parent, "failed to add superio child\n");
600 bus_set_resource(child, SYS_RES_IOPORT, 0, ports_table[i], 2);
601 if (superio_detect(child, false, NULL) != 0)
602 device_delete_child(parent, child);
607 superio_probe(device_t dev)
612 /* Make sure we do not claim some ISA PNP device. */
613 if (isa_get_logicalid(dev) != 0)
617 * XXX We can populate the softc now only because we return
620 sc = device_get_softc(dev);
621 error = superio_detect(dev, true, sc);
624 return (BUS_PROBE_SPECIFIC);
628 superio_add_known_child(device_t dev, superio_dev_type_t type, uint8_t ldn)
630 struct siosc *sc = device_get_softc(dev);
631 struct superio_devinfo *dinfo;
634 child = BUS_ADD_CHILD(dev, 0, NULL, -1);
636 device_printf(dev, "failed to add child for ldn %d, type %s\n",
637 ldn, devtype_to_str(type));
640 dinfo = device_get_ivars(child);
644 dinfo->iobase = sio_ldn_readw(sc, ldn, 0x60);
645 dinfo->iobase2 = sio_ldn_readw(sc, ldn, 0x62);
646 dinfo->irq = sio_ldn_readw(sc, ldn, 0x70);
647 dinfo->dma = sio_ldn_readw(sc, ldn, 0x74);
649 STAILQ_INSERT_TAIL(&sc->devlist, dinfo, link);
653 superio_attach(device_t dev)
655 struct siosc *sc = device_get_softc(dev);
658 mtx_init(&sc->conf_lock, device_get_nameunit(dev), "superio", MTX_DEF);
659 STAILQ_INIT(&sc->devlist);
661 for (i = 0; sc->known_devices[i].type != SUPERIO_DEV_NONE; i++) {
662 superio_add_known_child(dev, sc->known_devices[i].type,
663 sc->known_devices[i].ldn);
666 bus_generic_probe(dev);
667 bus_generic_attach(dev);
669 sc->chardev = make_dev(&superio_cdevsw, device_get_unit(dev),
670 UID_ROOT, GID_WHEEL, 0600, "superio%d", device_get_unit(dev));
671 if (sc->chardev == NULL)
672 device_printf(dev, "failed to create character device\n");
674 sc->chardev->si_drv1 = sc;
679 superio_detach(device_t dev)
681 struct siosc *sc = device_get_softc(dev);
684 error = bus_generic_detach(dev);
687 if (sc->chardev != NULL)
688 destroy_dev(sc->chardev);
689 device_delete_children(dev);
690 bus_release_resource(dev, SYS_RES_IOPORT, sc->io_rid, sc->io_res);
691 mtx_destroy(&sc->conf_lock);
696 superio_add_child(device_t dev, u_int order, const char *name, int unit)
698 struct superio_devinfo *dinfo;
701 child = device_add_child_ordered(dev, order, name, unit);
704 dinfo = malloc(sizeof(*dinfo), M_DEVBUF, M_NOWAIT | M_ZERO);
706 device_delete_child(dev, child);
710 dinfo->type = SUPERIO_DEV_NONE;
712 resource_list_init(&dinfo->resources);
713 device_set_ivars(child, dinfo);
718 superio_read_ivar(device_t dev, device_t child, int which, uintptr_t *result)
720 struct superio_devinfo *dinfo;
722 dinfo = device_get_ivars(child);
724 case SUPERIO_IVAR_LDN:
725 *result = dinfo->ldn;
727 case SUPERIO_IVAR_TYPE:
728 *result = dinfo->type;
730 case SUPERIO_IVAR_IOBASE:
731 *result = dinfo->iobase;
733 case SUPERIO_IVAR_IOBASE2:
734 *result = dinfo->iobase2;
736 case SUPERIO_IVAR_IRQ:
737 *result = dinfo->irq;
739 case SUPERIO_IVAR_DMA:
740 *result = dinfo->dma;
749 superio_write_ivar(device_t dev, device_t child, int which, uintptr_t value)
753 case SUPERIO_IVAR_LDN:
754 case SUPERIO_IVAR_TYPE:
755 case SUPERIO_IVAR_IOBASE:
756 case SUPERIO_IVAR_IOBASE2:
757 case SUPERIO_IVAR_IRQ:
758 case SUPERIO_IVAR_DMA:
765 static struct resource_list *
766 superio_get_resource_list(device_t dev, device_t child)
768 struct superio_devinfo *dinfo = device_get_ivars(child);
770 return (&dinfo->resources);
774 superio_printf(struct superio_devinfo *dinfo, const char *fmt, ...)
779 retval = printf("superio:%s@ldn%0x2x: ",
780 devtype_to_str(dinfo->type), dinfo->ldn);
782 retval += vprintf(fmt, ap);
788 superio_child_detached(device_t dev, device_t child)
790 struct superio_devinfo *dinfo;
791 struct resource_list *rl;
793 dinfo = device_get_ivars(child);
794 rl = &dinfo->resources;
796 if (resource_list_release_active(rl, dev, child, SYS_RES_IRQ) != 0)
797 superio_printf(dinfo, "Device leaked IRQ resources\n");
798 if (resource_list_release_active(rl, dev, child, SYS_RES_MEMORY) != 0)
799 superio_printf(dinfo, "Device leaked memory resources\n");
800 if (resource_list_release_active(rl, dev, child, SYS_RES_IOPORT) != 0)
801 superio_printf(dinfo, "Device leaked I/O resources\n");
805 superio_child_location_str(device_t parent, device_t child, char *buf,
810 ldn = superio_get_ldn(child);
811 snprintf(buf, buflen, "ldn=0x%02x", ldn);
816 superio_child_pnp_str(device_t parent, device_t child, char *buf,
819 superio_dev_type_t type;
821 type = superio_get_type(child);
822 snprintf(buf, buflen, "type=%s", devtype_to_str(type));
827 superio_print_child(device_t parent, device_t child)
829 superio_dev_type_t type;
833 ldn = superio_get_ldn(child);
834 type = superio_get_type(child);
836 retval = bus_print_child_header(parent, child);
837 retval += printf(" at %s ldn 0x%02x", devtype_to_str(type), ldn);
838 retval += bus_print_child_footer(parent, child);
844 superio_vendor(device_t dev)
846 device_t sio_dev = device_get_parent(dev);
847 struct siosc *sc = device_get_softc(sio_dev);
853 superio_devid(device_t dev)
855 device_t sio_dev = device_get_parent(dev);
856 struct siosc *sc = device_get_softc(sio_dev);
862 superio_revid(device_t dev)
864 device_t sio_dev = device_get_parent(dev);
865 struct siosc *sc = device_get_softc(sio_dev);
871 superio_read(device_t dev, uint8_t reg)
873 device_t sio_dev = device_get_parent(dev);
874 struct siosc *sc = device_get_softc(sio_dev);
875 struct superio_devinfo *dinfo = device_get_ivars(dev);
879 v = sio_ldn_read(sc, dinfo->ldn, reg);
885 superio_write(device_t dev, uint8_t reg, uint8_t val)
887 device_t sio_dev = device_get_parent(dev);
888 struct siosc *sc = device_get_softc(sio_dev);
889 struct superio_devinfo *dinfo = device_get_ivars(dev);
892 sio_ldn_write(sc, dinfo->ldn, reg, val);
897 superio_dev_enabled(device_t dev, uint8_t mask)
899 device_t sio_dev = device_get_parent(dev);
900 struct siosc *sc = device_get_softc(sio_dev);
901 struct superio_devinfo *dinfo = device_get_ivars(dev);
904 /* GPIO device is always active in ITE chips. */
905 if (sc->vendor == SUPERIO_VENDOR_ITE && dinfo->ldn == 7)
908 v = superio_read(dev, sc->enable_reg);
909 return ((v & mask) != 0);
913 superio_dev_enable(device_t dev, uint8_t mask)
915 device_t sio_dev = device_get_parent(dev);
916 struct siosc *sc = device_get_softc(sio_dev);
917 struct superio_devinfo *dinfo = device_get_ivars(dev);
920 /* GPIO device is always active in ITE chips. */
921 if (sc->vendor == SUPERIO_VENDOR_ITE && dinfo->ldn == 7)
925 v = sio_ldn_read(sc, dinfo->ldn, sc->enable_reg);
927 sio_ldn_write(sc, dinfo->ldn, sc->enable_reg, v);
932 superio_dev_disable(device_t dev, uint8_t mask)
934 device_t sio_dev = device_get_parent(dev);
935 struct siosc *sc = device_get_softc(sio_dev);
936 struct superio_devinfo *dinfo = device_get_ivars(dev);
939 /* GPIO device is always active in ITE chips. */
940 if (sc->vendor == SUPERIO_VENDOR_ITE && dinfo->ldn == 7)
944 v = sio_ldn_read(sc, dinfo->ldn, sc->enable_reg);
946 sio_ldn_write(sc, dinfo->ldn, sc->enable_reg, v);
951 superio_find_dev(device_t superio, superio_dev_type_t type, int ldn)
953 struct siosc *sc = device_get_softc(superio);
954 struct superio_devinfo *dinfo;
956 if (ldn < -1 || ldn > UINT8_MAX)
957 return (NULL); /* ERANGE */
958 if (type == SUPERIO_DEV_NONE && ldn == -1)
959 return (NULL); /* EINVAL */
961 STAILQ_FOREACH(dinfo, &sc->devlist, link) {
962 if (ldn != -1 && dinfo->ldn != ldn)
964 if (type != SUPERIO_DEV_NONE && dinfo->type != type)
972 superio_ioctl(struct cdev *dev, u_long cmd, caddr_t data, int flags,
976 struct superiocmd *s;
979 s = (struct superiocmd *)data;
981 case SUPERIO_CR_READ:
983 s->val = sio_ldn_read(sc, s->ldn, s->cr);
986 case SUPERIO_CR_WRITE:
988 sio_ldn_write(sc, s->ldn, s->cr, s->val);
996 static devclass_t superio_devclass;
998 static device_method_t superio_methods[] = {
999 DEVMETHOD(device_identify, superio_identify),
1000 DEVMETHOD(device_probe, superio_probe),
1001 DEVMETHOD(device_attach, superio_attach),
1002 DEVMETHOD(device_detach, superio_detach),
1003 DEVMETHOD(device_shutdown, bus_generic_shutdown),
1004 DEVMETHOD(device_suspend, bus_generic_suspend),
1005 DEVMETHOD(device_resume, bus_generic_resume),
1007 DEVMETHOD(bus_add_child, superio_add_child),
1008 DEVMETHOD(bus_child_detached, superio_child_detached),
1009 DEVMETHOD(bus_child_location_str, superio_child_location_str),
1010 DEVMETHOD(bus_child_pnpinfo_str, superio_child_pnp_str),
1011 DEVMETHOD(bus_print_child, superio_print_child),
1012 DEVMETHOD(bus_read_ivar, superio_read_ivar),
1013 DEVMETHOD(bus_write_ivar, superio_write_ivar),
1014 DEVMETHOD(bus_get_resource_list, superio_get_resource_list),
1015 DEVMETHOD(bus_alloc_resource, bus_generic_rl_alloc_resource),
1016 DEVMETHOD(bus_release_resource, bus_generic_rl_release_resource),
1017 DEVMETHOD(bus_set_resource, bus_generic_rl_set_resource),
1018 DEVMETHOD(bus_get_resource, bus_generic_rl_get_resource),
1019 DEVMETHOD(bus_delete_resource, bus_generic_rl_delete_resource),
1020 DEVMETHOD(bus_activate_resource, bus_generic_activate_resource),
1021 DEVMETHOD(bus_deactivate_resource, bus_generic_deactivate_resource),
1022 DEVMETHOD(bus_setup_intr, bus_generic_setup_intr),
1023 DEVMETHOD(bus_teardown_intr, bus_generic_teardown_intr),
1028 static driver_t superio_driver = {
1031 sizeof(struct siosc)
1034 DRIVER_MODULE(superio, isa, superio_driver, superio_devclass, 0, 0);
1035 MODULE_VERSION(superio, 1);