Commit Graph

368 Commits

Author SHA1 Message Date
Mark Johnston
519b64e27f Revert "Define PNP info after defining driver modules"
This reverts commit aa37baf3d7.

The reverted commit was motivated by a problem observed on stable/12,
but it turns out that a better solution was committed in r348309 but not
MFCed.  So, revert this change since it is unnecessary and not really
correct: it assumes that the order in which module metadata records is
defined determines their order in the output linker set.  While this
seems to hold in my testing, it is not guaranteed.

Reported by:	cem
Discussed with:	imp
MFC after:	3 days
2021-01-23 10:59:41 -05:00
Mark Johnston
aa37baf3d7 Define PNP info after defining driver modules
PNP info definitions currently have an unfortunate requirement in that
they must follow the associated module definition in the module metadata
linker set.  Otherwise devmatch can segfault while processing the linker
hints file since kldxref maintains the order in the linker set.

A number of drivers violate this requirement.  In some cases this can
cause devmatch(8) to segfault when processing the linker hints file.
Work around the problem for now simply by adjusting the drivers.

Reviewed by:	imp
MFC after:	1 week
Sponsored by:	Rubicon Communications, LLC ("Netgate")
Differential Revision:	https://reviews.freebsd.org/D28260
2021-01-21 14:30:18 -05:00
Andriy Gapon
2c98edd6d6 htu21: driver for HTU21D I2C temperature and humidity sensor
MFC after:	2 weeks
Relnotes:	perhaps
2021-01-19 15:08:51 +02:00
Vladimir Kondratyev
8ffcde2554 hid: fix extraneous SYSCTL_ADD_INT() options revealed by LINT build
Reviewed by:	hselasky (as part of D28060)
2021-01-10 22:17:20 +03:00
Vladimir Kondratyev
b1f1b07f6d hid: Import iichid - I2C transport backend for HID subsystem
This implements hid_if.m methods for HID-over-I2C protocol [1].

Following kernel options are added:

IICHID_SAMPLING - Enable support for a sampling mode as interrupt
                  resource acquisition is not always possible in a case
                  of GPIO interrupts.
IICHID_DEBUG    - Enable debug output.

The module is based on prior Marc Priggemeyer work (D16698).

[1] http://download.microsoft.com/download/7/d/d/7dd44bb7-2a7a-4505-ac1c-7227d3d96d5b/hid-over-i2c-protocol-spec-v1-0.docx

Differential revision:	https://reviews.freebsd.org/D27892
2021-01-08 02:18:43 +03:00
Michal Meloun
6844eecfed Add basic support for Freescale LX2160A SoC.
All peripherals but the network processor are supported.
2020-12-05 12:08:37 +00:00
Michal Meloun
e62f770bca Add a driver for FAN53555 based PMIC. 2020-12-04 15:23:43 +00:00
Michal Meloun
81359d594f Add a driver for HYM8563 based RTC. 2020-12-04 15:09:42 +00:00
Michal Meloun
4388c70c08 Add a driver for ACT8846 used as PMIC for RK3288 SoC. 2020-12-04 14:57:12 +00:00
Vladimir Kondratyev
9c6e377448 Add plug and play information macroses for ACPI and I2C buses.
Matching table format is compatible with ACPI_ID_PROBE bus method.

Note that while ACPI_ID_PROBE matches against _HID and all _CIDs, current
acpi_pnpinfo_str() exports only _HID and first _CID.  That means second
and further _CIDs should be added to both acpi_pnpinfo_str() and
ACPICOMPAT_PNP_INFO if device matching against them is required.

Reviewed by:	imp
MFC after:	2 weeks
Differential Revision:	https://reviews.freebsd.org/D26824
2020-10-31 22:15:59 +00:00
Nathan Whitehorn
3a3332a0b8 Provide a slightly more-tolerant set of thermal parameters for PowerMac
motherboard temperatures. In particular, the U4 northbridge die is very
hard to cool or heat effectively with fans and is not responsive to load.
It generally sits around 64C, where it seems happy, so (like Linux) just
declare that to be its target temperature.

This makes the PowerMac G5 much less loud, with no change in the
temperatures of any system components.

