#
# Copyright (C) 2015 MediaTek Inc.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 as
# published by the Free Software Foundation.
#
# 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.
#

###############################################################################
# Necessary Check

ifneq ($(KERNEL_OUT),)
    ccflags-y += -imacros $(KERNEL_OUT)/include/generated/autoconf.h
endif

ifndef TOP
    TOP := $(srctree)/..
endif

# Force build fail on modpost warning
KBUILD_MODPOST_FAIL_ON_WARNINGS := y
###############################################################################

# only WMT align this design flow
#ccflags-y += -D MTK_WCN_REMOVE_KERNEL_MODULE

ifeq ($(CONFIG_ARM64), y)
    ccflags-y += -D CONFIG_MTK_WCN_ARM64
endif

ifeq ($(CONFIG_MTK_CONN_LTE_IDC_SUPPORT),y)
    ccflags-y += -D WMT_IDC_SUPPORT=1
else
    ccflags-y += -D WMT_IDC_SUPPORT=0
endif
ccflags-y += -D MTK_WCN_WMT_STP_EXP_SYMBOL_ABSTRACT

ccflags-y += -I$(srctree)/drivers/misc/mediatek/include
ccflags-y += -I$(srctree)/drivers/misc/mediatek/include/mt-plat

ifeq ($(CONFIG_FM_USER_LOAD),1)
    ccflags-y += -D CONFIG_MTK_USER_BUILD
endif

# Makefile generated by Mediatek
# fm support

obj-m += $(MODULE_NAME).o

ifeq ($(CFG_FM_CHIP),)
    FM_CHIP := mt6631_6635

    ccflags-y += -I$(src)/chips/mt6631/inc -I$(src)/chips/mt6635/inc

    $(FM_CHIP)-objs += chips/mt6631/pub/mt6631_fm_rds.o
    $(FM_CHIP)-objs += chips/mt6635/pub/mt6635_fm_rds.o
    $(FM_CHIP)-objs += chips/mt6631/pub/mt6631_fm_lib.o
    $(FM_CHIP)-objs += chips/mt6635/pub/mt6635_fm_lib.o

else
    ifeq ($(CFG_FM_LAYERDEC_2),)
        ifeq ($(CONFIG_MTK_FM_CHIP),)
            $(error CONFIG_MTK_FM_CHIP not defined)
        endif

        ifneq ($(CFG_FM_CHIP_ID),)
            ccflags-y += -D CFG_FM_CHIP_ID=0x$(CFG_FM_CHIP_ID)
        endif
        FM_CHIP := $(subst _FM,,$(subst MT,mt,$(subst ",,$(CONFIG_MTK_FM_CHIP))))
    else
        FM_CHIP := $(CFG_FM_CHIP)
    endif

    ifeq ($(FM_CHIP), mt6625)
        FM_CHIP := mt6627
        ccflags-y += -DMT6625_FM
    endif

    ifeq ($(FM_CHIP), mt6627)
        FM_CHIP := mt6627
        ccflags-y += -DMT6627_FM
    endif

    ifeq ($(FM_CHIP), mt6580)
        FM_CHIP := soc
        ccflags-y += -Dsoc
    endif

    ifeq ($(FM_CHIP), mt0633)
        FM_CHIP := soc
        ccflags-y += -Dsoc
    endif

    ifeq ($(FM_CHIP), mt6630)
        ccflags-y += -DMT6630_FM
    endif

    ifeq ($(FM_CHIP), mt6632)
        ccflags-y += -DMT6632_FM
    endif

    ifeq ($(FM_CHIP), mt6631)
        ccflags-y += -DMT6631_FM
    endif

    ifeq ($(FM_CHIP), mt6635)
        ccflags-y += -DMT6635_FM
    endif

    FM_CHIP_PATH := $(FM_CHIP)/pub/$(FM_CHIP)
    ccflags-y += -I$(src)/chips/$(FM_CHIP)/inc

    ifneq ($(CFG_BUILD_CONNAC2), true)
        $(FM_CHIP)-objs += chips/$(FM_CHIP_PATH)_fm_rds.o
        $(FM_CHIP)-objs += chips/$(FM_CHIP_PATH)_fm_lib.o
    else
        $(FM_CHIP)-objs += chips/mt6635/pub/mt6635_fm_rds.o
        $(FM_CHIP)-objs += chips/connac2x/pub/connac2x_fm_lib.o
        ccflags-y += -DFM_DTS_PROBE
    endif
endif


ccflags-y += -I$(src)/inc \
             -I$(src)/plat/inc

$(FM_CHIP)-objs    += core/fm_module.o \
                core/fm_main.o \
                core/fm_config.o \
                core/fm_rds_parser.o \
                core/fm_patch.o \
                core/fm_utils.o \
                core/fm_link.o \
                core/fm_eint.o \
                core/fm_cmd.o \
                core/fm_reg_utils.o

ifeq ($(CFG_BUILD_CONNAC2), true)
    CONNINFRA_SRC_FOLDER := $(TOP)/vendor/mediatek/kernel_modules/connectivity/conninfra

    ccflags-y += -I$(CONNINFRA_SRC_FOLDER)/include
    ccflags-y += -DCFG_FM_CONNAC2=1
    $(FM_CHIP)-objs += plat/conn_infra.o
else
    WMT_SRC_FOLDER := $(TOP)/vendor/mediatek/kernel_modules/connectivity/common
    WMT_INCLUDE_PATH := common_main

    ccflags-y += -I$(WMT_SRC_FOLDER)/$(WMT_INCLUDE_PATH)/include \
                 -I$(WMT_SRC_FOLDER)/$(WMT_INCLUDE_PATH)/linux/include
    ccflags-y += -DCFG_FM_CONNAC2=0
    $(FM_CHIP)-objs += plat/legacy_wmt.o
endif

$(MODULE_NAME)-objs += $($(FM_CHIP)-objs)
#obj-$(CONFIG_MTK_FMRADIO) += private/

obj-y += dummy.o
