From alsa-devel-owner@alsa.jcu.cz  Wed Jan 20 20:48:07 1999
Received: from suncom.rz.hu-berlin.de (suncom.rz.hu-berlin.de [141.20.1.31])
	by marvin.jcu.cz (8.9.1a/8.9.1) with ESMTP id UAA15842
	for <alsa-devel@alsa.jcu.cz>; Wed, 20 Jan 1999 20:48:01 +0100
Received: from mathematik.hu-berlin.de (ppp198-13.rz.hu-berlin.de [141.20.198.13])
	by suncom.rz.hu-berlin.de (8.8.8/8.8.8) with ESMTP id UAA17240
	for <alsa-devel@alsa.jcu.cz>; Wed, 20 Jan 1999 20:47:55 +0100 (MET)
Message-ID: <36A63407.57FFB4F5@mathematik.hu-berlin.de>
Date: Wed, 20 Jan 1999 20:52:39 +0100
From: Lex Teba <elte@mathematik.hu-berlin.de>
MIME-Version: 1.0
To: alsa-devel@alsa.jcu.cz
Subject: CMI8330
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: 8bit
Reply-To: alsa-devel@alsa.jcu.cz
Sender: alsa-devel-owner@alsa.jcu.cz
Precedence: list

Hallo Im not subscribben, so please send any answers back to me.

thanks


( I wanted to write an videophone for linux therefore I need a
full-duplex driver with one mixer!)

so thats the deal:

Subject: 
        cmi8330
   Date: 
        Thu, 14 Jan 1999 13:31:54 +0100
   From: 
        Lex Teba <elte@mathematik.hu-berlin.de>
     To: 
        Jaroslav Kysela <perex@jcu.cz>




Hallo Jaroslav,

some weeks ago, I wrote to you about my cmi8330 sound chip on board.
Because it is a very cheap and often selled chip (I know from some news
groups) it would be very good you to include support for the chip in
your driver project. I now know, that it is realy Windows (Microdoft )
Sound System and SB 16 (4.13) compatible. That's why it is a good full
duplex sound chip. Maybe you'll get anough information from the oss-free
sound driver included in the 2.0.x kernels about the WSS. Then you only
have to realize the, I think 6, different Register, which differ from
the WSS to CMI8330. The C-Media offers a PDF file with the nessesary
Information.

For some more ideas I sent a small file, which explanes itselfs.

#################################################################

Here it is.  Try it out and let me know of any problems.  It's pretty
much
straight from my notes, so changes and further acknowledgements will be
added.

**********

CMI8330 Mini-HOWTO
Version 0.01
Author: Ken McCord (ken.mccord@usa.net)


This Mini-HOWTO explains how to configure sound from motherboards
containing
the CMI8330 chip set.


Disclaimer:

This Mini-HOWTO is an outline of what I needed to do to add sound to my
system.  I assume no responsibility for any damage that may occur from
following the instructions.  Use it at your own risk.


Background:

This Mini-HOWTO was tested on a PC Chips M571 with the CMI8330 chipset. 
The
following peripherals were attached to the system at the time of
testing:

Linksys Ether16 NE2000 clone - set to io=0x300 and irq=3
Western Digital Caviar 2540 IDE Hard Drive as Primary IDE Master
Digital Research (Jamicon) ATAPI 32x CD-Rom as Primary IDE Slave
Sanyo 3.5" floppy drive as Primary floppy
32 MB SDRAM


I. Check BIOS and Verify Sound Card Settings

