aboutsummaryrefslogtreecommitdiff
path: root/sys/dev/gpio
Commit message (Collapse)AuthorAgeFilesLines
* gpiobus: plug IRQ leaksAhmad Khalifa2025-07-171-3/+21
| | | | | | | | | | | | | Unmap the IRQ instead of just freeing the map data in the case of an error. Also don't overwrite the resource's virtual address since the copy of the map data made by intr_activate_irq is stored there. Implement gpiobus_release_resource so it can unmap IRQs mapped by gpio_alloc_intr_resource. Reviewed by: imp Approved by: imp (mentor) Differential Revision: https://reviews.freebsd.org/D51325
* acpi_gpiobus: don't print error message if _AEI object doesn't existAhmad Khalifa2025-07-111-1/+1
| | | | | | | | GPIO controllers aren't required to have an _AEI object. Reviewed by: wulf Approved by: imp (mentor) Differential Revision: https://reviews.freebsd.org/D51236
* gpio: hide internal gpiobus symbolsAhmad Khalifa2025-07-045-14/+50
| | | | | | | | | Move functions and variables internal to gpiobus to their own header to avoid namespace pollution and misuse. Reviewed by: wulf, imp Approved by: imp (mentor) Differential Revision: https://reviews.freebsd.org/D50872
* gpiopps: don't use internal gpiobus functionAhmad Khalifa2025-07-041-1/+1
| | | | | | | | | | | | gpiobus_release_pin is only meant to be used internally by gpiobus. Use gpio_pin_release instead. This also fixes a memory leak since gpio_pin_get_by_ofw_idx returns a malloc'd pointer, which gpio_pin_release now frees. Reviewed by: wulf, imp Approved by: imp (mentor) Differential Revision: https://reviews.freebsd.org/D50871
* gpiobus: add gpio_pin_acquireAhmad Khalifa2025-07-042-0/+24
| | | | | | | | | | | In some cases, drivers may need to acquire an existing gpio_pin_t. With the functions gpiobus currently exposes, this isn't possible as they allocate a new pin then acquire that. Add a new gpio_pin_acquire function which accepts an existing gpiobus_pin structure. Reviewed by: mmel, imp Approved by: imp (mentor) Differential Revision: https://reviews.freebsd.org/D50869
* gpiobus: gpio_pin_release: convert checks to KASSERTsAhmad Khalifa2025-07-041-5/+3
| | | | | | Reviewed by: mmel, imp Approved by: imp (mentor) Differential Revision: https://reviews.freebsd.org/D50868
* gpiobus: gpiobus_release_pin: convert errors to panicAhmad Khalifa2025-07-042-14/+9
| | | | | | | | | These are programming errors. Suggested by: mmel Reviewed by: imp Approved by: imp (mentor) Differential Revision: https://reviews.freebsd.org/D50939
* gpiobus: gpiobus_acquire_pin: panic on invalid pinAhmad Khalifa2025-07-041-4/+3
| | | | | | | | | | It is a programming error to call this function with an invalid pin. Also return proper error value on failure. Suggested by: mmel Reviewed by: imp, mmel Approved by: imp (mentor) Differential Revision: https://reviews.freebsd.org/D50940
* gpio: attach gpiobus when the controller is readyAhmad Khalifa2025-07-045-29/+25
| | | | | | | | | | Only attach gpiobus when the controller is fully initialized. Children of gpiobus expect this to be the case. Reviewed by: mmel, imp, andrew Approved by: imp (mentor) MFC after: 3 days Differential Revision: https://reviews.freebsd.org/D51088
* gpiobus: add a gpiobus_add_bus functionAhmad Khalifa2025-07-042-2/+19
| | | | | | | | | | | | Some drivers need to postpone the attachment of gpiobus until hardware init is done. Add a new gpiobus_add_bus function to accommodate this case. Suggested by: mmel, andrew Reviewed by: mmel, imp, andrew Approved by: imp (mentor) MFC after: 3 days Differential Revision: https://reviews.freebsd.org/D51133
* newbus: replace leftover device unit wildcardsAhmad Khalifa2025-06-211-1/+1
| | | | | | Reviewed by: imp, jhb Approved by: imp (mentor) Differential Revision: https://reviews.freebsd.org/D50913
* machine/stdarg.h -> sys/stdarg.hBrooks Davis2025-06-111-1/+1
| | | | | | | | | | | | | Switch to using sys/stdarg.h for va_list type and va_* builtins. Make an attempt to insert the include in a sensible place. Where style(9) was followed this is easy, where it was ignored, aim for the first block of sys/*.h headers and don't get too fussy or try to fix other style bugs. Reviewed by: imp Exp-run by: antoine (PR 286274) Pull Request: https://github.com/freebsd/freebsd-src/pull/1595
* gpioaei: mark the AEI ithread as sleepableAhmad Khalifa2025-04-211-2/+3
| | | | | | | | | | | We call an ACPICA function in the interrupt handler which may attempt to lock a mutex. If this is done while another instance of the handler already holds the lock, it would cause a kernel panic since sleeping isn't allowed. Reviewed-by: Warner Losh <imp@FreeBSD.org> Pull-request: https://github.com/freebsd/freebsd-src/pull/1667 Signed-off-by: Ahmad Khalifa <ahmadkhalifa570@gmail.com>
* acpi_gpiobus: mask pin flags for GPIOBUS_PIN_SETFLAGSAhmad Khalifa2025-04-211-1/+2
| | | | | | | | | GPIOBUS_PIN_SETFLAGS calls GPIO_PIN_SETFLAGS, which doesn't accept interrupt flags. Reviewed-by: Warner Losh <imp@FreeBSD.org> Pull-request: https://github.com/freebsd/freebsd-src/pull/1667 Signed-off-by: Ahmad Khalifa <ahmadkhalifa570@gmail.com>
* gpio: don't misuse pin->flagsAhmad Khalifa2025-04-213-23/+11
| | | | | | | | | | | | The flags member of gpio_pin_t was only meant for pin flags acquired via the FDT. Instead, make an accessor so gpioaei can still access the flags and remove the now unused gpio_pin_get_by_acpi_index. Reviewed-by: Warner Losh <imp@FreeBSD.org> Pull-request: https://github.com/freebsd/freebsd-src/pull/1667 Signed-off-by: Ahmad Khalifa <ahmadkhalifa570@gmail.com>
* acpi_gpiobus: clarify error messageAhmad Khalifa2025-04-211-1/+1
| | | | | | | | | | This message was identical to another a few lines up, making it hard to tell where the error occurred. Reviewed-by: Ed Maste <emaste@FreeBSD.org> Reviewed-by: Warner Losh <imp@FreeBSD.org> Pull-request: https://github.com/freebsd/freebsd-src/pull/1667 Signed-off-by: Ahmad Khalifa <ahmadkhalifa570@gmail.com>
* gpioaei: Add support for ACPI _EVT methodVladimir Kondratyev2025-03-071-9/+31
| | | | | | | | | | This method is often used to process GPIO "Power on" button press on modern x86 laptops with S0ix sleep mode. Tested with patch from https://reviews.freebsd.org/D26407 Sponsored by: Future Crew LLC MFC after: 2 month
* acpi_gpiobus: assume GPIO_PIN_INPUT for interrupt pinsAhmad Khalifa2025-03-071-0/+1
| | | | | Different drivers respond differently to having neither GPIO_PIN_INPUT or GPIO_PIN_OUTPUT set, this stops the unpredictable results.
* Remove now-redundant calls to device_delete_childrenJohn Baldwin2025-01-021-9/+1
| | | | | | | Earlier calls to bus_generic_detach now take care of deleting children. Differential Revision: https://reviews.freebsd.org/D47962
* Use bus_detach_children instead of bus_generic_detachJohn Baldwin2025-01-022-2/+2
| | | | | | | These drivers perform additional teardown steps in between detaching child devices and deleting child devices. Differential Revision: https://reviews.freebsd.org/D47957
* acpi_gpiobus: Fix cleanup on set flags failureAndrew Turner2024-12-091-2/+0
| | | | | | | | | | | | | | When GPIOBUS_PIN_SETFLAGS fails we called gpiobus_free_ivars to clean up the contents of the ivar, then would free the ivar. This lead to a use-after-free as the ivar had already been set on the child so gpiobus_child_deleted would try to free it again. Fix this by removing the early cleanup and letting gpiobus_child_deleted handle it. Fixes: c9e880c0ceef ("gpiobus: Use a bus_child_deleted method to free ivars for children") Sponsored by: Arm Ltd Differential Revision: https://reviews.freebsd.org/D47670
* Replace calls to bus_generic_attach with bus_attach_childrenJohn Baldwin2024-12-065-7/+12
| | | | | Reviewed by: imp Differential Revision: https://reviews.freebsd.org/D47675
* Replace calls to bus_generic_probe with bus_identify_childrenJohn Baldwin2024-12-063-3/+3
| | | | | Reviewed by: imp Differential Revision: https://reviews.freebsd.org/D47674
* kern: Make fileops and filterops tables const where possibleMark Johnston2024-11-261-1/+1
| | | | | | No functional change intended. MFC after: 1 week
* gpiospi: Fix module dependencies.Dag-Erling Smørgrav2024-11-151-2/+2
| | | | | | MFC after: 3 days Reviewed by: ray Differential Revision: https://reviews.freebsd.org/D47570
* Remove bogus detach routinesJohn Baldwin2024-11-051-1/+0
| | | | | | | | | These drivers are not bus drivers, and would need proper detach routines that tore down state stored in the softc. Better to just fail detach outright instead of an incorrect success. Reviewed by: imp Differential Revision: https://reviews.freebsd.org/D47389
* gpiobus: Use a bus_child_deleted method to free ivars for childrenJohn Baldwin2024-11-011-19/+17
| | | | | Reviewed by: imp Differential Revision: https://reviews.freebsd.org/D47369
* GPIO: Add ACPI _AEI supportColin Percival2024-10-313-0/+301
| | | | | | | | | | | | | | | | | | | Changes to acpi_gpiobus.c handle discovering and parsing the _AEI objects and storing necessary data in device ivars. A new gpioaei.c file implements the device, which simply requests an interrupt when the pin is triggered and invokes the appropriate _Exx or _Lxx ACPI method. This makes the GPIO "power button" work on arm64 Graviton systems, allowing EC2 "Stop"/"Reboot" instance calls to be handled cleanly. (Prior to this change, those requests would time out after 4 minutes and the instance would be forcibly killed.) Reviwed by: imp, andrew, Ahmad Khalifa MFC after: 3 days Sponsored by: Amazon Differential Revision: https://reviews.freebsd.org/D47253 Co-authored-by: Andrew Turner <andrew@FreeBSD.org>
* acpi_gpiobus: IoRestriction is only for type IOColin Percival2024-10-291-7/+9
| | | | | | | | | The IoRestriction field of ACPI_RESOURCE_GPIO is only meaningful for resources of type ACPI_RESOURCE_GPIO_TYPE_IO. Reported by: jrtc27 Reviewed by: jrtc27 Differential Revision: <https://reviews.freebsd.org/D47331>
* acpi_gpiobus: Narrow scope of NOT_YETColin Percival2024-10-261-3/+3
| | | | | | | | | | | GPIO interrupts work just fine and will be used shortly. We still do not support GPIO_INTR_SHAREABLE however, so leave that within the NOT_YET scope. Reviwed by: andrew MFC after: 1 week Sponsored by: Amazon Differential Revision: https://reviews.freebsd.org/D47251
* gpiobus: Make gpiobus_read_ivar externColin Percival2024-10-262-1/+2
| | | | | | | | | | This allows acpi_gpiobus to override the method and fall back to the generic gpiobus_read_ivar function if needed. Reviewed by: andrew MFC after: 1 week Sponsored by: Amazon Differential Revision: https://reviews.freebsd.org/D47250
* dev/gpio: Mask all pl011 interruptsAndrew Turner2024-10-241-0/+3
| | | | | | | | | | The firmware may have unmasked pl011 interrupts. If we don't have a device to handle one the kernel will print a spurious interrupt warning. Rather than print the warning mask all interrupts until we are ready to handle them. Sponsored by: Arm Ltd Differential Revision: https://reviews.freebsd.org/D46863
* acpi_gpiobus: OR GPIO_PIN_(IN|OUT)PUT into flagsColin Percival2024-10-121-2/+2
| | | | | | | | Right now flags is set to 0 before this "=" -> "|=" change, but it will matter when the NOT_YET section above becomes effective. MFC after: 2 weeks Sponsored by: Amazon
* gpioc: Fix handling of priv data during openTom Jones2024-09-261-8/+13
| | | | | | | | | | | | Fix the ordering of priv data creation with setting priv data. This handles failure better and resolves a panic when repeatedly running tools/tools/gpioevents. Explicitly initialise more fields in priv data while we are here. Reviewed by: markj Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D46568
* gpiobus(4): Add an acpi variant of gpiobusAhmad Khalifa2024-09-143-4/+315
| | | | | | | | | This currently only implements the address space handler and attempts to configure pins with flags obtained from ACPI. Reviewed by: wulf MFC after: 1 month Pull Request: https://github.com/freebsd/freebsd-src/pull/1359
* bytgpio: expose PNP infoAhmad Khalifa2024-07-291-2/+4
| | | | | Reviewed by: imp Pull Request: https://github.com/freebsd/freebsd-src/pull/1349
* newbus: globally replace device_add_child(..., -1) with DEVICE_UNIT_ANYWarner Losh2024-07-254-4/+4
| | | | Sponsored by: Netflix
* gpiobus: Add missing DEVMETHOD for bus_get_rmanJohn Baldwin2024-02-231-0/+1
| | | | | Reported by: andrew Fixes: 5bda26333a8e gpiobus: Use bus_generic_rman_*
* gpiobus: Use bus_generic_rman_*John Baldwin2024-02-141-38/+19
| | | | | Reviewed by: imp Differential Revision: https://reviews.freebsd.org/D43887
* gpiopower: trigger low, high and both edgesAndriy Gapon2024-01-281-3/+25
| | | | | | | | | | | Power off or reset may be activated either by low or high signal or by an edge. So, try everything. Also, the driver now supports DTS properties for timings. Finally, the driver does not change the pin configuration during attach. It is assumed that the pin is already in a state that does not trigger the power event (otherwise we wouldn't be running).
* regulator: Move regulator code in dev/regulatorEmmanuel Vadot2024-01-101-1/+1
| | | | | | | | | | | We've removed kernel option EXT_RESOURCES almost two years ago. While it was ok to have some code under a common 'extres' subdirectory at first, we now have a lot of consumer of it and we made it mandatory so no need to have it under a cryptic name. Reviewed by: emaste, imp Sponsored by: Beckhoff Automation GmbH & Co. KG Differential Revision: https://reviews.freebsd.org/D43194
* sys: Automated cleanup of cdefs and other formattingWarner Losh2023-11-2714-14/+1
| | | | | | | | | | | | | | | | Apply the following automated changes to try to eliminate no-longer-needed sys/cdefs.h includes as well as now-empty blank lines in a row. Remove /^#if.*\n#endif.*\n#include\s+<sys/cdefs.h>.*\n/ Remove /\n+#include\s+<sys/cdefs.h>.*\n+#if.*\n#endif.*\n+/ Remove /\n+#if.*\n#endif.*\n+/ Remove /^#if.*\n#endif.*\n/ Remove /\n+#include\s+<sys/cdefs.h>\n#include\s+<sys/types.h>/ Remove /\n+#include\s+<sys/cdefs.h>\n#include\s+<sys/param.h>/ Remove /\n+#include\s+<sys/cdefs.h>\n#include\s+<sys/capsicum.h>/ Sponsored by: Netflix
* gpiobus: Use bus_generic_rl_* methodsJohn Baldwin2023-11-221-19/+3
| | | | | Reviewed by: imp Differential Revision: https://reviews.freebsd.org/D42715
* sys: Remove $FreeBSD$: one-line sh patternWarner Losh2023-08-163-3/+0
| | | | Remove /^\s*#[#!]?\s*\$FreeBSD\$.*$\n/
* sys: Remove $FreeBSD$: one-line .c patternWarner Losh2023-08-1622-44/+0
| | | | Remove /^[\s*]*__FBSDID\("\$FreeBSD\$"\);?\s*\n/
* sys: Remove $FreeBSD$: two-line .c patternWarner Losh2023-08-161-3/+0
| | | | Remove /^#include\s+<sys/cdefs.h>.*$\n\s+__FBSDID\("\$FreeBSD\$"\);\n/
* sys: Remove $FreeBSD$: two-line .h patternWarner Losh2023-08-167-14/+0
| | | | Remove /^\s*\*\n \*\s+\$FreeBSD\$$\n/
* kbd: consolidate kb interfaces (phase one)Michael2023-07-071-8/+2
| | | | | | | | | | | | | | Refactor to eliminate duplicated rate and delay tables, with minor style tweaks for changed lines. Remove an obsolete comment about needing to convert from microseconds to ticks (that's done elsewhere). Remove traiing whitespace in kbdcontrol.c. Except for the new warning, no change in behavior Sponsored by: DSS GmbH Reviewed by: imp [minor style tweaks as well] Pull Request: https://github.com/freebsd/pull/683 Differential Revision: https://reviews.freebsd.org/D38818
* spdx: The BSD-2-Clause-FreeBSD identifier is obsolete, drop -FreeBSDWarner Losh2023-05-1211-11/+11
| | | | | | | | | The SPDX folks have obsoleted the BSD-2-Clause-FreeBSD identifier. Catch up to that fact and revert to their recommended match of BSD-2-Clause. Discussed with: pfg MFC After: 3 days Sponsored by: Netflix
* sys/kbio.h: make pre-unicode keymap support optionalStefan Eßer2023-02-141-3/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | FreeBSD-9 had introduced support for the full set of Unicode characters to the parsing and processing of keymap character tables. This support has been extended to cover the table for accented characters that are reached via dead key combinations in FreeBSD-13.2. New ioctls have been introduced to support both the pre-Unicode and the Unicode formats and keyboard drivers have been extended to support those ioctls. This commit makes the ABI compatibility functions in the kernel optional and dependent on COMPAT_FREEBSD13 in -CURRENT. The kbdcontrol command in -CURRENT and 13-STABLE (before 13.2) has been made ABI compatible with old kernels to allow a new world to be run on an old kernel (that does not have full Unicode support for keymaps). This commit is not to merged back to 12-STABLE or 13-STABLE. It is part of review D38465, which has been split into 3 separate commits due to different MFC and life-time requirements of either commit. Approved by: imp Differential Revision: https://reviews.freebsd.org/D38465