Skip to contentSkip to conversation

ES938 support for ES18xx driver

RFC PATCH In review Ondrej Zary 2 participants 9 messages Sep 14, 2013 – Sep 19, 2013 Sound

lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/1 ES938 support for ES18xx driver

Hello,
this is an attempt to support ES938 3-D Audio Effects Processor found on some ES18xx (and possibly other) sound cards, doing bass/treble and 3D control.

ES938 is controlled by MIDI SysEx commands sent through card's MPU401 port.

The following patch works but has a problem: the midi port cannot be used by userspace applications. Opening and closing the rawmidi device on each control change would probably work (as long as the port is not used by an application) but that just does not seem right. Is there a way to cleanly fix this?

(There are two problems: 3D level does not have any effect and alsamixer does not display the TLV dB values - but don't know why).

---
 sound/isa/Kconfig  |    4 +
 sound/isa/Makefile |    2 +
 sound/isa/es18xx.c |   12 +++-
 sound/isa/es938.c  |  181 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 sound/isa/es938.h  |   24 +++++++
 5 files changed, 222 insertions(+), 1 deletions(-)
 create mode 100644 sound/isa/es938.c
 create mode 100644 sound/isa/es938.h
sound/isa/Kconfig +4 -0
index affa134..a8bf3e3 100644
@@ -17,6 +17,9 @@ config SND_SB16_DSP
         select SND_PCM
         select SND_SB_COMMON
 
+config SND_ES938
+	tristate
+
 menuconfig SND_ISA
 	bool "ISA sound devices"
 	depends on ISA && ISA_DMA_API
@@ -183,6 +186,7 @@ config SND_ES18XX
 	select SND_OPL3_LIB
 	select SND_MPU401_UART
 	select SND_PCM
+	select SND_ES938
 	help
 	  Say Y here to include support for ESS AudioDrive ES18xx chips.
 
sound/isa/Makefile +2 -0
index 9a15f14..d59e0bf 100644
@@ -8,6 +8,7 @@ snd-als100-objs := als100.o
 snd-azt2320-objs := azt2320.o
 snd-cmi8328-objs := cmi8328.o
 snd-cmi8330-objs := cmi8330.o
+snd-es938-objs := es938.o
 snd-es18xx-objs := es18xx.o
 snd-opl3sa2-objs := opl3sa2.o
 snd-sc6000-objs := sc6000.o
@@ -19,6 +20,7 @@ obj-$(CONFIG_SND_ALS100) += snd-als100.o
 obj-$(CONFIG_SND_AZT2320) += snd-azt2320.o
 obj-$(CONFIG_SND_CMI8328) += snd-cmi8328.o
 obj-$(CONFIG_SND_CMI8330) += snd-cmi8330.o
+obj-$(CONFIG_SND_ES938) += snd-es938.o
 obj-$(CONFIG_SND_ES18XX) += snd-es18xx.o
 obj-$(CONFIG_SND_OPL3SA2) += snd-opl3sa2.o
 obj-$(CONFIG_SND_SC6000) += snd-sc6000.o
sound/isa/es18xx.c +11 -1
index 12978b8..c502aa0 100644
@@ -96,6 +96,7 @@
 #define SNDRV_LEGACY_FIND_FREE_IRQ
 #define SNDRV_LEGACY_FIND_FREE_DMA
 #include <sound/initval.h>
+#include "es938.h"
 
 #define PFX "es18xx: "
 
@@ -122,6 +123,7 @@ struct snd_es18xx {
 	struct snd_pcm_substream *playback_b_substream;
 
 	struct snd_rawmidi *rmidi;
+	struct snd_es938 es938;
 
 	struct snd_kcontrol *hw_volume;
 	struct snd_kcontrol *hw_switch;
@@ -2166,7 +2168,15 @@ static int snd_audiodrive_probe(struct snd_card *card, int dev)
 			return err;
 	}
 
-	return snd_card_register(card);
+	err = snd_card_register(card);
+	if (err < 0)
+		return err;
+
+	if (mpu_port[dev] > 0 && mpu_port[dev] != SNDRV_AUTO_PORT)
+		if (snd_es938_init(&chip->es938, card, 0, 0) == 0)
+			printk("es938 found!\n");
+
+	return 0;
 }
 
 static int snd_es18xx_isa_match(struct device *pdev, unsigned int dev)
