static int fimc_is_ois_i2c_config(struct i2c_client *client, bool onoff)
{
	struct pinctrl *pinctrl_i2c = NULL;
	struct device *i2c_dev = NULL;
	struct fimc_is_device_ois *ois_device;
	struct fimc_is_ois_gpio *gpio;

	if (!client) {
		pr_info("%s: client is null\n", __func__);
		return -ENODEV;
	}

	i2c_dev = client->dev.parent->parent;
	ois_device = i2c_get_clientdata(client);
	gpio = &ois_device->gpio;

	if (ois_device->ois_hsi2c_status != onoff) {
		info("%s : ois_hsi2c_stauts(%d),onoff(%d), use_i2c_pinctrl(%d)\n",
			__func__, ois_device->ois_hsi2c_status, onoff, gpio->use_i2c_pinctrl);
		if (onoff) {
			if(gpio->use_i2c_pinctrl) {
				pin_config_set(gpio->pinname, gpio->sda,
					PINCFG_PACK(PINCFG_TYPE_FUNC, gpio->pinfunc_on));
				pin_config_set(gpio->pinname, gpio->scl,
					PINCFG_PACK(PINCFG_TYPE_FUNC, gpio->pinfunc_on));
			}
			pinctrl_i2c = devm_pinctrl_get_select(i2c_dev, "on_i2c");
			if (IS_ERR_OR_NULL(pinctrl_i2c)) {
				printk(KERN_ERR "%s: Failed to configure i2c pin\n", __func__);
			} else {
				devm_pinctrl_put(pinctrl_i2c);
			}
		} else {
			pinctrl_i2c = devm_pinctrl_get_select(i2c_dev, "off_i2c");
			if (IS_ERR_OR_NULL(pinctrl_i2c)) {
				printk(KERN_ERR "%s: Failed to configure i2c pin\n", __func__);
			} else {
				devm_pinctrl_put(pinctrl_i2c);
			}
			if(gpio->use_i2c_pinctrl) {
				pin_config_set(gpio->pinname, gpio->sda,
					PINCFG_PACK(PINCFG_TYPE_FUNC, gpio->pinfunc_off));
				pin_config_set(gpio->pinname, gpio->scl,
					PINCFG_PACK(PINCFG_TYPE_FUNC, gpio->pinfunc_off));
			}
		}
		ois_device->ois_hsi2c_status = onoff;
	}

	return 0;
}
Esempio n. 2
0
/**
 * gyr_free_platform_resource - free ir related resource
 * return value:
 */
static void ir_free_platform_resource(enum input_sensor_type *ir_type)
{
	struct ir_config_info *data = container_of(ir_type,
					struct ir_config_info, input_type);
	if (!IS_ERR_OR_NULL(data->pinctrl))
		devm_pinctrl_put(data->pinctrl);
}
Esempio n. 3
0
static int cyttsp4_pinctrl_init(struct cyttsp4_core_platform_data *data, int on, struct device *dev)
{
	if (!on) {
		goto pinctrl_put;
	}

	data->pinctrl = devm_pinctrl_get(dev->parent);
	if (IS_ERR_OR_NULL(data->pinctrl)) {
		dev_err(dev, "%s:failed to get pinctrl!\n", __func__);
		return PTR_ERR(data->pinctrl);
	}

	data->gpio_state_active = pinctrl_lookup_state(data->pinctrl, "pmx_ts_active");
	if (IS_ERR_OR_NULL(data->gpio_state_active)) {
		dev_err(dev, "%s:failed to look up pmx_ts_active state!\n", __func__);
		return PTR_ERR(data->gpio_state_active);
	}

	data->gpio_state_suspend = pinctrl_lookup_state(data->pinctrl, "pmx_ts_suspend");
	if (IS_ERR_OR_NULL(data->gpio_state_suspend)) {
		dev_err(dev, "%s:failed to look up pmx_ts_suspend state!\n", __func__);
		return PTR_ERR(data->gpio_state_suspend);
	}

	return 0;

pinctrl_put:
	devm_pinctrl_put(data->pinctrl);
	return 0;
}
Esempio n. 4
0
static void aml_m6_pinmux_deinit(struct snd_soc_card *card)
{
    struct aml_audio_private_data *p_aml_audio;

    p_aml_audio = snd_soc_card_get_drvdata(card);

    amlogic_gpio_free(p_aml_audio->gpio_hp_det,"wm8960");
    devm_pinctrl_put(p_aml_audio->pin_ctl);
}
/*
 **************************************************************************
 * FunctionName: ispv1_io_hw_deinit;
 * Description : ispio & csi deinit;
 * Input       : NA
 * Output      : NA;
 * ReturnValue : NA;
 * Other       : NA;
 **************************************************************************
 */
