Skip to content

Commit d452fc3

Browse files
cunyuan-cixamazingfate
authored andcommitted
drm/panthor: Add ACPI support
Add ACPI support for the Panthor DRM driver
1 parent af54620 commit d452fc3

File tree

6 files changed

+103
-60
lines changed

6 files changed

+103
-60
lines changed

drivers/gpu/drm/panthor/panthor_device.c

Lines changed: 80 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -25,38 +25,30 @@
2525

2626
static int panthor_clk_init(struct panthor_device *ptdev)
2727
{
28-
ptdev->clks.core = devm_clk_get(ptdev->base.dev, NULL);
28+
ptdev->clks.core = devm_clk_get(ptdev->base.dev, "gpu_clk_core");
2929
if (IS_ERR(ptdev->clks.core))
3030
return dev_err_probe(ptdev->base.dev,
3131
PTR_ERR(ptdev->clks.core),
3232
"get 'core' clock failed");
3333

34-
ptdev->clks.stacks = devm_clk_get_optional(ptdev->base.dev, "gpu_clk_stacks");
34+
ptdev->clks.stacks = devm_clk_get(ptdev->base.dev, "gpu_clk_stacks");
3535
if (IS_ERR(ptdev->clks.stacks))
3636
return dev_err_probe(ptdev->base.dev,
3737
PTR_ERR(ptdev->clks.stacks),
3838
"get 'stacks' clock failed");
3939

40-
ptdev->clks.coregroup = devm_clk_get_optional(ptdev->base.dev, "coregroup");
41-
if (IS_ERR(ptdev->clks.coregroup))
40+
/* CIX SKY1 needs additional backup clocks */
41+
ptdev->clks.backup[0] = devm_clk_get_optional(ptdev->base.dev, "gpu_clk_200M");
42+
if (IS_ERR(ptdev->clks.backup[0]))
4243
return dev_err_probe(ptdev->base.dev,
43-
PTR_ERR(ptdev->clks.coregroup),
44-
"get 'coregroup' clock failed");
44+
PTR_ERR(ptdev->clks.backup[0]),
45+
"get 'gpu_clk_200M' clock failed");
4546

46-
/* CIX SKY1 needs additional backup clocks */
47-
if (of_device_is_compatible(ptdev->base.dev->of_node, "arm,mali-valhall")) {
48-
ptdev->clks.backup[0] = devm_clk_get_optional(ptdev->base.dev, "gpu_clk_200M");
49-
if (IS_ERR(ptdev->clks.backup[0]))
50-
return dev_err_probe(ptdev->base.dev,
51-
PTR_ERR(ptdev->clks.backup[0]),
52-
"get 'gpu_clk_200M' clock failed");
53-
54-
ptdev->clks.backup[1] = devm_clk_get_optional(ptdev->base.dev, "gpu_clk_400M");
55-
if (IS_ERR(ptdev->clks.backup[1]))
56-
return dev_err_probe(ptdev->base.dev,
57-
PTR_ERR(ptdev->clks.backup[1]),
58-
"get 'gpu_clk_400M' clock failed");
59-
}
47+
ptdev->clks.backup[1] = devm_clk_get_optional(ptdev->base.dev, "gpu_clk_400M");
48+
if (IS_ERR(ptdev->clks.backup[1]))
49+
return dev_err_probe(ptdev->base.dev,
50+
PTR_ERR(ptdev->clks.backup[1]),
51+
"get 'gpu_clk_400M' clock failed");
6052

6153
drm_info(&ptdev->base, "clock rate = %lu\n", clk_get_rate(ptdev->clks.core));
6254
return 0;
@@ -68,7 +60,7 @@ static void panthor_pm_domain_fini(struct panthor_device *ptdev)
6860

