public inbox for linux-arm-kernel@lists.infradead.org
 help / color / mirror / Atom feed
From: "Jernej Škrabec" <jernej.skrabec@gmail.com>
To: Dmitry Torokhov <dmitry.torokhov@gmail.com>,
	Hans de Goede <hdegoede@redhat.com>,
	Samuel Holland <samuel@sholland.org>
Cc: Samuel Holland <samuel@sholland.org>,
	Maxime Ripard <maxime@cerno.tech>, Rob Herring <robh@kernel.org>,
	Chen-Yu Tsai <wens@csie.org>,
	Krzysztof Kozlowski <krzk+dt@kernel.org>,
	Maxime Ripard <mripard@kernel.org>,
	Rob Herring <robh+dt@kernel.org>,
	devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org,
	linux-input@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-sunxi@lists.linux.dev,
	Philipp Zabel <p.zabel@pengutronix.de>
Subject: Re: [PATCH v2 2/3] Input: sun4i-lradc-keys: Add optional clock/reset support
Date: Fri, 15 Apr 2022 20:21:55 +0200	[thread overview]
Message-ID: <2821426.e9J7NaK4W3@jernej-laptop> (raw)
In-Reply-To: <20220414002349.24332-2-samuel@sholland.org>

Dne četrtek, 14. april 2022 ob 02:23:47 CEST je Samuel Holland napisal(a):
> Until the R329, the LRADC hardware was always active. Now it requires
> enabling a clock gate and deasserting a reset line. Add support for this
> variant of the hardware.
> 
> Signed-off-by: Samuel Holland <samuel@sholland.org>

Acked-by: Jernej Skrabec <jernej.skrabec@gmail.com>

Best regards,
Jernej

