Exemplo n.º 1
0
int tegra_camera_power_off(struct tegra_camera *camera)
{
	int ret = 0;

	dev_dbg(camera->dev, "%s++\n", __func__);

#ifndef CONFIG_ARCH_TEGRA_2x_SOC
	/* Powergate VE */
	ret = tegra_powergate_partition(TEGRA_POWERGATE_VENC);
	if (ret)
		dev_err(camera->dev,
			"%s: VENC powergate failed.\n",
			__func__);

#ifndef CONFIG_ARCH_TEGRA_3x_SOC
	ret = tegra_powergate_partition(TEGRA_POWERGATE_DISA);
	if (ret)
		dev_err(camera->dev,
			"%s: DIS powergate failed.\n",
			__func__);
#endif
#endif
	/* Disable external power */
	if (camera->reg) {
		ret = regulator_disable(camera->reg);
		if (ret) {
			dev_err(camera->dev,
				"%s: disable csi regulator failed.\n",
				__func__);
			return ret;
		}
	}
	camera->power_on = 0;
	return ret;
}
Exemplo n.º 2
0
static void powergate(struct nvhost_module *mod)
{
	if (mod->desc->can_powergate) {
		if (mod->desc->powergate_ids[0] != -1)
			tegra_powergate_partition(mod->desc->powergate_ids[0]);

		if (mod->desc->powergate_ids[1] != -1)
			tegra_powergate_partition(mod->desc->powergate_ids[1]);
	}
}
Exemplo n.º 3
0
static int tegra_camera_power_off(struct tegra_camera_dev *dev)
{
	int ret = 0;

	dev_dbg(dev->dev, "%s++\n", __func__);

#ifndef CONFIG_ARCH_TEGRA_2x_SOC
	/* Powergate VE */
	ret = tegra_powergate_partition(TEGRA_POWERGATE_VENC);
	if (ret)
		dev_err(dev->dev,
			"%s: powergate failed.\n",
			__func__);
#endif
	/* Disable external power */
	if (dev->reg) {
		ret = regulator_disable(dev->reg);
		if (ret) {
			dev_err(dev->dev,
				"%s: disable csi regulator failed.\n",
				__func__);
			return ret;
		}
	}
	dev->power_on = 0;
	tegra_camera_on = dev->power_on;
	return ret;
}
Exemplo n.º 4
0
static int tegra_camera_release(struct inode *inode, struct file *file)
{
	int i, err;
	struct tegra_camera_dev *dev = file->private_data;

	dev_info(dev->dev, "%s\n", __func__);
	for (i = 0; i < ARRAY_SIZE(tegra_camera_block); i++)
		if (tegra_camera_block[i].is_enabled) {
			tegra_camera_block[i].disable(dev);
			tegra_camera_block[i].is_enabled = false;
		}

	/* If camera blocks are not powergated yet, do it now */
	if (dev->power_refcnt > 0) {
		mutex_lock(&dev->tegra_camera_lock);
#ifndef CONFIG_ARCH_TEGRA_2x_SOC
		err = tegra_powergate_partition(TEGRA_POWERGATE_VENC);
		if (err)
			dev_err(dev->dev, "%s: powergate failed.\n", __func__);
#endif
		dev->power_refcnt = 0;
		mutex_unlock(&dev->tegra_camera_lock);
	}

	tegra_camera_disable_emc(dev);

	return 0;
}
int tegraxx_powergate_partition_with_clk_off(int id,
        struct powergate_partition_info *pg_info)
{
    int ret = 0;

    /* Disable clks for the partition */
    partition_clk_disable(pg_info);

    ret = is_partition_clk_disabled(pg_info);
    if (ret)
        goto err_powergate_clk;

    ret = tegra_powergate_partition(id);
    if (ret)
        goto err_powergating;

    return ret;

err_powergate_clk:
    WARN(1, "Could not Powergate Partition %d, all clks not disabled", id);
err_powergating:
    ret = partition_clk_enable(pg_info);
    if (ret)
        return ret;
    WARN(1, "Could not Powergate Partition %d", id);
    return ret;
}
Exemplo n.º 6
0
static int tegra_camera_power_off(struct tegra_camera_dev *dev)
{
	int ret = 0;

	if (--dev->power_refcnt == 0) {
#ifndef CONFIG_ARCH_TEGRA_2x_SOC
		/* Powergate VE */
		ret = tegra_powergate_partition(TEGRA_POWERGATE_VENC);
		if (ret)
			dev_err(dev->dev,
				"%s: powergate failed.\n",
				__func__);
#endif
#if !defined(CONFIG_MACH_PICASSO_E)
		/* Disable external power */
		if (dev->reg) {
			ret = regulator_disable(dev->reg);
			if (ret) {
				dev_err(dev->dev,
					"%s: disable csi regulator failed.\n",
					__func__);
				return ret;
			}
		}
#endif
	}
	return ret;
}
Exemplo n.º 7
0
int tegra_camera_powergate_init(struct tegra_camera *camera)
{
	int ret = 0;

#ifndef CONFIG_ARCH_TEGRA_2x_SOC
	ret = tegra_powergate_partition(TEGRA_POWERGATE_VENC);
	if (ret)
		dev_err(camera->dev, "%s: powergate failed.\n", __func__);
#endif
	return ret;
}
Exemplo n.º 8
0
static int tegra_camera_release(struct inode *inode, struct file *file)
{
        int i, err = 0;

	for (i = 0; i < ARRAY_SIZE(tegra_camera_block); i++)
		if (tegra_camera_block[i].is_enabled) {
			tegra_camera_block[i].disable();
			tegra_camera_block[i].is_enabled = false;
		}
	/* If camera blocks are not powergated yet, do it now */
	if (tegra_camera_powergate > 0) {
		mutex_lock(&tegra_camera_lock);
		tegra_camera_powergate = 0;
		err = tegra_powergate_partition(TEGRA_POWERGATE_VENC);
		if (err)
			pr_err("%s: Powergating failed.\n", __func__);
		mutex_unlock(&tegra_camera_lock);
	}
	return 0;
}
int tegraxx_unpowergate_partition_with_clk_on(int id,
        struct powergate_partition_info *pg_info)
{
    int ret = 0;

    ret = tegra_unpowergate_partition(id);
    if (ret)
        goto err_unpowergating;

    /* Enable clks for the partition */
    ret = partition_clk_enable(pg_info);
    if (ret)
        goto err_unpowergate_clk;

    return ret;

err_unpowergate_clk:
    tegra_powergate_partition(id);
    WARN(1, "Could not Un-Powergate %d, err in enabling clk", id);
err_unpowergating:
    WARN(1, "Could not Un-Powergate %d", id);

