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>
34 #include "hw/host1x01.h"
35 #include "host1x_client.h"
37 void host1x_set_drm_data(struct device *dev, void *data)
39 struct host1x *host1x = dev_get_drvdata(dev);
40 host1x->drm_data = data;
43 void *host1x_get_drm_data(struct device *dev)
45 struct host1x *host1x = dev_get_drvdata(dev);
46 return host1x->drm_data;
49 void host1x_sync_writel(struct host1x *host1x, u32 v, u32 r)
51 void __iomem *sync_regs = host1x->regs + host1x->info->sync_offset;
53 writel(v, sync_regs + r);
56 u32 host1x_sync_readl(struct host1x *host1x, u32 r)
58 void __iomem *sync_regs = host1x->regs + host1x->info->sync_offset;
60 return readl(sync_regs + r);
63 void host1x_ch_writel(struct host1x_channel *ch, u32 v, u32 r)
65 writel(v, ch->regs + r);
68 u32 host1x_ch_readl(struct host1x_channel *ch, u32 r)
70 return readl(ch->regs + r);
73 static const struct host1x_info host1x01_info = {
78 .init = host1x01_init,
79 .sync_offset = 0x3000,
82 static struct of_device_id host1x_of_match[] = {
83 { .compatible = "nvidia,tegra30-host1x", .data = &host1x01_info, },
84 { .compatible = "nvidia,tegra20-host1x", .data = &host1x01_info, },
87 MODULE_DEVICE_TABLE(of, host1x_of_match);
89 static int host1x_probe(struct platform_device *pdev)
91 const struct of_device_id *id;
93 struct resource *regs;
97 id = of_match_device(host1x_of_match, &pdev->dev);
101 regs = platform_get_resource(pdev, IORESOURCE_MEM, 0);
103 dev_err(&pdev->dev, "failed to get registers\n");
107 syncpt_irq = platform_get_irq(pdev, 0);
108 if (syncpt_irq < 0) {
109 dev_err(&pdev->dev, "failed to get IRQ\n");
113 host = devm_kzalloc(&pdev->dev, sizeof(*host), GFP_KERNEL);
117 host->dev = &pdev->dev;
118 host->info = id->data;
120 /* set common host1x device data */
121 platform_set_drvdata(pdev, host);
123 host->regs = devm_ioremap_resource(&pdev->dev, regs);
124 if (IS_ERR(host->regs))
125 return PTR_ERR(host->regs);
127 if (host->info->init) {
128 err = host->info->init(host);
133 host->clk = devm_clk_get(&pdev->dev, NULL);
134 if (IS_ERR(host->clk)) {
135 dev_err(&pdev->dev, "failed to get clock\n");
136 err = PTR_ERR(host->clk);
140 err = host1x_channel_list_init(host);
142 dev_err(&pdev->dev, "failed to initialize channel list\n");
146 err = clk_prepare_enable(host->clk);
148 dev_err(&pdev->dev, "failed to enable clock\n");
152 err = host1x_syncpt_init(host);
154 dev_err(&pdev->dev, "failed to initialize syncpts\n");
158 err = host1x_intr_init(host, syncpt_irq);
160 dev_err(&pdev->dev, "failed to initialize interrupts\n");
161 goto fail_deinit_syncpt;
164 host1x_debug_init(host);
166 host1x_drm_alloc(pdev);
171 host1x_syncpt_deinit(host);
175 static int __exit host1x_remove(struct platform_device *pdev)
177 struct host1x *host = platform_get_drvdata(pdev);
179 host1x_intr_deinit(host);
180 host1x_syncpt_deinit(host);
181 clk_disable_unprepare(host->clk);
186 static struct platform_driver tegra_host1x_driver = {
187 .probe = host1x_probe,
188 .remove = __exit_p(host1x_remove),
190 .owner = THIS_MODULE,
191 .name = "tegra-host1x",
192 .of_match_table = host1x_of_match,
196 static int __init tegra_host1x_init(void)
200 err = platform_driver_register(&tegra_host1x_driver);
204 #ifdef CONFIG_DRM_TEGRA
205 err = platform_driver_register(&tegra_dc_driver);
207 goto unregister_host1x;
209 err = platform_driver_register(&tegra_hdmi_driver);
213 err = platform_driver_register(&tegra_gr2d_driver);
215 goto unregister_hdmi;
220 #ifdef CONFIG_DRM_TEGRA
222 platform_driver_unregister(&tegra_hdmi_driver);
224 platform_driver_unregister(&tegra_dc_driver);
226 platform_driver_unregister(&tegra_host1x_driver);
230 module_init(tegra_host1x_init);
232 static void __exit tegra_host1x_exit(void)
234 #ifdef CONFIG_DRM_TEGRA
235 platform_driver_unregister(&tegra_gr2d_driver);
236 platform_driver_unregister(&tegra_hdmi_driver);
237 platform_driver_unregister(&tegra_dc_driver);
239 platform_driver_unregister(&tegra_host1x_driver);
241 module_exit(tegra_host1x_exit);
245 MODULE_DESCRIPTION("Host1x driver for Tegra products");
246 MODULE_LICENSE("GPL");