/ src / core / input.cc
input.cc
  1  #include "version.h"
  2  #include "hw.h"
  3  #include "sysfs.h"
  4  #include "osutils.h"
  5  #include "input.h"
  6  #include "disk.h"
  7  #include "heuristics.h"
  8  
  9  #include <vector>
 10  #include <iostream>
 11  
 12  __ID("@(#) $Id$");
 13  
 14  #define BUS_PCI                 0x01
 15  #define BUS_ISAPNP              0x02
 16  #define BUS_USB                 0x03
 17  #define BUS_HIL                 0x04
 18  #define BUS_BLUETOOTH           0x05
 19  #define BUS_VIRTUAL             0x06
 20  
 21  #define BUS_ISA                 0x10
 22  #define BUS_I8042               0x11
 23  #define BUS_XTKBD               0x12
 24  #define BUS_RS232               0x13
 25  #define BUS_GAMEPORT            0x14
 26  #define BUS_PARPORT             0x15
 27  #define BUS_AMIGA               0x16
 28  #define BUS_ADB                 0x17
 29  #define BUS_I2C                 0x18
 30  #define BUS_HOST                0x19
 31  #define BUS_GSC                 0x1A
 32  #define BUS_ATARI               0x1B
 33  #define BUS_SPI                 0x1C
 34  #define BUS_RMI                 0x1D
 35  #define BUS_CEC                 0x1E
 36  #define BUS_INTEL_ISHTP         0x1F
 37  
 38  using namespace std;
 39  
 40  bool scan_input(hwNode & n)
 41  {
 42    vector < sysfs::entry > entries = sysfs::entries_by_class("input");
 43  
 44    if (entries.empty())
 45      return false;
 46  
 47    for (vector < sysfs::entry >::iterator it = entries.begin();
 48        it != entries.end(); ++it)
 49    {
 50      const sysfs::entry & e = *it;
 51  
 52      if(!e.hassubdir("id")) continue;
 53  
 54      hwNode *device = n.findChildByBusInfo(e.leaf().businfo());
 55      if(!device)
 56      {
 57        device = n.findChildByBusInfo(e.leaf().parent().businfo());
 58        if(device)
 59          device = device->addChild(hwNode("input", hw::input));
 60      }
 61      if(!device)
 62        device = n.addChild(hwNode("input", hw::input));
 63      else
 64      {
 65        if(device->getClass() == hw::generic)
 66          device->setClass(hw::input);
 67      }
 68      device->claim();
 69      device->setLogicalName("input/"+e.name());
 70      device->setProduct(e.string_attr("name"));
 71      device->setModalias(e.modalias());
 72      switch(e.hex_attr("id/bustype"))
 73      {
 74        case BUS_PCI:
 75  	      device->addCapability("pci", "PCI");
 76  	      break;
 77        case BUS_ISAPNP:
 78  	      device->addCapability("isa", "ISA");
 79  	      device->addCapability("pnp", "PnP");
 80  	      break;
 81        case BUS_USB:
 82  	      device->addCapability("usb", "USB");
 83  	      break;
 84        case BUS_HIL:
 85  	      device->addCapability("hil", "HP-HIL");
 86  	      break;
 87        case BUS_BLUETOOTH:
 88  	      device->addCapability("bluetooth", "Bluetooth");
 89  	      break;
 90        case BUS_VIRTUAL:
 91  	      device->addCapability("virtual");
 92  	      break;
 93        case BUS_ISA:
 94  	      device->addCapability("isa", "ISA bus");
 95  	      break;
 96        case BUS_I8042:
 97  	      device->addCapability("i8042", "i8042 PC AT keyboard controller");
 98  	      break;
 99        case BUS_XTKBD:
100  	      device->addCapability("xtkbd", "XT keyboard controller");
101  	      break;
102        case BUS_RS232:
103  	      device->addCapability("rs232", "RS-232 serial");
104  	      break;
105        case BUS_GAMEPORT:
106  	      device->addCapability("gameport", "game port");
107  	      break;
108        case BUS_PARPORT:
109  	      device->addCapability("parport", "parallel port");
110  	      break;
111        case BUS_AMIGA:
112  	      device->addCapability("amiga", "Amiga bus");
113  	      break;
114        case BUS_ADB:
115  	      device->addCapability("adb", "Apple Desktop Bus");
116  	      break;
117        case BUS_I2C:
118  	      device->addCapability("i2c", "I²C bus");
119  	      break;
120        case BUS_HOST:
121  	      device->addCapability("platform");
122  	      break;
123        case BUS_GSC:
124  	      device->addCapability("gsc", "GSC bus");
125  	      break;
126        case BUS_ATARI:
127  	      device->addCapability("atari", "Atari bus");
128  	      break;
129        case BUS_SPI:
130  	      device->addCapability("spi", "SPI");
131  	      break;
132        case BUS_RMI:
133  	      device->addCapability("rmi", "RMI");
134  	      break;
135        case BUS_CEC:
136  	      device->addCapability("cec", "CEC");
137  	      break;
138        case BUS_INTEL_ISHTP:
139  	      device->addCapability("intelishtp", "Intel Integrated Sensor Hub");
140  	      break;
141      }
142  
143      vector < sysfs::entry > events = e.devices();
144      for(vector < sysfs::entry >::iterator i = events.begin(); i != events.end(); ++i)
145      {
146        const sysfs::entry & d = *i;
147        device->setLogicalName("input/"+d.name());
148      }
149    }
150  
151    return true;
152  }