From patchwork Fri Apr 13 10:24:21 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 133351 Delivered-To: patch@linaro.org Received: by 10.46.84.18 with SMTP id i18csp572935ljb; Fri, 13 Apr 2018 03:24:33 -0700 (PDT) X-Google-Smtp-Source: AIpwx48hRZR95BcZP/5W8HXgRqXqgLe/OxwQh30xKN5vs6OKv0giFG1MxJEL/1qa7B0+rLQc6N9h X-Received: by 2002:a17:902:b283:: with SMTP id u3-v6mr4661017plr.263.1523615073295; Fri, 13 Apr 2018 03:24:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523615073; cv=none; d=google.com; s=arc-20160816; b=mwl20oIZuRVGgpyFlUgGsS9eWHlDanJw4ymELxKGURGp7RozG9GygoxnYWrddEX2hA jF9grhRZoyodfZy05HmmIHcDmArzavcyFVpCjyxlbI4ytwwecqaVYP/hpB5UXmOawFwk WQceWVKQglWeyZn/ZTmic8SoWLWK8ZnC46yyO4GJlqY43A9mHsl5ZBaUcNd0fKAJo6Fe lXHyi93Ndjb3KMFgmRwIoyAVgYolM4Q+2798XHh/VtpLFeSfVqWb2HBFez0XvXb32+DC 8a9Ox1ZaMeiTGOZtSJFRQSVzpiEvHWv2JbOdQZk5gnuvKmvUcKtBEwUAl0CDYBUTQpZ8 umUA== 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=vZuGIsorKwMQjiBic82RiZNKf4HrSbkxG9J2aTv6GI0=; b=oZJ/Njdg/066qRyv8A/3F5bDpycsjy0GM33fcB3Kua96313lrKACPpnBZgv0LZCDzI 5T7E3geKEYitqVu4pvJuzKfkj5E4vFY4MyHI3XDfQoGv8gKxC1KEsmm7o7tWPiokletq r8gTYsGM++Tx0MSS3ALxdqK2yCqZGe7Zrn1lF7KwQ7xcVrnD/wBmjFBUVz+DbXuVWB56 iuWx9H6GApqoyRvkm3F+i/TDyWVT8BRnvOm6eun6rsnfXhbv/I6Pe3Nzihuya679ZAIp 3NtP/tRTfq3UPx572afJYvVI4YTm6xLe6MwXNDrcKFrN8Ber0ByREgug3YvhE5fdk7oV oyZw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=beZbYCRx; spf=pass (google.com: best guess record for domain of linux-gpio-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-gpio-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 44-v6si5101266pla.376.2018.04.13.03.24.32; Fri, 13 Apr 2018 03:24:33 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-gpio-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=beZbYCRx; spf=pass (google.com: best guess record for domain of linux-gpio-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-gpio-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753421AbeDMKYc (ORCPT + 5 others); Fri, 13 Apr 2018 06:24:32 -0400 Received: from mail-lf0-f67.google.com ([209.85.215.67]:40069 "EHLO mail-lf0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753082AbeDMKYb (ORCPT ); Fri, 13 Apr 2018 06:24:31 -0400 Received: by mail-lf0-f67.google.com with SMTP id e5-v6so11873808lfb.7 for ; Fri, 13 Apr 2018 03:24:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=z8kpapX5/6q7JgjDTgbScLYzNEYYEt7mBHjkOq7DOL0=; b=beZbYCRxPsjzEwS8KpJp+SQZqD2BCvny4P7fnCjOVuTjFvBgQozAoMnnrTngekSYyk eC3Q0/Jpefcmz2IxYfPGkRgO70eOSYBiwnTDyxg7SJRBKTzrVf/gpUP1gW9bZrXmkRKe Qlpb1xOAY/o5+fO3OdrBPtSYAap7L7NdV1UIs= 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=z8kpapX5/6q7JgjDTgbScLYzNEYYEt7mBHjkOq7DOL0=; b=MwlSCOvX+TjdiiCPdV0atdx+4t8XMcaCK+BmnZE0FylP4Alu1h/GUJXLEb+njGjkcT YHAn1vNBj1oGVyGUATbc43xqqLyM5S2Kfug3vPoa5LOFp42x1r3xIV66C9UVNm4JNF7B VkSgz2tJLwCn04S5dPdZfEd0ZvXXfhlKZKVv/2tlUT7/kjDnN7YeSEMrO5/tUHsxKGoF fIScLODO7QCMJxfkgQuKg4ZaQVe+tiuJ1fYsvMloUe4xyXZA58WJvc7Lbb9fJsI6/O/f J+Ov6aXuBL/VybaoCMyseDWIs7LY/D0os7B1kQ7RJ7WbTXbCwAezVW9Q5TOtqFxAOcWj +HtA== X-Gm-Message-State: ALQs6tBzjF/ZjDbo40M/FpFTx0W6E/+NNTqIqyS+VyrD03qM2G+3QFW8 Ykqx8c2h5bCaB4k1ZYu15t+k24w3S8E= X-Received: by 2002:a19:921a:: with SMTP id u26-v6mr7565563lfd.112.1523615070210; Fri, 13 Apr 2018 03:24:30 -0700 (PDT) Received: from genomnajs.payandsurf.com ([192.36.80.8]) by smtp.gmail.com with ESMTPSA id c4sm915360lja.97.2018.04.13.03.24.29 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 13 Apr 2018 03:24:29 -0700 (PDT) From: Linus Walleij To: linux-gpio@vger.kernel.org Cc: Linus Walleij , Keguang Zhang , Jiaxun Yang , Huacai Chen , linux-mips@linux-mips.org Subject: [PATCH 3/3] gpio: loongson: Use BIT() macros Date: Fri, 13 Apr 2018 12:24:21 +0200 Message-Id: <20180413102421.23939-3-linus.walleij@linaro.org> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180413102421.23939-1-linus.walleij@linaro.org> References: <20180413102421.23939-1-linus.walleij@linaro.org> Sender: linux-gpio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org This switches the Loongson driver over to using the bitops BIT() macros and drops some local variables and make the code easier to read (in my opinion). Cc: Keguang Zhang Cc: Jiaxun Yang Cc: Huacai Chen Cc: linux-mips@linux-mips.org Signed-off-by: Linus Walleij --- drivers/gpio/gpio-loongson.c | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) -- 2.14.3 -- To unsubscribe from this list: send the line "unsubscribe linux-gpio" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/gpio/gpio-loongson.c b/drivers/gpio/gpio-loongson.c index 3c9d4f3ed550..16cfbe9e72fe 100644 --- a/drivers/gpio/gpio-loongson.c +++ b/drivers/gpio/gpio-loongson.c @@ -19,6 +19,7 @@ #include #include #include +#include #include #include @@ -31,6 +32,11 @@ #define LOONGSON_N_GPIO STLS2F_N_GPIO #endif +/* + * Offset into the register where we read lines, we write them from offset 0. + * This offset is the only thing that stand between us and using + * GPIO_GENERIC. + */ #define LOONGSON_GPIO_IN_OFFSET 16 static DEFINE_SPINLOCK(gpio_lock); @@ -38,30 +44,25 @@ static DEFINE_SPINLOCK(gpio_lock); static int loongson_gpio_get_value(struct gpio_chip *chip, unsigned gpio) { u32 val; - u32 mask; - mask = 1 << (gpio + LOONGSON_GPIO_IN_OFFSET); spin_lock(&gpio_lock); val = LOONGSON_GPIODATA; spin_unlock(&gpio_lock); - return (val & mask) != 0; + return !!(val & BIT(gpio + LOONGSON_GPIO_IN_OFFSET)); } static void loongson_gpio_set_value(struct gpio_chip *chip, unsigned gpio, int value) { u32 val; - u32 mask; - - mask = 1 << gpio; spin_lock(&gpio_lock); val = LOONGSON_GPIODATA; if (value) - val |= mask; + val |= BIT(gpio); else - val &= (~mask); + val &= ~BIT(gpio); LOONGSON_GPIODATA = val; spin_unlock(&gpio_lock); } @@ -69,12 +70,10 @@ static void loongson_gpio_set_value(struct gpio_chip *chip, static int loongson_gpio_direction_input(struct gpio_chip *chip, unsigned gpio) { u32 temp; - u32 mask; spin_lock(&gpio_lock); - mask = 1 << gpio; temp = LOONGSON_GPIOIE; - temp |= mask; + temp |= BIT(gpio); LOONGSON_GPIOIE = temp; spin_unlock(&gpio_lock); @@ -85,13 +84,11 @@ static int loongson_gpio_direction_output(struct gpio_chip *chip, unsigned gpio, int level) { u32 temp; - u32 mask; loongson_gpio_set_value(chip, gpio, level); spin_lock(&gpio_lock); - mask = 1 << gpio; temp = LOONGSON_GPIOIE; - temp &= (~mask); + temp &= ~BIT(gpio); LOONGSON_GPIOIE = temp; spin_unlock(&gpio_lock);