##############################################################################
#
#    Copyright (c) 2021 by sietium.  All rights reserved.
#
#
##############################################################################

quiet_cmd_xxd = XXD     $@
cmd_xxd = xxd -r $< $@

all: $(subst .hex,.o,$(wildcard *.hex))

%.o: %.o.hex
	$(call cmd,xxd)

GB_DIR_PATH = $(srctree)/$(src)
os=Kylin
osver=Kylinv10-5.4.18
gb_version=V2.0.1

ifeq ($(os),Kylin)
	OSVER=CONFIG_SKYLIN_OS_V10
else ifeq ($(os),uos)
	OSVER=CONFIG_UOS_20
else ifeq ($(os),loongnix)
	OSVER=CONFIG_LOONGSON_OS
else ifeq ($(os),CentOS)
	OSVER=CONFIG_CENTOS8
endif

ifeq ($(CONFIG_ARM64),y)
OBJ_DIR = aarch64
ccflags-y += -mcmodel=large -mfix-cortex-a53-843419
subdir-ccflags-y += -mcmodel=large -mfix-cortex-a53-843419
endif

ifeq ($(CONFIG_MIPS),y)
OBJ_DIR = mips
endif

ifeq ($(CONFIG_X86_64),y)
OBJ_DIR = x86_64
endif

# defines in build
DEFINE += $(OSVER)
DEFINE += OS_VERSION="$(osver)"
DEFINE += GB_VERSION=$(gb_version)
DEFINES = $(addprefix -D,$(DEFINE))

GB_OBJ_DIR := objs/$(OBJ_DIR)

ccflags-y += $(DEFINES)
subdir-ccflags-y += $(DEFINES)
subdir-ccflags-y += -Wno-implicit-fallthrough

ccflags-y += -I$(srctree)/include -I$(srctree)/include/linux -I$(srctree)/include/drm
ccflags-y += -I$(GB_DIR_PATH)/src/common -I$(GB_DIR_PATH)/src/kms -I$(GB_DIR_PATH)/src/gpu -I$(GB_DIR_PATH)/src/vpu/vpu_mm -I$(GB_DIR_PATH)/src/vpu/vpu_enc -I$(GB_DIR_PATH)/src/vpu/vpu_dec -I$(GB_DIR_PATH)/src/vpu/vpu_comm/ -I$(GB_DIR_PATH)/src -Iinclude/drm
ccflags-y += -DCONFIG_MCU_I2C=n -DCONFIG_MCU_UART=n -DCONFIG_MCU_GPIO=y -DCONFIG_MCU_PWM=y -DCONFIG_GPIO_PWM=n -DCONFIG_MCU_SPI=n -DCONFIG_MCU_PVT=y -DCONFIG_MCU_FREQ=y -DCONFIG_MCU_FAN=y -DCONFIG_SN_INFO=y -DCONFIG_PCIE_MSG=y -DCONFIG_MCU_PERI=y
subdir-ccflags-y += -Wno-implicit-fallthrough -I$(GB_DIR_PATH)/src/kms

#include $(GB_DIR_PATH)/src/common/Kbuild
#include $(GB_DIR_PATH)/src/kms/Kbuild
#include $(GB_DIR_PATH)/src/audio/Kbuild
#include $(GB_DIR_PATH)/src/mcu_peripherals/gpio/Kbuild
#include $(GB_DIR_PATH)/src/mcu_peripherals/pwm/Kbuild
#include $(GB_DIR_PATH)/src/mcu_peripherals/spi/Kbuild
#include $(GB_DIR_PATH)/src/mcu_peripherals/i2c/Kbuild
#include $(GB_DIR_PATH)/src/mcu_peripherals/pvt/Kbuild
#include $(GB_DIR_PATH)/src/gpu_test/Kbuild

audio-y += \
        src/audio/dwc-i2s.o \
        src/audio/i2s_platform.o \
        src/audio/gb02_fpga_v2vdma.o \
        src/audio/gb_audio_procfs.o \
        src/audio/gb_snd_codec.o

gb_common-y += \
	src/common/gb_procfs.o \
	src/common/gb_pcie_info.o \
	src/common/gb_gpuinfo.o \
	src/common/gb_irq.o \
	src/common/gb02_debugfs.o

gpu_debug-y := \
	src/gpu_test/gb_easy_shell.o \
	src/gpu_test/gb_mem_tool.o

i2c-y += \
	src/mcu_peripherals/i2c/i2c-gb02-mcu.o \
	src/mcu_peripherals/i2c/ina2xx.o \
	src/mcu_peripherals/i2c/ads1015.o 

gpio-y += \
	src/mcu_peripherals/gpio/pinctrl-gb02-mcu.o

spi-y += \
	src/mcu_peripherals/spi/spi-gb02-mcu.o

pvt-y += \
	src/mcu_peripherals/pvt/gb02-pvt.o

pwm-y += \
	src/mcu_peripherals/pwm/gb_pwm.o \
	src/mcu_peripherals/pwm/fan/gb02-pwm-fan.o \
	src/mcu_peripherals/pwm/gb02_mcu_pwm.o \
	src/mcu_peripherals/pwm/backlight/gb02-pwm-bl.o

gpio-pwm-y += \
	src/mcu_peripherals/pwm/gb_pwm.o \
	src/mcu_peripherals/pwm/backlight/gb02-pwm-bl.o \
	src/mcu_peripherals/pwm/gpio-pwm.o \
	src/mcu_peripherals/pwm/fan/gb02-pwm-fan.o

dc_kms-y += \
	src/kms/gbdc_hdmi_ddc.o \
	src/kms/gbdc_vga_bridge.o \
	src/kms/gbdc_backlight.o \
	src/kms/gbdc_connector.o \
	src/kms/gbdc_crtc.o \
	src/kms/gbdc_display.o \
	src/kms/gbdc_encoder.o \
	src/kms/gbdc_fbdev.o \
	src/kms/gbdc_mm.o \
	src/kms/gbdc_planes.o \
	src/kms/gb_kms.o \
	src/kms/gbdc_drv.o \
	src/kms/gbdc_irq.o \

gb_peri_common-y += \
	src/mcu_peripherals/gb_peripherals_common.o
pcie_msg-y += \
        src/mcu_peripherals/pcie_msg/gb02_pcie_msg.o
gpu_freq-y += \
	src/mcu_peripherals/gpu_freq/gpu_freq.o
sn_info-y += \
	src/mcu_peripherals/sn_info/param_def.o  \
	src/mcu_peripherals/sn_info/gb_sn_info.o
uart-y += \
	src/mcu_peripherals/uart/gb02_usart.o
fan-y += \
	src/mcu_peripherals/fan/gb02_fan.o

gb02-objs += $(gb_common-y)
gb02-objs += $(dc_kms-y)
gb02-objs += $(audio-y)
gb02-objs += $(gpio-y)
gb02-objs += $(pwm-y)
gb02-objs += $(gpio-pwm-y)
gb02-objs += $(spi-y)
gb02-objs += $(i2c-y)
gb02-objs += $(pvt-y)
gb02-objs += $(gpu_debug-y)
gb02-objs += $(gb_peri_common-y)
gb02-objs += $(pcie_msg-y)
gb02-objs += $(gpu_freq-y)
gb02-objs += $(sn_info-y)
gb02-objs += $(uart-y)
gb02-objs += $(fan-y)
gb02-objs += $(GB_OBJ_DIR)/$(os)/gbgpu_$(osver).o

obj-$(CONFIG_GPU_SIETIUM_GENBU02) += gb02.o

