xref: /kernel/linux/linux-5.10/sound/isa/cmi8330.c (revision 8c2ecf20)
18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-or-later
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci *  Driver for C-Media's CMI8330 and CMI8329 soundcards.
48c2ecf20Sopenharmony_ci *  Copyright (c) by George Talusan <gstalusan@uwaterloo.ca>
58c2ecf20Sopenharmony_ci *    http://www.undergrad.math.uwaterloo.ca/~gstalusa
68c2ecf20Sopenharmony_ci */
78c2ecf20Sopenharmony_ci
88c2ecf20Sopenharmony_ci/*
98c2ecf20Sopenharmony_ci * NOTES
108c2ecf20Sopenharmony_ci *
118c2ecf20Sopenharmony_ci *  The extended registers contain mixer settings which are largely
128c2ecf20Sopenharmony_ci *  untapped for the time being.
138c2ecf20Sopenharmony_ci *
148c2ecf20Sopenharmony_ci *  MPU401 and SPDIF are not supported yet.  I don't have the hardware
158c2ecf20Sopenharmony_ci *  to aid in coding and testing, so I won't bother.
168c2ecf20Sopenharmony_ci *
178c2ecf20Sopenharmony_ci *  To quickly load the module,
188c2ecf20Sopenharmony_ci *
198c2ecf20Sopenharmony_ci *  modprobe -a snd-cmi8330 sbport=0x220 sbirq=5 sbdma8=1
208c2ecf20Sopenharmony_ci *    sbdma16=5 wssport=0x530 wssirq=11 wssdma=0 fmport=0x388
218c2ecf20Sopenharmony_ci *
228c2ecf20Sopenharmony_ci *  This card has two mixers and two PCM devices.  I've cheesed it such
238c2ecf20Sopenharmony_ci *  that recording and playback can be done through the same device.
248c2ecf20Sopenharmony_ci *  The driver "magically" routes the capturing to the AD1848 codec,
258c2ecf20Sopenharmony_ci *  and playback to the SB16 codec.  This allows for full-duplex mode
268c2ecf20Sopenharmony_ci *  to some extent.
278c2ecf20Sopenharmony_ci *  The utilities in alsa-utils are aware of both devices, so passing
288c2ecf20Sopenharmony_ci *  the appropriate parameters to amixer and alsactl will give you
298c2ecf20Sopenharmony_ci *  full control over both mixers.
308c2ecf20Sopenharmony_ci */
318c2ecf20Sopenharmony_ci
328c2ecf20Sopenharmony_ci#include <linux/init.h>
338c2ecf20Sopenharmony_ci#include <linux/err.h>
348c2ecf20Sopenharmony_ci#include <linux/isa.h>
358c2ecf20Sopenharmony_ci#include <linux/pnp.h>
368c2ecf20Sopenharmony_ci#include <linux/module.h>
378c2ecf20Sopenharmony_ci#include <sound/core.h>
388c2ecf20Sopenharmony_ci#include <sound/wss.h>
398c2ecf20Sopenharmony_ci#include <sound/opl3.h>
408c2ecf20Sopenharmony_ci#include <sound/mpu401.h>
418c2ecf20Sopenharmony_ci#include <sound/sb.h>
428c2ecf20Sopenharmony_ci#include <sound/initval.h>
438c2ecf20Sopenharmony_ci
448c2ecf20Sopenharmony_ci/*
458c2ecf20Sopenharmony_ci */
468c2ecf20Sopenharmony_ci/* #define ENABLE_SB_MIXER */
478c2ecf20Sopenharmony_ci#define PLAYBACK_ON_SB
488c2ecf20Sopenharmony_ci
498c2ecf20Sopenharmony_ci/*
508c2ecf20Sopenharmony_ci */
518c2ecf20Sopenharmony_ciMODULE_AUTHOR("George Talusan <gstalusan@uwaterloo.ca>");
528c2ecf20Sopenharmony_ciMODULE_DESCRIPTION("C-Media CMI8330/CMI8329");
538c2ecf20Sopenharmony_ciMODULE_LICENSE("GPL");
548c2ecf20Sopenharmony_ciMODULE_SUPPORTED_DEVICE("{{C-Media,CMI8330,isapnp:{CMI0001,@@@0001,@X@0001}}}");
558c2ecf20Sopenharmony_ci
568c2ecf20Sopenharmony_cistatic int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX;
578c2ecf20Sopenharmony_cistatic char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR;
588c2ecf20Sopenharmony_cistatic bool enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_ISAPNP;
598c2ecf20Sopenharmony_ci#ifdef CONFIG_PNP
608c2ecf20Sopenharmony_cistatic bool isapnp[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 1};
618c2ecf20Sopenharmony_ci#endif
628c2ecf20Sopenharmony_cistatic long sbport[SNDRV_CARDS] = SNDRV_DEFAULT_PORT;
638c2ecf20Sopenharmony_cistatic int sbirq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ;
648c2ecf20Sopenharmony_cistatic int sbdma8[SNDRV_CARDS] = SNDRV_DEFAULT_DMA;
658c2ecf20Sopenharmony_cistatic int sbdma16[SNDRV_CARDS] = SNDRV_DEFAULT_DMA;
668c2ecf20Sopenharmony_cistatic long wssport[SNDRV_CARDS] = SNDRV_DEFAULT_PORT;
678c2ecf20Sopenharmony_cistatic int wssirq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ;
688c2ecf20Sopenharmony_cistatic int wssdma[SNDRV_CARDS] = SNDRV_DEFAULT_DMA;
698c2ecf20Sopenharmony_cistatic long fmport[SNDRV_CARDS] = SNDRV_DEFAULT_PORT;
708c2ecf20Sopenharmony_cistatic long mpuport[SNDRV_CARDS] = SNDRV_DEFAULT_PORT;
718c2ecf20Sopenharmony_cistatic int mpuirq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ;
728c2ecf20Sopenharmony_ci
738c2ecf20Sopenharmony_cimodule_param_array(index, int, NULL, 0444);
748c2ecf20Sopenharmony_ciMODULE_PARM_DESC(index, "Index value for CMI8330/CMI8329 soundcard.");
758c2ecf20Sopenharmony_cimodule_param_array(id, charp, NULL, 0444);
768c2ecf20Sopenharmony_ciMODULE_PARM_DESC(id, "ID string  for CMI8330/CMI8329 soundcard.");
778c2ecf20Sopenharmony_cimodule_param_array(enable, bool, NULL, 0444);
788c2ecf20Sopenharmony_ciMODULE_PARM_DESC(enable, "Enable CMI8330/CMI8329 soundcard.");
798c2ecf20Sopenharmony_ci#ifdef CONFIG_PNP
808c2ecf20Sopenharmony_cimodule_param_array(isapnp, bool, NULL, 0444);
818c2ecf20Sopenharmony_ciMODULE_PARM_DESC(isapnp, "PnP detection for specified soundcard.");
828c2ecf20Sopenharmony_ci#endif
838c2ecf20Sopenharmony_ci
848c2ecf20Sopenharmony_cimodule_param_hw_array(sbport, long, ioport, NULL, 0444);
858c2ecf20Sopenharmony_ciMODULE_PARM_DESC(sbport, "Port # for CMI8330/CMI8329 SB driver.");
868c2ecf20Sopenharmony_cimodule_param_hw_array(sbirq, int, irq, NULL, 0444);
878c2ecf20Sopenharmony_ciMODULE_PARM_DESC(sbirq, "IRQ # for CMI8330/CMI8329 SB driver.");
888c2ecf20Sopenharmony_cimodule_param_hw_array(sbdma8, int, dma, NULL, 0444);
898c2ecf20Sopenharmony_ciMODULE_PARM_DESC(sbdma8, "DMA8 for CMI8330/CMI8329 SB driver.");
908c2ecf20Sopenharmony_cimodule_param_hw_array(sbdma16, int, dma, NULL, 0444);
918c2ecf20Sopenharmony_ciMODULE_PARM_DESC(sbdma16, "DMA16 for CMI8330/CMI8329 SB driver.");
928c2ecf20Sopenharmony_ci
938c2ecf20Sopenharmony_cimodule_param_hw_array(wssport, long, ioport, NULL, 0444);
948c2ecf20Sopenharmony_ciMODULE_PARM_DESC(wssport, "Port # for CMI8330/CMI8329 WSS driver.");
958c2ecf20Sopenharmony_cimodule_param_hw_array(wssirq, int, irq, NULL, 0444);
968c2ecf20Sopenharmony_ciMODULE_PARM_DESC(wssirq, "IRQ # for CMI8330/CMI8329 WSS driver.");
978c2ecf20Sopenharmony_cimodule_param_hw_array(wssdma, int, dma, NULL, 0444);
988c2ecf20Sopenharmony_ciMODULE_PARM_DESC(wssdma, "DMA for CMI8330/CMI8329 WSS driver.");
998c2ecf20Sopenharmony_ci
1008c2ecf20Sopenharmony_cimodule_param_hw_array(fmport, long, ioport, NULL, 0444);
1018c2ecf20Sopenharmony_ciMODULE_PARM_DESC(fmport, "FM port # for CMI8330/CMI8329 driver.");
1028c2ecf20Sopenharmony_cimodule_param_hw_array(mpuport, long, ioport, NULL, 0444);
1038c2ecf20Sopenharmony_ciMODULE_PARM_DESC(mpuport, "MPU-401 port # for CMI8330/CMI8329 driver.");
1048c2ecf20Sopenharmony_cimodule_param_hw_array(mpuirq, int, irq, NULL, 0444);
1058c2ecf20Sopenharmony_ciMODULE_PARM_DESC(mpuirq, "IRQ # for CMI8330/CMI8329 MPU-401 port.");
1068c2ecf20Sopenharmony_ci#ifdef CONFIG_PNP
1078c2ecf20Sopenharmony_cistatic int isa_registered;
1088c2ecf20Sopenharmony_cistatic int pnp_registered;
1098c2ecf20Sopenharmony_ci#endif
1108c2ecf20Sopenharmony_ci
1118c2ecf20Sopenharmony_ci#define CMI8330_RMUX3D    16
1128c2ecf20Sopenharmony_ci#define CMI8330_MUTEMUX   17
1138c2ecf20Sopenharmony_ci#define CMI8330_OUTPUTVOL 18
1148c2ecf20Sopenharmony_ci#define CMI8330_MASTVOL   19
1158c2ecf20Sopenharmony_ci#define CMI8330_LINVOL    20
1168c2ecf20Sopenharmony_ci#define CMI8330_CDINVOL   21
1178c2ecf20Sopenharmony_ci#define CMI8330_WAVVOL    22
1188c2ecf20Sopenharmony_ci#define CMI8330_RECMUX    23
1198c2ecf20Sopenharmony_ci#define CMI8330_WAVGAIN   24
1208c2ecf20Sopenharmony_ci#define CMI8330_LINGAIN   25
1218c2ecf20Sopenharmony_ci#define CMI8330_CDINGAIN  26
1228c2ecf20Sopenharmony_ci
1238c2ecf20Sopenharmony_cistatic const unsigned char snd_cmi8330_image[((CMI8330_CDINGAIN)-16) + 1] =
1248c2ecf20Sopenharmony_ci{
1258c2ecf20Sopenharmony_ci	0x40,			/* 16 - recording mux (SB-mixer-enabled) */
1268c2ecf20Sopenharmony_ci#ifdef ENABLE_SB_MIXER
1278c2ecf20Sopenharmony_ci	0x40,			/* 17 - mute mux (Mode2) */
1288c2ecf20Sopenharmony_ci#else
1298c2ecf20Sopenharmony_ci	0x0,			/* 17 - mute mux */
1308c2ecf20Sopenharmony_ci#endif
1318c2ecf20Sopenharmony_ci	0x0,			/* 18 - vol */
1328c2ecf20Sopenharmony_ci	0x0,			/* 19 - master volume */
1338c2ecf20Sopenharmony_ci	0x0,			/* 20 - line-in volume */
1348c2ecf20Sopenharmony_ci	0x0,			/* 21 - cd-in volume */
1358c2ecf20Sopenharmony_ci	0x0,			/* 22 - wave volume */
1368c2ecf20Sopenharmony_ci	0x0,			/* 23 - mute/rec mux */
1378c2ecf20Sopenharmony_ci	0x0,			/* 24 - wave rec gain */
1388c2ecf20Sopenharmony_ci	0x0,			/* 25 - line-in rec gain */
1398c2ecf20Sopenharmony_ci	0x0			/* 26 - cd-in rec gain */
1408c2ecf20Sopenharmony_ci};
1418c2ecf20Sopenharmony_ci
1428c2ecf20Sopenharmony_citypedef int (*snd_pcm_open_callback_t)(struct snd_pcm_substream *);
1438c2ecf20Sopenharmony_ci
1448c2ecf20Sopenharmony_cienum card_type {
1458c2ecf20Sopenharmony_ci	CMI8330,
1468c2ecf20Sopenharmony_ci	CMI8329
1478c2ecf20Sopenharmony_ci};
1488c2ecf20Sopenharmony_ci
1498c2ecf20Sopenharmony_cistruct snd_cmi8330 {
1508c2ecf20Sopenharmony_ci#ifdef CONFIG_PNP
1518c2ecf20Sopenharmony_ci	struct pnp_dev *cap;
1528c2ecf20Sopenharmony_ci	struct pnp_dev *play;
1538c2ecf20Sopenharmony_ci	struct pnp_dev *mpu;
1548c2ecf20Sopenharmony_ci#endif
1558c2ecf20Sopenharmony_ci	struct snd_card *card;
1568c2ecf20Sopenharmony_ci	struct snd_wss *wss;
1578c2ecf20Sopenharmony_ci	struct snd_sb *sb;
1588c2ecf20Sopenharmony_ci
1598c2ecf20Sopenharmony_ci	struct snd_pcm *pcm;
1608c2ecf20Sopenharmony_ci	struct snd_cmi8330_stream {
1618c2ecf20Sopenharmony_ci		struct snd_pcm_ops ops;
1628c2ecf20Sopenharmony_ci		snd_pcm_open_callback_t open;
1638c2ecf20Sopenharmony_ci		void *private_data; /* sb or wss */
1648c2ecf20Sopenharmony_ci	} streams[2];
1658c2ecf20Sopenharmony_ci
1668c2ecf20Sopenharmony_ci	enum card_type type;
1678c2ecf20Sopenharmony_ci};
1688c2ecf20Sopenharmony_ci
1698c2ecf20Sopenharmony_ci#ifdef CONFIG_PNP
1708c2ecf20Sopenharmony_ci
1718c2ecf20Sopenharmony_cistatic const struct pnp_card_device_id snd_cmi8330_pnpids[] = {
1728c2ecf20Sopenharmony_ci	{ .id = "CMI0001", .devs = { { "@X@0001" }, { "@@@0001" }, { "@H@0001" }, { "A@@0001" } } },
1738c2ecf20Sopenharmony_ci	{ .id = "CMI0001", .devs = { { "@@@0001" }, { "@X@0001" }, { "@H@0001" } } },
1748c2ecf20Sopenharmony_ci	{ .id = "" }
1758c2ecf20Sopenharmony_ci};
1768c2ecf20Sopenharmony_ci
1778c2ecf20Sopenharmony_ciMODULE_DEVICE_TABLE(pnp_card, snd_cmi8330_pnpids);
1788c2ecf20Sopenharmony_ci
1798c2ecf20Sopenharmony_ci#endif
1808c2ecf20Sopenharmony_ci
1818c2ecf20Sopenharmony_ci
1828c2ecf20Sopenharmony_cistatic const struct snd_kcontrol_new snd_cmi8330_controls[] = {
1838c2ecf20Sopenharmony_ciWSS_DOUBLE("Master Playback Volume", 0,
1848c2ecf20Sopenharmony_ci		CMI8330_MASTVOL, CMI8330_MASTVOL, 4, 0, 15, 0),
1858c2ecf20Sopenharmony_ciWSS_SINGLE("Loud Playback Switch", 0,
1868c2ecf20Sopenharmony_ci		CMI8330_MUTEMUX, 6, 1, 1),
1878c2ecf20Sopenharmony_ciWSS_DOUBLE("PCM Playback Switch", 0,
1888c2ecf20Sopenharmony_ci		CS4231_LEFT_OUTPUT, CS4231_RIGHT_OUTPUT, 7, 7, 1, 1),
1898c2ecf20Sopenharmony_ciWSS_DOUBLE("PCM Playback Volume", 0,
1908c2ecf20Sopenharmony_ci		CS4231_LEFT_OUTPUT, CS4231_RIGHT_OUTPUT, 0, 0, 63, 1),
1918c2ecf20Sopenharmony_ciWSS_DOUBLE("Line Playback Switch", 0,
1928c2ecf20Sopenharmony_ci		CMI8330_MUTEMUX, CMI8330_MUTEMUX, 4, 3, 1, 0),
1938c2ecf20Sopenharmony_ciWSS_DOUBLE("Line Playback Volume", 0,
1948c2ecf20Sopenharmony_ci		CMI8330_LINVOL, CMI8330_LINVOL, 4, 0, 15, 0),
1958c2ecf20Sopenharmony_ciWSS_DOUBLE("Line Capture Switch", 0,
1968c2ecf20Sopenharmony_ci		CMI8330_RMUX3D, CMI8330_RMUX3D, 2, 1, 1, 0),
1978c2ecf20Sopenharmony_ciWSS_DOUBLE("Line Capture Volume", 0,
1988c2ecf20Sopenharmony_ci		CMI8330_LINGAIN, CMI8330_LINGAIN, 4, 0, 15, 0),
1998c2ecf20Sopenharmony_ciWSS_DOUBLE("CD Playback Switch", 0,
2008c2ecf20Sopenharmony_ci		CMI8330_MUTEMUX, CMI8330_MUTEMUX, 2, 1, 1, 0),
2018c2ecf20Sopenharmony_ciWSS_DOUBLE("CD Capture Switch", 0,
2028c2ecf20Sopenharmony_ci		CMI8330_RMUX3D, CMI8330_RMUX3D, 4, 3, 1, 0),
2038c2ecf20Sopenharmony_ciWSS_DOUBLE("CD Playback Volume", 0,
2048c2ecf20Sopenharmony_ci		CMI8330_CDINVOL, CMI8330_CDINVOL, 4, 0, 15, 0),
2058c2ecf20Sopenharmony_ciWSS_DOUBLE("CD Capture Volume", 0,
2068c2ecf20Sopenharmony_ci		CMI8330_CDINGAIN, CMI8330_CDINGAIN, 4, 0, 15, 0),
2078c2ecf20Sopenharmony_ciWSS_SINGLE("Mic Playback Switch", 0,
2088c2ecf20Sopenharmony_ci		CMI8330_MUTEMUX, 0, 1, 0),
2098c2ecf20Sopenharmony_ciWSS_SINGLE("Mic Playback Volume", 0,
2108c2ecf20Sopenharmony_ci		CMI8330_OUTPUTVOL, 0, 7, 0),
2118c2ecf20Sopenharmony_ciWSS_SINGLE("Mic Capture Switch", 0,
2128c2ecf20Sopenharmony_ci		CMI8330_RMUX3D, 0, 1, 0),
2138c2ecf20Sopenharmony_ciWSS_SINGLE("Mic Capture Volume", 0,
2148c2ecf20Sopenharmony_ci		CMI8330_OUTPUTVOL, 5, 7, 0),
2158c2ecf20Sopenharmony_ciWSS_DOUBLE("Wavetable Playback Switch", 0,
2168c2ecf20Sopenharmony_ci		CMI8330_RECMUX, CMI8330_RECMUX, 1, 0, 1, 0),
2178c2ecf20Sopenharmony_ciWSS_DOUBLE("Wavetable Playback Volume", 0,
2188c2ecf20Sopenharmony_ci		CMI8330_WAVVOL, CMI8330_WAVVOL, 4, 0, 15, 0),
2198c2ecf20Sopenharmony_ciWSS_DOUBLE("Wavetable Capture Switch", 0,
2208c2ecf20Sopenharmony_ci		CMI8330_RECMUX, CMI8330_RECMUX, 5, 4, 1, 0),
2218c2ecf20Sopenharmony_ciWSS_DOUBLE("Wavetable Capture Volume", 0,
2228c2ecf20Sopenharmony_ci		CMI8330_WAVGAIN, CMI8330_WAVGAIN, 4, 0, 15, 0),
2238c2ecf20Sopenharmony_ciWSS_SINGLE("3D Control - Switch", 0,
2248c2ecf20Sopenharmony_ci		CMI8330_RMUX3D, 5, 1, 1),
2258c2ecf20Sopenharmony_ciWSS_SINGLE("Beep Playback Volume", 0,
2268c2ecf20Sopenharmony_ci		CMI8330_OUTPUTVOL, 3, 3, 0),
2278c2ecf20Sopenharmony_ciWSS_DOUBLE("FM Playback Switch", 0,
2288c2ecf20Sopenharmony_ci		CS4231_AUX2_LEFT_INPUT, CS4231_AUX2_RIGHT_INPUT, 7, 7, 1, 1),
2298c2ecf20Sopenharmony_ciWSS_DOUBLE("FM Playback Volume", 0,
2308c2ecf20Sopenharmony_ci		CS4231_AUX2_LEFT_INPUT, CS4231_AUX2_RIGHT_INPUT, 0, 0, 31, 1),
2318c2ecf20Sopenharmony_ciWSS_SINGLE(SNDRV_CTL_NAME_IEC958("Input ", CAPTURE, SWITCH), 0,
2328c2ecf20Sopenharmony_ci		CMI8330_RMUX3D, 7, 1, 1),
2338c2ecf20Sopenharmony_ciWSS_SINGLE(SNDRV_CTL_NAME_IEC958("Input ", PLAYBACK, SWITCH), 0,
2348c2ecf20Sopenharmony_ci		CMI8330_MUTEMUX, 7, 1, 1),
2358c2ecf20Sopenharmony_ci};
2368c2ecf20Sopenharmony_ci
2378c2ecf20Sopenharmony_ci#ifdef ENABLE_SB_MIXER
2388c2ecf20Sopenharmony_cistatic const struct sbmix_elem cmi8330_sb_mixers[] = {
2398c2ecf20Sopenharmony_ciSB_DOUBLE("SB Master Playback Volume", SB_DSP4_MASTER_DEV, (SB_DSP4_MASTER_DEV + 1), 3, 3, 31),
2408c2ecf20Sopenharmony_ciSB_DOUBLE("Tone Control - Bass", SB_DSP4_BASS_DEV, (SB_DSP4_BASS_DEV + 1), 4, 4, 15),
2418c2ecf20Sopenharmony_ciSB_DOUBLE("Tone Control - Treble", SB_DSP4_TREBLE_DEV, (SB_DSP4_TREBLE_DEV + 1), 4, 4, 15),
2428c2ecf20Sopenharmony_ciSB_DOUBLE("SB PCM Playback Volume", SB_DSP4_PCM_DEV, (SB_DSP4_PCM_DEV + 1), 3, 3, 31),
2438c2ecf20Sopenharmony_ciSB_DOUBLE("SB Synth Playback Volume", SB_DSP4_SYNTH_DEV, (SB_DSP4_SYNTH_DEV + 1), 3, 3, 31),
2448c2ecf20Sopenharmony_ciSB_DOUBLE("SB CD Playback Switch", SB_DSP4_OUTPUT_SW, SB_DSP4_OUTPUT_SW, 2, 1, 1),
2458c2ecf20Sopenharmony_ciSB_DOUBLE("SB CD Playback Volume", SB_DSP4_CD_DEV, (SB_DSP4_CD_DEV + 1), 3, 3, 31),
2468c2ecf20Sopenharmony_ciSB_DOUBLE("SB Line Playback Switch", SB_DSP4_OUTPUT_SW, SB_DSP4_OUTPUT_SW, 4, 3, 1),
2478c2ecf20Sopenharmony_ciSB_DOUBLE("SB Line Playback Volume", SB_DSP4_LINE_DEV, (SB_DSP4_LINE_DEV + 1), 3, 3, 31),
2488c2ecf20Sopenharmony_ciSB_SINGLE("SB Mic Playback Switch", SB_DSP4_OUTPUT_SW, 0, 1),
2498c2ecf20Sopenharmony_ciSB_SINGLE("SB Mic Playback Volume", SB_DSP4_MIC_DEV, 3, 31),
2508c2ecf20Sopenharmony_ciSB_SINGLE("SB Beep Volume", SB_DSP4_SPEAKER_DEV, 6, 3),
2518c2ecf20Sopenharmony_ciSB_DOUBLE("SB Capture Volume", SB_DSP4_IGAIN_DEV, (SB_DSP4_IGAIN_DEV + 1), 6, 6, 3),
2528c2ecf20Sopenharmony_ciSB_DOUBLE("SB Playback Volume", SB_DSP4_OGAIN_DEV, (SB_DSP4_OGAIN_DEV + 1), 6, 6, 3),
2538c2ecf20Sopenharmony_ciSB_SINGLE("SB Mic Auto Gain", SB_DSP4_MIC_AGC, 0, 1),
2548c2ecf20Sopenharmony_ci};
2558c2ecf20Sopenharmony_ci
2568c2ecf20Sopenharmony_cistatic const unsigned char cmi8330_sb_init_values[][2] = {
2578c2ecf20Sopenharmony_ci	{ SB_DSP4_MASTER_DEV + 0, 0 },
2588c2ecf20Sopenharmony_ci	{ SB_DSP4_MASTER_DEV + 1, 0 },
2598c2ecf20Sopenharmony_ci	{ SB_DSP4_PCM_DEV + 0, 0 },
2608c2ecf20Sopenharmony_ci	{ SB_DSP4_PCM_DEV + 1, 0 },
2618c2ecf20Sopenharmony_ci	{ SB_DSP4_SYNTH_DEV + 0, 0 },
2628c2ecf20Sopenharmony_ci	{ SB_DSP4_SYNTH_DEV + 1, 0 },
2638c2ecf20Sopenharmony_ci	{ SB_DSP4_INPUT_LEFT, 0 },
2648c2ecf20Sopenharmony_ci	{ SB_DSP4_INPUT_RIGHT, 0 },
2658c2ecf20Sopenharmony_ci	{ SB_DSP4_OUTPUT_SW, 0 },
2668c2ecf20Sopenharmony_ci	{ SB_DSP4_SPEAKER_DEV, 0 },
2678c2ecf20Sopenharmony_ci};
2688c2ecf20Sopenharmony_ci
2698c2ecf20Sopenharmony_ci
2708c2ecf20Sopenharmony_cistatic int cmi8330_add_sb_mixers(struct snd_sb *chip)
2718c2ecf20Sopenharmony_ci{
2728c2ecf20Sopenharmony_ci	int idx, err;
2738c2ecf20Sopenharmony_ci	unsigned long flags;
2748c2ecf20Sopenharmony_ci
2758c2ecf20Sopenharmony_ci	spin_lock_irqsave(&chip->mixer_lock, flags);
2768c2ecf20Sopenharmony_ci	snd_sbmixer_write(chip, 0x00, 0x00);		/* mixer reset */
2778c2ecf20Sopenharmony_ci	spin_unlock_irqrestore(&chip->mixer_lock, flags);
2788c2ecf20Sopenharmony_ci
2798c2ecf20Sopenharmony_ci	/* mute and zero volume channels */
2808c2ecf20Sopenharmony_ci	for (idx = 0; idx < ARRAY_SIZE(cmi8330_sb_init_values); idx++) {
2818c2ecf20Sopenharmony_ci		spin_lock_irqsave(&chip->mixer_lock, flags);
2828c2ecf20Sopenharmony_ci		snd_sbmixer_write(chip, cmi8330_sb_init_values[idx][0],
2838c2ecf20Sopenharmony_ci				  cmi8330_sb_init_values[idx][1]);
2848c2ecf20Sopenharmony_ci		spin_unlock_irqrestore(&chip->mixer_lock, flags);
2858c2ecf20Sopenharmony_ci	}
2868c2ecf20Sopenharmony_ci
2878c2ecf20Sopenharmony_ci	for (idx = 0; idx < ARRAY_SIZE(cmi8330_sb_mixers); idx++) {
2888c2ecf20Sopenharmony_ci		if ((err = snd_sbmixer_add_ctl_elem(chip, &cmi8330_sb_mixers[idx])) < 0)
2898c2ecf20Sopenharmony_ci			return err;
2908c2ecf20Sopenharmony_ci	}
2918c2ecf20Sopenharmony_ci	return 0;
2928c2ecf20Sopenharmony_ci}
2938c2ecf20Sopenharmony_ci#endif
2948c2ecf20Sopenharmony_ci
2958c2ecf20Sopenharmony_cistatic int snd_cmi8330_mixer(struct snd_card *card, struct snd_cmi8330 *acard)
2968c2ecf20Sopenharmony_ci{
2978c2ecf20Sopenharmony_ci	unsigned int idx;
2988c2ecf20Sopenharmony_ci	int err;
2998c2ecf20Sopenharmony_ci
3008c2ecf20Sopenharmony_ci	strcpy(card->mixername, (acard->type == CMI8329) ? "CMI8329" : "CMI8330/C3D");
3018c2ecf20Sopenharmony_ci
3028c2ecf20Sopenharmony_ci	for (idx = 0; idx < ARRAY_SIZE(snd_cmi8330_controls); idx++) {
3038c2ecf20Sopenharmony_ci		err = snd_ctl_add(card,
3048c2ecf20Sopenharmony_ci				snd_ctl_new1(&snd_cmi8330_controls[idx],
3058c2ecf20Sopenharmony_ci					     acard->wss));
3068c2ecf20Sopenharmony_ci		if (err < 0)
3078c2ecf20Sopenharmony_ci			return err;
3088c2ecf20Sopenharmony_ci	}
3098c2ecf20Sopenharmony_ci
3108c2ecf20Sopenharmony_ci#ifdef ENABLE_SB_MIXER
3118c2ecf20Sopenharmony_ci	if ((err = cmi8330_add_sb_mixers(acard->sb)) < 0)
3128c2ecf20Sopenharmony_ci		return err;
3138c2ecf20Sopenharmony_ci#endif
3148c2ecf20Sopenharmony_ci	return 0;
3158c2ecf20Sopenharmony_ci}
3168c2ecf20Sopenharmony_ci
3178c2ecf20Sopenharmony_ci#ifdef CONFIG_PNP
3188c2ecf20Sopenharmony_cistatic int snd_cmi8330_pnp(int dev, struct snd_cmi8330 *acard,
3198c2ecf20Sopenharmony_ci			   struct pnp_card_link *card,
3208c2ecf20Sopenharmony_ci			   const struct pnp_card_device_id *id)
3218c2ecf20Sopenharmony_ci{
3228c2ecf20Sopenharmony_ci	struct pnp_dev *pdev;
3238c2ecf20Sopenharmony_ci	int err;
3248c2ecf20Sopenharmony_ci
3258c2ecf20Sopenharmony_ci	/* CMI8329 has a device with ID A@@0001, CMI8330 does not */
3268c2ecf20Sopenharmony_ci	acard->type = (id->devs[3].id[0]) ? CMI8329 : CMI8330;
3278c2ecf20Sopenharmony_ci
3288c2ecf20Sopenharmony_ci	acard->cap = pnp_request_card_device(card, id->devs[0].id, NULL);
3298c2ecf20Sopenharmony_ci	if (acard->cap == NULL)
3308c2ecf20Sopenharmony_ci		return -EBUSY;
3318c2ecf20Sopenharmony_ci
3328c2ecf20Sopenharmony_ci	acard->play = pnp_request_card_device(card, id->devs[1].id, NULL);
3338c2ecf20Sopenharmony_ci	if (acard->play == NULL)
3348c2ecf20Sopenharmony_ci		return -EBUSY;
3358c2ecf20Sopenharmony_ci
3368c2ecf20Sopenharmony_ci	acard->mpu = pnp_request_card_device(card, id->devs[2].id, NULL);
3378c2ecf20Sopenharmony_ci	if (acard->mpu == NULL)
3388c2ecf20Sopenharmony_ci		return -EBUSY;
3398c2ecf20Sopenharmony_ci
3408c2ecf20Sopenharmony_ci	pdev = acard->cap;
3418c2ecf20Sopenharmony_ci
3428c2ecf20Sopenharmony_ci	err = pnp_activate_dev(pdev);
3438c2ecf20Sopenharmony_ci	if (err < 0) {
3448c2ecf20Sopenharmony_ci		snd_printk(KERN_ERR "AD1848 PnP configure failure\n");
3458c2ecf20Sopenharmony_ci		return -EBUSY;
3468c2ecf20Sopenharmony_ci	}
3478c2ecf20Sopenharmony_ci	wssport[dev] = pnp_port_start(pdev, 0);
3488c2ecf20Sopenharmony_ci	wssdma[dev] = pnp_dma(pdev, 0);
3498c2ecf20Sopenharmony_ci	wssirq[dev] = pnp_irq(pdev, 0);
3508c2ecf20Sopenharmony_ci	if (pnp_port_start(pdev, 1))
3518c2ecf20Sopenharmony_ci		fmport[dev] = pnp_port_start(pdev, 1);
3528c2ecf20Sopenharmony_ci
3538c2ecf20Sopenharmony_ci	/* allocate SB16 resources */
3548c2ecf20Sopenharmony_ci	pdev = acard->play;
3558c2ecf20Sopenharmony_ci
3568c2ecf20Sopenharmony_ci	err = pnp_activate_dev(pdev);
3578c2ecf20Sopenharmony_ci	if (err < 0) {
3588c2ecf20Sopenharmony_ci		snd_printk(KERN_ERR "SB16 PnP configure failure\n");
3598c2ecf20Sopenharmony_ci		return -EBUSY;
3608c2ecf20Sopenharmony_ci	}
3618c2ecf20Sopenharmony_ci	sbport[dev] = pnp_port_start(pdev, 0);
3628c2ecf20Sopenharmony_ci	sbdma8[dev] = pnp_dma(pdev, 0);
3638c2ecf20Sopenharmony_ci	sbdma16[dev] = pnp_dma(pdev, 1);
3648c2ecf20Sopenharmony_ci	sbirq[dev] = pnp_irq(pdev, 0);
3658c2ecf20Sopenharmony_ci	/* On CMI8239, the OPL3 port might be present in SB16 PnP resources */
3668c2ecf20Sopenharmony_ci	if (fmport[dev] == SNDRV_AUTO_PORT) {
3678c2ecf20Sopenharmony_ci		if (pnp_port_start(pdev, 1))
3688c2ecf20Sopenharmony_ci			fmport[dev] = pnp_port_start(pdev, 1);
3698c2ecf20Sopenharmony_ci		else
3708c2ecf20Sopenharmony_ci			fmport[dev] = 0x388;	/* Or hardwired */
3718c2ecf20Sopenharmony_ci	}
3728c2ecf20Sopenharmony_ci
3738c2ecf20Sopenharmony_ci	/* allocate MPU-401 resources */
3748c2ecf20Sopenharmony_ci	pdev = acard->mpu;
3758c2ecf20Sopenharmony_ci
3768c2ecf20Sopenharmony_ci	err = pnp_activate_dev(pdev);
3778c2ecf20Sopenharmony_ci	if (err < 0)
3788c2ecf20Sopenharmony_ci		snd_printk(KERN_ERR "MPU-401 PnP configure failure: will be disabled\n");
3798c2ecf20Sopenharmony_ci	else {
3808c2ecf20Sopenharmony_ci		mpuport[dev] = pnp_port_start(pdev, 0);
3818c2ecf20Sopenharmony_ci		mpuirq[dev] = pnp_irq(pdev, 0);
3828c2ecf20Sopenharmony_ci	}
3838c2ecf20Sopenharmony_ci	return 0;
3848c2ecf20Sopenharmony_ci}
3858c2ecf20Sopenharmony_ci#endif
3868c2ecf20Sopenharmony_ci
3878c2ecf20Sopenharmony_ci/*
3888c2ecf20Sopenharmony_ci * PCM interface
3898c2ecf20Sopenharmony_ci *
3908c2ecf20Sopenharmony_ci * since we call the different chip interfaces for playback and capture
3918c2ecf20Sopenharmony_ci * directions, we need a trick.
3928c2ecf20Sopenharmony_ci *
3938c2ecf20Sopenharmony_ci * - copy the ops for each direction into a local record.
3948c2ecf20Sopenharmony_ci * - replace the open callback with the new one, which replaces the
3958c2ecf20Sopenharmony_ci *   substream->private_data with the corresponding chip instance
3968c2ecf20Sopenharmony_ci *   and calls again the original open callback of the chip.
3978c2ecf20Sopenharmony_ci *
3988c2ecf20Sopenharmony_ci */
3998c2ecf20Sopenharmony_ci
4008c2ecf20Sopenharmony_ci#ifdef PLAYBACK_ON_SB
4018c2ecf20Sopenharmony_ci#define CMI_SB_STREAM	SNDRV_PCM_STREAM_PLAYBACK
4028c2ecf20Sopenharmony_ci#define CMI_AD_STREAM	SNDRV_PCM_STREAM_CAPTURE
4038c2ecf20Sopenharmony_ci#else
4048c2ecf20Sopenharmony_ci#define CMI_SB_STREAM	SNDRV_PCM_STREAM_CAPTURE
4058c2ecf20Sopenharmony_ci#define CMI_AD_STREAM	SNDRV_PCM_STREAM_PLAYBACK
4068c2ecf20Sopenharmony_ci#endif
4078c2ecf20Sopenharmony_ci
4088c2ecf20Sopenharmony_cistatic int snd_cmi8330_playback_open(struct snd_pcm_substream *substream)
4098c2ecf20Sopenharmony_ci{
4108c2ecf20Sopenharmony_ci	struct snd_cmi8330 *chip = snd_pcm_substream_chip(substream);
4118c2ecf20Sopenharmony_ci
4128c2ecf20Sopenharmony_ci	/* replace the private_data and call the original open callback */
4138c2ecf20Sopenharmony_ci	substream->private_data = chip->streams[SNDRV_PCM_STREAM_PLAYBACK].private_data;
4148c2ecf20Sopenharmony_ci	return chip->streams[SNDRV_PCM_STREAM_PLAYBACK].open(substream);
4158c2ecf20Sopenharmony_ci}
4168c2ecf20Sopenharmony_ci
4178c2ecf20Sopenharmony_cistatic int snd_cmi8330_capture_open(struct snd_pcm_substream *substream)
4188c2ecf20Sopenharmony_ci{
4198c2ecf20Sopenharmony_ci	struct snd_cmi8330 *chip = snd_pcm_substream_chip(substream);
4208c2ecf20Sopenharmony_ci
4218c2ecf20Sopenharmony_ci	/* replace the private_data and call the original open callback */
4228c2ecf20Sopenharmony_ci	substream->private_data = chip->streams[SNDRV_PCM_STREAM_CAPTURE].private_data;
4238c2ecf20Sopenharmony_ci	return chip->streams[SNDRV_PCM_STREAM_CAPTURE].open(substream);
4248c2ecf20Sopenharmony_ci}
4258c2ecf20Sopenharmony_ci
4268c2ecf20Sopenharmony_cistatic int snd_cmi8330_pcm(struct snd_card *card, struct snd_cmi8330 *chip)
4278c2ecf20Sopenharmony_ci{
4288c2ecf20Sopenharmony_ci	struct snd_pcm *pcm;
4298c2ecf20Sopenharmony_ci	const struct snd_pcm_ops *ops;
4308c2ecf20Sopenharmony_ci	int err;
4318c2ecf20Sopenharmony_ci	static const snd_pcm_open_callback_t cmi_open_callbacks[2] = {
4328c2ecf20Sopenharmony_ci		snd_cmi8330_playback_open,
4338c2ecf20Sopenharmony_ci		snd_cmi8330_capture_open
4348c2ecf20Sopenharmony_ci	};
4358c2ecf20Sopenharmony_ci
4368c2ecf20Sopenharmony_ci	if ((err = snd_pcm_new(card, (chip->type == CMI8329) ? "CMI8329" : "CMI8330", 0, 1, 1, &pcm)) < 0)
4378c2ecf20Sopenharmony_ci		return err;
4388c2ecf20Sopenharmony_ci	strcpy(pcm->name, (chip->type == CMI8329) ? "CMI8329" : "CMI8330");
4398c2ecf20Sopenharmony_ci	pcm->private_data = chip;
4408c2ecf20Sopenharmony_ci
4418c2ecf20Sopenharmony_ci	/* SB16 */
4428c2ecf20Sopenharmony_ci	ops = snd_sb16dsp_get_pcm_ops(CMI_SB_STREAM);
4438c2ecf20Sopenharmony_ci	chip->streams[CMI_SB_STREAM].ops = *ops;
4448c2ecf20Sopenharmony_ci	chip->streams[CMI_SB_STREAM].open = ops->open;
4458c2ecf20Sopenharmony_ci	chip->streams[CMI_SB_STREAM].ops.open = cmi_open_callbacks[CMI_SB_STREAM];
4468c2ecf20Sopenharmony_ci	chip->streams[CMI_SB_STREAM].private_data = chip->sb;
4478c2ecf20Sopenharmony_ci
4488c2ecf20Sopenharmony_ci	/* AD1848 */
4498c2ecf20Sopenharmony_ci	ops = snd_wss_get_pcm_ops(CMI_AD_STREAM);
4508c2ecf20Sopenharmony_ci	chip->streams[CMI_AD_STREAM].ops = *ops;
4518c2ecf20Sopenharmony_ci	chip->streams[CMI_AD_STREAM].open = ops->open;
4528c2ecf20Sopenharmony_ci	chip->streams[CMI_AD_STREAM].ops.open = cmi_open_callbacks[CMI_AD_STREAM];
4538c2ecf20Sopenharmony_ci	chip->streams[CMI_AD_STREAM].private_data = chip->wss;
4548c2ecf20Sopenharmony_ci
4558c2ecf20Sopenharmony_ci	snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &chip->streams[SNDRV_PCM_STREAM_PLAYBACK].ops);
4568c2ecf20Sopenharmony_ci	snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &chip->streams[SNDRV_PCM_STREAM_CAPTURE].ops);
4578c2ecf20Sopenharmony_ci
4588c2ecf20Sopenharmony_ci	snd_pcm_set_managed_buffer_all(pcm, SNDRV_DMA_TYPE_DEV,
4598c2ecf20Sopenharmony_ci				       card->dev, 64*1024, 128*1024);
4608c2ecf20Sopenharmony_ci	chip->pcm = pcm;
4618c2ecf20Sopenharmony_ci
4628c2ecf20Sopenharmony_ci	return 0;
4638c2ecf20Sopenharmony_ci}
4648c2ecf20Sopenharmony_ci
4658c2ecf20Sopenharmony_ci
4668c2ecf20Sopenharmony_ci#ifdef CONFIG_PM
4678c2ecf20Sopenharmony_cistatic int snd_cmi8330_suspend(struct snd_card *card)
4688c2ecf20Sopenharmony_ci{
4698c2ecf20Sopenharmony_ci	struct snd_cmi8330 *acard = card->private_data;
4708c2ecf20Sopenharmony_ci
4718c2ecf20Sopenharmony_ci	snd_power_change_state(card, SNDRV_CTL_POWER_D3hot);
4728c2ecf20Sopenharmony_ci	acard->wss->suspend(acard->wss);
4738c2ecf20Sopenharmony_ci	snd_sbmixer_suspend(acard->sb);
4748c2ecf20Sopenharmony_ci	return 0;
4758c2ecf20Sopenharmony_ci}
4768c2ecf20Sopenharmony_ci
4778c2ecf20Sopenharmony_cistatic int snd_cmi8330_resume(struct snd_card *card)
4788c2ecf20Sopenharmony_ci{
4798c2ecf20Sopenharmony_ci	struct snd_cmi8330 *acard = card->private_data;
4808c2ecf20Sopenharmony_ci
4818c2ecf20Sopenharmony_ci	snd_sbdsp_reset(acard->sb);
4828c2ecf20Sopenharmony_ci	snd_sbmixer_suspend(acard->sb);
4838c2ecf20Sopenharmony_ci	acard->wss->resume(acard->wss);
4848c2ecf20Sopenharmony_ci	snd_power_change_state(card, SNDRV_CTL_POWER_D0);
4858c2ecf20Sopenharmony_ci	return 0;
4868c2ecf20Sopenharmony_ci}
4878c2ecf20Sopenharmony_ci#endif
4888c2ecf20Sopenharmony_ci
4898c2ecf20Sopenharmony_ci
4908c2ecf20Sopenharmony_ci/*
4918c2ecf20Sopenharmony_ci */
4928c2ecf20Sopenharmony_ci
4938c2ecf20Sopenharmony_ci#ifdef CONFIG_PNP
4948c2ecf20Sopenharmony_ci#define is_isapnp_selected(dev)		isapnp[dev]
4958c2ecf20Sopenharmony_ci#else
4968c2ecf20Sopenharmony_ci#define is_isapnp_selected(dev)		0
4978c2ecf20Sopenharmony_ci#endif
4988c2ecf20Sopenharmony_ci
4998c2ecf20Sopenharmony_ci#define PFX	"cmi8330: "
5008c2ecf20Sopenharmony_ci
5018c2ecf20Sopenharmony_cistatic int snd_cmi8330_card_new(struct device *pdev, int dev,
5028c2ecf20Sopenharmony_ci				struct snd_card **cardp)
5038c2ecf20Sopenharmony_ci{
5048c2ecf20Sopenharmony_ci	struct snd_card *card;
5058c2ecf20Sopenharmony_ci	struct snd_cmi8330 *acard;
5068c2ecf20Sopenharmony_ci	int err;
5078c2ecf20Sopenharmony_ci
5088c2ecf20Sopenharmony_ci	err = snd_card_new(pdev, index[dev], id[dev], THIS_MODULE,
5098c2ecf20Sopenharmony_ci			   sizeof(struct snd_cmi8330), &card);
5108c2ecf20Sopenharmony_ci	if (err < 0) {
5118c2ecf20Sopenharmony_ci		snd_printk(KERN_ERR PFX "could not get a new card\n");
5128c2ecf20Sopenharmony_ci		return err;
5138c2ecf20Sopenharmony_ci	}
5148c2ecf20Sopenharmony_ci	acard = card->private_data;
5158c2ecf20Sopenharmony_ci	acard->card = card;
5168c2ecf20Sopenharmony_ci	*cardp = card;
5178c2ecf20Sopenharmony_ci	return 0;
5188c2ecf20Sopenharmony_ci}
5198c2ecf20Sopenharmony_ci
5208c2ecf20Sopenharmony_cistatic int snd_cmi8330_probe(struct snd_card *card, int dev)
5218c2ecf20Sopenharmony_ci{
5228c2ecf20Sopenharmony_ci	struct snd_cmi8330 *acard;
5238c2ecf20Sopenharmony_ci	int i, err;
5248c2ecf20Sopenharmony_ci	struct snd_opl3 *opl3;
5258c2ecf20Sopenharmony_ci
5268c2ecf20Sopenharmony_ci	acard = card->private_data;
5278c2ecf20Sopenharmony_ci	err = snd_wss_create(card, wssport[dev] + 4, -1,
5288c2ecf20Sopenharmony_ci			     wssirq[dev],
5298c2ecf20Sopenharmony_ci			     wssdma[dev], -1,
5308c2ecf20Sopenharmony_ci			     WSS_HW_DETECT, 0, &acard->wss);
5318c2ecf20Sopenharmony_ci	if (err < 0) {
5328c2ecf20Sopenharmony_ci		snd_printk(KERN_ERR PFX "AD1848 device busy??\n");
5338c2ecf20Sopenharmony_ci		return err;
5348c2ecf20Sopenharmony_ci	}
5358c2ecf20Sopenharmony_ci	if (acard->wss->hardware != WSS_HW_CMI8330) {
5368c2ecf20Sopenharmony_ci		snd_printk(KERN_ERR PFX "AD1848 not found during probe\n");
5378c2ecf20Sopenharmony_ci		return -ENODEV;
5388c2ecf20Sopenharmony_ci	}
5398c2ecf20Sopenharmony_ci
5408c2ecf20Sopenharmony_ci	if ((err = snd_sbdsp_create(card, sbport[dev],
5418c2ecf20Sopenharmony_ci				    sbirq[dev],
5428c2ecf20Sopenharmony_ci				    snd_sb16dsp_interrupt,
5438c2ecf20Sopenharmony_ci				    sbdma8[dev],
5448c2ecf20Sopenharmony_ci				    sbdma16[dev],
5458c2ecf20Sopenharmony_ci				    SB_HW_AUTO, &acard->sb)) < 0) {
5468c2ecf20Sopenharmony_ci		snd_printk(KERN_ERR PFX "SB16 device busy??\n");
5478c2ecf20Sopenharmony_ci		return err;
5488c2ecf20Sopenharmony_ci	}
5498c2ecf20Sopenharmony_ci	if (acard->sb->hardware != SB_HW_16) {
5508c2ecf20Sopenharmony_ci		snd_printk(KERN_ERR PFX "SB16 not found during probe\n");
5518c2ecf20Sopenharmony_ci		return -ENODEV;
5528c2ecf20Sopenharmony_ci	}
5538c2ecf20Sopenharmony_ci
5548c2ecf20Sopenharmony_ci	snd_wss_out(acard->wss, CS4231_MISC_INFO, 0x40); /* switch on MODE2 */
5558c2ecf20Sopenharmony_ci	for (i = CMI8330_RMUX3D; i <= CMI8330_CDINGAIN; i++)
5568c2ecf20Sopenharmony_ci		snd_wss_out(acard->wss, i,
5578c2ecf20Sopenharmony_ci			    snd_cmi8330_image[i - CMI8330_RMUX3D]);
5588c2ecf20Sopenharmony_ci
5598c2ecf20Sopenharmony_ci	if ((err = snd_cmi8330_mixer(card, acard)) < 0) {
5608c2ecf20Sopenharmony_ci		snd_printk(KERN_ERR PFX "failed to create mixers\n");
5618c2ecf20Sopenharmony_ci		return err;
5628c2ecf20Sopenharmony_ci	}
5638c2ecf20Sopenharmony_ci
5648c2ecf20Sopenharmony_ci	if ((err = snd_cmi8330_pcm(card, acard)) < 0) {
5658c2ecf20Sopenharmony_ci		snd_printk(KERN_ERR PFX "failed to create pcms\n");
5668c2ecf20Sopenharmony_ci		return err;
5678c2ecf20Sopenharmony_ci	}
5688c2ecf20Sopenharmony_ci	if (fmport[dev] != SNDRV_AUTO_PORT) {
5698c2ecf20Sopenharmony_ci		if (snd_opl3_create(card,
5708c2ecf20Sopenharmony_ci				    fmport[dev], fmport[dev] + 2,
5718c2ecf20Sopenharmony_ci				    OPL3_HW_AUTO, 0, &opl3) < 0) {
5728c2ecf20Sopenharmony_ci			snd_printk(KERN_ERR PFX
5738c2ecf20Sopenharmony_ci				   "no OPL device at 0x%lx-0x%lx ?\n",
5748c2ecf20Sopenharmony_ci				   fmport[dev], fmport[dev] + 2);
5758c2ecf20Sopenharmony_ci		} else {
5768c2ecf20Sopenharmony_ci			err = snd_opl3_hwdep_new(opl3, 0, 1, NULL);
5778c2ecf20Sopenharmony_ci			if (err < 0)
5788c2ecf20Sopenharmony_ci				return err;
5798c2ecf20Sopenharmony_ci		}
5808c2ecf20Sopenharmony_ci	}
5818c2ecf20Sopenharmony_ci
5828c2ecf20Sopenharmony_ci	if (mpuport[dev] != SNDRV_AUTO_PORT) {
5838c2ecf20Sopenharmony_ci		if (snd_mpu401_uart_new(card, 0, MPU401_HW_MPU401,
5848c2ecf20Sopenharmony_ci					mpuport[dev], 0, mpuirq[dev],
5858c2ecf20Sopenharmony_ci					NULL) < 0)
5868c2ecf20Sopenharmony_ci			printk(KERN_ERR PFX "no MPU-401 device at 0x%lx.\n",
5878c2ecf20Sopenharmony_ci				mpuport[dev]);
5888c2ecf20Sopenharmony_ci	}
5898c2ecf20Sopenharmony_ci
5908c2ecf20Sopenharmony_ci	strcpy(card->driver, (acard->type == CMI8329) ? "CMI8329" : "CMI8330/C3D");
5918c2ecf20Sopenharmony_ci	strcpy(card->shortname, (acard->type == CMI8329) ? "C-Media CMI8329" : "C-Media CMI8330/C3D");
5928c2ecf20Sopenharmony_ci	sprintf(card->longname, "%s at 0x%lx, irq %d, dma %d",
5938c2ecf20Sopenharmony_ci		card->shortname,
5948c2ecf20Sopenharmony_ci		acard->wss->port,
5958c2ecf20Sopenharmony_ci		wssirq[dev],
5968c2ecf20Sopenharmony_ci		wssdma[dev]);
5978c2ecf20Sopenharmony_ci
5988c2ecf20Sopenharmony_ci	return snd_card_register(card);
5998c2ecf20Sopenharmony_ci}
6008c2ecf20Sopenharmony_ci
6018c2ecf20Sopenharmony_cistatic int snd_cmi8330_isa_match(struct device *pdev,
6028c2ecf20Sopenharmony_ci				 unsigned int dev)
6038c2ecf20Sopenharmony_ci{
6048c2ecf20Sopenharmony_ci	if (!enable[dev] || is_isapnp_selected(dev))
6058c2ecf20Sopenharmony_ci		return 0;
6068c2ecf20Sopenharmony_ci	if (wssport[dev] == SNDRV_AUTO_PORT) {
6078c2ecf20Sopenharmony_ci		snd_printk(KERN_ERR PFX "specify wssport\n");
6088c2ecf20Sopenharmony_ci		return 0;
6098c2ecf20Sopenharmony_ci	}
6108c2ecf20Sopenharmony_ci	if (sbport[dev] == SNDRV_AUTO_PORT) {
6118c2ecf20Sopenharmony_ci		snd_printk(KERN_ERR PFX "specify sbport\n");
6128c2ecf20Sopenharmony_ci		return 0;
6138c2ecf20Sopenharmony_ci	}
6148c2ecf20Sopenharmony_ci	return 1;
6158c2ecf20Sopenharmony_ci}
6168c2ecf20Sopenharmony_ci
6178c2ecf20Sopenharmony_cistatic int snd_cmi8330_isa_probe(struct device *pdev,
6188c2ecf20Sopenharmony_ci				 unsigned int dev)
6198c2ecf20Sopenharmony_ci{
6208c2ecf20Sopenharmony_ci	struct snd_card *card;
6218c2ecf20Sopenharmony_ci	int err;
6228c2ecf20Sopenharmony_ci
6238c2ecf20Sopenharmony_ci	err = snd_cmi8330_card_new(pdev, dev, &card);
6248c2ecf20Sopenharmony_ci	if (err < 0)
6258c2ecf20Sopenharmony_ci		return err;
6268c2ecf20Sopenharmony_ci	if ((err = snd_cmi8330_probe(card, dev)) < 0) {
6278c2ecf20Sopenharmony_ci		snd_card_free(card);
6288c2ecf20Sopenharmony_ci		return err;
6298c2ecf20Sopenharmony_ci	}
6308c2ecf20Sopenharmony_ci	dev_set_drvdata(pdev, card);
6318c2ecf20Sopenharmony_ci	return 0;
6328c2ecf20Sopenharmony_ci}
6338c2ecf20Sopenharmony_ci
6348c2ecf20Sopenharmony_cistatic int snd_cmi8330_isa_remove(struct device *devptr,
6358c2ecf20Sopenharmony_ci				  unsigned int dev)
6368c2ecf20Sopenharmony_ci{
6378c2ecf20Sopenharmony_ci	snd_card_free(dev_get_drvdata(devptr));
6388c2ecf20Sopenharmony_ci	return 0;
6398c2ecf20Sopenharmony_ci}
6408c2ecf20Sopenharmony_ci
6418c2ecf20Sopenharmony_ci#ifdef CONFIG_PM
6428c2ecf20Sopenharmony_cistatic int snd_cmi8330_isa_suspend(struct device *dev, unsigned int n,
6438c2ecf20Sopenharmony_ci				   pm_message_t state)
6448c2ecf20Sopenharmony_ci{
6458c2ecf20Sopenharmony_ci	return snd_cmi8330_suspend(dev_get_drvdata(dev));
6468c2ecf20Sopenharmony_ci}
6478c2ecf20Sopenharmony_ci
6488c2ecf20Sopenharmony_cistatic int snd_cmi8330_isa_resume(struct device *dev, unsigned int n)
6498c2ecf20Sopenharmony_ci{
6508c2ecf20Sopenharmony_ci	return snd_cmi8330_resume(dev_get_drvdata(dev));
6518c2ecf20Sopenharmony_ci}
6528c2ecf20Sopenharmony_ci#endif
6538c2ecf20Sopenharmony_ci
6548c2ecf20Sopenharmony_ci#define DEV_NAME	"cmi8330"
6558c2ecf20Sopenharmony_ci
6568c2ecf20Sopenharmony_cistatic struct isa_driver snd_cmi8330_driver = {
6578c2ecf20Sopenharmony_ci	.match		= snd_cmi8330_isa_match,
6588c2ecf20Sopenharmony_ci	.probe		= snd_cmi8330_isa_probe,
6598c2ecf20Sopenharmony_ci	.remove		= snd_cmi8330_isa_remove,
6608c2ecf20Sopenharmony_ci#ifdef CONFIG_PM
6618c2ecf20Sopenharmony_ci	.suspend	= snd_cmi8330_isa_suspend,
6628c2ecf20Sopenharmony_ci	.resume		= snd_cmi8330_isa_resume,
6638c2ecf20Sopenharmony_ci#endif
6648c2ecf20Sopenharmony_ci	.driver		= {
6658c2ecf20Sopenharmony_ci		.name	= DEV_NAME
6668c2ecf20Sopenharmony_ci	},
6678c2ecf20Sopenharmony_ci};
6688c2ecf20Sopenharmony_ci
6698c2ecf20Sopenharmony_ci
6708c2ecf20Sopenharmony_ci#ifdef CONFIG_PNP
6718c2ecf20Sopenharmony_cistatic int snd_cmi8330_pnp_detect(struct pnp_card_link *pcard,
6728c2ecf20Sopenharmony_ci				  const struct pnp_card_device_id *pid)
6738c2ecf20Sopenharmony_ci{
6748c2ecf20Sopenharmony_ci	static int dev;
6758c2ecf20Sopenharmony_ci	struct snd_card *card;
6768c2ecf20Sopenharmony_ci	int res;
6778c2ecf20Sopenharmony_ci
6788c2ecf20Sopenharmony_ci	for ( ; dev < SNDRV_CARDS; dev++) {
6798c2ecf20Sopenharmony_ci		if (enable[dev] && isapnp[dev])
6808c2ecf20Sopenharmony_ci			break;
6818c2ecf20Sopenharmony_ci	}
6828c2ecf20Sopenharmony_ci	if (dev >= SNDRV_CARDS)
6838c2ecf20Sopenharmony_ci		return -ENODEV;
6848c2ecf20Sopenharmony_ci
6858c2ecf20Sopenharmony_ci	res = snd_cmi8330_card_new(&pcard->card->dev, dev, &card);
6868c2ecf20Sopenharmony_ci	if (res < 0)
6878c2ecf20Sopenharmony_ci		return res;
6888c2ecf20Sopenharmony_ci	if ((res = snd_cmi8330_pnp(dev, card->private_data, pcard, pid)) < 0) {
6898c2ecf20Sopenharmony_ci		snd_printk(KERN_ERR PFX "PnP detection failed\n");
6908c2ecf20Sopenharmony_ci		snd_card_free(card);
6918c2ecf20Sopenharmony_ci		return res;
6928c2ecf20Sopenharmony_ci	}
6938c2ecf20Sopenharmony_ci	if ((res = snd_cmi8330_probe(card, dev)) < 0) {
6948c2ecf20Sopenharmony_ci		snd_card_free(card);
6958c2ecf20Sopenharmony_ci		return res;
6968c2ecf20Sopenharmony_ci	}
6978c2ecf20Sopenharmony_ci	pnp_set_card_drvdata(pcard, card);
6988c2ecf20Sopenharmony_ci	dev++;
6998c2ecf20Sopenharmony_ci	return 0;
7008c2ecf20Sopenharmony_ci}
7018c2ecf20Sopenharmony_ci
7028c2ecf20Sopenharmony_cistatic void snd_cmi8330_pnp_remove(struct pnp_card_link *pcard)
7038c2ecf20Sopenharmony_ci{
7048c2ecf20Sopenharmony_ci	snd_card_free(pnp_get_card_drvdata(pcard));
7058c2ecf20Sopenharmony_ci	pnp_set_card_drvdata(pcard, NULL);
7068c2ecf20Sopenharmony_ci}
7078c2ecf20Sopenharmony_ci
7088c2ecf20Sopenharmony_ci#ifdef CONFIG_PM
7098c2ecf20Sopenharmony_cistatic int snd_cmi8330_pnp_suspend(struct pnp_card_link *pcard, pm_message_t state)
7108c2ecf20Sopenharmony_ci{
7118c2ecf20Sopenharmony_ci	return snd_cmi8330_suspend(pnp_get_card_drvdata(pcard));
7128c2ecf20Sopenharmony_ci}
7138c2ecf20Sopenharmony_ci
7148c2ecf20Sopenharmony_cistatic int snd_cmi8330_pnp_resume(struct pnp_card_link *pcard)
7158c2ecf20Sopenharmony_ci{
7168c2ecf20Sopenharmony_ci	return snd_cmi8330_resume(pnp_get_card_drvdata(pcard));
7178c2ecf20Sopenharmony_ci}
7188c2ecf20Sopenharmony_ci#endif
7198c2ecf20Sopenharmony_ci
7208c2ecf20Sopenharmony_cistatic struct pnp_card_driver cmi8330_pnpc_driver = {
7218c2ecf20Sopenharmony_ci	.flags = PNP_DRIVER_RES_DISABLE,
7228c2ecf20Sopenharmony_ci	.name = "cmi8330",
7238c2ecf20Sopenharmony_ci	.id_table = snd_cmi8330_pnpids,
7248c2ecf20Sopenharmony_ci	.probe = snd_cmi8330_pnp_detect,
7258c2ecf20Sopenharmony_ci	.remove = snd_cmi8330_pnp_remove,
7268c2ecf20Sopenharmony_ci#ifdef CONFIG_PM
7278c2ecf20Sopenharmony_ci	.suspend	= snd_cmi8330_pnp_suspend,
7288c2ecf20Sopenharmony_ci	.resume		= snd_cmi8330_pnp_resume,
7298c2ecf20Sopenharmony_ci#endif
7308c2ecf20Sopenharmony_ci};
7318c2ecf20Sopenharmony_ci#endif /* CONFIG_PNP */
7328c2ecf20Sopenharmony_ci
7338c2ecf20Sopenharmony_cistatic int __init alsa_card_cmi8330_init(void)
7348c2ecf20Sopenharmony_ci{
7358c2ecf20Sopenharmony_ci	int err;
7368c2ecf20Sopenharmony_ci
7378c2ecf20Sopenharmony_ci	err = isa_register_driver(&snd_cmi8330_driver, SNDRV_CARDS);
7388c2ecf20Sopenharmony_ci#ifdef CONFIG_PNP
7398c2ecf20Sopenharmony_ci	if (!err)
7408c2ecf20Sopenharmony_ci		isa_registered = 1;
7418c2ecf20Sopenharmony_ci
7428c2ecf20Sopenharmony_ci	err = pnp_register_card_driver(&cmi8330_pnpc_driver);
7438c2ecf20Sopenharmony_ci	if (!err)
7448c2ecf20Sopenharmony_ci		pnp_registered = 1;
7458c2ecf20Sopenharmony_ci
7468c2ecf20Sopenharmony_ci	if (isa_registered)
7478c2ecf20Sopenharmony_ci		err = 0;
7488c2ecf20Sopenharmony_ci#endif
7498c2ecf20Sopenharmony_ci	return err;
7508c2ecf20Sopenharmony_ci}
7518c2ecf20Sopenharmony_ci
7528c2ecf20Sopenharmony_cistatic void __exit alsa_card_cmi8330_exit(void)
7538c2ecf20Sopenharmony_ci{
7548c2ecf20Sopenharmony_ci#ifdef CONFIG_PNP
7558c2ecf20Sopenharmony_ci	if (pnp_registered)
7568c2ecf20Sopenharmony_ci		pnp_unregister_card_driver(&cmi8330_pnpc_driver);
7578c2ecf20Sopenharmony_ci
7588c2ecf20Sopenharmony_ci	if (isa_registered)
7598c2ecf20Sopenharmony_ci#endif
7608c2ecf20Sopenharmony_ci		isa_unregister_driver(&snd_cmi8330_driver);
7618c2ecf20Sopenharmony_ci}
7628c2ecf20Sopenharmony_ci
7638c2ecf20Sopenharmony_cimodule_init(alsa_card_cmi8330_init)
7648c2ecf20Sopenharmony_cimodule_exit(alsa_card_cmi8330_exit)
765