Commit Graph

193 Commits

Author SHA1 Message Date
Ganbold Tsagaankhuu
37d97b10ff Fix style. 2023-04-07 03:18:42 +00:00
Ganbold Tsagaankhuu
4720afaffe Improve RK3568 pcie phy handling codes a bit.
Move phy bifurcation code to a separate function
that can be called during the attach phase.
Also initialize both pcie lanes accordingly.
2023-04-07 02:54:13 +00:00
Ganbold Tsagaankhuu
396b6914c9 Fix pcie phy enabling codes for RK3568 SoC.
Handle data-lanes property for pcie phy and set it accordingly.
This makes devices attached to pcie3 work properly.
For some RK3568 based boards, RTL8125B based device is
connected it. So with this, realtek-re-kmod driver attaches
and works.

Partially obtained from OpenBSD.
Tested on NanoPI-R5S, FireFly Station P2 boards.
2023-04-04 02:50:29 +00:00
Ganbold Tsagaankhuu
b98fbf3781 Fix driver name.
Submitted by:	Tyuryukanov S.Y.
2023-04-03 14:20:28 +00:00
Andrew Turner
cb894f746c Map arm64 pci config memory as non-posted
On arm64 PCI config memory is expected to be mapped with a non-posted
device type. To handle this use the new bus_map_resource support in
arm64 to map memory with the new VM_MEMATTR_DEVICE_NP attribute. This
memory has already been allocated and activated, it just needs to be
mapped.

Reviewed by:	kevans, mmel
Differential Revision:	https://reviews.freebsd.org/D30079
2023-03-05 20:17:21 +00:00
Søren Schmidt
11b5b9e8a5 Add delay to have things settle. 2023-01-07 07:42:44 +00:00
Ganbold Tsagaankhuu
9427c47de6 Remove unnecessary sys/cdefs.h includes. 2023-01-07 06:05:52 +00:00
Val Packett
0b4531511e copyright: chase my name and email change
Reviewed by:	imp, emaste
Differential Revision:	https://reviews.freebsd.org/D37945
2023-01-06 15:28:42 -05:00
Ganbold Tsagaankhuu
90737b632e Use BSD-2-Clause for the SPDX license id as -FreeBSD variant has been deprecated. 2023-01-06 08:15:44 +00:00
Ganbold Tsagaankhuu
7e2600ea7b Add SPDX-License-Identifier. 2023-01-06 04:14:49 +00:00
Ganbold Tsagaankhuu
0d4a240b0d Remove unnecessary $Id string from license.
While there add SPDX-License-Identifier.
2023-01-06 04:10:09 +00:00
Søren Schmidt
5723e5ac6d Add Naneng combo PHY support for RK3568 SoC.
It can be used as pcie-phy, usb3-phy, sata-phy or sgmii-phy.
2023-01-06 03:04:53 +00:00
Søren Schmidt
7daf96523b Add PCIe driver for RK3568 SoC.
PCIe3 ports work, however PCIe2x1 is not working yet in this case as it depends on Naneng Combo Phy driver.
2023-01-05 04:15:56 +00:00
Søren Schmidt
79c6e0b31f Improve and make it more general Rockchip USB2PHY driver.
Add support for Rockchip RK3568.
2022-12-28 03:48:48 +00:00
Søren Schmidt
355cb40c3a Set RK3568 specific pin mux for GMAC1. 2022-12-28 03:00:19 +00:00
Andrew Turner
7ebc4c9bf7 Use hwreset_array in the Rockchip tsadc driver
The order of asserting/deasserting the resets doesn't matter so use
the new hwreset_array to manage them all.

Reviewed by:	manu
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D37358
2022-12-21 11:25:27 +00:00
Søren Schmidt
a48301a5e0 Add initial clocks support for Rockchip RK3568 SoC.
Partially from:	https://reviews.freebsd.org/D36027

This can be eventually improved or simplified or fixed if necessary.

Following devices work with proper drivers and with the necessary clocks:
Native networking via eqos driver
USB3 and USB2
PCIe support is working but a bit picky about what hardware it supports (but so is Linux)
SD & (e)MMC
With the EDK2 loader video also works

Supported hardwares are Quartz64, NanoPI R5S and Firefly Station P2, more to come as DTS files gets done.
2022-12-18 12:05:29 +00:00
Søren Schmidt
0e3c99cbed Fix/add compat strings for Rockchip RK356x GRF. 2022-12-18 11:22:11 +00:00
Søren Schmidt
896d3e43b1 Add driver for Rockchip One Time Programmable (OTP) device.
This driver created the possibility to assign fixed MAC adresses to eqos devices.
2022-12-12 14:34:18 +00:00
Emmanuel Vadot
dbd7bb7c89 arm64/rk_dwc3: Remove RK3328 support
The RK3328 dts doesn't have the glue node so we need the dwc3 driver
to attach directly.

