Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Asihpi soundcard |
Eliot Blennerhassett | f9a376c | 2014-11-20 16:22:53 +1300 | [diff] [blame] | 3 | * Copyright (c) by AudioScience Inc <support@audioscience.com> |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of version 2 of the GNU General Public License as |
| 7 | * published by the Free Software Foundation; |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License |
| 15 | * along with this program; if not, write to the Free Software |
| 16 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 17 | * |
| 18 | * |
| 19 | * The following is not a condition of use, merely a request: |
| 20 | * If you modify this program, particularly if you fix errors, AudioScience Inc |
| 21 | * would appreciate it if you grant us the right to use those modifications |
| 22 | * for any purpose including commercial applications. |
| 23 | */ |
Eliot Blennerhassett | e64b1a2 | 2011-02-10 17:25:59 +1300 | [diff] [blame] | 24 | |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 25 | #include "hpi_internal.h" |
Eliot Blennerhassett | f50efa2 | 2011-12-22 13:38:48 +1300 | [diff] [blame] | 26 | #include "hpi_version.h" |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 27 | #include "hpimsginit.h" |
| 28 | #include "hpioctl.h" |
Eliot Blennerhassett | 7036b92 | 2011-12-22 13:38:43 +1300 | [diff] [blame] | 29 | #include "hpicmn.h" |
| 30 | |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 31 | #include <linux/pci.h> |
| 32 | #include <linux/init.h> |
| 33 | #include <linux/jiffies.h> |
| 34 | #include <linux/slab.h> |
| 35 | #include <linux/time.h> |
| 36 | #include <linux/wait.h> |
Paul Gortmaker | da155d5 | 2011-07-15 12:38:28 -0400 | [diff] [blame] | 37 | #include <linux/module.h> |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 38 | #include <sound/core.h> |
| 39 | #include <sound/control.h> |
| 40 | #include <sound/pcm.h> |
| 41 | #include <sound/pcm_params.h> |
| 42 | #include <sound/info.h> |
| 43 | #include <sound/initval.h> |
| 44 | #include <sound/tlv.h> |
| 45 | #include <sound/hwdep.h> |
| 46 | |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 47 | MODULE_LICENSE("GPL"); |
| 48 | MODULE_AUTHOR("AudioScience inc. <support@audioscience.com>"); |
Eliot Blennerhassett | e9886ab | 2014-11-20 16:22:48 +1300 | [diff] [blame] | 49 | MODULE_DESCRIPTION("AudioScience ALSA ASI5xxx ASI6xxx ASI87xx ASI89xx " |
Eliot Blennerhassett | f50efa2 | 2011-12-22 13:38:48 +1300 | [diff] [blame] | 50 | HPI_VER_STRING); |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 51 | |
Eliot Blennerhassett | b2e65c8 | 2011-03-25 15:25:48 +1300 | [diff] [blame] | 52 | #if defined CONFIG_SND_DEBUG_VERBOSE |
| 53 | /** |
| 54 | * snd_printddd - very verbose debug printk |
| 55 | * @format: format string |
| 56 | * |
| 57 | * Works like snd_printk() for debugging purposes. |
| 58 | * Ignored when CONFIG_SND_DEBUG_VERBOSE is not set. |
| 59 | * Must set snd module debug parameter to 3 to enable at runtime. |
| 60 | */ |
| 61 | #define snd_printddd(format, args...) \ |
| 62 | __snd_printk(3, __FILE__, __LINE__, format, ##args) |
| 63 | #else |
Eliot Blennerhassett | b0096a6 | 2011-04-05 20:55:46 +1200 | [diff] [blame] | 64 | #define snd_printddd(format, args...) do { } while (0) |
Eliot Blennerhassett | b2e65c8 | 2011-03-25 15:25:48 +1300 | [diff] [blame] | 65 | #endif |
| 66 | |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 67 | static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* index 0-MAX */ |
| 68 | static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */ |
Rusty Russell | a67ff6a | 2011-12-15 13:49:36 +1030 | [diff] [blame] | 69 | static bool enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP; |
| 70 | static bool enable_hpi_hwdep = 1; |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 71 | |
| 72 | module_param_array(index, int, NULL, S_IRUGO); |
| 73 | MODULE_PARM_DESC(index, "ALSA index value for AudioScience soundcard."); |
| 74 | |
| 75 | module_param_array(id, charp, NULL, S_IRUGO); |
| 76 | MODULE_PARM_DESC(id, "ALSA ID string for AudioScience soundcard."); |
| 77 | |
| 78 | module_param_array(enable, bool, NULL, S_IRUGO); |
| 79 | MODULE_PARM_DESC(enable, "ALSA enable AudioScience soundcard."); |
| 80 | |
| 81 | module_param(enable_hpi_hwdep, bool, S_IRUGO|S_IWUSR); |
| 82 | MODULE_PARM_DESC(enable_hpi_hwdep, |
| 83 | "ALSA enable HPI hwdep for AudioScience soundcard "); |
| 84 | |
| 85 | /* identify driver */ |
| 86 | #ifdef KERNEL_ALSA_BUILD |
Eliot Blennerhassett | e64b1a2 | 2011-02-10 17:25:59 +1300 | [diff] [blame] | 87 | static char *build_info = "Built using headers from kernel source"; |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 88 | module_param(build_info, charp, S_IRUGO); |
Eliot Blennerhassett | e9886ab | 2014-11-20 16:22:48 +1300 | [diff] [blame] | 89 | MODULE_PARM_DESC(build_info, "Built using headers from kernel source"); |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 90 | #else |
Eliot Blennerhassett | e64b1a2 | 2011-02-10 17:25:59 +1300 | [diff] [blame] | 91 | static char *build_info = "Built within ALSA source"; |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 92 | module_param(build_info, charp, S_IRUGO); |
Eliot Blennerhassett | e9886ab | 2014-11-20 16:22:48 +1300 | [diff] [blame] | 93 | MODULE_PARM_DESC(build_info, "Built within ALSA source"); |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 94 | #endif |
| 95 | |
| 96 | /* set to 1 to dump every control from adapter to log */ |
| 97 | static const int mixer_dump; |
| 98 | |
| 99 | #define DEFAULT_SAMPLERATE 44100 |
| 100 | static int adapter_fs = DEFAULT_SAMPLERATE; |
| 101 | |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 102 | /* defaults */ |
| 103 | #define PERIODS_MIN 2 |
Eliot Blennerhassett | e64b1a2 | 2011-02-10 17:25:59 +1300 | [diff] [blame] | 104 | #define PERIOD_BYTES_MIN 2048 |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 105 | #define BUFFER_BYTES_MAX (512 * 1024) |
| 106 | |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 107 | #define MAX_CLOCKSOURCES (HPI_SAMPLECLOCK_SOURCE_LAST + 1 + 7) |
| 108 | |
| 109 | struct clk_source { |
| 110 | int source; |
| 111 | int index; |
Eliot Blennerhassett | 3872f19 | 2014-11-20 16:22:49 +1300 | [diff] [blame] | 112 | const char *name; |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 113 | }; |
| 114 | |
| 115 | struct clk_cache { |
| 116 | int count; |
| 117 | int has_local; |
| 118 | struct clk_source s[MAX_CLOCKSOURCES]; |
| 119 | }; |
| 120 | |
| 121 | /* Per card data */ |
| 122 | struct snd_card_asihpi { |
| 123 | struct snd_card *card; |
| 124 | struct pci_dev *pci; |
Eliot Blennerhassett | 7036b92 | 2011-12-22 13:38:43 +1300 | [diff] [blame] | 125 | struct hpi_adapter *hpi; |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 126 | |
Eliot Blennerhassett | f9a376c | 2014-11-20 16:22:53 +1300 | [diff] [blame] | 127 | /* In low latency mode there is only one stream, a pointer to its |
| 128 | * private data is stored here on trigger and cleared on stop. |
| 129 | * The interrupt handler uses it as a parameter when calling |
| 130 | * snd_card_asihpi_timer_function(). |
| 131 | */ |
| 132 | struct snd_card_asihpi_pcm *llmode_streampriv; |
| 133 | struct tasklet_struct t; |
| 134 | void (*pcm_start)(struct snd_pcm_substream *substream); |
| 135 | void (*pcm_stop)(struct snd_pcm_substream *substream); |
| 136 | |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 137 | u32 h_mixer; |
| 138 | struct clk_cache cc; |
| 139 | |
Eliot Blennerhassett | f3d145a | 2011-04-05 20:55:44 +1200 | [diff] [blame] | 140 | u16 can_dma; |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 141 | u16 support_grouping; |
| 142 | u16 support_mrx; |
| 143 | u16 update_interval_frames; |
| 144 | u16 in_max_chans; |
| 145 | u16 out_max_chans; |
Eliot Blennerhassett | c382a5d | 2011-12-22 13:38:33 +1300 | [diff] [blame] | 146 | u16 in_min_chans; |
| 147 | u16 out_min_chans; |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 148 | }; |
| 149 | |
| 150 | /* Per stream data */ |
| 151 | struct snd_card_asihpi_pcm { |
| 152 | struct timer_list timer; |
| 153 | unsigned int respawn_timer; |
| 154 | unsigned int hpi_buffer_attached; |
Eliot Blennerhassett | ba94455 | 2011-02-10 17:26:04 +1300 | [diff] [blame] | 155 | unsigned int buffer_bytes; |
| 156 | unsigned int period_bytes; |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 157 | unsigned int bytes_per_sec; |
Eliot Blennerhassett | e64b1a2 | 2011-02-10 17:25:59 +1300 | [diff] [blame] | 158 | unsigned int pcm_buf_host_rw_ofs; /* Host R/W pos */ |
| 159 | unsigned int pcm_buf_dma_ofs; /* DMA R/W offset in buffer */ |
| 160 | unsigned int pcm_buf_elapsed_dma_ofs; /* DMA R/W offset in buffer */ |
Eliot Blennerhassett | 0b7ce9e | 2011-04-05 20:55:43 +1200 | [diff] [blame] | 161 | unsigned int drained_count; |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 162 | struct snd_pcm_substream *substream; |
| 163 | u32 h_stream; |
| 164 | struct hpi_format format; |
| 165 | }; |
| 166 | |
| 167 | /* universal stream verbs work with out or in stream handles */ |
| 168 | |
| 169 | /* Functions to allow driver to give a buffer to HPI for busmastering */ |
| 170 | |
| 171 | static u16 hpi_stream_host_buffer_attach( |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 172 | u32 h_stream, /* handle to outstream. */ |
| 173 | u32 size_in_bytes, /* size in bytes of bus mastering buffer */ |
| 174 | u32 pci_address |
| 175 | ) |
| 176 | { |
| 177 | struct hpi_message hm; |
| 178 | struct hpi_response hr; |
| 179 | unsigned int obj = hpi_handle_object(h_stream); |
| 180 | |
| 181 | if (!h_stream) |
| 182 | return HPI_ERROR_INVALID_OBJ; |
| 183 | hpi_init_message_response(&hm, &hr, obj, |
| 184 | obj == HPI_OBJ_OSTREAM ? |
| 185 | HPI_OSTREAM_HOSTBUFFER_ALLOC : |
| 186 | HPI_ISTREAM_HOSTBUFFER_ALLOC); |
| 187 | |
| 188 | hpi_handle_to_indexes(h_stream, &hm.adapter_index, |
| 189 | &hm.obj_index); |
| 190 | |
| 191 | hm.u.d.u.buffer.buffer_size = size_in_bytes; |
| 192 | hm.u.d.u.buffer.pci_address = pci_address; |
| 193 | hm.u.d.u.buffer.command = HPI_BUFFER_CMD_INTERNAL_GRANTADAPTER; |
| 194 | hpi_send_recv(&hm, &hr); |
| 195 | return hr.error; |
| 196 | } |
| 197 | |
Eliot Blennerhassett | ba94455 | 2011-02-10 17:26:04 +1300 | [diff] [blame] | 198 | static u16 hpi_stream_host_buffer_detach(u32 h_stream) |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 199 | { |
| 200 | struct hpi_message hm; |
| 201 | struct hpi_response hr; |
| 202 | unsigned int obj = hpi_handle_object(h_stream); |
| 203 | |
| 204 | if (!h_stream) |
| 205 | return HPI_ERROR_INVALID_OBJ; |
| 206 | |
| 207 | hpi_init_message_response(&hm, &hr, obj, |
| 208 | obj == HPI_OBJ_OSTREAM ? |
| 209 | HPI_OSTREAM_HOSTBUFFER_FREE : |
| 210 | HPI_ISTREAM_HOSTBUFFER_FREE); |
| 211 | |
| 212 | hpi_handle_to_indexes(h_stream, &hm.adapter_index, |
| 213 | &hm.obj_index); |
| 214 | hm.u.d.u.buffer.command = HPI_BUFFER_CMD_INTERNAL_REVOKEADAPTER; |
| 215 | hpi_send_recv(&hm, &hr); |
| 216 | return hr.error; |
| 217 | } |
| 218 | |
Eliot Blennerhassett | ba94455 | 2011-02-10 17:26:04 +1300 | [diff] [blame] | 219 | static inline u16 hpi_stream_start(u32 h_stream) |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 220 | { |
| 221 | if (hpi_handle_object(h_stream) == HPI_OBJ_OSTREAM) |
Eliot Blennerhassett | ba94455 | 2011-02-10 17:26:04 +1300 | [diff] [blame] | 222 | return hpi_outstream_start(h_stream); |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 223 | else |
Eliot Blennerhassett | ba94455 | 2011-02-10 17:26:04 +1300 | [diff] [blame] | 224 | return hpi_instream_start(h_stream); |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 225 | } |
| 226 | |
Eliot Blennerhassett | ba94455 | 2011-02-10 17:26:04 +1300 | [diff] [blame] | 227 | static inline u16 hpi_stream_stop(u32 h_stream) |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 228 | { |
| 229 | if (hpi_handle_object(h_stream) == HPI_OBJ_OSTREAM) |
Eliot Blennerhassett | ba94455 | 2011-02-10 17:26:04 +1300 | [diff] [blame] | 230 | return hpi_outstream_stop(h_stream); |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 231 | else |
Eliot Blennerhassett | ba94455 | 2011-02-10 17:26:04 +1300 | [diff] [blame] | 232 | return hpi_instream_stop(h_stream); |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 233 | } |
| 234 | |
| 235 | static inline u16 hpi_stream_get_info_ex( |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 236 | u32 h_stream, |
| 237 | u16 *pw_state, |
| 238 | u32 *pbuffer_size, |
| 239 | u32 *pdata_in_buffer, |
| 240 | u32 *psample_count, |
| 241 | u32 *pauxiliary_data |
| 242 | ) |
| 243 | { |
Eliot Blennerhassett | e64b1a2 | 2011-02-10 17:25:59 +1300 | [diff] [blame] | 244 | u16 e; |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 245 | if (hpi_handle_object(h_stream) == HPI_OBJ_OSTREAM) |
Eliot Blennerhassett | ba94455 | 2011-02-10 17:26:04 +1300 | [diff] [blame] | 246 | e = hpi_outstream_get_info_ex(h_stream, pw_state, |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 247 | pbuffer_size, pdata_in_buffer, |
| 248 | psample_count, pauxiliary_data); |
| 249 | else |
Eliot Blennerhassett | ba94455 | 2011-02-10 17:26:04 +1300 | [diff] [blame] | 250 | e = hpi_instream_get_info_ex(h_stream, pw_state, |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 251 | pbuffer_size, pdata_in_buffer, |
| 252 | psample_count, pauxiliary_data); |
Eliot Blennerhassett | e64b1a2 | 2011-02-10 17:25:59 +1300 | [diff] [blame] | 253 | return e; |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 254 | } |
| 255 | |
Eliot Blennerhassett | ba94455 | 2011-02-10 17:26:04 +1300 | [diff] [blame] | 256 | static inline u16 hpi_stream_group_add( |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 257 | u32 h_master, |
| 258 | u32 h_stream) |
| 259 | { |
| 260 | if (hpi_handle_object(h_master) == HPI_OBJ_OSTREAM) |
Eliot Blennerhassett | ba94455 | 2011-02-10 17:26:04 +1300 | [diff] [blame] | 261 | return hpi_outstream_group_add(h_master, h_stream); |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 262 | else |
Eliot Blennerhassett | ba94455 | 2011-02-10 17:26:04 +1300 | [diff] [blame] | 263 | return hpi_instream_group_add(h_master, h_stream); |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 264 | } |
| 265 | |
Eliot Blennerhassett | ba94455 | 2011-02-10 17:26:04 +1300 | [diff] [blame] | 266 | static inline u16 hpi_stream_group_reset(u32 h_stream) |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 267 | { |
| 268 | if (hpi_handle_object(h_stream) == HPI_OBJ_OSTREAM) |
Eliot Blennerhassett | ba94455 | 2011-02-10 17:26:04 +1300 | [diff] [blame] | 269 | return hpi_outstream_group_reset(h_stream); |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 270 | else |
Eliot Blennerhassett | ba94455 | 2011-02-10 17:26:04 +1300 | [diff] [blame] | 271 | return hpi_instream_group_reset(h_stream); |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 272 | } |
| 273 | |
Eliot Blennerhassett | ba94455 | 2011-02-10 17:26:04 +1300 | [diff] [blame] | 274 | static inline u16 hpi_stream_group_get_map( |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 275 | u32 h_stream, u32 *mo, u32 *mi) |
| 276 | { |
| 277 | if (hpi_handle_object(h_stream) == HPI_OBJ_OSTREAM) |
Eliot Blennerhassett | ba94455 | 2011-02-10 17:26:04 +1300 | [diff] [blame] | 278 | return hpi_outstream_group_get_map(h_stream, mo, mi); |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 279 | else |
Eliot Blennerhassett | ba94455 | 2011-02-10 17:26:04 +1300 | [diff] [blame] | 280 | return hpi_instream_group_get_map(h_stream, mo, mi); |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 281 | } |
| 282 | |
| 283 | static u16 handle_error(u16 err, int line, char *filename) |
| 284 | { |
| 285 | if (err) |
| 286 | printk(KERN_WARNING |
| 287 | "in file %s, line %d: HPI error %d\n", |
| 288 | filename, line, err); |
| 289 | return err; |
| 290 | } |
| 291 | |
| 292 | #define hpi_handle_error(x) handle_error(x, __LINE__, __FILE__) |
| 293 | |
| 294 | /***************************** GENERAL PCM ****************/ |
Eliot Blennerhassett | a647713 | 2011-04-05 20:55:42 +1200 | [diff] [blame] | 295 | |
| 296 | static void print_hwparams(struct snd_pcm_substream *substream, |
| 297 | struct snd_pcm_hw_params *p) |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 298 | { |
Eliot Blennerhassett | 0a17e99 | 2011-07-22 15:52:44 +1200 | [diff] [blame] | 299 | char name[16]; |
| 300 | snd_pcm_debug_name(substream, name, sizeof(name)); |
Eliot Blennerhassett | 35a8dc1 | 2014-11-20 16:22:50 +1300 | [diff] [blame] | 301 | snd_printdd("%s HWPARAMS\n", name); |
| 302 | snd_printdd(" samplerate=%dHz channels=%d format=%d subformat=%d\n", |
| 303 | params_rate(p), params_channels(p), |
| 304 | params_format(p), params_subformat(p)); |
| 305 | snd_printdd(" buffer=%dB period=%dB period_size=%dB periods=%d\n", |
| 306 | params_buffer_bytes(p), params_period_bytes(p), |
| 307 | params_period_size(p), params_periods(p)); |
| 308 | snd_printdd(" buffer_size=%d access=%d data_rate=%dB/s\n", |
| 309 | params_buffer_size(p), params_access(p), |
| 310 | params_rate(p) * params_channels(p) * |
Eliot Blennerhassett | a647713 | 2011-04-05 20:55:42 +1200 | [diff] [blame] | 311 | snd_pcm_format_width(params_format(p)) / 8); |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 312 | } |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 313 | |
| 314 | static snd_pcm_format_t hpi_to_alsa_formats[] = { |
| 315 | -1, /* INVALID */ |
| 316 | SNDRV_PCM_FORMAT_U8, /* HPI_FORMAT_PCM8_UNSIGNED 1 */ |
| 317 | SNDRV_PCM_FORMAT_S16, /* HPI_FORMAT_PCM16_SIGNED 2 */ |
| 318 | -1, /* HPI_FORMAT_MPEG_L1 3 */ |
| 319 | SNDRV_PCM_FORMAT_MPEG, /* HPI_FORMAT_MPEG_L2 4 */ |
| 320 | SNDRV_PCM_FORMAT_MPEG, /* HPI_FORMAT_MPEG_L3 5 */ |
| 321 | -1, /* HPI_FORMAT_DOLBY_AC2 6 */ |
| 322 | -1, /* HPI_FORMAT_DOLBY_AC3 7 */ |
| 323 | SNDRV_PCM_FORMAT_S16_BE,/* HPI_FORMAT_PCM16_BIGENDIAN 8 */ |
| 324 | -1, /* HPI_FORMAT_AA_TAGIT1_HITS 9 */ |
| 325 | -1, /* HPI_FORMAT_AA_TAGIT1_INSERTS 10 */ |
| 326 | SNDRV_PCM_FORMAT_S32, /* HPI_FORMAT_PCM32_SIGNED 11 */ |
| 327 | -1, /* HPI_FORMAT_RAW_BITSTREAM 12 */ |
| 328 | -1, /* HPI_FORMAT_AA_TAGIT1_HITS_EX1 13 */ |
| 329 | SNDRV_PCM_FORMAT_FLOAT, /* HPI_FORMAT_PCM32_FLOAT 14 */ |
| 330 | #if 1 |
| 331 | /* ALSA can't handle 3 byte sample size together with power-of-2 |
| 332 | * constraint on buffer_bytes, so disable this format |
| 333 | */ |
| 334 | -1 |
| 335 | #else |
Eliot Blennerhassett | ba94455 | 2011-02-10 17:26:04 +1300 | [diff] [blame] | 336 | /* SNDRV_PCM_FORMAT_S24_3LE */ /* HPI_FORMAT_PCM24_SIGNED 15 */ |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 337 | #endif |
| 338 | }; |
| 339 | |
| 340 | |
| 341 | static int snd_card_asihpi_format_alsa2hpi(snd_pcm_format_t alsa_format, |
| 342 | u16 *hpi_format) |
| 343 | { |
| 344 | u16 format; |
| 345 | |
| 346 | for (format = HPI_FORMAT_PCM8_UNSIGNED; |
| 347 | format <= HPI_FORMAT_PCM24_SIGNED; format++) { |
| 348 | if (hpi_to_alsa_formats[format] == alsa_format) { |
| 349 | *hpi_format = format; |
| 350 | return 0; |
| 351 | } |
| 352 | } |
| 353 | |
| 354 | snd_printd(KERN_WARNING "failed match for alsa format %d\n", |
| 355 | alsa_format); |
| 356 | *hpi_format = 0; |
| 357 | return -EINVAL; |
| 358 | } |
| 359 | |
| 360 | static void snd_card_asihpi_pcm_samplerates(struct snd_card_asihpi *asihpi, |
| 361 | struct snd_pcm_hardware *pcmhw) |
| 362 | { |
| 363 | u16 err; |
| 364 | u32 h_control; |
| 365 | u32 sample_rate; |
| 366 | int idx; |
| 367 | unsigned int rate_min = 200000; |
| 368 | unsigned int rate_max = 0; |
| 369 | unsigned int rates = 0; |
| 370 | |
| 371 | if (asihpi->support_mrx) { |
| 372 | rates |= SNDRV_PCM_RATE_CONTINUOUS; |
| 373 | rates |= SNDRV_PCM_RATE_8000_96000; |
| 374 | rate_min = 8000; |
| 375 | rate_max = 100000; |
| 376 | } else { |
| 377 | /* on cards without SRC, |
| 378 | valid rates are determined by sampleclock */ |
Eliot Blennerhassett | ba94455 | 2011-02-10 17:26:04 +1300 | [diff] [blame] | 379 | err = hpi_mixer_get_control(asihpi->h_mixer, |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 380 | HPI_SOURCENODE_CLOCK_SOURCE, 0, 0, 0, |
| 381 | HPI_CONTROL_SAMPLECLOCK, &h_control); |
| 382 | if (err) { |
Eliot Blennerhassett | 12eb089 | 2014-11-20 16:22:55 +1300 | [diff] [blame] | 383 | dev_err(&asihpi->pci->dev, |
Eliot Blennerhassett | e64b1a2 | 2011-02-10 17:25:59 +1300 | [diff] [blame] | 384 | "No local sampleclock, err %d\n", err); |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 385 | } |
| 386 | |
Eliot Blennerhassett | 7bf76c3 | 2011-03-25 15:25:46 +1300 | [diff] [blame] | 387 | for (idx = -1; idx < 100; idx++) { |
| 388 | if (idx == -1) { |
| 389 | if (hpi_sample_clock_get_sample_rate(h_control, |
| 390 | &sample_rate)) |
| 391 | continue; |
| 392 | } else if (hpi_sample_clock_query_local_rate(h_control, |
| 393 | idx, &sample_rate)) { |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 394 | break; |
| 395 | } |
| 396 | |
| 397 | rate_min = min(rate_min, sample_rate); |
| 398 | rate_max = max(rate_max, sample_rate); |
| 399 | |
| 400 | switch (sample_rate) { |
| 401 | case 5512: |
| 402 | rates |= SNDRV_PCM_RATE_5512; |
| 403 | break; |
| 404 | case 8000: |
| 405 | rates |= SNDRV_PCM_RATE_8000; |
| 406 | break; |
| 407 | case 11025: |
| 408 | rates |= SNDRV_PCM_RATE_11025; |
| 409 | break; |
| 410 | case 16000: |
| 411 | rates |= SNDRV_PCM_RATE_16000; |
| 412 | break; |
| 413 | case 22050: |
| 414 | rates |= SNDRV_PCM_RATE_22050; |
| 415 | break; |
| 416 | case 32000: |
| 417 | rates |= SNDRV_PCM_RATE_32000; |
| 418 | break; |
| 419 | case 44100: |
| 420 | rates |= SNDRV_PCM_RATE_44100; |
| 421 | break; |
| 422 | case 48000: |
| 423 | rates |= SNDRV_PCM_RATE_48000; |
| 424 | break; |
| 425 | case 64000: |
| 426 | rates |= SNDRV_PCM_RATE_64000; |
| 427 | break; |
| 428 | case 88200: |
| 429 | rates |= SNDRV_PCM_RATE_88200; |
| 430 | break; |
| 431 | case 96000: |
| 432 | rates |= SNDRV_PCM_RATE_96000; |
| 433 | break; |
| 434 | case 176400: |
| 435 | rates |= SNDRV_PCM_RATE_176400; |
| 436 | break; |
| 437 | case 192000: |
| 438 | rates |= SNDRV_PCM_RATE_192000; |
| 439 | break; |
| 440 | default: /* some other rate */ |
| 441 | rates |= SNDRV_PCM_RATE_KNOT; |
| 442 | } |
| 443 | } |
| 444 | } |
| 445 | |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 446 | pcmhw->rates = rates; |
| 447 | pcmhw->rate_min = rate_min; |
| 448 | pcmhw->rate_max = rate_max; |
| 449 | } |
| 450 | |
| 451 | static int snd_card_asihpi_pcm_hw_params(struct snd_pcm_substream *substream, |
| 452 | struct snd_pcm_hw_params *params) |
| 453 | { |
| 454 | struct snd_pcm_runtime *runtime = substream->runtime; |
| 455 | struct snd_card_asihpi_pcm *dpcm = runtime->private_data; |
| 456 | struct snd_card_asihpi *card = snd_pcm_substream_chip(substream); |
| 457 | int err; |
| 458 | u16 format; |
Kulikov Vasiliy | 315e8f7 | 2010-07-15 22:48:19 +0400 | [diff] [blame] | 459 | int width; |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 460 | unsigned int bytes_per_sec; |
| 461 | |
Eliot Blennerhassett | a647713 | 2011-04-05 20:55:42 +1200 | [diff] [blame] | 462 | print_hwparams(substream, params); |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 463 | err = snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(params)); |
| 464 | if (err < 0) |
| 465 | return err; |
| 466 | err = snd_card_asihpi_format_alsa2hpi(params_format(params), &format); |
| 467 | if (err) |
| 468 | return err; |
| 469 | |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 470 | hpi_handle_error(hpi_format_create(&dpcm->format, |
| 471 | params_channels(params), |
| 472 | format, params_rate(params), 0, 0)); |
| 473 | |
| 474 | if (substream->stream == SNDRV_PCM_STREAM_CAPTURE) { |
Eliot Blennerhassett | ba94455 | 2011-02-10 17:26:04 +1300 | [diff] [blame] | 475 | if (hpi_instream_reset(dpcm->h_stream) != 0) |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 476 | return -EINVAL; |
| 477 | |
Eliot Blennerhassett | ba94455 | 2011-02-10 17:26:04 +1300 | [diff] [blame] | 478 | if (hpi_instream_set_format( |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 479 | dpcm->h_stream, &dpcm->format) != 0) |
| 480 | return -EINVAL; |
| 481 | } |
| 482 | |
| 483 | dpcm->hpi_buffer_attached = 0; |
Eliot Blennerhassett | f3d145a | 2011-04-05 20:55:44 +1200 | [diff] [blame] | 484 | if (card->can_dma) { |
Eliot Blennerhassett | ba94455 | 2011-02-10 17:26:04 +1300 | [diff] [blame] | 485 | err = hpi_stream_host_buffer_attach(dpcm->h_stream, |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 486 | params_buffer_bytes(params), runtime->dma_addr); |
| 487 | if (err == 0) { |
Eliot Blennerhassett | b2e65c8 | 2011-03-25 15:25:48 +1300 | [diff] [blame] | 488 | snd_printdd( |
Eliot Blennerhassett | 35a8dc1 | 2014-11-20 16:22:50 +1300 | [diff] [blame] | 489 | "stream_host_buffer_attach success %u %lu\n", |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 490 | params_buffer_bytes(params), |
| 491 | (unsigned long)runtime->dma_addr); |
| 492 | } else { |
Eliot Blennerhassett | b2e65c8 | 2011-03-25 15:25:48 +1300 | [diff] [blame] | 493 | snd_printd("stream_host_buffer_attach error %d\n", |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 494 | err); |
| 495 | return -ENOMEM; |
| 496 | } |
| 497 | |
Eliot Blennerhassett | ba94455 | 2011-02-10 17:26:04 +1300 | [diff] [blame] | 498 | err = hpi_stream_get_info_ex(dpcm->h_stream, NULL, |
Eliot Blennerhassett | 35a8dc1 | 2014-11-20 16:22:50 +1300 | [diff] [blame] | 499 | &dpcm->hpi_buffer_attached, NULL, NULL, NULL); |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 500 | } |
| 501 | bytes_per_sec = params_rate(params) * params_channels(params); |
Kulikov Vasiliy | 315e8f7 | 2010-07-15 22:48:19 +0400 | [diff] [blame] | 502 | width = snd_pcm_format_width(params_format(params)); |
| 503 | bytes_per_sec *= width; |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 504 | bytes_per_sec /= 8; |
Kulikov Vasiliy | 315e8f7 | 2010-07-15 22:48:19 +0400 | [diff] [blame] | 505 | if (width < 0 || bytes_per_sec == 0) |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 506 | return -EINVAL; |
| 507 | |
| 508 | dpcm->bytes_per_sec = bytes_per_sec; |
Eliot Blennerhassett | ba94455 | 2011-02-10 17:26:04 +1300 | [diff] [blame] | 509 | dpcm->buffer_bytes = params_buffer_bytes(params); |
| 510 | dpcm->period_bytes = params_period_bytes(params); |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 511 | |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 512 | return 0; |
| 513 | } |
| 514 | |
Eliot Blennerhassett | e64b1a2 | 2011-02-10 17:25:59 +1300 | [diff] [blame] | 515 | static int |
| 516 | snd_card_asihpi_hw_free(struct snd_pcm_substream *substream) |
| 517 | { |
| 518 | struct snd_pcm_runtime *runtime = substream->runtime; |
| 519 | struct snd_card_asihpi_pcm *dpcm = runtime->private_data; |
| 520 | if (dpcm->hpi_buffer_attached) |
Eliot Blennerhassett | ba94455 | 2011-02-10 17:26:04 +1300 | [diff] [blame] | 521 | hpi_stream_host_buffer_detach(dpcm->h_stream); |
Eliot Blennerhassett | e64b1a2 | 2011-02-10 17:25:59 +1300 | [diff] [blame] | 522 | |
| 523 | snd_pcm_lib_free_pages(substream); |
| 524 | return 0; |
| 525 | } |
| 526 | |
| 527 | static void snd_card_asihpi_runtime_free(struct snd_pcm_runtime *runtime) |
| 528 | { |
| 529 | struct snd_card_asihpi_pcm *dpcm = runtime->private_data; |
| 530 | kfree(dpcm); |
| 531 | } |
| 532 | |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 533 | static void snd_card_asihpi_pcm_timer_start(struct snd_pcm_substream * |
| 534 | substream) |
| 535 | { |
| 536 | struct snd_pcm_runtime *runtime = substream->runtime; |
| 537 | struct snd_card_asihpi_pcm *dpcm = runtime->private_data; |
| 538 | int expiry; |
| 539 | |
Eliot Blennerhassett | ba94455 | 2011-02-10 17:26:04 +1300 | [diff] [blame] | 540 | expiry = HZ / 200; |
Eliot Blennerhassett | e9886ab | 2014-11-20 16:22:48 +1300 | [diff] [blame] | 541 | |
Eliot Blennerhassett | e64b1a2 | 2011-02-10 17:25:59 +1300 | [diff] [blame] | 542 | expiry = max(expiry, 1); /* don't let it be zero! */ |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 543 | dpcm->timer.expires = jiffies + expiry; |
| 544 | dpcm->respawn_timer = 1; |
| 545 | add_timer(&dpcm->timer); |
| 546 | } |
| 547 | |
| 548 | static void snd_card_asihpi_pcm_timer_stop(struct snd_pcm_substream *substream) |
| 549 | { |
| 550 | struct snd_pcm_runtime *runtime = substream->runtime; |
| 551 | struct snd_card_asihpi_pcm *dpcm = runtime->private_data; |
| 552 | |
| 553 | dpcm->respawn_timer = 0; |
| 554 | del_timer(&dpcm->timer); |
| 555 | } |
| 556 | |
Eliot Blennerhassett | f9a376c | 2014-11-20 16:22:53 +1300 | [diff] [blame] | 557 | static void snd_card_asihpi_pcm_int_start(struct snd_pcm_substream *substream) |
| 558 | { |
| 559 | struct snd_card_asihpi_pcm *dpcm; |
| 560 | struct snd_card_asihpi *card; |
| 561 | |
| 562 | BUG_ON(!substream); |
| 563 | |
| 564 | dpcm = (struct snd_card_asihpi_pcm *)substream->runtime->private_data; |
| 565 | card = snd_pcm_substream_chip(substream); |
| 566 | |
| 567 | BUG_ON(in_interrupt()); |
| 568 | tasklet_disable(&card->t); |
| 569 | card->llmode_streampriv = dpcm; |
| 570 | tasklet_enable(&card->t); |
| 571 | |
| 572 | hpi_handle_error(hpi_adapter_set_property(card->hpi->adapter->index, |
| 573 | HPI_ADAPTER_PROPERTY_IRQ_RATE, |
| 574 | card->update_interval_frames, 0)); |
| 575 | } |
| 576 | |
| 577 | static void snd_card_asihpi_pcm_int_stop(struct snd_pcm_substream *substream) |
| 578 | { |
| 579 | struct snd_card_asihpi_pcm *dpcm; |
| 580 | struct snd_card_asihpi *card; |
| 581 | |
| 582 | BUG_ON(!substream); |
| 583 | |
| 584 | dpcm = (struct snd_card_asihpi_pcm *)substream->runtime->private_data; |
| 585 | card = snd_pcm_substream_chip(substream); |
| 586 | |
| 587 | hpi_handle_error(hpi_adapter_set_property(card->hpi->adapter->index, |
| 588 | HPI_ADAPTER_PROPERTY_IRQ_RATE, 0, 0)); |
| 589 | |
| 590 | if (in_interrupt()) |
| 591 | card->llmode_streampriv = NULL; |
| 592 | else { |
| 593 | tasklet_disable(&card->t); |
| 594 | card->llmode_streampriv = NULL; |
| 595 | tasklet_enable(&card->t); |
| 596 | } |
| 597 | } |
| 598 | |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 599 | static int snd_card_asihpi_trigger(struct snd_pcm_substream *substream, |
| 600 | int cmd) |
| 601 | { |
| 602 | struct snd_card_asihpi_pcm *dpcm = substream->runtime->private_data; |
| 603 | struct snd_card_asihpi *card = snd_pcm_substream_chip(substream); |
| 604 | struct snd_pcm_substream *s; |
| 605 | u16 e; |
Eliot Blennerhassett | 0a17e99 | 2011-07-22 15:52:44 +1200 | [diff] [blame] | 606 | char name[16]; |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 607 | |
Eliot Blennerhassett | 0a17e99 | 2011-07-22 15:52:44 +1200 | [diff] [blame] | 608 | snd_pcm_debug_name(substream, name, sizeof(name)); |
Eliot Blennerhassett | a647713 | 2011-04-05 20:55:42 +1200 | [diff] [blame] | 609 | |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 610 | switch (cmd) { |
| 611 | case SNDRV_PCM_TRIGGER_START: |
Eliot Blennerhassett | 35a8dc1 | 2014-11-20 16:22:50 +1300 | [diff] [blame] | 612 | snd_printdd("%s trigger start\n", name); |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 613 | snd_pcm_group_for_each_entry(s, substream) { |
Eliot Blennerhassett | e64b1a2 | 2011-02-10 17:25:59 +1300 | [diff] [blame] | 614 | struct snd_pcm_runtime *runtime = s->runtime; |
| 615 | struct snd_card_asihpi_pcm *ds = runtime->private_data; |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 616 | |
| 617 | if (snd_pcm_substream_chip(s) != card) |
| 618 | continue; |
| 619 | |
Eliot Blennerhassett | ba94455 | 2011-02-10 17:26:04 +1300 | [diff] [blame] | 620 | /* don't link Cap and Play */ |
| 621 | if (substream->stream != s->stream) |
| 622 | continue; |
| 623 | |
Eliot Blennerhassett | 0b7ce9e | 2011-04-05 20:55:43 +1200 | [diff] [blame] | 624 | ds->drained_count = 0; |
Eliot Blennerhassett | f3d145a | 2011-04-05 20:55:44 +1200 | [diff] [blame] | 625 | if (s->stream == SNDRV_PCM_STREAM_PLAYBACK) { |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 626 | /* How do I know how much valid data is present |
Eliot Blennerhassett | e64b1a2 | 2011-02-10 17:25:59 +1300 | [diff] [blame] | 627 | * in buffer? Must be at least one period! |
| 628 | * Guessing 2 periods, but if |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 629 | * buffer is bigger it may contain even more |
| 630 | * data?? |
| 631 | */ |
Eliot Blennerhassett | ba94455 | 2011-02-10 17:26:04 +1300 | [diff] [blame] | 632 | unsigned int preload = ds->period_bytes * 1; |
Eliot Blennerhassett | 35a8dc1 | 2014-11-20 16:22:50 +1300 | [diff] [blame] | 633 | snd_printddd("%d preload %d\n", s->number, preload); |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 634 | hpi_handle_error(hpi_outstream_write_buf( |
Eliot Blennerhassett | ba94455 | 2011-02-10 17:26:04 +1300 | [diff] [blame] | 635 | ds->h_stream, |
Eliot Blennerhassett | e64b1a2 | 2011-02-10 17:25:59 +1300 | [diff] [blame] | 636 | &runtime->dma_area[0], |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 637 | preload, |
| 638 | &ds->format)); |
Eliot Blennerhassett | e64b1a2 | 2011-02-10 17:25:59 +1300 | [diff] [blame] | 639 | ds->pcm_buf_host_rw_ofs = preload; |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 640 | } |
| 641 | |
| 642 | if (card->support_grouping) { |
Eliot Blennerhassett | a647713 | 2011-04-05 20:55:42 +1200 | [diff] [blame] | 643 | snd_printdd("%d group\n", s->number); |
Eliot Blennerhassett | ba94455 | 2011-02-10 17:26:04 +1300 | [diff] [blame] | 644 | e = hpi_stream_group_add( |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 645 | dpcm->h_stream, |
| 646 | ds->h_stream); |
| 647 | if (!e) { |
| 648 | snd_pcm_trigger_done(s, substream); |
| 649 | } else { |
| 650 | hpi_handle_error(e); |
| 651 | break; |
| 652 | } |
| 653 | } else |
| 654 | break; |
| 655 | } |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 656 | /* start the master stream */ |
Eliot Blennerhassett | f9a376c | 2014-11-20 16:22:53 +1300 | [diff] [blame] | 657 | card->pcm_start(substream); |
Eliot Blennerhassett | c4ed97d | 2011-02-10 17:26:20 +1300 | [diff] [blame] | 658 | if ((substream->stream == SNDRV_PCM_STREAM_CAPTURE) || |
Eliot Blennerhassett | f3d145a | 2011-04-05 20:55:44 +1200 | [diff] [blame] | 659 | !card->can_dma) |
Eliot Blennerhassett | ba94455 | 2011-02-10 17:26:04 +1300 | [diff] [blame] | 660 | hpi_handle_error(hpi_stream_start(dpcm->h_stream)); |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 661 | break; |
| 662 | |
| 663 | case SNDRV_PCM_TRIGGER_STOP: |
Eliot Blennerhassett | 35a8dc1 | 2014-11-20 16:22:50 +1300 | [diff] [blame] | 664 | snd_printdd("%s trigger stop\n", name); |
Eliot Blennerhassett | f9a376c | 2014-11-20 16:22:53 +1300 | [diff] [blame] | 665 | card->pcm_stop(substream); |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 666 | snd_pcm_group_for_each_entry(s, substream) { |
| 667 | if (snd_pcm_substream_chip(s) != card) |
| 668 | continue; |
Eliot Blennerhassett | ba94455 | 2011-02-10 17:26:04 +1300 | [diff] [blame] | 669 | /* don't link Cap and Play */ |
| 670 | if (substream->stream != s->stream) |
| 671 | continue; |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 672 | |
| 673 | /*? workaround linked streams don't |
| 674 | transition to SETUP 20070706*/ |
| 675 | s->runtime->status->state = SNDRV_PCM_STATE_SETUP; |
| 676 | |
| 677 | if (card->support_grouping) { |
Eliot Blennerhassett | a647713 | 2011-04-05 20:55:42 +1200 | [diff] [blame] | 678 | snd_printdd("%d group\n", s->number); |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 679 | snd_pcm_trigger_done(s, substream); |
| 680 | } else |
| 681 | break; |
| 682 | } |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 683 | |
| 684 | /* _prepare and _hwparams reset the stream */ |
Eliot Blennerhassett | ba94455 | 2011-02-10 17:26:04 +1300 | [diff] [blame] | 685 | hpi_handle_error(hpi_stream_stop(dpcm->h_stream)); |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 686 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) |
| 687 | hpi_handle_error( |
Eliot Blennerhassett | ba94455 | 2011-02-10 17:26:04 +1300 | [diff] [blame] | 688 | hpi_outstream_reset(dpcm->h_stream)); |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 689 | |
| 690 | if (card->support_grouping) |
Eliot Blennerhassett | ba94455 | 2011-02-10 17:26:04 +1300 | [diff] [blame] | 691 | hpi_handle_error(hpi_stream_group_reset(dpcm->h_stream)); |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 692 | break; |
| 693 | |
| 694 | case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: |
Eliot Blennerhassett | 35a8dc1 | 2014-11-20 16:22:50 +1300 | [diff] [blame] | 695 | snd_printdd("%s trigger pause release\n", name); |
Eliot Blennerhassett | f9a376c | 2014-11-20 16:22:53 +1300 | [diff] [blame] | 696 | card->pcm_start(substream); |
Eliot Blennerhassett | ba94455 | 2011-02-10 17:26:04 +1300 | [diff] [blame] | 697 | hpi_handle_error(hpi_stream_start(dpcm->h_stream)); |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 698 | break; |
| 699 | case SNDRV_PCM_TRIGGER_PAUSE_PUSH: |
Eliot Blennerhassett | 35a8dc1 | 2014-11-20 16:22:50 +1300 | [diff] [blame] | 700 | snd_printdd("%s trigger pause push\n", name); |
Eliot Blennerhassett | f9a376c | 2014-11-20 16:22:53 +1300 | [diff] [blame] | 701 | card->pcm_stop(substream); |
Eliot Blennerhassett | ba94455 | 2011-02-10 17:26:04 +1300 | [diff] [blame] | 702 | hpi_handle_error(hpi_stream_stop(dpcm->h_stream)); |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 703 | break; |
| 704 | default: |
Eliot Blennerhassett | ba94455 | 2011-02-10 17:26:04 +1300 | [diff] [blame] | 705 | snd_printd(KERN_ERR "\tINVALID\n"); |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 706 | return -EINVAL; |
| 707 | } |
| 708 | |
| 709 | return 0; |
| 710 | } |
| 711 | |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 712 | /*algorithm outline |
| 713 | Without linking degenerates to getting single stream pos etc |
| 714 | Without mmap 2nd loop degenerates to snd_pcm_period_elapsed |
| 715 | */ |
| 716 | /* |
Eliot Blennerhassett | e64b1a2 | 2011-02-10 17:25:59 +1300 | [diff] [blame] | 717 | pcm_buf_dma_ofs=get_buf_pos(s); |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 718 | for_each_linked_stream(s) { |
Eliot Blennerhassett | e64b1a2 | 2011-02-10 17:25:59 +1300 | [diff] [blame] | 719 | pcm_buf_dma_ofs=get_buf_pos(s); |
Eliot Blennerhassett | ba94455 | 2011-02-10 17:26:04 +1300 | [diff] [blame] | 720 | min_buf_pos = modulo_min(min_buf_pos, pcm_buf_dma_ofs, buffer_bytes) |
Eliot Blennerhassett | e64b1a2 | 2011-02-10 17:25:59 +1300 | [diff] [blame] | 721 | new_data = min(new_data, calc_new_data(pcm_buf_dma_ofs,irq_pos) |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 722 | } |
| 723 | timer.expires = jiffies + predict_next_period_ready(min_buf_pos); |
| 724 | for_each_linked_stream(s) { |
Eliot Blennerhassett | e64b1a2 | 2011-02-10 17:25:59 +1300 | [diff] [blame] | 725 | s->pcm_buf_dma_ofs = min_buf_pos; |
Eliot Blennerhassett | ba94455 | 2011-02-10 17:26:04 +1300 | [diff] [blame] | 726 | if (new_data > period_bytes) { |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 727 | if (mmap) { |
Eliot Blennerhassett | ba94455 | 2011-02-10 17:26:04 +1300 | [diff] [blame] | 728 | irq_pos = (irq_pos + period_bytes) % buffer_bytes; |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 729 | if (playback) { |
Eliot Blennerhassett | ba94455 | 2011-02-10 17:26:04 +1300 | [diff] [blame] | 730 | write(period_bytes); |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 731 | } else { |
Eliot Blennerhassett | ba94455 | 2011-02-10 17:26:04 +1300 | [diff] [blame] | 732 | read(period_bytes); |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 733 | } |
| 734 | } |
| 735 | snd_pcm_period_elapsed(s); |
| 736 | } |
| 737 | } |
| 738 | */ |
| 739 | |
| 740 | /** Minimum of 2 modulo values. Works correctly when the difference between |
| 741 | * the values is less than half the modulus |
| 742 | */ |
| 743 | static inline unsigned int modulo_min(unsigned int a, unsigned int b, |
| 744 | unsigned long int modulus) |
| 745 | { |
| 746 | unsigned int result; |
| 747 | if (((a-b) % modulus) < (modulus/2)) |
| 748 | result = b; |
| 749 | else |
| 750 | result = a; |
| 751 | |
| 752 | return result; |
| 753 | } |
| 754 | |
| 755 | /** Timer function, equivalent to interrupt service routine for cards |
| 756 | */ |
| 757 | static void snd_card_asihpi_timer_function(unsigned long data) |
| 758 | { |
| 759 | struct snd_card_asihpi_pcm *dpcm = (struct snd_card_asihpi_pcm *)data; |
Eliot Blennerhassett | ba94455 | 2011-02-10 17:26:04 +1300 | [diff] [blame] | 760 | struct snd_pcm_substream *substream = dpcm->substream; |
| 761 | struct snd_card_asihpi *card = snd_pcm_substream_chip(substream); |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 762 | struct snd_pcm_runtime *runtime; |
| 763 | struct snd_pcm_substream *s; |
| 764 | unsigned int newdata = 0; |
Eliot Blennerhassett | e64b1a2 | 2011-02-10 17:25:59 +1300 | [diff] [blame] | 765 | unsigned int pcm_buf_dma_ofs, min_buf_pos = 0; |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 766 | unsigned int remdata, xfercount, next_jiffies; |
| 767 | int first = 1; |
Eliot Blennerhassett | ba94455 | 2011-02-10 17:26:04 +1300 | [diff] [blame] | 768 | int loops = 0; |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 769 | u16 state; |
Eliot Blennerhassett | e64b1a2 | 2011-02-10 17:25:59 +1300 | [diff] [blame] | 770 | u32 buffer_size, bytes_avail, samples_played, on_card_bytes; |
Eliot Blennerhassett | 0a17e99 | 2011-07-22 15:52:44 +1200 | [diff] [blame] | 771 | char name[16]; |
| 772 | |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 773 | |
Eliot Blennerhassett | f9a376c | 2014-11-20 16:22:53 +1300 | [diff] [blame] | 774 | snd_pcm_debug_name(substream, name, sizeof(name)); |
Eliot Blennerhassett | ba94455 | 2011-02-10 17:26:04 +1300 | [diff] [blame] | 775 | |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 776 | /* find minimum newdata and buffer pos in group */ |
Eliot Blennerhassett | ba94455 | 2011-02-10 17:26:04 +1300 | [diff] [blame] | 777 | snd_pcm_group_for_each_entry(s, substream) { |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 778 | struct snd_card_asihpi_pcm *ds = s->runtime->private_data; |
| 779 | runtime = s->runtime; |
| 780 | |
| 781 | if (snd_pcm_substream_chip(s) != card) |
| 782 | continue; |
| 783 | |
Eliot Blennerhassett | ba94455 | 2011-02-10 17:26:04 +1300 | [diff] [blame] | 784 | /* don't link Cap and Play */ |
| 785 | if (substream->stream != s->stream) |
| 786 | continue; |
| 787 | |
| 788 | hpi_handle_error(hpi_stream_get_info_ex( |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 789 | ds->h_stream, &state, |
Eliot Blennerhassett | e64b1a2 | 2011-02-10 17:25:59 +1300 | [diff] [blame] | 790 | &buffer_size, &bytes_avail, |
| 791 | &samples_played, &on_card_bytes)); |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 792 | |
| 793 | /* number of bytes in on-card buffer */ |
Eliot Blennerhassett | e64b1a2 | 2011-02-10 17:25:59 +1300 | [diff] [blame] | 794 | runtime->delay = on_card_bytes; |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 795 | |
Eliot Blennerhassett | f3d145a | 2011-04-05 20:55:44 +1200 | [diff] [blame] | 796 | if (!card->can_dma) |
| 797 | on_card_bytes = bytes_avail; |
| 798 | |
Eliot Blennerhassett | ba94455 | 2011-02-10 17:26:04 +1300 | [diff] [blame] | 799 | if (s->stream == SNDRV_PCM_STREAM_PLAYBACK) { |
Eliot Blennerhassett | e64b1a2 | 2011-02-10 17:25:59 +1300 | [diff] [blame] | 800 | pcm_buf_dma_ofs = ds->pcm_buf_host_rw_ofs - bytes_avail; |
Eliot Blennerhassett | ba94455 | 2011-02-10 17:26:04 +1300 | [diff] [blame] | 801 | if (state == HPI_STATE_STOPPED) { |
Eliot Blennerhassett | 0be55c4 | 2011-12-22 13:38:37 +1300 | [diff] [blame] | 802 | if (bytes_avail == 0) { |
Eliot Blennerhassett | ba94455 | 2011-02-10 17:26:04 +1300 | [diff] [blame] | 803 | hpi_handle_error(hpi_stream_start(ds->h_stream)); |
Eliot Blennerhassett | b2e65c8 | 2011-03-25 15:25:48 +1300 | [diff] [blame] | 804 | snd_printdd("P%d start\n", s->number); |
Eliot Blennerhassett | 0b7ce9e | 2011-04-05 20:55:43 +1200 | [diff] [blame] | 805 | ds->drained_count = 0; |
Eliot Blennerhassett | ba94455 | 2011-02-10 17:26:04 +1300 | [diff] [blame] | 806 | } |
| 807 | } else if (state == HPI_STATE_DRAINED) { |
Eliot Blennerhassett | b2e65c8 | 2011-03-25 15:25:48 +1300 | [diff] [blame] | 808 | snd_printd(KERN_WARNING "P%d drained\n", |
Eliot Blennerhassett | ba94455 | 2011-02-10 17:26:04 +1300 | [diff] [blame] | 809 | s->number); |
Eliot Blennerhassett | 0b7ce9e | 2011-04-05 20:55:43 +1200 | [diff] [blame] | 810 | ds->drained_count++; |
Eliot Blennerhassett | 0be55c4 | 2011-12-22 13:38:37 +1300 | [diff] [blame] | 811 | if (ds->drained_count > 20) { |
Takashi Iwai | 1fb8510 | 2014-11-07 17:08:28 +0100 | [diff] [blame] | 812 | snd_pcm_stop_xrun(s); |
Eliot Blennerhassett | 0b7ce9e | 2011-04-05 20:55:43 +1200 | [diff] [blame] | 813 | continue; |
| 814 | } |
| 815 | } else { |
| 816 | ds->drained_count = 0; |
Eliot Blennerhassett | ba94455 | 2011-02-10 17:26:04 +1300 | [diff] [blame] | 817 | } |
| 818 | } else |
Eliot Blennerhassett | e64b1a2 | 2011-02-10 17:25:59 +1300 | [diff] [blame] | 819 | pcm_buf_dma_ofs = bytes_avail + ds->pcm_buf_host_rw_ofs; |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 820 | |
| 821 | if (first) { |
| 822 | /* can't statically init min when wrap is involved */ |
Eliot Blennerhassett | e64b1a2 | 2011-02-10 17:25:59 +1300 | [diff] [blame] | 823 | min_buf_pos = pcm_buf_dma_ofs; |
Eliot Blennerhassett | ba94455 | 2011-02-10 17:26:04 +1300 | [diff] [blame] | 824 | newdata = (pcm_buf_dma_ofs - ds->pcm_buf_elapsed_dma_ofs) % ds->buffer_bytes; |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 825 | first = 0; |
| 826 | } else { |
| 827 | min_buf_pos = |
Eliot Blennerhassett | e64b1a2 | 2011-02-10 17:25:59 +1300 | [diff] [blame] | 828 | modulo_min(min_buf_pos, pcm_buf_dma_ofs, UINT_MAX+1L); |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 829 | newdata = min( |
Eliot Blennerhassett | ba94455 | 2011-02-10 17:26:04 +1300 | [diff] [blame] | 830 | (pcm_buf_dma_ofs - ds->pcm_buf_elapsed_dma_ofs) % ds->buffer_bytes, |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 831 | newdata); |
| 832 | } |
| 833 | |
Eliot Blennerhassett | f9a376c | 2014-11-20 16:22:53 +1300 | [diff] [blame] | 834 | snd_printddd( |
| 835 | "timer1, %s, %d, S=%d, elap=%d, rw=%d, dsp=%d, left=%d, aux=%d, space=%d, hw_ptr=%ld, appl_ptr=%ld\n", |
Eliot Blennerhassett | 35a8dc1 | 2014-11-20 16:22:50 +1300 | [diff] [blame] | 836 | name, s->number, state, |
| 837 | ds->pcm_buf_elapsed_dma_ofs, |
| 838 | ds->pcm_buf_host_rw_ofs, |
| 839 | pcm_buf_dma_ofs, |
| 840 | (int)bytes_avail, |
| 841 | |
| 842 | (int)on_card_bytes, |
| 843 | buffer_size-bytes_avail, |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 844 | (unsigned long)frames_to_bytes(runtime, |
| 845 | runtime->status->hw_ptr), |
| 846 | (unsigned long)frames_to_bytes(runtime, |
Eliot Blennerhassett | 35a8dc1 | 2014-11-20 16:22:50 +1300 | [diff] [blame] | 847 | runtime->control->appl_ptr) |
| 848 | ); |
Eliot Blennerhassett | ba94455 | 2011-02-10 17:26:04 +1300 | [diff] [blame] | 849 | loops++; |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 850 | } |
Eliot Blennerhassett | e64b1a2 | 2011-02-10 17:25:59 +1300 | [diff] [blame] | 851 | pcm_buf_dma_ofs = min_buf_pos; |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 852 | |
Eliot Blennerhassett | ba94455 | 2011-02-10 17:26:04 +1300 | [diff] [blame] | 853 | remdata = newdata % dpcm->period_bytes; |
| 854 | xfercount = newdata - remdata; /* a multiple of period_bytes */ |
Eliot Blennerhassett | e64b1a2 | 2011-02-10 17:25:59 +1300 | [diff] [blame] | 855 | /* come back when on_card_bytes has decreased enough to allow |
| 856 | write to happen, or when data has been consumed to make another |
| 857 | period |
| 858 | */ |
Eliot Blennerhassett | ba94455 | 2011-02-10 17:26:04 +1300 | [diff] [blame] | 859 | if (xfercount && (on_card_bytes > dpcm->period_bytes)) |
| 860 | next_jiffies = ((on_card_bytes - dpcm->period_bytes) * HZ / dpcm->bytes_per_sec); |
Eliot Blennerhassett | e64b1a2 | 2011-02-10 17:25:59 +1300 | [diff] [blame] | 861 | else |
Eliot Blennerhassett | ba94455 | 2011-02-10 17:26:04 +1300 | [diff] [blame] | 862 | next_jiffies = ((dpcm->period_bytes - remdata) * HZ / dpcm->bytes_per_sec); |
Eliot Blennerhassett | e64b1a2 | 2011-02-10 17:25:59 +1300 | [diff] [blame] | 863 | |
| 864 | next_jiffies = max(next_jiffies, 1U); |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 865 | dpcm->timer.expires = jiffies + next_jiffies; |
Eliot Blennerhassett | 35a8dc1 | 2014-11-20 16:22:50 +1300 | [diff] [blame] | 866 | snd_printddd("timer2, jif=%d, buf_pos=%d, newdata=%d, xfer=%d\n", |
Eliot Blennerhassett | e64b1a2 | 2011-02-10 17:25:59 +1300 | [diff] [blame] | 867 | next_jiffies, pcm_buf_dma_ofs, newdata, xfercount); |
| 868 | |
Eliot Blennerhassett | ba94455 | 2011-02-10 17:26:04 +1300 | [diff] [blame] | 869 | snd_pcm_group_for_each_entry(s, substream) { |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 870 | struct snd_card_asihpi_pcm *ds = s->runtime->private_data; |
Eliot Blennerhassett | f9a376c | 2014-11-20 16:22:53 +1300 | [diff] [blame] | 871 | runtime = s->runtime; |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 872 | |
Eliot Blennerhassett | ba94455 | 2011-02-10 17:26:04 +1300 | [diff] [blame] | 873 | /* don't link Cap and Play */ |
| 874 | if (substream->stream != s->stream) |
| 875 | continue; |
| 876 | |
Eliot Blennerhassett | f9a376c | 2014-11-20 16:22:53 +1300 | [diff] [blame] | 877 | /* Store dma offset for use by pointer callback */ |
Eliot Blennerhassett | e64b1a2 | 2011-02-10 17:25:59 +1300 | [diff] [blame] | 878 | ds->pcm_buf_dma_ofs = pcm_buf_dma_ofs; |
| 879 | |
Eliot Blennerhassett | f3d145a | 2011-04-05 20:55:44 +1200 | [diff] [blame] | 880 | if (xfercount && |
| 881 | /* Limit use of on card fifo for playback */ |
| 882 | ((on_card_bytes <= ds->period_bytes) || |
| 883 | (s->stream == SNDRV_PCM_STREAM_CAPTURE))) |
| 884 | |
| 885 | { |
| 886 | |
| 887 | unsigned int buf_ofs = ds->pcm_buf_host_rw_ofs % ds->buffer_bytes; |
| 888 | unsigned int xfer1, xfer2; |
| 889 | char *pd = &s->runtime->dma_area[buf_ofs]; |
| 890 | |
Eliot Blennerhassett | b0096a6 | 2011-04-05 20:55:46 +1200 | [diff] [blame] | 891 | if (card->can_dma) { /* buffer wrap is handled at lower level */ |
Eliot Blennerhassett | f3d145a | 2011-04-05 20:55:44 +1200 | [diff] [blame] | 892 | xfer1 = xfercount; |
| 893 | xfer2 = 0; |
| 894 | } else { |
| 895 | xfer1 = min(xfercount, ds->buffer_bytes - buf_ofs); |
| 896 | xfer2 = xfercount - xfer1; |
| 897 | } |
| 898 | |
| 899 | if (s->stream == SNDRV_PCM_STREAM_PLAYBACK) { |
Eliot Blennerhassett | 35a8dc1 | 2014-11-20 16:22:50 +1300 | [diff] [blame] | 900 | snd_printddd("write1, P=%d, xfer=%d, buf_ofs=%d\n", |
Eliot Blennerhassett | f3d145a | 2011-04-05 20:55:44 +1200 | [diff] [blame] | 901 | s->number, xfer1, buf_ofs); |
| 902 | hpi_handle_error( |
| 903 | hpi_outstream_write_buf( |
| 904 | ds->h_stream, pd, xfer1, |
| 905 | &ds->format)); |
| 906 | |
| 907 | if (xfer2) { |
| 908 | pd = s->runtime->dma_area; |
| 909 | |
Eliot Blennerhassett | 35a8dc1 | 2014-11-20 16:22:50 +1300 | [diff] [blame] | 910 | snd_printddd("write2, P=%d, xfer=%d, buf_ofs=%d\n", |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 911 | s->number, |
Eliot Blennerhassett | f3d145a | 2011-04-05 20:55:44 +1200 | [diff] [blame] | 912 | xfercount - xfer1, buf_ofs); |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 913 | hpi_handle_error( |
| 914 | hpi_outstream_write_buf( |
Eliot Blennerhassett | f3d145a | 2011-04-05 20:55:44 +1200 | [diff] [blame] | 915 | ds->h_stream, pd, |
| 916 | xfercount - xfer1, |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 917 | &ds->format)); |
Eliot Blennerhassett | f3d145a | 2011-04-05 20:55:44 +1200 | [diff] [blame] | 918 | } |
| 919 | } else { |
Eliot Blennerhassett | 35a8dc1 | 2014-11-20 16:22:50 +1300 | [diff] [blame] | 920 | snd_printddd("read1, C=%d, xfer=%d\n", |
Eliot Blennerhassett | f3d145a | 2011-04-05 20:55:44 +1200 | [diff] [blame] | 921 | s->number, xfer1); |
| 922 | hpi_handle_error( |
| 923 | hpi_instream_read_buf( |
| 924 | ds->h_stream, |
| 925 | pd, xfer1)); |
| 926 | if (xfer2) { |
| 927 | pd = s->runtime->dma_area; |
Eliot Blennerhassett | 35a8dc1 | 2014-11-20 16:22:50 +1300 | [diff] [blame] | 928 | snd_printddd("read2, C=%d, xfer=%d\n", |
Eliot Blennerhassett | f3d145a | 2011-04-05 20:55:44 +1200 | [diff] [blame] | 929 | s->number, xfer2); |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 930 | hpi_handle_error( |
| 931 | hpi_instream_read_buf( |
Eliot Blennerhassett | ba94455 | 2011-02-10 17:26:04 +1300 | [diff] [blame] | 932 | ds->h_stream, |
Eliot Blennerhassett | f3d145a | 2011-04-05 20:55:44 +1200 | [diff] [blame] | 933 | pd, xfer2)); |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 934 | } |
Eliot Blennerhassett | f3d145a | 2011-04-05 20:55:44 +1200 | [diff] [blame] | 935 | } |
Eliot Blennerhassett | f9a376c | 2014-11-20 16:22:53 +1300 | [diff] [blame] | 936 | /* ? host_rw_ofs always ahead of elapsed_dma_ofs by preload size? */ |
Eliot Blennerhassett | 47a74a5 | 2011-12-22 11:54:02 +1300 | [diff] [blame] | 937 | ds->pcm_buf_host_rw_ofs += xfercount; |
| 938 | ds->pcm_buf_elapsed_dma_ofs += xfercount; |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 939 | snd_pcm_period_elapsed(s); |
| 940 | } |
| 941 | } |
| 942 | |
Eliot Blennerhassett | f9a376c | 2014-11-20 16:22:53 +1300 | [diff] [blame] | 943 | if (!card->hpi->interrupt_mode && dpcm->respawn_timer) |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 944 | add_timer(&dpcm->timer); |
| 945 | } |
| 946 | |
Eliot Blennerhassett | f9a376c | 2014-11-20 16:22:53 +1300 | [diff] [blame] | 947 | static void snd_card_asihpi_int_task(unsigned long data) |
| 948 | { |
| 949 | struct hpi_adapter *a = (struct hpi_adapter *)data; |
| 950 | struct snd_card_asihpi *asihpi; |
| 951 | |
| 952 | WARN_ON(!a || !a->snd_card || !a->snd_card->private_data); |
| 953 | asihpi = (struct snd_card_asihpi *)a->snd_card->private_data; |
| 954 | if (asihpi->llmode_streampriv) |
| 955 | snd_card_asihpi_timer_function( |
| 956 | (unsigned long)asihpi->llmode_streampriv); |
| 957 | } |
| 958 | |
| 959 | static void snd_card_asihpi_isr(struct hpi_adapter *a) |
| 960 | { |
| 961 | struct snd_card_asihpi *asihpi; |
| 962 | |
| 963 | WARN_ON(!a || !a->snd_card || !a->snd_card->private_data); |
| 964 | asihpi = (struct snd_card_asihpi *)a->snd_card->private_data; |
| 965 | tasklet_schedule(&asihpi->t); |
| 966 | } |
| 967 | |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 968 | /***************************** PLAYBACK OPS ****************/ |
| 969 | static int snd_card_asihpi_playback_ioctl(struct snd_pcm_substream *substream, |
| 970 | unsigned int cmd, void *arg) |
| 971 | { |
Eliot Blennerhassett | cbd757d | 2011-12-22 13:38:35 +1300 | [diff] [blame] | 972 | char name[16]; |
| 973 | snd_pcm_debug_name(substream, name, sizeof(name)); |
| 974 | snd_printddd(KERN_INFO "%s ioctl %d\n", name, cmd); |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 975 | return snd_pcm_lib_ioctl(substream, cmd, arg); |
| 976 | } |
| 977 | |
| 978 | static int snd_card_asihpi_playback_prepare(struct snd_pcm_substream * |
| 979 | substream) |
| 980 | { |
| 981 | struct snd_pcm_runtime *runtime = substream->runtime; |
| 982 | struct snd_card_asihpi_pcm *dpcm = runtime->private_data; |
| 983 | |
Eliot Blennerhassett | a647713 | 2011-04-05 20:55:42 +1200 | [diff] [blame] | 984 | snd_printdd("P%d prepare\n", substream->number); |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 985 | |
Eliot Blennerhassett | ba94455 | 2011-02-10 17:26:04 +1300 | [diff] [blame] | 986 | hpi_handle_error(hpi_outstream_reset(dpcm->h_stream)); |
Eliot Blennerhassett | e64b1a2 | 2011-02-10 17:25:59 +1300 | [diff] [blame] | 987 | dpcm->pcm_buf_host_rw_ofs = 0; |
| 988 | dpcm->pcm_buf_dma_ofs = 0; |
| 989 | dpcm->pcm_buf_elapsed_dma_ofs = 0; |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 990 | return 0; |
| 991 | } |
| 992 | |
| 993 | static snd_pcm_uframes_t |
| 994 | snd_card_asihpi_playback_pointer(struct snd_pcm_substream *substream) |
| 995 | { |
| 996 | struct snd_pcm_runtime *runtime = substream->runtime; |
| 997 | struct snd_card_asihpi_pcm *dpcm = runtime->private_data; |
| 998 | snd_pcm_uframes_t ptr; |
Eliot Blennerhassett | cbd757d | 2011-12-22 13:38:35 +1300 | [diff] [blame] | 999 | char name[16]; |
| 1000 | snd_pcm_debug_name(substream, name, sizeof(name)); |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 1001 | |
Eliot Blennerhassett | ba94455 | 2011-02-10 17:26:04 +1300 | [diff] [blame] | 1002 | ptr = bytes_to_frames(runtime, dpcm->pcm_buf_dma_ofs % dpcm->buffer_bytes); |
Eliot Blennerhassett | 35a8dc1 | 2014-11-20 16:22:50 +1300 | [diff] [blame] | 1003 | snd_printddd("%s, pointer=%ld\n", name, (unsigned long)ptr); |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 1004 | return ptr; |
| 1005 | } |
| 1006 | |
Eliot Blennerhassett | 68d5339 | 2011-12-22 13:38:51 +1300 | [diff] [blame] | 1007 | static u64 snd_card_asihpi_playback_formats(struct snd_card_asihpi *asihpi, |
| 1008 | u32 h_stream) |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 1009 | { |
| 1010 | struct hpi_format hpi_format; |
| 1011 | u16 format; |
| 1012 | u16 err; |
| 1013 | u32 h_control; |
| 1014 | u32 sample_rate = 48000; |
Eliot Blennerhassett | 68d5339 | 2011-12-22 13:38:51 +1300 | [diff] [blame] | 1015 | u64 formats = 0; |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 1016 | |
| 1017 | /* on cards without SRC, must query at valid rate, |
| 1018 | * maybe set by external sync |
| 1019 | */ |
Eliot Blennerhassett | ba94455 | 2011-02-10 17:26:04 +1300 | [diff] [blame] | 1020 | err = hpi_mixer_get_control(asihpi->h_mixer, |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 1021 | HPI_SOURCENODE_CLOCK_SOURCE, 0, 0, 0, |
| 1022 | HPI_CONTROL_SAMPLECLOCK, &h_control); |
| 1023 | |
| 1024 | if (!err) |
Eliot Blennerhassett | ba94455 | 2011-02-10 17:26:04 +1300 | [diff] [blame] | 1025 | err = hpi_sample_clock_get_sample_rate(h_control, |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 1026 | &sample_rate); |
| 1027 | |
| 1028 | for (format = HPI_FORMAT_PCM8_UNSIGNED; |
| 1029 | format <= HPI_FORMAT_PCM24_SIGNED; format++) { |
Eliot Blennerhassett | c1d70dd | 2011-12-22 13:38:50 +1300 | [diff] [blame] | 1030 | err = hpi_format_create(&hpi_format, asihpi->out_max_chans, |
| 1031 | format, sample_rate, 128000, 0); |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 1032 | if (!err) |
Eliot Blennerhassett | c1d70dd | 2011-12-22 13:38:50 +1300 | [diff] [blame] | 1033 | err = hpi_outstream_query_format(h_stream, &hpi_format); |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 1034 | if (!err && (hpi_to_alsa_formats[format] != -1)) |
Eldad Zack | 74c34ca | 2013-04-23 01:00:41 +0200 | [diff] [blame] | 1035 | formats |= pcm_format_to_bits(hpi_to_alsa_formats[format]); |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 1036 | } |
Eliot Blennerhassett | 68d5339 | 2011-12-22 13:38:51 +1300 | [diff] [blame] | 1037 | return formats; |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 1038 | } |
| 1039 | |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 1040 | static int snd_card_asihpi_playback_open(struct snd_pcm_substream *substream) |
| 1041 | { |
| 1042 | struct snd_pcm_runtime *runtime = substream->runtime; |
| 1043 | struct snd_card_asihpi_pcm *dpcm; |
| 1044 | struct snd_card_asihpi *card = snd_pcm_substream_chip(substream); |
Eliot Blennerhassett | 68d5339 | 2011-12-22 13:38:51 +1300 | [diff] [blame] | 1045 | struct snd_pcm_hardware snd_card_asihpi_playback; |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 1046 | int err; |
| 1047 | |
| 1048 | dpcm = kzalloc(sizeof(*dpcm), GFP_KERNEL); |
| 1049 | if (dpcm == NULL) |
| 1050 | return -ENOMEM; |
| 1051 | |
Eliot Blennerhassett | 68d5339 | 2011-12-22 13:38:51 +1300 | [diff] [blame] | 1052 | err = hpi_outstream_open(card->hpi->adapter->index, |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 1053 | substream->number, &dpcm->h_stream); |
| 1054 | hpi_handle_error(err); |
| 1055 | if (err) |
| 1056 | kfree(dpcm); |
| 1057 | if (err == HPI_ERROR_OBJ_ALREADY_OPEN) |
| 1058 | return -EBUSY; |
| 1059 | if (err) |
| 1060 | return -EIO; |
| 1061 | |
| 1062 | /*? also check ASI5000 samplerate source |
| 1063 | If external, only support external rate. |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 1064 | If internal and other stream playing, can't switch |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 1065 | */ |
| 1066 | |
| 1067 | init_timer(&dpcm->timer); |
| 1068 | dpcm->timer.data = (unsigned long) dpcm; |
| 1069 | dpcm->timer.function = snd_card_asihpi_timer_function; |
| 1070 | dpcm->substream = substream; |
| 1071 | runtime->private_data = dpcm; |
| 1072 | runtime->private_free = snd_card_asihpi_runtime_free; |
| 1073 | |
Eliot Blennerhassett | 68d5339 | 2011-12-22 13:38:51 +1300 | [diff] [blame] | 1074 | memset(&snd_card_asihpi_playback, 0, sizeof(snd_card_asihpi_playback)); |
Eliot Blennerhassett | f9a376c | 2014-11-20 16:22:53 +1300 | [diff] [blame] | 1075 | if (!card->hpi->interrupt_mode) { |
| 1076 | snd_card_asihpi_playback.buffer_bytes_max = BUFFER_BYTES_MAX; |
| 1077 | snd_card_asihpi_playback.period_bytes_min = PERIOD_BYTES_MIN; |
| 1078 | snd_card_asihpi_playback.period_bytes_max = BUFFER_BYTES_MAX / PERIODS_MIN; |
| 1079 | snd_card_asihpi_playback.periods_min = PERIODS_MIN; |
| 1080 | snd_card_asihpi_playback.periods_max = BUFFER_BYTES_MAX / PERIOD_BYTES_MIN; |
| 1081 | } else { |
| 1082 | size_t pbmin = card->update_interval_frames * |
| 1083 | card->out_max_chans; |
| 1084 | snd_card_asihpi_playback.buffer_bytes_max = BUFFER_BYTES_MAX; |
| 1085 | snd_card_asihpi_playback.period_bytes_min = pbmin; |
| 1086 | snd_card_asihpi_playback.period_bytes_max = BUFFER_BYTES_MAX / PERIODS_MIN; |
| 1087 | snd_card_asihpi_playback.periods_min = PERIODS_MIN; |
| 1088 | snd_card_asihpi_playback.periods_max = BUFFER_BYTES_MAX / pbmin; |
| 1089 | } |
| 1090 | |
Eliot Blennerhassett | 68d5339 | 2011-12-22 13:38:51 +1300 | [diff] [blame] | 1091 | /* snd_card_asihpi_playback.fifo_size = 0; */ |
| 1092 | snd_card_asihpi_playback.channels_max = card->out_max_chans; |
| 1093 | snd_card_asihpi_playback.channels_min = card->out_min_chans; |
| 1094 | snd_card_asihpi_playback.formats = |
| 1095 | snd_card_asihpi_playback_formats(card, dpcm->h_stream); |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 1096 | |
| 1097 | snd_card_asihpi_pcm_samplerates(card, &snd_card_asihpi_playback); |
| 1098 | |
| 1099 | snd_card_asihpi_playback.info = SNDRV_PCM_INFO_INTERLEAVED | |
| 1100 | SNDRV_PCM_INFO_DOUBLE | |
| 1101 | SNDRV_PCM_INFO_BATCH | |
| 1102 | SNDRV_PCM_INFO_BLOCK_TRANSFER | |
Eliot Blennerhassett | f3d145a | 2011-04-05 20:55:44 +1200 | [diff] [blame] | 1103 | SNDRV_PCM_INFO_PAUSE | |
| 1104 | SNDRV_PCM_INFO_MMAP | |
| 1105 | SNDRV_PCM_INFO_MMAP_VALID; |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 1106 | |
Eliot Blennerhassett | 09c728a | 2011-12-22 13:38:38 +1300 | [diff] [blame] | 1107 | if (card->support_grouping) { |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 1108 | snd_card_asihpi_playback.info |= SNDRV_PCM_INFO_SYNC_START; |
Eliot Blennerhassett | 09c728a | 2011-12-22 13:38:38 +1300 | [diff] [blame] | 1109 | snd_pcm_set_sync(substream); |
| 1110 | } |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 1111 | |
| 1112 | /* struct is copied, so can create initializer dynamically */ |
| 1113 | runtime->hw = snd_card_asihpi_playback; |
| 1114 | |
Eliot Blennerhassett | f3d145a | 2011-04-05 20:55:44 +1200 | [diff] [blame] | 1115 | if (card->can_dma) |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 1116 | err = snd_pcm_hw_constraint_pow2(runtime, 0, |
| 1117 | SNDRV_PCM_HW_PARAM_BUFFER_BYTES); |
| 1118 | if (err < 0) |
| 1119 | return err; |
| 1120 | |
| 1121 | snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_SIZE, |
| 1122 | card->update_interval_frames); |
Eliot Blennerhassett | 26aebef | 2011-03-25 15:25:47 +1300 | [diff] [blame] | 1123 | |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 1124 | snd_pcm_hw_constraint_minmax(runtime, SNDRV_PCM_HW_PARAM_PERIOD_SIZE, |
Eliot Blennerhassett | f9a376c | 2014-11-20 16:22:53 +1300 | [diff] [blame] | 1125 | card->update_interval_frames, UINT_MAX); |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 1126 | |
Eliot Blennerhassett | b2e65c8 | 2011-03-25 15:25:48 +1300 | [diff] [blame] | 1127 | snd_printdd("playback open\n"); |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 1128 | |
| 1129 | return 0; |
| 1130 | } |
| 1131 | |
| 1132 | static int snd_card_asihpi_playback_close(struct snd_pcm_substream *substream) |
| 1133 | { |
| 1134 | struct snd_pcm_runtime *runtime = substream->runtime; |
| 1135 | struct snd_card_asihpi_pcm *dpcm = runtime->private_data; |
| 1136 | |
Eliot Blennerhassett | ba94455 | 2011-02-10 17:26:04 +1300 | [diff] [blame] | 1137 | hpi_handle_error(hpi_outstream_close(dpcm->h_stream)); |
Eliot Blennerhassett | b2e65c8 | 2011-03-25 15:25:48 +1300 | [diff] [blame] | 1138 | snd_printdd("playback close\n"); |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 1139 | |
| 1140 | return 0; |
| 1141 | } |
| 1142 | |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 1143 | static struct snd_pcm_ops snd_card_asihpi_playback_mmap_ops = { |
| 1144 | .open = snd_card_asihpi_playback_open, |
| 1145 | .close = snd_card_asihpi_playback_close, |
| 1146 | .ioctl = snd_card_asihpi_playback_ioctl, |
| 1147 | .hw_params = snd_card_asihpi_pcm_hw_params, |
| 1148 | .hw_free = snd_card_asihpi_hw_free, |
| 1149 | .prepare = snd_card_asihpi_playback_prepare, |
| 1150 | .trigger = snd_card_asihpi_trigger, |
| 1151 | .pointer = snd_card_asihpi_playback_pointer, |
| 1152 | }; |
| 1153 | |
| 1154 | /***************************** CAPTURE OPS ****************/ |
| 1155 | static snd_pcm_uframes_t |
| 1156 | snd_card_asihpi_capture_pointer(struct snd_pcm_substream *substream) |
| 1157 | { |
| 1158 | struct snd_pcm_runtime *runtime = substream->runtime; |
| 1159 | struct snd_card_asihpi_pcm *dpcm = runtime->private_data; |
Eliot Blennerhassett | 35a8dc1 | 2014-11-20 16:22:50 +1300 | [diff] [blame] | 1160 | char name[16]; |
| 1161 | snd_pcm_debug_name(substream, name, sizeof(name)); |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 1162 | |
Eliot Blennerhassett | 35a8dc1 | 2014-11-20 16:22:50 +1300 | [diff] [blame] | 1163 | snd_printddd("%s, pointer=%d\n", name, dpcm->pcm_buf_dma_ofs); |
Eliot Blennerhassett | e64b1a2 | 2011-02-10 17:25:59 +1300 | [diff] [blame] | 1164 | /* NOTE Unlike playback can't use actual samples_played |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 1165 | for the capture position, because those samples aren't yet in |
| 1166 | the local buffer available for reading. |
| 1167 | */ |
Eliot Blennerhassett | ba94455 | 2011-02-10 17:26:04 +1300 | [diff] [blame] | 1168 | return bytes_to_frames(runtime, dpcm->pcm_buf_dma_ofs % dpcm->buffer_bytes); |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 1169 | } |
| 1170 | |
| 1171 | static int snd_card_asihpi_capture_ioctl(struct snd_pcm_substream *substream, |
| 1172 | unsigned int cmd, void *arg) |
| 1173 | { |
| 1174 | return snd_pcm_lib_ioctl(substream, cmd, arg); |
| 1175 | } |
| 1176 | |
| 1177 | static int snd_card_asihpi_capture_prepare(struct snd_pcm_substream *substream) |
| 1178 | { |
| 1179 | struct snd_pcm_runtime *runtime = substream->runtime; |
| 1180 | struct snd_card_asihpi_pcm *dpcm = runtime->private_data; |
| 1181 | |
Eliot Blennerhassett | ba94455 | 2011-02-10 17:26:04 +1300 | [diff] [blame] | 1182 | hpi_handle_error(hpi_instream_reset(dpcm->h_stream)); |
Eliot Blennerhassett | e64b1a2 | 2011-02-10 17:25:59 +1300 | [diff] [blame] | 1183 | dpcm->pcm_buf_host_rw_ofs = 0; |
| 1184 | dpcm->pcm_buf_dma_ofs = 0; |
| 1185 | dpcm->pcm_buf_elapsed_dma_ofs = 0; |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 1186 | |
Eliot Blennerhassett | b2e65c8 | 2011-03-25 15:25:48 +1300 | [diff] [blame] | 1187 | snd_printdd("Capture Prepare %d\n", substream->number); |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 1188 | return 0; |
| 1189 | } |
| 1190 | |
Eliot Blennerhassett | 68d5339 | 2011-12-22 13:38:51 +1300 | [diff] [blame] | 1191 | static u64 snd_card_asihpi_capture_formats(struct snd_card_asihpi *asihpi, |
| 1192 | u32 h_stream) |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 1193 | { |
| 1194 | struct hpi_format hpi_format; |
| 1195 | u16 format; |
| 1196 | u16 err; |
| 1197 | u32 h_control; |
| 1198 | u32 sample_rate = 48000; |
Eliot Blennerhassett | 68d5339 | 2011-12-22 13:38:51 +1300 | [diff] [blame] | 1199 | u64 formats = 0; |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 1200 | |
| 1201 | /* on cards without SRC, must query at valid rate, |
| 1202 | maybe set by external sync */ |
Eliot Blennerhassett | ba94455 | 2011-02-10 17:26:04 +1300 | [diff] [blame] | 1203 | err = hpi_mixer_get_control(asihpi->h_mixer, |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 1204 | HPI_SOURCENODE_CLOCK_SOURCE, 0, 0, 0, |
| 1205 | HPI_CONTROL_SAMPLECLOCK, &h_control); |
| 1206 | |
| 1207 | if (!err) |
Eliot Blennerhassett | ba94455 | 2011-02-10 17:26:04 +1300 | [diff] [blame] | 1208 | err = hpi_sample_clock_get_sample_rate(h_control, |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 1209 | &sample_rate); |
| 1210 | |
| 1211 | for (format = HPI_FORMAT_PCM8_UNSIGNED; |
| 1212 | format <= HPI_FORMAT_PCM24_SIGNED; format++) { |
| 1213 | |
Eliot Blennerhassett | c1d70dd | 2011-12-22 13:38:50 +1300 | [diff] [blame] | 1214 | err = hpi_format_create(&hpi_format, asihpi->in_max_chans, |
| 1215 | format, sample_rate, 128000, 0); |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 1216 | if (!err) |
Eliot Blennerhassett | c1d70dd | 2011-12-22 13:38:50 +1300 | [diff] [blame] | 1217 | err = hpi_instream_query_format(h_stream, &hpi_format); |
Eldad Zack | 167d0a1 | 2013-04-23 01:00:42 +0200 | [diff] [blame] | 1218 | if (!err && (hpi_to_alsa_formats[format] != -1)) |
Eldad Zack | 74c34ca | 2013-04-23 01:00:41 +0200 | [diff] [blame] | 1219 | formats |= pcm_format_to_bits(hpi_to_alsa_formats[format]); |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 1220 | } |
Eliot Blennerhassett | 68d5339 | 2011-12-22 13:38:51 +1300 | [diff] [blame] | 1221 | return formats; |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 1222 | } |
| 1223 | |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 1224 | static int snd_card_asihpi_capture_open(struct snd_pcm_substream *substream) |
| 1225 | { |
| 1226 | struct snd_pcm_runtime *runtime = substream->runtime; |
| 1227 | struct snd_card_asihpi *card = snd_pcm_substream_chip(substream); |
| 1228 | struct snd_card_asihpi_pcm *dpcm; |
Eliot Blennerhassett | 68d5339 | 2011-12-22 13:38:51 +1300 | [diff] [blame] | 1229 | struct snd_pcm_hardware snd_card_asihpi_capture; |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 1230 | int err; |
| 1231 | |
| 1232 | dpcm = kzalloc(sizeof(*dpcm), GFP_KERNEL); |
| 1233 | if (dpcm == NULL) |
| 1234 | return -ENOMEM; |
| 1235 | |
Eliot Blennerhassett | b2e65c8 | 2011-03-25 15:25:48 +1300 | [diff] [blame] | 1236 | snd_printdd("capture open adapter %d stream %d\n", |
Eliot Blennerhassett | 7036b92 | 2011-12-22 13:38:43 +1300 | [diff] [blame] | 1237 | card->hpi->adapter->index, substream->number); |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 1238 | |
| 1239 | err = hpi_handle_error( |
Eliot Blennerhassett | 7036b92 | 2011-12-22 13:38:43 +1300 | [diff] [blame] | 1240 | hpi_instream_open(card->hpi->adapter->index, |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 1241 | substream->number, &dpcm->h_stream)); |
| 1242 | if (err) |
| 1243 | kfree(dpcm); |
| 1244 | if (err == HPI_ERROR_OBJ_ALREADY_OPEN) |
| 1245 | return -EBUSY; |
| 1246 | if (err) |
| 1247 | return -EIO; |
| 1248 | |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 1249 | init_timer(&dpcm->timer); |
| 1250 | dpcm->timer.data = (unsigned long) dpcm; |
| 1251 | dpcm->timer.function = snd_card_asihpi_timer_function; |
| 1252 | dpcm->substream = substream; |
| 1253 | runtime->private_data = dpcm; |
| 1254 | runtime->private_free = snd_card_asihpi_runtime_free; |
| 1255 | |
Eliot Blennerhassett | 68d5339 | 2011-12-22 13:38:51 +1300 | [diff] [blame] | 1256 | memset(&snd_card_asihpi_capture, 0, sizeof(snd_card_asihpi_capture)); |
Eliot Blennerhassett | f9a376c | 2014-11-20 16:22:53 +1300 | [diff] [blame] | 1257 | if (!card->hpi->interrupt_mode) { |
| 1258 | snd_card_asihpi_capture.buffer_bytes_max = BUFFER_BYTES_MAX; |
| 1259 | snd_card_asihpi_capture.period_bytes_min = PERIOD_BYTES_MIN; |
| 1260 | snd_card_asihpi_capture.period_bytes_max = BUFFER_BYTES_MAX / PERIODS_MIN; |
| 1261 | snd_card_asihpi_capture.periods_min = PERIODS_MIN; |
| 1262 | snd_card_asihpi_capture.periods_max = BUFFER_BYTES_MAX / PERIOD_BYTES_MIN; |
| 1263 | } else { |
| 1264 | size_t pbmin = card->update_interval_frames * |
| 1265 | card->out_max_chans; |
| 1266 | snd_card_asihpi_capture.buffer_bytes_max = BUFFER_BYTES_MAX; |
| 1267 | snd_card_asihpi_capture.period_bytes_min = pbmin; |
| 1268 | snd_card_asihpi_capture.period_bytes_max = BUFFER_BYTES_MAX / PERIODS_MIN; |
| 1269 | snd_card_asihpi_capture.periods_min = PERIODS_MIN; |
| 1270 | snd_card_asihpi_capture.periods_max = BUFFER_BYTES_MAX / pbmin; |
| 1271 | } |
Eliot Blennerhassett | 68d5339 | 2011-12-22 13:38:51 +1300 | [diff] [blame] | 1272 | /* snd_card_asihpi_capture.fifo_size = 0; */ |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 1273 | snd_card_asihpi_capture.channels_max = card->in_max_chans; |
Eliot Blennerhassett | c382a5d | 2011-12-22 13:38:33 +1300 | [diff] [blame] | 1274 | snd_card_asihpi_capture.channels_min = card->in_min_chans; |
Eliot Blennerhassett | 68d5339 | 2011-12-22 13:38:51 +1300 | [diff] [blame] | 1275 | snd_card_asihpi_capture.formats = |
| 1276 | snd_card_asihpi_capture_formats(card, dpcm->h_stream); |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 1277 | snd_card_asihpi_pcm_samplerates(card, &snd_card_asihpi_capture); |
Eliot Blennerhassett | f3d145a | 2011-04-05 20:55:44 +1200 | [diff] [blame] | 1278 | snd_card_asihpi_capture.info = SNDRV_PCM_INFO_INTERLEAVED | |
| 1279 | SNDRV_PCM_INFO_MMAP | |
| 1280 | SNDRV_PCM_INFO_MMAP_VALID; |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 1281 | |
Eliot Blennerhassett | e64b1a2 | 2011-02-10 17:25:59 +1300 | [diff] [blame] | 1282 | if (card->support_grouping) |
| 1283 | snd_card_asihpi_capture.info |= SNDRV_PCM_INFO_SYNC_START; |
| 1284 | |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 1285 | runtime->hw = snd_card_asihpi_capture; |
| 1286 | |
Eliot Blennerhassett | f3d145a | 2011-04-05 20:55:44 +1200 | [diff] [blame] | 1287 | if (card->can_dma) |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 1288 | err = snd_pcm_hw_constraint_pow2(runtime, 0, |
| 1289 | SNDRV_PCM_HW_PARAM_BUFFER_BYTES); |
| 1290 | if (err < 0) |
| 1291 | return err; |
| 1292 | |
| 1293 | snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_SIZE, |
| 1294 | card->update_interval_frames); |
| 1295 | snd_pcm_hw_constraint_minmax(runtime, SNDRV_PCM_HW_PARAM_PERIOD_SIZE, |
Eliot Blennerhassett | f9a376c | 2014-11-20 16:22:53 +1300 | [diff] [blame] | 1296 | card->update_interval_frames, UINT_MAX); |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 1297 | |
| 1298 | snd_pcm_set_sync(substream); |
| 1299 | |
| 1300 | return 0; |
| 1301 | } |
| 1302 | |
| 1303 | static int snd_card_asihpi_capture_close(struct snd_pcm_substream *substream) |
| 1304 | { |
| 1305 | struct snd_card_asihpi_pcm *dpcm = substream->runtime->private_data; |
| 1306 | |
Eliot Blennerhassett | ba94455 | 2011-02-10 17:26:04 +1300 | [diff] [blame] | 1307 | hpi_handle_error(hpi_instream_close(dpcm->h_stream)); |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 1308 | return 0; |
| 1309 | } |
| 1310 | |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 1311 | static struct snd_pcm_ops snd_card_asihpi_capture_mmap_ops = { |
| 1312 | .open = snd_card_asihpi_capture_open, |
| 1313 | .close = snd_card_asihpi_capture_close, |
| 1314 | .ioctl = snd_card_asihpi_capture_ioctl, |
| 1315 | .hw_params = snd_card_asihpi_pcm_hw_params, |
| 1316 | .hw_free = snd_card_asihpi_hw_free, |
| 1317 | .prepare = snd_card_asihpi_capture_prepare, |
| 1318 | .trigger = snd_card_asihpi_trigger, |
| 1319 | .pointer = snd_card_asihpi_capture_pointer, |
| 1320 | }; |
| 1321 | |
Bill Pemberton | e23e7a1 | 2012-12-06 12:35:10 -0500 | [diff] [blame] | 1322 | static int snd_card_asihpi_pcm_new(struct snd_card_asihpi *asihpi, int device) |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 1323 | { |
| 1324 | struct snd_pcm *pcm; |
| 1325 | int err; |
Eliot Blennerhassett | 7036b92 | 2011-12-22 13:38:43 +1300 | [diff] [blame] | 1326 | u16 num_instreams, num_outstreams, x16; |
| 1327 | u32 x32; |
| 1328 | |
| 1329 | err = hpi_adapter_get_info(asihpi->hpi->adapter->index, |
| 1330 | &num_outstreams, &num_instreams, |
| 1331 | &x16, &x32, &x16); |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 1332 | |
Eliot Blennerhassett | e64b1a2 | 2011-02-10 17:25:59 +1300 | [diff] [blame] | 1333 | err = snd_pcm_new(asihpi->card, "Asihpi PCM", device, |
Eliot Blennerhassett | 7036b92 | 2011-12-22 13:38:43 +1300 | [diff] [blame] | 1334 | num_outstreams, num_instreams, &pcm); |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 1335 | if (err < 0) |
| 1336 | return err; |
Dan Carpenter | c687c9b | 2014-03-31 10:49:15 +0300 | [diff] [blame] | 1337 | |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 1338 | /* pointer to ops struct is stored, dont change ops afterwards! */ |
Dan Carpenter | c687c9b | 2014-03-31 10:49:15 +0300 | [diff] [blame] | 1339 | snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, |
| 1340 | &snd_card_asihpi_playback_mmap_ops); |
| 1341 | snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, |
| 1342 | &snd_card_asihpi_capture_mmap_ops); |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 1343 | |
| 1344 | pcm->private_data = asihpi; |
| 1345 | pcm->info_flags = 0; |
Eliot Blennerhassett | e64b1a2 | 2011-02-10 17:25:59 +1300 | [diff] [blame] | 1346 | strcpy(pcm->name, "Asihpi PCM"); |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 1347 | |
| 1348 | /*? do we want to emulate MMAP for non-BBM cards? |
| 1349 | Jack doesn't work with ALSAs MMAP emulation - WHY NOT? */ |
| 1350 | snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV, |
| 1351 | snd_dma_pci_data(asihpi->pci), |
| 1352 | 64*1024, BUFFER_BYTES_MAX); |
| 1353 | |
| 1354 | return 0; |
| 1355 | } |
| 1356 | |
| 1357 | /***************************** MIXER CONTROLS ****************/ |
| 1358 | struct hpi_control { |
| 1359 | u32 h_control; |
| 1360 | u16 control_type; |
| 1361 | u16 src_node_type; |
| 1362 | u16 src_node_index; |
| 1363 | u16 dst_node_type; |
| 1364 | u16 dst_node_index; |
| 1365 | u16 band; |
Takashi Iwai | 975cc02 | 2013-06-28 11:56:49 +0200 | [diff] [blame] | 1366 | char name[SNDRV_CTL_ELEM_ID_NAME_MAXLEN]; /* copied to snd_ctl_elem_id.name[44]; */ |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 1367 | }; |
| 1368 | |
Eliot Blennerhassett | ba94455 | 2011-02-10 17:26:04 +1300 | [diff] [blame] | 1369 | static const char * const asihpi_tuner_band_names[] = { |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 1370 | "invalid", |
| 1371 | "AM", |
| 1372 | "FM mono", |
| 1373 | "TV NTSC-M", |
| 1374 | "FM stereo", |
| 1375 | "AUX", |
| 1376 | "TV PAL BG", |
| 1377 | "TV PAL I", |
| 1378 | "TV PAL DK", |
| 1379 | "TV SECAM", |
Eliot Blennerhassett | 3872f19 | 2014-11-20 16:22:49 +1300 | [diff] [blame] | 1380 | "TV DAB", |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 1381 | }; |
Eliot Blennerhassett | 3872f19 | 2014-11-20 16:22:49 +1300 | [diff] [blame] | 1382 | /* Number of strings must match the enumerations for HPI_TUNER_BAND in hpi.h */ |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 1383 | compile_time_assert( |
| 1384 | (ARRAY_SIZE(asihpi_tuner_band_names) == |
| 1385 | (HPI_TUNER_BAND_LAST+1)), |
| 1386 | assert_tuner_band_names_size); |
| 1387 | |
Eliot Blennerhassett | ba94455 | 2011-02-10 17:26:04 +1300 | [diff] [blame] | 1388 | static const char * const asihpi_src_names[] = { |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 1389 | "no source", |
Eliot Blennerhassett | e64b1a2 | 2011-02-10 17:25:59 +1300 | [diff] [blame] | 1390 | "PCM", |
| 1391 | "Line", |
| 1392 | "Digital", |
| 1393 | "Tuner", |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 1394 | "RF", |
Eliot Blennerhassett | e64b1a2 | 2011-02-10 17:25:59 +1300 | [diff] [blame] | 1395 | "Clock", |
| 1396 | "Bitstream", |
Eliot Blennerhassett | c830613 | 2011-07-22 15:53:00 +1200 | [diff] [blame] | 1397 | "Mic", |
| 1398 | "Net", |
Eliot Blennerhassett | e64b1a2 | 2011-02-10 17:25:59 +1300 | [diff] [blame] | 1399 | "Analog", |
| 1400 | "Adapter", |
Eliot Blennerhassett | c830613 | 2011-07-22 15:53:00 +1200 | [diff] [blame] | 1401 | "RTP", |
Eliot Blennerhassett | 3872f19 | 2014-11-20 16:22:49 +1300 | [diff] [blame] | 1402 | "Internal", |
| 1403 | "AVB", |
| 1404 | "BLU-Link" |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 1405 | }; |
Eliot Blennerhassett | 3872f19 | 2014-11-20 16:22:49 +1300 | [diff] [blame] | 1406 | /* Number of strings must match the enumerations for HPI_SOURCENODES in hpi.h */ |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 1407 | compile_time_assert( |
| 1408 | (ARRAY_SIZE(asihpi_src_names) == |
Eliot Blennerhassett | 168f1b0 | 2010-07-06 08:37:06 +1200 | [diff] [blame] | 1409 | (HPI_SOURCENODE_LAST_INDEX-HPI_SOURCENODE_NONE+1)), |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 1410 | assert_src_names_size); |
| 1411 | |
Eliot Blennerhassett | ba94455 | 2011-02-10 17:26:04 +1300 | [diff] [blame] | 1412 | static const char * const asihpi_dst_names[] = { |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 1413 | "no destination", |
Eliot Blennerhassett | e64b1a2 | 2011-02-10 17:25:59 +1300 | [diff] [blame] | 1414 | "PCM", |
| 1415 | "Line", |
| 1416 | "Digital", |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 1417 | "RF", |
Eliot Blennerhassett | e64b1a2 | 2011-02-10 17:25:59 +1300 | [diff] [blame] | 1418 | "Speaker", |
Eliot Blennerhassett | c830613 | 2011-07-22 15:53:00 +1200 | [diff] [blame] | 1419 | "Net", |
| 1420 | "Analog", |
| 1421 | "RTP", |
Eliot Blennerhassett | 3872f19 | 2014-11-20 16:22:49 +1300 | [diff] [blame] | 1422 | "AVB", |
| 1423 | "Internal", |
| 1424 | "BLU-Link" |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 1425 | }; |
Eliot Blennerhassett | 3872f19 | 2014-11-20 16:22:49 +1300 | [diff] [blame] | 1426 | /* Number of strings must match the enumerations for HPI_DESTNODES in hpi.h */ |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 1427 | compile_time_assert( |
| 1428 | (ARRAY_SIZE(asihpi_dst_names) == |
Eliot Blennerhassett | 168f1b0 | 2010-07-06 08:37:06 +1200 | [diff] [blame] | 1429 | (HPI_DESTNODE_LAST_INDEX-HPI_DESTNODE_NONE+1)), |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 1430 | assert_dst_names_size); |
| 1431 | |
| 1432 | static inline int ctl_add(struct snd_card *card, struct snd_kcontrol_new *ctl, |
| 1433 | struct snd_card_asihpi *asihpi) |
| 1434 | { |
| 1435 | int err; |
| 1436 | |
| 1437 | err = snd_ctl_add(card, snd_ctl_new1(ctl, asihpi)); |
| 1438 | if (err < 0) |
| 1439 | return err; |
| 1440 | else if (mixer_dump) |
Eliot Blennerhassett | 12eb089 | 2014-11-20 16:22:55 +1300 | [diff] [blame] | 1441 | dev_info(&asihpi->pci->dev, "added %s(%d)\n", ctl->name, ctl->index); |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 1442 | |
| 1443 | return 0; |
| 1444 | } |
| 1445 | |
| 1446 | /* Convert HPI control name and location into ALSA control name */ |
| 1447 | static void asihpi_ctl_init(struct snd_kcontrol_new *snd_control, |
| 1448 | struct hpi_control *hpi_ctl, |
| 1449 | char *name) |
| 1450 | { |
Eliot Blennerhassett | 550ac6b | 2011-04-05 20:55:41 +1200 | [diff] [blame] | 1451 | char *dir; |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 1452 | memset(snd_control, 0, sizeof(*snd_control)); |
| 1453 | snd_control->name = hpi_ctl->name; |
| 1454 | snd_control->private_value = hpi_ctl->h_control; |
| 1455 | snd_control->iface = SNDRV_CTL_ELEM_IFACE_MIXER; |
| 1456 | snd_control->index = 0; |
| 1457 | |
Eliot Blennerhassett | 550ac6b | 2011-04-05 20:55:41 +1200 | [diff] [blame] | 1458 | if (hpi_ctl->src_node_type + HPI_SOURCENODE_NONE == HPI_SOURCENODE_CLOCK_SOURCE) |
| 1459 | dir = ""; /* clock is neither capture nor playback */ |
| 1460 | else if (hpi_ctl->dst_node_type + HPI_DESTNODE_NONE == HPI_DESTNODE_ISTREAM) |
Eliot Blennerhassett | e64b1a2 | 2011-02-10 17:25:59 +1300 | [diff] [blame] | 1461 | dir = "Capture "; /* On or towards a PCM capture destination*/ |
| 1462 | else if ((hpi_ctl->src_node_type + HPI_SOURCENODE_NONE != HPI_SOURCENODE_OSTREAM) && |
| 1463 | (!hpi_ctl->dst_node_type)) |
| 1464 | dir = "Capture "; /* On a source node that is not PCM playback */ |
Eliot Blennerhassett | ba94455 | 2011-02-10 17:26:04 +1300 | [diff] [blame] | 1465 | else if (hpi_ctl->src_node_type && |
| 1466 | (hpi_ctl->src_node_type + HPI_SOURCENODE_NONE != HPI_SOURCENODE_OSTREAM) && |
Eliot Blennerhassett | e64b1a2 | 2011-02-10 17:25:59 +1300 | [diff] [blame] | 1467 | (hpi_ctl->dst_node_type)) |
| 1468 | dir = "Monitor Playback "; /* Between an input and an output */ |
| 1469 | else |
| 1470 | dir = "Playback "; /* PCM Playback source, or output node */ |
| 1471 | |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 1472 | if (hpi_ctl->src_node_type && hpi_ctl->dst_node_type) |
Eliot Blennerhassett | 550ac6b | 2011-04-05 20:55:41 +1200 | [diff] [blame] | 1473 | sprintf(hpi_ctl->name, "%s %d %s %d %s%s", |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 1474 | asihpi_src_names[hpi_ctl->src_node_type], |
| 1475 | hpi_ctl->src_node_index, |
| 1476 | asihpi_dst_names[hpi_ctl->dst_node_type], |
| 1477 | hpi_ctl->dst_node_index, |
Eliot Blennerhassett | e64b1a2 | 2011-02-10 17:25:59 +1300 | [diff] [blame] | 1478 | dir, name); |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 1479 | else if (hpi_ctl->dst_node_type) { |
Eliot Blennerhassett | e64b1a2 | 2011-02-10 17:25:59 +1300 | [diff] [blame] | 1480 | sprintf(hpi_ctl->name, "%s %d %s%s", |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 1481 | asihpi_dst_names[hpi_ctl->dst_node_type], |
| 1482 | hpi_ctl->dst_node_index, |
Eliot Blennerhassett | e64b1a2 | 2011-02-10 17:25:59 +1300 | [diff] [blame] | 1483 | dir, name); |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 1484 | } else { |
Eliot Blennerhassett | e64b1a2 | 2011-02-10 17:25:59 +1300 | [diff] [blame] | 1485 | sprintf(hpi_ctl->name, "%s %d %s%s", |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 1486 | asihpi_src_names[hpi_ctl->src_node_type], |
| 1487 | hpi_ctl->src_node_index, |
Eliot Blennerhassett | e64b1a2 | 2011-02-10 17:25:59 +1300 | [diff] [blame] | 1488 | dir, name); |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 1489 | } |
Eliot Blennerhassett | ba94455 | 2011-02-10 17:26:04 +1300 | [diff] [blame] | 1490 | /* printk(KERN_INFO "Adding %s %d to %d ", hpi_ctl->name, |
| 1491 | hpi_ctl->wSrcNodeType, hpi_ctl->wDstNodeType); */ |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 1492 | } |
| 1493 | |
| 1494 | /*------------------------------------------------------------ |
| 1495 | Volume controls |
| 1496 | ------------------------------------------------------------*/ |
| 1497 | #define VOL_STEP_mB 1 |
| 1498 | static int snd_asihpi_volume_info(struct snd_kcontrol *kcontrol, |
| 1499 | struct snd_ctl_elem_info *uinfo) |
| 1500 | { |
| 1501 | u32 h_control = kcontrol->private_value; |
Eliot Blennerhassett | d4b06d2 | 2011-12-22 13:38:34 +1300 | [diff] [blame] | 1502 | u32 count; |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 1503 | u16 err; |
| 1504 | /* native gains are in millibels */ |
| 1505 | short min_gain_mB; |
| 1506 | short max_gain_mB; |
| 1507 | short step_gain_mB; |
| 1508 | |
Eliot Blennerhassett | ba94455 | 2011-02-10 17:26:04 +1300 | [diff] [blame] | 1509 | err = hpi_volume_query_range(h_control, |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 1510 | &min_gain_mB, &max_gain_mB, &step_gain_mB); |
| 1511 | if (err) { |
| 1512 | max_gain_mB = 0; |
| 1513 | min_gain_mB = -10000; |
| 1514 | step_gain_mB = VOL_STEP_mB; |
| 1515 | } |
| 1516 | |
Eliot Blennerhassett | d4b06d2 | 2011-12-22 13:38:34 +1300 | [diff] [blame] | 1517 | err = hpi_meter_query_channels(h_control, &count); |
| 1518 | if (err) |
| 1519 | count = HPI_MAX_CHANNELS; |
| 1520 | |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 1521 | uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; |
Eliot Blennerhassett | d4b06d2 | 2011-12-22 13:38:34 +1300 | [diff] [blame] | 1522 | uinfo->count = count; |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 1523 | uinfo->value.integer.min = min_gain_mB / VOL_STEP_mB; |
| 1524 | uinfo->value.integer.max = max_gain_mB / VOL_STEP_mB; |
| 1525 | uinfo->value.integer.step = step_gain_mB / VOL_STEP_mB; |
| 1526 | return 0; |
| 1527 | } |
| 1528 | |
| 1529 | static int snd_asihpi_volume_get(struct snd_kcontrol *kcontrol, |
| 1530 | struct snd_ctl_elem_value *ucontrol) |
| 1531 | { |
| 1532 | u32 h_control = kcontrol->private_value; |
| 1533 | short an_gain_mB[HPI_MAX_CHANNELS]; |
| 1534 | |
Eliot Blennerhassett | ba94455 | 2011-02-10 17:26:04 +1300 | [diff] [blame] | 1535 | hpi_handle_error(hpi_volume_get_gain(h_control, an_gain_mB)); |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 1536 | ucontrol->value.integer.value[0] = an_gain_mB[0] / VOL_STEP_mB; |
| 1537 | ucontrol->value.integer.value[1] = an_gain_mB[1] / VOL_STEP_mB; |
| 1538 | |
| 1539 | return 0; |
| 1540 | } |
| 1541 | |
| 1542 | static int snd_asihpi_volume_put(struct snd_kcontrol *kcontrol, |
| 1543 | struct snd_ctl_elem_value *ucontrol) |
| 1544 | { |
| 1545 | int change; |
| 1546 | u32 h_control = kcontrol->private_value; |
| 1547 | short an_gain_mB[HPI_MAX_CHANNELS]; |
| 1548 | |
| 1549 | an_gain_mB[0] = |
| 1550 | (ucontrol->value.integer.value[0]) * VOL_STEP_mB; |
| 1551 | an_gain_mB[1] = |
| 1552 | (ucontrol->value.integer.value[1]) * VOL_STEP_mB; |
| 1553 | /* change = asihpi->mixer_volume[addr][0] != left || |
| 1554 | asihpi->mixer_volume[addr][1] != right; |
| 1555 | */ |
| 1556 | change = 1; |
Eliot Blennerhassett | ba94455 | 2011-02-10 17:26:04 +1300 | [diff] [blame] | 1557 | hpi_handle_error(hpi_volume_set_gain(h_control, an_gain_mB)); |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 1558 | return change; |
| 1559 | } |
| 1560 | |
| 1561 | static const DECLARE_TLV_DB_SCALE(db_scale_100, -10000, VOL_STEP_mB, 0); |
| 1562 | |
Takashi Iwai | 000477a | 2011-07-22 07:57:44 +0200 | [diff] [blame] | 1563 | #define snd_asihpi_volume_mute_info snd_ctl_boolean_mono_info |
Eliot Blennerhassett | fe0aa88e | 2011-07-22 15:53:03 +1200 | [diff] [blame] | 1564 | |
| 1565 | static int snd_asihpi_volume_mute_get(struct snd_kcontrol *kcontrol, |
| 1566 | struct snd_ctl_elem_value *ucontrol) |
| 1567 | { |
| 1568 | u32 h_control = kcontrol->private_value; |
| 1569 | u32 mute; |
| 1570 | |
| 1571 | hpi_handle_error(hpi_volume_get_mute(h_control, &mute)); |
| 1572 | ucontrol->value.integer.value[0] = mute ? 0 : 1; |
| 1573 | |
| 1574 | return 0; |
| 1575 | } |
| 1576 | |
| 1577 | static int snd_asihpi_volume_mute_put(struct snd_kcontrol *kcontrol, |
| 1578 | struct snd_ctl_elem_value *ucontrol) |
| 1579 | { |
| 1580 | u32 h_control = kcontrol->private_value; |
| 1581 | int change = 1; |
| 1582 | /* HPI currently only supports all or none muting of multichannel volume |
| 1583 | ALSA Switch element has opposite sense to HPI mute: on==unmuted, off=muted |
| 1584 | */ |
| 1585 | int mute = ucontrol->value.integer.value[0] ? 0 : HPI_BITMASK_ALL_CHANNELS; |
| 1586 | hpi_handle_error(hpi_volume_set_mute(h_control, mute)); |
| 1587 | return change; |
| 1588 | } |
| 1589 | |
Bill Pemberton | e23e7a1 | 2012-12-06 12:35:10 -0500 | [diff] [blame] | 1590 | static int snd_asihpi_volume_add(struct snd_card_asihpi *asihpi, |
| 1591 | struct hpi_control *hpi_ctl) |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 1592 | { |
| 1593 | struct snd_card *card = asihpi->card; |
| 1594 | struct snd_kcontrol_new snd_control; |
Eliot Blennerhassett | fe0aa88e | 2011-07-22 15:53:03 +1200 | [diff] [blame] | 1595 | int err; |
| 1596 | u32 mute; |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 1597 | |
Eliot Blennerhassett | e64b1a2 | 2011-02-10 17:25:59 +1300 | [diff] [blame] | 1598 | asihpi_ctl_init(&snd_control, hpi_ctl, "Volume"); |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 1599 | snd_control.access = SNDRV_CTL_ELEM_ACCESS_READWRITE | |
| 1600 | SNDRV_CTL_ELEM_ACCESS_TLV_READ; |
| 1601 | snd_control.info = snd_asihpi_volume_info; |
| 1602 | snd_control.get = snd_asihpi_volume_get; |
| 1603 | snd_control.put = snd_asihpi_volume_put; |
| 1604 | snd_control.tlv.p = db_scale_100; |
| 1605 | |
Eliot Blennerhassett | fe0aa88e | 2011-07-22 15:53:03 +1200 | [diff] [blame] | 1606 | err = ctl_add(card, &snd_control, asihpi); |
| 1607 | if (err) |
| 1608 | return err; |
| 1609 | |
| 1610 | if (hpi_volume_get_mute(hpi_ctl->h_control, &mute) == 0) { |
| 1611 | asihpi_ctl_init(&snd_control, hpi_ctl, "Switch"); |
| 1612 | snd_control.access = SNDRV_CTL_ELEM_ACCESS_READWRITE; |
| 1613 | snd_control.info = snd_asihpi_volume_mute_info; |
| 1614 | snd_control.get = snd_asihpi_volume_mute_get; |
| 1615 | snd_control.put = snd_asihpi_volume_mute_put; |
| 1616 | err = ctl_add(card, &snd_control, asihpi); |
| 1617 | } |
| 1618 | return err; |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 1619 | } |
| 1620 | |
| 1621 | /*------------------------------------------------------------ |
| 1622 | Level controls |
| 1623 | ------------------------------------------------------------*/ |
| 1624 | static int snd_asihpi_level_info(struct snd_kcontrol *kcontrol, |
| 1625 | struct snd_ctl_elem_info *uinfo) |
| 1626 | { |
| 1627 | u32 h_control = kcontrol->private_value; |
| 1628 | u16 err; |
| 1629 | short min_gain_mB; |
| 1630 | short max_gain_mB; |
| 1631 | short step_gain_mB; |
| 1632 | |
| 1633 | err = |
Eliot Blennerhassett | ba94455 | 2011-02-10 17:26:04 +1300 | [diff] [blame] | 1634 | hpi_level_query_range(h_control, &min_gain_mB, |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 1635 | &max_gain_mB, &step_gain_mB); |
| 1636 | if (err) { |
| 1637 | max_gain_mB = 2400; |
| 1638 | min_gain_mB = -1000; |
| 1639 | step_gain_mB = 100; |
| 1640 | } |
| 1641 | |
| 1642 | uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; |
| 1643 | uinfo->count = 2; |
| 1644 | uinfo->value.integer.min = min_gain_mB / HPI_UNITS_PER_dB; |
| 1645 | uinfo->value.integer.max = max_gain_mB / HPI_UNITS_PER_dB; |
| 1646 | uinfo->value.integer.step = step_gain_mB / HPI_UNITS_PER_dB; |
| 1647 | return 0; |
| 1648 | } |
| 1649 | |
| 1650 | static int snd_asihpi_level_get(struct snd_kcontrol *kcontrol, |
| 1651 | struct snd_ctl_elem_value *ucontrol) |
| 1652 | { |
| 1653 | u32 h_control = kcontrol->private_value; |
| 1654 | short an_gain_mB[HPI_MAX_CHANNELS]; |
| 1655 | |
Eliot Blennerhassett | ba94455 | 2011-02-10 17:26:04 +1300 | [diff] [blame] | 1656 | hpi_handle_error(hpi_level_get_gain(h_control, an_gain_mB)); |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 1657 | ucontrol->value.integer.value[0] = |
| 1658 | an_gain_mB[0] / HPI_UNITS_PER_dB; |
| 1659 | ucontrol->value.integer.value[1] = |
| 1660 | an_gain_mB[1] / HPI_UNITS_PER_dB; |
| 1661 | |
| 1662 | return 0; |
| 1663 | } |
| 1664 | |
| 1665 | static int snd_asihpi_level_put(struct snd_kcontrol *kcontrol, |
| 1666 | struct snd_ctl_elem_value *ucontrol) |
| 1667 | { |
| 1668 | int change; |
| 1669 | u32 h_control = kcontrol->private_value; |
| 1670 | short an_gain_mB[HPI_MAX_CHANNELS]; |
| 1671 | |
| 1672 | an_gain_mB[0] = |
| 1673 | (ucontrol->value.integer.value[0]) * HPI_UNITS_PER_dB; |
| 1674 | an_gain_mB[1] = |
| 1675 | (ucontrol->value.integer.value[1]) * HPI_UNITS_PER_dB; |
| 1676 | /* change = asihpi->mixer_level[addr][0] != left || |
| 1677 | asihpi->mixer_level[addr][1] != right; |
| 1678 | */ |
| 1679 | change = 1; |
Eliot Blennerhassett | ba94455 | 2011-02-10 17:26:04 +1300 | [diff] [blame] | 1680 | hpi_handle_error(hpi_level_set_gain(h_control, an_gain_mB)); |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 1681 | return change; |
| 1682 | } |
| 1683 | |
| 1684 | static const DECLARE_TLV_DB_SCALE(db_scale_level, -1000, 100, 0); |
| 1685 | |
Bill Pemberton | e23e7a1 | 2012-12-06 12:35:10 -0500 | [diff] [blame] | 1686 | static int snd_asihpi_level_add(struct snd_card_asihpi *asihpi, |
| 1687 | struct hpi_control *hpi_ctl) |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 1688 | { |
| 1689 | struct snd_card *card = asihpi->card; |
| 1690 | struct snd_kcontrol_new snd_control; |
| 1691 | |
| 1692 | /* can't use 'volume' cos some nodes have volume as well */ |
Eliot Blennerhassett | e64b1a2 | 2011-02-10 17:25:59 +1300 | [diff] [blame] | 1693 | asihpi_ctl_init(&snd_control, hpi_ctl, "Level"); |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 1694 | snd_control.access = SNDRV_CTL_ELEM_ACCESS_READWRITE | |
| 1695 | SNDRV_CTL_ELEM_ACCESS_TLV_READ; |
| 1696 | snd_control.info = snd_asihpi_level_info; |
| 1697 | snd_control.get = snd_asihpi_level_get; |
| 1698 | snd_control.put = snd_asihpi_level_put; |
| 1699 | snd_control.tlv.p = db_scale_level; |
| 1700 | |
| 1701 | return ctl_add(card, &snd_control, asihpi); |
| 1702 | } |
| 1703 | |
| 1704 | /*------------------------------------------------------------ |
| 1705 | AESEBU controls |
| 1706 | ------------------------------------------------------------*/ |
| 1707 | |
| 1708 | /* AESEBU format */ |
Eliot Blennerhassett | ba94455 | 2011-02-10 17:26:04 +1300 | [diff] [blame] | 1709 | static const char * const asihpi_aesebu_format_names[] = { |
| 1710 | "N/A", "S/PDIF", "AES/EBU" }; |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 1711 | |
| 1712 | static int snd_asihpi_aesebu_format_info(struct snd_kcontrol *kcontrol, |
| 1713 | struct snd_ctl_elem_info *uinfo) |
| 1714 | { |
Takashi Iwai | 30d0ae4 | 2014-10-20 18:15:50 +0200 | [diff] [blame] | 1715 | return snd_ctl_enum_info(uinfo, 1, 3, asihpi_aesebu_format_names); |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 1716 | } |
| 1717 | |
| 1718 | static int snd_asihpi_aesebu_format_get(struct snd_kcontrol *kcontrol, |
| 1719 | struct snd_ctl_elem_value *ucontrol, |
Eliot Blennerhassett | ba94455 | 2011-02-10 17:26:04 +1300 | [diff] [blame] | 1720 | u16 (*func)(u32, u16 *)) |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 1721 | { |
| 1722 | u32 h_control = kcontrol->private_value; |
| 1723 | u16 source, err; |
| 1724 | |
Eliot Blennerhassett | ba94455 | 2011-02-10 17:26:04 +1300 | [diff] [blame] | 1725 | err = func(h_control, &source); |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 1726 | |
| 1727 | /* default to N/A */ |
| 1728 | ucontrol->value.enumerated.item[0] = 0; |
| 1729 | /* return success but set the control to N/A */ |
| 1730 | if (err) |
| 1731 | return 0; |
| 1732 | if (source == HPI_AESEBU_FORMAT_SPDIF) |
| 1733 | ucontrol->value.enumerated.item[0] = 1; |
| 1734 | if (source == HPI_AESEBU_FORMAT_AESEBU) |
| 1735 | ucontrol->value.enumerated.item[0] = 2; |
| 1736 | |
| 1737 | return 0; |
| 1738 | } |
| 1739 | |
| 1740 | static int snd_asihpi_aesebu_format_put(struct snd_kcontrol *kcontrol, |
| 1741 | struct snd_ctl_elem_value *ucontrol, |
Eliot Blennerhassett | ba94455 | 2011-02-10 17:26:04 +1300 | [diff] [blame] | 1742 | u16 (*func)(u32, u16)) |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 1743 | { |
| 1744 | u32 h_control = kcontrol->private_value; |
| 1745 | |
| 1746 | /* default to S/PDIF */ |
| 1747 | u16 source = HPI_AESEBU_FORMAT_SPDIF; |
| 1748 | |
| 1749 | if (ucontrol->value.enumerated.item[0] == 1) |
| 1750 | source = HPI_AESEBU_FORMAT_SPDIF; |
| 1751 | if (ucontrol->value.enumerated.item[0] == 2) |
| 1752 | source = HPI_AESEBU_FORMAT_AESEBU; |
| 1753 | |
Eliot Blennerhassett | ba94455 | 2011-02-10 17:26:04 +1300 | [diff] [blame] | 1754 | if (func(h_control, source) != 0) |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 1755 | return -EINVAL; |
| 1756 | |
| 1757 | return 1; |
| 1758 | } |
| 1759 | |
| 1760 | static int snd_asihpi_aesebu_rx_format_get(struct snd_kcontrol *kcontrol, |
| 1761 | struct snd_ctl_elem_value *ucontrol) { |
| 1762 | return snd_asihpi_aesebu_format_get(kcontrol, ucontrol, |
Eliot Blennerhassett | ba94455 | 2011-02-10 17:26:04 +1300 | [diff] [blame] | 1763 | hpi_aesebu_receiver_get_format); |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 1764 | } |
| 1765 | |
| 1766 | static int snd_asihpi_aesebu_rx_format_put(struct snd_kcontrol *kcontrol, |
| 1767 | struct snd_ctl_elem_value *ucontrol) { |
| 1768 | return snd_asihpi_aesebu_format_put(kcontrol, ucontrol, |
Eliot Blennerhassett | ba94455 | 2011-02-10 17:26:04 +1300 | [diff] [blame] | 1769 | hpi_aesebu_receiver_set_format); |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 1770 | } |
| 1771 | |
| 1772 | static int snd_asihpi_aesebu_rxstatus_info(struct snd_kcontrol *kcontrol, |
| 1773 | struct snd_ctl_elem_info *uinfo) |
| 1774 | { |
| 1775 | uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; |
| 1776 | uinfo->count = 1; |
| 1777 | |
| 1778 | uinfo->value.integer.min = 0; |
| 1779 | uinfo->value.integer.max = 0X1F; |
| 1780 | uinfo->value.integer.step = 1; |
| 1781 | |
| 1782 | return 0; |
| 1783 | } |
| 1784 | |
| 1785 | static int snd_asihpi_aesebu_rxstatus_get(struct snd_kcontrol *kcontrol, |
| 1786 | struct snd_ctl_elem_value *ucontrol) { |
| 1787 | |
| 1788 | u32 h_control = kcontrol->private_value; |
| 1789 | u16 status; |
| 1790 | |
Eliot Blennerhassett | ba94455 | 2011-02-10 17:26:04 +1300 | [diff] [blame] | 1791 | hpi_handle_error(hpi_aesebu_receiver_get_error_status( |
| 1792 | h_control, &status)); |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 1793 | ucontrol->value.integer.value[0] = status; |
| 1794 | return 0; |
| 1795 | } |
| 1796 | |
Bill Pemberton | e23e7a1 | 2012-12-06 12:35:10 -0500 | [diff] [blame] | 1797 | static int snd_asihpi_aesebu_rx_add(struct snd_card_asihpi *asihpi, |
| 1798 | struct hpi_control *hpi_ctl) |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 1799 | { |
| 1800 | struct snd_card *card = asihpi->card; |
| 1801 | struct snd_kcontrol_new snd_control; |
| 1802 | |
Eliot Blennerhassett | e64b1a2 | 2011-02-10 17:25:59 +1300 | [diff] [blame] | 1803 | asihpi_ctl_init(&snd_control, hpi_ctl, "Format"); |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 1804 | snd_control.access = SNDRV_CTL_ELEM_ACCESS_READWRITE; |
| 1805 | snd_control.info = snd_asihpi_aesebu_format_info; |
| 1806 | snd_control.get = snd_asihpi_aesebu_rx_format_get; |
| 1807 | snd_control.put = snd_asihpi_aesebu_rx_format_put; |
| 1808 | |
| 1809 | |
| 1810 | if (ctl_add(card, &snd_control, asihpi) < 0) |
| 1811 | return -EINVAL; |
| 1812 | |
Eliot Blennerhassett | e64b1a2 | 2011-02-10 17:25:59 +1300 | [diff] [blame] | 1813 | asihpi_ctl_init(&snd_control, hpi_ctl, "Status"); |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 1814 | snd_control.access = |
| 1815 | SNDRV_CTL_ELEM_ACCESS_VOLATILE | SNDRV_CTL_ELEM_ACCESS_READ; |
| 1816 | snd_control.info = snd_asihpi_aesebu_rxstatus_info; |
| 1817 | snd_control.get = snd_asihpi_aesebu_rxstatus_get; |
| 1818 | |
| 1819 | return ctl_add(card, &snd_control, asihpi); |
| 1820 | } |
| 1821 | |
| 1822 | static int snd_asihpi_aesebu_tx_format_get(struct snd_kcontrol *kcontrol, |
| 1823 | struct snd_ctl_elem_value *ucontrol) { |
| 1824 | return snd_asihpi_aesebu_format_get(kcontrol, ucontrol, |
Eliot Blennerhassett | ba94455 | 2011-02-10 17:26:04 +1300 | [diff] [blame] | 1825 | hpi_aesebu_transmitter_get_format); |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 1826 | } |
| 1827 | |
| 1828 | static int snd_asihpi_aesebu_tx_format_put(struct snd_kcontrol *kcontrol, |
| 1829 | struct snd_ctl_elem_value *ucontrol) { |
| 1830 | return snd_asihpi_aesebu_format_put(kcontrol, ucontrol, |
Eliot Blennerhassett | ba94455 | 2011-02-10 17:26:04 +1300 | [diff] [blame] | 1831 | hpi_aesebu_transmitter_set_format); |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 1832 | } |
| 1833 | |
| 1834 | |
Bill Pemberton | e23e7a1 | 2012-12-06 12:35:10 -0500 | [diff] [blame] | 1835 | static int snd_asihpi_aesebu_tx_add(struct snd_card_asihpi *asihpi, |
| 1836 | struct hpi_control *hpi_ctl) |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 1837 | { |
| 1838 | struct snd_card *card = asihpi->card; |
| 1839 | struct snd_kcontrol_new snd_control; |
| 1840 | |
Eliot Blennerhassett | e64b1a2 | 2011-02-10 17:25:59 +1300 | [diff] [blame] | 1841 | asihpi_ctl_init(&snd_control, hpi_ctl, "Format"); |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 1842 | snd_control.access = SNDRV_CTL_ELEM_ACCESS_READWRITE; |
| 1843 | snd_control.info = snd_asihpi_aesebu_format_info; |
| 1844 | snd_control.get = snd_asihpi_aesebu_tx_format_get; |
| 1845 | snd_control.put = snd_asihpi_aesebu_tx_format_put; |
| 1846 | |
| 1847 | return ctl_add(card, &snd_control, asihpi); |
| 1848 | } |
| 1849 | |
| 1850 | /*------------------------------------------------------------ |
| 1851 | Tuner controls |
| 1852 | ------------------------------------------------------------*/ |
| 1853 | |
| 1854 | /* Gain */ |
| 1855 | |
| 1856 | static int snd_asihpi_tuner_gain_info(struct snd_kcontrol *kcontrol, |
| 1857 | struct snd_ctl_elem_info *uinfo) |
| 1858 | { |
| 1859 | u32 h_control = kcontrol->private_value; |
| 1860 | u16 err; |
| 1861 | short idx; |
| 1862 | u16 gain_range[3]; |
| 1863 | |
| 1864 | for (idx = 0; idx < 3; idx++) { |
Eliot Blennerhassett | ba94455 | 2011-02-10 17:26:04 +1300 | [diff] [blame] | 1865 | err = hpi_tuner_query_gain(h_control, |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 1866 | idx, &gain_range[idx]); |
| 1867 | if (err != 0) |
| 1868 | return err; |
| 1869 | } |
| 1870 | |
| 1871 | uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; |
| 1872 | uinfo->count = 1; |
| 1873 | uinfo->value.integer.min = ((int)gain_range[0]) / HPI_UNITS_PER_dB; |
| 1874 | uinfo->value.integer.max = ((int)gain_range[1]) / HPI_UNITS_PER_dB; |
| 1875 | uinfo->value.integer.step = ((int) gain_range[2]) / HPI_UNITS_PER_dB; |
| 1876 | return 0; |
| 1877 | } |
| 1878 | |
| 1879 | static int snd_asihpi_tuner_gain_get(struct snd_kcontrol *kcontrol, |
| 1880 | struct snd_ctl_elem_value *ucontrol) |
| 1881 | { |
| 1882 | /* |
| 1883 | struct snd_card_asihpi *asihpi = snd_kcontrol_chip(kcontrol); |
| 1884 | */ |
| 1885 | u32 h_control = kcontrol->private_value; |
| 1886 | short gain; |
| 1887 | |
Eliot Blennerhassett | ba94455 | 2011-02-10 17:26:04 +1300 | [diff] [blame] | 1888 | hpi_handle_error(hpi_tuner_get_gain(h_control, &gain)); |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 1889 | ucontrol->value.integer.value[0] = gain / HPI_UNITS_PER_dB; |
| 1890 | |
| 1891 | return 0; |
| 1892 | } |
| 1893 | |
| 1894 | static int snd_asihpi_tuner_gain_put(struct snd_kcontrol *kcontrol, |
| 1895 | struct snd_ctl_elem_value *ucontrol) |
| 1896 | { |
| 1897 | /* |
| 1898 | struct snd_card_asihpi *asihpi = snd_kcontrol_chip(kcontrol); |
| 1899 | */ |
| 1900 | u32 h_control = kcontrol->private_value; |
| 1901 | short gain; |
| 1902 | |
| 1903 | gain = (ucontrol->value.integer.value[0]) * HPI_UNITS_PER_dB; |
Eliot Blennerhassett | ba94455 | 2011-02-10 17:26:04 +1300 | [diff] [blame] | 1904 | hpi_handle_error(hpi_tuner_set_gain(h_control, gain)); |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 1905 | |
| 1906 | return 1; |
| 1907 | } |
| 1908 | |
| 1909 | /* Band */ |
| 1910 | |
| 1911 | static int asihpi_tuner_band_query(struct snd_kcontrol *kcontrol, |
| 1912 | u16 *band_list, u32 len) { |
| 1913 | u32 h_control = kcontrol->private_value; |
| 1914 | u16 err = 0; |
| 1915 | u32 i; |
| 1916 | |
| 1917 | for (i = 0; i < len; i++) { |
Eliot Blennerhassett | ba94455 | 2011-02-10 17:26:04 +1300 | [diff] [blame] | 1918 | err = hpi_tuner_query_band( |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 1919 | h_control, i, &band_list[i]); |
| 1920 | if (err != 0) |
| 1921 | break; |
| 1922 | } |
| 1923 | |
| 1924 | if (err && (err != HPI_ERROR_INVALID_OBJ_INDEX)) |
| 1925 | return -EIO; |
| 1926 | |
| 1927 | return i; |
| 1928 | } |
| 1929 | |
| 1930 | static int snd_asihpi_tuner_band_info(struct snd_kcontrol *kcontrol, |
| 1931 | struct snd_ctl_elem_info *uinfo) |
| 1932 | { |
| 1933 | u16 tuner_bands[HPI_TUNER_BAND_LAST]; |
| 1934 | int num_bands = 0; |
| 1935 | |
| 1936 | num_bands = asihpi_tuner_band_query(kcontrol, tuner_bands, |
| 1937 | HPI_TUNER_BAND_LAST); |
| 1938 | |
| 1939 | if (num_bands < 0) |
| 1940 | return num_bands; |
| 1941 | |
Takashi Iwai | 30d0ae4 | 2014-10-20 18:15:50 +0200 | [diff] [blame] | 1942 | return snd_ctl_enum_info(uinfo, 1, num_bands, asihpi_tuner_band_names); |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 1943 | } |
| 1944 | |
| 1945 | static int snd_asihpi_tuner_band_get(struct snd_kcontrol *kcontrol, |
| 1946 | struct snd_ctl_elem_value *ucontrol) |
| 1947 | { |
| 1948 | u32 h_control = kcontrol->private_value; |
| 1949 | /* |
| 1950 | struct snd_card_asihpi *asihpi = snd_kcontrol_chip(kcontrol); |
| 1951 | */ |
| 1952 | u16 band, idx; |
| 1953 | u16 tuner_bands[HPI_TUNER_BAND_LAST]; |
| 1954 | u32 num_bands = 0; |
| 1955 | |
| 1956 | num_bands = asihpi_tuner_band_query(kcontrol, tuner_bands, |
| 1957 | HPI_TUNER_BAND_LAST); |
| 1958 | |
Eliot Blennerhassett | ba94455 | 2011-02-10 17:26:04 +1300 | [diff] [blame] | 1959 | hpi_handle_error(hpi_tuner_get_band(h_control, &band)); |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 1960 | |
| 1961 | ucontrol->value.enumerated.item[0] = -1; |
| 1962 | for (idx = 0; idx < HPI_TUNER_BAND_LAST; idx++) |
| 1963 | if (tuner_bands[idx] == band) { |
| 1964 | ucontrol->value.enumerated.item[0] = idx; |
| 1965 | break; |
| 1966 | } |
| 1967 | |
| 1968 | return 0; |
| 1969 | } |
| 1970 | |
| 1971 | static int snd_asihpi_tuner_band_put(struct snd_kcontrol *kcontrol, |
| 1972 | struct snd_ctl_elem_value *ucontrol) |
| 1973 | { |
| 1974 | /* |
| 1975 | struct snd_card_asihpi *asihpi = snd_kcontrol_chip(kcontrol); |
| 1976 | */ |
| 1977 | u32 h_control = kcontrol->private_value; |
Dan Carpenter | 0c21fcc | 2013-09-13 10:44:44 +0300 | [diff] [blame] | 1978 | unsigned int idx; |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 1979 | u16 band; |
| 1980 | u16 tuner_bands[HPI_TUNER_BAND_LAST]; |
| 1981 | u32 num_bands = 0; |
| 1982 | |
| 1983 | num_bands = asihpi_tuner_band_query(kcontrol, tuner_bands, |
| 1984 | HPI_TUNER_BAND_LAST); |
| 1985 | |
Dan Carpenter | 0c21fcc | 2013-09-13 10:44:44 +0300 | [diff] [blame] | 1986 | idx = ucontrol->value.enumerated.item[0]; |
| 1987 | if (idx >= ARRAY_SIZE(tuner_bands)) |
| 1988 | idx = ARRAY_SIZE(tuner_bands) - 1; |
| 1989 | band = tuner_bands[idx]; |
Eliot Blennerhassett | ba94455 | 2011-02-10 17:26:04 +1300 | [diff] [blame] | 1990 | hpi_handle_error(hpi_tuner_set_band(h_control, band)); |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 1991 | |
| 1992 | return 1; |
| 1993 | } |
| 1994 | |
| 1995 | /* Freq */ |
| 1996 | |
| 1997 | static int snd_asihpi_tuner_freq_info(struct snd_kcontrol *kcontrol, |
| 1998 | struct snd_ctl_elem_info *uinfo) |
| 1999 | { |
| 2000 | u32 h_control = kcontrol->private_value; |
| 2001 | u16 err; |
| 2002 | u16 tuner_bands[HPI_TUNER_BAND_LAST]; |
| 2003 | u16 num_bands = 0, band_iter, idx; |
| 2004 | u32 freq_range[3], temp_freq_range[3]; |
| 2005 | |
| 2006 | num_bands = asihpi_tuner_band_query(kcontrol, tuner_bands, |
| 2007 | HPI_TUNER_BAND_LAST); |
| 2008 | |
| 2009 | freq_range[0] = INT_MAX; |
| 2010 | freq_range[1] = 0; |
| 2011 | freq_range[2] = INT_MAX; |
| 2012 | |
| 2013 | for (band_iter = 0; band_iter < num_bands; band_iter++) { |
| 2014 | for (idx = 0; idx < 3; idx++) { |
Eliot Blennerhassett | ba94455 | 2011-02-10 17:26:04 +1300 | [diff] [blame] | 2015 | err = hpi_tuner_query_frequency(h_control, |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 2016 | idx, tuner_bands[band_iter], |
| 2017 | &temp_freq_range[idx]); |
| 2018 | if (err != 0) |
| 2019 | return err; |
| 2020 | } |
| 2021 | |
| 2022 | /* skip band with bogus stepping */ |
| 2023 | if (temp_freq_range[2] <= 0) |
| 2024 | continue; |
| 2025 | |
| 2026 | if (temp_freq_range[0] < freq_range[0]) |
| 2027 | freq_range[0] = temp_freq_range[0]; |
| 2028 | if (temp_freq_range[1] > freq_range[1]) |
| 2029 | freq_range[1] = temp_freq_range[1]; |
| 2030 | if (temp_freq_range[2] < freq_range[2]) |
| 2031 | freq_range[2] = temp_freq_range[2]; |
| 2032 | } |
| 2033 | |
| 2034 | uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; |
| 2035 | uinfo->count = 1; |
| 2036 | uinfo->value.integer.min = ((int)freq_range[0]); |
| 2037 | uinfo->value.integer.max = ((int)freq_range[1]); |
| 2038 | uinfo->value.integer.step = ((int)freq_range[2]); |
| 2039 | return 0; |
| 2040 | } |
| 2041 | |
| 2042 | static int snd_asihpi_tuner_freq_get(struct snd_kcontrol *kcontrol, |
| 2043 | struct snd_ctl_elem_value *ucontrol) |
| 2044 | { |
| 2045 | u32 h_control = kcontrol->private_value; |
| 2046 | u32 freq; |
| 2047 | |
Eliot Blennerhassett | ba94455 | 2011-02-10 17:26:04 +1300 | [diff] [blame] | 2048 | hpi_handle_error(hpi_tuner_get_frequency(h_control, &freq)); |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 2049 | ucontrol->value.integer.value[0] = freq; |
| 2050 | |
| 2051 | return 0; |
| 2052 | } |
| 2053 | |
| 2054 | static int snd_asihpi_tuner_freq_put(struct snd_kcontrol *kcontrol, |
| 2055 | struct snd_ctl_elem_value *ucontrol) |
| 2056 | { |
| 2057 | u32 h_control = kcontrol->private_value; |
| 2058 | u32 freq; |
| 2059 | |
| 2060 | freq = ucontrol->value.integer.value[0]; |
Eliot Blennerhassett | ba94455 | 2011-02-10 17:26:04 +1300 | [diff] [blame] | 2061 | hpi_handle_error(hpi_tuner_set_frequency(h_control, freq)); |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 2062 | |
| 2063 | return 1; |
| 2064 | } |
| 2065 | |
| 2066 | /* Tuner control group initializer */ |
Bill Pemberton | e23e7a1 | 2012-12-06 12:35:10 -0500 | [diff] [blame] | 2067 | static int snd_asihpi_tuner_add(struct snd_card_asihpi *asihpi, |
| 2068 | struct hpi_control *hpi_ctl) |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 2069 | { |
| 2070 | struct snd_card *card = asihpi->card; |
| 2071 | struct snd_kcontrol_new snd_control; |
| 2072 | |
| 2073 | snd_control.private_value = hpi_ctl->h_control; |
| 2074 | snd_control.access = SNDRV_CTL_ELEM_ACCESS_READWRITE; |
| 2075 | |
Eliot Blennerhassett | ba94455 | 2011-02-10 17:26:04 +1300 | [diff] [blame] | 2076 | if (!hpi_tuner_get_gain(hpi_ctl->h_control, NULL)) { |
Eliot Blennerhassett | e64b1a2 | 2011-02-10 17:25:59 +1300 | [diff] [blame] | 2077 | asihpi_ctl_init(&snd_control, hpi_ctl, "Gain"); |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 2078 | snd_control.info = snd_asihpi_tuner_gain_info; |
| 2079 | snd_control.get = snd_asihpi_tuner_gain_get; |
| 2080 | snd_control.put = snd_asihpi_tuner_gain_put; |
| 2081 | |
| 2082 | if (ctl_add(card, &snd_control, asihpi) < 0) |
| 2083 | return -EINVAL; |
| 2084 | } |
| 2085 | |
Eliot Blennerhassett | e64b1a2 | 2011-02-10 17:25:59 +1300 | [diff] [blame] | 2086 | asihpi_ctl_init(&snd_control, hpi_ctl, "Band"); |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 2087 | snd_control.info = snd_asihpi_tuner_band_info; |
| 2088 | snd_control.get = snd_asihpi_tuner_band_get; |
| 2089 | snd_control.put = snd_asihpi_tuner_band_put; |
| 2090 | |
| 2091 | if (ctl_add(card, &snd_control, asihpi) < 0) |
| 2092 | return -EINVAL; |
| 2093 | |
Eliot Blennerhassett | e64b1a2 | 2011-02-10 17:25:59 +1300 | [diff] [blame] | 2094 | asihpi_ctl_init(&snd_control, hpi_ctl, "Freq"); |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 2095 | snd_control.info = snd_asihpi_tuner_freq_info; |
| 2096 | snd_control.get = snd_asihpi_tuner_freq_get; |
| 2097 | snd_control.put = snd_asihpi_tuner_freq_put; |
| 2098 | |
| 2099 | return ctl_add(card, &snd_control, asihpi); |
| 2100 | } |
| 2101 | |
| 2102 | /*------------------------------------------------------------ |
| 2103 | Meter controls |
| 2104 | ------------------------------------------------------------*/ |
| 2105 | static int snd_asihpi_meter_info(struct snd_kcontrol *kcontrol, |
| 2106 | struct snd_ctl_elem_info *uinfo) |
| 2107 | { |
Eliot Blennerhassett | d4b06d2 | 2011-12-22 13:38:34 +1300 | [diff] [blame] | 2108 | u32 h_control = kcontrol->private_value; |
| 2109 | u32 count; |
| 2110 | u16 err; |
| 2111 | err = hpi_meter_query_channels(h_control, &count); |
| 2112 | if (err) |
| 2113 | count = HPI_MAX_CHANNELS; |
| 2114 | |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 2115 | uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; |
Eliot Blennerhassett | d4b06d2 | 2011-12-22 13:38:34 +1300 | [diff] [blame] | 2116 | uinfo->count = count; |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 2117 | uinfo->value.integer.min = 0; |
| 2118 | uinfo->value.integer.max = 0x7FFFFFFF; |
| 2119 | return 0; |
| 2120 | } |
| 2121 | |
| 2122 | /* linear values for 10dB steps */ |
| 2123 | static int log2lin[] = { |
| 2124 | 0x7FFFFFFF, /* 0dB */ |
| 2125 | 679093956, |
| 2126 | 214748365, |
| 2127 | 67909396, |
| 2128 | 21474837, |
| 2129 | 6790940, |
| 2130 | 2147484, /* -60dB */ |
| 2131 | 679094, |
| 2132 | 214748, /* -80 */ |
| 2133 | 67909, |
| 2134 | 21475, /* -100 */ |
| 2135 | 6791, |
| 2136 | 2147, |
| 2137 | 679, |
| 2138 | 214, |
| 2139 | 68, |
| 2140 | 21, |
| 2141 | 7, |
| 2142 | 2 |
| 2143 | }; |
| 2144 | |
| 2145 | static int snd_asihpi_meter_get(struct snd_kcontrol *kcontrol, |
| 2146 | struct snd_ctl_elem_value *ucontrol) |
| 2147 | { |
| 2148 | u32 h_control = kcontrol->private_value; |
| 2149 | short an_gain_mB[HPI_MAX_CHANNELS], i; |
| 2150 | u16 err; |
| 2151 | |
Eliot Blennerhassett | ba94455 | 2011-02-10 17:26:04 +1300 | [diff] [blame] | 2152 | err = hpi_meter_get_peak(h_control, an_gain_mB); |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 2153 | |
| 2154 | for (i = 0; i < HPI_MAX_CHANNELS; i++) { |
| 2155 | if (err) { |
| 2156 | ucontrol->value.integer.value[i] = 0; |
| 2157 | } else if (an_gain_mB[i] >= 0) { |
| 2158 | ucontrol->value.integer.value[i] = |
| 2159 | an_gain_mB[i] << 16; |
| 2160 | } else { |
| 2161 | /* -ve is log value in millibels < -60dB, |
| 2162 | * convert to (roughly!) linear, |
| 2163 | */ |
| 2164 | ucontrol->value.integer.value[i] = |
| 2165 | log2lin[an_gain_mB[i] / -1000]; |
| 2166 | } |
| 2167 | } |
| 2168 | return 0; |
| 2169 | } |
| 2170 | |
Bill Pemberton | e23e7a1 | 2012-12-06 12:35:10 -0500 | [diff] [blame] | 2171 | static int snd_asihpi_meter_add(struct snd_card_asihpi *asihpi, |
| 2172 | struct hpi_control *hpi_ctl, int subidx) |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 2173 | { |
| 2174 | struct snd_card *card = asihpi->card; |
| 2175 | struct snd_kcontrol_new snd_control; |
| 2176 | |
Eliot Blennerhassett | e64b1a2 | 2011-02-10 17:25:59 +1300 | [diff] [blame] | 2177 | asihpi_ctl_init(&snd_control, hpi_ctl, "Meter"); |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 2178 | snd_control.access = |
| 2179 | SNDRV_CTL_ELEM_ACCESS_VOLATILE | SNDRV_CTL_ELEM_ACCESS_READ; |
| 2180 | snd_control.info = snd_asihpi_meter_info; |
| 2181 | snd_control.get = snd_asihpi_meter_get; |
| 2182 | |
| 2183 | snd_control.index = subidx; |
| 2184 | |
| 2185 | return ctl_add(card, &snd_control, asihpi); |
| 2186 | } |
| 2187 | |
| 2188 | /*------------------------------------------------------------ |
| 2189 | Multiplexer controls |
| 2190 | ------------------------------------------------------------*/ |
| 2191 | static int snd_card_asihpi_mux_count_sources(struct snd_kcontrol *snd_control) |
| 2192 | { |
| 2193 | u32 h_control = snd_control->private_value; |
| 2194 | struct hpi_control hpi_ctl; |
| 2195 | int s, err; |
| 2196 | for (s = 0; s < 32; s++) { |
Eliot Blennerhassett | ba94455 | 2011-02-10 17:26:04 +1300 | [diff] [blame] | 2197 | err = hpi_multiplexer_query_source(h_control, s, |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 2198 | &hpi_ctl. |
| 2199 | src_node_type, |
| 2200 | &hpi_ctl. |
| 2201 | src_node_index); |
| 2202 | if (err) |
| 2203 | break; |
| 2204 | } |
| 2205 | return s; |
| 2206 | } |
| 2207 | |
| 2208 | static int snd_asihpi_mux_info(struct snd_kcontrol *kcontrol, |
| 2209 | struct snd_ctl_elem_info *uinfo) |
| 2210 | { |
| 2211 | int err; |
| 2212 | u16 src_node_type, src_node_index; |
| 2213 | u32 h_control = kcontrol->private_value; |
| 2214 | |
| 2215 | uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; |
| 2216 | uinfo->count = 1; |
| 2217 | uinfo->value.enumerated.items = |
| 2218 | snd_card_asihpi_mux_count_sources(kcontrol); |
| 2219 | |
| 2220 | if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items) |
| 2221 | uinfo->value.enumerated.item = |
| 2222 | uinfo->value.enumerated.items - 1; |
| 2223 | |
| 2224 | err = |
Eliot Blennerhassett | ba94455 | 2011-02-10 17:26:04 +1300 | [diff] [blame] | 2225 | hpi_multiplexer_query_source(h_control, |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 2226 | uinfo->value.enumerated.item, |
| 2227 | &src_node_type, &src_node_index); |
| 2228 | |
| 2229 | sprintf(uinfo->value.enumerated.name, "%s %d", |
Eliot Blennerhassett | 168f1b0 | 2010-07-06 08:37:06 +1200 | [diff] [blame] | 2230 | asihpi_src_names[src_node_type - HPI_SOURCENODE_NONE], |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 2231 | src_node_index); |
| 2232 | return 0; |
| 2233 | } |
| 2234 | |
| 2235 | static int snd_asihpi_mux_get(struct snd_kcontrol *kcontrol, |
| 2236 | struct snd_ctl_elem_value *ucontrol) |
| 2237 | { |
| 2238 | u32 h_control = kcontrol->private_value; |
| 2239 | u16 source_type, source_index; |
| 2240 | u16 src_node_type, src_node_index; |
| 2241 | int s; |
| 2242 | |
Eliot Blennerhassett | ba94455 | 2011-02-10 17:26:04 +1300 | [diff] [blame] | 2243 | hpi_handle_error(hpi_multiplexer_get_source(h_control, |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 2244 | &source_type, &source_index)); |
| 2245 | /* Should cache this search result! */ |
| 2246 | for (s = 0; s < 256; s++) { |
Eliot Blennerhassett | ba94455 | 2011-02-10 17:26:04 +1300 | [diff] [blame] | 2247 | if (hpi_multiplexer_query_source(h_control, s, |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 2248 | &src_node_type, &src_node_index)) |
| 2249 | break; |
| 2250 | |
| 2251 | if ((source_type == src_node_type) |
| 2252 | && (source_index == src_node_index)) { |
| 2253 | ucontrol->value.enumerated.item[0] = s; |
| 2254 | return 0; |
| 2255 | } |
| 2256 | } |
| 2257 | snd_printd(KERN_WARNING |
Eliot Blennerhassett | e64b1a2 | 2011-02-10 17:25:59 +1300 | [diff] [blame] | 2258 | "Control %x failed to match mux source %hu %hu\n", |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 2259 | h_control, source_type, source_index); |
| 2260 | ucontrol->value.enumerated.item[0] = 0; |
| 2261 | return 0; |
| 2262 | } |
| 2263 | |
| 2264 | static int snd_asihpi_mux_put(struct snd_kcontrol *kcontrol, |
| 2265 | struct snd_ctl_elem_value *ucontrol) |
| 2266 | { |
| 2267 | int change; |
| 2268 | u32 h_control = kcontrol->private_value; |
| 2269 | u16 source_type, source_index; |
| 2270 | u16 e; |
| 2271 | |
| 2272 | change = 1; |
| 2273 | |
Eliot Blennerhassett | ba94455 | 2011-02-10 17:26:04 +1300 | [diff] [blame] | 2274 | e = hpi_multiplexer_query_source(h_control, |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 2275 | ucontrol->value.enumerated.item[0], |
| 2276 | &source_type, &source_index); |
| 2277 | if (!e) |
| 2278 | hpi_handle_error( |
Eliot Blennerhassett | ba94455 | 2011-02-10 17:26:04 +1300 | [diff] [blame] | 2279 | hpi_multiplexer_set_source(h_control, |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 2280 | source_type, source_index)); |
| 2281 | return change; |
| 2282 | } |
| 2283 | |
| 2284 | |
Bill Pemberton | e23e7a1 | 2012-12-06 12:35:10 -0500 | [diff] [blame] | 2285 | static int snd_asihpi_mux_add(struct snd_card_asihpi *asihpi, |
| 2286 | struct hpi_control *hpi_ctl) |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 2287 | { |
| 2288 | struct snd_card *card = asihpi->card; |
| 2289 | struct snd_kcontrol_new snd_control; |
| 2290 | |
Eliot Blennerhassett | e64b1a2 | 2011-02-10 17:25:59 +1300 | [diff] [blame] | 2291 | asihpi_ctl_init(&snd_control, hpi_ctl, "Route"); |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 2292 | snd_control.access = SNDRV_CTL_ELEM_ACCESS_READWRITE; |
| 2293 | snd_control.info = snd_asihpi_mux_info; |
| 2294 | snd_control.get = snd_asihpi_mux_get; |
| 2295 | snd_control.put = snd_asihpi_mux_put; |
| 2296 | |
| 2297 | return ctl_add(card, &snd_control, asihpi); |
| 2298 | |
| 2299 | } |
| 2300 | |
| 2301 | /*------------------------------------------------------------ |
| 2302 | Channel mode controls |
| 2303 | ------------------------------------------------------------*/ |
| 2304 | static int snd_asihpi_cmode_info(struct snd_kcontrol *kcontrol, |
| 2305 | struct snd_ctl_elem_info *uinfo) |
| 2306 | { |
Eliot Blennerhassett | e64b1a2 | 2011-02-10 17:25:59 +1300 | [diff] [blame] | 2307 | static const char * const mode_names[HPI_CHANNEL_MODE_LAST + 1] = { |
| 2308 | "invalid", |
| 2309 | "Normal", "Swap", |
| 2310 | "From Left", "From Right", |
| 2311 | "To Left", "To Right" |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 2312 | }; |
| 2313 | |
| 2314 | u32 h_control = kcontrol->private_value; |
| 2315 | u16 mode; |
| 2316 | int i; |
Takashi Iwai | 30d0ae4 | 2014-10-20 18:15:50 +0200 | [diff] [blame] | 2317 | const char *mapped_names[6]; |
Eliot Blennerhassett | e64b1a2 | 2011-02-10 17:25:59 +1300 | [diff] [blame] | 2318 | int valid_modes = 0; |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 2319 | |
| 2320 | /* HPI channel mode values can be from 1 to 6 |
| 2321 | Some adapters only support a contiguous subset |
| 2322 | */ |
| 2323 | for (i = 0; i < HPI_CHANNEL_MODE_LAST; i++) |
Eliot Blennerhassett | e64b1a2 | 2011-02-10 17:25:59 +1300 | [diff] [blame] | 2324 | if (!hpi_channel_mode_query_mode( |
Eliot Blennerhassett | ba94455 | 2011-02-10 17:26:04 +1300 | [diff] [blame] | 2325 | h_control, i, &mode)) { |
Takashi Iwai | 30d0ae4 | 2014-10-20 18:15:50 +0200 | [diff] [blame] | 2326 | mapped_names[valid_modes] = mode_names[mode]; |
Eliot Blennerhassett | e64b1a2 | 2011-02-10 17:25:59 +1300 | [diff] [blame] | 2327 | valid_modes++; |
| 2328 | } |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 2329 | |
Takashi Iwai | 74eeb14 | 2012-01-09 18:26:05 +0100 | [diff] [blame] | 2330 | if (!valid_modes) |
| 2331 | return -EINVAL; |
| 2332 | |
Takashi Iwai | 30d0ae4 | 2014-10-20 18:15:50 +0200 | [diff] [blame] | 2333 | return snd_ctl_enum_info(uinfo, 1, valid_modes, mapped_names); |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 2334 | } |
| 2335 | |
| 2336 | static int snd_asihpi_cmode_get(struct snd_kcontrol *kcontrol, |
| 2337 | struct snd_ctl_elem_value *ucontrol) |
| 2338 | { |
| 2339 | u32 h_control = kcontrol->private_value; |
| 2340 | u16 mode; |
| 2341 | |
Eliot Blennerhassett | ba94455 | 2011-02-10 17:26:04 +1300 | [diff] [blame] | 2342 | if (hpi_channel_mode_get(h_control, &mode)) |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 2343 | mode = 1; |
| 2344 | |
| 2345 | ucontrol->value.enumerated.item[0] = mode - 1; |
| 2346 | |
| 2347 | return 0; |
| 2348 | } |
| 2349 | |
| 2350 | static int snd_asihpi_cmode_put(struct snd_kcontrol *kcontrol, |
| 2351 | struct snd_ctl_elem_value *ucontrol) |
| 2352 | { |
| 2353 | int change; |
| 2354 | u32 h_control = kcontrol->private_value; |
| 2355 | |
| 2356 | change = 1; |
| 2357 | |
Eliot Blennerhassett | ba94455 | 2011-02-10 17:26:04 +1300 | [diff] [blame] | 2358 | hpi_handle_error(hpi_channel_mode_set(h_control, |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 2359 | ucontrol->value.enumerated.item[0] + 1)); |
| 2360 | return change; |
| 2361 | } |
| 2362 | |
| 2363 | |
Bill Pemberton | e23e7a1 | 2012-12-06 12:35:10 -0500 | [diff] [blame] | 2364 | static int snd_asihpi_cmode_add(struct snd_card_asihpi *asihpi, |
| 2365 | struct hpi_control *hpi_ctl) |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 2366 | { |
| 2367 | struct snd_card *card = asihpi->card; |
| 2368 | struct snd_kcontrol_new snd_control; |
| 2369 | |
Eliot Blennerhassett | e64b1a2 | 2011-02-10 17:25:59 +1300 | [diff] [blame] | 2370 | asihpi_ctl_init(&snd_control, hpi_ctl, "Mode"); |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 2371 | snd_control.access = SNDRV_CTL_ELEM_ACCESS_READWRITE; |
| 2372 | snd_control.info = snd_asihpi_cmode_info; |
| 2373 | snd_control.get = snd_asihpi_cmode_get; |
| 2374 | snd_control.put = snd_asihpi_cmode_put; |
| 2375 | |
| 2376 | return ctl_add(card, &snd_control, asihpi); |
| 2377 | } |
| 2378 | |
| 2379 | /*------------------------------------------------------------ |
| 2380 | Sampleclock source controls |
| 2381 | ------------------------------------------------------------*/ |
Eliot Blennerhassett | 3872f19 | 2014-11-20 16:22:49 +1300 | [diff] [blame] | 2382 | static const char const *sampleclock_sources[] = { |
Eliot Blennerhassett | ba94455 | 2011-02-10 17:26:04 +1300 | [diff] [blame] | 2383 | "N/A", "Local PLL", "Digital Sync", "Word External", "Word Header", |
| 2384 | "SMPTE", "Digital1", "Auto", "Network", "Invalid", |
Eliot Blennerhassett | 3872f19 | 2014-11-20 16:22:49 +1300 | [diff] [blame] | 2385 | "Prev Module", "BLU-Link", |
Eliot Blennerhassett | ba94455 | 2011-02-10 17:26:04 +1300 | [diff] [blame] | 2386 | "Digital2", "Digital3", "Digital4", "Digital5", |
| 2387 | "Digital6", "Digital7", "Digital8"}; |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 2388 | |
Eliot Blennerhassett | 3872f19 | 2014-11-20 16:22:49 +1300 | [diff] [blame] | 2389 | /* Number of strings must match expected enumerated values */ |
| 2390 | compile_time_assert( |
| 2391 | (ARRAY_SIZE(sampleclock_sources) == MAX_CLOCKSOURCES), |
| 2392 | assert_sampleclock_sources_size); |
| 2393 | |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 2394 | static int snd_asihpi_clksrc_info(struct snd_kcontrol *kcontrol, |
| 2395 | struct snd_ctl_elem_info *uinfo) |
| 2396 | { |
| 2397 | struct snd_card_asihpi *asihpi = |
| 2398 | (struct snd_card_asihpi *)(kcontrol->private_data); |
| 2399 | struct clk_cache *clkcache = &asihpi->cc; |
| 2400 | uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; |
| 2401 | uinfo->count = 1; |
| 2402 | uinfo->value.enumerated.items = clkcache->count; |
| 2403 | |
| 2404 | if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items) |
| 2405 | uinfo->value.enumerated.item = |
| 2406 | uinfo->value.enumerated.items - 1; |
| 2407 | |
| 2408 | strcpy(uinfo->value.enumerated.name, |
| 2409 | clkcache->s[uinfo->value.enumerated.item].name); |
| 2410 | return 0; |
| 2411 | } |
| 2412 | |
| 2413 | static int snd_asihpi_clksrc_get(struct snd_kcontrol *kcontrol, |
| 2414 | struct snd_ctl_elem_value *ucontrol) |
| 2415 | { |
| 2416 | struct snd_card_asihpi *asihpi = |
| 2417 | (struct snd_card_asihpi *)(kcontrol->private_data); |
| 2418 | struct clk_cache *clkcache = &asihpi->cc; |
| 2419 | u32 h_control = kcontrol->private_value; |
| 2420 | u16 source, srcindex = 0; |
| 2421 | int i; |
| 2422 | |
| 2423 | ucontrol->value.enumerated.item[0] = 0; |
Eliot Blennerhassett | ba94455 | 2011-02-10 17:26:04 +1300 | [diff] [blame] | 2424 | if (hpi_sample_clock_get_source(h_control, &source)) |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 2425 | source = 0; |
| 2426 | |
| 2427 | if (source == HPI_SAMPLECLOCK_SOURCE_AESEBU_INPUT) |
Eliot Blennerhassett | ba94455 | 2011-02-10 17:26:04 +1300 | [diff] [blame] | 2428 | if (hpi_sample_clock_get_source_index(h_control, &srcindex)) |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 2429 | srcindex = 0; |
| 2430 | |
| 2431 | for (i = 0; i < clkcache->count; i++) |
| 2432 | if ((clkcache->s[i].source == source) && |
| 2433 | (clkcache->s[i].index == srcindex)) |
| 2434 | break; |
| 2435 | |
| 2436 | ucontrol->value.enumerated.item[0] = i; |
| 2437 | |
| 2438 | return 0; |
| 2439 | } |
| 2440 | |
| 2441 | static int snd_asihpi_clksrc_put(struct snd_kcontrol *kcontrol, |
| 2442 | struct snd_ctl_elem_value *ucontrol) |
| 2443 | { |
| 2444 | struct snd_card_asihpi *asihpi = |
| 2445 | (struct snd_card_asihpi *)(kcontrol->private_data); |
| 2446 | struct clk_cache *clkcache = &asihpi->cc; |
Dan Carpenter | 0c21fcc | 2013-09-13 10:44:44 +0300 | [diff] [blame] | 2447 | unsigned int item; |
| 2448 | int change; |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 2449 | u32 h_control = kcontrol->private_value; |
| 2450 | |
| 2451 | change = 1; |
| 2452 | item = ucontrol->value.enumerated.item[0]; |
| 2453 | if (item >= clkcache->count) |
| 2454 | item = clkcache->count-1; |
| 2455 | |
Eliot Blennerhassett | ba94455 | 2011-02-10 17:26:04 +1300 | [diff] [blame] | 2456 | hpi_handle_error(hpi_sample_clock_set_source( |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 2457 | h_control, clkcache->s[item].source)); |
| 2458 | |
| 2459 | if (clkcache->s[item].source == HPI_SAMPLECLOCK_SOURCE_AESEBU_INPUT) |
Eliot Blennerhassett | ba94455 | 2011-02-10 17:26:04 +1300 | [diff] [blame] | 2460 | hpi_handle_error(hpi_sample_clock_set_source_index( |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 2461 | h_control, clkcache->s[item].index)); |
| 2462 | return change; |
| 2463 | } |
| 2464 | |
| 2465 | /*------------------------------------------------------------ |
| 2466 | Clkrate controls |
| 2467 | ------------------------------------------------------------*/ |
| 2468 | /* Need to change this to enumerated control with list of rates */ |
| 2469 | static int snd_asihpi_clklocal_info(struct snd_kcontrol *kcontrol, |
| 2470 | struct snd_ctl_elem_info *uinfo) |
| 2471 | { |
| 2472 | uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; |
| 2473 | uinfo->count = 1; |
| 2474 | uinfo->value.integer.min = 8000; |
| 2475 | uinfo->value.integer.max = 192000; |
| 2476 | uinfo->value.integer.step = 100; |
| 2477 | |
| 2478 | return 0; |
| 2479 | } |
| 2480 | |
| 2481 | static int snd_asihpi_clklocal_get(struct snd_kcontrol *kcontrol, |
| 2482 | struct snd_ctl_elem_value *ucontrol) |
| 2483 | { |
| 2484 | u32 h_control = kcontrol->private_value; |
| 2485 | u32 rate; |
| 2486 | u16 e; |
| 2487 | |
Eliot Blennerhassett | ba94455 | 2011-02-10 17:26:04 +1300 | [diff] [blame] | 2488 | e = hpi_sample_clock_get_local_rate(h_control, &rate); |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 2489 | if (!e) |
| 2490 | ucontrol->value.integer.value[0] = rate; |
| 2491 | else |
| 2492 | ucontrol->value.integer.value[0] = 0; |
| 2493 | return 0; |
| 2494 | } |
| 2495 | |
| 2496 | static int snd_asihpi_clklocal_put(struct snd_kcontrol *kcontrol, |
| 2497 | struct snd_ctl_elem_value *ucontrol) |
| 2498 | { |
| 2499 | int change; |
| 2500 | u32 h_control = kcontrol->private_value; |
| 2501 | |
| 2502 | /* change = asihpi->mixer_clkrate[addr][0] != left || |
| 2503 | asihpi->mixer_clkrate[addr][1] != right; |
| 2504 | */ |
| 2505 | change = 1; |
Eliot Blennerhassett | ba94455 | 2011-02-10 17:26:04 +1300 | [diff] [blame] | 2506 | hpi_handle_error(hpi_sample_clock_set_local_rate(h_control, |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 2507 | ucontrol->value.integer.value[0])); |
| 2508 | return change; |
| 2509 | } |
| 2510 | |
| 2511 | static int snd_asihpi_clkrate_info(struct snd_kcontrol *kcontrol, |
| 2512 | struct snd_ctl_elem_info *uinfo) |
| 2513 | { |
| 2514 | uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; |
| 2515 | uinfo->count = 1; |
| 2516 | uinfo->value.integer.min = 8000; |
| 2517 | uinfo->value.integer.max = 192000; |
| 2518 | uinfo->value.integer.step = 100; |
| 2519 | |
| 2520 | return 0; |
| 2521 | } |
| 2522 | |
| 2523 | static int snd_asihpi_clkrate_get(struct snd_kcontrol *kcontrol, |
| 2524 | struct snd_ctl_elem_value *ucontrol) |
| 2525 | { |
| 2526 | u32 h_control = kcontrol->private_value; |
| 2527 | u32 rate; |
| 2528 | u16 e; |
| 2529 | |
Eliot Blennerhassett | ba94455 | 2011-02-10 17:26:04 +1300 | [diff] [blame] | 2530 | e = hpi_sample_clock_get_sample_rate(h_control, &rate); |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 2531 | if (!e) |
| 2532 | ucontrol->value.integer.value[0] = rate; |
| 2533 | else |
| 2534 | ucontrol->value.integer.value[0] = 0; |
| 2535 | return 0; |
| 2536 | } |
| 2537 | |
Bill Pemberton | e23e7a1 | 2012-12-06 12:35:10 -0500 | [diff] [blame] | 2538 | static int snd_asihpi_sampleclock_add(struct snd_card_asihpi *asihpi, |
| 2539 | struct hpi_control *hpi_ctl) |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 2540 | { |
Eliot Blennerhassett | f9a376c | 2014-11-20 16:22:53 +1300 | [diff] [blame] | 2541 | struct snd_card *card; |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 2542 | struct snd_kcontrol_new snd_control; |
| 2543 | |
Eliot Blennerhassett | f9a376c | 2014-11-20 16:22:53 +1300 | [diff] [blame] | 2544 | struct clk_cache *clkcache; |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 2545 | u32 hSC = hpi_ctl->h_control; |
| 2546 | int has_aes_in = 0; |
| 2547 | int i, j; |
| 2548 | u16 source; |
| 2549 | |
Eliot Blennerhassett | f9a376c | 2014-11-20 16:22:53 +1300 | [diff] [blame] | 2550 | if (snd_BUG_ON(!asihpi)) |
| 2551 | return -EINVAL; |
| 2552 | card = asihpi->card; |
| 2553 | clkcache = &asihpi->cc; |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 2554 | snd_control.private_value = hpi_ctl->h_control; |
| 2555 | |
| 2556 | clkcache->has_local = 0; |
| 2557 | |
| 2558 | for (i = 0; i <= HPI_SAMPLECLOCK_SOURCE_LAST; i++) { |
Eliot Blennerhassett | ba94455 | 2011-02-10 17:26:04 +1300 | [diff] [blame] | 2559 | if (hpi_sample_clock_query_source(hSC, |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 2560 | i, &source)) |
| 2561 | break; |
| 2562 | clkcache->s[i].source = source; |
| 2563 | clkcache->s[i].index = 0; |
| 2564 | clkcache->s[i].name = sampleclock_sources[source]; |
| 2565 | if (source == HPI_SAMPLECLOCK_SOURCE_AESEBU_INPUT) |
| 2566 | has_aes_in = 1; |
| 2567 | if (source == HPI_SAMPLECLOCK_SOURCE_LOCAL) |
| 2568 | clkcache->has_local = 1; |
| 2569 | } |
| 2570 | if (has_aes_in) |
| 2571 | /* already will have picked up index 0 above */ |
| 2572 | for (j = 1; j < 8; j++) { |
Eliot Blennerhassett | ba94455 | 2011-02-10 17:26:04 +1300 | [diff] [blame] | 2573 | if (hpi_sample_clock_query_source_index(hSC, |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 2574 | j, HPI_SAMPLECLOCK_SOURCE_AESEBU_INPUT, |
| 2575 | &source)) |
| 2576 | break; |
| 2577 | clkcache->s[i].source = |
| 2578 | HPI_SAMPLECLOCK_SOURCE_AESEBU_INPUT; |
| 2579 | clkcache->s[i].index = j; |
| 2580 | clkcache->s[i].name = sampleclock_sources[ |
| 2581 | j+HPI_SAMPLECLOCK_SOURCE_LAST]; |
| 2582 | i++; |
| 2583 | } |
| 2584 | clkcache->count = i; |
| 2585 | |
Eliot Blennerhassett | e64b1a2 | 2011-02-10 17:25:59 +1300 | [diff] [blame] | 2586 | asihpi_ctl_init(&snd_control, hpi_ctl, "Source"); |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 2587 | snd_control.access = SNDRV_CTL_ELEM_ACCESS_READWRITE ; |
| 2588 | snd_control.info = snd_asihpi_clksrc_info; |
| 2589 | snd_control.get = snd_asihpi_clksrc_get; |
| 2590 | snd_control.put = snd_asihpi_clksrc_put; |
| 2591 | if (ctl_add(card, &snd_control, asihpi) < 0) |
| 2592 | return -EINVAL; |
| 2593 | |
| 2594 | |
| 2595 | if (clkcache->has_local) { |
Eliot Blennerhassett | e64b1a2 | 2011-02-10 17:25:59 +1300 | [diff] [blame] | 2596 | asihpi_ctl_init(&snd_control, hpi_ctl, "Localrate"); |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 2597 | snd_control.access = SNDRV_CTL_ELEM_ACCESS_READWRITE ; |
| 2598 | snd_control.info = snd_asihpi_clklocal_info; |
| 2599 | snd_control.get = snd_asihpi_clklocal_get; |
| 2600 | snd_control.put = snd_asihpi_clklocal_put; |
| 2601 | |
| 2602 | |
| 2603 | if (ctl_add(card, &snd_control, asihpi) < 0) |
| 2604 | return -EINVAL; |
| 2605 | } |
| 2606 | |
Eliot Blennerhassett | e64b1a2 | 2011-02-10 17:25:59 +1300 | [diff] [blame] | 2607 | asihpi_ctl_init(&snd_control, hpi_ctl, "Rate"); |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 2608 | snd_control.access = |
| 2609 | SNDRV_CTL_ELEM_ACCESS_VOLATILE | SNDRV_CTL_ELEM_ACCESS_READ; |
| 2610 | snd_control.info = snd_asihpi_clkrate_info; |
| 2611 | snd_control.get = snd_asihpi_clkrate_get; |
| 2612 | |
| 2613 | return ctl_add(card, &snd_control, asihpi); |
| 2614 | } |
| 2615 | /*------------------------------------------------------------ |
| 2616 | Mixer |
| 2617 | ------------------------------------------------------------*/ |
| 2618 | |
Bill Pemberton | e23e7a1 | 2012-12-06 12:35:10 -0500 | [diff] [blame] | 2619 | static int snd_card_asihpi_mixer_new(struct snd_card_asihpi *asihpi) |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 2620 | { |
Wei Yongjun | 2e9b9a3 | 2013-03-12 00:16:40 +0800 | [diff] [blame] | 2621 | struct snd_card *card; |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 2622 | unsigned int idx = 0; |
| 2623 | unsigned int subindex = 0; |
| 2624 | int err; |
| 2625 | struct hpi_control hpi_ctl, prev_ctl; |
| 2626 | |
| 2627 | if (snd_BUG_ON(!asihpi)) |
| 2628 | return -EINVAL; |
Wei Yongjun | 2e9b9a3 | 2013-03-12 00:16:40 +0800 | [diff] [blame] | 2629 | card = asihpi->card; |
Eliot Blennerhassett | e64b1a2 | 2011-02-10 17:25:59 +1300 | [diff] [blame] | 2630 | strcpy(card->mixername, "Asihpi Mixer"); |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 2631 | |
| 2632 | err = |
Eliot Blennerhassett | 7036b92 | 2011-12-22 13:38:43 +1300 | [diff] [blame] | 2633 | hpi_mixer_open(asihpi->hpi->adapter->index, |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 2634 | &asihpi->h_mixer); |
| 2635 | hpi_handle_error(err); |
| 2636 | if (err) |
| 2637 | return -err; |
| 2638 | |
Takashi Iwai | 21896bc | 2010-06-02 12:08:37 +0200 | [diff] [blame] | 2639 | memset(&prev_ctl, 0, sizeof(prev_ctl)); |
| 2640 | prev_ctl.control_type = -1; |
| 2641 | |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 2642 | for (idx = 0; idx < 2000; idx++) { |
| 2643 | err = hpi_mixer_get_control_by_index( |
Eliot Blennerhassett | ba94455 | 2011-02-10 17:26:04 +1300 | [diff] [blame] | 2644 | asihpi->h_mixer, |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 2645 | idx, |
| 2646 | &hpi_ctl.src_node_type, |
| 2647 | &hpi_ctl.src_node_index, |
| 2648 | &hpi_ctl.dst_node_type, |
| 2649 | &hpi_ctl.dst_node_index, |
| 2650 | &hpi_ctl.control_type, |
| 2651 | &hpi_ctl.h_control); |
| 2652 | if (err) { |
| 2653 | if (err == HPI_ERROR_CONTROL_DISABLED) { |
| 2654 | if (mixer_dump) |
Eliot Blennerhassett | 12eb089 | 2014-11-20 16:22:55 +1300 | [diff] [blame] | 2655 | dev_info(&asihpi->pci->dev, |
Eliot Blennerhassett | e64b1a2 | 2011-02-10 17:25:59 +1300 | [diff] [blame] | 2656 | "Disabled HPI Control(%d)\n", |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 2657 | idx); |
| 2658 | continue; |
| 2659 | } else |
| 2660 | break; |
| 2661 | |
| 2662 | } |
| 2663 | |
Eliot Blennerhassett | 168f1b0 | 2010-07-06 08:37:06 +1200 | [diff] [blame] | 2664 | hpi_ctl.src_node_type -= HPI_SOURCENODE_NONE; |
| 2665 | hpi_ctl.dst_node_type -= HPI_DESTNODE_NONE; |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 2666 | |
| 2667 | /* ASI50xx in SSX mode has multiple meters on the same node. |
| 2668 | Use subindex to create distinct ALSA controls |
| 2669 | for any duplicated controls. |
| 2670 | */ |
| 2671 | if ((hpi_ctl.control_type == prev_ctl.control_type) && |
| 2672 | (hpi_ctl.src_node_type == prev_ctl.src_node_type) && |
| 2673 | (hpi_ctl.src_node_index == prev_ctl.src_node_index) && |
| 2674 | (hpi_ctl.dst_node_type == prev_ctl.dst_node_type) && |
| 2675 | (hpi_ctl.dst_node_index == prev_ctl.dst_node_index)) |
| 2676 | subindex++; |
| 2677 | else |
| 2678 | subindex = 0; |
| 2679 | |
| 2680 | prev_ctl = hpi_ctl; |
| 2681 | |
| 2682 | switch (hpi_ctl.control_type) { |
| 2683 | case HPI_CONTROL_VOLUME: |
| 2684 | err = snd_asihpi_volume_add(asihpi, &hpi_ctl); |
| 2685 | break; |
| 2686 | case HPI_CONTROL_LEVEL: |
| 2687 | err = snd_asihpi_level_add(asihpi, &hpi_ctl); |
| 2688 | break; |
| 2689 | case HPI_CONTROL_MULTIPLEXER: |
| 2690 | err = snd_asihpi_mux_add(asihpi, &hpi_ctl); |
| 2691 | break; |
| 2692 | case HPI_CONTROL_CHANNEL_MODE: |
| 2693 | err = snd_asihpi_cmode_add(asihpi, &hpi_ctl); |
| 2694 | break; |
| 2695 | case HPI_CONTROL_METER: |
| 2696 | err = snd_asihpi_meter_add(asihpi, &hpi_ctl, subindex); |
| 2697 | break; |
| 2698 | case HPI_CONTROL_SAMPLECLOCK: |
| 2699 | err = snd_asihpi_sampleclock_add( |
| 2700 | asihpi, &hpi_ctl); |
| 2701 | break; |
| 2702 | case HPI_CONTROL_CONNECTION: /* ignore these */ |
| 2703 | continue; |
| 2704 | case HPI_CONTROL_TUNER: |
| 2705 | err = snd_asihpi_tuner_add(asihpi, &hpi_ctl); |
| 2706 | break; |
| 2707 | case HPI_CONTROL_AESEBU_TRANSMITTER: |
| 2708 | err = snd_asihpi_aesebu_tx_add(asihpi, &hpi_ctl); |
| 2709 | break; |
| 2710 | case HPI_CONTROL_AESEBU_RECEIVER: |
| 2711 | err = snd_asihpi_aesebu_rx_add(asihpi, &hpi_ctl); |
| 2712 | break; |
| 2713 | case HPI_CONTROL_VOX: |
| 2714 | case HPI_CONTROL_BITSTREAM: |
| 2715 | case HPI_CONTROL_MICROPHONE: |
| 2716 | case HPI_CONTROL_PARAMETRIC_EQ: |
| 2717 | case HPI_CONTROL_COMPANDER: |
| 2718 | default: |
| 2719 | if (mixer_dump) |
Eliot Blennerhassett | 12eb089 | 2014-11-20 16:22:55 +1300 | [diff] [blame] | 2720 | dev_info(&asihpi->pci->dev, |
| 2721 | "Untranslated HPI Control (%d) %d %d %d %d %d\n", |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 2722 | idx, |
| 2723 | hpi_ctl.control_type, |
| 2724 | hpi_ctl.src_node_type, |
| 2725 | hpi_ctl.src_node_index, |
| 2726 | hpi_ctl.dst_node_type, |
| 2727 | hpi_ctl.dst_node_index); |
| 2728 | continue; |
Peter Senna Tschudin | 395d9dd | 2012-09-28 11:24:57 +0200 | [diff] [blame] | 2729 | } |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 2730 | if (err < 0) |
| 2731 | return err; |
| 2732 | } |
| 2733 | if (HPI_ERROR_INVALID_OBJ_INDEX != err) |
| 2734 | hpi_handle_error(err); |
| 2735 | |
Eliot Blennerhassett | 12eb089 | 2014-11-20 16:22:55 +1300 | [diff] [blame] | 2736 | dev_info(&asihpi->pci->dev, "%d mixer controls found\n", idx); |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 2737 | |
| 2738 | return 0; |
| 2739 | } |
| 2740 | |
| 2741 | /*------------------------------------------------------------ |
| 2742 | /proc interface |
| 2743 | ------------------------------------------------------------*/ |
| 2744 | |
| 2745 | static void |
| 2746 | snd_asihpi_proc_read(struct snd_info_entry *entry, |
| 2747 | struct snd_info_buffer *buffer) |
| 2748 | { |
| 2749 | struct snd_card_asihpi *asihpi = entry->private_data; |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 2750 | u32 h_control; |
| 2751 | u32 rate = 0; |
| 2752 | u16 source = 0; |
Eliot Blennerhassett | 7036b92 | 2011-12-22 13:38:43 +1300 | [diff] [blame] | 2753 | |
| 2754 | u16 num_outstreams; |
| 2755 | u16 num_instreams; |
| 2756 | u16 version; |
| 2757 | u32 serial_number; |
| 2758 | u16 type; |
| 2759 | |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 2760 | int err; |
| 2761 | |
| 2762 | snd_iprintf(buffer, "ASIHPI driver proc file\n"); |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 2763 | |
Eliot Blennerhassett | 7036b92 | 2011-12-22 13:38:43 +1300 | [diff] [blame] | 2764 | hpi_handle_error(hpi_adapter_get_info(asihpi->hpi->adapter->index, |
| 2765 | &num_outstreams, &num_instreams, |
| 2766 | &version, &serial_number, &type)); |
| 2767 | |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 2768 | snd_iprintf(buffer, |
Eliot Blennerhassett | 7036b92 | 2011-12-22 13:38:43 +1300 | [diff] [blame] | 2769 | "Adapter type ASI%4X\nHardware Index %d\n" |
| 2770 | "%d outstreams\n%d instreams\n", |
| 2771 | type, asihpi->hpi->adapter->index, |
| 2772 | num_outstreams, num_instreams); |
| 2773 | |
| 2774 | snd_iprintf(buffer, |
| 2775 | "Serial#%d\nHardware version %c%d\nDSP code version %03d\n", |
| 2776 | serial_number, ((version >> 3) & 0xf) + 'A', version & 0x7, |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 2777 | ((version >> 13) * 100) + ((version >> 7) & 0x3f)); |
| 2778 | |
Eliot Blennerhassett | ba94455 | 2011-02-10 17:26:04 +1300 | [diff] [blame] | 2779 | err = hpi_mixer_get_control(asihpi->h_mixer, |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 2780 | HPI_SOURCENODE_CLOCK_SOURCE, 0, 0, 0, |
| 2781 | HPI_CONTROL_SAMPLECLOCK, &h_control); |
| 2782 | |
| 2783 | if (!err) { |
Eliot Blennerhassett | 7036b92 | 2011-12-22 13:38:43 +1300 | [diff] [blame] | 2784 | err = hpi_sample_clock_get_sample_rate(h_control, &rate); |
Eliot Blennerhassett | ba94455 | 2011-02-10 17:26:04 +1300 | [diff] [blame] | 2785 | err += hpi_sample_clock_get_source(h_control, &source); |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 2786 | |
| 2787 | if (!err) |
Eliot Blennerhassett | 7036b92 | 2011-12-22 13:38:43 +1300 | [diff] [blame] | 2788 | snd_iprintf(buffer, "Sample Clock %dHz, source %s\n", |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 2789 | rate, sampleclock_sources[source]); |
| 2790 | } |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 2791 | } |
| 2792 | |
Bill Pemberton | e23e7a1 | 2012-12-06 12:35:10 -0500 | [diff] [blame] | 2793 | static void snd_asihpi_proc_init(struct snd_card_asihpi *asihpi) |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 2794 | { |
| 2795 | struct snd_info_entry *entry; |
| 2796 | |
| 2797 | if (!snd_card_proc_new(asihpi->card, "info", &entry)) |
| 2798 | snd_info_set_text_ops(entry, asihpi, snd_asihpi_proc_read); |
| 2799 | } |
| 2800 | |
| 2801 | /*------------------------------------------------------------ |
| 2802 | HWDEP |
| 2803 | ------------------------------------------------------------*/ |
| 2804 | |
| 2805 | static int snd_asihpi_hpi_open(struct snd_hwdep *hw, struct file *file) |
| 2806 | { |
| 2807 | if (enable_hpi_hwdep) |
| 2808 | return 0; |
| 2809 | else |
| 2810 | return -ENODEV; |
| 2811 | |
| 2812 | } |
| 2813 | |
| 2814 | static int snd_asihpi_hpi_release(struct snd_hwdep *hw, struct file *file) |
| 2815 | { |
| 2816 | if (enable_hpi_hwdep) |
| 2817 | return asihpi_hpi_release(file); |
| 2818 | else |
| 2819 | return -ENODEV; |
| 2820 | } |
| 2821 | |
| 2822 | static int snd_asihpi_hpi_ioctl(struct snd_hwdep *hw, struct file *file, |
| 2823 | unsigned int cmd, unsigned long arg) |
| 2824 | { |
| 2825 | if (enable_hpi_hwdep) |
| 2826 | return asihpi_hpi_ioctl(file, cmd, arg); |
| 2827 | else |
| 2828 | return -ENODEV; |
| 2829 | } |
| 2830 | |
| 2831 | |
| 2832 | /* results in /dev/snd/hwC#D0 file for each card with index # |
| 2833 | also /proc/asound/hwdep will contain '#-00: asihpi (HPI) for each card' |
| 2834 | */ |
Lars-Peter Clausen | d18132a | 2015-01-02 12:24:45 +0100 | [diff] [blame^] | 2835 | static int snd_asihpi_hpi_new(struct snd_card_asihpi *asihpi, int device) |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 2836 | { |
| 2837 | struct snd_hwdep *hw; |
| 2838 | int err; |
| 2839 | |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 2840 | err = snd_hwdep_new(asihpi->card, "HPI", device, &hw); |
| 2841 | if (err < 0) |
| 2842 | return err; |
| 2843 | strcpy(hw->name, "asihpi (HPI)"); |
| 2844 | hw->iface = SNDRV_HWDEP_IFACE_LAST; |
| 2845 | hw->ops.open = snd_asihpi_hpi_open; |
| 2846 | hw->ops.ioctl = snd_asihpi_hpi_ioctl; |
| 2847 | hw->ops.release = snd_asihpi_hpi_release; |
| 2848 | hw->private_data = asihpi; |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 2849 | return 0; |
| 2850 | } |
| 2851 | |
| 2852 | /*------------------------------------------------------------ |
| 2853 | CARD |
| 2854 | ------------------------------------------------------------*/ |
Bill Pemberton | e23e7a1 | 2012-12-06 12:35:10 -0500 | [diff] [blame] | 2855 | static int snd_asihpi_probe(struct pci_dev *pci_dev, |
| 2856 | const struct pci_device_id *pci_id) |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 2857 | { |
| 2858 | int err; |
Eliot Blennerhassett | 7036b92 | 2011-12-22 13:38:43 +1300 | [diff] [blame] | 2859 | struct hpi_adapter *hpi; |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 2860 | struct snd_card *card; |
| 2861 | struct snd_card_asihpi *asihpi; |
| 2862 | |
| 2863 | u32 h_control; |
| 2864 | u32 h_stream; |
Eliot Blennerhassett | 7036b92 | 2011-12-22 13:38:43 +1300 | [diff] [blame] | 2865 | u32 adapter_index; |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 2866 | |
| 2867 | static int dev; |
| 2868 | if (dev >= SNDRV_CARDS) |
| 2869 | return -ENODEV; |
| 2870 | |
Eliot Blennerhassett | 7036b92 | 2011-12-22 13:38:43 +1300 | [diff] [blame] | 2871 | /* Should this be enable[hpi->index] ? */ |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 2872 | if (!enable[dev]) { |
| 2873 | dev++; |
| 2874 | return -ENOENT; |
| 2875 | } |
| 2876 | |
Eliot Blennerhassett | 7036b92 | 2011-12-22 13:38:43 +1300 | [diff] [blame] | 2877 | /* Initialise low-level HPI driver */ |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 2878 | err = asihpi_adapter_probe(pci_dev, pci_id); |
| 2879 | if (err < 0) |
| 2880 | return err; |
| 2881 | |
Eliot Blennerhassett | 7036b92 | 2011-12-22 13:38:43 +1300 | [diff] [blame] | 2882 | hpi = pci_get_drvdata(pci_dev); |
| 2883 | adapter_index = hpi->adapter->index; |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 2884 | /* first try to give the card the same index as its hardware index */ |
Takashi Iwai | 60c5772 | 2014-01-29 14:20:19 +0100 | [diff] [blame] | 2885 | err = snd_card_new(&pci_dev->dev, adapter_index, id[adapter_index], |
| 2886 | THIS_MODULE, sizeof(struct snd_card_asihpi), &card); |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 2887 | if (err < 0) { |
| 2888 | /* if that fails, try the default index==next available */ |
Takashi Iwai | 60c5772 | 2014-01-29 14:20:19 +0100 | [diff] [blame] | 2889 | err = snd_card_new(&pci_dev->dev, index[dev], id[dev], |
| 2890 | THIS_MODULE, sizeof(struct snd_card_asihpi), |
| 2891 | &card); |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 2892 | if (err < 0) |
| 2893 | return err; |
Eliot Blennerhassett | 12eb089 | 2014-11-20 16:22:55 +1300 | [diff] [blame] | 2894 | dev_warn(&pci_dev->dev, "Adapter index %d->ALSA index %d\n", |
Eliot Blennerhassett | 7036b92 | 2011-12-22 13:38:43 +1300 | [diff] [blame] | 2895 | adapter_index, card->number); |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 2896 | } |
| 2897 | |
Eliot Blennerhassett | 7036b92 | 2011-12-22 13:38:43 +1300 | [diff] [blame] | 2898 | asihpi = card->private_data; |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 2899 | asihpi->card = card; |
Eliot Blennerhassett | 1225367 | 2011-02-10 17:26:10 +1300 | [diff] [blame] | 2900 | asihpi->pci = pci_dev; |
Eliot Blennerhassett | 7036b92 | 2011-12-22 13:38:43 +1300 | [diff] [blame] | 2901 | asihpi->hpi = hpi; |
Eliot Blennerhassett | f9a376c | 2014-11-20 16:22:53 +1300 | [diff] [blame] | 2902 | hpi->snd_card = card; |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 2903 | |
Eliot Blennerhassett | 7036b92 | 2011-12-22 13:38:43 +1300 | [diff] [blame] | 2904 | err = hpi_adapter_get_property(adapter_index, |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 2905 | HPI_ADAPTER_PROPERTY_CAPS1, |
| 2906 | NULL, &asihpi->support_grouping); |
| 2907 | if (err) |
| 2908 | asihpi->support_grouping = 0; |
| 2909 | |
Eliot Blennerhassett | 7036b92 | 2011-12-22 13:38:43 +1300 | [diff] [blame] | 2910 | err = hpi_adapter_get_property(adapter_index, |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 2911 | HPI_ADAPTER_PROPERTY_CAPS2, |
| 2912 | &asihpi->support_mrx, NULL); |
| 2913 | if (err) |
| 2914 | asihpi->support_mrx = 0; |
| 2915 | |
Eliot Blennerhassett | 7036b92 | 2011-12-22 13:38:43 +1300 | [diff] [blame] | 2916 | err = hpi_adapter_get_property(adapter_index, |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 2917 | HPI_ADAPTER_PROPERTY_INTERVAL, |
| 2918 | NULL, &asihpi->update_interval_frames); |
| 2919 | if (err) |
| 2920 | asihpi->update_interval_frames = 512; |
| 2921 | |
Eliot Blennerhassett | f9a376c | 2014-11-20 16:22:53 +1300 | [diff] [blame] | 2922 | if (hpi->interrupt_mode) { |
| 2923 | asihpi->pcm_start = snd_card_asihpi_pcm_int_start; |
| 2924 | asihpi->pcm_stop = snd_card_asihpi_pcm_int_stop; |
| 2925 | tasklet_init(&asihpi->t, snd_card_asihpi_int_task, |
| 2926 | (unsigned long)hpi); |
| 2927 | hpi->interrupt_callback = snd_card_asihpi_isr; |
| 2928 | } else { |
| 2929 | asihpi->pcm_start = snd_card_asihpi_pcm_timer_start; |
| 2930 | asihpi->pcm_stop = snd_card_asihpi_pcm_timer_stop; |
| 2931 | } |
Eliot Blennerhassett | 26aebef | 2011-03-25 15:25:47 +1300 | [diff] [blame] | 2932 | |
Eliot Blennerhassett | 7036b92 | 2011-12-22 13:38:43 +1300 | [diff] [blame] | 2933 | hpi_handle_error(hpi_instream_open(adapter_index, |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 2934 | 0, &h_stream)); |
| 2935 | |
Eliot Blennerhassett | ba94455 | 2011-02-10 17:26:04 +1300 | [diff] [blame] | 2936 | err = hpi_instream_host_buffer_free(h_stream); |
Eliot Blennerhassett | f3d145a | 2011-04-05 20:55:44 +1200 | [diff] [blame] | 2937 | asihpi->can_dma = (!err); |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 2938 | |
Eliot Blennerhassett | ba94455 | 2011-02-10 17:26:04 +1300 | [diff] [blame] | 2939 | hpi_handle_error(hpi_instream_close(h_stream)); |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 2940 | |
Eliot Blennerhassett | f9a376c | 2014-11-20 16:22:53 +1300 | [diff] [blame] | 2941 | if (!asihpi->can_dma) |
| 2942 | asihpi->update_interval_frames *= 2; |
| 2943 | |
Eliot Blennerhassett | 7036b92 | 2011-12-22 13:38:43 +1300 | [diff] [blame] | 2944 | err = hpi_adapter_get_property(adapter_index, |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 2945 | HPI_ADAPTER_PROPERTY_CURCHANNELS, |
| 2946 | &asihpi->in_max_chans, &asihpi->out_max_chans); |
| 2947 | if (err) { |
| 2948 | asihpi->in_max_chans = 2; |
| 2949 | asihpi->out_max_chans = 2; |
| 2950 | } |
| 2951 | |
Eliot Blennerhassett | c382a5d | 2011-12-22 13:38:33 +1300 | [diff] [blame] | 2952 | if (asihpi->out_max_chans > 2) { /* assume LL mode */ |
| 2953 | asihpi->out_min_chans = asihpi->out_max_chans; |
| 2954 | asihpi->in_min_chans = asihpi->in_max_chans; |
| 2955 | asihpi->support_grouping = 0; |
| 2956 | } else { |
| 2957 | asihpi->out_min_chans = 1; |
| 2958 | asihpi->in_min_chans = 1; |
| 2959 | } |
| 2960 | |
Eliot Blennerhassett | 12eb089 | 2014-11-20 16:22:55 +1300 | [diff] [blame] | 2961 | dev_info(&pci_dev->dev, "Has dma:%d, grouping:%d, mrx:%d, uif:%d\n", |
Eliot Blennerhassett | f3d145a | 2011-04-05 20:55:44 +1200 | [diff] [blame] | 2962 | asihpi->can_dma, |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 2963 | asihpi->support_grouping, |
Eliot Blennerhassett | 12eb089 | 2014-11-20 16:22:55 +1300 | [diff] [blame] | 2964 | asihpi->support_mrx, |
| 2965 | asihpi->update_interval_frames |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 2966 | ); |
| 2967 | |
Eliot Blennerhassett | 7036b92 | 2011-12-22 13:38:43 +1300 | [diff] [blame] | 2968 | err = snd_card_asihpi_pcm_new(asihpi, 0); |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 2969 | if (err < 0) { |
Eliot Blennerhassett | 12eb089 | 2014-11-20 16:22:55 +1300 | [diff] [blame] | 2970 | dev_err(&pci_dev->dev, "pcm_new failed\n"); |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 2971 | goto __nodev; |
| 2972 | } |
| 2973 | err = snd_card_asihpi_mixer_new(asihpi); |
| 2974 | if (err < 0) { |
Eliot Blennerhassett | 12eb089 | 2014-11-20 16:22:55 +1300 | [diff] [blame] | 2975 | dev_err(&pci_dev->dev, "mixer_new failed\n"); |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 2976 | goto __nodev; |
| 2977 | } |
| 2978 | |
Eliot Blennerhassett | ba94455 | 2011-02-10 17:26:04 +1300 | [diff] [blame] | 2979 | err = hpi_mixer_get_control(asihpi->h_mixer, |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 2980 | HPI_SOURCENODE_CLOCK_SOURCE, 0, 0, 0, |
| 2981 | HPI_CONTROL_SAMPLECLOCK, &h_control); |
| 2982 | |
| 2983 | if (!err) |
| 2984 | err = hpi_sample_clock_set_local_rate( |
Eliot Blennerhassett | ba94455 | 2011-02-10 17:26:04 +1300 | [diff] [blame] | 2985 | h_control, adapter_fs); |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 2986 | |
| 2987 | snd_asihpi_proc_init(asihpi); |
| 2988 | |
| 2989 | /* always create, can be enabled or disabled dynamically |
| 2990 | by enable_hwdep module param*/ |
Lars-Peter Clausen | d18132a | 2015-01-02 12:24:45 +0100 | [diff] [blame^] | 2991 | snd_asihpi_hpi_new(asihpi, 0); |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 2992 | |
Eliot Blennerhassett | f3d145a | 2011-04-05 20:55:44 +1200 | [diff] [blame] | 2993 | strcpy(card->driver, "ASIHPI"); |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 2994 | |
Eliot Blennerhassett | 7036b92 | 2011-12-22 13:38:43 +1300 | [diff] [blame] | 2995 | sprintf(card->shortname, "AudioScience ASI%4X", |
| 2996 | asihpi->hpi->adapter->type); |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 2997 | sprintf(card->longname, "%s %i", |
Eliot Blennerhassett | 7036b92 | 2011-12-22 13:38:43 +1300 | [diff] [blame] | 2998 | card->shortname, adapter_index); |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 2999 | err = snd_card_register(card); |
Eliot Blennerhassett | b2e65c8 | 2011-03-25 15:25:48 +1300 | [diff] [blame] | 3000 | |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 3001 | if (!err) { |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 3002 | dev++; |
| 3003 | return 0; |
| 3004 | } |
| 3005 | __nodev: |
| 3006 | snd_card_free(card); |
Eliot Blennerhassett | 12eb089 | 2014-11-20 16:22:55 +1300 | [diff] [blame] | 3007 | dev_err(&pci_dev->dev, "snd_asihpi_probe error %d\n", err); |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 3008 | return err; |
| 3009 | |
| 3010 | } |
| 3011 | |
Bill Pemberton | e23e7a1 | 2012-12-06 12:35:10 -0500 | [diff] [blame] | 3012 | static void snd_asihpi_remove(struct pci_dev *pci_dev) |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 3013 | { |
Eliot Blennerhassett | 7036b92 | 2011-12-22 13:38:43 +1300 | [diff] [blame] | 3014 | struct hpi_adapter *hpi = pci_get_drvdata(pci_dev); |
Eliot Blennerhassett | f9a376c | 2014-11-20 16:22:53 +1300 | [diff] [blame] | 3015 | struct snd_card_asihpi *asihpi = hpi->snd_card->private_data; |
| 3016 | |
| 3017 | /* Stop interrupts */ |
| 3018 | if (hpi->interrupt_mode) { |
| 3019 | hpi->interrupt_callback = NULL; |
| 3020 | hpi_handle_error(hpi_adapter_set_property(hpi->adapter->index, |
| 3021 | HPI_ADAPTER_PROPERTY_IRQ_RATE, 0, 0)); |
| 3022 | tasklet_kill(&asihpi->t); |
| 3023 | } |
| 3024 | |
Eliot Blennerhassett | 7036b92 | 2011-12-22 13:38:43 +1300 | [diff] [blame] | 3025 | snd_card_free(hpi->snd_card); |
| 3026 | hpi->snd_card = NULL; |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 3027 | asihpi_adapter_remove(pci_dev); |
| 3028 | } |
| 3029 | |
Benoit Taine | 9baa3c3 | 2014-08-08 15:56:03 +0200 | [diff] [blame] | 3030 | static const struct pci_device_id asihpi_pci_tbl[] = { |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 3031 | {HPI_PCI_VENDOR_ID_TI, HPI_PCI_DEV_ID_DSP6205, |
| 3032 | HPI_PCI_VENDOR_ID_AUDIOSCIENCE, PCI_ANY_ID, 0, 0, |
| 3033 | (kernel_ulong_t)HPI_6205}, |
| 3034 | {HPI_PCI_VENDOR_ID_TI, HPI_PCI_DEV_ID_PCI2040, |
| 3035 | HPI_PCI_VENDOR_ID_AUDIOSCIENCE, PCI_ANY_ID, 0, 0, |
| 3036 | (kernel_ulong_t)HPI_6000}, |
| 3037 | {0,} |
| 3038 | }; |
| 3039 | MODULE_DEVICE_TABLE(pci, asihpi_pci_tbl); |
| 3040 | |
| 3041 | static struct pci_driver driver = { |
Takashi Iwai | 3733e42 | 2011-06-10 16:20:20 +0200 | [diff] [blame] | 3042 | .name = KBUILD_MODNAME, |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 3043 | .id_table = asihpi_pci_tbl, |
| 3044 | .probe = snd_asihpi_probe, |
Bill Pemberton | e23e7a1 | 2012-12-06 12:35:10 -0500 | [diff] [blame] | 3045 | .remove = snd_asihpi_remove, |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 3046 | }; |
| 3047 | |
| 3048 | static int __init snd_asihpi_init(void) |
| 3049 | { |
| 3050 | asihpi_init(); |
| 3051 | return pci_register_driver(&driver); |
| 3052 | } |
| 3053 | |
| 3054 | static void __exit snd_asihpi_exit(void) |
| 3055 | { |
| 3056 | |
| 3057 | pci_unregister_driver(&driver); |
| 3058 | asihpi_exit(); |
| 3059 | } |
| 3060 | |
| 3061 | module_init(snd_asihpi_init) |
| 3062 | module_exit(snd_asihpi_exit) |
| 3063 | |