Example #1
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;
}
Example #2
0
static long tegra_camera_ioctl(struct file *file,
			       unsigned int cmd, unsigned long arg)
{
	uint id;
	struct tegra_camera_dev *dev = file->private_data;

	/* 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))) {
		dev_err(dev->dev,
				"%s: Failed to copy arg from user", __func__);
		return -EFAULT;
	}

	if (id >= ARRAY_SIZE(tegra_camera_block)) {
		dev_err(dev->dev,
				"%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(&dev->tegra_camera_lock);
		/* Unpowergate camera blocks (vi, csi and isp)
		   before enabling clocks */
		ret = tegra_camera_power_on(dev);
		if (ret) {
			dev->power_refcnt = 0;
			mutex_unlock(&dev->tegra_camera_lock);
			return ret;
		}

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

		mutex_lock(&dev->tegra_camera_lock);
		if (tegra_camera_block[id].is_enabled) {
			ret = tegra_camera_block[id].disable(dev);
			tegra_camera_block[id].is_enabled = false;
		}
		/* Powergate camera blocks (vi, csi and isp)
		   after disabling all the clocks */
		if (!ret) {
			ret = tegra_camera_power_off(dev);
		}
		mutex_unlock(&dev->tegra_camera_lock);
		return ret;
	}
	case TEGRA_CAMERA_IOCTL_CLK_SET_RATE:
	{
		int ret;

		if (copy_from_user(&dev->info, (const void __user *)arg,
				   sizeof(struct tegra_camera_clk_info))) {
			dev_err(dev->dev,
				"%s: Failed to copy arg from user\n", __func__);
			return -EFAULT;
		}
		ret = tegra_camera_clk_set_rate(dev);
		if (ret)
			return ret;
		if (copy_to_user((void __user *)arg, &dev->info,
				 sizeof(struct tegra_camera_clk_info))) {
			dev_err(dev->dev,
				"%s: Failed to copy arg to user\n", __func__);
			return -EFAULT;
		}
		return 0;
	}
	case TEGRA_CAMERA_IOCTL_RESET:
		return tegra_camera_reset(dev, id);
	default:
		dev_err(dev->dev,
				"%s: Unknown tegra_camera ioctl.\n", __func__);
		return -EINVAL;
	}
	return 0;
}
Example #3
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);
		nvhost_set_max_acm_timeout(true);
		if (!tegra_camera_block[id].is_enabled) {
			ret = tegra_camera_block[id].enable();
			tegra_camera_block[id].is_enabled = true;
		}
#ifdef CONFIG_TEGRA_DYNAMIC_CAMERA_CLK_RATE
		tegra_camera_save_graphic_clk();
		current_rates = NULL;
#endif
#if defined CONFIG_HAS_EARLYSUSPEND && defined CONFIG_CPU_FREQ
		if (work_q_set_conservative == 0) {
			work_q_set_conservative = 1;
			schedule_delayed_work(&scaling_gov_work, SET_CONSERVATIVE_GOVERNOR_DELAY);
		}
#endif
		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;
		}
#ifdef CONFIG_TEGRA_DYNAMIC_CAMERA_CLK_RATE
		tegra_camera_restore_graphic_clk();
		current_rates = NULL;
#endif
#if defined CONFIG_HAS_EARLYSUSPEND && defined CONFIG_CPU_FREQ
		if (work_q_set_conservative == 1) {
			work_q_set_conservative = 0;
			schedule_delayed_work(&scaling_gov_work, 0);
		}
#endif
		nvhost_set_max_acm_timeout(false);
		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);
