Received: by 10.223.185.116 with SMTP id b49csp1896722wrg; Thu, 22 Feb 2018 05:04:14 -0800 (PST) X-Google-Smtp-Source: AH8x227vXS4Eq8IsjgGpEp4/NRTxMOUCAV/Rcis1FA10+kien7pgHiyxvh4NluBC41as47cP7g93 X-Received: by 2002:a17:902:a70f:: with SMTP id w15-v6mr2025636plq.79.1519304654756; Thu, 22 Feb 2018 05:04:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519304654; cv=none; d=google.com; s=arc-20160816; b=xpl8uYQNWTbefka6N4qjdrJ7qAN/6k3WL3pViGzV9kyv64t5uuumxVwhZtqCkvOuSp Ker58uBprPuFvkU1VICNPZ+k4wrZRN0MMTefijSxq1hMuUp118g+7vdAQFIseHKXgvIw 8W3k/dr3Jh2PzMHec9bxKUpECtcBk8rpZPCsR9IW/U+jmhaSDCC9148Bj2HYV9FTjSZi kHRRX4swAzk79MuDr4hiI0S5fIARWBmQLzOg/ZZw5QCLLbrQzA4eKbdanCrcmXQwcpHk EiD7tPJCB/MzqSVh7cEHkntKN4MUWGsXtld8SCiaQhk3gyuETs82H3f5VfVIiHVWDkl5 AT1Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:arc-authentication-results; bh=r7OP7q1F0ymHgIy+WrFS+LHCnbhvcJ13OsjFWaoc42Y=; b=r3yJBFvHUZ1qM0R90WlpNnhZO6kRHsPstcMovypN7rWhlKXl8tlT/0tidN3T/luLor JAl8AfgyCoov/mUidKiQ1JB4i7nOsO2/BjIZRWb7hzKOoW7jECAroagnXqKsuij2eMpG n98dG4puDPorZ1pUR/WTm2pabeE3CNFx5Np9Kb3OJwj5/GQ51TrBVm81KnECuuT4uQ3B 3gtPXRIspzqOUyUpfv8QtcRxPDe08SrwC6bZZ9AXc8RXr22HtcCilr8yoPGd593+zy0Y ZsIdweRJBEwrV2WASQ03LjaHN4CIcm2zCANxSrPEMkJG4n2XZaXv9pagRoF0pqXZMOWR NW4g== ARC-Authentication-Results: i=1; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x4si24293pfb.281.2018.02.22.05.03.35; Thu, 22 Feb 2018 05:04:14 -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 S932389AbeBVM7T (ORCPT + 99 others); Thu, 22 Feb 2018 07:59:19 -0500 Received: from mx0a-001ae601.pphosted.com ([67.231.149.25]:60840 "EHLO mx0b-001ae601.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1753811AbeBVM7R (ORCPT ); Thu, 22 Feb 2018 07:59:17 -0500 Received: from pps.filterd (m0077473.ppops.net [127.0.0.1]) by mx0a-001ae601.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w1MCsKe5021796; Thu, 22 Feb 2018 06:59:16 -0600 Authentication-Results: ppops.net; spf=none smtp.mailfrom=ckeepax@opensource.cirrus.com Received: from mail4.cirrus.com ([87.246.98.35]) by mx0a-001ae601.pphosted.com with ESMTP id 2g6jp5enpg-1; Thu, 22 Feb 2018 06:59:15 -0600 Received: from EX17.ad.cirrus.com (unknown [172.20.9.81]) by mail4.cirrus.com (Postfix) with ESMTP id 606F6611CE71; Thu, 22 Feb 2018 07:00:08 -0600 (CST) Received: from imbe.wolfsonmicro.main (198.61.95.81) by EX17.ad.cirrus.com (172.20.9.81) with Microsoft SMTP Server id 14.3.301.0; Thu, 22 Feb 2018 12:59:14 +0000 Received: from algalon.ad.cirrus.com (algalon.ad.cirrus.com [198.90.251.122]) by imbe.wolfsonmicro.main (8.14.4/8.14.4) with ESMTP id w1MCxEPp011915; Thu, 22 Feb 2018 12:59:14 GMT From: Charles Keepax To: CC: , Subject: [PATCH 3/5] regmap: Move the handling for max_raw_write into regmap_raw_write Date: Thu, 22 Feb 2018 12:59:12 +0000 Message-ID: <20180222125914.17016-3-ckeepax@opensource.cirrus.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180222125914.17016-1-ckeepax@opensource.cirrus.com> References: <20180222125914.17016-1-ckeepax@opensource.cirrus.com> MIME-Version: 1.0 Content-Type: text/plain X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 suspectscore=1 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1711220000 definitions=main-1802220164 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Currently regmap_bulk_write will split a write into chunks before calling regmap_raw_write if max_raw_write is set. It is more logical for this handling to be inside regmap_raw_write itself, as this removes the need to keep re-implementing the chunking code, which would be the same for all users of regmap_raw_write. Signed-off-by: Charles Keepax --- drivers/base/regmap/regmap.c | 117 ++++++++++++++++++++----------------------- 1 file changed, 54 insertions(+), 63 deletions(-) diff --git a/drivers/base/regmap/regmap.c b/drivers/base/regmap/regmap.c index c84c4d5d2df7..dd17e2e7a3d7 100644 --- a/drivers/base/regmap/regmap.c +++ b/drivers/base/regmap/regmap.c @@ -1440,8 +1440,8 @@ static void regmap_set_work_buf_flag_mask(struct regmap *map, int max_bytes, buf[i] |= (mask >> (8 * i)) & 0xff; } -int _regmap_raw_write(struct regmap *map, unsigned int reg, - const void *val, size_t val_len) +static int _regmap_raw_write_impl(struct regmap *map, unsigned int reg, + const void *val, size_t val_len) { struct regmap_range_node *range; unsigned long flags; @@ -1492,8 +1492,9 @@ int _regmap_raw_write(struct regmap *map, unsigned int reg, while (val_num > win_residue) { dev_dbg(map->dev, "Writing window %d/%zu\n", win_residue, val_len / map->format.val_bytes); - ret = _regmap_raw_write(map, reg, val, win_residue * - map->format.val_bytes); + ret = _regmap_raw_write_impl(map, reg, val, + win_residue * + map->format.val_bytes); if (ret != 0) return ret; @@ -1709,11 +1710,11 @@ static int _regmap_bus_raw_write(void *context, unsigned int reg, map->format.format_val(map->work_buf + map->format.reg_bytes + map->format.pad_bytes, val, 0); - return _regmap_raw_write(map, reg, - map->work_buf + - map->format.reg_bytes + - map->format.pad_bytes, - map->format.val_bytes); + return _regmap_raw_write_impl(map, reg, + map->work_buf + + map->format.reg_bytes + + map->format.pad_bytes, + map->format.val_bytes); } static inline void *_regmap_map_get_context(struct regmap *map) @@ -1808,6 +1809,49 @@ int regmap_write_async(struct regmap *map, unsigned int reg, unsigned int val) } EXPORT_SYMBOL_GPL(regmap_write_async); +int _regmap_raw_write(struct regmap *map, unsigned int reg, + const void *val, size_t val_len) +{ + size_t val_bytes = map->format.val_bytes; + size_t val_count = val_len / val_bytes; + int chunk_stride = map->reg_stride; + size_t chunk_size = val_bytes; + size_t chunk_count = val_count; + int ret, i; + + if (!val_count) + return -EINVAL; + + if (!map->use_single_write) { + if (map->max_raw_write) + chunk_size = map->max_raw_write; + else + chunk_size = val_len; + if (chunk_size % val_bytes) + chunk_size -= chunk_size % val_bytes; + chunk_count = val_len / chunk_size; + chunk_stride *= chunk_size / val_bytes; + } + + /* Write as many bytes as possible with chunk_size */ + for (i = 0; i < chunk_count; i++) { + ret = _regmap_raw_write_impl(map, + reg + (i * chunk_stride), + val + (i * chunk_size), + chunk_size); + if (ret) + return ret; + } + + /* Write remaining bytes */ + if (!ret && chunk_size * i < val_len) + ret = _regmap_raw_write_impl(map, reg + (i * chunk_stride), + val + (i * chunk_size), + val_len - i * chunk_size); + + return ret; +} + /** * regmap_raw_write() - Write raw values to one or more registers * @@ -1833,8 +1877,6 @@ int regmap_raw_write(struct regmap *map, unsigned int reg, return -EINVAL; if (val_len % map->format.val_bytes) return -EINVAL; - if (map->max_raw_write && map->max_raw_write < val_len) - return -E2BIG; map->lock(map->lock_arg); @@ -1925,7 +1967,6 @@ int regmap_bulk_write(struct regmap *map, unsigned int reg, const void *val, { int ret = 0, i; size_t val_bytes = map->format.val_bytes; - size_t total_size = val_bytes * val_count; if (!IS_ALIGNED(reg, map->reg_stride)) return -EINVAL; @@ -2000,57 +2041,9 @@ int regmap_bulk_write(struct regmap *map, unsigned int reg, const void *val, if (ret) return ret; } - } else if (map->use_single_write || - (map->max_raw_write && map->max_raw_write < total_size)) { - int chunk_stride = map->reg_stride; - size_t chunk_size = val_bytes; - size_t chunk_count = val_count; - void *wval; - - if (!val_count) - return -EINVAL; - - wval = kmemdup(val, val_count * val_bytes, map->alloc_flags); - if (!wval) - return -ENOMEM; - - for (i = 0; i < val_count * val_bytes; i += val_bytes) - map->format.parse_inplace(wval + i); - - if (!map->use_single_write) { - chunk_size = map->max_raw_write; - if (chunk_size % val_bytes) - chunk_size -= chunk_size % val_bytes; - chunk_count = total_size / chunk_size; - chunk_stride *= chunk_size / val_bytes; - } - - map->lock(map->lock_arg); - /* Write as many bytes as possible with chunk_size */ - for (i = 0; i < chunk_count; i++) { - ret = _regmap_raw_write(map, - reg + (i * chunk_stride), - wval + (i * chunk_size), - chunk_size); - if (ret) - break; - } - - /* Write remaining bytes */ - if (!ret && chunk_size * i < total_size) { - ret = _regmap_raw_write(map, reg + (i * chunk_stride), - wval + (i * chunk_size), - total_size - i * chunk_size); - } - map->unlock(map->lock_arg); - - kfree(wval); } else { void *wval; - if (!val_count) - return -EINVAL; - wval = kmemdup(val, val_count * val_bytes, map->alloc_flags); if (!wval) return -ENOMEM; @@ -2058,9 +2051,7 @@ int regmap_bulk_write(struct regmap *map, unsigned int reg, const void *val, for (i = 0; i < val_count * val_bytes; i += val_bytes) map->format.parse_inplace(wval + i); - map->lock(map->lock_arg); - ret = _regmap_raw_write(map, reg, wval, val_bytes * val_count); - map->unlock(map->lock_arg); + ret = regmap_raw_write(map, reg, wval, val_bytes * val_count); kfree(wval); } -- 2.11.0