aboutsummaryrefslogtreecommitdiff
path: root/sys/dev/gpio/gpiobus.c
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
* gpio: hide internal gpiobus symbolsAhmad Khalifa2025-07-041-0/+1
| | | | | | | | | 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
* gpiobus: add gpio_pin_acquireAhmad Khalifa2025-07-041-0/+22
| | | | | | | | | | | 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-041-13/+8
| | | | | | | | | 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
* gpiobus: add a gpiobus_add_bus functionAhmad Khalifa2025-07-041-2/+18
| | | | | | | | | | | | 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
* 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-021-1/+1
| | | | | | | These drivers perform additional teardown steps in between detaching child devices and deleting child devices. Differential Revision: https://reviews.freebsd.org/D47957
* Replace calls to bus_generic_attach with bus_attach_childrenJohn Baldwin2024-12-061-3/+4
| | | | | Reviewed by: imp Differential Revision: https://reviews.freebsd.org/D47675
* Replace calls to bus_generic_probe with bus_identify_childrenJohn Baldwin2024-12-061-1/+1
| | | | | Reviewed by: imp Differential Revision: https://reviews.freebsd.org/D47674
* 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
* gpiobus: Make gpiobus_read_ivar externColin Percival2024-10-261-1/+1
| | | | | | | | | | 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
* gpiobus(4): Add an acpi variant of gpiobusAhmad Khalifa2024-09-141-4/+2
| | | | | | | | | 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
* newbus: globally replace device_add_child(..., -1) with DEVICE_UNIT_ANYWarner Losh2024-07-251-1/+1
| | | | 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
* sys: Automated cleanup of cdefs and other formattingWarner Losh2023-11-271-1/+0
| | | | | | | | | | | | | | | | 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 .c patternWarner Losh2023-08-161-2/+0
| | | | Remove /^[\s*]*__FBSDID\("\$FreeBSD\$"\);?\s*\n/
* spdx: The BSD-2-Clause-FreeBSD identifier is obsolete, drop -FreeBSDWarner Losh2023-05-121-1/+1
| | | | | | | | | 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
* gpio: Remove unused devclass arguments to DRIVER_MODULE.John Baldwin2022-05-091-3/+1
|
* newbus: Move from bus_child_{pnpinfo,location}_src to ↵Warner Losh2021-06-231-47/+25
| | | | | | | | | | | | | | | | | | | | | | bus_child_{pnpinfo,location} with sbuf Now that the upper layers all go through a layer to tie into these information functions that translates an sbuf into char * and len. The current interface suffers issues of what to do in cases of truncation, etc. Instead, migrate all these functions to using struct sbuf and these issues go away. The caller is also in charge of any memory allocation and/or expansion that's needed during this process. Create a bus_generic_child_{pnpinfo,location} and make it default. It just returns success. This is for those busses that have no information for these items. Migrate the now-empty routines to using this as appropriate. Document these new interfaces with man pages, and oversight from before. Reviewed by: jhb, bcr Sponsored by: Netflix Differential Revision: https://reviews.freebsd.org/D29937
* Provide userland notification of gpio pin changes ("userland gpio interrupts").Ian Lepore2020-12-121-0/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This is an import of the Google Summer of Code 2018 project completed by Christian Kramer (and, sadly, ignored by us for two years now). The goals stated for that project were: FreeBSD already has support for interrupts implemented in the GPIO controller drivers of several SoCs, but there are no interfaces to take advantage of them out of user space yet. The goal of this work is to implement such an interface by providing descriptors which integrate with the common I/O system calls and multiplexing mechanisms. The initial imported code supports the following functionality: - A kernel driver that provides an interface to the user space; the existing gpioc(4) driver was enhanced with this functionality. - Implement support for the most common I/O system calls / multiplexing mechanisms: - read() Places the pin number on which the interrupt occurred in the buffer. Blocking and non-blocking behaviour supported. - poll()/select() - kqueue() - signal driven I/O. Posting SIGIO when the O_ASYNC was set. - Many-to-many relationship between pins and file descriptors. - A file descriptor can monitor several GPIO pins. - A GPIO pin can be monitored by multiple file descriptors. - Integration with gpioctl and libgpio. I added some fixes (mostly to locking) and feature enhancements on top of the original gsoc code. The feature ehancements allow the user to choose between detailed and summary event reporting. Detailed reporting provides a record describing each pin change event. Summary reporting provides the time of the first and last change of each pin, and a count of how many times it changed state since the last read(2) call. Another enhancement allows the recording of multiple state change events on multiple pins between each call to read(2) (the original code would track only a single event at a time). The phabricator review for these changes timed out without approval, but I cite it below anyway, because the review contains a series of diffs that show how I evolved the code from its original state in Christian's github repo for the gsoc project to what is being commited here. (In effect, the phab review extends the VC history back to the original code.) Submitted by: Christian Kramer Obtained from: https://github.com/ckraemer/freebsd/tree/gsoc2018 Differential Revision: https://reviews.freebsd.org/D27398 Notes: svn path=/head/; revision=368585
* gpiobus_release_pin: remove incorrect prefix from error messagesAndriy Gapon2020-06-221-2/+2
| | | | | | | | | | | | It's interesting that similar messages from gpiobus_acquire_pin never had any prefix while gpiobus_release_pin messages were prefixed with "gpiobus_acquire_pin". Anyway, the prefix is not that useful and can be deduced from context. MFC after: 2 weeks Notes: svn path=/head/; revision=362492
* Implement bus_rescan for gpiobus(4). This allows on-the-fly reconfigurationIan Lepore2019-12-061-0/+20
| | | | | | | | | | | | of gpio devices by using kenv to add hints for a new device and then do 'devctl rescan gpiobus4' to make the new device(s) attach. It's not particularly easy to detect whether the 'at' hint has been deleted for a child device that's currently attached, so this doesn't handle that. But the user can use devctl commands to manually detach an existing device. Notes: svn path=/head/; revision=355467
* Do not initialize the flags field in struct gpiobus_pin from the flags inIan Lepore2019-12-021-2/+12
| | | | | | | | | | | | | | struct gpio_pin. It turns out these two sets of flags are completely unrelated to each other. Also, update the comment for GPIO_ACTIVE_LOW to reflect the fact that it does get set, somewhat unobviously, by code that parses FDT data. The bits from the FDT cell containing flags are just copied to gpiobus_pin.flags, so there's never any obvious reference to the symbol GPIO_ACTIVE_LOW being stored into the flags field. Notes: svn path=/head/; revision=355298
* Move most of the gpio_pin_* functions from ofw_gpiobus.c to gpiobus.c soIan Lepore2019-12-011-4/+110
| | | | | | | | | | | | | | | | | | | | | | | that they can be used by drivers on non-FDT-configured systems. Only the functions related to acquiring pins by parsing FDT data remain in ofw_gpiobus. Also, add two new functions for acquiring gpio pins based on child device_t and index, or on the bus device_t and pin number. And finally, defer reserving pins for gpiobus children until they acquire the pin, rather than reserving them as soon as the child is added (before it's even known whether the child will attach). This will allow drivers configured with hints (or any other mechanism) to use the same code as drivers configured via FDT data. Until now, a hinted driver and an FDT driver had to be two completely different sets of code, because hinted drivers could only use gpiobus calls to manipulate pins, while fdt-configured drivers could not use that API (due to not always being children of the bus that owns the pins) and had to use the newer gpio_pin_xxxx() functions. Now drivers can be written in the more traditional form, where most of the code is shared and only the resource acquisition code at attachment time changes. Notes: svn path=/head/; revision=355274
* gpiobus: provide a new hint, pin_listAndriy Gapon2019-06-271-25/+160
| | | | | | | | | | | | | | | | | | | | | | | | | "pin_list" allows to specify child pins as a list of pin numbers. Existing hint "pins" serves the same purpose but with a 32-bit wide bit mask. One problem with that is that a controller can have more than 32 pins. One example is amdgpio. Also, a list of numbers is a little bit more human friendly than a matching bit mask. As a side note, it seems that in FDT pins are typically specified by their numbers as well. This commit also adds accessors for instance variables (IVARs) that define the child pins. My primary goal is to allow a child to be configured programmatically rather than via hints (assuming that FDT is not supported on a platform). Also, while a child should not care about specific pin numbers that are allocated to it, it could be interested in how many were actually assigned to it. While there, I removed "flags" instance variable. It was unused. Reviewed by: mizhka MFC after: 2 weeks Differential Revision: https://reviews.freebsd.org/D20459 Notes: svn path=/head/; revision=349460
* Revert r327828, r327949, r327953, r328016-r328026, r328041:Pedro F. Giffuni2018-01-211-3/+3
| | | | | | | | | | | | | | | | | | Uses of mallocarray(9). The use of mallocarray(9) has rocketed the required swap to build FreeBSD. This is likely caused by the allocation size attributes which put extra pressure on the compiler. Given that most of these checks are superfluous we have to choose better where to use mallocarray(9). We still have more uses of mallocarray(9) but hopefully this is enough to bring swap usage to a reasonable level. Reported by: wosch PR: 225197 Notes: svn path=/head/; revision=328218
* dev: make some use of mallocarray(9).Pedro F. Giffuni2018-01-131-3/+3
| | | | | | | | | | | | | | Focus on code where we are doing multiplications within malloc(9). None of these is likely to overflow, however the change is still useful as some static checkers can benefit from the allocation attributes we use for mallocarray. This initial sweep only covers malloc(9) calls with M_NOWAIT. No good reason but I started doing the changes before r327796 and at that time it was convenient to make sure the sorrounding code could handle NULL values. Notes: svn path=/head/; revision=327949
* sys/dev: further adoption of SPDX licensing ID tags.Pedro F. Giffuni2017-11-271-0/+2
| | | | | | | | | | | | | | | Mainly focus on files that use BSD 2-Clause license, however the tool I was using misidentified many licenses so this was mostly a manual - error prone - task. The Software Package Data Exchange (SPDX) group provides a specification to make it easier for automated tools to detect and summarize well known opensource licenses. We are gradually adopting the specification, noting that the tags are considered only advisory and do not, in any way, superceed or replace the license texts. Notes: svn path=/head/; revision=326255
* Remove a too strict test and instead, just filter the passed flags with theLuiz Otavio O Souza2016-12-131-3/+3
| | | | | | | | | | supported capabilities. Spotted by: yamori813@yahoo.co.jp (Hiroki Mori) MFC after: 2 weeks Notes: svn path=/head/; revision=310000
* Make gpiobus early driver at BUS_PAS_BUS.Ruslan Bukin2016-11-171-1/+2
| | | | | | | | | | | | | The gpiobus driver is attached explicitly and generally should be at the same pass as its parent. Making it use BUS_PAS_BUS ensures that it attaches immediately after parent adds it (assuming the parent itself attached at BUS_PAS_BUS and above). Submitted by: kan Sponsored by: DARPA, AFRL Notes: svn path=/head/; revision=308767
* INTRNG: Rework handling with resources. Partially revert r301453.Michal Meloun2016-08-191-21/+6
| | | | | | | | | | | | | | | | | | | | - Read interrupt properties at bus enumeration time and store it into global mapping table. - At bus_activate_resource() time, given mapping entry is resolved and connected to real interrupt source. A copy of mapping entry is attached to given resource. - At bus_setup_intr() time, mapping entry stored in resource is used for delivery of requested interrupt configuration. - For MSI/MSIX interrupts, mapping entry is created within pci_alloc_msi()/pci_alloc_msix() call. - For legacy PCI interrupts, mapping entry must be created within pcib_route_interrupt() by pcib driver itself. Reviewed by: nwhitehorn, andrew Differential Revision: https://reviews.freebsd.org/D7493 Notes: svn path=/head/; revision=304459
* INTRNG: As follow up of r301451, implement mapping and configurationMichal Meloun2016-06-071-10/+35
| | | | | | | | | | of gpio pin interrupts by new way. Note: This removes last consumer of intr_ddata machinery and we remove it in separate commit. Notes: svn path=/head/; revision=301539
* Don't wrap the declaration of gpio_alloc_intr_resource() in #ifdef INTRNG,Ian Lepore2016-05-271-0/+8
| | | | | | | | | | | wrap the implementation so that it returns an error if INTRNG support is not available. It should be possible to write a non-INTRNG implementation of this function some day. In the meantime, there is code that contains calls to this function (so the decl is needed), but have runtime checks to avoid calling it in the non-INTRNG case. Notes: svn path=/head/; revision=300871
* Rename gpiobus_map_pin() to gpiobus_acquire_pin(), to better reflect theIan Lepore2016-05-261-4/+4
| | | | | | | | fact that the caller is requesting exclusive use of the pin, and also to better match the inverse operation which is named gpiobus_release_pin(). Notes: svn path=/head/; revision=300750
* Add gpiobus_release_pin function to release mapped pinOleksandr Tymoshenko2016-05-121-0/+24
| | | | | | | | | Add gpiobus_release_pin as a counterpart for gpiobus_map_pin. Without it it's impossible to properly release pin so if kernel module is reloaded it can't re-use pins again Notes: svn path=/head/; revision=299563
* INTRNG: Define 'INTR_IRQ_INVALID' constant and use it consistentlyMichal Meloun2016-04-281-1/+1
| | | | | | | as error indicator. Notes: svn path=/head/; revision=298739
* GPIO: Add support for gpio pin interrupts.Michal Meloun2016-04-281-0/+26
| | | | | | | | | | | | Add new function gpio_alloc_intr_resource(), which allows an allocation of interrupt resource associated to given gpio pin. It also allows to specify interrupt configuration. Note: This functionality is dependent on INTRNG, and must be implemented in each GPIO controller. Notes: svn path=/head/; revision=298738
* Fix the resource_list_print_type() calls to use uintmax_t.Justin Hibbits2016-03-221-2/+2
| | | | | | | Missed a bunch from r297000. Notes: svn path=/head/; revision=297199
* Introduce a RMAN_IS_DEFAULT_RANGE() macro, and use it.Justin Hibbits2016-02-201-1/+1
| | | | | | | | | | | | | | This simplifies checking for default resource range for bus_alloc_resource(), and improves readability. This is part of, and related to, the migration of rman_res_t from u_long to uintmax_t. Discussed with: jhb Suggested by: marcel Notes: svn path=/head/; revision=295832
* Convert rman to use rman_res_t instead of u_longJustin Hibbits2016-01-271-2/+2
| | | | | | | | | | | | | | | | | | | | | | | Summary: Migrate to using the semi-opaque type rman_res_t to specify rman resources. For now, this is still compatible with u_long. This is step one in migrating rman to use uintmax_t for resources instead of u_long. Going forward, this could feasibly be used to specify architecture-specific definitions of resource ranges, rather than baking a specific integer type into the API. This change has been broken out to facilitate MFC'ing drivers back to 10 without breaking ABI. Reviewed By: jhb Sponsored by: Alex Perez/Inertial Computing Differential Revision: https://reviews.freebsd.org/D5075 Notes: svn path=/head/; revision=294883
* [gpiobus] handle the case of there being a single GPIO pin available.Adrian Chadd2016-01-141-1/+1
| | | | | | | | PR: kern/206035 Submitted by: Stanislav Galabov <sgalabov@gmail.com> Notes: svn path=/head/; revision=293872
* Fix the use of plural in two cases that I missed on r285784.Luiz Otavio O Souza2015-08-181-2/+8
| | | | | | | This should cause no functional change. Notes: svn path=/head/; revision=286909
* Fix a few bugs when gpiobus is detaching:Luiz Otavio O Souza2015-08-171-4/+14
| | | | | | | | | | | | | | | | | | - Detach the gpiobus and the gpioc devices from the GPIO controller. - Fix the leak of gpiobus IRQ rman(9) region descriptor. - Fix the leak of child ivars and IRQ resource list. While here return NULL (instead of 0) for a device_t that fails to allocate the ivar memory. Tested with gpiobus built as a module. Sponsored by: Rubicon Communications (Netgate) Notes: svn path=/head/; revision=286845
* Panic when a device is trying to recursively acquire rather than hangWarner Losh2015-07-241-2/+11
| | | | | | | indefinitely. Improve error messages from other panics. Notes: svn path=/head/; revision=285833
* Cosmetic change. When printing the child's mapped pins, use the pluralLuiz Otavio O Souza2015-07-221-3/+8
| | | | | | | | | | only when necessary. Reported by: Daniel O'Connor <darius@dons.net.au>, Sulev-Madis Silber (ketas) Notes: svn path=/head/; revision=285784