Pseudocode to enable USB XOSC
[rpi-open-firmware.git] / drivers / BCM2708UsbPhy.cc
index e57674b..8442e0b 100644 (file)
@@ -6,8 +6,7 @@
  */
 
 #include <drivers/IODevice.hpp>
-#include <drivers/BCM2708PowerManagement.hpp>
-
+#include <drivers/BCM2708PowerManagement.hpp> 
 #define FLAG_BUSY (1 << 31)
 
 struct BCM2708UsbPhy : IODevice {
@@ -35,7 +34,7 @@ struct BCM2708UsbPhy : IODevice {
 
        uint16_t usb_read(int reg) {
                write_bare(reg, 0, 0x60020000);
-               return USB_MDIO_CSR & 0x3FF;
+               return USB_MDIO_CSR & 0xFFFFF;
        }
 
        virtual void usb_write(int reg, uint16_t value) {
@@ -46,24 +45,58 @@ struct BCM2708UsbPhy : IODevice {
        virtual void start() override {
                IODriverLog("starting ...");
 
+               /* pseudo code really.. */
+               A2W_XOSC_CTRL |= A2W_PASSWORD | A2W_XOSC_USBEN_SET;
+               while(!(A2W_XOSC_CTRL & A2W_XOSC_USBOK_SET));
+
+               /* the LAN_RUN pin is GPIO6 according to the schematic */
+               /* edit: it's different between models.
+                * see https://github.com/raspberrypi/firmware/blob/master/extra/dt-blob.dts#L711
+                * e.g. on the RPi 2B it's pin 31
+                */
+
+               unsigned int ra = GP_FSEL3;
+               ra &= ~(7 << 3);
+               ra |= 1 << 3;
+               GP_FSEL3 = ra;
+
+               udelay(300);
+               GP_CLR0 = (1 << 31);
+               udelay(300);
+               GP_SET0 = (1 << 31);
+               udelay(300);
+
+               IODriverLog("LAN reset");
+
                USB_GMDIOCSR = (1 << 18);
 
-               usb_write(0x15, 4369/*cond ? 4569 : 272*/);
+               usb_write(0x15, 272 /* devmode ? 4369 : 272*/);
                usb_write(0x19, 0x4);
                usb_write(0x18, 0x10);
                usb_write(0x1D, 0x4);
                usb_write(0x17, 5682);
 
-               while(!usb_read(0x1B) & 0x7);
+               while((usb_read(0x1B) & (1 << 7)) != 0);
+
+               USB_GVBUSDRV &= ~(1 << 7);
 
-               usb_write(0x1E, 0x01);
+               usb_write(0x1E, 0x8000);
 
                usb_write(0x1D, 0x5000);
                usb_write(0x19, 0xC004);
-               usb_write(0x32, 0x1C2F);
-               usb_write(34, 256);
-               usb_write(36, 0x10);
-               usb_write(0x19, 0x04);
+               usb_write(0x20, 0x1C2F);
+               usb_write(0x22, 0x0100);
+               usb_write(0x24, 0x0010);
+               usb_write(0x19, 0x0004);
+
+               USB_GVBUSDRV = USB_GVBUSDRV & 0xFFF0FFFF | 0xD0000;
+               udelay(300);
+               mmio_write32(0x7E980400 + 3084, 0x20402700);
+               udelay(300);
+               mmio_write32(0x7E980400, 1);
+               udelay(300);
+               mmio_write32(0x7E980404, 0xBB80);
+               udelay(300);
 
                IODriverLog("started");
 
This page took 0.028092 seconds and 4 git commands to generate.