Index: stable/11/sys/dev/gpio/bytgpio.c =================================================================== --- stable/11/sys/dev/gpio/bytgpio.c (revision 309374) +++ stable/11/sys/dev/gpio/bytgpio.c (revision 309375) @@ -1,435 +1,679 @@ /*- * Copyright (c) 2016 Oleksandr Tymoshenko * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #include __FBSDID("$FreeBSD$"); #include "opt_acpi.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include "gpio_if.h" /** * Macros for driver mutex locking */ #define BYTGPIO_LOCK(_sc) mtx_lock_spin(&(_sc)->sc_mtx) #define BYTGPIO_UNLOCK(_sc) mtx_unlock_spin(&(_sc)->sc_mtx) #define BYTGPIO_LOCK_INIT(_sc) \ mtx_init(&_sc->sc_mtx, device_get_nameunit((_sc)->sc_dev), \ "bytgpio", MTX_SPIN) #define BYTGPIO_LOCK_DESTROY(_sc) mtx_destroy(&(_sc)->sc_mtx) #define BYTGPIO_ASSERT_LOCKED(_sc) mtx_assert(&(_sc)->sc_mtx, MA_OWNED) #define BYTGPIO_ASSERT_UNLOCKED(_sc) mtx_assert(&(_sc)->sc_mtx, MA_NOTOWNED) +struct pinmap_info { + int reg; + int pad_func; +}; + +/* Ignore function check, no info is available at the moment */ +#define PADCONF_FUNC_ANY -1 + +#define GPIO_PIN_MAP(r, f) { .reg = (r), .pad_func = (f) } + struct bytgpio_softc { ACPI_HANDLE sc_handle; device_t sc_dev; device_t sc_busdev; struct mtx sc_mtx; int sc_mem_rid; struct resource *sc_mem_res; int sc_npins; const char* sc_bank_prefix; - const int *sc_pinpad_map; + const struct pinmap_info *sc_pinpad_map; + /* List of current functions for pads shared by GPIO */ + int *sc_pad_funcs; }; static int bytgpio_probe(device_t dev); static int bytgpio_attach(device_t dev); +static int bytgpio_detach(device_t dev); -#define SCORE_UID 1 -#define SCORE_BANK_PREFIX "GPIO_S0_SC" -const int bytgpio_score_pins[] = { - 85, 89, 93, 96, 99, 102, 98, 101, 34, 37, 36, 38, 39, 35, 40, - 84, 62, 61, 64, 59, 54, 56, 60, 55, 63, 57, 51, 50, 53, 47, - 52, 49, 48, 43, 46, 41, 45, 42, 58, 44, 95, 105, 70, 68, 67, - 66, 69, 71, 65, 72, 86, 90, 88, 92, 103, 77, 79, 83, 78, 81, - 80, 82, 13, 12, 15, 14, 17, 18, 19, 16, 2, 1, 0, 4, 6, 7, 9, - 8, 33, 32, 31, 30, 29, 27, 25, 28, 26, 23, 21, 20, 24, 22, 5, - 3, 10, 11, 106, 87, 91, 104, 97, 100 +#define SCORE_UID 1 +#define SCORE_BANK_PREFIX "GPIO_S0_SC" +const struct pinmap_info bytgpio_score_pins[] = { + GPIO_PIN_MAP(85, 0), + GPIO_PIN_MAP(89, 0), + GPIO_PIN_MAP(93, 0), + GPIO_PIN_MAP(96, 0), + GPIO_PIN_MAP(99, 0), + GPIO_PIN_MAP(102, 0), + GPIO_PIN_MAP(98, 0), + GPIO_PIN_MAP(101, 0), + GPIO_PIN_MAP(34, 0), + GPIO_PIN_MAP(37, 0), + GPIO_PIN_MAP(36, 0), + GPIO_PIN_MAP(38, 0), + GPIO_PIN_MAP(39, 0), + GPIO_PIN_MAP(35, 0), + GPIO_PIN_MAP(40, 0), + GPIO_PIN_MAP(84, 0), + GPIO_PIN_MAP(62, 0), + GPIO_PIN_MAP(61, 0), + GPIO_PIN_MAP(64, 0), + GPIO_PIN_MAP(59, 0), + GPIO_PIN_MAP(54, 0), + GPIO_PIN_MAP(56, 0), + GPIO_PIN_MAP(60, 0), + GPIO_PIN_MAP(55, 0), + GPIO_PIN_MAP(63, 0), + GPIO_PIN_MAP(57, 0), + GPIO_PIN_MAP(51, 0), + GPIO_PIN_MAP(50, 0), + GPIO_PIN_MAP(53, 0), + GPIO_PIN_MAP(47, 0), + GPIO_PIN_MAP(52, 0), + GPIO_PIN_MAP(49, 0), + GPIO_PIN_MAP(48, 0), + GPIO_PIN_MAP(43, 0), + GPIO_PIN_MAP(46, 0), + GPIO_PIN_MAP(41, 0), + GPIO_PIN_MAP(45, 0), + GPIO_PIN_MAP(42, 0), + GPIO_PIN_MAP(58, 0), + GPIO_PIN_MAP(44, 0), + GPIO_PIN_MAP(95, 0), + GPIO_PIN_MAP(105, 0), + GPIO_PIN_MAP(70, 0), + GPIO_PIN_MAP(68, 0), + GPIO_PIN_MAP(67, 0), + GPIO_PIN_MAP(66, 0), + GPIO_PIN_MAP(69, 0), + GPIO_PIN_MAP(71, 0), + GPIO_PIN_MAP(65, 0), + GPIO_PIN_MAP(72, 0), + GPIO_PIN_MAP(86, 0), + GPIO_PIN_MAP(90, 0), + GPIO_PIN_MAP(88, 0), + GPIO_PIN_MAP(92, 0), + GPIO_PIN_MAP(103, 0), + GPIO_PIN_MAP(77, 0), + GPIO_PIN_MAP(79, 0), + GPIO_PIN_MAP(83, 0), + GPIO_PIN_MAP(78, 0), + GPIO_PIN_MAP(81, 0), + GPIO_PIN_MAP(80, 0), + GPIO_PIN_MAP(82, 0), + GPIO_PIN_MAP(13, 0), + GPIO_PIN_MAP(12, 0), + GPIO_PIN_MAP(15, 0), + GPIO_PIN_MAP(14, 0), + GPIO_PIN_MAP(17, 0), + GPIO_PIN_MAP(18, 0), + GPIO_PIN_MAP(19, 0), + GPIO_PIN_MAP(16, 0), + GPIO_PIN_MAP(2, 0), + GPIO_PIN_MAP(1, 0), + GPIO_PIN_MAP(0, 0), + GPIO_PIN_MAP(4, 0), + GPIO_PIN_MAP(6, 0), + GPIO_PIN_MAP(7, 0), + GPIO_PIN_MAP(9, 0), + GPIO_PIN_MAP(8, 0), + GPIO_PIN_MAP(33, 0), + GPIO_PIN_MAP(32, 0), + GPIO_PIN_MAP(31, 0), + GPIO_PIN_MAP(30, 0), + GPIO_PIN_MAP(29, 0), + GPIO_PIN_MAP(27, 0), + GPIO_PIN_MAP(25, 0), + GPIO_PIN_MAP(28, 0), + GPIO_PIN_MAP(26, 0), + GPIO_PIN_MAP(23, 0), + GPIO_PIN_MAP(21, 0), + GPIO_PIN_MAP(20, 0), + GPIO_PIN_MAP(24, 0), + GPIO_PIN_MAP(22, 0), + GPIO_PIN_MAP(5, 1), + GPIO_PIN_MAP(3, 1), + GPIO_PIN_MAP(10, 0), + GPIO_PIN_MAP(11, 0), + GPIO_PIN_MAP(106, 0), + GPIO_PIN_MAP(87, 0), + GPIO_PIN_MAP(91, 0), + GPIO_PIN_MAP(104, 0), + GPIO_PIN_MAP(97, 0), + GPIO_PIN_MAP(100, 0) }; -#define SCORE_PINS nitems(bytgpio_score_pins) -#define NCORE_UID 2 -#define NCORE_BANK_PREFIX "GPIO_S0_NC" -const int bytgpio_ncore_pins[] = { - 19, 18, 17, 20, 21, 22, 24, 25, 23, 16, 14, 15, 12, 26, 27, - 1, 4, 8, 11, 0, 3, 6, 10, 13, 2, 5, 9, 7 +#define SCORE_PINS nitems(bytgpio_score_pins) + +#define NCORE_UID 2 +#define NCORE_BANK_PREFIX "GPIO_S0_NC" +const struct pinmap_info bytgpio_ncore_pins[] = { + GPIO_PIN_MAP(19, PADCONF_FUNC_ANY), + GPIO_PIN_MAP(18, PADCONF_FUNC_ANY), + GPIO_PIN_MAP(17, PADCONF_FUNC_ANY), + GPIO_PIN_MAP(20, PADCONF_FUNC_ANY), + GPIO_PIN_MAP(21, PADCONF_FUNC_ANY), + GPIO_PIN_MAP(22, PADCONF_FUNC_ANY), + GPIO_PIN_MAP(24, PADCONF_FUNC_ANY), + GPIO_PIN_MAP(25, PADCONF_FUNC_ANY), + GPIO_PIN_MAP(23, PADCONF_FUNC_ANY), + GPIO_PIN_MAP(16, PADCONF_FUNC_ANY), + GPIO_PIN_MAP(14, PADCONF_FUNC_ANY), + GPIO_PIN_MAP(15, PADCONF_FUNC_ANY), + GPIO_PIN_MAP(12, PADCONF_FUNC_ANY), + GPIO_PIN_MAP(26, PADCONF_FUNC_ANY), + GPIO_PIN_MAP(27, PADCONF_FUNC_ANY), + GPIO_PIN_MAP(1, PADCONF_FUNC_ANY), + GPIO_PIN_MAP(4, PADCONF_FUNC_ANY), + GPIO_PIN_MAP(8, PADCONF_FUNC_ANY), + GPIO_PIN_MAP(11, PADCONF_FUNC_ANY), + GPIO_PIN_MAP(0, PADCONF_FUNC_ANY), + GPIO_PIN_MAP(3, PADCONF_FUNC_ANY), + GPIO_PIN_MAP(6, PADCONF_FUNC_ANY), + GPIO_PIN_MAP(10, PADCONF_FUNC_ANY), + GPIO_PIN_MAP(13, PADCONF_FUNC_ANY), + GPIO_PIN_MAP(2, PADCONF_FUNC_ANY), + GPIO_PIN_MAP(5, PADCONF_FUNC_ANY), + GPIO_PIN_MAP(9, PADCONF_FUNC_ANY), + GPIO_PIN_MAP(7, PADCONF_FUNC_ANY) }; #define NCORE_PINS nitems(bytgpio_ncore_pins) -#define SUS_UID 3 -#define SUS_BANK_PREFIX "GPIO_S5_" -const int bytgpio_sus_pins[] = { - 29, 33, 30, 31, 32, 34, 36, 35, 38, 37, 18, 7, 11, 20, 17, 1, - 8, 10, 19, 12, 0, 2, 23, 39, 28, 27, 22, 21, 24, 25, 26, 51, - 56, 54, 49, 55, 48, 57, 50, 58, 52, 53, 59, 40 +#define SUS_UID 3 +#define SUS_BANK_PREFIX "GPIO_S5_" +const struct pinmap_info bytgpio_sus_pins[] = { + GPIO_PIN_MAP(29, 0), + GPIO_PIN_MAP(33, 0), + GPIO_PIN_MAP(30, 0), + GPIO_PIN_MAP(31, 0), + GPIO_PIN_MAP(32, 0), + GPIO_PIN_MAP(34, 0), + GPIO_PIN_MAP(36, 0), + GPIO_PIN_MAP(35, 0), + GPIO_PIN_MAP(38, 0), + GPIO_PIN_MAP(37, 0), + GPIO_PIN_MAP(18, 0), + GPIO_PIN_MAP(7, 1), + GPIO_PIN_MAP(11, 1), + GPIO_PIN_MAP(20, 1), + GPIO_PIN_MAP(17, 1), + GPIO_PIN_MAP(1, 1), + GPIO_PIN_MAP(8, 1), + GPIO_PIN_MAP(10, 1), + GPIO_PIN_MAP(19, 1), + GPIO_PIN_MAP(12, 1), + GPIO_PIN_MAP(0, 1), + GPIO_PIN_MAP(2, 1), + GPIO_PIN_MAP(23, 0), + GPIO_PIN_MAP(39, 0), + GPIO_PIN_MAP(28, 0), + GPIO_PIN_MAP(27, 0), + GPIO_PIN_MAP(22, 0), + GPIO_PIN_MAP(21, 0), + GPIO_PIN_MAP(24, 0), + GPIO_PIN_MAP(25, 0), + GPIO_PIN_MAP(26, 0), + GPIO_PIN_MAP(51, 0), + GPIO_PIN_MAP(56, 0), + GPIO_PIN_MAP(54, 0), + GPIO_PIN_MAP(49, 0), + GPIO_PIN_MAP(55, 0), + GPIO_PIN_MAP(48, 0), + GPIO_PIN_MAP(57, 0), + GPIO_PIN_MAP(50, 0), + GPIO_PIN_MAP(58, 0), + GPIO_PIN_MAP(52, 0), + GPIO_PIN_MAP(53, 0), + GPIO_PIN_MAP(59, 0), + GPIO_PIN_MAP(40, 0) }; + #define SUS_PINS nitems(bytgpio_sus_pins) -#define BYGPIO_PIN_REGISTER(sc, pin, reg) ((sc)->sc_pinpad_map[(pin)] * 16 + (reg)) +#define BYGPIO_PIN_REGISTER(sc, pin, r) ((sc)->sc_pinpad_map[(pin)].reg * 16 + (r)) #define BYTGPIO_PCONF0 0x0000 +#define BYTGPIO_PCONF0_FUNC_MASK 7 #define BYTGPIO_PAD_VAL 0x0008 #define BYTGPIO_PAD_VAL_LEVEL (1 << 0) #define BYTGPIO_PAD_VAL_I_OUTPUT_ENABLED (1 << 1) #define BYTGPIO_PAD_VAL_I_INPUT_ENABLED (1 << 2) #define BYTGPIO_PAD_VAL_DIR_MASK (3 << 1) static inline uint32_t bytgpio_read_4(struct bytgpio_softc *sc, bus_size_t off) { return (bus_read_4(sc->sc_mem_res, off)); } static inline void bytgpio_write_4(struct bytgpio_softc *sc, bus_size_t off, uint32_t val) { bus_write_4(sc->sc_mem_res, off, val); } static device_t bytgpio_get_bus(device_t dev) { struct bytgpio_softc *sc; sc = device_get_softc(dev); return (sc->sc_busdev); } static int bytgpio_pin_max(device_t dev, int *maxpin) { struct bytgpio_softc *sc; sc = device_get_softc(dev); *maxpin = sc->sc_npins - 1; return (0); } static int bytgpio_valid_pin(struct bytgpio_softc *sc, int pin) { if (pin >= sc->sc_npins || sc->sc_mem_res == NULL) return (EINVAL); return (0); } +/* + * Returns true if pad configured to be used as GPIO + */ +static bool +bytgpio_pad_is_gpio(struct bytgpio_softc *sc, int pin) +{ + if ((sc->sc_pinpad_map[pin].pad_func == PADCONF_FUNC_ANY) || + (sc->sc_pad_funcs[pin] == sc->sc_pinpad_map[pin].pad_func)) + return (true); + else + return (false); +} + static int bytgpio_pin_getcaps(device_t dev, uint32_t pin, uint32_t *caps) { struct bytgpio_softc *sc; sc = device_get_softc(dev); if (bytgpio_valid_pin(sc, pin) != 0) return (EINVAL); - *caps = GPIO_PIN_INPUT | GPIO_PIN_OUTPUT; + *caps = 0; + if (bytgpio_pad_is_gpio(sc, pin)) + *caps = GPIO_PIN_INPUT | GPIO_PIN_OUTPUT; return (0); } static int bytgpio_pin_getflags(device_t dev, uint32_t pin, uint32_t *flags) { struct bytgpio_softc *sc; uint32_t reg, val; sc = device_get_softc(dev); if (bytgpio_valid_pin(sc, pin) != 0) return (EINVAL); + *flags = 0; + if (!bytgpio_pad_is_gpio(sc, pin)) + return (0); + /* Get the current pin state */ BYTGPIO_LOCK(sc); reg = BYGPIO_PIN_REGISTER(sc, pin, BYTGPIO_PAD_VAL); val = bytgpio_read_4(sc, reg); - *flags = 0; if ((val & BYTGPIO_PAD_VAL_I_OUTPUT_ENABLED) == 0) *flags |= GPIO_PIN_OUTPUT; /* * this bit can be cleared to read current output value * sou output bit takes precedense */ else if ((val & BYTGPIO_PAD_VAL_I_INPUT_ENABLED) == 0) *flags |= GPIO_PIN_INPUT; BYTGPIO_UNLOCK(sc); return (0); } static int bytgpio_pin_setflags(device_t dev, uint32_t pin, uint32_t flags) { struct bytgpio_softc *sc; uint32_t reg, val; uint32_t allowed; sc = device_get_softc(dev); if (bytgpio_valid_pin(sc, pin) != 0) return (EINVAL); - allowed = GPIO_PIN_INPUT | GPIO_PIN_OUTPUT; + if (bytgpio_pad_is_gpio(sc, pin)) + allowed = GPIO_PIN_INPUT | GPIO_PIN_OUTPUT; + else + allowed = 0; /* * Only directtion flag allowed */ if (flags & ~allowed) return (EINVAL); /* * Not both directions simultaneously */ if ((flags & allowed) == allowed) return (EINVAL); /* Set the GPIO mode and state */ BYTGPIO_LOCK(sc); reg = BYGPIO_PIN_REGISTER(sc, pin, BYTGPIO_PAD_VAL); val = bytgpio_read_4(sc, reg); val = val | BYTGPIO_PAD_VAL_DIR_MASK; if (flags & GPIO_PIN_INPUT) val = val & ~BYTGPIO_PAD_VAL_I_INPUT_ENABLED; if (flags & GPIO_PIN_OUTPUT) val = val & ~BYTGPIO_PAD_VAL_I_OUTPUT_ENABLED; bytgpio_write_4(sc, reg, val); BYTGPIO_UNLOCK(sc); return (0); } static int bytgpio_pin_getname(device_t dev, uint32_t pin, char *name) { struct bytgpio_softc *sc; sc = device_get_softc(dev); if (bytgpio_valid_pin(sc, pin) != 0) return (EINVAL); /* Set a very simple name */ snprintf(name, GPIOMAXNAME, "%s%u", sc->sc_bank_prefix, pin); name[GPIOMAXNAME - 1] = '\0'; return (0); } static int bytgpio_pin_set(device_t dev, uint32_t pin, unsigned int value) { struct bytgpio_softc *sc; uint32_t reg, val; sc = device_get_softc(dev); if (bytgpio_valid_pin(sc, pin) != 0) return (EINVAL); + if (!bytgpio_pad_is_gpio(sc, pin)) + return (EINVAL); + BYTGPIO_LOCK(sc); reg = BYGPIO_PIN_REGISTER(sc, pin, BYTGPIO_PAD_VAL); val = bytgpio_read_4(sc, reg); if (value == GPIO_PIN_LOW) val = val & ~BYTGPIO_PAD_VAL_LEVEL; else val = val | BYTGPIO_PAD_VAL_LEVEL; bytgpio_write_4(sc, reg, val); BYTGPIO_UNLOCK(sc); return (0); } static int bytgpio_pin_get(device_t dev, uint32_t pin, unsigned int *value) { struct bytgpio_softc *sc; uint32_t reg, val; sc = device_get_softc(dev); if (bytgpio_valid_pin(sc, pin) != 0) return (EINVAL); + /* + * Report non-GPIO pads as pin LOW + */ + if (!bytgpio_pad_is_gpio(sc, pin)) { + *value = GPIO_PIN_LOW; + return (0); + } BYTGPIO_LOCK(sc); reg = BYGPIO_PIN_REGISTER(sc, pin, BYTGPIO_PAD_VAL); /* - * Enable input to read current value - */ - val = bytgpio_read_4(sc, reg); - val = val & ~BYTGPIO_PAD_VAL_I_INPUT_ENABLED; - bytgpio_write_4(sc, reg, val); - /* * And read actual value */ val = bytgpio_read_4(sc, reg); if (val & BYTGPIO_PAD_VAL_LEVEL) *value = GPIO_PIN_HIGH; else *value = GPIO_PIN_LOW; BYTGPIO_UNLOCK(sc); return (0); } static int bytgpio_pin_toggle(device_t dev, uint32_t pin) { struct bytgpio_softc *sc; uint32_t reg, val; sc = device_get_softc(dev); if (bytgpio_valid_pin(sc, pin) != 0) return (EINVAL); + if (!bytgpio_pad_is_gpio(sc, pin)) + return (EINVAL); + /* Toggle the pin */ BYTGPIO_LOCK(sc); reg = BYGPIO_PIN_REGISTER(sc, pin, BYTGPIO_PAD_VAL); val = bytgpio_read_4(sc, reg); val = val ^ BYTGPIO_PAD_VAL_LEVEL; bytgpio_write_4(sc, reg, val); BYTGPIO_UNLOCK(sc); return (0); } static int bytgpio_probe(device_t dev) { static char *gpio_ids[] = { "INT33FC", NULL }; if (acpi_disabled("gpio") || ACPI_ID_PROBE(device_get_parent(dev), dev, gpio_ids) == NULL) return (ENXIO); device_set_desc(dev, "Intel Baytrail GPIO Controller"); return (0); } static int bytgpio_attach(device_t dev) { struct bytgpio_softc *sc; ACPI_STATUS status; int uid; + int pin; + uint32_t reg, val; sc = device_get_softc(dev); sc->sc_dev = dev; sc->sc_handle = acpi_get_handle(dev); status = acpi_GetInteger(sc->sc_handle, "_UID", &uid); if (ACPI_FAILURE(status)) { device_printf(dev, "failed to read _UID\n"); return (ENXIO); } + BYTGPIO_LOCK_INIT(sc); + switch (uid) { case SCORE_UID: sc->sc_npins = SCORE_PINS; sc->sc_bank_prefix = SCORE_BANK_PREFIX; sc->sc_pinpad_map = bytgpio_score_pins; break; case NCORE_UID: sc->sc_npins = NCORE_PINS; sc->sc_bank_prefix = NCORE_BANK_PREFIX; sc->sc_pinpad_map = bytgpio_ncore_pins; break; case SUS_UID: sc->sc_npins = SUS_PINS; sc->sc_bank_prefix = SUS_BANK_PREFIX; sc->sc_pinpad_map = bytgpio_sus_pins; break; default: device_printf(dev, "invalid _UID value: %d\n", uid); + goto error; } + sc->sc_pad_funcs = malloc(sizeof(int)*sc->sc_npins, M_DEVBUF, + M_WAITOK | M_ZERO); + sc->sc_mem_rid = 0; sc->sc_mem_res = bus_alloc_resource_any(sc->sc_dev, SYS_RES_MEMORY, &sc->sc_mem_rid, RF_ACTIVE); if (sc->sc_mem_res == NULL) { device_printf(dev, "can't allocate resource\n"); goto error; } - BYTGPIO_LOCK_INIT(sc); + for (pin = 0; pin < sc->sc_npins; pin++) { + reg = BYGPIO_PIN_REGISTER(sc, pin, BYTGPIO_PCONF0); + val = bytgpio_read_4(sc, reg); + sc->sc_pad_funcs[pin] = val & BYTGPIO_PCONF0_FUNC_MASK; + } sc->sc_busdev = gpiobus_attach_bus(dev); if (sc->sc_busdev == NULL) { BYTGPIO_LOCK_DESTROY(sc); bus_release_resource(dev, SYS_RES_MEMORY, sc->sc_mem_rid, sc->sc_mem_res); return (ENXIO); } return (0); error: + BYTGPIO_LOCK_DESTROY(sc); + return (ENXIO); } + +static int +bytgpio_detach(device_t dev) +{ + struct bytgpio_softc *sc; + + sc = device_get_softc(dev); + + if (sc->sc_busdev) + gpiobus_detach_bus(dev); + + BYTGPIO_LOCK_DESTROY(sc); + + if (sc->sc_pad_funcs) + free(sc->sc_pad_funcs, M_DEVBUF); + + if (sc->sc_mem_res != NULL) + bus_release_resource(dev, SYS_RES_MEMORY, + sc->sc_mem_rid, sc->sc_mem_res); + + return (0); +} + static device_method_t bytgpio_methods[] = { /* Device interface */ DEVMETHOD(device_probe, bytgpio_probe), DEVMETHOD(device_attach, bytgpio_attach), + DEVMETHOD(device_detach, bytgpio_detach), /* GPIO protocol */ DEVMETHOD(gpio_get_bus, bytgpio_get_bus), DEVMETHOD(gpio_pin_max, bytgpio_pin_max), DEVMETHOD(gpio_pin_getname, bytgpio_pin_getname), DEVMETHOD(gpio_pin_getflags, bytgpio_pin_getflags), DEVMETHOD(gpio_pin_getcaps, bytgpio_pin_getcaps), DEVMETHOD(gpio_pin_setflags, bytgpio_pin_setflags), DEVMETHOD(gpio_pin_get, bytgpio_pin_get), DEVMETHOD(gpio_pin_set, bytgpio_pin_set), DEVMETHOD(gpio_pin_toggle, bytgpio_pin_toggle), DEVMETHOD_END }; static driver_t bytgpio_driver = { "gpio", bytgpio_methods, sizeof(struct bytgpio_softc), }; static devclass_t bytgpio_devclass; DRIVER_MODULE(bytgpio, acpi, bytgpio_driver, bytgpio_devclass, 0, 0); MODULE_DEPEND(bytgpio, acpi, 1, 1, 1); -MODULE_DEPEND(bytgpio, gpio, 1, 1, 1); +MODULE_DEPEND(bytgpio, gpiobus, 1, 1, 1); Index: stable/11/sys/modules/Makefile =================================================================== --- stable/11/sys/modules/Makefile (revision 309374) +++ stable/11/sys/modules/Makefile (revision 309375) @@ -1,804 +1,806 @@ # $FreeBSD$ SYSDIR?=${.CURDIR}/.. .include "${SYSDIR}/conf/kern.opts.mk" SUBDIR_PARALLEL= # Modules that include binary-only blobs of microcode should be selectable by # MK_SOURCELESS_UCODE option (see below). .if defined(MODULES_OVERRIDE) && !defined(ALL_MODULES) SUBDIR=${MODULES_OVERRIDE} .else SUBDIR= \ ${_3dfx} \ ${_3dfx_linux} \ ${_aac} \ ${_aacraid} \ accf_data \ accf_dns \ accf_http \ acl_nfs4 \ acl_posix1e \ ${_acpi} \ ae \ ${_aesni} \ age \ ${_agp} \ aha \ ${_ahb} \ ahci \ ${_aic} \ aic7xxx \ alc \ ale \ alq \ ${_amdsbwd} \ ${_amdtemp} \ amr \ ${_an} \ ${_aout} \ ${_apm} \ ${_arcmsr} \ ${_arcnet} \ ${_asmc} \ ata \ ath \ ath_pci \ ${_autofs} \ ${_auxio} \ ${_bce} \ bfe \ bhnd \ bge \ bhnd \ ${_bxe} \ ${_bios} \ ${_bktr} \ ${_bm} \ bridgestp \ bwi \ bwn \ bwn_pci \ + ${_bytgpio} \ cam \ ${_canbepm} \ ${_canbus} \ ${_cardbus} \ ${_carp} \ cas \ ${_cbb} \ cc \ cd9660 \ cd9660_iconv \ ${_ce} \ ${_cfi} \ ${_ciss} \ cloudabi \ ${_cloudabi32} \ ${_cloudabi64} \ ${_cm} \ ${_cmx} \ ${_coff} \ ${_coretemp} \ ${_cp} \ ${_cpsw} \ ${_cpuctl} \ ${_cpufreq} \ ${_crypto} \ ${_cryptodev} \ ${_cs} \ ${_ct} \ ${_ctau} \ ctl \ ${_cxgb} \ ${_cxgbe} \ dc \ dcons \ dcons_crom \ de \ ${_dpms} \ ${_dpt} \ ${_drm} \ ${_drm2} \ dummynet \ ${_ed} \ ${_efirt} \ ${_elink} \ ${_em} \ en \ ${_ep} \ ${_epic} \ esp \ ${_et} \ evdev \ ${_ex} \ ${_exca} \ ext2fs \ ${_fatm} \ fdc \ fdescfs \ ${_fe} \ filemon \ firewire \ firmware \ fuse \ ${_fxp} \ gem \ geom \ ${_glxiic} \ ${_glxsb} \ gpio \ hatm \ hifn \ hme \ ${_hpt27xx} \ ${_hptiop} \ ${_hptmv} \ ${_hptnr} \ ${_hptrr} \ hwpmc \ ${_hyperv} \ i2c \ ${_ibcore} \ ${_ibcs2} \ ${_ichwd} \ ${_ida} \ ${_ie} \ if_bridge \ if_disc \ if_edsc \ ${_if_enc} \ if_epair \ ${_if_gif} \ ${_if_gre} \ ${_if_me} \ if_lagg \ ${_if_ndis} \ ${_if_stf} \ if_tap \ if_tun \ if_vlan \ if_vxlan \ ${_igb} \ ${_iir} \ imgact_binmisc \ ${_io} \ ${_ioat} \ ${_ipoib} \ ${_ipdivert} \ ${_ipfilter} \ ${_ipfw} \ ipfw_nat \ ${_ipmi} \ ip6_mroute_mod \ ip_mroute_mod \ ${_ips} \ ${_ipw} \ ${_ipwfw} \ ${_isci} \ ${_iser} \ isp \ ${_ispfw} \ ${_iwi} \ ${_iwifw} \ ${_iwm} \ ${_iwmfw} \ ${_iwn} \ ${_iwnfw} \ ${_ix} \ ${_ixv} \ ${_ixgb} \ ${_ixl} \ ${_ixlv} \ jme \ joy \ kbdmux \ kgssapi \ kgssapi_krb5 \ khelp \ krpc \ ksyms \ le \ lge \ libalias \ libiconv \ libmbpool \ libmchain \ ${_linprocfs} \ ${_linsysfs} \ ${_linux} \ ${_linux_common} \ ${_linux64} \ linuxkpi \ lmc \ lpt \ mac_biba \ mac_bsdextended \ mac_ifoff \ mac_lomac \ mac_mls \ mac_none \ mac_partition \ mac_portacl \ mac_seeotheruids \ mac_stub \ mac_test \ malo \ mcd \ md \ mdio \ mem \ mfi \ mii \ mlx \ ${_mlx4} \ ${_mlx4ib} \ ${_mlxen} \ ${_mlx5} \ ${_mlx5en} \ ${_mly} \ mmc \ mmcsd \ mpr \ mps \ mpt \ mqueue \ mrsas \ msdosfs \ msdosfs_iconv \ ${_mse} \ msk \ ${_mthca} \ mvs \ mwl \ ${_mwlfw} \ mxge \ my \ ${_nandfs} \ ${_nandsim} \ ${_ncr} \ ${_nctgpio} \ ${_ncv} \ ${_ndis} \ netfpga10g \ ${_netgraph} \ ${_nfe} \ nfscl \ nfscommon \ nfsd \ nfslock \ nfslockd \ nfssvc \ nge \ nmdm \ ${_nsp} \ nullfs \ ${_ntb} \ ${_nvd} \ ${_nvme} \ ${_nvram} \ ${_nxge} \ oce \ otus \ ${_otusfw} \ ow \ ${_padlock} \ ${_padlock_rng} \ patm \ ${_pccard} \ ${_pcfclock} \ pcn \ ${_pf} \ ${_pflog} \ ${_pfsync} \ plip \ ${_pmc} \ ${_pms} \ ppbus \ ppc \ ppi \ pps \ procfs \ proto \ pseudofs \ ${_pst} \ pty \ puc \ ${_qlxge} \ ${_qlxgb} \ ${_qlxgbe} \ ral \ ${_ralfw} \ ${_random_fortuna} \ ${_random_yarrow} \ ${_random_other} \ rc4 \ ${_rdma} \ ${_rdrand_rng} \ re \ rl \ rtwn \ ${_rtwnfw} \ ${_s3} \ ${_safe} \ ${_sbni} \ scc \ scd \ ${_scsi_low} \ sdhci \ sdhci_pci \ sem \ send \ ${_sf} \ ${_sfxge} \ sge \ ${_si} \ siba_bwn \ siftr \ siis \ sis \ sk \ smbfs \ sn \ ${_snc} \ snp \ sound \ ${_speaker} \ ${_splash} \ ${_sppp} \ ste \ ${_stg} \ stge \ ${_streams} \ ${_svr4} \ ${_sym} \ ${_syscons} \ sysvipc \ ${_ti} \ ${_tcp_fastpath} \ tests/framework \ tests/callout_test \ tl \ tmpfs \ ${_toecore} \ ${_tpm} \ trm \ ${_twa} \ twe \ tws \ tx \ ${_txp} \ uart \ ubsec \ udf \ udf_iconv \ ufs \ uinput \ unionfs \ urtwn \ ${_urtwnfw} \ usb \ utopia \ ${_vesa} \ ${_virtio} \ vge \ ${_viawd} \ videomode \ vkbd \ ${_vmm} \ ${_vmware} \ ${_vpo} \ vr \ vte \ vx \ ${_vxge} \ wb \ ${_wbwd} \ ${_wds} \ ${_wi} \ ${_wl} \ wlan \ wlan_acl \ wlan_amrr \ wlan_ccmp \ wlan_rssadapt \ wlan_tkip \ wlan_wep \ wlan_xauth \ ${_wpi} \ ${_wpifw} \ ${_x86bios} \ ${_xe} \ xl \ zlib .if ${MK_AUTOFS} != "no" || defined(ALL_MODULES) _autofs= autofs .endif .if ${MK_CDDL} != "no" || defined(ALL_MODULES) .if (${MACHINE_CPUARCH} != "arm" || ${MACHINE_ARCH:Marmv6*} != "") && \ ${MACHINE_CPUARCH} != "mips" && \ ${MACHINE_CPUARCH} != "sparc64" SUBDIR+= dtrace .endif SUBDIR+= opensolaris .endif .if ${MK_CRYPT} != "no" || defined(ALL_MODULES) .if exists(${.CURDIR}/../opencrypto) _crypto= crypto _cryptodev= cryptodev _random_fortuna=random_fortuna _random_yarrow= random_yarrow _random_other= random_other .endif .endif .if ${MK_CUSE} != "no" || defined(ALL_MODULES) SUBDIR+= cuse .endif .if ${MK_EXTRA_TCP_STACKS} != "no" || defined(ALL_MODULES) _tcp_fastpath= tcp/fastpath .endif .if (${MK_INET_SUPPORT} != "no" || ${MK_INET6_SUPPORT} != "no") || \ defined(ALL_MODULES) _carp= carp _toecore= toecore _if_enc= if_enc _if_gif= if_gif _if_gre= if_gre .endif .if (${MK_INET_SUPPORT} != "no" && ${MK_INET6_SUPPORT} != "no") || \ defined(ALL_MODULES) _if_stf= if_stf .endif .if ${MK_INET_SUPPORT} != "no" || defined(ALL_MODULES) _if_me= if_me _ipdivert= ipdivert _ipfw= ipfw .endif .if ${MK_IPFILTER} != "no" || defined(ALL_MODULES) _ipfilter= ipfilter .endif .if ${MK_ISCSI} != "no" || defined(ALL_MODULES) SUBDIR+= iscsi SUBDIR+= iscsi_initiator .endif .if ${MK_NAND} != "no" || defined(ALL_MODULES) _nandfs= nandfs _nandsim= nandsim .endif .if ${MK_NETGRAPH} != "no" || defined(ALL_MODULES) _netgraph= netgraph .endif .if (${MK_PF} != "no" && (${MK_INET_SUPPORT} != "no" || \ ${MK_INET6_SUPPORT} != "no")) || defined(ALL_MODULES) _pf= pf _pflog= pflog .if ${MK_INET_SUPPORT} != "no" _pfsync= pfsync .endif .endif .if ${MK_SOURCELESS_UCODE} != "no" _bce= bce _fatm= fatm _fxp= fxp _ispfw= ispfw _mwlfw= mwlfw _otusfw= otusfw _ralfw= ralfw _rtwnfw= rtwnfw _urtwnfw= urtwnfw _sf= sf _ti= ti _txp= txp .endif .if ${MK_SOURCELESS_UCODE} != "no" && ${MACHINE_CPUARCH} != "arm" && \ ${MACHINE_ARCH:C/mips(el)?/mips/} != "mips" && \ ${MACHINE_ARCH} != "powerpc" && ${MACHINE_CPUARCH} != "riscv" _cxgbe= cxgbe .endif .if ${MK_ZFS} != "no" || defined(ALL_MODULES) SUBDIR+= zfs .endif .if ${MACHINE_CPUARCH} != "aarch64" && ${MACHINE_CPUARCH} != "arm" && \ ${MACHINE_CPUARCH} != "mips" && ${MACHINE_CPUARCH} != "powerpc" && \ ${MACHINE_CPUARCH} != "riscv" _syscons= syscons _vpo= vpo .endif .if ${MACHINE_CPUARCH} != "mips" # no BUS_SPACE_UNSPECIFIED # No barrier instruction support (specific to this driver) _sym= sym # intr_disable() is a macro, causes problems .if ${MK_SOURCELESS_UCODE} != "no" _cxgb= cxgb .endif .endif .if ${MACHINE_CPUARCH} == "aarch64" _em= em _igb= igb .endif .if ${MACHINE_CPUARCH} == "i386" || ${MACHINE_CPUARCH} == "amd64" _agp= agp _an= an _aout= aout _bktr= bktr _bxe= bxe _cardbus= cardbus _cbb= cbb _cpuctl= cpuctl _cpufreq= cpufreq _cs= cs _dpms= dpms _drm= drm _drm2= drm2 _ed= ed _em= em _ep= ep _et= et _exca= exca _fe= fe .if ${MK_OFED} != "no" || defined(ALL_MODULES) _ibcore= ibcore .endif _if_ndis= if_ndis _igb= igb _io= io .if ${MK_OFED} != "no" || defined(ALL_MODULES) _ipoib= ipoib _iser= iser .endif _ix= ix _ixv= ixv _linprocfs= linprocfs _linsysfs= linsysfs _linux= linux _nctgpio= nctgpio _ndis= ndis _pccard= pccard .if ${MK_OFED} != "no" || defined(ALL_MODULES) _rdma= rdma .endif _safe= safe _scsi_low= scsi_low _si= si _speaker= speaker _splash= splash _sppp= sppp _vmware= vmware _vxge= vxge _wbwd= wbwd _wi= wi _xe= xe .if ${MACHINE} != "pc98" _aac= aac _aacraid= aacraid _acpi= acpi .if ${MK_CRYPT} != "no" || defined(ALL_MODULES) _aesni= aesni .endif _amdsbwd= amdsbwd _amdtemp= amdtemp _arcmsr= arcmsr _asmc= asmc +_bytgpio= bytgpio _ciss= ciss _cmx= cmx _coretemp= coretemp .if ${MK_SOURCELESS_HOST} != "no" _hpt27xx= hpt27xx .endif _hptiop= hptiop .if ${MK_SOURCELESS_HOST} != "no" _hptmv= hptmv _hptnr= hptnr _hptrr= hptrr .endif _hyperv= hyperv _ichwd= ichwd _ida= ida _iir= iir _ipmi= ipmi _ips= ips _isci= isci _ipw= ipw _iwi= iwi _iwm= iwm _iwn= iwn _ixgb= ixgb .if ${MK_SOURCELESS_UCODE} != "no" _ipwfw= ipwfw _iwifw= iwifw _iwmfw= iwmfw _iwnfw= iwnfw .endif .if ${MK_OFED} != "no" || defined(ALL_MODULES) _mlx4= mlx4 _mlx4ib= mlx4ib _mlxen= mlxen .endif _mlx5= mlx5 .if (${MK_INET_SUPPORT} != "no" && ${MK_INET6_SUPPORT} != "no") || \ defined(ALL_MODULES) _mlx5en= mlx5en .endif _mly= mly .if ${MK_OFED} != "no" || defined(ALL_MODULES) _mthca= mthca .endif _nfe= nfe _nvd= nvd _nvme= nvme _nvram= nvram _nxge= nxge .if ${MK_CRYPT} != "no" || defined(ALL_MODULES) _padlock= padlock _padlock_rng= padlock_rng _rdrand_rng= rdrand_rng .endif _s3= s3 _tpm= tpm _twa= twa _vesa= vesa _viawd= viawd _virtio= virtio _wpi= wpi .if ${MK_SOURCELESS_UCODE} != "no" _wpifw= wpifw .endif _x86bios= x86bios .endif .endif .if ${MACHINE_CPUARCH} == "amd64" _efirt= efirt _ioat= ioat _ixl= ixl _ixlv= ixlv _linux64= linux64 _linux_common= linux_common _ntb= ntb _pms= pms _qlxge= qlxge _qlxgb= qlxgb _qlxgbe= qlxgbe _sfxge= sfxge .if ${MK_BHYVE} != "no" || defined(ALL_MODULES) _vmm= vmm .endif .endif .if ${MACHINE_CPUARCH} == "i386" # XXX some of these can move to the general case when de-i386'ed # XXX some of these can move now, but are untested on other architectures. _3dfx= 3dfx _3dfx_linux= 3dfx_linux _aic= aic _apm= apm _arcnet= arcnet .if ${MK_SOURCELESS_UCODE} != "no" _ce= ce .endif _coff= coff .if ${MK_SOURCELESS_UCODE} != "no" _cp= cp .endif _elink= elink _glxiic= glxiic _glxsb= glxsb #_ibcs2= ibcs2 _ie= ie _mse= mse _ncr= ncr _ncv= ncv _nsp= nsp _pcfclock= pcfclock _pst= pst _sbni= sbni _streams= streams _stg= stg _svr4= svr4 _wds= wds .if ${MACHINE} == "i386" .if ${MK_EISA} != "no" _ahb= ahb .endif _bios= bios _cm= cm .if ${MK_SOURCELESS_UCODE} != "no" _ctau= ctau .endif _dpt= dpt _ex= ex _wl= wl .elif ${MACHINE} == "pc98" _canbepm= canbepm _canbus= canbus _ct= ct _pmc= pmc _snc= snc .endif .endif .if ${MACHINE_CPUARCH} == "arm" _cfi= cfi _cpsw= cpsw .endif .if ${MACHINE_CPUARCH} == "powerpc" _agp= agp _an= an _bm= bm _cardbus= cardbus _cbb= cbb _cfi= cfi _cpufreq= cpufreq _drm= drm _exca= exca _nvram= powermac_nvram _pccard= pccard _wi= wi .endif .if ${MACHINE_ARCH} == "powerpc64" _drm2= drm2 .endif .if ${MACHINE_CPUARCH} == "sparc64" _auxio= auxio _em= em _epic= epic _igb= igb .endif .if (${MACHINE_CPUARCH} == "amd64" || ${MACHINE_ARCH} == "armv6" || \ ${MACHINE_CPUARCH} == "i386") _cloudabi32= cloudabi32 .endif .if ${MACHINE_CPUARCH} == "aarch64" || ${MACHINE_CPUARCH} == "amd64" _cloudabi64= cloudabi64 .endif .endif SUBDIR+=${MODULES_EXTRA} .for reject in ${WITHOUT_MODULES} SUBDIR:= ${SUBDIR:N${reject}} .endfor # Calling kldxref(8) for each module is expensive. .if !defined(NO_XREF) .MAKEFLAGS+= -DNO_XREF afterinstall: .PHONY @if type kldxref >/dev/null 2>&1; then \ ${ECHO} kldxref ${DESTDIR}${KMODDIR}; \ kldxref ${DESTDIR}${KMODDIR}; \ fi .endif .include "${SYSDIR}/conf/config.mk" SUBDIR:= ${SUBDIR:u:O} .include Index: stable/11/sys/modules/bytgpio/Makefile =================================================================== --- stable/11/sys/modules/bytgpio/Makefile (nonexistent) +++ stable/11/sys/modules/bytgpio/Makefile (revision 309375) @@ -0,0 +1,8 @@ +# $FreeBSD$ + +.PATH: ${.CURDIR}/../../dev/gpio +KMOD= bytgpio +SRCS= bytgpio.c +SRCS+= acpi_if.h device_if.h bus_if.h gpio_if.h + +.include Property changes on: stable/11/sys/modules/bytgpio/Makefile ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +FreeBSD=%H \ No newline at end of property Added: svn:mime-type ## -0,0 +1 ## +text/plain \ No newline at end of property Index: stable/11 =================================================================== --- stable/11 (revision 309374) +++ stable/11 (revision 309375) Property changes on: stable/11 ___________________________________________________________________ Modified: svn:mergeinfo ## -0,0 +0,1 ## Merged /head:r308898,308940,308942,308944,309112