sl811-hcd.c 18 KB

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