@@ -1997,7 +1997,7 @@ static int wacom_initialize_remotes(struct wacom *wacom)
19971997 spin_lock_init (& remote -> remote_lock );
19981998
19991999 error = kfifo_alloc (& remote -> remote_fifo ,
2000- 5 * sizeof (struct wacom_remote_data ),
2000+ 5 * sizeof (struct wacom_remote_work_data ),
20012001 GFP_KERNEL );
20022002 if (error ) {
20032003 hid_err (wacom -> hdev , "failed allocating remote_fifo\n" );
@@ -2523,6 +2523,18 @@ static void wacom_wireless_work(struct work_struct *work)
25232523 return ;
25242524}
25252525
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+
25262538static void wacom_remote_destroy_one (struct wacom * wacom , unsigned int index )
25272539{
25282540 struct wacom_remote * remote = wacom -> remote ;
@@ -2537,17 +2549,14 @@ static void wacom_remote_destroy_one(struct wacom *wacom, unsigned int index)
25372549 remote -> remotes [i ].registered = false;
25382550 spin_unlock_irqrestore (& remote -> remote_lock , flags );
25392551
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 );
25432553
25442554 if (remote -> remotes [i ].group .name )
25452555 devres_release_group (& wacom -> hdev -> dev ,
25462556 & remote -> remotes [i ]);
25472557
25482558 remote -> remotes [i ].serial = 0 ;
25492559 remote -> remotes [i ].group .name = NULL ;
2550- remote -> remotes [i ].battery .battery = NULL ;
25512560 wacom -> led .groups [i ].select = WACOM_STATUS_UNKNOWN ;
25522561 }
25532562 }
@@ -2632,6 +2641,9 @@ static int wacom_remote_attach_battery(struct wacom *wacom, int index)
26322641 if (remote -> remotes [index ].battery .battery )
26332642 return 0 ;
26342643
2644+ if (!remote -> remotes [index ].active_time )
2645+ return 0 ;
2646+
26352647 if (wacom -> led .groups [index ].select == WACOM_STATUS_UNKNOWN )
26362648 return 0 ;
26372649
@@ -2647,17 +2659,19 @@ static void wacom_remote_work(struct work_struct *work)
26472659{
26482660 struct wacom * wacom = container_of (work , struct wacom , remote_work );
26492661 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 ;
26512664 unsigned long flags ;
26522665 unsigned int count ;
2653- u32 serial ;
2666+ u32 work_serial ;
26542667 int i ;
26552668
26562669 spin_lock_irqsave (& remote -> remote_lock , flags );
26572670
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 ));
26592673
2660- if (count != sizeof (data )) {
2674+ if (count != sizeof (remote_work_data )) {
26612675 hid_err (wacom -> hdev ,
26622676 "workitem triggered without status available\n" );
26632677 spin_unlock_irqrestore (& remote -> remote_lock , flags );
@@ -2670,18 +2684,22 @@ static void wacom_remote_work(struct work_struct *work)
26702684 spin_unlock_irqrestore (& remote -> remote_lock , flags );
26712685
26722686 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 );
26752693
2676- if (remote -> remotes [i ].serial == serial ) {
2694+ if (remote -> remotes [i ].serial == work_serial ) {
26772695 wacom_remote_attach_battery (wacom , i );
26782696 continue ;
26792697 }
26802698
26812699 if (remote -> remotes [i ].serial )
26822700 wacom_remote_destroy_one (wacom , i );
26832701
2684- wacom_remote_create_one (wacom , serial , i );
2702+ wacom_remote_create_one (wacom , work_serial , i );
26852703
26862704 } else if (remote -> remotes [i ].serial ) {
26872705 wacom_remote_destroy_one (wacom , i );
0 commit comments