mirror of
https://github.com/tbsdtv/linux_media.git
synced 2025-07-23 12:43:29 +02:00
Merge branch 'topic/midi20' into for-next
Pull one more API update for UMP core. Signed-off-by: Takashi Iwai <tiwai@suse.de>
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
#ifndef __UMP_CONVERT_H
|
#ifndef __SOUND_UMP_CONVERT_H
|
||||||
#define __UMP_CONVERT_H
|
#define __SOUND_UMP_CONVERT_H
|
||||||
|
|
||||||
#include <sound/ump_msg.h>
|
#include <sound/ump_msg.h>
|
||||||
|
|
||||||
@@ -31,13 +31,16 @@ struct ump_cvt_to_ump {
|
|||||||
struct ump_cvt_to_ump_bank bank[16]; /* per channel */
|
struct ump_cvt_to_ump_bank bank[16]; /* per channel */
|
||||||
};
|
};
|
||||||
|
|
||||||
int snd_ump_convert_init(struct snd_ump_endpoint *ump);
|
int snd_ump_convert_from_ump(const u32 *data, unsigned char *dst,
|
||||||
void snd_ump_convert_free(struct snd_ump_endpoint *ump);
|
|
||||||
int snd_ump_convert_from_ump(struct snd_ump_endpoint *ump,
|
|
||||||
const u32 *data, unsigned char *dst,
|
|
||||||
unsigned char *group_ret);
|
unsigned char *group_ret);
|
||||||
void snd_ump_convert_to_ump(struct snd_ump_endpoint *ump,
|
void snd_ump_convert_to_ump(struct ump_cvt_to_ump *cvt, unsigned char group,
|
||||||
unsigned char group, unsigned char c);
|
unsigned int protocol, unsigned char c);
|
||||||
void snd_ump_reset_convert_to_ump(struct snd_ump_endpoint *ump,
|
|
||||||
unsigned char group);
|
/* reset the converter context, called at each open to ump */
|
||||||
#endif /* __UMP_CONVERT_H */
|
static inline void snd_ump_convert_reset(struct ump_cvt_to_ump *ctx)
|
||||||
|
{
|
||||||
|
memset(ctx, 0, sizeof(*ctx));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* __SOUND_UMP_CONVERT_H */
|
@@ -11,7 +11,7 @@
|
|||||||
#include <sound/core.h>
|
#include <sound/core.h>
|
||||||
#include <sound/rawmidi.h>
|
#include <sound/rawmidi.h>
|
||||||
#include <sound/ump.h>
|
#include <sound/ump.h>
|
||||||
#include "ump_convert.h"
|
#include <sound/ump_convert.h>
|
||||||
|
|
||||||
#define ump_err(ump, fmt, args...) dev_err(&(ump)->core.dev, fmt, ##args)
|
#define ump_err(ump, fmt, args...) dev_err(&(ump)->core.dev, fmt, ##args)
|
||||||
#define ump_warn(ump, fmt, args...) dev_warn(&(ump)->core.dev, fmt, ##args)
|
#define ump_warn(ump, fmt, args...) dev_warn(&(ump)->core.dev, fmt, ##args)
|
||||||
@@ -87,7 +87,7 @@ static void snd_ump_endpoint_free(struct snd_rawmidi *rmidi)
|
|||||||
ump->private_free(ump);
|
ump->private_free(ump);
|
||||||
|
|
||||||
#if IS_ENABLED(CONFIG_SND_UMP_LEGACY_RAWMIDI)
|
#if IS_ENABLED(CONFIG_SND_UMP_LEGACY_RAWMIDI)
|
||||||
snd_ump_convert_free(ump);
|
kfree(ump->out_cvts);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1002,7 +1002,7 @@ static int snd_ump_legacy_open(struct snd_rawmidi_substream *substream)
|
|||||||
goto unlock;
|
goto unlock;
|
||||||
}
|
}
|
||||||
ump->legacy_out_opens++;
|
ump->legacy_out_opens++;
|
||||||
snd_ump_reset_convert_to_ump(ump, group);
|
snd_ump_convert_reset(&ump->out_cvts[group]);
|
||||||
}
|
}
|
||||||
spin_lock_irq(&ump->legacy_locks[dir]);
|
spin_lock_irq(&ump->legacy_locks[dir]);
|
||||||
ump->legacy_substreams[dir][group] = substream;
|
ump->legacy_substreams[dir][group] = substream;
|
||||||
@@ -1091,7 +1091,7 @@ static int process_legacy_output(struct snd_ump_endpoint *ump,
|
|||||||
ctx = &ump->out_cvts[group];
|
ctx = &ump->out_cvts[group];
|
||||||
while (!ctx->ump_bytes &&
|
while (!ctx->ump_bytes &&
|
||||||
snd_rawmidi_transmit(substream, &c, 1) > 0)
|
snd_rawmidi_transmit(substream, &c, 1) > 0)
|
||||||
snd_ump_convert_to_ump(ump, group, c);
|
snd_ump_convert_to_ump(ctx, group, ump->info.protocol, c);
|
||||||
if (ctx->ump_bytes && ctx->ump_bytes <= count) {
|
if (ctx->ump_bytes && ctx->ump_bytes <= count) {
|
||||||
size = ctx->ump_bytes;
|
size = ctx->ump_bytes;
|
||||||
memcpy(buffer, ctx->ump, size);
|
memcpy(buffer, ctx->ump, size);
|
||||||
@@ -1113,7 +1113,7 @@ static void process_legacy_input(struct snd_ump_endpoint *ump, const u32 *src,
|
|||||||
const int dir = SNDRV_RAWMIDI_STREAM_INPUT;
|
const int dir = SNDRV_RAWMIDI_STREAM_INPUT;
|
||||||
int size;
|
int size;
|
||||||
|
|
||||||
size = snd_ump_convert_from_ump(ump, src, buf, &group);
|
size = snd_ump_convert_from_ump(src, buf, &group);
|
||||||
if (size <= 0)
|
if (size <= 0)
|
||||||
return;
|
return;
|
||||||
spin_lock_irqsave(&ump->legacy_locks[dir], flags);
|
spin_lock_irqsave(&ump->legacy_locks[dir], flags);
|
||||||
@@ -1130,9 +1130,9 @@ int snd_ump_attach_legacy_rawmidi(struct snd_ump_endpoint *ump,
|
|||||||
bool input, output;
|
bool input, output;
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
err = snd_ump_convert_init(ump);
|
ump->out_cvts = kcalloc(16, sizeof(*ump->out_cvts), GFP_KERNEL);
|
||||||
if (err < 0)
|
if (!ump->out_cvts)
|
||||||
return err;
|
return -ENOMEM;
|
||||||
|
|
||||||
input = ump->core.info_flags & SNDRV_RAWMIDI_INFO_INPUT;
|
input = ump->core.info_flags & SNDRV_RAWMIDI_INFO_INPUT;
|
||||||
output = ump->core.info_flags & SNDRV_RAWMIDI_INFO_OUTPUT;
|
output = ump->core.info_flags & SNDRV_RAWMIDI_INFO_OUTPUT;
|
||||||
@@ -1140,7 +1140,7 @@ int snd_ump_attach_legacy_rawmidi(struct snd_ump_endpoint *ump,
|
|||||||
output ? 16 : 0, input ? 16 : 0,
|
output ? 16 : 0, input ? 16 : 0,
|
||||||
&rmidi);
|
&rmidi);
|
||||||
if (err < 0) {
|
if (err < 0) {
|
||||||
snd_ump_convert_free(ump);
|
kfree(ump->out_cvts);
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -8,7 +8,7 @@
|
|||||||
#include <sound/core.h>
|
#include <sound/core.h>
|
||||||
#include <sound/asound.h>
|
#include <sound/asound.h>
|
||||||
#include <sound/ump.h>
|
#include <sound/ump.h>
|
||||||
#include "ump_convert.h"
|
#include <sound/ump_convert.h>
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Upgrade / downgrade value bits
|
* Upgrade / downgrade value bits
|
||||||
@@ -205,12 +205,18 @@ static int cvt_ump_sysex7_to_legacy(const u32 *data, unsigned char *buf)
|
|||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* convert from a UMP packet @data to MIDI 1.0 bytes at @buf;
|
/**
|
||||||
* the target group is stored at @group_ret,
|
* snd_ump_convert_from_ump - convert from UMP to legacy MIDI
|
||||||
* returns the number of bytes of MIDI 1.0 stream
|
* @data: UMP packet
|
||||||
|
* @buf: buffer to store legacy MIDI data
|
||||||
|
* @group_ret: pointer to store the target group
|
||||||
|
*
|
||||||
|
* Convert from a UMP packet @data to MIDI 1.0 bytes at @buf.
|
||||||
|
* The target group is stored at @group_ret.
|
||||||
|
*
|
||||||
|
* The function returns the number of bytes of MIDI 1.0 stream.
|
||||||
*/
|
*/
|
||||||
int snd_ump_convert_from_ump(struct snd_ump_endpoint *ump,
|
int snd_ump_convert_from_ump(const u32 *data,
|
||||||
const u32 *data,
|
|
||||||
unsigned char *buf,
|
unsigned char *buf,
|
||||||
unsigned char *group_ret)
|
unsigned char *group_ret)
|
||||||
{
|
{
|
||||||
@@ -230,6 +236,7 @@ int snd_ump_convert_from_ump(struct snd_ump_endpoint *ump,
|
|||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
EXPORT_SYMBOL_GPL(snd_ump_convert_from_ump);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* MIDI 1 byte stream -> UMP conversion
|
* MIDI 1 byte stream -> UMP conversion
|
||||||
@@ -302,10 +309,10 @@ static void fill_rpn(struct ump_cvt_to_ump_bank *cc,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* convert to a MIDI 1.0 Channel Voice message */
|
/* convert to a MIDI 1.0 Channel Voice message */
|
||||||
static int cvt_legacy_cmd_to_ump(struct snd_ump_endpoint *ump,
|
static int cvt_legacy_cmd_to_ump(struct ump_cvt_to_ump *cvt,
|
||||||
struct ump_cvt_to_ump *cvt,
|
unsigned char group,
|
||||||
unsigned char group, u32 *data,
|
unsigned int protocol,
|
||||||
unsigned char bytes)
|
u32 *data, unsigned char bytes)
|
||||||
{
|
{
|
||||||
const unsigned char *buf = cvt->buf;
|
const unsigned char *buf = cvt->buf;
|
||||||
struct ump_cvt_to_ump_bank *cc;
|
struct ump_cvt_to_ump_bank *cc;
|
||||||
@@ -316,7 +323,7 @@ static int cvt_legacy_cmd_to_ump(struct snd_ump_endpoint *ump,
|
|||||||
BUILD_BUG_ON(sizeof(union snd_ump_midi2_msg) != 8);
|
BUILD_BUG_ON(sizeof(union snd_ump_midi2_msg) != 8);
|
||||||
|
|
||||||
/* for MIDI 1.0 UMP, it's easy, just pack it into UMP */
|
/* for MIDI 1.0 UMP, it's easy, just pack it into UMP */
|
||||||
if (ump->info.protocol & SNDRV_UMP_EP_INFO_PROTO_MIDI1) {
|
if (protocol & SNDRV_UMP_EP_INFO_PROTO_MIDI1) {
|
||||||
data[0] = ump_compose(UMP_MSG_TYPE_MIDI1_CHANNEL_VOICE,
|
data[0] = ump_compose(UMP_MSG_TYPE_MIDI1_CHANNEL_VOICE,
|
||||||
group, 0, buf[0]);
|
group, 0, buf[0]);
|
||||||
data[0] |= buf[1] << 8;
|
data[0] |= buf[1] << 8;
|
||||||
@@ -413,8 +420,8 @@ static int cvt_legacy_cmd_to_ump(struct snd_ump_endpoint *ump,
|
|||||||
return 8;
|
return 8;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int do_convert_to_ump(struct snd_ump_endpoint *ump,
|
static int do_convert_to_ump(struct ump_cvt_to_ump *cvt, unsigned char group,
|
||||||
unsigned char group, unsigned char c, u32 *data)
|
unsigned int protocol, unsigned char c, u32 *data)
|
||||||
{
|
{
|
||||||
/* bytes for 0x80-0xf0 */
|
/* bytes for 0x80-0xf0 */
|
||||||
static unsigned char cmd_bytes[8] = {
|
static unsigned char cmd_bytes[8] = {
|
||||||
@@ -424,7 +431,6 @@ static int do_convert_to_ump(struct snd_ump_endpoint *ump,
|
|||||||
static unsigned char system_bytes[16] = {
|
static unsigned char system_bytes[16] = {
|
||||||
0, 2, 3, 2, 0, 0, 1, 0, 1, 1, 1, 1, 0, 0, 1, 1
|
0, 2, 3, 2, 0, 0, 1, 0, 1, 1, 1, 1, 0, 0, 1, 1
|
||||||
};
|
};
|
||||||
struct ump_cvt_to_ump *cvt = &ump->out_cvts[group];
|
|
||||||
unsigned char bytes;
|
unsigned char bytes;
|
||||||
|
|
||||||
if (c == UMP_MIDI1_MSG_SYSEX_START) {
|
if (c == UMP_MIDI1_MSG_SYSEX_START) {
|
||||||
@@ -478,40 +484,22 @@ static int do_convert_to_ump(struct snd_ump_endpoint *ump,
|
|||||||
cvt->len = 1;
|
cvt->len = 1;
|
||||||
if ((cvt->buf[0] & 0xf0) == UMP_MIDI1_MSG_REALTIME)
|
if ((cvt->buf[0] & 0xf0) == UMP_MIDI1_MSG_REALTIME)
|
||||||
return cvt_legacy_system_to_ump(cvt, group, data);
|
return cvt_legacy_system_to_ump(cvt, group, data);
|
||||||
return cvt_legacy_cmd_to_ump(ump, cvt, group, data, cvt->cmd_bytes);
|
return cvt_legacy_cmd_to_ump(cvt, group, protocol, data, cvt->cmd_bytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* feed a MIDI 1.0 byte @c and convert to a UMP packet;
|
/**
|
||||||
* the target group is @group,
|
* snd_ump_convert_to_ump - convert legacy MIDI byte to UMP packet
|
||||||
* the result is stored in out_cvts[group].ump[] and out_cvts[group].ump_bytes
|
* @cvt: converter context
|
||||||
|
* @group: target UMP group
|
||||||
|
* @protocol: target UMP protocol
|
||||||
|
* @c: MIDI 1.0 byte data
|
||||||
|
*
|
||||||
|
* Feed a MIDI 1.0 byte @c and convert to a UMP packet if completed.
|
||||||
|
* The result is stored in the buffer in @cvt.
|
||||||
*/
|
*/
|
||||||
void snd_ump_convert_to_ump(struct snd_ump_endpoint *ump,
|
void snd_ump_convert_to_ump(struct ump_cvt_to_ump *cvt, unsigned char group,
|
||||||
unsigned char group, unsigned char c)
|
unsigned int protocol, unsigned char c)
|
||||||
{
|
{
|
||||||
struct ump_cvt_to_ump *cvt = &ump->out_cvts[group];
|
cvt->ump_bytes = do_convert_to_ump(cvt, group, protocol, c, cvt->ump);
|
||||||
|
|
||||||
cvt->ump_bytes = do_convert_to_ump(ump, group, c, cvt->ump);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* reset the converter context, called at each open */
|
|
||||||
void snd_ump_reset_convert_to_ump(struct snd_ump_endpoint *ump,
|
|
||||||
unsigned char group)
|
|
||||||
{
|
|
||||||
memset(&ump->out_cvts[group], 0, sizeof(*ump->out_cvts));
|
|
||||||
}
|
|
||||||
|
|
||||||
/* initialize converters */
|
|
||||||
int snd_ump_convert_init(struct snd_ump_endpoint *ump)
|
|
||||||
{
|
|
||||||
ump->out_cvts = kcalloc(16, sizeof(*ump->out_cvts), GFP_KERNEL);
|
|
||||||
if (!ump->out_cvts)
|
|
||||||
return -ENOMEM;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* release resources */
|
|
||||||
void snd_ump_convert_free(struct snd_ump_endpoint *ump)
|
|
||||||
{
|
|
||||||
kfree(ump->out_cvts);
|
|
||||||
ump->out_cvts = NULL;
|
|
||||||
}
|
}
|
||||||
|
EXPORT_SYMBOL_GPL(snd_ump_convert_to_ump);
|
||||||
|
Reference in New Issue
Block a user