blob: 314bf3718cc799b01462dd2cee678dcec604632e [file] [log] [blame]
Terje Bergstrom75471682013-03-22 16:34:01 +02001/*
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
Thierry Reding776dc382013-10-14 14:43:22 +020030#include "bus.h"
Terje Bergstrom75471682013-03-22 16:34:01 +020031#include "dev.h"
Terje Bergstrom7ede0b02013-03-22 16:34:02 +020032#include "intr.h"
Terje Bergstrom65793242013-03-22 16:34:03 +020033#include "channel.h"
Terje Bergstrom62364512013-03-22 16:34:04 +020034#include "debug.h"
Terje Bergstrom75471682013-03-22 16:34:01 +020035#include "hw/host1x01.h"
Thierry Reding5407f312013-09-30 14:17:39 +020036#include "hw/host1x02.h"
Thierry Redinge6fff4a2013-11-15 14:58:05 +010037#include "hw/host1x04.h"
Thierry Redinga1347892015-03-23 10:46:28 +010038#include "hw/host1x05.h"
Terje Bergstrom75471682013-03-22 16:34:01 +020039
40void host1x_sync_writel(struct host1x *host1x, u32 v, u32 r)
41{
42 void __iomem *sync_regs = host1x->regs + host1x->info->sync_offset;
43
44 writel(v, sync_regs + r);
45}
46
47u32 host1x_sync_readl(struct host1x *host1x, u32 r)
48{
49 void __iomem *sync_regs = host1x->regs + host1x->info->sync_offset;
50
51 return readl(sync_regs + r);
52}
53
Terje Bergstrom65793242013-03-22 16:34:03 +020054void host1x_ch_writel(struct host1x_channel *ch, u32 v, u32 r)
55{
56 writel(v, ch->regs + r);
57}
58
59u32 host1x_ch_readl(struct host1x_channel *ch, u32 r)
60{
61 return readl(ch->regs + r);
62}
63
Terje Bergstrom75471682013-03-22 16:34:01 +020064static const struct host1x_info host1x01_info = {
65 .nb_channels = 8,
66 .nb_pts = 32,
67 .nb_mlocks = 16,
68 .nb_bases = 8,
69 .init = host1x01_init,
70 .sync_offset = 0x3000,
71};
72
Thierry Reding5407f312013-09-30 14:17:39 +020073static const struct host1x_info host1x02_info = {
74 .nb_channels = 9,
75 .nb_pts = 32,
76 .nb_mlocks = 16,
77 .nb_bases = 12,
78 .init = host1x02_init,
79 .sync_offset = 0x3000,
80};
81
Thierry Redinge6fff4a2013-11-15 14:58:05 +010082static const struct host1x_info host1x04_info = {
83 .nb_channels = 12,
84 .nb_pts = 192,
85 .nb_mlocks = 16,
86 .nb_bases = 64,
87 .init = host1x04_init,
88 .sync_offset = 0x2100,
89};
90
Thierry Redinga1347892015-03-23 10:46:28 +010091static const struct host1x_info host1x05_info = {
92 .nb_channels = 14,
93 .nb_pts = 192,
94 .nb_mlocks = 16,
95 .nb_bases = 64,
96 .init = host1x05_init,
97 .sync_offset = 0x2100,
98};
99
Terje Bergstrom75471682013-03-22 16:34:01 +0200100static struct of_device_id host1x_of_match[] = {
Thierry Redinga1347892015-03-23 10:46:28 +0100101 { .compatible = "nvidia,tegra210-host1x", .data = &host1x05_info, },
Thierry Redinge6fff4a2013-11-15 14:58:05 +0100102 { .compatible = "nvidia,tegra124-host1x", .data = &host1x04_info, },
Thierry Reding5407f312013-09-30 14:17:39 +0200103 { .compatible = "nvidia,tegra114-host1x", .data = &host1x02_info, },
Terje Bergstrom75471682013-03-22 16:34:01 +0200104 { .compatible = "nvidia,tegra30-host1x", .data = &host1x01_info, },
105 { .compatible = "nvidia,tegra20-host1x", .data = &host1x01_info, },
106 { },
107};
108MODULE_DEVICE_TABLE(of, host1x_of_match);
109
110static int host1x_probe(struct platform_device *pdev)
111{
112 const struct of_device_id *id;
113 struct host1x *host;
114 struct resource *regs;
115 int syncpt_irq;
116 int err;
117
118 id = of_match_device(host1x_of_match, &pdev->dev);
119 if (!id)
120 return -EINVAL;
121
122 regs = platform_get_resource(pdev, IORESOURCE_MEM, 0);
123 if (!regs) {
124 dev_err(&pdev->dev, "failed to get registers\n");
125 return -ENXIO;
126 }
127
128 syncpt_irq = platform_get_irq(pdev, 0);
129 if (syncpt_irq < 0) {
130 dev_err(&pdev->dev, "failed to get IRQ\n");
131 return -ENXIO;
132 }
133
134 host = devm_kzalloc(&pdev->dev, sizeof(*host), GFP_KERNEL);
135 if (!host)
136 return -ENOMEM;
137
Thierry Reding776dc382013-10-14 14:43:22 +0200138 mutex_init(&host->devices_lock);
139 INIT_LIST_HEAD(&host->devices);
140 INIT_LIST_HEAD(&host->list);
Terje Bergstrom75471682013-03-22 16:34:01 +0200141 host->dev = &pdev->dev;
142 host->info = id->data;
143
144 /* set common host1x device data */
145 platform_set_drvdata(pdev, host);
146
147 host->regs = devm_ioremap_resource(&pdev->dev, regs);
148 if (IS_ERR(host->regs))
149 return PTR_ERR(host->regs);
150
151 if (host->info->init) {
152 err = host->info->init(host);
153 if (err)
154 return err;
155 }
156
157 host->clk = devm_clk_get(&pdev->dev, NULL);
158 if (IS_ERR(host->clk)) {
159 dev_err(&pdev->dev, "failed to get clock\n");
160 err = PTR_ERR(host->clk);
161 return err;
162 }
163
Terje Bergstrom65793242013-03-22 16:34:03 +0200164 err = host1x_channel_list_init(host);
165 if (err) {
166 dev_err(&pdev->dev, "failed to initialize channel list\n");
167 return err;
168 }
169
Terje Bergstrom75471682013-03-22 16:34:01 +0200170 err = clk_prepare_enable(host->clk);
171 if (err < 0) {
172 dev_err(&pdev->dev, "failed to enable clock\n");
173 return err;
174 }
175
176 err = host1x_syncpt_init(host);
177 if (err) {
178 dev_err(&pdev->dev, "failed to initialize syncpts\n");
Wei Yongjun9c78c4c2013-10-21 13:37:31 +0800179 goto fail_unprepare_disable;
Terje Bergstrom75471682013-03-22 16:34:01 +0200180 }
181
Terje Bergstrom7ede0b02013-03-22 16:34:02 +0200182 err = host1x_intr_init(host, syncpt_irq);
183 if (err) {
184 dev_err(&pdev->dev, "failed to initialize interrupts\n");
185 goto fail_deinit_syncpt;
186 }
187
Terje Bergstrom62364512013-03-22 16:34:04 +0200188 host1x_debug_init(host);
189
Thierry Reding776dc382013-10-14 14:43:22 +0200190 err = host1x_register(host);
191 if (err < 0)
192 goto fail_deinit_intr;
Terje Bergstrom692e6d72013-03-22 16:34:07 +0200193
Terje Bergstrom75471682013-03-22 16:34:01 +0200194 return 0;
Terje Bergstrom7ede0b02013-03-22 16:34:02 +0200195
Thierry Reding776dc382013-10-14 14:43:22 +0200196fail_deinit_intr:
197 host1x_intr_deinit(host);
Terje Bergstrom7ede0b02013-03-22 16:34:02 +0200198fail_deinit_syncpt:
199 host1x_syncpt_deinit(host);
Wei Yongjun9c78c4c2013-10-21 13:37:31 +0800200fail_unprepare_disable:
201 clk_disable_unprepare(host->clk);
Terje Bergstrom7ede0b02013-03-22 16:34:02 +0200202 return err;
Terje Bergstrom75471682013-03-22 16:34:01 +0200203}
204
Thierry Reding452e7f02013-09-25 18:33:31 +0200205static int host1x_remove(struct platform_device *pdev)
Terje Bergstrom75471682013-03-22 16:34:01 +0200206{
207 struct host1x *host = platform_get_drvdata(pdev);
208
Thierry Reding776dc382013-10-14 14:43:22 +0200209 host1x_unregister(host);
Terje Bergstrom7ede0b02013-03-22 16:34:02 +0200210 host1x_intr_deinit(host);
Terje Bergstrom75471682013-03-22 16:34:01 +0200211 host1x_syncpt_deinit(host);
212 clk_disable_unprepare(host->clk);
213
214 return 0;
215}
216
Terje Bergstrom692e6d72013-03-22 16:34:07 +0200217static struct platform_driver tegra_host1x_driver = {
Terje Bergstrom75471682013-03-22 16:34:01 +0200218 .driver = {
Terje Bergstrom75471682013-03-22 16:34:01 +0200219 .name = "tegra-host1x",
220 .of_match_table = host1x_of_match,
221 },
Thierry Reding452e7f02013-09-25 18:33:31 +0200222 .probe = host1x_probe,
223 .remove = host1x_remove,
Terje Bergstrom75471682013-03-22 16:34:01 +0200224};
225
Thierry Reding28fae812015-12-02 17:24:20 +0100226static struct platform_driver * const drivers[] = {
227 &tegra_host1x_driver,
228 &tegra_mipi_driver,
229};
230
Terje Bergstrom692e6d72013-03-22 16:34:07 +0200231static int __init tegra_host1x_init(void)
232{
233 int err;
Terje Bergstrom75471682013-03-22 16:34:01 +0200234
Thierry Redingf4c5cf82014-12-18 15:29:14 +0100235 err = bus_register(&host1x_bus_type);
Terje Bergstrom692e6d72013-03-22 16:34:07 +0200236 if (err < 0)
237 return err;
238
Thierry Reding28fae812015-12-02 17:24:20 +0100239 err = platform_register_drivers(drivers, ARRAY_SIZE(drivers));
Thierry Reding4de6a2d2013-09-02 09:48:53 +0200240 if (err < 0)
Thierry Reding28fae812015-12-02 17:24:20 +0100241 bus_unregister(&host1x_bus_type);
Thierry Reding4de6a2d2013-09-02 09:48:53 +0200242
Thierry Reding4de6a2d2013-09-02 09:48:53 +0200243 return err;
Terje Bergstrom692e6d72013-03-22 16:34:07 +0200244}
245module_init(tegra_host1x_init);
246
247static void __exit tegra_host1x_exit(void)
248{
Thierry Reding28fae812015-12-02 17:24:20 +0100249 platform_unregister_drivers(drivers, ARRAY_SIZE(drivers));
Thierry Redingf4c5cf82014-12-18 15:29:14 +0100250 bus_unregister(&host1x_bus_type);
Terje Bergstrom692e6d72013-03-22 16:34:07 +0200251}
252module_exit(tegra_host1x_exit);
253
254MODULE_AUTHOR("Thierry Reding <thierry.reding@avionic-design.de>");
Terje Bergstrom75471682013-03-22 16:34:01 +0200255MODULE_AUTHOR("Terje Bergstrom <tbergstrom@nvidia.com>");
256MODULE_DESCRIPTION("Host1x driver for Tegra products");
257MODULE_LICENSE("GPL");