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: */
140 * SPI-thread without acquiring the HCD lock:
146 * cache-lines:
156 int urb_done; /* > 0 -> no errors, < 0: errno */
241 MAX3421_HI_BUSEVENT_BIT = 0, /* bus-reset/-resume */
297 /* Return same error-codes as ohci.h:cc_to_error: */
300 [MAX3421_HRSL_BUSY] = -EINVAL,
301 [MAX3421_HRSL_BADREQ] = -EINVAL,
302 [MAX3421_HRSL_UNDEF] = -EINVAL,
303 [MAX3421_HRSL_NAK] = -EAGAIN,
304 [MAX3421_HRSL_STALL] = -EPIPE,
305 [MAX3421_HRSL_TOGERR] = -EILSEQ,
306 [MAX3421_HRSL_WRONGPID] = -EPROTO,
307 [MAX3421_HRSL_BADBC] = -EREMOTEIO,
308 [MAX3421_HRSL_PIDERR] = -EPROTO,
309 [MAX3421_HRSL_PKTERR] = -EPROTO,
310 [MAX3421_HRSL_CRCERR] = -EILSEQ,
311 [MAX3421_HRSL_KERR] = -EIO,
312 [MAX3421_HRSL_JERR] = -EIO,
313 [MAX3421_HRSL_TIMEOUT] = -ETIME,
314 [MAX3421_HRSL_BABBLE] = -EOVERFLOW
330 #define field(val, bit) ((val) << (bit)) argument
335 return ((unsigned) (left - right)) % (USB_MAX_FRAME_NUMBER + 1); in frame_diff()
341 return (struct max3421_hcd *) hcd->hcd_priv; in hcd_to_max3421()
354 struct spi_device *spi = to_spi_device(hcd->self.controller); in spi_rd8()
362 max3421_hcd->tx->data[0] = in spi_rd8()
366 transfer.tx_buf = max3421_hcd->tx->data; in spi_rd8()
367 transfer.rx_buf = max3421_hcd->rx->data; in spi_rd8()
373 return max3421_hcd->rx->data[1]; in spi_rd8()
379 struct spi_device *spi = to_spi_device(hcd->self.controller); in spi_wr8()
388 max3421_hcd->tx->data[0] = in spi_wr8()
391 max3421_hcd->tx->data[1] = val; in spi_wr8()
393 transfer.tx_buf = max3421_hcd->tx->data; in spi_wr8()
403 struct spi_device *spi = to_spi_device(hcd->self.controller); in spi_rd_buf()
412 max3421_hcd->tx->data[0] = in spi_rd_buf()
415 transfer[0].tx_buf = max3421_hcd->tx->data; in spi_rd_buf()
429 struct spi_device *spi = to_spi_device(hcd->self.controller); in spi_wr_buf()
438 max3421_hcd->tx->data[0] = in spi_wr_buf()
442 transfer[0].tx_buf = max3421_hcd->tx->data; in spi_wr_buf()
455 * bits. The HUBPRE bit needs to be set when MAX3421E operates at
456 * full speed, but it's talking to a low-speed device (i.e., through a
457 * hub). Setting that bit ensures that every low-speed packet is
458 * preceded by a full-speed PRE PID. Possible configurations:
460 * Hub speed: Device speed: => LOWSPEED bit: HUBPRE bit:
461 * FULL FULL => 0 0
462 * FULL LOW => 1 1
464 * LOW FULL => 1 0
470 u8 mode_lowspeed, mode_hubpre, mode = max3421_hcd->mode; in max3421_set_speed()
472 mode_lowspeed = BIT(MAX3421_MODE_LOWSPEED_BIT); in max3421_set_speed()
473 mode_hubpre = BIT(MAX3421_MODE_HUBPRE_BIT); in max3421_set_speed()
474 if (max3421_hcd->port_status & USB_PORT_STAT_LOW_SPEED) { in max3421_set_speed()
477 } else if (dev->speed == USB_SPEED_LOW) { in max3421_set_speed()
482 if (mode != max3421_hcd->mode) { in max3421_set_speed()
483 max3421_hcd->mode = mode; in max3421_set_speed()
484 spi_wr8(hcd, MAX3421_REG_MODE, max3421_hcd->mode); in max3421_set_speed()
501 hctl = (BIT(rcvtog + MAX3421_HCTL_RCVTOG0_BIT) | in max3421_set_address()
502 BIT(sndtog + MAX3421_HCTL_SNDTOG0_BIT)); in max3421_set_address()
508 * address-assignment so it's best to just always load the in max3421_set_address()
509 * address whenever the end-point changed/was forced. in max3421_set_address()
511 spi_wr8(hcd, MAX3421_REG_PERADDR, dev->devnum); in max3421_set_address()
517 spi_wr_buf(hcd, MAX3421_REG_SUDFIFO, urb->setup_packet, 8); in max3421_ctrl_setup()
525 int epnum = usb_pipeendpoint(urb->pipe); in max3421_transfer_in()
527 max3421_hcd->curr_len = 0; in max3421_transfer_in()
528 max3421_hcd->hien |= BIT(MAX3421_HI_RCVDAV_BIT); in max3421_transfer_in()
535 struct spi_device *spi = to_spi_device(hcd->self.controller); in max3421_transfer_out()
537 int epnum = usb_pipeendpoint(urb->pipe); in max3421_transfer_out()
541 src = urb->transfer_buffer + urb->actual_length; in max3421_transfer_out()
544 if (max3421_hcd->rev == 0x12) { in max3421_transfer_out()
548 spi_wr8(hcd, MAX3421_REG_SNDBC, max3421_hcd->curr_len); in max3421_transfer_out()
553 max_packet = usb_maxpacket(urb->dev, urb->pipe, 1); in max3421_transfer_out()
560 dev_err(&spi->dev, in max3421_transfer_out()
561 "%s: packet-size of %u too big (limit is %u bytes)", in max3421_transfer_out()
563 max3421_hcd->urb_done = -EMSGSIZE; in max3421_transfer_out()
564 return -EMSGSIZE; in max3421_transfer_out()
566 max3421_hcd->curr_len = min((urb->transfer_buffer_length - in max3421_transfer_out()
567 urb->actual_length), max_packet); in max3421_transfer_out()
569 spi_wr_buf(hcd, MAX3421_REG_SNDFIFO, src, max3421_hcd->curr_len); in max3421_transfer_out()
570 spi_wr8(hcd, MAX3421_REG_SNDBC, max3421_hcd->curr_len); in max3421_transfer_out()
575 * Issue the next host-transfer command.
582 struct urb *urb = max3421_hcd->curr_urb; in max3421_next_transfer()
584 int cmd = -EINVAL; in max3421_next_transfer()
589 max3421_ep = urb->ep->hcpriv; in max3421_next_transfer()
591 switch (max3421_ep->pkt_state) { in max3421_next_transfer()
618 /* issue the command and wait for host-xfer-done interrupt: */ in max3421_next_transfer()
621 max3421_hcd->hien |= BIT(MAX3421_HI_HXFRDN_BIT); in max3421_next_transfer()
631 * frame to process non-periodic (bulk & control) transfers.
635 * o max3421_hcd->curr_urb MUST BE NULL.
641 struct spi_device *spi = to_spi_device(hcd->self.controller); in max3421_select_and_start_urb()
650 spin_lock_irqsave(&max3421_hcd->lock, flags); in max3421_select_and_start_urb()
653 max3421_hcd->sched_pass < SCHED_PASS_DONE; in max3421_select_and_start_urb()
654 ++max3421_hcd->sched_pass) in max3421_select_and_start_urb()
655 list_for_each(pos, &max3421_hcd->ep_list) { in max3421_select_and_start_urb()
659 ep = max3421_ep->ep; in max3421_select_and_start_urb()
661 switch (usb_endpoint_type(&ep->desc)) { in max3421_select_and_start_urb()
664 if (max3421_hcd->sched_pass != in max3421_select_and_start_urb()
671 if (max3421_hcd->sched_pass != in max3421_select_and_start_urb()
677 if (list_empty(&ep->urb_list)) in max3421_select_and_start_urb()
679 urb = list_first_entry(&ep->urb_list, struct urb, in max3421_select_and_start_urb()
681 if (urb->unlinked) { in max3421_select_and_start_urb()
682 dev_dbg(&spi->dev, "%s: URB %p unlinked=%d", in max3421_select_and_start_urb()
683 __func__, urb, urb->unlinked); in max3421_select_and_start_urb()
684 max3421_hcd->curr_urb = urb; in max3421_select_and_start_urb()
685 max3421_hcd->urb_done = 1; in max3421_select_and_start_urb()
686 spin_unlock_irqrestore(&max3421_hcd->lock, in max3421_select_and_start_urb()
691 switch (usb_endpoint_type(&ep->desc)) { in max3421_select_and_start_urb()
697 if (frame_diff(max3421_ep->last_active, in max3421_select_and_start_urb()
698 max3421_hcd->frame_number) == 0) in max3421_select_and_start_urb()
703 if (max3421_ep->retransmit in max3421_select_and_start_urb()
704 && (frame_diff(max3421_ep->last_active, in max3421_select_and_start_urb()
705 max3421_hcd->frame_number) in max3421_select_and_start_urb()
717 if (frame_diff(max3421_hcd->frame_number, in max3421_select_and_start_urb()
718 max3421_ep->last_active) in max3421_select_and_start_urb()
719 < urb->interval) in max3421_select_and_start_urb()
722 * end-point in the current in max3421_select_and_start_urb()
730 list_move_tail(pos, &max3421_hcd->ep_list); in max3421_select_and_start_urb()
736 spin_unlock_irqrestore(&max3421_hcd->lock, flags); in max3421_select_and_start_urb()
740 urb = max3421_hcd->curr_urb = curr_urb; in max3421_select_and_start_urb()
741 epnum = usb_endpoint_num(&urb->ep->desc); in max3421_select_and_start_urb()
742 if (max3421_ep->retransmit) in max3421_select_and_start_urb()
744 max3421_ep->retransmit = 0; in max3421_select_and_start_urb()
747 if (usb_endpoint_xfer_control(&ep->desc)) { in max3421_select_and_start_urb()
752 usb_settoggle(urb->dev, epnum, 0, 1); in max3421_select_and_start_urb()
753 usb_settoggle(urb->dev, epnum, 1, 1); in max3421_select_and_start_urb()
754 max3421_ep->pkt_state = PKT_STATE_SETUP; in max3421_select_and_start_urb()
756 max3421_ep->pkt_state = PKT_STATE_TRANSFER; in max3421_select_and_start_urb()
759 spin_unlock_irqrestore(&max3421_hcd->lock, flags); in max3421_select_and_start_urb()
761 max3421_ep->last_active = max3421_hcd->frame_number; in max3421_select_and_start_urb()
762 max3421_set_address(hcd, urb->dev, epnum); in max3421_select_and_start_urb()
763 max3421_set_speed(hcd, urb->dev); in max3421_select_and_start_urb()
776 struct spi_device *spi = to_spi_device(hcd->self.controller); in max3421_check_unlink()
784 spin_lock_irqsave(&max3421_hcd->lock, flags); in max3421_check_unlink()
785 list_for_each_entry(max3421_ep, &max3421_hcd->ep_list, ep_list) { in max3421_check_unlink()
786 ep = max3421_ep->ep; in max3421_check_unlink()
787 list_for_each_entry_safe(urb, next, &ep->urb_list, urb_list) { in max3421_check_unlink()
788 if (urb->unlinked) { in max3421_check_unlink()
790 dev_dbg(&spi->dev, "%s: URB %p unlinked=%d", in max3421_check_unlink()
791 __func__, urb, urb->unlinked); in max3421_check_unlink()
793 spin_unlock_irqrestore(&max3421_hcd->lock, in max3421_check_unlink()
796 spin_lock_irqsave(&max3421_hcd->lock, flags); in max3421_check_unlink()
800 spin_unlock_irqrestore(&max3421_hcd->lock, flags); in max3421_check_unlink()
811 struct urb *urb = max3421_hcd->curr_urb; in max3421_slow_retransmit()
814 max3421_ep = urb->ep->hcpriv; in max3421_slow_retransmit()
815 max3421_ep->retransmit = 1; in max3421_slow_retransmit()
816 max3421_hcd->curr_urb = NULL; in max3421_slow_retransmit()
826 struct urb *urb = max3421_hcd->curr_urb; in max3421_recv_data_available()
834 if (urb->actual_length >= urb->transfer_buffer_length) in max3421_recv_data_available()
837 remaining = urb->transfer_buffer_length - urb->actual_length; in max3421_recv_data_available()
842 void *dst = urb->transfer_buffer + urb->actual_length; in max3421_recv_data_available()
845 urb->actual_length += transfer_size; in max3421_recv_data_available()
846 max3421_hcd->curr_len = transfer_size; in max3421_recv_data_available()
850 spi_wr8(hcd, MAX3421_REG_HIRQ, BIT(MAX3421_HI_RCVDAV_BIT)); in max3421_recv_data_available()
856 struct spi_device *spi = to_spi_device(hcd->self.controller); in max3421_handle_error()
859 struct urb *urb = max3421_hcd->curr_urb; in max3421_handle_error()
860 struct max3421_ep *max3421_ep = urb->ep->hcpriv; in max3421_handle_error()
865 * (i.e., error or NAK), we have to perform a dummy-write to in max3421_handle_error()
869 switch_sndfifo = (max3421_ep->pkt_state == PKT_STATE_TRANSFER && in max3421_handle_error()
880 case MAX3421_HRSL_KERR: /* K-state instead of response */ in max3421_handle_error()
881 case MAX3421_HRSL_JERR: /* J-state instead of response */ in max3421_handle_error()
886 max3421_hcd->urb_done = hrsl_to_error[result_code]; in max3421_handle_error()
887 dev_dbg(&spi->dev, "%s: unexpected error HRSL=0x%02x", in max3421_handle_error()
895 /* flip the send toggle bit: */ in max3421_handle_error()
900 BIT(sndtog + MAX3421_HCTL_SNDTOG0_BIT)); in max3421_handle_error()
909 if (max3421_ep->retries++ < USB_MAX_RETRIES) in max3421_handle_error()
914 max3421_hcd->urb_done = hrsl_to_error[result_code]; in max3421_handle_error()
915 dev_dbg(&spi->dev, "%s: unexpected error HRSL=0x%02x", in max3421_handle_error()
921 dev_dbg(&spi->dev, "%s: unexpected error HRSL=0x%02x", in max3421_handle_error()
923 max3421_hcd->urb_done = hrsl_to_error[result_code]; in max3421_handle_error()
931 if (max3421_ep->naks++ < NAK_MAX_FAST_RETRANSMITS) { in max3421_handle_error()
948 struct spi_device *spi = to_spi_device(hcd->self.controller); in max3421_transfer_in_done()
952 if (urb->actual_length >= urb->transfer_buffer_length) in max3421_transfer_in_done()
956 * USB 2.0 Section 5.3.2 Pipes: packets must be full size in max3421_transfer_in_done()
959 max_packet = usb_maxpacket(urb->dev, urb->pipe, 0); in max3421_transfer_in_done()
965 dev_err(&spi->dev, in max3421_transfer_in_done()
966 "%s: packet-size of %u too big (limit is %u bytes)", in max3421_transfer_in_done()
968 return -EINVAL; in max3421_transfer_in_done()
971 if (max3421_hcd->curr_len < max_packet) { in max3421_transfer_in_done()
972 if (urb->transfer_flags & URB_SHORT_NOT_OK) { in max3421_transfer_in_done()
975 * unexpected partial packet -> in max3421_transfer_in_done()
978 return -EREMOTEIO; in max3421_transfer_in_done()
994 urb->actual_length += max3421_hcd->curr_len; in max3421_transfer_out_done()
995 if (urb->actual_length < urb->transfer_buffer_length) in max3421_transfer_out_done()
997 if (urb->transfer_flags & URB_ZERO_PACKET) { in max3421_transfer_out_done()
999 * Some hardware needs a zero-size packet at the end in max3421_transfer_out_done()
1000 * of a bulk-out transfer if the last transfer was a in max3421_transfer_out_done()
1001 * full-sized packet (i.e., such hardware use < in max3421_transfer_out_done()
1005 u32 max_packet = usb_maxpacket(urb->dev, urb->pipe, 1); in max3421_transfer_out_done()
1007 if (max3421_hcd->curr_len == max_packet) in max3421_transfer_out_done()
1020 struct urb *urb = max3421_hcd->curr_urb; in max3421_host_transfer_done()
1025 max3421_hcd->hien &= ~(BIT(MAX3421_HI_HXFRDN_BIT) | in max3421_host_transfer_done()
1026 BIT(MAX3421_HI_RCVDAV_BIT)); in max3421_host_transfer_done()
1032 ++max3421_hcd->err_stat[result_code]; in max3421_host_transfer_done()
1035 max3421_ep = urb->ep->hcpriv; in max3421_host_transfer_done()
1042 max3421_ep->naks = 0; in max3421_host_transfer_done()
1043 max3421_ep->retries = 0; in max3421_host_transfer_done()
1044 switch (max3421_ep->pkt_state) { in max3421_host_transfer_done()
1047 if (urb->transfer_buffer_length > 0) in max3421_host_transfer_done()
1048 max3421_ep->pkt_state = PKT_STATE_TRANSFER; in max3421_host_transfer_done()
1050 max3421_ep->pkt_state = PKT_STATE_TERMINATE; in max3421_host_transfer_done()
1058 if (urb_done > 0 && usb_pipetype(urb->pipe) == PIPE_CONTROL) { in max3421_host_transfer_done()
1060 * We aren't really done - we still need to in max3421_host_transfer_done()
1063 max3421_hcd->urb_done = urb_done = 0; in max3421_host_transfer_done()
1064 max3421_ep->pkt_state = PKT_STATE_TERMINATE; in max3421_host_transfer_done()
1074 max3421_hcd->urb_done = urb_done; in max3421_host_transfer_done()
1096 mode = max3421_hcd->mode; in max3421_detect_conn()
1101 * Turn off SOFKAENAB bit to avoid getting interrupt in max3421_detect_conn()
1102 * every milli-second: in max3421_detect_conn()
1104 mode &= ~BIT(MAX3421_MODE_SOFKAENAB_BIT); in max3421_detect_conn()
1107 case 0x1: /* J=0,K=1: low-speed (in full-speed or vice versa) */ in max3421_detect_conn()
1108 case 0x2: /* J=1,K=0: full-speed (in full-speed or vice versa) */ in max3421_detect_conn()
1111 mode ^= BIT(MAX3421_MODE_LOWSPEED_BIT); in max3421_detect_conn()
1112 /* turn on SOFKAENAB bit: */ in max3421_detect_conn()
1113 mode |= BIT(MAX3421_MODE_SOFKAENAB_BIT); in max3421_detect_conn()
1121 max3421_hcd->mode = mode; in max3421_detect_conn()
1122 spi_wr8(hcd, MAX3421_REG_MODE, max3421_hcd->mode); in max3421_detect_conn()
1124 spin_lock_irqsave(&max3421_hcd->lock, flags); in max3421_detect_conn()
1125 old_port_status = max3421_hcd->port_status; in max3421_detect_conn()
1127 max3421_hcd->port_status |= USB_PORT_STAT_CONNECTION; in max3421_detect_conn()
1129 max3421_hcd->port_status &= ~USB_PORT_STAT_CONNECTION; in max3421_detect_conn()
1130 if (mode & BIT(MAX3421_MODE_LOWSPEED_BIT)) in max3421_detect_conn()
1131 max3421_hcd->port_status |= USB_PORT_STAT_LOW_SPEED; in max3421_detect_conn()
1133 max3421_hcd->port_status &= ~USB_PORT_STAT_LOW_SPEED; in max3421_detect_conn()
1134 chg = (old_port_status ^ max3421_hcd->port_status); in max3421_detect_conn()
1135 max3421_hcd->port_status |= chg << 16; in max3421_detect_conn()
1136 spin_unlock_irqrestore(&max3421_hcd->lock, flags); in max3421_detect_conn()
1143 struct spi_device *spi = to_spi_device(hcd->self.controller); in max3421_irq_handler()
1146 if (max3421_hcd->spi_thread) in max3421_irq_handler()
1147 wake_up_process(max3421_hcd->spi_thread); in max3421_irq_handler()
1148 if (!test_and_set_bit(ENABLE_IRQ, &max3421_hcd->todo)) in max3421_irq_handler()
1149 disable_irq_nosync(spi->irq); in max3421_irq_handler()
1166 spin_lock_irqsave(&max3421_hcd->lock, flags); in dump_eps()
1167 list_for_each_entry(max3421_ep, &max3421_hcd->ep_list, ep_list) { in dump_eps()
1168 ep = max3421_ep->ep; in dump_eps()
1173 list_for_each_entry(urb, &ep->urb_list, urb_list) { in dump_eps()
1174 ret = snprintf(dp, end - dp, " %p(%d.%s %d/%d)", urb, in dump_eps()
1175 usb_pipetype(urb->pipe), in dump_eps()
1177 urb->actual_length, in dump_eps()
1178 urb->transfer_buffer_length); in dump_eps()
1179 if (ret < 0 || ret >= end - dp) in dump_eps()
1180 break; /* error or buffer full */ in dump_eps()
1184 epnum = usb_endpoint_num(&ep->desc); in dump_eps()
1186 epnum, max3421_ep->pkt_state, max3421_ep->last_active, in dump_eps()
1187 max3421_ep->retries, max3421_ep->naks, in dump_eps()
1188 max3421_ep->retransmit, ubuf); in dump_eps()
1190 spin_unlock_irqrestore(&max3421_hcd->lock, flags); in dump_eps()
1210 hirq &= max3421_hcd->hien; in max3421_handle_irqs()
1215 hirq & ~(BIT(MAX3421_HI_SNDBAV_BIT) | in max3421_handle_irqs()
1216 BIT(MAX3421_HI_RCVDAV_BIT))); in max3421_handle_irqs()
1218 if (hirq & BIT(MAX3421_HI_FRAME_BIT)) { in max3421_handle_irqs()
1219 max3421_hcd->frame_number = ((max3421_hcd->frame_number + 1) in max3421_handle_irqs()
1221 max3421_hcd->sched_pass = SCHED_PASS_PERIODIC; in max3421_handle_irqs()
1224 if (hirq & BIT(MAX3421_HI_RCVDAV_BIT)) in max3421_handle_irqs()
1227 if (hirq & BIT(MAX3421_HI_HXFRDN_BIT)) in max3421_handle_irqs()
1230 if (hirq & BIT(MAX3421_HI_CONDET_BIT)) in max3421_handle_irqs()
1235 * other than the end-points: in max3421_handle_irqs()
1237 spin_lock_irqsave(&max3421_hcd->lock, flags); in max3421_handle_irqs()
1239 old_port_status = max3421_hcd->port_status; in max3421_handle_irqs()
1240 if (hirq & BIT(MAX3421_HI_BUSEVENT_BIT)) { in max3421_handle_irqs()
1241 if (max3421_hcd->port_status & USB_PORT_STAT_RESET) { in max3421_handle_irqs()
1243 max3421_hcd->port_status &= ~USB_PORT_STAT_RESET; in max3421_handle_irqs()
1244 max3421_hcd->port_status |= USB_PORT_STAT_ENABLE; in max3421_handle_irqs()
1250 if (hirq & BIT(MAX3421_HI_RWU_BIT)) in max3421_handle_irqs()
1252 if (hirq & BIT(MAX3421_HI_SUSDN_BIT)) in max3421_handle_irqs()
1255 chg = (old_port_status ^ max3421_hcd->port_status); in max3421_handle_irqs()
1256 max3421_hcd->port_status |= chg << 16; in max3421_handle_irqs()
1258 spin_unlock_irqrestore(&max3421_hcd->lock, flags); in max3421_handle_irqs()
1271 int ret = snprintf(dp, end - dp, " %lu", in max3421_handle_irqs()
1272 max3421_hcd->err_stat[i]); in max3421_handle_irqs()
1273 if (ret < 0 || ret >= end - dp) in max3421_handle_irqs()
1274 break; /* error or buffer full */ in max3421_handle_irqs()
1278 memset(max3421_hcd->err_stat, 0, in max3421_handle_irqs()
1279 sizeof(max3421_hcd->err_stat)); in max3421_handle_irqs()
1292 struct spi_device *spi = to_spi_device(hcd->self.controller); in max3421_reset_hcd()
1297 spi_wr8(hcd, MAX3421_REG_USBCTL, BIT(MAX3421_USBCTL_CHIPRES_BIT)); in max3421_reset_hcd()
1303 & BIT(MAX3421_USBIRQ_OSCOKIRQ_BIT)) in max3421_reset_hcd()
1305 if (--timeout < 0) { in max3421_reset_hcd()
1306 dev_err(&spi->dev, in max3421_reset_hcd()
1315 * enable pull-down registers on DM/DP: in max3421_reset_hcd()
1317 max3421_hcd->mode = (BIT(MAX3421_MODE_HOST_BIT) | in max3421_reset_hcd()
1318 BIT(MAX3421_MODE_SOFKAENAB_BIT) | in max3421_reset_hcd()
1319 BIT(MAX3421_MODE_DMPULLDN_BIT) | in max3421_reset_hcd()
1320 BIT(MAX3421_MODE_DPPULLDN_BIT)); in max3421_reset_hcd()
1321 spi_wr8(hcd, MAX3421_REG_MODE, max3421_hcd->mode); in max3421_reset_hcd()
1323 /* reset frame-number: */ in max3421_reset_hcd()
1324 max3421_hcd->frame_number = USB_MAX_FRAME_NUMBER; in max3421_reset_hcd()
1325 spi_wr8(hcd, MAX3421_REG_HCTL, BIT(MAX3421_HCTL_FRMRST_BIT)); in max3421_reset_hcd()
1327 /* sample the state of the D+ and D- lines */ in max3421_reset_hcd()
1328 spi_wr8(hcd, MAX3421_REG_HCTL, BIT(MAX3421_HCTL_SAMPLEBUS_BIT)); in max3421_reset_hcd()
1331 /* enable frame, connection-detected, and bus-event interrupts: */ in max3421_reset_hcd()
1332 max3421_hcd->hien = (BIT(MAX3421_HI_FRAME_BIT) | in max3421_reset_hcd()
1333 BIT(MAX3421_HI_CONDET_BIT) | in max3421_reset_hcd()
1334 BIT(MAX3421_HI_BUSEVENT_BIT)); in max3421_reset_hcd()
1335 spi_wr8(hcd, MAX3421_REG_HIEN, max3421_hcd->hien); in max3421_reset_hcd()
1338 spi_wr8(hcd, MAX3421_REG_CPUCTL, BIT(MAX3421_CPUCTL_IE_BIT)); in max3421_reset_hcd()
1350 status = max3421_hcd->urb_done; in max3421_urb_done()
1351 max3421_hcd->urb_done = 0; in max3421_urb_done()
1354 urb = max3421_hcd->curr_urb; in max3421_urb_done()
1356 /* save the old end-points toggles: */ in max3421_urb_done()
1360 int epnum = usb_endpoint_num(&urb->ep->desc); in max3421_urb_done()
1363 usb_settoggle(urb->dev, epnum, 0, rcvtog); in max3421_urb_done()
1364 usb_settoggle(urb->dev, epnum, 1, sndtog); in max3421_urb_done()
1366 max3421_hcd->curr_urb = NULL; in max3421_urb_done()
1367 spin_lock_irqsave(&max3421_hcd->lock, flags); in max3421_urb_done()
1369 spin_unlock_irqrestore(&max3421_hcd->lock, flags); in max3421_urb_done()
1381 struct spi_device *spi = to_spi_device(hcd->self.controller); in max3421_spi_thread()
1385 /* set full-duplex SPI mode, low-active interrupt pin: */ in max3421_spi_thread()
1387 (BIT(MAX3421_PINCTL_FDUPSPI_BIT) | /* full-duplex */ in max3421_spi_thread()
1388 BIT(MAX3421_PINCTL_INTLEVEL_BIT))); /* low-active irq */ in max3421_spi_thread()
1391 max3421_hcd->rev = spi_rd8(hcd, MAX3421_REG_REVISION); in max3421_spi_thread()
1392 if (max3421_hcd->rev == 0x12 || max3421_hcd->rev == 0x13) in max3421_spi_thread()
1394 dev_err(&spi->dev, "bad rev 0x%02x", max3421_hcd->rev); in max3421_spi_thread()
1397 dev_info(&spi->dev, "rev 0x%x, SPI clk %dHz, bpw %u, irq %d\n", in max3421_spi_thread()
1398 max3421_hcd->rev, spi->max_speed_hz, spi->bits_per_word, in max3421_spi_thread()
1399 spi->irq); in max3421_spi_thread()
1408 spi_wr8(hcd, MAX3421_REG_HIEN, max3421_hcd->hien); in max3421_spi_thread()
1411 if (test_and_clear_bit(ENABLE_IRQ, &max3421_hcd->todo)) in max3421_spi_thread()
1412 enable_irq(spi->irq); in max3421_spi_thread()
1419 if (max3421_hcd->urb_done) in max3421_spi_thread()
1423 else if (!max3421_hcd->curr_urb) in max3421_spi_thread()
1426 if (test_and_clear_bit(RESET_HCD, &max3421_hcd->todo)) in max3421_spi_thread()
1429 if (test_and_clear_bit(RESET_PORT, &max3421_hcd->todo)) { in max3421_spi_thread()
1432 BIT(MAX3421_HCTL_BUSRST_BIT)); in max3421_spi_thread()
1435 if (test_and_clear_bit(CHECK_UNLINK, &max3421_hcd->todo)) in max3421_spi_thread()
1437 if (test_and_clear_bit(IOPIN_UPDATE, &max3421_hcd->todo)) { in max3421_spi_thread()
1439 * IOPINS1/IOPINS2 do not auto-increment, so we can't in max3421_spi_thread()
1442 for (i = 0; i < ARRAY_SIZE(max3421_hcd->iopins); ++i) { in max3421_spi_thread()
1446 (max3421_hcd->iopins[i] & 0x0f)); in max3421_spi_thread()
1448 max3421_hcd->iopins[i] = val; in max3421_spi_thread()
1454 dev_info(&spi->dev, "SPI thread exiting"); in max3421_spi_thread()
1463 max3421_hcd->port_status &= ~(USB_PORT_STAT_ENABLE | in max3421_reset_port()
1465 max3421_hcd->port_status |= USB_PORT_STAT_RESET; in max3421_reset_port()
1466 set_bit(RESET_PORT, &max3421_hcd->todo); in max3421_reset_port()
1467 wake_up_process(max3421_hcd->spi_thread); in max3421_reset_port()
1476 hcd->self.sg_tablesize = 0; in max3421_reset()
1477 hcd->speed = HCD_USB2; in max3421_reset()
1478 hcd->self.root_hub->speed = USB_SPEED_FULL; in max3421_reset()
1479 set_bit(RESET_HCD, &max3421_hcd->todo); in max3421_reset()
1480 wake_up_process(max3421_hcd->spi_thread); in max3421_reset()
1489 spin_lock_init(&max3421_hcd->lock); in max3421_start()
1490 max3421_hcd->rh_state = MAX3421_RH_RUNNING; in max3421_start()
1492 INIT_LIST_HEAD(&max3421_hcd->ep_list); in max3421_start()
1494 hcd->power_budget = POWER_BUDGET; in max3421_start()
1495 hcd->state = HC_STATE_RUNNING; in max3421_start()
1496 hcd->uses_new_polling = 1; in max3421_start()
1508 struct spi_device *spi = to_spi_device(hcd->self.controller); in max3421_urb_enqueue()
1514 switch (usb_pipetype(urb->pipe)) { in max3421_urb_enqueue()
1517 if (urb->interval < 0) { in max3421_urb_enqueue()
1518 dev_err(&spi->dev, in max3421_urb_enqueue()
1519 "%s: interval=%d for intr-/iso-pipe; expected > 0\n", in max3421_urb_enqueue()
1520 __func__, urb->interval); in max3421_urb_enqueue()
1521 return -EINVAL; in max3421_urb_enqueue()
1528 spin_lock_irqsave(&max3421_hcd->lock, flags); in max3421_urb_enqueue()
1530 max3421_ep = urb->ep->hcpriv; in max3421_urb_enqueue()
1535 retval = -ENOMEM; in max3421_urb_enqueue()
1538 max3421_ep->ep = urb->ep; in max3421_urb_enqueue()
1539 max3421_ep->last_active = max3421_hcd->frame_number; in max3421_urb_enqueue()
1540 urb->ep->hcpriv = max3421_ep; in max3421_urb_enqueue()
1542 list_add_tail(&max3421_ep->ep_list, &max3421_hcd->ep_list); in max3421_urb_enqueue()
1548 max3421_hcd->sched_pass = SCHED_PASS_PERIODIC; in max3421_urb_enqueue()
1549 wake_up_process(max3421_hcd->spi_thread); in max3421_urb_enqueue()
1553 spin_unlock_irqrestore(&max3421_hcd->lock, flags); in max3421_urb_enqueue()
1564 spin_lock_irqsave(&max3421_hcd->lock, flags); in max3421_urb_dequeue()
1567 * This will set urb->unlinked which in turn causes the entry in max3421_urb_dequeue()
1572 set_bit(CHECK_UNLINK, &max3421_hcd->todo); in max3421_urb_dequeue()
1573 wake_up_process(max3421_hcd->spi_thread); in max3421_urb_dequeue()
1575 spin_unlock_irqrestore(&max3421_hcd->lock, flags); in max3421_urb_dequeue()
1585 spin_lock_irqsave(&max3421_hcd->lock, flags); in max3421_endpoint_disable()
1587 if (ep->hcpriv) { in max3421_endpoint_disable()
1588 struct max3421_ep *max3421_ep = ep->hcpriv; in max3421_endpoint_disable()
1591 if (!list_empty(&max3421_ep->ep_list)) in max3421_endpoint_disable()
1592 list_del(&max3421_ep->ep_list); in max3421_endpoint_disable()
1594 ep->hcpriv = NULL; in max3421_endpoint_disable()
1597 spin_unlock_irqrestore(&max3421_hcd->lock, flags); in max3421_endpoint_disable()
1604 return max3421_hcd->frame_number; in max3421_get_frame_number()
1608 * Should return a non-zero value when any port is undergoing a resume
1618 spin_lock_irqsave(&max3421_hcd->lock, flags); in max3421_hub_status_data()
1623 if ((max3421_hcd->port_status & PORT_C_MASK) != 0) { in max3421_hub_status_data()
1624 *buf = (1 << 1); /* a hub over-current condition exists */ in max3421_hub_status_data()
1625 dev_dbg(hcd->self.controller, in max3421_hub_status_data()
1627 max3421_hcd->port_status); in max3421_hub_status_data()
1629 if (max3421_hcd->rh_state == MAX3421_RH_SUSPENDED) in max3421_hub_status_data()
1633 spin_unlock_irqrestore(&max3421_hcd->lock, flags); in max3421_hub_status_data()
1642 * See Table 11-13: Hub Descriptor in USB 2.0 spec. in hub_descriptor()
1644 desc->bDescriptorType = USB_DT_HUB; /* hub descriptor */ in hub_descriptor()
1645 desc->bDescLength = 9; in hub_descriptor()
1646 desc->wHubCharacteristics = cpu_to_le16(HUB_CHAR_INDV_PORT_LPSM | in hub_descriptor()
1648 desc->bNbrPorts = 1; in hub_descriptor()
1652 * Set the MAX3421E general-purpose output with number PIN_NUMBER to
1653 * VALUE (0 or 1). PIN_NUMBER may be in the range from 1-8. For
1654 * any other value, this function acts as a no-op.
1662 --pin_number; in max3421_gpout_set_value()
1670 max3421_hcd->iopins[idx] |= mask; in max3421_gpout_set_value()
1672 max3421_hcd->iopins[idx] &= ~mask; in max3421_gpout_set_value()
1673 set_bit(IOPIN_UPDATE, &max3421_hcd->todo); in max3421_gpout_set_value()
1674 wake_up_process(max3421_hcd->spi_thread); in max3421_gpout_set_value()
1681 struct spi_device *spi = to_spi_device(hcd->self.controller); in max3421_hub_control()
1687 pdata = spi->dev.platform_data; in max3421_hub_control()
1689 spin_lock_irqsave(&max3421_hcd->lock, flags); in max3421_hub_control()
1699 dev_dbg(hcd->self.controller, "power-off\n"); in max3421_hub_control()
1700 max3421_gpout_set_value(hcd, pdata->vbus_gpout, in max3421_hub_control()
1701 !pdata->vbus_active_level); in max3421_hub_control()
1704 max3421_hcd->port_status &= ~(1 << value); in max3421_hub_control()
1723 retval = -EPIPE; in max3421_hub_control()
1726 ((__le16 *) buf)[0] = cpu_to_le16(max3421_hcd->port_status); in max3421_hub_control()
1728 cpu_to_le16(max3421_hcd->port_status >> 16); in max3421_hub_control()
1732 retval = -EPIPE; in max3421_hub_control()
1743 if (max3421_hcd->active) in max3421_hub_control()
1744 max3421_hcd->port_status |= in max3421_hub_control()
1748 dev_dbg(hcd->self.controller, "power-on\n"); in max3421_hub_control()
1749 max3421_hcd->port_status |= USB_PORT_STAT_POWER; in max3421_hub_control()
1750 max3421_gpout_set_value(hcd, pdata->vbus_gpout, in max3421_hub_control()
1751 pdata->vbus_active_level); in max3421_hub_control()
1757 if ((max3421_hcd->port_status & USB_PORT_STAT_POWER) in max3421_hub_control()
1759 max3421_hcd->port_status |= (1 << value); in max3421_hub_control()
1764 dev_dbg(hcd->self.controller, in max3421_hub_control()
1768 retval = -EPIPE; in max3421_hub_control()
1771 spin_unlock_irqrestore(&max3421_hcd->lock, flags); in max3421_hub_control()
1778 return -1; in max3421_bus_suspend()
1784 return -1; in max3421_bus_resume()
1812 return -EINVAL; in max3421_of_vbus_en_pin()
1814 retval = of_property_read_u32_array(dev->of_node, "maxim,vbus-en-pin", value, 2); in max3421_of_vbus_en_pin()
1816 dev_err(dev, "device tree node property 'maxim,vbus-en-pin' is missing\n"); in max3421_of_vbus_en_pin()
1819 dev_info(dev, "property 'maxim,vbus-en-pin' value is <%d %d>\n", value[0], value[1]); in max3421_of_vbus_en_pin()
1821 pdata->vbus_gpout = value[0]; in max3421_of_vbus_en_pin()
1822 pdata->vbus_active_level = value[1]; in max3421_of_vbus_en_pin()
1830 struct device *dev = &spi->dev; in max3421_probe()
1837 dev_err(&spi->dev, "Unable to setup SPI bus"); in max3421_probe()
1838 return -EFAULT; in max3421_probe()
1841 if (!spi->irq) { in max3421_probe()
1843 return -EFAULT; in max3421_probe()
1846 if (IS_ENABLED(CONFIG_OF) && dev->of_node) { in max3421_probe()
1847 pdata = devm_kzalloc(&spi->dev, sizeof(*pdata), GFP_KERNEL); in max3421_probe()
1849 retval = -ENOMEM; in max3421_probe()
1856 spi->dev.platform_data = pdata; in max3421_probe()
1859 pdata = spi->dev.platform_data; in max3421_probe()
1861 dev_err(&spi->dev, "driver configuration data is not provided\n"); in max3421_probe()
1862 retval = -EFAULT; in max3421_probe()
1865 if (pdata->vbus_active_level > 1) { in max3421_probe()
1866 …dev_err(&spi->dev, "vbus active level value %d is out of range (0/1)\n", pdata->vbus_active_level); in max3421_probe()
1867 retval = -EINVAL; in max3421_probe()
1870 if (pdata->vbus_gpout < 1 || pdata->vbus_gpout > MAX3421_GPOUT_COUNT) { in max3421_probe()
1871 dev_err(&spi->dev, "vbus gpout value %d is out of range (1..8)\n", pdata->vbus_gpout); in max3421_probe()
1872 retval = -EINVAL; in max3421_probe()
1876 retval = -ENOMEM; in max3421_probe()
1877 hcd = usb_create_hcd(&max3421_hcd_desc, &spi->dev, in max3421_probe()
1878 dev_name(&spi->dev)); in max3421_probe()
1880 dev_err(&spi->dev, "failed to create HCD structure\n"); in max3421_probe()
1883 set_bit(HCD_FLAG_POLL_RH, &hcd->flags); in max3421_probe()
1885 max3421_hcd->next = max3421_hcd_list; in max3421_probe()
1887 INIT_LIST_HEAD(&max3421_hcd->ep_list); in max3421_probe()
1889 max3421_hcd->tx = kmalloc(sizeof(*max3421_hcd->tx), GFP_KERNEL); in max3421_probe()
1890 if (!max3421_hcd->tx) in max3421_probe()
1892 max3421_hcd->rx = kmalloc(sizeof(*max3421_hcd->rx), GFP_KERNEL); in max3421_probe()
1893 if (!max3421_hcd->rx) in max3421_probe()
1896 max3421_hcd->spi_thread = kthread_run(max3421_spi_thread, hcd, in max3421_probe()
1898 if (max3421_hcd->spi_thread == ERR_PTR(-ENOMEM)) { in max3421_probe()
1899 dev_err(&spi->dev, in max3421_probe()
1906 dev_err(&spi->dev, "failed to add HCD\n"); in max3421_probe()
1910 retval = request_irq(spi->irq, max3421_irq_handler, in max3421_probe()
1913 dev_err(&spi->dev, "failed to request irq %d\n", spi->irq); in max3421_probe()
1919 if (IS_ENABLED(CONFIG_OF) && dev->of_node && pdata) { in max3421_probe()
1920 devm_kfree(&spi->dev, pdata); in max3421_probe()
1921 spi->dev.platform_data = NULL; in max3421_probe()
1925 kfree(max3421_hcd->tx); in max3421_probe()
1926 kfree(max3421_hcd->rx); in max3421_probe()
1927 if (max3421_hcd->spi_thread) in max3421_probe()
1928 kthread_stop(max3421_hcd->spi_thread); in max3421_probe()
1941 for (prev = &max3421_hcd_list; *prev; prev = &(*prev)->next) { in max3421_remove()
1944 if (hcd->self.controller == &spi->dev) in max3421_remove()
1948 dev_err(&spi->dev, "no MAX3421 HCD found for SPI device %p\n", in max3421_remove()
1950 return -ENODEV; in max3421_remove()
1955 spin_lock_irqsave(&max3421_hcd->lock, flags); in max3421_remove()
1957 kthread_stop(max3421_hcd->spi_thread); in max3421_remove()
1958 *prev = max3421_hcd->next; in max3421_remove()
1960 spin_unlock_irqrestore(&max3421_hcd->lock, flags); in max3421_remove()
1962 free_irq(spi->irq, hcd); in max3421_remove()
1978 .name = "max3421-hcd",