2011-06-21 21:51:26 +08:00
|
|
|
/*
|
2012-08-15 04:31:16 +08:00
|
|
|
* linux/drivers/media/platform/s5p-mfc/s5p_mfc_pm.c
|
2011-06-21 21:51:26 +08:00
|
|
|
*
|
|
|
|
* Copyright (c) 2010 Samsung Electronics Co., Ltd.
|
|
|
|
* http://www.samsung.com/
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/clk.h>
|
|
|
|
#include <linux/err.h>
|
|
|
|
#include <linux/platform_device.h>
|
|
|
|
#include <linux/pm_runtime.h>
|
|
|
|
#include "s5p_mfc_common.h"
|
|
|
|
#include "s5p_mfc_debug.h"
|
|
|
|
#include "s5p_mfc_pm.h"
|
|
|
|
|
|
|
|
#define MFC_GATE_CLK_NAME "mfc"
|
2014-08-27 20:36:28 +08:00
|
|
|
#define MFC_SCLK_NAME "sclk_mfc"
|
2011-06-21 21:51:26 +08:00
|
|
|
|
|
|
|
static struct s5p_mfc_pm *pm;
|
|
|
|
static struct s5p_mfc_dev *p_dev;
|
2012-10-17 18:11:50 +08:00
|
|
|
static atomic_t clk_ref;
|
2011-06-21 21:51:26 +08:00
|
|
|
|
|
|
|
int s5p_mfc_init_pm(struct s5p_mfc_dev *dev)
|
|
|
|
{
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
pm = &dev->pm;
|
|
|
|
p_dev = dev;
|
2016-11-10 18:31:23 +08:00
|
|
|
pm->use_clock_gating = dev->variant->use_clock_gating;
|
2011-06-21 21:51:26 +08:00
|
|
|
pm->clock_gate = clk_get(&dev->plat_dev->dev, MFC_GATE_CLK_NAME);
|
|
|
|
if (IS_ERR(pm->clock_gate)) {
|
|
|
|
mfc_err("Failed to get clock-gating control\n");
|
2012-02-16 21:51:56 +08:00
|
|
|
ret = PTR_ERR(pm->clock_gate);
|
2011-06-21 21:51:26 +08:00
|
|
|
goto err_g_ip_clk;
|
|
|
|
}
|
2012-02-16 21:51:56 +08:00
|
|
|
|
|
|
|
ret = clk_prepare(pm->clock_gate);
|
|
|
|
if (ret) {
|
2013-01-02 16:13:33 +08:00
|
|
|
mfc_err("Failed to prepare clock-gating control\n");
|
2012-02-16 21:51:56 +08:00
|
|
|
goto err_p_ip_clk;
|
|
|
|
}
|
|
|
|
|
2014-07-10 17:00:39 +08:00
|
|
|
if (dev->variant->version != MFC_VERSION_V6) {
|
|
|
|
pm->clock = clk_get(&dev->plat_dev->dev, MFC_SCLK_NAME);
|
|
|
|
if (IS_ERR(pm->clock)) {
|
|
|
|
mfc_info("Failed to get MFC special clock control\n");
|
2016-05-03 03:14:22 +08:00
|
|
|
pm->clock = NULL;
|
2014-07-10 17:00:39 +08:00
|
|
|
} else {
|
|
|
|
ret = clk_prepare_enable(pm->clock);
|
|
|
|
if (ret) {
|
|
|
|
mfc_err("Failed to enable MFC special clock\n");
|
|
|
|
goto err_s_clk;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-06-21 21:51:26 +08:00
|
|
|
pm->device = &dev->plat_dev->dev;
|
|
|
|
pm_runtime_enable(pm->device);
|
|
|
|
atomic_set(&clk_ref, 0);
|
2016-11-16 17:04:54 +08:00
|
|
|
|
2011-06-21 21:51:26 +08:00
|
|
|
return 0;
|
2014-07-10 17:00:39 +08:00
|
|
|
|
|
|
|
err_s_clk:
|
|
|
|
clk_put(pm->clock);
|
2016-06-29 03:17:18 +08:00
|
|
|
pm->clock = NULL;
|
2012-02-16 21:51:56 +08:00
|
|
|
err_p_ip_clk:
|
2011-06-21 21:51:26 +08:00
|
|
|
clk_put(pm->clock_gate);
|
2016-06-29 03:17:18 +08:00
|
|
|
pm->clock_gate = NULL;
|
2011-06-21 21:51:26 +08:00
|
|
|
err_g_ip_clk:
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
void s5p_mfc_final_pm(struct s5p_mfc_dev *dev)
|
|
|
|
{
|
2014-07-10 17:00:39 +08:00
|
|
|
if (dev->variant->version != MFC_VERSION_V6 &&
|
|
|
|
pm->clock) {
|
|
|
|
clk_disable_unprepare(pm->clock);
|
|
|
|
clk_put(pm->clock);
|
2016-06-29 03:17:18 +08:00
|
|
|
pm->clock = NULL;
|
2014-07-10 17:00:39 +08:00
|
|
|
}
|
2012-02-16 21:51:56 +08:00
|
|
|
clk_unprepare(pm->clock_gate);
|
2011-06-21 21:51:26 +08:00
|
|
|
clk_put(pm->clock_gate);
|
2016-06-29 03:17:18 +08:00
|
|
|
pm->clock_gate = NULL;
|
2011-06-21 21:51:26 +08:00
|
|
|
pm_runtime_disable(pm->device);
|
|
|
|
}
|
|
|
|
|
|
|
|
int s5p_mfc_clock_on(void)
|
|
|
|
{
|
2016-06-29 03:17:18 +08:00
|
|
|
int ret = 0;
|
2016-11-16 17:04:54 +08:00
|
|
|
|
2011-06-21 21:51:26 +08:00
|
|
|
atomic_inc(&clk_ref);
|
2013-05-28 14:26:16 +08:00
|
|
|
mfc_debug(3, "+ %d\n", atomic_read(&clk_ref));
|
2016-11-16 17:04:54 +08:00
|
|
|
|
2016-11-10 18:31:23 +08:00
|
|
|
if (!pm->use_clock_gating)
|
|
|
|
return 0;
|
2016-06-29 03:17:18 +08:00
|
|
|
if (!IS_ERR_OR_NULL(pm->clock_gate))
|
|
|
|
ret = clk_enable(pm->clock_gate);
|
2011-06-21 21:51:26 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
void s5p_mfc_clock_off(void)
|
|
|
|
{
|
|
|
|
atomic_dec(&clk_ref);
|
2013-05-28 14:26:16 +08:00
|
|
|
mfc_debug(3, "- %d\n", atomic_read(&clk_ref));
|
2016-11-16 17:04:54 +08:00
|
|
|
|
2016-11-10 18:31:23 +08:00
|
|
|
if (!pm->use_clock_gating)
|
|
|
|
return;
|
2016-06-29 03:17:18 +08:00
|
|
|
if (!IS_ERR_OR_NULL(pm->clock_gate))
|
|
|
|
clk_disable(pm->clock_gate);
|
2011-06-21 21:51:26 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int s5p_mfc_power_on(void)
|
|
|
|
{
|
2016-11-10 18:31:23 +08:00
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
ret = pm_runtime_get_sync(pm->device);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
2016-11-16 17:04:54 +08:00
|
|
|
|
2016-11-10 18:31:23 +08:00
|
|
|
if (!pm->use_clock_gating && !IS_ERR_OR_NULL(pm->clock_gate))
|
|
|
|
ret = clk_enable(pm->clock_gate);
|
|
|
|
return ret;
|
2011-06-21 21:51:26 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int s5p_mfc_power_off(void)
|
|
|
|
{
|
2016-11-10 18:31:23 +08:00
|
|
|
if (!pm->use_clock_gating && !IS_ERR_OR_NULL(pm->clock_gate))
|
|
|
|
clk_disable(pm->clock_gate);
|
2011-06-21 21:51:26 +08:00
|
|
|
return pm_runtime_put_sync(pm->device);
|
|
|
|
}
|
|
|
|
|
|
|
|
|