From patchwork Fri Apr 13 10:24:19 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 133349 Delivered-To: patch@linaro.org Received: by 10.46.84.18 with SMTP id i18csp572898ljb; Fri, 13 Apr 2018 03:24:29 -0700 (PDT) X-Google-Smtp-Source: AIpwx49PN23m2wYDSwnFbjslD+h2TrOS4xpFv6Cp0KqOcIn4BJIBppm4Hr5Lab0hLe3q2r2xoWU9 X-Received: by 2002:a17:902:44c:: with SMTP id 70-v6mr4667001ple.354.1523615069268; Fri, 13 Apr 2018 03:24:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523615069; cv=none; d=google.com; s=arc-20160816; b=yN7qzWnmIVGkMFb05GXEidPFbx8vVYW3TVLeFcVrX24SBdrrBSHjQRiEmsRbVUcXgS sNxiO3OsOG6Gwh7PQmlNbODwQNo8xVGYlEB237i1YkFzpEB9mnxFtmnEAqcFxvkg84i8 4kYDlCL5erdSfQRVIN06hHXxYHAUc8rmkhIX0vBmAK5ycQ8nxsCosEl4g082lQoDH8M+ BynVyAqkf5U6fksX4efYx5sg4hljy/kGtB/sANbButaNNdg0U/cTwHedMPIDD+n+4o7k urwAaSqXd8rqFBepIORAKVXeY107jZXl/nNmAK6BDKIYN6TNPqWrwnOF3etRIIS3JDq/ Izyg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=xW7mMSl0CNCzRb2AVzDjLQthmNSFjVUfhDjtd1tAO38=; b=SshulalX58oNI3FRqxHaPeu4W452PSiNAaB4HLBU7wiWlqBOdV8Nugh9XZsgnL1iXR 17iii37iFl7kWy5XPky4XeQc3d5JKzajdPT1FKyedX5yTWLSes1v1hsqTCUOkhkFuAhe y5TV+wgvlYRJOHcnzGeUJsePkBn3GBw7e+0PuSz0sLArdN/qdqG1d/nO/VcO6wiss+Oj bgX7dDG8H/imP6Tu4whgOTqOw5fOC26uVEGCawuHA0rYlNJO7GOfG6WChVIlo+gyrfbJ KOxkiuUG/JqTyxPT/uWaRpZVhBtxu2MWbiIwYiIQlKaW76hYnWny/9w0+6Lbe6srUCN8 ArXw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=XL0JSUsL; 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.29; Fri, 13 Apr 2018 03:24:29 -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=XL0JSUsL; 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 S1753076AbeDMKY2 (ORCPT + 5 others); Fri, 13 Apr 2018 06:24:28 -0400 Received: from mail-lf0-f65.google.com ([209.85.215.65]:33796 "EHLO mail-lf0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750960AbeDMKY1 (ORCPT ); Fri, 13 Apr 2018 06:24:27 -0400 Received: by mail-lf0-f65.google.com with SMTP id r7-v6so4767612lfr.1 for ; Fri, 13 Apr 2018 03:24:27 -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; bh=sI4KHeJmJJitIJprqm3skr6oFmAjI0sQMaj0NB/vNz4=; b=XL0JSUsL5p4eHi4ygivCZ+H3RnSRKVIzR1pnWlhXUpT1GQ32tGYo5suiZY8RLRQGPe go5/dDza7D5ulXf49lENNBTOoZLS6aI2ScbjYp01/K7scrsH9Bvo3tfTo+CGYinpdWUd 238axNdzMy1DSJTudCUfa5oJN63Xy2BUhNAOE= 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; bh=sI4KHeJmJJitIJprqm3skr6oFmAjI0sQMaj0NB/vNz4=; b=Ai+rIfL/6VirV5NjFkZxluBR2qjq0/KmvKC0kylaNcFCi42Pffe6jkECl9wf7yB9bA 58Rkt8e1+U278pq/bJl/qyfhngNw0Sij9z1nlq/QiZfr+d1JbfNLyz7ZYuc52M+p8lYD bGsRtPa/YTOFOh7ZWtWtnIdoVSmdLZ9zlBV/m6CGZGrNu64lMufIiUqSPhQRBfbeQidd MiL/Fxxyoo/N5lglCnDMcbOataReaAar5xH3Fj1bqEnxKT9yNB3QmznWm9p2qNZxDgtv E1leCsMaEWryPyIKJqpYoobLTqzbo0GQOrYSZgTRgqordVCi4iXIxfoJ950U7ziIXie+ I8Iw== X-Gm-Message-State: ALQs6tBcepkQvm2xSZjdcsy0ndkJ5//xwdLkpoz9vl7QkKSBkjkU0GNy N5ZEdbiEWEjvs64mQHGfdEWWKKozgIE= X-Received: by 2002:a19:1754:: with SMTP id n81-v6mr6912435lfi.113.1523615066125; Fri, 13 Apr 2018 03:24:26 -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.24 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 13 Apr 2018 03:24:25 -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 1/3] gpio: loongson: Use right include Date: Fri, 13 Apr 2018 12:24:19 +0200 Message-Id: <20180413102421.23939-1-linus.walleij@linaro.org> X-Mailer: git-send-email 2.14.3 Sender: linux-gpio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org The driver includes which is wrong, rely on and remove to call to gpio_set_value() in favor of calling the internal function. Move functions around to avoid forward declarations. 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 | 66 ++++++++++++++++++++++---------------------- 1 file changed, 33 insertions(+), 33 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 92c4fe7b2677..973d82a29442 100644 --- a/drivers/gpio/gpio-loongson.c +++ b/drivers/gpio/gpio-loongson.c @@ -17,9 +17,9 @@ #include #include #include +#include #include #include -#include #define STLS2F_N_GPIO 4 #define STLS3A_N_GPIO 16 @@ -34,38 +34,6 @@ static DEFINE_SPINLOCK(gpio_lock); -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; - LOONGSON_GPIOIE = temp; - spin_unlock(&gpio_lock); - - return 0; -} - -static int loongson_gpio_direction_output(struct gpio_chip *chip, - unsigned gpio, int level) -{ - u32 temp; - u32 mask; - - gpio_set_value(gpio, level); - spin_lock(&gpio_lock); - mask = 1 << gpio; - temp = LOONGSON_GPIOIE; - temp &= (~mask); - LOONGSON_GPIOIE = temp; - spin_unlock(&gpio_lock); - - return 0; -} - static int loongson_gpio_get_value(struct gpio_chip *chip, unsigned gpio) { u32 val; @@ -97,6 +65,38 @@ static void loongson_gpio_set_value(struct gpio_chip *chip, spin_unlock(&gpio_lock); } +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; + LOONGSON_GPIOIE = temp; + spin_unlock(&gpio_lock); + + return 0; +} + +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); + LOONGSON_GPIOIE = temp; + spin_unlock(&gpio_lock); + + return 0; +} + static struct gpio_chip loongson_chip = { .label = "Loongson-gpio-chip", .direction_input = loongson_gpio_direction_input, From patchwork Fri Apr 13 10:24:20 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 133350 Delivered-To: patch@linaro.org Received: by 10.46.84.18 with SMTP id i18csp572922ljb; Fri, 13 Apr 2018 03:24:31 -0700 (PDT) X-Google-Smtp-Source: AIpwx49/Q2oah9bjp1wfceQfxQ/AJfoVcH7ChUjeV143R0VLZsIns02a9QF2LWxsZDAFs0YGAZ2V X-Received: by 10.99.116.76 with SMTP id e12mr3617170pgn.270.1523615071578; Fri, 13 Apr 2018 03:24:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523615071; cv=none; d=google.com; s=arc-20160816; b=z9McXKoPj/jLndBsy695DSgdt5xOmbXeQHW31RWwko/9WRsJbqN1ihUMnXwnPj/TcX FDk7rHkneGqe8C0LC/Z0Eb2i0SSLEnKsrNsOAvLz0fwgoa9nd8LmlMyk6S1jNrHcucqW BO90MqmHqOHnrhiPZOYQKZoA54FToeLbRGLtfzJfSlakXKwjlsOjDLhx8E6ASNQzyg7d Jq3dabkypMpxZpr3kMEmRIWoKnDtQLNIuLKsgO7xirydyTr+Nz2BjBDyOKNpQRU8/B+p MGsSTtCVwkY/4oI4vG/pQaim4K6RecfSk/TUOwVwHmpFOT+QWv7eM1rGO9rAgt0pEsF5 oIUw== 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=xTdRn4sOOOzg9vVpng22uOSYrO9COBzbFp8hNWDn/aE=; b=eRriJ0QQNLTMKWsuisQEgjG92/qKt1JWfvGVd37Zd8cgb+9qXx2pZh7uY/hFZ1eLWv EA4OOuCOG70Cgy29Ks4LlE3HfDROvW+4ak1rpx2b4yMTk+H4Io/nzp/1iZA7qjIjCg4t Y92mGsNAWZNFYIUF8Pd7CXr9gVlzRrLEUIezhWmLMshBh6s565at/ZqDs74IDnXtYPhD 0NV6leVBlaE2tAMkk69LA/NCZ5ztETd1ziH8qiQk7tjIIRlCy0vscAzKfTBxNVVN6Ut6 uw0yJLRuKxYeYVooOkLQQhGU2BWPhlq8WXMXlgv6YDoiqm0A05UuQ6t4LiU7NZMFWoFF 41Tg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=KmS2YPrV; 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.31; Fri, 13 Apr 2018 03:24:31 -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=KmS2YPrV; 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 S1753099AbeDMKYa (ORCPT + 5 others); Fri, 13 Apr 2018 06:24:30 -0400 Received: from mail-lf0-f67.google.com ([209.85.215.67]:43315 "EHLO mail-lf0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752899AbeDMKYa (ORCPT ); Fri, 13 Apr 2018 06:24:30 -0400 Received: by mail-lf0-f67.google.com with SMTP id v207-v6so11870196lfa.10 for ; Fri, 13 Apr 2018 03:24:29 -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=4xSDZrFhiVzNg6qzME55uTU6osxICtcjU5z/C/QSRg0=; b=KmS2YPrVmdYxxXdZCzp1Veul3qpngyf4jdcloqc7MvqhU4uLhM6MaP5b/5bypRUXM1 /7VehM+3CN6osJfNil12Z8zpWU3C7sCIOtiTPucuFntVVnMXCDF7yiqyMte7b2yZ8XmC kvQhc+muA1f8TMfaiiUNFXMIiHRl3va/ADTRs= 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=4xSDZrFhiVzNg6qzME55uTU6osxICtcjU5z/C/QSRg0=; b=rVdkQTrNqqSXNuIBK1aAdHNqxBBMnuxFFeWuUe1/Rcxvr6xtqrqeYyn3d9si/E6H0c LNUpMm+ZquHHVgmjlm9kbHuqNUfnggbLQFwdQAOrpy1tjComdnngnJX6Kuxfq8DyjUft XqxdgFJagxFcwDkii7KaCQzfxlxxe84qhmYTTF9tv10E0dPo+zpckVnzYyjgXUmzGU4p wgZaOhmV7D6AqzktOv/sGq0YNF7t6ruVfxzBSJ7nOLMrvs4pdV1ur4ADE9IbwI0mMTbv 7OhLZB6Tx3pEJLc8wMGHpwYkDCc3E+j/aggtKTXnzAqjmQVrefLREk0SPAUAdyUHqYiD hFRQ== X-Gm-Message-State: ALQs6tCR/+ss6wIZYDGzxKYyjbWv0fnqBWw3cLQY1vpBbNJ7E73Xb6av hwEn2ZjS8WDJVMcWqrCBSQMIC6hltxM= X-Received: by 2002:a19:d085:: with SMTP id h127-v6mr7634531lfg.29.1523615068602; Fri, 13 Apr 2018 03:24:28 -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.27 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 13 Apr 2018 03:24:27 -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 2/3] gpio: loongson: Create a dynamic platform device Date: Fri, 13 Apr 2018 12:24:20 +0200 Message-Id: <20180413102421.23939-2-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 It is pretty helpful to create some kind of device for backing the GPIO chips, especially when preparing the driver for using GENERIC_GPIO, so let's create a simple platform device and a simple platform device driver and create the gpiochip in the .probe() routine for the device driver. Keep all at the core initcall so the behaviour is the same as before. 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 | 47 ++++++++++++++++++++++++++++++++++---------- 1 file changed, 37 insertions(+), 10 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 973d82a29442..3c9d4f3ed550 100644 --- a/drivers/gpio/gpio-loongson.c +++ b/drivers/gpio/gpio-loongson.c @@ -18,6 +18,7 @@ #include #include #include +#include #include #include @@ -97,19 +98,45 @@ static int loongson_gpio_direction_output(struct gpio_chip *chip, return 0; } -static struct gpio_chip loongson_chip = { - .label = "Loongson-gpio-chip", - .direction_input = loongson_gpio_direction_input, - .get = loongson_gpio_get_value, - .direction_output = loongson_gpio_direction_output, - .set = loongson_gpio_set_value, - .base = 0, - .ngpio = LOONGSON_N_GPIO, - .can_sleep = false, +static int loongson_gpio_probe(struct platform_device *pdev) +{ + struct gpio_chip *gc; + struct device *dev = &pdev->dev; + + gc = devm_kzalloc(dev, sizeof(*gc), GFP_KERNEL); + if (!gc) + return -ENOMEM; + + gc->label = "loongson-gpio-chip"; + gc->base = 0; + gc->ngpio = LOONGSON_N_GPIO; + gc->get = loongson_gpio_get_value; + gc->set = loongson_gpio_set_value; + gc->direction_input = loongson_gpio_direction_input; + gc->direction_output = loongson_gpio_direction_output; + + return gpiochip_add_data(gc, NULL); +} + +static struct platform_driver loongson_gpio_driver = { + .driver = { + .name = "loongson-gpio", + }, + .probe = loongson_gpio_probe, }; static int __init loongson_gpio_setup(void) { - return gpiochip_add_data(&loongson_chip, NULL); + struct platform_device *pdev; + int ret; + + ret = platform_driver_register(&loongson_gpio_driver); + if (ret) { + pr_err("error registering loongson GPIO driver\n"); + return ret; + } + + pdev = platform_device_register_simple("loongson-gpio", -1, NULL, 0); + return PTR_ERR_OR_ZERO(pdev); } postcore_initcall(loongson_gpio_setup); 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);