Sunday, January 14, 2007

Twinview With Xorg and Nvidia using TVOut, CRT and DFP

Linux has come a long way since the early days, and along with it, so has the X server. Add to this the fact that Linux has come so far that Nvidia now writes drivers for their hardware for linux, and all of a sudden you can do some really sweet stuff with X and multiple displays. This post is the combination of many different experiments with X that I've played around with for the last several years, and will cover how to set up TwinView (dual monitors) using a Television, CRT or DFP (digital flat panel) as a second monitor.

For this post I will assume that you have a working X configuration for 1 monitor, that you have a nvidia graphics card, and that you have the proprietary nvidia drivers for linux installed. If you don't have the drivers installed I will offer an assist here for ubuntu and debian linux. The installation is as simple as:


sudo aptitude install nvidia-glx nvidia-kernel-common


We will be working extensively with the xorg.conf file (found on most linux distros in the /etc/X11/ folder). This file seems daunting and may certainly put the beginner off their game, but have no fear, this file is easy to work with once you understand how it works.

To start with the config file is split up into sections noted by starting and ending section tags like so:


Section "<section type>"
# section stuff
# more section stuff
EndSection


The first section germaine to our current task is the "Module" section. This section loads the various modules that X uses, such as the nvidia driver you've installed. In this section you will need to make sure that you have X load at least the following modules:


Section "Modules"
Load "glx"
Load "int10"
EndSection


And also make sure that the old drivers are commented out:


#Load "GLcore"


The two modules we added to the "Modules" section will allow us to use TwinView, and now all we have to do is configure our second monitor. My setup will assume that you only have one graphics card with multiple outputs, if you have the luxury of multiple graphics cards, you will need to adjust the value of the BusID option to the proper value for each individual graphics card. Each monitor that we configure will need three sections, a "Device" section, a "Monitor" section and a "Screen" section. The device section tells X which graphics card to look for the monitor in, and what type of monitor it is (TV, CRT, or DFP). The monitor section configures various hardware specific values for your monitor. The screen section links the monitor and device section together and sets the values for resolution for the attached monitor. I will go through these three sections for each of TV, CRT and DFP. Before you edit this file, make sure you make a backup:


cp /etc/X11/xorg.conf /etc/X11/xorg.conf.back


To use a traditional (non-HD) TV as a second monitor, these three sections will look like this:


##TVOut Setup
Section "Device"
Identifier "nvidia1"
Driver "nvidia"
BusID "PCI:1:0:0"
Screen 1
Option "TVOutFormat" "SVIDEO"
Option "TVStandard" "NTSC-M"
Option "ConnectedMonitor" "TV"
EndSection

##TVOut Setup
Section "Monitor"
Identifier "Monitor1"
Option "HorizSync" "30-50"
Option "VertRefresh" "60"
EndSection

##TVOut Setup
Section "Screen"
Identifier "Screen1"
Device "nvidia1"
Monitor "Monitor1"
DefaultDepth 24
SubSection "Display"
Depth 24
Modes "800x600"
EndSubSection
EndSection



Some things to note here, before I go on. First in the "Device" section, the "BusID" value should be the same as the BusID value in the Device section for your primary monitor if you are using the same graphics card. Second, the "TVOutFormat" option here is specifically for using S-Video for TVOut, if you are using some other format, such as "Composite" you will have to adjust the value here accordingly. Thridly, the "TVStandard" option "NTSC-M" will work for american make TVs, but if you're not in the states or somewhere else that uses "NTSC-M" you'll need to adjust the value to whatever it is you are using. A complete list of these by region can be found here: http://gentoo-wiki.com/TV-Out_with_GeForce. The HorizSync and VertRefresh values are the standard values for CRT Televisions, and if you're using a HDTV you should set up TV-Out using the DFP set-up that can be found later.

Now for the CRT setup, the three sections should look like this:


##CRT Setup
Section "Device"
Identifier "nvidia1"
Driver "nvidia"
BusID "PCI:1:0:0"
Screen 1
Option "UseInt10Module" "1"
Option "ConnectedMonitor" "CRT"
EndSection

##CRT Setup
Section "Monitor"
Identifier "Monitor1"
Option "HorizSync" "31.5-70"
Option "VertRefresh" "50-120"
Option "DPMS"
EndSection

##CRT Setup
Section "Screen"
Identifier "Screen1"
Device "nvidia1"
Monitor "Monitor1"
DefaultDepth 24
SubSection "Display"
Depth 24
Modes "1600x1200"
EndSubSection
EndSection


You can see that some of the values have been changed . . . and some have been added. Specifically the Monitor section includes the directive: Option "DPMS," this option is a powersaving option unavailable for TVs, but available for CRT and DFP monitors that turns the screen off after a certain amount of idle time. Aside from that you should be aware that the values of the HorizSync and VertRefresh vary from monitor to monitor, and if you get these wrong there is the possibility of destorying your monitor. So, google the make and model of your monitor, and these values should be relatively widely available. For common monitors you will easily find these values in any linux forum as well.

On to these sections for DFP:


##DFP Setup
Section "Device"
Identifier "nvidia1"
Driver "nvidia"
BusID "PCI:1:0:0"
Screen 1
Option "ConnectedMonitor" "DFP"
Option "UseInt10Module" "1"
EndSection

##DFP Setup
Section "Monitor"
Identifier "Monitor1"
Option "DPMS"
HorizSync 28-80
VertRefresh 43-60
EndSection

##DFP Setup
Section "Screen"
Identifier "Screen1"
Device "nvidia1"
Monitor "Monitor1"
DefaultDepth 16
SubSection "Display"
Depth 1
Modes "1600x1200"
EndSubSection
SubSection "Display"
Depth 4
Modes "1600x1200"
EndSubSection
SubSection "Display"
Depth 8
Modes "1600x1200"
EndSubSection
SubSection "Display"
Depth 15
Modes "1600x1200"
EndSubSection
SubSection "Display"
Depth 16
Modes "1600x1200"
EndSubSection
SubSection "Display"
Depth 24
Modes "1600x1200"
EndSubSection
EndSection


Again a few values have changed, and while the Screen section is quite a bit larger, it merely supports more depths than the previous two screen sections. Like the CRT, be carefull with the HorizSync and VertRefresh values as they vary and you could destroy your monitor if you mess this up. Use google and forums to find these values for your monitor.

Once you have defined these three sections for your TV, CRT or DFP we now have only to edit the "ServerLayout" section to tell the X server to use the second monitor and to tell X where it will be placed relative to your primary monitor. Add the following line to your "ServerLayout" Section:


Screen 1 "Screen1" leftof "Screen0"


This assumes that your primary monitor is titled Screen0, and that the secondary monitor is located to the left of your primary monitor. You can swap in rightof, above, or below for the value of leftof, depending on where the secondary monitor is located in physical relation to the primary monitor. Once this is done you need to restart the X server, the easiest way to do this is simply to restart the machine, but you can restart it if you like by using CTRL-ALT-F1, and then once you're in the command line CTRL-D or /etc/init.d/xorg-common. But this may vary from flavor to flavor, and so your safest bet is to just restart the computer. Should you have problems, hard reboot the machine, and boot into recovery mode, then copy your backup config file back to it's original location and hit CTRL-D and you should be good to go again.

Enjoy!

No comments: