From patchwork Thu Mar 6 09:19:55 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Santosh Shilimkar X-Patchwork-Id: 25791 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-yh0-f71.google.com (mail-yh0-f71.google.com [209.85.213.71]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 6DAF5203C3 for ; Thu, 6 Mar 2014 09:23:17 +0000 (UTC) Received: by mail-yh0-f71.google.com with SMTP id v1sf5875941yhn.10 for ; Thu, 06 Mar 2014 01:23:17 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:sender:precedence:list-id :x-original-sender:x-original-authentication-results:mailing-list :list-post:list-help:list-archive:list-unsubscribe:content-type; bh=zXeTFlwyNPfofw2hpGzCuE7tfo+5Xlcby4HTi5CttAI=; b=jauIR+sWEUabFold1/p2sF52N2blxXY2CEQbDUGqFy1Z5biZZIEJAS24CsB5Ed4dYx RjOanfobD1JcmfFClgHIgmj4o3yEma1EhKZBmsSGMA8emslCr3rnZN21YIPo8T9KjcJo AE2XGKyjUgoZ2PIXM0mKGxNfRfKedAKEz4XZWgqwNYeUmIiEDs5t9Orh52Ig8LyCySfo plFzfiIXthQjjkgi4tFKJbuY5EMYe+9BKnfDMOe0KtNPhkVq5ATYfS4uvPm4pv7znYyb SvPrFXbkzDSYmVhCWR1g4p6eEFtKipkSf+7QRdTBmP6t5sPziO8FK2LnEu/v536o96kd 6B4g== X-Gm-Message-State: ALoCoQk5KUf+JtA+3IZrzwJpjVk/AXgaenLiFhiHblAvfMWDNU//lpcSH/UavGet5m49v3wdy1MV X-Received: by 10.224.163.71 with SMTP id z7mr4870839qax.5.1394097797072; Thu, 06 Mar 2014 01:23:17 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.87.241 with SMTP id r104ls700257qgd.98.gmail; Thu, 06 Mar 2014 01:23:16 -0800 (PST) X-Received: by 10.52.12.36 with SMTP id v4mr3508526vdb.20.1394097796937; Thu, 06 Mar 2014 01:23:16 -0800 (PST) Received: from mail-vc0-f170.google.com (mail-vc0-f170.google.com [209.85.220.170]) by mx.google.com with ESMTPS id tz5si1642761vdc.124.2014.03.06.01.23.16 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 06 Mar 2014 01:23:16 -0800 (PST) Received-SPF: neutral (google.com: 209.85.220.170 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.220.170; Received: by mail-vc0-f170.google.com with SMTP id hu8so2299268vcb.15 for ; Thu, 06 Mar 2014 01:23:16 -0800 (PST) X-Received: by 10.220.147.16 with SMTP id j16mr164104vcv.28.1394097796839; Thu, 06 Mar 2014 01:23:16 -0800 (PST) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.220.78.9 with SMTP id i9csp25218vck; Thu, 6 Mar 2014 01:23:16 -0800 (PST) X-Received: by 10.68.194.65 with SMTP id hu1mr13029982pbc.158.1394097795850; Thu, 06 Mar 2014 01:23:15 -0800 (PST) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id ey10si4518915pab.111.2014.03.06.01.23.14; Thu, 06 Mar 2014 01:23:14 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752993AbaCFJXI (ORCPT + 26 others); Thu, 6 Mar 2014 04:23:08 -0500 Received: from comal.ext.ti.com ([198.47.26.152]:33309 "EHLO comal.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752760AbaCFJVL (ORCPT ); Thu, 6 Mar 2014 04:21:11 -0500 Received: from dlelxv90.itg.ti.com ([172.17.2.17]) by comal.ext.ti.com (8.13.7/8.13.7) with ESMTP id s269KVKL031376; Thu, 6 Mar 2014 03:20:31 -0600 Received: from DLEE70.ent.ti.com (dlemailx.itg.ti.com [157.170.170.113]) by dlelxv90.itg.ti.com (8.14.3/8.13.8) with ESMTP id s269KVb3029391; Thu, 6 Mar 2014 03:20:31 -0600 Received: from dflp33.itg.ti.com (10.64.6.16) by DLEE70.ent.ti.com (157.170.170.113) with Microsoft SMTP Server id 14.3.174.1; Thu, 6 Mar 2014 03:20:31 -0600 Received: from ula0393909.itg.ti.com (ileax41-snat.itg.ti.com [10.172.224.153]) by dflp33.itg.ti.com (8.14.3/8.13.8) with ESMTP id s269K8N2031770; Thu, 6 Mar 2014 03:20:28 -0600 From: Santosh Shilimkar To: CC: , , Grygorii Strashko , Greg Kroah-Hartman , Russell King , Arnd Bergmann , Olof Johansson , Grant Likely , Rob Herring , Catalin Marinas , Linus Walleij , Santosh Shilimkar Subject: [PATCH 4/7] of: configure the platform device dma_mask and dma_pfn_offset Date: Thu, 6 Mar 2014 17:19:55 +0800 Message-ID: <1394097598-17622-5-git-send-email-santosh.shilimkar@ti.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1394097598-17622-1-git-send-email-santosh.shilimkar@ti.com> References: <1394097598-17622-1-git-send-email-santosh.shilimkar@ti.com> MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: santosh.shilimkar@ti.com X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.220.170 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , From: Grygorii Strashko Retrieve DMA configuration from DT and setup platform device's DMA parameters. The DMA configuration in DT has to be specified using "dma-ranges" property if supported. The DMA configuration applied by dt_dma_configure() as following: - call of_get_dma_range() and get supported DMA range info (dma_addr, cpu_addr, dma_size); - if "not found" then fill dma_mask as DMA_BIT_MASK(32) (this is default behaviour); - if "failed" then clean up dma_mask (DMA not supported) - if ok then update devices DMA configuration: set dma_mask to (dma_addr + dma_size - 1) set dma_pfn_offset to PFN_DOWN(cpu_addr - dma_addr) Cc: Greg Kroah-Hartman Cc: Russell King Cc: Arnd Bergmann Cc: Olof Johansson Cc: Grant Likely Cc: Rob Herring Cc: Catalin Marinas Cc: Linus Walleij Signed-off-by: Grygorii Strashko Signed-off-by: Santosh Shilimkar --- drivers/of/platform.c | 75 +++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 72 insertions(+), 3 deletions(-) diff --git a/drivers/of/platform.c b/drivers/of/platform.c index bd080db..53bb12f 100644 --- a/drivers/of/platform.c +++ b/drivers/of/platform.c @@ -187,6 +187,77 @@ struct platform_device *of_device_alloc(struct device_node *np, EXPORT_SYMBOL(of_device_alloc); /** + * dt_dma_configure - apply default DMA configuration from dt + * @dev: Device to apply DMA configuration + * + * Try to get devices's DMA configuration from DT and apply it. + * The DMA configuration is represented in DT by "dma-ranges" property. + * It configures: + * dma_pfn_offset, dma_mask and coherent_dma_mask. + * + * In case if DMA configuration can't be acquired from DT the default one is + * applied: + * dma_pfn_offset = 0, + * dma_mask = DMA_BIT_MASK(32) + * coherent_dma_mask = DMA_BIT_MASK(32). + * + * In case if platform code need to use own DMA configuration - it can use + * Platform bus notifier and handle BUS_NOTIFY_ADD_DEVICE event to fix up + * DMA configuration. + */ +static void dt_dma_configure(struct device *dev) +{ + dma_addr_t dma_addr; + phys_addr_t paddr, size; + dma_addr_t dma_mask; + int ret; + + /* + * if dma-ranges property doesn't exist - use 32 bits DMA mask + * by default and don't set skip archdata.dma_pfn_offset + */ + ret = of_dma_get_range(dev->of_node, &dma_addr, &paddr, &size); + if (ret == -ENODEV) { + dev->coherent_dma_mask = DMA_BIT_MASK(32); + if (!dev->dma_mask) + dev->dma_mask = &dev->coherent_dma_mask; + return; + } + + /* if failed - disable DMA for device */ + if (ret < 0) { + dev_err(dev, "failed to configure DMA\n"); + return; + } + + /* DMA ranges found. Calculate and set dma_pfn_offset */ + dev->dma_pfn_offset = PFN_DOWN(paddr - dma_addr); + + /* Configure DMA mask */ + dev->dma_mask = &dev->coherent_dma_mask; + if (!dev->dma_mask) + return; + + dma_mask = dma_addr + size - 1; + + ret = dma_set_mask(dev, dma_mask); + if (ret < 0) { + dev_err(dev, "failed to set DMA mask %pad\n", &dma_mask); + dev->dma_mask = NULL; + return; + } + + dev_dbg(dev, "dma_pfn_offset(%#08lx) dma_mask(%pad)\n", + dev->dma_pfn_offset, dev->dma_mask); + + ret = dma_set_coherent_mask(dev, dma_mask); + if (ret < 0) { + dev_err(dev, "failed to set coherent DMA mask %pad\n", + &dma_mask); + } +} + +/** * of_platform_device_create_pdata - Alloc, initialize and register an of_device * @np: pointer to node to create device for * @bus_id: name to assign device @@ -214,9 +285,7 @@ static struct platform_device *of_platform_device_create_pdata( #if defined(CONFIG_MICROBLAZE) dev->archdata.dma_mask = 0xffffffffUL; #endif - dev->dev.coherent_dma_mask = DMA_BIT_MASK(32); - if (!dev->dev.dma_mask) - dev->dev.dma_mask = &dev->dev.coherent_dma_mask; + dt_dma_configure(&dev->dev); dev->dev.bus = &platform_bus_type; dev->dev.platform_data = platform_data;