Skip to content

Commit

Permalink
Merge tag 'drm/tegra/for-6.2-rc1' of https://gitlab.freedesktop.org/d…
Browse files Browse the repository at this point in the history
…rm/tegra into drm-next

drm/tegra: Changes for v6.2-rc1

This contains a bunch of cleanups across the board as well as support
for the NVDEC hardware found on the Tegra234 SoC.

Signed-off-by: Dave Airlie <airlied@redhat.com>

From: Thierry Reding <thierry.reding@gmail.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20221125155219.3352952-1-thierry.reding@gmail.com
  • Loading branch information
Dave Airlie committed Nov 30, 2022
2 parents 795bd9b + 08fef75 commit 02339a8
Show file tree
Hide file tree
Showing 18 changed files with 362 additions and 76 deletions.
3 changes: 2 additions & 1 deletion drivers/gpu/drm/tegra/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ tegra-drm-y := \
gr3d.o \
falcon.o \
vic.o \
nvdec.o
nvdec.o \
riscv.o

tegra-drm-y += trace.o

Expand Down
4 changes: 3 additions & 1 deletion drivers/gpu/drm/tegra/dc.c
Original file line number Diff line number Diff line change
Expand Up @@ -3205,8 +3205,10 @@ static int tegra_dc_probe(struct platform_device *pdev)
usleep_range(2000, 4000);

err = reset_control_assert(dc->rst);
if (err < 0)
if (err < 0) {
clk_disable_unprepare(dc->clk);
return err;
}

usleep_range(2000, 4000);

Expand Down
1 change: 1 addition & 0 deletions drivers/gpu/drm/tegra/drm.c
Original file line number Diff line number Diff line change
Expand Up @@ -1386,6 +1386,7 @@ static const struct of_device_id host1x_drm_subdevs[] = {
{ .compatible = "nvidia,tegra194-vic", },
{ .compatible = "nvidia,tegra194-nvdec", },
{ .compatible = "nvidia,tegra234-vic", },
{ .compatible = "nvidia,tegra234-nvdec", },
{ /* sentinel */ }
};

Expand Down
9 changes: 1 addition & 8 deletions drivers/gpu/drm/tegra/hdmi.c
Original file line number Diff line number Diff line change
Expand Up @@ -867,14 +867,7 @@ static int tegra_hdmi_reconfigure_audio(struct tegra_hdmi *hdmi)

static bool tegra_output_is_hdmi(struct tegra_output *output)
{
struct edid *edid;

if (!output->connector.edid_blob_ptr)
return false;

edid = (struct edid *)output->connector.edid_blob_ptr->data;

return drm_detect_hdmi_monitor(edid);
return output->connector.display_info.is_hdmi;
}

static enum drm_connector_status
Expand Down
171 changes: 146 additions & 25 deletions drivers/gpu/drm/tegra/nvdec.c
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
// SPDX-License-Identifier: GPL-2.0-only
/*
* Copyright (c) 2015-2021, NVIDIA Corporation.
* Copyright (c) 2015-2022, NVIDIA Corporation.
*/

#include <linux/clk.h>
#include <linux/delay.h>
#include <linux/dma-mapping.h>
#include <linux/host1x.h>
#include <linux/iommu.h>
#include <linux/iopoll.h>
#include <linux/module.h>
#include <linux/of.h>
#include <linux/of_device.h>
Expand All @@ -16,18 +17,22 @@
#include <linux/pm_runtime.h>
#include <linux/reset.h>

#include <soc/tegra/pmc.h>
#include <soc/tegra/mc.h>

#include "drm.h"
#include "falcon.h"
#include "riscv.h"
#include "vic.h"

#define NVDEC_FALCON_DEBUGINFO 0x1094
#define NVDEC_TFBIF_TRANSCFG 0x2c44

struct nvdec_config {
const char *firmware;
unsigned int version;
bool supports_sid;
bool has_riscv;
bool has_extra_clocks;
};

