Terje Bergstrom | 7547168 | 2013-03-22 16:34:01 +0200 | [diff] [blame] | 1 | /* |
| 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 Bergstrom | 7ede0b0 | 2013-03-22 16:34:02 +0200 | [diff] [blame] | 31 | #include "intr.h" |
Terje Bergstrom | 6579324 | 2013-03-22 16:34:03 +0200 | [diff] [blame] | 32 | #include "channel.h" |
Terje Bergstrom | 6236451 | 2013-03-22 16:34:04 +0200 | [diff] [blame] | 33 | #include "debug.h" |
Terje Bergstrom | 7547168 | 2013-03-22 16:34:01 +0200 | [diff] [blame] | 34 | #include "hw/host1x01.h" |
Terje Bergstrom | 692e6d7 | 2013-03-22 16:34:07 +0200 | [diff] [blame] | 35 | #include "host1x_client.h" |
| 36 | |
| 37 | void host1x_set_drm_data(struct device *dev, void *data) |
| 38 | { |
| 39 | struct host1x *host1x = dev_get_drvdata(dev); |
| 40 | host1x->drm_data = data; |
| 41 | } |
| 42 | |
| 43 | void *host1x_get_drm_data(struct device *dev) |
| 44 | { |
| 45 | struct host1x *host1x = dev_get_drvdata(dev); |
Thierry Reding | 03c961b | 2013-09-03 08:50:39 +0200 | [diff] [blame] | 46 | return host1x ? host1x->drm_data : NULL; |
Terje Bergstrom | 692e6d7 | 2013-03-22 16:34:07 +0200 | [diff] [blame] | 47 | } |
Terje Bergstrom | 7547168 | 2013-03-22 16:34:01 +0200 | [diff] [blame] | 48 | |
| 49 | void host1x_sync_writel(struct host1x *host1x, u32 v, u32 r) |
| 50 | { |
| 51 | void __iomem *sync_regs = host1x->regs + host1x->info->sync_offset; |
| 52 | |
| 53 | writel(v, sync_regs + r); |
| 54 | } |
| 55 | |
| 56 | u32 host1x_sync_readl(struct host1x *host1x, u32 r) |
| 57 | { |
| 58 | void __iomem *sync_regs = host1x->regs + host1x->info->sync_offset; |
| 59 | |
| 60 | return readl(sync_regs + r); |
| 61 | } |
| 62 | |
Terje Bergstrom | 6579324 | 2013-03-22 16:34:03 +0200 | [diff] [blame] | 63 | void host1x_ch_writel(struct host1x_channel *ch, u32 v, u32 r) |
| 64 | { |
| 65 | writel(v, ch->regs + r); |
| 66 | } |
| 67 | |
| 68 | u32 host1x_ch_readl(struct host1x_channel *ch, u32 r) |
| 69 | { |
| 70 | return readl(ch->regs + r); |
| 71 | } |
| 72 | |
Terje Bergstrom | 7547168 | 2013-03-22 16:34:01 +0200 | [diff] [blame] | 73 | static const struct host1x_info host1x01_info = { |
| 74 | .nb_channels = 8, |
| 75 | .nb_pts = 32, |
| 76 | .nb_mlocks = 16, |
| 77 | .nb_bases = 8, |
| 78 | .init = host1x01_init, |
| 79 | .sync_offset = 0x3000, |
| 80 | }; |
| 81 | |
| 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, }, |
| 85 | { }, |
| 86 | }; |
| 87 | MODULE_DEVICE_TABLE(of, host1x_of_match); |
| 88 | |
| 89 | static int host1x_probe(struct platform_device *pdev) |
| 90 | { |
| 91 | const struct of_device_id *id; |
| 92 | struct host1x *host; |
| 93 | struct resource *regs; |
| 94 | int syncpt_irq; |
| 95 | int err; |
| 96 | |
| 97 | id = of_match_device(host1x_of_match, &pdev->dev); |
| 98 | if (!id) |
| 99 | return -EINVAL; |
| 100 | |
| 101 | regs = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 102 | if (!regs) { |
| 103 | dev_err(&pdev->dev, "failed to get registers\n"); |
| 104 | return -ENXIO; |
| 105 | } |
| 106 | |
| 107 | syncpt_irq = platform_get_irq(pdev, 0); |
| 108 | if (syncpt_irq < 0) { |
| 109 | dev_err(&pdev->dev, "failed to get IRQ\n"); |
| 110 | return -ENXIO; |
| 111 | } |
| 112 | |
| 113 | host = devm_kzalloc(&pdev->dev, sizeof(*host), GFP_KERNEL); |
| 114 | if (!host) |
| 115 | return -ENOMEM; |
| 116 | |
| 117 | host->dev = &pdev->dev; |
| 118 | host->info = id->data; |
| 119 | |
| 120 | /* set common host1x device data */ |
| 121 | platform_set_drvdata(pdev, host); |
| 122 | |
| 123 | host->regs = devm_ioremap_resource(&pdev->dev, regs); |
| 124 | if (IS_ERR(host->regs)) |
| 125 | return PTR_ERR(host->regs); |
| 126 | |
| 127 | if (host->info->init) { |
| 128 | err = host->info->init(host); |
| 129 | if (err) |
| 130 | return err; |
| 131 | } |
| 132 | |
| 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); |
| 137 | return err; |
| 138 | } |
| 139 | |
Terje Bergstrom | 6579324 | 2013-03-22 16:34:03 +0200 | [diff] [blame] | 140 | err = host1x_channel_list_init(host); |
| 141 | if (err) { |
| 142 | dev_err(&pdev->dev, "failed to initialize channel list\n"); |
| 143 | return err; |
| 144 | } |
| 145 | |
Terje Bergstrom | 7547168 | 2013-03-22 16:34:01 +0200 | [diff] [blame] | 146 | err = clk_prepare_enable(host->clk); |
| 147 | if (err < 0) { |
| 148 | dev_err(&pdev->dev, "failed to enable clock\n"); |
| 149 | return err; |
| 150 | } |
| 151 | |
| 152 | err = host1x_syncpt_init(host); |
| 153 | if (err) { |
| 154 | dev_err(&pdev->dev, "failed to initialize syncpts\n"); |
| 155 | return err; |
| 156 | } |
| 157 | |
Terje Bergstrom | 7ede0b0 | 2013-03-22 16:34:02 +0200 | [diff] [blame] | 158 | err = host1x_intr_init(host, syncpt_irq); |
| 159 | if (err) { |
| 160 | dev_err(&pdev->dev, "failed to initialize interrupts\n"); |
| 161 | goto fail_deinit_syncpt; |
| 162 | } |
| 163 | |
Terje Bergstrom | 6236451 | 2013-03-22 16:34:04 +0200 | [diff] [blame] | 164 | host1x_debug_init(host); |
| 165 | |
Thierry Reding | 386a2a7 | 2013-09-24 13:22:17 +0200 | [diff] [blame] | 166 | tegra_drm_alloc(pdev); |
Terje Bergstrom | 692e6d7 | 2013-03-22 16:34:07 +0200 | [diff] [blame] | 167 | |
Terje Bergstrom | 7547168 | 2013-03-22 16:34:01 +0200 | [diff] [blame] | 168 | return 0; |
Terje Bergstrom | 7ede0b0 | 2013-03-22 16:34:02 +0200 | [diff] [blame] | 169 | |
| 170 | fail_deinit_syncpt: |
| 171 | host1x_syncpt_deinit(host); |
| 172 | return err; |
Terje Bergstrom | 7547168 | 2013-03-22 16:34:01 +0200 | [diff] [blame] | 173 | } |
| 174 | |
Thierry Reding | 452e7f0 | 2013-09-25 18:33:31 +0200 | [diff] [blame^] | 175 | static int host1x_remove(struct platform_device *pdev) |
Terje Bergstrom | 7547168 | 2013-03-22 16:34:01 +0200 | [diff] [blame] | 176 | { |
| 177 | struct host1x *host = platform_get_drvdata(pdev); |
| 178 | |
Terje Bergstrom | 7ede0b0 | 2013-03-22 16:34:02 +0200 | [diff] [blame] | 179 | host1x_intr_deinit(host); |
Terje Bergstrom | 7547168 | 2013-03-22 16:34:01 +0200 | [diff] [blame] | 180 | host1x_syncpt_deinit(host); |
| 181 | clk_disable_unprepare(host->clk); |
| 182 | |
| 183 | return 0; |
| 184 | } |
| 185 | |
Terje Bergstrom | 692e6d7 | 2013-03-22 16:34:07 +0200 | [diff] [blame] | 186 | static struct platform_driver tegra_host1x_driver = { |
Terje Bergstrom | 7547168 | 2013-03-22 16:34:01 +0200 | [diff] [blame] | 187 | .driver = { |
Terje Bergstrom | 7547168 | 2013-03-22 16:34:01 +0200 | [diff] [blame] | 188 | .name = "tegra-host1x", |
| 189 | .of_match_table = host1x_of_match, |
| 190 | }, |
Thierry Reding | 452e7f0 | 2013-09-25 18:33:31 +0200 | [diff] [blame^] | 191 | .probe = host1x_probe, |
| 192 | .remove = host1x_remove, |
Terje Bergstrom | 7547168 | 2013-03-22 16:34:01 +0200 | [diff] [blame] | 193 | }; |
| 194 | |
Terje Bergstrom | 692e6d7 | 2013-03-22 16:34:07 +0200 | [diff] [blame] | 195 | static int __init tegra_host1x_init(void) |
| 196 | { |
| 197 | int err; |
Terje Bergstrom | 7547168 | 2013-03-22 16:34:01 +0200 | [diff] [blame] | 198 | |
Terje Bergstrom | 692e6d7 | 2013-03-22 16:34:07 +0200 | [diff] [blame] | 199 | err = platform_driver_register(&tegra_host1x_driver); |
| 200 | if (err < 0) |
| 201 | return err; |
| 202 | |
| 203 | #ifdef CONFIG_DRM_TEGRA |
| 204 | err = platform_driver_register(&tegra_dc_driver); |
| 205 | if (err < 0) |
| 206 | goto unregister_host1x; |
| 207 | |
| 208 | err = platform_driver_register(&tegra_hdmi_driver); |
| 209 | if (err < 0) |
| 210 | goto unregister_dc; |
Terje Bergstrom | d43f81c | 2013-03-22 16:34:09 +0200 | [diff] [blame] | 211 | |
| 212 | err = platform_driver_register(&tegra_gr2d_driver); |
| 213 | if (err < 0) |
| 214 | goto unregister_hdmi; |
Terje Bergstrom | 692e6d7 | 2013-03-22 16:34:07 +0200 | [diff] [blame] | 215 | #endif |
| 216 | |
| 217 | return 0; |
| 218 | |
| 219 | #ifdef CONFIG_DRM_TEGRA |
Terje Bergstrom | d43f81c | 2013-03-22 16:34:09 +0200 | [diff] [blame] | 220 | unregister_hdmi: |
| 221 | platform_driver_unregister(&tegra_hdmi_driver); |
Terje Bergstrom | 692e6d7 | 2013-03-22 16:34:07 +0200 | [diff] [blame] | 222 | unregister_dc: |
| 223 | platform_driver_unregister(&tegra_dc_driver); |
| 224 | unregister_host1x: |
| 225 | platform_driver_unregister(&tegra_host1x_driver); |
| 226 | return err; |
| 227 | #endif |
| 228 | } |
| 229 | module_init(tegra_host1x_init); |
| 230 | |
| 231 | static void __exit tegra_host1x_exit(void) |
| 232 | { |
| 233 | #ifdef CONFIG_DRM_TEGRA |
Terje Bergstrom | d43f81c | 2013-03-22 16:34:09 +0200 | [diff] [blame] | 234 | platform_driver_unregister(&tegra_gr2d_driver); |
Terje Bergstrom | 692e6d7 | 2013-03-22 16:34:07 +0200 | [diff] [blame] | 235 | platform_driver_unregister(&tegra_hdmi_driver); |
| 236 | platform_driver_unregister(&tegra_dc_driver); |
| 237 | #endif |
| 238 | platform_driver_unregister(&tegra_host1x_driver); |
| 239 | } |
| 240 | module_exit(tegra_host1x_exit); |
| 241 | |
| 242 | MODULE_AUTHOR("Thierry Reding <thierry.reding@avionic-design.de>"); |
Terje Bergstrom | 7547168 | 2013-03-22 16:34:01 +0200 | [diff] [blame] | 243 | MODULE_AUTHOR("Terje Bergstrom <tbergstrom@nvidia.com>"); |
| 244 | MODULE_DESCRIPTION("Host1x driver for Tegra products"); |
| 245 | MODULE_LICENSE("GPL"); |