1616#include <linux/crc8.h>
1717#include <linux/crc32.h>
1818#include <linux/string_helpers.h>
19+ #include <linux/gpio/consumer.h>
1920
2021#include <net/bluetooth/bluetooth.h>
2122#include <net/bluetooth/hci_core.h>
3435/* NXP HW err codes */
3536#define BTNXPUART_IR_HW_ERR 0xb0
3637
37- #define FIRMWARE_W8987 "uart8987_bt_v0 .bin"
38+ #define FIRMWARE_W8987 "uart8987_bt .bin"
3839#define FIRMWARE_W8987_OLD "uartuart8987_bt.bin"
3940#define FIRMWARE_W8997 "uart8997_bt_v4.bin"
4041#define FIRMWARE_W8997_OLD "uartuart8997_bt_v4.bin"
4142#define FIRMWARE_W9098 "uart9098_bt_v1.bin"
4243#define FIRMWARE_W9098_OLD "uartuart9098_bt_v1.bin"
43- #define FIRMWARE_IW416 "uartiw416_bt_v0.bin"
44+ #define FIRMWARE_IW416 "uartiw416_bt.bin"
45+ #define FIRMWARE_IW416_OLD "uartiw416_bt_v0.bin"
4446#define FIRMWARE_IW612 "uartspi_n61x_v1.bin.se"
45- #define FIRMWARE_IW615 "uartspi_iw610_v0 .bin"
46- #define FIRMWARE_SECURE_IW615 "uartspi_iw610_v0 .bin.se"
47+ #define FIRMWARE_IW610 "uartspi_iw610 .bin"
48+ #define FIRMWARE_SECURE_IW610 "uartspi_iw610 .bin.se"
4749#define FIRMWARE_IW624 "uartiw624_bt.bin"
4850#define FIRMWARE_SECURE_IW624 "uartiw624_bt.bin.se"
4951#define FIRMWARE_AW693 "uartaw693_bt.bin"
5961#define CHIP_ID_IW624c 0x8001
6062#define CHIP_ID_AW693a0 0x8200
6163#define CHIP_ID_AW693a1 0x8201
62- #define CHIP_ID_IW615a0 0x8800
63- #define CHIP_ID_IW615a1 0x8801
64+ #define CHIP_ID_IW610a0 0x8800
65+ #define CHIP_ID_IW610a1 0x8801
6466
6567#define FW_SECURE_MASK 0xc0
6668#define FW_OPEN 0x00
8183#define WAKEUP_METHOD_BREAK 1
8284#define WAKEUP_METHOD_EXT_BREAK 2
8385#define WAKEUP_METHOD_RTS 3
86+ #define WAKEUP_METHOD_GPIO 4
8487#define WAKEUP_METHOD_INVALID 0xff
8588
8689/* power save mode status */
@@ -134,6 +137,7 @@ struct ps_data {
134137 bool driver_sent_cmd ;
135138 u16 h2c_ps_interval ;
136139 u16 c2h_ps_interval ;
140+ struct gpio_desc * h2c_ps_gpio ;
137141 struct hci_dev * hdev ;
138142 struct work_struct work ;
139143 struct timer_list ps_timer ;
@@ -364,14 +368,22 @@ static void ps_control(struct hci_dev *hdev, u8 ps_state)
364368{
365369 struct btnxpuart_dev * nxpdev = hci_get_drvdata (hdev );
366370 struct ps_data * psdata = & nxpdev -> psdata ;
367- int status ;
371+ int status = 0 ;
368372
369373 if (psdata -> ps_state == ps_state ||
370374 !test_bit (BTNXPUART_SERDEV_OPEN , & nxpdev -> tx_state ))
371375 return ;
372376
373377 mutex_lock (& psdata -> ps_lock );
374378 switch (psdata -> cur_h2c_wakeupmode ) {
379+ case WAKEUP_METHOD_GPIO :
380+ if (ps_state == PS_STATE_AWAKE )
381+ gpiod_set_value_cansleep (psdata -> h2c_ps_gpio , 0 );
382+ else
383+ gpiod_set_value_cansleep (psdata -> h2c_ps_gpio , 1 );
384+ bt_dev_dbg (hdev , "Set h2c_ps_gpio: %s" ,
385+ str_high_low (ps_state == PS_STATE_SLEEP ));
386+ break ;
375387 case WAKEUP_METHOD_DTR :
376388 if (ps_state == PS_STATE_AWAKE )
377389 status = serdev_device_set_tiocm (nxpdev -> serdev , TIOCM_DTR , 0 );
@@ -421,15 +433,29 @@ static void ps_timeout_func(struct timer_list *t)
421433 }
422434}
423435
424- static void ps_setup (struct hci_dev * hdev )
436+ static int ps_setup (struct hci_dev * hdev )
425437{
426438 struct btnxpuart_dev * nxpdev = hci_get_drvdata (hdev );
439+ struct serdev_device * serdev = nxpdev -> serdev ;
427440 struct ps_data * psdata = & nxpdev -> psdata ;
428441
442+ psdata -> h2c_ps_gpio = devm_gpiod_get_optional (& serdev -> dev , "device-wakeup" ,
443+ GPIOD_OUT_LOW );
444+ if (IS_ERR (psdata -> h2c_ps_gpio )) {
445+ bt_dev_err (hdev , "Error fetching device-wakeup-gpios: %ld" ,
446+ PTR_ERR (psdata -> h2c_ps_gpio ));
447+ return PTR_ERR (psdata -> h2c_ps_gpio );
448+ }
449+
450+ if (!psdata -> h2c_ps_gpio )
451+ psdata -> h2c_wakeup_gpio = 0xff ;
452+
429453 psdata -> hdev = hdev ;
430454 INIT_WORK (& psdata -> work , ps_work_func );
431455 mutex_init (& psdata -> ps_lock );
432456 timer_setup (& psdata -> ps_timer , ps_timeout_func , 0 );
457+
458+ return 0 ;
433459}
434460
435461static bool ps_wakeup (struct btnxpuart_dev * nxpdev )
@@ -515,6 +541,9 @@ static int send_wakeup_method_cmd(struct hci_dev *hdev, void *data)
515541 pcmd .c2h_wakeupmode = psdata -> c2h_wakeupmode ;
516542 pcmd .c2h_wakeup_gpio = psdata -> c2h_wakeup_gpio ;
517543 switch (psdata -> h2c_wakeupmode ) {
544+ case WAKEUP_METHOD_GPIO :
545+ pcmd .h2c_wakeupmode = BT_CTRL_WAKEUP_METHOD_GPIO ;
546+ break ;
518547 case WAKEUP_METHOD_DTR :
519548 pcmd .h2c_wakeupmode = BT_CTRL_WAKEUP_METHOD_DSR ;
520549 break ;
@@ -549,6 +578,7 @@ static void ps_init(struct hci_dev *hdev)
549578{
550579 struct btnxpuart_dev * nxpdev = hci_get_drvdata (hdev );
551580 struct ps_data * psdata = & nxpdev -> psdata ;
581+ u8 default_h2c_wakeup_mode = DEFAULT_H2C_WAKEUP_MODE ;
552582
553583 serdev_device_set_tiocm (nxpdev -> serdev , 0 , TIOCM_RTS );
554584 usleep_range (5000 , 10000 );
@@ -560,8 +590,17 @@ static void ps_init(struct hci_dev *hdev)
560590 psdata -> c2h_wakeup_gpio = 0xff ;
561591
562592 psdata -> cur_h2c_wakeupmode = WAKEUP_METHOD_INVALID ;
593+ if (psdata -> h2c_ps_gpio )
594+ default_h2c_wakeup_mode = WAKEUP_METHOD_GPIO ;
595+
563596 psdata -> h2c_ps_interval = PS_DEFAULT_TIMEOUT_PERIOD_MS ;
564- switch (DEFAULT_H2C_WAKEUP_MODE ) {
597+
598+ switch (default_h2c_wakeup_mode ) {
599+ case WAKEUP_METHOD_GPIO :
600+ psdata -> h2c_wakeupmode = WAKEUP_METHOD_GPIO ;
601+ gpiod_set_value_cansleep (psdata -> h2c_ps_gpio , 0 );
602+ usleep_range (5000 , 10000 );
603+ break ;
565604 case WAKEUP_METHOD_DTR :
566605 psdata -> h2c_wakeupmode = WAKEUP_METHOD_DTR ;
567606 serdev_device_set_tiocm (nxpdev -> serdev , 0 , TIOCM_DTR );
@@ -946,12 +985,12 @@ static char *nxp_get_fw_name_from_chipid(struct hci_dev *hdev, u16 chipid,
946985 else
947986 bt_dev_err (hdev , "Illegal loader version %02x" , loader_ver );
948987 break ;
949- case CHIP_ID_IW615a0 :
950- case CHIP_ID_IW615a1 :
988+ case CHIP_ID_IW610a0 :
989+ case CHIP_ID_IW610a1 :
951990 if ((loader_ver & FW_SECURE_MASK ) == FW_OPEN )
952- fw_name = FIRMWARE_IW615 ;
991+ fw_name = FIRMWARE_IW610 ;
953992 else if ((loader_ver & FW_SECURE_MASK ) != FW_AUTH_ILLEGAL )
954- fw_name = FIRMWARE_SECURE_IW615 ;
993+ fw_name = FIRMWARE_SECURE_IW610 ;
955994 else
956995 bt_dev_err (hdev , "Illegal loader version %02x" , loader_ver );
957996 break ;
@@ -971,6 +1010,9 @@ static char *nxp_get_old_fw_name_from_chipid(struct hci_dev *hdev, u16 chipid,
9711010 case CHIP_ID_W9098 :
9721011 fw_name_old = FIRMWARE_W9098_OLD ;
9731012 break ;
1013+ case CHIP_ID_IW416 :
1014+ fw_name_old = FIRMWARE_IW416_OLD ;
1015+ break ;
9741016 }
9751017 return fw_name_old ;
9761018}
@@ -1275,6 +1317,9 @@ static int nxp_enqueue(struct hci_dev *hdev, struct sk_buff *skb)
12751317 psdata -> c2h_wakeup_gpio = wakeup_parm .c2h_wakeup_gpio ;
12761318 psdata -> h2c_wakeup_gpio = wakeup_parm .h2c_wakeup_gpio ;
12771319 switch (wakeup_parm .h2c_wakeupmode ) {
1320+ case BT_CTRL_WAKEUP_METHOD_GPIO :
1321+ psdata -> h2c_wakeupmode = WAKEUP_METHOD_GPIO ;
1322+ break ;
12781323 case BT_CTRL_WAKEUP_METHOD_DSR :
12791324 psdata -> h2c_wakeupmode = WAKEUP_METHOD_DTR ;
12801325 break ;
@@ -1341,7 +1386,7 @@ static void btnxpuart_tx_work(struct work_struct *work)
13411386 skb_pull (skb , len );
13421387 if (skb -> len > 0 ) {
13431388 skb_queue_head (& nxpdev -> txq , skb );
1344- break ;
1389+ continue ;
13451390 }
13461391
13471392 switch (hci_skb_pkt_type (skb )) {
@@ -1505,13 +1550,17 @@ static int nxp_serdev_probe(struct serdev_device *serdev)
15051550
15061551 if (hci_register_dev (hdev ) < 0 ) {
15071552 dev_err (& serdev -> dev , "Can't register HCI device\n" );
1508- hci_free_dev (hdev );
1509- return - ENODEV ;
1553+ goto probe_fail ;
15101554 }
15111555
1512- ps_setup (hdev );
1556+ if (ps_setup (hdev ))
1557+ goto probe_fail ;
15131558
15141559 return 0 ;
1560+
1561+ probe_fail :
1562+ hci_free_dev (hdev );
1563+ return - ENODEV ;
15151564}
15161565
15171566static void nxp_serdev_remove (struct serdev_device * serdev )
0 commit comments