]> git.proxmox.com Git - mirror_ubuntu-hirsute-kernel.git/blame - sound/pci/hda/hda_hwdep.c
Merge branch 'linus' into core/softlockup
[mirror_ubuntu-hirsute-kernel.git] / sound / pci / hda / hda_hwdep.c
CommitLineData
2807314d
TI
1/*
2 * HWDEP Interface for HD-audio codec
3 *
4 * Copyright (c) 2007 Takashi Iwai <tiwai@suse.de>
5 *
6 * This driver is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This driver is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20
2807314d
TI
21#include <linux/init.h>
22#include <linux/slab.h>
23#include <linux/pci.h>
24#include <linux/compat.h>
25#include <linux/mutex.h>
26#include <sound/core.h>
27#include "hda_codec.h"
28#include "hda_local.h"
29#include <sound/hda_hwdep.h>
30
31/*
32 * write/read an out-of-bound verb
33 */
34static int verb_write_ioctl(struct hda_codec *codec,
35 struct hda_verb_ioctl __user *arg)
36{
37 u32 verb, res;
38
39 if (get_user(verb, &arg->verb))
40 return -EFAULT;
41 res = snd_hda_codec_read(codec, verb >> 24, 0,
42 (verb >> 8) & 0xffff, verb & 0xff);
43 if (put_user(res, &arg->res))
44 return -EFAULT;
45 return 0;
46}
47
48static int get_wcap_ioctl(struct hda_codec *codec,
49 struct hda_verb_ioctl __user *arg)
50{
51 u32 verb, res;
52
53 if (get_user(verb, &arg->verb))
54 return -EFAULT;
55 res = get_wcaps(codec, verb >> 24);
56 if (put_user(res, &arg->res))
57 return -EFAULT;
58 return 0;
59}
60
61
62/*
63 */
64static int hda_hwdep_ioctl(struct snd_hwdep *hw, struct file *file,
65 unsigned int cmd, unsigned long arg)
66{
67 struct hda_codec *codec = hw->private_data;
68 void __user *argp = (void __user *)arg;
69
70 switch (cmd) {
71 case HDA_IOCTL_PVERSION:
72 return put_user(HDA_HWDEP_VERSION, (int __user *)argp);
73 case HDA_IOCTL_VERB_WRITE:
74 return verb_write_ioctl(codec, argp);
75 case HDA_IOCTL_GET_WCAP:
76 return get_wcap_ioctl(codec, argp);
77 }
78 return -ENOIOCTLCMD;
79}
80
81#ifdef CONFIG_COMPAT
82static int hda_hwdep_ioctl_compat(struct snd_hwdep *hw, struct file *file,
83 unsigned int cmd, unsigned long arg)
84{
312d045c 85 return hda_hwdep_ioctl(hw, file, cmd, (unsigned long)compat_ptr(arg));
2807314d
TI
86}
87#endif
88
89static int hda_hwdep_open(struct snd_hwdep *hw, struct file *file)
90{
62cf872a 91#ifndef CONFIG_SND_DEBUG_VERBOSE
2807314d
TI
92 if (!capable(CAP_SYS_RAWIO))
93 return -EACCES;
94#endif
95 return 0;
96}
97
98int __devinit snd_hda_create_hwdep(struct hda_codec *codec)
99{
100 char hwname[16];
101 struct snd_hwdep *hwdep;
102 int err;
103
104 sprintf(hwname, "HDA Codec %d", codec->addr);
105 err = snd_hwdep_new(codec->bus->card, hwname, codec->addr, &hwdep);
106 if (err < 0)
107 return err;
108 codec->hwdep = hwdep;
109 sprintf(hwdep->name, "HDA Codec %d", codec->addr);
110 hwdep->iface = SNDRV_HWDEP_IFACE_HDA;
111 hwdep->private_data = codec;
112 hwdep->exclusive = 1;
113
114 hwdep->ops.open = hda_hwdep_open;
115 hwdep->ops.ioctl = hda_hwdep_ioctl;
116#ifdef CONFIG_COMPAT
117 hwdep->ops.ioctl_compat = hda_hwdep_ioctl_compat;
118#endif
119
120 return 0;
121}