sound/isa/es938.c new file +181 -0

181 lines not on this page · raw message

sound/isa/es938.h new file +24 -0
new file mode 100644
index 0000000..1f8595f
@@ -0,0 +1,24 @@
+#include <sound/tlv.h>
+
+#define ES938_ID	0x00, 0x00, 0x7b
+
+#define ES938_CMD_REG_R		0x7e
+#define ES938_CMD_REG_W		0x7f
+
+#define ES938_REG_MISC		0
+#define ES938_REG_TONE		1
+#define ES938_REG_SPATIAL	5
+#define ES938_REG_SPATIAL_EN	6
+#define ES938_REG_POWER		7
+
+struct snd_es938 {
+	u8 regs[8];
+	struct snd_rawmidi_file rfile;
+};
+
+int snd_es938_init(struct snd_es938 *chip, struct snd_card *card, int device,
+		   int subdevice);
+void snd_es938_release(struct snd_es938 *chip);
+int snd_es938_info_mixer(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo);
+int snd_es938_get_mixer(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol);
+int snd_es938_put_mixer(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol);
Signature · 1 line
Ondrej Zary
#1 lore raw

Hi,

Quoted 6 lines

ES938 is controlled by MIDI SysEx commands sent through card's MPU401 port.

The following patch works but has a problem: the midi port cannot be used by userspace applications. Opening and closing the rawmidi device on each control change would probably work (as long as the port is not used by an application) but that just does not seem right. Is there a way to cleanly fix this?

Just to clarify matters:

The story here was a bit split, but then I got it:
you're saying that since ES938 control is via MIDI SysEx,
these operations will occupy MIDI resources at least while controlling ES938 and therefore they're unavailable for userspace.

Don't tell me we'd require a MIDI access multiplexing layer which perhaps does not exist yet...

Quoted 2 lines

(There are two problems: 3D level does not have any effect and alsamixer does not display the TLV dB values - but don't know why).

Hmm, I'm rather in the dark here as well - however from my driver experiences the actually sort-of standardized 3D level control
may have some "weird" deviations (at least when talking AC97 or pseudo-AC97) such as different bitmask indices or possibly even inverted volume operation (background: azt3328 is pseudo-AC97, thus it has some deviations). Sorry for not knowing any more helpful hints...

Hmm, or perhaps ES938_REG_POWER needs some special values configured to have 3D sound effects powered up, too?
OTOH if this is a simple non-DSP implementation then 3D probably is implemented via delay lines etc., so perhaps it is so simple that it does not have a special "enable power" switch after all.

Oh, and BTW, my azt3328.c said:

* - (non-bug) "Bass/Treble or 3D settings don't work" - they do get evaluated

 *    if you set PCM output switch to "pre 3D" instead of "post 3D".
 *    If this can't be set, then get a mixer application that Isn't Stupid (tm)
 *    (e.g. kmix, gamix) - unfortunately several are!!

So perhaps ES938 has (perhaps since it might more or less conform to certain standards specs?) another control for PCM output switch as well which would need implementing or simply isn't set properly?
(to clarify, we're talking about a switch which would cause output signal to be grabbed pre or post the 3D manipulation block)

sound/isa/es18xx.c static int snd_audiodrive_probe(struct snd_card *card, int dev) · line 2177

Quoted 2 lines
sound/isa/es18xx.c +2 -0
+		if (snd_es938_init(&chip->es938, card, 0, 0) == 0)
+			printk("es938 found!\n");

Perhaps we could have a more verbose message here?
That ES938 surely must have some human-readable characteristics... (hmm, what about "ES938 3D audio effects processor found!"?) ((or "Detected ..."))

sound/isa/es938.c line 115

Quoted 3 lines
sound/isa/es938.c new file +3 -0
+	/* try to read a register to detect chip presence */
+	if (snd_es938_read_reg(chip, ES938_REG_MISC, NULL) < 0)
+		return -ENODEV;

Perhaps that check is not specific enough, i.e. it might be useful to figure out a more precise check?

Thanks a ton for enhancing the feature set of certain sound cards :))

