From patchwork Mon May 2 07:05:00 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sanchayan X-Patchwork-Id: 8990331 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 B754E9F39D for ; Mon, 2 May 2016 07:13:29 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id E6D91201C7 for ; Mon, 2 May 2016 07:13:28 +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 1D096201D3 for ; Mon, 2 May 2016 07:13:28 +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 1ax81Q-00088p-6D; Mon, 02 May 2016 07:12:00 +0000 Received: from mail-pa0-x243.google.com ([2607:f8b0:400e:c03::243]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1ax81J-00084h-U7 for linux-arm-kernel@lists.infradead.org; Mon, 02 May 2016 07:11:54 +0000 Received: by mail-pa0-x243.google.com with SMTP id yl2so17405528pac.1 for ; Mon, 02 May 2016 00:11:33 -0700 (PDT) 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=3BvjAoTiy9cQ8lsKGSkVbC0/6UeBhQZFK39xpL6Hh2o=; b=Zn++6+QW2hvQFTnQkdWQ43XRrwaR76bsN/82Xf1tAN5kitFNjCJxRlaziwyQtKpMgK /OcxkKvzU2+jygdDe8QuiMYW2ZULXR6HvHltQ+1TnHJ5Ip72HEPevIbGtArFvG//8EC8 laPtqb2mimAksh7JY23f5cvGYBADZIkgzHLW1JBw+SADJW3Nc3PyeDiaI2awfJqbXOs7 wyMRHH4ImpseYRFqcPeuqkA4et/foxWrVaMShM6ctB+Mb4rTdN0IwG9iTvkBAUW9Cgtz Jk5bx+XEOyAdC8+qcxh5HjQgMujpIUUxDBO9yxZ6jb0QuP+57fWDuWapZcCNKcmvF9eZ Vtiw== 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=3BvjAoTiy9cQ8lsKGSkVbC0/6UeBhQZFK39xpL6Hh2o=; b=EUUL16heFbylHfd5R+R2U/TT442+X4hZ8Qi8NMKk00jfW4pKxT2SpIpi8+R4sI1YMQ wyaNmiBs2vIgnycv4BM8hazPTlqq0mbocqhM0bAemzXqWA8b4xTFORDCQFUf7oasOlG4 Jb3LPL2nY375l/nKFJhY7MWMdctr+nMAtV1AivMhUouzyps5fS/7bTBuWlps0f/u3/4a 9rZhbMAMuHSL/qbD7fxgrKThx1mJwm9A98unhZLnMi29rV83pD9sg8s3rEH+EOwmp5HQ 55mwR2XLjGhpLvDPzVDodd0jo4ItkmHANHlCW3iKjf6aHvSHvERX9DkvFUjMbGZOvfbc wppA== X-Gm-Message-State: AOPr4FWbABFFTXhokqDjlZ4uTQdRMzZcoi5xEoEEToZPhRCmVKkVwCn/Fv31D6fiIhXIXg== X-Received: by 10.66.123.105 with SMTP id lz9mr49633685pab.37.1462173093285; Mon, 02 May 2016 00:11:33 -0700 (PDT) Received: from localhost ([115.115.243.34]) by smtp.gmail.com with ESMTPSA id m12sm42389553pfi.5.2016.05.02.00.11.32 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 02 May 2016 00:11:32 -0700 (PDT) From: Sanchayan Maity To: arnd@arndb.de, shawnguo@kernel.org Subject: [PATCH v2 1/5] mfd: syscon: Introduce syscon_regmap_read_from_offset Date: Mon, 2 May 2016 12:35:00 +0530 Message-Id: X-Mailer: git-send-email 2.8.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-20160502_001154_031592_278DAC1E X-CRM114-Status: GOOD ( 13.11 ) 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=-5.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 2f2225e..74724c3 100644 --- a/drivers/mfd/syscon.c +++ b/drivers/mfd/syscon.c @@ -136,6 +136,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 1088149..42b0759 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(-ENOTSUPP); } + +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__ */