Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-only */
0002 /*
0003  * bebob.h - a part of driver for BeBoB based devices
0004  *
0005  * Copyright (c) 2013-2014 Takashi Sakamoto
0006  */
0007 
0008 #ifndef SOUND_BEBOB_H_INCLUDED
0009 #define SOUND_BEBOB_H_INCLUDED
0010 
0011 #include <linux/compat.h>
0012 #include <linux/device.h>
0013 #include <linux/firewire.h>
0014 #include <linux/firewire-constants.h>
0015 #include <linux/module.h>
0016 #include <linux/mod_devicetable.h>
0017 #include <linux/delay.h>
0018 #include <linux/slab.h>
0019 #include <linux/sched/signal.h>
0020 
0021 #include <sound/core.h>
0022 #include <sound/initval.h>
0023 #include <sound/info.h>
0024 #include <sound/rawmidi.h>
0025 #include <sound/pcm.h>
0026 #include <sound/pcm_params.h>
0027 #include <sound/firewire.h>
0028 #include <sound/hwdep.h>
0029 
0030 #include "../lib.h"
0031 #include "../fcp.h"
0032 #include "../packets-buffer.h"
0033 #include "../iso-resources.h"
0034 #include "../amdtp-am824.h"
0035 #include "../cmp.h"
0036 
0037 /* basic register addresses on DM1000/DM1100/DM1500 */
0038 #define BEBOB_ADDR_REG_INFO 0xffffc8020000ULL
0039 #define BEBOB_ADDR_REG_REQ  0xffffc8021000ULL
0040 
0041 struct snd_bebob;
0042 
0043 #define SND_BEBOB_STRM_FMT_ENTRIES  7
0044 struct snd_bebob_stream_formation {
0045     unsigned int pcm;
0046     unsigned int midi;
0047 };
0048 /* this is a lookup table for index of stream formations */
0049 extern const unsigned int snd_bebob_rate_table[SND_BEBOB_STRM_FMT_ENTRIES];
0050 
0051 /* device specific operations */
0052 enum snd_bebob_clock_type {
0053     SND_BEBOB_CLOCK_TYPE_INTERNAL = 0,
0054     SND_BEBOB_CLOCK_TYPE_EXTERNAL,
0055     SND_BEBOB_CLOCK_TYPE_SYT,
0056 };
0057 struct snd_bebob_clock_spec {
0058     unsigned int num;
0059     const char *const *labels;
0060     const enum snd_bebob_clock_type *types;
0061     int (*get)(struct snd_bebob *bebob, unsigned int *id);
0062 };
0063 struct snd_bebob_rate_spec {
0064     int (*get)(struct snd_bebob *bebob, unsigned int *rate);
0065     int (*set)(struct snd_bebob *bebob, unsigned int rate);
0066 };
0067 struct snd_bebob_meter_spec {
0068     unsigned int num;
0069     const char *const *labels;
0070     int (*get)(struct snd_bebob *bebob, u32 *target, unsigned int size);
0071 };
0072 struct snd_bebob_spec {
0073     const struct snd_bebob_clock_spec *clock;
0074     const struct snd_bebob_rate_spec *rate;
0075     const struct snd_bebob_meter_spec *meter;
0076 };
0077 
0078 enum snd_bebob_quirk {
0079     SND_BEBOB_QUIRK_INITIAL_DISCONTINUOUS_DBC = (1 << 0),
0080     SND_BEBOB_QUIRK_WRONG_DBC         = (1 << 1),
0081 };
0082 
0083 struct snd_bebob {
0084     struct snd_card *card;
0085     struct fw_unit *unit;
0086     int card_index;
0087 
0088     struct mutex mutex;
0089     spinlock_t lock;
0090 
0091     const struct snd_bebob_spec *spec;
0092     unsigned int quirks;    // Combination of snd_bebob_quirk enumerations.
0093 
0094     unsigned int midi_input_ports;
0095     unsigned int midi_output_ports;
0096 
0097     struct amdtp_stream tx_stream;
0098     struct amdtp_stream rx_stream;
0099     struct cmp_connection out_conn;
0100     struct cmp_connection in_conn;
0101     unsigned int substreams_counter;
0102 
0103     struct snd_bebob_stream_formation
0104         tx_stream_formations[SND_BEBOB_STRM_FMT_ENTRIES];
0105     struct snd_bebob_stream_formation
0106         rx_stream_formations[SND_BEBOB_STRM_FMT_ENTRIES];
0107 
0108     int sync_input_plug;
0109 
0110     /* for uapi */
0111     int dev_lock_count;
0112     bool dev_lock_changed;
0113     wait_queue_head_t hwdep_wait;
0114 
0115     /* for M-Audio special devices */
0116     void *maudio_special_quirk;
0117 
0118     struct amdtp_domain domain;
0119 };
0120 
0121 static inline int
0122 snd_bebob_read_block(struct fw_unit *unit, u64 addr, void *buf, int size)
0123 {
0124     return snd_fw_transaction(unit, TCODE_READ_BLOCK_REQUEST,
0125                   BEBOB_ADDR_REG_INFO + addr,
0126                   buf, size, 0);
0127 }
0128 
0129 static inline int
0130 snd_bebob_read_quad(struct fw_unit *unit, u64 addr, u32 *buf)
0131 {
0132     return snd_fw_transaction(unit, TCODE_READ_QUADLET_REQUEST,
0133                   BEBOB_ADDR_REG_INFO + addr,
0134                   (void *)buf, sizeof(u32), 0);
0135 }
0136 
0137 /* AV/C Audio Subunit Specification 1.0 (Oct 2000, 1394TA) */
0138 int avc_audio_set_selector(struct fw_unit *unit, unsigned int subunit_id,
0139                unsigned int fb_id, unsigned int num);
0140 int avc_audio_get_selector(struct fw_unit *unit, unsigned  int subunit_id,
0141                unsigned int fb_id, unsigned int *num);
0142 
0143 /*
0144  * AVC command extensions, AV/C Unit and Subunit, Revision 17
0145  * (Nov 2003, BridgeCo)
0146  */
0147 #define AVC_BRIDGECO_ADDR_BYTES 6
0148 enum avc_bridgeco_plug_dir {
0149     AVC_BRIDGECO_PLUG_DIR_IN    = 0x00,
0150     AVC_BRIDGECO_PLUG_DIR_OUT   = 0x01
0151 };
0152 enum avc_bridgeco_plug_mode {
0153     AVC_BRIDGECO_PLUG_MODE_UNIT     = 0x00,
0154     AVC_BRIDGECO_PLUG_MODE_SUBUNIT      = 0x01,
0155     AVC_BRIDGECO_PLUG_MODE_FUNCTION_BLOCK   = 0x02
0156 };
0157 enum avc_bridgeco_plug_unit {
0158     AVC_BRIDGECO_PLUG_UNIT_ISOC = 0x00,
0159     AVC_BRIDGECO_PLUG_UNIT_EXT  = 0x01,
0160     AVC_BRIDGECO_PLUG_UNIT_ASYNC    = 0x02
0161 };
0162 enum avc_bridgeco_plug_type {
0163     AVC_BRIDGECO_PLUG_TYPE_ISOC = 0x00,
0164     AVC_BRIDGECO_PLUG_TYPE_ASYNC    = 0x01,
0165     AVC_BRIDGECO_PLUG_TYPE_MIDI = 0x02,
0166     AVC_BRIDGECO_PLUG_TYPE_SYNC = 0x03,
0167     AVC_BRIDGECO_PLUG_TYPE_ANA  = 0x04,
0168     AVC_BRIDGECO_PLUG_TYPE_DIG  = 0x05,
0169     AVC_BRIDGECO_PLUG_TYPE_ADDITION = 0x06
0170 };
0171 static inline void
0172 avc_bridgeco_fill_unit_addr(u8 buf[AVC_BRIDGECO_ADDR_BYTES],
0173                 enum avc_bridgeco_plug_dir dir,
0174                 enum avc_bridgeco_plug_unit unit,
0175                 unsigned int pid)
0176 {
0177     buf[0] = 0xff;  /* Unit */
0178     buf[1] = dir;
0179     buf[2] = AVC_BRIDGECO_PLUG_MODE_UNIT;
0180     buf[3] = unit;
0181     buf[4] = 0xff & pid;
0182     buf[5] = 0xff;  /* reserved */
0183 }
0184 static inline void
0185 avc_bridgeco_fill_msu_addr(u8 buf[AVC_BRIDGECO_ADDR_BYTES],
0186                enum avc_bridgeco_plug_dir dir,
0187                unsigned int pid)
0188 {
0189     buf[0] = 0x60;  /* Music subunit */
0190     buf[1] = dir;
0191     buf[2] = AVC_BRIDGECO_PLUG_MODE_SUBUNIT;
0192     buf[3] = 0xff & pid;
0193     buf[4] = 0xff;  /* reserved */
0194     buf[5] = 0xff;  /* reserved */
0195 }
0196 int avc_bridgeco_get_plug_ch_pos(struct fw_unit *unit,
0197                  u8 addr[AVC_BRIDGECO_ADDR_BYTES],
0198                  u8 *buf, unsigned int len);
0199 int avc_bridgeco_get_plug_type(struct fw_unit *unit,
0200                    u8 addr[AVC_BRIDGECO_ADDR_BYTES],
0201                    enum avc_bridgeco_plug_type *type);
0202 int avc_bridgeco_get_plug_ch_count(struct fw_unit *unit, u8 addr[AVC_BRIDGECO_ADDR_BYTES],
0203                    unsigned int *ch_count);
0204 int avc_bridgeco_get_plug_section_type(struct fw_unit *unit,
0205                        u8 addr[AVC_BRIDGECO_ADDR_BYTES],
0206                        unsigned int id, u8 *type);
0207 int avc_bridgeco_get_plug_input(struct fw_unit *unit,
0208                 u8 addr[AVC_BRIDGECO_ADDR_BYTES],
0209                 u8 input[7]);
0210 int avc_bridgeco_get_plug_strm_fmt(struct fw_unit *unit,
0211                    u8 addr[AVC_BRIDGECO_ADDR_BYTES], u8 *buf,
0212                    unsigned int *len, unsigned int eid);
0213 
0214 /* for AMDTP streaming */
0215 int snd_bebob_stream_get_rate(struct snd_bebob *bebob, unsigned int *rate);
0216 int snd_bebob_stream_set_rate(struct snd_bebob *bebob, unsigned int rate);
0217 int snd_bebob_stream_get_clock_src(struct snd_bebob *bebob,
0218                    enum snd_bebob_clock_type *src);
0219 int snd_bebob_stream_discover(struct snd_bebob *bebob);
0220 int snd_bebob_stream_init_duplex(struct snd_bebob *bebob);
0221 int snd_bebob_stream_reserve_duplex(struct snd_bebob *bebob, unsigned int rate,
0222                     unsigned int frames_per_period,
0223                     unsigned int frames_per_buffer);
0224 int snd_bebob_stream_start_duplex(struct snd_bebob *bebob);
0225 void snd_bebob_stream_stop_duplex(struct snd_bebob *bebob);
0226 void snd_bebob_stream_destroy_duplex(struct snd_bebob *bebob);
0227 
0228 void snd_bebob_stream_lock_changed(struct snd_bebob *bebob);
0229 int snd_bebob_stream_lock_try(struct snd_bebob *bebob);
0230 void snd_bebob_stream_lock_release(struct snd_bebob *bebob);
0231 
0232 void snd_bebob_proc_init(struct snd_bebob *bebob);
0233 
0234 int snd_bebob_create_midi_devices(struct snd_bebob *bebob);
0235 
0236 int snd_bebob_create_pcm_devices(struct snd_bebob *bebob);
0237 
0238 int snd_bebob_create_hwdep_device(struct snd_bebob *bebob);
0239 
0240 /* model specific operations */
0241 extern const struct snd_bebob_spec phase88_rack_spec;
0242 extern const struct snd_bebob_spec yamaha_terratec_spec;
0243 extern const struct snd_bebob_spec saffirepro_26_spec;
0244 extern const struct snd_bebob_spec saffirepro_10_spec;
0245 extern const struct snd_bebob_spec saffire_le_spec;
0246 extern const struct snd_bebob_spec saffire_spec;
0247 extern const struct snd_bebob_spec maudio_fw410_spec;
0248 extern const struct snd_bebob_spec maudio_audiophile_spec;
0249 extern const struct snd_bebob_spec maudio_solo_spec;
0250 extern const struct snd_bebob_spec maudio_ozonic_spec;
0251 extern const struct snd_bebob_spec maudio_nrv10_spec;
0252 extern const struct snd_bebob_spec maudio_special_spec;
0253 int snd_bebob_maudio_special_discover(struct snd_bebob *bebob, bool is1814);
0254 int snd_bebob_maudio_load_firmware(struct fw_unit *unit);
0255 
0256 #endif