aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media/video/samsung/tvout/s5p_tvout_common_lib.c
blob: dd69187521fb7c9dcb079624b0277604e9f8fefb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
/* linux/drivers/media/video/samsung/tvout/s5p_tvout_common_lib.c
 *
 * Copyright (c) 2009 Samsung Electronics
 *		http://www.samsung.com/
 *
 * Common library file for SAMSUNG TVOUT driver
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 as
 * published by the Free Software Foundation.
 */

#include <linux/io.h>
#include <linux/slab.h>
#include <linux/err.h>

#include <linux/pm_runtime.h>

#include "s5p_tvout_common_lib.h"

#ifdef CONFIG_VCM
#include <plat/s5p-vcm.h>
#endif

#ifdef CONFIG_VCM
static atomic_t		s5p_tvout_vcm_usage = ATOMIC_INIT(0);

static void tvout_tlb_invalidator(enum vcm_dev_id id)
{
#if (defined(CONFIG_EXYNOS_DEV_PD) && defined(CONFIG_PM_RUNTIME))
	if (atomic_read(&s5p_tvout_vcm_usage) == 0) {
		return (void)0;
	}
#endif
}

static void tvout_pgd_base_specifier(enum vcm_dev_id id, unsigned long base)
{

#if (defined(CONFIG_EXYNOS_DEV_PD) && defined(CONFIG_PM_RUNTIME))
	if (atomic_read(&s5p_tvout_vcm_usage) == 0) {
		return (void)0;
	}
#endif
}

static struct s5p_vcm_driver s5ptv_vcm_driver = {
	.tlb_invalidator = &tvout_tlb_invalidator,
	.pgd_base_specifier = &tvout_pgd_base_specifier,
	.phys_alloc = NULL,
	.phys_free = NULL,
};

#endif


#ifdef CONFIG_VCM
static struct vcm	*s5p_vcm;

int s5p_tvout_vcm_create_unified(void)
{
	s5p_vcm = vcm_create_unified((SZ_64M), VCM_DEV_TV,
						&s5ptv_vcm_driver);

	if (IS_ERR(s5p_vcm))
		return PTR_ERR(s5p_vcm);

	return 0;
}

int s5p_tvout_vcm_init(void)
{
	if (vcm_activate(s5p_vcm) < 0)
		return -1;

	return 0;
}

void s5p_tvout_vcm_activate(void)
{
	vcm_set_pgtable_base(VCM_DEV_TV);
}

void s5p_tvout_vcm_deactivate(void)
{
}


#endif
int s5p_tvout_map_resource_mem(
		struct platform_device *pdev, char *name,
		void __iomem **base, struct resource **res)
{
	size_t		size;
	void __iomem	*tmp_base;
	struct resource	*tmp_res;

	tmp_res = platform_get_resource_byname(pdev, IORESOURCE_MEM, name);

	if (!tmp_res)
		goto not_found;

	size = (tmp_res->end - tmp_res->start) + 1;

	tmp_res = request_mem_region(tmp_res->start, size, tmp_res->name);

	if (!tmp_res) {
		tvout_err("%s: fail to get memory region\n", __func__);
		goto err_on_request_mem_region;
	}

	tmp_base = ioremap(tmp_res->start, size);

	if (!tmp_base) {
		tvout_err("%s: fail to ioremap address region\n", __func__);
		goto err_on_ioremap;
	}

	*res = tmp_res;
	*base = tmp_base;
	return 0;

err_on_ioremap:
	release_resource(tmp_res);
	kfree(tmp_res);

err_on_request_mem_region:
	return -ENXIO;

not_found:
	tvout_err("%s: fail to get IORESOURCE_MEM for %s\n", __func__, name);
	return -ENODEV;
}

void s5p_tvout_unmap_resource_mem(
		void __iomem *base, struct resource *res)
{
	if (base)
		iounmap(base);

	if (res) {
		release_resource(res);
		kfree(res);
	}
}

/* Libraries for runtime PM */
static struct device *s5p_tvout_dev;

void s5p_tvout_pm_runtime_enable(struct device *dev)
{
	pm_runtime_enable(dev);

	s5p_tvout_dev = dev;
}

void s5p_tvout_pm_runtime_disable(struct device *dev)
{
	pm_runtime_disable(dev);
}

void s5p_tvout_pm_runtime_get(void)
{
	pm_runtime_get_sync(s5p_tvout_dev);

#ifdef CONFIG_VCM
	atomic_inc(&s5p_tvout_vcm_usage);
	if (atomic_read(&s5p_tvout_vcm_usage) == 1)
		s5p_tvout_vcm_activate();
#endif
}

void s5p_tvout_pm_runtime_put(void)
{
#ifdef CONFIG_VCM
	if (atomic_read(&s5p_tvout_vcm_usage) == 1)
		s5p_tvout_vcm_deactivate();

	atomic_dec(&s5p_tvout_vcm_usage);
#endif

	pm_runtime_put_sync(s5p_tvout_dev);
}