Skip to content

Commit

Permalink
drm/panfrost: dynamically alloc regulators
Browse files Browse the repository at this point in the history
We will later introduce regulators managed by OPP.

Only alloc regulators when it's needed. This also help use
to release the regulators only when they are allocated.

Reviewed-by: Steven Price <[email protected]>
Reviewed-by: Alyssa Rosenzweig <[email protected]>
Signed-off-by: Clément Péron <[email protected]>
  • Loading branch information
clementperon authored and sigmaris committed Aug 8, 2020
1 parent 3201616 commit 26e39c0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
14 changes: 9 additions & 5 deletions drivers/gpu/drm/panfrost/panfrost_device.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,11 @@ static int panfrost_regulator_init(struct panfrost_device *pfdev)
{
int ret, i;

if (WARN(pfdev->comp->num_supplies > ARRAY_SIZE(pfdev->regulators),
"Too many supplies in compatible structure.\n"))
return -EINVAL;
pfdev->regulators = devm_kcalloc(pfdev->dev, pfdev->comp->num_supplies,
sizeof(*pfdev->regulators),
GFP_KERNEL);
if (!pfdev->regulators)
return -ENOMEM;

for (i = 0; i < pfdev->comp->num_supplies; i++)
pfdev->regulators[i].supply = pfdev->comp->supply_names[i];
Expand All @@ -117,8 +119,10 @@ static int panfrost_regulator_init(struct panfrost_device *pfdev)

static void panfrost_regulator_fini(struct panfrost_device *pfdev)
{
regulator_bulk_disable(pfdev->comp->num_supplies,
pfdev->regulators);
if (!pfdev->regulators)
return;

regulator_bulk_disable(pfdev->comp->num_supplies, pfdev->regulators);
}

static void panfrost_pm_domain_fini(struct panfrost_device *pfdev)
Expand Down
3 changes: 1 addition & 2 deletions drivers/gpu/drm/panfrost/panfrost_device.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ struct panfrost_job;
struct panfrost_perfcnt;

#define NUM_JOB_SLOTS 3
#define MAX_REGULATORS 2
#define MAX_PM_DOMAINS 3

struct panfrost_features {
Expand Down Expand Up @@ -81,7 +80,7 @@ struct panfrost_device {
void __iomem *iomem;
struct clk *clock;
struct clk *bus_clock;
struct regulator_bulk_data regulators[MAX_REGULATORS];
struct regulator_bulk_data *regulators;
struct reset_control *rstc;
/* pm_domains for devices with more than one. */
struct device *pm_domain_devs[MAX_PM_DOMAINS];
Expand Down

0 comments on commit 26e39c0

Please sign in to comment.