    return ret;
}
Exemplo n.º 10
0
static int tegra_camera_probe(struct platform_device *pdev)
{
	int err;
	struct tegra_camera_dev *dev;

	dev_info(&pdev->dev, "%s\n", __func__);
	dev = devm_kzalloc(&pdev->dev, sizeof(struct tegra_camera_dev),
			GFP_KERNEL);
	if (!dev) {
		err = -ENOMEM;
		dev_err(&pdev->dev, "%s: unable to allocate memory\n",
			__func__);
		goto alloc_err;
	}

	mutex_init(&dev->tegra_camera_lock);

	/* Powergate VE when boot */
	mutex_lock(&dev->tegra_camera_lock);
#ifndef CONFIG_ARCH_TEGRA_2x_SOC
	err = tegra_powergate_partition(TEGRA_POWERGATE_VENC);
	if (err)
		dev_err(&pdev->dev, "%s: powergate failed.\n", __func__);
#endif
	mutex_unlock(&dev->tegra_camera_lock);

	dev->dev = &pdev->dev;
	pdata = pdev->dev.platform_data;

	/* Get regulator pointer */
#ifdef CONFIG_ARCH_TEGRA_2x_SOC
	dev->reg = regulator_get(&pdev->dev, "vcsi");
#else
	dev->reg = regulator_get(&pdev->dev, "avdd_dsi_csi");
#endif
	if (IS_ERR_OR_NULL(dev->reg)) {
		if (dev->reg == ERR_PTR(-ENODEV)) {
			dev->reg = NULL;
			dev_info(&pdev->dev, "%s: no regulator device, overriding\n",
							__func__);
		} else {
			dev_err(&pdev->dev, "%s: couldn't get regulator\n",
							__func__);
			return PTR_ERR(dev->reg);
		}
	}

	regulator_set_voltage(dev->reg, 1200000, 1200000);

	dev->misc_dev.minor = MISC_DYNAMIC_MINOR;
	dev->misc_dev.name = TEGRA_CAMERA_NAME;
	dev->misc_dev.fops = &tegra_camera_fops;
	dev->misc_dev.parent = &pdev->dev;

	err = misc_register(&dev->misc_dev);
	if (err) {
		dev_err(&pdev->dev, "%s: Unable to register misc device!\n",
		       TEGRA_CAMERA_NAME);
		goto misc_register_err;
	}

	err = tegra_camera_clk_get(pdev, "isp", &dev->isp_clk);
	if (err)
		goto misc_register_err;
	err = tegra_camera_clk_get(pdev, "vi", &dev->vi_clk);
	if (err)
		goto vi_clk_get_err;
	err = tegra_camera_clk_get(pdev, "vi_sensor", &dev->vi_sensor_clk);
	if (err)
		goto vi_sensor_clk_get_err;
	err = tegra_camera_clk_get(pdev, "csus", &dev->csus_clk);
	if (err)
		goto csus_clk_get_err;
	err = tegra_camera_clk_get(pdev, "csi", &dev->csi_clk);
	if (err)
		goto csi_clk_get_err;
	err = tegra_camera_clk_get(pdev, "emc", &dev->emc_clk);
	if (err)
		goto emc_clk_get_err;

	/* dev is set in order to restore in _remove */
	platform_set_drvdata(pdev, dev);
	p_cam_dev = dev;

	return 0;

emc_clk_get_err:
	clk_put(dev->emc_clk);
csi_clk_get_err:
	clk_put(dev->csus_clk);
csus_clk_get_err:
	clk_put(dev->vi_sensor_clk);
vi_sensor_clk_get_err:
	clk_put(dev->vi_clk);
vi_clk_get_err:
	clk_put(dev->isp_clk);
misc_register_err:
	regulator_put(dev->reg);
alloc_err:
	return err;
}
Exemplo n.º 11
0
static int tegra_camera_probe(struct platform_device *pdev)
{
	int err;

	pr_info("%s: probe\n", TEGRA_CAMERA_NAME);

	mutex_lock(&tegra_camera_lock);
	tegra_camera_powergate = 0;
	err = tegra_powergate_partition(TEGRA_POWERGATE_VENC);
	if (err)
		pr_err("%s: Powergating failed.\n", __func__);
	mutex_unlock(&tegra_camera_lock);

#ifdef CONFIG_ARCH_TEGRA_2x_SOC
	tegra_camera_regulator_csi = regulator_get(&pdev->dev, "vcsi");
#else
	tegra_camera_regulator_csi = regulator_get(&pdev->dev, "avdd_dsi_csi");
#endif
	if (IS_ERR_OR_NULL(tegra_camera_regulator_csi)) {
		pr_err("%s: Couldn't get regulator\n", TEGRA_CAMERA_NAME);
		return PTR_ERR(tegra_camera_regulator_csi);
	}
	regulator_set_voltage(tegra_camera_regulator_csi, 1200000, 1200000);

	err = misc_register(&tegra_camera_device);
	if (err) {
		pr_err("%s: Unable to register misc device!\n",
		       TEGRA_CAMERA_NAME);
		goto misc_register_err;
	}

	err = tegra_camera_clk_get(pdev, "isp", &isp_clk);
	if (err)
		goto misc_register_err;
	err = tegra_camera_clk_get(pdev, "vi", &vi_clk);
	if (err)
		goto vi_clk_get_err;
	err = tegra_camera_clk_get(pdev, "vi_sensor", &vi_sensor_clk);
	if (err)
		goto vi_sensor_clk_get_err;
	err = tegra_camera_clk_get(pdev, "csus", &csus_clk);
	if (err)
		goto csus_clk_get_err;
	err = tegra_camera_clk_get(pdev, "csi", &csi_clk);
	if (err)
		goto csi_clk_get_err;

	return 0;

csi_clk_get_err:
	clk_put(csus_clk);
csus_clk_get_err:
	clk_put(vi_sensor_clk);
vi_sensor_clk_get_err:
	clk_put(vi_clk);
vi_clk_get_err:
	clk_put(isp_clk);
misc_register_err:
	regulator_put(tegra_camera_regulator_csi);
	return err;
}
Exemplo n.º 12
0
static long tegra_camera_ioctl(struct file *file,
			       unsigned int cmd, unsigned long arg)
{
	uint id;

	/* first element of arg must be u32 with id of module to talk to */
	if (copy_from_user(&id, (const void __user *)arg, sizeof(uint))) {
		pr_err("%s: Failed to copy arg from user", __func__);
		return -EFAULT;
	}

	if (id >= ARRAY_SIZE(tegra_camera_block)) {
		pr_err("%s: Invalid id to tegra isp ioctl%d\n", __func__, id);
		return -EINVAL;
	}

	switch (cmd) {
	case TEGRA_CAMERA_IOCTL_ENABLE:
	{
		int ret = 0;

		mutex_lock(&tegra_camera_lock);
		/* Unpowergate camera blocks (vi, csi and isp)
		   before enabling clocks */
		if (tegra_camera_powergate++ == 0) {
			ret = tegra_unpowergate_partition(TEGRA_POWERGATE_VENC);
			if (ret) {
				tegra_powergate_partition(TEGRA_POWERGATE_VENC);
				pr_err("%s: Unpowergating failed.\n", __func__);
				tegra_camera_powergate = 0;
				mutex_unlock(&tegra_camera_lock);
				return ret;
			}
		}

		if (!tegra_camera_block[id].is_enabled) {
			ret = tegra_camera_block[id].enable();
			tegra_camera_block[id].is_enabled = true;
		}
		mutex_unlock(&tegra_camera_lock);
		return ret;
	}
	case TEGRA_CAMERA_IOCTL_DISABLE:
	{
		int ret = 0;

		mutex_lock(&tegra_camera_lock);
		if (tegra_camera_block[id].is_enabled) {
			ret = tegra_camera_block[id].disable();
			tegra_camera_block[id].is_enabled = false;
		}
		/* Powergate camera blocks (vi, csi and isp)
		   after disabling all the clocks */
		if (!ret) {
			if (--tegra_camera_powergate == 0) {
				ret = tegra_powergate_partition(TEGRA_POWERGATE_VENC);
				if (ret)
					pr_err("%s: Powergating failed.\n", __func__);
			}
		}
		mutex_unlock(&tegra_camera_lock);
		return ret;
	}
	case TEGRA_CAMERA_IOCTL_CLK_SET_RATE:
	{
		struct tegra_camera_clk_info info;
		int ret;

		if (copy_from_user(&info, (const void __user *)arg,
				   sizeof(struct tegra_camera_clk_info))) {
			pr_err("%s: Failed to copy arg from user\n", __func__);
			return -EFAULT;
		}
		ret = tegra_camera_clk_set_rate(&info);
		if (ret)
			return ret;
		if (copy_to_user((void __user *)arg, &info,
				 sizeof(struct tegra_camera_clk_info))) {
			pr_err("%s: Failed to copy arg to user\n", __func__);
			return -EFAULT;
		}
		return 0;
	}
	case TEGRA_CAMERA_IOCTL_RESET:
		return tegra_camera_reset(id);
	default:
		pr_err("%s: Unknown tegra_camera ioctl.\n", TEGRA_CAMERA_NAME);
		return -EINVAL;
	}
	return 0;
}