sl811-hcd.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * (C) Copyright 2004
  4. * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  5. *
  6. * This code is based on linux driver for sl811hs chip, source at
  7. * drivers/usb/host/sl811.c:
  8. *
  9. * SL811 Host Controller Interface driver for USB.
  10. *
  11. * Copyright (c) 2003/06, Courage Co., Ltd.
  12. *
  13. * Based on:
  14. * 1.uhci.c by Linus Torvalds, Johannes Erdfelt, Randy Dunlap,
  15. * Georg Acher, Deti Fliegl, Thomas Sailer, Roman Weissgaerber,
  16. * Adam Richter, Gregory P. Smith;
  17. * 2.Original SL811 driver (hc_sl811.o) by Pei Liu <pbl@cypress.com>
  18. * 3.Rewrited as sl811.o by Yin Aihua <yinah:couragetech.com.cn>
  19. */
  20. #include <common.h>
  21. #include <mpc8xx.h>
  22. #include <usb.h>
  23. #include "sl811.h"
  24. #include "../../../board/kup/common/kup.h"
  25. #ifdef __PPC__
  26. # define EIEIO __asm__ volatile ("eieio")
  27. #else
  28. # define EIEIO /* nothing */
  29. #endif
  30. #define SL811_ADR (0x50000000)
  31. #define SL811_DAT (0x50000001)
  32. #ifdef SL811_DEBUG
  33. static int debug = 9;
  34. #endif
  35. static int root_hub_devnum = 0;
  36. static struct usb_port_status rh_status = { 0 };/* root hub port status */
  37. static int sl811_rh_submit_urb(struct usb_device *usb_dev, unsigned long pipe,
  38. void *data, int buf_len, struct devrequest *cmd);
  39. static void sl811_write (__u8 index, __u8 data)
  40. {
  41. *(volatile unsigned char *) (SL811_ADR) = index;
  42. EIEIO;
  43. *(volatile unsigned char *) (SL811_DAT) = data;
  44. EIEIO;
  45. }
  46. static __u8 sl811_read (__u8 index)
  47. {
  48. __u8 data;
  49. *(volatile unsigned char *) (SL811_ADR) = index;
  50. EIEIO;
  51. data = *(volatile unsigned char *) (SL811_DAT);
  52. EIEIO;
  53. return (data);
  54. }
  55. /*
  56. * Read consecutive bytes of data from the SL811H/SL11H buffer
  57. */
  58. static void inline sl811_read_buf(__u8 offset, __u8 *buf, __u8 size)
  59. {
  60. *(volatile unsigned char *) (SL811_ADR) = offset;
  61. EIEIO;
  62. while (size--) {
  63. *buf++ = *(volatile unsigned char *) (SL811_DAT);
  64. EIEIO;
  65. }
  66. }
  67. /*
  68. * Write consecutive bytes of data to the SL811H/SL11H buffer
  69. */
  70. static void inline sl811_write_buf(__u8 offset, __u8 *buf, __u8 size)
  71. {
  72. *(volatile unsigned char *) (SL811_ADR) = offset;
  73. EIEIO;
  74. while (size--) {
  75. *(volatile unsigned char *) (SL811_DAT) = *buf++;
  76. EIEIO;
  77. }
  78. }
  79. int usb_init_kup4x (void)
  80. {
  81. volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR;
  82. volatile memctl8xx_t *memctl = &immap->im_memctl;
  83. int i;
  84. unsigned char tmp;
  85. memctl = &immap->im_memctl;
  86. memctl->memc_or7 = 0xFFFF8726;
  87. memctl->memc_br7 = 0x50000401; /* start at 0x50000000 */
  88. /* BP 14 low = USB ON */
  89. immap->im_cpm.cp_pbdat &= ~(BP_USB_VCC);
  90. /* PB 14 nomal port */
  91. immap->im_cpm.cp_pbpar &= ~(BP_USB_VCC);
  92. /* output */
  93. immap->im_cpm.cp_pbdir |= (BP_USB_VCC);
  94. puts ("USB: ");
  95. for (i = 0x10; i < 0xff; i++) {
  96. sl811_write(i, i);
  97. tmp = (sl811_read(i));
  98. if (tmp != i) {
  99. printf ("SL811 compare error index=0x%02x read=0x%02x\n", i, tmp);
  100. return (-1);
  101. }
  102. }
  103. printf ("SL811 ready\n");
  104. return (0);
  105. }
  106. /*
  107. * This function resets SL811HS controller and detects the speed of
  108. * the connecting device
  109. *
  110. * Return: 0 = no device attached; 1 = USB device attached
  111. */
  112. static int sl811_hc_reset(void)
  113. {
  114. int status ;
  115. sl811_write(SL811_CTRL2, SL811_CTL2_HOST | SL811_12M_HI);
  116. sl811_write(SL811_CTRL1, SL811_CTRL1_RESET);
  117. mdelay(20);
  118. /* Disable hardware SOF generation, clear all irq status. */
  119. sl811_write(SL811_CTRL1, 0);
  120. mdelay(2);
  121. sl811_write(SL811_INTRSTS, 0xff);
  122. status = sl811_read(SL811_INTRSTS);
  123. if (status & SL811_INTR_NOTPRESENT) {
  124. /* Device is not present */
  125. PDEBUG(0, "Device not present\n");
  126. rh_status.wPortStatus &= ~(USB_PORT_STAT_CONNECTION | USB_PORT_STAT_ENABLE);
  127. rh_status.wPortChange |= USB_PORT_STAT_C_CONNECTION;
  128. sl811_write(SL811_INTR, SL811_INTR_INSRMV);
  129. return 0;
  130. }
  131. /* Send SOF to address 0, endpoint 0. */
  132. sl811_write(SL811_LEN_B, 0);
  133. sl811_write(SL811_PIDEP_B, PIDEP(USB_PID_SOF, 0));
  134. sl811_write(SL811_DEV_B, 0x00);
  135. sl811_write(SL811_SOFLOW, SL811_12M_LOW);
  136. if (status & SL811_INTR_SPEED_FULL) {
  137. /* full speed device connect directly to root hub */
  138. PDEBUG (0, "Full speed Device attached\n");
  139. sl811_write(SL811_CTRL1, SL811_CTRL1_RESET);
  140. mdelay(20);
  141. sl811_write(SL811_CTRL2, SL811_CTL2_HOST | SL811_12M_HI);
  142. sl811_write(SL811_CTRL1, SL811_CTRL1_SOF);
  143. /* start the SOF or EOP */
  144. sl811_write(SL811_CTRL_B, SL811_USB_CTRL_ARM);
  145. rh_status.wPortStatus |= USB_PORT_STAT_CONNECTION;
  146. rh_status.wPortStatus &= ~USB_PORT_STAT_LOW_SPEED;
  147. mdelay(2);
  148. sl811_write(SL811_INTRSTS, 0xff);
  149. } else {
  150. /* slow speed device connect directly to root-hub */
  151. PDEBUG(0, "Low speed Device attached\n");
  152. sl811_write(SL811_CTRL1, SL811_CTRL1_RESET);
  153. mdelay(20);
  154. sl811_write(SL811_CTRL2, SL811_CTL2_HOST | SL811_CTL2_DSWAP | SL811_12M_HI);
  155. sl811_write(SL811_CTRL1, SL811_CTRL1_SPEED_LOW | SL811_CTRL1_SOF);
  156. /* start the SOF or EOP */
  157. sl811_write(SL811_CTRL_B, SL811_USB_CTRL_ARM);
  158. rh_status.wPortStatus |= USB_PORT_STAT_CONNECTION | USB_PORT_STAT_LOW_SPEED;
  159. mdelay(2);
  160. sl811_write(SL811_INTRSTS, 0xff);
  161. }
  162. rh_status.wPortChange |= USB_PORT_STAT_C_CONNECTION;
  163. sl811_write(SL811_INTR, /*SL811_INTR_INSRMV*/SL811_INTR_DONE_A);
  164. return 1;
  165. }
  166. int usb_lowlevel_init(int index, enum usb_init_type init, void **controller)
  167. {
  168. root_hub_devnum = 0;
  169. sl811_hc_reset();
  170. return 0;
  171. }
  172. int usb_lowlevel_stop(int index)
  173. {
  174. sl811_hc_reset();
  175. return 0;
  176. }
  177. static int calc_needed_buswidth(int bytes, int need_preamble)
  178. {
  179. return !need_preamble ? bytes * 8 + 256 : 8 * 8 * bytes + 2048;
  180. }
  181. static int sl811_send_packet(struct usb_device *dev, unsigned long pipe, __u8 *buffer, int len)
  182. {
  183. __u8 ctrl = SL811_USB_CTRL_ARM | SL811_USB_CTRL_ENABLE;
  184. __u16 status = 0;
  185. int err = 0, time_start = get_timer(0);
  186. int need_preamble = !(rh_status.wPortStatus & USB_PORT_STAT_LOW_SPEED) &&
  187. (dev->speed == USB_SPEED_LOW);
  188. if (len > 239)
  189. return -1;
  190. if (usb_pipeout(pipe))
  191. ctrl |= SL811_USB_CTRL_DIR_OUT;
  192. if (usb_gettoggle(dev, usb_pipeendpoint(pipe), usb_pipeout(pipe)))
  193. ctrl |= SL811_USB_CTRL_TOGGLE_1;
  194. if (need_preamble)
  195. ctrl |= SL811_USB_CTRL_PREAMBLE;
  196. sl811_write(SL811_INTRSTS, 0xff);
  197. while (err < 3) {
  198. sl811_write(SL811_ADDR_A, 0x10);
  199. sl811_write(SL811_LEN_A, len);
  200. if (usb_pipeout(pipe) && len)
  201. sl811_write_buf(0x10, buffer, len);
  202. if (!(rh_status.wPortStatus & USB_PORT_STAT_LOW_SPEED) &&
  203. sl811_read(SL811_SOFCNTDIV)*64 < calc_needed_buswidth(len, need_preamble))
  204. ctrl |= SL811_USB_CTRL_SOF;
  205. else
  206. ctrl &= ~SL811_USB_CTRL_SOF;
  207. sl811_write(SL811_CTRL_A, ctrl);
  208. while (!(sl811_read(SL811_INTRSTS) & SL811_INTR_DONE_A)) {
  209. if (5*CONFIG_SYS_HZ < get_timer(time_start)) {
  210. printf("USB transmit timed out\n");
  211. return -USB_ST_CRC_ERR;
  212. }
  213. }
  214. sl811_write(SL811_INTRSTS, 0xff);
  215. status = sl811_read(SL811_STS_A);
  216. if (status & SL811_USB_STS_ACK) {
  217. int remainder = sl811_read(SL811_CNT_A);
  218. if (remainder) {
  219. PDEBUG(0, "usb transfer remainder = %d\n", remainder);
  220. len -= remainder;
  221. }
  222. if (usb_pipein(pipe) && len)
  223. sl811_read_buf(0x10, buffer, len);
  224. return len;
  225. }
  226. if ((status & SL811_USB_STS_NAK) == SL811_USB_STS_NAK)
  227. continue;
  228. PDEBUG(0, "usb transfer error %#x\n", (int)status);
  229. err++;
  230. }
  231. err = 0;
  232. if (status & SL811_USB_STS_ERROR)
  233. err |= USB_ST_BUF_ERR;
  234. if (status & SL811_USB_STS_TIMEOUT)
  235. err |= USB_ST_CRC_ERR;
  236. if (status & SL811_USB_STS_STALL)
  237. err |= USB_ST_STALLED;
  238. return -err;
  239. }
  240. int submit_bulk_msg(struct usb_device *dev, unsigned long pipe, void *buffer,
  241. int len)
  242. {
  243. int dir_out = usb_pipeout(pipe);
  244. int ep = usb_pipeendpoint(pipe);
  245. int max = usb_maxpacket(dev, pipe);
  246. int done = 0;
  247. PDEBUG(7, "dev = %ld pipe = %ld buf = %p size = %d dir_out = %d\n",
  248. usb_pipedevice(pipe), usb_pipeendpoint(pipe), buffer, len, dir_out);
  249. dev->status = 0;
  250. sl811_write(SL811_DEV_A, usb_pipedevice(pipe));
  251. sl811_write(SL811_PIDEP_A, PIDEP(!dir_out ? USB_PID_IN : USB_PID_OUT, ep));
  252. while (done < len) {
  253. int res = sl811_send_packet(dev, pipe, (__u8*)buffer+done,
  254. max > len - done ? len - done : max);
  255. if (res < 0) {
  256. dev->status = -res;
  257. return res;
  258. }
  259. if (!dir_out && res < max) /* short packet */
  260. break;
  261. done += res;
  262. usb_dotoggle(dev, ep, dir_out);
  263. }
  264. dev->act_len = done;
  265. return 0;
  266. }
  267. int submit_control_msg(struct usb_device *dev, unsigned long pipe, void *buffer,
  268. int len,struct devrequest *setup)
  269. {
  270. int done = 0;
  271. int devnum = usb_pipedevice(pipe);
  272. int ep = usb_pipeendpoint(pipe);
  273. dev->status = 0;
  274. if (devnum == root_hub_devnum)
  275. return sl811_rh_submit_urb(dev, pipe, buffer, len, setup);
  276. PDEBUG(7, "dev = %d pipe = %ld buf = %p size = %d rt = %#x req = %#x bus = %i\n",
  277. devnum, ep, buffer, len, (int)setup->requesttype,
  278. (int)setup->request, sl811_read(SL811_SOFCNTDIV)*64);
  279. sl811_write(SL811_DEV_A, devnum);
  280. sl811_write(SL811_PIDEP_A, PIDEP(USB_PID_SETUP, ep));
  281. /* setup phase */
  282. usb_settoggle(dev, ep, 1, 0);
  283. if (sl811_send_packet(dev, usb_sndctrlpipe(dev, ep),
  284. (__u8*)setup, sizeof(*setup)) == sizeof(*setup)) {
  285. int dir_in = usb_pipein(pipe);
  286. int max = usb_maxpacket(dev, pipe);
  287. /* data phase */
  288. sl811_write(SL811_PIDEP_A,
  289. PIDEP(dir_in ? USB_PID_IN : USB_PID_OUT, ep));
  290. usb_settoggle(dev, ep, usb_pipeout(pipe), 1);
  291. while (done < len) {
  292. int res = sl811_send_packet(dev, pipe, (__u8*)buffer+done,
  293. max > len - done ? len - done : max);
  294. if (res < 0) {
  295. PDEBUG(0, "status data failed!\n");
  296. dev->status = -res;
  297. return 0;
  298. }
  299. done += res;
  300. usb_dotoggle(dev, ep, usb_pipeout(pipe));
  301. if (dir_in && res < max) /* short packet */
  302. break;
  303. }
  304. /* status phase */
  305. sl811_write(SL811_PIDEP_A,
  306. PIDEP(!dir_in ? USB_PID_IN : USB_PID_OUT, ep));
  307. usb_settoggle(dev, ep, !usb_pipeout(pipe), 1);
  308. if (sl811_send_packet(dev,
  309. !dir_in ? usb_rcvctrlpipe(dev, ep) :
  310. usb_sndctrlpipe(dev, ep),
  311. 0, 0) < 0) {
  312. PDEBUG(0, "status phase failed!\n");
  313. dev->status = -1;
  314. }
  315. } else {
  316. PDEBUG(0, "setup phase failed!\n");
  317. dev->status = -1;
  318. }
  319. dev->act_len = done;
  320. return done;
  321. }
  322. int submit_int_msg(struct usb_device *dev, unsigned long pipe, void *buffer,
  323. int len, int interval)
  324. {
  325. PDEBUG(0, "dev = %p pipe = %#lx buf = %p size = %d int = %d\n", dev, pipe,
  326. buffer, len, interval);
  327. return -1;
  328. }
  329. /*
  330. * SL811 Virtual Root Hub
  331. */
  332. /* Device descriptor */
  333. static __u8 sl811_rh_dev_des[] =
  334. {
  335. 0x12, /* __u8 bLength; */
  336. 0x01, /* __u8 bDescriptorType; Device */
  337. 0x10, /* __u16 bcdUSB; v1.1 */
  338. 0x01,
  339. 0x09, /* __u8 bDeviceClass; HUB_CLASSCODE */
  340. 0x00, /* __u8 bDeviceSubClass; */
  341. 0x00, /* __u8 bDeviceProtocol; */
  342. 0x08, /* __u8 bMaxPacketSize0; 8 Bytes */
  343. 0x00, /* __u16 idVendor; */
  344. 0x00,
  345. 0x00, /* __u16 idProduct; */
  346. 0x00,
  347. 0x00, /* __u16 bcdDevice; */
  348. 0x00,
  349. 0x00, /* __u8 iManufacturer; */
  350. 0x02, /* __u8 iProduct; */
  351. 0x01, /* __u8 iSerialNumber; */
  352. 0x01 /* __u8 bNumConfigurations; */
  353. };
  354. /* Configuration descriptor */
  355. static __u8 sl811_rh_config_des[] =
  356. {
  357. 0x09, /* __u8 bLength; */
  358. 0x02, /* __u8 bDescriptorType; Configuration */
  359. 0x19, /* __u16 wTotalLength; */
  360. 0x00,
  361. 0x01, /* __u8 bNumInterfaces; */
  362. 0x01, /* __u8 bConfigurationValue; */
  363. 0x00, /* __u8 iConfiguration; */
  364. 0x40, /* __u8 bmAttributes;
  365. Bit 7: Bus-powered, 6: Self-powered, 5 Remote-wakwup,
  366. 4..0: resvd */
  367. 0x00, /* __u8 MaxPower; */
  368. /* interface */
  369. 0x09, /* __u8 if_bLength; */
  370. 0x04, /* __u8 if_bDescriptorType; Interface */
  371. 0x00, /* __u8 if_bInterfaceNumber; */
  372. 0x00, /* __u8 if_bAlternateSetting; */
  373. 0x01, /* __u8 if_bNumEndpoints; */
  374. 0x09, /* __u8 if_bInterfaceClass; HUB_CLASSCODE */
  375. 0x00, /* __u8 if_bInterfaceSubClass; */
  376. 0x00, /* __u8 if_bInterfaceProtocol; */
  377. 0x00, /* __u8 if_iInterface; */
  378. /* endpoint */
  379. 0x07, /* __u8 ep_bLength; */
  380. 0x05, /* __u8 ep_bDescriptorType; Endpoint */
  381. 0x81, /* __u8 ep_bEndpointAddress; IN Endpoint 1 */
  382. 0x03, /* __u8 ep_bmAttributes; Interrupt */
  383. 0x08, /* __u16 ep_wMaxPacketSize; */
  384. 0x00,
  385. 0xff /* __u8 ep_bInterval; 255 ms */
  386. };
  387. /* root hub class descriptor*/
  388. static __u8 sl811_rh_hub_des[] =
  389. {
  390. 0x09, /* __u8 bLength; */
  391. 0x29, /* __u8 bDescriptorType; Hub-descriptor */
  392. 0x01, /* __u8 bNbrPorts; */
  393. 0x00, /* __u16 wHubCharacteristics; */
  394. 0x00,
  395. 0x50, /* __u8 bPwrOn2pwrGood; 2ms */
  396. 0x00, /* __u8 bHubContrCurrent; 0 mA */
  397. 0xfc, /* __u8 DeviceRemovable; *** 7 Ports max *** */
  398. 0xff /* __u8 PortPwrCtrlMask; *** 7 ports max *** */
  399. };
  400. /*
  401. * helper routine for returning string descriptors in UTF-16LE
  402. * input can actually be ISO-8859-1; ASCII is its 7-bit subset
  403. */
  404. static int ascii2utf (char *s, u8 *utf, int utfmax)
  405. {
  406. int retval;
  407. for (retval = 0; *s && utfmax > 1; utfmax -= 2, retval += 2) {
  408. *utf++ = *s++;
  409. *utf++ = 0;
  410. }
  411. return retval;
  412. }
  413. /*
  414. * root_hub_string is used by each host controller's root hub code,
  415. * so that they're identified consistently throughout the system.
  416. */
  417. static int usb_root_hub_string (int id, int serial, char *type, __u8 *data, int len)
  418. {
  419. char buf [30];
  420. /* assert (len > (2 * (sizeof (buf) + 1)));
  421. assert (strlen (type) <= 8);*/
  422. /* language ids */
  423. if (id == 0) {
  424. *data++ = 4; *data++ = 3; /* 4 bytes data */
  425. *data++ = 0; *data++ = 0; /* some language id */
  426. return 4;
  427. /* serial number */
  428. } else if (id == 1) {
  429. sprintf (buf, "%#x", serial);
  430. /* product description */
  431. } else if (id == 2) {
  432. sprintf (buf, "USB %s Root Hub", type);
  433. /* id 3 == vendor description */
  434. /* unsupported IDs --> "stall" */
  435. } else
  436. return 0;
  437. ascii2utf (buf, data + 2, len - 2);
  438. data [0] = 2 + strlen(buf) * 2;
  439. data [1] = 3;
  440. return data [0];
  441. }
  442. /* helper macro */
  443. #define OK(x) len = (x); break
  444. /*
  445. * This function handles all USB request to the the virtual root hub
  446. */
  447. static int sl811_rh_submit_urb(struct usb_device *usb_dev, unsigned long pipe,
  448. void *data, int buf_len, struct devrequest *cmd)
  449. {
  450. __u8 data_buf[16];
  451. __u8 *bufp = data_buf;
  452. int len = 0;
  453. int status = 0;
  454. __u16 bmRType_bReq;
  455. __u16 wValue = le16_to_cpu (cmd->value);
  456. __u16 wLength = le16_to_cpu (cmd->length);
  457. #ifdef SL811_DEBUG
  458. __u16 wIndex = le16_to_cpu (cmd->index);
  459. #endif
  460. if (usb_pipeint(pipe)) {
  461. PDEBUG(0, "interrupt transfer unimplemented!\n");
  462. return 0;
  463. }
  464. bmRType_bReq = cmd->requesttype | (cmd->request << 8);
  465. PDEBUG(5, "submit rh urb, req = %d(%x) val = %#x index = %#x len=%d\n",
  466. bmRType_bReq, bmRType_bReq, wValue, wIndex, wLength);
  467. /* Request Destination:
  468. without flags: Device,
  469. USB_RECIP_INTERFACE: interface,
  470. USB_RECIP_ENDPOINT: endpoint,
  471. USB_TYPE_CLASS means HUB here,
  472. USB_RECIP_OTHER | USB_TYPE_CLASS almost ever means HUB_PORT here
  473. */
  474. switch (bmRType_bReq) {
  475. case RH_GET_STATUS:
  476. *(__u16 *)bufp = cpu_to_le16(1);
  477. OK(2);
  478. case RH_GET_STATUS | USB_RECIP_INTERFACE:
  479. *(__u16 *)bufp = cpu_to_le16(0);
  480. OK(2);
  481. case RH_GET_STATUS | USB_RECIP_ENDPOINT:
  482. *(__u16 *)bufp = cpu_to_le16(0);
  483. OK(2);
  484. case RH_GET_STATUS | USB_TYPE_CLASS:
  485. *(__u32 *)bufp = cpu_to_le32(0);
  486. OK(4);
  487. case RH_GET_STATUS | USB_RECIP_OTHER | USB_TYPE_CLASS:
  488. *(__u32 *)bufp = cpu_to_le32(rh_status.wPortChange<<16 | rh_status.wPortStatus);
  489. OK(4);
  490. case RH_CLEAR_FEATURE | USB_RECIP_ENDPOINT:
  491. switch (wValue) {
  492. case 1:
  493. OK(0);
  494. }
  495. break;
  496. case RH_CLEAR_FEATURE | USB_TYPE_CLASS:
  497. switch (wValue) {
  498. case C_HUB_LOCAL_POWER:
  499. OK(0);
  500. case C_HUB_OVER_CURRENT:
  501. OK(0);
  502. }
  503. break;
  504. case RH_CLEAR_FEATURE | USB_RECIP_OTHER | USB_TYPE_CLASS:
  505. switch (wValue) {
  506. case USB_PORT_FEAT_ENABLE:
  507. rh_status.wPortStatus &= ~USB_PORT_STAT_ENABLE;
  508. OK(0);
  509. case USB_PORT_FEAT_SUSPEND:
  510. rh_status.wPortStatus &= ~USB_PORT_STAT_SUSPEND;
  511. OK(0);
  512. case USB_PORT_FEAT_POWER:
  513. rh_status.wPortStatus &= ~USB_PORT_STAT_POWER;
  514. OK(0);
  515. case USB_PORT_FEAT_C_CONNECTION:
  516. rh_status.wPortChange &= ~USB_PORT_STAT_C_CONNECTION;
  517. OK(0);
  518. case USB_PORT_FEAT_C_ENABLE:
  519. rh_status.wPortChange &= ~USB_PORT_STAT_C_ENABLE;
  520. OK(0);
  521. case USB_PORT_FEAT_C_SUSPEND:
  522. rh_status.wPortChange &= ~USB_PORT_STAT_C_SUSPEND;
  523. OK(0);
  524. case USB_PORT_FEAT_C_OVER_CURRENT:
  525. rh_status.wPortChange &= ~USB_PORT_STAT_C_OVERCURRENT;
  526. OK(0);
  527. case USB_PORT_FEAT_C_RESET:
  528. rh_status.wPortChange &= ~USB_PORT_STAT_C_RESET;
  529. OK(0);
  530. }
  531. break;
  532. case RH_SET_FEATURE | USB_RECIP_OTHER | USB_TYPE_CLASS:
  533. switch (wValue) {
  534. case USB_PORT_FEAT_SUSPEND:
  535. rh_status.wPortStatus |= USB_PORT_STAT_SUSPEND;
  536. OK(0);
  537. case USB_PORT_FEAT_RESET:
  538. rh_status.wPortStatus |= USB_PORT_STAT_RESET;
  539. rh_status.wPortChange = 0;
  540. rh_status.wPortChange |= USB_PORT_STAT_C_RESET;
  541. rh_status.wPortStatus &= ~USB_PORT_STAT_RESET;
  542. rh_status.wPortStatus |= USB_PORT_STAT_ENABLE;
  543. OK(0);
  544. case USB_PORT_FEAT_POWER:
  545. rh_status.wPortStatus |= USB_PORT_STAT_POWER;
  546. OK(0);
  547. case USB_PORT_FEAT_ENABLE:
  548. rh_status.wPortStatus |= USB_PORT_STAT_ENABLE;
  549. OK(0);
  550. }
  551. break;
  552. case RH_SET_ADDRESS:
  553. root_hub_devnum = wValue;
  554. OK(0);
  555. case RH_GET_DESCRIPTOR:
  556. switch ((wValue & 0xff00) >> 8) {
  557. case USB_DT_DEVICE:
  558. len = sizeof(sl811_rh_dev_des);
  559. bufp = sl811_rh_dev_des;
  560. OK(len);
  561. case USB_DT_CONFIG:
  562. len = sizeof(sl811_rh_config_des);
  563. bufp = sl811_rh_config_des;
  564. OK(len);
  565. case USB_DT_STRING:
  566. len = usb_root_hub_string(wValue & 0xff, (int)(long)0, "SL811HS", data, wLength);
  567. if (len > 0) {
  568. bufp = data;
  569. OK(len);
  570. }
  571. default:
  572. status = -32;
  573. }
  574. break;
  575. case RH_GET_DESCRIPTOR | USB_TYPE_CLASS:
  576. len = sizeof(sl811_rh_hub_des);
  577. bufp = sl811_rh_hub_des;
  578. OK(len);
  579. case RH_GET_CONFIGURATION:
  580. bufp[0] = 0x01;
  581. OK(1);
  582. case RH_SET_CONFIGURATION:
  583. OK(0);
  584. default:
  585. PDEBUG(1, "unsupported root hub command\n");
  586. status = -32;
  587. }
  588. len = min(len, buf_len);
  589. if (data != bufp)
  590. memcpy(data, bufp, len);
  591. PDEBUG(5, "len = %d, status = %d\n", len, status);
  592. usb_dev->status = status;
  593. usb_dev->act_len = len;
  594. return status == 0 ? len : status;
  595. }