@@ -240,52 +240,57 @@ static inline void set_scan_rate(struct synaptics_i2c *touch, int scan_rate)
240240 */
241241static s32 synaptics_i2c_reg_get (struct i2c_client * client , u16 reg )
242242{
243- int ret ;
243+ int error ;
244244
245- ret = i2c_smbus_write_byte_data (client , PAGE_SEL_REG , reg >> 8 );
246- if (ret == 0 )
247- ret = i2c_smbus_read_byte_data ( client , reg & 0xff ) ;
245+ error = i2c_smbus_write_byte_data (client , PAGE_SEL_REG , reg >> 8 );
246+ if (error )
247+ return error ;
248248
249- return ret ;
249+ return i2c_smbus_read_byte_data ( client , reg & 0xff ) ;
250250}
251251
252252static s32 synaptics_i2c_reg_set (struct i2c_client * client , u16 reg , u8 val )
253253{
254- int ret ;
254+ int error ;
255255
256- ret = i2c_smbus_write_byte_data (client , PAGE_SEL_REG , reg >> 8 );
257- if (ret == 0 )
258- ret = i2c_smbus_write_byte_data ( client , reg & 0xff , val ) ;
256+ error = i2c_smbus_write_byte_data (client , PAGE_SEL_REG , reg >> 8 );
257+ if (error )
258+ return error ;
259259
260- return ret ;
260+ error = i2c_smbus_write_byte_data (client , reg & 0xff , val );
261+ if (error )
262+ return error ;
263+
264+ return error ;
261265}
262266
263267static s32 synaptics_i2c_word_get (struct i2c_client * client , u16 reg )
264268{
265- int ret ;
269+ int error ;
266270
267- ret = i2c_smbus_write_byte_data (client , PAGE_SEL_REG , reg >> 8 );
268- if (ret == 0 )
269- ret = i2c_smbus_read_word_data ( client , reg & 0xff ) ;
271+ error = i2c_smbus_write_byte_data (client , PAGE_SEL_REG , reg >> 8 );
272+ if (error )
273+ return error ;
270274
271- return ret ;
275+ return i2c_smbus_read_word_data ( client , reg & 0xff ) ;
272276}
273277
274278static int synaptics_i2c_config (struct i2c_client * client )
275279{
276- int ret , control ;
280+ int control ;
281+ int error ;
277282 u8 int_en ;
278283
279284 /* set Report Rate to Device Highest (>=80) and Sleep to normal */
280- ret = synaptics_i2c_reg_set (client , DEV_CONTROL_REG , 0xc1 );
281- if (ret )
282- return ret ;
285+ error = synaptics_i2c_reg_set (client , DEV_CONTROL_REG , 0xc1 );
286+ if (error )
287+ return error ;
283288
284289 /* set Interrupt Disable to Func20 / Enable to Func10) */
285290 int_en = (polling_req ) ? 0 : INT_ENA_ABS_MSK | INT_ENA_REL_MSK ;
286- ret = synaptics_i2c_reg_set (client , INTERRUPT_EN_REG , int_en );
287- if (ret )
288- return ret ;
291+ error = synaptics_i2c_reg_set (client , INTERRUPT_EN_REG , int_en );
292+ if (error )
293+ return error ;
289294
290295 control = synaptics_i2c_reg_get (client , GENERAL_2D_CONTROL_REG );
291296 /* No Deceleration */
@@ -294,42 +299,49 @@ static int synaptics_i2c_config(struct i2c_client *client)
294299 control |= reduce_report ? 1 << REDUCE_REPORTING : 0 ;
295300 /* No Filter */
296301 control |= no_filter ? 1 << NO_FILTER : 0 ;
297- ret = synaptics_i2c_reg_set (client , GENERAL_2D_CONTROL_REG , control );
298- if (ret )
299- return ret ;
302+ error = synaptics_i2c_reg_set (client , GENERAL_2D_CONTROL_REG , control );
303+ if (error )
304+ return error ;
300305
301306 return 0 ;
302307}
303308
304309static int synaptics_i2c_reset_config (struct i2c_client * client )
305310{
306- int ret ;
311+ int error ;
307312
308313 /* Reset the Touchpad */
309- ret = synaptics_i2c_reg_set (client , DEV_COMMAND_REG , RESET_COMMAND );
310- if (ret ) {
314+ error = synaptics_i2c_reg_set (client , DEV_COMMAND_REG , RESET_COMMAND );
315+ if (error ) {
311316 dev_err (& client -> dev , "Unable to reset device\n" );
312- } else {
313- usleep_range (SOFT_RESET_DELAY_US , SOFT_RESET_DELAY_US + 100 );
314- ret = synaptics_i2c_config (client );
315- if (ret )
316- dev_err (& client -> dev , "Unable to config device\n" );
317+ return error ;
318+ }
319+
320+ usleep_range (SOFT_RESET_DELAY_US , SOFT_RESET_DELAY_US + 100 );
321+ error = synaptics_i2c_config (client );
322+ if (error ) {
323+ dev_err (& client -> dev , "Unable to config device\n" );
324+ return error ;
317325 }
318326
319- return ret ;
327+ return 0 ;
320328}
321329
322330static int synaptics_i2c_check_error (struct i2c_client * client )
323331{
324- int status , ret = 0 ;
332+ int status ;
333+ int error ;
325334
326335 status = i2c_smbus_read_byte_data (client , DEVICE_STATUS_REG ) &
327336 (CONFIGURED_MSK | ERROR_MSK );
328337
329- if (status != CONFIGURED_MSK )
330- ret = synaptics_i2c_reset_config (client );
338+ if (status != CONFIGURED_MSK ) {
339+ error = synaptics_i2c_reset_config (client );
340+ if (error )
341+ return error ;
342+ }
331343
332- return ret ;
344+ return 0 ;
333345}
334346
335347static bool synaptics_i2c_get_input (struct synaptics_i2c * touch )
@@ -421,10 +433,10 @@ static unsigned long synaptics_i2c_adjust_delay(struct synaptics_i2c *touch,
421433 delay = NO_DATA_SLEEP_MSECS ;
422434 }
423435 return msecs_to_jiffies (delay );
424- } else {
425- delay = msecs_to_jiffies (THREAD_IRQ_SLEEP_MSECS );
426- return round_jiffies_relative (delay );
427436 }
437+
438+ delay = msecs_to_jiffies (THREAD_IRQ_SLEEP_MSECS );
439+ return round_jiffies_relative (delay );
428440}
429441
430442/* Work Handler */
@@ -454,15 +466,15 @@ static void synaptics_i2c_work_handler(struct work_struct *work)
454466static int synaptics_i2c_open (struct input_dev * input )
455467{
456468 struct synaptics_i2c * touch = input_get_drvdata (input );
457- int ret ;
469+ int error ;
458470
459- ret = synaptics_i2c_reset_config (touch -> client );
460- if (ret )
461- return ret ;
471+ error = synaptics_i2c_reset_config (touch -> client );
472+ if (error )
473+ return error ;
462474
463475 if (polling_req )
464476 mod_delayed_work (system_dfl_wq , & touch -> dwork ,
465- msecs_to_jiffies (NO_DATA_SLEEP_MSECS ));
477+ msecs_to_jiffies (NO_DATA_SLEEP_MSECS ));
466478
467479 return 0 ;
468480}
@@ -489,112 +501,74 @@ static void synaptics_i2c_set_input_params(struct synaptics_i2c *touch)
489501 input -> id .bustype = BUS_I2C ;
490502 input -> id .version = synaptics_i2c_word_get (touch -> client ,
491503 INFO_QUERY_REG0 );
492- input -> dev .parent = & touch -> client -> dev ;
493504 input -> open = synaptics_i2c_open ;
494505 input -> close = synaptics_i2c_close ;
495506 input_set_drvdata (input , touch );
496507
497508 /* Register the device as mouse */
498- __set_bit (EV_REL , input -> evbit );
499- __set_bit (REL_X , input -> relbit );
500- __set_bit (REL_Y , input -> relbit );
509+ input_set_capability (input , EV_REL , REL_X );
510+ input_set_capability (input , EV_REL , REL_Y );
501511
502512 /* Register device's buttons and keys */
503- __set_bit (EV_KEY , input -> evbit );
504- __set_bit (BTN_LEFT , input -> keybit );
513+ input_set_capability (input , EV_KEY , BTN_LEFT );
505514}
506515
507- static struct synaptics_i2c * synaptics_i2c_touch_create (struct i2c_client * client )
516+ static int synaptics_i2c_probe (struct i2c_client * client )
508517{
518+ struct device * dev = & client -> dev ;
509519 struct synaptics_i2c * touch ;
520+ int error ;
510521
511- touch = kzalloc ( sizeof (* touch ), GFP_KERNEL );
522+ touch = devm_kzalloc ( dev , sizeof (* touch ), GFP_KERNEL );
512523 if (!touch )
513- return NULL ;
524+ return - ENOMEM ;
514525
515526 touch -> client = client ;
516527 touch -> no_decel_param = no_decel ;
517528 touch -> scan_rate_param = scan_rate ;
518529 set_scan_rate (touch , scan_rate );
519530 INIT_DELAYED_WORK (& touch -> dwork , synaptics_i2c_work_handler );
520531
521- return touch ;
522- }
523-
524- static int synaptics_i2c_probe (struct i2c_client * client )
525- {
526- int ret ;
527- struct synaptics_i2c * touch ;
532+ error = synaptics_i2c_reset_config (client );
533+ if (error )
534+ return error ;
528535
529- touch = synaptics_i2c_touch_create (client );
530- if (!touch )
531- return - ENOMEM ;
532-
533- ret = synaptics_i2c_reset_config (client );
534- if (ret )
535- goto err_mem_free ;
536-
537- if (client -> irq < 1 )
536+ if (client -> irq <= 0 )
538537 polling_req = true;
539538
540- touch -> input = input_allocate_device ();
541- if (!touch -> input ) {
542- ret = - ENOMEM ;
543- goto err_mem_free ;
544- }
539+ touch -> input = devm_input_allocate_device (dev );
540+ if (!touch -> input )
541+ return - ENOMEM ;
545542
546543 synaptics_i2c_set_input_params (touch );
547544
548545 if (!polling_req ) {
549- dev_dbg (& touch -> client -> dev ,
550- "Requesting IRQ: %d\n" , touch -> client -> irq );
551-
552- ret = request_irq (touch -> client -> irq , synaptics_i2c_irq ,
553- IRQ_TYPE_EDGE_FALLING ,
554- DRIVER_NAME , touch );
555- if (ret ) {
556- dev_warn (& touch -> client -> dev ,
557- "IRQ request failed: %d, "
558- "falling back to polling\n" , ret );
546+ dev_dbg (dev , "Requesting IRQ: %d\n" , client -> irq );
547+
548+ error = devm_request_irq (dev , client -> irq , synaptics_i2c_irq ,
549+ IRQ_TYPE_EDGE_FALLING ,
550+ DRIVER_NAME , touch );
551+ if (error ) {
552+ dev_warn (dev , "IRQ request failed: %d, falling back to polling\n" ,
553+ error );
559554 polling_req = true;
560- synaptics_i2c_reg_set (touch -> client ,
561- INTERRUPT_EN_REG , 0 );
555+ synaptics_i2c_reg_set (client , INTERRUPT_EN_REG , 0 );
562556 }
563557 }
564558
565559 if (polling_req )
566- dev_dbg (& touch -> client -> dev ,
567- "Using polling at rate: %d times/sec\n" , scan_rate );
560+ dev_dbg (dev , "Using polling at rate: %d times/sec\n" , scan_rate );
568561
569562 /* Register the device in input subsystem */
570- ret = input_register_device (touch -> input );
571- if (ret ) {
572- dev_err (& client -> dev ,
573- "Input device register failed: %d\n" , ret );
574- goto err_input_free ;
563+ error = input_register_device (touch -> input );
564+ if (error ) {
565+ dev_err (dev , "Input device register failed: %d\n" , error );
566+ return error ;
575567 }
576568
577569 i2c_set_clientdata (client , touch );
578570
579571 return 0 ;
580-
581- err_input_free :
582- input_free_device (touch -> input );
583- err_mem_free :
584- kfree (touch );
585-
586- return ret ;
587- }
588-
589- static void synaptics_i2c_remove (struct i2c_client * client )
590- {
591- struct synaptics_i2c * touch = i2c_get_clientdata (client );
592-
593- if (!polling_req )
594- free_irq (client -> irq , touch );
595-
596- input_unregister_device (touch -> input );
597- kfree (touch );
598572}
599573
600574static int synaptics_i2c_suspend (struct device * dev )
@@ -612,14 +586,14 @@ static int synaptics_i2c_suspend(struct device *dev)
612586
613587static int synaptics_i2c_resume (struct device * dev )
614588{
615- int ret ;
616589 struct i2c_client * client = to_i2c_client (dev );
617590 struct synaptics_i2c * touch = i2c_get_clientdata (client );
618591 struct input_dev * input = touch -> input ;
592+ int error ;
619593
620- ret = synaptics_i2c_reset_config (client );
621- if (ret )
622- return ret ;
594+ error = synaptics_i2c_reset_config (client );
595+ if (error )
596+ return error ;
623597
624598 guard (mutex )(& input -> mutex );
625599 if (input_device_enabled (input ))
@@ -654,8 +628,6 @@ static struct i2c_driver synaptics_i2c_driver = {
654628 },
655629
656630 .probe = synaptics_i2c_probe ,
657- .remove = synaptics_i2c_remove ,
658-
659631 .id_table = synaptics_i2c_id_table ,
660632};
661633
0 commit comments