blob: b967f6e8df552ee4909819800676a6ab8203f10a [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
30#include "dev.h"
Terje Bergstrom7ede0b02013-03-22 16:34:02 +020031#include "intr.h"
Terje Bergstrom75471682013-03-22 16:34:01 +020032#include "hw/host1x01.h"
33
34void host1x_sync_writel(struct host1x *host1x, u32 v, u32 r)
35{
36 void __iomem *sync_regs = host1x->regs + host1x->info->sync_offset;
37
38 writel(v, sync_regs + r);
39}
40
41u32 host1x_sync_readl(struct host1x *host1x, u32 r)
42{
43 void __iomem *sync_regs = host1x->regs + host1x->info->sync_offset;
44
45 return readl(sync_regs + r);
46}
47
48static const struct host1x_info host1x01_info = {
49 .nb_channels = 8,
50 .nb_pts = 32,
51 .nb_mlocks = 16,
52 .nb_bases = 8,
53 .init = host1x01_init,
54 .sync_offset = 0x3000,
55};
56
57static struct of_device_id host1x_of_match[] = {
58 { .compatible = "nvidia,tegra30-host1x", .data = &host1x01_info, },
59 { .compatible = "nvidia,tegra20-host1x", .data = &host1x01_info, },
60 { },
61};
62MODULE_DEVICE_TABLE(of, host1x_of_match);
63
64static int host1x_probe(struct platform_device *pdev)
65{
66 const struct of_device_id *id;
67 struct host1x *host;
68 struct resource *regs;
69 int syncpt_irq;
70 int err;
71
72 id = of_match_device(host1x_of_match, &pdev->dev);
73 if (!id)
74 return -EINVAL;
75
76 regs = platform_get_resource(pdev, IORESOURCE_MEM, 0);
77 if (!regs) {
78 dev_err(&pdev->dev, "failed to get registers\n");
79 return -ENXIO;
80 }
81
82 syncpt_irq = platform_get_irq(pdev, 0);
83 if (syncpt_irq < 0) {
84 dev_err(&pdev->dev, "failed to get IRQ\n");
85 return -ENXIO;
86 }
87
88 host = devm_kzalloc(&pdev->dev, sizeof(*host), GFP_KERNEL);
89 if (!host)
90 return -ENOMEM;
91
92 host->dev = &pdev->dev;
93 host->info = id->data;
94
95 /* set common host1x device data */
96 platform_set_drvdata(pdev, host);
97
98 host->regs = devm_ioremap_resource(&pdev->dev, regs);
99 if (IS_ERR(host->regs))
100 return PTR_ERR(host->regs);
101
102 if (host->info->init) {
103 err = host->info->init(host);
104 if (err)
105 return err;
106 }
107
108 host->clk = devm_clk_get(&pdev->dev, NULL);
109 if (IS_ERR(host->clk)) {
110 dev_err(&pdev->dev, "failed to get clock\n");
111 err = PTR_ERR(host->clk);
112 return err;
113 }
114
115 err = clk_prepare_enable(host->clk);
116 if (err < 0) {
117 dev_err(&pdev->dev, "failed to enable clock\n");
118 return err;
119 }
120
121 err = host1x_syncpt_init(host);
122 if (err) {
123 dev_err(&pdev->dev, "failed to initialize syncpts\n");
124 return err;
125 }
126
Terje Bergstrom7ede0b02013-03-22 16:34:02 +0200127 err = host1x_intr_init(host, syncpt_irq);
128 if (err) {
129 dev_err(&pdev->dev, "failed to initialize interrupts\n");
130 goto fail_deinit_syncpt;
131 }
132
Terje Bergstrom75471682013-03-22 16:34:01 +0200133 return 0;
Terje Bergstrom7ede0b02013-03-22 16:34:02 +0200134
135fail_deinit_syncpt:
136 host1x_syncpt_deinit(host);
137 return err;
Terje Bergstrom75471682013-03-22 16:34:01 +0200138}
139
140static int __exit host1x_remove(struct platform_device *pdev)
141{
142 struct host1x *host = platform_get_drvdata(pdev);
143
Terje Bergstrom7ede0b02013-03-22 16:34:02 +0200144 host1x_intr_deinit(host);
Terje Bergstrom75471682013-03-22 16:34:01 +0200145 host1x_syncpt_deinit(host);
146 clk_disable_unprepare(host->clk);
147
148 return 0;
149}
150
151static struct platform_driver platform_driver = {
152 .probe = host1x_probe,
153 .remove = __exit_p(host1x_remove),
154 .driver = {
155 .owner = THIS_MODULE,
156 .name = "tegra-host1x",
157 .of_match_table = host1x_of_match,
158 },
159};
160
161module_platform_driver(platform_driver);
162
163MODULE_AUTHOR("Terje Bergstrom <tbergstrom@nvidia.com>");
164MODULE_DESCRIPTION("Host1x driver for Tegra products");
165MODULE_LICENSE("GPL");