Skip to content

Commit 9502ffc

Browse files
stephan-ghvinodkoul
authored andcommitted
dmaengine: qcom: bam_dma: Add "powered remotely" mode
In some configurations, the BAM DMA controller is set up by a remote processor and the local processor can simply start making use of it without setting up the BAM. This is already supported using the "qcom,controlled-remotely" property. However, for some reason another possible configuration is that the remote processor is responsible for powering up the BAM, but we are still responsible for initializing it (e.g. resetting it etc). This configuration is quite challenging to handle properly because the power control is handled through separate channels (e.g. device-specific SMSM interrupts / smem-states). Great care must be taken to ensure the BAM registers are not accessed while the BAM is powered off since this results in a bus stall. Attempt to support this configuration with minimal device-specific code in the bam_dma driver by tracking the number of requested channels. Consumers of DMA channels are responsible to only request DMA channels when the BAM was powered on by the remote processor, and to release them before the BAM is powered off. When the first channel is requested the BAM is initialized (reset) and it is also put into reset when the last channel was released. Signed-off-by: Stephan Gerhold <[email protected]> Reviewed-by: Bhupesh Sharma <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Vinod Koul <[email protected]>
1 parent 37aef53 commit 9502ffc

File tree

1 file changed

+57
-33
lines changed

1 file changed

+57
-33
lines changed

drivers/dma/qcom/bam_dma.c

Lines changed: 57 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,8 @@ struct bam_device {
388388
/* execution environment ID, from DT */
389389
u32 ee;
390390
bool controlled_remotely;
391+
bool powered_remotely;
392+
u32 active_channels;
391393

392394
const struct reg_offset_data *layout;
393395

@@ -415,6 +417,44 @@ static inline void __iomem *bam_addr(struct bam_device *bdev, u32 pipe,
415417
r.ee_mult * bdev->ee;
416418
}
417419

420+
/**
421+
* bam_reset() - reset and initialize BAM registers
422+
* @bdev: bam device
423+
*/
424+
static void bam_reset(struct bam_device *bdev)
425+
{
426+
u32 val;
427+
428+
/* s/w reset bam */
429+
/* after reset all pipes are disabled and idle */
430+
val = readl_relaxed(bam_addr(bdev, 0, BAM_CTRL));
431+
val |= BAM_SW_RST;
432+
writel_relaxed(val, bam_addr(bdev, 0, BAM_CTRL));
433+
val &= ~BAM_SW_RST;
434+
writel_relaxed(val, bam_addr(bdev, 0, BAM_CTRL));
435+
436+
/* make sure previous stores are visible before enabling BAM */
437+
wmb();
438+
439+
/* enable bam */
440+
val |= BAM_EN;
441+
writel_relaxed(val, bam_addr(bdev, 0, BAM_CTRL));
442+
443+
/* set descriptor threshhold, start with 4 bytes */
444+
writel_relaxed(DEFAULT_CNT_THRSHLD,
445+
bam_addr(bdev, 0, BAM_DESC_CNT_TRSHLD));
446+
447+
/* Enable default set of h/w workarounds, ie all except BAM_FULL_PIPE */
448+
writel_relaxed(BAM_CNFG_BITS_DEFAULT, bam_addr(bdev, 0, BAM_CNFG_BITS));
449+
450+
/* enable irqs for errors */
451+
writel_relaxed(BAM_ERROR_EN | BAM_HRESP_ERR_EN,
452+
bam_addr(bdev, 0, BAM_IRQ_EN));
453+
454+
/* unmask global bam interrupt */
455+
writel_relaxed(BAM_IRQ_MSK, bam_addr(bdev, 0, BAM_IRQ_SRCS_MSK_EE));
456+
}
457+
418458
/**
419459
* bam_reset_channel - Reset individual BAM DMA channel
420460
* @bchan: bam channel
@@ -512,6 +552,9 @@ static int bam_alloc_chan(struct dma_chan *chan)
512552
return -ENOMEM;
513553
}
514554

555+
if (bdev->active_channels++ == 0 && bdev->powered_remotely)
556+
bam_reset(bdev);
557+
515558
return 0;
516559
}
517560

@@ -565,6 +608,13 @@ static void bam_free_chan(struct dma_chan *chan)
565608
/* disable irq */
566609
writel_relaxed(0, bam_addr(bdev, bchan->id, BAM_P_IRQ_EN));
567610

611+
if (--bdev->active_channels == 0 && bdev->powered_remotely) {
612+
/* s/w reset bam */
613+
val = readl_relaxed(bam_addr(bdev, 0, BAM_CTRL));
614+
val |= BAM_SW_RST;
615+
writel_relaxed(val, bam_addr(bdev, 0, BAM_CTRL));
616+
}
617+
568618
err:
569619
pm_runtime_mark_last_busy(bdev->dev);
570620
pm_runtime_put_autosuspend(bdev->dev);
@@ -1164,37 +1214,9 @@ static int bam_init(struct bam_device *bdev)
11641214
bdev->num_channels = val & BAM_NUM_PIPES_MASK;
11651215
}
11661216

