Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-only */
0002 /*
0003  * Marvell Bluetooth driver: global definitions & declarations
0004  *
0005  * Copyright (C) 2009, Marvell International Ltd.
0006  */
0007 
0008 #include <linux/kthread.h>
0009 #include <linux/bitops.h>
0010 #include <linux/slab.h>
0011 #include <net/bluetooth/bluetooth.h>
0012 #include <linux/err.h>
0013 #include <linux/gfp.h>
0014 #include <linux/interrupt.h>
0015 #include <linux/io.h>
0016 #include <linux/of_platform.h>
0017 #include <linux/platform_device.h>
0018 #include <linux/pm_runtime.h>
0019 #include <linux/of_irq.h>
0020 
0021 #define BTM_HEADER_LEN          4
0022 #define BTM_UPLD_SIZE           2312
0023 
0024 /* Time to wait until Host Sleep state change in millisecond */
0025 #define WAIT_UNTIL_HS_STATE_CHANGED msecs_to_jiffies(5000)
0026 /* Time to wait for command response in millisecond */
0027 #define WAIT_UNTIL_CMD_RESP     msecs_to_jiffies(5000)
0028 
0029 enum rdwr_status {
0030     RDWR_STATUS_SUCCESS = 0,
0031     RDWR_STATUS_FAILURE = 1,
0032     RDWR_STATUS_DONE = 2
0033 };
0034 
0035 #define FW_DUMP_MAX_NAME_LEN    8
0036 #define FW_DUMP_HOST_READY      0xEE
0037 #define FW_DUMP_DONE            0xFF
0038 #define FW_DUMP_READ_DONE       0xFE
0039 
0040 struct memory_type_mapping {
0041     u8 mem_name[FW_DUMP_MAX_NAME_LEN];
0042     u8 *mem_ptr;
0043     u32 mem_size;
0044     u8 done_flag;
0045 };
0046 
0047 struct btmrvl_thread {
0048     struct task_struct *task;
0049     wait_queue_head_t wait_q;
0050     void *priv;
0051 };
0052 
0053 struct btmrvl_device {
0054     void *card;
0055     struct hci_dev *hcidev;
0056 
0057     u8 dev_type;
0058 
0059     u8 tx_dnld_rdy;
0060 
0061     u8 psmode;
0062     u8 pscmd;
0063     u8 hsmode;
0064     u8 hscmd;
0065 
0066     /* Low byte is gap, high byte is GPIO */
0067     u16 gpio_gap;
0068 
0069     u8 hscfgcmd;
0070     u8 sendcmdflag;
0071 };
0072 
0073 struct btmrvl_adapter {
0074     void *hw_regs_buf;
0075     u8 *hw_regs;
0076     u32 int_count;
0077     struct sk_buff_head tx_queue;
0078     u8 psmode;
0079     u8 ps_state;
0080     u8 hs_state;
0081     u8 wakeup_tries;
0082     wait_queue_head_t cmd_wait_q;
0083     wait_queue_head_t event_hs_wait_q;
0084     u8 cmd_complete;
0085     bool is_suspended;
0086     bool is_suspending;
0087 };
0088 
0089 struct btmrvl_private {
0090     struct btmrvl_device btmrvl_dev;
0091     struct btmrvl_adapter *adapter;
0092     struct btmrvl_thread main_thread;
0093     int (*hw_host_to_card)(struct btmrvl_private *priv,
0094                 u8 *payload, u16 nb);
0095     int (*hw_wakeup_firmware)(struct btmrvl_private *priv);
0096     int (*hw_process_int_status)(struct btmrvl_private *priv);
0097     spinlock_t driver_lock;     /* spinlock used by driver */
0098 #ifdef CONFIG_DEBUG_FS
0099     void *debugfs_data;
0100 #endif
0101     bool surprise_removed;
0102 };
0103 
0104 #define MRVL_VENDOR_PKT         0xFE
0105 
0106 /* Vendor specific Bluetooth commands */
0107 #define BT_CMD_PSCAN_WIN_REPORT_ENABLE  0xFC03
0108 #define BT_CMD_ROUTE_SCO_TO_HOST    0xFC1D
0109 #define BT_CMD_SET_BDADDR       0xFC22
0110 #define BT_CMD_AUTO_SLEEP_MODE      0xFC23
0111 #define BT_CMD_HOST_SLEEP_CONFIG    0xFC59
0112 #define BT_CMD_HOST_SLEEP_ENABLE    0xFC5A
0113 #define BT_CMD_MODULE_CFG_REQ       0xFC5B
0114 #define BT_CMD_LOAD_CONFIG_DATA     0xFC61
0115 
0116 /* Sub-commands: Module Bringup/Shutdown Request/Response */
0117 #define MODULE_BRINGUP_REQ      0xF1
0118 #define MODULE_BROUGHT_UP       0x00
0119 #define MODULE_ALREADY_UP       0x0C
0120 
0121 #define MODULE_SHUTDOWN_REQ     0xF2
0122 
0123 /* Vendor specific Bluetooth events */
0124 #define BT_EVENT_AUTO_SLEEP_MODE    0x23
0125 #define BT_EVENT_HOST_SLEEP_CONFIG  0x59
0126 #define BT_EVENT_HOST_SLEEP_ENABLE  0x5A
0127 #define BT_EVENT_MODULE_CFG_REQ     0x5B
0128 #define BT_EVENT_POWER_STATE        0x20
0129 
0130 /* Bluetooth Power States */
0131 #define BT_PS_ENABLE            0x02
0132 #define BT_PS_DISABLE           0x03
0133 #define BT_PS_SLEEP         0x01
0134 
0135 /* Host Sleep states */
0136 #define HS_ACTIVATED            0x01
0137 #define HS_DEACTIVATED          0x00
0138 
0139 /* Power Save modes */
0140 #define PS_SLEEP            0x01
0141 #define PS_AWAKE            0x00
0142 
0143 #define BT_CAL_HDR_LEN          4
0144 #define BT_CAL_DATA_SIZE        28
0145 
0146 struct btmrvl_event {
0147     u8 ec;      /* event counter */
0148     u8 length;
0149     u8 data[4];
0150 } __packed;
0151 
0152 /* Prototype of global function */
0153 
0154 int btmrvl_register_hdev(struct btmrvl_private *priv);
0155 struct btmrvl_private *btmrvl_add_card(void *card);
0156 int btmrvl_remove_card(struct btmrvl_private *priv);
0157 
0158 void btmrvl_interrupt(struct btmrvl_private *priv);
0159 
0160 bool btmrvl_check_evtpkt(struct btmrvl_private *priv, struct sk_buff *skb);
0161 int btmrvl_process_event(struct btmrvl_private *priv, struct sk_buff *skb);
0162 
0163 int btmrvl_send_module_cfg_cmd(struct btmrvl_private *priv, u8 subcmd);
0164 int btmrvl_pscan_window_reporting(struct btmrvl_private *priv, u8 subcmd);
0165 int btmrvl_send_hscfg_cmd(struct btmrvl_private *priv);
0166 int btmrvl_enable_ps(struct btmrvl_private *priv);
0167 int btmrvl_prepare_command(struct btmrvl_private *priv);
0168 int btmrvl_enable_hs(struct btmrvl_private *priv);
0169 
0170 #ifdef CONFIG_DEBUG_FS
0171 void btmrvl_debugfs_init(struct hci_dev *hdev);
0172 void btmrvl_debugfs_remove(struct hci_dev *hdev);
0173 #endif