From owner-p4-projects@FreeBSD.ORG Thu Aug 13 19:17:13 2009 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 4E1C11065675; Thu, 13 Aug 2009 19:17:12 +0000 (UTC) Delivered-To: perforce@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 0DEE7106564A for ; Thu, 13 Aug 2009 19:17:12 +0000 (UTC) (envelope-from syl@FreeBSD.org) Received: from repoman.freebsd.org (repoman.freebsd.org [IPv6:2001:4f8:fff6::29]) by mx1.freebsd.org (Postfix) with ESMTP id F0B1D8FC16 for ; Thu, 13 Aug 2009 19:17:11 +0000 (UTC) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.14.3/8.14.3) with ESMTP id n7DJHBDE031189 for ; Thu, 13 Aug 2009 19:17:11 GMT (envelope-from syl@FreeBSD.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.14.3/8.14.3/Submit) id n7DJHBbv031187 for perforce@freebsd.org; Thu, 13 Aug 2009 19:17:11 GMT (envelope-from syl@FreeBSD.org) Date: Thu, 13 Aug 2009 19:17:11 GMT Message-Id: <200908131917.n7DJHBbv031187@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to syl@FreeBSD.org using -f From: Sylvestre Gallon To: Perforce Change Reviews Cc: Subject: PERFORCE change 167303 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 13 Aug 2009 19:17:14 -0000 http://perforce.freebsd.org/chv.cgi?CH=167303 Change 167303 by syl@syl_atuin on 2009/08/13 19:16:28 Implement avr32dci dependant get_port_status. Change the code to use generic_roothub_exec. Remove old usb descriptor code. Remove old roothub_exec code. I cannot try to compile it, because this driver does not compile before my changes... Affected files ... .. //depot/projects/soc2009/syl_usb/src/sys/dev/usb/controller/avr32dci.c#10 edit Differences ... ==== //depot/projects/soc2009/syl_usb/src/sys/dev/usb/controller/avr32dci.c#10 (text+ko) ==== @@ -1410,366 +1410,20 @@ .start = avr32dci_device_isoc_fs_start, }; -/*------------------------------------------------------------------------* - * at91dci root control support - *------------------------------------------------------------------------* - * Simulate a hardware HUB by handling all the necessary requests. - *------------------------------------------------------------------------*/ - -static const struct usb_device_descriptor avr32dci_devd = { - .bLength = sizeof(struct usb_device_descriptor), - .bDescriptorType = UDESC_DEVICE, - .bcdUSB = {0x00, 0x02}, - .bDeviceClass = UDCLASS_HUB, - .bDeviceSubClass = UDSUBCLASS_HUB, - .bDeviceProtocol = UDPROTO_HSHUBSTT, - .bMaxPacketSize = 64, - .bcdDevice = {0x00, 0x01}, - .iManufacturer = 1, - .iProduct = 2, - .bNumConfigurations = 1, -}; - -static const struct usb_device_qualifier avr32dci_odevd = { - .bLength = sizeof(struct usb_device_qualifier), - .bDescriptorType = UDESC_DEVICE_QUALIFIER, - .bcdUSB = {0x00, 0x02}, - .bDeviceClass = UDCLASS_HUB, - .bDeviceSubClass = UDSUBCLASS_HUB, - .bDeviceProtocol = UDPROTO_FSHUB, - .bMaxPacketSize0 = 0, - .bNumConfigurations = 0, -}; - -static const struct avr32dci_config_desc avr32dci_confd = { - .confd = { - .bLength = sizeof(struct usb_config_descriptor), - .bDescriptorType = UDESC_CONFIG, - .wTotalLength[0] = sizeof(avr32dci_confd), - .bNumInterface = 1, - .bConfigurationValue = 1, - .iConfiguration = 0, - .bmAttributes = UC_SELF_POWERED, - .bMaxPower = 0, - }, - .ifcd = { - .bLength = sizeof(struct usb_interface_descriptor), - .bDescriptorType = UDESC_INTERFACE, - .bNumEndpoints = 1, - .bInterfaceClass = UICLASS_HUB, - .bInterfaceSubClass = UISUBCLASS_HUB, - .bInterfaceProtocol = UIPROTO_HSHUBSTT, - }, - .endpd = { - .bLength = sizeof(struct usb_endpoint_descriptor), - .bDescriptorType = UDESC_ENDPOINT, - .bEndpointAddress = (UE_DIR_IN | AVR32_INTR_ENDPT), - .bmAttributes = UE_INTERRUPT, - .wMaxPacketSize[0] = 8, - .bInterval = 255, - }, -}; - -static const struct usb_hub_descriptor_min avr32dci_hubd = { - .bDescLength = sizeof(avr32dci_hubd), - .bDescriptorType = UDESC_HUB, - .bNbrPorts = 1, - .wHubCharacteristics[0] = - (UHD_PWR_NO_SWITCH | UHD_OC_INDIVIDUAL) & 0xFF, - .wHubCharacteristics[1] = - (UHD_PWR_NO_SWITCH | UHD_OC_INDIVIDUAL) >> 8, - .bPwrOn2PwrGood = 50, - .bHubContrCurrent = 0, - .DeviceRemovable = {0}, /* port is removable */ -}; - -#define STRING_LANG \ - 0x09, 0x04, /* American English */ - -#define STRING_VENDOR \ - 'A', 0, 'V', 0, 'R', 0, '3', 0, '2', 0 - -#define STRING_PRODUCT \ - 'D', 0, 'C', 0, 'I', 0, ' ', 0, 'R', 0, \ - 'o', 0, 'o', 0, 't', 0, ' ', 0, 'H', 0, \ - 'U', 0, 'B', 0, - -USB_MAKE_STRING_DESC(STRING_LANG, avr32dci_langtab); -USB_MAKE_STRING_DESC(STRING_VENDOR, avr32dci_vendor); -USB_MAKE_STRING_DESC(STRING_PRODUCT, avr32dci_product); - static usb_error_t -avr32dci_roothub_exec(struct usb_device *udev, - struct usb_device_request *req, const void **pptr, uint16_t *plength) +avr32dci_clear_port_feature(struct usb_generic_softc *scav, + const struct usb_roothub_fops *fops, uint16_t *len, uint16_t *value, + uint16_t *index) { - struct avr32dci_softc *sc = AVR32_BUS2SC(udev->bus); - const void *ptr; - uint16_t len; - uint16_t value; - uint16_t index; + struct avr32dci_softc *sc = (struct avr32dci_softc *)scav; uint32_t temp; - usb_error_t err; - USB_BUS_LOCK_ASSERT(&sc->sc_bus, MA_OWNED); - - /* buffer reset */ - ptr = (const void *)&sc->sc_hub_temp; - len = 0; - err = 0; - - value = UGETW(req->wValue); - index = UGETW(req->wIndex); - - /* demultiplex the control request */ - - switch (req->bmRequestType) { - case UT_READ_DEVICE: - switch (req->bRequest) { - case UR_GET_DESCRIPTOR: - goto tr_handle_get_descriptor; - case UR_GET_CONFIG: - goto tr_handle_get_config; - case UR_GET_STATUS: - goto tr_handle_get_status; - default: - goto tr_stalled; - } - break; - - case UT_WRITE_DEVICE: - switch (req->bRequest) { - case UR_SET_ADDRESS: - goto tr_handle_set_address; - case UR_SET_CONFIG: - goto tr_handle_set_config; - case UR_CLEAR_FEATURE: - goto tr_valid; /* nop */ - case UR_SET_DESCRIPTOR: - goto tr_valid; /* nop */ - case UR_SET_FEATURE: - default: - goto tr_stalled; - } - break; - - case UT_WRITE_ENDPOINT: - switch (req->bRequest) { - case UR_CLEAR_FEATURE: - switch (UGETW(req->wValue)) { - case UF_ENDPOINT_HALT: - goto tr_handle_clear_halt; - case UF_DEVICE_REMOTE_WAKEUP: - goto tr_handle_clear_wakeup; - default: - goto tr_stalled; - } - break; - case UR_SET_FEATURE: - switch (UGETW(req->wValue)) { - case UF_ENDPOINT_HALT: - goto tr_handle_set_halt; - case UF_DEVICE_REMOTE_WAKEUP: - goto tr_handle_set_wakeup; - default: - goto tr_stalled; - } - break; - case UR_SYNCH_FRAME: - goto tr_valid; /* nop */ - default: - goto tr_stalled; - } - break; - - case UT_READ_ENDPOINT: - switch (req->bRequest) { - case UR_GET_STATUS: - goto tr_handle_get_ep_status; - default: - goto tr_stalled; - } - break; - - case UT_WRITE_INTERFACE: - switch (req->bRequest) { - case UR_SET_INTERFACE: - goto tr_handle_set_interface; - case UR_CLEAR_FEATURE: - goto tr_valid; /* nop */ - case UR_SET_FEATURE: - default: - goto tr_stalled; - } - break; - - case UT_READ_INTERFACE: - switch (req->bRequest) { - case UR_GET_INTERFACE: - goto tr_handle_get_interface; - case UR_GET_STATUS: - goto tr_handle_get_iface_status; - default: - goto tr_stalled; - } - break; - - case UT_WRITE_CLASS_INTERFACE: - case UT_WRITE_VENDOR_INTERFACE: - /* XXX forward */ - break; - - case UT_READ_CLASS_INTERFACE: - case UT_READ_VENDOR_INTERFACE: - /* XXX forward */ - break; - - case UT_WRITE_CLASS_DEVICE: - switch (req->bRequest) { - case UR_CLEAR_FEATURE: - goto tr_valid; - case UR_SET_DESCRIPTOR: - case UR_SET_FEATURE: - break; - default: - goto tr_stalled; - } - break; - - case UT_WRITE_CLASS_OTHER: - switch (req->bRequest) { - case UR_CLEAR_FEATURE: - goto tr_handle_clear_port_feature; - case UR_SET_FEATURE: - goto tr_handle_set_port_feature; - case UR_CLEAR_TT_BUFFER: - case UR_RESET_TT: - case UR_STOP_TT: - goto tr_valid; - - default: - goto tr_stalled; - } - break; - - case UT_READ_CLASS_OTHER: - switch (req->bRequest) { - case UR_GET_TT_STATE: - goto tr_handle_get_tt_state; - case UR_GET_STATUS: - goto tr_handle_get_port_status; - default: - goto tr_stalled; - } - break; - - case UT_READ_CLASS_DEVICE: - switch (req->bRequest) { - case UR_GET_DESCRIPTOR: - goto tr_handle_get_class_descriptor; - case UR_GET_STATUS: - goto tr_handle_get_class_status; - - default: - goto tr_stalled; - } - break; - default: - goto tr_stalled; + if (*index != 1) { + return (USB_ERR_STALLED); } - goto tr_valid; + DPRINTFN(9, "UR_CLEAR_PORT_FEATURE on port %d\n", *index); -tr_handle_get_descriptor: - switch (value >> 8) { - case UDESC_DEVICE: - if (value & 0xff) { - goto tr_stalled; - } - len = sizeof(avr32dci_devd); - ptr = (const void *)&avr32dci_devd; - goto tr_valid; - case UDESC_CONFIG: - if (value & 0xff) { - goto tr_stalled; - } - len = sizeof(avr32dci_confd); - ptr = (const void *)&avr32dci_confd; - goto tr_valid; - case UDESC_STRING: - switch (value & 0xff) { - case 0: /* Language table */ - len = sizeof(avr32dci_langtab); - ptr = (const void *)&avr32dci_langtab; - goto tr_valid; - - case 1: /* Vendor */ - len = sizeof(avr32dci_vendor); - ptr = (const void *)&avr32dci_vendor; - goto tr_valid; - - case 2: /* Product */ - len = sizeof(avr32dci_product); - ptr = (const void *)&avr32dci_product; - goto tr_valid; - default: - break; - } - break; - default: - goto tr_stalled; - } - goto tr_stalled; - -tr_handle_get_config: - len = 1; - sc->sc_hub_temp.wValue[0] = sc->sc_conf; - goto tr_valid; - -tr_handle_get_status: - len = 2; - USETW(sc->sc_hub_temp.wValue, UDS_SELF_POWERED); - goto tr_valid; - -tr_handle_set_address: - if (value & 0xFF00) { - goto tr_stalled; - } - sc->sc_rt_addr = value; - goto tr_valid; - -tr_handle_set_config: - if (value >= 2) { - goto tr_stalled; - } - sc->sc_conf = value; - goto tr_valid; - -tr_handle_get_interface: - len = 1; - sc->sc_hub_temp.wValue[0] = 0; - goto tr_valid; - -tr_handle_get_tt_state: -tr_handle_get_class_status: -tr_handle_get_iface_status: -tr_handle_get_ep_status: - len = 2; - USETW(sc->sc_hub_temp.wValue, 0); - goto tr_valid; - -tr_handle_set_halt: -tr_handle_set_interface: -tr_handle_set_wakeup: -tr_handle_clear_wakeup: -tr_handle_clear_halt: - goto tr_valid; - -tr_handle_clear_port_feature: - if (index != 1) { - goto tr_stalled; - } - DPRINTFN(9, "UR_CLEAR_PORT_FEATURE on port %d\n", index); - - switch (value) { + switch (*value) { case UHF_PORT_SUSPEND: avr32dci_wakeup_peer(sc); break; @@ -1828,42 +1482,22 @@ sc->sc_flags.change_suspend = 0; break; default: - err = USB_ERR_IOERROR; - goto done; + return (USB_ERR_IOERROR); } - goto tr_valid; + return (0); +} -tr_handle_set_port_feature: - if (index != 1) { - goto tr_stalled; - } - DPRINTFN(9, "UR_SET_PORT_FEATURE\n"); +static usb_error_t +avr32dci_get_port_status(struct usb_generic_softc *scav, + const struct usb_roothub_fops *fops, uint16_t *len, uint16_t *value, + uint16_t *index) +{ + struct avr32dci_softc *sc = (struct avr32dci_softc *)scav; - switch (value) { - case UHF_PORT_ENABLE: - sc->sc_flags.port_enabled = 1; - break; - case UHF_PORT_SUSPEND: - case UHF_PORT_RESET: - case UHF_PORT_TEST: - case UHF_PORT_INDICATOR: - /* nops */ - break; - case UHF_PORT_POWER: - sc->sc_flags.port_powered = 1; - break; - default: - err = USB_ERR_IOERROR; - goto done; - } - goto tr_valid; - -tr_handle_get_port_status: - DPRINTFN(9, "UR_GET_PORT_STATUS\n"); - if (index != 1) { - goto tr_stalled; + if (*index != 1) { + return (USB_ERR_STALLED); } if (sc->sc_flags.status_vbus) { avr32dci_clocks_on(sc); @@ -1875,54 +1509,57 @@ /* Select Device Side Mode */ - value = UPS_PORT_MODE_DEVICE; + *value = UPS_PORT_MODE_DEVICE; /* Check for High Speed */ if (AVR32_READ_4(sc, AVR32_INTSTA) & AVR32_INT_SPEED) - value |= UPS_HIGH_SPEED; + *value |= UPS_HIGH_SPEED; if (sc->sc_flags.port_powered) { - value |= UPS_PORT_POWER; + *value |= UPS_PORT_POWER; } if (sc->sc_flags.port_enabled) { - value |= UPS_PORT_ENABLED; + *value |= UPS_PORT_ENABLED; } if (sc->sc_flags.status_vbus && sc->sc_flags.status_bus_reset) { - value |= UPS_CURRENT_CONNECT_STATUS; + *value |= UPS_CURRENT_CONNECT_STATUS; } if (sc->sc_flags.status_suspend) { - value |= UPS_SUSPEND; + *value |= UPS_SUSPEND; } - USETW(sc->sc_hub_temp.ps.wPortStatus, value); + USETW(sc->sc_hub_temp.ps.wPortStatus, *value); - value = 0; + *value = 0; if (sc->sc_flags.change_connect) { - value |= UPS_C_CONNECT_STATUS; + *value |= UPS_C_CONNECT_STATUS; } if (sc->sc_flags.change_suspend) { - value |= UPS_C_SUSPEND; + *value |= UPS_C_SUSPEND; } - USETW(sc->sc_hub_temp.ps.wPortChange, value); - len = sizeof(sc->sc_hub_temp.ps); - goto tr_valid; + USETW(sc->sc_hub_temp.ps.wPortChange, *value); + *len = sizeof(sc->sc_hub_temp.ps); + return (0); +} -tr_handle_get_class_descriptor: - if (value & 0xFF) { - goto tr_stalled; - } - ptr = (const void *)&avr32dci_hubd; - len = sizeof(avr32dci_hubd); - goto tr_valid; - -tr_stalled: - err = USB_ERR_STALLED; -tr_valid: -done: - *plength = len; - *pptr = ptr; - return (err); +static usb_error_t +avr32dci_roothub_exec(struct usb_device *udev, + struct usb_device_request *req, const void **pptr, uint16_t *plength) +{ + struct avr32dci_softc *sc = AVR32_BUS2SC(udev->bus); + static const struct usb_roothub_fops fops = { + DEFAULT_ROOTHUB, + .handle_clear_port_feature = &avr32dci_clear_port_feature, + .handle_get_port_status = &avr32dci_get_port_status, + .handle_clocks_on = (usb_clocks_fops_t)&avr32dci_clocks_on, + .handle_clocks_off = (usb_clocks_fops_t)&avr32dci_clocks_off, + .handle_pull_up = (usb_clocks_fops_t)&avr32dci_pull_up, + .handle_pull_down = (usb_clocks_fops_t)&avr32dci_pull_down, + .handle_wakeup_peer = (usb_clocks_fops_t)&avr32dci_wakeup_peer, + }; + return generic_roothub_exec((struct usb_generic_softc *) sc, &fops, req, + pptr, plength); } static void