// SPDX-License-Identifier: (GPL-2.0 OR BSD-3-Clause)
/*
 * Copyright (c) 2020 MediaTek Inc.
 */

#include <linux/module.h>
#include <linux/io.h>
#include <linux/platform_device.h>
#include <linux/of.h>
#include <linux/dma-mapping.h>
#include "mtk_pcmcia_hal_diff.h"
#include "mtk_pcmcia.h"

#include "mtk_pcmcia_resource.h"

#define MLP_CI_CORE_ENTRY(fmt, arg...)	pr_info("[mdbgin_CADD_CI]" fmt, ##arg)

static int mdrv_ci_regmaps_init(struct platform_device *pdev,
				struct mdrv_ci_regmaps *pregmaps)
{
	struct resource *res;

	MLP_CI_CORE_ENTRY("[%s][%d]\n", __func__, __LINE__);

	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);	//RIU 1034-40
	if (!res) {
		MTK_CI_ERR("failed to get ci address\n");
		return -ENOENT;
	}

	//MTK_CI_INFO("resource[0]: start = %x, end = %x\n", res->start, res->end);

	pregmaps->riu_vaddr = devm_ioremap_resource(&pdev->dev, res);
	if (IS_ERR(pregmaps->riu_vaddr)) {
		MTK_CI_ERR("failed to ioremap RIU_vaddr\n");
		return PTR_ERR(pregmaps->riu_vaddr);
	}
	MTK_CI_INFO("resource[0]pregmaps->RIU_vaddr= %p\n", pregmaps->riu_vaddr);

	//res->start = 0x1f600000; //ext-RIU 3000
	return 0;
}

int mdrv_ci_res_init(struct platform_device *pdev, struct mdrv_ci_res *pres)
{
	int ret = 0;

	MLP_CI_CORE_ENTRY("[%s][%d]\n", __func__, __LINE__);

	pres->regmaps =
	    devm_kzalloc(&pdev->dev, sizeof(struct mdrv_ci_regmaps),
			 GFP_KERNEL);
	if (!pres->regmaps) {
		MTK_CI_ERR("allocate regmaps struct fail\n");
		return -ENOMEM;
	}
	ret = mdrv_ci_regmaps_init(pdev, pres->regmaps);
	if (ret < 0) {
		MTK_CI_ERR("init regmaps struct fail\n");
		return ret;
	}

	return 0;
}

