forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-01-31 f70575805708cabdedea7498aaa3f710fde4d920
kernel/drivers/dma/k3dma.c
....@@ -1,10 +1,7 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * Copyright (c) 2013 - 2015 Linaro Ltd.
34 * Copyright (c) 2013 Hisilicon Limited.
4
- *
5
- * This program is free software; you can redistribute it and/or modify
6
- * it under the terms of the GNU General Public License version 2 as
7
- * published by the Free Software Foundation.
85 */
96 #include <linux/sched.h>
107 #include <linux/device.h>
....@@ -52,8 +49,6 @@
5249 #define CX_SRC 0x814
5350 #define CX_DST 0x818
5451 #define CX_CFG 0x81c
55
-#define AXI_CFG 0x820
56
-#define AXI_CFG_DEFAULT 0x201201
5752
5853 #define CX_LLI_CHAIN_EN 0x2
5954 #define CX_CFG_EN 0x1
....@@ -87,10 +82,10 @@
8782 struct virt_dma_chan vc;
8883 struct k3_dma_phy *phy;
8984 struct list_head node;
90
- enum dma_transfer_direction dir;
9185 dma_addr_t dev_addr;
9286 enum dma_status status;
9387 bool cyclic;
88
+ struct dma_slave_config slave_config;
9489 };
9590
9691 struct k3_dma_phy {
....@@ -113,10 +108,23 @@
113108 struct dma_pool *pool;
114109 u32 dma_channels;
115110 u32 dma_requests;
111
+ u32 dma_channel_mask;
116112 unsigned int irq;
117113 };
118114
115
+
116
+#define K3_FLAG_NOCLK BIT(1)
117
+
118
+struct k3dma_soc_data {
119
+ unsigned long flags;
120
+};
121
+
122
+
119123 #define to_k3_dma(dmadev) container_of(dmadev, struct k3_dma_dev, slave)
124
+
125
+static int k3_dma_config_write(struct dma_chan *chan,
126
+ enum dma_transfer_direction dir,
127
+ struct dma_slave_config *cfg);
120128
121129 static struct k3_dma_chan *to_k3_chan(struct dma_chan *chan)
122130 {
....@@ -157,7 +165,6 @@
157165 writel_relaxed(hw->count, phy->base + CX_CNT0);
158166 writel_relaxed(hw->saddr, phy->base + CX_SRC);
159167 writel_relaxed(hw->daddr, phy->base + CX_DST);
160
- writel_relaxed(AXI_CFG_DEFAULT, phy->base + AXI_CFG);
161168 writel_relaxed(hw->config, phy->base + CX_CFG);
162169 }
163170
....@@ -290,9 +297,9 @@
290297 return -EAGAIN;
291298 }
292299
293
-static void k3_dma_tasklet(unsigned long arg)
300
+static void k3_dma_tasklet(struct tasklet_struct *t)
294301 {
295
- struct k3_dma_dev *d = (struct k3_dma_dev *)arg;
302
+ struct k3_dma_dev *d = from_tasklet(d, t, task);
296303 struct k3_dma_phy *p;
297304 struct k3_dma_chan *c, *cn;
298305 unsigned pch, pch_alloc = 0;
....@@ -316,6 +323,9 @@
316323 /* check new channel request in d->chan_pending */
317324 spin_lock_irq(&d->lock);
318325 for (pch = 0; pch < d->dma_channels; pch++) {
326
+ if (!(d->dma_channel_mask & (1 << pch)))
327
+ continue;
328
+
319329 p = &d->phy[pch];
320330
321331 if (p->vchan == NULL && !list_empty(&d->chan_pending)) {
....@@ -333,6 +343,9 @@
333343 spin_unlock_irq(&d->lock);
334344
335345 for (pch = 0; pch < d->dma_channels; pch++) {
346
+ if (!(d->dma_channel_mask & (1 << pch)))
347
+ continue;
348
+
336349 if (pch_alloc & (1 << pch)) {
337350 p = &d->phy[pch];
338351 c = p->vchan;
....@@ -507,14 +520,8 @@
507520 copy = min_t(size_t, len, DMA_MAX_SIZE);
508521 k3_dma_fill_desc(ds, dst, src, copy, num++, c->ccfg);
509522
510
- if (c->dir == DMA_MEM_TO_DEV) {
511
- src += copy;
512
- } else if (c->dir == DMA_DEV_TO_MEM) {
513
- dst += copy;
514
- } else {
515
- src += copy;
516
- dst += copy;
517
- }
523
+ src += copy;
524
+ dst += copy;
518525 len -= copy;
519526 } while (len);
520527
....@@ -548,6 +555,7 @@
548555 if (!ds)
549556 return NULL;
550557 num = 0;
558
+ k3_dma_config_write(chan, dir, &c->slave_config);
551559
552560 for_each_sg(sgl, sg, sglen, i) {
553561 addr = sg_dma_address(sg);
....@@ -608,6 +616,7 @@
608616 avail = buf_len;
609617 total = avail;
610618 num = 0;
619
+ k3_dma_config_write(chan, dir, &c->slave_config);
611620
612621 if (period_len < modulo)
613622 modulo = period_len;
....@@ -648,18 +657,26 @@
648657 struct dma_slave_config *cfg)
649658 {
650659 struct k3_dma_chan *c = to_k3_chan(chan);
660
+
661
+ memcpy(&c->slave_config, cfg, sizeof(*cfg));
662
+
663
+ return 0;
664
+}
665
+
666
+static int k3_dma_config_write(struct dma_chan *chan,
667
+ enum dma_transfer_direction dir,
668
+ struct dma_slave_config *cfg)
669
+{
670
+ struct k3_dma_chan *c = to_k3_chan(chan);
651671 u32 maxburst = 0, val = 0;
652672 enum dma_slave_buswidth width = DMA_SLAVE_BUSWIDTH_UNDEFINED;
653673
654
- if (cfg == NULL)
655
- return -EINVAL;
656
- c->dir = cfg->direction;
657
- if (c->dir == DMA_DEV_TO_MEM) {
674
+ if (dir == DMA_DEV_TO_MEM) {
658675 c->ccfg = CX_CFG_DSTINCR;
659676 c->dev_addr = cfg->src_addr;
660677 maxburst = cfg->src_maxburst;
661678 width = cfg->src_addr_width;
662
- } else if (c->dir == DMA_MEM_TO_DEV) {
679
+ } else if (dir == DMA_MEM_TO_DEV) {
663680 c->ccfg = CX_CFG_SRCINCR;
664681 c->dev_addr = cfg->dst_addr;
665682 maxburst = cfg->dst_maxburst;
....@@ -788,8 +805,21 @@
788805 return 0;
789806 }
790807
808
+static const struct k3dma_soc_data k3_v1_dma_data = {
809
+ .flags = 0,
810
+};
811
+
812
+static const struct k3dma_soc_data asp_v1_dma_data = {
813
+ .flags = K3_FLAG_NOCLK,
814
+};
815
+
791816 static const struct of_device_id k3_pdma_dt_ids[] = {
792
- { .compatible = "hisilicon,k3-dma-1.0", },
817
+ { .compatible = "hisilicon,k3-dma-1.0",
818
+ .data = &k3_v1_dma_data
819
+ },
820
+ { .compatible = "hisilicon,hisi-pcm-asp-dma-1.0",
821
+ .data = &asp_v1_dma_data
822
+ },
793823 {}
794824 };
795825 MODULE_DEVICE_TABLE(of, k3_pdma_dt_ids);
....@@ -808,20 +838,20 @@
808838
809839 static int k3_dma_probe(struct platform_device *op)
810840 {
841
+ const struct k3dma_soc_data *soc_data;
811842 struct k3_dma_dev *d;
812843 const struct of_device_id *of_id;
813
- struct resource *iores;
814844 int i, ret, irq = 0;
815
-
816
- iores = platform_get_resource(op, IORESOURCE_MEM, 0);
817
- if (!iores)
818
- return -EINVAL;
819845
820846 d = devm_kzalloc(&op->dev, sizeof(*d), GFP_KERNEL);
821847 if (!d)
822848 return -ENOMEM;
823849
824
- d->base = devm_ioremap_resource(&op->dev, iores);
850
+ soc_data = device_get_match_data(&op->dev);
851
+ if (!soc_data)
852
+ return -EINVAL;
853
+
854
+ d->base = devm_platform_ioremap_resource(op, 0);
825855 if (IS_ERR(d->base))
826856 return PTR_ERR(d->base);
827857
....@@ -831,12 +861,21 @@
831861 "dma-channels", &d->dma_channels);
832862 of_property_read_u32((&op->dev)->of_node,
833863 "dma-requests", &d->dma_requests);
864
+ ret = of_property_read_u32((&op->dev)->of_node,
865
+ "dma-channel-mask", &d->dma_channel_mask);
866
+ if (ret) {
867
+ dev_warn(&op->dev,
868
+ "dma-channel-mask doesn't exist, considering all as available.\n");
869
+ d->dma_channel_mask = (u32)~0UL;
870
+ }
834871 }
835872
836
- d->clk = devm_clk_get(&op->dev, NULL);
837
- if (IS_ERR(d->clk)) {
838
- dev_err(&op->dev, "no dma clk\n");
839
- return PTR_ERR(d->clk);
873
+ if (!(soc_data->flags & K3_FLAG_NOCLK)) {
874
+ d->clk = devm_clk_get(&op->dev, NULL);
875
+ if (IS_ERR(d->clk)) {
876
+ dev_err(&op->dev, "no dma clk\n");
877
+ return PTR_ERR(d->clk);
878
+ }
840879 }
841880
842881 irq = platform_get_irq(op, 0);
....@@ -860,8 +899,12 @@
860899 return -ENOMEM;
861900
862901 for (i = 0; i < d->dma_channels; i++) {
863
- struct k3_dma_phy *p = &d->phy[i];
902
+ struct k3_dma_phy *p;
864903
904
+ if (!(d->dma_channel_mask & BIT(i)))
905
+ continue;
906
+
907
+ p = &d->phy[i];
865908 p->idx = i;
866909 p->base = d->base + i * 0x40;
867910 }
....@@ -919,7 +962,7 @@
919962
920963 spin_lock_init(&d->lock);
921964 INIT_LIST_HEAD(&d->chan_pending);
922
- tasklet_init(&d->task, k3_dma_tasklet, (unsigned long)d);
965
+ tasklet_setup(&d->task, k3_dma_tasklet);
923966 platform_set_drvdata(op, d);
924967 dev_info(&op->dev, "initialized\n");
925968