4 * Copyright (c) 2010-2013, NVIDIA Corporation.
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.
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
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/>.
19 #include <linux/module.h>
20 #include <linux/list.h>
21 #include <linux/slab.h>
23 #include <linux/of_device.h>
24 #include <linux/clk.h>
27 #define CREATE_TRACE_POINTS
28 #include <trace/events/host1x.h>
35 #include "hw/host1x01.h"
36 #include "hw/host1x02.h"
37 #include "hw/host1x04.h"
38 #include "hw/host1x05.h"
40 void host1x_sync_writel(struct host1x *host1x, u32 v, u32 r)
42 void __iomem *sync_regs = host1x->regs + host1x->info->sync_offset;
44 writel(v, sync_regs + r);
47 u32 host1x_sync_readl(struct host1x *host1x, u32 r)
49 void __iomem *sync_regs = host1x->regs + host1x->info->sync_offset;
51 return readl(sync_regs + r);
54 void host1x_ch_writel(struct host1x_channel *ch, u32 v, u32 r)
56 writel(v, ch->regs + r);
59 u32 host1x_ch_readl(struct host1x_channel *ch, u32 r)
61 return readl(ch->regs + r);
64 static const struct host1x_info host1x01_info = {
69 .init = host1x01_init,
70 .sync_offset = 0x3000,
73 static const struct host1x_info host1x02_info = {
78 .init = host1x02_init,
79 .sync_offset = 0x3000,
82 static const struct host1x_info host1x04_info = {
87 .init = host1x04_init,
88 .sync_offset = 0x2100,
91 static const struct host1x_info host1x05_info = {
96 .init = host1x05_init,
97 .sync_offset = 0x2100,
100 static struct of_device_id host1x_of_match[] = {
101 { .compatible = "nvidia,tegra210-host1x", .data = &host1x05_info, },
102 { .compatible = "nvidia,tegra124-host1x", .data = &host1x04_info, },
103 { .compatible = "nvidia,tegra114-host1x", .data = &host1x02_info, },
104 { .compatible = "nvidia,tegra30-host1x", .data = &host1x01_info, },
105 { .compatible = "nvidia,tegra20-host1x", .data = &host1x01_info, },
108 MODULE_DEVICE_TABLE(of, host1x_of_match);
110 static int host1x_probe(struct platform_device *pdev)
112 const struct of_device_id *id;
114 struct resource *regs;
118 id = of_match_device(host1x_of_match, &pdev->dev);
122 regs = platform_get_resource(pdev, IORESOURCE_MEM, 0);
124 dev_err(&pdev->dev, "failed to get registers\n");
128 syncpt_irq = platform_get_irq(pdev, 0);
129 if (syncpt_irq < 0) {
130 dev_err(&pdev->dev, "failed to get IRQ\n");
134 host = devm_kzalloc(&pdev->dev, sizeof(*host), GFP_KERNEL);
138 mutex_init(&host->devices_lock);
139 INIT_LIST_HEAD(&host->devices);
140 INIT_LIST_HEAD(&host->list);
141 host->dev = &pdev->dev;
142 host->info = id->data;
144 /* set common host1x device data */
145 platform_set_drvdata(pdev, host);
147 host->regs = devm_ioremap_resource(&pdev->dev, regs);
148 if (IS_ERR(host->regs))
149 return PTR_ERR(host->regs);
151 if (host->info->init) {
152 err = host->info->init(host);
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);
164 err = host1x_channel_list_init(host);
166 dev_err(&pdev->dev, "failed to initialize channel list\n");
170 err = clk_prepare_enable(host->clk);
172 dev_err(&pdev->dev, "failed to enable clock\n");
176 err = host1x_syncpt_init(host);
178 dev_err(&pdev->dev, "failed to initialize syncpts\n");
179 goto fail_unprepare_disable;
182 err = host1x_intr_init(host, syncpt_irq);
184 dev_err(&pdev->dev, "failed to initialize interrupts\n");
185 goto fail_deinit_syncpt;
188 host1x_debug_init(host);
190 err = host1x_register(host);
192 goto fail_deinit_intr;
197 host1x_intr_deinit(host);
199 host1x_syncpt_deinit(host);
200 fail_unprepare_disable:
201 clk_disable_unprepare(host->clk);
205 static int host1x_remove(struct platform_device *pdev)
207 struct host1x *host = platform_get_drvdata(pdev);
209 host1x_unregister(host);
210 host1x_intr_deinit(host);
211 host1x_syncpt_deinit(host);
212 clk_disable_unprepare(host->clk);
217 static struct platform_driver tegra_host1x_driver = {
219 .name = "tegra-host1x",
220 .of_match_table = host1x_of_match,
222 .probe = host1x_probe,
223 .remove = host1x_remove,
226 static struct platform_driver * const drivers[] = {
227 &tegra_host1x_driver,
231 static int __init tegra_host1x_init(void)
235 err = bus_register(&host1x_bus_type);
239 err = platform_register_drivers(drivers, ARRAY_SIZE(drivers));
241 bus_unregister(&host1x_bus_type);
245 module_init(tegra_host1x_init);
247 static void __exit tegra_host1x_exit(void)
249 platform_unregister_drivers(drivers, ARRAY_SIZE(drivers));
250 bus_unregister(&host1x_bus_type);
252 module_exit(tegra_host1x_exit);
256 MODULE_DESCRIPTION("Host1x driver for Tegra products");
257 MODULE_LICENSE("GPL");