From patchwork Sat Apr 19 14:32:49 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Santosh Shilimkar X-Patchwork-Id: 28659 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ig0-f198.google.com (mail-ig0-f198.google.com [209.85.213.198]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 4376120553 for ; Sat, 19 Apr 2014 14:34:39 +0000 (UTC) Received: by mail-ig0-f198.google.com with SMTP id h3sf1962497igd.5 for ; Sat, 19 Apr 2014 07:34:38 -0700 (PDT) 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=tY3z3ydSt/QJyvpu1o0x0uc6xO5SEIBu+LcccH57qyE=; b=lWVdnx4BQuqmGun+zmBtVvnePU9hbuk5Gdr12vIDGeMtS2L8aTYYEUEX5BegNgkxPa 85TGWbigfuOksveYTIQR//p8p7odmgf0VeosZ5+A+7Q0SoC4xwk0U1a7jgDRIafiWwXE XPN/hhErlYDYswY7F5sFBnHo0LZ1aXQHpYV82OkopEOzjbeM7tTXgS1YI3kTRXyWMkc7 YbLjcB6juUrbW+zzQ7+a6wRGVBoHtgZ/wLXujS8R4EbIiARZV+icnBCEByjC0L3zqrtk mOFGYDRZGO5IDUMxs2UX380W+MSRaw4u4ldSDxynMszFSTwmyjp2IEXGC1RR1MsxJUpG pwXA== X-Gm-Message-State: ALoCoQmLw/7PExGo3Qat7g0da7pg2DbzDR9BETUiMo/G02vPhsxcj8awWYwQ4lo95BhWFd8DaIdT X-Received: by 10.50.108.47 with SMTP id hh15mr4929646igb.3.1397918078760; Sat, 19 Apr 2014 07:34:38 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.101.213 with SMTP id u79ls88752qge.79.gmail; Sat, 19 Apr 2014 07:34:38 -0700 (PDT) X-Received: by 10.58.1.97 with SMTP id 1mr20105379vel.23.1397918078655; Sat, 19 Apr 2014 07:34:38 -0700 (PDT) Received: from mail-ve0-f178.google.com (mail-ve0-f178.google.com [209.85.128.178]) by mx.google.com with ESMTPS id ui2si5431640vdc.118.2014.04.19.07.34.38 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Sat, 19 Apr 2014 07:34:38 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.128.178 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.128.178; Received: by mail-ve0-f178.google.com with SMTP id jw12so4802891veb.23 for ; Sat, 19 Apr 2014 07:34:38 -0700 (PDT) X-Received: by 10.58.23.6 with SMTP id i6mr23405296vef.12.1397918078561; Sat, 19 Apr 2014 07:34:38 -0700 (PDT) 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.221.72 with SMTP id ib8csp182178vcb; Sat, 19 Apr 2014 07:34:37 -0700 (PDT) X-Received: by 10.69.20.107 with SMTP id hb11mr27434192pbd.99.1397918077364; Sat, 19 Apr 2014 07:34:37 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id pb4si17955895pac.154.2014.04.19.07.34.36; Sat, 19 Apr 2014 07:34:36 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of devicetree-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 S1754859AbaDSOef (ORCPT + 9 others); Sat, 19 Apr 2014 10:34:35 -0400 Received: from arroyo.ext.ti.com ([192.94.94.40]:38770 "EHLO arroyo.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754172AbaDSOeZ (ORCPT ); Sat, 19 Apr 2014 10:34:25 -0400 Received: from dflxv15.itg.ti.com ([128.247.5.124]) by arroyo.ext.ti.com (8.13.7/8.13.7) with ESMTP id s3JEXnir014711; Sat, 19 Apr 2014 09:33:49 -0500 Received: from DLEE70.ent.ti.com (dlee70.ent.ti.com [157.170.170.113]) by dflxv15.itg.ti.com (8.14.3/8.13.8) with ESMTP id s3JEXn1V012024; Sat, 19 Apr 2014 09:33:49 -0500 Received: from dlep33.itg.ti.com (157.170.170.75) by DLEE70.ent.ti.com (157.170.170.113) with Microsoft SMTP Server id 14.3.174.1; Sat, 19 Apr 2014 09:33:49 -0500 Received: from ula0393909.am.dhcp.ti.com (ileax41-snat.itg.ti.com [10.172.224.153]) by dlep33.itg.ti.com (8.14.3/8.13.8) with ESMTP id s3JEXT32019097; Sat, 19 Apr 2014 09:33:48 -0500 From: Santosh Shilimkar To: CC: , , Santosh Shilimkar , Greg Kroah-Hartman , Russell King , Arnd Bergmann , Olof Johansson , Grant Likely , Rob Herring , Catalin Marinas , Linus Walleij , Grygorii Strashko Subject: [PATCH v2 4/7] of: configure the platform device dma parameters Date: Sat, 19 Apr 2014 10:32:49 -0400 Message-ID: <1397917972-6293-5-git-send-email-santosh.shilimkar@ti.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1397917972-6293-1-git-send-email-santosh.shilimkar@ti.com> References: <1397917972-6293-1-git-send-email-santosh.shilimkar@ti.com> MIME-Version: 1.0 Sender: devicetree-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: devicetree@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.128.178 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: , Retrieve DMA configuration from DT and setup platform device's DMA parameters. The DMA configuration in DT has to be specified using "dma-ranges" and "dma-coherent" properties if supported. We setup dma_pfn_offset using "dma-ranges" and dma_coherent_ops using "dma-coherent" device tree properties. The set_arch_dma_coherent_ops macro has to be defined by arch if it supports coherent dma_ops. Otherwise, set_arch_dma_coherent_ops() is declared as nop. 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 | 43 +++++++++++++++++++++++++++++++++++++++++++ include/linux/dma-mapping.h | 7 +++++++ 2 files changed, 50 insertions(+) diff --git a/drivers/of/platform.c b/drivers/of/platform.c index 573db15..7e4a43b 100644 --- a/drivers/of/platform.c +++ b/drivers/of/platform.c @@ -187,6 +187,47 @@ struct platform_device *of_device_alloc(struct device_node *np, EXPORT_SYMBOL(of_device_alloc); /** + * of_dma_configure - Setup DMA configuration + * @dev: Device to apply DMA configuration + * + * Try to get devices's DMA configuration from DT and update it + * accordingly. + * + * In case if platform code need to use own special DMA configuration,it + * can use Platform bus notifier and handle BUS_NOTIFY_ADD_DEVICE event + * to fix up DMA configuration. + */ +static void of_dma_configure(struct device *dev) +{ + dma_addr_t dma_addr; + phys_addr_t paddr, size; + int ret; + + /* + * if dma-coherent property exist, call arch hook to setup + * dma coherent operations. + */ + if (of_dma_is_coherent(dev->of_node)) { + set_arch_dma_coherent_ops(dev); + dev_dbg(dev, "device is dma coherent\n"); + } + + /* + * if dma-ranges property doesn't exist - just return else + * setup the dma offset + */ + ret = of_dma_get_range(dev->of_node, &dma_addr, &paddr, &size); + if (ret < 0) { + dev_dbg(dev, "no dma range information to setup\n"); + return; + } else { + /* DMA ranges found. Calculate and set dma_pfn_offset */ + dev->dma_pfn_offset = PFN_DOWN(paddr - dma_addr); + dev_dbg(dev, "dma_pfn_offset(%#08lx)\n", dev->dma_pfn_offset); + } +} + +/** * 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 @@ -217,6 +258,8 @@ static struct platform_device *of_platform_device_create_pdata( dev->dev.coherent_dma_mask = DMA_BIT_MASK(32); if (!dev->dev.dma_mask) dev->dev.dma_mask = &dev->dev.coherent_dma_mask; + + of_dma_configure(&dev->dev); dev->dev.bus = &platform_bus_type; dev->dev.platform_data = platform_data; diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h index fd4aee2..c7d9b1b 100644 --- a/include/linux/dma-mapping.h +++ b/include/linux/dma-mapping.h @@ -123,6 +123,13 @@ static inline int dma_coerce_mask_and_coherent(struct device *dev, u64 mask) extern u64 dma_get_required_mask(struct device *dev); +#ifndef set_arch_dma_coherent_ops +static inline int set_arch_dma_coherent_ops(struct device *dev) +{ + return 0; +} +#endif + static inline unsigned int dma_get_max_seg_size(struct device *dev) { return dev->dma_parms ? dev->dma_parms->max_segment_size : 65536;