2 * Driver for Midiman Portman2x4 parallel port midi interface
4 * Copyright (c) by Levent Guendogdu <levon@feature-it.com>
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., 675 Mass Ave, Cambridge, MA 02139, USA.
21 * Jan 24 2007 Matthias Koenig <mkoenig@suse.de>
22 * - cleanup and rewrite
23 * Sep 30 2004 Tobias Gehrig <tobias@gehrig.tk>
24 * - source code cleanup
25 * Sep 03 2004 Tobias Gehrig <tobias@gehrig.tk>
26 * - fixed compilation problem with alsa 1.0.6a (removed MODULE_CLASSES,
27 * MODULE_PARM_SYNTAX and changed MODULE_DEVICES to
28 * MODULE_SUPPORTED_DEVICE)
29 * Mar 24 2004 Tobias Gehrig <tobias@gehrig.tk>
30 * - added 2.6 kernel support
31 * Mar 18 2004 Tobias Gehrig <tobias@gehrig.tk>
32 * - added parport_unregister_driver to the startup routine if the driver fails to detect a portman
33 * - added support for all 4 output ports in portman_putmidi
34 * Mar 17 2004 Tobias Gehrig <tobias@gehrig.tk>
35 * - added checks for opened input device in interrupt handler
36 * Feb 20 2004 Tobias Gehrig <tobias@gehrig.tk>
37 * - ported from alsa 0.5 to 1.0
40 #include <linux/init.h>
41 #include <linux/platform_device.h>
42 #include <linux/parport.h>
43 #include <linux/spinlock.h>
44 #include <linux/delay.h>
45 #include <linux/slab.h>
46 #include <linux/module.h>
47 #include <sound/core.h>
48 #include <sound/initval.h>
49 #include <sound/rawmidi.h>
50 #include <sound/control.h>
52 #define CARD_NAME "Portman 2x4"
53 #define DRIVER_NAME "portman"
54 #define PLATFORM_DRIVER "snd_portman2x4"
56 static int index
[SNDRV_CARDS
] = SNDRV_DEFAULT_IDX
;
57 static char *id
[SNDRV_CARDS
] = SNDRV_DEFAULT_STR
;
58 static bool enable
[SNDRV_CARDS
] = SNDRV_DEFAULT_ENABLE_PNP
;
60 static struct platform_device
*platform_devices
[SNDRV_CARDS
];
61 static int device_count
;
63 module_param_array(index
, int, NULL
, S_IRUGO
);
64 MODULE_PARM_DESC(index
, "Index value for " CARD_NAME
" soundcard.");
65 module_param_array(id
, charp
, NULL
, S_IRUGO
);
66 MODULE_PARM_DESC(id
, "ID string for " CARD_NAME
" soundcard.");
67 module_param_array(enable
, bool, NULL
, S_IRUGO
);
68 MODULE_PARM_DESC(enable
, "Enable " CARD_NAME
" soundcard.");
70 MODULE_AUTHOR("Levent Guendogdu, Tobias Gehrig, Matthias Koenig");
71 MODULE_DESCRIPTION("Midiman Portman2x4");
72 MODULE_LICENSE("GPL");
73 MODULE_SUPPORTED_DEVICE("{{Midiman,Portman2x4}}");
75 /*********************************************************************
77 *********************************************************************/
78 #define PORTMAN_NUM_INPUT_PORTS 2
79 #define PORTMAN_NUM_OUTPUT_PORTS 4
83 struct snd_card
*card
;
84 struct snd_rawmidi
*rmidi
;
85 struct pardevice
*pardev
;
89 int mode
[PORTMAN_NUM_INPUT_PORTS
];
90 struct snd_rawmidi_substream
*midi_input
[PORTMAN_NUM_INPUT_PORTS
];
93 static int portman_free(struct portman
*pm
)
99 static int portman_create(struct snd_card
*card
,
100 struct pardevice
*pardev
,
101 struct portman
**rchip
)
107 pm
= kzalloc(sizeof(struct portman
), GFP_KERNEL
);
111 /* Init chip specific data */
112 spin_lock_init(&pm
->reg_lock
);
121 /*********************************************************************
122 * HW related constants
123 *********************************************************************/
125 /* Standard PC parallel port status register equates. */
126 #define PP_STAT_BSY 0x80 /* Busy status. Inverted. */
127 #define PP_STAT_ACK 0x40 /* Acknowledge. Non-Inverted. */
128 #define PP_STAT_POUT 0x20 /* Paper Out. Non-Inverted. */
129 #define PP_STAT_SEL 0x10 /* Select. Non-Inverted. */
130 #define PP_STAT_ERR 0x08 /* Error. Non-Inverted. */
132 /* Standard PC parallel port command register equates. */
133 #define PP_CMD_IEN 0x10 /* IRQ Enable. Non-Inverted. */
134 #define PP_CMD_SELI 0x08 /* Select Input. Inverted. */
135 #define PP_CMD_INIT 0x04 /* Init Printer. Non-Inverted. */
136 #define PP_CMD_FEED 0x02 /* Auto Feed. Inverted. */
137 #define PP_CMD_STB 0x01 /* Strobe. Inverted. */
139 /* Parallel Port Command Register as implemented by PCP2x4. */
140 #define INT_EN PP_CMD_IEN /* Interrupt enable. */
141 #define STROBE PP_CMD_STB /* Command strobe. */
143 /* The parallel port command register field (b1..b3) selects the
144 * various "registers" within the PC/P 2x4. These are the internal
145 * address of these "registers" that must be written to the parallel
146 * port command register.
148 #define RXDATA0 (0 << 1) /* PCP RxData channel 0. */
149 #define RXDATA1 (1 << 1) /* PCP RxData channel 1. */
150 #define GEN_CTL (2 << 1) /* PCP General Control Register. */
151 #define SYNC_CTL (3 << 1) /* PCP Sync Control Register. */
152 #define TXDATA0 (4 << 1) /* PCP TxData channel 0. */
153 #define TXDATA1 (5 << 1) /* PCP TxData channel 1. */
154 #define TXDATA2 (6 << 1) /* PCP TxData channel 2. */
155 #define TXDATA3 (7 << 1) /* PCP TxData channel 3. */
157 /* Parallel Port Status Register as implemented by PCP2x4. */
158 #define ESTB PP_STAT_POUT /* Echoed strobe. */
159 #define INT_REQ PP_STAT_ACK /* Input data int request. */
160 #define BUSY PP_STAT_ERR /* Interface Busy. */
162 /* Parallel Port Status Register BUSY and SELECT lines are multiplexed
163 * between several functions. Depending on which 2x4 "register" is
164 * currently selected (b1..b3), the BUSY and SELECT lines are
165 * assigned as follows:
167 * SELECT LINE: A3 A2 A1
170 #define RXAVAIL PP_STAT_SEL /* Rx Available, channel 0. 0 0 0 */
171 // RXAVAIL1 PP_STAT_SEL /* Rx Available, channel 1. 0 0 1 */
172 #define SYNC_STAT PP_STAT_SEL /* Reserved - Sync Status. 0 1 0 */
173 // /* Reserved. 0 1 1 */
174 #define TXEMPTY PP_STAT_SEL /* Tx Empty, channel 0. 1 0 0 */
175 // TXEMPTY1 PP_STAT_SEL /* Tx Empty, channel 1. 1 0 1 */
176 // TXEMPTY2 PP_STAT_SEL /* Tx Empty, channel 2. 1 1 0 */
177 // TXEMPTY3 PP_STAT_SEL /* Tx Empty, channel 3. 1 1 1 */
179 /* BUSY LINE: A3 A2 A1
182 #define RXDATA PP_STAT_BSY /* Rx Input Data, channel 0. 0 0 0 */
183 // RXDATA1 PP_STAT_BSY /* Rx Input Data, channel 1. 0 0 1 */
184 #define SYNC_DATA PP_STAT_BSY /* Reserved - Sync Data. 0 1 0 */
185 /* Reserved. 0 1 1 */
186 #define DATA_ECHO PP_STAT_BSY /* Parallel Port Data Echo. 1 0 0 */
187 #define A0_ECHO PP_STAT_BSY /* Address 0 Echo. 1 0 1 */
188 #define A1_ECHO PP_STAT_BSY /* Address 1 Echo. 1 1 0 */
189 #define A2_ECHO PP_STAT_BSY /* Address 2 Echo. 1 1 1 */
191 #define PORTMAN2X4_MODE_INPUT_TRIGGERED 0x01
193 /*********************************************************************
194 * Hardware specific functions
195 *********************************************************************/
196 static inline void portman_write_command(struct portman
*pm
, u8 value
)
198 parport_write_control(pm
->pardev
->port
, value
);
201 static inline u8
portman_read_command(struct portman
*pm
)
203 return parport_read_control(pm
->pardev
->port
);
206 static inline u8
portman_read_status(struct portman
*pm
)
208 return parport_read_status(pm
->pardev
->port
);
211 static inline u8
portman_read_data(struct portman
*pm
)
213 return parport_read_data(pm
->pardev
->port
);
216 static inline void portman_write_data(struct portman
*pm
, u8 value
)
218 parport_write_data(pm
->pardev
->port
, value
);
221 static void portman_write_midi(struct portman
*pm
,
222 int port
, u8 mididata
)
224 int command
= ((port
+ 4) << 1);
226 /* Get entering data byte and port number in BL and BH respectively.
227 * Set up Tx Channel address field for use with PP Cmd Register.
228 * Store address field in BH register.
229 * Inputs: AH = Output port number (0..3).
231 * command = TXDATA0 | INT_EN;
232 * Align port num with address field (b1...b3),
233 * set address for TXDatax, Strobe=0
237 /* Disable interrupts so that the process is not interrupted, then
238 * write the address associated with the current Tx channel to the
239 * PP Command Reg. Do not set the Strobe signal yet.
243 portman_write_command(pm
, command
);
245 /* While the address lines settle, write parallel output data to
246 * PP Data Reg. This has no effect until Strobe signal is asserted.
249 portman_write_data(pm
, mididata
);
251 /* If PCP channel's TxEmpty is set (TxEmpty is read through the PP
252 * Status Register), then go write data. Else go back and wait.
254 } while ((portman_read_status(pm
) & TXEMPTY
) != TXEMPTY
);
256 /* TxEmpty is set. Maintain PC/P destination address and assert
257 * Strobe through the PP Command Reg. This will Strobe data into
258 * the PC/P transmitter and set the PC/P BUSY signal.
261 portman_write_command(pm
, command
| STROBE
);
263 /* Wait for strobe line to settle and echo back through hardware.
264 * Once it has echoed back, assume that the address and data lines
268 while ((portman_read_status(pm
) & ESTB
) == 0)
271 /* Release strobe and immediately re-allow interrupts. */
272 portman_write_command(pm
, command
);
274 while ((portman_read_status(pm
) & ESTB
) == ESTB
)
277 /* PC/P BUSY is now set. We must wait until BUSY resets itself.
278 * We'll reenable ints while we're waiting.
281 while ((portman_read_status(pm
) & BUSY
) == BUSY
)
289 * Read MIDI byte from port
290 * Attempt to read input byte from specified hardware input port (0..).
291 * Return -1 if no data
293 static int portman_read_midi(struct portman
*pm
, int port
)
295 unsigned char midi_data
= 0;
296 unsigned char cmdout
; /* Saved address+IE bit. */
298 /* Make sure clocking edge is down before starting... */
299 portman_write_data(pm
, 0); /* Make sure edge is down. */
301 /* Set destination address to PCP. */
302 cmdout
= (port
<< 1) | INT_EN
; /* Address + IE + No Strobe. */
303 portman_write_command(pm
, cmdout
);
305 while ((portman_read_status(pm
) & ESTB
) == ESTB
)
306 cpu_relax(); /* Wait for strobe echo. */
308 /* After the address lines settle, check multiplexed RxAvail signal.
309 * If data is available, read it.
311 if ((portman_read_status(pm
) & RXAVAIL
) == 0)
312 return -1; /* No data. */
314 /* Set the Strobe signal to enable the Rx clocking circuitry. */
315 portman_write_command(pm
, cmdout
| STROBE
); /* Write address+IE+Strobe. */
317 while ((portman_read_status(pm
) & ESTB
) == 0)
318 cpu_relax(); /* Wait for strobe echo. */
320 /* The first data bit (msb) is already sitting on the input line. */
321 midi_data
= (portman_read_status(pm
) & 128);
322 portman_write_data(pm
, 1); /* Cause rising edge, which shifts data. */
325 portman_write_data(pm
, 0); /* Cause falling edge while data settles. */
326 midi_data
|= (portman_read_status(pm
) >> 1) & 64;
327 portman_write_data(pm
, 1); /* Cause rising edge, which shifts data. */
330 portman_write_data(pm
, 0); /* Cause falling edge while data settles. */
331 midi_data
|= (portman_read_status(pm
) >> 2) & 32;
332 portman_write_data(pm
, 1); /* Cause rising edge, which shifts data. */
335 portman_write_data(pm
, 0); /* Cause falling edge while data settles. */
336 midi_data
|= (portman_read_status(pm
) >> 3) & 16;
337 portman_write_data(pm
, 1); /* Cause rising edge, which shifts data. */
340 portman_write_data(pm
, 0); /* Cause falling edge while data settles. */
341 midi_data
|= (portman_read_status(pm
) >> 4) & 8;
342 portman_write_data(pm
, 1); /* Cause rising edge, which shifts data. */
345 portman_write_data(pm
, 0); /* Cause falling edge while data settles. */
346 midi_data
|= (portman_read_status(pm
) >> 5) & 4;
347 portman_write_data(pm
, 1); /* Cause rising edge, which shifts data. */
350 portman_write_data(pm
, 0); /* Cause falling edge while data settles. */
351 midi_data
|= (portman_read_status(pm
) >> 6) & 2;
352 portman_write_data(pm
, 1); /* Cause rising edge, which shifts data. */
355 portman_write_data(pm
, 0); /* Cause falling edge while data settles. */
356 midi_data
|= (portman_read_status(pm
) >> 7) & 1;
357 portman_write_data(pm
, 1); /* Cause rising edge, which shifts data. */
358 portman_write_data(pm
, 0); /* Return data clock low. */
361 /* De-assert Strobe and return data. */
362 portman_write_command(pm
, cmdout
); /* Output saved address+IE. */
364 /* Wait for strobe echo. */
365 while ((portman_read_status(pm
) & ESTB
) == ESTB
)
368 return (midi_data
& 255); /* Shift back and return value. */
372 * Checks if any input data on the given channel is available
375 static int portman_data_avail(struct portman
*pm
, int channel
)
377 int command
= INT_EN
;
386 /* Write hardware (assumme STROBE=0) */
387 portman_write_command(pm
, command
);
388 /* Check multiplexed RxAvail signal */
389 if ((portman_read_status(pm
) & RXAVAIL
) == RXAVAIL
)
390 return 1; /* Data available */
392 /* No Data available */
400 static void portman_flush_input(struct portman
*pm
, unsigned char port
)
402 /* Local variable for counting things */
404 unsigned char command
= 0;
414 snd_printk(KERN_WARNING
415 "portman_flush_input() Won't flush port %i\n",
420 /* Set address for specified channel in port and allow to settle. */
421 portman_write_command(pm
, command
);
423 /* Assert the Strobe and wait for echo back. */
424 portman_write_command(pm
, command
| STROBE
);
427 while ((portman_read_status(pm
) & ESTB
) == 0)
430 /* Output clock cycles to the Rx circuitry. */
431 portman_write_data(pm
, 0);
433 /* Flush 250 bits... */
434 for (i
= 0; i
< 250; i
++) {
435 portman_write_data(pm
, 1);
436 portman_write_data(pm
, 0);
439 /* Deassert the Strobe signal of the port and wait for it to settle. */
440 portman_write_command(pm
, command
| INT_EN
);
442 /* Wait for settling */
443 while ((portman_read_status(pm
) & ESTB
) == ESTB
)
447 static int portman_probe(struct parport
*p
)
449 /* Initialize the parallel port data register. Will set Rx clocks
450 * low in case we happen to be addressing the Rx ports at this time.
453 parport_write_data(p
, 0);
455 /* Initialize the parallel port command register, thus initializing
456 * hardware handshake lines to midi box:
459 * Interrupt Enable = 0
462 parport_write_control(p
, 0);
464 /* Check if Portman PC/P 2x4 is out there. */
466 parport_write_control(p
, RXDATA0
); /* Write Strobe=0 to command reg. */
468 /* Check for ESTB to be clear */
470 if ((parport_read_status(p
) & ESTB
) == ESTB
)
471 return 1; /* CODE 1 - Strobe Failure. */
473 /* Set for RXDATA0 where no damage will be done. */
475 parport_write_control(p
, RXDATA0
+ STROBE
); /* Write Strobe=1 to command reg. */
478 if ((parport_read_status(p
) & ESTB
) != ESTB
)
479 return 1; /* CODE 1 - Strobe Failure. */
482 parport_write_control(p
, 0); /* Reset Strobe=0. */
484 /* Check if Tx circuitry is functioning properly. If initialized
485 * unit TxEmpty is false, send out char and see if if goes true.
488 parport_write_control(p
, TXDATA0
); /* Tx channel 0, strobe off. */
490 /* If PCP channel's TxEmpty is set (TxEmpty is read through the PP
491 * Status Register), then go write data. Else go back and wait.
494 if ((parport_read_status(p
) & TXEMPTY
) == 0)
497 /* Return OK status. */
501 static int portman_device_init(struct portman
*pm
)
503 portman_flush_input(pm
, 0);
504 portman_flush_input(pm
, 1);
509 /*********************************************************************
511 *********************************************************************/
512 static int snd_portman_midi_open(struct snd_rawmidi_substream
*substream
)
517 static int snd_portman_midi_close(struct snd_rawmidi_substream
*substream
)
522 static void snd_portman_midi_input_trigger(struct snd_rawmidi_substream
*substream
,
525 struct portman
*pm
= substream
->rmidi
->private_data
;
528 spin_lock_irqsave(&pm
->reg_lock
, flags
);
530 pm
->mode
[substream
->number
] |= PORTMAN2X4_MODE_INPUT_TRIGGERED
;
532 pm
->mode
[substream
->number
] &= ~PORTMAN2X4_MODE_INPUT_TRIGGERED
;
533 spin_unlock_irqrestore(&pm
->reg_lock
, flags
);
536 static void snd_portman_midi_output_trigger(struct snd_rawmidi_substream
*substream
,
539 struct portman
*pm
= substream
->rmidi
->private_data
;
543 spin_lock_irqsave(&pm
->reg_lock
, flags
);
545 while ((snd_rawmidi_transmit(substream
, &byte
, 1) == 1))
546 portman_write_midi(pm
, substream
->number
, byte
);
548 spin_unlock_irqrestore(&pm
->reg_lock
, flags
);
551 static struct snd_rawmidi_ops snd_portman_midi_output
= {
552 .open
= snd_portman_midi_open
,
553 .close
= snd_portman_midi_close
,
554 .trigger
= snd_portman_midi_output_trigger
,
557 static struct snd_rawmidi_ops snd_portman_midi_input
= {
558 .open
= snd_portman_midi_open
,
559 .close
= snd_portman_midi_close
,
560 .trigger
= snd_portman_midi_input_trigger
,
563 /* Create and initialize the rawmidi component */
564 static int snd_portman_rawmidi_create(struct snd_card
*card
)
566 struct portman
*pm
= card
->private_data
;
567 struct snd_rawmidi
*rmidi
;
568 struct snd_rawmidi_substream
*substream
;
571 err
= snd_rawmidi_new(card
, CARD_NAME
, 0,
572 PORTMAN_NUM_OUTPUT_PORTS
,
573 PORTMAN_NUM_INPUT_PORTS
,
578 rmidi
->private_data
= pm
;
579 strcpy(rmidi
->name
, CARD_NAME
);
580 rmidi
->info_flags
= SNDRV_RAWMIDI_INFO_OUTPUT
|
581 SNDRV_RAWMIDI_INFO_INPUT
|
582 SNDRV_RAWMIDI_INFO_DUPLEX
;
586 /* register rawmidi ops */
587 snd_rawmidi_set_ops(rmidi
, SNDRV_RAWMIDI_STREAM_OUTPUT
,
588 &snd_portman_midi_output
);
589 snd_rawmidi_set_ops(rmidi
, SNDRV_RAWMIDI_STREAM_INPUT
,
590 &snd_portman_midi_input
);
592 /* name substreams */
594 list_for_each_entry(substream
,
595 &rmidi
->streams
[SNDRV_RAWMIDI_STREAM_OUTPUT
].substreams
,
597 sprintf(substream
->name
,
598 "Portman2x4 %d", substream
->number
+1);
601 list_for_each_entry(substream
,
602 &rmidi
->streams
[SNDRV_RAWMIDI_STREAM_INPUT
].substreams
,
604 pm
->midi_input
[substream
->number
] = substream
;
605 sprintf(substream
->name
,
606 "Portman2x4 %d", substream
->number
+1);
612 /*********************************************************************
614 *********************************************************************/
615 static void snd_portman_interrupt(void *userdata
)
617 unsigned char midivalue
= 0;
618 struct portman
*pm
= ((struct snd_card
*)userdata
)->private_data
;
620 spin_lock(&pm
->reg_lock
);
622 /* While any input data is waiting */
623 while ((portman_read_status(pm
) & INT_REQ
) == INT_REQ
) {
624 /* If data available on channel 0,
625 read it and stuff it into the queue. */
626 if (portman_data_avail(pm
, 0)) {
628 midivalue
= portman_read_midi(pm
, 0);
629 /* put midi into queue... */
630 if (pm
->mode
[0] & PORTMAN2X4_MODE_INPUT_TRIGGERED
)
631 snd_rawmidi_receive(pm
->midi_input
[0],
635 /* If data available on channel 1,
636 read it and stuff it into the queue. */
637 if (portman_data_avail(pm
, 1)) {
639 midivalue
= portman_read_midi(pm
, 1);
640 /* put midi into queue... */
641 if (pm
->mode
[1] & PORTMAN2X4_MODE_INPUT_TRIGGERED
)
642 snd_rawmidi_receive(pm
->midi_input
[1],
648 spin_unlock(&pm
->reg_lock
);
651 static int snd_portman_probe_port(struct parport
*p
)
653 struct pardevice
*pardev
;
656 pardev
= parport_register_device(p
, DRIVER_NAME
,
662 if (parport_claim(pardev
)) {
663 parport_unregister_device(pardev
);
667 res
= portman_probe(p
);
669 parport_release(pardev
);
670 parport_unregister_device(pardev
);
672 return res
? -EIO
: 0;
675 static void snd_portman_attach(struct parport
*p
)
677 struct platform_device
*device
;
679 device
= platform_device_alloc(PLATFORM_DRIVER
, device_count
);
683 /* Temporary assignment to forward the parport */
684 platform_set_drvdata(device
, p
);
686 if (platform_device_add(device
) < 0) {
687 platform_device_put(device
);
691 /* Since we dont get the return value of probe
692 * We need to check if device probing succeeded or not */
693 if (!platform_get_drvdata(device
)) {
694 platform_device_unregister(device
);
698 /* register device in global table */
699 platform_devices
[device_count
] = device
;
703 static void snd_portman_detach(struct parport
*p
)
705 /* nothing to do here */
708 static struct parport_driver portman_parport_driver
= {
709 .name
= "portman2x4",
710 .attach
= snd_portman_attach
,
711 .detach
= snd_portman_detach
714 /*********************************************************************
716 *********************************************************************/
717 static void snd_portman_card_private_free(struct snd_card
*card
)
719 struct portman
*pm
= card
->private_data
;
720 struct pardevice
*pardev
= pm
->pardev
;
723 if (pm
->pardev_claimed
)
724 parport_release(pardev
);
725 parport_unregister_device(pardev
);
731 static int snd_portman_probe(struct platform_device
*pdev
)
733 struct pardevice
*pardev
;
736 struct snd_card
*card
= NULL
;
737 struct portman
*pm
= NULL
;
740 p
= platform_get_drvdata(pdev
);
741 platform_set_drvdata(pdev
, NULL
);
743 if (dev
>= SNDRV_CARDS
)
748 if ((err
= snd_portman_probe_port(p
)) < 0)
751 err
= snd_card_new(&pdev
->dev
, index
[dev
], id
[dev
], THIS_MODULE
,
754 snd_printd("Cannot create card\n");
757 strcpy(card
->driver
, DRIVER_NAME
);
758 strcpy(card
->shortname
, CARD_NAME
);
759 sprintf(card
->longname
, "%s at 0x%lx, irq %i",
760 card
->shortname
, p
->base
, p
->irq
);
762 pardev
= parport_register_device(p
, /* port */
763 DRIVER_NAME
, /* name */
766 snd_portman_interrupt
, /* ISR */
767 PARPORT_DEV_EXCL
, /* flags */
768 (void *)card
); /* private */
769 if (pardev
== NULL
) {
770 snd_printd("Cannot register pardevice\n");
775 if ((err
= portman_create(card
, pardev
, &pm
)) < 0) {
776 snd_printd("Cannot create main component\n");
777 parport_unregister_device(pardev
);
780 card
->private_data
= pm
;
781 card
->private_free
= snd_portman_card_private_free
;
783 if ((err
= snd_portman_rawmidi_create(card
)) < 0) {
784 snd_printd("Creating Rawmidi component failed\n");
789 if (parport_claim(pardev
)) {
790 snd_printd("Cannot claim parport 0x%lx\n", pardev
->port
->base
);
794 pm
->pardev_claimed
= 1;
797 if ((err
= portman_device_init(pm
)) < 0)
800 platform_set_drvdata(pdev
, card
);
802 /* At this point card will be usable */
803 if ((err
= snd_card_register(card
)) < 0) {
804 snd_printd("Cannot register card\n");
808 snd_printk(KERN_INFO
"Portman 2x4 on 0x%lx\n", p
->base
);
816 static int snd_portman_remove(struct platform_device
*pdev
)
818 struct snd_card
*card
= platform_get_drvdata(pdev
);
827 static struct platform_driver snd_portman_driver
= {
828 .probe
= snd_portman_probe
,
829 .remove
= snd_portman_remove
,
831 .name
= PLATFORM_DRIVER
,
835 /*********************************************************************
837 *********************************************************************/
838 static void snd_portman_unregister_all(void)
842 for (i
= 0; i
< SNDRV_CARDS
; ++i
) {
843 if (platform_devices
[i
]) {
844 platform_device_unregister(platform_devices
[i
]);
845 platform_devices
[i
] = NULL
;
848 platform_driver_unregister(&snd_portman_driver
);
849 parport_unregister_driver(&portman_parport_driver
);
852 static int __init
snd_portman_module_init(void)
856 if ((err
= platform_driver_register(&snd_portman_driver
)) < 0)
859 if (parport_register_driver(&portman_parport_driver
) != 0) {
860 platform_driver_unregister(&snd_portman_driver
);
864 if (device_count
== 0) {
865 snd_portman_unregister_all();
872 static void __exit
snd_portman_module_exit(void)
874 snd_portman_unregister_all();
877 module_init(snd_portman_module_init
);
878 module_exit(snd_portman_module_exit
);