1167-
if (bdev->controlled_remotely)
1168-
return 0;
1169-
1170-
/* s/w reset bam */
1171-
/* after reset all pipes are disabled and idle */
1172-
val = readl_relaxed(bam_addr(bdev, 0, BAM_CTRL));
1173-
val |= BAM_SW_RST;
1174-
writel_relaxed(val, bam_addr(bdev, 0, BAM_CTRL));
1175-
val &= ~BAM_SW_RST;
1176-
writel_relaxed(val, bam_addr(bdev, 0, BAM_CTRL));
1177-
1178-
/* make sure previous stores are visible before enabling BAM */
1179-
wmb();
1180-
1181-
/* enable bam */
1182-
val |= BAM_EN;
1183-
writel_relaxed(val, bam_addr(bdev, 0, BAM_CTRL));
1184-
1185-
/* set descriptor threshhold, start with 4 bytes */
1186-
writel_relaxed(DEFAULT_CNT_THRSHLD,
1187-
bam_addr(bdev, 0, BAM_DESC_CNT_TRSHLD));
1188-
1189-
/* Enable default set of h/w workarounds, ie all except BAM_FULL_PIPE */
1190-
writel_relaxed(BAM_CNFG_BITS_DEFAULT, bam_addr(bdev, 0, BAM_CNFG_BITS));
1191-
1192-
/* enable irqs for errors */
1193-
writel_relaxed(BAM_ERROR_EN | BAM_HRESP_ERR_EN,
1194-
bam_addr(bdev, 0, BAM_IRQ_EN));
1195-
1196-
/* unmask global bam interrupt */
1197-
writel_relaxed(BAM_IRQ_MSK, bam_addr(bdev, 0, BAM_IRQ_SRCS_MSK_EE));
1217+
/* Reset BAM now if fully controlled locally */
1218+
if (!bdev->controlled_remotely && !bdev->powered_remotely)
1219+
bam_reset(bdev);
11981220

11991221
return 0;
12001222
}
@@ -1257,8 +1279,10 @@ static int bam_dma_probe(struct platform_device *pdev)
12571279

12581280
bdev->controlled_remotely = of_property_read_bool(pdev->dev.of_node,
12591281
"qcom,controlled-remotely");
1282+
bdev->powered_remotely = of_property_read_bool(pdev->dev.of_node,
1283+
"qcom,powered-remotely");
12601284

1261-
if (bdev->controlled_remotely) {
1285+
if (bdev->controlled_remotely || bdev->powered_remotely) {
12621286
ret = of_property_read_u32(pdev->dev.of_node, "num-channels",
12631287
&bdev->num_channels);
12641288
if (ret)
@@ -1270,7 +1294,7 @@ static int bam_dma_probe(struct platform_device *pdev)
12701294
dev_err(bdev->dev, "num-ees unspecified in dt\n");
12711295
}
12721296

1273-
if (bdev->controlled_remotely)
1297+
if (bdev->controlled_remotely || bdev->powered_remotely)
12741298
bdev->bamclk = devm_clk_get_optional(bdev->dev, "bam_clk");
12751299
else
12761300
bdev->bamclk = devm_clk_get(bdev->dev, "bam_clk");

0 commit comments

Comments
 (0)