Connecting the THG057VGLAC to BeagleBone Black

There’s a VGA display for sale at Pollin which costs 20€.

I connected to display to my Beagle Bone Black, which is able to drive the 3.3V compatible 18bit VGA TFT.
I’m using a regular Debian, that has been installed on the eMMC.

Here are the step to connect a display to the HDMI / LCD interface.

Step 1

Create a new file in
/opt/source/bb.org-overlays/src/arm

BB-BONE-LCDVGA-00A0.dts

/dts-v1/;
/plugin/;

#include #include #include

/ {
compatible = “ti,beaglebone”, “ti,beaglebone-black”, “ti,beaglebone-green”;

/* identification */
part-number = “BB-BONE-LCDVGA”;
version = “00A0″;

/* state the resources this cape uses */
exclusive-use =
/* the pin header uses */
“P8.45″, /* lcd: lcd_data0 */
“P8.46″, /* lcd: lcd_data1 */
“P8.43″, /* lcd: lcd_data2 */
“P8.44″, /* lcd: lcd_data3 */
“P8.41″, /* lcd: lcd_data4 */
“P8.42″, /* lcd: lcd_data5 */
“P8.39″, /* lcd: lcd_data6 */
“P8.40″, /* lcd: lcd_data7 */
“P8.37″, /* lcd: lcd_data8 */
“P8.38″, /* lcd: lcd_data9 */
“P8.36″, /* lcd: lcd_data10 */
“P8.34″, /* lcd: lcd_data11 */
“P8.35″, /* lcd: lcd_data12 */
“P8.33″, /* lcd: lcd_data13 */
“P8.31″, /* lcd: lcd_data14 */
“P8.32″, /* lcd: lcd_data15 */
“P8.27″, /* lcd: lcd_vsync */
“P8.29″, /* lcd: lcd_hsync */
“P8.28″, /* lcd: lcd_pclk */
“P8.30″, /* lcd: lcd_ac_bias_en */
“lcdc”;

fragment@0 {
target = <&am33xx_pinmux>;
__overlay__ {

bb_lcd_lcd_pins: pinmux_bb_lcd_lcd_pins {
pinctrl-single,pins = <
BONE_P8_45 (PIN_OUTPUT | MUX_MODE0) /* lcd_data0.lcd_data0 */
BONE_P8_46 (PIN_OUTPUT | MUX_MODE0) /* lcd_data1.lcd_data1 */
BONE_P8_43 (PIN_OUTPUT | MUX_MODE0) /* lcd_data2.lcd_data2 */
BONE_P8_44 (PIN_OUTPUT | MUX_MODE0) /* lcd_data3.lcd_data3 */
BONE_P8_41 (PIN_OUTPUT | MUX_MODE0) /* lcd_data4.lcd_data4 */
BONE_P8_42 (PIN_OUTPUT | MUX_MODE0) /* lcd_data5.lcd_data5 */
BONE_P8_39 (PIN_OUTPUT | MUX_MODE0) /* lcd_data6.lcd_data6 */
BONE_P8_40 (PIN_OUTPUT | MUX_MODE0) /* lcd_data7.lcd_data7 */
BONE_P8_37 (PIN_OUTPUT | MUX_MODE0) /* lcd_data8.lcd_data8 */
BONE_P8_38 (PIN_OUTPUT | MUX_MODE0) /* lcd_data9.lcd_data9 */
BONE_P8_36 (PIN_OUTPUT | MUX_MODE0) /* lcd_data10.lcd_data10 */
BONE_P8_34 (PIN_OUTPUT | MUX_MODE0) /* lcd_data11.lcd_data11 */
BONE_P8_35 (PIN_OUTPUT | MUX_MODE0) /* lcd_data12.lcd_data12 */
BONE_P8_33 (PIN_OUTPUT | MUX_MODE0) /* lcd_data13.lcd_data13 */
BONE_P8_31 (PIN_OUTPUT | MUX_MODE0) /* lcd_data14.lcd_data14 */
BONE_P8_32 (PIN_OUTPUT | MUX_MODE0) /* lcd_data15.lcd_data15 */

BONE_P8_27 (PIN_OUTPUT | MUX_MODE0) /* lcd_vsync.lcd_vsync */
BONE_P8_29 (PIN_OUTPUT | MUX_MODE0) /* lcd_hsync.lcd_hsync */
BONE_P8_28 (PIN_OUTPUT | MUX_MODE0) /* lcd_pclk.lcd_pclk */
BONE_P8_30 (PIN_OUTPUT | MUX_MODE0) /* lcd_ac_bias_en.lcd_ac_bias_en */
>;
};

};
};

fragment@1 {
target = <&lcdc>;
__overlay__ {
status = “okay”;
};
};

fragment@2 {
target-path=”/”;
__overlay__ {

/* avoid stupid warning */
#address-cells = <1>;
#size-cells = <1>;

panel {
status = “okay”;
compatible = “ti,tilcdc,panel”;
pinctrl-names = “default”;
pinctrl-0 = <&bb_lcd_lcd_pins>;
panel-info {
ac-bias = <255>;
ac-bias-intrpt = <0>;
dma-burst-sz = <16>;
bpp = <16>;
fdd = <0x80>;
sync-edge = <0>; /* 0. Shift clock by a half phase */
sync-ctrl = <1>;
raster-order = <1>;
fifo-th = <0>;
};
display-timings {
native-mode = <&timing0>;
timing0: 640×480 {
clock-frequency = <25200000>;
/* spec: htotal 770 – 900, hsync 2 – 200 default:96, hdisplay: 640, hfront porch 104 */
/* htotal = 800, hsync = 96, hfront porch = 104, hback porch > 44 */
hactive = <640>;
vactive = <480>;
hfront-porch = <20>; /* min 10 */
hback-porch = <104>; /* fixed */
hsync-len = <36>;
/* spec: vtotal 515 – 560, vsync 2 – 34, vfront porch + vsync: 34, vdisplay: 480 */
/* vtotal = 525, vsync + vback porch= 34, vsync = 5, vfront porch 29, vback port 11 */
vback-porch = <1>;
vfront-porch = <10>;
vsync-len = <33>;
hsync-active = <0>; /* active low */
vsync-active = <0>; /* active low */
de-active = <0>;
pixelclk-active = <1>;
};
};
};
};
};
};

