2 * linux/drivers/media/platform/s5p-mfc/s5p_mfc_pm.c
4 * Copyright (c) 2010 Samsung Electronics Co., Ltd.
5 * http://www.samsung.com/
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
13 #include <linux/clk.h>
14 #include <linux/err.h>
15 #include <linux/platform_device.h>
16 #ifdef CONFIG_PM_RUNTIME
17 #include <linux/pm_runtime.h>
19 #include "s5p_mfc_common.h"
20 #include "s5p_mfc_debug.h"
21 #include "s5p_mfc_pm.h"
23 #define MFC_GATE_CLK_NAME "mfc"
27 static struct s5p_mfc_pm *pm;
28 static struct s5p_mfc_dev *p_dev;
31 static atomic_t clk_ref;
34 int s5p_mfc_init_pm(struct s5p_mfc_dev *dev)
40 pm->clock_gate = clk_get(&dev->plat_dev->dev, MFC_GATE_CLK_NAME);
41 if (IS_ERR(pm->clock_gate)) {
42 mfc_err("Failed to get clock-gating control\n");
43 ret = PTR_ERR(pm->clock_gate);
47 ret = clk_prepare(pm->clock_gate);
49 mfc_err("Failed to preapre clock-gating control\n");
53 pm->clock = clk_get(&dev->plat_dev->dev, dev->variant->mclk_name);
54 if (IS_ERR(pm->clock)) {
55 mfc_err("Failed to get MFC clock\n");
56 ret = PTR_ERR(pm->clock);
60 ret = clk_prepare(pm->clock);
62 mfc_err("Failed to prepare MFC clock\n");
66 atomic_set(&pm->power, 0);
67 #ifdef CONFIG_PM_RUNTIME
68 pm->device = &dev->plat_dev->dev;
69 pm_runtime_enable(pm->device);
72 atomic_set(&clk_ref, 0);
78 clk_unprepare(pm->clock_gate);
80 clk_put(pm->clock_gate);
85 void s5p_mfc_final_pm(struct s5p_mfc_dev *dev)
87 clk_unprepare(pm->clock_gate);
88 clk_put(pm->clock_gate);
89 clk_unprepare(pm->clock);
91 #ifdef CONFIG_PM_RUNTIME
92 pm_runtime_disable(pm->device);
96 int s5p_mfc_clock_on(void)
100 atomic_inc(&clk_ref);
101 mfc_debug(3, "+ %d", atomic_read(&clk_ref));
103 ret = clk_enable(pm->clock_gate);
107 void s5p_mfc_clock_off(void)
110 atomic_dec(&clk_ref);
111 mfc_debug(3, "- %d", atomic_read(&clk_ref));
113 clk_disable(pm->clock_gate);
116 int s5p_mfc_power_on(void)
118 #ifdef CONFIG_PM_RUNTIME
119 return pm_runtime_get_sync(pm->device);
121 atomic_set(&pm->power, 1);
126 int s5p_mfc_power_off(void)
128 #ifdef CONFIG_PM_RUNTIME
129 return pm_runtime_put_sync(pm->device);
131 atomic_set(&pm->power, 0);