@@ -1997,7 +1997,7 @@ static int wacom_initialize_remotes(struct wacom *wacom)
1997
1997
spin_lock_init (& remote -> remote_lock );
1998
1998
1999
1999
error = kfifo_alloc (& remote -> remote_fifo ,
2000
- 5 * sizeof (struct wacom_remote_data ),
2000
+ 5 * sizeof (struct wacom_remote_work_data ),
2001
2001
GFP_KERNEL );
2002
2002
if (error ) {
2003
2003
hid_err (wacom -> hdev , "failed allocating remote_fifo\n" );
@@ -2523,6 +2523,18 @@ static void wacom_wireless_work(struct work_struct *work)
2523
2523
return ;
2524
2524
}
2525
2525
2526
+ static void wacom_remote_destroy_battery (struct wacom * wacom , int index )
2527
+ {
2528
+ struct wacom_remote * remote = wacom -> remote ;
2529
+
2530
+ if (remote -> remotes [index ].battery .battery ) {
2531
+ devres_release_group (& wacom -> hdev -> dev ,
2532
+ & remote -> remotes [index ].battery .bat_desc );
2533
+ remote -> remotes [index ].battery .battery = NULL ;
2534
+ remote -> remotes [index ].active_time = 0 ;
2535
+ }
2536
+ }
2537
+
2526
2538
static void wacom_remote_destroy_one (struct wacom * wacom , unsigned int index )
2527
2539
{
2528
2540
struct wacom_remote * remote = wacom -> remote ;
@@ -2537,17 +2549,14 @@ static void wacom_remote_destroy_one(struct wacom *wacom, unsigned int index)
2537
2549
remote -> remotes [i ].registered = false;
2538
2550
spin_unlock_irqrestore (& remote -> remote_lock , flags );
2539
2551
2540
- if (remote -> remotes [i ].battery .battery )
2541
- devres_release_group (& wacom -> hdev -> dev ,
2542
- & remote -> remotes [i ].battery .bat_desc );
2552
+ wacom_remote_destroy_battery (wacom , i );
2543
2553
2544
2554
if (remote -> remotes [i ].group .name )
2545
2555
devres_release_group (& wacom -> hdev -> dev ,
2546
2556
& remote -> remotes [i ]);
2547
2557
2548
2558
remote -> remotes [i ].serial = 0 ;
2549
2559
remote -> remotes [i ].group .name = NULL ;
2550
- remote -> remotes [i ].battery .battery = NULL ;
2551
2560
wacom -> led .groups [i ].select = WACOM_STATUS_UNKNOWN ;
2552
2561
}
2553
2562
}
@@ -2632,6 +2641,9 @@ static int wacom_remote_attach_battery(struct wacom *wacom, int index)
2632
2641
if (remote -> remotes [index ].battery .battery )
2633
2642
return 0 ;
2634
2643
2644
+ if (!remote -> remotes [index ].active_time )
2645
+ return 0 ;
2646
+
2635
2647
if (wacom -> led .groups [index ].select == WACOM_STATUS_UNKNOWN )
2636
2648
return 0 ;
2637
2649
@@ -2647,17 +2659,19 @@ static void wacom_remote_work(struct work_struct *work)
2647
2659
{
2648
2660
struct wacom * wacom = container_of (work , struct wacom , remote_work );
2649
2661
struct wacom_remote * remote = wacom -> remote ;
2650
- struct wacom_remote_data data ;
2662
+ ktime_t kt = ktime_get ();
2663
+ struct wacom_remote_work_data remote_work_data ;
2651
2664
unsigned long flags ;
2652
2665
unsigned int count ;
2653
- u32 serial ;
2666
+ u32 work_serial ;
2654
2667
int i ;
2655
2668
2656
2669
spin_lock_irqsave (& remote -> remote_lock , flags );
2657
2670
2658
- count = kfifo_out (& remote -> remote_fifo , & data , sizeof (data ));
2671
+ count = kfifo_out (& remote -> remote_fifo , & remote_work_data ,
2672
+ sizeof (remote_work_data ));
2659
2673
2660
- if (count != sizeof (data )) {
2674
+ if (count != sizeof (remote_work_data )) {
2661
2675
hid_err (wacom -> hdev ,
2662
2676
"workitem triggered without status available\n" );
2663
2677
spin_unlock_irqrestore (& remote -> remote_lock , flags );
@@ -2670,18 +2684,22 @@ static void wacom_remote_work(struct work_struct *work)
2670
2684
spin_unlock_irqrestore (& remote -> remote_lock , flags );
2671
2685
2672
2686
for (i = 0 ; i < WACOM_MAX_REMOTES ; i ++ ) {
2673
- serial = data .remote [i ].serial ;
2674
- if (data .remote [i ].connected ) {
2687
+ work_serial = remote_work_data .remote [i ].serial ;
2688
+ if (work_serial ) {
2689
+
2690
+ if (kt - remote -> remotes [i ].active_time > WACOM_REMOTE_BATTERY_TIMEOUT
2691
+ && remote -> remotes [i ].active_time != 0 )
2692
+ wacom_remote_destroy_battery (wacom , i );
2675
2693
2676
- if (remote -> remotes [i ].serial == serial ) {
2694
+ if (remote -> remotes [i ].serial == work_serial ) {
2677
2695
wacom_remote_attach_battery (wacom , i );
2678
2696
continue ;
2679
2697
}
2680
2698
2681
2699
if (remote -> remotes [i ].serial )
2682
2700
wacom_remote_destroy_one (wacom , i );
2683
2701
2684
- wacom_remote_create_one (wacom , serial , i );
2702
+ wacom_remote_create_one (wacom , work_serial , i );
2685
2703
2686
2704
} else if (remote -> remotes [i ].serial ) {
2687
2705
wacom_remote_destroy_one (wacom , i );
0 commit comments