int ispv1_io_hw_deinit(void)
{
	print_debug("Enter %s", __func__);

    devm_pinctrl_put(ispv1_io.isp_pinctrl);
    ispv1_io.isp_pinctrl = NULL;

	return 0;
}
Esempio n. 6
0
static int __exit sunxi_daudio0_dev_remove(struct platform_device *pdev)
{
	if (daudio_used) {
		daudio_used = 0;

		if ((NULL == daudio_moduleclk) ||(IS_ERR(daudio_moduleclk))) {
			pr_err("daudio_moduleclk handle is invalid, just return\n");
			return -EFAULT;
		} else {
			/*release the module clock*/
			clk_disable(daudio_moduleclk);
		}
		#ifdef CONFIG_ARCH_SUN8IW7
		if ((NULL == daudio_pll) ||(IS_ERR(daudio_pll))) {
			pr_err("daudio_pll handle is invalid, just return\n");
			return -EFAULT;
		} else {
			/*reease pll clk*/
			clk_put(daudio_pll);
		}
		#else
		#ifndef CONFIG_ARCH_SUN9I
		if ((NULL == daudio_pllx8) ||(IS_ERR(daudio_pllx8))) {
			pr_err("daudio_pllx8 handle is invalid, just return\n");
			return -EFAULT;
		} else {
			/*reease pllx8clk*/
			clk_put(daudio_pllx8);
		}
		#endif
		#endif
		#ifdef CONFIG_ARCH_SUN9I
		if ((NULL == daudio_pll3clk) ||(IS_ERR(daudio_pll3clk))) {
			pr_err("daudio_pll2clk handle is invalid, just return\n");
			return -EFAULT;
		} else {
			clk_put(daudio_pll3clk);
		}
		#else
		#ifndef CONFIG_ARCH_SUN8IW7
		if ((NULL == daudio_pll2clk) ||(IS_ERR(daudio_pll2clk))) {
			pr_err("daudio_pll2clk handle is invalid, just return\n");
			return -EFAULT;
		} else {
			/*release pll2clk*/
			clk_put(daudio_pll2clk);
		}
		#endif
		#endif

		devm_pinctrl_put(daudio_pinctrl);
		snd_soc_unregister_dai(&pdev->dev);
		platform_set_drvdata(pdev, NULL);
	}
	return 0;
}
Esempio n. 7
0
void sd_gpio_enable(SDIO_Pad_Type_t io_pad_type)
{
	switch (io_pad_type) {
		
		case SDHC_CARD_0_5 :	//SDHC-B
#ifdef CONFIG_OF
			if(p)
				devm_pinctrl_put(p);
			p=NULL;
#else
			pinmux_clr(&SDHC_CARD_0_5_set);
#endif
			CLEAR_CBUS_REG_MASK(SDIO_MULT_CONFIG, (1));
			break;

		case SDHC_BOOT_0_11 :	//SDHC-C
#ifdef CONFIG_OF
			if(p)
				devm_pinctrl_put(p);
			p=NULL;
#else
			pinmux_clr(&SDHC_BOOT_0_11_set);
#endif
			CLEAR_CBUS_REG_MASK(SDIO_MULT_CONFIG, (2));
			break;

		case SDHC_GPIOX_0_9 :	//SDHC-A
#ifdef CONFIG_OF
			if(p)
				devm_pinctrl_put(p);
			p=NULL;
#else
			pinmux_clr(&SDHC_GPIOX_0_9_set);
#endif
			CLEAR_CBUS_REG_MASK(SDIO_MULT_CONFIG, (0));
			break;
		default :
			printk("invalid hw io pad!!!\n");
			break;
	}
	
	return;
}
static void __tpiu_disable_setb(struct tpiu_drvdata *drvdata)
{
	int i;

	if (drvdata->tpiu_pctrl) {
		devm_pinctrl_put(drvdata->tpiu_pctrl->pctrl);
	} else {
		for (i = 0; i < drvdata->setb_gpiocnt; i++)
			gpio_free(drvdata->setb_gpios[i]);
	}
}
static void pn547_pinctrl_destroy(struct pn547_dev *dev)
{
	int ret = 0;

	ret = pn547_pinctrl_config(dev, 0);
	if (ret)
		dev_err(dev->dev, "%s: pinctrol failed on destroy %d\n",
			__func__, ret);

	devm_pinctrl_put(dev->pinctrl);
}
Esempio n. 10
0
static void aml_m8_pinmux_deinit(struct snd_soc_card *card)
{
    struct aml_audio_private_data *p_aml_audio;

    p_aml_audio = snd_soc_card_get_drvdata(card);
    if(p_aml_audio->gpio_hp_det)
        amlogic_gpio_free(p_aml_audio->gpio_hp_det,"hp_det");
    if(p_aml_audio->gpio_mute)
        amlogic_gpio_free(p_aml_audio->gpio_mute,"mute_spk");
    if(p_aml_audio->pin_ctl)
        devm_pinctrl_put(p_aml_audio->pin_ctl);
}
Esempio n. 11
0
static int __exit sunxi_spdif_dev_remove(struct platform_device *pdev)
{
	if (spdif_used) {
		spdif_used = 0;
		if ((NULL == spdif_moduleclk) ||(IS_ERR(spdif_moduleclk))) {
			printk("spdif_moduleclk handle is invalid, just return\n");
			return -EFAULT;
		} else {
			/*release the module clock*/
			clk_disable(spdif_moduleclk);
		}
#ifndef		CONFIG_ARCH_SUN9IW1
		if ((NULL == spdif_pllx8) ||(IS_ERR(spdif_pllx8))) {
			printk("spdif_pllx8 handle is invalid, just return\n");
			return -EFAULT;
		} else {
			/*release pllx8clk*/
			clk_put(spdif_pllx8);
		}

		if ((NULL == spdif_pll2clk) ||(IS_ERR(spdif_pll2clk))) {
			printk("spdif_pll2clk handle is invalid, just return\n");
			return -EFAULT;
		} else {
			/*release pll2clk*/
			clk_put(spdif_pll2clk);
		}
#else
		if ((NULL == spdif_pll3clk) ||(IS_ERR(spdif_pll3clk))) {
			printk("spdif_pll2clk handle is invalid, just return\n");
			return -EFAULT;
		} else {
			/*release pll3clk*/
			clk_put(spdif_pll3clk);
		}
#endif
//		if ((NULL == spdif_apbclk) ||(IS_ERR(spdif_apbclk))) {
//			printk("spdif_apbclk handle is invalid, just return\n");
//			return -EFAULT;
//		} else {
//			/*release apbclk*/
//			clk_put(spdif_apbclk);
//		}
		devm_pinctrl_put(spdif_pinctrl);

		snd_soc_unregister_dai(&pdev->dev);
		platform_set_drvdata(pdev, NULL);
	}
	
	return 0;
}
static void fimc_is_ois_i2c_config(struct i2c_client *client, bool onoff)
{
	struct pinctrl *pinctrl_i2c = NULL;
	struct device *i2c_dev = client->dev.parent->parent;
	struct fimc_is_device_ois *ois_device = i2c_get_clientdata(client);

	if (ois_device->ois_hsi2c_status != onoff) {
		info("%s : ois_hsi2c_stauts(%d),onoff(%d)\n",__func__,
			ois_device->ois_hsi2c_status, onoff);

		if (onoff) {
			pin_config_set(FIMC_IS_SPI_PINNAME, "gpc2-2",
				PINCFG_PACK(PINCFG_TYPE_FUNC, 0));
			pin_config_set(FIMC_IS_SPI_PINNAME, "gpc2-3",
				PINCFG_PACK(PINCFG_TYPE_FUNC, 0));

			pinctrl_i2c = devm_pinctrl_get_select(i2c_dev, "on_i2c");
			if (IS_ERR_OR_NULL(pinctrl_i2c)) {
				printk(KERN_ERR "%s: Failed to configure i2c pin\n", __func__);
			} else {
				devm_pinctrl_put(pinctrl_i2c);
			}
		} else {
			pinctrl_i2c = devm_pinctrl_get_select(i2c_dev, "off_i2c");
			if (IS_ERR_OR_NULL(pinctrl_i2c)) {
				printk(KERN_ERR "%s: Failed to configure i2c pin\n", __func__);
			} else {
				devm_pinctrl_put(pinctrl_i2c);
			}

			pin_config_set(FIMC_IS_SPI_PINNAME, "gpc2-2",
				PINCFG_PACK(PINCFG_TYPE_FUNC, 2));
			pin_config_set(FIMC_IS_SPI_PINNAME, "gpc2-3",
				PINCFG_PACK(PINCFG_TYPE_FUNC, 2));
		}
		ois_device->ois_hsi2c_status = onoff;
	}
}
Esempio n. 13
0
static int sunxi_daudio0_suspend(struct snd_soc_dai *cpu_dai)
{
	u32 reg_val;
	u32 pin_index = 0;
	u32 config;
	struct gpio_config *pin_daudio0_cfg;
	char pin_name[SUNXI_PIN_NAME_MAX_LEN];
	pr_debug("[DAUDIO]Entered %s\n", __func__);

	/*Global disable Digital Audio Interface*/
	reg_val = sunxi_smc_readl(sunxi_daudio.regs + SUNXI_DAUDIOCTL);
	reg_val &= ~SUNXI_DAUDIOCTL_GEN;
	sunxi_smc_writel(reg_val, sunxi_daudio.regs + SUNXI_DAUDIOCTL);

	daudioregsave();

	if ((NULL == daudio_moduleclk) ||(IS_ERR(daudio_moduleclk))) {
		pr_err("daudio_moduleclk handle is invalid, just return\n");
		return -EFAULT;
	} else {
		/*release the module clock*/
		clk_disable(daudio_moduleclk);
	}
	#if defined(CONFIG_ARCH_SUN8IW6) || defined(CONFIG_ARCH_SUN8IW8)
	if ((NULL == daudio_pll2clk) ||(IS_ERR(daudio_pll2clk))) {
		pr_err("daudio_pll2clk handle is invalid, just return\n");
		return -EFAULT;
	} else {
		/*release the module clock*/
		clk_disable(daudio_pll2clk);
	}
	if ((NULL == daudio_pllx8) ||(IS_ERR(daudio_pllx8))) {
		pr_err("daudio_pllx8 handle is invalid, just return\n");
		return -EFAULT;
	} else {
		/*release the module clock*/
		clk_disable(daudio_pllx8);
	}
	#endif
	devm_pinctrl_put(daudio_pinctrl);
	/* request pin individually */
	for (pin_index = 0; pin_index < pin_count; pin_index++) {
		pin_daudio0_cfg = &(pin_daudio0_list[pin_index].gpio);
		/* valid pin of sunxi-pinctrl, config pin attributes individually.*/
		sunxi_gpio_to_name(pin_daudio0_cfg->gpio, pin_name);
		config = SUNXI_PINCFG_PACK(SUNXI_PINCFG_TYPE_FUNC, 7);
		pin_config_set(SUNXI_PINCTRL, pin_name, config);
	}
	return 0;
}
Esempio n. 14
0
static int i2s_gpio_set(struct snd_soc_card *card)
{
    struct aml_audio_private_data *p_aml_audio;
    const char *str=NULL;
    int ret;
    

    p_aml_audio = snd_soc_card_get_drvdata(card);
    if(p_aml_audio->pin_ctl)
        devm_pinctrl_put(p_aml_audio->pin_ctl);
    ret = of_property_read_string(card->dev->of_node, "I2S_MCLK", &str);
    if (ret < 0) {
        printk("I2S_MCLK: faild to get gpio I2S_MCLK!\n");
    }else{
        p_aml_audio->gpio_i2s_m = amlogic_gpio_name_map_num(str);
        amlogic_gpio_request_one(p_aml_audio->gpio_i2s_m,GPIOF_OUT_INIT_LOW,"low_mclk");
        amlogic_set_value(p_aml_audio->gpio_i2s_m, 0, "low_mclk");
    }

    ret = of_property_read_string(card->dev->of_node, "I2S_SCLK", &str);
    if (ret < 0) {
        printk("I2S_SCLK: faild to get gpio I2S_SCLK!\n");
    }else{
        p_aml_audio->gpio_i2s_s = amlogic_gpio_name_map_num(str);
        amlogic_gpio_request_one(p_aml_audio->gpio_i2s_s,GPIOF_OUT_INIT_LOW,"low_sclk");
        amlogic_set_value(p_aml_audio->gpio_i2s_s, 0, "low_sclk");
    }

    ret = of_property_read_string(card->dev->of_node, "I2S_LRCLK", &str);
    if (ret < 0) {
        printk("I2S_LRCLK: faild to get gpio I2S_LRCLK!\n");
    }else{
        p_aml_audio->gpio_i2s_r = amlogic_gpio_name_map_num(str);
        amlogic_gpio_request_one(p_aml_audio->gpio_i2s_r,GPIOF_OUT_INIT_LOW,"low_lrclk");
        amlogic_set_value(p_aml_audio->gpio_i2s_r, 0, "low_lrclk");
    }

    ret = of_property_read_string(card->dev->of_node, "I2S_ODAT", &str);
    if (ret < 0) {
        printk("I2S_ODAT: faild to get gpio I2S_ODAT!\n");
    }else{
        p_aml_audio->gpio_i2s_o = amlogic_gpio_name_map_num(str);
        amlogic_gpio_request_one(p_aml_audio->gpio_i2s_o,GPIOF_OUT_INIT_LOW,"low_odata");
        amlogic_set_value(p_aml_audio->gpio_i2s_o, 0, "low_odata");
    }
    //mute spk
    amlogic_set_value(p_aml_audio->gpio_mute, 0, "mute_spk");
    return 0;
}
Esempio n. 15
0
int bt_enable_pinctrl_init(struct device *dev, struct bluetooth_pm_device_info *bdev)
{
	int ret = 0;

	bdev->gpio_state_active = bdev->gpio_state_suspend = 0;
	bdev->bt_pinctrl = devm_pinctrl_get(dev);
	if (IS_ERR_OR_NULL(bdev->bt_pinctrl)) {
		pr_err("%s: target does not use pinctrl for bt enable\n", __func__);
		return -ENODEV;
	}


	bdev->gpio_state_active = pinctrl_lookup_state(bdev->bt_pinctrl, "bt_enable_active");
	if (IS_ERR_OR_NULL(bdev->gpio_state_active)) {
		pr_err("%s: can't get gpio_state_active for bt enable\n", __func__);
		ret = -ENODEV;
		goto err_active_state;
	}

	bdev->gpio_state_suspend = pinctrl_lookup_state(bdev->bt_pinctrl, "bt_enable_suspend");
	if (IS_ERR_OR_NULL(bdev->gpio_state_suspend)) {
		pr_err("%s: can't get gpio_state_suspend for bt enable\n", __func__);
		ret = -ENODEV;
		goto err_suspend_state;
	}

	if (pinctrl_select_state(bdev->bt_pinctrl, bdev->gpio_state_suspend)) { 
		pr_err("%s: error on pinctrl_select_state for bt enable\n", __func__);
		ret = -ENODEV;
		goto err_suspend_state;
	} else {
	 	printk("%s: success to set pinctrl_select_state for bt enable\n", __func__);
	}
	pr_err("%s: bdev->gpio_bt_reset = %d		bsi->bt_reset = %d	 \n",__func__,bdev->gpio_bt_reset,bsi->bt_reset);
err_suspend_state:
	bdev->gpio_state_suspend = 0;

err_active_state:
	bdev->gpio_state_active = 0;
	devm_pinctrl_put(bdev->bt_pinctrl);
	bdev->bt_pinctrl = 0;
	
	return ret;	

}
int pinctrl_bind_pins(struct device *dev)
{
	int ret;

	dev->pins = devm_kzalloc(dev, sizeof(*(dev->pins)), GFP_KERNEL);
	if (!dev->pins)
		return -ENOMEM;

	dev->pins->p = devm_pinctrl_get(dev);
	if (IS_ERR(dev->pins->p)) {
		dev_dbg(dev, "no pinctrl handle\n");
		ret = PTR_ERR(dev->pins->p);
		goto cleanup_alloc;
	}

	dev->pins->default_state = pinctrl_lookup_state(dev->pins->p,
					PINCTRL_STATE_DEFAULT);
	if (IS_ERR(dev->pins->default_state)) {
		dev_dbg(dev, "no default pinctrl state\n");
		ret = 0;
		goto cleanup_get;
	}

	ret = pinctrl_select_state(dev->pins->p, dev->pins->default_state);
	if (ret) {
		dev_dbg(dev, "failed to activate default pinctrl state\n");
		goto cleanup_get;
	}

	return 0;

cleanup_get:
	devm_pinctrl_put(dev->pins->p);
cleanup_alloc:
	devm_kfree(dev, dev->pins);
	dev->pins = NULL;

	
	if (ret != -EPROBE_DEFER)
		ret = 0;

	return ret;
}
static int cw_bat_pinctrl_init(struct cw_battery *cw_bat)
{
	int retval;

	/* Get pinctrl if target uses pinctrl */
	cw_bat->ts_pinctrl = devm_pinctrl_get(&(cw_bat->client->dev));
	if (IS_ERR_OR_NULL(cw_bat->ts_pinctrl)) {
		retval = PTR_ERR(cw_bat->ts_pinctrl);
		dev_dbg(&cw_bat->client->dev,
			"%s Target does not use pinctrl  %d\n", __func__, retval);
		goto err_pinctrl_get;
	}

	cw_bat->pinctrl_state_active
		= pinctrl_lookup_state(cw_bat->ts_pinctrl,
				PINCTRL_STATE_ACTIVE);
	if (IS_ERR_OR_NULL(cw_bat->pinctrl_state_active)) {
		retval = PTR_ERR(cw_bat->pinctrl_state_active);
		dev_err(&cw_bat->client->dev,
			"%s Can not lookup %s pinstate %d\n",
			__func__, PINCTRL_STATE_ACTIVE, retval);
		goto err_pinctrl_lookup;
	}

	cw_bat->pinctrl_state_suspend
		= pinctrl_lookup_state(cw_bat->ts_pinctrl,
				PINCTRL_STATE_SUSPEND);
	if (IS_ERR_OR_NULL(cw_bat->pinctrl_state_suspend)) {
		retval = PTR_ERR(cw_bat->pinctrl_state_suspend);
		dev_err(&cw_bat->client->dev,
				"%s Can not lookup %s pinstate %d\n",
				__func__, PINCTRL_STATE_SUSPEND, retval);
		goto err_pinctrl_lookup;
	}

	return 0;

err_pinctrl_lookup:
	devm_pinctrl_put(cw_bat->ts_pinctrl);
err_pinctrl_get:
	cw_bat->ts_pinctrl = NULL;
	return retval;
}
static int hisi_gpio_key_remove(struct platform_device* pdev)
{
	struct hisi_gpio_key *gpio_key = platform_get_drvdata(pdev);

	if (gpio_key == NULL) {
		printk(KERN_ERR "get invalid gpio_key pointer\n");
		return -EINVAL;
	}

	free_irq(gpio_key->volume_up_irq, gpio_key);
	free_irq(gpio_key->volume_down_irq, gpio_key);
	gpio_free((unsigned int)gpio_key->gpio_up);
	gpio_free((unsigned int)gpio_key->gpio_down);
	devm_pinctrl_put(gpio_key->pctrl);
	cancel_delayed_work(&(gpio_key->gpio_keyup_work));
	cancel_delayed_work(&(gpio_key->gpio_keydown_work));
	wake_lock_destroy(&volume_down_key_lock);
	wake_lock_destroy(&volume_up_key_lock);
#ifdef CONFIG_HISI_GPIO_KEY_SUPPORT_HI6XXX
	free_irq(gpio_key->key_back_irq, gpio_key);
	gpio_free((unsigned int)gpio_key->gpio_back);
	cancel_delayed_work(&(gpio_key->gpio_keyback_work));
	wake_lock_destroy(&back_key_lock);
#endif
#ifdef CONFIG_HISI_GPIO_KEY_SUPPORT_SMART_KEY
	free_irq(gpio_key->key_smart_irq, gpio_key);
	gpio_free((unsigned int)gpio_key->gpio_smart);
	cancel_delayed_work(&(gpio_key->gpio_keysmart_work));
	wake_lock_destroy(&smart_key_lock);
#endif

	input_unregister_device(gpio_key->input_dev);
	platform_set_drvdata(pdev, NULL);
	kfree(gpio_key);
	gpio_key = NULL;
	return 0;
}
int fimc_is_sensor_parse_dt_with_companion(struct platform_device *pdev)
{
	int ret = 0;
	u32 temp;
	char *pprop;
	struct exynos_platform_fimc_is_sensor *pdata;
	struct device_node *dnode;
	struct device *dev;
	int gpio_reset = 0, gpio_standby = 0;
#ifdef CONFIG_SOC_EXYNOS5422
	int gpios_cam_en = 0;
#endif
#if !defined(CONFIG_USE_VENDER_FEATURE) /* LSI Patch */
	int gpio_cam_en = 0;
	int gpio_comp_en, gpio_comp_rst;
#else
	const char *name;
#endif
#ifdef CONFIG_SOC_EXYNOS5433
	struct pinctrl *pinctrl_ch = NULL;
#endif
	int gpio_none = 0;
	u32 id;

	BUG_ON(!pdev);
	BUG_ON(!pdev->dev.of_node);

	dev = &pdev->dev;
	dnode = dev->of_node;

	pdata = kzalloc(sizeof(struct exynos_platform_fimc_is_sensor), GFP_KERNEL);
	if (!pdata) {
		pr_err("%s: no memory for platform data\n", __func__);
		return -ENOMEM;
	}

	pdata->gpio_cfg = exynos_fimc_is_sensor_pins_cfg;
	pdata->iclk_cfg = exynos_fimc_is_sensor_iclk_cfg;
	pdata->iclk_on = exynos_fimc_is_sensor_iclk_on;
	pdata->iclk_off = exynos_fimc_is_sensor_iclk_off;
	pdata->mclk_on = exynos_fimc_is_sensor_mclk_on;
	pdata->mclk_off = exynos_fimc_is_sensor_mclk_off;

	ret = of_property_read_u32(dnode, "scenario", &pdata->scenario);
	if (ret) {
		err("scenario read is fail(%d)", ret);
		goto p_err;
	}

	ret = of_property_read_u32(dnode, "mclk_ch", &pdata->mclk_ch);
	if (ret) {
		err("mclk_ch read is fail(%d)", ret);
		goto p_err;
	}

	ret = of_property_read_u32(dnode, "csi_ch", &pdata->csi_ch);
	if (ret) {
		err("csi_ch read is fail(%d)", ret);
		goto p_err;
	}

	ret = of_property_read_u32(dnode, "flite_ch", &pdata->flite_ch);
	if (ret) {
		err("flite_ch read is fail(%d)", ret);
		goto p_err;
	}

	ret = of_property_read_u32(dnode, "i2c_ch", &pdata->i2c_ch);
	if (ret) {
		err("i2c_ch read is fail(%d)", ret);
		goto p_err;
	}

	ret = of_property_read_u32(dnode, "i2c_addr", &pdata->i2c_addr);
	if (ret) {
		err("i2c_addr read is fail(%d)", ret);
		goto p_err;
	}

	ret = of_property_read_u32(dnode, "is_bns", &pdata->is_bns);
	if (ret) {
		err("is_bns read is fail(%d)", ret);
		goto p_err;
	}

	ret = of_property_read_u32(dnode, "id", &id);
	if (ret) {
		err("id read is fail(%d)", ret);
		goto p_err;
	}
	pdata->id = id;

	DT_READ_U32(dnode, "flash_first_gpio",   pdata->flash_first_gpio );
	DT_READ_U32(dnode, "flash_second_gpio",  pdata->flash_second_gpio);

#ifdef CONFIG_USE_VENDER_FEATURE
	ret = of_property_read_string(dnode, "sensor_name", &name);
	if (ret) {
		err("sensor_name read is fail(%d)", ret);
		goto p_err;
	}
	strcpy(pdata->sensor_name, name);

	ret = of_property_read_u32(dnode, "sensor_id", &pdata->sensor_id);
	if (ret) {
		err("sensor_id read is fail(%d)", ret);
		goto p_err;
	}
#endif
	gpio_reset = of_get_named_gpio(dnode, "gpio_reset", 0);
	if (!gpio_is_valid(gpio_reset)) {
		dev_err(dev, "failed to get PIN_RESET\n");
		ret = -EINVAL;
		goto p_err;
	} else {
		gpio_request_one(gpio_reset, GPIOF_OUT_INIT_LOW, "CAM_GPIO_OUTPUT_LOW");
		gpio_free(gpio_reset);
	}
#ifdef CONFIG_SOC_EXYNOS5422
	gpios_cam_en = of_get_named_gpio(dnode, "gpios_cam_en", 0);
	if (!gpio_is_valid(gpios_cam_en)) {
		dev_err(dev, "failed to get main/front cam en gpio\n");
	} else {
		gpio_request_one(gpios_cam_en, GPIOF_OUT_INIT_LOW, "CAM_GPIO_OUTPUT_LOW");
		gpio_free(gpios_cam_en);
	}
#endif

#if !defined(CONFIG_USE_VENDER_FEATURE) /* LSI Patch */
	/* Optional Feature */
	gpio_comp_en = of_get_named_gpio(dnode, "gpios_comp_en", 0);
	if (!gpio_is_valid(gpio_comp_en))
	dev_err(dev, "failed to get main comp en gpio\n");

	gpio_comp_rst = of_get_named_gpio(dnode, "gpios_comp_reset", 0);
	if (!gpio_is_valid(gpio_comp_rst))
	dev_err(dev, "failed to get main comp reset gpio\n");

	gpio_standby = of_get_named_gpio(dnode, "gpio_standby", 0);
	if (!gpio_is_valid(gpio_standby))
		dev_err(dev, "failed to get gpio_standby\n");

	gpio_cam_en = of_get_named_gpio(dnode, "gpios_cam_en", 0);
	if (!gpio_is_valid(gpio_cam_en))
		dev_err(dev, "failed to get gpio_cam_en\n");

	SET_PIN(pdata, SENSOR_SCENARIO_NORMAL, GPIO_SCENARIO_ON, 0, gpio_cam_en, 0, NULL, PIN_OUTPUT_HIGH);
	SET_PIN(pdata, SENSOR_SCENARIO_NORMAL, GPIO_SCENARIO_ON, 1, gpio_reset, 0, NULL, PIN_RESET);
	SET_PIN(pdata, SENSOR_SCENARIO_NORMAL, GPIO_SCENARIO_ON, 2, gpio_none, 0, "ch", PIN_FUNCTION);
	SET_PIN(pdata, SENSOR_SCENARIO_NORMAL, GPIO_SCENARIO_ON, 3, gpio_comp_en, 0, NULL, PIN_OUTPUT_HIGH);
	SET_PIN(pdata, SENSOR_SCENARIO_NORMAL, GPIO_SCENARIO_ON, 4, gpio_comp_rst, 0, NULL, PIN_RESET);
	if (id == SENSOR_POSITION_REAR) {
		SET_PIN(pdata, SENSOR_SCENARIO_NORMAL, GPIO_SCENARIO_ON, 5, gpio_none, 0, "af", PIN_FUNCTION);
	}
	SET_PIN(pdata, SENSOR_SCENARIO_NORMAL, GPIO_SCENARIO_ON, 6, gpio_none, 0, NULL, PIN_END);

	SET_PIN(pdata, SENSOR_SCENARIO_NORMAL, GPIO_SCENARIO_OFF, 0, gpio_reset, 0, NULL, PIN_RESET);
	SET_PIN(pdata, SENSOR_SCENARIO_NORMAL, GPIO_SCENARIO_OFF, 1, gpio_reset, 0, NULL, PIN_INPUT);
	SET_PIN(pdata, SENSOR_SCENARIO_NORMAL, GPIO_SCENARIO_OFF, 2, gpio_comp_rst, 0, NULL, PIN_RESET);
	SET_PIN(pdata, SENSOR_SCENARIO_NORMAL, GPIO_SCENARIO_OFF, 3, gpio_comp_rst, 0, NULL, PIN_INPUT);
	SET_PIN(pdata, SENSOR_SCENARIO_NORMAL, GPIO_SCENARIO_OFF, 4, gpio_comp_en, 0, NULL, PIN_INPUT);
	SET_PIN(pdata, SENSOR_SCENARIO_NORMAL, GPIO_SCENARIO_OFF, 5, gpio_cam_en, 0, NULL, PIN_OUTPUT_LOW);
	SET_PIN(pdata, SENSOR_SCENARIO_NORMAL, GPIO_SCENARIO_OFF, 6, gpio_none, 0, NULL, PIN_END);

	SET_PIN(pdata, SENSOR_SCENARIO_VISION, GPIO_SCENARIO_ON, 0, gpio_cam_en, 0, NULL, PIN_OUTPUT_HIGH);
	SET_PIN(pdata, SENSOR_SCENARIO_VISION, GPIO_SCENARIO_ON, 1, gpio_reset, 0, NULL, PIN_OUTPUT_LOW);
	SET_PIN(pdata, SENSOR_SCENARIO_VISION, GPIO_SCENARIO_ON, 2, gpio_standby, 0, NULL, PIN_OUTPUT_HIGH);
	SET_PIN(pdata, SENSOR_SCENARIO_VISION, GPIO_SCENARIO_ON, 3, gpio_none, 0, NULL, PIN_END);

	SET_PIN(pdata, SENSOR_SCENARIO_VISION, GPIO_SCENARIO_OFF, 0, gpio_reset, 0, NULL, PIN_RESET);
	SET_PIN(pdata, SENSOR_SCENARIO_VISION, GPIO_SCENARIO_OFF, 1, gpio_reset, 0, NULL, PIN_INPUT);
	SET_PIN(pdata, SENSOR_SCENARIO_VISION, GPIO_SCENARIO_OFF, 2, gpio_standby, 0, NULL, PIN_OUTPUT_LOW);
	SET_PIN(pdata, SENSOR_SCENARIO_VISION, GPIO_SCENARIO_OFF, 4, gpio_cam_en, 0, NULL, PIN_OUTPUT_LOW);
	SET_PIN(pdata, SENSOR_SCENARIO_VISION, GPIO_SCENARIO_OFF, 3, gpio_none, 0, NULL, PIN_END);

#else /* TN CODE */

	if (id == SENSOR_POSITION_FRONT) {
		gpio_standby = of_get_named_gpio(dnode, "gpio_standby", 0);
		if (!gpio_is_valid(gpio_standby)) {
			dev_err(dev, "failed to get gpio_standby\n");
		} else {
			gpio_request_one(gpio_standby, GPIOF_OUT_INIT_LOW, "CAM_GPIO_OUTPUT_LOW");
			gpio_free(gpio_standby);
		}
#ifdef CONFIG_SOC_EXYNOS5433
		/* initial - i2c off */
		pinctrl_ch = devm_pinctrl_get_select(&pdev->dev, "off1");
		if (IS_ERR_OR_NULL(pinctrl_ch)) {
			pr_err("%s: cam %s pins are not configured\n", __func__, "off1");
		} else {
			devm_pinctrl_put(pinctrl_ch);
		}
#endif
	}
#ifdef CONFIG_SOC_EXYNOS5422
	if (id == SENSOR_POSITION_REAR) {
		/* BACK CAMERA	- POWER ON */
		SET_PIN(pdata, SENSOR_SCENARIO_NORMAL, GPIO_SCENARIO_ON, 0, gpio_none, 0, NULL, 0, PIN_END);

		/* BACK CAMERA	- POWER OFF */
		SET_PIN(pdata, SENSOR_SCENARIO_NORMAL, GPIO_SCENARIO_OFF, 0, gpio_none, 0, NULL, 0, PIN_END);
	} else {
		/* FRONT CAMERA  - POWER ON */
		SET_PIN(pdata, SENSOR_SCENARIO_NORMAL, GPIO_SCENARIO_ON, 0, gpio_standby, 0, NULL, 0, PIN_OUTPUT_LOW);
		SET_PIN(pdata, SENSOR_SCENARIO_NORMAL, GPIO_SCENARIO_ON, 1, gpio_none, 0, "VT_CAM_1.8V", 0, PIN_REGULATOR_ON);
		SET_PIN(pdata, SENSOR_SCENARIO_NORMAL, GPIO_SCENARIO_ON, 2, gpio_none, 0, "VT_CAM_2.8V", 0, PIN_REGULATOR_ON);
		SET_PIN(pdata, SENSOR_SCENARIO_NORMAL, GPIO_SCENARIO_ON, 3, gpios_cam_en, 0, NULL, 1000, PIN_OUTPUT_HIGH);
		SET_PIN(pdata, SENSOR_SCENARIO_NORMAL, GPIO_SCENARIO_ON, 4, gpio_reset, 0, NULL, 0, PIN_OUTPUT_HIGH);
		SET_PIN(pdata, SENSOR_SCENARIO_NORMAL, GPIO_SCENARIO_ON, 5, gpio_none, 0, "ch", 0, PIN_FUNCTION);
		SET_PIN(pdata, SENSOR_SCENARIO_NORMAL, GPIO_SCENARIO_ON, 6, gpio_none, 0, NULL, 0, PIN_END);

		/* FRONT CAMERA  - POWER OFF */
		SET_PIN(pdata, SENSOR_SCENARIO_NORMAL, GPIO_SCENARIO_OFF, 0, gpio_standby, 0, NULL, 0, PIN_OUTPUT_LOW);
		SET_PIN(pdata, SENSOR_SCENARIO_NORMAL, GPIO_SCENARIO_OFF, 1, gpio_none, 0, "off", 0, PIN_FUNCTION);
		SET_PIN(pdata, SENSOR_SCENARIO_NORMAL, GPIO_SCENARIO_OFF, 2, gpio_reset, 0, NULL, 0, PIN_OUTPUT_LOW);
		SET_PIN(pdata, SENSOR_SCENARIO_NORMAL, GPIO_SCENARIO_OFF, 3, gpios_cam_en, 0, NULL, 0, PIN_OUTPUT_LOW);
		SET_PIN(pdata, SENSOR_SCENARIO_NORMAL, GPIO_SCENARIO_OFF, 4, gpio_none, 0, "VT_CAM_2.8V", 0, PIN_REGULATOR_OFF);
		SET_PIN(pdata, SENSOR_SCENARIO_NORMAL, GPIO_SCENARIO_OFF, 5, gpio_none, 0, "VT_CAM_1.8V", 0, PIN_REGULATOR_OFF);
		SET_PIN(pdata, SENSOR_SCENARIO_NORMAL, GPIO_SCENARIO_OFF, 6, gpio_none, 0, NULL, 0, PIN_END);

		/* VISION CAMERA  - POWER ON */
		SET_PIN(pdata, SENSOR_SCENARIO_VISION, GPIO_SCENARIO_ON, 0, gpio_reset, 0, NULL, 0, PIN_OUTPUT_LOW);
		SET_PIN(pdata, SENSOR_SCENARIO_VISION, GPIO_SCENARIO_ON, 1, gpio_none, 0, "VT_CAM_1.8V", 0, PIN_REGULATOR_ON);
		SET_PIN(pdata, SENSOR_SCENARIO_VISION, GPIO_SCENARIO_ON, 2, gpio_none, 0, "VT_CAM_2.8V", 0, PIN_REGULATOR_ON);
		SET_PIN(pdata, SENSOR_SCENARIO_VISION, GPIO_SCENARIO_ON, 3, gpios_cam_en, 0, NULL, 1000, PIN_OUTPUT_HIGH);
		SET_PIN(pdata, SENSOR_SCENARIO_VISION, GPIO_SCENARIO_ON, 4, gpio_standby, 0, NULL, 0, PIN_OUTPUT_HIGH);
		SET_PIN(pdata, SENSOR_SCENARIO_VISION, GPIO_SCENARIO_ON, 5, gpio_none, 0, "ch", 0, PIN_FUNCTION);
		SET_PIN(pdata, SENSOR_SCENARIO_VISION, GPIO_SCENARIO_ON, 6, gpio_none, 0, NULL, 0, PIN_END);

		/* VISION CAMERA  - POWER OFF */
		SET_PIN(pdata, SENSOR_SCENARIO_VISION, GPIO_SCENARIO_OFF, 0, gpio_reset, 0, NULL, 0, PIN_OUTPUT_LOW);
		SET_PIN(pdata, SENSOR_SCENARIO_VISION, GPIO_SCENARIO_OFF, 1, gpio_none, 0, "off", 0, PIN_FUNCTION);
		SET_PIN(pdata, SENSOR_SCENARIO_VISION, GPIO_SCENARIO_OFF, 2, gpio_standby, 0, NULL, 0, PIN_OUTPUT_LOW);
		SET_PIN(pdata, SENSOR_SCENARIO_VISION, GPIO_SCENARIO_OFF, 3, gpios_cam_en, 0, NULL, 0, PIN_OUTPUT_LOW);
		SET_PIN(pdata, SENSOR_SCENARIO_VISION, GPIO_SCENARIO_OFF, 4, gpio_none, 0, "VT_CAM_2.8V", 0, PIN_REGULATOR_OFF);
		SET_PIN(pdata, SENSOR_SCENARIO_VISION, GPIO_SCENARIO_OFF, 5, gpio_none, 0, "VT_CAM_1.8V", 0, PIN_REGULATOR_OFF);
		SET_PIN(pdata, SENSOR_SCENARIO_VISION, GPIO_SCENARIO_OFF, 6, gpio_none, 0, NULL, 0, PIN_END);
	}
#else /*CONFIG_SOC_EXYNOS5430*/
	if (id == SENSOR_POSITION_REAR) {
		/* BACK CAMERA  - POWER ON */
		SET_PIN(pdata, SENSOR_SCENARIO_NORMAL, GPIO_SCENARIO_ON, 0, gpio_none, 0, NULL, 0, PIN_END);

		/* BACK CAMERA  - POWER OFF */
		SET_PIN(pdata, SENSOR_SCENARIO_NORMAL, GPIO_SCENARIO_OFF, 0, gpio_none, 0, NULL, 0, PIN_END);
	} else {
		/* FRONT CAMERA  - POWER ON */
		SET_PIN(pdata, SENSOR_SCENARIO_NORMAL, GPIO_SCENARIO_ON, 0, gpio_standby, 0, NULL, 0, PIN_OUTPUT_LOW);
		SET_PIN(pdata, SENSOR_SCENARIO_NORMAL, GPIO_SCENARIO_ON, 1, gpio_none, 0, "VT_CAM_1.8V", 0, PIN_REGULATOR_ON);
		SET_PIN(pdata, SENSOR_SCENARIO_NORMAL, GPIO_SCENARIO_ON, 2, gpio_none, 0, "VT_CAM_2.8V", 0, PIN_REGULATOR_ON);
		SET_PIN(pdata, SENSOR_SCENARIO_NORMAL, GPIO_SCENARIO_ON, 3, gpio_none, 0, "VT_CAM_1.2V", 1000, PIN_REGULATOR_ON);
		SET_PIN(pdata, SENSOR_SCENARIO_NORMAL, GPIO_SCENARIO_ON, 4, gpio_reset, 0, NULL, 0, PIN_OUTPUT_HIGH);
		SET_PIN(pdata, SENSOR_SCENARIO_NORMAL, GPIO_SCENARIO_ON, 5, gpio_none, 0, "ch", 0, PIN_FUNCTION);
		SET_PIN(pdata, SENSOR_SCENARIO_NORMAL, GPIO_SCENARIO_ON, 6, gpio_none, 0, NULL, 0, PIN_END);

		/* FRONT CAMERA  - POWER OFF */
		SET_PIN(pdata, SENSOR_SCENARIO_NORMAL, GPIO_SCENARIO_OFF, 0, gpio_standby, 0, NULL, 0, PIN_OUTPUT_LOW);
		SET_PIN(pdata, SENSOR_SCENARIO_NORMAL, GPIO_SCENARIO_OFF, 1, gpio_none, 0, "off", 0, PIN_FUNCTION);
		SET_PIN(pdata, SENSOR_SCENARIO_NORMAL, GPIO_SCENARIO_OFF, 2, gpio_reset, 0, NULL, 0, PIN_OUTPUT_LOW);
		SET_PIN(pdata, SENSOR_SCENARIO_NORMAL, GPIO_SCENARIO_OFF, 3, gpio_none, 0, "VT_CAM_1.2V", 0, PIN_REGULATOR_OFF);
		SET_PIN(pdata, SENSOR_SCENARIO_NORMAL, GPIO_SCENARIO_OFF, 4, gpio_none, 0, "VT_CAM_2.8V", 0, PIN_REGULATOR_OFF);
		SET_PIN(pdata, SENSOR_SCENARIO_NORMAL, GPIO_SCENARIO_OFF, 5, gpio_none, 0, "VT_CAM_1.8V", 0, PIN_REGULATOR_OFF);
		SET_PIN(pdata, SENSOR_SCENARIO_NORMAL, GPIO_SCENARIO_OFF, 6, gpio_none, 0, NULL, 0, PIN_END);

		/* VISION CAMERA  - POWER ON */
		SET_PIN(pdata, SENSOR_SCENARIO_VISION, GPIO_SCENARIO_ON, 0, gpio_reset, 0, NULL, 0, PIN_OUTPUT_LOW);
		SET_PIN(pdata, SENSOR_SCENARIO_VISION, GPIO_SCENARIO_ON, 1, gpio_none, 0, "VT_CAM_1.8V", 0, PIN_REGULATOR_ON);
		SET_PIN(pdata, SENSOR_SCENARIO_VISION, GPIO_SCENARIO_ON, 2, gpio_none, 0, "VT_CAM_2.8V", 0, PIN_REGULATOR_ON);
		SET_PIN(pdata, SENSOR_SCENARIO_VISION, GPIO_SCENARIO_ON, 3, gpio_none, 0, "VT_CAM_1.2V", 1000, PIN_REGULATOR_ON);
		SET_PIN(pdata, SENSOR_SCENARIO_VISION, GPIO_SCENARIO_ON, 4, gpio_standby, 0, NULL, 0, PIN_OUTPUT_HIGH);
		SET_PIN(pdata, SENSOR_SCENARIO_VISION, GPIO_SCENARIO_ON, 5, gpio_none, 0, "ch", 0, PIN_FUNCTION);
		SET_PIN(pdata, SENSOR_SCENARIO_VISION, GPIO_SCENARIO_ON, 6, gpio_none, 0, NULL, 0, PIN_END);

		/* VISION CAMERA  - POWER OFF */
		SET_PIN(pdata, SENSOR_SCENARIO_VISION, GPIO_SCENARIO_OFF, 0, gpio_reset, 0, NULL, 0, PIN_OUTPUT_LOW);
		SET_PIN(pdata, SENSOR_SCENARIO_VISION, GPIO_SCENARIO_OFF, 1, gpio_none, 0, "off", 0, PIN_FUNCTION);
		SET_PIN(pdata, SENSOR_SCENARIO_VISION, GPIO_SCENARIO_OFF, 2, gpio_standby, 0, NULL, 0, PIN_OUTPUT_LOW);
		SET_PIN(pdata, SENSOR_SCENARIO_VISION, GPIO_SCENARIO_OFF, 3, gpio_none, 0, "VT_CAM_1.2V", 0, PIN_REGULATOR_OFF);
		SET_PIN(pdata, SENSOR_SCENARIO_VISION, GPIO_SCENARIO_OFF, 4, gpio_none, 0, "VT_CAM_2.8V", 0, PIN_REGULATOR_OFF);
		SET_PIN(pdata, SENSOR_SCENARIO_VISION, GPIO_SCENARIO_OFF, 5, gpio_none, 0, "VT_CAM_1.8V", 0, PIN_REGULATOR_OFF);
		SET_PIN(pdata, SENSOR_SCENARIO_VISION, GPIO_SCENARIO_OFF, 6, gpio_none, 0, NULL, 0, PIN_END);
	}
#endif
#endif
	pdev->id = id;

	dev->platform_data = pdata;

	pdata->pinctrl = devm_pinctrl_get(dev);
	if (IS_ERR(pdata->pinctrl)) {
		err("devm_pinctrl_get is fail");
		goto p_err;
	} else {
		ret = get_pin_lookup_state(dev, pdata);
		if (ret < 0) {
			err("fimc_is_get_pin_lookup_state is fail");
			goto p_err;
		}
	}

	return ret;
p_err:
	kfree(pdata);
	return ret;
}
Esempio n. 20
0
void bf609_nor_flash_exit(struct platform_device *pdev)
{
	devm_pinctrl_put(pdev->dev.pins->p);
	bfin_write32(SMC_GCTL, 0);
}
Esempio n. 21
0
/**
 * pinctrl_bind_pins() - called by the device core before probe
 * @dev: the device that is just about to probe
 */
