#
# Copyright (C) 2026 Teltonika-Networks
#
# This is free software, licensed under the GNU General Public License v2.
# See /LICENSE for more information.
#

include $(TOPDIR)/rules.mk
include $(INCLUDE_DIR)/kernel.mk
include $(INCLUDE_DIR)/download.mk

PKG_NAME:=tlt-poe
PKG_LICENSE:=GPL-2.0-only
PKG_SOURCE_VERSION:=1.2

include $(INCLUDE_DIR)/package.mk

define KernelPackage/poe-core
	SUBMENU:=Other modules
	TITLE:=Hwmon based PoE board level driver
	FILES:=$(PKG_BUILD_DIR)/poe_core.ko
	AUTOLOAD:=$(call AutoLoad,49,poe-core)
endef

define KernelPackage/poe-ip80x
	SUBMENU:=Other modules
	TITLE:= PoE driver for IC+ IP808/IP804/IP802 chips
	FILES:=$(PKG_BUILD_DIR)/poe_ip80x.ko
	AUTOLOAD:=$(call AutoLoad,50,poe-ip80x)
	DEPENDS:=+kmod-poe-core
endef

define KernelPackage/poe-ip8008
	SUBMENU:=Other modules
	TITLE:=PoE driver for IC+ IP8008 chip
	FILES:=$(PKG_BUILD_DIR)/poe_ip8008.ko
	AUTOLOAD:=$(call AutoLoad,50,poe-ip8008)
	DEPENDS:=+kmod-poe-core
endef

define KernelPackage/poe-xs2184
	SUBMENU:=Other modules
	TITLE:=PoE driver for Chipup XS2184 chips
	FILES:=$(PKG_BUILD_DIR)/poe_xs2184.ko
	AUTOLOAD:=$(call AutoLoad,50,poe-xs2184)
	DEPENDS:=+kmod-poe-core
endef

MAKE_OPTS:=$(KERNEL_MAKE_FLAGS) M="$(PKG_BUILD_DIR)"

define Build/Compile
	$(MAKE) -C "$(LINUX_DIR)" $(MAKE_OPTS) modules
endef

define Build/Install
	true
endef

$(eval $(call KernelPackage,poe-core))
$(eval $(call KernelPackage,poe-ip80x))
$(eval $(call KernelPackage,poe-ip8008))
$(eval $(call KernelPackage,poe-xs2184))
