PCI: SR-IOV quirk for Intel 82576 NIC
[linux-2.6/mini2440.git] / sound / core / jack.c
blobc8254c667c6247cef5e402161b0b1ef076782a5e
1 /*
2 * Jack abstraction layer
4 * Copyright 2008 Wolfson Microelectronics
6 * This program 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.
11 * This program 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.
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
22 #include <linux/input.h>
23 #include <sound/jack.h>
24 #include <sound/core.h>
26 static int jack_types[] = {
27 SW_HEADPHONE_INSERT,
28 SW_MICROPHONE_INSERT,
29 SW_LINEOUT_INSERT,
30 SW_JACK_PHYSICAL_INSERT,
31 SW_VIDEOOUT_INSERT,
34 static int snd_jack_dev_free(struct snd_device *device)
36 struct snd_jack *jack = device->device_data;
38 /* If the input device is registered with the input subsystem
39 * then we need to use a different deallocator. */
40 if (jack->registered)
41 input_unregister_device(jack->input_dev);
42 else
43 input_free_device(jack->input_dev);
45 kfree(jack->id);
46 kfree(jack);
48 return 0;
51 static int snd_jack_dev_register(struct snd_device *device)
53 struct snd_jack *jack = device->device_data;
54 struct snd_card *card = device->card;
55 int err;
57 snprintf(jack->name, sizeof(jack->name), "%s %s",
58 card->shortname, jack->id);
59 jack->input_dev->name = jack->name;
61 /* Default to the sound card device. */
62 if (!jack->input_dev->dev.parent)
63 jack->input_dev->dev.parent = card->dev;
65 err = input_register_device(jack->input_dev);
66 if (err == 0)
67 jack->registered = 1;
69 return err;
72 /**
73 * snd_jack_new - Create a new jack
74 * @card: the card instance
75 * @id: an identifying string for this jack
76 * @type: a bitmask of enum snd_jack_type values that can be detected by
77 * this jack
78 * @jjack: Used to provide the allocated jack object to the caller.
80 * Creates a new jack object.
82 * Returns zero if successful, or a negative error code on failure.
83 * On success jjack will be initialised.
85 int snd_jack_new(struct snd_card *card, const char *id, int type,
86 struct snd_jack **jjack)
88 struct snd_jack *jack;
89 int err;
90 int i;
91 static struct snd_device_ops ops = {
92 .dev_free = snd_jack_dev_free,
93 .dev_register = snd_jack_dev_register,
96 jack = kzalloc(sizeof(struct snd_jack), GFP_KERNEL);
97 if (jack == NULL)
98 return -ENOMEM;
100 jack->id = kstrdup(id, GFP_KERNEL);
102 jack->input_dev = input_allocate_device();
103 if (jack->input_dev == NULL) {
104 err = -ENOMEM;
105 goto fail_input;
108 jack->input_dev->phys = "ALSA";
110 jack->type = type;
112 for (i = 0; i < ARRAY_SIZE(jack_types); i++)
113 if (type & (1 << i))
114 input_set_capability(jack->input_dev, EV_SW,
115 jack_types[i]);
117 err = snd_device_new(card, SNDRV_DEV_JACK, jack, &ops);
118 if (err < 0)
119 goto fail_input;
121 *jjack = jack;
123 return 0;
125 fail_input:
126 input_free_device(jack->input_dev);
127 kfree(jack);
128 return err;
130 EXPORT_SYMBOL(snd_jack_new);
133 * snd_jack_set_parent - Set the parent device for a jack
135 * @jack: The jack to configure
136 * @parent: The device to set as parent for the jack.
138 * Set the parent for the jack input device in the device tree. This
139 * function is only valid prior to registration of the jack. If no
140 * parent is configured then the parent device will be the sound card.
142 void snd_jack_set_parent(struct snd_jack *jack, struct device *parent)
144 WARN_ON(jack->registered);
146 jack->input_dev->dev.parent = parent;
148 EXPORT_SYMBOL(snd_jack_set_parent);
151 * snd_jack_report - Report the current status of a jack
153 * @jack: The jack to report status for
154 * @status: The current status of the jack
156 void snd_jack_report(struct snd_jack *jack, int status)
158 int i;
160 if (!jack)
161 return;
163 for (i = 0; i < ARRAY_SIZE(jack_types); i++) {
164 int testbit = 1 << i;
165 if (jack->type & testbit)
166 input_report_switch(jack->input_dev, jack_types[i],
167 status & testbit);
170 input_sync(jack->input_dev);
172 EXPORT_SYMBOL(snd_jack_report);
174 MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>");
175 MODULE_DESCRIPTION("Jack detection support for ALSA");
176 MODULE_LICENSE("GPL");