Back to index

lshw  02.16
Functions
fb.h File Reference
#include "hw.h"
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

bool scan_fb (hwNode &n)

Function Documentation

bool scan_fb ( hwNode n)

Definition at line 218 of file fb.cc.

{
  int fd[MAX_FB];
  unsigned int fbdevs = 0;
  unsigned int i;
  int major = lookup_dev("fb");

  if (major < 0)                                  // framebuffer support not loaded, there isn't
    return false;                                 // much we can do

  memset(fd, 0, sizeof(fd));
  for (i = 0; i < MAX_FB; i++)
  {
    fd[i] = open_dev((dev_t) ((major << 8) + i));

    if (fd[i] >= 0)
    {
      hwNode *fbdev = NULL;
      struct fb_fix_screeninfo fbi;

      if (ioctl(fd[i], FBIOGET_FSCREENINFO, &fbi) == 0)
      {
        fbdev =
          n.
          findChildByResource(hw::resource::
          iomem((unsigned long) fbi.smem_start,
          fbi.smem_len));

        if (fbdev)
        {
          char devname[20];
          struct fb_var_screeninfo fbconfig;

          snprintf(devname, sizeof(devname), "/dev/fb%d", i);
          fbdev->setLogicalName(devname);
          fbdev->claim();
          if (fbdev->getDescription() == "")
            fbdev->setDescription(hw::strip(fbi.id));
          fbdev->addCapability("fb");

          switch (fbi.visual)
          {
            case FB_VISUAL_MONO01:
              fbdev->setConfig("visual", "mono01");
              break;
            case FB_VISUAL_MONO10:
              fbdev->setConfig("visual", "mono10");
              break;
            case FB_VISUAL_TRUECOLOR:
              fbdev->setConfig("visual", "truecolor");
              break;
            case FB_VISUAL_PSEUDOCOLOR:
              fbdev->setConfig("visual", "pseudocolor");
              break;
            case FB_VISUAL_DIRECTCOLOR:
              fbdev->setConfig("visual", "directcolor");
              break;
            case FB_VISUAL_STATIC_PSEUDOCOLOR:
              fbdev->setConfig("visual", "static_pseudocolor");
              break;
          }

          if (fbi.accel != FB_ACCEL_NONE)
            fbdev->addCapability("accelerated");

          if (ioctl(fd[i], FBIOGET_VSCREENINFO, &fbconfig) == 0)
          {
            char vidmode[20];
            unsigned int htotal = 0;
            unsigned int vtotal = 0;

            snprintf(vidmode, sizeof(vidmode), "%dx%d", fbconfig.xres,
              fbconfig.yres);
            fbdev->setConfig("mode", vidmode);
            snprintf(vidmode, sizeof(vidmode), "%d", fbconfig.xres);
            fbdev->setConfig("xres", vidmode);
            snprintf(vidmode, sizeof(vidmode), "%d", fbconfig.yres);
            fbdev->setConfig("yres", vidmode);
            snprintf(vidmode, sizeof(vidmode), "%d", fbconfig.bits_per_pixel);
            fbdev->setConfig("depth", vidmode);

            vtotal =
              fbconfig.upper_margin + fbconfig.yres + fbconfig.lower_margin +
              fbconfig.vsync_len;
            htotal =
              fbconfig.left_margin + fbconfig.xres + fbconfig.right_margin +
              fbconfig.hsync_len;
            switch (fbconfig.vmode & FB_VMODE_MASK)
            {
              case FB_VMODE_INTERLACED:
                vtotal >>= 1;
                break;
              case FB_VMODE_DOUBLE:
                vtotal <<= 1;
                break;
            }

            if (fbconfig.pixclock)
            {
              char freq[20];

              double drate = 1E12 / fbconfig.pixclock;
              double hrate = drate / htotal;
              double vrate = hrate / vtotal;

              snprintf(freq, sizeof(freq), "%5.2fHz", vrate);
              fbdev->setConfig("frequency", freq);
            }

          }
        }
      }
    }
    else
      break;
  }

  for (unsigned int j = 0; j < fbdevs; j++)
  {
    close(fd[j]);
  }

  return false;
}

Here is the call graph for this function:

Here is the caller graph for this function: