diff options
author | Tormod Volden <debian.tormod@gmail.com> | 2011-08-23 19:26:52 +0200 |
---|---|---|
committer | Tormod Volden <debian.tormod@gmail.com> | 2011-10-03 23:31:21 +0200 |
commit | 3fb37e4abdc8184a86d818e0eafe59520fc77d61 (patch) | |
tree | 32bb6362125f65f45fe24fe7c2516730dc165ced | |
parent | 80c08767404705250467f378931fe8bf35a11c2d (diff) |
Only print current status in usage() if we are root
Otherwise print "unknown" for dac and backlight status.
Signed-off-by: Tormod Volden <debian.tormod@gmail.com>
-rw-r--r-- | radeontool.c | 24 |
1 files changed, 18 insertions, 6 deletions
diff --git a/radeontool.c b/radeontool.c index cb7f051..f9710fc 100644 --- a/radeontool.c +++ b/radeontool.c @@ -26,13 +26,15 @@ #include "radeon_reg.h" +static void map_radeon_cntl_mem(void); + int debug = 0; int skip = 0; /* *radeon_cntl_mem is mapped to the actual device's memory mapped control area. */ /* Not the address but what it points to is volatile. */ struct pci_device *avivo_device = NULL; -unsigned char * volatile radeon_cntl_mem; +unsigned char * volatile radeon_cntl_mem = NULL; int ctrl_region = -1, fb_region = -1; unsigned char * volatile fb_mem; unsigned char * volatile ctrl_mem; @@ -141,13 +143,24 @@ static void radeon_set_mcind(unsigned long offset, const char *name, static void usage(void) { + const char *dac_status = "unknown"; + const char *light_status = "unknown"; + + if (geteuid() == 0) { + if (radeon_cntl_mem == NULL) + map_radeon_cntl_mem(); + dac_status = (radeon_get(RADEON_DAC_CNTL, "RADEON_DAC_CNTL") + & RADEON_DAC_PDWN) ? "off" : "on"; + light_status = (radeon_get(RADEON_LVDS_GEN_CNTL, "RADEON_LVDS_GEN_CNTL") + & RADEON_LVDS_ON) ? "on" : "off"; + } fprintf(stderr,"usage: radeontool [options] [command]\n"); fprintf(stderr," --debug - show a little debug info\n"); fprintf(stderr," --skip=1 - use the second radeon card\n"); - fprintf(stderr," dac [on|off] - power down the external video outputs (%s)\n", - (radeon_get(RADEON_DAC_CNTL,"RADEON_DAC_CNTL")&RADEON_DAC_PDWN)?"off":"on"); - fprintf(stderr," light [on|off] - power down the backlight (%s)\n", - (radeon_get(RADEON_LVDS_GEN_CNTL,"RADEON_LVDS_GEN_CNTL")&RADEON_LVDS_ON)?"on":"off"); + fprintf(stderr," dac [on|off] - power down the external " + "video outputs (%s)\n", dac_status); + fprintf(stderr," light [on|off] - power down the backlight " + "(%s)\n", light_status); fprintf(stderr," stretch [on|off|vert|horiz|auto|manual] - stretching for resolution mismatch \n"); fprintf(stderr," regs - show a listing of some random registers\n"); fprintf(stderr," regmatch <pattern> - show registers matching wildcard pattern\n"); @@ -2954,7 +2967,6 @@ int main(int argc,char *argv[]) if (geteuid() != 0) fprintf(stderr, "Warning: Need root privileges to access hardware\n"); if(argc == 1) { - map_radeon_cntl_mem(); usage(); } while (argc >= 2) { |