blob: 58ab871a3b4d450537293aab1e6ef234bfda4648 [file] [log] [blame]
Svyatoslav Ryhelb9341da2025-02-28 20:02:23 +02001// SPDX-License-Identifier: GPL-2.0+
2/*
3 * Copyright (c) 2025 Svyatoslav Ryhel <clamor95@gmail.com>
4 */
5
6#include <dm.h>
7#include <clk.h>
8#include <log.h>
9#include <reset.h>
10#include <linux/delay.h>
11
12#include <asm/arch/clock.h>
13#include <asm/arch-tegra/clk_rst.h>
14
15struct tegra_host1x_info {
16 u32 clk_parent;
17 u32 rate;
18};
19
20static int tegra_host1x_probe(struct udevice *dev)
21{
22 struct clk *clk;
23 struct reset_ctl reset_ctl;
24 const struct tegra_host1x_info *info;
25 int ret;
26
27 clk = devm_clk_get(dev, NULL);
28 if (IS_ERR(clk)) {
29 log_debug("%s: cannot get HOST1X clock: %ld\n",
30 __func__, PTR_ERR(clk));
31 return PTR_ERR(clk);
32 }
33
34 ret = reset_get_by_name(dev, "host1x", &reset_ctl);
35 if (ret) {
36 log_debug("%s: cannot get HOST1X reset: %d\n",
37 __func__, ret);
38 return ret;
39 }
40
41 info = (struct tegra_host1x_info *)dev_get_driver_data(dev);
42
43 reset_assert(&reset_ctl);
44 clock_start_periph_pll(clk->id, info->clk_parent, info->rate);
45
46 mdelay(2);
47 reset_deassert(&reset_ctl);
48
49 return 0;
50}
51
52static const struct tegra_host1x_info tegra20_host1x_info = {
53 .clk_parent = CLOCK_ID_CGENERAL,
54 .rate = 150000000, /* 150 MHz */
55};
56
57static const struct tegra_host1x_info tegra114_host1x_info = {
58 .clk_parent = CLOCK_ID_PERIPH,
59 .rate = 136000000, /* 136 MHz */
60};
61
62static const struct udevice_id tegra_host1x_ids[] = {
63 {
64 .compatible = "nvidia,tegra20-host1x",
65 .data = (ulong)&tegra20_host1x_info
66 }, {
67 .compatible = "nvidia,tegra30-host1x",
68 .data = (ulong)&tegra20_host1x_info
69 }, {
70 .compatible = "nvidia,tegra114-host1x",
71 .data = (ulong)&tegra114_host1x_info
72 }, {
73 .compatible = "nvidia,tegra124-host1x",
74 .data = (ulong)&tegra114_host1x_info
75 }, {
76 /* sentinel */
77 }
78};
79
80U_BOOT_DRIVER(tegra_host1x) = {
81 .name = "tegra_host1x",
82 .id = UCLASS_SIMPLE_BUS,
83 .of_match = tegra_host1x_ids,
84 .probe = tegra_host1x_probe,
85 .flags = DM_FLAG_PRE_RELOC,
86};