Andreas Mohr

#2 lore raw
Quoted 13 lines · On Sunday 15 September 2013 20:49:02 Andreas Mohr wrote:

Hi,

Quoted 8 lines

ES938 is controlled by MIDI SysEx commands sent through card's MPU401 port.

The following patch works but has a problem: the midi port cannot be used by userspace applications. Opening and closing the rawmidi device on each control change would probably work (as long as the port is not used by an application) but that just does not seem right. Is there a way to cleanly fix this?

Just to clarify matters:

Quoted 7 lines

The story here was a bit split, but then I got it:
you're saying that since ES938 control is via MIDI SysEx, these operations will occupy MIDI resources at least while controlling ES938 and therefore they're unavailable for userspace.

Don't tell me we'd require a MIDI access multiplexing layer which perhaps does not exist yet...

Probably some hack that would allow the driver to send MIDI data behind everyone's back would be enough. Receiving is not needed (because the read register command is used only once for device detection). The SNDRV_RAWMIDI_LFLG_APPEND thing looks like that but does not seem to work.

And another bad thing I forgot to mention before: the driver cannot be unloaded because the MIDI device is open (circular dependency between snd-es18xx and snd-es938).

Maybe rawmidi_open_priv() would work, only if it was exported (and not _priv).

Quoted 16 lines
Quoted 2 lines

(There are two problems: 3D level does not have any effect and alsamixer does not display the TLV dB values - but don't know why).

Hmm, I'm rather in the dark here as well - however from my driver experiences the actually sort-of standardized 3D level control may have some "weird" deviations (at least when talking AC97 or pseudo-AC97) such as different bitmask indices or possibly even inverted volume operation (background: azt3328 is pseudo-AC97, thus it has some deviations). Sorry for not knowing any more helpful hints...

Hmm, or perhaps ES938_REG_POWER needs some special values configured to have 3D sound effects powered up, too?
OTOH if this is a simple non-DSP implementation then 3D probably is implemented via delay lines etc., so perhaps it is so simple that it does not have a special "enable power" switch after all.

Quoted 8 lines

Oh, and BTW, my azt3328.c said:

* - (non-bug) "Bass/Treble or 3D settings don't work" - they do get evaluated
* if you set PCM output switch to "pre 3D" instead of "post 3D".
* If this can't be set, then get a mixer application that Isn't Stupid
(tm)
* (e.g. kmix, gamix) - unfortunately several are!!

BTW. I've got an AZT3328 card and it works fine with your driver. Thanks for it.
I'm thinking about doing some reverse-engineering of thunderbird-based sound cards (VLSI Thunderbird - Aztech PCI 368-DSP, Thunderbird Avenger - Philips Acoustic/Seismic/Rhythmic Edge).

Quoted 5 lines

So perhaps ES938 has (perhaps since it might more or less conform to certain standards specs?) another control for PCM output switch as well which would need implementing or simply isn't set properly? (to clarify, we're talking about a switch which would cause output signal to be grabbed pre or post the 3D manipulation block)

The good thing is that there's a datasheet available for ES938 - e.g. at
http://www.datasheetarchive.com/ES938-datasheet.html

The 3D switch works but the level doesn't. Maybe I should use only the 3 specific level values from the datasheet and not a variable scale. Or just remove the level control completely as Windows driver does (there's only a 3D switch).

Quoted 7 lines

sound/isa/es18xx.c static int snd_audiodrive_probe(struct snd_card *card, int dev) · line 2177

Quoted 2 lines
sound/isa/es18xx.c +2 -0
+		if (snd_es938_init(&chip->es938, card, 0, 0) == 0)
+			printk("es938 found!\n");

Perhaps we could have a more verbose message here?
That ES938 surely must have some human-readable characteristics... (hmm, what about "ES938 3D audio effects processor found!"?) ((or "Detected ..."))

Yes, that's wrong - it's only for testing purposes. There should probably be no message at all as the es18xx driver itself does not display anything if everything is OK.

Quoted 6 lines

