static int of_get_key_gpio(struct device_node *np, const char *propname,
			   int prop_index, int gpio_index, enum of_gpio_flags *flags)
{
	int ret = 0;

#ifdef CONFIG_GPIO_LOGIC
	ret = of_get_gpio_by_prop(np, propname, prop_index, gpio_index, flags);
#else
	ret = of_get_named_gpio(np, propname, prop_index);
#endif

	return ret;
}
/*
**************************************************************************
* FunctionName: k3_socgpio_get_id_value;
* Description : get sensor id value;
* Input         :gpio_name:camera senor id_pin's name;
* Output       :value:camera sensor id_pin's value,ether 0 or 1,if ret < 0 ,it can not get id_pin value   ;
* ReturnValue:ret:if ret < 0 means error ,can not get right id_pin's value,if not ,means the value is right;
* Other         :NA;
**************************************************************************
*/
int k3_socgpio_get_id_value(char *gpio_name)
{
	int ret = -EINVAL;
	struct device_node *np = NULL;
	struct platform_device *pdev =NULL;
	int gpio_pin;
	enum of_gpio_flags gpio_flags;

	print_debug("enter %s", __func__);

	np = of_find_compatible_node(NULL, NULL, "hisi,hisi_isp");

	if (NULL == np) {
		print_error("the device node hisi_isp is null\n");
		return -1;
	}

	pdev = of_find_device_by_node(np);
	if (NULL == pdev) {
		print_error("the device hisi_isp is null\n");
		return -1;
	}

	gpio_pin = of_get_gpio_by_prop(np, gpio_name, 0, 0, &gpio_flags);
	if (!gpio_is_valid(gpio_pin)) {
		print_error("%s:huawei, pin read %s error.\n", __FUNCTION__, gpio_name);
		return -1;
	}

	print_info("%s: huawei, pin read %s:%d.\n", __FUNCTION__, gpio_name, gpio_pin);

	ret = gpio_request(gpio_pin, gpio_name);
	if (ret < 0) {
		print_error("%s: request camera gpio - %d(%s) failed, result = %d.",
			__func__, gpio_pin, gpio_name, ret);
		return -EINVAL;
	}

	ret = gpio_get_value(gpio_pin);
	if (ret < 0) {
		print_error("%s: fail to get value on gpio - %d(%s), result = %d.",
			__func__, gpio_pin, gpio_name, ret);
	}

	gpio_free(gpio_pin);

	print_debug("leave %s", __func__);

	return ret;
}
static int  bluesleep_probe(struct platform_device *pdev)
{
	struct device *bluetooth_sleep_dev = &pdev->dev;
	struct device_node *np = bluetooth_sleep_dev->of_node;
#if defined(CONFIG_BCM4343)
	enum of_gpio_flags gpio_flags;
#endif
	struct bluetooth_sleep_data *bluesleep_data = NULL;
	int ret = 0;

	bluesleep_data = devm_kzalloc(bluetooth_sleep_dev, sizeof(struct bluetooth_sleep_data), GFP_KERNEL);
	if ( bluesleep_data == NULL ) {
		dev_err(bluetooth_sleep_dev, "failed to allocate bluetooth_sleep_data\n");
		return -ENOMEM;
	}

	pr_info("bluesleep_probe in \n");

#if 0//use hisi new method get gpio num
	of_property_read_u32(np, "huawei,bt_wake_host", &(bluesleep_data->gpio_bt_wake_host.gpio));
	of_property_read_u32(np, "huawei,host_wake_bt", &(bluesleep_data->gpio_host_wake_bt.gpio));
#else
#if defined(CONFIG_BCM4343)
	bluesleep_data->gpio_bt_wake_host.gpio = of_get_gpio_by_prop(np , "huawei,bt_wake_host" , 0 , 0 , &gpio_flags);
#else
        of_property_read_u32(np, "huawei,bt_wake_host", &(bluesleep_data->gpio_bt_wake_host.gpio));
#endif
	if (!gpio_is_valid(bluesleep_data->gpio_bt_wake_host.gpio))
	{
		pr_err("%s: get bt_wake_host gpio failed. gpio=%d\n", __func__, bluesleep_data->gpio_bt_wake_host.gpio);
		goto free_g_bs_data;
	}

#if defined(CONFIG_BCM4343)
	bluesleep_data->gpio_host_wake_bt.gpio = of_get_gpio_by_prop(np , "huawei,host_wake_bt" , 0 , 0 , &gpio_flags);
#else
	of_property_read_u32(np, "huawei,host_wake_bt", &(bluesleep_data->gpio_host_wake_bt.gpio));
#endif
	if (!gpio_is_valid(bluesleep_data->gpio_host_wake_bt.gpio))
	{
		pr_err("%s: get host_wake_bt gpio failed. gpio=%d\n", __func__, bluesleep_data->gpio_host_wake_bt.gpio);
		goto free_g_bs_data;
	}
#endif

	ret = gpio_request( bluesleep_data->gpio_bt_wake_host.gpio , "bt_wake_host" );
	if (ret < 0) {
		pr_err("%s: gpio_request %d  failed, ret:%d .\n", __func__, bluesleep_data->gpio_bt_wake_host.gpio ,ret);
		goto free_g_bs_data;
	}
	
	ret = gpio_request( bluesleep_data->gpio_host_wake_bt.gpio , "host_wake_bt" );
	if (ret < 0) {
		pr_err("%s: gpio_request %d  failed, ret:%d .\n", __func__, bluesleep_data->gpio_host_wake_bt.gpio ,ret);
		goto free_bt_host_wake;
	}

	ret	= gpio_direction_input(bluesleep_data->gpio_bt_wake_host.gpio);
	if (ret < 0) {
		pr_err("%s: bt_host_wake gpio_direction_input failed\n", __func__);
		goto free_bt_ext_wake;
	}

	/* deassert bt wake */
	ret	= gpio_direction_output(bluesleep_data->gpio_host_wake_bt.gpio, LPM_BT_WAKE_DEASSERT);
	if (ret < 0) {
		pr_err("%s: bt_ext_wake gpio_direction_input failed\n", __func__);
		goto free_bt_ext_wake;
	}

	bluesleep_data->host_wake_irq = gpio_to_irq(bluesleep_data->gpio_bt_wake_host.gpio);
	if (bluesleep_data->host_wake_irq < 0)	{
		pr_err("%s: couldn't find host_wake	irq\n", __func__);
		ret	= -ENODEV;
		goto free_bt_ext_wake;
	}

	ret = create_bluesleep_proc_sys(bluesleep_data);
	if (ret) {
		pr_err("%s: create_bluesleep_proc_sys %d\n",
			__func__, ret);
		goto free_bt_ext_wake;
	}

	/* Initialize spinlock.*/
	spin_lock_init(&bluesleep_data->rw_lock);

	/* Initialize semaphore.*/
	sema_init(&bluesleep_data->bt_seam, 1);

	/* Initialize bluetooth wakelock*/
	wake_lock_init(&bluesleep_data->wake_lock, WAKE_LOCK_SUSPEND, "bluesleep");

	/* Initialize timer	*/
	init_timer(&bluesleep_data->tx_timer);
	bluesleep_data->tx_timer.function = bluesleep_tx_timer_expire;
	bluesleep_data->tx_timer.data = (unsigned long)bluesleep_data;

	/* initialize host wake	tasklet	*/
	tasklet_init(&bluesleep_data->hostwake_task,
			bluesleep_hostwake_task, (unsigned long)bluesleep_data);

	// other code
	platform_set_drvdata(pdev, bluesleep_data);
	g_bs_data = bluesleep_data;

	pr_info("bluesleep_probe out \n");

	return ret;

free_bt_ext_wake:
	gpio_free(bluesleep_data->gpio_host_wake_bt.gpio);
free_bt_host_wake:
	gpio_free(bluesleep_data->gpio_bt_wake_host.gpio);
free_g_bs_data:
        devm_kfree(bluetooth_sleep_dev, bluesleep_data);
	platform_set_drvdata(pdev, NULL);
	g_bs_data = NULL;

	return ret;
}
static int balong_sim_probe(struct platform_device *pdev)
{
    struct balong_sim_plat_data *plat = NULL;
    const struct of_device_id *match;
    enum of_gpio_flags gpio_flags;
    int err;

    dev_dbg(&pdev->dev, "balong_sim_probe\n");

    if ((match = of_match_node(balong_sim_match, pdev->dev.of_node)) == NULL) {
        dev_err(&pdev->dev, "dev node is not match. exiting.\n");
        return -ENODEV;   
    }
    
    plat = (struct balong_sim_plat_data *)match->data;
    if (plat == NULL) {
        dev_err(&pdev->dev, "no platform data\n");
        return -EINVAL;
    }

    pr_err("balong_sim_probe, enter %s\n",plat->name);

    if (!strcmp(SIM1 , plat->name))
    {
        sim1_plat_data = plat;               
        sim1_plat_data->sim_detection_gpio = of_get_gpio_by_prop(pdev->dev.of_node,"gpio-sim1_detect,gpio-irq",0,0, &gpio_flags);

        err = of_property_read_u32(pdev->dev.of_node, "gpio_sim1_in_val", &g_sim1_present_electrical_lvl);
        if (err < 0) 
        {
            dev_err(&pdev->dev, "sim1 obtain the ele lvl failed err = %d\n",err);  
            return -EINVAL;
        }
	                 
    }
    
    if (!strcmp(SIM2 , plat->name))
    {
        sim2_plat_data = plat;
        sim2_plat_data->sim_detection_gpio = of_get_gpio_by_prop(pdev->dev.of_node,"gpio-sim2_detect,gpio-irq",0,0, &gpio_flags);

        err = of_property_read_u32(pdev->dev.of_node, "gpio_sim2_in_val", &g_sim2_present_electrical_lvl);
        if (err < 0) 
        {
            dev_err(&pdev->dev, "sim2 obtain the ele lvl failed err = %d\n",err);  
            return -EINVAL;
        }
	          
    }


    err = gpio_request_one(plat->sim_detection_gpio, GPIOF_IN, plat->name);
    if (err) {
        dev_warn(&pdev->dev, "no sim-detect pin available!\n");
        return err;
    }

    /*Initialize sim status when booting*/
    if (!strcmp(SIM1 , plat->name))
    {
        plat->sim_status = get_sim_status(plat->sim_detection_gpio, g_sim1_present_electrical_lvl);
    }

    if (!strcmp(SIM2 , plat->name))
    {
        plat->sim_status = get_sim_status(plat->sim_detection_gpio, g_sim2_present_electrical_lvl);
    }
    /*以下代码只执行一次,SIM1和SIM2共用一个任务队列*/
    if (!workqueue) {
        /* Initialize works */
        workqueue = create_singlethread_workqueue("balong_sim_workqueue");
        if (!workqueue) {
            dev_err(&pdev->dev, "Create workqueue failed\n");
            err = -1;
            goto err_init_workqueue;
        }
        else
        {
            pr_info("balong_sim_probe, Initialization of workqueue succeed\n");
        }
    }

    /*request SIM irq*/
    if (!strcmp(SIM1 , plat->name))
    {
        /*request irq for sim1*/
        INIT_WORK(&sim1_irq_work, balong_sim1_set_status);
        
        err = request_irq(gpio_to_irq(sim1_plat_data->sim_detection_gpio), sim1_detection_irq_handler,
    	    IRQF_TRIGGER_FALLING | IRQF_TRIGGER_RISING,
    	    pdev->name, pdev);
        if (err) {
            dev_warn(&pdev->dev, "sim1:request gpio irq error\n");
            goto no_sim_detect_irq;
        }
           
        /* sysfs entries for IO control */
        err = device_create_file(&(pdev->dev), &dev_attr_sim1_status);
        if (err) {
            dev_err(&pdev->dev, "sim1:Failed to create sysfs entry\n");
            goto err_create_device_file;
        }
    }

    if (!strcmp(SIM2 , plat->name))
    {
        INIT_WORK(&sim2_irq_work, balong_sim2_set_status);

        err = request_irq(gpio_to_irq(sim2_plat_data->sim_detection_gpio), sim2_detection_irq_handler,
    	    IRQF_TRIGGER_FALLING | IRQF_TRIGGER_RISING,
    	    pdev->name, pdev);
        if (err) {
            dev_warn(&pdev->dev, "sim2:request gpio irq error\n");
            goto no_sim_detect_irq;
        }
        
        /* sysfs entries for IO control */
        err = device_create_file(&(pdev->dev), &dev_attr_sim2_status);
        if (err) {
            dev_err(&pdev->dev, "sim2:Failed to create sysfs entry\n");
            goto err_create_device_file;
        }
    }
    return 0;

err_create_device_file:
no_sim_detect_irq:
    destroy_workqueue(workqueue);
    workqueue = NULL;
err_init_workqueue:
    gpio_free(plat->sim_detection_gpio);
    return err;
}
static int hisi_gpio_key_probe(struct platform_device* pdev)
{
	struct hisi_gpio_key *gpio_key = NULL;
	struct input_dev *input_dev = NULL;
	enum of_gpio_flags flags;
	int err =0;

	if (NULL == pdev) {
		printk(KERN_ERR "[gpiokey]parameter error!\n");
		return -EINVAL;
	}

	dev_info(&pdev->dev, "hisi gpio key driver probes start!\n");
#ifdef CONFIG_OF
	if (!of_match_node(hs_gpio_key_match, pdev->dev.of_node)) {
		dev_err(&pdev->dev, "dev node is not match. exiting.\n");
		return -ENODEV;
	}
#endif

	gpio_key = devm_kzalloc(&pdev->dev, sizeof(struct hisi_gpio_key), GFP_KERNEL);
	if (!gpio_key) {
		dev_err(&pdev->dev, "Failed to allocate struct hisi_gpio_key!\n");
		return -ENOMEM;
	}

	input_dev = input_allocate_device();
	if (!input_dev) {
		dev_err(&pdev->dev, "Failed to allocate struct input_dev!\n");
		return -ENOMEM;
	}

	input_dev->name = pdev->name;
	input_dev->id.bustype = BUS_HOST;
	input_dev->dev.parent = &pdev->dev;
	input_set_drvdata(input_dev, gpio_key);
	set_bit(EV_KEY, input_dev->evbit);
	set_bit(EV_SYN, input_dev->evbit);
	set_bit(KEY_VOLUMEUP, input_dev->keybit);
	set_bit(KEY_VOLUMEDOWN, input_dev->keybit);
#ifdef CONFIG_HISI_GPIO_KEY_SUPPORT_HI6XXX
	set_bit(KEY_BACK, input_dev->keybit);
#endif
	input_dev->open = hisi_gpio_key_open;
	input_dev->close = hisi_gpio_key_close;

	gpio_key->input_dev = input_dev;

	/*initial work before we use it.*/
	INIT_DELAYED_WORK(&(gpio_key->gpio_keyup_work), hisi_gpio_keyup_work);
	INIT_DELAYED_WORK(&(gpio_key->gpio_keydown_work), hisi_gpio_keydown_work);
	wake_lock_init(&volume_down_key_lock, WAKE_LOCK_SUSPEND, "key_down_wake_lock");
	wake_lock_init(&volume_up_key_lock, WAKE_LOCK_SUSPEND, "key_up_wake_lock");
#ifdef CONFIG_HISI_GPIO_KEY_SUPPORT_HI6XXX
	INIT_DELAYED_WORK(&(gpio_key->gpio_keyback_work), hisi_gpio_keyback_work);
	wake_lock_init(&back_key_lock, WAKE_LOCK_SUSPEND, "key_back_wake_lock");
#endif

	gpio_key->gpio_up = of_get_gpio_by_prop(pdev->dev.of_node, "gpio-keyup,gpio-irq", 0, 0, &flags);
	if (!gpio_is_valid(gpio_key->gpio_up)) {
		printk(KERN_INFO "%s: gpio of volume up is not valid, check DTS\n", __FUNCTION__);
	}

	gpio_key->gpio_down = of_get_gpio_by_prop(pdev->dev.of_node, "gpio-keydown,gpio-irq", 0, 0, &flags);
	if (!gpio_is_valid(gpio_key->gpio_down)) {
		printk(KERN_INFO "%s: gpio of volume down is not valid, check DTS\n", __FUNCTION__);
	}

#ifdef CONFIG_HISI_GPIO_KEY_SUPPORT_HI6XXX
	gpio_key->gpio_back = of_get_gpio_by_prop(pdev->dev.of_node, "gpio-keyback,gpio-irq", 0, 0, &flags);
	if (!gpio_is_valid(gpio_key->gpio_back)) {
		printk(KERN_INFO "%s: gpio of back key is not valid, check DTS\n", __FUNCTION__);
	}
#endif
    
	vol_up_gpio = gpio_key->gpio_up;
	vol_up_active_low = GPIO_KEY_PRESS;
	vol_down_gpio = gpio_key->gpio_down;
	vol_down_active_low = GPIO_KEY_PRESS;

	if (gpio_is_valid(gpio_key->gpio_up)) {
		err = gpio_request(gpio_key->gpio_up, "gpio_up");
		if (err < 0) {
			dev_err(&pdev->dev, "Fail request gpio:%d\n", gpio_key->gpio_up);
			goto err_get_gpio;
		}
		
		gpio_direction_input(gpio_key->gpio_up);

		gpio_key->volume_up_irq = gpio_to_irq(gpio_key->gpio_up);
		if (gpio_key->volume_up_irq < 0) {
			dev_err(&pdev->dev, "Failed to get gpio key press irq!\n");
			err = gpio_key->volume_up_irq;
			goto err_gpio_to_irq;
		}
	}
	if (gpio_is_valid(gpio_key->gpio_down)) {
		err = gpio_request(gpio_key->gpio_down, "gpio_down");
		if (err) {
			dev_err(&pdev->dev, "Fail request gpio:%d\n", gpio_key->gpio_down);
			goto err_gpio_down_req;
		}
		
		gpio_direction_input(gpio_key->gpio_down);

		gpio_key->volume_down_irq = gpio_to_irq(gpio_key->gpio_down);
		if (gpio_key->volume_down_irq < 0) {
			dev_err(&pdev->dev, "Failed to get gpio key release irq!\n");
			err = gpio_key->volume_down_irq;
			goto err_gpio_to_irq;
		}
	}
#ifdef CONFIG_HISI_GPIO_KEY_SUPPORT_HI6XXX
	if (gpio_is_valid(gpio_key->gpio_back)) {
		err = gpio_request(gpio_key->gpio_back, "gpio_back");
		if (err) {
			dev_err(&pdev->dev, "Fail request gpio:%d\n", gpio_key->gpio_back);
			goto err_gpio_back_req;
		}

		gpio_direction_input(gpio_key->gpio_back);

		gpio_key->key_back_irq = gpio_to_irq(gpio_key->gpio_back);
		if (gpio_key->key_back_irq < 0) {
			dev_err(&pdev->dev, "Failed to get gpio key release irq!\n");
			err = gpio_key->key_back_irq;
			goto err_gpio_to_irq;
		}
	}
#endif

	gpio_key->pctrl = devm_pinctrl_get(&pdev->dev);
	if (IS_ERR(gpio_key->pctrl)) {
		dev_err(&pdev->dev, "failed to devm pinctrl get\n");
		err = -EINVAL;
		goto err_pinctrl;
	}
	gpio_key->pins_default = pinctrl_lookup_state(gpio_key->pctrl, PINCTRL_STATE_DEFAULT);
	if (IS_ERR(gpio_key->pins_default)) {
		dev_err(&pdev->dev, "failed to pinctrl lookup state default\n");
		err = -EINVAL;
		goto err_pinctrl_put;
	}
	gpio_key->pins_idle = pinctrl_lookup_state(gpio_key->pctrl, PINCTRL_STATE_IDLE);
	if (IS_ERR(gpio_key->pins_idle)) {
		dev_err(&pdev->dev, "failed to pinctrl lookup state idle\n");
		err = -EINVAL;
		goto err_pinctrl_put;
	}
	err = pinctrl_select_state(gpio_key->pctrl, gpio_key->pins_default);
	if (err < 0) {
		dev_err(&pdev->dev, "set iomux normal error, %d\n", err);
		goto err_pinctrl_put;
	}

#if defined (CONFIG_HUAWEI_DSM)
	/* initialize the statistic variable */
	volume_up_press_count = 0;
	volume_down_press_count = 0;
	volume_up_last_press_time = 0;
	volume_down_last_press_time = 0;
#endif

	setup_timer(&(gpio_key->key_up_timer), gpio_keyup_timer, (unsigned long )gpio_key);
	setup_timer(&(gpio_key->key_down_timer), gpio_keydown_timer, (unsigned long )gpio_key);
#ifdef CONFIG_HISI_GPIO_KEY_SUPPORT_HI6XXX
	setup_timer(&(gpio_key->key_back_timer), gpio_keyback_timer, (unsigned long )gpio_key);
#endif

#if defined (CONFIG_HUAWEI_DSM)
	setup_timer(&dsm_gpio_key_timer, dsm_gpio_key_timer_func, (unsigned long)gpio_key);
#endif
	/*
	 * support failing irq that means volume-up-key is pressed,
	 * and rising irq which means volume-up-key is released.
	 */
	 if (gpio_is_valid(gpio_key->gpio_up)) {
		err = request_irq(gpio_key->volume_up_irq, hisi_gpio_key_irq_handler, IRQF_NO_SUSPEND | IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING, pdev->name, gpio_key);
		if (err) {
			dev_err(&pdev->dev, "Failed to request press interupt handler!\n");
			goto err_up_irq_req;
		}
	 }

	/*
	 * support failing irq that means volume-down-key is pressed,
	 * and rising irq which means volume-down-key is released.
	 */
	 if (gpio_is_valid(gpio_key->gpio_down)) {
		err = request_irq(gpio_key->volume_down_irq, hisi_gpio_key_irq_handler, IRQF_NO_SUSPEND | IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING, pdev->name, gpio_key);
		if (err) {
			dev_err(&pdev->dev, "Failed to request release interupt handler!\n");
			goto err_down_irq_req;
		}
	 }

#ifdef CONFIG_HISI_GPIO_KEY_SUPPORT_HI6XXX
	if (gpio_is_valid(gpio_key->gpio_back)) {
		err = request_irq(gpio_key->key_back_irq, hisi_gpio_key_irq_handler, IRQF_NO_SUSPEND | IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING, pdev->name, gpio_key);
		if (err) {
			dev_err(&pdev->dev, "Failed to request release interupt handler!\n");
			goto err_back_irq_req;
		}
	}
#endif

	err = input_register_device(gpio_key->input_dev);
	if (err) {
		dev_err(&pdev->dev, "Failed to register input device!\n");
		goto err_register_dev;
	}

	device_init_wakeup(&pdev->dev, TRUE);
	platform_set_drvdata(pdev, gpio_key);

#if defined (CONFIG_HUAWEI_DSM)
	if (!key_dclient) {
		key_dclient = dsm_register_client(&dsm_key);
	}

	mod_timer(&dsm_gpio_key_timer, jiffies + STATISTIC_INTERVAL * HZ);
#endif

	dev_info(&pdev->dev, "hisi gpio key driver probes successfully!\n");
	return 0;

err_register_dev:
#ifdef  CONFIG_HISI_GPIO_KEY_SUPPORT_HI6XXX
	free_irq(gpio_key->key_back_irq, gpio_key);
err_back_irq_req:
#endif
	free_irq(gpio_key->volume_down_irq, gpio_key);
err_down_irq_req:
	free_irq(gpio_key->volume_up_irq, gpio_key);
err_up_irq_req:
err_pinctrl_put:
	devm_pinctrl_put(gpio_key->pctrl);
err_pinctrl:
err_gpio_to_irq:
#ifdef CONFIG_HISI_GPIO_KEY_SUPPORT_HI6XXX
	gpio_free(gpio_key->gpio_back);
err_gpio_back_req:
#endif
	gpio_free(gpio_key->gpio_down);
err_gpio_down_req:
	gpio_free(gpio_key->gpio_up);
err_get_gpio:
	input_free_device(input_dev);
	wake_lock_destroy(&volume_down_key_lock);
	wake_lock_destroy(&volume_up_key_lock);
#ifdef CONFIG_HISI_GPIO_KEY_SUPPORT_HI6XXX
	wake_lock_destroy(&back_key_lock);
#endif
	pr_info(KERN_ERR "[gpiokey]K3v3 gpio key probe failed! ret = %d.\n", err);
	return err;
}
/**************************GPIO ********************************************/
int gpio_cmds_tx(struct platform_device *pdev, struct gpio_desc *cmds, int cnt)
{
    int ret = 0;
    struct gpio_desc *cm = NULL;
    int i = 0;
    struct device      *dev;
    struct device_node *np;
    enum of_gpio_flags gpio_flags;

    if (pdev) {
        dev = &pdev->dev;
        np  = dev->of_node;
    }

    cm = cmds;
    for (i = 0; i < cnt; i++) {
        if ((cm == NULL) || (cm->label == NULL)) {
            balongfb_loge("cm or cm->label is null! index=%d\n", i);
            ret = -1;
            goto error;
        }
        if ((cm->dtype == DTYPE_GPIO_GET) && (pdev)) {
            *(cm->gpio) = of_get_gpio_by_prop(np, cm->label, 0, 0, &gpio_flags);
            if (!gpio_is_valid(*(cm->gpio))) {
                balongfb_loge("gpio invalid, dtype=%d, lable=%s, gpio=%d!\n",
                        cm->dtype, cm->label, *(cm->gpio));
            }
        } else if (cm->dtype == DTYPE_GPIO_INPUT) {
            if (gpio_direction_input(*(cm->gpio)) != 0) {
                balongfb_loge("failed to gpio_direction_input, lable=%s, gpio=%d!\n",
                        cm->label, *(cm->gpio));
                ret = -1;
                goto error;
            }
        } else if (cm->dtype == DTYPE_GPIO_OUTPUT) {
            if (gpio_direction_output(*(cm->gpio), cm->value) != 0) {
                balongfb_loge("failed to gpio_direction_output, label%s, gpio=%d!\n",
                        cm->label, *(cm->gpio));
                ret = -1;
                goto error;
            }
        } else if (cm->dtype == DTYPE_GPIO_REQUEST) {
            if (gpio_request(*(cm->gpio), cm->label) != 0) {
                balongfb_loge("failed to gpio_request, lable=%s, gpio=%d!\n",
                        cm->label, *(cm->gpio));
                ret = -1;
                goto error;
            }
        } else if (cm->dtype == DTYPE_GPIO_FREE) {
            gpio_free(*(cm->gpio));
        } else {
            balongfb_loge("dtype=%x NOT supported\n", cm->dtype);
            ret = -1;
            goto error;
        }

        if (cm->wait) {
            if (cm->waittype == WAIT_TYPE_US)
                udelay(cm->wait);
            else if (cm->waittype == WAIT_TYPE_MS)
                mdelay(cm->wait);
            else
                mdelay(cm->wait * 1000);
        }

        cm++;
    }

    return 0;

error:
    return ret;
}