aboutsummaryrefslogtreecommitdiffstats
path: root/sound/pci/hda/hda_hwdep.c
diff options
context:
space:
mode:
authorTakashi Iwai <tiwai@suse.de>2007-07-27 12:58:06 -0400
committerJaroslav Kysela <perex@perex.cz>2007-10-16 09:58:10 -0400
commit2807314d467e7dd929c42050031aabbd28e78f0b (patch)
treed4d05f61ef8cc1115ae73af900b8012392321caa /sound/pci/hda/hda_hwdep.c
parentef5fa1a49fc3b5fe8e734f25fa61bc73ccba344e (diff)
[ALSA] hda-intel - Add hwdep interface
Added a hwdep interface for each codec (enabled per kconfig). This interface can be used for reading/writing HD-audio verbs and other purposes as future extensions. Signed-off-by: Takashi Iwai <tiwai@suse.de> Signed-off-by: Jaroslav Kysela <perex@suse.cz>
Diffstat (limited to 'sound/pci/hda/hda_hwdep.c')
-rw-r--r--sound/pci/hda/hda_hwdep.c122
1 files changed, 122 insertions, 0 deletions
diff --git a/sound/pci/hda/hda_hwdep.c b/sound/pci/hda/hda_hwdep.c
new file mode 100644
index 000000000000..64be7b533488
--- /dev/null
+++ b/sound/pci/hda/hda_hwdep.c
@@ -0,0 +1,122 @@
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
21#include <sound/driver.h>
22#include <linux/init.h>
23#include <linux/slab.h>
24#include <linux/pci.h>
25#include <linux/compat.h>
26#include <linux/mutex.h>
27#include <sound/core.h>
28#include "hda_codec.h"
29#include "hda_local.h"
30#include <sound/hda_hwdep.h>
31
32/*
33 * write/read an out-of-bound verb
34 */
35static int verb_write_ioctl(struct hda_codec *codec,
36 struct hda_verb_ioctl __user *arg)
37{
38 u32 verb, res;
39
40 if (get_user(verb, &arg->verb))
41 return -EFAULT;
42 res = snd_hda_codec_read(codec, verb >> 24, 0,
43 (verb >> 8) & 0xffff, verb & 0xff);
44 if (put_user(res, &arg->res))
45 return -EFAULT;
46 return 0;
47}
48
49static int get_wcap_ioctl(struct hda_codec *codec,
50 struct hda_verb_ioctl __user *arg)
51{
52 u32 verb, res;
53
54 if (get_user(verb, &arg->verb))
55 return -EFAULT;
56 res = get_wcaps(codec, verb >> 24);
57 if (put_user(res, &arg->res))
58 return -EFAULT;
59 return 0;
60}
61
62
63/*
64 */
65static int hda_hwdep_ioctl(struct snd_hwdep *hw, struct file *file,
66 unsigned int cmd, unsigned long arg)
67{
68 struct hda_codec *codec = hw->private_data;
69 void __user *argp = (void __user *)arg;
70
71 switch (cmd) {
72 case HDA_IOCTL_PVERSION:
73 return put_user(HDA_HWDEP_VERSION, (int __user *)argp);
74 case HDA_IOCTL_VERB_WRITE:
75 return verb_write_ioctl(codec, argp);
76 case HDA_IOCTL_GET_WCAP:
77 return get_wcap_ioctl(codec, argp);
78 }
79 return -ENOIOCTLCMD;
80}
81
82#ifdef CONFIG_COMPAT
83static int hda_hwdep_ioctl_compat(struct snd_hwdep *hw, struct file *file,
84 unsigned int cmd, unsigned long arg)
85{
86 return hda_hwdep_ioctl(hw, file, cmd, compat_ptr(arg));
87}
88#endif
89
90static int hda_hwdep_open(struct snd_hwdep *hw, struct file *file)
91{
92#ifndef CONFIG_SND_DEBUG_DETECT
93 if (!capable(CAP_SYS_RAWIO))
94 return -EACCES;
95#endif
96 return 0;
97}
98
99int __devinit snd_hda_create_hwdep(struct hda_codec *codec)
100{
101 char hwname[16];
102 struct snd_hwdep *hwdep;
103 int err;
104
105 sprintf(hwname, "HDA Codec %d", codec->addr);
106 err = snd_hwdep_new(codec->bus->card, hwname, codec->addr, &hwdep);
107 if (err < 0)
108 return err;
109 codec->hwdep = hwdep;
110 sprintf(hwdep->name, "HDA Codec %d", codec->addr);
111 hwdep->iface = SNDRV_HWDEP_IFACE_HDA;
112 hwdep->private_data = codec;
113 hwdep->exclusive = 1;
114
115 hwdep->ops.open = hda_hwdep_open;
116 hwdep->ops.ioctl = hda_hwdep_ioctl;
117#ifdef CONFIG_COMPAT
118 hwdep->ops.ioctl_compat = hda_hwdep_ioctl_compat;
119#endif
120
121 return 0;
122}