Lines Matching +full:sc +full:- +full:resource
1 /*-
2 * SPDX-License-Identifier: BSD-2-Clause
44 #include <machine/resource.h>
53 typedef void (*sio_conf_enter_f)(struct resource*, uint16_t);
54 typedef void (*sio_conf_exit_f)(struct resource*, uint16_t);
82 struct resource* io_res;
108 sio_read(struct resource* res, uint8_t reg) in sio_read()
114 /* Read a word from two one-byte registers, big endian. */
116 sio_readw(struct resource* res, uint8_t reg) in sio_readw()
127 sio_write(struct resource* res, uint8_t reg, uint8_t val) in sio_write()
134 sio_ldn_select(struct siosc *sc, uint8_t ldn) in sio_ldn_select() argument
136 mtx_assert(&sc->conf_lock, MA_OWNED); in sio_ldn_select()
137 if (ldn == sc->current_ldn) in sio_ldn_select()
139 sio_write(sc->io_res, sc->ldn_reg, ldn); in sio_ldn_select()
140 sc->current_ldn = ldn; in sio_ldn_select()
144 sio_ldn_read(struct siosc *sc, uint8_t ldn, uint8_t reg) in sio_ldn_read() argument
146 mtx_assert(&sc->conf_lock, MA_OWNED); in sio_ldn_read()
147 if (reg >= sc->enable_reg) { in sio_ldn_read()
148 sio_ldn_select(sc, ldn); in sio_ldn_read()
149 KASSERT(sc->current_ldn == ldn, ("sio_ldn_select failed")); in sio_ldn_read()
151 return (sio_read(sc->io_res, reg)); in sio_ldn_read()
155 sio_ldn_readw(struct siosc *sc, uint8_t ldn, uint8_t reg) in sio_ldn_readw() argument
157 mtx_assert(&sc->conf_lock, MA_OWNED); in sio_ldn_readw()
158 if (reg >= sc->enable_reg) { in sio_ldn_readw()
159 sio_ldn_select(sc, ldn); in sio_ldn_readw()
160 KASSERT(sc->current_ldn == ldn, ("sio_ldn_select failed")); in sio_ldn_readw()
162 return (sio_readw(sc->io_res, reg)); in sio_ldn_readw()
166 sio_ldn_write(struct siosc *sc, uint8_t ldn, uint8_t reg, uint8_t val) in sio_ldn_write() argument
168 mtx_assert(&sc->conf_lock, MA_OWNED); in sio_ldn_write()
169 if (reg <= sc->ldn_reg) { in sio_ldn_write()
173 sio_ldn_select(sc, ldn); in sio_ldn_write()
174 KASSERT(sc->current_ldn == ldn, ("sio_ldn_select failed")); in sio_ldn_write()
175 sio_write(sc->io_res, reg, val); in sio_ldn_write()
179 sio_conf_enter(struct siosc *sc) in sio_conf_enter() argument
181 mtx_lock(&sc->conf_lock); in sio_conf_enter()
182 sc->methods->enter(sc->io_res, sc->io_port); in sio_conf_enter()
186 sio_conf_exit(struct siosc *sc) in sio_conf_exit() argument
188 sc->methods->exit(sc->io_res, sc->io_port); in sio_conf_exit()
189 sc->current_ldn = 0xff; in sio_conf_exit()
190 mtx_unlock(&sc->conf_lock); in sio_conf_exit()
194 ite_conf_enter(struct resource* res, uint16_t port) in ite_conf_enter()
203 ite_conf_exit(struct resource* res, uint16_t port) in ite_conf_exit()
215 nvt_conf_enter(struct resource* res, uint16_t port) in nvt_conf_enter()
222 nvt_conf_exit(struct resource* res, uint16_t port) in nvt_conf_exit()
234 fintek_conf_enter(struct resource* res, uint16_t port) in fintek_conf_enter()
241 fintek_conf_exit(struct resource* res, uint16_t port) in fintek_conf_exit()
417 .descr = "Winbond 83627DHG-P",
422 .descr = "Winbond 83667HG-B",
447 .descr = "Nuvoton NCT6796D-E",
512 superio_detect(device_t dev, bool claim, struct siosc *sc) in superio_detect() argument
514 struct resource *res; in superio_detect()
533 * Make a temporary resource reservation for hardware probing. in superio_detect()
543 device_printf(dev, "failed to allocate I/O resource\n"); in superio_detect()
553 methods_table[m]->enter(res, port); in superio_detect()
554 if (methods_table[m]->vendor == SUPERIO_VENDOR_ITE) { in superio_detect()
557 } else if (methods_table[m]->vendor == SUPERIO_VENDOR_NUVOTON) { in superio_detect()
561 } else if (methods_table[m]->vendor == SUPERIO_VENDOR_FINTEK) { in superio_detect()
568 methods_table[m]->exit(res, port); in superio_detect()
574 methods_table[m]->vendor) in superio_detect()
597 sc->methods = methods_table[m]; in superio_detect()
598 sc->vendor = sc->methods->vendor; in superio_detect()
599 sc->known_devices = superio_table[i].devices; in superio_detect()
600 sc->io_res = res; in superio_detect()
601 sc->io_rid = rid; in superio_detect()
602 sc->io_port = port; in superio_detect()
603 sc->devid = devid; in superio_detect()
604 sc->revid = revid; in superio_detect()
605 sc->extid = superio_table[i].extid; in superio_detect()
607 KASSERT(sc->vendor == SUPERIO_VENDOR_ITE || in superio_detect()
608 sc->vendor == SUPERIO_VENDOR_NUVOTON || in superio_detect()
609 sc->vendor == SUPERIO_VENDOR_FINTEK, in superio_detect()
610 ("Only ITE, Nuvoton and Fintek SuperIO-s are supported")); in superio_detect()
611 sc->ldn_reg = 0x07; in superio_detect()
612 sc->enable_reg = 0x30; /* FIXME enable_reg not used by nctgpio(4). */ in superio_detect()
613 sc->current_ldn = 0xff; /* no device should have this */ in superio_detect()
617 } else if (sc->vendor == SUPERIO_VENDOR_ITE) { in superio_detect()
620 sc->devid, sc->revid); in superio_detect()
649 "superio", -1); in superio_identify()
663 struct siosc *sc; in superio_probe() local
674 sc = device_get_softc(dev); in superio_probe()
675 error = superio_detect(dev, true, sc); in superio_probe()
684 struct siosc *sc = device_get_softc(dev); in superio_add_known_child() local
695 dinfo->ldn = ldn; in superio_add_known_child()
696 dinfo->type = type; in superio_add_known_child()
697 sio_conf_enter(sc); in superio_add_known_child()
698 dinfo->iobase = sio_ldn_readw(sc, ldn, 0x60); in superio_add_known_child()
699 dinfo->iobase2 = sio_ldn_readw(sc, ldn, 0x62); in superio_add_known_child()
700 dinfo->irq = sio_ldn_readw(sc, ldn, 0x70); in superio_add_known_child()
701 dinfo->dma = sio_ldn_readw(sc, ldn, 0x74); in superio_add_known_child()
702 sio_conf_exit(sc); in superio_add_known_child()
703 STAILQ_INSERT_TAIL(&sc->devlist, dinfo, link); in superio_add_known_child()
709 struct siosc *sc = device_get_softc(dev); in superio_attach() local
712 mtx_init(&sc->conf_lock, device_get_nameunit(dev), "superio", MTX_DEF); in superio_attach()
713 STAILQ_INIT(&sc->devlist); in superio_attach()
715 for (i = 0; sc->known_devices[i].type != SUPERIO_DEV_NONE; i++) { in superio_attach()
716 superio_add_known_child(dev, sc->known_devices[i].type, in superio_attach()
717 sc->known_devices[i].ldn); in superio_attach()
723 sc->chardev = make_dev(&superio_cdevsw, device_get_unit(dev), in superio_attach()
725 if (sc->chardev == NULL) in superio_attach()
728 sc->chardev->si_drv1 = sc; in superio_attach()
735 struct siosc *sc = device_get_softc(dev); in superio_detach() local
741 if (sc->chardev != NULL) in superio_detach()
742 destroy_dev(sc->chardev); in superio_detach()
743 bus_release_resource(dev, SYS_RES_IOPORT, sc->io_rid, sc->io_res); in superio_detach()
744 mtx_destroy(&sc->conf_lock); in superio_detach()
762 dinfo->ldn = 0xff; in superio_add_child()
763 dinfo->type = SUPERIO_DEV_NONE; in superio_add_child()
764 dinfo->dev = child; in superio_add_child()
765 resource_list_init(&dinfo->resources); in superio_add_child()
778 resource_list_free(&dinfo->resources); in superio_child_deleted()
790 *result = dinfo->ldn; in superio_read_ivar()
793 *result = dinfo->type; in superio_read_ivar()
796 *result = dinfo->iobase; in superio_read_ivar()
799 *result = dinfo->iobase2; in superio_read_ivar()
802 *result = dinfo->irq; in superio_read_ivar()
805 *result = dinfo->dma; in superio_read_ivar()
835 return (&dinfo->resources); in superio_get_resource_list()
845 devtype_to_str(dinfo->type), dinfo->ldn); in superio_printf()
859 rl = &dinfo->resources; in superio_child_detached()
910 struct siosc *sc = device_get_softc(sio_dev); in superio_vendor() local
912 return (sc->vendor); in superio_vendor()
919 struct siosc *sc = device_get_softc(sio_dev); in superio_devid() local
921 return (sc->devid); in superio_devid()
928 struct siosc *sc = device_get_softc(sio_dev); in superio_revid() local
930 return (sc->revid); in superio_revid()
937 struct siosc *sc = device_get_softc(sio_dev); in superio_extid() local
939 return (sc->extid); in superio_extid()
946 struct siosc *sc = device_get_softc(sio_dev); in superio_ldn_read() local
949 sio_conf_enter(sc); in superio_ldn_read()
950 v = sio_ldn_read(sc, ldn, reg); in superio_ldn_read()
951 sio_conf_exit(sc); in superio_ldn_read()
960 return (superio_ldn_read(dev, dinfo->ldn, reg)); in superio_read()
967 struct siosc *sc = device_get_softc(sio_dev); in superio_ldn_write() local
969 sio_conf_enter(sc); in superio_ldn_write()
970 sio_ldn_write(sc, ldn, reg, val); in superio_ldn_write()
971 sio_conf_exit(sc); in superio_ldn_write()
979 return (superio_ldn_write(dev, dinfo->ldn, reg, val)); in superio_write()
986 struct siosc *sc = device_get_softc(sio_dev); in superio_dev_enabled() local
991 if (sc->vendor == SUPERIO_VENDOR_ITE && dinfo->ldn == 7) in superio_dev_enabled()
994 v = superio_read(dev, sc->enable_reg); /* FIXME enable_reg not used by nctgpio(4). */ in superio_dev_enabled()
1002 struct siosc *sc = device_get_softc(sio_dev); in superio_dev_enable() local
1007 if (sc->vendor == SUPERIO_VENDOR_ITE && dinfo->ldn == 7) in superio_dev_enable()
1010 sio_conf_enter(sc); in superio_dev_enable()
1011 v = sio_ldn_read(sc, dinfo->ldn, sc->enable_reg); in superio_dev_enable()
1013 sio_ldn_write(sc, dinfo->ldn, sc->enable_reg, v); in superio_dev_enable()
1014 sio_conf_exit(sc); in superio_dev_enable()
1021 struct siosc *sc = device_get_softc(sio_dev); in superio_dev_disable() local
1026 if (sc->vendor == SUPERIO_VENDOR_ITE && dinfo->ldn == 7) in superio_dev_disable()
1029 sio_conf_enter(sc); in superio_dev_disable()
1030 v = sio_ldn_read(sc, dinfo->ldn, sc->enable_reg); in superio_dev_disable()
1032 sio_ldn_write(sc, dinfo->ldn, sc->enable_reg, v); in superio_dev_disable()
1033 sio_conf_exit(sc); in superio_dev_disable()
1039 struct siosc *sc = device_get_softc(superio); in superio_find_dev() local
1042 if (ldn < -1 || ldn > UINT8_MAX) in superio_find_dev()
1044 if (type == SUPERIO_DEV_NONE && ldn == -1) in superio_find_dev()
1047 STAILQ_FOREACH(dinfo, &sc->devlist, link) { in superio_find_dev()
1048 if (ldn != -1 && dinfo->ldn != ldn) in superio_find_dev()
1050 if (type != SUPERIO_DEV_NONE && dinfo->type != type) in superio_find_dev()
1052 return (dinfo->dev); in superio_find_dev()
1061 struct siosc *sc; in superio_ioctl() local
1064 sc = dev->si_drv1; in superio_ioctl()
1068 sio_conf_enter(sc); in superio_ioctl()
1069 s->val = sio_ldn_read(sc, s->ldn, s->cr); in superio_ioctl()
1070 sio_conf_exit(sc); in superio_ioctl()
1073 sio_conf_enter(sc); in superio_ioctl()
1074 sio_ldn_write(sc, s->ldn, s->cr, s->val); in superio_ioctl()
1075 sio_conf_exit(sc); in superio_ioctl()