MFC after:	2 weeks
2020-10-15 13:43:43 +00:00
Ian Lepore
c88da3b94d Bug fixes for the ads111x driver... make configurable gain and sample rate
hints work on per-channel basis as documented, rather than chip-wide.  Also,
when configured via hints, return BUS_PROBE_NOWILDCARD on successful hints
match, so that the hints don't bogusly match other types of i2c chips.
2020-10-12 18:02:51 +00:00
Warner Losh
44a8153672 Don't do the busy dance in icee_open/close
We don't need to do the busy dance for this driver. It's handled by
destroy_dev() entirely. Since all we did was busy/unbusy in
open/close, just delete them. We therefore don't need to track closes
either.

Reviewed by: ian@
Differential Revision: https://reviews.freebsd.org/D26431
2020-09-14 23:30:04 +00:00
Andriy Gapon
6305020526 twsi: some variants clear interrupt flag by writing 0, others by writing 1
Make that distinction more explicit and regular in the code.
The difference in behavior is documented in the respective datasheets.

Previously, the code handled the distinction by writing the control
register multiple times where at least one write was zero and another
was one.

This can be considered a follow-up to r363021.

Reviewed by:	manu
MFC after:	4 weeks
Differential Revision: https://reviews.freebsd.org/D26308
2020-09-07 06:32:03 +00:00
Andriy Gapon
e21a4ccfd1 twsi: use tsleep instead of pause for better responsiveness
wakeup() does not have any effect on pause(), so if a transfer was
not finished by the time of the first check, then the thread
would sleep full 30 ms.

To do: protect the transfer and interrupt code with the mutex,
switch from tsleep from msleep

Reviewed by:	manu
MFC after:	3 weeks
Differential Revision: https://reviews.freebsd.org/D26309
2020-09-07 06:29:41 +00:00
Andriy Gapon
e7fe5d60b1 move defintion of hw.i2c sysctl node from iicbb to iicbus
MFC after:	2 weeks
2020-09-03 08:02:19 +00:00
Andriy Gapon
0524c5fc82 twsi: no need to compare boolean with boolean constant
Testing the boolean directly is shorter and more idiomatic.

MFC after:	1 week
2020-09-03 08:01:21 +00:00
Andriy Gapon
d6adffa570 twsi: replace a couple of errno codes with i2c error codes
Reviewed by:	manu
MFC after:	1 week
2020-09-03 07:42:53 +00:00
John Baldwin
85b29fea3c Fix the variable name passed to OF_getprop().
Reported by:	tinderbox
2020-09-02 22:27:30 +00:00
Ian Lepore
ac07cdf8f7 In ltc430x(4), add the ability to configure control register 2 via FDT or
hints data.  Control register 2 holds the settings a user might want to
configure, such as the timeout value for idle busses and whether to enable
the mass-writes feature.

Also add hint support for disconnecting idle busses (which was already
supported using FDT data).

Update the manpage with the new features, and also split the hints section
into separate lists of required and optional hints.
2020-09-02 19:37:47 +00:00
Andriy Gapon
eda20682cb iicmux: fix a sign error in comparison
Because pcell_t is unsigned both sides of the comparison were treated as
such.
Because of that error iicmux created all possible sub-buses even if only
a subset was defined in the device tree.

MFC after:	1 week
2020-08-18 12:14:01 +00:00
Ian Lepore
d4fb0c0a56 The ds3231 RTC chip bitmask values for 12- versus 24-hour mode were reversed,
flip them so that times in the 20:00:00 to 23:59:59 range read correctly.

Reported by:	Dr. Rolf Jansen <freebsd-rj@obsigna.com>
Pointy hat:	ian@
2020-07-19 18:53:19 +00:00
Emmanuel Vadot
e18c80bcb6 twsi: Fix for > Allwinner A20
Every revision of twsi after the A20 have a bug where we need to
write again the control register after each interrupts. We also need
to add some delay before writing to this register, a simple read of the
same register does the job so do that.
Also fix the case when we have finish sending all the bytes, it only worked
for 1 byte transfer (the same kind that we do for talking to the PMIC on A20
boards).
While here add more debug messages and rework some of them.

This was tested by talking to a AT23C32 eeprom and a DS3231 RTC from an
H3 and A20 board.