int pinctrl_bind_pins(struct device *dev)
{
	int ret;

	dev->device_rh->pins = devm_kzalloc(dev, sizeof(*(dev->device_rh->pins)), GFP_KERNEL);
	if (!dev->device_rh->pins)
		return -ENOMEM;

	dev->device_rh->pins->p = devm_pinctrl_get(dev);
	if (IS_ERR(dev->device_rh->pins->p)) {
		dev_dbg(dev, "no pinctrl handle\n");
		ret = PTR_ERR(dev->device_rh->pins->p);
		goto cleanup_alloc;
	}

	dev->device_rh->pins->default_state = pinctrl_lookup_state(dev->device_rh->pins->p,
					PINCTRL_STATE_DEFAULT);
	if (IS_ERR(dev->device_rh->pins->default_state)) {
		dev_dbg(dev, "no default pinctrl state\n");
		ret = 0;
		goto cleanup_get;
	}

	ret = pinctrl_select_state(dev->device_rh->pins->p, dev->device_rh->pins->default_state);
	if (ret) {
		dev_dbg(dev, "failed to activate default pinctrl state\n");
		goto cleanup_get;
	}

#ifdef CONFIG_PM
	/*
	 * If power management is enabled, we also look for the optional
	 * sleep and idle pin states, with semantics as defined in
	 * <linux/pinctrl/pinctrl-state.h>
	 */
	dev->device_rh->pins->sleep_state = pinctrl_lookup_state(dev->device_rh->pins->p,
						PINCTRL_STATE_SLEEP);
	if (IS_ERR(dev->device_rh->pins->sleep_state))
		/* Not supplying this state is perfectly legal */
		dev_dbg(dev, "no sleep pinctrl state\n");

	dev->device_rh->pins->idle_state = pinctrl_lookup_state(dev->device_rh->pins->p,
						PINCTRL_STATE_IDLE);
	if (IS_ERR(dev->device_rh->pins->idle_state))
		/* Not supplying this state is perfectly legal */
		dev_dbg(dev, "no idle pinctrl state\n");
#endif

	return 0;

	/*
	 * If no pinctrl handle or default state was found for this device,
	 * let's explicitly free the pin container in the device, there is
	 * no point in keeping it around.
	 */
cleanup_get:
	devm_pinctrl_put(dev->device_rh->pins->p);
cleanup_alloc:
	devm_kfree(dev, dev->device_rh->pins);
	dev->device_rh->pins = NULL;

	/* Only return deferrals */
	if (ret != -EPROBE_DEFER)
		ret = 0;

	return ret;
}
static int tpiu_parse_of_data(struct platform_device *pdev,
					struct tpiu_drvdata *drvdata)
{
	struct device_node *node = pdev->dev.of_node;
	struct device_node *reg_node = NULL;
	struct device *dev = &pdev->dev;
	const __be32 *prop;
	int i, len, gpio, ret;
	uint32_t *seta_cfgs, *setb_cfgs;
	struct pinctrl *pctrl;

