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