From patchwork Mon Nov 16 10:42:36 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 324816 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 83E46C4742C for ; Mon, 16 Nov 2020 12:01:31 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1E3A72064C for ; Mon, 16 Nov 2020 12:01:31 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=bgdev-pl.20150623.gappssmtp.com header.i=@bgdev-pl.20150623.gappssmtp.com header.b="tMi80xyn" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729193AbgKPKmt (ORCPT ); Mon, 16 Nov 2020 05:42:49 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37478 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729178AbgKPKms (ORCPT ); Mon, 16 Nov 2020 05:42:48 -0500 Received: from mail-wr1-x444.google.com (mail-wr1-x444.google.com [IPv6:2a00:1450:4864:20::444]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 53979C0613D2 for ; Mon, 16 Nov 2020 02:42:48 -0800 (PST) Received: by mail-wr1-x444.google.com with SMTP id 23so18106371wrc.8 for ; Mon, 16 Nov 2020 02:42:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=CxfKxZTg1DbPHJWPzb3+j86ivMqV6vfkqrTZ7ZDLxTg=; b=tMi80xynRp4hBqkNkBreCUIY5H8i99McNc6u7JRzeN5b/v1RcIzqYDuz+u4VLBDa9a DqGiqDNYLTHNHjEbTpskAdupj5OGTAqmbli3Sh2tR66LFdqndOIncLE7KFbI1/p27XrZ uSML2nMbyQEvBIBSnQZtXsOiXifpczCGJxey9QA9YKTKKs+QMZQCELrY7r8/Bk7T4e4g SN2u1YF/IbX1X6eQdfq++GZFXy4245JLonuWUsblKnFP/fxfXseQJDlnqiXMNXPjel3d 1+287JeZmDMvKRaNBVubnTa9qIok9lF0OgCuoovXl+pqonNxE09wmRU6RjoRfSSVAxFP oqDg== 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:mime-version:content-transfer-encoding; bh=CxfKxZTg1DbPHJWPzb3+j86ivMqV6vfkqrTZ7ZDLxTg=; b=UIKAk+gbv2J3AVobBXfyXLgrXzdrKtpTjsswzczb4Lhcr0ZqdD0hcOT2IrKv0FRT2e wWWPzMstZsAZJiE/2Wcxav2mPYXalX78FV4JBq+CCimi0OqIz6qp2kTOId4dxByLKG9C Ibnun/bpwpwlWUU8WeDEQU4apzLSjrhVFNMF7025WhyOkC5CL6I91uN9CbtgXbWSSHfL Ty/acoKW9GgjvroQ8GRBXCAltDwwg1UcP3vjcTR30B7eb0ZIgm+iEtxNUBt+6NgtPX5p YXMHAhDKYTe8YN2yGi9HrRmeQmcFRygXP1LhalDhB25YHWm0vXQFZSDwgEE4095bZZxV B6cg== X-Gm-Message-State: AOAM530eOEsBuUEW8BHEBRL4IoxJ0lc/TccD8Hg/zkXI/cOYudv+y8dB U3esen0XkLg4jYQRVPJhWmRcvg== X-Google-Smtp-Source: ABdhPJzUKjTNKTbXFWJcsJH8ygfAj6l68RwUt/AazhZ6d2KIvuU+crBrvhbEHSdvAoUUE2Of0Iu60Q== X-Received: by 2002:adf:f304:: with SMTP id i4mr18285381wro.268.1605523367000; Mon, 16 Nov 2020 02:42:47 -0800 (PST) Received: from debian-brgl.home (amarseille-656-1-4-167.w90-8.abo.wanadoo.fr. [90.8.158.167]) by smtp.gmail.com with ESMTPSA id v16sm20583283wml.33.2020.11.16.02.42.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Nov 2020 02:42:46 -0800 (PST) From: Bartosz Golaszewski To: Linus Walleij , Andy Shevchenko , Jan Kiszka , David Laight Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH v5 1/7] gpio: exar: add a newline after the copyright notice Date: Mon, 16 Nov 2020 11:42:36 +0100 Message-Id: <20201116104242.19907-2-brgl@bgdev.pl> X-Mailer: git-send-email 2.29.1 In-Reply-To: <20201116104242.19907-1-brgl@bgdev.pl> References: <20201116104242.19907-1-brgl@bgdev.pl> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org From: Bartosz Golaszewski It's customary to have a newline between the copyright header and the includes. Add one to gpio-exar. Signed-off-by: Bartosz Golaszewski Reviewed-by: Andy Shevchenko --- drivers/gpio/gpio-exar.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/gpio/gpio-exar.c b/drivers/gpio/gpio-exar.c index b1accfba017d..4202dd363a11 100644 --- a/drivers/gpio/gpio-exar.c +++ b/drivers/gpio/gpio-exar.c @@ -4,6 +4,7 @@ * * Copyright (C) 2015 Sudip Mukherjee */ + #include #include #include From patchwork Mon Nov 16 10:42:37 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 324815 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 04F3FC5519F for ; Mon, 16 Nov 2020 12:02:53 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 942B02224B for ; Mon, 16 Nov 2020 12:02:52 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=bgdev-pl.20150623.gappssmtp.com header.i=@bgdev-pl.20150623.gappssmtp.com header.b="Ktg0VFJb" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729234AbgKPKmz (ORCPT ); Mon, 16 Nov 2020 05:42:55 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37486 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729211AbgKPKmv (ORCPT ); Mon, 16 Nov 2020 05:42:51 -0500 Received: from mail-wr1-x443.google.com (mail-wr1-x443.google.com [IPv6:2a00:1450:4864:20::443]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 649EAC0613D1 for ; Mon, 16 Nov 2020 02:42:49 -0800 (PST) Received: by mail-wr1-x443.google.com with SMTP id l1so18111875wrb.9 for ; Mon, 16 Nov 2020 02:42:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=4apnqJWN8UXAvTecYMu5JfVMbmh6VFU9aGBXnlA8P/0=; b=Ktg0VFJbNhT6Gyv5HvkEfFyTXEnt/sagcga2AKCTnRaxI3Vo7W5Jo2DIeexQEy/IL2 WuHGOefd+zsGbutiHhWiQPpPi7VZY7ZBOyeS7XNY/0s0CUv3pSujfZmbzMOLSrUTJuz9 tD9koaCivuaHB7vg1V9QnrsisX1tdlR1dF/uEsZEF/jZHhzeOSGuLq6wuUcEc1TVwCx+ cJ6jXaM6F4J1KG20hkW5LTZxraj8mqCW3pxzpx4GmnQF2LxXt48c8BRXT7P4DgX0sc9L F1q7TUFIRtId2L6jCxx9k66btiRvUTcT3/ZnTJ6EJ0/lc7k/qP1JRlyQmLBRYSUByM+e 3ufQ== 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:mime-version:content-transfer-encoding; bh=4apnqJWN8UXAvTecYMu5JfVMbmh6VFU9aGBXnlA8P/0=; b=m4/vDfkBia6tDfsSivFkTBoBdPXQPzbVVvCpSeuan9J8msCJD8OUDvxNH9QCeUOUhh kc6odMNNMgckc5jpyR5qdlXjc2JytYN7YtfBg4pVqndy5PIv4jcj5ZdY06Lv4XZpcltC /eZAveuYEKhDbM3WRjb52u3/ELSxjg0bRrY6wfOVHu09Xyh5hhaOffNvQIbvAN5VmQnZ NqSL37YfpkPfUEQ6zrLR7Ex3zCpRAR1GRg9VxCizhvsMSfwGTlggRffBEOAy2gVqIwd5 QPeEmQ9dCNz45NYl2A/HTnO0d07+TxLvGSKzvQDPpU5x7ok/y5e6kaOEgE5BKoCKiE7I Sfuw== X-Gm-Message-State: AOAM532YG+oP0nUMId0xJvpXLYJqW24jMGdgnMRG3iXDH1/3KeqKKz0/ RKeHBxtSxFBog/Z013Fyujn+oA== X-Google-Smtp-Source: ABdhPJwGmrcx6gHYvHJn300niK5264/YoVmJ2V0DOTP/flf2uNNb7eKaaKjY0lkh8vIe1LA3NtBzuQ== X-Received: by 2002:a5d:514f:: with SMTP id u15mr17805606wrt.385.1605523368152; Mon, 16 Nov 2020 02:42:48 -0800 (PST) Received: from debian-brgl.home (amarseille-656-1-4-167.w90-8.abo.wanadoo.fr. [90.8.158.167]) by smtp.gmail.com with ESMTPSA id v16sm20583283wml.33.2020.11.16.02.42.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Nov 2020 02:42:47 -0800 (PST) From: Bartosz Golaszewski To: Linus Walleij , Andy Shevchenko , Jan Kiszka , David Laight Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH v5 2/7] gpio: exar: include idr.h Date: Mon, 16 Nov 2020 11:42:37 +0100 Message-Id: <20201116104242.19907-3-brgl@bgdev.pl> X-Mailer: git-send-email 2.29.1 In-Reply-To: <20201116104242.19907-1-brgl@bgdev.pl> References: <20201116104242.19907-1-brgl@bgdev.pl> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org From: Bartosz Golaszewski This driver uses IDA APIs but doesn't include the relevant header. This fixes it. Signed-off-by: Bartosz Golaszewski Reviewed-by: Andy Shevchenko --- drivers/gpio/gpio-exar.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/gpio/gpio-exar.c b/drivers/gpio/gpio-exar.c index 4202dd363a11..1941ae533418 100644 --- a/drivers/gpio/gpio-exar.c +++ b/drivers/gpio/gpio-exar.c @@ -8,6 +8,7 @@ #include #include #include +#include #include #include #include From patchwork Mon Nov 16 10:42:38 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 327360 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3A06BC5519F for ; Mon, 16 Nov 2020 12:02:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id CE737206D9 for ; Mon, 16 Nov 2020 12:02:11 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=bgdev-pl.20150623.gappssmtp.com header.i=@bgdev-pl.20150623.gappssmtp.com header.b="ssb1fPhw" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729213AbgKPKmv (ORCPT ); Mon, 16 Nov 2020 05:42:51 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37488 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727282AbgKPKmu (ORCPT ); Mon, 16 Nov 2020 05:42:50 -0500 Received: from mail-wr1-x441.google.com (mail-wr1-x441.google.com [IPv6:2a00:1450:4864:20::441]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 79E11C0613D2 for ; Mon, 16 Nov 2020 02:42:50 -0800 (PST) Received: by mail-wr1-x441.google.com with SMTP id r17so18164332wrw.1 for ; Mon, 16 Nov 2020 02:42:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=5he8TNmm5mbVIm4qwCj0n+AT880D6huUC6HghVpVCsk=; b=ssb1fPhw+AYT1ZEpimGiGnY8xzlxxsENO9CdyP0qEH0OgfCq5ZCi3hHmzsUTn+jVWO VVqnwUVUjfW8kbpFfrFaHic4ZALwBGjDXZ+pWbyAt9lzCyg1kRRRoXg8skKsoSqIUeF4 MfmVX3vDSd7RUXU6HhigSUY9m31RSGLdMEWWK9Wxcd2tD4lvQfj4m9skPnf5dmF+mVsv sH5rWKfTUom2OepOXdqSPh+BQAeKYjcGWBSmK4ZKAO3vqEvlYWeorm/e9LgR8WAderXH elNM/Tw3pto06gkp0hCDUXStnDCjc5FiRkIkQWBAz4ee1G7PnLaERquDjoN/gUokJikG pkdg== 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:mime-version:content-transfer-encoding; bh=5he8TNmm5mbVIm4qwCj0n+AT880D6huUC6HghVpVCsk=; b=XAo2DGScKhs1A5jLH4HVJqdX9XB8hyggRaOQqTNp4WoRFGcdqZVrvxHWl+DDZKUTlG vu5NXZfXKCZOVConJxO1YgRW8KwKo/TlPQDRnZFKbCIs8kpWcNWwzwfA0SkuysGhAjyI OtyLHS1+BWjaKao1/EbD06UewaEZa9BonYtPLhvwXqRJUQZF0rKjDpkUR6X1NcH24KMW kj57iE08Grx3lW13+Rq7EQnfUYXzQ6rWh4Z8GWQhNbkRtzHhlbpTR5Tq0whlos2lEPv6 soAzYqIFfam8jAVcygOwnj/4pNTGw8j10W4ek3es+uI6Gmm/OonfdZPmgiLbaF70RHKV dL6g== X-Gm-Message-State: AOAM53351+lznHGhnEoqra0UHavPq9MpQegDFyCQtSZ6C7omujPkSD5+ wM54Hc4q2fmd2GdcRE0SUdagTw== X-Google-Smtp-Source: ABdhPJyHLzn4LpWuQ4zkHXYmdFJsiI9j8LrsDeRga0DLxOWIOCgrd3dKRc+NSbh/JWeIrgucZEmioQ== X-Received: by 2002:a5d:5643:: with SMTP id j3mr18033539wrw.43.1605523369284; Mon, 16 Nov 2020 02:42:49 -0800 (PST) Received: from debian-brgl.home (amarseille-656-1-4-167.w90-8.abo.wanadoo.fr. [90.8.158.167]) by smtp.gmail.com with ESMTPSA id v16sm20583283wml.33.2020.11.16.02.42.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Nov 2020 02:42:48 -0800 (PST) From: Bartosz Golaszewski To: Linus Walleij , Andy Shevchenko , Jan Kiszka , David Laight Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH v5 3/7] gpio: exar: switch to a simpler IDA interface Date: Mon, 16 Nov 2020 11:42:38 +0100 Message-Id: <20201116104242.19907-4-brgl@bgdev.pl> X-Mailer: git-send-email 2.29.1 In-Reply-To: <20201116104242.19907-1-brgl@bgdev.pl> References: <20201116104242.19907-1-brgl@bgdev.pl> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org From: Bartosz Golaszewski We don't need to specify any ranges when allocating IDs so we can switch to ida_alloc() and ida_free() instead of the ida_simple_ counterparts. ida_simple_get(ida, 0, 0, gfp) is equivalent to ida_alloc_range(ida, 0, UINT_MAX, gfp) which is equivalent to ida_alloc(ida, gfp). Note: IDR will never actually allocate an ID larger than INT_MAX. Signed-off-by: Bartosz Golaszewski Reviewed-by: Andy Shevchenko --- drivers/gpio/gpio-exar.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/gpio/gpio-exar.c b/drivers/gpio/gpio-exar.c index 1941ae533418..752e8437ff80 100644 --- a/drivers/gpio/gpio-exar.c +++ b/drivers/gpio/gpio-exar.c @@ -149,7 +149,7 @@ static int gpio_exar_probe(struct platform_device *pdev) mutex_init(&exar_gpio->lock); - index = ida_simple_get(&ida_index, 0, 0, GFP_KERNEL); + index = ida_alloc(&ida_index, GFP_KERNEL); if (index < 0) { ret = index; goto err_mutex_destroy; @@ -179,7 +179,7 @@ static int gpio_exar_probe(struct platform_device *pdev) return 0; err_destroy: - ida_simple_remove(&ida_index, index); + ida_free(&ida_index, index); err_mutex_destroy: mutex_destroy(&exar_gpio->lock); return ret; @@ -189,7 +189,7 @@ static int gpio_exar_remove(struct platform_device *pdev) { struct exar_gpio_chip *exar_gpio = platform_get_drvdata(pdev); - ida_simple_remove(&ida_index, exar_gpio->index); + ida_free(&ida_index, exar_gpio->index); mutex_destroy(&exar_gpio->lock); return 0; From patchwork Mon Nov 16 10:42:39 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 327202 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 86133C4742C for ; Mon, 16 Nov 2020 12:04:14 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1F7432224B for ; Mon, 16 Nov 2020 12:04:14 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=bgdev-pl.20150623.gappssmtp.com header.i=@bgdev-pl.20150623.gappssmtp.com header.b="MCQuYzsE" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729209AbgKPKm4 (ORCPT ); Mon, 16 Nov 2020 05:42:56 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37498 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729231AbgKPKmx (ORCPT ); Mon, 16 Nov 2020 05:42:53 -0500 Received: from mail-wr1-x444.google.com (mail-wr1-x444.google.com [IPv6:2a00:1450:4864:20::444]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8934AC0613D1 for ; Mon, 16 Nov 2020 02:42:51 -0800 (PST) Received: by mail-wr1-x444.google.com with SMTP id j7so18128241wrp.3 for ; Mon, 16 Nov 2020 02:42:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Q02O158u45chZEvNdMxWNUDzuTb+nVdXQtak9tzkd6k=; b=MCQuYzsE94uZ96MrROaVasMh9Yb+lHebTfb8vcCk3r0lVc8aEq/89ihbTdreqEjXL4 hjT5x13lZgRMOVTJYM3lj7DwDQCx+ypJeChiWSdYTg+eBWytFW8S/c8FpdnRUyplERRI RzAe2PDp1stjjQKzNKvoh6rV39adoUMS7nYMnpojzVaVaQRW6nj46qvwG5uYlbU3GjjJ YsMxW4qxcpOZRDRF1H9LO2AeMFo4L5bd42DuK69IbZX+SV2RlY9uGy3jplDhayDZbfGh fKJNwhQqzm/QFxS1fzpThR+dc0zSL5ffNl+eRIvOZ15uXxl5szI+jmjIadCk0NyXOc79 4LSw== 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:mime-version:content-transfer-encoding; bh=Q02O158u45chZEvNdMxWNUDzuTb+nVdXQtak9tzkd6k=; b=Xm2Bd1myrHlpAzNdruuaEwNZlOIdy0L5b+DEJSpBjwSpTsOEjmbaTn+Y58W6sGlyhe f+YBO/oKq3qNVWbJeBW3/GAOTh6QfGDmyE1XhGvTz9+lfNkPCHq9mKKJlxlJEw55gsjv Tt/oSQ/ko9oLjMJyllWOf7oYPBWk+vEKpSFqZJvl9tujuK5c9WH8Jy6rwFj/nFpyDtKe DYpVvmDz1l0HtWA4p0s8HB6LWCCQp+5woZ5fcgTEWqAYfstgVEb6vtBg8lcNSByKwaD1 RHma4wfScyBNoPmbTAvjk3YblnSK97n9JJCzz76qt4SxANQ6GqEBgNGf4CqMqAoRUKrZ 4IxQ== X-Gm-Message-State: AOAM533P+HZTduCr/tRGOtS0Xz5N5UuHcnxG/PERyC+LS5oNB30iUm5O rC5DiDoSjGsaphrRyzDo6Zo0jg== X-Google-Smtp-Source: ABdhPJyeaaYf9GeNATyQ2b7LcbL4id4iZBCKBQvrW1miT5wze9Rl7bxXn3r/PPAFCvUExed3atltnA== X-Received: by 2002:adf:fa10:: with SMTP id m16mr18573031wrr.194.1605523370347; Mon, 16 Nov 2020 02:42:50 -0800 (PST) Received: from debian-brgl.home (amarseille-656-1-4-167.w90-8.abo.wanadoo.fr. [90.8.158.167]) by smtp.gmail.com with ESMTPSA id v16sm20583283wml.33.2020.11.16.02.42.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Nov 2020 02:42:49 -0800 (PST) From: Bartosz Golaszewski To: Linus Walleij , Andy Shevchenko , Jan Kiszka , David Laight Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH v5 4/7] gpio: exar: use a helper variable for &pdev->dev Date: Mon, 16 Nov 2020 11:42:39 +0100 Message-Id: <20201116104242.19907-5-brgl@bgdev.pl> X-Mailer: git-send-email 2.29.1 In-Reply-To: <20201116104242.19907-1-brgl@bgdev.pl> References: <20201116104242.19907-1-brgl@bgdev.pl> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org From: Bartosz Golaszewski It's more elegant to use a helper local variable to store the address of the underlying struct device than to dereference pdev everywhere. It also has the benefit of avoiding unnecessary line breaks. Signed-off-by: Bartosz Golaszewski Reviewed-by: Andy Shevchenko --- drivers/gpio/gpio-exar.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/drivers/gpio/gpio-exar.c b/drivers/gpio/gpio-exar.c index 752e8437ff80..db366d85b6b4 100644 --- a/drivers/gpio/gpio-exar.c +++ b/drivers/gpio/gpio-exar.c @@ -120,7 +120,8 @@ static int exar_direction_input(struct gpio_chip *chip, unsigned int offset) static int gpio_exar_probe(struct platform_device *pdev) { - struct pci_dev *pcidev = to_pci_dev(pdev->dev.parent); + struct device *dev = &pdev->dev; + struct pci_dev *pcidev = to_pci_dev(dev->parent); struct exar_gpio_chip *exar_gpio; u32 first_pin, ngpios; void __iomem *p; @@ -134,16 +135,15 @@ static int gpio_exar_probe(struct platform_device *pdev) if (!p) return -ENOMEM; - ret = device_property_read_u32(&pdev->dev, "exar,first-pin", - &first_pin); + ret = device_property_read_u32(dev, "exar,first-pin", &first_pin); if (ret) return ret; - ret = device_property_read_u32(&pdev->dev, "ngpios", &ngpios); + ret = device_property_read_u32(dev, "ngpios", &ngpios); if (ret) return ret; - exar_gpio = devm_kzalloc(&pdev->dev, sizeof(*exar_gpio), GFP_KERNEL); + exar_gpio = devm_kzalloc(dev, sizeof(*exar_gpio), GFP_KERNEL); if (!exar_gpio) return -ENOMEM; @@ -157,7 +157,7 @@ static int gpio_exar_probe(struct platform_device *pdev) sprintf(exar_gpio->name, "exar_gpio%d", index); exar_gpio->gpio_chip.label = exar_gpio->name; - exar_gpio->gpio_chip.parent = &pdev->dev; + exar_gpio->gpio_chip.parent = dev; exar_gpio->gpio_chip.direction_output = exar_direction_output; exar_gpio->gpio_chip.direction_input = exar_direction_input; exar_gpio->gpio_chip.get_direction = exar_get_direction; @@ -169,8 +169,7 @@ static int gpio_exar_probe(struct platform_device *pdev) exar_gpio->index = index; exar_gpio->first_pin = first_pin; - ret = devm_gpiochip_add_data(&pdev->dev, - &exar_gpio->gpio_chip, exar_gpio); + ret = devm_gpiochip_add_data(dev, &exar_gpio->gpio_chip, exar_gpio); if (ret) goto err_destroy; From patchwork Mon Nov 16 10:42:40 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 327209 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A82C9C5519F for ; Mon, 16 Nov 2020 12:03:33 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 555852224B for ; Mon, 16 Nov 2020 12:03:33 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=bgdev-pl.20150623.gappssmtp.com header.i=@bgdev-pl.20150623.gappssmtp.com header.b="EVXPZ0Ti" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729242AbgKPKmz (ORCPT ); Mon, 16 Nov 2020 05:42:55 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37504 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729209AbgKPKmx (ORCPT ); Mon, 16 Nov 2020 05:42:53 -0500 Received: from mail-wr1-x444.google.com (mail-wr1-x444.google.com [IPv6:2a00:1450:4864:20::444]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B30B7C0613D2 for ; Mon, 16 Nov 2020 02:42:52 -0800 (PST) Received: by mail-wr1-x444.google.com with SMTP id p1so18096513wrf.12 for ; Mon, 16 Nov 2020 02:42:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=F5kdznBrJW+VypbGEPNf0OtiokFm6vP4lO2T+vXUmHA=; b=EVXPZ0TiziQKgJREjWEH4+lVZA8i3kfpAqcUeIU4xCWDqfKl0OSo8QzyyIsg9EinRn U3Ivt+N8tfUK8gXiitH9aELWzjQiciHk/lpQmNdL540ODe2cHm1d5W+k9jb/GhVLM/J/ IPp6LCg4rrDpquMBvpsNCpr7kWE/CoWvHnoMP/l/lRsyMMpBxTiIT+lOtoTCcujzLGmm 6fOAWM8PryqoyEpRH4rOaCSP9FOPz8B8bXXT1mOf7Kp7WLnF7MyECcBNdhP0SOt3bi7R VmMgglUFBk7iFwzg1GXuBcMfb/KcWMVbkPHDkGbp8DGknPA7YnmctXWDE4lKjz/7ipYD DwfA== 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:mime-version:content-transfer-encoding; bh=F5kdznBrJW+VypbGEPNf0OtiokFm6vP4lO2T+vXUmHA=; b=ni90dzGTh6Ny4uGAax1N1KCRPZbq4r0BfAbFyvZfV4Hmj/rH/ay3z5HKJZTC1PUDvn k8ANt+ARBTbbNQHN+eYXfLKU2SdYAPFHdmFnbcVAng+TFAEs8ogCg+/xYhfGjrQKFaBM ozb6SbxNx8+NcsMWw14jjYuwayJ4q+KbHobZaVugAejnIZvQj7vSiQgM87BXtGxeRu2h hcyH4a0FASDRbgu1KQ15OSmobgfJ1ugq0KXYaZgutlbU09YfsOxXK+LHoXZ6uSJv9V9S DKY3/0ffPgjD2y0p9MpPqwgXsGXut12y1OZ5/ypn15ZeBX/IXmO8R2AapLEfDr1mkTH9 Qpdw== X-Gm-Message-State: AOAM531P0kNrN8x1gqX74g20nQSnmzCMlBc5NdUrLSV7KMXf+tpgeo+O xRx2I0dX7piBTJnFND7co6H9Wg== X-Google-Smtp-Source: ABdhPJw3GjFgCz8jbwzhIXBPnEYlFhjGQd9hwHbFk5wksN1FbDj4MswRxXCr7Xt3Hg1WEFgX/oBXZg== X-Received: by 2002:a5d:44cf:: with SMTP id z15mr18324947wrr.353.1605523371487; Mon, 16 Nov 2020 02:42:51 -0800 (PST) Received: from debian-brgl.home (amarseille-656-1-4-167.w90-8.abo.wanadoo.fr. [90.8.158.167]) by smtp.gmail.com with ESMTPSA id v16sm20583283wml.33.2020.11.16.02.42.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Nov 2020 02:42:50 -0800 (PST) From: Bartosz Golaszewski To: Linus Walleij , Andy Shevchenko , Jan Kiszka , David Laight Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH v5 5/7] gpio: exar: unduplicate address and offset computation Date: Mon, 16 Nov 2020 11:42:40 +0100 Message-Id: <20201116104242.19907-6-brgl@bgdev.pl> X-Mailer: git-send-email 2.29.1 In-Reply-To: <20201116104242.19907-1-brgl@bgdev.pl> References: <20201116104242.19907-1-brgl@bgdev.pl> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org From: Bartosz Golaszewski Provide and use helpers for calculating the register address and bit offset instead of hand coding it in every function. Signed-off-by: Bartosz Golaszewski Reviewed-by: Andy Shevchenko --- drivers/gpio/gpio-exar.c | 40 ++++++++++++++++++++++++++++------------ 1 file changed, 28 insertions(+), 12 deletions(-) diff --git a/drivers/gpio/gpio-exar.c b/drivers/gpio/gpio-exar.c index db366d85b6b4..28b0b4b5fa35 100644 --- a/drivers/gpio/gpio-exar.c +++ b/drivers/gpio/gpio-exar.c @@ -33,6 +33,26 @@ struct exar_gpio_chip { unsigned int first_pin; }; +static unsigned int +exar_offset_to_sel_addr(struct exar_gpio_chip *exar_gpio, unsigned int offset) +{ + return (offset + exar_gpio->first_pin) / 8 ? EXAR_OFFSET_MPIOSEL_HI + : EXAR_OFFSET_MPIOSEL_LO; +} + +static unsigned int +exar_offset_to_lvl_addr(struct exar_gpio_chip *exar_gpio, unsigned int offset) +{ + return (offset + exar_gpio->first_pin) / 8 ? EXAR_OFFSET_MPIOLVL_HI + : EXAR_OFFSET_MPIOLVL_LO; +} + +static unsigned int +exar_offset_to_bit(struct exar_gpio_chip *exar_gpio, unsigned int offset) +{ + return (offset + exar_gpio->first_pin) % 8; +} + static void exar_update(struct gpio_chip *chip, unsigned int reg, int val, unsigned int offset) { @@ -52,9 +72,8 @@ static int exar_set_direction(struct gpio_chip *chip, int direction, unsigned int offset) { struct exar_gpio_chip *exar_gpio = gpiochip_get_data(chip); - unsigned int addr = (offset + exar_gpio->first_pin) / 8 ? - EXAR_OFFSET_MPIOSEL_HI : EXAR_OFFSET_MPIOSEL_LO; - unsigned int bit = (offset + exar_gpio->first_pin) % 8; + unsigned int addr = exar_offset_to_sel_addr(exar_gpio, offset); + unsigned int bit = exar_offset_to_bit(exar_gpio, offset); exar_update(chip, addr, direction, bit); return 0; @@ -75,9 +94,8 @@ static int exar_get(struct gpio_chip *chip, unsigned int reg) static int exar_get_direction(struct gpio_chip *chip, unsigned int offset) { struct exar_gpio_chip *exar_gpio = gpiochip_get_data(chip); - unsigned int addr = (offset + exar_gpio->first_pin) / 8 ? - EXAR_OFFSET_MPIOSEL_HI : EXAR_OFFSET_MPIOSEL_LO; - unsigned int bit = (offset + exar_gpio->first_pin) % 8; + unsigned int addr = exar_offset_to_sel_addr(exar_gpio, offset); + unsigned int bit = exar_offset_to_bit(exar_gpio, offset); if (exar_get(chip, addr) & BIT(bit)) return GPIO_LINE_DIRECTION_IN; @@ -88,9 +106,8 @@ static int exar_get_direction(struct gpio_chip *chip, unsigned int offset) static int exar_get_value(struct gpio_chip *chip, unsigned int offset) { struct exar_gpio_chip *exar_gpio = gpiochip_get_data(chip); - unsigned int addr = (offset + exar_gpio->first_pin) / 8 ? - EXAR_OFFSET_MPIOLVL_HI : EXAR_OFFSET_MPIOLVL_LO; - unsigned int bit = (offset + exar_gpio->first_pin) % 8; + unsigned int addr = exar_offset_to_lvl_addr(exar_gpio, offset); + unsigned int bit = exar_offset_to_bit(exar_gpio, offset); return !!(exar_get(chip, addr) & BIT(bit)); } @@ -99,9 +116,8 @@ static void exar_set_value(struct gpio_chip *chip, unsigned int offset, int value) { struct exar_gpio_chip *exar_gpio = gpiochip_get_data(chip); - unsigned int addr = (offset + exar_gpio->first_pin) / 8 ? - EXAR_OFFSET_MPIOLVL_HI : EXAR_OFFSET_MPIOLVL_LO; - unsigned int bit = (offset + exar_gpio->first_pin) % 8; + unsigned int addr = exar_offset_to_lvl_addr(exar_gpio, offset); + unsigned int bit = exar_offset_to_bit(exar_gpio, offset); exar_update(chip, addr, value, bit); } From patchwork Mon Nov 16 10:42:41 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 324814 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1F441C5519F for ; Mon, 16 Nov 2020 12:03:54 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id AC85A2224B for ; Mon, 16 Nov 2020 12:03:53 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=bgdev-pl.20150623.gappssmtp.com header.i=@bgdev-pl.20150623.gappssmtp.com header.b="HY31/PcY" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729236AbgKPKmz (ORCPT ); Mon, 16 Nov 2020 05:42:55 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37512 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729233AbgKPKmy (ORCPT ); Mon, 16 Nov 2020 05:42:54 -0500 Received: from mail-wm1-x344.google.com (mail-wm1-x344.google.com [IPv6:2a00:1450:4864:20::344]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D8CBBC0617A6 for ; Mon, 16 Nov 2020 02:42:53 -0800 (PST) Received: by mail-wm1-x344.google.com with SMTP id w24so23156668wmi.0 for ; Mon, 16 Nov 2020 02:42:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=NzHd8yMlzJUVP/iKaDBAkoAJiAGV4P4WxXUX90OVeHw=; b=HY31/PcYcfd4XT9V24pQkQqWPiOUyhA489/gFpMk5EzhTGUehSGkoh4XbTYis4TurZ xFA7hPao/FaH7kjJRaA+o2cA0y9LYvkn4Ib8khnLBbXNk0UMC0WMjnwgjFzsZ8Q303Xa oH8OghRsvqrlk7UlMphu8Zwz2C1iyypRxtlN/B/9lotAAdwBn59hvDhrw5uwvr+SjM66 jg58fpuYmU1XrKXbloI8ti/RLJsN4hW2nA3CYjdu2m0WYiuh//X1suMLpmYy5HYyM9gp hGJv1Wf2Nx+JW7lZ5L+5XQr/9UEg8HgQkoLPB52e6ZgnvUETnNUzXWsBCZnUIQvVvS3J DZEQ== 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:mime-version:content-transfer-encoding; bh=NzHd8yMlzJUVP/iKaDBAkoAJiAGV4P4WxXUX90OVeHw=; b=m+xWXny7/ZjmHpDPlnuMyXgOepgbBV+s8YZs2xOmMmgkcKo/KN5d15qZIJabVaaQzD z/aosWKDPbi3SOUsdYxzB3HR/sWZptxVPmYeNPLKuwSUf+dWZ66C12diCTh6Fs+Uckhy zGUHTsa2jmS/X9U+BagHyXU0wQ+knMQ/R8z3yc6e45QbRQhGfGFBvDDOdRYOt83II73c WySjvUi15gIHtmaqCdbKhMVd6BoBZ8H0V33fITt8Ouii4dIRaIpbBhmfssI1QuOg/FqD hyPHMsgSkzJgIWdjxYxM79L81AA+Dcr74EBvHQ1GBA0UzUSCAcxcOLXmBQgVy+hLibjV iolA== X-Gm-Message-State: AOAM5326XkofsWsHbsLihkF5eQAj5U1YctnbS+JrpSAMfJImpcpH0u8C XUVIvWQrAmcr/wCqtLbyDqtdPw== X-Google-Smtp-Source: ABdhPJysv+mfcnM/Yeqh8j8pF9nfGBraGAuzwMlySbsTsJLNspINsw2bCuMp0VAcFiy9zbgGT1USgg== X-Received: by 2002:a1c:e006:: with SMTP id x6mr15135428wmg.107.1605523372546; Mon, 16 Nov 2020 02:42:52 -0800 (PST) Received: from debian-brgl.home (amarseille-656-1-4-167.w90-8.abo.wanadoo.fr. [90.8.158.167]) by smtp.gmail.com with ESMTPSA id v16sm20583283wml.33.2020.11.16.02.42.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Nov 2020 02:42:52 -0800 (PST) From: Bartosz Golaszewski To: Linus Walleij , Andy Shevchenko , Jan Kiszka , David Laight Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH v5 6/7] gpio: exar: switch to using regmap Date: Mon, 16 Nov 2020 11:42:41 +0100 Message-Id: <20201116104242.19907-7-brgl@bgdev.pl> X-Mailer: git-send-email 2.29.1 In-Reply-To: <20201116104242.19907-1-brgl@bgdev.pl> References: <20201116104242.19907-1-brgl@bgdev.pl> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org From: Bartosz Golaszewski We can simplify the code in gpio-exar by using regmap. This allows us to drop the mutex (regmap provides its own locking) and we can also reuse regmap's bit operations instead of implementing our own update function. Signed-off-by: Bartosz Golaszewski Reviewed-by: Andy Shevchenko --- drivers/gpio/Kconfig | 1 + drivers/gpio/gpio-exar.c | 96 ++++++++++++++++++---------------------- 2 files changed, 43 insertions(+), 54 deletions(-) diff --git a/drivers/gpio/Kconfig b/drivers/gpio/Kconfig index 5d4de5cd6759..253a61ec9645 100644 --- a/drivers/gpio/Kconfig +++ b/drivers/gpio/Kconfig @@ -255,6 +255,7 @@ config GPIO_EP93XX config GPIO_EXAR tristate "Support for GPIO pins on XR17V352/354/358" depends on SERIAL_8250_EXAR + select REGMAP_MMIO help Selecting this option will enable handling of GPIO pins present on Exar XR17V352/354/358 chips. diff --git a/drivers/gpio/gpio-exar.c b/drivers/gpio/gpio-exar.c index 28b0b4b5fa35..79fb0964ace3 100644 --- a/drivers/gpio/gpio-exar.c +++ b/drivers/gpio/gpio-exar.c @@ -14,6 +14,7 @@ #include #include #include +#include #define EXAR_OFFSET_MPIOLVL_LO 0x90 #define EXAR_OFFSET_MPIOSEL_LO 0x93 @@ -26,9 +27,8 @@ static DEFINE_IDA(ida_index); struct exar_gpio_chip { struct gpio_chip gpio_chip; - struct mutex lock; + struct regmap *regmap; int index; - void __iomem *regs; char name[20]; unsigned int first_pin; }; @@ -53,51 +53,13 @@ exar_offset_to_bit(struct exar_gpio_chip *exar_gpio, unsigned int offset) return (offset + exar_gpio->first_pin) % 8; } -static void exar_update(struct gpio_chip *chip, unsigned int reg, int val, - unsigned int offset) -{ - struct exar_gpio_chip *exar_gpio = gpiochip_get_data(chip); - int temp; - - mutex_lock(&exar_gpio->lock); - temp = readb(exar_gpio->regs + reg); - temp &= ~BIT(offset); - if (val) - temp |= BIT(offset); - writeb(temp, exar_gpio->regs + reg); - mutex_unlock(&exar_gpio->lock); -} - -static int exar_set_direction(struct gpio_chip *chip, int direction, - unsigned int offset) -{ - struct exar_gpio_chip *exar_gpio = gpiochip_get_data(chip); - unsigned int addr = exar_offset_to_sel_addr(exar_gpio, offset); - unsigned int bit = exar_offset_to_bit(exar_gpio, offset); - - exar_update(chip, addr, direction, bit); - return 0; -} - -static int exar_get(struct gpio_chip *chip, unsigned int reg) -{ - struct exar_gpio_chip *exar_gpio = gpiochip_get_data(chip); - int value; - - mutex_lock(&exar_gpio->lock); - value = readb(exar_gpio->regs + reg); - mutex_unlock(&exar_gpio->lock); - - return value; -} - static int exar_get_direction(struct gpio_chip *chip, unsigned int offset) { struct exar_gpio_chip *exar_gpio = gpiochip_get_data(chip); unsigned int addr = exar_offset_to_sel_addr(exar_gpio, offset); unsigned int bit = exar_offset_to_bit(exar_gpio, offset); - if (exar_get(chip, addr) & BIT(bit)) + if (regmap_test_bits(exar_gpio->regmap, addr, BIT(bit))) return GPIO_LINE_DIRECTION_IN; return GPIO_LINE_DIRECTION_OUT; @@ -109,7 +71,7 @@ static int exar_get_value(struct gpio_chip *chip, unsigned int offset) unsigned int addr = exar_offset_to_lvl_addr(exar_gpio, offset); unsigned int bit = exar_offset_to_bit(exar_gpio, offset); - return !!(exar_get(chip, addr) & BIT(bit)); + return !!(regmap_test_bits(exar_gpio->regmap, addr, BIT(bit))); } static void exar_set_value(struct gpio_chip *chip, unsigned int offset, @@ -119,21 +81,47 @@ static void exar_set_value(struct gpio_chip *chip, unsigned int offset, unsigned int addr = exar_offset_to_lvl_addr(exar_gpio, offset); unsigned int bit = exar_offset_to_bit(exar_gpio, offset); - exar_update(chip, addr, value, bit); + if (value) + regmap_set_bits(exar_gpio->regmap, addr, BIT(bit)); + else + regmap_clear_bits(exar_gpio->regmap, addr, BIT(bit)); } static int exar_direction_output(struct gpio_chip *chip, unsigned int offset, int value) { + struct exar_gpio_chip *exar_gpio = gpiochip_get_data(chip); + unsigned int addr = exar_offset_to_sel_addr(exar_gpio, offset); + unsigned int bit = exar_offset_to_bit(exar_gpio, offset); + exar_set_value(chip, offset, value); - return exar_set_direction(chip, 0, offset); + regmap_clear_bits(exar_gpio->regmap, addr, BIT(bit)); + + return 0; } static int exar_direction_input(struct gpio_chip *chip, unsigned int offset) { - return exar_set_direction(chip, 1, offset); + struct exar_gpio_chip *exar_gpio = gpiochip_get_data(chip); + unsigned int addr = exar_offset_to_sel_addr(exar_gpio, offset); + unsigned int bit = exar_offset_to_bit(exar_gpio, offset); + + regmap_set_bits(exar_gpio->regmap, addr, BIT(bit)); + + return 0; } +static const struct regmap_config exar_regmap_config = { + .name = "exar-gpio", + /* + * While we're not programmatically blocking the regmap from accessing + * any non-GPIO registers, 11 address bits holds the maximum address + * we need to access from this driver. + */ + .reg_bits = 11, + .val_bits = 8, +}; + static int gpio_exar_probe(struct platform_device *pdev) { struct device *dev = &pdev->dev; @@ -163,13 +151,17 @@ static int gpio_exar_probe(struct platform_device *pdev) if (!exar_gpio) return -ENOMEM; - mutex_init(&exar_gpio->lock); + /* + * We don't need to check the return values of mmio regmap operations (unless + * the regmap has a clock attached which is not the case here). + */ + exar_gpio->regmap = devm_regmap_init_mmio(dev, p, &exar_regmap_config); + if (IS_ERR(exar_gpio->regmap)) + return PTR_ERR(exar_gpio->regmap); index = ida_alloc(&ida_index, GFP_KERNEL); - if (index < 0) { - ret = index; - goto err_mutex_destroy; - } + if (index < 0) + return index; sprintf(exar_gpio->name, "exar_gpio%d", index); exar_gpio->gpio_chip.label = exar_gpio->name; @@ -181,7 +173,6 @@ static int gpio_exar_probe(struct platform_device *pdev) exar_gpio->gpio_chip.set = exar_set_value; exar_gpio->gpio_chip.base = -1; exar_gpio->gpio_chip.ngpio = ngpios; - exar_gpio->regs = p; exar_gpio->index = index; exar_gpio->first_pin = first_pin; @@ -195,8 +186,6 @@ static int gpio_exar_probe(struct platform_device *pdev) err_destroy: ida_free(&ida_index, index); -err_mutex_destroy: - mutex_destroy(&exar_gpio->lock); return ret; } @@ -205,7 +194,6 @@ static int gpio_exar_remove(struct platform_device *pdev) struct exar_gpio_chip *exar_gpio = platform_get_drvdata(pdev); ida_free(&ida_index, exar_gpio->index); - mutex_destroy(&exar_gpio->lock); return 0; } From patchwork Mon Nov 16 10:42:42 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 324813 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1919CC5519F for ; Mon, 16 Nov 2020 12:05:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A3DA022263 for ; Mon, 16 Nov 2020 12:05:35 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=bgdev-pl.20150623.gappssmtp.com header.i=@bgdev-pl.20150623.gappssmtp.com header.b="T+tUvkIF" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729267AbgKPKnA (ORCPT ); Mon, 16 Nov 2020 05:43:00 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37516 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729232AbgKPKm4 (ORCPT ); Mon, 16 Nov 2020 05:42:56 -0500 Received: from mail-wm1-x342.google.com (mail-wm1-x342.google.com [IPv6:2a00:1450:4864:20::342]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D4224C061A04 for ; Mon, 16 Nov 2020 02:42:54 -0800 (PST) Received: by mail-wm1-x342.google.com with SMTP id c9so23251524wml.5 for ; Mon, 16 Nov 2020 02:42:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=v6hO2EdktD6tTwbP0hf9n6mHqN7h4IqXAlEVl1IexRM=; b=T+tUvkIF+iH4K8+P7U64YpgECCTYj+oVV2Ij3yc1MDvVMu+ziOO6jKj29VjW7Zf4UR BGkzB9TV+T8Xcu7p8oR2x2ePl/BzA8jQs6t/cqXalSzA54H0t8+smAzDpF3XqeLGkhkV 26uANPiz6+nqI0KfbuHTnqnGZRrsIJk7gSfik7PFY/WskKul9Ncz4pgNSohp69ulfP3P 4mccSQTOVDm9DnRGvo2m+83H8OGR165kgHaVg/HCu38Nyk1qHbL4GnEGPsL3pTqWJFWE ILMUnR6idga7JubvwejWzkqB87KiqagNkMJsHnjbkbu7n/kTUGOhZ0ZgIqwX5DNVV3ij 4CEg== 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:mime-version:content-transfer-encoding; bh=v6hO2EdktD6tTwbP0hf9n6mHqN7h4IqXAlEVl1IexRM=; b=sAJ+FQXQMIVpExSKalo4UnXeJjBISc7nOXCtD7zo0/k/Y4M98W4bWtWcRPc+NZ28Hz virVWI060/QLw6flux/baquLqzhjsSahIRRuhRo7ziGz9GY+wn7u0jKNrh1nBwRXLpR4 9ZuxQNiS9lJAERiqTq+JJH0QoznLX5SbqwHegetDB/ag9AkV5TBqL+h1zFtavkYONB/W vNXAs8gBNwGU59Vor5J5G0rHpc72nj/x1v904mRMq3lESsv/dADZs/NXPCoJaqmQ57zA SGfHS2lyZgrnUgQ9C0h9RCVni8eZiT1IWQMPNfoIUOr0DAYGufRVkl9tN2T9m3PVtGsD Iy5w== X-Gm-Message-State: AOAM531RTPI12aHF2TiSAzwmNSCgvuRA0bRnKmmr4S+5MxUKqBfUtjhe hKfr3uM3Au/kiNkrvcyqLTMzTg== X-Google-Smtp-Source: ABdhPJw+poV12SjtIeBVrkrmoi0MFRcpkejjbt0VzAUy70UMCekqpQfFhC7AOmFs6L7Fjs1chqY9Ww== X-Received: by 2002:a1c:21c1:: with SMTP id h184mr15545483wmh.106.1605523373631; Mon, 16 Nov 2020 02:42:53 -0800 (PST) Received: from debian-brgl.home (amarseille-656-1-4-167.w90-8.abo.wanadoo.fr. [90.8.158.167]) by smtp.gmail.com with ESMTPSA id v16sm20583283wml.33.2020.11.16.02.42.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Nov 2020 02:42:53 -0800 (PST) From: Bartosz Golaszewski To: Linus Walleij , Andy Shevchenko , Jan Kiszka , David Laight Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH v5 7/7] gpio: exar: use devm action for freeing the IDA and drop remove() Date: Mon, 16 Nov 2020 11:42:42 +0100 Message-Id: <20201116104242.19907-8-brgl@bgdev.pl> X-Mailer: git-send-email 2.29.1 In-Reply-To: <20201116104242.19907-1-brgl@bgdev.pl> References: <20201116104242.19907-1-brgl@bgdev.pl> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org From: Bartosz Golaszewski We can simplify the error path in probe() and drop remove() entirely if we provide a devm action for freeing the device ID. Signed-off-by: Bartosz Golaszewski Reviewed-by: Andy Shevchenko --- drivers/gpio/gpio-exar.c | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/drivers/gpio/gpio-exar.c b/drivers/gpio/gpio-exar.c index 79fb0964ace3..e4c1ac88d2ba 100644 --- a/drivers/gpio/gpio-exar.c +++ b/drivers/gpio/gpio-exar.c @@ -111,6 +111,13 @@ static int exar_direction_input(struct gpio_chip *chip, unsigned int offset) return 0; } +static void exar_devm_ida_free(void *data) +{ + struct exar_gpio_chip *exar_gpio = data; + + ida_free(&ida_index, exar_gpio->index); +} + static const struct regmap_config exar_regmap_config = { .name = "exar-gpio", /* @@ -163,6 +170,10 @@ static int gpio_exar_probe(struct platform_device *pdev) if (index < 0) return index; + ret = devm_add_action_or_reset(dev, exar_devm_ida_free, exar_gpio); + if (ret) + return ret; + sprintf(exar_gpio->name, "exar_gpio%d", index); exar_gpio->gpio_chip.label = exar_gpio->name; exar_gpio->gpio_chip.parent = dev; @@ -178,29 +189,15 @@ static int gpio_exar_probe(struct platform_device *pdev) ret = devm_gpiochip_add_data(dev, &exar_gpio->gpio_chip, exar_gpio); if (ret) - goto err_destroy; + return ret; platform_set_drvdata(pdev, exar_gpio); - return 0; - -err_destroy: - ida_free(&ida_index, index); - return ret; -} - -static int gpio_exar_remove(struct platform_device *pdev) -{ - struct exar_gpio_chip *exar_gpio = platform_get_drvdata(pdev); - - ida_free(&ida_index, exar_gpio->index); - return 0; } static struct platform_driver gpio_exar_driver = { .probe = gpio_exar_probe, - .remove = gpio_exar_remove, .driver = { .name = DRIVER_NAME, },