This section *may* be optional.  I have included it for completeness
(and
it's alway good to have a driver disk nearly).

Reboot your computer and go into the BIOS setup.  Make sure the 'Onboard
Sound' is enabled.  Save and exit.

Create a driver disk from the installation CD-Rom that came with your
motherboard.

If you do not have the CD-Rom (or may want to use an updated version),
you
can download the driver from
http://www.cmedia.com.tw/e_snd_drv.htm#released-drivers.  I used the
file
V4100132.EXE.  This file includes DOS, Win 3.x and Win 95 drivers.  We
will
only need to use the DOS drivers.  Download the file and extract to a
temporary directory.  Create a bootable floppy disk to which the DOS
files
will be installed.  Run the Install program from the temporary
directory.
At the installation screen, for the DOS drivers, use the path 'A:\DOS',
and
leave the Windows path blank.  Please note that after installation is
completed, the program will add three lines to your C:\AUTOEXEC.BAT. 
You
will want to remove these lines.

Reboot the system, using the floppy disk just created.  At the DOS
prompt,
type 'A:\DOS\CMINIT' and press <ENTER>.  Jot down the settings shown on
the
screen.  These are the settings on my card:

WSS BASE I/O ADDRESS  530
WSS IRQ CHANNEL  IRQ 11
WSS DMA CHANNEL  DMA 0
VOICE I/O ADDRESS  220
VOICE IRQ CHANNEL  IRQ 5
VOICE DMA CHANNEL  DMA 1
VOICE 16 BIT DMA CHANNEL DMA 5
MPU-401 MIDI DEVICE  DISABLE
MPU-401 I/O ADDRESS  330
MPU-401 IRQ CHANNEL  IRQ 9
GAME PORT I/O ADDRESS  DISABLE
FM(OPL3) I/O ADDRESS  DISABLE

Press <ESC> and select 'save settings and exit'.

At the DOS prompt, type 'A:\DOS\CMTEST' and press <ENTER>.  Press
<ENTER> as
necessary to scan for settings.  Select 'output voice' and press <ENTER>
to
test for sound output.  Repeat for 'output music'.  If all is working
well,
then we're ready to set up Linux!  Press <ESC> to exit.


II. Recompile Linux kernel for sound.

Reboot into (or Install) your favorite Linux distribution.  For this
Mini-HOWTO, I'm using RedHat 5.2 with kernel 2.0.36.  Your settings may
be
different with another distribution or kernel version.  Make sure your
system has the 'isapnptools' package.  Information about this package
can be
found at http://www.roestock.demon.co.uk/isapnptools.

Recompile the kernel. For the section dealing with sound, I selected the
following options as 'M'odules (everything else in the section as 'N'o):

Sound Card Support
OSS Sound Modules (new for 2.0.36??)
100% Sound Blaster compatibles
Generic OPL2/OPL3 FM synthesizer support
MPU-401 support
Microsoft Sound System

Reboot the system.


III. Configure /etc/isapnp.conf

At a bash prompt, type 'pnpdump > /etc/isapnp.conf'.

Modify the '/etc/isapnp.conf' file as necessary.  My file is as follows:

#
# CMI8330 /etc/isapnp.conf configuration file
#
(READPORT 0x0203)
(ISOLATE PRESERVE)
(IDENTIFY *)
#
# Windows Sound System Configuration
#
(CONFIGURE CMI0001/16777472 (LD 0
(IO 0 (BASE 0x0530))
(IO 1 (BASE 0x0388))
(INT 0 (IRQ 11 (MODE +E)))
(DMA 0 (CHANNEL 0))
(ACT Y)
))
#
# MPU-401 Midi Configuration
#
(CONFIGURE CMI0001/16777472 (LD 1
(IO 0 (BASE 0x0330))
(INT 0 (IRQ 9 (MODE +E)))
(ACT Y)
))
#
# Soundblaster 16 Configuration
#
(CONFIGURE CMI0001/16777472 (LD 3
(IO 0 (BASE 0x0220))
(INT 0 (IRQ 5 (MODE +E)))
(DMA 0 (CHANNEL 1))
(DMA 1 (CHANNEL 5))
(ACT Y)
))
(WAITFORKEY)

Compare these settings and those in section I to what you found.  Save
and
exit.


IV. Modify /etc/conf.modules

Add the following lines to /etc/conf.modules:

alias sound sb
alias midi opl3
options opl3 io=0x388
options sb io=0x220 irq=5 dma=1 dma16=5 mpu_io=0x330
options ad1848 io=0x530 irq=11 dma=0,0

Save and exit.


V. Compile the program fixcmi.c

Compile the program fixcmi.c listed below.  Please note the author's
(Luiz
Mendes) comments.

/***************************************************************/
/*                                                             */
/* Program name: fixcmi.c                                      */
/*                                                             */
/* Simple program to adjust the analog CD-in right and left    */
/* channels of the CMI8330 sound chip                          */
/*                                                             */
/* Author: Luiz T. S. Mendes (luizt@fisica.ufmg.br)            */
/*                                                             */
/* Version: 1.0                Date: Nov 23, 1998              */
/*                                                             */
/* DISCLAIMER: This software is provided as it is and comes    */
/*             with absolutely NO WARRANTY . Use it at your    */
/*             own risk.                                       */
/*                                                             */
/* NOTES: (1) This program is meant for the people who already */
/*            have their CMI8330-based sound cards working     */
/*            (except for playing audio CDs, of course). This  */
/*            means that the following two steps should have   */
/*            already succeeded on your linux box:             */
/*                                                             */
/*            - installing the proper Linux sound driver;      */
/*            - configuring the CMI8330 sound chip by means    */
/*              of the isapnptools (see the Web site at        */
/*              http://www.roestock.demon.co.uk/isapnptools/). */
/*              In this configuration the WSS logical device   */
/*              (logical device 0 in the CMI8330) MUST be      */
/*              included, even if the sound card is to be used */
/*              in the SoundBlaster mode.                      */
/*                                                             */
/*            These steps are fairly documented in the Linux   */
/*            HOWTOs and in the above isapnptools WWW site.    */
/*                                                             */
/*        (2) This program have been tested ONLY in my Linux   */
/*            box (Slackware 3.5, kernel 2.0.34). Though it    */
/*            should work in other configurations, there is    */
/*            no way to guarantee that.                        */
/*                                                             */
/*                                                             */
/* INSTRUCTIONS:                                               */
/*                                                             */
/* 1. Change the definition WSS_BASE to match the CMI8330 WSS  */
/*    I/O base address specified in your /etc/isapnp.conf      */
/*                                                             */
/* 2. Save the file and compile it with                        */
/*                                                             */
/*            $ gcc -o fixcmi -O fixcmi.c                      */
/*                                                             */
/*    (CAUTION: the -O option is MANDATORY)                    */
/*                                                             */
/* 3. You must be logged in as root to run the program, or     */
/*    SETUID it as root:                                       */
/*                                                             */
/*            # chmod +s fixcmi                                */
/*                                                             */
/* 4. Run it _after_ configuring the chip by the isapnp        */
/*    command.                                                 */
/*                                                             */
/***************************************************************/

#include <stdio.h>
#include <asm/io.h>
#include <unistd.h>

/* Some definitions, most related to the I/O addressing */

#define  WSS_BASE                0x530     /* or whatever */

#define  CMI8330_WSS_BASE        WSS_BASE+4
#define  CMI8330_WSS_INDEX_ADDR  CMI8330_WSS_BASE
#define  CMI8330_WSS_INDEX_REG   CMI8330_WSS_BASE+1
#define  CMI8330_WSS_STATUS_REG  CMI8330_WSS_BASE+2
#define  CMI8330_EXT_REG1        0x0C
#define  CMI8330_EXT_REG2        0x11
#define  ENABLE_EXT_REGS         0x40
#define  CDROM_ON                0x06

main()
{

  short int tmp;
  int status;

/* Set the required I/O privilege level for accessing the I/O ports. */

  status=iopl(3);
  if (status != 0) {
      perror("FIXCMI: IOPL() Error\n");
      exit(1);
      }

/* Check the CMI8330 WSS register locations */

  if (inb(CMI8330_WSS_STATUS_REG) != 0xCC) {
    printf("FIXCMI: Invalid WSS I/O address\n");
    exit(1);
    }


/* Now set the required bits for turning on the audio CD left and */
/* right channels                                                 */

  outb(CMI8330_EXT_REG1, CMI8330_WSS_INDEX_ADDR);
  outb(ENABLE_EXT_REGS,  CMI8330_WSS_INDEX_REG);

  outb(CMI8330_EXT_REG2, CMI8330_WSS_INDEX_ADDR);
  tmp = inb(CMI8330_WSS_INDEX_REG) | CDROM_ON;
  outb(tmp, CMI8330_WSS_INDEX_REG);

}


VI. Test the system.

Reboot the system.

If your system's startup does not automatically run 'isapnp
/etc/isapnp.conf' and 'insmod sound', type in each line and press
<ENTER>
(Note that RedHat 5.2 includes these lines in '/etc/rc.d/rc.sysinit').

Run the program 'fixcmi'.

Type 'cat /boot/vmlinuz > /dev/audio' and press <ENTER>.  You should get
output from your speakers.  Press <Control>+<C> to stop.

Place your favorite CD in the CD-Rom.

>From a command line, run 'cdplay' (or from X, run 'xplaycd' and press
start).  You should now hear music coming from the speakers.

If everything is working, edit '/etc/rc.d/rc.local' and place a call to
'fixcmi' in it so the file is loaded upon startup.  Save the file and
exit.


VII. Acknowledgements

I'd like to thank Luiz Mendes for the program 'fixcmi', for which this
mini
how-to would not be possible.

#################################################

I only wanted to have a good driver with only one mixer device for both
channels.

Thank You for your intiative

Lex



answer:

On Thu, 14 Jan 1999, Lex Teba wrote:

> Hallo Jaroslav,
> 
> some weeks ago, I wrote to you about my cmi8330 sound chip on board.
> Because it is a very cheap and often selled chip (I know from some news
> groups) it would be very good you to include support for the chip in
> your driver project. I now know, that it is realy Windows (Microdoft )
> Sound System and SB 16 (4.13) compatible. That's why it is a good full
> duplex sound chip. Maybe you'll get anough information from the oss-free
> sound driver included in the 2.0.x kernels about the WSS. Then you only
> have to realize the, I think 6, different Register, which differ from
> the WSS to CMI8330. The C-Media offers a PDF file with the nessesary
> Information.

OK. Maybe if I get some free time, I'll try do some driver for CMI..
Or you can ask alsa-devel mailing list if someone is working or will
work
on driver.

                                                        Jaroslav

-----
Jaroslav Kysela <perex@jcu.cz>
Academic Computer Centre, University of South Bohemia
Branisovska 31, C. Budejovice, CZ-370 05 Czech Republic

Any requests?

Thanx
Lex

