]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blob - drivers/gpu/host1x/dev.c
drm/tegra: Move subdevice infrastructure to host1x
[mirror_ubuntu-bionic-kernel.git] / drivers / gpu / host1x / dev.c
1 /*
2 * Tegra host1x driver
3 *
4 * Copyright (c) 2010-2013, NVIDIA Corporation.
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms and conditions of the GNU General Public License,
8 * version 2, as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 * more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19 #include <linux/module.h>
20 #include <linux/list.h>
21 #include <linux/slab.h>
22 #include <linux/of.h>
23 #include <linux/of_device.h>
24 #include <linux/clk.h>
25 #include <linux/io.h>
26
27 #define CREATE_TRACE_POINTS
28 #include <trace/events/host1x.h>
29
30 #include "bus.h"
31 #include "dev.h"
32 #include "intr.h"
33 #include "channel.h"
34 #include "debug.h"
35 #include "hw/host1x01.h"
36
37 void host1x_sync_writel(struct host1x *host1x, u32 v, u32 r)
38 {
39 void __iomem *sync_regs = host1x->regs + host1x->info->sync_offset;
40
41 writel(v, sync_regs + r);
42 }
43
44 u32 host1x_sync_readl(struct host1x *host1x, u32 r)
45 {
46 void __iomem *sync_regs = host1x->regs + host1x->info->sync_offset;
47
48 return readl(sync_regs + r);
49 }
50
51 void host1x_ch_writel(struct host1x_channel *ch, u32 v, u32 r)
52 {
53 writel(v, ch->regs + r);
54 }
55
56 u32 host1x_ch_readl(struct host1x_channel *ch, u32 r)
57 {
58 return readl(ch->regs + r);
59 }
60
61 static const struct host1x_info host1x01_info = {
62 .nb_channels = 8,
63 .nb_pts = 32,
64 .nb_mlocks = 16,
65 .nb_bases = 8,
66 .init = host1x01_init,
67 .sync_offset = 0x3000,
68 };
69
70 static struct of_device_id host1x_of_match[] = {
71 { .compatible = "nvidia,tegra30-host1x", .data = &host1x01_info, },
72 { .compatible = "nvidia,tegra20-host1x", .data = &host1x01_info, },
73 { },
74 };
75 MODULE_DEVICE_TABLE(of, host1x_of_match);
76
77 static int host1x_probe(struct platform_device *pdev)
78 {
79 const struct of_device_id *id;
80 struct host1x *host;
81 struct resource *regs;
82 int syncpt_irq;
83 int err;
84
85 id = of_match_device(host1x_of_match, &pdev->dev);
86 if (!id)
87 return -EINVAL;
88
89 regs = platform_get_resource(pdev, IORESOURCE_MEM, 0);
90 if (!regs) {
91 dev_err(&pdev->dev, "failed to get registers\n");
92 return -ENXIO;
93 }
94
95 syncpt_irq = platform_get_irq(pdev, 0);
96 if (syncpt_irq < 0) {
97 dev_err(&pdev->dev, "failed to get IRQ\n");
98 return -ENXIO;
99 }
100
101 host = devm_kzalloc(&pdev->dev, sizeof(*host), GFP_KERNEL);
102 if (!host)
103 return -ENOMEM;
104
105 mutex_init(&host->devices_lock);
106 INIT_LIST_HEAD(&host->devices);
107 INIT_LIST_HEAD(&host->list);
108 host->dev = &pdev->dev;
109 host->info = id->data;
110
111 /* set common host1x device data */
112 platform_set_drvdata(pdev, host);
113
114 host->regs = devm_ioremap_resource(&pdev->dev, regs);
115 if (IS_ERR(host->regs))
116 return PTR_ERR(host->regs);
117
118 if (host->info->init) {
119 err = host->info->init(host);
120 if (err)
121 return err;
122 }
123
124 host->clk = devm_clk_get(&pdev->dev, NULL);
125 if (IS_ERR(host->clk)) {
126 dev_err(&pdev->dev, "failed to get clock\n");
127 err = PTR_ERR(host->clk);
128 return err;
129 }
130
131 err = host1x_channel_list_init(host);
132 if (err) {
133 dev_err(&pdev->dev, "failed to initialize channel list\n");
134 return err;
135 }
136
137 err = clk_prepare_enable(host->clk);
138 if (err < 0) {
139 dev_err(&pdev->dev, "failed to enable clock\n");
140 return err;
141 }
142
143 err = host1x_syncpt_init(host);
144 if (err) {
145 dev_err(&pdev->dev, "failed to initialize syncpts\n");
146 return err;
147 }
148
149 err = host1x_intr_init(host, syncpt_irq);
150 if (err) {
151 dev_err(&pdev->dev, "failed to initialize interrupts\n");
152 goto fail_deinit_syncpt;
153 }
154
155 host1x_debug_init(host);
156
157 err = host1x_register(host);
158 if (err < 0)
159 goto fail_deinit_intr;
160
161 return 0;
162
163 fail_deinit_intr:
164 host1x_intr_deinit(host);
165 fail_deinit_syncpt:
166 host1x_syncpt_deinit(host);
167 return err;
168 }
169
170 static int host1x_remove(struct platform_device *pdev)
171 {
172 struct host1x *host = platform_get_drvdata(pdev);
173
174 host1x_unregister(host);
175 host1x_intr_deinit(host);
176 host1x_syncpt_deinit(host);
177 clk_disable_unprepare(host->clk);
178
179 return 0;
180 }
181
182 static struct platform_driver tegra_host1x_driver = {
183 .driver = {
184 .name = "tegra-host1x",
185 .of_match_table = host1x_of_match,
186 },
187 .probe = host1x_probe,
188 .remove = host1x_remove,
189 };
190
191 static int __init tegra_host1x_init(void)
192 {
193 int err;
194
195 err = host1x_bus_init();
196 if (err < 0)
197 return err;
198
199 err = platform_driver_register(&tegra_host1x_driver);
200 if (err < 0) {
201 host1x_bus_exit();
202 return err;
203 }
204
205 return 0;
206 }
207 module_init(tegra_host1x_init);
208
209 static void __exit tegra_host1x_exit(void)
210 {
211 platform_driver_unregister(&tegra_host1x_driver);
212 host1x_bus_exit();
213 }
214 module_exit(tegra_host1x_exit);
215
216 MODULE_AUTHOR("Thierry Reding <thierry.reding@avionic-design.de>");
217 MODULE_AUTHOR("Terje Bergstrom <tbergstrom@nvidia.com>");
218 MODULE_DESCRIPTION("Host1x driver for Tegra products");
219 MODULE_LICENSE("GPL");