Commit 07df1c55 authored by Jonathan Bakker's avatar Jonathan Bakker Committed by Dmitry Torokhov

Input: tm2-touchkey - allow specifying custom keycodes

Not all devices use the same keycodes in the same order,
so add possibility to define keycodes for buttons present
on actual hardware.

If keycodes property is not present, we assume that device has
at least MENU and BACK keys.
Signed-off-by: default avatarJonathan Bakker <xc-racer2@live.ca>
Signed-off-by: default avatarPaweł Chmiel <pawel.mikolaj.chmiel@gmail.com>
Signed-off-by: default avatarDmitry Torokhov <dmitry.torokhov@gmail.com>
parent d5a158ce
...@@ -12,6 +12,9 @@ Required properties: ...@@ -12,6 +12,9 @@ Required properties:
- vcc-supply : internal regulator output. 1.8V - vcc-supply : internal regulator output. 1.8V
- vdd-supply : power supply for IC 3.3V - vdd-supply : power supply for IC 3.3V
Optional properties:
- linux,keycodes: array of keycodes (max 4), default KEY_PHONE and KEY_BACK
[0]: Documentation/devicetree/bindings/interrupt-controller/interrupts.txt [0]: Documentation/devicetree/bindings/interrupt-controller/interrupts.txt
Example: Example:
...@@ -25,5 +28,6 @@ Example: ...@@ -25,5 +28,6 @@ Example:
interrupts = <2 IRQ_TYPE_EDGE_FALLING>; interrupts = <2 IRQ_TYPE_EDGE_FALLING>;
vcc-supply=<&ldo32_reg>; vcc-supply=<&ldo32_reg>;
vdd-supply=<&ldo33_reg>; vdd-supply=<&ldo33_reg>;
linux,keycodes = <KEY_PHONE KEY_BACK>;
}; };
}; };
...@@ -35,11 +35,6 @@ ...@@ -35,11 +35,6 @@
#define TM2_TOUCHKEY_LED_VOLTAGE_MIN 2500000 #define TM2_TOUCHKEY_LED_VOLTAGE_MIN 2500000
#define TM2_TOUCHKEY_LED_VOLTAGE_MAX 3300000 #define TM2_TOUCHKEY_LED_VOLTAGE_MAX 3300000
enum {
TM2_TOUCHKEY_KEY_MENU = 0x1,
TM2_TOUCHKEY_KEY_BACK,
};
struct touchkey_variant { struct touchkey_variant {
u8 keycode_reg; u8 keycode_reg;
u8 base_reg; u8 base_reg;
...@@ -52,6 +47,8 @@ struct tm2_touchkey_data { ...@@ -52,6 +47,8 @@ struct tm2_touchkey_data {
struct regulator *vdd; struct regulator *vdd;
struct regulator_bulk_data regulators[2]; struct regulator_bulk_data regulators[2];
const struct touchkey_variant *variant; const struct touchkey_variant *variant;
u32 keycodes[4];
int num_keycodes;
}; };
static const struct touchkey_variant tm2_touchkey_variant = { static const struct touchkey_variant tm2_touchkey_variant = {
...@@ -112,7 +109,8 @@ static irqreturn_t tm2_touchkey_irq_handler(int irq, void *devid) ...@@ -112,7 +109,8 @@ static irqreturn_t tm2_touchkey_irq_handler(int irq, void *devid)
{ {
struct tm2_touchkey_data *touchkey = devid; struct tm2_touchkey_data *touchkey = devid;
int data; int data;
int key; int index;
int i;
data = i2c_smbus_read_byte_data(touchkey->client, data = i2c_smbus_read_byte_data(touchkey->client,
touchkey->variant->keycode_reg); touchkey->variant->keycode_reg);
...@@ -122,26 +120,20 @@ static irqreturn_t tm2_touchkey_irq_handler(int irq, void *devid) ...@@ -122,26 +120,20 @@ static irqreturn_t tm2_touchkey_irq_handler(int irq, void *devid)
goto out; goto out;
} }
switch (data & TM2_TOUCHKEY_BIT_KEYCODE) { index = (data & TM2_TOUCHKEY_BIT_KEYCODE) - 1;
case TM2_TOUCHKEY_KEY_MENU: if (index < 0 || index >= touchkey->num_keycodes) {
key = KEY_PHONE;
break;
case TM2_TOUCHKEY_KEY_BACK:
key = KEY_BACK;
break;
default:
dev_warn(&touchkey->client->dev, dev_warn(&touchkey->client->dev,
"unhandled keycode, data %#02x\n", data); "invalid keycode index %d\n", index);
goto out; goto out;
} }
if (data & TM2_TOUCHKEY_BIT_PRESS_EV) { if (data & TM2_TOUCHKEY_BIT_PRESS_EV) {
input_report_key(touchkey->input_dev, KEY_PHONE, 0); for (i = 0; i < touchkey->num_keycodes; i++)
input_report_key(touchkey->input_dev, KEY_BACK, 0); input_report_key(touchkey->input_dev,
touchkey->keycodes[i], 0);
} else { } else {
input_report_key(touchkey->input_dev, key, 1); input_report_key(touchkey->input_dev,
touchkey->keycodes[index], 1);
} }
input_sync(touchkey->input_dev); input_sync(touchkey->input_dev);
...@@ -153,8 +145,10 @@ static irqreturn_t tm2_touchkey_irq_handler(int irq, void *devid) ...@@ -153,8 +145,10 @@ static irqreturn_t tm2_touchkey_irq_handler(int irq, void *devid)
static int tm2_touchkey_probe(struct i2c_client *client, static int tm2_touchkey_probe(struct i2c_client *client,
const struct i2c_device_id *id) const struct i2c_device_id *id)
{ {
struct device_node *np = client->dev.of_node;
struct tm2_touchkey_data *touchkey; struct tm2_touchkey_data *touchkey;
int error; int error;
int i;
if (!i2c_check_functionality(client->adapter, if (!i2c_check_functionality(client->adapter,
I2C_FUNC_SMBUS_BYTE | I2C_FUNC_SMBUS_BYTE_DATA)) { I2C_FUNC_SMBUS_BYTE | I2C_FUNC_SMBUS_BYTE_DATA)) {
...@@ -184,6 +178,16 @@ static int tm2_touchkey_probe(struct i2c_client *client, ...@@ -184,6 +178,16 @@ static int tm2_touchkey_probe(struct i2c_client *client,
/* Save VDD for easy access */ /* Save VDD for easy access */
touchkey->vdd = touchkey->regulators[1].consumer; touchkey->vdd = touchkey->regulators[1].consumer;
touchkey->num_keycodes = of_property_read_variable_u32_array(np,
"linux,keycodes", touchkey->keycodes, 0,
ARRAY_SIZE(touchkey->keycodes));
if (touchkey->num_keycodes <= 0) {
/* default keycodes */
touchkey->keycodes[0] = KEY_PHONE;
touchkey->keycodes[1] = KEY_BACK;
touchkey->num_keycodes = 2;
}
error = tm2_touchkey_power_enable(touchkey); error = tm2_touchkey_power_enable(touchkey);
if (error) { if (error) {
dev_err(&client->dev, "failed to power up device: %d\n", error); dev_err(&client->dev, "failed to power up device: %d\n", error);
...@@ -208,8 +212,9 @@ static int tm2_touchkey_probe(struct i2c_client *client, ...@@ -208,8 +212,9 @@ static int tm2_touchkey_probe(struct i2c_client *client,
touchkey->input_dev->name = TM2_TOUCHKEY_DEV_NAME; touchkey->input_dev->name = TM2_TOUCHKEY_DEV_NAME;
touchkey->input_dev->id.bustype = BUS_I2C; touchkey->input_dev->id.bustype = BUS_I2C;
input_set_capability(touchkey->input_dev, EV_KEY, KEY_PHONE); for (i = 0; i < touchkey->num_keycodes; i++)
input_set_capability(touchkey->input_dev, EV_KEY, KEY_BACK); input_set_capability(touchkey->input_dev, EV_KEY,
touchkey->keycodes[i]);
error = input_register_device(touchkey->input_dev); error = input_register_device(touchkey->input_dev);
if (error) { if (error) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment