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
236 static const struct sio_conf_methods * const methods_table[] = {
242 static const uint16_t ports_table[] = {
246 const struct sio_device ite_devices[] = {
247 { .ldn = 4, .type = SUPERIO_DEV_HWM },
248 { .ldn = 7, .type = SUPERIO_DEV_WDT },
249 { .type = SUPERIO_DEV_NONE },
252 const struct sio_device nvt_devices[] = {
253 { .ldn = 8, .type = SUPERIO_DEV_WDT },
254 { .type = SUPERIO_DEV_NONE },
257 const struct sio_device nct5104_devices[] = {
258 { .ldn = 7, .type = SUPERIO_DEV_GPIO },
259 { .ldn = 8, .type = SUPERIO_DEV_WDT },
260 { .ldn = 15, .type = SUPERIO_DEV_GPIO },
261 { .type = SUPERIO_DEV_NONE },
264 static const struct {
265 superio_vendor_t vendor;
269 const struct sio_device *devices;
270 } superio_table[] = {
272 .vendor = SUPERIO_VENDOR_ITE, .devid = 0x8712,
273 .devices = ite_devices,
276 .vendor = SUPERIO_VENDOR_ITE, .devid = 0x8716,
277 .devices = ite_devices,
280 .vendor = SUPERIO_VENDOR_ITE, .devid = 0x8718,
281 .devices = ite_devices,
284 .vendor = SUPERIO_VENDOR_ITE, .devid = 0x8720,
285 .devices = ite_devices,
288 .vendor = SUPERIO_VENDOR_ITE, .devid = 0x8721,
289 .devices = ite_devices,
292 .vendor = SUPERIO_VENDOR_ITE, .devid = 0x8726,
293 .devices = ite_devices,
296 .vendor = SUPERIO_VENDOR_ITE, .devid = 0x8728,
297 .devices = ite_devices,
300 .vendor = SUPERIO_VENDOR_ITE, .devid = 0x8771,
301 .devices = ite_devices,
304 .vendor = SUPERIO_VENDOR_NUVOTON, .devid = 0x1061, .mask = 0x00,
305 .descr = "Nuvoton NCT5104D/NCT6102D/NCT6106D (rev. A)",
306 .devices = nct5104_devices,
309 .vendor = SUPERIO_VENDOR_NUVOTON, .devid = 0x5200, .mask = 0xff,
310 .descr = "Winbond 83627HF/F/HG/G",
311 .devices = nvt_devices,
314 .vendor = SUPERIO_VENDOR_NUVOTON, .devid = 0x5900, .mask = 0xff,
315 .descr = "Winbond 83627S",
316 .devices = nvt_devices,
319 .vendor = SUPERIO_VENDOR_NUVOTON, .devid = 0x6000, .mask = 0xff,
320 .descr = "Winbond 83697HF",
321 .devices = nvt_devices,
324 .vendor = SUPERIO_VENDOR_NUVOTON, .devid = 0x6800, .mask = 0xff,
325 .descr = "Winbond 83697UG",
326 .devices = nvt_devices,
329 .vendor = SUPERIO_VENDOR_NUVOTON, .devid = 0x7000, .mask = 0xff,
330 .descr = "Winbond 83637HF",
331 .devices = nvt_devices,
334 .vendor = SUPERIO_VENDOR_NUVOTON, .devid = 0x8200, .mask = 0xff,
335 .descr = "Winbond 83627THF",
336 .devices = nvt_devices,
339 .vendor = SUPERIO_VENDOR_NUVOTON, .devid = 0x8500, .mask = 0xff,
340 .descr = "Winbond 83687THF",
341 .devices = nvt_devices,
344 .vendor = SUPERIO_VENDOR_NUVOTON, .devid = 0x8800, .mask = 0xff,
345 .descr = "Winbond 83627EHF",
346 .devices = nvt_devices,
349 .vendor = SUPERIO_VENDOR_NUVOTON, .devid = 0xa000, .mask = 0xff,
350 .descr = "Winbond 83627DHG",
351 .devices = nvt_devices,
354 .vendor = SUPERIO_VENDOR_NUVOTON, .devid = 0xa200, .mask = 0xff,
355 .descr = "Winbond 83627UHG",
356 .devices = nvt_devices,
359 .vendor = SUPERIO_VENDOR_NUVOTON, .devid = 0xa500, .mask = 0xff,
360 .descr = "Winbond 83667HG",
361 .devices = nvt_devices,
364 .vendor = SUPERIO_VENDOR_NUVOTON, .devid = 0xb000, .mask = 0xff,
365 .descr = "Winbond 83627DHG-P",
366 .devices = nvt_devices,
369 .vendor = SUPERIO_VENDOR_NUVOTON, .devid = 0xb300, .mask = 0xff,
370 .descr = "Winbond 83667HG-B",
371 .devices = nvt_devices,
374 .vendor = SUPERIO_VENDOR_NUVOTON, .devid = 0xb400, .mask = 0xff,
375 .descr = "Nuvoton NCT6775",
376 .devices = nvt_devices,
379 .vendor = SUPERIO_VENDOR_NUVOTON, .devid = 0xc300, .mask = 0xff,
380 .descr = "Nuvoton NCT6776",
381 .devices = nvt_devices,
384 .vendor = SUPERIO_VENDOR_NUVOTON, .devid = 0xc400, .mask = 0xff,
385 .descr = "Nuvoton NCT5104D/NCT6102D/NCT6106D (rev. B+)",
386 .devices = nct5104_devices,
389 .vendor = SUPERIO_VENDOR_NUVOTON, .devid = 0xc500, .mask = 0xff,
390 .descr = "Nuvoton NCT6779",
391 .devices = nvt_devices,
394 .vendor = SUPERIO_VENDOR_NUVOTON, .devid = 0xc800, .mask = 0xff,
395 .descr = "Nuvoton NCT6791",
396 .devices = nvt_devices,
399 .vendor = SUPERIO_VENDOR_NUVOTON, .devid = 0xc900, .mask = 0xff,
400 .descr = "Nuvoton NCT6792",
401 .devices = nvt_devices,
404 .vendor = SUPERIO_VENDOR_NUVOTON, .devid = 0xd100, .mask = 0xff,
405 .descr = "Nuvoton NCT6793",
406 .devices = nvt_devices,
409 .vendor = SUPERIO_VENDOR_NUVOTON, .devid = 0xd300, .mask = 0xff,
410 .descr = "Nuvoton NCT6795",
411 .devices = nvt_devices,
417 devtype_to_str(superio_dev_type_t type)
420 case SUPERIO_DEV_NONE:
422 case SUPERIO_DEV_HWM:
424 case SUPERIO_DEV_WDT:
426 case SUPERIO_DEV_GPIO:
428 case SUPERIO_DEV_MAX:
435 superio_detect(device_t dev, bool claim, struct siosc *sc)
437 struct resource *res;
446 error = bus_get_resource(dev, SYS_RES_IOPORT, 0, &port, &count);
449 if (port > UINT16_MAX || count < NUMPORTS) {
450 device_printf(dev, "unexpected I/O range size\n");
455 * Make a temporary resource reservation for hardware probing.
456 * If we can't get the resources we need then
457 * we need to abort. Possibly this indicates
458 * the resources were used by another device
459 * in which case the probe would have failed anyhow.
462 res = bus_alloc_resource_any(dev, SYS_RES_IOPORT, &rid, RF_ACTIVE);
465 device_printf(dev, "failed to allocate I/O resource\n");
469 for (m = 0; methods_table[m] != NULL; m++) {
470 methods_table[m]->enter(res, port);
471 if (methods_table[m]->vendor == SUPERIO_VENDOR_ITE) {
472 devid = sio_readw(res, 0x20);
473 revid = sio_read(res, 0x22);
474 } else if (methods_table[m]->vendor == SUPERIO_VENDOR_NUVOTON) {
475 devid = sio_read(res, 0x20);
476 revid = sio_read(res, 0x21);
477 devid = (devid << 8) | revid;
481 methods_table[m]->exit(res, port);
482 for (i = 0; superio_table[i].vendor != 0; i++) {
485 mask = superio_table[i].mask;
486 if (superio_table[i].vendor !=
487 methods_table[m]->vendor)
489 if ((superio_table[i].devid & ~mask) != (devid & ~mask))
494 /* Found a matching SuperIO entry. */
495 if (superio_table[i].vendor != 0)
499 if (methods_table[m] == NULL)
503 if (!claim || error != 0) {
504 bus_release_resource(dev, SYS_RES_IOPORT, rid, res);
508 sc->methods = methods_table[m];
509 sc->vendor = sc->methods->vendor;
510 sc->known_devices = superio_table[i].devices;
517 KASSERT(sc->vendor == SUPERIO_VENDOR_ITE ||
518 sc->vendor == SUPERIO_VENDOR_NUVOTON,
519 ("Only ITE and Nuvoton SuperIO-s are supported"));
521 sc->enable_reg = 0x30;
522 sc->current_ldn = 0xff; /* no device should have this */
524 if (superio_table[i].descr != NULL) {
525 device_set_desc(dev, superio_table[i].descr);
526 } else if (sc->vendor == SUPERIO_VENDOR_ITE) {
529 snprintf(descr, sizeof(descr),
530 "ITE IT%4x SuperIO (revision 0x%02x)",
531 sc->devid, sc->revid);
532 device_set_desc_copy(dev, descr);
538 superio_identify(driver_t *driver, device_t parent)
544 * Don't create child devices if any already exist.
545 * Those could be created via isa hints or if this
546 * driver is loaded, unloaded and then loaded again.
548 if (device_find_child(parent, "superio", -1)) {
550 printf("superio: device(s) already created\n");
555 * Create a child for each candidate port.
556 * It would be nice if we could somehow clean up those
557 * that this driver fails to probe.
559 for (i = 0; ports_table[i] != 0; i++) {
560 child = BUS_ADD_CHILD(parent, ISA_ORDER_SPECULATIVE,
563 device_printf(parent, "failed to add superio child\n");
566 bus_set_resource(child, SYS_RES_IOPORT, 0, ports_table[i], 2);
567 if (superio_detect(child, false, NULL) != 0)
568 device_delete_child(parent, child);
573 superio_probe(device_t dev)
578 /* Make sure we do not claim some ISA PNP device. */
579 if (isa_get_logicalid(dev) != 0)
583 * XXX We can populate the softc now only because we return
586 sc = device_get_softc(dev);
587 error = superio_detect(dev, true, sc);
590 return (BUS_PROBE_SPECIFIC);
594 superio_add_known_child(device_t dev, superio_dev_type_t type, uint8_t ldn)
596 struct siosc *sc = device_get_softc(dev);
597 struct superio_devinfo *dinfo;
600 child = BUS_ADD_CHILD(dev, 0, NULL, -1);
602 device_printf(dev, "failed to add child for ldn %d, type %s\n",
603 ldn, devtype_to_str(type));
606 dinfo = device_get_ivars(child);
610 dinfo->iobase = sio_ldn_readw(sc, ldn, 0x60);
611 dinfo->iobase2 = sio_ldn_readw(sc, ldn, 0x62);
612 dinfo->irq = sio_ldn_readw(sc, ldn, 0x70);
613 dinfo->dma = sio_ldn_readw(sc, ldn, 0x74);
615 STAILQ_INSERT_TAIL(&sc->devlist, dinfo, link);
619 superio_attach(device_t dev)
621 struct siosc *sc = device_get_softc(dev);
624 mtx_init(&sc->conf_lock, device_get_nameunit(dev), "superio", MTX_DEF);
625 STAILQ_INIT(&sc->devlist);
627 for (i = 0; sc->known_devices[i].type != SUPERIO_DEV_NONE; i++) {
628 superio_add_known_child(dev, sc->known_devices[i].type,
629 sc->known_devices[i].ldn);
632 bus_generic_probe(dev);
633 bus_generic_attach(dev);
635 sc->chardev = make_dev(&superio_cdevsw, device_get_unit(dev),
636 UID_ROOT, GID_WHEEL, 0600, "superio%d", device_get_unit(dev));
637 if (sc->chardev == NULL)
638 device_printf(dev, "failed to create character device\n");
640 sc->chardev->si_drv1 = sc;
645 superio_detach(device_t dev)
647 struct siosc *sc = device_get_softc(dev);
650 error = bus_generic_detach(dev);
653 if (sc->chardev != NULL)
654 destroy_dev(sc->chardev);
655 device_delete_children(dev);
656 bus_release_resource(dev, SYS_RES_IOPORT, sc->io_rid, sc->io_res);
657 mtx_destroy(&sc->conf_lock);
662 superio_add_child(device_t dev, u_int order, const char *name, int unit)
664 struct superio_devinfo *dinfo;
667 child = device_add_child_ordered(dev, order, name, unit);
670 dinfo = malloc(sizeof(*dinfo), M_DEVBUF, M_NOWAIT | M_ZERO);
672 device_delete_child(dev, child);
676 dinfo->type = SUPERIO_DEV_NONE;
678 resource_list_init(&dinfo->resources);
679 device_set_ivars(child, dinfo);
684 superio_read_ivar(device_t dev, device_t child, int which, uintptr_t *result)
686 struct superio_devinfo *dinfo;
688 dinfo = device_get_ivars(child);
690 case SUPERIO_IVAR_LDN:
691 *result = dinfo->ldn;
693 case SUPERIO_IVAR_TYPE:
694 *result = dinfo->type;
696 case SUPERIO_IVAR_IOBASE:
697 *result = dinfo->iobase;
699 case SUPERIO_IVAR_IOBASE2:
700 *result = dinfo->iobase2;
702 case SUPERIO_IVAR_IRQ:
703 *result = dinfo->irq;
705 case SUPERIO_IVAR_DMA:
706 *result = dinfo->dma;
715 superio_write_ivar(device_t dev, device_t child, int which, uintptr_t value)
719 case SUPERIO_IVAR_LDN:
720 case SUPERIO_IVAR_TYPE:
721 case SUPERIO_IVAR_IOBASE:
722 case SUPERIO_IVAR_IOBASE2:
723 case SUPERIO_IVAR_IRQ:
724 case SUPERIO_IVAR_DMA:
731 static struct resource_list *
732 superio_get_resource_list(device_t dev, device_t child)
734 struct superio_devinfo *dinfo = device_get_ivars(child);
736 return (&dinfo->resources);
740 superio_printf(struct superio_devinfo *dinfo, const char *fmt, ...)
745 retval = printf("superio:%s@ldn%0x2x: ",
746 devtype_to_str(dinfo->type), dinfo->ldn);
748 retval += vprintf(fmt, ap);
754 superio_child_detached(device_t dev, device_t child)
756 struct superio_devinfo *dinfo;
757 struct resource_list *rl;
759 dinfo = device_get_ivars(child);
760 rl = &dinfo->resources;
762 if (resource_list_release_active(rl, dev, child, SYS_RES_IRQ) != 0)
763 superio_printf(dinfo, "Device leaked IRQ resources\n");
764 if (resource_list_release_active(rl, dev, child, SYS_RES_MEMORY) != 0)
765 superio_printf(dinfo, "Device leaked memory resources\n");
766 if (resource_list_release_active(rl, dev, child, SYS_RES_IOPORT) != 0)
767 superio_printf(dinfo, "Device leaked I/O resources\n");
771 superio_child_location_str(device_t parent, device_t child, char *buf,
776 ldn = superio_get_ldn(child);
777 snprintf(buf, buflen, "ldn=0x%02x", ldn);
782 superio_child_pnp_str(device_t parent, device_t child, char *buf,
785 superio_dev_type_t type;
787 type = superio_get_type(child);
788 snprintf(buf, buflen, "type=%s", devtype_to_str(type));
793 superio_print_child(device_t parent, device_t child)
795 superio_dev_type_t type;
799 ldn = superio_get_ldn(child);
800 type = superio_get_type(child);
802 retval = bus_print_child_header(parent, child);
803 retval += printf(" at %s ldn 0x%02x", devtype_to_str(type), ldn);
804 retval += bus_print_child_footer(parent, child);
810 superio_vendor(device_t dev)
812 device_t sio_dev = device_get_parent(dev);
813 struct siosc *sc = device_get_softc(sio_dev);
819 superio_devid(device_t dev)
821 device_t sio_dev = device_get_parent(dev);
822 struct siosc *sc = device_get_softc(sio_dev);
828 superio_revid(device_t dev)
830 device_t sio_dev = device_get_parent(dev);
831 struct siosc *sc = device_get_softc(sio_dev);
837 superio_read(device_t dev, uint8_t reg)
839 device_t sio_dev = device_get_parent(dev);
840 struct siosc *sc = device_get_softc(sio_dev);
841 struct superio_devinfo *dinfo = device_get_ivars(dev);
845 v = sio_ldn_read(sc, dinfo->ldn, reg);
851 superio_write(device_t dev, uint8_t reg, uint8_t val)
853 device_t sio_dev = device_get_parent(dev);
854 struct siosc *sc = device_get_softc(sio_dev);
855 struct superio_devinfo *dinfo = device_get_ivars(dev);
858 sio_ldn_write(sc, dinfo->ldn, reg, val);
863 superio_dev_enabled(device_t dev, uint8_t mask)
865 device_t sio_dev = device_get_parent(dev);
866 struct siosc *sc = device_get_softc(sio_dev);
867 struct superio_devinfo *dinfo = device_get_ivars(dev);
870 /* GPIO device is always active in ITE chips. */
871 if (sc->vendor == SUPERIO_VENDOR_ITE && dinfo->ldn == 7)
874 v = superio_read(dev, sc->enable_reg);
875 return ((v & mask) != 0);
879 superio_dev_enable(device_t dev, uint8_t mask)
881 device_t sio_dev = device_get_parent(dev);
882 struct siosc *sc = device_get_softc(sio_dev);
883 struct superio_devinfo *dinfo = device_get_ivars(dev);
886 /* GPIO device is always active in ITE chips. */
887 if (sc->vendor == SUPERIO_VENDOR_ITE && dinfo->ldn == 7)
891 v = sio_ldn_read(sc, dinfo->ldn, sc->enable_reg);
893 sio_ldn_write(sc, dinfo->ldn, sc->enable_reg, v);
898 superio_dev_disable(device_t dev, uint8_t mask)
900 device_t sio_dev = device_get_parent(dev);
901 struct siosc *sc = device_get_softc(sio_dev);
902 struct superio_devinfo *dinfo = device_get_ivars(dev);
905 /* GPIO device is always active in ITE chips. */
906 if (sc->vendor == SUPERIO_VENDOR_ITE && dinfo->ldn == 7)
910 v = sio_ldn_read(sc, dinfo->ldn, sc->enable_reg);
912 sio_ldn_write(sc, dinfo->ldn, sc->enable_reg, v);
917 superio_find_dev(device_t superio, superio_dev_type_t type, int ldn)
919 struct siosc *sc = device_get_softc(superio);
920 struct superio_devinfo *dinfo;
922 if (ldn < -1 || ldn > UINT8_MAX)
923 return (NULL); /* ERANGE */
924 if (type == SUPERIO_DEV_NONE && ldn == -1)
925 return (NULL); /* EINVAL */
927 STAILQ_FOREACH(dinfo, &sc->devlist, link) {
928 if (ldn != -1 && dinfo->ldn != ldn)
930 if (type != SUPERIO_DEV_NONE && dinfo->type != type)
938 superio_ioctl(struct cdev *dev, u_long cmd, caddr_t data, int flags,
942 struct superiocmd *s;
945 s = (struct superiocmd *)data;
947 case SUPERIO_CR_READ:
949 s->val = sio_ldn_read(sc, s->ldn, s->cr);
952 case SUPERIO_CR_WRITE:
954 sio_ldn_write(sc, s->ldn, s->cr, s->val);
962 static devclass_t superio_devclass;
964 static device_method_t superio_methods[] = {
965 DEVMETHOD(device_identify, superio_identify),
966 DEVMETHOD(device_probe, superio_probe),
967 DEVMETHOD(device_attach, superio_attach),
968 DEVMETHOD(device_detach, superio_detach),
969 DEVMETHOD(device_shutdown, bus_generic_shutdown),
970 DEVMETHOD(device_suspend, bus_generic_suspend),
971 DEVMETHOD(device_resume, bus_generic_resume),
973 DEVMETHOD(bus_add_child, superio_add_child),
974 DEVMETHOD(bus_child_detached, superio_child_detached),
975 DEVMETHOD(bus_child_location_str, superio_child_location_str),
976 DEVMETHOD(bus_child_pnpinfo_str, superio_child_pnp_str),
977 DEVMETHOD(bus_print_child, superio_print_child),
978 DEVMETHOD(bus_read_ivar, superio_read_ivar),
979 DEVMETHOD(bus_write_ivar, superio_write_ivar),
980 DEVMETHOD(bus_get_resource_list, superio_get_resource_list),
981 DEVMETHOD(bus_alloc_resource, bus_generic_rl_alloc_resource),
982 DEVMETHOD(bus_release_resource, bus_generic_rl_release_resource),
983 DEVMETHOD(bus_set_resource, bus_generic_rl_set_resource),
984 DEVMETHOD(bus_get_resource, bus_generic_rl_get_resource),
985 DEVMETHOD(bus_delete_resource, bus_generic_rl_delete_resource),
986 DEVMETHOD(bus_activate_resource, bus_generic_activate_resource),
987 DEVMETHOD(bus_deactivate_resource, bus_generic_deactivate_resource),
988 DEVMETHOD(bus_setup_intr, bus_generic_setup_intr),
989 DEVMETHOD(bus_teardown_intr, bus_generic_teardown_intr),
994 static driver_t superio_driver = {
1000 DRIVER_MODULE(superio, isa, superio_driver, superio_devclass, 0, 0);
1001 MODULE_VERSION(superio, 1);