/*
 * Copyright 2022 Sony Corporation
 */

#include <common.h>
#include <dts_parser.h>
#include <dm/uclass.h>
#include <dm/platdata.h>
#include <dm/lists.h>
#include <asm/gpio.h>

#include "damp_selector.h"

static struct udevice *dev;

int init_damp_selector(void)
{
    int ret, offset;
    char node_name[32] = {0};

    printf("[DAMP selector] init_damp_selector start.\n");
    parse_dt("/odm/damp_selector", string_dt_parser, (void*)&node_name, "compatible");

    offset = fdt_node_offset_by_compatible(gd->fdt_blob, -1, "sony,damp_selector");
    ret = lists_bind_fdt(gd->dm_root, offset_to_ofnode(offset), &dev, false);
    if (ret != 0) {
        printf("[DAMP selector] lists_bind_fdt_fail.\n");
    }

    ret = uclass_get_device_by_name(UCLASS_AUDIO_CODEC, "damp_selector", &dev);
    if (ret != 0) {
        printf("[DAMP selector] uclass_get_device_by_name_fail.\n");
        return CMD_RET_FAILURE;
    }

    printf("[DAMP selector] init_damp_selector success.\n");
    return CMD_RET_SUCCESS;
}

int do_damp_selector_init(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
{
    return init_damp_selector();
}

U_BOOT_CMD(
    damp_selector_init, CONFIG_SYS_MAXARGS, 1, do_damp_selector_init,
    "damp_selector_init - init DAMP Selector.\n",
    NULL
);
