Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3227747imu; Mon, 28 Jan 2019 00:45:56 -0800 (PST) X-Google-Smtp-Source: ALg8bN5eBOn9lyIA1wrR8KQbpTihnbgaxcHecNFs3fFeImn/A1pgX577OXzI71iiGqjD8o7YR6zQ X-Received: by 2002:a17:902:82c2:: with SMTP id u2mr20911717plz.110.1548665156767; Mon, 28 Jan 2019 00:45:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548665156; cv=none; d=google.com; s=arc-20160816; b=bsRfTOInnWEC/3Z4yDutydl1OcJemI6aoPVZC3Wargek3LzAls90391JRryR02Z5Rt jDXjVy1ANvtwYlAW43/jmukEs4tMAKBtxC0eAtI9A4HZXLIs+vzBlAtBnTbewlpZDYET i8ioS7B/YB6EqiUsACj/3NjN+dI0jDuHpvYG7t1rkz4mcOOLbV+HijGvX9W11I6D1gGn C/CWyrCloL37wZ9DhDgoAGhg4g9SEWemHu2aFdkEqr+9rV3Z4u6wB0vuTRIgA/QRJN4g OhW7gPxuhXQIdbcHS4XMOe0wVzA6CeXumYncj7Hh3hvwNOc0nuYiwkRIOb0Uu7PUVGAI Hr/g== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=BnHCFTwpaQiLl/dpvZ10woTkAPogRr8qMd1CayaQm9w=; b=UuYoBkAwIBh8GF8LY2cG/bk/q2kqZhbKIwDgfeG6CDbk91/nlA51xehD3PWXA3cvXl Yi0IYj9Vrf3udQD0GBFEJmipa4SRqrk7Yt0RLXgdcS/slOJ9grVLeEQdJ5yXRk3UwIT/ CVddQsSIlIYBoHaJl0Yk4wQNRNb3AaDQV3tDzYG84sDnuB/5xZ2EggGl0RZs+wa0AO+o Y5VA3HR4Lb1vFa7vYrOHlOYD7f4cxaL/89OA0j4dFPFtLCkL5vTXUoOfr9CdLzu7P+Z6 Sny6S33W2ETOiIAqZ1gLNZeGNTuKl0hKEudD3fmQ3MD8XvM13Ms/QwOgpUEwE187fcAG 2FjQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@posteo.de header.s=2017 header.b=NNsZ0HSh; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=posteo.de Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r4si31425635pgi.387.2019.01.28.00.45.40; Mon, 28 Jan 2019 00:45:56 -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; dkim=pass header.i=@posteo.de header.s=2017 header.b=NNsZ0HSh; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=posteo.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726960AbfA1IpM (ORCPT + 99 others); Mon, 28 Jan 2019 03:45:12 -0500 Received: from mout01.posteo.de ([185.67.36.65]:38689 "EHLO mout01.posteo.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726763AbfA1IpD (ORCPT ); Mon, 28 Jan 2019 03:45:03 -0500 Received: from submission (posteo.de [89.146.220.130]) by mout01.posteo.de (Postfix) with ESMTPS id 9497F160068 for ; Mon, 28 Jan 2019 09:44:59 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.de; s=2017; t=1548665099; bh=YTDvFHiOHa9rBcgiiUydCcbY/GNbvcWh6RDXxk/umvA=; h=From:To:Cc:Subject:Date:From; b=NNsZ0HShazy/W+i+yLdv2kOIbKmYtJjIAFbHoab3U6xWp+z5gx9cudUqQZOwUkwE1 8c25euGEwzOClY780qF8o87xTVStnZQVHu1TsQREmlHFzQRZ87qj65bsxLi7IKn4io g4Bzv3Kllq1qHCSxug3HNLMhVA9KQlMj4rHhoeawe69c2RSoICi50d6y0nMKgOrMpG LrNW0V29s1ysBXiYzboHXbNXcH3KtHHKwS6tKCzlBmjPpnhc1HSutAl+9WMj2nM4ic sIXAf2f3T02zgbgmF5T6zU9wsqcz/OWUG1CbOgC2vP6ah5qaEocrIw17DNq4JGFKKg f6I6Zh9Lj4zig== Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 43p39656S4z6tmM; Mon, 28 Jan 2019 09:44:58 +0100 (CET) From: Martin Kepplinger To: devicetree@vger.kernel.org, linux-input@vger.kernel.org Cc: dmitry.torokhov@gmail.com, robh+dt@kernel.org, mark.rutland@arm.com, linux-kernel@vger.kernel.org, Martin Kepplinger Subject: [PATCH 2/3] Input: st1232 - add support for st1633 Date: Mon, 28 Jan 2019 09:44:48 +0100 Message-Id: <20190128084449.16070-2-martink@posteo.de> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190128084449.16070-1-martink@posteo.de> References: <20190128084449.16070-1-martink@posteo.de> 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 From: Martin Kepplinger Add support for the Sitronix ST1633 touchscreen controller to the st1232 driver. A protocol spec can be found here: www.ampdisplay.com/documents/pdf/AM-320480B6TZQW-TC0H.pdf Signed-off-by: Martin Kepplinger --- drivers/input/touchscreen/Kconfig | 6 +- drivers/input/touchscreen/st1232.c | 122 +++++++++++++++++++++-------- 2 files changed, 94 insertions(+), 34 deletions(-) diff --git a/drivers/input/touchscreen/Kconfig b/drivers/input/touchscreen/Kconfig index 068dbbc610fc..7c597a49c265 100644 --- a/drivers/input/touchscreen/Kconfig +++ b/drivers/input/touchscreen/Kconfig @@ -1168,11 +1168,11 @@ config TOUCHSCREEN_SIS_I2C module will be called sis_i2c. config TOUCHSCREEN_ST1232 - tristate "Sitronix ST1232 touchscreen controllers" + tristate "Sitronix ST1232 or ST1633 touchscreen controllers" depends on I2C help - Say Y here if you want to support Sitronix ST1232 - touchscreen controller. + Say Y here if you want to support the Sitronix ST1232 + or ST1633 touchscreen controller. If unsure, say N. diff --git a/drivers/input/touchscreen/st1232.c b/drivers/input/touchscreen/st1232.c index 11ff32c68025..19a665d48dad 100644 --- a/drivers/input/touchscreen/st1232.c +++ b/drivers/input/touchscreen/st1232.c @@ -23,13 +23,15 @@ #include #define ST1232_TS_NAME "st1232-ts" +#define ST1633_TS_NAME "st1633-ts" + +enum { + st1232, + st1633, +}; #define MIN_X 0x00 #define MIN_Y 0x00 -#define MAX_X 0x31f /* (800 - 1) */ -#define MAX_Y 0x1df /* (480 - 1) */ -#define MAX_AREA 0xff -#define MAX_FINGERS 2 struct st1232_ts_finger { u16 x; @@ -38,12 +40,24 @@ struct st1232_ts_finger { bool is_valid; }; +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 { struct i2c_client *client; struct input_dev *input_dev; - struct st1232_ts_finger finger[MAX_FINGERS]; struct dev_pm_qos_request low_latency_req; int reset_gpio; + const struct st_chip_info *chip_info; + int read_buf_len; + u8 *read_buf; + struct st1232_ts_finger *finger; }; static int st1232_ts_read_data(struct st1232_ts_data *ts) @@ -52,40 +66,35 @@ static int st1232_ts_read_data(struct st1232_ts_data *ts) struct i2c_client *client = ts->client; struct i2c_msg msg[2]; int error; - u8 start_reg; - u8 buf[10]; + int i, y; + u8 start_reg = ts->chip_info->start_reg; + u8 *buf = ts->read_buf; - /* read touchscreen data from ST1232 */ + /* read touchscreen data */ msg[0].addr = client->addr; msg[0].flags = 0; msg[0].len = 1; msg[0].buf = &start_reg; - start_reg = 0x10; msg[1].addr = ts->client->addr; msg[1].flags = I2C_M_RD; - msg[1].len = sizeof(buf); + msg[1].len = ts->read_buf_len; msg[1].buf = buf; error = i2c_transfer(client->adapter, msg, 2); if (error < 0) return error; - /* get "valid" bits */ - finger[0].is_valid = buf[2] >> 7; - finger[1].is_valid = buf[5] >> 7; + for (i = 0, y = 0; i < ts->chip_info->max_fingers; i++, y += 3) { + finger[i].is_valid = buf[i + y] >> 7; + if (finger[i].is_valid) { + finger[i].x = ((buf[i + y] & 0x0070) << 4) | buf[i + 1]; + finger[i].y = ((buf[i + y] & 0x0007) << 8) | buf[i + 2]; - /* get xy coordinate */ - if (finger[0].is_valid) { - finger[0].x = ((buf[2] & 0x0070) << 4) | buf[3]; - finger[0].y = ((buf[2] & 0x0007) << 8) | buf[4]; - finger[0].t = buf[8]; - } - - if (finger[1].is_valid) { - finger[1].x = ((buf[5] & 0x0070) << 4) | buf[6]; - finger[1].y = ((buf[5] & 0x0007) << 8) | buf[7]; - finger[1].t = buf[9]; + /* st1232 includes a z-axis / touch strength */ + if (ts->chip_info->have_z) + finger[i].t = buf[i + 6]; + } } return 0; @@ -104,11 +113,14 @@ static irqreturn_t st1232_ts_irq_handler(int irq, void *dev_id) goto end; /* multi touch protocol */ - for (i = 0; i < MAX_FINGERS; i++) { + for (i = 0; i < ts->chip_info->max_fingers; i++) { if (!finger[i].is_valid) continue; - input_report_abs(input_dev, ABS_MT_TOUCH_MAJOR, finger[i].t); + if (ts->chip_info->have_z) + input_report_abs(input_dev, ABS_MT_TOUCH_MAJOR, + finger[i].t); + input_report_abs(input_dev, ABS_MT_POSITION_X, finger[i].x); input_report_abs(input_dev, ABS_MT_POSITION_Y, finger[i].y); input_mt_sync(input_dev); @@ -142,12 +154,40 @@ static void st1232_ts_power(struct st1232_ts_data *ts, bool poweron) gpio_direction_output(ts->reset_gpio, poweron); } +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, const struct i2c_device_id *id) { struct st1232_ts_data *ts; + struct st1232_ts_finger *finger; struct input_dev *input_dev; int error; + const struct st_chip_info *match = NULL; + + match = device_get_match_data(&client->dev); + if (!match && id) + match = (const void *)id->driver_data; + if (!match) { + dev_err(&client->dev, "unknown device model\n"); + return -ENODEV; + } if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) { dev_err(&client->dev, "need I2C_FUNC_I2C\n"); @@ -163,6 +203,19 @@ static int st1232_ts_probe(struct i2c_client *client, if (!ts) return -ENOMEM; + ts->chip_info = match; + ts->finger = devm_kzalloc(&client->dev, + sizeof(*finger) * ts->chip_info->max_fingers, + GFP_KERNEL); + if (!ts->finger) + return -ENOMEM; + + /* allocate a buffer according to the number of registers to read */ + ts->read_buf_len = ts->chip_info->max_fingers * 4; + ts->read_buf = devm_kzalloc(&client->dev, ts->read_buf_len, GFP_KERNEL); + if (!ts->read_buf) + return -ENOMEM; + input_dev = devm_input_allocate_device(&client->dev); if (!input_dev) return -ENOMEM; @@ -192,9 +245,14 @@ static int st1232_ts_probe(struct i2c_client *client, __set_bit(EV_KEY, input_dev->evbit); __set_bit(EV_ABS, input_dev->evbit); - input_set_abs_params(input_dev, ABS_MT_TOUCH_MAJOR, 0, MAX_AREA, 0, 0); - input_set_abs_params(input_dev, ABS_MT_POSITION_X, MIN_X, MAX_X, 0, 0); - input_set_abs_params(input_dev, ABS_MT_POSITION_Y, MIN_Y, MAX_Y, 0, 0); + 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, + MIN_X, ts->chip_info->max_x, 0, 0); + input_set_abs_params(input_dev, ABS_MT_POSITION_Y, + MIN_Y, ts->chip_info->max_y, 0, 0); error = devm_request_threaded_irq(&client->dev, client->irq, NULL, st1232_ts_irq_handler, @@ -261,13 +319,15 @@ static SIMPLE_DEV_PM_OPS(st1232_ts_pm_ops, st1232_ts_suspend, st1232_ts_resume); static const struct i2c_device_id st1232_ts_id[] = { - { ST1232_TS_NAME, 0 }, + { ST1232_TS_NAME, (unsigned long)&st1232_chip_info }, + { ST1633_TS_NAME, (unsigned long)&st1633_chip_info }, { } }; MODULE_DEVICE_TABLE(i2c, st1232_ts_id); static const struct of_device_id st1232_ts_dt_ids[] = { - { .compatible = "sitronix,st1232", }, + { .compatible = "sitronix,st1232", .data = &st1232_chip_info }, + { .compatible = "sitronix,st1633", .data = &st1633_chip_info }, { } }; MODULE_DEVICE_TABLE(of, st1232_ts_dt_ids); -- 2.20.1