2 * Driver for Digigram VXpocket soundcards
6 * Copyright (c) 2002 by Takashi Iwai <tiwai@suse.de>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #include <sound/driver.h>
24 #include <sound/core.h>
26 #include <pcmcia/ciscode.h>
27 #include <pcmcia/cisreg.h>
30 MODULE_AUTHOR("Takashi Iwai <tiwai@suse.de>");
31 MODULE_DESCRIPTION("Common routines for Digigram PCMCIA VX drivers");
32 MODULE_LICENSE("GPL");
37 static void vxpocket_config(dev_link_t *link);
38 static int vxpocket_event(event_t event, int priority, event_callback_args_t *args);
41 static void vxpocket_release(dev_link_t *link)
43 if (link->state & DEV_CONFIG) {
44 /* release cs resources */
45 pcmcia_release_configuration(link->handle);
46 pcmcia_release_io(link->handle, &link->io);
47 pcmcia_release_irq(link->handle, &link->irq);
48 link->state &= ~DEV_CONFIG;
55 static int snd_vxpocket_free(vx_core_t *chip)
57 struct snd_vxpocket *vxp = (struct snd_vxpocket *)chip;
58 struct snd_vxp_entry *hw;
59 dev_link_t *link = &vxp->link;
61 vxpocket_release(link);
63 /* Break the link with Card Services */
65 pcmcia_deregister_client(link->handle);
69 hw->card_list[vxp->index] = NULL;
76 static int snd_vxpocket_dev_free(snd_device_t *device)
78 vx_core_t *chip = device->device_data;
79 return snd_vxpocket_free(chip);
83 * snd_vxpocket_attach - attach callback for cs
84 * @hw: the hardware information
86 dev_link_t *snd_vxpocket_attach(struct snd_vxp_entry *hw)
88 client_reg_t client_reg; /* Register with cardmgr */
89 dev_link_t *link; /* Info for cardmgr */
92 struct snd_vxpocket *vxp;
94 static snd_device_ops_t ops = {
95 .dev_free = snd_vxpocket_dev_free,
98 snd_printdd(KERN_DEBUG "vxpocket_attach called\n");
99 /* find an empty slot from the card list */
100 for (i = 0; i < SNDRV_CARDS; i++) {
101 if (! hw->card_list[i])
104 if (i >= SNDRV_CARDS) {
105 snd_printk(KERN_ERR "vxpocket: too many cards found\n");
108 if (! hw->enable_table[i])
109 return NULL; /* disabled explicitly */
111 /* ok, create a card instance */
112 card = snd_card_new(hw->index_table[i], hw->id_table[i], THIS_MODULE, 0);
114 snd_printk(KERN_ERR "vxpocket: cannot create a card instance\n");
118 chip = snd_vx_create(card, hw->hardware, hw->ops,
119 sizeof(struct snd_vxpocket) - sizeof(vx_core_t));
123 if (snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops) < 0) {
129 vxp = (struct snd_vxpocket *)chip;
132 chip->ibl.size = hw->ibl[i];
133 hw->card_list[i] = chip;
138 link->io.Attributes1 = IO_DATA_PATH_WIDTH_AUTO;
139 link->io.NumPorts1 = 16;
141 link->irq.Attributes = IRQ_TYPE_EXCLUSIVE | IRQ_HANDLE_PRESENT;
142 // link->irq.Attributes = IRQ_TYPE_DYNAMIC_SHARING|IRQ_FIRST_SHARED;
144 link->irq.IRQInfo1 = IRQ_INFO2_VALID | IRQ_LEVEL_ID;
145 if (hw->irq_list[0] == -1)
146 link->irq.IRQInfo2 = *hw->irq_mask_p;
148 for (i = 0; i < 4; i++)
149 link->irq.IRQInfo2 |= 1 << hw->irq_list[i];
150 link->irq.Handler = &snd_vx_irq_handler;
151 link->irq.Instance = chip;
153 link->conf.Attributes = CONF_ENABLE_IRQ;
155 link->conf.IntType = INT_MEMORY_AND_IO;
156 link->conf.ConfigIndex = 1;
157 link->conf.Present = PRESENT_OPTION;
160 link->next = hw->dev_list;
163 /* Register with Card Services */
164 client_reg.dev_info = hw->dev_info;
165 client_reg.Attributes = INFO_IO_CLIENT | INFO_CARD_SHARE;
166 client_reg.EventMask =
167 CS_EVENT_CARD_INSERTION | CS_EVENT_CARD_REMOVAL
169 | CS_EVENT_RESET_PHYSICAL | CS_EVENT_CARD_RESET
170 | CS_EVENT_PM_SUSPEND | CS_EVENT_PM_RESUME
173 client_reg.event_handler = &vxpocket_event;
174 client_reg.Version = 0x0210;
175 client_reg.event_callback_args.client_data = link;
177 ret = pcmcia_register_client(&link->handle, &client_reg);
178 if (ret != CS_SUCCESS) {
179 cs_error(link->handle, RegisterClient, ret);
180 snd_vxpocket_detach(hw, link);
189 * snd_vxpocket_assign_resources - initialize the hardware and card instance.
190 * @port: i/o port for the card
191 * @irq: irq number for the card
193 * this function assigns the specified port and irq, boot the card,
194 * create pcm and control instances, and initialize the rest hardware.
196 * returns 0 if successful, or a negative error code.
198 static int snd_vxpocket_assign_resources(vx_core_t *chip, int port, int irq)
201 snd_card_t *card = chip->card;
202 struct snd_vxpocket *vxp = (struct snd_vxpocket *)chip;
204 snd_printdd(KERN_DEBUG "vxpocket assign resources: port = 0x%x, irq = %d\n", port, irq);
207 sprintf(card->shortname, "Digigram %s", card->driver);
208 sprintf(card->longname, "%s at 0x%x, irq %i",
209 card->shortname, port, irq);
211 if ((err = snd_vx_hwdep_new(chip)) < 0)
216 if ((err = snd_card_register(chip->card)) < 0)
224 * snd_vxpocket_detach - detach callback for cs
225 * @hw: the hardware information
227 void snd_vxpocket_detach(struct snd_vxp_entry *hw, dev_link_t *link)
229 vx_core_t *chip = link->priv;
231 snd_printdd(KERN_DEBUG "vxpocket_detach called\n");
232 /* Remove the interface data from the linked list */
235 /* Locate device structure */
236 for (linkp = &hw->dev_list; *linkp; linkp = &(*linkp)->next)
242 chip->chip_status |= VX_STAT_IS_STALE; /* to be sure */
243 snd_card_disconnect(chip->card);
244 snd_card_free_in_thread(chip->card);
248 * snd_vxpocket_detach_all - detach all instances linked to the hw
250 void snd_vxpocket_detach_all(struct snd_vxp_entry *hw)
252 while (hw->dev_list != NULL)
253 snd_vxpocket_detach(hw, hw->dev_list);
257 * configuration callback
260 #define CS_CHECK(fn, ret) \
261 do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0)
263 static void vxpocket_config(dev_link_t *link)
265 client_handle_t handle = link->handle;
266 vx_core_t *chip = link->priv;
267 struct snd_vxpocket *vxp = (struct snd_vxpocket *)chip;
272 int last_fn, last_ret;
274 snd_printdd(KERN_DEBUG "vxpocket_config called\n");
275 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY;
276 tuple.Attributes = 0;
277 tuple.TupleData = (cisdata_t *)buf;
278 tuple.TupleDataMax = sizeof(buf);
279 tuple.TupleOffset = 0;
280 tuple.DesiredTuple = CISTPL_CONFIG;
281 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(handle, &tuple));
282 CS_CHECK(GetTupleData, pcmcia_get_tuple_data(handle, &tuple));
283 CS_CHECK(ParseTuple, pcmcia_parse_tuple(handle, &tuple, &parse));
284 link->conf.ConfigBase = parse.config.base;
285 link->conf.ConfigIndex = 1;
287 CS_CHECK(GetConfigurationInfo, pcmcia_get_configuration_info(handle, &conf));
288 link->conf.Vcc = conf.Vcc;
291 link->state |= DEV_CONFIG;
293 CS_CHECK(RequestIO, pcmcia_request_io(handle, &link->io));
294 CS_CHECK(RequestIRQ, pcmcia_request_irq(link->handle, &link->irq));
295 CS_CHECK(RequestConfiguration, pcmcia_request_configuration(link->handle, &link->conf));
297 if (snd_vxpocket_assign_resources(chip, link->io.BasePort1, link->irq.AssignedIRQ) < 0)
300 link->dev = &vxp->node;
301 link->state &= ~DEV_CONFIG_PENDING;
305 cs_error(link->handle, last_fn, last_ret);
307 pcmcia_release_configuration(link->handle);
308 pcmcia_release_io(link->handle, &link->io);
309 pcmcia_release_irq(link->handle, &link->irq);
316 static int vxpocket_event(event_t event, int priority, event_callback_args_t *args)
318 dev_link_t *link = args->client_data;
319 vx_core_t *chip = link->priv;
322 case CS_EVENT_CARD_REMOVAL:
323 snd_printdd(KERN_DEBUG "CARD_REMOVAL..\n");
324 link->state &= ~DEV_PRESENT;
325 if (link->state & DEV_CONFIG) {
326 chip->chip_status |= VX_STAT_IS_STALE;
329 case CS_EVENT_CARD_INSERTION:
330 snd_printdd(KERN_DEBUG "CARD_INSERTION..\n");
331 link->state |= DEV_PRESENT;
332 vxpocket_config(link);
335 case CS_EVENT_PM_SUSPEND:
336 snd_printdd(KERN_DEBUG "SUSPEND\n");
337 link->state |= DEV_SUSPEND;
339 snd_printdd(KERN_DEBUG "snd_vx_suspend calling\n");
340 snd_vx_suspend(chip);
342 /* Fall through... */
343 case CS_EVENT_RESET_PHYSICAL:
344 snd_printdd(KERN_DEBUG "RESET_PHYSICAL\n");
345 if (link->state & DEV_CONFIG)
346 pcmcia_release_configuration(link->handle);
348 case CS_EVENT_PM_RESUME:
349 snd_printdd(KERN_DEBUG "RESUME\n");
350 link->state &= ~DEV_SUSPEND;
351 /* Fall through... */
352 case CS_EVENT_CARD_RESET:
353 snd_printdd(KERN_DEBUG "CARD_RESET\n");
355 //struct snd_vxpocket *vxp = (struct snd_vxpocket *)chip;
356 snd_printdd(KERN_DEBUG "requestconfig...\n");
357 pcmcia_request_configuration(link->handle, &link->conf);
359 snd_printdd(KERN_DEBUG "calling snd_vx_resume\n");
363 snd_printdd(KERN_DEBUG "resume done!\n");
373 EXPORT_SYMBOL(snd_vxpocket_ops);
374 EXPORT_SYMBOL(snd_vxpocket_attach);
375 EXPORT_SYMBOL(snd_vxpocket_detach);
376 EXPORT_SYMBOL(snd_vxpocket_detach_all);