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): */
75 #define POWER_BUDGET 500 /* in mA; use 8 for low-power port testing */
77 /* Port-change mask: */
104 /* Bit numbers for max3421_hcd->todo: */
132 * SPI-thread without acquiring the HCD lock:
138 * cache-lines:
148 int urb_done; /* > 0 -> no errors, < 0: errno */
231 MAX3421_HI_BUSEVENT_BIT = 0, /* bus-reset/-resume */
287 /* Return same error-codes as ohci.h:cc_to_error: */
290 [MAX3421_HRSL_BUSY] = -EINVAL,
291 [MAX3421_HRSL_BADREQ] = -EINVAL,
292 [MAX3421_HRSL_UNDEF] = -EINVAL,
293 [MAX3421_HRSL_NAK] = -EAGAIN,
294 [MAX3421_HRSL_STALL] = -EPIPE,
295 [MAX3421_HRSL_TOGERR] = -EILSEQ,
296 [MAX3421_HRSL_WRONGPID] = -EPROTO,
297 [MAX3421_HRSL_BADBC] = -EREMOTEIO,
298 [MAX3421_HRSL_PIDERR] = -EPROTO,
299 [MAX3421_HRSL_PKTERR] = -EPROTO,
300 [MAX3421_HRSL_CRCERR] = -EILSEQ,
301 [MAX3421_HRSL_KERR] = -EIO,
302 [MAX3421_HRSL_JERR] = -EIO,
303 [MAX3421_HRSL_TIMEOUT] = -ETIME,
304 [MAX3421_HRSL_BABBLE] = -EOVERFLOW
320 #define field(val, bit) ((val) << (bit)) argument
325 return ((unsigned) (left - right)) % (USB_MAX_FRAME_NUMBER + 1); in frame_diff()
331 return (struct max3421_hcd *) hcd->hcd_priv; in hcd_to_max3421()
344 struct spi_device *spi = to_spi_device(hcd->self.controller); in spi_rd8()
352 max3421_hcd->tx->data[0] = in spi_rd8()
356 transfer.tx_buf = max3421_hcd->tx->data; in spi_rd8()
357 transfer.rx_buf = max3421_hcd->rx->data; in spi_rd8()
363 return max3421_hcd->rx->data[1]; in spi_rd8()
369 struct spi_device *spi = to_spi_device(hcd->self.controller); in spi_wr8()
378 max3421_hcd->tx->data[0] = in spi_wr8()
381 max3421_hcd->tx->data[1] = val; in spi_wr8()
383 transfer.tx_buf = max3421_hcd->tx->data; in spi_wr8()
393 struct spi_device *spi = to_spi_device(hcd->self.controller); in spi_rd_buf()
402 max3421_hcd->tx->data[0] = in spi_rd_buf()
405 transfer[0].tx_buf = max3421_hcd->tx->data; in spi_rd_buf()
419 struct spi_device *spi = to_spi_device(hcd->self.controller); in spi_wr_buf()
428 max3421_hcd->tx->data[0] = in spi_wr_buf()
432 transfer[0].tx_buf = max3421_hcd->tx->data; in spi_wr_buf()
445 * bits. The HUBPRE bit needs to be set when MAX3421E operates at
446 * full speed, but it's talking to a low-speed device (i.e., through a
447 * hub). Setting that bit ensures that every low-speed packet is
448 * preceded by a full-speed PRE PID. Possible configurations:
450 * Hub speed: Device speed: => LOWSPEED bit: HUBPRE bit:
451 * FULL FULL => 0 0
452 * FULL LOW => 1 1
454 * LOW FULL => 1 0
460 u8 mode_lowspeed, mode_hubpre, mode = max3421_hcd->mode; in max3421_set_speed()
462 mode_lowspeed = BIT(MAX3421_MODE_LOWSPEED_BIT); in max3421_set_speed()
463 mode_hubpre = BIT(MAX3421_MODE_HUBPRE_BIT); in max3421_set_speed()
464 if (max3421_hcd->port_status & USB_PORT_STAT_LOW_SPEED) { in max3421_set_speed()
467 } else if (dev->speed == USB_SPEED_LOW) { in max3421_set_speed()
472 if (mode != max3421_hcd->mode) { in max3421_set_speed()
473 max3421_hcd->mode = mode; in max3421_set_speed()
474 spi_wr8(hcd, MAX3421_REG_MODE, max3421_hcd->mode); in max3421_set_speed()
491 hctl = (BIT(rcvtog + MAX3421_HCTL_RCVTOG0_BIT) | in max3421_set_address()
492 BIT(sndtog + MAX3421_HCTL_SNDTOG0_BIT)); in max3421_set_address()
498 * address-assignment so it's best to just always load the in max3421_set_address()
499 * address whenever the end-point changed/was forced. in max3421_set_address()
501 spi_wr8(hcd, MAX3421_REG_PERADDR, dev->devnum); in max3421_set_address()
507 spi_wr_buf(hcd, MAX3421_REG_SUDFIFO, urb->setup_packet, 8); in max3421_ctrl_setup()
515 int epnum = usb_pipeendpoint(urb->pipe); in max3421_transfer_in()
517 max3421_hcd->curr_len = 0; in max3421_transfer_in()
518 max3421_hcd->hien |= BIT(MAX3421_HI_RCVDAV_BIT); in max3421_transfer_in()
525 struct spi_device *spi = to_spi_device(hcd->self.controller); in max3421_transfer_out()
527 int epnum = usb_pipeendpoint(urb->pipe); in max3421_transfer_out()
531 src = urb->transfer_buffer + urb->actual_length; in max3421_transfer_out()
534 if (max3421_hcd->rev == 0x12) { in max3421_transfer_out()
538 spi_wr8(hcd, MAX3421_REG_SNDBC, max3421_hcd->curr_len); in max3421_transfer_out()
543 max_packet = usb_maxpacket(urb->dev, urb->pipe); in max3421_transfer_out()
550 dev_err(&spi->dev, in max3421_transfer_out()
551 "%s: packet-size of %u too big (limit is %u bytes)", in max3421_transfer_out()
553 max3421_hcd->urb_done = -EMSGSIZE; in max3421_transfer_out()
554 return -EMSGSIZE; in max3421_transfer_out()
556 max3421_hcd->curr_len = min((urb->transfer_buffer_length - in max3421_transfer_out()
557 urb->actual_length), max_packet); in max3421_transfer_out()
559 spi_wr_buf(hcd, MAX3421_REG_SNDFIFO, src, max3421_hcd->curr_len); in max3421_transfer_out()
560 spi_wr8(hcd, MAX3421_REG_SNDBC, max3421_hcd->curr_len); in max3421_transfer_out()
565 * Issue the next host-transfer command.
572 struct urb *urb = max3421_hcd->curr_urb; in max3421_next_transfer()
574 int cmd = -EINVAL; in max3421_next_transfer()
579 max3421_ep = urb->ep->hcpriv; in max3421_next_transfer()
581 switch (max3421_ep->pkt_state) { in max3421_next_transfer()
608 /* issue the command and wait for host-xfer-done interrupt: */ in max3421_next_transfer()
611 max3421_hcd->hien |= BIT(MAX3421_HI_HXFRDN_BIT); in max3421_next_transfer()
621 * frame to process non-periodic (bulk & control) transfers.
625 * o max3421_hcd->curr_urb MUST BE NULL.
631 struct spi_device *spi = to_spi_device(hcd->self.controller); in max3421_select_and_start_urb()
640 spin_lock_irqsave(&max3421_hcd->lock, flags); in max3421_select_and_start_urb()
643 max3421_hcd->sched_pass < SCHED_PASS_DONE; in max3421_select_and_start_urb()
644 ++max3421_hcd->sched_pass) in max3421_select_and_start_urb()
645 list_for_each(pos, &max3421_hcd->ep_list) { in max3421_select_and_start_urb()
649 ep = max3421_ep->ep; in max3421_select_and_start_urb()
651 switch (usb_endpoint_type(&ep->desc)) { in max3421_select_and_start_urb()
654 if (max3421_hcd->sched_pass != in max3421_select_and_start_urb()
661 if (max3421_hcd->sched_pass != in max3421_select_and_start_urb()
667 if (list_empty(&ep->urb_list)) in max3421_select_and_start_urb()
669 urb = list_first_entry(&ep->urb_list, struct urb, in max3421_select_and_start_urb()
671 if (urb->unlinked) { in max3421_select_and_start_urb()
672 dev_dbg(&spi->dev, "%s: URB %p unlinked=%d", in max3421_select_and_start_urb()
673 __func__, urb, urb->unlinked); in max3421_select_and_start_urb()
674 max3421_hcd->curr_urb = urb; in max3421_select_and_start_urb()
675 max3421_hcd->urb_done = 1; in max3421_select_and_start_urb()
676 spin_unlock_irqrestore(&max3421_hcd->lock, in max3421_select_and_start_urb()
681 switch (usb_endpoint_type(&ep->desc)) { in max3421_select_and_start_urb()
687 if (frame_diff(max3421_ep->last_active, in max3421_select_and_start_urb()
688 max3421_hcd->frame_number) == 0) in max3421_select_and_start_urb()
693 if (max3421_ep->retransmit in max3421_select_and_start_urb()
694 && (frame_diff(max3421_ep->last_active, in max3421_select_and_start_urb()
695 max3421_hcd->frame_number) in max3421_select_and_start_urb()
707 if (frame_diff(max3421_hcd->frame_number, in max3421_select_and_start_urb()
708 max3421_ep->last_active) in max3421_select_and_start_urb()
709 < urb->interval) in max3421_select_and_start_urb()
712 * end-point in the current in max3421_select_and_start_urb()
720 list_move_tail(pos, &max3421_hcd->ep_list); in max3421_select_and_start_urb()
726 spin_unlock_irqrestore(&max3421_hcd->lock, flags); in max3421_select_and_start_urb()
730 urb = max3421_hcd->curr_urb = curr_urb; in max3421_select_and_start_urb()
731 epnum = usb_endpoint_num(&urb->ep->desc); in max3421_select_and_start_urb()
732 if (max3421_ep->retransmit) in max3421_select_and_start_urb()
734 max3421_ep->retransmit = 0; in max3421_select_and_start_urb()
737 if (usb_endpoint_xfer_control(&ep->desc)) { in max3421_select_and_start_urb()
742 usb_settoggle(urb->dev, epnum, 0, 1); in max3421_select_and_start_urb()
743 usb_settoggle(urb->dev, epnum, 1, 1); in max3421_select_and_start_urb()
744 max3421_ep->pkt_state = PKT_STATE_SETUP; in max3421_select_and_start_urb()
746 max3421_ep->pkt_state = PKT_STATE_TRANSFER; in max3421_select_and_start_urb()
749 spin_unlock_irqrestore(&max3421_hcd->lock, flags); in max3421_select_and_start_urb()
751 max3421_ep->last_active = max3421_hcd->frame_number; in max3421_select_and_start_urb()
752 max3421_set_address(hcd, urb->dev, epnum); in max3421_select_and_start_urb()
753 max3421_set_speed(hcd, urb->dev); in max3421_select_and_start_urb()
766 struct spi_device *spi = to_spi_device(hcd->self.controller); in max3421_check_unlink()
774 spin_lock_irqsave(&max3421_hcd->lock, flags); in max3421_check_unlink()
775 list_for_each_entry(max3421_ep, &max3421_hcd->ep_list, ep_list) { in max3421_check_unlink()
776 ep = max3421_ep->ep; in max3421_check_unlink()
777 list_for_each_entry_safe(urb, next, &ep->urb_list, urb_list) { in max3421_check_unlink()
778 if (urb->unlinked) { in max3421_check_unlink()
780 dev_dbg(&spi->dev, "%s: URB %p unlinked=%d", in max3421_check_unlink()
781 __func__, urb, urb->unlinked); in max3421_check_unlink()
782 if (urb == max3421_hcd->curr_urb) { in max3421_check_unlink()
783 max3421_hcd->urb_done = 1; in max3421_check_unlink()
784 max3421_hcd->hien &= ~(BIT(MAX3421_HI_HXFRDN_BIT) | in max3421_check_unlink()
785 BIT(MAX3421_HI_RCVDAV_BIT)); in max3421_check_unlink()
788 spin_unlock_irqrestore(&max3421_hcd->lock, in max3421_check_unlink()
791 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()
941 struct spi_device *spi = to_spi_device(hcd->self.controller); in max3421_transfer_in_done()
945 if (urb->actual_length >= urb->transfer_buffer_length) in max3421_transfer_in_done()
949 * USB 2.0 Section 5.3.2 Pipes: packets must be full size in max3421_transfer_in_done()
952 max_packet = usb_maxpacket(urb->dev, urb->pipe); in max3421_transfer_in_done()
958 dev_err(&spi->dev, in max3421_transfer_in_done()
959 "%s: packet-size of %u too big (limit is %u bytes)", in max3421_transfer_in_done()
961 return -EINVAL; in max3421_transfer_in_done()
964 if (max3421_hcd->curr_len < max_packet) { in max3421_transfer_in_done()
965 if (urb->transfer_flags & URB_SHORT_NOT_OK) { in max3421_transfer_in_done()
968 * unexpected partial packet -> in max3421_transfer_in_done()
971 return -EREMOTEIO; in max3421_transfer_in_done()
987 urb->actual_length += max3421_hcd->curr_len; in max3421_transfer_out_done()
988 if (urb->actual_length < urb->transfer_buffer_length) in max3421_transfer_out_done()
990 if (urb->transfer_flags & URB_ZERO_PACKET) { in max3421_transfer_out_done()
992 * Some hardware needs a zero-size packet at the end in max3421_transfer_out_done()
993 * of a bulk-out transfer if the last transfer was a in max3421_transfer_out_done()
994 * full-sized packet (i.e., such hardware use < in max3421_transfer_out_done()
998 u32 max_packet = usb_maxpacket(urb->dev, urb->pipe); in max3421_transfer_out_done()
1000 if (max3421_hcd->curr_len == max_packet) in max3421_transfer_out_done()
1013 struct urb *urb = max3421_hcd->curr_urb; in max3421_host_transfer_done()
1018 max3421_hcd->hien &= ~(BIT(MAX3421_HI_HXFRDN_BIT) | in max3421_host_transfer_done()
1019 BIT(MAX3421_HI_RCVDAV_BIT)); in max3421_host_transfer_done()
1025 ++max3421_hcd->err_stat[result_code]; in max3421_host_transfer_done()
1028 max3421_ep = urb->ep->hcpriv; in max3421_host_transfer_done()
1035 max3421_ep->naks = 0; in max3421_host_transfer_done()
1036 max3421_ep->retries = 0; in max3421_host_transfer_done()
1037 switch (max3421_ep->pkt_state) { in max3421_host_transfer_done()
1040 if (urb->transfer_buffer_length > 0) in max3421_host_transfer_done()
1041 max3421_ep->pkt_state = PKT_STATE_TRANSFER; in max3421_host_transfer_done()
1043 max3421_ep->pkt_state = PKT_STATE_TERMINATE; in max3421_host_transfer_done()
1051 if (urb_done > 0 && usb_pipetype(urb->pipe) == PIPE_CONTROL) { in max3421_host_transfer_done()
1053 * We aren't really done - we still need to in max3421_host_transfer_done()
1056 max3421_hcd->urb_done = urb_done = 0; in max3421_host_transfer_done()
1057 max3421_ep->pkt_state = PKT_STATE_TERMINATE; in max3421_host_transfer_done()
1067 max3421_hcd->urb_done = urb_done; in max3421_host_transfer_done()
1089 mode = max3421_hcd->mode; in max3421_detect_conn()
1094 * Turn off SOFKAENAB bit to avoid getting interrupt in max3421_detect_conn()
1095 * every milli-second: in max3421_detect_conn()
1097 mode &= ~BIT(MAX3421_MODE_SOFKAENAB_BIT); in max3421_detect_conn()
1100 case 0x1: /* J=0,K=1: low-speed (in full-speed or vice versa) */ in max3421_detect_conn()
1101 case 0x2: /* J=1,K=0: full-speed (in full-speed or vice versa) */ in max3421_detect_conn()
1104 mode ^= BIT(MAX3421_MODE_LOWSPEED_BIT); in max3421_detect_conn()
1105 /* turn on SOFKAENAB bit: */ in max3421_detect_conn()
1106 mode |= BIT(MAX3421_MODE_SOFKAENAB_BIT); in max3421_detect_conn()
1114 max3421_hcd->mode = mode; in max3421_detect_conn()
1115 spi_wr8(hcd, MAX3421_REG_MODE, max3421_hcd->mode); in max3421_detect_conn()
1117 spin_lock_irqsave(&max3421_hcd->lock, flags); in max3421_detect_conn()
1118 old_port_status = max3421_hcd->port_status; in max3421_detect_conn()
1120 max3421_hcd->port_status |= USB_PORT_STAT_CONNECTION; in max3421_detect_conn()
1122 max3421_hcd->port_status &= ~USB_PORT_STAT_CONNECTION; in max3421_detect_conn()
1123 if (mode & BIT(MAX3421_MODE_LOWSPEED_BIT)) in max3421_detect_conn()
1124 max3421_hcd->port_status |= USB_PORT_STAT_LOW_SPEED; in max3421_detect_conn()
1126 max3421_hcd->port_status &= ~USB_PORT_STAT_LOW_SPEED; in max3421_detect_conn()
1127 chg = (old_port_status ^ max3421_hcd->port_status); in max3421_detect_conn()
1128 max3421_hcd->port_status |= chg << 16; in max3421_detect_conn()
1129 spin_unlock_irqrestore(&max3421_hcd->lock, flags); in max3421_detect_conn()
1136 struct spi_device *spi = to_spi_device(hcd->self.controller); in max3421_irq_handler()
1139 if (max3421_hcd->spi_thread) in max3421_irq_handler()
1140 wake_up_process(max3421_hcd->spi_thread); in max3421_irq_handler()
1141 if (!test_and_set_bit(ENABLE_IRQ, &max3421_hcd->todo)) in max3421_irq_handler()
1142 disable_irq_nosync(spi->irq); in max3421_irq_handler()
1159 spin_lock_irqsave(&max3421_hcd->lock, flags); in dump_eps()
1160 list_for_each_entry(max3421_ep, &max3421_hcd->ep_list, ep_list) { in dump_eps()
1161 ep = max3421_ep->ep; in dump_eps()
1166 list_for_each_entry(urb, &ep->urb_list, urb_list) { in dump_eps()
1167 ret = scnprintf(dp, end - dp, " %p(%d.%s %d/%d)", urb, in dump_eps()
1168 usb_pipetype(urb->pipe), in dump_eps()
1170 urb->actual_length, in dump_eps()
1171 urb->transfer_buffer_length); in dump_eps()
1172 if (ret == end - dp - 1) in dump_eps()
1173 break; /* error or buffer full */ in dump_eps()
1177 epnum = usb_endpoint_num(&ep->desc); in dump_eps()
1179 epnum, max3421_ep->pkt_state, max3421_ep->last_active, in dump_eps()
1180 max3421_ep->retries, max3421_ep->naks, in dump_eps()
1181 max3421_ep->retransmit, ubuf); in dump_eps()
1183 spin_unlock_irqrestore(&max3421_hcd->lock, flags); in dump_eps()
1203 hirq &= max3421_hcd->hien; in max3421_handle_irqs()
1208 hirq & ~(BIT(MAX3421_HI_SNDBAV_BIT) | in max3421_handle_irqs()
1209 BIT(MAX3421_HI_RCVDAV_BIT))); in max3421_handle_irqs()
1211 if (hirq & BIT(MAX3421_HI_FRAME_BIT)) { in max3421_handle_irqs()
1212 max3421_hcd->frame_number = ((max3421_hcd->frame_number + 1) in max3421_handle_irqs()
1214 max3421_hcd->sched_pass = SCHED_PASS_PERIODIC; in max3421_handle_irqs()
1217 if (hirq & BIT(MAX3421_HI_RCVDAV_BIT)) in max3421_handle_irqs()
1220 if (hirq & BIT(MAX3421_HI_HXFRDN_BIT)) in max3421_handle_irqs()
1223 if (hirq & BIT(MAX3421_HI_CONDET_BIT)) in max3421_handle_irqs()
1228 * other than the end-points: in max3421_handle_irqs()
1230 spin_lock_irqsave(&max3421_hcd->lock, flags); in max3421_handle_irqs()
1232 old_port_status = max3421_hcd->port_status; in max3421_handle_irqs()
1233 if (hirq & BIT(MAX3421_HI_BUSEVENT_BIT)) { in max3421_handle_irqs()
1234 if (max3421_hcd->port_status & USB_PORT_STAT_RESET) { in max3421_handle_irqs()
1236 max3421_hcd->port_status &= ~USB_PORT_STAT_RESET; in max3421_handle_irqs()
1237 max3421_hcd->port_status |= USB_PORT_STAT_ENABLE; in max3421_handle_irqs()
1243 if (hirq & BIT(MAX3421_HI_RWU_BIT)) in max3421_handle_irqs()
1245 if (hirq & BIT(MAX3421_HI_SUSDN_BIT)) in max3421_handle_irqs()
1248 chg = (old_port_status ^ max3421_hcd->port_status); in max3421_handle_irqs()
1249 max3421_hcd->port_status |= chg << 16; in max3421_handle_irqs()
1251 spin_unlock_irqrestore(&max3421_hcd->lock, flags); in max3421_handle_irqs()
1264 int ret = scnprintf(dp, end - dp, " %lu", in max3421_handle_irqs()
1265 max3421_hcd->err_stat[i]); in max3421_handle_irqs()
1266 if (ret == end - dp - 1) in max3421_handle_irqs()
1267 break; /* error or buffer full */ in max3421_handle_irqs()
1271 memset(max3421_hcd->err_stat, 0, in max3421_handle_irqs()
1272 sizeof(max3421_hcd->err_stat)); in max3421_handle_irqs()
1285 struct spi_device *spi = to_spi_device(hcd->self.controller); in max3421_reset_hcd()
1290 spi_wr8(hcd, MAX3421_REG_USBCTL, BIT(MAX3421_USBCTL_CHIPRES_BIT)); in max3421_reset_hcd()
1296 & BIT(MAX3421_USBIRQ_OSCOKIRQ_BIT)) in max3421_reset_hcd()
1298 if (--timeout < 0) { in max3421_reset_hcd()
1299 dev_err(&spi->dev, in max3421_reset_hcd()
1308 * enable pull-down registers on DM/DP: in max3421_reset_hcd()
1310 max3421_hcd->mode = (BIT(MAX3421_MODE_HOST_BIT) | in max3421_reset_hcd()
1311 BIT(MAX3421_MODE_SOFKAENAB_BIT) | in max3421_reset_hcd()
1312 BIT(MAX3421_MODE_DMPULLDN_BIT) | in max3421_reset_hcd()
1313 BIT(MAX3421_MODE_DPPULLDN_BIT)); in max3421_reset_hcd()
1314 spi_wr8(hcd, MAX3421_REG_MODE, max3421_hcd->mode); in max3421_reset_hcd()
1316 /* reset frame-number: */ in max3421_reset_hcd()
1317 max3421_hcd->frame_number = USB_MAX_FRAME_NUMBER; in max3421_reset_hcd()
1318 spi_wr8(hcd, MAX3421_REG_HCTL, BIT(MAX3421_HCTL_FRMRST_BIT)); in max3421_reset_hcd()
1320 /* sample the state of the D+ and D- lines */ in max3421_reset_hcd()
1321 spi_wr8(hcd, MAX3421_REG_HCTL, BIT(MAX3421_HCTL_SAMPLEBUS_BIT)); in max3421_reset_hcd()
1324 /* enable frame, connection-detected, and bus-event interrupts: */ in max3421_reset_hcd()
1325 max3421_hcd->hien = (BIT(MAX3421_HI_FRAME_BIT) | in max3421_reset_hcd()
1326 BIT(MAX3421_HI_CONDET_BIT) | in max3421_reset_hcd()
1327 BIT(MAX3421_HI_BUSEVENT_BIT)); in max3421_reset_hcd()
1328 spi_wr8(hcd, MAX3421_REG_HIEN, max3421_hcd->hien); in max3421_reset_hcd()
1331 spi_wr8(hcd, MAX3421_REG_CPUCTL, BIT(MAX3421_CPUCTL_IE_BIT)); in max3421_reset_hcd()
1343 status = max3421_hcd->urb_done; in max3421_urb_done()
1344 max3421_hcd->urb_done = 0; in max3421_urb_done()
1347 urb = max3421_hcd->curr_urb; in max3421_urb_done()
1349 /* save the old end-points toggles: */ in max3421_urb_done()
1353 int epnum = usb_endpoint_num(&urb->ep->desc); in max3421_urb_done()
1356 usb_settoggle(urb->dev, epnum, 0, rcvtog); in max3421_urb_done()
1357 usb_settoggle(urb->dev, epnum, 1, sndtog); in max3421_urb_done()
1359 max3421_hcd->curr_urb = NULL; in max3421_urb_done()
1360 spin_lock_irqsave(&max3421_hcd->lock, flags); in max3421_urb_done()
1362 spin_unlock_irqrestore(&max3421_hcd->lock, flags); in max3421_urb_done()
1374 struct spi_device *spi = to_spi_device(hcd->self.controller); in max3421_spi_thread()
1378 /* set full-duplex SPI mode, low-active interrupt pin: */ in max3421_spi_thread()
1380 (BIT(MAX3421_PINCTL_FDUPSPI_BIT) | /* full-duplex */ in max3421_spi_thread()
1381 BIT(MAX3421_PINCTL_INTLEVEL_BIT))); /* low-active irq */ in max3421_spi_thread()
1384 max3421_hcd->rev = spi_rd8(hcd, MAX3421_REG_REVISION); in max3421_spi_thread()
1385 if (max3421_hcd->rev == 0x12 || max3421_hcd->rev == 0x13) in max3421_spi_thread()
1387 dev_err(&spi->dev, "bad rev 0x%02x", max3421_hcd->rev); in max3421_spi_thread()
1390 dev_info(&spi->dev, "rev 0x%x, SPI clk %dHz, bpw %u, irq %d\n", in max3421_spi_thread()
1391 max3421_hcd->rev, spi->max_speed_hz, spi->bits_per_word, in max3421_spi_thread()
1392 spi->irq); in max3421_spi_thread()
1401 spi_wr8(hcd, MAX3421_REG_HIEN, max3421_hcd->hien); in max3421_spi_thread()
1404 if (test_and_clear_bit(ENABLE_IRQ, &max3421_hcd->todo)) in max3421_spi_thread()
1405 enable_irq(spi->irq); in max3421_spi_thread()
1412 if (max3421_hcd->urb_done) in max3421_spi_thread()
1416 else if (!max3421_hcd->curr_urb) in max3421_spi_thread()
1419 if (test_and_clear_bit(RESET_HCD, &max3421_hcd->todo)) in max3421_spi_thread()
1422 if (test_and_clear_bit(RESET_PORT, &max3421_hcd->todo)) { in max3421_spi_thread()
1425 BIT(MAX3421_HCTL_BUSRST_BIT)); in max3421_spi_thread()
1428 if (test_and_clear_bit(CHECK_UNLINK, &max3421_hcd->todo)) in max3421_spi_thread()
1430 if (test_and_clear_bit(IOPIN_UPDATE, &max3421_hcd->todo)) { in max3421_spi_thread()
1432 * IOPINS1/IOPINS2 do not auto-increment, so we can't in max3421_spi_thread()
1435 for (i = 0; i < ARRAY_SIZE(max3421_hcd->iopins); ++i) { in max3421_spi_thread()
1439 (max3421_hcd->iopins[i] & 0x0f)); in max3421_spi_thread()
1441 max3421_hcd->iopins[i] = val; in max3421_spi_thread()
1447 dev_info(&spi->dev, "SPI thread exiting"); in max3421_spi_thread()
1456 max3421_hcd->port_status &= ~(USB_PORT_STAT_ENABLE | in max3421_reset_port()
1458 max3421_hcd->port_status |= USB_PORT_STAT_RESET; in max3421_reset_port()
1459 set_bit(RESET_PORT, &max3421_hcd->todo); in max3421_reset_port()
1460 wake_up_process(max3421_hcd->spi_thread); in max3421_reset_port()
1469 hcd->self.sg_tablesize = 0; in max3421_reset()
1470 hcd->speed = HCD_USB2; in max3421_reset()
1471 hcd->self.root_hub->speed = USB_SPEED_FULL; in max3421_reset()
1472 set_bit(RESET_HCD, &max3421_hcd->todo); in max3421_reset()
1473 wake_up_process(max3421_hcd->spi_thread); in max3421_reset()
1482 spin_lock_init(&max3421_hcd->lock); in max3421_start()
1483 max3421_hcd->rh_state = MAX3421_RH_RUNNING; in max3421_start()
1485 INIT_LIST_HEAD(&max3421_hcd->ep_list); in max3421_start()
1487 hcd->power_budget = POWER_BUDGET; in max3421_start()
1488 hcd->state = HC_STATE_RUNNING; in max3421_start()
1489 hcd->uses_new_polling = 1; in max3421_start()
1501 struct spi_device *spi = to_spi_device(hcd->self.controller); in max3421_urb_enqueue()
1507 switch (usb_pipetype(urb->pipe)) { in max3421_urb_enqueue()
1510 if (urb->interval < 0) { in max3421_urb_enqueue()
1511 dev_err(&spi->dev, in max3421_urb_enqueue()
1512 "%s: interval=%d for intr-/iso-pipe; expected > 0\n", in max3421_urb_enqueue()
1513 __func__, urb->interval); in max3421_urb_enqueue()
1514 return -EINVAL; in max3421_urb_enqueue()
1521 spin_lock_irqsave(&max3421_hcd->lock, flags); in max3421_urb_enqueue()
1523 max3421_ep = urb->ep->hcpriv; in max3421_urb_enqueue()
1528 retval = -ENOMEM; in max3421_urb_enqueue()
1531 max3421_ep->ep = urb->ep; in max3421_urb_enqueue()
1532 max3421_ep->last_active = max3421_hcd->frame_number; in max3421_urb_enqueue()
1533 urb->ep->hcpriv = max3421_ep; in max3421_urb_enqueue()
1535 list_add_tail(&max3421_ep->ep_list, &max3421_hcd->ep_list); in max3421_urb_enqueue()
1541 max3421_hcd->sched_pass = SCHED_PASS_PERIODIC; in max3421_urb_enqueue()
1542 wake_up_process(max3421_hcd->spi_thread); in max3421_urb_enqueue()
1546 spin_unlock_irqrestore(&max3421_hcd->lock, flags); in max3421_urb_enqueue()
1557 spin_lock_irqsave(&max3421_hcd->lock, flags); in max3421_urb_dequeue()
1560 * This will set urb->unlinked which in turn causes the entry in max3421_urb_dequeue()
1565 set_bit(CHECK_UNLINK, &max3421_hcd->todo); in max3421_urb_dequeue()
1566 wake_up_process(max3421_hcd->spi_thread); in max3421_urb_dequeue()
1568 spin_unlock_irqrestore(&max3421_hcd->lock, flags); in max3421_urb_dequeue()
1578 spin_lock_irqsave(&max3421_hcd->lock, flags); in max3421_endpoint_disable()
1580 if (ep->hcpriv) { in max3421_endpoint_disable()
1581 struct max3421_ep *max3421_ep = ep->hcpriv; in max3421_endpoint_disable()
1584 if (!list_empty(&max3421_ep->ep_list)) in max3421_endpoint_disable()
1585 list_del(&max3421_ep->ep_list); in max3421_endpoint_disable()
1587 ep->hcpriv = NULL; in max3421_endpoint_disable()
1590 spin_unlock_irqrestore(&max3421_hcd->lock, flags); in max3421_endpoint_disable()
1597 return max3421_hcd->frame_number; in max3421_get_frame_number()
1601 * Should return a non-zero value when any port is undergoing a resume
1611 spin_lock_irqsave(&max3421_hcd->lock, flags); in max3421_hub_status_data()
1616 if ((max3421_hcd->port_status & PORT_C_MASK) != 0) { in max3421_hub_status_data()
1617 *buf = (1 << 1); /* a hub over-current condition exists */ in max3421_hub_status_data()
1618 dev_dbg(hcd->self.controller, in max3421_hub_status_data()
1620 max3421_hcd->port_status); in max3421_hub_status_data()
1622 if (max3421_hcd->rh_state == MAX3421_RH_SUSPENDED) in max3421_hub_status_data()
1626 spin_unlock_irqrestore(&max3421_hcd->lock, flags); in max3421_hub_status_data()
1635 * See Table 11-13: Hub Descriptor in USB 2.0 spec. in hub_descriptor()
1637 desc->bDescriptorType = USB_DT_HUB; /* hub descriptor */ in hub_descriptor()
1638 desc->bDescLength = 9; in hub_descriptor()
1639 desc->wHubCharacteristics = cpu_to_le16(HUB_CHAR_INDV_PORT_LPSM | in hub_descriptor()
1641 desc->bNbrPorts = 1; in hub_descriptor()
1645 * Set the MAX3421E general-purpose output with number PIN_NUMBER to
1646 * VALUE (0 or 1). PIN_NUMBER may be in the range from 1-8. For
1647 * any other value, this function acts as a no-op.
1655 --pin_number; in max3421_gpout_set_value()
1663 max3421_hcd->iopins[idx] |= mask; in max3421_gpout_set_value()
1665 max3421_hcd->iopins[idx] &= ~mask; in max3421_gpout_set_value()
1666 set_bit(IOPIN_UPDATE, &max3421_hcd->todo); in max3421_gpout_set_value()
1667 wake_up_process(max3421_hcd->spi_thread); in max3421_gpout_set_value()
1674 struct spi_device *spi = to_spi_device(hcd->self.controller); in max3421_hub_control()
1680 pdata = spi->dev.platform_data; in max3421_hub_control()
1682 spin_lock_irqsave(&max3421_hcd->lock, flags); in max3421_hub_control()
1692 dev_dbg(hcd->self.controller, "power-off\n"); in max3421_hub_control()
1693 max3421_gpout_set_value(hcd, pdata->vbus_gpout, in max3421_hub_control()
1694 !pdata->vbus_active_level); in max3421_hub_control()
1697 max3421_hcd->port_status &= ~(1 << value); in max3421_hub_control()
1716 retval = -EPIPE; in max3421_hub_control()
1719 ((__le16 *) buf)[0] = cpu_to_le16(max3421_hcd->port_status); in max3421_hub_control()
1721 cpu_to_le16(max3421_hcd->port_status >> 16); in max3421_hub_control()
1725 retval = -EPIPE; in max3421_hub_control()
1736 if (max3421_hcd->active) in max3421_hub_control()
1737 max3421_hcd->port_status |= in max3421_hub_control()
1741 dev_dbg(hcd->self.controller, "power-on\n"); in max3421_hub_control()
1742 max3421_hcd->port_status |= USB_PORT_STAT_POWER; in max3421_hub_control()
1743 max3421_gpout_set_value(hcd, pdata->vbus_gpout, in max3421_hub_control()
1744 pdata->vbus_active_level); in max3421_hub_control()
1750 if ((max3421_hcd->port_status & USB_PORT_STAT_POWER) in max3421_hub_control()
1752 max3421_hcd->port_status |= (1 << value); in max3421_hub_control()
1757 dev_dbg(hcd->self.controller, in max3421_hub_control()
1761 retval = -EPIPE; in max3421_hub_control()
1764 spin_unlock_irqrestore(&max3421_hcd->lock, flags); in max3421_hub_control()
1771 return -1; in max3421_bus_suspend()
1777 return -1; in max3421_bus_resume()
1805 return -EINVAL; in max3421_of_vbus_en_pin()
1807 retval = of_property_read_u32_array(dev->of_node, "maxim,vbus-en-pin", value, 2); in max3421_of_vbus_en_pin()
1809 dev_err(dev, "device tree node property 'maxim,vbus-en-pin' is missing\n"); in max3421_of_vbus_en_pin()
1812 dev_info(dev, "property 'maxim,vbus-en-pin' value is <%d %d>\n", value[0], value[1]); in max3421_of_vbus_en_pin()
1814 pdata->vbus_gpout = value[0]; in max3421_of_vbus_en_pin()
1815 pdata->vbus_active_level = value[1]; in max3421_of_vbus_en_pin()
1823 struct device *dev = &spi->dev; in max3421_probe()
1830 dev_err(&spi->dev, "Unable to setup SPI bus"); in max3421_probe()
1831 return -EFAULT; in max3421_probe()
1834 if (!spi->irq) { in max3421_probe()
1836 return -EFAULT; in max3421_probe()
1839 if (IS_ENABLED(CONFIG_OF) && dev->of_node) { in max3421_probe()
1840 pdata = devm_kzalloc(&spi->dev, sizeof(*pdata), GFP_KERNEL); in max3421_probe()
1842 retval = -ENOMEM; in max3421_probe()
1849 spi->dev.platform_data = pdata; in max3421_probe()
1852 pdata = spi->dev.platform_data; in max3421_probe()
1854 dev_err(&spi->dev, "driver configuration data is not provided\n"); in max3421_probe()
1855 retval = -EFAULT; in max3421_probe()
1858 if (pdata->vbus_active_level > 1) { in max3421_probe()
1859 …dev_err(&spi->dev, "vbus active level value %d is out of range (0/1)\n", pdata->vbus_active_level); in max3421_probe()
1860 retval = -EINVAL; in max3421_probe()
1863 if (pdata->vbus_gpout < 1 || pdata->vbus_gpout > MAX3421_GPOUT_COUNT) { in max3421_probe()
1864 dev_err(&spi->dev, "vbus gpout value %d is out of range (1..8)\n", pdata->vbus_gpout); in max3421_probe()
1865 retval = -EINVAL; in max3421_probe()
1869 retval = -ENOMEM; in max3421_probe()
1870 hcd = usb_create_hcd(&max3421_hcd_desc, &spi->dev, in max3421_probe()
1871 dev_name(&spi->dev)); in max3421_probe()
1873 dev_err(&spi->dev, "failed to create HCD structure\n"); in max3421_probe()
1876 set_bit(HCD_FLAG_POLL_RH, &hcd->flags); in max3421_probe()
1878 INIT_LIST_HEAD(&max3421_hcd->ep_list); in max3421_probe()
1881 max3421_hcd->tx = kmalloc(sizeof(*max3421_hcd->tx), GFP_KERNEL); in max3421_probe()
1882 if (!max3421_hcd->tx) in max3421_probe()
1884 max3421_hcd->rx = kmalloc(sizeof(*max3421_hcd->rx), GFP_KERNEL); in max3421_probe()
1885 if (!max3421_hcd->rx) in max3421_probe()
1888 max3421_hcd->spi_thread = kthread_run(max3421_spi_thread, hcd, in max3421_probe()
1890 if (max3421_hcd->spi_thread == ERR_PTR(-ENOMEM)) { in max3421_probe()
1891 dev_err(&spi->dev, in max3421_probe()
1898 dev_err(&spi->dev, "failed to add HCD\n"); in max3421_probe()
1902 retval = request_irq(spi->irq, max3421_irq_handler, in max3421_probe()
1905 dev_err(&spi->dev, "failed to request irq %d\n", spi->irq); in max3421_probe()
1911 if (IS_ENABLED(CONFIG_OF) && dev->of_node && pdata) { in max3421_probe()
1912 devm_kfree(&spi->dev, pdata); in max3421_probe()
1913 spi->dev.platform_data = NULL; in max3421_probe()
1917 kfree(max3421_hcd->tx); in max3421_probe()
1918 kfree(max3421_hcd->rx); in max3421_probe()
1919 if (max3421_hcd->spi_thread) in max3421_probe()
1920 kthread_stop(max3421_hcd->spi_thread); in max3421_probe()
1938 spin_lock_irqsave(&max3421_hcd->lock, flags); in max3421_remove()
1940 kthread_stop(max3421_hcd->spi_thread); in max3421_remove()
1942 spin_unlock_irqrestore(&max3421_hcd->lock, flags); in max3421_remove()
1944 free_irq(spi->irq, hcd); in max3421_remove()
1959 .name = "max3421-hcd",