Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp153566pxj; Thu, 3 Jun 2021 03:22:23 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwOqOZ1FN2sXYPIrGnXGpaMMkEeg6hIcMIfYu/EM1NZqpSvctEMR4cGx6Qc12+/FfqHwLHe X-Received: by 2002:a17:906:7f8d:: with SMTP id f13mr21040546ejr.272.1622715743459; Thu, 03 Jun 2021 03:22:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622715743; cv=none; d=google.com; s=arc-20160816; b=dINovctb0iYU4biYyZshoMAJH00IoqLp+5YBA3TNla1iYW4LMtnZaYCfZ2SVQHIdTo AZyQTKmt/dU5EeHkyglaP+8LBsysCDVKJpWy9Fk7iaNw1kTLbAWLFsALMi39VXGdIJG+ FaEwHuvEc+O25D/rV2rTSRBnJcfqW5jB/otXciyPOpv+4dp1oF3mPsLBWLOZOYU01fFr ds+oBkzRDDETF5JjvOpTui0QbegYin7cFhNN3SCsMd0RuNJ9QPlvjXQ+2NTbW+6dVPBP 4W+7P+RTBOcrGvxsXcvMTTGjY//b9G1GEg3LpjvqpL7GTDEJ4+1dN839adD9kusQH2jg NbGA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from; bh=5Kylo8d68q42yBJ0Z9UugUKnVf4N11ZR2omieD/3fY0=; b=El84mNGjVf5hOgfcNN0AAUDPOxIaY3Wq8Ax2nWIHwyJllm/Hnqc5wKbCrf5fcbKz7i wS9hXz4i1rgiW+B1E48NP6gu531YsW2AS0JlZrG6MvA5hFsxIm8IVsfSSCa04r3e8G4Y xVCaOlC/DW/pq52dTUaKK02NiiSO4ClOCPirz4zH2NtzVfoROj5Kcu2tFMB6t2CLBBy9 H5QhdxqupGplEibultgGo54Q9o/2ECYaY2HmYXdjqkA2HltJmRJQuDLZGUth4Iraq294 1mNNZpQjT+rZ7IV1qt99L7xHvKZMv0VP5gDMGXeKU0TcGUad/3Z36W2Cwao6uhRB3kdH LXmQ== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id bt12si1950315ejb.669.2021.06.03.03.21.53; Thu, 03 Jun 2021 03:22:23 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229966AbhFCKUi (ORCPT + 99 others); Thu, 3 Jun 2021 06:20:38 -0400 Received: from twspam01.aspeedtech.com ([211.20.114.71]:60096 "EHLO twspam01.aspeedtech.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229810AbhFCKUh (ORCPT ); Thu, 3 Jun 2021 06:20:37 -0400 Received: from mail.aspeedtech.com ([192.168.0.24]) by twspam01.aspeedtech.com with ESMTP id 153A5CxE045512; Thu, 3 Jun 2021 18:05:12 +0800 (GMT-8) (envelope-from steven_lee@aspeedtech.com) Received: from slee-VirtualBox.localdomain (192.168.100.253) by TWMBX02.aspeed.com (192.168.0.24) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Thu, 3 Jun 2021 18:18:39 +0800 From: Steven Lee To: Linus Walleij , Bartosz Golaszewski , Rob Herring , Joel Stanley , Andrew Jeffery , "open list:GPIO SUBSYSTEM" , "open list:OPEN FIRMWARE AND FLATTENED DEVICE TREE BINDINGS" , "moderated list:ARM/ASPEED MACHINE SUPPORT" , "moderated list:ARM/ASPEED MACHINE SUPPORT" , open list CC: , , , Subject: [PATCH v3 4/5] gpio: gpio-aspeed-sgpio: Add set_config function Date: Thu, 3 Jun 2021 18:18:20 +0800 Message-ID: <20210603101822.9645-5-steven_lee@aspeedtech.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210603101822.9645-1-steven_lee@aspeedtech.com> References: <20210603101822.9645-1-steven_lee@aspeedtech.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [192.168.100.253] X-ClientProxiedBy: TWMBX02.aspeed.com (192.168.0.24) To TWMBX02.aspeed.com (192.168.0.24) X-DNSRBL: X-MAIL: twspam01.aspeedtech.com 153A5CxE045512 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org AST SoC supports *retain pin state* function when wdt reset. The patch adds set_config function for handling sgpio reset tolerance register. Signed-off-by: Steven Lee --- drivers/gpio/gpio-aspeed-sgpio.c | 54 +++++++++++++++++++++++++++++--- 1 file changed, 50 insertions(+), 4 deletions(-) diff --git a/drivers/gpio/gpio-aspeed-sgpio.c b/drivers/gpio/gpio-aspeed-sgpio.c index aa894c92143e..8003308811f7 100644 --- a/drivers/gpio/gpio-aspeed-sgpio.c +++ b/drivers/gpio/gpio-aspeed-sgpio.c @@ -52,9 +52,10 @@ struct aspeed_sgpio { }; struct aspeed_sgpio_bank { - uint16_t val_regs; - uint16_t rdata_reg; - uint16_t irq_regs; + u16 val_regs; + u16 rdata_reg; + u16 irq_regs; + u16 tolerance_regs; const char names[4][3]; }; @@ -70,24 +71,28 @@ static const struct aspeed_sgpio_bank aspeed_sgpio_banks[] = { .val_regs = 0x0000, .rdata_reg = 0x0070, .irq_regs = 0x0004, + .tolerance_regs = 0x0018, .names = { "A", "B", "C", "D" }, }, { .val_regs = 0x001C, .rdata_reg = 0x0074, .irq_regs = 0x0020, + .tolerance_regs = 0x0034, .names = { "E", "F", "G", "H" }, }, { .val_regs = 0x0038, .rdata_reg = 0x0078, .irq_regs = 0x003C, + .tolerance_regs = 0x0050, .names = { "I", "J", "K", "L" }, }, { .val_regs = 0x0090, .rdata_reg = 0x007C, .irq_regs = 0x0094, + .tolerance_regs = 0x00A8, .names = { "M", "N", "O", "P" }, }, }; @@ -100,6 +105,7 @@ enum aspeed_sgpio_reg { reg_irq_type1, reg_irq_type2, reg_irq_status, + reg_tolerance, }; #define GPIO_VAL_VALUE 0x00 @@ -128,6 +134,8 @@ static void __iomem *bank_reg(struct aspeed_sgpio *gpio, return gpio->base + bank->irq_regs + GPIO_IRQ_TYPE2; case reg_irq_status: return gpio->base + bank->irq_regs + GPIO_IRQ_STATUS; + case reg_tolerance: + return gpio->base + bank->tolerance_regs; default: /* acturally if code runs to here, it's an error case */ BUG(); @@ -484,6 +492,44 @@ static int aspeed_sgpio_setup_irqs(struct aspeed_sgpio *gpio, return 0; } +static int aspeed_sgpio_reset_tolerance(struct gpio_chip *chip, + unsigned int offset, bool enable) +{ + struct aspeed_sgpio *gpio = gpiochip_get_data(chip); + unsigned long flags; + void __iomem *reg; + u32 val; + + reg = bank_reg(gpio, to_bank(offset, gpio), reg_tolerance); + + spin_lock_irqsave(&gpio->lock, flags); + + val = readl(reg); + + if (enable) + val |= GPIO_BIT(offset, gpio); + else + val &= ~GPIO_BIT(offset, gpio); + + writel(val, reg); + + spin_unlock_irqrestore(&gpio->lock, flags); + + return 0; +} + +static int aspeed_sgpio_set_config(struct gpio_chip *chip, unsigned int offset, + unsigned long config) +{ + unsigned long param = pinconf_to_config_param(config); + u32 arg = pinconf_to_config_argument(config); + + if (param == PIN_CONFIG_PERSIST_STATE) + return aspeed_sgpio_reset_tolerance(chip, offset, arg); + else + return -EOPNOTSUPP; +} + static const struct aspeed_sgpio_pdata ast2600_sgpiom1_pdata = { .max_ngpios = 128, .pin_mask = GENMASK(10, 6), @@ -591,7 +637,7 @@ static int __init aspeed_sgpio_probe(struct platform_device *pdev) gpio->chip.free = NULL; gpio->chip.get = aspeed_sgpio_get; gpio->chip.set = aspeed_sgpio_set; - gpio->chip.set_config = NULL; + gpio->chip.set_config = aspeed_sgpio_set_config; gpio->chip.label = dev_name(&pdev->dev); gpio->chip.base = -1; -- 2.17.1