Commit graph

70 commits

Author SHA1 Message Date
Emmanuel Vadot 1f469a9fc4 hwreset: Move reset code in dev/hwreset
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
2024-01-10 19:20:28 +01:00
Emmanuel Vadot be82b3a0bf clk: Move clock code in dev/clk
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
2024-01-10 19:20:26 +01:00
Emmanuel Vadot ec2b0ccdee spibus: Move allwinner driver into the common directory
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
2024-01-10 19:20:15 +01:00
Emmanuel Vadot 994c943a00 spibus: Move rockchip driver into the common directory
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
2024-01-10 19:20:13 +01:00
Warner Losh fdafd315ad sys: Automated cleanup of cdefs and other formatting
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
2023-11-26 22:24:00 -07:00
Justin Hibbits 570688f0a5 spibus: Make ofw_spibus probe just a little more favored
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
2023-08-28 19:32:44 -04:00
Vladimir Kondratyev 62aa7ab939 Add plug and play information macro for SPI bus.
Matching table format is compatible with ACPI_ID_PROBE bus method.
2023-08-20 12:53:32 +03:00
Warner Losh 031beb4e23 sys: Remove $FreeBSD$: one-line sh pattern
Remove /^\s*#[#!]?\s*\$FreeBSD\$.*$\n/
2023-08-16 11:54:58 -06:00
Warner Losh 685dc743dc sys: Remove $FreeBSD$: one-line .c pattern
Remove /^[\s*]*__FBSDID\("\$FreeBSD\$"\);?\s*\n/
2023-08-16 11:54:36 -06:00
Warner Losh 95ee2897e9 sys: Remove $FreeBSD$: two-line .h pattern
Remove /^\s*\*\n \*\s+\$FreeBSD\$$\n/
2023-08-16 11:54:11 -06:00
Konstantin Belousov 676f02a482 acpi_spibus.c: fix i386 build
intmax_t requires %j format specifier, %z is for size_t.

Fixes:	7d380b986a
Sponsored by:	The FreeBSD Foundation
2023-08-07 00:09:52 +03:00
Vladimir Kondratyev 7d380b986a spibus(4): Add support for ACPI-based children enumeration
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
2023-08-03 19:10:50 +03:00
Vladimir Kondratyev c6889cbf66 spibus(4): Allow IRQ resource to be released
IRQ Resource is allocated on spibus(4). We must release it here too
rather than propagate request down the tree.

Fixes:	4dd8db62e9 ("Add IRQ resource to SPIBUS")

MFC after:	1 week
Reviewed by:	manu
Differential Revision:	https://reviews.freebsd.org/D41243
2023-08-03 19:10:50 +03:00
Vladimir Kondratyev 1e55a13062 spibus(4): Skip bus_generic_detach() on device detach
device_delete_children() detaches all children too.

MFC after:	1 month
Reviewed by:	manu
Differential Revision:	https://reviews.freebsd.org/D41240
2023-08-03 19:10:49 +03:00
Warner Losh 4d846d260e spdx: The BSD-2-Clause-FreeBSD identifier is obsolete, drop -FreeBSD
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
2023-05-12 10:44:03 -06:00
Val Packett 3c08673438 spibus: extend API: add cs_delay ivar, KEEP_CS and NO_SLEEP flags
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
2023-04-24 12:41:52 +03:00
John Baldwin 372cb4d0cc spigen: Remove unused devclass argument to DRIVER_MODULE. 2022-05-09 12:22:04 -07:00
John Baldwin 5f31d14a92 Remove unused spibus_devclass and ofw_spibus_devclass. 2022-05-09 12:22:00 -07:00
Warner Losh ddfc9c4c59 newbus: Move from bus_child_{pnpinfo,location}_src to 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
2021-06-22 20:52:06 -06:00
Emmanuel Vadot 4dd8db62e9 Add IRQ resource to SPIBUS
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
2020-12-17 17:11:14 +00:00
Mateusz Guzik 0866e8bcfb spibus: clean up empty lines in .c and .h files 2020-09-01 21:52:35 +00:00
Jeff Roberson 91e31c3c08 Consistently use busy and vm_page_valid() rather than touching page bits
directly.  This improves API compliance, asserts, etc.