	reg_node = of_parse_phandle(node, "vdd-supply", 0);
	if (reg_node) {
		drvdata->reg = devm_regulator_get(dev, "vdd");
		if (IS_ERR(drvdata->reg))
			return PTR_ERR(drvdata->reg);

		prop = of_get_property(node, "qcom,vdd-voltage-level", &len);
		if (!prop || (len != (2 * sizeof(__be32)))) {
			dev_err(dev, "sdc voltage levels not specified\n");
		} else {
			drvdata->reg_low = be32_to_cpup(&prop[0]);
			drvdata->reg_high = be32_to_cpup(&prop[1]);
		}

		prop = of_get_property(node, "qcom,vdd-current-level", &len);
		if (!prop || (len != (2 * sizeof(__be32)))) {
			dev_err(dev, "sdc current levels not specified\n");
		} else {
			drvdata->reg_lpm = be32_to_cpup(&prop[0]);
			drvdata->reg_hpm = be32_to_cpup(&prop[1]);
		}
		of_node_put(reg_node);
	} else {
		dev_err(dev, "sdc voltage supply not specified or available\n");
	}

	reg_node = of_parse_phandle(node, "vdd-io-supply", 0);
	if (reg_node) {
		drvdata->reg_io = devm_regulator_get(dev, "vdd-io");
		if (IS_ERR(drvdata->reg_io))
			return PTR_ERR(drvdata->reg_io);

		prop = of_get_property(node, "qcom,vdd-io-voltage-level", &len);
		if (!prop || (len != (2 * sizeof(__be32)))) {
			dev_err(dev, "sdc io voltage levels not specified\n");
		} else {
			drvdata->reg_low_io = be32_to_cpup(&prop[0]);
			drvdata->reg_high_io = be32_to_cpup(&prop[1]);
		}

		prop = of_get_property(node, "qcom,vdd-io-current-level", &len);
		if (!prop || (len != (2 * sizeof(__be32)))) {
			dev_err(dev, "sdc io current levels not specified\n");
		} else {
			drvdata->reg_lpm_io = be32_to_cpup(&prop[0]);
			drvdata->reg_hpm_io = be32_to_cpup(&prop[1]);
		}
		of_node_put(reg_node);
	} else {
		dev_err(dev,
			"sdc io voltage supply not specified or available\n");
	}

