Home | History | Annotate | Download | only in i2c
History log of /src/sys/dev/i2c/ihidev.c
RevisionDateAuthorComments
 1.34  17-Sep-2025  thorpej This driver only works with ACPI. Rather than consult i2c_attach_args::
ia_cookietype, consult self's devhandle and check for DEVHANDLE_TYPE_ACPI.
Use the devhandle to get the ACPI handle where necessary, so it is no longer
necessary to store the ACPI handle in a softc field called "sc_phandle"
(which is not an accurate name).
 1.33  09-Dec-2024  jmcneill ihidev: Only reset the HID device once during attach.

From OpenBSD:
https://github.com/openbsd/src/commit/e773e7e3935196eea66382160eeee2d3f77d2e3f
 1.32  09-Dec-2024  jmcneill fixup! remove debug printf
 1.31  08-Dec-2024  jmcneill ihidev: Add support for GPIO interrupts.
 1.30  29-Apr-2024  andvar branches: 1.30.2;
ihidev(4): make driver compile with ACPI option disabled.

This change unlikely useful in practice, but adds consistency to already
available guards. Driver won't attach currently without ACPI.
 1.29  01-Aug-2023  riastradh ihidev(4): Use iic_use_direct_match as intended.

This appears to have been a mistake; there's no obvious explanation
in the commit history for why this is different from all other
iic_use_direct_match users.

Patch from Vladimir 'phcoder' Serbinenko <phcoder@gmail.com>, thanks!

(If it really is intended to ues I2C_MATCH_DIRECT_COMPATIBLE here, we
need a clear explanation of why, written down in a nearby comment.)
 1.28  12-Feb-2022  riastradh sys: Fix various abuse of struct device internals.

Will help to make struct device opaque later.
 1.27  15-Jan-2022  skrll Trailing whitespace
 1.26  14-Jan-2022  riastradh ihidev(4): Prohibit closing an unopened ihidev.
 1.25  14-Jan-2022  riastradh ihidev(4): Avoid reference count overflow.
 1.24  14-Jan-2022  riastradh ihidev(4): Take the lock for ihidev_open, ihidev_close.

Need this to serialize access to sc_state, sc_refcnt.

XXX Should harmonize this with uhidev(4) and tighten assertions.
 1.23  14-Jan-2022  riastradh ihidev(4): Check kmem_alloc(..., KM_NOSLEEP) for failure.
 1.22  14-Jan-2022  riastradh ihidev(4): Allocate report buffer with KM_SLEEP.

Limited to 64k and only happens on attach anyway. Let's not leave a
rake to trip on here.
 1.21  14-Jan-2022  riastradh ihidev(4): Fix locking and interrupt handler.

- Can't run iic_exec in softint because it does cv_wait, at least on
some i2c controllers -- defer to workqueue instead.

- Fix violations of locking rules:
. Do not take a lock at higher IPL than it is defined at!
. Do not sleep under a lock!
. Definitely do not sleep under a spin lock!
In this case, sc_intr_lock was defined at IPL_VM but used at IPL_TTY,
and i2c transactions -- possibly causing sleep for cv_wait -- were
issued under it.

But in this case, the interrupt handler needs only a single bit to
mark whether the work is pending, so just use atomic_swap for that.

- Use an adaptive lock (IPL_NONE) for i2c transactions.

- Detach children, and do so before freeing anything.
 1.20  07-Aug-2021  thorpej branches: 1.20.2;
Merge thorpej-cfargs2.
 1.19  24-Apr-2021  thorpej branches: 1.19.2; 1.19.8;
Merge thorpej-cfargs branch:

Simplify and make extensible the config_search() / config_found() /
config_attach() interfaces: rather than having different variants for
which arguments you want pass along, just have a single call that
takes a variadic list of tag-value arguments.