sound/isa/es938.c line 115

Quoted 3 lines
sound/isa/es938.c new file +3 -0
+	/* try to read a register to detect chip presence */
+	if (snd_es938_read_reg(chip, ES938_REG_MISC, NULL) < 0)
+		return -ENODEV;

Perhaps that check is not specific enough, i.e. it might be useful to figure out a more precise check?

snd_es938_read_reg() checks that the returned data match the format used by ES938. Maybe we can reread all the register values back after writing to be sure.

Signature · 1 line
Ondrej Zary
#3 lore raw

Hi,

Quoted 3 lines · Ondrej Zary

On Sunday 15 September 2013 20:49:02 Andreas Mohr wrote:
BTW. I've got an AZT3328 card and it works fine with your driver. Thanks for it.

What!?!? I didn't quite expect any kernel dev to have that one, too ;)

(got several commits sitting here and waiting for submission though)

Quoted 3 lines

I'm thinking about doing some reverse-engineering of thunderbird-based sound cards (VLSI Thunderbird - Aztech PCI 368-DSP, Thunderbird Avenger - Philips Acoustic/Seismic/Rhythmic Edge).

Oh, nice. I've got the Aztech PCI 368-DSP, too (that was somewhat obligatory due to having written another Aztech card driver...).

And yeah, the PCI 368 (etc.) series does seem to be some rather heavy support hole indeed, IIRC (especially as it's more modern PCI-based and not ISA).

Quoted 6 lines
Quoted 5 lines

So perhaps ES938 has (perhaps since it might more or less conform to certain standards specs?) another control for PCM output switch as well which would need implementing or simply isn't set properly? (to clarify, we're talking about a switch which would cause output signal to be grabbed pre or post the 3D manipulation block)

Quoted 7 lines

The good thing is that there's a datasheet available for ES938 - e.g. at
http://www.datasheetarchive.com/ES938-datasheet.html

The 3D switch works but the level doesn't. Maybe I should use only the 3 specific level values from the datasheet and not a variable scale. Or just remove the level control completely as Windows driver does (there's only a 3D switch).

Hmm. Perhaps they removed it "Since It Does Not Work"? ;-P

Thanks for hinting at the TLV control dB values thingy! Didn't know that such thing existed, thus azt3328 does not have it (yet?).

Quoted 8 lines
Quoted 4 lines

Perhaps we could have a more verbose message here?
That ES938 surely must have some human-readable characteristics... (hmm, what about "ES938 3D audio effects processor found!"?) ((or "Detected ..."))

Yes, that's wrong - it's only for testing purposes. There should probably be no message at all as the es18xx driver itself does not display anything if everything is OK.

...or that, yeah.

Quoted 6 lines
Quoted 2 lines

Perhaps that check is not specific enough, i.e. it might be useful to figure out a more precise check?

snd_es938_read_reg() checks that the returned data match the format used by ES938. Maybe we can reread all the register values back after writing to be sure.

Is there any chip ID/version register to be identified?

Andreas Mohr

#4 lore raw
Quoted 8 lines · On Sunday 15 September 2013 22:35:20 Andreas Mohr wrote:

Hi,

Quoted 3 lines · Ondrej Zary

On Sunday 15 September 2013 20:49:02 Andreas Mohr wrote:
BTW. I've got an AZT3328 card and it works fine with your driver. Thanks for it.

What!?!? I didn't quite expect any kernel dev to have that one, too ;)

Don't remember where I got it from but it looked nice so I bought it :)

Quoted 6 lines

(got several commits sitting here and waiting for submission though)

Quoted 3 lines

I'm thinking about doing some reverse-engineering of thunderbird-based sound cards (VLSI Thunderbird - Aztech PCI 368-DSP, Thunderbird Avenger - Philips Acoustic/Seismic/Rhythmic Edge).

Quoted 6 lines

Oh, nice. I've got the Aztech PCI 368-DSP, too (that was somewhat obligatory due to having written another Aztech card driver...).

