From nobody Wed Aug 27 21:57:08 2025 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4cBz0460yHz65kJ5; Wed, 27 Aug 2025 21:57:08 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R12" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4cBz045C2kz3Dvn; Wed, 27 Aug 2025 21:57:08 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1756331828; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=goy2tU9MavPNGoMJRgNVIA5Lbw4O3wouh8p2zu07HIc=; b=e0w79tO23WMJLXePslh0UYtjSsqsCz3kGFLJlfnKVUVXHhB+4rrzNy892KogvjDctEVoVc 7vGhZ5spswHqrULHvVma3+ay/KSQ0U1vyHXR/YyFnf/ivOxE+cOltMC9011wfP+EMSw9cn 7r+LMMJP5bU3CcLULO5BfOZBd7bkQB1N3x9DHQpeLG/yJgmMuzNaR6PlKLQKBK1bIrhbrt r7olU/biz2Ibt+Fghm0G4shCTKyNIu0csgOPTHf72FMqOZ8spK/nwEOdG1LaRxNKszL9p8 NjD7w6rynPtUodFyCPObVHyO3adV5QdeRTCzp9tV+kyygHayHugmecjoy3Z3Iw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1756331828; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=goy2tU9MavPNGoMJRgNVIA5Lbw4O3wouh8p2zu07HIc=; b=QNWXhEVs6e0dWCL54JN0Bb2Km9+ert0wUd4p2wS9WCUgcZ+qUt3SCCrbPV0wEhz06vegLc gsIUzqjSRiQogUlAVmVnKSgOuZ+anaiHw0AAo9VZ0VE3dizAODCeLnC/mOU3VIwFKY4PEQ 6hhSuXaMjM1r/DsSxeRr7lqg9V8lQC9goQLxRRh5THc6AY5eh+lE7SP7u0K40DSl3XvlBk jvgUHo0MDm33i7ENhqFi7Ji/weauHw0c9Ao+Kv7rdREN3B5un+5v8q18RQejE9l9iHYAPY EmhCXB2EjQh29zBNiQhHh8r6uMC+xna9E8fRnqJk43JB7GJy/Q/gG+ylkE7WqA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1756331828; a=rsa-sha256; cv=none; b=EOt5xN8EITSLV/EprWmPP8ThDClSWfLDuQnDDo7+HKNrNjRwUTN7nfxZm3eWTvX/HZm3K4 UKR6sNWR4/1zOChQNMX7SlAaFEaktgaMlC7D+SupsDpqu8pTfIVH6SsuZvF2WyNjJrsXxY Qo9Lt8rX6HnTMyyFhAnjdHRR+uhDb0zH/JdFr+mHvKSXLGDrkuzGSc7ElCU7Yyh8dGSPYf NWXlWqqRqD55CRSzqZ+0uYvnr33AAYRc7+5WJ+2420SvLj6+NojOzICpI6KZktlqmfYP5D UB6Vs2j9PqA/casKiTdGMS4Gkxj1tERKIrvve61V97Lq1oMes9edJt/8+B/BsA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4cBz044pXpzh9V; Wed, 27 Aug 2025 21:57:08 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 57RLv8tG026423; Wed, 27 Aug 2025 21:57:08 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 57RLv8Gd026420; Wed, 27 Aug 2025 21:57:08 GMT (envelope-from git) Date: Wed, 27 Aug 2025 21:57:08 GMT Message-Id: <202508272157.57RLv8Gd026420@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Ahmad Khalifa Subject: git: 39bdc7d19b1a - main - gpiobus: add pin_config_32 and pin_access_32 List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: vexeduxr X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 39bdc7d19b1ac1443b1fb7adf81cfa3715625717 Auto-Submitted: auto-generated The branch main has been updated by vexeduxr: URL: https://cgit.FreeBSD.org/src/commit/?id=39bdc7d19b1ac1443b1fb7adf81cfa3715625717 commit 39bdc7d19b1ac1443b1fb7adf81cfa3715625717 Author: Ahmad Khalifa AuthorDate: 2025-08-27 21:24:28 +0000 Commit: Ahmad Khalifa CommitDate: 2025-08-27 21:38:31 +0000 gpiobus: add pin_config_32 and pin_access_32 Add pin_config_32 and pin_access_32 to the gpiobus interface. These work like the rest of the gpiobus interface. For example, if a child has the following pins in it's ivars: {2, 7 ... 38} calling these functions with pin 1 will configure/access pins 7 - 38 on the controller. Reviewed by: mmel Approved by: imp (mentor) Differential Revision: https://reviews.freebsd.org/D51931 --- sys/dev/gpio/gpiobus.c | 52 +++++++++++++++++++++++++++++++++++++++++++++++ sys/dev/gpio/gpiobus_if.m | 30 +++++++++++++++++++++++++++ 2 files changed, 82 insertions(+) diff --git a/sys/dev/gpio/gpiobus.c b/sys/dev/gpio/gpiobus.c index 650e662e4d86..5723c487e36b 100644 --- a/sys/dev/gpio/gpiobus.c +++ b/sys/dev/gpio/gpiobus.c @@ -1015,6 +1015,56 @@ gpiobus_pin_toggle(device_t dev, device_t child, uint32_t pin) return (GPIO_PIN_TOGGLE(sc->sc_dev, devi->pins[pin])); } +/* + * Verify that a child has all the pins they are requesting + * to access in their ivars. + */ +static bool +gpiobus_pin_verify_32(struct gpiobus_ivar *devi, uint32_t first_pin, + uint32_t num_pins) +{ + if (first_pin + num_pins > devi->npins) + return (false); + + /* Make sure the pins are consecutive. */ + for (uint32_t pin = first_pin; pin < first_pin + num_pins - 1; pin++) { + if (devi->pins[pin] + 1 != devi->pins[pin + 1]) + return (false); + } + + return (true); +} + +static int +gpiobus_pin_access_32(device_t dev, device_t child, uint32_t first_pin, + uint32_t clear_pins, uint32_t change_pins, uint32_t *orig_pins) +{ + struct gpiobus_softc *sc = GPIOBUS_SOFTC(dev); + struct gpiobus_ivar *devi = GPIOBUS_IVAR(child); + + if (!gpiobus_pin_verify_32(devi, first_pin, 32)) + return (EINVAL); + + return (GPIO_PIN_ACCESS_32(sc->sc_dev, devi->pins[first_pin], + clear_pins, change_pins, orig_pins)); +} + +static int +gpiobus_pin_config_32(device_t dev, device_t child, uint32_t first_pin, + uint32_t num_pins, uint32_t *pin_flags) +{ + struct gpiobus_softc *sc = GPIOBUS_SOFTC(dev); + struct gpiobus_ivar *devi = GPIOBUS_IVAR(child); + + if (num_pins > 32) + return (EINVAL); + if (!gpiobus_pin_verify_32(devi, first_pin, num_pins)) + return (EINVAL); + + return (GPIO_PIN_CONFIG_32(sc->sc_dev, + devi->pins[first_pin], num_pins, pin_flags)); +} + static int gpiobus_pin_getname(device_t dev, uint32_t pin, char *name) { @@ -1093,6 +1143,8 @@ static device_method_t gpiobus_methods[] = { DEVMETHOD(gpiobus_pin_get, gpiobus_pin_get), DEVMETHOD(gpiobus_pin_set, gpiobus_pin_set), DEVMETHOD(gpiobus_pin_toggle, gpiobus_pin_toggle), + DEVMETHOD(gpiobus_pin_access_32,gpiobus_pin_access_32), + DEVMETHOD(gpiobus_pin_config_32,gpiobus_pin_config_32), DEVMETHOD(gpiobus_pin_getname, gpiobus_pin_getname), DEVMETHOD(gpiobus_pin_setname, gpiobus_pin_setname), diff --git a/sys/dev/gpio/gpiobus_if.m b/sys/dev/gpio/gpiobus_if.m index 8bf29839ef4e..890738c4e809 100644 --- a/sys/dev/gpio/gpiobus_if.m +++ b/sys/dev/gpio/gpiobus_if.m @@ -106,6 +106,36 @@ METHOD int pin_setflags { uint32_t flags; }; +# +# Simultaneously read and/or change up to 32 adjacent pins. +# If the device cannot change the pins simultaneously, returns EOPNOTSUPP. +# +# More details about using this interface can be found in sys/gpio.h +# +METHOD int pin_access_32 { + device_t dev; + device_t child; + uint32_t first_pin; + uint32_t clear_pins; + uint32_t change_pins; + uint32_t *orig_pins; +}; + +# +# Simultaneously configure up to 32 adjacent pins. +# This is intended to change the configuration of all the pins simultaneously, +# but unlike pin_access_32, this will not fail if the hardware can't do so. +# +# More details about using this interface can be found in sys/gpio.h +# +METHOD int pin_config_32 { + device_t dev; + device_t child; + uint32_t first_pin; + uint32_t num_pins; + uint32_t *pin_flags; +}; + # # Get the pin name #