42 #include <linux/parport.h>
45 #include <linux/slab.h>
46 #include <linux/module.h>
52 #define CARD_NAME "Portman 2x4"
53 #define DRIVER_NAME "portman"
54 #define PLATFORM_DRIVER "snd_portman2x4"
61 static int device_count;
70 MODULE_AUTHOR(
"Levent Guendogdu, Tobias Gehrig, Matthias Koenig");
78 #define PORTMAN_NUM_INPUT_PORTS 2
79 #define PORTMAN_NUM_OUTPUT_PORTS 4
93 static int portman_free(
struct portman *
pm)
126 #define PP_STAT_BSY 0x80
127 #define PP_STAT_ACK 0x40
128 #define PP_STAT_POUT 0x20
129 #define PP_STAT_SEL 0x10
130 #define PP_STAT_ERR 0x08
133 #define PP_CMD_IEN 0x10
134 #define PP_CMD_SELI 0x08
135 #define PP_CMD_INIT 0x04
136 #define PP_CMD_FEED 0x02
137 #define PP_CMD_STB 0x01
140 #define INT_EN PP_CMD_IEN
141 #define STROBE PP_CMD_STB
148 #define RXDATA0 (0 << 1)
149 #define RXDATA1 (1 << 1)
150 #define GEN_CTL (2 << 1)
151 #define SYNC_CTL (3 << 1)
152 #define TXDATA0 (4 << 1)
153 #define TXDATA1 (5 << 1)
154 #define TXDATA2 (6 << 1)
155 #define TXDATA3 (7 << 1)
158 #define ESTB PP_STAT_POUT
159 #define INT_REQ PP_STAT_ACK
160 #define BUSY PP_STAT_ERR
170 #define RXAVAIL PP_STAT_SEL
172 #define SYNC_STAT PP_STAT_SEL
174 #define TXEMPTY PP_STAT_SEL
182 #define RXDATA PP_STAT_BSY
184 #define SYNC_DATA PP_STAT_BSY
186 #define DATA_ECHO PP_STAT_BSY
187 #define A0_ECHO PP_STAT_BSY
188 #define A1_ECHO PP_STAT_BSY
189 #define A2_ECHO PP_STAT_BSY
191 #define PORTMAN2X4_MODE_INPUT_TRIGGERED 0x01
196 static inline void portman_write_command(
struct portman *pm,
u8 value)
201 static inline u8 portman_read_command(
struct portman *pm)
206 static inline u8 portman_read_status(
struct portman *pm)
211 static inline u8 portman_read_data(
struct portman *pm)
216 static inline void portman_write_data(
struct portman *pm,
u8 value)
221 static void portman_write_midi(
struct portman *pm,
224 int command = ((port + 4) << 1);
243 portman_write_command(pm, command);
249 portman_write_data(pm, mididata);
254 }
while ((portman_read_status(pm) &
TXEMPTY) != TXEMPTY);
261 portman_write_command(pm, command |
STROBE);
268 while ((portman_read_status(pm) &
ESTB) == 0)
272 portman_write_command(pm, command);
274 while ((portman_read_status(pm) & ESTB) == ESTB)
281 while ((portman_read_status(pm) &
BUSY) == BUSY)
293 static int portman_read_midi(
struct portman *pm,
int port)
295 unsigned char midi_data = 0;
296 unsigned char cmdout;
299 portman_write_data(pm, 0);
302 cmdout = (port << 1) |
INT_EN;
303 portman_write_command(pm, cmdout);
305 while ((portman_read_status(pm) & ESTB) == ESTB)
311 if ((portman_read_status(pm) &
RXAVAIL) == 0)
315 portman_write_command(pm, cmdout |
STROBE);
317 while ((portman_read_status(pm) & ESTB) == 0)
321 midi_data = (portman_read_status(pm) & 128);
322 portman_write_data(pm, 1);
325 portman_write_data(pm, 0);
326 midi_data |= (portman_read_status(pm) >> 1) & 64;
327 portman_write_data(pm, 1);
330 portman_write_data(pm, 0);
331 midi_data |= (portman_read_status(pm) >> 2) & 32;
332 portman_write_data(pm, 1);
335 portman_write_data(pm, 0);
336 midi_data |= (portman_read_status(pm) >> 3) & 16;
337 portman_write_data(pm, 1);
340 portman_write_data(pm, 0);
341 midi_data |= (portman_read_status(pm) >> 4) & 8;
342 portman_write_data(pm, 1);
345 portman_write_data(pm, 0);
346 midi_data |= (portman_read_status(pm) >> 5) & 4;
347 portman_write_data(pm, 1);
350 portman_write_data(pm, 0);
351 midi_data |= (portman_read_status(pm) >> 6) & 2;
352 portman_write_data(pm, 1);
355 portman_write_data(pm, 0);
356 midi_data |= (portman_read_status(pm) >> 7) & 1;
357 portman_write_data(pm, 1);
358 portman_write_data(pm, 0);
362 portman_write_command(pm, cmdout);
365 while ((portman_read_status(pm) & ESTB) == ESTB)
368 return (midi_data & 255);
387 portman_write_command(pm, command);
389 if ((portman_read_status(pm) & RXAVAIL) == RXAVAIL)
400 static void portman_flush_input(
struct portman *pm,
unsigned char port)
404 unsigned char command = 0;
415 "portman_flush_input() Won't flush port %i\n",
421 portman_write_command(pm, command);
424 portman_write_command(pm, command |
STROBE);
427 while ((portman_read_status(pm) & ESTB) == 0)
431 portman_write_data(pm, 0);
434 for (i = 0; i < 250; i++) {
435 portman_write_data(pm, 1);
436 portman_write_data(pm, 0);
440 portman_write_command(pm, command |
INT_EN);
443 while ((portman_read_status(pm) & ESTB) == ESTB)
447 static int portman_probe(
struct parport *
p)
501 static int portman_device_init(
struct portman *pm)
503 portman_flush_input(pm, 0);
504 portman_flush_input(pm, 1);
533 spin_unlock_irqrestore(&pm->
reg_lock, flags);
546 portman_write_midi(pm, substream->
number, byte);
548 spin_unlock_irqrestore(&pm->
reg_lock, flags);
552 .open = snd_portman_midi_open,
553 .close = snd_portman_midi_close,
554 .trigger = snd_portman_midi_output_trigger,
558 .open = snd_portman_midi_open,
559 .close = snd_portman_midi_close,
560 .trigger = snd_portman_midi_input_trigger,
588 &snd_portman_midi_output);
590 &snd_portman_midi_input);
598 "Portman2x4 %d", substream->
number+1);
606 "Portman2x4 %d", substream->
number+1);
615 static void snd_portman_interrupt(
void *userdata)
617 unsigned char midivalue = 0;
623 while ((portman_read_status(pm) &
INT_REQ) == INT_REQ) {
626 if (portman_data_avail(pm, 0)) {
628 midivalue = portman_read_midi(pm, 0);
637 if (portman_data_avail(pm, 1)) {
639 midivalue = portman_read_midi(pm, 1);
667 res = portman_probe(p);
672 return res ? -
EIO : 0;
684 platform_set_drvdata(device, p);
693 if (!platform_get_drvdata(device)) {
699 platform_devices[device_count] = device;
703 static void snd_portman_detach(
struct parport *p)
709 .name =
"portman2x4",
710 .attach = snd_portman_attach,
711 .detach = snd_portman_detach
717 static void snd_portman_card_private_free(
struct snd_card *card)
740 p = platform_get_drvdata(pdev);
741 platform_set_drvdata(pdev,
NULL);
748 if ((err = snd_portman_probe_port(p)) < 0)
765 snd_portman_interrupt,
768 if (pardev ==
NULL) {
774 if ((err = portman_create(card, pardev, &pm)) < 0) {
782 if ((err = snd_portman_rawmidi_create(card)) < 0) {
783 snd_printd(
"Creating Rawmidi component failed\n");
796 if ((err = portman_device_init(pm)) < 0)
799 platform_set_drvdata(pdev, card);
819 struct snd_card *card = platform_get_drvdata(pdev);
829 .probe = snd_portman_probe,
840 static void snd_portman_unregister_all(
void)
845 if (platform_devices[i]) {
847 platform_devices[
i] =
NULL;
854 static int __init snd_portman_module_init(
void)
866 if (device_count == 0) {
867 snd_portman_unregister_all();
874 static void __exit snd_portman_module_exit(
void)
876 snd_portman_unregister_all();