Change into directory /opt/source/bb.org-overlays and run $ sudo install.sh

It will run the devicetree compiler dtc and it convert the dts into dto.
The dto is then copied to /lib/firmware.

Step 2

Edit /boot/uEnv.txt
find the line containing dtb= … and replace it with:

dtb=am335x-boneblack-emmc-overlay.dtb

It will disable the HDMI drm code, as I don’t want to use HDMI.

Step 3

Add this line CAPE=BB-BONE-LCDVGA to the file /etc/default/capemgr.

It’ll load the created devicetree fragment containing the description for the display.

Step 4

Connect the hardware.
Make sure to shield CLK, HSYNC and VSYNC !
Here’s the pinmux of the display:

Benchmarks
BBB connector BBB pin BBB function Function Display pin Display name
P8 46 LCD_DATA1 R4 8 R2
P8 45 LCD_DATA0 R3 7 R1
P8 44 LCD_DATA3 R6 10 R4
P8 43 LCD_DATA2 R5 9 R3
P8 42 LCD_DATA5 G2 13 G0
P8 41 LCD_DATA4 R7 11 R5
P8 40 LCD_DATA7 G4 15 G2
P8 39 LCD_DATA6 G3 14 G1
P8 38 LCD_DATA9 G6 17 G4
P8 37 LCD_DATA8 G5 16 G3
P8 36 LCD_DATA10 G7 18 G5
P8 35 LCD_DATA12 B4 22 B2
P8 34 LCD_DATA11 B3 21 B1
P8 33 LCD_DATA13 B5 23 B3
P8 32 LCD_DATA15 B7 25 B5
P8 31 LCD_DATA14 B6 24 B4
P8 30 LCD_BIAS_E DATA_ACTIVE 27 ENAB (tie low if unused)
P8 29 LCD_HSYNC HSYNC 3 HSYNC
P8 28 LCD_PCLK CLK 2 CLK
P8 27 LCD_VSYNC VSYNC 3 VSYNC
- - - - 30 Right/Left (tie low or high)
- - - - 31 Up/Down (tie low or high)

Final Result

EHCI Debug Dongle

EHCI Debug Dongle

EHCI Debug Dongle

EHCI Debug Dongle

Mesa Gallium Nine Benchmarks

Test-setup:
* Intel Core i5-3450
* 16GB DDR3
* Nvidia Geforce 8600GT, ATI HD4870, ATI HD6850
* Kernel 4.1.6
* Mesa 11.1-devel
* Wine 1.7.52
* DRI2

For more infos visit https://wiki.ixit.cz/d3d9.
All benchmarks are run with the following settings:
* Screen resolution 1280×720
* MSAA Off
* Vsync Off
* Qualitiy Low

I had to use low quality textures as the Geforce 8600GT only has 256Mbyte of VRAM and refuses to run the benchmark with higher resolution textures.

More Gallium Nine benchmarks: EXA vs GLAMOR
Test-setup:
* Intel(R) Core(TM) i7-2620M
* 8GB DDR3
* AMD CAICOS
* Kernel 3.18
* Mesa 10.6.0-devel
* Wine 1.7.38
* DRI3 enabled XServer
For more infos visit https://wiki.ixit.cz/d3d9.