Adjust all call sites:
- Simplify wherever possible; don't pass along arguments that aren't
actually needed.
- Don't be explicit about what interface attribute is attaching if
the device only has one. (More simplification.)
- Add a config_probe() function to be used in indirect configuiration
situations, making is visibly easier to see when indirect config is
in play, and allowing for future change in semantics. (As of now,
this is just a wrapper around config_match(), but that is an
implementation detail.)

Remove unnecessary or redundant interface attributes where they're not
needed.

There are currently 5 "cfargs" defined:
- CFARG_SUBMATCH (submatch function for direct config)
- CFARG_SEARCH (search function for indirect config)
- CFARG_IATTR (interface attribte)
- CFARG_LOCATORS (locators array)
- CFARG_DEVHANDLE (devhandle_t - wraps OFW, ACPI, etc. handles)

...and a sentinel value CFARG_EOL.

Add some extra sanity checking to ensure that interface attributes
aren't ambiguous.

Use CFARG_DEVHANDLE in MI FDT, OFW, and ACPI code, and macppc and shark
ports to associate those device handles with device_t instance. This
will trickle trough to more places over time (need back-end for pre-OFW
Sun OBP; any others?).
 1.18  27-Jan-2021  thorpej branches: 1.18.2;
Use DEVICE_COMPAT_EOL.
 1.17  26-Jan-2021  thorpej Now that the ACPI layer no longer does this for us, evaluate the _DSM
that returns the HID descriptor address at attach time.
 1.16  26-Jan-2021  thorpej Don't map ACPI _HID / _CID strings to "compatible" strings from the
Device Tree bindings. Just pass those strings in the standard
most-specific-to-least-specific order to the drivers and let them
deal.
 1.15  26-Jan-2021  thorpej Back out unintended change in previous.
 1.14  25-Jan-2021  thorpej Since we're using designated initialisers for compat data, we should
use a completely empty initializer for the sentinel.
 1.13  17-Jan-2021  thorpej Use designated initializers and a consistent termination style in
compat_data[].
 1.12  09-Jan-2020  thorpej branches: 1.12.6;
Re-enable the intr / mask / softint / unmask dance now that the x86
interrupt issue is fixed. Verified working by ryoon@ (thanks!).
 1.11  25-Dec-2019  thorpej branches: 1.11.2;
Revert previous until issues can be sorted out.
 1.10  22-Dec-2019  thorpej The hid-over-i2c spec specifies that compliant devices use level-sensitive
interrupts. However, it's not safe to do i2c bus access in hard interrupt
context, and we must read the event data off the device in order to clear
the interrupt condition.

Address this by using acpi_intr_mask() to mask off the interrupt source
while a softint is pending to service the events, re-enabling it once
servicing is completed.

While here, re-factor the interrupt setup / tear-down code a bit to
eventually once day simplify supporting the FDT bindings for hid-over-i2c.
 1.9  01-Oct-2019  chs in many device attach paths, allocate memory with KM_SLEEP instead of KM_NOSLEEP
and remove code to handle failures that can no longer happen.
 1.8  26-Sep-2019  bouyer Abort attach if acpi_intr_establish() fails. From K. Schreiner on
current-users@.
 1.7  16-Nov-2018  jmcneill branches: 1.7.4;
Use acpi_md_intr_establish/disestablish to handle device IRQs. The existing
code abused AcpiOsInstallInterruptHandler, which is meant for installing
the SCI handler.
 1.6  15-Nov-2018  jakllsch Correctly handle signed/unsigned quantities in kernel HID parser.

Should fix PR kern/53605.
 1.5  26-Jun-2018  thorpej branches: 1.5.2;
In my quest to make device_compatible_entry (and associated goo)
super-general, it turns out I also made it a little to cumbersome
to use (if my tired fingers are any indication). So, this is a
course-correction -- one string per entry (like of_compat_data,
which it will soon replace), and remove the over-verbose macros.
 1.4  18-Jun-2018  thorpej - Rename iic_compat_match() to iic_compatible_match() and change it
