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

Input: zforce_ts - convert to use the gpiod interface

Use the new GPIO descriptor interface to handle the zForce GPIOs.
This simplifies the code and allows transparently handle GPIO polarity, as
specified in device tree data.

Also switch to using gpio_{set|get}_value_cansleep() since none of the
callers is in atomic context and cansleep variant allows more GPIO
controllers to be used with the touchscreen.

Signed-off-by: Dirk Behme <dirk.behme@de.bosch.com>
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>

authored by

Dirk Behme and committed by
Dmitry Torokhov
2d538095 b7e79329

+30 -31
+30 -28
drivers/input/touchscreen/zforce_ts.c
··· 24 24 #include <linux/interrupt.h> 25 25 #include <linux/i2c.h> 26 26 #include <linux/delay.h> 27 - #include <linux/gpio.h> 27 + #include <linux/gpio/consumer.h> 28 28 #include <linux/device.h> 29 29 #include <linux/sysfs.h> 30 30 #include <linux/input/mt.h> 31 31 #include <linux/platform_data/zforce_ts.h> 32 32 #include <linux/regulator/consumer.h> 33 33 #include <linux/of.h> 34 - #include <linux/of_gpio.h> 35 34 36 35 #define WAIT_TIMEOUT msecs_to_jiffies(1000) 37 36 ··· 119 120 120 121 struct regulator *reg_vdd; 121 122 123 + struct gpio_desc *gpio_int; 124 + struct gpio_desc *gpio_rst; 125 + 122 126 bool suspending; 123 127 bool suspended; 124 128 bool boot_complete; ··· 161 159 } 162 160 163 161 return 0; 162 + } 163 + 164 + static void zforce_reset_assert(struct zforce_ts *ts) 165 + { 166 + gpiod_set_value_cansleep(ts->gpio_rst, 1); 167 + } 168 + 169 + static void zforce_reset_deassert(struct zforce_ts *ts) 170 + { 171 + gpiod_set_value_cansleep(ts->gpio_rst, 0); 164 172 } 165 173 166 174 static int zforce_send_wait(struct zforce_ts *ts, const char *buf, int len) ··· 491 479 { 492 480 struct zforce_ts *ts = dev_id; 493 481 struct i2c_client *client = ts->client; 494 - const struct zforce_ts_platdata *pdata = ts->pdata; 495 482 int ret; 496 483 u8 payload_buffer[FRAME_MAXSIZE]; 497 484 u8 *payload; ··· 510 499 if (!ts->suspending && device_may_wakeup(&client->dev)) 511 500 pm_stay_awake(&client->dev); 512 501 513 - while (!gpio_get_value(pdata->gpio_int)) { 502 + while (!gpiod_get_value_cansleep(ts->gpio_int)) { 514 503 ret = zforce_read_packet(ts, payload_buffer); 515 504 if (ret < 0) { 516 505 dev_err(&client->dev, ··· 701 690 { 702 691 struct zforce_ts *ts = data; 703 692 704 - gpio_set_value(ts->pdata->gpio_rst, 0); 693 + zforce_reset_assert(ts); 705 694 706 695 udelay(10); 707 696 ··· 721 710 if (!pdata) { 722 711 dev_err(dev, "failed to allocate platform data\n"); 723 712 return ERR_PTR(-ENOMEM); 724 - } 725 - 726 - pdata->gpio_int = of_get_gpio(np, 0); 727 - if (!gpio_is_valid(pdata->gpio_int)) { 728 - dev_err(dev, "failed to get interrupt gpio\n"); 729 - return ERR_PTR(-EINVAL); 730 - } 731 - 732 - pdata->gpio_rst = of_get_gpio(np, 1); 733 - if (!gpio_is_valid(pdata->gpio_rst)) { 734 - dev_err(dev, "failed to get reset gpio\n"); 735 - return ERR_PTR(-EINVAL); 736 713 } 737 714 738 715 if (of_property_read_u32(np, "x-size", &pdata->x_max)) { ··· 754 755 if (!ts) 755 756 return -ENOMEM; 756 757 757 - ret = devm_gpio_request_one(&client->dev, pdata->gpio_int, GPIOF_IN, 758 - "zforce_ts_int"); 759 - if (ret) { 760 - dev_err(&client->dev, "request of gpio %d failed, %d\n", 761 - pdata->gpio_int, ret); 758 + /* INT GPIO */ 759 + ts->gpio_int = devm_gpiod_get_index(&client->dev, NULL, 0, GPIOD_IN); 760 + if (IS_ERR(ts->gpio_int)) { 761 + ret = PTR_ERR(ts->gpio_int); 762 + dev_err(&client->dev, 763 + "failed to request interrupt GPIO: %d\n", ret); 762 764 return ret; 763 765 } 764 766 765 - ret = devm_gpio_request_one(&client->dev, pdata->gpio_rst, 766 - GPIOF_OUT_INIT_LOW, "zforce_ts_rst"); 767 - if (ret) { 768 - dev_err(&client->dev, "request of gpio %d failed, %d\n", 769 - pdata->gpio_rst, ret); 767 + /* RST GPIO */ 768 + ts->gpio_rst = devm_gpiod_get_index(&client->dev, NULL, 1, 769 + GPIOD_OUT_HIGH); 770 + if (IS_ERR(ts->gpio_rst)) { 771 + ret = PTR_ERR(ts->gpio_rst); 772 + dev_err(&client->dev, 773 + "failed to request reset GPIO: %d\n", ret); 770 774 return ret; 771 775 } 772 776 ··· 865 863 i2c_set_clientdata(client, ts); 866 864 867 865 /* let the controller boot */ 868 - gpio_set_value(pdata->gpio_rst, 1); 866 + zforce_reset_deassert(ts); 869 867 870 868 ts->command_waiting = NOTIFICATION_BOOTCOMPLETE; 871 869 if (wait_for_completion_timeout(&ts->command_done, WAIT_TIMEOUT) == 0)
-3
include/linux/platform_data/zforce_ts.h
··· 16 16 #define _LINUX_INPUT_ZFORCE_TS_H 17 17 18 18 struct zforce_ts_platdata { 19 - int gpio_int; 20 - int gpio_rst; 21 - 22 19 unsigned int x_max; 23 20 unsigned int y_max; 24 21 };