Unigine Heaven Benchmark:
* Windowed 1366×768
* Quality “High”
* AA “off”
* Vsync “off”

AtXmega128A3U broken USB enumeration

Today I found a strange issue in Atmels AtXmega128A3U USB controller.
The device wasn’t able to enumerate 3 times in a row, but the fourth time it was working.

It prints lots of errors to the syslog:

[129737.064357] usb 3-1: new full-speed USB device number 87 using xhci_hcd
[129737.178628] usb 3-1: device descriptor read/64, error -71
[129737.279393] xhci_hcd 0000:26:00.0: Setup ERROR: setup context command for slot 1.
[129737.279409] usb 3-1: hub failed to enable device, error -22
[129737.433373] usb 3-1: new full-speed USB device number 88 using xhci_hcd
[129737.547412] usb 3-1: device descriptor read/64, error -71
[...]

The USB engine is running from the internal 32Mhz RC oscillator tuned to 48Mhz.
This is a nice feature, but not very accurate. I measured an actual frequency of 50Mhz.
You need to enable the DFLL to provide a stable 48Mhz USB clock.

The problems are generated by the 32kHz RC oscillator !
It is enabled by either

#define CONFIG_OSC_AUTOCAL_RC2MHZ_REF_OSC OSC_ID_RC32KHZ

or by using the RTC

#define CONFIG_RTC_SOURCE CLK_RTCSRC_RCOSC_gc

or using it as CPU CLK source (which doesn’t make sense for USB).

Gallium Nine ST Benchmarks

More Gallium Nine benchmarks.
Test-setup:
* Intel Core i5-3450
* 8GB DDR3
* ATI HD6850
* Kernel 3.17
* Mesa 10.5.0-devel
* Wine 1.7.34
* DRI3 enabled XServer
For more infos visit https://wiki.ixit.cz/d3d9.

All benchmarks are run with the following settings:
* Screen resolution 1680×1050
* MSAA 4x / FXAA (Tomb Raider)
* Vsync Off



*Wine: spams “Mesa: User error: GL_INVALID_OPERATION”. shadows/light maps are broken. Test results might not be correct.

*Wine spams “Mesa: User error: GL_INVALID_OPERATION”. Test results might not be correct.


Gallium Nine ST benchmarks

Here’re some benchmarks of the new Mesa Gallium Nine ST. You need at least Mesa 10.4 and a patched version of WINE.

Test setup:
* Intel Core i5-3450
* 8GB DDR3
* ATI HD6850
* Kernel 3.17
* Mesa 10.4.0
* Wine 1.7.33
* DRI3 enabled X
* Screen resolution 1680×1050
For more infos visit https://wiki.ixit.cz/d3d9.

Benchmarks
application driver WineD3D i686 Wine + Gallium Nine i686 Linux OpenGL x86_64 Comments
3DMark05 Mesa 10.4 wine_3dmark05 nine_3dmark05 - postprocessing disabled
3DMark06 Mesa 10.4 wine_3dmark06 nine_3dmark06 - postprocessing disabled
Unigine Valley Mesa 10.4 wine_valley nine_valley opengl_valley_native Wine: some textures dark
Unigine Heaven Mesa 10.4 wine_heaven nine_heavon opengl_haeven_native Wine: no ambient occlusion; no volume shadows; shadows broken; some textures missing; Test results might not be correct !
Half Life2 Lost Coast Mesa 10.4 81 fps 183 fps 185 fps

Installing Gallium Nine Statetracker

This tutorial guides you through the process of using Mesas new Gallium Nine StateTracker (developed here). It allows to run DirectX9 Application using a modified version of WINE directly on the GPU, without translating all the commands to OpenGL first. The drawback of this, it’s only usable with Mesa Radeon or Nouveau driver. Proprietary drivers (like fglrx) and Mesas Intel drivers doesn’t work. However it boosts the 3D performance. More in the next tutorial.

This tutorial is for RHEL. Make sure you have all development packages required to build mesa and xorg and wine.
#1 Get a copy of official Mesa:
git clone git://anongit.freedesktop.org/mesa/mesa

#2 Checkout branch master or tag mesa-10.4.0
git checkout mesa-10.4.0

#3 build 64bit mesa
sh autogen.sh
./configure --enable-nine --enable-vdpau --enable-gles2 --enable-gles1 --enable-dri3 --enable-texture-float --prefix=/usr --enable-selinux --enable-debug --with-egl-platforms=drm,x11

#4 install 64bit mesa
sudo make install

