Lines Matching refs:devc

84 static inline int mpu401_status(struct mpu_config *devc)  in mpu401_status()  argument
86 return inb(STATPORT(devc->base)); in mpu401_status()
89 #define input_avail(devc) (!(mpu401_status(devc)&INPUT_AVAIL)) argument
90 #define output_ready(devc) (!(mpu401_status(devc)&OUTPUT_READY)) argument
92 static inline void write_command(struct mpu_config *devc, unsigned char cmd) in write_command() argument
94 outb(cmd, COMDPORT(devc->base)); in write_command()
97 static inline int read_data(struct mpu_config *devc) in read_data() argument
99 return inb(DATAPORT(devc->base)); in read_data()
102 static inline void write_data(struct mpu_config *devc, unsigned char byte) in write_data() argument
104 outb(byte, DATAPORT(devc->base)); in write_data()
117 static int reset_mpu401(struct mpu_config *devc);
118 static void set_uart_mode(int dev, struct mpu_config *devc, int arg);
122 static void timer_ext_event(struct mpu_config *devc, int event, int parm);
175 static int mpu_input_scanner(struct mpu_config *devc, unsigned char midic) in mpu_input_scanner() argument
178 switch (devc->m_state) in mpu_input_scanner()
192 if (devc->timer_flag) in mpu_input_scanner()
215 devc->m_state = ST_SYSMSG; in mpu_input_scanner()
222 devc->m_state = ST_TIMED; in mpu_input_scanner()
233 devc->m_state = ST_DATABYTE; in mpu_input_scanner()
238 msg = ((int) (devc->last_status & 0xf0) >> 4); in mpu_input_scanner()
240 devc->m_left = len_tab[msg] - 1; in mpu_input_scanner()
242 devc->m_ptr = 2; in mpu_input_scanner()
243 devc->m_buf[0] = devc->last_status; in mpu_input_scanner()
244 devc->m_buf[1] = midic; in mpu_input_scanner()
246 if (devc->m_left <= 0) in mpu_input_scanner()
248 devc->m_state = ST_INIT; in mpu_input_scanner()
249 do_midi_msg(devc->synthno, devc->m_buf, devc->m_ptr); in mpu_input_scanner()
250 devc->m_ptr = 0; in mpu_input_scanner()
255 devc->m_state = ST_INIT; in mpu_input_scanner()
277 devc->last_status = midic; in mpu_input_scanner()
280 devc->m_left = len_tab[msg]; in mpu_input_scanner()
282 devc->m_ptr = 1; in mpu_input_scanner()
283 devc->m_buf[0] = midic; in mpu_input_scanner()
285 if (devc->m_left <= 0) in mpu_input_scanner()
287 devc->m_state = ST_INIT; in mpu_input_scanner()
288 do_midi_msg(devc->synthno, devc->m_buf, devc->m_ptr); in mpu_input_scanner()
289 devc->m_ptr = 0; in mpu_input_scanner()
300 devc->m_state = ST_SYSEX; in mpu_input_scanner()
304 devc->m_state = ST_MTC; in mpu_input_scanner()
308 devc->m_state = ST_SONGPOS; in mpu_input_scanner()
309 devc->m_ptr = 0; in mpu_input_scanner()
313 devc->m_state = ST_SONGSEL; in mpu_input_scanner()
318 devc->m_state = ST_INIT; in mpu_input_scanner()
325 devc->m_state = ST_INIT; in mpu_input_scanner()
326 timer_ext_event(devc, TMR_CLOCK, 0); in mpu_input_scanner()
330 devc->m_state = ST_INIT; in mpu_input_scanner()
331 timer_ext_event(devc, TMR_START, 0); in mpu_input_scanner()
335 devc->m_state = ST_INIT; in mpu_input_scanner()
336 timer_ext_event(devc, TMR_CONTINUE, 0); in mpu_input_scanner()
340 devc->m_state = ST_INIT; in mpu_input_scanner()
341 timer_ext_event(devc, TMR_STOP, 0); in mpu_input_scanner()
346 devc->m_state = ST_INIT; in mpu_input_scanner()
351 devc->m_state = ST_INIT; in mpu_input_scanner()
356 devc->m_state = ST_INIT; in mpu_input_scanner()
361 devc->m_state = ST_INIT; in mpu_input_scanner()
369 devc->m_state = ST_INIT; in mpu_input_scanner()
376 BUFTEST(devc); in mpu_input_scanner()
377 devc->m_buf[devc->m_ptr++] = midic; in mpu_input_scanner()
378 if (devc->m_ptr == 2) in mpu_input_scanner()
380 devc->m_state = ST_INIT; in mpu_input_scanner()
381 devc->m_ptr = 0; in mpu_input_scanner()
382 timer_ext_event(devc, TMR_SPP, in mpu_input_scanner()
383 ((devc->m_buf[1] & 0x7f) << 7) | in mpu_input_scanner()
384 (devc->m_buf[0] & 0x7f)); in mpu_input_scanner()
389 BUFTEST(devc); in mpu_input_scanner()
390 devc->m_buf[devc->m_ptr++] = midic; in mpu_input_scanner()
391 if ((--devc->m_left) <= 0) in mpu_input_scanner()
393 devc->m_state = ST_INIT; in mpu_input_scanner()
394 do_midi_msg(devc->synthno, devc->m_buf, devc->m_ptr); in mpu_input_scanner()
395 devc->m_ptr = 0; in mpu_input_scanner()
400 printk("Bad state %d ", devc->m_state); in mpu_input_scanner()
401 devc->m_state = ST_INIT; in mpu_input_scanner()
406 static void mpu401_input_loop(struct mpu_config *devc) in mpu401_input_loop() argument
412 spin_lock_irqsave(&devc->lock,flags); in mpu401_input_loop()
413 busy = devc->m_busy; in mpu401_input_loop()
414 devc->m_busy = 1; in mpu401_input_loop()
415 spin_unlock_irqrestore(&devc->lock,flags); in mpu401_input_loop()
422 while (input_avail(devc) && n-- > 0) in mpu401_input_loop()
424 unsigned char c = read_data(devc); in mpu401_input_loop()
426 if (devc->mode == MODE_SYNTH) in mpu401_input_loop()
428 mpu_input_scanner(devc, c); in mpu401_input_loop()
430 else if (devc->opened & OPEN_READ && devc->inputintr != NULL) in mpu401_input_loop()
431 devc->inputintr(devc->devno, c); in mpu401_input_loop()
433 devc->m_busy = 0; in mpu401_input_loop()
438 struct mpu_config *devc; in mpuintr() local
442 devc = &dev_conf[dev]; in mpuintr()
444 if (input_avail(devc)) in mpuintr()
447 if (devc->base != 0 && (devc->opened & OPEN_READ || devc->mode == MODE_SYNTH)) in mpuintr()
448 mpu401_input_loop(devc); in mpuintr()
452 read_data(devc); in mpuintr()
464 struct mpu_config *devc; in mpu401_open() local
470 devc = &dev_conf[dev]; in mpu401_open()
472 if (devc->opened) in mpu401_open()
481 if (!devc->initialized) in mpu401_open()
483 if (mpu401_status(devc) == 0xff) /* Bus float */ in mpu401_open()
488 reset_mpu401(devc); in mpu401_open()
498 if ((err = coprocessor->open(coprocessor->devc, COPR_MIDI)) < 0) in mpu401_open()
506 set_uart_mode(dev, devc, 1); in mpu401_open()
507 devc->mode = MODE_MIDI; in mpu401_open()
508 devc->synthno = 0; in mpu401_open()
510 mpu401_input_loop(devc); in mpu401_open()
512 devc->inputintr = input; in mpu401_open()
513 devc->opened = mode; in mpu401_open()
520 struct mpu_config *devc; in mpu401_close() local
523 devc = &dev_conf[dev]; in mpu401_close()
524 if (devc->uart_mode) in mpu401_close()
525 reset_mpu401(devc); /* in mpu401_close()
528 devc->mode = 0; in mpu401_close()
529 devc->inputintr = NULL; in mpu401_close()
533 coprocessor->close(coprocessor->devc, COPR_MIDI); in mpu401_close()
536 devc->opened = 0; in mpu401_close()
544 struct mpu_config *devc; in mpu401_out() local
546 devc = &dev_conf[dev]; in mpu401_out()
553 for (timeout = 30000; timeout > 0 && !output_ready(devc); timeout--); in mpu401_out()
555 spin_lock_irqsave(&devc->lock,flags); in mpu401_out()
556 if (!output_ready(devc)) in mpu401_out()
559 spin_unlock_irqrestore(&devc->lock,flags); in mpu401_out()
562 write_data(devc, midi_byte); in mpu401_out()
563 spin_unlock_irqrestore(&devc->lock,flags); in mpu401_out()
572 struct mpu_config *devc; in mpu401_command() local
574 devc = &dev_conf[dev]; in mpu401_command()
576 if (devc->uart_mode) /* in mpu401_command()
586 if (input_avail(devc)) in mpu401_command()
587 mpu401_input_loop(devc); in mpu401_command()
601 spin_lock_irqsave(&devc->lock,flags); in mpu401_command()
603 if (!output_ready(devc)) in mpu401_command()
605 spin_unlock_irqrestore(&devc->lock,flags); in mpu401_command()
608 write_command(devc, cmd->cmd); in mpu401_command()
613 if (input_avail(devc)) in mpu401_command()
615 if (devc->opened && devc->mode == MODE_SYNTH) in mpu401_command()
617 if (mpu_input_scanner(devc, read_data(devc)) == MPU_ACK) in mpu401_command()
623 if (read_data(devc) == MPU_ACK) in mpu401_command()
630 spin_unlock_irqrestore(&devc->lock,flags); in mpu401_command()
637 for (timeout = 3000; timeout > 0 && !output_ready(devc); timeout--); in mpu401_command()
641 spin_unlock_irqrestore(&devc->lock,flags); in mpu401_command()
656 if (input_avail(devc)) in mpu401_command()
658 cmd->data[i] = read_data(devc); in mpu401_command()
663 spin_unlock_irqrestore(&devc->lock,flags); in mpu401_command()
668 spin_unlock_irqrestore(&devc->lock,flags); in mpu401_command()
690 struct mpu_config *devc = &dev_conf[dev]; in mpu401_prefix_cmd() local
692 if (devc->uart_mode) in mpu401_prefix_cmd()
725 struct mpu_config *devc; in mpu401_ioctl() local
729 devc = &dev_conf[dev]; in mpu401_ioctl()
733 if (!(devc->capabilities & MPU_CAP_INTLG)) { /* No intelligent mode */ in mpu401_ioctl()
739 set_uart_mode(dev, devc, !val); in mpu401_ioctl()
770 struct mpu_config *devc; in mpu_synth_ioctl() local
777 devc = &dev_conf[midi_dev]; in mpu_synth_ioctl()
799 struct mpu_config *devc; in mpu_synth_open() local
807 devc = &dev_conf[midi_dev]; in mpu_synth_open()
816 if (!devc->initialized) in mpu_synth_open()
818 if (mpu401_status(devc) == 0xff) /* Bus float */ in mpu_synth_open()
823 reset_mpu401(devc); in mpu_synth_open()
825 if (devc->opened) in mpu_synth_open()
827 devc->mode = MODE_SYNTH; in mpu_synth_open()
828 devc->synthno = dev; in mpu_synth_open()
830 devc->inputintr = NULL; in mpu_synth_open()
837 if ((err = coprocessor->open(coprocessor->devc, COPR_MIDI)) < 0) in mpu_synth_open()
843 devc->opened = mode; in mpu_synth_open()
844 reset_mpu401(devc); in mpu_synth_open()
858 struct mpu_config *devc; in mpu_synth_close() local
863 devc = &dev_conf[midi_dev]; in mpu_synth_close()
867 devc->inputintr = NULL; in mpu_synth_close()
871 coprocessor->close(coprocessor->devc, COPR_MIDI); in mpu_synth_close()
874 devc->opened = 0; in mpu_synth_close()
875 devc->mode = 0; in mpu_synth_close()
927 static void mpu401_chk_version(int n, struct mpu_config *devc) in mpu401_chk_version() argument
931 devc->version = devc->revision = 0; in mpu401_chk_version()
938 devc->version = tmp; in mpu401_chk_version()
941 devc->version = 0; in mpu401_chk_version()
944 devc->revision = tmp; in mpu401_chk_version()
953 struct mpu_config *devc; in attach_mpu401() local
963 devc = &dev_conf[m]; in attach_mpu401()
964 devc->base = hw_config->io_base; in attach_mpu401()
965 devc->osp = hw_config->osp; in attach_mpu401()
966 devc->irq = hw_config->irq; in attach_mpu401()
967 devc->opened = 0; in attach_mpu401()
968 devc->uart_mode = 0; in attach_mpu401()
969 devc->initialized = 0; in attach_mpu401()
970 devc->version = 0; in attach_mpu401()
971 devc->revision = 0; in attach_mpu401()
972 devc->capabilities = 0; in attach_mpu401()
973 devc->timer_flag = 0; in attach_mpu401()
974 devc->m_busy = 0; in attach_mpu401()
975 devc->m_state = ST_INIT; in attach_mpu401()
976 devc->shared_irq = hw_config->always_detect; in attach_mpu401()
977 devc->irq = hw_config->irq; in attach_mpu401()
978 spin_lock_init(&devc->lock); in attach_mpu401()
980 if (devc->irq < 0) in attach_mpu401()
982 devc->irq *= -1; in attach_mpu401()
983 devc->shared_irq = 1; in attach_mpu401()
989 if (!reset_mpu401(devc)) in attach_mpu401()
995 if (!devc->shared_irq) in attach_mpu401()
997 if (request_irq(devc->irq, mpuintr, 0, "mpu401", in attach_mpu401()
1000 printk(KERN_WARNING "mpu401: Failed to allocate IRQ%d\n", devc->irq); in attach_mpu401()
1005 spin_lock_irqsave(&devc->lock,flags); in attach_mpu401()
1006 mpu401_chk_version(m, devc); in attach_mpu401()
1007 if (devc->version == 0) in attach_mpu401()
1008 mpu401_chk_version(m, devc); in attach_mpu401()
1009 spin_unlock_irqrestore(&devc->lock, flags); in attach_mpu401()
1012 if (devc->version != 0) in attach_mpu401()
1015 devc->capabilities |= MPU_CAP_INTLG; /* Supports intelligent mode */ in attach_mpu401()
1026 if (!(devc->capabilities & MPU_CAP_INTLG)) /* No intelligent mode */ in attach_mpu401()
1053 if (devc->version == 0x20 && devc->revision >= 0x07) /* MusicQuest interface */ in attach_mpu401()
1055 int ports = (devc->revision & 0x08) ? 32 : 16; in attach_mpu401()
1057 devc->capabilities |= MPU_CAP_SYNC | MPU_CAP_SMPTE | in attach_mpu401()
1060 revision_char = (devc->revision == 0x7f) ? 'M' : ' '; in attach_mpu401()
1068 revision_char = devc->revision ? devc->revision + '@' : ' '; in attach_mpu401()
1069 if ((int) devc->revision > ('Z' - '@')) in attach_mpu401()
1072 devc->capabilities |= MPU_CAP_SYNC | MPU_CAP_FSK; in attach_mpu401()
1079 (int) (devc->version & 0xf0) >> 4, in attach_mpu401()
1080 devc->version & 0x0f, in attach_mpu401()
1090 mpu401_synth_operations[m]->midi_dev = devc->devno = m; in attach_mpu401()
1091 mpu401_synth_operations[devc->devno]->info = &mpu_synth_info[devc->devno]; in attach_mpu401()
1093 if (devc->capabilities & MPU_CAP_INTLG) /* Intelligent mode */ in attach_mpu401()
1096 midi_devs[m] = &mpu401_midi_operations[devc->devno]; in attach_mpu401()
1107 free_irq(devc->irq, hw_config); in attach_mpu401()
1115 static int reset_mpu401(struct mpu_config *devc) in reset_mpu401() argument
1128 timeout_limit = devc->initialized ? 30000 : 100000; in reset_mpu401()
1129 devc->initialized = 1; in reset_mpu401()
1134 ok = output_ready(devc); in reset_mpu401()
1136 write_command(devc, MPU_RESET); /* in reset_mpu401()
1147 spin_lock_irqsave(&devc->lock,flags); in reset_mpu401()
1148 if (input_avail(devc)) in reset_mpu401()
1149 if (read_data(devc) == MPU_ACK) in reset_mpu401()
1151 spin_unlock_irqrestore(&devc->lock,flags); in reset_mpu401()
1156 devc->m_state = ST_INIT; in reset_mpu401()
1157 devc->m_ptr = 0; in reset_mpu401()
1158 devc->m_left = 0; in reset_mpu401()
1159 devc->last_status = 0; in reset_mpu401()
1160 devc->uart_mode = 0; in reset_mpu401()
1165 static void set_uart_mode(int dev, struct mpu_config *devc, int arg) in set_uart_mode() argument
1167 if (!arg && (devc->capabilities & MPU_CAP_INTLG)) in set_uart_mode()
1169 if ((devc->uart_mode == 0) == (arg == 0)) in set_uart_mode()
1171 reset_mpu401(devc); /* This exits the uart mode */ in set_uart_mode()
1178 devc->uart_mode = 0; in set_uart_mode()
1182 devc->uart_mode = arg; in set_uart_mode()
1277 static void tmr_reset(struct mpu_config *devc) in tmr_reset() argument
1281 spin_lock_irqsave(&devc->lock,flags); in tmr_reset()
1285 spin_unlock_irqrestore(&devc->lock,flags); in tmr_reset()
1340 struct mpu_config *devc= &dev_conf[midi_dev]; in mpu_start_timer() local
1342 tmr_reset(devc); in mpu_start_timer()
1367 struct mpu_config *devc= &dev_conf[midi_dev]; in mpu_timer_open() local
1372 tmr_reset(devc); in mpu_timer_open()
1639 static void timer_ext_event(struct mpu_config *devc, int event, int parm) in timer_ext_event() argument
1641 int midi_dev = devc->devno; in timer_ext_event()
1643 if (!devc->timer_flag) in timer_ext_event()
1698 struct mpu_config *devc; in mpu_timer_init() local
1701 devc = &dev_conf[midi_dev]; in mpu_timer_init()
1716 if (devc->version < 0x20) /* Original MPU-401 */ in mpu_timer_init()
1728 if (devc->revision) in mpu_timer_init()
1731 if (devc->revision & 0x02) in mpu_timer_init()
1735 if (devc->revision & 0x40) in mpu_timer_init()