Received: by 2002:ac0:946b:0:0:0:0:0 with SMTP id j40csp2645431imj; Mon, 11 Feb 2019 06:24:19 -0800 (PST) X-Google-Smtp-Source: AHgI3IaKXXrlPPtdUZI3cYupupFAAAgXTMbKFbWEjigS0MDgI4j0ZLgRDK9UQlosn9remdjER4zs X-Received: by 2002:aa7:8d51:: with SMTP id s17mr23088528pfe.16.1549895059121; Mon, 11 Feb 2019 06:24:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549895059; cv=none; d=google.com; s=arc-20160816; b=NKyTgB4GBe1Q+Jv7ZQ1D/QuewybzaOkYCjaRQHY+Wy1jurGsPnXBi/9fqKfsJ+2gHC HmZVyNT+8elm9rCyJuP1josffagoB7h8texoAWB90D1cnQyWKH4PALmRxXekJpigqdFq QnRoCX8cN/u1cIMZzDrNZqT6S35VGwZm5WZ2/Dym6BHeYbohSuFGqwtQ/EdVefbPdDbQ LtBkJlr6oJPwfeGdB1lsFVwD/mwCmwKsHeKEx0K+sKktviwfH39IU9ChX4y60rqY281/ otStG9INqoPoguVLN0FWyHtg8rJQfY0yazRugBhSR9G1MSfHF1kZEvI+985M3uASTKtR FNXg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=cuLRk/t9fSUdXuBZrZZdYZONSGogdd6Ki1JaOwx09lw=; b=HvNcpE3aQXRXzBKaEvL9kiDACFoPu4I6Cwr8UCD3jn1dSN3r0QG4cqnxd4bY+2h00+ XCKg6J3fcMtroZAjebiQnlVaQXcYjs/QodxafUpyaET0EBnTLCkieC4rpZkEWI1wNpnW cPJ8eyT/+yA6up2ioiG92vZRuaixAxcm3ZGuMbAOQg9AeVSCPuacK9KYWK9MLv4yCXzv 5qC4eiNqjIRqSZZQBV0MC5Dv13JyF6CGxwkS7DBsWsFUPMQ7nvs4lbmh3Pw13x0OTDH1 0o9Y+rMrJ9ujiULtlXi6sfrctzj8H97/tv5N56ycptL3Qc68vNfqAJm98j3dFuN6YHqZ x/RA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f14si8862527pln.221.2019.02.11.06.23.18; Mon, 11 Feb 2019 06:24:19 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727816AbfBKN6W (ORCPT + 99 others); Mon, 11 Feb 2019 08:58:22 -0500 Received: from relay11.mail.gandi.net ([217.70.178.231]:46847 "EHLO relay11.mail.gandi.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726025AbfBKN6W (ORCPT ); Mon, 11 Feb 2019 08:58:22 -0500 Received: from localhost (aaubervilliers-681-1-80-177.w90-88.abo.wanadoo.fr [90.88.22.177]) (Authenticated sender: thomas.petazzoni@bootlin.com) by relay11.mail.gandi.net (Postfix) with ESMTPSA id A3792100018; Mon, 11 Feb 2019 13:58:19 +0000 (UTC) From: Thomas Petazzoni To: Michael Turquette , Stephen Boyd Cc: linux-clk@vger.kernel.org, linux-kernel@vger.kernel.org, Thomas Petazzoni Subject: [PATCH] clk: clk-gpio: add support for sleeping GPIOs in gpio-gate-clk Date: Mon, 11 Feb 2019 14:58:18 +0100 Message-Id: <20190211135818.10518-1-thomas.petazzoni@bootlin.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The current implementation of gpio-gate-clk enables/disables the clock using the GPIO in the ->enable() and ->disable() clock callbacks. This requires the GPIO to be configurable in atomic contexts. While it is the case for most memory-mapped GPIO controllers, it is not the case for GPIO expanders on I2C or SPI. This commit extends the gpio-gate-clk to check whether the GPIO calls require sleeping or not. If sleeping is not required, the current implementation based on ->enable()/->disable() is kept. However, if sleeping is needed, we instead implement the logic in the ->prepare() and ->unprepare() hooks. Thanks to this, a gate clock connected to a GPIO on a GPIO expander can be controlled with the existing driver. Signed-off-by: Thomas Petazzoni --- drivers/clk/clk-gpio.c | 39 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) diff --git a/drivers/clk/clk-gpio.c b/drivers/clk/clk-gpio.c index 6a43ce420492..f5d481713c7d 100644 --- a/drivers/clk/clk-gpio.c +++ b/drivers/clk/clk-gpio.c @@ -61,6 +61,35 @@ const struct clk_ops clk_gpio_gate_ops = { }; EXPORT_SYMBOL_GPL(clk_gpio_gate_ops); +static int clk_sleeping_gpio_gate_prepare(struct clk_hw *hw) +{ + struct clk_gpio *clk = to_clk_gpio(hw); + + gpiod_set_value_cansleep(clk->gpiod, 1); + + return 0; +} + +static void clk_sleeping_gpio_gate_unprepare(struct clk_hw *hw) +{ + struct clk_gpio *clk = to_clk_gpio(hw); + + gpiod_set_value_cansleep(clk->gpiod, 0); +} + +static int clk_sleeping_gpio_gate_is_prepared(struct clk_hw *hw) +{ + struct clk_gpio *clk = to_clk_gpio(hw); + + return gpiod_get_value_cansleep(clk->gpiod); +} + +const struct clk_ops clk_sleeping_gpio_gate_ops = { + .prepare = clk_sleeping_gpio_gate_prepare, + .unprepare = clk_sleeping_gpio_gate_unprepare, + .is_prepared = clk_sleeping_gpio_gate_is_prepared, +}; + /** * DOC: basic clock multiplexer which can be controlled with a gpio output * Traits of this clock: @@ -147,10 +176,16 @@ struct clk_hw *clk_hw_register_gpio_gate(struct device *dev, const char *name, const char *parent_name, struct gpio_desc *gpiod, unsigned long flags) { + const struct clk_ops *ops; + + if (gpiod_cansleep(gpiod)) + ops = &clk_sleeping_gpio_gate_ops; + else + ops = &clk_gpio_gate_ops; + return clk_register_gpio(dev, name, (parent_name ? &parent_name : NULL), - (parent_name ? 1 : 0), gpiod, flags, - &clk_gpio_gate_ops); + (parent_name ? 1 : 0), gpiod, flags, ops); } EXPORT_SYMBOL_GPL(clk_hw_register_gpio_gate); -- 2.20.1