struct nvdec {
Expand All @@ -37,10 +42,16 @@ struct nvdec {
struct tegra_drm_client client;
struct host1x_channel *channel;
struct device *dev;
struct clk *clk;
struct clk_bulk_data clks[3];
unsigned int num_clks;
struct reset_control *reset;

/* Platform configuration */
const struct nvdec_config *config;

/* RISC-V specific data */
struct tegra_drm_riscv riscv;
phys_addr_t carveout_base;
};

static inline struct nvdec *to_nvdec(struct tegra_drm_client *client)
Expand All @@ -54,7 +65,7 @@ static inline void nvdec_writel(struct nvdec *nvdec, u32 value,
writel(value, nvdec->regs + offset);
}

static int nvdec_boot(struct nvdec *nvdec)
static int nvdec_boot_falcon(struct nvdec *nvdec)
{
#ifdef CONFIG_IOMMU_API
struct iommu_fwspec *spec = dev_iommu_fwspec_get(nvdec->dev);
Expand Down Expand Up @@ -90,6 +101,64 @@ static int nvdec_boot(struct nvdec *nvdec)
return 0;
}

static int nvdec_wait_debuginfo(struct nvdec *nvdec, const char *phase)
{
int err;
u32 val;

err = readl_poll_timeout(nvdec->regs + NVDEC_FALCON_DEBUGINFO, val, val == 0x0, 10, 100000);
if (err) {
dev_err(nvdec->dev, "failed to boot %s, debuginfo=0x%x\n", phase, val);
return err;
}

return 0;
}

static int nvdec_boot_riscv(struct nvdec *nvdec)
{
int err;

err = reset_control_acquire(nvdec->reset);
if (err)
return err;

nvdec_writel(nvdec, 0xabcd1234, NVDEC_FALCON_DEBUGINFO);

err = tegra_drm_riscv_boot_bootrom(&nvdec->riscv, nvdec->carveout_base, 1,
&nvdec->riscv.bl_desc);
if (err) {
dev_err(nvdec->dev, "failed to execute bootloader\n");
goto release_reset;
}

err = nvdec_wait_debuginfo(nvdec, "bootloader");
if (err)
goto release_reset;

err = reset_control_reset(nvdec->reset);
if (err)
goto release_reset;

nvdec_writel(nvdec, 0xabcd1234, NVDEC_FALCON_DEBUGINFO);

err = tegra_drm_riscv_boot_bootrom(&nvdec->riscv, nvdec->carveout_base, 1,
&nvdec->riscv.os_desc);
if (err) {
dev_err(nvdec->dev, "failed to execute firmware\n");
goto release_reset;
}

err = nvdec_wait_debuginfo(nvdec, "firmware");
if (err)
goto release_reset;

release_reset:
reset_control_release(nvdec->reset);

return err;
}

static int nvdec_init(struct host1x_client *client)
{
struct tegra_drm_client *drm = host1x_to_drm_client(client);
Expand Down Expand Up @@ -189,7 +258,7 @@ static const struct host1x_client_ops nvdec_client_ops = {
.exit = nvdec_exit,
};

static int nvdec_load_firmware(struct nvdec *nvdec)
static int nvdec_load_falcon_firmware(struct nvdec *nvdec)
{
struct host1x_client *client = &nvdec->client.base;
struct tegra_drm *tegra = nvdec->client.drm;
Expand Down Expand Up @@ -252,30 +321,35 @@ static int nvdec_load_firmware(struct nvdec *nvdec)
return err;
}


static __maybe_unused int nvdec_runtime_resume(struct device *dev)
{
struct nvdec *nvdec = dev_get_drvdata(dev);
int err;

err = clk_prepare_enable(nvdec->clk);
err = clk_bulk_prepare_enable(nvdec->num_clks, nvdec->clks);
if (err < 0)
return err;

usleep_range(10, 20);

err = nvdec_load_firmware(nvdec);
if (err < 0)
goto disable;
if (nvdec->config->has_riscv) {
err = nvdec_boot_riscv(nvdec);
if (err < 0)
goto disable;
} else {
err = nvdec_load_falcon_firmware(nvdec);
if (err < 0)
goto disable;

err = nvdec_boot(nvdec);
if (err < 0)
goto disable;
err = nvdec_boot_falcon(nvdec);
if (err < 0)
goto disable;
}

return 0;

disable:
clk_disable_unprepare(nvdec->clk);
clk_bulk_disable_unprepare(nvdec->num_clks, nvdec->clks);
return err;
}

Expand All @@ -285,7 +359,7 @@ static __maybe_unused int nvdec_runtime_suspend(struct device *dev)

host1x_channel_stop(nvdec->channel);

clk_disable_unprepare(nvdec->clk);
clk_bulk_disable_unprepare(nvdec->num_clks, nvdec->clks);

return 0;
}
Expand Down Expand Up @@ -346,10 +420,18 @@ static const struct nvdec_config nvdec_t194_config = {
.supports_sid = true,
};

static const struct nvdec_config nvdec_t234_config = {
.version = 0x23,
.supports_sid = true,
.has_riscv = true,
.has_extra_clocks = true,
};

static const struct of_device_id tegra_nvdec_of_match[] = {
{ .compatible = "nvidia,tegra210-nvdec", .data = &nvdec_t210_config },
{ .compatible = "nvidia,tegra186-nvdec", .data = &nvdec_t186_config },
{ .compatible = "nvidia,tegra194-nvdec", .data = &nvdec_t194_config },
{ .compatible = "nvidia,tegra234-nvdec", .data = &nvdec_t234_config },
{ },
};
MODULE_DEVICE_TABLE(of, tegra_nvdec_of_match);
Expand Down Expand Up @@ -383,13 +465,22 @@ static int nvdec_probe(struct platform_device *pdev)
if (IS_ERR(nvdec->regs))
return PTR_ERR(nvdec->regs);

nvdec->clk = devm_clk_get(dev, NULL);
if (IS_ERR(nvdec->clk)) {
dev_err(&pdev->dev, "failed to get clock\n");
return PTR_ERR(nvdec->clk);
nvdec->clks[0].id = "nvdec";
nvdec->num_clks = 1;

if (nvdec->config->has_extra_clocks) {
nvdec->num_clks = 3;
nvdec->clks[1].id = "fuse";
nvdec->clks[2].id = "tsec_pka";
}

err = clk_set_rate(nvdec->clk, ULONG_MAX);
err = devm_clk_bulk_get(dev, nvdec->num_clks, nvdec->clks);
if (err) {
dev_err(&pdev->dev, "failed to get clock(s)\n");
return err;
}

err = clk_set_rate(nvdec->clks[0].clk, ULONG_MAX);
if (err < 0) {
dev_err(&pdev->dev, "failed to set clock rate\n");
return err;
Expand All @@ -399,12 +490,42 @@ static int nvdec_probe(struct platform_device *pdev)
if (err < 0)
host_class = HOST1X_CLASS_NVDEC;

nvdec->falcon.dev = dev;
nvdec->falcon.regs = nvdec->regs;
if (nvdec->config->has_riscv) {
struct tegra_mc *mc;

err = falcon_init(&nvdec->falcon);
if (err < 0)
return err;
mc = devm_tegra_memory_controller_get(dev);
if (IS_ERR(mc)) {
dev_err_probe(dev, PTR_ERR(mc),
"failed to get memory controller handle\n");
return PTR_ERR(mc);
}

err = tegra_mc_get_carveout_info(mc, 1, &nvdec->carveout_base, NULL);
if (err) {
dev_err(dev, "failed to get carveout info: %d\n", err);
return err;
}

nvdec->reset = devm_reset_control_get_exclusive_released(dev, "nvdec");
if (IS_ERR(nvdec->reset)) {
dev_err_probe(dev, PTR_ERR(nvdec->reset), "failed to get reset\n");
return PTR_ERR(nvdec->reset);
}

nvdec->riscv.dev = dev;
nvdec->riscv.regs = nvdec->regs;

err = tegra_drm_riscv_read_descriptors(&nvdec->riscv);
if (err < 0)
return err;
} else {
nvdec->falcon.dev = dev;
nvdec->falcon.regs = nvdec->regs;

err = falcon_init(&nvdec->falcon);
if (err < 0)
return err;
}

platform_set_drvdata(pdev, nvdec);

Expand Down
10 changes: 5 additions & 5 deletions drivers/gpu/drm/tegra/output.c
Original file line number Diff line number Diff line change
Expand Up @@ -133,11 +133,11 @@ int tegra_output_probe(struct tegra_output *output)
}
}

output->hpd_gpio = devm_gpiod_get_from_of_node(output->dev,
output->of_node,
"nvidia,hpd-gpio", 0,
GPIOD_IN,
"HDMI hotplug detect");
output->hpd_gpio = devm_fwnode_gpiod_get(output->dev,
of_fwnode_handle(output->of_node),
"nvidia,hpd",
GPIOD_IN,
"HDMI hotplug detect");
if (IS_ERR(output->hpd_gpio)) {
if (PTR_ERR(output->hpd_gpio) != -ENOENT)
return PTR_ERR(output->hpd_gpio);
Expand Down
Loading

0 comments on commit 02339a8

Please sign in to comment.