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

Input: bu21013_ts - move GPIO init and exit functions into the driver

These GPIO init and exit functions have no place in platform data, they
should be part of the driver instead,

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
31fbcda7 8c587f77

+53 -97
+1 -70
arch/arm/mach-ux500/board-mop500-stuib.c
··· 77 77 * BU21013 ROHM touchscreen interface on the STUIBs 78 78 */ 79 79 80 - /* tracks number of bu21013 devices being enabled */ 81 - static int bu21013_devices; 82 - 83 80 #define TOUCH_GPIO_PIN 84 84 81 85 82 #define TOUCH_XMAX 384 ··· 85 88 #define PRCMU_CLOCK_OCR 0x1CC 86 89 #define TSC_EXT_CLOCK_9_6MHZ 0x840000 87 90 88 - /** 89 - * bu21013_gpio_board_init : configures the touch panel. 90 - * @reset_pin: reset pin number 91 - * This function can be used to configures 92 - * the voltage and reset the touch panel controller. 93 - */ 94 - static int bu21013_gpio_board_init(int reset_pin) 95 - { 96 - int retval = 0; 97 - 98 - bu21013_devices++; 99 - if (bu21013_devices == 1) { 100 - retval = gpio_request(reset_pin, "touchp_reset"); 101 - if (retval) { 102 - printk(KERN_ERR "Unable to request gpio reset_pin"); 103 - return retval; 104 - } 105 - retval = gpio_direction_output(reset_pin, 1); 106 - if (retval < 0) { 107 - printk(KERN_ERR "%s: gpio direction failed\n", 108 - __func__); 109 - return retval; 110 - } 111 - } 112 - 113 - return retval; 114 - } 115 - 116 - /** 117 - * bu21013_gpio_board_exit : deconfigures the touch panel controller 118 - * @reset_pin: reset pin number 119 - * This function can be used to deconfigures the chip selection 120 - * for touch panel controller. 121 - */ 122 - static int bu21013_gpio_board_exit(int reset_pin) 123 - { 124 - int retval = 0; 125 - 126 - if (bu21013_devices == 1) { 127 - retval = gpio_direction_output(reset_pin, 0); 128 - if (retval < 0) { 129 - printk(KERN_ERR "%s: gpio direction failed\n", 130 - __func__); 131 - return retval; 132 - } 133 - gpio_set_value(reset_pin, 0); 134 - } 135 - bu21013_devices--; 136 - 137 - return retval; 138 - } 139 - 140 - /** 141 - * bu21013_read_pin_val : get the interrupt pin value 142 - * This function can be used to get the interrupt pin value for touch panel 143 - * controller. 144 - */ 145 - static int bu21013_read_pin_val(void) 146 - { 147 - return gpio_get_value(TOUCH_GPIO_PIN); 148 - } 149 - 150 91 static struct bu21013_platform_device tsc_plat_device = { 151 - .cs_en = bu21013_gpio_board_init, 152 - .cs_dis = bu21013_gpio_board_exit, 153 - .irq_read_val = bu21013_read_pin_val, 154 - .irq = NOMADIK_GPIO_TO_IRQ(TOUCH_GPIO_PIN), 92 + .touch_pin = TOUCH_GPIO_PIN, 155 93 .touch_x_max = TOUCH_XMAX, 156 94 .touch_y_max = TOUCH_YMAX, 157 95 .ext_clk = false, ··· 103 171 I2C_BOARD_INFO("bu21013_tp", 0x5D), 104 172 .platform_data = &tsc_plat_device, 105 173 }, 106 - 107 174 }; 108 175 109 176 void __init mop500_stuib_init(void)
+50 -19
drivers/input/touchscreen/bu21013_ts.c
··· 14 14 #include <linux/slab.h> 15 15 #include <linux/regulator/consumer.h> 16 16 #include <linux/module.h> 17 + #include <linux/gpio.h> 17 18 18 19 #define PEN_DOWN_INTR 0 19 20 #define MAX_FINGERS 2 ··· 149 148 struct bu21013_ts_data { 150 149 struct i2c_client *client; 151 150 wait_queue_head_t wait; 152 - bool touch_stopped; 153 151 const struct bu21013_platform_device *chip; 154 152 struct input_dev *in_dev; 155 - unsigned int intr_pin; 156 153 struct regulator *regulator; 154 + unsigned int irq; 155 + unsigned int intr_pin; 156 + bool touch_stopped; 157 157 }; 158 158 159 159 /** ··· 264 262 return IRQ_NONE; 265 263 } 266 264 267 - data->intr_pin = data->chip->irq_read_val(); 265 + data->intr_pin = gpio_get_value(data->chip->touch_pin); 268 266 if (data->intr_pin == PEN_DOWN_INTR) 269 267 wait_event_timeout(data->wait, data->touch_stopped, 270 268 msecs_to_jiffies(2)); ··· 420 418 { 421 419 bu21013_data->touch_stopped = true; 422 420 wake_up(&bu21013_data->wait); 423 - free_irq(bu21013_data->chip->irq, bu21013_data); 421 + free_irq(bu21013_data->irq, bu21013_data); 424 422 } 423 + 424 + /** 425 + * bu21013_cs_disable() - deconfigures the touch panel controller 426 + * @bu21013_data: device structure pointer 427 + * 428 + * This function is used to deconfigure the chip selection 429 + * for touch panel controller. 430 + */ 431 + static void bu21013_cs_disable(struct bu21013_ts_data *bu21013_data) 432 + { 433 + int error; 434 + 435 + error = gpio_direction_output(bu21013_data->chip->cs_pin, 0); 436 + if (error < 0) 437 + dev_warn(&bu21013_data->client->dev, 438 + "%s: gpio direction failed, error: %d\n", 439 + __func__, error); 440 + else 441 + gpio_set_value(bu21013_data->chip->cs_pin, 0); 442 + 443 + gpio_free(bu21013_data->chip->cs_pin); 444 + } 445 + 425 446 426 447 /** 427 448 * bu21013_probe() - initializes the i2c-client touchscreen driver ··· 455 430 * driver and returns integer. 456 431 */ 457 432 static int bu21013_probe(struct i2c_client *client, 458 - const struct i2c_device_id *id) 433 + const struct i2c_device_id *id) 459 434 { 460 435 struct bu21013_ts_data *bu21013_data; 461 436 struct input_dev *in_dev; ··· 474 449 return -EINVAL; 475 450 } 476 451 452 + if (!gpio_is_valid(pdata->touch_pin)) { 453 + dev_err(&client->dev, "invalid touch_pin supplied\n"); 454 + return -EINVAL; 455 + } 456 + 477 457 bu21013_data = kzalloc(sizeof(struct bu21013_ts_data), GFP_KERNEL); 478 458 in_dev = input_allocate_device(); 479 459 if (!bu21013_data || !in_dev) { ··· 490 460 bu21013_data->in_dev = in_dev; 491 461 bu21013_data->chip = pdata; 492 462 bu21013_data->client = client; 463 + bu21013_data->irq = gpio_to_irq(pdata->touch_pin); 493 464 494 465 bu21013_data->regulator = regulator_get(&client->dev, "avdd"); 495 466 if (IS_ERR(bu21013_data->regulator)) { ··· 509 478 init_waitqueue_head(&bu21013_data->wait); 510 479 511 480 /* configure the gpio pins */ 512 - if (pdata->cs_en) { 513 - error = pdata->cs_en(pdata->cs_pin); 514 - if (error < 0) { 515 - dev_err(&client->dev, "chip init failed\n"); 516 - goto err_disable_regulator; 517 - } 481 + error = gpio_request_one(pdata->cs_pin, GPIOF_OUT_INIT_HIGH, 482 + "touchp_reset"); 483 + if (error < 0) { 484 + dev_err(&client->dev, "Unable to request gpio reset_pin\n"); 485 + goto err_disable_regulator; 518 486 } 519 487 520 488 /* configure the touch panel controller */ ··· 538 508 pdata->touch_y_max, 0, 0); 539 509 input_set_drvdata(in_dev, bu21013_data); 540 510 541 - error = request_threaded_irq(pdata->irq, NULL, bu21013_gpio_irq, 511 + error = request_threaded_irq(bu21013_data->irq, NULL, bu21013_gpio_irq, 542 512 IRQF_TRIGGER_FALLING | IRQF_SHARED | 543 513 IRQF_ONESHOT, 544 514 DRIVER_TP, bu21013_data); 545 515 if (error) { 546 - dev_err(&client->dev, "request irq %d failed\n", pdata->irq); 516 + dev_err(&client->dev, "request irq %d failed\n", 517 + bu21013_data->irq); 547 518 goto err_cs_disable; 548 519 } 549 520 ··· 562 531 err_free_irq: 563 532 bu21013_free_irq(bu21013_data); 564 533 err_cs_disable: 565 - pdata->cs_dis(pdata->cs_pin); 534 + bu21013_cs_disable(bu21013_data); 566 535 err_disable_regulator: 567 536 regulator_disable(bu21013_data->regulator); 568 537 err_put_regulator: ··· 586 555 587 556 bu21013_free_irq(bu21013_data); 588 557 589 - bu21013_data->chip->cs_dis(bu21013_data->chip->cs_pin); 558 + bu21013_cs_disable(bu21013_data); 590 559 591 560 input_unregister_device(bu21013_data->in_dev); 592 561 ··· 615 584 616 585 bu21013_data->touch_stopped = true; 617 586 if (device_may_wakeup(&client->dev)) 618 - enable_irq_wake(bu21013_data->chip->irq); 587 + enable_irq_wake(bu21013_data->irq); 619 588 else 620 - disable_irq(bu21013_data->chip->irq); 589 + disable_irq(bu21013_data->irq); 621 590 622 591 regulator_disable(bu21013_data->regulator); 623 592 ··· 652 621 bu21013_data->touch_stopped = false; 653 622 654 623 if (device_may_wakeup(&client->dev)) 655 - disable_irq_wake(bu21013_data->chip->irq); 624 + disable_irq_wake(bu21013_data->irq); 656 625 else 657 - enable_irq(bu21013_data->chip->irq); 626 + enable_irq(bu21013_data->irq); 658 627 659 628 return 0; 660 629 }
+2 -8
include/linux/input/bu21013.h
··· 9 9 10 10 /** 11 11 * struct bu21013_platform_device - Handle the platform data 12 - * @cs_en: pointer to the cs enable function 13 - * @cs_dis: pointer to the cs disable function 14 - * @irq_read_val: pointer to read the pen irq value function 15 12 * @touch_x_max: touch x max 16 13 * @touch_y_max: touch y max 17 14 * @cs_pin: chip select pin 18 - * @irq: irq pin 15 + * @touch_pin: touch gpio pin 19 16 * @ext_clk: external clock flag 20 17 * @x_flip: x flip flag 21 18 * @y_flip: y flip flag ··· 21 24 * This is used to handle the platform data 22 25 */ 23 26 struct bu21013_platform_device { 24 - int (*cs_en)(int reset_pin); 25 - int (*cs_dis)(int reset_pin); 26 - int (*irq_read_val)(void); 27 27 int touch_x_max; 28 28 int touch_y_max; 29 29 unsigned int cs_pin; 30 - unsigned int irq; 30 + unsigned int touch_pin; 31 31 bool ext_clk; 32 32 bool x_flip; 33 33 bool y_flip;