And yeah, the PCI 368 (etc.) series does seem to be some rather heavy support hole indeed, IIRC (especially as it's more modern PCI-based and not ISA).

Got it on eBay but the Philips Edge cards are not that uncommon - they were sold here (in Slovakia) too, IIRC. I have Seismic Edge PSC705 (but bought it used).

Quoted 9 lines
Quoted 9 lines
Quoted 5 lines

So perhaps ES938 has (perhaps since it might more or less conform to certain standards specs?) another control for PCM output switch as well which would need implementing or simply isn't set properly? (to clarify, we're talking about a switch which would cause output signal to be grabbed pre or post the 3D manipulation block)

The good thing is that there's a datasheet available for ES938 - e.g. at
http://www.datasheetarchive.com/ES938-datasheet.html

Quoted 6 lines
Quoted 4 lines

The 3D switch works but the level doesn't. Maybe I should use only the 3 specific level values from the datasheet and not a variable scale. Or just remove the level control completely as Windows driver does (there's only a 3D switch).

Hmm. Perhaps they removed it "Since It Does Not Work"? ;-P

Maybe. The value is configured in the INF file and never changed.

Quoted 2 lines

Thanks for hinting at the TLV control dB values thingy! Didn't know that such thing existed, thus azt3328 does not have it (yet?).

It's a nice thing, especially for cards that can go above 0 dB. You then know that the sound can be distorted when you set e.g. PCM volume too high.

Quoted 11 lines
Quoted 8 lines
Quoted 4 lines

Perhaps we could have a more verbose message here?
That ES938 surely must have some human-readable characteristics... (hmm, what about "ES938 3D audio effects processor found!"?) ((or "Detected ..."))

Yes, that's wrong - it's only for testing purposes. There should probably be no message at all as the es18xx driver itself does not display anything if everything is OK.

...or that, yeah.

Quoted 8 lines
Quoted 6 lines
Quoted 2 lines

Perhaps that check is not specific enough, i.e. it might be useful to figure out a more precise check?

snd_es938_read_reg() checks that the returned data match the format used by ES938. Maybe we can reread all the register values back after writing to be sure.

Is there any chip ID/version register to be identified?