6961
for (i = 0; i < ARRAY_SIZE(ptdev->pm_domain_devs); i++) {
7062
if (!ptdev->pm_domain_devs[i])
71-
break;
63+
continue;
7264

7365
if (ptdev->pm_domain_links[i])
7466
device_link_del(ptdev->pm_domain_links[i]);
@@ -82,39 +74,78 @@ static int panthor_pm_domain_init(struct panthor_device *ptdev)
8274
int err;
8375
int i, num_domains;
8476

85-
num_domains = of_count_phandle_with_args(ptdev->base.dev->of_node,
86-
"power-domains",
87-
"#power-domain-cells");
77+
if (!has_acpi_companion(ptdev->base.dev)) {
78+
num_domains = of_count_phandle_with_args(ptdev->base.dev->of_node,
79+
"power-domains",
80+
"#power-domain-cells");
8881

89-
/*
90-
* Single domain is handled by the core, and, if only a single power
91-
* the power domain is requested, the property is optional.
92-
*/
93-
if (num_domains < 2)
94-
return 0;
95-
96-
if (WARN(num_domains > ARRAY_SIZE(ptdev->pm_domain_devs),
97-
"Too many supplies in compatible structure.\n"))
98-
return -EINVAL;
82+
/*
83+
* Single domain is handled by the core, and, if only a single power
84+
* the power domain is requested, the property is optional.
85+
*/
86+
if (num_domains < 2)
87+
return 0;
88+
89+
if (WARN(num_domains > ARRAY_SIZE(ptdev->pm_domain_devs),
90+
"Too many supplies in compatible structure.\n"))
91+
return -EINVAL;
9992

100-
for (i = 0; i < num_domains; i++) {
101-
ptdev->pm_domain_devs[i] =
102-
dev_pm_domain_attach_by_id(ptdev->base.dev, i);
103-
if (IS_ERR_OR_NULL(ptdev->pm_domain_devs[i])) {
104-
err = PTR_ERR(ptdev->pm_domain_devs[i]) ? : -ENODATA;
105-
ptdev->pm_domain_devs[i] = NULL;
93+
for (i = 0; i < num_domains; i++) {
94+
ptdev->pm_domain_devs[i] =
95+
dev_pm_domain_attach_by_id(ptdev->base.dev, i);
96+
if (IS_ERR_OR_NULL(ptdev->pm_domain_devs[i])) {
97+
err = PTR_ERR(ptdev->pm_domain_devs[i]) ? : -ENODATA;
98+
ptdev->pm_domain_devs[i] = NULL;
99+
dev_err(ptdev->base.dev,
100+
"failed to get pm-domain %d: %d\n",
101+
i, err);
102+
goto err;
103+
}
104+
105+
ptdev->pm_domain_links[i] = device_link_add(ptdev->base.dev,
106+
ptdev->pm_domain_devs[i], DL_FLAG_PM_RUNTIME |
107+
DL_FLAG_STATELESS | DL_FLAG_RPM_ACTIVE);
108+
if (!ptdev->pm_domain_links[i]) {
109+
dev_err(ptdev->pm_domain_devs[i],
110+
"adding device link failed!\n");
111+
err = -ENODEV;
112+
goto err;
113+
}
114+
}
115+
} else {
116+
ptdev->pm_domain_devs[1]= fwnode_dev_pm_domain_attach_by_name(ptdev->base.dev, "perf");
117+
if (IS_ERR_OR_NULL(ptdev->pm_domain_devs[1])) {
118+
err = PTR_ERR(ptdev->pm_domain_devs[1]) ? : -ENODATA;
119+
ptdev->pm_domain_devs[1] = NULL;
106120
dev_err(ptdev->base.dev,
107-
"failed to get pm-domain %d: %d\n",
108-
i, err);
121+
"failed to get acpi perf domain %d\n", err);
109122
goto err;
110123
}
111124

112-
ptdev->pm_domain_links[i] = device_link_add(ptdev->base.dev,
113-
ptdev->pm_domain_devs[i], DL_FLAG_PM_RUNTIME |
114-
DL_FLAG_STATELESS | DL_FLAG_RPM_ACTIVE);
115-
if (!ptdev->pm_domain_links[i]) {
116-
dev_err(ptdev->pm_domain_devs[i],
117-
"adding device link failed!\n");
125+
ptdev->pm_domain_links[1] = device_link_add(ptdev->base.dev,
126+
ptdev->pm_domain_devs[1], DL_FLAG_PM_RUNTIME |
127+
DL_FLAG_STATELESS | DL_FLAG_RPM_ACTIVE);
128+
if (!ptdev->pm_domain_links[1]) {
129+
dev_err(ptdev->base.dev, "Failed to add device_link to gpu perf domain.\n");
130+
err = -ENODEV;
131+
goto err;
132+
}
133+
134+
struct fwnode_handle *fwnode = fwnode_find_reference(ptdev->base.dev->fwnode, "power-supply", 0);
135+
if (IS_ERR_OR_NULL(fwnode)) {
136+
dev_warn(ptdev->base.dev, "Failed to get power-supply property, using single power domain.\n");
137+
return 0;
138+
}
139+
ptdev->pm_domain_devs[0] = bus_find_device_by_fwnode(&platform_bus_type, fwnode);
140+
pm_runtime_enable(ptdev->pm_domain_devs[0]);
141+
dev_pm_domain_attach(ptdev->pm_domain_devs[0], true);
142+
fwnode_handle_put(fwnode);
143+
144+
ptdev->pm_domain_links[0] = device_link_add(ptdev->base.dev,
145+
ptdev->pm_domain_devs[0], DL_FLAG_PM_RUNTIME |
146+
DL_FLAG_STATELESS | DL_FLAG_RPM_ACTIVE);
147+
if (!ptdev->pm_domain_links[0]) {
148+
dev_err(ptdev->base.dev, "Failed to add device_link to gpu power domain.\n");
118149
err = -ENODEV;
119150
goto err;
120151
}
@@ -567,9 +598,7 @@ int panthor_device_resume(struct device *dev)
567598
reset_control_deassert(ptdev->gpu_reset);
568599

569600
/* CIX SKY1 have custom devfreq, let's force max for now (XXX: devfreq) */
570-
if (of_device_is_compatible(ptdev->base.dev->of_node, "arm,mali-valhall")) {
571-
dev_pm_genpd_set_performance_state(ptdev->pm_domain_devs[1], 1000);
572-
}
601+
dev_pm_genpd_set_performance_state(ptdev->pm_domain_devs[1], 1000);
573602

574603
ret = panthor_devfreq_resume(ptdev);
575604
if (ret)

drivers/gpu/drm/panthor/panthor_device.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <linux/reset.h>
1313
#include <linux/sched.h>
1414
#include <linux/spinlock.h>
15+
#include <linux/acpi.h>
1516

1617
#include <drm/drm_device.h>
1718
#include <drm/drm_mm.h>

drivers/gpu/drm/panthor/panthor_drv.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1581,6 +1581,11 @@ static const struct of_device_id dt_match[] = {
15811581
};
15821582
MODULE_DEVICE_TABLE(of, dt_match);
15831583

1584+
static const struct acpi_device_id kbase_acpi_ids[] = {
1585+
{ .id = "CIXH5000", .driver_data = 0 },
1586+
{ /* sentinel */ } };
1587+
MODULE_DEVICE_TABLE(acpi, kbase_acpi_ids);
1588+
15841589
static DEFINE_RUNTIME_DEV_PM_OPS(panthor_pm_ops,
15851590
panthor_device_suspend,
15861591
panthor_device_resume,
@@ -1593,6 +1598,7 @@ static struct platform_driver panthor_driver = {
15931598
.name = "panthor",
15941599
.pm = pm_ptr(&panthor_pm_ops),
15951600
.of_match_table = dt_match,
1601+
.acpi_match_table = ACPI_PTR(kbase_acpi_ids),
15961602
.dev_groups = panthor_groups,
15971603
},
15981604
};

drivers/gpu/drm/panthor/panthor_fw.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1369,7 +1369,11 @@ int panthor_fw_init(struct panthor_device *ptdev)
13691369
INIT_LIST_HEAD(&fw->sections);
13701370
INIT_DELAYED_WORK(&fw->watchdog.ping_work, panthor_fw_ping_work);
13711371

1372-
irq = platform_get_irq_byname(to_platform_device(ptdev->base.dev), "JOB");
1372+
if (has_acpi_companion(ptdev->base.dev))
1373+
irq = platform_get_irq(to_platform_device(ptdev->base.dev), 0);
1374+
else
1375+
irq = platform_get_irq_byname(to_platform_device(ptdev->base.dev), "JOB");
1376+
13731377
if (irq <= 0)
13741378
return -ENODEV;
13751379

drivers/gpu/drm/panthor/panthor_gpu.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,11 @@ int panthor_gpu_init(struct panthor_device *ptdev)
222222
if (ret)
223223
return ret;
224224

225-
irq = platform_get_irq_byname(to_platform_device(ptdev->base.dev), "GPU");
225+
if (has_acpi_companion(ptdev->base.dev))
226+
irq = platform_get_irq(to_platform_device(ptdev->base.dev), 2);
227+
else
228+
irq = platform_get_irq_byname(to_platform_device(ptdev->base.dev), "GPU");
229+
226230
if (irq < 0)
227231
return irq;
228232

@@ -378,7 +382,6 @@ int panthor_gpu_l2_power_on(struct panthor_device *ptdev)
378382
}
379383

380384
/* CIX SKY1 needs a special PHBA setup before L2 activation */
381-
if (of_device_is_compatible(ptdev->base.dev->of_node, "arm,mali-valhall")) {
382385
gpu_write(ptdev, GPU_SYSC_PBHA_OVERRIDE(3), 0x22000000);
383386
gpu_write(ptdev, GPU_SYSC_ALLOC(0), 0x00230000);
384387
gpu_write(ptdev, GPU_SYSC_ALLOC(1), 0x00000023);
@@ -395,7 +398,6 @@ int panthor_gpu_l2_power_on(struct panthor_device *ptdev)
395398
gpu_write(ptdev, 0x307C, 0xFFFFFFFF);
396399
gpu_write(ptdev, 0x3074, 0xFFFFFFFF);
397400
gpu_write(ptdev, 0x3068, 0x1);
398-
}
399401

400402
return panthor_gpu_power_on(ptdev, L2, 1, 20000);
401403
}
@@ -460,10 +462,8 @@ int panthor_gpu_soft_reset(struct panthor_device *ptdev)
460462
ptdev->gpu->pending_reqs |= GPU_IRQ_RESET_COMPLETED;
461463
gpu_write(ptdev, GPU_INT_CLEAR, GPU_IRQ_RESET_COMPLETED);
462464

463-
if (of_device_is_compatible(ptdev->base.dev->of_node, "arm,mali-valhall")) {
464-
gpu_write(ptdev, GPU_PWR_KEY, GPU_PWR_KEY_UNLOCK);
465-
gpu_write(ptdev, GPU_PWR_OVERRIDE1, 0xFFFFFF);
466-
}
465+
gpu_write(ptdev, GPU_PWR_KEY, GPU_PWR_KEY_UNLOCK);
466+
gpu_write(ptdev, GPU_PWR_OVERRIDE1, 0xFFFFFF);
467467

468468
gpu_write(ptdev, GPU_CMD, GPU_SOFT_RESET);
469469
}

drivers/gpu/drm/panthor/panthor_mmu.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2713,7 +2713,10 @@ int panthor_mmu_init(struct panthor_device *ptdev)
27132713

27142714
ptdev->mmu = mmu;
27152715

2716-
irq = platform_get_irq_byname(to_platform_device(ptdev->base.dev), "MMU");
2716+
if (has_acpi_companion(ptdev->base.dev))
2717+
irq = platform_get_irq(to_platform_device(ptdev->base.dev), 1);
2718+
else
2719+
irq = platform_get_irq_byname(to_platform_device(ptdev->base.dev), "MMU");
27172720
if (irq <= 0)
27182721
return -ENODEV;
27192722

0 commit comments

Comments
 (0)