/* --------------------------------------------------------------------------- */
static void init_io_pad(void)
{
	LCD_CHECK_RET(LCD_Init_IO_pad(lcm_params));
}
static void disp_drv_init_io_pad(LCM_PARAMS *lcm)
{
	LCD_Init_IO_pad(lcm);
}
const LCM_DRIVER *disphal_get_lcm_driver(const char *lcm_name, unsigned int *lcm_index)
{
    LCM_DRIVER *lcm = NULL;
    bool isLCMFound = false;
    printk("[LCM Auto Detect], we have %d lcm drivers built in\n", lcm_count);
    printk("[LCM Auto Detect], try to find driver for [%s]\n", 
        (lcm_name==NULL)?"unknown":lcm_name);

    if(lcm_count == 1)
    {
        // we need to verify whether the lcm is connected
        // even there is only one lcm type defined
        lcm = lcm_driver_list[0];
        lcm->set_util_funcs(&lcm_utils);
        *lcm_index = 0;
        printk("[LCM Specified]\t[%s]\n", (lcm->name==NULL)?"unknown":lcm->name);
        isLCMFound = true;
        goto done;
    }
    else
    {
        int i;
        for(i = 0;i < lcm_count;i++)
        {
            lcm = lcm_driver_list[i];
            printk("[LCM Auto Detect] [%d] - [%s]\t", i, (lcm->name==NULL)?"unknown":lcm->name);
            lcm->set_util_funcs(&lcm_utils);
            memset((void*)&s_lcm_params, 0, sizeof(LCM_PARAMS));
            lcm->get_params(&s_lcm_params);

            disphal_init_ctrl_if();
            LCD_Set_DrivingCurrent(&s_lcm_params);
            LCD_Init_IO_pad(&s_lcm_params);

            if(lcm_name != NULL)
            {
                if(!strcmp(lcm_name,lcm->name))
                {
                    printk("\t\t[success]\n");
                    *lcm_index = i;
                    isLCMFound = true;
                    goto done;
                }
                else
                {
                    printk("\t\t[fail]\n");
                }
            }
            else 
            {
                if(LCM_TYPE_DSI == lcm_params->type)
                {
                    init_dsi(FALSE);
                }

                if(lcm->compare_id != NULL && lcm->compare_id())
                {
                    printk("\t\t[success]\n");
                    isLCMFound = true;
                    *lcm_index = i;
                    goto done;
                }
                else
                {
                    if(LCM_TYPE_DSI == lcm_params->type)
                        DSI_Deinit();
                    printk("\t\t[fail]\n");
                }
            }
        }
    }
done:
    if (isLCMFound)
    {
        memset((void*)&s_lcm_params, 0, sizeof(LCM_PARAMS));
        lcm->get_params(&s_lcm_params);
        return lcm;
    }
    else
        return NULL;
}