PERFORCE change 167254 for review
Sylvestre Gallon
syl at FreeBSD.org
Wed Aug 12 18:35:08 UTC 2009
http://perforce.freebsd.org/chv.cgi?CH=167254
Change 167254 by syl at syl_atuin on 2009/08/12 18:34:28
Implement atmegadci dependant clear_port_feature.
Change the code to use generic_roothub_exec.
Remove old usb descriptor code.
Remove old roothub_exec code.
Affected files ...
.. //depot/projects/soc2009/syl_usb/src/sys/dev/usb/controller/atmegadci.c#11 edit
Differences ...
==== //depot/projects/soc2009/syl_usb/src/sys/dev/usb/controller/atmegadci.c#11 (text+ko) ====
@@ -1476,366 +1476,20 @@
.start = atmegadci_device_isoc_fs_start,
};
-/*------------------------------------------------------------------------*
- * at91dci root control support
- *------------------------------------------------------------------------*
- * Simulate a hardware HUB by handling all the necessary requests.
- *------------------------------------------------------------------------*/
-
-static const struct usb_device_descriptor atmegadci_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 atmegadci_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 atmegadci_config_desc atmegadci_confd = {
- .confd = {
- .bLength = sizeof(struct usb_config_descriptor),
- .bDescriptorType = UDESC_CONFIG,
- .wTotalLength[0] = sizeof(atmegadci_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 | ATMEGA_INTR_ENDPT),
- .bmAttributes = UE_INTERRUPT,
- .wMaxPacketSize[0] = 8,
- .bInterval = 255,
- },
-};
-
-static const struct usb_hub_descriptor_min atmegadci_hubd = {
- .bDescLength = sizeof(atmegadci_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, 'T', 0, 'M', 0, 'E', 0, 'G', 0, 'A', 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, atmegadci_langtab);
-USB_MAKE_STRING_DESC(STRING_VENDOR, atmegadci_vendor);
-USB_MAKE_STRING_DESC(STRING_PRODUCT, atmegadci_product);
-
static usb_error_t
-atmegadci_roothub_exec(struct usb_device *udev,
- struct usb_device_request *req, const void **pptr, uint16_t *plength)
+atmega_clear_port_feature(struct usb_generic_softc *atsc,
+ struct usb_roothub_fops *fops, uint16_t *len, uint16_t *value,
+ uint16_t *index)
{
- struct atmegadci_softc *sc = ATMEGA_BUS2SC(udev->bus);
- const void *ptr;
- uint16_t len;
- uint16_t value;
- uint16_t index;
- uint8_t temp;
- usb_error_t err;
+ struct atmegadci_softc *sc = (struct atmegadci_softc *)atsc;
+ uint32_t temp;
- 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(atmegadci_devd);
- ptr = (const void *)&atmegadci_devd;
- goto tr_valid;
- case UDESC_CONFIG:
- if (value & 0xff) {
- goto tr_stalled;
- }
- len = sizeof(atmegadci_confd);
- ptr = (const void *)&atmegadci_confd;
- goto tr_valid;
- case UDESC_STRING:
- switch (value & 0xff) {
- case 0: /* Language table */
- len = sizeof(atmegadci_langtab);
- ptr = (const void *)&atmegadci_langtab;
- goto tr_valid;
-
- case 1: /* Vendor */
- len = sizeof(atmegadci_vendor);
- ptr = (const void *)&atmegadci_vendor;
- goto tr_valid;
-
- case 2: /* Product */
- len = sizeof(atmegadci_product);
- ptr = (const void *)&atmegadci_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:
atmegadci_wakeup_peer(sc);
break;
@@ -1899,97 +1553,27 @@
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
+atmegadci_roothub_exec(struct usb_device *udev,
+ struct usb_device_request *req, const void **pptr, uint16_t *plength)
+{
+ struct atmegadci_softc *sc = ATMEGA_BUS2SC(udev->bus);
+ struct usb_roothub_fops fops;
- 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 (sc->sc_flags.status_vbus) {
- atmegadci_clocks_on(sc);
- atmegadci_pull_up(sc);
- } else {
- atmegadci_pull_down(sc);
- atmegadci_clocks_off(sc);
- }
-
- /* Select FULL-speed and Device Side Mode */
-
- value = UPS_PORT_MODE_DEVICE;
-
- if (sc->sc_flags.port_powered) {
- value |= UPS_PORT_POWER;
- }
- if (sc->sc_flags.port_enabled) {
- value |= UPS_PORT_ENABLED;
- }
- if (sc->sc_flags.status_vbus &&
- sc->sc_flags.status_bus_reset) {
- value |= UPS_CURRENT_CONNECT_STATUS;
- }
- if (sc->sc_flags.status_suspend) {
- value |= UPS_SUSPEND;
- }
- USETW(sc->sc_hub_temp.ps.wPortStatus, value);
-
- value = 0;
-
- if (sc->sc_flags.change_connect) {
- value |= UPS_C_CONNECT_STATUS;
- }
- if (sc->sc_flags.change_suspend) {
- value |= UPS_C_SUSPEND;
- }
- USETW(sc->sc_hub_temp.ps.wPortChange, value);
- len = sizeof(sc->sc_hub_temp.ps);
- goto tr_valid;
-
-tr_handle_get_class_descriptor:
- if (value & 0xFF) {
- goto tr_stalled;
- }
- ptr = (const void *)&atmegadci_hubd;
- len = sizeof(atmegadci_hubd);
- goto tr_valid;
-
-tr_stalled:
- err = USB_ERR_STALLED;
-tr_valid:
-done:
- *plength = len;
- *pptr = ptr;
- return (err);
+ bzero(&fops, sizeof(fops));
+ fops.handle_clear_port_feature = &atmega_clear_port_feature;
+ fops.handle_clocks_on = (usb_clocks_fops_t)&atmegadci_clocks_on;
+ fops.handle_clocks_off = (usb_clocks_fops_t)&atmegadci_clocks_off;
+ fops.handle_pull_up = (usb_clocks_fops_t)&atmegadci_pull_up;
+ fops.handle_pull_down = (usb_clocks_fops_t)&atmegadci_pull_down;
+ fops.handle_wakeup_peer = (usb_clocks_fops_t)&atmegadci_wakeup_peer;
+ return generic_roothub_exec((struct usb_generic_softc *) sc, &fops, req,
+ pptr, plength);
}
static void
More information about the p4-projects
mailing list