From patchwork Mon Feb 1 21:38:14 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Brown X-Patchwork-Id: 105000 Delivered-To: patch@linaro.org Received: by 10.112.130.2 with SMTP id oa2csp335343lbb; Mon, 1 Feb 2016 13:38:33 -0800 (PST) X-Received: by 10.66.140.39 with SMTP id rd7mr41840679pab.86.1454362713691; Mon, 01 Feb 2016 13:38:33 -0800 (PST) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id we3si26459414pab.52.2016.02.01.13.38.33; Mon, 01 Feb 2016 13:38:33 -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; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932443AbcBAVi1 (ORCPT + 30 others); Mon, 1 Feb 2016 16:38:27 -0500 Received: from mezzanine.sirena.org.uk ([106.187.55.193]:58147 "EHLO mezzanine.sirena.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753777AbcBAViZ (ORCPT ); Mon, 1 Feb 2016 16:38:25 -0500 Received: from cpc11-sgyl31-2-0-cust672.sgyl.cable.virginm.net ([94.175.94.161] helo=debutante) by mezzanine.sirena.org.uk with esmtpsa (TLS1.2:RSA_AES_128_CBC_SHA1:128) (Exim 4.80) (envelope-from ) id 1aQMAt-0003nm-4S; Mon, 01 Feb 2016 21:38:19 +0000 Received: from broonie by debutante with local (Exim 4.86) (envelope-from ) id 1aQMAq-0002mz-6I; Mon, 01 Feb 2016 21:38:16 +0000 From: Mark Brown To: mail@maciej.szmigiero.name, Fabio Estevam Cc: alsa-devel@alsa-project.org, nicoleotsuka@gmail.com, linux-kernel@vger.kernel.org, Mark Brown Date: Mon, 1 Feb 2016 21:38:14 +0000 Message-Id: <1454362695-10682-1-git-send-email-broonie@kernel.org> X-Mailer: git-send-email 2.7.0.rc3 X-SA-Exim-Connect-IP: 94.175.94.161 X-SA-Exim-Mail-From: broonie@sirena.org.uk X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on mezzanine.sirena.org.uk X-Spam-Level: X-Spam-Status: No, score=-2.9 required=5.0 tests=ALL_TRUSTED,BAYES_00 autolearn=ham version=3.3.2 Subject: [PATCH 1/2] regmap: Return an error if a caller attempts to do an unsupported raw read X-SA-Exim-Version: 4.2.1 (built Mon, 26 Dec 2011 16:24:06 +0000) X-SA-Exim-Scanned: Yes (on mezzanine.sirena.org.uk) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org regmaps without raw I/O access can't implement raw I/O operations, return an error if someone tries to do that rather than crashing. Signed-off-by: Mark Brown --- drivers/base/regmap/regmap.c | 3 +++ 1 file changed, 3 insertions(+) -- 2.7.0.rc3 diff --git a/drivers/base/regmap/regmap.c b/drivers/base/regmap/regmap.c index 343263449aff..e2f68807d970 100644 --- a/drivers/base/regmap/regmap.c +++ b/drivers/base/regmap/regmap.c @@ -2255,6 +2255,9 @@ static int _regmap_raw_read(struct regmap *map, unsigned int reg, void *val, WARN_ON(!map->bus); + if (!map->bus || !map->bus->read) + return -EINVAL; + range = _regmap_range_lookup(map, reg); if (range) { ret = _regmap_select_page(map, ®, range, From patchwork Mon Feb 1 21:38:15 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Brown X-Patchwork-Id: 105001 Delivered-To: patch@linaro.org Received: by 10.112.130.2 with SMTP id oa2csp335300lbb; Mon, 1 Feb 2016 13:38:28 -0800 (PST) X-Received: by 10.66.122.97 with SMTP id lr1mr41525082pab.68.1454362708420; Mon, 01 Feb 2016 13:38:28 -0800 (PST) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t13si26503726pas.21.2016.02.01.13.38.28; Mon, 01 Feb 2016 13:38:28 -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; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932334AbcBAVi0 (ORCPT + 30 others); Mon, 1 Feb 2016 16:38:26 -0500 Received: from mezzanine.sirena.org.uk ([106.187.55.193]:58146 "EHLO mezzanine.sirena.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753643AbcBAViZ (ORCPT ); Mon, 1 Feb 2016 16:38:25 -0500 Received: from cpc11-sgyl31-2-0-cust672.sgyl.cable.virginm.net ([94.175.94.161] helo=debutante) by mezzanine.sirena.org.uk with esmtpsa (TLS1.2:RSA_AES_128_CBC_SHA1:128) (Exim 4.80) (envelope-from ) id 1aQMAt-0003nn-Ey; Mon, 01 Feb 2016 21:38:19 +0000 Received: from broonie by debutante with local (Exim 4.86) (envelope-from ) id 1aQMAq-0002n4-Ie; Mon, 01 Feb 2016 21:38:16 +0000 From: Mark Brown To: mail@maciej.szmigiero.name, Fabio Estevam Cc: alsa-devel@alsa-project.org, nicoleotsuka@gmail.com, linux-kernel@vger.kernel.org, Mark Brown Date: Mon, 1 Feb 2016 21:38:15 +0000 Message-Id: <1454362695-10682-2-git-send-email-broonie@kernel.org> X-Mailer: git-send-email 2.7.0.rc3 In-Reply-To: <1454362695-10682-1-git-send-email-broonie@kernel.org> References: <1454362695-10682-1-git-send-email-broonie@kernel.org> X-SA-Exim-Connect-IP: 94.175.94.161 X-SA-Exim-Mail-From: broonie@sirena.org.uk X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on mezzanine.sirena.org.uk X-Spam-Level: X-Spam-Status: No, score=-2.9 required=5.0 tests=ALL_TRUSTED,BAYES_00 autolearn=ham version=3.3.2 Subject: [PATCH 2/2] regmap: cache: Fall back to register by register read for cache defaults X-SA-Exim-Version: 4.2.1 (built Mon, 26 Dec 2011 16:24:06 +0000) X-SA-Exim-Scanned: Yes (on mezzanine.sirena.org.uk) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org If we are unable to read the cache defaults for a regmap then fall back on attempting to read them word by word. This is going to be painfully slow for large regmaps but might be adequate for smaller ones. Signed-off-by: Mark Brown --- drivers/base/regmap/regcache.c | 34 +++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-) -- 2.7.0.rc3 diff --git a/drivers/base/regmap/regcache.c b/drivers/base/regmap/regcache.c index 5c5090b68939..5f788f07b74c 100644 --- a/drivers/base/regmap/regcache.c +++ b/drivers/base/regmap/regcache.c @@ -30,7 +30,7 @@ static int regcache_hw_init(struct regmap *map) int i, j; int ret; int count; - unsigned int val; + unsigned int reg, val; void *tmp_buf; if (!map->num_reg_defaults_raw) @@ -67,27 +67,39 @@ static int regcache_hw_init(struct regmap *map) ret = regmap_raw_read(map, 0, tmp_buf, map->cache_size_raw); map->cache_bypass = cache_bypass; - if (ret < 0) - goto err_cache_free; - - map->reg_defaults_raw = tmp_buf; - map->cache_free = 1; + if (ret == 0) { + map->reg_defaults_raw = tmp_buf; + map->cache_free = 1; + } else { + kfree(tmp_buf); + } } /* fill the reg_defaults */ for (i = 0, j = 0; i < map->num_reg_defaults_raw; i++) { - if (regmap_volatile(map, i * map->reg_stride)) + reg = i * map->reg_stride; + + if (regmap_volatile(map, reg)) continue; - val = regcache_get_val(map, map->reg_defaults_raw, i); - map->reg_defaults[j].reg = i * map->reg_stride; + + if (map->reg_defaults_raw) { + val = regcache_get_val(map, map->reg_defaults_raw, i); + } else { + ret = regmap_read(map, reg, &val); + if (ret != 0) { + dev_err(map->dev, "Failed to read %d: %d\n", + reg, ret); + goto err_free; + } + } + + map->reg_defaults[j].reg = reg; map->reg_defaults[j].def = val; j++; } return 0; -err_cache_free: - kfree(tmp_buf); err_free: kfree(map->reg_defaults);