.. | .. |
---|
1 | | -/* SPDX-License-Identifier: GPL-2.0 */ |
---|
| 1 | +/* SPDX-License-Identifier: GPL-2.0-or-later */ |
---|
2 | 2 | /* |
---|
3 | 3 | * Rockchip DLP (Digital Loopback) driver |
---|
4 | 4 | * |
---|
.. | .. |
---|
10 | 10 | #ifndef _ROCKCHIP_DLP_H |
---|
11 | 11 | #define _ROCKCHIP_DLP_H |
---|
12 | 12 | |
---|
13 | | -struct snd_dlp_config { |
---|
14 | | - int (*get_fifo_count)(struct device *dev, int stream); |
---|
| 13 | +#include "rockchip_dlp_pcm.h" |
---|
| 14 | + |
---|
| 15 | +#define DLP_MAX_DRDS 8 |
---|
| 16 | + |
---|
| 17 | +/* MUST: enum dlp_mode should be match to dlp_text */ |
---|
| 18 | +enum dlp_mode { |
---|
| 19 | + DLP_MODE_DISABLED, |
---|
| 20 | + DLP_MODE_2CH_1LP_1MIC, /* replace cap-ch-0 with play-ch-0 */ |
---|
| 21 | + DLP_MODE_2CH_1MIC_1LP, /* replace cap-ch-1 with play-ch-1 */ |
---|
| 22 | + DLP_MODE_2CH_1MIC_1LP_MIX, /* replace cap-ch-1 with play-ch-all-mix */ |
---|
| 23 | + DLP_MODE_2CH_2LP, /* replace cap-ch-0~1 with play-ch-0~1 */ |
---|
| 24 | + DLP_MODE_4CH_2MIC_2LP, /* replace cap-ch-2~3 with play-ch-0~1 */ |
---|
| 25 | + DLP_MODE_4CH_2MIC_1LP_MIX, /* replace cap-ch-3 with play-ch-all-mix */ |
---|
| 26 | + DLP_MODE_4CH_4LP, /* replace cap-ch-0~3 with play-ch-0~3 */ |
---|
| 27 | + DLP_MODE_6CH_4MIC_2LP, /* replace cap-ch-4~5 with play-ch-0~1 */ |
---|
| 28 | + DLP_MODE_6CH_4MIC_1LP_MIX, /* replace cap-ch-4 with play-ch-all-mix */ |
---|
| 29 | + DLP_MODE_6CH_6LP, /* replace cap-ch-0~5 with play-ch-0~5 */ |
---|
| 30 | + DLP_MODE_8CH_6MIC_2LP, /* replace cap-ch-6~7 with play-ch-0~1 */ |
---|
| 31 | + DLP_MODE_8CH_6MIC_1LP_MIX, /* replace cap-ch-6 with play-ch-all-mix */ |
---|
| 32 | + DLP_MODE_8CH_8LP, /* replace cap-ch-0~7 with play-ch-0~7 */ |
---|
| 33 | + DLP_MODE_10CH_8MIC_2LP, /* replace cap-ch-8~9 with play-ch-0~1 */ |
---|
| 34 | + DLP_MODE_10CH_8MIC_1LP_MIX, /* replace cap-ch-8 with play-ch-all-mix */ |
---|
| 35 | + DLP_MODE_16CH_8MIC_8LP, /* replace cap-ch-8~f with play-ch-8~f */ |
---|
15 | 36 | }; |
---|
16 | 37 | |
---|
17 | | -#if IS_REACHABLE(CONFIG_SND_SOC_ROCKCHIP_DLP) |
---|
18 | | -int devm_snd_dmaengine_dlp_register(struct device *dev, |
---|
19 | | - const struct snd_dlp_config *config); |
---|
20 | | -#else |
---|
21 | | -static inline int devm_snd_dmaengine_dlp_register(struct device *dev, |
---|
22 | | - const struct snd_dlp_config *config) |
---|
| 38 | +struct dlp; |
---|
| 39 | + |
---|
| 40 | +struct dlp_runtime_data { |
---|
| 41 | + struct dlp *parent; |
---|
| 42 | + struct kref refcount; |
---|
| 43 | + struct list_head node; |
---|
| 44 | + char *buf; |
---|
| 45 | + snd_pcm_uframes_t buf_sz; |
---|
| 46 | + snd_pcm_uframes_t last_buf_sz; |
---|
| 47 | + snd_pcm_uframes_t period_sz; |
---|
| 48 | + int64_t hw_ptr; |
---|
| 49 | + int64_t hw_ptr_delta; /* play-ptr - cap-ptr */ |
---|
| 50 | + atomic64_t period_elapsed; |
---|
| 51 | + atomic_t stop; |
---|
| 52 | + unsigned int frame_bytes; |
---|
| 53 | + unsigned int channels; |
---|
| 54 | + unsigned int buf_ofs; |
---|
| 55 | + int stream; |
---|
| 56 | +}; |
---|
| 57 | + |
---|
| 58 | +struct dlp { |
---|
| 59 | + struct device *dev; |
---|
| 60 | + struct list_head drd_avl_list; |
---|
| 61 | + struct list_head drd_rdy_list; |
---|
| 62 | + struct list_head drd_ref_list; |
---|
| 63 | + struct dlp_runtime_data drds[DLP_MAX_DRDS]; |
---|
| 64 | + struct dlp_runtime_data *drd_pb_shadow; |
---|
| 65 | + struct snd_soc_component component; |
---|
| 66 | + const struct snd_dlp_config *config; |
---|
| 67 | + enum dlp_mode mode; |
---|
| 68 | + int drd_avl_count; |
---|
| 69 | + atomic_t active; |
---|
| 70 | + spinlock_t lock; |
---|
| 71 | +}; |
---|
| 72 | + |
---|
| 73 | +typedef snd_pcm_uframes_t (*dma_pointer_f)(struct snd_soc_component *component, |
---|
| 74 | + struct snd_pcm_substream *substream); |
---|
| 75 | + |
---|
| 76 | +static inline struct dlp *soc_component_to_dlp(struct snd_soc_component *p) |
---|
23 | 77 | { |
---|
24 | | - return -ENOSYS; |
---|
| 78 | + return container_of(p, struct dlp, component); |
---|
25 | 79 | } |
---|
26 | | -#endif |
---|
| 80 | + |
---|
| 81 | +static inline struct dlp_runtime_data *substream_to_drd( |
---|
| 82 | + const struct snd_pcm_substream *substream) |
---|
| 83 | +{ |
---|
| 84 | + if (!substream->runtime) |
---|
| 85 | + return NULL; |
---|
| 86 | + |
---|
| 87 | + return substream->runtime->private_data; |
---|
| 88 | +} |
---|
| 89 | + |
---|
| 90 | +static inline ssize_t dlp_channels_to_bytes(struct dlp_runtime_data *drd, |
---|
| 91 | + int channels) |
---|
| 92 | +{ |
---|
| 93 | + return (drd->frame_bytes / drd->channels) * channels; |
---|
| 94 | +} |
---|
| 95 | + |
---|
| 96 | +static inline ssize_t dlp_frames_to_bytes(struct dlp_runtime_data *drd, |
---|
| 97 | + snd_pcm_sframes_t size) |
---|
| 98 | +{ |
---|
| 99 | + return size * drd->frame_bytes; |
---|
| 100 | +} |
---|
| 101 | + |
---|
| 102 | +static inline snd_pcm_sframes_t dlp_bytes_to_frames(struct dlp_runtime_data *drd, |
---|
| 103 | + ssize_t size) |
---|
| 104 | +{ |
---|
| 105 | + return size / drd->frame_bytes; |
---|
| 106 | +} |
---|
| 107 | + |
---|
| 108 | +void dlp_dma_complete(struct dlp *dlp, struct dlp_runtime_data *drd); |
---|
| 109 | +int dlp_open(struct dlp *dlp, struct dlp_runtime_data *drd, |
---|
| 110 | + struct snd_pcm_substream *substream); |
---|
| 111 | +int dlp_close(struct dlp *dlp, struct dlp_runtime_data *drd, |
---|
| 112 | + struct snd_pcm_substream *substream); |
---|
| 113 | +int dlp_hw_params(struct snd_soc_component *component, |
---|
| 114 | + struct snd_pcm_substream *substream, |
---|
| 115 | + struct snd_pcm_hw_params *params); |
---|
| 116 | +int dlp_start(struct snd_soc_component *component, |
---|
| 117 | + struct snd_pcm_substream *substream, |
---|
| 118 | + struct device *dev, |
---|
| 119 | + dma_pointer_f dma_pointer); |
---|
| 120 | +void dlp_stop(struct snd_soc_component *component, |
---|
| 121 | + struct snd_pcm_substream *substream, |
---|
| 122 | + dma_pointer_f dma_pointer); |
---|
| 123 | +int dlp_copy_user(struct snd_soc_component *component, |
---|
| 124 | + struct snd_pcm_substream *substream, |
---|
| 125 | + int channel, unsigned long hwoff, |
---|
| 126 | + void __user *buf, unsigned long bytes); |
---|
| 127 | +int dlp_prepare(struct snd_soc_component *component, |
---|
| 128 | + struct snd_pcm_substream *substream); |
---|
| 129 | +int dlp_probe(struct snd_soc_component *component); |
---|
| 130 | +int dlp_register(struct dlp *dlp, struct device *dev, |
---|
| 131 | + const struct snd_soc_component_driver *driver, |
---|
| 132 | + const struct snd_dlp_config *config); |
---|
27 | 133 | |
---|
28 | 134 | #endif |
---|