/* SPDX-License-Identifier: GPL-2.0-only OR BSD-3-Clause */
/*
 * MediaTek Panel cust driver
 *
 * Copyright (c) 2022-2023 MediaTek Inc.
*/

#include <common.h>
#include <dm.h>
#include <debug_impl.h>

int mtk_pnl_cust_get_partition(char *partition_name)
{
    bool ret;
    struct udevice *dev;
    ofnode info_node;
    const char *get_name = NULL;

    ret = uclass_get_device_by_name(UCLASS_DISPLAY, "video_out", &dev);
    if (ret)
    {
        UBOOT_ERROR("Get video out device is fail\n");
        return -EINVAL;
    }

    info_node = dev_read_subnode(dev, "panel-cus-setting");
    if (!ofnode_valid(info_node))
    {
        UBOOT_ERROR("Read subnode (%s) FAIL\n", "panel-cus-setting");
        return -EINVAL;
    }

    get_name = ofnode_read_string(info_node, "binary_partition");

    if (partition_name && get_name)
    {
        memcpy(partition_name, get_name, strlen(get_name));
    }
    else
    {
        UBOOT_DEBUG("Get binary_partition fail!\n");
        return -EINVAL;
    }
    return 0;
}