Differential Revision:	https://reviews.freebsd.org/D37396
Sponsored by:	Beckhoff Automation GmbH & Co. KG
2022-11-16 11:58:31 +01:00
Andrew Turner
9142f3a885 Fix a rk356x pinctrl register offset
The pull-up/pull-down register offset was wrong on the Rockchip rk356x.
It was set such that the driver would modify the IOMUX control registers.

This seems to work with the current device tree files, but fails with
upstream files. Fix the offset so the later calculation has the correct
offset for the pull-up/pull-down control register.

Sponsored by:	The FreeBSD Foundation
2022-11-11 08:34:48 +00:00
Ganbold Tsagaankhuu
8eb94b238f Set denominator to 1 if it is 0 in the init phase.
This prevents panic and also helps when the clocks
become available later.
This is based on comment from manu@ on
https://reviews.freebsd.org/D31299
2022-10-01 02:01:59 +00:00
Ganbold Tsagaankhuu
48551d3240 Fix problem getting gpio version during attach.
Both RK3328 and RK3399 don't have GPIO_VER_ID register.
Set gpio version depending on compat string of the parent.
2022-09-01 07:21:56 +00:00
Søren Schmidt
ec556724d7 Add interrupt handling to rk_gpio driver. 2022-08-20 11:30:54 +00:00
Søren Schmidt
901df07a47 Code refactoring for existing rk_gpio driver.
It supports gpio type checking. Depending on gpio type some
register addresses are different.

Reviewed by:	manu
Differential Revision:	https://reviews.freebsd.org/D36262
2022-08-19 13:22:01 +00:00
Søren Schmidt
1331c0f44b Add support for RockChip RK356X to DWC3 driver.
For RK356x platform, we can set bit 26 of DWC3_GUCTL1 register
for usb 2.0 device.

Reviewed by:	manu
Differential Revision:	https://reviews.freebsd.org/D36211
2022-08-16 12:24:44 +00:00
Søren Schmidt
530d5f8338 Add RockChip RK356X support to existing RockChip iodomain driver. 2022-08-15 12:03:28 +00:00
Dimitry Andric
0fe8ab6851 Fix unused variable warning in rockchip's rk_spi.c
With clang 15, the following -Werror warning is produced:

    sys/arm64/rockchip/rk_spi.c:229:6: error: variable 'cnt' set but not used [-Werror,-Wunused-but-set-variable]
            int cnt = 0;
                ^

The 'cnt' variable was in rk_spi.c when it was first added, but it
appears to have been a debugging aid that has never been used, so remove
it.

MFC after:	3 days
2022-08-14 21:27:34 +02:00
Søren Schmidt
0b6d133c08 Add RockChip RK356X support to existing RockChip thermal driver. 2022-08-11 08:26:39 +00:00
Ganbold Tsagaankhuu
ace8bb34ce Add support for RK3568 to RockChip GRF and SPI drivers.
Partially from https://reviews.freebsd.org/D36027

Submitted by:	sos
2022-08-11 05:32:48 +00:00
Emmanuel Vadot
87f642ac03 arm64: rockchip: rk_gpio: Improve mode switching
Changing mode on a pin (input/output/pullup/pulldown) is a bit slow.
Improve this by caching what we can.
We need to check if the pin is in gpio mode, do that the first time
that we have a request for this pin and cache the result. We can't do
that at attach as we are a child of rk_pinctrl and it didn't finished
its attach then.
Cache also the flags specific to the pinctrl (pullup or pulldown) if the
pin is in input mode.
Cache the registers that deals with input/output mode and output value. Also
remove some register reads when we change the direction of a pin or when we
change the output value since the bit changed in the registers only affect output
pins.
2022-08-10 19:22:31 +02:00
Emmanuel Vadot
8d6b3a8570 arm64: rockchip: pinctrl: Do not rely on the node name
Node names for gpio bank were made generic in Linux 5.16 so stop
using them to map the gpio controller to the pin controller bank unit.

Sponsored by:	Beckhoff Automation GmbH & Co. KG
2022-08-10 15:47:22 +02:00
Ganbold Tsagaankhuu
5db5bd5f39 Add drive strength setting for RK3568 pinctrl driver.
Partially from https://reviews.freebsd.org/D36027

