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