From patchwork Wed Sep 20 07:35:12 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandre Bailon X-Patchwork-Id: 9961031 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 3D947600C5 for ; Wed, 20 Sep 2017 07:35:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3083028F7D for ; Wed, 20 Sep 2017 07:35:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 255E528FE9; Wed, 20 Sep 2017 07:35:30 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.3 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id ABF3A28F7D for ; Wed, 20 Sep 2017 07:35:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751819AbdITHf0 (ORCPT ); Wed, 20 Sep 2017 03:35:26 -0400 Received: from mail-wm0-f48.google.com ([74.125.82.48]:47887 "EHLO mail-wm0-f48.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751801AbdITHfX (ORCPT ); Wed, 20 Sep 2017 03:35:23 -0400 Received: by mail-wm0-f48.google.com with SMTP id 13so4542638wmq.2 for ; Wed, 20 Sep 2017 00:35:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=jBpLdRAGCqNoY+z6Cx6802AxNPCy3aZMn/hZGDQZ5V4=; b=bmfyb1J4UH4pKHm38h0MZnkztf6rflyRU6wE8uImGpcH26NYcwhRRGPC+/0aXzvpBt fM5nMx3lb15EtBz9PYoXBP9HO1e2X/H5l4CyP1udzQzozTR1UIJP5ZMc3fF7Q7Yncw6u n0dp0cnlzYXFjJAFG4X4FQMIg71MZz33ujEho/qTv+1ouYe7cXUVSbMWxlIY7KHq3+LL YWUPvRfxfSM6uHXRXEmPBwvyT7PT0O237giAVeLSoQuGPU9bwe7Wga7ldEQzMVEzJ7gC 9dUfOa+1mni4MmN8Tzfl8c1nB8wg5L4/5Gd6yDBeWm9b96kdZW/1cPetnT9VYK0F9Q+w +kVA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=jBpLdRAGCqNoY+z6Cx6802AxNPCy3aZMn/hZGDQZ5V4=; b=erBa60WrRY0LP6GrZmZthnmUHEn6B+jmvy7IjBMeLKls+3wvwM+w9Y44otZQHc3N5X tLr4qIsmisRGgyHs1oxxrzug9aMOkOWZdhJmIYJxgePnFpVBgVQdntV7zz5GQHs3lm0I 0EIOnsSOf4+tvsTuumop6mCErt898ABnUwUG2Phqur3xjbzgqYhwo86sIm4LwKOUYG/M 0kdmt3RY6JWR/r0dQSvDC2wPVi1TEjRCNeqe/W/25QtdhAVvWJtItmEZ1QIqrN9HhiQS XeZ88f41BPPWjBD67sj8Ig42vp618YvM/JKxWW7T9mDO8T5pfOecBJ2Tl1OKlJ4tIqbq r8rw== X-Gm-Message-State: AHPjjUiRuxe4D+8Zf4T7ziVIvaZ6sQ1l+jLK0NIlzQIClI2mVYro7IJg 3XCCS51f69GE3jY79XnHaHJRpQ== X-Google-Smtp-Source: AOwi7QDtp6zjo89+6U9qRLjYBaNy21PNhaGaiDs5r/nig9Y2a/5HSJIhlXV4xperaasnerUyOnBaSg== X-Received: by 10.28.224.4 with SMTP id x4mr3044303wmg.85.1505892922563; Wed, 20 Sep 2017 00:35:22 -0700 (PDT) Received: from localhost.localdomain (car75-h02-176-137-58-115.dsl.sta.abo.bbox.fr. [176.137.58.115]) by smtp.gmail.com with ESMTPSA id w14sm998875wmf.13.2017.09.20.00.35.21 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 20 Sep 2017 00:35:22 -0700 (PDT) From: Alexandre Bailon To: b-liu@ti.com Cc: linux-usb@vger.kernel.org, nsekhar@ti.com, ptitiano@baylibre.com, sergei.shtylyov@cogentembedded.com, linux-omap@vger.kernel.org, Alexandre Bailon Subject: [PATCH v2 3/4] usb: musb: musb_cppi41: Configure the number of channels for DA8xx Date: Wed, 20 Sep 2017 09:35:12 +0200 Message-Id: <20170920073513.11650-4-abailon@baylibre.com> X-Mailer: git-send-email 2.13.5 In-Reply-To: <20170920073513.11650-1-abailon@baylibre.com> References: <20170920073513.11650-1-abailon@baylibre.com> Sender: linux-omap-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-omap@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Currently, the number of channels is set to 15 but in the case of DA8xx, the number of channels is 4. Update the driver to configure the number of channels at runtime. Signed-off-by: Alexandre Bailon --- drivers/usb/musb/musb_cppi41.c | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/drivers/usb/musb/musb_cppi41.c b/drivers/usb/musb/musb_cppi41.c index b2b1306c01cf..2d1468cccae0 100644 --- a/drivers/usb/musb/musb_cppi41.c +++ b/drivers/usb/musb/musb_cppi41.c @@ -30,10 +30,12 @@ #define DA8XX_USB_AUTOREQ 0x14 #define DA8XX_USB_TEARDOWN 0x1c +#define DA8XX_DMA_NUM_CHANNELS 4 + struct cppi41_dma_controller { struct dma_controller controller; - struct cppi41_dma_channel rx_channel[MUSB_DMA_NUM_CHANNELS]; - struct cppi41_dma_channel tx_channel[MUSB_DMA_NUM_CHANNELS]; + struct cppi41_dma_channel *rx_channel; + struct cppi41_dma_channel *tx_channel; struct hrtimer early_tx; struct list_head early_tx_list; u32 rx_mode; @@ -45,6 +47,7 @@ struct cppi41_dma_controller { void (*set_dma_mode)(struct cppi41_dma_channel *cppi41_channel, unsigned int mode); + u8 num_channels; }; static void save_rx_toggle(struct cppi41_dma_channel *cppi41_channel) @@ -483,7 +486,7 @@ static struct dma_channel *cppi41_dma_channel_allocate(struct dma_controller *c, struct cppi41_dma_channel *cppi41_channel = NULL; u8 ch_num = hw_ep->epnum - 1; - if (ch_num >= MUSB_DMA_NUM_CHANNELS) + if (ch_num >= controller->num_channels) return NULL; if (is_tx) @@ -643,7 +646,7 @@ static void cppi41_release_all_dma_chans(struct cppi41_dma_controller *ctrl) struct dma_chan *dc; int i; - for (i = 0; i < MUSB_DMA_NUM_CHANNELS; i++) { + for (i = 0; i < ctrl->num_channels; i++) { dc = ctrl->tx_channel[i].dc; if (dc) dma_release_channel(dc); @@ -695,7 +698,7 @@ static int cppi41_dma_controller_start(struct cppi41_dma_controller *controller) goto err; ret = -EINVAL; - if (port > MUSB_DMA_NUM_CHANNELS || !port) + if (port > controller->num_channels || !port) goto err; if (is_tx) cppi41_channel = &controller->tx_channel[port - 1]; @@ -736,6 +739,8 @@ void cppi41_dma_controller_destroy(struct dma_controller *c) hrtimer_cancel(&controller->early_tx); cppi41_dma_controller_stop(controller); + kfree(controller->rx_channel); + kfree(controller->tx_channel); kfree(controller); } EXPORT_SYMBOL_GPL(cppi41_dma_controller_destroy); @@ -744,6 +749,7 @@ struct dma_controller * cppi41_dma_controller_create(struct musb *musb, void __iomem *base) { struct cppi41_dma_controller *controller; + int channel_size; int ret = 0; if (!musb->controller->parent->of_node) { @@ -770,18 +776,33 @@ cppi41_dma_controller_create(struct musb *musb, void __iomem *base) controller->tdown_reg = DA8XX_USB_TEARDOWN; controller->autoreq_reg = DA8XX_USB_AUTOREQ; controller->set_dma_mode = da8xx_set_dma_mode; + controller->num_channels = DA8XX_DMA_NUM_CHANNELS; } else { controller->tdown_reg = USB_TDOWN; controller->autoreq_reg = USB_CTRL_AUTOREQ; controller->set_dma_mode = cppi41_set_dma_mode; + controller->num_channels = MUSB_DMA_NUM_CHANNELS; } + channel_size = controller->num_channels * + sizeof(struct cppi41_dma_channel); + controller->rx_channel = kzalloc(channel_size, GFP_KERNEL); + if (controller->rx_channel) + goto rx_channel_alloc_fail; + controller->tx_channel = kzalloc(channel_size, GFP_KERNEL); + if (controller->tx_channel) + goto tx_channel_alloc_fail; + ret = cppi41_dma_controller_start(controller); if (ret) goto plat_get_fail; return &controller->controller; plat_get_fail: + kfree(controller->tx_channel); +tx_channel_alloc_fail: + kfree(controller->rx_channel); +rx_channel_alloc_fail: kfree(controller); kzalloc_fail: if (ret == -EPROBE_DEFER)