to use the new device_compatible_match() routine. A pointer to
the matching device_compatible_entry is returned if a match is
found.
- Adjust iic_use_direct_match() accordingly.
- i2c drivers now provide device_compatible_entry tables when performing
direct-config matching.
- In the dsrtc driver, take advantage of this new capability to greatly
simplify model selection.

(I'm coming for you next, of_compat_data...)
 1.3  16-Jun-2018  thorpej More cleanup to i2c autoconfiguration:

- Get all of the drivers onto the new match quality constants.
- Introduce a new helper function, iic_use_direct_match(), that has
all of the logic for direct-config matching. If it returns true,
the driver returns the match result (which may be 0). If it returns
false, the driver does indirect-config matching.
- iic_compat_match() now returns a weighted match quality; matches to
lower-indexed "compatible" device property are more-specific matches,
and return a better match quality accordingly.
 1.2  20-Mar-2018  bouyer Allow registering ACPI interrupt handlers with a xname.
AcpiOsInstallInterruptHandler(), part of ACPICA API, doesn't allow passing
the xname. I extend the API with AcpiOsInstallInterruptHandler_xname()
for this purpose, and change acpi_md_OsInstallInterruptHandler() to
accept and use the xname (ia64 doens't use it).
The xname was hardcoded to "acpi SCI" in the
x86 acpi_md_OsInstallInterruptHandler(), so I make
AcpiOsInstallInterruptHandler() call
AcpiOsInstallInterruptHandler_xname with xname = "acpi SCI".

Now 'vmstat -i' shows the device's name instead of "acpi SCI" for for i2c HID
interrupts.

Proposed on tech-kern@ on Dec 29.
 1.1  10-Dec-2017  bouyer branches: 1.1.2;
Add drivers for HID over I2C devices, and a driver for I2C mices.
From OpenBSD.
 1.1.2.4  26-Nov-2018  pgoyette Sync with HEAD, resolve a couple of conflicts
 1.1.2.3  28-Jul-2018  pgoyette Sync with HEAD
 1.1.2.2  25-Jun-2018  pgoyette Sync with HEAD
 1.1.2.1  22-Mar-2018  pgoyette Synch with HEAD, resolve conflicts
 1.5.2.2  13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.5.2.1  10-Jun-2019  christos Sync with HEAD
 1.7.4.1  26-Sep-2019  martin Pull up following revision(s) (requested by bouyer in ticket #244):

sys/dev/i2c/ihidev.c: revision 1.8

Abort attach if acpi_intr_establish() fails. From K. Schreiner on
current-users@.
 1.11.2.1  17-Jan-2020  ad Sync with head.
 1.12.6.1  03-Apr-2021  thorpej Sync with HEAD.
 1.18.2.2  22-Mar-2021  thorpej Audit CFARG_IATTR in config_found() calls, and remove it in situations
where the interface attribute is not ambiguous.
 1.18.2.1  22-Mar-2021  thorpej Mechanical conversion of config_found_sm_loc() -> config_found().
CFARG_IATTR usage needs to be audited.
 1.19.8.1  04-Aug-2021  thorpej Adapt to CFARGS().
 1.19.2.1  08-May-2021  thorpej Rather than using the "cookie" from the i2c_attach_args, use the
device handle that's already associated with our device_t.
 1.20.2.2  09-Aug-2021  thorpej Use the same idiom to cast the ACPI_HANDLE to uint64_t as other drivers
when passing it to acpi_intr_establish().

XXX This is gross, but fixing it is outside the scope of this branch.
 1.20.2.1  09-Aug-2021  thorpej Port over the changes from thorpej-i2c-spi-conf to thorpej-i2c-spi-conf2,
which is based on a newer HEAD revision.
 1.30.2.1  02-Aug-2025  perseant Sync with HEAD

RSS XML Feed