ASoC: Intel: Add support for Haswell/Broadwell DSP
Subsystems (4)
Liam Girdwood
maintainerPATCH 1/6 ASoC: Intel: Add support for Haswell/Broadwell DSP
Add support for low level differentiation functions for Haswell and Broadwell SST DSPs. This includes suppoprt for DSP boot and reset, DSP firmware module parsing and DSP memory block map initialisation.
--- sound/soc/intel/sst-dsp.c | 60 +++++ sound/soc/intel/sst-dsp.h | 10 + sound/soc/intel/sst-haswell-dsp.c | 517 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 587 insertions(+) create mode 100644 sound/soc/intel/sst-haswell-dsp.c
sound/soc/intel/sst-dsp.c +60 -0
@@ -27,6 +27,66 @@#define CREATE_TRACE_POINTS #include <trace/events/intel-sst.h> +/* Internal generic low-level SST IO functions - can be overidden */ +void sst_shim32_write (void __iomem *addr,u32 offset,u32 value) +{ +writel (value, addr + offset); +} +EXPORT_SYMBOL_GPL (sst_shim32_write); + +u32 sst_shim32_read (void __iomem *addr,u32 offset) +{ +return readl (addr + offset); +} +EXPORT_SYMBOL_GPL (sst_shim32_read); + +void sst_shim32_write64 (void __iomem *addr,u32 offset,u64 value) +{ +memcpy_toio (addr + offset, &value,sizeof (value)); +} +EXPORT_SYMBOL_GPL (sst_shim32_write64); + +u64 sst_shim32_read64 (void __iomem *addr,u32 offset) +{ +u64 val; + +memcpy_fromio (&val, addr + offset,sizeof (val)); +return val; +} +EXPORT_SYMBOL_GPL (sst_shim32_read64); + +static inline void _sst_memcpy_toio_32 (volatile u32 __iomem *dest, +u32 *src,size_t bytes) +{ +int i, words = bytes >>2 ; + +for (i =0 ; i < words; i++) +writel (src[i], dest + i); +} + +static inline void _sst_memcpy_fromio_32 (u32 *dest, +const volatile __iomem u32 *src,size_t bytes) +{ +int i, words = bytes >>2 ; + +for (i =0 ; i < words; i++) + dest[i] =readl (src + i); +} + +void sst_memcpy_toio_32 (struct sst_dsp *sst, +void __iomem *dest,void *src,size_t bytes) +{ +_sst_memcpy_toio_32 (dest, src, bytes); +} +EXPORT_SYMBOL_GPL (sst_memcpy_toio_32); + +void sst_memcpy_fromio_32 (struct sst_dsp *sst,void *dest, +void __iomem *src,size_t bytes) +{ +_sst_memcpy_fromio_32 (dest, src, bytes); +} +EXPORT_SYMBOL_GPL (sst_memcpy_fromio_32); +/* Public API */ void sst_dsp_shim_write (struct sst_dsp *sst,u32 offset,u32 value) {
sound/soc/intel/sst-dsp.h +10 -0
@@ -189,6 +189,16 @@ u64 sst_dsp_shim_read64_unlocked(struct sst_dsp *sst, u32 offset);int sst_dsp_shim_update_bits64_unlocked (struct sst_dsp *sst,u32 offset,u64 mask,u64 value); +/* Internal generic low-level SST IO functions - can be overidden */ +void sst_shim32_write (void __iomem *addr,u32 offset,u32 value); +u32 sst_shim32_read (void __iomem *addr,u32 offset); +void sst_shim32_write64 (void __iomem *addr,u32 offset,u64 value); +u64 sst_shim32_read64 (void __iomem *addr,u32 offset); +void sst_memcpy_toio_32 (struct sst_dsp *sst, +void __iomem *dest,void *src,size_t bytes); +void sst_memcpy_fromio_32 (struct sst_dsp *sst, +void *dest,void __iomem *src,size_t bytes); +/* DSP reset & boot */ void sst_dsp_reset (struct sst_dsp *sst);int sst_dsp_boot (struct sst_dsp *sst);
sound/soc/intel/sst-haswell-dsp.c new file +517 -0
517 lines not on this page · raw message
Signature · 1 line
1.8.3.2
Liam Girdwood
maintainerPATCH 2/6 ASoC: Intel: Add Haswell/Broadwell IPC
Add support for Haswell and Broadwell DSP IPC. This is used by the DSP platform PCM driver to configure the DSP for audio operations.
--- sound/soc/intel/sst-haswell-ipc.c | 1785 +++++++++++++++++++++++++++++++++++++ sound/soc/intel/sst-haswell-ipc.h | 488 ++++++++++ 2 files changed, 2273 insertions(+) create mode 100644 sound/soc/intel/sst-haswell-ipc.c create mode 100644 sound/soc/intel/sst-haswell-ipc.h
sound/soc/intel/sst-haswell-ipc.c new file +1785 -0
@@ -0,0 +1,1785 @@ +/* +* Intel SST Haswell/Broadwell IPC Support +* +* Copyright (C) 2013, Intel Corporation. All rights reserved. +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License version +* 2 as published by the Free Software Foundation. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +*/ + +#include <linux/types.h> +#include <linux/kernel.h> +#include <linux/list.h> +#include <linux/device.h> +#include <linux/wait.h> +#include <linux/spinlock.h> +#include <linux/workqueue.h> +#include <linux/export.h> +#include <linux/slab.h> +#include <linux/delay.h> +#include <linux/sched.h> +#include <linux/list.h> +#include <linux/platform_device.h> +#include <linux/kthread.h> +#include <linux/firmware.h> +#include <linux/dma-mapping.h> +#include <linux/debugfs.h> + +#include "sst-haswell-ipc.h" +#include "sst-dsp.h" +#include "sst-dsp-priv.h" + +/* Global Message - Generic */ +#define IPC_GLB_TYPE_SHIFT 24 +#define IPC_GLB_TYPE_MASK (0x1f << IPC_GLB_TYPE_SHIFT) +#define IPC_GLB_TYPE (x) (x << IPC_GLB_TYPE_SHIFT) + +/* Global Message - Reply */ +#define IPC_GLB_REPLY_SHIFT 0 +#define IPC_GLB_REPLY_MASK (0x1f << IPC_GLB_REPLY_SHIFT) +#define IPC_GLB_REPLY_TYPE (x) (x << IPC_GLB_REPLY_TYPE_SHIFT) + +/* Stream Message - Generic */ +#define IPC_STR_TYPE_SHIFT 20 +#define IPC_STR_TYPE_MASK (0xf << IPC_STR_TYPE_SHIFT) +#define IPC_STR_TYPE (x) (x << IPC_STR_TYPE_SHIFT) +#define IPC_STR_ID_SHIFT 16 +#define IPC_STR_ID_MASK (0xf << IPC_STR_ID_SHIFT) +#define IPC_STR_ID (x) (x << IPC_STR_ID_SHIFT) + +/* Stream Message - Reply */ +#define IPC_STR_REPLY_SHIFT 0 +#define IPC_STR_REPLY_MASK (0x1f << IPC_STR_REPLY_SHIFT) + +/* Stream Stage Message - Generic */ +#define IPC_STG_TYPE_SHIFT 12 +#define IPC_STG_TYPE_MASK (0xf << IPC_STG_TYPE_SHIFT) +#define IPC_STG_TYPE (x) (x << IPC_STG_TYPE_SHIFT) +#define IPC_STG_ID_SHIFT 10 +#define IPC_STG_ID_MASK (0x3 << IPC_STG_ID_SHIFT) +#define IPC_STG_ID (x) (x << IPC_STG_ID_SHIFT) + +/* Stream Stage Message - Reply */ +#define IPC_STG_REPLY_SHIFT 0 +#define IPC_STG_REPLY_MASK (0x1f << IPC_STG_REPLY_SHIFT) + +/* Debug Log Message - Generic */ +#define IPC_LOG_OP_SHIFT 20 +#define IPC_LOG_OP_MASK (0xf << IPC_LOG_OP_SHIFT) +#define IPC_LOG_OP_TYPE (x) (x << IPC_LOG_OP_SHIFT) +#define IPC_LOG_ID_SHIFT 16 +#define IPC_LOG_ID_MASK (0xf << IPC_LOG_ID_SHIFT) +#define IPC_LOG_ID (x) (x << IPC_LOG_ID_SHIFT) + +/* IPC message timeout (msecs) */ +#define IPC_TIMEOUT_MSECS 300 +#define IPC_BOOT_MSECS 200 +#define IPC_MSG_WAIT 0 +#define IPC_MSG_NOWAIT 1 + +/* Firmware Ready Message */ +#define IPC_FW_READY (0x1 << 29) +#define IPC_STATUS_MASK (0x3 << 30) + +#define IPC_EMPTY_LIST_SIZE 8 +#define IPC_MAX_STREAMS 4 + +/* Mailbox */ +#define IPC_MAX_MAILBOX_BYTES 256 + +/* Global Message - Types and Replies */ +enum ipc_glb_type { +IPC_GLB_GET_FW_VERSION =0 ,/* Retrieves firmware version */ +IPC_GLB_PERFORMANCE_MONITOR =1 ,/* Performance monitoring actions */ +IPC_GLB_ALLOCATE_STREAM =3 ,/* Request to allocate new stream */ +IPC_GLB_FREE_STREAM =4 ,/* Request to free stream */ +IPC_GLB_GET_FW_CAPABILITIES =5 ,/* Retrieves firmware capabilities */ +IPC_GLB_STREAM_MESSAGE =6 ,/* Message directed to stream or its stages */ +/* Request to store firmware context during D0->D3 transition */ +IPC_GLB_REQUEST_DUMP =7 , +/* Request to restore firmware context during D3->D0 transition */ +IPC_GLB_RESTORE_CONTEXT =8 , +IPC_GLB_GET_DEVICE_FORMATS =9 ,/* Set device format */ +IPC_GLB_SET_DEVICE_FORMATS =10 ,/* Get device format */ +IPC_GLB_SHORT_REPLY =11 , +IPC_GLB_ENTER_DX_STATE =12 , +IPC_GLB_GET_MIXER_STREAM_INFO =13 ,/* Request mixer stream params */ +IPC_GLB_DEBUG_LOG_MESSAGE =14 ,/* Message to or from the debug logger. */ +IPC_GLB_REQUEST_TRANSFER =16 ,/* < Request Transfer for host */ +IPC_GLB_MAX_IPC_MESSAGE_TYPE =17 ,/* Maximum message number */ +}; + +enum ipc_glb_reply { +IPC_GLB_REPLY_SUCCESS =0 ,/* The operation was successful. */ +IPC_GLB_REPLY_ERROR_INVALID_PARAM =1 ,/* Invalid parameter was passed. */ +IPC_GLB_REPLY_UNKNOWN_MESSAGE_TYPE =2 ,/* Uknown message type was resceived. */ +IPC_GLB_REPLY_OUT_OF_RESOURCES =3 ,/* No resources to satisfy the request. */ +IPC_GLB_REPLY_BUSY =4 ,/* The system or resource is busy. */ +IPC_GLB_REPLY_PENDING =5 ,/* The action was scheduled for processing. */ +IPC_GLB_REPLY_FAILURE =6 ,/* Critical error happened. */ +IPC_GLB_REPLY_INVALID_REQUEST =7 ,/* Request can not be completed. */ +IPC_GLB_REPLY_STAGE_UNINITIALIZED =8 ,/* Processing stage was uninitialized. */ +IPC_GLB_REPLY_NOT_FOUND =9 ,/* Required resource can not be found. */ +IPC_GLB_REPLY_SOURCE_NOT_STARTED =10 ,/* Source was not started. */ +}; + +/* Stream Message - Types */ +enum ipc_str_operation { +IPC_STR_RESET =0 , +IPC_STR_PAUSE =1 , +IPC_STR_RESUME =2 , +IPC_STR_STAGE_MESSAGE =3 , +IPC_STR_NOTIFICATION =4 , +IPC_STR_MAX_MESSAGE +}; + +/* Stream Stage Message Types */ +enum ipc_stg_operation { +IPC_STG_GET_VOLUME =0 , +IPC_STG_SET_VOLUME , +IPC_STG_SET_WRITE_POSITION , +IPC_STG_SET_FX_ENABLE , +IPC_STG_SET_FX_DISABLE , +IPC_STG_SET_FX_GET_PARAM , +IPC_STG_SET_FX_SET_PARAM , +IPC_STG_SET_FX_GET_INFO , +IPC_STG_MUTE_LOOPBACK , +IPC_STG_MAX_MESSAGE +}; + +/* Stream Stage Message Types For Notification*/ +enum ipc_stg_operation_notify { +IPC_POSITION_CHANGED =0 , +IPC_STG_GLITCH , +IPC_STG_MAX_NOTIFY +}; + +enum ipc_glitch_type { +IPC_GLITCH_UNDERRUN =1 , +IPC_GLITCH_DECODER_ERROR , +IPC_GLITCH_DOUBLED_WRITE_POS , +IPC_GLITCH_MAX +}; + +/* Debug Control */ +enum ipc_debug_operation { +IPC_DEBUG_ENABLE_LOG =0 , +IPC_DEBUG_DISABLE_LOG =1 , +IPC_DEBUG_REQUEST_LOG_DUMP =2 , +IPC_DEBUG_NOTIFY_LOG_DUMP =3 , +IPC_DEBUG_MAX_DEBUG_LOG +}; + +/* Firmware Ready */ +struct sst_hsw_ipc_fw_ready { +u32 inbox_offset; +u32 outbox_offset; +u32 inbox_size; +u32 outbox_size; +u32 fw_info_size; +u8 fw_info[1 ]; +} __attribute__((packed)); + +struct ipc_message { +struct list_head list; +u32 header; + +/* direction wrt host CPU */ +char tx_data[IPC_MAX_MAILBOX_BYTES ]; +size_t tx_size; +char rx_data[IPC_MAX_MAILBOX_BYTES ]; +size_t rx_size; + +wait_queue_head_t waitq; +bool pending; +bool complete; +bool wait; +int errno; +}; + +struct sst_hsw_stream ; +struct sst_hsw ; + +/* Stream infomation */ +struct sst_hsw_stream { +/* configuration */ +struct sst_hsw_ipc_stream_alloc_req request; +struct sst_hsw_ipc_stream_alloc_reply reply; +struct sst_hsw_ipc_stream_free_req free_req; + +/* Mixer info */ +u32 mute_volume[SST_HSW_NO_CHANNELS ]; +u32 mute[SST_HSW_NO_CHANNELS ]; + +/* runtime info */ +struct sst_hsw *hsw; +int host_id; +bool commited; +bool running; + +/* Notification work */ +struct work_struct notify_work; +u32 header; + +/* Position info from DSP */ +struct sst_hsw_ipc_stream_set_position wpos; +struct sst_hsw_ipc_stream_get_position rpos; +struct sst_hsw_ipc_stream_glitch_position glitch; + +/* Volume info */ +struct sst_hsw_ipc_volume_req vol_req; + +/* driver callback */ +u32 (*notify_position)(struct sst_hsw_stream *stream,void *data); +void *pdata; + +struct list_head node; +}; + +/* FW log ring information */ +struct sst_hsw_log_stream { +dma_addr_t dma_addr; +unsigned char *dma_area; +unsigned char *ring_descr; +int pages; +int size; + +/* Notification work */ +struct work_struct notify_work; +wait_queue_head_t readers_wait_q; +struct mutex rw_mutex; + +u32 last_pos; +u32 curr_pos; +u32 reader_pos; + +/* fw log config */ +u32 config[SST_HSW_FW_LOG_CONFIG_DWORDS ]; + +struct sst_hsw *hsw; +}; + +/* SST Haswell IPC data */ +struct sst_hsw { +struct device *dev; +struct sst_dsp *dsp; +struct platform_device *pdev_pcm; + +/* FW config */ +struct sst_hsw_ipc_fw_ready fw_ready; +struct sst_hsw_ipc_fw_version version; +struct sst_module *scratch; +bool fw_done; + +/* stream */ +struct list_head stream_list; + +/* global mixer */ +struct sst_hsw_ipc_stream_info_reply mixer_info; +enum sst_hsw_volume_curve curve_type; +u32 curve_duration; +u32 mute[SST_HSW_NO_CHANNELS ]; +u32 mute_volume[SST_HSW_NO_CHANNELS ]; + +/* DX */ +struct sst_hsw_ipc_dx_reply dx; + +/* boot */ +wait_queue_head_t boot_wait; +bool boot_complete; +bool shutdown; + +/* IPC messaging */ +struct list_head tx_list; +struct list_head rx_list; +struct list_head empty_list; +wait_queue_head_t wait_txq; +struct task_struct *tx_thread; +struct kthread_worker kworker; +struct kthread_work kwork; +bool pending; +struct ipc_message *msg; + +/* FW log stream */ +struct sst_hsw_log_stream log_stream; +}; + +#define CREATE_TRACE_POINTS +#include <trace/events/hswadsp.h> + +static inline u32 msg_get_global_type (u32 msg) +{ +return (msg &IPC_GLB_TYPE_MASK ) >>IPC_GLB_TYPE_SHIFT ; +} + +static inline u32 msg_get_global_reply (u32 msg) +{ +return (msg &IPC_GLB_REPLY_MASK ) >>IPC_GLB_REPLY_SHIFT ; +} + +static inline u32 msg_get_stream_type (u32 msg) +{ +return (msg &IPC_STR_TYPE_MASK ) >>IPC_STR_TYPE_SHIFT ; +} + +static inline u32 msg_get_stage_type (u32 msg) +{ +return (msg &IPC_STG_TYPE_MASK ) >>IPC_STG_TYPE_SHIFT ; +} + +static inline u32 msg_set_stage_type (u32 msg,u32 type) +{ +return (msg & ~IPC_STG_TYPE_MASK ) + + (type <<IPC_STG_TYPE_SHIFT ); +} + +static inline u32 msg_get_stream_id (u32 msg) +{ +return (msg &IPC_STR_ID_MASK ) >>IPC_STR_ID_SHIFT ; +} + +static inline u32 msg_get_notify_reason (u32 msg) +{ +return (msg &IPC_STG_TYPE_MASK ) >>IPC_STG_TYPE_SHIFT ; +} + +u32 create_channel_map (enum sst_hsw_channel_config config) +{ +switch (config) { +case SST_HSW_CHANNEL_CONFIG_MONO : +return (0xFFFFFFF0 |SST_HSW_CHANNEL_CENTER ); +case SST_HSW_CHANNEL_CONFIG_STEREO : +return (0xFFFFFF00 |SST_HSW_CHANNEL_LEFT + | (SST_HSW_CHANNEL_RIGHT <<4 )); +case SST_HSW_CHANNEL_CONFIG_2_POINT_1 : +return (0xFFFFF000 |SST_HSW_CHANNEL_LEFT + | (SST_HSW_CHANNEL_RIGHT <<4 ) + | (SST_HSW_CHANNEL_LFE <<8 )); +case SST_HSW_CHANNEL_CONFIG_3_POINT_0 : +return (0xFFFFF000 |SST_HSW_CHANNEL_LEFT + | (SST_HSW_CHANNEL_CENTER <<4 ) + | (SST_HSW_CHANNEL_RIGHT <<8 )); +case SST_HSW_CHANNEL_CONFIG_3_POINT_1 : +return (0xFFFF0000 |SST_HSW_CHANNEL_LEFT + | (SST_HSW_CHANNEL_CENTER <<4 ) + | (SST_HSW_CHANNEL_RIGHT <<8 ) + | (SST_HSW_CHANNEL_LFE <<12 )); +case SST_HSW_CHANNEL_CONFIG_QUATRO : +return (0xFFFF0000 |SST_HSW_CHANNEL_LEFT + | (SST_HSW_CHANNEL_RIGHT <<4 ) + | (SST_HSW_CHANNEL_LEFT_SURROUND <<8 ) + | (SST_HSW_CHANNEL_RIGHT_SURROUND <<12 )); +case SST_HSW_CHANNEL_CONFIG_4_POINT_0 : +return (0xFFFF0000 |SST_HSW_CHANNEL_LEFT + | (SST_HSW_CHANNEL_CENTER <<4 ) + | (SST_HSW_CHANNEL_RIGHT <<8 ) + | (SST_HSW_CHANNEL_CENTER_SURROUND <<12 )); +case SST_HSW_CHANNEL_CONFIG_5_POINT_0 : +return (0xFFF00000 |SST_HSW_CHANNEL_LEFT + | (SST_HSW_CHANNEL_CENTER <<4 ) + | (SST_HSW_CHANNEL_RIGHT <<8 ) + | (SST_HSW_CHANNEL_LEFT_SURROUND <<12 ) + | (SST_HSW_CHANNEL_RIGHT_SURROUND <<16 )); +case SST_HSW_CHANNEL_CONFIG_5_POINT_1 : +return (0xFF000000 |SST_HSW_CHANNEL_CENTER + | (SST_HSW_CHANNEL_LEFT <<4 ) + | (SST_HSW_CHANNEL_RIGHT <<8 ) + | (SST_HSW_CHANNEL_LEFT_SURROUND <<12 ) + | (SST_HSW_CHANNEL_RIGHT_SURROUND <<16 ) + | (SST_HSW_CHANNEL_LFE <<20 )); +case SST_HSW_CHANNEL_CONFIG_DUAL_MONO : +return (0xFFFFFF00 |SST_HSW_CHANNEL_LEFT + | (SST_HSW_CHANNEL_LEFT <<4 )); +default : +return 0xFFFFFFFF ; + } +} + +static struct sst_hsw_stream *get_stream_by_id (struct sst_hsw *hsw, +int stream_id) +{ +struct sst_hsw_stream *stream; + +list_for_each_entry (stream, &hsw->stream_list, node) { +if (stream->reply.stream_hw_id == stream_id) +return stream; + } + +return NULL ; +} + +static void ipc_shim_dbg (struct sst_hsw *hsw,const char *text) +{ +struct sst_dsp *sst = hsw->dsp; +u32 isr, ipcd, imrx, ipcx; + + ipcx =sst_dsp_shim_read_unlocked (sst,SST_IPCX ); + isr =sst_dsp_shim_read_unlocked (sst,SST_ISRX ); + ipcd =sst_dsp_shim_read_unlocked (sst,SST_IPCD ); + imrx =sst_dsp_shim_read_unlocked (sst,SST_IMRX ); + +dev_err (hsw->dev,"ipc: --%s-- ipcx 0x%8.8x isr 0x%8.8x ipcd 0x%8.8x imrx 0x%8.8x\n" , + text, ipcx, isr, ipcd, imrx); +} + +/* locks held by caller */ +static struct ipc_message *msg_get_empty (struct sst_hsw *hsw) +{ +struct ipc_message *msg =NULL ; + +if (!list_empty (&hsw->empty_list)) { + msg = list_first_entry(&hsw->empty_list, struct ipc_message, + list); +list_del (&msg->list); + } + +return msg; +} + +static void ipc_tx_msgs (struct kthread_work *work) +{ +struct sst_hsw *hsw = + container_of(work, struct sst_hsw, kwork); +struct ipc_message *msg; +unsigned long flags; +u32 ipcx; + +spin_lock_irqsave (&hsw->dsp->spinlock, flags); + +if (list_empty (&hsw->tx_list) || hsw->pending) { +spin_unlock_irqrestore (&hsw->dsp->spinlock, flags); +return ; + } + +/* if the DSP is busy we will TX messages after IRQ */ + ipcx =sst_dsp_shim_read_unlocked (hsw->dsp,SST_IPCX ); +if (ipcx &SST_IPCX_BUSY ) { +spin_unlock_irqrestore (&hsw->dsp->spinlock, flags); +return ; + } + + msg = list_first_entry(&hsw->tx_list, struct ipc_message, list); + +list_move (&msg->list, &hsw->rx_list); + +/* send the message */ +sst_dsp_outbox_write (hsw->dsp, msg->tx_data, msg->tx_size); +sst_dsp_ipc_msg_tx (hsw->dsp, msg->header |SST_IPCX_BUSY ); + +spin_unlock_irqrestore (&hsw->dsp->spinlock, flags); +} + +/* locks held by caller */ +static void tx_msg_reply_complete (struct sst_hsw *hsw,struct ipc_message *msg) +{ + msg->complete = true; +trace_ipc_reply ("completed" , msg->header); + +if (!msg->wait) +list_add_tail (&msg->list, &hsw->empty_list); +else +wake_up (&msg->waitq); +} + +static int tx_wait_done (struct sst_hsw *hsw,struct ipc_message *msg, +void *rx_data) +{ +unsigned long flags; +int ret; + +/* wait for DSP completion (in all cases atm inc pending) */ + ret =wait_event_timeout (msg->waitq, msg->complete, +msecs_to_jiffies (IPC_TIMEOUT_MSECS )); + +spin_lock_irqsave (&hsw->dsp->spinlock, flags); +if (ret ==0 ) { +ipc_shim_dbg (hsw,"message timeout" ); + +trace_ipc_error ("error message timeout for" , msg->header); + ret = -ETIMEDOUT ; + }else { + +/* copy the data returned from DSP */ +if (msg->rx_size) +memcpy (rx_data, msg->rx_data, msg->rx_size); + ret = msg->errno; + } + +list_add_tail (&msg->list, &hsw->empty_list); +spin_unlock_irqrestore (&hsw->dsp->spinlock, flags); +return ret; +} + +static int ipc_tx_message (struct sst_hsw *hsw,u32 header,void *tx_data, +size_t tx_bytes,void *rx_data,size_t rx_bytes,int wait) +{ +struct ipc_message *msg; +unsigned long flags; + +spin_lock_irqsave (&hsw->dsp->spinlock, flags); + + msg =msg_get_empty (hsw); +if (msg ==NULL ) { +spin_unlock (&hsw->dsp->spinlock); +return -EBUSY ; + } + +if (tx_bytes) +memcpy (msg->tx_data, tx_data, tx_bytes); + + msg->header = header; + msg->tx_size = tx_bytes; + msg->rx_size = rx_bytes; + msg->wait = wait; + msg->errno =0 ; + msg->pending = false; + msg->complete = false; + +list_add_tail (&msg->list, &hsw->tx_list); +spin_unlock_irqrestore (&hsw->dsp->spinlock, flags); + +queue_kthread_work (&hsw->kworker, &hsw->kwork); + +if (wait) +return tx_wait_done (hsw, msg, rx_data); +else +return 0 ; +} + +static inline int ipc_tx_message_wait (struct sst_hsw *hsw,u32 header, +void *tx_data,size_t tx_bytes,void *rx_data,size_t rx_bytes) +{ +return ipc_tx_message (hsw, header, tx_data, tx_bytes, rx_data, + rx_bytes,1 ); +} + +static inline int ipc_tx_message_nowait (struct sst_hsw *hsw,u32 header, +void *tx_data,size_t tx_bytes) +{ +return ipc_tx_message (hsw, header, tx_data, tx_bytes,NULL ,0 ,0 ); +} + +static void hsw_fw_ready (struct sst_hsw *hsw,u32 header) +{ +struct sst_hsw_ipc_fw_ready fw_ready; +u32 offset; + + offset = (header &0x1FFFFFFF ) <<3 ; + +dev_dbg (hsw->dev,"ipc: DSP is ready 0x%8.8x offset %d\n" , + header, offset); + +/* copy data from the DSP FW ready offset */ +sst_dsp_read (hsw->dsp, &fw_ready, offset,sizeof (fw_ready)); + +sst_dsp_mailbox_init (hsw->dsp, fw_ready.inbox_offset, + fw_ready.inbox_size, fw_ready.outbox_offset, + fw_ready.outbox_size); + + hsw->boot_complete = true; +wake_up (&hsw->boot_wait); + +dev_dbg (hsw->dev," mailbox upstream 0x%x - size 0x%x\n" , + fw_ready.inbox_offset, fw_ready.inbox_size); +dev_dbg (hsw->dev," mailbox downstream 0x%x - size 0x%x\n" , + fw_ready.outbox_offset, fw_ready.outbox_size); +} + +static void hsw_notification_work (struct work_struct *work) +{ +struct sst_hsw_stream *stream =container_of (work, + struct sst_hsw_stream, notify_work); +struct sst_hsw_ipc_stream_glitch_position *glitch = &stream->glitch; +struct sst_hsw_ipc_stream_get_position *pos = &stream->rpos; +struct sst_hsw *hsw = stream->hsw; +u32 reason; + + reason =msg_get_notify_reason (stream->header); + +switch (reason) { +case IPC_STG_GLITCH : +trace_ipc_notification ("DSP stream under/overrun" , + stream->reply.stream_hw_id); +sst_dsp_inbox_read (hsw->dsp, glitch,sizeof (*glitch)); + +dev_err (hsw->dev,"glitch %d pos 0x%x write pos 0x%x\n" , + glitch->glitch_type, glitch->present_pos, + glitch->write_pos); +break ; + +case IPC_POSITION_CHANGED : +trace_ipc_notification ("DSP stream position changed for" , + stream->reply.stream_hw_id); +sst_dsp_inbox_read (hsw->dsp, pos,sizeof (&pos)); + +if (stream->notify_position) + stream->notify_position (stream, stream->pdata); + +break ; +default : +dev_err (hsw->dev,"error: unknown notification 0x%x\n" , + stream->header); +break ; + } + +/* tell DSP that notification has been handled */ +sst_dsp_shim_update_bits_unlocked (hsw->dsp,SST_IPCD , +SST_IPCD_BUSY |SST_IPCD_DONE ,SST_IPCD_DONE ); + +/* unmask busy interrupt */ +sst_dsp_shim_update_bits_unlocked (hsw->dsp,SST_IMRX ,SST_IMRX_BUSY ,0 ); +} + +static struct ipc_message *reply_find_msg (struct sst_hsw *hsw,u32 header) +{ +struct ipc_message *msg; + +/* clear reply bits & status bits */ + header &= ~(IPC_STATUS_MASK |IPC_GLB_REPLY_MASK ); + +if (list_empty (&hsw->rx_list)) { +dev_err (hsw->dev,"error: rx list empty but received 0x%x\n" , + header); +return NULL ; + } + +list_for_each_entry (msg, &hsw->rx_list, list) { +if (msg->header == header) +return msg; + } + +return NULL ; +} + +static void hsw_stream_update (struct sst_hsw *hsw,struct ipc_message *msg) +{ +struct sst_hsw_stream *stream; +u32 header = msg->header & ~(IPC_STATUS_MASK |IPC_GLB_REPLY_MASK ); +u32 stream_id =msg_get_stream_id (header); +u32 stream_msg =msg_get_stream_type (header); + + stream =get_stream_by_id (hsw, stream_id); +if (stream ==NULL ) +return ; + +switch (stream_msg) { +case IPC_STR_STAGE_MESSAGE : +case IPC_STR_NOTIFICATION : +case IPC_STR_RESET : +break ; +case IPC_STR_PAUSE : + stream->running = false; +trace_ipc_notification ("stream paused" , + stream->reply.stream_hw_id); +break ; +case IPC_STR_RESUME : + stream->running = true; +trace_ipc_notification ("stream running" , + stream->reply.stream_hw_id); +break ; + } +} + +static int hsw_process_reply (struct sst_hsw *hsw,u32 header) +{ +struct ipc_message *msg; +u32 reply =msg_get_global_reply (header); + +trace_ipc_reply ("processing -->" , header); + + msg =reply_find_msg (hsw, header); +if (msg ==NULL ) { +trace_ipc_error ("error: can't find message header" , header); +return -EIO ; + } + +/* first process the header */ +switch (reply) { +case IPC_GLB_REPLY_PENDING : +trace_ipc_pending_reply ("received" , header); + msg->pending = true; + hsw->pending = true; +return 1 ; +case IPC_GLB_REPLY_SUCCESS : +if (msg->pending) { +trace_ipc_pending_reply ("completed" , header); +sst_dsp_inbox_read (hsw->dsp, msg->rx_data, + msg->rx_size); + hsw->pending = false; + }else { +/* copy data from the DSP */ +sst_dsp_outbox_read (hsw->dsp, msg->rx_data, + msg->rx_size); + } +break ; +/* these will be rare - but useful for debug */ +case IPC_GLB_REPLY_UNKNOWN_MESSAGE_TYPE : +trace_ipc_error ("error: unknown message type" , header); + msg->errno = -EBADMSG ; +break ; +case IPC_GLB_REPLY_OUT_OF_RESOURCES : +trace_ipc_error ("error: out of resources" , header); + msg->errno = -ENOMEM ; +break ; +case IPC_GLB_REPLY_BUSY : +trace_ipc_error ("error: reply busy" , header); + msg->errno = -EBUSY ; +break ; +case IPC_GLB_REPLY_FAILURE : +trace_ipc_error ("error: reply failure" , header); + msg->errno = -EINVAL ; +break ; +case IPC_GLB_REPLY_STAGE_UNINITIALIZED : +trace_ipc_error ("error: stage uninitialized" , header); + msg->errno = -EINVAL ; +break ; +case IPC_GLB_REPLY_NOT_FOUND : +trace_ipc_error ("error: reply not found" , header); + msg->errno = -EINVAL ; +break ; +case IPC_GLB_REPLY_SOURCE_NOT_STARTED : +trace_ipc_error ("error: source not started" , header); + msg->errno = -EINVAL ; +break ; +case IPC_GLB_REPLY_INVALID_REQUEST : +trace_ipc_error ("error: invalid request" , header); + msg->errno = -EINVAL ; +break ; +case IPC_GLB_REPLY_ERROR_INVALID_PARAM : +trace_ipc_error ("error: invalid parameter" , header); + msg->errno = -EINVAL ; +break ; +default : +trace_ipc_error ("error: unknown reply" , header); + msg->errno = -EINVAL ; +break ; + } + +/* update any stream states */ +hsw_stream_update (hsw, msg); + +/* wake up and return the error if we have waiters on this message ? */ +list_del (&msg->list); +tx_msg_reply_complete (hsw, msg); + +return 1 ; +} + +static int hsw_stream_message (struct sst_hsw *hsw,u32 header) +{ +u32 stream_msg, stream_id, stage_type; +struct sst_hsw_stream *stream; +int handled =0 ; + + stream_msg =msg_get_stream_type (header); + stream_id =msg_get_stream_id (header); + stage_type =msg_get_stage_type (header); + + stream =get_stream_by_id (hsw, stream_id); +if (stream ==NULL ) +return handled; + + stream->header = header; + +switch (stream_msg) { +case IPC_STR_STAGE_MESSAGE : +dev_err (hsw->dev,"error: stage msg not implemented 0x%8.8x\n" , + header); +break ; +case IPC_STR_NOTIFICATION : +schedule_work (&stream->notify_work); +break ; +default : +/* handle pending message complete request */ + handled =hsw_process_reply (hsw, header); +break ; + } + +return handled; +} + +static int hsw_log_message (struct sst_hsw *hsw,u32 header) +{ +u32 operation = (header &IPC_LOG_OP_MASK ) >>IPC_LOG_OP_SHIFT ; +struct sst_hsw_log_stream *stream = &hsw->log_stream; +int ret =1 ; + +if (operation !=IPC_DEBUG_REQUEST_LOG_DUMP ) { +dev_err (hsw->dev, +"error: log msg not implemented 0x%8.8x\n" , header); +return 0 ; + } + +mutex_lock (&stream->rw_mutex); + stream->last_pos = stream->curr_pos; +sst_dsp_inbox_read ( + hsw->dsp, &stream->curr_pos,sizeof (stream->curr_pos)); +mutex_unlock (&stream->rw_mutex); + +schedule_work (&stream->notify_work); + +return ret; +} + +static int hsw_process_notification (struct sst_hsw *hsw) +{ +struct sst_dsp *sst = hsw->dsp; +u32 type, header; +int handled =1 ; + + header =sst_dsp_shim_read_unlocked (sst,SST_IPCD ); + type =msg_get_global_type (header); + +trace_ipc_request ("processing -->" , header); + +/* FW Ready is a special case */ +if (!hsw->boot_complete && header &IPC_FW_READY ) { +hsw_fw_ready (hsw, header); +return handled; + } + +switch (type) { +case IPC_GLB_GET_FW_VERSION : +case IPC_GLB_ALLOCATE_STREAM : +case IPC_GLB_FREE_STREAM : +case IPC_GLB_GET_FW_CAPABILITIES : +case IPC_GLB_REQUEST_DUMP : +case IPC_GLB_GET_DEVICE_FORMATS : +case IPC_GLB_SET_DEVICE_FORMATS : +case IPC_GLB_ENTER_DX_STATE : +case IPC_GLB_GET_MIXER_STREAM_INFO : +case IPC_GLB_MAX_IPC_MESSAGE_TYPE : +case IPC_GLB_RESTORE_CONTEXT : +case IPC_GLB_SHORT_REPLY : +dev_err (hsw->dev,"error: message type %d header 0x%x\n" , + type, header); +break ; +case IPC_GLB_STREAM_MESSAGE : + handled =hsw_stream_message (hsw, header); +break ; +case IPC_GLB_DEBUG_LOG_MESSAGE : + handled =hsw_log_message (hsw, header); +break ; +default : +dev_err (hsw->dev,"error: unexpected type %d hdr 0x%8.8x\n" , + type, header); +break ; + } + +return handled; +} + +static irqreturn_t hsw_irq_thread (int irq,void *context) +{ +struct sst_dsp *sst = (struct sst_dsp *) context; +struct sst_hsw *hsw =sst_dsp_get_thread_context (sst); +u32 ipcx, ipcd; +int handled; +unsigned long flags; + +spin_lock_irqsave (&sst->spinlock, flags); + + ipcx =sst_dsp_ipc_msg_rx (hsw->dsp); + ipcd =sst_dsp_shim_read_unlocked (sst,SST_IPCD ); + +/* reply message from DSP */ +if (ipcx &SST_IPCX_DONE ) { + +/* Handle Immediate reply from DSP Core */ + handled =hsw_process_reply (hsw, ipcx); + +if (handled) { +/* clear DONE bit - tell DSP we have completed */ +sst_dsp_shim_update_bits_unlocked (sst,SST_IPCX , +SST_IPCX_DONE ,0 ); + +/* unmask Done interrupt */ +sst_dsp_shim_update_bits_unlocked (sst,SST_IMRX , +SST_IMRX_DONE ,0 ); + } + } + +/* new message from DSP */ +if (ipcd &SST_IPCD_BUSY ) { + +/* Handle Notification and Delayed reply from DSP Core */ + handled =hsw_process_notification (hsw); + +/* clear BUSY bit and set DONE bit - accept new messages */ +if (handled) { +sst_dsp_shim_update_bits_unlocked (sst,SST_IPCD , +SST_IPCD_BUSY |SST_IPCD_DONE ,SST_IPCD_DONE ); + +/* unmask busy interrupt */ +sst_dsp_shim_update_bits_unlocked (sst,SST_IMRX , +SST_IMRX_BUSY ,0 ); + } + } + +spin_unlock_irqrestore (&sst->spinlock, flags); + +/* continue to send any remaining messages... */ +queue_kthread_work (&hsw->kworker, &hsw->kwork); + +return IRQ_HANDLED ; +} + +int sst_hsw_fw_get_version (struct sst_hsw *hsw, +struct sst_hsw_ipc_fw_version *version) +{ +int ret; + + ret =ipc_tx_message_wait (hsw,IPC_GLB_TYPE (IPC_GLB_GET_FW_VERSION ), +NULL ,0 , version,sizeof (*version)); +if (ret <0 ) +dev_err (hsw->dev,"error: get version failed\n" ); + +return ret; +} + +/* Mixer Controls */ +int sst_hsw_stream_mute (struct sst_hsw *hsw,struct sst_hsw_stream *stream, +u32 stage_id,u32 channel) +{ +int ret; + + ret =sst_hsw_stream_get_volume (hsw, stream, stage_id, channel, + &stream->mute_volume[channel]); +if (ret <0 ) +return ret; + + ret =sst_hsw_stream_set_volume (hsw, stream, stage_id, channel,0 ); +if (ret <0 ) { +dev_err (hsw->dev,"error: can't unmute stream %d channel %d\n" , + stream->reply.stream_hw_id, channel); +return ret; + } + + stream->mute[channel] =1 ; +return 0 ; +} + +int sst_hsw_stream_unmute (struct sst_hsw *hsw,struct sst_hsw_stream *stream, +u32 stage_id,u32 channel) + +{ +int ret; + + stream->mute[channel] =0 ; + ret =sst_hsw_stream_set_volume (hsw, stream, stage_id, channel, + stream->mute_volume[channel]); +if (ret <0 ) { +dev_err (hsw->dev,"error: can't unmute stream %d channel %d\n" , + stream->reply.stream_hw_id, channel); +return ret; + } + +return 0 ; +} + +int sst_hsw_stream_get_volume (struct sst_hsw *hsw,struct sst_hsw_stream *stream, +u32 stage_id,u32 channel,u32 *volume) +{ +if (channel >1 ) +return -EINVAL ; + +sst_dsp_read (hsw->dsp, volume, + stream->reply.volume_register_address[channel],sizeof (volume)); + +return 0 ; +} + +int sst_hsw_stream_set_volume_curve (struct sst_hsw *hsw, +struct sst_hsw_stream *stream,u64 curve_duration, +enum sst_hsw_volume_curve curve) +{ +/* curve duration in steps of 100ns */ + stream->vol_req.curve_duration = curve_duration; + stream->vol_req.curve_type = curve; + +return 0 ; +} + +/* stream volume */ +int sst_hsw_stream_set_volume (struct sst_hsw *hsw, +struct sst_hsw_stream *stream,u32 stage_id,u32 channel,u32 volume) +{ +struct sst_hsw_ipc_volume_req *req; +u32 header; +int ret; + +trace_ipc_request ("set stream volume" , stream->reply.stream_hw_id); + +if (channel >1 ) +return -EINVAL ; + +if (stream->mute[channel]) { + stream->mute_volume[channel] = volume; +return 0 ; + } + + header =IPC_GLB_TYPE (IPC_GLB_STREAM_MESSAGE ) | +IPC_STR_TYPE (IPC_STR_STAGE_MESSAGE ); + header |= (stream->reply.stream_hw_id <<IPC_STR_ID_SHIFT ); + header |= (IPC_STG_SET_VOLUME <<IPC_STG_TYPE_SHIFT ); + header |= (stage_id <<IPC_STG_ID_SHIFT ); + + req = &stream->vol_req; + req->channel = channel; + req->target_volume = volume; + + ret =ipc_tx_message_wait (hsw, header, req,sizeof (*req),NULL ,0 ); +if (ret <0 ) { +dev_err (hsw->dev,"error: set stream volume failed\n" ); +return ret; + } + +return 0 ; +} + +int sst_hsw_mixer_mute (struct sst_hsw *hsw,u32 stage_id,u32 channel) +{ +int ret; + + ret =sst_hsw_mixer_get_volume (hsw, stage_id, channel, + &hsw->mute_volume[channel]); +if (ret <0 ) +return ret; + + ret =sst_hsw_mixer_set_volume (hsw, stage_id, channel,0 ); +if (ret <0 ) { +dev_err (hsw->dev,"error: failed to unmute mixer channel %d\n" , + channel); +return ret; + } + + hsw->mute[channel] =1 ; +return 0 ; +} + +int sst_hsw_mixer_unmute (struct sst_hsw *hsw,u32 stage_id,u32 channel) +{ +int ret; + + ret =sst_hsw_mixer_set_volume (hsw, stage_id, channel, + hsw->mixer_info.volume_register_address[channel]); +if (ret <0 ) { +dev_err (hsw->dev,"error: failed to unmute mixer channel %d\n" , + channel); +return ret; + } + + hsw->mute[channel] =0 ; +return 0 ; +} + +int sst_hsw_mixer_get_volume (struct sst_hsw *hsw,u32 stage_id,u32 channel, +u32 *volume) +{ +if (channel >1 ) +return -EINVAL ; + +sst_dsp_read (hsw->dsp, volume, + hsw->mixer_info.volume_register_address[channel], +sizeof (*volume)); + +return 0 ; +} + +int sst_hsw_mixer_set_volume_curve (struct sst_hsw *hsw, +u64 curve_duration,enum sst_hsw_volume_curve curve) +{ +/* curve duration in steps of 100ns */ + hsw->curve_duration = curve_duration; + hsw->curve_type = curve; + +return 0 ; +} + +/* global mixer volume */ +int sst_hsw_mixer_set_volume (struct sst_hsw *hsw,u32 stage_id,u32 channel, +u32 volume) +{ +struct sst_hsw_ipc_volume_req req; +u32 header; +int ret; + +trace_ipc_request ("set mixer volume" , volume); + +/* set both at same time ? */ +if (channel ==2 ) { +if (hsw->mute[0 ] && hsw->mute[1 ]) { + hsw->mute_volume[0 ] = hsw->mute_volume[1 ] = volume; +return 0 ; + }else if (hsw->mute[0 ]) + req.channel =1 ; +else if (hsw->mute[1 ]) + req.channel =0 ; +else + req.channel =0xffffffff ; + }else { +/* set only 1 channel */ +if (hsw->mute[channel]) { + hsw->mute_volume[channel] = volume; +return 0 ; + } + req.channel = channel; + } + + header =IPC_GLB_TYPE (IPC_GLB_STREAM_MESSAGE ) | +IPC_STR_TYPE (IPC_STR_STAGE_MESSAGE ); + header |= (hsw->mixer_info.mixer_hw_id <<IPC_STR_ID_SHIFT ); + header |= (IPC_STG_SET_VOLUME <<IPC_STG_TYPE_SHIFT ); + header |= (stage_id <<IPC_STG_ID_SHIFT ); + + req.curve_duration = hsw->curve_duration; + req.curve_type = hsw->curve_type; + req.target_volume = volume; + + ret =ipc_tx_message_wait (hsw, header, &req,sizeof (req),NULL ,0 ); +if (ret <0 ) { +dev_err (hsw->dev,"error: set mixer volume failed\n" ); +return ret; + } + +return 0 ; +} + +/* Stream API */ +struct sst_hsw_stream *sst_hsw_stream_new (struct sst_hsw *hsw,int id, +u32 (*notify_position)(struct sst_hsw_stream *stream,void *data), +void *data) +{ +struct sst_hsw_stream *stream; + + stream =kzalloc (sizeof (*stream),GFP_KERNEL ); +if (stream ==NULL ) +return NULL ; + +list_add (&stream->node, &hsw->stream_list); + stream->notify_position = notify_position; + stream->pdata = data; + stream->hsw = hsw; + stream->host_id = id; + +/* work to process notification messages */ +INIT_WORK (&stream->notify_work, hsw_notification_work); + +return stream; +} + +int sst_hsw_stream_free (struct sst_hsw *hsw,struct sst_hsw_stream *stream) +{ +u32 header; +int ret =0 ; + +/* dont free DSP streams that are not commited */ +if (!stream->commited) + goto out; + +trace_ipc_request ("stream free" , stream->host_id); + + stream->free_req.stream_id = stream->reply.stream_hw_id; + header =IPC_GLB_TYPE (IPC_GLB_FREE_STREAM ); + + ret =ipc_tx_message_wait (hsw, header, &stream->free_req, +sizeof (stream->free_req),NULL ,0 ); +if (ret <0 ) { +dev_err (hsw->dev,"error: free stream %d failed\n" , + stream->free_req.stream_id); +return -EAGAIN ; + } + +trace_hsw_stream_free_req (stream, &stream->free_req); + +out: +list_del (&stream->node); +kfree (stream); + +return ret; +} + +int sst_hsw_stream_set_bits (struct sst_hsw *hsw, +struct sst_hsw_stream *stream,enum sst_hsw_bitdepth bits) +{ +if (stream->commited) { +dev_err (hsw->dev,"error: stream committed for set bits\n" ); +return -EINVAL ; + } + + stream->request.format.bitdepth = bits; +return 0 ; +} + +int sst_hsw_stream_set_channels (struct sst_hsw *hsw, +struct sst_hsw_stream *stream,int channels) +{ +if (stream->commited) { +dev_err (hsw->dev,"error: stream committed for set channels\n" ); +return -EINVAL ; + } + +/* stereo is only supported atm */ +if (channels !=2 ) +return -EINVAL ; + + stream->request.format.ch_num = channels; +return 0 ; +} + +int sst_hsw_stream_set_rate (struct sst_hsw *hsw, +struct sst_hsw_stream *stream,int rate) +{ +if (stream->commited) { +dev_err (hsw->dev,"error: stream committed for set rate\n" ); +return -EINVAL ; + } + + stream->request.format.frequency = rate; +return 0 ; +} + +int sst_hsw_stream_set_map_config (struct sst_hsw *hsw, +struct sst_hsw_stream *stream,u32 map, +enum sst_hsw_channel_config config) +{ +if (stream->commited) { +dev_err (hsw->dev,"error: stream committed for set map\n" ); +return -EINVAL ; + } + + stream->request.format.map = map; + stream->request.format.config = config; +return 0 ; +} + +int sst_hsw_stream_set_style (struct sst_hsw *hsw, +struct sst_hsw_stream *stream,enum sst_hsw_interleaving style) +{ +if (stream->commited) { +dev_err (hsw->dev,"error: stream committed for set style\n" ); +return -EINVAL ; + } + + stream->request.format.style = style; +return 0 ; +} + +int sst_hsw_stream_set_valid (struct sst_hsw *hsw, +struct sst_hsw_stream *stream,u32 bits) +{ +if (stream->commited) { +dev_err (hsw->dev,"error: stream committed for set valid bits\n" ); +return -EINVAL ; + } + + stream->request.format.valid_bit = bits; +return 0 ; +} + +/* Stream Configuration */ +int sst_hsw_stream_format (struct sst_hsw *hsw,struct sst_hsw_stream *stream, +enum sst_hsw_stream_path_id path_id, +enum sst_hsw_stream_type stream_type, +enum sst_hsw_stream_format format_id) +{ +if (stream->commited) { +dev_err (hsw->dev,"error: stream committed for set format\n" ); +return -EINVAL ; + } + + stream->request.path_id = path_id; + stream->request.stream_type = stream_type; + stream->request.format_id = format_id; + +trace_hsw_stream_alloc_request (stream, &stream->request); + +return 0 ; +} + +int sst_hsw_stream_buffer (struct sst_hsw *hsw,struct sst_hsw_stream *stream, +u32 ring_pt_address,u32 num_pages, +u32 ring_size,u32 ring_offset,u32 ring_first_pfn) +{ +if (stream->commited) { +dev_err (hsw->dev,"error: stream committed for buffer\n" ); +return -EINVAL ; + } + + stream->request.ringinfo.ring_pt_address = ring_pt_address; + stream->request.ringinfo.num_pages = num_pages; + stream->request.ringinfo.ring_size = ring_size; + stream->request.ringinfo.ring_offset = ring_offset; + stream->request.ringinfo.ring_first_pfn = ring_first_pfn; + +trace_hsw_stream_buffer (stream); + +return 0 ; +} + +int sst_hsw_stream_set_module_info (struct sst_hsw *hsw, +struct sst_hsw_stream *stream,enum sst_hsw_module_id module_id, +u32 entry_point) +{ +struct sst_hsw_module_map *map = &stream->request.map; + +if (stream->commited) { +dev_err (hsw->dev,"error: stream committed for set module\n" ); +return -EINVAL ; + } + +/* only support initial module atm */ + map->module_entries_count =1 ; + map->module_entries[0 ].module_id = module_id; + map->module_entries[0 ].entry_point = entry_point; + +return 0 ; +} + +int sst_hsw_stream_set_pmemory_info (struct sst_hsw *hsw, +struct sst_hsw_stream *stream,u32 offset,u32 size) +{ +if (stream->commited) { +dev_err (hsw->dev,"error: stream committed for set pmem\n" ); +return -EINVAL ; + } + + stream->request.persistent_mem.offset = offset; + stream->request.persistent_mem.size = size; + +return 0 ; +} + +int sst_hsw_stream_set_smemory_info (struct sst_hsw *hsw, +struct sst_hsw_stream *stream,u32 offset,u32 size) +{ +if (stream->commited) { +dev_err (hsw->dev,"error: stream committed for set smem\n" ); +return -EINVAL ; + } + + stream->request.scratch_mem.offset = offset; + stream->request.scratch_mem.size = size; + +return 0 ; +} + +int sst_hsw_stream_commit (struct sst_hsw *hsw,struct sst_hsw_stream *stream) +{ +struct sst_hsw_ipc_stream_alloc_req *str_req = &stream->request; +struct sst_hsw_ipc_stream_alloc_reply *reply = &stream->reply; +u32 header; +int ret; + +trace_ipc_request ("stream alloc" , stream->host_id); + + header =IPC_GLB_TYPE (IPC_GLB_ALLOCATE_STREAM ); + + ret =ipc_tx_message_wait (hsw, header, str_req,sizeof (*str_req), + reply,sizeof (*reply)); +if (ret <0 ) { +dev_err (hsw->dev,"error: stream commit failed\n" ); +return ret; + } + + stream->commited =1 ; +trace_hsw_stream_alloc_reply (stream); + +return 0 ; +} + +/* Stream Information - these calls could be inline but we want the IPC +ABI to be opaque to client PCM drivers to cope with any future ABI changes */ +int sst_hsw_stream_get_hw_id (struct sst_hsw *hsw, +struct sst_hsw_stream *stream) +{ +return stream->reply.stream_hw_id; +} + +int sst_hsw_stream_get_mixer_id (struct sst_hsw *hsw, +struct sst_hsw_stream *stream) +{ +return stream->reply.mixer_hw_id; +} + +u32 sst_hsw_stream_get_read_reg (struct sst_hsw *hsw, +struct sst_hsw_stream *stream) +{ +return stream->reply.read_position_register_address; +} + +u32 sst_hsw_stream_get_pointer_reg (struct sst_hsw *hsw, +struct sst_hsw_stream *stream) +{ +return stream->reply.presentation_position_register_address; +} + +u32 sst_hsw_stream_get_peak_reg (struct sst_hsw *hsw, +struct sst_hsw_stream *stream,u32 channel) +{ +if (channel >=2 ) +return 0 ; + +return stream->reply.peak_meter_register_address[channel]; +} + +u32 sst_hsw_stream_get_vol_reg (struct sst_hsw *hsw, +struct sst_hsw_stream *stream,u32 channel) +{ +if (channel >=2 ) +return 0 ; + +return stream->reply.volume_register_address[channel]; +} + +int sst_hsw_mixer_get_info (struct sst_hsw *hsw) +{ +struct sst_hsw_ipc_stream_info_reply *reply; +u32 header; +int ret; + + reply = &hsw->mixer_info; + header =IPC_GLB_TYPE (IPC_GLB_GET_MIXER_STREAM_INFO ); + +trace_ipc_request ("get global mixer info" ,0 ); + + ret =ipc_tx_message_wait (hsw, header,NULL ,0 , reply,sizeof (*reply)); +if (ret <0 ) { +dev_err (hsw->dev,"error: get stream info failed\n" ); +return ret; + } + +trace_hsw_mixer_info_reply (reply); + +return 0 ; +} + +/* Send stream command */ +static int sst_hsw_stream_operations (struct sst_hsw *hsw,int type, +int stream_id,int wait) +{ +u32 header; + + header =IPC_GLB_TYPE (IPC_GLB_STREAM_MESSAGE ) |IPC_STR_TYPE (type); + header |= (stream_id <<IPC_STR_ID_SHIFT ); + +if (wait) +return ipc_tx_message_wait (hsw, header,NULL ,0 ,NULL ,0 ); +else +return ipc_tx_message_nowait (hsw, header,NULL ,0 ); +} + +/* Stream ALSA trigger operations */ +int sst_hsw_stream_pause (struct sst_hsw *hsw,struct sst_hsw_stream *stream, +int wait) +{ +int ret; + +trace_ipc_request ("stream pause" , stream->reply.stream_hw_id); + + ret =sst_hsw_stream_operations (hsw,IPC_STR_PAUSE , + stream->reply.stream_hw_id, wait); +if (ret <0 ) +dev_err (hsw->dev,"error: failed to pause stream %d\n" , + stream->reply.stream_hw_id); + +return ret; +} + +int sst_hsw_stream_resume (struct sst_hsw *hsw,struct sst_hsw_stream *stream, +int wait) +{ +int ret; + +trace_ipc_request ("stream resume" , stream->reply.stream_hw_id); + + ret =sst_hsw_stream_operations (hsw,IPC_STR_RESUME , + stream->reply.stream_hw_id, wait); +if (ret <0 ) +dev_err (hsw->dev,"error: failed to resume stream %d\n" , + stream->reply.stream_hw_id); + +return ret; +} + +int sst_hsw_stream_reset (struct sst_hsw *hsw,struct sst_hsw_stream *stream) +{ +int ret, tries =10 ; + +/* dont reset streams that are not commited */ +if (!stream->commited) +return 0 ; + +/* wait for pause to complete before we reset the stream */ +while (stream->running && tries--) +msleep (1 ); +if (!tries) { +dev_err (hsw->dev,"error: reset stream %d still running\n" , + stream->reply.stream_hw_id); +return -EINVAL ; + } + +trace_ipc_request ("stream reset" , stream->reply.stream_hw_id); + + ret =sst_hsw_stream_operations (hsw,IPC_STR_RESET , + stream->reply.stream_hw_id,1 ); +if (ret <0 ) +dev_err (hsw->dev,"error: failed to reset stream %d\n" , + stream->reply.stream_hw_id); +return ret; +} + +/* Stream pointer positions */ +int sst_hsw_get_dsp_position (struct sst_hsw *hsw, +struct sst_hsw_stream *stream) +{ +return stream->rpos.position; +} + +int sst_hsw_stream_set_write_position (struct sst_hsw *hsw, +struct sst_hsw_stream *stream,u32 stage_id,u32 position) +{ +u32 header; +int ret; + +trace_stream_write_position (stream->reply.stream_hw_id, position); + + header =IPC_GLB_TYPE (IPC_GLB_STREAM_MESSAGE ) | +IPC_STR_TYPE (IPC_STR_STAGE_MESSAGE ); + header |= (stream->reply.stream_hw_id <<IPC_STR_ID_SHIFT ); + header |= (IPC_STG_SET_WRITE_POSITION <<IPC_STG_TYPE_SHIFT ); + header |= (stage_id <<IPC_STG_ID_SHIFT ); + stream->wpos.position = position; + + ret =ipc_tx_message_nowait (hsw, header, &stream->wpos, +sizeof (stream->wpos)); +if (ret <0 ) +dev_err (hsw->dev,"error: stream %d set position %d failed\n" , + stream->reply.stream_hw_id, position); + +return ret; +} + +/* physical BE config */ +int sst_hsw_device_set_config (struct sst_hsw *hsw, +enum sst_hsw_device_id dev,enum sst_hsw_device_mclk mclk, +enum sst_hsw_device_mode mode,u32 clock_divider) +{ +struct sst_hsw_ipc_device_config_req config; +u32 header; +int ret; + +trace_ipc_request ("set device config" , dev); + + config.ssp_interface = dev; + config.clock_frequency = mclk; + config.mode = mode; + config.clock_divider = clock_divider; + +trace_hsw_device_config_req (&config); + + header =IPC_GLB_TYPE (IPC_GLB_SET_DEVICE_FORMATS ); + + ret =ipc_tx_message_wait (hsw, header, &config,sizeof (config), +NULL ,0 ); +if (ret <0 ) +dev_err (hsw->dev,"error: set device formats failed\n" ); + +return ret; +} +EXPORT_SYMBOL_GPL (sst_hsw_device_set_config); + +/* DX Config */ +int sst_hsw_dx_set_state (struct sst_hsw *hsw, +enum sst_hsw_dx_state state,struct sst_hsw_ipc_dx_reply *dx) +{ +u32 header, state_; +int ret; + + header =IPC_GLB_TYPE (IPC_GLB_ENTER_DX_STATE ); + state_ = state; + +trace_ipc_request ("PM enter Dx state" , state); + + ret =ipc_tx_message_wait (hsw, header, &state_,sizeof (state_), + dx,sizeof (dx)); +if (ret <0 ) { +dev_err (hsw->dev,"ipc: error set dx state %d failed\n" , state); +return ret; + } + +dev_dbg (hsw->dev,"ipc: got %d entry numbers for state %d\n" , + dx->entries_no, state); + +memcpy (&hsw->dx, dx,sizeof (*dx)); +return 0 ; +} + +/* Used to save state into hsw->dx_reply */ +int sst_hsw_dx_get_state (struct sst_hsw *hsw,u32 item, +u32 *offset,u32 *size,u32 *source) +{ +struct sst_hsw_ipc_dx_memory_item *dx_mem; +struct sst_hsw_ipc_dx_reply *dx_reply; +int entry_no; + + dx_reply = &hsw->dx; + entry_no = dx_reply->entries_no; + +trace_ipc_request ("PM get Dx state" , entry_no); + +if (item >= entry_no) +return -EINVAL ; + + dx_mem = &dx_reply->mem_info[item]; + *offset = dx_mem->offset; + *size = dx_mem->size; + *source = dx_mem->source; + +return 0 ; +} + +static int msg_empty_list_init (struct sst_hsw *hsw) +{ +int i; + + hsw->msg =kzalloc (sizeof (struct ipc_message ) * +IPC_EMPTY_LIST_SIZE ,GFP_KERNEL ); +if (hsw->msg ==NULL ) +return -ENOMEM ; + +for (i =0 ; i <IPC_EMPTY_LIST_SIZE ; i++) { +init_waitqueue_head (&hsw->msg[i].waitq); +list_add (&hsw->msg[i].list, &hsw->empty_list); + } + +return 0 ; +} + +void sst_hsw_set_scratch_module (struct sst_hsw *hsw, +struct sst_module *scratch) +{ + hsw->scratch = scratch; +} + +struct sst_dsp *sst_hsw_get_dsp (struct sst_hsw *hsw) +{ +return hsw->dsp; +} + +static struct sst_dsp_device hsw_dev = { + .thread = hsw_irq_thread, + .ops = &haswell_ops, +}; + +int sst_hsw_dsp_init (struct device *dev,struct sst_pdata *pdata) +{ +struct sst_hsw_ipc_fw_version version; +struct sst_hsw *hsw; +struct sst_fw *hsw_sst_fw; +int ret; + +dev_dbg (dev,"initialising Audio DSP IPC\n" ); + + hsw =devm_kzalloc (dev,sizeof (*hsw),GFP_KERNEL ); +if (hsw ==NULL ) +return -ENOMEM ; + + hsw->dev = dev; +INIT_LIST_HEAD (&hsw->stream_list); +INIT_LIST_HEAD (&hsw->tx_list); +INIT_LIST_HEAD (&hsw->rx_list); +INIT_LIST_HEAD (&hsw->empty_list); +init_waitqueue_head (&hsw->boot_wait); +init_waitqueue_head (&hsw->wait_txq); + + ret =msg_empty_list_init (hsw); +if (ret <0 ) + goto list_err; + +/* start the IPC message thread */ +init_kthread_worker (&hsw->kworker); + hsw->tx_thread =kthread_run (kthread_worker_fn, + &hsw->kworker, +dev_name (hsw->dev)); +if (IS_ERR (hsw->tx_thread)) { + ret =PTR_ERR (hsw->tx_thread); +dev_err (hsw->dev,"error: failed to create message TX task\n" ); + goto list_err; + } +init_kthread_work (&hsw->kwork, ipc_tx_msgs); + + hsw_dev.thread_context = hsw; + +/* init SST shim */ + hsw->dsp =sst_dsp_new (dev, &hsw_dev, pdata); +if (hsw->dsp ==NULL ) { + ret = -ENODEV ; + goto list_err; + } + +/* keep the DSP in reset state for base FW loading */ +sst_dsp_reset (hsw->dsp); + + hsw_sst_fw =sst_fw_new (hsw->dsp, pdata->fw, hsw); + +if (hsw_sst_fw ==NULL ) { + ret = -ENODEV ; +dev_err (dev,"error: failed to load firmware\n" ); + goto fw_err; + } + +/* wait for DSP boot completion */ +sst_dsp_boot (hsw->dsp); + ret =wait_event_timeout (hsw->boot_wait, hsw->boot_complete, +msecs_to_jiffies (IPC_BOOT_MSECS )); +if (ret ==0 ) { + ret = -EIO ; +dev_err (hsw->dev,"error: ADSP boot timeout\n" ); + goto boot_err; + } + +/* get the FW version */ +sst_hsw_fw_get_version (hsw, &version); +dev_info (hsw->dev,"FW loaded: type %d - version: %d.%d build %d\n" , + version.type, version.major, version.minor, version.build); + +/* get the globalmixer */ + ret =sst_hsw_mixer_get_info (hsw); +if (ret <0 ) { +dev_err (hsw->dev,"error: failed to get stream info\n" ); + goto boot_err; + } + + pdata->dsp = hsw; +return 0 ; + +boot_err: +sst_dsp_reset (hsw->dsp); +sst_fw_free (hsw_sst_fw); +fw_err: +sst_dsp_free (hsw->dsp); +kfree (hsw->msg); +list_err: +return ret; +} +EXPORT_SYMBOL_GPL (sst_hsw_dsp_init); + +void sst_hsw_dsp_free (struct device *dev,struct sst_pdata *pdata) +{ +struct sst_hsw *hsw = pdata->dsp; + +sst_dsp_reset (hsw->dsp); +sst_fw_free_all (hsw->dsp); +sst_dsp_free (hsw->dsp); +kfree (hsw->scratch); +kfree (hsw->msg); +} +EXPORT_SYMBOL_GPL (sst_hsw_dsp_free);
sound/soc/intel/sst-haswell-ipc.h new file +488 -0
488 lines not on this page · raw message
Signature · 1 line
1.8.3.2
Re: [PATCH 2/6] ASoC: Intel: Add Haswell/Broadwell IPC
Quoted 2 lines · Liam Girdwood
Add support for Haswell and Broadwell DSP IPC. This is used by the DSP platform PCM driver to configure the DSP for audio operations.
Applied, thanks.
Liam Girdwood
maintainerPATCH 3/6 ASoC: Intel: Add Haswell and Broadwell PCM platform driver
In reply to Liam GirdwoodAdd the Haswell and Broadwell PCM DSP platform driver. This driver uses the IPC driver for communication with the SST DSP.
--- sound/soc/intel/sst-haswell-pcm.c | 872 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 872 insertions(+) create mode 100644 sound/soc/intel/sst-haswell-pcm.c
sound/soc/intel/sst-haswell-pcm.c new file +872 -0
@@ -0,0 +1,872 @@ +/* +* Intel SST Haswell/Broadwell PCM Support +* +* Copyright (C) 2013, Intel Corporation. All rights reserved. +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License version +* 2 as published by the Free Software Foundation. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +*/ + +#include <linux/module.h> +#include <linux/dma-mapping.h> +#include <linux/slab.h> +#include <linux/module.h> +#include <linux/delay.h> +#include <asm/page.h> +#include <asm/pgtable.h> +#include <sound/core.h> +#include <sound/pcm.h> +#include <sound/pcm_params.h> +#include <sound/dmaengine_pcm.h> +#include <sound/soc.h> +#include <sound/tlv.h> +#include <sound/compress_driver.h> + +#include "sst-haswell-ipc.h" +#include "sst-dsp-priv.h" +#include "sst-dsp.h" + +#define HSW_PCM_COUNT 6 +#define HSW_VOLUME_MAX 0x7FFFFFFF/* 0dB */ + +/* simple volume table */ +static const u32 volume_map[] = { +HSW_VOLUME_MAX >>30 , +HSW_VOLUME_MAX >>29 , +HSW_VOLUME_MAX >>28 , +HSW_VOLUME_MAX >>27 , +HSW_VOLUME_MAX >>26 , +HSW_VOLUME_MAX >>25 , +HSW_VOLUME_MAX >>24 , +HSW_VOLUME_MAX >>23 , +HSW_VOLUME_MAX >>22 , +HSW_VOLUME_MAX >>21 , +HSW_VOLUME_MAX >>20 , +HSW_VOLUME_MAX >>19 , +HSW_VOLUME_MAX >>18 , +HSW_VOLUME_MAX >>17 , +HSW_VOLUME_MAX >>16 , +HSW_VOLUME_MAX >>15 , +HSW_VOLUME_MAX >>14 , +HSW_VOLUME_MAX >>13 , +HSW_VOLUME_MAX >>12 , +HSW_VOLUME_MAX >>11 , +HSW_VOLUME_MAX >>10 , +HSW_VOLUME_MAX >>9 , +HSW_VOLUME_MAX >>8 , +HSW_VOLUME_MAX >>7 , +HSW_VOLUME_MAX >>6 , +HSW_VOLUME_MAX >>5 , +HSW_VOLUME_MAX >>4 , +HSW_VOLUME_MAX >>3 , +HSW_VOLUME_MAX >>2 , +HSW_VOLUME_MAX >>1 , +HSW_VOLUME_MAX >>0 , +}; + +#define HSW_PCM_PERIODS_MAX 64 +#define HSW_PCM_PERIODS_MIN 2 + +static const struct snd_pcm_hardware hsw_pcm_hardware = { + .info =SNDRV_PCM_INFO_MMAP | +SNDRV_PCM_INFO_MMAP_VALID | +SNDRV_PCM_INFO_INTERLEAVED | +SNDRV_PCM_INFO_PAUSE | +SNDRV_PCM_INFO_RESUME | +SNDRV_PCM_INFO_NO_PERIOD_WAKEUP , + .formats =SNDRV_PCM_FMTBIT_S16_LE |SNDRV_PCM_FORMAT_S24_LE | +SNDRV_PCM_FMTBIT_S32_LE , + .period_bytes_min =PAGE_SIZE , + .period_bytes_max = (HSW_PCM_PERIODS_MAX /HSW_PCM_PERIODS_MIN ) *PAGE_SIZE , + .periods_min =HSW_PCM_PERIODS_MIN , + .periods_max =HSW_PCM_PERIODS_MAX , + .buffer_bytes_max =HSW_PCM_PERIODS_MAX *PAGE_SIZE , +}; + +/* private data for each PCM DSP stream */ +struct hsw_pcm_data { +int dai_id; +struct sst_hsw_stream *stream; +u32 volume[2 ]; +struct snd_pcm_substream *substream; +struct snd_compr_stream *cstream; +unsigned int wpos; +struct mutex mutex; +}; + +/* private data for the driver */ +struct hsw_priv_data { +/* runtime DSP */ +struct sst_hsw *hsw; + +/* page tables */ +unsigned char *pcm_pg[HSW_PCM_COUNT ][2 ]; + +/* DAI data */ +struct hsw_pcm_data pcm[HSW_PCM_COUNT ]; +}; + +static inline u32 hsw_mixer_to_ipc (unsigned int value) +{ +if (value >=ARRAY_SIZE (volume_map)) +return volume_map[0 ]; +else +return volume_map[value]; +} + +static inline unsigned int hsw_ipc_to_mixer (u32 value) +{ +int i; + +for (i =0 ; i <ARRAY_SIZE (volume_map); i++) { +if (volume_map[i] >= value) +return i; + } + +return i -1 ; +} + +static int hsw_stream_volume_put (struct snd_kcontrol *kcontrol, +struct snd_ctl_elem_value *ucontrol) +{ +struct snd_soc_platform *platform =snd_kcontrol_chip (kcontrol); +struct soc_mixer_control *mc = + (struct soc_mixer_control *)kcontrol->private_value; +struct hsw_priv_data *pdata = +snd_soc_platform_get_drvdata (platform); +struct hsw_pcm_data *pcm_data = &pdata->pcm[mc->reg]; +struct sst_hsw *hsw = pdata->hsw; +u32 volume; + +mutex_lock (&pcm_data->mutex); + +if (!pcm_data->stream) { + pcm_data->volume[0 ] = +hsw_mixer_to_ipc (ucontrol->value.integer.value[0 ]); + pcm_data->volume[1 ] = +hsw_mixer_to_ipc (ucontrol->value.integer.value[1 ]); +mutex_unlock (&pcm_data->mutex); +return 0 ; + } + +if (ucontrol->value.integer.value[0 ] == + ucontrol->value.integer.value[1 ]) { + volume =hsw_mixer_to_ipc (ucontrol->value.integer.value[0 ]); +sst_hsw_stream_set_volume (hsw, pcm_data->stream,0 ,2 , volume); + }else { + volume =hsw_mixer_to_ipc (ucontrol->value.integer.value[0 ]); +sst_hsw_stream_set_volume (hsw, pcm_data->stream,0 ,0 , volume); + volume =hsw_mixer_to_ipc (ucontrol->value.integer.value[1 ]); +sst_hsw_stream_set_volume (hsw, pcm_data->stream,0 ,1 , volume); + } + +mutex_unlock (&pcm_data->mutex); +return 0 ; +} + +static int hsw_stream_volume_get (struct snd_kcontrol *kcontrol, +struct snd_ctl_elem_value *ucontrol) +{ +struct snd_soc_platform *platform =snd_kcontrol_chip (kcontrol); +struct soc_mixer_control *mc = + (struct soc_mixer_control *)kcontrol->private_value; +struct hsw_priv_data *pdata = +snd_soc_platform_get_drvdata (platform); +struct hsw_pcm_data *pcm_data = &pdata->pcm[mc->reg]; +struct sst_hsw *hsw = pdata->hsw; +u32 volume; + +mutex_lock (&pcm_data->mutex); + +if (!pcm_data->stream) { + ucontrol->value.integer.value[0 ] = +hsw_ipc_to_mixer (pcm_data->volume[0 ]); + ucontrol->value.integer.value[1 ] = +hsw_ipc_to_mixer (pcm_data->volume[1 ]); +mutex_unlock (&pcm_data->mutex); +return 0 ; + } + +sst_hsw_stream_get_volume (hsw, pcm_data->stream,0 ,0 , &volume); + ucontrol->value.integer.value[0 ] =hsw_ipc_to_mixer (volume); +sst_hsw_stream_get_volume (hsw, pcm_data->stream,0 ,1 , &volume); + ucontrol->value.integer.value[1 ] =hsw_ipc_to_mixer (volume); +mutex_unlock (&pcm_data->mutex); + +return 0 ; +} + +static int hsw_volume_put (struct snd_kcontrol *kcontrol, +struct snd_ctl_elem_value *ucontrol) +{ +struct snd_soc_platform *platform =snd_kcontrol_chip (kcontrol); +struct hsw_priv_data *pdata =snd_soc_platform_get_drvdata (platform); +struct sst_hsw *hsw = pdata->hsw; +u32 volume; + +if (ucontrol->value.integer.value[0 ] == + ucontrol->value.integer.value[1 ]) { + + volume =hsw_mixer_to_ipc (ucontrol->value.integer.value[0 ]); +sst_hsw_mixer_set_volume (hsw,0 ,2 , volume); + + }else { + volume =hsw_mixer_to_ipc (ucontrol->value.integer.value[0 ]); +sst_hsw_mixer_set_volume (hsw,0 ,0 , volume); + + volume =hsw_mixer_to_ipc (ucontrol->value.integer.value[1 ]); +sst_hsw_mixer_set_volume (hsw,0 ,1 , volume); + } + +return 0 ; +} + +static int hsw_volume_get (struct snd_kcontrol *kcontrol, +struct snd_ctl_elem_value *ucontrol) +{ +struct snd_soc_platform *platform =snd_kcontrol_chip (kcontrol); +struct hsw_priv_data *pdata =snd_soc_platform_get_drvdata (platform); +struct sst_hsw *hsw = pdata->hsw; +unsigned int volume =0 ; + +sst_hsw_mixer_get_volume (hsw,0 ,0 , &volume); + ucontrol->value.integer.value[0 ] =hsw_ipc_to_mixer (volume); + +sst_hsw_mixer_get_volume (hsw,0 ,1 , &volume); + ucontrol->value.integer.value[1 ] =hsw_ipc_to_mixer (volume); + +return 0 ; +} + +/* TLV used by both global and stream volumes */ +static const DECLARE_TLV_DB_SCALE(hsw_vol_tlv, -9000, 300, 1); + +/* System Pin has no volume control */ +static const struct snd_kcontrol_new hsw_volume_controls[] = { +/* Global DSP volume */ +SOC_DOUBLE_EXT_TLV ("Master Playback Volume" ,0 ,0 ,8 , +ARRAY_SIZE (volume_map) -1 ,0 , + hsw_volume_get, hsw_volume_put, hsw_vol_tlv), +/* Offload 0 volume */ +SOC_DOUBLE_EXT_TLV ("Media0 Playback Volume" ,1 ,0 ,8 , +ARRAY_SIZE (volume_map),0 , + hsw_stream_volume_get, hsw_stream_volume_put, hsw_vol_tlv), +/* Offload 1 volume */ +SOC_DOUBLE_EXT_TLV ("Media1 Playback Volume" ,2 ,0 ,8 , +ARRAY_SIZE (volume_map),0 , + hsw_stream_volume_get, hsw_stream_volume_put, hsw_vol_tlv), +/* Loopback volume */ +SOC_DOUBLE_EXT_TLV ("Loopback Capture Volume" ,3 ,0 ,8 , +ARRAY_SIZE (volume_map),0 , + hsw_stream_volume_get, hsw_stream_volume_put, hsw_vol_tlv), +/* Mic Capture volume */ +SOC_DOUBLE_EXT_TLV ("Mic Capture Volume" ,4 ,0 ,8 , +ARRAY_SIZE (volume_map),0 , + hsw_stream_volume_get, hsw_stream_volume_put, hsw_vol_tlv), +}; + +/* Create DMA buffer page table for DSP */ +static int create_adsp_page_table (struct hsw_priv_data *pdata, +struct snd_soc_pcm_runtime *rtd, +unsigned char *dma_area,size_t size,int pcm,int stream) +{ +int i, pages; + +if (size %PAGE_SIZE ) + pages = (size /PAGE_SIZE ) +1 ; +else + pages = size /PAGE_SIZE ; + +dev_dbg (rtd->dev,"generating page table for %p size 0x%zu pages %d\n" , + dma_area, size, pages); + +for (i =0 ; i < pages; i++) { +u32 idx = (((i <<2 ) + i)) >>1 ; +u32 pfn = (virt_to_phys (dma_area + i *PAGE_SIZE )) >>PAGE_SHIFT ; +u32 *pg_table; + +dev_dbg (rtd->dev,"pfn i %i idx %d pfn %x\n" , i, idx, pfn); + + pg_table = (u32 *)(pdata->pcm_pg[pcm][stream] + idx); + +if (i &1 ) + *pg_table |= (pfn <<4 ); +else + *pg_table |= pfn; + } + +return 0 ; +} + +/* this may get called several times by oss emulation */ +static int hsw_pcm_hw_params (struct snd_pcm_substream *substream, +struct snd_pcm_hw_params *params) +{ +struct snd_soc_pcm_runtime *rtd = substream->private_data; +struct snd_pcm_runtime *runtime = substream->runtime; +struct hsw_priv_data *pdata = +snd_soc_platform_get_drvdata (rtd->platform); +struct hsw_pcm_data *pcm_data =snd_soc_pcm_get_drvdata (rtd); +struct sst_hsw *hsw = pdata->hsw; +struct sst_module *module_data; +struct sst_dsp *dsp; +enum sst_hsw_stream_type stream_type; +enum sst_hsw_stream_path_id path_id; +u32 rate, bits, map, pages, module_id; +u8 channels; +int ret; + +/* stream direction */ +if (substream->stream ==SNDRV_PCM_STREAM_PLAYBACK ) + path_id =SST_HSW_STREAM_PATH_SSP0_OUT ; +else + path_id =SST_HSW_STREAM_PATH_SSP0_IN ; + +/* DSP stream type depends on DAI ID */ +switch (rtd->cpu_dai->id) { +case 0 : + stream_type =SST_HSW_STREAM_TYPE_SYSTEM ; + module_id =SST_HSW_MODULE_PCM_SYSTEM ; +break ; +case 1 : +case 2 : + stream_type =SST_HSW_STREAM_TYPE_RENDER ; + module_id =SST_HSW_MODULE_PCM ; +break ; +case 3 : +/* path ID needs to be OUT for loopback */ + stream_type =SST_HSW_STREAM_TYPE_LOOPBACK ; + path_id =SST_HSW_STREAM_PATH_SSP0_OUT ; + module_id =SST_HSW_MODULE_PCM_REFERENCE ; +break ; +case 4 : + stream_type =SST_HSW_STREAM_TYPE_CAPTURE ; + module_id =SST_HSW_MODULE_PCM_CAPTURE ; +break ; +default : +dev_err (rtd->dev,"error: invalid DAI ID %d\n" , + rtd->cpu_dai->id); +return -EINVAL ; + }; + + ret =sst_hsw_stream_format (hsw, pcm_data->stream, + path_id, stream_type,SST_HSW_STREAM_FORMAT_PCM_FORMAT ); +if (ret <0 ) { +dev_err (rtd->dev,"error: failed to set format %d\n" , ret); +return ret; + } + + rate =params_rate (params); + ret =sst_hsw_stream_set_rate (hsw, pcm_data->stream, rate); +if (ret <0 ) { +dev_err (rtd->dev,"error: could not set rate %d\n" , rate); +return ret; + } + +switch (params_format (params)) { +case SNDRV_PCM_FORMAT_S16_LE : + bits =SST_HSW_DEPTH_16BIT ; +sst_hsw_stream_set_valid (hsw, pcm_data->stream,16 ); +break ; +case SNDRV_PCM_FORMAT_S24_LE : + bits =SST_HSW_DEPTH_24BIT ; +sst_hsw_stream_set_valid (hsw, pcm_data->stream,32 ); +break ; +default : +dev_err (rtd->dev,"error: invalid format %d\n" , +params_format (params)); +return -EINVAL ; + } + + ret =sst_hsw_stream_set_bits (hsw, pcm_data->stream, bits); +if (ret <0 ) { +dev_err (rtd->dev,"error: could not set bits %d\n" , bits); +return ret; + } + +/* we only support stereo atm */ + channels =params_channels (params); +if (channels !=2 ) { +dev_err (rtd->dev,"error: invalid channels %d\n" , channels); +return -EINVAL ; + } + + map =create_channel_map (SST_HSW_CHANNEL_CONFIG_STEREO ); +sst_hsw_stream_set_map_config (hsw, pcm_data->stream, + map,SST_HSW_CHANNEL_CONFIG_STEREO ); + + ret =sst_hsw_stream_set_channels (hsw, pcm_data->stream, channels); +if (ret <0 ) { +dev_err (rtd->dev,"error: could not set channels %d\n" , + channels); +return ret; + } + + ret =snd_pcm_lib_malloc_pages (substream,params_buffer_bytes (params)); +if (ret <0 ) { +dev_err (rtd->dev,"error: could not allocate %d bytes for PCM %d\n" , +params_buffer_bytes (params), ret); +return ret; + } + + ret =create_adsp_page_table (pdata, rtd, runtime->dma_area, + runtime->dma_bytes, rtd->cpu_dai->id, substream->stream); +if (ret <0 ) +return ret; + +sst_hsw_stream_set_style (hsw, pcm_data->stream, +SST_HSW_INTERLEAVING_PER_CHANNEL ); + +if (runtime->dma_bytes %PAGE_SIZE ) + pages = (runtime->dma_bytes /PAGE_SIZE ) +1 ; +else + pages = runtime->dma_bytes /PAGE_SIZE ; + + ret =sst_hsw_stream_buffer (hsw, pcm_data->stream, +virt_to_phys (pdata->pcm_pg[rtd->cpu_dai->id][substream->stream]), + pages, runtime->dma_bytes,0 , + (u32)(virt_to_phys (runtime->dma_area) >>PAGE_SHIFT )); +if (ret <0 ) { +dev_err (rtd->dev,"error: failed to set DMA buffer %d\n" , ret); +return ret; + } + + dsp =sst_hsw_get_dsp (hsw); + + module_data =sst_module_get_from_id (dsp, module_id); +if (module_data ==NULL ) { +dev_err (rtd->dev,"error: failed to get module config\n" ); +return -EINVAL ; + } + +/* we use hardcoded memory offsets atm, will be updated for new FW */ +if (stream_type ==SST_HSW_STREAM_TYPE_CAPTURE ) { +sst_hsw_stream_set_module_info (hsw, pcm_data->stream, +SST_HSW_MODULE_PCM_CAPTURE , module_data->entry); +sst_hsw_stream_set_pmemory_info (hsw, pcm_data->stream, +0x449400 ,0x4000 ); +sst_hsw_stream_set_smemory_info (hsw, pcm_data->stream, +0x400000 ,0 ); + }else {/* stream_type == SST_HSW_STREAM_TYPE_SYSTEM */ +sst_hsw_stream_set_module_info (hsw, pcm_data->stream, +SST_HSW_MODULE_PCM_SYSTEM , module_data->entry); + +sst_hsw_stream_set_pmemory_info (hsw, pcm_data->stream, + module_data->offset, module_data->size); +sst_hsw_stream_set_pmemory_info (hsw, pcm_data->stream, +0x44d400 ,0x3800 ); + +sst_hsw_stream_set_smemory_info (hsw, pcm_data->stream, + module_data->offset, module_data->size); +sst_hsw_stream_set_smemory_info (hsw, pcm_data->stream, +0x400000 ,0 ); + } + + ret =sst_hsw_stream_commit (hsw, pcm_data->stream); +if (ret <0 ) { +dev_err (rtd->dev,"error: failed to commit stream %d\n" , ret); +return ret; + } + + ret =sst_hsw_stream_pause (hsw, pcm_data->stream,1 ); +if (ret <0 ) +dev_err (rtd->dev,"error: failed to pause %d\n" , ret); + +return 0 ; +} + +static int hsw_pcm_hw_free (struct snd_pcm_substream *substream) +{ +snd_pcm_lib_free_pages (substream); +return 0 ; +} + +static int hsw_pcm_trigger (struct snd_pcm_substream *substream,int cmd) +{ +struct snd_soc_pcm_runtime *rtd = substream->private_data; +struct hsw_priv_data *pdata = +snd_soc_platform_get_drvdata (rtd->platform); +struct hsw_pcm_data *pcm_data =snd_soc_pcm_get_drvdata (rtd); +struct sst_hsw *hsw = pdata->hsw; + +switch (cmd) { +case SNDRV_PCM_TRIGGER_START : +case SNDRV_PCM_TRIGGER_RESUME : +case SNDRV_PCM_TRIGGER_PAUSE_RELEASE : +sst_hsw_stream_resume (hsw, pcm_data->stream,0 ); +break ; +case SNDRV_PCM_TRIGGER_STOP : +case SNDRV_PCM_TRIGGER_SUSPEND : +case SNDRV_PCM_TRIGGER_PAUSE_PUSH : +sst_hsw_stream_pause (hsw, pcm_data->stream,0 ); +break ; +default : +break ; + } + +return 0 ; +} + +static u32 hsw_notify_pointer (struct sst_hsw_stream *stream,void *data) +{ +struct hsw_pcm_data *pcm_data = data; +struct snd_pcm_substream *substream = pcm_data->substream; +struct snd_pcm_runtime *runtime = substream->runtime; +struct snd_soc_pcm_runtime *rtd = substream->private_data; +u32 pos; + + pos =frames_to_bytes (runtime, + (runtime->control->appl_ptr % runtime->buffer_size)); + +dev_dbg (rtd->dev,"PCM: App pointer %d bytes\n" , pos); + +/* let alsa know we have play a period */ +snd_pcm_period_elapsed (substream); +return pos; +} + +static snd_pcm_uframes_t hsw_pcm_pointer (struct snd_pcm_substream *substream) +{ +struct snd_soc_pcm_runtime *rtd = substream->private_data; +struct snd_pcm_runtime *runtime = substream->runtime; +struct hsw_priv_data *pdata = +snd_soc_platform_get_drvdata (rtd->platform); +struct hsw_pcm_data *pcm_data =snd_soc_pcm_get_drvdata (rtd); +struct sst_hsw *hsw = pdata->hsw; +snd_pcm_uframes_t offset; + + offset =bytes_to_frames (runtime, +sst_hsw_get_dsp_position (hsw, pcm_data->stream)); + +dev_dbg (rtd->dev,"PCM: DMA pointer %zu bytes\n" , +frames_to_bytes (runtime, (u32 )offset)); +return offset; +} + +static int hsw_pcm_open (struct snd_pcm_substream *substream) +{ +struct snd_soc_pcm_runtime *rtd = substream->private_data; +struct hsw_priv_data *pdata = +snd_soc_platform_get_drvdata (rtd->platform); +struct hsw_pcm_data *pcm_data; +struct sst_hsw *hsw = pdata->hsw; + + pcm_data = &pdata->pcm[rtd->cpu_dai->id]; + +mutex_lock (&pcm_data->mutex); + +snd_soc_pcm_set_drvdata (rtd, pcm_data); + pcm_data->substream = substream; + +snd_soc_set_runtime_hwparams (substream, &hsw_pcm_hardware); + + pcm_data->stream =sst_hsw_stream_new (hsw, rtd->cpu_dai->id, + hsw_notify_pointer, pcm_data); +if (pcm_data->stream ==NULL ) { +dev_err (rtd->dev,"error: failed to create stream\n" ); +mutex_unlock (&pcm_data->mutex); +return -EINVAL ; + } + +/* Set previous saved volume */ +sst_hsw_stream_set_volume (hsw, pcm_data->stream,0 , +0 , pcm_data->volume[0 ]); +sst_hsw_stream_set_volume (hsw, pcm_data->stream,0 , +1 , pcm_data->volume[1 ]); + +mutex_unlock (&pcm_data->mutex); +return 0 ; +} + +static int hsw_pcm_close (struct snd_pcm_substream *substream) +{ +struct snd_soc_pcm_runtime *rtd = substream->private_data; +struct hsw_priv_data *pdata = +snd_soc_platform_get_drvdata (rtd->platform); +struct hsw_pcm_data *pcm_data =snd_soc_pcm_get_drvdata (rtd); +struct sst_hsw *hsw = pdata->hsw; +int ret; + +mutex_lock (&pcm_data->mutex); + ret =sst_hsw_stream_reset (hsw, pcm_data->stream); +if (ret <0 ) { +dev_dbg (rtd->dev,"error: reset stream failed %d\n" , ret); + goto out; + } + + ret =sst_hsw_stream_free (hsw, pcm_data->stream); +if (ret <0 ) { +dev_dbg (rtd->dev,"error: free stream failed %d\n" , ret); + goto out; + } + pcm_data->stream =NULL ; + +out: +mutex_unlock (&pcm_data->mutex); +return ret; +} + +static struct snd_pcm_ops hsw_pcm_ops = { + .open = hsw_pcm_open, + .close = hsw_pcm_close, + .ioctl = snd_pcm_lib_ioctl, + .hw_params = hsw_pcm_hw_params, + .hw_free = hsw_pcm_hw_free, + .trigger = hsw_pcm_trigger, + .pointer = hsw_pcm_pointer, + .mmap = snd_pcm_lib_default_mmap, +}; + +static void hsw_pcm_free (struct snd_pcm *pcm) +{ +snd_pcm_lib_preallocate_free_for_all (pcm); +} + +static int hsw_pcm_new (struct snd_soc_pcm_runtime *rtd) +{ +struct snd_pcm *pcm = rtd->pcm; +int ret =0 ; + + ret =dma_coerce_mask_and_coherent (rtd->card->dev,DMA_BIT_MASK (32 )); +if (ret) +return ret; + +if (pcm->streams[SNDRV_PCM_STREAM_PLAYBACK ].substream || + pcm->streams[SNDRV_PCM_STREAM_CAPTURE ].substream) { + ret =snd_pcm_lib_preallocate_pages_for_all (pcm, +SNDRV_DMA_TYPE_DEV , + rtd->card->dev, + hsw_pcm_hardware.buffer_bytes_max, + hsw_pcm_hardware.buffer_bytes_max); +if (ret) { +dev_err (rtd->dev,"dma buffer allocation failed %d\n" , + ret); +return ret; + } + } + +return ret; +} + +#define HSW_FORMATS \ + (SNDRV_PCM_FMTBIT_S20_3LE | SNDRV_PCM_FMTBIT_S16_LE |\ + SNDRV_PCM_FMTBIT_S32_LE) + +static struct snd_soc_dai_driver hsw_dais[] = { + { + .name ="System Pin" , + .playback = { + .stream_name ="System Playback" , + .channels_min =2 , + .channels_max =2 , + .rates =SNDRV_PCM_RATE_48000 , + .formats =SNDRV_PCM_FMTBIT_S16_LE , + }, + }, + { +/* PCM */ + .name ="Offload0 Pin" , + .playback = { + .stream_name ="Offload0 Playback" , + .channels_min =2 , + .channels_max =2 , + .rates =SNDRV_PCM_RATE_8000_192000 , + .formats =HSW_FORMATS , + }, + }, + { +/* PCM */ + .name ="Offload1 Pin" , + .playback = { + .stream_name ="Offload1 Playback" , + .channels_min =2 , + .channels_max =2 , + .rates =SNDRV_PCM_RATE_8000_192000 , + .formats =HSW_FORMATS , + }, + }, + { + .name ="Loopback Pin" , + .capture = { + .stream_name ="Loopback Capture" , + .channels_min =2 , + .channels_max =2 , + .rates =SNDRV_PCM_RATE_8000_192000 , + .formats =HSW_FORMATS , + }, + }, + { + .name ="Capture Pin" , + .capture = { + .stream_name ="Analog Capture" , + .channels_min =2 , + .channels_max =2 , + .rates =SNDRV_PCM_RATE_8000_192000 , + .formats =HSW_FORMATS , + }, + }, +}; + +static const struct snd_soc_dapm_widget widgets[] = { + +/* Backend DAIs */ +SND_SOC_DAPM_AIF_IN ("SSP0 CODEC IN" ,NULL ,0 ,SND_SOC_NOPM ,0 ,0 ), +SND_SOC_DAPM_AIF_OUT ("SSP0 CODEC OUT" ,NULL ,0 ,SND_SOC_NOPM ,0 ,0 ), +SND_SOC_DAPM_AIF_IN ("SSP1 BT IN" ,NULL ,0 ,SND_SOC_NOPM ,0 ,0 ), +SND_SOC_DAPM_AIF_OUT ("SSP1 BT OUT" ,NULL ,0 ,SND_SOC_NOPM ,0 ,0 ), + +/* Global Playback Mixer */ +SND_SOC_DAPM_MIXER ("Playback VMixer" ,SND_SOC_NOPM ,0 ,0 ,NULL ,0 ), +}; + +static const struct snd_soc_dapm_route graph[] = { + +/* Playback Mixer */ + {"Playback VMixer" ,NULL ,"System Playback" }, + {"Playback VMixer" ,NULL ,"Offload0 Playback" }, + {"Playback VMixer" ,NULL ,"Offload1 Playback" }, + + {"SSP0 CODEC OUT" ,NULL ,"Playback VMixer" }, + + {"Analog Capture" ,NULL ,"SSP0 CODEC IN" }, +}; + +static int hsw_pcm_probe (struct snd_soc_platform *platform) +{ +struct sst_pdata *pdata =dev_get_platdata (platform->dev); +struct hsw_priv_data *priv_data; +int i; + +if (!pdata) +return -ENODEV ; + + priv_data =devm_kzalloc (platform->dev,sizeof (*priv_data),GFP_KERNEL ); + priv_data->hsw = pdata->dsp; +snd_soc_platform_set_drvdata (platform, priv_data); + +/* allocate DSP buffer page tables */ +for (i =0 ; i <ARRAY_SIZE (hsw_dais); i++) { + +mutex_init (&priv_data->pcm[i].mutex); + +/* playback */ +if (hsw_dais[i].playback.channels_min) { + priv_data->pcm_pg[i][0 ] =kzalloc (PAGE_SIZE ,GFP_DMA ); +if (priv_data->pcm_pg[i][0 ] ==NULL ) + goto err; + } + +/* capture */ +if (hsw_dais[i].capture.channels_min) { + priv_data->pcm_pg[i][1 ] =kzalloc (PAGE_SIZE ,GFP_DMA ); +if (priv_data->pcm_pg[i][1 ] ==NULL ) + goto err; + } + } + +return 0 ; + +err: +for (;i >=0 ; i--) { +if (hsw_dais[i].playback.channels_min) +kfree (priv_data->pcm_pg[i][0 ]); +if (hsw_dais[i].capture.channels_min) +kfree (priv_data->pcm_pg[i][1 ]); + } +return -ENOMEM ; +} + +static int hsw_pcm_remove (struct snd_soc_platform *platform) +{ +struct hsw_priv_data *priv_data = +snd_soc_platform_get_drvdata (platform); +int i; + +for (i =0 ; i <ARRAY_SIZE (hsw_dais); i++) { +if (hsw_dais[i].playback.channels_min) +kfree (priv_data->pcm_pg[i][0 ]); +if (hsw_dais[i].capture.channels_min) +kfree (priv_data->pcm_pg[i][1 ]); + } + +return 0 ; +} + +static struct snd_soc_platform_driver hsw_soc_platform = { + .probe = hsw_pcm_probe, + .remove = hsw_pcm_remove, + .ops = &hsw_pcm_ops, + .pcm_new = hsw_pcm_new, + .pcm_free = hsw_pcm_free, + .controls = hsw_volume_controls, + .num_controls =ARRAY_SIZE (hsw_volume_controls), + .dapm_widgets = widgets, + .num_dapm_widgets =ARRAY_SIZE (widgets), + .dapm_routes = graph, + .num_dapm_routes =ARRAY_SIZE (graph), +}; + +static const struct snd_soc_component_driver hsw_dai_component = { + .name ="haswell-dai" , +}; + +static int hsw_pcm_dev_probe (struct platform_device *pdev) +{ +struct sst_pdata *sst_pdata =dev_get_platdata (&pdev->dev); +int ret; + + ret =sst_hsw_dsp_init (&pdev->dev, sst_pdata); +if (ret <0 ) +return -ENODEV ; + + ret =snd_soc_register_platform (&pdev->dev, &hsw_soc_platform); +if (ret <0 ) + goto err_plat; + + ret =snd_soc_register_component (&pdev->dev, &hsw_dai_component, + hsw_dais,ARRAY_SIZE (hsw_dais)); +if (ret <0 ) + goto err_comp; + +return 0 ; + +err_comp: +snd_soc_unregister_platform (&pdev->dev); +err_plat: +sst_hsw_dsp_free (&pdev->dev, sst_pdata); +return 0 ; +} + +static int hsw_pcm_dev_remove (struct platform_device *pdev) +{ +struct sst_pdata *sst_pdata =dev_get_platdata (&pdev->dev); + +snd_soc_unregister_platform (&pdev->dev); +snd_soc_unregister_component (&pdev->dev); +sst_hsw_dsp_free (&pdev->dev, sst_pdata); + +return 0 ; +} + +static struct platform_driver hsw_pcm_driver = { + .driver = { + .name ="haswell-pcm-audio" , + .owner =THIS_MODULE , + }, + + .probe = hsw_pcm_dev_probe, + .remove = hsw_pcm_dev_remove, +}; +module_platform_driver (hsw_pcm_driver); + +MODULE_AUTHOR ("Liam Girdwood, Xingchao Wang" ); +MODULE_DESCRIPTION ("Haswell/Lynxpoint + Broadwell/Wildcatpoint PCM" ); +MODULE_LICENSE ("GPL v2" ); +MODULE_ALIAS ("platform:haswell-pcm-audio" );
Signature · 1 line
1.8.3.2
Re: [PATCH 3/6] ASoC: Intel: Add Haswell and Broadwell PCM platform driver
On Thu, Feb 20, 2014 at 09:48:44PM +0000, Liam Girdwood wrote:
Applied, thanks. Again a few comments below.
sound/soc/intel/sst-haswell-pcm.c line 41
Quoted 3 lines
sound/soc/intel/sst-haswell-pcm.c new file +3
-0+/* simple volume table */ +static const u32 volume_map[] = { +HSW_VOLUME_MAX >>30 ,
Interesting one here. On the one hand we always say to present the hardware features as directly as possible to the application layer. On the other hand I'd not be surprised if some userspaces failed to deal constructively with a full 31 bits of linearly mapped volume control (but I'm not sure how common they are and really they ought to be fixed). Anyway, not a problem more just a comment.
sound/soc/intel/sst-haswell-pcm.c line 157
Quoted 8 lines
sound/soc/intel/sst-haswell-pcm.c new file +8
-0+if (!pcm_data->stream) { + pcm_data->volume[0 ] = +hsw_mixer_to_ipc (ucontrol->value.integer.value[0 ]); + pcm_data->volume[1 ] = +hsw_mixer_to_ipc (ucontrol->value.integer.value[1 ]); +mutex_unlock (&pcm_data->mutex); +return 0 ; + }
It looks like we only record the volume when the stream is idle. What happens if the user changes the volume while it's idle, starts playing, changes again then stops playing? It's possible I missed the bit where it gets saved but I did look.
Quoted 4 lines
sound/soc/intel/sst-haswell-pcm.c new file +4
-0+if (!pcm_data->stream) { + ucontrol->value.integer.value[0 ] = +hsw_ipc_to_mixer (pcm_data->volume[0 ]); + ucontrol->value.integer.value[1] =
sound/soc/intel/sst-haswell-pcm.c line 201
Quoted 10 lines
sound/soc/intel/sst-haswell-pcm.c new file +10
-0+hsw_ipc_to_mixer (pcm_data->volume[1 ]); +mutex_unlock (&pcm_data->mutex); +return 0 ; + } + +sst_hsw_stream_get_volume (hsw, pcm_data->stream,0 ,0 , &volume); + ucontrol->value.integer.value[0 ] =hsw_ipc_to_mixer (volume); +sst_hsw_stream_get_volume (hsw, pcm_data->stream,0 ,1 , &volume); + ucontrol->value.integer.value[1 ] =hsw_ipc_to_mixer (volume); +mutex_unlock (&pcm_data->mutex);
Can the DSP adjust its own volume autonomously?
sound/soc/intel/sst-haswell-pcm.c line 278
Quoted 3 lines
sound/soc/intel/sst-haswell-pcm.c new file +3
-0+static int create_adsp_page_table (struct hsw_priv_data *pdata, +struct snd_soc_pcm_runtime *rtd, +unsigned char *dma_area,size_t size,int pcm,int stream)
No helper for this?
Re: [PATCH 3/6] ASoC: Intel: Add Haswell and Broadwell PCM platform driver
At Fri, 21 Feb 2014 14:16:03 +0900,
Quoted 5 lines · Mark Brown
On Thu, Feb 20, 2014 at 09:48:44PM +0000, Liam Girdwood wrote:
Applied, thanks. Again a few comments below.
Quoted 10 lines
sound/soc/intel/sst-haswell-pcm.c line 41
Quoted 3 lines
sound/soc/intel/sst-haswell-pcm.c new file +3
-0+/* simple volume table */ +static const u32 volume_map[] = { +HSW_VOLUME_MAX >>30 ,Interesting one here. On the one hand we always say to present the hardware features as directly as possible to the application layer. On the other hand I'd not be surprised if some userspaces failed to deal constructively with a full 31 bits of linearly mapped volume control (but I'm not sure how common they are and really they ought to be fixed). Anyway, not a problem more just a comment.
A straightforward implementation would be just to expose this 31bit raw value and declare it as a linear dB via TLV. The proper dB conversion is done in alsa-lib.
But, this depends on the use case; if an expected application rather doesn't dare to think of dB value, it's another way to provide the converted mixer values in the driver. Some drivers do it, too.
BTW, you need no table for this volume value at all. volume_map[] can be replaced like
#define volume_map(i) ((1U << (i) - 1)
Quoted 14 lines
sound/soc/intel/sst-haswell-pcm.c line 157
Quoted 9 lines
sound/soc/intel/sst-haswell-pcm.c new file +8
-0+if (!pcm_data->stream) { + pcm_data->volume[0 ] = +hsw_mixer_to_ipc (ucontrol->value.integer.value[0 ]); + pcm_data->volume[1 ] = +hsw_mixer_to_ipc (ucontrol->value.integer.value[1 ]); +mutex_unlock (&pcm_data->mutex); +return 0 ; + }It looks like we only record the volume when the stream is idle. What happens if the user changes the volume while it's idle, starts playing, changes again then stops playing? It's possible I missed the bit where it gets saved but I did look.
This seems restored in hsw_pcm_open().
+static int hsw_pcm_open(struct snd_pcm_substream *substream) +{
....
+ /* Set previous saved volume */
+ sst_hsw_stream_set_volume(hsw, pcm_data->stream, 0,
+ 0, pcm_data->volume[0]);
+ sst_hsw_stream_set_volume(hsw, pcm_data->stream, 0,
+ 1, pcm_data->volume[1]);
Takashi
Mark Brown
maintainerRe: [PATCH 3/6] ASoC: Intel: Add Haswell and Broadwell PCM platform driver
Quoted 9 lines · Takashi Iwai
Quoted 6 lines · Mark Brown
Interesting one here. On the one hand we always say to present the hardware features as directly as possible to the application layer. On the other hand I'd not be surprised if some userspaces failed to deal constructively with a full 31 bits of linearly mapped volume control (but I'm not sure how common they are and really they ought to be fixed). Anyway, not a problem more just a comment.
Quoted 3 lines
A straightforward implementation would be just to expose this 31bit raw value and declare it as a linear dB via TLV. The proper dB conversion is done in alsa-lib.
Yes, exactly. This should work well with most userspaces, the only thing that would worry me would be something basic that makes the user manually step through thousands of tiny volume steps. I don't think any modern application layer should have an issue there though and I'm not sure if I'd care about such application layers myself.
Quoted 3 lines
BTW, you need no table for this volume value at all. volume_map[] can be replaced like
#define volume_map(i) ((1U << (i) - 1)
It does mean it's easier to update the chosen steps in future though.
Quoted 14 lines
Quoted 5 lines
Quoted 5 lines
sound/soc/intel/sst-haswell-pcm.c new file +5
-0+if (!pcm_data->stream) { + pcm_data->volume[0 ] = +hsw_mixer_to_ipc (ucontrol->value.integer.value[0 ]); + pcm_data->volume[1 ] = +hsw_mixer_to_ipc (ucontrol->value.integer.value[1 ]);Quoted 8 lines
sound/soc/intel/sst-haswell-pcm.c line 157
Quoted 3 lines
sound/soc/intel/sst-haswell-pcm.c new file +3
-0+mutex_unlock (&pcm_data->mutex); +return 0 ; + }It looks like we only record the volume when the stream is idle. What happens if the user changes the volume while it's idle, starts playing, changes again then stops playing? It's possible I missed the bit where it gets saved but I did look.
Quoted 1 line
This seems restored in
hsw_pcm_open().
Yes, it's restored there - what concerned me was that the variables didn't seem to be being updated while the stream was running, it only wrote to the hardware so if the volume had subsequently been changed on a running stream then the older value from a closed stream would be written out. It'd at least be more obviously correct to just update the variables no matter what.
Liam Girdwood
maintainerRe: [PATCH 3/6] ASoC: Intel: Add Haswell and Broadwell PCM platform driver
Quoted 20 lines · Mark Brown
Quoted 9 lines · Takashi Iwai
Quoted 6 lines · Mark Brown
Interesting one here. On the one hand we always say to present the hardware features as directly as possible to the application layer. On the other hand I'd not be surprised if some userspaces failed to deal constructively with a full 31 bits of linearly mapped volume control (but I'm not sure how common they are and really they ought to be fixed). Anyway, not a problem more just a comment.
Quoted 3 lines
A straightforward implementation would be just to expose this 31bit raw value and declare it as a linear dB via TLV. The proper dB conversion is done in alsa-lib.
Yes, exactly. This should work well with most userspaces, the only thing that would worry me would be something basic that makes the user manually step through thousands of tiny volume steps. I don't think any modern application layer should have an issue there though and I'm not sure if I'd care about such application layers myself.
Quoted 6 lines
Quoted 3 lines
BTW, you need no table for this volume value at all. volume_map[] can be replaced like
#define volume_map(i) ((1U << (i) - 1)It does mean it's easier to update the chosen steps in future though.
Fwiw, the table was going to be replaced with a similar table that did not have exact power of 2 values. This was just temporary until I had some more time to build the correct table.
I should get some time to add the table after BYT upstream.
Quoted 14 lines
Quoted 13 lines
Quoted 13 lines
sound/soc/intel/sst-haswell-pcm.c line 157
Quoted 8 lines
sound/soc/intel/sst-haswell-pcm.c new file +8
-0+if (!pcm_data->stream) { + pcm_data->volume[0 ] = +hsw_mixer_to_ipc (ucontrol->value.integer.value[0 ]); + pcm_data->volume[1 ] = +hsw_mixer_to_ipc (ucontrol->value.integer.value[1 ]); +mutex_unlock (&pcm_data->mutex); +return 0 ; + }It looks like we only record the volume when the stream is idle. What happens if the user changes the volume while it's idle, starts playing, changes again then stops playing? It's possible I missed the bit where it gets saved but I did look.
Quoted 8 lines
Quoted 1 line
This seems restored in
hsw_pcm_open().Yes, it's restored there - what concerned me was that the variables didn't seem to be being updated while the stream was running, it only wrote to the hardware so if the volume had subsequently been changed on a running stream then the older value from a closed stream would be written out. It'd at least be more obviously correct to just update the variables no matter what.
Will check and fix this, it may be a regression at my end.
Liam
Re: [PATCH 3/6] ASoC: Intel: Add Haswell and Broadwell PCM platform driver
In reply to Liam GirdwoodAt Thu, 20 Feb 2014 21:48:44 +0000,
sound/soc/intel/sst-haswell-pcm.c line 260
Quoted 13 lines · Liam Girdwood
sound/soc/intel/sst-haswell-pcm.c new file +13
-0+/* TLV used by both global and stream volumes */ +static const DECLARE_TLV_DB_SCALE(hsw_vol_tlv, -9000, 300, 1); + +/* System Pin has no volume control */ +static const struct snd_kcontrol_new hsw_volume_controls[] = { +/* Global DSP volume */ +SOC_DOUBLE_EXT_TLV ("Master Playback Volume" ,0 ,0 ,8 , +ARRAY_SIZE (volume_map) -1 ,0 , + hsw_volume_get, hsw_volume_put, hsw_vol_tlv), +/* Offload 0 volume */ +SOC_DOUBLE_EXT_TLV ("Media0 Playback Volume" ,1 ,0 ,8 , +ARRAY_SIZE (volume_map),0 , + hsw_stream_volume_get, hsw_stream_volume_put, hsw_vol_tlv),
Why -1 is for Master and not for others although they use the same TLV?
Quoted 8 lines
sound/soc/intel/sst-haswell-pcm.c new file +8
-0+/* Create DMA buffer page table for DSP */ +static int create_adsp_page_table (struct hsw_priv_data *pdata, +struct snd_soc_pcm_runtime *rtd, +unsigned char *dma_area,size_t size,int pcm,int stream) +{ +int i, pages; + +if (size %PAGE_SIZE )
sound/soc/intel/sst-haswell-pcm.c line 292
Quoted 10 lines
sound/soc/intel/sst-haswell-pcm.c new file +10
-0+ pages = (size /PAGE_SIZE ) +1 ; + else + pages = size /PAGE_SIZE ; + +dev_dbg (rtd->dev,"generating page table for %p size 0x%zu pages %d\n" , + dma_area, size, pages); + +for (i =0 ; i < pages; i++) { +u32 idx = (((i <<2 ) + i)) >>1 ; +u32 pfn = (virt_to_phys (dma_area + i *PAGE_SIZE )) >>PAGE_SHIFT ;
virt_to_phys() is bad, pretty unportable. And, this implementation doesn't use SG-buffer although the hardware can it obviously.
For managing SG-buffer, just use SNDRV_DMA_TPE_DEV_SG for preallocation, and change the page setup code like:
struct snd_dma_buffer *dmab = snd_pcm_get_dma_buf(substream)
....
pages = snd_sgbuf_aligned_pages(size);
for (i = 0; i < pages; i++) {
u32 idx = (((i << 2) + i)) >> 1;
u32 pfn = snd_sgbuf_get_addr(dmab, i * PAGE_SIZE) >> PAGE_SHIFT;The only other thing to change is to pass snd_pcm_sgbuf_ops_page to snd_pcm_ops.page. That's all.
Takashi
Liam Girdwood
maintainerRe: [PATCH 3/6] ASoC: Intel: Add Haswell and Broadwell PCM platform driver
Quoted 18 lines · Takashi Iwai
At Thu, 20 Feb 2014 21:48:44 +0000,
sound/soc/intel/sst-haswell-pcm.c line 260
Quoted 13 lines · Liam Girdwood
sound/soc/intel/sst-haswell-pcm.c new file +13
-0+/* TLV used by both global and stream volumes */ +static const DECLARE_TLV_DB_SCALE(hsw_vol_tlv, -9000, 300, 1); + +/* System Pin has no volume control */ +static const struct snd_kcontrol_new hsw_volume_controls[] = { +/* Global DSP volume */ +SOC_DOUBLE_EXT_TLV ("Master Playback Volume" ,0 ,0 ,8 , +ARRAY_SIZE (volume_map) -1 ,0 , + hsw_volume_get, hsw_volume_put, hsw_vol_tlv), +/* Offload 0 volume */ +SOC_DOUBLE_EXT_TLV ("Media0 Playback Volume" ,1 ,0 ,8 , +ARRAY_SIZE (volume_map),0 , + hsw_stream_volume_get, hsw_stream_volume_put, hsw_vol_tlv),Why -1 is for Master and not for others although they use the same TLV?
Iirc, one could be gain and the other attenuation. Let me double check.
Quoted 35 lines
Quoted 10 lines
sound/soc/intel/sst-haswell-pcm.c new file +8
-0+/* Create DMA buffer page table for DSP */ +static int create_adsp_page_table (struct hsw_priv_data *pdata, +struct snd_soc_pcm_runtime *rtd, +unsigned char *dma_area,size_t size,int pcm,int stream) +{ +int i, pages; + +if (size %PAGE_SIZE )sound/soc/intel/sst-haswell-pcm.c line 292
Quoted 10 lines
sound/soc/intel/sst-haswell-pcm.c new file +10
-0+ pages = (size /PAGE_SIZE ) +1 ; + else + pages = size /PAGE_SIZE ; + +dev_dbg (rtd->dev,"generating page table for %p size 0x%zu pages %d\n" , + dma_area, size, pages); + +for (i =0 ; i < pages; i++) { +u32 idx = (((i <<2 ) + i)) >>1 ; +u32 pfn = (virt_to_phys (dma_area + i *PAGE_SIZE )) >>PAGE_SHIFT ;
virt_to_phys()is bad, pretty unportable. And, this implementation doesn't use SG-buffer although the hardware can it obviously.For managing SG-buffer, just use
SNDRV_DMA_TPE_DEV_SGfor preallocation, and change the page setup code like:struct snd_dma_buffer *dmab = snd_pcm_get_dma_buf(substream) .... pages = snd_sgbuf_aligned_pages(size); for (i = 0; i < pages; i++) { u32 idx = (((i << 2) + i)) >> 1; u32 pfn = snd_sgbuf_get_addr(dmab, i * PAGE_SIZE) >> PAGE_SHIFT;
Quoted 2 lines
The only other thing to change is to pass
snd_pcm_sgbuf_ops_pageto snd_pcm_ops.page. That's all.
Thanks, I wasn't aware these helpers existed. Will fix.
Liam
Liam Girdwood
maintainerPATCH 4/6 ASoC: Intel: Add trace support for Haswell/Broadwell SST IPC messages.
In reply to Liam GirdwoodProvide a trace mechanism for debugging Haswell/Broadwell specific SST IPC messages.
--- include/trace/events/hswadsp.h | 384 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 384 insertions(+) create mode 100644 include/trace/events/hswadsp.h
include/trace/events/hswadsp.h new file +384 -0
@@ -0,0 +1,384 @@ +#undef TRACE_SYSTEM +#define TRACE_SYSTEM hswadsp + +#if !defined(_TRACE_HSWADSP_H) || defined(TRACE_HEADER_MULTI_READ ) +#define _TRACE_HSWADSP_H + +#include <linux/types.h> +#include <linux/ktime.h> +#include <linux/tracepoint.h> + +struct sst_hsw ; +struct sst_hsw_stream ; +struct sst_hsw_ipc_stream_free_req ; +struct sst_hsw_ipc_volume_req ; +struct sst_hsw_ipc_stream_alloc_req ; +struct sst_hsw_audio_data_format_ipc ; +struct sst_hsw_ipc_stream_info_reply ; +struct sst_hsw_ipc_device_config_req ; + +DECLARE_EVENT_CLASS (sst_irq, + + TP_PROTO(uint32_t status, uint32_t mask), + +TP_ARGS (status, mask), + +TP_STRUCT__entry ( + __field( unsigned int, status ) + __field( unsigned int, mask ) + ), + +TP_fast_assign ( + __entry->status = status; + __entry->mask = mask; + ), + +TP_printk ("status 0x%8.8x mask 0x%8.8x" , + (unsigned int )__entry->status, (unsigned int )__entry->mask) +); + +DEFINE_EVENT (sst_irq, sst_irq_busy, + + TP_PROTO(unsigned int status, unsigned int mask), + +TP_ARGS (status, mask) + +); + +DEFINE_EVENT (sst_irq, sst_irq_done, + + TP_PROTO(unsigned int status, unsigned int mask), + +TP_ARGS (status, mask) + +); + +DECLARE_EVENT_CLASS (ipc, + + TP_PROTO(const char *name, int val), + +TP_ARGS (name, val), + +TP_STRUCT__entry ( + __string( name, name ) + __field( unsigned int, val ) + ), + +TP_fast_assign ( + __assign_str(name, name); + __entry->val = val; + ), + +TP_printk ("%s 0x%8.8x" ,__get_str (name), (unsigned int )__entry->val) + +); + +DEFINE_EVENT (ipc, ipc_request, + + TP_PROTO(const char *name, int val), + +TP_ARGS (name, val) + +); + +DEFINE_EVENT (ipc, ipc_reply, + + TP_PROTO(const char *name, int val), + +TP_ARGS (name, val) + +); + +DEFINE_EVENT (ipc, ipc_pending_reply, + + TP_PROTO(const char *name, int val), + +TP_ARGS (name, val) + +); + +DEFINE_EVENT (ipc, ipc_notification, + + TP_PROTO(const char *name, int val), + +TP_ARGS (name, val) + +); + +DEFINE_EVENT (ipc, ipc_error, + + TP_PROTO(const char *name, int val), + +TP_ARGS (name, val) + +); + +DECLARE_EVENT_CLASS (stream_position, + + TP_PROTO(unsigned int id, unsigned int pos), + +TP_ARGS (id, pos), + +TP_STRUCT__entry ( + __field( unsigned int, id ) + __field( unsigned int, pos ) + ), + +TP_fast_assign ( + __entry->id = id; + __entry->pos = pos; + ), + +TP_printk ("id %d position 0x%x" , + (unsigned int )__entry->id, (unsigned int )__entry->pos) +); + +DEFINE_EVENT (stream_position, stream_read_position, + + TP_PROTO(unsigned int id, unsigned int pos), + +TP_ARGS (id, pos) + +); + +DEFINE_EVENT (stream_position, stream_write_position, + + TP_PROTO(unsigned int id, unsigned int pos), + +TP_ARGS (id, pos) + +); + +TRACE_EVENT (hsw_stream_buffer, + + TP_PROTO(struct sst_hsw_stream *stream), + +TP_ARGS (stream), + +TP_STRUCT__entry ( + __field( int, id ) + __field( int, pt_addr ) + __field( int, num_pages ) + __field( int, ring_size ) + __field( int, ring_offset ) +__field ( int, first_pfn ) + ), + +TP_fast_assign ( + __entry->id = stream->host_id; + __entry->pt_addr = stream->request.ringinfo.ring_pt_address; + __entry->num_pages = stream->request.ringinfo.num_pages; + __entry->ring_size = stream->request.ringinfo.ring_size; + __entry->ring_offset = stream->request.ringinfo.ring_offset; + __entry->first_pfn = stream->request.ringinfo.ring_first_pfn; + ), + +TP_printk ("stream %d ring addr 0x%x pages %d size 0x%x offset 0x%x PFN 0x%x" , + (int ) __entry->id, (int )__entry->pt_addr, + (int )__entry->num_pages, (int )__entry->ring_size, + (int )__entry->ring_offset, (int )__entry->first_pfn) +); + +TRACE_EVENT (hsw_stream_alloc_reply, + + TP_PROTO(struct sst_hsw_stream *stream), + +TP_ARGS (stream), + +TP_STRUCT__entry ( + __field( int, id ) + __field( int, stream_id ) + __field( int, mixer_id ) + __field( int, peak0 ) + __field( int, peak1 ) + __field( int, vol0 ) +__field ( int, vol1 ) + ), + +TP_fast_assign ( + __entry->id = stream->host_id; + __entry->stream_id = stream->reply.stream_hw_id; + __entry->mixer_id = stream->reply.mixer_hw_id; + __entry->peak0 = stream->reply.peak_meter_register_address[0]; + __entry->peak1 = stream->reply.peak_meter_register_address[1]; + __entry->vol0 = stream->reply.volume_register_address[0]; + __entry->vol1 = stream->reply.volume_register_address[1]; + ), + +TP_printk ("stream %d hw id %d mixer %d peak 0x%x:0x%x vol 0x%x,0x%x" , + (int ) __entry->id, (int ) __entry->stream_id, (int )__entry->mixer_id, + (int )__entry->peak0, (int )__entry->peak1, + (int )__entry->vol0, (int )__entry->vol1) +); + +TRACE_EVENT (hsw_mixer_info_reply, + + TP_PROTO(struct sst_hsw_ipc_stream_info_reply *reply), + +TP_ARGS (reply), + +TP_STRUCT__entry ( + __field( int, mixer_id ) + __field( int, peak0 ) + __field( int, peak1 ) + __field( int, vol0 ) +__field ( int, vol1 ) + ), + +TP_fast_assign ( + __entry->mixer_id = reply->mixer_hw_id; + __entry->peak0 = reply->peak_meter_register_address[0]; + __entry->peak1 = reply->peak_meter_register_address[1]; + __entry->vol0 = reply->volume_register_address[0]; + __entry->vol1 = reply->volume_register_address[1]; + ), + +TP_printk ("mixer id %d peak 0x%x:0x%x vol 0x%x,0x%x" , + (int )__entry->mixer_id, + (int )__entry->peak0, (int )__entry->peak1, + (int )__entry->vol0, (int )__entry->vol1) +); + +TRACE_EVENT (hsw_stream_data_format, + + TP_PROTO(struct sst_hsw_stream *stream, + struct sst_hsw_audio_data_format_ipc *req), + +TP_ARGS (stream, req), + +TP_STRUCT__entry ( + __field( uint32_t, id ) + __field( uint32_t, frequency ) + __field( uint32_t, bitdepth ) + __field( uint32_t, map ) + __field( uint32_t, config ) + __field( uint32_t, style ) + __field( uint8_t, ch_num ) +__field ( uint8_t, valid_bit ) + ), + +TP_fast_assign ( + __entry->id = stream->host_id; + __entry->frequency = req->frequency; + __entry->bitdepth = req->bitdepth; + __entry->map = req->map; + __entry->config = req->config; + __entry->style = req->style; + __entry->ch_num = req->ch_num; + __entry->valid_bit = req->valid_bit; + ), + +TP_printk ("stream %d freq %d depth %d map 0x%x config 0x%x style 0x%x ch %d bits %d" , + (int ) __entry->id, (uint32_t )__entry->frequency, + (uint32_t )__entry->bitdepth, (uint32_t )__entry->map, + (uint32_t )__entry->config, (uint32_t )__entry->style, + (uint8_t )__entry->ch_num, (uint8_t )__entry->valid_bit) +); + +TRACE_EVENT (hsw_stream_alloc_request, + + TP_PROTO(struct sst_hsw_stream *stream, + struct sst_hsw_ipc_stream_alloc_req *req), + +TP_ARGS (stream, req), + +TP_STRUCT__entry ( + __field( uint32_t, id ) + __field( uint8_t, path_id ) + __field( uint8_t, stream_type ) +__field ( uint8_t, format_id ) + ), + +TP_fast_assign ( + __entry->id = stream->host_id; + __entry->path_id = req->path_id; + __entry->stream_type = req->stream_type; + __entry->format_id = req->format_id; + ), + +TP_printk ("stream %d path %d type %d format %d" , + (int ) __entry->id, (uint8_t )__entry->path_id, + (uint8_t )__entry->stream_type, (uint8_t )__entry->format_id) +); + +TRACE_EVENT (hsw_stream_free_req, + + TP_PROTO(struct sst_hsw_stream *stream, + struct sst_hsw_ipc_stream_free_req *req), + +TP_ARGS (stream, req), + +TP_STRUCT__entry ( + __field( int, id ) +__field ( int, stream_id ) + ), + +TP_fast_assign ( + __entry->id = stream->host_id; + __entry->stream_id = req->stream_id; + ), + +TP_printk ("stream %d hw id %d" , + (int ) __entry->id, (int ) __entry->stream_id) +); + +TRACE_EVENT (hsw_volume_req, + + TP_PROTO(struct sst_hsw_stream *stream, + struct sst_hsw_ipc_volume_req *req), + +TP_ARGS (stream, req), + +TP_STRUCT__entry ( + __field( int, id ) + __field( uint32_t, channel ) + __field( uint32_t, target_volume ) + __field( uint64_t, curve_duration ) +__field ( uint32_t, curve_type ) + ), + +TP_fast_assign ( + __entry->id = stream->host_id; + __entry->channel = req->channel; + __entry->target_volume = req->target_volume; + __entry->curve_duration = req->curve_duration; + __entry->curve_type = req->curve_type; + ), + +TP_printk ("stream %d chan 0x%x vol %d duration %llu type %d" , + (int ) __entry->id, (uint32_t ) __entry->channel, + (uint32_t )__entry->target_volume, + (uint64_t )__entry->curve_duration, + (uint32_t )__entry->curve_type) +); + +TRACE_EVENT (hsw_device_config_req, + + TP_PROTO(struct sst_hsw_ipc_device_config_req *req), + +TP_ARGS (req), + +TP_STRUCT__entry ( + __field( uint32_t, ssp ) + __field( uint32_t, clock_freq ) + __field( uint32_t, mode ) +__field ( uint16_t, clock_divider ) + ), + +TP_fast_assign ( + __entry->ssp = req->ssp_interface; + __entry->clock_freq = req->clock_frequency; + __entry->mode = req->mode; + __entry->clock_divider = req->clock_divider; + ), + +TP_printk ("SSP %d Freq %d mode %d div %d" , + (uint32_t )__entry->ssp, + (uint32_t )__entry->clock_freq, (uint32_t )__entry->mode, + (uint32_t )__entry->clock_divider) +); + +#endif /* _TRACE_HSWADSP_H */ + +/* This part must be outside protection */ +#include <trace/define_trace.h>
Signature · 1 line
1.8.3.2
Re: [PATCH 4/6] ASoC: Intel: Add trace support for Haswell/Broadwell SST IPC messages.
Quoted 2 lines · Liam Girdwood
Provide a trace mechanism for debugging Haswell/Broadwell specific SST IPC messages.
Applied, thanks.
include/trace/events/hswadsp.h line 37
Quoted 12 lines
include/trace/events/hswadsp.h new file +12
-0+TP_STRUCT__entry ( +__field (unsigned int ,status ) + __field( unsigned int, mask ) + ), + +TP_fast_assign ( + __entry->status = status; + __entry->mask = mask; + ), + +TP_printk ("status 0x%8.8x mask 0x%8.8x" , + (unsigned int )__entry->status, (unsigned int )__entry->mask)
I found out the other day that the trace infrastructure has a neat helper called __print_symbolic which can decode things - might be helpful for some of these, though I don't think it does bitfields it might help with making the IPC messages more legible.
Liam Girdwood
maintainerRe: [PATCH 4/6] ASoC: Intel: Add trace support for Haswell/Broadwell SST IPC messages.
Quoted 15 lines · Mark Brown
Quoted 2 lines · Liam Girdwood
Provide a trace mechanism for debugging Haswell/Broadwell specific SST IPC messages.
Applied, thanks.
Quoted 9 lines
include/trace/events/hswadsp.h new file +9
-0+TP_STRUCT__entry ( +__field (unsigned int ,status ) + __field( unsigned int, mask ) + ), + +TP_fast_assign ( + __entry->status = status; + __entry->mask = mask; + ),
Quoted 8 lines
include/trace/events/hswadsp.h line 37
Quoted 3 lines
include/trace/events/hswadsp.h new file +3
-0+ +TP_printk ("status 0x%8.8x mask 0x%8.8x" , + (unsigned int )__entry->status, (unsigned int )__entry->mask)I found out the other day that the trace infrastructure has a neat helper called
__print_symbolicwhich can decode things - might be helpful for some of these, though I don't think it does bitfields it might help with making the IPC messages more legible.
Interesting, will be useful for sure. Will be worth looking at when we integrate more features in the FW (and improve the trace SNR at the same time) :)
Liam
Liam Girdwood
maintainerPATCH 5/6 ASoC: Intel: Add build support for Haswell ADSP
In reply to Liam GirdwoodBuild the Haswell/Broadwell PCM, IPC and DSP drivers.
--- sound/soc/intel/Kconfig | 2 ++ sound/soc/intel/Makefile | 6 ++++++ 2 files changed, 8 insertions(+)
sound/soc/intel/Kconfig +2 -0
@@ -24,3 +24,5 @@ config SND_SOC_INTEL_SST config SND_SOC_INTEL_SST_ACPI tristate +config SND_SOC_INTEL_HASWELL + tristate
sound/soc/intel/Makefile +6 -0
@@ -10,3 +10,9 @@ obj-$(CONFIG_SND_MFLD_MACHINE) += snd-soc-mfld-machine.o obj-$(CONFIG_SND_SOC_INTEL_SST) += snd-soc-sst-dsp.o obj-$(CONFIG_SND_SOC_INTEL_SST_ACPI) += snd-soc-sst-acpi.o + +# Platform Support +snd-soc-sst-haswell-pcm-objs := \ + sst-haswell-ipc.o sst-haswell-pcm.o sst-haswell-dsp.o + +obj-$(CONFIG_SND_SOC_INTEL_HASWELL) += snd-soc-sst-haswell-pcm.o
Signature · 1 line
1.8.3.2
Re: [PATCH 5/6] ASoC: Intel: Add build support for Haswell ADSP
Quoted 1 line · Liam Girdwood
Build the Haswell/Broadwell PCM, IPC and DSP drivers.
Applied, thanks.
Liam Girdwood
maintainerPATCH 6/6 ASoC: Intel: Add Haswell Machine support
In reply to Liam GirdwoodAdd support for Haswell based machines with SST DSP audio.
--- sound/soc/intel/Kconfig | 11 +++ sound/soc/intel/Makefile | 5 + sound/soc/intel/haswell.c | 241 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 257 insertions(+) create mode 100644 sound/soc/intel/haswell.c
sound/soc/intel/Kconfig +11 -0
@@ -26,3 +26,14 @@ config SND_SOC_INTEL_SST_ACPI config SND_SOC_INTEL_HASWELL tristate + +config SND_SOC_INTEL_HASWELL_MACH + tristate "ASoC Audio DSP support for Intel Haswell Lynxpoint" + depends on SND_SOC_INTEL_SST && X86_INTEL_LPSS + select SND_SOC_INTEL_HASWELL + select SND_SOC_RT5640 + help + This adds support for the Lynxpoint Audio DSP on Intel(R) Haswell + Ultrabook platforms. + Say Y if you have such a device + If unsure select "N".
sound/soc/intel/Makefile +5 -0
@@ -16,3 +16,8 @@ snd-soc-sst-haswell-pcm-objs := \ sst-haswell-ipc.o sst-haswell-pcm.o sst-haswell-dsp.o obj-$(CONFIG_SND_SOC_INTEL_HASWELL) += snd-soc-sst-haswell-pcm.o + +# Machine support +snd-soc-sst-haswell-objs := haswell.o + +obj-$(CONFIG_SND_SOC_INTEL_HASWELL_MACH) += snd-soc-sst-haswell.o
sound/soc/intel/haswell.c new file +241 -0
241 lines not on this page · raw message
Signature · 1 line
1.8.3.2
Re: [PATCH 6/6] ASoC: Intel: Add Haswell Machine support
Quoted 1 line · Liam Girdwood
Add support for Haswell based machines with SST DSP audio.
Applied, thanks.
sound/soc/intel/Kconfig config SND_SOC_INTEL_SST_ACPI · line 39
Quoted 10 lines
sound/soc/intel/Kconfig +10
-0+config SND_SOC_INTEL_HASWELL_MACH + tristate "ASoC Audio DSP support for Intel Haswell Lynxpoint" + depends on SND_SOC_INTEL_SST && X86_INTEL_LPSS + select SND_SOC_INTEL_HASWELL + select SND_SOC_RT5640 + help + This adds support for the Lynxpoint Audio DSP on Intel(R) Haswell + Ultrabook platforms. + Say Y if you have such a device + If unsure select "N".
Looks like there's formatting issues here again - tab/space probably.
sound/soc/intel/haswell.c line 44
Quoted 10 lines
sound/soc/intel/haswell.c new file +10
-0+static const struct snd_soc_dapm_route haswell_rt5640_map[] = { + + {"Headphones" ,NULL ,"HPOR" }, + {"Headphones" ,NULL ,"HPOL" }, + {"IN2P" ,NULL ,"Mic" }, + +/* CODEC BE connections */ + {"SSP0 CODEC IN" ,NULL ,"AIF1 Capture" }, + {"AIF1 Playback" ,NULL ,"SSP0 CODEC OUT" }, +};
A DPCM system in mainline! Yay!
Quoted 4 lines
sound/soc/intel/haswell.c new file +4
-0+static int haswell_rt5640_hw_params (struct snd_pcm_substream *substream, +struct snd_pcm_hw_params *params) +{ +struct snd_soc_pcm_runtime *rtd = substream->private_data;
sound/soc/intel/haswell.c line 78
Quoted 10 lines
sound/soc/intel/haswell.c new file +10
-0+struct snd_soc_dai *codec_dai = rtd->codec_dai; +int ret; + +/* Set codec DAI configuration */ + ret =snd_soc_dai_set_fmt (codec_dai,SND_SOC_DAIFMT_I2S | +SND_SOC_DAIFMT_NB_NF |SND_SOC_DAIFMT_CBS_CFS ); +if (ret <0 ) { +dev_err (rtd->dev,"can't set codec DAI configuration\n" ); +return ret; + }
Set .dai_fmt in the dai_link?
sound/soc/intel/haswell.c line 89
Quoted 2 lines
sound/soc/intel/haswell.c new file +2
-0+/* set correct codec filter for DAI format and clock config */ +snd_soc_update_bits (rtd->codec,0x83 ,0xffff ,0x8000 );
The CODEC driver ought to be figuring out the magic numbers for itself really.
Liam Girdwood
maintainerRe: [PATCH 6/6] ASoC: Intel: Add Haswell Machine support
Quoted 31 lines · Mark Brown
Quoted 1 line · Liam Girdwood
Add support for Haswell based machines with SST DSP audio.
Applied, thanks.
sound/soc/intel/Kconfig config SND_SOC_INTEL_SST_ACPI · line 39
Quoted 10 lines
sound/soc/intel/Kconfig +10
-0+config SND_SOC_INTEL_HASWELL_MACH + tristate "ASoC Audio DSP support for Intel Haswell Lynxpoint" + depends on SND_SOC_INTEL_SST && X86_INTEL_LPSS + select SND_SOC_INTEL_HASWELL + select SND_SOC_RT5640 + help + This adds support for the Lynxpoint Audio DSP on Intel(R) Haswell + Ultrabook platforms. + Say Y if you have such a device + If unsure select "N".Looks like there's formatting issues here again - tab/space probably.
sound/soc/intel/haswell.c line 44
Quoted 10 lines
sound/soc/intel/haswell.c new file +10
-0+static const struct snd_soc_dapm_route haswell_rt5640_map[] = { + + {"Headphones" ,NULL ,"HPOR" }, + {"Headphones" ,NULL ,"HPOL" }, + {"IN2P" ,NULL ,"Mic" }, + +/* CODEC BE connections */ + {"SSP0 CODEC IN" ,NULL ,"AIF1 Capture" }, + {"AIF1 Playback" ,NULL ,"SSP0 CODEC OUT" }, +};A DPCM system in mainline! Yay!
Quoted 16 lines
Quoted 4 lines
sound/soc/intel/haswell.c new file +4
-0+static int haswell_rt5640_hw_params (struct snd_pcm_substream *substream, +struct snd_pcm_hw_params *params) +{ +struct snd_soc_pcm_runtime *rtd = substream->private_data;sound/soc/intel/haswell.c line 78
Quoted 10 lines
sound/soc/intel/haswell.c new file +10
-0+struct snd_soc_dai *codec_dai = rtd->codec_dai; +int ret; + +/* Set codec DAI configuration */ + ret =snd_soc_dai_set_fmt (codec_dai,SND_SOC_DAIFMT_I2S | +SND_SOC_DAIFMT_NB_NF |SND_SOC_DAIFMT_CBS_CFS ); +if (ret <0 ) { +dev_err (rtd->dev,"can't set codec DAI configuration\n" ); +return ret; + }Set .dai_fmt in the
dai_link?
Will update, I think we left that so we could read the DAI fmt from ACPI in the near future. However, I do intend to read the DAI link from ACPI in the near future too, so we should construct the DAI link with DAI format from ACPI at the same time.
Quoted 6 lines
sound/soc/intel/haswell.c line 89
Quoted 3 lines
sound/soc/intel/haswell.c new file +2
-0+/* set correct codec filter for DAI format and clock config */ +snd_soc_update_bits (rtd->codec,0x83 ,0xffff ,0x8000 );The CODEC driver ought to be figuring out the magic numbers for itself really.
I was thinking of a codec public API call for the last one here. I'll chat with Bard after BYT upstreaming and see what we can come up with.
Liam
Quoted 3 lines · Liam Girdwood
Add support for low level differentiation functions for Haswell and Broadwell SST DSPs. This includes suppoprt for DSP boot and reset, DSP firmware module parsing and DSP memory block map initialisation.
Applied, thanks. Some terribly minor things below:
sound/soc/intel/sst-dsp.c line 41
Quoted 5 lines
sound/soc/intel/sst-dsp.c +5
-0+u32 sst_shim32_read (void __iomem *addr,u32 offset) +{ +return readl (addr + offset); +} +EXPORT_SYMBOL_GPL (sst_shim32_read);
This lot all look like a regmap to me, though some extensions may be needed for the 64 bit variants!
sound/soc/intel/sst-haswell-dsp.c line 507
Quoted 4 lines
sound/soc/intel/sst-haswell-dsp.c new file +4
-0+struct sst_ops haswell_ops = { + .reset = hsw_reset, + .boot = hsw_boot, + .write = sst_shim32_write,
Something appears funky with the indentation for .boot - tab/space confusion?
Hi
Quoted 5 lines · Mark Brown
Quoted 3 lines · Liam Girdwood
Add support for low level differentiation functions for Haswell and Broadwell SST DSPs. This includes suppoprt for DSP boot and reset, DSP firmware module parsing and DSP memory block map initialisation.
Applied, thanks. Some terribly minor things below:
This patch appears to be missing from the tree. Can actually create a build error after commits 5207ab6b614e ("ASoC: Intel: Add build support for Haswell ADSP") and 6edbf73e03fd ("ASoC: Intel: Add Haswell Machine support").
Signature · 1 line
Jarkko
Liam Girdwood
maintainerQuoted 4 lines · Jarkko Nikula
Hi
Quoted 1 line · Mark Brown
On Thu, Feb 20, 2014 at 09:48:42PM +0000, Liam Girdwood wrote:
Quoted 9 lines
Quoted 4 lines
Quoted 3 lines
Add support for low level differentiation functions for Haswell and Broadwell SST DSPs. This includes suppoprt for DSP boot and reset, DSP firmware module parsing and DSP memory block map initialisation.
Applied, thanks. Some terribly minor things below:
This patch appears to be missing from the tree. Can actually create a build error after commits
5207ab6b614e("ASoC: Intel: Add build support for Haswell ADSP") and6edbf73e03fd("ASoC: Intel: Add Haswell Machine support").
Just did a remote update and I can see it now :)
Liam
Liam Girdwood
maintainerQuoted 7 lines · Mark Brown
Quoted 3 lines · Liam Girdwood
Add support for low level differentiation functions for Haswell and Broadwell SST DSPs. This includes suppoprt for DSP boot and reset, DSP firmware module parsing and DSP memory block map initialisation.
Applied, thanks. Some terribly minor things below:
Sorry, been away a few days. Will get around to fixes over the next few days.
Quoted 9 lines
sound/soc/intel/sst-dsp.c line 41
Quoted 5 lines
sound/soc/intel/sst-dsp.c +5
-0+u32 sst_shim32_read (void __iomem *addr,u32 offset) +{ +return readl (addr + offset); +} +EXPORT_SYMBOL_GPL (sst_shim32_read);This lot all look like a regmap to me, though some extensions may be needed for the 64 bit variants!
The SHIM is the register space that is used to configure the DSP and also for sending IPC messages. It's really just PCI register space that has some registers shared with the DSP. IIrc, there may be 2 shared registers out of about 8 in total, but the different cores may access them differently. Iirc, Vinod has a case where they needed to write then read a value for one of his cores.
Quoted 7 lines
sound/soc/intel/sst-haswell-dsp.c line 507
Quoted 4 lines
sound/soc/intel/sst-haswell-dsp.c new file +4
-0+struct sst_ops haswell_ops = { + .reset = hsw_reset, + .boot = hsw_boot, + .write = sst_shim32_write,Something appears funky with the indentation for .boot - tab/space confusion?
oops, will fix.
Thanks !
Liam