From patchwork Tue Oct 6 10:27:23 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 7334331 Return-Path: X-Original-To: patchwork-dmaengine@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 987A0BEEA4 for ; Tue, 6 Oct 2015 10:27:31 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 8168220619 for ; Tue, 6 Oct 2015 10:27:30 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 7749E20618 for ; Tue, 6 Oct 2015 10:27:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751616AbbJFK13 (ORCPT ); Tue, 6 Oct 2015 06:27:29 -0400 Received: from mail-la0-f54.google.com ([209.85.215.54]:35596 "EHLO mail-la0-f54.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751479AbbJFK12 (ORCPT ); Tue, 6 Oct 2015 06:27:28 -0400 Received: by laag4 with SMTP id g4so14725781laa.2 for ; Tue, 06 Oct 2015 03:27:27 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=Za0n3epfm14CzYlu2nCr7udVdp5tZkYBUyD8RTJRFgA=; b=jSW8fCQk+2Oo2skJvk/rThR9vJJEsPcxQIS7pHBP3Cr5cI9Pkf/UeG6y6terqAYL0W cg2L/8CXCWQ7AmdHy4A7X7bth+4o/Tj7enKSjGOPowchqHiTSXFQszE6gMlzT3d2m4S1 mg7jHVSiUzrHzgmXad21Q8T2Gagj4Vmc6Q0Y0f4Ttvr/QwX/COaaoMmjBMv7X+jIROWB wHAgiHx9OtBS7N2yCzFQ06CeziFMdIz1dlv8laqtXiRpID3EE//mJ+zpjttGnqGeoUaX LBaTiMQxEwc5znXKGUNBv3YS7/EL3lNQpx1J0LAt9Uta0zi0Dr44z8RzvIwVNO5Vf6Jg PAVA== X-Gm-Message-State: ALoCoQlZ6dEED2hFZwmGCfOj9K+sknBxCK5rhu5i7D+CQgz9gohqVGImna4tThtEy92hF5Rr1Pm0 X-Received: by 10.112.162.34 with SMTP id xx2mr14161323lbb.109.1444127247026; Tue, 06 Oct 2015 03:27:27 -0700 (PDT) Received: from localhost.localdomain.localdomain (c-297471d5.01-192-6c756e10.cust.bredbandsbolaget.se. [213.113.116.41]) by smtp.gmail.com with ESMTPSA id o195sm5171987lfe.17.2015.10.06.03.27.25 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 06 Oct 2015 03:27:26 -0700 (PDT) From: Linus Walleij To: Vinod Koul , dmaengine@vger.kernel.org, Joachim Eastwood Cc: Linus Walleij , Maxime Ripard Subject: [PATCH 2/3] dma: pl08x: allocate OF slave channel data at probe time Date: Tue, 6 Oct 2015 12:27:23 +0200 Message-Id: <1444127243-689-1-git-send-email-linus.walleij@linaro.org> X-Mailer: git-send-email 2.4.3 Sender: dmaengine-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: dmaengine@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The current OF translation of channels can never work with any DMA client using the DMA channels directly: the only way to get the channels initialized properly is in the dma_async_device_register() call, where chan->dev etc is allocated and initialized. Allocate and initialize all 32 possible DMA channels and only augment a target channel with the periph_buses at of_xlate(). Remove some const settings to make things work. Cc: Maxime Ripard Cc: Joachim Eastwood Signed-off-by: Linus Walleij --- Joachim: I think I need your teste-by on this to make sure the LPC machine survives this patch set. --- drivers/dma/amba-pl08x.c | 80 +++++++++++++++++++++++++++++----------------- include/linux/amba/pl08x.h | 2 +- 2 files changed, 52 insertions(+), 30 deletions(-) diff --git a/drivers/dma/amba-pl08x.c b/drivers/dma/amba-pl08x.c index dc864846f0a9..9420b9cdbf99 100644 --- a/drivers/dma/amba-pl08x.c +++ b/drivers/dma/amba-pl08x.c @@ -95,6 +95,13 @@ #define DRIVER_NAME "pl08xdmac" +/* + * The PL08X IP blocks has up to 32 routable hardware signals. Sometimes a MUX + * will be mounted on top of the signals to further extend the available DMA + * routes. + */ +#define PL08X_DMA_SIGNALS 32 + #define PL80X_DMA_BUSWIDTHS \ BIT(DMA_SLAVE_BUSWIDTH_UNDEFINED) | \ BIT(DMA_SLAVE_BUSWIDTH_1_BYTE) | \ @@ -241,7 +248,7 @@ struct pl08x_dma_chan { struct virt_dma_chan vc; struct pl08x_phy_chan *phychan; const char *name; - const struct pl08x_channel_data *cd; + struct pl08x_channel_data *cd; struct dma_slave_config cfg; struct pl08x_txd *at; struct pl08x_driver_data *host; @@ -2080,40 +2087,34 @@ static struct dma_chan *pl08x_of_xlate(struct of_phandle_args *dma_spec, struct of_dma *ofdma) { struct pl08x_driver_data *pl08x = ofdma->of_dma_data; - struct pl08x_channel_data *data; - struct pl08x_dma_chan *chan; struct dma_chan *dma_chan; if (!pl08x) return NULL; - if (dma_spec->args_count != 2) + if (dma_spec->args_count != 2) { + dev_err(&pl08x->adev->dev, + "DMA channel translation requires two cells\n"); return NULL; + } + /* Already allocated or coming from platform data */ dma_chan = pl08x_find_chan_id(pl08x, dma_spec->args[0]); - if (dma_chan) - return dma_get_slave_channel(dma_chan); - - chan = devm_kzalloc(pl08x->slave.dev, sizeof(*chan) + sizeof(*data), - GFP_KERNEL); - if (!chan) - return NULL; - - data = (void *)&chan[1]; - data->bus_id = "(none)"; - data->periph_buses = dma_spec->args[1]; - - chan->cd = data; - chan->host = pl08x; - chan->slave = true; - chan->name = data->bus_id; - chan->state = PL08X_CHAN_IDLE; - chan->signal = dma_spec->args[0]; - chan->vc.desc_free = pl08x_desc_free; + if (dma_chan) { + struct pl08x_dma_chan *plchan = to_pl08x_chan(dma_chan); - vchan_init(&chan->vc, &pl08x->slave); + dev_dbg(&pl08x->adev->dev, + "translated channel for signal %d\n", + dma_spec->args[0]); + /* Augment channel data for applicable AHB buses */ + plchan->cd->periph_buses = dma_spec->args[1]; + return dma_get_slave_channel(dma_chan); + } - return dma_get_slave_channel(&chan->vc.chan); + dev_err(&pl08x->adev->dev, + "can\'t find DMA slave channel for signal %d\n", + dma_spec->args[0]); + return NULL; } static int pl08x_of_probe(struct amba_device *adev, @@ -2121,9 +2122,11 @@ static int pl08x_of_probe(struct amba_device *adev, struct device_node *np) { struct pl08x_platform_data *pd; + struct pl08x_channel_data *chanp = NULL; u32 cctl_memcpy = 0; u32 val; int ret; + int i; pd = devm_kzalloc(&adev->dev, sizeof(*pd), GFP_KERNEL); if (!pd) @@ -2225,6 +2228,25 @@ static int pl08x_of_probe(struct amba_device *adev, /* Use the buses that can access memory, obviously */ pd->memcpy_channel.periph_buses = pd->mem_buses; + /* + * Allocate channel data for all possible slave channels (one for + * each possible signal), channels will then be allocated for a + * device and have it's AHB interfaces set up at translation time. + */ + chanp = devm_kzalloc(&adev->dev, + PL08X_DMA_SIGNALS * + sizeof(struct pl08x_channel_data), + GFP_KERNEL); + if (!chanp) + return -ENOMEM; + pd->slave_channels = chanp; + for (i = 0; i < PL08X_DMA_SIGNALS; i++) { + /* chanp->periph_buses will be assigned at translation */ + chanp->bus_id = kasprintf(GFP_KERNEL, "slave%d", i); + chanp++; + } + pd->num_slave_channels = PL08X_DMA_SIGNALS; + pl08x->pd = pd; return of_dma_controller_register(adev->dev.of_node, pl08x_of_xlate, @@ -2264,6 +2286,10 @@ static int pl08x_probe(struct amba_device *adev, const struct amba_id *id) goto out_no_pl08x; } + /* Assign useful pointers to the driver state */ + pl08x->adev = adev; + pl08x->vd = vd; + /* Initialize memcpy engine */ dma_cap_set(DMA_MEMCPY, pl08x->memcpy.cap_mask); pl08x->memcpy.dev = &adev->dev; @@ -2314,10 +2340,6 @@ static int pl08x_probe(struct amba_device *adev, const struct amba_id *id) } } - /* Assign useful pointers to the driver state */ - pl08x->adev = adev; - pl08x->vd = vd; - /* By default, AHB1 only. If dualmaster, from platform */ pl08x->lli_buses = PL08X_AHB1; pl08x->mem_buses = PL08X_AHB1; diff --git a/include/linux/amba/pl08x.h b/include/linux/amba/pl08x.h index 10fe2a211c2e..27e9ec8778eb 100644 --- a/include/linux/amba/pl08x.h +++ b/include/linux/amba/pl08x.h @@ -86,7 +86,7 @@ struct pl08x_channel_data { * @mem_buses: buses which memory can be accessed from: PL08X_AHB1 | PL08X_AHB2 */ struct pl08x_platform_data { - const struct pl08x_channel_data *slave_channels; + struct pl08x_channel_data *slave_channels; unsigned int num_slave_channels; struct pl08x_channel_data memcpy_channel; int (*get_xfer_signal)(const struct pl08x_channel_data *);