Skip to content

Commit 989e3af

Browse files
committed
Merge branch 'topic/k3dma' into for-linus
2 parents 8405448 + c4994a9 commit 989e3af

File tree

3 files changed

+59
-10
lines changed

3 files changed

+59
-10
lines changed

Documentation/devicetree/bindings/dma/dma.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ Optional properties:
1616
- dma-channels: Number of DMA channels supported by the controller.
1717
- dma-requests: Number of DMA request signals supported by the
1818
controller.
19+
- dma-channel-mask: Bitmask of available DMA channels in ascending order
20+
that are not reserved by firmware and are available to
21+
the kernel. i.e. first channel corresponds to LSB.
1922

2023
Example:
2124

@@ -29,6 +32,7 @@ Example:
2932
#dma-cells = <1>;
3033
dma-channels = <32>;
3134
dma-requests = <127>;
35+
dma-channel-mask = <0xfffe>
3236
};
3337

3438
* DMA router

Documentation/devicetree/bindings/dma/k3dma.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
See dma.txt first
44

55
Required properties:
6-
- compatible: Should be "hisilicon,k3-dma-1.0"
6+
- compatible: Must be one of
7+
- "hisilicon,k3-dma-1.0"
8+
- "hisilicon,hisi-pcm-asp-dma-1.0"
79
- reg: Should contain DMA registers location and length.
810
- interrupts: Should contain one interrupt shared by all channel
911
- #dma-cells: see dma.txt, should be 1, para number

drivers/dma/k3dma.c

Lines changed: 52 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,6 @@
5252
#define CX_SRC 0x814
5353
#define CX_DST 0x818
5454
#define CX_CFG 0x81c
55-
#define AXI_CFG 0x820
56-
#define AXI_CFG_DEFAULT 0x201201
5755

5856
#define CX_LLI_CHAIN_EN 0x2
5957
#define CX_CFG_EN 0x1
@@ -113,9 +111,18 @@ struct k3_dma_dev {
113111
struct dma_pool *pool;
114112
u32 dma_channels;
115113
u32 dma_requests;
114+
u32 dma_channel_mask;
116115
unsigned int irq;
117116
};
118117

118+
119+
#define K3_FLAG_NOCLK BIT(1)
120+
121+
struct k3dma_soc_data {
122+
unsigned long flags;
123+
};
124+
125+
119126
#define to_k3_dma(dmadev) container_of(dmadev, struct k3_dma_dev, slave)
120127

121128
static int k3_dma_config_write(struct dma_chan *chan,
@@ -161,7 +168,6 @@ static void k3_dma_set_desc(struct k3_dma_phy *phy, struct k3_desc_hw *hw)
161168
writel_relaxed(hw->count, phy->base + CX_CNT0);
162169
writel_relaxed(hw->saddr, phy->base + CX_SRC);
163170
writel_relaxed(hw->daddr, phy->base + CX_DST);
164-
writel_relaxed(AXI_CFG_DEFAULT, phy->base + AXI_CFG);
165171
writel_relaxed(hw->config, phy->base + CX_CFG);
166172
}
167173

@@ -314,6 +320,9 @@ static void k3_dma_tasklet(unsigned long arg)
314320
/* check new channel request in d->chan_pending */
315321
spin_lock_irq(&d->lock);
316322
for (pch = 0; pch < d->dma_channels; pch++) {
323+
if (!(d->dma_channel_mask & (1 << pch)))
324+
continue;
325+
317326
p = &d->phy[pch];
318327

319328
if (p->vchan == NULL && !list_empty(&d->chan_pending)) {
@@ -331,6 +340,9 @@ static void k3_dma_tasklet(unsigned long arg)
331340
spin_unlock_irq(&d->lock);
332341

333342
for (pch = 0; pch < d->dma_channels; pch++) {
343+
if (!(d->dma_channel_mask & (1 << pch)))
344+
continue;
345+
334346
if (pch_alloc & (1 << pch)) {
335347
p = &d->phy[pch];
336348
c = p->vchan;
@@ -790,8 +802,21 @@ static int k3_dma_transfer_resume(struct dma_chan *chan)
790802
return 0;
791803
}
792804

805+
static const struct k3dma_soc_data k3_v1_dma_data = {
806+
.flags = 0,
807+
};
808+
809+
static const struct k3dma_soc_data asp_v1_dma_data = {
810+
.flags = K3_FLAG_NOCLK,
811+
};
812+
793813
static const struct of_device_id k3_pdma_dt_ids[] = {
794-
{ .compatible = "hisilicon,k3-dma-1.0", },
814+
{ .compatible = "hisilicon,k3-dma-1.0",
815+
.data = &k3_v1_dma_data
816+
},
817+
{ .compatible = "hisilicon,hisi-pcm-asp-dma-1.0",
818+
.data = &asp_v1_dma_data
819+
},
795820
{}
796821
};
797822
MODULE_DEVICE_TABLE(of, k3_pdma_dt_ids);
@@ -810,6 +835,7 @@ static struct dma_chan *k3_of_dma_simple_xlate(struct of_phandle_args *dma_spec,
810835

811836
static int k3_dma_probe(struct platform_device *op)
812837
{
838+
const struct k3dma_soc_data *soc_data;
813839
struct k3_dma_dev *d;
814840
const struct of_device_id *of_id;
815841
struct resource *iores;
@@ -823,6 +849,10 @@ static int k3_dma_probe(struct platform_device *op)
823849
if (!d)
824850
return -ENOMEM;
825851

852+
soc_data = device_get_match_data(&op->dev);
853+
if (!soc_data)
854+
return -EINVAL;
855+
826856
d->base = devm_ioremap_resource(&op->dev, iores);
827857
if (IS_ERR(d->base))
828858
return PTR_ERR(d->base);
@@ -833,12 +863,21 @@ static int k3_dma_probe(struct platform_device *op)
833863
"dma-channels", &d->dma_channels);
834864
of_property_read_u32((&op->dev)->of_node,
835865
"dma-requests", &d->dma_requests);
866+
ret = of_property_read_u32((&op->dev)->of_node,
867+
"dma-channel-mask", &d->dma_channel_mask);
868+
if (ret) {
869+
dev_warn(&op->dev,
870+
"dma-channel-mask doesn't exist, considering all as available.\n");
871+
d->dma_channel_mask = (u32)~0UL;
872+
}
836873
}
837874

838-
d->clk = devm_clk_get(&op->dev, NULL);
839-
if (IS_ERR(d->clk)) {
840-
dev_err(&op->dev, "no dma clk\n");
841-
return PTR_ERR(d->clk);
875+
if (!(soc_data->flags & K3_FLAG_NOCLK)) {
876+
d->clk = devm_clk_get(&op->dev, NULL);
877+
if (IS_ERR(d->clk)) {
878+
dev_err(&op->dev, "no dma clk\n");
879+
return PTR_ERR(d->clk);
880+
}
842881
}
843882

844883
irq = platform_get_irq(op, 0);
@@ -862,8 +901,12 @@ static int k3_dma_probe(struct platform_device *op)
862901
return -ENOMEM;
863902

864903
for (i = 0; i < d->dma_channels; i++) {
865-
struct k3_dma_phy *p = &d->phy[i];
904+
struct k3_dma_phy *p;
905+
906+
if (!(d->dma_channel_mask & BIT(i)))
907+
continue;
866908

909+
p = &d->phy[i];
867910
p->idx = i;
868911
p->base = d->base + i * 0x40;
869912
}

0 commit comments

Comments
 (0)