aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/input/touchscreen/mms114.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/input/touchscreen/mms114.c')
-rw-r--r--drivers/input/touchscreen/mms114.c68
1 files changed, 63 insertions, 5 deletions
diff --git a/drivers/input/touchscreen/mms114.c b/drivers/input/touchscreen/mms114.c
index 560cf09d1c5a..98841d8aa635 100644
--- a/drivers/input/touchscreen/mms114.c
+++ b/drivers/input/touchscreen/mms114.c
@@ -10,6 +10,7 @@
10#include <linux/module.h> 10#include <linux/module.h>
11#include <linux/init.h> 11#include <linux/init.h>
12#include <linux/delay.h> 12#include <linux/delay.h>
13#include <linux/of.h>
13#include <linux/i2c.h> 14#include <linux/i2c.h>
14#include <linux/i2c/mms114.h> 15#include <linux/i2c/mms114.h>
15#include <linux/input/mt.h> 16#include <linux/input/mt.h>
@@ -360,14 +361,63 @@ static void mms114_input_close(struct input_dev *dev)
360 mms114_stop(data); 361 mms114_stop(data);
361} 362}
362 363
363static int __devinit mms114_probe(struct i2c_client *client, 364#ifdef CONFIG_OF
365static struct mms114_platform_data *mms114_parse_dt(struct device *dev)
366{
367 struct mms114_platform_data *pdata;
368 struct device_node *np = dev->of_node;
369
370 if (!np)
371 return NULL;
372
373 pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL);
374 if (!pdata) {
375 dev_err(dev, "failed to allocate platform data\n");
376 return NULL;
377 }
378
379 if (of_property_read_u32(np, "x-size", &pdata->x_size)) {
380 dev_err(dev, "failed to get x-size property\n");
381 return NULL;
382 };
383
384 if (of_property_read_u32(np, "y-size", &pdata->y_size)) {
385 dev_err(dev, "failed to get y-size property\n");
386 return NULL;
387 };
388
389 of_property_read_u32(np, "contact-threshold",
390 &pdata->contact_threshold);
391 of_property_read_u32(np, "moving-threshold",
392 &pdata->moving_threshold);
393
394 if (of_find_property(np, "x-invert", NULL))
395 pdata->x_invert = true;
396 if (of_find_property(np, "y-invert", NULL))
397 pdata->y_invert = true;
398
399 return pdata;
400}
401#else
402static inline struct mms114_platform_data *mms114_parse_dt(struct device *dev)
403{
404 return NULL;
405}
406#endif
407
408static int mms114_probe(struct i2c_client *client,
364 const struct i2c_device_id *id) 409 const struct i2c_device_id *id)
365{ 410{
411 const struct mms114_platform_data *pdata;
366 struct mms114_data *data; 412 struct mms114_data *data;
367 struct input_dev *input_dev; 413 struct input_dev *input_dev;
368 int error; 414 int error;
369 415
370 if (!client->dev.platform_data) { 416 pdata = dev_get_platdata(&client->dev);
417 if (!pdata)
418 pdata = mms114_parse_dt(&client->dev);
419
420 if (!pdata) {
371 dev_err(&client->dev, "Need platform data\n"); 421 dev_err(&client->dev, "Need platform data\n");
372 return -EINVAL; 422 return -EINVAL;
373 } 423 }
@@ -389,7 +439,7 @@ static int __devinit mms114_probe(struct i2c_client *client,
389 439
390 data->client = client; 440 data->client = client;
391 data->input_dev = input_dev; 441 data->input_dev = input_dev;
392 data->pdata = client->dev.platform_data; 442 data->pdata = pdata;
393 443
394 input_dev->name = "MELPAS MMS114 Touchscreen"; 444 input_dev->name = "MELPAS MMS114 Touchscreen";
395 input_dev->id.bustype = BUS_I2C; 445 input_dev->id.bustype = BUS_I2C;
@@ -458,7 +508,7 @@ err_free_mem:
458 return error; 508 return error;
459} 509}
460 510
461static int __devexit mms114_remove(struct i2c_client *client) 511static int mms114_remove(struct i2c_client *client)
462{ 512{
463 struct mms114_data *data = i2c_get_clientdata(client); 513 struct mms114_data *data = i2c_get_clientdata(client);
464 514
@@ -525,14 +575,22 @@ static const struct i2c_device_id mms114_id[] = {
525}; 575};
526MODULE_DEVICE_TABLE(i2c, mms114_id); 576MODULE_DEVICE_TABLE(i2c, mms114_id);
527 577
578#ifdef CONFIG_OF
579static struct of_device_id mms114_dt_match[] = {
580 { .compatible = "melfas,mms114" },
581 { }
582};
583#endif
584
528static struct i2c_driver mms114_driver = { 585static struct i2c_driver mms114_driver = {
529 .driver = { 586 .driver = {
530 .name = "mms114", 587 .name = "mms114",
531 .owner = THIS_MODULE, 588 .owner = THIS_MODULE,
532 .pm = &mms114_pm_ops, 589 .pm = &mms114_pm_ops,
590 .of_match_table = of_match_ptr(mms114_dt_match),
533 }, 591 },
534 .probe = mms114_probe, 592 .probe = mms114_probe,
535 .remove = __devexit_p(mms114_remove), 593 .remove = mms114_remove,
536 .id_table = mms114_id, 594 .id_table = mms114_id,
537}; 595};
538 596