From patchwork Tue Jul 21 13:50:46 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomeu Vizoso X-Patchwork-Id: 6836241 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id E296E9F380 for ; Tue, 21 Jul 2015 13:55:06 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 014CF206B0 for ; Tue, 21 Jul 2015 13:55:06 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id B4CC3206A0 for ; Tue, 21 Jul 2015 13:55:03 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1ZHXyd-0004zz-OQ; Tue, 21 Jul 2015 13:52:59 +0000 Received: from mail-wg0-x229.google.com ([2a00:1450:400c:c00::229]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1ZHXxv-0004gx-Gl for linux-arm-kernel@lists.infradead.org; Tue, 21 Jul 2015 13:52:16 +0000 Received: by wgbcc4 with SMTP id cc4so64002802wgb.3 for ; Tue, 21 Jul 2015 06:51:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=+EFGMgdbIeIcLTd3vtjoIJMB6UtMLlPiwUrLzXoM2lA=; b=oViRlq1eGzPLJwZpxaeLzyok8be07WMpKu3OfxwgFYnKesbCkwI9U/N2nR1VR+8AHQ iFJ5fTl7oYVXUTQ/Bw5FDd09kVMZI4qW1S5dq/0mYY50NwX8x0ojsa+Tk0mxP5wdy+lW FE/jeXA6UT9oghhHZpZwbUcIpTsg2gErBEmBDc3bLlgls622ycfl1ZFlt1FY0GRfEuZ6 UtQ3SLvUdTc/EGmyI4mPwMOlZIsgsyChwKFW+gtnQ48CIfyCMl2aOGyONzmM9Txt3/ku AoRQB31MkHOesouxXpY+5nBG5FyVKetrqbLPJCVTjaN/hb7IcMOAlgSrxLeAGVoicAqz NYDg== X-Received: by 10.180.109.6 with SMTP id ho6mr32535495wib.58.1437486713822; Tue, 21 Jul 2015 06:51:53 -0700 (PDT) Received: from cizrna.lan ([109.72.12.178]) by smtp.gmail.com with ESMTPSA id pf4sm37172056wjb.23.2015.07.21.06.51.52 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 21 Jul 2015 06:51:53 -0700 (PDT) From: Tomeu Vizoso To: linux-kernel@vger.kernel.org Subject: [RFC PATCH 04/16] Add DEVM_IOMAP() Date: Tue, 21 Jul 2015 15:50:46 +0200 Message-Id: <1437486658-28365-5-git-send-email-tomeu.vizoso@collabora.com> X-Mailer: git-send-email 2.4.3 In-Reply-To: <1437486658-28365-1-git-send-email-tomeu.vizoso@collabora.com> References: <1437486658-28365-1-git-send-email-tomeu.vizoso@collabora.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20150721_065215_726607_EBB61AF1 X-CRM114-Status: GOOD ( 15.23 ) X-Spam-Score: -1.7 (-) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Arnd Bergmann , Tomeu Vizoso , Stephen Warren , "Rafael J. Wysocki" , Mark Brown , linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-5.3 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,RP_MATCHES_RCVD,T_DKIM_INVALID,UNPARSEABLE_RELAY autolearn=unavailable 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 Signed-off-by: Tomeu Vizoso --- drivers/base/devres.c | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++ include/linux/device.h | 19 +++++++++++++++++ 2 files changed, 75 insertions(+) diff --git a/drivers/base/devres.c b/drivers/base/devres.c index 5198ccd28123..6af1ca9fa804 100644 --- a/drivers/base/devres.c +++ b/drivers/base/devres.c @@ -8,7 +8,10 @@ */ #include +#include #include +#include +#include #include #include "base.h" @@ -1034,3 +1037,56 @@ int devm_resource_alloc(struct device *dev, return 0; } EXPORT_SYMBOL_GPL(devm_resource_alloc); + +int devm_acquire_iomap(struct device *dev, + const struct devm_resource *resource) +{ + struct resource res, *resp = NULL; + void __iomem *vaddr; + void * __iomem *vaddrp; + int index, ret; + + /* find mem resource from platform device */ + if (dev->bus == &platform_bus_type) { + struct platform_device *pdev = to_platform_device(dev); + + if (resource->name) + resp = platform_get_resource_byname(pdev, + IORESOURCE_MEM, resource->name); + else + resp = platform_get_resource(pdev, + IORESOURCE_MEM, resource->index); + } + + /* try getting resource from device tree if that failed */ + if (!resp && dev->of_node) { + if (resource->name) + index = of_property_match_string(dev->of_node, + "reg-names", + resource->name); + else + index = resource->index; + + ret = of_address_to_resource(dev->of_node, index, &res); + if (ret) + return ret; + resp = &res; + } + + + if (resource->flags & DEVM_IOMAP_NOREQUEST) { + vaddr = devm_ioremap(dev, resp->start, resource_size(resp)); + if (!vaddr) + return -EINVAL; + } else { + vaddr = devm_ioremap_resource(dev, resp); + if (IS_ERR(vaddr)) + return PTR_ERR(vaddr); + } + + vaddrp = dev_get_drvdata(dev) + resource->offset; + *vaddrp = vaddr; + + return 0; +} +EXPORT_SYMBOL_GPL(devm_acquire_iomap); diff --git a/include/linux/device.h b/include/linux/device.h index c2bbee6b60ad..edcdc7a30114 100644 --- a/include/linux/device.h +++ b/include/linux/device.h @@ -687,6 +687,25 @@ extern int devm_resource_alloc(struct device *dev, #define DEVM_ALLOC(_struct) \ { .initfunc = devm_resource_alloc, .offset = sizeof(struct _struct), } +extern int devm_acquire_iomap(struct device *dev, + const struct devm_resource *resource); + +#define DEVM_IOMAP_NOREQUEST 1 + +#define DEVM_IOMAP(_struct, _member, _index, _flags) { \ + .initfunc = devm_acquire_iomap, \ + .offset = offsetof_t(struct _struct, _member, void __iomem *), \ + .index = _index, \ + .flags = _flags, \ +} + +#define DEVM_IOMAP_NAMED(_struct, _member, _name, _flags) { \ + .initfunc = devm_acquire_iomap, \ + .offset = offsetof_t(struct _struct, _member, void __iomem *), \ + .name = _name, \ + .flags = _flags, \ +} + void __iomem *devm_ioremap_resource(struct device *dev, struct resource *res); /* allows to add/remove a custom action to devres stack */