|
5 | 5 | * Copyright (c) 2023-2024 Phytium Technology Co., Ltd. |
6 | 6 | */ |
7 | 7 |
|
| 8 | +#include <linux/acpi.h> |
| 9 | +#include <linux/acpi_dma.h> |
8 | 10 | #include <linux/bitops.h> |
9 | 11 | #include <linux/delay.h> |
10 | 12 | #include <linux/device.h> |
|
29 | 31 | #include <asm/barrier.h> |
30 | 32 | #include "phytium-gdmac.h" |
31 | 33 |
|
32 | | -#define PHYTIUM_GDMA_DRIVER_VERSION "1.0.1" |
| 34 | +#define PHYTIUM_GDMA_DRIVER_VERSION "1.0.2" |
33 | 35 |
|
34 | 36 | static inline struct phytium_gdma_device *to_gdma_device(struct dma_chan *chan) |
35 | 37 | { |
@@ -788,6 +790,32 @@ static struct dma_chan *phytium_gdma_of_xlate(struct of_phandle_args *dma_spec, |
788 | 790 | return c; |
789 | 791 | } |
790 | 792 |
|
| 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 | + |
791 | 819 | static int phytium_gdma_probe(struct platform_device *pdev) |
792 | 820 | { |
793 | 821 | struct phytium_gdma_device *gdma; |
@@ -826,17 +854,17 @@ static int phytium_gdma_probe(struct platform_device *pdev) |
826 | 854 | goto out; |
827 | 855 | } |
828 | 856 |
|
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); |
831 | 859 | if (ret < 0) { |
832 | 860 | dev_err(&pdev->dev, |
833 | 861 | "can't get the number of dma channels: %d\n", ret); |
834 | 862 | goto out; |
835 | 863 | } |
836 | 864 | gdma->dma_channels = nr_channels; |
837 | 865 |
|
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); |
840 | 868 | if (ret < 0) { |
841 | 869 | dev_err(&pdev->dev, "can't get max outstanding %d\n", ret); |
842 | 870 | goto out; |
@@ -917,8 +945,11 @@ static int phytium_gdma_probe(struct platform_device *pdev) |
917 | 945 | if (ret) |
918 | 946 | goto out; |
919 | 947 |
|
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); |
922 | 953 | if (ret < 0) { |
923 | 954 | dev_err(&pdev->dev, |
924 | 955 | "phytium gdma of register failed %d\n", ret); |
@@ -999,12 +1030,19 @@ static const struct of_device_id phytium_dma_of_id_table[] = { |
999 | 1030 | }; |
1000 | 1031 | MODULE_DEVICE_TABLE(of, phytium_dma_of_id_table); |
1001 | 1032 |
|
| 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 | + |
1002 | 1039 | static struct platform_driver phytium_gdma_driver = { |
1003 | 1040 | .probe = phytium_gdma_probe, |
1004 | 1041 | .remove = phytium_gdma_remove, |
1005 | 1042 | .driver = { |
1006 | 1043 | .name = "phytium-gdma", |
1007 | 1044 | .of_match_table = of_match_ptr(phytium_dma_of_id_table), |
| 1045 | + .acpi_match_table = ACPI_PTR(phytium_gdma_acpi_match), |
1008 | 1046 | .pm = &phytium_gdma_pm_ops, |
1009 | 1047 | }, |
1010 | 1048 | }; |
|
0 commit comments