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