#include <linux/smp_lock.h>
#include <linux/bitops.h>
#include <linux/wait.h>
+#include <linux/dma-mapping.h>
#include <asm/io.h>
#include <asm/page.h>
struct address_info mpu_data;
#endif
#ifdef CONFIG_SOUND_CMPCI_JOYSTICK
- struct gameport gameport;
+ struct gameport *gameport;
#endif
int chip_version;
static LIST_HEAD(devs);
-static int mpuio = 0;
-static int fmio = 0;
-static int joystick = 0;
-static int spdif_inverse = 0;
-static int spdif_loop = 0;
-static int spdif_out = 0;
-static int use_line_as_rear = 0;
-static int use_line_as_bass = 0;
-static int use_mic_as_bass = 0;
-static int mic_boost = 0;
-static int hw_copy = 0;
-MODULE_PARM(mpuio, "i");
-MODULE_PARM(fmio, "i");
-MODULE_PARM(joystick, "i");
-MODULE_PARM(spdif_inverse, "i");
-MODULE_PARM(spdif_loop, "i");
-MODULE_PARM(spdif_out, "i");
-MODULE_PARM(use_line_as_rear, "i");
-MODULE_PARM(use_line_as_bass, "i");
-MODULE_PARM(use_mic_as_bass, "i");
-MODULE_PARM(mic_boost, "i");
-MODULE_PARM(hw_copy, "i");
+static int mpuio;
+static int fmio;
+static int joystick;
+static int spdif_inverse;
+static int spdif_loop;
+static int spdif_out;
+static int use_line_as_rear;
+static int use_line_as_bass;
+static int use_mic_as_bass;
+static int mic_boost;
+static int hw_copy;
+module_param(mpuio, int, 0);
+module_param(fmio, int, 0);
+module_param(joystick, bool, 0);
+module_param(spdif_inverse, bool, 0);
+module_param(spdif_loop, bool, 0);
+module_param(spdif_out, bool, 0);
+module_param(use_line_as_rear, bool, 0);
+module_param(use_line_as_bass, bool, 0);
+module_param(use_mic_as_bass, bool, 0);
+module_param(mic_boost, bool, 0);
+module_param(hw_copy, bool, 0);
MODULE_PARM_DESC(mpuio, "(0x330, 0x320, 0x310, 0x300) Base of MPU-401, 0 to disable");
MODULE_PARM_DESC(fmio, "(0x388, 0x3C8, 0x3E0) Base of OPL3, 0 to disable");
MODULE_PARM_DESC(joystick, "(1/0) Enable joystick interface, still need joystick driver");
spin_unlock_irqrestore(&s->lock, flags);
}
-static int trans_ac3(struct cm_state *s, void *dest, const char *source, int size)
+static int trans_ac3(struct cm_state *s, void *dest, const char __user *source, int size)
{
int i = size / 2;
unsigned long data;
unsigned short data16;
unsigned long *dst = (unsigned long *) dest;
- unsigned short *src = (unsigned short *)source;
+ unsigned short __user *src = (unsigned short __user *)source;
int err;
do {
enable_adc(s);
}
-static inline void enable_dac(struct cm_state *s)
-{
- unsigned long flags;
-
- spin_lock_irqsave(&s->lock, flags);
- enable_dac_unlocked(s);
- spin_unlock_irqrestore(&s->lock, flags);
-}
-
static inline void stop_adc_unlocked(struct cm_state *s)
{
if (s->enable & ENADC) {
if (!db->rawbuf || !db->dmaaddr)
return -ENOMEM;
db->buforder = order;
- /* now mark the pages as reserved; otherwise remap_page_range doesn't do what we want */
+ /* now mark the pages as reserved; otherwise remap_pfn_range doesn't do what we want */
pend = virt_to_page(db->rawbuf + (PAGE_SIZE << db->buforder) - 1);
for (pstart = virt_to_page(db->rawbuf); pstart <= pend; pstart++)
SetPageReserved(pstart);
unsigned long flags;
int i, val, j;
unsigned char l, r, rl, rr;
+ void __user *argp = (void __user *)arg;
+ int __user *p = argp;
VALIDATE_STATE(s);
if (cmd == SOUND_MIXER_INFO) {
strlcpy(info.id, "cmpci", sizeof(info.id));
strlcpy(info.name, "C-Media PCI", sizeof(info.name));
info.modify_counter = s->mix.modcnt;
- if (copy_to_user((void *)arg, &info, sizeof(info)))
+ if (copy_to_user(argp, &info, sizeof(info)))
return -EFAULT;
return 0;
}
memset(&info, 0, sizeof(info));
strlcpy(info.id, "cmpci", sizeof(info.id));
strlcpy(info.name, "C-Media cmpci", sizeof(info.name));
- if (copy_to_user((void *)arg, &info, sizeof(info)))
+ if (copy_to_user(argp, &info, sizeof(info)))
return -EFAULT;
return 0;
}
if (cmd == OSS_GETVERSION)
- return put_user(SOUND_VERSION, (int *)arg);
+ return put_user(SOUND_VERSION, p);
if (_IOC_TYPE(cmd) != 'M' || _SIOC_SIZE(cmd) != sizeof(int))
return -EINVAL;
if (_SIOC_DIR(cmd) == _SIOC_READ) {
switch (_IOC_NR(cmd)) {
case SOUND_MIXER_RECSRC: /* Arg contains a bit for each recording source */
val = mixer_recmask(s);
- return put_user(val, (int *)arg);
+ return put_user(val, p);
case SOUND_MIXER_OUTSRC: /* Arg contains a bit for each recording source */
val = mixer_outmask(s);
- return put_user(val, (int *)arg);
+ return put_user(val, p);
case SOUND_MIXER_DEVMASK: /* Arg contains a bit for each supported device */
for (val = i = 0; i < SOUND_MIXER_NRDEVICES; i++)
if (mixtable[i].type)
val |= 1 << i;
- return put_user(val, (int *)arg);
+ return put_user(val, p);
case SOUND_MIXER_RECMASK: /* Arg contains a bit for each supported recording source */
for (val = i = 0; i < SOUND_MIXER_NRDEVICES; i++)
if (mixtable[i].rec)
val |= 1 << i;
- return put_user(val, (int *)arg);
+ return put_user(val, p);
case SOUND_MIXER_OUTMASK: /* Arg contains a bit for each supported recording source */
for (val = i = 0; i < SOUND_MIXER_NRDEVICES; i++)
if (mixtable[i].play)
val |= 1 << i;
- return put_user(val, (int *)arg);
+ return put_user(val, p);
case SOUND_MIXER_STEREODEVS: /* Mixer channels supporting stereo */
for (val = i = 0; i < SOUND_MIXER_NRDEVICES; i++)
if (mixtable[i].type && mixtable[i].type != MT_4MUTEMONO)
val |= 1 << i;
- return put_user(val, (int *)arg);
+ return put_user(val, p);
case SOUND_MIXER_CAPS:
- return put_user(0, (int *)arg);
+ return put_user(0, p);
default:
i = _IOC_NR(cmd);
return -EINVAL;
if (!volidx[i])
return -EINVAL;
- return put_user(s->mix.vol[volidx[i]-1], (int *)arg);
+ return put_user(s->mix.vol[volidx[i]-1], p);
}
}
if (_SIOC_DIR(cmd) != (_SIOC_READ|_SIOC_WRITE))
s->mix.modcnt++;
switch (_IOC_NR(cmd)) {
case SOUND_MIXER_RECSRC: /* Arg contains a bit for each recording source */
- if (get_user(val, (int *)arg))
+ if (get_user(val, p))
return -EFAULT;
i = generic_hweight32(val);
for (j = i = 0; i < SOUND_MIXER_NRDEVICES; i++) {
return 0;
case SOUND_MIXER_OUTSRC: /* Arg contains a bit for each recording source */
- if (get_user(val, (int *)arg))
+ if (get_user(val, p))
return -EFAULT;
for (j = i = 0; i < SOUND_MIXER_NRDEVICES; i++) {
if (!(val & (1 << i)))
i = _IOC_NR(cmd);
if (i >= SOUND_MIXER_NRDEVICES || !mixtable[i].type)
return -EINVAL;
- if (get_user(val, (int *)arg))
+ if (get_user(val, p))
return -EFAULT;
l = val & 0xff;
r = (val >> 8) & 0xff;
if (!volidx[i])
return -EINVAL;
s->mix.vol[volidx[i]-1] = val;
- return put_user(s->mix.vol[volidx[i]-1], (int *)arg);
+ return put_user(s->mix.vol[volidx[i]-1], p);
}
}
}
VALIDATE_STATE(s);
file->private_data = s;
- return 0;
+ return nonseekable_open(inode, file);
}
static int cm_release_mixdev(struct inode *inode, struct file *file)
/* --------------------------------------------------------------------- */
-static ssize_t cm_read(struct file *file, char *buffer, size_t count, loff_t *ppos)
+static ssize_t cm_read(struct file *file, char __user *buffer, size_t count, loff_t *ppos)
{
struct cm_state *s = (struct cm_state *)file->private_data;
DECLARE_WAITQUEUE(wait, current);
int cnt;
VALIDATE_STATE(s);
- if (ppos != &file->f_pos)
- return -ESPIPE;
if (s->dma_adc.mapped)
return -ENXIO;
if (!s->dma_adc.ready && (ret = prog_dmabuf(s, 1)))
}
if (s->status & DO_BIGENDIAN_R) {
int i, err;
- unsigned char *src, *dst;
+ unsigned char *src;
+ char __user *dst = buffer;
unsigned char data[2];
src = (unsigned char *) (s->dma_adc.rawbuf + swptr);
- dst = (unsigned char *) buffer;
// copy left/right sample at one time
for (i = 0; i < cnt / 2; i++) {
data[0] = src[1];
return ret;
}
-static ssize_t cm_write(struct file *file, const char *buffer, size_t count, loff_t *ppos)
+static ssize_t cm_write(struct file *file, const char __user *buffer, size_t count, loff_t *ppos)
{
struct cm_state *s = (struct cm_state *)file->private_data;
DECLARE_WAITQUEUE(wait, current);
int cnt;
VALIDATE_STATE(s);
- if (ppos != &file->f_pos)
- return -ESPIPE;
if (s->dma_dac.mapped)
return -ENXIO;
if (!s->dma_dac.ready && (ret = prog_dmabuf(s, 0)))
swptr = (swptr + 2 * cnt) % s->dma_dac.dmasize;
} else if ((s->status & DO_DUAL_DAC) && (s->status & DO_BIGENDIAN_W)) {
int i, err;
- unsigned char *src, *dst0, *dst1;
+ const char __user *src = buffer;
+ unsigned char *dst0, *dst1;
unsigned char data[8];
- src = (unsigned char *) buffer;
dst0 = (unsigned char *) (s->dma_dac.rawbuf + swptr);
dst1 = (unsigned char *) (s->dma_adc.rawbuf + swptr);
// copy left/right sample at one time
swptr = (swptr + cnt) % s->dma_dac.dmasize;
} else if (s->status & DO_DUAL_DAC) {
int i, err;
- unsigned long *src, *dst0, *dst1;
+ unsigned long __user *src = (unsigned long __user *) buffer;
+ unsigned long *dst0, *dst1;
- src = (unsigned long *) buffer;
dst0 = (unsigned long *) (s->dma_dac.rawbuf + swptr);
dst1 = (unsigned long *) (s->dma_adc.rawbuf + swptr);
// copy left/right sample at one time
swptr = (swptr + cnt) % s->dma_dac.dmasize;
} else if (s->status & DO_BIGENDIAN_W) {
int i, err;
- unsigned char *src, *dst;
+ const char __user *src = buffer;
+ unsigned char *dst;
unsigned char data[2];
- src = (unsigned char *) buffer;
dst = (unsigned char *) (s->dma_dac.rawbuf + swptr);
// swap hi/lo bytes for each sample
for (i = 0; i < cnt / 2; i++) {
if (size > (PAGE_SIZE << db->buforder))
goto out;
ret = -EINVAL;
- if (remap_page_range(vma, vma->vm_start, virt_to_phys(db->rawbuf), size, vma->vm_page_prot))
+ if (remap_pfn_range(vma, vma->vm_start,
+ virt_to_phys(db->rawbuf) >> PAGE_SHIFT,
+ size, vma->vm_page_prot))
goto out;
db->mapped = 1;
ret = 0;
count_info cinfo;
int val, mapped, ret;
unsigned char fmtm, fmtd;
+ void __user *argp = (void __user *)arg;
+ int __user *p = argp;
VALIDATE_STATE(s);
mapped = ((file->f_mode & FMODE_WRITE) && s->dma_dac.mapped) ||
((file->f_mode & FMODE_READ) && s->dma_adc.mapped);
switch (cmd) {
case OSS_GETVERSION:
- return put_user(SOUND_VERSION, (int *)arg);
+ return put_user(SOUND_VERSION, p);
case SNDCTL_DSP_SYNC:
if (file->f_mode & FMODE_WRITE)
return 0;
case SNDCTL_DSP_GETCAPS:
- return put_user(DSP_CAP_DUPLEX | DSP_CAP_REALTIME | DSP_CAP_TRIGGER | DSP_CAP_MMAP | DSP_CAP_BIND, (int *)arg);
+ return put_user(DSP_CAP_DUPLEX | DSP_CAP_REALTIME | DSP_CAP_TRIGGER | DSP_CAP_MMAP | DSP_CAP_BIND, p);
case SNDCTL_DSP_RESET:
if (file->f_mode & FMODE_WRITE) {
return 0;
case SNDCTL_DSP_SPEED:
- if (get_user(val, (int *)arg))
+ if (get_user(val, p))
return -EFAULT;
if (val >= 0) {
if (file->f_mode & FMODE_READ) {
set_dac_rate(s, val);
}
}
- return put_user((file->f_mode & FMODE_READ) ? s->rateadc : s->ratedac, (int *)arg);
+ return put_user((file->f_mode & FMODE_READ) ? s->rateadc : s->ratedac, p);
case SNDCTL_DSP_STEREO:
- if (get_user(val, (int *)arg))
+ if (get_user(val, p))
return -EFAULT;
fmtd = 0;
fmtm = ~0;
return 0;
case SNDCTL_DSP_CHANNELS:
- if (get_user(val, (int *)arg))
+ if (get_user(val, p))
return -EFAULT;
if (val != 0) {
fmtd = 0;
if ((s->capability & CAN_MULTI_CH)
&& (file->f_mode & FMODE_WRITE)) {
val = set_dac_channels(s, val);
- return put_user(val, (int *)arg);
+ return put_user(val, p);
}
}
return put_user((s->fmt & ((file->f_mode & FMODE_READ) ? (CM_CFMT_STEREO << CM_CFMT_ADCSHIFT)
- : (CM_CFMT_STEREO << CM_CFMT_DACSHIFT))) ? 2 : 1, (int *)arg);
+ : (CM_CFMT_STEREO << CM_CFMT_DACSHIFT))) ? 2 : 1, p);
case SNDCTL_DSP_GETFMTS: /* Returns a mask */
return put_user(AFMT_S16_BE|AFMT_S16_LE|AFMT_U8|
- ((s->capability & CAN_AC3) ? AFMT_AC3 : 0), (int *)arg);
+ ((s->capability & CAN_AC3) ? AFMT_AC3 : 0), p);
case SNDCTL_DSP_SETFMT: /* Selects ONE fmt*/
- if (get_user(val, (int *)arg))
+ if (get_user(val, p))
return -EFAULT;
if (val != AFMT_QUERY) {
fmtd = 0;
}
set_fmt(s, fmtm, fmtd);
}
- if (s->status & DO_AC3) return put_user(AFMT_AC3, (int *)arg);
+ if (s->status & DO_AC3) return put_user(AFMT_AC3, p);
return put_user((s->fmt & ((file->f_mode & FMODE_READ) ? (CM_CFMT_16BIT << CM_CFMT_ADCSHIFT)
- : (CM_CFMT_16BIT << CM_CFMT_DACSHIFT))) ? val : AFMT_U8, (int *)arg);
+ : (CM_CFMT_16BIT << CM_CFMT_DACSHIFT))) ? val : AFMT_U8, p);
case SNDCTL_DSP_POST:
return 0;
(s->enable & ENDAC) &&
(s->enable & ENADC))
val |= PCM_ENABLE_OUTPUT;
- return put_user(val, (int *)arg);
+ return put_user(val, p);
}
if (file->f_mode & FMODE_READ && s->enable & ENADC)
val |= PCM_ENABLE_INPUT;
if (file->f_mode & FMODE_WRITE && s->enable & ENDAC)
val |= PCM_ENABLE_OUTPUT;
- return put_user(val, (int *)arg);
+ return put_user(val, p);
case SNDCTL_DSP_SETTRIGGER:
- if (get_user(val, (int *)arg))
+ if (get_user(val, p))
return -EFAULT;
if (file->f_mode & FMODE_READ) {
if (val & PCM_ENABLE_INPUT) {
abinfo.fragstotal = s->dma_dac.numfrag;
abinfo.fragments = abinfo.bytes >> s->dma_dac.fragshift;
spin_unlock_irqrestore(&s->lock, flags);
- return copy_to_user((void *)arg, &abinfo, sizeof(abinfo)) ? -EFAULT : 0;
+ return copy_to_user(argp, &abinfo, sizeof(abinfo)) ? -EFAULT : 0;
case SNDCTL_DSP_GETISPACE:
if (!(file->f_mode & FMODE_READ))
abinfo.fragstotal = s->dma_adc.numfrag;
abinfo.fragments = abinfo.bytes >> s->dma_adc.fragshift;
spin_unlock_irqrestore(&s->lock, flags);
- return copy_to_user((void *)arg, &abinfo, sizeof(abinfo)) ? -EFAULT : 0;
+ return copy_to_user(argp, &abinfo, sizeof(abinfo)) ? -EFAULT : 0;
case SNDCTL_DSP_NONBLOCK:
file->f_flags |= O_NONBLOCK;
cm_update_ptr(s);
val = s->dma_dac.count;
spin_unlock_irqrestore(&s->lock, flags);
- return put_user(val, (int *)arg);
+ return put_user(val, p);
case SNDCTL_DSP_GETIPTR:
if (!(file->f_mode & FMODE_READ))
if (s->dma_adc.mapped)
s->dma_adc.count &= s->dma_adc.fragsize-1;
spin_unlock_irqrestore(&s->lock, flags);
- return copy_to_user((void *)arg, &cinfo, sizeof(cinfo)) ? -EFAULT : 0;
+ return copy_to_user(argp, &cinfo, sizeof(cinfo)) ? -EFAULT : 0;
case SNDCTL_DSP_GETOPTR:
if (!(file->f_mode & FMODE_WRITE))
s->dma_adc.count &= s->dma_adc.fragsize-1;
}
spin_unlock_irqrestore(&s->lock, flags);
- return copy_to_user((void *)arg, &cinfo, sizeof(cinfo)) ? -EFAULT : 0;
+ return copy_to_user(argp, &cinfo, sizeof(cinfo)) ? -EFAULT : 0;
case SNDCTL_DSP_GETBLKSIZE:
if (file->f_mode & FMODE_WRITE) {
if (s->status & DO_DUAL_DAC) {
if ((val = prog_dmabuf(s, 1)))
return val;
- return put_user(2 * s->dma_dac.fragsize, (int *)arg);
+ return put_user(2 * s->dma_dac.fragsize, p);
}
- return put_user(s->dma_dac.fragsize, (int *)arg);
+ return put_user(s->dma_dac.fragsize, p);
}
if ((val = prog_dmabuf(s, 1)))
return val;
- return put_user(s->dma_adc.fragsize, (int *)arg);
+ return put_user(s->dma_adc.fragsize, p);
case SNDCTL_DSP_SETFRAGMENT:
- if (get_user(val, (int *)arg))
+ if (get_user(val, p))
return -EFAULT;
if (file->f_mode & FMODE_READ) {
s->dma_adc.ossfragshift = val & 0xffff;
if ((file->f_mode & FMODE_READ && s->dma_adc.subdivision) ||
(file->f_mode & FMODE_WRITE && s->dma_dac.subdivision))
return -EINVAL;
- if (get_user(val, (int *)arg))
+ if (get_user(val, p))
return -EFAULT;
if (val != 1 && val != 2 && val != 4)
return -EINVAL;
return 0;
case SOUND_PCM_READ_RATE:
- return put_user((file->f_mode & FMODE_READ) ? s->rateadc : s->ratedac, (int *)arg);
+ return put_user((file->f_mode & FMODE_READ) ? s->rateadc : s->ratedac, p);
case SOUND_PCM_READ_CHANNELS:
- return put_user((s->fmt & ((file->f_mode & FMODE_READ) ? (CM_CFMT_STEREO << CM_CFMT_ADCSHIFT) : (CM_CFMT_STEREO << CM_CFMT_DACSHIFT))) ? 2 : 1, (int *)arg);
+ return put_user((s->fmt & ((file->f_mode & FMODE_READ) ? (CM_CFMT_STEREO << CM_CFMT_ADCSHIFT) : (CM_CFMT_STEREO << CM_CFMT_DACSHIFT))) ? 2 : 1, p);
case SOUND_PCM_READ_BITS:
- return put_user((s->fmt & ((file->f_mode & FMODE_READ) ? (CM_CFMT_16BIT << CM_CFMT_ADCSHIFT) : (CM_CFMT_16BIT << CM_CFMT_DACSHIFT))) ? 16 : 8, (int *)arg);
+ return put_user((s->fmt & ((file->f_mode & FMODE_READ) ? (CM_CFMT_16BIT << CM_CFMT_ADCSHIFT) : (CM_CFMT_16BIT << CM_CFMT_DACSHIFT))) ? 16 : 8, p);
case SOUND_PCM_READ_FILTER:
- return put_user((file->f_mode & FMODE_READ) ? s->rateadc : s->ratedac, (int *)arg);
+ return put_user((file->f_mode & FMODE_READ) ? s->rateadc : s->ratedac, p);
case SNDCTL_DSP_GETCHANNELMASK:
- return put_user(DSP_BIND_FRONT|DSP_BIND_SURR|DSP_BIND_CENTER_LFE|DSP_BIND_SPDIF, (int *)arg);
+ return put_user(DSP_BIND_FRONT|DSP_BIND_SURR|DSP_BIND_CENTER_LFE|DSP_BIND_SPDIF, p);
case SNDCTL_DSP_BIND_CHANNEL:
- if (get_user(val, (int *)arg))
+ if (get_user(val, p))
return -EFAULT;
if (val == DSP_BIND_QUERY) {
val = DSP_BIND_FRONT;
}
}
}
- return put_user(val, (int *)arg);
+ return put_user(val, p);
case SOUND_PCM_WRITE_FILTER:
case SNDCTL_DSP_MAPINBUF:
case SNDCTL_DSP_SETSYNCRO:
return -EINVAL;
case SNDCTL_SPDIF_COPYRIGHT:
- if (get_user(val, (int *)arg))
+ if (get_user(val, p))
return -EFAULT;
set_spdif_copyright(s, val);
return 0;
case SNDCTL_SPDIF_LOOP:
- if (get_user(val, (int *)arg))
+ if (get_user(val, p))
return -EFAULT;
set_spdif_loop(s, val);
return 0;
case SNDCTL_SPDIF_MONITOR:
- if (get_user(val, (int *)arg))
+ if (get_user(val, p))
return -EFAULT;
set_spdif_monitor(s, val);
return 0;
case SNDCTL_SPDIF_LEVEL:
- if (get_user(val, (int *)arg))
+ if (get_user(val, p))
return -EFAULT;
set_spdifout_level(s, val);
return 0;
case SNDCTL_SPDIF_INV:
- if (get_user(val, (int *)arg))
+ if (get_user(val, p))
return -EFAULT;
set_spdifin_inverse(s, val);
return 0;
case SNDCTL_SPDIF_SEL2:
- if (get_user(val, (int *)arg))
+ if (get_user(val, p))
return -EFAULT;
set_spdifin_channel2(s, val);
return 0;
case SNDCTL_SPDIF_VALID:
- if (get_user(val, (int *)arg))
+ if (get_user(val, p))
return -EFAULT;
set_spdifin_valid(s, val);
return 0;
case SNDCTL_SPDIFOUT:
- if (get_user(val, (int *)arg))
+ if (get_user(val, p))
return -EFAULT;
set_spdifout(s, val ? s->ratedac : 0);
return 0;
case SNDCTL_SPDIFIN:
- if (get_user(val, (int *)arg))
+ if (get_user(val, p))
return -EFAULT;
set_spdifin(s, val ? s->rateadc : 0);
return 0;
set_fmt(s, fmtm, fmts);
s->open_mode |= file->f_mode & (FMODE_READ | FMODE_WRITE);
up(&s->open_sem);
- return 0;
+ return nonseekable_open(inode, file);
}
static int cm_release(struct inode *inode, struct file *file)
static struct initvol {
int mixch;
int vol;
-} initvol[] __initdata = {
+} initvol[] __devinitdata = {
{ SOUND_MIXER_WRITE_CD, 0x4f4f },
{ SOUND_MIXER_WRITE_LINE, 0x4f4f },
{ SOUND_MIXER_WRITE_MIC, 0x4f4f },
return ChipVersion;
}
+#ifdef CONFIG_SOUND_CMPCI_JOYSTICK
+static int __devinit cm_create_gameport(struct cm_state *s, int io_port)
+{
+ struct gameport *gp;
+
+ if (!request_region(io_port, CM_EXTENT_GAME, "cmpci GAME")) {
+ printk(KERN_ERR "cmpci: gameport io ports 0x%#x in use\n", io_port);
+ return -EBUSY;
+ }
+
+ if (!(s->gameport = gp = gameport_allocate_port())) {
+ printk(KERN_ERR "cmpci: can not allocate memory for gameport\n");
+ release_region(io_port, CM_EXTENT_GAME);
+ return -ENOMEM;
+ }
+
+ gameport_set_name(gp, "C-Media GP");
+ gameport_set_phys(gp, "pci%s/gameport0", pci_name(s->dev));
+ gp->dev.parent = &s->dev->dev;
+ gp->io = io_port;
+
+ /* enable joystick */
+ maskb(s->iobase + CODEC_CMI_FUNCTRL1, ~0, 0x02);
+
+ gameport_register_port(gp);
+
+ return 0;
+}
+
+static void __devexit cm_free_gameport(struct cm_state *s)
+{
+ if (s->gameport) {
+ int gpio = s->gameport->io;
+
+ gameport_unregister_port(s->gameport);
+ s->gameport = NULL;
+ maskb(s->iobase + CODEC_CMI_FUNCTRL1, ~0x02, 0);
+ release_region(gpio, CM_EXTENT_GAME);
+ }
+}
+#else
+static inline int cm_create_gameport(struct cm_state *s, int io_port) { return -ENOSYS; }
+static inline void cm_free_gameport(struct cm_state *s) { }
+#endif
+
#define echo_option(x)\
if (x) strcat(options, "" #x " ")
mm_segment_t fs;
int i, val, ret;
unsigned char reg_mask;
+ int timeout;
+ struct resource *ports;
struct {
unsigned short deviceid;
char *devicename;
return -ENODEV;
if (pcidev->irq == 0)
return -ENODEV;
- i = pci_set_dma_mask(pcidev, 0xffffffff);
+ i = pci_set_dma_mask(pcidev, DMA_32BIT_MASK);
if (i) {
printk(KERN_WARNING "cmpci: architecture does not support 32bit PCI busmaster DMA\n");
return i;
}
#endif
#ifdef CONFIG_SOUND_CMPCI_MIDI
+ switch (s->iomidi) {
+ case 0x330:
+ reg_mask = 0;
+ break;
+ case 0x320:
+ reg_mask = 0x20;
+ break;
+ case 0x310:
+ reg_mask = 0x40;
+ break;
+ case 0x300:
+ reg_mask = 0x60;
+ break;
+ default:
+ s->iomidi = 0;
+ goto skip_mpu;
+ }
+ ports = request_region(s->iomidi, 2, "mpu401");
+ if (!ports)
+ goto skip_mpu;
/* disable MPU-401 */
maskb(s->iobase + CODEC_CMI_FUNCTRL1, ~0x04, 0);
s->mpu_data.name = "cmpci mpu";
s->mpu_data.io_base = s->iomidi;
s->mpu_data.irq = -s->irq; // tell mpu401 to share irq
- if (probe_mpu401(&s->mpu_data))
+ if (probe_mpu401(&s->mpu_data, ports)) {
+ release_region(s->iomidi, 2);
s->iomidi = 0;
- if (s->iomidi) {
- /* set IO based at 0x330 */
- switch (s->iomidi) {
- case 0x330:
- reg_mask = 0;
- break;
- case 0x320:
- reg_mask = 0x20;
- break;
- case 0x310:
- reg_mask = 0x40;
- break;
- case 0x300:
- reg_mask = 0x60;
- break;
- default:
- s->iomidi = 0;
+ goto skip_mpu;
+ }
+ maskb(s->iobase + CODEC_CMI_LEGACY_CTRL + 3, ~0x60, reg_mask);
+ /* enable MPU-401 */
+ maskb(s->iobase + CODEC_CMI_FUNCTRL1, ~0, 0x04);
+ /* clear all previously received interrupt */
+ for (timeout = 900000; timeout > 0; timeout--) {
+ if ((inb(s->iomidi + 1) && 0x80) == 0)
+ inb(s->iomidi);
+ else
break;
- }
- maskb(s->iobase + CODEC_CMI_LEGACY_CTRL + 3, ~0x60, reg_mask);
- /* enable MPU-401 */
- if (s->iomidi) {
- int timeout;
-
- maskb(s->iobase + CODEC_CMI_FUNCTRL1, ~0, 0x04);
- /* clear all previously received interrupt */
- for (timeout = 900000; timeout > 0; timeout--) {
- if ((inb(s->iomidi + 1) && 0x80) == 0)
- inb(s->iomidi);
- else
- break;
- }
- if (!probe_mpu401(&s->mpu_data)) {
- s->iomidi = 0;
- maskb(s->iobase + CODEC_CMI_FUNCTRL1, ~0, 0x04);
- } else {
- attach_mpu401(&s->mpu_data, THIS_MODULE);
- s->midi_devc = s->mpu_data.slots[1];
- }
- }
}
-#endif
-#ifdef CONFIG_SOUND_CMPCI_JOYSTICK
- /* enable joystick */
- if (joystick) {
- s->gameport.io = 0x200;
- if (!request_region(s->gameport.io, CM_EXTENT_GAME, "cmpci GAME")) {
- printk(KERN_ERR "cmpci: gameport io ports in use\n");
- s->gameport.io = 0;
- } else {
- maskb(s->iobase + CODEC_CMI_FUNCTRL1, ~0, 0x02);
- gameport_register_port(&s->gameport);
- }
+ if (!probe_mpu401(&s->mpu_data, ports)) {
+ release_region(s->iomidi, 2);
+ s->iomidi = 0;
+ maskb(s->iobase + CODEC_CMI_FUNCTRL1, ~0, 0x04);
} else {
- maskb(s->iobase + CODEC_CMI_FUNCTRL1, ~0x02, 0);
- s->gameport.io = 0;
+ attach_mpu401(&s->mpu_data, THIS_MODULE);
+ s->midi_devc = s->mpu_data.slots[1];
}
+skip_mpu:
#endif
+ /* disable joystick port */
+ maskb(s->iobase + CODEC_CMI_FUNCTRL1, ~0x02, 0);
+ if (joystick)
+ cm_create_gameport(s, 0x200);
+
/* store it in the driver field */
pci_set_drvdata(pcidev, s);
/* put it into driver list */
MODULE_DESCRIPTION("CM8x38 Audio Driver");
MODULE_LICENSE("GPL");
-static void __devinit cm_remove(struct pci_dev *dev)
+static void __devexit cm_remove(struct pci_dev *dev)
{
struct cm_state *s = pci_get_drvdata(dev);
if (!s)
return;
-#ifdef CONFIG_SOUND_CMPCI_JOYSTICK
- if (s->gameport.io) {
- gameport_unregister_port(&s->gameport);
- release_region(s->gameport.io, CM_EXTENT_GAME);
- maskb(s->iobase + CODEC_CMI_FUNCTRL1, ~0x02, 0);
- }
-#endif
+
+ cm_free_gameport(s);
+
#ifdef CONFIG_SOUND_CMPCI_FM
if (s->iosynth) {
/* disable FM */
.name = "cmpci",
.id_table = id_table,
.probe = cm_probe,
- .remove = cm_remove
+ .remove = __devexit_p(cm_remove)
};
static int __init init_cmpci(void)
{
printk(KERN_INFO "cmpci: version $Revision: 6.82 $ time " __TIME__ " " __DATE__ "\n");
- return pci_module_init(&cm_driver);
+ return pci_register_driver(&cm_driver);
}
static void __exit cleanup_cmpci(void)