29
29
#include <linux/of_device.h>
30
30
#include <linux/of_irq.h>
31
31
#include <linux/suspend.h>
32
+ #include <linux/gpio/consumer.h>
32
33
#include <asm/unaligned.h>
33
34
34
35
#include <net/bluetooth/bluetooth.h>
@@ -439,6 +440,7 @@ static const struct dmi_system_id btusb_needs_reset_resume_table[] = {
439
440
#define BTUSB_BOOTING 9
440
441
#define BTUSB_DIAG_RUNNING 10
441
442
#define BTUSB_OOB_WAKE_ENABLED 11
443
+ #define BTUSB_HW_RESET_ACTIVE 12
442
444
443
445
struct btusb_data {
444
446
struct hci_dev * hdev ;
@@ -476,6 +478,8 @@ struct btusb_data {
476
478
struct usb_endpoint_descriptor * diag_tx_ep ;
477
479
struct usb_endpoint_descriptor * diag_rx_ep ;
478
480
481
+ struct gpio_desc * reset_gpio ;
482
+
479
483
__u8 cmdreq_type ;
480
484
__u8 cmdreq ;
481
485
@@ -489,8 +493,41 @@ struct btusb_data {
489
493
int (* setup_on_usb )(struct hci_dev * hdev );
490
494
491
495
int oob_wake_irq ; /* irq for out-of-band wake-on-bt */
496
+ unsigned cmd_timeout_cnt ;
492
497
};
493
498
499
+
500
+ static void btusb_intel_cmd_timeout (struct hci_dev * hdev )
501
+ {
502
+ struct btusb_data * data = hci_get_drvdata (hdev );
503
+ struct gpio_desc * reset_gpio = data -> reset_gpio ;
504
+
505
+ if (++ data -> cmd_timeout_cnt < 5 )
506
+ return ;
507
+
508
+ if (!reset_gpio ) {
509
+ bt_dev_err (hdev , "No way to reset. Ignoring and continuing" );
510
+ return ;
511
+ }
512
+
513
+ /*
514
+ * Toggle the hard reset line if the platform provides one. The reset
515
+ * is going to yank the device off the USB and then replug. So doing
516
+ * once is enough. The cleanup is handled correctly on the way out
517
+ * (standard USB disconnect), and the new device is detected cleanly
518
+ * and bound to the driver again like it should be.
519
+ */
520
+ if (test_and_set_bit (BTUSB_HW_RESET_ACTIVE , & data -> flags )) {
521
+ bt_dev_err (hdev , "last reset failed? Not resetting again" );
522
+ return ;
523
+ }
524
+
525
+ bt_dev_err (hdev , "Initiating HW reset via gpio" );
526
+ gpiod_set_value (reset_gpio , 1 );
527
+ mdelay (100 );
528
+ gpiod_set_value (reset_gpio , 0 );
529
+ }
530
+
494
531
static inline void btusb_free_frags (struct btusb_data * data )
495
532
{
496
533
unsigned long flags ;
@@ -2915,6 +2952,7 @@ static int btusb_probe(struct usb_interface *intf,
2915
2952
const struct usb_device_id * id )
2916
2953
{
2917
2954
struct usb_endpoint_descriptor * ep_desc ;
2955
+ struct gpio_desc * reset_gpio ;
2918
2956
struct btusb_data * data ;
2919
2957
struct hci_dev * hdev ;
2920
2958
unsigned ifnum_base ;
@@ -3028,6 +3066,15 @@ static int btusb_probe(struct usb_interface *intf,
3028
3066
3029
3067
SET_HCIDEV_DEV (hdev , & intf -> dev );
3030
3068
3069
+ reset_gpio = gpiod_get_optional (& data -> udev -> dev , "reset" ,
3070
+ GPIOD_OUT_LOW );
3071
+ if (IS_ERR (reset_gpio )) {
3072
+ err = PTR_ERR (reset_gpio );
3073
+ goto out_free_dev ;
3074
+ } else if (reset_gpio ) {
3075
+ data -> reset_gpio = reset_gpio ;
3076
+ }
3077
+
3031
3078
hdev -> open = btusb_open ;
3032
3079
hdev -> close = btusb_close ;
3033
3080
hdev -> flush = btusb_flush ;
@@ -3082,6 +3129,7 @@ static int btusb_probe(struct usb_interface *intf,
3082
3129
hdev -> shutdown = btusb_shutdown_intel ;
3083
3130
hdev -> set_diag = btintel_set_diag_mfg ;
3084
3131
hdev -> set_bdaddr = btintel_set_bdaddr ;
3132
+ hdev -> cmd_timeout = btusb_intel_cmd_timeout ;
3085
3133
set_bit (HCI_QUIRK_STRICT_DUPLICATE_FILTER , & hdev -> quirks );
3086
3134
set_bit (HCI_QUIRK_SIMULTANEOUS_DISCOVERY , & hdev -> quirks );
3087
3135
set_bit (HCI_QUIRK_NON_PERSISTENT_DIAG , & hdev -> quirks );
@@ -3094,6 +3142,7 @@ static int btusb_probe(struct usb_interface *intf,
3094
3142
hdev -> hw_error = btintel_hw_error ;
3095
3143
hdev -> set_diag = btintel_set_diag ;
3096
3144
hdev -> set_bdaddr = btintel_set_bdaddr ;
3145
+ hdev -> cmd_timeout = btusb_intel_cmd_timeout ;
3097
3146
set_bit (HCI_QUIRK_STRICT_DUPLICATE_FILTER , & hdev -> quirks );
3098
3147
set_bit (HCI_QUIRK_SIMULTANEOUS_DISCOVERY , & hdev -> quirks );
3099
3148
set_bit (HCI_QUIRK_NON_PERSISTENT_DIAG , & hdev -> quirks );
@@ -3226,6 +3275,8 @@ static int btusb_probe(struct usb_interface *intf,
3226
3275
return 0 ;
3227
3276
3228
3277
out_free_dev :
3278
+ if (data -> reset_gpio )
3279
+ gpiod_put (data -> reset_gpio );
3229
3280
hci_free_dev (hdev );
3230
3281
return err ;
3231
3282
}
@@ -3269,6 +3320,9 @@ static void btusb_disconnect(struct usb_interface *intf)
3269
3320
if (data -> oob_wake_irq )
3270
3321
device_init_wakeup (& data -> udev -> dev , false);
3271
3322
3323
+ if (data -> reset_gpio )
3324
+ gpiod_put (data -> reset_gpio );
3325
+
3272
3326
hci_free_dev (hdev );
3273
3327
}
3274
3328
0 commit comments