From patchwork Wed May 12 11:49:38 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ajay Kumar Gupta X-Patchwork-Id: 98997 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter.kernel.org (8.14.3/8.14.3) with ESMTP id o4CBo0Bk030402 for ; Wed, 12 May 2010 11:50:01 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932075Ab0ELLt4 (ORCPT ); Wed, 12 May 2010 07:49:56 -0400 Received: from arroyo.ext.ti.com ([192.94.94.40]:53936 "EHLO arroyo.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755669Ab0ELLtp (ORCPT ); Wed, 12 May 2010 07:49:45 -0400 Received: from dbdp31.itg.ti.com ([172.24.170.98]) by arroyo.ext.ti.com (8.13.7/8.13.7) with ESMTP id o4CBnf5f001642 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Wed, 12 May 2010 06:49:44 -0500 Received: from psplinux050.india.ti.com (localhost [127.0.0.1]) by dbdp31.itg.ti.com (8.13.8/8.13.8) with ESMTP id o4CBneBW016176; Wed, 12 May 2010 17:19:40 +0530 (IST) Received: from psplinux050.india.ti.com (localhost [127.0.0.1]) by psplinux050.india.ti.com (8.13.1/8.13.1) with ESMTP id o4CBnd71000554; Wed, 12 May 2010 17:19:39 +0530 Received: (from a0393629@localhost) by psplinux050.india.ti.com (8.13.1/8.13.1/Submit) id o4CBndtO000546; Wed, 12 May 2010 17:19:39 +0530 From: Ajay Kumar Gupta To: linux-usb@vger.kernel.org Cc: linux-omap@vger.kernel.org, Ajay Kumar Gupta Subject: [PATCH 4/5] musb: use system DMA for unaligned buffers on RTL >= 1.8 Date: Wed, 12 May 2010 17:19:38 +0530 Message-Id: <1273664979-493-4-git-send-email-ajay.gupta@ti.com> X-Mailer: git-send-email 1.6.2.4 In-Reply-To: <1273664979-493-3-git-send-email-ajay.gupta@ti.com> References: <1273664979-493-1-git-send-email-ajay.gupta@ti.com> <1273664979-493-2-git-send-email-ajay.gupta@ti.com> <1273664979-493-3-git-send-email-ajay.gupta@ti.com> Sender: linux-omap-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-omap@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter.kernel.org [140.211.167.41]); Wed, 12 May 2010 11:50:01 +0000 (UTC) diff --git a/drivers/usb/musb/Kconfig b/drivers/usb/musb/Kconfig index f847fe2..05db0ff 100644 --- a/drivers/usb/musb/Kconfig +++ b/drivers/usb/musb/Kconfig @@ -166,6 +166,12 @@ config MUSB_USE_SYSTEM_DMA_WORKAROUND DMA channels are simultaneously enabled. To work around this issue, you can choose to use System DMA for RX channels. + Also on Mentor DMA in MUSB RTL version 1.8 (OMAP3630, AM/DM37x) + requires buffers to be aligned on a four byte boundary. This affects + USB CDC/RNDIS class application where buffers are always unaligned. + To work around this issue, you can choose to use System DMA for + unaligned buffers. + config USB_TI_CPPI_DMA bool depends on USB_MUSB_HDRC && !MUSB_PIO_ONLY diff --git a/drivers/usb/musb/musb_gadget.c b/drivers/usb/musb/musb_gadget.c index 6fca870..9ac45e4 100644 --- a/drivers/usb/musb/musb_gadget.c +++ b/drivers/usb/musb/musb_gadget.c @@ -317,6 +317,22 @@ static void txstate(struct musb *musb, struct musb_request *req) else musb_ep->dma->desired_mode = 1; + /* + * Use system dma for unaligned buffers on RTL >= 1.8 + * for Inventra DMA. As system DMA can work only in + * mode-0 so update the desired_mode and request_size. + */ + if (is_inventra_dma_enabled() && + ((request->dma + request->actual) & 0x3) && + (musb->hwvers >= MUSB_HWVERS_1800)) { + + request_size = min_t(size_t, + musb_ep->hw_ep->max_packet_sz_tx, + request->length - request->actual); + + musb_ep->dma->desired_mode = 0; + } + use_dma = use_dma && c->channel_program( musb_ep->dma, musb_ep->packet_sz, musb_ep->dma->desired_mode, @@ -463,7 +479,6 @@ void musb_g_tx(struct musb *musb, u8 epnum) u8 is_dma = 0; if (dma && (csr & MUSB_TXCSR_DMAENAB)) { - is_dma = 1; csr |= MUSB_TXCSR_P_WZC_BITS; csr &= ~(MUSB_TXCSR_DMAENAB | MUSB_TXCSR_P_UNDERRUN | MUSB_TXCSR_TXPKTRDY); @@ -471,6 +486,10 @@ void musb_g_tx(struct musb *musb, u8 epnum) /* Ensure writebuffer is empty. */ csr = musb_readw(epio, MUSB_TXCSR); request->actual += musb_ep->dma->actual_len; + + if (request->actual == request->length) + is_dma = 1; + DBG(4, "TXCSR%d %04x, DMA off, len %zu, req %p\n", epnum, csr, musb_ep->dma->actual_len, request); } diff --git a/drivers/usb/musb/musbhsdma.c b/drivers/usb/musb/musbhsdma.c index 70342eb..6118d5f 100644 --- a/drivers/usb/musb/musbhsdma.c +++ b/drivers/usb/musb/musbhsdma.c @@ -54,12 +54,18 @@ static void musb_sysdma_completion(int lch, u16 ch_status, void *data) (struct musb_dma_channel *) data; struct musb_dma_controller *controller = musb_channel->controller; struct musb *musb = controller->private_data; + void __iomem *mbase = controller->base; + channel = &musb_channel->channel; DBG(2, "lch = 0x%d, ch_status = 0x%x\n", lch, ch_status); spin_lock_irqsave(&musb->lock, flags); - addr = (u32) omap_get_dma_dst_pos(musb_channel->sysdma_channel); + if (musb_channel->transmit) + addr = (u32) omap_get_dma_src_pos(musb_channel->sysdma_channel); + else + addr = (u32) omap_get_dma_dst_pos(musb_channel->sysdma_channel); + if (musb_channel->len == 0) channel->actual_len = 0; else @@ -72,6 +78,26 @@ static void musb_sysdma_completion(int lch, u16 ch_status, void *data) "=> reconfig 0 " : " => complete"); channel->status = MUSB_DMA_STATUS_FREE; + + /* completed */ + if ((musb_channel->transmit) && (channel->desired_mode == 0) + && (channel->actual_len == musb_channel->max_packet_sz)) { + + u8 epnum = musb_channel->epnum; + int offset = MUSB_EP_OFFSET(epnum, + MUSB_TXCSR); + u16 txcsr; + + /* + * The programming guide says that we + * must clear DMAENAB before DMAMODE. + */ + musb_ep_select(mbase, epnum); + txcsr = musb_readw(mbase, offset); + txcsr |= MUSB_TXCSR_TXPKTRDY; + musb_writew(mbase, offset, txcsr); + } + musb_dma_completion(musb, musb_channel->epnum, musb_channel->transmit); spin_unlock_irqrestore(&musb->lock, flags); @@ -138,8 +164,15 @@ static struct dma_channel *dma_channel_allocate(struct dma_controller *c, * issue when TX and RX DMA channels are simultaneously * enabled. To work around this issue, use system DMA * for all RX channels. + * Also on MUSB RTL version 1.8 onward (OMAP3630, OMAP4 + * and AM/DM37x) DMA requires buffers to be aligned on + * a four byte boundary. This affects USB CDC/RNDIS + * class application where buffers are always unaligned. + * Using system DMA for unaligned buffers as a + * workaround for this issue. */ - if (((musb->hwvers == MUSB_HWVERS_1400) && !transmit) + if ((((musb->hwvers == MUSB_HWVERS_1400) && !transmit) + || (musb->hwvers >= MUSB_HWVERS_1800)) && use_sdma_workaround()) { int ret; ret = omap_request_dma(OMAP24XX_DMA_NO_DEVICE, @@ -194,11 +227,18 @@ static void configure_channel(struct dma_channel *channel, struct musb *musb = controller->private_data; void __iomem *mbase = controller->base; u8 bchannel = musb_channel->idx; + u8 buffer_is_aligned = (dma_addr & 0x3) ? 0 : 1; + u8 use_sdma = (musb_channel->sysdma_channel == -1) ? 0 : 1; u16 csr = 0; DBG(4, "%p, pkt_sz %d, addr 0x%x, len %d, mode %d\n", channel, packet_sz, dma_addr, len, mode); - if (musb_channel->sysdma_channel != -1) { + + if (buffer_is_aligned && (packet_sz >= 512) && + (musb->hwvers >= MUSB_HWVERS_1800)) + use_sdma = 0; + + if (use_sdma && !musb_channel->transmit) { /* System DMA */ /* RX: set src = FIFO */ omap_set_dma_transfer_params(musb_channel->sysdma_channel, @@ -224,6 +264,32 @@ static void configure_channel(struct dma_channel *channel, omap_start_dma(musb_channel->sysdma_channel); + } else if (use_sdma && musb_channel->transmit) { + /* System DMA */ + /* TX: set dst = FIFO */ + omap_set_dma_transfer_params(musb_channel->sysdma_channel, + OMAP_DMA_DATA_TYPE_S8, + len ? len : 1, 1, /* One frame */ + OMAP_DMA_SYNC_ELEMENT, + OMAP24XX_DMA_NO_DEVICE, + 0); /* Src Sync */ + + omap_set_dma_src_params(musb_channel->sysdma_channel, 0, + OMAP_DMA_AMODE_POST_INC, dma_addr, + 0, 0); + + omap_set_dma_dest_params(musb_channel->sysdma_channel, 0, + OMAP_DMA_AMODE_CONSTANT, + MUSB_FIFO_ADDRESS(musb->ctrl_phys_base, + musb_channel->epnum), + 0, 0); + + omap_set_dma_dest_data_pack(musb_channel->sysdma_channel, 0); + omap_set_dma_dest_burst_mode(musb_channel->sysdma_channel, + OMAP_DMA_DATA_BURST_DIS); + + omap_start_dma(musb_channel->sysdma_channel); + } else { /* Mentor DMA */ if (mode) { @@ -299,6 +365,9 @@ static int dma_channel_abort(struct dma_channel *channel) if (channel->status == MUSB_DMA_STATUS_BUSY) { if (musb_channel->transmit) { + if (musb_channel->sysdma_channel != -1) + omap_stop_dma(musb_channel->sysdma_channel); + offset = MUSB_EP_OFFSET(musb_channel->epnum, MUSB_TXCSR);