2019-05-29 07:17:56 -07:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
2013-10-31 01:25:32 -07:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2012-2013 MundoReader S.L.
|
|
|
|
* Author: Heiko Stuebner <heiko@sntech.de>
|
|
|
|
*
|
|
|
|
* based in parts on Nook zforce driver
|
|
|
|
*
|
|
|
|
* Copyright (C) 2010 Barnes & Noble, Inc.
|
|
|
|
* Author: Pieter Truter<ptruter@intrinsyc.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/delay.h>
|
|
|
|
#include <linux/device.h>
|
2024-08-23 22:50:27 -07:00
|
|
|
#include <linux/gpio/consumer.h>
|
|
|
|
#include <linux/i2c.h>
|
|
|
|
#include <linux/input.h>
|
2013-10-31 01:25:32 -07:00
|
|
|
#include <linux/input/mt.h>
|
2023-12-24 00:04:23 -08:00
|
|
|
#include <linux/input/touchscreen.h>
|
2024-08-23 22:50:27 -07:00
|
|
|
#include <linux/interrupt.h>
|
|
|
|
#include <linux/module.h>
|
2014-01-27 12:37:21 -08:00
|
|
|
#include <linux/of.h>
|
2024-08-23 22:50:27 -07:00
|
|
|
#include <linux/property.h>
|
|
|
|
#include <linux/regulator/consumer.h>
|
|
|
|
#include <linux/slab.h>
|
2024-10-01 15:35:57 -04:00
|
|
|
#include <linux/unaligned.h>
|
2013-10-31 01:25:32 -07:00
|
|
|
|
|
|
|
#define WAIT_TIMEOUT msecs_to_jiffies(1000)
|
|
|
|
|
|
|
|
#define FRAME_START 0xee
|
2014-01-27 12:28:33 -08:00
|
|
|
#define FRAME_MAXSIZE 257
|
2013-10-31 01:25:32 -07:00
|
|
|
|
|
|
|
/* Offsets of the different parts of the payload the controller sends */
|
|
|
|
#define PAYLOAD_HEADER 0
|
|
|
|
#define PAYLOAD_LENGTH 1
|
|
|
|
#define PAYLOAD_BODY 2
|
|
|
|
|
|
|
|
/* Response offsets */
|
|
|
|
#define RESPONSE_ID 0
|
|
|
|
#define RESPONSE_DATA 1
|
|
|
|
|
|
|
|
/* Commands */
|
|
|
|
#define COMMAND_DEACTIVATE 0x00
|
|
|
|
#define COMMAND_INITIALIZE 0x01
|
|
|
|
#define COMMAND_RESOLUTION 0x02
|
|
|
|
#define COMMAND_SETCONFIG 0x03
|
|
|
|
#define COMMAND_DATAREQUEST 0x04
|
|
|
|
#define COMMAND_SCANFREQ 0x08
|
|
|
|
#define COMMAND_STATUS 0X1e
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Responses the controller sends as a result of
|
|
|
|
* command requests
|
|
|
|
*/
|
|
|
|
#define RESPONSE_DEACTIVATE 0x00
|
|
|
|
#define RESPONSE_INITIALIZE 0x01
|
|
|
|
#define RESPONSE_RESOLUTION 0x02
|
|
|
|
#define RESPONSE_SETCONFIG 0x03
|
|
|
|
#define RESPONSE_SCANFREQ 0x08
|
|
|
|
#define RESPONSE_STATUS 0X1e
|
|
|
|
|
|
|
|
/*
|
2014-01-27 12:27:06 -08:00
|
|
|
* Notifications are sent by the touch controller without
|
2013-10-31 01:25:32 -07:00
|
|
|
* being requested by the driver and include for example
|
|
|
|
* touch indications
|
|
|
|
*/
|
|
|
|
#define NOTIFICATION_TOUCH 0x04
|
|
|
|
#define NOTIFICATION_BOOTCOMPLETE 0x07
|
|
|
|
#define NOTIFICATION_OVERRUN 0x25
|
|
|
|
#define NOTIFICATION_PROXIMITY 0x26
|
|
|
|
#define NOTIFICATION_INVALID_COMMAND 0xfe
|
|
|
|
|
|
|
|
#define ZFORCE_REPORT_POINTS 2
|
|
|
|
#define ZFORCE_MAX_AREA 0xff
|
|
|
|
|
|
|
|
#define STATE_DOWN 0
|
|
|
|
#define STATE_MOVE 1
|
|
|
|
#define STATE_UP 2
|
|
|
|
|
|
|
|
#define SETCONFIG_DUALTOUCH (1 << 0)
|
|
|
|
|
|
|
|
struct zforce_point {
|
|
|
|
int coord_x;
|
|
|
|
int coord_y;
|
|
|
|
int state;
|
|
|
|
int id;
|
|
|
|
int area_major;
|
|
|
|
int area_minor;
|
|
|
|
int orientation;
|
|
|
|
int pressure;
|
|
|
|
int prblty;
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @client the i2c_client
|
|
|
|
* @input the input device
|
|
|
|
* @suspending in the process of going to suspend (don't emit wakeup
|
|
|
|
* events for commands executed to suspend the device)
|
|
|
|
* @suspended device suspended
|
|
|
|
* @command_done completion to wait for the command result
|
2014-01-27 12:27:06 -08:00
|
|
|
* @command_waiting the id of the command that is currently waiting
|
2013-10-31 01:25:32 -07:00
|
|
|
* for a result
|
|
|
|
* @command_result returned result of the command
|
|
|
|
*/
|
|
|
|
struct zforce_ts {
|
|
|
|
struct i2c_client *client;
|
|
|
|
struct input_dev *input;
|
2023-12-24 00:04:23 -08:00
|
|
|
struct touchscreen_properties prop;
|
2013-10-31 01:25:32 -07:00
|
|
|
char phys[32];
|
|
|
|
|
2015-07-06 15:57:44 -07:00
|
|
|
struct gpio_desc *gpio_int;
|
|
|
|
struct gpio_desc *gpio_rst;
|
|
|
|
|
2013-10-31 01:25:32 -07:00
|
|
|
bool suspending;
|
|
|
|
bool suspended;
|
|
|
|
bool boot_complete;
|
|
|
|
|
|
|
|
/* Firmware version information */
|
|
|
|
u16 version_major;
|
|
|
|
u16 version_minor;
|
|
|
|
u16 version_build;
|
|
|
|
u16 version_rev;
|
|
|
|
|
|
|
|
struct completion command_done;
|
|
|
|
int command_waiting;
|
|
|
|
int command_result;
|
|
|
|
};
|
|
|
|
|
|
|
|
static int zforce_command(struct zforce_ts *ts, u8 cmd)
|
|
|
|
{
|
|
|
|
struct i2c_client *client = ts->client;
|
|
|
|
char buf[3];
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
dev_dbg(&client->dev, "%s: 0x%x\n", __func__, cmd);
|
|
|
|
|
|
|
|
buf[0] = FRAME_START;
|
|
|
|
buf[1] = 1; /* data size, command only */
|
|
|
|
buf[2] = cmd;
|
|
|
|
|
|
|
|
ret = i2c_master_send(client, &buf[0], ARRAY_SIZE(buf));
|
|
|
|
if (ret < 0) {
|
|
|
|
dev_err(&client->dev, "i2c send data request error: %d\n", ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int zforce_send_wait(struct zforce_ts *ts, const char *buf, int len)
|
|
|
|
{
|
|
|
|
struct i2c_client *client = ts->client;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
dev_dbg(&client->dev, "sending %d bytes for command 0x%x\n",
|
|
|
|
buf[1], buf[2]);
|
|
|
|
|
|
|
|
ts->command_waiting = buf[2];
|
|
|
|
|
|
|
|
ret = i2c_master_send(client, buf, len);
|
|
|
|
if (ret < 0) {
|
|
|
|
dev_err(&client->dev, "i2c send data request error: %d\n", ret);
|
2024-08-23 22:50:36 -07:00
|
|
|
return ret;
|
2013-10-31 01:25:32 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
dev_dbg(&client->dev, "waiting for result for command 0x%x\n", buf[2]);
|
|
|
|
|
2024-08-23 22:50:30 -07:00
|
|
|
if (wait_for_completion_timeout(&ts->command_done, WAIT_TIMEOUT) == 0)
|
|
|
|
return -ETIME;
|
2013-10-31 01:25:32 -07:00
|
|
|
|
|
|
|
ret = ts->command_result;
|
2024-08-23 22:50:30 -07:00
|
|
|
return 0;
|
2013-10-31 01:25:32 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static int zforce_command_wait(struct zforce_ts *ts, u8 cmd)
|
|
|
|
{
|
|
|
|
struct i2c_client *client = ts->client;
|
|
|
|
char buf[3];
|
2024-08-23 22:50:36 -07:00
|
|
|
int error;
|
2013-10-31 01:25:32 -07:00
|
|
|
|
|
|
|
dev_dbg(&client->dev, "%s: 0x%x\n", __func__, cmd);
|
|
|
|
|
|
|
|
buf[0] = FRAME_START;
|
|
|
|
buf[1] = 1; /* data size, command only */
|
|
|
|
buf[2] = cmd;
|
|
|
|
|
2024-08-23 22:50:36 -07:00
|
|
|
error = zforce_send_wait(ts, &buf[0], ARRAY_SIZE(buf));
|
|
|
|
if (error) {
|
|
|
|
dev_err(&client->dev, "i2c send data request error: %d\n",
|
|
|
|
error);
|
|
|
|
return error;
|
2013-10-31 01:25:32 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int zforce_resolution(struct zforce_ts *ts, u16 x, u16 y)
|
|
|
|
{
|
|
|
|
struct i2c_client *client = ts->client;
|
|
|
|
char buf[7] = { FRAME_START, 5, COMMAND_RESOLUTION,
|
|
|
|
(x & 0xff), ((x >> 8) & 0xff),
|
|
|
|
(y & 0xff), ((y >> 8) & 0xff) };
|
|
|
|
|
|
|
|
dev_dbg(&client->dev, "set resolution to (%d,%d)\n", x, y);
|
|
|
|
|
|
|
|
return zforce_send_wait(ts, &buf[0], ARRAY_SIZE(buf));
|
|
|
|
}
|
|
|
|
|
|
|
|
static int zforce_scan_frequency(struct zforce_ts *ts, u16 idle, u16 finger,
|
|
|
|
u16 stylus)
|
|
|
|
{
|
|
|
|
struct i2c_client *client = ts->client;
|
|
|
|
char buf[9] = { FRAME_START, 7, COMMAND_SCANFREQ,
|
|
|
|
(idle & 0xff), ((idle >> 8) & 0xff),
|
|
|
|
(finger & 0xff), ((finger >> 8) & 0xff),
|
|
|
|
(stylus & 0xff), ((stylus >> 8) & 0xff) };
|
|
|
|
|
2014-01-27 12:27:35 -08:00
|
|
|
dev_dbg(&client->dev,
|
|
|
|
"set scan frequency to (idle: %d, finger: %d, stylus: %d)\n",
|
2013-10-31 01:25:32 -07:00
|
|
|
idle, finger, stylus);
|
|
|
|
|
|
|
|
return zforce_send_wait(ts, &buf[0], ARRAY_SIZE(buf));
|
|
|
|
}
|
|
|
|
|
|
|
|
static int zforce_setconfig(struct zforce_ts *ts, char b1)
|
|
|
|
{
|
|
|
|
struct i2c_client *client = ts->client;
|
|
|
|
char buf[7] = { FRAME_START, 5, COMMAND_SETCONFIG,
|
|
|
|
b1, 0, 0, 0 };
|
|
|
|
|
|
|
|
dev_dbg(&client->dev, "set config to (%d)\n", b1);
|
|
|
|
|
|
|
|
return zforce_send_wait(ts, &buf[0], ARRAY_SIZE(buf));
|
|
|
|
}
|
|
|
|
|
|
|
|
static int zforce_start(struct zforce_ts *ts)
|
|
|
|
{
|
|
|
|
struct i2c_client *client = ts->client;
|
2024-08-23 22:50:36 -07:00
|
|
|
int error;
|
2013-10-31 01:25:32 -07:00
|
|
|
|
|
|
|
dev_dbg(&client->dev, "starting device\n");
|
|
|
|
|
2024-08-23 22:50:36 -07:00
|
|
|
error = zforce_command_wait(ts, COMMAND_INITIALIZE);
|
|
|
|
if (error) {
|
|
|
|
dev_err(&client->dev, "Unable to initialize, %d\n", error);
|
|
|
|
return error;
|
2013-10-31 01:25:32 -07:00
|
|
|
}
|
|
|
|
|
2024-08-23 22:50:36 -07:00
|
|
|
error = zforce_resolution(ts, ts->prop.max_x, ts->prop.max_y);
|
|
|
|
if (error) {
|
|
|
|
dev_err(&client->dev, "Unable to set resolution, %d\n", error);
|
|
|
|
goto err_deactivate;
|
2013-10-31 01:25:32 -07:00
|
|
|
}
|
|
|
|
|
2024-08-23 22:50:36 -07:00
|
|
|
error = zforce_scan_frequency(ts, 10, 50, 50);
|
|
|
|
if (error) {
|
2013-10-31 01:25:32 -07:00
|
|
|
dev_err(&client->dev, "Unable to set scan frequency, %d\n",
|
2024-08-23 22:50:36 -07:00
|
|
|
error);
|
|
|
|
goto err_deactivate;
|
2013-10-31 01:25:32 -07:00
|
|
|
}
|
|
|
|
|
2024-08-23 22:50:36 -07:00
|
|
|
error = zforce_setconfig(ts, SETCONFIG_DUALTOUCH);
|
|
|
|
if (error) {
|
2013-10-31 01:25:32 -07:00
|
|
|
dev_err(&client->dev, "Unable to set config\n");
|
2024-08-23 22:50:36 -07:00
|
|
|
goto err_deactivate;
|
2013-10-31 01:25:32 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* start sending touch events */
|
2024-08-23 22:50:36 -07:00
|
|
|
error = zforce_command(ts, COMMAND_DATAREQUEST);
|
|
|
|
if (error) {
|
2013-10-31 01:25:32 -07:00
|
|
|
dev_err(&client->dev, "Unable to request data\n");
|
2024-08-23 22:50:36 -07:00
|
|
|
goto err_deactivate;
|
2013-10-31 01:25:32 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Per NN, initial cal. take max. of 200msec.
|
|
|
|
* Allow time to complete this calibration
|
|
|
|
*/
|
|
|
|
msleep(200);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
2024-08-23 22:50:36 -07:00
|
|
|
err_deactivate:
|
2013-10-31 01:25:32 -07:00
|
|
|
zforce_command_wait(ts, COMMAND_DEACTIVATE);
|
2024-08-23 22:50:36 -07:00
|
|
|
return error;
|
2013-10-31 01:25:32 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static int zforce_stop(struct zforce_ts *ts)
|
|
|
|
{
|
|
|
|
struct i2c_client *client = ts->client;
|
2024-08-23 22:50:36 -07:00
|
|
|
int error;
|
2013-10-31 01:25:32 -07:00
|
|
|
|
|
|
|
dev_dbg(&client->dev, "stopping device\n");
|
|
|
|
|
|
|
|
/* Deactivates touch sensing and puts the device into sleep. */
|
2024-08-23 22:50:36 -07:00
|
|
|
error = zforce_command_wait(ts, COMMAND_DEACTIVATE);
|
|
|
|
if (error) {
|
2013-10-31 01:25:32 -07:00
|
|
|
dev_err(&client->dev, "could not deactivate device, %d\n",
|
2024-08-23 22:50:36 -07:00
|
|
|
error);
|
|
|
|
return error;
|
2013-10-31 01:25:32 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int zforce_touch_event(struct zforce_ts *ts, u8 *payload)
|
|
|
|
{
|
|
|
|
struct i2c_client *client = ts->client;
|
|
|
|
struct zforce_point point;
|
|
|
|
int count, i, num = 0;
|
2024-08-23 22:50:34 -07:00
|
|
|
u8 *p;
|
2013-10-31 01:25:32 -07:00
|
|
|
|
|
|
|
count = payload[0];
|
|
|
|
if (count > ZFORCE_REPORT_POINTS) {
|
2014-01-27 12:27:35 -08:00
|
|
|
dev_warn(&client->dev,
|
|
|
|
"too many coordinates %d, expected max %d\n",
|
2013-10-31 01:25:32 -07:00
|
|
|
count, ZFORCE_REPORT_POINTS);
|
|
|
|
count = ZFORCE_REPORT_POINTS;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < count; i++) {
|
2024-08-23 22:50:34 -07:00
|
|
|
p = &payload[i * 9 + 1];
|
|
|
|
|
|
|
|
point.coord_x = get_unaligned_le16(&p[0]);
|
|
|
|
point.coord_y = get_unaligned_le16(&p[2]);
|
2013-10-31 01:25:32 -07:00
|
|
|
|
2023-12-24 00:04:23 -08:00
|
|
|
if (point.coord_x > ts->prop.max_x ||
|
|
|
|
point.coord_y > ts->prop.max_y) {
|
2013-10-31 01:25:32 -07:00
|
|
|
dev_warn(&client->dev, "coordinates (%d,%d) invalid\n",
|
|
|
|
point.coord_x, point.coord_y);
|
|
|
|
point.coord_x = point.coord_y = 0;
|
|
|
|
}
|
|
|
|
|
2024-08-23 22:50:34 -07:00
|
|
|
point.state = p[4] & 0x0f;
|
|
|
|
point.id = (p[4] & 0xf0) >> 4;
|
2013-10-31 01:25:32 -07:00
|
|
|
|
|
|
|
/* determine touch major, minor and orientation */
|
2024-08-23 22:50:34 -07:00
|
|
|
point.area_major = max(p[5], p[6]);
|
|
|
|
point.area_minor = min(p[5], p[6]);
|
|
|
|
point.orientation = p[5] > p[6];
|
|
|
|
|
|
|
|
point.pressure = p[7];
|
|
|
|
point.prblty = p[8];
|
2013-10-31 01:25:32 -07:00
|
|
|
|
|
|
|
dev_dbg(&client->dev,
|
|
|
|
"point %d/%d: state %d, id %d, pressure %d, prblty %d, x %d, y %d, amajor %d, aminor %d, ori %d\n",
|
|
|
|
i, count, point.state, point.id,
|
|
|
|
point.pressure, point.prblty,
|
|
|
|
point.coord_x, point.coord_y,
|
|
|
|
point.area_major, point.area_minor,
|
|
|
|
point.orientation);
|
|
|
|
|
|
|
|
/* the zforce id starts with "1", so needs to be decreased */
|
|
|
|
input_mt_slot(ts->input, point.id - 1);
|
|
|
|
|
2024-08-23 22:50:26 -07:00
|
|
|
if (input_mt_report_slot_state(ts->input, MT_TOOL_FINGER,
|
|
|
|
point.state != STATE_UP)) {
|
2023-12-24 00:04:23 -08:00
|
|
|
touchscreen_report_pos(ts->input, &ts->prop,
|
|
|
|
point.coord_x, point.coord_y,
|
|
|
|
true);
|
2013-10-31 01:25:32 -07:00
|
|
|
input_report_abs(ts->input, ABS_MT_TOUCH_MAJOR,
|
|
|
|
point.area_major);
|
|
|
|
input_report_abs(ts->input, ABS_MT_TOUCH_MINOR,
|
|
|
|
point.area_minor);
|
|
|
|
input_report_abs(ts->input, ABS_MT_ORIENTATION,
|
|
|
|
point.orientation);
|
|
|
|
num++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
input_mt_sync_frame(ts->input);
|
|
|
|
|
|
|
|
input_mt_report_finger_count(ts->input, num);
|
|
|
|
|
|
|
|
input_sync(ts->input);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int zforce_read_packet(struct zforce_ts *ts, u8 *buf)
|
|
|
|
{
|
|
|
|
struct i2c_client *client = ts->client;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
/* read 2 byte message header */
|
|
|
|
ret = i2c_master_recv(client, buf, 2);
|
|
|
|
if (ret < 0) {
|
|
|
|
dev_err(&client->dev, "error reading header: %d\n", ret);
|
2024-08-23 22:50:30 -07:00
|
|
|
return ret;
|
2013-10-31 01:25:32 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (buf[PAYLOAD_HEADER] != FRAME_START) {
|
|
|
|
dev_err(&client->dev, "invalid frame start: %d\n", buf[0]);
|
2024-08-23 22:50:30 -07:00
|
|
|
return -EIO;
|
2013-10-31 01:25:32 -07:00
|
|
|
}
|
|
|
|
|
2014-01-27 12:27:49 -08:00
|
|
|
if (buf[PAYLOAD_LENGTH] == 0) {
|
2013-10-31 01:25:32 -07:00
|
|
|
dev_err(&client->dev, "invalid payload length: %d\n",
|
|
|
|
buf[PAYLOAD_LENGTH]);
|
2024-08-23 22:50:30 -07:00
|
|
|
return -EIO;
|
2013-10-31 01:25:32 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* read the message */
|
|
|
|
ret = i2c_master_recv(client, &buf[PAYLOAD_BODY], buf[PAYLOAD_LENGTH]);
|
|
|
|
if (ret < 0) {
|
|
|
|
dev_err(&client->dev, "error reading payload: %d\n", ret);
|
2024-08-23 22:50:30 -07:00
|
|
|
return ret;
|
2013-10-31 01:25:32 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
dev_dbg(&client->dev, "read %d bytes for response command 0x%x\n",
|
|
|
|
buf[PAYLOAD_LENGTH], buf[PAYLOAD_BODY]);
|
|
|
|
|
2024-08-23 22:50:30 -07:00
|
|
|
return 0;
|
2013-10-31 01:25:32 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void zforce_complete(struct zforce_ts *ts, int cmd, int result)
|
|
|
|
{
|
|
|
|
struct i2c_client *client = ts->client;
|
|
|
|
|
|
|
|
if (ts->command_waiting == cmd) {
|
|
|
|
dev_dbg(&client->dev, "completing command 0x%x\n", cmd);
|
|
|
|
ts->command_result = result;
|
|
|
|
complete(&ts->command_done);
|
|
|
|
} else {
|
|
|
|
dev_dbg(&client->dev, "command %d not for us\n", cmd);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-12-14 01:41:55 -08:00
|
|
|
static irqreturn_t zforce_irq(int irq, void *dev_id)
|
|
|
|
{
|
|
|
|
struct zforce_ts *ts = dev_id;
|
|
|
|
struct i2c_client *client = ts->client;
|
|
|
|
|
|
|
|
if (ts->suspended && device_may_wakeup(&client->dev))
|
|
|
|
pm_wakeup_event(&client->dev, 500);
|
|
|
|
|
|
|
|
return IRQ_WAKE_THREAD;
|
|
|
|
}
|
|
|
|
|
|
|
|
static irqreturn_t zforce_irq_thread(int irq, void *dev_id)
|
2013-10-31 01:25:32 -07:00
|
|
|
{
|
|
|
|
struct zforce_ts *ts = dev_id;
|
|
|
|
struct i2c_client *client = ts->client;
|
2024-08-23 22:50:36 -07:00
|
|
|
int error;
|
2014-01-27 12:28:33 -08:00
|
|
|
u8 payload_buffer[FRAME_MAXSIZE];
|
2013-10-31 01:25:32 -07:00
|
|
|
u8 *payload;
|
2024-08-23 22:50:31 -07:00
|
|
|
bool suspending;
|
2013-10-31 01:25:32 -07:00
|
|
|
|
|
|
|
/*
|
2013-12-14 01:41:55 -08:00
|
|
|
* When still suspended, return.
|
2013-10-31 01:25:32 -07:00
|
|
|
* Due to the level-interrupt we will get re-triggered later.
|
|
|
|
*/
|
|
|
|
if (ts->suspended) {
|
|
|
|
msleep(20);
|
|
|
|
return IRQ_HANDLED;
|
|
|
|
}
|
|
|
|
|
|
|
|
dev_dbg(&client->dev, "handling interrupt\n");
|
|
|
|
|
|
|
|
/* Don't emit wakeup events from commands run by zforce_suspend */
|
2024-08-23 22:50:31 -07:00
|
|
|
suspending = READ_ONCE(ts->suspending);
|
|
|
|
if (!suspending && device_may_wakeup(&client->dev))
|
2013-10-31 01:25:32 -07:00
|
|
|
pm_stay_awake(&client->dev);
|
|
|
|
|
Input: zforce - make the interrupt GPIO optional
Add support for hardware which uses an I2C Serializer / Deserializer
(SerDes) to communicate with the zFroce touch driver. In this case the
SerDes will be configured as an interrupt controller and the zForce driver
will have no access to poll the GPIO line.
To support this, we add two dedicated new GPIOs in the device tree:
reset-gpios and irq-gpios, with the irq-gpios being optional.
To not break the existing device trees, the index based 'gpios' entries
are still supported, but marked as deprecated.
With this, if the interrupt GPIO is available, either via the old or new
device tree style, the while loop will read and handle the packets as long
as the GPIO indicates that the interrupt is asserted (existing, unchanged
driver behavior).
If the interrupt GPIO isn't available, i.e. not configured via the new
device tree style, we are falling back to one read per ISR invocation
(new behavior to support the SerDes).
Note that the gpiod functions help to handle the optional GPIO:
devm_gpiod_get_index_optional() will return NULL in case the interrupt
GPIO isn't available. And gpiod_get_value_cansleep() does cover this, too,
by returning 0 in this case.
Signed-off-by: Dirk Behme <dirk.behme@de.bosch.com>
Reviewed-by: Heiko Stuebner <heiko.stuebner@bq.com>
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
2015-08-03 13:03:09 -07:00
|
|
|
/*
|
|
|
|
* Run at least once and exit the loop if
|
|
|
|
* - the optional interrupt GPIO isn't specified
|
|
|
|
* (there is only one packet read per ISR invocation, then)
|
|
|
|
* or
|
|
|
|
* - the GPIO isn't active any more
|
|
|
|
* (packet read until the level GPIO indicates that there is
|
|
|
|
* no IRQ any more)
|
|
|
|
*/
|
|
|
|
do {
|
2024-08-23 22:50:36 -07:00
|
|
|
error = zforce_read_packet(ts, payload_buffer);
|
|
|
|
if (error) {
|
2014-01-27 12:27:35 -08:00
|
|
|
dev_err(&client->dev,
|
2024-08-23 22:50:36 -07:00
|
|
|
"could not read packet, ret: %d\n", error);
|
2013-10-31 01:25:32 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
payload = &payload_buffer[PAYLOAD_BODY];
|
|
|
|
|
|
|
|
switch (payload[RESPONSE_ID]) {
|
|
|
|
case NOTIFICATION_TOUCH:
|
|
|
|
/*
|
|
|
|
* Always report touch-events received while
|
|
|
|
* suspending, when being a wakeup source
|
|
|
|
*/
|
2024-08-23 22:50:31 -07:00
|
|
|
if (suspending && device_may_wakeup(&client->dev))
|
2013-10-31 01:25:32 -07:00
|
|
|
pm_wakeup_event(&client->dev, 500);
|
|
|
|
zforce_touch_event(ts, &payload[RESPONSE_DATA]);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NOTIFICATION_BOOTCOMPLETE:
|
|
|
|
ts->boot_complete = payload[RESPONSE_DATA];
|
|
|
|
zforce_complete(ts, payload[RESPONSE_ID], 0);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case RESPONSE_INITIALIZE:
|
|
|
|
case RESPONSE_DEACTIVATE:
|
|
|
|
case RESPONSE_SETCONFIG:
|
|
|
|
case RESPONSE_RESOLUTION:
|
|
|
|
case RESPONSE_SCANFREQ:
|
|
|
|
zforce_complete(ts, payload[RESPONSE_ID],
|
|
|
|
payload[RESPONSE_DATA]);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case RESPONSE_STATUS:
|
|
|
|
/*
|
|
|
|
* Version Payload Results
|
|
|
|
* [2:major] [2:minor] [2:build] [2:rev]
|
|
|
|
*/
|
2024-08-23 22:50:33 -07:00
|
|
|
ts->version_major =
|
|
|
|
get_unaligned_le16(&payload[RESPONSE_DATA]);
|
|
|
|
ts->version_minor =
|
|
|
|
get_unaligned_le16(&payload[RESPONSE_DATA + 2]);
|
|
|
|
ts->version_build =
|
|
|
|
get_unaligned_le16(&payload[RESPONSE_DATA + 4]);
|
|
|
|
ts->version_rev =
|
|
|
|
get_unaligned_le16(&payload[RESPONSE_DATA + 6]);
|
|
|
|
|
2014-01-27 12:27:35 -08:00
|
|
|
dev_dbg(&ts->client->dev,
|
|
|
|
"Firmware Version %04x:%04x %04x:%04x\n",
|
2013-10-31 01:25:32 -07:00
|
|
|
ts->version_major, ts->version_minor,
|
|
|
|
ts->version_build, ts->version_rev);
|
|
|
|
|
|
|
|
zforce_complete(ts, payload[RESPONSE_ID], 0);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NOTIFICATION_INVALID_COMMAND:
|
|
|
|
dev_err(&ts->client->dev, "invalid command: 0x%x\n",
|
|
|
|
payload[RESPONSE_DATA]);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2014-01-27 12:27:35 -08:00
|
|
|
dev_err(&ts->client->dev,
|
|
|
|
"unrecognized response id: 0x%x\n",
|
2013-10-31 01:25:32 -07:00
|
|
|
payload[RESPONSE_ID]);
|
|
|
|
break;
|
|
|
|
}
|
Input: zforce - make the interrupt GPIO optional
Add support for hardware which uses an I2C Serializer / Deserializer
(SerDes) to communicate with the zFroce touch driver. In this case the
SerDes will be configured as an interrupt controller and the zForce driver
will have no access to poll the GPIO line.
To support this, we add two dedicated new GPIOs in the device tree:
reset-gpios and irq-gpios, with the irq-gpios being optional.
To not break the existing device trees, the index based 'gpios' entries
are still supported, but marked as deprecated.
With this, if the interrupt GPIO is available, either via the old or new
device tree style, the while loop will read and handle the packets as long
as the GPIO indicates that the interrupt is asserted (existing, unchanged
driver behavior).
If the interrupt GPIO isn't available, i.e. not configured via the new
device tree style, we are falling back to one read per ISR invocation
(new behavior to support the SerDes).
Note that the gpiod functions help to handle the optional GPIO:
devm_gpiod_get_index_optional() will return NULL in case the interrupt
GPIO isn't available. And gpiod_get_value_cansleep() does cover this, too,
by returning 0 in this case.
Signed-off-by: Dirk Behme <dirk.behme@de.bosch.com>
Reviewed-by: Heiko Stuebner <heiko.stuebner@bq.com>
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
2015-08-03 13:03:09 -07:00
|
|
|
} while (gpiod_get_value_cansleep(ts->gpio_int));
|
2013-10-31 01:25:32 -07:00
|
|
|
|
2024-08-23 22:50:31 -07:00
|
|
|
if (!suspending && device_may_wakeup(&client->dev))
|
2013-10-31 01:25:32 -07:00
|
|
|
pm_relax(&client->dev);
|
|
|
|
|
|
|
|
dev_dbg(&client->dev, "finished interrupt\n");
|
|
|
|
|
|
|
|
return IRQ_HANDLED;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int zforce_input_open(struct input_dev *dev)
|
|
|
|
{
|
|
|
|
struct zforce_ts *ts = input_get_drvdata(dev);
|
|
|
|
|
2015-10-02 11:15:08 -07:00
|
|
|
return zforce_start(ts);
|
2013-10-31 01:25:32 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void zforce_input_close(struct input_dev *dev)
|
|
|
|
{
|
|
|
|
struct zforce_ts *ts = input_get_drvdata(dev);
|
|
|
|
struct i2c_client *client = ts->client;
|
2024-08-23 22:50:36 -07:00
|
|
|
int error;
|
2013-10-31 01:25:32 -07:00
|
|
|
|
2024-08-23 22:50:36 -07:00
|
|
|
error = zforce_stop(ts);
|
|
|
|
if (error)
|
2013-10-31 01:25:32 -07:00
|
|
|
dev_warn(&client->dev, "stopping zforce failed\n");
|
|
|
|
}
|
|
|
|
|
2024-08-23 22:50:32 -07:00
|
|
|
static int __zforce_suspend(struct zforce_ts *ts)
|
2013-10-31 01:25:32 -07:00
|
|
|
{
|
2024-08-23 22:50:32 -07:00
|
|
|
struct i2c_client *client = ts->client;
|
2013-10-31 01:25:32 -07:00
|
|
|
struct input_dev *input = ts->input;
|
2024-08-23 22:50:36 -07:00
|
|
|
int error;
|
2013-10-31 01:25:32 -07:00
|
|
|
|
2024-08-23 22:50:32 -07:00
|
|
|
guard(mutex)(&input->mutex);
|
2013-10-31 01:25:32 -07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* When configured as a wakeup source device should always wake
|
|
|
|
* the system, therefore start device if necessary.
|
|
|
|
*/
|
|
|
|
if (device_may_wakeup(&client->dev)) {
|
|
|
|
dev_dbg(&client->dev, "suspend while being a wakeup source\n");
|
|
|
|
|
|
|
|
/* Need to start device, if not open, to be a wakeup source. */
|
2020-10-04 21:16:07 -07:00
|
|
|
if (!input_device_enabled(input)) {
|
2024-08-23 22:50:36 -07:00
|
|
|
error = zforce_start(ts);
|
|
|
|
if (error)
|
|
|
|
return error;
|
2013-10-31 01:25:32 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
enable_irq_wake(client->irq);
|
2020-10-04 21:16:07 -07:00
|
|
|
} else if (input_device_enabled(input)) {
|
2014-01-27 12:27:35 -08:00
|
|
|
dev_dbg(&client->dev,
|
|
|
|
"suspend without being a wakeup source\n");
|
2013-10-31 01:25:32 -07:00
|
|
|
|
2024-08-23 22:50:36 -07:00
|
|
|
error = zforce_stop(ts);
|
|
|
|
if (error)
|
|
|
|
return error;
|
2013-10-31 01:25:32 -07:00
|
|
|
|
|
|
|
disable_irq(client->irq);
|
|
|
|
}
|
|
|
|
|
|
|
|
ts->suspended = true;
|
2024-08-23 22:50:32 -07:00
|
|
|
return 0;
|
|
|
|
}
|
2013-10-31 01:25:32 -07:00
|
|
|
|
2024-08-23 22:50:32 -07:00
|
|
|
static int zforce_suspend(struct device *dev)
|
|
|
|
{
|
|
|
|
struct i2c_client *client = to_i2c_client(dev);
|
|
|
|
struct zforce_ts *ts = i2c_get_clientdata(client);
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
WRITE_ONCE(ts->suspending, true);
|
2024-08-23 22:50:31 -07:00
|
|
|
smp_mb();
|
|
|
|
|
2024-08-23 22:50:32 -07:00
|
|
|
ret = __zforce_suspend(ts);
|
|
|
|
|
|
|
|
smp_mb();
|
|
|
|
WRITE_ONCE(ts->suspending, false);
|
2013-10-31 01:25:32 -07:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2023-01-02 18:18:40 +00:00
|
|
|
static int zforce_resume(struct device *dev)
|
2013-10-31 01:25:32 -07:00
|
|
|
{
|
|
|
|
struct i2c_client *client = to_i2c_client(dev);
|
|
|
|
struct zforce_ts *ts = i2c_get_clientdata(client);
|
|
|
|
struct input_dev *input = ts->input;
|
2024-08-23 22:50:36 -07:00
|
|
|
int error;
|
2013-10-31 01:25:32 -07:00
|
|
|
|
2024-08-23 22:50:32 -07:00
|
|
|
guard(mutex)(&input->mutex);
|
2013-10-31 01:25:32 -07:00
|
|
|
|
|
|
|
ts->suspended = false;
|
|
|
|
|
|
|
|
if (device_may_wakeup(&client->dev)) {
|
|
|
|
dev_dbg(&client->dev, "resume from being a wakeup source\n");
|
|
|
|
|
|
|
|
disable_irq_wake(client->irq);
|
|
|
|
|
|
|
|
/* need to stop device if it was not open on suspend */
|
2020-10-04 21:16:07 -07:00
|
|
|
if (!input_device_enabled(input)) {
|
2024-08-23 22:50:36 -07:00
|
|
|
error = zforce_stop(ts);
|
|
|
|
if (error)
|
|
|
|
return error;
|
2013-10-31 01:25:32 -07:00
|
|
|
}
|
2020-10-04 21:16:07 -07:00
|
|
|
} else if (input_device_enabled(input)) {
|
2013-10-31 01:25:32 -07:00
|
|
|
dev_dbg(&client->dev, "resume without being a wakeup source\n");
|
|
|
|
|
|
|
|
enable_irq(client->irq);
|
|
|
|
|
2024-08-23 22:50:36 -07:00
|
|
|
error = zforce_start(ts);
|
|
|
|
if (error)
|
|
|
|
return error;
|
2013-10-31 01:25:32 -07:00
|
|
|
}
|
|
|
|
|
2024-08-23 22:50:32 -07:00
|
|
|
return 0;
|
2013-10-31 01:25:32 -07:00
|
|
|
}
|
|
|
|
|
2023-01-02 18:18:40 +00:00
|
|
|
static DEFINE_SIMPLE_DEV_PM_OPS(zforce_pm_ops, zforce_suspend, zforce_resume);
|
2013-10-31 01:25:32 -07:00
|
|
|
|
|
|
|
static void zforce_reset(void *data)
|
|
|
|
{
|
|
|
|
struct zforce_ts *ts = data;
|
|
|
|
|
2024-08-23 22:50:41 -07:00
|
|
|
gpiod_set_value_cansleep(ts->gpio_rst, 1);
|
2014-07-21 10:02:11 -07:00
|
|
|
udelay(10);
|
2013-10-31 01:25:32 -07:00
|
|
|
}
|
|
|
|
|
2024-08-23 22:50:27 -07:00
|
|
|
static void zforce_ts_parse_legacy_properties(struct zforce_ts *ts)
|
2014-01-27 12:37:21 -08:00
|
|
|
{
|
2024-08-23 22:50:27 -07:00
|
|
|
u32 x_max = 0;
|
|
|
|
u32 y_max = 0;
|
2014-01-27 12:37:21 -08:00
|
|
|
|
2024-08-23 22:50:27 -07:00
|
|
|
device_property_read_u32(&ts->client->dev, "x-size", &x_max);
|
|
|
|
input_set_abs_params(ts->input, ABS_MT_POSITION_X, 0, x_max, 0, 0);
|
2014-01-27 12:37:21 -08:00
|
|
|
|
2024-08-23 22:50:27 -07:00
|
|
|
device_property_read_u32(&ts->client->dev, "y-size", &y_max);
|
|
|
|
input_set_abs_params(ts->input, ABS_MT_POSITION_Y, 0, y_max, 0, 0);
|
2014-01-27 12:37:21 -08:00
|
|
|
}
|
|
|
|
|
2022-11-18 23:40:01 +01:00
|
|
|
static int zforce_probe(struct i2c_client *client)
|
2013-10-31 01:25:32 -07:00
|
|
|
{
|
|
|
|
struct zforce_ts *ts;
|
|
|
|
struct input_dev *input_dev;
|
2024-08-23 22:50:36 -07:00
|
|
|
int error;
|
2013-10-31 01:25:32 -07:00
|
|
|
|
|
|
|
ts = devm_kzalloc(&client->dev, sizeof(struct zforce_ts), GFP_KERNEL);
|
|
|
|
if (!ts)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
Input: zforce - make the interrupt GPIO optional
Add support for hardware which uses an I2C Serializer / Deserializer
(SerDes) to communicate with the zFroce touch driver. In this case the
SerDes will be configured as an interrupt controller and the zForce driver
will have no access to poll the GPIO line.
To support this, we add two dedicated new GPIOs in the device tree:
reset-gpios and irq-gpios, with the irq-gpios being optional.
To not break the existing device trees, the index based 'gpios' entries
are still supported, but marked as deprecated.
With this, if the interrupt GPIO is available, either via the old or new
device tree style, the while loop will read and handle the packets as long
as the GPIO indicates that the interrupt is asserted (existing, unchanged
driver behavior).
If the interrupt GPIO isn't available, i.e. not configured via the new
device tree style, we are falling back to one read per ISR invocation
(new behavior to support the SerDes).
Note that the gpiod functions help to handle the optional GPIO:
devm_gpiod_get_index_optional() will return NULL in case the interrupt
GPIO isn't available. And gpiod_get_value_cansleep() does cover this, too,
by returning 0 in this case.
Signed-off-by: Dirk Behme <dirk.behme@de.bosch.com>
Reviewed-by: Heiko Stuebner <heiko.stuebner@bq.com>
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
2015-08-03 13:03:09 -07:00
|
|
|
ts->gpio_rst = devm_gpiod_get_optional(&client->dev, "reset",
|
|
|
|
GPIOD_OUT_HIGH);
|
2024-08-23 22:50:36 -07:00
|
|
|
error = PTR_ERR_OR_ZERO(ts->gpio_rst);
|
|
|
|
if (error)
|
|
|
|
return dev_err_probe(&client->dev, error,
|
|
|
|
"failed to request reset GPIO\n");
|
2013-10-31 01:25:32 -07:00
|
|
|
|
Input: zforce - make the interrupt GPIO optional
Add support for hardware which uses an I2C Serializer / Deserializer
(SerDes) to communicate with the zFroce touch driver. In this case the
SerDes will be configured as an interrupt controller and the zForce driver
will have no access to poll the GPIO line.
To support this, we add two dedicated new GPIOs in the device tree:
reset-gpios and irq-gpios, with the irq-gpios being optional.
To not break the existing device trees, the index based 'gpios' entries
are still supported, but marked as deprecated.
With this, if the interrupt GPIO is available, either via the old or new
device tree style, the while loop will read and handle the packets as long
as the GPIO indicates that the interrupt is asserted (existing, unchanged
driver behavior).
If the interrupt GPIO isn't available, i.e. not configured via the new
device tree style, we are falling back to one read per ISR invocation
(new behavior to support the SerDes).
Note that the gpiod functions help to handle the optional GPIO:
devm_gpiod_get_index_optional() will return NULL in case the interrupt
GPIO isn't available. And gpiod_get_value_cansleep() does cover this, too,
by returning 0 in this case.
Signed-off-by: Dirk Behme <dirk.behme@de.bosch.com>
Reviewed-by: Heiko Stuebner <heiko.stuebner@bq.com>
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
2015-08-03 13:03:09 -07:00
|
|
|
if (ts->gpio_rst) {
|
|
|
|
ts->gpio_int = devm_gpiod_get_optional(&client->dev, "irq",
|
|
|
|
GPIOD_IN);
|
2024-08-23 22:50:36 -07:00
|
|
|
error = PTR_ERR_OR_ZERO(ts->gpio_int);
|
|
|
|
if (error)
|
|
|
|
return dev_err_probe(&client->dev, error,
|
|
|
|
"failed to request interrupt GPIO\n");
|
Input: zforce - make the interrupt GPIO optional
Add support for hardware which uses an I2C Serializer / Deserializer
(SerDes) to communicate with the zFroce touch driver. In this case the
SerDes will be configured as an interrupt controller and the zForce driver
will have no access to poll the GPIO line.
To support this, we add two dedicated new GPIOs in the device tree:
reset-gpios and irq-gpios, with the irq-gpios being optional.
To not break the existing device trees, the index based 'gpios' entries
are still supported, but marked as deprecated.
With this, if the interrupt GPIO is available, either via the old or new
device tree style, the while loop will read and handle the packets as long
as the GPIO indicates that the interrupt is asserted (existing, unchanged
driver behavior).
If the interrupt GPIO isn't available, i.e. not configured via the new
device tree style, we are falling back to one read per ISR invocation
(new behavior to support the SerDes).
Note that the gpiod functions help to handle the optional GPIO:
devm_gpiod_get_index_optional() will return NULL in case the interrupt
GPIO isn't available. And gpiod_get_value_cansleep() does cover this, too,
by returning 0 in this case.
Signed-off-by: Dirk Behme <dirk.behme@de.bosch.com>
Reviewed-by: Heiko Stuebner <heiko.stuebner@bq.com>
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
2015-08-03 13:03:09 -07:00
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* Deprecated GPIO handling for compatibility
|
|
|
|
* with legacy binding.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* INT GPIO */
|
|
|
|
ts->gpio_int = devm_gpiod_get_index(&client->dev, NULL, 0,
|
|
|
|
GPIOD_IN);
|
2024-08-23 22:50:36 -07:00
|
|
|
|
|
|
|
error = PTR_ERR_OR_ZERO(ts->gpio_int);
|
|
|
|
if (error)
|
|
|
|
return dev_err_probe(&client->dev, error,
|
|
|
|
"failed to request interrupt GPIO\n");
|
Input: zforce - make the interrupt GPIO optional
Add support for hardware which uses an I2C Serializer / Deserializer
(SerDes) to communicate with the zFroce touch driver. In this case the
SerDes will be configured as an interrupt controller and the zForce driver
will have no access to poll the GPIO line.
To support this, we add two dedicated new GPIOs in the device tree:
reset-gpios and irq-gpios, with the irq-gpios being optional.
To not break the existing device trees, the index based 'gpios' entries
are still supported, but marked as deprecated.
With this, if the interrupt GPIO is available, either via the old or new
device tree style, the while loop will read and handle the packets as long
as the GPIO indicates that the interrupt is asserted (existing, unchanged
driver behavior).
If the interrupt GPIO isn't available, i.e. not configured via the new
device tree style, we are falling back to one read per ISR invocation
(new behavior to support the SerDes).
Note that the gpiod functions help to handle the optional GPIO:
devm_gpiod_get_index_optional() will return NULL in case the interrupt
GPIO isn't available. And gpiod_get_value_cansleep() does cover this, too,
by returning 0 in this case.
Signed-off-by: Dirk Behme <dirk.behme@de.bosch.com>
Reviewed-by: Heiko Stuebner <heiko.stuebner@bq.com>
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
2015-08-03 13:03:09 -07:00
|
|
|
|
|
|
|
/* RST GPIO */
|
|
|
|
ts->gpio_rst = devm_gpiod_get_index(&client->dev, NULL, 1,
|
|
|
|
GPIOD_OUT_HIGH);
|
2024-08-23 22:50:36 -07:00
|
|
|
error = PTR_ERR_OR_ZERO(ts->gpio_rst);
|
|
|
|
if (error)
|
|
|
|
return dev_err_probe(&client->dev, error,
|
|
|
|
"failed to request reset GPIO\n");
|
Input: zforce - make the interrupt GPIO optional
Add support for hardware which uses an I2C Serializer / Deserializer
(SerDes) to communicate with the zFroce touch driver. In this case the
SerDes will be configured as an interrupt controller and the zForce driver
will have no access to poll the GPIO line.
To support this, we add two dedicated new GPIOs in the device tree:
reset-gpios and irq-gpios, with the irq-gpios being optional.
To not break the existing device trees, the index based 'gpios' entries
are still supported, but marked as deprecated.
With this, if the interrupt GPIO is available, either via the old or new
device tree style, the while loop will read and handle the packets as long
as the GPIO indicates that the interrupt is asserted (existing, unchanged
driver behavior).
If the interrupt GPIO isn't available, i.e. not configured via the new
device tree style, we are falling back to one read per ISR invocation
(new behavior to support the SerDes).
Note that the gpiod functions help to handle the optional GPIO:
devm_gpiod_get_index_optional() will return NULL in case the interrupt
GPIO isn't available. And gpiod_get_value_cansleep() does cover this, too,
by returning 0 in this case.
Signed-off-by: Dirk Behme <dirk.behme@de.bosch.com>
Reviewed-by: Heiko Stuebner <heiko.stuebner@bq.com>
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
2015-08-03 13:03:09 -07:00
|
|
|
}
|
|
|
|
|
2024-08-23 22:50:39 -07:00
|
|
|
error = devm_regulator_get_enable(&client->dev, "vdd");
|
2024-08-23 22:50:38 -07:00
|
|
|
if (error)
|
|
|
|
return dev_err_probe(&client->dev, error,
|
|
|
|
"failed to request vdd supply\n");
|
2014-07-21 10:02:11 -07:00
|
|
|
|
2024-08-23 22:50:38 -07:00
|
|
|
/*
|
|
|
|
* According to datasheet add 100us grace time after regular
|
|
|
|
* regulator enable delay.
|
|
|
|
*/
|
|
|
|
usleep_range(100, 200);
|
2014-07-21 10:02:11 -07:00
|
|
|
|
2024-08-23 22:50:36 -07:00
|
|
|
error = devm_add_action_or_reset(&client->dev, zforce_reset, ts);
|
|
|
|
if (error)
|
|
|
|
return dev_err_probe(&client->dev, error,
|
|
|
|
"failed to register reset action\n");
|
2013-10-31 01:25:32 -07:00
|
|
|
|
|
|
|
snprintf(ts->phys, sizeof(ts->phys),
|
|
|
|
"%s/input0", dev_name(&client->dev));
|
|
|
|
|
|
|
|
input_dev = devm_input_allocate_device(&client->dev);
|
2024-08-23 22:50:36 -07:00
|
|
|
if (!input_dev)
|
|
|
|
return dev_err_probe(&client->dev, -ENOMEM,
|
|
|
|
"could not allocate input device\n");
|
2013-10-31 01:25:32 -07:00
|
|
|
|
|
|
|
ts->client = client;
|
|
|
|
ts->input = input_dev;
|
|
|
|
|
|
|
|
input_dev->name = "Neonode zForce touchscreen";
|
|
|
|
input_dev->phys = ts->phys;
|
|
|
|
input_dev->id.bustype = BUS_I2C;
|
|
|
|
|
|
|
|
input_dev->open = zforce_input_open;
|
|
|
|
input_dev->close = zforce_input_close;
|
|
|
|
|
2024-08-23 22:50:27 -07:00
|
|
|
zforce_ts_parse_legacy_properties(ts);
|
2023-12-24 00:04:23 -08:00
|
|
|
touchscreen_parse_properties(input_dev, true, &ts->prop);
|
2024-08-23 22:50:36 -07:00
|
|
|
if (ts->prop.max_x == 0 || ts->prop.max_y == 0)
|
|
|
|
return dev_err_probe(&client->dev, -EINVAL, "no size specified");
|
2023-12-24 00:04:23 -08:00
|
|
|
|
2013-10-31 01:25:32 -07:00
|
|
|
input_set_abs_params(input_dev, ABS_MT_TOUCH_MAJOR, 0,
|
|
|
|
ZFORCE_MAX_AREA, 0, 0);
|
|
|
|
input_set_abs_params(input_dev, ABS_MT_TOUCH_MINOR, 0,
|
|
|
|
ZFORCE_MAX_AREA, 0, 0);
|
|
|
|
input_set_abs_params(input_dev, ABS_MT_ORIENTATION, 0, 1, 0, 0);
|
2024-08-23 22:50:29 -07:00
|
|
|
|
2024-08-23 22:50:36 -07:00
|
|
|
error = input_mt_init_slots(input_dev, ZFORCE_REPORT_POINTS,
|
2024-08-23 22:50:29 -07:00
|
|
|
INPUT_MT_DIRECT);
|
2024-08-23 22:50:36 -07:00
|
|
|
if (error)
|
|
|
|
return error;
|
2013-10-31 01:25:32 -07:00
|
|
|
|
|
|
|
input_set_drvdata(ts->input, ts);
|
|
|
|
|
|
|
|
init_completion(&ts->command_done);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The zforce pulls the interrupt low when it has data ready.
|
|
|
|
* After it is triggered the isr thread runs until all the available
|
|
|
|
* packets have been read and the interrupt is high again.
|
|
|
|
* Therefore we can trigger the interrupt anytime it is low and do
|
|
|
|
* not need to limit it to the interrupt edge.
|
|
|
|
*/
|
2024-08-23 22:50:36 -07:00
|
|
|
error = devm_request_threaded_irq(&client->dev, client->irq,
|
|
|
|
zforce_irq, zforce_irq_thread,
|
2024-08-23 22:50:40 -07:00
|
|
|
IRQF_ONESHOT, input_dev->name, ts);
|
2024-08-23 22:50:36 -07:00
|
|
|
if (error)
|
|
|
|
return dev_err_probe(&client->dev, error,
|
|
|
|
"irq %d request failed\n", client->irq);
|
2013-10-31 01:25:32 -07:00
|
|
|
|
|
|
|
i2c_set_clientdata(client, ts);
|
|
|
|
|
|
|
|
/* let the controller boot */
|
2024-08-23 22:50:41 -07:00
|
|
|
gpiod_set_value_cansleep(ts->gpio_rst, 0);
|
2013-10-31 01:25:32 -07:00
|
|
|
|
|
|
|
ts->command_waiting = NOTIFICATION_BOOTCOMPLETE;
|
|
|
|
if (wait_for_completion_timeout(&ts->command_done, WAIT_TIMEOUT) == 0)
|
|
|
|
dev_warn(&client->dev, "bootcomplete timed out\n");
|
|
|
|
|
|
|
|
/* need to start device to get version information */
|
2024-08-23 22:50:36 -07:00
|
|
|
error = zforce_command_wait(ts, COMMAND_INITIALIZE);
|
|
|
|
if (error)
|
|
|
|
return dev_err_probe(&client->dev, error, "unable to initialize\n");
|
2013-10-31 01:25:32 -07:00
|
|
|
|
2014-01-27 12:27:06 -08:00
|
|
|
/* this gets the firmware version among other information */
|
2024-08-23 22:50:36 -07:00
|
|
|
error = zforce_command_wait(ts, COMMAND_STATUS);
|
|
|
|
if (error) {
|
|
|
|
dev_err_probe(&client->dev, error, "couldn't get status\n");
|
2013-10-31 01:25:32 -07:00
|
|
|
zforce_stop(ts);
|
2024-08-23 22:50:36 -07:00
|
|
|
return error;
|
2013-10-31 01:25:32 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* stop device and put it into sleep until it is opened */
|
2024-08-23 22:50:36 -07:00
|
|
|
error = zforce_stop(ts);
|
|
|
|
if (error)
|
|
|
|
return error;
|
2013-10-31 01:25:32 -07:00
|
|
|
|
|
|
|
device_set_wakeup_capable(&client->dev, true);
|
|
|
|
|
2024-08-23 22:50:36 -07:00
|
|
|
error = input_register_device(input_dev);
|
|
|
|
if (error)
|
|
|
|
return dev_err_probe(&client->dev, error,
|
|
|
|
"could not register input device\n");
|
2013-10-31 01:25:32 -07:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2024-08-23 22:50:37 -07:00
|
|
|
static const struct i2c_device_id zforce_idtable[] = {
|
2024-05-09 19:41:59 +02:00
|
|
|
{ "zforce-ts" },
|
2013-10-31 01:25:32 -07:00
|
|
|
{ }
|
|
|
|
};
|
|
|
|
MODULE_DEVICE_TABLE(i2c, zforce_idtable);
|
|
|
|
|
2014-01-27 12:37:21 -08:00
|
|
|
#ifdef CONFIG_OF
|
2014-05-07 13:10:16 -07:00
|
|
|
static const struct of_device_id zforce_dt_idtable[] = {
|
2014-01-27 12:37:21 -08:00
|
|
|
{ .compatible = "neonode,zforce" },
|
|
|
|
{},
|
|
|
|
};
|
|
|
|
MODULE_DEVICE_TABLE(of, zforce_dt_idtable);
|
|
|
|
#endif
|
|
|
|
|
2013-10-31 01:25:32 -07:00
|
|
|
static struct i2c_driver zforce_driver = {
|
|
|
|
.driver = {
|
|
|
|
.name = "zforce-ts",
|
2023-01-02 18:18:40 +00:00
|
|
|
.pm = pm_sleep_ptr(&zforce_pm_ops),
|
2014-01-27 12:37:21 -08:00
|
|
|
.of_match_table = of_match_ptr(zforce_dt_idtable),
|
2024-08-23 22:50:42 -07:00
|
|
|
.probe_type = PROBE_PREFER_ASYNCHRONOUS,
|
2013-10-31 01:25:32 -07:00
|
|
|
},
|
2023-05-17 09:55:42 -07:00
|
|
|
.probe = zforce_probe,
|
2013-10-31 01:25:32 -07:00
|
|
|
.id_table = zforce_idtable,
|
|
|
|
};
|
|
|
|
|
|
|
|
module_i2c_driver(zforce_driver);
|
|
|
|
|
|
|
|
MODULE_AUTHOR("Heiko Stuebner <heiko@sntech.de>");
|
|
|
|
MODULE_DESCRIPTION("zForce TouchScreen Driver");
|
|
|
|
MODULE_LICENSE("GPL");
|