sl811-hcd.c 18 KB

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