Lines Matching +full:reg +full:- +full:names

6  * based on USB Skeleton driver - 2.2
8 * Copyright (C) 2001-2004 Greg Kroah-Hartman (greg@kroah.com)
25 * RANT: this driver was written using a display 128x48 - converting it
28 * and the original meaningful names have been shortened into
67 u8 command_type; /* Bit7 - Rd/Wr */
82 u8 command_type; /* Bit7 - Rd/Wr */
138 struct offload_registers_access reg[INTERRUPT_REGISTER_ACCESSES]; member
153 struct offload_registers_access reg[PIGGYBACK_REGISTER_ACCESSES]; member
223 #define FUN(c) (0x000007 & (c->arg>>28))
224 #define REG(c) (0x01FFFF & (c->arg>>9)) macro
242 "Force SDIO Data Transfers to 1-bit Mode");
283 return -1; in interface_to_InterfaceNumber()
284 if (!interface->cur_altsetting) in interface_to_InterfaceNumber()
285 return -1; in interface_to_InterfaceNumber()
286 return interface->cur_altsetting->desc.bInterfaceNumber; in interface_to_InterfaceNumber()
330 #define MAXREGMASK (MAXREGS-1)
333 struct offload_registers_access reg[MAXREGS]; member
373 { /* kref callback - softirq */ in vub300_delete()
375 struct mmc_host *mmc = vub300->mmc; in vub300_delete()
376 usb_free_urb(vub300->command_out_urb); in vub300_delete()
377 vub300->command_out_urb = NULL; in vub300_delete()
378 usb_free_urb(vub300->command_res_urb); in vub300_delete()
379 vub300->command_res_urb = NULL; in vub300_delete()
380 usb_put_dev(vub300->udev); in vub300_delete()
390 kref_get(&vub300->kref); in vub300_queue_cmnd_work()
391 if (queue_work(cmndworkqueue, &vub300->cmndwork)) { in vub300_queue_cmnd_work()
404 kref_put(&vub300->kref, vub300_delete); in vub300_queue_cmnd_work()
410 kref_get(&vub300->kref); in vub300_queue_poll_work()
411 if (queue_delayed_work(pollworkqueue, &vub300->pollwork, delay)) { in vub300_queue_poll_work()
424 kref_put(&vub300->kref, vub300_delete); in vub300_queue_poll_work()
430 kref_get(&vub300->kref); in vub300_queue_dead_work()
431 if (queue_work(deadworkqueue, &vub300->deadwork)) { in vub300_queue_dead_work()
444 kref_put(&vub300->kref, vub300_delete); in vub300_queue_dead_work()
449 { /* urb completion handler - hardirq */ in irqpoll_res_completed()
450 struct vub300_mmc_host *vub300 = (struct vub300_mmc_host *)urb->context; in irqpoll_res_completed()
451 if (urb->status) in irqpoll_res_completed()
452 vub300->usb_transport_fail = urb->status; in irqpoll_res_completed()
453 complete(&vub300->irqpoll_complete); in irqpoll_res_completed()
457 { /* urb completion handler - hardirq */ in irqpoll_out_completed()
458 struct vub300_mmc_host *vub300 = (struct vub300_mmc_host *)urb->context; in irqpoll_out_completed()
459 if (urb->status) { in irqpoll_out_completed()
460 vub300->usb_transport_fail = urb->status; in irqpoll_out_completed()
461 complete(&vub300->irqpoll_complete); in irqpoll_out_completed()
466 usb_rcvbulkpipe(vub300->udev, vub300->cmnd_res_ep); in irqpoll_out_completed()
467 usb_fill_bulk_urb(vub300->command_res_urb, vub300->udev, pipe, in irqpoll_out_completed()
468 &vub300->resp, sizeof(vub300->resp), in irqpoll_out_completed()
470 vub300->command_res_urb->actual_length = 0; in irqpoll_out_completed()
471 ret = usb_submit_urb(vub300->command_res_urb, GFP_ATOMIC); in irqpoll_out_completed()
473 vub300->usb_transport_fail = ret; in irqpoll_out_completed()
474 complete(&vub300->irqpoll_complete); in irqpoll_out_completed()
484 int timeout = 0xFFFF & (0x0001FFFF - firmware_irqpoll_timeout); in send_irqpoll()
485 vub300->cmnd.poll.header_size = 22; in send_irqpoll()
486 vub300->cmnd.poll.header_type = 1; in send_irqpoll()
487 vub300->cmnd.poll.port_number = 0; in send_irqpoll()
488 vub300->cmnd.poll.command_type = 2; in send_irqpoll()
489 vub300->cmnd.poll.poll_timeout_lsb = 0xFF & (unsigned)timeout; in send_irqpoll()
490 vub300->cmnd.poll.poll_timeout_msb = 0xFF & (unsigned)(timeout >> 8); in send_irqpoll()
491 usb_fill_bulk_urb(vub300->command_out_urb, vub300->udev, in send_irqpoll()
492 usb_sndbulkpipe(vub300->udev, vub300->cmnd_out_ep) in send_irqpoll()
493 , &vub300->cmnd, sizeof(vub300->cmnd) in send_irqpoll()
495 retval = usb_submit_urb(vub300->command_out_urb, GFP_KERNEL); in send_irqpoll()
497 vub300->usb_transport_fail = retval; in send_irqpoll()
499 complete(&vub300->irqpoll_complete); in send_irqpoll()
508 int old_card_present = vub300->card_present; in new_system_port_status()
510 (0x0001 & vub300->system_port_status.port_flags) ? 1 : 0; in new_system_port_status()
511 vub300->read_only = in new_system_port_status()
512 (0x0010 & vub300->system_port_status.port_flags) ? 1 : 0; in new_system_port_status()
514 dev_info(&vub300->udev->dev, "card just inserted\n"); in new_system_port_status()
515 vub300->card_present = 1; in new_system_port_status()
516 vub300->bus_width = 0; in new_system_port_status()
518 strncpy(vub300->vub_name, "EMPTY Processing Disabled", in new_system_port_status()
519 sizeof(vub300->vub_name)); in new_system_port_status()
521 vub300->vub_name[0] = 0; in new_system_port_status()
522 mmc_detect_change(vub300->mmc, 1); in new_system_port_status()
524 dev_info(&vub300->udev->dev, "card just ejected\n"); in new_system_port_status()
525 vub300->card_present = 0; in new_system_port_status()
526 mmc_detect_change(vub300->mmc, 0); in new_system_port_status()
536 u8 r = vub300->fn[func].offload_point + vub300->fn[func].offload_count; in __add_offloaded_reg_to_fifo()
537 memcpy(&vub300->fn[func].reg[MAXREGMASK & r], register_access, in __add_offloaded_reg_to_fifo()
539 vub300->fn[func].offload_count += 1; in __add_offloaded_reg_to_fifo()
540 vub300->total_offload_count += 1; in __add_offloaded_reg_to_fifo()
546 u32 Register = ((0x03 & register_access->command_byte[0]) << 15) in add_offloaded_reg()
547 | ((0xFF & register_access->command_byte[1]) << 7) in add_offloaded_reg()
548 | ((0xFE & register_access->command_byte[2]) >> 1); in add_offloaded_reg()
549 u8 func = ((0x70 & register_access->command_byte[0]) >> 4); in add_offloaded_reg()
550 u8 regs = vub300->dynamic_register_count; in add_offloaded_reg()
552 while (0 < regs-- && 1 == vub300->sdio_register[i].activate) { in add_offloaded_reg()
553 if (vub300->sdio_register[i].func_num == func && in add_offloaded_reg()
554 vub300->sdio_register[i].sdio_reg == Register) { in add_offloaded_reg()
555 if (vub300->sdio_register[i].prepared == 0) in add_offloaded_reg()
556 vub300->sdio_register[i].prepared = 1; in add_offloaded_reg()
557 vub300->sdio_register[i].response = in add_offloaded_reg()
558 register_access->Respond_Byte[2]; in add_offloaded_reg()
559 vub300->sdio_register[i].regvalue = in add_offloaded_reg()
560 register_access->Respond_Byte[3]; in add_offloaded_reg()
578 usb_control_msg(vub300->udev, usb_rcvctrlpipe(vub300->udev, 0), in check_vub300_port_status()
581 0x0000, 0x0000, &vub300->system_port_status, in check_vub300_port_status()
582 sizeof(vub300->system_port_status), HZ); in check_vub300_port_status()
583 if (sizeof(vub300->system_port_status) == retval) in check_vub300_port_status()
590 if (vub300->command_res_urb->actual_length == 0) in __vub300_irqpoll_response()
593 switch (vub300->resp.common.header_type) { in __vub300_irqpoll_response()
595 mutex_lock(&vub300->irq_mutex); in __vub300_irqpoll_response()
596 if (vub300->irq_enabled) in __vub300_irqpoll_response()
597 mmc_signal_sdio_irq(vub300->mmc); in __vub300_irqpoll_response()
599 vub300->irqs_queued += 1; in __vub300_irqpoll_response()
600 vub300->irq_disabled = 1; in __vub300_irqpoll_response()
601 mutex_unlock(&vub300->irq_mutex); in __vub300_irqpoll_response()
604 if (vub300->resp.error.error_code == SD_ERROR_NO_DEVICE) in __vub300_irqpoll_response()
608 vub300->system_port_status = vub300->resp.status; in __vub300_irqpoll_response()
610 if (!vub300->card_present) in __vub300_irqpoll_response()
615 int offloaded_data_length = vub300->resp.common.header_size - 3; in __vub300_irqpoll_response()
618 while (register_count--) { in __vub300_irqpoll_response()
619 add_offloaded_reg(vub300, &vub300->resp.irq.reg[ri]); in __vub300_irqpoll_response()
622 mutex_lock(&vub300->irq_mutex); in __vub300_irqpoll_response()
623 if (vub300->irq_enabled) in __vub300_irqpoll_response()
624 mmc_signal_sdio_irq(vub300->mmc); in __vub300_irqpoll_response()
626 vub300->irqs_queued += 1; in __vub300_irqpoll_response()
627 vub300->irq_disabled = 1; in __vub300_irqpoll_response()
628 mutex_unlock(&vub300->irq_mutex); in __vub300_irqpoll_response()
633 int offloaded_data_length = vub300->resp.common.header_size - 3; in __vub300_irqpoll_response()
636 while (register_count--) { in __vub300_irqpoll_response()
637 add_offloaded_reg(vub300, &vub300->resp.irq.reg[ri]); in __vub300_irqpoll_response()
640 mutex_lock(&vub300->irq_mutex); in __vub300_irqpoll_response()
641 if (vub300->irq_enabled) in __vub300_irqpoll_response()
642 mmc_signal_sdio_irq(vub300->mmc); in __vub300_irqpoll_response()
643 else if (vub300->irqs_queued) in __vub300_irqpoll_response()
644 vub300->irqs_queued += 1; in __vub300_irqpoll_response()
646 vub300->irqs_queued += 1; in __vub300_irqpoll_response()
647 vub300->irq_disabled = 0; in __vub300_irqpoll_response()
648 mutex_unlock(&vub300->irq_mutex); in __vub300_irqpoll_response()
663 mod_timer(&vub300->inactivity_timer, jiffies + HZ); in __do_poll()
664 init_completion(&vub300->irqpoll_complete); in __do_poll()
666 commretval = wait_for_completion_timeout(&vub300->irqpoll_complete, in __do_poll()
668 if (vub300->usb_transport_fail) { in __do_poll()
671 vub300->usb_timed_out = 1; in __do_poll()
672 usb_kill_urb(vub300->command_out_urb); in __do_poll()
673 usb_kill_urb(vub300->command_res_urb); in __do_poll()
688 if (!vub300->interface) { in vub300_pollwork_thread()
689 kref_put(&vub300->kref, vub300_delete); in vub300_pollwork_thread()
692 mutex_lock(&vub300->cmd_mutex); in vub300_pollwork_thread()
693 if (vub300->cmd) { in vub300_pollwork_thread()
695 } else if (!vub300->card_present) { in vub300_pollwork_thread()
697 } else { /* vub300->card_present */ in vub300_pollwork_thread()
698 mutex_lock(&vub300->irq_mutex); in vub300_pollwork_thread()
699 if (!vub300->irq_enabled) { in vub300_pollwork_thread()
700 mutex_unlock(&vub300->irq_mutex); in vub300_pollwork_thread()
701 } else if (vub300->irqs_queued) { in vub300_pollwork_thread()
702 vub300->irqs_queued -= 1; in vub300_pollwork_thread()
703 mmc_signal_sdio_irq(vub300->mmc); in vub300_pollwork_thread()
704 mod_timer(&vub300->inactivity_timer, jiffies + HZ); in vub300_pollwork_thread()
705 mutex_unlock(&vub300->irq_mutex); in vub300_pollwork_thread()
706 } else { /* NOT vub300->irqs_queued */ in vub300_pollwork_thread()
707 mutex_unlock(&vub300->irq_mutex); in vub300_pollwork_thread()
711 mutex_unlock(&vub300->cmd_mutex); in vub300_pollwork_thread()
712 kref_put(&vub300->kref, vub300_delete); in vub300_pollwork_thread()
719 if (!vub300->interface) { in vub300_deadwork_thread()
720 kref_put(&vub300->kref, vub300_delete); in vub300_deadwork_thread()
723 mutex_lock(&vub300->cmd_mutex); in vub300_deadwork_thread()
724 if (vub300->cmd) { in vub300_deadwork_thread()
727 * timer expired - so we just let the in vub300_deadwork_thread()
731 } else if (vub300->card_present) { in vub300_deadwork_thread()
733 } else if (vub300->mmc && vub300->mmc->card && in vub300_deadwork_thread()
734 mmc_card_present(vub300->mmc->card)) { in vub300_deadwork_thread()
737 * to the previous indication - lets in vub300_deadwork_thread()
744 mod_timer(&vub300->inactivity_timer, jiffies + HZ); in vub300_deadwork_thread()
745 mutex_unlock(&vub300->cmd_mutex); in vub300_deadwork_thread()
746 kref_put(&vub300->kref, vub300_delete); in vub300_deadwork_thread()
752 if (!vub300->interface) { in vub300_inactivity_timer_expired()
753 kref_put(&vub300->kref, vub300_delete); in vub300_inactivity_timer_expired()
754 } else if (vub300->cmd) { in vub300_inactivity_timer_expired()
755 mod_timer(&vub300->inactivity_timer, jiffies + HZ); in vub300_inactivity_timer_expired()
758 mod_timer(&vub300->inactivity_timer, jiffies + HZ); in vub300_inactivity_timer_expired()
768 return -ETIMEDOUT; in vub300_response_error()
786 return -EILSEQ; in vub300_response_error()
788 return -EILSEQ; in vub300_response_error()
790 return -EINVAL; in vub300_response_error()
792 return -ENOMEDIUM; in vub300_response_error()
794 return -ENODEV; in vub300_response_error()
799 { /* urb completion handler - hardirq */ in command_res_completed()
800 struct vub300_mmc_host *vub300 = (struct vub300_mmc_host *)urb->context; in command_res_completed()
801 if (urb->status) { in command_res_completed()
803 } else if (vub300->command_res_urb->actual_length == 0) { in command_res_completed()
808 } else if (!vub300->data) { in command_res_completed()
810 } else if (vub300->resp.common.header_type != 0x02) { in command_res_completed()
815 } else if (vub300->urb) { in command_res_completed()
816 vub300->cmd->error = in command_res_completed()
817 vub300_response_error(vub300->resp.error.error_code); in command_res_completed()
818 usb_unlink_urb(vub300->urb); in command_res_completed()
820 vub300->cmd->error = in command_res_completed()
821 vub300_response_error(vub300->resp.error.error_code); in command_res_completed()
822 usb_sg_cancel(&vub300->sg_request); in command_res_completed()
824 complete(&vub300->command_complete); /* got_response_in */ in command_res_completed()
828 { /* urb completion handler - hardirq */ in command_out_completed()
829 struct vub300_mmc_host *vub300 = (struct vub300_mmc_host *)urb->context; in command_out_completed()
830 if (urb->status) { in command_out_completed()
831 complete(&vub300->command_complete); in command_out_completed()
835 usb_rcvbulkpipe(vub300->udev, vub300->cmnd_res_ep); in command_out_completed()
836 usb_fill_bulk_urb(vub300->command_res_urb, vub300->udev, pipe, in command_out_completed()
837 &vub300->resp, sizeof(vub300->resp), in command_out_completed()
839 vub300->command_res_urb->actual_length = 0; in command_out_completed()
840 ret = usb_submit_urb(vub300->command_res_urb, GFP_ATOMIC); in command_out_completed()
851 complete(&vub300->command_complete); in command_out_completed()
863 vub300->fbs[1] = (cmd_arg << 8) | (0x00FF & vub300->fbs[1]); in snoop_block_size_and_bus_width()
865 vub300->fbs[1] = (0xFF & cmd_arg) | (0xFF00 & vub300->fbs[1]); in snoop_block_size_and_bus_width()
867 vub300->fbs[2] = (cmd_arg << 8) | (0x00FF & vub300->fbs[2]); in snoop_block_size_and_bus_width()
869 vub300->fbs[2] = (0xFF & cmd_arg) | (0xFF00 & vub300->fbs[2]); in snoop_block_size_and_bus_width()
871 vub300->fbs[3] = (cmd_arg << 8) | (0x00FF & vub300->fbs[3]); in snoop_block_size_and_bus_width()
873 vub300->fbs[3] = (0xFF & cmd_arg) | (0xFF00 & vub300->fbs[3]); in snoop_block_size_and_bus_width()
875 vub300->fbs[4] = (cmd_arg << 8) | (0x00FF & vub300->fbs[4]); in snoop_block_size_and_bus_width()
877 vub300->fbs[4] = (0xFF & cmd_arg) | (0xFF00 & vub300->fbs[4]); in snoop_block_size_and_bus_width()
879 vub300->fbs[5] = (cmd_arg << 8) | (0x00FF & vub300->fbs[5]); in snoop_block_size_and_bus_width()
881 vub300->fbs[5] = (0xFF & cmd_arg) | (0xFF00 & vub300->fbs[5]); in snoop_block_size_and_bus_width()
883 vub300->fbs[6] = (cmd_arg << 8) | (0x00FF & vub300->fbs[6]); in snoop_block_size_and_bus_width()
885 vub300->fbs[6] = (0xFF & cmd_arg) | (0xFF00 & vub300->fbs[6]); in snoop_block_size_and_bus_width()
887 vub300->fbs[7] = (cmd_arg << 8) | (0x00FF & vub300->fbs[7]); in snoop_block_size_and_bus_width()
889 vub300->fbs[7] = (0xFF & cmd_arg) | (0xFF00 & vub300->fbs[7]); in snoop_block_size_and_bus_width()
891 vub300->bus_width = 1; in snoop_block_size_and_bus_width()
893 vub300->bus_width = 4; in snoop_block_size_and_bus_width()
899 struct mmc_command *cmd = vub300->cmd; in send_command()
900 struct mmc_data *data = vub300->data; in send_command()
904 if (vub300->app_spec) { in send_command()
905 switch (cmd->opcode) { in send_command()
908 vub300->resp_len = 6; in send_command()
909 if (0x00000000 == (0x00000003 & cmd->arg)) in send_command()
910 vub300->bus_width = 1; in send_command()
911 else if (0x00000002 == (0x00000003 & cmd->arg)) in send_command()
912 vub300->bus_width = 4; in send_command()
914 dev_err(&vub300->udev->dev, in send_command()
916 0x00000003 & cmd->arg); in send_command()
920 vub300->resp_len = 6; in send_command()
924 vub300->resp_len = 6; in send_command()
928 vub300->resp_len = 6; in send_command()
932 vub300->resp_len = 6; in send_command()
936 vub300->resp_len = 6; in send_command()
940 vub300->resp_len = 6; in send_command()
944 vub300->resp_len = 6; in send_command()
947 vub300->resp_len = 0; in send_command()
948 cmd->error = -EINVAL; in send_command()
949 complete(&vub300->command_complete); in send_command()
952 vub300->app_spec = 0; in send_command()
954 switch (cmd->opcode) { in send_command()
957 vub300->resp_len = 0; in send_command()
961 vub300->resp_len = 6; in send_command()
965 vub300->resp_len = 17; in send_command()
969 vub300->resp_len = 6; in send_command()
973 vub300->resp_len = 0; in send_command()
977 vub300->resp_len = 6; in send_command()
981 vub300->resp_len = 6; in send_command()
985 vub300->resp_len = 6; in send_command()
989 vub300->resp_len = 6; in send_command()
993 vub300->resp_len = 17; in send_command()
997 vub300->resp_len = 17; in send_command()
1001 vub300->resp_len = 6; in send_command()
1005 vub300->resp_len = 6; in send_command()
1009 vub300->resp_len = 0; in send_command()
1012 for (i = 0; i < ARRAY_SIZE(vub300->fbs); i++) in send_command()
1013 vub300->fbs[i] = 0xFFFF & cmd->arg; in send_command()
1015 vub300->resp_len = 6; in send_command()
1023 vub300->resp_len = 6; in send_command()
1028 vub300->resp_len = 6; in send_command()
1034 vub300->resp_len = 6; in send_command()
1038 vub300->resp_len = 6; in send_command()
1042 vub300->resp_len = 6; in send_command()
1046 vub300->resp_len = 6; in send_command()
1047 snoop_block_size_and_bus_width(vub300, cmd->arg); in send_command()
1051 vub300->resp_len = 6; in send_command()
1055 vub300->resp_len = 6; in send_command()
1056 vub300->app_spec = 1; in send_command()
1060 vub300->resp_len = 6; in send_command()
1063 vub300->resp_len = 0; in send_command()
1064 cmd->error = -EINVAL; in send_command()
1065 complete(&vub300->command_complete); in send_command()
1073 vub300->cmnd.head.header_size = 20; in send_command()
1074 vub300->cmnd.head.header_type = 0x00; in send_command()
1075 vub300->cmnd.head.port_number = 0; /* "0" means port 1 */ in send_command()
1076 vub300->cmnd.head.command_type = 0x00; /* standard read command */ in send_command()
1077 vub300->cmnd.head.response_type = response_type; in send_command()
1078 vub300->cmnd.head.command_index = cmd->opcode; in send_command()
1079 vub300->cmnd.head.arguments[0] = cmd->arg >> 24; in send_command()
1080 vub300->cmnd.head.arguments[1] = cmd->arg >> 16; in send_command()
1081 vub300->cmnd.head.arguments[2] = cmd->arg >> 8; in send_command()
1082 vub300->cmnd.head.arguments[3] = cmd->arg >> 0; in send_command()
1083 if (cmd->opcode == 52) { in send_command()
1084 int fn = 0x7 & (cmd->arg >> 28); in send_command()
1085 vub300->cmnd.head.block_count[0] = 0; in send_command()
1086 vub300->cmnd.head.block_count[1] = 0; in send_command()
1087 vub300->cmnd.head.block_size[0] = (vub300->fbs[fn] >> 8) & 0xFF; in send_command()
1088 vub300->cmnd.head.block_size[1] = (vub300->fbs[fn] >> 0) & 0xFF; in send_command()
1089 vub300->cmnd.head.command_type = 0x00; in send_command()
1090 vub300->cmnd.head.transfer_size[0] = 0; in send_command()
1091 vub300->cmnd.head.transfer_size[1] = 0; in send_command()
1092 vub300->cmnd.head.transfer_size[2] = 0; in send_command()
1093 vub300->cmnd.head.transfer_size[3] = 0; in send_command()
1095 vub300->cmnd.head.block_count[0] = 0; in send_command()
1096 vub300->cmnd.head.block_count[1] = 0; in send_command()
1097 vub300->cmnd.head.block_size[0] = (vub300->fbs[0] >> 8) & 0xFF; in send_command()
1098 vub300->cmnd.head.block_size[1] = (vub300->fbs[0] >> 0) & 0xFF; in send_command()
1099 vub300->cmnd.head.command_type = 0x00; in send_command()
1100 vub300->cmnd.head.transfer_size[0] = 0; in send_command()
1101 vub300->cmnd.head.transfer_size[1] = 0; in send_command()
1102 vub300->cmnd.head.transfer_size[2] = 0; in send_command()
1103 vub300->cmnd.head.transfer_size[3] = 0; in send_command()
1104 } else if (cmd->opcode == 53) { in send_command()
1105 int fn = 0x7 & (cmd->arg >> 28); in send_command()
1106 if (0x08 & vub300->cmnd.head.arguments[0]) { /* BLOCK MODE */ in send_command()
1107 vub300->cmnd.head.block_count[0] = in send_command()
1108 (data->blocks >> 8) & 0xFF; in send_command()
1109 vub300->cmnd.head.block_count[1] = in send_command()
1110 (data->blocks >> 0) & 0xFF; in send_command()
1111 vub300->cmnd.head.block_size[0] = in send_command()
1112 (data->blksz >> 8) & 0xFF; in send_command()
1113 vub300->cmnd.head.block_size[1] = in send_command()
1114 (data->blksz >> 0) & 0xFF; in send_command()
1116 vub300->cmnd.head.block_count[0] = 0; in send_command()
1117 vub300->cmnd.head.block_count[1] = 0; in send_command()
1118 vub300->cmnd.head.block_size[0] = in send_command()
1119 (vub300->datasize >> 8) & 0xFF; in send_command()
1120 vub300->cmnd.head.block_size[1] = in send_command()
1121 (vub300->datasize >> 0) & 0xFF; in send_command()
1123 vub300->cmnd.head.command_type = in send_command()
1124 (MMC_DATA_READ & data->flags) ? 0x00 : 0x80; in send_command()
1125 vub300->cmnd.head.transfer_size[0] = in send_command()
1126 (vub300->datasize >> 24) & 0xFF; in send_command()
1127 vub300->cmnd.head.transfer_size[1] = in send_command()
1128 (vub300->datasize >> 16) & 0xFF; in send_command()
1129 vub300->cmnd.head.transfer_size[2] = in send_command()
1130 (vub300->datasize >> 8) & 0xFF; in send_command()
1131 vub300->cmnd.head.transfer_size[3] = in send_command()
1132 (vub300->datasize >> 0) & 0xFF; in send_command()
1133 if (vub300->datasize < vub300->fbs[fn]) { in send_command()
1134 vub300->cmnd.head.block_count[0] = 0; in send_command()
1135 vub300->cmnd.head.block_count[1] = 0; in send_command()
1138 vub300->cmnd.head.block_count[0] = (data->blocks >> 8) & 0xFF; in send_command()
1139 vub300->cmnd.head.block_count[1] = (data->blocks >> 0) & 0xFF; in send_command()
1140 vub300->cmnd.head.block_size[0] = (data->blksz >> 8) & 0xFF; in send_command()
1141 vub300->cmnd.head.block_size[1] = (data->blksz >> 0) & 0xFF; in send_command()
1142 vub300->cmnd.head.command_type = in send_command()
1143 (MMC_DATA_READ & data->flags) ? 0x00 : 0x80; in send_command()
1144 vub300->cmnd.head.transfer_size[0] = in send_command()
1145 (vub300->datasize >> 24) & 0xFF; in send_command()
1146 vub300->cmnd.head.transfer_size[1] = in send_command()
1147 (vub300->datasize >> 16) & 0xFF; in send_command()
1148 vub300->cmnd.head.transfer_size[2] = in send_command()
1149 (vub300->datasize >> 8) & 0xFF; in send_command()
1150 vub300->cmnd.head.transfer_size[3] = in send_command()
1151 (vub300->datasize >> 0) & 0xFF; in send_command()
1152 if (vub300->datasize < vub300->fbs[0]) { in send_command()
1153 vub300->cmnd.head.block_count[0] = 0; in send_command()
1154 vub300->cmnd.head.block_count[1] = 0; in send_command()
1157 if (vub300->cmnd.head.block_size[0] || vub300->cmnd.head.block_size[1]) { in send_command()
1158 u16 block_size = vub300->cmnd.head.block_size[1] | in send_command()
1159 (vub300->cmnd.head.block_size[0] << 8); in send_command()
1160 u16 block_boundary = FIRMWARE_BLOCK_BOUNDARY - in send_command()
1162 vub300->cmnd.head.block_boundary[0] = in send_command()
1164 vub300->cmnd.head.block_boundary[1] = in send_command()
1167 vub300->cmnd.head.block_boundary[0] = 0; in send_command()
1168 vub300->cmnd.head.block_boundary[1] = 0; in send_command()
1170 usb_fill_bulk_urb(vub300->command_out_urb, vub300->udev, in send_command()
1171 usb_sndbulkpipe(vub300->udev, vub300->cmnd_out_ep), in send_command()
1172 &vub300->cmnd, sizeof(vub300->cmnd), in send_command()
1174 retval = usb_submit_urb(vub300->command_out_urb, GFP_KERNEL); in send_command()
1176 cmd->error = retval; in send_command()
1177 complete(&vub300->command_complete); in send_command()
1191 vub300->usb_timed_out = 1; in vub300_sg_timed_out()
1192 usb_sg_cancel(&vub300->sg_request); in vub300_sg_timed_out()
1193 usb_unlink_urb(vub300->command_out_urb); in vub300_sg_timed_out()
1194 usb_unlink_urb(vub300->command_res_urb); in vub300_sg_timed_out()
1211 const u8 *data = fw->data; in __download_offload_pseudocode()
1212 int size = fw->size; in __download_offload_pseudocode()
1214 dev_info(&vub300->udev->dev, "using %s for SDIO offload processing\n", in __download_offload_pseudocode()
1215 vub300->vub_name); in __download_offload_pseudocode()
1218 } while (size-- && c); /* skip comment */ in __download_offload_pseudocode()
1219 dev_info(&vub300->udev->dev, "using offload firmware %s %s\n", fw->data, in __download_offload_pseudocode()
1220 vub300->vub_name); in __download_offload_pseudocode()
1222 dev_err(&vub300->udev->dev, in __download_offload_pseudocode()
1224 vub300->vub_name); in __download_offload_pseudocode()
1225 strncpy(vub300->vub_name, "corrupt offload pseudocode", in __download_offload_pseudocode()
1226 sizeof(vub300->vub_name)); in __download_offload_pseudocode()
1230 size -= 1; in __download_offload_pseudocode()
1233 size -= 1; in __download_offload_pseudocode()
1241 xfer_length - interrupt_size); in __download_offload_pseudocode()
1242 size -= interrupt_size; in __download_offload_pseudocode()
1245 usb_control_msg(vub300->udev, in __download_offload_pseudocode()
1246 usb_sndctrlpipe(vub300->udev, 0), in __download_offload_pseudocode()
1253 strncpy(vub300->vub_name, in __download_offload_pseudocode()
1255 sizeof(vub300->vub_name)); in __download_offload_pseudocode()
1259 dev_err(&vub300->udev->dev, in __download_offload_pseudocode()
1261 " INTERRUPT_PSEUDOCODE for %s %s\n", fw->data, in __download_offload_pseudocode()
1262 vub300->vub_name); in __download_offload_pseudocode()
1263 strncpy(vub300->vub_name, in __download_offload_pseudocode()
1265 sizeof(vub300->vub_name)); in __download_offload_pseudocode()
1269 dev_err(&vub300->udev->dev, in __download_offload_pseudocode()
1271 fw->data, vub300->vub_name); in __download_offload_pseudocode()
1272 strncpy(vub300->vub_name, "corrupt interrupt pseudocode", in __download_offload_pseudocode()
1273 sizeof(vub300->vub_name)); in __download_offload_pseudocode()
1277 size -= 1; in __download_offload_pseudocode()
1280 size -= 1; in __download_offload_pseudocode()
1288 xfer_length - ts); in __download_offload_pseudocode()
1289 size -= ts; in __download_offload_pseudocode()
1292 usb_control_msg(vub300->udev, in __download_offload_pseudocode()
1293 usb_sndctrlpipe(vub300->udev, 0), in __download_offload_pseudocode()
1300 strncpy(vub300->vub_name, in __download_offload_pseudocode()
1302 sizeof(vub300->vub_name)); in __download_offload_pseudocode()
1306 dev_err(&vub300->udev->dev, in __download_offload_pseudocode()
1308 " TRANSFER_PSEUDOCODE for %s %s\n", fw->data, in __download_offload_pseudocode()
1309 vub300->vub_name); in __download_offload_pseudocode()
1310 strncpy(vub300->vub_name, in __download_offload_pseudocode()
1312 sizeof(vub300->vub_name)); in __download_offload_pseudocode()
1316 dev_err(&vub300->udev->dev, in __download_offload_pseudocode()
1318 fw->data, vub300->vub_name); in __download_offload_pseudocode()
1319 strncpy(vub300->vub_name, "corrupt transfer pseudocode", in __download_offload_pseudocode()
1320 sizeof(vub300->vub_name)); in __download_offload_pseudocode()
1324 size -= 1; in __download_offload_pseudocode()
1326 int I = vub300->dynamic_register_count = register_count; in __download_offload_pseudocode()
1328 while (I--) { in __download_offload_pseudocode()
1330 vub300->sdio_register[i].func_num = *data++; in __download_offload_pseudocode()
1331 size -= 1; in __download_offload_pseudocode()
1333 size -= 1; in __download_offload_pseudocode()
1336 size -= 1; in __download_offload_pseudocode()
1339 size -= 1; in __download_offload_pseudocode()
1340 vub300->sdio_register[i].sdio_reg = func_num; in __download_offload_pseudocode()
1341 vub300->sdio_register[i].activate = 1; in __download_offload_pseudocode()
1342 vub300->sdio_register[i].prepared = 0; in __download_offload_pseudocode()
1345 dev_info(&vub300->udev->dev, in __download_offload_pseudocode()
1347 vub300->dynamic_register_count); in __download_offload_pseudocode()
1350 dev_err(&vub300->udev->dev, in __download_offload_pseudocode()
1352 vub300->vub_name); in __download_offload_pseudocode()
1353 strncpy(vub300->vub_name, "corrupt dynamic registers", in __download_offload_pseudocode()
1354 sizeof(vub300->vub_name)); in __download_offload_pseudocode()
1361 * vub300->vub_name is set anyway in order to prevent an automatic retry
1365 struct mmc_card *card = vub300->mmc->card; in download_offload_pseudocode()
1366 int sdio_funcs = card->sdio_funcs; in download_offload_pseudocode()
1368 int l = snprintf(vub300->vub_name, sizeof(vub300->vub_name), in download_offload_pseudocode()
1369 "vub_%04X%04X", card->cis.vendor, card->cis.device); in download_offload_pseudocode()
1373 struct sdio_func *sf = card->sdio_func[n]; in download_offload_pseudocode()
1374 l += snprintf(vub300->vub_name + l, in download_offload_pseudocode()
1375 sizeof(vub300->vub_name) - l, "_%04X%04X", in download_offload_pseudocode()
1376 sf->vendor, sf->device); in download_offload_pseudocode()
1378 snprintf(vub300->vub_name + l, sizeof(vub300->vub_name) - l, ".bin"); in download_offload_pseudocode()
1379 dev_info(&vub300->udev->dev, "requesting offload firmware %s\n", in download_offload_pseudocode()
1380 vub300->vub_name); in download_offload_pseudocode()
1381 retval = request_firmware(&fw, vub300->vub_name, &card->dev); in download_offload_pseudocode()
1383 strncpy(vub300->vub_name, "vub_default.bin", in download_offload_pseudocode()
1384 sizeof(vub300->vub_name)); in download_offload_pseudocode()
1385 retval = request_firmware(&fw, vub300->vub_name, &card->dev); in download_offload_pseudocode()
1387 strncpy(vub300->vub_name, in download_offload_pseudocode()
1389 sizeof(vub300->vub_name)); in download_offload_pseudocode()
1401 { /* urb completion handler - hardirq */ in vub300_usb_bulk_msg_completion()
1402 complete((struct completion *)urb->context); in vub300_usb_bulk_msg_completion()
1410 struct usb_device *usb_dev = vub300->udev; in vub300_usb_bulk_msg()
1413 vub300->urb = usb_alloc_urb(0, GFP_KERNEL); in vub300_usb_bulk_msg()
1414 if (!vub300->urb) in vub300_usb_bulk_msg()
1415 return -ENOMEM; in vub300_usb_bulk_msg()
1416 usb_fill_bulk_urb(vub300->urb, usb_dev, pipe, data, len, in vub300_usb_bulk_msg()
1419 vub300->urb->context = &done; in vub300_usb_bulk_msg()
1420 vub300->urb->actual_length = 0; in vub300_usb_bulk_msg()
1421 retval = usb_submit_urb(vub300->urb, GFP_KERNEL); in vub300_usb_bulk_msg()
1426 retval = -ETIMEDOUT; in vub300_usb_bulk_msg()
1427 usb_kill_urb(vub300->urb); in vub300_usb_bulk_msg()
1429 retval = vub300->urb->status; in vub300_usb_bulk_msg()
1432 *actual_length = vub300->urb->actual_length; in vub300_usb_bulk_msg()
1433 usb_free_urb(vub300->urb); in vub300_usb_bulk_msg()
1434 vub300->urb = NULL; in vub300_usb_bulk_msg()
1442 int linear_length = vub300->datasize; in __command_read_data()
1443 int padded_length = vub300->large_usb_packets ? in __command_read_data()
1449 pipe = usb_rcvbulkpipe(vub300->udev, vub300->data_inp_ep); in __command_read_data()
1450 result = usb_sg_init(&vub300->sg_request, vub300->udev, in __command_read_data()
1451 pipe, 0, data->sg, in __command_read_data()
1452 data->sg_len, 0, GFP_KERNEL); in __command_read_data()
1454 usb_unlink_urb(vub300->command_out_urb); in __command_read_data()
1455 usb_unlink_urb(vub300->command_res_urb); in __command_read_data()
1456 cmd->error = result; in __command_read_data()
1457 data->bytes_xfered = 0; in __command_read_data()
1460 vub300->sg_transfer_timer.expires = in __command_read_data()
1463 add_timer(&vub300->sg_transfer_timer); in __command_read_data()
1464 usb_sg_wait(&vub300->sg_request); in __command_read_data()
1465 del_timer(&vub300->sg_transfer_timer); in __command_read_data()
1466 if (vub300->sg_request.status < 0) { in __command_read_data()
1467 cmd->error = vub300->sg_request.status; in __command_read_data()
1468 data->bytes_xfered = 0; in __command_read_data()
1471 data->bytes_xfered = vub300->datasize; in __command_read_data()
1479 unsigned pipe = usb_rcvbulkpipe(vub300->udev, in __command_read_data()
1480 vub300->data_inp_ep); in __command_read_data()
1486 cmd->error = result; in __command_read_data()
1487 data->bytes_xfered = 0; in __command_read_data()
1491 cmd->error = -EREMOTEIO; in __command_read_data()
1492 data->bytes_xfered = 0; in __command_read_data()
1496 sg_copy_from_buffer(data->sg, data->sg_len, buf, in __command_read_data()
1499 data->bytes_xfered = vub300->datasize; in __command_read_data()
1503 cmd->error = -ENOMEM; in __command_read_data()
1504 data->bytes_xfered = 0; in __command_read_data()
1514 unsigned pipe = usb_sndbulkpipe(vub300->udev, vub300->data_out_ep); in __command_write_data()
1515 int linear_length = vub300->datasize; in __command_write_data()
1521 sg_copy_to_buffer(data->sg, data->sg_len, in __command_write_data()
1522 vub300->padded_buffer, in __command_write_data()
1523 sizeof(vub300->padded_buffer)); in __command_write_data()
1524 memset(vub300->padded_buffer + linear_length, 0, in __command_write_data()
1525 sizeof(vub300->padded_buffer) - linear_length); in __command_write_data()
1526 result = vub300_usb_bulk_msg(vub300, pipe, vub300->padded_buffer, in __command_write_data()
1527 sizeof(vub300->padded_buffer), in __command_write_data()
1529 (sizeof(vub300->padded_buffer) / in __command_write_data()
1532 cmd->error = result; in __command_write_data()
1533 data->bytes_xfered = 0; in __command_write_data()
1535 data->bytes_xfered = vub300->datasize; in __command_write_data()
1537 } else if ((!vub300->large_usb_packets && (0 < modulo_64_length)) || in __command_write_data()
1538 (vub300->large_usb_packets && (64 > modulo_512_length)) in __command_write_data()
1539 ) { /* don't you just love these work-rounds */ in __command_write_data()
1545 sg_copy_to_buffer(data->sg, data->sg_len, buf, in __command_write_data()
1548 padded_length - linear_length); in __command_write_data()
1555 cmd->error = result; in __command_write_data()
1556 data->bytes_xfered = 0; in __command_write_data()
1558 data->bytes_xfered = vub300->datasize; in __command_write_data()
1561 cmd->error = -ENOMEM; in __command_write_data()
1562 data->bytes_xfered = 0; in __command_write_data()
1567 sg_copy_to_buffer(data->sg, data->sg_len, buf, sizeof(buf)); in __command_write_data()
1568 result = usb_sg_init(&vub300->sg_request, vub300->udev, in __command_write_data()
1569 pipe, 0, data->sg, in __command_write_data()
1570 data->sg_len, 0, GFP_KERNEL); in __command_write_data()
1572 usb_unlink_urb(vub300->command_out_urb); in __command_write_data()
1573 usb_unlink_urb(vub300->command_res_urb); in __command_write_data()
1574 cmd->error = result; in __command_write_data()
1575 data->bytes_xfered = 0; in __command_write_data()
1577 vub300->sg_transfer_timer.expires = in __command_write_data()
1580 add_timer(&vub300->sg_transfer_timer); in __command_write_data()
1581 usb_sg_wait(&vub300->sg_request); in __command_write_data()
1582 if (cmd->error) { in __command_write_data()
1583 data->bytes_xfered = 0; in __command_write_data()
1585 del_timer(&vub300->sg_transfer_timer); in __command_write_data()
1586 if (vub300->sg_request.status < 0) { in __command_write_data()
1587 cmd->error = vub300->sg_request.status; in __command_write_data()
1588 data->bytes_xfered = 0; in __command_write_data()
1590 data->bytes_xfered = vub300->datasize; in __command_write_data()
1606 wait_for_completion_timeout(&vub300->command_complete, in __vub300_command_response()
1611 vub300->usb_timed_out = 1; in __vub300_command_response()
1612 usb_kill_urb(vub300->command_out_urb); in __vub300_command_response()
1613 usb_kill_urb(vub300->command_res_urb); in __vub300_command_response()
1614 cmd->error = -ETIMEDOUT; in __vub300_command_response()
1615 result = usb_lock_device_for_reset(vub300->udev, in __vub300_command_response()
1616 vub300->interface); in __vub300_command_response()
1618 result = usb_reset_device(vub300->udev); in __vub300_command_response()
1619 usb_unlock_device(vub300->udev); in __vub300_command_response()
1623 usb_kill_urb(vub300->command_out_urb); in __vub300_command_response()
1624 usb_kill_urb(vub300->command_res_urb); in __vub300_command_response()
1625 cmd->error = respretval; in __vub300_command_response()
1626 } else if (cmd->error) { in __vub300_command_response()
1631 } else if (vub300->command_out_urb->status) { in __vub300_command_response()
1632 vub300->usb_transport_fail = vub300->command_out_urb->status; in __vub300_command_response()
1633 cmd->error = -EPROTO == vub300->command_out_urb->status ? in __vub300_command_response()
1634 -ESHUTDOWN : vub300->command_out_urb->status; in __vub300_command_response()
1635 } else if (vub300->command_res_urb->status) { in __vub300_command_response()
1636 vub300->usb_transport_fail = vub300->command_res_urb->status; in __vub300_command_response()
1637 cmd->error = -EPROTO == vub300->command_res_urb->status ? in __vub300_command_response()
1638 -ESHUTDOWN : vub300->command_res_urb->status; in __vub300_command_response()
1639 } else if (vub300->resp.common.header_type == 0x00) { in __vub300_command_response()
1644 } else if (vub300->resp.common.header_type == RESPONSE_ERROR) { in __vub300_command_response()
1645 cmd->error = in __vub300_command_response()
1646 vub300_response_error(vub300->resp.error.error_code); in __vub300_command_response()
1647 if (vub300->data) in __vub300_command_response()
1648 usb_sg_cancel(&vub300->sg_request); in __vub300_command_response()
1649 } else if (vub300->resp.common.header_type == RESPONSE_PIGGYBACKED) { in __vub300_command_response()
1651 vub300->resp.common.header_size - in __vub300_command_response()
1655 while (register_count--) { in __vub300_command_response()
1656 add_offloaded_reg(vub300, &vub300->resp.pig.reg[ri]); in __vub300_command_response()
1659 vub300->resp.common.header_size = in __vub300_command_response()
1661 vub300->resp.common.header_type = 0x00; in __vub300_command_response()
1662 cmd->error = 0; in __vub300_command_response()
1663 } else if (vub300->resp.common.header_type == RESPONSE_PIG_DISABLED) { in __vub300_command_response()
1665 vub300->resp.common.header_size - in __vub300_command_response()
1669 while (register_count--) { in __vub300_command_response()
1670 add_offloaded_reg(vub300, &vub300->resp.pig.reg[ri]); in __vub300_command_response()
1673 mutex_lock(&vub300->irq_mutex); in __vub300_command_response()
1674 if (vub300->irqs_queued) { in __vub300_command_response()
1675 vub300->irqs_queued += 1; in __vub300_command_response()
1676 } else if (vub300->irq_enabled) { in __vub300_command_response()
1677 vub300->irqs_queued += 1; in __vub300_command_response()
1680 vub300->irqs_queued += 1; in __vub300_command_response()
1682 vub300->irq_disabled = 1; in __vub300_command_response()
1683 mutex_unlock(&vub300->irq_mutex); in __vub300_command_response()
1684 vub300->resp.common.header_size = in __vub300_command_response()
1686 vub300->resp.common.header_type = 0x00; in __vub300_command_response()
1687 cmd->error = 0; in __vub300_command_response()
1688 } else if (vub300->resp.common.header_type == RESPONSE_PIG_ENABLED) { in __vub300_command_response()
1690 vub300->resp.common.header_size - in __vub300_command_response()
1694 while (register_count--) { in __vub300_command_response()
1695 add_offloaded_reg(vub300, &vub300->resp.pig.reg[ri]); in __vub300_command_response()
1698 mutex_lock(&vub300->irq_mutex); in __vub300_command_response()
1699 if (vub300->irqs_queued) { in __vub300_command_response()
1700 vub300->irqs_queued += 1; in __vub300_command_response()
1701 } else if (vub300->irq_enabled) { in __vub300_command_response()
1702 vub300->irqs_queued += 1; in __vub300_command_response()
1705 vub300->irqs_queued += 1; in __vub300_command_response()
1707 vub300->irq_disabled = 0; in __vub300_command_response()
1708 mutex_unlock(&vub300->irq_mutex); in __vub300_command_response()
1709 vub300->resp.common.header_size = in __vub300_command_response()
1711 vub300->resp.common.header_type = 0x00; in __vub300_command_response()
1712 cmd->error = 0; in __vub300_command_response()
1714 cmd->error = -EINVAL; in __vub300_command_response()
1721 int resp_len = vub300->resp_len; in construct_request_response()
1722 int less_cmd = (17 == resp_len) ? resp_len : resp_len - 1; in construct_request_response()
1725 u8 *r = vub300->resp.response.command_response; in construct_request_response()
1727 cmd->resp[words] = (r[1 + (words << 2)] << 24) in construct_request_response()
1731 cmd->resp[words] = (r[1 + (words << 2)] << 24) in construct_request_response()
1734 cmd->resp[words] = (r[1 + (words << 2)] << 24); in construct_request_response()
1736 while (words-- > 0) { in construct_request_response()
1737 cmd->resp[words] = (r[1 + (words << 2)] << 24) in construct_request_response()
1742 if ((cmd->opcode == 53) && (0x000000FF & cmd->resp[0])) in construct_request_response()
1743 cmd->resp[0] &= 0xFFFFFF00; in construct_request_response()
1751 if (!vub300->interface) { in vub300_cmndwork_thread()
1752 kref_put(&vub300->kref, vub300_delete); in vub300_cmndwork_thread()
1755 struct mmc_request *req = vub300->req; in vub300_cmndwork_thread()
1756 struct mmc_command *cmd = vub300->cmd; in vub300_cmndwork_thread()
1757 struct mmc_data *data = vub300->data; in vub300_cmndwork_thread()
1759 mutex_lock(&vub300->cmd_mutex); in vub300_cmndwork_thread()
1760 init_completion(&vub300->command_complete); in vub300_cmndwork_thread()
1761 if (likely(vub300->vub_name[0]) || !vub300->mmc->card || in vub300_cmndwork_thread()
1762 !mmc_card_present(vub300->mmc->card)) { in vub300_cmndwork_thread()
1768 } else if (0 == vub300->mmc->card->sdio_funcs) { in vub300_cmndwork_thread()
1769 strncpy(vub300->vub_name, "SD memory device", in vub300_cmndwork_thread()
1770 sizeof(vub300->vub_name)); in vub300_cmndwork_thread()
1777 else if (MMC_DATA_READ & data->flags) in vub300_cmndwork_thread()
1782 vub300->req = NULL; in vub300_cmndwork_thread()
1783 vub300->cmd = NULL; in vub300_cmndwork_thread()
1784 vub300->data = NULL; in vub300_cmndwork_thread()
1785 if (cmd->error) { in vub300_cmndwork_thread()
1786 if (cmd->error == -ENOMEDIUM) in vub300_cmndwork_thread()
1788 mutex_unlock(&vub300->cmd_mutex); in vub300_cmndwork_thread()
1789 mmc_request_done(vub300->mmc, req); in vub300_cmndwork_thread()
1790 kref_put(&vub300->kref, vub300_delete); in vub300_cmndwork_thread()
1794 vub300->resp_len = 0; in vub300_cmndwork_thread()
1795 mutex_unlock(&vub300->cmd_mutex); in vub300_cmndwork_thread()
1796 kref_put(&vub300->kref, vub300_delete); in vub300_cmndwork_thread()
1797 mmc_request_done(vub300->mmc, req); in vub300_cmndwork_thread()
1807 u8 cmd0 = 0xFF & (cmd->arg >> 24); in examine_cyclic_buffer()
1808 u8 cmd1 = 0xFF & (cmd->arg >> 16); in examine_cyclic_buffer()
1809 u8 cmd2 = 0xFF & (cmd->arg >> 8); in examine_cyclic_buffer()
1810 u8 cmd3 = 0xFF & (cmd->arg >> 0); in examine_cyclic_buffer()
1811 int first = MAXREGMASK & vub300->fn[Function].offload_point; in examine_cyclic_buffer()
1812 struct offload_registers_access *rf = &vub300->fn[Function].reg[first]; in examine_cyclic_buffer()
1813 if (cmd0 == rf->command_byte[0] && in examine_cyclic_buffer()
1814 cmd1 == rf->command_byte[1] && in examine_cyclic_buffer()
1815 cmd2 == rf->command_byte[2] && in examine_cyclic_buffer()
1816 cmd3 == rf->command_byte[3]) { in examine_cyclic_buffer()
1818 cmd->resp[1] = checksum << 24; in examine_cyclic_buffer()
1819 cmd->resp[0] = (rf->Respond_Byte[0] << 24) in examine_cyclic_buffer()
1820 | (rf->Respond_Byte[1] << 16) in examine_cyclic_buffer()
1821 | (rf->Respond_Byte[2] << 8) in examine_cyclic_buffer()
1822 | (rf->Respond_Byte[3] << 0); in examine_cyclic_buffer()
1823 vub300->fn[Function].offload_point += 1; in examine_cyclic_buffer()
1824 vub300->fn[Function].offload_count -= 1; in examine_cyclic_buffer()
1825 vub300->total_offload_count -= 1; in examine_cyclic_buffer()
1829 u8 register_count = vub300->fn[Function].offload_count - 1; in examine_cyclic_buffer()
1830 u32 register_point = vub300->fn[Function].offload_point + 1; in examine_cyclic_buffer()
1834 &vub300->fn[Function].reg[point]; in examine_cyclic_buffer()
1835 if (cmd0 == r->command_byte[0] && in examine_cyclic_buffer()
1836 cmd1 == r->command_byte[1] && in examine_cyclic_buffer()
1837 cmd2 == r->command_byte[2] && in examine_cyclic_buffer()
1838 cmd3 == r->command_byte[3]) { in examine_cyclic_buffer()
1840 cmd->resp[1] = checksum << 24; in examine_cyclic_buffer()
1841 cmd->resp[0] = (r->Respond_Byte[0] << 24) in examine_cyclic_buffer()
1842 | (r->Respond_Byte[1] << 16) in examine_cyclic_buffer()
1843 | (r->Respond_Byte[2] << 8) in examine_cyclic_buffer()
1844 | (r->Respond_Byte[3] << 0); in examine_cyclic_buffer()
1845 vub300->fn[Function].offload_point += delta; in examine_cyclic_buffer()
1846 vub300->fn[Function].offload_count -= delta; in examine_cyclic_buffer()
1847 vub300->total_offload_count -= delta; in examine_cyclic_buffer()
1851 register_count -= 1; in examine_cyclic_buffer()
1864 u8 regs = vub300->dynamic_register_count; in satisfy_request_from_offloaded_data()
1867 u32 reg = REG(cmd); in satisfy_request_from_offloaded_data() local
1868 while (0 < regs--) { in satisfy_request_from_offloaded_data()
1869 if ((vub300->sdio_register[i].func_num == func) && in satisfy_request_from_offloaded_data()
1870 (vub300->sdio_register[i].sdio_reg == reg)) { in satisfy_request_from_offloaded_data()
1871 if (!vub300->sdio_register[i].prepared) { in satisfy_request_from_offloaded_data()
1873 } else if ((0x80000000 & cmd->arg) == 0x80000000) { in satisfy_request_from_offloaded_data()
1878 vub300->sdio_register[i].prepared = 0; in satisfy_request_from_offloaded_data()
1884 u8 rsp2 = vub300->sdio_register[i].response; in satisfy_request_from_offloaded_data()
1885 u8 rsp3 = vub300->sdio_register[i].regvalue; in satisfy_request_from_offloaded_data()
1886 vub300->sdio_register[i].prepared = 0; in satisfy_request_from_offloaded_data()
1887 cmd->resp[1] = checksum << 24; in satisfy_request_from_offloaded_data()
1888 cmd->resp[0] = (rsp0 << 24) in satisfy_request_from_offloaded_data()
1899 if (vub300->total_offload_count == 0) in satisfy_request_from_offloaded_data()
1901 else if (vub300->fn[func].offload_count == 0) in satisfy_request_from_offloaded_data()
1909 struct mmc_command *cmd = req->cmd; in vub300_mmc_request()
1911 if (!vub300->interface) { in vub300_mmc_request()
1912 cmd->error = -ESHUTDOWN; in vub300_mmc_request()
1916 struct mmc_data *data = req->data; in vub300_mmc_request()
1917 if (!vub300->card_powered) { in vub300_mmc_request()
1918 cmd->error = -ENOMEDIUM; in vub300_mmc_request()
1922 if (!vub300->card_present) { in vub300_mmc_request()
1923 cmd->error = -ENOMEDIUM; in vub300_mmc_request()
1927 if (vub300->usb_transport_fail) { in vub300_mmc_request()
1928 cmd->error = vub300->usb_transport_fail; in vub300_mmc_request()
1932 if (!vub300->interface) { in vub300_mmc_request()
1933 cmd->error = -ENODEV; in vub300_mmc_request()
1937 kref_get(&vub300->kref); in vub300_mmc_request()
1938 mutex_lock(&vub300->cmd_mutex); in vub300_mmc_request()
1939 mod_timer(&vub300->inactivity_timer, jiffies + HZ); in vub300_mmc_request()
1944 if (cmd->opcode == 52 && in vub300_mmc_request()
1946 cmd->error = 0; in vub300_mmc_request()
1947 mutex_unlock(&vub300->cmd_mutex); in vub300_mmc_request()
1948 kref_put(&vub300->kref, vub300_delete); in vub300_mmc_request()
1952 vub300->cmd = cmd; in vub300_mmc_request()
1953 vub300->req = req; in vub300_mmc_request()
1954 vub300->data = data; in vub300_mmc_request()
1956 vub300->datasize = data->blksz * data->blocks; in vub300_mmc_request()
1958 vub300->datasize = 0; in vub300_mmc_request()
1960 mutex_unlock(&vub300->cmd_mutex); in vub300_mmc_request()
1961 kref_put(&vub300->kref, vub300_delete); in vub300_mmc_request()
1967 * and re-acquire it in the cmndwork thread in vub300_mmc_request()
1979 if (ios->clock >= 48000000) in __set_clock_speed()
1981 else if (ios->clock >= 24000000) in __set_clock_speed()
1983 else if (ios->clock >= 20000000) in __set_clock_speed()
1985 else if (ios->clock >= 15000000) in __set_clock_speed()
1987 else if (ios->clock >= 200000) in __set_clock_speed()
2000 usb_control_msg(vub300->udev, usb_sndctrlpipe(vub300->udev, 0), in __set_clock_speed()
2005 dev_err(&vub300->udev->dev, "SET_CLOCK_SPEED" in __set_clock_speed()
2008 dev_dbg(&vub300->udev->dev, "SET_CLOCK_SPEED" in __set_clock_speed()
2016 if (!vub300->interface) in vub300_mmc_set_ios()
2018 kref_get(&vub300->kref); in vub300_mmc_set_ios()
2019 mutex_lock(&vub300->cmd_mutex); in vub300_mmc_set_ios()
2020 if ((ios->power_mode == MMC_POWER_OFF) && vub300->card_powered) { in vub300_mmc_set_ios()
2021 vub300->card_powered = 0; in vub300_mmc_set_ios()
2022 usb_control_msg(vub300->udev, usb_sndctrlpipe(vub300->udev, 0), in vub300_mmc_set_ios()
2026 /* must wait for the VUB300 u-proc to boot up */ in vub300_mmc_set_ios()
2028 } else if ((ios->power_mode == MMC_POWER_UP) && !vub300->card_powered) { in vub300_mmc_set_ios()
2029 usb_control_msg(vub300->udev, usb_sndctrlpipe(vub300->udev, 0), in vub300_mmc_set_ios()
2034 vub300->card_powered = 1; in vub300_mmc_set_ios()
2035 } else if (ios->power_mode == MMC_POWER_ON) { in vub300_mmc_set_ios()
2044 mutex_unlock(&vub300->cmd_mutex); in vub300_mmc_set_ios()
2045 kref_put(&vub300->kref, vub300_delete); in vub300_mmc_set_ios()
2051 return vub300->read_only; in vub300_mmc_get_ro()
2057 if (!vub300->interface) in vub300_enable_sdio_irq()
2059 kref_get(&vub300->kref); in vub300_enable_sdio_irq()
2061 mutex_lock(&vub300->irq_mutex); in vub300_enable_sdio_irq()
2062 if (vub300->irqs_queued) { in vub300_enable_sdio_irq()
2063 vub300->irqs_queued -= 1; in vub300_enable_sdio_irq()
2064 mmc_signal_sdio_irq(vub300->mmc); in vub300_enable_sdio_irq()
2065 } else if (vub300->irq_disabled) { in vub300_enable_sdio_irq()
2066 vub300->irq_disabled = 0; in vub300_enable_sdio_irq()
2067 vub300->irq_enabled = 1; in vub300_enable_sdio_irq()
2069 } else if (vub300->irq_enabled) { in vub300_enable_sdio_irq()
2072 vub300->irq_enabled = 1; in vub300_enable_sdio_irq()
2075 mutex_unlock(&vub300->irq_mutex); in vub300_enable_sdio_irq()
2077 vub300->irq_enabled = 0; in vub300_enable_sdio_irq()
2079 kref_put(&vub300->kref, vub300_delete); in vub300_enable_sdio_irq()
2085 dev_info(&vub300->udev->dev, "NO host QUIRKS for this card\n"); in vub300_init_card()
2103 int retval = -ENOMEM; in vub300_probe()
2110 usb_string(udev, udev->descriptor.iManufacturer, manufacturer, in vub300_probe()
2112 usb_string(udev, udev->descriptor.iProduct, product, sizeof(product)); in vub300_probe()
2113 usb_string(udev, udev->descriptor.iSerialNumber, serial_number, in vub300_probe()
2115 dev_info(&udev->dev, "probing VID:PID(%04X:%04X) %s %s %s\n", in vub300_probe()
2116 udev->descriptor.idVendor, udev->descriptor.idProduct, in vub300_probe()
2120 retval = -ENOMEM; in vub300_probe()
2121 dev_err(&udev->dev, "not enough memory for command_out_urb\n"); in vub300_probe()
2126 retval = -ENOMEM; in vub300_probe()
2127 dev_err(&udev->dev, "not enough memory for command_res_urb\n"); in vub300_probe()
2131 mmc = mmc_alloc_host(sizeof(struct vub300_mmc_host), &udev->dev); in vub300_probe()
2133 retval = -ENOMEM; in vub300_probe()
2134 dev_err(&udev->dev, "not enough memory for the mmc_host\n"); in vub300_probe()
2138 mmc->caps = 0; in vub300_probe()
2140 mmc->caps |= MMC_CAP_4_BIT_DATA; in vub300_probe()
2142 mmc->caps |= MMC_CAP_SDIO_IRQ; in vub300_probe()
2143 mmc->caps &= ~MMC_CAP_NEEDS_POLL; in vub300_probe()
2150 mmc->caps |= MMC_CAP_MMC_HIGHSPEED; in vub300_probe()
2151 mmc->caps |= MMC_CAP_SD_HIGHSPEED; in vub300_probe()
2152 mmc->f_max = 24000000; in vub300_probe()
2153 dev_info(&udev->dev, "limiting SDIO speed to 24_MHz\n"); in vub300_probe()
2155 mmc->caps |= MMC_CAP_MMC_HIGHSPEED; in vub300_probe()
2156 mmc->caps |= MMC_CAP_SD_HIGHSPEED; in vub300_probe()
2157 mmc->f_max = 48000000; in vub300_probe()
2159 mmc->f_min = 200000; in vub300_probe()
2160 mmc->max_blk_count = 511; in vub300_probe()
2161 mmc->max_blk_size = 512; in vub300_probe()
2162 mmc->max_segs = 128; in vub300_probe()
2164 mmc->max_req_size = force_max_req_size * 1024; in vub300_probe()
2166 mmc->max_req_size = 64 * 1024; in vub300_probe()
2167 mmc->max_seg_size = mmc->max_req_size; in vub300_probe()
2168 mmc->ocr_avail = 0; in vub300_probe()
2169 mmc->ocr_avail |= MMC_VDD_165_195; in vub300_probe()
2170 mmc->ocr_avail |= MMC_VDD_20_21; in vub300_probe()
2171 mmc->ocr_avail |= MMC_VDD_21_22; in vub300_probe()
2172 mmc->ocr_avail |= MMC_VDD_22_23; in vub300_probe()
2173 mmc->ocr_avail |= MMC_VDD_23_24; in vub300_probe()
2174 mmc->ocr_avail |= MMC_VDD_24_25; in vub300_probe()
2175 mmc->ocr_avail |= MMC_VDD_25_26; in vub300_probe()
2176 mmc->ocr_avail |= MMC_VDD_26_27; in vub300_probe()
2177 mmc->ocr_avail |= MMC_VDD_27_28; in vub300_probe()
2178 mmc->ocr_avail |= MMC_VDD_28_29; in vub300_probe()
2179 mmc->ocr_avail |= MMC_VDD_29_30; in vub300_probe()
2180 mmc->ocr_avail |= MMC_VDD_30_31; in vub300_probe()
2181 mmc->ocr_avail |= MMC_VDD_31_32; in vub300_probe()
2182 mmc->ocr_avail |= MMC_VDD_32_33; in vub300_probe()
2183 mmc->ocr_avail |= MMC_VDD_33_34; in vub300_probe()
2184 mmc->ocr_avail |= MMC_VDD_34_35; in vub300_probe()
2185 mmc->ocr_avail |= MMC_VDD_35_36; in vub300_probe()
2186 mmc->ops = &vub300_mmc_ops; in vub300_probe()
2188 vub300->mmc = mmc; in vub300_probe()
2189 vub300->card_powered = 0; in vub300_probe()
2190 vub300->bus_width = 0; in vub300_probe()
2191 vub300->cmnd.head.block_size[0] = 0x00; in vub300_probe()
2192 vub300->cmnd.head.block_size[1] = 0x00; in vub300_probe()
2193 vub300->app_spec = 0; in vub300_probe()
2194 mutex_init(&vub300->cmd_mutex); in vub300_probe()
2195 mutex_init(&vub300->irq_mutex); in vub300_probe()
2196 vub300->command_out_urb = command_out_urb; in vub300_probe()
2197 vub300->command_res_urb = command_res_urb; in vub300_probe()
2198 vub300->usb_timed_out = 0; in vub300_probe()
2199 vub300->dynamic_register_count = 0; in vub300_probe()
2201 for (i = 0; i < ARRAY_SIZE(vub300->fn); i++) { in vub300_probe()
2202 vub300->fn[i].offload_point = 0; in vub300_probe()
2203 vub300->fn[i].offload_count = 0; in vub300_probe()
2206 vub300->total_offload_count = 0; in vub300_probe()
2207 vub300->irq_enabled = 0; in vub300_probe()
2208 vub300->irq_disabled = 0; in vub300_probe()
2209 vub300->irqs_queued = 0; in vub300_probe()
2211 for (i = 0; i < ARRAY_SIZE(vub300->sdio_register); i++) in vub300_probe()
2212 vub300->sdio_register[i++].activate = 0; in vub300_probe()
2214 vub300->udev = udev; in vub300_probe()
2215 vub300->interface = interface; in vub300_probe()
2216 vub300->cmnd_res_ep = 0; in vub300_probe()
2217 vub300->cmnd_out_ep = 0; in vub300_probe()
2218 vub300->data_inp_ep = 0; in vub300_probe()
2219 vub300->data_out_ep = 0; in vub300_probe()
2221 for (i = 0; i < ARRAY_SIZE(vub300->fbs); i++) in vub300_probe()
2222 vub300->fbs[i] = 512; in vub300_probe()
2227 * use the first pair of bulk-in and bulk-out in vub300_probe()
2230 * use the second pair of bulk-in and bulk-out in vub300_probe()
2233 vub300->large_usb_packets = 0; in vub300_probe()
2234 iface_desc = interface->cur_altsetting; in vub300_probe()
2235 for (i = 0; i < iface_desc->desc.bNumEndpoints; ++i) { in vub300_probe()
2237 &iface_desc->endpoint[i].desc; in vub300_probe()
2238 dev_info(&vub300->udev->dev, in vub300_probe()
2242 "UNKNOWN", i, endpoint->bEndpointAddress); in vub300_probe()
2243 if (endpoint->wMaxPacketSize > 64) in vub300_probe()
2244 vub300->large_usb_packets = 1; in vub300_probe()
2246 if (!vub300->cmnd_res_ep) { in vub300_probe()
2247 vub300->cmnd_res_ep = in vub300_probe()
2248 endpoint->bEndpointAddress; in vub300_probe()
2249 } else if (!vub300->data_inp_ep) { in vub300_probe()
2250 vub300->data_inp_ep = in vub300_probe()
2251 endpoint->bEndpointAddress; in vub300_probe()
2253 dev_warn(&vub300->udev->dev, in vub300_probe()
2258 if (!vub300->cmnd_out_ep) { in vub300_probe()
2259 vub300->cmnd_out_ep = in vub300_probe()
2260 endpoint->bEndpointAddress; in vub300_probe()
2261 } else if (!vub300->data_out_ep) { in vub300_probe()
2262 vub300->data_out_ep = in vub300_probe()
2263 endpoint->bEndpointAddress; in vub300_probe()
2265 dev_warn(&vub300->udev->dev, in vub300_probe()
2270 dev_warn(&vub300->udev->dev, in vub300_probe()
2272 endpoint->bEndpointAddress); in vub300_probe()
2275 if (vub300->cmnd_res_ep && vub300->cmnd_out_ep && in vub300_probe()
2276 vub300->data_inp_ep && vub300->data_out_ep) { in vub300_probe()
2277 dev_info(&vub300->udev->dev, in vub300_probe()
2280 vub300->large_usb_packets ? "LARGE" : "SMALL", in vub300_probe()
2281 vub300->cmnd_out_ep, vub300->cmnd_res_ep, in vub300_probe()
2282 vub300->data_out_ep, vub300->data_inp_ep); in vub300_probe()
2285 dev_err(&vub300->udev->dev, in vub300_probe()
2286 "Could not find two sets of bulk-in/out endpoint pairs\n"); in vub300_probe()
2287 retval = -EINVAL; in vub300_probe()
2291 usb_control_msg(vub300->udev, usb_rcvctrlpipe(vub300->udev, 0), in vub300_probe()
2294 0x0000, 0x0000, &vub300->hc_info, in vub300_probe()
2295 sizeof(vub300->hc_info), HZ); in vub300_probe()
2299 usb_control_msg(vub300->udev, usb_rcvctrlpipe(vub300->udev, 0), in vub300_probe()
2305 dev_info(&vub300->udev->dev, in vub300_probe()
2307 (mmc->caps & MMC_CAP_SDIO_IRQ) ? "IRQs" : "POLL", in vub300_probe()
2308 (mmc->caps & MMC_CAP_4_BIT_DATA) ? "4-bit" : "1-bit", in vub300_probe()
2309 mmc->f_max / 1000000, in vub300_probe()
2311 vub300->large_usb_packets ? 512 : 64); in vub300_probe()
2313 usb_control_msg(vub300->udev, usb_rcvctrlpipe(vub300->udev, 0), in vub300_probe()
2316 0x0000, 0x0000, &vub300->system_port_status, in vub300_probe()
2317 sizeof(vub300->system_port_status), HZ); in vub300_probe()
2320 } else if (sizeof(vub300->system_port_status) == retval) { in vub300_probe()
2321 vub300->card_present = in vub300_probe()
2322 (0x0001 & vub300->system_port_status.port_flags) ? 1 : 0; in vub300_probe()
2323 vub300->read_only = in vub300_probe()
2324 (0x0010 & vub300->system_port_status.port_flags) ? 1 : 0; in vub300_probe()
2329 INIT_DELAYED_WORK(&vub300->pollwork, vub300_pollwork_thread); in vub300_probe()
2330 INIT_WORK(&vub300->cmndwork, vub300_cmndwork_thread); in vub300_probe()
2331 INIT_WORK(&vub300->deadwork, vub300_deadwork_thread); in vub300_probe()
2332 kref_init(&vub300->kref); in vub300_probe()
2333 init_timer(&vub300->sg_transfer_timer); in vub300_probe()
2334 vub300->sg_transfer_timer.data = (unsigned long)vub300; in vub300_probe()
2335 vub300->sg_transfer_timer.function = vub300_sg_timed_out; in vub300_probe()
2336 kref_get(&vub300->kref); in vub300_probe()
2337 init_timer(&vub300->inactivity_timer); in vub300_probe()
2338 vub300->inactivity_timer.data = (unsigned long)vub300; in vub300_probe()
2339 vub300->inactivity_timer.function = vub300_inactivity_timer_expired; in vub300_probe()
2340 vub300->inactivity_timer.expires = jiffies + HZ; in vub300_probe()
2341 add_timer(&vub300->inactivity_timer); in vub300_probe()
2342 if (vub300->card_present) in vub300_probe()
2343 dev_info(&vub300->udev->dev, in vub300_probe()
2348 dev_info(&vub300->udev->dev, in vub300_probe()
2371 if (!vub300 || !vub300->mmc) { in vub300_disconnect()
2374 struct mmc_host *mmc = vub300->mmc; in vub300_disconnect()
2375 if (!vub300->mmc) { in vub300_disconnect()
2381 vub300->interface = NULL; in vub300_disconnect()
2382 kref_put(&vub300->kref, vub300_delete); in vub300_disconnect()
2395 if (!vub300 || !vub300->mmc) { in vub300_suspend()
2398 struct mmc_host *mmc = vub300->mmc; in vub300_suspend()
2407 if (!vub300 || !vub300->mmc) { in vub300_resume()
2410 struct mmc_host *mmc = vub300->mmc; in vub300_resume()
2422 mutex_lock(&vub300->cmd_mutex); in vub300_pre_reset()
2429 /* we are sure no URBs are active - no locking needed */ in vub300_post_reset()
2430 vub300->errors = -EPIPE; in vub300_post_reset()
2431 mutex_unlock(&vub300->cmd_mutex); in vub300_post_reset()
2456 result = -ENOMEM; in vub300_init()
2462 result = -ENOMEM; in vub300_init()
2468 result = -ENOMEM; in vub300_init()