Commit Graph

420 Commits

Author SHA1 Message Date
Andriy Gapon
94f4afd772 rk805 / rk808: re-add system poweroff support
This was lost by accident in 98c60dc31f.

Reviewed by:	manu
MFC after:	2 weeks
Differential Revision:	https://reviews.freebsd.org/D33844
2022-01-11 16:22:36 +02:00
Andriy Gapon
46e0c03795 twsi: use twsi_error() to handle wrong bus status when starting
MFC after:	1 week
2021-12-19 12:05:52 +02:00
Andriy Gapon
e5268c3d43 twsi: fix handling of consecuitve write messages in transaction
Make sure to reset 'message_done' flag when jumping from a message to the
next one within the same interrupt handler call.  This happens only when
a write with no-stop flag message is followed by a write with no-start
flag message.
Without this fix the second message would be prematurely "completed"
without waiting for an ACK (or NACK) for its first byte and without
sending subsequent bytes (if any).

Fixes:		ff1e8581 twsi: support more message combinations in transfers
MFC after:	4 days
2021-12-19 12:05:52 +02:00
Mateusz Guzik
f48ab7cc48 iicbus: plug set-but-not-used vars
Sponsored by:	Rubicon Communications, LLC ("Netgate")
2021-12-18 13:14:04 +00:00
Hubert Mazur
3e5fe3d5bf pcf85063: Set RTC device to work in 24h mode
Sometimes the device did not set default hour mode setting correctly,
which lead to conversion errors. Explicitly set device to work in 24h
mode by clearing flag in register, instead of allowing defaults.

Reviewed by:		imp
Obtained from:		Semihalf
Sponsored by:		Alstom Group
Differential revision:	https://reviews.freebsd.org/D33497
2021-12-17 11:07:07 +01:00
Andriy Gapon
b277ef3304 ds3231: fix accidental breakage of !FDT in 1256067c
MFC after:	10 days
2021-12-13 13:49:47 +02:00
Andriy Gapon
1256067c5c ds3231: allow configuration via hints on FDT systems
MFC after:	10 days
2021-12-13 13:40:00 +02:00
Andriy Gapon
b416345d5b pcf8591: remove write-only variables
MFC after:	1 week
2021-12-13 13:39:08 +02:00
Hubert Mazur
3662b8f1cf pcf85063: Fix real time clock
Previosuly real time clock driver always set time format to 12-hour
mode. Fix this by choosing hour mode depending on HW register.
2021-12-10 17:09:29 +01:00
Hubert Mazur
f89f6f9581 TMP461: Add thermal sensor driver
Add driver for TMP461 thermal sensor. Register new sysctl node
of integer type for device. Read register and fill sysctl with
valid temperature.

Reviewed by:
Sponsored by:		Alstom
Obtained from:		Semihalf
Differential revision:	https://reviews.freebsd.org/D32818
2021-12-02 09:18:48 +01:00
Vladimir Kondratyev
c508b0818b iichid(4): Perform acknowledgement of I2C device interrupt after RESET command
in sampling mode to workaround firmware bug.

This fixes reboot or poweroff on frame.work laptops after first touch.

Reported by:	many
PR:		259230
MFC after:	1 week
Tested by:	kevans, markj
2021-12-01 00:29:50 +03:00
Andriy Gapon
ff1e858180 twsi: support more message combinations in transfers
Most prominently, add support for a transfer where a write with no-stop
flag is followed by a write with no-start flag.  Logically, it's a
single larger write, but consumers may want to split it like that
because one part can be a register ID and the other part can be data to
be written to (or starting at) that register.

Such a transfer can be created by i2c tool and iic(4) driver, e.g., for
an EEPROM write at specific offset:
    i2c -m tr -a 0x50 -d w -w 16 -o 0 -c 8 -v < /dev/random

This should be fixed by new code that handles the end of data transfer
for both reads and writes.  It handles two existing conditions and one
new.  Namely:
- the last message has been completed -- end of transfer;
- a message has been completed and the next one requires the start
  condition;
- a message has been completed and the next one should be sent without
  the start condition.

