summaryrefslogtreecommitdiff
path: root/drivers/input/keyboard
diff options
context:
space:
mode:
authorAkinobu Mita <akinobu.mita@gmail.com>2017-01-15 14:51:12 -0800
committerDmitry Torokhov <dmitry.torokhov@gmail.com>2017-01-15 15:08:46 -0800
commitde901cc31d151c4c855346c29fb61eaf5ffac3ad (patch)
tree1e2f984b9858ab3957dd955b1138b3165fb3a7c5 /drivers/input/keyboard
parent08fea55e37f58371bffc5336a59e55d1f155955a (diff)
Input: mpr121 - switch to device tree probe
This driver currently only supports legacy platform data probe. This change adds device tree support and gets rid of platform data probe code since no one is actually using mpr121 platform data in the mainline. The device tree property parsing code is based on the work of atmel_captouch driver. Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com> Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Diffstat (limited to 'drivers/input/keyboard')
-rw-r--r--drivers/input/keyboard/mpr121_touchkey.c137
1 files changed, 94 insertions, 43 deletions
diff --git a/drivers/input/keyboard/mpr121_touchkey.c b/drivers/input/keyboard/mpr121_touchkey.c
index 83dd5616e470..989ca66f63af 100644
--- a/drivers/input/keyboard/mpr121_touchkey.c
+++ b/drivers/input/keyboard/mpr121_touchkey.c
@@ -12,14 +12,16 @@
*
*/
-#include <linux/module.h>
-#include <linux/input.h>
-#include <linux/i2c.h>
-#include <linux/slab.h>
-#include <linux/delay.h>
#include <linux/bitops.h>
+#include <linux/delay.h>
+#include <linux/i2c.h>
+#include <linux/input.h>
#include <linux/interrupt.h>
-#include <linux/i2c/mpr121_touchkey.h>
+#include <linux/module.h>
+#include <linux/of.h>
+#include <linux/property.h>
+#include <linux/regulator/consumer.h>
+#include <linux/slab.h>
/* Register definitions */
#define ELE_TOUCH_STATUS_0_ADDR 0x0
@@ -61,7 +63,7 @@ struct mpr121_touchkey {
struct input_dev *input_dev;
unsigned int statusbits;
unsigned int keycount;
- u16 keycodes[MPR121_MAX_KEY_COUNT];
+ u32 keycodes[MPR121_MAX_KEY_COUNT];
};
struct mpr121_init_register {
@@ -81,6 +83,42 @@ static const struct mpr121_init_register init_reg_table[] = {
{ AUTO_CONFIG_CTRL_ADDR, 0x0b },
};
+static void mpr121_vdd_supply_disable(void *data)
+{
+ struct regulator *vdd_supply = data;
+
+ regulator_disable(vdd_supply);
+}
+
+static struct regulator *mpr121_vdd_supply_init(struct device *dev)
+{
+ struct regulator *vdd_supply;
+ int err;
+
+ vdd_supply = devm_regulator_get(dev, "vdd");
+ if (IS_ERR(vdd_supply)) {
+ dev_err(dev, "failed to get vdd regulator: %ld\n",
+ PTR_ERR(vdd_supply));
+ return vdd_supply;
+ }
+
+ err = regulator_enable(vdd_supply);
+ if (err) {
+ dev_err(dev, "failed to enable vdd regulator: %d\n", err);
+ return ERR_PTR(err);
+ }
+
+ err = devm_add_action(dev, mpr121_vdd_supply_disable, vdd_supply);
+ if (err) {
+ regulator_disable(vdd_supply);
+ dev_err(dev, "failed to add disable regulator action: %d\n",
+ err);
+ return ERR_PTR(err);
+ }
+
+ return vdd_supply;
+}
+
static irqreturn_t mpr_touchkey_interrupt(int irq, void *dev_id)
{
struct mpr121_touchkey *mpr121 = dev_id;
@@ -126,9 +164,8 @@ out:
return IRQ_HANDLED;
}
-static int mpr121_phys_init(const struct mpr121_platform_data *pdata,
- struct mpr121_touchkey *mpr121,
- struct i2c_client *client)
+static int mpr121_phys_init(struct mpr121_touchkey *mpr121,
+ struct i2c_client *client, int vdd_uv)
{
const struct mpr121_init_register *reg;
unsigned char usl, lsl, tl, eleconf;
@@ -158,9 +195,9 @@ static int mpr121_phys_init(const struct mpr121_platform_data *pdata,
/*
* Capacitance on sensing input varies and needs to be compensated.
* The internal MPR121-auto-configuration can do this if it's
- * registers are set properly (based on pdata->vdd_uv).
+ * registers are set properly (based on vdd_uv).
*/
- vdd = pdata->vdd_uv / 1000;
+ vdd = vdd_uv / 1000;
usl = ((vdd - 700) * 256) / vdd;
lsl = (usl * 65) / 100;
tl = (usl * 90) / 100;
@@ -191,35 +228,26 @@ err_i2c_write:
static int mpr_touchkey_probe(struct i2c_client *client,
const struct i2c_device_id *id)
{
- const struct mpr121_platform_data *pdata =
- dev_get_platdata(&client->dev);
+ struct device *dev = &client->dev;
+ struct regulator *vdd_supply;
+ int vdd_uv;
struct mpr121_touchkey *mpr121;
struct input_dev *input_dev;
int error;
int i;
- if (!pdata) {
- dev_err(&client->dev, "no platform data defined\n");
- return -EINVAL;
- }
-
- if (!pdata->keymap || !pdata->keymap_size) {
- dev_err(&client->dev, "missing keymap data\n");
- return -EINVAL;
- }
-
- if (pdata->keymap_size > MPR121_MAX_KEY_COUNT) {
- dev_err(&client->dev, "too many keys defined\n");
- return -EINVAL;
- }
-
if (!client->irq) {
dev_err(&client->dev, "irq number should not be zero\n");
return -EINVAL;
}
- mpr121 = devm_kzalloc(&client->dev, sizeof(*mpr121),
- GFP_KERNEL);
+ vdd_supply = mpr121_vdd_supply_init(dev);
+ if (IS_ERR(vdd_supply))
+ return PTR_ERR(vdd_supply);
+
+ vdd_uv = regulator_get_voltage(vdd_supply);
+
+ mpr121 = devm_kzalloc(&client->dev, sizeof(*mpr121), GFP_KERNEL);
if (!mpr121)
return -ENOMEM;
@@ -229,33 +257,46 @@ static int mpr_touchkey_probe(struct i2c_client *client,
mpr121->client = client;
mpr121->input_dev = input_dev;
- mpr121->keycount = pdata->keymap_size;
+ mpr121->keycount = device_property_read_u32_array(dev, "linux,keycodes",
+ NULL, 0);
+ if (mpr121->keycount > MPR121_MAX_KEY_COUNT) {
+ dev_err(dev, "too many keys defined (%d)\n", mpr121->keycount);
+ return -EINVAL;
+ }
+
+ error = device_property_read_u32_array(dev, "linux,keycodes",
+ mpr121->keycodes,
+ mpr121->keycount);
+ if (error) {
+ dev_err(dev,
+ "failed to read linux,keycode property: %d\n", error);
+ return error;
+ }
input_dev->name = "Freescale MPR121 Touchkey";
input_dev->id.bustype = BUS_I2C;
input_dev->dev.parent = &client->dev;
- input_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_REP);
+ if (device_property_read_bool(dev, "autorepeat"))
+ __set_bit(EV_REP, input_dev->evbit);
input_set_capability(input_dev, EV_MSC, MSC_SCAN);
input_dev->keycode = mpr121->keycodes;
input_dev->keycodesize = sizeof(mpr121->keycodes[0]);
input_dev->keycodemax = mpr121->keycount;
- for (i = 0; i < pdata->keymap_size; i++) {
- input_set_capability(input_dev, EV_KEY, pdata->keymap[i]);
- mpr121->keycodes[i] = pdata->keymap[i];
- }
+ for (i = 0; i < mpr121->keycount; i++)
+ input_set_capability(input_dev, EV_KEY, mpr121->keycodes[i]);
- error = mpr121_phys_init(pdata, mpr121, client);
+ error = mpr121_phys_init(mpr121, client, vdd_uv);
if (error) {
dev_err(&client->dev, "Failed to init register\n");
return error;
}
- error = devm_request_threaded_irq(&client->dev, client->irq, NULL,
- mpr_touchkey_interrupt,
- IRQF_TRIGGER_FALLING | IRQF_ONESHOT,
- client->dev.driver->name, mpr121);
+ error = devm_request_threaded_irq(&client->dev, client->irq,
+ NULL, mpr_touchkey_interrupt,
+ IRQF_TRIGGER_FALLING | IRQF_ONESHOT,
+ client->dev.driver->name, mpr121);
if (error) {
dev_err(&client->dev, "Failed to register interrupt\n");
return error;
@@ -266,7 +307,8 @@ static int mpr_touchkey_probe(struct i2c_client *client,
return error;
i2c_set_clientdata(client, mpr121);
- device_init_wakeup(&client->dev, pdata->wakeup);
+ device_init_wakeup(dev,
+ device_property_read_bool(dev, "wakeup-source"));
return 0;
}
@@ -305,10 +347,19 @@ static const struct i2c_device_id mpr121_id[] = {
};
MODULE_DEVICE_TABLE(i2c, mpr121_id);
+#ifdef CONFIG_OF
+static const struct of_device_id mpr121_touchkey_dt_match_table[] = {
+ { .compatible = "fsl,mpr121-touchkey" },
+ { },
+};
+MODULE_DEVICE_TABLE(of, mpr121_touchkey_dt_match_table);
+#endif
+
static struct i2c_driver mpr_touchkey_driver = {
.driver = {
.name = "mpr121",
.pm = &mpr121_touchkey_pm_ops,
+ .of_match_table = of_match_ptr(mpr121_touchkey_dt_match_table),
},
.id_table = mpr121_id,
.probe = mpr_touchkey_probe,