• Home
  • Raw
  • Download

Lines Matching +full:full +full:- +full:bit

1 // SPDX-License-Identifier: GPL-2.0
5 * Author: David Mosberger-Tang <davidm@egauge.net>
7 * (C) Copyright 2014 David Mosberger-Tang <davidm@egauge.net>
9 * MAX3421 is a chip implementing a USB 2.0 Full-/Low-Speed host
16 * https://www.hdl.co.jp/ftpdata/utl-001/AN3785.pdf
24 * Important note on worst-case (full-speed) packet size constraints
27 * - control: 64 bytes
28 * - isochronous: 1023 bytes
29 * - interrupt: 64 bytes
30 * - bulk: 64 bytes
33 * multi-FIFO writes/reads for a single USB packet *except* for isochronous
38 * (AN3785) has conflicting info for the RCVDAVIRQ bit:
41 * this IRQ bit (by writing a 1 to it) before reading the
44 * However, the earlier section on "Programming BULK-IN
48 * RCVDAVIRQ bit.
54 * transactions while holding a spin-lock (and/or while interrupts are
66 #include <linux/platform_data/max3421-hcd.h>
68 #define DRIVER_DESC "MAX3421 USB Host-Controller Driver"
71 /* 11-bit counter that wraps around (USB 2.0 Section 8.3.3): */
81 #define POWER_BUDGET 500 /* in mA; use 8 for low-power port testing */
83 /* Port-change mask: */
110 /* Bit numbers for max3421_hcd->todo: */
138 * SPI-thread without acquiring the HCD lock:
144 * cache-lines:
154 int urb_done; /* > 0 -> no errors, < 0: errno */
237 MAX3421_HI_BUSEVENT_BIT = 0, /* bus-reset/-resume */
293 /* Return same error-codes as ohci.h:cc_to_error: */
296 [MAX3421_HRSL_BUSY] = -EINVAL,
297 [MAX3421_HRSL_BADREQ] = -EINVAL,
298 [MAX3421_HRSL_UNDEF] = -EINVAL,
299 [MAX3421_HRSL_NAK] = -EAGAIN,
300 [MAX3421_HRSL_STALL] = -EPIPE,
301 [MAX3421_HRSL_TOGERR] = -EILSEQ,
302 [MAX3421_HRSL_WRONGPID] = -EPROTO,
303 [MAX3421_HRSL_BADBC] = -EREMOTEIO,
304 [MAX3421_HRSL_PIDERR] = -EPROTO,
305 [MAX3421_HRSL_PKTERR] = -EPROTO,
306 [MAX3421_HRSL_CRCERR] = -EILSEQ,
307 [MAX3421_HRSL_KERR] = -EIO,
308 [MAX3421_HRSL_JERR] = -EIO,
309 [MAX3421_HRSL_TIMEOUT] = -ETIME,
310 [MAX3421_HRSL_BABBLE] = -EOVERFLOW
326 #define field(val, bit) ((val) << (bit)) argument
331 return ((unsigned) (left - right)) % (USB_MAX_FRAME_NUMBER + 1); in frame_diff()
337 return (struct max3421_hcd *) hcd->hcd_priv; in hcd_to_max3421()
350 struct spi_device *spi = to_spi_device(hcd->self.controller); in spi_rd8()
358 max3421_hcd->tx->data[0] = in spi_rd8()
362 transfer.tx_buf = max3421_hcd->tx->data; in spi_rd8()
363 transfer.rx_buf = max3421_hcd->rx->data; in spi_rd8()
369 return max3421_hcd->rx->data[1]; in spi_rd8()
375 struct spi_device *spi = to_spi_device(hcd->self.controller); in spi_wr8()
384 max3421_hcd->tx->data[0] = in spi_wr8()
387 max3421_hcd->tx->data[1] = val; in spi_wr8()
389 transfer.tx_buf = max3421_hcd->tx->data; in spi_wr8()
399 struct spi_device *spi = to_spi_device(hcd->self.controller); in spi_rd_buf()
408 max3421_hcd->tx->data[0] = in spi_rd_buf()
411 transfer[0].tx_buf = max3421_hcd->tx->data; in spi_rd_buf()
425 struct spi_device *spi = to_spi_device(hcd->self.controller); in spi_wr_buf()
434 max3421_hcd->tx->data[0] = in spi_wr_buf()
438 transfer[0].tx_buf = max3421_hcd->tx->data; in spi_wr_buf()
451 * bits. The HUBPRE bit needs to be set when MAX3421E operates at
452 * full speed, but it's talking to a low-speed device (i.e., through a
453 * hub). Setting that bit ensures that every low-speed packet is
454 * preceded by a full-speed PRE PID. Possible configurations:
456 * Hub speed: Device speed: => LOWSPEED bit: HUBPRE bit:
457 * FULL FULL => 0 0
458 * FULL LOW => 1 1
460 * LOW FULL => 1 0
466 u8 mode_lowspeed, mode_hubpre, mode = max3421_hcd->mode; in max3421_set_speed()
468 mode_lowspeed = BIT(MAX3421_MODE_LOWSPEED_BIT); in max3421_set_speed()
469 mode_hubpre = BIT(MAX3421_MODE_HUBPRE_BIT); in max3421_set_speed()
470 if (max3421_hcd->port_status & USB_PORT_STAT_LOW_SPEED) { in max3421_set_speed()
473 } else if (dev->speed == USB_SPEED_LOW) { in max3421_set_speed()
478 if (mode != max3421_hcd->mode) { in max3421_set_speed()
479 max3421_hcd->mode = mode; in max3421_set_speed()
480 spi_wr8(hcd, MAX3421_REG_MODE, max3421_hcd->mode); in max3421_set_speed()
497 hctl = (BIT(rcvtog + MAX3421_HCTL_RCVTOG0_BIT) | in max3421_set_address()
498 BIT(sndtog + MAX3421_HCTL_SNDTOG0_BIT)); in max3421_set_address()
504 * address-assignment so it's best to just always load the in max3421_set_address()
505 * address whenever the end-point changed/was forced. in max3421_set_address()
507 spi_wr8(hcd, MAX3421_REG_PERADDR, dev->devnum); in max3421_set_address()
513 spi_wr_buf(hcd, MAX3421_REG_SUDFIFO, urb->setup_packet, 8); in max3421_ctrl_setup()
521 int epnum = usb_pipeendpoint(urb->pipe); in max3421_transfer_in()
523 max3421_hcd->curr_len = 0; in max3421_transfer_in()
524 max3421_hcd->hien |= BIT(MAX3421_HI_RCVDAV_BIT); in max3421_transfer_in()
531 struct spi_device *spi = to_spi_device(hcd->self.controller); in max3421_transfer_out()
533 int epnum = usb_pipeendpoint(urb->pipe); in max3421_transfer_out()
537 src = urb->transfer_buffer + urb->actual_length; in max3421_transfer_out()
540 if (max3421_hcd->rev == 0x12) { in max3421_transfer_out()
544 spi_wr8(hcd, MAX3421_REG_SNDBC, max3421_hcd->curr_len); in max3421_transfer_out()
549 max_packet = usb_maxpacket(urb->dev, urb->pipe, 1); in max3421_transfer_out()
556 dev_err(&spi->dev, in max3421_transfer_out()
557 "%s: packet-size of %u too big (limit is %u bytes)", in max3421_transfer_out()
559 max3421_hcd->urb_done = -EMSGSIZE; in max3421_transfer_out()
560 return -EMSGSIZE; in max3421_transfer_out()
562 max3421_hcd->curr_len = min((urb->transfer_buffer_length - in max3421_transfer_out()
563 urb->actual_length), max_packet); in max3421_transfer_out()
565 spi_wr_buf(hcd, MAX3421_REG_SNDFIFO, src, max3421_hcd->curr_len); in max3421_transfer_out()
566 spi_wr8(hcd, MAX3421_REG_SNDBC, max3421_hcd->curr_len); in max3421_transfer_out()
571 * Issue the next host-transfer command.
578 struct urb *urb = max3421_hcd->curr_urb; in max3421_next_transfer()
580 int cmd = -EINVAL; in max3421_next_transfer()
585 max3421_ep = urb->ep->hcpriv; in max3421_next_transfer()
587 switch (max3421_ep->pkt_state) { in max3421_next_transfer()
614 /* issue the command and wait for host-xfer-done interrupt: */ in max3421_next_transfer()
617 max3421_hcd->hien |= BIT(MAX3421_HI_HXFRDN_BIT); in max3421_next_transfer()
627 * frame to process non-periodic (bulk & control) transfers.
631 * o max3421_hcd->curr_urb MUST BE NULL.
637 struct spi_device *spi = to_spi_device(hcd->self.controller); in max3421_select_and_start_urb()
646 spin_lock_irqsave(&max3421_hcd->lock, flags); in max3421_select_and_start_urb()
649 max3421_hcd->sched_pass < SCHED_PASS_DONE; in max3421_select_and_start_urb()
650 ++max3421_hcd->sched_pass) in max3421_select_and_start_urb()
651 list_for_each(pos, &max3421_hcd->ep_list) { in max3421_select_and_start_urb()
655 ep = max3421_ep->ep; in max3421_select_and_start_urb()
657 switch (usb_endpoint_type(&ep->desc)) { in max3421_select_and_start_urb()
660 if (max3421_hcd->sched_pass != in max3421_select_and_start_urb()
667 if (max3421_hcd->sched_pass != in max3421_select_and_start_urb()
673 if (list_empty(&ep->urb_list)) in max3421_select_and_start_urb()
675 urb = list_first_entry(&ep->urb_list, struct urb, in max3421_select_and_start_urb()
677 if (urb->unlinked) { in max3421_select_and_start_urb()
678 dev_dbg(&spi->dev, "%s: URB %p unlinked=%d", in max3421_select_and_start_urb()
679 __func__, urb, urb->unlinked); in max3421_select_and_start_urb()
680 max3421_hcd->curr_urb = urb; in max3421_select_and_start_urb()
681 max3421_hcd->urb_done = 1; in max3421_select_and_start_urb()
682 spin_unlock_irqrestore(&max3421_hcd->lock, in max3421_select_and_start_urb()
687 switch (usb_endpoint_type(&ep->desc)) { in max3421_select_and_start_urb()
693 if (frame_diff(max3421_ep->last_active, in max3421_select_and_start_urb()
694 max3421_hcd->frame_number) == 0) in max3421_select_and_start_urb()
699 if (max3421_ep->retransmit in max3421_select_and_start_urb()
700 && (frame_diff(max3421_ep->last_active, in max3421_select_and_start_urb()
701 max3421_hcd->frame_number) in max3421_select_and_start_urb()
713 if (frame_diff(max3421_hcd->frame_number, in max3421_select_and_start_urb()
714 max3421_ep->last_active) in max3421_select_and_start_urb()
715 < urb->interval) in max3421_select_and_start_urb()
718 * end-point in the current in max3421_select_and_start_urb()
726 list_move_tail(pos, &max3421_hcd->ep_list); in max3421_select_and_start_urb()
732 spin_unlock_irqrestore(&max3421_hcd->lock, flags); in max3421_select_and_start_urb()
736 urb = max3421_hcd->curr_urb = curr_urb; in max3421_select_and_start_urb()
737 epnum = usb_endpoint_num(&urb->ep->desc); in max3421_select_and_start_urb()
738 if (max3421_ep->retransmit) in max3421_select_and_start_urb()
740 max3421_ep->retransmit = 0; in max3421_select_and_start_urb()
743 if (usb_endpoint_xfer_control(&ep->desc)) { in max3421_select_and_start_urb()
748 usb_settoggle(urb->dev, epnum, 0, 1); in max3421_select_and_start_urb()
749 usb_settoggle(urb->dev, epnum, 1, 1); in max3421_select_and_start_urb()
750 max3421_ep->pkt_state = PKT_STATE_SETUP; in max3421_select_and_start_urb()
752 max3421_ep->pkt_state = PKT_STATE_TRANSFER; in max3421_select_and_start_urb()
755 spin_unlock_irqrestore(&max3421_hcd->lock, flags); in max3421_select_and_start_urb()
757 max3421_ep->last_active = max3421_hcd->frame_number; in max3421_select_and_start_urb()
758 max3421_set_address(hcd, urb->dev, epnum); in max3421_select_and_start_urb()
759 max3421_set_speed(hcd, urb->dev); in max3421_select_and_start_urb()
772 struct spi_device *spi = to_spi_device(hcd->self.controller); in max3421_check_unlink()
780 spin_lock_irqsave(&max3421_hcd->lock, flags); in max3421_check_unlink()
781 list_for_each_entry(max3421_ep, &max3421_hcd->ep_list, ep_list) { in max3421_check_unlink()
782 ep = max3421_ep->ep; in max3421_check_unlink()
783 list_for_each_entry_safe(urb, next, &ep->urb_list, urb_list) { in max3421_check_unlink()
784 if (urb->unlinked) { in max3421_check_unlink()
786 dev_dbg(&spi->dev, "%s: URB %p unlinked=%d", in max3421_check_unlink()
787 __func__, urb, urb->unlinked); in max3421_check_unlink()
789 spin_unlock_irqrestore(&max3421_hcd->lock, in max3421_check_unlink()
792 spin_lock_irqsave(&max3421_hcd->lock, flags); in max3421_check_unlink()
796 spin_unlock_irqrestore(&max3421_hcd->lock, flags); in max3421_check_unlink()
807 struct urb *urb = max3421_hcd->curr_urb; in max3421_slow_retransmit()
810 max3421_ep = urb->ep->hcpriv; in max3421_slow_retransmit()
811 max3421_ep->retransmit = 1; in max3421_slow_retransmit()
812 max3421_hcd->curr_urb = NULL; in max3421_slow_retransmit()
822 struct urb *urb = max3421_hcd->curr_urb; in max3421_recv_data_available()
830 if (urb->actual_length >= urb->transfer_buffer_length) in max3421_recv_data_available()
833 remaining = urb->transfer_buffer_length - urb->actual_length; in max3421_recv_data_available()
838 void *dst = urb->transfer_buffer + urb->actual_length; in max3421_recv_data_available()
841 urb->actual_length += transfer_size; in max3421_recv_data_available()
842 max3421_hcd->curr_len = transfer_size; in max3421_recv_data_available()
846 spi_wr8(hcd, MAX3421_REG_HIRQ, BIT(MAX3421_HI_RCVDAV_BIT)); in max3421_recv_data_available()
852 struct spi_device *spi = to_spi_device(hcd->self.controller); in max3421_handle_error()
855 struct urb *urb = max3421_hcd->curr_urb; in max3421_handle_error()
856 struct max3421_ep *max3421_ep = urb->ep->hcpriv; in max3421_handle_error()
861 * (i.e., error or NAK), we have to perform a dummy-write to in max3421_handle_error()
865 switch_sndfifo = (max3421_ep->pkt_state == PKT_STATE_TRANSFER && in max3421_handle_error()
876 case MAX3421_HRSL_KERR: /* K-state instead of response */ in max3421_handle_error()
877 case MAX3421_HRSL_JERR: /* J-state instead of response */ in max3421_handle_error()
882 max3421_hcd->urb_done = hrsl_to_error[result_code]; in max3421_handle_error()
883 dev_dbg(&spi->dev, "%s: unexpected error HRSL=0x%02x", in max3421_handle_error()
891 /* flip the send toggle bit: */ in max3421_handle_error()
896 BIT(sndtog + MAX3421_HCTL_SNDTOG0_BIT)); in max3421_handle_error()
905 if (max3421_ep->retries++ < USB_MAX_RETRIES) in max3421_handle_error()
910 max3421_hcd->urb_done = hrsl_to_error[result_code]; in max3421_handle_error()
911 dev_dbg(&spi->dev, "%s: unexpected error HRSL=0x%02x", in max3421_handle_error()
917 dev_dbg(&spi->dev, "%s: unexpected error HRSL=0x%02x", in max3421_handle_error()
919 max3421_hcd->urb_done = hrsl_to_error[result_code]; in max3421_handle_error()
927 if (max3421_ep->naks++ < NAK_MAX_FAST_RETRANSMITS) { in max3421_handle_error()
944 struct spi_device *spi = to_spi_device(hcd->self.controller); in max3421_transfer_in_done()
948 if (urb->actual_length >= urb->transfer_buffer_length) in max3421_transfer_in_done()
952 * USB 2.0 Section 5.3.2 Pipes: packets must be full size in max3421_transfer_in_done()
955 max_packet = usb_maxpacket(urb->dev, urb->pipe, 0); in max3421_transfer_in_done()
961 dev_err(&spi->dev, in max3421_transfer_in_done()
962 "%s: packet-size of %u too big (limit is %u bytes)", in max3421_transfer_in_done()
964 return -EINVAL; in max3421_transfer_in_done()
967 if (max3421_hcd->curr_len < max_packet) { in max3421_transfer_in_done()
968 if (urb->transfer_flags & URB_SHORT_NOT_OK) { in max3421_transfer_in_done()
971 * unexpected partial packet -> in max3421_transfer_in_done()
974 return -EREMOTEIO; in max3421_transfer_in_done()
990 urb->actual_length += max3421_hcd->curr_len; in max3421_transfer_out_done()
991 if (urb->actual_length < urb->transfer_buffer_length) in max3421_transfer_out_done()
993 if (urb->transfer_flags & URB_ZERO_PACKET) { in max3421_transfer_out_done()
995 * Some hardware needs a zero-size packet at the end in max3421_transfer_out_done()
996 * of a bulk-out transfer if the last transfer was a in max3421_transfer_out_done()
997 * full-sized packet (i.e., such hardware use < in max3421_transfer_out_done()
1001 u32 max_packet = usb_maxpacket(urb->dev, urb->pipe, 1); in max3421_transfer_out_done()
1003 if (max3421_hcd->curr_len == max_packet) in max3421_transfer_out_done()
1016 struct urb *urb = max3421_hcd->curr_urb; in max3421_host_transfer_done()
1021 max3421_hcd->hien &= ~(BIT(MAX3421_HI_HXFRDN_BIT) | in max3421_host_transfer_done()
1022 BIT(MAX3421_HI_RCVDAV_BIT)); in max3421_host_transfer_done()
1028 ++max3421_hcd->err_stat[result_code]; in max3421_host_transfer_done()
1031 max3421_ep = urb->ep->hcpriv; in max3421_host_transfer_done()
1038 max3421_ep->naks = 0; in max3421_host_transfer_done()
1039 max3421_ep->retries = 0; in max3421_host_transfer_done()
1040 switch (max3421_ep->pkt_state) { in max3421_host_transfer_done()
1043 if (urb->transfer_buffer_length > 0) in max3421_host_transfer_done()
1044 max3421_ep->pkt_state = PKT_STATE_TRANSFER; in max3421_host_transfer_done()
1046 max3421_ep->pkt_state = PKT_STATE_TERMINATE; in max3421_host_transfer_done()
1054 if (urb_done > 0 && usb_pipetype(urb->pipe) == PIPE_CONTROL) { in max3421_host_transfer_done()
1056 * We aren't really done - we still need to in max3421_host_transfer_done()
1059 max3421_hcd->urb_done = urb_done = 0; in max3421_host_transfer_done()
1060 max3421_ep->pkt_state = PKT_STATE_TERMINATE; in max3421_host_transfer_done()
1070 max3421_hcd->urb_done = urb_done; in max3421_host_transfer_done()
1092 mode = max3421_hcd->mode; in max3421_detect_conn()
1097 * Turn off SOFKAENAB bit to avoid getting interrupt in max3421_detect_conn()
1098 * every milli-second: in max3421_detect_conn()
1100 mode &= ~BIT(MAX3421_MODE_SOFKAENAB_BIT); in max3421_detect_conn()
1103 case 0x1: /* J=0,K=1: low-speed (in full-speed or vice versa) */ in max3421_detect_conn()
1104 case 0x2: /* J=1,K=0: full-speed (in full-speed or vice versa) */ in max3421_detect_conn()
1107 mode ^= BIT(MAX3421_MODE_LOWSPEED_BIT); in max3421_detect_conn()
1108 /* turn on SOFKAENAB bit: */ in max3421_detect_conn()
1109 mode |= BIT(MAX3421_MODE_SOFKAENAB_BIT); in max3421_detect_conn()
1117 max3421_hcd->mode = mode; in max3421_detect_conn()
1118 spi_wr8(hcd, MAX3421_REG_MODE, max3421_hcd->mode); in max3421_detect_conn()
1120 spin_lock_irqsave(&max3421_hcd->lock, flags); in max3421_detect_conn()
1121 old_port_status = max3421_hcd->port_status; in max3421_detect_conn()
1123 max3421_hcd->port_status |= USB_PORT_STAT_CONNECTION; in max3421_detect_conn()
1125 max3421_hcd->port_status &= ~USB_PORT_STAT_CONNECTION; in max3421_detect_conn()
1126 if (mode & BIT(MAX3421_MODE_LOWSPEED_BIT)) in max3421_detect_conn()
1127 max3421_hcd->port_status |= USB_PORT_STAT_LOW_SPEED; in max3421_detect_conn()
1129 max3421_hcd->port_status &= ~USB_PORT_STAT_LOW_SPEED; in max3421_detect_conn()
1130 chg = (old_port_status ^ max3421_hcd->port_status); in max3421_detect_conn()
1131 max3421_hcd->port_status |= chg << 16; in max3421_detect_conn()
1132 spin_unlock_irqrestore(&max3421_hcd->lock, flags); in max3421_detect_conn()
1139 struct spi_device *spi = to_spi_device(hcd->self.controller); in max3421_irq_handler()
1142 if (max3421_hcd->spi_thread && in max3421_irq_handler()
1143 max3421_hcd->spi_thread->state != TASK_RUNNING) in max3421_irq_handler()
1144 wake_up_process(max3421_hcd->spi_thread); in max3421_irq_handler()
1145 if (!test_and_set_bit(ENABLE_IRQ, &max3421_hcd->todo)) in max3421_irq_handler()
1146 disable_irq_nosync(spi->irq); in max3421_irq_handler()
1163 spin_lock_irqsave(&max3421_hcd->lock, flags); in dump_eps()
1164 list_for_each_entry(max3421_ep, &max3421_hcd->ep_list, ep_list) { in dump_eps()
1165 ep = max3421_ep->ep; in dump_eps()
1170 list_for_each_entry(urb, &ep->urb_list, urb_list) { in dump_eps()
1171 ret = snprintf(dp, end - dp, " %p(%d.%s %d/%d)", urb, in dump_eps()
1172 usb_pipetype(urb->pipe), in dump_eps()
1174 urb->actual_length, in dump_eps()
1175 urb->transfer_buffer_length); in dump_eps()
1176 if (ret < 0 || ret >= end - dp) in dump_eps()
1177 break; /* error or buffer full */ in dump_eps()
1181 epnum = usb_endpoint_num(&ep->desc); in dump_eps()
1183 epnum, max3421_ep->pkt_state, max3421_ep->last_active, in dump_eps()
1184 max3421_ep->retries, max3421_ep->naks, in dump_eps()
1185 max3421_ep->retransmit, ubuf); in dump_eps()
1187 spin_unlock_irqrestore(&max3421_hcd->lock, flags); in dump_eps()
1207 hirq &= max3421_hcd->hien; in max3421_handle_irqs()
1212 hirq & ~(BIT(MAX3421_HI_SNDBAV_BIT) | in max3421_handle_irqs()
1213 BIT(MAX3421_HI_RCVDAV_BIT))); in max3421_handle_irqs()
1215 if (hirq & BIT(MAX3421_HI_FRAME_BIT)) { in max3421_handle_irqs()
1216 max3421_hcd->frame_number = ((max3421_hcd->frame_number + 1) in max3421_handle_irqs()
1218 max3421_hcd->sched_pass = SCHED_PASS_PERIODIC; in max3421_handle_irqs()
1221 if (hirq & BIT(MAX3421_HI_RCVDAV_BIT)) in max3421_handle_irqs()
1224 if (hirq & BIT(MAX3421_HI_HXFRDN_BIT)) in max3421_handle_irqs()
1227 if (hirq & BIT(MAX3421_HI_CONDET_BIT)) in max3421_handle_irqs()
1232 * other than the end-points: in max3421_handle_irqs()
1234 spin_lock_irqsave(&max3421_hcd->lock, flags); in max3421_handle_irqs()
1236 old_port_status = max3421_hcd->port_status; in max3421_handle_irqs()
1237 if (hirq & BIT(MAX3421_HI_BUSEVENT_BIT)) { in max3421_handle_irqs()
1238 if (max3421_hcd->port_status & USB_PORT_STAT_RESET) { in max3421_handle_irqs()
1240 max3421_hcd->port_status &= ~USB_PORT_STAT_RESET; in max3421_handle_irqs()
1241 max3421_hcd->port_status |= USB_PORT_STAT_ENABLE; in max3421_handle_irqs()
1247 if (hirq & BIT(MAX3421_HI_RWU_BIT)) in max3421_handle_irqs()
1249 if (hirq & BIT(MAX3421_HI_SUSDN_BIT)) in max3421_handle_irqs()
1252 chg = (old_port_status ^ max3421_hcd->port_status); in max3421_handle_irqs()
1253 max3421_hcd->port_status |= chg << 16; in max3421_handle_irqs()
1255 spin_unlock_irqrestore(&max3421_hcd->lock, flags); in max3421_handle_irqs()
1268 int ret = snprintf(dp, end - dp, " %lu", in max3421_handle_irqs()
1269 max3421_hcd->err_stat[i]); in max3421_handle_irqs()
1270 if (ret < 0 || ret >= end - dp) in max3421_handle_irqs()
1271 break; /* error or buffer full */ in max3421_handle_irqs()
1275 memset(max3421_hcd->err_stat, 0, in max3421_handle_irqs()
1276 sizeof(max3421_hcd->err_stat)); in max3421_handle_irqs()
1289 struct spi_device *spi = to_spi_device(hcd->self.controller); in max3421_reset_hcd()
1294 spi_wr8(hcd, MAX3421_REG_USBCTL, BIT(MAX3421_USBCTL_CHIPRES_BIT)); in max3421_reset_hcd()
1300 & BIT(MAX3421_USBIRQ_OSCOKIRQ_BIT)) in max3421_reset_hcd()
1302 if (--timeout < 0) { in max3421_reset_hcd()
1303 dev_err(&spi->dev, in max3421_reset_hcd()
1312 * enable pull-down registers on DM/DP: in max3421_reset_hcd()
1314 max3421_hcd->mode = (BIT(MAX3421_MODE_HOST_BIT) | in max3421_reset_hcd()
1315 BIT(MAX3421_MODE_SOFKAENAB_BIT) | in max3421_reset_hcd()
1316 BIT(MAX3421_MODE_DMPULLDN_BIT) | in max3421_reset_hcd()
1317 BIT(MAX3421_MODE_DPPULLDN_BIT)); in max3421_reset_hcd()
1318 spi_wr8(hcd, MAX3421_REG_MODE, max3421_hcd->mode); in max3421_reset_hcd()
1320 /* reset frame-number: */ in max3421_reset_hcd()
1321 max3421_hcd->frame_number = USB_MAX_FRAME_NUMBER; in max3421_reset_hcd()
1322 spi_wr8(hcd, MAX3421_REG_HCTL, BIT(MAX3421_HCTL_FRMRST_BIT)); in max3421_reset_hcd()
1324 /* sample the state of the D+ and D- lines */ in max3421_reset_hcd()
1325 spi_wr8(hcd, MAX3421_REG_HCTL, BIT(MAX3421_HCTL_SAMPLEBUS_BIT)); in max3421_reset_hcd()
1328 /* enable frame, connection-detected, and bus-event interrupts: */ in max3421_reset_hcd()
1329 max3421_hcd->hien = (BIT(MAX3421_HI_FRAME_BIT) | in max3421_reset_hcd()
1330 BIT(MAX3421_HI_CONDET_BIT) | in max3421_reset_hcd()
1331 BIT(MAX3421_HI_BUSEVENT_BIT)); in max3421_reset_hcd()
1332 spi_wr8(hcd, MAX3421_REG_HIEN, max3421_hcd->hien); in max3421_reset_hcd()
1335 spi_wr8(hcd, MAX3421_REG_CPUCTL, BIT(MAX3421_CPUCTL_IE_BIT)); in max3421_reset_hcd()
1347 status = max3421_hcd->urb_done; in max3421_urb_done()
1348 max3421_hcd->urb_done = 0; in max3421_urb_done()
1351 urb = max3421_hcd->curr_urb; in max3421_urb_done()
1353 /* save the old end-points toggles: */ in max3421_urb_done()
1357 int epnum = usb_endpoint_num(&urb->ep->desc); in max3421_urb_done()
1360 usb_settoggle(urb->dev, epnum, 0, rcvtog); in max3421_urb_done()
1361 usb_settoggle(urb->dev, epnum, 1, sndtog); in max3421_urb_done()
1363 max3421_hcd->curr_urb = NULL; in max3421_urb_done()
1364 spin_lock_irqsave(&max3421_hcd->lock, flags); in max3421_urb_done()
1366 spin_unlock_irqrestore(&max3421_hcd->lock, flags); in max3421_urb_done()
1378 struct spi_device *spi = to_spi_device(hcd->self.controller); in max3421_spi_thread()
1382 /* set full-duplex SPI mode, low-active interrupt pin: */ in max3421_spi_thread()
1384 (BIT(MAX3421_PINCTL_FDUPSPI_BIT) | /* full-duplex */ in max3421_spi_thread()
1385 BIT(MAX3421_PINCTL_INTLEVEL_BIT))); /* low-active irq */ in max3421_spi_thread()
1388 max3421_hcd->rev = spi_rd8(hcd, MAX3421_REG_REVISION); in max3421_spi_thread()
1389 if (max3421_hcd->rev == 0x12 || max3421_hcd->rev == 0x13) in max3421_spi_thread()
1391 dev_err(&spi->dev, "bad rev 0x%02x", max3421_hcd->rev); in max3421_spi_thread()
1394 dev_info(&spi->dev, "rev 0x%x, SPI clk %dHz, bpw %u, irq %d\n", in max3421_spi_thread()
1395 max3421_hcd->rev, spi->max_speed_hz, spi->bits_per_word, in max3421_spi_thread()
1396 spi->irq); in max3421_spi_thread()
1405 spi_wr8(hcd, MAX3421_REG_HIEN, max3421_hcd->hien); in max3421_spi_thread()
1408 if (test_and_clear_bit(ENABLE_IRQ, &max3421_hcd->todo)) in max3421_spi_thread()
1409 enable_irq(spi->irq); in max3421_spi_thread()
1416 if (max3421_hcd->urb_done) in max3421_spi_thread()
1420 else if (!max3421_hcd->curr_urb) in max3421_spi_thread()
1423 if (test_and_clear_bit(RESET_HCD, &max3421_hcd->todo)) in max3421_spi_thread()
1426 if (test_and_clear_bit(RESET_PORT, &max3421_hcd->todo)) { in max3421_spi_thread()
1429 BIT(MAX3421_HCTL_BUSRST_BIT)); in max3421_spi_thread()
1432 if (test_and_clear_bit(CHECK_UNLINK, &max3421_hcd->todo)) in max3421_spi_thread()
1434 if (test_and_clear_bit(IOPIN_UPDATE, &max3421_hcd->todo)) { in max3421_spi_thread()
1436 * IOPINS1/IOPINS2 do not auto-increment, so we can't in max3421_spi_thread()
1439 for (i = 0; i < ARRAY_SIZE(max3421_hcd->iopins); ++i) { in max3421_spi_thread()
1443 (max3421_hcd->iopins[i] & 0x0f)); in max3421_spi_thread()
1445 max3421_hcd->iopins[i] = val; in max3421_spi_thread()
1451 dev_info(&spi->dev, "SPI thread exiting"); in max3421_spi_thread()
1460 max3421_hcd->port_status &= ~(USB_PORT_STAT_ENABLE | in max3421_reset_port()
1462 max3421_hcd->port_status |= USB_PORT_STAT_RESET; in max3421_reset_port()
1463 set_bit(RESET_PORT, &max3421_hcd->todo); in max3421_reset_port()
1464 wake_up_process(max3421_hcd->spi_thread); in max3421_reset_port()
1473 hcd->self.sg_tablesize = 0; in max3421_reset()
1474 hcd->speed = HCD_USB2; in max3421_reset()
1475 hcd->self.root_hub->speed = USB_SPEED_FULL; in max3421_reset()
1476 set_bit(RESET_HCD, &max3421_hcd->todo); in max3421_reset()
1477 wake_up_process(max3421_hcd->spi_thread); in max3421_reset()
1486 spin_lock_init(&max3421_hcd->lock); in max3421_start()
1487 max3421_hcd->rh_state = MAX3421_RH_RUNNING; in max3421_start()
1489 INIT_LIST_HEAD(&max3421_hcd->ep_list); in max3421_start()
1491 hcd->power_budget = POWER_BUDGET; in max3421_start()
1492 hcd->state = HC_STATE_RUNNING; in max3421_start()
1493 hcd->uses_new_polling = 1; in max3421_start()
1505 struct spi_device *spi = to_spi_device(hcd->self.controller); in max3421_urb_enqueue()
1511 switch (usb_pipetype(urb->pipe)) { in max3421_urb_enqueue()
1514 if (urb->interval < 0) { in max3421_urb_enqueue()
1515 dev_err(&spi->dev, in max3421_urb_enqueue()
1516 "%s: interval=%d for intr-/iso-pipe; expected > 0\n", in max3421_urb_enqueue()
1517 __func__, urb->interval); in max3421_urb_enqueue()
1518 return -EINVAL; in max3421_urb_enqueue()
1524 spin_lock_irqsave(&max3421_hcd->lock, flags); in max3421_urb_enqueue()
1526 max3421_ep = urb->ep->hcpriv; in max3421_urb_enqueue()
1531 retval = -ENOMEM; in max3421_urb_enqueue()
1534 max3421_ep->ep = urb->ep; in max3421_urb_enqueue()
1535 max3421_ep->last_active = max3421_hcd->frame_number; in max3421_urb_enqueue()
1536 urb->ep->hcpriv = max3421_ep; in max3421_urb_enqueue()
1538 list_add_tail(&max3421_ep->ep_list, &max3421_hcd->ep_list); in max3421_urb_enqueue()
1544 max3421_hcd->sched_pass = SCHED_PASS_PERIODIC; in max3421_urb_enqueue()
1545 wake_up_process(max3421_hcd->spi_thread); in max3421_urb_enqueue()
1549 spin_unlock_irqrestore(&max3421_hcd->lock, flags); in max3421_urb_enqueue()
1560 spin_lock_irqsave(&max3421_hcd->lock, flags); in max3421_urb_dequeue()
1563 * This will set urb->unlinked which in turn causes the entry in max3421_urb_dequeue()
1568 set_bit(CHECK_UNLINK, &max3421_hcd->todo); in max3421_urb_dequeue()
1569 wake_up_process(max3421_hcd->spi_thread); in max3421_urb_dequeue()
1571 spin_unlock_irqrestore(&max3421_hcd->lock, flags); in max3421_urb_dequeue()
1581 spin_lock_irqsave(&max3421_hcd->lock, flags); in max3421_endpoint_disable()
1583 if (ep->hcpriv) { in max3421_endpoint_disable()
1584 struct max3421_ep *max3421_ep = ep->hcpriv; in max3421_endpoint_disable()
1587 if (!list_empty(&max3421_ep->ep_list)) in max3421_endpoint_disable()
1588 list_del(&max3421_ep->ep_list); in max3421_endpoint_disable()
1590 ep->hcpriv = NULL; in max3421_endpoint_disable()
1593 spin_unlock_irqrestore(&max3421_hcd->lock, flags); in max3421_endpoint_disable()
1600 return max3421_hcd->frame_number; in max3421_get_frame_number()
1604 * Should return a non-zero value when any port is undergoing a resume
1614 spin_lock_irqsave(&max3421_hcd->lock, flags); in max3421_hub_status_data()
1619 if ((max3421_hcd->port_status & PORT_C_MASK) != 0) { in max3421_hub_status_data()
1620 *buf = (1 << 1); /* a hub over-current condition exists */ in max3421_hub_status_data()
1621 dev_dbg(hcd->self.controller, in max3421_hub_status_data()
1623 max3421_hcd->port_status); in max3421_hub_status_data()
1625 if (max3421_hcd->rh_state == MAX3421_RH_SUSPENDED) in max3421_hub_status_data()
1629 spin_unlock_irqrestore(&max3421_hcd->lock, flags); in max3421_hub_status_data()
1638 * See Table 11-13: Hub Descriptor in USB 2.0 spec. in hub_descriptor()
1640 desc->bDescriptorType = USB_DT_HUB; /* hub descriptor */ in hub_descriptor()
1641 desc->bDescLength = 9; in hub_descriptor()
1642 desc->wHubCharacteristics = cpu_to_le16(HUB_CHAR_INDV_PORT_LPSM | in hub_descriptor()
1644 desc->bNbrPorts = 1; in hub_descriptor()
1648 * Set the MAX3421E general-purpose output with number PIN_NUMBER to
1649 * VALUE (0 or 1). PIN_NUMBER may be in the range from 1-8. For
1650 * any other value, this function acts as a no-op.
1658 --pin_number; in max3421_gpout_set_value()
1666 max3421_hcd->iopins[idx] |= mask; in max3421_gpout_set_value()
1668 max3421_hcd->iopins[idx] &= ~mask; in max3421_gpout_set_value()
1669 set_bit(IOPIN_UPDATE, &max3421_hcd->todo); in max3421_gpout_set_value()
1670 wake_up_process(max3421_hcd->spi_thread); in max3421_gpout_set_value()
1677 struct spi_device *spi = to_spi_device(hcd->self.controller); in max3421_hub_control()
1683 pdata = spi->dev.platform_data; in max3421_hub_control()
1685 spin_lock_irqsave(&max3421_hcd->lock, flags); in max3421_hub_control()
1695 dev_dbg(hcd->self.controller, "power-off\n"); in max3421_hub_control()
1696 max3421_gpout_set_value(hcd, pdata->vbus_gpout, in max3421_hub_control()
1697 !pdata->vbus_active_level); in max3421_hub_control()
1700 max3421_hcd->port_status &= ~(1 << value); in max3421_hub_control()
1719 retval = -EPIPE; in max3421_hub_control()
1722 ((__le16 *) buf)[0] = cpu_to_le16(max3421_hcd->port_status); in max3421_hub_control()
1724 cpu_to_le16(max3421_hcd->port_status >> 16); in max3421_hub_control()
1728 retval = -EPIPE; in max3421_hub_control()
1739 if (max3421_hcd->active) in max3421_hub_control()
1740 max3421_hcd->port_status |= in max3421_hub_control()
1744 dev_dbg(hcd->self.controller, "power-on\n"); in max3421_hub_control()
1745 max3421_hcd->port_status |= USB_PORT_STAT_POWER; in max3421_hub_control()
1746 max3421_gpout_set_value(hcd, pdata->vbus_gpout, in max3421_hub_control()
1747 pdata->vbus_active_level); in max3421_hub_control()
1753 if ((max3421_hcd->port_status & USB_PORT_STAT_POWER) in max3421_hub_control()
1755 max3421_hcd->port_status |= (1 << value); in max3421_hub_control()
1760 dev_dbg(hcd->self.controller, in max3421_hub_control()
1764 retval = -EPIPE; in max3421_hub_control()
1767 spin_unlock_irqrestore(&max3421_hcd->lock, flags); in max3421_hub_control()
1774 return -1; in max3421_bus_suspend()
1780 return -1; in max3421_bus_resume()
1808 return -EINVAL; in max3421_of_vbus_en_pin()
1810 retval = of_property_read_u32_array(dev->of_node, "maxim,vbus-en-pin", value, 2); in max3421_of_vbus_en_pin()
1812 dev_err(dev, "device tree node property 'maxim,vbus-en-pin' is missing\n"); in max3421_of_vbus_en_pin()
1815 dev_info(dev, "property 'maxim,vbus-en-pin' value is <%d %d>\n", value[0], value[1]); in max3421_of_vbus_en_pin()
1817 pdata->vbus_gpout = value[0]; in max3421_of_vbus_en_pin()
1818 pdata->vbus_active_level = value[1]; in max3421_of_vbus_en_pin()
1826 struct device *dev = &spi->dev; in max3421_probe()
1833 dev_err(&spi->dev, "Unable to setup SPI bus"); in max3421_probe()
1834 return -EFAULT; in max3421_probe()
1837 if (!spi->irq) { in max3421_probe()
1839 return -EFAULT; in max3421_probe()
1842 if (IS_ENABLED(CONFIG_OF) && dev->of_node) { in max3421_probe()
1843 pdata = devm_kzalloc(&spi->dev, sizeof(*pdata), GFP_KERNEL); in max3421_probe()
1845 retval = -ENOMEM; in max3421_probe()
1852 spi->dev.platform_data = pdata; in max3421_probe()
1855 pdata = spi->dev.platform_data; in max3421_probe()
1857 dev_err(&spi->dev, "driver configuration data is not provided\n"); in max3421_probe()
1858 retval = -EFAULT; in max3421_probe()
1861 if (pdata->vbus_active_level > 1) { in max3421_probe()
1862 …dev_err(&spi->dev, "vbus active level value %d is out of range (0/1)\n", pdata->vbus_active_level); in max3421_probe()
1863 retval = -EINVAL; in max3421_probe()
1866 if (pdata->vbus_gpout < 1 || pdata->vbus_gpout > MAX3421_GPOUT_COUNT) { in max3421_probe()
1867 dev_err(&spi->dev, "vbus gpout value %d is out of range (1..8)\n", pdata->vbus_gpout); in max3421_probe()
1868 retval = -EINVAL; in max3421_probe()
1872 retval = -ENOMEM; in max3421_probe()
1873 hcd = usb_create_hcd(&max3421_hcd_desc, &spi->dev, in max3421_probe()
1874 dev_name(&spi->dev)); in max3421_probe()
1876 dev_err(&spi->dev, "failed to create HCD structure\n"); in max3421_probe()
1879 set_bit(HCD_FLAG_POLL_RH, &hcd->flags); in max3421_probe()
1881 INIT_LIST_HEAD(&max3421_hcd->ep_list); in max3421_probe()
1884 max3421_hcd->tx = kmalloc(sizeof(*max3421_hcd->tx), GFP_KERNEL); in max3421_probe()
1885 if (!max3421_hcd->tx) in max3421_probe()
1887 max3421_hcd->rx = kmalloc(sizeof(*max3421_hcd->rx), GFP_KERNEL); in max3421_probe()
1888 if (!max3421_hcd->rx) in max3421_probe()
1891 max3421_hcd->spi_thread = kthread_run(max3421_spi_thread, hcd, in max3421_probe()
1893 if (max3421_hcd->spi_thread == ERR_PTR(-ENOMEM)) { in max3421_probe()
1894 dev_err(&spi->dev, in max3421_probe()
1901 dev_err(&spi->dev, "failed to add HCD\n"); in max3421_probe()
1905 retval = request_irq(spi->irq, max3421_irq_handler, in max3421_probe()
1908 dev_err(&spi->dev, "failed to request irq %d\n", spi->irq); in max3421_probe()
1914 if (IS_ENABLED(CONFIG_OF) && dev->of_node && pdata) { in max3421_probe()
1915 devm_kfree(&spi->dev, pdata); in max3421_probe()
1916 spi->dev.platform_data = NULL; in max3421_probe()
1920 kfree(max3421_hcd->tx); in max3421_probe()
1921 kfree(max3421_hcd->rx); in max3421_probe()
1922 if (max3421_hcd->spi_thread) in max3421_probe()
1923 kthread_stop(max3421_hcd->spi_thread); in max3421_probe()
1941 spin_lock_irqsave(&max3421_hcd->lock, flags); in max3421_remove()
1943 kthread_stop(max3421_hcd->spi_thread); in max3421_remove()
1945 spin_unlock_irqrestore(&max3421_hcd->lock, flags); in max3421_remove()
1947 free_irq(spi->irq, hcd); in max3421_remove()
1963 .name = "max3421-hcd",