#
# Copyright (C) 2011 HBM Netherlands B.V.
# Schutweg 15a
# 5145NP Waalwijk
# The Netherlands
# http://www.hbm.com
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
#

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

PKG_NAME:=hbm-fpga-core
PKG_RELEASE:=1

include $(INCLUDE_DIR)/package.mk

define KernelPackage/hbm-fpga-core
  SUBMENU:=Other modules
  TITLE:=HBM Interface module FPGA core driver
  DEPENDS:=
  FILES:=$(PKG_BUILD_DIR)/hbm-fpga-core-driver.$(LINUX_KMOD_SUFFIX)
  AUTOLOAD:=$(call AutoLoad,61,hbm-fpga-core-driver)
endef

define KernelPackage/hbm-fpga-core/description
 Kernel module for the GenSeries Interface Module Mk2 FPGA core.
endef

EXTRA_KCONFIG:=
EXTRA_CFLAGS:=-I$(PKG_BUILD_DIR)
MAKE_OPTS:= \
	ARCH="$(LINUX_KARCH)" \
	CROSS_COMPILE="$(TARGET_CROSS)" \
	SUBDIRS="$(PKG_BUILD_DIR)" \
	EXTRA_CFLAGS="$(EXTRA_CFLAGS)" \
	$(EXTRA_KCONFIG)

define Build/Prepare
	mkdir -p $(PKG_BUILD_DIR)
	$(CP) ./src/*.c $(PKG_BUILD_DIR)/
	$(CP) ./src/*.h $(PKG_BUILD_DIR)/
endef

define Build/Compile
	echo 'obj-m	:= hbm-fpga-core-driver.o'> $(PKG_BUILD_DIR)/Makefile
	$(MAKE) -C "$(LINUX_DIR)" \
		$(MAKE_OPTS) \
		modules
	rm -f $(PKG_BUILD_DIR)/*.o
	echo 'obj-m	:= hbm-fpga-i2c.o'> $(PKG_BUILD_DIR)/Makefile
	$(MAKE) -C "$(LINUX_DIR)" \
		$(MAKE_OPTS) \
		modules
	echo 'obj-m	:= hbm-boardinfo-i2c.o'> $(PKG_BUILD_DIR)/Makefile
	$(MAKE) -C "$(LINUX_DIR)" \
		$(MAKE_OPTS) \
		modules
endef

define Build/InstallDev
	$(INSTALL_DIR) $(1)/usr/include/hbm
	$(CP) ./src/hbm-fpga.h $(1)/usr/include/hbm
	$(CP) ./src/hbm-fpga-driver.h $(1)/usr/include/hbm
endef

$(eval $(call KernelPackage,hbm-fpga-core))

define KernelPackage/hbm-fpga-i2c
  SUBMENU:=Other modules
  TITLE:=HBM Interface module FPGA I2C driver
  DEPENDS:=kmod-hbm-fpga-core
  FILES:=$(PKG_BUILD_DIR)/hbm-fpga-i2c.$(LINUX_KMOD_SUFFIX)
  AUTOLOAD:=$(call AutoLoad,60,hbm-fpga-i2c)
endef

define KernelPackage/hbm-fpga-i2c/description
 Kernel module for the GenSeries Interface Module Mk2 I2C functionality in the FPGA.
endef

$(eval $(call KernelPackage,hbm-fpga-i2c))

define KernelPackage/hbm-boardinfo-i2c
  SUBMENU:=Other modules
  TITLE:=HBM Interface module board info for I2C devices
  DEPENDS:=kmod-hbm-fpga-i2c
  FILES:=$(PKG_BUILD_DIR)/hbm-boardinfo-i2c.$(LINUX_KMOD_SUFFIX)
  AUTOLOAD:=$(call AutoLoad,62,hbm-boardinfo-i2c)
endef

define KernelPackage/hbm-boardinfo-i2c/description
 Kernel module for the GenSeries Interface Module Mk2 I2C functionality in the FPGA.
endef

$(eval $(call KernelPackage,hbm-boardinfo-i2c))
