Input: xpad - add support for Xbox1 PDP Camo series gamepad
[linux/fpc-iii.git] / drivers / media / platform / s5p-mfc / s5p_mfc_pm.c
blob930dc2dddae66c2bd0f757000cef5037828c87cc
1 /*
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 #include <linux/pm_runtime.h>
17 #include "s5p_mfc_common.h"
18 #include "s5p_mfc_debug.h"
19 #include "s5p_mfc_pm.h"
21 #define MFC_GATE_CLK_NAME "mfc"
22 #define MFC_SCLK_NAME "sclk_mfc"
23 #define MFC_SCLK_RATE (200 * 1000000)
25 #define CLK_DEBUG
27 static struct s5p_mfc_pm *pm;
28 static struct s5p_mfc_dev *p_dev;
30 #ifdef CLK_DEBUG
31 static atomic_t clk_ref;
32 #endif
34 int s5p_mfc_init_pm(struct s5p_mfc_dev *dev)
36 int ret = 0;
38 pm = &dev->pm;
39 p_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);
44 goto err_g_ip_clk;
47 ret = clk_prepare(pm->clock_gate);
48 if (ret) {
49 mfc_err("Failed to prepare clock-gating control\n");
50 goto err_p_ip_clk;
53 if (dev->variant->version != MFC_VERSION_V6) {
54 pm->clock = clk_get(&dev->plat_dev->dev, MFC_SCLK_NAME);
55 if (IS_ERR(pm->clock)) {
56 mfc_info("Failed to get MFC special clock control\n");
57 pm->clock = NULL;
58 } else {
59 clk_set_rate(pm->clock, MFC_SCLK_RATE);
60 ret = clk_prepare_enable(pm->clock);
61 if (ret) {
62 mfc_err("Failed to enable MFC special clock\n");
63 goto err_s_clk;
68 atomic_set(&pm->power, 0);
69 #ifdef CONFIG_PM
70 pm->device = &dev->plat_dev->dev;
71 pm_runtime_enable(pm->device);
72 #endif
73 #ifdef CLK_DEBUG
74 atomic_set(&clk_ref, 0);
75 #endif
76 return 0;
78 err_s_clk:
79 clk_put(pm->clock);
80 pm->clock = NULL;
81 err_p_ip_clk:
82 clk_put(pm->clock_gate);
83 pm->clock_gate = NULL;
84 err_g_ip_clk:
85 return ret;
88 void s5p_mfc_final_pm(struct s5p_mfc_dev *dev)
90 if (dev->variant->version != MFC_VERSION_V6 &&
91 pm->clock) {
92 clk_disable_unprepare(pm->clock);
93 clk_put(pm->clock);
94 pm->clock = NULL;
96 clk_unprepare(pm->clock_gate);
97 clk_put(pm->clock_gate);
98 pm->clock_gate = NULL;
99 #ifdef CONFIG_PM
100 pm_runtime_disable(pm->device);
101 #endif
104 int s5p_mfc_clock_on(void)
106 int ret = 0;
107 #ifdef CLK_DEBUG
108 atomic_inc(&clk_ref);
109 mfc_debug(3, "+ %d\n", atomic_read(&clk_ref));
110 #endif
111 if (!IS_ERR_OR_NULL(pm->clock_gate))
112 ret = clk_enable(pm->clock_gate);
113 return ret;
116 void s5p_mfc_clock_off(void)
118 #ifdef CLK_DEBUG
119 atomic_dec(&clk_ref);
120 mfc_debug(3, "- %d\n", atomic_read(&clk_ref));
121 #endif
122 if (!IS_ERR_OR_NULL(pm->clock_gate))
123 clk_disable(pm->clock_gate);
126 int s5p_mfc_power_on(void)
128 #ifdef CONFIG_PM
129 return pm_runtime_get_sync(pm->device);
130 #else
131 atomic_set(&pm->power, 1);
132 return 0;
133 #endif
136 int s5p_mfc_power_off(void)
138 #ifdef CONFIG_PM
139 return pm_runtime_put_sync(pm->device);
140 #else
141 atomic_set(&pm->power, 0);
142 return 0;
143 #endif