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"
24 #define MFC_SCLK_NAME "sclk-mfc"
25 #define MFC_SCLK_RATE (200 * 1000000)
29 static struct s5p_mfc_pm *pm;
30 static struct s5p_mfc_dev *p_dev;
33 static atomic_t clk_ref;
36 int s5p_mfc_init_pm(struct s5p_mfc_dev *dev)
42 pm->clock_gate = clk_get(&dev->plat_dev->dev, MFC_GATE_CLK_NAME);
43 if (IS_ERR(pm->clock_gate)) {
44 mfc_err("Failed to get clock-gating control\n");
45 ret = PTR_ERR(pm->clock_gate);
49 ret = clk_prepare(pm->clock_gate);
51 mfc_err("Failed to prepare clock-gating control\n");
55 if (dev->variant->version != MFC_VERSION_V6) {
56 pm->clock = clk_get(&dev->plat_dev->dev, MFC_SCLK_NAME);
57 if (IS_ERR(pm->clock)) {
58 mfc_info("Failed to get MFC special clock control\n");
60 clk_set_rate(pm->clock, MFC_SCLK_RATE);
61 ret = clk_prepare_enable(pm->clock);
63 mfc_err("Failed to enable MFC special clock\n");
69 atomic_set(&pm->power, 0);
70 #ifdef CONFIG_PM_RUNTIME
71 pm->device = &dev->plat_dev->dev;
72 pm_runtime_enable(pm->device);
75 atomic_set(&clk_ref, 0);
82 clk_put(pm->clock_gate);
87 void s5p_mfc_final_pm(struct s5p_mfc_dev *dev)
89 if (dev->variant->version != MFC_VERSION_V6 &&
91 clk_disable_unprepare(pm->clock);
94 clk_unprepare(pm->clock_gate);
95 clk_put(pm->clock_gate);
96 #ifdef CONFIG_PM_RUNTIME
97 pm_runtime_disable(pm->device);
101 int s5p_mfc_clock_on(void)
105 atomic_inc(&clk_ref);
106 mfc_debug(3, "+ %d\n", atomic_read(&clk_ref));
108 ret = clk_enable(pm->clock_gate);
112 void s5p_mfc_clock_off(void)
115 atomic_dec(&clk_ref);
116 mfc_debug(3, "- %d\n", atomic_read(&clk_ref));
118 clk_disable(pm->clock_gate);
121 int s5p_mfc_power_on(void)
123 #ifdef CONFIG_PM_RUNTIME
124 return pm_runtime_get_sync(pm->device);
126 atomic_set(&pm->power, 1);
131 int s5p_mfc_power_off(void)
133 #ifdef CONFIG_PM_RUNTIME
134 return pm_runtime_put_sync(pm->device);
136 atomic_set(&pm->power, 0);