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