ES938 support for ES18xx driver
PATCH 1/1 ES938 support for ES18xx driver
Add support for 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 code opens/closes the MIDI device everytime a mixer control value is changed so userspace apps can still use the MIDI port. Changing the mixer controls will fail when the MIDI port is open by an application.
--- 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 deletion(-) create mode 100644 sound/isa/es938.c create mode 100644 sound/isa/es938.h
sound/isa/Kconfig +4 -0
@@ -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
@@ -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
@@ -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;
@@ -2167,7 +2169,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
@@ -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
Hi,
sound/isa/es18xx.c static int snd_audiodrive_probe(struct snd_card *card, int dev) · line 2176
Quoted 6 lines · Ondrej Zary
sound/isa/es18xx.c +5
-1-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 )
Should probably add comment here, like:
/* Since ES938 support is an optional component,
we choose to not take into account its failure result codes as reason for fatal abort of soundcard registration. */
sound/isa/es18xx.c static int snd_audiodrive_probe(struct snd_card *card, int dev) · line 2180
Quoted 4 lines
sound/isa/es18xx.c +3
-0+snd_es938_init (&chip->es938, card,0 ,0 ); + +return 0 ; }
OTOH completely ignoring es938 result might be undesirable,
thus it could be suitable to at least add announcing failure via a dev_warn() in addition to the comment.
sound/isa/es938.c line 41
Quoted 9 lines
sound/isa/es938.c new file +9
-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));
long snd_rawmidi_kernel_write(struct snd_rawmidi_substream *substream,
const unsigned char *buf, long count);
--> constify sysex!
Also, there is a "unsigned char" vs. "u8" type ""violation"".
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 ; + }
Could we somehow manage to get rid of basing the calculation on jiffies? AFAIK the kernel is strongly steering away from jiffies-based calculation (normalizing things on ktime instead, AFAIK, or seconds-based), for hopefully good reasons...
(ktime is an abstract, future-proof "kernel time",
and "msecs" is an obvious human-parseable unit,
whereas jiffies is a rather hardware-specific and ugly thingy).
sound/isa/es938.c line 59
Quoted 7 lines
sound/isa/es938.c new file +7
-0+ +/* check reply */ +if (memcmp (buf, sysex,6 ) || buf[7 ] !=MIDI_CMD_COMMON_SYSEX_END ) +return -1 ; + +if (out) + *out = buf[6 ];
A wee bit too many literals here for my taste...
(but it's not an overly clear-cut case of a simple direct sizeof(x) replacement OTOH, so I'm still left wondering)
sound/isa/es938.c line 67
Quoted 8 lines
sound/isa/es938.c new file +8
-0+ +return 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 };
See case above.
Quoted 1 line
+static const
DECLARE_TLV_DB_SCALE(db_scale_tone, -900, 300, 0);
Yup, I also wanted to make use of TLV controls in my driver - good to see that you're doing that already :)
Quoted 10 lines
sound/isa/es938.c new file +10
-0+ +static struct snd_kcontrol_new snd_es938_controls[] = { +ES938_MIXER_TLV ("Tone Control - Bass" ,0 ,ES938_REG_TONE ,0 ,7 , db_scale_tone), +ES938_MIXER_TLV ("Tone Control - Treble" ,0 ,ES938_REG_TONE ,4 ,7 , db_scale_tone), +ES938_MIXER ("3D Control - Level" ,0 ,ES938_REG_SPATIAL ,1 ,63 ), +ES938_MIXER ("3D Control - Switch" ,0 ,ES938_REG_SPATIAL_EN ,0 ,1 ), +}; + +int snd_es938_init (struct snd_es938 *chip,struct snd_card *card,int device, +int subdevice)
sound/isa/es938.c line 107
Quoted 10 lines
sound/isa/es938.c new file +10
-0+{ +int ret, i; + + ret =snd_rawmidi_kernel_open (card, device, subdevice, +SNDRV_RAWMIDI_LFLG_OPEN |SNDRV_RAWMIDI_LFLG_APPEND , + &chip->rfile); +if (ret <0 ) { +snd_printk (KERN_WARNING "es938: unable to open MIDI device\n" ); +return ret; + }
I've been told the Fashionable Logger API Of The Week is dev_warn(), since it's providing proper implicitly dev context decorated logging, thus changing all affected code might be useful.
OTOH prior code happens to be making use of snd_printk currently, so there should be an earlier commit to first convert existing parts to new API, and then have your ES938 commit, doing a dev_warn();
or simply have some resignation and do add this line as snd_printk(), too ;) (for a later commit to then change everything to dev_warn())
Thanks for such an interesting addition,
Andreas Mohr
Signature · 1 line
GNU/Linux. It's not the software that's free, it's you.