From: "Martin Povišer" <povik@cutebit.org>
To: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
Cc: "Martin Povišer" <povik+lin@cutebit.org>,
"Hector Martin" <marcan@marcan.st>,
"Sven Peter" <sven@svenpeter.dev>,
"Vinod Koul" <vkoul@kernel.org>,
"Rob Herring" <robh+dt@kernel.org>,
"Krzysztof Kozlowski" <krzk+dt@kernel.org>,
"Alyssa Rosenzweig" <alyssa@rosenzweig.io>,
linux-arm-kernel@lists.infradead.org, dmaengine@vger.kernel.org,
devicetree@vger.kernel.org, linux-kernel@vger.kernel.org,
"Mark Kettenis" <kettenis@openbsd.org>
Subject: Re: [PATCH 2/2] dmaengine: apple-admac: Add Apple ADMAC driver
Date: Thu, 31 Mar 2022 11:42:00 +0200 [thread overview]
Message-ID: <AA1C6D16-9016-4A11-9F90-C49A13FACBC0@cutebit.org> (raw)
In-Reply-To: <2b67081a-0b59-20d2-dbb5-a3e0b24862db@linaro.org>
> On 31. 3. 2022, at 8:25, Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org> wrote:
>
> On 30/03/2022 18:44, Martin Povišer wrote:
>> Add driver for Audio DMA Controller present on Apple SoCs from the
>> "Apple Silicon" family.
>>
>> Signed-off-by: Martin Povišer <povik+lin@cutebit.org>
>> ---
>> MAINTAINERS | 2 +
>> drivers/dma/Kconfig | 8 +
>> drivers/dma/Makefile | 1 +
>> drivers/dma/apple-admac.c | 799 ++++++++++++++++++++++++++++++++++++++
>> 4 files changed, 810 insertions(+)
>> create mode 100644 drivers/dma/apple-admac.c
>>
>
> (...)
>
>> +
>> +static void admac_poke(struct admac_data *ad, int reg, u32 val)
>> +{
>> + writel_relaxed(val, ad->base + reg);
>> +}
>> +
>> +static u32 admac_peek(struct admac_data *ad, int reg)
>> +{
>
> Please do not write some custom-named functions for common functions. No
> need to "#define true 0" or "#define read peek" etc. Read is read, write
> is write. Using other names is counter intuitive and makes reading the
> code more difficult.
>
> You actually should not have these wrappers because they don't make the
> code smaller (more arguments needed...).
>
> If you want the wrappers, please use regmap_mmio.
>
> Only modify wrapper save some space, so it could stay.
I get the aversion to custom naming, but I would rather keep the helpers.
Compare e.g.
admac_write(ad, REG_BUS_WIDTH(adchan->no), bus_width);
and
writel_relaxed(bus_width, ad->base + REG_BUS_WIDTH(adchan->no));
Although I guess as you said I may use regmap.
>> + return readl_relaxed(ad->base + reg);
>> +}
>> +
>> +static void admac_modify(struct admac_data *ad, int reg, u32 mask, u32 val)
>> +{
>> + void __iomem *addr = ad->base + reg;
>> + u32 curr = readl_relaxed(addr);
>> +
>> + writel_relaxed((curr & ~mask) | (val & mask), addr);
>> +}
>> +
>> +/*
>> + * Write one hardware descriptor for a dmaengine cyclic transaction.
>> + */
>> +static void admac_cyclic_write_one_desc(struct admac_data *ad, int channo,
>> + struct admac_tx *tx)
>> +{
>> + dma_addr_t addr;
>> +
>> + if (WARN_ON(!tx->cyclic))
>
> WARN_ON_ONCE() - although I wonder why do you need this. You fully
> control the callers to this function, don't you?
I do. Not really needed, just wanted to make it obvious we are operating
under that assumption. Can drop it then.
>> + return;
>> +
>> + addr = tx->buf_addr + (tx->submitted_pos % tx->buf_len);
>> + WARN_ON(addr + tx->period_len > tx->buf_end);
>
> If this is possible, you have buggy code. If this is not possible, why warn?
Well so if the code is buggy, I will get kicked right away here! Again,
happy to drop it then.
>> +
>> + dev_dbg(ad->dev, "ch%d descriptor: addr=0x%pad len=0x%zx flags=0x%x\n",
>> + channo, addr, tx->period_len, FLAG_DESC_NOTIFY);
>> +
>> + admac_poke(ad, REG_DESC_WRITE(channo), addr);
>> + admac_poke(ad, REG_DESC_WRITE(channo), addr >> 32);
>> + admac_poke(ad, REG_DESC_WRITE(channo), tx->period_len);
>> + admac_poke(ad, REG_DESC_WRITE(channo), FLAG_DESC_NOTIFY);
>> +
>> + tx->submitted_pos += tx->period_len;
>> + tx->submitted_pos %= 2 * tx->buf_len;
>> +}
(snip)
>> +static void admac_handle_status_err(struct admac_data *ad, int channo)
>> +{
>> + bool handled = false;
>> +
>> + if (admac_peek(ad, REG_DESC_RING(channo) & RING_ERR)) {
>> + admac_poke(ad, REG_DESC_RING(channo), RING_ERR);
>> + dev_err(ad->dev, "ch%d descriptor ring error\n", channo);
>
> It looks this is executed on every interrupt, so you might flood the
> dmesg. This should be ratelimited.
OK
>> + handled = true;
>> + }
>> +
>> + if (admac_peek(ad, REG_REPORT_RING(channo)) & RING_ERR) {
>> + admac_poke(ad, REG_REPORT_RING(channo), RING_ERR);
>> + dev_err(ad->dev, "ch%d report ring error\n", channo);
>> + handled = true;
>> + }
>> +
>> + if (unlikely(!handled)) {
>> + dev_err(ad->dev, "ch%d unknown error, masking errors as cause of IRQs\n", channo);
>> + admac_modify(ad, REG_CHAN_INTMASK(channo, ad->irq_index),
>> + STATUS_ERR, 0);
>> + }
>> +}
(snip)
>> +static int admac_probe(struct platform_device *pdev)
>> +{
>> + struct device_node *np = pdev->dev.of_node;
>> + struct admac_data *ad;
>> + struct dma_device *dma;
>> + int nchannels;
>> + int err, irq, i;
>> +
>> + err = of_property_read_u32(np, "dma-channels", &nchannels);
>> + if (err || nchannels > NCHANNELS_MAX) {
>> + dev_err(&pdev->dev, "missing or invalid dma-channels property\n");
>> + return -EINVAL;
>> + }
>> +
>> + ad = devm_kzalloc(&pdev->dev, struct_size(ad, channels, nchannels), GFP_KERNEL);
>> + if (!ad)
>> + return -ENOMEM;
>> +
>> + platform_set_drvdata(pdev, ad);
>> + ad->dev = &pdev->dev;
>> + ad->nchannels = nchannels;
>> +
>> + err = of_property_read_u32(np, "apple,internal-irq-destination",
>> + &ad->irq_index);
>> + if (err || ad->irq_index >= IRQ_NINDICES) {
>> + dev_err(&pdev->dev, "missing or invalid apple,internal-irq-destination property\n");
>> + return -EINVAL;
>> + }
>> +
>> + irq = platform_get_irq(pdev, 0);
>> + if (irq < 0) {
>> + dev_err(&pdev->dev, "unable to obtain interrupt resource\n");
>> + return irq;
>> + }
>> +
>> + err = devm_request_irq(&pdev->dev, irq, admac_interrupt,
>> + 0, dev_name(&pdev->dev), ad);
>
> Align the arguments with previous line. This applies everywhere in the
> driver.
I hope best-effort tab aligning is okay.
>> + if (err) {
>> + dev_err(&pdev->dev, "unable to register interrupt: %d\n", err);
>> + return err;
>> + }
>> +
>> + ad->base = devm_platform_ioremap_resource(pdev, 0);
>> + if (IS_ERR(ad->base)) {
>> + dev_err(&pdev->dev, "unable to obtain MMIO resource\n");
>> + return PTR_ERR(ad->base);
>> + }
>> +
>> + dma = &ad->dma;
>> +
>> + dma_cap_set(DMA_PRIVATE, dma->cap_mask);
>> + dma_cap_set(DMA_CYCLIC, dma->cap_mask);
>> +
>> + dma->dev = &pdev->dev;
>> + dma->device_alloc_chan_resources = admac_alloc_chan_resources;
>> + dma->device_free_chan_resources = admac_free_chan_resources;
>> + dma->device_tx_status = admac_tx_status;
>> + dma->device_issue_pending = admac_issue_pending;
>> + dma->device_terminate_all = admac_terminate_all;
>> + dma->device_prep_dma_cyclic = admac_prep_dma_cyclic;
>> + dma->device_config = admac_device_config;
>> + dma->device_pause = admac_pause;
>> + dma->device_resume = admac_resume;
>> +
>> + dma->directions = BIT(DMA_MEM_TO_DEV) | BIT(DMA_DEV_TO_MEM);
>> + dma->residue_granularity = DMA_RESIDUE_GRANULARITY_BURST;
>> + dma->dst_addr_widths = BIT(DMA_SLAVE_BUSWIDTH_1_BYTE) |
>> + BIT(DMA_SLAVE_BUSWIDTH_2_BYTES) |
>> + BIT(DMA_SLAVE_BUSWIDTH_4_BYTES);
>> +
>> + INIT_LIST_HEAD(&dma->channels);
>> + for (i = 0; i < nchannels; i++) {
>> + struct admac_chan *adchan = &ad->channels[i];
>> +
>> + adchan->host = ad;
>> + adchan->no = i;
>> + adchan->chan.device = &ad->dma;
>> + spin_lock_init(&adchan->lock);
>> + INIT_LIST_HEAD(&adchan->submitted);
>> + INIT_LIST_HEAD(&adchan->issued);
>> + list_add_tail(&adchan->chan.device_node, &dma->channels);
>> + tasklet_setup(&adchan->tasklet, admac_chan_tasklet);
>> + }
>> +
>> + err = dma_async_device_register(&ad->dma);
>> + if (err) {
>> + dev_err(&pdev->dev, "failed to register DMA device: %d\n", err);
>
> Use dev_err_probe() here and in other places.
Okay!
>> + return err;
>> + }
>> +
>> + err = of_dma_controller_register(pdev->dev.of_node, admac_dma_of_xlate, ad);
>> + if (err) {
>> + dev_err(&pdev->dev, "failed to register with OF: %d\n", err);
>> + dma_async_device_unregister(&ad->dma);
>> + return err;
>> + }
>> +
>> + dev_dbg(&pdev->dev, "all good, ready to go!\n");
>
> No debugging messages for simple probe success, please.
If you insist. :)
>
> Best regards,
> Krzysztof
Best, Martin
next prev parent reply other threads:[~2022-03-31 9:42 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-03-30 16:44 [PATCH 0/2] Apple ADMAC driver Martin Povišer
2022-03-30 16:44 ` [PATCH 1/2] dt-bindings: dma: Add Apple ADMAC Martin Povišer
2022-03-30 18:32 ` Rob Herring
2022-03-31 5:23 ` Vinod Koul
2022-03-31 6:50 ` Martin Povišer
2022-03-31 7:06 ` Martin Povišer
2022-03-31 14:10 ` Vinod Koul
2022-03-31 16:13 ` Martin Povišer
2022-03-31 17:21 ` Rob Herring
2022-03-31 19:09 ` Martin Povišer
2022-03-30 16:44 ` [PATCH 2/2] dmaengine: apple-admac: Add Apple ADMAC driver Martin Povišer
2022-03-31 6:25 ` Krzysztof Kozlowski
2022-03-31 9:42 ` Martin Povišer [this message]
2022-03-31 9:49 ` Krzysztof Kozlowski
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=AA1C6D16-9016-4A11-9F90-C49A13FACBC0@cutebit.org \
--to=povik@cutebit.org \
--cc=alyssa@rosenzweig.io \
--cc=devicetree@vger.kernel.org \
--cc=dmaengine@vger.kernel.org \
--cc=kettenis@openbsd.org \
--cc=krzk+dt@kernel.org \
--cc=krzysztof.kozlowski@linaro.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=marcan@marcan.st \
--cc=povik+lin@cutebit.org \
--cc=robh+dt@kernel.org \
--cc=sven@svenpeter.dev \
--cc=vkoul@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).