Merge branch 'next' into for-linus

Prepare input updates for 5.1 merge window.
This commit is contained in:
Dmitry Torokhov
2019-03-03 23:14:44 -08:00
31 changed files with 1203 additions and 367 deletions

View File

@@ -1015,8 +1015,18 @@ static int __maybe_unused gpio_keys_resume(struct device *dev)
static SIMPLE_DEV_PM_OPS(gpio_keys_pm_ops, gpio_keys_suspend, gpio_keys_resume);
static void gpio_keys_shutdown(struct platform_device *pdev)
{
int ret;
ret = gpio_keys_suspend(&pdev->dev);
if (ret)
dev_err(&pdev->dev, "failed to shutdown\n");
}
static struct platform_driver gpio_keys_device_driver = {
.probe = gpio_keys_probe,
.shutdown = gpio_keys_shutdown,
.driver = {
.name = "gpio-keys",
.pm = &gpio_keys_pm_ops,

View File

@@ -113,9 +113,8 @@ static int mcs_touchkey_probe(struct i2c_client *client,
return -EINVAL;
}
data = kzalloc(sizeof(struct mcs_touchkey_data) +
sizeof(data->keycodes[0]) * (pdata->key_maxval + 1),
GFP_KERNEL);
data = kzalloc(struct_size(data, keycodes, pdata->key_maxval + 1),
GFP_KERNEL);
input_dev = input_allocate_device();
if (!data || !input_dev) {
dev_err(&client->dev, "Failed to allocate memory\n");

View File

@@ -14,18 +14,17 @@
*
*/
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/input.h>
#include <linux/interrupt.h>
#include <linux/platform_device.h>
#include <linux/kernel.h>
#include <linux/of.h>
#include <linux/of_device.h>
#include <linux/regmap.h>
#include <linux/mfd/mt6323/registers.h>
#include <linux/mfd/mt6397/registers.h>
#include <linux/mfd/mt6397/core.h>
#include <linux/mfd/mt6397/registers.h>
#include <linux/module.h>
#include <linux/of_device.h>
#include <linux/of.h>
#include <linux/platform_device.h>
#include <linux/regmap.h>
#define MTK_PMIC_PWRKEY_RST_EN_MASK 0x1
#define MTK_PMIC_PWRKEY_RST_EN_SHIFT 6

View File

@@ -68,7 +68,6 @@ struct qt2160_data {
struct i2c_client *client;
struct input_dev *input;
struct delayed_work dwork;
spinlock_t lock; /* Protects canceling/rescheduling of dwork */
unsigned short keycodes[ARRAY_SIZE(qt2160_key2code)];
u16 key_matrix;
#ifdef CONFIG_LEDS_CLASS
@@ -212,22 +211,15 @@ static int qt2160_get_key_matrix(struct qt2160_data *qt2160)
static irqreturn_t qt2160_irq(int irq, void *_qt2160)
{
struct qt2160_data *qt2160 = _qt2160;
unsigned long flags;
spin_lock_irqsave(&qt2160->lock, flags);
mod_delayed_work(system_wq, &qt2160->dwork, 0);
spin_unlock_irqrestore(&qt2160->lock, flags);
return IRQ_HANDLED;
}
static void qt2160_schedule_read(struct qt2160_data *qt2160)
{
spin_lock_irq(&qt2160->lock);
schedule_delayed_work(&qt2160->dwork, QT2160_CYCLE_INTERVAL);
spin_unlock_irq(&qt2160->lock);
}
static void qt2160_worker(struct work_struct *work)
@@ -391,7 +383,6 @@ static int qt2160_probe(struct i2c_client *client,
qt2160->client = client;
qt2160->input = input;
INIT_DELAYED_WORK(&qt2160->dwork, qt2160_worker);
spin_lock_init(&qt2160->lock);
input->name = "AT42QT2160 Touch Sense Keyboard";
input->id.bustype = BUS_I2C;

View File

@@ -219,9 +219,7 @@ static int tca6416_keypad_probe(struct i2c_client *client,
return -EINVAL;
}
chip = kzalloc(sizeof(struct tca6416_keypad_chip) +
pdata->nbuttons * sizeof(struct tca6416_button),
GFP_KERNEL);
chip = kzalloc(struct_size(chip, buttons, pdata->nbuttons), GFP_KERNEL);
input = input_allocate_device();
if (!chip || !input) {
error = -ENOMEM;

View File

@@ -22,12 +22,14 @@
#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 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)
@@ -35,9 +37,13 @@
#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 {
u8 keycode_reg;
u8 base_reg;
u8 cmd_led_on;
u8 cmd_led_off;
bool no_reg;
bool fixed_regulator;
};
struct tm2_touchkey_data {
@@ -46,9 +52,33 @@ struct tm2_touchkey_data {
struct led_classdev led_dev;
struct regulator *vdd;
struct regulator_bulk_data regulators[2];
const struct touchkey_variant *variant;
u32 keycodes[4];
int num_keycodes;
};
static void tm2_touchkey_led_brightness_set(struct led_classdev *led_dev,
static const struct touchkey_variant tm2_touchkey_variant = {
.keycode_reg = 0x03,
.base_reg = 0x00,
.cmd_led_on = TM2_TOUCHKEY_CMD_LED_ON,
.cmd_led_off = TM2_TOUCHKEY_CMD_LED_OFF,
};
static const struct touchkey_variant midas_touchkey_variant = {
.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 = {
.no_reg = true,
.fixed_regulator = true,
.cmd_led_on = ARIES_TOUCHKEY_CMD_LED_ON,
.cmd_led_off = ARIES_TOUCHKEY_CMD_LED_OFF,
};
static int tm2_touchkey_led_brightness_set(struct led_classdev *led_dev,
enum led_brightness brightness)
{
struct tm2_touchkey_data *touchkey =
@@ -58,15 +88,19 @@ 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,
TM2_TOUCHKEY_BASE_REG, data);
if (!touchkey->variant->fixed_regulator)
regulator_set_voltage(touchkey->vdd, volt, volt);
return touchkey->variant->no_reg ?
i2c_smbus_write_byte(touchkey->client, data) :
i2c_smbus_write_byte_data(touchkey->client,
touchkey->variant->base_reg, data);
}
static int tm2_touchkey_power_enable(struct tm2_touchkey_data *touchkey)
@@ -96,49 +130,57 @@ 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,
TM2_TOUCHKEY_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);
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);
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;
}
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)) {
@@ -153,6 +195,8 @@ static int tm2_touchkey_probe(struct i2c_client *client,
touchkey->client = client;
i2c_set_clientdata(client, touchkey);
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,
@@ -166,6 +210,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_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);
if (error) {
dev_err(&client->dev, "failed to power up device: %d\n", error);
@@ -190,8 +244,9 @@ static int tm2_touchkey_probe(struct i2c_client *client,
touchkey->input_dev->name = TM2_TOUCHKEY_DEV_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) {
@@ -212,9 +267,10 @@ static int tm2_touchkey_probe(struct i2c_client *client,
/* led device */
touchkey->led_dev.name = TM2_TOUCHKEY_DEV_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;
touchkey->led_dev.brightness_set_blocking =
tm2_touchkey_led_brightness_set;
error = devm_led_classdev_register(&client->dev, &touchkey->led_dev);
if (error) {
@@ -223,6 +279,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;
}
@@ -262,7 +321,16 @@ static const struct i2c_device_id tm2_touchkey_id_table[] = {
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,
}, {
.compatible = "cypress,aries-touchkey",
.data = &aries_touchkey_variant,
},
{ },
};
MODULE_DEVICE_TABLE(of, tm2_touchkey_of_match);