Submitted by:	sos
2022-08-08 04:42:22 +00:00
Ganbold Tsagaankhuu
eec3290266 Add RK3568 SoC support to pinctrl driver.
Submitted by:	sos
Reviewed by:	manu
Differential Revision:	https://reviews.freebsd.org/D31330
2022-07-09 13:06:52 +00:00
Andrew Turner
ee2324aaf6 Add Rockchip PCIe cleanup on attach faulure
We should clean up on failure as it may panic the kernel later, e.g.
if we crate the rman, but fail to destroy it on attach faulure.

Reviewed by:	imp
Sponsored by:	The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D35682
2022-07-04 15:27:01 +01:00
Andrew Turner
1c799a6f29 Support decoding mem32 memory in the rk pcie driver
This is needed with some dtb files.

While here use a switch statement as the two options are mutually
exclusive in any iteration of the loop.

Reviewed by:	imp
Sponsored by:	The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D35680
2022-07-04 15:27:00 +01:00
John Baldwin
b2c1681aa1 arm64 rockchip: Remove unused devclass arguments to DRIVER_MODULE. 2022-05-09 14:26:45 -07:00
John Baldwin
5f31d14a92 Remove unused spibus_devclass and ofw_spibus_devclass. 2022-05-09 12:22:00 -07:00
John Baldwin
85447c525b Remove unused ofw_iicbus_devclass. 2022-05-06 15:39:30 -07:00
John Baldwin
8bf0d2d3e3 arm64 rk_pcie: Use __diagused for a variable only used in KASSERT(). 2022-04-13 16:08:23 -07:00
John Baldwin
f4bd36ba2a rk_usbphy: Remove unused variable. 2022-04-08 18:31:29 -07:00
Andriy Gapon
b7bcd21d2d rk_i2c_fill_tx: fixup previous commit
I forgot to amend the previous commit where i was uninitialized.

Fixes:		c663545951 rk_i2c_fill_tx: fix a number of issues
MFC after:	1 week
2021-12-15 13:21:16 +02:00
Andriy Gapon
c663545951 rk_i2c_fill_tx: fix a number of issues
- maximum number of bytes that can be sent is 32, not 8;
- previous interface required callers to bump sc->msg->len in addition
  to setting sc->tx_slave_addr;
- because of the above there was an issue with writing one too many bytes
  because sc->cnt is not advanced when the slave address is written;
- the inetraction between outer and inner loops was confusing as the former
  was bounded on the number of bytes to write and the counter was
  incremented by one, but the inner loop advanced four bytes at a time;
- the return value was incorrect in the tx_slave_addr case; one call place
  had to use its own (and incorrect in some cases) notion of the write
  lenth.

All of the above issues should be fixed.
Some sanity asserts are added.
All callers use the return value to program RK_I2C_MTXCNT.
iic_msg::len no longer needs to be hacked.
A constant is added to reflect the maximum number of octets that can be
sent or received in one go (they are the same).

MFC after:	1 week
2021-12-15 13:16:14 +02:00
Andriy Gapon
25e92673b5 rk_i2c_transfer: minor improvement to bit twiddling
No need to mask a uint8_t with 0xff, the mask covers the whole type.
Explcitly cast to uint32_t before bit shifting instead of relying on
the implicit promotion to signed int.

MFC after:	1 week
2021-12-15 13:16:09 +02:00
Andriy Gapon
4501b07071 rk_i2c: do not hide NACK condition from consumers
Previously the driver would happily talk to addresses with no device
returning some garbage for reads and sending bits into the void for writes.

MFC after:	1 week
2021-12-15 13:16:04 +02:00
Andriy Gapon
7dc8a0e5df rk_i2c: keep sending bytes until all bytes are sent
Previously the code would decalre the transfer complete after sending
first 31 bytes (plus the slave address) of a larger I2C write transfer.

That was tested using a large write to an EEPROM with 32-byte write page
size and a 2-byte address type.  Such a transaction needed to send 34
bytes, 2 bytes for an offset and 32 bytes of actual data.

MFC after:	1 week
2021-12-15 13:15:58 +02:00
Andriy Gapon
b6a2aba959 rk_i2c_transfer: fix off-by-one in check for last message
This also fixes an access beyond msgs array.

MFC after:	1 week
2021-12-15 13:15:50 +02:00
Andriy Gapon
ede576831b rk_i2c_drain_rx: remove useless arithmetic manipulations
When i % 4 == 0 the result of (i / 4) * 4 is always i.

MFC after:	1 week
2021-12-15 13:15:45 +02:00
Andriy Gapon
1da04ae8fb rk_i2c: consistently treat booleans as such
MFC after:	1 week
2021-12-15 13:15:23 +02:00
Andriy Gapon
552503aca9 rk_i2c_transfer: use iicbus error codes instead of generic ones
MFC after:	1 week
2021-12-15 13:14:56 +02:00