123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430 |
- #ifndef __PHY_AUDIO_COMMON_H__
- #define __PHY_AUDIO_COMMON_H__
- #include <device.h>
- #ifdef CONFIG_SOC_SERIES_LARK
- #include "audio_acts_utils.h"
- #endif
- #ifdef CONFIG_SOC_SERIES_LEOPARD
- #include "phy_leopard/audio_acts_utils.h"
- #endif
- #ifndef BIT
- #define BIT(n) (1UL << (n))
- #endif
- #define PHY_CMD_BASE (0xFF)
- #define PHY_CMD_OFFSET (64)
- #define PHY_CMD_DUMP_REGS (PHY_CMD_BASE + 1)
- #define PHY_CMD_FIFO_GET (PHY_CMD_BASE + 2)
- #define PHY_CMD_FIFO_PUT (PHY_CMD_BASE + 3)
- #define PHY_CMD_FIFO_DRQ_LEVEL_GET (PHY_CMD_BASE + 16)
- #define PHY_CMD_FIFO_DRQ_LEVEL_SET (PHY_CMD_BASE + 17)
- #define PHY_CMD_GET_AIN_DMA_INFO (PHY_CMD_BASE + 18)
- #define PHY_CMD_GET_AOUT_DMA_INFO (PHY_CMD_BASE + 19)
- #define PHY_CMD_CHANNEL_START (PHY_CMD_BASE + 20)
- #define PHY_CMD_DAC_BASE (PHY_CMD_BASE + PHY_CMD_OFFSET)
- #define PHY_CMD_DAC_WAIT_EMPTY (PHY_CMD_DAC_BASE + 1)
- #define PHY_CMD_DAC_FIFO_GET_SAMPLE_CNT (PHY_CMD_DAC_BASE + 2)
- #define PHY_CMD_DAC_FIFO_RESET_SAMPLE_CNT (PHY_CMD_DAC_BASE + 3)
- #define PHY_CMD_DAC_FIFO_DISABLE_SAMPLE_CNT (PHY_CMD_DAC_BASE + 4)
- #define PHY_CMD_DAC_FIFO_ENABLE_SAMPLE_CNT (PHY_CMD_DAC_BASE + 5)
- #define PHY_CMD_DAC_FIFO_VOLUME_GET (PHY_CMD_DAC_BASE + 6)
- #define PHY_CMD_DAC_FIFO_VOLUME_SET (PHY_CMD_DAC_BASE + 7)
- #define PHY_CMD_CLAIM_WITH_128FS (PHY_CMD_DAC_BASE + 8)
- #define PHY_CMD_CLAIM_WITHOUT_128FS (PHY_CMD_DAC_BASE + 9)
- #define PHY_CMD_ANC_MIX2_DAC_ENABLE (PHY_CMD_DAC_BASE + 10)
- #define PHY_CMD_ANC_MIX2_DAC_LR_INVERSE (PHY_CMD_DAC_BASE + 11)
- #define PHY_CMD_I2STX_BASE (PHY_CMD_DAC_BASE + PHY_CMD_OFFSET)
- #define PHY_CMD_I2STX_IS_OPENED (PHY_CMD_I2STX_BASE + 1)
- #define PHY_CMD_I2STX_DISABLE_DEVICE (PHY_CMD_I2STX_BASE + 2)
- #define PHY_CMD_I2STX_CLK_SET (PHY_CMD_I2STX_BASE + 3)
- #define PHY_CMD_I2STX_IS_MCLK_128FS (PHY_CMD_I2STX_BASE + 4)
- #define PHY_CMD_I2S_LOOPBACK (PHY_CMD_I2STX_BASE + 5)
- #define PHY_CMD_I2SRX_BASE (PHY_CMD_I2STX_BASE + PHY_CMD_OFFSET)
- #define PHY_CMD_I2SRX_IS_OPENED (PHY_CMD_I2SRX_BASE + 1)
- #define PHY_CMD_ADC_BASE (PHY_CMD_I2SRX_BASE + PHY_CMD_OFFSET)
- #define PHY_CMD_ADC_DIGITAL_ENABLE (PHY_CMD_ADC_BASE + 1)
- #define PHY_CMD_GET_AUDIOPLL_IDX (PHY_CMD_ADC_BASE + 2)
- #define PHY_CMD_ADC_GAIN_CONFIG (PHY_CMD_ADC_BASE + 3)
- #define PHY_CMD_IS_ADC_BUSY (PHY_CMD_DAC_BASE + 4)
- typedef enum {
- FIFO_SEL_CPU = 0,
- FIFO_SEL_DMA,
- FIFO_SEL_ASRC,
- FIFO_SEL_DSP,
- FIFO_SEL_DSP_DMA
- } audio_fifouse_sel_e;
- typedef enum {
- DMA_WIDTH_32BITS = 0,
- DMA_WIDTH_16BITS
- } audio_dma_width_e;
- typedef enum {
- I2S_SRD_2LRCLK = 0,
- I2S_SRD_4LRCLK
- } audio_i2s_srd_period_e;
- typedef enum {
- FF_IIR_US = 0,
- FF_DSFIFO_USFIFO,
- } audio_anc_work_mode;
- struct audio_dma_dt {
- const char *dma_dev_name;
- uint32_t dma_chan;
- uint8_t dma_id;
- };
- struct audio_in_dma_info {
- uint16_t input_dev;
- struct audio_dma_dt dma_info;
- };
- struct aduio_in_adc_en {
- uint16_t *input_dev_array;
- uint8_t input_dev_num;
- };
- struct audio_out_dma_info {
- uint8_t fifo_type;
- struct audio_dma_dt dma_info;
- };
- struct audio_debug_trace_t {
- #define AUDIO_DEBUG_TRACE_START_FLAG BIT(0)
- uint32_t sec_timestamp;
- uint32_t trace_exec_timestamp;
- uint32_t trace_start_timestamp;
- uint32_t max_exec_time;
- uint32_t total_exec_time;
- uint32_t counter_per_sec;
- uint32_t counter_per_sec_bak;
- uint32_t total_counter;
- uint8_t flags;
- };
- extern struct audio_debug_trace_t audio_debug_trace;
- static inline void audio_debug_trace_info(void)
- {
- printk("audio trace total %dus {max_exec_time:%dus,total_exec_time:%dus}\n",
- k_cyc_to_us_floor32(k_cycle_get_32() - audio_debug_trace.trace_start_timestamp),
- k_cyc_to_us_floor32(audio_debug_trace.max_exec_time),
- k_cyc_to_us_floor32(audio_debug_trace.total_exec_time));
- printk("audio trace coutner_per_sec_bak:%d total_counter:%d\n",
- audio_debug_trace.counter_per_sec_bak, audio_debug_trace.total_counter);
- }
- static inline void audio_debug_trace_start(void)
- {
- audio_debug_trace.trace_exec_timestamp = k_cycle_get_32();
- audio_debug_trace.counter_per_sec++;
- audio_debug_trace.total_counter++;
- if (!(audio_debug_trace.flags & AUDIO_DEBUG_TRACE_START_FLAG)) {
- audio_debug_trace.trace_start_timestamp = audio_debug_trace.trace_exec_timestamp;
- audio_debug_trace.flags |= AUDIO_DEBUG_TRACE_START_FLAG;
- }
- }
- static inline void audio_debug_trace_end(void)
- {
- uint32_t delta, cur_time = k_cycle_get_32();
- delta = cur_time - audio_debug_trace.trace_exec_timestamp;
- if (delta > audio_debug_trace.max_exec_time)
- audio_debug_trace.max_exec_time = delta;
- audio_debug_trace.total_exec_time += delta;
- delta = k_cyc_to_us_floor32(cur_time - audio_debug_trace.sec_timestamp);
- if (delta > 1000000UL) {
-
- audio_debug_trace.sec_timestamp = cur_time;
- audio_debug_trace.counter_per_sec_bak = audio_debug_trace.counter_per_sec;
- audio_debug_trace.counter_per_sec = 0;
- }
- }
- static inline void audio_debug_trace_clear(void)
- {
- memset(&audio_debug_trace, 0, sizeof(struct audio_debug_trace_t));
- }
- #define AUDIO_DMA_FIFO_DEF(m, n) \
- .dma_fifo##n = { \
- .dma_dev_name = CONFIG_DMA_0_NAME, \
- .dma_chan = CONFIG_AUDIO_##m##_0_FIFO##n##_DMA_CHAN, \
- .dma_id = CONFIG_AUDIO_##m##_0_FIFO##n##_DMA_ID \
- }
- #define PHY_DEV_FEATURE_DEF(x) .features.v.x
- #define PHY_DEV_FEATURE(x) (cfg->features.v.x)
- #define PHY_FIFO_INDEX_OFFSET (16)
- #define PHY_FIFO_CMD(i, x) (((i) << PHY_FIFO_INDEX_OFFSET) | (x))
- #define PHY_GET_FIFO_CMD_INDEX(x) ((x) >> PHY_FIFO_INDEX_OFFSET)
- #define PHY_GET_FIFO_CMD_VAL(x) ((x) & 0xFFFF)
- #define PHY_DEV_SHOW_DT_INFO (0)
- #ifdef CONFIG_CFG_DRV
- #define PHY_AUDIO_CFG(x, item_key, item) \
- { uint32_t val = 0; \
- if (!cfg_get_by_key(item_key, &val, sizeof((x).item))) \
- return __LINE__; \
- LOG_INF("%s:%d", #item, val); \
- (x).item = val; \
- }
- #define PHY_AUDIO_PIN_NUM_CFG(x) ((x) & 0xFF)
- #define PHY_AUDIO_PIN_MFP_CFG(x) ((x) >> 8)
- #endif
- struct phy_audio_driver_api {
- int (*audio_enable)(struct device *dev, void *param);
- int (*audio_disable)(struct device *dev, void *param);
- int (*audio_ioctl)(struct device *dev, uint32_t cmd, void *param);
- };
- static inline int phy_audio_enable(struct device *dev, void *param)
- {
- if (!dev)
- return -EINVAL;
- const struct phy_audio_driver_api *api = dev->api;
- return api->audio_enable(dev, param);
- }
- static inline int phy_audio_disable(struct device *dev, void *param)
- {
- if (!dev)
- return -EINVAL;
- const struct phy_audio_driver_api *api = dev->api;
- return api->audio_disable(dev, param);
- }
- static inline int phy_audio_control(struct device *dev, uint32_t cmd, void *param)
- {
- if (!dev)
- return -EINVAL;
- const struct phy_audio_driver_api *api = dev->api;
- return api->audio_ioctl(dev, cmd, param);
- }
- #endif
|