linux-input.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Andrej Valek <andrej.valek@siemens.com>
To: robh@kernel.org, nick@shmanahar.org, hadess@hadess.net,
	dmitry.torokhov@gmail.com
Cc: linux-input@vger.kernel.org, linux-kernel@vger.kernel.org,
	devicetree@vger.kernel.org,
	Andrej Valek <andrej.valek@siemens.com>
Subject: [PATCH v3 4/4] Input: st1232 - add support resolution reading
Date: Tue, 10 Nov 2020 10:07:20 +0100	[thread overview]
Message-ID: <20201110090720.6650-5-andrej.valek@siemens.com> (raw)
In-Reply-To: <20201106100539.6646-2-andrej.valek@siemens.com>

Hard-coding resolution for st1633 device was wrong. Some of LCDs like
YTS700TLBC-02-100C has assembled Sitronix st1633 touchcontroller too. But
the resolution is not 320x480 as was hard-coded.
Add new function which reads correct resolution directly from register.

Signed-off-by: Andrej Valek <andrej.valek@siemens.com>
---
 drivers/input/touchscreen/st1232.c | 52 +++++++++++++++++++++---------
 1 file changed, 36 insertions(+), 16 deletions(-)

diff --git a/drivers/input/touchscreen/st1232.c b/drivers/input/touchscreen/st1232.c
index 63b29c7279e29..1b4b139c85330 100644
--- a/drivers/input/touchscreen/st1232.c
+++ b/drivers/input/touchscreen/st1232.c
@@ -26,15 +26,14 @@
 #define ST1232_TS_NAME	"st1232-ts"
 #define ST1633_TS_NAME	"st1633-ts"
 
