Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp5180061imm; Tue, 21 Aug 2018 07:33:41 -0700 (PDT) X-Google-Smtp-Source: AA+uWPxjvjbSiYxnmZjBRbc5TSK5rGEatiLIZWjP1X4WRnjnb2IPkpKMoghXGOBdFrymDixCSZDP X-Received: by 2002:a63:2d05:: with SMTP id t5-v6mr12524899pgt.403.1534862021857; Tue, 21 Aug 2018 07:33:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1534862021; cv=none; d=google.com; s=arc-20160816; b=yxhNcGs8I+dha2E79OWGYPM+fQU/Pg3CRLT74cW3rD3cvqfOUVfsQUqTD3IREl9Z78 O41rxioOtFRPgo4C9Xxbw/GbyetVlxZzISdqbw+O63mpLrbH4Bt5OiGq7GGXvGNplQ0n YIhxIyYzDoAd5ldRHGD5zNj8DW8aORKEoW0WyZlI4LIu9mPinZLEDyUrR55jHfD4C7qN 8LijBJOUQvlGugvLCjY92fdqZA46TjS/Tsn4ieq/XOVZYgzMK92+vbItfZOkVKmCAKnh 5TGkKeY6zPUZvGs9wY5fvCcwf1nW34soIMzN4NNqyYas4lscwaLdIpAzQCLw3d8ZYnM5 bdzA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=44fsOrKDWVfx58fmV+sNI0c2GFQ2Hz2krxcXHva4qK0=; b=wC9QpDmonOtXXoR27IbPenCohVOrytnZzKcsNSfWia9qjoIxX72huawT9J51gXlHIb wC+DI6UD+rbeO/ZUI75XdALJ5+xGa2oinaCYP1ukNkfFkomw09bXhICo/iUxcchmBqIr +vd+NzbBPi1T5E7lGb+pv1j5BoZGyk+AOLB3h+bIkGldBq86lBQWL+Uf2sULxR/BnabJ Pwo5Rr8r1qDjRL3PD8XbG8iXrOEM9oWIgOtKc9W4C9r6Ci56tvi36npsqS2uIHsKIhys JsrVJCPXffCZTFpM9JTjslxtcioj1wgdjOEWfZHI7i2gVx0o7rbUZBxC2t7fFXk5YZ6u BYLA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=TureFM6X; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d27-v6si8210719pgm.428.2018.08.21.07.33.26; Tue, 21 Aug 2018 07:33:41 -0700 (PDT) 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; dkim=pass header.i=@gmail.com header.s=20161025 header.b=TureFM6X; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727650AbeHURwb (ORCPT + 99 others); Tue, 21 Aug 2018 13:52:31 -0400 Received: from mail-ed1-f66.google.com ([209.85.208.66]:43149 "EHLO mail-ed1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727491AbeHURw3 (ORCPT ); Tue, 21 Aug 2018 13:52:29 -0400 Received: by mail-ed1-f66.google.com with SMTP id j21-v6so10755943edp.10 for ; Tue, 21 Aug 2018 07:32:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=44fsOrKDWVfx58fmV+sNI0c2GFQ2Hz2krxcXHva4qK0=; b=TureFM6XuEiWuY/Bkj9QWy52n0JEuGjKSwf7RlimF/A+f+aHVtugg8XZo6tNbvLQfy L9TtR6qJuNnPKxIBhTx7JwKbR9Jqh8KGFWf4SsQKceTHK4/LR/zrlnizwLERaq2EEeDL NBlbDNz6Ne/vTIi96V2OuGPuaXgOMgbxA9QO2qGyypMgLSX63cWEoF2aN5KtPJBB3hh7 zb80wCwH8FEADvrGc/KlDmbAIpcMuiwJoG8PpWmW/KIXNeTSJLLEj3Hf4B0msxJjVV3Q RQacGc+kyJJFoHYhvV9uedRhSE3+sGIpFqp/DcfY5Uy5727I1iFCLFewbut3CVFypYCa keFA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=44fsOrKDWVfx58fmV+sNI0c2GFQ2Hz2krxcXHva4qK0=; b=IR7BLFGyzyxMDOkQl9plXHZGoXNhx20PJLK9xspLPegye+cufkEGMzRQh/ZkODP+Hr ql+U8oA3pPvVboz/R23VFVESfl9E2mSvpuvfK2U5vKLOtfc6sk8AAJ5wOo4kep2j3uEy 4SyyMZHh2Ta+BmuK1M0vkQWV1+i+jn3kuYdbRP+zOZ/KdYrh6x5ybCrv+BBlnpOFBxZy s4AGHGOjNnbkrN2RQUKVBfZVMruPt2rCrFWwhf4CzpjhRoAZs9oQDKV4t5RW5MzKfAsJ nFrzz11V51X38ew8KWxLqehy4L0sGmLOYlPxA5PoqICevYgaeUjwEwmVu+7Aaw8etrQb ZTwA== X-Gm-Message-State: AOUpUlEmJTMFNI5TZHmwEhQoWEM5/XC3yxAgJuLFVD/jVxFBpfASveR8 SEX8iavXGSar77Quht9N8Ks= X-Received: by 2002:a50:a6c7:: with SMTP id f7-v6mr61217318edc.225.1534861925625; Tue, 21 Aug 2018 07:32:05 -0700 (PDT) Received: from neopili.qtec.com (cpe.xe-3-0-1-778.vbrnqe10.dk.customer.tdc.net. [80.197.57.18]) by smtp.gmail.com with ESMTPSA id n17-v6sm6766144edq.10.2018.08.21.07.32.02 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 21 Aug 2018 07:32:02 -0700 (PDT) From: Ricardo Ribalda Delgado To: David Woodhouse , Brian Norris , Boris Brezillon , Marek Vasut , Richard Weinberger , Zhouyang Jia , linux-mtd@lists.infradead.org, linux-kernel@vger.kernel.org Cc: Ricardo Ribalda Delgado Subject: [PATCH 5/8] mtd: maps: gpio-addr-flash: Replace array with an integer Date: Tue, 21 Aug 2018 16:31:49 +0200 Message-Id: <20180821143152.32293-6-ricardo.ribalda@gmail.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180821143152.32293-1-ricardo.ribalda@gmail.com> References: <20180821143152.32293-1-ricardo.ribalda@gmail.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org By replacing the array with an integer we can avoid completely the bit comparison loop if the value has not changed (by far the most common case). Signed-off-by: Ricardo Ribalda Delgado --- drivers/mtd/maps/gpio-addr-flash.c | 31 +++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/drivers/mtd/maps/gpio-addr-flash.c b/drivers/mtd/maps/gpio-addr-flash.c index 22e100f07112..8f5e3dce9be3 100644 --- a/drivers/mtd/maps/gpio-addr-flash.c +++ b/drivers/mtd/maps/gpio-addr-flash.c @@ -43,7 +43,7 @@ struct async_state { struct map_info map; size_t gpio_count; unsigned *gpio_addrs; - int *gpio_values; + unsigned int gpio_values; unsigned int win_order; }; #define gf_map_info_to_state(mi) ((struct async_state *)(mi)->map_priv_1) @@ -55,22 +55,25 @@ struct async_state { * * Rather than call the GPIO framework every time, cache the last-programmed * value. This speeds up sequential accesses (which are by far the most common - * type). We rely on the GPIO framework to treat non-zero value as high so - * that we don't have to normalize the bits. + * type). */ static void gf_set_gpios(struct async_state *state, unsigned long ofs) { - size_t i = 0; - int value; + int i; ofs >>= state->win_order; - do { - value = ofs & (1 << i); - if (state->gpio_values[i] != value) { - gpio_set_value(state->gpio_addrs[i], value); - state->gpio_values[i] = value; - } - } while (++i < state->gpio_count); + + if (ofs == state->gpio_values) + return; + + for (i = 0; i < state->gpio_count; i++) { + if ((ofs & BIT(i)) == (state->gpio_values & BIT(i))) + continue; + + gpio_set_value(state->gpio_addrs[i], !!(ofs & BIT(i))); + } + + state->gpio_values = ofs; } /** @@ -215,7 +218,7 @@ static int gpio_flash_probe(struct platform_device *pdev) if (!memory || !gpios || !gpios->end) return -EINVAL; - arr_size = sizeof(int) * gpios->end; + arr_size = sizeof(state->gpio_addrs[0]) * gpios->end; state = devm_kzalloc(&pdev->dev, sizeof(*state) + arr_size, GFP_KERNEL); if (!state) return -ENOMEM; @@ -226,9 +229,7 @@ static int gpio_flash_probe(struct platform_device *pdev) */ state->gpio_count = gpios->end; state->gpio_addrs = (void *)(unsigned long)gpios->start; - state->gpio_values = (void *)(state + 1); state->win_order = get_bitmask_order(resource_size(memory)) - 1; - memset(state->gpio_values, 0xff, arr_size); state->map.name = DRIVER_NAME; state->map.read = gf_read; -- 2.18.0