Reviewed by:	kib, markj
Differential Revision:	https://reviews.freebsd.org/D23283
2020-01-23 04:54:49 +00:00
Warner Losh f86e60008b Regularize my copyright notice
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.
2019-12-04 16:56:11 +00:00
Ian Lepore db63d25160 Use the new FDTCOMPAT_PNP_INFO() macro to define SPIBUS_FDT_PNP_INFO().
Also rename SPIBUS_PNP_INFO -> SPIBUS_FDT_PNP_INFO because there could be
other kinds of pnpinfo for other (non-fdt) bus attachments.
2019-05-23 15:59:50 +00:00
Ian Lepore 47a7da7612 Set maximum bus clock speed from hints when attaching hinted spibus(4) children.
Some devices (such as spigen(4)) document that this works, but it appears that the
code to implement it never got added.
2019-02-25 23:49:58 +00:00
Warner Losh 329e817fcc Reapply, with minor tweaks, r338025, from the original commit:
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)
2018-09-26 17:12:14 +00:00
Conrad Meyer b8e771e97a Back out r338035 until Warner is finished churning GSoC PNP patches
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.
2018-08-19 00:46:22 +00:00
Conrad Meyer faa319436f 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).
2018-08-19 00:22:21 +00:00
Ian Lepore 7a4f19151a Enhancements and fixes for the spigen(4) driver...
- 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.
2018-07-11 17:54:41 +00:00
Ian Lepore 1fcf4de055 Incorporate bus and chip select numbers into spigen(4) cdev names. Rather
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
2018-06-21 21:16:26 +00:00
Emmanuel Vadot 64b507e5fe spi: Add SPIBUS_PNP_INFO macro
The PNP info string is the same as the SIMPLEBUS one but driver should
depend on spibus and not simplebus
2018-06-14 17:20:47 +00:00
Ian Lepore bc7b44aeaf Allow hinted attachment on FDT-based systems. Instead of returning ENXIO
when the FDT data doesn't enable the device instance, return
BUS_PROBE_NOWILDCARD, the same as for non-FDT systems.
2018-04-08 17:06:30 +00:00
Ian Lepore 197d784bf3 Cast the data pointer to the correct type for the data being accessed (as
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@
2018-04-07 22:21:06 +00:00
Ian Lepore e973ad2298 Don't check for impossible NULL return from malloc(..., M_WAITOK). 2018-04-07 21:31:09 +00:00
Ian Lepore a0e911e097 Add an ioctl to get/set the SPI transfer mode. Also, make the bus clock
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.
2018-04-07 20:38:01 +00:00
Ian Lepore 948a7ee9d8 Generate a spibus_set_[ivarname]() convenience function for each ivar,
now that they can be set.
2018-04-07 20:34:57 +00:00
Ian Lepore 3b46d8687a Remove the existing identify() hack to force-add a spigen device on
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".
2018-04-07 20:04:03 +00:00
Ian Lepore ade70a1ad1 Return BUS_PROBE_DEFAULT, not zero, because this is not the one driver
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.
2018-04-07 18:58:58 +00:00
Ian Lepore c1ec6ac510 A couple minor improvements to spibus.c...
- 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.
2018-04-07 18:25:07 +00:00
Ian Lepore 392bffb9b1 Add support for writing/changing spi device ivars. The SPI mode (polarity
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.
2018-04-07 18:09:31 +00:00
Ian Lepore cdfebb9cf5 Add a missing MODULE_DEPEND(). 2018-04-04 21:19:33 +00:00
Ian Lepore 747de77cd5 Provide public declarations for ofw_spibus_driver and ofw_spibus_devclass
so other drivers can refer to them in DRIVER_MODULE() decls.
2018-02-18 23:35:23 +00:00
Pedro F. Giffuni bd9ba70127 SPDX: fix wrong license ID tag in dev/spibus. 2017-12-28 03:04:36 +00:00
Pedro F. Giffuni 718cf2ccb9 sys/dev: further adoption of SPDX licensing ID tags.
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.
2017-11-27 14:52:40 +00:00
Oleksandr Tymoshenko 50868fa68b [spigen] make spigen device ready to be compiled as a module
- Add flag to indicate that device is opened by userland
- Replace "always fail" detach method with proper detach implementation

MFC after:	1 week
2017-03-09 01:00:27 +00:00
Michael Zhilin f73628e7b1 [spibus] small code refactoring
Merge 3 sequential printf calls into one.

Reported by:	rpokala
Reviewed by:	rpokala, adrian
Approved by:	adrian (mentor)
Differential Revision:	https://reviews.freebsd.org/D8795
2017-01-16 15:23:55 +00:00
Oleksandr Tymoshenko 32d7412741 [spigen] Fix spigen attaching as a driver for SPI devices nodes in FDT
Return BUS_PROBE_NOWILDCARD in probe method to make sure that spigen
attaches only to the device created in identify method.

Before this change spigen probe method used to return 0 which meant it
competed with other drivers to be attached to the devices created for
child nodes of SPI bus node in FDT.

Reported by:	Daniel Braniss
MFC after:	1 week
2016-12-24 00:30:29 +00:00
Emmanuel Vadot 7073d12c4d ofw_spi: Parse property for the SPI mode and CS polarity.
As cs is stored in a uint32_t, use the last bit to store the
active high flag as it's unlikely that we will have that much CS.

Reviewed by:	loos
MFC after:	2 weeks
Differential Revision:	https://reviews.freebsd.org/D8614
2016-12-18 14:54:20 +00:00
Oleksandr Tymoshenko 3c43a826c6 [spigen] Make "data" part of spigen_transfer optional
Make st_data part of spigen_transfer optional by letting pass zero length
and NULL pointer. SPI controller drivers handle this case fine.

MFC after:	1 week
2016-12-16 19:09:57 +00:00
Michael Zhilin 167a228d79 [spi] reformat message and ar5315_spi minor fix
This commit corrects print of nomatch (newline was too early) and fix
unit number for new child in ar5315_spi (was 0, now is -1 to calculate it
according to actual system state)

Submitted by:	Hiroki Mori <yamori813@yahoo.co.jp>
Reviewed by:	ray, loos, mizhka
MFC after:	2 weeks
Differential Revision:	https://reviews.freebsd.org/D8749
2016-12-13 09:53:43 +00:00