No, there are only 8 registers, all(? - haven't tested) R/W.

Signature · 1 line
Ondrej Zary
#5 lore raw
Quoted 4 lines · Ondrej Zary
Quoted 1 line · On Sunday 15 September 2013 22:35:20 Andreas Mohr wrote:

What!?!? I didn't quite expect any kernel dev to have that one, too ;)

Don't remember where I got it from but it looked nice so I bought it :)

Yup, e.g. the builtin amp is quite nice.

Quoted 5 lines
Quoted 2 lines

Thanks for hinting at the TLV control dB values thingy! Didn't know that such thing existed, thus azt3328 does not have it (yet?).

It's a nice thing, especially for cards that can go above 0 dB. You then know that the sound can be distorted when you set e.g. PCM volume too high.

Hmm, any hint how to precisely do dB values normalization scaling, for a card where this is not documented? Or perhaps that's actually easy - haven't thought about it...

Quoted 3 lines
Quoted 1 line

Is there any chip ID/version register to be identified?

No, there are only 8 registers, all(? - haven't tested) R/W.

OK, but possibly they happen to be creating another virtual register mapping range? (i.e. index/data register combo?)

Andreas Mohr

#6 lore raw
Quoted 11 lines · On Sunday 15 September 2013 23:23:58 Andreas Mohr wrote:
Quoted 4 lines · Ondrej Zary
Quoted 1 line · On Sunday 15 September 2013 22:35:20 Andreas Mohr wrote:

What!?!? I didn't quite expect any kernel dev to have that one, too ;)

Don't remember where I got it from but it looked nice so I bought it :)

Yup, e.g. the builtin amp is quite nice.

Quoted 3 lines
Quoted 2 lines

Thanks for hinting at the TLV control dB values thingy! Didn't know that such thing existed, thus azt3328 does not have it (yet?).

Quoted 7 lines
Quoted 3 lines

It's a nice thing, especially for cards that can go above 0 dB. You then know that the sound can be distorted when you set e.g. PCM volume too high.

Hmm, any hint how to precisely do dB values normalization scaling, for a card where this is not documented? Or perhaps that's actually easy - haven't thought about it...

Perhaps with 3 sound cards: one for recording, one with known dB values and one unknown.
First play some test signal at known dB value and record that. Then play the signal using on the unknown card and ajdust its mixer so that the recording revel is the same as before.
Repeat a few times to find out the dB value of mixer step.

Quoted 6 lines
Quoted 3 lines
Quoted 1 line

Is there any chip ID/version register to be identified?

No, there are only 8 registers, all(? - haven't tested) R/W.

OK, but possibly they happen to be creating another virtual register mapping range? (i.e. index/data register combo?)

Datasheet says that there are no more registers - just 0..7 (2,3,4 are reserved).

Signature · 1 line
Ondrej Zary
#7 lore raw
In reply to Andreas Mohr

This is v2, which opens/closes the MIDI device everytime a mixer control value is changed. Userspace apps can now use the MIDI port. Changing the mixer controls will fail when the MIDI port is open.

Also the 3D level control now works - seems that the reserved bit 0 must be set.

---
 sound/isa/Kconfig  |    4 +
 sound/isa/Makefile |    2 +
 sound/isa/es18xx.c |   11 +++-
 sound/isa/es938.c  |  203 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 sound/isa/es938.h  |   29 ++++++++
 5 files changed, 248 insertions(+), 1 deletions(-)
 create mode 100644 sound/isa/es938.c
 create mode 100644 sound/isa/es938.h
sound/isa/Kconfig +4 -0
index affa134..a8bf3e3 100644
@@ -17,6 +17,9 @@ config SND_SB16_DSP
         select SND_PCM
         select SND_SB_COMMON
 
+config SND_ES938
+	tristate
+
 menuconfig SND_ISA
 	bool "ISA sound devices"
 	depends on ISA && ISA_DMA_API
@@ -183,6 +186,7 @@ config SND_ES18XX
 	select SND_OPL3_LIB
 	select SND_MPU401_UART
 	select SND_PCM
+	select SND_ES938
 	help
 	  Say Y here to include support for ESS AudioDrive ES18xx chips.
 
sound/isa/Makefile +2 -0
index 9a15f14..d59e0bf 100644
@@ -8,6 +8,7 @@ snd-als100-objs := als100.o
 snd-azt2320-objs := azt2320.o
 snd-cmi8328-objs := cmi8328.o
 snd-cmi8330-objs := cmi8330.o
+snd-es938-objs := es938.o
 snd-es18xx-objs := es18xx.o
 snd-opl3sa2-objs := opl3sa2.o
 snd-sc6000-objs := sc6000.o
@@ -19,6 +20,7 @@ obj-$(CONFIG_SND_ALS100) += snd-als100.o
 obj-$(CONFIG_SND_AZT2320) += snd-azt2320.o
 obj-$(CONFIG_SND_CMI8328) += snd-cmi8328.o
 obj-$(CONFIG_SND_CMI8330) += snd-cmi8330.o
+obj-$(CONFIG_SND_ES938) += snd-es938.o
 obj-$(CONFIG_SND_ES18XX) += snd-es18xx.o
 obj-$(CONFIG_SND_OPL3SA2) += snd-opl3sa2.o
 obj-$(CONFIG_SND_SC6000) += snd-sc6000.o
sound/isa/es18xx.c +10 -1
index 12978b8..5e496a7 100644
@@ -96,6 +96,7 @@
 #define SNDRV_LEGACY_FIND_FREE_IRQ
 #define SNDRV_LEGACY_FIND_FREE_DMA
 #include <sound/initval.h>
+#include "es938.h"
 
 #define PFX "es18xx: "
 
@@ -122,6 +123,7 @@ struct snd_es18xx {
 	struct snd_pcm_substream *playback_b_substream;
 
 	struct snd_rawmidi *rmidi;
+	struct snd_es938 es938;
 
 	struct snd_kcontrol *hw_volume;
 	struct snd_kcontrol *hw_switch;
@@ -2166,7 +2168,14 @@ static int snd_audiodrive_probe(struct snd_card *card, int dev)
 			return err;
 	}
 
-	return snd_card_register(card);
+	err = snd_card_register(card);
+	if (err < 0)
+		return err;
+
+	if (mpu_port[dev] > 0 && mpu_port[dev] != SNDRV_AUTO_PORT)
+		snd_es938_init(&chip->es938, card, 0, 0);
+
+	return 0;
 }
 
 static int snd_es18xx_isa_match(struct device *pdev, unsigned int dev)
sound/isa/es938.c new file +203 -0

203 lines not on this page · raw message

sound/isa/es938.h new file +29 -0
new file mode 100644
index 0000000..b67dfc7
@@ -0,0 +1,29 @@
+#include <sound/tlv.h>
+
+#define ES938_ID		0x7b
+
+#define ES938_CMD_REG_R		0x7e
+#define ES938_CMD_REG_W		0x7f
+
+#define ES938_REG_MISC		0
+#define ES938_REG_TONE		1
+#define ES938_REG_SPATIAL	5
+#define ES938_REG_SPATIAL_EN	6
+#define ES938_REG_POWER		7
+
+struct snd_es938 {
+	u8 regs[8];
+	struct snd_card *card;
+	int device;
+	int subdevice;
+	struct snd_rawmidi_file rfile;
+};
+
+int snd_es938_init(struct snd_es938 *chip, struct snd_card *card, int device,
+		   int subdevice);
+int snd_es938_info_mixer(struct snd_kcontrol *kcontrol,
+			 struct snd_ctl_elem_info *uinfo);
+int snd_es938_get_mixer(struct snd_kcontrol *kcontrol,
+			struct snd_ctl_elem_value *ucontrol);
+int snd_es938_put_mixer(struct snd_kcontrol *kcontrol,
+			struct snd_ctl_elem_value *ucontrol);
Signature · 1 line
Ondrej Zary
#8 lore raw

Hi,

Quoted 10 lines · Ondrej Zary
sound/isa/es938.c new file +10 -0
+static int snd_es938_read_reg(struct snd_es938 *chip, u8 reg, u8 *out)
+{
+	u8 buf[8];
+	int i = 0, res;
+	u8 sysex[] = { MIDI_CMD_COMMON_SYSEX, 0x00, 0x00, ES938_ID,
+		       ES938_CMD_REG_R, reg, MIDI_CMD_COMMON_SYSEX_END };
+	unsigned long end_time;
+
+	snd_rawmidi_kernel_write(chip->rfile.output, sysex, sizeof(sysex));
+

sound/isa/es938.c line 52

Quoted 10 lines
sound/isa/es938.c new file +10 -0
+	memset(buf, 0, sizeof(buf));
+	end_time = jiffies + msecs_to_jiffies(100);
+	while (i < sizeof(buf)) {
+		res = snd_rawmidi_kernel_read(chip->rfile.input, buf + i,
+					      sizeof(buf) - i);
+		if (res > 0)
+			i += res;
+		if (time_after(jiffies, end_time))
+			return -1;
+	}

Forgive me, but I seem to faintly remember that it's preferred for user code to tend towards non-jiffies-based timing (IIRC due to NOHZ efforts etc.).
So if that actually is the case, then one might want to change it to less jiffies-dependent handling (use non-jiffies helpers), but then how?

sound/isa/es938.c line 69

Quoted 6 lines
sound/isa/es938.c new file +6 -0
+static void snd_es938_write_reg(struct snd_es938 *chip, u8 reg, u8 val)
+{
+	u8 sysex[] = { MIDI_CMD_COMMON_SYSEX, 0x00, 0x00, ES938_ID,
+		       ES938_CMD_REG_W, reg, val, MIDI_CMD_COMMON_SYSEX_END };
+
+	snd_rawmidi_kernel_write(chip->rfile.output, sysex, sizeof(sysex));

snd_rawmidi_kernel_write() is prototyped as const unsigned char *buf, so perhaps...
const unsigned char buf[] = ...;?
(static const probably not so useful
e.g. since static const may be rather prone to cache misses)

Though personally I do favour u8, since "char" seems so unsuitably stringy - but the prototype currently doesn't offer it typed that way...

(Almost-)Reviewed-By: Andreas Mohr <[email protected]>

Andreas Mohr