Back to home page

Quest Cross Reference

 
 

    


Warning, cross-references for /kernel/drivers/usb/usb.c need to be fixed.

0001 /*                    The Quest Operating System
0002  *  Copyright (C) 2005-2010  Richard West, Boston University
0003  *
0004  *  This program is free software: you can redistribute it and/or modify
0005  *  it under the terms of the GNU General Public License as published by
0006  *  the Free Software Foundation, either version 3 of the License, or
0007  *  (at your option) any later version.
0008  *
0009  *  This program is distributed in the hope that it will be useful,
0010  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
0011  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0012  *  GNU General Public License for more details.
0013  *
0014  *  You should have received a copy of the GNU General Public License
0015  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
0016  */
0017 
0018 #include <drivers/usb/usb.h>
0019 #include <drivers/usb/uhci.h>
0020 #include <arch/i386.h>
0021 #include <util/printf.h>
0022 #include <kernel.h>
0023 
0024 #define DEBUG_USB
0025 
0026 #ifdef DEBUG_USB
0027 #define DLOG(fmt,...) DLOG_PREFIX("USB",fmt,##__VA_ARGS__)
0028 #else
0029 #define DLOG(fmt,...) ;
0030 #endif
0031 
0032 int
0033 usb_control_transfer(
0034     USB_DEVICE_INFO * dev,
0035     addr_t setup_req,
0036     uint16_t req_len,
0037     addr_t data,
0038     uint16_t data_len)
0039 {
0040   switch (dev->host_type)
0041   {
0042     case USB_TYPE_HC_UHCI :
0043       if ((dev->devd).bMaxPacketSize0 == 0) {
0044         DLOG("USB_DEVICE_INFO is probably not initialized!");
0045         return -1;
0046       } else {
0047         return uhci_control_transfer(dev->address, setup_req,
0048             req_len, data, data_len, (dev->devd).bMaxPacketSize0);
0049       }
0050 
0051     case USB_TYPE_HC_EHCI :
0052       DLOG("EHCI Host Controller is not supported now!");
0053       return -1;
0054 
0055     case USB_TYPE_HC_OHCI :
0056       DLOG("OHCI Host Controller is not supported now!");
0057       return -1;
0058 
0059     default :
0060       DLOG("Unknown Host Controller request!");
0061       return -1;
0062   }
0063   return -1;
0064 }
0065 
0066 int
0067 usb_bulk_transfer(
0068     USB_DEVICE_INFO * dev,
0069     uint8_t endp,
0070     addr_t data,
0071     uint16_t len,
0072     uint8_t packet_len,
0073     uint8_t dir,
0074     uint32_t *act_len)
0075 {
0076   switch (dev->host_type)
0077   {
0078     case USB_TYPE_HC_UHCI :
0079       if ((dev->devd).bMaxPacketSize0 == 0) {
0080         DLOG("USB_DEVICE_INFO is probably not initialized!");
0081         return -1;
0082       } else {
0083         return uhci_bulk_transfer(dev->address, endp, data,
0084                                   len, packet_len, dir, act_len);
0085       }
0086 
0087     case USB_TYPE_HC_EHCI :
0088       DLOG("EHCI Host Controller is not supported now!");
0089       return -1;
0090 
0091     case USB_TYPE_HC_OHCI :
0092       DLOG("OHCI Host Controller is not supported now!");
0093       return -1;
0094 
0095     default :
0096       DLOG("Unknown Host Controller request!");
0097       return -1;
0098   }
0099   return -1;
0100 }
0101 
0102 int
0103 usb_get_descriptor (
0104     USB_DEVICE_INFO * dev,
0105     uint16_t dtype,
0106     uint16_t dindex,
0107     uint16_t index,
0108     uint16_t length,
0109     addr_t desc)
0110 {
0111   switch (dev->host_type)
0112   {
0113     case USB_TYPE_HC_UHCI :
0114       if ((dev->devd).bMaxPacketSize0 == 0) {
0115         DLOG("USB_DEVICE_INFO is probably not initialized!");
0116         return -1;
0117       } else {
0118         return uhci_get_descriptor(dev->address, dtype, dindex,
0119             index, length, desc, (dev->devd).bMaxPacketSize0);
0120       }
0121 
0122     case USB_TYPE_HC_EHCI :
0123       DLOG("EHCI Host Controller is not supported now!");
0124       return -1;
0125 
0126     case USB_TYPE_HC_OHCI :
0127       DLOG("OHCI Host Controller is not supported now!");
0128       return -1;
0129 
0130     default :
0131       DLOG("Unknown Host Controller request!");
0132       return -1;
0133   }
0134   return -1;
0135 }
0136 
0137 int
0138 usb_set_address (USB_DEVICE_INFO * dev, uint8_t new_addr)
0139 {
0140   switch (dev->host_type)
0141   {
0142     case USB_TYPE_HC_UHCI :
0143       if ((dev->devd).bMaxPacketSize0 == 0) {
0144         DLOG("USB_DEVICE_INFO is probably not initialized!");
0145         return -1;
0146       } else {
0147         return uhci_set_address(dev->address, new_addr,
0148             (dev->devd).bMaxPacketSize0);
0149       }
0150 
0151     case USB_TYPE_HC_EHCI :
0152       DLOG("EHCI Host Controller is not supported now!");
0153       return -1;
0154 
0155     case USB_TYPE_HC_OHCI :
0156       DLOG("OHCI Host Controller is not supported now!");
0157       return -1;
0158 
0159     default :
0160       DLOG("Unknown Host Controller request!");
0161       return -1;
0162   }
0163   return -1;
0164 }
0165 
0166 int
0167 usb_get_configuration(USB_DEVICE_INFO * dev)
0168 {
0169   switch (dev->host_type)
0170   {
0171     case USB_TYPE_HC_UHCI :
0172       if ((dev->devd).bMaxPacketSize0 == 0) {
0173         DLOG("USB_DEVICE_INFO is probably not initialized!");
0174         return -1;
0175       } else {
0176         return uhci_get_configuration(dev->address,
0177             (dev->devd).bMaxPacketSize0);
0178       }
0179 
0180     case USB_TYPE_HC_EHCI :
0181       DLOG("EHCI Host Controller is not supported now!");
0182       return -1;
0183 
0184     case USB_TYPE_HC_OHCI :
0185       DLOG("OHCI Host Controller is not supported now!");
0186       return -1;
0187 
0188     default :
0189       DLOG("Unknown Host Controller request!");
0190       return -1;
0191   }
0192   return -1;
0193 }
0194 
0195 int
0196 usb_set_configuration(USB_DEVICE_INFO * dev, uint8_t conf)
0197 {
0198   switch (dev->host_type)
0199   {
0200     case USB_TYPE_HC_UHCI :
0201       if ((dev->devd).bMaxPacketSize0 == 0) {
0202         DLOG("USB_DEVICE_INFO is probably not initialized!");
0203         return -1;
0204       } else {
0205         return uhci_set_configuration(dev->address, conf,
0206             (dev->devd).bMaxPacketSize0);
0207       }
0208 
0209     case USB_TYPE_HC_EHCI :
0210       DLOG("EHCI Host Controller is not supported now!");
0211       return -1;
0212 
0213     case USB_TYPE_HC_OHCI :
0214       DLOG("OHCI Host Controller is not supported now!");
0215       return -1;
0216 
0217     default :
0218       DLOG("Unknown Host Controller request!");
0219       return -1;
0220   }
0221   return -1;
0222 }
0223 
0224 int
0225 usb_get_interface(USB_DEVICE_INFO * dev, uint16_t interface)
0226 {
0227   switch (dev->host_type)
0228   {
0229     case USB_TYPE_HC_UHCI :
0230       if ((dev->devd).bMaxPacketSize0 == 0) {
0231         DLOG("USB_DEVICE_INFO is probably not initialized!");
0232         return -1;
0233       } else {
0234         return uhci_get_interface(dev->address, interface,
0235             (dev->devd).bMaxPacketSize0);
0236       }
0237 
0238     case USB_TYPE_HC_EHCI :
0239       DLOG("EHCI Host Controller is not supported now!");
0240       return -1;
0241 
0242     case USB_TYPE_HC_OHCI :
0243       DLOG("OHCI Host Controller is not supported now!");
0244       return -1;
0245 
0246     default :
0247       DLOG("Unknown Host Controller request!");
0248       return -1;
0249   }
0250   return -1;
0251 }
0252 
0253 int
0254 usb_set_interface(USB_DEVICE_INFO * dev, uint16_t alt, uint16_t interface)
0255 {
0256   switch (dev->host_type)
0257   {
0258     case USB_TYPE_HC_UHCI :
0259       if ((dev->devd).bMaxPacketSize0 == 0) {
0260         DLOG("USB_DEVICE_INFO is probably not initialized!");
0261         return -1;
0262       } else {
0263         return uhci_set_interface(dev->address, alt, interface,
0264             (dev->devd).bMaxPacketSize0);
0265       }
0266 
0267     case USB_TYPE_HC_EHCI :
0268       DLOG("EHCI Host Controller is not supported now!");
0269       return -1;
0270 
0271     case USB_TYPE_HC_OHCI :
0272       DLOG("OHCI Host Controller is not supported now!");
0273       return -1;
0274 
0275     default :
0276       DLOG("Unknown Host Controller request!");
0277       return -1;
0278   }
0279   return -1;
0280 }
0281 
0282 bool
0283 usb_init (void)
0284 {
0285   return TRUE;
0286 }
0287 
0288 #include "module/header.h"
0289 
0290 static const struct module_ops mod_ops = {
0291   .init = usb_init
0292 };
0293 
0294 DEF_MODULE (usb, "USB manager", &mod_ops, {});
0295 
0296 /*
0297  * Local Variables:
0298  * indent-tabs-mode: nil
0299  * mode: C
0300  * c-file-style: "gnu"
0301  * c-basic-offset: 2
0302  * End:
0303  */
0304 
0305 /* vi: set et sw=2 sts=2: */