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