Skip to content

Commit

Permalink
Input: atmel_mxt_ts - implement T15 Key Array support
Browse files Browse the repository at this point in the history
There is a key array object in many maXTouch chips which allows some X/Y
lines to be used as a key array. This patch maps them to a series of keys
which may be configured in a platform data array.

Signed-off-by: Nick Dyer <[email protected]>
Acked-by: Benson Leung <[email protected]>
Acked-by: Yufeng Shen <[email protected]>
  • Loading branch information
ndyer committed Apr 26, 2016
1 parent a6f0ee9 commit 15bb074
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
54 changes: 54 additions & 0 deletions drivers/input/touchscreen/atmel_mxt_ts.c
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,7 @@ struct mxt_data {
u8 multitouch;
struct t7_config t7_cfg;
bool use_retrigen_workaround;
unsigned long t15_keystatus;

/* Cached parameters from object table */
u16 T5_address;
Expand All @@ -264,6 +265,8 @@ struct mxt_data {
u16 T71_address;
u8 T9_reportid_min;
u8 T9_reportid_max;
u8 T15_reportid_min;
u8 T15_reportid_max;
u16 T18_address;
u8 T19_reportid;
u8 T42_reportid_min;
Expand Down Expand Up @@ -913,6 +916,38 @@ static void mxt_proc_t100_message(struct mxt_data *data, u8 *message)
data->update_input = true;
}

static void mxt_proc_t15_messages(struct mxt_data *data, u8 *msg)
{
struct input_dev *input_dev = data->input_dev;
struct device *dev = &data->client->dev;
int key;
bool curr_state, new_state;
bool sync = false;
unsigned long keystates = le32_to_cpu(msg[2]);

for (key = 0; key < data->pdata->t15_num_keys; key++) {
curr_state = test_bit(key, &data->t15_keystatus);
new_state = test_bit(key, &keystates);

if (!curr_state && new_state) {
dev_dbg(dev, "T15 key press: %u\n", key);
__set_bit(key, &data->t15_keystatus);
input_event(input_dev, EV_KEY,
data->pdata->t15_keymap[key], 1);
sync = true;
} else if (curr_state && !new_state) {
dev_dbg(dev, "T15 key release: %u\n", key);
__clear_bit(key, &data->t15_keystatus);
input_event(input_dev, EV_KEY,
data->pdata->t15_keymap[key], 0);
sync = true;
}
}

if (sync)
input_sync(input_dev);
}

static void mxt_proc_t42_messages(struct mxt_data *data, u8 *msg)
{
struct device *dev = &data->client->dev;
Expand Down Expand Up @@ -971,6 +1006,9 @@ static int mxt_proc_message(struct mxt_data *data, u8 *message)
} else if (report_id == data->T19_reportid) {
mxt_input_button(data, message);
data->update_input = true;
} else if (report_id >= data->T15_reportid_min
&& report_id <= data->T15_reportid_max) {
mxt_proc_t15_messages(data, message);
} else {
mxt_dump_message(data, message);
}
Expand Down Expand Up @@ -1627,6 +1665,8 @@ static void mxt_free_object_table(struct mxt_data *data)
data->T71_address = 0;
data->T9_reportid_min = 0;
data->T9_reportid_max = 0;
data->T15_reportid_min = 0;
data->T15_reportid_max = 0;
data->T18_address = 0;
data->T19_reportid = 0;
data->T42_reportid_min = 0;
Expand Down Expand Up @@ -1705,6 +1745,10 @@ static int mxt_parse_object_table(struct mxt_data *data,
object->num_report_ids - 1;
data->num_touchids = object->num_report_ids;
break;
case MXT_TOUCH_KEYARRAY_T15:
data->T15_reportid_min = min_id;
data->T15_reportid_max = max_id;
break;
case MXT_SPT_COMMSCONFIG_T18:
data->T18_address = object->start_address;
break;
Expand Down Expand Up @@ -1973,6 +2017,7 @@ static int mxt_initialize_input_device(struct mxt_data *data)
int error;
unsigned int num_mt_slots;
unsigned int mt_flags = 0;
int i;

switch (data->multitouch) {
case MXT_TOUCH_MULTI_T9:
Expand Down Expand Up @@ -2086,6 +2131,15 @@ static int mxt_initialize_input_device(struct mxt_data *data)
0, 255, 0, 0);
}

/* For T15 Key Array */
if (data->T15_reportid_min) {
data->t15_keystatus = 0;

for (i = 0; i < data->pdata->t15_num_keys; i++)
input_set_capability(input_dev, EV_KEY,
data->pdata->t15_keymap[i]);
}

input_set_drvdata(input_dev, data);

error = input_register_device(input_dev);
Expand Down
2 changes: 2 additions & 0 deletions include/linux/platform_data/atmel_mxt_ts.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ struct mxt_platform_data {
u8 t19_num_keys;
const unsigned int *t19_keymap;
enum mxt_suspend_mode suspend_mode;
int t15_num_keys;
const unsigned int *t15_keymap;
};

#endif /* __LINUX_PLATFORM_DATA_ATMEL_MXT_TS_H */

0 comments on commit 15bb074

Please sign in to comment.