	drvdata->out_mode = TPIU_OUT_MODE_MICTOR;
	drvdata->set = TPIU_SET_B;

	pctrl = devm_pinctrl_get(dev);
	if (!IS_ERR(pctrl)) {
		drvdata->tpiu_pctrl = devm_kzalloc(dev,
						   sizeof(struct tpiu_pinctrl),
						   GFP_KERNEL);
		if (!drvdata->tpiu_pctrl)
			return -ENOMEM;
		devm_pinctrl_put(pctrl);
		goto out;
	}

	dev_err(dev, "Pinctrl failed, falling back to GPIO lib\n");

	drvdata->seta_gpiocnt = of_gpio_named_count(node, "qcom,seta-gpios");
	if (drvdata->seta_gpiocnt > 0) {
		drvdata->seta_gpios = devm_kzalloc(dev,
				sizeof(*drvdata->seta_gpios) *
				drvdata->seta_gpiocnt, GFP_KERNEL);
		if (!drvdata->seta_gpios)
			return -ENOMEM;

		for (i = 0; i < drvdata->seta_gpiocnt; i++) {
			gpio = of_get_named_gpio(node, "qcom,seta-gpios", i);
			if (!gpio_is_valid(gpio))
				return gpio;

			drvdata->seta_gpios[i] = gpio;
		}

		drvdata->seta_cfgs = devm_kzalloc(dev,
				sizeof(*drvdata->seta_cfgs) *
				drvdata->seta_gpiocnt, GFP_KERNEL);
		if (!drvdata->seta_cfgs)
			return -ENOMEM;

		seta_cfgs = devm_kzalloc(dev, sizeof(*seta_cfgs) *
					 drvdata->seta_gpiocnt, GFP_KERNEL);
		if (!seta_cfgs)
			return -ENOMEM;

		ret = of_property_read_u32_array(node, "qcom,seta-gpios-func",
						 (u32 *)seta_cfgs,
						 drvdata->seta_gpiocnt);
		if (ret)
			return ret;

		for (i = 0; i < drvdata->seta_gpiocnt; i++)
			drvdata->seta_cfgs[i].func = seta_cfgs[i];

		ret = of_property_read_u32_array(node, "qcom,seta-gpios-drv",
						 (u32 *)seta_cfgs,
						 drvdata->seta_gpiocnt);
		if (ret)
			return ret;

		for (i = 0; i < drvdata->seta_gpiocnt; i++)
			drvdata->seta_cfgs[i].drv = seta_cfgs[i];

		ret = of_property_read_u32_array(node, "qcom,seta-gpios-pull",
						 (u32 *)seta_cfgs,
						 drvdata->seta_gpiocnt);
		if (ret)
			return ret;

		for (i = 0; i < drvdata->seta_gpiocnt; i++)
			drvdata->seta_cfgs[i].pull = seta_cfgs[i];

		ret = of_property_read_u32_array(node, "qcom,seta-gpios-dir",
						 (u32 *)seta_cfgs,
						 drvdata->seta_gpiocnt);
		if (ret)
			return ret;

		for (i = 0; i < drvdata->seta_gpiocnt; i++)
			drvdata->seta_cfgs[i].dir = seta_cfgs[i];

		devm_kfree(dev, seta_cfgs);
	} else {
		dev_err(dev, "seta gpios not specified\n");
	}

