Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp1609169pxj; Sat, 12 Jun 2021 14:15:34 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzsGHTZpFmiYumW1cvR3zbKIpInyY11hmpt5ju4DnPKHw6UZCfQ/DXmoQFb2lmnKyT+Js6z X-Received: by 2002:a17:906:4a17:: with SMTP id w23mr7017500eju.460.1623532534415; Sat, 12 Jun 2021 14:15:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623532534; cv=none; d=google.com; s=arc-20160816; b=0BsxOg/W7qy3TlqpQHe2NCoJzcziBQoxo995AA7EDLvBdJz7MdU9sq4IV93VyZodVi jftjfxEuA6cxYeEw3wyu1xVefJ4gXw2JPkHkMERh9q7fZbNVwhUmPARWKXa2FIiQ+EPO ztcYgYwKnSp+oFkOIdWqACK8bdKnlu3414Z6E6tfYOvfL/1nGEg++PEO0UswIpylLV5W gSEpfifQZ/lbdRW3M9AcBaAAMm9ER8Kyc87xfeTZVbQ5rHcw4Eg4v7Ej3EdByf3/oY+g x52N85vtuLj1LwsgLCdjIXH6mHpybb8QXHgH0jp0KzrFnUuFXXBrxy5OVWAU8B/6iKiG 1alw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=317W/muonwzc8HyyIWPeaiAscRYe6DIw3INbtrhWtnM=; b=qHLzrgpi7jJ4u7yv07L3yEWLykBNNExjjzpyhg7j257yG6dHC4GSQTcsa+8Z4elrke w6g4VK9hAjNV6X8AG8rYUqQh5RsrVaxazdsRjyyYzlFRkSOqbBvXAztRrOntY4WczRce EaDpFpaAVD4S38151qtAqA8eFEUkGTmQjk3oCM8rzv3QzA4wM/GrS4H0WzJI06hkH4mC cmwf3nZX0j3JLux3j5AD1klMrOEiSIjz+5oFuzNkiOoUcHX/1WRA6p1wxCCI6MjWuJhK qiEA2Lg0KarefMu9mn/Z2DFekHMJce3k/Z/Ceq9fSnS+TO0ZxwGcl2eqgkc3sUfLXf5e FmrQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@svanheule.net header.s=mail1707 header.b=RuCEaKti; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=svanheule.net Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id f15si7653370ejk.164.2021.06.12.14.15.11; Sat, 12 Jun 2021 14:15:34 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@svanheule.net header.s=mail1707 header.b=RuCEaKti; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=svanheule.net Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231613AbhFLVPl (ORCPT + 99 others); Sat, 12 Jun 2021 17:15:41 -0400 Received: from polaris.svanheule.net ([84.16.241.116]:48018 "EHLO polaris.svanheule.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231535AbhFLVPi (ORCPT ); Sat, 12 Jun 2021 17:15:38 -0400 Received: from terra.local.svanheule.net (unknown [IPv6:2a02:a03f:eafb:ee01:a4dd:c59:8cbd:ee0d]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: sander@svanheule.net) by polaris.svanheule.net (Postfix) with ESMTPSA id 4A2EE20C9CE; Sat, 12 Jun 2021 23:13:35 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=svanheule.net; s=mail1707; t=1623532415; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=317W/muonwzc8HyyIWPeaiAscRYe6DIw3INbtrhWtnM=; b=RuCEaKtiUTzxYp/z23JXa71RRL9w5iN+5OQaQKxpJAXMoOgumORYPsBRakUWfcZiWSaAlY s7kxGe0yVVIvzgB13qclbFAPPeMnMucXX5H9bPVrxUNLF2oe28nt3lS6Wsm5FM4REYhNye eMHDRzgOKW54n6/YmKyKNhtWnX4v7pY81GtZBzFeChxxpZyfLMA1gnI5TBrmPeUrRj5n1u fWmpLfPornw8GBY91LkkziaFgwLQRadl18URvbew+T5ojUMK4Y5Fe/Phw+KIhSPazgE81n pKVJ55PKXBM3W9oRoH86Mj4+luMW3Fp09S5HrW4itOwTQweVsWq48xWuG1THwQ== From: Sander Vanheule To: Pavel Machek , Rob Herring , Lee Jones , Mark Brown , Greg Kroah-Hartman , "Rafael J . Wysocki" , Michael Walle , Linus Walleij , Bartosz Golaszewski , linux-leds@vger.kernel.org, devicetree@vger.kernel.org, linux-gpio@vger.kernel.org Cc: Andrew Lunn , Andy Shevchenko , linux-kernel@vger.kernel.org, Sander Vanheule Subject: [PATCH v5 2/8] gpio: regmap: Add quirk for aliased data registers Date: Sat, 12 Jun 2021 23:12:32 +0200 Message-Id: <5d8e5e8a29ecf39da48beb94c42003a5c686ec4e.1623532208.git.sander@svanheule.net> X-Mailer: git-send-email 2.31.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Some chips have the read-only input and write-only output data registers aliased to the same offset. As a result it is not possible to perform read-modify-writes on the output values, when a line is still configured as input. Add a quirk for aliased data registers, and document how the regmap should be set up for correct operation. Signed-off-by: Sander Vanheule --- drivers/gpio/gpio-regmap.c | 7 ++++++- include/linux/gpio/regmap.h | 13 +++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/drivers/gpio/gpio-regmap.c b/drivers/gpio/gpio-regmap.c index 134cedf151a7..3a3d0d9a945c 100644 --- a/drivers/gpio/gpio-regmap.c +++ b/drivers/gpio/gpio-regmap.c @@ -15,6 +15,7 @@ struct gpio_regmap { struct device *parent; struct regmap *regmap; struct gpio_chip gpio_chip; + unsigned int quirks; int reg_stride; int ngpio_per_reg; @@ -68,7 +69,10 @@ static int gpio_regmap_get(struct gpio_chip *chip, unsigned int offset) if (ret) return ret; - ret = regmap_read(gpio->regmap, reg, &val); + if (gpio->quirks & GPIO_REGMAP_QUIRK_ALIASED_DATA) + ret = regmap_read_bypassed(gpio->regmap, reg, &val); + else + ret = regmap_read(gpio->regmap, reg, &val); if (ret) return ret; @@ -227,6 +231,7 @@ struct gpio_regmap *gpio_regmap_register(const struct gpio_regmap_config *config gpio->parent = config->parent; gpio->regmap = config->regmap; + gpio->quirks = config->quirks; gpio->ngpio_per_reg = config->ngpio_per_reg; gpio->reg_stride = config->reg_stride; gpio->reg_mask_xlate = config->reg_mask_xlate; diff --git a/include/linux/gpio/regmap.h b/include/linux/gpio/regmap.h index 334dd928042b..b0751a10fa4a 100644 --- a/include/linux/gpio/regmap.h +++ b/include/linux/gpio/regmap.h @@ -12,6 +12,17 @@ struct regmap; #define GPIO_REGMAP_ADDR_ZERO ((unsigned int)(-1)) #define GPIO_REGMAP_ADDR(addr) ((addr) ? : GPIO_REGMAP_ADDR_ZERO) +enum gpio_regmap_quirk { + /* + * For hardware where the (read-only) input and (write-only) output + * registers are aliased to the same offset. In this case the register + * must not be marked as volatile and a regcache must be used, to cache + * the write-only output values. Register reads for the input values + * will be performed by bypassing the cache. + */ + GPIO_REGMAP_QUIRK_ALIASED_DATA = BIT(0), +}; + /** * struct gpio_regmap_config - Description of a generic regmap gpio_chip. * @parent: The parent device @@ -31,6 +42,7 @@ struct regmap; * @reg_stride: (Optional) May be set if the registers (of the * same type, dat, set, etc) are not consecutive. * @ngpio_per_reg: Number of GPIOs per register + * @quirks: Flags indicating GPIO chip hardware issues * @irq_domain: (Optional) IRQ domain if the controller is * interrupt-capable * @reg_mask_xlate: (Optional) Translates base address and GPIO @@ -73,6 +85,7 @@ struct gpio_regmap_config { unsigned int reg_dir_out_base; int reg_stride; int ngpio_per_reg; + unsigned int quirks; struct irq_domain *irq_domain; int (*reg_mask_xlate)(struct gpio_regmap *gpio, unsigned int base, -- 2.31.1