Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0+
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * c67x00-hcd.c: Cypress C67X00 USB Host Controller Driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * Copyright (C) 2006-2008 Barco N.V.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  *    Derived from the Cypress cy7c67200/300 ezusb linux driver and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  *    based on multiple host controller drivers inside the linux kernel.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include <linux/device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/platform_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/usb.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include "c67x00.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include "c67x00-hcd.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) /* --------------------------------------------------------------------------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18)  * Root Hub Support
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) static __u8 c67x00_hub_des[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) 	0x09,			/*  __u8  bLength; */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 	USB_DT_HUB,		/*  __u8  bDescriptorType; Hub-descriptor */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) 	0x02,			/*  __u8  bNbrPorts; */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 	0x00,			/* __u16  wHubCharacteristics; */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 	0x00,			/*   (per-port OC, no power switching) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 	0x32,			/*  __u8  bPwrOn2pwrGood; 2ms */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 	0x00,			/*  __u8  bHubContrCurrent; 0 mA */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 	0x00,			/*  __u8  DeviceRemovable; ** 7 Ports max ** */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 	0xff,			/*  __u8  PortPwrCtrlMask; ** 7 ports max ** */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) static void c67x00_hub_reset_host_port(struct c67x00_sie *sie, int port)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 	struct c67x00_hcd *c67x00 = sie->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 	c67x00_ll_husb_reset(sie, port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 	spin_lock_irqsave(&c67x00->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 	c67x00_ll_husb_reset_port(sie, port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 	spin_unlock_irqrestore(&c67x00->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 	c67x00_ll_set_husb_eot(sie->dev, DEFAULT_EOT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) static int c67x00_hub_status_data(struct usb_hcd *hcd, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 	struct c67x00_hcd *c67x00 = hcd_to_c67x00_hcd(hcd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 	struct c67x00_sie *sie = c67x00->sie;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 	u16 status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	*buf = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	status = c67x00_ll_usb_get_status(sie);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	for (i = 0; i < C67X00_PORTS; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 		if (status & PORT_CONNECT_CHANGE(i))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 			*buf |= (1 << i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	/* bit 0 denotes hub change, b1..n port change */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	*buf <<= 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	return !!*buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) static int c67x00_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 			      u16 wIndex, char *buf, u16 wLength)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 	struct c67x00_hcd *c67x00 = hcd_to_c67x00_hcd(hcd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	struct c67x00_sie *sie = c67x00->sie;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	u16 status, usb_status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	int len = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	unsigned int port = wIndex-1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	u16 wPortChange, wPortStatus;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	switch (typeReq) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	case GetHubStatus:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 		*(__le32 *) buf = cpu_to_le32(0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 		len = 4;		/* hub power */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	case GetPortStatus:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 		if (wIndex > C67X00_PORTS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 			return -EPIPE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 		status = c67x00_ll_usb_get_status(sie);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 		usb_status = c67x00_ll_get_usb_ctl(sie);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 		wPortChange = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 		if (status & PORT_CONNECT_CHANGE(port))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 			wPortChange |= USB_PORT_STAT_C_CONNECTION;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 		wPortStatus = USB_PORT_STAT_POWER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 		if (!(status & PORT_SE0_STATUS(port)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 			wPortStatus |= USB_PORT_STAT_CONNECTION;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 		if (usb_status & LOW_SPEED_PORT(port)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 			wPortStatus |= USB_PORT_STAT_LOW_SPEED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 			c67x00->low_speed_ports |= (1 << port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 		} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 			c67x00->low_speed_ports &= ~(1 << port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 		if (usb_status & SOF_EOP_EN(port))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 			wPortStatus |= USB_PORT_STAT_ENABLE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 		*(__le16 *) buf = cpu_to_le16(wPortStatus);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 		*(__le16 *) (buf + 2) = cpu_to_le16(wPortChange);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 		len = 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 	case SetHubFeature:	/* We don't implement these */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 	case ClearHubFeature:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 		switch (wValue) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 		case C_HUB_OVER_CURRENT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 		case C_HUB_LOCAL_POWER:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 			len = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 		default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 			return -EPIPE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	case SetPortFeature:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 		if (wIndex > C67X00_PORTS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 			return -EPIPE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 		switch (wValue) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 		case USB_PORT_FEAT_SUSPEND:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 			dev_dbg(c67x00_hcd_dev(c67x00),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 				"SetPortFeature %d (SUSPEND)\n", port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 			len = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 		case USB_PORT_FEAT_RESET:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 			c67x00_hub_reset_host_port(sie, port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 			len = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 		case USB_PORT_FEAT_POWER:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 			/* Power always enabled */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 			len = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 		default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 			dev_dbg(c67x00_hcd_dev(c67x00),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 				"%s: SetPortFeature %d (0x%04x) Error!\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 				__func__, port, wValue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 			return -EPIPE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 	case ClearPortFeature:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 		if (wIndex > C67X00_PORTS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 			return -EPIPE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 		switch (wValue) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 		case USB_PORT_FEAT_ENABLE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 			/* Reset the port so that the c67x00 also notices the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 			 * disconnect */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 			c67x00_hub_reset_host_port(sie, port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 			len = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 		case USB_PORT_FEAT_C_ENABLE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 			dev_dbg(c67x00_hcd_dev(c67x00),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 				"ClearPortFeature (%d): C_ENABLE\n", port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 			len = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 		case USB_PORT_FEAT_SUSPEND:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 			dev_dbg(c67x00_hcd_dev(c67x00),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 				"ClearPortFeature (%d): SUSPEND\n", port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 			len = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 		case USB_PORT_FEAT_C_SUSPEND:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 			dev_dbg(c67x00_hcd_dev(c67x00),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 				"ClearPortFeature (%d): C_SUSPEND\n", port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 			len = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 		case USB_PORT_FEAT_POWER:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 			dev_dbg(c67x00_hcd_dev(c67x00),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 				"ClearPortFeature (%d): POWER\n", port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 			return -EPIPE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 		case USB_PORT_FEAT_C_CONNECTION:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 			c67x00_ll_usb_clear_status(sie,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 						   PORT_CONNECT_CHANGE(port));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 			len = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 		case USB_PORT_FEAT_C_OVER_CURRENT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 			dev_dbg(c67x00_hcd_dev(c67x00),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 				"ClearPortFeature (%d): OVER_CURRENT\n", port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 			len = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 		case USB_PORT_FEAT_C_RESET:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 			dev_dbg(c67x00_hcd_dev(c67x00),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 				"ClearPortFeature (%d): C_RESET\n", port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 			len = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 		default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 			dev_dbg(c67x00_hcd_dev(c67x00),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 				"%s: ClearPortFeature %d (0x%04x) Error!\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 				__func__, port, wValue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 			return -EPIPE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 	case GetHubDescriptor:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 		len = min_t(unsigned int, sizeof(c67x00_hub_des), wLength);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 		memcpy(buf, c67x00_hub_des, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 		dev_dbg(c67x00_hcd_dev(c67x00), "%s: unknown\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 		return -EPIPE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) /* ---------------------------------------------------------------------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228)  * Main part of host controller driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232)  * c67x00_hcd_irq
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234)  * This function is called from the interrupt handler in c67x00-drv.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) static void c67x00_hcd_irq(struct c67x00_sie *sie, u16 int_status, u16 msg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 	struct c67x00_hcd *c67x00 = sie->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 	struct usb_hcd *hcd = c67x00_hcd_to_hcd(c67x00);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 	/* Handle sie message flags */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 	if (msg) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 		if (msg & HUSB_TDListDone)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 			c67x00_sched_kick(c67x00);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 			dev_warn(c67x00_hcd_dev(c67x00),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 				 "Unknown SIE msg flag(s): 0x%04x\n", msg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 	if (unlikely(hcd->state == HC_STATE_HALT))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 	if (!HCD_HW_ACCESSIBLE(hcd))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 	/* Handle Start of frame events */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 	if (int_status & SOFEOP_FLG(sie->sie_num)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 		c67x00_ll_usb_clear_status(sie, SOF_EOP_IRQ_FLG);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 		c67x00_sched_kick(c67x00);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264)  * c67x00_hcd_start: Host controller start hook
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) static int c67x00_hcd_start(struct usb_hcd *hcd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 	hcd->uses_new_polling = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 	hcd->state = HC_STATE_RUNNING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 	set_bit(HCD_FLAG_POLL_RH, &hcd->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276)  * c67x00_hcd_stop: Host controller stop hook
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) static void c67x00_hcd_stop(struct usb_hcd *hcd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 	/* Nothing to do */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) static int c67x00_hcd_get_frame(struct usb_hcd *hcd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 	struct c67x00_hcd *c67x00 = hcd_to_c67x00_hcd(hcd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 	u16 temp_val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 	dev_dbg(c67x00_hcd_dev(c67x00), "%s\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 	temp_val = c67x00_ll_husb_get_frame(c67x00->sie);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 	temp_val &= HOST_FRAME_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 	return temp_val ? (temp_val - 1) : HOST_FRAME_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) static const struct hc_driver c67x00_hc_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 	.description	= "c67x00-hcd",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 	.product_desc	= "Cypress C67X00 Host Controller",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 	.hcd_priv_size	= sizeof(struct c67x00_hcd),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 	.flags		= HCD_USB11 | HCD_MEMORY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 	 * basic lifecycle operations
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 	.start		= c67x00_hcd_start,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 	.stop		= c67x00_hcd_stop,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 	 * managing i/o requests and associated device resources
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 	.urb_enqueue	= c67x00_urb_enqueue,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 	.urb_dequeue	= c67x00_urb_dequeue,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 	.endpoint_disable = c67x00_endpoint_disable,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 	 * scheduling support
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 	.get_frame_number = c67x00_hcd_get_frame,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 	 * root hub support
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 	.hub_status_data = c67x00_hub_status_data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 	.hub_control	= c67x00_hub_control,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) /* ---------------------------------------------------------------------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326)  * Setup/Teardown routines
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) int c67x00_hcd_probe(struct c67x00_sie *sie)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 	struct c67x00_hcd *c67x00;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 	struct usb_hcd *hcd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 	int retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 	if (usb_disabled())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 	hcd = usb_create_hcd(&c67x00_hc_driver, sie_dev(sie), "c67x00_sie");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 	if (!hcd) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 		retval = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 		goto err0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 	c67x00 = hcd_to_c67x00_hcd(hcd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 	spin_lock_init(&c67x00->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 	c67x00->sie = sie;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 	INIT_LIST_HEAD(&c67x00->list[PIPE_ISOCHRONOUS]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) 	INIT_LIST_HEAD(&c67x00->list[PIPE_INTERRUPT]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 	INIT_LIST_HEAD(&c67x00->list[PIPE_CONTROL]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) 	INIT_LIST_HEAD(&c67x00->list[PIPE_BULK]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 	c67x00->urb_count = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) 	INIT_LIST_HEAD(&c67x00->td_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) 	c67x00->td_base_addr = CY_HCD_BUF_ADDR + SIE_TD_OFFSET(sie->sie_num);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) 	c67x00->buf_base_addr = CY_HCD_BUF_ADDR + SIE_BUF_OFFSET(sie->sie_num);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) 	c67x00->max_frame_bw = MAX_FRAME_BW_STD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) 	c67x00_ll_husb_init_host_port(sie);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) 	init_completion(&c67x00->endpoint_disable);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) 	retval = c67x00_sched_start_scheduler(c67x00);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) 	if (retval)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) 		goto err1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) 	retval = usb_add_hcd(hcd, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) 	if (retval) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) 		dev_dbg(sie_dev(sie), "%s: usb_add_hcd returned %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) 			__func__, retval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) 		goto err2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) 	device_wakeup_enable(hcd->self.controller);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) 	spin_lock_irqsave(&sie->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) 	sie->private_data = c67x00;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) 	sie->irq = c67x00_hcd_irq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) 	spin_unlock_irqrestore(&sie->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) 	return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382)  err2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) 	c67x00_sched_stop_scheduler(c67x00);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384)  err1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) 	usb_put_hcd(hcd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386)  err0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) 	return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) /* may be called with controller, bus, and devices active */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) void c67x00_hcd_remove(struct c67x00_sie *sie)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) 	struct c67x00_hcd *c67x00 = sie->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) 	struct usb_hcd *hcd = c67x00_hcd_to_hcd(c67x00);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) 	c67x00_sched_stop_scheduler(c67x00);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) 	usb_remove_hcd(hcd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) 	usb_put_hcd(hcd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) }