summaryrefslogtreecommitdiff
path: root/sys/dev/gpio
AgeCommit message (Collapse)Author
2025-12-09gpio_alloc_intr_resource: Pass rid by valueJohn Baldwin
Reviewed by: imp Differential Revision: https://reviews.freebsd.org/D53407
2025-12-09bus_alloc_resource: Pass rid by value to BUS_ALLOC_RESOURCE DEVMETHODJohn Baldwin
The wrapper functions such as bus_alloc_resource_any() still support passing the rid by value or pointer, but the underlying implementation now passes by value. Reviewed by: imp Differential Revision: https://reviews.freebsd.org/D53402
2025-10-29acpi_gpiobus: implement bus_child_deletedAhmad Khalifa
Implement bus_child_deleted and attach the gpio_aei dev to it's ACPI handle. Reviewed by: wulf Differential Revision: https://reviews.freebsd.org/D51585
2025-10-29gpiobus: use bus_generic_detach when detachingAhmad Khalifa
Use bus_generic_detach instead of bus_detach_children so the children actually get deleted. Reviewed by: jhb MFC after: 3 days Differential Revision: https://reviews.freebsd.org/D52305
2025-10-18Match style in 3613896David E. O'Brien
Reviewed by: kib Differential Revision: https://reviews.freebsd.org/D53193
2025-10-18knotes: kqueue: handle copy for trivial filtersKonstantin Belousov
Reviewed by: markj Tested by: pho Sponsored by: The FreeBSD Foundation MFC after: 2 weeks Differential revision: https://reviews.freebsd.org/D52045
2025-09-30gpioc: allocate new fifo sizeAhmad Khalifa
This slipped through after I resolved some merge conflicts. Fixes: d000adfe MFC after: 1 day
2025-09-30gpioc: fix race in ioctl(GPIOCONFIGEVENTS)Ahmad Khalifa
A race can occur in gpioc_ioctl when it is called with GPIOCONFIGEVENTS closely followed by GPIOSETCONFIG. GPIOSETCONFIG can alter the priv->pins list, making it no longer empty and opening the door for access to priv->events while we are reallocating it. Fix this by holding priv->mtx while handling GPIOCONFIGEVENTS. Reported by: Qiu-ji Chen PR: 289120 Reviewed by: mmel MFC after: 1 day Differential Revision: https://reviews.freebsd.org/D52783
2025-09-30gpioc: allocate priv->events with the correct sizeAhmad Khalifa
MFC after: 1 day
2025-09-30gpio: implement bus_setup_intr and bus_teardown_intrAhmad Khalifa
Implement bus_setup_intr and bus_teardown_intr as bus_generic_setup_intr and bus_generic_teardown_intr respectively for GPIO drivers that support interrupts. This allows children to setup interrupts. Reported by: Evgenii Ivanov <devivanov@proton.me> Reviewed by: imp MFC after: 1 day Differential Revision: https://reviews.freebsd.org/D52197
2025-09-19gpioled: remove redundant -1 checkAhmad Khalifa
The function is never called with onoff = -1 MFC after: 3 days MFC with: 9ae3c30
2025-09-05gpioled: use hw pin inversion if availableStéphane Rochoy
Add hint.gpioled.%d.invmode to allow setting the pin inversion method. Accept the following values: - auto Use hardware pin inversion if available, else fallback to software pin inversion. - hw Use hardware pin inversion. - sw Use software pin inversion. Default is auto. This hint is ignored when no pin inversion is requested (hint.gpioled.%d.invert=0). Signed-off-by: Stéphane Rochoy <stephane.rochoy@stormshield.eu> Sponsored-by: Stormshield Reviewed by: imp Pull Request: https://github.com/freebsd/freebsd-src/pull/1805
2025-08-28gpioc: remove unnecessary bus_generic_* callsAhmad Khalifa
gpioc never has any children, so there's no need to call these. Reviewed by: jhb Approved by: imp (mentor) Differential Revision: https://reviews.freebsd.org/D51933
2025-08-28gpio: make gpioc a child of gpiobusAhmad Khalifa
With gpioc being a direct child of the GPIO controller, it can't allocate interrupts properly. It currently allocates interrupts using it's parent dev (gpioX). This causes problems since the call never goes through gpiobus. Instead, make gpioc a child of gpiobus and allocate interrupts using our own dev. Also don't misuse pin->flags, it's not meant to store the flags from sys/gpio.h Reported by: Evgenii Ivanov <devivanov@proton.me> Reviewed by: mmel Approved by: imp (mentor) Differential Revision: https://reviews.freebsd.org/D51932
2025-08-28gpio: add GPIO_GET_PIN_LISTAhmad Khalifa
While most GPIO controllers provide pins from 0 .. N in a sequential manner, not all controllers start with pin 0, and not all controllers order their pins sequentially. Allow callers to get a pin list from the controller. The default behaviour is to fill pin_list with pins 0 to GPIO_PIN_MAX(). Suggested by: mmel Reviewed by: mmel Approved by: imp (mentor) Differential Revision: https://reviews.freebsd.org/D52172
2025-08-28gpioc: cleanup if pin allocation failsAhmad Khalifa
gpioc normally depends on gpioc_cdevpriv_dtor to call gpioc_release_pin_intr when it's done with a pin. However, if gpioc_allocate_pin_intr fails, the pin is never added to the linked list which the destructor loops over to free the pins. Make it so gpioc_allocate_pin_intr cleans up after itself if it fails. Reported by: Evgenii Ivanov <devivanov@proton.me> Approved by: imp (mentor, implicit) Differential Revision: https://reviews.freebsd.org/D51998
2025-08-28gpiobus: add pin_config_32 and pin_access_32Ahmad Khalifa
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
2025-08-28gpiobus: styleAhmad Khalifa
Approved by: imp (mentor, implicit)
2025-08-20acpi_gpiobus: implement bus_child_locationAhmad Khalifa
Reviewed by: imp, andrew Approved by: imp (mentor) Differential Revision: https://reviews.freebsd.org/D51586
2025-08-20gpio: rework gpioaeiAhmad Khalifa
Rework gpioaei to make it support more than one pin per GPIO resource. Also allow one instance of gpioaei to handle multiple resources. Reviewed by: imp, jhb Approved by: imp (mentor) Differential Revision: https://reviews.freebsd.org/D51584
2025-08-20gpiobus: factorize common add_child codeAhmad Khalifa
Move common bus_add_child code to gpiobus_add_child_common. Reviewed by: andrew Approved by: imp (mentor) Differential Revision: https://reviews.freebsd.org/D51582
2025-08-13acpi_gpiobus: style nitAhmad Khalifa
Reviewed by: imp Approved by: imp (mentor) Differential Revision: https://reviews.freebsd.org/D51587
2025-08-13gpio: remove gpiobus_attach_busAhmad Khalifa
Since gpiobus_attach_bus can attach the gpiobus child along with its children in the same bus pass, the parent controller's reference to gpiobus might not be set by the time the children need it. Instead, drivers should use gpiobus_add_bus and explicitly call bus_attach_children. Reviewed by: mmel, imp (older version) Approved by: imp (mentor) Differential Revision: https://reviews.freebsd.org/D51578
2025-07-17gpiobus: plug IRQ leaksAhmad Khalifa
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
2025-07-11acpi_gpiobus: don't print error message if _AEI object doesn't existAhmad Khalifa
GPIO controllers aren't required to have an _AEI object. Reviewed by: wulf Approved by: imp (mentor) Differential Revision: https://reviews.freebsd.org/D51236
2025-07-04gpio: hide internal gpiobus symbolsAhmad Khalifa
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
2025-07-04gpiopps: don't use internal gpiobus functionAhmad Khalifa
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
2025-07-04gpiobus: add gpio_pin_acquireAhmad Khalifa
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
2025-07-04gpiobus: gpio_pin_release: convert checks to KASSERTsAhmad Khalifa
Reviewed by: mmel, imp Approved by: imp (mentor) Differential Revision: https://reviews.freebsd.org/D50868
2025-07-04gpiobus: gpiobus_release_pin: convert errors to panicAhmad Khalifa
These are programming errors. Suggested by: mmel Reviewed by: imp Approved by: imp (mentor) Differential Revision: https://reviews.freebsd.org/D50939
2025-07-04gpiobus: gpiobus_acquire_pin: panic on invalid pinAhmad Khalifa
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
2025-07-04gpio: attach gpiobus when the controller is readyAhmad Khalifa
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
2025-07-04gpiobus: add a gpiobus_add_bus functionAhmad Khalifa
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
2025-06-21newbus: replace leftover device unit wildcardsAhmad Khalifa
Reviewed by: imp, jhb Approved by: imp (mentor) Differential Revision: https://reviews.freebsd.org/D50913
2025-06-11machine/stdarg.h -> sys/stdarg.hBrooks Davis
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
2025-04-21gpioaei: mark the AEI ithread as sleepableAhmad Khalifa
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>
2025-04-21acpi_gpiobus: mask pin flags for GPIOBUS_PIN_SETFLAGSAhmad Khalifa
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>
2025-04-21gpio: don't misuse pin->flagsAhmad Khalifa
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>
2025-04-21acpi_gpiobus: clarify error messageAhmad Khalifa
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>
2025-03-07gpioaei: Add support for ACPI _EVT methodVladimir Kondratyev
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
2025-03-07acpi_gpiobus: assume GPIO_PIN_INPUT for interrupt pinsAhmad Khalifa
Different drivers respond differently to having neither GPIO_PIN_INPUT or GPIO_PIN_OUTPUT set, this stops the unpredictable results.
2025-01-02Remove now-redundant calls to device_delete_childrenJohn Baldwin
Earlier calls to bus_generic_detach now take care of deleting children. Differential Revision: https://reviews.freebsd.org/D47962
2025-01-02Use bus_detach_children instead of bus_generic_detachJohn Baldwin
These drivers perform additional teardown steps in between detaching child devices and deleting child devices. Differential Revision: https://reviews.freebsd.org/D47957
2024-12-09acpi_gpiobus: Fix cleanup on set flags failureAndrew Turner
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
2024-12-06Replace calls to bus_generic_attach with bus_attach_childrenJohn Baldwin
Reviewed by: imp Differential Revision: https://reviews.freebsd.org/D47675
2024-12-06Replace calls to bus_generic_probe with bus_identify_childrenJohn Baldwin
Reviewed by: imp Differential Revision: https://reviews.freebsd.org/D47674
2024-11-26kern: Make fileops and filterops tables const where possibleMark Johnston
No functional change intended. MFC after: 1 week
2024-11-15gpiospi: Fix module dependencies.Dag-Erling Smørgrav
MFC after: 3 days Reviewed by: ray Differential Revision: https://reviews.freebsd.org/D47570
2024-11-04Remove bogus detach routinesJohn Baldwin
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
2024-11-01gpiobus: Use a bus_child_deleted method to free ivars for childrenJohn Baldwin
Reviewed by: imp Differential Revision: https://reviews.freebsd.org/D47369