PR:		247576
Reported by:	Manuel Stühn (freebsd@justmail.de)
MFC after:	1 week
2020-07-08 19:14:44 +00:00
Andriy Gapon
4b869dd71d iicbb: rebuild the bit-banging algorithms using different primitives
I2C_SET was quite inflexible, it used too long delays as well as some
unnecessary delays.  The new building blocks are iicbb_clockin and
iicbb_clockout.  The former sets SDA and starts the high period of SCL,
the latter executes the low period of SCL.  What happens during the high
phase depends on the operation.  For writes we just hold both lines, for
reads we poll SDA.  S, Sr and P change SDA in the middle of the high
period.

Also, the calculation of udelay has been updated, so that the resulting
period more closely corresponds the requested bus frequency.  There is a
new knob, io_delay, that allows to further adjust udelay based on the
estimated latency of pin toggling operations.

Finally, I slightly changed debug tracing and added error indicators to
it.  The debug prints are compiled in but disabled by default.  This can
be of use if there is any fallout from this change.

Some ideas for further improvements:
- add a function for sub-microsecond delays (e.g., in units of 1/10th of
  a microsecond) and use it for more precise timing of short delays;
- account for the actual time spent in the pin I/O.

Some sample debug output with the new code follows.

Reading temperature and humidity from HTU21 in the bus hold mode:
  <<w80+ we3+ <w81+ .....r6d+ rac+ r94- >>
  <<w80+ we5+ <w81+ .............r47+ re2+ r84- >>
where '<<' is S, '<' is Sr, '>>' is P, '.' is one millisecond of clock
stretching by the slave.

Reading temperature and humidity in the no-hold mode:
  <<w80+ wf3+ >>
  <<w81- >>
  <<w81+ r6d+ r54+ raf- >>
  <<w80+ wf5+ >>
  <<w81- >>
  <<w81+ r48+ r4e+ r9c- >>
where '+' is Ack and '-' is NoAck.
We see that first read attempts are not acknowledged.

MFC after:	4 weeks
Differential Revision: https://reviews.freebsd.org/D22206
2020-06-11 05:34:31 +00:00
Marcin Wojtas
d97d838569 Introduce support for Epson RX-8803 RTC.
This patch introduces support for Epson RX-8803 RTC controller accessible
over I2C bus. It has a resolution of 1 sec.
Support for interrupt based alarm was not implemented.

Submitted by: Kornel Duleba <mindal@semihalf.com>
Reviewed by: manu
Obtained from: Semihalf
Sponsored by: Alstom Group
Differential Revision: https://reviews.freebsd.org/D24364
2020-05-25 15:40:02 +00:00
Marcin Wojtas
7187ccccdc Add TCA6416 GPIO expander support.
Add basic TCA6416 GPIO expander support over I2C bus. The driver handles
enabling and disabling pins, setting pin mode to IN and OUT and
toggling the pins. External interrupts are not supported.

Submitted by: Dawid Gorecki <dgr@semihalf.com>
Reviewed by: manu, mmel
Obtained from: Semihalf
Sponsored by: Alstom Group
Differential Revision: https://reviews.freebsd.org/D24363
2020-05-25 15:31:43 +00:00
Andriy Gapon
36b9e62831 acpi_iicbus: set device description in the probe method
Kernel prints the device announcement before the attach method is
called, so if the correct description is not set by the probe method,
then the announcement would have an incorrect one.

MFC after:	1 week
2020-04-24 07:55:39 +00:00
Vladimir Kondratyev
9b7938dcf3 iicbus(4): Add support for ACPI-based children enumeration
When iicbus is attached as child of Designware I2C controller it scans all
ACPI nodes for "I2C Serial Bus Connection Resource Descriptor" described
in section 19.6.57 of ACPI specs.
If such a descriptor is found, I2C child is added to iicbus, it's I2C
address, IRQ resource and ACPI handle are added to ivars. Existing
ACPI bus-hosted child is deleted afterwards.

The driver also installs so called "I2C address space handler" which is
disabled by default as nontested.
Set hw.iicbus.enable_acpi_space_handler loader tunable to 1 to enable it.