In the last case we simply switch to the next message and start sending
its data.  Reads without the start condition are not supported yet,
though.  That's because we NACK the last byte of the previous message,
so the device stops sending data.  To fix this we will need to add a
look-ahead at the next message when handling the penultimate byte of the
current one.

This change also fixed a bug where msg_idx was not incremented after a
read message.  Apparently, typically a read message is a last message in
a transfer, so the bug did not cause much trouble.

PR:		258994
MFC after:	3 weeks
2021-11-26 16:20:27 +02:00
Andriy Gapon
00c07d9559 twsi: make data receiving code safer
Assert that we are not receiving data beyond the requested length.
Assert that we have not NACK-ed incoming data prematurely.
Abort the current transfer if the incoming data is NACK-ed or not
NACK-ed unexpectedly.

Add debug logging of received data to complement logging of sent data.

MFC after:	3 weeks
2021-11-26 16:18:51 +02:00
Andriy Gapon
aeacf172fd twsi: remove redundant write of control register
The write at the end of twsi_intr() already handles all cases, no need
to have another write for TWSI_STATUS_START / TWSI_STATUS_RPTD_START.

MFC after:	3 weeks
2021-11-26 16:18:30 +02:00
Andriy Gapon
04622a7f21 twsi: move handling of TWSI_CONTROL_ACK into the state machine
Previously the code set TWSI_CONTROL_ACK in twsi_transfer() based on
whether the first message had a length of one.  That was done regardless
of whether the message was a read or write and what kind of messages
followed it.
Now the bit is set or cleared while handling TWSI_STATUS_ADDR_R_ACK
state transition based on the current (read) message.

The old code did not correctly work in a scenario where a single byte
was read from an EEPROM device with two byte addressing.
For example:
    i2c -m tr -a 0x50 -d r -w 16 -o 0 -c 1 -v
The reason is that the first message (a write) has two bytes, so
TWSI_CONTROL_ACK was set and never cleared.
Since the controller did not send NACK the EEPROM sent more data resulting
in a buffer overrun.

While working on TWSI_STATUS_ADDR_R_ACK I also added support for
the zero-length read access and then I did the same for zero-length write
access.
While rare, those types of I2C transactions are completely valid and are
used by some devices.

PR:		258994
MFC after:	3 weeks
2021-11-26 16:17:24 +02:00
Andriy Gapon
a4fe892208 twsi: unify error handling, explicitly handle more conditions
twsi_error() is a new function that stops the current transfer and sets
up softc when an error condition is detected.
TWSI_STATUS_DATA_WR_NACK, TWSI_STATUS_BUS_ERROR and
TWSI_STATUS_ARBITRATION_LOST are now handled explicitly rather than
via the catch-all unknown status.

Also, twsi_intr() now calls wakeup() in a single place when the
transfer is finished.

MFC after:	2 weeks
2021-11-26 16:16:21 +02:00
Andriy Gapon
578707ed4e twsi: improve a handful of debug messages
- use 0x prefix for hex values
- print indexes and counts as decimals
- break too long lines

MFC after:	2 weeks
2021-11-26 16:16:01 +02:00
Andriy Gapon
cb167e1ae9 twsi: do not attempt transfer if bus is not idle
MFC after:	2 weeks
2021-11-26 16:15:43 +02:00
Andriy Gapon
bc02583c4d twsi: remove redundant enabling of the controller
MFC after:	2 weeks
2021-11-26 16:15:21 +02:00
Andriy Gapon
69cfa60ddd twsi: protect interaction between twsi_transfer and twsi_intr
All accesses to softc are now done under a mutex to prevent data races
between the open context and the interrupt handler.
Additionally, the wait time in twsi_transfer is bounded now.
Previously we could get stuck there forever if an interrupt got lost.

MFC after:	2 weeks
2021-11-26 16:14:28 +02:00
Andriy Gapon
a2793d6182 twsi: compile in support for debug messages, disabled by default
Debug messages can now be enabled per driver instance via a new sysctl.
Also, debug messages in TWSI_READ and TWSI_WRITE require debug level
greater than 1 as they are mostly redundant because callers of those
functions already log most interesting results.

NB: the twsi drivers call their device iichb, so the new sysctl will
appear under dev.iichb.N.

