Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Input: mms114 - add device tree bindings

Add device tree bindings for mms114 touchscreen.

[Dmitry Torokhov: added #ifdef CONFIG_OF guards]

Signed-off-by: Tomasz Figa <t.figa@samsung.com>
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>

authored by

Tomasz Figa and committed by
Dmitry Torokhov
ad5396ee dae6ba4a

+94 -2
+34
Documentation/devicetree/bindings/input/touchscreen/mms114.txt
··· 1 + * MELFAS MMS114 touchscreen controller 2 + 3 + Required properties: 4 + - compatible: must be "melfas,mms114" 5 + - reg: I2C address of the chip 6 + - interrupts: interrupt to which the chip is connected 7 + - x-size: horizontal resolution of touchscreen 8 + - y-size: vertical resolution of touchscreen 9 + 10 + Optional properties: 11 + - contact-threshold: 12 + - moving-threshold: 13 + - x-invert: invert X axis 14 + - y-invert: invert Y axis 15 + 16 + Example: 17 + 18 + i2c@00000000 { 19 + /* ... */ 20 + 21 + touchscreen@48 { 22 + compatible = "melfas,mms114"; 23 + reg = <0x48>; 24 + interrupts = <39 0>; 25 + x-size = <720>; 26 + y-size = <1280>; 27 + contact-threshold = <10>; 28 + moving-threshold = <10>; 29 + x-invert; 30 + y-invert; 31 + }; 32 + 33 + /* ... */ 34 + };
+60 -2
drivers/input/touchscreen/mms114.c
··· 10 10 #include <linux/module.h> 11 11 #include <linux/init.h> 12 12 #include <linux/delay.h> 13 + #include <linux/of.h> 13 14 #include <linux/i2c.h> 14 15 #include <linux/i2c/mms114.h> 15 16 #include <linux/input/mt.h> ··· 361 360 mms114_stop(data); 362 361 } 363 362 363 + #ifdef CONFIG_OF 364 + static struct mms114_platform_data * __devinit mms114_parse_dt(struct device *dev) 365 + { 366 + struct mms114_platform_data *pdata; 367 + struct device_node *np = dev->of_node; 368 + 369 + if (!np) 370 + return NULL; 371 + 372 + pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL); 373 + if (!pdata) { 374 + dev_err(dev, "failed to allocate platform data\n"); 375 + return NULL; 376 + } 377 + 378 + if (of_property_read_u32(np, "x-size", &pdata->x_size)) { 379 + dev_err(dev, "failed to get x-size property\n"); 380 + return NULL; 381 + }; 382 + 383 + if (of_property_read_u32(np, "y-size", &pdata->y_size)) { 384 + dev_err(dev, "failed to get y-size property\n"); 385 + return NULL; 386 + }; 387 + 388 + of_property_read_u32(np, "contact-threshold", 389 + &pdata->contact_threshold); 390 + of_property_read_u32(np, "moving-threshold", 391 + &pdata->moving_threshold); 392 + 393 + if (of_find_property(np, "x-invert", NULL)) 394 + pdata->x_invert = true; 395 + if (of_find_property(np, "y-invert", NULL)) 396 + pdata->y_invert = true; 397 + 398 + return pdata; 399 + } 400 + #else 401 + static inline struct mms114_platform_data *mms114_parse_dt(struct device *dev) 402 + { 403 + return NULL; 404 + } 405 + #endif 406 + 364 407 static int __devinit mms114_probe(struct i2c_client *client, 365 408 const struct i2c_device_id *id) 366 409 { 410 + const struct mms114_platform_data *pdata; 367 411 struct mms114_data *data; 368 412 struct input_dev *input_dev; 369 413 int error; 370 414 371 - if (!client->dev.platform_data) { 415 + pdata = dev_get_platdata(&client->dev); 416 + if (!pdata) 417 + pdata = mms114_parse_dt(&client->dev); 418 + 419 + if (!pdata) { 372 420 dev_err(&client->dev, "Need platform data\n"); 373 421 return -EINVAL; 374 422 } ··· 439 389 440 390 data->client = client; 441 391 data->input_dev = input_dev; 442 - data->pdata = client->dev.platform_data; 392 + data->pdata = pdata; 443 393 444 394 input_dev->name = "MELPAS MMS114 Touchscreen"; 445 395 input_dev->id.bustype = BUS_I2C; ··· 575 525 }; 576 526 MODULE_DEVICE_TABLE(i2c, mms114_id); 577 527 528 + #ifdef CONFIG_OF 529 + static struct of_device_id __devinitdata mms114_dt_match[] = { 530 + { .compatible = "melfas,mms114" }, 531 + { } 532 + }; 533 + #endif 534 + 578 535 static struct i2c_driver mms114_driver = { 579 536 .driver = { 580 537 .name = "mms114", 581 538 .owner = THIS_MODULE, 582 539 .pm = &mms114_pm_ops, 540 + .of_match_table = of_match_ptr(mms114_dt_match), 583 541 }, 584 542 .probe = mms114_probe, 585 543 .remove = __devexit_p(mms114_remove),