	drvdata->setb_gpiocnt = of_gpio_named_count(node, "qcom,setb-gpios");
	if (drvdata->setb_gpiocnt > 0) {
		drvdata->setb_gpios = devm_kzalloc(dev,
				sizeof(*drvdata->setb_gpios) *
				drvdata->setb_gpiocnt, GFP_KERNEL);
		if (!drvdata->setb_gpios)
			return -ENOMEM;

		for (i = 0; i < drvdata->setb_gpiocnt; i++) {
			gpio = of_get_named_gpio(node, "qcom,setb-gpios", i);
			if (!gpio_is_valid(gpio))
				return gpio;

			drvdata->setb_gpios[i] = gpio;
		}

		drvdata->setb_cfgs = devm_kzalloc(dev,
				sizeof(*drvdata->setb_cfgs) *
				drvdata->setb_gpiocnt, GFP_KERNEL);
		if (!drvdata->setb_cfgs)
			return -ENOMEM;

		setb_cfgs = devm_kzalloc(dev, sizeof(*setb_cfgs) *
					 drvdata->setb_gpiocnt, GFP_KERNEL);
		if (!setb_cfgs)
			return -ENOMEM;

		ret = of_property_read_u32_array(node, "qcom,setb-gpios-func",
						 (u32 *)setb_cfgs,
						 drvdata->setb_gpiocnt);
		if (ret)
			return ret;

		for (i = 0; i < drvdata->setb_gpiocnt; i++)
			drvdata->setb_cfgs[i].func = setb_cfgs[i];

		ret = of_property_read_u32_array(node, "qcom,setb-gpios-drv",
						 (u32 *)setb_cfgs,
						 drvdata->setb_gpiocnt);
		if (ret)
			return ret;

		for (i = 0; i < drvdata->setb_gpiocnt; i++)
			drvdata->setb_cfgs[i].drv = setb_cfgs[i];

		ret = of_property_read_u32_array(node, "qcom,setb-gpios-pull",
						 (u32 *)setb_cfgs,
						 drvdata->setb_gpiocnt);
		if (ret)
			return ret;

		for (i = 0; i < drvdata->setb_gpiocnt; i++)
			drvdata->setb_cfgs[i].pull = setb_cfgs[i];

		ret = of_property_read_u32_array(node, "qcom,setb-gpios-dir",
						 (u32 *)setb_cfgs,
						 drvdata->setb_gpiocnt);
		if (ret)
			return ret;

		for (i = 0; i < drvdata->setb_gpiocnt; i++)
			drvdata->setb_cfgs[i].dir = setb_cfgs[i];

		devm_kfree(dev, setb_cfgs);
	} else {
		dev_err(dev, "setb gpios not specified\n");
	}
out:
	drvdata->nidnt = of_property_read_bool(pdev->dev.of_node,
					       "qcom,nidnt");
	return 0;
}
static int __tpiu_enable_setb(struct tpiu_drvdata *drvdata)
{
	int i, ret;
	struct pinctrl *pctrl;
	struct pinctrl_state *setb_pctrl;

	if (drvdata->tpiu_pctrl) {
		pctrl = devm_pinctrl_get(drvdata->dev);
		if (IS_ERR(pctrl)) {
			ret = PTR_ERR(pctrl);
			goto err0;
		}

		setb_pctrl = pinctrl_lookup_state(pctrl, "setb-pctrl");
		if (IS_ERR(setb_pctrl)) {
			dev_err(drvdata->dev,
				"pinctrl get state failed for setb\n");
			ret = PTR_ERR(setb_pctrl);
			goto err0;
		}

		ret = pinctrl_select_state(pctrl, setb_pctrl);
		if (ret) {
			dev_err(drvdata->dev,
				"pinctrl enable state failed for setb\n");
			goto err0;
		}

		drvdata->tpiu_pctrl->pctrl = pctrl;
		drvdata->tpiu_pctrl->setb_pctrl = setb_pctrl;
		return 0;
	}

	if (!drvdata->setb_gpiocnt)
		return -EINVAL;

	for (i = 0; i < drvdata->setb_gpiocnt; i++) {
		ret = gpio_request(drvdata->setb_gpios[i], NULL);
		if (ret) {
			dev_err(drvdata->dev,
				"gpio_request failed for setb_gpio: %u\n",
				drvdata->setb_gpios[i]);
			goto err1;
		}
		ret = msm_gpiomux_write(drvdata->setb_gpios[i],
					GPIOMUX_ACTIVE,
					&drvdata->setb_cfgs[i],
					&old_cfg);
		if (ret < 0) {
			dev_err(drvdata->dev,
				"gpio write failed for setb_gpio: %u\n",
				drvdata->setb_gpios[i]);
			goto err2;
		}
	}
	return 0;
err2:
	gpio_free(drvdata->setb_gpios[i]);
err1:
	i--;
	while (i >= 0) {
		gpio_free(drvdata->setb_gpios[i]);
		i--;
	}
	return ret;
err0:
	devm_pinctrl_put(pctrl);
	return ret;
}
Esempio n. 24
0
static int k3v3_gpio_key_probe(struct platform_device* pdev)
{
	struct k3v3_gpio_key *gpio_key = NULL;
	struct input_dev *input_dev = NULL;
	int err =0;

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

	dev_info(&pdev->dev, "k3v3 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 k3v3_gpio_key), GFP_KERNEL);
	if (!gpio_key) {
		dev_err(&pdev->dev, "Failed to allocate struct k3v3_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);
	input_dev->open = k3v3_gpio_key_open;
	input_dev->close = k3v3_gpio_key_close;

	gpio_key->input_dev = input_dev;

	/*initial work before we use it.*/
	INIT_DELAYED_WORK(&(gpio_key->gpio_keyup_work), k3v3_gpio_keyup_work);
	INIT_DELAYED_WORK(&(gpio_key->gpio_keydown_work), k3v3_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");

	gpio_key->gpio_up = of_get_named_gpio(pdev->dev.of_node, "gpio-keyup,gpio-irq", 0);
	if (!gpio_is_valid(gpio_key->gpio_up)) {
		dev_err(&pdev->dev, "gpio keyup is not valid!\n");
		err = -EINVAL;
		goto err_get_gpio;
	}
	gpio_key->gpio_down = of_get_named_gpio(pdev->dev.of_node, "gpio-keydown,gpio-irq", 0);
	if (!gpio_is_valid(gpio_key->gpio_down)) {
		dev_err(&pdev->dev, "gpio keydown is not valid!\n");
		err = -EINVAL;
		goto err_get_gpio;
	}
	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;
	}
	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_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;
	}

	gpio_direction_input(gpio_key->gpio_up);
	gpio_direction_input(gpio_key->gpio_down);

	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;
	}

	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;
	}

	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);
	/*
	 * support failing irq that means volume-up-key is pressed,
	 * and rising irq which means volume-up-key is released.
	 */
	err = request_irq(gpio_key->volume_up_irq, k3v3_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.
	 */
	err = request_irq(gpio_key->volume_down_irq, k3v3_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;
	}

	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);

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