#5 build 32bit mesa
make distclean
LLVM_CONFIG=/usr/bin/llvm-config-32 CFLAGS="-m32 -O2" CXXFLAGS="-m32 -O2" ./configure --enable-nine --enable-vdpau --enable-gles2 --enable-gles1 --enable-dri3 --enable-texture-float --prefix=/usr --host=i686-linux --enable-selinux --enable-debug --with-egl-platforms=drm,x11

#6 install 32bit mesa
sudo make install

#7 verify installation
glxinfo
It should show that you are now on mesa 10.4.0, if not make sure no other drivers are installed.

#8 install DRI3 Xorg ati driver (for ATI users only)
git clone https://github.com/iXit/xf86-video-ati.git
sh autogen.sh
./configure --enable-glamor --prefix=/usr
make
sudo make install

#9 install modified version of WINE
git clone https://github.com/iXit/wine.git
./configure --prefix=/usr
make
sudo make install

#10 check if it’s working
winecfg

You should see a checkbox under Tab “Graphics” saying “Allow native Direct3D” . Enable it.
Run a DirectX9 application to be sure it’s working.
If you see a green text in console “Native Direct3D is active.” you have done it.
Attention: On DRI2 enabled Xorg driver it falls back to WINEs OpenGL wrapper without any notice!

That’s it, your now able to run DirectX9 application !

mapping coherent buffers into userspace

On some platforms it might be useful to map coherent memory into userspace. Such a platform is the Xillinx Zynq heterogeneous system. The Zynq allows you to generate hardware, that is able to modify data inside the DRAM of the ARM, while the ARM is running. The standard way would be to allocate a buffer in kernelspace, and pass the physical address of this buffer to the hardware working on it. However this way involves copying the data to and from kernel memory using ioctls or read/write commands. Here’s a solution that allows you to memory map the buffer into userspace, thus no copy is required at all.
The important part is to use the same cache configuration for “both” buffers. They are using the same physical memory, but the kernel doesn’t care about that.
Here’s the kernels mmap function, that is being called from userspace using mmap:


static int mmap(struct file *file, struct vm_area_struct *vma)
{
struct mem_object *mo = file->private_data;
long length;
unsigned long start;
int i;
start = vma->vm_start;
length = vma->vm_end - vma->vm_start;
for(i = 0; i < mo->pages; i++)
{
int ret;
int size = length > KMALLOC_MAX_SIZE ? KMALLOC_MAX_SIZE : length;
if (sg_phys(mo->sg_list + i) >= __pa(high_memory) || (file->f_flags & O_SYNC))
vma->vm_flags |= VM_IO;
/*
* disable cache for coherent, enable for non coherent
* don't mix coherent and non coherent on user <-> kernel mapping
*/
if (mo->coherent)
vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
/* map the whole physically contiguous area in one piece */
if ((ret = remap_pfn_range(vma,
start,
sg_phys(mo->sg_list + i)>>PAGE_SHIFT,
size,
vma->vm_page_prot)) < 0) {
return ret;
}
start += size;
length -= size;
}
return 0;
}

mo->sg_list is a scatterlist with one or multiple page entries, that point to the memory allocated. A page can have a size up to KMALLOC_MAX_SIZE (here 4Mbyte).
mo->pages holds the count of pages stored in mo->sg_list
mo->coherent is set when coherent memory was allocated

The important command is "vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);". It disables the cache on the userspace memory if the kernel memory has no cache enabled either.
To allocate coherent memory (without cache) use the dma_alloc_coherent( ... ) function and set mo->coherent to 1.
On the other hand, if the kernel memory has cache enabled, by using kmalloc( ... ) for example, you don't have to disable the cache on userspace memory. Set mo->coherent to 0. Mixing coherent and non coherent mappings results in undefined caching behavior !

Attention: If you use non-coherent memory use the dma_map_sg( ... , DMA_FROM_DEVICE ) functions to flush / invalidate the cache on the buffer before and after working on it using the hardware.

Virtualbox 4.3.12 Guest Windows 7 Video slow motion

I’ve run into this issue today.
Setup:
Virtualbox 4.3.12
Linux Host
Windows 7 VM with Guest Additions installed

Issue:

    Windows 7 VM

  • Windows Mediaplayer plays videos in slowmotion
  • Flash videos / livestreams in Internet Explorer or Firefox are played in slowmotion
  • VLC behaves normal
    Windows XP VM

  • Windows Mediaplayer behaves normal
  • Flash videos / livestreams in Internet Explorer or Firefox behaves normal
  • VLC behaves normal

Fix:
It turns out the VM audio backend was set to OSS. I’ve switched to pulse (Pulseaudio) and the issue disapeared.
VBoxManage modifyvm "name" --audio pulse