Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp2330289pxj; Sun, 9 May 2021 23:39:03 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzSsGP2xA0gAdGUOSS8GXaBWZJIS6etC8yscqde4AaITKN2o75xVNO2Uk7LxPXmTSRkUIGi X-Received: by 2002:a05:6602:1222:: with SMTP id z2mr10242538iot.120.1620628742834; Sun, 09 May 2021 23:39:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620628742; cv=none; d=google.com; s=arc-20160816; b=S3V4OqLpcLaTTSoooPFqTAY3W10Vn2lKeNW0vfI53eU6DQmZy73N9baeNwKsWg8qch QskOJM9OW/yIJYXfXTpf/cy07ZxPcJjBmBuewG9xeMAEGCK9SdlEXSLomBUHNrmceR4N zndVgMExyZ5yD8OT0fwwLtFB3vJQ5zX2D+XObySmfR40NCrBrPwOFrA9+SJdWrmpuTIz 1GW6hG4Ro03JqgLzk9Oi6otGYDd1CaBJnInYLleNOh9IH4gq6/mV+OwTK3GDKT9rZDds X1ZaxUYpzp+CF6fceveVxLxtOJKIVrzYOB1k7uPOiqLK9XDDTMM15hZGFWpwLy2AGoLp 7NkQ== 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; bh=BVpNTklLM8whlYOxo2CNkxbJ0YVjk/I/l2KNdYryym4=; b=oJJiEZmrPjJdcSKtz2NcyRf26S8rDLbqimAyrMWclf9P8+dr6kpFREny/EOOt8naaG RSF7cymmuAqFF8WPxGz3Kx1Y3ecftdk2piVVPJwqxKNpQTTFbdFYNYcnW4OncUn76MtP eQL+kHUlkthRnEnd6I3vi+tOHz5/LywgdNxhIcqVdavu6DUqLP2xPGt8PtRhcNiVOFKd 64yZx8rMvib/vj4xOrG6YFPiIpqMk3LIgFYzuOOAlIUDqPlOztQtDC+Oo4io1eg/C63T WdiVO0mvTgq21djochRfz5Geo1ui38U8LiSDIlI3nI8Z5qendxgCJZhVTcM0SWn9Ht3/ ezww== 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 u12si18786080jad.101.2021.05.09.23.38.50; Sun, 09 May 2021 23:39:02 -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 S230180AbhEJGib (ORCPT + 99 others); Mon, 10 May 2021 02:38:31 -0400 Received: from lucky1.263xmail.com ([211.157.147.135]:47622 "EHLO lucky1.263xmail.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230002AbhEJGib (ORCPT ); Mon, 10 May 2021 02:38:31 -0400 Received: from localhost (unknown [192.168.167.235]) by lucky1.263xmail.com (Postfix) with ESMTP id 42371ACE55; Mon, 10 May 2021 14:37:25 +0800 (CST) X-MAIL-GRAY: 0 X-MAIL-DELIVERY: 1 X-ADDR-CHECKED4: 1 X-ANTISPAM-LEVEL: 2 X-ABS-CHECKED: 0 Received: from localhost.localdomain (unknown [58.22.7.114]) by smtp.263.net (postfix) whith ESMTP id P2750T140649296815872S1620628644490835_; Mon, 10 May 2021 14:37:25 +0800 (CST) X-IP-DOMAINF: 1 X-UNIQUE-TAG: <8b00ada8a2bf46d5f68735743bd0f948> X-RL-SENDER: jay.xu@rock-chips.com X-SENDER: xjq@rock-chips.com X-LOGIN-NAME: jay.xu@rock-chips.com X-FST-TO: heiko@sntech.de X-RCPT-COUNT: 7 X-SENDER-IP: 58.22.7.114 X-ATTACHMENT-NUM: 0 X-System-Flag: 0 From: Jianqun Xu To: heiko@sntech.de, linus.walleij@linaro.org, robh+dt@kernel.org Cc: linux-gpio@vger.kernel.org, linux-rockchip@lists.infradead.org, linux-kernel@vger.kernel.org, Jianqun Xu Subject: [PATCH 6/7] gpio/rockchip: always enable clock for gpio controller Date: Mon, 10 May 2021 14:37:22 +0800 Message-Id: <20210510063722.506009-1-jay.xu@rock-chips.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210510063602.505829-1-jay.xu@rock-chips.com> References: <20210510063602.505829-1-jay.xu@rock-chips.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Since gate and ungate pclk of gpio has very litte benifit for system power consumption, just keep it always ungate. Signed-off-by: Jianqun Xu --- drivers/gpio/gpio-rockchip.c | 68 +++++------------------------------- 1 file changed, 9 insertions(+), 59 deletions(-) diff --git a/drivers/gpio/gpio-rockchip.c b/drivers/gpio/gpio-rockchip.c index 92aaf1848449..048e7eecddba 100644 --- a/drivers/gpio/gpio-rockchip.c +++ b/drivers/gpio/gpio-rockchip.c @@ -139,17 +139,8 @@ static int rockchip_gpio_get_direction(struct gpio_chip *chip, { struct rockchip_pin_bank *bank = gpiochip_get_data(chip); u32 data; - int ret; - ret = clk_enable(bank->clk); - if (ret < 0) { - dev_err(bank->drvdata->dev, - "failed to enable clock for bank %s\n", bank->name); - return ret; - } data = rockchip_gpio_readl_bit(bank, offset, bank->gpio_regs->port_ddr); - clk_disable(bank->clk); - if (data & BIT(offset)) return GPIO_LINE_DIRECTION_OUT; @@ -163,11 +154,9 @@ static int rockchip_gpio_set_direction(struct gpio_chip *chip, unsigned long flags; u32 data = input ? 0 : 1; - clk_enable(bank->clk); raw_spin_lock_irqsave(&bank->slock, flags); rockchip_gpio_writel_bit(bank, offset, data, bank->gpio_regs->port_ddr); raw_spin_unlock_irqrestore(&bank->slock, flags); - clk_disable(bank->clk); return 0; } @@ -178,11 +167,9 @@ static void rockchip_gpio_set(struct gpio_chip *gc, unsigned int offset, struct rockchip_pin_bank *bank = gpiochip_get_data(gc); unsigned long flags; - clk_enable(bank->clk); raw_spin_lock_irqsave(&bank->slock, flags); rockchip_gpio_writel_bit(bank, offset, value, bank->gpio_regs->port_dr); raw_spin_unlock_irqrestore(&bank->slock, flags); - clk_disable(bank->clk); } static int rockchip_gpio_get(struct gpio_chip *gc, unsigned int offset) @@ -190,11 +177,10 @@ static int rockchip_gpio_get(struct gpio_chip *gc, unsigned int offset) struct rockchip_pin_bank *bank = gpiochip_get_data(gc); u32 data; - clk_enable(bank->clk); data = readl(bank->reg_base + bank->gpio_regs->ext_port); - clk_disable(bank->clk); data >>= offset; data &= 1; + return data; } @@ -315,9 +301,7 @@ static int rockchip_gpio_to_irq(struct gpio_chip *gc, unsigned int offset) if (!bank->domain) return -ENXIO; - clk_enable(bank->clk); virq = irq_create_mapping(bank->domain, offset); - clk_disable(bank->clk); return (virq) ? : -ENXIO; } @@ -409,7 +393,6 @@ static int rockchip_irq_set_type(struct irq_data *d, unsigned int type) unsigned long flags; int ret = 0; - clk_enable(bank->clk); raw_spin_lock_irqsave(&bank->slock, flags); rockchip_gpio_writel_bit(bank, d->hwirq, 0, @@ -480,7 +463,6 @@ static int rockchip_irq_set_type(struct irq_data *d, unsigned int type) out: irq_gc_unlock(gc); raw_spin_unlock_irqrestore(&bank->slock, flags); - clk_disable(bank->clk); return ret; } @@ -490,10 +472,8 @@ static void rockchip_irq_suspend(struct irq_data *d) struct irq_chip_generic *gc = irq_data_get_irq_chip_data(d); struct rockchip_pin_bank *bank = gc->private; - clk_enable(bank->clk); bank->saved_masks = irq_reg_readl(gc, bank->gpio_regs->int_mask); irq_reg_writel(gc, ~gc->wake_active, bank->gpio_regs->int_mask); - clk_disable(bank->clk); } static void rockchip_irq_resume(struct irq_data *d) @@ -501,27 +481,7 @@ static void rockchip_irq_resume(struct irq_data *d) struct irq_chip_generic *gc = irq_data_get_irq_chip_data(d); struct rockchip_pin_bank *bank = gc->private; - clk_enable(bank->clk); irq_reg_writel(gc, bank->saved_masks, bank->gpio_regs->int_mask); - clk_disable(bank->clk); -} - -static void rockchip_irq_enable(struct irq_data *d) -{ - struct irq_chip_generic *gc = irq_data_get_irq_chip_data(d); - struct rockchip_pin_bank *bank = gc->private; - - clk_enable(bank->clk); - irq_gc_mask_clr_bit(d); -} - -static void rockchip_irq_disable(struct irq_data *d) -{ - struct irq_chip_generic *gc = irq_data_get_irq_chip_data(d); - struct rockchip_pin_bank *bank = gc->private; - - irq_gc_mask_set_bit(d); - clk_disable(bank->clk); } static int rockchip_interrupts_register(struct rockchip_pin_bank *bank) @@ -530,19 +490,11 @@ static int rockchip_interrupts_register(struct rockchip_pin_bank *bank) struct irq_chip_generic *gc; int ret; - ret = clk_enable(bank->clk); - if (ret) { - dev_err(bank->dev, "failed to enable clock for bank %s\n", - bank->name); - return -EINVAL; - } - bank->domain = irq_domain_add_linear(bank->of_node, 32, &irq_generic_chip_ops, NULL); if (!bank->domain) { dev_warn(bank->dev, "could not init irq domain for bank %s\n", bank->name); - clk_disable(bank->clk); return -EINVAL; } @@ -554,7 +506,6 @@ static int rockchip_interrupts_register(struct rockchip_pin_bank *bank) dev_err(bank->dev, "could not alloc generic chips for bank %s\n", bank->name); irq_domain_remove(bank->domain); - clk_disable(bank->clk); return -EINVAL; } @@ -571,8 +522,8 @@ static int rockchip_interrupts_register(struct rockchip_pin_bank *bank) gc->chip_types[0].chip.irq_ack = irq_gc_ack_set_bit; gc->chip_types[0].chip.irq_mask = irq_gc_mask_set_bit; gc->chip_types[0].chip.irq_unmask = irq_gc_mask_clr_bit; - gc->chip_types[0].chip.irq_enable = rockchip_irq_enable; - gc->chip_types[0].chip.irq_disable = rockchip_irq_disable; + gc->chip_types[0].chip.irq_enable = irq_gc_mask_clr_bit; + gc->chip_types[0].chip.irq_disable = irq_gc_mask_set_bit; gc->chip_types[0].chip.irq_set_wake = irq_gc_set_wake; gc->chip_types[0].chip.irq_suspend = rockchip_irq_suspend; gc->chip_types[0].chip.irq_resume = rockchip_irq_resume; @@ -591,7 +542,6 @@ static int rockchip_interrupts_register(struct rockchip_pin_bank *bank) irq_set_chained_handler_and_data(bank->irq, rockchip_irq_demux, bank); - clk_disable(bank->clk); return 0; } @@ -695,7 +645,6 @@ static int rockchip_get_bank_data(struct rockchip_pin_bank *bank) if (IS_ERR(bank->db_clk)) { dev_err(bank->dev, "cannot find debounce clk\n"); bank->db_clk = NULL; - clk_disable(bank->clk); return -EINVAL; } } else { @@ -703,7 +652,6 @@ static int rockchip_get_bank_data(struct rockchip_pin_bank *bank) bank->gpio_type = GPIO_TYPE_V1; } - clk_disable(bank->clk); return 0; } @@ -756,15 +704,17 @@ static int rockchip_gpio_probe(struct platform_device *pdev) return ret; ret = rockchip_gpiolib_register(bank); - if (ret) { - clk_disable_unprepare(bank->clk); - return ret; - } + if (ret) + goto err_clk; platform_set_drvdata(pdev, bank); dev_info(dev, "probed %pOF\n", np); return 0; +err_clk: + clk_disable_unprepare(bank->clk); + + return ret; } static int rockchip_gpio_remove(struct platform_device *pdev) -- 2.25.1