This patches adds support for Aries (Samsung i9000) and Midsa (Samsung S3)
based devices to TM2 Touchkey driver.
Jonathan Bakker (6):
Input: tm2-touchkey: Use predefined device name
Input: tm2-touchkey: Correct initial brightness
Input: tm2-touchkey: Allow specifying custom keycodes
Input: dt-bindings: tm2-touchkey: Document new keycodes property
Input: tm2-touchkey: Add support for aries touchkey variant
Input: dt-bindings: tm2-touchkey: Add support for aries touchkey
Simon Shields (2):
Input: tm2-touchkey: Add support for midas touchkey
Input: dt-bindings: tm2-touchkey: Add support for midas touchkey
.../bindings/input/cypress,tm2-touchkey.txt | 9 +-
drivers/input/keyboard/tm2-touchkey.c | 149 +++++++++++++-----
2 files changed, 121 insertions(+), 37 deletions(-)
--
2.17.1
From: Jonathan Bakker <[email protected]>
Purely a cosmetic fix, using the names defined earlier
Signed-off-by: Jonathan Bakker <[email protected]>
Signed-off-by: Paweł Chmiel <[email protected]>
---
drivers/input/keyboard/tm2-touchkey.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/input/keyboard/tm2-touchkey.c b/drivers/input/keyboard/tm2-touchkey.c
index 37a5ced24009..cc713b901bf2 100644
--- a/drivers/input/keyboard/tm2-touchkey.c
+++ b/drivers/input/keyboard/tm2-touchkey.c
@@ -57,13 +57,13 @@ struct tm2_touchkey_data {
};
static struct touchkey_variant tm2_touchkey_variant = {
- .name = "tm2-touchkey",
+ .name = TM2_TOUCHKEY_DEV_NAME,
.keycode_reg = 0x03,
.base_reg = 0x00,
};
static struct touchkey_variant midas_touchkey_variant = {
- .name = "midas-touchkey",
+ .name = MIDAS_TOUCHKEY_DEV_NAME,
.keycode_reg = 0x00,
.base_reg = 0x00,
};
--
2.17.1
From: Jonathan Bakker <[email protected]>
Document compatible for aries touchkey.
Signed-off-by: Jonathan Bakker <[email protected]>
Signed-off-by: Paweł Chmiel <[email protected]>
---
Documentation/devicetree/bindings/input/cypress,tm2-touchkey.txt | 1 +
1 file changed, 1 insertion(+)
diff --git a/Documentation/devicetree/bindings/input/cypress,tm2-touchkey.txt b/Documentation/devicetree/bindings/input/cypress,tm2-touchkey.txt
index 3b54d997b8de..c518125d16f5 100644
--- a/Documentation/devicetree/bindings/input/cypress,tm2-touchkey.txt
+++ b/Documentation/devicetree/bindings/input/cypress,tm2-touchkey.txt
@@ -4,6 +4,7 @@ Required properties:
- compatible:
* "cypress,tm2-touchkey" - for the touchkey found on the tm2 board
* "cypress,midas-touchkey" - for the touchkey found on midas boards
+ * "cypress,aries-touchkey" - for the touchkey found on aries boards
- reg: I2C address of the chip.
- interrupts: interrupt to which the chip is connected (see interrupt
binding[0]).
--
2.17.1
From: Jonathan Bakker <[email protected]>
The touchkey variant found on aries board is slighty different,
it uses a fixed regulator and writes/read to the same place
Signed-off-by: Jonathan Bakker <[email protected]>
Signed-off-by: Paweł Chmiel <[email protected]>
---
drivers/input/keyboard/tm2-touchkey.c | 56 +++++++++++++++++++++++----
1 file changed, 49 insertions(+), 7 deletions(-)
diff --git a/drivers/input/keyboard/tm2-touchkey.c b/drivers/input/keyboard/tm2-touchkey.c
index ebc275ab8ad1..6f1235183c21 100644
--- a/drivers/input/keyboard/tm2-touchkey.c
+++ b/drivers/input/keyboard/tm2-touchkey.c
@@ -28,7 +28,10 @@
#define TM2_TOUCHKEY_DEV_NAME "tm2-touchkey"
#define MIDAS_TOUCHKEY_DEV_NAME "midas-touchkey"
+#define ARIES_TOUCHKEY_DEV_NAME "aries-touchkey"
+#define ARIES_TOUCHKEY_CMD_LED_ON 0x1
+#define ARIES_TOUCHKEY_CMD_LED_OFF 0x2
#define TM2_TOUCHKEY_CMD_LED_ON 0x10
#define TM2_TOUCHKEY_CMD_LED_OFF 0x20
#define TM2_TOUCHKEY_BIT_PRESS_EV BIT(3)
@@ -40,6 +43,10 @@ struct touchkey_variant {
const char *name;
u8 keycode_reg;
u8 base_reg;
+ u8 cmd_led_on;
+ u8 cmd_led_off;
+ bool no_reg;
+ bool fixed_regulator;
};
struct tm2_touchkey_data {
@@ -57,12 +64,24 @@ static struct touchkey_variant tm2_touchkey_variant = {
.name = TM2_TOUCHKEY_DEV_NAME,
.keycode_reg = 0x03,
.base_reg = 0x00,
+ .cmd_led_on = TM2_TOUCHKEY_CMD_LED_ON,
+ .cmd_led_off = TM2_TOUCHKEY_CMD_LED_OFF,
};
static struct touchkey_variant midas_touchkey_variant = {
.name = MIDAS_TOUCHKEY_DEV_NAME,
.keycode_reg = 0x00,
.base_reg = 0x00,
+ .cmd_led_on = TM2_TOUCHKEY_CMD_LED_ON,
+ .cmd_led_off = TM2_TOUCHKEY_CMD_LED_OFF,
+};
+
+static struct touchkey_variant aries_touchkey_variant = {
+ .name = ARIES_TOUCHKEY_DEV_NAME,
+ .no_reg = true,
+ .fixed_regulator = true,
+ .cmd_led_on = ARIES_TOUCHKEY_CMD_LED_ON,
+ .cmd_led_off = ARIES_TOUCHKEY_CMD_LED_OFF,
};
static void tm2_touchkey_led_brightness_set(struct led_classdev *led_dev,
@@ -75,15 +94,20 @@ static void tm2_touchkey_led_brightness_set(struct led_classdev *led_dev,
if (brightness == LED_OFF) {
volt = TM2_TOUCHKEY_LED_VOLTAGE_MIN;
- data = TM2_TOUCHKEY_CMD_LED_OFF;
+ data = touchkey->variant->cmd_led_off;
} else {
volt = TM2_TOUCHKEY_LED_VOLTAGE_MAX;
- data = TM2_TOUCHKEY_CMD_LED_ON;
+ data = touchkey->variant->cmd_led_on;
}
- regulator_set_voltage(touchkey->vdd, volt, volt);
- i2c_smbus_write_byte_data(touchkey->client,
- touchkey->variant->base_reg, data);
+ if (!touchkey->variant->fixed_regulator)
+ regulator_set_voltage(touchkey->vdd, volt, volt);
+
+ if (touchkey->variant->no_reg)
+ i2c_smbus_write_byte(touchkey->client, data);
+ else
+ i2c_smbus_write_byte_data(touchkey->client,
+ touchkey->variant->base_reg, data);
}
static int tm2_touchkey_power_enable(struct tm2_touchkey_data *touchkey)
@@ -116,8 +140,11 @@ static irqreturn_t tm2_touchkey_irq_handler(int irq, void *devid)
int index;
int i;
- data = i2c_smbus_read_byte_data(touchkey->client,
- touchkey->variant->keycode_reg);
+ if (touchkey->variant->no_reg)
+ data = i2c_smbus_read_byte(touchkey->client);
+ else
+ data = i2c_smbus_read_byte_data(touchkey->client,
+ touchkey->variant->keycode_reg);
if (data < 0) {
dev_err(&touchkey->client->dev,
"failed to read i2c data: %d\n", data);
@@ -143,6 +170,14 @@ static irqreturn_t tm2_touchkey_irq_handler(int irq, void *devid)
input_sync(touchkey->input_dev);
out:
+ if (touchkey->variant->fixed_regulator &&
+ data & TM2_TOUCHKEY_BIT_PRESS_EV) {
+ /* touch turns backlight on, so make sure we're in sync */
+ if (touchkey->led_dev.brightness == LED_OFF)
+ tm2_touchkey_led_brightness_set(&touchkey->led_dev,
+ LED_OFF);
+ }
+
return IRQ_HANDLED;
}
@@ -251,6 +286,9 @@ static int tm2_touchkey_probe(struct i2c_client *client,
return error;
}
+ if (touchkey->variant->fixed_regulator)
+ tm2_touchkey_led_brightness_set(&touchkey->led_dev, LED_ON);
+
return 0;
}
@@ -286,6 +324,7 @@ static SIMPLE_DEV_PM_OPS(tm2_touchkey_pm_ops,
static const struct i2c_device_id tm2_touchkey_id_table[] = {
{ TM2_TOUCHKEY_DEV_NAME, 0 },
{ MIDAS_TOUCHKEY_DEV_NAME, 0 },
+ { ARIES_TOUCHKEY_DEV_NAME, 0 },
{ },
};
MODULE_DEVICE_TABLE(i2c, tm2_touchkey_id_table);
@@ -297,6 +336,9 @@ static const struct of_device_id tm2_touchkey_of_match[] = {
}, {
.compatible = "cypress,midas-touchkey",
.data = &midas_touchkey_variant,
+ }, {
+ .compatible = "cypress,aries-touchkey",
+ .data = &aries_touchkey_variant,
},
{ },
};
--
2.17.1
From: Jonathan Bakker <[email protected]>
Document new optional property for setting custom keycodes.
Signed-off-by: Jonathan Bakker <[email protected]>
Signed-off-by: Paweł Chmiel <[email protected]>
---
.../devicetree/bindings/input/cypress,tm2-touchkey.txt | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/Documentation/devicetree/bindings/input/cypress,tm2-touchkey.txt b/Documentation/devicetree/bindings/input/cypress,tm2-touchkey.txt
index dfb3b9f0ee40..3b54d997b8de 100644
--- a/Documentation/devicetree/bindings/input/cypress,tm2-touchkey.txt
+++ b/Documentation/devicetree/bindings/input/cypress,tm2-touchkey.txt
@@ -10,6 +10,9 @@ Required properties:
- vcc-supply : internal regulator output. 1.8V
- vdd-supply : power supply for IC 3.3V
+Optional properties:
+- keycodes: array of keycodes (max 4), default KEY_PHONE and KEY_BACK
+
[0]: Documentation/devicetree/bindings/interrupt-controller/interrupts.txt
Example:
@@ -23,5 +26,6 @@ Example:
interrupts = <2 IRQ_TYPE_EDGE_FALLING>;
vcc-supply=<&ldo32_reg>;
vdd-supply=<&ldo33_reg>;
+ keycodes = /bits/ 8 <KEY_PHONE KEY_BACK>;
};
};
--
2.17.1
From: Jonathan Bakker <[email protected]>
Not all devices use the same keycodes in the same order
Signed-off-by: Jonathan Bakker <[email protected]>
Signed-off-by: Paweł Chmiel <[email protected]>
---
drivers/input/keyboard/tm2-touchkey.c | 49 +++++++++++++++------------
1 file changed, 27 insertions(+), 22 deletions(-)
diff --git a/drivers/input/keyboard/tm2-touchkey.c b/drivers/input/keyboard/tm2-touchkey.c
index a73894b8dede..ebc275ab8ad1 100644
--- a/drivers/input/keyboard/tm2-touchkey.c
+++ b/drivers/input/keyboard/tm2-touchkey.c
@@ -36,11 +36,6 @@
#define TM2_TOUCHKEY_LED_VOLTAGE_MIN 2500000
#define TM2_TOUCHKEY_LED_VOLTAGE_MAX 3300000
-enum {
- TM2_TOUCHKEY_KEY_MENU = 0x1,
- TM2_TOUCHKEY_KEY_BACK,
-};
-
struct touchkey_variant {
const char *name;
u8 keycode_reg;
@@ -54,6 +49,8 @@ struct tm2_touchkey_data {
struct regulator *vdd;
struct regulator_bulk_data regulators[2];
struct touchkey_variant *variant;
+ u8 keycodes[4];
+ int num_keycodes;
};
static struct touchkey_variant tm2_touchkey_variant = {
@@ -116,7 +113,8 @@ static irqreturn_t tm2_touchkey_irq_handler(int irq, void *devid)
{
struct tm2_touchkey_data *touchkey = devid;
int data;
- int key;
+ int index;
+ int i;
data = i2c_smbus_read_byte_data(touchkey->client,
touchkey->variant->keycode_reg);
@@ -126,26 +124,20 @@ static irqreturn_t tm2_touchkey_irq_handler(int irq, void *devid)
goto out;
}
- switch (data & TM2_TOUCHKEY_BIT_KEYCODE) {
- case TM2_TOUCHKEY_KEY_MENU:
- key = KEY_PHONE;
- break;
-
- case TM2_TOUCHKEY_KEY_BACK:
- key = KEY_BACK;
- break;
-
- default:
+ index = (data & TM2_TOUCHKEY_BIT_KEYCODE) - 1;
+ if (index < 0 || index >= touchkey->num_keycodes) {
dev_warn(&touchkey->client->dev,
- "unhandled keycode, data %#02x\n", data);
+ "invalid keycode index %d\n", index);
goto out;
}
if (data & TM2_TOUCHKEY_BIT_PRESS_EV) {
- input_report_key(touchkey->input_dev, KEY_PHONE, 0);
- input_report_key(touchkey->input_dev, KEY_BACK, 0);
+ for (i = 0; i < touchkey->num_keycodes; i++)
+ input_report_key(touchkey->input_dev,
+ touchkey->keycodes[i], 0);
} else {
- input_report_key(touchkey->input_dev, key, 1);
+ input_report_key(touchkey->input_dev,
+ touchkey->keycodes[index], 1);
}
input_sync(touchkey->input_dev);
@@ -157,8 +149,10 @@ static irqreturn_t tm2_touchkey_irq_handler(int irq, void *devid)
static int tm2_touchkey_probe(struct i2c_client *client,
const struct i2c_device_id *id)
{
+ struct device_node *np = client->dev.of_node;
struct tm2_touchkey_data *touchkey;
int error;
+ int i;
if (!i2c_check_functionality(client->adapter,
I2C_FUNC_SMBUS_BYTE | I2C_FUNC_SMBUS_BYTE_DATA)) {
@@ -189,6 +183,16 @@ static int tm2_touchkey_probe(struct i2c_client *client,
/* Save VDD for easy access */
touchkey->vdd = touchkey->regulators[1].consumer;
+ touchkey->num_keycodes = of_property_read_variable_u8_array(np,
+ "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);
if (error) {
dev_err(&client->dev, "failed to power up device: %d\n", error);
@@ -213,8 +217,9 @@ static int tm2_touchkey_probe(struct i2c_client *client,
touchkey->input_dev->name = touchkey->variant->name;
touchkey->input_dev->id.bustype = BUS_I2C;
- input_set_capability(touchkey->input_dev, EV_KEY, KEY_PHONE);
- input_set_capability(touchkey->input_dev, EV_KEY, KEY_BACK);
+ for (i = 0; i < touchkey->num_keycodes; i++)
+ input_set_capability(touchkey->input_dev, EV_KEY,
+ touchkey->keycodes[i]);
error = input_register_device(touchkey->input_dev);
if (error) {
--
2.17.1
From: Jonathan Bakker <[email protected]>
Tm2-touchkey don't have brightness levels, but only on/off states,
so replace LED_FULL with LED_ON.
Signed-off-by: Jonathan Bakker <[email protected]>
Signed-off-by: Paweł Chmiel <[email protected]>
---
drivers/input/keyboard/tm2-touchkey.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/input/keyboard/tm2-touchkey.c b/drivers/input/keyboard/tm2-touchkey.c
index cc713b901bf2..a73894b8dede 100644
--- a/drivers/input/keyboard/tm2-touchkey.c
+++ b/drivers/input/keyboard/tm2-touchkey.c
@@ -235,7 +235,7 @@ static int tm2_touchkey_probe(struct i2c_client *client,
/* led device */
touchkey->led_dev.name = touchkey->variant->name;
- touchkey->led_dev.brightness = LED_FULL;
+ touchkey->led_dev.brightness = LED_ON;
touchkey->led_dev.max_brightness = LED_ON;
touchkey->led_dev.brightness_set = tm2_touchkey_led_brightness_set;
--
2.17.1
From: Simon Shields <[email protected]>
The touchkey on midas boards is almost identical.
The only real difference is that it uses the same register for both
keycode and base.
Signed-off-by: Simon Shields <[email protected]>
Signed-off-by: Paweł Chmiel <[email protected]>
---
drivers/input/keyboard/tm2-touchkey.c | 48 ++++++++++++++++++++++-----
1 file changed, 39 insertions(+), 9 deletions(-)
diff --git a/drivers/input/keyboard/tm2-touchkey.c b/drivers/input/keyboard/tm2-touchkey.c
index abc266e40e17..37a5ced24009 100644
--- a/drivers/input/keyboard/tm2-touchkey.c
+++ b/drivers/input/keyboard/tm2-touchkey.c
@@ -22,12 +22,13 @@
#include <linux/leds.h>
#include <linux/module.h>
#include <linux/of.h>
+#include <linux/of_device.h>
#include <linux/pm.h>
#include <linux/regulator/consumer.h>
-#define TM2_TOUCHKEY_DEV_NAME "tm2-touchkey"
-#define TM2_TOUCHKEY_KEYCODE_REG 0x03
-#define TM2_TOUCHKEY_BASE_REG 0x00
+#define TM2_TOUCHKEY_DEV_NAME "tm2-touchkey"
+#define MIDAS_TOUCHKEY_DEV_NAME "midas-touchkey"
+
#define TM2_TOUCHKEY_CMD_LED_ON 0x10
#define TM2_TOUCHKEY_CMD_LED_OFF 0x20
#define TM2_TOUCHKEY_BIT_PRESS_EV BIT(3)
@@ -40,12 +41,31 @@ enum {
TM2_TOUCHKEY_KEY_BACK,
};
+struct touchkey_variant {
+ const char *name;
+ u8 keycode_reg;
+ u8 base_reg;
+};
+
struct tm2_touchkey_data {
struct i2c_client *client;
struct input_dev *input_dev;
struct led_classdev led_dev;
struct regulator *vdd;
struct regulator_bulk_data regulators[2];
+ struct touchkey_variant *variant;
+};
+
+static struct touchkey_variant tm2_touchkey_variant = {
+ .name = "tm2-touchkey",
+ .keycode_reg = 0x03,
+ .base_reg = 0x00,
+};
+
+static struct touchkey_variant midas_touchkey_variant = {
+ .name = "midas-touchkey",
+ .keycode_reg = 0x00,
+ .base_reg = 0x00,
};
static void tm2_touchkey_led_brightness_set(struct led_classdev *led_dev,
@@ -66,7 +86,7 @@ static void tm2_touchkey_led_brightness_set(struct led_classdev *led_dev,
regulator_set_voltage(touchkey->vdd, volt, volt);
i2c_smbus_write_byte_data(touchkey->client,
- TM2_TOUCHKEY_BASE_REG, data);
+ touchkey->variant->base_reg, data);
}
static int tm2_touchkey_power_enable(struct tm2_touchkey_data *touchkey)
@@ -99,7 +119,7 @@ static irqreturn_t tm2_touchkey_irq_handler(int irq, void *devid)
int key;
data = i2c_smbus_read_byte_data(touchkey->client,
- TM2_TOUCHKEY_KEYCODE_REG);
+ touchkey->variant->keycode_reg);
if (data < 0) {
dev_err(&touchkey->client->dev,
"failed to read i2c data: %d\n", data);
@@ -153,6 +173,9 @@ static int tm2_touchkey_probe(struct i2c_client *client,
touchkey->client = client;
i2c_set_clientdata(client, touchkey);
+ touchkey->variant = (struct touchkey_variant *)
+ of_device_get_match_data(&client->dev);
+
touchkey->regulators[0].supply = "vcc";
touchkey->regulators[1].supply = "vdd";
error = devm_regulator_bulk_get(&client->dev,
@@ -187,7 +210,7 @@ static int tm2_touchkey_probe(struct i2c_client *client,
return -ENOMEM;
}
- touchkey->input_dev->name = TM2_TOUCHKEY_DEV_NAME;
+ touchkey->input_dev->name = touchkey->variant->name;
touchkey->input_dev->id.bustype = BUS_I2C;
input_set_capability(touchkey->input_dev, EV_KEY, KEY_PHONE);
@@ -203,7 +226,7 @@ static int tm2_touchkey_probe(struct i2c_client *client,
error = devm_request_threaded_irq(&client->dev, client->irq,
NULL, tm2_touchkey_irq_handler,
IRQF_ONESHOT,
- TM2_TOUCHKEY_DEV_NAME, touchkey);
+ touchkey->variant->name, touchkey);
if (error) {
dev_err(&client->dev,
"failed to request threaded irq: %d\n", error);
@@ -211,7 +234,7 @@ static int tm2_touchkey_probe(struct i2c_client *client,
}
/* led device */
- touchkey->led_dev.name = TM2_TOUCHKEY_DEV_NAME;
+ touchkey->led_dev.name = touchkey->variant->name;
touchkey->led_dev.brightness = LED_FULL;
touchkey->led_dev.max_brightness = LED_ON;
touchkey->led_dev.brightness_set = tm2_touchkey_led_brightness_set;
@@ -257,12 +280,19 @@ static SIMPLE_DEV_PM_OPS(tm2_touchkey_pm_ops,
static const struct i2c_device_id tm2_touchkey_id_table[] = {
{ TM2_TOUCHKEY_DEV_NAME, 0 },
+ { MIDAS_TOUCHKEY_DEV_NAME, 0 },
{ },
};
MODULE_DEVICE_TABLE(i2c, tm2_touchkey_id_table);
static const struct of_device_id tm2_touchkey_of_match[] = {
- { .compatible = "cypress,tm2-touchkey", },
+ {
+ .compatible = "cypress,tm2-touchkey",
+ .data = &tm2_touchkey_variant,
+ }, {
+ .compatible = "cypress,midas-touchkey",
+ .data = &midas_touchkey_variant,
+ },
{ },
};
MODULE_DEVICE_TABLE(of, tm2_touchkey_of_match);
--
2.17.1
From: Simon Shields <[email protected]>
Document compatible for midas touchkey.
Signed-off-by: Simon Shields <[email protected]>
Signed-off-by: Paweł Chmiel <[email protected]>
---
.../devicetree/bindings/input/cypress,tm2-touchkey.txt | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/Documentation/devicetree/bindings/input/cypress,tm2-touchkey.txt b/Documentation/devicetree/bindings/input/cypress,tm2-touchkey.txt
index 0c252d9306da..dfb3b9f0ee40 100644
--- a/Documentation/devicetree/bindings/input/cypress,tm2-touchkey.txt
+++ b/Documentation/devicetree/bindings/input/cypress,tm2-touchkey.txt
@@ -1,7 +1,9 @@
Samsung tm2-touchkey
Required properties:
-- compatible: must be "cypress,tm2-touchkey"
+- compatible:
+ * "cypress,tm2-touchkey" - for the touchkey found on the tm2 board
+ * "cypress,midas-touchkey" - for the touchkey found on midas boards
- reg: I2C address of the chip.
- interrupts: interrupt to which the chip is connected (see interrupt
binding[0]).
--
2.17.1
Hi Paweł,
On Fri, Dec 07, 2018 at 11:58:04AM +0100, Paweł Chmiel wrote:
> From: Simon Shields <[email protected]>
>
> The touchkey on midas boards is almost identical.
> The only real difference is that it uses the same register for both
> keycode and base.
>
> Signed-off-by: Simon Shields <[email protected]>
> Signed-off-by: Paweł Chmiel <[email protected]>
> ---
> drivers/input/keyboard/tm2-touchkey.c | 48 ++++++++++++++++++++++-----
> 1 file changed, 39 insertions(+), 9 deletions(-)
>
> diff --git a/drivers/input/keyboard/tm2-touchkey.c b/drivers/input/keyboard/tm2-touchkey.c
> index abc266e40e17..37a5ced24009 100644
> --- a/drivers/input/keyboard/tm2-touchkey.c
> +++ b/drivers/input/keyboard/tm2-touchkey.c
> @@ -22,12 +22,13 @@
> #include <linux/leds.h>
> #include <linux/module.h>
> #include <linux/of.h>
> +#include <linux/of_device.h>
> #include <linux/pm.h>
> #include <linux/regulator/consumer.h>
>
> -#define TM2_TOUCHKEY_DEV_NAME "tm2-touchkey"
> -#define TM2_TOUCHKEY_KEYCODE_REG 0x03
> -#define TM2_TOUCHKEY_BASE_REG 0x00
> +#define TM2_TOUCHKEY_DEV_NAME "tm2-touchkey"
> +#define MIDAS_TOUCHKEY_DEV_NAME "midas-touchkey"
I am not sure why we need to bother with name changes... We can get to
compatible if it is that interesting, but other than that it seems
only complicate things. Also, you use MIDAS_TOUCHKEY_DEV_NAME in only
one place and open-code it in others.
> +
> #define TM2_TOUCHKEY_CMD_LED_ON 0x10
> #define TM2_TOUCHKEY_CMD_LED_OFF 0x20
> #define TM2_TOUCHKEY_BIT_PRESS_EV BIT(3)
> @@ -40,12 +41,31 @@ enum {
> TM2_TOUCHKEY_KEY_BACK,
> };
>
> +struct touchkey_variant {
> + const char *name;
> + u8 keycode_reg;
> + u8 base_reg;
> +};
> +
> struct tm2_touchkey_data {
> struct i2c_client *client;
> struct input_dev *input_dev;
> struct led_classdev led_dev;
> struct regulator *vdd;
> struct regulator_bulk_data regulators[2];
> + struct touchkey_variant *variant;
const struct touchkey_variant *variant;
> +};
> +
> +static struct touchkey_variant tm2_touchkey_variant = {
static const
> + .name = "tm2-touchkey",
> + .keycode_reg = 0x03,
> + .base_reg = 0x00,
> +};
> +
> +static struct touchkey_variant midas_touchkey_variant = {
static const
> + .name = "midas-touchkey",
> + .keycode_reg = 0x00,
> + .base_reg = 0x00,
> };
>
> static void tm2_touchkey_led_brightness_set(struct led_classdev *led_dev,
> @@ -66,7 +86,7 @@ static void tm2_touchkey_led_brightness_set(struct led_classdev *led_dev,
>
> regulator_set_voltage(touchkey->vdd, volt, volt);
> i2c_smbus_write_byte_data(touchkey->client,
> - TM2_TOUCHKEY_BASE_REG, data);
> + touchkey->variant->base_reg, data);
> }
>
> static int tm2_touchkey_power_enable(struct tm2_touchkey_data *touchkey)
> @@ -99,7 +119,7 @@ static irqreturn_t tm2_touchkey_irq_handler(int irq, void *devid)
> int key;
>
> data = i2c_smbus_read_byte_data(touchkey->client,
> - TM2_TOUCHKEY_KEYCODE_REG);
> + touchkey->variant->keycode_reg);
> if (data < 0) {
> dev_err(&touchkey->client->dev,
> "failed to read i2c data: %d\n", data);
> @@ -153,6 +173,9 @@ static int tm2_touchkey_probe(struct i2c_client *client,
> touchkey->client = client;
> i2c_set_clientdata(client, touchkey);
>
> + touchkey->variant = (struct touchkey_variant *)
Is cast really needed?
> + of_device_get_match_data(&client->dev);
> +
> touchkey->regulators[0].supply = "vcc";
> touchkey->regulators[1].supply = "vdd";
> error = devm_regulator_bulk_get(&client->dev,
> @@ -187,7 +210,7 @@ static int tm2_touchkey_probe(struct i2c_client *client,
> return -ENOMEM;
> }
>
> - touchkey->input_dev->name = TM2_TOUCHKEY_DEV_NAME;
> + touchkey->input_dev->name = touchkey->variant->name;
> touchkey->input_dev->id.bustype = BUS_I2C;
>
> input_set_capability(touchkey->input_dev, EV_KEY, KEY_PHONE);
> @@ -203,7 +226,7 @@ static int tm2_touchkey_probe(struct i2c_client *client,
> error = devm_request_threaded_irq(&client->dev, client->irq,
> NULL, tm2_touchkey_irq_handler,
> IRQF_ONESHOT,
> - TM2_TOUCHKEY_DEV_NAME, touchkey);
> + touchkey->variant->name, touchkey);
> if (error) {
> dev_err(&client->dev,
> "failed to request threaded irq: %d\n", error);
> @@ -211,7 +234,7 @@ static int tm2_touchkey_probe(struct i2c_client *client,
> }
>
> /* led device */
> - touchkey->led_dev.name = TM2_TOUCHKEY_DEV_NAME;
> + touchkey->led_dev.name = touchkey->variant->name;
> touchkey->led_dev.brightness = LED_FULL;
> touchkey->led_dev.max_brightness = LED_ON;
> touchkey->led_dev.brightness_set = tm2_touchkey_led_brightness_set;
> @@ -257,12 +280,19 @@ static SIMPLE_DEV_PM_OPS(tm2_touchkey_pm_ops,
>
> static const struct i2c_device_id tm2_touchkey_id_table[] = {
> { TM2_TOUCHKEY_DEV_NAME, 0 },
> + { MIDAS_TOUCHKEY_DEV_NAME, 0 },
> { },
> };
> MODULE_DEVICE_TABLE(i2c, tm2_touchkey_id_table);
>
> static const struct of_device_id tm2_touchkey_of_match[] = {
> - { .compatible = "cypress,tm2-touchkey", },
> + {
> + .compatible = "cypress,tm2-touchkey",
> + .data = &tm2_touchkey_variant,
> + }, {
> + .compatible = "cypress,midas-touchkey",
> + .data = &midas_touchkey_variant,
> + },
> { },
> };
> MODULE_DEVICE_TABLE(of, tm2_touchkey_of_match);
> --
> 2.17.1
>
Thanks.
--
Dmitry
On Fri, Dec 07, 2018 at 11:58:06AM +0100, Paweł Chmiel wrote:
> From: Jonathan Bakker <[email protected]>
>
> Purely a cosmetic fix, using the names defined earlier
If we decide to keep different names please fold into first patch.
>
> Signed-off-by: Jonathan Bakker <[email protected]>
> Signed-off-by: Paweł Chmiel <[email protected]>
> ---
> drivers/input/keyboard/tm2-touchkey.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/input/keyboard/tm2-touchkey.c b/drivers/input/keyboard/tm2-touchkey.c
> index 37a5ced24009..cc713b901bf2 100644
> --- a/drivers/input/keyboard/tm2-touchkey.c
> +++ b/drivers/input/keyboard/tm2-touchkey.c
> @@ -57,13 +57,13 @@ struct tm2_touchkey_data {
> };
>
> static struct touchkey_variant tm2_touchkey_variant = {
> - .name = "tm2-touchkey",
> + .name = TM2_TOUCHKEY_DEV_NAME,
> .keycode_reg = 0x03,
> .base_reg = 0x00,
> };
>
> static struct touchkey_variant midas_touchkey_variant = {
> - .name = "midas-touchkey",
> + .name = MIDAS_TOUCHKEY_DEV_NAME,
> .keycode_reg = 0x00,
> .base_reg = 0x00,
> };
> --
> 2.17.1
>
--
Dmitry
On Fri, Dec 07, 2018 at 11:58:09AM +0100, Paweł Chmiel wrote:
> From: Jonathan Bakker <[email protected]>
>
> Document new optional property for setting custom keycodes.
>
> Signed-off-by: Jonathan Bakker <[email protected]>
> Signed-off-by: Paweł Chmiel <[email protected]>
> ---
> .../devicetree/bindings/input/cypress,tm2-touchkey.txt | 4 ++++
> 1 file changed, 4 insertions(+)
>
> diff --git a/Documentation/devicetree/bindings/input/cypress,tm2-touchkey.txt b/Documentation/devicetree/bindings/input/cypress,tm2-touchkey.txt
> index dfb3b9f0ee40..3b54d997b8de 100644
> --- a/Documentation/devicetree/bindings/input/cypress,tm2-touchkey.txt
> +++ b/Documentation/devicetree/bindings/input/cypress,tm2-touchkey.txt
> @@ -10,6 +10,9 @@ Required properties:
> - vcc-supply : internal regulator output. 1.8V
> - vdd-supply : power supply for IC 3.3V
>
> +Optional properties:
> +- keycodes: array of keycodes (max 4), default KEY_PHONE and KEY_BACK
> +
> [0]: Documentation/devicetree/bindings/interrupt-controller/interrupts.txt
>
> Example:
> @@ -23,5 +26,6 @@ Example:
> interrupts = <2 IRQ_TYPE_EDGE_FALLING>;
> vcc-supply=<&ldo32_reg>;
> vdd-supply=<&ldo33_reg>;
> + keycodes = /bits/ 8 <KEY_PHONE KEY_BACK>;
We definitely have key codes bigger than 255. Just keep them normal
ints please.
> };
> };
> --
> 2.17.1
>
--
Dmitry
On Fri, 7 Dec 2018 11:58:11 +0100, =?UTF-8?q?Pawe=C5=82=20Chmiel?= wrote:
> From: Jonathan Bakker <[email protected]>
>
> Document compatible for aries touchkey.
>
> Signed-off-by: Jonathan Bakker <[email protected]>
> Signed-off-by: Paweł Chmiel <[email protected]>
> ---
> Documentation/devicetree/bindings/input/cypress,tm2-touchkey.txt | 1 +
> 1 file changed, 1 insertion(+)
>
Reviewed-by: Rob Herring <[email protected]>
On Fri, 7 Dec 2018 11:58:05 +0100, =?UTF-8?q?Pawe=C5=82=20Chmiel?= wrote:
> From: Simon Shields <[email protected]>
>
> Document compatible for midas touchkey.
>
> Signed-off-by: Simon Shields <[email protected]>
> Signed-off-by: Paweł Chmiel <[email protected]>
> ---
> .../devicetree/bindings/input/cypress,tm2-touchkey.txt | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
>
Reviewed-by: Rob Herring <[email protected]>