From patchwork Fri Mar 11 08:59:28 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sanchayan X-Patchwork-Id: 8563571 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 733909F9A0 for ; Fri, 11 Mar 2016 09:07:33 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 81E1420173 for ; Fri, 11 Mar 2016 09:07:32 +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 959E220172 for ; Fri, 11 Mar 2016 09:07:31 +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 1aeJ0x-0007Pg-N6; Fri, 11 Mar 2016 09:05:43 +0000 Received: from mail-pa0-x231.google.com ([2607:f8b0:400e:c03::231]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1aeJ0u-0007NA-Vf for linux-arm-kernel@lists.infradead.org; Fri, 11 Mar 2016 09:05:42 +0000 Received: by mail-pa0-x231.google.com with SMTP id td3so64284501pab.2 for ; Fri, 11 Mar 2016 01:05:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=8vK35cQncCYDO2DZiPJHpiDa9R6Sh2uK8gP5eZE4y+g=; b=HqCKL7ejaK7eoXZFPz1jMzChHTppwdrdzi/tAZU8KATd/9FDYt1v+uXa/Jdjd4eWqy O4kqbnqncmamj0S4yY6HKQ8eOJOOqdYQktCTKUVQcbdjHOsij+Z2UjZmwBDxm/OQNxt4 WBdzyhE4s5qQcuc6gGZqaADg7LT2VyLxJIATCa8rbmFXXNIQSKf8qc6XZqvJKxFPfmTu 8g3/u3yezCDD0GUoCo6TwvNcTHp3XFWKRhk0fGHiYuOuwxclNCLY+UqiazYjUYpjKu/0 w8JeiyXlI7fi5HVE95BG16rww8xULsla1+eYk3lrO2uIrumcFU6s4Wd7SPfpOmAJmfVC 5HfA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=8vK35cQncCYDO2DZiPJHpiDa9R6Sh2uK8gP5eZE4y+g=; b=m/fFzEqJULxvIjK3wAUYUKhFD3LTK/bM7kVeXtQG76JEfkbWwPGMaiGrpsNrL/QsTD oOZfO0pHbp/fB8AngnMTBV56B5v76N0SDsZDCI7qkddy3Bjq6JG80G6OG09uSA/IgEzv bFjnov5gRO6UZ/t04HPm1/QnntQNWBUjphfiQJqIJ3OM3rxbSNHycwNxoRSbxHNEYMrE jdwx2kqbFr/Ut4+WOGZitrxgRX4XLAIwsB12g6b8lX7mvG9yllTjlyKwMcJUNGhhaFLx C45ufLA9E0jJU+GZEpH8zlpW+h3DEhLZJa+uhPDALSMnK8nG3LbD7kpb6is9MqCGF+3/ Obwg== X-Gm-Message-State: AD7BkJJI66TkeYFRKt1RszSgo9+o75VsjsVerJOjydZ9QZIs3nw8/ks5GsCFN663t1D6qw== X-Received: by 10.66.66.1 with SMTP id b1mr12946389pat.63.1457687123473; Fri, 11 Mar 2016 01:05:23 -0800 (PST) Received: from localhost ([115.115.225.206]) by smtp.gmail.com with ESMTPSA id n68sm11146433pfj.46.2016.03.11.01.05.21 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 11 Mar 2016 01:05:22 -0800 (PST) From: Sanchayan Maity To: arnd@arndb.de, shawnguo@kernel.org Subject: [PATCH v1 1/4] mfd: syscon: Introduce syscon_regmap_read_from_offset Date: Fri, 11 Mar 2016 14:29:28 +0530 Message-Id: X-Mailer: git-send-email 2.7.2 In-Reply-To: References: In-Reply-To: References: X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160311_010541_157927_F9A8AE3E X-CRM114-Status: GOOD ( 12.13 ) X-Spam-Score: -2.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: devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, stefan@agner.ch, Sanchayan Maity , robh+dt@kernel.org, lee.jones@linaro.org, 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=-4.1 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, 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 Currently syscon does not provide an abstraction to access a register from syscon reference like below ocotp-cfg1 = <&ocotp 0x20> syscon_regmap_read_from_offset provides a generic abstraction to access a register from syscon reference as above. It allows to specify the node and node name of phandle reference, reading the offset from the node entry and providing the value from the offset in the register map. Signed-off-by: Sanchayan Maity --- drivers/mfd/syscon.c | 30 ++++++++++++++++++++++++++++++ include/linux/mfd/syscon.h | 10 ++++++++++ 2 files changed, 40 insertions(+) diff --git a/drivers/mfd/syscon.c b/drivers/mfd/syscon.c index b7aabee..349c38e 100644 --- a/drivers/mfd/syscon.c +++ b/drivers/mfd/syscon.c @@ -129,6 +129,36 @@ struct regmap *syscon_node_to_regmap(struct device_node *np) } EXPORT_SYMBOL_GPL(syscon_node_to_regmap); +int syscon_regmap_read_from_offset(struct device_node *np, + const char *s, unsigned int *val) +{ + struct of_phandle_args pargs; + struct regmap *regmap; + int offset; + int ret; + + if (!np) + return -ENODEV; + + ret = of_parse_phandle_with_fixed_args(np, s, 1, 0, &pargs); + if (ret) + return ret; + + regmap = syscon_node_to_regmap(pargs.np); + if (IS_ERR(regmap)) { + of_node_put(pargs.np); + return PTR_ERR(regmap); + } + + offset = pargs.args[0]; + of_node_put(pargs.np); + + ret = regmap_read(regmap, offset, val); + + return ret; +} +EXPORT_SYMBOL_GPL(syscon_regmap_read_from_offset); + struct regmap *syscon_regmap_lookup_by_compatible(const char *s) { struct device_node *syscon_np; diff --git a/include/linux/mfd/syscon.h b/include/linux/mfd/syscon.h index 75e543b..3c02ed9 100644 --- a/include/linux/mfd/syscon.h +++ b/include/linux/mfd/syscon.h @@ -26,6 +26,9 @@ extern struct regmap *syscon_regmap_lookup_by_pdevname(const char *s); extern struct regmap *syscon_regmap_lookup_by_phandle( struct device_node *np, const char *property); +extern int syscon_regmap_read_from_offset(struct device_node *np, + const char *s, + unsigned int *val); #else static inline struct regmap *syscon_node_to_regmap(struct device_node *np) { @@ -48,6 +51,13 @@ static inline struct regmap *syscon_regmap_lookup_by_phandle( { return ERR_PTR(-ENOSYS); } + +static inline int syscon_regmap_read_from_offset(struct device_node *np, + const char *s, + unsigned int *val) +{ + return ERR_PTR(-ENOSYS); +} #endif #endif /* __LINUX_MFD_SYSCON_H__ */