From patchwork Tue Nov 10 14:55:46 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 1397679 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=linux-gpio-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=bgdev.pl Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=bgdev-pl.20150623.gappssmtp.com header.i=@bgdev-pl.20150623.gappssmtp.com header.a=rsa-sha256 header.s=20150623 header.b=w+ZcawHw; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4CVrYf3ZC9z9sVT for ; Wed, 11 Nov 2020 01:57:10 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731450AbgKJO4O (ORCPT ); Tue, 10 Nov 2020 09:56:14 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36640 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731227AbgKJO4H (ORCPT ); Tue, 10 Nov 2020 09:56:07 -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 5BD36C0613D1 for ; Tue, 10 Nov 2020 06:56:05 -0800 (PST) Received: by mail-wr1-x443.google.com with SMTP id k2so9587627wrx.2 for ; Tue, 10 Nov 2020 06:56:05 -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=A7Q6GcsOlUvCk0TynHXF9lujyUa3NnBo8eWmuL6l7+w=; b=w+ZcawHwB0e3nB10uWI5DX6CesgFsMuEwayRrb8XkjoRWUp0F/fCC7j5OVqQ1ZPWGj tA3151tQRB2+KJHEb8MJkzDqtN0Phvg7QYOrINaW1/t21gObq8PaefxB3iOo07bLp6yr E3xmoNacZfG6A/RDC+1A6gH1QB7CizNMfRH99ZAOdBMJT4B9ApoA8ppYNSyA9jsAolxF +3ZmzwdrQVL8BGfjkRg+eYYHtMKxklpKZDQUtUae5SROj/DPYAmpI2o5rVNLFozbXHIX GiCajga5UXzrpUP7/w7fPR+DcfeYuD8CvF51qkIi2A7kQW3DyQchWcv3us+i+q4GBySD SPcg== 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=A7Q6GcsOlUvCk0TynHXF9lujyUa3NnBo8eWmuL6l7+w=; b=b7RLG/ikVwMWZGL7xXkXuaePY3Zsdctp/POnYrm4A+gJY4YfoenEuRlp1qqk9wnBWH Hj4CxRJY/r9bBKNEP7vePlZWZ8zGtpkHJygdzVKsnsCwsrwI8ajTlgvh+8Lp4RrYG/YJ 3wzlYZHdFeHFTpzzSdWU56RF1WMIPw6YPcKIyAAH/h+l03LGWs0tIByyM3R79ayShS97 9B47pTWw0S08InmMdXHRe0zIhJK1UJ6vZE3p6Di5dlvut2tjJM/sCNL6XpXo6a1BbDzR 0xkxtSHbl6l1EvcFQIgChNirRqiGq3ULlE+dP+PhWGn0oJbHxV8hhrgZHfiR7RR66iWR 90rg== X-Gm-Message-State: AOAM533M1K64DfNOYAOySIbE4OWxsdFIyEkWa4sH2jECHQxU3ycYH3Mi vrYkDLTBv4xhnIZA9v6R3OPVgQ== X-Google-Smtp-Source: ABdhPJxOU/dttXRMN7VN6gM9Zf9mVLj8tSVjQRRNqbDf/ak/UG0PszbRWOZvfgV4zELM3w7aMe8OSA== X-Received: by 2002:adf:8304:: with SMTP id 4mr23920371wrd.215.1605020164113; Tue, 10 Nov 2020 06:56:04 -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 f17sm3261827wmf.41.2020.11.10.06.56.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Nov 2020 06:56:03 -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 v4 1/7] gpio: exar: add a newline after the copyright notice Date: Tue, 10 Nov 2020 15:55:46 +0100 Message-Id: <20201110145552.23024-2-brgl@bgdev.pl> X-Mailer: git-send-email 2.29.1 In-Reply-To: <20201110145552.23024-1-brgl@bgdev.pl> References: <20201110145552.23024-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 --- 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 Tue Nov 10 14:55:47 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 1397681 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=linux-gpio-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=bgdev.pl Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=bgdev-pl.20150623.gappssmtp.com header.i=@bgdev-pl.20150623.gappssmtp.com header.a=rsa-sha256 header.s=20150623 header.b=yCgj1oxm; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4CVrZ93XpZz9sSn for ; Wed, 11 Nov 2020 01:57:37 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730980AbgKJO4K (ORCPT ); Tue, 10 Nov 2020 09:56:10 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36646 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731269AbgKJO4H (ORCPT ); Tue, 10 Nov 2020 09:56:07 -0500 Received: from mail-wm1-x343.google.com (mail-wm1-x343.google.com [IPv6:2a00:1450:4864:20::343]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2C575C0613CF for ; Tue, 10 Nov 2020 06:56:07 -0800 (PST) Received: by mail-wm1-x343.google.com with SMTP id a65so3278363wme.1 for ; Tue, 10 Nov 2020 06:56:07 -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=t/9DP21Y/K7Z/VraeZB1byIXgPmUm3+JNNTaYKuJoag=; b=yCgj1oxmbWVJO6aVvwgbnT+plK9gHErnJySsC0rvLE93LMEFpncao3WCRK2Vup/Ftp EvrQK5aOtyaqccw82bjKKT0By1YBbO6mB2VIUCHAs1BbXmyAlUn7ZNr5rYeSkQPOoA2g HLnjsndjEM2rY7DKAdnMVkgmpOUSzOsEVMsrr00Sq5MfBYkn29umHdi7QLVBeUWLlzJh AcX1onVuBbUB7J66a6ZCYYynMVjHjNWINKWUBDoPAPe0xKULJ/5USryuRpPm/r7V8OKC gonR75UmoEROFpEIYWd867tsCTBgFsPGlbv7w/XO8HO33JKkV1F4f489NxT8OFiHWdSm Wk9Q== 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=t/9DP21Y/K7Z/VraeZB1byIXgPmUm3+JNNTaYKuJoag=; b=JmtM2UaG+X3Gh+7KfuSb6p1pgVAojuJiywxL3sLUDk9vB9bJT0hOBVJdS1+KDTG+// OxiqI05G7TQHwtnBdcb4mIfIgiaJu3L85j04+S6VD5yv7epYDyv13bbhwaSFF7+dZjMq 60yPLTr7am57q7vPs2EsSKSDFAyMvn+U6k34U1k5SjKTHrMA7MjLaFyfMWxrlYgtknEy TZhPmc+s+uStdmrAeXnpFLG2ft/QNkk7OInTGVNYBE31PdNV0zFJvDHJ7yiJVHFw+edp afz5KxaFoReykbDcYxiMzDfP0pPKs5oXt0+RAkRzbn4UGvmaFEsDjvjA4J2YtpvstIfB GLFA== X-Gm-Message-State: AOAM533ftiI4C7fUfkYIynfuwYmgunxW8GBs99SjnVJNf0S3Sa7zkktQ qPwc+2bDThwBqkH5MUeWRvfAU1HzpktMpQ== X-Google-Smtp-Source: ABdhPJzM0Wppb5vLfoZiyRJDDDkhJ0pmMKa0I+sNKbEvWvqYYWvGmSu7oNwQqM1QJgr9I+msZ4mQWQ== X-Received: by 2002:a1c:dc43:: with SMTP id t64mr24205wmg.93.1605020165987; Tue, 10 Nov 2020 06:56:05 -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 f17sm3261827wmf.41.2020.11.10.06.56.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Nov 2020 06:56:05 -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 v4 2/7] gpio: exar: include idr.h Date: Tue, 10 Nov 2020 15:55:47 +0100 Message-Id: <20201110145552.23024-3-brgl@bgdev.pl> X-Mailer: git-send-email 2.29.1 In-Reply-To: <20201110145552.23024-1-brgl@bgdev.pl> References: <20201110145552.23024-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 --- 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 Tue Nov 10 14:55:48 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 1397676 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=linux-gpio-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=bgdev.pl Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=bgdev-pl.20150623.gappssmtp.com header.i=@bgdev-pl.20150623.gappssmtp.com header.a=rsa-sha256 header.s=20150623 header.b=mkdc4a/V; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4CVrXb29KMz9sSn for ; Wed, 11 Nov 2020 01:56:15 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731336AbgKJO4M (ORCPT ); Tue, 10 Nov 2020 09:56:12 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36658 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731071AbgKJO4J (ORCPT ); Tue, 10 Nov 2020 09:56:09 -0500 Received: from mail-wm1-x343.google.com (mail-wm1-x343.google.com [IPv6:2a00:1450:4864:20::343]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 69076C0613CF for ; Tue, 10 Nov 2020 06:56:09 -0800 (PST) Received: by mail-wm1-x343.google.com with SMTP id p22so3268625wmg.3 for ; Tue, 10 Nov 2020 06:56:09 -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=lQQN2ZXT/G4B3VsGNJyIkmXWhvmT1sWJqpvE2SPt6Is=; b=mkdc4a/Vq0qaL8gzrCe8K5A2vQu2bDGUGNMOeokwa3SNxVFKN5NQ1nqgyL6x8vjDU8 TvuapYnLvidxCywlQpqzHoeu4gxVV7vfXNY2Ic/IR6F4tiXAdA3mPbZhY8oe4J6rwOxf TQNXyX/nq2GamnXff5eUnNYIW6MHne+p9zLEdW3yLy/2ipXjMGCUXAfJIZCqDWly9sHe E6RvXY2WhYx0oRoJ1+yKG2LNdlWOe7RdvnuosyFREaL01OTliWHMlPZuZ7sgsD5uE5Bx YAFrzboacb/mr0AGHEOnho1mkb4I23ovwZzRrkW+gYhfJjXgrCqSK8ZyuxpwVoLXa2OJ uyvQ== 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=lQQN2ZXT/G4B3VsGNJyIkmXWhvmT1sWJqpvE2SPt6Is=; b=sVwLF1lFoVfvqeej0GuogzfKW2pPuhGuq1LPCJMJsETzoc7fag8NaKD08E7dSyzLbi II6BZjjohrvwXWB5uLN/WN3Ci0GSS1CFd4Xp+cxL5sjufc4AhjISQX4ffr1v3qnNJ2bX bcJhFGGdMwP92Ujh14Md4EobbKlAEQ7xFSYFRGBzq2W4N9GS2UarFarSOQLjaJgNJm+f 3DDsCVr1x664jJl/STwU48PBGCzGNW+AJ0cZ5q/gwjRIfBPXDA519A64cXjnxeyNTf/X kM0iJrvWBc8M1V7OQnDW532p1JFR2WOacJ7VfFlhoWoA1RQ/fObO03sfVs3g51ujUPCV Xj/A== X-Gm-Message-State: AOAM532IuGAmDSEiGM6LvyC5KHLualVrvpEMgOmDsANj64I2Dv0ubk/V O6IqSl4gEZRlaVA+mz9YBpsxEs/w9DOOqQ== X-Google-Smtp-Source: ABdhPJwhjmOoXzlfLdo6Htid2e6bfJNCrwZ7lF3zV1eOPcQ5phWcPfA0pn7jw10OizzBVSS79h2M7g== X-Received: by 2002:a1c:5f45:: with SMTP id t66mr86249wmb.20.1605020168221; Tue, 10 Nov 2020 06:56:08 -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 f17sm3261827wmf.41.2020.11.10.06.56.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Nov 2020 06:56:07 -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 v4 3/7] gpio: exar: switch to a simpler IDA interface Date: Tue, 10 Nov 2020 15:55:48 +0100 Message-Id: <20201110145552.23024-4-brgl@bgdev.pl> X-Mailer: git-send-email 2.29.1 In-Reply-To: <20201110145552.23024-1-brgl@bgdev.pl> References: <20201110145552.23024-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 --- 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 Tue Nov 10 14:55:49 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 1397682 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=linux-gpio-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=bgdev.pl Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=bgdev-pl.20150623.gappssmtp.com header.i=@bgdev-pl.20150623.gappssmtp.com header.a=rsa-sha256 header.s=20150623 header.b=oH8PSeyx; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4CVrZ96Bdyz9sTL for ; Wed, 11 Nov 2020 01:57:37 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732579AbgKJO5g (ORCPT ); Tue, 10 Nov 2020 09:57:36 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36666 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731362AbgKJO4M (ORCPT ); Tue, 10 Nov 2020 09:56:12 -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 F0227C0613D1 for ; Tue, 10 Nov 2020 06:56:10 -0800 (PST) Received: by mail-wm1-x344.google.com with SMTP id p22so3268677wmg.3 for ; Tue, 10 Nov 2020 06:56:10 -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=PfaggvFtdrOq7HMZ8nUir6KiglSCvEmyQ3kUEaGT+6M=; b=oH8PSeyxv2g2mkm6KifL0XdKT+rnspnOhbMzDwnzQm+pMPh1hvK7EOwAMzac79SqZK 02bezL3Z26b5Y1QQInMat2eNtle5JTjAlMPuOmYYL9tIDPn8i/wV0kU/a76NDy1hQkYb i8OAz2nc+GlPheoFPrE3frOE7yBA/OWej0UIrmeftDJdeDPE6z5ldKOHMS319H2Xcp4S 6Vrzkze/jhidKVPQpXUgmzS6ZAsFrfPzEHRLnVuBLTm/sR9bFvw9bxLF+imueoV1cy6i azs3f+c6EFu7MuIdUFVfMfdCndE6lYwqZdGE5oIg89LV8RIst4wl68eLeWZYMrvZzTkx nImA== 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=PfaggvFtdrOq7HMZ8nUir6KiglSCvEmyQ3kUEaGT+6M=; b=tc3L/hb9+Y21B3yvzTv6SseTbz8sYUaQ85vhWf7eoWgQCFcKVrrl5T9w6/CDAYGVfU BCxue46iNP1LlUIgCMGMQ08j0CBNYWigy76D+LbuDRVlkdWKYVINB0uQ5ncWLHxC3++i 4L7S5JDq6lCumu2ZlJ2s1TFFBpCK9qE2lqgxGDQZHtwkRvw2U2oouquZmntnvJyzWRS8 D4NlntFRV5Y8pvO0qnibJ39k8S8cg06C2TxBP2Sbb8b75bRg7b5opuXH4WPWj4a0z/Gg aLqMjw5QO5m431dYlTUgxrt9u2lcewj+FeJHzsGAMYqgDYCggmLflUaxMdiRroBskzBP VR/A== X-Gm-Message-State: AOAM5305ZNfSiSevoKwFv8XZ5kmxpTunu7v2LdalFy8bH2mI3ZAZVxDG 9SisafeKhsk+1UyQqP7VV2lcgA== X-Google-Smtp-Source: ABdhPJw59JjHRG83+v/lXqJnyd7wHgrv1ByRW6rnrf5bN06bCOwu6mtyTnRWQB6aq876+beC9tOOPQ== X-Received: by 2002:a1c:87:: with SMTP id 129mr87959wma.34.1605020169728; Tue, 10 Nov 2020 06:56:09 -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 f17sm3261827wmf.41.2020.11.10.06.56.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Nov 2020 06:56:09 -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 v4 4/7] gpio: exar: use a helper variable for &pdev->dev Date: Tue, 10 Nov 2020 15:55:49 +0100 Message-Id: <20201110145552.23024-5-brgl@bgdev.pl> X-Mailer: git-send-email 2.29.1 In-Reply-To: <20201110145552.23024-1-brgl@bgdev.pl> References: <20201110145552.23024-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 --- 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 Tue Nov 10 14:55:50 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 1397680 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=linux-gpio-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=bgdev.pl Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=bgdev-pl.20150623.gappssmtp.com header.i=@bgdev-pl.20150623.gappssmtp.com header.a=rsa-sha256 header.s=20150623 header.b=zDD20QVM; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4CVrYr07gFz9sSn for ; Wed, 11 Nov 2020 01:57:20 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732628AbgKJO5S (ORCPT ); Tue, 10 Nov 2020 09:57:18 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36672 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731365AbgKJO4M (ORCPT ); Tue, 10 Nov 2020 09:56:12 -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 12E11C0613D3 for ; Tue, 10 Nov 2020 06:56:12 -0800 (PST) Received: by mail-wm1-x344.google.com with SMTP id d142so3272678wmd.4 for ; Tue, 10 Nov 2020 06:56:12 -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=SyfsPFMi1Ol5bHDdeg25EiAHS6gH8P7QyAg8QmJ1Sho=; b=zDD20QVMC5IWBHog2KuNoZ8pGkgPX7Zgy2+KbJMYTZd7PKhDV4IOzOKifhW8EuzDVK D0U/twFCuXZ3WEeYgaxiAHj5xg5Sab2cVpforIiTC+gHdaOo4vIxiq6Ck47ijCy+UjZ6 amPapieoKB19FzEe7XAlat3NXSfFVxI5Zieabreptqz//W5hT1Fy8o+6mi2LiTpAIrQg U7gawmdly0dGU8m5G8tglRiier3RXnuLCy6oRDMNKXgbVNnDTWtzeXFfn4KE+4HKc3OG fVejE3kUK5B71SR2eBjKFiiKInsZ0q1k3XN4h9j3i6IiqiteJ7VC757UDUZc1fiWNU3V 6gvA== 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=SyfsPFMi1Ol5bHDdeg25EiAHS6gH8P7QyAg8QmJ1Sho=; b=Ds2SA8vZxO9Ml6ZUQ7BFC9SXAGyjHffYAt+ibP/sZpCdt6/m+wOnBx5KgGL6FUzS5z 42jSwFl+thqLEnMUeUCHpOHE5BzQWR7k+JTAdIfJCqXh/oy9m2m8u5cS+LcJIBH5Dwao G3aCeFjEbADeL2hr3OLX5eUZGK7hsHl7Ld96uqHbJJGY6+BGXR2+N4T8CyuWGe/l/Kb+ F3McXGlqhqvleLAYLAAw2AfUPoTgx5s08IfL6hhin+Cdt0CVAw8+BRfyAnMiCeg7nTRe bCm0Lg/WY/TAXpKXEAU/QwLSD+V7HIVZec2XE8/CES296zuAI8mNpA6PIY/8116wJ9qt sEbg== X-Gm-Message-State: AOAM530wMzViw3zKWIHUeaSS+F8968nD9teUq83M4oLmYQD6cg9Y9AcT ptmyBsLYZtH6k9S+ZWkzkFRJ+A== X-Google-Smtp-Source: ABdhPJzaDMq9yF/90PfbDtmjMrDDyU6nQWF5HcfMvUY6Hf+4iouCXqUCX+g+a816+uzUAvJbyXGhyA== X-Received: by 2002:a1c:3d54:: with SMTP id k81mr60297wma.144.1605020170860; Tue, 10 Nov 2020 06:56:10 -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 f17sm3261827wmf.41.2020.11.10.06.56.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Nov 2020 06:56:10 -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 v4 5/7] gpio: exar: unduplicate address and offset computation Date: Tue, 10 Nov 2020 15:55:50 +0100 Message-Id: <20201110145552.23024-6-brgl@bgdev.pl> X-Mailer: git-send-email 2.29.1 In-Reply-To: <20201110145552.23024-1-brgl@bgdev.pl> References: <20201110145552.23024-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 --- 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 Tue Nov 10 14:55:51 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 1397678 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=linux-gpio-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=bgdev.pl Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=bgdev-pl.20150623.gappssmtp.com header.i=@bgdev-pl.20150623.gappssmtp.com header.a=rsa-sha256 header.s=20150623 header.b=R382tRCd; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4CVrXs6zPlz9sTR for ; Wed, 11 Nov 2020 01:56:29 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731397AbgKJO4Z (ORCPT ); Tue, 10 Nov 2020 09:56:25 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36684 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731568AbgKJO4P (ORCPT ); Tue, 10 Nov 2020 09:56:15 -0500 Received: from mail-wr1-x442.google.com (mail-wr1-x442.google.com [IPv6:2a00:1450:4864:20::442]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3FED9C0617A6 for ; Tue, 10 Nov 2020 06:56:13 -0800 (PST) Received: by mail-wr1-x442.google.com with SMTP id c17so12959428wrc.11 for ; Tue, 10 Nov 2020 06:56:13 -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=eF5Pv7mEAlXI6C/QGTuoDj1KVDl964SOsKyolgiMmMk=; b=R382tRCdKYLuKQ4UXulN/H8a1Txbho9ExpbMDez21VAC4M5uQFRuZXoX1+krIYaXxk HELbNG4ZeAoGXPUrKQCkRRchnp0i1xyvoSULHQFBcZ5aXUeNd3pD52dFDdbwoJpd4yy+ 9fiizLd9qckSVqS162yfWwYc9GNDDUd/ZwpgNrjNskSy4Ki1TuEoBFK7XvyiU0kyNzCt 3R1qbxEVZAAAQibnTfmB1VDpJVvw8gQEOhl1LeV8sfQfMZmWfGvab+sKEX85Seg1bgjz c4JTM4qUOuh3dfruDRIFwtR72puP6hYcc5LblTdYUdLqfcc+kMV3m4x7IOtt9HxWAz7a B1yA== 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=eF5Pv7mEAlXI6C/QGTuoDj1KVDl964SOsKyolgiMmMk=; b=mCdMLHHVzl7va0h99lSbnzVt9upYw919EuyPzUsYfAUM7VM38n5qTnyWJBgekJf2R8 XMd0axYg0pCorKLGZ9jcvUIyz/4IJDtdPewnaWasBcXAOVe17Q3WDAkLtJ35CjP+Wjle c83DVR0o565zplZRXtfWqkWch4i+xe9BEMkpf56+WgrKLfcwAzWAw8owJcpf2LQEaAlH aJobm61VbtvfM6P1xddw8XUFBpvqbng/eowcueIzM7E4YfnxkkT7/9sU4dAn9sKYuFll /1O//gUgZyMuFZjq9mqCe/EimOG8KY+hIuQ8uTRoVp4QZvqgLz3O5hQtnZdfLEJy8oet 3uGg== X-Gm-Message-State: AOAM531Z3K5Xzd29f6EE0aPgzDbHwhLrecm+bFCc5PRUXDAR4Wwjpa1n XfbTGn9vPrrB0nBWl80dgCXY8Q== X-Google-Smtp-Source: ABdhPJyCX8uazOJ1aPD5pIfj+zL0aWd17z9E8p/d8V0En7L1q/zCkJICSvvuR/sPd1Gwwve9r0/EXA== X-Received: by 2002:adf:e54f:: with SMTP id z15mr23960872wrm.159.1605020171956; Tue, 10 Nov 2020 06:56:11 -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 f17sm3261827wmf.41.2020.11.10.06.56.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Nov 2020 06:56:11 -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 v4 6/7] gpio: exar: switch to using regmap Date: Tue, 10 Nov 2020 15:55:51 +0100 Message-Id: <20201110145552.23024-7-brgl@bgdev.pl> X-Mailer: git-send-email 2.29.1 In-Reply-To: <20201110145552.23024-1-brgl@bgdev.pl> References: <20201110145552.23024-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 --- drivers/gpio/Kconfig | 1 + drivers/gpio/gpio-exar.c | 91 ++++++++++++++++------------------------ 2 files changed, 38 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..2fdca872c7c0 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,42 @@ 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", + .reg_bits = 16, + .val_bits = 8, +}; + static int gpio_exar_probe(struct platform_device *pdev) { struct device *dev = &pdev->dev; @@ -163,13 +146,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 +168,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 +181,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 +189,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 Tue Nov 10 14:55:52 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 1397677 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=linux-gpio-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=bgdev.pl Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=bgdev-pl.20150623.gappssmtp.com header.i=@bgdev-pl.20150623.gappssmtp.com header.a=rsa-sha256 header.s=20150623 header.b=dHlBKlol; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4CVrXs2ZWmz9sSn for ; Wed, 11 Nov 2020 01:56:29 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732326AbgKJO42 (ORCPT ); Tue, 10 Nov 2020 09:56:28 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36686 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731562AbgKJO4P (ORCPT ); Tue, 10 Nov 2020 09:56:15 -0500 Received: from mail-wm1-x343.google.com (mail-wm1-x343.google.com [IPv6:2a00:1450:4864:20::343]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 437DDC0617A7 for ; Tue, 10 Nov 2020 06:56:14 -0800 (PST) Received: by mail-wm1-x343.google.com with SMTP id h2so3293067wmm.0 for ; Tue, 10 Nov 2020 06:56:14 -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=IQh6Jo5zoHL7/3I5hGMlwjltjV3kz9H+4fZOBa3eDu8=; b=dHlBKlolnhqDQUiW04dQgyoqrmqH4sPOBeDpM+s/gEPkY9Fd552NUSYcptJJCPHOk7 ak6DPDgZ5pgdVJQ/LlxjCMqrETWDnz1Y7QPIM/e/6v1f06k3U9v/uRj+QnuruoU8yik6 PE22kni59Wt8ooHuvyLlSYaG2BA1AzVYuV/k9Msd3cXyFcO36UvvKC2iJ93qmhYZqJ8c u/d3Hzxfa9QaHfJENsmfkiN5nWIPx8HU88R5Adok4gUIHTbKghxsZyS2DjR8iotznRqN iXawjQznG4Enn1JEOuPZnXvZiPQeqfJvKZYeFkGdYYOfFiSgCy0b7A9tV7fkCBnfwsgV WUTw== 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=IQh6Jo5zoHL7/3I5hGMlwjltjV3kz9H+4fZOBa3eDu8=; b=EL92ierFbBSfTY0cuIaWfyP+uirk0wmJWAQt6klZpF7slx7idPQELxu5vPZ8cY8P0Y 4P7tGMXKpMnNl6+DUVkPVYrV4PJRCKXd3C5tkzIkhH12HwwU3FyDgOBU2bLoLgjAhZn2 IAZ0/dIBx02jagX4BsyQSYPUOkKYxX9lByElUa/s2dqp2+TZeRVGR1HTN7T+Uv/+iz1F /RG2JCilbPobGLZwLvOK7O2FeNa4yeU0g58JbU8FV75rvS6KaeL45tdLEnK5fqeyUFmh DvnLitvOT7h+UBIRctjMNuCm2pfh+tKSh2kgNrF/V393U6xXC1sLZRtIByQe4Vhxg1vU TuIA== X-Gm-Message-State: AOAM5330PsP5+oMto7UFohcZSb9VUHp+YgttHEvw+DXc1q4SBld0NxAQ +iVP3JQFciszMJnf7Z8etUCJjQ== X-Google-Smtp-Source: ABdhPJzHAt9kZO/l5er2IvaDzk5nsY8wRTuZO4a5c5akLJXdSs7Q4ajjgdyStZuZs6jxse0ZVMn6lg== X-Received: by 2002:a1c:9e12:: with SMTP id h18mr42650wme.11.1605020173067; Tue, 10 Nov 2020 06:56:13 -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 f17sm3261827wmf.41.2020.11.10.06.56.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Nov 2020 06:56:12 -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 v4 7/7] gpio: exar: use devm action for freeing the IDA and drop remove() Date: Tue, 10 Nov 2020 15:55:52 +0100 Message-Id: <20201110145552.23024-8-brgl@bgdev.pl> X-Mailer: git-send-email 2.29.1 In-Reply-To: <20201110145552.23024-1-brgl@bgdev.pl> References: <20201110145552.23024-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 --- 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 2fdca872c7c0..d37de78247a6 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", .reg_bits = 16, @@ -158,6 +165,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; @@ -173,29 +184,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, },