rpi-4.4.y: Add USB gadget support to Pi Zero#1239
rpi-4.4.y: Add USB gadget support to Pi Zero#1239notro wants to merge 124 commits intoraspberrypi:rpi-4.4.yfrom notro:otg-zero
Conversation
|
I only get the warning on keyboard disconnect if I have g_serial loaded. |
|
Thanks. No objections. @pelwell ? I did mention the inverted ACT led shortly before launch, but I think Mike liked the inverted, mostly on behaviour due to the absence of a PWR led, so it wasn't fixed then. I still think fixing it is probably the right thing to do, but we'll see what @pelwell and others think. |
|
The ACT led is great how it works at the moment. Ideal as there is no PWR led. Please don't change it. |
In what way ideal, that it works excatly as a PWR led? The trigger can be changed to The problem with the inverted behaviour is that trigger There's a DT overlay parameter (act_led_activelow) to change the inversion, but I think that the expected behaviour should be the default. Available triggers: Change trigger from boot with overlay parameter: act_led_trigger Change trigger immediately: |
|
I didn't say it works "exactly" as a PWR led, but it does provide a good indication the Pi zer0 is powered. It appears to default to ON indicating the Pi is powered and flashes off when the SD card is being accessed/written. My Pi zero sat next to me is idle at the moment and the ACT led is lit showing it is being powered. If it is changed to behave like the earlier Pi's that have a seperate PWR led then it would be off and I would not know if it was powered on or not. Or is this a case of it ain't broke fix it so it is, like the changes to the wifi made over the last few months. |
|
I think the original Zero LED behaviour should stay! I'm more interested in a visual indication that the Zero is being powered than its SDCARD is being accessed. What we have now is a good compromise, only having a single LED available to work with. |
|
How about this change which will turn the led on, but keep the correct behaviour for the other triggers? &leds {
act_led: act {
label = "led0";
- linux,default-trigger = "mmc0";
+ linux,default-trigger = "default-on";
gpios = <&gpio 47 1>;
};
};I agree that it's useful to have a power indicator. Some thoughts on using the act led: This way I would now that if the led never lights, there's a power/sdcard problem. If it lights up I know the firmware is loaded. |
smsc95xx is adjusting truesize when it shouldn't, and following a recent patch from Eric this is now triggering warnings. This patch stops smsc95xx from changing truesize. Signed-off-by: Steve Glendinning <steve.glendinning@smsc.com>
The old arch-specific IRQ macros included a dsb to ensure the write to clear the mailbox interrupt completed before returning from the interrupt. The BCM2836 irqchip driver needs the same precaution to avoid spurious interrupts. Spurious interrupts are still possible for other reasons, though, so trap them early.
Add a duplicate irq range with an offset on the hwirq's so the driver can detect that enable_fiq() is used. Tested with downstream dwc_otg USB controller driver. Signed-off-by: Noralf Trønnes <noralf@tronnes.org> Reviewed-by: Eric Anholt <eric@anholt.net> Acked-by: Stephen Warren <swarren@wwwdotorg.org>
Signed-off-by: Noralf Trønnes <noralf@tronnes.org>
Signed-off-by: Noralf Tronnes <notro@tronnes.org>
Contrary to the documentation, the BCM2835 GPIO controller actually has four interrupt lines - one each for the three IRQ groups and one common. Rather confusingly, the GPIO interrupt groups don't correspond directly with the GPIO control banks. Instead, GPIOs 0-27 generate IRQ GPIO0, 28-45 GPIO1 and 46-53 GPIO2. Awkwardly, the GPIOS for IRQ GPIO1 straddle two 32-entry GPIO banks, so it is cleaner to split out a function to process the interrupts for a single GPIO bank. This bug has only just been observed because GPIOs above 27 can only be accessed on an old Raspberry Pi with the optional P5 header fitted, where the pins are often used for I2S instead.
Although the GPIO controller can generate three interrupts (four counting the common one), the device tree files currently only specify two. In the absence of the third, simply don't register that interrupt (as opposed to registering 0), which has the effect of making it impossible to generate interrupts for GPIOs 46-53 which, since they share pins with the SD card interface, is unlikely to be a problem.
The spi-bcm2835 driver automatically uses GPIO chip-selects due to some unreliability of the native ones. In doing so it chooses the same pins as the native chip-selects would use, but the existing code always uses pins 7 and 8, wherever the SPI function is mapped. Search the pinctrl group assigned to the driver for pins that correspond to native chip-selects, and use those for GPIO chip- selects. Signed-off-by: Phil Elwell <phil@raspberrypi.org>
The VideoCore bootloader passes in Serial number and Revision number through Device Tree. Make these available to userspace through /proc/cpuinfo. Mainline status: There is a commit in linux-next that standardize passing the serial number through Device Tree (string: /serial-number): ARM: 8355/1: arch: Show the serial number from devicetree in cpuinfo There was an attempt to do the same with the revision number, but it didn't get in: [PATCH v2 1/2] arm: devtree: Set system_rev from DT revision Signed-off-by: Noralf Trønnes <noralf@tronnes.org>
Code copied from spi-bcm2835. Get physical address from devicetree instead of using hardcoded constant. Signed-off-by: Matthias Reichl <hias@horus.com>
Code ported from bcm2708-i2s driver in Raspberry Pi tree. RPi commit 62c05a0 ("ASoC: BCM2708: Add 24 bit support") This adds 24 bit support to the I2S driver of the BCM2708. Besides enabling the 24 bit flags, it includes two bug fixes: MMAP is not supported. Claiming this leads to strange issues when the format of driver and file do not match. The datasheet states that the width extension bit should be set for widths greater than 24, but greater or equal would be correct. This follows from the definition of the width field. Signed-off-by: Florian Meier <florian.meier@koalo.de> RPi commit 3e8c672 ("bcm2708-i2s: Update bclk_ratio to more correct values") Discussion about blck_ratio affecting sound quality: #681 Signed-off-by: Matthias Reichl <hias@horus.com>
Code ported from bcm2708-i2s driver in Raspberry Pi tree. RPi commit c14827e ("bcm2708: Allow option card devices to be configured via DT") Original work by Zoltan Szenczi, committed to RPi tree by Phil Elwell. Signed-off-by: Matthias Reichl <hias@horus.com>
Code ported from bcm2708-i2s driver in Raspberry Pi tree. RPi commit fd7d7a3 ("bcm2708: Eliminate i2s debugfs directory error") Qualify the two regmap ranges uses by bcm2708-i2s ('-i2s' and '-clk') to avoid the name clash when registering debugfs entries. Signed-off-by: Matthias Reichl <hias@horus.com>
Code ported from bcm2708-i2s driver in Raspberry Pi tree. RPi commit ba46b49 ("ASoC: Add support for BCM2708") This driver adds support for digital audio (I2S) for the BCM2708 SoC that is used by the Raspberry Pi. External audio codecs can be connected to the Raspberry Pi via P5 header. It relies on cyclic DMA engine support for BCM2708. Signed-off-by: Florian Meier <florian.meier@koalo.de> Signed-off-by: Matthias Reichl <hias@horus.com>
Code ported from bcm2708-i2s driver in Raspberry Pi tree. RPi commit 7ee829f ("bcm2708-i2s: Enable MMAP support via a DT property and overlay") The i2s driver used to claim to support MMAP, but that feature was disabled when some problems were found. Add the ability to enable this feature through Device Tree, using the i2s-mmap overlay. See: #1004 Signed-off-by: Matthias Reichl <hias@horus.com>
Add slave transfer capability to BCM2835 dmaengine driver. This patch is pulled from the bcm2708-dmaengine driver in the Raspberry Pi repo. The work was done by Gellert Weisz. Tested using the bcm2835-mmc driver from the same repo. Signed-off-by: Noralf Trønnes <noralf@tronnes.org>
bcm2835-dma supports residue reporting at burst level but didn't report this via the residue_granularity field. Without this field set properly we get playback issues with I2S cards. [by HiassofT, taken from bcm2708-dmaengine] Signed-off-by: Noralf Trønnes <noralf@tronnes.org>
|
I updated the tutorial above now with a lot more details! It works great, and with the patch @nmaas87 suggested everything works now at boot. Plug in your pi and it always connects with the same mac now. @shrx I guess we dont. I just tried with the full install. Feel free to test the lite image. I guess it should work without any problems. I guess its quite easy to use OTG now ;) |
|
@notro LOL. You're making me nostalgic! I remember how cool I thought it was when I plugged my first BeagleBone into a PC and got a serial console....... But the fact doesn't change, without dwc2 receiving some love, while it may be the answer for world peace in device mode, it leaves something to be desired, (that's the politest way of putting it), in host mode. wifi dongles suddenly disconnecting from USB bus is the tip of an iceberg. Heaven help you, (train crash leading to toxic chemical spill), trying to use it for USB audio! ;) |
Me too, it was so easy to get started. Your comment jogged my Solution-Finder-Unit and I realised that my goal might not be so far away after all. A keyboard plugged in after boot will still work, and if this behaviour is not desirable, the service can just be disabled. So here's project for me when I'm done banging my head agaist getting Pi2 mainline support working without issues (unless someone can't wait that long and finds a way to actually implement this).
My focus on an easily available serial console gave me tunnel vision, so I'm glad there's a review process :-) |
|
Just a small question: pi@raspberrypizero:~$ ping 8.8.8.8
ping: icmp open socket: Operation not permitted |
|
@NicoHood Not a problem because of g_ether I think. Test if the SUID bit is set correctly on your ping command, as described here: http://ben.goodacre.name/tech/Ping:_icmp_open_socket:_Operation_not_permitted_(Linux) |
|
I now also tried the usb gadget. It seems to work fine, I tried to install an OS into the emulated usb drive, but it failed after booting. But it was used on a slow "random" sd card, I will try this again on a better one. The question is now, how to enable the gadgets by default on a zero, but disable them in a pi2? We currently have to edit the config.txt. Is there a way to add something like Also can we automatically enable the dwc2 module if g_ether is loaded for example? Would this work too? Then people do not have to type both of them in the I really would like to see this feature more flexible across different pi models. This is really awesome. And some of the responsible pi people should solve the power issue by providing a schematic, so we know if connecting a PSU in device mode hurts any device. |
|
I just tried again (with a different sd card, from the beginning) and after applying: The raspi stops booting and the rainbow screen only shows up. If i remove the line (with an sd card reader) it boots up again. Using g_ether without those line does not work, but the line itself now also doesnt work anymore. So what has changed? I first setup the device with a pi2, however the 4.4 kernel all boots fine on a zero, just the device tree setting makes it not boot up anymore. Edit: |
|
@NicoHood no, the zero specific .dtb is no more as I found out. Just inside |
firmware: Fix for h264 picture corruption with german tv See: raspberrypi/firmware#499 firmware: TC358762: Avoid hanging when no DISPLAY_I2C_PORT defined in blob See: raspberrypi/firmware#526 firmware: video_render: Ensure pixel_x/pixel_y don't overflow calculations See: raspberrypi/firmware#525 firmware: arm_loader: Set uart0_clkrate before merging overlays See: https://www.raspberrypi.org/forums/viewtopic.php?f=29&t=113753&sid=df96fc384c4794d3344e5462a2ab0c45&start=150#p879523
|
What's the link to the Raspian github issue tracker? I can't find it. |
I guess https://github.com/RPi-Distro/repo/issues is the nearest match? |
|
Correct. For raspbian build of default debian packages it is: For raspberry pi specific packages and init scripts (not from debian) then: |
|
Thanks. RPi-Distro/repo#17 |
|
@t3chguy thanks! I updated the tutorial above. Is there a chance to load this overlay by default or is there any disadvantage for this? There is also another bug that |
See the messages from @clivem earlier in this discussion. |
|
So its unstable for host mode on some devices and it will be kept like this? Cant we load/unload those overlays at runtime? (Sorry i never did such kernel things before). |
|
Hey, what about using with usbip client as host on Raspberry Pi Zero (as usbip server running in another rasbperry pi with a device connected), then wirelessly you can plug Raspberry Pi Zero on a computer and see the device if it where connected directly to the computer. Can this be done? |
|
@braian87b I've read your comment several times, and I'm still not quite sure what you're asking for? I think what you're suggesting is having a PiZero in gadget-mode connected over USB to a PC, and then having the PiZero communicating wirelessly with another Raspberry Pi, and then having a USB device you connect to this second Raspberry Pi "tunnelled" wirelessly to the PiZero, and then exposing it as a 'virtual' USB device to the PC which the PiZero is connected to? However the PiZero only has one USB OTG port, which can operate in either host or device mode. So if you've got the Pi connected in device-mode to a PC, there's then no 'spare' USB host port into which to plug a Wifi dongle. There are ways of communicating with a wifi chip over the Pi's GPIO pins e.g. https://shop.pimoroni.com/products/esp8266-phat but that only runs at 1mbps, whereas USB2 runs at up to 480mbps (even USB1 is 12mbps). |
|
@lurch Right... sorry, I didn't notice... thanks! |
|
I was catching up on this discussion in light of some discussion elsewhere ( https://plus.google.com/u/0/+EricRaymond/posts/DR2zNNyNs3Z ) and I see my pi2 had in 4.4.12+/ for dwc2.ko but not in my latest update (4.4.12-v7). Does the OTG stuff work on the pi2 or pi3? |
No. The USB hub in the LAN9514 'gets in the way' and means that the single USB port in the SoC on those devices can only work in host (master) mode. It's only because the PiZero has a single USB port (i.e. no USB hub) that it's also able to (optionally) work in device (slave) mode. |
|
Anyone happen to have documentation on how to use the
I want to just connect it to my desktop computer and connect to it via The CHIP does this out of the box, so I was hoping to get the same sort of interface out of the Pi Zero. Can someone point me in the right direction for that? (I'm willing to be a guinea pig as I have 2 Pi Zero Ws and 1 Pi Zero - All of them I intend on using as headless servers. So never having to get a USB keyboard and Mini HDMI to HDMI connector is a bonus.) |
|
@Dygear you can use this for reference https://bit.ovh/2016/01/31/Raspberry-Pi-Zero-Gadget-Mode/ You can ignore rpi-update and run all those commands in a chroot of the mounted sd card (or even looped iso/img) You will have to create an appropriate symlink so systemd starts the tty/getty, and ignore the interfaces related commands and replace g_ether with g_serial I have notes on my laptop, I'll update when I get home |
|
I now need PI zero to implement a function: use USB Wire to connect PIzero and iPhone so that iPhone is the host, PIzero is the slave? I want to known if the funtion has been finished? Is there open source code? |
|
This is a question, not an issue. Please open a topic in the Raspberry Pi forums, stating what functionality the PiZero should provide - mass storage, etc. |
Build the dwc2 usb driver as a module to be able to use the USB On-the-Go functionality (supports both host and device/peripheral mode).
Add a specific Device Tree file for Pi Zero with dwc2 enabled in otg mode. Also fix the inverted ACT led.
This requires a change in the bootloader to give the Zero a dtb of it's own. Currently it uses this:
This PR can be tested by setting the dtb manually in /boot/config.txt:
Testing
This will give a serial console on a connected computer:
On my Windows 8 computer, the USB serial port shows up as: ELMO GMAS (COM5)
Hotswapping to a keyboard works.
Controller fifo
The fifo assignment isn't optimal. This PR uses only 1024 of the 4080 available dynamic fifo entries:
Currently assigned in Device Tree:
I don't know how to best distribute the remaining entries.
Issue
When I disconnect the keyboard, I get a warning:
Failed on 4.1
I also tried to do this PR on rpi-4.1.y but it didn't work and I didn't try to find out why. Got this error:
This PR is based on work done by several people in #1212