#ifdef CONFIG_TEGRA_DYNAMIC_CAMERA_CLK_RATE
	case TEGRA_CAMERA_IOCTL_CAMERA_USECASE:
	{
		int buf[2];
		unsigned long *rates;

		if (copy_from_user(buf, (const void __user *)arg, sizeof(buf))){
			pr_err("%s: Failed to copy arg from user\n", __func__);
			return -EFAULT;
		}
		mutex_lock(&tegra_camera_lock);
		current_usecase = buf[1];
		rates = graphics_clk_cfg->get_graphics_clk_freqs(
			current_usecase,
			current_resolution[1],
			current_resolution[2],
			current_resolution[3]);
		if (rates != NULL && rates != current_rates) {
			current_rates = rates;
			tegra_camera_graphic_clk_set_rate(rates);
		}

		mutex_unlock(&tegra_camera_lock);
		break;
	}
	case TEGRA_CAMERA_IOCTL_CAMERA_MODE:
	{
		unsigned long *rates;
		if (graphics_clk_cfg == 0)
			break;

		mutex_lock(&tegra_camera_lock);
		if (copy_from_user(current_resolution, (const void __user *)arg,
					sizeof(current_resolution))){
			pr_err("%s: Failed to copy arg from user\n", __func__);
			mutex_unlock(&tegra_camera_lock);
			return -EFAULT;
		}

		rates = graphics_clk_cfg->get_graphics_clk_freqs(
					current_usecase,
					current_resolution[1],
					current_resolution[2],
					current_resolution[3]);
		if (rates != NULL && rates != current_rates) {
			current_rates = rates;
			tegra_camera_graphic_clk_set_rate(rates);
		}

		mutex_unlock(&tegra_camera_lock);
		break;
	}
