sm8750: init kernel modules repo
This commit is contained in:
10
qcom/opensource/bt-kernel/btfmcodec/Kconfig
Normal file
10
qcom/opensource/bt-kernel/btfmcodec/Kconfig
Normal file
@@ -0,0 +1,10 @@
|
||||
# SPDX-License-Identifier: GPL-2.0-only
|
||||
config BTFM_CODEC
|
||||
tristate "MSM Bluetooth/FM CODEC Driver"
|
||||
help
|
||||
This will enables BT/FM Codec driver. Hardware endpoint
|
||||
drivers will register to this driver to communicates with ALSA codec
|
||||
driver.
|
||||
|
||||
Say Y here to compile support for BT/FM Codec driver
|
||||
into the kernel or say M to compile as a module.
|
||||
4
qcom/opensource/bt-kernel/btfmcodec/Makefile
Normal file
4
qcom/opensource/bt-kernel/btfmcodec/Makefile
Normal file
@@ -0,0 +1,4 @@
|
||||
ccflags-y += -I$(BT_ROOT)/include
|
||||
ccflags-y += -I$(BT_ROOT)/btfmcodec/include
|
||||
btfmcodec-objs := btfm_codec.o btfm_codec_hw_interface.o btfm_codec_interface.o btfm_codec_btadv_interface.o
|
||||
obj-$(CONFIG_BTFM_CODEC) += btfmcodec.o
|
||||
788
qcom/opensource/bt-kernel/btfmcodec/btfm_codec.c
Normal file
788
qcom/opensource/bt-kernel/btfmcodec/btfm_codec.c
Normal file
@@ -0,0 +1,788 @@
|
||||
// SPDX-License-Identifier: GPL-2.0-only
|
||||
/*
|
||||
* Copyright (c) 2023-2025 Qualcomm Innovation Center, Inc. All rights reserved.
|
||||
*/
|
||||
|
||||
#include <linux/slab.h>
|
||||
#include <linux/kdev_t.h>
|
||||
#include <linux/refcount.h>
|
||||
#include <linux/idr.h>
|
||||
#include <linux/cdev.h>
|
||||
#include <linux/device.h>
|
||||
#include <linux/kernel.h>
|
||||
#include <linux/fs.h>
|
||||
#include <linux/module.h>
|
||||
#include "btfm_codec.h"
|
||||
#include "btfm_codec_pkt.h"
|
||||
#include "btfm_codec_btadv_interface.h"
|
||||
|
||||
#define dev_to_btfmcodec(_dev) container_of(_dev, struct btfmcodec_data, dev)
|
||||
|
||||
static DEFINE_IDR(dev_minor);
|
||||
static struct class *dev_class;
|
||||
static dev_t dev_major;
|
||||
struct btfmcodec_data *btfmcodec;
|
||||
struct device_driver driver = {.name = "btfmcodec-driver", .owner = THIS_MODULE};
|
||||
struct btfmcodec_char_device *btfmcodec_dev;
|
||||
bool is_cp_supported = true;
|
||||
|
||||
#define cdev_to_btfmchardev(_cdev) container_of(_cdev, struct btfmcodec_char_device, cdev)
|
||||
#define MIN_PKT_LEN 0x9
|
||||
|
||||
char *coverttostring(enum btfmcodec_states state) {
|
||||
switch (state) {
|
||||
case IDLE:
|
||||
return "IDLE";
|
||||
break;
|
||||
case BT_Connected:
|
||||
return "BT_CONNECTED";
|
||||
break;
|
||||
case BT_Connecting:
|
||||
return "BT_CONNECTING";
|
||||
break;
|
||||
case BTADV_AUDIO_Connected:
|
||||
return "BTADV_AUDIO_CONNECTED";
|
||||
break;
|
||||
case BTADV_AUDIO_Connecting:
|
||||
return "BTADV_AUDIO_CONNECTING";
|
||||
break;
|
||||
default:
|
||||
return "INVALID_STATE";
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* btfmcodec_dev_open() - open() syscall for the btfmcodec dev node
|
||||
* inode: Pointer to the inode structure.
|
||||
* file: Pointer to the file structure.
|
||||
*
|
||||
* This function is used to open the btfmcodec char device when
|
||||
* userspace client do a open() system call. All input arguments are
|
||||
* validated by the virtual file system before calling this function.
|
||||
* Note: btfmcodec dev node works on nonblocking mode.
|
||||
*/
|
||||
static int btfmcodec_dev_open(struct inode *inode, struct file *file)
|
||||
{
|
||||
struct btfmcodec_char_device *btfmcodec_dev = cdev_to_btfmchardev(inode->i_cdev);
|
||||
struct btfmcodec_data *btfmcodec = (struct btfmcodec_data *)btfmcodec_dev->btfmcodec;
|
||||
unsigned int active_clients = refcount_read(&btfmcodec_dev->active_clients);
|
||||
|
||||
BTFMCODEC_INFO("for %s by %s:%d active_clients[%d]\n",
|
||||
btfmcodec_dev->dev_name, current->comm,
|
||||
task_pid_nr(current), refcount_read(&btfmcodec_dev->active_clients));
|
||||
/* Don't allow a new client if already one is active. */
|
||||
if (active_clients > 1) {
|
||||
BTFMCODEC_WARN("%s: Not honoring open as other client is active", __func__);
|
||||
return EACCES;
|
||||
}
|
||||
/* for now have btfmcodec and later we can think of having it btfmcodec_dev */
|
||||
file->private_data = btfmcodec;
|
||||
refcount_inc(&btfmcodec_dev->active_clients);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* btfmcodec_pkt_release() - release operation on btfmcodec device
|
||||
* inode: Pointer to the inode structure.
|
||||
* file: Pointer to the file structure.
|
||||
*
|
||||
* This function is used to release the btfmcodec dev node when
|
||||
* userspace client do a close() system call. All input arguments are
|
||||
* validated by the virtual file system before calling this function.
|
||||
*/
|
||||
static int btfmcodec_dev_release(struct inode *inode, struct file *file)
|
||||
{
|
||||
struct btfmcodec_char_device *btfmcodec_dev = cdev_to_btfmchardev(inode->i_cdev);
|
||||
unsigned long flags;
|
||||
int idx;
|
||||
|
||||
BTFMCODEC_INFO("for %s by %s:%d active_clients[%u]\n",
|
||||
btfmcodec_dev->dev_name, current->comm,
|
||||
task_pid_nr(current), refcount_read(&btfmcodec_dev->active_clients));
|
||||
|
||||
refcount_dec(&btfmcodec_dev->active_clients);
|
||||
if (refcount_read(&btfmcodec_dev->active_clients) == 1) {
|
||||
spin_lock_irqsave(&btfmcodec_dev->tx_queue_lock, flags);
|
||||
skb_queue_purge(&btfmcodec_dev->txq);
|
||||
/* Wakeup the device if waiting for the data */
|
||||
wake_up_interruptible(&btfmcodec_dev->readq);
|
||||
spin_unlock_irqrestore(&btfmcodec_dev->tx_queue_lock, flags);
|
||||
/* we need to have separte rx lock for below buff */
|
||||
skb_queue_purge(&btfmcodec_dev->rxq);
|
||||
skb_queue_purge(&btfmcodec_dev->trans_rxq);
|
||||
}
|
||||
|
||||
/* Notify waiting clients that client is closed or killed */
|
||||
for (idx = 0; idx < BTM_PKT_TYPE_MAX; idx++) {
|
||||
btfmcodec_dev->status[idx] = BTM_RSP_NOT_RECV_CLIENT_KILLED;
|
||||
wake_up_interruptible(&btfmcodec_dev->rsp_wait_q[idx]);
|
||||
}
|
||||
|
||||
if (btfmcodec_dev->wq_hwep_shutdown.func)
|
||||
cancel_work_sync(&btfmcodec_dev->wq_hwep_shutdown);
|
||||
if (btfmcodec_dev->wq_hwep_configure.func)
|
||||
cancel_work_sync(&btfmcodec_dev->wq_hwep_configure);
|
||||
if (btfmcodec_dev->wq_prepare_bearer.func)
|
||||
cancel_work_sync(&btfmcodec_dev->wq_prepare_bearer);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
btm_opcode STREAM_TO_UINT32 (struct sk_buff *skb)
|
||||
{
|
||||
return (skb->data[0] | (skb->data[1] << 8) |
|
||||
(skb->data[2] << 16) | (skb->data[3] << 24));
|
||||
}
|
||||
|
||||
static void btfmcodec_dev_rxwork(struct work_struct *work)
|
||||
{
|
||||
struct btfmcodec_char_device *btfmcodec_dev = container_of(work, struct btfmcodec_char_device, rx_work);
|
||||
struct sk_buff *skb;
|
||||
struct btfmcodec_state_machine *state = &btfmcodec->states;
|
||||
uint32_t len;
|
||||
uint8_t status;
|
||||
int idx;
|
||||
uint8_t *bearer_switch_ind, *dma_rsp;
|
||||
|
||||
BTFMCODEC_DBG("start");
|
||||
while ((skb = skb_dequeue(&btfmcodec_dev->rxq))) {
|
||||
btm_opcode opcode = STREAM_TO_UINT32(skb);
|
||||
skb_pull(skb, sizeof(btm_opcode));
|
||||
len = STREAM_TO_UINT32(skb);
|
||||
skb_pull(skb, sizeof(len));
|
||||
switch (opcode) {
|
||||
case BTM_BTFMCODEC_PREPARE_AUDIO_BEARER_SWITCH_REQ:
|
||||
idx = BTM_PKT_TYPE_PREPARE_REQ;
|
||||
BTFMCODEC_DBG("BTM_BTFMCODEC_PREPARE_AUDIO_BEARER_SWITCH_REQ");
|
||||
if (len == BTM_PREPARE_AUDIO_BEARER_SWITCH_REQ_LEN) {
|
||||
/* Reset bearer switch ind flag */
|
||||
bearer_switch_ind =
|
||||
&btfmcodec_dev->status[BTM_PKT_TYPE_BEARER_SWITCH_IND];
|
||||
*bearer_switch_ind = BTM_WAITING_RSP;
|
||||
btfmcodec_enqueue_transport(btfmcodec_dev, skb->data[0]);
|
||||
if (skb->data[0] == NONE &&
|
||||
btfmcodec_get_current_transport(state) == BT_Connecting &&
|
||||
btfmcodec_get_prev_transport(state) ==
|
||||
BTADV_AUDIO_Connected) {
|
||||
BTFMCODEC_INFO("KP might be awaiting for codec dma rsp");
|
||||
idx = BTM_PKT_TYPE_DMA_CONFIG_RSP;
|
||||
dma_rsp = &btfmcodec_dev->status[idx];
|
||||
*dma_rsp = BTM_FAIL_RESP_RECV;
|
||||
wake_up_interruptible(&btfmcodec_dev->rsp_wait_q[idx]);
|
||||
}
|
||||
queue_work(btfmcodec_dev->workqueue,
|
||||
&btfmcodec_dev->wq_prepare_bearer);
|
||||
} else {
|
||||
BTFMCODEC_ERR("wrong packet format with len:%d", len);
|
||||
}
|
||||
break;
|
||||
case BTM_BTFMCODEC_MASTER_CONFIG_RSP:
|
||||
idx = BTM_PKT_TYPE_MASTER_CONFIG_RSP;
|
||||
if (len == BTM_MASTER_CONFIG_RSP_LEN) {
|
||||
status = skb->data[1];
|
||||
if (status == MSG_SUCCESS)
|
||||
btfmcodec_dev->status[idx] = BTM_RSP_RECV;
|
||||
else
|
||||
btfmcodec_dev->status[idx] = BTM_FAIL_RESP_RECV;
|
||||
} else {
|
||||
BTFMCODEC_ERR("wrong packet format with len:%d", len);
|
||||
btfmcodec_dev->status[idx] = BTM_FAIL_RESP_RECV;
|
||||
}
|
||||
BTFMCODEC_INFO("Rx BTM_BTFMCODEC_MASTER_CONFIG_RSP status:%d",
|
||||
status);
|
||||
wake_up_interruptible(&btfmcodec_dev->rsp_wait_q[idx]);
|
||||
break;
|
||||
case BTM_BTFMCODEC_CODEC_CONFIG_DMA_RSP:
|
||||
idx = BTM_PKT_TYPE_DMA_CONFIG_RSP;
|
||||
if (len == BTM_CODEC_CONFIG_DMA_RSP_LEN) {
|
||||
status = skb->data[1];
|
||||
if (status == MSG_SUCCESS)
|
||||
btfmcodec_dev->status[idx] = BTM_RSP_RECV;
|
||||
else
|
||||
btfmcodec_dev->status[idx] = BTM_FAIL_RESP_RECV;
|
||||
} else {
|
||||
BTFMCODEC_ERR("wrong packet format with len:%d", len);
|
||||
btfmcodec_dev->status[idx] = BTM_FAIL_RESP_RECV;
|
||||
}
|
||||
BTFMCODEC_INFO("Rx BTM_BTFMCODEC_CODEC_CONFIG_DMA_RSP status:%d",
|
||||
status);
|
||||
wake_up_interruptible(&btfmcodec_dev->rsp_wait_q[idx]);
|
||||
break;
|
||||
case BTM_BTFMCODEC_CTRL_MASTER_SHUTDOWN_RSP:
|
||||
idx = BTM_PKT_TYPE_MASTER_SHUTDOWN_RSP;
|
||||
if (len == BTM_MASTER_CONFIG_RSP_LEN) {
|
||||
status = skb->data[1];
|
||||
if (status == MSG_SUCCESS)
|
||||
btfmcodec_dev->status[idx] = BTM_RSP_RECV;
|
||||
else
|
||||
btfmcodec_dev->status[idx] = BTM_FAIL_RESP_RECV;
|
||||
} else {
|
||||
BTFMCODEC_ERR("wrong packet format with len:%d", len);
|
||||
btfmcodec_dev->status[idx] = BTM_FAIL_RESP_RECV;
|
||||
}
|
||||
BTFMCODEC_INFO("Rx BTM_BTFMCODEC_CTRL_MASTER_SHUTDOWN_RSP status:%d",
|
||||
status);
|
||||
wake_up_interruptible(&btfmcodec_dev->rsp_wait_q[idx]);
|
||||
BTFMCODEC_INFO("%s: waiting to cancel prepare bearer wq", __func__);
|
||||
cancel_work_sync(&btfmcodec_dev->wq_prepare_bearer);
|
||||
BTFMCODEC_INFO("%s: prepare bearer wq canceled", __func__);
|
||||
break;
|
||||
case BTM_BTFMCODEC_BEARER_SWITCH_IND:
|
||||
idx = BTM_PKT_TYPE_BEARER_SWITCH_IND;
|
||||
if (len == BTM_BEARER_SWITCH_IND_LEN) {
|
||||
status = skb->data[0];
|
||||
if (status == MSG_SUCCESS)
|
||||
btfmcodec_dev->status[idx] = BTM_RSP_RECV;
|
||||
else
|
||||
btfmcodec_dev->status[idx] = BTM_FAIL_RESP_RECV;
|
||||
} else {
|
||||
BTFMCODEC_ERR("wrong packet format with len:%d", len);
|
||||
btfmcodec_dev->status[idx] = BTM_FAIL_RESP_RECV;
|
||||
}
|
||||
BTFMCODEC_INFO("Rx BTM_BTFMCODEC_BEARER_SWITCH_IND status:%d",
|
||||
status);
|
||||
wake_up_interruptible(&btfmcodec_dev->rsp_wait_q[idx]);
|
||||
break;
|
||||
case BTM_BTFMCODEC_CTRL_LOG_LVL_IND:
|
||||
if (len == BTM_LOG_LVL_IND_LEN) {
|
||||
log_lvl = skb->data[0];
|
||||
} else {
|
||||
BTFMCODEC_ERR("wrong packet format with len:%d", len);
|
||||
}
|
||||
BTFMCODEC_INFO("Rx BTM_BTFMCODEC_CTRL_LOG_LVL_IND status:%d",
|
||||
log_lvl);
|
||||
wake_up_interruptible(&btfmcodec_dev->rsp_wait_q[idx]);
|
||||
break;
|
||||
case BTM_BTFMCODEC_USECASE_START_RSP:
|
||||
idx = BTM_PKT_TYPE_USECASE_START_RSP;
|
||||
if (len == BTM_USECASE_START_RSP_LEN) {
|
||||
status = skb->data[0];
|
||||
if (status == MSG_SUCCESS)
|
||||
btfmcodec_dev->status[idx] = BTM_RSP_RECV;
|
||||
else
|
||||
btfmcodec_dev->status[idx] = BTM_FAIL_RESP_RECV;
|
||||
} else {
|
||||
BTFMCODEC_ERR("wrong packet format with len:%d", len);
|
||||
btfmcodec_dev->status[idx] = BTM_FAIL_RESP_RECV;
|
||||
}
|
||||
BTFMCODEC_INFO("Rx BTM_BTFMCODEC_USECASE_START_RSP status:%d",
|
||||
status);
|
||||
wake_up_interruptible(&btfmcodec_dev->rsp_wait_q[idx]);
|
||||
break;
|
||||
default:
|
||||
BTFMCODEC_ERR("wrong opcode:%08x", opcode);
|
||||
}
|
||||
kfree_skb(skb);
|
||||
}
|
||||
BTFMCODEC_DBG("end");
|
||||
}
|
||||
|
||||
/*
|
||||
* btfmcodec_pkt_write() - write() syscall for the btfmcodec_pkt device
|
||||
* file: Pointer to the file structure.
|
||||
* buf: Pointer to the userspace buffer.
|
||||
* count: Number bytes to read from the file.
|
||||
* ppos: Pointer to the position into the file.
|
||||
*
|
||||
* This function is used to write the data to btfmcodec dev node when
|
||||
* userspace client do a write() system call. All input arguments are
|
||||
* validated by the virtual file system before calling this function.
|
||||
*/
|
||||
static ssize_t btfmcodec_dev_write(struct file *file,
|
||||
const char __user *buf, size_t count, loff_t *ppos)
|
||||
{
|
||||
struct btfmcodec_data *btfmcodec = file->private_data;
|
||||
struct btfmcodec_char_device *btfmcodec_dev= NULL;
|
||||
struct sk_buff *skb;
|
||||
void *kbuf;
|
||||
int ret = 0;
|
||||
|
||||
if (!btfmcodec || !btfmcodec->btfmcodec_dev || refcount_read(&btfmcodec->btfmcodec_dev->active_clients) == 1) {
|
||||
BTFMCODEC_INFO("%s: %d\n", current->comm, task_pid_nr(current));
|
||||
return -EINVAL;
|
||||
} else {
|
||||
btfmcodec_dev = btfmcodec->btfmcodec_dev;
|
||||
}
|
||||
|
||||
if (mutex_lock_interruptible(&btfmcodec_dev->lock)) {
|
||||
ret = -ERESTARTSYS;
|
||||
goto free_kbuf;
|
||||
}
|
||||
|
||||
/* Hack for Now */
|
||||
if (count < MIN_PKT_LEN) {
|
||||
BTFMCODEC_ERR("minimum packet len should be greater than 3 bytes");
|
||||
goto free_kbuf;
|
||||
}
|
||||
if (refcount_read(&btfmcodec->btfmcodec_dev->active_clients) == 0) {
|
||||
BTFMCODEC_WARN("Client disconnected");
|
||||
ret = -ENETRESET;
|
||||
goto free_kbuf;
|
||||
}
|
||||
|
||||
BTFMCODEC_DBG("begin to %s buffer_size %zu\n", btfmcodec_dev->dev_name, count);
|
||||
kbuf = memdup_user(buf, count);
|
||||
if (IS_ERR(kbuf)) {
|
||||
ret = PTR_ERR(kbuf);
|
||||
goto free_kbuf;
|
||||
}
|
||||
|
||||
/* Check whether we need a dedicated chunk of memory for this driver */
|
||||
skb = alloc_skb(count* sizeof(size_t), GFP_KERNEL);
|
||||
if (!skb) {
|
||||
BTFMCODEC_ERR("failed to allocate memory for recevied packet");
|
||||
ret = -ENOMEM;
|
||||
goto free_kbuf;
|
||||
}
|
||||
|
||||
skb_put_data(skb, (uint8_t *)kbuf, count);
|
||||
skb_queue_tail(&btfmcodec_dev->rxq, skb);
|
||||
schedule_work(&btfmcodec_dev->rx_work);
|
||||
|
||||
kfree(kbuf);
|
||||
|
||||
free_kbuf:
|
||||
mutex_unlock(&btfmcodec_dev->lock);
|
||||
BTFMCODEC_DBG("finish to %s ret %d\n", btfmcodec_dev->dev_name, ret);
|
||||
return ret < 0 ? ret : count;
|
||||
}
|
||||
|
||||
int btfmcodec_dev_enqueue_pkt(struct btfmcodec_char_device *btfmcodec_dev, void *buf, int len)
|
||||
{
|
||||
struct sk_buff *skb;
|
||||
unsigned long flags;
|
||||
uint8_t *cmd = buf;
|
||||
|
||||
BTFMCODEC_DBG("start");
|
||||
spin_lock_irqsave(&btfmcodec_dev->tx_queue_lock, flags);
|
||||
if (refcount_read(&btfmcodec_dev->active_clients) == 1) {
|
||||
BTFMCODEC_WARN("no active clients discarding the packet");
|
||||
spin_unlock_irqrestore(&btfmcodec_dev->tx_queue_lock, flags);
|
||||
return -EINVAL;
|
||||
}
|
||||
skb = alloc_skb(len, GFP_ATOMIC);
|
||||
if (!skb) {
|
||||
BTFMCODEC_ERR("failed to allocate memory");
|
||||
spin_unlock_irqrestore(&btfmcodec_dev->tx_queue_lock, flags);
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
skb_put_data(skb, cmd, len);
|
||||
skb_queue_tail(&btfmcodec_dev->txq, skb);
|
||||
wake_up_interruptible(&btfmcodec_dev->readq);
|
||||
spin_unlock_irqrestore(&btfmcodec_dev->tx_queue_lock, flags);
|
||||
BTFMCODEC_DBG("end");
|
||||
return 0;
|
||||
}
|
||||
|
||||
int btfmcodec_enqueue_transport(struct btfmcodec_char_device *btfmcodec_dev,
|
||||
uint8_t transport)
|
||||
{
|
||||
struct sk_buff *skb;
|
||||
|
||||
mutex_lock(&btfmcodec_dev->trans_lock);
|
||||
skb = alloc_skb(1, GFP_ATOMIC);
|
||||
if (!skb) {
|
||||
BTFMCODEC_ERR("failed to allocate memory");
|
||||
mutex_unlock(&btfmcodec_dev->trans_lock);
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
skb_put_data(skb, &transport, 1);
|
||||
skb_queue_tail(&btfmcodec_dev->trans_rxq, skb);
|
||||
mutex_unlock(&btfmcodec_dev->trans_lock);
|
||||
wake_up_interruptible(&btfmcodec_dev->rsp_wait_q[BTM_PKT_TYPE_BEARER_SWITCH_IND]);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int btfmcodec_dequeue_transport(struct btfmcodec_char_device *btfmcodec_dev)
|
||||
{
|
||||
uint8_t transport = 0xFF;
|
||||
struct sk_buff *skb;
|
||||
|
||||
mutex_lock(&btfmcodec_dev->trans_lock);
|
||||
skb = skb_dequeue(&btfmcodec_dev->trans_rxq);
|
||||
if (!skb) {
|
||||
mutex_unlock(&btfmcodec_dev->trans_lock);
|
||||
return transport;
|
||||
}
|
||||
transport = skb->data[0];
|
||||
skb_pull(skb, 1);
|
||||
kfree_skb(skb);
|
||||
mutex_unlock(&btfmcodec_dev->trans_lock);
|
||||
return transport;
|
||||
}
|
||||
|
||||
/*
|
||||
* btfmcodec_pkt_poll() - poll() syscall for the btfmcodec device
|
||||
* file: Pointer to the file structure.
|
||||
* wait: pointer to Poll table.
|
||||
*
|
||||
* This function is used to poll on the btfmcodec dev node when
|
||||
* userspace client do a poll() system call. All input arguments are
|
||||
* validated by the virtual file system before calling this function.
|
||||
*/
|
||||
static __poll_t btfmcodec_dev_poll(struct file *file, poll_table *wait)
|
||||
{
|
||||
struct btfmcodec_data *btfmcodec = file->private_data;
|
||||
struct btfmcodec_char_device *btfmcodec_dev= NULL;
|
||||
__poll_t mask = 0;
|
||||
unsigned long flags;
|
||||
|
||||
BTFMCODEC_DBG("start");
|
||||
if (!btfmcodec || !btfmcodec->btfmcodec_dev || refcount_read(&btfmcodec->btfmcodec_dev->active_clients) == 1) {
|
||||
BTFMCODEC_INFO("%s: %d\n", current->comm, task_pid_nr(current));
|
||||
return -EINVAL;
|
||||
} else {
|
||||
btfmcodec_dev = btfmcodec->btfmcodec_dev;
|
||||
}
|
||||
|
||||
/* Wait here for timeout or for a wakeup signal on readq */
|
||||
poll_wait(file, &btfmcodec_dev->readq, wait);
|
||||
|
||||
mutex_lock(&btfmcodec_dev->lock);
|
||||
/* recheck if the client has released by the driver */
|
||||
if (refcount_read(&btfmcodec_dev->active_clients) == 1) {
|
||||
BTFMCODEC_WARN("port has been closed already");
|
||||
mutex_unlock(&btfmcodec_dev->lock);
|
||||
return POLLHUP;
|
||||
}
|
||||
|
||||
spin_lock_irqsave(&btfmcodec_dev->tx_queue_lock, flags);
|
||||
/* Set flags if data is avilable to read */
|
||||
if (!skb_queue_empty(&btfmcodec_dev->txq))
|
||||
mask |= POLLIN | POLLRDNORM;
|
||||
|
||||
spin_unlock_irqrestore(&btfmcodec_dev->tx_queue_lock, flags);
|
||||
mutex_unlock(&btfmcodec_dev->lock);
|
||||
|
||||
BTFMCODEC_DBG("end with reason %d", mask);
|
||||
return mask;
|
||||
}
|
||||
|
||||
/*
|
||||
* btfmcodec_dev_read() - read() syscall for the btfmcodec dev node
|
||||
* file: Pointer to the file structure.
|
||||
* buf: Pointer to the userspace buffer.
|
||||
* count: Number bytes to read from the file.
|
||||
* ppos: Pointer to the position into the file.
|
||||
*
|
||||
* This function is used to Read the data from btfmcodec pkt device when
|
||||
* userspace client do a read() system call. All input arguments are
|
||||
* validated by the virtual file system before calling this function.
|
||||
*/
|
||||
static ssize_t btfmcodec_dev_read(struct file *file,
|
||||
char __user *buf, size_t count, loff_t *ppos)
|
||||
{
|
||||
struct btfmcodec_data *btfmcodec = file->private_data;
|
||||
struct btfmcodec_char_device *btfmcodec_dev= NULL;
|
||||
unsigned long flags;
|
||||
struct sk_buff *skb;
|
||||
int use;
|
||||
|
||||
BTFMCODEC_DBG("start");
|
||||
if (!btfmcodec || !btfmcodec->btfmcodec_dev || refcount_read(&btfmcodec->btfmcodec_dev->active_clients) == 1) {
|
||||
BTFMCODEC_INFO("%s: %d\n", current->comm, task_pid_nr(current));
|
||||
return -EINVAL;
|
||||
} else {
|
||||
btfmcodec_dev = btfmcodec->btfmcodec_dev;
|
||||
}
|
||||
|
||||
spin_lock_irqsave(&btfmcodec_dev->tx_queue_lock, flags);
|
||||
/* Wait for data in the queue */
|
||||
if (skb_queue_empty(&btfmcodec_dev->txq)) {
|
||||
spin_unlock_irqrestore(&btfmcodec_dev->tx_queue_lock, flags);
|
||||
|
||||
if (file->f_flags & O_NONBLOCK)
|
||||
return -EAGAIN;
|
||||
|
||||
/* Wait until we get data*/
|
||||
if (wait_event_interruptible(btfmcodec_dev->readq,
|
||||
!skb_queue_empty(&btfmcodec_dev->txq)))
|
||||
return -ERESTARTSYS;
|
||||
|
||||
/* We lost the client while waiting */
|
||||
if (refcount_read(&btfmcodec->btfmcodec_dev->active_clients) == 1)
|
||||
return -ENETRESET;
|
||||
|
||||
spin_lock_irqsave(&btfmcodec_dev->tx_queue_lock, flags);
|
||||
}
|
||||
|
||||
skb = skb_dequeue(&btfmcodec_dev->txq);
|
||||
spin_unlock_irqrestore(&btfmcodec_dev->tx_queue_lock, flags);
|
||||
if (!skb)
|
||||
return -EFAULT;
|
||||
|
||||
use = min_t(size_t, count, skb->len);
|
||||
if (copy_to_user(buf, skb->data, use))
|
||||
use = -EFAULT;
|
||||
|
||||
kfree_skb(skb);
|
||||
|
||||
BTFMCODEC_DBG("end for %s by %s:%d ret[%d]\n", btfmcodec_dev->dev_name,
|
||||
current->comm, task_pid_nr(current), use);
|
||||
|
||||
return use;
|
||||
}
|
||||
|
||||
bool isCpSupported(void)
|
||||
{
|
||||
return is_cp_supported;
|
||||
}
|
||||
|
||||
static long btfmcodec_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
|
||||
{
|
||||
struct btfmcodec_data *btfmcodec = file->private_data;
|
||||
struct hwep_data *hwep_info;
|
||||
|
||||
BTFMCODEC_INFO("%s: command %04x", __func__, cmd);
|
||||
|
||||
mutex_lock(&btfmcodec->hwep_drv_lock);
|
||||
hwep_info = btfmcodec->hwep_info;
|
||||
if (!hwep_info) {
|
||||
BTFMCODEC_WARN("%s: HWEP is not registered with btfmcodec", __func__);
|
||||
BTFMCODEC_WARN("%s: caching required info", __func__);
|
||||
is_cp_supported = ((int)arg == 1) ? true : false;
|
||||
mutex_unlock(&btfmcodec->hwep_drv_lock);
|
||||
return 0;
|
||||
}
|
||||
|
||||
mutex_unlock(&btfmcodec->hwep_drv_lock);
|
||||
switch (cmd) {
|
||||
case BTM_CP_UPDATE: {
|
||||
if ((int)arg == 1) {
|
||||
if (!strcmp(hwep_info->driver_name, "btfmslim"))
|
||||
set_bit(BTADV_AUDIO_MASTER_CONFIG, &hwep_info->flags);
|
||||
else if (!strcmp(hwep_info->driver_name, "btfmswr_slave"))
|
||||
set_bit(BTADV_CONFIGURE_DMA, &hwep_info->flags);
|
||||
BTFMCODEC_INFO("%s: This target support CP hwep %s",
|
||||
__func__, hwep_info->driver_name);
|
||||
} else {
|
||||
clear_bit(BTADV_AUDIO_MASTER_CONFIG, &hwep_info->flags);
|
||||
clear_bit(BTADV_CONFIGURE_DMA, &hwep_info->flags);
|
||||
BTFMCODEC_INFO("%s: This target support doesn't CP", __func__);
|
||||
}
|
||||
|
||||
BTFMCODEC_INFO("%s: mastr %d dma codec %d", __func__,
|
||||
(int)test_bit(BTADV_AUDIO_MASTER_CONFIG, &hwep_info->flags),
|
||||
(int)test_bit(BTADV_CONFIGURE_DMA, &hwep_info->flags));
|
||||
break;
|
||||
} default: {
|
||||
BTFMCODEC_ERR("%s unhandled cmd %04x", __func__, cmd);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
static const struct file_operations btfmcodec_fops = {
|
||||
.owner = THIS_MODULE,
|
||||
.open = btfmcodec_dev_open,
|
||||
.release = btfmcodec_dev_release,
|
||||
.write = btfmcodec_dev_write,
|
||||
.poll = btfmcodec_dev_poll,
|
||||
.read = btfmcodec_dev_read,
|
||||
/* For Now add no hookups for below callbacks */
|
||||
.unlocked_ioctl = btfmcodec_ioctl,
|
||||
.compat_ioctl = btfmcodec_ioctl,
|
||||
};
|
||||
|
||||
static ssize_t btfmcodec_attributes_store(struct device *dev,
|
||||
struct device_attribute *attr,
|
||||
const char *buf, size_t n)
|
||||
{
|
||||
struct btfmcodec_data *btfmcodec = dev_to_btfmcodec(dev);
|
||||
struct btfmcodec_char_device *btfmcodec_dev = btfmcodec->btfmcodec_dev;
|
||||
long tmp;
|
||||
|
||||
mutex_lock(&btfmcodec_dev->lock);
|
||||
if (kstrtol(buf, 0, &tmp)) {
|
||||
mutex_unlock(&btfmcodec_dev->lock);
|
||||
return -EINVAL;
|
||||
}
|
||||
mutex_unlock(&btfmcodec_dev->lock);
|
||||
|
||||
return n;
|
||||
}
|
||||
|
||||
static ssize_t btfmcodec_attributes_show(struct device *dev,
|
||||
struct device_attribute *attr,
|
||||
char *buf)
|
||||
{
|
||||
// struct btfmcodec_get_current_transport *btfmcodec_dev = dev_to_btfmcodec(dev);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct btfmcodec_data* btfm_get_btfmcodec(void)
|
||||
{
|
||||
return btfmcodec;
|
||||
}
|
||||
EXPORT_SYMBOL(btfm_get_btfmcodec);
|
||||
|
||||
static DEVICE_ATTR_RW(btfmcodec_attributes);
|
||||
|
||||
static int __init btfmcodec_init(void)
|
||||
{
|
||||
struct btfmcodec_state_machine *states;
|
||||
struct btfmcodec_char_device *btfmcodec_dev;
|
||||
struct device *dev;
|
||||
int ret, i;
|
||||
|
||||
BTFMCODEC_INFO("starting up the module");
|
||||
btfmcodec = kzalloc(sizeof(struct btfmcodec_data), GFP_KERNEL);
|
||||
if (!btfmcodec) {
|
||||
BTFMCODEC_ERR("failed to allocate memory");
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
mutex_init(&btfmcodec->hwep_drv_lock);
|
||||
states = &btfmcodec->states;
|
||||
states->current_state = IDLE;
|
||||
states->next_state = IDLE;
|
||||
|
||||
BTFMCODEC_INFO("creating device node");
|
||||
/* create device node for communication between userspace and kernel */
|
||||
btfmcodec_dev = kzalloc(sizeof(struct btfmcodec_char_device), GFP_KERNEL);
|
||||
if (!btfmcodec_dev) {
|
||||
BTFMCODEC_ERR("failed to allocate memory");
|
||||
ret = -ENOMEM;
|
||||
goto info_cleanup;
|
||||
}
|
||||
|
||||
BTFMCODEC_INFO("trying to get major number\n");
|
||||
ret = alloc_chrdev_region(&dev_major, 0, 0, "btfmcodec");
|
||||
if (ret < 0) {
|
||||
BTFMCODEC_ERR("failed to allocate character device region");
|
||||
goto dev_cleanup;
|
||||
}
|
||||
|
||||
BTFMCODEC_INFO("creating btfm codec class");
|
||||
dev_class = class_create("btfmcodec");
|
||||
if (IS_ERR(dev_class)) {
|
||||
ret = PTR_ERR(dev_class);
|
||||
BTFMCODEC_ERR("class_create failed ret:%d\n", ret);
|
||||
goto deinit_chrdev;
|
||||
}
|
||||
|
||||
btfmcodec_dev->reuse_minor = idr_alloc(&dev_minor, btfmcodec, 1, 0, GFP_KERNEL);
|
||||
if (ret < 0) {
|
||||
BTFMCODEC_ERR("failed to allocated minor number");
|
||||
goto deinit_class;
|
||||
}
|
||||
|
||||
dev = &btfmcodec->dev;
|
||||
dev->driver = &driver;
|
||||
|
||||
// ToDo Rethink of having btfmcodec alone instead of btfmcodec
|
||||
btfmcodec->btfmcodec_dev = btfmcodec_dev;
|
||||
refcount_set(&btfmcodec_dev->active_clients, 1);
|
||||
mutex_init(&btfmcodec_dev->lock);
|
||||
mutex_init(&btfmcodec_dev->trans_lock);
|
||||
strscpy(btfmcodec_dev->dev_name, "btfmcodec_dev", DEVICE_NAME_MAX_LEN);
|
||||
device_initialize(dev);
|
||||
dev->class = dev_class;
|
||||
dev->devt = MKDEV(MAJOR(dev_major), btfmcodec_dev->reuse_minor);
|
||||
dev_set_drvdata(dev, btfmcodec);
|
||||
|
||||
cdev_init(&btfmcodec_dev->cdev, &btfmcodec_fops);
|
||||
btfmcodec_dev->cdev.owner = THIS_MODULE;
|
||||
btfmcodec_dev->btfmcodec = (struct btfmcodec_data *)btfmcodec;
|
||||
dev_set_name(dev, btfmcodec_dev->dev_name, btfmcodec_dev->reuse_minor);
|
||||
ret = cdev_add(&btfmcodec_dev->cdev, dev->devt, 1);
|
||||
if (ret) {
|
||||
BTFMCODEC_ERR("cdev_add failed with error no %d", ret);
|
||||
goto idr_cleanup;
|
||||
}
|
||||
|
||||
// ToDo to handler HIDL abrupt kill
|
||||
dev->release = NULL;
|
||||
ret = device_add(dev);
|
||||
if (ret) {
|
||||
BTFMCODEC_ERR("Failed to add device error no %d", ret);
|
||||
goto free_device;
|
||||
}
|
||||
|
||||
BTFMCODEC_ERR("Creating a sysfs entry with name: %s", btfmcodec_dev->dev_name);
|
||||
ret = device_create_file(dev, &dev_attr_btfmcodec_attributes);
|
||||
if (ret) {
|
||||
BTFMCODEC_ERR("Failed to create a devicd node: %s", btfmcodec_dev->dev_name);
|
||||
goto free_device;
|
||||
}
|
||||
|
||||
BTFMCODEC_INFO("created a node at /dev/%s with %u:%u\n",
|
||||
btfmcodec_dev->dev_name, dev_major, btfmcodec_dev->reuse_minor);
|
||||
|
||||
skb_queue_head_init(&btfmcodec_dev->rxq);
|
||||
skb_queue_head_init(&btfmcodec_dev->trans_rxq);
|
||||
mutex_init(&btfmcodec_dev->lock);
|
||||
INIT_WORK(&btfmcodec_dev->rx_work, btfmcodec_dev_rxwork);
|
||||
init_waitqueue_head(&btfmcodec_dev->readq);
|
||||
spin_lock_init(&btfmcodec_dev->tx_queue_lock);
|
||||
skb_queue_head_init(&btfmcodec_dev->txq);
|
||||
INIT_LIST_HEAD(&btfmcodec->config_head);
|
||||
for (i = 0; i < BTM_PKT_TYPE_MAX; i++) {
|
||||
init_waitqueue_head(&btfmcodec_dev->rsp_wait_q[i]);
|
||||
}
|
||||
mutex_init(&states->state_machine_lock);
|
||||
btfmcodec_dev->workqueue = alloc_ordered_workqueue("btfmcodec_wq", 0);
|
||||
if (!btfmcodec_dev->workqueue) {
|
||||
BTFMCODEC_ERR("btfmcodec_dev Workqueue not initialized properly");
|
||||
ret = -ENOMEM;
|
||||
goto free_device;
|
||||
}
|
||||
return ret;
|
||||
|
||||
free_device:
|
||||
put_device(dev);
|
||||
idr_cleanup:
|
||||
idr_remove(&dev_minor, btfmcodec_dev->reuse_minor);
|
||||
deinit_class:
|
||||
class_destroy(dev_class);
|
||||
deinit_chrdev:
|
||||
unregister_chrdev_region(MAJOR(dev_major), 0);
|
||||
dev_cleanup:
|
||||
kfree(btfmcodec_dev);
|
||||
info_cleanup:
|
||||
kfree(btfmcodec);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void __exit btfmcodec_deinit(void)
|
||||
{
|
||||
struct btfmcodec_char_device *btfmcodec_dev;
|
||||
struct device *dev;
|
||||
BTFMCODEC_INFO("%s: cleaning up btfm codec driver", __func__);
|
||||
if (!btfmcodec) {
|
||||
BTFMCODEC_ERR("%s: skiping driver cleanup", __func__);
|
||||
goto info_cleanup;
|
||||
}
|
||||
|
||||
dev = &btfmcodec->dev;
|
||||
|
||||
device_remove_file(dev, &dev_attr_btfmcodec_attributes);
|
||||
put_device(dev);
|
||||
|
||||
if (!btfmcodec->btfmcodec_dev) {
|
||||
BTFMCODEC_ERR("%s: skiping device node cleanup", __func__);
|
||||
goto info_cleanup;
|
||||
}
|
||||
|
||||
btfmcodec_dev = btfmcodec->btfmcodec_dev;
|
||||
skb_queue_purge(&btfmcodec_dev->rxq);
|
||||
idr_remove(&dev_minor, btfmcodec_dev->reuse_minor);
|
||||
class_destroy(dev_class);
|
||||
unregister_chrdev_region(MAJOR(dev_major), 0);
|
||||
kfree(btfmcodec_dev);
|
||||
info_cleanup:
|
||||
kfree(btfmcodec);
|
||||
BTFMCODEC_INFO("%s: btfm codec driver cleanup completed", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
MODULE_LICENSE("GPL v2");
|
||||
MODULE_DESCRIPTION("MSM Bluetooth FM CODEC driver");
|
||||
|
||||
module_init(btfmcodec_init);
|
||||
module_exit(btfmcodec_deinit);
|
||||
352
qcom/opensource/bt-kernel/btfmcodec/btfm_codec_btadv_interface.c
Normal file
352
qcom/opensource/bt-kernel/btfmcodec/btfm_codec_btadv_interface.c
Normal file
@@ -0,0 +1,352 @@
|
||||
// SPDX-License-Identifier: GPL-2.0-only
|
||||
/*
|
||||
* Copyright (c) 2023-2024 Qualcomm Innovation Center, Inc. All rights reserved.
|
||||
*/
|
||||
|
||||
#include "btfm_codec.h"
|
||||
#include "btfm_codec_pkt.h"
|
||||
#include "btfm_codec_btadv_interface.h"
|
||||
|
||||
void btfmcodec_initiate_hwep_shutdown(struct btfmcodec_char_device *btfmcodec_dev)
|
||||
{
|
||||
wait_queue_head_t *rsp_wait_q =
|
||||
&btfmcodec_dev->rsp_wait_q[BTM_PKT_TYPE_HWEP_SHUTDOWN];
|
||||
int ret;
|
||||
uint8_t *status = &btfmcodec_dev->status[BTM_PKT_TYPE_HWEP_SHUTDOWN];
|
||||
|
||||
*status = BTM_WAITING_RSP;
|
||||
BTFMCODEC_INFO("queuing work to shutdown");
|
||||
schedule_work(&btfmcodec_dev->wq_hwep_shutdown);
|
||||
BTFMCODEC_INFO("waiting here for shutdown");
|
||||
ret = wait_event_interruptible_timeout(*rsp_wait_q,
|
||||
*status != BTM_WAITING_RSP,
|
||||
msecs_to_jiffies(BTM_MASTER_CONFIG_RSP_TIMEOUT));
|
||||
|
||||
/* Rethink of having a new packet to notify transport switch error */
|
||||
if (ret == 0) {
|
||||
BTFMCODEC_ERR("failed to recevie to complete hwep_shutdown");
|
||||
flush_work(&btfmcodec_dev->wq_hwep_shutdown);
|
||||
} else {
|
||||
if (*status == BTM_RSP_RECV) {
|
||||
BTFMCODEC_ERR("sucessfully closed hwep");
|
||||
return;
|
||||
} else if (*status == BTM_FAIL_RESP_RECV ||
|
||||
*status == BTM_RSP_NOT_RECV_CLIENT_KILLED) {
|
||||
BTFMCODEC_ERR("Failed to close hwep");
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void btfmcodec_move_to_next_state(struct btfmcodec_state_machine *state)
|
||||
{
|
||||
mutex_lock(&state->state_machine_lock);
|
||||
if (state->current_state == BT_Connecting ||
|
||||
state->current_state == BTADV_AUDIO_Connecting) {
|
||||
state->current_state += 1;
|
||||
BTFMCODEC_INFO("moving from %s to %s",
|
||||
coverttostring(state->current_state -1 ),
|
||||
coverttostring(state->current_state));
|
||||
} else {
|
||||
BTFMCODEC_ERR("State machine might have gone bad. reseting to default");
|
||||
state->current_state = IDLE;
|
||||
}
|
||||
|
||||
state->prev_state = IDLE;
|
||||
mutex_unlock(&state->state_machine_lock);
|
||||
}
|
||||
|
||||
void btfmcodec_revert_current_state(struct btfmcodec_state_machine *state)
|
||||
{
|
||||
mutex_lock(&state->state_machine_lock);
|
||||
BTFMCODEC_INFO("reverting from %s to %s", coverttostring(state->current_state),
|
||||
coverttostring(state->prev_state));
|
||||
state->current_state = state->prev_state;
|
||||
state->prev_state = IDLE;
|
||||
mutex_unlock(&state->state_machine_lock);
|
||||
}
|
||||
|
||||
void btfmcodec_set_current_state(struct btfmcodec_state_machine *state,
|
||||
btfmcodec_state current_state)
|
||||
{
|
||||
mutex_lock(&state->state_machine_lock);
|
||||
BTFMCODEC_INFO("moving from %s to %s", coverttostring(state->current_state),
|
||||
coverttostring(current_state));
|
||||
state->prev_state = state->current_state;
|
||||
state->current_state = current_state;
|
||||
mutex_unlock(&state->state_machine_lock);
|
||||
}
|
||||
|
||||
btfmcodec_state btfmcodec_get_current_transport(struct
|
||||
btfmcodec_state_machine *state)
|
||||
{
|
||||
btfmcodec_state current_state;
|
||||
|
||||
mutex_lock(&state->state_machine_lock);
|
||||
current_state = state->current_state;
|
||||
mutex_unlock(&state->state_machine_lock);
|
||||
return current_state;
|
||||
}
|
||||
|
||||
btfmcodec_state btfmcodec_get_prev_transport(struct btfmcodec_state_machine *state)
|
||||
{
|
||||
btfmcodec_state prev_state;
|
||||
|
||||
mutex_lock(&state->state_machine_lock);
|
||||
prev_state = state->prev_state;
|
||||
mutex_unlock(&state->state_machine_lock);
|
||||
return prev_state;
|
||||
}
|
||||
|
||||
int btfmcodec_frame_transport_switch_ind_pkt(struct btfmcodec_char_device *btfmcodec_dev,
|
||||
uint8_t active_transport,
|
||||
uint8_t status)
|
||||
{
|
||||
struct btm_ctrl_pkt rsp;
|
||||
|
||||
rsp.opcode = BTM_BTFMCODEC_TRANSPORT_SWITCH_FAILED_IND;
|
||||
rsp.len = BTM_PREPARE_AUDIO_BEARER_SWITCH_RSP_LEN;
|
||||
rsp.active_transport = active_transport;
|
||||
rsp.status = status;
|
||||
return btfmcodec_dev_enqueue_pkt(btfmcodec_dev, &rsp, (rsp.len +
|
||||
BTM_HEADER_LEN));
|
||||
}
|
||||
|
||||
int btfmcodec_frame_prepare_bearer_rsp_pkt(struct btfmcodec_char_device *btfmcodec_dev,
|
||||
uint8_t active_transport,
|
||||
uint8_t status)
|
||||
{
|
||||
struct btm_ctrl_pkt rsp;
|
||||
|
||||
rsp.opcode = BTM_BTFMCODEC_PREPARE_AUDIO_BEARER_SWITCH_RSP;
|
||||
rsp.len =BTM_PREPARE_AUDIO_BEARER_SWITCH_RSP_LEN;
|
||||
rsp.active_transport = active_transport;
|
||||
rsp.status = status;
|
||||
return btfmcodec_dev_enqueue_pkt(btfmcodec_dev, &rsp, (rsp.len +
|
||||
BTM_HEADER_LEN));
|
||||
}
|
||||
|
||||
int btfmcodec_wait_for_bearer_ind(struct btfmcodec_char_device *btfmcodec_dev)
|
||||
{
|
||||
wait_queue_head_t *rsp_wait_q =
|
||||
&btfmcodec_dev->rsp_wait_q[BTM_PKT_TYPE_BEARER_SWITCH_IND];
|
||||
int ret;
|
||||
uint8_t *status = &btfmcodec_dev->status[BTM_PKT_TYPE_BEARER_SWITCH_IND];
|
||||
|
||||
ret = wait_event_interruptible_timeout(*rsp_wait_q,
|
||||
(*status != BTM_WAITING_RSP ||
|
||||
skb_queue_empty(&btfmcodec_dev->trans_rxq) != true),
|
||||
msecs_to_jiffies(BTM_BEARER_SWITCH_IND_TIMEOUT));
|
||||
|
||||
if (!skb_queue_empty(&btfmcodec_dev->trans_rxq)) {
|
||||
BTFMCODEC_INFO("%s: new transport is waiting to process", __func__);
|
||||
ret = -1;
|
||||
return ret;
|
||||
}
|
||||
|
||||
if (ret == 0) {
|
||||
BTFMCODEC_ERR("failed to recevie BTM_BEARER_SWITCH_IND");
|
||||
ret = -MSG_INTERNAL_TIMEOUT;
|
||||
} else {
|
||||
if (*status == BTM_RSP_RECV) {
|
||||
ret = 0;
|
||||
} else if (*status == BTM_FAIL_RESP_RECV) {
|
||||
BTFMCODEC_ERR("Rx BTM_BEARER_SWITCH_IND with failure status");
|
||||
ret = -1;
|
||||
} else if (*status == BTM_RSP_NOT_RECV_CLIENT_KILLED) {
|
||||
BTFMCODEC_ERR("client killed so moving further");
|
||||
ret = -1;
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int btfmcodec_initiate_hwep_configuration(struct btfmcodec_char_device *btfmcodec_dev)
|
||||
{
|
||||
wait_queue_head_t *rsp_wait_q =
|
||||
&btfmcodec_dev->rsp_wait_q[BTM_PKT_TYPE_HWEP_CONFIG];
|
||||
uint8_t *status = &btfmcodec_dev->status[BTM_PKT_TYPE_HWEP_CONFIG];
|
||||
int ret;
|
||||
|
||||
schedule_work(&btfmcodec_dev->wq_hwep_configure);
|
||||
|
||||
*status = BTM_WAITING_RSP;
|
||||
ret = wait_event_interruptible_timeout(*rsp_wait_q,
|
||||
*status != BTM_WAITING_RSP,
|
||||
msecs_to_jiffies(BTM_MASTER_CONFIG_RSP_TIMEOUT));
|
||||
|
||||
if (ret == 0) {
|
||||
BTFMCODEC_ERR("failed to recevie complete hwep configure");
|
||||
flush_work(&btfmcodec_dev->wq_hwep_configure);
|
||||
ret = -1;
|
||||
} else {
|
||||
if (*status == BTM_RSP_RECV) {
|
||||
ret = 0;
|
||||
} else if (*status == BTM_FAIL_RESP_RECV ||
|
||||
*status == BTM_RSP_NOT_RECV_CLIENT_KILLED) {
|
||||
BTFMCODEC_ERR("Failed to close hwep moving back to previous state");
|
||||
ret = -1;
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
void btfmcodec_configure_hwep(struct btfmcodec_char_device *btfmcodec_dev)
|
||||
{
|
||||
struct btfmcodec_data *btfmcodec = (struct btfmcodec_data *)btfmcodec_dev->btfmcodec;
|
||||
struct btfmcodec_state_machine *state = &btfmcodec->states;
|
||||
int ret;
|
||||
uint8_t status = MSG_SUCCESS;
|
||||
|
||||
ret = btfmcodec_initiate_hwep_configuration(btfmcodec_dev);
|
||||
if (ret < 0) {
|
||||
status = MSG_FAILED_TO_CONFIGURE_HWEP;
|
||||
/* Move back to BTADV_AUDIO_Connected from BT_Connecting */
|
||||
btfmcodec_revert_current_state(state);
|
||||
}
|
||||
|
||||
ret = btfmcodec_frame_prepare_bearer_rsp_pkt(btfmcodec_dev,
|
||||
btfmcodec_get_current_transport(state), status);
|
||||
|
||||
if (status != MSG_SUCCESS)
|
||||
return;
|
||||
|
||||
if (ret == 0) {
|
||||
ret = btfmcodec_wait_for_bearer_ind(btfmcodec_dev);
|
||||
if (ret < 0) {
|
||||
/* Move back to BTADV_AUDIO_Connected for failure cases*/
|
||||
BTFMCODEC_ERR("moving back to previous state");
|
||||
btfmcodec_revert_current_state(state);
|
||||
/* close HWEP */
|
||||
btfmcodec_initiate_hwep_shutdown(btfmcodec_dev);
|
||||
if (ret == -MSG_INTERNAL_TIMEOUT) {
|
||||
btfmcodec_frame_transport_switch_ind_pkt(btfmcodec_dev, BT,
|
||||
MSG_INTERNAL_TIMEOUT);
|
||||
}
|
||||
} else {
|
||||
/* move from BT_Connecting to BT_Connected */
|
||||
btfmcodec_move_to_next_state(state);
|
||||
}
|
||||
} else {
|
||||
/* add code to handle packet errors */
|
||||
}
|
||||
}
|
||||
|
||||
void btfmcodec_prepare_bearer(struct btfmcodec_char_device *btfmcodec_dev,
|
||||
enum transport_type new_transport)
|
||||
{
|
||||
struct btfmcodec_data *btfmcodec = (struct btfmcodec_data *)btfmcodec_dev->btfmcodec;
|
||||
struct btfmcodec_state_machine *state = &btfmcodec->states;
|
||||
btfmcodec_state current_state;
|
||||
int ret = -1;
|
||||
|
||||
if (new_transport > (ARRAY_SIZE(transport_type_text))) {
|
||||
btfmcodec_frame_prepare_bearer_rsp_pkt(btfmcodec_dev,
|
||||
(uint8_t) btfmcodec_get_current_transport(state),
|
||||
MSG_WRONG_TRANSPORT_TYPE);
|
||||
return;
|
||||
}
|
||||
|
||||
BTFMCODEC_INFO("Rx to switch from transport type %s to %s",
|
||||
coverttostring(btfmcodec_get_current_transport(state)),
|
||||
transport_type_text[new_transport - 1]);
|
||||
|
||||
current_state = btfmcodec_get_current_transport(state);
|
||||
if (new_transport == BT) {
|
||||
/* If BT is already active. send +ve ack to BTADV Audio Manager */
|
||||
if (current_state == BT_Connected ||
|
||||
current_state == BT_Connecting) {
|
||||
btfmcodec_frame_prepare_bearer_rsp_pkt(btfmcodec_dev,
|
||||
(uint8_t)current_state, MSG_SUCCESS);
|
||||
return;
|
||||
} else if (current_state == BTADV_AUDIO_Connected ||
|
||||
current_state == BTADV_AUDIO_Connecting||
|
||||
current_state == IDLE) {
|
||||
if (btfmcodec_is_valid_cache_avb(btfmcodec)) {
|
||||
BTFMCODEC_INFO("detected BTADV audio Gaming usecase to BT usecase");
|
||||
btfmcodec_set_current_state(state, BT_Connecting);
|
||||
btfmcodec_configure_hwep(btfmcodec_dev);
|
||||
} else {
|
||||
if (current_state != IDLE)
|
||||
BTFMCODEC_INFO("detected BTADV Audio lossless to IDLE");
|
||||
BTFMCODEC_INFO("moving to IDLE as no config available");
|
||||
btfmcodec_set_current_state(state, IDLE);
|
||||
btfmcodec_frame_prepare_bearer_rsp_pkt(btfmcodec_dev,
|
||||
btfmcodec_get_current_transport(state),
|
||||
MSG_SUCCESS);
|
||||
/* No need wait for bearer switch indications as BTFMCODEC
|
||||
* driver doesn't have configs to configure
|
||||
*/
|
||||
}
|
||||
}
|
||||
} else if(new_transport == BTADV) {
|
||||
/* If BTADV audio is already active. send +ve ack to BTADV audio Manager */
|
||||
if (current_state == BTADV_AUDIO_Connecting ||
|
||||
current_state == BTADV_AUDIO_Connected) {
|
||||
btfmcodec_frame_prepare_bearer_rsp_pkt(btfmcodec_dev,
|
||||
(uint8_t)current_state, MSG_SUCCESS);
|
||||
return;
|
||||
} else {
|
||||
btfmcodec_set_current_state(state, BTADV_AUDIO_Connecting);
|
||||
if (btfmcodec_is_valid_cache_avb(btfmcodec)) {
|
||||
BTFMCODEC_INFO("detected BT to BTADV audio Gaming usecase");
|
||||
} else {
|
||||
BTFMCODEC_INFO("detected IDLE to BTADV audio lossless usecase");
|
||||
}
|
||||
|
||||
ret = btfmcodec_frame_prepare_bearer_rsp_pkt(btfmcodec_dev,
|
||||
BTADV_AUDIO_Connecting, MSG_SUCCESS);
|
||||
if (ret < 0)
|
||||
return;
|
||||
|
||||
/* Wait here to get Bearer switch indication */
|
||||
ret = btfmcodec_wait_for_bearer_ind(btfmcodec_dev);
|
||||
if (ret < 0) {
|
||||
BTFMCODEC_ERR("moving back to previous state");
|
||||
if (btfmcodec_get_current_transport(state) == IDLE) {
|
||||
BTFMCODEC_INFO("state moved to IDLE");
|
||||
} else if (current_state == btfmcodec_get_prev_transport(state)) {
|
||||
btfmcodec_revert_current_state(state);
|
||||
}
|
||||
if (ret == -MSG_INTERNAL_TIMEOUT) {
|
||||
btfmcodec_frame_transport_switch_ind_pkt(
|
||||
btfmcodec_dev, BTADV,
|
||||
MSG_INTERNAL_TIMEOUT);
|
||||
}
|
||||
} else {
|
||||
btfmcodec_move_to_next_state(state);
|
||||
}
|
||||
if (ret < 0)
|
||||
return;
|
||||
|
||||
if (current_state != IDLE && btfmcodec_is_valid_cache_avb(btfmcodec)) {
|
||||
BTFMCODEC_INFO("Initiating BT port close...");
|
||||
btfmcodec_initiate_hwep_shutdown(btfmcodec_dev);
|
||||
}
|
||||
}
|
||||
} else if (new_transport == NONE) {
|
||||
/* Let ALSA handles the transport close for BT */
|
||||
if (current_state != BT_Connecting && current_state != BT_Connected)
|
||||
btfmcodec_set_current_state(state, IDLE);
|
||||
btfmcodec_frame_prepare_bearer_rsp_pkt(btfmcodec_dev, (uint8_t)current_state,
|
||||
MSG_SUCCESS);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void btfmcodec_wq_prepare_bearer(struct work_struct *work)
|
||||
{
|
||||
struct btfmcodec_char_device *btfmcodec_dev = container_of(work,
|
||||
struct btfmcodec_char_device,
|
||||
wq_prepare_bearer);
|
||||
int transport = btfmcodec_dequeue_transport(btfmcodec_dev);
|
||||
|
||||
BTFMCODEC_INFO("%s new transport:%d", __func__, transport);
|
||||
|
||||
if (transport == 0xFF)
|
||||
BTFMCODEC_ERR("invalid transport");
|
||||
else
|
||||
btfmcodec_prepare_bearer(btfmcodec_dev, transport);
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
// SPDX-License-Identifier: GPL-2.0-only
|
||||
/*
|
||||
* Copyright (c) 2023 Qualcomm Innovation Center, Inc. All rights reserved.
|
||||
*/
|
||||
#include "btfm_codec.h"
|
||||
#include "btfm_codec_hw_interface.h"
|
||||
#include "btfm_codec_interface.h"
|
||||
|
||||
int btfmcodec_register_hw_ep (struct hwep_data *ep_info)
|
||||
{
|
||||
struct btfmcodec_data *btfmcodec;
|
||||
struct hwep_data *hwep_info;
|
||||
int ret = 0;
|
||||
|
||||
btfmcodec = btfm_get_btfmcodec();
|
||||
mutex_lock(&btfmcodec->hwep_drv_lock);
|
||||
if (!btfmcodec) {
|
||||
BTFMCODEC_ERR("btfm codec driver it not initialized");
|
||||
ret = -EPERM;
|
||||
goto end;
|
||||
}
|
||||
|
||||
if (ep_info->num_dai == 0) {
|
||||
BTFMCODEC_ERR("no active information provided by hw ep interface");
|
||||
ret = -EPERM;
|
||||
goto end;
|
||||
|
||||
}
|
||||
|
||||
hwep_info = btfmcodec->hwep_info;
|
||||
if (hwep_info) {
|
||||
BTFMCODEC_ERR("driver already holds hardware endpoint info");
|
||||
ret = -EPERM;
|
||||
goto end;
|
||||
}
|
||||
|
||||
hwep_info = kzalloc(sizeof(struct hwep_data), GFP_KERNEL);
|
||||
if (!hwep_info) {
|
||||
BTFMCODEC_ERR("%s: failed to allocate memory\n", __func__);
|
||||
ret = -ENOMEM;
|
||||
goto end;
|
||||
}
|
||||
|
||||
btfmcodec->hwep_info = hwep_info;
|
||||
memcpy(hwep_info, ep_info, sizeof(struct hwep_data));
|
||||
|
||||
BTFMCODEC_INFO("Below driver registered with btfm codec\n");
|
||||
BTFMCODEC_INFO("Driver name: %s\n", hwep_info->driver_name);
|
||||
BTFMCODEC_INFO("Num of dai: %d supported", hwep_info->num_dai);
|
||||
BTFMCODEC_INFO("Master config enabled: %u\n", test_bit(BTADV_AUDIO_MASTER_CONFIG,
|
||||
&hwep_info->flags));
|
||||
ret = btfm_register_codec(hwep_info);
|
||||
end:
|
||||
mutex_unlock(&btfmcodec->hwep_drv_lock);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int btfmcodec_unregister_hw_ep (char *driver_name)
|
||||
{
|
||||
struct btfmcodec_data *btfmcodec;
|
||||
struct hwep_data *hwep_info;
|
||||
int ret;
|
||||
|
||||
btfmcodec = btfm_get_btfmcodec();
|
||||
mutex_lock(&btfmcodec->hwep_drv_lock);
|
||||
if (!btfmcodec) {
|
||||
BTFMCODEC_ERR("btfm codec driver it not initialized");
|
||||
ret = -EPERM;
|
||||
goto end;
|
||||
}
|
||||
|
||||
hwep_info = btfmcodec->hwep_info;
|
||||
if (!hwep_info) {
|
||||
BTFMCODEC_ERR("%s: no active hardware endpoint registered\n", __func__);
|
||||
ret = -EPERM;
|
||||
goto end;
|
||||
}
|
||||
|
||||
if(!strncmp(hwep_info->driver_name, driver_name, DEVICE_NAME_MAX_LEN)) {
|
||||
btfm_unregister_codec();
|
||||
kfree(hwep_info);
|
||||
BTFMCODEC_INFO("%s: deleted %s hardware endpoint\n", __func__, driver_name);
|
||||
ret = -1;
|
||||
goto end;
|
||||
} else {
|
||||
BTFMCODEC_ERR("%s: No hardware endpoint registered with %s\n", __func__, driver_name);
|
||||
ret = -1;
|
||||
goto end;
|
||||
}
|
||||
end:
|
||||
mutex_unlock(&btfmcodec->hwep_drv_lock);
|
||||
return ret;
|
||||
}
|
||||
|
||||
EXPORT_SYMBOL(btfmcodec_register_hw_ep);
|
||||
EXPORT_SYMBOL(btfmcodec_unregister_hw_ep);
|
||||
979
qcom/opensource/bt-kernel/btfmcodec/btfm_codec_interface.c
Normal file
979
qcom/opensource/bt-kernel/btfmcodec/btfm_codec_interface.c
Normal file
@@ -0,0 +1,979 @@
|
||||
// SPDX-License-Identifier: GPL-2.0-only
|
||||
/*
|
||||
* Copyright (c) 2023-2025 Qualcomm Innovation Center, Inc. All rights reserved.
|
||||
*/
|
||||
|
||||
#include <linux/kernel.h>
|
||||
#include <linux/remoteproc.h>
|
||||
#include <linux/remoteproc/qcom_rproc.h>
|
||||
#include "btfm_codec.h"
|
||||
#include "btfm_codec_interface.h"
|
||||
#include "btfm_codec_pkt.h"
|
||||
#include "btfm_codec_btadv_interface.h"
|
||||
|
||||
static struct snd_soc_dai_driver *btfmcodec_dai_info;
|
||||
uint32_t bits_per_second;
|
||||
uint8_t num_channels;
|
||||
static int btfmcodec_port_state_notify(uint8_t port_state);
|
||||
|
||||
static int btfm_codec_get_mixer_control(struct snd_kcontrol *kcontrol,
|
||||
struct snd_ctl_elem_value *ucontrol)
|
||||
{
|
||||
struct snd_soc_component *codec = kcontrol->private_data;
|
||||
struct btfmcodec_data *btfmcodec = snd_soc_component_get_drvdata(codec);
|
||||
struct hwep_data *hwepinfo = btfmcodec->hwep_info;
|
||||
struct snd_kcontrol_new *mixer_ctrl = hwepinfo->mixer_ctrl;
|
||||
struct snd_ctl_elem_id id = kcontrol->id;
|
||||
int num_mixer_ctrl = hwepinfo->num_mixer_ctrl;
|
||||
int i = 0;
|
||||
|
||||
BTFMCODEC_DBG("");
|
||||
for (; i < num_mixer_ctrl ; i++) {
|
||||
BTFMCODEC_DBG("checking mixer_ctrl:%s and current mixer:%s",
|
||||
id.name, mixer_ctrl[i].name);
|
||||
if (!strncmp(id.name, mixer_ctrl[i].name, 64)) {
|
||||
BTFMCODEC_DBG("Matched");
|
||||
mixer_ctrl[i].get(kcontrol, ucontrol);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (num_mixer_ctrl == i)
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
static int btfmcodec_put_mixer_control(struct snd_kcontrol *kcontrol,
|
||||
struct snd_ctl_elem_value *ucontrol)
|
||||
{
|
||||
struct snd_soc_component *codec = kcontrol->private_data;
|
||||
struct btfmcodec_data *btfmcodec = snd_soc_component_get_drvdata(codec);
|
||||
struct hwep_data *hwepinfo = btfmcodec->hwep_info;
|
||||
struct snd_kcontrol_new *mixer_ctrl = hwepinfo->mixer_ctrl;
|
||||
struct snd_ctl_elem_id id = kcontrol->id;
|
||||
int num_mixer_ctrl = hwepinfo->num_mixer_ctrl;
|
||||
int i = 0;
|
||||
|
||||
BTFMCODEC_DBG("");
|
||||
for (; i < num_mixer_ctrl ; i++) {
|
||||
BTFMCODEC_DBG("checking mixer_ctrl:%s and current mixer:%s",
|
||||
id.name, mixer_ctrl[i].name);
|
||||
if (!strncmp(id.name, mixer_ctrl[i].name, 64)) {
|
||||
BTFMCODEC_DBG("Matched");
|
||||
mixer_ctrl[i].put(kcontrol, ucontrol);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (num_mixer_ctrl == i)
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int btfmcodec_codec_probe(struct snd_soc_component *codec)
|
||||
{
|
||||
struct btfmcodec_data *btfmcodec = snd_soc_component_get_drvdata(codec);
|
||||
struct btfmcodec_state_machine *state = &btfmcodec->states;
|
||||
struct hwep_data *hwep_info = btfmcodec->hwep_info;
|
||||
int num_mixer_ctrl = hwep_info->num_mixer_ctrl;
|
||||
BTFMCODEC_DBG("");
|
||||
|
||||
// ToDo: check Whether probe has to allowed when state if different
|
||||
if (btfmcodec_get_current_transport(state)!= IDLE) {
|
||||
BTFMCODEC_WARN("Received probe when state is :%s",
|
||||
coverttostring(btfmcodec_get_current_transport(state)));
|
||||
} else if (hwep_info->drv && hwep_info->drv->hwep_probe) {
|
||||
hwep_info->drv->hwep_probe(codec);
|
||||
/* Register mixer control */
|
||||
if (hwep_info->mixer_ctrl && num_mixer_ctrl >= 1) {
|
||||
struct snd_kcontrol_new *mixer_ctrl;
|
||||
int i = 0;
|
||||
mixer_ctrl = (struct snd_kcontrol_new *)
|
||||
kzalloc(num_mixer_ctrl *
|
||||
sizeof(struct snd_kcontrol_new), GFP_KERNEL);
|
||||
if (!mixer_ctrl) {
|
||||
BTFMCODEC_ERR("failed to register mixer controls");
|
||||
goto end;
|
||||
}
|
||||
|
||||
BTFMCODEC_INFO("Registering %d mixer controls", num_mixer_ctrl);
|
||||
memcpy(mixer_ctrl, hwep_info->mixer_ctrl, num_mixer_ctrl * sizeof(struct snd_kcontrol_new));
|
||||
for (; i< num_mixer_ctrl; i++) {
|
||||
BTFMCODEC_INFO("name of control:%s", mixer_ctrl[i].name);
|
||||
mixer_ctrl[i].get = btfm_codec_get_mixer_control;
|
||||
mixer_ctrl[i].put = btfmcodec_put_mixer_control;
|
||||
}
|
||||
snd_soc_add_component_controls(codec, mixer_ctrl, num_mixer_ctrl);
|
||||
kfree(mixer_ctrl);
|
||||
BTFMCODEC_INFO("CODEC address while registering mixer ctrl:%p", codec);
|
||||
}
|
||||
}
|
||||
|
||||
end:
|
||||
// ToDo to add mixer control.
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void btfmcodec_codec_remove(struct snd_soc_component *codec)
|
||||
{
|
||||
struct btfmcodec_data *btfmcodec = snd_soc_component_get_drvdata(codec);
|
||||
struct btfmcodec_state_machine *state = &btfmcodec->states;
|
||||
struct hwep_data *hwep_info = btfmcodec->hwep_info;
|
||||
BTFMCODEC_DBG("");
|
||||
|
||||
// ToDo: check whether remove has to allowed when state if different
|
||||
if (btfmcodec_get_current_transport(state)!= IDLE) {
|
||||
BTFMCODEC_WARN("Received probe when state is :%s",
|
||||
coverttostring(btfmcodec_get_current_transport(state)));
|
||||
} else if (hwep_info->drv && hwep_info->drv->hwep_remove) {
|
||||
hwep_info->drv->hwep_remove(codec);
|
||||
}
|
||||
}
|
||||
|
||||
static int btfmcodec_codec_write(struct snd_soc_component *codec,
|
||||
unsigned int reg, unsigned int value)
|
||||
{
|
||||
struct btfmcodec_data *btfmcodec = snd_soc_component_get_drvdata(codec);
|
||||
struct btfmcodec_state_machine *state = &btfmcodec->states;
|
||||
struct hwep_data *hwep_info = btfmcodec->hwep_info;
|
||||
BTFMCODEC_DBG("");
|
||||
|
||||
// ToDo: check whether write has to allowed when state if different
|
||||
if (btfmcodec_get_current_transport(state)!= IDLE) {
|
||||
BTFMCODEC_WARN("Received probe when state is :%s",
|
||||
coverttostring(btfmcodec_get_current_transport(state)));
|
||||
} else if (hwep_info->drv && hwep_info->drv->hwep_remove) {
|
||||
return hwep_info->drv->hwep_write(codec, reg, value);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static unsigned int btfmcodec_codec_read(struct snd_soc_component *codec,
|
||||
unsigned int reg)
|
||||
{
|
||||
struct btfmcodec_data *btfmcodec = snd_soc_component_get_drvdata(codec);
|
||||
struct btfmcodec_state_machine *state = &btfmcodec->states;
|
||||
struct hwep_data *hwep_info = btfmcodec->hwep_info;
|
||||
BTFMCODEC_DBG("");
|
||||
|
||||
// ToDo: check whether read has to allowed when state if different
|
||||
if (btfmcodec_get_current_transport(state)!= IDLE) {
|
||||
BTFMCODEC_WARN("Received probe when state is :%s",
|
||||
coverttostring(btfmcodec_get_current_transport(state)));
|
||||
} else if (hwep_info->drv && hwep_info->drv->hwep_read) {
|
||||
return hwep_info->drv->hwep_read(codec, reg);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const struct snd_soc_component_driver btfmcodec_codec_component = {
|
||||
.probe = btfmcodec_codec_probe,
|
||||
.remove = btfmcodec_codec_remove,
|
||||
.read = btfmcodec_codec_read,
|
||||
.write = btfmcodec_codec_write,
|
||||
};
|
||||
|
||||
|
||||
static inline void * btfmcodec_get_dai_drvdata(struct hwep_data *hwep_info)
|
||||
{
|
||||
if (!hwep_info || !hwep_info->dai_drv) return NULL;
|
||||
return hwep_info->dai_drv;
|
||||
}
|
||||
|
||||
int btfmcodec_hwep_startup(struct btfmcodec_data *btfmcodec)
|
||||
{
|
||||
struct hwep_data *hwep_info = btfmcodec->hwep_info;
|
||||
struct hwep_dai_driver *dai_drv = (struct hwep_dai_driver *)
|
||||
btfmcodec_get_dai_drvdata(hwep_info);
|
||||
|
||||
if (dai_drv && dai_drv->dai_ops && dai_drv->dai_ops->hwep_startup) {
|
||||
return dai_drv->dai_ops->hwep_startup((void *)btfmcodec->hwep_info);
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
static int btfmcodec_dai_startup(struct snd_pcm_substream *substream,
|
||||
struct snd_soc_dai *dai)
|
||||
{
|
||||
struct btfmcodec_data *btfmcodec = snd_soc_component_get_drvdata(dai->component);
|
||||
struct btfmcodec_state_machine *state = &btfmcodec->states;
|
||||
|
||||
BTFMCODEC_DBG("substream = %s stream = %d dai->name = %s",
|
||||
substream->name, substream->stream, dai->name);
|
||||
|
||||
if (btfmcodec_get_current_transport(state) != IDLE &&
|
||||
btfmcodec_get_current_transport(state) != BT_Connected) {
|
||||
BTFMCODEC_DBG("Not allowing as state is:%s",
|
||||
coverttostring(btfmcodec_get_current_transport(state)));
|
||||
} else {
|
||||
return btfmcodec_hwep_startup(btfmcodec);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int btfmcodec_hwep_shutdown(struct btfmcodec_data *btfmcodec, int id,
|
||||
bool disable_master)
|
||||
{
|
||||
struct hwep_data *hwep_info = btfmcodec->hwep_info;
|
||||
struct btfmcodec_char_device *btfmcodec_dev = btfmcodec->btfmcodec_dev;
|
||||
struct hwep_dai_driver *dai_drv = (struct hwep_dai_driver *)
|
||||
btfmcodec_get_dai_drvdata(hwep_info);
|
||||
struct btfmcodec_state_machine *state = &btfmcodec->states;
|
||||
struct btm_master_shutdown_req shutdown_req;
|
||||
wait_queue_head_t *rsp_wait_q =
|
||||
&btfmcodec_dev->rsp_wait_q[BTM_PKT_TYPE_MASTER_SHUTDOWN_RSP];
|
||||
uint8_t *status = &btfmcodec_dev->status[BTM_PKT_TYPE_MASTER_SHUTDOWN_RSP];
|
||||
int ret = 0;
|
||||
|
||||
/* for master configurations failure cases, we don't need to send
|
||||
* shutdown request
|
||||
*/
|
||||
if (btfmcodec_get_current_transport(state) == BT_Connected && disable_master) {
|
||||
BTFMCODEC_DBG("sending master shutdown request..");
|
||||
shutdown_req.opcode = BTM_BTFMCODEC_MASTER_SHUTDOWN_REQ;
|
||||
shutdown_req.len = BTM_MASTER_SHUTDOWN_REQ_LEN;
|
||||
shutdown_req.stream_id = id;
|
||||
/* See if we need to protect below with lock */
|
||||
*status = BTM_WAITING_RSP;
|
||||
btfmcodec_dev_enqueue_pkt(btfmcodec_dev, &shutdown_req, (shutdown_req.len +
|
||||
BTM_HEADER_LEN));
|
||||
|
||||
ret = wait_event_interruptible_timeout(*rsp_wait_q,
|
||||
(*status) != BTM_WAITING_RSP,
|
||||
msecs_to_jiffies(BTM_MASTER_CONFIG_RSP_TIMEOUT));
|
||||
if (ret == 0) {
|
||||
BTFMCODEC_ERR("failed to recevie response from BTADV audio Manager");
|
||||
} else {
|
||||
if (*status == BTM_RSP_RECV)
|
||||
ret = 0;
|
||||
else if (*status == BTM_FAIL_RESP_RECV ||
|
||||
*status == BTM_RSP_NOT_RECV_CLIENT_KILLED)
|
||||
ret = -1;
|
||||
}
|
||||
} else {
|
||||
if (!disable_master)
|
||||
BTFMCODEC_WARN("Not sending master shutdown request as graph might have closed");
|
||||
else
|
||||
BTFMCODEC_WARN("Not sending master shutdown request as state is:%s",
|
||||
coverttostring(btfmcodec_get_current_transport(state)));
|
||||
}
|
||||
|
||||
if (dai_drv && dai_drv->dai_ops && dai_drv->dai_ops->hwep_shutdown) {
|
||||
dai_drv->dai_ops->hwep_shutdown((void *)btfmcodec->hwep_info, id);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
void btfmcodec_wq_hwep_shutdown(struct work_struct *work)
|
||||
{
|
||||
struct btfmcodec_char_device *btfmcodec_dev = container_of(work,
|
||||
struct btfmcodec_char_device,
|
||||
wq_hwep_shutdown);
|
||||
struct btfmcodec_data *btfmcodec = (struct btfmcodec_data *)btfmcodec_dev->btfmcodec;
|
||||
struct list_head *head = &btfmcodec->config_head;
|
||||
struct hwep_configurations *hwep_configs = NULL, *tmp;
|
||||
int ret = -1;
|
||||
int idx = BTM_PKT_TYPE_HWEP_SHUTDOWN;
|
||||
|
||||
BTFMCODEC_INFO(" starting shutdown");
|
||||
/* Just check if first Rx has to be closed first or
|
||||
* any order should be ok.
|
||||
*/
|
||||
list_for_each_entry_safe(hwep_configs, tmp, head, dai_list) {
|
||||
BTFMCODEC_INFO("shuting down dai id:%d", hwep_configs->stream_id);
|
||||
ret = btfmcodec_hwep_shutdown(btfmcodec, hwep_configs->stream_id, true);
|
||||
hwep_configs->is_port_opened = 0;
|
||||
if (ret < 0) {
|
||||
BTFMCODEC_ERR("failed to shutdown master with id %d", hwep_configs->stream_id);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (ret < 0)
|
||||
btfmcodec_dev->status[idx] = BTM_FAIL_RESP_RECV;
|
||||
else
|
||||
btfmcodec_dev->status[idx] = BTM_RSP_RECV;
|
||||
|
||||
wake_up_interruptible(&btfmcodec_dev->rsp_wait_q[idx]);
|
||||
}
|
||||
|
||||
static int btfmcodec_delete_configs(struct btfmcodec_data *btfmcodec, uint8_t id)
|
||||
{
|
||||
struct list_head *head = &btfmcodec->config_head;
|
||||
struct hwep_configurations *hwep_configs, *tmp;
|
||||
int ret = -1;
|
||||
|
||||
list_for_each_entry_safe(hwep_configs, tmp, head, dai_list) {
|
||||
if (hwep_configs->stream_id == id) {
|
||||
BTFMCODEC_INFO("deleting configs with id %d", id);
|
||||
list_del(&hwep_configs->dai_list);
|
||||
ret = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void btfmcodec_dai_shutdown(struct snd_pcm_substream *substream,
|
||||
struct snd_soc_dai *dai)
|
||||
{
|
||||
struct btfmcodec_data *btfmcodec = snd_soc_component_get_drvdata(dai->component);
|
||||
struct btfmcodec_state_machine *state = &btfmcodec->states;
|
||||
|
||||
BTFMCODEC_DBG("dai->name: %s, dai->id: %d, dai->rate: %d", dai->name,
|
||||
dai->id, dai->rate);
|
||||
|
||||
if (btfmcodec_get_current_transport(state) == IDLE) {
|
||||
BTFMCODEC_INFO("%s not allowing shutdown as state is IDLE", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
if ((btfmcodec_get_current_transport(state) == BTADV_AUDIO_Connecting &&
|
||||
btfmcodec_get_prev_transport(state) == BT_Connected) ||
|
||||
((btfmcodec_get_current_transport(state) == BT_Connecting &&
|
||||
btfmcodec_get_prev_transport(state) == BTADV_AUDIO_Connected))) {
|
||||
BTFMCODEC_INFO("%s: Informing port closure to upper layers", __func__);
|
||||
btfmcodec_port_state_notify(IDLE);
|
||||
}
|
||||
|
||||
if (btfmcodec_get_current_transport(state) == BTADV_AUDIO_Connecting &&
|
||||
btfmcodec_get_prev_transport(state) == BT_Connected) {
|
||||
BTFMCODEC_INFO("%s: closing these ports as graph stopped when CIS is active",
|
||||
__func__);
|
||||
btfmcodec_hwep_shutdown(btfmcodec, dai->id, false);
|
||||
btfmcodec_delete_configs(btfmcodec, dai->id);
|
||||
if (!btfmcodec_is_valid_cache_avb(btfmcodec))
|
||||
btfmcodec_set_current_state(state, IDLE);
|
||||
return;
|
||||
}
|
||||
|
||||
if ((btfmcodec_get_current_transport(state) != IDLE &&
|
||||
btfmcodec_get_current_transport(state) != BT_Connected) ||
|
||||
(btfmcodec_get_current_transport(state) == BTADV_AUDIO_Connecting &&
|
||||
btfmcodec_get_prev_transport(state) != BT_Connected)) {
|
||||
BTFMCODEC_WARN("Allowing cache retention in current state:%s, prev state: %s",
|
||||
coverttostring(btfmcodec_get_current_transport(state)),
|
||||
coverttostring(btfmcodec_get_prev_transport(state)));
|
||||
return;
|
||||
} else {
|
||||
/* first master shutdown has to done */
|
||||
btfmcodec_hwep_shutdown(btfmcodec, dai->id, false);
|
||||
btfmcodec_delete_configs(btfmcodec, dai->id);
|
||||
if (!btfmcodec_is_valid_cache_avb(btfmcodec))
|
||||
btfmcodec_set_current_state(state, IDLE);
|
||||
else {
|
||||
BTFMCODEC_WARN("valid stream id is available not updating state\n");
|
||||
btfmcodec_set_current_state(state, BT_Connected);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int btfmcodec_hwep_hw_params (struct btfmcodec_data *btfmcodec, uint32_t bps,
|
||||
uint32_t direction, uint8_t num_channels)
|
||||
{
|
||||
struct hwep_data *hwep_info = btfmcodec->hwep_info;
|
||||
struct hwep_dai_driver *dai_drv = (struct hwep_dai_driver *)
|
||||
btfmcodec_get_dai_drvdata(hwep_info);
|
||||
|
||||
if (dai_drv && dai_drv->dai_ops && dai_drv->dai_ops->hwep_hw_params) {
|
||||
return dai_drv->dai_ops->hwep_hw_params((void *)btfmcodec->hwep_info,
|
||||
bps, direction,
|
||||
num_channels);
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
static int btfmcodec_dai_hw_params(struct snd_pcm_substream *substream,
|
||||
struct snd_pcm_hw_params *params,
|
||||
struct snd_soc_dai *dai)
|
||||
{
|
||||
struct btfmcodec_data *btfmcodec = snd_soc_component_get_drvdata(dai->component);
|
||||
struct btfmcodec_state_machine *state = &btfmcodec->states;
|
||||
uint32_t direction = substream->stream;
|
||||
|
||||
BTFMCODEC_DBG("dai->name = %s DAI-ID %x rate %d bps %d num_ch %d",
|
||||
dai->name, dai->id, params_rate(params), params_width(params),
|
||||
params_channels(params));
|
||||
|
||||
bits_per_second = params_width(params);
|
||||
num_channels = params_channels(params);
|
||||
if (btfmcodec_get_current_transport(state) != IDLE &&
|
||||
btfmcodec_get_current_transport(state) != BT_Connected) {
|
||||
BTFMCODEC_WARN("caching bps and num_channels as state is :%s",
|
||||
coverttostring(btfmcodec_get_current_transport(state)));
|
||||
} else {
|
||||
return btfmcodec_hwep_hw_params(btfmcodec, bits_per_second,
|
||||
direction, num_channels);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool btfmcodec_is_valid_cache_avb(struct btfmcodec_data *btfmcodec)
|
||||
{
|
||||
struct list_head *head = &btfmcodec->config_head;
|
||||
struct hwep_configurations *hwep_configs, *tmp;
|
||||
bool cache_avb = false;
|
||||
|
||||
list_for_each_entry_safe(hwep_configs, tmp, head, dai_list) {
|
||||
cache_avb = true;
|
||||
break;
|
||||
}
|
||||
|
||||
return cache_avb;
|
||||
}
|
||||
|
||||
static int btfmcodec_check_and_cache_configs(struct btfmcodec_data *btfmcodec,
|
||||
uint32_t sampling_rate, uint32_t direction,
|
||||
int id, uint8_t codectype)
|
||||
{
|
||||
struct list_head *head = &btfmcodec->config_head;
|
||||
struct hwep_configurations *hwep_configs, *tmp;
|
||||
|
||||
list_for_each_entry_safe(hwep_configs, tmp, head, dai_list) {
|
||||
if (hwep_configs->stream_id == id) {
|
||||
BTFMCODEC_WARN("previous entry for %d is already available",
|
||||
id);
|
||||
list_del(&hwep_configs->dai_list);
|
||||
}
|
||||
}
|
||||
|
||||
hwep_configs = kzalloc(sizeof(struct hwep_configurations),
|
||||
GFP_KERNEL);
|
||||
if (!hwep_configs) {
|
||||
BTFMCODEC_ERR("failed to allocate memory");
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
hwep_configs->stream_id = id; /* Stream identifier */
|
||||
hwep_configs->sample_rate = sampling_rate;
|
||||
hwep_configs->bit_width = bits_per_second;
|
||||
hwep_configs->codectype = codectype;
|
||||
hwep_configs->direction = direction;
|
||||
hwep_configs->num_channels = num_channels;
|
||||
|
||||
list_add(&hwep_configs->dai_list, head);
|
||||
BTFMCODEC_INFO("added dai id:%d to list with sampling_rate :%u, direction:%u", id, sampling_rate, direction);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int btfmcodec_configure_master(struct btfmcodec_data *btfmcodec, uint8_t id)
|
||||
{
|
||||
struct btfmcodec_char_device *btfmcodec_dev = btfmcodec->btfmcodec_dev;
|
||||
struct hwep_data *hwep_info = btfmcodec->hwep_info;
|
||||
struct master_hwep_configurations hwep_configs;
|
||||
struct btm_master_config_req config_req;
|
||||
struct hwep_dai_driver *dai_drv = (struct hwep_dai_driver *)
|
||||
btfmcodec_get_dai_drvdata(hwep_info);
|
||||
wait_queue_head_t *rsp_wait_q =
|
||||
&btfmcodec_dev->rsp_wait_q[BTM_PKT_TYPE_MASTER_CONFIG_RSP];
|
||||
uint8_t *status = &btfmcodec_dev->status[BTM_PKT_TYPE_MASTER_CONFIG_RSP];
|
||||
int ret = 0;
|
||||
|
||||
if (dai_drv && dai_drv->dai_ops && dai_drv->dai_ops->hwep_get_configs) {
|
||||
dai_drv->dai_ops->hwep_get_configs((void *)btfmcodec->hwep_info,
|
||||
&hwep_configs, id);
|
||||
} else {
|
||||
BTFMCODEC_ERR("No hwep_get_configs is set by hw ep driver");
|
||||
return -1;
|
||||
}
|
||||
|
||||
BTFMCODEC_INFO("framing packet for %d", id);
|
||||
config_req.opcode = BTM_BTFMCODEC_MASTER_CONFIG_REQ;
|
||||
config_req.len = BTM_MASTER_CONFIG_REQ_LEN;
|
||||
config_req.stream_id = hwep_configs.stream_id;
|
||||
config_req.device_id = hwep_configs.device_id;
|
||||
config_req.sample_rate = hwep_configs.sample_rate;
|
||||
config_req.bit_width = hwep_configs.bit_width;
|
||||
config_req.num_channels = hwep_configs.num_channels;
|
||||
config_req.channel_num = hwep_configs.chan_num;
|
||||
config_req.codec_id = hwep_configs.codectype;
|
||||
BTFMCODEC_DBG("================================================\n");
|
||||
BTFMCODEC_DBG("dma_config_req.len :%d", config_req.len);
|
||||
BTFMCODEC_DBG("dma_config_req.stream_id :%d", config_req.stream_id);
|
||||
BTFMCODEC_DBG("dma_config_req.device_id :%d", config_req.device_id);
|
||||
BTFMCODEC_DBG("dma_config_req.sample_rate :%d", config_req.sample_rate);
|
||||
BTFMCODEC_DBG("dma_config_req.bit_width :%d", config_req.bit_width);
|
||||
BTFMCODEC_DBG("dma_config_req.num_channels :%d", config_req.num_channels);
|
||||
BTFMCODEC_DBG("dma_config_req.channel_num :%d", config_req.channel_num);
|
||||
BTFMCODEC_DBG("dma_config_req.codec_id :%d", config_req.codec_id);
|
||||
BTFMCODEC_DBG("================================================\n");
|
||||
/* See if we need to protect below with lock */
|
||||
*status = BTM_WAITING_RSP;
|
||||
btfmcodec_dev_enqueue_pkt(btfmcodec_dev, &config_req, (config_req.len +
|
||||
BTM_HEADER_LEN));
|
||||
ret = wait_event_interruptible_timeout(*rsp_wait_q,
|
||||
(*status) != BTM_WAITING_RSP,
|
||||
msecs_to_jiffies(BTM_MASTER_CONFIG_RSP_TIMEOUT));
|
||||
if (ret == 0) {
|
||||
BTFMCODEC_ERR("failed to recevie response from BTADV audio Manager");
|
||||
ret = -ETIMEDOUT;
|
||||
} else {
|
||||
if (*status == BTM_RSP_RECV)
|
||||
return 0;
|
||||
else if (*status == BTM_FAIL_RESP_RECV ||
|
||||
*status == BTM_RSP_NOT_RECV_CLIENT_KILLED)
|
||||
return -1;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int btfmcodec_configure_dma(struct btfmcodec_data *btfmcodec, uint8_t id)
|
||||
{
|
||||
struct btfmcodec_char_device *btfmcodec_dev = btfmcodec->btfmcodec_dev;
|
||||
struct hwep_data *hwep_info = btfmcodec->hwep_info;
|
||||
struct hwep_dma_configurations dma_config;
|
||||
struct btm_dma_config_req dma_config_req;
|
||||
struct hwep_dai_driver *dai_drv = (struct hwep_dai_driver *)
|
||||
btfmcodec_get_dai_drvdata(hwep_info);
|
||||
wait_queue_head_t *rsp_wait_q =
|
||||
&btfmcodec_dev->rsp_wait_q[BTM_PKT_TYPE_DMA_CONFIG_RSP];
|
||||
uint8_t *status = &btfmcodec_dev->status[BTM_PKT_TYPE_DMA_CONFIG_RSP];
|
||||
int ret = 0;
|
||||
|
||||
if (dai_drv && dai_drv->dai_ops && dai_drv->dai_ops->hwep_get_configs) {
|
||||
dai_drv->dai_ops->hwep_get_configs((void *)btfmcodec->hwep_info,
|
||||
&dma_config, id);
|
||||
} else {
|
||||
BTFMCODEC_ERR("No hwep_get_configs is set by hw ep driver");
|
||||
return -1;
|
||||
}
|
||||
|
||||
BTFMCODEC_INFO("framing packet for %d", id);
|
||||
dma_config_req.opcode = BTM_BTFMCODEC_CODEC_CONFIG_DMA_REQ;
|
||||
dma_config_req.len = BTM_CODEC_CONFIG_DMA_REQ_LEN;
|
||||
dma_config_req.stream_id = dma_config.stream_id;
|
||||
dma_config_req.sample_rate = dma_config.sample_rate;
|
||||
dma_config_req.bit_width = dma_config.bit_width;
|
||||
dma_config_req.num_channels = dma_config.num_channels;
|
||||
dma_config_req.codec_id = dma_config.codectype;
|
||||
dma_config_req.lpaif = dma_config.lpaif;
|
||||
dma_config_req.inf_index = dma_config.inf_index;
|
||||
dma_config_req.active_channel_mask = dma_config.active_channel_mask;
|
||||
|
||||
BTFMCODEC_DBG("================================================\n");
|
||||
BTFMCODEC_DBG("dma_config_req.len :%d", dma_config_req.len);
|
||||
BTFMCODEC_DBG("dma_config_req.stream_id :%d", dma_config_req.stream_id);
|
||||
BTFMCODEC_DBG("dma_config_req.sample_rate :%d", dma_config_req.sample_rate);
|
||||
BTFMCODEC_DBG("dma_config_req.bit_width :%d", dma_config_req.bit_width);
|
||||
BTFMCODEC_DBG("dma_config_req.num_channels :%d", dma_config_req.num_channels);
|
||||
BTFMCODEC_DBG("dma_config_req.codec_id :%d", dma_config_req.codec_id);
|
||||
BTFMCODEC_DBG("dma_config_req.lpaif :%d", dma_config_req.lpaif);
|
||||
BTFMCODEC_DBG("dma_config_req.inf_index :%d", dma_config_req.inf_index);
|
||||
BTFMCODEC_DBG("dma_config_req.active_channel_mask :%d", dma_config_req.active_channel_mask);
|
||||
BTFMCODEC_DBG("================================================\n");
|
||||
|
||||
*status = BTM_WAITING_RSP;
|
||||
btfmcodec_dev_enqueue_pkt(btfmcodec_dev, &dma_config_req, (dma_config_req.len +
|
||||
BTM_HEADER_LEN));
|
||||
|
||||
ret = wait_event_interruptible_timeout(*rsp_wait_q,
|
||||
(*status) != BTM_WAITING_RSP,
|
||||
msecs_to_jiffies(BTM_MASTER_DMA_CONFIG_RSP_TIMEOUT));
|
||||
|
||||
if (ret == 0) {
|
||||
BTFMCODEC_ERR("failed to recevie response from BTADV audio Manager");
|
||||
ret = -ETIMEDOUT;
|
||||
} else {
|
||||
if (*status == BTM_RSP_RECV)
|
||||
return 0;
|
||||
else if (*status == BTM_FAIL_RESP_RECV ||
|
||||
*status == BTM_RSP_NOT_RECV_CLIENT_KILLED)
|
||||
return -1;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int btfmcodec_hwep_prepare(struct btfmcodec_data *btfmcodec, uint32_t sampling_rate,
|
||||
uint32_t direction, int id, bool seamless)
|
||||
{
|
||||
struct hwep_data *hwep_info = btfmcodec->hwep_info;
|
||||
struct hwep_dai_driver *dai_drv = (struct hwep_dai_driver *)
|
||||
btfmcodec_get_dai_drvdata(hwep_info);
|
||||
struct btfmcodec_state_machine *state = &btfmcodec->states;
|
||||
|
||||
int ret;
|
||||
if (dai_drv && dai_drv->dai_ops && dai_drv->dai_ops->hwep_prepare) {
|
||||
ret = dai_drv->dai_ops->hwep_prepare((void *)hwep_info, sampling_rate,
|
||||
direction, id);
|
||||
BTFMCODEC_ERR("%s: hwep info %ld", __func__, hwep_info->flags);
|
||||
if (ret == 0 && test_bit(BTADV_AUDIO_MASTER_CONFIG, &hwep_info->flags)) {
|
||||
ret = btfmcodec_configure_master(btfmcodec, (uint8_t)id);
|
||||
if (ret < 0) {
|
||||
BTFMCODEC_ERR("failed to configure master error %d", ret);
|
||||
if (seamless == false)
|
||||
btfmcodec_set_current_state(state, IDLE);
|
||||
} else {
|
||||
if (seamless == false)
|
||||
btfmcodec_set_current_state(state, BT_Connected);
|
||||
}
|
||||
} else if (ret == 0 && test_bit(BTADV_CONFIGURE_DMA, &hwep_info->flags)) {
|
||||
/* Don't send request to cp for fm as it is non cp */
|
||||
if (id == 0)
|
||||
return ret;
|
||||
ret = btfmcodec_configure_dma(btfmcodec, (uint8_t)id);
|
||||
if (ret < 0) {
|
||||
BTFMCODEC_ERR("failed to configure Codec DMA %d", ret);
|
||||
if (seamless == false)
|
||||
btfmcodec_set_current_state(state, IDLE);
|
||||
else {
|
||||
if (dai_drv && dai_drv->dai_ops &&
|
||||
dai_drv->dai_ops->hwep_shutdown) {
|
||||
dai_drv->dai_ops->hwep_shutdown((void *)hwep_info,
|
||||
id);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (seamless == false)
|
||||
btfmcodec_set_current_state(state, BT_Connected);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int btfmcodec_notify_usecase_start(struct btfmcodec_data *btfmcodec,
|
||||
uint8_t transport, uint8_t stream_id)
|
||||
{
|
||||
struct btfmcodec_char_device *btfmcodec_dev = btfmcodec->btfmcodec_dev;
|
||||
struct btm_usecase_start_ind ind;
|
||||
wait_queue_head_t *rsp_wait_q =
|
||||
&btfmcodec_dev->rsp_wait_q[BTM_PKT_TYPE_USECASE_START_RSP];
|
||||
uint8_t *status = &btfmcodec_dev->status[BTM_PKT_TYPE_USECASE_START_RSP];
|
||||
int ret;
|
||||
|
||||
*status = BTM_WAITING_RSP;
|
||||
ind.opcode = BTM_BTFMCODEC_USECASE_START_REQ;
|
||||
ind.len = BTM_USECASE_START_IND_LEN;
|
||||
ind.transport = transport;
|
||||
ind.stream_id = stream_id;
|
||||
ret = btfmcodec_dev_enqueue_pkt(btfmcodec_dev, &ind, (ind.len + BTM_HEADER_LEN));
|
||||
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
|
||||
BTFMCODEC_INFO("waiting for BTM_BTFMCODEC_USECASE_START_RSP");
|
||||
ret = wait_event_interruptible_timeout(*rsp_wait_q,
|
||||
*status != BTM_WAITING_RSP,
|
||||
msecs_to_jiffies(BTM_MASTER_CONFIG_RSP_TIMEOUT));
|
||||
|
||||
if (ret == 0) {
|
||||
BTFMCODEC_ERR("failed to recevie BTM_USECASE_START_IND_RSP");
|
||||
ret = -MSG_INTERNAL_TIMEOUT;
|
||||
} else {
|
||||
if (*status == BTM_RSP_RECV) {
|
||||
ret = 0;
|
||||
} else if (*status == BTM_FAIL_RESP_RECV) {
|
||||
BTFMCODEC_ERR("Rx BTM_USECASE_START_IND_RSP with failure status");
|
||||
ret = -1;
|
||||
} else if (*status == BTM_RSP_NOT_RECV_CLIENT_KILLED) {
|
||||
BTFMCODEC_ERR("client killed so moving further");
|
||||
ret = -1;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int btfmcodec_dai_prepare(struct snd_pcm_substream *substream,
|
||||
struct snd_soc_dai *dai)
|
||||
{
|
||||
struct btfmcodec_data *btfmcodec = snd_soc_component_get_drvdata(dai->component);
|
||||
struct btfmcodec_state_machine *state = &btfmcodec->states;
|
||||
struct hwep_data *hwep_info = btfmcodec->hwep_info;
|
||||
struct hwep_dai_driver *dai_drv = (struct hwep_dai_driver *)
|
||||
btfmcodec_get_dai_drvdata(hwep_info);
|
||||
uint8_t *codectype = dai_drv->dai_ops->hwep_codectype;
|
||||
uint32_t sampling_rate = dai->rate;
|
||||
uint32_t direction = substream->stream;
|
||||
int id = dai->id;
|
||||
int ret ;
|
||||
|
||||
BTFMCODEC_INFO("dai->name: %s, dai->id: %d, dai->rate: %d direction: %d",
|
||||
dai->name, id, sampling_rate, direction);
|
||||
|
||||
ret = btfmcodec_check_and_cache_configs(btfmcodec, sampling_rate,
|
||||
direction, id, *codectype);
|
||||
if (btfmcodec_get_current_transport(state) != IDLE &&
|
||||
btfmcodec_get_current_transport(state) != BT_Connected) {
|
||||
BTFMCODEC_WARN("cached required info as state is:%s",
|
||||
coverttostring(btfmcodec_get_current_transport(state)));
|
||||
ret = btfmcodec_notify_usecase_start(btfmcodec, BTADV, (uint8_t)id);
|
||||
} else {
|
||||
ret = btfmcodec_hwep_prepare(btfmcodec, sampling_rate, direction, id, false);
|
||||
/* if (ret >= 0) {
|
||||
btfmcodec_check_and_cache_configs(btfmcodec, sampling_rate, direction,
|
||||
id, *codectype);
|
||||
}
|
||||
*/ }
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int btfmcodec_hwep_set_channel_map(void *hwep_info, unsigned int tx_num,
|
||||
unsigned int *tx_slot, unsigned int rx_num,
|
||||
unsigned int *rx_slot)
|
||||
{
|
||||
struct hwep_dai_driver *dai_drv = (struct hwep_dai_driver *)
|
||||
btfmcodec_get_dai_drvdata(hwep_info);
|
||||
|
||||
if (dai_drv && dai_drv->dai_ops && dai_drv->dai_ops->hwep_set_channel_map) {
|
||||
return dai_drv->dai_ops->hwep_set_channel_map(hwep_info, tx_num,
|
||||
tx_slot, rx_num,
|
||||
rx_slot);
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static int btfmcodec_dai_set_channel_map(struct snd_soc_dai *dai,
|
||||
unsigned int tx_num, unsigned int *tx_slot,
|
||||
unsigned int rx_num, unsigned int *rx_slot)
|
||||
{
|
||||
struct btfmcodec_data *btfmcodec = snd_soc_component_get_drvdata(dai->component);
|
||||
struct btfmcodec_state_machine states = btfmcodec->states;
|
||||
|
||||
BTFMCODEC_DBG("");
|
||||
// ToDo: check whether hw_params has to allowed when state if different
|
||||
if (states.current_state != IDLE) {
|
||||
BTFMCODEC_WARN("Received probe when state is :%s", coverttostring(states.current_state));
|
||||
} else {
|
||||
return btfmcodec_hwep_set_channel_map((void *)btfmcodec->hwep_info, tx_num,
|
||||
tx_slot, rx_num, rx_slot);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int btfmcodec_hwep_get_channel_map(void *hwep_info, unsigned int *tx_num,
|
||||
unsigned int *tx_slot, unsigned int *rx_num,
|
||||
unsigned int *rx_slot, int id)
|
||||
{
|
||||
struct hwep_dai_driver *dai_drv = (struct hwep_dai_driver *)
|
||||
btfmcodec_get_dai_drvdata(hwep_info);
|
||||
|
||||
if (dai_drv && dai_drv->dai_ops && dai_drv->dai_ops->hwep_get_channel_map) {
|
||||
return dai_drv->dai_ops->hwep_get_channel_map(hwep_info, tx_num,
|
||||
tx_slot, rx_num,
|
||||
rx_slot, id);
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
static int btfmcodec_dai_get_channel_map(struct snd_soc_dai *dai,
|
||||
unsigned int *tx_num, unsigned int *tx_slot,
|
||||
unsigned int *rx_num, unsigned int *rx_slot)
|
||||
{
|
||||
struct btfmcodec_data *btfmcodec = snd_soc_component_get_drvdata(dai->component);
|
||||
// struct btfmcodec_state_machine states = btfmcodec->states;
|
||||
|
||||
BTFMCODEC_DBG("");
|
||||
// ToDo: get_channel_map is not needed for new driver
|
||||
/* if (states.current_state != IDLE) {
|
||||
BTFMCODEC_WARN("Received probe when state is :%s", coverttostring(states.current_state));
|
||||
} else {
|
||||
*/ return btfmcodec_hwep_get_channel_map((void *)btfmcodec->hwep_info,
|
||||
tx_num, tx_slot, rx_num,
|
||||
rx_slot, dai->id);
|
||||
// }
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void btfmcodec_wq_hwep_configure(struct work_struct *work)
|
||||
{
|
||||
struct btfmcodec_char_device *btfmcodec_dev = container_of(work,
|
||||
struct btfmcodec_char_device,
|
||||
wq_hwep_configure);
|
||||
struct btfmcodec_data *btfmcodec = (struct btfmcodec_data *)btfmcodec_dev->btfmcodec;
|
||||
struct list_head *head = &btfmcodec->config_head;
|
||||
struct hwep_configurations *hwep_configs = NULL, *tmp;
|
||||
int ret;
|
||||
int idx = BTM_PKT_TYPE_HWEP_CONFIG;
|
||||
uint32_t sample_rate, direction;
|
||||
uint8_t id, bit_width, codectype, num_channels;
|
||||
|
||||
list_for_each_entry_safe(hwep_configs, tmp, head, dai_list) {
|
||||
id = hwep_configs->stream_id;
|
||||
sample_rate = hwep_configs->sample_rate;
|
||||
bit_width = hwep_configs->bit_width;
|
||||
codectype = hwep_configs->codectype;
|
||||
direction = hwep_configs->direction;
|
||||
num_channels = hwep_configs->num_channels;
|
||||
|
||||
BTFMCODEC_INFO("configuring dai id:%d with sampling rate:%d bit_width:%d", id, sample_rate, bit_width);
|
||||
ret = btfmcodec_hwep_startup(btfmcodec);
|
||||
if (ret >= 0)
|
||||
ret = btfmcodec_hwep_hw_params(btfmcodec, bit_width, direction, num_channels);
|
||||
if (ret >= 0)
|
||||
ret = btfmcodec_hwep_prepare(btfmcodec, sample_rate, direction, id, true);
|
||||
if (ret < 0) {
|
||||
hwep_configs->is_port_opened = 1;
|
||||
BTFMCODEC_ERR("failed to configure hwep %d", hwep_configs->stream_id);
|
||||
break;
|
||||
} else {
|
||||
hwep_configs->is_port_opened = 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (ret < 0) {
|
||||
list_for_each_entry_safe(hwep_configs, tmp, head, dai_list) {
|
||||
if (hwep_configs->is_port_opened) {
|
||||
BTFMCODEC_INFO("shuting down dai id:%d", hwep_configs->stream_id);
|
||||
ret = btfmcodec_hwep_shutdown(btfmcodec, hwep_configs->stream_id,
|
||||
true);
|
||||
hwep_configs->is_port_opened = 0;
|
||||
if (ret < 0) {
|
||||
BTFMCODEC_ERR("failed to shutdown master with id %d",
|
||||
hwep_configs->stream_id);
|
||||
}
|
||||
}
|
||||
}
|
||||
btfmcodec_dev->status[idx] = BTM_FAIL_RESP_RECV;
|
||||
} else {
|
||||
btfmcodec_dev->status[idx] = BTM_RSP_RECV;
|
||||
}
|
||||
wake_up_interruptible(&btfmcodec_dev->rsp_wait_q[idx]);
|
||||
}
|
||||
static struct snd_soc_dai_ops btfmcodec_dai_ops = {
|
||||
.startup = btfmcodec_dai_startup,
|
||||
.shutdown = btfmcodec_dai_shutdown,
|
||||
.hw_params = btfmcodec_dai_hw_params,
|
||||
.prepare = btfmcodec_dai_prepare,
|
||||
.set_channel_map = btfmcodec_dai_set_channel_map,
|
||||
.get_channel_map = btfmcodec_dai_get_channel_map,
|
||||
};
|
||||
|
||||
static int btfmcodec_adsp_ssr_notify(struct notifier_block *nb,
|
||||
unsigned long action, void *data)
|
||||
{
|
||||
struct btfmcodec_data *btfmcodec = container_of(nb,
|
||||
struct btfmcodec_data, notifier.nb);
|
||||
struct btfmcodec_char_device *btfmcodec_dev = btfmcodec->btfmcodec_dev;
|
||||
struct btm_adsp_state_ind state_ind;
|
||||
|
||||
switch (action) {
|
||||
case QCOM_SSR_BEFORE_SHUTDOWN: {
|
||||
BTFMCODEC_WARN("LPASS SSR triggered");
|
||||
break;
|
||||
} case QCOM_SSR_AFTER_SHUTDOWN: {
|
||||
BTFMCODEC_WARN("LPASS SSR Completed");
|
||||
break;
|
||||
} case QCOM_SSR_BEFORE_POWERUP: {
|
||||
BTFMCODEC_WARN("LPASS booted up after SSR");
|
||||
break;
|
||||
} case QCOM_SSR_AFTER_POWERUP: {
|
||||
BTFMCODEC_WARN("LPASS booted up completely");
|
||||
state_ind.opcode = BTM_BTFMCODEC_ADSP_STATE_IND;
|
||||
state_ind.len = BTM_ADSP_STATE_IND_LEN;
|
||||
state_ind.action = (uint32_t)action;
|
||||
btfmcodec_dev_enqueue_pkt(btfmcodec_dev, &state_ind,
|
||||
(state_ind.len +
|
||||
BTM_HEADER_LEN));
|
||||
break;
|
||||
} default:
|
||||
BTFMCODEC_WARN("unhandled action id %lu", action);
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int btfmcodec_port_state_notify(uint8_t port_state)
|
||||
{
|
||||
struct btm_port_state_ind state_ind;
|
||||
struct btfmcodec_data *btfmcodec;
|
||||
struct btfmcodec_char_device *btfmcodec_dev;
|
||||
|
||||
BTFMCODEC_WARN("%s: port state = %d", __func__, port_state);
|
||||
btfmcodec = btfm_get_btfmcodec();
|
||||
btfmcodec_dev = btfmcodec->btfmcodec_dev;
|
||||
state_ind.opcode = BTM_BTFMCODEC_PORT_STATE_IND;
|
||||
state_ind.len = BTM_PORT_STATE_IND_LEN;
|
||||
state_ind.port_state = (uint8_t)port_state;
|
||||
btfmcodec_dev_enqueue_pkt(btfmcodec_dev, &state_ind,
|
||||
(state_ind.len + BTM_HEADER_LEN));
|
||||
return 0;
|
||||
}
|
||||
|
||||
int btfm_register_codec(struct hwep_data *hwep_info)
|
||||
{
|
||||
struct btfmcodec_data *btfmcodec;
|
||||
struct btfmcodec_char_device *btfmcodec_dev;
|
||||
struct device *dev;
|
||||
struct hwep_dai_driver *dai_drv;
|
||||
int i, ret;
|
||||
|
||||
btfmcodec = btfm_get_btfmcodec();
|
||||
btfmcodec_dev = btfmcodec->btfmcodec_dev;
|
||||
dev = &btfmcodec->dev;
|
||||
|
||||
btfmcodec->notifier.nb.notifier_call = btfmcodec_adsp_ssr_notify;
|
||||
btfmcodec->notifier.notifier = qcom_register_ssr_notifier("lpass",
|
||||
&btfmcodec->notifier.nb);
|
||||
if (IS_ERR(btfmcodec->notifier.notifier)) {
|
||||
ret = PTR_ERR(btfmcodec->notifier.notifier);
|
||||
BTFMCODEC_ERR("Failed to register SSR notification: %d\n", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
btfmcodec_dai_info = kzalloc((sizeof(struct snd_soc_dai_driver) * hwep_info->num_dai), GFP_KERNEL);
|
||||
if (!btfmcodec_dai_info) {
|
||||
BTFMCODEC_ERR("failed to allocate memory");
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
for (i = 0; i < hwep_info->num_dai; i++) {
|
||||
dai_drv = &hwep_info->dai_drv[i];
|
||||
btfmcodec_dai_info[i].name = dai_drv->dai_name;
|
||||
btfmcodec_dai_info[i].id = dai_drv->id;
|
||||
btfmcodec_dai_info[i].capture = dai_drv->capture;
|
||||
btfmcodec_dai_info[i].playback = dai_drv->playback;
|
||||
btfmcodec_dai_info[i].ops = &btfmcodec_dai_ops;
|
||||
}
|
||||
|
||||
BTFMCODEC_INFO("Adding %d dai support to codec", hwep_info->num_dai);
|
||||
BTFMCODEC_INFO("slim bus driver name:%s", dev->driver->name);
|
||||
ret = snd_soc_register_component(dev, &btfmcodec_codec_component,
|
||||
btfmcodec_dai_info, hwep_info->num_dai);
|
||||
BTFMCODEC_INFO("Dev node address: %p", dev);
|
||||
BTFMCODEC_INFO("btfmcodec address :%p", btfmcodec);
|
||||
BTFMCODEC_INFO("HWEPINFO address:%p", hwep_info);
|
||||
BTFMCODEC_INFO("btfmcodec_dev INFO address:%p", btfmcodec->btfmcodec_dev);
|
||||
INIT_WORK(&btfmcodec_dev->wq_hwep_shutdown, btfmcodec_wq_hwep_shutdown);
|
||||
INIT_WORK(&btfmcodec_dev->wq_prepare_bearer, btfmcodec_wq_prepare_bearer);
|
||||
INIT_WORK(&btfmcodec_dev->wq_hwep_configure, btfmcodec_wq_hwep_configure);
|
||||
|
||||
if (isCpSupported()) {
|
||||
if (!strcmp(hwep_info->driver_name, "btfmslim"))
|
||||
set_bit(BTADV_AUDIO_MASTER_CONFIG, &hwep_info->flags);
|
||||
else if (!strcmp(hwep_info->driver_name, "btfmswr_slave"))
|
||||
set_bit(BTADV_CONFIGURE_DMA, &hwep_info->flags);
|
||||
|
||||
BTFMCODEC_INFO("%s: master %d dma codec %d", __func__,
|
||||
(int)test_bit(BTADV_AUDIO_MASTER_CONFIG, &hwep_info->flags),
|
||||
(int)test_bit(BTADV_CONFIGURE_DMA, &hwep_info->flags));
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
void btfm_unregister_codec(void)
|
||||
{
|
||||
struct btfmcodec_data *btfmcodec;
|
||||
|
||||
btfmcodec = btfm_get_btfmcodec();
|
||||
snd_soc_unregister_component(&btfmcodec->dev);
|
||||
}
|
||||
111
qcom/opensource/bt-kernel/btfmcodec/include/btfm_codec.h
Normal file
111
qcom/opensource/bt-kernel/btfmcodec/include/btfm_codec.h
Normal file
@@ -0,0 +1,111 @@
|
||||
// SPDX-License-Identifier: GPL-2.0-only
|
||||
/*
|
||||
* Copyright (c) 2023-2024 Qualcomm Innovation Center, Inc. All rights reserved.
|
||||
*/
|
||||
|
||||
#ifndef __LINUX_BTFM_CODEC_H
|
||||
#define __LINUX_BTFM_CODEC_H
|
||||
|
||||
#include <linux/kernel.h>
|
||||
#include <linux/bitops.h>
|
||||
#include <linux/printk.h>
|
||||
#include <linux/cdev.h>
|
||||
#include <linux/skbuff.h>
|
||||
#include "btfm_codec_hw_interface.h"
|
||||
|
||||
#define BTM_BTFMCODEC_DEFAULT_LOG_LVL 0x03
|
||||
#define BTM_BTFMCODEC_DEBUG_LOG_LVL 0x04
|
||||
#define BTM_BTFMCODEC_INFO_LOG_LVL 0x08
|
||||
|
||||
static uint8_t log_lvl = BTM_BTFMCODEC_DEFAULT_LOG_LVL;
|
||||
|
||||
#define BTFMCODEC_ERR(fmt, arg...) pr_err("%s: " fmt "\n", __func__, ## arg)
|
||||
#define BTFMCODEC_WARN(fmt, arg...) pr_warn("%s: " fmt "\n", __func__, ## arg)
|
||||
#define BTFMCODEC_DBG(fmt, arg...) { if(log_lvl >= BTM_BTFMCODEC_DEBUG_LOG_LVL) \
|
||||
pr_err("%s: " fmt "\n", __func__, ## arg); \
|
||||
else \
|
||||
pr_debug("%s: " fmt "\n", __func__, ## arg); \
|
||||
}
|
||||
#define BTFMCODEC_INFO(fmt, arg...) { if(log_lvl >= BTM_BTFMCODEC_INFO_LOG_LVL) \
|
||||
pr_err("%s: " fmt "\n", __func__, ## arg);\
|
||||
else \
|
||||
pr_info("%s: " fmt "\n", __func__, ## arg);\
|
||||
}
|
||||
|
||||
#define DEVICE_NAME_MAX_LEN 64
|
||||
#define BTM_CP_UPDATE 0xbfaf
|
||||
|
||||
typedef enum btfmcodec_states {
|
||||
/*Default state of kernel proxy driver */
|
||||
IDLE = 0,
|
||||
/* Waiting for BT bearer indication after configuring HW ports */
|
||||
BT_Connecting = 1,
|
||||
/* When BT is active transport */
|
||||
BT_Connected = 2,
|
||||
/* Waiting for BTADV Audio bearer switch indications */
|
||||
BTADV_AUDIO_Connecting = 3,
|
||||
/* When BTADV audio is active transport */
|
||||
BTADV_AUDIO_Connected = 4
|
||||
} btfmcodec_state;
|
||||
|
||||
enum btfm_pkt_type {
|
||||
BTM_PKT_TYPE_PREPARE_REQ = 0,
|
||||
BTM_PKT_TYPE_MASTER_CONFIG_RSP,
|
||||
BTM_PKT_TYPE_MASTER_SHUTDOWN_RSP,
|
||||
BTM_PKT_TYPE_BEARER_SWITCH_IND,
|
||||
BTM_PKT_TYPE_HWEP_SHUTDOWN,
|
||||
BTM_PKT_TYPE_HWEP_CONFIG,
|
||||
BTM_PKT_TYPE_DMA_CONFIG_RSP,
|
||||
BTM_PKT_TYPE_USECASE_START_RSP,
|
||||
BTM_PKT_TYPE_MAX,
|
||||
};
|
||||
|
||||
|
||||
char *coverttostring(enum btfmcodec_states);
|
||||
struct btfmcodec_state_machine {
|
||||
struct mutex state_machine_lock;
|
||||
btfmcodec_state prev_state;
|
||||
btfmcodec_state current_state;
|
||||
btfmcodec_state next_state;
|
||||
};
|
||||
|
||||
struct btfmcodec_char_device {
|
||||
struct cdev cdev;
|
||||
refcount_t active_clients;
|
||||
struct mutex lock;
|
||||
struct mutex trans_lock;
|
||||
int reuse_minor;
|
||||
char dev_name[DEVICE_NAME_MAX_LEN];
|
||||
struct workqueue_struct *workqueue;
|
||||
struct sk_buff_head rxq;
|
||||
struct sk_buff_head trans_rxq;
|
||||
struct work_struct rx_work;
|
||||
struct work_struct wq_hwep_shutdown;
|
||||
struct work_struct wq_prepare_bearer;
|
||||
struct work_struct wq_hwep_configure;
|
||||
wait_queue_head_t readq;
|
||||
spinlock_t tx_queue_lock;
|
||||
struct sk_buff_head txq;
|
||||
wait_queue_head_t rsp_wait_q[BTM_PKT_TYPE_MAX];
|
||||
uint8_t status[BTM_PKT_TYPE_MAX];
|
||||
void *btfmcodec;
|
||||
};
|
||||
|
||||
struct adsp_notifier {
|
||||
void *notifier;
|
||||
struct notifier_block nb;
|
||||
};
|
||||
|
||||
struct btfmcodec_data {
|
||||
struct device dev;
|
||||
struct btfmcodec_state_machine states;
|
||||
struct btfmcodec_char_device *btfmcodec_dev;
|
||||
struct hwep_data *hwep_info;
|
||||
struct list_head config_head;
|
||||
struct adsp_notifier notifier;
|
||||
struct mutex hwep_drv_lock;
|
||||
};
|
||||
|
||||
struct btfmcodec_data *btfm_get_btfmcodec(void);
|
||||
bool isCpSupported(void);
|
||||
#endif /*__LINUX_BTFM_CODEC_H */
|
||||
@@ -0,0 +1,23 @@
|
||||
// SPDX-License-Identifier: GPL-2.0-only
|
||||
/*
|
||||
* Copyright (c) 2022, 2024 Qualcomm Innovation Center, Inc. All rights reserved.
|
||||
*/
|
||||
|
||||
#ifndef __LINUX_BTFM_CODEC_BTADV_INTERFACE_H
|
||||
#define __LINUX_BTFM_CODEC_BTADV_INTERFACE_H
|
||||
|
||||
enum transport_type {
|
||||
BT = 1,
|
||||
BTADV,
|
||||
NONE,
|
||||
};
|
||||
|
||||
static char *transport_type_text[] = {"BT", "BTADV", "NONE"};
|
||||
|
||||
void btfmcodec_set_current_state(struct btfmcodec_state_machine *, btfmcodec_state);
|
||||
void btfmcodec_wq_prepare_bearer(struct work_struct *);
|
||||
void btfmcodec_wq_hwep_shutdown(struct work_struct *);
|
||||
void btfmcodec_initiate_hwep_shutdown(struct btfmcodec_char_device *btfmcodec_dev);
|
||||
btfmcodec_state btfmcodec_get_current_transport(struct btfmcodec_state_machine *state);
|
||||
btfmcodec_state btfmcodec_get_prev_transport(struct btfmcodec_state_machine *state);
|
||||
#endif /* __LINUX_BTFM_CODEC_BTADV_INTERFACE_H */
|
||||
@@ -0,0 +1,117 @@
|
||||
// SPDX-License-Identifier: GPL-2.0-only
|
||||
/*
|
||||
* Copyright (c) 2023-2025 Qualcomm Innovation Center, Inc. All rights reserved.
|
||||
*/
|
||||
|
||||
#ifndef __LINUX_BTFM_CODEC_HW_INTERFACE_H
|
||||
#define __LINUX_BTFM_CODEC_HW_INTERFACE_H
|
||||
|
||||
#include <linux/kernel.h>
|
||||
#include <linux/bitops.h>
|
||||
#include <sound/pcm.h>
|
||||
#include <sound/pcm_params.h>
|
||||
#include <sound/soc.h>
|
||||
#include <sound/soc-dapm.h>
|
||||
#include <sound/tlv.h>
|
||||
|
||||
/* This flag is set to indicate btfm codec driver is
|
||||
* responsible to configure master.
|
||||
*/
|
||||
#define BTADV_AUDIO_MASTER_CONFIG 0
|
||||
#define BTADV_CONFIGURE_DMA 1
|
||||
#define DEVICE_NAME_MAX_LEN 64
|
||||
|
||||
struct hwep_configurations {
|
||||
void *btfmcodec;
|
||||
uint8_t stream_id;
|
||||
uint32_t sample_rate;
|
||||
uint8_t bit_width;
|
||||
uint8_t codectype;
|
||||
uint32_t direction;
|
||||
uint8_t num_channels;
|
||||
uint8_t is_port_opened;
|
||||
struct list_head dai_list;
|
||||
};
|
||||
|
||||
struct master_hwep_configurations {
|
||||
uint8_t stream_id;
|
||||
uint32_t device_id;
|
||||
uint32_t sample_rate;
|
||||
uint8_t bit_width;
|
||||
uint8_t num_channels;
|
||||
uint8_t chan_num;
|
||||
uint8_t codectype;
|
||||
uint16_t direction;
|
||||
};
|
||||
|
||||
struct hwep_dma_configurations {
|
||||
uint8_t stream_id;
|
||||
uint32_t sample_rate;
|
||||
uint8_t bit_width;
|
||||
uint8_t num_channels;
|
||||
uint8_t codectype;
|
||||
uint8_t lpaif; // Low power audio interface
|
||||
uint8_t inf_index; // interface index
|
||||
uint8_t active_channel_mask;
|
||||
};
|
||||
|
||||
struct hwep_comp_drv {
|
||||
int (*hwep_probe) (struct snd_soc_component *);
|
||||
void (*hwep_remove) (struct snd_soc_component *);
|
||||
unsigned int (*hwep_read)(struct snd_soc_component *, unsigned int );
|
||||
int (*hwep_write)(struct snd_soc_component *, unsigned int,
|
||||
unsigned int);
|
||||
};
|
||||
|
||||
struct hwep_dai_ops {
|
||||
int (*hwep_startup)(void *);
|
||||
void (*hwep_shutdown)(void *, int);
|
||||
int (*hwep_hw_params)(void *, uint32_t, uint32_t, uint8_t);
|
||||
int (*hwep_prepare)(void *, uint32_t, uint32_t, int);
|
||||
int (*hwep_set_channel_map)(void *, unsigned int, unsigned int *,
|
||||
unsigned int, unsigned int *);
|
||||
int (*hwep_get_channel_map)(void *, unsigned int *, unsigned int *,
|
||||
unsigned int *, unsigned int *, int);
|
||||
int (*hwep_get_configs)(void *a, void *b, uint8_t c);
|
||||
uint8_t *hwep_codectype;
|
||||
};
|
||||
|
||||
struct hwep_dai_driver {
|
||||
const char *dai_name;
|
||||
unsigned int id;
|
||||
struct snd_soc_pcm_stream capture;
|
||||
struct snd_soc_pcm_stream playback;
|
||||
struct hwep_dai_ops *dai_ops;
|
||||
};
|
||||
|
||||
struct hwep_data {
|
||||
struct device *dev;
|
||||
char driver_name [DEVICE_NAME_MAX_LEN];
|
||||
struct hwep_comp_drv *drv;
|
||||
struct hwep_dai_driver *dai_drv;
|
||||
struct snd_kcontrol_new *mixer_ctrl;
|
||||
int num_dai;
|
||||
int num_mixer_ctrl;
|
||||
unsigned long flags;
|
||||
};
|
||||
|
||||
int btfmcodec_register_hw_ep(struct hwep_data *);
|
||||
int btfmcodec_unregister_hw_ep(char *);
|
||||
// ToDo below.
|
||||
/*
|
||||
#if IS_ENABLED(CONFIG_SLIM_BTFM_CODEC_DRV)
|
||||
int btfmcodec_register_hw_ep(struct hwep_data *);
|
||||
int btfmcodec_unregister_hw_ep(char *);
|
||||
#else
|
||||
static inline int btfmcodec_register_hw_ep(struct hwep_data *hwep_info)
|
||||
{
|
||||
return -EOPNOTSUPP;
|
||||
}
|
||||
|
||||
static inline int btfmcodec_unregister_hw_ep(char *dev_name)
|
||||
{
|
||||
return -EOPNOTSUPP;
|
||||
}
|
||||
#endif
|
||||
*/
|
||||
#endif /*__LINUX_BTFM_CODEC_HW_INTERFACE_H */
|
||||
@@ -0,0 +1,12 @@
|
||||
// SPDX-License-Identifier: GPL-2.0-only
|
||||
/*
|
||||
* Copyright (c) 2023 Qualcomm Innovation Center, Inc. All rights reserved.
|
||||
*/
|
||||
|
||||
#ifndef __LINUX_BTFM_CODEC_INTERFACE
|
||||
#define __LINUX_BTFM_CODEC_INTERFACE
|
||||
|
||||
#include "btfm_codec_hw_interface.h"
|
||||
int btfm_register_codec(struct hwep_data *hwep_info);
|
||||
void btfm_unregister_codec(void);
|
||||
#endif /*__LINUX_BTFM_CODEC_INTERFACE */
|
||||
150
qcom/opensource/bt-kernel/btfmcodec/include/btfm_codec_pkt.h
Normal file
150
qcom/opensource/bt-kernel/btfmcodec/include/btfm_codec_pkt.h
Normal file
@@ -0,0 +1,150 @@
|
||||
// SPDX-License-Identifier: GPL-2.0-only
|
||||
/*
|
||||
* Copyright (c) 2023-2024 Qualcomm Innovation Center, Inc. All rights reserved.
|
||||
*/
|
||||
|
||||
#ifndef __LINUX_BTFM_CODEC_PKT_H
|
||||
#define __LINUX_BTFM_CODEC_PKT_H
|
||||
|
||||
typedef uint32_t btm_opcode;
|
||||
|
||||
struct btm_req {
|
||||
btm_opcode opcode;
|
||||
uint32_t len;
|
||||
uint8_t *data;
|
||||
}__attribute__((packed));
|
||||
|
||||
struct btm_rsp {
|
||||
btm_opcode opcode;
|
||||
uint8_t status;
|
||||
}__attribute__((packed));
|
||||
|
||||
struct btm_ind {
|
||||
btm_opcode opcode;
|
||||
uint32_t len;
|
||||
uint8_t *data;
|
||||
}__attribute__((packed));
|
||||
|
||||
struct btm_ctrl_pkt {
|
||||
btm_opcode opcode;
|
||||
uint32_t len;
|
||||
uint8_t active_transport;
|
||||
uint8_t status;
|
||||
}__attribute__((packed));
|
||||
|
||||
#define BTM_BTFMCODEC_PREPARE_AUDIO_BEARER_SWITCH_REQ 0x50000000
|
||||
#define BTM_BTFMCODEC_PREPARE_AUDIO_BEARER_SWITCH_RSP 0x50000001
|
||||
#define BTM_BTFMCODEC_MASTER_CONFIG_REQ 0x50000002
|
||||
#define BTM_BTFMCODEC_MASTER_CONFIG_RSP 0x50000003
|
||||
#define BTM_BTFMCODEC_MASTER_SHUTDOWN_REQ 0x50000004
|
||||
#define BTM_BTFMCODEC_CTRL_MASTER_SHUTDOWN_RSP 0x50000005
|
||||
#define BTM_BTFMCODEC_CODEC_CONFIG_DMA_REQ 0x58000006
|
||||
#define BTM_BTFMCODEC_CODEC_CONFIG_DMA_RSP 0x58000007
|
||||
|
||||
#define BTM_BTFMCODEC_BEARER_SWITCH_IND 0x58000001
|
||||
#define BTM_BTFMCODEC_TRANSPORT_SWITCH_FAILED_IND 0x58000002
|
||||
#define BTM_BTFMCODEC_ADSP_STATE_IND 0x58000003
|
||||
#define BTM_BTFMCODEC_CTRL_LOG_LVL_IND 0x58000004
|
||||
#define BTM_BTFMCODEC_PORT_STATE_IND 0x58000005
|
||||
|
||||
#define BTM_MASTER_CONFIG_REQ_LEN 13
|
||||
#define BTM_MASTER_CONFIG_RSP_TIMEOUT 5000
|
||||
#define BTM_BEARER_SWITCH_IND_TIMEOUT 25000
|
||||
#define BTM_MASTER_DMA_CONFIG_RSP_TIMEOUT 5000
|
||||
#define BTM_HEADER_LEN 8
|
||||
#define BTM_PREPARE_AUDIO_BEARER_SWITCH_RSP_LEN 2
|
||||
#define BTM_MASTER_CONFIG_RSP_LEN 2
|
||||
#define BTM_CODEC_CONFIG_DMA_RSP_LEN 2
|
||||
#define BTM_MASTER_SHUTDOWN_REQ_LEN 1
|
||||
#define BTM_PREPARE_AUDIO_BEARER_SWITCH_REQ_LEN 1
|
||||
#define BTM_BEARER_SWITCH_IND_LEN 1
|
||||
#define BTM_LOG_LVL_IND_LEN 1
|
||||
#define BTM_ADSP_STATE_IND_LEN 4
|
||||
#define BTM_CODEC_CONFIG_DMA_REQ_LEN 11
|
||||
#define BTM_PORT_STATE_IND_LEN 1
|
||||
|
||||
#define BTM_BTFMCODEC_USECASE_START_REQ 0x58000008
|
||||
#define BTM_BTFMCODEC_USECASE_START_RSP 0x58000009
|
||||
#define BTM_USECASE_START_IND_LEN 2
|
||||
#define BTM_USECASE_START_RSP_LEN 1
|
||||
|
||||
enum rx_status {
|
||||
/* Waiting for response */
|
||||
BTM_WAITING_RSP,
|
||||
/* Response recevied */
|
||||
BTM_RSP_RECV,
|
||||
/* Response recevied with failure status*/
|
||||
BTM_FAIL_RESP_RECV,
|
||||
/* Response not recevied, but client killed */
|
||||
BTM_RSP_NOT_RECV_CLIENT_KILLED,
|
||||
};
|
||||
|
||||
enum btfm_kp_status {
|
||||
/* KP processed message succesfully */
|
||||
MSG_SUCCESS = 0,
|
||||
/* Error while processing the message */
|
||||
MSG_FAILED,
|
||||
/* Wrong transport type selected by BTADV audio manager */
|
||||
MSG_WRONG_TRANSPORT_TYPE,
|
||||
/* Timeout triggered to receive bearer switch indications*/
|
||||
MSG_INTERNAL_TIMEOUT,
|
||||
MSG_FAILED_TO_CONFIGURE_HWEP,
|
||||
MSG_FAILED_TO_SHUTDOWN_HWEP,
|
||||
MSG_ERR_WHILE_SHUTING_DOWN_HWEP,
|
||||
};
|
||||
|
||||
struct btm_master_config_req {
|
||||
btm_opcode opcode;
|
||||
uint32_t len;
|
||||
uint8_t stream_id;
|
||||
uint32_t device_id;
|
||||
uint32_t sample_rate;
|
||||
uint8_t bit_width;
|
||||
uint8_t num_channels;
|
||||
uint8_t channel_num;
|
||||
uint8_t codec_id;
|
||||
} __packed;
|
||||
|
||||
struct btm_dma_config_req {
|
||||
btm_opcode opcode;
|
||||
uint32_t len;
|
||||
uint8_t stream_id;
|
||||
uint32_t sample_rate;
|
||||
uint8_t bit_width;
|
||||
uint8_t num_channels;
|
||||
uint8_t codec_id;
|
||||
uint8_t lpaif; // Low power audio interface
|
||||
uint8_t inf_index; // interface index
|
||||
uint8_t active_channel_mask;
|
||||
} __packed;
|
||||
|
||||
struct btm_usecase_start_ind {
|
||||
btm_opcode opcode;
|
||||
uint32_t len;
|
||||
uint8_t transport;
|
||||
uint8_t stream_id;
|
||||
} __packed;
|
||||
|
||||
struct btm_master_shutdown_req {
|
||||
btm_opcode opcode;
|
||||
uint32_t len;
|
||||
uint8_t stream_id;
|
||||
} __packed;
|
||||
|
||||
struct btm_adsp_state_ind {
|
||||
btm_opcode opcode;
|
||||
uint32_t len;
|
||||
uint32_t action;
|
||||
} __packed;
|
||||
|
||||
struct btm_port_state_ind {
|
||||
btm_opcode opcode;
|
||||
uint32_t len;
|
||||
uint8_t port_state;
|
||||
} __packed;
|
||||
|
||||
int btfmcodec_dev_enqueue_pkt(struct btfmcodec_char_device *btfmcodec_dev, void *buf, int len);
|
||||
bool btfmcodec_is_valid_cache_avb(struct btfmcodec_data *btfmcodec);
|
||||
int btfmcodec_enqueue_transport(struct btfmcodec_char_device *btfmcodec_dev, uint8_t transport);
|
||||
int btfmcodec_dequeue_transport(struct btfmcodec_char_device *btfmcodec_dev);
|
||||
#endif /* __LINUX_BTFM_CODEC_PKT_H*/
|
||||
Reference in New Issue
Block a user