MFC after:	1 week
2021-11-26 16:04:23 +02:00
Andriy Gapon
f00bc54f62 twsi: remove write-only softc field
MFC after:	1 week
2021-11-26 16:04:14 +02:00
Andriy Gapon
de86f339cd twsi: add more of status definitions
For completeness and for future use.

MFC after:	1 week
2021-11-26 16:03:38 +02:00
Andriy Gapon
26559dd177 twsi: sort headers, remove unneeded
MFC after:	1 week
2021-11-26 16:03:38 +02:00
Hubert Mazur
26d6547567 Pcf85063: Add RTC driver
Add driver for pcf85063 real time clock. Register set and get time
methods. Parse data obtained from bus according to specification
and fill kernel structures.

Obtained from: Semihalf
Sponsored by: Alstom Group
Differential revision: https://reviews.freebsd.org/D32817
2021-11-24 07:40:38 +01:00
Hubert Mazur
cb35af13f9 TCA6408: Add driver for tca6408 gpio expander
Driver for tca6408 gpio expander over i2c bus. Expose API for
manipulating pin's direction, state and polarity inversion.

Obtained from: Semihalf
Sponsored by: Alstom Group
Differential revision: https://reviews.freebsd.org/D32819
2021-11-24 07:40:38 +01:00
Emmanuel Vadot
91a908e051 pmic: rockchip: Rename the driver with _pmu as it was before 2021-11-14 20:26:33 +01:00
Emmanuel Vadot
c200441872 pmic: rockchip: Name the driver rk80{5,8}
And add the needed relationship with iicbus.
2021-11-14 13:48:10 +01:00
Emmanuel Vadot
98c60dc31f pmic: rockchip: Split the driver in rk805 and rk808
This make the base driver cleaner and the subclassed driver only have
related code.

Kernel config wise this is still only handled by rk805.

No functional changes intended.
2021-11-14 12:31:26 +01:00
Emmanuel Vadot
cb3c3e0a42 pmic: rockchip: Split the clocks part in its own file
No functional changes intended.
2021-11-14 12:31:23 +01:00
Emmanuel Vadot
ad651f176b pmic: rockchip: Split the regulators part in its own file
No functional changes intended.
2021-11-14 12:31:21 +01:00
Emmanuel Vadot
328077bb8f pmic: rockchip: Split the rtc part in its own file
Even if for now all the RTC-related register are at the same offset don't
use some hardcoded values for them but set them based on the PMIC type.

No functional changes intended.
2021-11-14 12:31:18 +01:00
Emmanuel Vadot
c9b101d241 pmic: rockchip: Rename most of rk805 driver to rk8xx
This is in preparation of correctly splitting the driver.

No functional changes intended.
2021-11-14 12:31:15 +01:00
Emmanuel Vadot
43301ad2b6 pmic: rockchip: Add dedicated file for rk808
While here rename registers for rk805 and rk808 based on the names
on the datasheet.

No functional changes intended.
2021-11-14 12:31:12 +01:00
Emmanuel Vadot
51919325ff arm64: rockchip: Move rk805 pmic driver to dev/iicbus/pmic/rockchip
Having all PMIC driver at the same place makes it easier.
2021-11-14 12:31:07 +01:00
Andriy Gapon
c0525ab1d1 pca954x: driver for PCA954x / TCA954x I2C switches
At the moment only PCA9548A is supported and has been tested.

MFC after:	2 weeks
2021-11-13 11:27:41 +02:00
Andriy Gapon
01e3492337 icee: allow configuration via hints on FDT-based systems
On-board devices should be configured via the FDT and overlays.
Hints are primarily useful for external and temporarily attached devices.
Adding hints is much easier and faster than writing and compiling
an overlay.

MFC after:	2 weeks
2021-11-13 11:24:57 +02:00
Andriy Gapon
27645265c4 ds1307: allow configuration via hints on FDT-based systems
On-board devices should be configured via the FDT and overlays.
Hints are primarily useful for external and temporarily attached devices.
Adding hints is much easier and faster than writing and compiling
an overlay.

MFC after:	2 weeks
2021-11-13 11:23:10 +02:00
Andriy Gapon
43b031a371 htu21: don't needlessly bother hardware when measurements are not needed
sysctl(8) first queries a sysctl to get a size of its value even if the
sysctl is of a fixed size, e.g. it has an integer type.
Only after that sysctl(8) queries an actual value of the sysctl.

Previosuly the driver would needlessly read a sensor in the first step.

MFC after:	1 week
2021-11-06 19:39:52 +02:00
Andriy Gapon
a75159eabc htu21: allow configuration via hints on FDT-based systems
On-board devices should be configured via the FDT and overlays.
Hints are primarily useful for external and temporarily attached devices.
Adding hints is much easier and faster than writing and compiling
an overlay.

MFC after:	1 week
2021-11-06 19:24:44 +02:00
Andriy Gapon
6354154ef5 pcf8574: driver for 8-pin quasi-bidirectional GPIO over I2C
MFC after:	2 weeks
2021-11-06 19:23:27 +02:00
Andriy Gapon
ff6fe29835 driver for MAX44009 I2C illuminance sensor 2021-11-06 19:19:04 +02:00
Andriy Gapon
a60b304697 pcf8591: driver for adc/dac with i2c interface 2021-11-06 19:14:50 +02:00
Thomas Skibo
99443830fa iicoc: support building as a module
Only build on RISC-V for now, since we're not aware of any other cores
with this IP supported by FreeBSD.

Reviewed by:	jrtc27, philip
MFC after:	3 days
Differential Revision:	https://reviews.freebsd.org/D32737
2021-11-01 12:33:39 +08:00
Thomas Skibo
2a36909a94 iicoc: fix repeated start
Reviewed by:	jrtc27, philip
MFC after:	3 days
Differential Revision:	https://reviews.freebsd.org/D32737
2021-11-01 12:29:29 +08:00
Thomas Skibo
e528757ca6 iicoc: add support for SiFive HiFive Unmatched
Reviewed by:	jrtc27, philip
MFC after:	3 days
Differential Revision:	https://reviews.freebsd.org/D32737
2021-11-01 12:26:49 +08:00
Zhenlei Huang
62e1a437f3 routing: Allow using IPv6 next-hops for IPv4 routes (RFC 5549).
Implement kernel support for RFC 5549/8950.

* Relax control plane restrictions and allow specifying IPv6 gateways
 for IPv4 routes. This behavior is controlled by the
 net.route.rib_route_ipv6_nexthop sysctl (on by default).

* Always pass final destination in ro->ro_dst in ip_forward().

* Use ro->ro_dst to exract packet family inside if_output() routines.
 Consistently use RO_GET_FAMILY() macro to handle ro=NULL case.

* Pass extracted family to nd6_resolve() to get the LLE with proper encap.
 It leverages recent lltable changes committed in c541bd368f.

Presence of the functionality can be checked using ipv4_rfc5549_support feature(3).
Example usage:
  route add -net 192.0.0.0/24 -inet6 fe80::5054:ff:fe14:e319%vtnet0

Differential Revision: https://reviews.freebsd.org/D30398
MFC after:	2 weeks
2021-08-22 22:56:08 +00:00
Vladimir Kondratyev
82626fef62 iichid(4): Perform bus_teardown_intr/bus_setup_intr to disable interrupts
during suspend/resume cycle. Previously used bus_generic_suspend_intr and
bus_generic_resume_intr may cause interrupt storm because of missed
interrupt acknowledges caused by blocking of intr handler.

Reported by:	J.R. Oldroyd <jr_AT_opal_DOT_com>
MFC after:	1 week
2021-07-09 22:32:59 +03: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
J.R. Oldroyd
5236888db7 iichid(4): disable interrupt on suspend
Commit message of the identical change in Linux driver says:
"When an I2C HID device is powered off during system sleep, as a result
of removing its power resources (by the ACPI core) the interrupt line
might go low as well.  This results inadvertent interrupts."

This change fixes suspend/resume on Asus S510UQ laptops.

While here add a couple of typo fixes as well as a slight change to the
iichid_attach() code to have the power_on flag set properly.

Submitted by:	J.R. Oldroyd <jr_AT_opal_DOT_com>
Reviewed by:	wulf
MFC after:	1 week
2021-05-31 22:33:07 +03:00