err_register_dev:
	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_gpio_to_irq:
err_pinctrl_put:
	devm_pinctrl_put(gpio_key->pctrl);
err_pinctrl:
	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);
	pr_info(KERN_ERR "[gpiokey]K3v3 gpio key probe failed! ret = %d.\n", err);
	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
#ifdef CONFIG_HISI_GPIO_KEY_SUPPORT_SMART_KEY
	set_bit(KEY_F24, 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
#ifdef CONFIG_HISI_GPIO_KEY_SUPPORT_SMART_KEY
	INIT_DELAYED_WORK(&(gpio_key->gpio_keysmart_work), hisi_gpio_keysmart_work);
	wake_lock_init(&smart_key_lock, WAKE_LOCK_SUSPEND, "key_smart_wake_lock");
#endif

	gpio_key->gpio_up = of_get_key_gpio(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_key_gpio(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_key_gpio(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
#ifdef CONFIG_HISI_GPIO_KEY_SUPPORT_SMART_KEY
	gpio_key->gpio_smart = of_get_key_gpio(pdev->dev.of_node, "gpio-keysmart,gpio-irq", 0, 0, &flags);
	if (!gpio_is_valid(gpio_key->gpio_smart)) {
		printk(KERN_INFO "%s: gpio of smart 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((unsigned int)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((unsigned int)gpio_key->gpio_up);

		gpio_key->volume_up_irq = gpio_to_irq((unsigned int)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((unsigned int)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((unsigned int)gpio_key->gpio_down);

		gpio_key->volume_down_irq = gpio_to_irq((unsigned int)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((unsigned int)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((unsigned int)gpio_key->gpio_back);

		gpio_key->key_back_irq = gpio_to_irq((unsigned int)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
#ifdef CONFIG_HISI_GPIO_KEY_SUPPORT_SMART_KEY
	if (gpio_is_valid(gpio_key->gpio_smart)) {
		err = gpio_request((unsigned int)gpio_key->gpio_smart, "gpio_smart");
		if (err) {
			dev_err(&pdev->dev, "Fail request gpio:%d\n", gpio_key->gpio_smart);
			goto err_gpio_smart_req;
		}

		gpio_direction_input((unsigned int)gpio_key->gpio_smart);

		gpio_key->key_smart_irq = gpio_to_irq((unsigned int)gpio_key->gpio_smart);
		if (gpio_key->key_smart_irq < 0) {
			dev_err(&pdev->dev, "Failed to get gpio key release irq!\n");
			err = gpio_key->key_smart_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
#ifdef CONFIG_HISI_GPIO_KEY_SUPPORT_SMART_KEY
	setup_timer(&(gpio_key->key_smart_timer), gpio_keysmart_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
#ifdef CONFIG_HISI_GPIO_KEY_SUPPORT_SMART_KEY
	if (gpio_is_valid(gpio_key->gpio_smart)) {
		err = request_irq(gpio_key->key_smart_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_smart_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
#ifdef  CONFIG_HISI_GPIO_KEY_SUPPORT_SMART_KEY
	free_irq(gpio_key->key_smart_irq, gpio_key);
err_smart_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((unsigned int)gpio_key->gpio_back);
err_gpio_back_req:
#endif
#ifdef CONFIG_HISI_GPIO_KEY_SUPPORT_SMART_KEY
	gpio_free((unsigned int)gpio_key->gpio_smart);
err_gpio_smart_req:
#endif
	gpio_free((unsigned int)gpio_key->gpio_down);
err_gpio_down_req:
	gpio_free((unsigned int)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
#ifdef CONFIG_HISI_GPIO_KEY_SUPPORT_SMART_KEY
	wake_lock_destroy(&smart_key_lock);
#endif
	pr_info(KERN_ERR "[gpiokey]K3v3 gpio key probe failed! ret = %d.\n", err);
	return err;
}
int msm_camera_power_up(struct msm_camera_power_ctrl_t *ctrl,
	enum msm_camera_device_type_t device_type,
	struct msm_camera_i2c_client *sensor_i2c_client)
{
	int rc = 0, index = 0, no_gpio = 0, ret = 0;
	struct msm_sensor_power_setting *power_setting = NULL;

	CDBG("%s:%d\n", __func__, __LINE__);
	if (!ctrl || !sensor_i2c_client) {
		pr_err("failed ctrl %p sensor_i2c_client %p\n", ctrl,
			sensor_i2c_client);
		return -EINVAL;
	}
	if (ctrl->gpio_conf->cam_gpiomux_conf_tbl != NULL) {
		pr_err("%s:%d mux install\n", __func__, __LINE__);
	}
	ret = msm_camera_pinctrl_init(ctrl);
	if (ret < 0) {
		pr_err("%s:%d Initialization of pinctrl failed\n",
				__func__, __LINE__);
		ctrl->cam_pinctrl_status = 0;
	} else {
		ctrl->cam_pinctrl_status = 1;
	}
	rc = msm_camera_request_gpio_table(
		ctrl->gpio_conf->cam_gpio_req_tbl,
		ctrl->gpio_conf->cam_gpio_req_tbl_size, 1);
	if (rc < 0)
		no_gpio = rc;
	if (ctrl->cam_pinctrl_status) {
		ret = pinctrl_select_state(ctrl->pinctrl_info.pinctrl,
			ctrl->pinctrl_info.gpio_state_active);
		if (ret)
			pr_err("%s:%d cannot set pin to active state",
				__func__, __LINE__);
	}
	for (index = 0; index < ctrl->power_setting_size; index++) {
		CDBG("%s index %d\n", __func__, index);
		power_setting = &ctrl->power_setting[index];
		CDBG("%s type %d\n", __func__, power_setting->seq_type);
		switch (power_setting->seq_type) {
		case SENSOR_CLK:
			if (power_setting->seq_val >= ctrl->clk_info_size) {
				pr_err("%s clk index %d >= max %d\n", __func__,
					power_setting->seq_val,
					ctrl->clk_info_size);
				goto power_up_failed;
			}
			if (power_setting->config_val)
				ctrl->clk_info[power_setting->seq_val].
					clk_rate = power_setting->config_val;

			rc = msm_cam_clk_enable(ctrl->dev,
				&ctrl->clk_info[0],
				(struct clk **)&power_setting->data[0],
				ctrl->clk_info_size,
				1);
			if (rc < 0) {
				pr_err("%s: clk enable failed\n",
					__func__);
				goto power_up_failed;
			}
			break;
		case SENSOR_GPIO:
			if (no_gpio) {
				pr_err("%s: request gpio failed\n", __func__);

				//LGE_CHANGE_S, goto 'power up fail routine' before return error, [email protected]
			#if defined (CONFIG_MACH_MSM8916_C70W_KR)
				rc = no_gpio;
				goto power_up_failed;
			#else
				return no_gpio;
			#endif
				//LGE_CHANGE_E, goto 'power up fail routine' before return error, [email protected]
			}
			if (power_setting->seq_val >= SENSOR_GPIO_MAX ||
				!ctrl->gpio_conf->gpio_num_info) {
				pr_err("%s gpio index %d >= max %d\n", __func__,
					power_setting->seq_val,
					SENSOR_GPIO_MAX);
				goto power_up_failed;
			}
			if (!ctrl->gpio_conf->gpio_num_info->valid
				[power_setting->seq_val])
				continue;
			CDBG("%s:%d gpio set val %d\n", __func__, __LINE__,
				ctrl->gpio_conf->gpio_num_info->gpio_num
				[power_setting->seq_val]);
			gpio_set_value_cansleep(
				ctrl->gpio_conf->gpio_num_info->gpio_num
				[power_setting->seq_val],
				(int) power_setting->config_val);
			break;
		case SENSOR_VREG:
			if (power_setting->seq_val >= CAM_VREG_MAX) {
				pr_err("%s vreg index %d >= max %d\n", __func__,
					power_setting->seq_val,
					SENSOR_GPIO_MAX);
				goto power_up_failed;
			}
			if (power_setting->seq_val < ctrl->num_vreg)
				msm_camera_config_single_vreg(ctrl->dev,
				&ctrl->cam_vreg[power_setting->seq_val],
				(struct regulator **)&power_setting->data[0],
				1);
			else
				pr_err("ERR:%s: %d usr_idx:%d dts_idx:%d\n",
					__func__, __LINE__,
					power_setting->seq_val, ctrl->num_vreg);
			break;
		case SENSOR_I2C_MUX:
			if (ctrl->i2c_conf && ctrl->i2c_conf->use_i2c_mux)
				msm_camera_enable_i2c_mux(ctrl->i2c_conf);
			break;
		default:
			pr_err("%s error power seq type %d\n", __func__,
				power_setting->seq_type);
			break;
		}
		if (power_setting->delay > 20) {
			msleep(power_setting->delay);
		} else if (power_setting->delay) {
			usleep_range(power_setting->delay * 1000,
				(power_setting->delay * 1000) + 1000);
		}
	}

	if (device_type == MSM_CAMERA_PLATFORM_DEVICE) {
		rc = sensor_i2c_client->i2c_func_tbl->i2c_util(
			sensor_i2c_client, MSM_CCI_INIT);
		if (rc < 0) {
			pr_err("%s cci_init failed\n", __func__);
			goto power_up_failed;
		}
	}

	CDBG("%s exit\n", __func__);
	return 0;
power_up_failed:
	pr_err("%s:%d failed\n", __func__, __LINE__);
	for (index--; index >= 0; index--) {
		CDBG("%s index %d\n", __func__, index);
		power_setting = &ctrl->power_setting[index];
		CDBG("%s type %d\n", __func__, power_setting->seq_type);
		switch (power_setting->seq_type) {

		case SENSOR_CLK:
			msm_cam_clk_enable(ctrl->dev,
				&ctrl->clk_info[0],
				(struct clk **)&power_setting->data[0],
				ctrl->clk_info_size,
				0);
			break;
		case SENSOR_GPIO:
			if (!ctrl->gpio_conf->gpio_num_info)
				continue;
			if (!ctrl->gpio_conf->gpio_num_info->valid
				[power_setting->seq_val])
				continue;
			gpio_set_value_cansleep(
				ctrl->gpio_conf->gpio_num_info->gpio_num
				[power_setting->seq_val], GPIOF_OUT_INIT_LOW);
			break;
		case SENSOR_VREG:
			if (power_setting->seq_val < ctrl->num_vreg)
				msm_camera_config_single_vreg(ctrl->dev,
				&ctrl->cam_vreg[power_setting->seq_val],
				(struct regulator **)&power_setting->data[0],
				0);
			else
				pr_err("%s:%d:seq_val: %d > num_vreg: %d\n",
					__func__, __LINE__,
					power_setting->seq_val, ctrl->num_vreg);
			break;
		case SENSOR_I2C_MUX:
			if (ctrl->i2c_conf && ctrl->i2c_conf->use_i2c_mux)
				msm_camera_disable_i2c_mux(ctrl->i2c_conf);
			break;
		default:
			pr_err("%s error power seq type %d\n", __func__,
				power_setting->seq_type);
			break;
		}
		if (power_setting->delay > 20) {
			msleep(power_setting->delay);
		} else if (power_setting->delay) {
			usleep_range(power_setting->delay * 1000,
				(power_setting->delay * 1000) + 1000);
		}
	}
	if (ctrl->cam_pinctrl_status) {
		ret = pinctrl_select_state(ctrl->pinctrl_info.pinctrl,
				ctrl->pinctrl_info.gpio_state_suspend);
		if (ret)
			pr_err("%s:%d cannot set pin to suspend state\n",
				__func__, __LINE__);
		devm_pinctrl_put(ctrl->pinctrl_info.pinctrl);
	}
	ctrl->cam_pinctrl_status = 0;
	msm_camera_request_gpio_table(
		ctrl->gpio_conf->cam_gpio_req_tbl,
		ctrl->gpio_conf->cam_gpio_req_tbl_size, 0);
	return rc;
}
Esempio n. 27
0
static void keypad_free_platform(void)
{
	if (!IS_ERR_OR_NULL(keypad_pinctrl))
		devm_pinctrl_put(keypad_pinctrl);
}
Esempio n. 28
0
static void sw_uart_release_gpio(struct sw_uart_port *sw_uport)
{
	devm_pinctrl_put(sw_uport->pctrl);
	sw_uport->pctrl = NULL;
}
Esempio n. 29
0
static void scr_release_gpio(void)
{
	if (!IS_ERR_OR_NULL(scr_pinctrl))
		devm_pinctrl_put(scr_pinctrl);
}
int msm_camera_power_down(struct msm_camera_power_ctrl_t *ctrl,
	enum msm_camera_device_type_t device_type,
	struct msm_camera_i2c_client *sensor_i2c_client)
{
	int index = 0, ret = 0;
	struct msm_sensor_power_setting *pd = NULL;
	struct msm_sensor_power_setting *ps;

	CDBG("%s:%d\n", __func__, __LINE__);
	if (!ctrl || !sensor_i2c_client) {
		pr_err("failed ctrl %p sensor_i2c_client %p\n", ctrl,
			sensor_i2c_client);
		return -EINVAL;
	}
	if (device_type == MSM_CAMERA_PLATFORM_DEVICE)
		sensor_i2c_client->i2c_func_tbl->i2c_util(
			sensor_i2c_client, MSM_CCI_RELEASE);

	for (index = 0; index < ctrl->power_down_setting_size; index++) {
		CDBG("%s index %d\n", __func__, index);
		pd = &ctrl->power_down_setting[index];
		ps = NULL;
		CDBG("%s type %d\n", __func__, pd->seq_type);
		switch (pd->seq_type) {
		case SENSOR_CLK:

			ps = msm_camera_get_power_settings(ctrl,
						pd->seq_type,
						pd->seq_val);
			if (ps)
				msm_cam_clk_enable(ctrl->dev,
					&ctrl->clk_info[0],
					(struct clk **)&ps->data[0],
					ctrl->clk_info_size,
					0);
			else
				pr_err("%s error in power up/down seq data\n",
								__func__);
				break;
		case SENSOR_GPIO:
			if (pd->seq_val >= SENSOR_GPIO_MAX ||
				!ctrl->gpio_conf->gpio_num_info) {
				pr_err("%s gpio index %d >= max %d\n", __func__,
					pd->seq_val,
					SENSOR_GPIO_MAX);
				continue;
			}
			if (!ctrl->gpio_conf->gpio_num_info->valid
				[pd->seq_val])
				continue;
			gpio_set_value_cansleep(
				ctrl->gpio_conf->gpio_num_info->gpio_num
				[pd->seq_val],
				0); //pd->config_val); //LGE_CHANGE, 2014-06-05, temp fix for power down, jongkwon.chae
			break;
		case SENSOR_VREG:
			if (pd->seq_val >= CAM_VREG_MAX) {
				pr_err("%s vreg index %d >= max %d\n", __func__,
					pd->seq_val,
					SENSOR_GPIO_MAX);
				continue;
			}

			ps = msm_camera_get_power_settings(ctrl,
						pd->seq_type,
						pd->seq_val);
			if (ps) {
				if (pd->seq_val < ctrl->num_vreg)
					msm_camera_config_single_vreg(ctrl->dev,
					&ctrl->cam_vreg[pd->seq_val],
					(struct regulator **)&ps->data[0],
					0);
				else
					pr_err("%s:%d:seq_val:%d > num_vreg: %d\n"
						, __func__, __LINE__,
						pd->seq_val, ctrl->num_vreg);
			} else
				pr_err("%s error in power up/down seq data\n",
								__func__);
			break;
		case SENSOR_I2C_MUX:
			if (ctrl->i2c_conf && ctrl->i2c_conf->use_i2c_mux)
				msm_camera_disable_i2c_mux(ctrl->i2c_conf);
			break;
		default:
			pr_err("%s error power seq type %d\n", __func__,
				pd->seq_type);
			break;
		}
		if (pd->delay > 20) {
			msleep(pd->delay);
		} else if (pd->delay) {
			usleep_range(pd->delay * 1000,
				(pd->delay * 1000) + 1000);
		}
	}
	if (ctrl->cam_pinctrl_status) {
		ret = pinctrl_select_state(ctrl->pinctrl_info.pinctrl,
				ctrl->pinctrl_info.gpio_state_suspend);
		if (ret)
			pr_err("%s:%d cannot set pin to suspend state",
				__func__, __LINE__);
		devm_pinctrl_put(ctrl->pinctrl_info.pinctrl);
	}
	ctrl->cam_pinctrl_status = 0;
	msm_camera_request_gpio_table(
		ctrl->gpio_conf->cam_gpio_req_tbl,
		ctrl->gpio_conf->cam_gpio_req_tbl_size, 0);
	CDBG("%s exit\n", __func__);
	return 0;
}