linux/sound/soc/intel/sst/sst.h
<<
>>
Prefs
   1/*
   2 *  sst.h - Intel SST Driver for audio engine
   3 *
   4 *  Copyright (C) 2008-14 Intel Corporation
   5 *  Authors:    Vinod Koul <vinod.koul@intel.com>
   6 *              Harsha Priya <priya.harsha@intel.com>
   7 *              Dharageswari R <dharageswari.r@intel.com>
   8 *              KP Jeeja <jeeja.kp@intel.com>
   9 *  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  10 *
  11 *  This program is free software; you can redistribute it and/or modify
  12 *  it under the terms of the GNU General Public License as published by
  13 *  the Free Software Foundation; version 2 of the License.
  14 *
  15 *  This program is distributed in the hope that it will be useful, but
  16 *  WITHOUT ANY WARRANTY; without even the implied warranty of
  17 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  18 *  General Public License for more details.
  19 *
  20 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  21 *
  22 *  Common private declarations for SST
  23 */
  24#ifndef __SST_H__
  25#define __SST_H__
  26
  27#include <linux/firmware.h>
  28
  29/* driver names */
  30#define SST_DRV_NAME "intel_sst_driver"
  31#define SST_MRFLD_PCI_ID 0x119A
  32#define SST_BYT_ACPI_ID 0x80860F28
  33#define SST_CHV_ACPI_ID 0x808622A8
  34
  35#define SST_SUSPEND_DELAY 2000
  36#define FW_CONTEXT_MEM (64*1024)
  37#define SST_ICCM_BOUNDARY 4
  38#define SST_CONFIG_SSP_SIGN 0x7ffe8001
  39
  40#define MRFLD_FW_VIRTUAL_BASE 0xC0000000
  41#define MRFLD_FW_DDR_BASE_OFFSET 0x0
  42#define MRFLD_FW_FEATURE_BASE_OFFSET 0x4
  43#define MRFLD_FW_BSS_RESET_BIT 0
  44
  45extern const struct dev_pm_ops intel_sst_pm;
  46enum sst_states {
  47        SST_FW_LOADING = 1,
  48        SST_FW_RUNNING,
  49        SST_RESET,
  50        SST_SHUTDOWN,
  51};
  52
  53enum sst_algo_ops {
  54        SST_SET_ALGO = 0,
  55        SST_GET_ALGO = 1,
  56};
  57
  58#define SST_BLOCK_TIMEOUT       1000
  59
  60#define FW_SIGNATURE_SIZE       4
  61
  62/* stream states */
  63enum sst_stream_states {
  64        STREAM_UN_INIT  = 0,    /* Freed/Not used stream */
  65        STREAM_RUNNING  = 1,    /* Running */
  66        STREAM_PAUSED   = 2,    /* Paused stream */
  67        STREAM_DECODE   = 3,    /* stream is in decoding only state */
  68        STREAM_INIT     = 4,    /* stream init, waiting for data */
  69        STREAM_RESET    = 5,    /* force reset on recovery */
  70};
  71
  72enum sst_ram_type {
  73        SST_IRAM        = 1,
  74        SST_DRAM        = 2,
  75        SST_DDR = 5,
  76        SST_CUSTOM_INFO = 7,    /* consists of FW binary information */
  77};
  78
  79/* SST shim registers to structure mapping */
  80union interrupt_reg {
  81        struct {
  82                u64 done_interrupt:1;
  83                u64 busy_interrupt:1;
  84                u64 rsvd:62;
  85        } part;
  86        u64 full;
  87};
  88
  89union sst_pisr_reg {
  90        struct {
  91                u32 pssp0:1;
  92                u32 pssp1:1;
  93                u32 rsvd0:3;
  94                u32 dmac:1;
  95                u32 rsvd1:26;
  96        } part;
  97        u32 full;
  98};
  99
 100union sst_pimr_reg {
 101        struct {
 102                u32 ssp0:1;
 103                u32 ssp1:1;
 104                u32 rsvd0:3;
 105                u32 dmac:1;
 106                u32 rsvd1:10;
 107                u32 ssp0_sc:1;
 108                u32 ssp1_sc:1;
 109                u32 rsvd2:3;
 110                u32 dmac_sc:1;
 111                u32 rsvd3:10;
 112        } part;
 113        u32 full;
 114};
 115
 116union config_status_reg_mrfld {
 117        struct {
 118                u64 lpe_reset:1;
 119                u64 lpe_reset_vector:1;
 120                u64 runstall:1;
 121                u64 pwaitmode:1;
 122                u64 clk_sel:3;
 123                u64 rsvd2:1;
 124                u64 sst_clk:3;
 125                u64 xt_snoop:1;
 126                u64 rsvd3:4;
 127                u64 clk_sel1:6;
 128                u64 clk_enable:3;
 129                u64 rsvd4:6;
 130                u64 slim0baseclk:1;
 131                u64 rsvd:32;
 132        } part;
 133        u64 full;
 134};
 135
 136union interrupt_reg_mrfld {
 137        struct {
 138                u64 done_interrupt:1;
 139                u64 busy_interrupt:1;
 140                u64 rsvd:62;
 141        } part;
 142        u64 full;
 143};
 144
 145union sst_imr_reg_mrfld {
 146        struct {
 147                u64 done_interrupt:1;
 148                u64 busy_interrupt:1;
 149                u64 rsvd:62;
 150        } part;
 151        u64 full;
 152};
 153
 154/**
 155 * struct sst_block - This structure is used to block a user/fw data call to another
 156 * fw/user call
 157 *
 158 * @condition: condition for blocking check
 159 * @ret_code: ret code when block is released
 160 * @data: data ptr
 161 * @size: size of data
 162 * @on: block condition
 163 * @msg_id: msg_id = msgid in mfld/ctp, mrfld = NULL
 164 * @drv_id: str_id in mfld/ctp, = drv_id in mrfld
 165 * @node: list head node
 166 */
 167struct sst_block {
 168        bool    condition;
 169        int     ret_code;
 170        void    *data;
 171        u32     size;
 172        bool    on;
 173        u32     msg_id;
 174        u32     drv_id;
 175        struct list_head node;
 176};
 177
 178/**
 179 * struct stream_info - structure that holds the stream information
 180 *
 181 * @status : stream current state
 182 * @prev : stream prev state
 183 * @ops : stream operation pb/cp/drm...
 184 * @bufs: stream buffer list
 185 * @lock : stream mutex for protecting state
 186 * @pcm_substream : PCM substream
 187 * @period_elapsed : PCM period elapsed callback
 188 * @sfreq : stream sampling freq
 189 * @str_type : stream type
 190 * @cumm_bytes : cummulative bytes decoded
 191 * @str_type : stream type
 192 * @src : stream source
 193 */
 194struct stream_info {
 195        unsigned int            status;
 196        unsigned int            prev;
 197        unsigned int            ops;
 198        struct mutex            lock;
 199
 200        void                    *pcm_substream;
 201        void (*period_elapsed)(void *pcm_substream);
 202
 203        unsigned int            sfreq;
 204        u32                     cumm_bytes;
 205
 206        void                    *compr_cb_param;
 207        void (*compr_cb)(void *compr_cb_param);
 208
 209        void                    *drain_cb_param;
 210        void (*drain_notify)(void *drain_cb_param);
 211
 212        unsigned int            num_ch;
 213        unsigned int            pipe_id;
 214        unsigned int            str_id;
 215        unsigned int            task_id;
 216};
 217
 218#define SST_FW_SIGN "$SST"
 219#define SST_FW_LIB_SIGN "$LIB"
 220
 221/**
 222 * struct sst_fw_header - FW file headers
 223 *
 224 * @signature : FW signature
 225 * @file_size: size of fw image
 226 * @modules : # of modules
 227 * @file_format : version of header format
 228 * @reserved : reserved fields
 229 */
 230struct sst_fw_header {
 231        unsigned char signature[FW_SIGNATURE_SIZE];
 232        u32 file_size;
 233        u32 modules;
 234        u32 file_format;
 235        u32 reserved[4];
 236};
 237
 238/**
 239 * struct fw_module_header - module header in FW
 240 *
 241 * @signature: module signature
 242 * @mod_size: size of module
 243 * @blocks: block count
 244 * @type: block type
 245 * @entry_point: module netry point
 246 */
 247struct fw_module_header {
 248        unsigned char signature[FW_SIGNATURE_SIZE];
 249        u32 mod_size;
 250        u32 blocks;
 251        u32 type;
 252        u32 entry_point;
 253};
 254
 255/**
 256 * struct fw_block_info - block header for FW
 257 *
 258 * @type: block ram type I/D
 259 * @size: size of block
 260 * @ram_offset: offset in ram
 261 */
 262struct fw_block_info {
 263        enum sst_ram_type       type;
 264        u32                     size;
 265        u32                     ram_offset;
 266        u32                     rsvd;
 267};
 268
 269struct sst_runtime_param {
 270        struct snd_sst_runtime_params param;
 271};
 272
 273struct sst_sg_list {
 274        struct scatterlist *src;
 275        struct scatterlist *dst;
 276        int list_len;
 277        unsigned int sg_idx;
 278};
 279
 280struct sst_memcpy_list {
 281        struct list_head memcpylist;
 282        void *dstn;
 283        const void *src;
 284        u32 size;
 285        bool is_io;
 286};
 287
 288/*Firmware Module Information*/
 289enum sst_lib_dwnld_status {
 290        SST_LIB_NOT_FOUND = 0,
 291        SST_LIB_FOUND,
 292        SST_LIB_DOWNLOADED,
 293};
 294
 295struct sst_module_info {
 296        const char *name; /*Library name*/
 297        u32     id; /*Module ID*/
 298        u32     entry_pt; /*Module entry point*/
 299        u8      status; /*module status*/
 300        u8      rsvd1;
 301        u16     rsvd2;
 302};
 303
 304/*
 305 * Structure for managing the Library Region(1.5MB)
 306 * in DDR in Merrifield
 307 */
 308struct sst_mem_mgr {
 309        phys_addr_t current_base;
 310        int avail;
 311        unsigned int count;
 312};
 313
 314struct sst_ipc_reg {
 315        int ipcx;
 316        int ipcd;
 317};
 318
 319struct sst_shim_regs64 {
 320        u64 csr;
 321        u64 pisr;
 322        u64 pimr;
 323        u64 isrx;
 324        u64 isrd;
 325        u64 imrx;
 326        u64 imrd;
 327        u64 ipcx;
 328        u64 ipcd;
 329        u64 isrsc;
 330        u64 isrlpesc;
 331        u64 imrsc;
 332        u64 imrlpesc;
 333        u64 ipcsc;
 334        u64 ipclpesc;
 335        u64 clkctl;
 336        u64 csr2;
 337};
 338
 339/**
 340 * struct intel_sst_drv - driver ops
 341 *
 342 * @sst_state : current sst device state
 343 * @dev_id : device identifier, pci_id for pci devices and acpi_id for acpi
 344 *           devices
 345 * @shim : SST shim pointer
 346 * @mailbox : SST mailbox pointer
 347 * @iram : SST IRAM pointer
 348 * @dram : SST DRAM pointer
 349 * @pdata : SST info passed as a part of pci platform data
 350 * @shim_phy_add : SST shim phy addr
 351 * @shim_regs64: Struct to save shim registers
 352 * @ipc_dispatch_list : ipc messages dispatched
 353 * @rx_list : to copy the process_reply/process_msg from DSP
 354 * @ipc_post_msg_wq : wq to post IPC messages context
 355 * @mad_ops : MAD driver operations registered
 356 * @mad_wq : MAD driver wq
 357 * @post_msg_wq : wq to post IPC messages
 358 * @streams : sst stream contexts
 359 * @list_lock : sst driver list lock (deprecated)
 360 * @ipc_spin_lock : spin lock to handle audio shim access and ipc queue
 361 * @block_lock : spin lock to add block to block_list and assign pvt_id
 362 * @rx_msg_lock : spin lock to handle the rx messages from the DSP
 363 * @scard_ops : sst card ops
 364 * @pci : sst pci device struture
 365 * @dev : pointer to current device struct
 366 * @sst_lock : sst device lock
 367 * @pvt_id : sst private id
 368 * @stream_cnt : total sst active stream count
 369 * @pb_streams : total active pb streams
 370 * @cp_streams : total active cp streams
 371 * @audio_start : audio status
 372 * @qos         : PM Qos struct
 373 * firmware_name : Firmware / Library name
 374 */
 375struct intel_sst_drv {
 376        int                     sst_state;
 377        int                     irq_num;
 378        unsigned int            dev_id;
 379        void __iomem            *ddr;
 380        void __iomem            *shim;
 381        void __iomem            *mailbox;
 382        void __iomem            *iram;
 383        void __iomem            *dram;
 384        unsigned int            mailbox_add;
 385        unsigned int            iram_base;
 386        unsigned int            dram_base;
 387        unsigned int            shim_phy_add;
 388        unsigned int            iram_end;
 389        unsigned int            dram_end;
 390        unsigned int            ddr_end;
 391        unsigned int            ddr_base;
 392        unsigned int            mailbox_recv_offset;
 393        struct sst_shim_regs64  *shim_regs64;
 394        struct list_head        block_list;
 395        struct list_head        ipc_dispatch_list;
 396        struct sst_platform_info *pdata;
 397        struct list_head        rx_list;
 398        struct work_struct      ipc_post_msg_wq;
 399        wait_queue_head_t       wait_queue;
 400        struct workqueue_struct *post_msg_wq;
 401        unsigned int            tstamp;
 402        /* str_id 0 is not used */
 403        struct stream_info      streams[MAX_NUM_STREAMS+1];
 404        spinlock_t              ipc_spin_lock;
 405        spinlock_t              block_lock;
 406        spinlock_t              rx_msg_lock;
 407        struct pci_dev          *pci;
 408        struct device           *dev;
 409        volatile long unsigned          pvt_id;
 410        struct mutex            sst_lock;
 411        unsigned int            stream_cnt;
 412        unsigned int            csr_value;
 413        void                    *fw_in_mem;
 414        struct sst_sg_list      fw_sg_list, library_list;
 415        struct intel_sst_ops    *ops;
 416        struct sst_info         info;
 417        struct pm_qos_request   *qos;
 418        unsigned int            use_dma;
 419        unsigned int            use_lli;
 420        atomic_t                fw_clear_context;
 421        bool                    lib_dwnld_reqd;
 422        struct list_head        memcpy_list;
 423        struct sst_ipc_reg      ipc_reg;
 424        struct sst_mem_mgr      lib_mem_mgr;
 425        /*
 426         * Holder for firmware name. Due to async call it needs to be
 427         * persistent till worker thread gets called
 428         */
 429        char firmware_name[20];
 430};
 431
 432/* misc definitions */
 433#define FW_DWNL_ID 0x01
 434
 435struct intel_sst_ops {
 436        irqreturn_t (*interrupt)(int, void *);
 437        irqreturn_t (*irq_thread)(int, void *);
 438        void (*clear_interrupt)(struct intel_sst_drv *ctx);
 439        int (*start)(struct intel_sst_drv *ctx);
 440        int (*reset)(struct intel_sst_drv *ctx);
 441        void (*process_reply)(struct intel_sst_drv *ctx, struct ipc_post *msg);
 442        int (*post_message)(struct intel_sst_drv *ctx,
 443                        struct ipc_post *msg, bool sync);
 444        void (*process_message)(struct ipc_post *msg);
 445        void (*set_bypass)(bool set);
 446        int (*save_dsp_context)(struct intel_sst_drv *sst);
 447        void (*restore_dsp_context)(void);
 448        int (*alloc_stream)(struct intel_sst_drv *ctx, void *params);
 449        void (*post_download)(struct intel_sst_drv *sst);
 450};
 451
 452int sst_pause_stream(struct intel_sst_drv *sst_drv_ctx, int id);
 453int sst_resume_stream(struct intel_sst_drv *sst_drv_ctx, int id);
 454int sst_drop_stream(struct intel_sst_drv *sst_drv_ctx, int id);
 455int sst_free_stream(struct intel_sst_drv *sst_drv_ctx, int id);
 456int sst_start_stream(struct intel_sst_drv *sst_drv_ctx, int str_id);
 457int sst_send_byte_stream_mrfld(struct intel_sst_drv *ctx,
 458                        struct snd_sst_bytes_v2 *sbytes);
 459int sst_set_stream_param(int str_id, struct snd_sst_params *str_param);
 460int sst_set_metadata(int str_id, char *params);
 461int sst_get_stream(struct intel_sst_drv *sst_drv_ctx,
 462                struct snd_sst_params *str_param);
 463int sst_get_stream_allocated(struct intel_sst_drv *ctx,
 464                struct snd_sst_params *str_param,
 465                struct snd_sst_lib_download **lib_dnld);
 466int sst_drain_stream(struct intel_sst_drv *sst_drv_ctx,
 467                int str_id, bool partial_drain);
 468int sst_post_message_mrfld(struct intel_sst_drv *ctx,
 469                struct ipc_post *msg, bool sync);
 470void sst_process_reply_mrfld(struct intel_sst_drv *ctx, struct ipc_post *msg);
 471int sst_start_mrfld(struct intel_sst_drv *ctx);
 472int intel_sst_reset_dsp_mrfld(struct intel_sst_drv *ctx);
 473void intel_sst_clear_intr_mrfld(struct intel_sst_drv *ctx);
 474
 475int sst_load_fw(struct intel_sst_drv *ctx);
 476int sst_load_library(struct snd_sst_lib_download *lib, u8 ops);
 477void sst_post_download_mrfld(struct intel_sst_drv *ctx);
 478int sst_get_block_stream(struct intel_sst_drv *sst_drv_ctx);
 479void sst_memcpy_free_resources(struct intel_sst_drv *ctx);
 480
 481int sst_wait_interruptible(struct intel_sst_drv *sst_drv_ctx,
 482                                struct sst_block *block);
 483int sst_wait_timeout(struct intel_sst_drv *sst_drv_ctx,
 484                        struct sst_block *block);
 485int sst_create_ipc_msg(struct ipc_post **arg, bool large);
 486int free_stream_context(struct intel_sst_drv *ctx, unsigned int str_id);
 487void sst_clean_stream(struct stream_info *stream);
 488int intel_sst_register_compress(struct intel_sst_drv *sst);
 489int intel_sst_remove_compress(struct intel_sst_drv *sst);
 490void sst_cdev_fragment_elapsed(struct intel_sst_drv *ctx, int str_id);
 491int sst_send_sync_msg(int ipc, int str_id);
 492int sst_get_num_channel(struct snd_sst_params *str_param);
 493int sst_get_sfreq(struct snd_sst_params *str_param);
 494int sst_alloc_stream_mrfld(struct intel_sst_drv *sst_drv_ctx, void *params);
 495void sst_restore_fw_context(void);
 496struct sst_block *sst_create_block(struct intel_sst_drv *ctx,
 497                                u32 msg_id, u32 drv_id);
 498int sst_create_block_and_ipc_msg(struct ipc_post **arg, bool large,
 499                struct intel_sst_drv *sst_drv_ctx, struct sst_block **block,
 500                u32 msg_id, u32 drv_id);
 501int sst_free_block(struct intel_sst_drv *ctx, struct sst_block *freed);
 502int sst_wake_up_block(struct intel_sst_drv *ctx, int result,
 503                u32 drv_id, u32 ipc, void *data, u32 size);
 504int sst_request_firmware_async(struct intel_sst_drv *ctx);
 505int sst_driver_ops(struct intel_sst_drv *sst);
 506struct sst_platform_info *sst_get_acpi_driver_data(const char *hid);
 507void sst_firmware_load_cb(const struct firmware *fw, void *context);
 508int sst_prepare_and_post_msg(struct intel_sst_drv *sst,
 509                int task_id, int ipc_msg, int cmd_id, int pipe_id,
 510                size_t mbox_data_len, const void *mbox_data, void **data,
 511                bool large, bool fill_dsp, bool sync, bool response);
 512
 513void sst_process_pending_msg(struct work_struct *work);
 514int sst_assign_pvt_id(struct intel_sst_drv *sst_drv_ctx);
 515void sst_init_stream(struct stream_info *stream,
 516                int codec, int sst_id, int ops, u8 slot);
 517int sst_validate_strid(struct intel_sst_drv *sst_drv_ctx, int str_id);
 518struct stream_info *get_stream_info(struct intel_sst_drv *sst_drv_ctx,
 519                int str_id);
 520int get_stream_id_mrfld(struct intel_sst_drv *sst_drv_ctx,
 521                u32 pipe_id);
 522u32 relocate_imr_addr_mrfld(u32 base_addr);
 523void sst_add_to_dispatch_list_and_post(struct intel_sst_drv *sst,
 524                                        struct ipc_post *msg);
 525int sst_pm_runtime_put(struct intel_sst_drv *sst_drv);
 526int sst_shim_write(void __iomem *addr, int offset, int value);
 527u32 sst_shim_read(void __iomem *addr, int offset);
 528u64 sst_reg_read64(void __iomem *addr, int offset);
 529int sst_shim_write64(void __iomem *addr, int offset, u64 value);
 530u64 sst_shim_read64(void __iomem *addr, int offset);
 531void sst_set_fw_state_locked(
 532                struct intel_sst_drv *sst_drv_ctx, int sst_state);
 533void sst_fill_header_mrfld(union ipc_header_mrfld *header,
 534                                int msg, int task_id, int large, int drv_id);
 535void sst_fill_header_dsp(struct ipc_dsp_hdr *dsp, int msg,
 536                                        int pipe_id, int len);
 537
 538int sst_register(struct device *);
 539int sst_unregister(struct device *);
 540
 541int sst_alloc_drv_context(struct intel_sst_drv **ctx,
 542                struct device *dev, unsigned int dev_id);
 543int sst_context_init(struct intel_sst_drv *ctx);
 544void sst_context_cleanup(struct intel_sst_drv *ctx);
 545void sst_configure_runtime_pm(struct intel_sst_drv *ctx);
 546#endif
 547