aboutsummaryrefslogtreecommitdiff
path: root/sys/dev/spibus
Commit message (Collapse)AuthorAgeFilesLines
* 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
* spibus: Use bus_generic_* directly instead of wrappersJohn Baldwin2025-01-023-28/+4
| | | | Differential Revision: https://reviews.freebsd.org/D47971
* Use bus_generic_detach instead of device_delete_children in detachJohn Baldwin2025-01-021-1/+1
| | | | | | | While here, check for errors from bus_generic_detach and move it to the start of detach if necessary. Differential Revision: https://reviews.freebsd.org/D47969
* bus_generic_detach: Delete children after detaching themJohn Baldwin2025-01-022-4/+0
| | | | | | | | | | | | | | | | | This provides better semantics as a standalone DEVMETHOD for device_attach as bus drivers should remove child devices they created as part of detach cleanup. The implementation calls bus_detach_children() first to permit child devices an opportunity to veto the detach operation. If that succeeds, device_delete_children() is used to delete the child devices. This requires fixing various drivers that were deleting devices explicitly (via a device_t pointer cached in the softc) after calling bus_generic_detach to stop doing that and just rely on bus_generic_detach to remove child devices. Reviewed by: imp Differential Revision: https://reviews.freebsd.org/D47959
* Replace calls to bus_generic_attach with bus_attach_childrenJohn Baldwin2024-12-064-4/+8
| | | | | 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
* spibus: Use a bus_child_deleted method to free ivars for childrenJohn Baldwin2024-11-014-0/+22
| | | | | Reviewed by: imp Differential Revision: https://reviews.freebsd.org/D47373
* newbus: globally replace device_add_child(..., -1) with DEVICE_UNIT_ANYWarner Losh2024-07-253-3/+3
| | | | Sponsored by: Netflix
* hwreset: Move reset code in dev/hwresetEmmanuel Vadot2024-01-102-2/+2
| | | | | | | | | | | 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: imp Sponsored by: Beckhoff Automation GmbH & Co. KG Differential Revision: https://reviews.freebsd.org/D43192
* clk: Move clock code in dev/clkEmmanuel Vadot2024-01-102-2/+2
| | | | | | | | | | | 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: mhorne Sponsored by: Beckhoff Automation GmbH & Co. KG Differential Revision: https://reviews.freebsd.org/D43191
* spibus: Move allwinner driver into the common directoryEmmanuel Vadot2024-01-101-0/+610
| | | | | | | | No need to keep it under sys/arm/allwinner It's easier to find which controller we support by looking under one directory. Sponsored by: Beckhoff Automation GmbH & Co. KG Differential Revision: https://reviews.freebsd.org/D43185
* spibus: Move rockchip driver into the common directoryEmmanuel Vadot2024-01-101-0/+476
| | | | | | | No need to keep it under sys/arm64/rockchip It's easier to find which controller we support by looking under one directory. Sponsored by: Beckhoff Automation GmbH & Co. KG
* sys: Automated cleanup of cdefs and other formattingWarner Losh2023-11-272-2/+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
* spibus: Make ofw_spibus probe just a little more favoredJustin Hibbits2023-08-281-1/+1
| | | | | | | | | | | With ade70a1ad(svn r332196) ofw_spibus probes at the BUS_PROBE_DEFAULT instead of 0. However, this races with spibus, resulting in ofw_spibus often times losing the race and the OFW node not being referenced. This in turn causes child device tree nodes to not be attached. Solve this by returning 1 higher than spibus, just like acpi_spibus. Sponsored by: Juniper Networks, Inc. MFC after: 1 week
* Add plug and play information macro for SPI bus.Vladimir Kondratyev2023-08-201-0/+6
| | | | Matching table format is compatible with ACPI_ID_PROBE bus method.
* sys: Remove $FreeBSD$: one-line sh patternWarner Losh2023-08-161-1/+0
| | | | Remove /^\s*#[#!]?\s*\$FreeBSD\$.*$\n/
* sys: Remove $FreeBSD$: one-line .c patternWarner Losh2023-08-163-6/+0
| | | | Remove /^[\s*]*__FBSDID\("\$FreeBSD\$"\);?\s*\n/
* sys: Remove $FreeBSD$: two-line .h patternWarner Losh2023-08-162-4/+0
| | | | Remove /^\s*\*\n \*\s+\$FreeBSD\$$\n/
* acpi_spibus.c: fix i386 buildKonstantin Belousov2023-08-061-1/+1
| | | | | | | intmax_t requires %j format specifier, %z is for size_t. Fixes: 7d380b986a1808164846cfd9afb5ae3f99921fcf Sponsored by: The FreeBSD Foundation
* spibus(4): Add support for ACPI-based children enumerationVladimir Kondratyev2023-08-033-10/+606
| | | | | | | | | | | | | When spibus is attached as child of Intel SPI controller it scans all ACPI nodes for "SPI Serial Bus Connection Resource Descriptor" described in section 19.6.126 of ACPI specs. If such a descriptor is found, SPI child is added to spibus, it's SPI chip select, mode, clock, IRQ resource and ACPI handle are added to ivars. Existing ACPI bus-hosted child is deleted afterwards. Apple ACPI SPI extensions are supported. Reviewed by: manu Differential Revision: https://reviews.freebsd.org/D41248
* spibus(4): Allow IRQ resource to be releasedVladimir Kondratyev2023-08-031-1/+1
| | | | | | | | | | | IRQ Resource is allocated on spibus(4). We must release it here too rather than propagate request down the tree. Fixes: 4dd8db62e9d3 ("Add IRQ resource to SPIBUS") MFC after: 1 week Reviewed by: manu Differential Revision: https://reviews.freebsd.org/D41243
* spibus(4): Skip bus_generic_detach() on device detachVladimir Kondratyev2023-08-031-7/+1
| | | | | | | | device_delete_children() detaches all children too. MFC after: 1 month Reviewed by: manu Differential Revision: https://reviews.freebsd.org/D41240
* 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
* spibus: extend API: add cs_delay ivar, KEEP_CS and NO_SLEEP flagsVal Packett2023-04-243-0/+13
| | | | | | | | | | | | | | | | | | These feature are required for an upcoming Apple MacBook topcase (HID over SPI) driver: A delay after toggling CS is required to avoid anomalies like an extra junk byte in front of the message. Keeping CS asserted is required to be able to read a status report after writing a command. (The device won't return the status if CS was deasserted.) Sleep is not allowed in the interrupt context where the Apple input driver runs its transactions. Use a flag to tell the SPI driver to avoid mtx_sleep. Reviewed by: manu (ok to SPI part of larger patch) MFC afret: 1 month Differential revision: https://reviews.freebsd.org/D29534
* spigen: Remove unused devclass argument to DRIVER_MODULE.John Baldwin2022-05-091-3/+1
|
* Remove unused spibus_devclass and ofw_spibus_devclass.John Baldwin2022-05-093-8/+2
|
* newbus: Move from bus_child_{pnpinfo,location}_src to ↵Warner Losh2021-06-232-15/+5
| | | | | | | | | | | | | | | | | | | | | | 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
* Add IRQ resource to SPIBUSEmmanuel Vadot2020-12-173-0/+44
| | | | | | | | | | | | | | Add capability to SPIBUS to have child device with IRQ. For example many ADC chip have a dedicated pin to signal "data ready" and the host can just wait for a interrupt to go out and read the result. It is the same code as in R282674 and R282702 for IICBUS by Michal Meloun Submitted by: Oskar Holmund <oskar.holmlund@ohdata.se> Differential Revision: https://reviews.freebsd.org/D27396 Notes: svn path=/head/; revision=368725
* spibus: clean up empty lines in .c and .h filesMateusz Guzik2020-09-012-4/+2
| | | | Notes: svn path=/head/; revision=365151
* Consistently use busy and vm_page_valid() rather than touching page bitsJeff Roberson2020-01-231-2/+3
| | | | | | | | | | directly. This improves API compliance, asserts, etc. Reviewed by: kib, markj Differential Revision: https://reviews.freebsd.org/D23283 Notes: svn path=/head/; revision=357017
* Regularize my copyright noticeWarner Losh2019-12-044-8/+4
| | | | | | | | | | | | o Remove All Rights Reserved from my notices o imp@FreeBSD.org everywhere o regularize punctiation, eliminate date ranges o Make sure that it's clear that I don't claim All Rights reserved by listing All Rights Reserved on same line as other copyright holders (but not me). Other such holders are also listed last where it's clear. Notes: svn path=/head/; revision=355394
* Use the new FDTCOMPAT_PNP_INFO() macro to define SPIBUS_FDT_PNP_INFO().Ian Lepore2019-05-231-3/+5
| | | | | | | | Also rename SPIBUS_PNP_INFO -> SPIBUS_FDT_PNP_INFO because there could be other kinds of pnpinfo for other (non-fdt) bus attachments. Notes: svn path=/head/; revision=348172
* Set maximum bus clock speed from hints when attaching hinted spibus(4) children.Ian Lepore2019-02-251-0/+1
| | | | | | | | Some devices (such as spigen(4)) document that this works, but it appears that the code to implement it never got added. Notes: svn path=/head/; revision=344556
* Reapply, with minor tweaks, r338025, from the original commit:Warner Losh2018-09-261-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Remove unused and easy to misuse PNP macro parameter Inspired by r338025, just remove the element size parameter to the MODULE_PNP_INFO macro entirely. The 'table' parameter is now required to have correct pointer (or array) type. Since all invocations of the macro already had this property and the emitted PNP data continues to include the element size, there is no functional change. Mostly done with the coccinelle 'spatch' tool: $ cat modpnpsize0.cocci @normaltables@ identifier b,c; expression a,d,e; declarer MODULE_PNP_INFO; @@ MODULE_PNP_INFO(a,b,c,d, -sizeof(d[0]), e); @singletons@ identifier b,c,d; expression a; declarer MODULE_PNP_INFO; @@ MODULE_PNP_INFO(a,b,c,&d, -sizeof(d), 1); $ rg -l MODULE_PNP_INFO -- sys | \ xargs spatch --in-place --sp-file modpnpsize0.cocci (Note that coccinelle invokes diff(1) via a PATH search and expects diff to tolerate the -B flag, which BSD diff does not. So I had to link gdiff into PATH as diff to use spatch.) Tinderbox'd (-DMAKE_JUST_KERNELS). Approved by: re (glen) Notes: svn path=/head/; revision=338948
* Back out r338035 until Warner is finished churning GSoC PNP patchesConrad Meyer2018-08-191-1/+1
| | | | | | | | | | I was not aware Warner was making or planning to make forward progress in this area and have since been informed of that. It's easy to apply/reapply when churn dies down. Notes: svn path=/head/; revision=338037
* Remove unused and easy to misuse PNP macro parameterConrad Meyer2018-08-191-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Inspired by r338025, just remove the element size parameter to the MODULE_PNP_INFO macro entirely. The 'table' parameter is now required to have correct pointer (or array) type. Since all invocations of the macro already had this property and the emitted PNP data continues to include the element size, there is no functional change. Mostly done with the coccinelle 'spatch' tool: $ cat modpnpsize0.cocci @normaltables@ identifier b,c; expression a,d,e; declarer MODULE_PNP_INFO; @@ MODULE_PNP_INFO(a,b,c,d, -sizeof(d[0]), e); @singletons@ identifier b,c,d; expression a; declarer MODULE_PNP_INFO; @@ MODULE_PNP_INFO(a,b,c,&d, -sizeof(d), 1); $ rg -l MODULE_PNP_INFO -- sys | \ xargs spatch --in-place --sp-file modpnpsize0.cocci (Note that coccinelle invokes diff(1) via a PATH search and expects diff to tolerate the -B flag, which BSD diff does not. So I had to link gdiff into PATH as diff to use spatch.) Tinderbox'd (-DMAKE_JUST_KERNELS). Notes: svn path=/head/; revision=338035
* Enhancements and fixes for the spigen(4) driver...Ian Lepore2018-07-111-168/+71
| | | | | | | | | | | | | | | | | | | | | | | | | | | | - Resources used by spigen_mmap_single() are now tracked using devfs_set_cdevpriv() rather than in the softc. - Since resources are now tracked per-open-fd, there is no need to try to impose any exclusive-open logic, so flags related to that are removed. - Flags used to track open status to prevent detach() when the device is open are replaced with calls to device_busy()/device_unbusy(). That extends the protection up the hierarchy so that the spibus and hardware controller drivers also can't be detached while the device is open/in use. - Arbitrary limits on the maximum size of a transfer are removed, along with the sysctl variables that allowed the limits to be changed. There is just no reason to limit the size of a spi transfer to the machine's page size. Or to any other arbitrary value, really. - Most of the locking is removed. It was mostly protecting access to flags and fields in the softc that no longer exist. The locking that remains is just to prevent concurrent calls to device_[un]busy(). - The code was calling malloc() with M_WAITOK while holding a mutex in several places. Since most of the locking is gone, that's fixed. Notes: svn path=/head/; revision=336202
* Incorporate bus and chip select numbers into spigen(4) cdev names. RatherIan Lepore2018-06-212-6/+48
| | | | | | | | | | | | | | | | | | | | | | | | | | | than assigning spigen device names in order of creation, this uses a device name that corresponds to the owning spibus and chip-select index. Example: /dev/spigen0.1 would be a child of spibus0, and use cs = 1 The intent is for systems like Raspberry Pi to have a consistent way of using an SPI interface with a specific cs value from a user application. Otherwise, there is no consistent way of knowing which cs pin will be assigned to a particular spigen device. The alternative is to specify everything in "the right order" in an overlay file, which is less than ideal. Additionally, this duplicates (to some extent) the way Linux handles a similar situation with their 'spidev' device, so it would be somewhat familiar to those who also use Linux. A new kernel config option, SPIGEN_LEGACY_CDEVNAME, causes the driver to also create /dev/spigenN device name aliases, with N incrementing in the order of device instantiation. This is provided to ease the transition for existing systems using the original naming convention (particularly when these changes are MFC'd to stable branches). Differential Revision: https://reviews.freebsd.org/D15301 Notes: svn path=/head/; revision=335506
* spi: Add SPIBUS_PNP_INFO macroEmmanuel Vadot2018-06-141-0/+4
| | | | | | | | The PNP info string is the same as the SIMPLEBUS one but driver should depend on spibus and not simplebus Notes: svn path=/head/; revision=335158
* Allow hinted attachment on FDT-based systems. Instead of returning ENXIOIan Lepore2018-04-081-8/+11
| | | | | | | | when the FDT data doesn't enable the device instance, return BUS_PROBE_NOWILDCARD, the same as for non-FDT systems. Notes: svn path=/head/; revision=332292
* Cast the data pointer to the correct type for the data being accessed (asIan Lepore2018-04-071-2/+2
| | | | | | | | | | | opposed to one that accidentally worked on the one arch I test-compiled for on my first try). Reported by: np@, O. Hartmann <ohartmann@walstatt.org> Pointy hat: ian@ Notes: svn path=/head/; revision=332259
* Don't check for impossible NULL return from malloc(..., M_WAITOK).Ian Lepore2018-04-071-6/+0
| | | | Notes: svn path=/head/; revision=332258
* Add an ioctl to get/set the SPI transfer mode. Also, make the bus clockIan Lepore2018-04-071-12/+11
| | | | | | | | | frequency ioctl actually set the corresponding ivar instead of just storing the value locally in the softc (and then not using it for anything). Also, return the correct error code if the ioctl cmd is not recognized. Notes: svn path=/head/; revision=332233
* Generate a spibus_set_[ivarname]() convenience function for each ivar,Ian Lepore2018-04-071-1/+7
| | | | | | | now that they can be set. Notes: svn path=/head/; revision=332231
* Remove the existing identify() hack to force-add a spigen device onIan Lepore2018-04-071-15/+16
| | | | | | | | | | FDT-based systems, and instead add proper FDT probe code. Because this driver is freebsd-specific and just provides generic userland access to run spibus transactions, there is no bindings document to mandate a compatible string, so just arbitrarily use "freebsd,spigen". Notes: svn path=/head/; revision=332219
* Return BUS_PROBE_DEFAULT, not zero, because this is not the one driverIan Lepore2018-04-071-1/+5
| | | | | | | | | | implementation that must be used, it's just the base system default driver. Also add a comment noting that we're being more liberal about the bus frequency property than the dts binding documents require. Notes: svn path=/head/; revision=332196
* A couple minor improvements to spibus.c...Ian Lepore2018-04-071-9/+5
| | | | | | | | | | | | | - Change the description string to "SPI bus" (was "spibus bus"). - This is the default driver for a SPI bus, not a generic implementation, so return the probe value that indicates such. - Use device_delete_children() at detach time, instead of a local loop to enumerate the children and detach each one individually. Notes: svn path=/head/; revision=332195
* Add support for writing/changing spi device ivars. The SPI mode (polarityIan Lepore2018-04-071-0/+32
| | | | | | | | | | and phase) and the maximum bus speed can be changed. The chip select number cannot be changed, because the device instances which are children of spibus are inherently associated with the chip select number they were instantiated for. Notes: svn path=/head/; revision=332194
* Add a missing MODULE_DEPEND().Ian Lepore2018-04-041-0/+1
| | | | Notes: svn path=/head/; revision=332046
* Provide public declarations for ofw_spibus_driver and ofw_spibus_devclassIan Lepore2018-02-182-2/+4
| | | | | | | so other drivers can refer to them in DRIVER_MODULE() decls. Notes: svn path=/head/; revision=329539