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"
37 void host1x_sync_writel(struct host1x *host1x, u32 v, u32 r)
39 void __iomem *sync_regs = host1x->regs + host1x->info->sync_offset;
41 writel(v, sync_regs + r);
44 u32 host1x_sync_readl(struct host1x *host1x, u32 r)
46 void __iomem *sync_regs = host1x->regs + host1x->info->sync_offset;
48 return readl(sync_regs + r);
51 void host1x_ch_writel(struct host1x_channel *ch, u32 v, u32 r)
53 writel(v, ch->regs + r);
56 u32 host1x_ch_readl(struct host1x_channel *ch, u32 r)
58 return readl(ch->regs + r);
61 static const struct host1x_info host1x01_info = {
66 .init = host1x01_init,
67 .sync_offset = 0x3000,
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, },
75 MODULE_DEVICE_TABLE(of, host1x_of_match);
77 static int host1x_probe(struct platform_device *pdev)
79 const struct of_device_id *id;
81 struct resource *regs;
85 id = of_match_device(host1x_of_match, &pdev->dev);
89 regs = platform_get_resource(pdev, IORESOURCE_MEM, 0);
91 dev_err(&pdev->dev, "failed to get registers\n");
95 syncpt_irq = platform_get_irq(pdev, 0);
97 dev_err(&pdev->dev, "failed to get IRQ\n");
101 host = devm_kzalloc(&pdev->dev, sizeof(*host), GFP_KERNEL);
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;
111 /* set common host1x device data */
112 platform_set_drvdata(pdev, host);
114 host->regs = devm_ioremap_resource(&pdev->dev, regs);
115 if (IS_ERR(host->regs))
116 return PTR_ERR(host->regs);
118 if (host->info->init) {
119 err = host->info->init(host);
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);
131 err = host1x_channel_list_init(host);
133 dev_err(&pdev->dev, "failed to initialize channel list\n");
137 err = clk_prepare_enable(host->clk);
139 dev_err(&pdev->dev, "failed to enable clock\n");
143 err = host1x_syncpt_init(host);
145 dev_err(&pdev->dev, "failed to initialize syncpts\n");
149 err = host1x_intr_init(host, syncpt_irq);
151 dev_err(&pdev->dev, "failed to initialize interrupts\n");
152 goto fail_deinit_syncpt;
155 host1x_debug_init(host);
157 err = host1x_register(host);
159 goto fail_deinit_intr;
164 host1x_intr_deinit(host);
166 host1x_syncpt_deinit(host);
170 static int host1x_remove(struct platform_device *pdev)
172 struct host1x *host = platform_get_drvdata(pdev);
174 host1x_unregister(host);
175 host1x_intr_deinit(host);
176 host1x_syncpt_deinit(host);
177 clk_disable_unprepare(host->clk);
182 static struct platform_driver tegra_host1x_driver = {
184 .name = "tegra-host1x",
185 .of_match_table = host1x_of_match,
187 .probe = host1x_probe,
188 .remove = host1x_remove,
191 static int __init tegra_host1x_init(void)
195 err = host1x_bus_init();
199 err = platform_driver_register(&tegra_host1x_driver);
207 module_init(tegra_host1x_init);
209 static void __exit tegra_host1x_exit(void)
211 platform_driver_unregister(&tegra_host1x_driver);
214 module_exit(tegra_host1x_exit);
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");