Skip to content

Commit 8200fe6

Browse files
hyqopsiff
authored andcommitted
gdma:phytium: Add ACPI support for GDMA driver
This patch used to support GDMA driver in ACPI mode. Signed-off-by: Wu Jinyong <wujinyong1788@phytium.com.cn> Signed-off-by: Wang Yinfeng <wangyinfeng@phytium.com.cn> Signed-off-by: Hu Yeqing <huyeqing2074@phytium.com.cn>
1 parent f0be3bb commit 8200fe6

1 file changed

Lines changed: 45 additions & 7 deletions

File tree

drivers/dma/phytium/phytium-gdmac.c

Lines changed: 45 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
* Copyright (c) 2023-2024 Phytium Technology Co., Ltd.
66
*/
77

8+
#include <linux/acpi.h>
9+
#include <linux/acpi_dma.h>
810
#include <linux/bitops.h>
911
#include <linux/delay.h>
1012
#include <linux/device.h>
@@ -29,7 +31,7 @@
2931
#include <asm/barrier.h>
3032
#include "phytium-gdmac.h"
3133

32-
#define PHYTIUM_GDMA_DRIVER_VERSION "1.0.1"
34+
#define PHYTIUM_GDMA_DRIVER_VERSION "1.0.2"
3335

3436
static inline struct phytium_gdma_device *to_gdma_device(struct dma_chan *chan)
3537
{
@@ -788,6 +790,32 @@ static struct dma_chan *phytium_gdma_of_xlate(struct of_phandle_args *dma_spec,
788790
return c;
789791
}
790792

793+
static struct dma_chan *phytium_gdma_acpi_xlate(struct acpi_dma_spec *dma_spec,
794+
struct acpi_dma *acpidma)
795+
{
796+
struct phytium_gdma_device *gdma = (struct phytium_gdma_device *)acpidma->data;
797+
struct device *dev = gdma->dev;
798+
struct phytium_gdma_chan *chan = NULL;
799+
struct dma_chan *c = NULL;
800+
u32 channel_id = 0;
801+
802+
channel_id = dma_spec->chan_id;
803+
804+
if (channel_id >= gdma->dma_channels) {
805+
dev_err(dev, "bad channel %d\n", channel_id);
806+
return NULL;
807+
}
808+
809+
chan = &gdma->chan[channel_id];
810+
c = &chan->vchan.chan;
811+
if (!c) {
812+
dev_err(dev, "no more channels available\n");
813+
return NULL;
814+
}
815+
816+
return c;
817+
}
818+
791819
static int phytium_gdma_probe(struct platform_device *pdev)
792820
{
793821
struct phytium_gdma_device *gdma;
@@ -826,17 +854,17 @@ static int phytium_gdma_probe(struct platform_device *pdev)
826854
goto out;
827855
}
828856

829-
ret = of_property_read_u32(pdev->dev.of_node, "dma-channels",
830-
&nr_channels);
857+
ret = device_property_read_u32(&pdev->dev, "dma-channels",
858+
&nr_channels);
831859
if (ret < 0) {
832860
dev_err(&pdev->dev,
833861
"can't get the number of dma channels: %d\n", ret);
834862
goto out;
835863
}
836864
gdma->dma_channels = nr_channels;
837865

838-
ret = of_property_read_u32(pdev->dev.of_node, "max-outstanding",
839-
&max_outstanding);
866+
ret = device_property_read_u32(&pdev->dev, "max-outstanding",
867+
&max_outstanding);
840868
if (ret < 0) {
841869
dev_err(&pdev->dev, "can't get max outstanding %d\n", ret);
842870
goto out;
@@ -917,8 +945,11 @@ static int phytium_gdma_probe(struct platform_device *pdev)
917945
if (ret)
918946
goto out;
919947

920-
ret = of_dma_controller_register(pdev->dev.of_node,
921-
phytium_gdma_of_xlate, gdma);
948+
if (has_acpi_companion(&pdev->dev))
949+
ret = acpi_dma_controller_register(&pdev->dev, phytium_gdma_acpi_xlate, gdma);
950+
else
951+
ret = of_dma_controller_register(pdev->dev.of_node,
952+
phytium_gdma_of_xlate, gdma);
922953
if (ret < 0) {
923954
dev_err(&pdev->dev,
924955
"phytium gdma of register failed %d\n", ret);
@@ -999,12 +1030,19 @@ static const struct of_device_id phytium_dma_of_id_table[] = {
9991030
};
10001031
MODULE_DEVICE_TABLE(of, phytium_dma_of_id_table);
10011032

1033+
static const struct acpi_device_id phytium_gdma_acpi_match[] = {
1034+
{ "PHYT0026", 0 },
1035+
{ }
1036+
};
1037+
MODULE_DEVICE_TABLE(acpi, phytium_gdma_acpi_match);
1038+
10021039
static struct platform_driver phytium_gdma_driver = {
10031040
.probe = phytium_gdma_probe,
10041041
.remove = phytium_gdma_remove,
10051042
.driver = {
10061043
.name = "phytium-gdma",
10071044
.of_match_table = of_match_ptr(phytium_dma_of_id_table),
1045+
.acpi_match_table = ACPI_PTR(phytium_gdma_acpi_match),
10081046
.pm = &phytium_gdma_pm_ops,
10091047
},
10101048
};

0 commit comments

Comments
 (0)