1 /* linux/drivers/media/video/samsung/tvout/s5p_tvout_common_lib.c
3 * Copyright (c) 2009 Samsung Electronics
4 * http://www.samsung.com/
6 * Common library file for SAMSUNG TVOUT driver
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
14 #include <linux/slab.h>
15 #include <linux/err.h>
17 #include <linux/pm_runtime.h>
19 #include "s5p_tvout_common_lib.h"
22 #include <plat/s5p-vcm.h>
26 static atomic_t s5p_tvout_vcm_usage = ATOMIC_INIT(0);
28 static void tvout_tlb_invalidator(enum vcm_dev_id id)
30 #if (defined(CONFIG_S5PV310_DEV_PD) && defined(CONFIG_PM_RUNTIME))
31 if (atomic_read(&s5p_tvout_vcm_usage) == 0) {
35 #ifdef CONFIG_S5P_SYSMMU_TV
36 sysmmu_tlb_invalidate(SYSMMU_TV);
40 static void tvout_pgd_base_specifier(enum vcm_dev_id id, unsigned long base)
43 #if (defined(CONFIG_S5PV310_DEV_PD) && defined(CONFIG_PM_RUNTIME))
44 if (atomic_read(&s5p_tvout_vcm_usage) == 0) {
48 #ifdef CONFIG_S5P_SYSMMU_TV
49 sysmmu_set_tablebase_pgd(SYSMMU_TV, base);
53 static struct s5p_vcm_driver s5ptv_vcm_driver = {
54 .tlb_invalidator = &tvout_tlb_invalidator,
55 .pgd_base_specifier = &tvout_pgd_base_specifier,
64 static struct vcm *s5p_vcm;
66 int s5p_tvout_vcm_create_unified(void)
68 s5p_vcm = vcm_create_unified((SZ_64M), VCM_DEV_TV,
72 return PTR_ERR(s5p_vcm);
77 int s5p_tvout_vcm_init(void)
79 if (vcm_activate(s5p_vcm) < 0)
85 void s5p_tvout_vcm_activate(void)
87 #ifdef CONFIG_S5P_SYSMMU_TV
90 vcm_set_pgtable_base(VCM_DEV_TV);
93 void s5p_tvout_vcm_deactivate(void)
95 #ifdef CONFIG_S5P_SYSMMU_TV
96 sysmmu_off(SYSMMU_TV);
102 int s5p_tvout_map_resource_mem(
103 struct platform_device *pdev, char *name,
104 void __iomem **base, struct resource **res)
107 void __iomem *tmp_base;
108 struct resource *tmp_res;
110 tmp_res = platform_get_resource_byname(pdev, IORESOURCE_MEM, name);
115 size = resource_size(tmp_res);
117 tmp_res = request_mem_region(tmp_res->start, size, tmp_res->name);
120 tvout_err("%s: fail to get memory region\n", __func__);
121 goto err_on_request_mem_region;
124 tmp_base = ioremap(tmp_res->start, size);
127 tvout_err("%s: fail to ioremap address region\n", __func__);
136 release_resource(tmp_res);
139 err_on_request_mem_region:
143 tvout_err("%s: fail to get IORESOURCE_MEM for %s\n", __func__, name);
147 void s5p_tvout_unmap_resource_mem(
148 void __iomem *base, struct resource *res)
154 release_resource(res);
159 /* Libraries for runtime PM */
160 static struct device *s5p_tvout_dev;
163 void s5p_tvout_pm_runtime_enable(struct device *dev)
165 pm_runtime_enable(dev);
170 void s5p_tvout_pm_runtime_disable(struct device *dev)
172 pm_runtime_disable(dev);
175 void s5p_tvout_pm_runtime_get(void)
177 pm_runtime_get_sync(s5p_tvout_dev);
180 atomic_inc(&s5p_tvout_vcm_usage);
181 if (atomic_read(&s5p_tvout_vcm_usage) == 1)
182 s5p_tvout_vcm_activate();
186 void s5p_tvout_pm_runtime_put(void)
189 if (atomic_read(&s5p_tvout_vcm_usage) == 1)
190 s5p_tvout_vcm_deactivate();
192 atomic_dec(&s5p_tvout_vcm_usage);
195 pm_runtime_put_sync(s5p_tvout_dev);