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

Input: bu21013_ts - add support for Device Tree booting

Now we can register the BU21013_ts touch screen when booting with Device
Tree enabled. Here we parse all the necessary components previously
expected to be passed from platform data.

Acked-by: Arnd Bergmann <arnd@arndb.de>
Acked-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Lee Jones <lee.jones@linaro.org>
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>

authored by

Lee Jones and committed by
Dmitry Torokhov
48fceb7d 31fbcda7

+46 -4
+46 -4
drivers/input/touchscreen/bu21013_ts.c
··· 15 15 #include <linux/regulator/consumer.h> 16 16 #include <linux/module.h> 17 17 #include <linux/gpio.h> 18 + #include <linux/of.h> 19 + #include <linux/of_gpio.h> 18 20 19 21 #define PEN_DOWN_INTR 0 20 22 #define MAX_FINGERS 2 ··· 447 445 gpio_free(bu21013_data->chip->cs_pin); 448 446 } 449 447 448 + #ifdef CONFIG_OF 449 + static const struct bu21013_platform_device * 450 + bu21013_parse_dt(struct device *dev) 451 + { 452 + struct device_node *np = dev->of_node; 453 + struct bu21013_platform_device *pdata; 454 + 455 + if (!np) { 456 + dev_err(dev, "no device tree or platform data\n"); 457 + return ERR_PTR(-EINVAL); 458 + } 459 + 460 + pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL); 461 + if (!pdata) 462 + return ERR_PTR(-ENOMEM); 463 + 464 + pdata->y_flip = pdata->x_flip = false; 465 + 466 + pdata->x_flip = of_property_read_bool(np, "rohm,flip-x"); 467 + pdata->y_flip = of_property_read_bool(np, "rohm,flip-y"); 468 + 469 + of_property_read_u32(np, "rohm,touch-max-x", &pdata->touch_x_max); 470 + of_property_read_u32(np, "rohm,touch-max-y", &pdata->touch_y_max); 471 + 472 + pdata->touch_pin = of_get_named_gpio(np, "touch-gpio", 0); 473 + pdata->cs_pin = of_get_named_gpio(np, "reset-gpio", 0); 474 + 475 + pdata->ext_clk = false; 476 + 477 + return pdata; 478 + } 479 + #else 480 + static inline const struct bu21013_platform_device * 481 + bu21013_parse_dt(struct device *dev) 482 + { 483 + dev_err(dev, "no platform data available\n"); 484 + return ERR_PTR(-EINVAL); 485 + } 486 + #endif 450 487 451 488 /** 452 489 * bu21013_probe() - initializes the i2c-client touchscreen driver ··· 498 457 static int bu21013_probe(struct i2c_client *client, 499 458 const struct i2c_device_id *id) 500 459 { 460 + const struct bu21013_platform_device *pdata = 461 + dev_get_platdata(&client->dev); 501 462 struct bu21013_ts_data *bu21013_data; 502 463 struct input_dev *in_dev; 503 - const struct bu21013_platform_device *pdata = 504 - client->dev.platform_data; 505 464 int error; 506 465 507 466 if (!i2c_check_functionality(client->adapter, ··· 511 470 } 512 471 513 472 if (!pdata) { 514 - dev_err(&client->dev, "platform data not defined\n"); 515 - return -EINVAL; 473 + pdata = bu21013_parse_dt(&client->dev); 474 + if (IS_ERR(pdata)) 475 + return PTR_ERR(pdata); 516 476 } 517 477 518 478 if (!gpio_is_valid(pdata->touch_pin)) {