sl811_usb.c 18 KB

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