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
148149struct 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 */
432457static 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,
531562err_free_irq :
532563 bu21013_free_irq (bu21013_data );
533564err_cs_disable :
534- pdata -> cs_dis ( pdata -> cs_pin );
565+ bu21013_cs_disable ( bu21013_data );
535566err_disable_regulator :
536567 regulator_disable (bu21013_data -> regulator );
537568err_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}
0 commit comments