+#define REG_XY_RESOLUTION	0x04
+#define REG_XY_COORDINATES	0x12
 #define ST_TS_MAX_FINGERS	10
 
 struct st_chip_info {
 	bool	have_z;
-	u16	max_x;
-	u16	max_y;
 	u16	max_area;
 	u16	max_fingers;
-	u8	start_reg;
 };
 
 struct st1232_ts_data {
@@ -48,15 +47,14 @@ struct st1232_ts_data {
 	u8 *read_buf;
 };
 
-static int st1232_ts_read_data(struct st1232_ts_data *ts)
+static int st1232_ts_read_data(struct st1232_ts_data *ts, u8 reg)
 {
 	struct i2c_client *client = ts->client;
-	u8 start_reg = ts->chip_info->start_reg;
 	struct i2c_msg msg[] = {
 		{
 			.addr	= client->addr,
-			.len	= sizeof(start_reg),
-			.buf	= &start_reg,
+			.len	= sizeof(reg),
+			.buf	= &reg,
 		},
 		{
 			.addr	= client->addr,
@@ -74,6 +72,25 @@ static int st1232_ts_read_data(struct st1232_ts_data *ts)
 	return 0;
 }
 
+static int st1232_ts_read_resolution(struct st1232_ts_data *ts, u16 *max_x,
+				     u16 *max_y)
+{
+	u8 *buf;
+	int error;
+
+	/* select resolution register */
+	error = st1232_ts_read_data(ts, REG_XY_RESOLUTION);
+	if (error)
+		return error;
+
+	buf = ts->read_buf;
+
+	*max_x = ((buf[0] & 0x0070) << 4) | buf[1];
+	*max_y = ((buf[0] & 0x0007) << 8) | buf[2];
+
+	return 0;
+}
+
 static int st1232_ts_parse_and_report(struct st1232_ts_data *ts)
 {
 	struct input_dev *input = ts->input_dev;
@@ -123,7 +140,7 @@ static irqreturn_t st1232_ts_irq_handler(int irq, void *dev_id)
 	int count;
 	int error;
 
-	error = st1232_ts_read_data(ts);
+	error = st1232_ts_read_data(ts, REG_XY_COORDINATES);
 	if (error)
 		goto out;
 
@@ -157,20 +174,14 @@ static void st1232_ts_power_off(void *data)
 
 static const struct st_chip_info st1232_chip_info = {
 	.have_z		= true,
-	.max_x		= 0x31f, /* 800 - 1 */
-	.max_y		= 0x1df, /* 480 -1 */
 	.max_area	= 0xff,
 	.max_fingers	= 2,
-	.start_reg	= 0x12,
 };
 
 static const struct st_chip_info st1633_chip_info = {
 	.have_z		= false,
-	.max_x		= 0x13f, /* 320 - 1 */
-	.max_y		= 0x1df, /* 480 -1 */
 	.max_area	= 0x00,
 	.max_fingers	= 5,
-	.start_reg	= 0x12,
 };
 
 static int st1232_ts_probe(struct i2c_client *client,
@@ -179,6 +190,7 @@ static int st1232_ts_probe(struct i2c_client *client,
 	const struct st_chip_info *match;
 	struct st1232_ts_data *ts;
 	struct input_dev *input_dev;
+	u16 max_x, max_y;
 	int error;
 
 	match = device_get_match_data(&client->dev);
@@ -239,14 +251,22 @@ static int st1232_ts_probe(struct i2c_client *client,
 	input_dev->name = "st1232-touchscreen";
 	input_dev->id.bustype = BUS_I2C;
 
+	/* read resolution from chip */
+	error = st1232_ts_read_resolution(ts, &max_x, &max_y);
+	if (error) {
+		dev_err(&client->dev,
+			"Failed to read resolution: %d\n", error);
+		return error;
+	}
+
 	if (ts->chip_info->have_z)
 		input_set_abs_params(input_dev, ABS_MT_TOUCH_MAJOR, 0,
 				     ts->chip_info->max_area, 0, 0);
 
 	input_set_abs_params(input_dev, ABS_MT_POSITION_X,
-			     0, ts->chip_info->max_x, 0, 0);
+			     0, max_x, 0, 0);
 	input_set_abs_params(input_dev, ABS_MT_POSITION_Y,
-			     0, ts->chip_info->max_y, 0, 0);
+			     0, max_y, 0, 0);
 
 	touchscreen_parse_properties(input_dev, true, &ts->prop);
 
-- 
2.20.1


  reply	other threads:[~2020-11-10  9:08 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-29 17:03 [PATCH 0/3] Firmware loading option Andrej Valek
2020-10-29 17:03 ` [PATCH 1/3] Input: goodix - add option to disable firmware loading Andrej Valek
2020-10-29 20:36   ` Dmitry Torokhov
2020-10-30  8:45     ` Valek, Andrej
2020-10-30  9:56     ` Hans de Goede
2020-10-30 11:02       ` Valek, Andrej
2020-11-23  6:53       ` Dmitry Torokhov
2020-11-23  8:46         ` Hans de Goede
2020-11-10  9:07   ` [PATCH v3 1/4] " Andrej Valek
2020-11-10 18:15   ` [PATCH v4 " Andrej Valek
2020-10-29 17:03 ` [PATCH 2/3] dt-bindings: goodix Andrej Valek
2020-11-04 21:44   ` Rob Herring
2020-11-10  9:07   ` [PATCH v3 2/4] dt-bindings: touchscreen: goodix: add info about disabling FW loading Andrej Valek
2020-11-10 13:43     ` Rob Herring
2020-11-10 18:15   ` [PATCH v4 " Andrej Valek
2020-11-16 17:08     ` Rob Herring
2020-10-29 17:03 ` [PATCH 3/3] Input: atmel_mxt_ts - add option to disable firmware loading Andrej Valek
2020-11-10  9:07   ` [PATCH v3 3/4] " Andrej Valek
2020-11-10 18:15   ` [PATCH v4 " Andrej Valek
2020-11-23  6:56     ` Dmitry Torokhov
2020-11-06 10:05 ` [PATCH v2 0/3] Firmware loading option Andrej Valek
2020-11-06 10:05 ` [PATCH v2 1/3] Input: st1232 - add support resolution reading Andrej Valek
2020-11-10  9:07   ` Andrej Valek [this message]
2020-11-10 18:15   ` [PATCH v4 4/4] " Andrej Valek
2020-11-06 10:05 ` [PATCH v2 2/3] dt-bindings: goodix Andrej Valek
2020-11-09 21:37   ` Rob Herring
2020-11-06 10:05 ` [PATCH v2 3/3] Input: goodix - add option to disable firmware loading Andrej Valek
2020-11-10  9:07 ` [PATCH v3 0/4] Firmware loading option Andrej Valek
2020-11-10 18:15 ` [PATCH v4 " Andrej Valek

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=20201110090720.6650-5-andrej.valek@siemens.com \
    --to=andrej.valek@siemens.com \
    --cc=devicetree@vger.kernel.org \
    --cc=dmitry.torokhov@gmail.com \
    --cc=hadess@hadess.net \
    --cc=linux-input@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=nick@shmanahar.org \
    --cc=robh@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;
as well as URLs for NNTP newsgroup(s).