Takashi Sakamoto | 7c2d4c0c | 2014-11-29 00:59:13 +0900 | [diff] [blame] | 1 | /* |
| 2 | * dice.h - a part of driver for Dice based devices |
| 3 | * |
| 4 | * Copyright (c) Clemens Ladisch |
| 5 | * Copyright (c) 2014 Takashi Sakamoto |
| 6 | * |
| 7 | * Licensed under the terms of the GNU General Public License, version 2. |
| 8 | */ |
| 9 | |
| 10 | #ifndef SOUND_DICE_H_INCLUDED |
| 11 | #define SOUND_DICE_H_INCLUDED |
| 12 | |
| 13 | #include <linux/compat.h> |
| 14 | #include <linux/completion.h> |
| 15 | #include <linux/delay.h> |
| 16 | #include <linux/device.h> |
| 17 | #include <linux/firewire.h> |
| 18 | #include <linux/firewire-constants.h> |
| 19 | #include <linux/jiffies.h> |
| 20 | #include <linux/module.h> |
| 21 | #include <linux/mod_devicetable.h> |
| 22 | #include <linux/mutex.h> |
| 23 | #include <linux/slab.h> |
| 24 | #include <linux/spinlock.h> |
| 25 | #include <linux/wait.h> |
| 26 | |
| 27 | #include <sound/control.h> |
| 28 | #include <sound/core.h> |
| 29 | #include <sound/firewire.h> |
| 30 | #include <sound/hwdep.h> |
| 31 | #include <sound/info.h> |
| 32 | #include <sound/initval.h> |
| 33 | #include <sound/pcm.h> |
| 34 | #include <sound/pcm_params.h> |
| 35 | |
| 36 | #include "../amdtp.h" |
| 37 | #include "../iso-resources.h" |
| 38 | #include "../lib.h" |
| 39 | #include "dice-interface.h" |
| 40 | |
| 41 | struct snd_dice { |
| 42 | struct snd_card *card; |
| 43 | struct fw_unit *unit; |
| 44 | spinlock_t lock; |
| 45 | struct mutex mutex; |
| 46 | |
| 47 | /* Offsets for sub-addresses */ |
| 48 | unsigned int global_offset; |
| 49 | unsigned int rx_offset; |
| 50 | unsigned int tx_offset; |
| 51 | unsigned int sync_offset; |
| 52 | unsigned int rsrv_offset; |
| 53 | |
| 54 | unsigned int clock_caps; |
| 55 | unsigned int rx_channels[3]; |
| 56 | unsigned int rx_midi_ports[3]; |
| 57 | struct fw_address_handler notification_handler; |
| 58 | int owner_generation; |
| 59 | int dev_lock_count; /* > 0 driver, < 0 userspace */ |
| 60 | bool dev_lock_changed; |
| 61 | bool global_enabled; |
| 62 | struct completion clock_accepted; |
| 63 | wait_queue_head_t hwdep_wait; |
| 64 | u32 notification_bits; |
| 65 | struct fw_iso_resources rx_resources; |
| 66 | struct amdtp_stream rx_stream; |
| 67 | }; |
| 68 | |
| 69 | enum snd_dice_addr_type { |
| 70 | SND_DICE_ADDR_TYPE_PRIVATE, |
| 71 | SND_DICE_ADDR_TYPE_GLOBAL, |
| 72 | SND_DICE_ADDR_TYPE_TX, |
| 73 | SND_DICE_ADDR_TYPE_RX, |
| 74 | SND_DICE_ADDR_TYPE_SYNC, |
| 75 | SND_DICE_ADDR_TYPE_RSRV, |
| 76 | }; |
| 77 | |
| 78 | int snd_dice_transaction_write(struct snd_dice *dice, |
| 79 | enum snd_dice_addr_type type, |
| 80 | unsigned int offset, |
| 81 | void *buf, unsigned int len); |
| 82 | int snd_dice_transaction_read(struct snd_dice *dice, |
| 83 | enum snd_dice_addr_type type, unsigned int offset, |
| 84 | void *buf, unsigned int len); |
| 85 | |
| 86 | static inline int snd_dice_transaction_write_global(struct snd_dice *dice, |
| 87 | unsigned int offset, |
| 88 | void *buf, unsigned int len) |
| 89 | { |
| 90 | return snd_dice_transaction_write(dice, |
| 91 | SND_DICE_ADDR_TYPE_GLOBAL, offset, |
| 92 | buf, len); |
| 93 | } |
| 94 | static inline int snd_dice_transaction_read_global(struct snd_dice *dice, |
| 95 | unsigned int offset, |
| 96 | void *buf, unsigned int len) |
| 97 | { |
| 98 | return snd_dice_transaction_read(dice, |
| 99 | SND_DICE_ADDR_TYPE_GLOBAL, offset, |
| 100 | buf, len); |
| 101 | } |
| 102 | static inline int snd_dice_transaction_write_tx(struct snd_dice *dice, |
| 103 | unsigned int offset, |
| 104 | void *buf, unsigned int len) |
| 105 | { |
| 106 | return snd_dice_transaction_write(dice, SND_DICE_ADDR_TYPE_TX, offset, |
| 107 | buf, len); |
| 108 | } |
| 109 | static inline int snd_dice_transaction_read_tx(struct snd_dice *dice, |
| 110 | unsigned int offset, |
| 111 | void *buf, unsigned int len) |
| 112 | { |
| 113 | return snd_dice_transaction_read(dice, SND_DICE_ADDR_TYPE_TX, offset, |
| 114 | buf, len); |
| 115 | } |
| 116 | static inline int snd_dice_transaction_write_rx(struct snd_dice *dice, |
| 117 | unsigned int offset, |
| 118 | void *buf, unsigned int len) |
| 119 | { |
| 120 | return snd_dice_transaction_write(dice, SND_DICE_ADDR_TYPE_RX, offset, |
| 121 | buf, len); |
| 122 | } |
| 123 | static inline int snd_dice_transaction_read_rx(struct snd_dice *dice, |
| 124 | unsigned int offset, |
| 125 | void *buf, unsigned int len) |
| 126 | { |
| 127 | return snd_dice_transaction_read(dice, SND_DICE_ADDR_TYPE_RX, offset, |
| 128 | buf, len); |
| 129 | } |
| 130 | static inline int snd_dice_transaction_write_sync(struct snd_dice *dice, |
| 131 | unsigned int offset, |
| 132 | void *buf, unsigned int len) |
| 133 | { |
| 134 | return snd_dice_transaction_write(dice, SND_DICE_ADDR_TYPE_SYNC, offset, |
| 135 | buf, len); |
| 136 | } |
| 137 | static inline int snd_dice_transaction_read_sync(struct snd_dice *dice, |
| 138 | unsigned int offset, |
| 139 | void *buf, unsigned int len) |
| 140 | { |
| 141 | return snd_dice_transaction_read(dice, SND_DICE_ADDR_TYPE_SYNC, offset, |
| 142 | buf, len); |
| 143 | } |
| 144 | |
| 145 | int snd_dice_transaction_set_clock_source(struct snd_dice *dice, |
| 146 | unsigned int source); |
| 147 | int snd_dice_transaction_get_clock_source(struct snd_dice *dice, |
| 148 | unsigned int *source); |
| 149 | int snd_dice_transaction_set_rate(struct snd_dice *dice, unsigned int rate); |
| 150 | int snd_dice_transaction_get_rate(struct snd_dice *dice, unsigned int *rate); |
| 151 | int snd_dice_transaction_set_enable(struct snd_dice *dice); |
| 152 | void snd_dice_transaction_clear_enable(struct snd_dice *dice); |
| 153 | int snd_dice_transaction_init(struct snd_dice *dice); |
| 154 | int snd_dice_transaction_reinit(struct snd_dice *dice); |
| 155 | void snd_dice_transaction_destroy(struct snd_dice *dice); |
| 156 | |
| 157 | #define SND_DICE_RATES_COUNT 7 |
| 158 | extern const unsigned int snd_dice_rates[SND_DICE_RATES_COUNT]; |
| 159 | |
Takashi Sakamoto | 6eb6c81 | 2014-11-29 00:59:14 +0900 | [diff] [blame] | 160 | int snd_dice_stream_get_rate_mode(struct snd_dice *dice, |
| 161 | unsigned int rate, unsigned int *mode); |
| 162 | |
| 163 | int snd_dice_stream_start_packets(struct snd_dice *dice); |
| 164 | int snd_dice_stream_start(struct snd_dice *dice); |
| 165 | void snd_dice_stream_stop_packets(struct snd_dice *dice); |
| 166 | void snd_dice_stream_stop(struct snd_dice *dice); |
| 167 | int snd_dice_stream_init(struct snd_dice *dice); |
| 168 | void snd_dice_stream_destroy(struct snd_dice *dice); |
| 169 | void snd_dice_stream_update(struct snd_dice *dice); |
| 170 | |
| 171 | int snd_dice_stream_lock_try(struct snd_dice *dice); |
| 172 | void snd_dice_stream_lock_release(struct snd_dice *dice); |
| 173 | |
Takashi Sakamoto | c50fb91 | 2014-11-29 00:59:15 +0900 | [diff] [blame] | 174 | int snd_dice_create_pcm(struct snd_dice *dice); |
| 175 | |
Takashi Sakamoto | 19af57b | 2014-11-29 00:59:16 +0900 | [diff] [blame^] | 176 | int snd_dice_create_hwdep(struct snd_dice *dice); |
| 177 | |
Takashi Sakamoto | 7c2d4c0c | 2014-11-29 00:59:13 +0900 | [diff] [blame] | 178 | #endif |