• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 MIN_PERIOD_SIZE (2 * 1024)
21 #define BITSTOBYTE 8
22 #define MAX_BUFF_SIZE (128 * 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 };
62 
63 /* head file: pnp_message_report */
64 enum PnpReportType {
65     DEVICE_PULG,
66     EVENT_REPORT,
67     REPORT_TYPE_INVALID
68 };
69 
70 enum PnpEventID {
71     THRESHOLD_REPORT,
72     LOAD_ADAPTER,
73     SERVICE_STATUS,
74     EVENT_ID_INVALID
75 };
76 
77 enum PnpDeviceType {
78     PRIMARY_DEVICE,
79     USB_DEVICE,
80     A2DP_DEVICE,
81     DEVICE_TYPE_INVALID
82 };
83 
84 struct PnpReportDevPlugMsg {
85     uint8_t eventType;
86     uint8_t state;
87     uint8_t deviceType;
88     uint8_t deviceCap;
89     uint8_t id;
90 };
91 
92 struct PnpReportEventMsg {
93     uint8_t eventType;
94     uint8_t eventId;
95     uint8_t eventValue;
96     uint8_t deviceType;
97     uint8_t reserve;      /* Reserved fields are not used for the time being */
98 };
99 
100 struct PnpReportMsg {
101     enum PnpReportType reportType;
102     union {
103         struct PnpReportDevPlugMsg devPlugMsg;
104         struct PnpReportEventMsg eventMsg;
105     };
106 };
107 
108 unsigned int SysReadl(unsigned long addr);
109 void SysWritel(unsigned long addr, unsigned int value);
110 
111 struct PlatformData *PlatformDataFromCard(const struct AudioCard *card);
112 uint32_t AudioBytesToFrames(uint32_t frameBits, uint32_t size);
113 int32_t AudioDataBigEndianChange(char *srcData, uint32_t audioLen, enum DataBitWidth bitWidth);
114 int32_t AudioFramatToBitWidth(enum AudioFormat format, unsigned int *bitWidth);
115 int32_t AudioSetPcmInfo(struct PlatformData *platformData, const struct AudioPcmHwParams *param);
116 int32_t AudioSetRenderBufInfo(struct PlatformData *data, const struct AudioPcmHwParams *param);
117 int32_t AudioSetCaptureBufInfo(struct PlatformData *data, const struct AudioPcmHwParams *param);
118 int32_t AudioPcmWrite(const struct AudioCard *card, struct AudioTxData *txData);
119 int32_t AudioPcmRead(const struct AudioCard *card, struct AudioRxData *rxData);
120 int32_t AudioPcmMmapWrite(const struct AudioCard *card, const struct AudioMmapData *txMmapData);
121 int32_t AudioPcmMmapRead(const struct AudioCard *card, const struct AudioMmapData *rxMmapData);
122 int32_t AudioRenderOpen(const struct AudioCard *card);
123 int32_t AudioCaptureOpen(const struct AudioCard *card);
124 int32_t AudioRenderClose(const struct AudioCard *card);
125 int32_t AudioPcmPointer(const struct AudioCard *card, uint32_t *pointer, enum AudioStreamType streamType);
126 int32_t AudioCaptureClose(const struct AudioCard *card);
127 int32_t AudioHwParams(const struct AudioCard *card, const struct AudioPcmHwParams *param);
128 int32_t AudioRenderPrepare(const struct AudioCard *card);
129 int32_t AudioCapturePrepare(const struct AudioCard *card);
130 int32_t AudioRenderTrigger(struct AudioCard *card, int cmd);
131 int32_t AudioCaptureTrigger(struct AudioCard *card, int cmd);
132 int32_t AudioCapSilenceThresholdEvent(struct HdfDeviceObject *device, const struct PnpReportMsg *reportMsg);
133 
134 #ifdef __cplusplus
135 #if __cplusplus
136 }
137 #endif
138 #endif /* __cplusplus */
139 
140 #endif /* CODEC_CORE_H */
141