]> rtime.felk.cvut.cz Git - sojka/nv-tegra/linux-3.10.git/blob - drivers/media/platform/tegra/tpg/tpg.c
media: tegra_camera: add SoC fops for VI
[sojka/nv-tegra/linux-3.10.git] / drivers / media / platform / tegra / tpg / tpg.c
1 /*
2  * drivers/video/tegra/host/tpg/tpg.c
3  *
4  * Tegra VI test pattern generator driver
5  *
6  * Copyright (c) 2016, NVIDIA CORPORATION. All rights reserved.
7  *
8  * This program is free software; you can redistribute it and/or modify it
9  * under the terms and conditions of the GNU General Public License,
10  * version 2, as published by the Free Software Foundation.
11  *
12  * This program is distributed in the hope it will be useful, but WITHOUT
13  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
15  * more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
19  */
20
21 #include <linux/init.h>
22 #include <linux/export.h>
23 #include <linux/module.h>
24
25 #include "vi/vi.h"
26 #include "csi/csi.h"
27
28 #define TPG_CHANNELS 6
29
30 static struct tegra_csi_device tpg_csi;
31 static struct tegra_mc_vi tpg_mc_vi;
32
33 static int tpg_probe(struct vi *tegra_vi)
34 {
35         struct tegra_csi_device *csi = &tpg_csi;
36         struct tegra_mc_vi *mc_vi = &tpg_mc_vi;
37         struct platform_device *pdev = tegra_vi->ndev;
38         int ret;
39
40         /* Init CSI related media controller interface */
41         csi->num_ports = TPG_CHANNELS;
42         csi->pg_mode = TEGRA_VI_PG_PATCH;
43         ret = tegra_csi_media_controller_init(csi, pdev);
44         if (ret)
45                 return ret;
46
47         /* Init Tegra VI TPG channels */
48         mc_vi->vi = tegra_vi;
49         mc_vi->csi = csi;
50         mc_vi->reg = tegra_vi->reg;
51         mc_vi->pg_mode = TEGRA_VI_PG_PATCH;
52         mc_vi->num_channels = TPG_CHANNELS;
53         mc_vi->fops = tegra_vi->data->vi_fops;
54         ret = tegra_vi_media_controller_init(mc_vi, pdev);
55         if (ret)
56                 goto vi_mc_error;
57         return 0;
58
59 vi_mc_error:
60         tegra_csi_media_controller_remove(csi);
61         return ret;
62 }
63
64 static int __exit tpg_remove(struct vi *tegra_vi)
65 {
66         struct tegra_csi_device *csi = &tpg_csi;
67         struct tegra_mc_vi *mc_vi = &tpg_mc_vi;
68
69         tegra_csi_media_controller_remove(csi);
70         tegra_vi_channels_cleanup(mc_vi);
71         tegra_vi_v4l2_cleanup(mc_vi);
72
73         return 0;
74 }
75
76 static int __init tpg_init(void)
77 {
78         struct vi *tegra_vi = tegra_vi_get();
79         if (tegra_vi)
80                 return tpg_probe(tegra_vi);
81
82         return 0;
83 }
84
85 static void __exit tpg_exit(void)
86 {
87         struct vi *tegra_vi = tegra_vi_get();
88         if (tegra_vi)
89                 tpg_remove(tegra_vi);
90 }
91
92 module_init(tpg_init);
93 module_exit(tpg_exit);
94 MODULE_LICENSE("GPL v2");