Skip to content

Commit

Permalink
drm/panfrost: Add support for multiple regulators
Browse files Browse the repository at this point in the history
Some GPUs, namely, the bifrost/g72 part on MT8183, have a second
regulator for their SRAM, let's add support for that.

We extend the framework in a generic manner so that we could
support more than 2 regulators, if required.

Signed-off-by: Nicolas Boichat <drinkcat@chromium.org>
Reviewed-by: Steven Price <steven.price@arm.com>
Reviwed-by: Mark Brown <broonie@kernel.org>
Signed-off-by: Rob Herring <robh@kernel.org>
Link: https://patchwork.freedesktop.org/patch/msgid/20200207052627.130118-5-drinkcat@chromium.org
  • Loading branch information
Nicolas Boichat authored and Rob Herring committed Feb 25, 2020
1 parent a9d73b3 commit 3e1399b
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 18 deletions.
26 changes: 18 additions & 8 deletions drivers/gpu/drm/panfrost/panfrost_device.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,18 +87,27 @@ static void panfrost_clk_fini(struct panfrost_device *pfdev)

static int panfrost_regulator_init(struct panfrost_device *pfdev)
{
int ret;
int ret, i;

pfdev->regulator = devm_regulator_get(pfdev->dev, "mali");
if (IS_ERR(pfdev->regulator)) {
ret = PTR_ERR(pfdev->regulator);
dev_err(pfdev->dev, "failed to get regulator: %d\n", ret);
if (WARN(pfdev->comp->num_supplies > ARRAY_SIZE(pfdev->regulators),
"Too many supplies in compatible structure.\n"))
return -EINVAL;

for (i = 0; i < pfdev->comp->num_supplies; i++)
pfdev->regulators[i].supply = pfdev->comp->supply_names[i];

ret = devm_regulator_bulk_get(pfdev->dev,
pfdev->comp->num_supplies,
pfdev->regulators);
if (ret < 0) {
dev_err(pfdev->dev, "failed to get regulators: %d\n", ret);
return ret;
}

ret = regulator_enable(pfdev->regulator);
ret = regulator_bulk_enable(pfdev->comp->num_supplies,
pfdev->regulators);
if (ret < 0) {
dev_err(pfdev->dev, "failed to enable regulator: %d\n", ret);
dev_err(pfdev->dev, "failed to enable regulators: %d\n", ret);
return ret;
}

Expand All @@ -107,7 +116,8 @@ static int panfrost_regulator_init(struct panfrost_device *pfdev)

static void panfrost_regulator_fini(struct panfrost_device *pfdev)
{
regulator_disable(pfdev->regulator);
regulator_bulk_disable(pfdev->comp->num_supplies,
pfdev->regulators);
}

int panfrost_device_init(struct panfrost_device *pfdev)
Expand Down
15 changes: 14 additions & 1 deletion drivers/gpu/drm/panfrost/panfrost_device.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#include <linux/atomic.h>
#include <linux/io-pgtable.h>
#include <linux/regulator/consumer.h>
#include <linux/spinlock.h>
#include <drm/drm_device.h>
#include <drm/drm_mm.h>
Expand All @@ -19,6 +20,7 @@ struct panfrost_job;
struct panfrost_perfcnt;

#define NUM_JOB_SLOTS 3
#define MAX_REGULATORS 2

struct panfrost_features {
u16 id;
Expand Down Expand Up @@ -51,6 +53,16 @@ struct panfrost_features {
unsigned long hw_issues[64 / BITS_PER_LONG];
};

/*
* Features that cannot be automatically detected and need matching using the
* compatible string, typically SoC-specific.
*/
struct panfrost_compatible {
/* Supplies count and names. */
int num_supplies;
const char * const *supply_names;
};

struct panfrost_device {
struct device *dev;
struct drm_device *ddev;
Expand All @@ -59,10 +71,11 @@ struct panfrost_device {
void __iomem *iomem;
struct clk *clock;
struct clk *bus_clock;
struct regulator *regulator;
struct regulator_bulk_data regulators[MAX_REGULATORS];
struct reset_control *rstc;

struct panfrost_features features;
const struct panfrost_compatible *comp;

spinlock_t as_lock;
unsigned long as_in_use_mask;
Expand Down
28 changes: 19 additions & 9 deletions drivers/gpu/drm/panfrost/panfrost_drv.c
Original file line number Diff line number Diff line change
Expand Up @@ -584,6 +584,10 @@ static int panfrost_probe(struct platform_device *pdev)

platform_set_drvdata(pdev, pfdev);

pfdev->comp = of_device_get_match_data(&pdev->dev);
if (!pfdev->comp)
return -ENODEV;

/* Allocate and initialze the DRM device. */
ddev = drm_dev_alloc(&panfrost_drm_driver, &pdev->dev);
if (IS_ERR(ddev))
Expand Down Expand Up @@ -655,16 +659,22 @@ static int panfrost_remove(struct platform_device *pdev)
return 0;
}

const char * const default_supplies[] = { "mali" };
static const struct panfrost_compatible default_data = {
.num_supplies = ARRAY_SIZE(default_supplies),
.supply_names = default_supplies,
};

static const struct of_device_id dt_match[] = {
{ .compatible = "arm,mali-t604" },
{ .compatible = "arm,mali-t624" },
{ .compatible = "arm,mali-t628" },
{ .compatible = "arm,mali-t720" },
{ .compatible = "arm,mali-t760" },
{ .compatible = "arm,mali-t820" },
{ .compatible = "arm,mali-t830" },
{ .compatible = "arm,mali-t860" },
{ .compatible = "arm,mali-t880" },
{ .compatible = "arm,mali-t604", .data = &default_data, },
{ .compatible = "arm,mali-t624", .data = &default_data, },
{ .compatible = "arm,mali-t628", .data = &default_data, },
{ .compatible = "arm,mali-t720", .data = &default_data, },
{ .compatible = "arm,mali-t760", .data = &default_data, },
{ .compatible = "arm,mali-t820", .data = &default_data, },
{ .compatible = "arm,mali-t830", .data = &default_data, },
{ .compatible = "arm,mali-t860", .data = &default_data, },
{ .compatible = "arm,mali-t880", .data = &default_data, },
{}
};
MODULE_DEVICE_TABLE(of, dt_match);
Expand Down

0 comments on commit 3e1399b

Please sign in to comment.