Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-1.0+
0002 /*
0003  * OHCI HCD (Host Controller Driver) for USB.
0004  *
0005  * (C) Copyright 1999 Roman Weissgaerber <weissg@vienna.at>
0006  * (C) Copyright 2000-2002 David Brownell <dbrownell@users.sourceforge.net>
0007  * (C) Copyright 2002 Hewlett-Packard Company
0008  *
0009  * SA1111 Bus Glue
0010  *
0011  * Written by Christopher Hoover <ch@hpl.hp.com>
0012  * Based on fragments of previous driver by Russell King et al.
0013  *
0014  * This file is licenced under the GPL.
0015  */
0016 
0017 #include <asm/mach-types.h>
0018 #include <asm/hardware/sa1111.h>
0019 
0020 #ifndef CONFIG_SA1111
0021 #error "This file is SA-1111 bus glue.  CONFIG_SA1111 must be defined."
0022 #endif
0023 
0024 #define USB_STATUS  0x0118
0025 #define USB_RESET   0x011c
0026 #define USB_IRQTEST 0x0120
0027 
0028 #define USB_RESET_FORCEIFRESET  (1 << 0)
0029 #define USB_RESET_FORCEHCRESET  (1 << 1)
0030 #define USB_RESET_CLKGENRESET   (1 << 2)
0031 #define USB_RESET_SIMSCALEDOWN  (1 << 3)
0032 #define USB_RESET_USBINTTEST    (1 << 4)
0033 #define USB_RESET_SLEEPSTBYEN   (1 << 5)
0034 #define USB_RESET_PWRSENSELOW   (1 << 6)
0035 #define USB_RESET_PWRCTRLLOW    (1 << 7)
0036 
0037 #define USB_STATUS_IRQHCIRMTWKUP  (1 <<  7)
0038 #define USB_STATUS_IRQHCIBUFFACC  (1 <<  8)
0039 #define USB_STATUS_NIRQHCIM       (1 <<  9)
0040 #define USB_STATUS_NHCIMFCLR      (1 << 10)
0041 #define USB_STATUS_USBPWRSENSE    (1 << 11)
0042 
0043 #if 0
0044 static void dump_hci_status(struct usb_hcd *hcd, const char *label)
0045 {
0046     unsigned long status = readl_relaxed(hcd->regs + USB_STATUS);
0047 
0048     printk(KERN_DEBUG "%s USB_STATUS = { %s%s%s%s%s}\n", label,
0049          ((status & USB_STATUS_IRQHCIRMTWKUP) ? "IRQHCIRMTWKUP " : ""),
0050          ((status & USB_STATUS_IRQHCIBUFFACC) ? "IRQHCIBUFFACC " : ""),
0051          ((status & USB_STATUS_NIRQHCIM) ? "" : "IRQHCIM "),
0052          ((status & USB_STATUS_NHCIMFCLR) ? "" : "HCIMFCLR "),
0053          ((status & USB_STATUS_USBPWRSENSE) ? "USBPWRSENSE " : ""));
0054 }
0055 #endif
0056 
0057 static int ohci_sa1111_reset(struct usb_hcd *hcd)
0058 {
0059     struct ohci_hcd *ohci = hcd_to_ohci(hcd);
0060 
0061     ohci_hcd_init(ohci);
0062     return ohci_init(ohci);
0063 }
0064 
0065 static int ohci_sa1111_start(struct usb_hcd *hcd)
0066 {
0067     struct ohci_hcd *ohci = hcd_to_ohci(hcd);
0068     int ret;
0069 
0070     ret = ohci_run(ohci);
0071     if (ret < 0) {
0072         ohci_err(ohci, "can't start\n");
0073         ohci_stop(hcd);
0074     }
0075     return ret;
0076 }
0077 
0078 static const struct hc_driver ohci_sa1111_hc_driver = {
0079     .description =      hcd_name,
0080     .product_desc =     "SA-1111 OHCI",
0081     .hcd_priv_size =    sizeof(struct ohci_hcd),
0082 
0083     /*
0084      * generic hardware linkage
0085      */
0086     .irq =          ohci_irq,
0087     .flags =        HCD_USB11 | HCD_DMA | HCD_MEMORY,
0088 
0089     /*
0090      * basic lifecycle operations
0091      */
0092     .reset =        ohci_sa1111_reset,
0093     .start =        ohci_sa1111_start,
0094     .stop =         ohci_stop,
0095     .shutdown =     ohci_shutdown,
0096 
0097     /*
0098      * managing i/o requests and associated device resources
0099      */
0100     .urb_enqueue =      ohci_urb_enqueue,
0101     .urb_dequeue =      ohci_urb_dequeue,
0102     .endpoint_disable = ohci_endpoint_disable,
0103 
0104     /*
0105      * scheduling support
0106      */
0107     .get_frame_number = ohci_get_frame,
0108 
0109     /*
0110      * root hub support
0111      */
0112     .hub_status_data =  ohci_hub_status_data,
0113     .hub_control =      ohci_hub_control,
0114 #ifdef  CONFIG_PM
0115     .bus_suspend =      ohci_bus_suspend,
0116     .bus_resume =       ohci_bus_resume,
0117 #endif
0118     .start_port_reset = ohci_start_port_reset,
0119 };
0120 
0121 static int sa1111_start_hc(struct sa1111_dev *dev)
0122 {
0123     unsigned int usb_rst = 0;
0124     int ret;
0125 
0126     dev_dbg(&dev->dev, "starting SA-1111 OHCI USB Controller\n");
0127 
0128     if (machine_is_xp860() ||
0129         machine_is_assabet() ||
0130         machine_is_pfs168() ||
0131         machine_is_badge4())
0132         usb_rst = USB_RESET_PWRSENSELOW | USB_RESET_PWRCTRLLOW;
0133 
0134     /*
0135      * Configure the power sense and control lines.  Place the USB
0136      * host controller in reset.
0137      */
0138     writel_relaxed(usb_rst | USB_RESET_FORCEIFRESET | USB_RESET_FORCEHCRESET,
0139               dev->mapbase + USB_RESET);
0140 
0141     /*
0142      * Now, carefully enable the USB clock, and take
0143      * the USB host controller out of reset.
0144      */
0145     ret = sa1111_enable_device(dev);
0146     if (ret == 0) {
0147         udelay(11);
0148         writel_relaxed(usb_rst, dev->mapbase + USB_RESET);
0149     }
0150 
0151     return ret;
0152 }
0153 
0154 static void sa1111_stop_hc(struct sa1111_dev *dev)
0155 {
0156     unsigned int usb_rst;
0157 
0158     dev_dbg(&dev->dev, "stopping SA-1111 OHCI USB Controller\n");
0159 
0160     /*
0161      * Put the USB host controller into reset.
0162      */
0163     usb_rst = readl_relaxed(dev->mapbase + USB_RESET);
0164     writel_relaxed(usb_rst | USB_RESET_FORCEIFRESET | USB_RESET_FORCEHCRESET,
0165               dev->mapbase + USB_RESET);
0166 
0167     /*
0168      * Stop the USB clock.
0169      */
0170     sa1111_disable_device(dev);
0171 }
0172 
0173 /**
0174  * ohci_hcd_sa1111_probe - initialize SA-1111-based HCDs
0175  *
0176  * Allocates basic resources for this USB host controller, and
0177  * then invokes the start() method for the HCD associated with it.
0178  */
0179 static int ohci_hcd_sa1111_probe(struct sa1111_dev *dev)
0180 {
0181     struct usb_hcd *hcd;
0182     int ret, irq;
0183 
0184     if (usb_disabled())
0185         return -ENODEV;
0186 
0187     /*
0188      * We don't call dma_set_mask_and_coherent() here because the
0189      * DMA mask has already been appropraitely setup by the core
0190      * SA-1111 bus code (which includes bug workarounds.)
0191      */
0192 
0193     hcd = usb_create_hcd(&ohci_sa1111_hc_driver, &dev->dev, "sa1111");
0194     if (!hcd)
0195         return -ENOMEM;
0196 
0197     hcd->rsrc_start = dev->res.start;
0198     hcd->rsrc_len = resource_size(&dev->res);
0199 
0200     irq = sa1111_get_irq(dev, 1);
0201     if (irq <= 0) {
0202         ret = irq ? : -ENXIO;
0203         goto err1;
0204     }
0205 
0206     /*
0207      * According to the "Intel StrongARM SA-1111 Microprocessor Companion
0208      * Chip Specification Update" (June 2000), erratum #7, there is a
0209      * significant bug in the SA1111 SDRAM shared memory controller.  If
0210      * an access to a region of memory above 1MB relative to the bank base,
0211      * it is important that address bit 10 _NOT_ be asserted. Depending
0212      * on the configuration of the RAM, bit 10 may correspond to one
0213      * of several different (processor-relative) address bits.
0214      *
0215      * Section 4.6 of the "Intel StrongARM SA-1111 Development Module
0216      * User's Guide" mentions that jumpers R51 and R52 control the
0217      * target of SA-1111 DMA (either SDRAM bank 0 on Assabet, or
0218      * SDRAM bank 1 on Neponset). The default configuration selects
0219      * Assabet, so any address in bank 1 is necessarily invalid.
0220      *
0221      * As a workaround, use a bounce buffer in addressable memory
0222      * as local_mem, relying on ZONE_DMA to provide an area that
0223      * fits within the above constraints.
0224      *
0225      * SZ_64K is an estimate for what size this might need.
0226      */
0227     ret = usb_hcd_setup_local_mem(hcd, 0, 0, SZ_64K);
0228     if (ret)
0229         goto err1;
0230 
0231     if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) {
0232         dev_dbg(&dev->dev, "request_mem_region failed\n");
0233         ret = -EBUSY;
0234         goto err1;
0235     }
0236 
0237     hcd->regs = dev->mapbase;
0238 
0239     ret = sa1111_start_hc(dev);
0240     if (ret)
0241         goto err2;
0242 
0243     ret = usb_add_hcd(hcd, irq, 0);
0244     if (ret == 0) {
0245         device_wakeup_enable(hcd->self.controller);
0246         return ret;
0247     }
0248 
0249     sa1111_stop_hc(dev);
0250  err2:
0251     release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
0252  err1:
0253     usb_put_hcd(hcd);
0254     return ret;
0255 }
0256 
0257 /**
0258  * ohci_hcd_sa1111_remove - shutdown processing for SA-1111-based HCDs
0259  * @dev: USB Host Controller being removed
0260  *
0261  * Reverses the effect of ohci_hcd_sa1111_probe(), first invoking
0262  * the HCD's stop() method.
0263  */
0264 static void ohci_hcd_sa1111_remove(struct sa1111_dev *dev)
0265 {
0266     struct usb_hcd *hcd = sa1111_get_drvdata(dev);
0267 
0268     usb_remove_hcd(hcd);
0269     sa1111_stop_hc(dev);
0270     release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
0271     usb_put_hcd(hcd);
0272 }
0273 
0274 static void ohci_hcd_sa1111_shutdown(struct device *_dev)
0275 {
0276     struct sa1111_dev *dev = to_sa1111_device(_dev);
0277     struct usb_hcd *hcd = sa1111_get_drvdata(dev);
0278 
0279     if (test_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags)) {
0280         hcd->driver->shutdown(hcd);
0281         sa1111_stop_hc(dev);
0282     }
0283 }
0284 
0285 static struct sa1111_driver ohci_hcd_sa1111_driver = {
0286     .drv = {
0287         .name   = "sa1111-ohci",
0288         .owner  = THIS_MODULE,
0289         .shutdown = ohci_hcd_sa1111_shutdown,
0290     },
0291     .devid      = SA1111_DEVID_USB,
0292     .probe      = ohci_hcd_sa1111_probe,
0293     .remove     = ohci_hcd_sa1111_remove,
0294 };