Thomas Gleixner | d2912cb | 2019-06-04 10:11:33 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
Thierry Reding | 5f60ed0 | 2013-02-28 08:08:01 +0100 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2013 Avionic Design GmbH |
| 4 | * Copyright (C) 2013 NVIDIA Corporation |
Thierry Reding | 5f60ed0 | 2013-02-28 08:08:01 +0100 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #include <linux/clk.h> |
| 8 | #include <linux/host1x.h> |
Dmitry Osipenko | c9ac521 | 2018-05-04 02:47:21 +0300 | [diff] [blame] | 9 | #include <linux/iommu.h> |
Thierry Reding | 5f60ed0 | 2013-02-28 08:08:01 +0100 | [diff] [blame] | 10 | #include <linux/module.h> |
Thierry Reding | 33f150e | 2018-05-16 17:07:38 +0200 | [diff] [blame] | 11 | #include <linux/of_device.h> |
Thierry Reding | 5f60ed0 | 2013-02-28 08:08:01 +0100 | [diff] [blame] | 12 | #include <linux/platform_device.h> |
Stephen Warren | ca48080 | 2013-11-06 16:20:54 -0700 | [diff] [blame] | 13 | #include <linux/reset.h> |
Thierry Reding | 306a7f9 | 2014-07-17 13:17:24 +0200 | [diff] [blame] | 14 | |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 15 | #include <soc/tegra/pmc.h> |
Thierry Reding | 5f60ed0 | 2013-02-28 08:08:01 +0100 | [diff] [blame] | 16 | |
| 17 | #include "drm.h" |
| 18 | #include "gem.h" |
| 19 | #include "gr3d.h" |
| 20 | |
Thierry Reding | 33f150e | 2018-05-16 17:07:38 +0200 | [diff] [blame] | 21 | struct gr3d_soc { |
| 22 | unsigned int version; |
| 23 | }; |
| 24 | |
Thierry Reding | 5f60ed0 | 2013-02-28 08:08:01 +0100 | [diff] [blame] | 25 | struct gr3d { |
| 26 | struct tegra_drm_client client; |
| 27 | struct host1x_channel *channel; |
| 28 | struct clk *clk_secondary; |
| 29 | struct clk *clk; |
Stephen Warren | ca48080 | 2013-11-06 16:20:54 -0700 | [diff] [blame] | 30 | struct reset_control *rst_secondary; |
| 31 | struct reset_control *rst; |
Thierry Reding | 5f60ed0 | 2013-02-28 08:08:01 +0100 | [diff] [blame] | 32 | |
Thierry Reding | 33f150e | 2018-05-16 17:07:38 +0200 | [diff] [blame] | 33 | const struct gr3d_soc *soc; |
| 34 | |
Thierry Reding | 5f60ed0 | 2013-02-28 08:08:01 +0100 | [diff] [blame] | 35 | DECLARE_BITMAP(addr_regs, GR3D_NUM_REGS); |
| 36 | }; |
| 37 | |
| 38 | static inline struct gr3d *to_gr3d(struct tegra_drm_client *client) |
| 39 | { |
| 40 | return container_of(client, struct gr3d, client); |
| 41 | } |
| 42 | |
| 43 | static int gr3d_init(struct host1x_client *client) |
| 44 | { |
| 45 | struct tegra_drm_client *drm = host1x_to_drm_client(client); |
Thierry Reding | 608f43a | 2019-12-02 10:51:58 +0100 | [diff] [blame] | 46 | struct drm_device *dev = dev_get_drvdata(client->host); |
Thierry Reding | 977386a | 2013-10-28 10:23:11 +0100 | [diff] [blame] | 47 | unsigned long flags = HOST1X_SYNCPT_HAS_BASE; |
Thierry Reding | 5f60ed0 | 2013-02-28 08:08:01 +0100 | [diff] [blame] | 48 | struct gr3d *gr3d = to_gr3d(drm); |
Dmitry Osipenko | c9ac521 | 2018-05-04 02:47:21 +0300 | [diff] [blame] | 49 | int err; |
Thierry Reding | 5f60ed0 | 2013-02-28 08:08:01 +0100 | [diff] [blame] | 50 | |
Thierry Reding | caccddc | 2018-06-18 14:01:51 +0200 | [diff] [blame] | 51 | gr3d->channel = host1x_channel_request(client); |
Thierry Reding | 5f60ed0 | 2013-02-28 08:08:01 +0100 | [diff] [blame] | 52 | if (!gr3d->channel) |
| 53 | return -ENOMEM; |
| 54 | |
Thierry Reding | 617dd7c | 2017-08-30 12:48:31 +0200 | [diff] [blame] | 55 | client->syncpts[0] = host1x_syncpt_request(client, flags); |
Thierry Reding | 5f60ed0 | 2013-02-28 08:08:01 +0100 | [diff] [blame] | 56 | if (!client->syncpts[0]) { |
Thierry Reding | 230630b | 2018-05-04 15:08:49 +0200 | [diff] [blame] | 57 | err = -ENOMEM; |
| 58 | dev_err(client->dev, "failed to request syncpoint: %d\n", err); |
| 59 | goto put; |
Thierry Reding | 5f60ed0 | 2013-02-28 08:08:01 +0100 | [diff] [blame] | 60 | } |
| 61 | |
Thierry Reding | 7edd796 | 2019-10-28 13:37:08 +0100 | [diff] [blame] | 62 | err = host1x_client_iommu_attach(client); |
Thierry Reding | aacdf19 | 2019-02-08 14:35:13 +0100 | [diff] [blame] | 63 | if (err < 0) { |
Thierry Reding | 0c407de | 2018-05-04 15:02:24 +0200 | [diff] [blame] | 64 | dev_err(client->dev, "failed to attach to domain: %d\n", err); |
| 65 | goto free; |
Dmitry Osipenko | c9ac521 | 2018-05-04 02:47:21 +0300 | [diff] [blame] | 66 | } |
| 67 | |
Thierry Reding | 230630b | 2018-05-04 15:08:49 +0200 | [diff] [blame] | 68 | err = tegra_drm_register_client(dev->dev_private, drm); |
| 69 | if (err < 0) { |
| 70 | dev_err(client->dev, "failed to register client: %d\n", err); |
| 71 | goto detach; |
| 72 | } |
| 73 | |
| 74 | return 0; |
| 75 | |
| 76 | detach: |
Thierry Reding | aacdf19 | 2019-02-08 14:35:13 +0100 | [diff] [blame] | 77 | host1x_client_iommu_detach(client); |
Thierry Reding | 230630b | 2018-05-04 15:08:49 +0200 | [diff] [blame] | 78 | free: |
| 79 | host1x_syncpt_free(client->syncpts[0]); |
| 80 | put: |
| 81 | host1x_channel_put(gr3d->channel); |
| 82 | return err; |
Thierry Reding | 5f60ed0 | 2013-02-28 08:08:01 +0100 | [diff] [blame] | 83 | } |
| 84 | |
| 85 | static int gr3d_exit(struct host1x_client *client) |
| 86 | { |
| 87 | struct tegra_drm_client *drm = host1x_to_drm_client(client); |
Thierry Reding | 608f43a | 2019-12-02 10:51:58 +0100 | [diff] [blame] | 88 | struct drm_device *dev = dev_get_drvdata(client->host); |
Thierry Reding | 5f60ed0 | 2013-02-28 08:08:01 +0100 | [diff] [blame] | 89 | struct gr3d *gr3d = to_gr3d(drm); |
| 90 | int err; |
| 91 | |
Thierry Reding | 9910f5c | 2014-05-22 09:57:15 +0200 | [diff] [blame] | 92 | err = tegra_drm_unregister_client(dev->dev_private, drm); |
Thierry Reding | 5f60ed0 | 2013-02-28 08:08:01 +0100 | [diff] [blame] | 93 | if (err < 0) |
| 94 | return err; |
| 95 | |
Thierry Reding | aacdf19 | 2019-02-08 14:35:13 +0100 | [diff] [blame] | 96 | host1x_client_iommu_detach(client); |
Thierry Reding | 5f60ed0 | 2013-02-28 08:08:01 +0100 | [diff] [blame] | 97 | host1x_syncpt_free(client->syncpts[0]); |
Mikko Perttunen | 8474b02 | 2017-06-15 02:18:42 +0300 | [diff] [blame] | 98 | host1x_channel_put(gr3d->channel); |
Thierry Reding | 5f60ed0 | 2013-02-28 08:08:01 +0100 | [diff] [blame] | 99 | |
| 100 | return 0; |
| 101 | } |
| 102 | |
| 103 | static const struct host1x_client_ops gr3d_client_ops = { |
| 104 | .init = gr3d_init, |
| 105 | .exit = gr3d_exit, |
| 106 | }; |
| 107 | |
| 108 | static int gr3d_open_channel(struct tegra_drm_client *client, |
| 109 | struct tegra_drm_context *context) |
| 110 | { |
| 111 | struct gr3d *gr3d = to_gr3d(client); |
| 112 | |
| 113 | context->channel = host1x_channel_get(gr3d->channel); |
| 114 | if (!context->channel) |
| 115 | return -ENOMEM; |
| 116 | |
| 117 | return 0; |
| 118 | } |
| 119 | |
| 120 | static void gr3d_close_channel(struct tegra_drm_context *context) |
| 121 | { |
| 122 | host1x_channel_put(context->channel); |
| 123 | } |
| 124 | |
| 125 | static int gr3d_is_addr_reg(struct device *dev, u32 class, u32 offset) |
| 126 | { |
| 127 | struct gr3d *gr3d = dev_get_drvdata(dev); |
| 128 | |
| 129 | switch (class) { |
| 130 | case HOST1X_CLASS_HOST1X: |
| 131 | if (offset == 0x2b) |
| 132 | return 1; |
| 133 | |
| 134 | break; |
| 135 | |
| 136 | case HOST1X_CLASS_GR3D: |
| 137 | if (offset >= GR3D_NUM_REGS) |
| 138 | break; |
| 139 | |
| 140 | if (test_bit(offset, gr3d->addr_regs)) |
| 141 | return 1; |
| 142 | |
| 143 | break; |
| 144 | } |
| 145 | |
| 146 | return 0; |
| 147 | } |
| 148 | |
| 149 | static const struct tegra_drm_client_ops gr3d_ops = { |
| 150 | .open_channel = gr3d_open_channel, |
| 151 | .close_channel = gr3d_close_channel, |
| 152 | .is_addr_reg = gr3d_is_addr_reg, |
| 153 | .submit = tegra_drm_submit, |
| 154 | }; |
| 155 | |
Thierry Reding | 33f150e | 2018-05-16 17:07:38 +0200 | [diff] [blame] | 156 | static const struct gr3d_soc tegra20_gr3d_soc = { |
| 157 | .version = 0x20, |
| 158 | }; |
| 159 | |
| 160 | static const struct gr3d_soc tegra30_gr3d_soc = { |
| 161 | .version = 0x30, |
| 162 | }; |
| 163 | |
| 164 | static const struct gr3d_soc tegra114_gr3d_soc = { |
| 165 | .version = 0x35, |
| 166 | }; |
| 167 | |
Thierry Reding | 5f60ed0 | 2013-02-28 08:08:01 +0100 | [diff] [blame] | 168 | static const struct of_device_id tegra_gr3d_match[] = { |
Thierry Reding | 33f150e | 2018-05-16 17:07:38 +0200 | [diff] [blame] | 169 | { .compatible = "nvidia,tegra114-gr3d", .data = &tegra114_gr3d_soc }, |
| 170 | { .compatible = "nvidia,tegra30-gr3d", .data = &tegra30_gr3d_soc }, |
| 171 | { .compatible = "nvidia,tegra20-gr3d", .data = &tegra20_gr3d_soc }, |
Thierry Reding | 5f60ed0 | 2013-02-28 08:08:01 +0100 | [diff] [blame] | 172 | { } |
| 173 | }; |
Stephen Warren | ef70728 | 2014-06-18 16:21:55 -0600 | [diff] [blame] | 174 | MODULE_DEVICE_TABLE(of, tegra_gr3d_match); |
Thierry Reding | 5f60ed0 | 2013-02-28 08:08:01 +0100 | [diff] [blame] | 175 | |
| 176 | static const u32 gr3d_addr_regs[] = { |
| 177 | GR3D_IDX_ATTRIBUTE( 0), |
| 178 | GR3D_IDX_ATTRIBUTE( 1), |
| 179 | GR3D_IDX_ATTRIBUTE( 2), |
| 180 | GR3D_IDX_ATTRIBUTE( 3), |
| 181 | GR3D_IDX_ATTRIBUTE( 4), |
| 182 | GR3D_IDX_ATTRIBUTE( 5), |
| 183 | GR3D_IDX_ATTRIBUTE( 6), |
| 184 | GR3D_IDX_ATTRIBUTE( 7), |
| 185 | GR3D_IDX_ATTRIBUTE( 8), |
| 186 | GR3D_IDX_ATTRIBUTE( 9), |
| 187 | GR3D_IDX_ATTRIBUTE(10), |
| 188 | GR3D_IDX_ATTRIBUTE(11), |
| 189 | GR3D_IDX_ATTRIBUTE(12), |
| 190 | GR3D_IDX_ATTRIBUTE(13), |
| 191 | GR3D_IDX_ATTRIBUTE(14), |
| 192 | GR3D_IDX_ATTRIBUTE(15), |
| 193 | GR3D_IDX_INDEX_BASE, |
| 194 | GR3D_QR_ZTAG_ADDR, |
| 195 | GR3D_QR_CTAG_ADDR, |
| 196 | GR3D_QR_CZ_ADDR, |
| 197 | GR3D_TEX_TEX_ADDR( 0), |
| 198 | GR3D_TEX_TEX_ADDR( 1), |
| 199 | GR3D_TEX_TEX_ADDR( 2), |
| 200 | GR3D_TEX_TEX_ADDR( 3), |
| 201 | GR3D_TEX_TEX_ADDR( 4), |
| 202 | GR3D_TEX_TEX_ADDR( 5), |
| 203 | GR3D_TEX_TEX_ADDR( 6), |
| 204 | GR3D_TEX_TEX_ADDR( 7), |
| 205 | GR3D_TEX_TEX_ADDR( 8), |
| 206 | GR3D_TEX_TEX_ADDR( 9), |
| 207 | GR3D_TEX_TEX_ADDR(10), |
| 208 | GR3D_TEX_TEX_ADDR(11), |
| 209 | GR3D_TEX_TEX_ADDR(12), |
| 210 | GR3D_TEX_TEX_ADDR(13), |
| 211 | GR3D_TEX_TEX_ADDR(14), |
| 212 | GR3D_TEX_TEX_ADDR(15), |
| 213 | GR3D_DW_MEMORY_OUTPUT_ADDRESS, |
| 214 | GR3D_GLOBAL_SURFADDR( 0), |
| 215 | GR3D_GLOBAL_SURFADDR( 1), |
| 216 | GR3D_GLOBAL_SURFADDR( 2), |
| 217 | GR3D_GLOBAL_SURFADDR( 3), |
| 218 | GR3D_GLOBAL_SURFADDR( 4), |
| 219 | GR3D_GLOBAL_SURFADDR( 5), |
| 220 | GR3D_GLOBAL_SURFADDR( 6), |
| 221 | GR3D_GLOBAL_SURFADDR( 7), |
| 222 | GR3D_GLOBAL_SURFADDR( 8), |
| 223 | GR3D_GLOBAL_SURFADDR( 9), |
| 224 | GR3D_GLOBAL_SURFADDR(10), |
| 225 | GR3D_GLOBAL_SURFADDR(11), |
| 226 | GR3D_GLOBAL_SURFADDR(12), |
| 227 | GR3D_GLOBAL_SURFADDR(13), |
| 228 | GR3D_GLOBAL_SURFADDR(14), |
| 229 | GR3D_GLOBAL_SURFADDR(15), |
| 230 | GR3D_GLOBAL_SPILLSURFADDR, |
| 231 | GR3D_GLOBAL_SURFOVERADDR( 0), |
| 232 | GR3D_GLOBAL_SURFOVERADDR( 1), |
| 233 | GR3D_GLOBAL_SURFOVERADDR( 2), |
| 234 | GR3D_GLOBAL_SURFOVERADDR( 3), |
| 235 | GR3D_GLOBAL_SURFOVERADDR( 4), |
| 236 | GR3D_GLOBAL_SURFOVERADDR( 5), |
| 237 | GR3D_GLOBAL_SURFOVERADDR( 6), |
| 238 | GR3D_GLOBAL_SURFOVERADDR( 7), |
| 239 | GR3D_GLOBAL_SURFOVERADDR( 8), |
| 240 | GR3D_GLOBAL_SURFOVERADDR( 9), |
| 241 | GR3D_GLOBAL_SURFOVERADDR(10), |
| 242 | GR3D_GLOBAL_SURFOVERADDR(11), |
| 243 | GR3D_GLOBAL_SURFOVERADDR(12), |
| 244 | GR3D_GLOBAL_SURFOVERADDR(13), |
| 245 | GR3D_GLOBAL_SURFOVERADDR(14), |
| 246 | GR3D_GLOBAL_SURFOVERADDR(15), |
| 247 | GR3D_GLOBAL_SAMP01SURFADDR( 0), |
| 248 | GR3D_GLOBAL_SAMP01SURFADDR( 1), |
| 249 | GR3D_GLOBAL_SAMP01SURFADDR( 2), |
| 250 | GR3D_GLOBAL_SAMP01SURFADDR( 3), |
| 251 | GR3D_GLOBAL_SAMP01SURFADDR( 4), |
| 252 | GR3D_GLOBAL_SAMP01SURFADDR( 5), |
| 253 | GR3D_GLOBAL_SAMP01SURFADDR( 6), |
| 254 | GR3D_GLOBAL_SAMP01SURFADDR( 7), |
| 255 | GR3D_GLOBAL_SAMP01SURFADDR( 8), |
| 256 | GR3D_GLOBAL_SAMP01SURFADDR( 9), |
| 257 | GR3D_GLOBAL_SAMP01SURFADDR(10), |
| 258 | GR3D_GLOBAL_SAMP01SURFADDR(11), |
| 259 | GR3D_GLOBAL_SAMP01SURFADDR(12), |
| 260 | GR3D_GLOBAL_SAMP01SURFADDR(13), |
| 261 | GR3D_GLOBAL_SAMP01SURFADDR(14), |
| 262 | GR3D_GLOBAL_SAMP01SURFADDR(15), |
| 263 | GR3D_GLOBAL_SAMP23SURFADDR( 0), |
| 264 | GR3D_GLOBAL_SAMP23SURFADDR( 1), |
| 265 | GR3D_GLOBAL_SAMP23SURFADDR( 2), |
| 266 | GR3D_GLOBAL_SAMP23SURFADDR( 3), |
| 267 | GR3D_GLOBAL_SAMP23SURFADDR( 4), |
| 268 | GR3D_GLOBAL_SAMP23SURFADDR( 5), |
| 269 | GR3D_GLOBAL_SAMP23SURFADDR( 6), |
| 270 | GR3D_GLOBAL_SAMP23SURFADDR( 7), |
| 271 | GR3D_GLOBAL_SAMP23SURFADDR( 8), |
| 272 | GR3D_GLOBAL_SAMP23SURFADDR( 9), |
| 273 | GR3D_GLOBAL_SAMP23SURFADDR(10), |
| 274 | GR3D_GLOBAL_SAMP23SURFADDR(11), |
| 275 | GR3D_GLOBAL_SAMP23SURFADDR(12), |
| 276 | GR3D_GLOBAL_SAMP23SURFADDR(13), |
| 277 | GR3D_GLOBAL_SAMP23SURFADDR(14), |
| 278 | GR3D_GLOBAL_SAMP23SURFADDR(15), |
| 279 | }; |
| 280 | |
| 281 | static int gr3d_probe(struct platform_device *pdev) |
| 282 | { |
| 283 | struct device_node *np = pdev->dev.of_node; |
| 284 | struct host1x_syncpt **syncpts; |
| 285 | struct gr3d *gr3d; |
| 286 | unsigned int i; |
| 287 | int err; |
| 288 | |
| 289 | gr3d = devm_kzalloc(&pdev->dev, sizeof(*gr3d), GFP_KERNEL); |
| 290 | if (!gr3d) |
| 291 | return -ENOMEM; |
| 292 | |
Thierry Reding | 33f150e | 2018-05-16 17:07:38 +0200 | [diff] [blame] | 293 | gr3d->soc = of_device_get_match_data(&pdev->dev); |
| 294 | |
Thierry Reding | 5f60ed0 | 2013-02-28 08:08:01 +0100 | [diff] [blame] | 295 | syncpts = devm_kzalloc(&pdev->dev, sizeof(*syncpts), GFP_KERNEL); |
| 296 | if (!syncpts) |
| 297 | return -ENOMEM; |
| 298 | |
| 299 | gr3d->clk = devm_clk_get(&pdev->dev, NULL); |
| 300 | if (IS_ERR(gr3d->clk)) { |
| 301 | dev_err(&pdev->dev, "cannot get clock\n"); |
| 302 | return PTR_ERR(gr3d->clk); |
| 303 | } |
| 304 | |
Stephen Warren | ca48080 | 2013-11-06 16:20:54 -0700 | [diff] [blame] | 305 | gr3d->rst = devm_reset_control_get(&pdev->dev, "3d"); |
| 306 | if (IS_ERR(gr3d->rst)) { |
| 307 | dev_err(&pdev->dev, "cannot get reset\n"); |
| 308 | return PTR_ERR(gr3d->rst); |
| 309 | } |
| 310 | |
Thierry Reding | 5f60ed0 | 2013-02-28 08:08:01 +0100 | [diff] [blame] | 311 | if (of_device_is_compatible(np, "nvidia,tegra30-gr3d")) { |
| 312 | gr3d->clk_secondary = devm_clk_get(&pdev->dev, "3d2"); |
Christophe Jaillet | 87ba3e1 | 2016-07-03 08:18:57 +0200 | [diff] [blame] | 313 | if (IS_ERR(gr3d->clk_secondary)) { |
Thierry Reding | 5f60ed0 | 2013-02-28 08:08:01 +0100 | [diff] [blame] | 314 | dev_err(&pdev->dev, "cannot get secondary clock\n"); |
Christophe Jaillet | 87ba3e1 | 2016-07-03 08:18:57 +0200 | [diff] [blame] | 315 | return PTR_ERR(gr3d->clk_secondary); |
Thierry Reding | 5f60ed0 | 2013-02-28 08:08:01 +0100 | [diff] [blame] | 316 | } |
Stephen Warren | ca48080 | 2013-11-06 16:20:54 -0700 | [diff] [blame] | 317 | |
| 318 | gr3d->rst_secondary = devm_reset_control_get(&pdev->dev, |
| 319 | "3d2"); |
| 320 | if (IS_ERR(gr3d->rst_secondary)) { |
| 321 | dev_err(&pdev->dev, "cannot get secondary reset\n"); |
| 322 | return PTR_ERR(gr3d->rst_secondary); |
| 323 | } |
Thierry Reding | 5f60ed0 | 2013-02-28 08:08:01 +0100 | [diff] [blame] | 324 | } |
| 325 | |
Stephen Warren | 80b2879 | 2013-11-06 15:45:46 -0700 | [diff] [blame] | 326 | err = tegra_powergate_sequence_power_up(TEGRA_POWERGATE_3D, gr3d->clk, |
| 327 | gr3d->rst); |
Thierry Reding | 5f60ed0 | 2013-02-28 08:08:01 +0100 | [diff] [blame] | 328 | if (err < 0) { |
| 329 | dev_err(&pdev->dev, "failed to power up 3D unit\n"); |
| 330 | return err; |
| 331 | } |
| 332 | |
| 333 | if (gr3d->clk_secondary) { |
| 334 | err = tegra_powergate_sequence_power_up(TEGRA_POWERGATE_3D1, |
Stephen Warren | 80b2879 | 2013-11-06 15:45:46 -0700 | [diff] [blame] | 335 | gr3d->clk_secondary, |
| 336 | gr3d->rst_secondary); |
Thierry Reding | 5f60ed0 | 2013-02-28 08:08:01 +0100 | [diff] [blame] | 337 | if (err < 0) { |
| 338 | dev_err(&pdev->dev, |
| 339 | "failed to power up secondary 3D unit\n"); |
| 340 | return err; |
| 341 | } |
| 342 | } |
| 343 | |
| 344 | INIT_LIST_HEAD(&gr3d->client.base.list); |
| 345 | gr3d->client.base.ops = &gr3d_client_ops; |
| 346 | gr3d->client.base.dev = &pdev->dev; |
| 347 | gr3d->client.base.class = HOST1X_CLASS_GR3D; |
| 348 | gr3d->client.base.syncpts = syncpts; |
| 349 | gr3d->client.base.num_syncpts = 1; |
| 350 | |
| 351 | INIT_LIST_HEAD(&gr3d->client.list); |
Thierry Reding | 33f150e | 2018-05-16 17:07:38 +0200 | [diff] [blame] | 352 | gr3d->client.version = gr3d->soc->version; |
Thierry Reding | 5f60ed0 | 2013-02-28 08:08:01 +0100 | [diff] [blame] | 353 | gr3d->client.ops = &gr3d_ops; |
| 354 | |
| 355 | err = host1x_client_register(&gr3d->client.base); |
| 356 | if (err < 0) { |
| 357 | dev_err(&pdev->dev, "failed to register host1x client: %d\n", |
| 358 | err); |
| 359 | return err; |
| 360 | } |
| 361 | |
| 362 | /* initialize address register map */ |
| 363 | for (i = 0; i < ARRAY_SIZE(gr3d_addr_regs); i++) |
| 364 | set_bit(gr3d_addr_regs[i], gr3d->addr_regs); |
| 365 | |
| 366 | platform_set_drvdata(pdev, gr3d); |
| 367 | |
| 368 | return 0; |
| 369 | } |
| 370 | |
| 371 | static int gr3d_remove(struct platform_device *pdev) |
| 372 | { |
| 373 | struct gr3d *gr3d = platform_get_drvdata(pdev); |
| 374 | int err; |
| 375 | |
| 376 | err = host1x_client_unregister(&gr3d->client.base); |
| 377 | if (err < 0) { |
| 378 | dev_err(&pdev->dev, "failed to unregister host1x client: %d\n", |
| 379 | err); |
| 380 | return err; |
| 381 | } |
| 382 | |
| 383 | if (gr3d->clk_secondary) { |
| 384 | tegra_powergate_power_off(TEGRA_POWERGATE_3D1); |
| 385 | clk_disable_unprepare(gr3d->clk_secondary); |
| 386 | } |
| 387 | |
| 388 | tegra_powergate_power_off(TEGRA_POWERGATE_3D); |
| 389 | clk_disable_unprepare(gr3d->clk); |
| 390 | |
| 391 | return 0; |
| 392 | } |
| 393 | |
| 394 | struct platform_driver tegra_gr3d_driver = { |
| 395 | .driver = { |
| 396 | .name = "tegra-gr3d", |
| 397 | .of_match_table = tegra_gr3d_match, |
| 398 | }, |
| 399 | .probe = gr3d_probe, |
| 400 | .remove = gr3d_remove, |
| 401 | }; |