Reviewed by:		markj
MFC after:		2 weeks
Differential Revision:	https://reviews.freebsd.org/D22901
2020-03-09 20:31:38 +00:00
Andreas Tobler
5870983d6e Drop 'All rights reserved'
Replace hardcoded sizes by nitems and sizeof
Replace CTLFLAG_NEEDGIANT with CTLFLAG_MPSAFE, I run this driver since a few
years with CTLFLAG_MPSAFE w/o issues.
Add a HACK to handle a special case for a sensor location.
2020-03-06 21:32:42 +00:00
Andreas Tobler
a68ab49154 Drop 'All rights reserved'
Replace hardcoded size by nitems
2020-03-06 21:26:35 +00:00
Andreas Tobler
e65d6406fd Drop 'All rights reserved'
Replace hardcoded sizes by nitems and sizeof
2020-03-06 21:24:09 +00:00
Andreas Tobler
7cc4d41e40 - Drop 'All rights reserved'
- Replace hardcoded size by nitems
2020-03-06 21:21:01 +00:00
Pawel Biernacki
7029da5c36 Mark more nodes as CTLFLAG_MPSAFE or CTLFLAG_NEEDGIANT (17 of many)
r357614 added CTLFLAG_NEEDGIANT to make it easier to find nodes that are
still not MPSAFE (or already are but aren’t properly marked).
Use it in preparation for a general review of all nodes.

This is non-functional change that adds annotations to SYSCTL_NODE and
SYSCTL_PROC nodes using one of the soon-to-be-required flags.

Mark all obvious cases as MPSAFE.  All entries that haven't been marked
as MPSAFE before are by default marked as NEEDGIANT

Approved by:	kib (mentor, blanket)
Commented by:	kib, gallatin, melifaro
Differential Revision:	https://reviews.freebsd.org/D23718
2020-02-26 14:26:36 +00:00
Emmanuel Vadot
b74b94d2a1 twsi: Rework how we handle the i2c messages
We use to handle each message separately in i2c_transfer but that cannot
work with message with NOSTOP as it confuses the controller that we disable
the interrupts and start a new message.
Handle every message in the interrupt handler and fire a new start condition
if the previous message have NOSTOP, the controller understand this as a
repeated start.
This fixes booting on Allwinner A10/A20 platform where before the i2c controller
used to write 0 to the PMIC register that control the regulators as it though that
this was the continuation of the write message.

Tested on:   A20 BananaPi, Cubieboard 1 (kevans)
Reported by:	kevans
MFC after:	1 month
2020-01-10 18:52:14 +00:00
Ian Lepore
e371a9e6cc Remove some trailing whitespace; no functional changes. 2020-01-08 23:06:13 +00:00
Ian Lepore
ca16c2b8de Split the code to find and add iicbus children out to its own function.
Move the decision to take an early exit from that function after adding
children based on FDT data into the #ifdef FDT block, so that it doesn't
offend coverity's notion of how the code should be written.  (What's the
point of compilers optimizing away dead code if static analyzers won't
let you use the feature in conjuction with an #ifdef block?)

Reported by:	coverity via vangyzen@
2020-01-08 23:03:47 +00:00
Ian Lepore
a5910414d4 Change some KASSERT to device_printf + return EINVAL. There's no need to
bring the whole kernel down due to a configuration error detected when a
module is loaded, it suffices to just not attach the device.
2020-01-08 22:48:14 +00:00
Ian Lepore
b29fdcf8b3 Init sc->maxbus to -1, not 0. It represents the highest array index that
has a non-NULL child bus stored in it, so the "none" value can't be zero
since that's a valid array index.  Also, when adding all possible buses
because there is no specific per-bus config, there's no need to reset
sc->maxbus on each loop iteration, it can be set once after the loop.
2020-01-08 22:45:32 +00:00
Ian Lepore
d9b35549d4 Ensure any reserved gpio pins get released if an early exit is taken
from the attach function.
2020-01-08 22:06:31 +00:00
Ian Lepore
422d05da14 Add support for i2c bus mux hardware.
An i2c bus can be divided into segments which can be selectively connected
and disconnected from the main bus. This is usually done to enable using
multiple slave devices having the same address, by isolating the devices
onto separate bus segments, only one of which is connected to the main bus
at once.

There are several types of i2c bus muxes, which break down into two general
categories...

 - Muxes which are themselves i2c slaves. These devices respond to i2c
   commands on their upstream bus, and based on those commands, connect
   various downstream buses to the upstream. In newbus terms, they are both
   a child of an iicbus and the parent of one or more iicbus instances.
 - Muxes which are not i2c devices themselves. Such devices are part of the
   i2c bus electrically, but in newbus terms their parent is some other
   bus. The association with the upstream bus must be established by
   separate metadata (such as FDT data).