> ---
> 
> Changes in v2:
>  - Guard the code with a flag instead of using "_optional" variants.
> 
>  drivers/input/keyboard/sun4i-lradc-keys.c | 33 +++++++++++++++++++++++
>  1 file changed, 33 insertions(+)
> 
> diff --git a/drivers/input/keyboard/sun4i-lradc-keys.c
> b/drivers/input/keyboard/sun4i-lradc-keys.c index
> 4a796bed48ac..5630334a6c09 100644
> --- a/drivers/input/keyboard/sun4i-lradc-keys.c
> +++ b/drivers/input/keyboard/sun4i-lradc-keys.c
> @@ -14,6 +14,7 @@
>   * there are no boards known to use channel 1.
>   */
> 
> +#include <linux/clk.h>
>  #include <linux/err.h>
>  #include <linux/init.h>
>  #include <linux/input.h>
> @@ -23,6 +24,7 @@
>  #include <linux/of_platform.h>
>  #include <linux/platform_device.h>
>  #include <linux/regulator/consumer.h>
> +#include <linux/reset.h>
>  #include <linux/slab.h>
> 
>  #define LRADC_CTRL		0x00
> @@ -58,10 +60,12 @@
>  /* struct lradc_variant - Describe sun4i-a10-lradc-keys hardware variant
>   * @divisor_numerator:		The numerator of lradc Vref internally 
divisor
>   * @divisor_denominator:	The denominator of lradc Vref internally 
divisor
> + * @has_clock_reset:		If the binding requires a clock and reset
>   */
>  struct lradc_variant {
>  	u8 divisor_numerator;
>  	u8 divisor_denominator;
> +	bool has_clock_reset;
>  };
> 
>  static const struct lradc_variant lradc_variant_a10 = {
> @@ -83,6 +87,8 @@ struct sun4i_lradc_data {
>  	struct device *dev;
>  	struct input_dev *input;
>  	void __iomem *base;
> +	struct clk *clk;
> +	struct reset_control *reset;
>  	struct regulator *vref_supply;
>  	struct sun4i_lradc_keymap *chan0_map;
>  	const struct lradc_variant *variant;
> @@ -140,6 +146,14 @@ static int sun4i_lradc_open(struct input_dev *dev)
>  	if (error)
>  		return error;
> 
> +	error = reset_control_deassert(lradc->reset);
> +	if (error)
> +		goto err_disable_reg;
> +
> +	error = clk_prepare_enable(lradc->clk);
> +	if (error)
> +		goto err_assert_reset;
> +
>  	lradc->vref = regulator_get_voltage(lradc->vref_supply) *
>  		      lradc->variant->divisor_numerator /
>  		      lradc->variant->divisor_denominator;
> @@ -153,6 +167,13 @@ static int sun4i_lradc_open(struct input_dev *dev)
>  	writel(CHAN0_KEYUP_IRQ | CHAN0_KEYDOWN_IRQ, lradc->base + 
LRADC_INTC);
> 
>  	return 0;
> +
> +err_assert_reset:
> +	reset_control_assert(lradc->reset);
> +err_disable_reg:
> +	regulator_disable(lradc->vref_supply);
> +
> +	return error;
>  }
> 
>  static void sun4i_lradc_close(struct input_dev *dev)
> @@ -164,6 +185,8 @@ static void sun4i_lradc_close(struct input_dev *dev)
>  		SAMPLE_RATE(2), lradc->base + LRADC_CTRL);
>  	writel(0, lradc->base + LRADC_INTC);
> 
> +	clk_disable_unprepare(lradc->clk);
> +	reset_control_assert(lradc->reset);
>  	regulator_disable(lradc->vref_supply);
>  }
> 
> @@ -243,6 +266,16 @@ static int sun4i_lradc_probe(struct platform_device
> *pdev) return -EINVAL;
>  	}
> 
> +	if (lradc->variant->has_clock_reset) {
> +		lradc->clk = devm_clk_get(dev, NULL);
> +		if (IS_ERR(lradc->clk))
> +			return PTR_ERR(lradc->clk);
> +
> +		lradc->reset = devm_reset_control_get_exclusive(dev, 
NULL);
> +		if (IS_ERR(lradc->reset))
> +			return PTR_ERR(lradc->reset);
> +	}
> +
>  	lradc->vref_supply = devm_regulator_get(dev, "vref");
>  	if (IS_ERR(lradc->vref_supply))
>  		return PTR_ERR(lradc->vref_supply);





_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

  reply	other threads:[~2022-04-15 18:23 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-14  0:23 [PATCH v2 1/3] dt-bindings: input: sun4i-lradc-keys: Add R329 and D1 compatibles Samuel Holland
2022-04-14  0:23 ` [PATCH v2 2/3] Input: sun4i-lradc-keys: Add optional clock/reset support Samuel Holland
2022-04-15 18:21   ` Jernej Škrabec [this message]
2022-04-25  3:42   ` Dmitry Torokhov
2022-04-14  0:23 ` [PATCH v2 3/3] Input: sun4i-lradc-keys: Add support for R329 and D1 Samuel Holland
2022-04-15 18:21   ` Jernej Škrabec
2022-04-25  3:42   ` Dmitry Torokhov
2022-04-25  3:39 ` [PATCH v2 1/3] dt-bindings: input: sun4i-lradc-keys: Add R329 and D1 compatibles Dmitry Torokhov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=2821426.e9J7NaK4W3@jernej-laptop \
    --to=jernej.skrabec@gmail.com \
    --cc=devicetree@vger.kernel.org \
    --cc=dmitry.torokhov@gmail.com \
    --cc=hdegoede@redhat.com \
    --cc=krzk+dt@kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-input@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-sunxi@lists.linux.dev \
    --cc=maxime@cerno.tech \
    --cc=mripard@kernel.org \
    --cc=p.zabel@pengutronix.de \
    --cc=robh+dt@kernel.org \
    --cc=robh@kernel.org \
    --cc=samuel@sholland.org \
    --cc=wens@csie.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox