# Copyright 1999-2026 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2

EAPI=8

inherit linux-mod-r1

DESCRIPTION="Linux device driver for Motorcomm YT6801 Gigabit Ethernet controllers"
HOMEPAGE="https://www.motor-comm.com/product/ethernet-control-chip"
SRC_URI="https://en.motor-comm.com/Public/Uploads/uploadfile/files/20251217/yt6801-linux-driver-${PV}.zip"
S="${WORKDIR}"
LICENSE="GPL-2"
SLOT="0"
KEYWORDS="amd64"
BDEPEND="app-arch/unzip"

src_unpack() {
	unpack ${A}
	unpack "${S}/${P}.tar.gz"
}

src_prepare() {
	# fix undeclared FXGMAC_INT_MODERATION_ENABLED
	eapply -p0 "${FILESDIR}/${PN}-${PV}-fuxi-os.h.patch"

	# 2 from https://github.com/NixOS/nixpkgs/tree/master/pkgs/os-specific/linux/yt6801
	# fix deprecated del_timer_sync
	eapply -p0 "${FILESDIR}/${PN}-del_timer_sync.patch"

	# fix timer setup for kv >= 6.16
	eapply -p0 "${FILESDIR}/${PN}-timer_setup.patch"

	eapply_user
}

src_compile() {
	local modlist=(
		${PN}="${PN}:${WORKDIR}"
	)
	local modargs=(
		KERNELDIR="${KV_OUT_DIR}"
	)

	linux-mod-r1_src_compile
}