Received: by 2002:a05:6500:1b8f:b0:1fa:5c73:8e2d with SMTP id df15csp1197608lqb; Thu, 30 May 2024 03:21:29 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVbGWB0DWKFRJoH/9gHLUR0Z2LoKtFqgjZpK/fV4RkqICwaGMPR9jHAhIltKzpotjhkd1alj359gQ0Cl+Cqc3Kup9Yeqq0UaYHDkHsAlw== X-Google-Smtp-Source: AGHT+IESKY+nGSXejg7jO/iyDkZIGhYOjGHYQUlZlnKDGAl5gd2T4dz/kQHAuZzsD/ypj4yFxz12 X-Received: by 2002:a50:cc96:0:b0:578:881e:7b77 with SMTP id 4fb4d7f45d1cf-57a1793b43bmr1455323a12.34.1717064489733; Thu, 30 May 2024 03:21:29 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717064489; cv=pass; d=google.com; s=arc-20160816; b=Hz15I86X85uLwwpNkSQXM7F52Ns81aldCY1WieRS9SBT1SoJqJd/aARJMOPX+HVOyT vKlZGlKt5bDlG+LoMgbbjJhsNtOsQL4+4EszSrUkEg/4EikcLE3UVp12CA7U7i3+96Yd hzoM/6n2b++roGy/slRDbHA5eFZOFM67xEeVN5OYF4f3bD4K6jv91npfknLOJDh/T3Oe MJJ69S9zFloe47pxC54G2fY43Gz5BoGFl86r1hIZp7Ywl4pOFONLMWXLs4i72a8e+j1x n/OuTQpWquDHlrdL9KguIEK/G9YdVtd+Mmz4SFnsVvvGMa4SvMjPlADl08o7E4doPFGz A6oQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature:dkim-signature; bh=pV6xOVNrVp5MkIWD0BIWMbmJBcDgsjfm31+wvnFNx1s=; fh=FDrBqZC62wUIXBG6A5oepzLRCzd70HcTCEYDxU+dZMg=; b=ndtWjdInVNd4PYjOEcpKkZprapiK4SkGKTkisrLaJJ6+FKM5giSW0as1+J7KZQGeOO ULhBVann7tozqUK+n/Nuj08/xnLRq0FN+5FbUjXFuNrWWfYqrI8Ei+Xikb1pTHcKO650 lEn6FWTcoqF17PHHZnFYpS6GA0Gb634qzfFMrSyVvsCWIzZFGWB7VazYLoE7RmzwxjTO L1kmuwM+AcQoPkIrUdQ1QQRFpwBS+qxP5miqZ+MrDCx+Uu4q6KVhTuxnh6qJ7Cb4sv79 ibnAgPmmJ2fF9xQadoWNKAAhOwXRrn8b51SXU3ZdhQ75+/VytpELYnIX0IQIXO3vAoCH v9zQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@tq-group.com header.s=key1 header.b=a2prJpHm; dkim=temperror (no key for signature) header.i=@ew.tq-group.com header.s=dkim header.b=XVLs+pSK; arc=pass (i=1 spf=pass spfdomain=ew.tq-group.com dkim=pass dkdomain=tq-group.com dmarc=pass fromdomain=ew.tq-group.com); spf=pass (google.com: domain of linux-kernel+bounces-195244-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-195244-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=tq-group.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id 4fb4d7f45d1cf-578671cef0bsi6379441a12.247.2024.05.30.03.21.29 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 May 2024 03:21:29 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-195244-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@tq-group.com header.s=key1 header.b=a2prJpHm; dkim=temperror (no key for signature) header.i=@ew.tq-group.com header.s=dkim header.b=XVLs+pSK; arc=pass (i=1 spf=pass spfdomain=ew.tq-group.com dkim=pass dkdomain=tq-group.com dmarc=pass fromdomain=ew.tq-group.com); spf=pass (google.com: domain of linux-kernel+bounces-195244-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-195244-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=tq-group.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 740EC1F23FAE for ; Thu, 30 May 2024 10:21:29 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3C88B17D34A; Thu, 30 May 2024 10:20:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=tq-group.com header.i=@tq-group.com header.b="a2prJpHm"; dkim=fail reason="key not found in DNS" (0-bit key) header.d=ew.tq-group.com header.i=@ew.tq-group.com header.b="XVLs+pSK" Received: from mx1.tq-group.com (mx1.tq-group.com [93.104.207.81]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E624C1761B1; Thu, 30 May 2024 10:20:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=93.104.207.81 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717064451; cv=none; b=R6NiLs31/MTPSY5nYEX6mhR9MpAw03TSLEmYG+rSJAGsouYIJJ+rIfimhqCd4OY5kghGDcDY71WefAasoxgk0B/iaj6c4y+rykYCo86/naNgVcS86kKf6O9z57aM5mSyQZvGgwHMq3UQijgN/LbicSFQ+2ED/PXsq2CNLQkaL1s= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717064451; c=relaxed/simple; bh=u52T1BLdg7V8uIm/Xqta4vGvy70GQpllaYbNXinkqbE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=dLJUslJxJ/i2KIWOLhVznxEsrAb7SucC4GshyBURFyVFiITO70KdlV7cdTlGy5XDNFyLwUznrNLXRbidMMFP462KOrA0xKk5uSmu5Phr2hvELBMnJK8td18UWbqkot19s4Yxe+tQNJfbfUu7yJsLtoBm1/le0HnJlwJOMqlGSdw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=ew.tq-group.com; spf=pass smtp.mailfrom=ew.tq-group.com; dkim=pass (2048-bit key) header.d=tq-group.com header.i=@tq-group.com header.b=a2prJpHm; dkim=fail (0-bit key) header.d=ew.tq-group.com header.i=@ew.tq-group.com header.b=XVLs+pSK reason="key not found in DNS"; arc=none smtp.client-ip=93.104.207.81 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=ew.tq-group.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ew.tq-group.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tq-group.com; i=@tq-group.com; q=dns/txt; s=key1; t=1717064448; x=1748600448; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=pV6xOVNrVp5MkIWD0BIWMbmJBcDgsjfm31+wvnFNx1s=; b=a2prJpHmSCSxW7tvXct0P7ZvFuc5aMsuhi6Gycxj7FnHDSn6vCnnbHcm TKTHpwDqAtNMx3rP0YF8+tZH1wTNIYnoqlJbeLahXhtxgtH9KPz5qqa61 uMWTArcxg+cLxpxlLBzkCGLfXnb2f0LLygu8rAeLsQKtoK1gO73exUe20 z2dK271bowEFM4ZjkvI0ZjqZn+W9CL5fdFano6Rf/S9D1K67SELtRBpLd NA6iOZyf8o69zcuv8yR3exgZWmctoK7Y7fY/k2e00GGULxl5PTj+1N9Fd 0nrf1fxBjs39s3C2uzahODCfRA6C619mmaxfFfZyDBst16paFV2dt77Hq A==; X-CSE-ConnectionGUID: LQjt2KniSKmyQ/81T/5UHw== X-CSE-MsgGUID: /TJHXBzKS+Gwysk0Z7y88w== X-IronPort-AV: E=Sophos;i="6.08,201,1712613600"; d="scan'208";a="37143000" Received: from vmailcow01.tq-net.de ([10.150.86.48]) by mx1.tq-group.com with ESMTP; 30 May 2024 12:20:45 +0200 Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id 65F9016633A; Thu, 30 May 2024 12:20:41 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ew.tq-group.com; s=dkim; t=1717064441; h=from:subject:date:message-id:to:cc:mime-version:content-type: content-transfer-encoding:in-reply-to:references; bh=pV6xOVNrVp5MkIWD0BIWMbmJBcDgsjfm31+wvnFNx1s=; b=XVLs+pSKSFrmcZPnxujT09gAVfm9Att43T91Shp7N5EMZPabzEnF7qW4bvdkBbXkRo4saU tRyydq7/N/CggBmcBpkSyVV8e/ovYRrpS4zKSvbDp8K3bazd/ooRrhkOEwi4WyN7V9T7gG 55A40NNRGV9zmCI8ZdYL2oohVUEgJRorpa+XrkyMFp0Cf2csOui4Zq+wRU/sKv1a5OGICj ij9UWKMsSnNthtwBJf8h2qJDUyzJqtSeBq3/5mQmdkSO1pDx3AN26UeF/Lpx/FU9mAwPtV g+CiZpydCkbDftF2m0MhGnyCSoNG8IP2Dc7NvrHn4SdhSuv2hHnsGV08UEfhtg== From: Matthias Schiffer To: Linus Walleij , Bartosz Golaszewski Cc: Andrew Lunn , linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, Gregor Herburger , linux@ew.tq-group.com, Matthias Schiffer Subject: [PATCH v2 2/4] gpio: tqmx86: introduce shadow register for GPIO output value Date: Thu, 30 May 2024 12:20:00 +0200 Message-ID: X-Mailer: git-send-email 2.45.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Last-TLS-Session-Version: TLSv1.3 The TQMx86 GPIO controller uses the same register address for input and output data. Reading the register will always return current inputs rather than the previously set outputs (regardless of the current direction setting). Therefore, using a RMW pattern does not make sense when setting output values. Instead, the previously set output register value needs to be stored as a shadow register. As there is no reliable way to get the current output values from the hardware, also initialize all channels to 0, to ensure that stored and actual output values match. This should usually not have any effect in practise, as the TQMx86 UEFI sets all outputs to 0 during boot. Also prepare for extension of the driver to more than 8 GPIOs by using DECLARE_BITMAP. Fixes: b868db94a6a7 ("gpio: tqmx86: Add GPIO from for this IO controller") Signed-off-by: Matthias Schiffer Reviewed-by: Andrew Lunn --- v2: added Reviewed-by drivers/gpio/gpio-tqmx86.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/drivers/gpio/gpio-tqmx86.c b/drivers/gpio/gpio-tqmx86.c index 3a28c1f273c39..b7e2dbbdc4ebe 100644 --- a/drivers/gpio/gpio-tqmx86.c +++ b/drivers/gpio/gpio-tqmx86.c @@ -6,6 +6,7 @@ * Vadim V.Vlasov */ +#include #include #include #include @@ -38,6 +39,7 @@ struct tqmx86_gpio_data { void __iomem *io_base; int irq; raw_spinlock_t spinlock; + DECLARE_BITMAP(output, TQMX86_NGPIO); u8 irq_type[TQMX86_NGPI]; }; @@ -64,15 +66,10 @@ static void tqmx86_gpio_set(struct gpio_chip *chip, unsigned int offset, { struct tqmx86_gpio_data *gpio = gpiochip_get_data(chip); unsigned long flags; - u8 val; raw_spin_lock_irqsave(&gpio->spinlock, flags); - val = tqmx86_gpio_read(gpio, TQMX86_GPIOD); - if (value) - val |= BIT(offset); - else - val &= ~BIT(offset); - tqmx86_gpio_write(gpio, val, TQMX86_GPIOD); + __assign_bit(offset, gpio->output, value); + tqmx86_gpio_write(gpio, bitmap_get_value8(gpio->output, 0), TQMX86_GPIOD); raw_spin_unlock_irqrestore(&gpio->spinlock, flags); } @@ -277,6 +274,13 @@ static int tqmx86_gpio_probe(struct platform_device *pdev) tqmx86_gpio_write(gpio, (u8)~TQMX86_DIR_INPUT_MASK, TQMX86_GPIODD); + /* + * Reading the previous output state is not possible with TQMx86 hardware. + * Initialize all outputs to 0 to have a defined state that matches the + * shadow register. + */ + tqmx86_gpio_write(gpio, 0, TQMX86_GPIOD); + chip = &gpio->chip; chip->label = "gpio-tqmx86"; chip->owner = THIS_MODULE; -- TQ-Systems GmbH | Mühlstraße 2, Gut Delling | 82229 Seefeld, Germany Amtsgericht München, HRB 105018 Geschäftsführer: Detlef Schneider, Rüdiger Stahl, Stefan Schneider https://www.tq-group.com/