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