#endif
	default:
		pr_err("%s: Unknown tegra_camera ioctl.\n", TEGRA_CAMERA_NAME);
		return -EINVAL;
	}
	return 0;
}
Example #4
0
static long tegra_camera_ioctl(struct file *file,
                               unsigned int cmd, unsigned long arg)
{
    uint id;
    struct tegra_camera_dev *dev = file->private_data;

    /* 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))) {
        dev_err(dev->dev,
                "%s: Failed to copy arg from user", __func__);
        return -EFAULT;
    }

    if (id >= ARRAY_SIZE(tegra_camera_block)) {
        dev_err(dev->dev,
                "%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(&dev->tegra_camera_lock);
        /* Unpowergate camera blocks (vi, csi and isp)
           before enabling clocks */
        ret = tegra_camera_power_on(dev);
        if (ret) {
            dev->power_refcnt = 0;
            mutex_unlock(&dev->tegra_camera_lock);
            return ret;
        }

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

        mutex_lock(&dev->tegra_camera_lock);
        if (tegra_camera_block[id].is_enabled) {
            ret = tegra_camera_block[id].disable(dev);
            tegra_camera_block[id].is_enabled = false;
        }
        /* Powergate camera blocks (vi, csi and isp)
           after disabling all the clocks */
        if (!ret) {
            ret = tegra_camera_power_off(dev);
        }
        mutex_unlock(&dev->tegra_camera_lock);
        return ret;
    }
    case TEGRA_CAMERA_IOCTL_CLK_SET_RATE:
    {
        int ret;

        if (copy_from_user(&dev->info, (const void __user *)arg,
                           sizeof(struct tegra_camera_clk_info))) {
            dev_err(dev->dev,
                    "%s: Failed to copy arg from user\n", __func__);
            return -EFAULT;
        }
        ret = tegra_camera_clk_set_rate(dev);
        if (ret)
            return ret;
        if (copy_to_user((void __user *)arg, &dev->info,
                         sizeof(struct tegra_camera_clk_info))) {
            dev_err(dev->dev,
                    "%s: Failed to copy arg to user\n", __func__);
            return -EFAULT;
        }
        return 0;
    }
    case TEGRA_CAMERA_IOCTL_RESET:
        return tegra_camera_reset(dev, id);

    case TEGRA_CAMERA_IOCTL_CAMERA_USECASE:
    {
        int buf[2];

        if (copy_from_user(buf, (const void __user *)arg, sizeof(buf))) {
            pr_err("%s: Failed to copy arg from user\n", __func__);
            return -EFAULT;
        }
        mutex_lock(&dev->tegra_camera_lock);
        current_usecase = buf[1];

#ifdef CONFIG_TEGRA_CPU_FREQ_LOCK
        if (current_usecase == CAMERA_USECASE_PREVIEW)
            // need test to optimize
            tegra_cpu_lock_speed(312000, 760000, 0); /* min and max cpu clock for preview */
        else if (current_usecase == CAMERA_USECASE_CAMERA_CAPTURE)
            tegra_cpu_lock_speed(1000000, 0, 5000); /* for snapshot performance */
        else if (current_usecase == CAMERA_USECASE_VIDEO_RECORD)
        {
            if (current_resolution[1]*current_resolution[2]*current_resolution[3] >= 1280*720*30)
            {
                tegra_cpu_lock_speed(816000, 0, 0); /* for hd-video performance */
            }
            else
            {
                tegra_cpu_unlock_speed();
            }
        }
        else if(current_usecase == CAMERA_USECASE_PREVIEW_STOP)
            tegra_cpu_lock_speed(1000000, 0, 5000); /* for stoping performance */
        else
            tegra_cpu_unlock_speed();
#endif /* CONFIG_TEGRA_CPU_FREQ_LOCK */

#if 1
        if (current_usecase == CAMERA_USECASE_CAMERA_CAPTURE)
            printk(" -- CAMERA_USECASE_CAMERA_CAPTURE --\n");
        else if (current_usecase == CAMERA_USECASE_PREVIEW)
            printk(" -- CAMERA_USECASE_PREVIEW --\n");
        else if ((current_usecase == CAMERA_USECASE_VIDEO_RECORD)
                 && (current_resolution[1]*current_resolution[2]*current_resolution[3] < 1280*720*30))
            printk(" -- CAMERA_USECASE_VIDEO_RECORD : LOW %d*%d*%d--\n", current_resolution[1], current_resolution[2], current_resolution[3]);
        else
        {
            printk(" -- CAMERA_USECASE_VIDEO_RECORD : HIGH over 1280*720*30 --\n");
            printk(" -- CAMERA_USECASE_VIDEO_RECORD : HIGH %d*%d*%d--\n", current_resolution[1], current_resolution[2], current_resolution[3]);
        }
#endif

        mutex_unlock(&dev->tegra_camera_lock);
        break;
    }
    case TEGRA_CAMERA_IOCTL_CAMERA_MODE:
    {

        mutex_lock(&dev->tegra_camera_lock);
        if (copy_from_user(current_resolution, (const void __user *)arg,
                           sizeof(current_resolution))) {
            pr_err("%s: Failed to copy arg from user\n", __func__);
            mutex_unlock(&dev->tegra_camera_lock);
            return -EFAULT;
        }

#if 1
        if (current_usecase == CAMERA_USECASE_CAMERA_CAPTURE)
            printk(" -- CAMERA_USECASE_CAMERA_CAPTURE --\n");
        else if (current_usecase == CAMERA_USECASE_PREVIEW)
            printk(" -- CAMERA_USECASE_PREVIEW --\n");
        else if ((current_usecase == CAMERA_USECASE_VIDEO_RECORD)
                 && (current_resolution[1]*current_resolution[2]*current_resolution[3] < 1280*720*30))
            printk(" -- CAMERA_USECASE_VIDEO_RECORD : LOW %d*%d*%d--\n", current_resolution[1], current_resolution[2], current_resolution[3]);
        else
        {
            printk(" -- CAMERA_USECASE_VIDEO_RECORD : HIGH over 1280*720*30 --\n");
            printk(" -- CAMERA_USECASE_VIDEO_RECORD : HIGH %d*%d*%d--\n", current_resolution[1], current_resolution[2], current_resolution[3]);
        }
#endif
        mutex_unlock(&dev->tegra_camera_lock);
        break;
    }
    default:
        dev_err(dev->dev,
                "%s: Unknown tegra_camera ioctl.\n", __func__);
        return -EINVAL;
    }
    return 0;
}