14
14
#include <linux/module.h>
15
15
#include <linux/i2c.h>
16
16
#include <linux/input.h>
17
- #include <linux/input-polldev.h>
18
17
#include <linux/interrupt.h>
19
18
#include <linux/delay.h>
20
19
#include <linux/slab.h>
123
122
124
123
struct bma150_data {
125
124
struct i2c_client * client ;
126
- struct input_polled_dev * input_polled ;
127
125
struct input_dev * input ;
128
126
u8 mode ;
129
127
};
@@ -336,13 +334,16 @@ static irqreturn_t bma150_irq_thread(int irq, void *dev)
336
334
return IRQ_HANDLED ;
337
335
}
338
336
339
- static void bma150_poll (struct input_polled_dev * dev )
337
+ static void bma150_poll (struct input_dev * input )
340
338
{
341
- bma150_report_xyz (dev -> private );
339
+ struct bma150_data * bma150 = input_get_drvdata (input );
340
+
341
+ bma150_report_xyz (bma150 );
342
342
}
343
343
344
- static int bma150_open (struct bma150_data * bma150 )
344
+ static int bma150_open (struct input_dev * input )
345
345
{
346
+ struct bma150_data * bma150 = input_get_drvdata (input );
346
347
int error ;
347
348
348
349
error = pm_runtime_get_sync (& bma150 -> client -> dev );
@@ -362,44 +363,18 @@ static int bma150_open(struct bma150_data *bma150)
362
363
return 0 ;
363
364
}
364
365
365
- static void bma150_close (struct bma150_data * bma150 )
366
+ static void bma150_close (struct input_dev * input )
366
367
{
368
+ struct bma150_data * bma150 = input_get_drvdata (input );
369
+
367
370
pm_runtime_put_sync (& bma150 -> client -> dev );
368
371
369
372
if (bma150 -> mode != BMA150_MODE_SLEEP )
370
373
bma150_set_mode (bma150 , BMA150_MODE_SLEEP );
371
374
}
372
375
373
- static int bma150_irq_open (struct input_dev * input )
374
- {
375
- struct bma150_data * bma150 = input_get_drvdata (input );
376
-
377
- return bma150_open (bma150 );
378
- }
379
-
380
- static void bma150_irq_close (struct input_dev * input )
381
- {
382
- struct bma150_data * bma150 = input_get_drvdata (input );
383
-
384
- bma150_close (bma150 );
385
- }
386
-
387
- static void bma150_poll_open (struct input_polled_dev * ipoll_dev )
388
- {
389
- struct bma150_data * bma150 = ipoll_dev -> private ;
390
-
391
- bma150_open (bma150 );
392
- }
393
-
394
- static void bma150_poll_close (struct input_polled_dev * ipoll_dev )
395
- {
396
- struct bma150_data * bma150 = ipoll_dev -> private ;
397
-
398
- bma150_close (bma150 );
399
- }
400
-
401
376
static int bma150_initialize (struct bma150_data * bma150 ,
402
- const struct bma150_cfg * cfg )
377
+ const struct bma150_cfg * cfg )
403
378
{
404
379
int error ;
405
380
@@ -439,78 +414,14 @@ static int bma150_initialize(struct bma150_data *bma150,
439
414
return bma150_set_mode (bma150 , BMA150_MODE_SLEEP );
440
415
}
441
416
442
- static void bma150_init_input_device (struct input_dev * idev )
443
- {
444
- idev -> name = BMA150_DRIVER ;
445
- idev -> phys = BMA150_DRIVER "/input0" ;
446
- idev -> id .bustype = BUS_I2C ;
447
-
448
- idev -> evbit [0 ] = BIT_MASK (EV_ABS );
449
- input_set_abs_params (idev , ABS_X , ABSMIN_ACC_VAL , ABSMAX_ACC_VAL , 0 , 0 );
450
- input_set_abs_params (idev , ABS_Y , ABSMIN_ACC_VAL , ABSMAX_ACC_VAL , 0 , 0 );
451
- input_set_abs_params (idev , ABS_Z , ABSMIN_ACC_VAL , ABSMAX_ACC_VAL , 0 , 0 );
452
- }
453
-
454
- static int bma150_register_input_device (struct bma150_data * bma150 )
455
- {
456
- struct input_dev * idev ;
457
- int error ;
458
-
459
- idev = devm_input_allocate_device (& bma150 -> client -> dev );
460
- if (!idev )
461
- return - ENOMEM ;
462
-
463
- bma150_init_input_device (idev );
464
-
465
- idev -> open = bma150_irq_open ;
466
- idev -> close = bma150_irq_close ;
467
- input_set_drvdata (idev , bma150 );
468
-
469
- bma150 -> input = idev ;
470
-
471
- error = input_register_device (idev );
472
- if (error )
473
- return error ;
474
-
475
- return 0 ;
476
- }
477
-
478
- static int bma150_register_polled_device (struct bma150_data * bma150 )
479
- {
480
- struct input_polled_dev * ipoll_dev ;
481
- int error ;
482
-
483
- ipoll_dev = devm_input_allocate_polled_device (& bma150 -> client -> dev );
484
- if (!ipoll_dev )
485
- return - ENOMEM ;
486
-
487
- ipoll_dev -> private = bma150 ;
488
- ipoll_dev -> open = bma150_poll_open ;
489
- ipoll_dev -> close = bma150_poll_close ;
490
- ipoll_dev -> poll = bma150_poll ;
491
- ipoll_dev -> poll_interval = BMA150_POLL_INTERVAL ;
492
- ipoll_dev -> poll_interval_min = BMA150_POLL_MIN ;
493
- ipoll_dev -> poll_interval_max = BMA150_POLL_MAX ;
494
-
495
- bma150_init_input_device (ipoll_dev -> input );
496
-
497
- bma150 -> input_polled = ipoll_dev ;
498
- bma150 -> input = ipoll_dev -> input ;
499
-
500
- error = input_register_polled_device (ipoll_dev );
501
- if (error )
502
- return error ;
503
-
504
- return 0 ;
505
- }
506
-
507
417
static int bma150_probe (struct i2c_client * client ,
508
- const struct i2c_device_id * id )
418
+ const struct i2c_device_id * id )
509
419
{
510
420
const struct bma150_platform_data * pdata =
511
421
dev_get_platdata (& client -> dev );
512
422
const struct bma150_cfg * cfg ;
513
423
struct bma150_data * bma150 ;
424
+ struct input_dev * idev ;
514
425
int chip_id ;
515
426
int error ;
516
427
@@ -550,11 +461,39 @@ static int bma150_probe(struct i2c_client *client,
550
461
if (error )
551
462
return error ;
552
463
553
- if (client -> irq > 0 ) {
554
- error = bma150_register_input_device (bma150 );
464
+ idev = devm_input_allocate_device (& bma150 -> client -> dev );
465
+ if (!idev )
466
+ return - ENOMEM ;
467
+
468
+ input_set_drvdata (idev , bma150 );
469
+ bma150 -> input = idev ;
470
+
471
+ idev -> name = BMA150_DRIVER ;
472
+ idev -> phys = BMA150_DRIVER "/input0" ;
473
+ idev -> id .bustype = BUS_I2C ;
474
+
475
+ idev -> open = bma150_open ;
476
+ idev -> close = bma150_close ;
477
+
478
+ input_set_abs_params (idev , ABS_X , ABSMIN_ACC_VAL , ABSMAX_ACC_VAL , 0 , 0 );
479
+ input_set_abs_params (idev , ABS_Y , ABSMIN_ACC_VAL , ABSMAX_ACC_VAL , 0 , 0 );
480
+ input_set_abs_params (idev , ABS_Z , ABSMIN_ACC_VAL , ABSMAX_ACC_VAL , 0 , 0 );
481
+
482
+ if (client -> irq <= 0 ) {
483
+ error = input_setup_polling (idev , bma150_poll );
555
484
if (error )
556
485
return error ;
557
486
487
+ input_set_poll_interval (idev , BMA150_POLL_INTERVAL );
488
+ input_set_min_poll_interval (idev , BMA150_POLL_MIN );
489
+ input_set_max_poll_interval (idev , BMA150_POLL_MAX );
490
+ }
491
+
492
+ error = input_register_device (idev );
493
+ if (error )
494
+ return error ;
495
+
496
+ if (client -> irq > 0 ) {
558
497
error = devm_request_threaded_irq (& client -> dev , client -> irq ,
559
498
NULL , bma150_irq_thread ,
560
499
IRQF_TRIGGER_RISING | IRQF_ONESHOT ,
@@ -565,10 +504,6 @@ static int bma150_probe(struct i2c_client *client,
565
504
client -> irq , error );
566
505
return error ;
567
506
}
568
- } else {
569
- error = bma150_register_polled_device (bma150 );
570
- if (error )
571
- return error ;
572
507
}
573
508
574
509
i2c_set_clientdata (client , bma150 );
@@ -585,23 +520,21 @@ static int bma150_remove(struct i2c_client *client)
585
520
return 0 ;
586
521
}
587
522
588
- #ifdef CONFIG_PM
589
- static int bma150_suspend (struct device * dev )
523
+ static int __maybe_unused bma150_suspend (struct device * dev )
590
524
{
591
525
struct i2c_client * client = to_i2c_client (dev );
592
526
struct bma150_data * bma150 = i2c_get_clientdata (client );
593
527
594
528
return bma150_set_mode (bma150 , BMA150_MODE_SLEEP );
595
529
}
596
530
597
- static int bma150_resume (struct device * dev )
531
+ static int __maybe_unused bma150_resume (struct device * dev )
598
532
{
599
533
struct i2c_client * client = to_i2c_client (dev );
600
534
struct bma150_data * bma150 = i2c_get_clientdata (client );
601
535
602
536
return bma150_set_mode (bma150 , BMA150_MODE_NORMAL );
603
537
}
604
- #endif
605
538
606
539
static UNIVERSAL_DEV_PM_OPS (bma150_pm , bma150_suspend , bma150_resume , NULL) ;
607
540
0 commit comments