Commit 7d250a06 authored by Balakrishna Godavarthi's avatar Balakrishna Godavarthi Committed by Marcel Holtmann

Bluetooth: hci_qca: Add support for Qualcomm Bluetooth SoC WCN3991

This patch add support for WCN3991 i.e. current values and fw download
support.
Signed-off-by: default avatarBalakrishna Godavarthi <bgodavar@codeaurora.org>
Signed-off-by: default avatarMarcel Holtmann <marcel@holtmann.org>
parent e303d124
...@@ -14,19 +14,33 @@ ...@@ -14,19 +14,33 @@
#define VERSION "0.1" #define VERSION "0.1"
int qca_read_soc_version(struct hci_dev *hdev, u32 *soc_version) int qca_read_soc_version(struct hci_dev *hdev, u32 *soc_version,
enum qca_btsoc_type soc_type)
{ {
struct sk_buff *skb; struct sk_buff *skb;
struct edl_event_hdr *edl; struct edl_event_hdr *edl;
struct qca_btsoc_version *ver; struct qca_btsoc_version *ver;
char cmd; char cmd;
int err = 0; int err = 0;
u8 event_type = HCI_EV_VENDOR;
u8 rlen = sizeof(*edl) + sizeof(*ver);
u8 rtype = EDL_APP_VER_RES_EVT;
bt_dev_dbg(hdev, "QCA Version Request"); bt_dev_dbg(hdev, "QCA Version Request");
/* Unlike other SoC's sending version command response as payload to
* VSE event. WCN3991 sends version command response as a payload to
* command complete event.
*/
if (soc_type == QCA_WCN3991) {
event_type = 0;
rlen += 1;
rtype = EDL_PATCH_VER_REQ_CMD;
}
cmd = EDL_PATCH_VER_REQ_CMD; cmd = EDL_PATCH_VER_REQ_CMD;
skb = __hci_cmd_sync_ev(hdev, EDL_PATCH_CMD_OPCODE, EDL_PATCH_CMD_LEN, skb = __hci_cmd_sync_ev(hdev, EDL_PATCH_CMD_OPCODE, EDL_PATCH_CMD_LEN,
&cmd, HCI_EV_VENDOR, HCI_INIT_TIMEOUT); &cmd, event_type, HCI_INIT_TIMEOUT);
if (IS_ERR(skb)) { if (IS_ERR(skb)) {
err = PTR_ERR(skb); err = PTR_ERR(skb);
bt_dev_err(hdev, "Reading QCA version information failed (%d)", bt_dev_err(hdev, "Reading QCA version information failed (%d)",
...@@ -34,7 +48,7 @@ int qca_read_soc_version(struct hci_dev *hdev, u32 *soc_version) ...@@ -34,7 +48,7 @@ int qca_read_soc_version(struct hci_dev *hdev, u32 *soc_version)
return err; return err;
} }
if (skb->len != sizeof(*edl) + sizeof(*ver)) { if (skb->len != rlen) {
bt_dev_err(hdev, "QCA Version size mismatch len %d", skb->len); bt_dev_err(hdev, "QCA Version size mismatch len %d", skb->len);
err = -EILSEQ; err = -EILSEQ;
goto out; goto out;
...@@ -48,13 +62,16 @@ int qca_read_soc_version(struct hci_dev *hdev, u32 *soc_version) ...@@ -48,13 +62,16 @@ int qca_read_soc_version(struct hci_dev *hdev, u32 *soc_version)
} }
if (edl->cresp != EDL_CMD_REQ_RES_EVT || if (edl->cresp != EDL_CMD_REQ_RES_EVT ||
edl->rtype != EDL_APP_VER_RES_EVT) { edl->rtype != rtype) {
bt_dev_err(hdev, "QCA Wrong packet received %d %d", edl->cresp, bt_dev_err(hdev, "QCA Wrong packet received %d %d", edl->cresp,
edl->rtype); edl->rtype);
err = -EIO; err = -EIO;
goto out; goto out;
} }
if (soc_type == QCA_WCN3991)
memmove(&edl->data, &edl->data[1], sizeof(*ver));
ver = (struct qca_btsoc_version *)(edl->data); ver = (struct qca_btsoc_version *)(edl->data);
BT_DBG("%s: Product:0x%08x", hdev->name, le32_to_cpu(ver->product_id)); BT_DBG("%s: Product:0x%08x", hdev->name, le32_to_cpu(ver->product_id));
...@@ -223,13 +240,17 @@ static void qca_tlv_check_data(struct qca_fw_config *config, ...@@ -223,13 +240,17 @@ static void qca_tlv_check_data(struct qca_fw_config *config,
} }
static int qca_tlv_send_segment(struct hci_dev *hdev, int seg_size, static int qca_tlv_send_segment(struct hci_dev *hdev, int seg_size,
const u8 *data, enum qca_tlv_dnld_mode mode) const u8 *data, enum qca_tlv_dnld_mode mode,
enum qca_btsoc_type soc_type)
{ {
struct sk_buff *skb; struct sk_buff *skb;
struct edl_event_hdr *edl; struct edl_event_hdr *edl;
struct tlv_seg_resp *tlv_resp; struct tlv_seg_resp *tlv_resp;
u8 cmd[MAX_SIZE_PER_TLV_SEGMENT + 2]; u8 cmd[MAX_SIZE_PER_TLV_SEGMENT + 2];
int err = 0; int err = 0;
u8 event_type = HCI_EV_VENDOR;
u8 rlen = (sizeof(*edl) + sizeof(*tlv_resp));
u8 rtype = EDL_TVL_DNLD_RES_EVT;
cmd[0] = EDL_PATCH_TLV_REQ_CMD; cmd[0] = EDL_PATCH_TLV_REQ_CMD;
cmd[1] = seg_size; cmd[1] = seg_size;
...@@ -239,15 +260,25 @@ static int qca_tlv_send_segment(struct hci_dev *hdev, int seg_size, ...@@ -239,15 +260,25 @@ static int qca_tlv_send_segment(struct hci_dev *hdev, int seg_size,
return __hci_cmd_send(hdev, EDL_PATCH_CMD_OPCODE, seg_size + 2, return __hci_cmd_send(hdev, EDL_PATCH_CMD_OPCODE, seg_size + 2,
cmd); cmd);
/* Unlike other SoC's sending version command response as payload to
* VSE event. WCN3991 sends version command response as a payload to
* command complete event.
*/
if (soc_type == QCA_WCN3991) {
event_type = 0;
rlen = sizeof(*edl);
rtype = EDL_PATCH_TLV_REQ_CMD;
}
skb = __hci_cmd_sync_ev(hdev, EDL_PATCH_CMD_OPCODE, seg_size + 2, cmd, skb = __hci_cmd_sync_ev(hdev, EDL_PATCH_CMD_OPCODE, seg_size + 2, cmd,
HCI_EV_VENDOR, HCI_INIT_TIMEOUT); event_type, HCI_INIT_TIMEOUT);
if (IS_ERR(skb)) { if (IS_ERR(skb)) {
err = PTR_ERR(skb); err = PTR_ERR(skb);
bt_dev_err(hdev, "QCA Failed to send TLV segment (%d)", err); bt_dev_err(hdev, "QCA Failed to send TLV segment (%d)", err);
return err; return err;
} }
if (skb->len != sizeof(*edl) + sizeof(*tlv_resp)) { if (skb->len != rlen) {
bt_dev_err(hdev, "QCA TLV response size mismatch"); bt_dev_err(hdev, "QCA TLV response size mismatch");
err = -EILSEQ; err = -EILSEQ;
goto out; goto out;
...@@ -260,13 +291,19 @@ static int qca_tlv_send_segment(struct hci_dev *hdev, int seg_size, ...@@ -260,13 +291,19 @@ static int qca_tlv_send_segment(struct hci_dev *hdev, int seg_size,
goto out; goto out;
} }
tlv_resp = (struct tlv_seg_resp *)(edl->data); if (edl->cresp != EDL_CMD_REQ_RES_EVT || edl->rtype != rtype) {
bt_dev_err(hdev, "QCA TLV with error stat 0x%x rtype 0x%x",
edl->cresp, edl->rtype);
err = -EIO;
}
if (edl->cresp != EDL_CMD_REQ_RES_EVT || if (soc_type == QCA_WCN3991)
edl->rtype != EDL_TVL_DNLD_RES_EVT || tlv_resp->result != 0x00) { goto out;
tlv_resp = (struct tlv_seg_resp *)(edl->data);
if (tlv_resp->result) {
bt_dev_err(hdev, "QCA TLV with error stat 0x%x rtype 0x%x (0x%x)", bt_dev_err(hdev, "QCA TLV with error stat 0x%x rtype 0x%x (0x%x)",
edl->cresp, edl->rtype, tlv_resp->result); edl->cresp, edl->rtype, tlv_resp->result);
err = -EIO;
} }
out: out:
...@@ -301,7 +338,8 @@ static int qca_inject_cmd_complete_event(struct hci_dev *hdev) ...@@ -301,7 +338,8 @@ static int qca_inject_cmd_complete_event(struct hci_dev *hdev)
} }
static int qca_download_firmware(struct hci_dev *hdev, static int qca_download_firmware(struct hci_dev *hdev,
struct qca_fw_config *config) struct qca_fw_config *config,
enum qca_btsoc_type soc_type)
{ {
const struct firmware *fw; const struct firmware *fw;
const u8 *segment; const u8 *segment;
...@@ -331,7 +369,7 @@ static int qca_download_firmware(struct hci_dev *hdev, ...@@ -331,7 +369,7 @@ static int qca_download_firmware(struct hci_dev *hdev,
config->dnld_mode = QCA_SKIP_EVT_NONE; config->dnld_mode = QCA_SKIP_EVT_NONE;
ret = qca_tlv_send_segment(hdev, segsize, segment, ret = qca_tlv_send_segment(hdev, segsize, segment,
config->dnld_mode); config->dnld_mode, soc_type);
if (ret) if (ret)
goto out; goto out;
...@@ -405,7 +443,7 @@ int qca_uart_setup(struct hci_dev *hdev, uint8_t baudrate, ...@@ -405,7 +443,7 @@ int qca_uart_setup(struct hci_dev *hdev, uint8_t baudrate,
"qca/rampatch_%08x.bin", soc_ver); "qca/rampatch_%08x.bin", soc_ver);
} }
err = qca_download_firmware(hdev, &config); err = qca_download_firmware(hdev, &config, soc_type);
if (err < 0) { if (err < 0) {
bt_dev_err(hdev, "QCA Failed to download patch (%d)", err); bt_dev_err(hdev, "QCA Failed to download patch (%d)", err);
return err; return err;
...@@ -426,7 +464,7 @@ int qca_uart_setup(struct hci_dev *hdev, uint8_t baudrate, ...@@ -426,7 +464,7 @@ int qca_uart_setup(struct hci_dev *hdev, uint8_t baudrate,
snprintf(config.fwname, sizeof(config.fwname), snprintf(config.fwname, sizeof(config.fwname),
"qca/nvm_%08x.bin", soc_ver); "qca/nvm_%08x.bin", soc_ver);
err = qca_download_firmware(hdev, &config); err = qca_download_firmware(hdev, &config, soc_type);
if (err < 0) { if (err < 0) {
bt_dev_err(hdev, "QCA Failed to download NVM (%d)", err); bt_dev_err(hdev, "QCA Failed to download NVM (%d)", err);
return err; return err;
......
...@@ -125,6 +125,7 @@ enum qca_btsoc_type { ...@@ -125,6 +125,7 @@ enum qca_btsoc_type {
QCA_AR3002, QCA_AR3002,
QCA_ROME, QCA_ROME,
QCA_WCN3990, QCA_WCN3990,
QCA_WCN3991,
QCA_WCN3998, QCA_WCN3998,
}; };
...@@ -134,12 +135,14 @@ int qca_set_bdaddr_rome(struct hci_dev *hdev, const bdaddr_t *bdaddr); ...@@ -134,12 +135,14 @@ int qca_set_bdaddr_rome(struct hci_dev *hdev, const bdaddr_t *bdaddr);
int qca_uart_setup(struct hci_dev *hdev, uint8_t baudrate, int qca_uart_setup(struct hci_dev *hdev, uint8_t baudrate,
enum qca_btsoc_type soc_type, u32 soc_ver, enum qca_btsoc_type soc_type, u32 soc_ver,
const char *firmware_name); const char *firmware_name);
int qca_read_soc_version(struct hci_dev *hdev, u32 *soc_version); int qca_read_soc_version(struct hci_dev *hdev, u32 *soc_version,
enum qca_btsoc_type);
int qca_set_bdaddr(struct hci_dev *hdev, const bdaddr_t *bdaddr); int qca_set_bdaddr(struct hci_dev *hdev, const bdaddr_t *bdaddr);
int qca_send_pre_shutdown_cmd(struct hci_dev *hdev); int qca_send_pre_shutdown_cmd(struct hci_dev *hdev);
static inline bool qca_is_wcn399x(enum qca_btsoc_type soc_type) static inline bool qca_is_wcn399x(enum qca_btsoc_type soc_type)
{ {
return soc_type == QCA_WCN3990 || soc_type == QCA_WCN3998; return soc_type == QCA_WCN3990 || soc_type == QCA_WCN3991 ||
soc_type == QCA_WCN3998;
} }
#else #else
...@@ -155,7 +158,8 @@ static inline int qca_uart_setup(struct hci_dev *hdev, uint8_t baudrate, ...@@ -155,7 +158,8 @@ static inline int qca_uart_setup(struct hci_dev *hdev, uint8_t baudrate,
return -EOPNOTSUPP; return -EOPNOTSUPP;
} }
static inline int qca_read_soc_version(struct hci_dev *hdev, u32 *soc_version) static inline int qca_read_soc_version(struct hci_dev *hdev, u32 *soc_version,
enum qca_btsoc_type)
{ {
return -EOPNOTSUPP; return -EOPNOTSUPP;
} }
......
...@@ -1288,7 +1288,7 @@ static int qca_setup(struct hci_uart *hu) ...@@ -1288,7 +1288,7 @@ static int qca_setup(struct hci_uart *hu)
if (ret) if (ret)
return ret; return ret;
ret = qca_read_soc_version(hdev, &soc_ver); ret = qca_read_soc_version(hdev, &soc_ver, soc_type);
if (ret) if (ret)
return ret; return ret;
} else { } else {
...@@ -1308,7 +1308,7 @@ static int qca_setup(struct hci_uart *hu) ...@@ -1308,7 +1308,7 @@ static int qca_setup(struct hci_uart *hu)
if (!qca_is_wcn399x(soc_type)) { if (!qca_is_wcn399x(soc_type)) {
/* Get QCA version information */ /* Get QCA version information */
ret = qca_read_soc_version(hdev, &soc_ver); ret = qca_read_soc_version(hdev, &soc_ver, soc_type);
if (ret) if (ret)
return ret; return ret;
} }
...@@ -1366,6 +1366,17 @@ static const struct qca_vreg_data qca_soc_data_wcn3990 = { ...@@ -1366,6 +1366,17 @@ static const struct qca_vreg_data qca_soc_data_wcn3990 = {
.num_vregs = 4, .num_vregs = 4,
}; };
static const struct qca_vreg_data qca_soc_data_wcn3991 = {
.soc_type = QCA_WCN3991,
.vregs = (struct qca_vreg []) {
{ "vddio", 15000 },
{ "vddxo", 80000 },
{ "vddrf", 300000 },
{ "vddch0", 450000 },
},
.num_vregs = 4,
};
static const struct qca_vreg_data qca_soc_data_wcn3998 = { static const struct qca_vreg_data qca_soc_data_wcn3998 = {
.soc_type = QCA_WCN3998, .soc_type = QCA_WCN3998,
.vregs = (struct qca_vreg []) { .vregs = (struct qca_vreg []) {
...@@ -1662,6 +1673,7 @@ static SIMPLE_DEV_PM_OPS(qca_pm_ops, qca_suspend, qca_resume); ...@@ -1662,6 +1673,7 @@ static SIMPLE_DEV_PM_OPS(qca_pm_ops, qca_suspend, qca_resume);
static const struct of_device_id qca_bluetooth_of_match[] = { static const struct of_device_id qca_bluetooth_of_match[] = {
{ .compatible = "qcom,qca6174-bt" }, { .compatible = "qcom,qca6174-bt" },
{ .compatible = "qcom,wcn3990-bt", .data = &qca_soc_data_wcn3990}, { .compatible = "qcom,wcn3990-bt", .data = &qca_soc_data_wcn3990},
{ .compatible = "qcom,wcn3991-bt", .data = &qca_soc_data_wcn3991},
{ .compatible = "qcom,wcn3998-bt", .data = &qca_soc_data_wcn3998}, { .compatible = "qcom,wcn3998-bt", .data = &qca_soc_data_wcn3998},
{ /* sentinel */ } { /* sentinel */ }
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment