Skip to content

Commit 31fbcda

Browse files
Lee Jonesdtor
authored andcommitted
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>
1 parent 8c587f7 commit 31fbcda

3 files changed

Lines changed: 53 additions & 97 deletions

File tree

arch/arm/mach-ux500/board-mop500-stuib.c

Lines changed: 1 addition & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,6 @@ static struct i2c_board_info __initdata mop500_i2c0_devices_stuib[] = {
7777
* BU21013 ROHM touchscreen interface on the STUIBs
7878
*/
7979

80-
/* tracks number of bu21013 devices being enabled */
81-
static int bu21013_devices;
82-
8380
#define TOUCH_GPIO_PIN 84
8481

8582
#define TOUCH_XMAX 384
@@ -88,73 +85,8 @@ static int bu21013_devices;
8885
#define PRCMU_CLOCK_OCR 0x1CC
8986
#define TSC_EXT_CLOCK_9_6MHZ 0x840000
9087

91-
/**
92-
* bu21013_gpio_board_init : configures the touch panel.
93-
* @reset_pin: reset pin number
94-
* This function can be used to configures
95-
* the voltage and reset the touch panel controller.
96-
*/
97-
static int bu21013_gpio_board_init(int reset_pin)
98-
{
99-
int retval = 0;
100-
101-
bu21013_devices++;
102-
if (bu21013_devices == 1) {
103-
retval = gpio_request(reset_pin, "touchp_reset");
104-
if (retval) {
105-
printk(KERN_ERR "Unable to request gpio reset_pin");
106-
return retval;
107-
}
108-
retval = gpio_direction_output(reset_pin, 1);
109-
if (retval < 0) {
110-
printk(KERN_ERR "%s: gpio direction failed\n",
111-
__func__);
112-
return retval;
113-
}
114-
}
115-
116-
return retval;
117-
}
118-
119-
/**
120-
* bu21013_gpio_board_exit : deconfigures the touch panel controller
121-
* @reset_pin: reset pin number
122-
* This function can be used to deconfigures the chip selection
123-
* for touch panel controller.
124-
*/
125-
static int bu21013_gpio_board_exit(int reset_pin)
126-
{
127-
int retval = 0;
128-
129-
if (bu21013_devices == 1) {
130-
retval = gpio_direction_output(reset_pin, 0);
131-
if (retval < 0) {
132-
printk(KERN_ERR "%s: gpio direction failed\n",
133-
__func__);
134-
return retval;
135-
}
136-
gpio_set_value(reset_pin, 0);
137-
}
138-
bu21013_devices--;
139-
140-
return retval;
141-
}
142-
143-
/**
144-
* bu21013_read_pin_val : get the interrupt pin value
145-
* This function can be used to get the interrupt pin value for touch panel
146-
* controller.
147-
*/
148-
static int bu21013_read_pin_val(void)
149-
{
150-
return gpio_get_value(TOUCH_GPIO_PIN);
151-
}
152-
15388
static struct bu21013_platform_device tsc_plat_device = {
154-
.cs_en = bu21013_gpio_board_init,
155-
.cs_dis = bu21013_gpio_board_exit,
156-
.irq_read_val = bu21013_read_pin_val,
157-
.irq = NOMADIK_GPIO_TO_IRQ(TOUCH_GPIO_PIN),
89+
.touch_pin = TOUCH_GPIO_PIN,
15890
.touch_x_max = TOUCH_XMAX,
15991
.touch_y_max = TOUCH_YMAX,
16092
.ext_clk = false,
@@ -171,7 +103,6 @@ static struct i2c_board_info __initdata u8500_i2c3_devices_stuib[] = {
171103
I2C_BOARD_INFO("bu21013_tp", 0x5D),
172104
.platform_data = &tsc_plat_device,
173105
},
174-
175106
};
176107

177108
void __init mop500_stuib_init(void)

drivers/input/touchscreen/bu21013_ts.c

Lines changed: 50 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include <linux/slab.h>
1515
#include <linux/regulator/consumer.h>
1616
#include <linux/module.h>
17+
#include <linux/gpio.h>
1718

1819
#define PEN_DOWN_INTR 0
1920
#define MAX_FINGERS 2
@@ -148,11 +149,12 @@
148149
struct bu21013_ts_data {
149150
struct i2c_client *client;
150151
wait_queue_head_t wait;
151-
bool touch_stopped;
152152
const struct bu21013_platform_device *chip;
153153
struct input_dev *in_dev;
154-
unsigned int intr_pin;
155154
struct regulator *regulator;
155+
unsigned int irq;
156+
unsigned int intr_pin;
157+
bool touch_stopped;
156158
};
157159

158160
/**
@@ -262,7 +264,7 @@ static irqreturn_t bu21013_gpio_irq(int irq, void *device_data)
262264
return IRQ_NONE;
263265
}
264266

265-
data->intr_pin = data->chip->irq_read_val();
267+
data->intr_pin = gpio_get_value(data->chip->touch_pin);
266268
if (data->intr_pin == PEN_DOWN_INTR)
267269
wait_event_timeout(data->wait, data->touch_stopped,
268270
msecs_to_jiffies(2));
@@ -418,9 +420,32 @@ static void bu21013_free_irq(struct bu21013_ts_data *bu21013_data)
418420
{
419421
bu21013_data->touch_stopped = true;
420422
wake_up(&bu21013_data->wait);
421-
free_irq(bu21013_data->chip->irq, bu21013_data);
423+
free_irq(bu21013_data->irq, bu21013_data);
422424
}
423425

426+
/**
427+
* bu21013_cs_disable() - deconfigures the touch panel controller
428+
* @bu21013_data: device structure pointer
429+
*
430+
* This function is used to deconfigure the chip selection
431+
* for touch panel controller.
432+
*/
433+
static void bu21013_cs_disable(struct bu21013_ts_data *bu21013_data)
434+
{
435+
int error;
436+
437+
error = gpio_direction_output(bu21013_data->chip->cs_pin, 0);
438+
if (error < 0)
439+
dev_warn(&bu21013_data->client->dev,
440+
"%s: gpio direction failed, error: %d\n",
441+
__func__, error);
442+
else
443+
gpio_set_value(bu21013_data->chip->cs_pin, 0);
444+
445+
gpio_free(bu21013_data->chip->cs_pin);
446+
}
447+
448+
424449
/**
425450
* bu21013_probe() - initializes the i2c-client touchscreen driver
426451
* @client: i2c client structure pointer
@@ -430,7 +455,7 @@ static void bu21013_free_irq(struct bu21013_ts_data *bu21013_data)
430455
* driver and returns integer.
431456
*/
432457
static int bu21013_probe(struct i2c_client *client,
433-
const struct i2c_device_id *id)
458+
const struct i2c_device_id *id)
434459
{
435460
struct bu21013_ts_data *bu21013_data;
436461
struct input_dev *in_dev;
@@ -449,6 +474,11 @@ static int bu21013_probe(struct i2c_client *client,
449474
return -EINVAL;
450475
}
451476

477+
if (!gpio_is_valid(pdata->touch_pin)) {
478+
dev_err(&client->dev, "invalid touch_pin supplied\n");
479+
return -EINVAL;
480+
}
481+
452482
bu21013_data = kzalloc(sizeof(struct bu21013_ts_data), GFP_KERNEL);
453483
in_dev = input_allocate_device();
454484
if (!bu21013_data || !in_dev) {
@@ -460,6 +490,7 @@ static int bu21013_probe(struct i2c_client *client,
460490
bu21013_data->in_dev = in_dev;
461491
bu21013_data->chip = pdata;
462492
bu21013_data->client = client;
493+
bu21013_data->irq = gpio_to_irq(pdata->touch_pin);
463494

464495
bu21013_data->regulator = regulator_get(&client->dev, "avdd");
465496
if (IS_ERR(bu21013_data->regulator)) {
@@ -478,12 +509,11 @@ static int bu21013_probe(struct i2c_client *client,
478509
init_waitqueue_head(&bu21013_data->wait);
479510

480511
/* configure the gpio pins */
481-
if (pdata->cs_en) {
482-
error = pdata->cs_en(pdata->cs_pin);
483-
if (error < 0) {
484-
dev_err(&client->dev, "chip init failed\n");
485-
goto err_disable_regulator;
486-
}
512+
error = gpio_request_one(pdata->cs_pin, GPIOF_OUT_INIT_HIGH,
513+
"touchp_reset");
514+
if (error < 0) {
515+
dev_err(&client->dev, "Unable to request gpio reset_pin\n");
516+
goto err_disable_regulator;
487517
}
488518

489519
/* configure the touch panel controller */
@@ -508,12 +538,13 @@ static int bu21013_probe(struct i2c_client *client,
508538
pdata->touch_y_max, 0, 0);
509539
input_set_drvdata(in_dev, bu21013_data);
510540

511-
error = request_threaded_irq(pdata->irq, NULL, bu21013_gpio_irq,
541+
error = request_threaded_irq(bu21013_data->irq, NULL, bu21013_gpio_irq,
512542
IRQF_TRIGGER_FALLING | IRQF_SHARED |
513543
IRQF_ONESHOT,
514544
DRIVER_TP, bu21013_data);
515545
if (error) {
516-
dev_err(&client->dev, "request irq %d failed\n", pdata->irq);
546+
dev_err(&client->dev, "request irq %d failed\n",
547+
bu21013_data->irq);
517548
goto err_cs_disable;
518549
}
519550

@@ -531,7 +562,7 @@ static int bu21013_probe(struct i2c_client *client,
531562
err_free_irq:
532563
bu21013_free_irq(bu21013_data);
533564
err_cs_disable:
534-
pdata->cs_dis(pdata->cs_pin);
565+
bu21013_cs_disable(bu21013_data);
535566
err_disable_regulator:
536567
regulator_disable(bu21013_data->regulator);
537568
err_put_regulator:
@@ -555,7 +586,7 @@ static int bu21013_remove(struct i2c_client *client)
555586

556587
bu21013_free_irq(bu21013_data);
557588

558-
bu21013_data->chip->cs_dis(bu21013_data->chip->cs_pin);
589+
bu21013_cs_disable(bu21013_data);
559590

560591
input_unregister_device(bu21013_data->in_dev);
561592

@@ -584,9 +615,9 @@ static int bu21013_suspend(struct device *dev)
584615

585616
bu21013_data->touch_stopped = true;
586617
if (device_may_wakeup(&client->dev))
587-
enable_irq_wake(bu21013_data->chip->irq);
618+
enable_irq_wake(bu21013_data->irq);
588619
else
589-
disable_irq(bu21013_data->chip->irq);
620+
disable_irq(bu21013_data->irq);
590621

591622
regulator_disable(bu21013_data->regulator);
592623

@@ -621,9 +652,9 @@ static int bu21013_resume(struct device *dev)
621652
bu21013_data->touch_stopped = false;
622653

623654
if (device_may_wakeup(&client->dev))
624-
disable_irq_wake(bu21013_data->chip->irq);
655+
disable_irq_wake(bu21013_data->irq);
625656
else
626-
enable_irq(bu21013_data->chip->irq);
657+
enable_irq(bu21013_data->irq);
627658

628659
return 0;
629660
}

include/linux/input/bu21013.h

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,10 @@
99

1010
/**
1111
* 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
1512
* @touch_x_max: touch x max
1613
* @touch_y_max: touch y max
1714
* @cs_pin: chip select pin
18-
* @irq: irq pin
15+
* @touch_pin: touch gpio pin
1916
* @ext_clk: external clock flag
2017
* @x_flip: x flip flag
2118
* @y_flip: y flip flag
@@ -24,13 +21,10 @@
2421
* This is used to handle the platform data
2522
*/
2623
struct bu21013_platform_device {
27-
int (*cs_en)(int reset_pin);
28-
int (*cs_dis)(int reset_pin);
29-
int (*irq_read_val)(void);
3024
int touch_x_max;
3125
int touch_y_max;
3226
unsigned int cs_pin;
33-
unsigned int irq;
27+
unsigned int touch_pin;
3428
bool ext_clk;
3529
bool x_flip;
3630
bool y_flip;

0 commit comments

Comments
 (0)