/*
 * Copyright (c) Huawei Technologies Co., Ltd. 2025. All rights reserved.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 and
 * only 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.
 */

#include "fms_module.h"
#include "pbl_feature_loader.h"
#include "ka_kernel_def_pub.h"

struct submodule_ops {
    int (*init) (void);
    void (*uninit)(void);
};

STATIC struct submodule_ops g_sub_table[] = {
    {dms_dtm_init, dms_dtm_exit},
    {dms_smf_init, dms_smf_exit},
#ifndef CFG_EDGE_HOST
    {fpdc_receiver_init, fpdc_receiver_exit},
#endif
    {module_feature_auto_init, module_feature_auto_uninit},
};

STATIC int KA_MODULE_INIT init_fms_base(void)
{
    int index, ret;
    int table_size = sizeof(g_sub_table) / sizeof(struct submodule_ops);

    for (index = 0; index < table_size; index++) {
        ret = g_sub_table[index].init();
        if  (ret != 0) {
            goto out;
        }
    }
    return 0;
out:
    for (; index > 0; index--) {
        g_sub_table[index - 1].uninit();
    }
    return ret;
}

STATIC void KA_MODULE_EXIT exit_fms_base(void)
{
    int index;
    int table_size = sizeof(g_sub_table) / sizeof(struct submodule_ops);

    for (index = table_size; index > 0; index--) {
        g_sub_table[index - 1].uninit();
    }
}

ka_module_init(init_fms_base);
ka_module_exit(exit_fms_base);

KA_MODULE_LICENSE("GPL");
KA_MODULE_AUTHOR("Huawei Tech. Co., Ltd.");
KA_MODULE_DESCRIPTION("DAVINCI driver");