1 /* 2 * Copyright (c) 2021 Huawei Device Co., Ltd. 3 * 4 * HDF is dual licensed: you can use it either under the terms of 5 * the GPL, or the BSD license, at your option. 6 * See the LICENSE file in the root of this repository for complete details. 7 */ 8 9 #ifndef AUDIO_PLATFORM_BASE_H 10 #define AUDIO_PLATFORM_BASE_H 11 12 #include "audio_host.h" 13 14 #ifdef __cplusplus 15 #if __cplusplus 16 extern "C" { 17 #endif 18 #endif /* __cplusplus */ 19 20 #define BITSTOBYTE 8 21 #define MAX_BUFF_SIZE (128 * 1024) 22 #define MIN_BUFF_SIZE (16 * 1024) 23 24 enum DataBitWidth { 25 DATA_BIT_WIDTH8 = 8, /* 8 bit witdth */ 26 DATA_BIT_WIDTH16 = 16, /* 16 bit witdth */ 27 DATA_BIT_WIDTH18 = 18, /* 18 bit witdth */ 28 DATA_BIT_WIDTH20 = 20, /* 20 bit witdth */ 29 DATA_BIT_WIDTH24 = 24, /* 24 bit witdth */ 30 DATA_BIT_WIDTH32 = 32, /* 32 bit witdth */ 31 }; 32 33 enum PcmStatus { 34 PCM_STOP = 0, /* pcm stream stop flag */ 35 PCM_PAUSE, /* pcm stream pause flag */ 36 PCM_START, /* pcm stream start flag */ 37 }; 38 39 struct CircleBufInfo { 40 uint32_t cirBufSize; /* Current DMA cache size */ 41 uint32_t trafBufSize; /* PCM data per transmission default size */ 42 uint32_t period; /* not used */ 43 uint32_t periodSize; /* DMA cache period size */ 44 uint32_t periodCount; /* Number of DMA cache periods */ 45 unsigned long phyAddr; /* DMA cache physical address */ 46 uint32_t *virtAddr; /* DMA cache virtual address */ 47 uint32_t wbufOffSet; /* DMA cache write address offset */ 48 uint32_t wptrOffSet; /* DMA cache write pointer offset */ 49 uint32_t rbufOffSet; /* DMA cache read address offset */ 50 uint32_t rptrOffSet; /* DMA cache read pointer offset */ 51 enum PcmStatus runStatus; /* PCM status */ 52 uint32_t chnId; /* Channel ID */ 53 uint32_t enable; /* Enable identification */ 54 struct OsalMutex buffMutex; /* mutex */ 55 uint32_t framesPosition; /* Frame position */ 56 uint32_t pointer; /* Read/write pointer position during playback and recording */ 57 uint32_t periodsMax; /* Maximum number of periods */ 58 uint32_t periodsMin; /* Minimum number of periods */ 59 uint32_t cirBufMax; /* Size of DMA cache requested */ 60 uint32_t curTrafSize; /* The size of each actual transmission of PCM data */ 61 uint32_t oneMsBytes; /* Number of bytes transferred per millisecond. */ 62 uint32_t trafCompCount; /* Number of DMA transfers completed. */ 63 }; 64 65 #define HDF_AUDIO_CAPTURE_THRESHOLD (0x9) 66 #define HDF_AUDIO_PRIMARY_DEVICE (0x80) 67 68 struct AudioEvent { 69 uint32_t eventType; 70 uint32_t deviceType; 71 }; 72 73 uint32_t SysReadl(unsigned long addr); 74 void SysWritel(unsigned long addr, uint32_t value); 75 76 struct PlatformData *PlatformDataFromCard(const struct AudioCard *card); 77 uint32_t AudioBytesToFrames(uint32_t frameBits, uint32_t size); 78 int32_t AudioDataBigEndianChange(char *srcData, uint32_t audioLen, enum DataBitWidth bitWidth); 79 int32_t AudioFormatToBitWidth(enum AudioFormat format, uint32_t *bitWidth); 80 int32_t AudioSetPcmInfo(struct PlatformData *platformData, const struct AudioPcmHwParams *param); 81 int32_t AudioSetRenderBufInfo(struct PlatformData *data, const struct AudioPcmHwParams *param); 82 int32_t AudioSetCaptureBufInfo(struct PlatformData *data, const struct AudioPcmHwParams *param); 83 int32_t AudioPcmWrite(const struct AudioCard *card, struct AudioTxData *txData); 84 int32_t AudioPcmRead(const struct AudioCard *card, struct AudioRxData *rxData); 85 int32_t AudioPcmMmapWrite(const struct AudioCard *card, const struct AudioMmapData *txMmapData); 86 int32_t AudioPcmMmapRead(const struct AudioCard *card, const struct AudioMmapData *rxMmapData); 87 int32_t AudioRenderOpen(const struct AudioCard *card); 88 int32_t AudioCaptureOpen(const struct AudioCard *card); 89 int32_t AudioRenderClose(const struct AudioCard *card); 90 int32_t AudioPcmPointer(const struct AudioCard *card, uint32_t *pointer, enum AudioStreamType streamType); 91 int32_t AudioCaptureClose(const struct AudioCard *card); 92 int32_t AudioHwParams(const struct AudioCard *card, const struct AudioPcmHwParams *param); 93 int32_t AudioRenderPrepare(const struct AudioCard *card); 94 int32_t AudioCapturePrepare(const struct AudioCard *card); 95 int32_t AudioRenderTrigger(struct AudioCard *card, int32_t cmd); 96 int32_t AudioCaptureTrigger(struct AudioCard *card, int32_t cmd); 97 int32_t AudioCapSilenceThresholdEvent(struct HdfDeviceObject *device, const struct AudioEvent *reportMsg); 98 99 #ifdef __cplusplus 100 #if __cplusplus 101 } 102 #endif 103 #endif /* __cplusplus */ 104 105 #endif /* CODEC_CORE_H */ 106