mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Mike Looijmans <mike.looijmans@topic.nl>
To: linux-input@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, dmitry.torokhov@gmail.com,
	john@metanate.com, geert+renesas@glider.be,
	Mike Looijmans <mike.looijmans@topic.nl>
Subject: [PATCH v2 1/2] Input: st1232 - Support power supply regulators
Date: Fri,  3 Jun 2022 07:09:35 +0200	[thread overview]
Message-ID: <20220603050935.5984-1-mike.looijmans@topic.nl> (raw)

Add support for the VDD and IOVDD power supply inputs. This allows the
chip to share its supplies with other components (e.g. panel) and manage
them.

Signed-off-by: Mike Looijmans <mike.looijmans@topic.nl>
---
v2: Split devicetree and code parts

 drivers/input/touchscreen/st1232.c | 54 +++++++++++++++++++++++++-----
 1 file changed, 46 insertions(+), 8 deletions(-)

diff --git a/drivers/input/touchscreen/st1232.c b/drivers/input/touchscreen/st1232.c
index e38ba3e4f183..d9c9f6f1f11a 100644
--- a/drivers/input/touchscreen/st1232.c
+++ b/drivers/input/touchscreen/st1232.c
@@ -44,6 +44,11 @@
 #define REG_XY_COORDINATES	0x12
 #define ST_TS_MAX_FINGERS	10
 
+enum st1232_regulators {
+	ST1232_REGULATOR_VDD,
+	ST1232_REGULATOR_IOVDD,
+};
+
 struct st_chip_info {
 	bool	have_z;
 	u16	max_area;
@@ -56,6 +61,7 @@ struct st1232_ts_data {
 	struct touchscreen_properties prop;
 	struct dev_pm_qos_request low_latency_req;
 	struct gpio_desc *reset_gpio;
+	struct regulator_bulk_data regulators[2];
 	const struct st_chip_info *chip_info;
 	int read_buf_len;
 	u8 *read_buf;
@@ -197,17 +203,36 @@ static irqreturn_t st1232_ts_irq_handler(int irq, void *dev_id)
 	return IRQ_HANDLED;
 }
 
-static void st1232_ts_power(struct st1232_ts_data *ts, bool poweron)
+static int st1232_ts_power_on(struct st1232_ts_data *ts)
+{
+	int err;
+
+	err = regulator_bulk_enable(ARRAY_SIZE(ts->regulators), ts->regulators);
+	if (err)
+		return err;
+
+	usleep_range(5000, 6000);
+
+	if (ts->reset_gpio)
+		gpiod_set_value_cansleep(ts->reset_gpio, 0);
+
+	return 0;
+}
+
+static void st1232_ts_power_off(struct st1232_ts_data *ts)
 {
 	if (ts->reset_gpio)
-		gpiod_set_value_cansleep(ts->reset_gpio, !poweron);
+		gpiod_set_value_cansleep(ts->reset_gpio, 1);
+	usleep_range(100, 150);
+	regulator_bulk_disable(ARRAY_SIZE(ts->regulators), ts->regulators);
 }
 
-static void st1232_ts_power_off(void *data)
+static void st1232_ts_power_off_action(void *data)
 {
-	st1232_ts_power(data, false);
+	st1232_ts_power_off(data);
 }
 
+
 static const struct st_chip_info st1232_chip_info = {
 	.have_z		= true,
 	.max_area	= 0xff,
@@ -266,6 +291,14 @@ static int st1232_ts_probe(struct i2c_client *client,
 	ts->client = client;
 	ts->input_dev = input_dev;
 
+	ts->regulators[ST1232_REGULATOR_VDD].supply = "vdd";
+	ts->regulators[ST1232_REGULATOR_IOVDD].supply = "iovdd";
+	error = devm_regulator_bulk_get(&client->dev,
+					ARRAY_SIZE(ts->regulators),
+					ts->regulators);
+	if (error)
+		return error;
+
 	ts->reset_gpio = devm_gpiod_get_optional(&client->dev, NULL,
 						 GPIOD_OUT_HIGH);
 	if (IS_ERR(ts->reset_gpio)) {
@@ -275,9 +308,14 @@ static int st1232_ts_probe(struct i2c_client *client,
 		return error;
 	}
 
-	st1232_ts_power(ts, true);
+	error = st1232_ts_power_on(ts);
+	if (error) {
+		dev_err(&client->dev, "Failed to power on: %d\n", error);
+		return error;
+	}
 
-	error = devm_add_action_or_reset(&client->dev, st1232_ts_power_off, ts);
+	error = devm_add_action_or_reset(&client->dev,
+					 st1232_ts_power_off_action, ts);
 	if (error) {
 		dev_err(&client->dev,
 			"Failed to install power off action: %d\n", error);
@@ -348,7 +386,7 @@ static int __maybe_unused st1232_ts_suspend(struct device *dev)
 	disable_irq(client->irq);
 
 	if (!device_may_wakeup(&client->dev))
-		st1232_ts_power(ts, false);
+		st1232_ts_power_off(ts);
 
 	return 0;
 }
@@ -359,7 +397,7 @@ static int __maybe_unused st1232_ts_resume(struct device *dev)
 	struct st1232_ts_data *ts = i2c_get_clientdata(client);
 
 	if (!device_may_wakeup(&client->dev))
-		st1232_ts_power(ts, true);
+		st1232_ts_power_on(ts);
 
 	enable_irq(client->irq);
 
-- 
2.17.1


                 reply	other threads:[~2022-06-03  5:09 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20220603050935.5984-1-mike.looijmans@topic.nl \
    --to=mike.looijmans@topic.nl \
    --cc=dmitry.torokhov@gmail.com \
    --cc=geert+renesas@glider.be \
    --cc=john@metanate.com \
    --cc=linux-input@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.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

all inboxes | Powered by JetHome®