2 * Copyright (c) 2012-2013, NVIDIA Corporation.
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms and conditions of the GNU General Public License,
6 * version 2, as published by the Free Software Foundation.
8 * This program is distributed in the hope it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 #include <linux/clk.h>
24 struct tegra_drm_client client;
25 struct host1x_channel *channel;
28 DECLARE_BITMAP(addr_regs, GR2D_NUM_REGS);
31 static inline struct gr2d *to_gr2d(struct tegra_drm_client *client)
33 return container_of(client, struct gr2d, client);
36 static int gr2d_init(struct host1x_client *client)
38 struct tegra_drm_client *drm = host1x_to_drm_client(client);
39 struct tegra_drm *tegra = dev_get_drvdata(client->parent);
40 struct gr2d *gr2d = to_gr2d(drm);
42 gr2d->channel = host1x_channel_request(client->dev);
46 client->syncpts[0] = host1x_syncpt_request(client->dev, false);
47 if (!client->syncpts[0]) {
48 host1x_channel_free(gr2d->channel);
52 return tegra_drm_register_client(tegra, drm);
55 static int gr2d_exit(struct host1x_client *client)
57 struct tegra_drm_client *drm = host1x_to_drm_client(client);
58 struct tegra_drm *tegra = dev_get_drvdata(client->parent);
59 struct gr2d *gr2d = to_gr2d(drm);
62 err = tegra_drm_unregister_client(tegra, drm);
66 host1x_syncpt_free(client->syncpts[0]);
67 host1x_channel_free(gr2d->channel);
72 static const struct host1x_client_ops gr2d_client_ops = {
77 static int gr2d_open_channel(struct tegra_drm_client *client,
78 struct tegra_drm_context *context)
80 struct gr2d *gr2d = to_gr2d(client);
82 context->channel = host1x_channel_get(gr2d->channel);
83 if (!context->channel)
89 static void gr2d_close_channel(struct tegra_drm_context *context)
91 host1x_channel_put(context->channel);
94 static int gr2d_is_addr_reg(struct device *dev, u32 class, u32 offset)
96 struct gr2d *gr2d = dev_get_drvdata(dev);
99 case HOST1X_CLASS_HOST1X:
105 case HOST1X_CLASS_GR2D:
106 case HOST1X_CLASS_GR2D_SB:
107 if (offset >= GR2D_NUM_REGS)
110 if (test_bit(offset, gr2d->addr_regs))
119 static const struct tegra_drm_client_ops gr2d_ops = {
120 .open_channel = gr2d_open_channel,
121 .close_channel = gr2d_close_channel,
122 .is_addr_reg = gr2d_is_addr_reg,
123 .submit = tegra_drm_submit,
126 static const struct of_device_id gr2d_match[] = {
127 { .compatible = "nvidia,tegra30-gr2d" },
128 { .compatible = "nvidia,tegra20-gr2d" },
132 static const u32 gr2d_addr_regs[] = {
141 GR2D_SRC_BASE_ADDR_SB,
142 GR2D_DSTA_BASE_ADDR_SB,
143 GR2D_DSTB_BASE_ADDR_SB,
144 GR2D_UA_BASE_ADDR_SB,
145 GR2D_VA_BASE_ADDR_SB,
148 static int gr2d_probe(struct platform_device *pdev)
150 struct device *dev = &pdev->dev;
151 struct host1x_syncpt **syncpts;
156 gr2d = devm_kzalloc(dev, sizeof(*gr2d), GFP_KERNEL);
160 syncpts = devm_kzalloc(dev, sizeof(*syncpts), GFP_KERNEL);
164 gr2d->clk = devm_clk_get(dev, NULL);
165 if (IS_ERR(gr2d->clk)) {
166 dev_err(dev, "cannot get clock\n");
167 return PTR_ERR(gr2d->clk);
170 err = clk_prepare_enable(gr2d->clk);
172 dev_err(dev, "cannot turn on clock\n");
176 INIT_LIST_HEAD(&gr2d->client.base.list);
177 gr2d->client.base.ops = &gr2d_client_ops;
178 gr2d->client.base.dev = dev;
179 gr2d->client.base.class = HOST1X_CLASS_GR2D;
180 gr2d->client.base.syncpts = syncpts;
181 gr2d->client.base.num_syncpts = 1;
183 INIT_LIST_HEAD(&gr2d->client.list);
184 gr2d->client.ops = &gr2d_ops;
186 err = host1x_client_register(&gr2d->client.base);
188 dev_err(dev, "failed to register host1x client: %d\n", err);
192 /* initialize address register map */
193 for (i = 0; i < ARRAY_SIZE(gr2d_addr_regs); i++)
194 set_bit(gr2d_addr_regs[i], gr2d->addr_regs);
196 platform_set_drvdata(pdev, gr2d);
201 static int gr2d_remove(struct platform_device *pdev)
203 struct gr2d *gr2d = platform_get_drvdata(pdev);
206 err = host1x_client_unregister(&gr2d->client.base);
208 dev_err(&pdev->dev, "failed to unregister host1x client: %d\n",
213 clk_disable_unprepare(gr2d->clk);
218 struct platform_driver tegra_gr2d_driver = {
220 .name = "tegra-gr2d",
221 .of_match_table = gr2d_match,
224 .remove = gr2d_remove,