Takashi Iwai | 2807314 | 2007-07-27 18:58:06 +0200 | [diff] [blame] | 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 | |
Takashi Iwai | 2807314 | 2007-07-27 18:58:06 +0200 | [diff] [blame] | 21 | #include <linux/init.h> |
| 22 | #include <linux/slab.h> |
Takashi Iwai | 2807314 | 2007-07-27 18:58:06 +0200 | [diff] [blame] | 23 | #include <linux/compat.h> |
Takashi Iwai | 2807314 | 2007-07-27 18:58:06 +0200 | [diff] [blame] | 24 | #include <sound/core.h> |
| 25 | #include "hda_codec.h" |
| 26 | #include "hda_local.h" |
| 27 | #include <sound/hda_hwdep.h> |
Takashi Iwai | d7ffba1 | 2008-07-30 15:01:46 +0200 | [diff] [blame] | 28 | #include <sound/minors.h> |
Takashi Iwai | 2807314 | 2007-07-27 18:58:06 +0200 | [diff] [blame] | 29 | |
| 30 | /* |
| 31 | * write/read an out-of-bound verb |
| 32 | */ |
| 33 | static int verb_write_ioctl(struct hda_codec *codec, |
| 34 | struct hda_verb_ioctl __user *arg) |
| 35 | { |
| 36 | u32 verb, res; |
| 37 | |
| 38 | if (get_user(verb, &arg->verb)) |
| 39 | return -EFAULT; |
| 40 | res = snd_hda_codec_read(codec, verb >> 24, 0, |
| 41 | (verb >> 8) & 0xffff, verb & 0xff); |
| 42 | if (put_user(res, &arg->res)) |
| 43 | return -EFAULT; |
| 44 | return 0; |
| 45 | } |
| 46 | |
| 47 | static int get_wcap_ioctl(struct hda_codec *codec, |
| 48 | struct hda_verb_ioctl __user *arg) |
| 49 | { |
| 50 | u32 verb, res; |
| 51 | |
| 52 | if (get_user(verb, &arg->verb)) |
| 53 | return -EFAULT; |
| 54 | res = get_wcaps(codec, verb >> 24); |
| 55 | if (put_user(res, &arg->res)) |
| 56 | return -EFAULT; |
| 57 | return 0; |
| 58 | } |
| 59 | |
| 60 | |
| 61 | /* |
| 62 | */ |
| 63 | static int hda_hwdep_ioctl(struct snd_hwdep *hw, struct file *file, |
| 64 | unsigned int cmd, unsigned long arg) |
| 65 | { |
| 66 | struct hda_codec *codec = hw->private_data; |
| 67 | void __user *argp = (void __user *)arg; |
| 68 | |
| 69 | switch (cmd) { |
| 70 | case HDA_IOCTL_PVERSION: |
| 71 | return put_user(HDA_HWDEP_VERSION, (int __user *)argp); |
| 72 | case HDA_IOCTL_VERB_WRITE: |
| 73 | return verb_write_ioctl(codec, argp); |
| 74 | case HDA_IOCTL_GET_WCAP: |
| 75 | return get_wcap_ioctl(codec, argp); |
| 76 | } |
| 77 | return -ENOIOCTLCMD; |
| 78 | } |
| 79 | |
| 80 | #ifdef CONFIG_COMPAT |
| 81 | static int hda_hwdep_ioctl_compat(struct snd_hwdep *hw, struct file *file, |
| 82 | unsigned int cmd, unsigned long arg) |
| 83 | { |
Takashi Iwai | 312d045 | 2007-07-31 11:08:10 +0200 | [diff] [blame] | 84 | return hda_hwdep_ioctl(hw, file, cmd, (unsigned long)compat_ptr(arg)); |
Takashi Iwai | 2807314 | 2007-07-27 18:58:06 +0200 | [diff] [blame] | 85 | } |
| 86 | #endif |
| 87 | |
| 88 | static int hda_hwdep_open(struct snd_hwdep *hw, struct file *file) |
| 89 | { |
Takashi Iwai | 62cf872 | 2008-05-20 12:15:15 +0200 | [diff] [blame] | 90 | #ifndef CONFIG_SND_DEBUG_VERBOSE |
Takashi Iwai | 2807314 | 2007-07-27 18:58:06 +0200 | [diff] [blame] | 91 | if (!capable(CAP_SYS_RAWIO)) |
| 92 | return -EACCES; |
| 93 | #endif |
| 94 | return 0; |
| 95 | } |
| 96 | |
Takashi Iwai | 6a0f56a | 2012-12-07 07:41:56 +0100 | [diff] [blame] | 97 | int snd_hda_create_hwdep(struct hda_codec *codec) |
Takashi Iwai | 2807314 | 2007-07-27 18:58:06 +0200 | [diff] [blame] | 98 | { |
| 99 | char hwname[16]; |
| 100 | struct snd_hwdep *hwdep; |
| 101 | int err; |
| 102 | |
| 103 | sprintf(hwname, "HDA Codec %d", codec->addr); |
| 104 | err = snd_hwdep_new(codec->bus->card, hwname, codec->addr, &hwdep); |
| 105 | if (err < 0) |
| 106 | return err; |
| 107 | codec->hwdep = hwdep; |
| 108 | sprintf(hwdep->name, "HDA Codec %d", codec->addr); |
| 109 | hwdep->iface = SNDRV_HWDEP_IFACE_HDA; |
| 110 | hwdep->private_data = codec; |
| 111 | hwdep->exclusive = 1; |
Takashi Iwai | caa751b | 2014-02-25 08:30:50 +0100 | [diff] [blame] | 112 | hwdep->groups = snd_hda_dev_attr_groups; |
Takashi Iwai | 2807314 | 2007-07-27 18:58:06 +0200 | [diff] [blame] | 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 | |
Takashi Iwai | 13aeaf6 | 2014-02-25 07:53:47 +0100 | [diff] [blame] | 120 | /* link to codec */ |
| 121 | hwdep->dev = &codec->dev; |
| 122 | |
Takashi Iwai | 2807314 | 2007-07-27 18:58:06 +0200 | [diff] [blame] | 123 | return 0; |
| 124 | } |