1*99c926ceSThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-only */ 2132ff4e5SBing Zhao /* 3132ff4e5SBing Zhao * Marvell Bluetooth driver: global definitions & declarations 4132ff4e5SBing Zhao * 5132ff4e5SBing Zhao * Copyright (C) 2009, Marvell International Ltd. 6132ff4e5SBing Zhao */ 7132ff4e5SBing Zhao 8132ff4e5SBing Zhao #include <linux/kthread.h> 9132ff4e5SBing Zhao #include <linux/bitops.h> 105a0e3ad6STejun Heo #include <linux/slab.h> 11132ff4e5SBing Zhao #include <net/bluetooth/bluetooth.h> 12bb7f4f0bSXinming Hu #include <linux/err.h> 13bb7f4f0bSXinming Hu #include <linux/gfp.h> 14bb7f4f0bSXinming Hu #include <linux/interrupt.h> 15bb7f4f0bSXinming Hu #include <linux/io.h> 16bb7f4f0bSXinming Hu #include <linux/of_platform.h> 17bb7f4f0bSXinming Hu #include <linux/platform_device.h> 18bb7f4f0bSXinming Hu #include <linux/pm_runtime.h> 19bb7f4f0bSXinming Hu #include <linux/of_irq.h> 20132ff4e5SBing Zhao 21132ff4e5SBing Zhao #define BTM_HEADER_LEN 4 22132ff4e5SBing Zhao #define BTM_UPLD_SIZE 2312 23132ff4e5SBing Zhao 24132ff4e5SBing Zhao /* Time to wait until Host Sleep state change in millisecond */ 250333d6ddSAmitkumar Karwar #define WAIT_UNTIL_HS_STATE_CHANGED msecs_to_jiffies(5000) 26132ff4e5SBing Zhao /* Time to wait for command response in millisecond */ 270333d6ddSAmitkumar Karwar #define WAIT_UNTIL_CMD_RESP msecs_to_jiffies(5000) 28132ff4e5SBing Zhao 29dc759613SXinming Hu enum rdwr_status { 30dc759613SXinming Hu RDWR_STATUS_SUCCESS = 0, 31dc759613SXinming Hu RDWR_STATUS_FAILURE = 1, 32dc759613SXinming Hu RDWR_STATUS_DONE = 2 33dc759613SXinming Hu }; 34dc759613SXinming Hu 35dc759613SXinming Hu #define FW_DUMP_MAX_NAME_LEN 8 36dc759613SXinming Hu #define FW_DUMP_HOST_READY 0xEE 37dc759613SXinming Hu #define FW_DUMP_DONE 0xFF 38dc759613SXinming Hu #define FW_DUMP_READ_DONE 0xFE 39dc759613SXinming Hu 40dc759613SXinming Hu struct memory_type_mapping { 41dc759613SXinming Hu u8 mem_name[FW_DUMP_MAX_NAME_LEN]; 42dc759613SXinming Hu u8 *mem_ptr; 43dc759613SXinming Hu u32 mem_size; 44dc759613SXinming Hu u8 done_flag; 45dc759613SXinming Hu }; 46dc759613SXinming Hu 47132ff4e5SBing Zhao struct btmrvl_thread { 48132ff4e5SBing Zhao struct task_struct *task; 49132ff4e5SBing Zhao wait_queue_head_t wait_q; 50132ff4e5SBing Zhao void *priv; 51132ff4e5SBing Zhao }; 52132ff4e5SBing Zhao 53132ff4e5SBing Zhao struct btmrvl_device { 54132ff4e5SBing Zhao void *card; 55132ff4e5SBing Zhao struct hci_dev *hcidev; 56132ff4e5SBing Zhao 57f120c6b6SBing Zhao u8 dev_type; 58f120c6b6SBing Zhao 59132ff4e5SBing Zhao u8 tx_dnld_rdy; 60132ff4e5SBing Zhao 61132ff4e5SBing Zhao u8 psmode; 62132ff4e5SBing Zhao u8 pscmd; 63132ff4e5SBing Zhao u8 hsmode; 64132ff4e5SBing Zhao u8 hscmd; 65132ff4e5SBing Zhao 66132ff4e5SBing Zhao /* Low byte is gap, high byte is GPIO */ 67132ff4e5SBing Zhao u16 gpio_gap; 68132ff4e5SBing Zhao 69132ff4e5SBing Zhao u8 hscfgcmd; 70132ff4e5SBing Zhao u8 sendcmdflag; 71132ff4e5SBing Zhao }; 72132ff4e5SBing Zhao 73132ff4e5SBing Zhao struct btmrvl_adapter { 740d367408SBing Zhao void *hw_regs_buf; 750d367408SBing Zhao u8 *hw_regs; 76132ff4e5SBing Zhao u32 int_count; 77132ff4e5SBing Zhao struct sk_buff_head tx_queue; 78132ff4e5SBing Zhao u8 psmode; 79132ff4e5SBing Zhao u8 ps_state; 80132ff4e5SBing Zhao u8 hs_state; 81132ff4e5SBing Zhao u8 wakeup_tries; 82132ff4e5SBing Zhao wait_queue_head_t cmd_wait_q; 83396e04f4SChin-Ran Lo wait_queue_head_t event_hs_wait_q; 84132ff4e5SBing Zhao u8 cmd_complete; 85ba54a16fSAmitkumar Karwar bool is_suspended; 868cf60cf2SChin-Ran Lo bool is_suspending; 87132ff4e5SBing Zhao }; 88132ff4e5SBing Zhao 89132ff4e5SBing Zhao struct btmrvl_private { 90132ff4e5SBing Zhao struct btmrvl_device btmrvl_dev; 91132ff4e5SBing Zhao struct btmrvl_adapter *adapter; 92132ff4e5SBing Zhao struct btmrvl_thread main_thread; 93132ff4e5SBing Zhao int (*hw_host_to_card)(struct btmrvl_private *priv, 94132ff4e5SBing Zhao u8 *payload, u16 nb); 95132ff4e5SBing Zhao int (*hw_wakeup_firmware)(struct btmrvl_private *priv); 96d1d10d78SAmitkumar Karwar int (*hw_process_int_status)(struct btmrvl_private *priv); 97132ff4e5SBing Zhao spinlock_t driver_lock; /* spinlock used by driver */ 98fb784f05SBing Zhao #ifdef CONFIG_DEBUG_FS 99fb784f05SBing Zhao void *debugfs_data; 100fb784f05SBing Zhao #endif 1017b4b8740SAmitkumar Karwar bool surprise_removed; 102132ff4e5SBing Zhao }; 103132ff4e5SBing Zhao 104132ff4e5SBing Zhao #define MRVL_VENDOR_PKT 0xFE 105132ff4e5SBing Zhao 1063e4543abSBing Zhao /* Vendor specific Bluetooth commands */ 1074df82b59SBing Zhao #define BT_CMD_PSCAN_WIN_REPORT_ENABLE 0xFC03 108a715d11eSAmitkumar Karwar #define BT_CMD_ROUTE_SCO_TO_HOST 0xFC1D 10927b869f5SAmitkumar Karwar #define BT_CMD_SET_BDADDR 0xFC22 1103e4543abSBing Zhao #define BT_CMD_AUTO_SLEEP_MODE 0xFC23 1113e4543abSBing Zhao #define BT_CMD_HOST_SLEEP_CONFIG 0xFC59 1123e4543abSBing Zhao #define BT_CMD_HOST_SLEEP_ENABLE 0xFC5A 1133e4543abSBing Zhao #define BT_CMD_MODULE_CFG_REQ 0xFC5B 1143e4543abSBing Zhao #define BT_CMD_LOAD_CONFIG_DATA 0xFC61 115132ff4e5SBing Zhao 116903c8437SBing Zhao /* Sub-commands: Module Bringup/Shutdown Request/Response */ 117132ff4e5SBing Zhao #define MODULE_BRINGUP_REQ 0xF1 118903c8437SBing Zhao #define MODULE_BROUGHT_UP 0x00 119903c8437SBing Zhao #define MODULE_ALREADY_UP 0x0C 120903c8437SBing Zhao 121132ff4e5SBing Zhao #define MODULE_SHUTDOWN_REQ 0xF2 122132ff4e5SBing Zhao 1233e4543abSBing Zhao /* Vendor specific Bluetooth events */ 1243e4543abSBing Zhao #define BT_EVENT_AUTO_SLEEP_MODE 0x23 1253e4543abSBing Zhao #define BT_EVENT_HOST_SLEEP_CONFIG 0x59 1263e4543abSBing Zhao #define BT_EVENT_HOST_SLEEP_ENABLE 0x5A 1273e4543abSBing Zhao #define BT_EVENT_MODULE_CFG_REQ 0x5B 128132ff4e5SBing Zhao #define BT_EVENT_POWER_STATE 0x20 129132ff4e5SBing Zhao 130132ff4e5SBing Zhao /* Bluetooth Power States */ 131132ff4e5SBing Zhao #define BT_PS_ENABLE 0x02 132132ff4e5SBing Zhao #define BT_PS_DISABLE 0x03 133132ff4e5SBing Zhao #define BT_PS_SLEEP 0x01 134132ff4e5SBing Zhao 135132ff4e5SBing Zhao /* Host Sleep states */ 136132ff4e5SBing Zhao #define HS_ACTIVATED 0x01 137132ff4e5SBing Zhao #define HS_DEACTIVATED 0x00 138132ff4e5SBing Zhao 139132ff4e5SBing Zhao /* Power Save modes */ 140132ff4e5SBing Zhao #define PS_SLEEP 0x01 141132ff4e5SBing Zhao #define PS_AWAKE 0x00 142132ff4e5SBing Zhao 1438a4934f1SBing Zhao #define BT_CAL_HDR_LEN 4 1442cc86890SAmitkumar Karwar #define BT_CAL_DATA_SIZE 28 1452cc86890SAmitkumar Karwar 146132ff4e5SBing Zhao struct btmrvl_event { 147132ff4e5SBing Zhao u8 ec; /* event counter */ 148132ff4e5SBing Zhao u8 length; 149132ff4e5SBing Zhao u8 data[4]; 15081ca405aSGustavo F. Padovan } __packed; 151132ff4e5SBing Zhao 152132ff4e5SBing Zhao /* Prototype of global function */ 153132ff4e5SBing Zhao 15464061607SBing Zhao int btmrvl_register_hdev(struct btmrvl_private *priv); 155132ff4e5SBing Zhao struct btmrvl_private *btmrvl_add_card(void *card); 156132ff4e5SBing Zhao int btmrvl_remove_card(struct btmrvl_private *priv); 157132ff4e5SBing Zhao 158132ff4e5SBing Zhao void btmrvl_interrupt(struct btmrvl_private *priv); 159132ff4e5SBing Zhao 160ea1e76a3SAndrei Emeltchenko bool btmrvl_check_evtpkt(struct btmrvl_private *priv, struct sk_buff *skb); 161132ff4e5SBing Zhao int btmrvl_process_event(struct btmrvl_private *priv, struct sk_buff *skb); 162132ff4e5SBing Zhao 1637125df53SPetri Gynther int btmrvl_send_module_cfg_cmd(struct btmrvl_private *priv, u8 subcmd); 164af963243SJohan Hedberg int btmrvl_pscan_window_reporting(struct btmrvl_private *priv, u8 subcmd); 1652a8ff611SAmitkumar Karwar int btmrvl_send_hscfg_cmd(struct btmrvl_private *priv); 16632fd6398SAmitkumar Karwar int btmrvl_enable_ps(struct btmrvl_private *priv); 167132ff4e5SBing Zhao int btmrvl_prepare_command(struct btmrvl_private *priv); 168ba54a16fSAmitkumar Karwar int btmrvl_enable_hs(struct btmrvl_private *priv); 169132ff4e5SBing Zhao 170fb784f05SBing Zhao #ifdef CONFIG_DEBUG_FS 171fb784f05SBing Zhao void btmrvl_debugfs_init(struct hci_dev *hdev); 172fb784f05SBing Zhao void btmrvl_debugfs_remove(struct hci_dev *hdev); 173fb784f05SBing Zhao #endif 174