In both cases, the mux driver has one or more iicbus child instances
representing the downstream buses. The mux driver implements the iicbus_if
interface, as if it were an iichb host bridge/i2c controller driver. It
services the IO requests sent to it by forwarding them to the iicbus
instance representing the upstream bus, after electrically connecting the
upstream bus to the downstream bus that hosts the i2c slave device which
made the IO request.

The net effect is automatic mux switching which is transparent to slaves on
the downstream buses. They just do i2c IO they way they normally do, and the
bus is electrically connected for the duration of the IO and then idled when
it is complete.

The existing iicbus_if callback() method is enhanced so that the parameter
passed to it can be a struct which contains a device_t for the requesting
bus and slave devices. This change is done by adding a flag that indicates
the extra values are present, and making the flags field the first field of
a new args struct. If the flag is set, the iichb or mux driver can recast
the pointer-to-flags into a pointer-to-struct and access the extra
fields. Thus abi compatibility with older drivers is retained (but a mux
cannot exist on the bus with the older iicbus driver in use.)

A new set of core support routines exists in iicbus.c. This code will help
implement mux drivers for any type of mux hardware by supplying all the
boilerplate code that forwards IO requests upstream. It also has code for
parsing metadata and instantiating the child iicbus instances based on it.

Two new hardware mux drivers are added. The ltc430x driver supports the
LTC4305/4306 mux chips which are controlled via i2c commands. The
iic_gpiomux driver supports any mux hardware which is controlled by
manipulating the state of one or more gpio pins.  Test Plan

Tested locally using a variety of mux'd bus configurations involving both
ltc4305 and a homebrew gpio-controlled mux. Tested configurations included
cascaded muxes (unlikely in the real world, but useful to prove that 'it all
just works' in terms of the automatic switching and upstream forwarding of
IO requests).
2020-01-02 17:51:49 +00:00
Philip Paeps
15c023175f iicoc: fix the build on PCI machines
Pointy hat to:   philip
2019-12-20 05:15:03 +00:00
Philip Paeps
6386edbb5a iicoc: add FDT bus attachment
This adds support for OpenCores I2C master controllers on FDT systems.

Reviewed by:    kp
Sponsored by:   Axiado
2019-12-20 03:40:50 +00:00
Philip Paeps
eb95689a82 iicoc: split up common core and PCI bus specifics
The OpenCores I2C IP core can be found on any bus.  Split out the PCI
bus specifics into their own file, only compiled on systems with PCI.

Reviewed by:    kp
Sponsored by:   Axiado
2019-12-20 03:40:46 +00:00
Philip Paeps
fe434b6acf iicoc: minor whitespace and style(9) fixes
No functional changes.  This commit will make upcoming changes
which do affect functionality easier to read.

Reviewed by:    kp
Sponsored by:   Axiado
2019-12-20 03:40:07 +00:00
Ian Lepore
7c280087a4 If device_delete_children() returns an error, bail on the rest of the
detach work and return the error.  Especially don't call iicbus_reset()
since the most likely cause of failing to detach children is that one
of them has IO in progress.
2019-12-13 02:20:26 +00:00
Ian Lepore
dbb7749081 Clean up some of my copyrights; add SPDX tag and remove All rights reserved. 2019-12-13 01:38:48 +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
Emmanuel Vadot
357145a0ce Remove "all rights reserved" from copyright for the file that Jared McNeill
own. He gave me permission to do this.
2019-12-03 21:05:33 +00:00
Ian Lepore
e3c42ad809 Rewrite iicdev_writeto() to use a single buffer and a single iic_msg, rather
than effectively doing scatter/gather IO with a pair of iic_msgs that direct
the controller to do a single transfer with no bus STOP/START between the
two buffers.  It turns out we have multiple i2c hardware drivers that don't
honor the NOSTOP and NOSTART flags; sometimes they just try to do the
transfers anyway, creating confusing failures or leading to corrupted data.
2019-11-21 19:13:05 +00:00
Vladimir Kondratyev
db7caa2ea7 [ig4] Add suspend/resume support
That is done with re-execution of controller initialization procedure
from resume handler.

PR:		238037
2019-11-03 21:00:55 +00:00